malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   template <class T>   inline void gn(T &first) {     char c, sg = 0;     while (c = getchar(), (c >  9  || c <  0 ) && c !=  - )       ;     for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ;          c = getchar())       first = (first << 1) + (first << 3) + c -  0 ;     if (sg) first = -first;   }   template <class T>   inline void print(T first) {     if (first < 0) {       putchar( - );       return print(-first);     }     if (first < 10) {       putchar( 0  + first);       return;     }     print(first / 10);     putchar(first % 10 +  0 );   }   int power(int a, int b, int m, int ans = 1) {     for (; b; b >>= 1, a = 1LL * a * a % m)       if (b & 1) ans = 1LL * ans * a % m;     return ans;   }   char s[100011];   pair<int, int> dp[100011];   int cnt[100011], mx[100011][2];   int main() {     int n, m;     cin >> n >> s + 1 >> m;     for (int i = 1; i <= n; i++) {       if (s[i] !=  b ) mx[i][0] = mx[i - 1][1] + 1;       if (s[i] !=  a ) mx[i][1] = mx[i - 1][0] + 1;       cnt[i] = cnt[i - 1] + (s[i] ==  ? );       dp[i] = dp[i - 1];       if (mx[i][!(m & 1)] >= m) {         if (dp[i - m].first + 1 == dp[i].first) {           smin(dp[i].second, dp[i - m].second + cnt[i] - cnt[i - m]);         }         if (dp[i - m].first + 1 > dp[i].first) {           dp[i].first = dp[i - m].first + 1;           dp[i].second = dp[i - m].second + cnt[i] - cnt[i - m];         }       }     }     cout << dp[n].second << endl;     return 0;   }
#include <bits/stdc++.h>   const double eps = 1e-10;   using namespace std;   using ll = long long;   using ul = unsigned long long;   using PII = pair<int, int>;   const int NN = 1011101;   const int NZ = 511100;   const int MM = 151;   const int need = (1 << 30) - 1;   int n, m, s, x, i, j, t, a, b, k, c, r, col[NN];   int l;   ll in[NN];   int comp[NN];   PII gr[NN];   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d %d , &a, &b);       a--, b--;       gr[i + i] = {a, b};       gr[i + i + 1] = {b, a};     }     set<int> sv;     for (int i = 0; i < n; i++) sv.insert(i);     m += m;     sort(gr, gr + m);     vector<vector<int>> answww;     while (!sv.empty()) {       int ff = *sv.begin();       sv.erase(ff);       queue<int> qq;       qq.push(ff);       vector<int> _comp;       while (!qq.empty()) {         int v = qq.front();         qq.pop();         _comp.push_back(v);         vector<int> rv;         for (auto it : sv) {           int vv = it;           if (!binary_search(gr, gr + m, make_pair(v, it))) {             qq.push(vv);             rv.push_back(vv);           }         }         for (int i = 0; i < rv.size(); i++) {           sv.erase(rv[i]);         }       }       answww.push_back(_comp);     }     printf( %d n , answww.size());     for (int i = 0; i < answww.size(); i++) {       printf( %d  , answww[i].size());       for (int j = 0; j < answww[i].size(); j++) {         printf(  %d , answww[i][j] + 1);       }       puts(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (b == 0) {       return a;     }     gcd(b, a % b);   }   int n, m, a, b, t;   bool eo = 0;   int main() {     cin >> n >> m;     n++;     m++;     for (int i = 1; i <= n; i++) {       if (i == 1)         cin >> a;       else         cin >> t;     }     for (int i = 1; i <= m; i++) {       if (i == 1)         cin >> b;       else         cin >> t;     }     if (a * b < 0) eo = 1;     if (n > m) {       if (eo) cout <<  - ;       cout <<  Infinity  << endl;     }     if (n < m) {       cout <<  0/1 ;     }     if (n == m) {       a = abs(a), b = abs(b);       int t = gcd(a, b);       if (eo) cout <<  - ;       a /= t, b /= t;       cout << a <<  /  << b;     }   }
#include <bits/stdc++.h>   using namespace std;   bool test_cases;   void init(bool k) {     test_cases = k;     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   struct test_cases {     void prepare_left(long long *great_left, long long n, long long *a) {       stack<long long> st;       great_left[0] = -1;       st.push(a[0]);       for (long long i = 1; i < n; i++) {         while (!st.empty() and st.top() < a[i]) {           st.pop();         }         if (st.empty()) {           great_left[i] = -1;         } else {           great_left[i] = st.top();         }         st.push(a[i]);       }     }     void prepare_right(long long *great_right, long long n, long long *a) {       stack<long long> st;       great_right[n - 1] = -1;       st.push(a[n - 1]);       for (long long i = n - 2; i >= 0; i--) {         while (!st.empty() and st.top() < a[i]) {           st.pop();         }         if (st.empty()) {           great_right[i] = -1;         } else {           great_right[i] = st.top();         }         st.push(a[i]);       }     }     void test_case(long long test) {       long long n;       cin >> n;       long long a[n];       long long great_left[n];       long long great_right[n];       for (long long i = 0; i < n; i++) cin >> a[i];       long long ans = 0;       for (long long i = 0; i < n - 1; i++) {         ans = max(ans, a[i] ^ a[i + 1]);       }       prepare_left(great_left, n, a);       prepare_right(great_right, n, a);       for (long long i = 0; i < n; i++) {         long long left = great_left[i];         long long right = great_right[i];         if (left != -1) {           ans = max(ans, left ^ a[i]);         }         if (right != -1) {           ans = max(ans, right ^ a[i]);         }         if (left != -1 and right != -1) {           ans = max(ans, left ^ right);         }       }       cout << ans <<   n ;     }   };   int32_t main() {     init(false);     long long tc;     if (test_cases) {       cin >> tc;     } else {       tc = 1;     }     for (long long i = 0; i < tc; i++) {       struct test_cases o;       o.test_case(i + 1);     }     return 0;   };
#include <bits/stdc++.h>   using namespace std;   bool solve(vector<int>& arr, int m, int n, int k) {     vector<int> dp(n + 1, 0);     int last = 0;     for (int i = k; i <= n; i++) {       int l = dp[i - k] + 1;       if (arr[i] - arr[l] <= m) last = i;       dp[i] = last;     }     return dp[n] == n;   }   int main() {     int n, k;     cin >> n >> k;     vector<int> arr(n + 1);     for (int i = 1; i <= n; i++) cin >> arr[i];     sort(arr.begin() + 1, arr.end());     int s = 0;     int g = 1e9 + 1;     int ans = -1;     while (s != g) {       int m = (s + g) / 2;       if (solve(arr, m, n, k)) {         g = m;         ans = m;       } else {         if (s == m) {           break;         }         s = m;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int light[3000];   int agr[3000];   int main() {     int n;     scanf( %d , &n);     int m = pow(2, n + 1) - 1;     for (int i = 2; i <= m; i++) {       scanf( %d , &light[i]);     }     int ans = 0;     for (int i = m; i >= 3; i--) {       if (i % 2 == 0) continue;       int a = light[i] + agr[i];       int b = light[i - 1] + agr[i - 1];       int c = a;       if (a != b) {         c = max(a, b);         ans += abs(b - a);       }       agr[i / 2] = c;       agr[(i - 1) / 2] = c;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   long long k, wyn;   long long tab[27][27];   map<long long, long long> odp[27][27];   void back1(int, int, long long);   void back2(int, int, long long);   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) cin >> tab[i][j];     }     back1(1, 1, tab[1][1]);     back2(n, m, k);     if (n == 1 && m == 1 && tab[1][1] == k)       cout << 1;     else       cout << wyn;     return 0;   }   void back1(int x, int y, long long akt) {     if (x + y == n + 1) {       odp[x][y][akt]++;       return;     }     if (x + 1 <= n) back1(x + 1, y, (akt ^ tab[x + 1][y]));     if (y + 1 <= m) back1(x, y + 1, (akt ^ tab[x][y + 1]));   }   void back2(int x, int y, long long akt) {     if (x + y == n + 1) {       wyn += odp[x][y][akt];       return;     }     if (x - 1 >= 1) back2(x - 1, y, (akt ^ tab[x][y]));     if (y - 1 >= 1) back2(x, y - 1, (akt ^ tab[x][y]));   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int calc(int a, int x, int n) { return max(0, min(x - (a + 1) / 2, n - a)); }   void solve(istream &in, ostream &out) {     int n, m, x, y, a, b;     in >> n >> m >> x >> y >> a >> b;     int d = gcd(a, b);     a /= d;     b /= d;     int t = min(n / a, m / b);     a *= t;     b *= t;     int x1 = calc(a, x, n);     int y1 = calc(b, y, m);     int x2 = x1 + a;     int y2 = y1 + b;     out << x1 <<     << y1 <<     << x2 <<     << y2 << endl;   }   int main() {     solve(cin, cout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string a, b;     cin >> a >> b;     n *= 2;     int n1 = 0, n2 = 0, q = 0;     for (int i = 0; i < n; ++i)       if (a[i] ==  1 )         if (b[i] ==  1 )           q = !q;         else           ++n1;       else if (b[i] ==  1 )         ++n2;     n1 += q;     if (n1 == n2 - 1 || n1 == n2)       cout <<  Draw ;     else if (n1 > n2)       cout <<  First ;     else       cout <<  Second ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[300010], p[300010], d[32];   int f[6000010][3], cnt = 1, ans;   void insert(int x, int y) {     f[x][2]++;     if (y > 30) return;     if (!f[x][d[y]])       f[x][d[y]] = ++cnt, insert(cnt, y + 1);     else       insert(f[x][d[y]], y + 1);   }   void dg(int x, int y) {     f[x][2]--;     if (y > 30) {       printf( %d  , ans);       return;     }     if (f[x][d[y]] && f[f[x][d[y]]][2])       dg(f[x][d[y]], y + 1);     else {       ans = ans + (1 << (30 - y));       dg(f[x][1 - d[y]], y + 1);     }   }   int main() {     int n, i, j, k;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     for (i = 1; i <= n; i++) {       scanf( %d , &p[i]);       j = p[i];       d[0] = 30;       while (j) {         d[d[0]--] = j % 2;         j /= 2;       }       for (k = d[0]; k > 0; k--) d[k] = 0;       insert(1, 1);     }     for (i = 1; i <= n; i++) {       j = a[i];       d[0] = 30;       ans = 0;       while (j) {         d[d[0]--] = j % 2;         j /= 2;       }       for (k = d[0]; k > 0; k--) d[k] = 0;       dg(1, 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool a[18][18];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) a[i][j] = 1;     }     map<string, int> mp;     string name;     vector<string> names(n);     for (int i = 0; i < n; i++) {       cin >> name;       mp[name] = i;       names[i] = name;     }     string s1, s2;     for (int i = 0; i < m; i++) {       cin >> s1 >> s2;       a[mp[s1]][mp[s2]] = 0;       a[mp[s2]][mp[s1]] = 0;     }     int res = 0;     vector<int> v;     vector<int> vres;     for (int i = 1; i < (1 << n); i++) {       v.clear();       for (int j = 0; j < n; j++) {         if ((1 << j) & i) {           v.push_back(j);         }       }       bool b = true;       for (int j = 0; j < v.size(); j++) {         for (int k = j + 1; k < v.size(); k++) {           if (!a[v[j]][v[k]]) {             b = false;             break;           }         }       }       if (b) {         if (v.size() > res) {           res = v.size();           vres = v;         }       }     }     cout << res << endl;     vector<string> team;     for (int i = 0; i < vres.size(); i++) {       team.push_back(names[vres[i]]);     }     sort(team.begin(), team.end());     for (int i = 0; i < team.size(); i++) {       if (i != 0) cout << endl;       cout << team[i];     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[2010], b[2010];   unordered_map<int, int> mp;   int main() {     int n;     scanf( %d , &n);     int ans = 0;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       mp[a[i]] = 1;     }     for (int i = 0; i < n; i++) {       scanf( %d , &b[i]);       mp[b[i]] = 1;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (mp[a[i] ^ b[j]] == 1) ans++;       }     }     if (ans % 2 == 1) {       puts( Koyomi );     } else {       puts( Karen );     }   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   int n, sum;   int cnt[100005], from[100005], to[100005], c[100005];   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) scanf( %d%d , &from[i], &to[i]);     for (int i = 1; i <= n; i++) scanf( %d , &c[i]);     for (int i = 1; i < n; i++) {       if (c[from[i]] != c[to[i]]) {         cnt[from[i]]++;         cnt[to[i]]++;         sum++;       }     }     for (int i = 1; i <= n; i++) {       if (cnt[i] == sum) {         printf( YES n%d n , i);         return 0;       }     }     printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int solve(int t) {     int a, b, c, rem = 0, sum = 0;     while (t != 0) {       rem = t % 10;       sum += rem;       t /= 10;     }     if (sum % 4 == 0) return 1;     return 0;   }   int main() {     int t, n, flag = 0;     cin >> t;     while (1) {       flag = solve(t);       if (flag == 1) {         cout << t <<   n ;         break;       } else         t++;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int power(long long int a, long long int b) {     if (b == 0) return 1;     if (b == 1) return a;     long long int r = power(a, b / 2) % 1000000007;     if (b % 2 == 0)       return (r * r) % 1000000007;     else       return (((r * r) % 1000000007) * a) % 1000000007;   }   int prime[1000009];   int sumprime[1000009];   void sieve(int n) {     prime[0] = prime[1] = 1;     for (int i = 2; i <= sqrt(n); i++) {       if (!prime[i]) {         for (int j = 2 * i; j <= n; j = j + i) {           prime[j]++;         }       }     }     for (int i = 1; i <= n; i++) {       if (!prime[i]) {         sumprime[i] = sumprime[i - 1] + 1;       } else {         sumprime[i] = sumprime[i - 1];       }     }   }   bool comp(const pair<long long int, long long int> &a,             const pair<long long int, long long int> &b) {     return (a.second < b.second);   }   const int N = 5 * 1e5 + 9;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     string s;     cin >> s;     int n = s.length();     int flag = 0;     map<char, int> mp;     mp[ A ]++;     mp[ H ]++;     mp[ I ]++;     mp[ M ]++;     mp[ O ]++;     mp[ o ]++;     mp[ T ]++;     mp[ U ]++;     mp[ V ]++;     mp[ v ]++;     mp[ W ]++;     mp[ w ]++;     mp[ X ]++;     mp[ x ]++;     mp[ Y ]++;     mp[ b ]++;     mp[ d ]++;     mp[ p ]++;     mp[ q ]++;     if (n % 2) {       char c = s[n / 2];       if (c ==  p  || c ==  q  || c ==  d  || c ==  b ) {         flag++;       }     }     for (int i = 0; i < n; i++) {       if (mp.find(s[i]) == mp.end()) {         flag++;         break;       }       if (s[i] ==  b ) {         if (s[n - i - 1] !=  d ) {           flag++;           break;         }         continue;       }       if (s[i] ==  d ) {         if (s[n - i - 1] !=  b ) {           flag++;           break;         }         continue;       }       if (s[i] ==  p ) {         if (s[n - i - 1] !=  q ) {           flag++;           break;         }         continue;       }       if (s[i] ==  q ) {         if (s[n - i - 1] !=  p ) {           flag++;           break;         }         continue;       }       if (s[i] != s[n - i - 1]) {         flag++;         break;       }     }     if (flag) {       cout <<  NIE n ;       return 0;     }     cout <<  TAK n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     std::string a;     std::getline(cin, a);     ;     std::string b;     std::getline(cin, b);     ;     int team1 = 0;     int team2 = 0;     for (int i = 0; i < a.size(); i = i + 2) {       if (a[i] == b[i]) {       } else if ((a[i] ==  8  && b[i] ==  [ ) || (a[i] ==  [  && b[i] ==  ( ) ||                  (a[i] ==  (  && b[i] ==  8 )) {         team1++;       } else {         team2++;       }     }     if (team1 == team2) {       cout <<  TIE ;     } else if (team1 > team2) {       cout <<  TEAM 1 WINS ;     } else {       cout <<  TEAM 2 WINS ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, x, y, z;     cin >> a >> b >> c >> x >> y >> z;     int a1, b1, c1, a2, b2, c2, m = 0, n = 0;     if (a > x) {       if (abs(a - x) >= 2) {         if ((a - x) % 2 == 0)           m = m + a - x;         else           m = m + a - x - 1;       }     } else       n = n + a - x;     if (b > y) {       if (abs(b - y) >= 2) {         if ((b - y) % 2 == 0)           m = m + b - y;         else           m = m + b - y - 1;       }     } else       n = n + b - y;     if (c > z) {       if (abs(c - z) >= 2) {         if ((c - z) % 2 == 0)           m = m + c - z;         else           m = m + c - z - 1;       }     } else       n = n + c - z;     if (m >= n * -2)       cout <<  Yes  << endl;     else       cout <<  No  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   int R, C;   string t[2222];   int s1[2222][2222];   int main() {     memset(s1, 0, sizeof(s1));     cin >> R >> C;     for (int r = 0; r < (int)R; r++) {       cin >> t[r];       for (int c = 0; c < (int)C; c++) {         if (t[r][c] ==  w ) {           s1[r + 1][c + 1]++;         }       }     }     for (int r = 0; r < (int)2221; r++) {       for (int c = 0; c < (int)2221; c++) {         s1[r + 1][c + 1] += (s1[r + 1][c] + s1[r][c + 1] - s1[r][c]);       }     }     int lo = 0;     int hi = max(R, C);     while (lo < hi - 1) {       int len = (lo + hi) / 2;       bool isSome = false;       for (int r = 0; r + len - 1 < max(R, C); r++) {         for (int c = 0; c + len - 1 < max(R, C); c++) {           if (s1[r + len][c + len] - s1[r + len][c] - s1[r][c + len] + s1[r][c] ==               s1[2221][2221]) {             isSome = true;             break;           }         }         if (isSome) break;       }       if (isSome)         hi = len;       else         lo = len;     }     cerr << hi << endl;     bool done = false;     for (int r = 0; r + hi - 1 < R; r++) {       for (int c = 0; c + hi - 1 < C; c++) {         int big = s1[r + hi][c + hi] - s1[r][c + hi] - s1[r + hi][c] + s1[r][c];         int small = 0;         if (hi != 1 && hi != 2) {           small = s1[r + hi - 1][c + hi - 1] - s1[r + 1][c + hi - 1] -                   s1[r + hi - 1][c + 1] + s1[r + 1][c + 1];         }         if (big - small == s1[2221][2221]) {           for (int i = 0; i < hi; i++) {             if (t[r][c + i] ==  . ) t[r][c + i] =  + ;             if (t[r + hi - 1][c + i] ==  . ) t[r + hi - 1][c + i] =  + ;             if (t[r + i][c] ==  . ) t[r + i][c] =  + ;             if (t[r + i][c + hi - 1] ==  . ) t[r + i][c + hi - 1] =  + ;           }           done = true;           break;         }         if (done) break;       }       if (done) break;     }     if (done) {       for (int r = 0; r < (int)R; r++) {         for (int c = 0; c < (int)C; c++) {           cout << t[r][c];         }         cout << endl;       }       cout << endl;     } else {       cout << -1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double EPS = 1e-9;   int N, K;   double L, V1, V2;   bool f(double t) {     if (L / V1 < t - EPS) return true;     int nGroups = N / K;     if (N % K != 0) nGroups++;     double distByBus = (t * V1 * V2 - L * V2) / (V1 - V2);     double tByBus = distByBus / V2;     double posBus = distByBus;     double tElapsed = tByBus;     nGroups--;     while (nGroups > 0) {       double posGroup = tElapsed * V1;       if (posGroup > L - EPS) break;       double tMeet = (posBus - posGroup) / (V1 + V2);       double posMeet = posGroup + tMeet * V1;       tElapsed += tMeet;       if (L - posMeet < distByBus - EPS) {         tElapsed += (L - posMeet) / V2;         posBus = L;       } else {         tElapsed += tByBus;         posBus = posMeet + distByBus;       }       nGroups--;     }     return tElapsed < t + EPS;   }   int main() {     cin >> N >> L >> V1 >> V2 >> K;     double lo = 0, hi = 1e9 + 5;     int i = 0;     while (hi - lo > EPS && i++ < 100) {       double mid = (lo + hi) / 2;       if (f(mid)) {         hi = mid;       } else         lo = mid;     }     cout << fixed << setprecision(10) << hi << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mod = 1e9 + 7;   int w[1007];   int n, x;   int d[107];   int N = 101;   int mat[107][107];   void mNoz(int (&a)[107][107], int (&b)[107][107], int (&c)[107][107]) {     long long res[107][107];     for (int i = 1; i <= N; ++i)       for (int j = 1; j <= N; ++j) res[i][j] = 0;     for (int i = 1; i <= N; ++i)       for (int k = 1; k <= N; ++k)         for (int j = 1; j <= N; ++j)           res[i][j] += ((long long)a[i][k] * b[k][j]) % mod;     for (int i = 1; i <= N; ++i)       for (int j = 1; j <= N; ++j) c[i][j] = res[i][j] % mod;   }   void pot(int (&a)[107][107], int (&c)[107][107], int k) {     int res[107][107];     for (int i = 1; i <= N; ++i)       for (int j = 1; j <= N; ++j) res[i][j] = i == j;     while (k > 0) {       if (k & 1) mNoz(res, a, res);       mNoz(a, a, a);       k /= 2;     }     for (int i = 1; i <= N; ++i)       for (int j = 1; j <= N; ++j) c[i][j] = res[i][j];   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> x;     for (int i = 1; i <= n; ++i) {       int a;       cin >> a;       mat[1][a]++;     }     mat[1][N] = mat[N][N] = 1;     for (int i = 1; i + 1 < N; ++i) mat[i + 1][i] = 1;     pot(mat, mat, x);     int wyn = mat[1][1] + mat[1][N];     wyn %= mod;     cout << wyn << endl;     return 0;   }
#include <bits/stdc++.h>   inline char nc() {     static char buf[1000000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline void read(int &x) {     static char c;     for (c = getchar(); !( 0  <= c && c <=  9 ); c = getchar())       ;     for (x = 0; ( 0  <= c && c <=  9 ); c = getchar()) x = x * 10 + c - 48;   }   void write(int x) {     if (x < 10) {       putchar( 0  + x);       return;     }     write(x / 10);     putchar( 0  + x % 10);   }   inline void writeln(int x) {     if (x < 0) putchar( - ), x *= -1;     write(x);     putchar(  n );   }   inline void writel(int x) {     if (x < 0) putchar( - ), x *= -1;     write(x);     putchar(   );   }   using namespace std;   int T, a[1007], sb, ans[1007 * 1007], n, tot;   void play(int x) {     ans[++tot] = x;     a[x] ^= a[x + 2], a[x + 2] ^= a[x], a[x] ^= a[x + 2];     a[x + 1] ^= a[x + 2], a[x + 2] ^= a[x + 1], a[x + 1] ^= a[x + 2];   }   signed main() {     read(T);     while (T--) {       read(n);       tot = 0;       for (int i = 1; i <= n; i++) read(a[i]);       for (int i = 1; i <= n - 2; i++) {         sb = i;         for (int j = i + 1; j <= n; j++)           if (a[j] < a[sb]) sb = j;         while (sb >= i + 2) play(sb - 2), sb -= 2;         if (sb == i + 1) {           play(i), play(i);           continue;         }       }       for (int i = n; i >= 3; i--) {         sb = i;         for (int j = i - 1; j; j--)           if (a[j] > a[sb]) sb = j;         while (sb <= i - 2) play(sb), play(sb), sb += 2;         if (sb == i - 1) {           play(sb - 1);           continue;         }       }       for (int i = 1; i < n; i++)         if (a[i] > a[i + 1]) tot = -1;       writeln(tot);       if (tot <= 0) continue;       for (int i = 1; i < tot; i++) writel(ans[i]);       writeln(ans[tot]);     }     return 0;   }