#include <bits/stdc++.h>   using namespace std;   long long a[300005];   vector<long long> adjlist[1048585];   int main() {     long long n, i;     scanf( %lld , &n);     for (i = 0; i < n; i++) {       scanf( %lld , a + i);     }     for (i = 1; i < n; i++) {       a[i] = a[i - 1] ^ a[i];     }     adjlist[0].push_back(0);     for (i = 0; i < n; i++) {       adjlist[a[i]].push_back(i + 1);     }     long long ans = 0;     for (i = 0; i < 1048580; i++) {       if (adjlist[i].size() > 0) {         long long od = 0, ev = 0;         for (auto e : adjlist[i]) {           if (e % 2 == 0)             ev++;           else             od++;         }         ans += (ev * (ev - 1)) / 2;         ans += (od * (od - 1)) / 2;       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   int n, m;   int d[250000];   int h[250000];   int c[250000];   int r[250000];   int diferencias[160000];   int a[401];   bool sirve(int v, int idCamion) {     int litros = v;     int cantRecargas = r[idCamion];     for (int i = d[idCamion] + 1; i <= h[idCamion]; i++) {       if (v < a[i] - a[i - 1]) {         return false;       }       if (litros < a[i] - a[i - 1]) {         if (cantRecargas) {           litros = v;           cantRecargas--;         } else {           return false;         }       }       litros -= a[i] - a[i - 1];     }     return true;   }   int cmpfunc(const void* a, const void* b) { return (*(int*)a - *(int*)b); }   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) scanf( %d , &a[i + 1]);     for (int i = 0; i < m; i++) scanf( %d %d %d %d , &d[i], &h[i], &c[i], &r[i]);     int tam2 = 0;     for (int i = 1; i <= n; i++)       for (int j = i; j <= n; j++) diferencias[tam2++] = a[j] - a[i];     qsort(diferencias, tam2, sizeof(int), cmpfunc);     int tam = 1;     for (int i = 1; i < tam2; i++)       if (diferencias[i] != diferencias[tam - 1])         diferencias[tam++] = diferencias[i];     long long minV = 0;     int ini, fin, mid;     for (int i = 0; i < m; i++) {       ini = 0;       fin = tam - 1;       while (ini + 1 < fin) {         mid = (ini + fin) / 2;         if (sirve(diferencias[mid], i))           fin = mid;         else           ini = mid;       }       if (sirve(diferencias[ini], i))         minV = (minV > ((long long)diferencias[ini]) * ((long long)c[i])                     ? minV                     : ((long long)diferencias[ini]) * ((long long)c[i]));       else         minV = (minV > ((long long)diferencias[fin]) * ((long long)c[i])                     ? minV                     : ((long long)diferencias[fin]) * ((long long)c[i]));     }     printf( %I64d n , minV);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[300010][27];   int val[300010], cost[610];   int fail[300010];   string st[610];   char s[300010], p[300010];   int main() {     int T, op, len, slen, i, j, k, x;     long long ans;     for (scanf( %d , &T); T; --T) {       scanf( %d %s , &op, s);       len = strlen(s);       if (op <= 2) {         if (len <= 500) {           for (i = 0, j = 0; i < len; ++i) {             if (!a[j][x = s[i] -  a ]) a[j][x] = ++m;             j = a[j][x];           }           val[j] += op == 1 ? 1 : -1;         } else {           st[++n] = s;           cost[n] = op == 1 ? 1 : -1;         }       } else {         ans = 0;         for (i = 0; i < len; ++i)           for (k = i, j = 0; k < len; ++k) {             if (!a[j][x = s[k] -  a ]) break;             j = a[j][x];             ans += val[j];           }         for (i = 1; i <= n; ++i) {           if ((slen = st[i].length()) > len) continue;           fail[0] = fail[1] = 0;           for (j = 1; j < slen; ++j) {             for (k = fail[j]; k && st[i][k] != st[i][j]; k = fail[k])               ;             fail[j + 1] = st[i][k] == st[i][j] ? k + 1 : 0;           }           for (j = 0, k = 0; j < len; ++j) {             while (k && st[i][k] != s[j]) k = fail[k];             if (st[i][k] == s[j]) ++k;             if (k == slen) {               ans += cost[i];               k = fail[k];             }           }         }         cout << ans << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1234567;   vector<int> rev[N];   char foo[N];   int on_cycle[N];   int digit[N], to[N];   bool found;   void dfs(int v, int pos) {     if (pos < 0) {       found = true;     }     if (found) {       return;     }     int sz = rev[v].size();     for (int j = 0; j < sz; j++) {       int u = rev[v][j];       if (on_cycle[u] != -1) {         continue;       }       dfs(u, pos - (digit[u] == foo[pos] -  0 ));     }   }   int dx[42], dy[42];   int last[42];   bool vis[N];   const int NNN = 444;   char s[NNN][NNN];   int main() {     int n, m, q;     scanf( %d %d %d , &n, &m, &q);     for (int i = 0; i < n; i++) {       scanf( %s , s[i]);     }     for (int d = 0; d <= 9; d++) {       scanf( %d %d , dx + d, dy + d);     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         int d = s[i][j] -  0 ;         int x = i + dx[d];         int y = j + dy[d];         if (x < 0 || y < 0 || x >= n || y >= m) {           x = i;           y = j;         }         digit[i * m + j] = d;         to[i * m + j] = x * m + y;       }     }     n = n * m;     for (int i = 0; i < n; i++) {       vis[i] = false;       rev[i].clear();       on_cycle[i] = -1;     }     for (int i = 0; i < n; i++) {       rev[to[i]].push_back(i);     }     for (int i = 0; i < n; i++) {       if (vis[i]) {         continue;       }       int p = i;       vector<int> cycle;       while (!vis[p]) {         cycle.push_back(p);         vis[p] = true;         p = to[p];       }       int id = -1;       for (int i = 0; i < (int)cycle.size(); i++) {         if (cycle[i] == p) {           id = i;           break;         }       }       if (id == -1) {         continue;       }       int mask = 0;       for (int i = id; i < (int)cycle.size(); i++) {         mask |= (1 << digit[cycle[i]]);       }       for (int i = id; i < (int)cycle.size(); i++) {         on_cycle[cycle[i]] = mask;       }     }     while (q--) {       scanf( %s , foo);       int len = strlen(foo);       for (int d = 0; d <= 9; d++) {         last[d] = -1;       }       for (int i = 0; i < len; i++) {         last[foo[i] -  0 ] = i;       }       found = false;       for (int start = 0; start < n; start++) {         if (on_cycle[start] == -1) {           continue;         }         int pos = -1;         for (int d = 0; d <= 9; d++) {           if (on_cycle[start] & (1 << d)) {             continue;           }           pos = max(pos, last[d]);         }         dfs(start, pos);       }       puts(found ?  YES  :  NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     vector<int> v;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int t;       cin >> t;       v.push_back(t);     }     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());     v.erase(remove(v.begin(), v.end(), 0), v.end());     cout << v.size() <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int d, f, t;     long long c;   } a[100005];   int cmp(node a, node b) { return a.d < b.d; }   long long INF = 0x3f3f3f3f3f3f;   long long cost[100005];   int vis[100005];   int cnt1[1000006];   int cnt2[1000006];   long long sum2[1000006];   long long sum1[1000006];   int main() {     int n, m, k;     memset(cnt1, 0, sizeof(cnt1));     memset(cnt2, 0, sizeof(cnt2));     memset(vis, 0, sizeof(vis));     memset(cost, INF, sizeof(cost));     memset(sum1, 0, sizeof(sum1));     memset(sum2, 0, sizeof(sum2));     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= m; i++) {       scanf( %d%d%d%I64d , &a[i].d, &a[i].f, &a[i].t, &a[i].c);     }     sort(a + 1, a + 1 + m, cmp);     int pre = 0;     for (int i = 1; i <= m; i++) {       if (a[i].f == 0) continue;       int f = a[i].f;       int d = a[i].d;       sum1[d] = sum1[pre];       cnt1[d] = cnt1[pre];       if (cost[f] > a[i].c) {         if (vis[f] == 1)           sum1[d] = sum1[d] - cost[f] + a[i].c;         else           sum1[d] += a[i].c;         cost[f] = a[i].c;         if (vis[f] == 0) {           cnt1[d]++;           vis[f] = 1;         }       }       pre = d;     }     for (int i = 1; i <= 1000000; i++) {       if (cnt1[i] == 0) cnt1[i] = cnt1[i - 1];       if (sum1[i] == 0) sum1[i] = sum1[i - 1];     }     memset(vis, 0, sizeof(vis));     pre = 1000000;     memset(cost, INF, sizeof(cost));     for (int i = m; i >= 1; i--) {       if (a[i].t == 0) continue;       int d = a[i].d;       int t = a[i].t;       sum2[d] = sum2[pre];       cnt2[d] = cnt2[pre];       if (cost[t] > a[i].c) {         if (vis[t] == 1)           sum2[d] = sum2[d] - cost[t] + a[i].c;         else           sum2[d] += a[i].c;         cost[t] = a[i].c;         if (vis[t] == 0) {           cnt2[d]++;           vis[t] = 1;         }       }       pre = d;     }     for (int i = 1000000; i >= 0; i--) {       if (cnt2[i] == 0) cnt2[i] = cnt2[i + 1];       if (sum2[i] == 0) sum2[i] = sum2[i + 1];     }     long long ans = INF;     for (int i = 1; i <= 1000000; i++) {       if (i + k + 1 > 1000000) break;       if (cnt1[i] == n && cnt2[i + k + 1] == n)         ans = min(ans, (long long)sum1[i] + sum2[i + k + 1]);     }     if (ans == INF) {       printf( -1 n );       return 0;     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e6;   long long n, b, s[MAXN], m[MAXN], t = 0;   long long i, j, d = 0;   bool q[MAXN];   int main() {     cin >> n >> b;     fill(q, q + n, false);     for (i = 0; i < n; i++) {       cin >> s[i] >> m[i];     }     j = 0;     for (i = 0; i < n; i++) {       if (i > 0) cout << endl;       if (j == i && q[j] == false) {         q[j] = true;         t = s[i];         d++;         j++;       }       if (q[i] == true) {         t += m[i];         d--;         cout << t;       } else         cout << -1;       while (q[j] == false && t > s[j] && j < n) {         if (d + 1 > b)           d--;         else           q[j] = true;         j++;         d++;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2111;   const int mod = 1e9 + 7;   int n;   int pri[N], tot;   long long a[N], b[N];   struct node {     long long k, b;     node(long long _k = 0, long long _b = 0) {       k = _k;       b = _b;     }   } f[N], g[N];   long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }   long long ksm(long long base, long long x) {     long long ans = 1;     while (x) {       if (x & 1) ans = ans * base % mod;       base = base * base % mod;       x >>= 1;     }     return ans;   }   void get(int x) {     for (int i = 2; i * i <= x; i++) {       if (x % i == 0) {         pri[++tot] = i;         while (x % i == 0) x /= i;       }     }     if (x > 1) pri[++tot] = x;   }   void get_g(int id) {     for (int i = 1; i <= tot; i++) {       g[i].b = g[i].k = 0;       while (a[id] % pri[i] == 0) {         g[i].b++;         a[id] /= pri[i];       }       while (b[id] % pri[i] == 0) {         g[i].k++;         b[id] /= pri[i];       }     }   }   long long ex_gcd(long long A, long long B, long long &x, long long &y) {     if (!B) {       x = 1;       y = 0;       return A;     }     long long xx, yy;     long long d = ex_gcd(B, A % B, xx, yy);     x = yy;     y = xx - A / B * yy;     return d;   }   bool merge() {     bool flag = 0;     for (int t = 0; t < 3; t++) {       for (int i = 1; i <= tot; i++) {         long long fk = f[i].k, fb = f[i].b;         long long gk = g[i].k, gb = g[i].b;         bool fl = 0;         if (!fk && !gk) {           if (fb != gb) return 0;         } else {           if (!gk || !fk) {             if (!fk) swap(fk, gk), swap(fb, gb), fl = 1;             if (fb > gb || (gb - fb) % fk != 0) return 0;             long long k = (gb - fb) / fk;             if (fl)               for (int j = 1; j <= tot; j++) g[j].b += g[j].k * k, g[j].k = 0;             else               for (int j = 1; j <= tot; j++) f[j].b += f[j].k * k, f[j].k = 0;             flag = 1;           }         }       }     }     if (flag) return 1;     int fl = 0;     long long A = 0, B = 0, C = 0;     for (int i = 1; i <= tot; i++) {       if (!f[i].k || !g[i].k) continue;       if (!fl)         A = f[i].k, B = -g[i].k, C = g[i].b - f[i].b, fl = 1;       else if (fl == 1) {         long long nA = f[i].k, nB = -g[i].k, nC = g[i].b - f[i].b;         long long d = gcd(nA, A);         A *= nA / d;         B *= nA / d;         C *= nA / d;         nA *= A / d;         nB *= A / d;         nC *= A / d;         if (B == nB) {           if (C != nC) return 0;           long long d = gcd(A, gcd(abs(B), abs(C)));           A /= d;           B /= d;           C /= d;           continue;         } else {           if ((C - nC) % (B - nB)) return 0;           long long y = (C - nC) / (B - nB);           if (y < 0) return 0;           if ((C - B * y) % A) return 0;           long long x = (C - B * y) / A;           if (x < 0) return 0;           for (int j = 1; j <= tot; j++) f[j].b += f[j].k * x, f[j].k = 0;           for (int j = i + 1; j <= tot; j++) {             nA = f[j].k, nB = -g[j].k, nC = g[j].b - f[j].b;             if (nA * x + nB * y != nC) return 0;           }           return 1;         }       }     }     long long x = -1, y = -1;     long long d = ex_gcd(A, -B, x, y);     if (C % d) return 0;     y *= -1;     long long kx = (-B) / d;     long long ky = A / d;     x *= C / d, y *= C / d;     long long tx = x < 0 ? -(-x + kx - 1) / kx : x / kx;     long long ty = y < 0 ? -(-y + ky - 1) / ky : y / ky;     x -= min(tx, ty) * kx;     y -= min(tx, ty) * ky;     for (int i = 1; i <= tot; i++) {       f[i].b += f[i].k * x;       f[i].k = f[i].k * kx;     }     return 1;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d%d , &a[i], &b[i]);       get(a[i]);       get(b[i]);     }     sort(pri + 1, pri + 1 + tot);     tot = unique(pri + 1, pri + 1 + tot) - (pri + 1);     for (int i = 1; i <= tot; i++) {       while (a[1] % pri[i] == 0) {         f[i].b++;         a[1] /= pri[i];       }       while (b[1] % pri[i] == 0) {         f[i].k++;         b[1] /= pri[i];       }     }     for (int i = 2; i <= n; i++) {       get_g(i);       if (!merge()) {         puts( -1 );         return 0;       }     }     int ans = 1;     for (int i = 1; i <= tot; i++) {       ans = 1LL * ans * ksm(pri[i], f[i].b) % mod;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     long long u, v, a, b;     scanf( %lld%lld , &u, &v);     if (v == 0)       printf( 0 n );     else if (u > v)       printf( -1 n );     else if (u == v) {       printf( 1 n );       printf( %lld n , u);     } else if ((v - u) % 2 == 0) {       a = u, b = (v - u) / 2;       if ((a ^ b) == (a + b)) {         printf( 2 n );         printf( %lld %lld n , a + b, b);       } else {         printf( 3 n );         printf( %lld %lld %lld n , a, b, b);       }     } else       printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k = 0, c = -1, x, z;     cin >> n;     while (true) {       c += 1;       x = pow(10, c);       z = 9 * x;       if (n - z > 0) {         n -= z;         k += (z * (c + 1));       } else {         n *= (c + 1);         k += n;         break;       }     }     cout << k;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[27], sum, gcd;   int odd;   int _gcd(int x, int y) {     if (x == 0 or x == y) return y;     if (x > y) swap(x, y);     while (y % x) {       y %= x;       swap(x, y);     }     return x;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , a + i);       if (a[i] & 1) odd++;       sum += a[i];       gcd = _gcd(gcd, a[i]);     }     if (odd > 1) {       printf( %d n , 0);       int k = 0;       string s(sum,  0 );       for (int i = 0; i < n; i++) {         int j = 0;         while (j < a[i]) {           s[j + k] =  a  + i;           j++;         }         k += a[i];       }       cout << s << endl;       return 0;     }     for (int i = 0; i < n; i++) a[i] /= gcd;     sum /= gcd;     printf( %d n , gcd);     if (odd) {       string s(sum,  0 );       int k = 0;       for (int i = 0; i < n; i++) {         int j = 0;         while (j < a[i] / 2) {           s[j + k] =  a  + i;           s[sum - 1 - j - k] =  a  + i;           j++;         }         if (a[i] & 1) odd = i;         k += a[i] / 2;       }       s[k] = odd +  a ;       for (int i = 0; i < gcd; i++) cout << s;       cout << endl;     } else {       string s(sum,  0 );       string t(sum,  0 );       int k = 0;       for (int i = 0; i < n; i++) {         int j = 0;         while (j < a[i]) {           s[j + k] =  a  + i;           t[sum - 1 - j - k] =  a  + i;           t[sum - 1 - j - k] =  a  + i;           j++;         }         k += a[i];       }       for (int i = 0; i < gcd / 2; i++) cout << s << t;       cout << endl;     }   }


