#include <bits/stdc++.h>   using namespace std;   int n, m;   int A[600006];   vector<int> G[600006];   int dfn[600006], bc[600006], clo;   int g[600006][20], dep[600006];   void dfs(int u) {     dfn[u] = ++clo, bc[clo] = u;     if (u == 1) dep[u] = 1;     for (int v : G[u]) {       g[v][0] = u;       dep[v] = dep[u] + 1;       for (int k = (1), kend = (18); k <= kend; ++k)         if (g[g[v][k - 1]][k - 1])           g[v][k] = g[g[v][k - 1]][k - 1];         else           break;       dfs(v);     }   }   int lca(int u, int v) {     if (dep[u] < dep[v]) swap(u, v);     if (dep[u] != dep[v])       for (int k = (18), kend = (0); k >= kend; --k)         if (dep[g[u][k]] >= dep[v]) u = g[u][k];     if (u == v) return u;     for (int k = (18), kend = (0); k >= kend; --k)       if (g[u][k] != g[v][k]) u = g[u][k], v = g[v][k];     return g[u][0];   }   int dis(int u, int v) { return dep[u] + dep[v] - 2 * dep[lca(u, v)]; }   set<int> S;   void solve() {     cin >> n;     ++n;     for (int i = (2), iend = (n); i <= iend; ++i) {       int p;       scanf( %d , &p);       G[p].push_back(i);     }     dfs(1);     int s = 1, t = 1, lt = 0;     auto wkr = [&](int x) { return max(dis(x, s), dis(x, t)); };     S.insert(1);     for (int i = (2), iend = (n); i <= iend; ++i) {       int is = dis(i, s), it = dis(i, t), flg = 0;       if (is >= lt && is >= it)         t = i, lt = is, flg = 1;       else if (it >= lt && it >= is)         s = i, lt = it, flg = 1;       if (!flg) {         printf( %d n , (int)S.size());         continue;       }       auto tr = S.lower_bound(dfn[i]), st = tr;       while (tr != S.end()) {         if (wkr(bc[*tr]) < lt)           ++tr;         else           break;       }       if (tr == S.end()) {         auto sr = S.begin();         while (sr != st) {           if (wkr(bc[*sr]) < lt)             ++sr;           else             break;         }         S.erase(S.begin(), sr);       }       S.erase(st, tr);       tr = S.lower_bound(dfn[i]), st = tr;       while (tr != S.begin()) {         --tr;         if (wkr(bc[*tr]) >= lt) {           ++tr;           break;         }       }       if (tr == S.begin()) {         auto sr = S.end();         while (sr != st) {           --sr;           if (wkr(bc[*sr]) >= lt) {             ++sr;             break;           }         }         S.erase(sr, S.end());       }       S.erase(tr, st);       S.insert(dfn[i]);       printf( %d n , (int)S.size());     }   }   signed main() { solve(); }


