#P2582. 函数

函数

Description

Alice gives a permutation of 11 to nn representing a function y=f(x)y=f(x), i.e., the ii-th number given is f(i)f(i).

Now Bob needs to give a function y=g(x)y=g(x) that is lexicographically as small as possible, such that for any ii, f(g(i))=g(f(i))f(g(i))=g(f(i)).

Input Format

The first line contains an integer nn. The second line contains nn integers, representing f(1),f(2)f(n)f(1), f(2) \cdots f(n) in order.

Output Format

Output one line containing nn integers, representing g(1),g(2)g(n)g(1), g(2) \cdots g(n) in order.

5
1 2 3 4 5
1 1 1 1 1
5
2 3 4 5 1
1 2 3 4 5

Hint

Sample Explanation Sample 1

  • g(f(1))=f(g(1))=1g(f(1))=f(g(1))=1.
  • g(f(2))=f(g(2))=1g(f(2))=f(g(2))=1.
  • g(f(3))=f(g(3))=1g(f(3))=f(g(3))=1.
  • g(f(4))=f(g(4))=1g(f(4))=f(g(4))=1.
  • g(f(5))=f(g(5))=1g(f(5))=f(g(5))=1.

Sample 2

  • g(f(1))=f(g(1))=2g(f(1))=f(g(1))=2.
  • g(f(2))=f(g(2))=3g(f(2))=f(g(2))=3.
  • g(f(3))=f(g(3))=4g(f(3))=f(g(3))=4.
  • g(f(4))=f(g(4))=5g(f(4))=f(g(4))=5.
  • g(f(5))=f(g(5))=1g(f(5))=f(g(5))=1.

Constraints

  • For 30%30\% of the testdata, n5n \le 5.
  • For 60%60\% of the testdata, n103n \le 10^3.
  • For 100%100\% of the testdata, 1n8×1051 \le n \le 8 \times 10^5.

Translated by ChatGPT 5