#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   const int maxk = 17;   struct TNode {     int L, R;     int lc, rc;     int sum;     bool sw;     TNode(int L = 0, int R = 0) : L(L), R(R), lc(-1), rc(-1), sum(0), sw(false) {}   };   TNode t[3 * maxn];   int tc = 0;   int build(int L, int R) {     int node = tc++;     t[node] = TNode(L, R);     if (R - L > 1) {       int M = (L + R) / 2;       t[node].lc = build(L, M);       t[node].rc = build(M, R);     }     return node;   }   void relax(int node) {     if (t[node].sw) {       t[node].sw = false;       t[node].sum = t[node].R - t[node].L - t[node].sum;       if (t[node].R - t[node].L > 1) {         t[t[node].lc].sw ^= true;         t[t[node].rc].sw ^= true;       }     }   }   void combine(int node) { t[node].sum = t[t[node].lc].sum + t[t[node].rc].sum; }   int getsum(int node, int L, int R) {     relax(node);     if (R <= t[node].L || t[node].R <= L) {       return 0;     }     if (L <= t[node].L && t[node].R <= R) {       return t[node].sum;     }     return getsum(t[node].lc, L, R) + getsum(t[node].rc, L, R);   }   void swapseg(int node, int L, int R) {     relax(node);     if (R <= t[node].L || t[node].R <= L) {       return;     }     if (L <= t[node].L && t[node].R <= R) {       t[node].sw = true;       relax(node);       return;     }     swapseg(t[node].lc, L, R);     swapseg(t[node].rc, L, R);     combine(node);   }   int N, M;   vector<int> e[maxn];   int par[maxn], d[maxn], w[maxn];   int root[maxn], len[maxn], sky[maxn], tr[maxn];   int up[maxk + 1][maxn];   int A, B;   bool enabled;   void dfs_build(int v, int p) {     par[v] = p;     d[v] = (p == -1 ? 0 : d[p] + 1);     w[v] = 1;     root[v] = v;     len[v] = 1;     for (int i = 0; i < (int)(e[v].size()); ++i) {       int u = e[v][i];       if (u == p) {         continue;       }       if (d[u] == -1) {         dfs_build(u, v);         w[v] += w[u];       } else {         A = u;         B = v;       }     }     for (int i = 0; i < (int)(e[v].size()); ++i) {       int u = e[v][i];       if (u == p) {         continue;       }       if (d[u] == d[v] + 1 && 2 * w[u] >= w[v]) {         root[v] = root[u];         ++len[root[v]];       }     }   }   void build_up() {     for (int i = 0; i < (int)(N); ++i) {       up[0][i] = par[i];     }     for (int j = 0; j < (int)(maxk); ++j) {       for (int i = 0; i < (int)(N); ++i) {         up[j + 1][i] = (up[j][i] == -1 ? -1 : up[j][up[j][i]]);       }     }   }   int get_up(int v, int d) {     for (int j = maxk; j >= 0; --j) {       if ((1 << j) <= d) {         d -= 1 << j;         v = up[j][v];       }     }     return v;   }   int lca(int v, int u) {     if (d[v] < d[u]) {       swap(v, u);     }     v = get_up(v, d[v] - d[u]);     if (v == u) {       return v;     }     for (int j = maxk; j >= 0; --j) {       if (up[j][v] != up[j][u]) {         v = up[j][v];         u = up[j][u];       }     }     return par[v];   }   int dist(int v, int u) {     int w = lca(u, v);     return d[u] + d[v] - 2 * d[w];   }   int total;   void swap_up(int v, int x) {     int r = root[v];     int p = d[r] - d[v];     total += getsum(tr[r], 0, len[r]);     if (p + x <= len[r]) {       swapseg(tr[r], p, p + x);     } else {       swapseg(tr[r], p, len[r]);       swap_up(sky[r], x - (len[r] - p));     }     total -= getsum(tr[r], 0, len[r]);   }   void swap_path(int x, int y) {     int w = lca(x, y);     swap_up(x, d[x] - d[w]);     swap_up(y, d[y] - d[w]);   }   int sum_up(int v, int x) {     int r = root[v];     int p = d[r] - d[v];     if (p + x <= len[r]) {       return getsum(tr[r], p, p + x);     } else {       return getsum(tr[r], p, len[r]) + sum_up(sky[r], x - (len[r] - p));     }   }   int onpath(int x, int y, int z) {     int w = lca(x, y), l = dist(x, y);     if (z <= d[x] - d[w]) {       return get_up(x, z);     } else {       return get_up(y, l - z);     }   }   int fork(int x) {     int d1 = dist(x, A), d2 = dist(x, B), d3 = dist(A, B);     return onpath(x, A, (d1 + d2 - d3) / 2);   }   int bonus() {     if (!enabled) {       return 0;     }     int w = lca(A, B);     if (sum_up(A, d[A] - d[w]) + sum_up(B, d[B] - d[w]) == dist(A, B)) {       return 0;     } else {       return 1;     }   }   int main() {     scanf( %d%d , &N, &M);     for (int i = 0; i < (int)(N); ++i) {       int x, y;       scanf( %d%d , &x, &y);       --x;       --y;       e[x].push_back(y);       e[y].push_back(x);     }     for (int i = 0; i < (int)(N); ++i) {       d[i] = -1;     }     dfs_build(0, -1);     build_up();     for (int i = 0; i < (int)(N); ++i) {       if (root[i] == i) {         tr[i] = build(0, len[i]);         sky[i] = get_up(i, len[i]);       }     }     if (d[A] > d[B]) {       swap(A, B);     }     total = N;     enabled = false;     for (int i = 0; i < (int)(M); ++i) {       int x, y;       scanf( %d%d , &x, &y);       --x;       --y;       int p = fork(x), q = fork(y);       if (p == q) {         swap_path(x, y);       } else {         swap_path(x, p);         swap_path(y, q);         int lup = d[q] < d[p] ? d[p] - d[q] : d[p] - d[A] + 1 + d[B] - d[q];         int ldown = d[q] > d[p] ? d[q] - d[p] : d[B] - d[p] + 1 + d[q] - d[A];         if (lup == ldown) {           int vup = p == A ? B : par[p];           int vdown = p == B ? A : get_up(B, d[B] - d[p] - 1);           if (vup < vdown) {             --lup;           } else {             --ldown;           }         }         if (lup < ldown) {           if (d[q] < d[p]) {             swap_path(p, q);           } else {             swap_path(p, A);             enabled ^= true;             swap_path(B, q);           }         } else {           if (d[q] > d[p]) {             swap_path(p, q);           } else {             swap_path(p, B);             enabled ^= true;             swap_path(q, A);           }         }       }       cout << total - bonus() <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int A[200005];   int lazy[600005], ma[600005], mi[600005];   long long sum[600005];   void push_up(int cur) {     sum[cur] = sum[cur * 2] + sum[cur * 2 + 1];     ma[cur] = max(ma[cur * 2], ma[cur * 2 + 1]);     mi[cur] = min(mi[cur * 2], mi[cur * 2 + 1]);   }   void push_down(int cur, int l, int r) {     if (lazy[cur] == 0) return;     int mid = (l + r) / 2;     sum[cur * 2] = (lazy[cur] * 1ll * (mid - l + 1));     ma[cur * 2] = mi[cur * 2] = lazy[cur];     lazy[cur * 2] = lazy[cur];     sum[cur * 2 + 1] = (lazy[cur] * 1ll * (r - mid));     ma[cur * 2 + 1] = mi[cur * 2 + 1] = lazy[cur];     lazy[cur * 2 + 1] = lazy[cur];     lazy[cur] = 0;   }   int __ma;   void build(int cur, int l, int r) {     lazy[cur] = 0;     __ma = max(__ma, cur);     if (l == r) {       sum[cur] = mi[cur] = ma[cur] = A[r];       return;     }     int mid = (l + r) / 2;     build(cur * 2, l, mid);     build(cur * 2 + 1, mid + 1, r);     push_up(cur);   }   void modify_toMax(int cur, int l, int r, int cl, int cr, int Ma) {     if (mi[cur] >= Ma) return;     if (l >= cl && r <= cr) {       if (ma[cur] <= Ma) {         ma[cur] = mi[cur] = Ma;         sum[cur] = Ma * 1ll * (r - l + 1);         lazy[cur] = Ma;         return;       }     }     push_down(cur, l, r);     int mid = (l + r) / 2;     if (cl <= mid) modify_toMax(cur * 2, l, mid, cl, cr, Ma);     if (cr > mid) modify_toMax(cur * 2 + 1, mid + 1, r, cl, cr, Ma);     push_up(cur);   }   long long query_sum(int cur, int l, int r, int cl, int cr) {     if (l >= cl && r <= cr) return sum[cur];     push_down(cur, l, r);     int mid = (l + r) / 2;     long long ans = 0;     if (cl <= mid) ans += query_sum(cur * 2, l, mid, cl, cr);     if (cr > mid) ans += query_sum(cur * 2 + 1, mid + 1, r, cl, cr);     return ans;   }   int query_firSmallInd(int cur, int l, int r, int cl, int cr, int Ma) {     if (mi[cur] > Ma) return -1;     if (l == r) {       if (ma[cur] <= Ma) return r;       return -1;     }     push_down(cur, l, r);     int mid = (l + r) / 2;     if (cl <= mid) {       int ind = query_firSmallInd(cur * 2, l, mid, cl, cr, Ma);       if (ind != -1) return ind;     }     if (cr > mid) return query_firSmallInd(cur * 2 + 1, mid + 1, r, cl, cr, Ma);     return -1;   }   int query_maxPresum(int cur, int l, int r, long long Ma) {     if (l == r) {       if (ma[cur] <= Ma) return r + 1;       return r;     }     push_down(cur, l, r);     int mid = (l + r) / 2;     if (sum[cur * 2] <= Ma)       return query_maxPresum(cur * 2 + 1, mid + 1, r, Ma - sum[cur * 2]);     return query_maxPresum(cur * 2, l, mid, Ma);   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i += 1) scanf( %d , &A[i]);     build(1, 1, n);     int a, b, c;     for (int i = 1; i <= m; i += 1) {       scanf( %d%d%d , &a, &b, &c);       if (a == 1) {         modify_toMax(1, 1, n, 1, b, c);       } else {         int lef, rig, cur_ind = b, ans = 0;         while (cur_ind <= n) {           lef = query_firSmallInd(1, 1, n, cur_ind, n, c);           if (lef == -1) break;           long long pre = 0;           if (lef > 1) pre = query_sum(1, 1, n, 1, lef - 1);           rig = query_maxPresum(1, 1, n, pre + c);           --rig;           c -= query_sum(1, 1, n, lef, rig);           ans += (rig - lef + 1);           cur_ind = rig + 2;         }         printf( %d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while ( 0  <= c && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x * f;   }   int n, m, cnt, maxx, tab[300], f[1005][105][105];   char s[15];   struct Trie {     int bj, len, fail, ch[4];   } tree[105];   void Insert() {     int len = strlen(s + 1), now = 1;     maxx = max(maxx, len);     for (int i = 1; i <= len; ++i) {       int v = tab[s[i]];       int &o = tree[now].ch[v];       if (!o) o = ++cnt;       now = o;     }     tree[now].bj = 1;     tree[now].len = len;   }   void Build() {     queue<int> q;     for (int i = 0; i <= 3; ++i) tree[0].ch[i] = 1;     q.push(1);     while (!q.empty()) {       int x = q.front(), fail = tree[x].fail;       q.pop();       tree[x].bj |= tree[fail].bj;       tree[x].len = max(tree[x].len, tree[fail].len);       for (int i = 0; i <= 3; ++i) {         int &y = tree[x].ch[i];         if (!y)           y = tree[fail].ch[i];         else           tree[y].fail = tree[fail].ch[i], q.push(y);       }     }   }   inline int Mod(int x) { return x >= 1000000009 ? x - 1000000009 : x; }   int main() {     tab[ A ] = 0;     tab[ C ] = 1;     tab[ G ] = 2;     tab[ T ] = 3;     n = read();     m = read();     cnt = 1;     for (int i = 1; i <= m; ++i) scanf( %s , s + 1), Insert();     Build();     f[0][0][1] = 1;     for (int i = 0; i < n; ++i)       for (int j = 0; j <= maxx; ++j)         for (int k = 1; k <= cnt; ++k)           if (f[i][j][k])             for (int p = 0; p <= 3; ++p) {               int y = tree[k].ch[p];               if (j + 1 <= tree[y].len)                 f[i + 1][0][y] = Mod(f[i + 1][0][y] + f[i][j][k]);               else                 f[i + 1][j + 1][y] = Mod(f[i + 1][j + 1][y] + f[i][j][k]);             }     int ans = 0;     for (int k = 1; k <= cnt; ++k) ans = Mod(ans + f[n][0][k]);     cout << ans <<   n ;   }


