#include <bits/stdc++.h>   using namespace std;   #define pb push_back   #define mp make_pair   #define x first   #define y second   #define LL long long   #define LD long double   #define Complex complex<double>   #define y1 ___y1   #define next ___next   #define left ___left   #define right ___right   #define pii pair<int, int>   #define pll pair<LL, LL>   #define pdd pair<double, double>   #define pldld pair<LD, LD>   #define vi vector<int>   #define vl vector<LL>   #define vii vector<pii>   #define vll vector<pll>   #define PQ priority_queue   #define ffo fflush(stdout)   #define gch getchar()   #define e (int)(1e9 + 7)   #define e2 (double)2.71828182846   #define pi (double)3.14159265358979   #define ri(X) scanf( %d , &(X))   #define rii(X, Y) scanf( %d%d , &(X), &(Y))   #define riii(X, Y, Z) scanf( %d%d%d , &(X), &(Y), &(Z))   #define rl(X) scanf( %lld , &(X))   #define rll(X, Y) scanf( %lld%lld , &(X), &(Y))   #define rlll(X, Y, Z) scanf( %lld%lld%lld , &(X), &(Y), &(Z))   #define printi(X) printf( %d , (int)(X))   #define printii(X, Y) printf( %d %d , (int)(X), (int)(Y))   #define printiii(X, Y, Z) printf( %d %d %d , (int)(X), (int)(Y), (int)(Z))   #define printl(X) printf( %lld , (LL)(X))   #define printll(X, Y) printf( %lld %lld , (LL)(X), (LL)(Y))   #define printlll(X, Y, Z) printf( %lld %lld %lld , (LL)(X), (LL)(Y), (LL)(Z))   #define enter printf(  n )   #define space printf(   )   struct matrix {       int sz;       LL a[105][105];       matrix& operator = (const matrix &T) {           sz = T.sz;           for (int i = 1; i <= sz; i++) {               for (int j = 1; j <= sz; j++) {                   a[i][j] = T.a[i][j];               }           }           return *this;       }       matrix operator + (const matrix &T) const {           matrix ans;           ans.sz = sz;           for (int i = 1; i <= sz; i++) {               for (int j = 1; j <= sz; j++) {                   ans.a[i][j] = a[i][j] + T.a[i][j];                   ans.a[i][j] %= e;               }           }           return ans;       }       matrix operator * (const matrix &T) const {           matrix ans;           ans.sz = sz;           for (int i = 1; i <= sz; i++) {               for (int j = 1; j <= sz; j++) {                   ans.a[i][j] = 0;                   for (int k = 1; k <= sz; k++) {                       ans.a[i][j] += a[i][k] * T.a[k][j];                       ans.a[i][j] %= e;                   }               }           }           return ans;       }       matrix I() {           matrix ans;           ans.sz = sz;           for (int i = 1; i <= sz; i++) {               for (int j = 1; j <= sz; j++) {                   if (i == j) ans.a[i][j] = 1;                   else ans.a[i][j] = 0;               }           }           return ans;       }       matrix power(LL p) {           if (p == 0) return I();           if (p == 1) return *this;           matrix tmp = power(p / 2);           if (p % 2) tmp = tmp * tmp * (*this);           else tmp = tmp * tmp;           return tmp;       }       void print() {           for (int i = 1; i <= sz; i++) {               for (int j = 1; j <= sz; j++) {                   printf(j == sz?  %lld n  :  %lld  , a[i][j]);               }           }           return;       }   };   struct polynomial {       vector<Complex> v;       int sz;       polynomial operator * (const polynomial &T) const {           polynomial ans;           if (sz >= T.sz) {               ans = *this;               for (int i = 0; i < T.sz; i++) {                   ans.v[i] *= T.v[i];               }           }           else {               ans = T;               for (int i = 0; i < sz; i++) {                   ans.v[i] *= v[i];               }           }           return ans;       }   };   polynomial FFT(polynomial a) {       if (a.sz <= 1) return a;       polynomial even, odd;       even.sz = odd.sz = 0;       for (int i = 0; i < a.sz; i += 2) {           even.v.pb(a.v[i]);           even.sz++;       }       for (int i = 1; i < a.sz; i += 2) {           odd.v.pb(a.v[i]);           odd.sz++;       }       polynomial Even = FFT(even);       polynomial Odd = FFT(odd);       polynomial ans;       ans.sz = a.sz;       for (int i = 0; i < ans.sz; i++) {           ans.v.pb(0);       }       for (int i = 0; i < a.sz / 2; i++) {           Complex w = polar(1.0, -2 * pi * i / a.sz) * Odd.v[i];           ans.v[i] = Even.v[i] + w;           ans.v[i + a.sz / 2] = Even.v[i] - w;       }       return ans;   }   polynomial IFFT(polynomial a) {       for (int i = 0; i < a.sz; i++) {           a.v[i] = conj(a.v[i]);       }       polynomial ans = FFT(a);       for (int i = 0; i < a.sz; i++) {           ans.v[i] = conj(ans.v[i]);           ans.v[i] /= ans.sz;       }       return ans;   }   struct polygon {       int n;       pii a[1005];       double area() {           double d1 = 0, d2 = 0;           for (int i = 0; i < n; i++) {               d1 += a[i].x * a[(i + 1) % n].y;               d2 += a[(i + 1) % n].x * a[i].y;           }           return (d1 - d2) / 2;       }       bool inside(pldld p) {           int ct = 0;           LD d;           pldld p1 = a[0];           for (int i = 1; i <= n; i++) {               pldld p2 = a[i % n];               if (p.y > min(p1.y, p2.y) && p.y <= max(p1.y, p2.y) && p.x <= max(p1.x, p2.x) && p1.y != p2.y) {                   d = (p.y - p1.y) * (p2.x - p1.x) / (p2.y - p1.y) + p1.x;                   if (p1.x == p2.x || p.x <= d) ct++;               }               p1 = p2;           }           return ct % 2;       }   };   struct segtree {       int l, r, mid;       LL val = 0, lazy = 0;       segtree *lc, *rc;       segtree(int L, int R) {           l = L;           r = R;           mid = (l + r) / 2;           if (l != r) {               lc = new segtree(l, mid);               rc = new segtree(mid + 1, r);           }       }       void apply(LL X) {           val += X;           // val += X * (r - l + 1);           lazy += X;       }       void push() {           if (l == r) return;           lc->apply(lazy);           rc->apply(lazy);           lazy = 0;       }       void update(int L, int R, LL X) {           push();           if (l == L && r == R) {               apply(X);               return;           }           else if (R <= mid) lc->update(L, R, X);           else if (L >= mid + 1) rc->update(L, R, X);           else {               lc->update(L, mid, X);               rc->update(mid + 1, R, X);           }           val = min(lc->val, rc->val);           // val = lc->val + rc->val;       }       LL query(int L, int R) {           push();           if (l == L && r == R) return val;           else if (R <= mid) return lc->query(L, R);           else if (L >= mid + 1) return rc->query(L, R);           else {               return min(lc->query(L, mid), rc->query(mid + 1, R));               // return lc->query(L, mid) + rc->query(mid + 1, R);           }       }       //segroot = new segtree(0, n - 1)   } *segroot;   LL power(LL a, LL p) {       if (p == 0) return 1;       if (p == 1) return a;       LL tmp = power(a, p / 2);       if (p % 2) tmp = tmp * tmp % e * a;       else tmp *= tmp;       return tmp % e;   }   struct node {       int num;       int l, r;   };      int T;   int n, a[200005];   node p[200005];      void solve(int CASE) {       ri(n);       for (int i = 1; i <= n; i++) {           ri(a[i]);       }       int small = 0;       int big = 0;       int sz = 3;       p[3].l = 1;       p[3].r = 2;       p[3].num = a[1];       int pl = 3;       for (int i = 2; i <= n; i++) {           if (a[i] == p[pl].num) {           }           else if (a[i] > p[pl].num) {               if (p[pl].r == 2) {                   int next = ++sz;                   p[pl].r = next;                   p[next].num = a[i];                   p[next].l = pl;                   p[next].r = 2;                   pl = next;               }               else if (p[p[pl].r].num == a[i]) {                   pl = p[pl].r;               }               else if (p[p[pl].r].num > a[i]) {                   int next = ++sz;                   p[next].num = a[i];                   p[next].l = pl;                   p[next].r = p[pl].r;                   p[p[next].r].l = next;                   p[pl].r = next;                   pl = next;               }               else {                   printf( NO n );                   return;               }           }           else {               if (p[pl].l == 1) {                   int next = ++sz;                   p[pl].l = next;                   p[next].num = a[i];                   p[next].l = 1;                   p[next].r = pl;                   pl = next;               }               else if (p[p[pl].l].num == a[i]) {                   pl = p[pl].l;               }               else if (p[p[pl].l].num < a[i]) {                   int next = ++sz;                   p[next].num = a[i];                   p[next].r = pl;                   p[next].l = p[pl].l;                   p[p[next].l].r = next;                   p[pl].l = next;                   pl = next;               }               else {                   printf( NO n );                   return;               }           }       }       printf( YES n );       return;   }      int main() {       // ios::sync_with_stdio(false);       // cin.tie(NULL), cout.tie(NULL);       T = 1;       ri(T); // delete if one test case       for (int _ = 1; _ <= T; _++) {           solve(_);       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     ll N, M;     cin >> N >> M;     if (N > M) swap(N, M);     ll rem = 0;     if (N == 1) {       rem = min(M % 6, 6 - M % 6);     } else {       if (N % 2 == 1 && M % 2 == 1) {         rem = 1;       } else {         if (M == 2) {           rem = 4;         } else if (M == 3 || M == 7) {           rem = 2;         } else {           rem = 0;         }       }     }     cout << N * M - rem << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   constexpr int maxn = 2200;   LL a[maxn * 2], b[maxn * 2];   using PII = pair<int, int>;   constexpr int inf = 1000000000;   struct SSPA {     struct Edge {       int u, v, f, c;     };     int n, s, t;     vector<Edge> edges;     vector<vector<int>> adj;     vector<int> h, d, p, done;     SSPA(int n, int s, int t) : n(n), s(s), t(t) {       adj.resize(n);       h.resize(n);       d.resize(n);       p.resize(n);       done.resize(n);     }     void add(int u, int v, int f, int c) {       adj[u].push_back(edges.size());       edges.push_back({u, v, f, c});       adj[v].push_back(edges.size());       edges.push_back({v, u, 0, -c});     }     bool dijkstra() {       fill(d.begin(), d.end(), inf);       fill(p.begin(), p.end(), -1);       fill(done.begin(), done.end(), 0);       priority_queue<PII, vector<PII>, greater<PII>> q;       q.push({d[s] = 0, s});       while (not q.empty()) {         int u = q.top().second;         q.pop();         if (done[u]) continue;         done[u] = 1;         for (int i : adj[u]) {           if (auto& e = edges[i]; e.f and d[e.v] > d[e.u] + e.c + h[u] - h[e.v]) {             p[e.v] = i;             q.push({d[e.v] = d[e.u] + e.c + h[u] - h[e.v], e.v});           }         }       }       return ~p[t];     }     int min_cost_flow() {       int flow = 0, cost = 0;       while (dijkstra()) {         for (int i = 0; i < n; i += 1) h[i] += d[i];         int f = inf;         for (int u = t; u != s; u = edges[p[u]].u) f = min(f, edges[p[u]].f);         flow += f;         cost += f * h[t];         for (int u = t; u != s; u = edges[p[u]].u) {           edges[p[u]].f -= f;           edges[p[u] ^ 1].f += f;         }       }       return cost;     }   };   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int n;     cin >> n;     for (int i = 0; i < 2 * n; i += 1) cin >> a[i] >> b[i];     LL L = 0, R = 1000000000 + 1;     vector<int> u;     for (int i = 0; i < 2 * n; i += 1) u.push_back(i);     sort(u.begin(), u.end(), [&](const int& x, const int& y) {       if (b[x] != b[y]) return b[x] < b[y];       return a[x] > a[y];     });     while (L < R) {       LL M = (L + R) >> 1;       vector<LL> v, w;       LL m = 0;       for (int i : u) {         m = max(m, a[i] * M + b[i]);         if (i < n)           v.push_back(m);         else           w.push_back(a[i] * M + b[i]);       }       int ok = 1;       sort(w.begin(), w.end());       for (int i = 0; i < n; i += 1) ok &= v[i] >= w[i];       if (ok)         R = M;       else         L = M + 1;     }     if (L == 1000000000 + 1) {       cout <<  -1 ;       return 0;     }     cout << L <<    ;     int s = 0, t = 8 * n + 1;     SSPA SSPA(t + 1, s, t);     for (int i = 0; i < n; i += 1) SSPA.add(s, i + 1, 1, 0);     for (int i = n; i < 2 * n; i += 1) SSPA.add(4 * n + i + 1, t, 1, 0);     for (int i = 0; i < 2 * n; i += 1) {       SSPA.add(2 * n + i + 1, i + 1, inf, 0);       SSPA.add(i + 1, 2 * n + i + 1, inf, 1);       SSPA.add(6 * n + i + 1, 4 * n + i + 1, inf, 0);       SSPA.add(4 * n + i + 1, 6 * n + i + 1, inf, 1);       SSPA.add(i + 1, 4 * n + i + 1, inf, 0);     }     for (int i = 1; i < 2 * n; i += 1) {       SSPA.add(2 * n + u[i] + 1, 2 * n + u[i - 1] + 1, inf, 0);       if (b[u[i]] == b[u[i - 1]])         SSPA.add(2 * n + u[i - 1] + 1, 2 * n + u[i] + 1, inf, 0);     }     sort(u.begin(), u.end(), [&](const int& x, const int& y) {       return a[x] * L + b[x] < a[y] * L + b[y];     });     for (int i = 1; i < 2 * n; i += 1) {       SSPA.add(6 * n + u[i] + 1, 6 * n + u[i - 1] + 1, inf, 0);       if (a[u[i]] * L + b[u[i]] == a[u[i - 1]] * L + b[u[i - 1]])         SSPA.add(6 * n + u[i - 1] + 1, 6 * n + u[i] + 1, inf, 0);     }     cout << SSPA.min_cost_flow();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 100005;   const int MOD = 1000000007;   unordered_map<int, bool> sp;   vector<int> g[MAX];   struct node {     int u, v;     int cost;     node(int _u, int _v, int _cost) {       u = _u;       v = _v;       cost = _cost;     }   };   bool mst_sort(node &a, node &b) { return a.cost < b.cost; }   bool ans_sort(node &a, node &b) { return a.cost > b.cost; }   vector<node> e;   int par[MAX];   int findpar(int r) {     if (par[r] == r) return r;     par[r] = findpar(par[r]);     return par[r];   }   vector<node> tree;   void mst(int n) {     for (int i = 0; i < n; i++) par[i] = i;     sort(e.begin(), e.end(), mst_sort);     int c = 0;     for (int i = 0; i < e.size(); i++) {       int u = findpar(e[i].u);       int v = findpar(e[i].v);       if (u != v) {         par[u] = v;         tree.push_back(e[i]);         g[e[i].u].push_back(e[i].v);         g[e[i].v].push_back(e[i].u);         c++;         if (c == n - 1) break;       }     }     return;   }   int can[MAX];   map<pair<int, int>, bool> vis;   bool dfs(int n, int par) {     if (sp[n]) return can[n] = true;     if (vis[pair<int, int>(n, par)]) return can[n] = false;     if (can[n] != -1) return can[n];     bool ret = false;     for (int i : g[n]) {       if (i != par) ret |= dfs(i, n);       if (ret) return can[n] = ret;     }     return can[n] = ret;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     ;     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < k; i++) {       int temp;       cin >> temp;       sp[temp] = true;     }     while (m--) {       int u, v, cost;       cin >> u >> v >> cost;       e.push_back(node(u, v, cost));     }     mst(n);     sort(tree.begin(), tree.end(), ans_sort);     int ans = 0;     memset(can, -1, sizeof can);     for (int i = 0; i < tree.size(); i++) {       node p = tree[i];       if (sp[p.u] && sp[p.v]) {         ans = p.cost;         break;       }       if (sp[p.u]) {         can[p.v] = -1;         if (dfs(p.v, p.u)) {           ans = p.cost;           break;         }       } else if (sp[p.v]) {         can[p.u] = -1;         if (dfs(p.u, p.v)) {           ans = p.cost;           break;         }       } else {         can[p.u] = can[p.v] = -1;         if (dfs(p.u, p.v) && dfs(p.v, p.u)) {           ans = p.cost;           break;         }       }       vis[pair<int, int>(p.u, p.v)] = true;     }     for (int i = 0; i < k; i++) cout << ans <<    ;     cout <<   n ;   }