#include <bits/stdc++.h>   using namespace std;   struct fenwick {     long long n, fen[100005];     void resize(int _n) {       n = _n + 1;       memset(fen, 0, sizeof fen);     }     int query(int ind) {       ind++;       int ans = 0;       while (ind >= 1) {         ans += fen[ind];         ind -= ind & -ind;       }       return ans;     }     void update(int ind, int val) {       ind++;       while (ind <= n) {         fen[ind] += val;         ind += ind & -ind;       }     }     int query(int l, int r) { return query(r) - query(l - 1); }   };   const int maxn = 100001;   int n, l, w, x, y, sz[maxn];   long long res;   bool blocked[maxn];   vector<pair<int, int> > c, v[maxn];   fenwick tree;   void dfs(int node, int pnode, int curw, int curl) {     c.push_back(make_pair(curw, curl));     for (auto &i : v[node])       if (i.first != pnode && !blocked[i.first])         dfs(i.first, node, curw + i.second, curl + 1);   }   long long solve(int node, int curw, int curl) {     long long ret = 0;     c.clear();     dfs(node, 0, curw, curl);     sort(c.begin(), c.end());     for (auto &i : c) tree.update(i.second, 1);     for (int i = 0, j = c.size() - 1; i < c.size(); i++) {       while (i <= j && c[i].first + c[j].first > w)         tree.update(c[j--].second, -1);       if (j < i) break;       tree.update(c[i].second, -1);       ret += tree.query(l - c[i].second);     }     return ret;   }   int dfsz(int node, int pnode) {     sz[node] = 1;     for (auto &i : v[node])       if (i.first != pnode && !blocked[i.first]) sz[node] += dfsz(i.first, node);     return sz[node];   }   int find(int node, int pnode, int n) {     for (auto &i : v[node])       if (i.first != pnode && !blocked[i.first] && 2 * sz[i.first] > n)         return find(i.first, node, n);     return node;   }   void decompose(int node) {     int centroid = find(node, 0, dfsz(node, 0));     blocked[centroid] = 1;     res += solve(centroid, 0, 0);     for (auto &i : v[centroid])       if (!blocked[i.first]) res -= solve(i.first, i.second, 1);     for (auto &i : v[centroid])       if (!blocked[i.first]) decompose(i.first);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> l >> w;     tree.resize(n + 1);     for (int i = 2; i <= n && cin >> x >> y; i++) {       v[i].push_back(make_pair(x, y));       v[x].push_back(make_pair(i, y));     }     decompose(1);     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   const int maxn = 1e5 + 10;   const int N = 5e2 + 10;   using namespace std;   long long gcd(long long p, long long q) { return q == 0 ? p : gcd(q, p % q); }   long long qpow(long long p, long long q) {     long long f = 1;     while (q) {       if (q & 1) f = f * p % 1000000007;       p = p * p % 1000000007;       q >>= 1;     }     return f;   }   int n, m, k, t;   vector<int> d[4][11][10];   char a[maxn], b[maxn];   int gao(char p) {     if (p ==  A )       return 0;     else if (p ==  T )       return 1;     else if (p ==  G )       return 2;     else       return 3;   }   void add(vector<int>& d, int x, int y) {     while (x < d.size()) d[x] += y, x += x & (-x);   }   int get(vector<int>& d, int x) {     int ret = 0;     while (x) ret += d[x], x -= x & (-x);     return ret;   }   int main() {     int i, j;     scanf( %s , a + 1);     n = strlen(a + 1);     for (i = 0; i <= (int)3; i++)       for (j = 1; j <= (int)10; j++)         for (k = 0; k <= (int)j - 1; k++) d[i][j][k].resize((n + j - 1) / j + 1);     for (i = 1; i <= n; i++) {       for (j = 1; j <= 10; j++) {         add(d[gao(a[i])][j][(i - 1) % j], (i - 1) / j + 1, 1);       }     }     int q;     scanf( %d , &q);     while (q--) {       int op, x, y;       scanf( %d%d , &op, &x);       if (op == 1) {         scanf( %s , b);         for (i = 1; i <= (int)10; i++)           add(d[gao(a[x])][i][(x - 1) % i], (x - 1) / i + 1, -1);         for (i = 1; i <= (int)10; i++)           add(d[gao(b[0])][i][(x - 1) % i], (x - 1) / i + 1, 1);         a[x] = b[0];       } else {         scanf( %d%s , &y, b);         int len = strlen(b), ret = 0;         for (i = 0; i < len && i < y - x + 1; i++) {           int mo = (i + x - 1) % len;           ret += get(d[gao(b[i])][len][mo], (y - 1 - mo) / len + 1) -                  get(d[gao(b[i])][len][mo], (x - 1 + len - 1 - mo) / len);         }         printf( %d n , ret);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int i, j, t;     cin >> t;     for (long long int aa = 0; aa < t; aa++) {       long long int n, k, d;       cin >> n >> k >> d;       long long int mini = k;       vector<long long int> v(n);       map<long long int, long long int> m;       for (i = 0; i < n; i++) {         cin >> v[i];         if (i < d) {           long long int ss = m.size();           m[v[i]]++;           if (ss < m.size()) m[v[i]] = 1;         }       }       m.size() < mini ? mini = m.size() : mini = mini;       for (i = 1; i < n - d + 1; i++) {         m[v[i - 1]]--;         if (m[v[i - 1]] == 0) m.erase(v[i - 1]);         long long int ss = m.size();         m[v[i + d - 1]]++;         if (ss < m.size()) m[v[i + d - 1]] = 1;         m.size() < mini ? mini = m.size() : mini = mini;       }       m.size() < mini ? mini = m.size() : mini = mini;       cout << mini << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int *p = new int[n + 1], c = 0;     int *m = new int[n + 1];     for (int i = 0; i <= n; i++) {       p[i] = m[i] = 0;       c ^= i;       m[i] = c;     }     int f = 0;     for (int i = 1; i <= n; i++) {       cin >> p[i];       f ^= p[i];     }     int r = 0;     for (int i = 2; i <= n; i++) {       int grps = (n / i);       int rem = n % i;       if (grps & 1) r ^= m[i - 1];       r ^= m[rem];     }     cout << (r ^ f);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   long long a[maxn], b[maxn], dp[maxn];   int q[maxn];   int head = 0, tail = 0;   double A(int i, int j) { return dp[i] - dp[j]; }   double B(int i, int j) { return b[i] - b[j]; }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> b[i];     dp[1] = 0;     int head = 1, tail = 1;     q[tail] = 1;     for (int i = 2; i <= n; i++) {       while (head < tail &&              A(q[head + 1], q[head]) / B(q[head + 1], q[head]) >= -a[i])         head++;       dp[i] = dp[q[head]] + b[q[head]] * a[i];       while (head < tail && A(i, q[tail]) / B(i, q[tail]) >=                                 A(q[tail], q[tail - 1]) / B(q[tail], q[tail - 1]))         tail--;       q[++tail] = i;     }     cout << dp[n] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_INT = numeric_limits<int>::max();   const int MAX_UINT = numeric_limits<unsigned int>::max();   void get_acum(const vector<int>& v, vector<int>& acum) {     int sum = 0;     for (unsigned int i = 0; i < v.size(); ++i) {       acum.push_back(sum);       sum += v[i];     }     acum.push_back(sum);   }   int solve(vector<int>& A, vector<int>& B, vector<int>& X, unsigned int k) {     if (A.size() + X.size() < k || B.size() + X.size() < k) {       return -1;     } else {       sort(A.begin(), A.end());       sort(B.begin(), B.end());       sort(X.begin(), X.end());       vector<int> A_acum, B_acum, X_acum;       get_acum(A, A_acum);       get_acum(B, B_acum);       get_acum(X, X_acum);       int res = MAX_INT;       unsigned int max_i = min((unsigned int)X.size(), k);       for (unsigned int i = 0; i < max_i + 1; ++i) {         if (k - i < A_acum.size() && k - i < B_acum.size()) {           int total = A_acum[k - i] + B_acum[k - i] + X_acum[i];           if (total < res) res = total;         }       }       return res;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     unsigned int n, k;     cin >> n >> k;     vector<int> A;     vector<int> B;     vector<int> X;     for (unsigned int i = 0; i < n; ++i) {       unsigned int ti;       bool ai, bi;       cin >> ti >> ai >> bi;       if (ai && bi)         X.push_back(ti);       else if (ai)         A.push_back(ti);       else if (bi)         B.push_back(ti);     }     cout << solve(A, B, X, k);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<long long int> adj[3005];   map<long long int, long long int> mq;   long long int done[3005][3005];   int main() {     ios_base::sync_with_stdio(false);     long long int n, m, i, ans = 0;     cin >> n >> m;     for (i = 0; i < m; i++) {       long long int x, y;       cin >> x >> y;       adj[x].insert(y);     }     for (i = 1; i <= n; i++) {       for (auto it : adj[i]) {         for (auto it2 : adj[it]) {           if (mq.find(it2) != mq.end() && it2 != i) {             ans += mq[it2];           }           mq[it2]++;         }       }       mq.clear();     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int main() {     int a, b, h;     cin >> a >> b >> h;     int c = 0;     while (h != 0) {       if (c % 2 == 0) {         h = h - gcd(a, h);       } else {         h = h - gcd(b, h);       }       c++;     }     if (c % 2 == 0) {       cout << 1 << endl;     } else       cout << 0 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100000 + 5;   const double EPS = 1e-3;   int n;   int t[MAXN];   int g(double q) {     bool ok = true;     for (int i = 1; i < n; i++)       if (fabs(double(t[i] - t[i - 1] * q)) > EPS) ok = false;     if (ok) return 0;     ok = true;     for (int i = 2; i < n; i++)       if (fabs(double(t[i] - t[i - 1] * q)) > EPS) ok = false;     if (ok) return 1;     ok = true;     int prev = t[0];     for (int i = 1; i < n; i++)       if (fabs(double(t[i] - prev * q)) > EPS) {         if (!ok) return 2;         ok = false;       } else         prev = t[i];     return 1;   }   int f() {     if (n == 1) return 0;     double q1 = 0, q2 = 0;     if (t[0] != 0) q1 = double(t[1]) / t[0];     if (t[n - 2] != 0) q2 = double(t[n - 1]) / t[n - 2];     return min(g(q1), g(q2));   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &t[i]);     printf( %d n , f());   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e6 + 5;   int a[MAX], run[MAX], ans[MAX];   char s[MAX];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     scanf( %d , &n);     scanf( %s , s);     for (int i = 0; i < n; ++i) {       if (s[i] ==  0 )         a[i] = 0;       else if (s[i] ==  1 )         a[i] = 1;       else         a[i] = -1;     }     vector<pair<int, int>> blocks;     int it1 = 0, it2 = 0;     while (it1 != n) {       while (it2 < n - 1 && a[it1] == a[it2 + 1]) ++it2;       blocks.emplace_back(it2 - it1 + 1, a[it1]);       ++it2;       it1 = it2;     }     for (int i = 0; i < (int)blocks.size(); ++i) {       if (blocks[i].second != -1) continue;       if (i == 0)         blocks[i].second = blocks[i + 1].second;       else if (i == (int)blocks.size() - 1)         blocks[i].second = blocks[i - 1].second;       else if (blocks[i - 1].second == blocks[i + 1].second)         blocks[i].second = blocks[i - 1].second;     }     vector<pair<int, int>> compress;     it1 = 0;     it2 = 0;     while (it1 != (int)blocks.size()) {       int len = blocks[it1].first;       while (it2 < (int)blocks.size() - 1 &&              blocks[it1].second == blocks[it2 + 1].second)         it2++, len += blocks[it2].first;       compress.emplace_back(len, blocks[it1].second);       ++it2;       it1 = it2;     }     for (auto block : compress) {       if (block.second == -1) continue;       for (int len = 1; len <= block.first; len++) ans[len] += block.first / len;     }     int max_size = -1, bef = -2;     int size = compress.size();     for (int i = 0; i < size; i++) {       int len = compress[i].first;       int type = compress[i].second;       if (bef != -1 && type != -1) {         max_size = len;         if (i != size - 1) max_size += compress[i + 1].first;         for (int l = 1; l <= max_size; l++) run[l] = len % l;       } else if (type == -1) {         for (int l = 1; l <= max_size; l++) {           if (run[l] + len >= l)             run[l] += len, ans[l] += run[l] / l, run[l] %= l;           else             run[l] = len;         }         int add = 0;         if (i != (int)size - 1) add += compress[i + 1].first;         if (i != (int)size - 2) add += compress[i + 2].first;         for (int l = max_size + 1; l <= len + add; ++l) run[l] = (len % l);         max_size = len + add;       } else {         for (int l = 1; l <= max_size; ++l) {           if (run[l] + (len % l) >= l)             run[l] += ((len % l) - l), ans[l]++;           else             run[l] += (len % l);         }       }       bef = type;     }     for (int i = 1; i <= n; ++i) printf( %d  , ans[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int f = 1, x = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) {         f = -1;       }       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   const int N = 55;   struct W {     int x, y, tx, ty, id;   } up[N], down[N];   bool cmp_down(W a, W b) { return a.tx == b.tx ? a.ty < b.ty : a.tx > b.tx; }   bool cmp_up(W a, W b) { return a.x == b.x ? a.y < b.y : a.x < b.x; }   vector<pair<int, int> > ans_fr, ans_to;   bool has[N][N];   void move_up(int& x, int y) {     int dx = x;     has[x][y] = 0;     has[x - 1][y] = 1;     ans_fr.push_back(make_pair(dx, y));     ans_to.push_back(make_pair(dx - 1, y));     --x;   }   void move_down(int& x, int y) {     int dx = x;     has[x][y] = 0;     has[x + 1][y] = 1;     ans_fr.push_back(make_pair(dx, y));     ans_to.push_back(make_pair(dx + 1, y));     ++x;   }   void move_left(int x, int& y) {     int dy = y;     has[x][y] = 0;     has[x][y - 1] = 1;     ans_fr.push_back(make_pair(x, dy));     ans_to.push_back(make_pair(x, dy - 1));     --y;   }   void move_right(int x, int& y) {     int dy = y;     has[x][y] = 0;     has[x][y + 1] = 1;     ans_fr.push_back(make_pair(x, dy));     ans_to.push_back(make_pair(x, dy + 1));     ++y;   }   void move_row(int& x, int& y, int tx, int ty) {     while (y < ty && has[x][y + 1] == 0) {       move_right(x, y);     }     while (y > ty && has[x][y - 1] == 0) {       move_left(x, y);     }   }   void move(int& x, int& y, int tx, int ty) {     while (x < tx) {       move_down(x, y);     }     while (x > tx) {       move_up(x, y);     }     while (y < ty) {       move_right(x, y);     }     while (y > ty) {       move_left(x, y);     }   }   int check(W a) {     if (a.x == a.tx) {       return a.y == a.ty ? 0 : 1;     } else {       return a.y == a.ty ? 2 : 3;     }   }   int nx[N], ny[N];   char mp[N][N];   int vis[N];   void write(int n) {     for (int i = 1; i <= n; i++) {       cout << mp[i] + 1 << endl;     }     puts( ---------------------- );   }   void deal(int n, int m) {     if (n == 1) {       puts( 0 );     } else {       if (m == 1) {         move(up[1].x, up[1].y, up[1].tx, up[1].ty);       } else {         if (cmp_up(up[1], up[2]) == 0) {           swap(up[1], up[2]);         }         if (up[1].x == 2) {           move_up(up[1].x, up[1].y);           move_up(up[2].x, up[2].y);         } else if (up[2].x == 2) {           move_up(up[2].x, up[2].y);         }         switch (check(up[1])) {           case 0:             break;           case 1:             move(up[2].x, up[2].y, 2, 1);             move_right(up[1].x, up[1].y);             break;           case 2:             move(up[1].x, up[1].y, up[1].tx, up[1].ty);             break;           case 3:             move(up[1].x, up[1].y, up[1].tx, up[1].ty);             move_left(up[2].x, up[2].y);             break;         }         move(up[2].x, up[2].y, up[2].tx, up[2].ty);       }       cout << ans_fr.size() << endl;       for (int i = 0; i < ans_fr.size(); i++) {         int xx1 = ans_fr[i].first, xx2 = ans_to[i].first;         int yy1 = ans_fr[i].second, yy2 = ans_to[i].second;         printf( %d %d %d %d n , xx1, yy1, xx2, yy2);       }     }   }   int main() {     int n = read(), m = read();     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         mp[i][j] =  . ;       }     }     for (int i = 1; i <= m; i++) {       up[i].id = i;       nx[i] = up[i].x = read();       ny[i] = up[i].y = read();       has[nx[i]][ny[i]] = 1;       mp[nx[i]][ny[i]] = i +  0 ;     }     for (int i = 1; i <= m; i++) {       up[i].tx = read();       up[i].ty = read();     }     if (n <= 2) {       deal(n, m);       return 0;     }     copy(up + 1, up + 1 + m, down + 1);     sort(up + 1, up + 1 + m, cmp_up);     int cnt = m;     while (cnt) {       for (int i = 1; i <= m; i++) {         if (vis[i] == 0) {           int id = up[i].id;           move_row(nx[id], ny[id], 1, i);           if (ny[id] == i) {             vis[i] = 1;             cnt--;           }         }       }     }     for (int i = 1; i <= m; i++) {       int id = up[i].id;       while (nx[id] > 1) {         move_up(nx[id], ny[id]);       }     }     for (int i = 1; i <= m; i++) {       move_down(nx[i], ny[i]);       move_down(nx[i], ny[i]);     }     sort(down + 1, down + 1 + m, cmp_down);     for (int i = 1; i <= m; i++) {       int id = down[i].id;       move_up(nx[id], ny[id]);       move_row(nx[id], ny[id], 1, i);       move_up(nx[id], ny[id]);     }     for (int i = 1; i <= m; i++) {       int id = down[i].id;       while (nx[id] < down[i].tx) {         move_down(nx[id], ny[id]);       }     }     cnt = m;     while (cnt) {       for (int i = 1; i <= m; i++) {         if (vis[i] == 1) {           int id = down[i].id;           move_row(nx[id], ny[id], nx[id], down[i].ty);           if (ny[id] == down[i].ty) {             vis[i] = 2;             cnt--;           }         }       }     }     assert(ans_fr.size() == ans_to.size());     assert(ans_fr.size() <= 10800);     cout << ans_fr.size() << endl;     for (int i = 0; i < ans_fr.size(); i++) {       int xx1 = ans_fr[i].first, xx2 = ans_to[i].first;       int yy1 = ans_fr[i].second, yy2 = ans_to[i].second;       printf( %d %d %d %d n , xx1, yy1, xx2, yy2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int a[m], b[m];     int ndup = n;     for (int i = 0; i < m; i++) {       cin >> a[i];       b[i] = a[i];     }     sort(a, a + m);     sort(b, b + m, greater<int>());     int mn = 0, mx = 0;     for (int i = 0; i < m; i++) {       while (a[i] > 0 && n > 0) {         mn += a[i];         a[i]--;         n--;       }     }     while (ndup > 0) {       mx += b[0];       b[0]--;       ndup--;       sort(b, b + m, greater<int>());     }     cout << mx <<     << mn;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, c, d, e, f, g, h, i, j, k, l, m, n, t;     cin >> t;     while (t--) {       cin >> n;       cout << (n + 1) / 2 << endl;     }   }


