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*).
class Union:
    def __init__(self, n):
        self.p    = [i for i in range(n+1)]
        self.rank = [0] * (n+1) 
        
    def find(self, x):
        if self.p[x] != x:
            self.p[x] = self.find(self.p[x])
        return self.p[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x != y:
            if self.rank[x] < self.rank[y]:
                self.p[x]     = y
                self.rank[y] += self.rank[x]
            else:
                self.p[y]     = x
                self.rank[x] += self.rank[y]               
                
def solve(p, n):
    if n==1:
        return 'YES', []
    
    if n==2:
        return 'YES', ['1 2']
    
    # n >= 3
    U = Union(n)

    for i, x in enumerate(p):
        U.union(i+1, x)
    
    pos = {}
    arr = []
    
    for i, p in enumerate(U.p):
        if i == 0:
            continue
        
        if p not in pos:
            pos[p] = len(pos)
            arr.append([])
        arr[pos[p]].append(i)   
    
    if len(arr)==1:
        return False, None
        
    found=None
    all_2=True
        
    for a in arr:
        if len(a) != 2:
            all_2=False
            
        if len(a) == 1:
            found=a[0]
            
    if found is not None:
        ans=[]
        for i in range(1, n+1):
            if i==found:
                continue
            ans.append(str(found)+' '+str(i))
        return True, ans
    
    if all_2==True:
        ans=[str(arr[0][0])+' '+str(arr[0][1])]
        for a, b in zip(arr[:-1], arr[1:]):
            ans.append(str(a[0])+' '+str(b[0]))
            ans.append(str(a[1])+' '+str(b[1]))
        return True, ans
    return False, None

n = int(input())
p = list(map(int, input().split()))
flg, ans = solve(p, n)

if flg==True:
    print('YES')
    print('\n'.join(ans))
else:
    print('NO')