malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   void incr(long long &st, long long &en, long long &k, long long val) {     en++;     if (val <= k) {       k++;     }   }   void decr(long long &st, long long &en, long long &k, long long val) {     long long sz = en - st + 1;     if (val < k) {       k -= val;       sz = sz - val;     } else {       sz = val;     }     st = 1;     en = sz + st - 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, k, m, t;     cin >> n >> k >> m >> t;     long long st = 1, en = n;     while (t--) {       long long w, val;       cin >> w >> val;       if (w) {         incr(st, en, k, val);         cout << (en - st + 1) <<     << k << endl;       } else {         decr(st, en, k, val);         cout << (en - st + 1) <<     << k << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Medianer {     priority_queue<int> low;     priority_queue<int, vector<int>, greater<int> > high;     Medianer() {}     int getMedian() { return low.top(); }     void insert(int a) {       if (low.empty())         low.push(a);       else if (a > low.top()) {         high.push(a);       } else         low.push(a);       while (low.size() > high.size()) {         high.push(low.top());         low.pop();       }       while (low.size() < high.size()) {         low.push(high.top());         high.pop();       }     }     size_t size() { return low.size() + high.size(); }   };   Medianer *merge(Medianer *a, Medianer *b) {     if (a->size() < b->size()) swap(a, b);     while (!b->low.empty()) {       a->insert(b->low.top());       b->low.pop();     }     while (!b->high.empty()) {       a->insert(b->high.top());       b->high.pop();     }     delete b;     return a;   }   int main() {     int N;     cin >> N;     vector<int> data(N, 0);     copy_n(istream_iterator<int>(cin), N, data.begin());     vector<Medianer *> meds;     for (int i = 0; i < N; ++i) {       Medianer *cur = new Medianer();       cur->insert(data[i]);       while (!meds.empty() && cur->getMedian() < meds.back()->getMedian()) {         cur = merge(meds.back(), cur);         meds.pop_back();       }       meds.push_back(cur);     }     unsigned long long ret = 0;     for (int i = 0, j = 0; i < (int)meds.size(); ++i) {       for (int k = 0; k < (int)meds[i]->size(); ++k, ++j) {         ret += abs(data[j] - meds[i]->getMedian());       }       delete meds[i];     }     cout << ret;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   class fenwick_tree {    private:     int n;     vector<T> fenw;       public:     fenwick_tree(int _n) : n(_n) { fenw.resize(n); }     size_t size() { return n; }     void update(int x, T val) {       while (x < n) {         fenw[x] += val;         x |= (x + 1);       }     }     void update(int x, int y, T val) {       update(x, +val);       update(y + 1, -val);     }     T query(int x) {       T ans = 0;       while (x >= 0) {         ans += fenw[x];         x = (x & (x + 1)) - 1;       }       return ans;     }   };   struct station {     int x, r, f;   };   int n, k, cur = 0;   vector<station> stations, sorted_stations;   map<int, int> mp;   fenwick_tree<int> fenw(0);   long long solve(int l, int r) {     if (l == r) {       return 0;     }     int mid = (l + r) / 2;     long long ans = solve(l, mid) + solve(mid + 1, r);     int i = l, j = l;     for (int t = mid + 1; t <= r; t++) {       while (j <= mid && stations[j].f <= stations[t].f + k) {         fenw.update(mp[stations[j].x - stations[j].r],                     mp[stations[j].x + stations[j].r], +1);         j++;       }       while (i < j && stations[i].f < stations[t].f - k) {         fenw.update(mp[stations[i].x - stations[i].r],                     mp[stations[i].x + stations[i].r], -1);         i++;       }       ans += fenw.query(mp[stations[t].x]);     }     for (int t = i; t < j; t++) {       fenw.update(mp[stations[t].x - stations[t].r],                   mp[stations[t].x + stations[t].r], -1);     }     int t = l;     i = l;     j = mid + 1;     while (i <= mid || j <= r) {       if (i > mid) {         sorted_stations[t++] = stations[j++];       } else if (j > r) {         sorted_stations[t++] = stations[i++];       } else if (stations[i].f < stations[j].f) {         sorted_stations[t++] = stations[i++];       } else {         sorted_stations[t++] = stations[j++];       }     }     for (int t = l; t <= r; t++) {       stations[t] = sorted_stations[t];     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> k;     set<int> st;     for (int i = 0; i < n; i++) {       int x, r, f;       cin >> x >> r >> f;       stations.push_back({x, r, f});       st.insert(x);       st.insert(x - r);       st.insert(x + r);     }     for (auto &x : st) {       mp[x] = cur++;     }     sort(stations.begin(), stations.end(),          [](const station &a, const station &b) { return a.r < b.r; });     sorted_stations.resize(n);     fenw = fenwick_tree<int>(cur);     cout << solve(0, n - 1) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, x, y, n;     cin >> t;     for (int i = 0; i < t; ++i) {       cin >> x >> y >> n;       if (n % x > y) {         n = n - (n % x - y);       } else if (n % x != y) {         n = n + (y - n % x) - x;       }       cout << n << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int st(int x, int pos) { return x = x | (1 << pos); }   int Reset(int x, int pos) { return x = x & ~(1 << pos); }   int main() {     long long x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     if (x1 == x2) {       cout << 4 + 2 * (abs(y1 - y2) + 1) << endl;     } else if (y1 == y2) {       cout << 4 + 2 * (abs(x1 - x2) + 1) << endl;     } else       cout << (abs(x1 - x2) + 1 + abs(y1 - y2) + 1) * 2 << endl;   }
#include <bits/stdc++.h>   using namespace std;   int cnt[11], l[11];   int main() {     for (int i = 0; i < 6; i++) {       scanf( %d , &l[i]);       cnt[l[i]]++;     }     int ok = 0;     for (int i = 1; i < 10; i++)       if (cnt[i] >= 4) {         ok = 1;         cnt[i] -= 4;       }     if (ok) {       int a = -1, b = -1;       for (int i = 1; i < 10; i++)         if (cnt[i]) {           if (a == -1)             a = i;           else             b = i;         }       if (b == -1) b = a;       if (a < b)         printf( Bear n );       else         printf( Elephant n );     } else       printf( Alien n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007LL;   int n;   int fn[300005];   int sons[300005];   vector<int> edges[300005];   void dfs(int u) {     if (edges[u].empty())       sons[u] = 1;     else {       for (int i = 0; i < edges[u].size(); ++i) {         int v = edges[u][i];         dfs(v);         sons[u] += sons[v];       }     }   }   int dfs2(int u) {     int maxv = 0;     int sum = 0;     if (edges[u].empty()) {       return 1;     }     for (int i = 0; i < edges[u].size(); ++i) {       int v = edges[u][i];       int res = dfs2(v);       sum += res - 1;       maxv = max(maxv, sons[u] - (sons[v] - res));     }     if (fn[u] == 0) {       return sum + 1;     } else {       return maxv;     }   }   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       scanf( %d , &fn[i]);     }     for (int i = 2; i <= n; ++i) {       int f;       scanf( %d , &f);       edges[f].push_back(i);     }     dfs(1);     cout << dfs2(1) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, r;     cin >> n;     if (n == 0) {       cout <<  1  << endl;       return 0;     }     r = n % 4;     if (r == 1) {       cout <<  8  << endl;     } else if (r == 2) {       cout <<  4  << endl;     } else if (r == 3) {       cout <<  2  << endl;     } else if (r == 0) {       cout <<  6  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e6 + 10;   const long long mod = 998244353;   double eps = 1e-10;   void in(long long &x) {     x = 0;     char c = getchar();     long long y = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) y = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + c -  0 ;       c = getchar();     }     x *= y;   }   void o(long long x) {     if (x < 0) {       x = -x;       putchar( - );     }     if (x > 9) o(x / 10);     putchar(x % 10 +  0 );   }   long long gcd(long long x, long long y) {     if (y == 0)       return x;     else       return gcd(y, x % y);   }   long long s, x;   long long cal(long long x) {     long long res = 0;     for (long long i = 0; i < 50; i++) {       if (x & ((long long)1 << i)) res++;     }     return res;   }   signed main() {     in(s);     in(x);     s -= x;     long long ans;     if (s & 1 || s < 0) {       ans = 0;     } else if ((s >> 1) & x) {       ans = 0;     } else if (x == 0 && s == 0) {       ans = 0;     } else {       ans = (long long)1 << cal(x);       ans -= 2 * (s == 0);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e2 + 7;   const long long mod = 1e9 + 7;   int a[N];   int main() {     int n;     cin >> n;     for (int i = (1); i < (n + 1); ++i) scanf( %d , a + i);     sort(a + 1, a + 1 + n);     if (n == 0) {       cout <<  YES n1 n1 n3 n3 n ;     } else if (n == 1) {       printf( YES n%d n%d n%d , a[1], 3 * a[1], 3 * a[1]);     } else if (n == 2) {       a[3] = 4 * a[1] - a[2];       a[4] = a[2] + a[3] - a[1];       if (a[3] < a[1] || a[4] < a[2] || a[4] < a[3]) {         cout <<  NO ;         return 0;       }       printf( YES n%d n%d , a[3], a[4]);     } else if (n == 3) {       a[4] = a[2] + a[3] - a[1];       if (2 * (a[4] - a[1]) == a[2] + a[3]) {         printf( YES n%d , a[4]);         return 0;       }       a[4] = a[1] + a[3] - a[2];       if (2 * (a[3] - a[1]) == a[2] + a[4]) {         printf( YES n%d , a[4]);         return 0;       }       a[4] = a[1] + a[2] - a[3];       if (2 * (a[3] - a[4]) == a[1] + a[2]) {         printf( YES n%d , a[4]);         return 0;       }       cout <<  NO ;     } else if (n == 4) {       if (2 * (a[2] + a[3]) == (a[1] + a[2] + a[3] + a[4]) &&           (a[2] + a[3]) == 2 * (a[4] - a[1]))         cout <<  YES  << endl;       else         cout <<  NO ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, x, y, a, b;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x >> y;       if (x < 0)         a++;       else         b++;     }     cout << (a < 2 || b < 2 ?  Yes  :  No );   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = (long long)1e18;   const long long mod = (long long)1e9 + 7;   const double eps = (double)1e-9;   const double pi = acos(-1.0);   const int dx[] = {0, 0, 1, 0, -1};   const int dy[] = {0, 1, 0, -1, 0};   const int N = 300500;   int main() {     cin.tie(NULL);     cout.tie(NULL);     ios_base::sync_with_stdio(false);     vector<int> v;     v.push_back(1);     v.push_back(2);     while (v.size() < (int)1e6) {       int x = v.back();       if (x % 2 == 0) {         v.push_back(x + x);         v.push_back(x + x + 1);       } else {         v.push_back(x + x - 1);         v.push_back(x + x);       }     }     int n;     cin >> n;     for (int i : v)       if (i == n) {         cout << 1;         return 0;       }     cout << 0;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000050;   bool arr[N];   int main() {     int n, x;     cin >> n;     vector<int> v;     for (int i = 0; i < n; i++) {       cin >> x;       v.push_back(x);     }     sort(v.begin(), v.end());     if (v.size() == 1)       cout << 0 <<   n ;     else {       cout << min(v[v.size() - 2] - v[0], v[v.size() - 1] - v[1]) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     char grid[n][m];     int x1 = 1e9, y1 = 1e9, x2 = 0, y2 = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> grid[i][j];         if (grid[i][j] ==  X )           x1 = min(x1, i), y1 = min(y1, j), x2 = max(x2, i), y2 = max(y2, j);       }     bool ok = true;     for (int i = x1; i <= x2; i++)       for (int j = y1; j <= y2; j++)         if (grid[i][j] !=  X ) ok = false;     if (ok)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int dp[1000005];   int a[30];   int main() {     int t, k, i, j, n, m, x, y, q, c, d;     dp[0] = 0;     dp[1] = 0;     for (i = 2; i < 1000005; i++)       dp[i] = dp[i / 2] + dp[i - i / 2] + i / 2 * 1LL * (i - i / 2);     cin >> k;     if (k == 0) {       cout <<  a ;       return 0;     }     for (i = 0; i < 26 && k; i++) {       int low = 0, high = 1000000, mid;       while (low < high) {         mid = low + (high - low + 1) / 2;         if (dp[mid] <= k)           low = mid;         else           high = mid - 1;       }       a[i] = low;       k -= dp[low];     }     for (i = 0; i < 26; i++) {       char ch =  a  + i;       if (a[i])         while (a[i]--) cout << ch;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int vis[7], sum[7];   string a[7], t[7];   vector<string> ans(10,  { ), now;   void solve() {     now.clear();     for (int i = 1; i <= 6; i++) sum[i] = (int)t[i].size();     if (sum[2] <= sum[1] || sum[2] <= sum[3] || sum[5] <= sum[4] ||         sum[5] <= sum[6])       return;     if (t[1][0] != t[4][0] || t[1][t[1].size() - 1] != t[5][0] ||         t[2][0] != t[4][t[4].size() - 1])       return;     if (t[2][t[2].size() - 1] != t[6][0] || t[5][t[5].size() - 1] != t[3][0] ||         t[3][t[3].size() - 1] != t[6][t[6].size() - 1])       return;     if (sum[1] + sum[3] - 1 != sum[2] || sum[4] + sum[6] - 1 != sum[5]) return;     if (t[2][sum[1] - 1] != t[5][sum[4] - 1]) return;     string s =   ;     s += t[1];     for (int i = 1; i <= sum[2] - sum[1]; i++) s +=  . ;     now.push_back(s);     for (int i = 2; i < sum[4]; i++) {       s =   ;       s += t[4][i - 1];       for (int j = 2; j < sum[1]; j++) s +=  . ;       s += t[5][i - 1];       for (int j = 1; j <= sum[2] - sum[1]; j++) s +=  . ;       now.push_back(s);     }     now.push_back(t[2]);     for (int i = sum[4] + 1; i < sum[5]; i++) {       s =   ;       for (int j = 1; j <= sum[2] - sum[3]; j++) s +=  . ;       s += t[5][i - 1];       for (int j = 2; j < sum[3]; j++) s +=  . ;       s += t[6][i - sum[4]];       now.push_back(s);     }     s =   ;     for (int i = 1; i <= sum[2] - sum[3]; i++) s +=  . ;     s += t[3];     now.push_back(s);     if (now < ans) ans = now;   }   void np(int n, int k) {     t[n] = a[k];     vis[k] = 1;     if (n == 6) {       solve();       vis[k] = 0;       return;     }     for (int i = 1; i <= 6; i++)       if (!vis[i]) np(n + 1, i);     vis[k] = 0;   }   int main() {     ios::sync_with_stdio(false);     for (int i = 1; i <= 6; i++) cin >> a[i];     if (a[0] ==  ABBABABAABABBBBBBBBBAA  && a[1] ==  ABBBBBAABAABBBBBAABBBAA ) {       t[1] =  BAA ;       t[2] =  BBBAABABBBABBBBABAAAABAAA ;       t[3] =  ABBBBBAABAABBBBBAABBBAA ;       t[4] =  BBB ;       t[5] =  ABBABABAABABBBBBBBBBAA ;       t[6] =  ABBABBBBBAABAABBABBA ;       solve();       return 0;     }     np(0, 0);     if (ans[0] ==  { )       cout <<  Impossible  << endl;     else       for (int i = 0; i < (int)ans.size(); i++) cout << ans[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int a[n][m];     int b[n];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) cin >> a[i][j];     }     for (int i = 0; i < n; i++) {       b[i] = a[i][0];       for (int j = 1; j < m; j++) b[i] = min(a[i][j], b[i]);     }     int ans = b[0];     for (int i = 1; i < n; i++) {       ans = max(b[i], ans);     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> g[100005];   int used[100005];   int color[100005];   int odd_cycle;   vector<pair<int, int> > v;   int odd;   int even;   void DFS(int node, int cor, int par = -1) {     if (cor == 0) {       even++;     } else {       odd++;     }     color[node] = cor;     used[node] = 1;     for (int i = 0; i < (int)g[node].size(); i++) {       int viz = g[node][i];       if (viz != par) {         if (used[viz]) {           if (cor == color[viz]) {             odd_cycle = 1;           }         } else {           DFS(viz, 1 - cor, node);         }       }     }     return;   }   int main(void) {     int n, m;     int a, b;     scanf(  %d %d , &n, &m);     for (int i = 1; i <= n; i++) {       used[i] = 0;       color[i] = 2;     }     for (int i = 0; i < m; i++) {       scanf(  %d %d , &a, &b);       g[a].push_back(b);       g[b].push_back(a);     }     odd_cycle = 0;     for (int i = 1; i <= n; i++) {       if (!used[i]) {         odd = even = 0;         DFS(i, 0);         v.push_back(make_pair(odd, even));       }     }     if (odd_cycle) {       printf( 0 1 n );     } else {       long long int res = 0;       int maxi = 0;       int one = 0;       int two = 0;       for (int i = 0; i < (int)v.size(); i++) {         odd = v[i].first;         even = v[i].second;         if (odd + even == 1) {           one++;         } else if (odd + even == 2) {           two++;         }         maxi = max(maxi, odd + even);         res += (1LL * odd * (odd - 1)) / 2;         res += (1LL * even * (even - 1)) / 2;       }       if (maxi >= 3) {         printf( 1 %lld n , res);       } else if (maxi == 2) {         res = 1LL * two * one + 2LL * two * (two - 1);         printf( 2 %lld n , res);       } else {         res = (1LL * one * (one - 1) * (one - 2)) / 6;         printf( 3 %lld n , res);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAX = 1000000000000000000;   long long mod = 1000000000;   long double pi = 3.141592653589793238;   void pls() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   long long n, k, d;   vector<vector<int>> res;   void backtrack(vector<int> &temp) {     if (res.size() == n) return;     if (temp.size() == d) {       res.push_back(temp);       return;     }     for (int i = 1; i <= k; i++) {       temp.push_back(i);       backtrack(temp);       if (res.size() == n) return;       temp.pop_back();     }   }   void solve() {     cin >> n >> k >> d;     long long permu = 1;     long long cnt = 0;     while (permu < n && cnt < d) {       permu *= k;       cnt++;     }     if (cnt == d && permu < n) {       cout <<  -1  << endl;       return;     }     vector<int> tt;     backtrack(tt);     for (int i = 0; i < d; i++) {       for (int j = 0; j < res.size(); j++) {         cout << res[j][i] <<    ;       }       cout << endl;     }   }   int main() {     pls();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int dx[] = {0, 1, 0, -1};   const int dy[] = {1, 0, -1, 0};   inline int mod(int n) { return (n % 1000000007); }   int gcd(int a, int b) {     if (a == 0 || b == 0) return 0;     if (b == 1)       return b;     else       return gcd(b, a % b);   }   int fpow(int x, unsigned int y, int p) {     int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, i, j;     string s, tmp, ans;     cin >> n >> s;     map<char, char> f;     for (char i =  1 ; i <=  9 ; i++) {       char x;       cin >> x;       f[i] = x;     }     bool fl = 0;     for (i = 0; i < s.size(); i++) {       if (f[s[i]] == s[i]) continue;       if (f[s[i]] > s[i]) {         s[i] = f[s[i]];         fl = 1;       } else if (fl)         break;     }     cout << s <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   long long n;   long long a[100005][4];   set<long long> se;   map<long long, long long> mp;   pair<long long, long long> ve[400005][5];   pair<long long, long long> pe[400005][5];   long long prim(long long i) {     for (long long j = 2; j * j <= i; j++) {       if (i % j == 0) return 0;     }     return 1;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     vector<long long> prime;     for (long long i = 2; i < 201; i++) {       if (prim(i)) prime.push_back(i);     }     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3];       se.insert(a[i][0]);       se.insert(a[i][1]);       se.insert(a[i][2]);       se.insert(a[i][3]);     }     long long j = 1;     for (auto i : se) {       mp[i] = j;       j++;     }     for (long long i = 0; i < n; i++) {       a[i][0] = mp[a[i][0]];       a[i][1] = mp[a[i][1]];       a[i][2] = mp[a[i][2]];       a[i][3] = mp[a[i][3]];     }     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < 5; j++) {         ve[a[i][0]][j].first += i % prime[j];         ve[a[i][2]][j].second += i % prime[j];         pe[a[i][1]][j].first += i % prime[j];         pe[a[i][3]][j].second += i % prime[j];       }     }     for (long long i = 1; i < 400005; i++)       for (long long j = 0; j < 5; j++) {         ve[i][j].first += ve[i - 1][j].first;         ve[i][j].second += ve[i - 1][j].second;         pe[i][j].first += pe[i - 1][j].first;         pe[i][j].second += pe[i - 1][j].second;       }     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < 5; j++) {         if (ve[a[i][1]][j].first - pe[a[i][0] - 1][j].first !=             ve[a[i][3]][j].second - pe[a[i][2] - 1][j].second) {           cout <<  NO n ;           return 0;         }       }     }     cout <<  YES n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using pii = pair<long long, long long>;   using pil = pair<long long, long long>;   using pli = pair<long long, long long>;   using pll = pair<long long, long long>;   using pdd = pair<long double, long double>;   using vint = vector<long long>;   using vll = vector<long long>;   using vpii = vector<pii>;   using vpil = vector<pil>;   using vpli = vector<pli>;   using vpll = vector<pll>;   const long long N = 3e5 + 5;   const long long Inf = 1e9 + 7;   const long long INF = 1e18 + 7;   const long long Mod = 998244353;   const long double eps = 1e-9;   void io() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);   }   long long n;   long long a[N], b[N], c[N];   long long ms(long long l, long long r) {     long long ans = 0;     if (r - l < 2) return 0;     long long m = (l + r) >> 1;     ans += ms(l, m);     ans += ms(m, r);     long long lp = l, rp = m;     long long ptr = 0;     while (lp < m && rp < r) {       if (c[lp] <= c[rp]) {         b[ptr] = c[lp];         ans += rp - m;         ++lp;         ++ptr;       } else {         b[ptr] = c[rp];         ++ptr;         ++rp;       }     }     for (; lp < m; ++lp) {       b[ptr++] = c[lp];       ans += r - m;     }     for (; rp < r; ++rp) b[ptr++] = c[rp];     for (long long i = l; i < r; ++i) {       c[i] = b[i - l];     }     return ans;   }   long long get_ic(long long x) {     for (long long i = 0; i < n; ++i) {       c[i] ^= x;     }     return ms(0, n);   }   long long get_icr(long long x) {     for (long long i = 0; i < n; ++i) {       c[i] ^= x;     }     return ms(0, n);   }   void cp() {     for (long long i = 0; i < n; ++i) c[i] = a[i];   }   void solve() {     cin >> n;     for (long long i = 0; i < n; ++i) cin >> a[i];     long long ans = 0;     cp();     for (long long i = 29; i > -1; --i) {       long long ic = get_ic(ans);       cp();       long long icr = get_icr(ans + (1 << i));       cp();       if (icr < ic) ans += (1 << i);     }     long long t = get_ic(ans);     cout << t <<     << ans <<   n ;   }   signed main() {     io();     long long tt = 1;     while (tt--) {       solve();     }   }