malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n;     cin >> n;     vector<long long int> s(2 * n);     for (int i = 0; i < 2 * n; i++) cin >> s[i];     sort(s.begin(), s.end());     if (s[0] == s[2 * n - 1]) {       cout << -1 <<   n ;       return;     }     for (int i = 0; i < 2 * n; i++) cout << s[i] <<    ;     cout <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long int t;     t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 10, LG = 45;   long long n, ts, Mx, B[N], S[N];   struct Node {     int32_t l, r, c;     Node() { l = r = c = 0; }   };   vector<Node> A;   inline long long Creat() { return (ts++); }   inline void Add(long long val, long long tp) {     long long id = 0;     A[id].c += tp;     for (long long i = LG - 1; ~i; i--) {       bool b = (val >> i) & 1;       if (!A[id].l) A[id].l = Creat();       if (!A[id].r) A[id].r = Creat();       if (!b) id = A[id].l;       if (b) id = A[id].r;       A[id].c += tp;     }   }   inline long long Get(long long val) {     long long id = 0, ret = 0;     for (long long i = LG - 1; ~i; i--) {       if (!A[id].l) A[id].l = Creat();       if (!A[id].r) A[id].r = Creat();       bool b = (val >> i) & 1, w = 0;       if ((!b && A[A[id].r].c) || (b && !A[A[id].l].c))         id = A[id].r, ret |= (1ll << i), w = 1;       if (!w) id = A[id].l;     }     return (val ^ ret);   }   int32_t main() {     scanf( %lld , &n);     A.resize(2e7, Node());     Creat();     Add(0, 2);     for (long long i = 1; i <= n; i++) scanf( %lld , &B[i]);     for (long long i = n; i; i--) S[i] = S[i + 1] ^ B[i], Add(S[i], 1);     for (long long i = 0, r = 0; i <= n; i++, r ^= B[i])       Mx = max(Mx, Get(r)), Add(S[i + 1], -1);     return !printf( %lld , Mx);   }
#include <bits/stdc++.h>   using namespace std;   int fuck[2010], de[2010], n;   char mp[2010][2010];   int check() {     sort(fuck + 1, fuck + 1 + n);     int sum = 0;     for (int i = 1; i < n; i++) {       sum += fuck[i];       if (sum == i * (i - 1) / 2) return 0;     }     return 1;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %s , mp[i] + 1);       for (int j = 1; j <= n; j++) {         if (mp[i][j] ==  1 ) de[i]++, fuck[i] = de[i];       }     }     if (check()) {       cout << 0 <<     << 1;       return 0;     }     if (n <= 6) {       int minn = 1e9, res = 0;       for (int i = 1; i < (1 << n); i++) {         int now = 0;         for (int j = 1; j <= n; j++) {           if ((1 << (j - 1)) & i) {             now++;             de[j] = n - 1 - de[j];             for (int k = 1; k <= n; k++) {               if (k == j) continue;               if (mp[j][k] ==  1 ) {                 mp[j][k] =  0 ;                 mp[k][j] =  1 ;                 de[k]++;               } else {                 mp[j][k] =  1 ;                 mp[k][j] =  0 ;                 de[k]--;               }             }           }         }         for (int j = 1; j <= n; j++) fuck[j] = de[j];         for (int j = 1; j <= n; j++) {           if ((1 << (j - 1)) & i) {             de[j] = n - 1 - de[j];             for (int k = 1; k <= n; k++) {               if (k == j) continue;               if (mp[j][k] ==  1 ) {                 mp[j][k] =  0 ;                 mp[k][j] =  1 ;                 de[k]++;               } else {                 mp[j][k] =  1 ;                 mp[k][j] =  0 ;                 de[k]--;               }             }           }         }         if (now > minn) continue;         if (check()) {           if (now < minn)             minn = now, res = 1;           else             res++;         }       }       if (minn == 1e9)         cout << -1;       else {         for (int i = 1; i <= minn; i++) res *= i;         cout << minn <<     << res;       }     } else {       int res = 0;       for (int j = 1; j <= n; j++) {         de[j] = n - 1 - de[j];         for (int k = 1; k <= n; k++) {           if (k == j) continue;           if (mp[j][k] ==  1 ) {             mp[j][k] =  0 ;             mp[k][j] =  1 ;             de[k]++;           } else {             mp[j][k] =  1 ;             mp[k][j] =  0 ;             de[k]--;           }         }         for (int j = 1; j <= n; j++) fuck[j] = de[j];         de[j] = n - 1 - de[j];         for (int k = 1; k <= n; k++) {           if (k == j) continue;           if (mp[j][k] ==  1 ) {             mp[j][k] =  0 ;             mp[k][j] =  1 ;             de[k]++;           } else {             mp[j][k] =  1 ;             mp[k][j] =  0 ;             de[k]--;           }         }         if (check()) res++;       }       cout << 1 <<     << res << endl;     }   }
#include <bits/stdc++.h>   int n, a, b, p;   char s[51];   int main(void) {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d %s , &a, s);       b = 0;       p = a / 2;       for (int j = 0; j < a; j++) {         if (s[j] ==  ( ) {           b++;         } else {           if (b > 0) {             b--;             p--;           }         }       }       printf( %d n , p);     }   }
#include <bits/stdc++.h>   using std::cin;   using std::cout;   using std::pair;   using std::set;   using std::sort;   using std::string;   using std::vector;   int main() {     int n, m;     cin >> n >> m;     vector<vector<pair<string, int>>> byreg(m);     for (int i = 0; i < n; i++) {       string a;       int b, c;       cin >> a >> b >> c;       byreg[b - 1].push_back(make_pair(a, c));     }     for (int i = 0; i < m; i++) {       sort(byreg[i].begin(), byreg[i].end(),            [](pair<string, int> &l, pair<string, int> &r) {              return l.second > r.second;            });     }     for (int i = 0; i < m; i++) {       if (byreg[i].size() > 2) {         if (byreg[i][0].second == byreg[i][2].second ||             byreg[i][1].second == byreg[i][2].second) {           cout <<  ? n ;         } else           cout << byreg[i][0].first <<     << byreg[i][1].first <<   n ;       } else         cout << byreg[i][0].first <<     << byreg[i][1].first <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1010;   const int INF = 100000000;   string str[maxn];   int dp[maxn][maxn];   int n, m, ans;   int flag[maxn][maxn];   int dir[4][2] = {0, -1, 0, 1, 1, 0, -1, 0};   char ch[5] = { D ,  I ,  M ,  A };   vector<pair<int, int> > q;   bool Ok(int ki, int kj) {     if (ki >= 0 && ki < n && kj >= 0 && kj < m) return true;     return false;   }   int dfs(int ki, int kj, int d, int f) {     int Ans = 1;     for (int i = 0; i < 4; i++) {       int ti = ki + dir[i][0];       int tj = kj + dir[i][1];       if (Ok(ti, tj) && str[ti][tj] == ch[d + 1 < 4 ? d + 1 : 0]) {         if (flag[ti][tj] < f) {           int k = flag[ti][tj];           flag[ti][tj] = f;           if (dp[ti][tj] > 0)             Ans = max(Ans, dp[ti][tj] + 1);           else             Ans = max(Ans, dfs(ti, tj, d + 1 < 4 ? d + 1 : 0, f) + 1);           flag[ti][tj] = k;         } else {           Ans = INF;           break;         }       }     }     dp[ki][kj] = Ans;     return Ans;   }   void solve() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       cin >> str[i];       for (int j = 0; j < m; j++) {         if (str[i][j] ==  D ) q.push_back(pair<int, int>(i, j));       }     }     for (int i = 0; i < q.size(); i++) {       if (dp[q[i].first][q[i].second] == 0)         ans = max(ans, dfs(q[i].first, q[i].second, 0, i + 1) / 4);     }     if (ans == 0)       cout <<  Poor Dima!  << endl;     else if (ans >= 2500000)       cout <<  Poor Inna!  << endl;     else       cout << ans << endl;   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   long long int inverse(long long int i) {     if (i == 1) return 1;     return (MOD - ((MOD / i) * inverse(MOD % i)) % MOD + MOD) % MOD;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long m, n, x;     cin >> m >> n;     cout << flush;     long long a[n];     for (int i = 0; i < n; i++) {       cout << 1 << endl;       cout << flush;       cin >> x;       if (x == 0)         exit(0);       else if (x == 1)         a[i] = 1;       else         a[i] = 0;     }     long long l = 2, r = m, mid, j = 0;     while (1) {       mid = (l + r) / 2;       cout << mid << endl;       cout << flush;       cin >> x;       if (x == 0 || x == -2)         exit(0);       else {         if (x == 1) {           if (a[j] == 1)             l = mid + 1;           else             r = mid - 1;         } else if (x == -1) {           if (a[j] == 1)             r = mid - 1;           else             l = mid + 1;         }       }       j++;       j %= n;     }   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-8;   const int inf = 1 << 30;   const int mod = int(1e9) + 7;   const int base = 257;   const int maxn = 2005;   int n, m, d[maxn][maxn], ans = -1, sx = -1, sy = -1;   char c[maxn][maxn];   int get(int xa, int ya, int xb, int yb) {     int res = d[xb][yb];     res -= d[xa - 1][yb];     res -= d[xb][ya - 1];     res += d[xa - 1][ya - 1];     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         cin >> c[i][j];         d[i][j] = d[i][j - 1] + (c[i][j] ==  X );       }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         if (c[i][j] ==  X  && sx == -1) sx = i, sy = j;         d[i][j] += d[i - 1][j];       }     for (int x = 1; x <= n; x++)       for (int y = 1; y <= m; y++) {         if (get(sx, sy, sx + x - 1, sy + y - 1) == x * y) {           int sxx = sx, syy = sy;           vector<pair<int, int> > v;           v.push_back(make_pair(sxx, syy));         go:;           int sum1 = get(sxx + 1, syy, sxx + 1 + x - 1, syy + y - 1);           int sum2 = get(sxx, syy + 1, sxx + x - 1, syy + 1 + y - 1);           if (sum1 == x * y && sum2 == x * y) continue;           if (sum1 == x * y) {             sxx++;             v.push_back(make_pair(sxx, syy));             goto go;           } else if (sum2 == x * y) {             syy++;             v.push_back(make_pair(sxx, syy));             goto go;           } else {             int tot = 1ll * get(v[0].first, v[0].second, v[0].first + x - 1,                                 v[0].second + y - 1);             for (int i = 1; i < v.size(); i++) {               tot += get(v[i].first, v[i].second, v[i].first + x - 1,                          v[i].second + y - 1);               tot -= get(v[i].first, v[i].second, v[i - 1].first + x - 1,                          v[i - 1].second + y - 1);             }             if (d[n][m] == tot) {               if (ans == -1)                 ans = x * y;               else                 ans = min(ans, x * y);             } else               continue;           }         }       }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int dp[205][205][205];   long long int n, k;   string s, t;   char c1, c2;   long long int solve(long long int pos, long long int k, long long int cnt) {     if (pos >= n) {       return 0;     }     if (dp[pos][k][cnt] != -1) return dp[pos][k][cnt];     long long int ans = 0;     ans = max(solve(pos + 1, k, cnt), ans);     if (c1 == s[pos] && k >= 0) {       ans = max(solve(pos + 1, k, cnt + 1), ans);     } else if (c1 != s[pos] && k >= 1) {       ans = max(solve(pos + 1, k - 1, cnt + 1), ans);     }     if (c2 == s[pos] && k >= 0) {       ans = max(cnt + solve(pos + 1, k, cnt), ans);     } else if (c2 != s[pos] && k >= 1) {       ans = max(cnt + solve(pos + 1, k - 1, cnt), ans);     }     return dp[pos][k][cnt] = ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     cin >> n >> k;     cin >> s >> t;     c1 = t[0];     c2 = t[1];     for (int i = 0; i < 205; i++)       for (int j = 0; j < 205; j++)         for (int p = 0; p < 205; p++) dp[i][j][p] = -1;     if (c1 != c2) {       cout << solve(0, k, 0) << endl;     } else {       long long int cnt = 0;       for (int i = 0; i < n; i++) {         if (s[i] == c1) cnt++;       }       long long int ans = min(cnt + k, n);       ans = ans * (ans - 1) / 2;       cout << ans;     }   }
#include <bits/stdc++.h>   using namespace ::std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long add(long long a, long long b, long long m = 1000000007) {     return (a % m + b % m + 2 * m) % m;   }   long long mul(long long a, long long b, long long m = 1000000007) {     return ((a % m + m) * (b % m + m)) % m;   }   int main(void) {     int n;     scanf( %d , &(n));     if (n % 2 == 0)       puts( Mahmoud );     else       puts( Ehab );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int N = 70, M = 11, MA = 1030;   long long int dp[M][N][M][MA], dps[M][N][MA], dpt[M][N], n, q, b, l, r, x;   vector<long long int> v;   long long int get(long long int a, long long int b) {     long long int x = a, ans, mask = 0, l;     v.resize(0);     while (x > 0) {       v.push_back(x % b);       x /= b;     }     l = (long long int)v.size();     ans = dpt[b][l];     reverse(v.begin(), v.end());     for (auto y : v) {       for (int j = b - 1; j > y; j--) ans -= dp[b][l][j][mask];       mask ^= (1 << y);       l--;     }     return ans;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     for (long long int bi = 2; bi <= 10; bi++) {       for (int l = 2; l <= 65; l++) {         for (int c = 0; c < bi; c++) {           dp[bi][1][c][(1ll << c)] = 1;           for (int mask = 0; mask < (1ll << bi); mask++)             dps[bi][1][mask] += dp[bi][1][c][mask];         }         dpt[bi][1] = 0;       }     }     for (long long int bi = 2; bi <= 10; bi++) {       for (int l = 2; l <= 65; l++) {         dpt[bi][l] = dpt[bi][l - 1];         for (int c = 0; c < bi; c++) {           for (int i = 0; i < bi; i++)             for (int mask = 0; mask < (1ll << bi); mask++) {               x = mask, x ^= (1ll << c);               dp[bi][l][c][mask] += dp[bi][l - 1][i][x];             }           for (int mask = 0; mask < (1ll << bi); mask++)             dps[bi][l][mask] += dp[bi][l][c][mask];           if (c != 0) dpt[bi][l] += dp[bi][l][c][0];         }       }     }     cin >> q;     for (int i = 1; i <= q; i++) {       cin >> b >> l >> r;       l--;       cout << get(r, b) - get(l, b) <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   int A[1 << 21], B[1 << 21];   long long level_index1[21];   long long level_index2[21];   long long mergesort(int begin, int end, int level) {     if (begin == end) return 0;     long long inv_index = 0;     int middle = (begin + end) / 2;     inv_index += mergesort(begin, middle, level + 1);     inv_index += mergesort(middle + 1, end, level + 1);     int left = begin;     int right = middle + 1;     long long ct = 0;     long long ct2 = 0;     for (int k = begin; k <= end; ++k) {       if (right > end || (left <= middle && (A[left] <= A[right]))) {         B[k] = A[left++];       } else {         B[k] = A[right++];         ct += (middle - left + 1);       }     }     left = begin, right = middle + 1;     for (int k = begin; k <= end; ++k) {       if (right > end || (left <= middle && (A[left] < A[right]))) {         left++;         ct2 += (end - right + 1);       } else {         right++;       }     }     for (int k = begin; k <= end; ++k) A[k] = B[k];     level_index1[level] += ct;     level_index2[level] += ct2;     return inv_index + ct;   }   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     int fim = 1 << n;     for (int i = 0; i < fim; ++i) cin >> A[i];     for (int lvl = 0; lvl <= n; ++lvl) {       level_index1[lvl] = level_index2[lvl] = 0;     }     mergesort(0, fim - 1, 0);     int m;     cin >> m;     while (m--) {       int q;       cin >> q;       long long ans = 0;       q = n - q;       for (int lvl = 0; lvl < q; ++lvl) {         ans += level_index1[lvl];       }       for (int lvl = q; lvl < n; ++lvl) {         swap(level_index1[lvl], level_index2[lvl]);         ans += level_index1[lvl];       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, minn = 1000000, indx;     cin >> n;     int arr[n + 1];     for (int i = 1; i <= n; i++) cin >> arr[i];     for (int i = 1; i < n; i++) {       if (abs(arr[i] - arr[i + 1]) < minn) {         minn = abs(arr[i] - arr[i + 1]);         indx = i;       }     }     if (abs(arr[1] - arr[n]) < minn)       cout << n <<     << 1 << endl;     else       cout << indx <<     << indx + 1 << endl;     return 0;   }
#include <bits/stdc++.h>   const int maxn = 300 + 10;   char st[maxn][maxn];   int n, m, p;   int main() {     scanf( %d%d%d , &n, &m, &p);     for (int i = 1; i <= n; i++) scanf( %s , st[i] + 1);     for (int k = 1; k <= n; k++) {       for (int i = 1 + k; i + k <= n; i++)         for (int j = 1 + k; j + k <= m; j++)           if (st[i][j] ==  *  && st[i - k][j] ==  *  && st[i + k][j] ==  *  &&               st[i][j - k] ==  *  && st[i][j + k] ==  * ) {             p--;             if (!p) {               printf( %d %d n%d %d n%d %d n%d %d n%d %d n , i, j, i - k, j, i + k,                      j, i, j - k, i, j + k);               return 0;             }           }     }     printf( -1 n );   }
#include <bits/stdc++.h>   using namespace std;   long long int power(long long int x, long long int y) {     int temp;     if (y == 0) return 1;     temp = power(x, y / 2);     if (y % 2 == 0)       return temp * temp;     else       return x * temp * temp;   }   long long int fun(long long int n) {     if (n == 0)       return 0;     else {       return n % 10 + fun(n / 10);     }   }   int main() {     long long int t;     cin >> t;     for (int _ = 0; _ < t; _++) {       long long int n, k, a, b;       cin >> k >> n >> a >> b;       if (k - (n * b) <= 0)         cout <<  -1 n ;       else {         long long int ans = 0;         if ((k - (n * b)) % (a - b) == 0) {           ans = ((k - (n * b)) / (a - b)) - 1;         } else {           ans = (k - (n * b)) / (a - b);         }         ans = min(n, ans);         cout << ans <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e3 + 7;   long long M = 1e9 + 7;   long long dp[N];   long long g[N][30];   int n;   vector<int> a;   int ch[N][N];   int main() {     ch[0][0] = 1;     cin >> n;     for (int i = 1; i <= n; i++) {       for (int j = 0; j <= i; j++) {         if (j == 0) {           ch[j][i] = 1;           continue;         }         ch[j][i] = (ch[j - 1][i - 1] + ch[j][i - 1]) % M;       }     }     for (int i = 1; i <= n; i++) {       char c;       cin >> c;       if (!a.size())         a.push_back(c -  a  + 1);       else if (a.back() != c -  a  + 1)         a.push_back(c -  a  + 1);     }     dp[0] = 1;     for (int i = 0; i < a.size(); i++) {       for (int j = a.size(); j >= 2; j--) {         dp[j] += -g[j][a[i]] - g[j - 1][a[i]] + dp[j - 1];         g[j][a[i]] = dp[j - 1] - g[j - 1][a[i]];         dp[j] %= M;         g[j][a[i]] %= M;       }       if (g[1][a[i]] == 0) dp[1]++;       g[1][a[i]] = 1;     }     long long res = 0;     for (int i = 1; i <= n; i++) {       dp[i] = (((dp[i] % M) + M) % M);       res = (res + ch[i - 1][n - 1] * dp[i]) % M;     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool a[2001][2001], w[2001][2001];   int n, fi, fj, si, sj, dist, s, clr = 4;   inline bool val(int x, int y) { return (x > 0 && y > 0 && x < n && y < n); }   inline void clear(int x, int y) {     s = 0;     for (int i = 0; i < clr; i++)       for (int j = 0; j < clr; j++)         if (a[i + x][j + y]) s++;     if (s <= clr)       for (int i = 0; i < clr; i++)         for (int j = 0; j < clr; j++) a[i + x][j + y] = 0;   }   void dfs(int x, int y) {     w[x][y] = 1;     s++;     if (((x - fi) * (x - fi)) + ((y - fj) * (y - fj)) > dist)       dist = ((x - fi) * (x - fi)) + ((y - fj) * (y - fj));     if (val(x - 1, y) && a[x - 1][y] && !w[x - 1][y]) dfs(x - 1, y);     if (val(x + 1, y) && a[x + 1][y] && !w[x + 1][y]) dfs(x + 1, y);     if (val(x, y - 1) && a[x][y - 1] && !w[x][y - 1]) dfs(x, y - 1);     if (val(x, y + 1) && a[x][y + 1] && !w[x][y + 1]) dfs(x, y + 1);   }   int main() {     ios_base::sync_with_stdio(0);     int i, j, x, as = 0, ac = 0;     cin >> n;     for (i = 0; i < n; i++)       for (j = 0; j < n; j++) cin >> a[i][j];     for (i = 0; i < n; i += clr)       for (j = 0; j < n; j += clr) clear(i, j);     for (i = 0; i < n; i++)       for (j = 0; j < n; j++)         if (!w[i][j] && a[i][j]) {           dist = s = 0;           fi = i, fj = j;           dfs(i, j);           if (dist < 200.0) {             a[i][j] = 0;             continue;           }           s *= 1.2;           double d = sqrt(dist), sq = ((d / sqrt(2.0)) * (d / sqrt(2.0))),                  circ = ((d / 2.0) * (d / 2.0)) * M_PI;           if (abs(s - sq) < abs(s - circ))             as++;           else             ac++;         }     cout << ac <<     << as;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 999999999;   const long long INFL = 99999999999999999LL;   const double EPSILON = 0.00000001;   const long long MOD = 1000000007;   long long a[100005];   int32_t main() {     long long n, t;     scanf( %I64d , &n);     ;     scanf( %I64d , &t);     ;     for (long long i = 0; i < n; i++) scanf( %I64d , &a[i]);     ;     long long ans = 0;     long long l = 0, r = 0;     long long cur = 0;     long long s = 0;     while (l < n) {       while (r < n and s + a[r] <= t) {         s += a[r];         r++;         cur++;         ans = ((ans) > (cur) ? (ans) : (cur));       }       l++;       if (l > r)         r++;       else {         s -= a[l - 1];         cur--;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int fr[200004];   struct cmp {     bool operator()(int a, int b) const { return a > b; }   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     auto make = [](vector<int>& a, int pos) {       swap(a[pos + 2], a[pos + 1]);       swap(a[pos + 1], a[pos]);     };     int t;     cin >> t;     while (t--) {       int n, i, j, k, l;       cin >> n;       vector<int> v(n);       vector<pair<int, int>> p(n);       for (i = 0; i < n; i++) {         cin >> v[i];         p[i] = {v[i], i};       }       sort(p.begin(), p.end());       for (i = 0; i < n; i++) v[p[i].second] = i;       int cnt = 0;       for (i = 0; i < n - 1; i++) {         for (j = i + 1; j < n; j++)           if (v[j] < v[i]) cnt++;       }       if (cnt & 1) {         for (i = 0; i < n - 1; i++)           if (p[i].first == p[i + 1].first) {             swap(v[p[i].second], v[p[i + 1].second]);             break;           }       }       vector<int> ans;       for (i = 0; i < n - 2; i++) {         int pos = min_element(v.begin() + i, v.end()) - v.begin();         while (pos > i + 1) {           make(v, pos - 2);           ans.push_back(pos - 2);           pos = pos - 2;         }         if (pos != i) {           make(v, i);           make(v, i);           ans.push_back(i);           ans.push_back(i);           pos = i;         }       }       for (i = 0; i < 3; i++) {         if (is_sorted(v.begin(), v.end())) {           break;         }         make(v, n - 3);         ans.push_back(n - 3);       }       if (!is_sorted(v.begin(), v.end())) {         cout << -1 <<   n ;         continue;       }       cout << ans.size() <<   n ;       for (int x : ans) cout << x + 1 <<    ;       cout <<   n ;     }   }