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 = list(map(lambda x: int(x) - 1, input().split()))
p = q = -1
for i in range(n):
  if a[a[i]] == i:
    p, q = i, a[i]        
  if a[i] == i:
    print('YES')
    [print(i + 1, j + 1) for j in range(n) if i != j]
    exit()
if p < 0 or q < 0:
  print('NO')
  exit()
r = [(p, q)]
v = [0] * n
v[p] = v[q] = 1
for i in range(n):
  if not v[i]:
    r.append((p, i))
    v[i] = 1
    t = 0
    x = a[i]
    while x != i:
      r.append((p if t else q, x))
      v[x] = 1
      t = 1 - t
      x = a[x]
    if not t:
      print('NO')
      exit()
print('YES')
[print(x + 1, y + 1) for x, y in r]