#include <bits/stdc++.h>   const long long M = 1000005;   const long long mod = 1e9 + 7;   using namespace std;   long long n, m, a, b, fac[M], Ans;   inline long long Fpw(long long Base, long long k) {     long long temp = 1;     while (k) {       if (k & 1) temp = (1LL * temp * Base) % mod;       Base = (1LL * Base * Base) % mod;       k >>= 1;     }     return temp;   }   inline long long Inv(long long a) { return Fpw(a, mod - 2); }   inline long long C(long long n, long long m) {     if (n < 0 || m < 0 || n < m) return 0;     return fac[n] * Inv(fac[m]) % mod * Inv(fac[n - m]) % mod;   }   int main() {     scanf( %lld%lld , &n, &m);     fac[0] = 1;     for (long long i = 1; i <= 1000000; i++)       fac[i] = (1LL * fac[i - 1] * i) % mod;     for (long long i = 2; i <= n; i++) {       long long temp = C(n - 2, i - 2) * fac[i - 2] % mod;       temp = temp * C(m - 1, i - 2) % mod;       if (n - i - 1 >= 0) temp = temp * i % mod * Fpw(n, n - i - 1) % mod;       temp = temp * Fpw(m, n - i) % mod;       Ans = (Ans + temp) % mod;     }     printf( %lld n , Ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100 + 10;   int n, m, k;   string l[maxn];   int t[maxn], T;   int w[5][3];   vector<pair<int, int> > v;   pair<pair<int, int>, pair<int, int> > a[maxn];   int vis[24 * 30 * 60 + 10];   int cor[24 * 30 * 60 + 10];   int dp[maxn][24 * 30 * 60 + 10];   int par[maxn][24 * 30 * 60 + 10];   inline bool cmp(pair<pair<int, int>, pair<int, int> > fi,                   pair<pair<int, int>, pair<int, int> > se) {     return fi.first.second < se.first.second;   }   inline int solve(int work, int time) {     time++;     int &ret = dp[work][time];     if (ret > -1) return ret;     if (work == 0) return ret = 0;     int need = t[a[work].first.first];     if (need <= time) {       int Max = solve(work - 1, min(time - 1 - need, a[work - 1].first.second)) +                 a[work].second.first;       int Max_ = solve(work - 1, min(time - 1, a[work - 1].first.second));       if (Max > Max_) par[work][time] = 1;       return ret = max(Max, Max_);     } else       return ret = solve(work - 1, min(time - 1, a[work - 1].first.second));   }   inline void Out_(int Time) {     int t = cor[Time];     cout << t / 1440 + 1 <<    ;     int p, q;     t %= 1440;     p = t / 60;     q = t % 60;     if (p < 10)       cout <<  0  << p <<  : ;     else       cout << p <<  : ;     if (q < 10)       cout <<  0  << q;     else       cout << q;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m >> k;     for (int i = 1; i <= n; ++i) cin >> l[i];     for (int i = 1; i <= n; ++i) cin >> t[i];     for (int i = 1; i <= 4; ++i) {       int p, q;       int p_, q_;       char g, g_;       cin >> p >> g >> q >> g_ >> p_ >> g >> q_;       w[i][1] = p * 60 + q;       w[i][2] = p_ * 60 + q_;     }     for (int i = 1; i <= k; ++i)       for (int j = 1; j <= 4; ++j)         v.push_back(pair<int, int>(24 * 60 * (i - 1) + w[j][1],                                    24 * 60 * (i - 1) + w[j][2]));     for (int i = 0; i < v.size(); ++i)       for (int j = v[i].first; j <= v[i].second; ++j) vis[j] = 1;     int cp = m;     for (int i = 1, cur = 1; i <= m; ++i, cur++) {       string hlp;       cin >> hlp;       for (int j = 1; j <= n; ++j)         if (hlp == l[j]) a[i].first.first = j;       int day;       cin >> day;       int p, q;       char g;       cin >> p >> g >> q;       a[i].first.second = (day - 1) * 24 * 60 + p * 60 + q;       cin >> a[i].second.first;       a[i].second.second = cur;       if (a[i].first.first == 0) {         a[m] = a[i];         i--;         m--;       }     }     for (int i = 1; i <= m; ++i) {       int q = 0;       bool flag = false;       for (int j = 0; j < v.size(); ++j)         if (a[i].first.second >= v[j].first)           if (a[i].first.second > v[j].second)             q += v[j].second - v[j].first + 1;           else {             q += a[i].first.second - v[j].first + 1;             flag = true;           }       a[i].first.second -= q;       if (flag == false) a[i].first.second--;     }     sort(a + 1, a + 1 + m, cmp);     int cur = 0;     for (int i = 0; i < k * 24 * 60; ++i)       if (vis[i] == 0) {         cor[cur++] = i;         T++;       }     T--;     memset(dp, -1, sizeof dp);     cout << solve(m, min(a[m].first.second, T)) << endl;     vector<int> ans;     int ind, time;     time = min(a[m].first.second, T);     ind = m;     for (; ind > 0;) {       time++;       int need = t[a[ind].first.first];       int nex = par[ind][time];       if (nex == 1) {         ans.push_back(ind);         time = min(time - 1 - need, a[ind - 1].first.second);         ind--;       } else {         time = min(time - 1, a[ind - 1].first.second);         ind--;       }     }     cout << ans.size() << endl;     int Min = 0;     for (int i = ans.size() - 1; i >= 0; --i) {       cout << a[ans[i]].second.second <<    ;       Out_(Min);       cout <<    ;       Out_(Min + t[a[ans[i]].first.first] - 1);       cout << endl;       Min += t[a[ans[i]].first.first];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   enum { MAXPOS = 110500, MAXBYTE = 20, MAXN = 7070 };   int q_level[MAXN], q_left[MAXN], q_right[MAXN], q_value[MAXN];   int jump_up[MAXBYTE][MAXPOS], jump_low[MAXBYTE][MAXPOS];   int high[MAXPOS];   void init() {     for (int i = 0; (1 << i) < MAXPOS; i++) high[1 << i] = 1;     for (int i = 2; i < MAXPOS; i++) {       high[i] += high[i - 1];     }     for (int i = 1; i < MAXPOS; i++) {       jump_up[0][i] = i + high[i];       jump_low[0][i] = i + high[i] - !(i & (i - 1));     }     for (int i = 1; i < MAXBYTE; i++) {       for (int j = 1; j < MAXPOS; j++) {         if (jump_up[i - 1][j] < MAXPOS) {           jump_up[i][j] = jump_up[i - 1][jump_up[i - 1][j]];         }         if (jump_low[i - 1][j] < MAXPOS) {           jump_low[i][j] = jump_low[i - 1][jump_low[i - 1][j]];         }       }     }   }   inline int get_left(int start, int jumps) {     if (jumps == 0) return start;     for (int i = MAXBYTE - 1; i >= 0; i--) {       if (jumps >= (1 << i)) {         jumps -= (1 << i);         start = jump_low[i][start];       }     }     return start;   }   inline int get_right(int start, int jumps) {     if (jumps == 0) return start;     for (int i = MAXBYTE - 1; i >= 0; i--) {       if (jumps >= (1 << i)) {         jumps -= (1 << i);         start = jump_up[i][start];       }     }     return start;   }   int main() {     init();     int n, m;     scanf( %d %d , &n, &m);     int q_cnt = 0;     for (int i = 0; i < m; i++) {       int type;       scanf( %d , &type);       if (type == 1) {         scanf( %d %d %d %d , &q_level[q_cnt], &q_left[q_cnt], &q_right[q_cnt],               &q_value[q_cnt]);         q_cnt++;       } else {         int level, position;         scanf( %d %d , &level, &position);         set<int> subtree;         for (int j = 0; j < q_cnt; j++) {           if (q_level[j] < level) continue;           int left = get_left(position, q_level[j] - level);           int right = get_right(position, q_level[j] - level);           if (max(left, q_left[j]) <= min(right, q_right[j]))             subtree.insert(q_value[j]);         }         printf( %d n , (int)subtree.size());       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[107];   stack<int> Q[100];   int cmp(int a, int b) { return a > b; }   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     sort(a + 1, a + 1 + n, cmp);     int ans = 0;     int tmp = -1;     int flag = 1;     for (int i = 1; i <= n; i++) {       if (a[i] != k) {         flag = 0;         break;       }     }     if (flag) {       printf( 0 n );       return 0;     }     while (1) {       tmp = -1;       ans++;       for (int i = 1; i <= n; i++) {         if (a[i] == k)           continue;         else if (tmp == a[i])           continue;         else {           tmp = a[i];           a[i]++;         }       }       int flag = 1;       for (int i = 1; i <= n; i++) {         if (a[i] != k) {           flag = 0;           break;         }       }       if (flag) break;     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool gt(long double a, long double b) { return a > b + 1e-12; }   int n, m;   vector<pair<bool, pair<int, int> > > pt, org;   pair<int, int> o;   inline bool left_turn(const pair<int, int> &a, const pair<int, int> &b,                         const pair<int, int> &c) {     return 1LL * (b.first - a.first) * (c.second - b.second) -                1LL * (b.second - a.second) * (c.first - b.first) >            0;   }   inline bool cmp(pair<bool, pair<int, int> > a, pair<bool, pair<int, int> > b) {     return left_turn(o, a.second, b.second);   }   inline bool by_Y(pair<bool, pair<int, int> > a, pair<bool, pair<int, int> > b) {     return a.second.second < b.second.second;   }   int main() {     ios::sync_with_stdio(false);     int n, m;     cin >> n >> m;     org.resize(n + m);     for (register int i = (0); i < (int)(n); ++i)       cin >> org[i].second.first >> org[i].second.second, org[i].first = 0;     for (register int i = (0); i < (int)(m); ++i)       cin >> org[i + n].second.first >> org[i + n].second.second,           org[i + n].first = 1;     int tot = 0;     sort((org).begin(), (org).end(), by_Y);     for (register int rep = (0); rep < (int)(((int)(org).size())); ++rep)       if (org[rep].first == 0) {         pt.clear();         for (register int i = (0); i < (int)(((int)(org).size())); ++i)           if (org[rep].second <= org[i].second && i != rep) pt.push_back(org[i]);         o = org[rep].second;         sort((pt).begin(), (pt).end(), cmp);         for (register int oth = (0); oth < (int)(((int)(pt).size())); ++oth)           if (pt[oth].first == 0) {             pair<int, int> worst;             bool wfound = false;             for (register int i = (1); i < (int)(((int)(pt).size())); ++i) {               pair<bool, pair<int, int> > next =                   pt[(oth + i) % ((int)(pt).size())];               if (!left_turn(o, pt[oth].second, next.second)) break;               if (next.first == 1 &&                   (wfound == false ||                    left_turn(pt[oth].second, worst, next.second)))                 worst = next.second, wfound = true;               if (next.first == 0 &&                   (wfound == false ||                    left_turn(pt[oth].second, worst, next.second)))                 tot++;             }           }       }     cout << tot << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int res = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -f;       ch = getchar();     }     while (isdigit(ch)) {       res = res * 10 + ch -  0 ;       ch = getchar();     }     return res * f;   }   namespace qiqi {   const int N = 3005;   int n, m, ecnt, head[N], a[N], siz[N];   pair<long long, long long> f[N][N], g[N];   struct Edge {     int v, nxt;   } e[N << 1];   inline void add(int u, int v) {     e[++ecnt] = (Edge){v, head[u]};     head[u] = ecnt;   }   void dfs(int u, int fa) {     f[u][siz[u] = 1] = make_pair(0, a[u]);     for (int k = head[u], v = e[k].v; k; v = e[k = e[k].nxt].v)       if (v != fa) {         dfs(v, u);         for (int i = (1); i <= (siz[u] + siz[v]); ++i) g[i] = make_pair(-1, 0);         for (int i = (siz[u]); i >= (1); --i)           for (int j = (siz[v]); j >= (1); --j) {             g[i + j] = max(g[i + j], make_pair(f[u][i].first + f[v][j].first +                                                    (f[v][j].second > 0),                                                f[u][i].second));             g[i + j - 1] =                 max(g[i + j - 1], make_pair(f[u][i].first + f[v][j].first,                                             f[u][i].second + f[v][j].second));           }         siz[u] += siz[v];         for (int i = (1); i <= (siz[u]); ++i) f[u][i] = g[i];       }   }   void main() {     memset(head, ecnt = 0, sizeof(head));     n = read();     m = read();     for (int i = (1); i <= (n); ++i) a[i] = read();     for (int i = (1); i <= (n); ++i) a[i] = read() - a[i];     int u, v;     for (int i = (2); i <= (n); ++i) {       u = read();       v = read();       add(u, v);       add(v, u);     }     dfs(1, 0);     printf( %lld n , f[1][m].first + (f[1][m].second > 0));   }   }  // namespace qiqi   int main() {     int T = read();     while (T--) qiqi::main();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int sum(long long int n) {     long long int s2um = 0;     while (n > 0) {       s2um += n % 10;       n = n / 10;     }     return s2um;   }   long long int answer(long long int n) {     long long int x = 0, y = 0;     while (10 * y + 9 < n) {       y = 10 * y + 9;       x = x + 9;     }     long long int m = n - y;     x += sum(m);     return x;   }   int main() {     ios_base::sync_with_stdio(false);     std::cin.tie(NULL);     std::cout.tie(NULL);     long long int n;     cin >> n;     cout << answer(n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200100;   int n, l, r, m, a[N], b[N], c, pos, mi, ma;   pair<int, int> t[4 * N];   void build(int v, int tl, int tr) {     if (tl == tr) {       t[v].first = a[tl];       t[v].second = b[tl];       return;     }     int tm = (tl + tr) / 2;     build(2 * v, tl, tm);     build(2 * v + 1, tm + 1, tr);     t[v].first = max(t[2 * v].first, t[2 * v + 1].first);     t[v].second = min(t[2 * v].second, t[2 * v + 1].second);     return;   }   void get(int v, int tl, int tr, int l, int r) {     if (l > r) return;     if (tl == l && tr == r) {       ma = max(ma, t[v].first);       mi = min(mi, t[v].second);       return;     }     int tm = (tl + tr) / 2;     get(2 * v, tl, tm, l, min(r, tm));     get(2 * v + 1, tm + 1, tr, max(l, tm + 1), r);     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     a[n + 1] = 1e9 - 2;     for (int i = 1; i <= n; i++) cin >> b[i];     b[n + 1] = -1e9 - 2;     build(1, 1, n);     long long ans = 0;     for (int i = 1; i <= n; i++)       if (a[i] - b[i] < 1) {         l = i;         r = n + 1;         while (l < r) {           c = (l + r) / 2;           mi = 1e9 + 2;           ma = -1e9 - 2;           get(1, 1, n, i, c);           if (mi > ma)             l = c + 1;           else             r = c;         }         pos = l;         l = i;         r = n + 1;         while (l < r) {           c = (l + r) / 2;           mi = 1e9 + 2;           ma = -1e9 - 2;           get(1, 1, n, i, c);           if (mi >= ma)             l = c + 1;           else             r = c;         }         ans += max(l - pos, 0);       }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     long long int n, x, y, sum = 0;     cin >> n;     long long int a[n + 1][n + 1];     for (long long int i = 1; i <= n; i++)       for (long long int j = 1; j <= n; j++) {         cin >> a[i][j];         if (a[i][j] == 0) {           y = j;           x = i;         }       }     set<long long int> s;     if (n == 1) {       cout <<  1 ;       exit(0);     }     if (x != y) {       for (long long int i = 1; i <= n; i++) sum += a[i][i];       s.insert(sum);     }     if (x != n - y + 1) {       sum = 0;       for (long long int i = 1; i <= n; i++) sum += a[i][n - i + 1];       s.insert(sum);     }     for (long long int i = 1; i <= n; i++) {       if (i == x) continue;       sum = 0;       for (long long int j = 1; j <= n; j++) sum += a[i][j];       s.insert(sum);     }     for (long long int j = 1; j <= n; j++) {       if (j == y) continue;       sum = 0;       for (long long int i = 1; i <= n; i++) sum += a[i][j];       s.insert(sum);     }     long long int val = *(s.begin());     sum = 0;     for (long long int i = 1; i <= n; i++) sum += a[i][y];     long long int t = val - sum;     if ((long long int)s.size() > 1 || t <= 0) {       cout <<  -1 ;       exit(0);     }     a[x][y] = t;     sum = 0;     long long int sum1 = 0, sum2 = 0;     for (long long int i = 1; i <= n; i++) sum += a[x][i];     for (long long int i = 1; i <= n; i++) sum1 += a[i][i];     for (long long int i = 1; i <= n; i++) sum2 += a[i][n - i + 1];     if (sum != val || sum1 != val || sum2 != val) {       cout <<  -1 ;       exit(0);     }     cout << t;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const long long Inf = 1e18;   const int N = 2e6 + 10;   const int mod = 1e9 + 7;   int gi() {     int x = 0, o = 1;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) o = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * o;   }   template <typename T>   bool chkmax(T &a, T b) {     return a < b ? a = b, 1 : 0;   };   template <typename T>   bool chkmin(T &a, T b) {     return a > b ? a = b, 1 : 0;   };   int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }   int sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; }   void inc(int &a, int b) { a = (a + b >= mod ? a + b - mod : a + b); }   void dec(int &a, int b) { a = (a - b < 0 ? a - b + mod : a - b); }   int n, p[N], a[N], pw[N], cnt[N];   int pri[N], tot = 0, d[N];   bool vis[N];   void init() {     const int n = 2e6;     for (int i = 2; i <= n; i++) {       if (!vis[i]) pri[++tot] = i, d[i] = i;       for (int j = 1; j <= tot && i * pri[j] <= n; j++) {         vis[i * pri[j]] = 1;         d[i * pri[j]] = pri[j];         if (i % pri[j] == 0) break;       }     }   }   int qpow(int a, int b) {     int ret = 1;     while (b) {       if (b & 1) ret = 1ll * ret * a % mod;       a = 1ll * a * a % mod;       b >>= 1;     }     return ret;   }   int main() {     init();     cin >> n;     for (int i = 1; i <= n; i++) p[i] = gi();     sort(p + 1, p + n + 1);     for (int i = n; i; i--) {       if (!pw[p[i]])         pw[p[i]] = cnt[p[i]] = 1, a[i] = p[i];       else {         int x = p[i] - 1;         a[i] = p[i] - 1;         while (x > 1) {           int y = d[x], sum = 0;           while (x % y == 0) x /= y, sum++;           if (pw[y] < sum)             pw[y] = sum, cnt[y] = 1;           else if (pw[y] == sum)             cnt[y]++;         }       }     }     int tag = 0;     for (int i = n; i; i--) {       int x = a[i], fl = 1;       while (x > 1) {         int y = d[x], sum = 0;         while (x % y == 0) x /= y, sum++;         if (sum == pw[y] && cnt[y] == 1) fl = 0;       }       tag |= fl;     }     int ans = 1;     for (int i = 2; i <= 2000000; i++) ans = 1ll * ans * qpow(i, pw[i]) % mod;     printf( %d n , add(ans, tag));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXARR = 2e5 + 5, MAXVAL = 1e6 + 5, MOD = 1e9 + 7, INF = 2147483647;   const long long INFLL = (1LL << 62);   int n, d, m;   int last[MAXARR];   pair<long long, long long> stop[MAXARR];   stack<pair<long long, long long> > st;   long long ans = 0LL;   template <class T>   void maximize(T &x, T y) {     if (x < y) x = y;   }   template <class T>   void minimize(T &x, T y) {     if (x > y) x = y;   }   bool get_bit(int i, int k) { return ((k >> (i - 1)) & 1); }   int change_bit(int i, int k) { return (k ^ (1 << (i - 1))); }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> d >> n >> m;     for (int i = 1; i <= m; i++) {       cin >> stop[i].first >> stop[i].second;     }     stop[++m] = pair<long long, long long>(0, 0);     stop[++m] = pair<long long, long long>(d, 0);     sort(stop + 1, stop + m + 1);     for (int i = 1; i <= m; i++) {       last[i] = INF;     }     for (int i = 1; i <= m; i++) {       while (!st.empty() && st.top().first > stop[i].second) {         last[st.top().second] = i;         st.pop();       }       st.push(pair<long long, long long>(stop[i].second, i));     }     long long now = n;     for (int i = 2; i <= m; i++) {       now -= stop[i].first - stop[i - 1].first;       if (now < 0) {         cout <<  -1 ;         exit(0);       }       if (last[i] != INF && stop[last[i]].first - stop[i].first <= n) {         ans += 1LL * max(0LL, (stop[last[i]].first - stop[i].first - now)) *                stop[i].second;         now = max(now, stop[last[i]].first - stop[i].first);       } else if (n + stop[i].first < d) {         ans += 1LL * (n - now) * stop[i].second;         now = n;       } else {         ans += 1LL * max(0LL, d - stop[i].first - now) * stop[i].second;         now = max(now, d - stop[i].first);       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     std::ios_base::sync_with_stdio(0), cin.tie(0);     string s, t;     cin >> s >> t;     int a[26] = {};     int n = s.size(), m = t.size();     for (int i = 0; i < n; ++i) a[s[i] -  a ]++;     bool ok = 0;     if (n < m) {       s =   ;       for (int i = 0; i < n && !ok; ++i) {         if (a[t[i] -  a ]) {           a[t[i] -  a ]--;           s += t[i];           continue;         } else {           for (int j = t[i] -  a  + 1; j < 26; ++j) {             if (a[j]) {               a[j]--;               s += char( a  + j);               ok = 1;               break;             }           }           if (ok) break;           for (int j = i - 1; j >= 0 && !ok; --j) {             a[s[j] -  a ]++;             s.pop_back();             for (int k = t[j] -  a  + 1; k < 26; ++k) {               if (a[k]) {                 a[k]--;                 s += char(k +  a );                 ok = 1;                 break;               }             }           }           if (!ok) {             cout << -1;             return 0;           }         }       }       if (!ok) {         cout << -1;         return 0;       }       for (int i = 0; i < 26; ++i) {         for (int j = 0; j < a[i]; ++j) {           s += char( a  + i);         }       }       cout << s;       return 0;     }     s =   ;     for (int i = 0; i < m && !ok; ++i) {       if (a[t[i] -  a ]) {         a[t[i] -  a ]--;         s += t[i];         continue;       } else {         for (int j = t[i] -  a  + 1; j < 26; ++j) {           if (a[j]) {             a[j]--;             s += char( a  + j);             ok = 1;             break;           }         }         if (ok) break;         for (int j = i - 1; j >= 0 && !ok; --j) {           a[s[j] -  a ]++;           s.pop_back();           for (int k = t[j] -  a  + 1; k < 26; ++k) {             if (a[k]) {               a[k]--;               s += char(k +  a );               ok = 1;               break;             }           }         }         if (!ok) {           cout << -1;           return 0;         }       }     }     if (!ok) {       if (n == m) {         if (next_permutation(s.begin(), s.end()))           cout << s;         else           cout << -1;         return 0;       }     }     for (int i = 0; i < 26; ++i) {       for (int j = 0; j < a[i]; ++j) {         s += char( a  + i);       }     }     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int power(int a, int n, int m) {     if (n <= 0) return 1;     if (n % 2 == 1) {       return ((int)(((long long)power(a, n - 1, m) * a) % m));     } else {       int k = power(a, n / 2, m);       return ((int)(((long long)k * k) % m));     }   }   int main() {     long long n, m;     cin >> n >> m;     long long ans = (power(3, n, m) - 1) % m;     if (ans < 0) ans += m;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   const int N = 100005;   long long num1[N], num2[N], num3[N];   void init() {     memset(num1, 0, sizeof(num1));     memset(num2, 0, sizeof(num2));     memset(num3, 0, sizeof(num3));     for (int i = 1; i < N; ++i) {       for (int j = i; j < N; j += i) {         num1[j] += 1;       }     }     num2[0] = 0;     for (int i = 1; i < N; ++i) {       num2[i] = num2[i - 1] + i;     }     num3[0] = 0;     for (int i = 1; i < N; ++i) {       num3[i] = num3[i - 1] + num2[i];     }   }   int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }   int main() {     init();     int t;     scanf( %d , &t);     while (t--) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       int gcd_3 = gcd(x, gcd(y, z));       int gcd_xy = gcd(x, y);       int gcd_yz = gcd(y, z);       int gcd_xz = gcd(x, z);       long long g_3 = num1[gcd_3];       long long g_xy = num1[gcd_xy] - num1[gcd_3];       long long g_xz = num1[gcd_xz] - num1[gcd_3];       long long g_yz = num1[gcd_yz] - num1[gcd_3];       long long g_x = num1[x] + num1[gcd_3] - num1[gcd_xy] - num1[gcd_xz];       long long g_y = num1[y] + num1[gcd_3] - num1[gcd_xy] - num1[gcd_yz];       long long g_z = num1[z] + num1[gcd_3] - num1[gcd_xz] - num1[gcd_yz];       long long cnt = 0;       cnt += num3[g_3];       cnt += num2[g_3] * (g_xy + g_yz + g_xz + g_x + g_y + g_z);       cnt += g_3 * (g_x * g_y + g_y * g_z + g_x * g_z + num2[g_xy] + num2[g_xz] +                     num2[g_yz]);       cnt += g_3 * ((g_xy + g_yz + g_xz) * (g_x + g_y + g_z));       cnt += g_3 * (g_xy * g_xz + g_xz * g_yz + g_xy * g_yz);       cnt += num2[g_xy] * (g_z + g_xz + g_yz) + num2[g_yz] * (g_x + g_xy + g_xz) +              num2[g_xz] * (g_y + g_xy + g_yz);       cnt += (g_x + g_y + g_z) * (g_xy * g_yz + g_xz * g_yz + g_xy * g_xz);       cnt += (g_x * g_y) * (g_xz + g_yz) + (g_y * g_z) * (g_xy + g_xz) +              (g_x * g_z) * (g_xy + g_yz);       cnt += g_x * g_y * g_z;       cnt += g_xy * g_yz * g_xz;       printf( %d n , (int)cnt);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<pair<int, int>, int>> ordered;   deque<pair<int, int>> solutions;   vector<bool> stay, check;   bool cmp(pair<pair<int, int>, int> &a, pair<pair<int, int>, int> &b) {     int A = a.first.second - a.first.first;     int B = b.first.second - b.first.first;     return A < B;   }   vector<pair<pair<int, int>, int>> new_array(       vector<pair<pair<int, int>, int>> &v, int value) {     vector<pair<pair<int, int>, int>> temp;     for (int i = 0; i < v.size(); i++) {       if (stay[i])         temp.push_back(make_pair(             make_pair(v[i].first.first + value, v[i].first.second), v[i].second));     }     return temp;   }   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       int aux;       cin >> aux;       stay.push_back(false);       check.push_back(false);       if (i < k)         ordered.push_back(make_pair(make_pair(1, aux), i));       else         solutions.push_back(make_pair(aux, i));     }     sort(ordered.begin(), ordered.end(), cmp);     int d = 0, ans = 0, m = 0;     while (ordered.size() != 0) {       int mini = ordered[0].first.second - ordered[0].first.first + 1;       int index = 0, out = 0, change = 0, intern_ans = 0;       for (auto &x : ordered) {         int L = x.first.first;         int R = L + mini - 1;         int id = x.second;         if (L <= d && d <= R && check[id] == false) {           ans++;           intern_ans++;           check[id] = true;         }         int range = x.first.second - x.first.first + 1;         if (range == mini) {           stay[index++] = false;           m++;           out++;           change = true;         } else           stay[index++] = true;       }       ordered = new_array(ordered, mini);       double temp = 100.00 * ((double)m / n) + 0.5;       d = (int)temp;       while (solutions.size() != 0 && out > 0) {         ordered.push_back(             make_pair(make_pair(1, solutions[0].first), solutions[0].second));         solutions.pop_front();         out--;       }       if (change) sort(ordered.begin(), ordered.end(), cmp);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long funk(long long x, long long y) {     bool used[10000];     long long res = 1;     for (long long i = 1; i <= 100; i++) used[i] = 0;     for (long long i = x + 1; i <= y; i++) {       res *= i;       for (long long j = 2; j <= y - x; j++) {         if (!used[j] && res % j == 0) {           res /= j;           used[j] = 1;         }       }     }     return res;   }   int main() {     long long n, m, t, i, j;     cin >> n >> m >> t;     long long s = 0;     for (i = 4; i < t && i <= n; i++) {       if (t - i <= m) {         s += (funk(i, n) * funk(t - i, m));       }     }     cout << s <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int par[200009];   int flag, sum, ans, cnt, mini, maxi;   int main() {     int n;     scanf( %d , &n);     int a[n];     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     sort(a, a + n);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i == j) continue;         par[a[i] + a[j]]++;         ans = max(par[a[i] + a[j]], ans);       }     }     cout << ans / 2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 12;   const int Maxm = 105;   int n, m, k;   string s;   int a[Maxn][Maxm], b[Maxn][Maxm], c[Maxn][Maxm];   int res;   int main() {     scanf( %d %d %d , &n, &m, &k);     getline(cin, s);     for (int i = 0; i < n; i++) {       getline(cin, s);       for (int j = 0; j < m; j++) scanf( %d %d %d , &a[i][j], &b[i][j], &c[i][j]);       getline(cin, s);     }     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (i != j) {           int cand = 0;           priority_queue<int> Q;           for (int l = 0; l < m; l++)             for (int k = 0; k < c[i][l]; k++) Q.push(b[j][l] - a[i][l]);           for (int l = 0; l < k && !Q.empty() && Q.top() > 0; l++) {             cand += Q.top();             Q.pop();           }           res = max(res, cand);         }     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool comp(pair<int, pair<int, int> > a, pair<int, pair<int, int> > b) {     return a.first < b.first;   }   int main() {     int n, k;     cin >> n >> k;     vector<pair<int, pair<int, int> > > book;     for (int i = 0; i < n; i++) {       pair<int, pair<int, int> > temp;       cin >> temp.first >> temp.second.first >> temp.second.second;       book.push_back(temp);     }     stack<int> alice, bob, both;     sort(book.begin(), book.end(), comp);     for (int i = 0; i < n; i++) {       int t = book[i].first;       bool a = book[i].second.first;       bool b = book[i].second.second;       if (a && b) {         int t1 = 0, t2 = 0;         if (!alice.empty()) {           t1 = alice.top();         }         if (!bob.empty()) {           t2 = bob.top();         }         if (t1 + t2 >= t) {           both.push(t);           if (alice.size() + both.size() > k) {             alice.pop();           }           if (bob.size() + both.size() > k) {             bob.pop();           }         } else {           if (alice.size() + bob.size() + 2 * both.size() < 2 * k) {             both.push(t);           }           if (alice.size() + both.size() > k) {             alice.pop();           }           if (bob.size() + both.size() > k) {             bob.pop();           }         }       } else if (a) {         if (alice.size() + both.size() < k) {           alice.push(t);         }       } else if (b) {         if (bob.size() + both.size() < k) {           bob.push(t);         }       }     }     if (alice.size() + bob.size() + 2 * both.size() < 2 * k) {       cout << -1 << endl;     } else {       int ans = 0;       while (!alice.empty()) {         ans += alice.top();         alice.pop();       }       while (!bob.empty()) {         ans += bob.top();         bob.pop();       }       while (!both.empty()) {         ans += both.top();         both.pop();       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   void _print(int t) { cerr << t; }   void _print(string t) { cerr << t; }   void _print(char t) { cerr << t; }   void _print(long double t) { cerr << t; }   void _print(double t) { cerr << t; }   void _print(unsigned long long t) { cerr << t; }   template <class T, class V>   void _print(pair<T, V> p);   template <class T>   void _print(vector<T> v);   template <class T>   void _print(set<T> v);   template <class T, class V>   void _print(map<T, V> v);   template <class T>   void _print(multiset<T> v);   template <class T, class V>   void _print(pair<T, V> p) {     cerr <<  { ;     _print(p.first);     cerr <<  , ;     _print(p.second);     cerr <<  } ;   }   template <class T>   void _print(vector<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(set<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(multiset<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T, class V>   void _print(map<T, V> v) {     cerr <<  [  ;     for (auto i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   void init_code() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   void solve() {     string a;     string b;     cin >> a >> b;     string ans;     int n = ((int)(a).size());     int n1 = ((int)(b).size());     int j = n1 - 1;     int flag = 0;     int i = n - 1;     while (i >= 0) {       if (a[i] == b[j]) {         i--;         j--;       } else {         i -= 2;       }       if (j == -1) {         flag = 1;         break;       }     }     if (flag)       cout <<  YES ;     else       cout <<  NO ;     cout <<   n ;   }   signed main() {     init_code();     long long t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, x_num;     x_num = 0;     std::string x;     std::cin >> n;     for (int i = 0; i < n; i++) {       std::cin >> x;       if (x.substr(0, 2) ==  --  || x.substr(1, 2) ==  -- )         x_num--;       else         x_num++;     }     std::cout << x_num;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long const mod = 998244353;   long long const inf = 1e15;   long long n, m, k, x;   long long w[200004], ans[200004];   pair<long long, long long> t[800003];   void build(long long nd, long long l, long long r) {     if (l == r) {       t[nd] = {w[l], l};       return;     }     long long mid = (l + r) / 2;     build(2 * nd, l, mid);     build(2 * nd + 1, mid + 1, r);     if (t[2 * nd].first <= t[2 * nd + 1].first)       t[nd] = t[2 * nd];     else       t[nd] = t[2 * nd + 1];   }   void up(long long nd, long long l, long long r, long long a, long long b) {     if (a > r || a < l) return;     if (l == r) {       t[nd] = {b, a};       return;     }     long long mid = (l + r) / 2;     up(2 * nd, l, mid, a, b);     up(2 * nd + 1, mid + 1, r, a, b);     if (t[2 * nd].first <= t[2 * nd + 1].first)       t[nd] = t[2 * nd];     else       t[nd] = t[2 * nd + 1];   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k >> x;     long long d1 = 0, d2 = 0;     long long mn = 0, mx = n + 1;     w[0] = inf;     w[n + 1] = -inf;     long long v = -1;     for (int i = 1; i <= n; i++) {       cin >> w[i];       if (w[i] == 0) {         if (v == -1)           v = i;         else {           if (k) {             w[i] -= x;             k--;           }         }       }       if (w[i] > 0) {         d1++;         if (w[i] < w[mn]) mn = i;       } else if (w[i] < 0) {         d2++;         if (w[i] > w[mx]) mx = i;       }     }     if (v != -1 && k) {       if (d2 % 2)         w[v] = x;       else         w[v] = -x, d2++;       k--;     }     if (d2 % 2 == 0) {       long long dd1, dd2;       dd1 = dd2 = 1e9;       if (d1) dd1 = w[mn] / x + 1;       if (d2) dd2 = (abs(w[mx])) / x + 1;       if ((dd1 == dd2 && (x - w[mn] % x) >= (x - (abs(w[mx])) % x)) ||           (dd1 < dd2)) {         w[mn] -= min(dd1, k) * x;         k -= min(dd1, k);       } else {         w[mx] += min(dd2, k) * x;         k -= min(dd2, k);       }     }     for (int i = 1; i <= n; i++) ans[i] = w[i], w[i] = abs(w[i]);     build(1, 1, n);     for (int ff = 1; ff <= k; ff++) {       pair<long long, long long> d = t[1];       if (ans[d.second] > 0)         ans[d.second] += x;       else         ans[d.second] -= x;       up(1, 1, n, d.second, abs(ans[d.second]));     }     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int LimitLength = 1e5 + 10;   const int oo = 1e9 + 7;   const int Shift =  a ;   vector<vector<int> > F;   int Next[LimitLength][27];   int nS, nT;   char S[2 * LimitLength], T[LimitLength];   int KMP[2 * LimitLength];   int main() {     cin >> S + 1 >> T + 1;     nS = strlen(S + 1);     nT = strlen(T + 1);     KMP[0] = -1;     for (int iT = 1; iT <= nT; iT++) {       for (int k = KMP[iT - 1]; k != -1; k = KMP[k]) {         if (T[k + 1] == T[iT]) {           KMP[iT] = k + 1;           break;         }       }     }     memset(Next, 0xff, sizeof(Next));     for (int Char = 0; Char < 26; Char++) Next[0][Char] = 0;     for (int iT = 1; iT <= nT; iT++) {       Next[iT - 1][T[iT] - Shift] = iT;     }     for (int iT = 1; iT <= nT; iT++) {       for (int Char = 0; Char < 26; Char++) {         if (Next[iT][Char] == -1) Next[iT][Char] = Next[KMP[iT]][Char];       }     }     F.resize(nS + 2);     for (int iS = 0; iS <= nS + 1; iS++) {       F[iS].resize(nT + 2);     }     for (int iS = 0; iS <= nS; iS++) {       for (int iT = 0; iT <= nT; iT++) {         F[iS][iT] = -oo;       }     }     F[0][0] = 0;     int res = 0;     for (int iS = 0; iS < nS; iS++) {       for (int preT = 0; preT <= nT; preT++) {         if (S[iS + 1] ==  ? ) {           for (int Char = 0; Char < 26; Char++) {             if (Next[preT][Char] != -1) {               F[iS + 1][Next[preT][Char]] =                   max(F[iS + 1][Next[preT][Char]],                       F[iS][preT] + (Next[preT][Char] == nT));             }           }         } else {           int Char = S[iS + 1] - Shift;           if (Next[preT][Char] != -1) {             F[iS + 1][Next[preT][Char]] =                 max(F[iS + 1][Next[preT][Char]],                     F[iS][preT] + (Next[preT][Char] == nT));           }         }       }     }     for (int iS = 0; iS <= nS; iS++) {       for (int preT = 0; preT <= nT; preT++) {         res = max(res, F[iS][preT]);       }     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   const unsigned Upper = (1LL << 32) - 1;   unsigned a[maxn], b[maxn];   int main() {     int n, K;     int i, j;     unsigned s, a0, a1, a2, a3;     scanf( %d%d , &n, &K);     for (i = 0; i < n; ++i) {       scanf( %u.%u.%u.%u , &a0, &a1, &a2, &a3);       a[i] = (a0 << 24) + (a1 << 16) + (a2 << 8) + a3;     }     sort(a, a + n);     for (j = 31; j; --j) {       s = Upper >> j << j;       for (i = 0; i < n; ++i) b[i] = a[i] & s;       if (unique(b, b + n) - b == K) {         printf( %u.%u.%u.%u n , (s >> 24) & 255, (s >> 16) & 255, (s >> 8) & 255,                s & 255);         return 0;       }     }     puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int n, m;     cin >> n >> m;     vector<long long int> dp(n + 1);     vector<pair<pair<long long int, long long int>,                 pair<long long int, long long int>>>         input;     for (long long int i = 1; i <= m; i++) {       long long int s, d, c;       cin >> s >> d >> c;       input.push_back({{d, c}, {s, i}});       dp[d] = m + 1;     }     sort(input.begin(), input.end());     for (int i = 1; i <= n; i++) {       int flag = 0;       if (dp[i] == m + 1) continue;       for (int j = 0; j < m; j++) {         if (input[j].second.first <= i && input[j].first.second > 0 &&             input[j].first.first > i) {           dp[i] = input[j].second.second;           input[j].first.second--;           flag = 1;           break;         }       }       if (!flag) dp[i] = 0;     }     int flag = 1;     for (int i = 0; i < m; i++) {       if (input[i].first.second != 0) flag = 0;     }     if (!flag)       cout << -1;     else       for (int i = 1; i <= n; i++) cout << dp[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int x, y, mn, mx, ai;   int an[200], ax[200];   int main() {     cin >> x >> y;     for (int i = 1; i <= x; i++) {       cin >> ai;       an[i] = ax[i] = ai;     }     for (int i = 1; i <= y; i++) {       sort(an + 1, an + 1 + x);       an[1]++;     }     sort(ax + 1, ax + 1 + x);     ax[x] += y;     sort(an + 1, an + 1 + x);     mn = an[x];     mx = ax[x];     cout << mn <<     << mx;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> a(n), b;       for (int i = 0; i < n; i++) cin >> a[i];       b = a;       sort(b.begin(), b.end());       int k = 0, set1 = 0;       for (int i = 0; i < n; i++) {         if (a[i] != b[i] && k == 0) {           k++;           set1++;         } else if (a[i] == b[i] && k == 1) {           k++;         } else if (a[i] != b[i] && k == 2) {           set1++;           break;         }       }       cout << set1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   const long long mod = 1000000007;   const long long Inf = 2 * 1e9;   const long long p = 31;   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   int n, k;   vector<int> q;   vector<vector<int>> a;   vector<int> ans, used, used2;   void dfs(int x) {     if (used2[x]) return;     if (used[x]) {       cout << -1;       exit(0);     }     used[x] = true;     if (a[x].size() == 0) {       used2[x] = true;       ans.push_back(x);       return;     }     for (int(i) = 0; (i) < a[x].size(); (i)++) {       int to = a[x][i];       dfs(to);     }     ans.push_back(x);     used2[x] = true;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> k;     q.resize(k + 1);     used.resize(n + 1, 0);     used2.resize(n + 1, 0);     a.resize(n + 1);     for (int(i) = 0; (i) < k; (i)++) cin >> q[i];     for (int(i) = 1; (i) < n + 1; (i)++) {       int sz;       cin >> sz;       a[i].resize(sz);       for (int(j) = 0; (j) < sz; (j)++) cin >> a[i][j];     }     for (int(i) = 0; (i) < k; (i)++) {       dfs(q[i]);     }     cout << ans.size() << endl;     for (int(i) = 0; (i) < ans.size(); (i)++) {       cout << ans[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long base, long long pow, long long mo) {     long long res = 1;     while (pow) {       if (pow % 2 != 0) res = (res * base) % mo;       base = (base * base) % mo;       pow /= 2;     }     return res;   }   long long inv(long long i) { return power(i, 1000000007 - 2, 1000000007); }   std::string str =  All Good Till Here ;   void solve() {     long long i, j, x, n;     string str;     cin >> str;     long long up = 0, lr = 0, up1 = 0, lr1 = 0;     n = str.length();     for (long long i = 0; i < n; i++) {       if (str[i] >=  a  && str[i] <=  z )         lr++;       else         up++;     }     long long ans = INT_MAX;     for (long long i = 0; i < n; i++) {       ans = min(ans, lr1 + up - up1);       if (str[i] >=  a  && str[i] <=  z )         lr1++;       else         up1++;     }     ans = min(ans, lr1 + up - up1);     cout << ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long tt;     tt = 1;     while (tt--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   class Scanner {    private:     static const int BUFFER_SIZE = 10000;     char buff[BUFFER_SIZE];     int buffPos, buffLim;       public:     Scanner() {       buffLim = fread(buff, 1, BUFFER_SIZE, stdin);       buffPos = 0;     }       private:     inline void flushBuff() {       buffLim = fread(buff, 1, BUFFER_SIZE, stdin);       if (buffLim == 0) {         buff[buffLim++] =   n ;       }       buffPos = 0;     }     inline bool isWS(char t) { return t ==     || t ==   n ; }     inline bool isDig(char t) { return t >=  0  && t <=  9 ; }     void nextPos() {       buffPos++;       if (buffPos == buffLim) {         flushBuff();       }     }       public:     inline char getchar() {       char ch = buff[buffPos];       nextPos();       return ch;     }     inline void next(char* s) {       while (isWS(buff[buffPos])) {         nextPos();       }       while (!isWS(buff[buffPos])) {         *s = buff[buffPos];         s++;         nextPos();       }       *s =   0 ;     }     inline void nextLine(char* s) {       while (buff[buffPos] !=   n ) {         nextPos();       }       if (buff[buffPos] ==   n ) {         nextPos();       }       while (buff[buffPos] !=   n ) {         *s = buff[buffPos];         s++;         buffPos++;       }       *s =   0 ;     }     inline int nextInt() {       while (!isDig(buff[buffPos]) && buff[buffPos] !=  - ) {         nextPos();       }       int sign = (buff[buffPos] ==  - ) ? nextPos(), -1 : 1;       int res = 0;       while (isDig(buff[buffPos])) {         res = res * 10 + buff[buffPos] -  0 ;         nextPos();       }       return res * sign;     }     inline long long nextLong() {       while (!isDig(buff[buffPos]) && buff[buffPos] !=  - ) {         nextPos();       }       long long sign = (buff[buffPos] ==  - ) ? nextPos(), -1 : 1;       long long res = 0;       while (isDig(buff[buffPos])) {         res = res * 10 + buff[buffPos] -  0 ;         nextPos();       }       return res * sign;     }     inline int n() {       while (buff[buffPos] <  0  || buff[buffPos] >  9 ) {         buffPos++;         if (buffPos == buffLim) {           flushBuff();         }       }       int res = 0;       while (buff[buffPos] >=  0  && buff[buffPos] <=  9 ) {         res = res * 10 + (buff[buffPos] -  0 );         buffPos++;         if (buffPos == buffLim) {           flushBuff();         }       }       return res;     }     inline long long nl() {       while (buff[buffPos] <  0  || buff[buffPos] >  9 ) {         buffPos++;         if (buffPos == buffLim) {           flushBuff();         }       }       long long res = 0;       while (buff[buffPos] >=  0  && buff[buffPos] <=  9 ) {         res = res * 10 + (buff[buffPos] -  0 );         buffPos++;         if (buffPos == buffLim) {           flushBuff();         }       }       return res;     }     inline long long nlm(const int MOD) {       while (buff[buffPos] <  0  || buff[buffPos] >  9 ) {         buffPos++;         if (buffPos == buffLim) {           flushBuff();         }       }       long long res = 0;       while (buff[buffPos] >=  0  && buff[buffPos] <=  9 ) {         res = (res * 10 + (buff[buffPos] -  0 )) % MOD;         buffPos++;         if (buffPos == buffLim) {           flushBuff();         }       }       return res;     }     inline double nextDouble() {       while (isWS(buff[buffPos])) {         nextPos();       }       int sign = (buff[buffPos] ==  - ) ? nextPos(), -1 : 1;       double res = 0;       while (isDig(buff[buffPos])) {         res = res * 10 + buff[buffPos] -  0 ;         nextPos();       }       if (buff[buffPos] ==  . ) {         nextPos();         double ep = 1;         while (isDig(buff[buffPos])) {           ep *= 0.1;           res += ep * (buff[buffPos] -  0 );           nextPos();         }       }       return sign * res;     }     inline char nextChar() {       while (isWS(buff[buffPos])) nextPos();       char res = buff[buffPos];       nextPos();       return res;     }   };   Scanner sc;   template <class _Type>   void logArray(_Type a[], int n) {     for (int i = 0; i < n; ++i) std::cout << a[i] <<    ;     std::cout << std::endl;   }   template <class T>   inline bool checkMin(T& a, T b) {     return (a > b ? a = b, 1 : 0);   }   template <class T>   inline bool checkMax(T& a, T b) {     return (a < b ? a = b, 1 : 0);   }   void preInit();   void init();   void solve();   int32_t main() {     preInit();     init();     solve();     return 0;   }   const int N = 300005;   std::vector<int> e[N];   int col[N], n;   int dp[N], sz[N];   void dfs(int u) {     dp[u] = 1;     sz[u] = (e[u].size() == 0);     for (int v : e[u]) {       dfs(v);       sz[u] += sz[v];     }     if (col[u] == 0) {       for (int v : e[u]) dp[u] += dp[v] - 1;     } else {       for (int v : e[u]) checkMax(dp[u], sz[u] - sz[v] + dp[v]);     }   }   void preInit() {}   void init() {     n = sc.n();     for (int i = 1; i <= n; i++) col[i] = sc.n();     for (int i = 2; i <= n; i++) {       e[sc.n()].push_back(i);     }   }   void solve() {     dfs(1);     printf( %d n , dp[1]);   }


