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:
//package codeforces.br22;

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

/**
 * User: Kandy
 * Date: 29.06.2010
 * Time: 22:35:21
 */
public class ProblemE {

    int[] p;
    int[] rank;

    private int findSet(int i) {
        if (i != p[i]) {
            p[i] = findSet(p[i]);
        }
        return p[i];
    }

    private void merge(int i, int j) {
        int s1, s2;
        s1 = findSet(i);
        s2 = findSet(j);
        if (rank[s1] < rank[s2]) {
            p[s1] = s2;
        } else if (rank[s1] > rank[s2]) {
            p[s2] = s1;
        } else {
            p[s2] = s1;
            rank[s1]++;
        }
    }

    private class Interval {
        public int l, r;
    }

    public void solve() {
        boolean oj = true;

        try {
            Reader reader = oj ? new InputStreamReader(System.in) : new FileReader("E.in");
            Writer writer = oj ? new OutputStreamWriter(System.out) : new FileWriter("E.out");
            BufferedReader br = new BufferedReader(reader);
            StreamTokenizer st = new StreamTokenizer(reader);
            PrintWriter out = new PrintWriter(writer);

            MyTokenizer tok = new MyTokenizer(br.readLine());
            int n = (int) tok.getNum();
            int[] g = new int[n];
            p = new int[n];
            rank = new int[n];
            int[] inp = new int[n];
            tok = new MyTokenizer(br.readLine());
            for (int i = 0; i < n; i++) {
                g[i] = (int) tok.getNum() - 1;
                p[i] = i;
                rank[i] = 1;
                inp[g[i]]++;
            }
            for (int i = 0; i < n; i++) {
                merge(i, g[i]);
            }


            int[] ss = new int[n];
            for (int i = 0; i < n; i++) {
                ss[i] = -1;
            }
            int setc = 0;
            List<Integer> sets = new ArrayList<Integer>();
            for (int i = 0; i < n; i++) {
                int s = findSet(i);
                if (ss[s] == -1) {
                    setc++;
                    ss[s] = 0;
                    sets.add(s);
                }
            }

            int[] stok = new int[n];
            for (int i = 0; i < n; i++)
                stok[i] = -1;
            boolean[] used = new boolean[n];

            for (int i = 0; i < sets.size(); i++) {
                int s = sets.get(i);

                int cur = s;
                while (!used[cur]) {
                    used[cur] = true;
                    cur = g[cur];
                }
                stok[s] = cur;
            }

            Map<Integer, ArrayList<Integer>> map = new HashMap<Integer, ArrayList<Integer>>();
            for (int i = 0; i < sets.size(); i++) {
                map.put(sets.get(i), new ArrayList<Integer>());
            }
            for (int i = 0; i < n; i++)
                if (inp[i] == 0) {
                    int s = findSet(i);
                    ArrayList<Integer> arr = map.get(s);
                    arr.add(i);
                }

            for (Map.Entry<Integer, ArrayList<Integer>> entry : map.entrySet()) {
                if (entry.getValue().size() == 0) {
                    entry.getValue().add(entry.getKey());
                }
            }

            int anystock = -1;
            List<Interval> list = new ArrayList<Interval>();
            for (int i = 0; i < sets.size(); i++) {
                int next = (i + 1) % sets.size();
                int f1 = stok[sets.get(i)];
                anystock = f1;

                int f2 = map.get(sets.get(next)).get(0);
                int k = map.get(sets.get(next)).remove(0);
                Interval t = new Interval();
                t.l = f1;
                t.r = f2;
                if (t.l != t.r)
                    list.add(t);
            }
            for (Map.Entry<Integer, ArrayList<Integer>> entry : map.entrySet()) {
                if (entry.getValue().size() > 0) {
                    for (int i = 0; i < entry.getValue().size(); i++) {
                        Interval t = new Interval();
                        t.l = anystock;
                        t.r = entry.getValue().get(i);
                        if (t.l != t.r)
                            list.add(t);
                    }
                }
            }
            out.printf("%d", list.size());

            for (int i = 0; i < list.size(); i++) {
                out.printf("\n");
                out.printf("%d %d", list.get(i).l + 1, list.get(i).r + 1);
            }

            /*
            out.printf("\n%d\n", 100000);
            for(int i=0;i<100000;i++) {
                int next = (i + 1) % 100000;
                out.printf("%d ", next + 1);
            }
            */

            br.close();
            out.close();
            reader.close();
            writer.close();
        }
        catch (Exception ex) {
            ex.printStackTrace();
        }
        finally {
        }
    }


    public static void main(String[] args) {
        ProblemE f = new ProblemE();
        f.solve();
    }

    private class MyTokenizer {
        private String s;
        private int cur;

        public MyTokenizer(String s) {
            this.s = s;
            cur = 0;
        }

        public void skip() {
            while (cur < s.length() && (s.charAt(cur) == ' ' || s.charAt(cur) == '\n')) {
                cur++;
            }
        }

        public double getNum() {
            skip();
            String snum = "";
            while (cur < s.length() && (s.charAt(cur) >= '0' && s.charAt(cur) <= '9' || s.charAt(cur) == '.' || s.charAt(cur) == '-')) {
                snum += s.charAt(cur);
                cur++;
            }
            return Double.valueOf(snum);
        }

        public String getString() {
            skip();
            String s2 = "";
            while (cur < s.length() && (((s.charAt(cur) >= 'a' && s.charAt(cur) <= 'z')) || ((s.charAt(cur) >= 'A' && s.charAt(cur) <= 'Z')))) {
                s2 += s.charAt(cur);
                cur++;
            }
            return s2;
        }

        public char getCurrentChar() throws Exception {
            if (cur < s.length())
                return s.charAt(cur);
            else
                throw new Exception("Current character out of string length");
        }

        public void moveNextChar() {
            if (cur < s.length())
                cur++;
        }

        public boolean isFinished() {
            return cur >= s.length();
        }
    }
}