#include <bits/stdc++.h>   inline void in(int &MAGNUS) { scanf( %d , &MAGNUS); }   inline void out(int MAGNUS) { printf( %d n , MAGNUS); }   inline void in(int &MAGNUS, int &CLAR) { scanf( %d%d , &MAGNUS, &CLAR); }   inline void out(int MAGNUS, int CLAR) { printf( %d %d n , MAGNUS, CLAR); }   inline void inl(long long &LIV) { scanf( %lld , &LIV); }   inline void inl(long long &LIV, long long &MART) {     scanf( %lld%lld , &LIV, &MART);   }   inline void outl(long long LIV) { printf( %lld n , LIV); }   inline void outl(long long LIV, long long MART) {     printf( %lld %lld n , LIV, MART);   }   using namespace std;   int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};   int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};   int R, C, x[405][405], sum[8][405][405];   bool inside(int r, int c) { return 1 <= r && r <= R && 1 <= c && c <= C; }   int rsum(int dir, int r1, int c1, int r2, int c2) {     return abs(sum[dir][r2][c2] - sum[dir][r1 - dx[dir]][c1 - dy[dir]]);   }   int main() {     in(R, C);     for (int i = 1; i <= R; i++) {       for (int j = 1; j <= C; j++) {         char ch;         cin >> ch;         x[i][j] = ch -  0 ;       }     }     for (int dir = 0; dir <= 7; dir++) {       for (int i = 1; i <= R; i++) {         for (int j = 1; j <= C; j++) {           if (inside(i - dx[dir], j - dy[dir])) continue;           int r = i, c = j;           while (inside(r, c)) {             if (r == i && c == j)               sum[dir][r][c] = x[i][j];             else               sum[dir][r][c] = x[r][c] + sum[dir][r - dx[dir]][c - dy[dir]];             r += dx[dir];             c += dy[dir];           }         }       }     }     long long ans = 0;     for (int i = 1; i <= R; i++) {       for (int j = 1; j <= C; j++) {         for (int dir = 0; dir <= 3; dir++) {           for (int k = 1; k <= min(R, C); k++) {             int r1 = i + dx[dir] * k, c1 = j + dy[dir] * k;             int r2 = i + dx[(dir + 1) % 4] * k, c2 = j + dy[(dir + 1) % 4] * k;             if (!inside(r1, c1) || !inside(r2, c2)) continue;             int s1 = rsum(dir, i, j, r1, c1),                 s2 = rsum((dir + 1) % 4, i, j, r2, c2),                 s3 = rsum(dir + 4, r2, c2, r1, c1);             ans += (s1 == 0 && s2 == 0 && s3 == 0);           }           for (int k = 1; k <= min(R, C); k++) {             int r1 = i + dx[dir] * k, c1 = j + dy[dir] * k;             int r2 = i + dx[(dir + 1) % 4] * k, c2 = j + dy[(dir + 1) % 4] * k;             int r3 = i + dx[(dir + 2) % 4] * k, c3 = j + dy[(dir + 2) % 4] * k;             if (!inside(r1, c1) || !inside(r2, c2) || !inside(r3, c3)) continue;             int s1 = rsum(dir, i, j, r1, c1), s2 = rsum(dir + 4, r2, c2, r1, c1);             int s3 = rsum((dir + 2) % 4, i, j, r3, c3),                 s4 = rsum((dir + 1) % 4 + 4, r3, c3, r2, c2);             ans += (s1 == 0 && s2 == 0 && s3 == 0 && s4 == 0);           }         }       }     }     outl(ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e7 + 7;   const int Mx = (int)1e7;   int n, m;   int A[N], B[N];   int lp[N];   map<int, vector<int> > a, b;   void precalc() {     for (int i = 2; i <= Mx; i++) {       if (!lp[i]) {         lp[i] = i;         if (i * 1ll * i <= Mx) {           for (int j = i * i; j <= Mx; j += i) {             if (!lp[j]) lp[j] = i;           }         }       }     }   }   int main() {     precalc();     scanf( %d%d , &n, &m);     for (int i = 1, x; i <= n; i++) {       scanf( %d , &A[i]);       x = A[i];       while (x > 1) {         int p = lp[x];         a[p].push_back(i);         x /= p;       }     }     for (int i = 1, x; i <= m; i++) {       scanf( %d , &B[i]);       x = B[i];       while (x > 1) {         int p = lp[x];         b[p].push_back(i);         x /= p;       }     }     for (int i = 2; i < N; i++) {       if (lp[i] == i) {         int len = min(a[i].size(), b[i].size());         while (len) {           len--;           A[a[i].back()] /= i;           B[b[i].back()] /= i;           a[i].pop_back();           b[i].pop_back();         }       }     }     printf( %d %d n , n, m);     for (int i = 1; i <= n; i++) {       printf( %d  , A[i]);     }     printf(  n );     for (int i = 1; i <= m; i++) {       printf( %d  , B[i]);     }     return 0;   }


#include <bits/stdc++.h>   int f[100001];   int a[100001];   using namespace std;   int main() {     bool isAm = false;     long long int n, m, x;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> x;       if (f[x] == 0)         f[x] = i + 1;       else         f[x] = -1;     }     for (int i = 0; i < m; i++) {       cin >> x;       if (f[x] == 0) {         cout <<  Impossible ;         return 0;       } else if (f[x] != -1) {         a[i] = f[x];       } else         isAm = true;     }     if (isAm) {       cout <<  Ambiguity ;       return 0;     }     cout <<  Possible n ;     for (int i = 0; i < m; i++) cout << a[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   using namespace std;   long long binpow(long long base, long long exp, int mod) {     long long res = 1;     while (exp > 0) {       if (exp % 2 == 1) res = (res * base) % mod;       exp = exp >> 1;       base = (base * base) % mod;     }     return res;   }   long long mod(long long x) {     return ((x % 1000000007LL + 1000000007LL) % 1000000007LL);   }   long long add(long long a, long long b) { return mod(mod(a) + mod(b)); }   long long mul(long long a, long long b) { return mod(mod(a) * mod(b)); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int m;     cin >> m;     vector<long long int> v1;     for (long long int i = 0; i < m; i++) {       long long int x;       cin >> x;       v1.push_back(x);     };     sort(v1.begin(), v1.end());     long long int n;     cin >> n;     vector<long long int> v2;     for (long long int i = 0; i < n; i++) {       long long int x;       cin >> x;       v2.push_back(x);     };     sort(v2.begin(), v2.end());     long long int sum = 0;     for (int i = 0; i < n; i++) sum += v2[i];     if (n < v1[0] + 2) {       cout << sum <<   n ;     } else {       long long int sum2 = 0;       for (long long int i = n - 1; i >= 0; i -= v1[0] + 2) {         for (long long int j = i; j >= max(i - v1[0] + 1, 0LL); j--)           sum2 += v2[j];       }       cout << sum2 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 29;   struct abc {     int left, right, capacity, cost;   } edge[12345];   int n, k, x, e = 0, cost[50], p[50];   void addEdge(int a, int b, int c, int d) {     edge[e].left = a;     edge[e].right = b;     edge[e].capacity = c;     edge[e].cost = d;     e++;     edge[e].left = b;     edge[e].right = a;     edge[e].capacity = 0;     edge[e].cost = -d;     e++;   }   bool getPath(int s, int t) {     for (int i = 0; i < n; i++) cost[i] = INF;     cost[s] = 0;     bool upd = true;     for (int it = 1; upd && it < n; it++)       for (int i = upd = 0; i < e; i++)         if (edge[i].capacity > 0 && cost[edge[i].left] < INF &&             cost[edge[i].right] > cost[edge[i].left] + edge[i].cost) {           cost[edge[i].right] = cost[edge[i].left] + edge[i].cost;           p[edge[i].right] = i;           upd = true;         }     return cost[t] < INF;   }   int minCostMaxFlow(int s, int t) {     int MaxFlow = 0, MinCost = 0, flow;     while (getPath(s, t)) {       MinCost += cost[t];       if (MinCost > k) return MaxFlow;       flow = INF;       for (int c = t; c != s; c = edge[p[c]].left) {         flow = min(flow, edge[p[c]].capacity);         if (edge[p[c]].cost != 0) flow = 1;       }       for (int c = t; c != s; c = edge[p[c]].left) {         edge[p[c]].capacity -= flow;         edge[p[c] ^ 1].capacity += flow;       }       MaxFlow += flow;     }     return MaxFlow;   }   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         cin >> x;         if (x) {           addEdge(i, j, x, 0);           addEdge(i, j, INF, 1);         }       }     cout << minCostMaxFlow(0, n - 1);   }