#include<bits/stdc++.h>   using namespace std;   #define ll long long   #define mod 1000000007   void solve()   {           int k,n,m;           cin >> k >> n >> m;           vector<int> a(n);           for(auto &i:a)           {               cin >> i;           }           vector<int> b(m);           for(auto &i:b)           {               cin >> i;           }           vector<int> res(n+m);           int i=0,j=0,ind=0;           while(i!=n && j!=m)           {               if(a[i]==0)               {                   res[ind]=0;                   ind++;                   i++;                   k++;               }               else if(b[j]==0)               {                   res[ind]=0;                   ind++;                   j++;                   k++;               }               else if(a[i]<=b[j] && a[i]<=k)               {                   res[ind]=a[i];                   ind++;                   i++;               }               else if(a[i]>=b[j] && b[j]<=k)               {                   res[ind]=b[j];                   ind++;                   j++;               }               else               {                   cout << -1 << endl;                   return;               }           }           while(i!=n)           {               if(a[i]==0)               {                   res[ind]=0;                   ind++;                   i++;                   k++;               }               else{               if(a[i]>k)               {                   cout << -1 << endl;                   return;               }               res[ind]=a[i];               ind++;               i++;               }           }           while(j!=m)           {               if(b[j]==0)               {                   res[ind]=0;                   ind++;                   j++;                   k++;               }               else{               if(b[j]>k)               {                   cout << -1 << endl;                   return;               }               res[ind]=b[j];               ind++;               j++;}           }           for(auto x:res)               cout << x <<    ;           cout << endl;   }   int main()   {       int t;       cin >> t;       while(t--)       {           solve();       }   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     ;     int n;     cin >> n;     int odd = 0, even = 0;     for (int i = 0; i < n; i++) {       int val;       cin >> val;       if (val % 2)         odd++;       else         even++;     }     if (odd > even) {       cout << even + (odd - even) / 3 <<   n ;     } else       cout << odd <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct TrieNode {     TrieNode *arr[2];     TrieNode() { arr[0] = arr[1] = nullptr; }   };   void insert(TrieNode *root, int num) {     TrieNode *curr = root;     for (int i = 20; i >= 0; i--) {       if (curr->arr[(num >> i) & 1] == nullptr)         curr->arr[(num >> i) & 1] = new TrieNode();       curr = curr->arr[(num >> i) & 1];     }     return;   }   int query(TrieNode *root, int xr) {     int ans = 0;     TrieNode *curr = root;     for (int i = 20; i >= 0; i--) {       if (curr->arr[(xr >> i) & 1] == nullptr) {         ans |= (1 << i);         curr = curr->arr[((xr >> i) & 1) ^ 1];       } else {         curr = curr->arr[(xr >> i) & 1];       }     }     return ans;   }   const int N = 1 << 20 + 1;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     bool present[N];     memset(present, false, sizeof(present));     vector<int> a(n);     for (int &i : a) cin >> i, present[i] = true;     TrieNode *root = new TrieNode();     for (int i = 0; i < N; i++)       if (!present[i]) insert(root, i);     int curr_xor = 0;     while (m--) {       int x;       cin >> x;       curr_xor ^= x;       cout << query(root, curr_xor) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long bp(long long x, long long y) {     long long ans = 1;     x %= mod;     while (y) {       if (y & 1) ans = ans * x % mod;       x = x * x % mod;       y >>= 1;     }     return ans;   }   long long mod_inverse(long long x) { return bp(x, mod - 2); }   long long gcd(long long a, long long b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   long long max(long long a, long long b) {     if (a < b) swap(a, b);     return a;   }   long long min(long long a, long long b) {     if (a > b) swap(a, b);     return a;   }   long long countSetBits(long long n) {     long long count = 0;     while (n) {       count += n & 1;       n >>= 1;     }     return count;   }   void solve() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long a[n], b[n];       for (long long i = 0; i < n; i++) cin >> a[i];       for (long long i = 0; i < n; i++) cin >> b[i];       if (n % 2 == 1 && a[n / 2] != b[n / 2]) {         cout <<  No  << endl;         continue;       }       map<pair<long long, long long>, long long> m;       for (long long i = 0; i < n / 2; i++) {         m[make_pair(min(a[i], a[n - 1 - i]), max(a[i], a[n - 1 - i]))]++;       }       long long flag = 0;       for (long long i = 0; i < n / 2; i++) {         pair<long long, long long> p = {min(b[i], b[n - 1 - i]),                                         max(b[i], b[n - 1 - i])};         if (m[p] <= 0) {           flag = 1;           break;         }         m[p]--;       }       if (flag == 1)         cout <<  No  << endl;       else         cout <<  yes  << endl;     }   }   signed main() { solve(); }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int x, long long int y, long long int p) {     long long 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;   }   long long int modInverse(long long int n, long long int p) {     return power(n, p - 2, p) % p;   }   void solve() {     long long int n;     cin >> n;     long long int a[n];     for (long long int i = 0; i < n; i++) cin >> a[i];     string s =   , s1 =   , s2 =   ;     for (long long int i = 0; i < 200; i++) {       s +=  a ;       s1 +=  b ;       s2 +=  a ;     }     cout << s <<   n ;     for (long long int i = 0; i < n; i++) {       if (s[a[i]] ==  a ) {         s = s.substr(0, a[i]) + s1.substr(0, 200 - a[i]);       } else {         s = s.substr(0, a[i]) + s2.substr(0, 200 - a[i]);       }       cout << s <<   n ;     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s[8] = { vaporeon ,  jolteon ,  flareon ,  espeon ,                   umbreon ,   leafeon ,  glaceon ,  sylveon };   int f[8] = {0};   int main() {     string x;     int n, k;     scanf( %d , &n);     cin >> x;     for (int i = 0; i < 8; i++) {       if (s[i].size() != n) {         f[i] = -1;       } else {         f[i] = 1;         for (int j = 0; j < n; j++) {           if (s[i][j] == x[j]) {             f[i]++;           } else if (s[i][j] != x[j] && x[j] !=  . ) {             f[i] = -1;             break;           }         }       }     }     for (int i = 0; i < 8; i++) {       if (f[i] > -1) {         k = i;       }     }     cout << s[k];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const double eps = 1e-9;   const int inf = 2000000000;   const long long infLL = 9000000000000000000;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     string second;     cin >> second;     int c = 0, d = 0;     for (auto u : second) {       if (u ==  n )         c++;       else if (u ==  z )         d++;     }     while (c--) cout << 1 <<    ;     while (d--) cout << 0 <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int t = 1;     while (t--) {       long long int n, k;       cin >> n >> k;       long long int ans = -1;       for (long long int i = 1;; i++) {         long long int p = n + ((-1) * (i)*k);         if (p < i) break;         long long int c = 0;         while (p > 0) {           if (p % 2 == 1) c++;           p /= 2;         }         if (c <= i) {           ans = i;           break;         }       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   #pragma gcc optimize(O3)   using namespace std;   long long INF = static_cast<long long>(2e18);   long long inf = static_cast<long long>(1e9 + 7);   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   vector<vector<set<long long> > > dp;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, k;     cin >> n >> k;     vector<long long> vals(n);     dp.resize(k, vector<set<long long> >(n));     for (auto& it : vals) cin >> it;     for (long long i = n - 2; i >= 0; --i) vals[i] += vals[i + 1];     for (long long i = n - 1; i >= 0; --i) dp[0][i].insert(vals[i]);     if (k == 1) {       cout << vals[0];       return 0;     }     long long res = 0;     for (long long i = 1; i < k; i++) {       for (long long j = n - 1 - i; j >= k - i - 1; --j) {         for (long long q = j + 1; q < n - i + 1; ++q) {           for (auto& it : dp[i - 1][q]) {             if (i == (k - 1) && (!j)) {               res = max(res, ((vals[j] - vals[q]) & it));             } else               dp[i][j].insert((vals[j] - vals[q]) & it);           }         }       }     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> vis;   vector<pair<long long, long long>> v;   void dfs(long long x, long long y) {     pair<long long, long long> p = v[x];     vis[x] = 1;     if (x == y) return;     for (long long i = 0; i < v.size(); i++) {       if (vis[i]) continue;       if (p.first > v[i].first && p.first < v[i].second) {         dfs(i, y);       } else if (p.second > v[i].first && p.second < v[i].second) {         dfs(i, y);       }     }   }   signed main() {     ios::sync_with_stdio(0);     long long n, m, b, c;     while (cin >> n) {       v.clear();       long long mp[105][105];       for (long long i = 0; i < n; i++) {         cin >> m >> b >> c;         if (m == 2) {           vis.assign(100, 0);           dfs(b - 1, c - 1);           if (vis[c - 1]) {             cout <<  YES n ;           } else {             cout <<  NO n ;           }         }         if (m == 1) {           v.push_back(make_pair(b, c));         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000000 + 10;   const int mod = 1e9 + 7;   int n, k, a[maxn], f[maxn], g[maxn];   int fast_pow(int a, int b) {     int ret = 1;     for (; b; b >>= 1, a = 1ll * a * a % mod)       if (b & 1) ret = 1ll * ret * a % mod;     return ret;   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= min(k + 2, n); i++)       a[i] = (a[i - 1] + fast_pow(i, k)) % mod;     if (n <= k + 2) {       printf( %d n , a[n]);       return 0;     }     int now, ans = 0;     now = f[0] = g[0] = 1;     for (int i = 1; i <= k + 2; i++) {       now = 1ll * now * (n - i) % mod;       f[i] = 1ll * f[i - 1] * i % mod;       g[i] = 1ll * -g[i - 1] * i % mod;     }     for (int i = 1; i <= k + 2; i++)       ans = (ans + 1ll * a[i] * now % mod * fast_pow(n - i, mod - 2) % mod *                        fast_pow(1ll * f[i - 1] * g[k + 2 - i] % mod, mod - 2) %                        mod) %             mod;     ans = (ans + mod) % mod;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long bigmod(long long a, long long p) {     long long ret = 1;     while (p > 0) {       if ((p & 1)) ret = (ret * a) % 998244353LL;       p >>= 1;       a = (a * a) % 998244353LL;     }     return ret;   }   long long modinverse(long long a) { return bigmod(a, 998244353LL - 2); }   long long n, fre[300009], eng[300009], mat[300009];   vector<int> graph[300009];   void dfs(int u, int par) {     fre[u] = eng[u] = mat[u] = 0;     long long mul = 1, mul2 = 1;     for (int i = 0; i < graph[u].size(); i++) {       int v = graph[u][i];       if (v == par) continue;       dfs(v, u);       mul *= (fre[v] + eng[v]);       mul2 *= (fre[v] + 2 * eng[v]);       mul %= 998244353LL;       mul2 %= 998244353LL;     }     fre[u] = mul;     mat[u] = mul2;     for (int i = 0; i < graph[u].size(); i++) {       int v = graph[u][i];       if (v == par) continue;       eng[u] += (modinverse((fre[v] + 2 * eng[v]) % 998244353LL) * mat[v]) %                 998244353LL;     }     eng[u] %= 998244353LL;     eng[u] *= mul2;     eng[u] %= 998244353LL;   }   int main() {     scanf( %lld , &n);     int u, v;     for (int i = 1; i < n; i++) {       scanf( %d %d , &u, &v);       graph[u].push_back(v);       graph[v].push_back(u);     }     dfs(1, -1);     long long ans = (fre[1] + eng[1]) % 998244353LL;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> m >> n;     char a[n][m];     int i, j, c;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         cin >> a[i][j];       }     }     char b[m][n];     for (i = 0; i < m; i++) {       for (j = 0; j < n; j++) {         b[i][j] = a[j][i];       }     }     for (i = 0; i < m; i++) {       c = 2;       while (c--) {         for (j = 0; j < n; j++) {           cout << b[i][j] << b[i][j];         }         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int cnt = 0, cur = 0;     do {       cur++;     } while (cur * 5 < n);     cnt = cur;     cur = 0;     do {       cur++;     } while (cur * 4 < n);     cnt = max(cnt, cur);     for (int i = 0; i < cnt; i++) cout << 5;     cout << 1;     cout << endl;     for (int i = 0; i < cnt; i++) cout << 4;     cout << 9;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100000 + 5, inf = 1e9 + 7;   int n, m, x, y, l, r, f[N];   struct tt {     int l, r;   } a[100];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &x, &y);       l = max(1, x - y), r = min(m, x + y);       a[i].l = l, a[i].r = r;     }     for (int i = 1; i <= m; i++) {       f[i] = i;       for (int j = 1; j <= n; j++) {         if (a[j].l <= i && i <= a[j].r)           f[i] = min(f[i], f[i - 1]);         else if (a[j].r < i)           f[i] = min(f[i], i - a[j].r + f[max(0, a[j].l - i + a[j].r - 1)]);       }     }     printf( %d n , f[m]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   const int N = 300005;   vector<pair<int, int>> g[N];   int pre[N], vis[N], sz[N];   long long d[N];   void dfs1(int u, int fa) {     pre[u] = fa;     for (auto [v, w] : g[u]) {       if (v != fa) {         d[v] = d[u] + w;         dfs1(v, u);       }     }   }   long long dfs2(int u) {     long long ret = 0;     sz[u] = 1;     for (auto [v, w] : g[u]) {       if (!vis[v]) {         vis[v] = true;         ret = max(ret, dfs2(v) + w);         sz[u] += sz[v];       }     }     return ret;   }   int main(int argc, char *argv[]) {     std::ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     for (int i = 0; i < n - 1; i++) {       int u, v, w;       cin >> u >> v >> w;       g[u].emplace_back(v, w);       g[v].emplace_back(u, w);     }     dfs1(1, 0);     vector<int> path;     for (int i = n; i; i = pre[i]) path.push_back(i), vis[i] = 1;     reverse(path.begin(), path.end());     long long mx = -inf, now = dfs2(path[0]), now2 = -inf;     for (int i = 1; i < path.size(); i++) {       long long x = dfs2(path[i]);       if (sz[path[i]] > 2) x = inf;       if (now == 0 && x == 0) {         if (i > 1) {           mx = max(mx, now2 + x - (d[path[i]] - d[path[i - 1]]));         }       } else {         mx = max(mx, now + x - (d[path[i]] - d[path[i - 1]]));       }       now = now - (d[path[i]] - d[path[i - 1]]);       now2 = now;       now = max(now, x);     }     while (m--) {       long long x;       cin >> x;       if (x + mx >= 0)         cout << d[n] << endl;       else         cout << d[n] + x + mx << endl;     }     return 0;   }


