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*).
import sys
readline = sys.stdin.readline

N = int(readline())
P = list(map(lambda x: int(x)-1, readline().split()))

PP = []
used = set()
for i in range(N):
    if i not in used:
        res = []
        while i not in used:
            used.add(i)
            res.append(i)
            i = P[i]
        PP.append(res)

if any(len(p) == 1 for p in PP):
    print('YES')
    for p in PP:
        if len(p) == 1:
            break
    d = p[0]
    Ans = []
    for i in range(N):
        if i != d:
            Ans.append('{} {}'.format(i+1, d+1))
    print('\n'.join(Ans))
elif not any(len(p) == 2 for p in PP):
    print('NO')

elif any(len(p) & 1 for p in PP):
    print('NO')
else:
    print('YES')
    dd = None
    for p in PP:
        if len(p) == 2:
            dd = p
            PP.remove(p)
            break
    d1, d2 = dd

    Ans = ['{} {}'.format(d1+1, d2+1)]
    for p in PP:
        for i in range(len(p)):
            if i&1:
                Ans.append('{} {}'.format(d1+1, p[i]+1))
            else:
                Ans.append('{} {}'.format(d2+1, p[i]+1))
    print('\n'.join(Ans))
            
            