#include <bits/stdc++.h>   using namespace std;   int Month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   int A[1000 + 1];   int B[126];   void omae_wa_mou_shindeiru() {     int n, k;     cin >> n >> k;     string s;     cin >> s;     for (int i = 0; i < n; ++i) {       int c = 1;       while (s[i] == s[i + 1] && i < n) {         ++c;         ++i;       }       B[s[i]] += c / k;     }     int ans = 0;     for (int i =  a ; i <=  z ; ++i) {       ans = max(ans, B[i]);     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     ;     int t = 1;     while (t--) {       omae_wa_mou_shindeiru();       if (t) cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long i;     while (cin >> i) {       if (i % 2)         cout << 1 << endl;       else         cout << 2 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int maxN = 1e5 + 10;   int n, m, s, f;   int t[maxN], l[maxN], r[maxN];   bool inside(int l, int m, int r) { return l <= m && m <= r; }   void slv() {     int d = f > s ? 1 : -1;     m++;     t[m] = inf, l[m] = inf, r[m] = -inf;     int tm = 1;     int p = 1;     while (true) {       if (s == f) break;       if (tm != t[p])         s += d, printf( %c , d > 0 ?  R  :  L );       else {         if (inside(l[p], s, r[p]) || inside(l[p], s + d, r[p]))           printf( X );         else           printf( %c , d > 0 ?  R  :  L ), s += d;         p++;       }       tm++;     }   }   int main() {     while (~scanf( %d%d%d%d , &n, &m, &s, &f)) {       for (int i = 1; i <= m; i++) scanf( %d%d%d , &t[i], &l[i], &r[i]);       slv();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   string s[55];   vector<int> getRow(int x) {     vector<int> R;     for (int i = 1; i <= m; i++)       if (s[x][i] ==  # ) R.push_back(i);     return R;   }   vector<int> getCol(int x) {     vector<int> C;     for (int i = 1; i <= n; i++)       if (s[i][x] ==  # ) C.push_back(i);     return C;   }   int Viz[55];   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       string t;       cin >> t;       s[i] =  .  + t +  . ;     }     int nope = 0;     for (int i = 1; i <= n && !nope; i++) {       if (!Viz[i]) {         vector<int> V, R;         int ok = 0;         for (int j = 1; j <= m; j++) {           if (s[i][j] ==  # ) {             R.push_back(j);             if (!ok)               V = getCol(j), ok = 1;             else {               vector<int> U = getCol(j);               if (U != V) nope = 1;             }           }         }         for (int j : V) {           Viz[j] = 1;           vector<int> Row = getRow(j);           if (R != Row) {             nope = 1;           }         }       }     }     if (nope)       cout <<  No ;     else       cout <<  Yes ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int const nmax = 200000;   struct Person {     int cost;     int number;     bool operator<(Person const &a) const { return number < a.number; }   };   Person v[1 + nmax];   void solve() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> v[i].number >> v[i].cost;     sort(v + 1, v + n + 1);     ll result = 0;     int votes = 0;     priority_queue<int, vector<int>, greater<int>> pq;     for (int i = n; 1 <= i; i--) {       pq.push(v[i].cost);       if (v[i].number <= i - 1 + votes)         continue;       else {         result += pq.top();         votes++;         pq.pop();       }     }     cout << result <<   n ;   }   int main() {     int t;     cin >> t;     for (int testcase = 1; testcase <= t; testcase++) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int times[50] = {0};   int graph[50][50] = {0};   void findMissing(int n, int &temp1, int &temp2) {     bool condition = false;     for (int i = 0; i < n; i++) {       if (times[i] != (n - 1)) {         if (condition)           temp2 = i;         else {           temp1 = i;           condition = true;         }       }     }   }   void swap(int &n1, int &n2) {     n1 += n2;     n2 = n1 - n2;     n1 -= n2;   }   void findOrder(int n, int &temp1, int &temp2) {     for (int i = 0; i < n; i++) {       bool condition = false;       if (i == temp1 || i == temp2)         continue;       else {         if (graph[temp1][i] == 1 && graph[i][temp2] == 1)           return;         else if (graph[i][temp1] == 1 && graph[temp2][i] == 1) {           swap(temp1, temp2);           return;         }       }     }   }   int main() {     int n, temp1, temp2;     cin >> n;     for (int i = 0; i < (((n * (n - 1)) / 2) - 1); i++) {       cin >> temp1 >> temp2;       times[temp1 - 1]++;       times[temp2 - 1]++;       graph[temp1 - 1][temp2 - 1] = 1;     }     findMissing(n, temp1, temp2);     findOrder(n, temp1, temp2);     cout << temp1 + 1 <<     << temp2 + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const string FILENAME =  input ;   vector<pair<int, int> > best;   vector<int> a;   int main() {     int n, m;     cin >> n >> m;     vector<int> has(2 * n, 0);     vector<int> pr(2 * n, -1);     vector<pair<int, int> > next(2 * n, {0, 0});     for (int i = 0; i < 2 * n; i++) {       int t;       cin >> t;       a.push_back(t);       next[i] = {-a[i], i};     }     sort((next).begin(), (next).end());     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       x--;       y--;       pr[x] = y;       pr[y] = x;       if (a[x] > a[y]) {         swap(x, y);       }       best.push_back({y, x});     }     int ans;     int cnt = 0;     int t;     cin >> t;     if (t == 1) {       for (int i = 0; i < m; i++) {         cout << best[i].first + 1 << endl;         cin >> ans;         if (ans == -1) return 0;         has[best[i].first] = 1;         has[ans - 1] = 1;       }       for (int i = 0; i < 2 * n; i++) {         if (has[next[i].second] == 0) {           cout << next[i].second + 1 << endl;           cin >> ans;           if (ans == -1) return 0;           has[ans - 1] = 1;           has[next[i].second] = 1;         }       }       return 0;     }     cin >> ans;     ans--;     has[ans] = 1;     cnt++;     while (pr[ans] != -1) {       cout << pr[ans] + 1 << endl;       cnt++;       if (cnt == 2 * n) return 0;       has[pr[ans]] = 1;       cin >> ans;       cnt++;       if (ans == -1) return 0;       ans--;       has[ans] = 1;     }     for (int i = 0; i < m; i++) {       if (has[best[i].first] == 0) {         has[best[i].first] = 1;         cout << best[i].first + 1 << endl;         cnt++;         if (cnt == 2 * n) return 0;         cin >> ans;         cnt++;         if (ans == -1) return 0;         ans--;         has[ans] = 1;       }     }     for (int i = 0; i < 2 * n; i++) {       if (has[next[i].second] == 0) {         cout << next[i].second + 1 << endl;         cnt++;         if (cnt == 2 * n) return 0;         cin >> ans;         cnt++;         if (ans == -1) return 0;         ans--;         has[ans] = 1;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, k, i, j;     bool flag, flag1, final_flag;     string p, q;     cin >> t;     for (i = 0; i < t; i++) {       map<char, int> m;       final_flag = false;       cin >> p >> q;       for (j = 0; j < p.size(); j++) {         if (m.find(p[j]) == m.end())           m[p[j]] = 1;         else           m[p[j]] += 1;       }       for (j = 0; j < q.size(); j++) {         map<char, int> m1;         flag1 = true;         flag = true;         if (m.find(q[j]) != m.end()) {           k = j;           for (k = j; k < p.size() + j; k++) {             if (m.find(q[k]) == m.end()) {               flag = false;               break;             } else {               if (m1.find(q[k]) == m1.end())                 m1[q[k]] = 1;               else                 m1[q[k]] += 1;             }           }           if (flag) {             map<char, int>::iterator it;             for (it = m.begin(); it != m.end(); it++) {               if (m1.find(it->first) == m1.end()) {                 flag1 = false;                 break;               }               if (m1[it->first] != m[it->first]) {                 flag1 = false;                 break;               }             }             if (flag1) final_flag = true;           }         }         if (final_flag) break;       }       if (final_flag)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const long long oo = 1e18;   const long long mod = 1e9 + 7;   const int INF = 1 << 30;   vector<pair<pair<int, long long>, int>> adj[N];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     ios_base::sync_with_stdio(0);     int n, m, k;     cin >> n >> m >> k;     map<pair<int, int>, long long> edges;     for (int i = 0; i < m; i++) {       int u, v;       long long w;       cin >> u >> v >> w;       edges[{u, v}] = w;       adj[u].push_back({{v, w}, 0});       adj[v].push_back({{u, w}, 0});     }     int ans = 0;     for (int i = 0; i < k; i++) {       int s;       long long y;       cin >> s >> y;       adj[1].push_back({{s, y}, 1});     }     priority_queue<pair<pair<int, long long>, int>,                    vector<pair<pair<int, long long>, int>>,                    greater<pair<pair<int, long long>, int>>>         q;     long long dis[N];     bool anagetHenaBeTrain[N];     for (int i = 0; i < N; i++) dis[i] = INF;     memset(anagetHenaBeTrain, false, sizeof(anagetHenaBeTrain));     dis[1] = 0;     q.push({{dis[1], 1}, 0});     while (q.size()) {       auto top = q.top();       q.pop();       long long cost = top.first.first;       int node = top.first.second;       int type = top.second;       if (cost > dis[node]) continue;       for (auto v : adj[node]) {         if (v.first.second + cost < dis[v.first.first]) {           dis[v.first.first] = v.first.second + cost;           anagetHenaBeTrain[v.first.first] = v.second;           q.push({{dis[v.first.first], v.first.first}, v.second});         } else if (v.first.second + cost == dis[v.first.first]) {           if (anagetHenaBeTrain[v.first.first] == 1 && v.second == 0) {             anagetHenaBeTrain[v.first.first] = 0;           }         }       }     }     for (int i = 1; i <= n; i++)       if (anagetHenaBeTrain[i] == 1) ans++;     cout << k - ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double EPS = 1E-9;   const int INF = (int)1E9;   const long long INF64 = (long long)1E18;   const long double PI = 2 * acos(.0);   int n, k;   string number;   int repla2[11];   string construct(int ind) {     string resp =   ;     bool used[10005];     memset(used, false, sizeof(used));     for (int i = 0; i < (int)((number).size()); i++) {       bool cent2 = 1;       if (repla2[abs((number[i] -  0 ) - ind)] > 0 && ind <= (number[i] -  0 )) {         repla2[abs((number[i] -  0 ) - ind)]--;         char a =  0  + ind;         used[i] = true;         resp += a;         cent2 = 0;       }       if (cent2) resp += number[i];     }     for (int i = n - 1; i >= 0; i--) {       bool cent2 = 1;       if (!used[i] && repla2[abs((number[i] -  0 ) - ind)] > 0 &&           ind >= (number[i] -  0 )) {         repla2[abs((number[i] -  0 ) - ind)]--;         char a =  0  + ind;         resp[i] = a;         cent2 = 0;       }     }     return resp;   }   int main() {     cin >> n >> k >> number;     string winner;     int mini = INF;     int ind = -1;     int conts[11];     fill(conts, conts + 11, 0);     for (int i = 0; i < (int)((number).size()); i++) {       conts[number[i] -  0 ]++;     }     bool cent = 0;     string resp2;     for (int i = 0; i < (int)(10); i++) {       int kk = k - conts[i];       if (kk <= 0) {         cent = 1;         cout << 0 << endl;         cout << number << endl;         break;       }       int temp = 0;       fill(repla2, repla2 + 11, 0);       for (int j = 1; j < (int)(10); j++) {         int cont1 = i - j;         int cont2 = i + j;         if (cont2 < 10) {           if (kk <= conts[cont2]) {             temp += (kk * j);             repla2[j] += kk;             if (temp < mini) {               ind = i;               mini = temp;               resp2 = construct(i);             } else if (temp == mini) {               string temp = construct(i);               if (temp < resp2) resp2 = temp;             }             break;           } else {             temp += (conts[cont2] * j);             kk -= conts[cont2];             repla2[j] += conts[cont2];           }         }         if (cont1 >= 0) {           if (kk <= conts[cont1]) {             temp += (kk * j);             repla2[j] += kk;             if (temp < mini) {               mini = temp;               resp2 = construct(i);             } else if (temp == mini) {               string temp = construct(i);               if (temp < resp2) resp2 = temp;             }             break;           } else {             temp += (conts[cont1] * j);             kk -= conts[cont1];             repla2[j] += conts[cont1];           }         }       }     }     bool used[10005];     memset(used, false, sizeof(used));     if (!cent) {       cout << mini << endl;       cout << resp2;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   const int MOD = 998244353;   int n, c, a[3005], cnt[3005], pw[3005], ipw1[3005], ans[3005];   inline int mval(int x) { return x >= MOD ? x - MOD : x; }   inline void inc(int &x, int a) { (x += a) >= MOD && (x -= MOD); }   inline void dec(int &x, int a) { x = mval(MOD + x - a); }   inline int qpow(int x, int p) {     int ret = 1;     while (p) {       if (p & 1) ret = 1ll * ret * x % MOD;       p >>= 1, x = 1ll * x * x % MOD;     }     return ret;   }   namespace sub1 {   int f[3005][1 << 10], g[3005];   inline void solve(void) {     int u = (1 << c) - 1;     g[0] = 1;     ans[0] = pw[n] - 1;     for (int t = 1; t * c <= n + 1; ++t) {       for (int i = 1; i <= n; ++i) std::fill(f[i], f[i] + (1 << c), 0);       for (int i = 1; i <= n; ++i) {         inc(f[i][0], g[i - 1]);         inc(f[i][1 << a[i]], g[i - 1]);         for (int s = 0; s < u; ++s)           inc(f[i][s], f[i - 1][s]), inc(f[i][s | (1 << a[i])], f[i - 1][s]);       }       for (int i = 0; i <= n; ++i) g[i] = f[i][u ^ (1 << a[i])];       for (int i = 0; i <= n; ++i) inc(ans[t], 1ll * g[i] * pw[n - i] % MOD);     }     for (int i = 0; i <= n; ++i) dec(ans[i], ans[i + 1]);   }   }  // namespace sub1   namespace sub2 {   long long *f, *g, dp[2][3005], tr[3005][3005];   inline void solve(void) {     for (int i = 1; i <= n; ++i) {       std::fill(cnt, cnt + c + 1, 0);       int cur = 1, cc = 0;       tr[i][i] = (c == 1);       for (int j = i - 1; j; --j) {         if (a[j] != a[i]) {           cur = 1ll * ipw1[cnt[a[j]]] * cur % MOD;           if (!cnt[a[j]]) ++cc;           ++cnt[a[j]];           cur = 1ll * (pw[cnt[a[j]]] - 1) * cur % MOD;         }         tr[j][i] = (cc == c - 1 ? cur : 0);       }     }     f = dp[0], g = dp[1];     f[0] = 1;     ans[0] = pw[n] - 1;     for (int t = 1; t * c <= n; ++t) {       std::swap(f, g);       std::fill(f, f + n + 1, 0);       for (int j = 1; j <= n; ++j)         if (g[j - 1])           for (int i = j; i <= n; ++i) f[i] += g[j - 1] * tr[j][i] % MOD;       for (int i = 1; i <= n; ++i) f[i] %= MOD;       for (int i = 0; i <= n; ++i) inc(ans[t], f[i] * pw[n - i] % MOD);     }     for (int i = 0; i <= n; ++i) dec(ans[i], ans[i + 1]);   }   }  // namespace sub2   int main() {     scanf( %d%d , &n, &c);     pw[0] = 1;     ipw1[0] = 1;     for (int i = 1; i <= n; ++i)       pw[i] = 2ll * pw[i - 1] % MOD, ipw1[i] = qpow(pw[i] - 1, MOD - 2);     for (int i = 1; i <= n; ++i) scanf( %d , a + i), --a[i];     if (c <= 10)       sub1::solve();     else       sub2::solve();     for (int i = 0; i <= n; ++i) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   const int N = 1e5 + 7;   const int xinc[] = {0, 0, 1, -1};   const int yinc[] = {1, -1, 0, 0};   const long double PI = acos(-1.0);   const double EPS = 1e-9;   string s;   long long a, n, sum[4007], ans;   map<long long, long long> m;   void solve() {     cin >> a >> s;     n = s.size();     for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + s[i - 1] -  0 ;     long long t = 0;     for (int i = 1; i <= n; i++)       for (int j = i; j <= n; j++) {         long long psum = sum[j] - sum[i - 1];         m[psum]++;         t++;       }     for (auto i : m) {       long long psum = i.first;       if (psum != 0 && a != 0 && a % psum == 0) {         long long cur = m[a / psum] * i.second;         ans += cur;       }       if (a == 0) {         if (psum == 0)           ans += m[psum] * t;         else           ans += m[psum] * m[0];       }     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int num[100008];   int cnt1[100008];   int cnt2[100008];   int cnt;   struct node {     int s, t;   } ans[100008];   bool cmp(node a, node b) {     if (a.s == b.s) return a.t < b.t;     return a.s < b.s;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &num[i]);       if (num[i] == 1) {         cnt1[i] = cnt1[i - 1] + 1;         cnt2[i] = cnt2[i - 1];       } else if (num[i] == 2) {         cnt1[i] = cnt1[i - 1];         cnt2[i] = cnt2[i - 1] + 1;       }     }     int acnt = 0;     int bcnt = 0;     int pre;     int atmp;     int btmp;     for (int i = 1; i <= n; i++) {       pre = 1;       acnt = 0;       bcnt = 0;       while (true) {         atmp = lower_bound(cnt1 + pre, cnt1 + 1 + n, i + cnt1[pre - 1]) - cnt1;         btmp = lower_bound(cnt2 + pre, cnt2 + 1 + n, i + cnt2[pre - 1]) - cnt2;         if (atmp < btmp) {           acnt++;           pre = atmp + 1;           if (atmp == n) {             if (num[n] != 2 && acnt > bcnt) {               cnt++;               ans[cnt].s = acnt;               ans[cnt].t = i;             }             break;           }         } else if (atmp > btmp) {           bcnt++;           pre = btmp + 1;           if (btmp == n) {             if (num[n] != 1 && acnt < bcnt) {               cnt++;               ans[cnt].s = bcnt;               ans[cnt].t = i;             }             break;           }         } else {           break;         }       }     }     sort(ans + 1, ans + 1 + cnt, cmp);     printf( %d n , cnt);     for (int i = 1; i <= cnt; i++) {       printf( %d %d n , ans[i].s, ans[i].t);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     string s;     cin >> s;     bool ans = false;     for (int i = 1; i <= n; ++i)       for (int start = 0; start < n; ++start) {         int jump = 0;         int cur = start;         while (cur < n && s[cur] ==  * ) {           jump += 1;           cur += i;         }         if (jump >= 5) ans = true;       }     if (ans)       cout <<  yes  << endl;     else       cout <<  no  << endl;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(time(0));   const double eps = 1e-10;   const long long inf = 0x3f3f3f3f3f3f3f3fLL;   const long long N = 2e5 + 5;   const long long MOD = 1e9 + 7;   long long pw(long long b, long long p) {     long long res = 1;     while (p > 0) {       if (p & 1) res = res * b % MOD;       b = b * b % MOD;       p >>= 1;     }     return res;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n;     cin >> n;     vector<long long> h(n);     long long sum = 0;     for (long long i = 0; i < n; i++) {       cin >> h[i];       sum += h[i];     }     sum -= (n * (n - 1)) / 2;     long long rem = sum % n;     long long cnt = sum / n;     for (long long i = 0; i < n; i++) {       cout << i + cnt + (rem >= i + 1) <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   long long n, m, a, d;   long long t[N];   int main() {     cin >> n >> m >> a >> d;     for (int j = 1; j <= m; j++) {       scanf( %lld , &t[j]);     }     t[m + 1] = 8e18;     long long i = 1, ans = 0, last = -1;     for (int j = 1; j <= m + 1; j++) {       if (i > n) {         if (j <= m && last < t[j]) {           ans++;           last = t[j] + d;         }         continue;       }       if (t[j] > last) {         if (t[j] <= i * a) {           ans++;           last = t[j] + d;           i = last / a + 1;           continue;         }         long long u = d / a + 1;         long long togo = min(n, t[j] / a);         long long dis = ((togo - i) / u);         ans += dis + 1;         i += dis * u;         last = i * a + d;         if (j <= m && last < t[j]) {           ans++;           last = t[j] + d;         }         i = last / a + 1;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double esp = 1e-8;   const int msz = 10000;   const int mod = 1e9 + 7;   struct Tr {     char s[26];     int len, l;   };   Tr s[111];   bool vis[26];   int main() {     char str[1111];     int n, ans;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %s , str);       s[i].len = strlen(str);       s[i].l = 0;       memset(vis, 0, sizeof(vis));       for (int j = 0; j < s[i].len; ++j) {         if (!vis[str[j] -  a ]) {           vis[str[j] -  a ] = 1;           s[i].s[s[i].l++] = str[j];         }       }     }     int mx = 0;     for (int i =  a ; i <=  z ; ++i) {       for (int j = i; j <=  z ; ++j) {         ans = 0;         for (int k = 0; k < n; ++k) {           if (s[k].l == 1 && (s[k].s[0] == i || s[k].s[0] == j))             ans += s[k].len;           else if (s[k].l == 2 && ((s[k].s[0] == i && s[k].s[1] == j) ||                                    (s[k].s[1] == i && s[k].s[0] == j)))             ans += s[k].len;         }         mx = max(mx, ans);       }     }     printf( %d n , mx);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e1 + 5;   int a[N][N], pos[N][N], last[N * N];   double ev[N * N], reg[N * N];   int main() {     for (int i = 0; i < 10; i++) {       for (int j = 0; j < 10; j++) {         scanf( %d , &a[i][j]);         if (i % 2 == 0) {           pos[i][j] = 10 * i + j;         } else {           pos[i][j] = 10 * i + 9 - j;         }         last[pos[i][j]] = pos[i - a[i][j]][j];       }     }     ev[0] = 0;     for (int i = 1; i < 100; i++) {       double sum = 0;       int cnt = 0;       for (int j = i - 1; j >= max(i - 6, 0); j--) {         sum += ev[j];         cnt++;       }       ev[i] = 1 + (1.0 * sum / 6);       ev[i] *= 6.0 / cnt;       reg[i] = ev[i];       ev[i] = min(ev[i], reg[last[i]]);     }     printf( %.7f n , ev[99]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, m, cnt = 0, k, cntt = 0, cnts = 0;   long long int v[100001];   bool vis[100001], ans[100001];   long long int cnte[100001];   int main() {     cin >> n >> m;     memset(vis, false, sizeof(vis));     memset(cnte, 0, sizeof(cnte));     for (int i = 1; i <= m; i++) {       cin >> v[i];       cnte[v[i]]++;       if (vis[v[i]] == false) {         vis[v[i]] = true;         cnt++;       }       if (cnt == n) {         ans[i] = 1;         for (int j = 1; j <= n; j++) {           if (cnte[j] > 1) {             cnte[j]--;           } else {             cnt--;             cnte[j]--;             vis[j] = false;           }         }       } else {         ans[i] = 0;       }     }     for (int i = 1; i <= m; i++) {       cout << ans[i];     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<int>;   void solve() {     int n;     cin >> n;     vector<int> v(n);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     if (count(v.begin(), v.end(), 1) == 1) {       cout << 0 << endl;       return;     }     int s, e;     for (s = 0; s < n; s++) {       if (v[s] == 1) {         break;       }     }     for (e = n - 1; e >= 0; e--) {       if (v[e] == 1) {         break;       }     }     int ans = 0;     for (int i = s; i <= e; i++) {       if (v[i] == 0) {         ans++;       }     }     cout << ans << endl;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt[1 << 14];   signed main() {     ios_base ::sync_with_stdio(false);     cin.tie(0);     int n, k, maxn = 0;     cin >> n >> k;     for (int i = 0; i < n; ++i) {       int a;       cin >> a;       maxn = max(maxn, a);       ++cnt[a];     }     long long ans = 0;     if (k == 0) {       for (int i = 0; i <= maxn; ++i) ans += cnt[i] * (cnt[i] - 1LL) / 2;       cout << ans <<   n ;       return 0;     }     int l = 32 - __builtin_clz(max(1, maxn));     for (int i = 0; i < (1 << l); ++i) {       if (__builtin_popcount(i) != l - k) continue;       for (int j = 0; j <= maxn; ++j)         ans += 1LL * cnt[j] * cnt[(j & i) | (~j & ~i & ((1 << l) - 1))];     }     cout << ans / 2 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char s[1000];     gets(s);     int a[1000] = {0};     for (int i = 0; i < strlen(s); i++) {       if (s[i] <=  z  && s[i] >=  a ) a[s[i]]++;     }     int m = 0;     for (int i = 0; i < 1000; i++)       if (a[i]) m++;     cout << m;   }


