#include <bits/stdc++.h>   const long long mod = 1000000007;   const long long Inf = 2 * 1e9;   using namespace std;   long long toint(string s) {     long long anss = 0;     for (int(i) = 0; (i) < s.length(); (i)++) anss = anss * 10 + (s[i] -  0 );     return anss;   }   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   vector<bool> used(200001, false);   vector<int> g(200001);   void dfs(int v) {     used[v] = true;     if (!used[g[v]]) dfs(g[v]);   }   int main() {     int n;     cin >> n;     vector<int> t(n + 1), ch(n + 1);     for (int(i) = 1; (i) < n + 1; (i)++) {       scanf( %d , &t[i]);       if (i > 1) t[i] -= t[1];     }     t[1] = 0;     ch[0] = 0;     for (int(i) = 1; (i) < n + 1; (i)++) {       int ans = 20;       ch[i] = ch[i - 1];       int pos =           lower_bound((t).begin(), (t).end(), max(0, t[i] - 89)) - t.begin();       int sum = ch[i] - ch[max(0, pos - 1)];       ans = min({ans, 50 - sum});       pos = lower_bound((t).begin(), (t).end(), max(0, t[i] - 1439)) - t.begin();       sum = ch[i] - ch[max(0, pos - 1)];       ans = min({ans, 120 - sum});       ch[i] += ans;       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void input() {}   int main() {     input();     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     if (n % 2 == 0)       cout << -1 <<   n ;     else {       for (int i = 0; i < n; i++) cout << i <<    ;       cout <<   n ;       for (int i = 0; i < n; i++) cout << i <<    ;       cout <<   n ;       for (int i = 0; i < n; i++) cout << (2 * i) % n <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int i, j, k, n, m, l;   const int N = 1e5 + 8;   int vis[N];   vector<int> adj[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     queue<int> q;     q.push(1);     memset(vis, 0, sizeof(vis));     vis[1] = 1;     l = 0;     long long ev = 0, od = 0;     while (1) {       int c = q.size();       if (!c) break;       while (c) {         int s = q.front();         q.pop();         c--;         if (l & 1)           ev++;         else           od++;         for (auto u : adj[s]) {           if (!vis[u]) {             vis[u] = 1;             q.push(u);           }         }       }       l++;     }     cout << (ev * od - (n - 1)) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double r[1000];   double p = atan(1.) * 4.;   int main() {     double rez = 0;     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> r[i];     sort(r, r + n);     bool t = true;     for (int i = n - 1; i >= 0; i--) {       if (t)         rez += r[i] * r[i] * p;       else         rez -= r[i] * r[i] * p;       t = !t;     }     printf( %.6f , rez);     cin >> n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     getline(cin, s);     int i = s.size() - 1;     while (s[i] ==  ? ) {       i--;     }     while (s[i] == 32) {       i--;     }     if (s[i] ==  y  || s[i] ==  u  || s[i] ==  o  || s[i] ==  i  || s[i] ==  e  ||         s[i] ==  a ) {       cout <<  YES ;       return 0;     }     if (s[i] ==  Y  || s[i] ==  U  || s[i] ==  O  || s[i] ==  I  || s[i] ==  E  ||         s[i] ==  A ) {       cout <<  YES ;       return 0;     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double eps = 1e-6;   const int INF = 0x3f3f3f3f;   const int MAXN = 1e5 + 10;   int cnt, head[MAXN], tot;   int n, tim, a[MAXN], root[MAXN];   struct Poi {     int w, dfn, dep, col;   } poi[MAXN];   bool cmp(int a, int b) { return poi[a].dep < poi[b].dep; }   struct Edge {     int v, nex;   } edge[MAXN * 2];   struct Node {     int l, r, m;   } node[MAXN * 20];   void add(int u, int v) {     edge[cnt] = {v, head[u]};     head[u] = cnt++;   }   void dfs(int u, int fa) {     poi[u].dep = poi[fa].dep + 1;     poi[u].dfn = ++tim;     for (int i = head[u]; ~i; i = edge[i].nex) {       int v = edge[i].v;       if (v == fa) continue;       dfs(v, u);     }     poi[u].col = tim;   }   void up(int rt) { node[rt].m = min(node[node[rt].l].m, node[node[rt].r].m); }   void update(int &rt, int l, int r, int k, int x) {     node[++tot] = node[rt];     rt = tot;     if (l == r) {       node[rt].m = x;       return;     }     int mid = ((l + r) >> 1);     if (k <= mid)       update(node[rt].l, l, mid, k, x);     else       update(node[rt].r, mid + 1, r, k, x);     up(rt);   }   int bin(int x) {     int l = 1, r = n;     while (l <= r) {       int mid = ((l + r) >> 1);       if (poi[a[mid]].dep <= x)         l = mid + 1;       else         r = mid - 1;     }     return r;   }   int query(int rt, int l, int r, int L, int R) {     if (l == L && r == R) return node[rt].m;     int mid = ((l + r) >> 1);     if (R <= mid)       return query(node[rt].l, l, mid, L, R);     else if (L > mid)       return query(node[rt].r, mid + 1, r, L, R);     else {       int a = query(node[rt].l, l, mid, L, mid);       int b = query(node[rt].r, mid + 1, r, mid + 1, R);       return min(a, b);     }   }   inline int read() {     int k = 0;     char f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) k = k * 10 + c -  0 ;     return k * f;   }   int main() {     int s;     memset(head, -1, sizeof head);     cin >> n >> s;     for (int i = 1; i <= n; i++) poi[i].w = read(), a[i] = i;     for (int i = 1; i < n; i++) {       int u, v;       u = read(), v = read();       add(u, v);       add(v, u);     }     dfs(s, 0);     sort(a + 1, a + 1 + n, cmp);     node[0].m = INF;     for (int i = 1; i <= n; i++) {       root[i] = root[i - 1];       int idx = a[i];       int p = poi[idx].dfn;       int w = poi[idx].w;       update(root[i], 1, n, p, w);     }     int m;     cin >> m;     int ans = 0;     while (m--) {       int x, k;       x = read(), k = read();       x = (x + ans) % n + 1;       k = (k + ans) % n;       int dep = poi[x].dep + k;       int l = poi[x].dfn, r = poi[x].col;       int p = bin(dep);       ans = query(root[p], 1, n, l, r);       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     for (int row = -n; row <= n; row++) {       int top = n - abs(row);       for (int i = 0; i < abs(row); i++) {         cout <<     ;       }       for (int i = 0; i < top; ++i) {         cout << i <<    ;       }       for (int i = top; i > 0; --i) {         cout << i <<    ;       }       cout << 0 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n, d = 0;     n = s.size();     for (int i = 0; i < n; i++) {       if (s[i] ==  o ) d++;     }     if (d == 0) {       cout <<  YES ;       return 0;     }     if ((n - d) % d == 0) {       cout <<  YES ;       return 0;     }     cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 10002;   const int maxm = 15000002;   int f[maxm], p[maxn];   bool v[maxn];   int a[maxn];   int n, m, s;   int main() {     int i, j;     for (i = 2; i < 12; i++) {       if (!v[i]) p[s++] = i;       for (j = 0; j < s && i * p[j] < 12; j++) {         v[i * p[j]] = 1;         if (i % p[j] == 0) break;       }     }     for (i = 2; i < maxm; i++)       if (!f[i])         for (j = i; j < maxm; j += i) f[j] = i;     scanf( %d , &n);     m = 1;     for (j = 0; j < s; ++j) {       m *= p[j];       if (m > n) break;     }     --j;     m = 0;     for (i = 2; i <= 2 * n * n && i < maxm; ++i)       if (f[i] <= p[j]) {         a[m++] = i;       }     sort(a, a + m);     reverse(a, a + m);     for (i = 0; i < n; ++i) printf( %d  , a[i]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   int minx, miny, minz, maxx, maxy, maxz, n, m, Q, x, y, z, mx1, mn1, mx2, mn2,       mx3, mn3, D, cnt;   using namespace std;   struct node {     int l, r, maxx, maxy, maxz, minx, miny, minz, d[3];   } t[2000005];   inline bool cmp(node aa, node bb) {     if (aa.d[D] == bb.d[D]) {       if (aa.d[(D + 1) % 3] == bb.d[(D + 1) % 3])         return aa.d[(D + 2) % 3] < bb.d[(D + 2) % 3];       return aa.d[(D + 1) % 3] < bb.d[(D + 1) % 3];     }     return aa.d[D] < bb.d[D];   }   inline void update(int x, int y) {     t[x].maxx = max(t[x].maxx, t[y].maxx);     t[x].minx = min(t[x].minx, t[y].minx);     t[x].maxy = max(t[x].maxy, t[y].maxy);     t[x].miny = min(t[x].miny, t[y].miny);     t[x].maxz = max(t[x].maxz, t[y].maxz);     t[x].minz = min(t[x].minz, t[y].minz);   }   int build(int l, int r, int d) {     int mid = (l + r) >> 1;     D = d;     nth_element(t + l, t + mid, t + r + 1, cmp);     t[mid].minx = t[mid].maxx = t[mid].d[0];     t[mid].miny = t[mid].maxy = t[mid].d[1];     t[mid].minz = t[mid].maxz = t[mid].d[2];     if (l < mid) t[mid].l = build(l, mid - 1, (d + 1) % 3), update(mid, t[mid].l);     ;     if (r > mid) t[mid].r = build(mid + 1, r, (d + 1) % 3), update(mid, t[mid].r);     ;     return mid;   }   bool inc(int l1, int r1, int l2, int r2) {     if (l1 > r2 || l2 > r1)       return 0;     else       return 1;   }   bool in(int d) {     if (!inc(t[d].minx, t[d].maxx, mn1, mx1)) return 0;     if (!inc(t[d].miny, t[d].maxy, mn2, mx2)) return 0;     if (!inc(t[d].minz, t[d].maxz, mn3, mx3)) return 0;     return 0 ^ 1;   }   bool check(int l1, int r1, int l2, int r2) { return l2 <= l1 && r2 >= r1; }   bool check(int d) {     if (!check(t[d].minx, t[d].maxx, mn1, mx1)) return 0;     if (!check(t[d].miny, t[d].maxy, mn2, mx2)) return 0;     if (!check(t[d].minz, t[d].maxz, mn3, mx3)) return 0;     return 1;   }   int query(int k) {     if (!k) return 0;     if (!in(k)) return 0;     if (check(k)) return 0 ^ 1;     if (t[k].d[0] >= mn1 && t[k].d[0] <= mx1 && t[k].d[1] >= mn2 &&         t[k].d[1] <= mx2 && t[k].d[2] >= mn3 && t[k].d[2] <= mx3)       return 0 ^ 1;     if (query(t[k].l)) return 1;     if (query(t[k].r)) return 1;     return 0;   }   inline int read() {     char ch = getchar();     int f = 1, w = 0;     for (; ch <  0  || ch >  9 ; ch = getchar())       if (ch ==  - ) f = -1;     for (; ch >=  0  && ch <=  9 ; ch = getchar()) w = w * 10 + ch -  0 ;     return w * f;   }   int main() {     minx = read();     miny = read();     minz = read();     n = read();     m = read();     Q = read();     maxx = maxy = maxz = 1;     for (int i = 1; i <= n; i++) {       x = read();       y = read();       z = read();       minx = min(minx, x);       maxx = max(maxx, x);       miny = min(miny, y);       maxy = max(maxy, y);       minz = min(minz, z);       maxz = max(maxz, z);     }     for (int i = 1; i <= m; i++) {       x = read();       y = read();       z = read();       if (x >= minx && x <= maxx && y >= miny && y <= maxy && z <= maxz &&           z >= minz)         return puts( INCORRECT ), 0;       t[++cnt].d[0] = x;       t[cnt].d[1] = y;       t[cnt].d[2] = z;     }     puts( CORRECT );     int rt = build(1, cnt, 1);     while (Q--) {       x = read();       y = read();       z = read();       if (minx <= x && x <= maxx && miny <= y && y <= maxy && minz <= z &&           z <= maxz) {         puts( OPEN );         continue;       }       mx1 = max(x, maxx);       mn1 = min(x, minx);       mx2 = max(y, maxy);       mn2 = min(y, miny);       mx3 = max(z, maxz);       mn3 = min(z, minz);       if (query(rt))         puts( CLOSED );       else         puts( UNKNOWN );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool debug = false;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   long long ln, lk, lm;   int gg(int x, int y) {     int z = y;     while (x % y != 0) {       z = x % y;       x = y;       y = z;     }     return z;   }   map<int, vector<int>> X[2];   map<pair<pair<int, int>, pair<int, int>>, vector<int>> mp[2];   int cx[20005], cy[20005], cr[20005], ans;   int dis(int i, int j) {     return (cx[i] - cx[j]) * (cx[i] - cx[j]) + (cy[i] - cy[j]) * (cy[i] - cy[j]);   }   pair<int, int> gett(int x, int y) {     if (y == 0) return {0, 1};     int tmp = gg(abs(x), abs(y));     pair<int, int> tt = {abs(y / tmp), abs(x / tmp)};     if ((y < 0 && x > 0) || (y > 0 && x < 0)) tt.second *= -1;     return tt;   }   void cal(int i, int j) {     if (cy[i] == cy[j]) {       int x = cx[i] + cx[j];       if (x % 2 != 0) return;       x /= 2;       auto p = X[0][x];       int sz = p.size();       if (sz == 0) return;       int tar = cy[i];       int c = p.end() - upper_bound(p.begin(), p.end(), tar);       p = X[1][x];       c += sz - (p.end() - lower_bound(p.begin(), p.end(), tar));       ans += sz - c;       return;     }     int x = cx[i] - cx[j], y = cy[i] - cy[j];     int zx = (cx[i] + cx[j]), zy = (cy[i] + cy[j]);     pair<int, int> kk = gett(y * -1, x);     pair<int, int> bb = gett(kk.second * 2, kk.second * zy - kk.first * zx);     if (mp[0].find({kk, bb}) == mp[0].end()) return;     auto p = mp[0][{kk, bb}];     int sz = p.size();     int tar = zx / 2;     int c = p.end() - upper_bound(p.begin(), p.end(), tar);     p = mp[1][{kk, bb}];     c += sz - (p.end() - lower_bound(p.begin(), p.end(), tar));     ans += sz - c;   }   int main() {     scanf( %d%d , &n, &m);     int a, b, c, d;     for (int(i) = 0; (i) < (int)(n); (i)++) {       scanf( %d%d%d%d , &a, &b, &c, &d);       if (a == c) {         X[0][a].push_back({min(b, d)});         X[1][a].push_back({max(b, d)});       } else {         int x = a - c, y = b - d;         pair<int, int> tt = gett(x, y);         y = d * a - c * b;         pair<int, int> bb = gett(x, y);         mp[0][{tt, bb}].push_back(min(a, c));         mp[1][{tt, bb}].push_back(max(a, c));       }     }     for (int(i) = 0; (i) < (int)(2); (i)++) {       for (auto &p : X[i]) sort(p.second.begin(), p.second.end());       for (auto &p : mp[i]) sort(p.second.begin(), p.second.end());     }     for (int(i) = 0; (i) < (int)(m); (i)++)       scanf( %d%d%d , cx + i, cy + i, cr + i);     for (int(i) = 0; (i) < (int)(m); (i)++)       for (int j = i + 1; j < m; j++)         if (cr[i] == cr[j]) {           int D = cr[i] + cr[j];           D *= D;           if (dis(i, j) > D) {             cal(i, j);           }         }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MN = 200010;   int a[MN], b[MN], p[MN], q[MN];   char ans[MN];   int main() {     int t, m, k;     for (scanf( %d , &t); t--;) {       scanf( %d%d , &m, &k);       int pos = 0, pos1;       for (int i = 1; i <= k; i++) {         scanf( %d , &a[i]);       }       bool flag = false;       for (int i = 1; i < m; i++) {         scanf( %d%d , &p[i], &q[i]);         if (q[i] == 1 && !flag) {           flag = true;           for (int j = 1; j <= k; j++) {             b[j] = a[j];           }           pos1 = pos;         }         if (p[i] != 0) {           a[p[i]]--;         } else {           pos++;         }       }       int minA = MN;       if (flag) {         for (int i = 1; i <= k; i++) {           if (a[i] == b[i]) {             minA = min(minA, a[i]);           }         }         pos -= minA;       }       for (int i = 1; i <= k; i++) {         if (flag && a[i] == b[i] && a[i] <= pos1) {           printf( Y );         } else {           printf( %c , (a[i] > pos ?  N  :  Y ));         }       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char a[10][10];     char b[10][10];     vector<char> v, l;     long long int i, count = 0, j;     for (i = 0; i < 2; i++) {       for (j = 0; j < 2; j++) {         cin >> a[i][j];       }     }     v.push_back(a[0][0]);     v.push_back(a[0][1]);     v.push_back(a[1][1]);     v.push_back(a[1][0]);     for (i = 0; i < 2; i++) {       for (j = 0; j < 2; j++) {         cin >> b[i][j];       }     }     l.push_back(b[0][0]);     l.push_back(b[0][1]);     l.push_back(b[1][1]);     l.push_back(b[1][0]);     int flag = 0;     v.erase(remove(v.begin(), v.end(),  X ), v.end());     l.erase(remove(l.begin(), l.end(),  X ), l.end());     for (i = 0; i < 3; i++) {       if (equal(v.begin(), v.end(), l.begin())) {         flag = 1;         break;       } else {         vector<char>::iterator k = v.begin() + 2;         char la = *k;         v.insert(v.begin(), *k);         v.erase(v.begin() + 3);       }     }     if (flag)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     vector<int> a(n);     int sum = 0, maxi = -1;     for (int i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];       maxi = max(a[i], maxi);     }     if (maxi > (sum / 2))       cout <<  T             <<   n ;     else {       if (sum % 2 == 0)         cout <<  HL               <<   n ;       else         cout <<  T               <<   n ;     }   }   int main() {     int t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   int main() {     int k, d, i, n, x;     scanf( %d%d , &k, &d);     n = k;     x = d;     if ((k > 1) && (d == 0)) {       printf( No solution );     } else {       for (i = 1; ((i < n) && (x > 0)); i++) {         printf( 1 );         x--;       }       while (i < n) {         printf( 0 );         i++;       }       if (x == 0) {         printf( 0 );       } else {         printf( %d , (d - i + 1));       }     }   }