#include <bits/stdc++.h>   using namespace std;   vector<int> d;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, u;     cin >> n >> u;     d.resize(n);     for (int i = 0; i < n; i++) {       cin >> d[i];     }     double ans = -1.0;     for (int k = 2; k < n; k++) {       int i = lower_bound(d.begin(), d.end(), d[k] - u) - d.begin();       int j = i + 1;       if (i == j || j == k || k == i) continue;       double res = double(d[k] - d[j]) / double(d[k] - d[i]);       ans = max(ans, res);     }     for (int i = 0; i < n - 2; i++) {       int j = i + 1;       int k = upper_bound(d.begin(), d.end(), u + d[i]) - d.begin();       k--;       if (i == j || j == k || k == i) continue;       double res = double(d[k] - d[j]) / double(d[k] - d[i]);       ans = max(ans, res);     }     cout.precision(15);     cout.fixed;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, x, p, q, ans = 0, cnt = 0;     ;     cin >> n >> k >> x;     int a[n + 5];     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     if (n == 1) {       cout << x << endl;       return 0;     }     for (int i = n; i > 1; i--) {       if (a[i] >= a[i - 1] && cnt < k) {         cnt++;         ans += x;       } else         ans += a[i];     }     if (cnt < k && a[1] <= a[2])       ans += x;     else       ans += a[1];     cout << ans << endl;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:667772160 )   using namespace std;   struct __isoff {     __isoff() {       if (0) freopen( input.txt ,  r , stdin), freopen( output.txt ,  w , stdout);       srand(time(0));     }     ~__isoff() {}   } __osafwf;   const unsigned long long p1 = 31;   const unsigned long long p2 = 29;   const double eps = 1e-8;   const double pi = acos(-1.0);   const long long inf = 1e18 + 7;   const int infi = 1e9 + 7;   const long long dd = 1e6 + 70;   const long long mod = 1e9 + 7;   int n, k;   vector<int> P[dd];   vector<int> T(1);   vector<pair<int, int> > Z;   bool Bs[dd];   int get(int l, int r, int x) {     return upper_bound(P[x].begin(), P[x].end(), r) -            lower_bound(P[x].begin(), P[x].end(), l);   }   set<int> Q, W;   int main() {     cin >> n >> k;     long long s = 0;     P[0].push_back(0);     for (long long i = 0; i < (long long)n; i++) {       int t;       scanf( %d , &t);       Z.push_back(make_pair(-t, i));       s = (s + t) % k;       T.push_back(s);       P[s].push_back(i + 1);     }     sort(Z.begin(), Z.end());     Bs[0] = Bs[n] = 1;     long long res = 0;     Q.insert(-1);     Q.insert(n);     W.insert(1);     W.insert(-n);     for (long long i = 0; i < (long long)n; i++) {       int t = Z[i].second;       int r = *Q.lower_bound(t);       int l = -(*W.lower_bound(-t));       if (t - l < r - t) {         for (int j = l + 1; j <= t; j++) {           int z = max(j + 2, t + 1);           int ts = (T[j] - Z[i].first) % k;           int tt = get(z, r, ts);           res += tt;         }       } else {         for (int j = t + 1; j <= r; j++) {           int z = min(j - 2, t);           int ts = ((T[j] + Z[i].first) % k + k) % k;           int tt = get(l + 1, z, ts);           res += tt;         }       }       Q.insert(t);       W.insert(-t);     }     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int main() {     int h;     cin >> h;     int n = (1 << h) - 1;     vector<pair<int, int>> c(n + 1);     for (int i = 0; i <= n; i++) c[i] = {0, i};     for (int i = 0; i < 420; i++) {       int u = rng() % n + 1, v = rng() % n + 1, w = rng() % n + 1;       while (u == v) v = rng() % n + 1;       while (w == u || w == v) w = rng() % n + 1;       cout <<  ?   << u <<     << v <<     << w <<   n ;       int x;       cin >> x;       c[x].first++;     }     sort(c.rbegin(), c.rend());     for (int i = 1; i <= n; i++) {       if (i == c[0].second || i == c[1].second) continue;       cout <<  ?   << c[0].second <<     << c[1].second <<     << i <<   n ;       int x;       cin >> x;       if (x == i) {         cout <<  !   << i <<   n ;         return 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int N, T, L, R, X, H;   unordered_map<int, int> siz;   unordered_map<int, pair<int, int> > par;   pair<int, int> find(int now) {     if (par.count(now)) {       pair<int, int> a, b;       a = par[now];       b = find(a.first);       return {b.first, a.second ^ b.second};     }     return {now, 0};   }   int getsize(int now) {     if (!siz.count(now)) {       siz[now] = 1;     }     return siz[now];   }   void merge(int x, int y, int z) {     pair<int, int> a, b;     a = find(x);     b = find(y);     if (a.first == b.first) {       return;     }     if (getsize(a.first) > getsize(b.first)) {       par[b.first] = {a.first, z ^ a.second ^ b.second};       siz[a.first] += siz[b.first];     } else {       par[a.first] = {b.first, z ^ a.second ^ b.second};       siz[b.first] += siz[a.first];     }     return;   }   int ans(int x, int y) {     pair<int, int> a, b;     a = find(x);     b = find(y);     if (a.first != b.first) {       return -1;     }     return a.second ^ b.second;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> N;     for (int i = 0; i < N; i++) {       cin >> T >> L >> R;       L ^= H;       R ^= H;       if (L > R) {         swap(L, R);       }       if (T == 1) {         cin >> X;         X ^= H;         merge(L - 1, R, X);       } else {         H = ans(L - 1, R);         cout << H <<   n ;         if (H == -1) {           H = 1;         }       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(3)   using namespace std;   template <typename T>   void chkmax(T &x, T y) {     if (x < y) x = y;   }   template <typename T>   void chkmin(T &x, T y) {     if (x > y) x = y;   }   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;   }   const int maxn = 1e5 + 10, P = 998244353;   int Inc(int x, int y) { return x + y < P ? x + y : x + y - P; }   int Dec(int x, int y) { return x < y ? x - y + P : x - y; }   void Add(int &x, int y) {     x += y;     if (x >= P) x -= P;   }   void Sub(int &x, int y) {     x -= y;     if (x < 0) x += P;   }   int n, k, A[maxn], lev[maxn], dp[maxn], vp[maxn], lst[maxn];   int bsz, bl[maxn];   int ns, tag[505];   int buf_top, buf_st[maxn * 100], nxt[maxn * 100], key[maxn * 100],       val[maxn * 100];   struct hashmap {     int ct, h[1009];     int find(int x) {       for (int i = h[(x + 114514) % 1009]; i; i = nxt[i])         if (key[i] == x) return i;       return -1;     }     int query(int x) {       int tp = find(x);       return tp == -1 ? 0 : val[tp];     }     void add(int x, int v) {       int tp = find(x);       if (tp != -1) {         Add(val[tp], v);       } else {         int &p = h[(x + 114514) % 1009];         tp = buf_st[buf_top--], nxt[tp] = p, p = tp, key[tp] = x, val[tp] = v,         ct++;       }     }     void clear() {       for (int x = (0), xend = (1008); x <= xend; ++x) {         int &i = h[x];         while (i) {           key[i] = val[i] = 0, buf_st[++buf_top] = i;           int &tp = nxt[i];           i = tp, tp = 0;         }       }     }   } ump[505];   void pushdown(int ps) {     int l = (ps - 1) * bsz + 1, r = min(n, ps * bsz);     ump[ps].clear();     for (int i = (l), iend = (r); i <= iend; ++i) {       ump[ps].add(lev[i] += tag[ps], dp[i - 1]);     }     tag[ps] = 0;   }   void upd(int l, int r, int x) {     int ps = bl[l], &tp = tag[ps];     if (ump[ps].ct > 1000) pushdown(ps);     for (int i = (l), iend = (r); i <= iend; ++i) {       if (lev[i] + tp == -1 && x == 1) Add(ns, dp[i - 1]);       if (lev[i] + tp == 0 && x == -1) Sub(ns, dp[i - 1]);       if (dp[i - 1]) ump[ps].add(lev[i], P - dp[i - 1]);       ump[ps].add(lev[i] += x, dp[i - 1]);     }   }   void add(int l, int r, int x) {     if (bl[l] == bl[r]) {       upd(l, r, x);       return;     }     upd(l, bl[l] * bsz, x);     upd((bl[r] - 1) * bsz + 1, r, x);     for (int ps = (bl[l] + 1), psend = (bl[r] - 1); ps <= psend; ++ps) {       if (x == 1) {         Add(ns, ump[ps].query(-1 - tag[ps]));       } else {         Sub(ns, ump[ps].query(-tag[ps]));       }       tag[ps] += x;     }   }   void ins(int x, int v) {     pushdown(bl[x]);     if (lev[x] >= 0) Add(ns, v);   }   void solve() {     buf_top = maxn * 100 - 1;     for (int i = (1), iend = (maxn * 100 - 1); i <= iend; ++i) buf_st[i] = i;     cin >> n >> k;     bsz = 200;     for (int i = (1), iend = (n); i <= iend; ++i)       lev[i] = k, A[i] = read(), bl[i] = (i - 1) / bsz + 1;     dp[0] = 1;     for (int i = (1), iend = (n); i <= iend; ++i) {       int &p = lst[i];       p = vp[A[i]], vp[A[i]] = i;       if (p) add(lst[p] + 1, p, 1);       add(p + 1, i, -1), ins(i, dp[i - 1]), dp[i] = ns;     }     cout << dp[n] << endl;   }   signed main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long tree[4000005];   long long level[4000005];   long long num[1000005];   long long build(long long at, long long L, long long R) {     if (L == R) {       tree[at] = num[L];       level[at] = 1;       return num[L];     }     long long mid = (L + R) / 2, a, b, p;     a = build(at * 2, L, mid);     b = build(at * 2 + 1, mid + 1, R);     level[at] = p = level[at * 2] + 1;     if (p % 2)       tree[at] = a ^ b;     else       tree[at] = a | b;     return tree[at];   }   long long update(long long at, long long L, long long R, long long i,                    long long x) {     if (L == R) {       tree[at] = x;       return tree[at];     }     long long mid = (L + R) / 2, a, b;     if (L <= i && mid >= i)       a = update(at * 2, L, mid, i, x), b = tree[at * 2 + 1];     else       a = update(at * 2 + 1, mid + 1, R, i, x), b = tree[at * 2];     if (level[at] % 2)       tree[at] = a ^ b;     else       tree[at] = a | b;     return tree[at];   }   int main() {     long long n, m;     long long a, i, j;     long long x, y;     cin >> n >> m;     n = pow(2, n);     for (a = 1; a <= n; a++) cin >> num[a];     build(1, 1, n);     for (a = 0; a < m; a++) {       cin >> x >> y;       update(1, 1, n, x, y);       cout << tree[1] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 4 * 1e5 + 5;   vector<int> g[N];   int n, dp[N], res[N];   int dfs(int i, int p = -1) {     dp[i] = 1;     for (auto j : g[i]) {       if (j != p) {         dp[i] += dfs(j, i);       }     }     return dp[i];   }   int dfs2(int i, int p = -1) {     for (auto j : g[i]) {       if (j != p && dp[j] * 2 > n) {         return dfs2(j, i);       }     }     return i;   }   void dfs3(int i, int p, int c1, int c2) {     if (c1 * 2 >= n) res[i] = 1;     if ((dp[i] + c2) * 2 >= n) res[i] = 1;     for (auto j : g[i]) {       if (j != p) {         dfs3(j, i, c1, c2);       }     }   }   int main() {     std::ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i < n; ++i) {       int a, b;       cin >> a >> b;       --a;       --b;       g[a].push_back(b);       g[b].push_back(a);     }     dfs(0);     int a = dfs2(0);     dfs(a);     res[a] = 1;     int mx = -1, mx2 = -1, v;     for (auto j : g[a]) {       if (dp[j] > mx) {         mx2 = mx;         mx = dp[j];         v = j;       } else if (dp[j] > mx2) {         mx2 = dp[j];       }     }     for (auto j : g[a]) {       if (j == v)         dfs3(j, a, dp[j], mx2);       else         dfs3(j, a, dp[j], mx);     }     for (int i = 0; i < n; ++i) cout << res[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, persons, valids;   int main() {     scanf( %d %d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , &persons);       if (persons + k <= 5) {         valids++;       }     }     printf( %d , valids / 3);     return 0;   }


