#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > g, tr, comp;   vector<int> us, vis, whr, col;   void dfs(int v) {     us[v] = 1;     for (int i = 0; i < g[v].size(); i++) {       int j = g[v][i];       if (!us[j]) dfs(j);     }     vis.push_back(v);     return;   }   void dfstr(int v) {     comp[comp.size() - 1].push_back(v);     whr[v] = comp.size() - 1;     us[v] = 1;     for (int i = 0; i < tr[v].size(); i++) {       int j = tr[v][i];       if (!us[j]) dfstr(j);     }     return;   }   void doit(int v, int c) {     us[v] = 1;     if ((v & 1) ^ c)       col[v / 2] = 1;     else       col[v / 2] = 0;     for (int i = 0; i < g[v].size(); i++) {       int j = g[v][i];       if (!us[j]) doit(j, c);     }     return;   }   int main() {     iostream::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     int n;     cin >> n;     vector<string> all(n);     vector<pair<string, string> > add(n);     for (int i = 0; i < n; i++) {       string s, c;       cin >> s >> c;       all[i] = s.substr(0, 2);       add[i].first = s.substr(2, 1);       add[i].second = c.substr(0, 1);     }     g.resize(2 * n);     tr.resize(2 * n);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i == j) continue;         if (all[i] + add[i].first == all[j] + add[j].first) {           g[2 * i].push_back(2 * j + 1);           g[2 * j].push_back(2 * i + 1);           tr[2 * j + 1].push_back(2 * i);           tr[2 * i + 1].push_back(2 * j);           g[2 * i + 1].push_back(2 * j + 1);           g[2 * j + 1].push_back(2 * i + 1);           tr[2 * i + 1].push_back(2 * j + 1);           tr[2 * j + 1].push_back(2 * i + 1);         }         if (all[i] + add[i].first == all[j] + add[j].second) {           g[2 * i].push_back(2 * j);           g[2 * j + 1].push_back(2 * i + 1);           tr[2 * j].push_back(2 * i);           tr[2 * i + 1].push_back(2 * j + 1);         }         if (all[i] + add[i].second == all[j] + add[j].second) {           g[2 * i + 1].push_back(2 * j);           g[2 * j + 1].push_back(2 * i);           tr[2 * j].push_back(2 * i + 1);           tr[2 * i].push_back(2 * j + 1);         }         if (all[i] + add[i].second == all[j] + add[j].first) {           g[2 * i + 1].push_back(2 * j + 1);           g[2 * j].push_back(2 * i);           tr[2 * j + 1].push_back(2 * i + 1);           tr[2 * i].push_back(2 * j);         }       }     }     us.resize(2 * n, 0);     for (int i = 0; i < 2 * n; i++) {       if (!us[i]) {         dfs(i);       }     }     us.assign(2 * n, 0);     whr.resize(2 * n);     for (int i = 2 * n - 1; i >= 0; i--) {       int x = vis[i];       if (!us[x]) {         comp.emplace_back(vector<int>());         dfstr(x);       }     }     for (int i = 0; i < n; i++) {       if (whr[2 * i] == whr[2 * i + 1]) {         cout <<  NO n ;         return 0;       }     }     col.resize(n);     us.assign(2 * n, 0);     reverse(comp.begin(), comp.end());     for (int i = 0; i < comp.size(); i++) {       for (int j = 0; j < comp[i].size(); j++) {         if (!us[comp[i][j]]) doit(comp[i][j], 1);       }     }     cout <<  YES n ;     for (int i = 0; i < n; i++) {       cout << all[i] << (col[i] == 0 ? add[i].first : add[i].second) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int conv[][3] = {{1, 2, 3}, {2, 3, 1}, {3, 1, 2}};   void solve(long long int n) {     int r = n % 3;     if (r != 0) n = (n / 3 + 1) * 3;     if (r == 0)       r = 2;     else       r = r - 1;     int k = 0;     long long int cnt = 3;     while (cnt < n) {       k++;       cnt += 3 * pow(4, k);     }     cnt -= 3 * pow(4, k);     cnt = n - cnt;     vector<int> v(k + 1);     v[0] = 1;     int j;     for (int i = 1; i < k + 1; i++) {       for (j = 0; j < 4; j++) {         cnt -= 3 * pow(4, k - i);         if (cnt <= 0) {           cnt += 3 * pow(4, k - i);           break;         }       }       v[i] = j;     }     long long int ans = 0;     for (int i = 0; i < k + 1; i++) {       if (v[i] > 0) {         ans += conv[v[i] - 1][r] << (2 * (k - i));       }     }     printf( %lld n , ans);   }   int main() {     int t;     long long int n;     scanf( %d , &t);     while (t--) {       scanf( %lld , &n);       solve(n);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 9.2e18;   const int maxn = 1e6 + 70;   const int INF = 2.1e9;   const int maxm = 1e6 + 70;   const int MOD = 1e9 + 7;   const double eps = 1e-7;   const double PI = acos(-1.0);   int n, m, k;   vector<int> G[maxn];   int dep[maxn], mind[maxn], dp[maxn];   int dfs(int u) {     if (!G[u].size()) {       mind[u] = dep[u] - k;       dp[u] = 1;       return 1;     } else {       int mx = 0;       mind[u] = dep[u];       dp[u] = 0;       for (int i = 0; i < G[u].size(); i++) {         int v = G[u][i];         dep[v] = dep[u] + 1;         int val = dfs(v);         mind[u] = min(mind[u], mind[v]);         if (mind[v] <= dep[u]) {           dp[u] += dp[v];           mx = max(mx, val - dp[v]);         } else {           mx = max(mx, val);         }       }       return dp[u] + mx;     }   }   int main() {     while (cin >> n >> k) {       for (int i = 1; i <= n; i++) G[i].clear();       for (int i = 2; i <= n; i++) {         int f;         scanf( %d , &f);         G[f].push_back(i);       }       dep[1] = 0;       int ans = dfs(1);       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, d, a, b, x, y;     cin >> n >> d >> a >> b;     pair<long long, long long> arr[n];     for (int i = 0; i < n; i++) {       cin >> x >> y;       x *= a;       y *= b;       arr[i] = {x + y, i + 1};     }     sort(arr, arr + n);     vector<int> vec;     for (int i = 0; i < n; i++) {       if (d >= arr[i].first) {         d -= arr[i].first;         vec.push_back(arr[i].second);       } else         break;     }     cout << vec.size() << endl;     for (int i = 0; i < vec.size(); i++) cout << vec[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   const int maxn = 5e4 + 9;   int p[1009], a[1009];   bool vis[1009];   int dfs(int i) {     if (vis[i]) return i;     vis[i] = 1;     int id = dfs(p[i]);     return id;   }   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> p[i];     }     for (int i = 1; i <= n; i++) {       memset(vis, 0, sizeof(vis));       a[i] = dfs(i);     }     for (int i = 1; i <= n; i++) {       cout << a[i] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int M = 1e3 + 7;   map<long long int, long long int> value, visit;   long long int n, m, points[M][M];   long long int bfs(long long int node) {     long long int i;     for (i = 1; i < n + 1; i++) {       if (points[node][i] == 1) {         if (value[i] == 0) {           value[i] = value[node];         } else if (value[i] != 2 && value[i] != value[node])           return -1;       }     }     return 0;   }   long long int check() {     long long int i, j;     for (i = 1; i < n + 1; i++) {       for (j = 1; j < n + 1; j++) {         if (points[i][j] == 1) {           if ((value[i] == 1 && value[j] == 3) ||               (value[i] == 3 && value[j] == 1)) {             return 0;           }         }       }     }   }   int main() {     scanf( %lld , &n);     scanf( %lld , &m);     long long int i, j, a, b, cnta = 0, cntb = 0, cntc = 0;     for (i = 0; i < m; i++) {       scanf( %lld , &a);       scanf( %lld , &b);       points[a][b] = 1;       points[b][a] = 1;     }     for (i = 1; i < n + 1; i++) {       long long int flag = 1;       for (j = 1; j < n + 1; j++) {         if (points[i][j] == 0 && i != j) flag = 0;       }       if (flag == 1) {         value[i] = 2;       }     }     for (i = 1; i < n + 1; i++) {       for (j = 1; j < n + 1; j++) {         if (points[i][j] == 0 && i != j) {           if (value[i] == 0 || value[j] == 0) {             if (value[i] == 0 && value[j] == 0) {               value[i] = 1;               value[j] = 3;               if (bfs(i) == -1) {                 printf( No n );                 return 0;               }               if (bfs(j) == -1) {                 printf( No n );                 return 0;               }             } else if (value[i] == 0) {               value[i] = 4 - value[j];               if (bfs(i) == -1) {                 printf( No n );                 return 0;               }             } else {               value[j] = 4 - value[i];               if (bfs(j) == -1) {                 printf( No n );                 return 0;               }             }           } else if (value[i] == value[j]) {             printf( No n );             return 0;           }         }       }     }     if (check() == 0) {       printf( No n );       return 0;     }     printf( Yes n );     for (i = 1; i < n + 1; i++) {       if (value[i] == 1)         printf( a );       else if (value[i] == 2)         printf( b );       else         printf( c );     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1 << 17;   const long long MN = N;   long long s[MN];   long long m[MN];   long long rr[MN];   bool st[2 * N];   long long tme[2 * N];   long long lz[2 * N];   long long nn;   vector<pair<long long, pair<long long, long long> > > manaFull[2 * N];   struct second {     long long s, m, r;   };   void f1(long long k, long long l, long long r) {     for (long long i = l; i <= r; ++i) {       if (rr[i]) {         manaFull[k].push_back({m[i] / rr[i] + !!(m[i] % rr[i]), {m[i], rr[i]}});       } else {         manaFull[k].push_back({1e18, {m[i], rr[i]}});       }     }     sort(manaFull[k].begin(), manaFull[k].end());     for (long long i = 1; i < manaFull[k].size(); ++i) {       manaFull[k][i].second.first += manaFull[k][i - 1].second.first;     }     for (long long i = (long long)manaFull[k].size() - 1; i > 0; --i) {       manaFull[k][i - 1].second.second += manaFull[k][i].second.second;     }     if (l == r) return;     long long mid = (l + r) / 2;     f1(k * 2, l, mid);     f1(k * 2 + 1, mid + 1, r);   }   long long getFirstNotFull(long long k, long long t) {     long long lo = 0;     long long hi = (long long)manaFull[k].size() - 1;     long long res = hi + 1;     while (lo <= hi) {       long long mid = (lo + hi) / 2;       if (manaFull[k][mid].first > t) {         hi = mid - 1;         res = mid;       } else {         lo = mid + 1;       }     }     return res;   }   void lol(long long k, long long l, long long r, long long t) {     if (l < r && lz[k]) {       lz[k] = 0;       lz[k * 2] = 1;       lz[k * 2 + 1] = 1;       tme[k * 2] = tme[k];       tme[k * 2 + 1] = tme[k];     }   }   bool eka[2 * N];   long long absorbMana(long long k, long long l, long long r, long long x,                        long long y, long long t) {     long long res = 0;     if (l > y || r < x) return 0;     if (l >= x && r <= y && lz[k]) {       long long firstNotFull = getFirstNotFull(k, t - tme[k]);       if (firstNotFull != 0) {         res += manaFull[k][firstNotFull - 1].second.first;       }       long long sz = r - l + 1;       if (firstNotFull != sz)         res += (manaFull[k][firstNotFull].second.second) * (t - tme[k]);       if (eka[k]) {         eka[k] = 0;         res = min(m[k - N], s[k - N] + (t - tme[k]) * rr[k - N]);       }       lz[k] = 1;       tme[k] = t;       return res;     }     lol(k, l, r, t);     long long mid = (l + r) / 2;     long long q = absorbMana(k * 2, l, mid, x, y, t);     long long w = absorbMana(k * 2 + 1, mid + 1, r, x, y, t);     if (l >= x && r <= y) {       lz[k] = 1;       tme[k] = t;     }     return q + w;   }   int main() {     long long n;     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     nn = n;     for (long long i = 0; i < n; ++i) {       cin >> s[i] >> m[i] >> rr[i];       lz[i + N] = 1;       eka[i + N] = 1;     }     f1(1, 0, N - 1);     long long m;     cin >> m;     for (long long i = 0; i < m; ++i) {       long long t, l, r;       cin >> t >> l >> r;       cout << absorbMana(1, 0, N - 1, l - 1, r - 1, t) <<   n ;     }   }