#include <bits/stdc++.h>   int main() {     int n, o, i, k, m;     scanf( %d%d , &n, &o);     scanf( %d%d , &k, &m);     int a[n], b[o];     for (i = 0; i < n; i++) scanf( %d , &a[i]);     for (i = 0; i < o; i++) scanf( %d , &b[i]);     if (a[k - 1] < b[o - m])       printf( YES );     else       printf( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 5e5 + 9;   vector<long long> adj[N], vec[N];   long long h[N], up[N], ans[N];   pair<long long, long long> edge[N];   vector<pair<long long, long long> > a[N];   void DFS1(long long u, long long par) {     h[u] = 1;     for (long long v : adj[u])       if (v != par) {         DFS1(v, u);         h[u] = max(h[u], h[v] + 1);         vec[u].push_back(h[v]);       }   }   void DFS2(long long u, long long par) {     multiset<long long> s;     for (long long v : adj[u])       if (v != par) s.insert(-h[v]);     for (long long v : adj[u])       if (v != par) {         s.erase(s.find(-h[v]));         up[v] = up[u] + 1;         if (!s.empty()) up[v] = max(up[v], -(*s.begin()) + 1);         vec[v].push_back(up[v]);         s.insert(-h[v]);       }     for (long long v : adj[u])       if (v != par) DFS2(v, u);   }   void DFS3(long long u, long long par) {     for (long long v : adj[u])       if (v != par) {         vector<pair<long long, long long> > b;         long long iu = 0, iv = 0;         while (iu < a[u].size() && iv < a[v].size()) {           if (a[u][iu].first < a[v][iv].first)             b.push_back(a[u][iu++]);           else if (a[u][iu].first > a[v][iv].first)             b.push_back(a[v][iv++]);           else if (a[u][iu].first == a[v][iv].first)             b.push_back({a[v][iv].first, a[v][iv++].second + a[u][iu++].second});         }         while (iv < a[v].size()) b.push_back(a[v][iv++]);         while (iu < a[u].size()) b.push_back(a[u][iu++]);         for (long long i = 0; i < b.size(); i++) {           if (b[i].first == up[v]) b[i].second--;           if (b[i].first == h[v]) b[i].second--;         }         long long num = 0;         while (b.size()) {           ans[b.back().first * 2] =               max(ans[b.back().first * 2], (num += b.back().second));           b.pop_back();         }         DFS3(v, u);       }   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     for (long long i = 1; i < n; i++) {       long long u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     fill(ans, ans + N, 1);     DFS1(1, 0);     DFS2(1, 0);     for (long long i = 1; i <= n; i++) {       sort(vec[i].begin(), vec[i].end());       for (long long j = 0; j < vec[i].size() - 1; j++)         if (vec[i][j] != vec[i][j + 1])           ans[vec[i][j] * 2 + 1] =               max(ans[vec[i][j] * 2 + 1], (long long)vec[i].size() - j);       for (long long j = 0; j < vec[i].size(); j++)         ans[vec[i][j] * 2 - 1] =             max(ans[vec[i][j] * 2 - 1], (long long)vec[i].size() - j),                             ans[vec[i][j] * 2] = max(                                 ans[vec[i][j] * 2], (long long)vec[i].size() - j);       for (long long j = 0, k = 0; max(j, k) < vec[i].size(); j = k) {         while (k < vec[i].size() && vec[i][j] == vec[i][k]) k++;         a[i].push_back({vec[i][j], k - j});       }     }     DFS3(1, 0);     for (long long i = n; i > 0; i--) ans[i] = max(ans[i], ans[i + 2]);     for (long long i = 1; i <= n; i++)       ans[1] = max(ans[1], (long long)adj[i].size() + 1);     for (long long i = 1; i <= n; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool dp[10005][3];   int main() {     int n, i;     string s;     set<string> ans;     cin >> s;     n = s.length();     for (i = n - 1; i >= 5; i--) {       if (i + 2 <= n) {         if (i + 2 == n || dp[i + 2][1] ||             (dp[i + 2][0] && s.substr(i + 2, 2) != s.substr(i, 2))) {           dp[i][0] = true;           ans.insert(s.substr(i, 2));         }       }       if (i + 3 <= n) {         if (i + 3 == n || dp[i + 3][0] ||             (dp[i + 3][1] && s.substr(i + 3, 3) != s.substr(i, 3))) {           dp[i][1] = true;           ans.insert(s.substr(i, 3));         }       }     }     cout << ans.size() << endl;     while (!ans.empty()) {       cout << *ans.begin() << endl;       ans.erase(ans.begin());     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 345;   int ai[maxn];   int bi[maxn];   bool used[maxn];   int m, r, t;   void init() {     for (int i = 1; i <= m; i++) {       scanf( %d , &ai[i]);       ai[i]++;     }   }   vector<int> V;   void play() {     memset(bi, 0, sizeof(bi));     memset(used, 0, sizeof(used));     V.clear();     if (t < r) {       printf( -1 n );       return;     }     long long sum = 0;     for (int i = 1; i <= m; i++) {       int st = 0;       while (bi[ai[i]] < r) {         for (int j = ai[i] - st; j <= ai[i] - st + t - 1; j++) {           if (j <= 0 || j > 320) continue;           bi[j]++;         }         sum++;         st++;       }     }     printf( %I64d n , sum);   }   int main() {     while (scanf( %d%d%d , &m, &t, &r) != EOF) {       init();       play();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7, N = 1e5 + 5;   int main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     long long a[n + 5], ans = 0, maxx = 0, sum = 0;     vector<long long> e, o;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] & 1)         e.push_back(a[i]);       else         o.push_back(a[i]);       maxx = max(a[i], maxx);       sum += a[i];     }     sort(e.begin(), e.end()), sort(o.begin(), o.end());     long long es = (long long)e.size(), os = (long long)o.size();     if (abs(es - os) <= 1) {       cout << 0;       return 0;     }     if (es == 0 || os == 0) {       cout << sum - maxx;       return 0;     }     if (es > os) {       for (int i = 0; i < (es - os - 1); i++) {         ans += e[i];       }     } else {       for (int i = 0; i < (os - es - 1); i++) {         ans += o[i];       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k, x, y;     scanf( %d%d%d , &n, &m, &k);     bool f = false;     while (k--) {       scanf( %d%d , &x, &y);       int mn = (1 << 20);       for (int i = 1; i <= n; ++i)         for (int j = 1; j <= m; ++j)           if (i == 1 || j == 1 || i == n || j == m)             mn = min(mn, abs(i - x) + abs(j - y));       if (mn <= 4) f = true;     }     if (f)       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }


#include<bits/stdc++.h>   using namespace std;       #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);   #define int long long   #define rep(i,a,b)    for(int i=a;i<b;i++)   #define repn(i,a,b)   for(int i=a;i>=b;i--)   #define ff first   #define ss second   #define lb lower_bound   #define ub upper_bound   #define pii pair<int,int>   #define vi vector<int>   #define vs vector<string>   #define vii vector<pii>   #define vvi vector<vector<int>>   #define vvii vector<vector<pii>>   #define pb push_back   #define ppb pop_back   #define pf push_front   #define ppf pop_front   #define sz(x) (int)x.size()   #define all(v) (v).begin(), (v).end()      #define ret(x) return cout<<x,0;   #define rety return cout<< YES ,0;   #define retn return cout<< NO ,0;   #define fl fflush(stdout)      #define hell 1000000007   #define hell2 998244353    #define pi 3.14159265358979323846      int solve(){       int n,m;       cin >> n >> m;       string s,a;       cin >> s;       a = s;       for(int i = 0; i < min(m,n); i++){           int x{};           for(int j = 0; j < n; j++){               if(j == 0){                   if(s[1] ==  1  && s[0] ==  0 )                       a[0] =  1 ;                   x++;                   }               else if(j == n-1){                   if(s[n-1] ==  0  && s[n-2] ==  1 )                       a[n-1] =  1 ;                   x++;               }               else{                   if((s[j-1] ==  1  && s[j+1] ==  0  && s[j] ==  0 ) || (s[j-1] ==  0  && s[j+1] ==  1  && s[j] ==  0 ))                       a[j] =  1 ;                   x++;                   }           }           s = a;           if(x == 0)               break;       }       cout << s << endl;              return 0;   }          signed main(){       IOS;       int tp=1;    cin>>tp;       while(tp--){           solve();       }              return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int ans = 0;     int inp;     for (int i = 0; i < n; i++) {       cin >> inp;       int temp = (inp + k - 1) / k;       ans += temp;     }     cout << (ans + 1) / 2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   map<char, int> m;   char letters[30];   int numbers[30];   int mystring[30];   int ceiling(int top, int bottom) { return (top + bottom - 1) / bottom; }   int main() {     string s;     int n;     cin >> s >> n;     for (int i = 0; i < (int)s.length(); i++) m[s[i]]++;     int numChar = 0;     for (map<char, int>::iterator it = m.begin(); it != m.end(); ++it) {       letters[numChar] = it->first;       numbers[numChar] = it->second;       numChar++;     }     if (numChar > n) {       cout << -1 << endl;       return 0;     }     for (int i = 0; i < numChar; i++) mystring[i] = 1;     for (int i = numChar; i < n; i++) {       int needMost = -1, needMostIndex = -1;       for (int j = 0; j < numChar; j++) {         if (ceiling(numbers[j], mystring[j]) > needMost) {           needMost = ceiling(numbers[j], mystring[j]);           needMostIndex = j;         }       }       mystring[needMostIndex]++;     }     int needMost = -1;     for (int j = 0; j < numChar; j++) {       if (ceiling(numbers[j], mystring[j]) > needMost) {         needMost = ceiling(numbers[j], mystring[j]);       }     }     cout << needMost << endl;     for (int i = 0; i < numChar; i++)       for (int j = 0; j < mystring[i]; j++) cout << letters[i];     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long Size = 501;   const long long mod = 1e9 + 7;   long long a[Size], num[Size];   bool vis[Size];   long long f[Size], d[Size];   long long dp[Size][Size];   inline long long min(long long a, long long b) { return a < b ? a : b; }   inline long long max(long long a, long long b) { return a > b ? a : b; }   long long fastpow(long long b, long long p, long long k) {     long long ans = 1;     while (p) {       if (p & 1) ans = ans * b % k;       b = b * b % k;       p >>= 1;     }     return ans;   }   void init() {     f[0] = 1;     for (long long i = 1; i <= 300; i++) f[i] = f[i - 1] * i % mod;     d[300] = fastpow(f[300], mod - 2, mod);     for (long long i = 299; i >= 0; i--) d[i] = d[i + 1] * (i + 1) % mod;   }   long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = 10 * x + ch -  0 ;       ch = getchar();     }     return x * f;   }   long long C(long long a, long long b) {     if (a < 0 || b < 0 || a < b) return 0;     if (!b || a == b) return 1;     return (f[a] * d[b] % mod) * d[a - b] % mod;   }   int main() {     init();     C(2, 1);     long long n = read(), size = 0;     for (long long i = 1; i <= n; i++) a[i] = read();     for (long long i = 1; i <= n; i++) {       if (!vis[i]) {         size++;         for (long long j = i; j <= n; j++) {           if (sqrt(a[i] * a[j]) == (long long)sqrt(a[i] * a[j])) {             vis[j] = true;             num[size]++;           }         }       }     }     long long sum = num[1] - 1;     dp[1][sum] = 1;     for (long long i = 2; i <= size; sum += num[i++]) {       for (long long j = 0; j <= sum; j++) {         if (!dp[i - 1][j]) continue;         for (long long k = 0; k <= num[i]; k++) {           long long tmp = min(j, k + 1), temp;           for (long long l = 0; l <= tmp; l++) {             temp = dp[i - 1][j] * C(num[i] - 1, k) % mod * C(j, l) % mod *                    C(sum + 2 - j, k - l + 1) % mod;             dp[i][j + num[i] - 1 - k - l] += temp;             dp[i][j + num[i] - 1 - k - l] %= mod;           }         }       }     }     long long ans = dp[size][0];     for (long long i = 1; i <= size; i++) ans = ans * f[num[i]] % mod;     printf( %I64d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 500010;   const int MAXM = 500010;   const int INF = 1e9 + 7;   const double pi = acos(0.0) * 2.0;   const double eps = 1e-12;   inline int read(int &x) {     scanf( %d , &x);     return x;   }   inline long long read(long long &x) {     scanf( %I64d , &x);     return x;   }   inline char read(char c) {     c = getchar();     return c;   }   inline char *read(char *&x) {     scanf( %s , x);     return x;   }   inline char *readln(char *&x) {     gets(x);     return x;   }   inline string read(string &x) {     cin >> x;     return x;   }   inline string readln(string &x) {     getline(cin, x);     return x;   }   inline float read(float &x) {     scanf( %f , &x);     return x;   }   inline double read(double &x) {     scanf( %lf , &x);     return x;   }   inline void ToString(char *x, string &y) { y = x; }   template <typename T>   inline void read(vector<T> &a, int n) {     a.clear();     T x;     for (int i = 0; i < n; i++) a.push_back(read(x));   }   template <typename T>   inline void read(T a[], int n) {     for (int i = 0; i < n; i++) read(a[i]);   }   inline int write(int x) {     printf( %d , x);     return x;   }   inline int writeln(int x) {     printf( %d n , x);     return x;   }   inline long long write(long long x) {     printf( %I64d , x);     return x;   }   inline long long writeln(long long x) {     printf( %I64d n , x);     return x;   }   inline char write(char c) {     putchar(c);     return c;   }   inline char writeln(char c) {     putchar(c);     putchar(  n );     return c;   }   inline char *write(char *x) {     printf( %s , x);     return x;   }   inline char *writeln(char *x) {     puts(x);     return x;   }   inline string write(string x) {     cout << x;     return x;   }   inline string writeln(string x) {     cout << x <<   n ;     return x;   }   inline float write(float x) {     printf( %f , x);     return x;   }   inline float writeln(float x) {     printf( %f n , x);     return x;   }   inline double write(double x) {     printf( %lf , x);     return x;   }   inline double writeln(double x) {     printf( %lf n , x);     return x;   }   template <typename T>   inline void write(vector<T> &a, int n) {     for (int i = 0; i < n - 1; i++) {       write(a[i]);       putchar(   );     }     writeln(a[n - 1]);   }   template <typename T>   inline void writeln(vector<T> &a, int n) {     for (int i = 0; i < n; i++) writeln(a[i]);   }   template <typename T>   inline void write(T a[], int n) {     for (int i = 0; i < n - 1; i++) {       write(a[i]);       putchar(   );     }     writeln(a[n - 1]);   }   template <typename T>   inline void writeln(T a[], int n) {     for (int i = 0; i < n; i++) writeln(a[i]);   }   template <class T>   inline T abs1(T a) {     return a < 0 ? -a : a;   }   template <class T>   inline T max1(T a, T b) {     return a > b ? a : b;   }   template <class T>   inline T max1(T a, T b, T c) {     return max1(max1(a, b), c);   }   template <class T>   inline T max1(T a, T b, T c, T d) {     return max1(max1(a, b, c), d);   }   template <class T>   inline T max1(T a, T b, T c, T d, T e) {     return max1(max1(a, b, c, d), e);   }   template <class T>   inline T min1(T a, T b) {     return a < b ? a : b;   }   template <class T>   inline T min1(T a, T b, T c) {     return min1(min1(a, b), c);   }   template <class T>   inline T min1(T a, T b, T c, T d) {     return min1(min1(a, b, c), d);   }   template <class T>   inline T min1(T a, T b, T c, T d, T e) {     return min1(min1(a, b, c, d), e);   }   inline int jud(double a, double b) {     if (abs(a) < eps && abs(b) < eps)       return 0;     else if (abs1(a - b) / abs1(a) < eps)       return 0;     if (a < b) return -1;     return 1;   }   template <typename t>   inline int jud(t a, t b) {     if (a < b) return -1;     if (a == b) return 0;     return 1;   }   int N, M, T = INF, Cases = 0;   double l, r;   double ans[MAXN];   string s;   int main() {     std::ios::sync_with_stdio(false);     cin >> s;     N = s.length();     double sum = 0;     for (int i = 1; i <= N; i++) sum += 1 / double(i);     ans[0] = ans[N - 1] = sum;     l = 1;     r = N;     for (int i = 1; i < (N + 1) / 2; i++) {       sum -= 1.0 / l + 1.0 / r;       ans[i] = ans[N - i - 1] = ans[i - 1] + sum;       l += 1;       r -= 1;     }     double res = 0;     for (int i = 0; i < N; i++) {       if (s[i] ==  A  || s[i] ==  E  || s[i] ==  O  || s[i] ==  I  ||           s[i] ==  U  || s[i] ==  Y )         res += ans[i];     }     cout.setf(ios::fixed);     cout << setprecision(9) << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   using v2d = vector<vector<T> >;   template <class T>   bool uin(T &a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   bool uax(T &a, T b) {     return a < b ? (a = b, true) : false;   }   mt19937 rng(chrono::system_clock::now().time_since_epoch().count());   const int maxN = 2e5 + 10;   const int maxM = 5e5 + 10;   int n, m, a, b;   vector<int> adj[maxN];   int fa[maxN], fb[maxN];   long long ca = 0, cb = 0;   void DFSa(int u) {     if (u == b) {       return;     }     fa[u] = 1;     for (auto &v : adj[u]) {       if (!fa[v]) {         DFSa(v);       }     }   }   void DFSb(int u) {     if (u == a) {       return;     }     fb[u] = 1;     for (auto &v : adj[u]) {       if (!fb[v]) {         DFSb(v);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int T;     cin >> T;     while (T--) {       cin >> n >> m >> a >> b;       for (int i = 1; i <= (int)(n); ++i) {         adj[i].clear();         fa[i] = fb[i] = 0;       }       while (m--) {         int u, v;         cin >> u >> v;         adj[u].emplace_back(v);         adj[v].emplace_back(u);       }       DFSa(a);       DFSb(b);       ca = cb = 0;       for (int i = 1; i <= (int)(n); ++i) {         if (fa[i]) {           ca += !fb[i];         }         if (fb[i]) {           cb += !fa[i];         }       }       cout << (ca - 1) * (cb - 1) <<   n ;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   void solve(priority_queue<pair<long long, int>, vector<pair<long long, int> >,                             greater<pair<long long, int> > > &P,              priority_queue<pair<long long, int> > &N, vector<long long> &ans,              int k, int x) {     while (k > 0) {       int ps = P.size(), pn = N.size();       if (ps && pn) {         pair<long long, int> pt = P.top();         P.pop();         pair<long long, int> nt = N.top();         N.pop();         int sign = (pn & 1) ? -1 : 1;         if (nt.first * -1 <= pt.first) {           nt.first += sign * x;           if (nt.first >= 0) {             P.push(nt);             P.push(pt);           } else {             N.push(nt);             P.push(pt);           }         } else {           pt.first -= sign * x;           if (pt.first < 0) {             N.push(nt);             N.push(pt);           } else {             N.push(nt);             P.push(pt);           }         }       } else if (ps) {         pair<long long, int> pt = P.top();         P.pop();         pt.first -= x;         if (pt.first < 0) {           N.push(pt);         } else {           P.push(pt);         }       } else {         pair<long long, int> nt = N.top();         N.pop();         int sign = (pn & 1) ? -1 : 1;         nt.first += sign * x;         if (nt.first >= 0) {           P.push(nt);         } else {           N.push(nt);         }       }       k--;     }     while (!P.empty()) {       pair<long long, int> it = P.top();       P.pop();       ans[it.second] = it.first;     }     while (!N.empty()) {       pair<long long, int> it = N.top();       N.pop();       ans[it.second] = it.first;     }   }   int main() {     int n, k, x, t;     while (cin >> n >> k >> x) {       priority_queue<pair<long long, int>, vector<pair<long long, int> >,                      greater<pair<long long, int> > >           Qp;       priority_queue<pair<long long, int> > Qn;       for (int i = 0; i < n; i++) {         cin >> t;         if (t >= 0)           Qp.push(make_pair(t, i));         else           Qn.push(make_pair(t, i));       }       vector<long long> ans(n);       solve(Qp, Qn, ans, k, x);       for (int i = 0; i < n; i++) cout << ans[i] <<    ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   char ch[200000];   int main() {     scanf( %s , ch + 1);     int n = strlen(ch + 1);     int flag = 0;     for (int i = 1; i <= n; i++) {       if (ch[i] != ch[n - i + 1]) flag++;     }     if (flag == 2 || n % 2 == 1 && flag == 0)       printf( YES );     else       printf( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<string, int> globmap;   int optwin[32000];   int optptsc[32000];   int optptso[32000];   int pts[32000];   map<string, int> hashid;   string hashinv[32000];   void findit(int s) {     if (optwin[s] != -1) {       return;     }     string S = hashinv[s];     string append =  z ;     optwin[s] = 0;     optptsc[s] = 0;     optptso[s] = 1000000000;     bool can = 0;     for (int c =  a ; c <=  z ; c++) {       append[0] = c;       string Snext;       for (int b = 0; b < 2; b++) {         if (b)           Snext = S + append;         else           Snext = append + S;         if (hashid.find(Snext) == hashid.end()) continue;         can = 1;         int snext = hashid[Snext];         findit(snext);         int candwin = !optwin[snext];         int candptsc = pts[snext] + optptso[snext];         int candptso = optptsc[snext];         if (candwin < optwin[s]) continue;         if (candwin > optwin[s]) {           optwin[s] = candwin;           optptsc[s] = candptsc;           optptso[s] = candptso;           continue;         }         if (candptsc < optptsc[s]) continue;         if (candptsc > optptsc[s]) {           optwin[s] = candwin;           optptsc[s] = candptsc;           optptso[s] = candptso;           continue;         }         if (candptso > optptso[s]) continue;         if (candptso < optptso[s]) {           optwin[s] = candwin;           optptsc[s] = candptsc;           optptso[s] = candptso;           continue;         }       }     }     if (!can) {       optwin[s] = 0;       optptsc[s] = 0;       optptso[s] = 0;     }   }   int main() {     int n;     scanf( %d , &n);     map<string, int> globmap;     for (int i = 0; i < n; i++) {       string word;       cin >> word;       map<string, bool> allsubs;       int L = word.size();       for (int i = 0; i < L; i++)         for (int j = i; j < L; j++) allsubs[word.substr(i, j - i + 1)] = 1;       for (map<string, bool>::iterator it = allsubs.begin(); it != allsubs.end();            it++) {         string S = (*it).first;         if (globmap.find(S) == globmap.end())           globmap[S] = 1;         else           globmap[S]++;       }     }     int ct = 0;     for (map<string, int>::iterator it = globmap.begin(); it != globmap.end();          it++) {       string S = (*it).first;       int L = S.size();       int maxx = 0;       int summ = 0;       for (int i = 0; i < L; i++) {         summ += S[i] -  a  + 1;         if (S[i] -  a  + 1 > maxx) maxx = S[i] -  a  + 1;       }       (*it).second += summ * maxx;       hashid[S] = ct + 1;       hashinv[ct + 1] = S;       pts[ct + 1] = (*it).second;       ct++;     }     hashid[  ] = 0;     hashinv[0] =   ;     pts[0] = 0;     ct++;     for (int i = 0; i < ct; i++) {       optwin[i] = -1;       optptsc[i] = -1;       optptso[i] = -1;     }     findit(0);     if (optwin[0])       printf( First n );     else       printf( Second n );     printf( %d %d n , optptsc[0], optptso[0]);   }


