malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <typename S, typename T>   inline bool smin(S &l, T r) {     return r < l ? l = r, 1 : 0;   }   template <typename S, typename T>   inline bool smax(S &l, T r) {     return l < r ? l = r, 1 : 0;   }   constexpr int MOD = 1e9 + 7;   template <typename S>   inline S mod(S &l) {     return l = (l % MOD + MOD) % MOD;   }   template <typename S, typename T>   inline S add(S &l, T r) {     return mod(l += r);   }   void fileIO(string s) {     freopen((s +  .in ).c_str(),  r , stdin);     freopen((s +  .out ).c_str(),  w , stdout);   }   constexpr int N = 1e5 + 10;   constexpr int SQ = 780;   int n, k;   vector<int> vec[N];   int bias, dp[2][SQ], pd[2];   inline void input() {     cin >> n >> k;     for (int i = 0; i < k; i++) {       int x, y;       cin >> x >> y;       vec[y].push_back(n - x + 1);     }   }   inline void faze_0() {     for (int i = 1; i < n + 1; i++) {       sort(vec[i].begin(), vec[i].end());       while (vec[i].size() && vec[i].back() >= SQ - 2) {         bias++;         vec[i].pop_back();       }     }   }   inline void faze_1() {     memset(dp[0], 63, sizeof(dp));     dp[0][0] = 0;     for (int i = 1; i < n + 1; i++) {       int me = i & 1, num = 0;       pd[me] = 1e9;       for (int j = min(n - i + 1, SQ - 2); ~j; j--) {         dp[me][j] = num * 3 + min(dp[me ^ 1][j + 1],                                   pd[me ^ 1] + (j ? 2 : 0) + j * (j + 1) / 2);         smin(pd[me], dp[me][j]);         if (vec[i].size() && vec[i].back() == j) {           num++;           vec[i].pop_back();         }       }     }   }   int main() {     input();     faze_0();     faze_1();     cout << 3 * bias + pd[n & 1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       long long a, b, k;       cin >> a >> b >> k;       if (k % 2 == 0)         cout << a * (k / 2) - b * (k / 2) <<   n ;       else         cout << a * (k / 2 + 1) - b * (k / 2) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int cnt[7];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, i, a, x;     bool test = true;     vector<pair<long long int, pair<long long int, long long int>>> v;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a;       cnt[a]++;     }     x = n / 3;     if (cnt[1] + cnt[2] + cnt[3] + cnt[4] + cnt[6] != n) test = false;     if (cnt[1] == x && test) {       for (i = 1; i <= x; i++) {         if (cnt[4] > 0) {           if (cnt[2] > 0) {             v.push_back({1, {2, 4}});             cnt[2]--;             cnt[4]--;           } else {             test = false;             break;           }         } else if (cnt[3] > 0) {           if (cnt[6] > 0) {             v.push_back({1, {3, 6}});             cnt[3]--;             cnt[6]--;           } else {             test = false;             break;           }         } else if (cnt[2] > 0) {           if (cnt[6] > 0) {             v.push_back({1, {2, 6}});             cnt[2]--;             cnt[6]--;           } else {             test = false;             break;           }         }       }     } else       test = false;     if (test && cnt[2] == 0 && cnt[6] == 0 && cnt[3] == 0 && cnt[4] == 0) {       for (i = 0; i < v.size(); i++)         cout << v[i].first <<     << v[i].second.first <<                  << v[i].second.second << endl;     } else       cout <<  -1  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int n, m;   long long int power(long long int a, long long int b) {     if (b == 0) return 1;     long long int sr = power(a, b >> 1);     long long int r = sr * sr;     if (b & 1) r = a * r;     return r;   }   void solve() {     long long int z = power(2, 0);     cin >> n;     vector<long long int> v(n);     long long int ans = 0;     long long int p = 1;     for (long long int i = 0; i < n; i++) cin >> v[i];     sort(v.begin(), v.end());     long long int count = 0;     for (long long int i = 0; i < n; i++) {       if (v[i] >= z) {         ans += (count * (count - 1) / 2);         while (v[i] >= z) {           z = power(2, p);           p++;         }         count = 0;       }       count++;     }     ans += (count * (count - 1) / 2);     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int x;     cin >> x;     for (long long int i = 1; i <= x; i++) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 5e5 + 5;   long long n, m;   vector<vector<long long> > g(N, vector<long long>());   vector<long long> d(N, 0), last(N, -1);   vector<long long> path;   long long k = 0;   vector<bool> in_path(N, 0);   vector<pair<long long, long long> > pairs;   long long p = 0;   void dfs(long long v, long long l) {     d[v] = l;     if (last[l] != -1) {       pairs.push_back({last[l] + 1, v + 1});       last[l] = -1;       p++;     } else {       last[l] = v;     }     for (auto u : g[v]) {       if (d[u] == 0) {         dfs(u, l + 1);         if (in_path[u]) {           path.push_back(v + 1);           k++;           in_path[v] = 1;         }       }     }     if (d[v] >= (n + 1) / 2 && !in_path[v] && k == 0) {       path.push_back(v + 1);       k++;       in_path[v] = 1;     }   }   void solve() {     cin >> n >> m;     for (long long i = 0; i < m; ++i) {       long long u, v;       cin >> u >> v;       u--;       v--;       g[u].push_back(v);       g[v].push_back(u);     }     dfs(0, 1);     if (k >= (n + 1) / 2) {       cout <<  PATH n ;       cout << k <<   n ;       for (long long i = 0; i < k; ++i) {         cout << path[i] <<    ;       }       cout <<   n ;     } else {       cout <<  PAIRING n ;       cout << p <<   n ;       for (long long i = 0; i < p; ++i) {         cout << pairs[i].first <<     << pairs[i].second <<   n ;       }     }     for (long long i = 0; i <= n; ++i) {       g[i].clear();       d[i] = 0;       last[i] = -1;       in_path[i] = 0;     }     path.clear();     pairs.clear();     k = 0;     p = 0;   }   signed main() {     ios_base::sync_with_stdio(false);     long long t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool check(string cards, int a, int b) {     bool isValid = false;     for (int j = 0; j < b && !isValid; j++) {       int shift = 0;       isValid = true;       for (int i = 0; i < a; i++, shift += b) {         if (cards[shift + j] !=  X ) {           isValid = false;           break;         }       }     }     return isValid;   }   int main() {     int t;     vector<string> ways;     cin >> t;     for (int i = 0; i < t; i++) {       string cards;       cin >> cards;       if (check(cards, 1, 12)) ways.push_back( 1x12 );       if (check(cards, 2, 6)) ways.push_back( 2x6 );       if (check(cards, 3, 4)) ways.push_back( 3x4 );       if (check(cards, 4, 3)) ways.push_back( 4x3 );       if (check(cards, 6, 2)) ways.push_back( 6x2 );       if (check(cards, 12, 1)) ways.push_back( 12x1 );       cout << ways.size() <<    ;       vector<string>::iterator itr = ways.begin();       for (; itr != ways.end(); itr++) cout << *itr <<    ;       cout << endl;       ways.clear();     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int oo = 1e9 + 9;   const long long inf = 1e18 + 18;   const int max6 = 1e6 + 6;   const int modx = 1e9 + 123;   const int mody = 997;   const int base = 137;   int t[max6];   int n, k;   bool ok(int l, int r) {     int cnt = 0;     for (int i = l; i <= r; ++i) cnt += t[i] == 1;     if (cnt) return false;     int cur = 0;     for (int i = r + 1; i <= n; ++i) {       if (t[i] == 2)         cur++;       else         cur = 0;       if (cur > k) return false;     }     for (int i = 1; i < l; ++i) {       if (t[i] == 2)         cur++;       else         cur = 0;       if (cur > k) return false;     }     return true;   }   int main() {     cin >> n >> k;     string s;     cin >> s;     for (int i = 1; i <= n; ++i)       if (s[i - 1] ==  Y )         t[i] = 1;       else if (s[i - 1] ==  N )         t[i] = 2;       else if (s[i - 1] ==  ? )         t[i] = 3;     int res = 0;     for (int i = 1; i <= n; ++i)       if (i == 1 || t[i - 1] == 1 || t[i - 1] == 3) {         int j = i + k - 1;         if (j == n || t[j + 1] == 1 || t[j + 1] == 3)           if (ok(i, j)) res = 1;       }     cout << (res ?  YES  :  NO );   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> m;   int main() {     int a, t, n, i, j, k, l, mn = INT_MAX, mx = 0;     cin >> n >> k;     int cnt = 0;     int ans = 0;     for (int i = 0; i < n; i++) {       cin >> a;       mn = min(mn, a);       m[a]++;     }     int p = mn;     while (p < k) {       ans++;       mn = INT_MAX;       for (int i = k - 1; i >= p; i--) {         if (m[i] > 0) m[i]--, m[i + 1]++;         if (m[i] > 0) mn = min(mn, i);         if (m[i + 1] > 0) mn = min(mn, i + 1);       }       p = mn;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const long double PI = 3.141592653589793238;   const double EPS = 1e-6;   void solve() {     long long r, g, b, w;     cin >> r >> g >> b >> w;     long long total = r + g + b + w;     long long odd = 0;     odd = r % 2 + g % 2 + b % 2 + w % 2;     long long col = r && g && b;     if (odd <= 1 || odd == 4 || (odd == 3 && col))       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long tc;     cin >> tc;     while (tc--) {       solve();     }     return 0;   }
#include<bits/stdc++.h>   using namespace std;   typedef long long ll;   int main()   {        int t,n,k;    string x= abc ;    cin>>t;    while(t--)    {     cin>>n>>k;     string s,h;     for(int i=0;i<n-k;i++)     {      s+=x[i%3];     }          char c=x[(n-k)%3];          while(k--)     {      s+=c;     }     cout<<s<<endl;    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       string s =   ;       for (int i = 0;; i++) {         bool flag = 1;         for (int j = i * k; j < (i + 1) * k; j++) {           s += ( a  + j - i * k);           if (j == n - 1) {             flag = 0;             break;           }         }         if (flag == 0) break;       }       cout << s << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   void start() {}   void sober() {     long long int n, x = 0, a = 0, b = 0, y = 0, sum = 0, k = 0, m = 0;     cin >> n >> a >> b;     string s;     cin >> s;     a--, b--;     if (s[a] == s[b])       cout <<  0 n ;     else       cout <<  1 n ;   }   signed main() {     start();     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int t = 1;     while (t--) {       sober();     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   int a[maxn];   unordered_map<int, int> b, c;   unordered_map<int, int>::iterator it, it2;   vector<int> ans;   int main() {     ios_base::sync_with_stdio(0);     int n, m, p;     cin >> n >> m >> p;     int x;     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < m; ++i) {       cin >> x;       it = b.find(x);       if (it == b.end())         b.insert(make_pair(x, 1));       else         ++it->second;     }     for (int q = 0; q < p; ++q) {       int cur = 0;       c.clear();       for (int i = q; i < n; i += p) {         if (1ll * i >= 1ll * m * p) {           it = b.find(a[i - m * p]);           if (it != b.end()) {             it2 = c.find(a[i - m * p]);             if (it2->second <= it->second) --cur;             --it2->second;           }         }         it = b.find(a[i]);         if (it == b.end())           continue;         else {           it2 = c.find(a[i]);           if (it2 == c.end()) it2 = c.insert(make_pair(a[i], 0)).first;           if (it2->second < it->second) ++cur;           ++it2->second;         }         if (cur == m) ans.push_back(i - (m - 1) * p + 1);       }     }     sort(ans.begin(), ans.end());     cout << ans.size() <<   n ;     for (int i : ans) cout << i <<    ;     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int k;     cin >> k;     char s[200];     vector<int> __v;     __v.assign(1000000, 127);     cin >> s;     int n;     cin >> n;     set<int> n_del[ z  -  a  + 1];     set<int>::iterator pos_n_del[ z  -  a  + 1];     for (int i = 0; i < n; i++) {       char c;       int nc;       cin >> nc >> c;       set<int>::iterator it = n_del[c -  a ].begin();       if (n_del[c -  a ].empty() || nc <= *it) {         n_del[c -  a ].insert(nc - 1);         continue;       }       nc -= *it;       int pos = 0;       while (it != n_del[c -  a ].end() && nc > 0) {         set<int>::iterator it0 = it;         it++;         if (it != n_del[c -  a ].end()) {           nc -= *it - *it0 - 1;         }       }       if (nc > 0) {         it--;         pos = *it + nc;       } else         pos = *it + nc - 1;       n_del[c -  a ].insert(pos);     }     for (int i = 0; i <  z  -  a  + 1; ++i) {       pos_n_del[i] = n_del[i].begin();     }     int tSums[ z  -  a  + 1] = {0};     for (int i = 0, len = strlen(s), j = 0; i < len * k; ++i, ++j) {       if (j == len) j = 0;       if (pos_n_del[s[j] -  a ] != n_del[s[j] -  a ].end() &&           *pos_n_del[s[j] -  a ] == tSums[s[j] -  a ]) {         pos_n_del[s[j] -  a ]++;       } else         cout << s[j];       tSums[s[j] -  a ]++;     }     cout << endl;     cerr << __v[rand() % __v.size()];   }
#include <bits/stdc++.h>   using namespace std;   const int dx[4] = {0, 1, -1, 0}, dy[4] = {-1, 0, 0, 1};   int n, m;   char g[60][60];   bool col[60][60][2][4];   bool tmp[60][60][2][4];   bool inrange(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }   void solve(int x, int y, int turn, int dir) {     int nx = x + dx[dir], ny = y + dy[dir];     if (inrange(nx, ny) && g[nx][ny] ==  B  && tmp[nx][ny][turn][dir] == false) {       tmp[nx][ny][turn][dir] = tmp[nx][ny][1][dir] = true;       solve(nx, ny, turn, dir);     }     if (turn == 1) return;     for (int i = 0; i < 4; i++) {       if (i == dir) continue;       nx = x + dx[i], ny = y + dy[i];       if (inrange(nx, ny) && g[nx][ny] ==  B  && tmp[nx][ny][1][i] == false) {         tmp[nx][ny][1][i] = true;         solve(nx, ny, 1, i);       }     }     return;   }   bool check() {     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (g[i][j] ==  B ) {           bool ok = false;           for (int x = 0; x < 2 && !ok; x++)             for (int y = 0; y < 4 && !ok; y++)               if (tmp[i][j][x][y]) ok = true;           if (!ok) return false;         }     return true;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> g[i][j];       }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (g[i][j] ==  B ) {           memset(tmp, false, sizeof(tmp));           for (int k = 0; k < 4; k++)             tmp[i][j][0][k] = tmp[i][j][1][k] = true, solve(i, j, 0, k);           if (!check()) {             cout <<  NO  << endl;             return 0;           }         }     cout <<  YES  << endl;     return 0;   }
#include<bits/stdc++.h>   using namespace std;      typedef long long ll;   typedef long double ld;   typedef string ss ;   typedef pair<int, int> pi;   typedef pair<ll,ll> pl;   typedef vector<int> vi;   typedef vector<ll> vl;      #define mp make_pair   #define pb push_back            void solve(){          ll n,k=0,q=0;          string s;         cin >> n >> k ;         ll x[n],y[n];         for(int i=0 ; i<n ; i++){             cin >> x[i] >> y[i];         }         bool ok=false;         for(int i=0 ; i<n ; i++){             for(int j=0 ; j<n ; j++){               if(abs(x[i]-x[j]) + abs(y[i]-y[j]) <= k){                 q++;               }               if(q==n) ok=true;         } q=0;         }         cout << (ok ?  1 n  :  -1 n ) ;                  }               int main() {       ios_base::sync_with_stdio(0); cin.tie(0);       int t=1;       cin >> t;       while(t--)        solve();       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 17;   int N, Q;   int main() {     ios_base::sync_with_stdio(false);     cin >> Q;     while (Q--) {       cin >> N;       long long mx;       cin >> mx;       long long diff = 0;       while (--N) {         long long x;         cin >> x;         mx = max(mx, x);         diff = max(diff, mx - x);       }       long long ans = 0;       while (diff) {         ans++;         diff >>= 1;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, p;   string msg, s[100001], h =  <3 ;   int sub(int &i, string &w) {     int k = 0;     for (; k < w.length() && i < msg.length(); i++) {       if (w[k] == msg[i]) {         ++k;       }     }     return k == w.length();   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s[i];     }     cin >> msg;     int j = 0, o = 1;     for (int i = 0; o && i < n; i++) {       if (!sub(j, h)) {         o = 0;       }       if (o && !sub(j, s[i])) {         o = 0;       }     }     if (!sub(j, h)) {       o = 0;     }     if (o) {       cout <<  yes             <<   n ;     } else {       cout <<  no             <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int OO = 1e9;   const double EPS = 1e-9;   const int MX = 1e6 + 5;   int p = 1299709, n, m, u, v;   vector<vector<int>> adj(MX);   unsigned long long pPw[MX], M = 1000000009, Hash[MX];   int main() {     ios::sync_with_stdio(false);     cout.precision(10);     cin.tie(0);     pPw[0] = 1;     for (int i = 1; i < MX; ++i) pPw[i] = p * pPw[i - 1];     cin >> n >> m;     for (int i = 0; i < m; ++i) {       cin >> u >> v;       for (int I = 0; I < 1; ++I) {         Hash[u] += pPw[v];         Hash[v] += pPw[u];       }     }     map<unsigned long long, int> hashes;     for (int i = 1; i <= n; ++i) {       ++hashes[Hash[i]];     }     unsigned long long ans = 0;     for (auto& pr : hashes) {       ans += pr.second * 1LL * (pr.second - 1) / 2;     }     hashes.clear();     for (int i = 1; i <= n; ++i) {       ++hashes[Hash[i] + pPw[i]];     }     for (auto& pr : hashes) {       ans += pr.second * 1LL * (pr.second - 1) / 2;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[200], ans[200];   int v[1000001];   int main() {     int T, n;     cin >> T;     while (T--) {       memset(v, 0, sizeof v);       scanf( %d , &n);       for (int i = 1; i <= n; i++) scanf( %d , &a[i]);       sort(a + 1, a + n + 1);       for (int i = 1; i <= n; i++) {         for (int j = i; j <= n; j++) v[a[j] - a[i]] = 1;       }       memset(ans, 0, sizeof ans);       ans[1] = 1;       int len = 2;       for (int j = 1; j <= 1e6; j++) {         int tag = 1;         for (int k = 1; k < len; k++) {           if (v[j - ans[k]]) {             tag = 0;             break;           }         }         if (tag) ans[len++] = j;         if (len > n) break;       }       int tag = 1;       for (int i = 1; i <= n; i++)         if (ans[i] == 0) tag = 0;       if (tag) {         puts( YES );         for (int i = 1; i <= n; i++) printf( %d%c , ans[i], i == n ?   n  :    );       } else         puts( NO );     }     return 0;   }
#include  bits/stdc++.h       using namespace std;      string alpha[26] = {     1 0 0 1 0 ,     1 1 0 2 0 ,     2 0 0 1 1 ,     2 1 0 1 2 ,     1 1 0 1 1 ,     2 1 0 2 1 ,     2 2 0 2 2 ,     1 2 0 2 1 ,     1 1 0 1 1 ,     1 2 0 1 2 ,     1 0 1 2 0 ,     1 1 1 3 0 ,     2 0 1 2 1 ,     2 1 1 2 2 ,     1 1 1 2 1 ,     2 1 1 3 1 ,     2 2 1 3 2 ,     1 2 1 3 1 ,     1 1 1 2 1 ,     1 2 1 2 2 ,     1 0 2 2 1 ,     1 1 2 3 1 ,     1 2 1 1 3 ,     2 0 2 2 2 ,     2 1 2 2 3 ,     1 1 2 2 2    };      int main() {    int n;    string s;    cin >> n;    cin.ignore();    unordered_map<string, char> m;    for (int i = 25; i >= 0; i--) {     m[alpha[i]] =  a  + i;    }    for (int i = 0; i < n; i++) {     getline(cin, s);     putchar(m[s]);    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   char c[503][503];   vector<pair<int, int> > v[503][503];   int main() {     int n, m, k;     cin >> n >> m >> k;     int s = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> c[i][j];         if (c[i][j] ==  . ) s++;       }     }     pair<int, int> st;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (c[i][j] ==  . ) {           st.first = i;           st.second = j;           if (c[i - 1][j] == c[i][j]) {             v[i][j].push_back(make_pair(i - 1, j));           }           if (c[i + 1][j] == c[i][j]) {             v[i][j].push_back(make_pair(i + 1, j));           }           if (c[i][j - 1] == c[i][j]) {             v[i][j].push_back(make_pair(i, j - 1));           }           if (c[i][j + 1] == c[i][j]) {             v[i][j].push_back(make_pair(i, j + 1));           }         }       }     }     queue<pair<int, int> > q;     q.push(st);     int num = s - k;     if (num) {       c[st.first][st.second] =  q ;       num--;     }     while (!q.empty()) {       pair<int, int> tp = q.front();       q.pop();       for (pair<int, int> kom : v[tp.first][tp.second]) {         if (c[kom.first][kom.second] ==  .  && num > 0) {           c[kom.first][kom.second] =  q ;           num--;           q.push(make_pair(kom.first, kom.second));         }       }     }     for (int i = 1; i < n + 1; i++) {       for (int j = 1; j <= m; j++) {         if (c[i][j] ==  q )           cout <<  . ;         else if (c[i][j] ==  .  && k)           cout <<  X ;         else           cout << c[i][j];       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 32, M = 2e5 + 10;   int q[N], qz[M];   bool insert(int x) {     for (int i = N - 1; i >= 0; --i) {       if ((x >> i) & 1) {         if (!q[i]) {           q[i] = x;           return true;         } else           x ^= q[i];       }     }     return false;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &qz[i]);     for (int i = 1; i <= n; ++i) qz[i] ^= qz[i - 1];     int ans = 0;     if (!qz[n]) return printf( -1 n ), 0;     for (int i = n; i >= 1; --i) {       if (insert(qz[i])) ans++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int n, a[N], b[N], c[N];   multiset<int> S;   multiset<int>::iterator it;   int main() {     std::ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i], c[a[i]] = i;     for (int i = 0; i < n; i++) cin >> b[i];     for (int i = 0; i < n; i++) {       int t = i - c[b[i]];       S.insert(t);     }     vector<int> r;     for (int i = 0; i < n; i++) {       int t = 1000000;       it = S.lower_bound(i);       if (it != S.end()) t = min(t, *(it)-i);       if (it != S.begin()) t = min(t, i - *(--it));       r.push_back(t);       S.erase(S.find(i - c[b[i]]));       S.insert(n - c[b[i]] + i);     }     for (int i = 0; i < r.size(); i++) cout << r[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     long long n, i, j;     cin >> n;     vector<long long> v(n / 2);     for (i = 0; i < v.size(); i++) {       cin >> v[i];     }     sort(v.begin(), v.end());     long long mn = LLONG_MAX;     j = 1;     long long ans = 0;     for (i = 0; i < v.size(); i++) {       ans += abs(j - v[i]);       j += 2;     }     mn = ans;     reverse(v.begin(), v.end());     ans = 0;     j = n;     for (i = 0; i < v.size(); i++) {       ans += abs(j - v[i]);       j -= 2;     }     cout << min(mn, ans);     return 0;   }