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.
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int INF = 100000000;
const int mod = 1000 * 1000 * 1000 + 7;
const double PI = 3.1415926535897932;
double sqr(double first) { return first * first; };
long double sqr(long double first) { return first * first; };
long long sqr(long long first) { return first * first; };
long long sqr(int first) { return first * 1LL * first; };
long long bpm(long long a, long long n = -2, long long m = mod) {
  n = n >= 0 ? n : m + n;
  long long r = 1;
  while (n) {
    if (n & 1) r = (r * a) % m;
    a = (a * a) % m;
    n >>= 1;
  }
  return r;
}
const int N = 100002;
int p[N], u[N];
vector<int> c[N];
int main(int argc, char* argv[]) {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
  int ch = 0;
  for (int i = 1; i <= n; i++)
    if (!u[i]) {
      for (int first = p[i]; !u[first]; first = p[first])
        u[first] = true, c[ch].push_back(first);
      ch++;
    }
  sort(c, c + ch, [](const vector<int>& a, const vector<int>& b) {
    return a.size() < b.size();
  });
  if (c[0].size() == 1) {
    cout << "YES\n";
    int first = c[0][0];
    for (int i = 1; i <= n; i++)
      if (i != first) cout << first << " " << i << "\n";
    return 0;
  } else if (c[0].size() == 2) {
    bool second = false;
    for (int i = 0; i < ch; i++) second |= c[i].size() % 2;
    if (!second) {
      cout << "YES\n";
      int f = c[0][0], s = c[0][1];
      cout << f << " " << s << endl;
      for (int i = 0; i < ch; i++)
        for (int first : c[i])
          if (first != f && first != s) {
            cout << f << " " << first << endl;
            swap(f, s);
          }
      return 0;
    }
  }
  cout << "NO\n";
  return 0;
}