//...START BY DOING WHAT IS NECESSARY, THEN WHAT IS POSSIBLE AND SUDDENLY YOU ARE DOING THE IMPOSSIBLE...    #include <bits/stdc++.h>   using namespace std;   #define FAST_FURIER ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);   #define pb push_back   #define mk make_pair   #define rep(i,a,N) for(ll i=a;i<N;i++)   #define rrep(i,a,N) for(ll i=a;i>N;i--)   typedef long long ll;   #define M 1000000007   bool comp(int x,int y)   {       return x > y;   }           /*..............................code starts here........................*/   // C is first won in M           int main() {       FAST_FURIER;       int tt=1;       cin >> tt;       ll m,d,k;      //ll a,b,c;       while(tt--)       {           cin >> d >> k;           ll x = 0,y = 0;           int f = 0;           while(true){               ll d1 = pow(x+k,2)+pow(y,2), d2 = pow(x,2)+pow(y+k,2);               f = abs(f-1);               if(d1 < d2 and d1 <= d*d){                   x += k;               }               else if(d2 <= d1 and d2 <= d*d) y += k;               else break;           }           if(f) cout <<  Utkarsh ;           else cout <<  Ashish ;           cout << endl;          }   }               // Author : shivam_123       // g++ -std=c++17


#include <bits/stdc++.h>   using namespace std;   long long a, b, c, e[200000], mix, l, r, o, d[200000];   vector<long long> v[100000], v1;   set<long long> st;   map<long long, long long> mp, mp1;   string s;   pair<int, int> p[100000], p1[100000];   char ch[10];   deque<char> dq;   int main() {     cin >> a;     for (int i = 0; i < a / 4; i++)       if ((a - 2 * (i + 1)) % 2 == 0) c++;     if (a % 4 == 0) {       cout << c - 1;     } else       cout << c;   }