//doing a 800 difficulty question using dynammic programming   #include<bits/stdc++.h>   #define ll long long   using namespace std;   int main(){       int t;       cin>>t;       while(t--){           ll n,m,k;           cin>>n>>m>>k;           ll dp[n][m];           for(ll i=0;i<n;i++){               for(ll j=0;j<m;j++){                   if(i==0){                       dp[i][j]=j;                   }                   if(i!=0){                       dp[i][j]=dp[i-1][j]+(j+1);                   }}}                   if(dp[n-1][m-1]==k){                       cout<< YES <<  n ;                   }                   else{                       cout<< NO <<  n ;                   }           }}


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> c;   vector<bool> used;   vector<vector<int> > e;   vector<vector<int> > ices;   int colors = 1;   int cur = 1;   int used_colors[1000000];   void dfs(int v) {     if (used[v]) return;     used[v] = 1;     if (ices[v].size() > colors) {       colors = ices[v].size();     }     cur++;     for (int j = 0; j < ices[v].size(); j++) {       int t = ices[v][j];       if (c[t]) {         used_colors[c[t]] = cur;       }     }     int cur_unused = 1;     for (int j = 0; j < ices[v].size(); j++) {       int t = ices[v][j];       if (!c[t]) {         while (used_colors[cur_unused] == cur) cur_unused++;         c[t] = cur_unused++;       }     }     for (int i = 0; i < e[v].size(); i++) {       dfs(e[v][i]);     }   }   int main() {     for (int i = 0; i < 1e6; i++) {       used_colors[i] = 0;     }     ios_base::sync_with_stdio(0);     cin >> n >> m;     c.resize(m + 1);     e.resize(n);     used.assign(n, 0);     ices.resize(n);     int cnt;     for (int i = 0; i < n; i++) {       cin >> cnt;       if (cnt == 0) continue;       ices[i].resize(cnt);       for (int j = 0; j < cnt; j++) {         cin >> ices[i][j];       }     }     for (int i = 0; i < n - 1; i++) {       int v, u;       cin >> v >> u;       v--, u--;       e[v].push_back(u);       e[u].push_back(v);     }     dfs(0);     cout << colors <<   n ;     for (int i = 0; i < m; i++) {       cout << max(1, c[i + 1]) <<    ;     }     cout <<   n ;   }


