Problems
Ancestors
Ancestors
Examining the genes of several thousand people, scientists assumed that all mankind originated from a small tribe of $20$ people who lived somewhere in West Africa.
United Association of Cloned Martians decided to conduct similar studies for the inhabitants of Mars. Write a program to ACM, which, using the results of a large genetic study of Martians, assigning him the progenitor of a Martian.
\InputFile
The first line contains the number $n~(1 < n \le 10^5)$ of surveyed Martians. Is followed by $n$ lines, each containing a single integer from $0$ to $n$. In the $(i + 1)$-th line the number is the parent of $i$-th Martian, or $0$, if it has no parent (i.e. he is the father, like Adam and Eve in the Bible). The input data does not contain cycles.
\OutputFile
Print for each Martian his ancestor, or $0$ if he is the father.
\includegraphics{https://static.eolymp.com/content/f4/f47f49cf5053064582b6bcbe1ef9e03b015aaf21.gif}
Input example #1
7 3 3 6 7 4 0 0
Output example #1
6 6 6 7 7 0 0