#include #include using namespace std; using T = atcoder::fenwick_tree; int main() { int N; cin >> N; vector P(N), inv(N); vector C(N); for (int i = 0; i < N; ++i) cin >> P[i], --P[i]; for (int i = 0; i < N; ++i) inv[P[i]] = i; T t(N); for (int i = 0; i < N; ++i) { C[i] = t.sum(0, P[i]); t.add(P[i], 1); } int pre = N; // popped until pre int l = 0, r = N - 1; vector> arr; for (int p = N - 1; p >= 0; --p) { if (C[inv[p]] % 2 == 0) { if (max(l, inv[p]) > r) { if (p + 2 == pre) { cout << "No" << endl; return 0; } arr.emplace_back(p + 1, C[inv[p + 1]]); for (int x = pre - 1; x > p + 1; --x) arr.emplace_back(x, C[inv[x]] - C[inv[x]] % 2); pre = p; } else l = max(l, inv[p]); } else { if (l > min(inv[p], r)) { if (p + 2 == pre) { cout << "No" << endl; return 0; } arr.emplace_back(p + 1, C[inv[p + 1]]); for (int x = pre - 1; x > p + 1; --x) arr.emplace_back(x, C[inv[x]] - C[inv[x]] % 2); pre = p; } else r = min(r, inv[p]); } } reverse(arr.begin(), arr.end()); cout << "Yes" << endl; for (auto [a, b] : arr) cout << a + 1 << " " << b + 1 << endl; return 0; }