#include <bits/stdc++.h>   namespace my_std {   using namespace std;   inline int read() {     char c = getchar();     int ans = 0, f = 1;     while (c >  9  || c <  0 ) {       f ^= (c ==  - );       c = getchar();     }     for (; c <=  9  && c >=  0 ; c = getchar())       ans = (ans << 1) + (ans << 3) + (c ^ 48);     return f ? ans : -ans;   }   const int mod = 1e9 + 7, N = 5010;   inline void inc(int &x, const int &y) {     x += y;     if (x >= mod) x -= mod;   }   inline int ksm(int x, long long y) {     int res = 1;     for (; y; y >>= 1, x = 1ll * x * x % mod)       if (y & 1) res = 1ll * res * x % mod;     return res;   }   inline int gcd(int x, int y) {     if (x > y) swap(y, x);     return y ? gcd(y, x % y) : x;   }   }  // namespace my_std   using namespace my_std;   vector<int> e[N << 1];   int n, m, d, lv[N], ans[N], wt[N << 1], vis[N << 1];   struct People_CF1139E {     int pot, cl, lf;   } st[N];   inline bool find(int u) {     register int v;     for (register int i = (0); i <= (int(e[u].size()) - 1); ++i) {       v = e[u][i];       if (vis[v]) continue;       vis[v] = 1;       if (wt[v] == -1 || find(wt[v])) {         wt[v] = u;         return 1;       }     }     return 0;   }   int main() {     n = read(), m = read();     for (register int i = (1); i <= (n); ++i) st[i].pot = read();     for (register int i = (1); i <= (n); ++i) st[i].cl = read();     d = read();     for (register int i = (1); i <= (d); ++i) lv[i] = read(), st[lv[i]].lf = 1;     for (register int i = (1); i <= (n); ++i) {       if (!st[i].lf && st[i].pot <= m) {         e[st[i].pot].push_back(st[i].cl + m);         e[st[i].cl + m].push_back(st[i].pot);       }     }     memset(wt, -1, sizeof(wt));     for (register int i = (d); i >= (1); --i) {       for (register int j = (ans[i + 1]); j <= (m); ++j) {         memset(vis, 0, sizeof(vis));         if (!find(j)) {           ans[i] = j;           break;         }       }       if (st[lv[i]].pot > m) continue;       e[st[lv[i]].pot].push_back(st[lv[i]].cl + m);       e[st[lv[i]].cl + m].push_back(st[lv[i]].pot);     }     for (register int i = (1); i <= (d); ++i) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct query {     int l, r, id, rng;     bool operator<(const query &tmp) const {       return rng != tmp.rng ? rng < tmp.rng : r < tmp.r;     }   } Q[100100];   int n, q, a[100100], b[100100], c[100100], cnt[100100], ans[100100];   int D;   vector<int> v;   void add(int x) { c[cnt[x]++]--, c[cnt[x]]++; }   void del(int x) { c[cnt[x]--]--, c[cnt[x]]++; }   int calc() {     int rlt = 0;     for (int i = 1; i <= D; i++) b[i] = c[i];     priority_queue<int> pq;     for (int i = 0; i < v.size(); i++)       if (cnt[v[i]] > D) pq.push(-cnt[v[i]]);     for (int i = 1, j = 2; i <= D; i++) {       rlt += b[i] / 2 * (2 * i);       if (i * 2 <= D)         b[i * 2] += b[i] / 2;       else {         for (int k = 1; k <= b[i] / 2; k++) pq.push(-i * 2);       }       if (b[i] & 1) {         if (j <= i) j = i + 1;         while (j <= D && !b[j]) j++;         if (j > D) {           pq.push(-i);           break;         }         rlt += i + j;         b[j]--;         if (i + j <= D)           b[i + j]++;         else           pq.push(-(i + j));       }     }     while (!pq.empty()) {       int x = pq.top();       pq.pop();       if (pq.empty()) break;       int y = pq.top();       pq.pop();       rlt -= x + y;       pq.push(x + y);     }     return rlt;   }   int main() {     scanf( %d , &n);     D = 2 * sqrt(n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), cnt[a[i]]++;     for (int i = 1; i <= 100000; i++) {       if (cnt[i] > D) v.push_back(i);       cnt[i] = 0;     }     scanf( %d , &q);     for (int i = 1; i <= q; i++)       scanf( %d %d , &Q[i].l, &Q[i].r), Q[i].id = i, Q[i].rng = Q[i].l / D;     sort(Q + 1, Q + q + 1);     int l = 1, r = 0;     for (int i = 1; i <= q; i++) {       while (r < Q[i].r) add(a[++r]);       while (l < Q[i].l) del(a[l++]);       while (r > Q[i].r) del(a[r--]);       while (l > Q[i].l) add(a[--l]);       ans[Q[i].id] = calc();     }     for (int i = 1; i <= q; i++) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Graph {     struct Edge {       int u, v;       int cost;       Edge(int _u, int _v, int _cost) : u(_u), v(_v), cost(_cost) {}     };     int n, m;     bool is_digraph;     vector<vector<int>> g;     vector<Edge> e;     Graph(int _n) : n(_n), m(0) {       assert(n >= 1);       g.resize(n);       set_di(false);     }     Graph(int _n, int _m, bool _di = false) : n(_n) {       assert(n >= 1);       g.resize(n);       e.reserve(_m);       m = 0;       set_di(_di);       input(_m);     }     void set_di(bool _di) {       pos = vector<int>(n, 0);       deg = vector<int>(n, 0);       is_digraph = _di;     }     vector<int> deg;     inline void add(int u, int v, int cost = 1) {       assert(0 <= u && u < n);       assert(0 <= v && v < n);       if (is_digraph) {         g[u].emplace_back(m);       } else {         deg[u]++;         deg[v]++;         g[u].emplace_back(m);         g[v].emplace_back(m);       }       e.emplace_back(u, v, cost);       m++;     }     void input(int _m) {       int u, v;       for (int i = 0; i < _m; i++) {         cin >> u >> v;         u--;         v--;         add(u, v);       }     }     vector<int> pos;     void dfs(int u) {       for (; pos[u] < g[u].size(); pos[u]++) {         int i = g[u][pos[u]];         int v = e[i].u ^ e[i].v ^ u;         dfs(v);       }     }     int k;     void dele() {       int need_del = m - (n + m + 1) / 2;       if (need_del > 0) {         int cnt = 0;         random_shuffle(e.begin(), e.end());         vector<int> d = deg;         for (auto& x : e) {           if (cnt < need_del && d[x.u] - 1 >= (deg[x.u] + 1) / 2 &&               d[x.v] - 1 >= (deg[x.v] + 1) / 2) {             d[x.u]--;             d[x.v]--;             x.cost = 0;             cnt++;           }         }         assert(cnt == need_del);         k = (n + m + 1) / 2;       } else {         k = m;       }     }     void pri() {       cout << k <<   n ;       for (auto& x : e) {         if (x.cost) cout << x.u + 1 <<     << x.v + 1 <<   n ;       }     }   };   void solve() {     int n, m;     cin >> n >> m;     Graph g(n, m);     g.dele();     g.pri();   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     cout << endl;   }


#include<bits/stdc++.h>   using namespace std;   #define N 1500009   #define INF 5e8   #define mymin(x,y) (x>=y?y:x)   #define mymax(x,y) (x>=y?x:y)   typedef long long int LL;   map<LL, int> mp[3];   int a[4][N];   struct din{       int ap, id;   }dn[4][N];   bool cmp(din af, din bf){       return af.ap < bf.ap;   }   int main() {    std::ios::sync_with_stdio(0); std::cin.tie(0);       int n[4];       for(int i = 0; i < 4; i++) cin >> n[i];       for(int i = 0; i < 4; i++){           for(int j = 0; j < n[i]; j++){               cin >> dn[i][j].ap;               dn[i][j].id = j + 1;           }       }       for(int i = 0; i < 3; i++){           int m; cin >> m;           for(int j = 0; j < m; j++){               int x, y; cin >> x >> y;               mp[i][1ll * x * N + y] = 1;           }       }       for(int i = 2; i >= 0; i--){           // cout << i <<     << n[i] << endl;           // cout << dn[3][0].id <<     << mp[2][0 * N + 1] << endl;           sort(dn[i + 1], dn[i + 1] + n[i + 1], cmp);           for(int j = 0; j < n[i]; j++){               int ind = 0;               while(ind < n[i + 1] && mp[i][1ll * (j + 1) * N + dn[i + 1][ind].id]) ind++;               if(ind == n[i + 1]) dn[i][j].ap = INF;               else dn[i][j].ap += dn[i + 1][ind].ap;               // cout << dn[i][j].ap <<    ;           }           // cout << endl;       }       sort(dn[0], dn[0] + n[0], cmp);       if(dn[0][0].ap >= INF) cout << -1 << endl;       else cout << dn[0][0].ap << endl;    return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long arr1[100][10000], arr[10000];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t, i, j, k, n, m, x, y, z, a, b, mx;     cin >> t;     while (t--) {       cin >> n;       for (i = 0; i < n; i++) {         cin >> arr[i];       }       for (i = 1; i < 27; i++) {         x = 0;         for (j = 0; j < n; j++) {           if (arr[j] == i) {             x++;             arr1[i][j] = x;           } else {             arr1[i][j] = x;           }         }       }       mx = 1;       for (i = 0; i < n; i++) {         for (j = i + 1; j < n; j++) {           if (arr[j] == arr[i] &&               (arr1[arr[i]][i]) == (arr1[arr[i]][n - 1] - arr1[arr[i]][j] + 1)) {             x = arr1[arr[i]][i] + arr1[arr[i]][n - 1] - arr1[arr[i]][j] + 1;             for (k = 1; k <= 26; k++) {               y = arr1[k][j - 1] - arr1[k][i];               z = x + y;               mx = max(z, mx);             }           }         }       }       cout << mx << endl;     }   }


