malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   void rs(int &x) { scanf( %d , &x); }   void rsl(long long &x) { scanf( %I64d , &x); }   void rsd(double &x) { scanf( %lf , &x); }   void rss(char *str) { scanf( %s , str); }   void ws(int &x) { printf( %d  , x); }   void wsl(long long &x) { printf( %I64d  , x); }   void wsd(double &x) { printf( %lf  , x); }   void wss(char *str) { printf( %s  , str); }   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   int const N = (2e5) + 5;   int const mod = (1e9) + 7;   int a[N], t[N], suma[N], sumt[N];   priority_queue<int> que;   set<pair<int, int>> ms, mns;   map<int, int> mm;   int ins[N], inns[N];   int main() {     int n, w, k;     cin >> n >> w >> k;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       suma[i] = suma[i - 1] + a[i];     }     for (int i = 1; i <= n; ++i) {       cin >> t[i];       mm[t[i]] = i;       sumt[i] = sumt[i - 1] + t[i];     }     int ans = 0;     int r = 1;     int ct = 0;     int cp = 0;     for (int i = 1; i <= n; ++i) {       r = max(r, i);       while (r <= n) {         int dt = 0;         if (ms.size() < w) {           dt = t[r] / 2 + t[r] % 2;           if (ct + dt <= k) {             ms.insert(make_pair(t[r], r));             ins[r] = 1;             ct += dt;           } else {             break;           }         } else {           int var = ms.begin()->first;           if (t[r] > var) {             int dt = t[r] / 2 + t[r] % 2;             int ddt = (var / 2);             if (ct + dt + ddt <= k) {               ins[ms.begin()->second] = 0;               ins[r] = 1;               mns.insert(*ms.begin());               ms.erase(ms.begin());               ms.insert(make_pair(t[r], r));               ct += dt + ddt;             } else {               break;             }           } else {             int dt = t[r];             if (ct + dt <= k) {               ct += dt;               mns.insert(make_pair(t[r], r));             } else {               break;             }           }         }         r++;       }       ans = max(suma[r - 1] - suma[i - 1], ans);       if (ins[i] == 0) {         ct -= t[i];       } else {         ct -= (t[i] / 2 + t[i] % 2);         ins[i] = 0;         set<pair<int, int>>::iterator it = ms.find(make_pair(t[i], i));         if (it != ms.end()) {           ms.erase(it);         }         while (mns.size() > 0 && ((--mns.end())->second <= i)) {           mns.erase(--mns.end());         }         if (mns.size() > 0) {           it = --mns.end();           ct -= ((it->first) / 2);           ins[it->second] = 1;           ms.insert(*(--mns.end()));           mns.erase((--mns.end()));         }       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int generateb(int a, long int nos[], long int noa[], long int nob[]) {     int i, minb = 100002;     for (i = 0; i < 26; i++) {       nos[i] = nos[i] - (noa[i] * a);     }     for (i = 0; i < 26; i++) {       if (nob[i] != 0) {         if (nos[i] / nob[i] < minb) {           minb = nos[i] / nob[i];         }       }     }     return minb;   }   int generatea(int b, long int nos[], long int noa[], long int nob[]) {     int i, mina = 100002;     for (i = 0; i < 26; i++) {       nos[i] = nos[i] - (nob[i] * b);     }     for (i = 0; i < 26; i++) {       if (noa[i] != 0) {         if (nos[i] / noa[i] < mina) {           mina = nos[i] / noa[i];         }       }     }     return mina;   }   int main() {     char s[100010], a[100010], b[100010];     long int nos[26] = {0}, i, lens = 0, noa[26] = {0}, nob[26] = {0}, lena = 0,              lenb = 0, j, nos1[26] = {0}, mina = 100002, counta, countb, max = -1,              maxa, maxb, minb = 100002, r;     cin >> s >> a >> b;     for (i = 0; s[i] !=   0 ; i++) {       nos[s[i] -  a ]++;       lens++;     }     for (j = 0; j < 26; j++) {       nos1[j] = nos[j];     }     for (i = 0; a[i] !=   0 ; i++) {       noa[a[i] -  a ]++;       lena++;     }     for (i = 0; b[i] !=   0 ; i++) {       nob[b[i] -  a ]++;       lenb++;     }     for (i = 0; i < 26; i++) {       if (noa[i] != 0) {         if (nos[i] / noa[i] < mina) {           mina = nos[i] / noa[i];         }       }     }     for (i = 0; i <= mina; i++) {       countb = generateb(i, nos, noa, nob);       for (j = 0; j < 26; j++) {         nos[j] = nos1[j];       }       if (i + countb > max) {         max = i + countb;         maxa = i;         maxb = countb;       }     }     for (i = 0; i < 26; i++) {       if (nob[i] != 0) {         if (nos[i] / nob[i] < minb) {           minb = nos[i] / nob[i];         }       }     }     for (i = 0; i <= minb; i++) {       counta = generatea(i, nos, noa, nob);       for (j = 0; j < 26; j++) {         nos[j] = nos1[j];       }       if (i + counta > max) {         max = i + counta;         maxb = i;         maxa = counta;       }     }     for (i = 0; i < maxa; i++) {       cout << a;     }     for (i = 0; i < maxb; i++) {       cout << b;     }     for (i = 0; i < 26; i++) {       nos[i] = nos[i] - (maxa * noa[i]) - (maxb * nob[i]);     }     for (i = 0; i < 26; i++) {       for (j = 0; j < nos[i]; j++) {         cout << char(i +  a );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #define F first   #define S second   #define rep(i, a, b) for(int i = a; i < (b); ++i)   #define per(i, a, b) for(int i = b-1; i>=a ; i--)   #define trav(a, x) for(auto& a : x)   #define allin(a , x) for(auto a : x)   #define all(x) begin(x), end(x)   #define sz(x) (int)(x).size()   typedef long long ll;   typedef pair<int, int> pii;   typedef vector<ll> vl;   typedef vector<pii> vpi;   typedef pair<ll,ll> pll;   typedef vector<string> vs;   typedef vector<pll> vpl;   typedef vector<int> vi;   std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());      int ask(int x , int i , vi v){    cout << 2 <<    << x  <<    << i <<    ;    for(int j = 0 ; j < i ; j ++){     cout << v[j]  <<   ;    }    cout << endl;    int ans;    cin >> ans;    return ans;   }                  int32_t main(){    int t;    cin >> t;    while(t--){     int n;     cin >> n;     vector<int> v;     for(int i = 0 ; i < n; i ++)      v.push_back(i);     stable_sort(all(v) , [&](int a , int b){      cout << 1 <<    << a <<    << b << endl;      int ans;      cin >> ans;      return ans;     });     vector< vector<char> > ans(n, vector<char>(n, 0 ));     for(int i = 0 ; i < n ; i ++){      for(int j = i ; j < n; j ++){       ans[v[i]][v[j]] =  1 ;      }     }     int pr = n-1;     vector< vector<int> > g(n);     for(int i = 0 ; i < n - 1; i ++)      g[v[i]].push_back(v[i+1]);     for(int i = n - 1 ; i >= 0 ; i --){      pr = min(pr, i);      while(pr > 0 && ask(v[i] , pr , v)){       pr -- ;      }      g[v[i]].push_back(v[pr]);     }     vector< vector<bool> > vis(n , vector<bool> (n));     for(int i = 0 ; i< n; i ++){      queue<int> q;      q.push(i);      while(sz(q)){       auto u = q.front();       q.pop();       if(vis[i][u])        continue;       vis[i][u] = true;       for(auto w : g[u])        if(!vis[i][w])         q.push(w);      }     }     cout << 3 << endl;     for(int i = 0; i < n; i ++){      for(int j = 0; j < n; j ++)       cout << (vis[i][j] ? 1 : 0);      cout << endl;     }     int ansx;     cin >> ansx;     assert(ansx != -1);    }    exit(0);   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   const int maxn = 100086;   const double PI = atan(1.0) * 4.0;   const double eps = 1e-9;   const long long mod = 1000000007;   const int maxe = 10086 * 2;   long long quick_pow(long long a, long long n) {     long long ret = 1;     while (n) {       if (n & 1) ret = ret * a % mod;       a = a * a % mod;       n >>= 1;     }     return ret;   }   char s[maxn];   int n, num[5];   int main() {     scanf( %d%s , &n, s);     memset(num, 0, sizeof num);     for (int i = 0; i < n; i++) {       if (s[i] ==  A )         num[0]++;       else if (s[i] ==  G )         num[1]++;       else if (s[i] ==  T )         num[2]++;       else         num[3]++;     }     int maxx = -1;     for (int i = 0; i < 4; i++) maxx = max(maxx, num[i]);     int a = 0;     for (int i = 0; i < 4; i++)       if (maxx == num[i]) a++;     cout << quick_pow(a, n) << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int mo = 1e9 + 7;   struct node {     int mat[210][210];   } qwq;   int n, k, m;   inline int ha(int x, int y) { return x * (1 << m) + y; }   node ksm(int l) {     if (l == 1) return qwq;     node op = ksm(l / 2), op2;     memset(op2.mat, 0, sizeof(op2.mat));     for (int i = 0; i < (k + 1) * (1 << m); i++)       for (int j = 0; j < (k + 1) * (1 << m); j++)         for (int h = 0; h < (k + 1) * (1 << m); h++)           op2.mat[i][j] =               (op2.mat[i][j] + 1ll * op.mat[i][h] * op.mat[h][j]) % mo;     if (l % 2 == 0) return op2;     node op3;     memset(op3.mat, 0, sizeof(op3.mat));     for (int i = 0; i < (k + 1) * (1 << m); i++)       for (int j = 0; j < (k + 1) * (1 << m); j++)         for (int h = 0; h < (k + 1) * (1 << m); h++)           op3.mat[i][j] =               (op3.mat[i][j] + 1ll * qwq.mat[i][h] * op2.mat[h][j]) % mo;     return op3;   }   int main() {     scanf( %d%d%d , &n, &k, &m);     for (int i = 0; i <= k; i++)       for (int j = 0; j < (1 << m); j++) {         int ovo = (j << 1) % (1 << m);         qwq.mat[ha(i, ovo)][ha(i, j)]++;         if (i > 0) {           int way_to_here = 1;           for (int r = 0; r < m; r++)             if ((1 << r) & j) way_to_here++;           qwq.mat[ha(i, ovo | 1)][ha(i - 1, j)] += way_to_here;         }       }     node uoj = ksm(n);     int ans = 0;     for (int i = 0; i < (1 << m); i++)       ans = (ans + 1ll * uoj.mat[ha(k, i)][0]) % mo;     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MN = 2011;   int n, a[MN];   vector<int> ls[MN];   void solve1(int u) {     cout <<  YES  << endl;     for (int turn = 0, _a = (3); turn < _a; turn++) {       for (int i = (1), _b = (2000); i <= _b; i++) {         if (i != u) {           for (int x = 0, _a = (ls[i].size()); x < _a; x++)             cout << ls[i][x] <<    ;         } else {           if (turn == 0)             cout << ls[i][0] <<     << ls[i][1] <<     << ls[i][2] <<    ;           else if (turn == 1)             cout << ls[i][0] <<     << ls[i][2] <<     << ls[i][1] <<    ;           else             cout << ls[i][1] <<     << ls[i][0] <<     << ls[i][2] <<    ;           for (int x = (3), _b = (ls[i].size() - 1); x <= _b; x++)             cout << ls[i][x] <<    ;         }       }       cout << endl;     }   }   void solve2(int u, int v) {     cout <<  YES  << endl;     for (int turn = 0, _a = (3); turn < _a; turn++) {       for (int i = (1), _b = (2000); i <= _b; i++) {         if (i != u && i != v) {           for (int x = 0, _a = (ls[i].size()); x < _a; x++)             cout << ls[i][x] <<    ;         } else if (i == u) {           if (turn == 0)             cout << ls[i][0] <<     << ls[i][1] <<    ;           else if (turn == 1)             cout << ls[i][0] <<     << ls[i][1] <<    ;           else             cout << ls[i][1] <<     << ls[i][0] <<    ;           for (int x = (2), _b = (ls[i].size() - 1); x <= _b; x++)             cout << ls[i][x] <<    ;         } else if (i == v) {           if (turn == 0)             cout << ls[i][0] <<     << ls[i][1] <<    ;           else if (turn == 1)             cout << ls[i][1] <<     << ls[i][0] <<    ;           else             cout << ls[i][1] <<     << ls[i][0] <<    ;           for (int x = (2), _b = (ls[i].size() - 1); x <= _b; x++)             cout << ls[i][x] <<    ;         }       }       cout << endl;     }   }   int main() {     ios ::sync_with_stdio(false);     while (cin >> n) {       for (int i = (1), _b = (n); i <= _b; i++) cin >> a[i];       for (int i = (0), _b = (2000); i <= _b; i++) ls[i].clear();       for (int i = (1), _b = (n); i <= _b; i++) {         ls[a[i]].push_back(i);       }       bool ok = false;       for (int i = (0), _b = (2000); i <= _b; i++)         if (ls[i].size() >= 3) {           solve1(i);           ok = true;           break;         }       if (ok) continue;       for (int i = (1), _b = (2000); i <= _b; i++) {         for (int j = (i + 1), _b = (2000); j <= _b; j++)           if (ls[i].size() >= 2 && ls[j].size() >= 2) {             solve2(i, j);             ok = true;             break;           }         if (ok) break;       }       if (!ok) cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   const int sqrtN = 320;   int countA[sqrtN], countP[sqrtN];   map<int, int> dm[sqrtN];   void recomp(int ind) {     int a, p;     a = p = 0;     for (auto& x : dm[ind]) {       if (x.second != -1) {         if (p != 0)           p--;         else           (a++);       } else {         p++;       }     }     countA[ind] = a;     countP[ind] = p;   }   int getTop(int ind, int p) {     for (auto& x : dm[ind]) {       if (x.second != -1) {         if (p != 0)           p--;         else           return x.second;       } else {         p++;       }     }   }   int top() {     int p = 0;     for (int i = 0; i < sqrtN; ++i) {       if (p - countA[i] < 0) return getTop(i, p);       p += countP[i] - countA[i];     }     return -1;   }   const long long mod = 1e9 + 7;   long long sums(long long a, long long b) {     long long ans = a + b;     if (ans >= mod) ans -= mod;     return ans;   }   long long mins(long long a, long long b) {     long long ans = a - b;     if (ans < 0) ans += mod;     return ans;   }   int p = 31;   long long nextH(long long h, char a) { return h * p + (a -  a ) + 1; }   int last[26], sum[5010] = {0}, f[5010] = {0};   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     string str;     cin >> str;     f[0] = 1;     for (int step = 0; step < n; ++step) {       for (int i = 0; i < 26; ++i) last[i] = -1;       sum[0] = 0;       for (int i = 0; i < n; ++i) sum[i + 1] = sums(sum[i], f[i]);       for (int i = 0; i < n; ++i) {         f[i] = mins(sum[i + 1], sum[last[str[i] -  a ] + 1]);         last[str[i] -  a ] = i;       }     }     int ans = 0;     for (int i = 0; i < n; ++i) ans = sums(ans, f[i]);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   int ah = 911382323;   int bh = 972663749;   template <typename F, typename S>   ostream &operator<<(ostream &os, const pair<F, S> &p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  { ;     typename vector<T>::const_iterator it;     for (it = v.begin(); it != v.end(); it++) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  } ;   }   template <typename T>   ostream &operator<<(ostream &os, const set<T> &v) {     os <<  [ ;     typename set<T>::const_iterator it;     for (it = v.begin(); it != v.end(); it++) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  ] ;   }   template <typename F, typename S>   ostream &operator<<(ostream &os, const map<F, S> &v) {     os <<  [ ;     typename map<F, S>::const_iterator it;     for (it = v.begin(); it != v.end(); it++) {       if (it != v.begin()) os <<  ,  ;       os << it->first <<   =   << it->second;     }     return os <<  ] ;   }   long long dx[8] = {1, -1, 0, 0, 1, 1, -1, -1};   long long dy[8] = {0, 0, 1, -1, 1, -1, 1, -1};   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long(t);     cin >> (t);     while ((t)--) {       long long n;       cin >> n;       vector<long long> v(n);       for (long long i = 0; i < n; i++) cin >> v[i];       long long ind = 0;       while (ind < n && v[ind] == 1) ind++;       if (ind == n) {         if (n % 2)           cout << ( First ) <<   n ;         else           cout << ( Second ) <<   n ;       } else {         if (ind % 2 == 0)           cout << ( First ) <<   n ;         else           cout << ( Second ) <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e6;   int cost[N], n, a, b, T;   string s;   long long l[N], r[N];   bool check(int d) {     --d;     long long bst = min(l[d], r[d]);     for (int i = 1; i < d; ++i) {       bst = min(bst, l[i] + r[d - i] + a * i);       bst = min(bst, r[i] + l[d - i] + a * i);     }     return bst + d + 1 + cost[0] <= T;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> a >> b >> T;     cin >> s;     for (int i = 0; i < s.size(); ++i) {       cost[i] = (s[i] ==  w  ? b : 0);     }     for (int i = 1; i < n; ++i) {       r[i] = r[i - 1] + cost[i] + a;     }     for (int i = 1; i < n; ++i) {       l[i] = l[i - 1] + cost[n - i] + a;     }     int L = 0, R = n + 1;     while (R - L > 1) {       int m = (L + R) >> 1;       if (check(m))         L = m;       else         R = m;     }     cout << L;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a, s, d, f, g, h, j, k, l, i, n, m;   string x[2], z[2];   char c;   int dfs(int i1, int i2, int tri) {     if (x[0] == z[0] && x[1] == z[1]) {       return 1;     }     if (tri < 0) return 0;     int ret = 0;     if (i1 < 1) {       c = x[i1][i2];       x[i1][i2] = x[i1 + 1][i2];       x[i1 + 1][i2] = c;       ret = dfs(i1 + 1, i2, tri - 1);       c = x[i1][i2];       x[i1][i2] = x[i1 + 1][i2];       x[i1 + 1][i2] = c;     }     if (i1 > 0) {       c = x[i1][i2];       x[i1][i2] = x[i1 - 1][i2];       x[i1 - 1][i2] = c;       ret |= dfs(i1 - 1, i2, tri - 1);       c = x[i1][i2];       x[i1][i2] = x[i1 - 1][i2];       x[i1 - 1][i2] = c;     }     if (i2 < 1) {       c = x[i1][i2];       x[i1][i2] = x[i1][i2 + 1];       x[i1][i2 + 1] = c;       ret |= dfs(i1, i2 + 1, tri - 1);       c = x[i1][i2];       x[i1][i2] = x[i1][i2 + 1];       x[i1][i2 + 1] = c;     }     if (i2 > 0) {       c = x[i1][i2];       x[i1][i2] = x[i1][i2 - 1];       x[i1][i2 - 1] = c;       ret |= dfs(i1, i2 - 1, tri - 1);       c = x[i1][i2];       x[i1][i2] = x[i1][i2 - 1];       x[i1][i2 - 1] = c;     }     return 0 | ret;   }   int main() {     cin >> x[0] >> x[1] >> z[0] >> z[1];     for (i = 0; i < 2; i++) {       for (a = 0; a < 2; a++) {         if (x[i][a] ==  X ) {           l = i;           j = a;         }       }     }     if (dfs(l, j, 20) != 0)       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     long long a(-1), b(-1), ans(INT_MAX), tempA, tempB;     for (int i = 0;; i++) {       if (i * 7 > n) {         break;       }       if ((n - i * 7) % 4 == 0) {         tempA = (n - i * 7) / 4;         tempB = i;         if (tempA + tempB < ans) {           a = tempA;           b = tempB;           ans = a + b;         }       }     }     if (a == -1 && b == -1) {       cout << -1 << endl;     } else {       for (int i = 0; i < a; i++) {         cout << 4;       }       for (int i = 0; i < b; i++) {         cout << 7;       }       cout <<   n ;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.precision(8);     long long t(1);     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ans;   int n, a, b;   vector<pair<int, int> > v;   int main() {     ans = 0;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d %d , &a, &b);       v.push_back(make_pair(b, a));     }     sort(v.begin(), v.end());     for (int i = 0, j = 0; i < v.size(); ++i) {       if (v[i].second > j) {         j = v[i].first;         ++ans;       }     }     printf( %I64d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using cd = complex<double>;   const double PI = acos(-1);   int reverse(int num, int lg_n) {     int res = 0;     for (int i = 0; i < lg_n; i++) {       if (num & (1 << i)) res |= 1 << (lg_n - 1 - i);     }     return res;   }   void fft(vector<cd> &a, bool invert) {     int n = a.size();     int lg_n = 0;     while ((1 << lg_n) < n) lg_n++;     for (int i = 0; i < n; i++) {       if (i < reverse(i, lg_n)) swap(a[i], a[reverse(i, lg_n)]);     }     for (int len = 2; len <= n; len <<= 1) {       double ang = 2 * PI / len * (invert ? -1 : 1);       cd wlen(cos(ang), sin(ang));       for (int i = 0; i < n; i += len) {         cd w(1);         for (int j = 0; j < len / 2; j++) {           cd u = a[i + j], v = a[i + j + len / 2] * w;           a[i + j] = u + v;           a[i + j + len / 2] = u - v;           w *= wlen;         }       }     }     if (invert) {       for (cd &x : a) x /= n;     }   }   vector<int> mult(vector<cd> &a, vector<cd> &b) {     vector<cd> fa(a.begin(), a.end()), fb(b.begin(), b.end());     int n = 1;     while (n < a.size() + b.size()) n <<= 1;     fa.resize(n);     fb.resize(n);     fft(fa, false);     fft(fb, false);     for (int i = 0; i < n; i++) fa[i] *= fb[i];     fft(fa, true);     vector<int> result(n);     for (int i = 0; i < n; i++) {       result[i] = round(fa[i].real());     }     return result;   }   long long mdp[1000010];   void crive() {     for (long long i = 2; i <= 1000000; i++) {       if (mdp[i] == 0) {         mdp[i] = i;         for (long long j = i * i; j <= 1000000; j += i) {           if (mdp[j] == 0) mdp[j] = i;         }       }     }   }   vector<long long> div(int l) {     vector<long long> ans = {1};     int sz = 1;     while (l > 1) {       long long p = mdp[l];       long long it = p;       while (l % it == 0) {         for (int j = 0; j < sz; j++) ans.push_back(it * ans[j]);         it *= p;       }       it /= p;       sz = ans.size();       l /= it;     }     sort(ans.begin(), ans.end());     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     crive();     long long n, x, y;     cin >> n >> x >> y;     vector<cd> a(x + 1), b(x + 1);     for (int i = 0; i < n + 1; i++) {       int num;       cin >> num;       a[x - num] = 1;       b[num] = 1;     }     vector<int> c = mult(a, b);     int q;     cin >> q;     for (int i = 0; i < q; i++) {       int l;       cin >> l;       vector<long long> d = div(l);       long long resp = -1;       for (int i = d.size() - 1; i >= 0 && d[i] > 2 * y; i--) {         long long u = d[i];         if (u & 1) continue;         if ((u - 2 * y) / 2 + x < c.size() && c[(u - 2 * y) / 2 + x])           resp = u, i = -1;       }       cout << resp <<    ;     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   struct segtree {     int n;     vector<long long> tree;     void init(int s) {       n = s;       tree.resize(4 * s);     }     long long qry(int i, int j) { return qry(i, j, 1, 0, n - 1); }     void upd(int i, long long v) { upd(i, v, 1, 0, n - 1); }     long long qry(int i, int j, int x, int nowi, int nowj) {       if (i <= nowi && nowj <= j) return tree[x];       if (nowi > j || nowj < i) return 0;       int m = (nowi + nowj) / 2;       return qry(i, j, 2 * x, nowi, m) + qry(i, j, 2 * x + 1, m + 1, nowj);     }     void upd(int i, long long v, int x, int nowi, int nowj) {       if (nowi == i && nowj == i) {         tree[x] = v;         return;       }       if (nowi > i || nowj < i) return;       int m = (nowi + nowj) / 2;       upd(i, v, 2 * x, nowi, m);       upd(i, v, 2 * x + 1, m + 1, nowj);       tree[x] = tree[2 * x] + tree[2 * x + 1];     }   };   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, ans = 0;     cin >> n;     n *= 2;     vector<int> a(n), p(n + 1, -1), v(n + 1);     for (auto &i : a) cin >> i;     for (int i = 0; i < n; ++i) {       if (p[a[i]] == -1) p[a[i]] = i;       v[i] = p[a[i]];     }     segtree s;     s.init(n);     for (int i = n - 1; ~i; --i) {       s.upd(v[i], 1);       if (v[i]) ans += s.qry(0, v[i] - 1);     }     cout << ans;   }