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
input = sys.stdin.buffer.readline

def process(A):
    n = len(A)
    answer = []
    for i in range(n):
        ai = A[i]
        if ai==i+1:
            for j in range(n):
                if j != i:
                    answer.append([j+1, i+1])
            return ['YES', answer]    
    cycles = []
    seen = [0 for i in range(n+1)]
    I = 1
    while True:
        while seen[I]==1:
            I+=1
            if I==n+1:
                break
        if I==n+1:
            break
        cycle = [I]
        while True:
            ai = A[cycle[-1]-1]
            if ai != I:
                cycle.append(ai)
            else:
                break
        for c in cycle:
            seen[c] = 1
        if len(cycle) % 2==1:
            return ['NO', None]
        cycles.append(cycle)
    cycles = sorted(cycles, key=lambda a:len(a))
    if len(cycles[0]) != 2:
        return ['NO', None]
    a1, a2 = cycles[0]
    answer.append([a1, a2])
    m = len(cycles)
    for i in range(1, m):
        m2 = len(cycles[i])
        for j in range(0, m2, 2):
            A1 = cycles[i][j]
            A2 = cycles[i][j+1]
            answer.append([a1, A1])
            answer.append([a2, A2])
    return ['YES', answer]
            
        
    
    
    
    
n = int(input())
A = [int(x) for x in input().split()]
a1, a2 = process(A)
print(a1)
if a1=='YES':
    for x, y in a2:
        sys.stdout.write(f'{x} {y}\n')