func_code_string: #include <bits/stdc++.h>   uint32_t readu32() {     int c;     while ((c = getchar()) <  0 )       ;     uint32_t n = c & 15U;     while ((c = getchar()) >=  0 ) n = n * 10 + (c & 15U);     return n;   }   uint64_t readu64() {     int c;     while ((c = getchar()) <  0 )       ;     uint64_t n = c & 15U;     while ((c = getchar()) >=  0 ) n = n * 10 + (c & 15U);     return n;   }   int32_t read32() {     int c;     while ((c = getchar()) <  - )       ;     bool neg = c ==  - ;     if (neg) c = getchar();     uint32_t n = c & 15U;     while ((c = getchar()) >=  0 ) n = n * 10 + (c & 15U);     return neg ? -(int32_t)n : n;   }   int64_t read64() {     int c;     while ((c = getchar()) <  - )       ;     bool neg = c ==  - ;     if (neg) c = getchar();     uint64_t n = c & 15;     while ((c = getchar()) >=  0 ) n = n * 10 + (c & 15U);     return neg ? -(int64_t)n : n;   }   using namespace std;   bool v[100005];   int p[100005];   int main() {     ios_base::sync_with_stdio(0);     int n = readu32();     for (int i = 1; i <= n; i++) p[i] = readu32();     int hub = 0, two = 0;     bool hasodd = 0;     for (int i = 1; i <= n; i++) {       if (v[i]) continue;       if (p[i] == i)         hub = i;       else if (p[p[i]] == i)         two = i;       else {         int j = i;         int cl = 0;         for (;;) {           v[j] = 1;           j = p[j];           cl++;           if (j == i) break;         }         if (cl & 1) hasodd = true;       }     }     if (!hub && (hasodd || !two)) {       cout <<  NO ;       return 0;     }     printf( YES n );     if (hub) {       for (int i = 1; i <= n; i++)         if (i != hub) printf( %d %d n , i, hub);     } else {       memset(v, 0, sizeof(v));       int par[] = {two, p[two]};       v[par[0]] = v[par[1]] = 1;       printf( %d %d n , par[0], par[1]);       for (int i = 1; i <= n; i++) {         if (v[i]) continue;         int j = i, pa = 0;         for (;; pa ^= 1) {           v[j] = 1;           printf( %d %d n , j, par[pa]);           j = p[j];           if (j == i) break;         }       }     }     return 0;   }   