#include <bits/stdc++.h>   using namespace std;   struct Lem {     int m, v, id;     bool operator<(Lem b) const { return m < b.m || (m == b.m && v < b.v); }   };   int n, k, h;   Lem a[(100000 + 10)];   bool can(long double t) {     int j = k;     for (int i(n - 1), _l(0); i >= _l; --i) {       if (j > 0 && (long double)j * h / a[i].v - t <= -1e-7) j--;     }     return j == 0;   }   void putAns(long double t) {     int ans[(100000 + 10)];     int j = k;     for (int i(n - 1), _l(0); i >= _l; --i) {       if (j > 0 && (long double)j * h / a[i].v - t <= -1e-7) ans[--j] = a[i].id;     }     for (int i(0), _n(k - 1); i < _n; ++i) printf( %d  , ans[i]);     printf( %d n , (ans[k - 1]));   }   int main() {     scanf( %d , &(n)), scanf( %d , &(k)), scanf( %d , &(h));     for (int i(0), _n(n); i < _n; ++i) scanf( %d , &(a[i].m)), a[i].id = i + 1;     for (int i(0), _n(n); i < _n; ++i) scanf( %d , &(a[i].v));     sort(a, a + n);     long double l = 0, r = 1e10;     int cnt = 100;     while (cnt--) {       long double mid = (l + r) / 2.0;       if (can(mid))         r = mid;       else         l = mid;     }     putAns(r);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[200000];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     long long prev = 0;     long long last = 1e18;     for (int i = 0; i < n / 2; ++i) {       long long x;       cin >> x;       prev = max(prev, x - last);       last = x - prev;       a[i] = prev;       a[n - i - 1] = last;     }     for (int i = 0; i < n; ++i) {       cout << a[i] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 5;   char a[N][N];   void fileIO() {}   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     fileIO();     int h, w;     int tot = 0;     cin >> h >> w;     for (int i = 0; i < h; i++)       for (int j = 0; j < w; j++) {         cin >> a[i][j];         if (a[i][j] ==  * ) tot++;       }     int now = 0;     int curi, curj;     for (int i = 1; i < h - 1; i++) {       for (int j = 1; j < w - 1; j++) {         now = 0;         if (a[i][j] ==  *  and a[i + 1][j] ==  *  and a[i - 1][j] ==  *  and             a[i][j + 1] ==  *  and a[i][j - 1] ==  * ) {           curi = i, curj = j;           while (a[curi + 1][j] ==  * ) {             now++;             curi++;           }           curi = i, curj = j;           while (a[curi - 1][j] ==  * ) {             now++;             curi--;           }           curi = i, curj = j;           while (a[i][curj + 1] ==  * ) {             now++;             curj++;           }           curi = i, curj = j;           while (a[i][curj - 1] ==  * ) {             now++;             curj--;           }           if (now + 1 == tot) {             cout <<  YES ;             exit(0);           }         }       }     }     cout <<  NO ;     return 0;   }