#include <bits/stdc++.h>   using namespace std;   int longestIncreasingSubsequenceDP(int a[], int n) {     int dp[n], ans = 0;     for (int k = 0; k < n; k++) {       dp[k] = 1;       for (int i = 0; i < k; i++) {         if (a[i] <= a[k]) {           dp[k] = max(dp[k], dp[i] + 1);           ans = max(dp[k], ans);         }       }     }     return ans;   }   int gcd(int a, int b) {     if (a == 0) return b;     if (b == 0) return a;     if (a == b) return a;     if (a > b) return gcd(a - b, b);     return gcd(a, b - a);   }   void scanArray(int arr[], int n) {     for (int i = 0; i < n; i++) {       cin >> arr[i];     }   }   int highestFromThree(int n1, int n2, int n3) { return max(max(n1, n2), n3); }   int highestFromFour(int n1, int n2, int n3, int n4) {     return max(max(n1, n2), max(n3, n4));   }   int result[1000] = {0};   int factDP(int n) {     if (n >= 0) {       result[0] = 1;       for (int i = 1; i <= n; ++i) {         result[i] = i * result[i - 1];       }       return result[n];     }   }   int main() {     int n, m;     cin >> n >> m;     int l[n], r[n];     vector<pair<int, int>> v;     int points[m];     for (int i = 0; i < m; i++) {       points[i] = i + 1;     }     for (int i = 0; i < n; i++) {       cin >> l[i] >> r[i];       v.push_back(make_pair(l[i], r[i]));     }     int count = m;     for (int i = 0; i < m; i++) {       for (int j = 0; j < v.size(); j++) {         if (points[i] >= v[j].first && points[i] <= v[j].second) {           count--;           points[i] = 0;           break;         }       }     }     cout << count <<   n ;     for (int i = 0; i < m; i++) {       if (points[i] != 0) {         cout << points[i] <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int n, a[4];   char s[N];   int main() {     cin >> n >> s;     for (int i = 0; i < n; ++i) {       if (s[i] ==  A )         a[0]++;       else if (s[i] ==  C )         a[1]++;       else if (s[i] ==  G )         a[2]++;       else if (s[i] ==  T )         a[3]++;     }     sort(a, a + 4);     int mx = a[3];     long long m = 0;     for (int i = 0; i < 4; ++i)       if (a[i] == mx) m++;     long long ans = 1;     for (int i = 0; i < n; ++i) ans = (ans * m) % (1000000007);     cout << ans << endl;   }


#include <bits/stdc++.h>   using std::abs;   using std::bitset;   using std::cerr;   using std::cin;   using std::copy;   using std::cout;   using std::deque;   using std::endl;   using std::fill;   using std::fixed;   using std::greater;   using std::iota;   using std::istream;   using std::lower_bound;   using std::make_pair;   using std::make_tuple;   using std::map;   using std::max;   using std::max_element;   using std::min;   using std::min_element;   using std::multiset;   using std::next_permutation;   using std::nth_element;   using std::ostream;   using std::pair;   using std::priority_queue;   using std::queue;   using std::reverse;   using std::rotate;   using std::set;   using std::sort;   using std::string;   using std::swap;   using std::tie;   using std::tuple;   using std::unique;   using std::unordered_map;   using std::unordered_set;   using std::upper_bound;   using std::vector;   long long rnd(long long x, long long y) {     static auto gen = std::bind(std::uniform_int_distribution<long long>(),                                 std::mt19937(960172));     return gen() % (y - x + 1) + x;   }   long long gcd(long long a, long long b) {     while (b > 0) {       long long t = a % b;       a = b;       b = t;     }     return a;   }   template <typename T>   T sqr(T const& a) {     return a * a;   }   int const INF = 100 + (int)1e9;   long long const INFL = 100 + (long long)1e18;   long double const PI = 3.1415926535897932384626433832795028;   void solve() {     vector<string> const hs = { Anka ,    Chapay ,  Cleo ,        Troll ,                                 Dracul ,  Snowy ,   Hexadecimal };     int qq;     cin >> qq;     int n = hs.size();     vector<vector<int>> z(n, vector<int>(n));     while (qq--) {       string a, b, c;       cin >> a >> b >> c;       int i = 0;       while (hs[i] != a) ++i;       int j = 0;       while (hs[j] != c) ++j;       ++z[i][j];     }     int A, B, C;     cin >> A >> B >> C;     int three = 1;     for (int i = 0; i < n; ++i) three *= 3;     int diff = 2 * INF;     int sym = 0;     for (int mask = 0; mask < three; ++mask) {       int val = mask;       vector<int> who(n), cnt(3);       for (int i = 0; i < n; ++i) {         int x = val % 3;         val /= 3;         who[i] = x;         ++cnt[x];       }       if (!cnt[0] || !cnt[1] || !cnt[2]) continue;       int a = A / cnt[0], b = B / cnt[1], c = C / cnt[2];       int cdiff = max({a, b, c}) - min({a, b, c});       int csym = 0;       for (int x = 0; x < n; ++x)         for (int y = 0; y < n; ++y) csym += z[x][y] * (who[x] == who[y]);       if (cdiff < diff || (cdiff == diff && csym > sym)) {         diff = cdiff;         sym = csym;       }     }     cout << diff <<     << sym << endl;   }   int main() {     cout.precision(15);     cout << fixed;     cerr.precision(6);     cerr << fixed;     solve();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100 * 1000 + 5;   int xs, ys, xt, yt, n, a[N], b[N], r[N];   map<pair<int, int>, int> mark;   map<pair<int, int>, int> dist;   int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};   int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};   void bfs(int x, int y) {     queue<pair<int, int> > q;     dist[{x, y}] = 0;     q.push({x, y});     while (!q.empty()) {       pair<int, int> p = q.front();       q.pop();       x = p.first, y = p.second;       for (int i = 0; i < 8; i++) {         int nx = x + dx[i], ny = y + dy[i];         if (!mark[{nx, ny}])           continue;         else if (dist[{nx, ny}] > dist[{x, y}] + 1) {           dist[{nx, ny}] = dist[{x, y}] + 1;           q.push({nx, ny});         }       }     }   }   void input() {     cin >> xs >> ys >> xt >> yt >> n;     for (int i = 0; i < n; i++) cin >> r[i] >> a[i] >> b[i];   }   void solve() {     for (int i = 0; i < n; i++) {       for (int j = a[i]; j <= b[i]; j++) {         mark[{r[i], j}] = true;         dist[{r[i], j}] = 1e9;       }     }     bfs(xs, ys);   }   void output() {     int ans = dist[{xt, yt}];     if (ans == 1e9)       cout << -1 <<   n ;     else       cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     input();     solve();     output();   }


