Gug is having fun with a dance. In Gug Dance, there are a total of N dancing mats, numbered from 0 to N-1. There are N minions, with minion i standing on dance mat i. Each dance mat i has a number Ai written on it, between 0 to N-1 and the number on each dance mat is unique.
When Gug shouts 'banana', the minion standing on dance mat i will move to dance mat Ai. Peanut finds himself watching this Gug Dance, after Gug shouts 'banana' twice. The minion standing at dance mat i originally is at dance mat Bi after the two shouts of 'banana'. However, Peanut cannot see the numbers on the dance mats. Given B, construct the array A. It is guaranteed that there is at least one possible array.
The first line of input will consist of one integer, N.
The second line of input will consist of N integers, representing the array B. B will be a permutation of 0...N-1.
The output should contain one line with N integers, the array A satisfying the above conditions. A should also be a permutation of 0...N-1.
Subtask 1 (26%): 1 ≤ N ≤ 8.
Subtask 2 (30%): 1 ≤ N ≤ 500000, Bi = (i + 1) % N.
Subtask 3 (44%): 1 ≤ N ≤ 500000.
Subtask 4 (0%): Sample Testcases.
4 1 0 3 2
2 3 1 0
5 1 2 3 4 0
3 4 0 1 2
Subtask | Score |
---|---|
1 | 26 |
2 | 30 |
3 | 44 |
4 | 0 |