#include <bits/stdc++.h>   const int M = 5500;   const double esp = 1e-6;   const double PI = 3.14159265359;   const int INF = 0x3f3f3f3f;   using namespace std;   struct node {     double x, y, z;   } arr[M];   double judge(node x, node y) {     return sqrt((x.x - y.x) * (x.x - y.x) + (x.y - y.y) * (x.y - y.y) +                 (x.z - y.z) * (x.z - y.z));   }   int main() {     int n;     while (~scanf( %d , &n)) {       for (int i = 1; i <= n; i++) {         scanf( %lf %lf %lf , &arr[i].x, &arr[i].y, &arr[i].z);       }       double qmin = (double)INF;       for (int i = 2; i <= n; i++) {         for (int j = i + 1; j <= n; j++) {           qmin = min(qmin, judge(arr[1], arr[i]) + judge(arr[1], arr[j]) +                                judge(arr[i], arr[j]));         }       }       printf( %lf n , qmin / 2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int INF = 1e9 + 7;   const int N = 1010;   const double pi = 3.1415926;   int main() {     char str[100010];     while (~scanf( %s , str)) {       int len = strlen(str);       int idx = INF, sum0 = 0, sum1 = 0;       for (int i = 0; i < len; i++) {         if (str[i] ==  2 ) {           idx = i;           break;         }         if (str[i] ==  1 ) sum1++;         if (str[i] ==  0 ) sum0++;       }       for (int i = 0; i < sum0; i++) printf( 0 );       for (int i = 0; i < sum1; i++) printf( 1 );       sum1 = 0;       for (int i = idx; i < len; i++) {         if (str[i] ==  1 ) sum1++;       }       for (int i = 0; i < sum1; i++) printf( 1 );       for (int i = idx; i < len; i++) {         if (str[i] !=  1 ) printf( %c , str[i]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<int> st;   int main() {     int t, i, j, k, n, m;     scanf( %d , &n);     for (i = 0; i < n; i++) {       int x;       scanf( %d , &x);       st.insert(x);     }     int a, b;     scanf( %d , &a);     scanf( %d , &b);     set<int>::iterator it, cit;     int ans = 0;     while (1) {       if (a == b) {         cout << ans << endl;         return 0;       }       int mx = 1;       for (it = st.begin(); it != st.end();) {         int val = *it;         cit = it;         it++;         if (a - (a % val) < b) {           st.erase(cit);         } else {           mx = max(mx, a % val);         }       }       ans++;       a = a - mx;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     int p;     scanf( %I64d %I64d %d , &n, &k, &p);     long long ndiv2 = n / 2;     long long ndiv2minus1 = n / 2 - 1;     long long nminusk = n - k;     for (int i = 0; i < p; i++) {       long long x;       scanf( %I64d , &x);       printf( %c , (((x == n) ? (n)                               : (1 + (x / 2) * ndiv2 -                                  ((x - 1) / 2) * ndiv2minus1)) <= nminusk)                        ? ( . )                        : ( X ));     }   exit:     return (0);   }