#include <bits/stdc++.h>   long long int mod = 1000000000 + 7;   long long int inf = 1000000000000000000;   using namespace std;   int main() {     iostream::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int ans = 1, a;       cin >> a;       for (int i = 0; i < 31; i++) {         if ((a >> i) & 1) ans *= 2;       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5002, NP = 1e9;   int Add[MAXN], MyResult[MAXN], MyCheck[MAXN];   bool check(int n, vector<pair<int, pair<int, pair<int, int> > > > A) {     for (int i = 0; i < A.size(); i++) {       int t = A[i].first, s = A[i].second.first, e = A[i].second.second.first,           v = A[i].second.second.second;       if (t == 1) {         for (int i = s - 1; i <= e - 1; i++) {           MyCheck[i] += v;         }       } else {         int mx = MyCheck[s - 1];         for (int i = s - 1; i <= e - 1; i++) mx = max(mx, MyCheck[i]);         if (mx != v) return 0;       }     }     return 1;   }   int main() {     int t, n, m, s, e, v;     vector<pair<int, pair<int, pair<int, int> > > > A;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) MyCheck[i] = MyResult[i] = NP;     while (m--) {       scanf( %d%d%d%d , &t, &s, &e, &v);       A.push_back(make_pair(t, make_pair(s, make_pair(e, v))));       if (t == 1) {         for (int i = s - 1; i <= e - 1; i++) Add[i] += v;       } else {         for (int i = s - 1; i <= e - 1; i++)           MyResult[i] = min(MyResult[i], v - Add[i]);       }     }     for (int i = 0; i < n; i++) MyCheck[i] = MyResult[i];     if (check(n, A)) {       printf( YES n );       for (int i = 0; i < n; i++) {         if (i) printf(   );         printf( %d , MyResult[i]);       }       printf(  n );     } else       printf( NO n );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     for (; t; t--) {       int n;       cin >> n;       vector<int> a(n);       for (int i = 0; i < n; i++) cin >> a[i];       vector<int> gist(3);       for (int i = 0; i < n; i++) gist[a[i] % 3]++;       while (gist[1] > 0 && gist[2] > 0) {         gist[1]--;         gist[2]--;         gist[0]++;       }       while (gist[1] - 3 >= 0) {         gist[1] -= 3;         gist[0]++;       }       while (gist[2] - 3 >= 0) {         gist[2] -= 3;         gist[0]++;       }       cout << gist[0] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 2 * acos(0.0);   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());   const string DIGITS =  0123456789 ;   const string ALPH =  abcdefghijklmnopqrstuvwxyz ;   template <class T0, class T1>   inline ostream &operator<<(ostream &out, pair<T0, T1> &a) {     return out <<  {  << a.first <<  ,   << a.second <<  } ;   }   template <class T0, class T1, class T2>   inline ostream &operator<<(ostream &out, tuple<T0, T1, T2> &a) {     return out <<  {  << get<0>(a) <<  ,   << get<1>(a) <<  ,   << get<2>(a)                <<  } ;   }   template <class T0, class T1, class T2, class T3>   inline ostream &operator<<(ostream &out, tuple<T0, T1, T2, T3> &a) {     return out <<  {  << get<0>(a) <<  ,   << get<1>(a) <<  ,   << get<2>(a)                <<  ,   << get<3>(a) <<  } ;   }   template <class T>   inline ostream &operator<<(ostream &out, vector<T> &a) {     out <<  [ ;     for (int i = 0; i < (int)(a.size()); ++i)       out << a[i] << vector<string>{ ,  ,  ]   }[i + 1 == a.size()];     return out;   }   void smain();   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << setprecision(10) << fixed;     smain();     return 0;   }   const int N = 510;   int n, m;   vector<string> t;   vector<vector<int> > glav[4];   void kek(char p, int u) {     vector<vector<int> > a(n, vector<int>(m));     auto b = a, c = a;     for (int i = 0; i < n; i++) {       int u = 0;       string s = t[i];       for (int j = 0; j < m; j++) {         if (s[j] == p) {           a[i][j] = 1;           u++;         } else {           a[i][j] = 0;           u = 0;         }         b[i][j] = u;       }     }     for (int i = 0; i < m; i++) {       int u = 0;       for (int j = n - 1; j >= 0; j--) {         if (a[j][i] == 1)           u++;         else           u = 0;         c[j][i] = u;       }     }     vector<vector<int> > ans(n, vector<int>(m));     for (int i = n - 1; i >= 0; i--) {       for (int j = 0; j < m; j++) {         if (a[i][j] == 0) continue;         if (j == 0 || i == n - 1) {           ans[i][j] = 1;         } else {           int v = min(b[i][j], c[i][j]);           ans[i][j] = min(ans[i + 1][j - 1] + 1, v);         }       }     }     glav[u] = ans;   }   int flex[N][N];   int lol[N][N][251];   int get(int r, int c, int k) {     if (r < 0 || c < 0) return 0;     return lol[r][c][k];   }   int get(int r1, int c1, int r2, int c2, int k) {     return get(r2, c2, k) - get(r1 - 1, c2, k) - get(r2, c1 - 1, k) +            get(r1 - 1, c1 - 1, k);   }   void smain() {     int q;     cin >> n >> m >> q;     string s;     for (int i = 0; i < n; i++) {       cin >> s;       t.push_back(s);     }     kek( G , 0);     kek( R , 1);     kek( B , 2);     kek( Y , 3);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         for (int k = 1;; k++) {           if (i + k >= n || j - k < 0) break;           if (glav[0][i][j] >= k && glav[1][i][j - k] >= k &&               glav[2][i + k][j] >= k && glav[3][i + k][j - k] >= k) {             flex[i][j] = k;           }         }       }     }     for (int k = 1; k <= 250; k++) {       for (int i = 0; i < n; i++) {         int prev = 0;         for (int j = 0; j < m; j++) {           prev += (flex[i][j] == k);           if (i) {             lol[i][j][k] += lol[i - 1][j][k];           }           lol[i][j][k] += prev;         }       }     }     while (q--) {       int r1, c1, r2, c2;       cin >> r1 >> c1 >> r2 >> c2;       r1--;       c1--;       r2--;       c2--;       swap(c1, c2);       int l = 0, r = 251;       while (l + 1 < r) {         int mid = l + r >> 1;         int r3 = r2 - mid * 2 + 1;         int c3 = c2 + mid * 2 - 1;         bool flag = true;         if (r3 < r1 || c3 > c1) flag = false;         if (flag) {           if (get(r1, c3, r3, c1, mid) == 0) flag = false;         }         if (flag)           l = mid;         else           r = mid;       }       cout << 1LL * l * 2 * l * 2 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1000000000;   long long mod = 1000000007LL;   long long mod2 = 998244353LL;   int n;   bool mat[2005][2005];   int cntr[2005], cntc[2005];   int cnt[2005];   int main() {     cin >> n;     memset(mat, false, sizeof(mat));     memset(cntr, 0, sizeof(cntr));     memset(cntc, 0, sizeof(cntc));     memset(cnt, 0, sizeof(cnt));     for (int i = 1; i <= n; ++i) {       string s;       cin >> s;       for (int j = 1; j <= n; ++j) {         mat[i][j] = (s[j - 1] ==  1 );       }     }     int ans = 0;     for (int i = 1; i <= n; ++i) {       for (int j = n; j >= i; --j) {         if (j == i) continue;         bool x = ((cntr[i] + cntc[j]) % 2 > 0);         if (mat[i][j] != x) {           ans++;           cntr[i]++;           cntc[j]++;         }       }     }     for (int i = 1; i <= n; ++i) {       cnt[i] += cntr[i] + cntc[i];     }     memset(cntr, 0, sizeof(cntr));     memset(cntc, 0, sizeof(cntc));     for (int i = n; i >= 1; --i) {       for (int j = 1; j <= i; ++j) {         if (j == i) continue;         bool x = ((cntr[i] + cntc[j]) % 2 > 0);         if (mat[i][j] != x) {           ans++;           cntr[i]++;           cntc[j]++;         }       }     }     for (int i = 1; i <= n; ++i) {       cnt[i] += cntr[i] + cntc[i];     }     for (int i = 1; i <= n; ++i) {       bool x = (cnt[i] % 2 > 0);       if (mat[i][i] != x) {         ans++;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename _T>   inline void _DBG(const char *s, _T x) {     cerr << s <<   =   << x <<   n ;   }   template <typename _T, typename... args>   void _DBG(const char *s, _T x, args... a) {     while (*s !=  , ) cerr << *s++;     cerr <<   =   << x <<  , ;     _DBG(s + 1, a...);   }   const int N = 1e5 + 7;   vector<int> G[N];   int dist[N];   bool vis[N];   void dfs(int v, int d) {     vis[v] = true;     dist[v] = d;     for (auto &u : G[v]) {       if (!vis[u]) {         dfs(u, d + 1);       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       G[u].push_back(v);       G[v].push_back(u);     }     int root = -1;     for (int i = 1; i <= n; i++) {       if ((int)(G[i]).size() == 1) {         root = i;         break;       }     }     dfs(root, 0);     int parity = dist[root] % 2;     bool good = true;     for (int i = 2; i <= n; i++) {       if ((int)(G[i]).size() == 1 && dist[i] % 2 != parity) {         good = false;       }     }     if (good) {       cout << 1 <<    ;     } else {       cout << 3 <<    ;     }     int edges = n - 1;     int leaves = 0;     set<int> leaf_parents;     for (int i = 1; i <= n; i++) {       if ((int)(G[i]).size() == 1) {         leaves++;       } else {         for (auto &u : G[i]) {           if ((int)(G[u]).size() == 1) {             leaf_parents.insert(i);           }         }       }     }     cout << edges - leaves + (int)(leaf_parents).size() <<   n ;     return 0;   }


#include <bits/stdc++.h>   int N, Q;   int a[300005];   int p[300005];   int oop[1100005];   int ui, uv;   void update(int n, int nl, int nr) {     if (nl == ui && ui + 1 == nr) {       oop[n] = uv;     } else {       int mid = (nl + nr) / 2;       if (ui < mid)         update(n * 2 + 1, nl, mid);       else         update(n * 2 + 2, mid, nr);       oop[n] = oop[n * 2 + 1] + oop[n * 2 + 2];     }   }   int ql, qr;   int query(int n, int nl, int nr) {     if (qr <= nl || nr <= ql)       return 0;     else if (ql <= nl && nr <= qr)       return oop[n];     else {       int mid = (nl + nr) / 2;       return query(n * 2 + 1, nl, mid) + query(n * 2 + 2, mid, nr);     }   }   int main() {     scanf( %d , &N);     a[0] = p[0] = 0;     for (int i = 1; i <= N; i++) {       scanf( %d , &a[i]);       p[a[i]] = i;     }     a[N + 1] = p[N + 1] = N + 1;     for (int i = 1; i < N; i++) {       ui = i;       uv = p[i] > p[i + 1];       update(0, 0, N + 2);     }     scanf( %d , &Q);     for (int i = 0; i < Q; i++) {       int t, x, y;       scanf( %d%d%d , &t, &x, &y);       if (t == 1) {         ql = x, qr = y;         printf( %d n , query(0, 0, N + 2) + 1);       } else {         std::swap(a[x], a[y]);         p[a[x]] = x;         p[a[y]] = y;         ui = a[x] - 1;         uv = p[a[x] - 1] > p[a[x]];         update(0, 0, N + 2);         ui = a[x];         uv = p[a[x]] > p[a[x] + 1];         update(0, 0, N + 2);         ui = a[y] - 1;         uv = p[a[y] - 1] > p[a[y]];         update(0, 0, N + 2);         ui = a[y];         uv = p[a[y]] > p[a[y] + 1];         update(0, 0, N + 2);       }     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<int, int>;   constexpr int MAXN = 5 + 50;   constexpr ll INF = 1000000000000000002LL;   namespace dsu {   int f[MAXN], sz[MAXN];   void build(int n) {     fill(sz, sz + n, 1);     for (int i = (int)0; i < (int)n; ++i) f[i] = i;   }   int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }   bool join(int x, int y) {     if ((x = find(x)) == (y = find(y))) return false;     if (sz[x] < sz[y]) swap(x, y);     sz[x] += sz[y];     f[y] = x;     return true;   }   bool connected(int i, int j) { return find(i) == find(j); }   }  // namespace dsu   ll memo[MAXN], f[MAXN];   int res[MAXN];   bitset<MAXN> used;   ll add(ll a, ll b) {     if (a + b >= INF) return INF;     return a + b;   }   ll mul(ll a, ll b) {     long double ans = (long double)(a) * (long double)(b);     if (ans >= INF) return INF;     return a * b;   }   ll dp(int len) {     ll& ans = memo[len];     if (~ans) {       assert(ans >= 0);       return ans;     }     if (len == 0) return ans = 1;     ans = 0;     for (int i = 1; i <= len; ++i)       ans = add(ans, mul(dp(len - i), f[max(0, i - 2)]));     return ans;   }   void rebuild(int len, ll k, int pos, int n) {     if (len == 0) {       assert(pos == n);       return;     }     ll ans = 0;     for (int i = 1; i <= len; ++i) {       ll ol = ans;       ans = add(ans, mul(dp(len - i), f[max(0, i - 2)]));       if (k <= ans) {         k -= ol;         ll j = k / dp(len - i);         while (mul(j, dp(len - i)) < k) ++j;         k -= mul(j - 1, dp(len - i));         res[pos] = i + pos;         dsu::build(MAXN);         used.reset();         for (int posin = 2; posin <= i; ++posin) {           int put = -1;           ll ac = 0, olac;           for (int num = 1; num < i; ++num) {             if (dsu::connected(num, posin) || used[num]) continue;             olac = ac;             ac = add(ac, f[max(0, i - posin - 1)]);             if (j <= ac) {               put = num;               break;             }           }           assert(put != -1);           res[pos + posin - 1] = put + pos;           used[put] = true;           dsu::join(put, posin);           j -= olac;         }         rebuild(len - i, k, i + pos, n);         return;       }     }     assert(false);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     f[0] = 1;     for (int i = (int)1; i < (int)MAXN; ++i) {       if (f[i - 1] == INF) {         f[i] = f[i - 1];       } else {         f[i] = min(INF, 1LL * i * f[i - 1]);       }     }     memset(memo, -1, sizeof memo);     int tc;     cin >> tc;     while (tc--) {       int n;       ll k;       cin >> n >> k;       if (k <= dp(n)) {         rebuild(n, k, 0, n);         for (int i = (int)0; i < (int)n; ++i) cout << res[i] <<    ;       } else {         cout << -1;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   vector<int> a[100005];   int dp[100005], n, t;   int main() {     for (int i = 2; i <= 100000; i++)       for (int j = 1; j * i <= 100000; j++) a[i * j].push_back(i);     while (cin >> n) {       memset(dp, 0, sizeof(dp));       for (int i = 0; i < n; i++) {         cin >> t;         int mx = 0;         for (int j = 0; j < a[t].size(); j++) {           mx = max(mx, dp[a[t][j]]);         }         for (int j = 0; j < a[t].size(); j++) {           dp[a[t][j]] = mx + 1;         }       }       cout << max(1, *max_element(dp, dp + 100001)) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n1, n2, k1, k2;     cin >> n1 >> n2 >> k1 >> k2;     if (n1 <= n2)       cout <<  Second ;     else       cout <<  First ;   }