#include<bits/stdc++.h>   #define pb(x) push_back(x)   #define all(x) x.begin(), x.end()   #define N 200005   #define FIFO ios::sync_with_stdio(false)   #define cout3(x, y, z) cout << x <<     << y <<     << z << endl   #define cout2(x, y) cout << x <<     << y << endl   #define INF (1<<30)   #define MOD 1000000007   #define ones(x) __builtin_popcountll(x)   #define EPS 1e-6      using namespace std;      long double v;   map<pair<long double, long double>, long double>memo;      long double DP(long double c, long double m, long double p){        //cout3(c, m, p);    if(c < EPS && m < EPS)return p;    if(memo.find(make_pair(c, m)) != memo.end())return memo[make_pair(c, m)];        long double ans = 0;    //chosing c    if(c > EPS){          if(c + EPS <= v){            if(m > EPS)ans += c * (1 + DP(0, m + c/2., p + c/2.));       else ans += c * (1 + DP(0, m, p + c));     }     else{            if(m > EPS)ans += c * (1 + DP(c - v, m + v/2, p + v/2));      else ans += c * (1 + DP(c - v, m, p + v));      }    }        if(m > EPS){     if(m + EPS <= v){            if(c > EPS)ans += m * (1 + DP(c + m/2, 0, p + m/2));      else ans += m * (1 + DP(c, 0, p + m));     }     else{            if(c > EPS)ans += m * (1 + DP(c + v/2, m - v, p + v/2));      else ans += m * (1 + DP(c, m - v, p + v));      }    }        if(p > EPS)ans += p;         return memo[make_pair(c, m)] = ans;       }            //string cases[7] = { 2 ,  02 ,  012 ,  0112 ,  12 ,  102 ,  1002 };      int main(){       FIFO;       int tc = 0;    cin >> tc;       while(tc--){        long double c, m, p, ans = 0;        cin >> c >> m >> p >> v;     memo.clear();          cout << fixed << setprecision(6) << DP(c, m, p) << endl;            /*     for(int i = 0; i < 7; i++){            double curProp[] = {c, m, p};      bool ok = true;      double prop = 1.0;            for(int j = 0, id; j < cases[i].size() && ok; j++){              id = cases[i][j] -  0 ;       if(curProp[id] == 0)ok = false;       else{                prop *= curProp[id];        if(curProp[id] <= v){                  vector<int>candidates;         int len = 0;                  for(int l = 0; l < 3; l++)if(l != id && curProp[l] != 0)candidates.pb(l);                  len = candidates.size();         double add = curProp[id]/len;         for(int l = 0; l < candidates.size(); l++)curProp[candidates[l]] += add;                  curProp[id] = 0;        }        else{                   vector<int>candidates;         int len = 0;                  for(int l = 0; l < 3; l++)if(l != id && curProp[l] != 0)candidates.pb(l);                  len = candidates.size();         double add = v/len;         for(int l = 0; l < candidates.size(); l++)curProp[candidates[l]] += add;                  curProp[id] -= v;        }       }              //for(int l = 0; l < 3; l++)cout  << curProp[l] <<    ;       //cout << endl;      }            //cout2(ok, prop);      if(ok)ans += prop * cases[i].size();      }               cout << ans << endl;        */    }         }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long mod1 = 998244353;   long long power(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b % 2 == 1) {         res = (res * a) % mod;       }       a = (a * a) % mod;       b >>= 1;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     t = 1;     long long lookup[1001][11];     for (int i = 0; i < 1001; i++) {       for (int j = 0; j < 11; j++) {         lookup[i][j] = 0;       }     }     lookup[0][0] = 0;     for (int i = 1; i <= 10; i++) {       lookup[1][i] = 1;       lookup[0][i] = 1;     }     for (int i = 1; i <= 1000; i++) {       lookup[i][1] = i;       lookup[i][0] = 1;     }     for (int i = 2; i <= 1000; i++) {       for (int j = 2; j <= 10; j++) {         lookup[i][j] += lookup[i - 1][j] + lookup[i][j - 1];         lookup[i][j] %= mod;       }     }     while (t--) {       int n, m;       cin >> n >> m;       long long ans = 0;       long long temp1, temp2, temp3;       for (int i = 1; i <= n; i++) {         temp1 = n - i + 1;         temp1 = lookup[temp1][m];         temp2 = i;         temp2 = lookup[temp2][m - 1];         temp3 = (temp1 * temp2) % mod;         ans += temp3;         ans %= mod;       }       cout << ans;     }   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma GCC optimize(3)   #pragma GCC optimize( Ofast )   #pragma GCC optimize( inline )   #pragma GCC optimize( -fgcse )   #pragma GCC optimize( -fgcse-lm )   #pragma GCC optimize( -fipa-sra )   #pragma GCC optimize( -ftree-pre )   #pragma GCC optimize( -ftree-vrp )   #pragma GCC optimize( -fpeephole2 )   #pragma GCC optimize( -ffast-math )   #pragma GCC optimize( -fsched-spec )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( -falign-jumps )   #pragma GCC optimize( -falign-loops )   #pragma GCC optimize( -falign-labels )   #pragma GCC optimize( -fdevirtualize )   #pragma GCC optimize( -fcaller-saves )   #pragma GCC optimize( -fcrossjumping )   #pragma GCC optimize( -fthread-jumps )   #pragma GCC optimize( -funroll-loops )   #pragma GCC optimize( -fwhole-program )   #pragma GCC optimize( -freorder-blocks )   #pragma GCC optimize( -fschedule-insns )   #pragma GCC optimize( inline-functions )   #pragma GCC optimize( -ftree-tail-merge )   #pragma GCC optimize( -fschedule-insns2 )   #pragma GCC optimize( -fstrict-aliasing )   #pragma GCC optimize( -fstrict-overflow )   #pragma GCC optimize( -falign-functions )   #pragma GCC optimize( -fcse-skip-blocks )   #pragma GCC optimize( -fcse-follow-jumps )   #pragma GCC optimize( -fsched-interblock )   #pragma GCC optimize( -fpartial-inlining )   #pragma GCC optimize( no-stack-protector )   #pragma GCC optimize( -freorder-functions )   #pragma GCC optimize( -findirect-inlining )   #pragma GCC optimize( -fhoist-adjacent-loads )   #pragma GCC optimize( -frerun-cse-after-loop )   #pragma GCC optimize( inline-small-functions )   #pragma GCC optimize( -finline-small-functions )   #pragma GCC optimize( -ftree-switch-conversion )   #pragma GCC optimize( -foptimize-sibling-calls )   #pragma GCC optimize( -fexpensive-optimizations )   #pragma GCC optimize( -funsafe-loop-optimizations )   #pragma GCC optimize( inline-functions-called-once )   #pragma GCC optimize( -fdelete-null-pointer-checks )   using namespace std;   const long long maxn = 1005;   const long long maxm = 1000005;   const long long dd = 998244353;   long long n, m;   long long a[maxm], sav[maxm], dp[maxn][maxn], col[maxn][maxn], L[maxn], R[maxn];   vector<long long> t[maxn];   struct nod {     long long val, pos;   } uni[maxm];   inline bool cmp(nod x, nod y) { return x.val < y.val; }   inline long long read() {     long long ret = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -f;       ch = getchar();     }     while (isdigit(ch)) {       ret = ret * 10 + ch -  0 ;       ch = getchar();     }     return ret * f;   }   void scan() {     m = read();     n = read();     for (long long k = 1; k <= n; k++) {       uni[k].val = read();       uni[k].pos = k;     }   }   void prework() {     long long lst = 0;     sort(uni + 1, uni + n + 1, cmp);     for (long long k = 1; k <= n; k++) {       if (uni[k].val != uni[k - 1].val) lst++;       sav[uni[k].pos] = lst;     }     m = lst;     long long now = 0;     for (long long k = 1; k <= n; k++)       if (sav[k] != a[now]) a[++now] = sav[k];     n = now;     for (long long k = 1; k <= n; k++) t[a[k]].push_back(k);     for (long long k = 1; k <= m; k++)       L[k] = t[k][0], R[k] = t[k][t[k].size() - 1];     for (long long k = 1; k <= m; k++)       for (long long j = k + 1; j <= m; j++)         if ((L[j] <= R[k] && R[k] < R[j]) || (R[j] >= L[k] && L[k] > L[j])) {           puts( 0 );           exit(0);         }     for (long long k = 1; k <= n; k++) {       long long now = k;       for (long long j = k; j <= n; j++)         col[k][j] = a[j] > a[now] ? now : now = j;     }   }   void solve() {     for (long long k = 0; k <= n + 1; k++)       for (long long j = 0; j <= k; j++) dp[k][j] = 1;     dp[0][1] = dp[1][1];     for (long long k = 2; k <= n; k++) {       for (long long l = 1; l + k - 1 <= n; l++) {         long long r = l + k - 1;         long long x = col[l][r], siz = t[a[x]].size();         long long ll = L[a[x]], rr = R[a[x]];         long long ans1 = 0, ans2 = 0, ans3 = 1;         for (long long k = l - 1; k < ll; k++)           ans1 = (ans1 + dp[l][k] * dp[k + 1][ll - 1]) % dd;         for (long long k = r + 1; k > rr; k--)           ans2 = (ans2 + dp[k][r] * dp[rr + 1][k - 1]) % dd;         dp[l][r] = ans1 * ans2 % dd;         for (long long k = 0; k < siz - 1; k++)           ans3 = ans3 * dp[t[a[x]][k] + 1][t[a[x]][k + 1] - 1] % dd;         dp[l][r] = dp[l][r] * ans3 % dd;       }     }     printf( %lld n , dp[1][n]);   }   signed main() {     scan();     prework();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 7;   const int mod = 1e9 + 7;   int n, m, f[N], jc[N], njc[N], ans;   int qpow(int x, int y) {     if (!x) return 0;     int res = 1;     for (; y; x = 1ll * x * x % mod, y >>= 1)       if (y & 1) res = 1ll * res * x % mod;     return res;   }   int ny(int x) { return qpow(x, mod - 2); }   int C(int x, int y) { return 1ll * jc[x] * njc[x - y] % mod * njc[y] % mod; }   int main() {     scanf( %d%d , &n, &m);     jc[0] = njc[0] = 1;     for (int i = 1, iE = n; i <= iE; i++)       jc[i] = 1ll * jc[i - 1] * i % mod, njc[i] = ny(jc[i]);     ans = n;     f[0] = 1;     int sum = 1;     for (int i = 1, iE = n - 1; i <= iE; i++) {       f[i] = sum, f[i] = 1ll * f[i] * ny(i) % mod, (sum += f[i]) %= mod;       if (i >= m) (sum += mod - f[i - m]) %= mod;     }     for (int i = 0, iE = n - 1; i <= iE; i++) (ans += mod - f[i]) %= mod;     ans = 1ll * ans * jc[n - 1] % mod;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma 03   using namespace std;   int main() {     cout <<  INTERCAL n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[26];   int b[26];   int main() {     for (int i = 0; i < 26; i++) a[i].second = i;     string s;     cin >> s;     int d;     cin >> d;     for (int i = 0; i < int(s.size()); i++) a[int(s[i] -  a )].first++;     sort(a, a + 26);     int tmp = 0;     for (int i = 0; i < 26; i++)       if (d >= a[i].first) {         b[tmp] = a[i].second;         tmp++;         d -= a[i].first;       }     bool g;     cout << 26 - tmp << endl;     for (int i = 0; i < int(s.size()); i++) {       g = 1;       for (int j = 0; j < tmp; j++)         if (int(s[i] -  a ) == b[j]) g = 0;       if (g) cout << s[i];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int res = 0;     int a[200005], n, i, mm = INT_MAX;     scanf( %d , &n);     for (i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       mm = min(mm, a[i]);     }     set<int> second;     for (i = 1; i <= n; ++i)       if (a[i] == mm) second.insert(i);     res = 1ll * mm * n;     long long int mx = 0;     for (i = 1; i <= n; ++i) {       if (a[i] == mm) continue;       auto it = second.upper_bound(i);       if (it != second.end())         mx = max(mx, (long long int)(*it - i));       else         mx = max(mx, (long long int)(n - i + *second.begin()));     }     res += mx;     printf( %lld , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int points[11] = {0, 25, 18, 15, 12, 10, 8, 6, 4, 2, 1};   struct T {     vector<int> a;     string name;     T() {       for (int i = (1); i <= (55); i++) a.push_back(0);     }     bool operator<(const T &b) const { return a > b.a; }   } ma[1100];   int n, games;   map<string, int> name;   int main() {     cin >> games;     while (games--) {       int man;       cin >> man;       for (int i = (1); i <= (man); i++) {         string s;         cin >> s;         int id = name[s];         if (id == 0) {           id = name[s] = ++n;           ma[id].name = s;         }         if (i <= 10) ma[id].a[0] += points[i];         ma[id].a[i]++;       }     }     sort(ma + 1, ma + n + 1);     cout << ma[1].name << endl;     for (int i = (1); i <= (n); i++) swap(ma[i].a[0], ma[i].a[1]);     sort(ma + 1, ma + n + 1);     cout << ma[1].name << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     while (cin >> n) {       int pos, val;       multimap<int, int> mp1, mp2;       while (n--) {         cin >> pos >> val;         pos < 0 ? mp1.insert(pair<int, int>(pos, val))                 : mp2.insert(pair<int, int>(pos, val));       }       int min_size = min(mp1.size(), mp2.size());       multimap<int, int>::reverse_iterator it1 = mp1.rbegin();       multimap<int, int>::iterator it2 = mp2.begin();       long long ans = 0;       for (int i = 0; i < min_size; ++i, ++it1, ++it2)         ans += ((it1->second) + (it2->second));       if (mp1.size() > mp2.size()) ans += (it1->second);       if (mp1.size() < mp2.size()) ans += (it2->second);       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 10;   vector<int> G[maxn];   int p[maxn], d[maxn], vis[maxn], mx, rt;   int find(int x) {     if (p[x] != x) p[x] = find(p[x]);     return p[x];   }   void dfs(int u, int fa, int dep, int tp) {     vis[u] = 1;     if (dep > mx) {       mx = dep;       if (!tp) rt = u;     }     if (tp) p[u] = rt;     for (int i = 0; i < G[u].size(); i++) {       int v = G[u][i];       if (v != fa) dfs(v, u, dep + 1, tp);     }   }   int main() {     int n, m, q, tp, u, v;     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= n; i++) p[i] = i;     for (int i = 1; i <= m; i++) {       scanf( %d%d , &u, &v);       G[u].push_back(v);       G[v].push_back(u);     }     for (int i = 1; i <= n; i++)       if (!vis[i]) {         mx = rt = 0;         dfs(i, 0, 0, 0);         dfs(rt, 0, 0, 1);         d[rt] = mx;       }     while (q--) {       scanf( %d , &tp);       if (tp == 2) {         scanf( %d%d , &u, &v);         int fu = find(u), fv = find(v);         if (fu != fv) {           p[fu] = fv;           int t1 = d[fu] / 2 + d[fu] % 2;           int t2 = d[fv] / 2 + d[fv] % 2;           d[fv] = max(d[fu], d[fv]);           d[fv] = max(d[fv], t1 + t2 + 1);         }       } else {         scanf( %d , &u);         int fu = find(u);         printf( %d n , d[fu]);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 1010, Maxm = 20;   const unsigned long long Seed = 19990213;   const long long Mod = 1000000007;   int n, m, cnt, tot1, fst1[Maxn], pre1[Maxn << 1], to1[Maxn << 1], tot2,       fst2[Maxm], pre2[Maxm << 1], to2[Maxm << 1], bel[Maxm], tot[Maxm],       stat[(1 << 12) + 10][Maxm], cur[Maxm], S, w[Maxm], size[Maxm];   bool vis[Maxn], leaf[Maxm];   long long f[Maxn][Maxm], g[Maxn][(1 << 12) + 10], ans;   unsigned long long ha[Maxm];   map<unsigned long long, bool> Hash;   vector<int> son[Maxn], sub[Maxm];   int Get() {     char ch;     int v = 0;     bool f = false;     while (!isdigit(ch = getchar()))       if (ch ==  - ) f = true;     v = ch - 48;     while (isdigit(ch = getchar())) v = v * 10 + ch - 48;     if (f)       return -v;     else       return v;   }   void AddE1(int x, int y) {     pre1[++tot1] = fst1[x], fst1[x] = tot1, to1[tot1] = y;     pre1[++tot1] = fst1[y], fst1[y] = tot1, to1[tot1] = x;   }   void AddE2(int x, int y) {     pre2[++tot2] = fst2[x], fst2[x] = tot2, to2[tot2] = y;     pre2[++tot2] = fst2[y], fst2[y] = tot2, to2[tot2] = x;   }   bool cmp(const int &a, const int &b) {     return ha[a] < ha[b] || (ha[a] == ha[b] && size[a] < size[b]);   }   void Add(long long &x, long long y) {     x += y;     if (x >= Mod) x -= Mod;   }   void Calc(int x, int fa) {     leaf[x] = true, size[x] = 1;     sub[x].clear();     for (int i = fst2[x]; i; i = pre2[i])       if (to2[i] != fa) {         Calc(to2[i], x);         size[x] += size[to2[i]];         sub[x].push_back(to2[i]);         leaf[x] = false;       }     if (leaf[x])       ha[x] = 666072;     else {       ha[x] = 0;       sort(sub[x].begin(), sub[x].end(), cmp);       for (int i = 0; i < sub[x].size(); i++)         ha[x] = (ha[x] * Seed + ha[sub[x][i]]) % Mod;       ha[x] = ha[x] * 1234 % Mod;     }   }   void Transform(int x, int w, int s) {     if (x == cnt + 1) {       S = max(S, s);       for (int i = 1; i <= cnt; i++) stat[s][i] = cur[i];       return;     } else {       for (int i = 0; i <= tot[x]; i++) {         cur[x] = i;         Transform(x + 1, w * (tot[x] + 1), s + i * w);       }     }   }   void dfs(int x) {     vis[x] = true;     son[x].clear();     for (int i = fst1[x]; i; i = pre1[i])       if (!vis[to1[i]]) son[x].push_back(to1[i]), dfs(to1[i]);     int len1 = int(son[x].size());     for (int i = 1; i <= m; i++)       if (leaf[i])         f[x][i] = 1;       else if (len1 > 0) {         f[x][i] = 0, cnt = 0, S = 0;         int len2 = int(sub[i].size());         for (int j = 0; j <= len2 - 1; j++) {           bel[++cnt] = sub[i][j], tot[cnt] = 1;           for (; j < len2 - 1 && ha[sub[i][j]] == ha[sub[i][j + 1]] &&                  size[sub[i][j]] == size[sub[i][j + 1]];                j++)             tot[cnt]++;         }         w[1] = 1;         for (int j = 2; j <= cnt; j++) w[j] = w[j - 1] * (tot[j - 1] + 1);         Transform(1, 1, 0);         for (int s = 0; s <= S; s++) g[0][s] = 0;         g[0][S] = 1;         for (int j = 0; j <= len1 - 1; j++) {           int u = son[x][j];           for (int s = 0; s <= S; s++) g[j + 1][s] = g[j][s];           for (int k = 1; k <= cnt; k++) {             int v = bel[k];             if (f[u][v]) {               for (int s = 0; s <= S; s++)                 if (stat[s][k]) {                   Add(g[j + 1][s - w[k]], g[j][s] * f[u][v] % Mod);                 }             }           }         }         f[x][i] = g[len1][0];       }   }   void solve(int root) {     for (int i = 1; i <= n; i++) vis[i] = false;     dfs(1);     long long res = 0;     for (int i = 1; i <= n; i++) {       Add(ans, f[i][root]);       Add(res, f[i][root]);       for (int j = 1; j <= m; j++) f[i][j] = 0;     }   }   int main() {     n = Get();     int x, y;     for (int i = 1; i <= n - 1; i++) x = Get(), y = Get(), AddE1(x, y);     m = Get();     for (int i = 1; i <= m - 1; i++) x = Get(), y = Get(), AddE2(x, y);     for (int i = 1; i <= m; i++) {       Calc(i, -1);       if (!Hash[ha[i]]) {         Hash[ha[i]] = true;         solve(i);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[300005];   int lastone[300005];   int nextone[300005];   long long sum[300005];   vector<int> vt[3];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       sum[i] = sum[i - 1] + a[i];       lastone[i] = (a[i] == 1000) ? i : lastone[i - 1];     }     for (int i = n; i >= 1; i--) {       nextone[i] = (a[i] == 1000) ? i : nextone[i + 1];     }     long long ans = sum[n];     for (int i = 1; i <= n; i++) {       long long bonus = sum[i] / 10;       long long rem = sum[n] - sum[i];       long long res = sum[i] + rem - min(rem, bonus);       ans = min(ans, res);       if (a[i] == 2000) {         int las = lastone[i];         if (las) {           res = sum[las - 1];           bonus = sum[las - 1] / 10;           res += a[las] - min(a[las] + 0ll, bonus);           bonus -= min(a[las] + 0ll, bonus);           bonus += (sum[i] - sum[las]) / 10;           res += (sum[i] - sum[las]);           rem = sum[n] - sum[i];           res += rem - min(rem, bonus);           ans = min(ans, res);         }         las = nextone[i + 1];         if (las) {           res = sum[i];           bonus = sum[i] / 10;           res += (sum[las - 1] - sum[i]) - min(sum[las - 1] - sum[i], bonus);           bonus -= min(sum[las - 1] - sum[i], bonus);           bonus += a[las] / 10;           res += a[las];           rem = sum[n] - sum[las];           res += rem - min(rem, bonus);           ans = min(ans, res);         }       }     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 2000000000000000000;   long double eps = 1e-12;   long long t, n, m, a;   vector<long long> vec;   void Stefan() {     cin >> n >> m;     long long cur = 1;     for (int i = 0; i < n; i++) {       cin >> a;       vec.push_back(a);     }     if (n > m) {       cout << 0;       return;     }     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         cur *= abs(vec[i] - vec[j]);         cur %= m;         if (!cur) {           cout << 0;           return;         }       }     }     cout << cur;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     t = 1;     while (t) {       Stefan();       t--;     }   }


#include <bits/stdc++.h>   using namespace std;      #define f first   #define s second   #define pb push_back   #define ar array   #define all(x) x.begin(), x.end()   #define siz(x) (int)x.size()      #define FOR(x, y, z) for(int x = (y); x < (z); x++)   #define ROF(x, z, y) for(int x = (y-1); x >= (z); x--)   #define F0R(x, z) FOR(x, 0, z)   #define R0F(x, z) ROF(x, 0, z)   #define trav(x, y) for(auto&x:y)      using ll = long long;   using vi = vector<int>;   using vl = vector<long long>;   using pii = pair<int, int>;   using vpii = vector<pair<int, int>>;      template<class T> inline bool ckmin(T&a, T b) {return b < a ? a = b, 1 : 0;}   template<class T> inline bool ckmax(T&a, T b) {return b > a ? a = b, 1 : 0;}   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());      const char nl =   n ;   const int mxN = 2e5 + 10;   const int MOD = 1e9 + 7;   const long long infLL = 1e18;      struct dsu{       int n; vector<int> sz, par;       void init(int _n){           n = _n; sz.resize(n); par.resize(n);           F0R(i, n) sz[i] = 1, par[i] = i;       }       int find(int x){ return par[x] = ( x == par[x] ? par[x] : find(par[x])); }       void comb(int a, int b) {           a=find(a); b=find(b);             if(a!=b) {sz[a]+=sz[b]; par[b] = a; }       }   };   #undef D   #define D QWERWQWEQWEQWEQ   dsu D;       set<ar<int, 3>> pq;      int32_t main(){       ios_base::sync_with_stdio(0); cin.tie(0);       int n; cin >> n;       vector<vi> a(n, vi(n));       vi par(n*10);       D.init(10*n);       vector<int> ans(10*n);       int cnt = n;       F0R(i, n){           F0R(j, n){               cin >> a[i][j];               if(i<=j)               pq.insert(ar<int, 3>{a[i][j], i, j});           }       }       while(!pq.empty()){           ar<int, 3> t = *pq.begin(); pq.erase(t);           if(t[1]==t[2]){               ans[t[1]] = t[0];           }           else{                               int u = D.find(t[1]), v = D.find(t[2]);               if(t[0]==ans[u]) par[v] = u, D.comb(u, v);               else if(t[0]==ans[v]) par[u] = v, D.comb(v, u);               else {                   ans[cnt] = t[0];                   par[u]=cnt;                   par[v]=cnt;                   D.comb(cnt, u);                   D.comb(cnt, v);                   cnt++;               }           }       }       cout << cnt << nl;       F0R(i, cnt){           cout << ans[i] <<    ;       }       cout << nl;       cout << cnt << nl;       F0R(i, cnt-1){           cout << i+1 <<     << par[i]+1 << nl;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     cin >> n;     const int maxN = n;     int r[maxN];     int c[maxN];     int a[maxN][maxN];     for (int i = 0; i < n; i++) {       r[i] = 0;       for (int j = 0; j < n; j++) {         cin >> a[i][j];         r[i] = r[i] + a[i][j];       }     }     for (int i = 0; i < n; i++) {       c[i] = 0;       for (int j = 0; j < n; j++) {         c[i] = c[i] + a[j][i];       }     }     int ans = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (c[j] > r[i]) {           ans++;         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T read() {     T f = 0, x = 0;     char c = getchar();     while (!isdigit(c)) f = c ==  - , c = getchar();     while (isdigit(c)) x = x * 10 + c - 48, c = getchar();     return f ? -x : x;   }   namespace run {   const int mod = 998244353, N = 1 << 16, inv2 = (mod + 1) / 2;   inline int add(int x, int y) { return x + y >= mod ? x - mod + y : x + y; }   inline int sub(int x, int y) { return x >= y ? x - y : x + mod - y; }   inline int qpow(int x, int y) {     int ret = 1;     while (y) {       if (y & 1) ret = 1LL * x * ret % mod;       x = 1LL * x * x % mod, y >>= 1;     }     return ret;   }   int inv[17], fac[17], ifac[17];   inline void Getln(int *a, int *b, int len) {     assert(a[0] == 1), b[0] = 0;     for (int i = 0; i < len - 1; i++) {       int sum = 1LL * a[i + 1] * (i + 1) % mod;       for (int j = 0; j < i; j++)         sum = sub(sum, 1LL * a[i - j] * (j + 1) % mod * b[j + 1] % mod);       b[i + 1] = 1LL * sum * inv[i + 1] % mod;     }   }   inline void Getexp(int *a, int *b, int len) {     assert(a[0] == 0), b[0] = 1;     for (int i = 0; i < len - 1; i++) {       b[i + 1] = 0;       for (int j = 0; j <= i; j++)         b[i + 1] = (1LL * (j + 1) * a[j + 1] % mod * b[i - j] + b[i + 1]) % mod;       b[i + 1] = 1LL * inv[i + 1] * b[i + 1] % mod;     }   }   inline void fwt_xor(int *a, int inv, int limit) {     for (int mid = 1; mid < limit; mid <<= 1)       for (int i = 0; i < limit; i += (mid << 1))         for (int j = 0; j < mid; j++) {           int x = a[i + j], y = a[i + j + mid];           if (inv == -1) x = 1LL * inv2 * x % mod, y = 1LL * inv2 * y % mod;           a[i + j] = add(x, y), a[i + j + mid] = sub(x, y);         }   }   int a[N], n, f[N], K, C, vis[N];   map<vector<int>, int> mp;   vector<int> st[209];   int count[N], tot, top, num[209], r[209], A[209];   int main() {     n = read<int>(), K = read<int>(), C = read<int>();     inv[0] = inv[1] = fac[0] = ifac[0] = ifac[1] = 1, count[0] = 0;     for (int i = 1; i <= K; i++) fac[i] = 1LL * fac[i - 1] * i % mod;     for (int i = 2; i <= K; i++)       inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod,       ifac[i] = 1LL * inv[i] * ifac[i - 1] % mod;     for (int i = 1; i < 1 << C; i++) count[i] = count[i >> 1] + (i & 1);     int xorsum = 0;     for (int i = 0; i < n; i++) xorsum ^= (a[i] = read<int>());     for (int i = 0; i < n; i++) {       vector<int> b;       for (int j = 0; j <= K; j++) b.push_back(a[i] ^ (a[i] - j));       mp[b]++;     }     for (map<vector<int>, int>::iterator i = mp.begin(); i != mp.end(); i++)       st[++top] = i->first, num[top] = i->second;     for (int s = 0; s < 1 << C; s++) {       tot = 0;       for (int i = 1; i <= top; i++) {         int tmp = 0;         for (int j = 0; j <= K; j++) tmp = (tmp << 1) | (count[st[i][j] & s] & 1);         if (!vis[tmp])           A[++tot] = tmp, r[tot] = num[i], vis[tmp] = tot;         else           r[vis[tmp]] += num[i];       }       static int c[17], d[17], ret[17];       memset(ret, 0, sizeof ret);       for (int i = 1; i <= tot; i++) {         for (int j = 0; j <= K; j++)           c[j] = (A[i] >> (K - j) & 1) ? mod - ifac[j] : ifac[j];         Getln(c, d, K + 1);         for (int j = 0; j <= K; j++) ret[j] = (1LL * d[j] * r[i] + ret[j]) % mod;         vis[A[i]] = 0;       }       Getexp(ret, c, K + 1), f[s] = 1LL * c[K] * fac[K] % mod;     }     fwt_xor(f, -1, 1 << C);     int p = qpow(qpow(n, K), mod - 2);     for (int i = 0; i < 1 << C; i++)       printf( %lld  , 1LL * f[i ^ xorsum] * p % mod);     return 0;   }   }  // namespace run   int main() { return run::main(); }


#include <bits/stdc++.h>   using namespace std;   int n, m, dx, dy;   int a[1000001];   int cnt[1000000] = {};   bool vis[1000000] = {};   inline int gcd(int a, int b) {     while (b) a %= b, swap(a, b);     return a;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m >> dx >> dy;     int g = gcd(dx, dy);     dx /= g, dy /= g;     a[0] = 0;     int x = 0, y = 0;     for (int i = 1; i <= n; ++i) {       x += dx;       if (x >= n) x -= n;       y += dy;       if (y >= n) y -= n;       a[x] = y;     }     for (int i = 0; i < (int)(m); ++i) {       cin >> x >> y;       int c = y - a[x];       if (c < 0) c += n;       ++cnt[c];     }     int best = -1, bestind = -1;     int delta = a[n];     for (int i = 0; i < (int)(n); ++i)       if (!vis[i]) {         int cur = 0;         int j = i;         while (!vis[j]) {           vis[j] = true;           cur += cnt[j];           j += delta;         }         if (cur > best) {           best = cur;           bestind = i;         }       }     cout << 0 <<     << bestind <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T checkmin(T &a, T b) {     return (a < b) ? a : a = b;   }   template <class T>   inline T checkmax(T &a, T b) {     return (a > b) ? a : a = b;   }   template <class T>   T GCD(T a, T b) {     if (a < 0) return GCD(-a, b);     if (b < 0) return GCD(a, -b);     return (a == 0) ? b : GCD(b % a, a);   }   template <class T>   T LCM(T a, T b) {     if (a < 0) return LCM(-a, b);     if (b < 0) return LCM(a, -b);     return (a == 0 || b == 0) ? 0 : a / GCD(a, b) * b;   }   template <class T>   inline T sqr(T X) {     return X * X;   }   namespace Poor {   const int MaxiN = 100005;   const int LogMaxiN = 18;   const int CharSet = 256;   int N;   char St[MaxiN];   long long Ra[CharSet];   long long X[LogMaxiN][MaxiN];   int SA[MaxiN], H[MaxiN];   int LCP(int A, int B) {     int Rec = A;     for (int j = LogMaxiN - 1; j >= 0; --j)       if (A + (1 << j) <= N && B + (1 << j) <= N && X[j][A] == X[j][B]) {         A += (1 << j);         B += (1 << j);       }     return A - Rec;   }   bool Cmp(int A, int B) {     int L = LCP(A, B);     return A + L == N || (B + L < N && St[A + L] < St[B + L]);   }   long long Solve(int L, int R, int C) {     int Len = LCP(SA[L], SA[R]);     long long res =         (long long)(R - L + 1) * (R - L + 2) / 2LL * (long long)(Len - C);     if (L == R) return res;     if (LCP(SA[L], SA[L]) == Len) return res + Solve(L + 1, R, Len);     if (LCP(SA[R], SA[R]) == Len) return res + Solve(L, R - 1, Len);     int l = L, r = R;     while (l < r) {       int mid = (l + r + 1) >> 1;       if (LCP(SA[L], SA[mid]) > Len)         l = mid;       else         r = mid - 1;     }     res += Solve(L, l, Len) + Solve(l + 1, R, Len);     return res;   }   void Run() {     srand(time(NULL));     gets(St);     N = strlen(St);     for (int i = 0; i < CharSet; ++i)       Ra[i] = (long long)rand() + (((long long)rand()) << 32LL);     for (int i = 0; i < N; ++i) X[0][i] = Ra[(int)St[i]];     for (int j = 0; j < LogMaxiN - 1; ++j)       for (int i = 0; i < N - (1 << j); ++i)         X[j + 1][i] = (X[j][i] * Ra[j + 1]) ^ (X[j][i + (1 << j)]);     for (int i = 0; i < N; ++i) SA[i] = i;     sort(SA, SA + N, Cmp);     cout << Solve(0, N - 1, 0) << endl;   }   }  // namespace Poor   int main() {     Poor::Run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, c, k;     cin >> a >> b >> c >> k;     if (k >= a + b + c - 3) {       cout << a * b * c << endl;     } else {       long long res = 1;       for (int x1 = 0; x1 < a; x1++) {         long long help = (-k + x1) / (-2);         for (int n = -1; n < 1; n++) {           long long x2 = min(min(help + n, b - 1), k - x1);           long long x3 = min(k - x1 - x2, c - 1);           res = max(res, (1 + x1) * (1 + x2) * (1 + x3));         }       }       for (int x1 = 0; x1 < a; x1++) {         long long help = (-k + x1) / (-2);         for (int n = -1; n < 1; n++) {           long long x2 = min(min(help + n, c - 1), k - x1);           long long x3 = min(k - x1 - x2, b - 1);           res = max(res, (1 + x1) * (1 + x2) * (1 + x3));         }       }       cout << res << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j;     scanf( %d , &n);     int arr[n];     for (i = 0; i < n; i++) scanf( %d , &arr[i]);     int t = 0;     int index = -1;     for (i = 0; i < n; i++)       if (arr[i] - arr[(i + 1) % n] > 0) {         t++;         index = i;       }     if (t > 1) {       cout <<  -1 n ;       return 0;     }     if (index == -1)       cout <<  0 n ;     else       cout << (n - index - 1) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       cout << x - !(x & 1) <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int x, y, z;   };   node q[200001];   int n, m;   bool ok[2][100001];   char s[100005];   int main(void) {     scanf( %d %d , &n, &m);     for (int i = 0; i < 2; ++i) {       scanf( %s , s + 1);       for (int j = 1; j <= n; ++j)         if (s[j] ==  - ) ok[i][j] = true;     }     bool flag = false;     q[1].x = 0;     q[1].y = 1;     q[1].z = 0;     int h = 1, e = 1;     ok[0][1] = false;     while (h <= e) {       node p = q[h];       ++h;       int i = p.x, j = p.y, k = p.z;       if (j <= k) continue;       if ((j + 1 > n) || (j + m > n)) {         flag = true;         break;       }       if (ok[i][j + 1]) {         ++e;         q[e].x = i;         q[e].y = j + 1;         q[e].z = k + 1;         ok[i][j + 1] = false;       }       if (ok[i ^ 1][j + m]) {         ++e;         q[e].x = i ^ 1;         q[e].y = j + m;         q[e].z = k + 1;         ok[i ^ 1][j + m] = false;       }       if (ok[i][j - 1]) {         ++e;         q[e].x = i;         q[e].y = j - 1;         q[e].z = k + 1;         ok[i][j - 1] = false;       }     }     if (flag)       printf( YES n );     else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, cnt[2000000];     scanf( %d , &n);     for (int i = 0; i < 2000000; ++i) cnt[i] = 0;     for (int i = 0; i < n; ++i) {       scanf( %d , &t);       cnt[t]++;     }     long long ans = 0;     for (int i = 0; i < 2000000 - 1; ++i) {       cnt[i + 1] += cnt[i] / 2;       if (cnt[i] % 2) ++ans;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math )   #pragma GCC target(         sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native )   using namespace std;   namespace _c {   const double pi = acos(-1.0);   namespace min {   const int i8 = -128;   const int i16 = -32768;   const int i = -2147483647 - 1;   const long long l = -9223372036854775807LL - 1;   }  // namespace min   namespace max {   const int i8 = 127;   const int i16 = 32767;   const int i = 2147483647;   const long long l = 9223372036854775807LL;   }  // namespace max   }  // namespace _c   namespace _f {   template <typename T>   inline const T gcd(T m, T n) {     while (n != 0) {       T t = m % n;       m = n;       n = t;     }     return m;   }   template <typename T>   inline const T max(const T &a, const T &b) {     return a > b ? a : b;   }   template <typename T>   inline const T min(const T &a, const T &b) {     return a < b ? a : b;   }   template <typename T>   inline const T abs(const T &a) {     return a > 0 ? a : -a;   }   template <typename T>   inline T pow(T a, T b) {     T res = 1;     while (b > 0) {       if (b & 1) {         res = res * a;       }       a = a * a;       b >>= 1;     }     return res;   }   template <typename T>   inline T pow(T a, T b, const T &m) {     a %= m;     T res = 1;     while (b > 0) {       if (b & 1) {         res = res * a % m;       }       a = a * a % m;       b >>= 1;     }     return res % m;   }   }  // namespace _f   namespace io {   template <typename T>   inline void read(T &t) {     register T res = 0, neg = 1;     char g = getchar();     for (; !isdigit(g); g = getchar()) {       if (g ==  - ) {         neg = -1;       }     }     for (; isdigit(g); g = getchar()) {       res = res * 10 + g -  0 ;     }     t = res * neg;   }   inline int in() {     register int T;     read(T);     return T;   }   inline long long in_ll() {     register long long T;     read(T);     return T;   }   }  // namespace io   int Ans, T(2), x[11000], y[11000], z[11000], r[11000], f[11000], F[11000],       s[1100000], b[11000], n, m, t[11000], c[11000], K, q[11000], Q[11000];   void In(int a, int b, int c, int d) {     x[T] = f[a];     y[T] = b;     z[T] = c;     r[T] = d;     f[a] = T++;     x[T] = f[b];     y[T] = a;     z[T] = 0;     r[T] = -d;     f[b] = T++;   }   int main() {     int i, j, k;     scanf( %d%d , &n, &K);     for (i = 0; i < n; i++) {       scanf( %d%d%d , s + i, t + i, c + i);       t[i] += s[i];       q[m++] = s[i];       q[m++] = t[i];     }     q[m++] = -1;     std::sort(q, q + m);     for (i = j = 1; i < m; i++)       if (q[i] != q[j - 1]) q[j++] = q[i];     m = j;     for (i = 0; i + 1 < m; i++) In(i, i + 1, K, 0);     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++)         if (q[j] == s[i]) break;       s[i] = j;       for (j = 0; j < m; j++)         if (q[j] == t[i]) break;       t[i] = j;       Q[i] = T;       In(s[i], t[i], 1, -c[i]);     }     s[0] = 0;     for (;;) {       memset(b, 127, sizeof(b));       b[0] = 0;       for (i = 0, j = 1; i < j; i++)         for (k = f[s[i]]; k; k = x[k])           if (z[k] && b[s[i]] + r[k] < b[y[k]]) {             b[y[k]] = b[s[i]] + r[k];             F[y[k]] = k;             s[j++] = y[k];           }       if (b[m - 1] == 2139062143) break;       j = 2139062143;       for (i = m - 1; i; i = y[F[i] ^ 1])         if (j > z[F[i]]) j = z[F[i]];       for (i = m - 1; i; i = y[F[i] ^ 1]) {         Ans += j * r[F[i]];         z[F[i]] -= j;         z[F[i] ^ 1] += j;       }     }     for (i = 0; i < n; i++)       if (z[Q[i]])         printf( 0  );       else         printf( 1  );     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   auto random_address = [] {     char *p = new char;     delete p;     return (uint64_t)p;   };   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count() *               (random_address() | 1));   const int INF = 1e9 + 5;   struct edge {     int a, b, color, index;   };   int N, M, K;   vector<edge> edges;   vector<vector<int>> color_count;   void set_color(edge &e, int color) {     color_count[e.a][e.color]--;     color_count[e.b][e.color]--;     e.color = color;     color_count[e.a][e.color]++;     color_count[e.b][e.color]++;   }   bool fix() {     vector<int> minimum(N, INF), maximum(N, 0);     for (int i = 0; i < N; i++)       for (int k = 0; k < K; k++) {         minimum[i] = min(minimum[i], color_count[i][k]);         maximum[i] = max(maximum[i], color_count[i][k]);       }     bool change = false;     for (edge &e : edges)       if ((maximum[e.a] - minimum[e.a] > 2 &&            color_count[e.a][e.color] == maximum[e.a]) ||           (maximum[e.b] - minimum[e.b] > 2 &&            color_count[e.b][e.color] == maximum[e.b])) {         set_color(e, rng() % K);         change = true;       }     return change;   }   int main() {     cin >> N >> M >> K;     color_count.assign(N, vector<int>(K, 0));     for (int i = 0; i < N; i++) {       int _;       cin >> _;     }     edges.resize(M);     for (int i = 0; i < M; i++) {       edge &e = edges[i];       cin >> e.a >> e.b;       e.a--;       e.b--;       e.index = i;       e.color = rng() % K;       color_count[e.a][e.color]++;       color_count[e.b][e.color]++;     }     bool bad;     do {       shuffle(edges.begin(), edges.end(), rng);       bad = false;       while (fix()) bad = true;     } while (bad);     vector<int> answers(M);     for (edge &e : edges) answers[e.index] = e.color + 1;     for (int i = 0; i < M; i++) cout << answers[i] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC diagnostic warning  -Wall    int main() {     int n;     scanf( %d , &n);     vector<vector<int> > sec(n);     for (typeof(n) i = (0); i < (n); i++) {       int k;       scanf( %d , &k);       sec[i].resize(k);       for (typeof(k) j = (0); j < (k); j++) scanf( %d , &sec[i][j]);       sort((sec[i]).begin(), (sec[i]).end());     }     int count = 0;     for (typeof(n) i = (0); i < (n); i++) {       int k = int(sec[i].size());       if (not k) continue;       int lasth = sec[i][0];       ;       int l = (i - 1 + n) % n;       int r = (i + 1) % n;       for (typeof(k) j = (1); j < (k); j++) {         int nl = lower_bound((sec[l]).begin(), (sec[l]).end(), sec[i][j]) -                  lower_bound((sec[l]).begin(), (sec[l]).end(), lasth);         int nr = lower_bound((sec[r]).begin(), (sec[r]).end(), sec[i][j]) -                  lower_bound((sec[r]).begin(), (sec[r]).end(), lasth);         if (nl != nr) count++;         lasth = sec[i][j];       }     }     printf( %d n , count);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, g;     cin >> n >> g;     vector<long long> v, ans;     map<long long, long long> m;     map<long long, long long>::iterator it;     for (int i = 0; i < n; i++) {       long long a;       cin >> a;       m[a]++;     }     for (it = m.begin(); it != m.end(); ++it) {       v.push_back(it->second);     }     long long s1 = 0;     for (int i = 0; i < v.size() - 1; i++) {       long long s = 0;       for (int j = i + 1; j < v.size(); j++) {         s += v[j];       }       s1 += s * v[i];     }     cout << s1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cout << fixed << setprecision(15);     int N, M, S, K;     cin >> N >> M >> S >> K;     vector<int> type(N);     for (int i = 0; i < N; i++) {       cin >> type[i];       --type[i];     }     vector<vector<int>> adj(N);     for (int i = 0; i < M; i++) {       int u, v;       cin >> u >> v;       adj[u - 1].push_back(v - 1);       adj[v - 1].push_back(u - 1);     }     vector<vector<int>> opt(N);     for (int tp = 0; tp < S; tp++) {       vector<int> dist(N, -1);       queue<pair<int, int>> q;       for (int i = 0; i < N; i++) {         if (type[i] == tp) {           q.push({i, 0});           dist[i] = 0;         }       }       while (!q.empty()) {         int loc = q.front().first;         int tot = q.front().second;         q.pop();         for (int nbr : adj[loc]) {           if (dist[nbr] != -1) continue;           dist[nbr] = tot + 1;           q.push({nbr, tot + 1});         }       };       ;       for (int i = 0; i < N; i++) {         opt[i].push_back(dist[i]);       }     }     for (int i = 0; i < N; i++) {       sort((opt[i]).begin(), (opt[i]).end());       int ans = 0;       for (int j = 0; j < K; j++) {         ans += opt[i][j];       }       cout << ans <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int list[n];     int i;     for (i = 0; i < n; i++) cin >> list[i];     int total = accumulate(list, list + n, 0);     n++;     int count = 0;     for (i = 1; i <= 5; i++) {       if ((total + i) % n != 1) {         count++;       }     }     cout << count;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     long long l;     long long r;     long long s;     node* ln;     node* rn;     void change(long long n, long long k) {       if (l == r)         s += k;       else {         if (n <= (l + r) / 2) {           if (ln == 0) {             ln = new node;             *ln = {l, (l + r) / 2, 0};           }           ln->change(n, k);         } else {           if (rn == 0) {             rn = new node;             *rn = {(l + r) / 2 + 1, r, 0};           }           rn->change(n, k);         }         s = 0;         if (ln != 0) s += ln->s;         if (rn != 0) s += rn->s;       }     }     long long query(long long a, long long b) {       if (a == l && b == r) return s;       if (b < l || a > r) return 0;       long long v = 0;       if (ln != 0) v += ln->query(a, min(b, (l + r) / 2));       if (rn != 0) v += rn->query(max(a, (l + r) / 2 + 1), b);       return v;     }   };   int main() {     cin.sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     unordered_map<int, node> m;     for (int i = 0; i < n; i++) {       long long a, b, c;       cin >> a >> b >> c;       if (!m.count(c)) m[c] = {1, 1 << 30, 0};       if (a == 1)         m[c].change(b, 1);       else if (a == 2)         m[c].change(b, -1);       else         cout << m[c].query(1, b) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long int x, y, k;       cin >> x >> y >> k;       long long int tot = y * k + k;       if (x >= tot) {         cout << 1 + k << endl;         continue;       } else if (x == 2) {         cout << tot - 1 + k << endl;       } else {         if ((tot - x) % (x - 1) != 0) {           cout << ((tot - x) / (x - 1)) + 2 + k << endl;         } else {           cout << ((tot - x) / (x - 1)) + 1 + k << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, c[1001], i, x, a, b;   int main() {     cin >> n >> k;     for (int x, i = 1; i <= n; ++i) {       cin >> x;       c[x]++;     }     for (i = 1; i <= k; ++i) {       a = a + c[i] / 2 * 2;       b = b + c[i] % 2;     }     cout << a + (b + 1) / 2;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e6;   const int maxv = 4e5;   const long long INF = 3e14 + 333;   struct Node {     int u, v, c;     void in() { scanf( %d%d%d , &u, &v, &c); }   } wo[maxn];   vector<int> G[maxv], st[maxv], ed[maxv];   int n, m;   int dfn = 0;   int d[maxv][2];   int wd[maxv];   void dfs(int v, int f) {     d[v][0] = dfn;     for (int i = 0; i < G[v].size(); i++) {       int u = G[v][i];       if (u == f) continue;       dfs(u, v);     }     for (int i = 0; i < st[v].size(); i++) wd[st[v][i]] = dfn++;     d[v][1] = dfn;   }   unsigned long long dp[maxn];   unsigned long long val[maxn], add[maxn];   void push(int o, int l, int r) {     if (r - l <= 1 || !add[o]) return;     val[((o << 1))] += add[o];     val[((o << 1) | 1)] += add[o];     add[((o << 1))] += add[o];     add[((o << 1) | 1)] += add[o];     add[o] = 0;   }   void change(int o, int p, int l, int r, unsigned long long x) {     push(o, l, r);     if (r - l <= 1) {       val[o] = x;       return;     }     if (p < ((r + l) >> 1))       change(((o << 1)), p, l, ((r + l) >> 1), x);     else       change(((o << 1) | 1), p, ((r + l) >> 1), r, x);     val[o] = min(val[((o << 1))], val[((o << 1) | 1)]);   }   void Add(int o, int a, int b, int l, int r, unsigned long long x) {     if (a >= r || b <= l) return;     push(o, l, r);     if (l >= a && r <= b) {       val[o] += x;       add[o] += x;       return;     }     Add(((o << 1)), a, b, l, ((r + l) >> 1), x);     Add(((o << 1) | 1), a, b, ((r + l) >> 1), r, x);     val[o] = min(val[((o << 1))], val[((o << 1) | 1)]);   }   unsigned long long rmq(int o, int a, int b, int l, int r) {     if (a >= r || b <= l) return INF;     push(o, l, r);     if (l >= a && r <= b) return val[o];     return min(rmq(((o << 1)), a, b, l, ((r + l) >> 1)),                rmq(((o << 1) | 1), a, b, ((r + l) >> 1), r));   }   unsigned long long ans = 0;   void DP(int v, int f) {     unsigned long long sum = 0;     for (int i = 0; i < G[v].size(); i++) {       int u = G[v][i];       if (u == f) continue;       DP(u, v);       sum += dp[u];     }     for (int i = 0; i < G[v].size(); i++) {       int u = G[v][i];       if (u == f) continue;       Add(1, d[u][0], d[u][1], 0, m, sum - dp[u]);     }     for (int i = 0; i < st[v].size(); i++) {       int w = st[v][i];       change(1, wd[w], 0, m, sum + wo[w].c);     }     for (int i = 0; i < ed[v].size(); i++) {       int w = ed[v][i];       change(1, wd[w], 0, m, INF);     }     if (v == 1) ans = sum;     dp[v] = rmq(1, d[v][0], d[v][1], 0, m);   }   int main() {     cin >> n >> m;     for (int i = 0; i < n - 1; i++) {       int x, y;       scanf( %d%d , &x, &y);       G[x].push_back(y);       G[y].push_back(x);     }     for (int i = 0; i < m; i++) {       wo[i].in();       st[wo[i].u].push_back(i);       ed[wo[i].v].push_back(i);     }     for (int i = 0; i < m; i++) change(1, i, 0, m, INF);     dfs(1, -1);     DP(1, -1);     if (ans >= INF)       cout << -1 << endl;     else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d;     cin >> a >> b >> c >> d;     int pa = a, pb = b, pc = c, pd = d;     a = pa;     b = pb;     c = pc;     d = pd;     vector<int> ans;     if (a > 0) {       ans.push_back(0);       a--;       while (a + b + c + d != 0) {         if (ans.back() == 0) {           if (b != 0) {             b--;             ans.push_back(1);           } else {             break;           }         } else if (ans.back() == 1) {           if (a != 0) {             ans.push_back(0);             a--;           } else if (c != 0) {             ans.push_back(2);             c--;           } else {             break;           }         } else if (ans.back() == 2) {           if (d != 0) {             ans.push_back(3);             d--;           } else if (b != 0) {             ans.push_back(1);             b--;           } else {             break;           }         } else {           if (c != 0) {             ans.push_back(2);             c--;           } else {             break;           }         }       }       if (a + b + c + d == 0) {         cout <<  YES  << endl;         for (int i = 0; i < ans.size(); i++) {           cout << ans[i] <<    ;         }         return 0;       }     }     ans.resize(0);     a = pa;     b = pb;     c = pc;     d = pd;     if (b >= 1) {       ans.push_back(1);       b--;       while (a + b + c + d != 0) {         if (ans.back() == 0) {           if (b != 0) {             b--;             ans.push_back(1);           } else {             break;           }         } else if (ans.back() == 1) {           if (a != 0) {             ans.push_back(0);             a--;           } else if (c != 0) {             ans.push_back(2);             c--;           } else {             break;           }         } else if (ans.back() == 2) {           if (d != 0) {             ans.push_back(3);             d--;           } else if (b != 0) {             ans.push_back(1);             b--;           } else {             break;           }         } else {           if (c != 0) {             ans.push_back(2);             c--;           } else {             break;           }         }       }       if (a + b + c + d == 0) {         cout <<  YES  << endl;         for (int i = 0; i < ans.size(); i++) {           cout << ans[i] <<    ;         }         return 0;       }     }     a = pa;     b = pb;     c = pc;     d = pd;     ans.resize(0);     if (c >= 1) {       ans.push_back(2);       c--;       while (a + b + c + d != 0) {         if (ans.back() == 0) {           if (b != 0) {             b--;             ans.push_back(1);           } else {             break;           }         } else if (ans.back() == 1) {           if (a != 0) {             ans.push_back(0);             a--;           } else if (c != 0) {             ans.push_back(2);             c--;           } else {             break;           }         } else if (ans.back() == 2) {           if (d != 0) {             ans.push_back(3);             d--;           } else if (b != 0) {             ans.push_back(1);             b--;           } else {             break;           }         } else {           if (c != 0) {             ans.push_back(2);             c--;           } else {             break;           }         }       }       if (a + b + c + d == 0) {         cout <<  YES  << endl;         for (int i = 0; i < ans.size(); i++) {           cout << ans[i] <<    ;         }         return 0;       }     }     a = pa;     b = pb;     c = pc;     d = pd;     ans.resize(0);     if (d >= 1) {       ans.push_back(3);       d--;       while (a + b + c + d != 0) {         if (ans.back() == 0) {           if (b != 0) {             b--;             ans.push_back(1);           } else {             break;           }         } else if (ans.back() == 1) {           if (a != 0) {             ans.push_back(0);             a--;           } else if (c != 0) {             ans.push_back(2);             c--;           } else {             break;           }         } else if (ans.back() == 2) {           if (d != 0) {             ans.push_back(3);             d--;           } else if (b != 0) {             ans.push_back(1);             b--;           } else {             break;           }         } else {           if (c != 0) {             ans.push_back(2);             c--;           } else {             break;           }         }       }       if (a + b + c + d == 0) {         cout <<  YES  << endl;         for (int i = 0; i < ans.size(); i++) {           cout << ans[i] <<    ;         }         return 0;       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-12;   int main() {     int n;     double r, v, T;     scanf( %d%lf%lf , &n, &r, &v);     T = 2 * acos(-1) * r / v;     for (int i = 0; i < n; i++) {       double s, f, tim, tot = 0;       scanf( %lf%lf , &s, &f);       tim = (f - s) / v;       tot = T * floor(tim / T);       tim -= tot;       double lef = 0.0, rig = T;       for (int j = 0; j < 100; j++) {         double t = (lef + rig) / 2.0;         double g = t + (2.0 * r / v) * sin(v * t / (2.0 * r));         if (g - tim >= -eps)           rig = t;         else           lef = t;       }       tot += lef;       printf( %.12lf n , tot);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, k;     cin >> n >> k;     int ans = n;     if (k >= n) {       cout << 1;     } else {       for (int i = 2; i <= sqrt(n); i++) {         if (n % i == 0) {           if (i <= k) {             ans = min(ans, n / i);           }           if (n / i <= k) {             ans = min(ans, i);           }         }       }       cout << ans;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int test;     cin >> test;     for (int i = 1; i <= test; i++) {       solve();       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   char c[1010];   int main() {     scanf( %d , &n);     scanf( %s , c + 1);     c[0] =  0 , c[n + 1] =  0 ;     if (n == 1) {       if (c[1] ==  0 ) return 0 * puts( No );       return 0 * puts( Yes );     }     for (int i = 1; i < n; i++) {       if (c[i] ==  1  && c[i + 1] ==  1 ) return 0 * puts( No );     }     for (int i = 1; i <= n; i++) {       if (c[i - 1] ==  0  && c[i] ==  0  && c[i + 1] ==  0 )         return 0 * puts( No );     }     puts( Yes );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, x;       cin >> n >> x;       int arr[n];       int o, e;       o = e = 0;       int i = 0;       for (int j = 0; j < 10; j++) {       }       for (int j = 0; j < 10; j++) {       }       for (int j = 0; j < 10; j++) {       }       while (i < n) {         int x;         cin >> x;         if (x % 2 == 0) {           e++;         } else           o++;         i++;       }       if (o == 0)         cout <<  No  << endl;       else {         bool pos = false;         i = 1;         while (i <= o) {           if (i > x) break;           if ((x - i) <= e) {             pos = true;             break;           }           i = i + 2;         }         if (!pos)           cout <<  No  << endl;         else           cout <<  Yes  << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, mx = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a;       if (a > mx) mx = a;     }     if (mx - 25 > 0)       cout << mx - 25 << endl;     else       cout << 0 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long c, w, v, a, l, pages, days = 1;     cin >> c >> v >> w >> a >> l;     pages = v;     while (pages < c) {       v += a;       if (v > w) v = w;       pages = pages - l + v;       days++;     }     cout << days;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, x, y;   struct node {     int L, R, e;     long long int Lsum, Rsum, Ls, Rs;     int mid() { return (L + R) / 2; }   } a[200005 * 4];   void BuildTree(int r, int L, int R) {     a[r].L = L;     a[r].R = R;     a[r].e = 0;     a[r].Lsum = 0;     a[r].Rsum = 0;     a[r].Ls = 0;     a[r].Rs = 0;     if (L == R) return;     BuildTree(r << 1 | 1, L, a[r].mid());     BuildTree(r << 1, a[r].mid() + 1, R);     a[r].Lsum = a[r << 1 | 1].Lsum + a[r << 1].Lsum;     a[r].Rsum = a[r << 1 | 1].Rsum + a[r << 1].Rsum;     a[r].Ls = a[r << 1 | 1].Ls + a[r << 1].Ls;     a[r].Rs = a[r << 1 | 1].Rs + a[r << 1].Rs;   }   void Update(int r, int L, int v) {     if (a[r].L == a[r].R && a[r].L == L) {       int kk = a[r].e;       a[r].e += v;       if (a[r].e >= y && kk < y) {         a[r].Lsum++;         a[r].Ls -= kk;       }       if (a[r].e >= x && kk < x) {         a[r].Rs -= kk;         a[r].Rsum++;       }       if (a[r].e < y) a[r].Ls = a[r].e;       if (a[r].e < x) a[r].Rs = a[r].e;       return;     }     if (L > a[r].mid())       Update(r << 1, L, v);     else       Update(r << 1 | 1, L, v);     a[r].Lsum = a[r << 1 | 1].Lsum + a[r << 1].Lsum;     a[r].Rsum = a[r << 1 | 1].Rsum + a[r << 1].Rsum;     a[r].Ls = a[r << 1 | 1].Ls + a[r << 1].Ls;     a[r].Rs = a[r << 1 | 1].Rs + a[r << 1].Rs;   }   long long int Qurry(int r, int L, int R, int b) {     if (L > R) return 0;     if (a[r].L == L && a[r].R == R) {       if (b == 1)         return a[r].Lsum * y + a[r].Ls;       else if (b == 2)         return a[r].Rsum * x + a[r].Rs;     }     if (L > a[r].mid())       return Qurry(r << 1, L, R, b);     else if (R <= a[r].mid())       return Qurry(r << 1 | 1, L, R, b);     else {       long long a1 = Qurry(r << 1 | 1, L, a[r].mid(), b);       long long a2 = Qurry(r << 1, a[r].mid() + 1, R, b);       return a1 + a2;     }   }   int main() {     int q;     while (scanf( %d , &n) != EOF) {       memset(a, 0, sizeof(0));       int u, v;       BuildTree(1, 1, n);       scanf( %d %d %d %d , &k, &x, &y, &q);       while (q--) {         int kk;         scanf( %d , &kk);         if (kk == 1) {           scanf( %d %d , &u, &v);           Update(1, u, v);         } else {           scanf( %d , &u);           long long int sum1 = Qurry(1, 1, u - 1, 1);           long long int sum2 = Qurry(1, u + k, n, 2);           printf( %lld n , sum1 + sum2);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int MOD = 1000000007;   const long long BIG = 1446803456761533460LL;   const int Big = 336860180;   const long long int INF = LONG_LONG_MAX;   const long long int adj4[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};   const long long int adj8[8][2] = {{0, 1},   {0, -1}, {1, 0},  {-1, 0},                                     {-1, -1}, {1, -1}, {-1, 1}, {1, 1}};   long long int clk_ar[10];   long long int gcd(long long int a, long long int b) {     return b == 0 ? a : gcd(b, a % b);   }   long long int powMod(long long int a, long long int b) {     long long int n = 1;     long long int p = a;     while (b > 0) {       if (b % 2 == 1) {         n *= p;         n %= MOD;       }       p *= p;       p %= MOD;       b /= 2;     }     return n;   }   long long int modularInverse(long long int a) { return powMod(a, MOD - 2); }   stringstream sss;   const long long int maxn = 150010;   const long long int maxm = 310;   long long int dp[2][maxn];   long long int ts[maxm];   long long int ai[maxm];   void MAIN() {     long long int n, m, V;     cin >> n >> m >> V;     long long int sb = 0;     for (long long int i = 0; i < (m); ++i) {       long long int b;       cin >> ai[i + 1] >> b >> ts[i + 1];       --ai[i + 1];       sb += b;     }     for (long long int i = (1); i < (m + 1); ++i) {       long long int d = (ts[i] - ts[i - 1]) * V;       deque<long long int> q;       for (long long int j = 0; j < (min(d, n)); ++j) {         while (!q.empty() && dp[i & 1 ^ 1][j] >= dp[i & 1 ^ 1][q.back()]) {           q.pop_back();         }         q.push_back(j);       }       for (long long int j = 0; j < (n); ++j) {         if (j + d < n) {           while (!q.empty() && dp[i & 1 ^ 1][j + d] >= dp[i & 1 ^ 1][q.back()]) {             q.pop_back();           }           q.push_back(j + d);         }         dp[i & 1][j] = dp[i & 1 ^ 1][q.front()] - abs(j - ai[i]);         if (q.front() == j - d) {           q.pop_front();         }       }     }     cout << (sb + *max_element(dp[m & 1], dp[m & 1] + n)) <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(10);     sss << R (   50 3 1   49 1 1   26 1 4   6 1 10       ) ;     MAIN();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int* x = new int[2 * n];     int odd = 0;     int even = n;     int len = n - 1;     for (int len = n - 1, i = 1; len > 0; len--, i++)       if (i % 2 == 1) {         x[odd] = i;         x[odd + len] = i;         odd++;       } else {         x[even] = i;         x[even + len] = i;         even++;       }     x[2 * n - 1] = n;     if (n % 2 == 0)       x[even] = n;     else       x[odd] = n;     int s = 0;     for (int i = 0; i < 2 * n; i++) printf( %d  , x[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool issorted(long long int *arr, int n) {     int flag = 0;     for (int i = 1; i < n; i++) {       if (arr[i - 1] > arr[i]) {         flag = 1;         break;       }     }     if (flag == 0) return true;     flag = 0;     for (int i = n - 2; i >= 0; i--) {       if (arr[i + 1] > arr[i]) {         flag = 1;         break;       }     }     if (flag == 0) return true;     return false;   }   int main(void) {     int n;     cin >> n;     long long int arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     long long int flag = 0;     for (int i = 1; i < n; i++) {       if (arr[i] != arr[i - 1]) {         flag = 1;         break;       }     }     if (flag == 0 || n <= 2)       cout <<  -1  << endl;     else if (n == 3 && arr[0] == arr[2])       cout <<  -1  << endl;     else {       flag = 0;       for (int i = 1; i < n; i++) {         if (arr[i] != arr[i - 1]) {           long long int swap = arr[i];           arr[i] = arr[i - 1];           arr[i - 1] = swap;           if (!issorted(arr, n)) {             cout << i + 1 <<     << i << endl;             break;           } else {             swap = arr[i];             arr[i] = arr[i - 1];             arr[i - 1] = swap;           }         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int MDA[10000010];   int MDB[10000010];   int main() {     long long a, b, m;     int i;     cin >> a >> b >> m;     for (i = 0; i < (min(m, a + 1)); i++) {       MDA[i] = (i * 1000000000) % m;     }     for (i = 0; i < (min(m, b + 1)); i++) {       MDB[(i) % m] = 1;     }     int ans = 2, mov;     for (i = 0; i < (min(m, a + 1)); i++) {       if (MDB[(m - MDA[i]) % m] == 0) {         ans = 1;         mov = i;         break;       }     }     cout << ans;     if (ans == 1) {       cout <<    ;       char str[100];       sprintf(str,  %ld , mov);       string s = str;       while (s.size() != 9) s =  0  + s;       cout << s;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   int main() {     int n, k;     cin >> n >> k;     if (k / n > 2)       cout <<  0 n ;     else       cout << n - (k % n) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   int num[maxn];   map<int, int> mp;   int sum[maxn];   int main() {     int n, i, j, k;     cin >> n;     for (i = 1; i <= n; i++) cin >> num[i], sum[i] = sum[i - 1] + num[i];     int s = 0;     long long ans = 0;     for (i = 1; i < n; i++) {       int tmp = sum[n] - sum[i];       if (sum[i] == 2 * tmp) {         ans += mp[tmp];       }       mp[sum[i]]++;     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int MOD = 1e9 + 7;   int a[100001], n, num, siz = 0, sq;   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     vector<int> kill(n, 1);     stack<int> s;     s.push(0);     kill[0] = 1000000000;     for (int i = 1; i < n; i++) {       while (!s.empty() && a[i] > a[s.top()]) {         kill[i] = max(kill[s.top()] + 1, kill[i]);         s.pop();       }       s.push(i);     }     num = 0;     for (int i = 0; i < n; i++)       if (kill[i] < 1000000000) num = max(num, kill[i]);     cout << num;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   int t, n, m, sum;   int fa[1000010], sz[1000010];   vector<int> vec[1000010];   int find(int x) {     if (x == fa[x])       return x;     else       return fa[x] = find(fa[x]);   }   int main() {     ios_base::sync_with_stdio(false);     t = 1;     while (t--) {       cin >> n >> m;       for (int i = 1; i <= m; ++i) {         vec[i].clear();         sz[i] = 0;         fa[n + i] = n + i;       }       for (int i = 1; i <= n; ++i) {         int x;         cin >> x;         sz[x + n]++;         vec[x + n].push_back(i);         fa[i] = x + n;       }       sum = 0;       for (int i = 2; i <= n; ++i) {         if (find(i) == find(i - 1)) {           sum++;         }       }       cout << n - sum - 1 <<   n ;       for (int i = 1; i <= m - 1; ++i) {         int x, y;         cin >> x >> y;         int fx = find(x + n), fy = find(y + n);         if (sz[fx] < sz[fy]) {           for (int j = 0; j < vec[fx].size(); ++j) {             if ((vec[fx][j] > 1 && find(vec[fx][j] - 1) == fy)) sum++;             if ((vec[fx][j] < n && find(vec[fx][j] + 1) == fy)) sum++;             vec[fy].push_back(vec[fx][j]);             sz[fy]++;           }           sz[fx] = 0;           fa[fx] = fy;         } else {           for (int j = 0; j < vec[fy].size(); ++j) {             if ((vec[fy][j] > 1 && find(vec[fy][j] - 1) == fx)) sum++;             if ((vec[fy][j] < n && find(vec[fy][j] + 1) == fx)) sum++;             vec[fx].push_back(vec[fy][j]);             sz[fx]++;           }           sz[fy] = 0;           fa[fy] = fx;         }         cout << n - sum - 1 <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using std ::vector;   template <typename Tp>   Tp Max(const Tp &a, const Tp &b) {     return a > b ? a : b;   }   template <typename Tp>   Tp Min(const Tp &a, const Tp &b) {     return a < b ? a : b;   }   template <typename Tp>   Tp Abs(const Tp &a) {     return a > 0 ? a : -a;   }   template <typename Tp>   void Read(Tp &x) {     Tp in = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       in = in * 10 + ch -  0 ;       ch = getchar();     }     x = in * f;   }   const int SN = 200000 + 10;   vector<int> G[SN];   int a[SN], b[SN], c[SN], min[SN], n;   int res0[SN], res1[SN];   long long ans;   void pre(int u, int fa) {     for (auto v : G[u])       if (v != fa) min[v] = Min(min[v], min[u]);     for (auto v : G[u])       if (v != fa) pre(v, u);   }   void Dfs(int u, int fa) {     if (b[u] != c[u])       if (b[u] == 0)         res0[u]++;       else         res1[u]++;     for (auto v : G[u])       if (v != fa) Dfs(v, u), res1[u] += res1[v], res0[u] += res0[v];     int K = Min(res0[u], res1[u]);     ans += 2LL * K * min[u];     res0[u] -= K, res1[u] -= K;   }   int main(int argc, const char *argv[]) {     Read(n);     for (int i = 1; i <= n; i++)       Read(a[i]), Read(b[i]), Read(c[i]), min[i] = a[i];     int u, v;     for (int i = 1; i < n; i++) {       Read(u), Read(v);       G[u].push_back(v);       G[v].push_back(u);     }     u = 0, v = 0;     for (int i = 1; i <= n; i++) {       if (b[i] == 0) u++;       if (c[i] == 0) v++;     }     if (u != v) {       printf( -1 n );       return 0;     }     pre(1, 0);     Dfs(1, 0);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   const int MAXN = (int)3e5 + 3;   const int infint = (int)1e9 + 3;   const long long inf = (long long)2e18;   struct node {     int minf, tedf, mimm, tmimm, mipm, tmipm, min, max, lazymax, lazymin;     node() {       minf = infint, tedf = 0;       mimm = infint, tmimm = 0;       mipm = infint, tmipm = 0;       min = infint, max = -infint;       lazymax = -1, lazymin = -1;     }   } seg[4 * MAXN];   void updmax(int node, int st, int en, int x) {     seg[node].max = x;     seg[node].mipm = st + seg[node].max, seg[node].tmipm = 1;     seg[node].minf = seg[node].mimm + seg[node].max,     seg[node].tedf = seg[node].tmimm;     seg[node].lazymax = x;     return;   }   void updmin(int node, int st, int en, int x) {     seg[node].min = x;     seg[node].mimm = st - seg[node].min, seg[node].tmimm = 1;     seg[node].minf = seg[node].mipm - seg[node].min,     seg[node].tedf = seg[node].tmipm;     seg[node].lazymin = x;   }   void shift(int node, int st, int en) {     int mid = (st + en) >> 1;     if (seg[node].lazymax != -1)       updmax(node << 1, st, mid, seg[node].lazymax),           updmax(node << 1 | 1, mid, en, seg[node].lazymax);     if (seg[node].lazymin != -1)       updmin(node << 1, st, mid, seg[node].lazymin),           updmin(node << 1 | 1, mid, en, seg[node].lazymin);     seg[node].lazymax = seg[node].lazymin = -1;   }   node merge(node a, node b) {     node c;     c.min = min(a.min, b.min);     c.max = max(a.max, b.max);     c.minf = a.minf, c.tedf = a.tedf;     if (b.minf < c.minf)       c.minf = b.minf, c.tedf = b.tedf;     else if (b.minf == c.minf)       c.tedf += b.tedf;     c.mimm = a.mimm, c.tmimm = a.tmimm;     if (b.mimm < c.mimm)       c.mimm = b.mimm, c.tmimm = b.tmimm;     else if (b.mimm == c.mimm)       c.tmimm += b.tmimm;     c.mipm = a.mipm, c.tmipm = a.tmipm;     if (b.mipm < c.mipm)       c.mipm = b.mipm, c.tmipm = b.tmipm;     else if (b.mipm == c.mipm)       c.tmipm += b.tmipm;     c.lazymax = -1, c.lazymin = -1;     return c;   }   void updatemax(int node, int st, int en, int l, int r, int x) {     if (l >= en || st >= r) return;     if (l <= st && en <= r) {       updmax(node, st, en, x);       return;     }     int mid = (st + en) >> 1;     shift(node, st, en);     updatemax(node << 1, st, mid, l, r, x);     updatemax(node << 1 | 1, mid, en, l, r, x);     seg[node] = merge(seg[node << 1], seg[node << 1 | 1]);   }   void updatemin(int node, int st, int en, int l, int r, int x) {     if (l >= en || st >= r) return;     if (l <= st && en <= r) {       updmin(node, st, en, x);       return;     }     int mid = (st + en) >> 1;     shift(node, st, en);     updatemin(node << 1, st, mid, l, r, x);     updatemin(node << 1 | 1, mid, en, l, r, x);     seg[node] = merge(seg[node << 1], seg[node << 1 | 1]);   }   node emp;   node get(int node, int st, int en, int l, int r) {     if (l >= en || st >= r) {       emp.minf = infint, emp.tedf = 0;       emp.mimm = infint, emp.tmimm = 0;       emp.mipm = infint, emp.tmipm = 0;       emp.min = infint, emp.max = -infint;       emp.lazymax = -1, emp.lazymin = -1;       return emp;     }     if (l <= st && en <= r) return seg[node];     int mid = (st + en) >> 1;     shift(node, st, en);     return merge(get(node << 1, st, mid, l, r),                  get(node << 1 | 1, mid, en, l, r));   }   int n, a[MAXN], s[MAXN], g[MAXN];   int zero[MAXN], oc[MAXN], prv[MAXN];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < 4 * MAXN; i++) seg[i] = node();     for (int i = 0; i < n; i++) {       cin >> a[i];       a[i]--;     }     for (int i = 0; i < n; i++)       if (a[i] == 0)         zero[i] = i;       else if (i == 0)         zero[i] = -1;       else         zero[i] = zero[i - 1];     memset(oc, -1, sizeof oc);     for (int i = 0; i < n; i++) {       prv[i] = oc[a[i]], oc[a[i]] = i;       if (i) prv[i] = max(prv[i], prv[i - 1]);     }     for (int i = 0; i < n; i++) prv[i]++;     stack<int> S;     for (int i = 0; i < n; i++) {       while (!S.empty() && a[S.top()] > a[i]) S.pop();       if (S.size())         s[i] = S.top();       else         s[i] = -1;       S.push(i);     }     while (S.size()) S.pop();     for (int i = 0; i < n; i++) {       while (!S.empty() && a[S.top()] < a[i]) S.pop();       if (S.size())         g[i] = S.top();       else         g[i] = -1;       S.push(i);     }     long long ans = 0;     for (int i = 0; i < n; i++) {       updatemin(1, 0, n, s[i] + 1, i + 1, a[i]);       updatemax(1, 0, n, g[i] + 1, i + 1, a[i]);       if (prv[i] <= zero[i]) {         node cur = get(1, 0, n, prv[i], zero[i] + 1);         if (cur.minf == i) ans += cur.tedf;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000010;   const int s = 1000000;   int n;   int b[maxn];   int p[maxn];   int c[maxn];   vector<int> ans;   int main() {     scanf( %d , &n);     int t;     for (int i = 0; i < n; ++i) {       scanf( %d , &t);       b[t] = 1;       p[i] = t;     }     int l = 1;     for (int i = 0; i < n; ++i) {       if (c[p[i]] == 0) {         if (b[s - p[i] + 1] == 0) {           ans.push_back(s - p[i] + 1);           b[s - p[i] + 1] = 1;         } else {           while (b[l] || b[s - l + 1]) {             l++;           }           ans.push_back(l);           b[l] = 1;           ans.push_back(s - l + 1);           b[s - l + 1] = 1;           c[s - p[i] + 1] = 1;         }       }     }     printf( %ld n , ans.size());     for (int i = 0; i < ans.size(); ++i) {       if (i) printf(   );       printf( %d , ans[i]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const int MOD = 1e9 + 7;   const int N = 0;   string s;   long long solve(string s) {     int n = s.length();     long long ans = 1988;     for (auto i = (n - 1); i >= (4); i--) {       long long mul = 1, add = 0;       for (auto j = (i); j < (n); j++) {         mul = 10 * mul;         add = 10 * add + s[j] -  0 ;       }       long long nx = max(mul + ans - add, 0LL) / mul;       ans = nx * mul + add;     }     return ans;   }   int main() {     int test;     cin >> test;     while (test--) {       cin >> s;       cout << solve(s) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   string name[105], body[105];   int n;   string s;   int d[105];   map<string, int> macro_id;   int add(string& s, int& ptr);   void go(int k);   int un(string& s, int& ptr) {     if (s[ptr] ==  ( ) {       ptr++;       int r = add(s, ptr);       if (r & 2) r ^= 2;       if (r & 4) r ^= 4;       ptr++;       return r;     }     string id =   ;     while (ptr < s.size() && (isalpha(s[ptr]) || isdigit(s[ptr]))) {       id += s[ptr++];     }     if (macro_id.count(id)) {       int k = macro_id[id];       go(k);       return d[k];     } else {       return 0;     }   }   int mul(string& s, int& ptr) {     int ret = un(s, ptr);     int cnt = 1;     char last_op =  * ;     bool f = true;     while (ptr < s.size() && (s[ptr] ==  *  || s[ptr] ==  / )) {       if (f && (ret & 2)) {         ret |= 1;       }       f = false;       last_op = s[ptr];       ptr++;       int next = un(s, ptr);       if (next & 4) ret |= 4;       if (next & 1) ret |= 1;       if (next & 2) ret |= 1;       if (last_op ==  /  && (next & 4)) ret |= 1;       cnt++;     }     if (cnt > 1) ret |= 4;     return ret;   }   int add(string& s, int& ptr) {     int ret = mul(s, ptr);     int cnt = 1;     char last_op =  + ;     while (ptr < s.size() && (s[ptr] ==  +  || s[ptr] ==  - )) {       last_op = s[ptr];       ptr++;       int next = mul(s, ptr);       if (next & 2) ret |= 2;       if (next & 1) ret |= 1;       if (last_op ==  -  && (next & 2)) ret |= 1;       cnt++;     }     if (cnt > 1) {       if (ret & 4) ret ^= 4;       ret |= 2;     }     return ret;   }   void go(int k) {     if (d[k] != -1) {       return;     }     string str = body[k];     int ptr = 0;     int code = add(str, ptr);     d[k] = code;   }   int main() {     scanf( %d n , &n);     for (int i = 0; i < int(n); i++) {       getline(cin, s);       while (s[0] ==    ) s.erase(0, 1);       s.erase(0, 1);       while (s[0] ==    ) s.erase(0, 1);       s.erase(0, 7);       while (s[0] ==    ) s.erase(0, 1);       int p = s.find(   );       name[i] = s.substr(0, p);       s.erase(0, p + 1);       for (int j = 0; j < int(s.size()); j++) {         if (s[j] !=    ) {           body[i] += s[j];         }       }       macro_id[name[i]] = i;     }     getline(cin, s);     for (int j = 0; j < int(s.size()); j++) {       if (s[j] !=    ) {         body[n] += s[j];       }     }     for (int i = 0; i < int(n + 1); i++) {       d[i] = -1;     }     go(n);     if (d[n] & 1) {       printf( Suspicious n );     } else {       printf( OK n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NMAX = 200005;   int n;   char str[NMAX];   int in, allin;   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     cin >> str;     for (int i = 0; i < n; ++i)       if (str[i] ==  A )         ++allin;       else if (str[i] ==  I )         ++in;     if (!in)       cout << allin <<   n ;     else       cout << (in == 1 ? 1 : 0) <<   n ;     return 0;   }


