#include <bits/stdc++.h>
#pragma GCC optimize("-O2")
using namespace std;
void err(istream_iterator<string> it) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << "\t";
  err(++it, args...);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& c, pair<T1, T2>& v) {
  c << "(" << v.first << "," << v.second << ")";
  return c;
}
template <template <class...> class TT, class... T>
ostream& operator<<(ostream& out, TT<T...>& c) {
  out << "{ ";
  for (auto& x : c) out << x << " ";
  out << "}";
  return out;
}
const int LIM = 1e5 + 5, MOD = 1e9 + 7;
int t, n, m, k, x, y, w;
using Permutation = vector<int>;
vector<vector<int> > decompose_cycles(Permutation p) {
  int cnt = 0;
  vector<vector<int> > dec;
  for (int i = 0; i < p.size(); i++) {
    if (p[i] != -1) {
      dec.push_back(vector<int>(0));
      auto& cur = dec[cnt];
      cnt++;
      for (int j = i; p[j] != -1;) {
        cur.push_back(p[j]);
        int next = p[j];
        p[j] = -1;
        j = next;
      }
    }
  }
  return dec;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  Permutation p;
  for (int i = 0; i < n; ++i) cin >> x, --x, p.push_back(x);
  auto dec = decompose_cycles(p);
  vector<int> odd, even;
  for (int j = 0; j < dec.size(); ++j) {
    if (dec[j].size() & 1)
      odd.push_back(j);
    else
      even.push_back(j);
  }
  for (int i = 0; i < dec.size(); ++i) {
    if (dec[i].size() == 1) {
      int g = dec[i][0];
      cout << "YES\n";
      for (int i = 0; i < n; ++i)
        if (i != g) cout << i + 1 << " " << g + 1 << '\n';
      exit(0);
    } else if (dec[i].size() == 2 and odd.size() == 0) {
      cout << "YES\n";
      cout << dec[i][0] + 1 << " " << dec[i][1] + 1 << '\n';
      for (auto& j : even) {
        if (j == i) continue;
        int ptr = 0;
        for (auto& it : dec[j]) {
          cout << dec[i][ptr] + 1 << " " << it + 1 << '\n';
          ptr ^= 1;
        }
      }
      exit(0);
    }
  }
  cout << "NO\n";
  return 0;
}