#include <bits/stdc++.h>   using namespace std;   int n, sum, cnt[10];   bool check;   void ghi() {     bool check = false;     for (int i = 9; i > -1; i--) {       if (cnt[i] == 0) continue;       if (i != 0) check = true;       if (!i && !check) cnt[i] = 1;       for (int j = 1; j <= cnt[i]; j++) printf( %d , i);     }     printf(  n );   }   int main() {     if (0) {       freopen( a.inp ,  r , stdin);     };     scanf( %d , &n);     int x;     for (int i = 0; i < n; i++) {       scanf( %d , &x);       cnt[x]++;       sum += x;       if (x == 0) check = true;     }     if (!check) {       printf( -1 n );       return 0;     }     if (sum % 3 == 1) {       for (int i = 0; i < 10; i++) {         if (i % 3 != 1 || cnt[i] == 0) continue;         cnt[i]--;         ghi();         return 0;       }       for (int i = 0; i < 10; i++) {         if (i % 3 != 2 || cnt[i] == 0) continue;         cnt[i]--;         for (int j = i; j < 10; j++) {           if (j % 3 != 2 || cnt[j] == 0) continue;           cnt[j]--;           ghi();           return 0;         }       }     } else if (sum % 3 == 2) {       for (int i = 0; i < 10; i++) {         if (i % 3 != 2 || cnt[i] == 0) continue;         cnt[i]--;         ghi();         return 0;       }       for (int i = 0; i < 10; i++) {         if (i % 3 != 1 || cnt[i] == 0) continue;         cnt[i]--;         for (int j = i; j < 10; j++) {           if (j % 3 != 1 || cnt[j] == 0) continue;           cnt[j]--;           ghi();           return 0;         }       }     } else       ghi();   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100100;   int N, M;   int app[MAXN];   char type[MAXN];   int P[MAXN];   bool check(int leader) {     set<int> users;     users.insert(leader);     for (int i = 0; i < M; i++) {       if (type[i] ==  + )         users.insert(P[i]);       else         users.erase(P[i]);       if (!users.empty() && users.find(leader) == users.end()) return false;     }     return true;   }   int main() {     cin >> N >> M;     for (int i = 0; i < M; i++) cin >> type[i] >> P[i];     int offp = 0;     for (int i = 0; i < M; i++) {       if (type[i] ==  -  && !app[P[i]]) offp = P[i];       app[P[i]] = true;     }     if (offp != 0) {       if (check(offp)) app[offp] = false;     } else {       if (check(P[0])) app[P[0]] = false;     }     int total = 0;     for (int i = 1; i <= N; i++) total += !app[i];     cout << total <<   n ;     for (int i = 1; i <= N; i++)       if (!app[i]) cout << i <<    ;     return 0;   }


#include <bits/stdc++.h>      using namespace std;   typedef long long ll;      const int N = 1e6 + 9;      int main () {       int t;       cin >> t;       while (t--) {           ll n, last;           cin >> n;           for (ll i = 0; i < 33; i++) {               if (n & (1ll << i))                   last = i;           }           cout << ((1ll << last) - 1ll) <<   n ;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int total, n;     cin >> total >> n;     vector<int> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     int ans = 0;     for (int i = 0; i < n - 1; i++) {       ans += (total - v[i]);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> v;     int total, num, i, koita = 0;     scanf( %d , &total);     for (i = 0; i < total; i++) {       scanf( %d , &num);       v.push_back(num);     }     int maximum = v[0];     int minimum = v[0];     for (i = 1; i < total; i++) {       num = v[i];       if (num > maximum) {         maximum = num;         koita++;       }       if (num < minimum) {         minimum = num;         koita++;       }     }     printf( %d n , koita);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     char ch = getchar();     long long nega = 1;     while (!isdigit(ch)) {       if (ch ==  - ) nega = -1;       ch = getchar();     }     long long ans = 0;     while (isdigit(ch)) {       ans = ans * 10 + ch - 48;       ch = getchar();     }     if (nega == -1) return -ans;     return ans;   }   inline long long min(long long x, long long y, long long z) {     return min(x, min(y, z));   }   inline long long max(long long x, long long y, long long z) {     return max(x, max(y, z));   }   inline long long add(long long x, long long y) {     return x + y >= 998244353 ? x + y - 998244353 : x + y;   }   inline long long add(long long x, long long y, long long z) {     return add(add(x, y), z);   }   inline long long sub(long long x, long long y) {     return x - y < 0 ? x - y + 998244353 : x - y;   }   inline long long mul(long long x, long long y) {     return 1LL * x * y % 998244353;   }   inline long long mul(long long x, long long y, long long z) {     return mul(mul(x, y), z);   }   vector<long long> a, b;   vector<char> ans;   long long n;   void solve1() {     if (a[0] == b[0])       cout <<  SMALL n0 n ;     else       cout <<  IMPOSSIBLE n ;   }   bool rsame(vector<long long> x, vector<long long> y) {     reverse(x.begin(), x.end());     return x == y;   }   void fail() { cout <<  IMPOSSIBLE n , exit(0); }   bool push_back(char s) {     if ((long long)ans.size() <= 200000) {       ans.push_back(s);       return 1;     }     return 0;   }   void solve2() {     long long tot = 0, sum = 0;     while (a != b && !rsame(a, b)) {       if (b[0] > b[1]) swap(b[0], b[1]), tot++, push_back( R );       if (a[0] > a[1] && b[0] == a[1]) {         if (b[0] == 0) fail();         if (b[1] < a[0]) fail();         long long ned = b[1] - a[0];         if (ned % b[0] != 0) fail();         sum += ned / b[0], tot += ned / b[0] + 1;         if (sum <= 200000) {           for (long long i = 1; i <= ned / b[0]; i++) push_back( P );           push_back( R );         }         if (sum <= 200000) {           cout <<  SMALL n ;           reverse(ans.begin(), ans.end());           cout << (long long)ans.size() << endl;           for (auto i : ans) putchar(i);         } else {           cout <<  BIG n ;           cout << sum << endl;         }         exit(0);       }       if (b[0] == a[0]) {         if (b[0] == 0) fail();         if (b[1] < a[1]) fail();         long long ned = b[1] - a[1];         if (ned % b[0] != 0) fail();         sum += ned / b[0], tot += ned / b[0] + 1;         if (sum <= 200000) {           for (long long i = 1; i <= ned / b[0]; i++) push_back( P );           push_back( R );         }         if (sum <= 200000) {           cout <<  SMALL n ;           reverse(ans.begin(), ans.end());           cout << (long long)ans.size() << endl;           for (auto i : ans) putchar(i);         } else {           cout <<  BIG n ;           cout << sum << endl;         }         exit(0);       }       if (b[0] == 0) fail();       tot += b[1] / b[0];       sum += b[1] / b[0];       if (sum <= 200000) {         for (long long i = 1; i <= b[1] / b[0]; i++) push_back( P );       }       b[1] %= b[0];     }     if (a != b) swap(b[0], b[1]), tot++, push_back( R );     if (sum <= 200000) {       cout <<  SMALL n ;       reverse(ans.begin(), ans.end());       cout << (long long)ans.size() << endl;       for (auto i : ans) putchar(i);     } else {       cout <<  BIG n ;       cout << sum << endl;     }     exit(0);   }   bool inc(vector<long long> x) {     for (long long i = 1; i < n; i++) {       if (x[i] < x[i - 1]) return 0;     }     return 1;   }   bool dec(vector<long long> x) {     for (long long i = 1; i < n; i++) {       if (x[i] > x[i - 1]) return 0;     }     return 1;   }   bool alz(vector<long long> x) {     for (long long i = 0; i < n - 1; i++)       if (x[i] != 0) return 0;     return 1;   }   void print(vector<long long> x) {     for (long long i : x) printf( %lld  , i);     cout <<   n ;   }   void solve3() {     long long tot = 0, sum = 0;     while (a != b && !rsame(a, b)) {       if (alz(b)) fail();       if (dec(b)) reverse(b.begin(), b.end()), tot++, push_back( R );       if (!inc(b)) fail();       sum++;       tot++;       push_back( P );       for (long long i = n - 1; i > 0; i--) b[i] -= b[i - 1];     }     if (a != b) reverse(b.begin(), b.end()), tot++, push_back( R );     if (sum <= 200000) {       cout <<  SMALL n ;       cout << ans.size() << endl;       reverse(ans.begin(), ans.end());       for (auto i : ans) putchar(i);     } else {       cout <<  BIG n ;       cout << sum << endl;     }   }   signed main() {     cin >> n;     a.resize(n), b.resize(n);     for (long long i = 0; i < n; i++) a[i] = read();     for (long long i = 0; i < n; i++) b[i] = read();     if (n >= 3)       solve3();     else if (n == 2)       solve2();     else       solve1();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 9;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long s[maxn];   int f[maxn], F[maxn], p[maxn];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %lld , &s[i]);     }     for (int i = 2; i <= n; ++i) {       scanf( %d , &p[i]);     }     for (int i = n; i > 1; --i) {       s[p[i]] += s[i];     }     for (int i = n; i; --i) {       long long t = s[1] / gcd(s[1], s[i]);       if (t <= n) {         ++f[t];       }     }     for (int i = n; i; --i) {       for (int j = i; (j += i) <= n;) {         f[j] += f[i];       }     }     int ans = 0;     F[1] = 1;     for (int i = 1; i <= n; ++i) {       if (f[i] == i) {         ans += F[i];         for (int j = i * 2; j <= n; j += i) {           F[j] += F[i];         }       }     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, j, k, n, m;   int fa[200010], an[200010];   vector<int> a[200010];   pair<int, int> f[200010];   inline void P(int &x, int y) { x = 1ll * x * y % 1000000007; }   inline void merge(pair<int, int> &a, pair<int, int> b) {     P(a.first, b.first);     int g = (2ll * b.first + b.second) % 1000000007;     P(a.second, g);   }   inline void gao(pair<int, int> &a) {     a.second = (a.second - a.first) % 1000000007;   }   inline void ch(pair<int, int> &a, pair<int, int> b) {     a.first = 1ll * a.first * b.first % 1000000007;     a.second = 1ll * a.second * b.second % 1000000007;   }   void dfs(int x) {     f[x] = make_pair(1, 1);     for (auto i : a[x]) {       if (fa[x] == i) continue;       fa[i] = x;       dfs(i);       merge(f[x], f[i]);     }     gao(f[x]);   }   void huan(int x) {     an[x] = (f[x].first + f[x].second) % 1000000007;     int t = 0, i, len = a[x].size() + 5;     vector<pair<int, int> > g(len), f1(len), f2(len);     for (auto i : a[x]) g[++t] = f[i];     f1[0] = make_pair(1, 1);     for (i = 1; i <= t; i++) f1[i] = f1[i - 1], merge(f1[i], g[i]);     f2[t + 1] = make_pair(1, 1);     for (i = t; i; i--) f2[i] = f2[i + 1], merge(f2[i], g[i]);     int _ = 0;     for (auto i : a[x]) {       _++;       if (fa[x] == i) continue;       pair<int, int> v = f1[_ - 1];       ch(v, f2[_ + 1]);       gao(v);       swap(f[x], v);       pair<int, int> tmp = f[i];       f[i].second = (f[i].second + f[i].first) % 1000000007;       merge(f[i], f[x]);       gao(f[i]);       huan(i);       swap(f[x], v);       f[i] = tmp;     }   }   int main() {     scanf( %d , &n);     for (i = 1; i <= n - 1; i++) {       int x;       scanf( %d , &x);       a[x].push_back(i + 1);       a[i + 1].push_back(x);     }     dfs(1);     huan(1);     for (i = 1; i <= n; i++) printf( %d  , (an[i] + 1000000007) % 1000000007);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int ans[200005];   void query(int nl, int nr) {     if (nl > nr) return;     printf( ? %d %d n , nl, nr);     fflush(stdout);     int x, f;     scanf( %d%d , &x, &f);     if (nr - f + 1 <= nl + f - 1) {       for (int i = nr - f + 1; i <= nl + f - 1; i++) ans[i] = x;       query(nl, nr - f);       query(nl + f, nr);     } else {       query(nl, ((nl + nr) >> 1));       query(((nl + nr) >> 1) + 1, nr);     }   }   int main() {     scanf( %d , &n);     query(1, n);     printf( ! %d , ans[1]);     for (int i = 2; i <= n; i++) printf(  %d , ans[i]);     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = s.length();     for (int i = 0; i < n - 1; i++) {       if (s[i] == s[i + 1]) {         if (i + 2 < n) {           if (s[i + 1] ==  z  && s[i + 2] !=  a )             s[i + 1] =  a ;           else if (s[i + 1] ==  z  && s[i + 2] ==  a )             s[i + 1] =  b ;           else if (s[i + 1] !=  z  && s[i + 2] !=  z )             s[i + 1] =  z ;           else {             if (s[i + 1] ==  y )               s[i + 1] =  x ;             else               s[i + 1] =  y ;           }         } else {           if (s[i + 1] ==  z )             s[i + 1] =  a ;           else             s[i + 1] =  z ;         }       }     }     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   ostream& operator<<(ostream& cout, vector<T> V) {     cout <<  [  ;     for (auto v : V) cout << v <<    ;     return cout <<  ] ;   }   template <class L, class R>   ostream& operator<<(ostream& cout, pair<L, R> P) {     return cout <<  (  << P.first <<  ,  << P.second <<  ) ;   }   long long int n;   vector<long long int> a, b, c;   vector<vector<long long int>> conn;   vector<long long int> c0, c1;   long long int ans = 0;   void dfs1(long long int node, long long int par, long long int val) {     a[node] = min(a[node], val);     for (long long int i : conn[node]) {       if (i == par) continue;       dfs1(i, node, a[node]);     }   }   void dfs2(long long int node, long long int par) {     for (long long int i : conn[node]) {       if (i == par) continue;       dfs2(i, node);       c0[node] += c0[i];       c1[node] += c1[i];     }     if (b[node] == 0 && c[node] == 1) {       c0[node]++;     }     if (b[node] == 1 && c[node] == 0) {       c1[node]++;     }   }   long long int dfs3(long long int node, long long int par) {     long long int ct0 = 0, ct1 = 0;     if (b[node] == 0 && c[node] == 1) ct0 = 1;     if (b[node] == 1 && c[node] == 0) ct1 = 1;     for (long long int i : conn[node]) {       if (i == par) continue;       long long int temp = dfs3(i, node);       if (temp > 0) {         ct0 += temp;       } else {         ct1 -= temp;       }     }     long long int m = min(ct0, ct1);     ans += a[node] * m;     ct0 -= m;     ct1 -= m;     if (ct0) return ct0;     return -ct1;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     a.resize(n);     b.resize(n);     c.resize(n);     conn.resize(n);     for (long long int i = 0; i < (n); i++) cin >> a[i] >> b[i] >> c[i];     for (long long int i = 0; i < (n - 1); i++) {       long long int x;       cin >> x;       long long int y;       cin >> y;       x--, y--;       conn[x].push_back(y);       conn[y].push_back(x);     }     dfs1(0, -1, (long long int)1e18);     c0.resize(n);     c1.resize(n);     dfs2(0, -1);     if (dfs3(0, -1)) {       cout << -1 <<   n ;     } else {       cout << 2 * ans <<   n ;     }     cerr <<  Time :   << 1000 * (long double)clock() / (long double)CLOCKS_PER_SEC          <<  ms n ;     ;   }