#include <bits/stdc++.h>   int a, b, n;   long long ans;   int chk[10000010];   int np, pri[10000010];   int lis[10000010], mon[10000010];   void go(int now, int poi) {     lis[now] = 1;     for (int i = poi; i < np; ++i) {       long long t = (long long)now * pri[i];       if (t > n) break;       go(t, i + 1);     }   }   void solve() {     for (int i = 2; i * i <= n; ++i)       if (chk[i] == 0)         for (int j = i * i; j <= n; j += i) chk[j] = 1;     for (int i = 2; i <= n; ++i)       if (chk[i] == 0) {         pri[np] = i;         ++np;       }     go(1, 0);     for (int i = n, j = -1; i >= 1; --i) {       if (lis[i] == 1) {         lis[i] = j;         j = i;       }     }     for (int i = 1; i != -1; i = lis[i]) {       for (int j = 1;; ++j) {         int t = j * j * i;         if (j * j * i > n) break;         mon[t] = i;       }     }   }   int main(void) {     scanf( %d%d , &a, &n);     b = a + n - 1;     n = b;     solve();     for (int i = a; i <= b; ++i) ans += mon[i];     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3009;   int box[N], kk;   struct node {     int t, next;   } e[N << 1];   int n;   void add(int s, int t) {     e[kk].t = t, e[kk].next = box[s];     box[s] = kk++;   }   int tot;   void pre_dfs(int r, int fa) {     for (int i = box[r]; i + 1; i = e[i].next)       if (e[i].t != fa) {         pre_dfs(e[i].t, r);         tot += i & 1;       }   }   int cut;   void dfs(int r, int fa, int now) {     cut = max(now, cut);     for (int i = box[r]; i + 1; i = e[i].next)       if (e[i].t != fa) {         if (i & 1)           dfs(e[i].t, r, now + 1);         else           dfs(e[i].t, r, max(now - 1, 0));       }   }   int main() {     memset(box, -1, sizeof(box));     cin >> n;     for (int i = 1; i < n; i++) {       int s, t;       cin >> s >> t;       add(s, t);       add(t, s);     }     int ans = N;     for (int i = 1; i <= n; i++) {       tot = 0;       pre_dfs(i, i);       cut = 0;       dfs(i, i, 0);       ans = min(tot - cut, ans);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e3 + 5;   int a[maxn], n, x;   int main() {     int k;     cin >> k;     while (k--) {       cin >> n >> x;       int sum = 0;       bool f = 1, f1 = 0;       for (int i = 1; i <= n; i++) {         cin >> a[i];         sum += a[i];         if (a[i] != x) f = 0;         if (a[i] == x) f1 = 1;       }       if (f == 1)         cout << 0 << endl;       else if (sum == n * x || f1 == 1)         cout << 1 << endl;       else         cout << 2 << endl;     }     return 0;   }


