malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 5;   const long long MOD = 1e9 + 7;   set<char> seen;   void solve() {     int n;     cin >> n;     string a;     string b;     cin >> a >> b;     for (int i = 0; i < n; i++) {       if (a[i] > b[i]) {         cout <<  -1 n ;         return;       }     }     int ans = 0;     for (char c =  a ; c <=  t ; c++) {       char smallest =  z ;       for (int i = 0; i < n; i++) {         if (a[i] == c) {           if (a[i] != b[i]) smallest = min(smallest, b[i]);         }       }       if (smallest !=  z ) {         ans++;         for (int i = 0; i < n; i++) {           if (a[i] == c) {             if (a[i] != b[i]) {               a[i] = smallest;             }           }         }       }     }     cout << ans <<   n ;   }   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     int TC;     cin >> TC;     while (TC--) {       solve();     }   }
#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma G++ optimize(2)   using namespace std;   char nc() { return getchar(); }   int read() {     int x = 0, y = 1;     char c = nc();     while (!isdigit(c)) {       if (c ==  - ) y = -1;       c = nc();     }     while (isdigit(c)) {       x = (x << 1) + (x << 3) + (c ^ 48);       c = nc();     }     return x * y;   }   int n, p, q, up, prime[135], vst[135], bin[135];   unsigned int now = 1, C[135], ANS = 0;   void divide(int x, int op) {     for (int i = 1; i <= prime[0]; i++)       while (!(x % prime[i])) bin[i] += op, x /= prime[i];     if (op == 1 && x > 1) now *= (unsigned int)x;   }   unsigned int quick_pow(unsigned int x, int y) {     unsigned int re = 1;     while (y) {       if (y & 1) re = re * x;       x = x * x;       y >>= 1;     }     return re;   }   void pre() {     for (int i = 2; i <= up; i++) {       if (!vst[i]) prime[++prime[0]] = i;       for (int j = 1; j <= prime[0]; j++) {         if (i * prime[j] > up) break;         vst[i * prime[j]] = 1;         if (!(i % prime[j])) break;       }     }     C[0] = 1;     for (int i = 1; i <= up; i++) {       divide(n - i + 1, 1);       divide(i, -1);       C[i] = now;       for (int j = 1; j <= prime[0]; j++) C[i] *= quick_pow(prime[j], bin[j]);     }   }   int main() {     n = read();     p = read();     q = read();     up = min(n - 1, p);     pre();     for (int i = 1; i <= q; i++) {       unsigned int sm = 0, ha = 1;       for (int j = 0; j <= up; j++) sm += C[j] * ha, ha *= (unsigned int)i;       ANS ^= (sm * (unsigned int)i);     }     cout << ANS;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   string s;   long long ans;   bool flag;   struct A {     int id, p, s;   };   bool comp(A a, A b) {     if (a.p > b.p) return true;     return false;   }   void solve() {     cin >> n >> m >> k;     vector<int> p(n);     for (auto i = 0; i < n; i++) cin >> p[i];     ;     vector<int> s(n);     for (auto i = 0; i < n; i++) cin >> s[i];     ;     vector<A> v(n);     for (auto i = 0; i < n; i++) {       v[i].id = i + 1;       v[i].s = s[i];       v[i].p = p[i];     }     sort(v.begin(), v.end(), comp);     unordered_set<int> school;     unordered_set<int> kid;     for (auto i = 0; i < n; i++) {       if (school.find(v[i].s) == school.end()) {         school.insert(v[i].s);         kid.insert(v[i].id);       }       int mm = school.size();       if (mm == m) break;     }     vector<int> K(k);     for (auto i = 0; i < k; i++) cin >> K[i];     ;     int count = 0;     for (auto i = 0; i < k; i++) {       if (kid.find(K[i]) == kid.end()) {         count++;       }     }     cout << count;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 3, mod = 1e9 + 7, inf = 3e18 + 7;   long long tc, n, m, a, b, c, d, i, j, k;   long long A[N], odd[N], even[N];   string s[N];   vector<long long> vec;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> tc;     while (tc--) {       cin >> n;       long long sum = 0, ans = 0, mx;       for (i = 1; i <= n; i++) cin >> A[i], sum += (i % 2 ? A[i] : 0);       A[n + 1] = A[n];       for (i = 2; i <= n; i += 2) even[i] = even[i - 2] + A[i] - A[i - 1];       for (i = 2; i <= n; i += 2) odd[i] = odd[i - 2] + A[i] - A[i + 1];       if (n % 2) n--;       for (i = n, mx = even[n]; i > 0; i -= 2)         mx = max(mx, even[i]), ans = max(ans, mx - even[i - 2]);       for (i = n, mx = odd[n]; i > 0; i -= 2)         mx = max(mx, odd[i]), ans = max(ans, mx - odd[i - 2]);       cout << ans + sum << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long x, y;     cin >> x >> y;     long long n;     cin >> n;     n %= 6;     if (n == 0) n = 6;     long long data[7];     data[1] = x;     data[2] = y;     for (int i = 3; i <= 6; i++) {       data[i] = data[i - 1] - data[i - 2];     }     for (int i = 1; i <= 6; i++)       if (data[i] < 0) data[i] += 1000000007;     if (data[n] < 0) data[n] += 1000000007;     cout << data[n] % 1000000007 <<   n ;     return 0;   }
#include <bits/stdc++.h>   long long read() {     long long res = 0, flag = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) flag = -1;       ch = getchar();     }     while (isdigit(ch)) res = res * 10 + ch - 48, ch = getchar();     return res * flag;   }   void print(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) print(x / 10);     putchar(x % 10 + 48);   }   const long long N = 5000 + 5;   long long n, k, a[N], c[N];   std::vector<long long> g[N];   void solution() {     n = read(), k = read();     long long tot = 0;     for (long long i = (1); i <= (n); ++i) a[i] = read(), g[a[i]].push_back(i);     for (long long i = (1); i <= (N - 1); ++i) {       if (g[i].size() > k) {         puts( NO );         return;       }       for (auto v : g[i]) c[v] = ++tot, tot %= k;     }     puts( YES );     for (long long i = (1); i <= (n); ++i) print(c[i]), putchar(   );     putchar(  n );   }   signed main() {     42;     solution();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       vector<long long> v(n), vec;       for (int i = 0; i < n; i++) cin >> v[i];       for (int i = 0; i < n; i++) {         if (v[i] == -1) continue;         if (i - 1 >= 0 && v[i - 1] == -1) vec.push_back(v[i]);         if (i + 1 < n && v[i + 1] == -1) vec.push_back(v[i]);       }       sort(vec.begin(), vec.end());       long long num, res = -1;       if (vec.size() == 0) num = 1;       if (vec.size() == 1) num = vec[0];       if (vec.size() >= 2) num = (vec[vec.size() - 1] + vec[0]) / 2;       for (int i = 0; i < n; i++) {         if (v[i] == -1) v[i] = num;       }       for (int i = 0; i < n - 1; i++) {         res = max(res, abs(v[i] - v[i + 1]));       }       cout << res <<     << num << endl;     }     return 0;   }
// annotshy      #include <bits/stdc++.h>   #define Task  CF    #define pb push_back   #define MOD 1000000007   #define F first   #define S second   #define int long long      using namespace std;      const int maxn = 2005;      int n, m, w;   int a[maxn][maxn];   int dx[5] = {1, 0, -1, 0};   int dy[5] = {0, 1, 0, -1};   long long dp[maxn][maxn], to1 = 0, to2 = 0;      long long BFS(int i, int j) {     queue<pair<int, int> > Q;     Q.push({i, j});     for(int p = 1; p <= n; ++ p) {       for(int q = 1; q <= m; ++ q) dp[p][q] = 1e18;     }     dp[i][j] = 0;     while(Q.size()) {       int u = Q.front().F;       int v = Q.front().S;       Q.pop();       for(int k = 0; k < 4; ++ k) {         int x = u + dx[k];         int y = v + dy[k];         if(x < 1 || y < 1 || x > n || y > m || a[x][y] == -1) continue;         if(dp[x][y] > dp[u][v] + w) {           dp[x][y] = dp[u][v] + w;           Q.push({x, y});         }       }     }     long long res = 1e18;     if(i == 1 && j == 1) to1 = dp[n][m];     if(i == n && j == m) to2 = dp[1][1];     for(int i = 1; i <= n; ++ i) {       for(int j = 1; j <= m; ++ j) if(a[i][j] > 0) {         res = min(res, dp[i][j] + a[i][j]);       }     }     return res;   }      void Solve() {     cin >> n >> m >> w;     for(int i = 1; i <= n; ++ i) {       for(int j = 1; j <= m; ++ j) cin >> a[i][j];     }     long long res1 = BFS(1, 1);     long long res2 = BFS(n, m);     if(res1 + res2 >= 1e18 && to1 == 1e18 && to2 == 1e18) cout << - 1 <<   n ;     else cout << min({to1, to2, res1 + res2}) <<   n ;   }      signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     if(fopen(Task .inp ,  r )) {       freopen(Task .inp ,  r , stdin);       freopen(Task .out ,  w , stdout);     }     int test = 1;   //  cin >> test;     while(test --) {       Solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int mx, n, m, sum, hh, la, v[1000001], a[100001], sz[1000010], tot, e[10000001],       nt[10000001], hd[1000010];   void build(int x, int y) {     tot++;     e[tot] = y;     nt[tot] = hd[x];     hd[x] = tot;   }   int main() {     int i, j, k;     mx = 1e6;     scanf( %d%d , &n, &m);     la = m;     m = m * (m + 1) / 2;     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + n + 1);     for (i = 1; i <= n; i++)       for (j = 1; j < i; j++) sz[a[i] - a[j]]++;     for (i = 1; i <= n; i++)       for (j = 1; j < i; j++)         if (sz[a[i] - a[j]] <= m) build(a[i] - a[j], a[j]);     for (i = 1; i <= mx + 1; i++) {       sum = 0;       for (j = i; j <= mx + 1; j += i) sum += sz[j];       if (sum > m) continue;       for (j = i; j <= mx + 1; j += i)         for (k = hd[j]; k; k = nt[k])           if (v[e[k]] != i) {             v[e[k]] = i;             hh++;           }       if (hh <= la) return printf( %d , i), 0;       hh = 0;     }   }
#include <bits/stdc++.h>   using namespace std;   long long n, cv;   long long level[3501];   long long vis[3501] = {};   vector<long long> graph[3501];   vector<long long> cycles[3501];   vector<long long> z;   void dfs_cycle(long long u, long long p, long long color[], long long mark[],                  long long par[], long long& cyclenumber) {     if (color[u] == 2) {       return;     }     if (color[u] == 1) {       cyclenumber++;       long long cur = p;       mark[cur] = cyclenumber;       while (cur != u) {         cur = par[cur];         mark[cur] = cyclenumber;       }       return;     }     par[u] = p;     color[u] = 1;     for (long long v : graph[u]) {       if (v == par[u]) {         continue;       }       dfs_cycle(v, u, color, mark, par, cyclenumber);     }     color[u] = 2;   }   void printCycles(long long edges, long long mark[], long long& cyclenumber) {     for (long long i = 1; i <= edges; i++) {       if (mark[i] != 0) cycles[mark[i]].push_back(i);     }     for (long long i = 1; i <= cyclenumber; i++) {       for (long long x : cycles[i]) z.push_back(x);     }   }   void bfs(long long s) {     queue<long long> q;     q.push(s);     level[s] = 0;     vis[s] = 1;     while (!q.empty()) {       long long p = q.front();       q.pop();       for (long long i = 0; i < graph[p].size(); i++) {         if (vis[graph[p][i]] == 0) {           level[graph[p][i]] = min(level[graph[p][i]], level[p] + 1);           q.push(graph[p][i]);           vis[graph[p][i]] = 1;         }       }     }   }   void quickly_quickly_kro() {     cin >> n;     for (long long i = 1; i < n + 1; i++) {       long long a, b;       cin >> a >> b;       graph[a].push_back(b);       graph[b].push_back(a);     }     long long color[3501];     long long par[3501];     long long mark[3501];     long long cyclenumber = 0;     long long edges = n;     dfs_cycle(1, 0, color, mark, par, cyclenumber);     printCycles(edges, mark, cyclenumber);     for (long long i = 1; i < n + 1; i++) level[i] = (long long)2e18;     for (auto k : z) {       for (long long i = 1; i < n + 1; i++) {         vis[i] = 0;       }       bfs(k);     }     for (long long i = 1; i < n + 1; i++) {       cout << level[i] <<    ;     }   }   signed main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     t = 1;     while (t--) {       quickly_quickly_kro();       cout <<   n ;     }     return 0;   }
#include <iostream>   #include <map>   #include <set>   #include <queue>   #include <stack>   #include <algorithm>   #include <vector>   #include <string>   #include <iomanip>   #include <cmath>   #include <cstdio>   #include <cstring>   #include <climits>   #define Buff std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)   #define ll long long   #define inf LONG_LONG_MAX   #define Inf INT_MAX   #define endl   n       using namespace std;      const int Maxn = 1e3 + 10;   const ll Mod = 1e9 + 7;      int t, n;   char bd[Maxn][Maxn];   bool firPos1;   int posX1, posX2, posX3, posX4;   int posY1, posY2, posY3, posY4;   int dis;      void work()   {       firPos1 = false;       cin >> n;       for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)       {           cin >> bd[i][j];           if (bd[i][j] ==  * )           {               if (firPos1 == false)               {                   posX1 = i;                   posY1 = j;                   firPos1 = true;               }else               {                   posX2 = i;                   posY2 = j;               }           }       }       if (posX2 == posX1)       {           dis = 1;           if (posX1 - dis >= 1)           {               posX3 = posX1 - dis;               posX4 = posX1 - dis;               posY3 = posY1;               posY4 = posY2;           }else           {               posX3 = posX1 + dis;               posX4 = posX1 + dis;               posY3 = posY1;               posY4 = posY2;           }       }else       if (posY2 == posY1)       {           dis = 1;           if (posY1 - dis >= 1)           {               posY3 = posY1 - dis;               posY4 = posY1 - dis;               posX3 = posX1;               posX4 = posX2;           }else           {               posY3 = posY1 + dis;               posY4 = posY1 + dis;               posX3 = posX1;               posX4 = posX2;           }       }else       {           int minx = min(posX1,posX2);           int maxx = max(posX1,posX2);           int miny = min(posY1,posY2);           int maxy = max(posY1,posY2);           posX1 = minx;           posY1 = miny;           posX2 = minx;           posY2 = maxy;           posX3 = maxx;           posY3 = miny;           posX4 = maxx;           posY4 = maxy;       }       bd[posX1][posY1] =  * ;       bd[posX2][posY2] =  * ;       bd[posX3][posY3] =  * ;       bd[posX4][posY4] =  * ;       for (int i = 1; i <= n; i++)       {           for (int j = 1; j <= n; j++)               cout << bd[i][j];           cout << endl;       }   }      int main()   {       Buff;       cin >> t;       while (t--)           work();       return 0;   }
#include <bits/stdc++.h>   int main() {     int t, i, j, k;     scanf( %d , &t);     int ranges[t][2000];     int len[t];     for (i = 0; i < t; ++i) {       scanf( %d , &len[i]);       for (j = 0; j < (2 * len[i]); j += 2) {         scanf( %d %d , &ranges[i][j], &ranges[i][j + 1]);       }     }     for (i = 0; i < t; ++i) {       int num[len[i]];       for (j = 0; j < len[i]; ++j) {         num[j] = j + 1;       }       int sort[2 * len[i]];       int c = 0, diff = 0;       while (c < 2 * len[i]) {         for (j = 0; j < (2 * len[i]); j += 2) {           if (ranges[i][j + 1] - ranges[i][j] == diff) {             sort[c] = ranges[i][j];             sort[c + 1] = ranges[i][j + 1];             c += 2;           }         }         diff += 1;       }       for (j = 0; j < (2 * len[i]); j += 2) {         int d;         diff = sort[j + 1] - sort[j];         if (diff == 0) {           d = sort[j];           num[d - 1] = 0;           printf( %d %d %d n , sort[j], sort[j + 1], d);         } else {           c = sort[j + 1];           while (c >= sort[j]) {             if (num[c - 1] != 0) {               d = c;               num[c - 1] = 0;               printf( %d %d %d n , sort[j], sort[j + 1], d);               break;             }             c -= 1;           }         }       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int pp(int n) {     for (int i = 2; i <= floor(sqrt(n)); i++) {       if (n % i == 0) return i;     }     return 1;   }   void solve() {     long long int n, k;     cin >> n >> k;     if (k > n)       cout << max(0ll, n - k / 2) << endl;     else       cout << max(0ll, (k - 1) / 2) << endl;   }   int main() {     int t = 1;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     ios::sync_with_stdio(0), cin.tie(0);     ;     int n, m;     cin >> n >> m;     vector<vector<char>> v(n, vector<char>(m));     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> v[i][j];     bool st = 1;     int mx = 0;     set<int> se;     for (int i = 0; i < n; i++) {       int s = -1, g = -1;       for (int j = 0; j < m; j++) {         if (v[i][j] ==  G )           g = j;         else if (v[i][j] ==  S )           s = j;       }       if (s < g)         st = 0;       else         se.insert(s - g);     }     if (st)       cout << se.size();     else       cout << -1;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     priority_queue<int, vector<int>, greater<int> > a;     int temp;     int n, i;     int sum = 0;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &temp);       a.push(temp);     }     temp = -1;     while (!a.empty()) {       if (a.top() == temp) {         printf( -1 n );         return 0;       } else if (a.top() == 0) {         a.pop();       } else {         temp = a.top();         a.pop();         if (!a.empty() && a.top() == temp) {           sum++;           a.pop();         }       }     }     printf( %d n , sum);     return 0;   }
#include <bits/stdc++.h>   int main() {     using namespace std;     int num, t1, t2, k;     cin >> num >> t1 >> t2 >> k;     double ms[1000];     double ms2[1000];     for (int i = 0; i < 1000; i++) {       ms[i] = 0;       ms2[i] = 0;     }     for (int i = 0; i < num; i++) {       int a, b;       cin >> a >> b;       double s1, s2;       s1 = a * t1 * ((100 - k) / 100.0) + t2 * b;       s2 = b * t1 * ((100 - k) / 100.0) + t2 * a;       if (s1 >= s2)         ms[i] = s1;       else         ms[i] = s2;       ms2[i] = ms[i];     }     stable_sort(ms, ms + num);     int same;     for (int i = num - 1; i >= 0; i--) {       if (i < num - 1 && ms[i] == ms[i + 1])         same++;       else         same = 0;       int p;       int pass = same;       for (int j = 0; j < num; j++) {         if (ms2[j] == ms[i]) {           if (pass > 0) {             pass--;             continue;           }           p = j + 1;           break;         }       }       double d = ((int)(ms[i] * 100 + 0.5)) / 100.0;       printf( %d %3.2f n , p, d);     }   }
#include <bits/stdc++.h>   using namespace std;   long long int x[1000007], y[1000007], z[1000007], n;   string s, S;   vector<long long int> v;   int main() {     {       long long int a = 0, b = 0, c = 0, d, e, f, g, i, j, k, l, m, p, q, r, u, w,                     t, tc, in, mod, loc, diff, val, sz, lo, hi, mid,                     mn = 2134567891, mx = 0, sum = 0, ans = 0;       cin >> s;       l = s.size();       for (i = 0; i < l; i++)         if (s[i] ==  a ) a++;       if (a * 2 > l)         cout << l << endl;       else         cout << a * 2 - 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double PI = 3.141592653589793238462643l;   void solve();   int main() {     solve();     return 0;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   void solve() {     long long a, b, x1, y1, x2, y2;     cin >> a >> b >> x1 >> y1 >> x2 >> y2;     long long ans1, ans2;     long long eps11 = 0, eps12 = 0, eps21 = 0, eps22 = 0;     if (x1 + y1 < 0) eps11 = -2 * a;     if (x2 + y2 < 0) eps12 = -2 * a;     if (x1 - y1 < 0) eps21 = -2 * b;     if (x2 - y2 < 0) eps22 = -2 * b;     ans1 = (x1 + y1 + eps11) / (2 * a) - (eps12 + x2 + y2) / (2 * a);     ans2 = (eps21 + x1 - y1) / (2 * b) - (eps22 + x2 - y2) / (2 * b);     if (ans1 < 0) ans1 = -ans1;     if (ans2 < 0) ans2 = -ans2;     cout << max(ans1, ans2);   }
#include <bits/stdc++.h>   using namespace std;   long long a, b, c, d, L, R, k, l, kk, ll, l1, r1, l2, r2, x, gcd, lcm;   inline long long exgcd(long long a, long long b, long long &x, long long &y) {     if (!b) {       return x = 1, y = 0, a;     }     long long t = exgcd(b, a % b, y, x);     return y -= a / b * x, t;   }   int main() {     scanf( %lld%lld%lld%lld%lld%lld , &a, &c, &b, &d, &L, &R);     gcd = exgcd(a, b, k, l), lcm = a * b / gcd;     if ((d - c) % gcd) return puts( 0 ), 0;     k *= (d - c) / gcd, kk = lcm / a;     l *= (c - d) / gcd, ll = lcm / b;     l1 = max(0ll, (L - c) / a + (L - c > 0 ? (!!((L - c) % a)) : 0));     r1 = (R - c) / a - (R - c < 0 ? (!!((R - c) % a)) : 0);     l2 = max(0ll, (L - d) / b + (L - d > 0 ? (!!((L - d) % b)) : 0));     r2 = (R - d) / b - (R - d < 0 ? (!!((R - d) % b)) : 0);     x = max((l1 - k) / kk, (l2 - l) / ll);     k += x * kk, l += x * ll;     if (k < l1 || l < l2) k += kk, l += ll;     if (k > r1 || l > r2) return puts( 0 ), 0;     printf( %lld n , min((r1 - k) / kk, (r2 - l) / ll) + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long t = 1;   template <class myType>   void print_arr(myType &arr, long long L, string sep) {     for (long long(i) = (0); (i) < (L); ++(i)) {       cout << arr[i];       if (i < L - 1) {         cout << sep;       }     }     cout <<   n ;     return;   }   long long merge(long long arr[], long long temp_arr[], long long left,                   long long mid, long long right) {     long long i, j, k;     i = left;     j = mid + 1;     k = left;     long long inv_count = 0;     while (i <= mid && j <= right) {       if (arr[i] <= arr[j]) {         temp_arr[k] = arr[i];         k += 1;         i += 1;       } else {         temp_arr[k] = arr[j];         inv_count += (mid - i + 1);         k += 1;         j += 1;       }     }     while (i <= mid) {       temp_arr[k] = arr[i];       k += 1;       i += 1;     }     while (j <= right) {       temp_arr[k] = arr[j];       k += 1;       j += 1;     }     for (long long loop_var = left; loop_var <= right; loop_var++) {       arr[loop_var] = temp_arr[loop_var];     }     return inv_count;   }   long long _mergeSort(long long arr[], long long temp_arr[], long long left,                        long long right) {     long long inv_count = 0;     if (left < right) {       long long mid;       mid = (left + right) / 2;       inv_count += _mergeSort(arr, temp_arr, left, mid);       inv_count += _mergeSort(arr, temp_arr, mid + 1, right);       inv_count += merge(arr, temp_arr, left, mid, right);     }     return inv_count;   }   long long mergeSort(long long arr[], long long n) {     long long temp_arr[n];     for (long long(i) = (0); (i) < (n); ++(i)) temp_arr[i] = 0;     return _mergeSort(arr, temp_arr, 0, n - 1);   }   void solve() {     long long n;     cin >> n;     long long a[n];     for (long long(i) = (0); (i) < (n); ++(i)) cin >> a[i];     long long invs, invs2;     long long b[n];     for (long long(i) = (0); (i) < (n); ++(i)) b[i] = a[i];     invs = mergeSort(b, n);     long long ans = 0;     long long p;     for (long long(i) = (0); (i) < (30); ++(i)) {       p = (1 << i);       for (long long(j) = (0); (j) < (n); ++(j)) b[j] = a[j] ^ p;       invs2 = mergeSort(b, n);       if (invs2 < invs) {         ans += p;       }     }     for (long long(j) = (0); (j) < (n); ++(j)) b[j] = a[j] ^ ans;     cout << mergeSort(b, n) <<     << ans <<   n ;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     while (t--) {       solve();     }     return 0;   }