#include <bits/stdc++.h>   long long n, md;   void rid(int n, int m) {     int i;     long long sol = 1, p = 1;     for (i = 0, p = n; i <= 30; i++) {       if ((m & (1 << i)) == (1 << i)) {         sol = (long long)sol * p;         sol = (long long)sol % md;       }       p = (long long)p * p;       p = (long long)p % md;     }     if (sol == 0)       sol = md - 1;     else       sol--;     printf( %I64d , sol);   }   int main() {     scanf( %I64d%I64d , &n, &md);     rid(3, n);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a[11], mx, n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     printf( %d , *max_element(a + 1, a + n + 1) ^ a[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 510;   char g[maxn][maxn];   int col[maxn][maxn], v[maxn * maxn], b[maxn * maxn], cnt, n, k, sum;   int dx[] = {0, 0, 1, -1};   int dy[] = {1, -1, 0, 0};   void dfs(int x, int y, int c) {     col[x][y] = c;     ++cnt;     for (int i = 0; i < 4; ++i) {       int tx = x + dx[i], ty = y + dy[i];       if (tx < 0 || ty < 0 || tx >= n || ty >= n || g[tx][ty] ==  X  ||           col[tx][ty])         continue;       dfs(tx, ty, c);     }   }   void add(int x, int y) {     if (col[x][y] && ++v[col[x][y]] == 1) sum += b[col[x][y]];   }   void dec(int x, int y) {     if (col[x][y] && --v[col[x][y]] == 0) sum -= b[col[x][y]];   }   int main() {     scanf( %d %d , &n, &k);     for (int i = 0; i < n; ++i) scanf( %s , g[i]);     int c = 1;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j)         if (g[i][j] ==  .  && !col[i][j]) {           cnt = 0;           dfs(i, j, c);           b[c++] = cnt;         }     }     int ans = 0;     for (int i = 0; i + k <= n; ++i) {       memset(v, 0, sizeof v);       sum = 0;       for (int x = 0; x < k; ++x) {         for (int y = 0; y < k; ++y) {           add(x + i, y);           if (!col[x + i][y]) ++sum;         }         if (i + k < n) add(i + k, x);         if (k < n) add(x + i, k);         if (i) add(i - 1, x);       }       ans = max(ans, sum);       for (int j = 1; j + k <= n; ++j) {         if (i) {           if (j - 1 >= 0) dec(i - 1, j - 1);           add(i - 1, j + k - 1);         }         if (i + k < n) {           if (j - 1 >= 0) dec(i + k, j - 1);           add(i + k, j + k - 1);         }         if (j - 1 >= 0)           for (int t = 0; t < k; ++t)             if (!col[i + t][j - 1]) --sum;         if (j - 2 >= 0)           for (int t = 0; t < k; ++t) dec(i + t, j - 2);         if (j + k - 1 < n)           for (int t = 0; t < k; ++t)             if (!col[i + t][j + k - 1]) ++sum;         if (j + k <= n)           for (int t = 0; t < k; ++t) add(i + t, j + k);         ans = max(ans, sum);       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000100;   int N;   long long K;   long long arr[MAXN], anew[MAXN], tcur[MAXN], tnew[MAXN];   int main() {     scanf( %d %I64d , &N, &K);     arr[0] = 0;     for (int i = 1; i < N; i++) {       int p;       long long w;       scanf( %d %I64d , &p, &w);       p--;       arr[i] = arr[p] ^ w;     }     sort(arr, arr + N);     for (int i = 0; i < N; i++) anew[i] = arr[i];     long long ans = 0;     for (int i = 61; i >= 0; i--) {       for (int j = 0; j < N; j++) {         tcur[j] = (arr[j] >> i);         tnew[j] = (anew[j] >> i);       }       long long pp = 0;       int lloc = 0, rloc = 0;       while (lloc < N) {         long long cv = tcur[lloc];         while (rloc < N && tnew[rloc] < cv) rloc++;         long long nl = 0, nr = 0;         while (lloc < N && tcur[lloc] == cv) {           lloc++;           nl++;         }         while (rloc < N && tnew[rloc] == cv) {           rloc++;           nr++;         }         pp += nl * nr;       }       if (pp < K) {         ans += (1LL << i);         K -= pp;         for (int j = 0; j < N; j++) anew[j] ^= (1LL << i);         for (int j = 0; j < N - 1; j++) {           if (anew[j] > anew[j + 1]) {             int cj = j, ej = j + 1;             while (cj && anew[cj - 1] > anew[j + 1]) cj--;             while (ej < N - 1 && anew[ej + 1] < anew[j]) ej++;             reverse(anew + cj, anew + j + 1);             reverse(anew + j + 1, anew + ej + 1);             reverse(anew + cj, anew + ej + 1);           }         }       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> by;   vector<int> sl;   int main() {     long long int a, b, c, d, m, n, ck = 0, ans, s, r;     cin >> n >> m >> r;     for (int i = 0; i < n; i++) {       cin >> s;       by.push_back(s);     }     sort(by.begin(), by.end());     for (int j = 0; j < m; j++) {       cin >> b;       sl.push_back(b);     }     sort(sl.begin(), sl.end(), greater<int>());     long long int buy = r / by[0];     long long int rem = r % by[0];     long long int sell = buy * sl[0];     ans = sell + rem;     if (ans > r) {       cout << ans << endl;     } else {       cout << r << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   long long int M = 1e9 + 7;   long long int MOD = 998244353;   const double PI = 3.141592653589793238460;   long long int power(long long int a, long long int b) {     long long int res = 1;     if (a == 0) return 0;     if (a == 1) return 1;     for (; b > 0; b >>= 1) {       if (b & 1) {         res = (res * a);         if (res > M) res %= M;       }       a = (a * a);       if (a > M) a = a % M;     }     return res;   }   int main() {     long long int maxi = -1e18;     long long int n;     cin >> n;     long long int a[n], b[n];     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     for (int i = 0; i < n; i++) {       long long int x = a[i];       long long int y = b[i];       for (int j = i; j < n; j++) {         x |= (a[j]);         y |= (b[j]);         maxi = max(maxi, x + y);       }     }     cout << maxi;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     int arr[n][n];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) cin >> arr[i][j];     }     a[0] = 0;     for (int j = 1; j < n; j++) {       a[0] = a[0] | arr[0][j];       a[j] = arr[0][j];     }     for (int i = 1; i < n; i++) {       for (int j = i + 1; j < n; j++) {         a[i] = a[i] | arr[i][j];         a[j] = arr[i][j] | a[j];       }     }     for (int i = 0; i < n; i++) cout << a[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long a, long long p, long long mod) {     long long ret = 1;     while (p) {       if (p & 1) ret = (ret * a) % mod;       a = (a * a) % mod;       p /= 2;     }     return ret;   }   long long DP[1000];   int A[1000];   int main() {     int n;     cin >> n;     for (__typeof((__typeof(n))0) i((__typeof(n))0); i < n; i++) {       cin >> A[i];       A[i]--;     }     for (int i = 0; i < n; i++) {       DP[i] = 2;       for (int j = A[i]; j < i; j++) DP[i] = (DP[i] + DP[j]) % 1000000007;     }     long long ans = 0;     for (int i = 0; i < n; i++) ans = (ans + DP[i]) % 1000000007;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1511, M = 3010100, inf = 0x7fffffff;   const long long llinf = 0x7fffffff7fffffffll;   long long x[N], y[N], r[N];   long long c[N];   double dist(int i, int j) {     return sqrtl((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));   }   double area(int i) {     return 3.14159265358979323846264338327950288 * r[i] * r[i];   }   int main(int argc, const char* argv[]) {     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> x[i] >> y[i] >> r[i];     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         if (r[i] < r[j] && dist(i, j) <= r[j]) {           ++c[i];         }       }     }     double sum = 0;     for (int i = 1; i <= n; ++i) {       if (c[i] == 0) {         sum += area(i);       } else if (c[i] % 2 == 1) {         sum += area(i);       } else {         sum -= area(i);       }     }     printf( %.10f , sum);     return 0;   }


