A tree of size *n* is an undirected connected graph consisting of *n* vertices without cycles.

Consider some tree with *n* vertices. We call a tree invariant relative to permutation *p* = *p*<sub class="lower-index">1</sub>*p*<sub class="lower-index">2</sub>... *p*<sub class="lower-index">*n*</sub>, if for any two vertices of the tree *u* and *v* the condition holds: "vertices *u* and *v* are connected by an edge if and only if vertices *p*<sub class="lower-index">*u*</sub> and *p*<sub class="lower-index">*v*</sub> are connected by an edge".

You are given permutation *p* of size *n*. Find some tree size *n*, invariant relative to the given permutation.
The first line contains number *n* (1 ≤ *n* ≤ 10<sup class="upper-index">5</sup>) — the size of the permutation (also equal to the size of the sought tree).

The second line contains permutation *p*<sub class="lower-index">*i*</sub> (1 ≤ *p*<sub class="lower-index">*i*</sub> ≤ *n*).
n = int(input())
s = input().split(' ')
l = [int(i)-1 for i in s]

cycles = []
used = []
for i in range(n):
    if i not in used:
        z = [i+1]
        t = l[i]
        used.append(i)
        while t != i:
            z.append(t+1)
            used.append(t)
            t = l[t]
        cycles.append(z)
cycles.sort(key = lambda x: len(x))

lc = len(cycles)
lens = [len(i) for i in cycles]
ans = 'YES'
if lens[0] > 2:
    ans = 'NO'
for i in range(lc-1):
    if lens[i+1] % lens[i] != 0:
        ans = 'NO'

print(ans)

if ans == 'YES':
    if lens[0] == 2:
        print(cycles[0][0], cycles[0][1])
    for i in range(lc-1):
        for k in range(lens[i+1]):
            print(cycles[i][k % lens[i]], cycles[i+1][k])