#include<bits/stdc++.h>   #define ll long long   using namespace std;   ll T,n,k;   void work(){    scanf( %lld%lld ,&n,&k);    if(n<=k){printf( %lld n ,(long long)ceil((double)k*1.0/(double)n));return;}    else{     if(n%k==0){      printf( %lld n ,1LL);      return;     }     else printf( %lld n ,2LL);    }    return;   }   int main(){    scanf( %d ,&T);    while(T--)work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int INF = 1000 * 1000 * 1000 + 7;   const long long LINF = INF * (long long)INF;   const int MAX = 3000 + 47;   vector<int> g[MAX];   vector<int> S;   int L[MAX];   int U[MAX];   queue<int> q;   int D[MAX];   int n;   void dfs(int v, int p) {     if (U[v] == 1) {       int sz = (int)S.size() - 1;       L[v] = 1;       while (S[sz] != v) {         L[S[sz]] = 1;         sz--;       }       return;     }     U[v] = 1;     S.push_back(v);     for (int i = (0); i < ((int)g[v].size()); i++) {       int to = g[v][i];       if (to == p) continue;       dfs(to, v);     }     S.pop_back();     U[v] = 2;   }   void bfs() {     for (int i = (0); i < (n); i++) D[i] = INF;     for (int i = (0); i < (n); i++) {       if (!L[i]) continue;       q.push(i);       D[i] = 0;     }     while (!q.empty()) {       int v = q.front();       q.pop();       for (int i = (0); i < ((int)g[v].size()); i++) {         int to = g[v][i];         if (D[to] != INF) continue;         D[to] = D[v] + 1;         q.push(to);       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = (0); i < (n); i++) {       int x, y;       cin >> x >> y;       x--;       y--;       g[x].push_back(y);       g[y].push_back(x);     }     dfs(0, 0);     bfs();     for (int i = (0); i < (n); i++) {       cout << D[i] <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, l, r, cnt;   int a[105];   int main() {     cin >> n >> m;     for (int i = 0; i < n; ++i) {       cin >> l >> r;       for (int i = l; i <= r; ++i) {         a[i] = 1;       }     }     for (int i = 1; i <= m; ++i) {       if (!a[i]) cnt++;     }     cout << cnt << endl;     for (int i = 1; i <= m; ++i) {       if (!a[i]) cout << i <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, ser = 0, dim = 0;     vector<int> v;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x;       v.push_back(x);     }     for (int i = 0; i < n; i++) {       if (i % 2 == 0) {         ser += max(v.front(), v.back());         if (v.front() > v.back())           v.erase(v.begin());         else           v.pop_back();       } else {         dim += max(v.front(), v.back());         if (v.front() > v.back())           v.erase(v.begin());         else           v.pop_back();       }     }     cout << ser <<     << dim << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   long long MOD = 1e9 + 7;   long long dp[4000][4000];   long long mn[4000][4000];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     set<long long> uss;     long long a[n];     long long b[n];     long long sm = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       a[i] = a[i] - i;       uss.insert(a[i]);     }     vector<long long> us;     for (auto i : uss) {       us.push_back(i);     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < us.size(); j++) {         dp[i + 1][j] = mn[i][j] + abs(us[j] - a[i]);         mn[i + 1][j] = dp[i + 1][j];         if (j) mn[i + 1][j] = min(mn[i + 1][j], mn[i + 1][j - 1]);       }     }     cout << mn[n][us.size() - 1];   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     int n;     cin >> n;     int t;     int speed = 0;     int ans = 0;     int c = 0;     int bs;     stack<int> s;     cin >> t >> speed;     for (int i = 1; i < n; i++) {       cin >> t;       if (t == 1) {         cin >> speed;         while (!s.empty() && speed > s.top()) {           s.pop();           ans++;         }       } else if (t == 2) {         ans += c;         c = 0;       } else if (t == 3) {         cin >> bs;         s.push(bs);         if (bs < speed) {           s.pop();           ans++;         }       } else if (t == 4) {         c = 0;       } else if (t == 5) {         while (!s.empty()) s.pop();       } else {         c++;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps(1e-8);   const long long inf = -99999999999999999;   long long row, col, k, p;   long long sumr[1001];   long long sumc[1001];   long long answerR[1000001];   long long answerC[1000001];   priority_queue<long long> Rtmp, Ctmp;   int main() {     scanf( %I64d %I64d %I64d %I64d , &row, &col, &k, &p);     memset(sumr, 0, sizeof(sumr));     memset(sumc, 0, sizeof(sumc));     long long tmp;     for (int i = 1; i <= row; i++) {       for (int j = 1; j <= col; j++) {         scanf( %I64d , &tmp);         sumr[i] += tmp;         sumc[j] += tmp;       }     }     for (int i = 1; i <= row; i++) {       Rtmp.push(sumr[i]);     }     for (int i = 1; i <= col; i++) {       Ctmp.push(sumc[i]);     }     memset(answerR, 0, sizeof(answerR));     memset(answerC, 0, sizeof(answerC));     long long ans = 0;     for (int j = 1; j <= k; j++) {       ans += Rtmp.top();       tmp = Rtmp.top();       tmp -= col * p;       Rtmp.pop();       Rtmp.push(tmp);       answerR[j] = ans;     }     ans = 0;     for (int j = 1; j <= k; j++) {       ans += Ctmp.top();       tmp = Ctmp.top();       tmp -= row * p;       Ctmp.pop();       Ctmp.push(tmp);       answerC[j] = ans;     }     long long answer = inf;     for (int i = 0; i <= k; i++) {       answer = max(answer, answerR[i] + answerC[k - i] - i * (k - i) * p);     }     printf( %I64d n , answer);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1000000000 + 7;   const long long int N = 10000000 + 6;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, k;     cin >> n >> k;     char matrix[4][n];     for (int i = 0; i < 4; i++)       for (int j = 0; j < n; j++) matrix[i][j] =  . ;     bool bo = true;     if (k & 1) {       if (k > n - 2) {         int g = n - 2;         for (int i = 1; i <= g; i++) matrix[1][i] =  # ;         int l = k - n;         matrix[2][1] =  # ;         matrix[2][n - 2] =  # ;         for (int i = 2; i <= l + 1; i++) matrix[2][i] =  # ;       } else {         int i = n / 2 - k / 2;         int c = 1;         for (int j = i; c <= k; c++, j++) matrix[1][j] =  # ;       }     } else {       int g = k / 2;       for (int i = 1; i <= g; i++) matrix[1][i] =  # ;       for (int i = 1; i <= g; i++) matrix[2][i] =  # ;     }     if (bo) {       cout <<  YES n ;       for (int i = 0; i < 4; i++) {         for (int j = 0; j < n; j++) cout << matrix[i][j];         cout <<   n ;       }     } else       cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   template <typename T>   void read(T& val) {     std::string tmp = typeid(val).name();     if (strcmp(tmp.c_str(),  i ) == 0)       scanf( %d , &val);     else if (strcmp(tmp.c_str(),  x ) == 0)       scanf( %I64d , &val);     else if (strcmp(tmp.c_str(),  d ) == 0)       scanf( %lf , &val);     else if (tmp.length() > 2 && tmp.back() ==  c )       scanf( %s , val);     else if (strcmp(tmp.c_str(),  c ) == 0)       scanf( %c , &val);   }   template <typename T, typename... Targs>   void read(T& val, Targs&... Fargs) {     read(val);     read(Fargs...);   }   template <typename T>   void print(T val) {     std::string tmp = typeid(val).name();     if (strcmp(tmp.c_str(),  i ) == 0)       printf( %d , val);     else if (strcmp(tmp.c_str(),  x ) == 0)       printf( %I64d , val);     else if (strcmp(tmp.c_str(),  d ) == 0)       printf( %.15f , val);     else if (strcmp(tmp.c_str(),  c ) == 0)       printf( %c , val);     else if (tmp.length() > 2 && tmp.back() ==  c )       printf( %s , val);   }   template <typename T, typename... Targs>   void print(T val, Targs... Fargs) {     print(val);     print(Fargs...);   }   const double pi = acos(-1);   const int MOD = 1e9 + 7;   const int INF = 1e9 + 7;   const int MAXN = 1e6 + 5;   const double eps = 1e-9;   using namespace std;   int a = 1, b, c, n, x, y, z;   int main() {     read(n, x, y, c);     while (a < c) {       b++;       z = min(x - 1, b);       a += max(z - max((y + b - n), 0) + 1, 0) +            max(z - max((b - y + 1), 0) + 1, 0) - (z == b);       z = min(n - x, b);       a += max(z - max((y + b - n), 1) + 1, 0) +            max(z - max((b - y + 1), 1) + 1, 0) - (z == b);     }     print(b);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18;   const long double Pi = 3.141592653589793116, EPS = 1e-9,                     Gold = ((1 + sqrt(5)) / 2);   long long keymod[] = {1000000007LL, 1000000009LL, 1000000021LL, 1000000033LL};   long long keyCount = sizeof(keymod) / sizeof(long long);   mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());   mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());   template <class T>   int getbit(T s, int i) {     return (s >> i) & 1;   }   template <class T>   T onbit(T s, int i) {     return s | (T(1) << i);   }   template <class T>   T offbit(T s, int i) {     return s & (~(T(1) << i));   }   template <class T>   int cntbit(T s) {     return __builtin_popcountll(s);   }   auto TimeStart = chrono::steady_clock::now();   auto TimeEnd = chrono::steady_clock::now();   void ControlIO(int argc, char* argv[]);   void TimerStart();   void TimerStop();   void Exit();   string cppstr_infile =  FILE.IN ;   string cppstr_outfile =  FILE.OUT ;   int n;   vector<int> c;   vector<long long> dp;   vector<vector<int>> adj;   vector<vector<int>> DependencyList;   set<int> FinalList;   void DFS_GetList(int z, int last, vector<int>& MaxLeaf, vector<int>& MaxID,                    vector<int>& MaxCnt) {     dp[z] = 0;     bool isLeaf = true;     for (auto t : adj[z]) {       if (t == last) continue;       isLeaf = false;       DFS_GetList(t, z, MaxLeaf, MaxID, MaxCnt);       dp[z] += dp[t];       if (MaxLeaf[t] >= MaxLeaf[z]) MaxID[z] = MaxID[t];       if (MaxLeaf[t] > MaxLeaf[z])         MaxCnt[z] = MaxCnt[t];       else if (MaxLeaf[t] == MaxLeaf[z])         MaxCnt[z] += MaxCnt[t];       MaxLeaf[z] = max(MaxLeaf[z], MaxLeaf[t]);     }     if (isLeaf) {       MaxLeaf[z] = dp[z] = c[z];       MaxID[z] = z;       MaxCnt[z] = 1;       DependencyList[z].push_back(z);       return;     }     int MaxRemovable = -MaxLeaf[z];     if (MaxRemovable + c[z] > 0) return;     if (MaxRemovable + c[z] < 0 && MaxCnt[z] == 1) {       DependencyList[MaxID[z]].clear();     }     if (MaxCnt[z] == 1)       DependencyList[MaxID[z]].push_back(z);     else {       DependencyList[z].push_back(z);       MaxID[z] = z;     }     dp[z] += (MaxRemovable + c[z]);     MaxLeaf[z] = c[z];     MaxCnt[z] = 1;   }   void Input() {     cin >> n;     c.resize(n);     dp.resize(n);     adj.resize(n);     DependencyList.resize(n);     for (auto& z : c) cin >> z;     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       adj[a].push_back(b);       adj[b].push_back(a);     }   }   void Solve() {     vector<int> MaxLeaf(n, -1), MaxID(n, -1), MaxCnt(n, 0);     DFS_GetList(0, -1, MaxLeaf, MaxID, MaxCnt);     for (int id = 0; id < n; id++) {       for (auto z : DependencyList[id]) FinalList.insert(z + 1);     }     cout << dp[0] <<     << FinalList.size() <<   n ;     for (auto it = FinalList.begin(); it != FinalList.end(); it++)       cout << (*it) <<    ;     cout <<   n ;   }   int main(int argc, char* argv[]) {     ControlIO(argc, argv);     ios_base::sync_with_stdio(0);     cin.tie(NULL);     Input();     TimerStart();     Solve();     TimerStop();     return 0;   }   void ControlIO(int argc, char* argv[]) {     char* infile = new char[cppstr_infile.size() + 1];     char* outfile = new char[cppstr_outfile.size() + 1];     strcpy(infile, cppstr_infile.c_str());     strcpy(outfile, cppstr_outfile.c_str());   }   void TimerStart() {}   void TimerStop() {}   void Exit() {     TimerStop();     exit(0);   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pll = pair<ll, ll>;   using pii = pair<int, int>;   struct Node {     vector<ll> con;     ll h1, h2;   } g[100010];   ll dfs(ll n, ll p) {     g[n].h1 = g[n].h2 = 0;     for (auto &i : g[n].con) {       if (i == p) continue;       ll k = dfs(i, n) + 1;       if (k >= g[n].h1) {         g[n].h2 = g[n].h1;         g[n].h1 = k;       } else if (k >= g[n].h2) {         g[n].h2 = k;       }     }     return g[n].h1;   }   ll dist(ll n, ll p, ll t) {     if (n == t) return 0;     ll ans = (ll)(1e17);     for (auto &i : g[n].con) {       if (i == p) continue;       ans = min(ans, dist(i, n, t) + 1);     }     return ans;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     ll N;     cin >> N;     while (N--) {       ll n, a, b, da, db;       cin >> n >> a >> b >> da >> db;       for (ll i = 0; i <= n - 1; i++) g[i].con.clear();       a--;       b--;       ll s, t;       for (ll i = 0; i <= n - 2; i++) {         cin >> s >> t;         s--;         t--;         g[s].con.emplace_back(t);         g[t].con.emplace_back(s);       }       dfs(0, 0);       ll height = 0;       for (ll i = 0; i <= n - 1; i++) height = max(height, g[i].h1 + g[i].h2);       ll dis = dist(a, a, b);       if (da * 2 < db && da * 2 < height && dis > da)         cout <<  Bob n ;       else         cout <<  Alice n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int n, m;       cin >> n;       vector<int> v(2 * n), v2;       for (int i = 0; i < 2 * n; i++) {         cin >> v[i];       }       for (int i = 0; i < 2 * n; i++) {         int d = 1;         for (int j = 0; j < i; j++) {           if (v[j] == v[i]) {             d = 0;             break;           }         }         if (d) {           v2.push_back(v[i]);         }       }       for (int i = 0; i < v2.size(); i++) {         cout << v2[i] <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int a[305], ans[305], b[305][305], n, mx = 0;   bool visit[305];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 1; i <= n; i++) {       cin >> s;       for (int j = 0; j < n; j++) {         b[i][j + 1] = s[j] - 48;       }     }     for (int k = 1; k <= n; k++) {       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           if (b[i][k] && b[k][j]) b[i][j] = 1;         }       }     }     for (int i = 1; i <= n; i++) {       mx = a[i];       for (int j = 1; j <= n; j++) {         if (b[i][j]) {           if (a[j] < mx && !visit[a[j]]) {             mx = a[j];             swap(a[i], a[j]);           }         }       }       visit[mx] = 1;       ans[i] = mx;     }     for (int i = 0; i < n; i++) {       if (i)         cout <<     << ans[i + 1];       else         cout << ans[i + 1];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int isp[100005];   void pp() {     for (long long int i = 2; i <= 100000; i++) {       if (!isp[i]) {         for (long long int j = i * i; j <= 100000; j += i) {           isp[j] = 1;         }       }     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     cin >> t;     pp();     while (t--) {       long long int n, i, j, x, y;       cin >> n;       if (!isp[n]) {         for (long long int i = 1; i <= n; i++) {           for (long long int j = 1; j <= n; j++) {             cout << 1 <<    ;           }           cout <<   n ;         }         continue;       }       x = -1;       for (long long int i = n + 1; i <= 100000; i++) {         if (!isp[i] && isp[i - n + 1]) {           x = i - n + 1;           break;         }       }       for (long long int i = 1; i < n; i++) {         for (long long int j = 1; j < n; j++) {           cout << 1 <<    ;         }         cout << x <<   n ;       }       y = 0;       for (long long int i = 1; i < n; i++) {         y += x;         cout << x <<    ;       }       for (long long int i = y; i <= 100000; i++) {         if (!isp[i] && isp[i - y]) {           x = i - y;           break;         }       }       cout << x <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<long long, long long> p;   vector<pair<long long, long long>> adj[101];   long long visited[101];   long long parent[101];   long long maxi = 0;   set<long long, greater<long long>> set1;   vector<long long> arr;   long long ans[101];   void dfs(long long v, long long p) {     for (auto q : adj[v]) {       long long u = q.first;       if (u == p) continue;       dfs(u, v);       ans[v] = max(ans[v], ans[u] + q.second);     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, a, b, c;     cin >> n;     long long z = n - 1;     while (z--) {       cin >> a >> b >> c;       adj[a].push_back(make_pair(b, c));       adj[b].push_back(make_pair(a, c));     }     memset(visited, 0, sizeof(visited));     dfs(0, -1);     cout << ans[0] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int INF = 0x3f3f3f3f;   long long n, l, r;   pair<long long, long long> dfs(long long x) {     if (x == 0)       return make_pair(1, 0);     else if (x == 1)       return make_pair(1, 1);     long long tmp = x & 1;     pair<long long, long long> t = dfs(x / 2);     t.first = t.first * 2 + 1;     t.second = t.second * 2 + tmp;     return t;   }   long long get(long long x, long long k) {     if (x == 0)       return 0;     else if (x == 1)       return 1;     pair<long long, long long> t = dfs(x / 2);     if (k <= t.first)       return get(x / 2, k);     else if (k == t.first + 1)       return t.second + (x & 1);     else {       return t.second + (x & 1) + get(x / 2, k - t.first - 1);     }   }   int main() {     scanf( %I64d%I64d%I64d , &n, &l, &r);     printf( %I64d n , get(n, r) - (l - 1 == 0 ? 0 : get(n, l - 1)));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200;   int s[maxn][6], n;   int cnt[maxn];   int get_score(int id, int f, int a) {     if (s[f][id] == -1) return 0;     int sum = 0;     if (s[1][id] == -1 || s[2][id] == -1 || s[1][id] < s[2][id])       sum = cnt[id];     else       sum = cnt[id] + a;     int score = 500;     for (int i = 2; i <= 32; i *= 2) {       if (sum * i > n + a) {         break;       } else {         score += 500;       }     }     return score * (250.0 - s[f][id]) * 250.0;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= 5; j++) scanf( %d , &s[i][j]);     memset(cnt, 0, sizeof(cnt));     for (int i = 1; i <= n; i++)       for (int j = 1; j <= 5; j++)         if (s[i][j] != -1) cnt[j]++;     int sum1 = 0, sum2 = 0;     int ss = -1;     for (int v = 0; v <= 120 * 32; v++) {       sum1 = 0, sum2 = 0;       for (int j = 1; j <= 5; j++) {         sum1 += get_score(j, 1, v);         sum2 += get_score(j, 2, v);       }       if (sum1 > sum2) {         ss = v;         break;       }     }     printf( %d n , ss);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     long long a, b, sum = 0;     cin >> a >> b;     while (true) {       if (a >= b) {         sum += a / b;         a %= b;       }       if (a == 0) {         break;       }       swap(a, b);     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long p = 1000000007;   long long fact[100000];   long long dp[100000];   long long factdp[100000];   long long ar[200000];   int main() {     fact[0] = 1;     fact[1] = 1;     dp[0] = 1;     dp[1] = 1;     factdp[0] = 1;     factdp[1] = 1;     for (int i = 2; i < 10000; i++) {       dp[i] = dp[p % i] * (p - (p / i)) % p;       fact[i] = i * fact[i - 1] % p;       factdp[i] = factdp[i - 1] * (dp[i]) % p;     }     long long n, m;     cin >> n >> m;     long long ans =         (fact[2 * m + n - 1] * factdp[2 * m] % p * factdp[n - 1] % p + p) % p;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   long long cal(long long x) { return (x + 1) * x / 2; }   int main() {     std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long n;     cin >> n;     long long l = 0, r = 1e8, ans = -1;     while (l <= r) {       long long mid = (l + r) >> 1;       if (cal(mid) < n)         l = mid + 1, ans = mid;       else         r = mid - 1;     }     cout << n - cal(ans) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int main() {     int n, k;     scanf( %d %d , &n, &k);     int def = 0;     int a[N], d[N] = {};     for (int i = 0; i <= n; i++) {       int a[N];       char c[10];       if (scanf( %d , &a[i]))         d[i] = 1, def++;       else         scanf( %s , c);     }     if (k == 0) {       if (d[0])         printf( %s n , a[0] == 0 ?  Yes  :  No );       else         printf( %s n , def % 2 == 0 ?  No  :  Yes );     } else {       if (def != n + 1) {         printf( %s n , n % 2 ?  Yes  :  No );       } else {         if (k == 1) {           int resp = 0;           for (int i = n; i >= 0; i--) resp += a[i];           printf( %s n , resp == 0 ?  Yes  :  No );         } else {           long long r = 0;           for (int i = 0; i <= n; i++) {             r = r / k + a[i];             if (r % k) break;           }           printf( %s n , r == 0 ?  Yes  :  No );         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int INF = (1ll << 60) - 1;   long long int nCrModpDP(long long int n, long long int r, long long int p) {     long long int i, j, C[r + 1];     memset(C, 0, sizeof(C));     C[0] = 1;     for (i = 1; i <= n; i++) {       for (j = min(i, r); j > 0; j--) {         C[j] = (C[j] + C[j - 1]) % p;       }     }     return C[r];   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int tc = 1;     while (tc--) {       long long int fact[1001];       fact[0] = fact[1] = 1;       fact[2] = 2;       fact[3] = 6;       for (long long int i = 4; i < 1001; i++)         fact[i] = ((fact[i - 1] % 1000000007) * (i % 1000000007)) % 1000000007;       long long int n, m;       cin >> n >> m;       long long int ans = nCrModpDP(n + 2 * m - 1, n - 1, 1000000007);       cout << ans % 1000000007;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   long long ans;   int a[100002];   int b[100002];   bool jobs[100002];   priority_queue<int> pq[100002];   priority_queue<int> pq2;   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     for (int i = 0; i < n; i++) {       pq[a[i]].push(-b[i]);       jobs[a[i]] = true;     }     for (int i = 1; i <= n; i++) {       while (pq[i].size() > 1) {         pq2.push(pq[i].top());         pq[i].pop();       }     }     for (int i = 1; i <= k; i++) {       if (!jobs[i]) {         ans -= pq2.top();         pq2.pop();       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0;     char c = getchar();     bool f = 0;     while (c < 48) f |= c ==  - , c = getchar();     while (c > 47) x = x * 10 + (c ^ 48), c = getchar();     return f ? -x : x;   }   int n, k;   struct node {     int sz, mn[10], mx[10];     bool operator<(const node& o) const {       for (int i = (0), iend = (k - 1); i <= iend; ++i)         if (mx[i] > o.mn[i]) return 0;       return 1;     }   };   node merge(node A, node B) {     node res;     res.sz = A.sz + B.sz;     for (int i = (0), iend = (k - 1); i <= iend; ++i)       res.mn[i] = min(A.mn[i], B.mn[i]), res.mx[i] = max(A.mx[i], B.mx[i]);     return res;   }   multiset<node> S;   int main() {     cin >> n >> k;     for (int _ = (1), _end = (n); _ <= _end; ++_) {       node cur;       cur.sz = 1;       for (int i = (0), iend = (k - 1); i <= iend; ++i)         cur.mn[i] = cur.mx[i] = read();       while (1) {         auto it1 = S.lower_bound(cur), it2 = S.upper_bound(cur);         if (it1 != it2) {           cur = merge(*it1, cur), S.erase(it1);         } else           break;       }       S.insert(cur);       printf( %d n , S.rbegin()->sz);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e3 + 10, H = 2e5 + 10, MOD = 1e9 + 7;   struct node {     int x, y;   } a[N];   long long fac[H], inv[H], f[N];   int h, w, n;   long long popow(long long x, int y) {     long long t = x, re = 1;     while (y) {       if (y & 1) re = re * t % MOD;       t = t * t % MOD;       y >>= 1;     }     return re;   }   void prepare() {     fac[0] = inv[0] = 1;     for (int i = 1; i <= 2e5; ++i) {       fac[i] = fac[i - 1] * i % MOD;       inv[i] = popow(fac[i], MOD - 2);     }   }   bool cmp(const node &aa, const node &bb) {     return aa.x < bb.x || (aa.x == bb.x && aa.y < bb.y);   }   long long calc(int aa, int bb) {     if (aa < bb) return 0;     return fac[aa] * inv[bb] % MOD * inv[aa - bb] % MOD;   }   int main() {     prepare();     scanf( %d%d%d , &h, &w, &n);     for (int i = 1; i <= n; ++i) scanf( %d%d , &a[i].x, &a[i].y);     ++n;     a[n].x = h;     a[n].y = w;     sort(&a[1], &a[1 + n], cmp);     for (int i = 1; i <= n; ++i) {       f[i] = calc(a[i].x + a[i].y - 2, a[i].x - 1);       for (int j = 1; j < i; ++j)         if (a[j].y <= a[i].y) {           f[i] -= f[j] * calc(a[i].x + a[i].y - a[j].x - a[j].y, a[i].x - a[j].x);           f[i] %= MOD;         }     }     printf( %lld n , (f[n] + MOD) % MOD);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   const int MXN = 2e5 + 10;   const int MXS = MXN * 4;   const int INF = 1e9;   const int Mod = 998244353;   int n, q, num;   int Seg[MXS], MUL[MXS], ADD[MXS];   set<pair<pair<int, int>, int> > st[MXN];   void Shift(int id, int s, int e) {     if (MUL[id] == 1 && ADD[id] == 0) return;     Seg[id] =         ((1ll * Seg[id] * MUL[id] % Mod) + (1ll * ADD[id] * (e - s + 1) % Mod)) %         Mod;     if ((e - s + 1) > 1) {       ADD[(id * 2)] = ((1ll * ADD[(id * 2)] * MUL[id] % Mod) + ADD[id]) % Mod;       ADD[(id * 2 + 1)] =           ((1ll * ADD[(id * 2 + 1)] * MUL[id] % Mod) + ADD[id]) % Mod;       MUL[(id * 2)] = 1ll * MUL[(id * 2)] * MUL[id] % Mod;       MUL[(id * 2 + 1)] = 1ll * MUL[(id * 2 + 1)] * MUL[id] % Mod;     }     ADD[id] = 0, MUL[id] = 1;   }   void Upd(int l, int r, int add, int mul, int id = 1, int s = 1, int e = n) {     Shift(id, s, e);     if (e < l || s > r) return;     if (l <= s && e <= r) {       ADD[id] = add, MUL[id] = mul;       Shift(id, s, e);       return;     }     Upd(l, r, add, mul, (id * 2), s, ((s + e) / 2)),         Upd(l, r, add, mul, (id * 2 + 1), ((s + e) / 2 + 1), e);     Seg[id] = (Seg[(id * 2)] + Seg[(id * 2 + 1)]) % Mod;   }   int Get(int l, int r, int id = 1, int s = 1, int e = n) {     Shift(id, s, e);     if (e < l || s > r) return 0;     if (l <= s && e <= r) return Seg[id];     return (Get(l, r, (id * 2), s, ((s + e) / 2)) +             Get(l, r, (id * 2 + 1), ((s + e) / 2 + 1), e)) %            Mod;   }   void Split(int tp, int p, bool f) {     auto itr = st[tp].upper_bound({{p, INF}, 0});     itr--;     int l, r, sit = itr->second;     tie(l, r) = itr->first;     if (!f && l == p) return;     if (f && r == p) return;     st[tp].erase(itr);     st[tp].insert({{l, p - 1 + f}, sit});     st[tp].insert({{p + f, r}, sit});   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> q;     for (int i = 0; i < MXS; i++) MUL[i] = 1;     for (int i = 1; i <= n; i++) st[i].insert({{1, n}, 0});     for (int i = 0; i < q; i++) {       int t, l, r, x;       cin >> t >> l >> r;       if (t != 2) cin >> x;       if (t == 2) {         cout << Get(l, r) <<   n ;         continue;       }       Split(x, l, 0), Split(x, r, 1);       auto itr = st[x].lower_bound({{l, l}, 0});       while (itr != st[x].end() && itr->first.second <= r) {         int nl, nr, ns = itr->second;         tie(nl, nr) = itr->first;         if (ns) Upd(nl, nr, 0, 2);         if (!ns) Upd(nl, nr, 1, 1);         st[x].erase(itr);         itr = st[x].lower_bound({{nr + 1, nr + 1}, 0});       }       st[x].insert({{l, r}, 1});     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     int arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     int ok = 0;     for (int i = 0; i < n - 1; i++) {       if (((long long int)arr[i] * 2) > arr[i + 1] and arr[i + 1] > arr[i])         ok = 1;     }     if (ok)       cout <<  YES  <<   n ;     else       cout <<  NO  <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long int arr[1000005], t = 0;   int main() {     int n, cnt;     cin >> n;     map<long long int, int> m;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     cnt = 1;     long long int t = arr[0];     m[t]++;     for (int i = 1; i < n; i++) {       t = t + arr[i];       m[t]++;       cnt = max(cnt, m[t]);     }     cout << n - cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace Dango {   const int MAXN = 200005, INF = 0x3f3f3f3f;   struct Edge {     int from, to, dis, id;     bool operator<(const Edge b) const { return dis < b.dis; }   } e[MAXN];   struct tree {     int l, r, data;     bool tag;   } t[MAXN << 2];   int n, m;   int head[MAXN], to[MAXN * 2], dis[MAXN * 2], nxt[MAXN * 2];   int fa[MAXN];   int ans[MAXN];   int size[MAXN], maxson[MAXN], belong[MAXN], f[MAXN];   int id[MAXN], link[MAXN], tmp[MAXN], d[MAXN];   bool flag[MAXN];   int read() {     int x = 0, f = 0;     char ch = getchar();     while (!isdigit(ch)) {       f |= (ch ==  - );       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return f ? -x : x;   }   int ffind(int a) { return f[a] == a ? a : f[a] = ffind(f[a]); }   void add(int u, int v, int w) {     static int cnt;     cnt++;     to[cnt] = v;     dis[cnt] = w;     nxt[cnt] = head[u];     head[u] = cnt;   }   void dfs1(int u, int f) {     size[u] = 1;     fa[u] = f;     d[u] = d[f] + 1;     for (int i = head[u]; i; i = nxt[i]) {       int v = to[i];       if (v == f) continue;       tmp[v] = dis[i];       dfs1(v, u);       size[u] += size[v];       if (size[v] > size[maxson[u]]) maxson[u] = v;     }   }   void dfs2(int u, int f, int anc) {     static int cnt;     id[u] = ++cnt;     link[cnt] = u;     belong[u] = anc;     if (maxson[u]) dfs2(maxson[u], u, anc);     for (int i = head[u]; i; i = nxt[i]) {       int v = to[i];       if (v == f || v == maxson[u]) continue;       dfs2(v, u, v);     }   }   void build(int a, int l, int r) {     t[a].l = l;     t[a].r = r;     t[a].tag = false;     if (l == r) {       t[a].data = tmp[link[l]];       return;     }     int mid = (l + r) >> 1;     build(a << 1, l, mid);     build(a << 1 | 1, mid + 1, r);     t[a].data = max(t[a << 1].data, t[a << 1 | 1].data);   }   void pushdown(int a) {     int l = a << 1, r = a << 1 | 1;     t[a].tag = false;     t[l].data = min(t[l].data, t[a].data);     t[r].data = min(t[r].data, t[a].data);     t[l].tag = t[r].tag = true;   }   void update(int a, int l, int r, int data) {     if (t[a].l >= l && t[a].r <= r) {       t[a].data = min(t[a].data, data);       t[a].tag = true;       return;     }     if (t[a].tag) pushdown(a);     int mid = (t[a].l + t[a].r) >> 1;     if (l <= mid) update(a << 1, l, r, data);     if (r > mid) update(a << 1 | 1, l, r, data);   }   int querymax(int a, int l, int r) {     if (t[a].l >= l && t[a].r <= r) return t[a].data;     if (t[a].tag) pushdown(a);     int mid = (t[a].l + t[a].r) >> 1, res = 0;     if (l <= mid) res = max(res, querymax(a << 1, l, r));     if (r > mid) res = max(res, querymax(a << 1 | 1, l, r));     return res;   }   int querymin(int a, int l, int r) {     if (t[a].l >= l && t[a].r <= r) return t[a].data;     if (t[a].tag) pushdown(a);     int mid = (t[a].l + t[a].r) >> 1, res = INF;     if (l <= mid) res = min(res, querymin(a << 1, l, r));     if (r > mid) res = min(res, querymin(a << 1 | 1, l, r));     return res;   }   int solve(int u, int v) {     int res = 0;     while (belong[u] != belong[v]) {       if (d[belong[u]] < d[belong[v]]) swap(u, v);       res = max(res, querymax(1, id[belong[u]], id[u]));       u = fa[belong[u]];     }     if (u != v) {       if (d[u] > d[v]) swap(u, v);       res = max(res, querymax(1, id[u] + 1, id[v]));     }     return res - 1;   }   void fix(int u, int v, int w) {     while (belong[u] != belong[v]) {       if (d[belong[u]] < d[belong[v]]) swap(u, v);       update(1, id[belong[u]], id[u], w);       u = fa[belong[u]];     }     if (u != v) {       if (d[u] > d[v]) swap(u, v);       update(1, id[u] + 1, id[v], w);     }   }   int solve2(int u, int v) {     int res = INF;     while (belong[u] != belong[v]) {       if (d[belong[u]] < d[belong[v]]) swap(u, v);       res = min(res, querymin(1, id[belong[u]], id[u]));       u = fa[belong[u]];     }     if (u != v) {       if (d[u] > d[v]) swap(u, v);       res = min(res, querymin(1, id[u] + 1, id[v]));     }     if (res == INF) res = 0;     return res - 1;   }   int work() {     n = read();     m = read();     for (int i = 1; i <= n; i++) f[i] = i;     for (int i = 1; i <= m; i++) {       e[i].from = read();       e[i].to = read();       e[i].dis = read();       e[i].id = i;     }     sort(e + 1, e + m + 1);     for (int i = 1; i <= m; i++) {       int u = e[i].from, v = e[i].to, w = e[i].dis;       int a = ffind(u), b = ffind(v);       if (a != b) {         f[a] = b;         add(u, v, w);         add(v, u, w);       } else         flag[i] = true;     }     dfs1(1, 0);     dfs2(1, 0, 1);     build(1, 1, n);     for (int i = 1; i <= m; i++) {       if (!flag[i]) continue;       ans[e[i].id] = solve(e[i].from, e[i].to);     }     memset(tmp, INF, sizeof(tmp));     build(1, 1, n);     for (int i = 1; i <= m; i++) {       if (!flag[i]) continue;       fix(e[i].from, e[i].to, e[i].dis);     }     for (int i = 1; i <= m; i++) {       if (flag[i]) continue;       ans[e[i].id] = solve2(e[i].from, e[i].to);     }     for (int i = 1; i <= m; i++) printf( %d  , ans[i]);     return 0;   }   }  // namespace Dango   int main() { return Dango::work(); }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > v[200010];   int mark[200010];   vector<pair<int, int> > sorted;   int Query[200010];   int main() {     int n, q, i, j;     memset(mark, 0, sizeof(mark));     scanf( %d , &n);     for (i = 0; i < n; i++) {       int x, y;       scanf( %d , &x);       scanf( %d , &y);       v[x].push_back(make_pair(y, i));     }     for (i = 1; i <= n; i++) {       if ((int)v[i].size() == 0) continue;       sorted.push_back(make_pair(v[i][v[i].size() - 1].first, i));     }     sort(sorted.begin(), sorted.end());     scanf( %d , &q);     while (q--) {       int k, x;       scanf( %d , &k);       for (i = 0; i < k; i++) {         scanf( %d , &Query[i]);         mark[Query[i]] = 1;       }       for (i = (int)sorted.size() - 1; i >= 0; --i)         if (!mark[sorted[i].second]) break;       if (i < 0) {         printf( 0 0 n );         for (i = 0; i < k; i++) mark[Query[i]] = 0;         continue;       }       int p = sorted[i].second;       int lo = 0, hi = v[p].size() - 1, mid;       while (lo < hi) {         mid = (lo + hi) / 2;         int pos = v[p][mid].second, val = v[p][mid].first;         int cnt = (int)v[p].size() - 1 - mid;         for (i = 0; i < k; i++) {           if ((int)v[Query[i]].size() == 0) continue;           int pos = upper_bound(v[Query[i]].begin(), v[Query[i]].end(),                                 make_pair(val, 0)) -                     v[Query[i]].begin();           cnt += (int)v[Query[i]].size() - pos;         }         if (cnt == n - 1 - pos)           hi = mid;         else           lo = mid + 1;       }       printf( %d %d n , p, v[p][lo].first);       for (i = 0; i < k; i++) mark[Query[i]] = 0;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long oo = 1e18;   const long long maxn = 2e5, maxm = 1e6, M = 20;   struct girl {     long long w, id;     bool operator<(const girl a) const { return w > a.w; }   };   pair<long long, long long> operator+(pair<long long, long long> a,                                        pair<long long, long long> b) {     return make_pair(a.first + b.first, a.second + b.second);   }   vector<girl> gf[maxn];   vector<int> g[maxn];   priority_queue<girl> Q[maxn];   pair<long long, long long> Min[maxm];   long long c[maxn], d[maxn], X[maxn][2], Y[maxn];   long long f[maxn][22];   long long nex[maxn], par[maxn], size[maxn], per[maxn];   long long Z[maxm], pos[maxm];   girl sta[maxn];   long long tot, L, R;   long long n, m, q, i, j, x, y, z, la;   void partition(long long o, long long fa) {     f[o][0] = fa;     size[o] = 1;     d[o] = d[fa] + 1;     long long len = g[o].size(), i;     for (i = 0; i < len; i++) {       long long v = g[o][i];       if (v == fa) continue;       partition(v, o);       size[o] += size[v];       if (size[v] > size[nex[o]]) nex[o] = v;     }   }   void dfs(long long o, long long fa) {     X[o][0] = ++tot;     Y[tot] = o;     if (nex[o]) dfs(nex[o], o);     long long len = g[o].size(), i;     for (i = 0; i < len; i++) {       long long v = g[o][i];       if (v == fa || v == nex[o]) continue;       dfs(v, o);     }     X[o][1] = tot;   }   void getPar(long long o, long long fa) {     if (nex[o]) getPar(nex[o], fa);     par[o] = fa;   }   void update(long long o) {     if (Min[2 * o] + make_pair(Z[2 * o], 0) <         Min[2 * o + 1] + make_pair(Z[2 * o + 1], 0)) {       Min[o] = Min[2 * o] + make_pair(Z[2 * o], 0);       pos[o] = pos[2 * o];     } else {       Min[o] = Min[2 * o + 1] + make_pair(Z[2 * o + 1], 0);       pos[o] = pos[2 * o + 1];     }   }   void pushdown(long long o) {     Z[2 * o] += Z[o];     Z[2 * o + 1] += Z[o];     Z[o] = 0;   }   void build(long long o, long long l, long long r) {     if (l + 1 == r) {       Q[l].push((girl){oo, 0});       long long len = gf[Y[l]].size(), i;       for (i = 0; i < len; i++) Q[l].push(gf[Y[l]][i]);       Min[o] = make_pair(Q[l].top().w, Y[l]);       pos[o] = l;       return;     }     long long m = (l + r) >> 1;     build(2 * o, l, m);     build(2 * o + 1, m, r);     update(o);   }   void change(long long o, long long l, long long r, long long x, long long y,               long long z) {     if (x <= l && r <= y) {       Z[o] += z;       return;     }     pushdown(o);     long long m = (l + r) >> 1;     if (x < m) change(2 * o, l, m, x, y, z);     if (m < y) change(2 * o + 1, m, r, x, y, z);     update(o);   }   void find(long long o, long long l, long long r, long long x, long long y,             pair<long long, long long> &MIN, long long &POS) {     if (x <= l && r <= y) {       if (Min[o] + make_pair(Z[o], 0) < MIN) {         MIN = Min[o] + make_pair(Z[o], 0);         POS = pos[o];       }       return;     }     pushdown(o);     long long m = (l + r) >> 1;     if (x < m) find(2 * o, l, m, x, y, MIN, POS);     if (m < y) find(2 * o + 1, m, r, x, y, MIN, POS);     update(o);   }   void take(long long o, long long l, long long r, long long v, girl &re) {     if (l + 1 == r) {       re = Q[l].top();       re.w += Z[o];       Q[l].pop();       Min[o] = make_pair(Q[l].top().w, Y[l]);       pos[o] = l;       return;     }     pushdown(o);     long long m = (l + r) >> 1;     if (v < m)       take(2 * o, l, m, v, re);     else       take(2 * o + 1, m, r, v, re);     update(o);   }   void insert(long long o, long long l, long long r, long long v, girl re) {     if (l + 1 == r) {       re.w -= Z[o];       Q[l].push(re);       Min[o] = make_pair(Q[l].top().w, Y[l]);       pos[o] = l;       return;     }     pushdown(o);     long long m = (l + r) >> 1;     if (v < m)       insert(2 * o, l, m, v, re);     else       insert(2 * o + 1, m, r, v, re);     update(o);   }   long long lca(long long x, long long y) {     if (d[x] < d[y]) swap(x, y);     long long i;     for (i = M; i >= 0; i--)       if (d[f[x][i]] >= d[y]) x = f[x][i];     if (x == y) return x;     for (i = M; i >= 0; i--)       if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];     return f[x][0];   }   girl find(long long u, long long v) {     long long a = lca(u, v);     pair<long long, long long> MIN = make_pair(oo, 0);     long long POS = 0;     for (long long i = 1; i <= 2; i++) {       while (d[u] >= d[a]) {         if (d[par[u]] >= d[a]) {           find(1, L, R, X[par[u]][0], X[u][0] + 1, MIN, POS);           u = f[par[u]][0];         } else {           find(1, L, R, X[a][0], X[u][0] + 1, MIN, POS);           u = f[a][0];         }       }       u = v;     }     girl re = (girl){oo, 0};     if (MIN == make_pair(oo, 0ll)) return re;     take(1, L, R, POS, re);     return re;   }   void solve(long long u, long long v, long long K) {     long long i, j;     for (i = 1; i <= K; i++) {       sta[i] = find(u, v);       if (sta[i].id == 0) break;     }     printf( %lld , i - 1);     for (j = 1; j < i; j++) printf(  %lld , sta[j].id);     printf(  n );   }   bool cmp(long long a, long long b) { return d[a] < d[b]; }   int main() {     scanf( %lld%lld%lld , &n, &m, &q);     for (i = 1; i < n; i++) {       scanf( %lld%lld , &x, &y);       g[x].push_back(y);       g[y].push_back(x);     }     for (i = 1; i <= m; i++) {       scanf( %lld , &x);       c[i] = x;       gf[x].push_back((girl){i, i});     }     partition(1, 0);     dfs(1, 0);     for (i = 1; i <= n; i++) per[i] = i;     sort(per + 1, per + n + 1, cmp);     for (i = 1; i <= n; i++)       if (!par[per[i]]) getPar(per[i], per[i]);     for (i = 1; i <= M; i++)       for (j = 1; j <= n; j++) f[j][i] = f[f[j][i - 1]][i - 1];     L = 1;     R = n + 1;     build(1, L, R);     for (long long qq = 1; qq <= q; qq++) {       scanf( %lld , &x);       if (x == 1) {         scanf( %lld%lld%lld , &x, &y, &z);         solve(x, y, z);       } else {         scanf( %lld%lld , &x, &y);         change(1, L, R, X[x][0], X[x][1] + 1, y);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[111];   int main() {     int n;     scanf( %d , &n);     for (int i = (0); i < (n); ++i) scanf( %d , &arr[i]);     sort(arr, arr + n);     int t = 10;     int ans = 0;     int qts = 0;     for (int i = (0); i < (n); ++i) {       t += arr[i];       if (t > 720) break;       qts++;       if (t > 360) ans += (t - 360);     }     printf( %d %d n , qts, ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 10;   int T, N;   int a[MAX];   int main() {     scanf( %d , &T);     while (T--) {       scanf( %d , &N);       for (int i = 1; i <= N; i++) scanf( %d , &a[i]);       sort(a + 1, a + 1 + N);       int l = (N + 1) / 2, r = (N + 1) / 2;       printf( %d , a[l]);       for (int i = 1; i < N; i++) {         if (i & 1)           printf(  %d , a[++r]);         else           printf(  %d , a[--l]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int a, long long int b);   int main() {     long long int a, b, c, i, j, x, k, sum, count;     scanf( %lld , &a);     scanf( %lld , &b);     scanf( %lld , &c);     long long int arr[81];     count = 0;     for (i = 1; i < 82; i++) {       long long int t = power(i, a);       k = ((b * t) + c);       if (k <= 0 && k >= 1000000000) continue;       x = k;       sum = 0;       while (x != 0) {         j = x % 10;         x = x / 10;         sum = sum + j;       }       if (sum == i && k > 0 && k < 1000000000) {         count++;         arr[count - 1] = k;       }     }     cout << count;     if (count) {       cout << endl;       for (i = 0; i < count; i++) {         cout << arr[i] <<    ;       }     }     return 0;   }   long long int power(long long int a, long long int b) {     long long int tpower = 1;     for (int i = 0; i < b; i++) {       tpower = tpower * a;     }     return tpower;   }


