func_code_string: #include <bits/stdc++.h>   using namespace std;   const int oo = 0x3f3f3f3f;   const double eps = 1e-9;   vector<int> p, vg;   set<pair<int, int> > done;   bool cando(int i, int j) {     return done.find(make_pair(min(i, j), max(i, j))) == done.end();   }   int moves = 0;   void doswap(int i, int j) {     ++moves;     assert(i != j);     assert(min(i, j) >= 0 && max(i, j) < int((vg).size()));     assert(cando(i, j));     printf( %d %d n , min(i, j) + 1, max(i, j) + 1);     swap(p[i], p[j]);     swap(vg[i], vg[j]);     done.insert(make_pair(min(i, j), max(i, j)));   }   void brute_force(vector<int> pp) {     int N = int((pp).size());     vector<pair<int, int> > op;     vector<int> aim = pp;     sort((aim).begin(), (aim).end());     for (int i = (0); i < (N); i++)       for (int j = (0); j < (i); j++)         if (cando(i, j)) op.push_back(make_pair(i, j));     sort((op).begin(), (op).end());     do {       vector<int> tmp = pp;       for (auto it : op) {         swap(tmp[it.first], tmp[it.second]);       }       if (tmp == aim) {         for (auto it : op) doswap(it.first, it.second);         return;       }     } while (next_permutation((op).begin(), (op).end()));     cerr <<  EPIC FAIL n ;   }   int main() {     ios::sync_with_stdio(false);     int N;     cin >> N;     if (N == 1) {       cout <<  YES n ;       return 0;     }     if ((N * (N - 1)) % 4 != 0) {       cout <<  NO n ;       return 0;     }     printf( YES n );     p = vector<int>(N);     for (int i = (0); i < (N); i++) p[i] = i;     vg = p;     while (true) {       vector<int> ids;       for (int i = (0); i < (N); i++)         if (p[i] != -1) ids.push_back(i);       int S = int((ids).size());       if (S <= 1) break;       assert(ids[S - 1] == S - 1);       if (S <= 5) {         vector<int> tmp(S);         for (int i = (0); i < (S); i++) tmp[i] = p[i];         brute_force(tmp);         break;       }       vector<int> x(S - 1);       for (int i = (0); i < (S - 1); i++) x[i] = i;       random_shuffle((x).begin(), (x).end());       if (p[S - 1] == S - 1) {         bool ok = false;         while (!ok) {           int z1 = max((rand() % (S - 1)), rand() % (S - 1));           int z2 = max((rand() % (S - 1)), rand() % (S - 1));           if (z1 == z2) continue;           if (!cando(z1, S - 1) || !cando(z2, S - 1)) continue;           if (!cando(z1, z2)) continue;           ok = true;           doswap(z2, S - 1);           doswap(z2, z1);           for (auto i : x) {             if (i != z1 && i != z2 && cando(i, S - 1)) {               doswap(i, S - 1);             }           }           doswap(z1, S - 1);         }       } else {         int id_largest = -1;         for (int i = (0); i < (S); i++)           if (p[i] == S - 1) id_largest = i;         assert(id_largest != -1);         if (cando(id_largest, S - 1)) {           for (auto i : x) {             if (i != id_largest && cando(i, S - 1)) {               doswap(i, S - 1);             }           }           doswap(id_largest, S - 1);         } else {           int z = S - 2;           while (!cando(z, S - 1) || !cando(id_largest, z)) --z;           assert(z >= 0);           assert(z != id_largest);           doswap(id_largest, z);           for (auto i : x) {             if (i != z && cando(i, S - 1)) {               doswap(i, S - 1);             }           }           doswap(z, S - 1);         }       }       assert(p[S - 1] == S - 1);       p[S - 1] = -1;     }     assert(moves == (N * (N - 1)) / 2);     for (int i = (0); i < (N); i++) assert(vg[i] == i);     return 0;   }   