- Time limit: 1.00 s
- Memory limit: 512 MB
You are playing a game consisting of planets. Each planet has a teleporter to another planet (or the planet itself).
You start on a planet and then travel through teleporters until you reach a planet that you have already visited before.
Your task is to calculate for each planet the number of teleportations there would be if you started on that planet.
Input
The first input line has an integer : the number of planets. The planets are numbered .
The second line has integers : for each planet, the destination of the teleporter. It is possible that .
Output
Print integers according to the problem statement.
Constraints
Example
Input:
5 2 4 3 1 4
Output:
3 3 1 3 4