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*).
def read_data():
    n = int(input())
    ps = list(map(int, input().split()))
    return n, ps

def solve(n, ps):
    ps = [p - 1 for p in ps]
    cycles = [0] * n
    roots = []
    has_odd_cycle = False
    for i in range(n):
        if cycles[i] > 0:
            continue
        q = ps[i]
        cycle = 1
        while q != i:
            cycle += 1
            q = ps[q]
        if cycle & 1:
            has_odd_cycle = True
        cycles[i] = cycle
        roots.append(i)
        q = ps[i]
        while q != i:
            cycles[q] = cycle
            q = ps[q]
    mincycle = min(cycles)
    if mincycle > 2:
        return False, []
    if mincycle == 1:
        p = cycles.index(1)
        return True, [(p, i) for i in range(n) if i != p]
    if has_odd_cycle:
        return False, []
    p = cycles.index(2)
    q = ps[p]
    edges = [(p, q)]
    for root in roots:
        if root == p or root == q:
            continue
        edges.append((p, root))
        r = ps[root]
        edges.append((q, r))
        r = ps[r]
        while r != root:
            edges.append((p, r))
            r = ps[r]
            edges.append((q, r))
            r = ps[r]
    return True, edges

n, ps = read_data()
is_possible, edges = solve(n, ps)
if is_possible:
    print('YES')
    for a, b in edges:
        print(a + 1, b + 1)
else:
    print('NO')