#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int x[n + 1], y[n + 1], z[n + 1];
  for (int i = 1; i <= n; ++i) cin >> x[i];
  memcpy(y, x, sizeof(x));
  memset(z, 0, sizeof(z));
  bool hasOne = false;
  bool hasTwo = false;
  bool allEven = true;
  vector<vector<int>> cycles;
  vector<int> cdd;
  {
    int i = 1;
    while (i <= n) {
      if (z[i])
        ++i;
      else {
        cdd.push_back(x[i]);
        z[x[i]] = 1;
        if (i != x[i])
          swap(x[i], x[x[i]]);
        else {
          ++i;
          cycles.push_back(cdd);
          cdd.clear();
        }
      }
    }
  }
  int one, two;
  for (int i = 0; i < cycles.size(); ++i) {
    if (cycles[i].size() == 1) {
      hasOne = true;
      one = i;
    }
    if (cycles[i].size() == 2) {
      hasTwo = true;
      two = i;
    }
    if (cycles[i].size() % 2) allEven = false;
  }
  if (hasOne) {
    cout << "YES" << endl;
    for (int i = 1; i <= n; ++i)
      if (i != cycles[one][0]) cout << cycles[one][0] << " " << i << endl;
  } else if (hasTwo && allEven) {
    cout << "YES" << endl;
    for (int i = 0; i < cycles.size(); ++i)
      if (i != two) {
        for (int j = 0; j < cycles[i].size(); ++j)
          cout << cycles[i][j] << " " << cycles[two][j % 2] << endl;
      }
    cout << cycles[two][0] << " " << cycles[two][1] << endl;
  } else
    cout << "NO" << endl;
  return 0;
}