#include <bits/stdc++.h>   using namespace std;   char s[5000005];   int len[1000005];   int idx[1000005];   int sum[1000005];   int sz = 0;   int dp[1000005][20];   int p[1000005];   int main() {     int n, r, c;     scanf( %d%d%d , &n, &r, &c);     gets(s);     gets(s);     int cnt = 0, slen = 0;     for (int i = 0; s[i]; i++, slen++) {       if (s[i] ==     && cnt != 0) {         len[sz] = cnt;         idx[sz++] = i - cnt;         cnt = 0;       } else         cnt++;     }     if (cnt > 0) {       len[sz] = cnt;       idx[sz++] = slen - cnt;       cnt = 0;     }     sum[0] = len[0];     for (int i = 1; i < n; i++) sum[i] = sum[i - 1] + 1 + len[i];     for (int i = n - 1; i >= 0; i--) {       int id = upper_bound(sum, sum + n, (i > 0 ? sum[i - 1] + 1 : 0) + c) - sum;       if (id > n) id = n;       dp[i][0] = id - i;     }     for (int j = 2, t = 1; j <= r; j *= 2, t++) {       for (int i = n - 1; i >= 0; i--)         dp[i][t] = dp[i][t - 1] + dp[i + dp[i][t - 1]][t - 1];     }     int maid = -1, ma = 0;     for (int i = 0; i < n; i++) {       int idx = i, rr = r, cur = 0;       for (int j = 20; j >= 0; j--) {         if (rr >= (1 << j)) {           rr -= (1 << j);           cur += dp[idx][j];           idx += dp[idx][j];         }       }       if (cur > ma) maid = i, ma = cur;     }     int cn = 1, cs = dp[maid][0];     for (int i = maid; i < maid + ma; i++) {       s[idx[i] + len[i]] = 0;       if (cn < cs) {         printf( %s  , s + idx[i]);         cn++;       } else {         printf( %s n , s + idx[i]);         cs = dp[i + 1][0];         cn = 1;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char change(char curranswer) {     if (curranswer ==  z )       curranswer =  A ;     else if (curranswer ==  Z )       curranswer =  0 ;     else if (curranswer ==  9 )       ;     else       curranswer++;     return curranswer;   }   int main() {     long long i, j, t;     cin >> t;     while (t--) {       long long r, c, k;       long long rice = 0;       char a[100][100];       cin >> r >> c >> k;       for (i = 0; i < r; i++) {         for (j = 0; j < c; j++) {           cin >> a[i][j];           if (a[i][j] ==  R ) rice++;         }       }       long long ans = rice / k;       long long maxx = rice - k * ans;       long long minn = k - maxx;       char curranswer =  a ;       long long currcount = 0;       bool flag = true;       for (i = 0; i < r; i++) {         for (flag ? (j = 0) : (j = c - 1); flag ? (j < c) : j >= 0;              flag ? j++ : j--) {           bool local = false;           if (a[i][j] ==  R ) local = true;           a[i][j] = curranswer;           if (local) {             currcount++;             if (maxx > 0) {               if (currcount == ans + 1) {                 maxx--;                 currcount = 0;                 curranswer = change(curranswer);               }             } else if (minn > 0) {               if (currcount == ans) {                 minn--;                 currcount = 0;                 if (minn) curranswer = change(curranswer);               }             }           }         }         flag = !flag;       }       for (i = 0; i < r; i++) {         for (j = 0; j < c; j++) cout << a[i][j];         cout << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long x, long long y) {     if (y == 0)       return x;     else       return gcd(y, x % y);   }   long long expo(long long n, long long m) {     long long r = 1;     while (m > 0) {       if (m % 2) r = (r * n) % 1000000009;       n = (n * n) % 1000000009;       m = m / 2;     }     return r % 1000000009;   }   long long lx = 0, ly = 0;   bool check(long long x, long long y) {}   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long a, b;     cin >> a >> b;     string s;     cin >> s;     long long p = 0, q = 0;     if (a == 0 && b == 0) {       cout <<  Yes ;       return 0;     }     for (long long i = 0; i < s.size(); i++) {       if (s[i] ==  U ) {         ly++;       } else if (s[i] ==  D )         ly--;       else if (s[i] ==  L )         lx--;       else         lx++;       if (lx == a && ly == b) {         cout <<  Yes ;         return 0;       }     }     if (lx == 0 && ly == 0) {       cout <<  No ;       return 0;     }     for (long long i = 0; i < s.size(); i++) {       if (s[i] ==  U ) {         q++;       } else if (s[i] ==  D )         q--;       else if (s[i] ==  L )         p--;       else         p++;       long long x = a - p, y = b - q, X = lx, Y = ly;       if (lx == 0) {         if (ly > 0 && y > 0 && x == 0 && y % ly == 0) {           cout <<  Yes ;           return 0;         } else if (ly < 0 && y < 0 && x == 0) {           ly = -1 * ly, y = -1 * y;           if (y % ly == 0) {             cout <<  Yes ;             return 0;           }         }       } else if (ly == 0) {         if (lx > 0 && x > 0 && y == 0 && x % lx == 0) {           cout <<  Yes ;           return 0;         } else if (lx < 0 && x < 0 && y == 0) {           lx = -1 * lx, x = -1 * x;           if (x % lx == 0) {             cout <<  Yes ;             return 0;           }         }       } else {         if (lx > 0 && x > 0) {           if (ly > 0 && y > 0) {             if (x / lx == y / ly && x % lx == 0 && y % ly == 0) {               cout <<  Yes ;               return 0;             }           } else if (ly < 0 && y < 0) {             ly = -1 * ly, y = -1 * y;             if (x / lx == y / ly && x % lx == 0 && y % ly == 0) {               cout <<  Yes ;               return 0;             }           }         } else if (lx < 0 && x < 0) {           lx = -1 * lx, x = -1 * x;           if (ly > 0 && y > 0) {             if (x / lx == y / ly && x % lx == 0 && y % ly == 0) {               cout <<  Yes ;               return 0;             }           } else if (ly < 0 && y < 0) {             ly = -1 * ly, y = -1 * y;             if (x / lx == y / ly && x % lx == 0 && y % ly == 0) {               cout <<  Yes ;               return 0;             }           }         }       }       lx = X, ly = Y;     }     cout <<  No ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = int(3e5), mod = int(1e9) + 7;   int n;   int a[N], c[N];   long long t[N];   long long x[N], pref[N];   long double p[N];   long long suf[N];   void upd(int v, int val) {     v += n - 1;     t[v] += val;     c[v]++;     while (v > 1) {       v >>= 1;       t[v] = t[v + v] + t[v + v + 1];       c[v] = c[v + v] + c[v + v + 1];     }   }   long long get(int l, int r) {     l += n - 1;     r += n - 1;     long long res = 0;     while (l <= r) {       if (l & 1) res += t[l];       if (!(r & 1)) res += t[r];       l = (l + 1) >> 1;       r = (r - 1) >> 1;     }     return res;   }   int cnt(int l, int r) {     l += n - 1;     r += n - 1;     int res = 0;     while (l <= r) {       if (l & 1) res += c[l];       if (!(r & 1)) res += c[r];       l = (l + 1) >> 1;       r = (r - 1) >> 1;     }     return res;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     long long all = 1ll * n * (n + 1) / 2;     long double res = 0;     for (int i = 1; i <= n; i++) {       long long cur = get(1, a[i] - 1);       long double p = (cur + 0.0) * (n - i + 1) / all;       res += p * 0.5;       cur = get(a[i] + 1, n);       p = (cur + 0.0) * (n - i + 1) / all;       res += cnt(a[i] + 1, n);       res -= p * 0.5;       upd(a[i], i);     }     printf( %.12lf , double(res));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b;     cin >> a >> b;     long long ans = 0;     while (true) {       long long x = max(a, b);       long long y = min(a, b);       if (x == 0 || y == 0) break;       long long n = x / y;       ans += n;       x -= n * y;       a = x;       b = y;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int x, test;     cin >> test;     while (test--) {       int n, c0, c1, h;       string s;       cin >> n >> c0 >> c1 >> h >> s;       int cnt0 = 0, cnt1 = 0;       for (auto &z : s) {         cnt0 += z ==  0 ;         cnt1 += z ==  1 ;       }       int cost = (cnt0 * c0) + (cnt1 * c1);       int cost0 = (c0 * n) + (cnt1 * h);       int cost1 = (c1 * n) + (cnt0 * h);       cout << min({cost, cost0, cost1}) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = int(1e9) + 123;   int main() {     int n, v;     cin >> n >> v;     vector<int> a;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       a.push_back(x);     }     sort(a.begin(), a.end());     int sum = 0;     for (int i = 0; i < a.size() - 1; i++) {       sum += a[i];     }     if (sum <= v) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }