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 = p1p2... pn, 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 pu and pv are connected by an edge".

You are given permutation p of size n. Find some tree size n, invariant relative to the given permutation.

Input

The first line contains number n (1 ≤ n ≤ 105) — the size of the permutation (also equal to the size of the sought tree).

The second line contains permutation pi (1 ≤ pi ≤ n).

Output

If the sought tree does not exist, print "NO" (without the quotes).

Otherwise, print "YES", and then print n - 1 lines, each of which contains two integers — the numbers of vertices connected by an edge of the tree you found. The vertices are numbered from 1, the order of the edges and the order of the vertices within the edges does not matter.

If there are multiple solutions, output any of them.

Examples

Input

4
4 3 2 1


Output

YES
4 1
4 2
1 3


Input

3
3 1 2


Output

NO

Note

In the first sample test a permutation transforms edge (4, 1) into edge (1, 4), edge (4, 2) into edge (1, 3) and edge (1, 3) into edge (4, 2). These edges all appear in the resulting tree.

It can be shown that in the second sample test no tree satisfies the given condition.
/**
 * Created by Andrew on 10.09.2015.
 */

import java.io.*;
import java.util.*;

public class B {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void solve() throws IOException {
        int n = readInt();
        int[] p = new int[n];
        for(int i = 0; i < n; i++) {
            p[i] = readInt()-1;
            if(p[i] == i) {
                out.println("YES");
                for(int j = 0; j < n; j++) {
                    if(i != j) {
                        out.println((i+1) + " " + (j+1));
                    }
                }
                return;
            }
        }

        List<Set<Integer>> comp = new ArrayList<Set<Integer>>();
        boolean[] used = new boolean[n];
        int first = -1;
        int second = -1;
        for(int i = 0; i < n; i++) {
            if(!used[i]) {
                TreeSet<Integer> cur = new TreeSet<Integer>();
                cur.add(i);
                int tmp = i;
                boolean ch = true;
                while (i != tmp || ch) {
                    ch = false;
                    used[tmp] = true;
                    cur.add(tmp);
                    tmp = p[tmp];
                }
                if(cur.size() % 2 != 0) {
                    out.println("NO");
                    return;
                }
                if(cur.size() == 2 && first == -1) {
                    first = cur.first();
                    second = cur.last();
                } else {
                    comp.add(cur);
                }
            }
        }

        if(first == -1) {
            out.println("NO");
            return;
        }

        out.println("YES");
        out.println((first+1) + " " + (second + 1));
        for(Set<Integer> x: comp) {
            int a = x.iterator().next();
            int tmp = a;
            boolean ch = true;
            while(a != tmp || ch) {
                ch = false;
                out.println((tmp+1) + " " + (first + 1));
                tmp = p[tmp];
                int z = first;
                first = second;
                second = z;
            }
        }
    }


    void init() throws FileNotFoundException {
        if (ONLINE_JUDGE) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    int[] readArr(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = readInt();
        }
        return res;
    }

    long[] readArrL(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = readLong();
        }
        return res;
    }

    public static void main(String[] args) {
        new B().run();
    }

    public void run() {
        try {
            long t1 = System.currentTimeMillis();
            init();
            solve();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }
}