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
#sys.stdin = open("in.txt")
try:
    while True:
        n = int(input())
        val = []
        pos = [0] + list(map(int, input().split(" ")))
        flag = True
        for i in range(1, n+1, 1):
            if i != pos[pos[i]] and pos[pos[i]] != -1:
                flag = False
            elif pos[i] != -1:
                val.append([i, pos[i]])
        if not flag:
            print("NO")
            continue
        tmp1 = val[0][0]
        tmp2 = val[0][1]
        print("YES")
        print(str(val[0][0])+" "+str(val[0][1]))
        for i in range(1, n//2, 1):
            print(str(tmp1)+" "+str(val[i][0]))
            print(str(tmp2)+" "+str(val[i][1]))
            tmp1 = val[i][0]
            tmp2 = val[i][1]
except EOFError:
    pass
