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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long f = 1, x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + (s - '0');
    s = getchar();
  }
  return x * f;
}
const int jzm = 1000000007;
const int zxy = 998244353;
int n, m, i, j, s, o, k;
int U[100005], V[100005];
struct it {
  int v, w;
  it() { v = w = 0; }
  it(int V, int W) {
    v = V;
    w = W;
  }
};
vector<int> g[100005];
int dfn[100005], low[100005], cnt;
int bel[100005], v[100005];
stack<int> st;
void dfs(int x) {
  v[x] = 1;
  dfn[x] = low[x] = ++cnt;
  st.push(x);
  for (int i = 0; i < g[x].size(); i++) {
    int y = g[x][i];
    if (v[y] > 1) continue;
    if (!v[y]) {
      dfs(y);
      low[x] = min(low[x], low[y]);
    } else
      low[x] = min(low[x], dfn[y]);
  }
  if (low[x] == dfn[x]) {
    while (!st.empty() && v[x] < 2) {
      int t = st.top();
      st.pop();
      bel[t] = x;
      v[t] = 2;
    }
  }
  return;
}
int ind[100005];
int rt[100005], lf[100005], cn;
int fa[100005];
int findf(int x) { return x == fa[x] ? x : (fa[x] = findf(fa[x])); }
void unionSet(int a, int b) { fa[findf(a)] = findf(b); }
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    fa[i] = i;
    s = read();
    g[i].push_back(s);
    U[i] = i;
    V[i] = s;
  }
  for (int i = 1; i <= n; i++) {
    if (!v[i]) dfs(i);
  }
  for (int i = 1; i <= n; i++) {
    s = V[i];
    if (bel[i] != bel[s]) {
      unionSet(bel[i], bel[s]);
      ind[bel[s]]++;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (bel[i] == i && ind[i] == 0) {
      rt[++cn] = bel[i];
      lf[cn] = findf(bel[i]);
    }
  }
  if (cn == 1 && rt[1] == lf[1]) {
    printf("0\n");
    return 0;
  }
  rt[cn + 1] = rt[1];
  printf("%d\n", cn);
  for (int i = 1; i <= cn; i++) {
    printf("%d %d\n", lf[i], rt[i + 1]);
  }
  return 0;
}