Problem: To learn as soon as possible the latest news about their favourite fundamentally new operating system, BolgenOS community from Nizhni Tagil decided to develop a scheme. According to this scheme a community member, who is the first to learn the news, calls some other member, the latter, in his turn, calls some third member, and so on; i.e. a person with index i got a person with index fi, to whom he has to call, if he learns the news. With time BolgenOS community members understood that their scheme doesn't work sometimes — there were cases when some members didn't learn the news at all. Now they want to supplement the scheme: they add into the scheme some instructions of type (xi, yi), which mean that person xi has to call person yi as well. What is the minimum amount of instructions that they need to add so, that at the end everyone learns the news, no matter who is the first to learn it?

Input

The first input line contains number n (2 ≤ n ≤ 105) — amount of BolgenOS community members. The second line contains n space-separated integer numbers fi (1 ≤ fi ≤ n, i ≠ fi) — index of a person, to whom calls a person with index i.

Output

In the first line output one number — the minimum amount of instructions to add. Then output one of the possible variants to add these instructions into the scheme, one instruction in each line. If the solution is not unique, output any.

Examples

Input

3
3 3 2


Output

1
3 1


Input

7
2 3 1 3 4 4 1


Output

3
2 5
2 6
3 7

Solution (in JAVA):

Solution:
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import static java.lang.Math.*;

public class code0 {
    private static boolean oj = System.getProperty("ONLINE_JUDGE") != null;
    private static InputReader in;
    private static PrintWriter out;
    //////////////////////////////////////////////////////////
    private static int min(int... a){int min=a[0]; for(int i:a) min=Math.min(min, i); return min;}
    private static int max(int... a){int max=a[0]; for(int i:a) max=Math.max(max, i); return max;}
    private static long min(long... a){long min=a[0]; for(long i:a)min=Math.min(min, i); return min;}
    private static long max(long... a){long max=a[0]; for(long i:a)max=Math.max(max, i); return max;}
    private static String strm(String str, long m) {
        String ans = "";
        while(m > 0) {
            if ((m&1) == 1) ans = ans.concat(str);
            str = str.concat(str); m >>= 1;
        } return ans;
    }
    private static long mod(long a, long mod) {long res = a%mod; return res>=0 ? res : res+mod;}
    private static int mod(int a, int mod) {int res = a%mod; return res>=0 ? res : res+mod;}
    private static long modpow(long x, long n, long mod) {
        x = mod(x, mod);
        long res = 1;
        while (n > 0) {
            if ((n&1) == 1) res = mod(res*x, mod);
            x = mod(x*x, mod);
            n >>= 1;
        } return res;
    }
    private static long gcd(long a, long b) {return b == 0 ? Math.abs(a) : gcd(b, a % b);}
    private static int gcd(int a, int b) {return b == 0 ? Math.abs(a) : gcd(b, a % b);}
    private static long gcd(long... a) {long gcd=a[0]; for(long x:a) gcd=gcd(gcd, x); return gcd;}
    private static int gcd(int... a) {int gcd=a[0]; for(int x:a) gcd=gcd(gcd, x); return gcd;}
    private static long lcm(long a, long b) {return Math.abs(a / gcd(a, b) * b);}
    private static boolean isEven(int num) {return ((num&1) == 0);}
    private static boolean isOdd(int num) {return !isEven(num);}
    private static boolean isEven(long num) {return ((num&1) == 0);}
    private static boolean isOdd(long num) {return !isEven(num);}
    private static class Pair<T> {
        public T x, y;
        public Pair(T x, T y) {
            this.x = x;
            this.y = y;
        }
        @Override
        public boolean equals(Object obj) {
            if (obj == this) return true;
            if (!(obj instanceof Pair)) return false;
            Pair<T> pair = (Pair<T>)obj;
            return this.x == pair.x && this.y == pair.y;
        }
        @Override
        public String toString() {
            return ("(" + this.x + "," + this.y + ")");
        }
        @Override
        public int hashCode() {
            return (this.x+" "+this.y).hashCode();
        }
    }
    private static class Triplet<T> {
        public T x, y, z;
        public Triplet(T x, T y, T z) {
            this.x = x;
            this.y = y;
            this.z = z;
        }
        @Override
        public boolean equals(Object obj) {
            if (obj == this) return true;
            if (!(obj instanceof Triplet)) return false;
            Triplet<T> triplet = (Triplet<T>)obj;
            return this.x == triplet.x && this.y == triplet.y && this.z == triplet.z;
        }
        @Override
        public String toString() {
            return ("(" + this.x + "," + this.y + "," + this.z + ")");
        }
        @Override
        public int hashCode() {
            return (this.x+" "+this.y+" "+this.z).hashCode();
        }
    }
    //////////////////////////////////////////////////////////
    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar, numChars;
        public InputReader() {
            this.stream = System.in;
        }
        public InputReader(FileInputStream file) {
            this.stream = file;
        }
        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res = (res<<3) + (res<<1) + c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E') {
                    return res * Math.pow(10, nextInt());
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E') {
                        return res * Math.pow(10, nextInt());
                    }
                    if (c < '0' || c > '9') {
                        throw new InputMismatchException();
                    }
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res = (res<<3) + (res<<1) + c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }
        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }
        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }
    }
    //////////////////////////////////////////////////////////
    private static final int mod = 1_000_000_007;
    private ArrayList<Integer>[] graph;
    private int[] vis;
    private int dfs(int start) {
        vis[start] = 1;
        int x = graph[start].get(0);
        if (vis[x] != 1) return dfs(x);
        else return start;
    }
    private void solve() throws Exception {
        int n = in.nextInt();
        int[] inDegree = new int[n +1];
        vis = new int[n +1];
        graph = new ArrayList[n +1];
        for (int i = 0; i<= n; i++) graph[i] = new ArrayList<>();
        for (int i = 1; i<= n; i++) {
            int to = in.nextInt();
            inDegree[to]++;
            graph[i].add(to);
        }
        ArrayList<Pair<Integer>> al = new ArrayList<>();
        for (int i = 1; i<= n; i++) if (inDegree[i] == 0) al.add(new Pair<>(i, dfs(i)));
        for (int i = 1; i<= n; i++) if (vis[i] == 0) al.add(new Pair<>(i, dfs(i)));
        if (al.size() == 1) {
            int from = al.get(0).x, to = al.get(0).y;
            if (graph[to].get(0) == from) out.printf("%d\n", 0);
            else out.printf("%d\n%d %d\n", 1, to, from);
        } else {
            out.printf("%d\n", al.size());
            for (int i=0; i<al.size(); i++) {
                Pair p1 = al.get(i), p2 = al.get(mod((i+1), al.size()));
                out.printf("%d %d\n", p1.y, p2.x);
            }
        }
    }
    private void run() throws Exception {
//        in = new InputReader();
//        in = new InputReader(new FileInputStream("input.txt"));
//        out = new PrintWriter(new FileWriter("output.txt"));
        in = oj ? new InputReader() : new InputReader(new FileInputStream("/home/raiden/Desktop/input.txt"));
        out = new PrintWriter(System.out, false);
//        out = new PrintWriter(new FileWriter("/home/raiden/Desktop/output.txt"), false);
        long ti = System.currentTimeMillis();
        solve(); out.flush();
        if (!oj) System.out.println("\n"+(System.currentTimeMillis()-ti)+"ms");
    }
    public static void main(String[] args) throws Exception {new code0().run();}
}