#include <iostream>   #include <vector>   #include <algorithm>   #include <string>   #include <map>   #include <cstdio>   #include <utility>    #include <queue>   #include <math.h>   #include <set>   #include <bitset>   #include <cmath>   #include <bitset>   #include <stack>   #include <cstring>   #include <deque>   using namespace std;   typedef long long ll;   typedef pair<int, int> pii;      int main() {       ios_base::sync_with_stdio(0);       cin.tie(NULL);       int t; cin >> t;       while(t--) {           int n, m; cin >> n >> m;           vector<ll> k(n + 1);           vector<ll> c(m + 1);           for(int i = 1; i <= n; i++) cin >> k[i];           for(int i = 1; i <= m; i++) cin >> c[i];           int idx = 1;           sort(k.begin(), k.end());           ll ans = 0;           for(int i = n; i >= 1; i--) {               if(idx > k[i] || c[k[i]] < c[idx]) ans += c[k[i]];               else {                   ans += c[idx];                   idx++;               }           }           cout << ans <<   n ;       }   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   long long mod = 1e9 + 7;   vector<long long> g[27];   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s1, s2;     cin >> s1 >> s2;     long long n1 = s1.size(), n2 = s2.size(), i, j;     for (i = 0; i < n1; ++i) g[s1[i] -  a ].push_back(i);     long long cnt = 1, prev = -1, it, sz;     for (i = 0; i < n2; ++i) {       j = s2[i] -  a ;       sz = g[j].size();       if (sz == 0) return cout << -1, 0;       it = upper_bound(g[j].begin(), g[j].end(), prev) - g[j].begin();       if (it == sz) it = 0, ++cnt;       prev = g[j][it];     }     cout << cnt <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dir[4][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};   int n, m, k;   bool isValid(int i, int j) { return i >= 0 && j >= 0 && i < n && j < m; }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     int freex = -1, freey = -1, remains = 0;     char grid[n][m];     bool visited[n][m];     memset(visited, false, sizeof visited);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> grid[i][j];         if (grid[i][j] ==  . ) {           remains++;           freex = i;           freey = j;         }       }     if (k == 0) {       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           cout << grid[i][j];         }         cout <<   n ;       }       return 0;     }     queue<pair<int, int>> q;     q.push({freex, freey});     int count = 0;     while (!q.empty()) {       auto tmp = q.front();       q.pop();       int x = tmp.first;       int y = tmp.second;       if (visited[x][y]) continue;       visited[x][y] = true;       count++;       if (count == remains - k) break;       for (int i = 0; i < 4; i++) {         int nx = x + dir[i][0];         int ny = y + dir[i][1];         if (isValid(nx, ny) && grid[nx][ny] ==  .  && !visited[nx][ny])           q.push({nx, ny});       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (!visited[i][j] && grid[i][j] ==  . )           cout <<  X ;         else if (grid[i][j] ==  # )           cout <<  # ;         else           cout <<  . ;       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int ar[30];   int br[30];   unordered_map<long, long> nm;   int main() {     std::ios::sync_with_stdio(false);     ;     int n;     std::cin >> n;     for (int i = 0; i < n; i++) {       std::cin >> ar[i];       br[i] = ar[i];       nm[ar[i]] = i;     }     sort(ar, ar + n);     for (int i = 0; i < n - 1; i++) {       br[nm[ar[i]]] = ar[i + 1];     }     br[nm[ar[n - 1]]] = ar[0];     for (int i = 0; i < n; i++) {       std::cout << br[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};   int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};   long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }   long long power(long long a, long long b, long long ret = 1LL) {     while (b--) ret = (ret * a);     return ret;   }   char a[105];   int main() {     long long n, k;     cin >> n >> k;     int ans = 0;     for (int i = 1; i <= n; i++) {       int cnt = 0;       long long x;       cin >> x;       while (x > 0) {         if (x % 10 == 7 || x % 10 == 4) {           cnt++;         }         x /= 10;       }       if (cnt <= k) ans++;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( -ffloat-store )   #pragma GCC optimize( -fno-defer-pop )   long long int power(long long int a, long long int b, long long int m) {     if (b == 0) return 1;     if (b == 1) return a % m;     long long int t = power(a, b / 2, m) % m;     t = (t * t) % m;     if (b & 1) t = ((t % m) * (a % m)) % m;     return t;   }   long long int modInverse(long long int a, long long int m) {     return power(a, m - 2, m);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int q;     cin >> q;     while (q--) {       long long int i, j, k, l, n;       cin >> n >> k;       long long int ar[n + 1];       for (i = 1; i <= n; i++) {         cin >> ar[i];       }       vector<long long int> an;       long long int s = 0;       for (i = 1; i <= n; i++) {         s += ar[i];         if (s % 2) {           an.push_back(i);           s = 0;         } else if (i == n) {           if (an.size() > 0) {             an.pop_back();             an.push_back(i);           }         }       }       if (an.size() < k) {         cout <<  NO               <<   n ;       } else {         long long int v = (an.size() - k);         if (v % 2 == 0) {           cout <<  YES                 <<   n ;           i = v;           while (i < an.size()) {             cout << an[i] <<    ;             i++;           }           cout <<   n ;         } else {           cout <<  NO                 <<   n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 250 + 7;   int a[MAXN][MAXN], ans[MAXN][MAXN];   bool rmax[MAXN * MAXN], cmax[MAXN * MAXN], vis[MAXN * MAXN];   bool canr[MAXN], canc[MAXN];   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         scanf( %d , &a[i][j]);       }     for (int i = 1; i <= n; i++) {       int MAX = 0;       for (int j = 1; j <= m; j++) MAX = max(MAX, a[i][j]);       rmax[MAX] = 1;     }     for (int j = 1; j <= m; j++) {       int MAX = 0;       for (int i = 1; i <= n; i++) MAX = max(MAX, a[i][j]);       cmax[MAX] = 1;     }     int x = 0, y = 0;     queue<pair<int, int> > pos;     for (int num = n * m; num >= 1; num--) {       x += rmax[num];       y += cmax[num];       if (rmax[num] || cmax[num]) {         ans[x][y] = num;       } else {         pair<int, int> p = pos.front();         pos.pop();         ans[p.first][p.second] = num;       }       if (rmax[num]) {         canr[x] = 1;         for (int j = y - 1; j >= 1; j--)           if (canc[j]) pos.push({x, j});         for (int j = y + 1; j <= m; j++)           if (canc[j]) pos.push({x, j});       }       if (cmax[num]) {         canc[y] = 1;         for (int i = x - 1; i >= 1; i--)           if (canr[i]) pos.push({i, y});         for (int i = x + 1; i <= n; i++)           if (canr[i]) pos.push({i, y});       }     }     for (int i = 1; i <= n; i++, puts(  ))       for (int j = 1; j <= m; j++) printf( %d  , ans[i][j]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b, d = 0;     cin >> n >> a >> b;     n = n - a;     if (n <= b) {       cout << n;     } else {       cout << b + 1;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long i, j, k, n, t, x, l, r, m;     cin >> t;     while (t--) {       cin >> n;       k = n / 2;       long long sum = 0, y, cnt = 1;       x = 3;       y = 1;       while (k--) {         sum += ((x * 2 * cnt) + (y * 2 * cnt));         x += 2;         y += 2;         cnt++;       }       cout << sum <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   ll MOD = 1000000007;   ll mod = 998244353;   int inf = 1000001000;   ll INF = 1e18 + 5;   int main() {     std::cin.tie(nullptr);     std::ios::sync_with_stdio(false);     int t;     cin >> t;     for (int(_) = 0; (_) < (t); (_)++) {       int n;       cin >> n;       if (n == 1)         cout <<  FastestFinger  << endl;       else if (n == 2)         cout <<  Ashishgup  << endl;       else {         if (n % 2)           cout <<  Ashishgup  << endl;         else {           int cnt = 0;           while (n % 2 == 0) {             n /= 2;             cnt++;           }           if (n == 1) {             cout <<  FastestFinger  << endl;           } else {             if (cnt > 1)               cout <<  Ashishgup  << endl;             else {               int q = 0;               for (ll i = 3; i * i <= n; i += 2) {                 if (n % i == 0) {                   cout <<  Ashishgup  << endl;                   q++;                   break;                 }               }               if (q == 0) cout <<  FastestFinger  << endl;             }           }         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   const int FFTMOD = 119 << 23 | 1;   const int INF = (int)1e9 + 23111992;   const long long LINF = (long long)1e18 + 23111992;   const long double PI = acos((long double)-1);   const long double EPS = 1e-9;   inline long long gcd(long long a, long long b) {     long long r;     while (b) {       r = a % b;       a = b;       b = r;     }     return a;   }   inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   inline long long fpow(long long n, long long k, int p = MOD) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   template <class T>   inline int chkmin(T& a, const T& val) {     return val < a ? a = val, 1 : 0;   }   template <class T>   inline int chkmax(T& a, const T& val) {     return a < val ? a = val, 1 : 0;   }   inline unsigned long long isqrt(unsigned long long k) {     unsigned long long r = sqrt(k) + 1;     while (r * r > k) r--;     return r;   }   inline long long icbrt(long long k) {     long long r = cbrt(k) + 1;     while (r * r * r > k) r--;     return r;   }   inline void addmod(int& a, int val, int p = MOD) {     if ((a = (a + val)) >= p) a -= p;   }   inline void submod(int& a, int val, int p = MOD) {     if ((a = (a - val)) < 0) a += p;   }   inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }   inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }   inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }   inline int sign(long double x, long double y) { return sign(x - y); }   mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());   inline int myrand() { return abs((int)mt()); }   const int maxn = 2e6 + 5;   int fac[maxn];   int ifac[maxn];   int binom(int a, int b) {     if (a > b) return 0;     return mult(fac[b], mult(ifac[a], ifac[b - a]));   }   void chemthan() {     fac[0] = 1;     for (int i = (1); i < (maxn); ++i) fac[i] = mult(fac[i - 1], i);     for (int i = (0); i < (maxn); ++i) ifac[i] = inv(fac[i]);     int n, m, a, b;     cin >> n >> m >> a >> b;     int res = 0;     for (int k = (1); k < (n); ++k) {       int coef = binom(k - 1, m - 1);       int d = n - 1 - k;       int coef2 = !d ? 1 : mult(n - d, fpow(n, d - 1));       coef = mult(coef, fac[k - 1]);       addmod(res, mult(coef, mult(binom(k - 1, n - 2),                                   mult(coef2, fpow(m, n - k - 1)))));     }     cout << res <<   n ;   }   int main(int argc, char* argv[]) {     ios_base::sync_with_stdio(0), cin.tie(0);     if (argc > 1) {       assert(freopen(argv[1],  r , stdin));     }     if (argc > 2) {       assert(freopen(argv[2],  wb , stdout));     }     chemthan();     cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long sign = 1;     long long x = 0;     char ch;     while (!isdigit(ch = getchar()))       if (ch ==  - ) sign = -1;     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return x * sign;   }   inline void wonl() { putchar(  n ); }   inline void wws() { putchar(   ); }   inline void dbg() { cout << endl; }   inline void ww(long long k) {     if (k < 0) putchar( - ), k *= -1;     char ch[20];     int num = 0;     while (k) ch[++num] = k % 10, k /= 10;     if (num == 0) ch[++num] = 0;     while (num) putchar(ch[num--] +  0 );   }   const int N = 1e5 + 4;   template <typename T, typename... V>   inline void wonl(T t, V... v) {     ww(t);     if (sizeof...(v)) putchar(   );     wonl(v...);   }   template <typename T, typename... V>   inline void wws(T t, V... v) {     ww(t);     if (sizeof...(v)) putchar(   );     wws(v...);   }   template <typename T, typename... V>   inline void dbg(T t, V... v) {     cout <<     << t;     dbg(v...);   }   void solve() {     int n = read(), a;     map<int, int> ma;     for (int i = 0; i < n; i++) a = read(), ma[a]++;     vector<int> v;     for (auto it : ma) v.push_back(it.second);     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     long long num = 1;     while (v[0] >= num) num *= 2;     long long fans = 0;     while (num) {       long long ter = num;       long long a = INT_MAX;       int k = 0;       while (ter != 0 && k < v.size()) {         a = min(a, v[k] / ter), ter = ter / 2, k++;       }       if (ter == 0) fans = max(fans, a * (num * 2 - 1));       num = num / 2;     }     wonl(fans);   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 300000;   const long long mod = 1e9 + 7;   const long long inf = 1e18;   long long a[MX + 5];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long tc, cs = 1, i, j, k, x, y, z, n, m;     cin >> n;     for (i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + n + 1);     for (i = 1; i <= n; i++) a[i] += a[i - 1];     cin >> m;     for (i = 1; i <= m; i++) {       cin >> x;       y = a[n] - (a[n - x + 1] - a[n - x]);       cout << y << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int a[n], i, max = 0, f;     for (i = 0; i < n; i++) scanf( %d , &a[i]);     stack<int> s;     for (i = 0; i < n; i++) {       while (!s.empty()) {         if (s.top() < a[i]) {           f = s.top() ^ a[i];           s.pop();           if (f > max) max = f;         } else {           f = s.top() ^ a[i];           if (f > max) max = f;           break;         }       }       s.push(a[i]);     }     printf( %d , max);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n;     cin >> n;     while (n--) {       long long int m;       cin >> m;       if (m % 3 == 0 || m % 7 == 0)         cout <<  YES  << endl;       else {         long long int k = m / 3;         if (k >= 4)           cout <<  YES  << endl;         else {           if (m <= 8 || m == 11) cout <<  NO  << endl;         }         if (m == 10) cout <<  YES  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e3 + 5;   const int mod = 998244353;   map<pair<int, int>, int> mp;   pair<int, int> a[maxn], b[maxn];   int n;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d%d , &a[i].first, &a[i].second);     for (int i = 1; i <= n; ++i) scanf( %d%d , &b[i].first, &b[i].second);     if (n == 1) {       printf( %d %d n , a[1].first + b[1].first, a[1].second + b[1].second);       return 0;     }     for (int i = 1; i <= n; ++i) {       ++mp[{a[1].first + b[i].first, a[1].second + b[i].second}];     }     for (int i = 2; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         int x = a[i].first + b[j].first, y = a[i].second + b[j].second;         if (mp.find({x, y}) != mp.end()) ++mp[{x, y}];       }     }     for (auto it : mp) {       if (it.second == n) {         printf( %d %d n , it.first.first, it.first.second);         break;       }     }     return 0;   }


