func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, arr[1042], cc[1042];   vector<pair<int, int> > path;   vector<pair<int, int> > ans;   map<pair<long long, long long>, pair<int, int> > m;   long long base = 1031, mod = 1000000007LL, mod2 = 1000000009LL;   long long pows[1042] = {1};   pair<long long, long long> h(int a[]) {     long long ret = 0, ret2 = 0;     for (int i = 0; i < n; i++) {       ret *= base;       ret2 *= base;       ret += a[i];       ret2 += a[i];       ret %= mod;       ret2 %= mod2;     }     return make_pair(ret, ret2);   }   bool ok() {     if (m.find(h(arr)) != m.end()) {       return 1;     }     return 0;     for (int i = 1; i <= n; i++) {       if (arr[i - 1] != i) {         return 0;       }     }     return 1;   }   bool f = 0;   void get(int ck) {     if (ans.size()) {       return;     }     if (ck == 2) {       if (ok()) {         ans = path;         ans.push_back(m[h(arr)]);       }       return;     }     for (int s = 0; s < n; s++) {       if (s != 0 && abs(arr[s] - arr[s - 1]) == 1 && s != 1 &&           abs(arr[s - 2] - arr[s - 1]) == 1) {         continue;       }       for (int f = s; f < n; f++) {         if (f != n - 1 && abs(arr[f] - arr[f + 1]) == 1 && f != n - 2 &&             abs(arr[f + 1] - arr[f + 2]) == 1) {           continue;         }         path.push_back(make_pair(s, f));         reverse(arr + s, arr + f + 1);         get(ck + 1);         reverse(arr + s, arr + f + 1);         path.pop_back();         if (ans.size()) {           return;         }       }     }   }   long long ss[1042], ff[1042], revHs[1042][1042];   long long ss2[1042], ff2[1042], revHs2[1042][1042];   long long pows2[1042];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     pows[0] = 1;     pows2[0] = 1;     for (int i = 1; i <= n; i++) {       pows[i] = pows[i - 1] * base % mod;       pows2[i] = pows2[i - 1] * base % mod2;     }     for (int i = 0; i < n; i++) {       cin >> arr[i];       cc[i] = i + 1;     }     ss[0] = 0;     ss2[0] = 0;     for (int i = 1; i <= n; i++) {       ss[i] = ss[i - 1] + i * pows[n - i];       ss2[i] = ss2[i - 1] + i * pows2[n - i];       ss[i] %= mod;       ss2[i] %= mod2;     }     ff[n - 1] = 0;     ff2[n - 1] = 0;     for (int i = n - 2; i >= 0; i--) {       ff[i] = ff[i + 1] + (i + 2) * pows[n - i - 2];       ff2[i] = ff2[i + 1] + (i + 2) * pows2[n - i - 2];       ff[i] %= mod;       ff2[i] %= mod2;     }     for (int s = 0; s < n; s++) {       revHs[s][s] = s + 1;       revHs2[s][s] = s + 1;       for (int f = s + 1; f < n; f++) {         revHs[s][f] = revHs[s][f - 1] + (f + 1) * pows[f - s];         revHs2[s][f] = revHs2[s][f - 1] + (f + 1) * pows2[f - s];         revHs[s][f] %= mod;         revHs2[s][f] %= mod2;       }     }     for (int s = 0; s < n; s++) {       for (int f = s; f < n; f++) {         long long c = ss[s] + revHs[s][f] * pows[n - f - 1] + ff[f];         long long c2 = ss2[s] + revHs2[s][f] * pows2[n - f - 1] + ff2[f];         c %= mod;         c2 %= mod2;         m[make_pair(c, c2)] = make_pair(s, f);       }     }     get(0);     reverse(ans.begin(), ans.end());     path = ans;     int kk = 0;     for (int j = 0; j < path.size(); j++) {       if (path[j].first == path[j].second) {         continue;       }       kk++;     }     cout << kk <<   n ;     for (int j = 0; j < path.size(); j++) {       if (path[j].first == path[j].second) {         continue;       }       cout << path[j].first + 1 <<     << path[j].second + 1 <<   n ;     }     return 0;   }   