#DSU0000021. Trao đổi sách – bản dễ (Books Exchange (Easy Version))
Bài tập thuộc lộ trình
Mục lục đề ⌄
Trao đổi sách – bản dễ (Books Exchange (Easy Version))
Books Exchange (Easy Version)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are students numbered from to . Initially, student holds book . At the end of each day, every student simultaneously passes the book currently in their possession to student .
The sequence is a permutation of . Hence each student sends exactly one book and receives exactly one book each day. All transfers happen simultaneously; a book received during a day cannot be passed on again that same day.
For each student , find the smallest positive number of days after which their original book returns to them. All students keep following the given transfer rule.
Input
The first line contains . The second line contains a permutation .
Output
Print integers; the -th is the first return day of student 's original book.
Subtasks
- Subtask 1 (20 points): ; is a permutation of .
- Subtask 2 (30 points): ; is a permutation of .
- Subtask 3 (50 points): ; is a permutation of .
Examples
Input
5
5 1 2 4 3
Output
4 4 4 1 4
Explanation
The exchanges follow the cycle , which contains four people. Each person in positions can therefore receive four different books. Position forms a cycle of length one, giving 4 4 4 1 4.