F. Football in Osijek
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

The famous Osijek Competitive Programming Camp has grown so popular, it branched out to other training camps as well, one of which is the Osijek Football Training Camp. The big Osijek Football Cup is soon starting, so the camp wants to assemble a team. But the rules are quite strict and require that a team consists of exactly $$$k$$$ players. The camp has $$$n$$$ football players, numbered from $$$1$$$ to $$$n$$$. The players have preferences for who they want to be in the team with. Player $$$i$$$ has a preference of the form:

"If I join the team, then player $$$a_i$$$ must also join the team."

It can be that $$$i = a_i$$$; that means that this particular player only cares about themselves.

Further more, the players have an extra demand:

"I don't want to be in a team with somebody who is not connected to me with a preference chain."

A preference chain is a sequence of players $$$u, p_2, p_3, p_4 ... v$$$, such that the next player in the sequence is $$$a_\text{current player}$$$. Two players $$$u$$$ and $$$v$$$ are connected, if there's a preference chain from $$$u$$$ to $$$v$$$, or from $$$v$$$ to $$$u$$$.

Unfortunately, after careful reading of the rules, it's still vague what the value of $$$k$$$ is. So for all $$$k$$$ from $$$1$$$ to $$$n$$$ you want to consider the scenario, where you need a team of size $$$k$$$. If it's impossible to make a team, you decide to talk to the players. In one meeting, you can choose a player $$$i$$$, and convince them to change their preference. Formally, you choose $$$1 \leq i,x \leq n$$$ and do the update $$$a_i := x$$$. After this it's allowed that $$$a_i = i$$$.

Find, for each $$$k$$$ from $$$1$$$ to $$$n$$$, the least number of meetings you need to form a team of size $$$k$$$.

Input

The first line of input contains one integer, $$$n$$$ ($$$1 \leq n \leq 500\,000$$$)  — the number of players in the Osijek Football Training Camp.

The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq n$$$)  — the current preferences of all the players.

Output

Output one line consisting of $$$n$$$ integers, the minimum number of meetings for all $$$k$$$ from $$$1$$$ to $$$n$$$.

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