#include <bits/stdc++.h>   char str1[200], str2[200];   char lenstr1, lenstr2;   int dp1[200];   int dp2[200];   int got[200] = {0};   int twice;   int twicep;   int countc;   int calel(int st) {     int ite = st;     int len = 1;     for (int i = 0; i < lenstr2; i++) {       int flag = 0;       while (str1[st] != str2[i]) {         st++;         if (st == lenstr1) {           len++;           st = 0;           if (flag) return 1;           flag = 1;         }       }       st++;       if (st == lenstr1) {         len++;         st = 0;       }     }     dp1[ite] = len;     dp2[ite] = st;     return 0;   }   int main() {     int s1, s2;     scanf( %d%d , &s1, &s2);     scanf( %s%s , str1, str2);     lenstr1 = strlen(str1);     lenstr2 = strlen(str2);     for (int i = 0; i < lenstr1; i++)       if (calel(i)) {         printf( 0 n );         return 0;       }     got[0] = 1;     for (int i = 0;;) {       int j = dp2[i];       if (got[j]) {         twice = got[i] + dp1[i] - 1;         twicep = j;         break;       }       got[j] = got[i] + dp1[i] - 1;       i = j;     }     if (twice >= s1) {       countc = 0;       int i, j;       for (i = 0, j = 1; j <= s1;) {         j += dp1[i] - 1;         i = dp2[i];         countc++;       }       if (i == 0 && countc != 1) countc++;     } else {       countc = 0;       int p1 = 1;       for (int i = 0; i != twicep;) {         p1 += dp1[i] - 1;         i = dp2[i];         countc++;       }       int left = s1 - p1;       int i = twicep;       int single = 0;       do {         i = dp2[i];         single++;       } while (i != twicep);       int sinlen = twice - p1;       countc += single * (left / sinlen);       int p2 = p1 + left / sinlen * sinlen;       for (i = twicep;;) {         p2 += dp1[i] - 1;         i = dp2[i];         if (p2 > s1) break;         countc++;       }       if (i == 0) countc++;     }     printf( %d n , countc / s2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[400 + 2], ans = 1 << 30;   int main() {     cin >> n;     for (register int i = 1; i <= n; i++) cin >> a[i];     for (int i = n; i >= 2; i--) {       if (a[i] >= ans) break;       for (int j = i; j <= n; j++) {         register int num = a[i - 1] - 1, x = 1, t;         for (register int k = i; k <= j; k++)           if (num >= a[k]) {             t = num / a[k];             x += t, num -= t * a[k];           }         num = a[i - 1] - 1 - num + a[j];         int res = num;         if (res < ans) {           for (register int k = 1; k <= n; k++)             if (num >= a[k]) {               t = num / a[k];               x -= t, num -= t * a[k];               if (x < 0) break;             }           if (x < 0) ans = res;         }       }     }     if (ans == 1 << 30) ans = -1;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[101][4];   int main() {     int n;     cin >> n;     int min = 0, ind = 0;     for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3];     min = 100000;     ind = 0;     for (int i = 0; i < n; i++) {       bool ust = false;       for (int j = 0; j < n; j++)         if (i != j)           if (a[i][0] < a[j][0] && a[i][1] < a[j][1] && a[i][2] < a[j][2]) {             ust = true;             break;           }       if (!ust)         if (a[i][3] < min) {           min = a[i][3];           ind = i;         }     }     cout << ind + 1 << endl;     return 0;   }