#include<bits/stdc++.h>      typedef long long ll;   typedef long double ld;   using namespace std;   mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());   #define ii for(int i=1;i<=n;++i)   #define ji for(int j=1;j<=n;++j)   #define jj for(int j=1;j<=m;++j)   #define ij for(int i=1;i<=m;++i)   #define all(x) x.begin(),x.end()   #define al(x) x+1,x+1+n   #define asd cout<< ok <<endl;   #define vi vector<int>   #define vvi vector<vector<int>>   #define vl vector<ll>   #define vii vector<pair<int,int>>   #define pc(x) __builtin_popcount(x)   #define pb push_back      vector<int> a[200005];   vector<pair<int,int>> r[200005];   int cnt[200005];   inline int read() {       char c=getchar();int x=0,f=1;       while(c< 0 ||c> 9 ) {if(c== - ) f=-1;c=getchar();}       while(c>= 0 &&c<= 9 )x=x*10+c- 0 ,c=getchar();       return x*f;   }   int main() {       int t = read();       while(t--) {           int n = read();           int sz = 0;           for(int i=1;i<=n;++i) a[i].clear();           vector<int> aa;           for(int i=1;i<=n;++i) {               int x = read();               sz += x;               while(x--) {                   int y = read();                   a[i].push_back(y);                   aa.push_back(y);               }           }           sort(aa.begin(), aa.end());           aa.resize(unique(aa.begin(), aa.end()) - aa.begin());           auto f = [&](int x) {               return lower_bound(aa.begin(), aa.end(), x) - aa.begin() + 1;           };           for(int i=1;i<=n;++i) {               for(int &j:a[i]) j=f(j);               sort(all(a[i]));           }           int sq = pow(sz, 0.4), ok = 0;           for(int i=1;i<=n;++i) {               if(a[i].size() > sq) {                   for(int j:a[i]) cnt[j]++;                   for(int j=1;j<=n;++j) {                       if(i==j) continue;                       int cnt2=0;                       for(int k:a[j]) cnt2+=cnt[k];                       if(cnt2>1) {                           printf( %d %d n , i, j);                           ok=1;                           break;                       }                   }                   for(int j:a[i]) cnt[j]--;               } else {                   for(int j=0;j<a[i].size();++j) {                       for(int k=j+1;k<a[i].size();++k) {                           r[a[i][j]].push_back({a[i][k], i});                       }                   }               }               if(ok) break;           }           if(!ok) {               for(int i=1;i<=aa.size();++i) {                   sort(all(r[i]));                   for(int j=1;j<r[i].size();++j) {                       if(r[i][j].first == r[i][j-1].first) {                           ok = 1;                           printf( %d %d n , r[i][j].second, r[i][j-1].second);                           break;                       }                   }                   if(ok) break;               }           }           for(int i=1;i<=aa.size();++i) r[i].clear();           if(!ok) puts( -1 );       }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1010;   int c1, c2;   char str[maxn];   int main() {     scanf( %s , str);     int len = int(strlen(str));     for (int i = 0; i < len; i++) {       int t = str[i] -  0 ;       if (t == 0) {         if (!c1) {           puts( 1 1 );         } else           puts( 3 1 );         c1 ^= 1;       } else {         if (!c2) {           puts( 4 3 );         } else           puts( 4 1 );         c2 ^= 1;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long labs(long long a) { return a < 0 ? (-a) : a; }   long long max(long long a, long long b) { return a > b ? a : b; }   long long min(long long a, long long b) { return a < b ? a : b; }   const int MAXN = 1005;   const int UNDEF = -1;   const int IMPOS = INT_MAX - 2;   char f[MAXN][MAXN];   int dph[MAXN], dpv[MAXN];   int n, m;   int RecV(int i);   int RecH(int j) {     if (dph[j] != UNDEF) return dph[j];     dph[j] = IMPOS;     for (int i = 0; i < n; i++) {       if (f[i][j] ==  # ) {         dph[j] = min(dph[j], RecV(i) + 1);       }     }     return dph[j];   }   int RecV(int i) {     if (dpv[i] != UNDEF) return dpv[i];     dpv[i] = IMPOS;     for (int j = 0; j < m; j++) {       if (f[i][j] ==  # ) {         dpv[i] = min(dpv[i], RecH(j) + 1);       }     }     return dpv[i];   }   int main() {     cin >> n >> m;     fill(dph, dph + MAXN, UNDEF);     fill(dpv, dpv + MAXN, UNDEF);     for (int(i) = 0; (i) < (n); (i)++) {       cin >> f[i];     }     dpv[n - 1] = 0;     int res = RecV(0);     if (res == IMPOS) {       res = -1;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[503400], b[477574], c[534567], d, e, i, j, r, m, y, k, l, n, s, z,       x, t, tt;   string p[3456], q, qq;   map<long long, long long> zz;   int main() {     cin >> n >> m;     for (i = 1; i <= n; i++) cin >> p[i];     cin >> x;     q = p[x];     a[x] = 1;     t = q.size();     for (i = 1; i < m; i++) {       cin >> y;       a[y] = 1;       if (p[y].size() != t) {         cout <<  No ;         return 0;       }       for (j = 0; j < t; j++) {         if (q[j] ==  ? ) continue;         if (p[y][j] != q[j]) q[j] =  ? ;       }     }     for (i = 1; i <= n; i++) {       if (a[i] == 1) continue;       if (p[i].size() != t) continue;       x = 0;       for (j = 0; j < t; j++) {         if (q[j] ==  ? ) continue;         if (q[j] != p[i][j]) x = 1;       }       if (x == 0) {         cout <<  No ;         return 0;       }     }     cout <<  Yes  << endl << q;   }