#include <bits/stdc++.h>   int GCD(int u, int v) {     while (v != 0) {       int r = u % v;       u = v;       v = r;     }     return u;   }   int main() {     int amtV;     int amtE;     std::vector<std::pair<int, int>> graph;     std::cin >> amtV >> amtE;     int connected = 0;     int remaining = amtE;     if (amtE >= amtV - 1) {       for (int i = 2; i <= amtV; i++) {         graph.push_back(std::pair<int, int>(i, 1));       }       remaining = amtE - (amtV - 1);       for (int i = 3; i <= amtV; i += 2) {         if (remaining == 0) break;         graph.push_back(std::pair<int, int>(i, 2));         remaining--;       }       int currInd = 3;       int currCompare;       while (remaining > 0 && currInd < amtV) {         currCompare = currInd + 1;         while (remaining > 0 && currCompare <= amtV) {           if (GCD(currInd, currCompare) == 1) {             graph.push_back(std::pair<int, int>(currInd, currCompare));             remaining--;           }           currCompare++;         }         currInd++;       }     }     if (remaining == 0) {       std::cout <<  Possible  << std::endl;       for (auto it = graph.begin(); it != graph.end(); it++) {         std::cout << it->first <<     << it->second << std::endl;       }     } else {       std::cout <<  Impossible  << std::endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dist(int x, int y) {     if (y > x)       return (y - x);     else       return (12 - x + y);   }   int main() {     int i, j, q, r, t;     string a, b, c;     cin >> a >> b >> c;     map<string, int> m;     m[ C ] = 1;     m[ C# ] = 2;     m[ D ] = 3;     m[ D# ] = 4;     m[ E ] = 5;     m[ F ] = 6;     m[ F# ] = 7;     m[ G ] = 8;     m[ G# ] = 9;     m[ A ] = 10;     m[ B ] = 11;     m[ H ] = 12;     int x, y, z;     x = m[a];     y = m[b];     z = m[c];     if (dist(x, y) == 3 && dist(y, z) == 4)       cout <<  minor ;     else if (dist(x, y) == 4 && dist(y, z) == 3)       cout <<  major ;     else if (dist(x, z) == 3 && dist(z, y) == 4)       cout <<  minor ;     else if (dist(x, z) == 4 && dist(z, y) == 3)       cout <<  major ;     else if (dist(y, x) == 3 && dist(x, z) == 4)       cout <<  minor ;     else if (dist(y, x) == 4 && dist(x, z) == 3)       cout <<  major ;     else if (dist(y, z) == 3 && dist(z, x) == 4)       cout <<  minor ;     else if (dist(y, z) == 4 && dist(z, x) == 3)       cout <<  major ;     else if (dist(z, x) == 3 && dist(x, y) == 4)       cout <<  minor ;     else if (dist(z, x) == 4 && dist(x, y) == 3)       cout <<  major ;     else if (dist(z, y) == 3 && dist(y, x) == 4)       cout <<  minor ;     else if (dist(z, y) == 4 && dist(y, x) == 3)       cout <<  major ;     else       cout <<  strange ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long x, y, n, m, t, q, a, b, count = 0;     cin >> n;     long long arr[n];     for (x = 0; x < n; x++) cin >> arr[x];     long long cop[n];     for (x = 0; x < n; x++) cop[x] = arr[x];     sort(cop, cop + n);     vector<long long> v;     for (x = 0; x < n; x++)       if (arr[x] != cop[x]) count++, v.push_back(x);     if (count <= 2)       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   using pii = pair<int, int>;   using pll = pair<long long, long long>;   using vb = vector<bool>;   using vi = vector<int>;   using vl = vector<long long>;   using vvb = vector<vector<bool>>;   using vvi = vector<vector<int>>;   using vvl = vector<vector<long long>>;   using vpii = vector<pair<int, int>>;   using mii = map<int, int>;   template <typename... ArgTypes>   void print(ArgTypes... args);   template <typename... ArgTypes>   void input(ArgTypes &...args);   template <>   void print() {}   template <>   void input() {}   template <typename T, typename... ArgTypes>   void print(T t, ArgTypes... args) {     cout << t;     print(args...);   }   template <typename T, typename... ArgTypes>   void input(T &t, ArgTypes &...args) {     cin >> t;     input(args...);   }   void traverse(int n, int mul) {     if (n == 0) return;     int a = n - n / 2, b = n - n / 3;     int x = 2, y = 3;     if (a >= b) {       swap(a, b);       swap(x, y);     }     for (int i = 1; i <= a; i++) cout << mul <<    ;     int remaining = n / x;     traverse(remaining, mul * x);   }   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     traverse(n, 1);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cout << fixed << setprecision(0) << powl(2, n + 1) - 2;   }


#include <bits/stdc++.h>   inline int two(int n) { return 1 << n; }   inline int test(int n, int b) { return (n >> b) & 1; }   inline void set_bit(int& n, int b) { n |= two(b); }   inline void unset_bit(int& n, int b) { n &= ~two(b); }   inline int last_bit(int n) { return n & (-n); }   inline int ones(int n) {     int res = 0;     while (n && ++res) n -= n & (-n);     return res;   }   long long int gcd(long long int a, long long int b) {     return (a ? gcd(b % a, a) : b);   }   long long int modPow(long long int a, long long int b, long long int MOD) {     long long int x = 1, y = a;     while (b > 0) {       if (b % 2 == 1) {         x = (x * y) % MOD;       }       b /= 2;       y = (y * y) % MOD;     }     return x;   }   long long int modInverse(long long int a, long long int p) {     return modPow(a, p - 2, p);   }   using namespace std;   const int N = 1e3 + 3;   int arr[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, i, j, l, r, taiyar, submit, ans, m;     ans = 0;     taiyar = 0;     submit = 0;     cin >> n;     for (int i = 0; i < (n); i++) {       cin >> arr[i];       taiyar += arr[i];     }     cin >> m;     while (m--) {       cin >> l >> r;       if (taiyar <= r) {         cout << max(taiyar, l);         return 0;       }     }     cout <<  -1 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double eps = 1e-7;   int main() {     int t;     double a, b, ans;     scanf( %d , &t);     while (t--) {       scanf( %lf%lf , &a, &b);       ans = 0.50000000;       if (b < eps) {         printf( %lf n , 1.0);         continue;       }       if (a < eps) {         printf( %lf n , 0.5);         continue;       }       if (a / b - 4.0 < -eps) {         ans += 0.5 * (a * a / 8.0) / (a * b);       } else {         ans += 0.5 * (a * b - b * 2.0 * b) / (a * b);       }       printf( %lf n , ans);     }     return 0;   }


#include <bits/stdc++.h>   #define ll long long   #define II pair<int,int>   #define fi first   #define se second   #define task  test    using namespace std;      void Init(){       ios::sync_with_stdio(0);       cin.tie(0);cout.tie(0);   }      int n;   int a[200001];   int res;      int d(II &a,II &b){       return abs(a.fi-b.fi)+b.se-a.se;   }      bool Check(int i,int j,int k){       II p={a[i],i};       II q={a[j],j};       II r={a[k],k};       //int s=d( p,q )+d( q,r ),S=d( p,r );       //cout<<i<<   <<j<<   <<k<<   <<s<<   <<S<<  n ;       return( d( p,q )+d( q,r )==d( p,r ) );   }      bool Cal(int l,int r){       for(int i=l;i<r;++i)       for(int j=i+1;j<r;++j)       if(Check(i,j,r))return 1;       res++;       return 0;   }      void Solve(){       cin>>n;       while(cin>>n){           for(int i=1;i<=n;++i)cin>>a[i];              res=0;           for(int i=1;i<=n;++i)           for(int j=i+2;j<=n;++j){               if(Cal(i,j))break;               //cout<<i<<   <<j<<  n ;           }              cout<<res+n+n-1<<  n ;       }   }      int main(){       Init();       Solve();   }


