malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, m, notFind;   vector<pair<int, int>> edge[100001];   vector<int> ans[2], e[2];   int vis[100001];   void DFS(int u, int c, int vit) {     vis[u] = c;     e[c].push_back(u);     for (auto k : edge[u]) {       int v, col, nextCol;       tie(v, col) = k;       col = (col + c) % 2;       nextCol = col == vit ? 0 : 1;       if (vis[v] != -1) {         if (vis[v] != nextCol) notFind = 1;         continue;       }       DFS(v, nextCol, vit);     }   }   bool solve(int vit) {     memset(vis, -1, sizeof(vis));     notFind = 0;     for (int i = 1; i <= n; ++i) {       if (vis[i] != -1) continue;       e[0].clear();       e[1].clear();       DFS(i, 0, vit);       if (notFind) return 0;       if (e[0].size() > e[1].size()) swap(e[0], e[1]);       for (auto j : e[0]) ans[vit].push_back(j);     }     return 1;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < m; ++i) {       int u, v;       char chr;       cin >> u >> v >> chr;       edge[u].push_back({v, chr ==  R });       edge[v].push_back({u, chr ==  R });     }     bool n1, n2;     int id = 0;     n1 = solve(0);     n2 = solve(1);     if (!n1 && !n2) return cout <<  -1 , 0;     if (!n1 || n1 && n2 && ans[0].size() > ans[1].size()) id = 1;     cout << ans[id].size() <<   n ;     for (auto k : ans[id]) cout << k <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> v[100];   int n;   long long tmp;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int cnt = 0;       scanf( %I64d , &tmp);       while (tmp % 2 == 0) {         tmp >>= 1;         cnt++;       }       v[cnt].push_back(tmp);     }     tmp = 0;     for (int i = 1; i <= 64; i++)       if (v[i].size() > v[tmp].size()) tmp = i;     printf( %d n , n - v[tmp].size());     for (int i = 0; i <= 64; i++) {       if (i == tmp) continue;       for (int j = 0; j < v[i].size(); j++) printf( %I64d  , v[i][j] << i);     }   }
#include <bits/stdc++.h>   using namespace std;   int N;   int X[6060], Y[6060];   long long C[4][4];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin.exceptions(ios::badbit | ios::failbit);     cin >> N;     for (int i = 1; i <= N; i++) cin >> X[i] >> Y[i];     long long res = 0;     for (int i = 1; i <= N; i++) C[X[i] % 4][Y[i] % 4]++;     res += C[0][0] * (C[0][0] - 1) * (C[0][0] - 2) / 6;     res += C[0][2] * (C[0][2] - 1) * (C[0][2] - 2) / 6;     res += C[2][0] * (C[2][0] - 1) * (C[2][0] - 2) / 6;     res += C[2][2] * (C[2][2] - 1) * (C[2][2] - 2) / 6;     for (int i = 1; i <= N; i++)       for (int j = i + 1; j <= N; j++) {         if (X[i] % 4 == X[j] % 4 && Y[i] % 4 == Y[j] % 4) {           int x = X[i] % 4, y = Y[i] % 4;           for (int nx = 0; nx < 4; nx += 2)             for (int ny = 0; ny < 4; ny += 2) {               if (nx == x && ny == y) continue;               res += C[nx][ny];             }         }       }     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000 * 2 + 5;   const int maxd = 25;   long long d[maxn], h[maxn], s[maxn], f[maxn], g[maxn];   int f_fst[maxd][maxn], f_snd[maxd][maxn], g_fst[maxd][maxn], g_snd[maxd][maxn];   void GetMax(long long a[], int &r0, int &r1, int x0, int x1, int y0, int y1) {     if (a[x0] > a[y0]) {       r0 = x0;       r1 = x1 != x0 && a[x1] > a[y0] ? x1 : y0;     } else if (a[x0] < a[y0]) {       r0 = y0;       r1 = y1 != y0 && a[y1] > a[x0] ? y1 : x0;     } else {       r0 = x0;       if (x0 == y0)         r1 = a[x1] > a[y1] ? x1 : y1;       else         r1 = y0;     }   }   void BuildRMQ(long long a[maxn], int fst[][maxn], int snd[][maxn], int n) {     for (int k = 0; (1 << k) <= n; k++)       for (int i = 1; i + (1 << k) - 1 <= n; i++)         if (k == 0)           fst[k][i] = snd[k][i] = i;         else {           int j = i + (1 << k - 1);           GetMax(a, fst[k][i], snd[k][i], fst[k - 1][i], snd[k - 1][i],                  fst[k - 1][j], snd[k - 1][j]);         }   }   pair<int, int> QueryRMQ(long long a[maxn], int fst[][maxn], int snd[][maxn],                           int n, int x, int y) {     for (int k = maxd - 1; k >= 0; k--)       if ((y - x + 1) >> k) {         int i = x, j = y - (1 << k) + 1;         pair<int, int> ret;         GetMax(a, ret.first, ret.second, fst[k][i], snd[k][i], fst[k][j],                snd[k][j]);         return ret;       }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %I64d , &d[i]);       s[i + 1] = s[i] + d[i];     }     for (int i = 1; i <= n; i++) {       scanf( %I64d , &h[i]);       h[i + n] = h[i];       s[i + n + 1] = s[i + n] + d[i];     }     for (int i = 1; i <= n * 2; i++) {       f[i] = h[i] * 2LL - s[i];       g[i] = h[i] * 2LL + s[i];     }     BuildRMQ(f, f_fst, f_snd, n * 2);     BuildRMQ(g, g_fst, g_snd, n * 2);     for (int i = 0; i < m; i++) {       int ai, bi;       scanf( %d%d , &ai, &bi);       if (ai <= bi) ai += n;       bi++;       ai--;       pair<int, int> fmax = QueryRMQ(f, f_fst, f_snd, n * 2, bi, ai);       pair<int, int> gmax = QueryRMQ(g, g_fst, g_snd, n * 2, bi, ai);       long long ans;       if (fmax.first != gmax.first)         ans = f[fmax.first] + g[gmax.first];       else         ans = max(f[fmax.first] + g[gmax.second], f[fmax.second] + g[gmax.first]);       printf( %I64d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int res = INT_MAX;   int i, j;   int n, d;   int a[2018];   int main() {     cin >> n >> d;     for (int x = 0; x < n; x++) cin >> a[x];     sort(a, a + n);     for (i = 0; i < n; i++)       for (j = n - 1; j >= i; j--) {         if (a[j] - a[i] <= d) {           res = min(res, n - j + i - 1);           break;         }       }     return !printf( %d , res);   }
#include <bits/stdc++.h>   using namespace std;   long long int mod = 1e9 + 7;   long long int exp(long long int t, long long int x) {     if (x == 0) return 1;     if (x == 1) return t;     if (x % 2 == 1) return (t * exp((t * t) % mod, x / 2)) % mod;     if (x % 2 == 0) return exp((t * t) % mod, x / 2);   }   long long int gcd(long long int x, long long int y) {     return x % y == 0 ? y : gcd(y, x % y);   }   long long int lcm(long long int x, long long int y) {     return x * (y / gcd(x, y));   }   long long int bsum(long long int u, long long int b) {     return u < b ? u : bsum(u / b, b) + u % b;   }   long long int prival(long long int u, long long int p) {     int cn = 0;     while (u % p == 0) {       cn++;       u = u / p;     }     return cn;   }   bool isprime(long long int x) {     for (long long int i = 2; i * i <= x; i++) {       if (x % i == 0) {         return false;       }     }     return true;   }   void YAY(void) { cout <<  YES  << endl; }   void NAY(void) { cout <<  NO  << endl; }   struct var {     string id;     string val;     int def;     int V1, V2;     string OP;   } num[5111];   int temp[5111];   map<string, int> go;   string mmin, mmax;   int n, m;   int getbit(int loc, int b) {     int i;     int ret = 0;     for (i = 1; i <= n; i++) {       temp[i] = 0;     }     for (i = 1; i <= n; i++) {       if (num[i].def == 0) {         ret += num[i].val[loc] -  0 ;         temp[i] = num[i].val[loc] -  0 ;       } else {         int u, v;         if (num[i].V1 == 0) {           u = b;         } else if (num[i].V1 != 0) {           u = temp[num[i].V1];         }         if (num[i].V2 == 0) {           v = b;         } else if (num[i].V2 != 0) {           v = temp[num[i].V2];         }         if (num[i].OP ==  XOR ) {           ret += u ^ v;           temp[i] = u ^ v;         } else if (num[i].OP ==  OR ) {           ret += u | v;           temp[i] = u | v;         } else if (num[i].OP ==  AND ) {           ret += u & v;           temp[i] = u & v;         }       }     }     for (i = 1; i <= n; i++) {       temp[i] = 0;     }     return ret;   }   int main(void) {     int i, j;     cin >> n >> m;     for (i = 1; i <= n; i++) {       string s, trash, num1;       cin >> s >> trash >> num1;       go[s] = i;       num[i].id = s;       if (num1[0] ==  0  || num1[0] ==  1 ) {         num[i].def = 0;         num[i].val = num1;       } else {         num[i].def = 1;         if (num1[0] ==  ? ) {           num[i].V1 = 0;         } else {           num[i].V1 = go[num1];         }         string op, num2;         cin >> op >> num2;         num[i].OP = op;         if (num2[0] ==  ? ) {           num[i].V2 = 0;         } else {           num[i].V2 = go[num2];         }       }     }     for (i = 0; i <= m - 1; i++) {       int X = getbit(i, 0);       int Y = getbit(i, 1);       if (X > Y) {         mmin.push_back( 1 );         mmax.push_back( 0 );       } else if (X < Y) {         mmin.push_back( 0 );         mmax.push_back( 1 );       } else if (X == Y) {         mmin.push_back( 0 );         mmax.push_back( 0 );       }     }     cout << mmin << endl << mmax;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 150009;   long long a[N];   long long b[N], n, m, h;   struct Tree {     long long l, r;     long long ly, mi;   } t[N << 2];   void build_tree(long long p, long long l, long long r) {     t[p].l = l, t[p].r = r;     if (l == r) {       t[p].mi = l - m - 1;       t[p].ly = 0;       return;     }     build_tree((p << 1), l, ((t[p].l + t[p].r) >> 1));     build_tree(((p << 1) | 1), ((t[p].l + t[p].r) >> 1) + 1, r);     t[p].mi = min(t[(p << 1)].mi, t[((p << 1) | 1)].mi);   }   void push_down(long long p) {     if (t[p].ly) {       t[(p << 1)].ly += t[p].ly;       t[((p << 1) | 1)].ly += t[p].ly;       t[(p << 1)].mi += t[p].ly;       t[((p << 1) | 1)].mi += t[p].ly;       t[p].ly = 0;     }   }   void modify(long long p, long long l, long long r, long long v) {     if (t[p].l == l && t[p].r == r) {       t[p].mi += v;       t[p].ly += v;       return;     }     push_down(p);     if (r <= ((t[p].l + t[p].r) >> 1))       modify((p << 1), l, r, v);     else if (l > ((t[p].l + t[p].r) >> 1))       modify(((p << 1) | 1), l, r, v);     else {       modify((p << 1), l, ((t[p].l + t[p].r) >> 1), v);       modify(((p << 1) | 1), ((t[p].l + t[p].r) >> 1) + 1, r, v);     }     t[p].mi = min(t[(p << 1)].mi, t[((p << 1) | 1)].mi);   }   long long query(long long p, long long l, long long r) {     if (t[p].l == l && t[p].r == r) {       return t[p].mi;     }     push_down(p);     if (r <= ((t[p].l + t[p].r) >> 1))       return query((p << 1), l, r);     else if (l > ((t[p].l + t[p].r) >> 1))       return query(((p << 1) | 1), l, r);     else       return min(query((p << 1), l, ((t[p].l + t[p].r) >> 1)),                  query(((p << 1) | 1), ((t[p].l + t[p].r) >> 1) + 1, r));   }   long long cal(long long x) {     long long s = 1, t = m;     while (s <= t) {       long long i = (s + t) >> 1;       if (b[i] > x)         t = i - 1;       else         s = i + 1;     }     return t;   }   long long p[N];   int main() {     cin >> n >> m >> h;     for (long long i = 1; i <= m; i++) cin >> b[i], b[i] = h - b[i];     sort(b + 1, b + m + 1);     build_tree(1, 1, m);     for (long long i = 0; i < m; i++) {       long long v;       cin >> v;       p[i] = cal(v);       if (p[i]) modify(1, 1, p[i], 1);     }     long long ans = (query(1, 1, m) >= 0);     for (long long i = m; i < n; i++) {       long long v;       cin >> v;       p[i] = cal(v);       if (p[i]) modify(1, 1, p[i], 1);       if (p[i - m]) modify(1, 1, p[i - m], -1);       ans += (query(1, 1, m) >= 0);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n;   map<int, pair<int, int> > m;   int main() {     scanf( %i , &n);     for (int i = 0; i < n; i++) {       int a, b;       scanf( %i%i , &a, &b);       if (m.find(a) == m.end())         m[a] = make_pair(1, 0);       else         m[a].first += 1;       if (b != a)         if (m.find(b) == m.end())           m[b] = make_pair(0, 1);         else           m[b].second += 1;     }     int ans = 1e9;     for (map<int, pair<int, int> >::iterator it = m.begin(); it != m.end(); it++)       if (it->second.first + it->second.second >= (n + 1) / 2)         ans = min(ans, max(0, (n + 1) / 2 - it->second.first));     if (ans == 1e9)       cout << -1;     else       cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int arr[30] = {}, n, i = 0;     cin >> n;     while (n > 0) arr[i] = n % 2, n /= 2, i++;     for (i = 29; i >= 0; i--)       if (arr[i]) cout << i + 1 <<    ;     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int s = 0;     int d = 0;     vector<int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int i = 0;     int count = 1;     int beg = 0;     int last = n - 1;     while (count <= n) {       if (i == 0) {         if (a[beg] > a[last]) {           s = s + a[beg];           beg++;           i = 1;         } else {           s = s + a[last];           last--;           i = 1;         }       } else {         if (a[beg] > a[last]) {           d = d + a[beg];           beg++;           i = 0;         } else {           d = d + a[last];           last--;           i = 0;         }       }       count++;     }     cout << s <<     << d;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, count = 1, ans = 0;     string input;     cin >> input;     for (i = 1; i < input.length(); i++) {       if (input[i] != input[i - 1]) {         ans += (count / 5) + (count % 5 > 0);         count = 0;       }       count++;     }     ans += (count / 5) + (count % 5 > 0);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 300005;   int needread[maxn];   int readed[maxn];   int cnt[maxn];   int main() {     int n, q, type, num, pop_cnt = 0;     queue<int> que;     scanf( %d %d , &n, &q);     int ans = 0;     while (q--) {       scanf( %d %d , &type, &num);       if (type == 1) {         ans++;         needread[num]++;         que.push(num);       } else if (type == 2) {         ans -= needread[num] - readed[num];         readed[num] = needread[num];       } else {         int t = num - pop_cnt;         while (!que.empty() && t > 0) {           t--;           int cur = que.front();           que.pop();           pop_cnt++;           cnt[cur]++;           if (cnt[cur] > readed[cur]) {             ans -= cnt[cur] - readed[cur];             readed[cur] = cnt[cur];           }         }       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > vec[105];   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) vec[i].push_back(make_pair(i, i));     int ct = 101;     int a, b;     for (int i = 1; i <= k; i++) {       scanf( %d%d , &a, &b);       vec[a].push_back(make_pair(ct, a));       vec[b].push_back(make_pair(ct, b));       ct++;     }     for (int i = 1; i <= n; i++) {       printf( %d n , vec[i].size());       for (int j = 0; j < vec[i].size(); j++)         printf( %d %d n , vec[i][j].first, vec[i][j].second);     }   }
#include <bits/stdc++.h>   using namespace std;   bool sortin(const pair<long long int, long long int> &e,               const pair<long long int, long long int> &f) {     return (e.first < f.first);   }   long long int i, j, k, l, m, n, c, p, q, ts, mn = 10e17, mod = 10e8 + 7;   long long int a[250002], b[250002], x[250002];   int main() {     {       ios_base::sync_with_stdio(false);       cin.tie(0);       cout.tie(0);     };     cin >> n >> m >> k;     l = ((n + k - 1) / k) * ((m + k - 1) / k) * ((n - 1) % k + 1) *         ((m - 1) % k + 1);     cout << l;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1111;   int n;   struct Edge {     int u, v;     long long weight;     int adj(int x) { return x == u ? v : u; }   };   struct Path {     int u, v;     long long weight;   };   vector<Edge> E;   vector<int> G[N];   vector<Path> res;   int Trace[N];   int FindLeaf(int u, int parent) {     if ((int)G[u].size() == 1) return u;     for (auto e : G[u]) {       int v = E[e].adj(u);       if (v == parent) continue;       Trace[v] = u;       int l = FindLeaf(v, u);       if (l != -1) return l;     }     return -1;   }   void Solve() {     for (int i = 1; i <= n; ++i) {       if ((int)G[i].size() == 2) {         cout <<  NO n ;         return;       }     }     cout <<  YES n ;     for (auto e : E) {       vector<int> U, V;       int u = e.u;       int v = e.v;       long long w = e.weight;       for (int i = 0; i < (int)G[u].size(); ++i) {         int uu = E[G[u][i]].adj(u);         if (uu == v) continue;         U.push_back(FindLeaf(uu, u));       }       if (U.empty()) U.push_back(u);       for (int i = 0; i < (int)G[v].size(); ++i) {         int vv = E[G[v][i]].adj(v);         if (vv == u) continue;         V.push_back(FindLeaf(vv, v));       }       if (V.empty()) V.push_back(v);       res.push_back({U[0], V[0], w / 2});       if ((int)U.size() > 1 && (int)V.size() > 1)         res.push_back({U[1], V[1], w / 2});       else if ((int)U.size() > 1)         res.push_back({U[1], V[0], w / 2});       else if ((int)V.size() > 1)         res.push_back({U[0], V[1], w / 2});       else         res.push_back({U[0], V[0], w / 2});       if ((int)U.size() > 1) res.push_back({U[0], U[1], -w / 2});       if ((int)V.size() > 1) res.push_back({V[0], V[1], -w / 2});     }     cout << (int)res.size() <<   n ;     for (int i = 0; i < (int)res.size(); ++i) {       cout << res[i].u <<     << res[i].v <<     << res[i].weight <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n - 1; ++i) {       int u, v;       long long w;       cin >> u >> v >> w;       G[u].push_back(i);       G[v].push_back(i);       E.push_back({u, v, w});     }     Solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     int arr[n];     int sum = 0;     int ans = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];       sum += arr[i];     }     sum = sum / 2 + 1;     sort(arr, arr + n, greater<int>());     for (int j = 0; j < n; j++) {       if (sum <= 0) break;       sum -= arr[j];       ans++;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   const int maxn = 2e5 + 5;   const int mo = 998244353;   using namespace std;   int rd() {     int x = 0, f = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) x = (x << 3) + (x << 1) + c -  0 , c = getchar();     return x * f;   }   int n, f[maxn][4], head[maxn];   vector<int> G[maxn];   void dfs(int u, int y) {     f[u][1] = f[u][3] = 1;     int sum = 1;     bool flag = false;     for (int v : G[u]) {       if (v == y) {         flag = true;         continue;       }       dfs(v, u);       f[u][2] = 1LL * f[u][2] * (1LL * f[v][0] + f[v][2] + f[v][3]) % mo;       f[u][0] = 1LL * f[u][0] * (1LL * f[v][0] + f[v][2] + f[v][3]) % mo;       if (flag) {         f[u][1] = 1LL * f[u][1] * (1LL * f[v][0] + f[v][2] + f[v][3]) % mo;         f[u][2] = (f[u][2] + 1LL * sum * (f[v][2] + f[v][3])) % mo;       } else {         f[u][0] = (f[u][0] + 1LL * sum * (f[v][2] + f[v][3])) % mo;         f[u][1] = 1LL * f[u][1] * (1LL * f[v][0] + f[v][1]) % mo;       }       sum = 1LL * sum * (f[v][0] + f[v][1]) % mo;       f[u][3] = 1LL * f[u][3] * (f[v][0] + f[v][1]) % mo;     }   }   int main() {     n = rd();     for (int i = 1, u, v; i < n; i++)       u = rd(), v = rd(), G[u].push_back(v), G[v].push_back(u);     dfs(1, 0);     printf( %d n , (f[1][0] + f[1][3]) % mo);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   pair<string, int> A[11];   int main() {     scanf( %i , &n);     for (int i = 0; i < 7; i++) A[i].second = 2e7;     for (int i = 0; i < n; i++) {       string s;       int p;       cin >> p >> s;       sort(s.begin(), s.end());       if (s ==  ABC )         A[0] = make_pair(s, min(A[0].second, p));       else if (s ==  AB )         A[1] = make_pair(s, min(A[1].second, p));       else if (s ==  AC )         A[2] = make_pair(s, min(A[2].second, p));       else if (s ==  BC )         A[3] = make_pair(s, min(A[3].second, p));       else if (s ==  A )         A[4] = make_pair(s, min(A[4].second, p));       else if (s ==  B )         A[5] = make_pair(s, min(A[5].second, p));       else if (s ==  C )         A[6] = make_pair(s, min(A[6].second, p));     }     int ans = 2e7;     for (int i = 0; i < 1 << 7; i++) {       int occ[3] = {0};       int cost = 0;       for (int j = 0; j < 7; j++) {         if (i & 1 << j) {           for (int k = 0; k < A[j].first.size(); k++) occ[A[j].first[k] -  A ]++;           cost += A[j].second;         }       }       if (occ[0] && occ[1] && occ[2]) ans = min(cost, ans);     }     printf( %i n , ans == 2e7 ? -1 : ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     vector<int> x(n);     vector<int> p(n);     for (int i = (0); i < ((n)); ++i) {       cin >> x[i];       --x[i];       p[x[i]] = i;     }     int const MAX_SUM = 100001;     vector<int> primes;     for (int k = (2); k < (2 * n + 1); ++k) {       bool isPrime = true;       for (int j = 2; j * j <= k; ++j) {         if (k % j == 0) {           isPrime = false;           break;         }       }       if (isPrime) {         primes.push_back(k);       }     }     vector<pair<int, int> > res;     for (int i = (0); i < ((n)); ++i) {       int const pos1 = p[i];       int const pos2 = i;       int p1 = min(pos1, pos2);       int const p2 = max(pos1, pos2);       vector<int> positions;       positions.push_back(p1);       while (p1 != p2) {         int const diff = p2 - p1 + 1;         auto it = lower_bound(primes.begin(), primes.end(), diff);         if (it == primes.end() || *it > diff) --it;         int const usedPrime = *it;         p1 += usedPrime - 1;         positions.push_back(p1);       }       if (pos1 > pos2) reverse(positions.begin(), positions.end());       for (int j = (0); j < (((int)positions.size() - 1)); ++j) {         int const p1 = positions[j];         int const p2 = positions[j + 1];         swap(x[p1], x[p2]);         p[x[p1]] = p1;         p[x[p2]] = p2;         res.push_back(make_pair(min(p1, p2), max(p1, p2)));       }     }     vector<int> orig(n);     for (int i = (0); i < ((n)); ++i) orig[i] = i;     if (orig != x) {       cout <<  FAILED! n ;       throw 10;     }     cout << (int)res.size() << endl;     for (int i = (0); i < (((int)res.size())); ++i) {       cout << res[i].first + 1 <<     << res[i].second + 1 <<   n ;     }     return 0;   }