Given a sequence of n integers, p(1),p(2),…,p(n) where each element is distinct and satisfies 1 <= p(x) <= n. For each x where 1 <= x <= n, find any integer y such that p(p(y)) = x and print the value of y on a new line.
For example, assume the sequence p = [5, 2, 1, 3, 4]. Each value of x between 1 and 5, the length of the sequence, is analyzed as follows:
- , so p[p[4]] = 1
- , so p[p[2]] = 2
- , so p[p[5]] = 3
- , so p[p[1]] = 4
- , so p[p[3]] = 5
The values for y are [4,2,5,1,3].