#include <bits/stdc++.h>   using namespace std;   int n;   bool r[100], c[100];   int main() {     cin >> n;     vector<int> ans;     for (int i = 1; i <= n * n; i++) {       int x, y;       cin >> x >> y;       if (!r[x] && !c[y]) {         ans.push_back(i);         r[x] = true;         c[y] = true;       }     }     for (int i = 0; i < ans.size(); i++) {       cout << ans[i] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, i;     char ch;     char str[2010];     scanf( %d , &n);     scanf( %c , &ch);     if (n % 2 == 1) {       scanf( %c , &str[n / 2]);       for (i = 1; i <= n / 2; i++) {         scanf( %c , &str[n / 2 - i]);         scanf( %c , &str[n / 2 + i]);       }     } else {       scanf( %c , &str[n / 2 - 1]);       for (i = 1; i < n / 2; i++) {         scanf( %c , &str[n / 2 - 1 + i]);         scanf( %c , &str[n / 2 - 1 - i]);       }       scanf( %c , &str[n - 1]);     }     str[n] =   0 ;     printf( %s n , str);     return 0;   }


#include<bits/stdc++.h>   using namespace std;   const int N=3e5+10;   int n,m,mx;   int dif[N],b[N];    vector <int> a[N];   void end(){    puts( No ); exit(0);    }   int main(){    scanf( %d%d ,&n,&m);    for(int i=1;i<=n;i++){     a[i].push_back(0);     for(int j=1;j<=m;j++){ int x; scanf( %d ,&x); a[i].push_back(x); }     }    for(int i=2;i<=n;i++){     for(int j=1;j<=m;j++) if(a[1][j]!=a[i][j]) dif[i]++;       mx=max(mx,dif[i]);     }    if(mx>4) end();     if(mx<=2){     puts( Yes );     for(int i=1;i<=m;i++) printf( %d  ,a[1][i]); exit(0);     }    if(mx==4){     int ps=0,now=0,cur[4]={};      for(int i=2;i<=n;i++) if(dif[i]==4){ ps=i; break; }     for(int i=1;i<=m;i++) if(a[1][i]!=a[ps][i]) cur[now++]=i;           for(int i=0;i<4;i++)      for(int j=i+1;j<4;j++){        for(int k=1;k<=m;k++) b[k]=a[1][k];       for(int k=0;k<4;k++){        if(k!=i && k!=j) b[cur[k]]=a[ps][cur[k]];        }              int pd=0;       for(int k=1;k<=n;k++){        int sum=0; for(int p=1;p<=m;p++) if(a[k][p]!=b[p]) sum++;         if(sum>2){ pd=1; break; }       }       if(!pd){        puts( Yes );        for(int k=1;k<=m;k++) printf( %d  ,b[k]); exit(0);        }      }      end();     }    else if(mx==3){      int ps=0,now=0,cur[3]={};     for(int i=2;i<=n;i++) if(dif[i]==3){ ps=i; break; }     for(int i=1;i<=m;i++) if(a[1][i]!=a[ps][i]) cur[now++]=i;           for(int p=0;p<3;p++)      for(int q=p+1;q<3;q++){       for(int d=0;d<2;d++){        for(int i=1;i<=m;i++) b[i]=a[1][i];         if(d==0){         b[cur[q]]=a[ps][cur[q]];         }        else{         b[cur[p]]=a[ps][cur[p]];          }                int pd=0,vis=0,at=0;        for(int i=2;i<=n;i++){         int sum=0; for(int j=1;j<=m;j++) if(a[i][j]!=b[j]) sum++;         if(sum>=3){ vis=1; at=i; break; }        }        if(!vis){         puts( Yes );          for(int i=1;i<=m;i++) printf( %d  ,b[i]); exit(0);        }        else{         b[cur[3-p-q]]=a[at][cur[3-p-q]];          for(int i=2;i<=n;i++){          int sum=0; for(int j=1;j<=m;j++) if(a[i][j]!=b[j]) sum++;           if(sum==3){ pd=1; break; }         }         if(!pd){          puts( Yes );           for(int i=1;i<=m;i++) printf( %d  ,b[i]); exit(0);                }        }       }      }          end();     }        }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     int uppery = y2 + 1;     int lowery = y2 - 1;     int upperx = x2 + 1;     int lowerx = x2 - 1;     int ans = 4;     ans +=         abs(x1 - upperx) + abs(y1 - lowery) + abs(x1 - lowerx) + abs(y1 - uppery);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int a) {     long long int pdt = 1, i = 0, t = 19;     while (i++ < min(a, t)) pdt *= 2;     return pdt;   }   int main() {     long long int n, b, i, j, cnt = 0, k = 0;     cin >> n >> b;     long long int a[n], c[n];     b = power((b * 8) / n);     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     for (i = 0; i < n; i++) {       j = i + 1;       while (j < n && a[j] == a[i]) j++;       cnt++;       c[k++] = j - i;       i = j - 1;     }     if (cnt < b)       cout << 0;     else {       long long int maxi = 0;       for (i = 0; i < k; i++) {         if (i > 0) c[i] += c[i - 1];         if (i - b >= 0)           maxi = max(maxi, c[i] - c[i - b]);         else if (!(i - b + 1))           maxi = max(maxi, c[i]);       }       cout << n - maxi << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[200005], s1[200005];   void sol() {     int i, l, xp;     l = strlen(s);     memset(s1, 0, sizeof(s1));     xp = -1;     for (i = 0; i < l; i++) {       if (xp == -1) {         xp++;         s1[xp] = s[i];         continue;       }       if (s1[xp] == s[i])         xp--;       else {         xp++;         s1[xp] = s[i];       }     }     xp++;     s1[xp] = 0;     printf( %s n , s1);   }   int main() {     while (gets(s)) sol();     return 0;   }


#include <bits/stdc++.h>    using namespace std;   typedef long long ll;   int main()    {    ll t;    cin>>t;    while(t--){     ll n,k;     cin>>n>>k;     ll ans;     if(n%2==0)     {      if(k%n==0)      ans=n;      else      ans=k%n;     }     else {      ll x1=k%n;      if(x1==0)      x1=n;      ll x2=(k/n);      if(k%n!=0)      x2++;      ll x3=x2%(n/2);      if(x3==0)      x3=n/2;      ll x4=(x3-1)*n+x1;      ll x5=x4/(n/2);      if(x4%(n/2)==0)      x5--;      ans=(x1+x5)%n;      if(ans==0)      ans=n;     }     cout<<ans<<endl;    }    return 0;   }