#include <bits/stdc++.h>   // #include <atcoder/all>      //tabaicho  see https://boostjp.github.io/tips/multiprec-int.html      // #include <boost/multiprecision/cpp_int.hpp>      // using namespace boost::multiprecision;      // cpp_int   // int128_t   // int256_t   // int512_t   // int1024_t      // uint128_t   // uint256_t   // uint512_t   // uint1024_t             #define int long long    #define inf  1000000007   // #define inf  998244353       #define pa pair<int,int>    #define ll long long    #define PI 3.14159265358979323846    #define  mp make_pair    #define  pb push_back    #define EPS (1e-8)             using namespace std;                                                 int dx[8]={0,1,0,-1,1,1,-1,-1};    int dy[8]={1,0,-1,0,-1,1,1,-1};                                                  class pa3{    public:    int x;    int y,z;    pa3(int x=0,int y=0,int z=0):x(x),y(y),z(z) {}    bool operator < (const pa3 &p) const{     if(x!=p.x) return x<p.x;     if(y!=p.y) return y<p.y;      return z<p.z;     //return x != p.x ? x<p.x: y<p.y;    }    bool operator > (const pa3 &p) const{     if(x!=p.x) return x>p.x;     if(y!=p.y) return y>p.y;      return z>p.z;     //return x != p.x ? x<p.x: y<p.y;    }    bool operator == (const pa3 &p) const{     return x==p.x && y==p.y && z==p.z;    }     bool operator != (const pa3 &p) const{      return !( x==p.x && y==p.y && z==p.z);    }      };      class pa4{    public:    int x;    int y,z,w;    pa4(int x=0,int y=0,int z=0,int w=0):x(x),y(y),z(z),w(w) {}    bool operator < (const pa4 &p) const{     if(x!=p.x) return x<p.x;     if(y!=p.y) return y<p.y;     if(z!=p.z)return z<p.z;     return w<p.w;     //return x != p.x ? x<p.x: y<p.y;    }    bool operator > (const pa4 &p) const{     if(x!=p.x) return x>p.x;     if(y!=p.y) return y>p.y;     if(z!=p.z)return z>p.z;     return w>p.w;     //return x != p.x ? x<p.x: y<p.y;    }    bool operator == (const pa4 &p) const{     return x==p.x && y==p.y && z==p.z &&w==p.w;    }           };   class pa2{    public:    int x,y;    pa2(int x=0,int y=0):x(x),y(y) {}    pa2 operator + (pa2 p) {return pa2(x+p.x,y+p.y);}    pa2 operator - (pa2 p) {return pa2(x-p.x,y-p.y);}    bool operator < (const pa2 &p) const{     return y != p.y ? y<p.y: x<p.x;    }    bool operator > (const pa2 &p) const{     return x != p.x ? x<p.x: y<p.y;    }    bool operator == (const pa2 &p) const{     return abs(x-p.x)==0 && abs(y-p.y)==0;    }    bool operator != (const pa2 &p) const{     return !(abs(x-p.x)==0 && abs(y-p.y)==0);    }           };            string itos( int i ) {    ostringstream s ;    s << i ;    return s.str() ;   }       int Gcd(int v,int b){    if(v==0) return b;    if(b==0) return v;    if(v>b) return Gcd(b,v);    if(v==b) return b;    if(b%v==0) return v;    return Gcd(v,b%v);   }          int mod;   int extgcd(int a, int b, int &x, int &y) {       if (b == 0) {           x = 1;           y = 0;           return a;       }       int d = extgcd(b, a%b, y, x);       y -= a/b * x;       return d;   }   pa operator+(const pa & l,const pa & r) {          return {l.first+r.first,l.second+r.second};                                       }       pa operator-(const pa & l,const pa & r) {          return {l.first-r.first,l.second-r.second};                                       }        ostream& operator<<(ostream& os, const vector<int>& VEC){    for(auto v:VEC)os<<v<<   ;       return os;   }      ostream& operator<<(ostream& os, const pa& PAI){    os<<PAI.first<<  :  <<PAI.second;       return os;   }      ostream& operator<<(ostream& os, const pa3& PAI){    os<<PAI.x<<  :  <<PAI.y<<  :  <<PAI.z;       return os;   }      ostream& operator<<(ostream& os, const pa4& PAI){    os<<PAI.x<<  :  <<PAI.y<<  :  <<PAI.z<<  :  <<PAI.w;       return os;   }      ostream& operator<<(ostream& os, const vector<pa>& VEC){    for(auto v:VEC)os<<v<<   ;       return os;   }         int beki(int wa,int rr,int warukazu){    if(rr==0) return 1%warukazu;    if(rr==1) return wa%warukazu;    wa%=warukazu;    if(rr%2==1) return ((ll)beki(wa,rr-1,warukazu)*(ll)wa)%warukazu;    ll zx=beki(wa,rr/2,warukazu);    return (zx*zx)%warukazu;   }                       int pr[1];   int inv[1];            int comb(int nn,int rr){    if(rr<0 || rr>nn || nn<0) return 0;    int r=pr[nn]*inv[rr];    r%=mod;    r*=inv[nn-rr];    r%=mod;    return r;   }      void gya(int ert){    pr[0]=1;    for(int i=1;i<=ert;i++){     pr[i]=((ll)pr[i-1]*i)%mod;    }     inv[ert]=beki(pr[ert],mod-2,mod);    for(int i=ert-1;i>=0;i--){     inv[i]=(ll)inv[i+1]*(i+1)%mod;    }   }                                                                   //   cin.tie(0);         // ios::sync_with_stdio(false);          //priority_queue<pa3,vector<pa3>,greater<pa3>> pq;                                //sort(ve.begin(),ve.end(),greater<int>());    //   mt19937(clock_per_sec);     //  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()) ;                  void solve(){   int n;    cin>>n;    vector<int>dp(n,0);            vector<int>id(n),s(n);    //int xn=0;    for(auto &v:id){     cin>>v;     v--;    // pos[v].pb(xn);    // xn++;    }    for(auto &v:s)cin>>v;        int ans=0;    for(int i=n-1;i>=0;i--){     int pos=0;     for(int j=0;j<i;j++){      if(id[i]!=id[j]){       int g=dp[j]+abs(s[i]-s[j]);       int f=max(dp[i],pos)+abs(s[i]-s[j]);              dp[j]=max(dp[j],f);       pos=max(pos,g);       ans=max(ans,g);       ans=max(ans,f);      }           }    }    cout<<ans<<endl;      }            signed main(){    mod=inf;    cin.tie(0);    ios::sync_with_stdio(false);   int n=1;    cin>>n;       for(int i=0;i<n;i++)solve();        return 0;    }


#include <bits/stdc++.h>   using namespace std;   vector<string> prices;   enum State { name, price };   double to_num(string s) {     double n = 0;     int dots = 0, dot = 0;     bool frac = false;     for (char c : s)       if (c ==  . ) ++dots;     if (s[s.size() - 3] ==  . ) frac = true;     for (int i = 0; i < s.size(); ++i) {       if (s[i] >=  0  && s[i] <=  9 ) {         n *= 10;         n += s[i] -  0 ;       } else if (s[i] ==  . )         ++dot;       if (dot == dots && frac) {         n += double(s[i + 1] -  0 ) / 10.;         n += double(s[i + 2] -  0 ) / 100.;         break;       }     }     return n;   }   string to_price(double n) {     string s = to_string(n);     string fraction;     int dot = 0;     for (int i = 0; i < s.size(); ++i)       if (s[i] ==  . ) dot = i;     if (s[dot + 1] !=  0  || s[dot + 2] !=  0 ) {       fraction.push_back( . );       fraction.push_back(s[dot + 1]);       fraction.push_back(s[dot + 2]);     }     string c = s.substr(0, dot);     s = c;     string integer = to_string(int(n));     string res;     for (int i = integer.size() - 1, k = 0; i >= 0; --i) {       ++k;       res.push_back(integer[i]);       if (k % 3 == 0 && i != 0) res.push_back( . );     }     reverse(res.begin(), res.end());     res += fraction;     return res;   }   int main() {     string input;     getline(cin, input);     string s;     State state = name;     for (char c : input) {       if (isalpha(c) && state == name)         continue;       else if (!isalpha(c) && state == name) {         state = price;         s.push_back(c);       } else if (!isalpha(c) && state == price)         s.push_back(c);       else if (isalpha(c) && state == price) {         state = name;         prices.push_back(s);         s.clear();       }     }     prices.push_back(s);     double sum = 0;     for (int i = 0; i < prices.size(); ++i) sum += to_num(prices[i]);     cout << to_price(sum);   }


#include <bits/stdc++.h>   const int fin = 0, maxn = 400000, maxm = maxn << 1;   int n, m, cent, tot;   int fs[maxn], e[maxm], next[maxm];   int bel[maxn], pos[maxn], len[maxn], left[maxn];   int c[maxn], deg[maxn], b[maxn];   bool v[maxn];   struct rec {     int x, y;   } g[maxn];   int sum(int *a, int n, int x) {     int s = 0;     for (; x; x -= ((x) & (-(x)))) s += a[x];     return s;   }   void upd(int *a, int n, int x, int w) {     for (; x <= n; x += ((x) & (-(x)))) a[x] += w;   }   inline void addedge(int x, int y) {     e[++m] = y;     next[m] = fs[x];     fs[x] = m;     e[++m] = x;     next[m] = fs[y];     fs[y] = m;   }   void init() {     int i;     scanf( %d , &n);     m = 0;     for (i = 1; i < n; ++i) {       scanf( %d%d , &g[i].x, &g[i].y);       addedge(g[i].x, g[i].y);       deg[g[i].x]++;       deg[g[i].y]++;     }     cent = 0;     for (i = 1; i <= n; ++i)       if (deg[i] > 2) {         cent = i;         break;       }     if (!cent) cent = 1;   }   void build() {     int i, j, p, k, t;     i = fs[cent];     tot = 0;     v[cent] = true;     bel[cent] = 0;     for (j = 1; j <= deg[cent]; ++j) {       p = e[i];       bel[p] = j;       v[p] = true;       b[++tot] = p;       pos[p] = 1;       left[j] = tot;       while (next[fs[p]]) {         if (v[e[fs[p]]])           t = e[next[fs[p]]];         else           t = e[fs[p]];         v[t] = true;         b[++tot] = t;         bel[t] = j;         pos[t] = pos[p] + 1;         p = t;       }       len[j] = tot - left[j] + 1;       i = next[i];       for (k = 1; k <= len[j]; ++k) upd(c + left[j] - 1, len[j], k, 1);     }   }   void solve() {     int que, x, y, j, t, type, p, k;     scanf( %d , &que);     while (que--) {       scanf( %d , &type);       if (type == 1) {         scanf( %d , &p);         x = g[p].x;         y = g[p].y;         if ((!bel[x]) || (!bel[y])) {           j = bel[y] + bel[x];           upd(c + left[j] - 1, len[j], 1, 1);         } else {           j = bel[x];           if (pos[x] > pos[y])             k = pos[x];           else             k = pos[y];           upd(c + left[j] - 1, len[j], k, 1);         }       } else if (type == 2) {         scanf( %d , &p);         x = g[p].x;         y = g[p].y;         if ((!bel[x]) || (!bel[y])) {           j = bel[y] + bel[x];           upd(c + left[j] - 1, len[j], 1, -1);         } else {           j = bel[x];           if (pos[x] > pos[y])             k = pos[x];           else             k = pos[y];           upd(c + left[j] - 1, len[j], k, -1);         }       } else {         scanf( %d%d , &x, &y);         if (x == y)           printf( 0 n );         else {           if ((!bel[x]) || (!bel[y])) {             j = bel[x] + bel[y];             if (!bel[x])               k = pos[y];             else               k = pos[x];             t = sum(c + left[j] - 1, len[j], k);             if (t == k)               printf( %d n , t);             else               printf( -1 n );           } else if (bel[x] == bel[y]) {             j = bel[x];             if (pos[x] > pos[y]) {               t = x;               x = y;               y = t;             }             t = sum(c + left[j] - 1, len[j], pos[y]) -                 sum(c + left[j] - 1, len[j], pos[x]);             if (t == pos[y] - pos[x])               printf( %d n , t);             else               printf( -1 n );           } else {             j = bel[x];             t = sum(c + left[j] - 1, len[j], pos[x]);             j = bel[y];             t += sum(c + left[j] - 1, len[j], pos[y]);             if (t == pos[x] + pos[y])               printf( %d n , t);             else               printf( -1 n );           }         }       }     }   }   int main() {     if (fin) {       freopen( t.in ,  r , stdin);       freopen( t.out ,  w , stdout);     }     init();     build();     solve();     if (fin) {       fclose(stdin);       fclose(stdout);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, sum, ans;   int cnt[1000010], pre[1000010];   char a[1000010], b[1000010];   int main() {     scanf( %s%s , a + 1, b + 1);     n = strlen(a + 1);     m = strlen(b + 1);     for (int i = 1; i < n; i++)       if (a[i] != a[i + 1]) cnt[i] = 1;     for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + cnt[i];     for (int i = 1; i <= m; i++) {       if (a[i] != b[i]) sum++;     }     if (sum % 2 == 0) ans = 1;     for (int i = m + 1; i <= n; i++) {       sum += pre[i - 1] - pre[i - m - 1];       if (sum % 2 == 0) ans++;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j, sum, count;     cin >> n;     int a[n][n];     int row[n], col[n];     for (i = 0; i < n; i++) {       sum = 0;       for (j = 0; j < n; j++) {         cin >> a[i][j];         sum += a[i][j];       }       row[i] = sum;     }     for (j = 0; j < n; j++) {       sum = 0;       for (i = 0; i < n; i++) {         sum += a[i][j];       }       col[j] = sum;     }     count = 0;     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         if (col[i] > row[j]) count++;       }     }     cout << count << endl;     return 0;   }