#include <bits/stdc++.h>   using namespace std;   int tata[2010], g[2010];   vector<pair<int, int>> edges;   bitset<2001> secret[2001];   int find(int x) {     return (tata[tata[x]] == tata[x] ? tata[x] : tata[x] = find(tata[x]));   }   void unite(int a, int b) {     a = find(a);     b = find(b);     assert(a != b);     if (g[a] >= g[b])       tata[b] = a, g[a] += g[b];     else       tata[a] = b, g[b] += g[a];   }   void test() {     edges.clear();     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       tata[i] = i, g[i] = 1;       secret[i] = bitset<2001>();     }     for (int i = 0; i < m; i++) {       string s;       cin >> s;       for (int j = 0; j < n; j++) secret[j][i] = s[j] -  0 ;     }     vector<pair<int, pair<int, int>>> ord;     for (int i = 0; i < n; i++)       for (int j = i + 1; j < n; j++)         ord.push_back({(secret[i] & secret[j]).count(), {i, j}});     sort(ord.rbegin(), ord.rend());     for (auto i : ord) {       if (find(i.second.first) == find(i.second.second)) continue;       unite(i.second.first, i.second.second);       edges.push_back({i.second.first, i.second.second});     }     for (int i = 0; i < m; i++) {       int nr = 0;       for (int j = 0; j < n; j++) nr += secret[j][i];       for (auto j : edges) nr -= secret[j.first][i] & secret[j.second][i];       if (nr != 1) {         cout <<  NO n ;         return;       }     }     cout <<  YES n ;     for (auto i : edges) cout << i.first + 1 <<     << i.second + 1 <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) test();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f, N = 10;   int ans = inf, n, k, idx[N];   char arr[N][N];   int convert(int num) {     int ret = 0;     for (int i = 0; i < k; ++i) {       ret = (ret * 10) + (arr[num][idx[i]] -  0 );     }     return ret;   }   int main() {     cin >> n >> k;     for (int i = 0; i < k; ++i) idx[i] = i;     for (int i = 0; i < n; ++i) scanf( %s , arr[i]);     do {       int mn = inf, mx = 0;       for (int i = 0; i < n; ++i) {         mn = min(mn, convert(i));         mx = max(mx, convert(i));       }       ans = min(ans, mx - mn);     } while (next_permutation(idx, idx + k));     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class A, class B>   inline bool mina(A &x, B y) {     return (x > y) ? (x = y, 1) : 0;   }   template <class A, class B>   inline bool maxa(A &x, B y) {     return (x < y) ? (x = y, 1) : 0;   }   template <class Value_t>   class SegmentTree {    public:     typedef struct segment_st {       Value_t value;       int left, right;     } TreeNode;     vector<TreeNode> tree;     int N;     int tree_size;     vector<int> leaves;     SegmentTree(int n) {       vector<Value_t> v(n);       build_tree(n, v);     }     SegmentTree(int n, vector<Value_t> &v) { build_tree(n, v); }     Value_t query(int ll, int rr) { return query(1, ll, rr); }     void update(int at, Value_t val) { internal_update(at, val); }       private:     void build_tree(int n, vector<Value_t> &v) {       N = n;       int base = 1;       while (base < N) base *= 2;       tree_size = base * 2;       leaves.resize(N + 1);       tree = vector<TreeNode>(tree_size);       init(1, 1, n, v);     }     void init(int at, int ll, int rr, vector<Value_t> &v) {       tree[at].left = ll;       tree[at].right = rr;       if (ll == rr) {         tree[at].value = v[ll - 1];         leaves[ll] = at;       } else {         int mid = (tree[at].left + tree[at].right) / 2;         init(at * 2, tree[at].left, mid, v);         init(at * 2 + 1, mid + 1, tree[at].right, v);         update_up(at);       }     }     Value_t initial_value() { return tuple<int, int>(-1, 0); }     Value_t node_to_value(int at) { return tree[at].value; }     void update_up(int at) {       tuple<int, int> left = node_to_value(at * 2);       tuple<int, int> right = node_to_value(at * 2 + 1);       if (get<0>(left) > get<0>(right)) {         tree[at].value = left;       } else {         tree[at].value = right;       }     }     void update_result(Value_t &res, Value_t val) {       if (get<0>(val) > get<0>(res)) {         res = val;       }     }     void update_leaf_value(int at, Value_t val) { tree[at].value = val; }     Value_t query(int at, int ll, int rr) {       if (tree[at].left == ll && tree[at].right == rr) {         return node_to_value(at);       } else {         int mid = (tree[at].left + tree[at].right) / 2;         Value_t res = initial_value();         if (ll <= mid) update_result(res, query(at * 2, ll, min(rr, mid)));         if (rr > mid) update_result(res, query(at * 2 + 1, max(mid + 1, ll), rr));         return res;       }     }     void internal_update(int at, Value_t val) {       at = leaves[at];       update_leaf_value(at, val);       at /= 2;       while (at) {         update_up(at);         at /= 2;       }     }   };   map<int, long long> ans[(100005)];   int in[(100005)];   int N, Q;   SegmentTree<tuple<int, int> > tree(1);   int solve2(int l, int r, int &x, int &y) {     tuple<int, int> a = tree.query(l, r - 1);     x = get<1>(a);     y = x + 1;     return get<0>(a);   }   long long solve(int l, int r) {     if (l >= r) return 0;     if (ans[l].find(r) != ans[l].end()) {       return ans[l][r];     }     int x = 0, y = 0;     long long L = solve2(l, r, x, y);     if (x > y) swap(x, y);     ans[l][r] = L * (x - l + 1) * (r - y + 1) + solve(l, x) + solve(y, r);     return ans[l][r];   }   int main() {     scanf( %d %d , &N, &Q);     for (int(i) = 0; (i) < (N); ++(i)) {       scanf( %d , &in[i]);     }     tree = SegmentTree<tuple<int, int> >(N - 1);     for (int(i) = 0; (i) < (N - 1); ++(i)) {       tree.update(i + 1, tuple<int, int>(abs(in[i + 1] - in[i]), i + 1));     }     int l, r;     for (int(q) = 0; (q) < (Q); ++(q)) {       scanf( %d %d , &l, &r);       printf( %I64d n , solve(l, r));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char* argv[]) {     int v1, v2, t, d, sum, a, t1, t2;     while (cin >> v1 >> v2 >> t >> d) {       sum = v1 + v2;       for (int i = 2; i < t; i++) {         if (v1 <= v2) {           v1 += d;           sum += v1;         } else {           v2 += d;           sum += v2;         }       }       cout << sum << endl;     }     return 0;   }


#include <bits/stdc++.h>   const int INF = 1e9 + 100;   const long long lINF = 4e18;   const double EPS = 1e-12;   using namespace std;   const int N = 5e5 + 100;   int n, k, h[N], s[N], mn = INF, mxh[N], should = INF;   vector<int> graph[N];   vector<int> can, need;   void dfs1(int v, int par = -1, int mx = INF) {     mxh[v] = mx;     mx = min(mx, h[v]);     can.push_back(mx);     for (auto j : graph[v]) {       if (j != par) dfs1(j, v, mx);     }   }   void dfs2(int v, int par, map<int, int>& ans) {     map<int, int> ans2;     for (auto j : graph[v]) {       if (j != par) {         dfs2(j, v, ans2);         if (ans.size() < ans2.size()) {           swap(ans, ans2);         }         for (auto k : ans2) {           ans[k.first] += k.second;         }         ans2.clear();       }     }     if (mxh[v] >= need[0] && h[v] <= should) {       bool flag = true;       ans[need[0]]++;       map<int, int>::reverse_iterator j = ans.rbegin();       for (int i = 0; i < (int)need.size(); i++) {         while (j != ans.rend() && j->second == 0) {           j++;         }         if (j == ans.rend() || j->first < need[i]) {           flag = false;         } else {           j->second--;         }       }       if (flag) {         mn = min(mn, need[0] - h[v]);       }       ans.clear();     } else {       while (ans.size() > 0 && ans.rbegin()->first > h[v]) {         int p = ans.rbegin()->second;         ans.erase(ans.rbegin()->first);         ans[h[v]] += p;       }       ans[h[v]]++;     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &h[i]);     }     for (int i = 0; i < n - 1; i++) {       int a, b;       scanf( %d%d , &a, &b);       graph[a].push_back(b);       graph[b].push_back(a);     }     scanf( %d , &k);     for (int i = 0; i < k; i++) {       scanf( %d , &s[i]);     }     dfs1(1);     sort(s, s + k);     reverse(s, s + k);     sort((can).begin(), (can).end());     reverse((can).begin(), (can).end());     for (int i = 0, j = 0, delta = 0; i < k; i++) {       delta--;       while (j < (int)can.size() && can[j] >= s[i]) {         j++;         delta++;       }       if (j < i + 1) {         should = min(should, s[i] - 1);       }       if (delta < 0) {         need.push_back(s[i]);         delta++;       }     }     if (need.size() == 0) {       cout << 0 << endl;     } else {       map<int, int> res;       dfs2(1, -1, res);       if (mn == INF) {         cout <<  -1  << endl;       } else {         cout << mn << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000;   bool isprime[maxn];   int p[5], s[5], n;   const int tenpow[6] = {1, 10, 100, 1000, 10000, 100000};   int tenpowmul[6][10];   int getd[maxn][5];   int ans;   bool good[2 * maxn][6];   int tans[maxn];   void solve(int i) {     if (i == 0) {       for (int i = 0; i < n; ++i) s[i] = tenpowmul[n - 1][getd[p[0]][n - 1 - i]];       solve(i + 1);     } else if (i + 1 == n)       ans += tans[s[i]];     else       for (int j = 0; j < tenpow[n - i]; ++j)         if (isprime[s[i] + j]) {           p[i] = s[i] + j;           int y[5], k;           for (k = i; k < n; ++k) {             s[k] += (y[k] = tenpowmul[n - i - 1][getd[p[i]][n - k - 1]]);             if (!good[s[k]][n - i]) break;           }           if (k == n) solve(i + 1), k--;           for (; k >= i; --k) s[k] -= y[k];         }   }   int main() {     for (int i = 0; i < (int)(6); ++i)       for (int j = 0; j < (int)(10); ++j) tenpowmul[i][j] = tenpow[i] * j;     for (int i = 0; i < (int)(maxn); ++i)       for (int j = 0; j < (int)(5); ++j) getd[i][j] = (i / tenpow[j]) % 10;     for (int i = (int)(2); i <= (int)(maxn); ++i) isprime[i] = 1;     for (int i = 2; i * i < maxn; ++i)       if (isprime[i])         for (int j = i * i; j < maxn; j += i) isprime[j] = 0;     for (int i = 0; i < (int)(maxn); ++i) good[i][0] = isprime[i];     for (int j = (int)(1); j <= (int)(5); ++j)       for (int i = 0; i < (int)(maxn); ++i)         for (int k = 0; k < (int)(10); ++k)           good[i][j] |= good[i + tenpowmul[j - 1][k]][j - 1];     for (int i = 0; i < (int)(maxn); ++i)       if (i % 10 == 0)         for (int k = 0; k < (int)(10); ++k) tans[i] += isprime[i + k];     int T;     cin >> T;     for (int _t = 0; _t < (int)(T); ++_t) {       cin >> p[0];       int k = 1;       n = 0;       while (k <= p[0]) k *= 10, n += 1;       for (int i = (int)(1); i <= (int)(n - 1); ++i) p[i] = 0;       ans = 0;       solve(0);       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch - 48;       ch = getchar();     }     return x * f;   }   namespace star {   const int maxn = 2e5 + 5;   int head[maxn], len[maxn], dis[maxn], pre[maxn];   int n, cnt = 1, m, ans;   char ch[maxn];   bool vis[maxn];   priority_queue<pair<int, int> > q;   queue<int> qt;   struct edge {     int to, nxt, val;   } e[maxn];   void add(int u, int v, int w) {     e[++cnt].to = v;     e[cnt].val = w;     e[cnt].nxt = head[u];     head[u] = cnt;     e[++cnt].to = u;     e[cnt].val = w;     e[cnt].nxt = head[v];     head[v] = cnt;   }   inline void dijkstra() {     memset(pre, 0, sizeof(pre));     memset(dis, 0x3f, sizeof(dis));     memset(len, 0x3f, sizeof(len));     qt.push(n);     dis[n] = 0;     len[n] = 1;     while (!qt.empty()) {       int u = qt.front();       qt.pop();       q.push(make_pair(0, u));       for (int i = head[u]; i; i = e[i].nxt) {         int v = e[i].to;         int w = e[i].val;         if (dis[v] && w == 0) {           dis[v] = 0;           len[v] = len[u] + 1;           pre[v] = (i ^ 1);           qt.push(v);         }       }     }     int pos = 0, lst = -1;     while (!q.empty()) {       int u = q.top().second;       q.pop();       if (vis[u]) continue;       vis[u] = true;       if (lst != dis[u]) pos++, lst = dis[u];       for (int i = head[u]; i; i = e[i].nxt) {         int v = e[i].to;         int w = e[i].val;         if (dis[v] > pos * 10 + w) {           dis[v] = pos * 10 + w;           len[v] = len[u] + 1;           pre[v] = i ^ 1;           q.push(make_pair(-dis[v], v));         } else if (dis[v] == pos * 10 + w && len[v] > len[u] + 1) {           len[v] = len[u] + 1;           pre[v] = i ^ 1;           q.push(make_pair(-dis[v], v));         }       }     }   }   void work() {     n = read();     m = read();     for (int a, b, i = 1; i <= m; i++)       a = read() + 1, b = read() + 1, add(a, b, read());     dijkstra();     int tmp = 1;     stack<int> s;     while (tmp != n) {       s.push(e[pre[tmp]].val);       tmp = e[pre[tmp]].to;     }     while (!s.empty() && s.top() == 0) s.pop();     if (s.empty())       printf( 0 );     else       while (!s.empty()) printf( %d , s.top()), s.pop();     putchar(  n );     printf( %d n0  , len[1]);     tmp = 1;     while (tmp != n) {       tmp = e[pre[tmp]].to;       printf( %d  , tmp - 1);     }   }   }  // namespace star   signed main() {     star::work();     return 0;   }


