#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 1000 + 20;
int a[N], e[N], visited[N];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    e[i] = a[i];
  }
  int t = 0, o = 0, flag = 1;
  for (int i = 1; i <= n; i++) {
    if (i == e[i]) {
      t = e[i];
    }
    if (e[e[i]] == i) {
      o = i;
    }
    if (visited[i] == 0) {
      visited[i] = 1;
      int d = e[i], t = 1, p = 1;
      while (d != i) {
        visited[d] = 1;
        p++;
        d = e[d];
      }
      if (p % 2 == 1) {
        flag = 0;
      }
    }
  }
  fill(visited, visited + n + 1, 0);
  if (t != 0) {
    cout << "YES\n";
    for (int i = 1; i <= n; i++) {
      if (t != i) {
        cout << t << " " << i << "\n";
      }
    }
  } else if (o != 0 and flag == 1) {
    cout << "YES\n";
    int x = o;
    int y = e[o];
    cout << x << " " << y << "\n";
    for (int i = 1; i <= n; i++) {
      if (i != x and i != y and visited[i] == 0) {
        visited[i] = 1;
        cout << y << " " << i << "\n";
        int d = e[i], t = 1;
        while (d != i) {
          visited[d] = 1;
          if (t == 1) {
            cout << x << " " << d << "\n";
            t *= -1;
          } else {
            cout << y << " " << d << "\n";
            t *= -1;
          }
          d = e[d];
        }
      }
    }
  } else {
    cout << "NO";
  }
}

### Prompt

Your challenge is to write a Cpp solution to the following problem:

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.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 1000 + 20;
int a[N], e[N], visited[N];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    e[i] = a[i];
  }
  int t = 0, o = 0, flag = 1;
  for (int i = 1; i <= n; i++) {
    if (i == e[i]) {
      t = e[i];
    }
    if (e[e[i]] == i) {
      o = i;
    }
    if (visited[i] == 0) {
      visited[i] = 1;
      int d = e[i], t = 1, p = 1;
      while (d != i) {
        visited[d] = 1;
        p++;
        d = e[d];
      }
      if (p % 2 == 1) {
        flag = 0;
      }
    }
  }
  fill(visited, visited + n + 1, 0);
  if (t != 0) {
    cout << "YES\n";
    for (int i = 1; i <= n; i++) {
      if (t != i) {
        cout << t << " " << i << "\n";
      }
    }
  } else if (o != 0 and flag == 1) {
    cout << "YES\n";
    int x = o;
    int y = e[o];
    cout << x << " " << y << "\n";
    for (int i = 1; i <= n; i++) {
      if (i != x and i != y and visited[i] == 0) {
        visited[i] = 1;
        cout << y << " " << i << "\n";
        int d = e[i], t = 1;
        while (d != i) {
          visited[d] = 1;
          if (t == 1) {
            cout << x << " " << d << "\n";
            t *= -1;
          } else {
            cout << y << " " << d << "\n";
            t *= -1;
          }
          d = e[d];
        }
      }
    }
  } else {
    cout << "NO";
  }
}

```