In Summer Informatics School, if a student doesn't behave well, teachers make a hole in his badge. And today one of the teachers caught a group of $n$ students doing yet another trick.
Let's assume that all these students are numbered from $1$ to $n$. The teacher came to student $a$ and put a hole in his badge. The student, however, claimed that the main culprit is some other student $p_a$.
After that, the teacher came to student $p_a$ and made a hole in his badge as well. The student in reply said that the main culprit was student $p_{p_a}$.
This process went on for a while, but, since the number of students was finite, eventually the teacher came to the student, who already had a hole in his badge.
After that, the teacher put a second hole in the student's badge and decided that he is done with this process, and went to the sauna.
You don't know the first student who was caught by the teacher. However, you know all the numbers $p_i$. Your task is to find out for every student $a$, who would be the student with two holes in the badge if the first caught student was $a$.
## Input
The first line of the input contains the only integer $n$ ($1 \le n \le 1000$) — the number of the naughty students.
The second line contains $n$ integers $p_1$, ..., $p_n$ ($1 \le p_i \le n$), where $p_i$ indicates the student who was reported to the teacher by student $i$.
## Output
For every student $a$ from $1$ to $n$ print which student would receive two holes in the badge, if $a$ was the first student caught by the teacher.
[samples]
## Note
The picture corresponds to the first example test case.
<center></center>When $a = 1$, the teacher comes to students $1$, $2$, $3$, $2$, in this order, and the student $2$ is the one who receives a second hole in his badge.
When $a = 2$, the teacher comes to students $2$, $3$, $2$, and the student $2$ gets a second hole in his badge. When $a = 3$, the teacher will visit students $3$, $2$, $3$ with student $3$ getting a second hole in his badge.
For the second example test case it's clear that no matter with whom the teacher starts, that student would be the one who gets the second hole in his badge.
在夏季信息学学校中,如果学生行为不端,老师会在他的徽章上打一个洞。今天,一位老师抓到了一群共 $n$ 名学生在搞恶作剧。
假设这些学生编号从 $1$ 到 $n$。老师先找到学生 $a$,并在他的徽章上打了一个洞。然而,这名学生声称真正的主谋是另一个学生 $p_a$。
随后,老师找到学生 $p_a$,也在他的徽章上打了一个洞。这名学生则声称主谋是学生 $p_(p_a)$。
这个过程持续了一段时间,但由于学生数量有限,最终老师会再次来到一个已经有一个洞的徽章的学生面前。
这时,老师会在该学生的徽章上打第二个洞,并认为这个过程已经结束,然后去桑拿房了。
你不知道老师最初抓到的是哪个学生。但你知道所有的 $p_i$ 值。你的任务是:对于每个学生 $a$,如果第一个被抓的学生是 $a$,那么最终哪个学生会得到两个洞的徽章。
输入的第一行包含一个整数 $n$ ($1 lt.eq n lt.eq 1000$) —— 淘气学生的数量。
第二行包含 $n$ 个整数 $p_1$, ..., $p_n$ ($1 lt.eq p_i lt.eq n$),其中 $p_i$ 表示学生 $i$ 指认给老师的主谋学生。
对于每个学生 $a$(从 $1$ 到 $n$),请输出如果 $a$ 是第一个被抓的学生,那么最终哪个学生会得到两个洞的徽章。
下图对应第一个示例测试用例。
当 $a = 1$ 时,老师依次访问学生 $1$、$2$、$3$、$2$,学生 $2$ 得到第二个洞。
当 $a = 2$ 时,老师依次访问学生 $2$、$3$、$2$,学生 $2$ 得到第二个洞。当 $a = 3$ 时,老师依次访问学生 $3$、$2$、$3$,学生 $3$ 得到第二个洞。
对于第二个示例测试用例,无论老师从谁开始,该学生都会是获得第二个洞的学生。
## Input
输入的第一行包含一个整数 $n$ ($1 lt.eq n lt.eq 1000$) —— 淘气学生的数量。第二行包含 $n$ 个整数 $p_1$, ..., $p_n$ ($1 lt.eq p_i lt.eq n$),其中 $p_i$ 表示学生 $i$ 指认给老师的主谋学生。
## Output
对于每个学生 $a$(从 $1$ 到 $n$),请输出如果 $a$ 是第一个被抓的学生,那么最终哪个学生会得到两个洞的徽章。
[samples]
## Note
下图对应第一个示例测试用例。当 $a = 1$ 时,老师依次访问学生 $1$、$2$、$3$、$2$,学生 $2$ 得到第二个洞。当 $a = 2$ 时,老师依次访问学生 $2$、$3$、$2$,学生 $2$ 得到第二个洞。当 $a = 3$ 时,老师依次访问学生 $3$、$2$、$3$,学生 $3$ 得到第二个洞。对于第二个示例测试用例,无论老师从谁开始,该学生都会是获得第二个洞的学生。
**Definitions**
Let $ n \in \mathbb{Z}^+ $ be the number of students.
Let $ p: \{1, 2, \dots, n\} \to \{1, 2, \dots, n\} $ be a function where $ p_i $ denotes the student accused by student $ i $.
**Constraints**
$ 1 \leq n \leq 1000 $, and for all $ i \in \{1, \dots, n\} $, $ 1 \leq p_i \leq n $.
**Objective**
For each starting student $ a \in \{1, \dots, n\} $, define the sequence:
$$
s_0 = a, \quad s_{k+1} = p(s_k) \quad \text{for } k \geq 0
$$
Let $ t_a $ be the smallest index $ k \geq 1 $ such that $ s_k \in \{s_0, s_1, \dots, s_{k-1}\} $.
Then, the student who receives the second hole is $ s_{t_a} $.
For each $ a \in \{1, \dots, n\} $, output $ s_{t_a} $.