malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;         const int maxn = 2e5+5;   typedef long long ll;      char s[maxn],f[maxn];   int t[maxn<<2],lz[maxn<<2];      void pushup(int rt){    t[rt]=t[rt<<1]+t[rt<<1|1];   }   void pushdown(int rt,int l,int r){    if(lz[rt]!=-1){     int mid=l+r>>1;     t[rt<<1]=lz[rt]*(mid-l+1);     t[rt<<1|1]=lz[rt]*(r-mid);     lz[rt<<1]=lz[rt<<1|1]=lz[rt];     lz[rt]=-1;    }   }   void build(int rt,int l,int r){    lz[rt]=-1;    if(l==r){     t[rt]=f[l]- 0 ;     return;    }    int mid=l+r>>1;    build(rt<<1,l,mid);    build(rt<<1|1,mid+1,r);    pushup(rt);   }   void cg(int rt,int l,int r,int ql,int qr,int v){    if(l>=ql && r<=qr){     t[rt]=(r-l+1)*v;     lz[rt]=v;      return;    }    int mid=l+r>>1;    pushdown(rt,l,r);    if(ql<=mid && qr>=l)cg(rt<<1,l,mid,ql,qr,v);    if(ql<=r && qr>=mid+1)cg(rt<<1|1,mid+1,r,ql,qr,v);    pushup(rt);   }   int qry(int rt,int l,int r,int ql,int qr){    if(l>=ql && r<=qr){     return t[rt];    }     pushdown(rt,l,r);    int mid=l+r>>1;    int ans=0;    if(ql<=mid)ans+=qry(rt<<1,l,mid,ql,qr);    if(qr>=mid+1)ans+=qry(rt<<1|1,mid+1,r,ql,qr);    pushup(rt);    return ans;   }      struct Node{    int l,r;   }a[maxn];   int main(){    int t;    scanf( %d ,&t);    while(t--){     int n,q;     scanf( %d%d%s%s ,&n,&q,s+1,f+1);     build(1,1,n);     bool failed=false;     for(int i=1;i<=q;++i){      scanf( %d%d ,&a[i].l,&a[i].r);     }     for(int i=q;i>=1;--i){      int l=a[i].l,r=a[i].r;      int num=qry(1,1,n,l,r),k=(r-l+2)/2-1;      if(r-l+1<=2){       if(num!=r-l+1 && num){        failed=true;        break;       }      }else if(r-l+1-num<=k)cg(1,1,n,l,r,1);else if(num<=k)cg(1,1,n,l,r,0);else{       if(num!=r-l+1 && num){        failed=true;        break;       }      }     }     if(failed){      printf( NO n );      continue;     }     for(int i=1;i<=n;++i){      if(qry(1,1,n,i,i)!=s[i]- 0 ){       failed=true;       break;      }     }     if(failed){      printf( NO n );     }else printf( YES n );    }   }/*test:   2   9 10   111101101   110001101   7 7   9 9   5 5   1 4   7 7   3 3   5 5   9 9   9 9   5 5   */
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, i = 0, j = 0;     cin >> a >> b;     if (a > b) {       i = b;       a = a - b;       j = a / 2;     } else if (a < b) {       i = a;       b = b - a;       j = b / 2;     } else {       i = a;       j = 0;     }     cout << i <<     << j;   }
#include <bits/stdc++.h>   using namespace std;   const long long mo = 998244353;   const long long g = 3;   const int N = 500000;   int n, ax, bx, rev[N + 10];   long long aa[N + 10], bb[N + 10], c[N + 10], fac[N + 10], inv[N + 10];   long long mul(long long x, long long y) {     long long z = 1;     while (y) {       if (y & 1) z = z * x % mo;       y >>= 1;       x = x * x % mo;     }     return z;   }   struct poly {     vector<int> a;     void pre(int n) {       rev[0] = 0;       for (int i = 1; i < n; i++)         if (i & 1)           rev[i] = rev[i ^ 1] + (n >> 1);         else           rev[i] = rev[i >> 1] >> 1;     }     void FFT(long long *a, int n) {       for (int i = 0; i < n; i++) c[rev[i]] = a[i];       for (int i = 2; i <= n; i <<= 1) {         long long wn = mul(g, (mo - 1) / i);         for (int j = 0; j < n; j += i) {           long long w = 1;           for (int k = j; k < j + i / 2; k++, w = wn * w % mo) {             long long ck = c[k];             c[k] = (ck + w * c[k + i / 2]) % mo;             c[k + i / 2] = (ck - w * c[k + i / 2]) % mo;           }         }       }       for (int i = 0; i < n; i++) a[i] = (c[i] + mo) % mo;     }     void IFFT(long long *a, int n) {       FFT(a, n);       for (int i = 1; i < n / 2; i++) swap(a[i], a[n - i]);       long long invn = mul(n, mo - 2);       for (int i = 0; i < n; i++) a[i] = a[i] * invn % mo;     }     poly operator*(poly &p) {       int sz = a.size() + p.a.size() - 1;       int nx = 1;       while (nx < sz) nx <<= 1;       pre(nx);       for (int i = 0; i < nx; i++) {         if (i < (int)a.size())           aa[i] = a[i];         else           aa[i] = 0;         if (i < (int)p.a.size())           bb[i] = p.a[i];         else           bb[i] = 0;       }       FFT(aa, nx);       FFT(bb, nx);       for (int i = 0; i < nx; i++) aa[i] = aa[i] * bb[i] % mo;       IFFT(aa, nx);       poly ans;       ans.a.clear();       for (int i = 0; i < sz; i++) ans.a.push_back(aa[i]);       return ans;     }   };   void prework() {     fac[0] = 1;     for (int i = 1; i <= N; i++) fac[i] = fac[i - 1] * i % mo;     inv[N] = mul(fac[N], mo - 2);     for (int i = N - 1; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % mo;   }   poly Calc_Stirling(int l, int r) {     poly f;     f.a.clear();     if (l > r) {       f.a.push_back(1);       return f;     }     if (l == r) {       f.a.push_back(l);       f.a.push_back(1);       return f;     }     int mid = (l + r) / 2;     f = Calc_Stirling(l, mid);     poly g = Calc_Stirling(mid + 1, r);     f = f * g;     return f;   }   int main() {     scanf( %d%d%d , &n, &ax, &bx);     if (ax == 0 || bx == 0) {       printf( 0 n );       return 0;     }     prework();     poly f = Calc_Stirling(0, n - 2);     long long ans;     if (ax + bx - 2 < (int)f.a.size())       ans = f.a[ax + bx - 2];     else       ans = 0;     ans =         (ans * fac[ax + bx - 2] % mo * inv[ax - 1] % mo * inv[bx - 1] % mo + mo) %         mo;     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long m, b;     cin >> m >> b;     long long Max = 0;     for (long long i = b; i >= 0; i--) {       long long p = (m * b - m * i + 1) * (i + 1) * (m * b - m * i + i) / 2;       Max = max(p, Max);     }     printf( %I64d , Max);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int L = 1 << 20;   const int R = 1 << 21;   const int Maxn = 200005;   int tree[R], A, B;   int d[Maxn];   char s[Maxn];   bool vowel(char x) {     x = tolower(x);     if (x ==  a  || x ==  e  || x ==  i  || x ==  o  || x ==  u ) return 1;     return 0;   }   int read(int lo, int hi, int x) {     if (hi < A || lo > B) return Maxn;     if (A <= lo && hi <= B) return tree[x];     int mid = (lo + hi) >> 1;     return min(read(lo, mid, 2 * x), read(mid + 1, hi, 2 * x + 1));   }   void update(int x, int id) {     tree[x] = min(id, tree[x]);     for (x >>= 1; x > 0; x >>= 1) tree[x] = min(tree[2 * x], tree[2 * x + 1]);   }   int main() {     for (int i = 0; i < R; ++i) tree[i] = Maxn;     scanf( %s , s);     int n = strlen(s);     for (int i = 0; i < n; ++i) {       if (i) d[i] = d[i - 1];       if (vowel(s[i]))         --d[i];       else         d[i] += 2;     }     for (int i = 0; i < n; ++i) d[i] += Maxn;     update(L + Maxn, -1);     int sol = 0, cnt = 0;     for (int i = 0; i < n; ++i) {       A = L, B = L + d[i];       int id = read(L, R - 1, 1);       update(L + d[i], i);       if (id == Maxn) continue;       if (i - id > sol)         sol = i - id, cnt = 1;       else if (i - id == sol)         ++cnt;     }     if (!sol)       printf( No solution n );     else       printf( %d %d n , sol, cnt);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int T;   int h, c, t;   int main() {     scanf( %d , &T);     while (T--) {       scanf( %d%d%d , &h, &c, &t);       if (t * 2 <= (h + c))         printf( %d n , 2);       else {         long long lef = (h - t) / (2 * t - (h + c));         double a1 = (1.0 * h * (lef + 1) + c * lef) / (2 * lef + 1);         lef++;         double a2 = (1.0 * h * (lef + 1) + c * lef) / (2 * lef + 1);         if (abs(a1 - t) <= abs(a2 - t))           printf( %lld n , 2 * (lef - 1) + 1);         else           printf( %lld n , 2 * lef + 1);       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int gi() {     int x = 0, o = 1;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) o = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * o;   }   int n, d, b, sum[N];   int calc() {     int s1 = 0, s2 = 0;     for (int i = 1; i <= (n + 1) / 2; i++) {       int f1 = sum[min(i + 1ll * d * i, (long long)n)] - s1 * b;       int f2 = sum[n] - sum[max(0ll, n - i - 1ll * d * i)] - s2 * b;       if (i == n - i + 1)         s1 += f1 >= b;       else         s1 += f1 >= b, s2 += f2 >= b;     }     return min(s1 - n % 2, s2);   }   int main() {     cin >> n >> d >> b;     for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + gi();     printf( %d n , n / 2 - calc());     return 0;   }
#include <bits/stdc++.h>   template <typename T>   inline void SWAP(T &a, T &b) {     T tmp = a;     a = b;     b = tmp;   }   template <typename T>   inline T ABS(const T &val) {     return val < 0 ? -val : val;   }   template <typename T>   inline T MAX(const T &a, const T &b) {     return a > b ? a : b;   }   template <typename T>   inline T MIN(const T &a, const T &b) {     return a < b ? a : b;   }   template <typename T>   inline T SQR(const T &a) {     return a * a;   }   const int INTinf = 2147483647;   const int nINTinf = 0 - 2147483648;   using namespace std;   int n, m, p;   const int SZ = 20002;   int _X[SZ], _Y[SZ];   int A[142][SZ];   int B[141][SZ];   int F[SZ << 1];   int *m1, *m2;   int kol = 0;   long long answ2 = 0L;   string answ =   ;   inline int f(const int &a, const int &b) { return F[_X[a] + _Y[b]]; }   int main() {     cin >> n >> m >> p;     int SZ2 = SZ << 1;     for (int i = 0; i != SZ2; i++) {       F[i] = i % p;     }     for (int i = 0; i != n; i++) cin >> _X[i];     for (int i = 0; i != m; i++) cin >> _Y[i];     m1 = A[0];     m1[0] = f(0, 0);     for (int i = 1; i <= n - 1; i++) {       m1[i] = m1[i - 1] + f(i, 0);     }     int nPos = 0;     for (int i = 1; i <= m - 1; i++) {       if (!nPos) {         copy(m1, m1 + SZ, B[kol++]);       }       nPos++;       if (nPos == 142) nPos = 0;       m2 = A[nPos];       m2[0] = m1[0] + f(0, i);       for (int j = 1; j <= n - 1; j++) {         m2[j] = MAX(m1[j], m2[j - 1]) + f(j, i);       }       m1 = m2;     }     int Y = n - 1;     int X = m - 1;     while (true) {       while (Y && (A[nPos][Y] - f(Y, X) == A[nPos][Y - 1])) {         answ.push_back( C );         answ2 += f(Y, X);         Y--;       }       answ2 += f(Y, X);       answ.push_back( S );       X--;       if (!nPos) {         break;       }       nPos--;     }     kol--;     if (m % 142 != 1) {       kol--;     }     while (kol > -1) {       copy(B[kol], B[kol] + SZ, A[0]);       int to = (kol + 1) * 142;       m1 = A[0];       for (int i = 142 * kol + 1; i != to; i++) {         nPos++;         m2 = A[nPos];         m2[0] = m1[0] + f(0, i);         for (int j = 1; j <= n - 1; j++) {           m2[j] = MAX(m1[j], m2[j - 1]) + f(j, i);         }         m1 = m2;       }       while (true) {         while (Y && (A[nPos][Y] - f(Y, X) == A[nPos][Y - 1])) {           answ.push_back( C );           answ2 += f(Y, X);           Y--;         }         answ2 += f(Y, X);         answ.push_back( S );         X--;         if (!nPos) {           break;         }         nPos--;       }       kol--;     }     answ = answ.substr(0, answ.size() - 1);     reverse(answ.begin(), answ.end());     cout << answ2 << endl;     cout << answ << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s, t;     cin >> s >> t;     if (s ==  monday  && (t ==  thursday  || t ==  wednesday  || t ==  monday ))       cout <<  YES ;     else if (s ==  tuesday  &&              (t ==  friday  || t ==  thursday  || t ==  tuesday ))       cout <<  YES ;     else if (s ==  wednesday  &&              (t ==  friday  || t ==  saturday  || t ==  wednesday ))       cout <<  YES ;     else if (s ==  thursday  &&              (t ==  saturday  || t ==  sunday  || t ==  thursday ))       cout <<  YES ;     else if (s ==  friday  && (t ==  sunday  || t ==  monday  || t ==  friday ))       cout <<  YES ;     else if (s ==  saturday  &&              (t ==  monday  || t ==  tuesday  || t ==  saturday ))       cout <<  YES ;     else if (s ==  sunday  &&              (t ==  tuesday  || t ==  wednesday  || t ==  sunday ))       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, t, timer = 0;     scanf( %d%d%d , &n, &m, &t);     deque<int> q;     vector<int> col(n);     char isOk = false;     for (int i = 0, j = 0; i < n; i++) {       int x, y, z, start;       scanf(  n%d:%d:%d , &x, &y, &z);       start = x * 3600 + y * 60 + z;       while (!q.empty() && q.front() <= start) {         j--;         q.pop_front();       }       if (j < m) {         j++;         q.push_back(start + t);         timer++;       } else {         q.back() = start + t;       }       if (j == m) {         isOk = true;       }       col[i] = timer;     }     if (!isOk) {       printf( No solution );       return 0;     }     printf( %d n , timer);     for (int i : col) {       printf( %d n , i);     }     return 0;   }
#include <bits/stdc++.h>   struct vit {     int price;     char vit[4];   };   int main() {     int i, n, min;     scanf( %d , &n);     struct vit t[n];     for (i = 0; i < n; i++) {       scanf( %d %s , &t[i].price, t[i].vit);     }     int A = 300001, B = 300001, C = 300001, AB = 300001, AC = 300001, BC = 300001,         ABC = 300001;     for (i = 0; i < n; i++) {       if (strcmp( A , t[i].vit) == 0) {         if (A > t[i].price) A = t[i].price;       }     }     for (i = 0; i < n; i++) {       if (strcmp( B , t[i].vit) == 0) {         if (B > t[i].price) B = t[i].price;       }     }     for (i = 0; i < n; i++) {       if (strcmp( C , t[i].vit) == 0) {         if (C > t[i].price) C = t[i].price;       }     }     for (i = 0; i < n; i++) {       if ((strcmp( AB , t[i].vit) == 0) || (strcmp( BA , t[i].vit) == 0)) {         if (AB > t[i].price) AB = t[i].price;       }     }     for (i = 0; i < n; i++) {       if ((strcmp( BC , t[i].vit) == 0) || (strcmp( CB , t[i].vit) == 0)) {         if (BC > t[i].price) BC = t[i].price;       }     }     for (i = 0; i < n; i++) {       if ((strcmp( AC , t[i].vit) == 0) || (strcmp( CA , t[i].vit) == 0)) {         if (AC > t[i].price) AC = t[i].price;       }     }     for (i = 0; i < n; i++) {       if ((strcmp( ABC , t[i].vit) == 0) || (strcmp( ACB , t[i].vit) == 0) ||           (strcmp( BAC , t[i].vit) == 0) || (strcmp( BCA , t[i].vit) == 0) ||           (strcmp( CAB , t[i].vit) == 0) || (strcmp( CBA , t[i].vit) == 0)) {         if (ABC > t[i].price) ABC = t[i].price;       }     }     min = ABC;     if (A + B + C < min) min = A + B + C;     if (AB + C < min) min = AB + C;     if (BC + A < min) min = BC + A;     if (AC + B < min) min = AC + B;     if (AB + BC < min) min = AB + BC;     if (AB + AC < min) min = AB + AC;     if (BC + AC < min) min = BC + AC;     if (min > 300000) {       printf( -1 );       return 0;     }     printf( %d , min);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int f[200][200], c[500010], n, i, j, ans;   char a[500010], b[500010], str[20];   int main() {     cin >> n;     for (i = 1; i <= n; i++) {       scanf( %s , str);       a[i] = str[0], b[i] = str[strlen(str) - 1], c[i] = strlen(str);     }     memset(f, -1, sizeof(f));     for (i = 1; i <= n; i++) {       for (j =  a ; j <=  z ; j++)         if (f[j][a[i]] != -1) f[j][b[i]] = max(f[j][b[i]], f[j][a[i]] + c[i]);       f[a[i]][b[i]] = max(f[a[i]][b[i]], c[i]);     }     for (i =  a ; i <=  z ; i++) ans = max(ans, f[i][i]);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Edge {     long long to, dis, next, cost;   } edge[24050];   long long num = -1;   bool vis[10010];   long long mincost;   long long pre[10010], head[10010], cost[10010], last[10010], flow[10010], n, k,       a[110], b[110], s, t, maxflow;   long long to[110];   void add(long long f, long long t, long long dis, long long cost) {     edge[++num].to = t;     edge[num].dis = dis;     edge[num].next = head[f];     edge[num].cost = cost;     head[f] = num;     edge[++num].to = f;     edge[num].dis = 0;     edge[num].cost = -cost;     edge[num].next = head[t];     head[t] = num;   }   queue<long long> q;   bool spfa(long long s, long long t) {     memset(cost, 0x3f3f3f3f, sizeof cost);     memset(flow, 0x3f3f3f3f, sizeof flow);     memset(vis, 0, sizeof vis);     q.push(s);     vis[s] = 1;     cost[s] = 0;     pre[t] = -1;     while (!q.empty()) {       long long nowp = q.front();       q.pop();       vis[nowp] = 0;       for (long long i = head[nowp]; i != -1; i = edge[i].next) {         if (edge[i].dis > 0 && cost[edge[i].to] > cost[nowp] + edge[i].cost) {           cost[edge[i].to] = cost[nowp] + edge[i].cost;           pre[edge[i].to] = nowp;           last[edge[i].to] = i;           flow[edge[i].to] = min(flow[nowp], edge[i].dis);           if (!vis[edge[i].to]) {             vis[edge[i].to] = 1;             q.push(edge[i].to);           }         }       }     }     return pre[t] != -1;   }   void MCMF(long long s, long long t) {     while (spfa(s, t)) {       long long now = t;       maxflow += flow[t];       mincost += flow[t] * cost[t];       while (now != s) {         edge[last[now]].dis -= flow[t];         edge[last[now] ^ 1].dis += flow[t];         now = pre[now];       }     }   }   signed main() {     long long T;     cin >> T;     while (T--) {       num = -1;       memset(to, -1, sizeof to);       memset(head, -1, sizeof head);       cin >> n >> k;       for (long long i = 1; i <= n; i++) cin >> a[i] >> b[i];       maxflow = mincost = 0;       s = 0;       t = 2 * n + 1;       for (long long i = 1; i <= n; i++) add(s, i, 1, 0), add(i + n, t, 1, 0);       for (long long i = 1; i <= n; i++) {         for (long long j = 1; j <= n; j++) {           long long nc = 0;           if (j <= k - 1)             nc = a[i] + b[i] * (j - 1ll);           else if (j != n)             nc = b[i] * (k - 1ll);           else             nc = a[i] + b[i] * (k - 1ll);           nc = 0x3f3f3f3f - nc;           add(i, j + n, 1, nc);         }       }       MCMF(s, t);       long long nowi = -1;       for (long long i = n * 4; i <= num; i += 2) {         nowi++;         if (edge[i].dis == 0) to[1 + nowi % n] = 1 + nowi / n;       }       cout << 2 * n - k << endl;       for (long long i = 1; i <= k - 1; i++) cout << to[i] <<    ;       for (long long i = k; i < n; i++) cout << to[i] <<     << -to[i] <<    ;       cout << to[n];       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 29;   const double EPS = 1e-9;   const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};   int n, m;   int main() {     cin >> n >> m;     int ans = 0;     for (int i = 0; i <= n; i++) {       int tmp = 0;       int a1 = i;       int b1 = (m - 2 * i);       if (b1 < 0) break;       int r1, r2;       r1 = n - i;       r2 = (m - 2 * i);       int a2 = (r1 / 2);       int b2 = r2 - a2;       if (b2 < 0) {         tmp = i + r2;       } else {         tmp = i + a2;       }       ans = max(ans, tmp);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   struct hdm {     int first, second, id;     hdm(){};     hdm(int first, int second, int id) : first(first), second(second), id(id){};   };   vector<hdm> v1, v2;   bool cmp1(hdm A, hdm B) { return (A.second < B.second); }   bool cmp2(hdm A, hdm B) { return (A.first > B.first); }   int main() {     ios::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) {       int A, B;       cin >> A >> B;       pair<int, int> p = make_pair(A, B);       if (A > B) {         v1.push_back(hdm(A, B, i));       } else {         v2.push_back(hdm(A, B, i));       }     }     sort(v1.begin(), v1.end(), cmp1);     sort(v2.begin(), v2.end(), cmp2);     int rs1 = (int)v1.size();     int rs2 = (int)v2.size();     if (rs1 >= rs2) {       cout << rs1 <<   n ;       for (int i = 0; i < v1.size(); i++) cout << v1[i].id <<    ;     } else {       cout << rs2 <<   n ;       for (int i = 0; i < v2.size(); i++) cout << v2[i].id <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll base = 1000000007;   int n;   ll p2[1000000];   class reimu {    public:     ll sum, sum2;     int sz;     ll ans = 0;     void operator+=(reimu x) {       (sum2 += x.sum2) %= base;       (sum += x.sum) %= base;       sz += x.sz;     }     void operator-=(reimu x) {       (sum2 -= x.sum2) %= base;       (sum -= x.sum) %= base;       sz -= x.sz;     }     void cal() {       (ans = sum2 * p2[sz - 1] +              ((sz == 1) ? 0 : ((sum * sum - sum2) % base) * p2[sz - 2])) %= base;     }   } f[1000000];   ll pre[64];   int main() {     p2[0] = 1;     for (int i = 1; i < 1000000; i++) (p2[i] = p2[i - 1] * 2) %= base;     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n;     for (int i = 0; i < 64; i++) {       for (int d = 0, p10 = 1; d < 6; d++, p10 *= 10)         if (i & (1 << d)) {           pre[i] += p10;         }     }     for (int i = 0; i < n; i++) {       ll a;       cin >> a;       reimu temp;       temp.sum = a;       (temp.sum2 = a * a) %= base;       temp.sz = 1;       f[a] += temp;     }     for (int x = 999999; x >= 0; x--) {       int mask = 0;       for (int d = 0, p10 = 1; d < 6; d++, p10 *= 10) {         if ((x / p10) % 10 != 9) mask |= 1 << d;       }       for (int sub = mask; sub; (sub -= 1) &= mask) {         if (__builtin_popcount(sub) % 2 == 1)           f[x] += f[x + pre[sub]];         else           f[x] -= f[x + pre[sub]];       }     }     for (int i = 0; i <= 999999; i++) f[i].cal();     ll ans = 0;     for (int x = 0; x <= 999999; x++) {       int mask = 0;       for (int d = 0, p10 = 1; d < 6; d++, p10 *= 10) {         if ((x / p10) % 10 != 9) mask |= 1 << d;       }       ll res = f[x].ans;       for (int sub = mask; sub; (sub -= 1) &= mask) {         if (__builtin_popcount(sub) % 2 == 0)           res += f[x + pre[sub]].ans;         else           res -= f[x + pre[sub]].ans;       }       ((res %= base) += base) %= base;       (res *= x);       ans ^= res;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   bool isPrime(int N) {     for (int i = 2; i * i <= N; ++i) {       if (N % i == 0) return false;     }     return true;   }   bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {     return (a.first > b.first);   }   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   bool comp(const pair<int, int> &a, const pair<int, int> &b) {     if (a.first == b.first)       return a.second < b.second;     else       return a.first > b.first;   }   int main() {     int n;     cin >> n;     int flag = 0;     char a[5][5];     int max = 11;     int digit[11] = {0};     for (int i = 0; i < 4; i++) {       for (int j = 0; j < 4; j++) {         cin >> a[i][j];         if (a[i][j] !=  . ) {           digit[a[i][j] - 48]++;         }       }     }     for (int i = 0; i < 10; i++) {       if (digit[i] > 2 * n) {         cout <<  NO ;         flag = 1;         break;       }     }     if (flag == 0) {       cout <<  YES ;     }     return 0;   }