#include <bits/stdc++.h>   using ll = long long;   using namespace std;   int main() {     cin.tie(0);     ios_base::sync_with_stdio(false);     int n, m;     char c;     cin >> n >> m >> c;     vector<string> vec(n);     for (int i = 0; i < n; ++i) {       cin >> vec[i];     }     unordered_set<char> s;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (vec[i][j] == c) {           if (i - 1 >= 0 && vec[i - 1][j] !=  .  && vec[i - 1][j] != c) {             s.insert(vec[i - 1][j]);           }           if (j - 1 >= 0 && vec[i][j - 1] !=  .  && vec[i][j - 1] != c) {             s.insert(vec[i][j - 1]);           }           if (i + 1 < n && vec[i + 1][j] !=  .  && vec[i + 1][j] != c) {             s.insert(vec[i + 1][j]);           }           if (j + 1 < m && vec[i][j + 1] !=  .  && vec[i][j + 1] != c) {             s.insert(vec[i][j + 1]);           }         }       }     }     cout << s.size() <<   n ;     return 0;   }


#include<bits/stdc++.h>      using namespace std;   #define show(x) cout<< #x <<  =   << x <<    n  ;   #define mod 998244353   #define INF 1000000000000000000   #define pie 3.14159265358979323846   #define ll long long int   #define pb push_back   #define popcnt __builtin_popcount   #define mp make_pair   #define pii pair<ll,ll>   #define prod(a,b) ((a*b)%mod)   #define set0(x) memset(x,0,sizeof(x))   #define setm1(x) memset(x,-1,sizeof(x))   #define printlist(arr) for(auto lstelem :arr) cout<< lstelem <<    ;cout<<   n     #define all(a) a.begin(),a.end()   #define sqre(a) ((a)*(a))      //maths stuff   ll powr(ll a,ll b){       ll res=1;       while(b){           if(b%2)               res=(a*res)%mod;           a=(a*a)%mod;           b/=2;       }       return res;   }      void extentded_eucledian(ll a,ll b,ll &ex,ll &ey){       if(b==0){           ex=1;           ey=0;           return;       }       extentded_eucledian(b,a%b,ex,ey);       swap(ex,ey);       ey-= (a/b)*ex;//gcd= x*a+y*b   }      ll dp[1002][1002][2];      int main(){        #ifdef ONLINE_JUDGE           //onlinesubmission       #else       freopen( input.txt , r ,stdin);       #endif       ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);       string x,y; cin>> x >> y ;       ll n=x.size(),m=y.size();       set0(dp);       ll ans=0;       for(ll i=0;i<=n;++i){           for(ll j=0;j<=m;++j){               if(i>0) dp[i][j][0]=(dp[i][j][0]+1)%mod;               if(j>0) dp[i][j][1]=(dp[i][j][1]+1)%mod;               if(i>1){                   if(x[i-1]!=x[i-2]) dp[i][j][0]=(dp[i][j][0]+dp[i-1][j][0])%mod;               }               if(i>0 && j>0){                   if(x[i-1]!=y[j-1]){                       dp[i][j][0]=(dp[i][j][0]+dp[i-1][j][1])%mod;                       dp[i][j][1]=(dp[i][j][1]+dp[i][j-1][0])%mod;                   }               }               if(j>1){                   if(y[j-1]!=y[j-2]) dp[i][j][1]=(dp[i][j][1]+dp[i][j-1][1])%mod;               }               ans=(ans+dp[i][j][0]+dp[i][j][1])%mod;           }       }       for(ll i=0;i<n;++i){           ll j=i;           while(j+1<n) if(x[j]!=x[j+1]) ++j; else break;           ll l=(j-i+1),v=(( ((l+1)*l/2)%mod )*(m+1))%mod;           ans=(ans-v+mod)%mod;           i=j;       }       for(ll i=0;i<m;++i){           ll j=i;           while(j+1<m) if(y[j]!=y[j+1]) ++j; else break;           ll l=(j-i+1),v=((((l+1)*l/2)%mod)*(n+1))%mod;           ans=(ans-v+mod)%mod;           i=j;       }       cout<< ans ;       return 0;   }      //might1331 pratapSingh: Try Kr raha hu mai bc, timer laga rakha h


#include <bits/stdc++.h>   using namespace std;   bool prime(long long x) {     if (x == 2) {       return true;     }     if (x <= 1) {       return false;     }     for (int i = 2; i < sqrt(x); i++) {       if (x % i == 0) {         return false;       }     }     return true;   }   void printv(vector<long long> v) {     for (int i = 0; i < v.size(); i++) {       cout << v[i] <<    ;     }     cout << endl;   }   string Y =  YES n ;   string N =  NO n ;   int rec(string s, int pos, int team1, int team2) {     if (team1 < team2) {       if (5 - (ceil((pos * 1.0) / 2)) < (team2 - team1)) {         return pos;       }     } else {       if (5 - (pos / 2) < (team1 - team2)) {         return pos;       }     }     if (pos == 10) {       return 10;     }     int h = 10;     if (pos % 2 == 0) {       if (s[pos] ==  1 ) {         h = min(h, rec(s, pos + 1, team1 + 1, team2));       } else if (s[pos] ==  0 ) {         h = min(h, rec(s, pos + 1, team1, team2));       } else {         int x =             min(rec(s, pos + 1, team1 + 1, team2), rec(s, pos + 1, team1, team2));         h = min(x, h);       }     } else {       if (s[pos] ==  1 ) {         h = min(h, rec(s, pos + 1, team1, team2 + 1));       } else if (s[pos] ==  0 ) {         h = min(h, rec(s, pos + 1, team1, team2));       } else {         int x =             min(rec(s, pos + 1, team1, team2 + 1), rec(s, pos + 1, team1, team2));         h = min(x, h);       }     }     return h;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     for (int pop = 0; pop < t; pop++) {       string q;       cin >> q;       int c = rec(q, 0, 0, 0);       cout << c << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int k[3];   int t[3];   long long a[100010];   struct mydata {     int idx;     long long x;     bool operator<(const mydata &r) const {       if (x == r.x)         return idx < r.idx;       else         return x < r.x;     }   } b[100010];   std::priority_queue<long long, vector<long long>, greater<long long> > Q;   int main() {     int i;     cin >> k[0] >> k[1] >> k[2];     cin >> t[0] >> t[1] >> t[2];     int n;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     for (i = 0; i < n; i++) {       b[i].x = a[i];       b[i].idx = i;     }     for (i = 0; i < n; i++) {       if (k[0] > 0) {         b[i].x += t[0];         Q.push(b[i].x);         k[0]--;       } else {         long long x = Q.top();         Q.pop();         b[i].x = max(x, b[i].x) + t[0];         Q.push(b[i].x);       }     }     while (!Q.empty()) Q.pop();     sort(b, b + n);     for (i = 0; i < n; i++) {       if (k[1] > 0) {         b[i].x += t[1];         Q.push(b[i].x);         k[1]--;       } else {         long long x = Q.top();         Q.pop();         b[i].x = max(x, b[i].x) + t[1];         Q.push(b[i].x);       }     }     while (!Q.empty()) Q.pop();     sort(b, b + n);     for (i = 0; i < n; i++) {       if (k[2] > 0) {         b[i].x += t[2];         Q.push(b[i].x);         k[2]--;       } else {         long long x = Q.top();         Q.pop();         b[i].x = max(x, b[i].x) + t[2];         Q.push(b[i].x);       }     }     while (!Q.empty()) Q.pop();     sort(b, b + n);     long long ret = 0;     for (i = 0; i < n; i++) {       if (ret < b[i].x - a[b[i].idx]) ret = b[i].x - a[b[i].idx];     }     cout << ret << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005, MAXM = 1005;   bitset<MAXM> All, P[MAXM];   int n, m, Q;   int start[MAXN], cnt = 0;   int Ans[MAXN];   struct Node {     int op, x, y, id;   } T[MAXN];   struct Edge {     int next, to;   } edge[MAXN];   void add(int from, int to) {     cnt++;     edge[cnt].to = to;     edge[cnt].next = start[from];     start[from] = cnt;     return;   }   void DFS(int x, int from, int Now) {     bool q = 0;     if (T[x].op == 1) {       q = P[T[x].x][T[x].y];       if (P[T[x].x][T[x].y] == 0) Now++;       P[T[x].x][T[x].y] = 1;     }     if (T[x].op == 2) {       q = P[T[x].x][T[x].y];       if (P[T[x].x][T[x].y] == 1) Now--;       P[T[x].x][T[x].y] = 0;     }     if (T[x].op == 3) {       int A = P[T[x].x].count();       P[T[x].x] ^= All;       Now += P[T[x].x].count() - A;     }     Ans[T[x].id] = Now;     for (int i = start[x]; i; i = edge[i].next) {       int to = edge[i].to;       if (to != from) DFS(to, x, Now);     }     if (T[x].op <= 2) P[T[x].x][T[x].y] = q;     if (T[x].op == 3) P[T[x].x] ^= All;     return;   }   inline int read() {     int x = 0, flag = 1;     char ch = getchar();     for (; ch >  9  || ch <  0 ; ch = getchar())       if (ch ==  - ) flag = -1;     for (; ch >=  0  && ch <=  9 ; ch = getchar())       x = (x << 3) + (x << 1) + ch -  0 ;     return x * flag;   }   int main() {     n = read(), m = read(), Q = read();     for (int i = 1; i <= m; i++) All[i] = 1;     for (int i = 1; i <= n; i++) P[i].reset();     T[0].x = T[0].y = 0;     for (int i = 1; i <= Q; i++) {       T[i].op = read();       T[i].id = i;       if (T[i].op <= 2)         T[i].x = read(), T[i].y = read();       else         T[i].x = read();       if (T[i].op <= 3)         add(i - 1, i);       else         add(T[i].x, i);     }     DFS(0, 0, 0);     for (int i = 1; i <= Q; i++) cout << Ans[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T, class L>   bool smax(T& x, L y) {     return x < y ? (x = y, 1) : 0;   }   template <class T, class L>   bool smin(T& x, L y) {     return x > y ? (x = y, 1) : 0;   }   const int maxn = 2e5 + 17;   int n, m, gp[maxn], rate[maxn], cnt, sz[maxn];   unordered_map<int, pair<int, int> > p;   set<int> s[maxn];   vector<int> ag[maxn];   void dfs(int v, int rt = 0) {     if (gp[v]) return;     gp[v] = cnt, rate[v] = rt;     s[cnt].insert(rt);     sz[cnt]++;     dfs((v + m) % n, rt + 1);   }   int main() {     long long ans = 0;     p.max_load_factor(0.25), p.reserve(512);     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++)       if (!gp[i]) cnt++, dfs(i);     int q;     cin >> q;     for (int id, h; q--;) {       char c;       scanf(  %c %d , &c, &id);       if (c ==  + ) {         scanf( %d , &h);         int g = gp[h], r = rate[h];         auto it = s[g].lower_bound(r);         if (it == s[g].end()) it = s[g].begin(), ans += sz[g];         ans += *it - r;         p[id] = {g, *it};         s[g].erase(it);       } else {         auto tmp = p[id];         s[tmp.first].insert(tmp.second);       }     }     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> mp;   long long v[100000];   vector<long long> V[200005];   long long sum[200005] = {0}, l[5005], r[5005], ans[5005];   int main() {     long long int n, k, q, i, j, a, b, d, l1, t, sm = 0;     cin >> t;     for (i = 1; i <= t; i++) {       cin >> l[i];     }     for (i = 1; i <= t; i++) {       memset(r, 0, sizeof(r));       long long mx = 0, w = -1;       for (j = i; j <= t; j++) {         r[l[j]]++;         if (r[l[j]] > mx) {           mx = r[l[j]];           w = l[j];         } else if (r[l[j]] == mx && w > l[j]) {           w = l[j];         }         ans[w]++;       }     }     for (i = 1; i <= t; i++) {       cout << ans[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   const int MAX = 1e5 + 5;   const long long MAX2 = 11;   const int MOD = 1000000000 + 7;   const long long INF = 20000;   const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1};   const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};   const double pi = acos(-1);   long long n;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     cout << n / 2520;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char str[1000001];   int main() {     int n;     scanf( %d , &n);     scanf( %s , str);     int sum = 0;     int ln = -1;     int i, j, k, ans = 0;     for (i = 0; i < n; i++) {       if (str[i] ==  ( ) {         sum++;         if (sum == 0) {           ans += i - ln + 1;           ln = -1;         }       } else {         sum--;         if (sum < 0 && ln == -1) ln = i;       }     }     if (sum != 0) {       printf( -1 n );     } else       printf( %d n , ans);     return 0;   }