#include <stdio.h>   #include <string.h>   #include <math.h>   #include <limits.h>   #include <time.h>   #include <vector>   #include <queue>   #include <stack>   #include <map>   #include <set>   #include <algorithm>   #pragma warning(disable:4996)   #pragma warning(disable:6031)   #define MAX(X,Y) (X>Y?X:Y)   #define MIN(X,Y) (X<Y?X:Y)   #define ll long long   #define pii pair<int,int>   using namespace std;      int t,n;   char str[201];      int main() {    scanf( %d , &t);    while (t--) {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf(  %c , &str[i]);     bool ans = false;     if (str[0] ==  2 ) {      if (str[1] ==  0 ) {       if (str[2] ==  2 ) {        if (str[3] ==  0 ) ans = true;        else if (str[n - 1] ==  0 ) ans = true;       }       else if (str[n - 1] ==  0  && str[n - 2] ==  2 ) ans = true;      }      else if (str[n - 1] ==  0  && str[n - 2] ==  2  && str[n - 3] ==  0 ) ans = true;     }     else if (str[n - 1] ==  0  && str[n - 2] ==  2  && str[n - 3] ==  0  && str[n - 4] ==  2 ) ans = true;     printf( %s n , (ans ?  YES  :  NO ));    }   }


#include <bits/stdc++.h>   using namespace std;   namespace IO {   long long len = 0;   char ibuf[(1 << 20) + 1], *iS, *iT, out[(1 << 25) + 1];   inline long long read() {     char ch = (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, (1 << 20) + 1, stdin),                (iS == iT ? EOF : *iS++) : *iS++);     long long x = 0;     char t = 0;     while (ch <  0  || ch >  9 )       t |= ch ==  - , ch = (iS == iT ? iT = (iS = ibuf) +                                             fread(ibuf, 1, (1 << 20) + 1, stdin),                             (iS == iT ? EOF : *iS++) : *iS++);     while (ch >=  0  && ch <=  9 )       x = x * 10 + (ch ^ 48),       ch = (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, (1 << 20) + 1, stdin),             (iS == iT ? EOF : *iS++) : *iS++);     return t ? -x : x;   }   inline void putc(char ch) { out[len++] = ch; }   template <class T>   inline void write(T x) {     if (x < 0) putc( - ), x = -x;     if (x > 9) write(x / 10);     out[len++] = x % 10 + 48;   }   string getstr(void) {     string s =   ;     char c = (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, (1 << 20) + 1, stdin),               (iS == iT ? EOF : *iS++) : *iS++);     while (c ==     || c ==   n  || c ==   r  || c ==   t  || c == EOF)       c = (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, (1 << 20) + 1, stdin),            (iS == iT ? EOF : *iS++) : *iS++);     while (!(c ==     || c ==   n  || c ==   r  || c ==   t  || c == EOF))       s.push_back(c),           c = (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, (1 << 20) + 1, stdin),                (iS == iT ? EOF : *iS++) : *iS++);     return s;   }   void putstr(string str, long long begin = 0, long long end = -1) {     if (end == -1) end = str.size();     for (long long i = begin; i < end; i++) putc(str[i]);     return;   }   inline void flush() {     fwrite(out, 1, len, stdout);     len = 0;   }   }  // namespace IO   using IO::flush;   using IO::getstr;   using IO::putc;   using IO::putstr;   using IO::read;   using IO::write;   const long long N = 3000;   long long n, m, q, ans, cnt, a[N][N], dp1[N][N], dp2[N][N];   void solve() {     n = read(), m = read(), q = read();     for (long long i = 1; i <= n; i++)       for (long long j = 1; j <= m; j++) dp1[i][j] = dp2[i][j] = 1;     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= m; j++) {         if (i > 1) dp1[i][j] = 1 + dp2[i - 1][j];         if (j > 1) dp2[i][j] = 1 + dp1[i][j - 1];         a[i][j] = 1;       }     }     long long ans = 0, tot = n * m;     for (long long i = 1; i <= n; i++)       for (long long j = 1; j <= m; j++) ans += dp1[i][j] + dp2[i][j];     while (q--) {       long long i, j;       i = read(), j = read();       a[i][j] ^= 1;       if (a[i][j] == 0) {         tot--;         ans -= (dp1[i][j] + dp2[i][j]);         dp1[i][j] = dp2[i][j] = 0;         ans += (dp1[i][j] + dp2[i][j]);       } else {         tot++;         ans -= dp1[i][j] + dp2[i][j];         if (i > 1)           dp1[i][j] = 1 + dp2[i - 1][j];         else           dp1[i][j] = 1;         if (j > 1)           dp2[i][j] = 1 + dp1[i][j - 1];         else           dp2[i][j] = 1;         ans += dp1[i][j] + dp2[i][j];       }       while (i <= n && j <= m) {         if (i < n) {           ans -= dp1[i + 1][j];           dp1[i + 1][j] = a[i + 1][j] * (1 + dp2[i][j]);           ans += dp1[i + 1][j];         }         if (j < m) {           ans -= dp2[i][j + 1];           dp2[i][j + 1] = a[i][j + 1] * (1 + dp1[i][j]);           ans += dp2[i][j + 1];         }         if (i < n && j < m) {           ans -= dp1[i + 1][j + 1] + dp2[i + 1][j + 1];           dp1[i + 1][j + 1] = a[i + 1][j + 1] * (1 + dp2[i][j + 1]);           dp2[i + 1][j + 1] = a[i + 1][j + 1] * (1 + dp1[i + 1][j]);           ans += dp1[i + 1][j + 1] + dp2[i + 1][j + 1];         }         i++, j++;       }       cout << ans - tot <<     << endl;     }   }   signed main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, y;     cin >> n >> x >> y;     n /= 2;     if ((x == n || x == n + 1) && (y == n || y == n + 1))       printf( NO );     else       printf( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, a[33][33], vis[33];   int dfs(int u, int sum, int lim) {     if (sum > lim) return 0;     if (u > n) return 1;     int ans = dfs(u + 1, sum, lim);     for (int v = 1; v <= n && ans < k; v++)       if (!vis[v] && a[u][v])         vis[v] = 1, ans += dfs(u + 1, sum + a[u][v], lim), vis[v] = 0;     return ans;   }   int main() {     cin >> n >> m >> k;     while (m--) {       int x, y, z;       cin >> x >> y >> z;       a[x][y] = z;     }     int l = 0, r = 20000, ans = 0;     while (l <= r) {       m = (l + r) / 2;       if (dfs(1, 0, m) >= k)         ans = m, r = m - 1;       else         l = m + 1;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   std::vector<long long> v[100009];   long long vis[100009], c = 0;   void dfs(long long x) {     c++;     vis[x] = 1;     for (auto i : v[x])       if (!vis[i]) dfs(i);   }   signed main() {     ios_base::sync_with_stdio(false), cin.tie(NULL);     long long i, n, m, s = 0;     cin >> n >> m;     for (i = 1; i <= m; i++) {       long long a, b;       cin >> a >> b;       v[a].push_back(b);       v[b].push_back(a);     }     for (i = 1; i <= n; i++) {       if (!vis[i]) {         c = 0;         dfs(i);         s += (c - 1);       }     }     cout << m - s;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   const int INF = 0x3f3f3f3f;   int n, h, m, k;   pair<int, int> arr[maxn];   vector<int> out;   int calc(int l, int r, int s) {     if (l <= r) {       int low = lower_bound(arr + 1, arr + 1 + n, make_pair(l, 0)) - arr;       int up = upper_bound(arr + 1, arr + 1 + n, make_pair(r, INF)) - arr;       --up;       if (s) {         for (int i = low; i <= up; i++) out.emplace_back(arr[i].second);       }       return max(0, up - low + 1);     }     swap(l, r);     int low = upper_bound(arr + 1, arr + 1 + n, make_pair(l, INF)) - arr;     --low;     if (s) {       for (int i = 1; i <= low; i++) out.emplace_back(arr[i].second);     }     int up = lower_bound(arr + 1, arr + 1 + n, make_pair(r, 0)) - arr;     if (s) {       for (int i = up; i <= n; i++) out.emplace_back(arr[i].second);     }     return low + (n - up + 1);   }   int solve(int t, int s) {     t = (t + m) % m;     int s1 = t;     int t1 = (s1 + k - 1) % m;     int s2 = (t + m / 2) % m;     int t2 = (s2 + k - 1) % m;     return calc(s1, t1, s) + calc(s2, t2, s);   }   int main() {     scanf( %d%d%d%d , &n, &h, &m, &k);     --k;     for (int i = 1; i <= n; i++) {       int h;       scanf( %d%d , &h, &arr[i].first);       arr[i].second = i;     }     if (k == 0) {       printf( 0 0 n );       return 0;     }     sort(arr + 1, arr + 1 + n);     int ans = INF;     int t = 0;     for (int i = 1; i <= n; i++) {       int nt = arr[i].first + 1;       int ncnt = solve(nt, 0);       if (ncnt < ans) {         ans = ncnt;         t = arr[i].first + k + 1;       }       nt = arr[i].first - k;       ncnt = solve(nt, 0);       if (ncnt < ans) {         ans = ncnt;         t = arr[i].first;       }     }     printf( %d %d n , ans, t % (m / 2));     solve(t - k, 1);     int lens = out.size();     for (int i = 0; i < lens; i++)       printf( %d%c , out[i], i == lens - 1 ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ans[100005], t, n, d;   signed main() {     cin >> t;     while (t--) {       scanf( %d , &n);       int sum = ans[0] = 1;       for (int i = 1; i <= n; ++i) {         if (sum + (1 << (i + 1)) > n) {           d = i;           break;         }         sum += (1 << i);         ans[i] = (1 << i);       }       if (n - sum <= (1 << d)) {         ans[d] = n - sum;       } else {         ans[d] = (n - sum) / 2;         ans[d + 1] = n - sum - ans[d];         d++;       }       printf( %d n , d);       for (int i = 1; i < d; ++i) {         printf( %d  , ans[i] - ans[i - 1]);       }       printf( %d n , ans[d] - ans[d - 1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = int(1e9);   const double EPS = 1e-5;   const long long mod = ((long long)1e18) - 131;   int n, m, ans = 0;   set<string> h;   string s;   int main() {     cin >> s;     for (int i = 0; i < s.length(); i++)       for (int j = i; j < s.length(); j++) {         if (h.count(s.substr(i, j - i + 1)))           ans = max(ans, j - i + 1);         else           h.insert(s.substr(i, j - i + 1));       }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     while (b != 0) {       long long c = a % b;       a = b;       b = c;     }     return a;   }   long long lcm(long long a, long long b) { return a * b / gcd(a, b); }   bool C() {     long long n, k;     cin >> n >> k;     long long lcmk = 1;     for (long long i = 1; i <= k; ++i) {       lcmk = lcm(lcmk, i);       if (lcmk > n + 1) return false;     }     if ((n + 1) % lcmk == 0)       return true;     else       return false;   }   int main() {     if (C())       cout <<  Yes ;     else       cout <<  No ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int maxn = 1e6 + 5;   class Tree {    public:     int son1, son2;     int val;     int op;     bool rev;     vector<int> v;   } tree[maxn];   int degree[maxn];   queue<int> q;   void dfs(int id) {     tree[id].rev = 1;     if (tree[id].op == 5) return;     if (tree[id].op == 1) {       if (tree[tree[id].son1].val) dfs(tree[id].son2);       if (tree[tree[id].son2].val) dfs(tree[id].son1);     }     if (tree[id].op == 2) {       if (!tree[tree[id].son1].val) dfs(tree[id].son2);       if (!tree[tree[id].son2].val) dfs(tree[id].son1);     }     if (tree[id].op == 3) {       dfs(tree[id].son1);       dfs(tree[id].son2);     }     if (tree[id].op == 4) {       dfs(tree[id].son1);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       tree[i].rev = 0;       string s;       cin >> s;       if (s ==  AND ) {         tree[i].op = 1;         cin >> tree[i].son1 >> tree[i].son2;         tree[tree[i].son1].v.push_back(i);         tree[tree[i].son2].v.push_back(i);         degree[i] = 2;       } else if (s ==  OR ) {         tree[i].op = 2;         cin >> tree[i].son1 >> tree[i].son2;         tree[tree[i].son1].v.push_back(i);         tree[tree[i].son2].v.push_back(i);         degree[i] = 2;       } else if (s ==  XOR ) {         tree[i].op = 3;         cin >> tree[i].son1 >> tree[i].son2;         tree[tree[i].son1].v.push_back(i);         tree[tree[i].son2].v.push_back(i);         degree[i] = 2;       } else if (s ==  NOT ) {         tree[i].op = 4;         cin >> tree[i].son1;         tree[tree[i].son1].v.push_back(i);         degree[i] = 1;       } else if (s ==  IN ) {         tree[i].op = 5;         cin >> tree[i].val;         q.push(i);       }     }     int root;     while (!q.empty()) {       int id = q.front();       root = id;       q.pop();       for (int i = 0; i < tree[id].v.size(); i++) {         degree[tree[id].v[i]]--;         if (!degree[tree[id].v[i]]) q.push(tree[id].v[i]);       }       if (tree[id].op == 5)         continue;       else if (tree[id].op == 1) {         tree[id].val = (tree[tree[id].son1].val && tree[tree[id].son2].val);       } else if (tree[id].op == 2) {         tree[id].val = (tree[tree[id].son1].val || tree[tree[id].son2].val);       } else if (tree[id].op == 3) {         tree[id].val = (tree[tree[id].son1].val ^ tree[tree[id].son2].val);       } else if (tree[id].op == 4) {         tree[id].val = !tree[tree[id].son1].val;       }     }     dfs(root);     for (int i = 1; i <= n; i++)       if (tree[i].op == 5) {         if (tree[i].rev)           cout << !tree[root].val;         else           cout << tree[root].val;       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f, N = 1e5 + 10;   template <class T>   inline bool chkmin(T &A, T B) {     return B < A ? A = B, 1 : 0;   }   template <class T>   inline bool chkmax(T &A, T B) {     return A < B ? A = B, 1 : 0;   }   int n, m, A[N], cnt[N], L = 1, R, cur;   long long tot, dp[2][N];   void get(int l, int r) {     while (l < L) tot += cnt[A[--L]]++;     while (R < r) tot += cnt[A[++R]]++;     while (L < l) tot -= --cnt[A[L++]];     while (r < R) tot -= --cnt[A[R--]];   }   void Solve(int l, int r, int lim1, int lim2) {     if (l > r) return;     int mid = (l + r) >> 1, t = l;     for (int i = (lim1), i_end = (min(lim2, mid)); i <= i_end; ++i) {       get(i, mid);       if (chkmin(dp[!cur][mid], dp[cur][i - 1] + tot)) t = i;     }     Solve(l, mid - 1, lim1, t);     Solve(mid + 1, r, t, lim2);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = (1), i_end = (n); i <= i_end; ++i) {       scanf( %d , &A[i]);       get(1, i);       dp[0][i] = tot;     }     for (int i = (2), i_end = (m); i <= i_end; ++i) {       memset(dp[!cur], 63, sizeof(dp[!cur]));       Solve(1, n, 1, n);       cur = !cur;     }     printf( %lld n , dp[cur][n]);     return 0;   }