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())
a = [0] + list(map(int, input().split()))
vis = [False] * (n + 1)
lp = []
for i in range(1, n + 1):
    if vis[i]:
        continue
    cur = i
    q = []
    while not vis[cur]:
        vis[cur] = True
        q.append(cur)
        cur = a[cur]
    lp.append(q)
lp.sort(key=len)
res = []
def solve2():
    res.append(tuple(lp[0]))
    for q in lp[1:]:
        if len(q) % 2 == 1:
            print('NO')
            exit()
        for i in range(len(q)):
            res.append((lp[0][i % 2], q[i]))
def solve1():
    for i in range(1, n + 1):
        if i == lp[0][0]:
            continue
        res.append((lp[0][0], i))
if len(lp[0]) >= 3:
    print('NO')
    exit()
if len(lp[0]) >= 2:
    solve2()
else:
    solve1()
print('YES')
for u, v in res:
    print(u, v)