D. Rooms
time limit per test
10 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

In previous meetings of the Independent Organization for Epizootics, also known as the World Organization for Animal Health, everyone gathered in Barcelona to discuss the most relevant topics. However, every year several problems occurred.

Many members lost the key to their room. For this reason and others, this year the meeting will be held remotely.

Although the meeting will not take place, the organization wants to solve the problem and proposes a solution. They know that $$$N$$$ people will attend the meeting, and each person $$$p_i$$$ has two keys to their room: one they will carry with them and the other they will leave in the room of the person $$$c_i$$$ ($$$c_1 \neq p_i$$$) whom they trust. Thus, whenever person $$$c_i$$$ can access their room, they will be able to enter and take the key of person $$$p_i$$$. It is guaranteed that there is at least one person such that if they can access their room, then all other people will be able to access theirs.

The association is interested in knowing for each person $$$p_i$$$, what is the minimum number of people that need to lose their key for them to be unable to access their room.

Input

The input consists of several cases. Each case consists of two lines.

The first line of each case is an integer $$$N$$$, the number of people attending the meeting. The second line of each case contains $$$N$$$ integers $$$c_i$$$, the room where the i-th person leaves their second key.

Output

For each case, you must print $$$N$$$ integers separated by a space and with a newline at the end.

The i-th integer is the minimum number of people that must lose their key for person $$$p_i$$$ to be unable to access their room.

Scoring

$$$ 2 \leq N \leq 10^5 $$$

$$$ 0 \leq c_i \lt N $$$

Subcases

Subcase 1 (10pt):

- $$$ N \leq 100 $$$

Subcase 2 (35pt):

- $$$ N \leq 1000 $$$

Subcase 3 (55pt):

- No additional restrictions

Example
Input
2
1 0
5
1 0 0 0 0
5
1 2 3 2 3
Output
2 2 
2 2 3 3 3 
4 3 2 2 3