欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1020B.Badge
Badge
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 students doing yet another trick.
Let's assume that all these students are numbered from to . The teacher came to student and put a hole in his badge. The student, however, claimed that the main culprit is some other student .
After that, the teacher came to student and made a hole in his badge as well. The student in reply said that the main culprit was student .
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 . Your task is to find out for every student , who would be the student with two holes in the badge if the first caught student was .
Input
The first line of the input contains the only integer () — the number of the naughty students.
The second line contains integers , ..., (), where indicates the student who was reported to the teacher by student .
Output
For every student from to print which student would receive two holes in the badge, if was the first student caught by the teacher.
Note
The picture corresponds to the first example test case.

When , the teacher comes to students , , , , in this order, and the student is the one who receives a second hole in his badge.
When , the teacher comes to students , , , and the student gets a second hole in his badge. When , the teacher will visit students , , with student 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.
Samples
3
2 3 2
2 2 3
3
1 2 3
1 2 3
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |