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]

win = ()
for i in range(n):
    if i == l[i]:
        win = (i,)
        break
    elif i == l[l[i]]:
        win = (i,l[i])
if win == ():
    print('NO')
elif len(win) == 1:
    print('YES')
    for i in l:
        if i != win[0]:
            print(i+1, win[0]+1)
elif len(win) == 2:
    ans = 'YES'
    edges = []
    used = []
    for i in range(n):
        if i not in win and i not in used:
            cyc = [i]
            used.append(i)
            t = l[i]
            while t != i:
                cyc.append(t)
                used.append(t)
                t = l[t]
            if len(cyc) % 2 == 1:
                ans = 'NO'
                break
            else:
                edges += [(win[k%2], cyc[k]) for k in range(len(cyc))]
    print(ans)
    if ans == 'YES':
        print(win[0]+1, win[1]+1)
        for e in edges:
            print(e[0]+1,e[1]+1)
