#include <bits/stdc++.h>   inline int read() {     int s = 0, w = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 , ch = getchar();     return s * w;   }   inline long long readll() {     long long s = 0, w = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 , ch = getchar();     return s * w;   }   using namespace std;   int a[1000003];   long long w[1000003], ans[1000003];   long long qp(long long x, long long y) {     if (y == 1) return x;     if (y & 1) {       long long t = qp(x, y >> 1);       return t * t % 998244353LL * x % 998244353LL;     }     long long t = qp(x, y >> 1);     return t * t % 998244353LL;   }   int main() {     int n = read();     for (int i = 1; i <= n; i++) a[i] = read();     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) w[i] = w[i - 1] + a[i];     for (int i = 1; i < n; i++)       for (int j = i; j > 0; j -= (n - i)) ans[i] += w[j], ans[i] %= 998244353LL;     for (int i = n - 1; i >= 0; i--)       printf( %lld  , ans[i] * qp(n, 998244351LL) % 998244353LL);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[40005];   int main() {     int i, j;     int n, m, x;     while (scanf( %d %d , &n, &m) != EOF) {       if ((n == 1 || n == 2) && m == 1) {         printf( -1 n );         continue;       }       if (n < (2 * m + 1)) {         if (m == 1) {           printf( %d n , n * m);           for (i = 1; i <= n; i++) {             for (j = 1; j <= m; j++) {               x = i + j;               if (x > n) {                 x = x - n;               }               printf( %d %d n , i, x);             }           }         } else           printf( -1 n );         continue;       }       printf( %d n , n * m);       for (i = 1; i <= n; i++) {         for (j = 1; j <= m; j++) {           x = i + j;           if (x > n) {             x = x - n;           }           printf( %d %d n , i, x);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool collinear(int x1, int y1, int x2, int y2, int x3, int y3) {     return (y1 - y2) * (x1 - x3) == (y1 - y3) * (x1 - x2);   }   int main() {     int n, x, y;     cin >> n;     vector<pair<int, int> > points;     for (int i = 0; i < n; i++) {       cin >> x >> y;       points.push_back(make_pair(x, y));     }     long long ans = 0;     for (int i = 0; i < n - 2; i++)       for (int j = i + 1; j < n - 1; j++)         for (int k = j + 1; k < n; k++) {           if (!collinear(points[i].first, points[i].second, points[j].first,                          points[j].second, points[k].first, points[k].second))             ans++;         }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int Get() {     char c;     while (c = getchar(), c <  0  || c >  9 )       ;     int X = c - 48;     while (c = getchar(), c >=  0  && c <=  9 ) X = X * 10 + c - 48;     return X;   }   int Pow(int A, int B, int Mod) {     if (!B) return 1;     int T = Pow((long long)A * A % Mod, B / 2, Mod);     if (B & 1) T = (long long)T * A % Mod;     return T;   }   int main() {     int N = Get(), M = Get(), Mod = Get();     static int G[600][600], In[600], Out[600];     memset(G, 0, sizeof(G));     memset(In, 0, sizeof(In));     memset(Out, 0, sizeof(Out));     for (int i = 0; i < M; i++) {       int X = Get() - 1, Y = Get() - 1;       G[X][Y]++;       In[Y]++;       Out[X]++;     }     static vector<int> List[600];     for (int i = 0; i < N; i++)       for (int j = 0; j < N; j++)         if (G[i][j]) List[i].push_back(j);     static int Temp[600], Stack[600];     int Top = 0;     for (int i = 0; i < N; i++) {       Temp[i] = In[i];       if (!Temp[i]) Stack[Top++] = i;     }     static int Queue[600];     int Count = 0;     while (Top--) {       int V = Stack[Top];       Queue[Count++] = V;       for (int i = 0; i < N; i++)         if (G[V][i]) {           Temp[i] -= G[V][i];           if (!Temp[i]) Stack[Top++] = i;         }     }     static int P[600][600];     memset(P, 0, sizeof(P));     for (int i = 0; i < N; i++) {       int V = Queue[i];       P[V][V] = 1;       for (int j = i; j < N; j++) {         int U = Queue[j];         if (!P[V][U]) continue;         for (int k = 0; k < List[U].size(); k++) {           int _U = List[U][k];           P[V][_U] = ((long long)P[V][U] * G[U][_U] + P[V][_U]) % Mod;         }       }     }     int K0 = 0, K1 = 0;     static int X[600], Y[600];     for (int i = 0; i < N; i++) {       if (!In[i] && Out[i]) X[K0++] = i;       if (!Out[i] && In[i]) Y[K1++] = i;     }     int K = K0;     static long long A[600][600];     for (int i = 0; i < K; i++)       for (int j = 0; j < K; j++) A[i][j] = P[X[i]][Y[j]];     int Ans = 1;     for (int i = 0; i < N; i++)       if (!In[i] && !Out[i]) X[K0++] = Y[K1++] = i;     for (int i = 0; i < K0; i++)       for (int j = 0; j < K0; j++)         if (X[i] < X[j] && Y[i] > Y[j]) Ans = -Ans;     for (int i = 0; i < K; i++) {       int P = i;       while (P < K && !A[P][i]) P++;       if (P == K) {         printf( 0 n );         return 0;       }       if (P != i) {         Ans = -Ans;         for (int j = i; j < K; j++) swap(A[i][j], A[P][j]);       }       int Q = Pow(A[i][i], Mod - 2, Mod);       for (int j = i + 1; j < K; j++) {         int T = (long long)A[j][i] * Q % Mod;         if (!T) continue;         for (int k = i; k < K; k++) {           A[j][k] = (A[j][k] - (long long)T * A[i][k]) % Mod;           if (A[j][k] < 0) A[j][k] += Mod;         }       }     }     for (int i = 0; i < K; i++) Ans = (long long)Ans * A[i][i] % Mod;     if (Ans < 0) Ans += Mod;     printf( %d n , Ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int par[20][100001], dep[100001], lg[100001], sizes[100001];   bool isParent[100001];   vector<int> adj[100001];   void dfs(int u) {     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (v != par[0][u]) {         isParent[u] = true;         dep[v] = dep[u] + 1;         par[0][v] = u;         dfs(v);       }     }   }   int subtree(int u) {     if (sizes[u] == -1) {       sizes[u] = 1;       if (isParent[u]) {         for (int i = 0; i < adj[u].size(); i++) {           int v = adj[u][i];           if (v != par[0][u]) sizes[u] += subtree(v);         }       }     }     return sizes[u];   }   void buildLCA(int root, int n) {     memset(par, -1, sizeof par);     memset(sizes, -1, sizeof sizes);     memset(isParent, false, sizeof isParent);     dep[root] = 0;     dfs(root);     for (int i = 2; i < n; i++) lg[i] = lg[i >> 1] + 1;     for (int i = 1; (1 << i) < n; i++)       for (int u = 0; u < n; u++)         if ((1 << i) <= dep[u]) par[i][u] = par[i - 1][par[i - 1][u]];     subtree(root);   }   int climb(int u, int k) {     if (dep[u] < k) return -1;     for (; k > 0; k -= (1 << lg[k])) u = par[lg[k]][u];     return u;   }   int lca(int a, int b) {     if (dep[a] < dep[b])       b = climb(b, dep[b] - dep[a]);     else       a = climb(a, dep[a] - dep[b]);     for (int k = lg[dep[a]]; k >= 0 && a != b; k--)       if (par[k][a] != par[k][b]) {         a = par[k][a];         b = par[k][b];       }     if (a != b && dep[a] > 0) {       a = par[0][a];       b = par[0][b];     }     return a == b ? a : -1;   }   int dist(int u, int v) {     int L = lca(u, v);     return L == -1 ? -1 : dep[u] + dep[v] - 2 * dep[L];   }   int main() {     int n, m;     cin >> n;     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     buildLCA(1, n + 1);     cin >> m;     while (m--) {       int a, b;       cin >> a >> b;       if (a != b) {         int l = lca(a, b), distance = dist(a, b);         if (distance % 2 == 0) {           if (dep[a] != dep[b]) {             int deepernode;             if (dep[a] > dep[b])               deepernode = a;             else               deepernode = b;             int mid1 = climb(deepernode, distance / 2),                 mid2 = climb(deepernode, distance / 2 - 1);             cout << sizes[mid1] - sizes[mid2] << endl;           } else {             int aa = climb(a, dist(a, l) - 1), bb = climb(b, dist(a, l) - 1);             cout << n - sizes[aa] - sizes[bb] << endl;           }         } else           cout << 0 << endl;       } else         cout << n << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300100;   int head[maxn], nxt[maxn << 1], ver[maxn << 1], tot;   void addedge(int a, int b) {     nxt[++tot] = head[a];     ver[tot] = b;     head[a] = tot;     nxt[++tot] = head[b];     ver[tot] = a;     head[b] = tot;   }   int f[maxn], getlen;   void treedp(int x, int fat) {     f[x] = 0;     int mx = 0, sm = 0;     for (int i = head[x]; i; i = nxt[i]) {       int y = ver[i];       if (y == fat) continue;       treedp(y, x);       int F = f[y] + 1;       f[x] = max(f[x], F);       if (F >= mx)         sm = mx, mx = F;       else if (F > sm)         sm = F;     }     getlen = max(getlen, mx + sm);   }   int getpath(int x) {     getlen = 0;     treedp(x, 0);     return getlen;   }   int v[maxn], fa[maxn];   int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }   int main() {     int n, m, q;     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= n; i++) fa[i] = i;     for (int i = 1; i <= m; i++) {       int a, b;       scanf( %d%d , &a, &b);       addedge(a, b);       fa[find(a)] = find(b);     }     for (int i = 1; i <= n; i++)       if (find(i) == i) v[i] = getpath(i);     for (int i = 1; i <= q; i++) {       int opt, a, b;       scanf( %d , &opt);       if (opt == 1)         scanf( %d , &a), printf( %d n , v[find(a)]);       else {         scanf( %d%d , &a, &b);         a = find(a);         b = find(b);         if (a == b) continue;         v[b] = max(max(v[a], v[b]), ((v[a] + 1) >> 1) + ((v[b] + 1) >> 1) + 1);         fa[a] = b;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[5002];   int main() {     int n, i;     scanf( %d , &n);     if (n <= 2) {       printf( 1 n1 n );       return 0;     }     if (n == 3) {       printf( 2 n1 3 n );       return 0;     }     int curr = (n & 1) ? n : n - 1;     for (i = 0; i < n; i++) {       if (curr < 0) curr = (n & 1) ? n - 1 : n;       arr[i] = curr;       curr -= 2;     }     printf( %d n , n);     for (i = 0; i < n; i++) printf( %d  , arr[i]);     putchar(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, i, m = 1000000007, a, b;   int main() {     cin >> n;     a = 1, b = 1;     for (i = 0; i < 3 * n; i++) a = (a * 3) % m;     for (i = 0; i < n; i++) b = (b * 7) % m;     cout << (a - b + m) % m;     return 0;   }


#include <bits/stdc++.h>   const int mxn = 1e5;   int cost[mxn][3], go[mxn][2], deg[mxn], path[mxn];   int color[mxn];   long long cc[3][3];   int main() {     int n, u, a, b, c = 0;     scanf( %d , &n);     for (int j = 0; j < 3; ++j)       for (int i = 1; i <= n; ++i) scanf( %d , &cost[i][j]);     for (int i = 1; i < n; ++i) {       scanf( %d%d , &a, &b);       ++deg[a], ++deg[b];       go[a][0] ? go[a][1] = b : go[a][0] = b;       go[b][0] ? go[b][1] = a : go[b][0] = a;     }     for (int i = 1; i <= n; ++i) {       if (deg[i] == 1) ++c, u = i;       if (deg[i] > 2) return 0 * printf( -1 );     }     if (c != 2) return 0 * printf( -1 );     for (int i = 1, v = u, p = 0, pa; p != v; ++i, p = pa) {       path[i] = pa = v;       if (go[v][0] != p && go[v][0])         v = go[v][0];       else if (go[v][1] != p && go[v][1])         v = go[v][1];     }     for (int i = 0; i < 3; ++i) {       for (int j = 0; j < 3; ++j)         if (i != j) {           a = i, b = j;           cc[i][j] = cost[path[1]][i] + cost[path[2]][j];           for (int k = 3; k <= n; ++k) {             c = (3 - a - b) % 3;             cc[i][j] += cost[path[k]][c];             a = b, b = c;           }         }     }     long long min_cost = (long long)1e18;     for (int i = 0; i < 3; ++i)       for (int j = 0; j < 3; ++j)         if (i != j)           if (min_cost > cc[i][j]) a = i, b = j, min_cost = cc[i][j];     color[path[1]] = a, color[path[2]] = b;     for (int k = 3; k <= n; ++k) {       c = (3 - a - b) % 3;       color[path[k]] = c;       a = b, b = c;     }     printf( %lld n , min_cost);     for (int i = 1; i <= n; ++i) printf( %d  , color[i] + 1);   }


#include <bits/stdc++.h>   using namespace std;   map<string, int> ma;   map<string, int>::iterator p;   long i, n, m;   double ex, k;   int main() {     cin >> n >> m >> k;     string st;     for (i = 1; i <= n; i++) {       cin >> st >> ex;       ma[st] = (int)(ex * k + 1e-9);       if (ma[st] < 100) ma.erase(st);     }     for (i = 1; i <= m; i++) {       cin >> st;       ma[st] += 0;     }     cout << ma.size() << endl;     for (p = ma.begin(); p != ma.end(); p++)       cout << p->first <<     << p->second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long cc = 1e9 + 7;   map<int, int> A;   map<int, int>::iterator itr, it;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       int nn = s.size();       vector<int> p;       for (int j = 0; j < nn; j++) {         int nnn = p.size();         if (p.size() == 0) {           if (s[j] ==  ( )             p.push_back(1);           else             p.push_back(-1);         } else {           if (s[j] ==  ) ) {             if (p[nnn - 1] == 1)               p.pop_back();             else               p.push_back(-1);           } else {             p.push_back(1);           }         }       }       int nnn = p.size();       if (nnn == 0)         A[0]++;       else if (p[0] == p[nnn - 1]) {         A[(p[0] * nnn)]++;       }     }     int sum = 0;     for (itr = A.begin(); itr != A.end(); itr++) {       if (itr->first == 0) {         sum += (itr->second) / 2;       } else {         int yy = itr->first;         it = A.find(0 - yy);         if (it != A.end()) {           sum += (min(itr->second, it->second));           it->second = 0;         }       }     }     cout << sum << endl;   }


#include<bits/stdc++.h>   using namespace std;   typedef long long int ll;   #define endl   n                bool powerOf2(ll x){       return x && (!(x&(x-1)));   }      void solve(){              ll u, v;              cin>>u>>v;                     if(v<u || (powerOf2(u) && !powerOf2(v))){           cout<< No n ;       }else{           if(u==v || (powerOf2(v))){               cout<< Yes n ;           }else{               ll num = u;                                                          bool flag = false;                                 while(num<v){                   ll maxN = -1;                      for(int i = 0;i<32; i++){                                              ll msk = 1<<i;                                              if(num + msk > v){                           break;                       }                                              if(num & msk){                           if(num + msk == v){                               flag = true;                               break;                           }                           maxN = max(maxN, msk);                       }                   }                                                         if(flag || maxN == -1) break;                                      num+=maxN;               }                                             if(flag || num==v){                   cout<< Yes n ;               }else{                   cout<< No n ;               }                          }               }                                  }      int main(){       int t;       cin>>t;       while(t--)           solve();       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 7;   int clr[MAX] = {0}, vis[MAX] = {0}, res = 0;   vector<int> adj[MAX];   void dfs(int u, int p, int clr_p) {     int f = 0;     if (!vis[clr[u]]) {       f = 1;       vis[clr[u]] = 1;       res++;     } else if (p != -1 && clr_p != clr[u])       res++;     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (p == v) continue;       dfs(v, u, clr[u]);     }     if (f) vis[clr[u]] = 0;   }   int main(int argc, char const *argv[]) {     int n, x;     cin >> n;     for (int i = 2; i <= n; i++) {       cin >> x;       adj[i].push_back(x);       adj[x].push_back(i);     }     for (int i = 1; i <= n; i++) cin >> clr[i];     dfs(1, -1, -1);     std::cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<pair<int, int> > e;   bool check(vector<pair<int, int> > res) {     if (res.size() > (n + m + 1) / 2) return false;     vector<int> d(n, 0), d2(n, 0);     for (pair<int, int> i : res) {       d[--i.first]++;       d[--i.second]++;     }     for (pair<int, int> i : e) {       d2[--i.first]++;       d2[--i.second]++;     }     for (int i = 0; i < n; i++) {       if ((d2[i] + 1) / 2 > d[i]) return false;     }     return true;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     e.resize(m);     vector<set<int> > g(n + 1);     for (int i = 0; i < m; i++) {       cin >> e[i].first >> e[i].second;       g[e[i].first].insert(e[i].second);       g[e[i].second].insert(e[i].first);     }     for (int i = 1; i <= n; i++) {       if ((int)(g[i].size()) & 1) {         g[i].insert(0);         g[0].insert(i);       }     }     vector<int> c(n + 1, 0);     vector<pair<int, int> > res;     for (int s = 1; s <= n; s++) {       if (!c[s]) {         vector<int> st, ep;         st.push_back(s);         while (!st.empty()) {           int f = st.back();           c[f] = 1;           if (g[f].empty()) {             st.pop_back();             ep.push_back(f);           } else {             int v = *g[f].begin();             g[f].erase(v);             g[v].erase(f);             st.push_back(v);           }         }         ep.pop_back();         for (int i = 0; i < (int)ep.size(); i++) {           int v0 = ep[(ep.size() + i - 1) % ep.size()], v1 = ep[i],               v2 = ep[(i + 1) % ep.size()], v3 = ep[(i + 2) % ep.size()];           if (!v1 || !v2) continue;           if (!v0 || !v3 || !(i & 1)) {             res.push_back({v1, v2});           }         }       }     }     cout << res.size() <<   n ;     for (pair<int, int> i : res) {       cout << i.first <<     << i.second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long input() {     long long x;     scanf( %lld , &x);     return x;   }   const int inf = 1e9;   int clamp(int a, int l, int r) {     if (a < l) a = l;     if (a > r) a = r;     return a;   }   int main() {     int n, m;     cin >> n >> m;     vector<int> pos(1010101, -1);     vector<int> L(1010101, -1), R(1010101, -1);     set<tuple<int, int, int, int>> st;     const int MostLeft = 1010101 - 2;     const int MostRight = 1010101 - 3;     pos[MostLeft] = -inf;     pos[MostRight] = inf;     const auto calcPos = [&](int i, int j) {       if (i == MostLeft && j == MostRight) return 1;       return clamp((pos[i] + pos[j]) / 2, 1, n);     };     const auto calcDist = [&](int i, int j) {       if (i == MostLeft && j == MostRight)         return n - 1;       else if (i == MostLeft)         return pos[j] - 1;       else if (j == MostRight)         return n - pos[i];       return (pos[j] - pos[i]) / 2;     };     for (int ii = 0; ii < m; ii++) {       int t = input();       int id = input();       if (t == 1) {         int lid, rid;         if (st.empty()) {           lid = MostLeft;           rid = MostRight;         } else {           tie(ignore, ignore, lid, rid) = *st.begin();           st.erase(st.begin());         }         pos[id] = calcPos(lid, rid);         R[lid] = L[rid] = id;         L[id] = lid;         R[id] = rid;         st.emplace(-calcDist(lid, id), pos[lid], lid, id);         st.emplace(-calcDist(id, rid), pos[id], id, rid);         printf( %d n , pos[id]);       } else {         int lid = L[id];         int rid = R[id];         R[lid] = rid;         L[rid] = lid;         st.erase(make_tuple(-calcDist(lid, id), pos[lid], lid, id));         st.erase(make_tuple(-calcDist(id, rid), pos[id], id, rid));         st.emplace(-calcDist(lid, rid), pos[lid], lid, rid);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5;   int m;   int num[MAXN + 10];   int tree[4 * MAXN + 10];   int prop[4 * MAXN + 10];   void upd(int cn, int b, int e, int l, int r, int x, int p = 0) {     if (l <= b && e <= r) {       tree[cn] += x + p;       prop[cn] += x + p;       return;     }     if (r < b || l > e) {       tree[cn] += p;       prop[cn] += p;       return;     }     p += prop[cn];     prop[cn] = 0;     int m = (b + e) / 2;     upd(2 * cn, b, m, l, r, x, p);     upd(2 * cn + 1, m + 1, e, l, r, x, p);     tree[cn] = min(tree[2 * cn], tree[2 * cn + 1]);   }   void upd(int i, int x) { upd(1, 1, m, i, m, x); }   int get(int cn, int b, int e, int l, int r, int p = 0) {     if (l <= b && e <= r) return tree[cn] + p;     if (r < b || l > e) return 1e9;     int m = (b + e) / 2;     int L = get(2 * cn, b, m, l, r, p + prop[cn]);     int R = get(2 * cn + 1, m + 1, e, l, r, p + prop[cn]);     return min(L, R);   }   bool oka(int j) {     if (j == 0) return 0 < get(1, 1, m, m, m);     return get(1, 1, m, j, m) < get(1, 1, m, m, m);   }   int solve() {     int lo = 0, hi = m - 1;     while (hi - lo > 1) {       int m = (lo + hi) / 2;       if (oka(m))         lo = m;       else         hi = m - 1;     }     if (oka(hi)) return num[hi + 1];     if (oka(lo)) return num[lo + 1];     return -1;   }   int main() {     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       int ps, tp;       scanf( %d%d , &ps, &tp);       if (tp == 0)         upd(ps, -1);       else {         int x;         scanf( %d , &x);         num[ps] = x;         upd(ps, +1);       }       printf( %d n , solve());     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (int)2e9;   const int mod = (int)1e9 + 123;   const int N = (int)1e6 + 10;   const long long LLINF = (long long)3e18 + 10;   const long double pi = acos(-1);   template <typename T1, typename T2>   bool umin(T1 &x, T2 y) {     if (x > y) return x = y, true;     return false;   }   template <typename T1, typename T2>   bool umax(T1 &x, T2 y) {     if (x < y) return x = y, true;     return false;   }   template <typename T>   T getint() {     char c = getchar();     T p = 1, x = 0;     while (c ==     || c ==   n ) c = getchar();     if (c ==  - ) p = -1, c = getchar();     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return x * p;   }   long long bp[N], h[N];   int n, m, q;   map<tuple<int, int, int, int>, long long> s;   struct tree {     vector<tree *> t;     vector<long long> a;     tree(int n, int m) {       t.resize(n + 1);       for (int i = 1; i <= n; ++i) {         t[i] = new tree(m);       }     }     tree(int m) { a.resize(m + 1); }     void add(int x, int y, long long val) {       if (x >= t.size()) return;       for (; x <= n; x |= (x + 1)) t[x]->add(y, val);     }     void add(int y, long long val) {       if (y >= a.size()) return;       for (; y <= m; y |= (y + 1)) a[y] += val;     }     long long get(int x, int y) {       long long ans = 0;       for (; x >= 1; x = (x & (x + 1)) - 1) {         ans += t[x]->get(y);       }       return ans;     }     long long get(int y) {       long long ans = 0;       for (; y >= 1; y = (y & (y + 1)) - 1) {         ans += a[y];       }       return ans;     }     void couttree() {       if (t.size()) {         for (int i = 1; i < t.size(); ++i) {           t[i]->couttree();           cout <<   n ;         }         cout << endl;       } else {         for (int i = 1; i < a.size(); ++i) {           cout << a[i] <<    ;         }       }     }   };   int main() {     srand(time(NULL));     ios_base::sync_with_stdio(0);     n = getint<int>();     m = getint<int>();     q = getint<int>();     tree *t = new tree(n, m);     for (int i = 0; i < q; ++i) {       bp[i] = (i ? bp[i - 1] * 23123 % mod : 1);       h[i] = ((i ? h[i - 1] : 0) + (i + 1) * bp[i]) % mod;       int ty = getint<int>();       int x1 = getint<int>(), y1 = getint<int>();       int x2 = getint<int>(), y2 = getint<int>();       if (ty == 1) {         s[make_tuple(x1, y1, x2, y2)] = h[i];         t->add(x1, y1, h[i]);         t->add(x1, y2 + 1, -h[i]);         t->add(x2 + 1, y1, -h[i]);         t->add(x2 + 1, y2 + 1, h[i]);       }       if (ty == 2) {         long long val = s[make_tuple(x1, y1, x2, y2)];         t->add(x1, y1, -val);         t->add(x1, y2 + 1, val);         t->add(x2 + 1, y1, val);         t->add(x2 + 1, y2 + 1, -val);       }       if (ty == 3) {         if (t->get(x1, y1) == t->get(x2, y2))           printf( Yes n );         else           printf( No n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5;   int n, m, k, a[N][5];   int sparse[5][17][N];   vector<int> last(5, 0);   void build(int u) {     for (int i = 0; i < n; i++) sparse[u][0][i] = a[i][u];     for (int j = 1; j <= 17; j++)       for (int i = 0; i + (1 << (j - 1)) < n; i++)         sparse[u][j][i] =             max(sparse[u][j - 1][i], sparse[u][j - 1][i + (1 << (j - 1))]);   }   int q(int u, int x, int y) {     int v = log2(y - x + 1);     return max(sparse[u][v][x], sparse[u][v][y + 1 - (1 << v)]);   }   bool check(int mid) {     vector<int> v(5, 0);     int sum;     for (int i = 0; i < n - mid; i++) {       sum = 0;       for (int j = 0; j < m; j++) {         v[j] = q(j, i, i + mid);         sum += v[j];       }       if (sum <= k) {         last = v;         return 1;       }     }     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> a[i][j];     for (int i = 0; i < m; i++) build(i);     int l = 0, r = n, mid;     while (l <= r) {       mid = (l + r) / 2;       if (check(mid))         l = mid + 1;       else         r = mid - 1;     }     for (int i = 0; i < m; i++) cout << last[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   struct pi {     int x, y, t;     double p;   } pp[1005];   double dp[1005];   int cmp(pi a, pi b) { return a.t < b.t; }   double get(int a, int b) {     return sqrt(pow(pp[a].x - pp[b].x, 2.0) + pow(pp[a].y - pp[b].y, 2.0));   }   int main() {     int i, j, n;     cin >> n;     for (i = 1; i <= n; i++) {       scanf( %d%d%d%lf , &pp[i].x, &pp[i].y, &pp[i].t, &pp[i].p);     }     sort(pp + 1, pp + 1 + n, cmp);     dp[1] = pp[1].p;     for (i = 2; i <= n; i++) {       dp[i] = pp[i].p;       for (j = 1; j < i; j++) {         if (get(j, i) <= pp[i].t - pp[j].t) {           dp[i] = max(dp[i], dp[j] + pp[i].p);         }       }     }     double s = 0;     for (i = 1; i <= n; i++) s = max(s, dp[i]);     printf( %.9lf n , s);   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7, mod2 = 998244353;   unsigned long long base = 131;   const int w = 1e7 + 5;   long long m, n;   int main() {     long long i, j, k, t, qqq;     cin >> n;     string a, b;     cin >> a >> b;     int flag = 0;     for (i = a.size() - 1; i >= 0; i--) {       int x = (b[i] -  a );       int y = (int)a[i] + x;       if (flag) y++, flag = 0;       if (y > (int) z ) y -= 26, flag++;       a[i] = (char)y;     }     if (flag) a.insert(a.begin(),  b );     flag = 0;     for (i = 0; i < a.size(); i++) {       int x = a[i] -  a ;       if (flag) x += 26, flag = 0;       int y = x % 2;       x /= 2;       a[i] = x +  a ;       if (y) flag = 1;     }     if (a.size() == n)       cout << a << endl;     else {       for (i = 1; i < a.size(); i++) printf( %c , a[i]);       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   const int maxm = 1e5 + 10;   const int INF = 0x3f3f3f3f;   const long long LINF = 3e17 + 1;   const int mod = 998244353;   int n, m, eid, sz;   inline int read() {     register int x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = (x << 3) + (x << 1) + ch -  0 ;       ch = getchar();     }     return (f == 1) ? x : -x;   }   int a[maxn];   int main() {     ;     ios::sync_with_stdio(0);     cin.tie(0);     ;     int r;     cin >> n >> r;     for (int i = 1; i <= n; i++) cin >> a[i];     int cur = 1, res = 0;     while (cur <= n) {       int idx = 0;       for (int i = 1; i <= n; i++) {         if (a[i]) {           if (cur >= i - r + 1 && cur <= i + r - 1) {             idx = i;           }         }       }       if (idx == 0) {         cout << -1 << endl;         return 0;       }       res++;       cur = idx + r;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1LL << 28;   const long long mod = 1LL;   int arr[3 * 100010];   int main() {     int n, k, i, ans, flag, j;     while (scanf( %d %d , &n, &k) == 2) {       for (i = 0; i < n; i++) {         scanf( %d , &arr[i]);       }       sort(arr, arr + n);       ans = arr[0];       while (true) {         flag = true;         for (i = 0; i < n; i++) {           if (arr[i] % ans <= k) continue;           flag = false;           j = arr[i] / ans;           j++;           ans = arr[i] / j;         }         if (flag) break;       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 7;   const long long INF = 1e18;   const long long mod = 1e9 + 7;   int n;   int a;   int b;   int mxa;   int mxb;   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> a >> b;     mxb = b;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       if (x && b < mxb) {         if (a) {           a--;           b += b < mxb;         } else if (b) {           b--;         }       } else {         if (b) {           b--;         } else if (a) {           a--;         }       }       if (!a && !b) {         cout << i << endl;         return 0;       }     }     cout << n << endl;   }


#include <bits/stdc++.h>   int prm[20] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};   long long n, ans;   void find(int k, long long cnt, long long sum) {     int i;     if (sum > n) return;     if (sum == n && cnt < ans) ans = cnt;     for (i = 1; i <= 63; i++) {       if (ans / prm[k] < cnt) break;       cnt = cnt * prm[k];       find(k + 1, cnt, sum * (i + 1));     }   }   int main() {     while (scanf( %I64d , &n) != EOF) {       ans = 2e65;       find(0, 1, 1);       printf( %I64d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int v[4000 + 10], d[4000 + 10], p[4000 + 10];   int result[4000 + 10], check[1000000 + 10];   int main() {     int n, a, b;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       cin >> v[i] >> d[i] >> p[i];     }     int lost = 0;     for (int i = 0; i < n; i++) {       if (p[i] >= 0) {         result[lost++] = i + 1;         long long q = v[i];         long long k = 0;         for (int j = i + 1; j < n; j++) {           if (p[j] < 0) continue;           p[j] -= q;           p[j] -= k;           if (q) q--;           if (p[j] < 0 && k < 1e7) k += d[j];         }       }     }     printf( %d n , lost);     for (int i = 0; i < lost; i++) {       printf( %d  , result[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 7;   const int inf = 0x3f3f3f3f;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const int mod = 1e9 + 7;   const double eps = 1e-8;   const double PI = acos(-1);   int n;   long long h[N], dp[N][2];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lld , &h[i]), h[i]--;     h[n + 1] = inf;     dp[1][0] = h[1];     dp[1][1] = min(h[1], h[2]);     long long ans = dp[1][0];     for (int i = 2; i <= n; i++) {       dp[i][0] = (dp[i - 1][1] * min(h[i - 1], h[i]) + h[i]) % mod;       dp[i][1] = ((dp[i - 1][1] * min(h[i - 1], min(h[i], h[i + 1])) % mod) +                   min(h[i], h[i + 1])) %                  mod;       ans = (ans + dp[i][0]) % mod;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 4 * atan(1);   int T, N;   long long X[100013], Y[100013], Z[100013];   long long xmi, xma, ymi, yma, zmi, zma, smi, sma;   long long ansx, ansy, ansz;   inline bool is(long long x, int p) { return (((x % 2) + 2) % 2) == p; }   bool go(long long d) {     xmi = -8.1e18, xma = 8.1e18, ymi = -8.1e18, yma = 8.1e18, zmi = -8.1e18,     zma = 8.1e18, smi = -8.1e18, sma = 8.1e18;     for (int i = 0; i < N; i++) {       xmi = max(xmi, Y[i] + Z[i] - X[i] - d);       xma = min(xma, Y[i] + Z[i] - X[i] + d);       ymi = max(ymi, -Y[i] + Z[i] + X[i] - d);       yma = min(yma, -Y[i] + Z[i] + X[i] + d);       zmi = max(zmi, Y[i] - Z[i] + X[i] - d);       zma = min(zma, Y[i] - Z[i] + X[i] + d);       smi = max(smi, Y[i] + Z[i] + X[i] - d);       sma = min(sma, Y[i] + Z[i] + X[i] + d);     }     if (smi > sma || xmi > xma || ymi > yma || zmi > zma) return false;     for (int p = 0; p < 2; p++) {       if (smi == sma && is(smi, !p) || xmi == xma && is(xmi, !p) ||           ymi == yma && is(ymi, !p) || zmi == zma && is(zmi, !p))         continue;       long long qmi = 0;       qmi += (is(xmi, p) ? xmi : xmi + 1);       qmi += (is(ymi, p) ? ymi : ymi + 1);       qmi += (is(zmi, p) ? zmi : zmi + 1);       long long qma = 0;       qma += (is(xma, p) ? xma : xma - 1);       qma += (is(yma, p) ? yma : yma - 1);       qma += (is(zma, p) ? zma : zma - 1);       if (qmi <= qma && qmi <= sma && qma >= smi) {         if (qmi >= smi) {           ansx = (is(xmi, p) ? xmi : xmi + 1);           ansy = (is(ymi, p) ? ymi : ymi + 1);           ansz = (is(zmi, p) ? zmi : zmi + 1);         } else if (qma <= sma) {           ansx = (is(xma, p) ? xma : xma - 1);           ansy = (is(yma, p) ? yma : yma - 1);           ansz = (is(zma, p) ? zma : zma - 1);         } else {           xmi += is(xmi, !p);           xma -= is(xma, !p);           ymi += is(ymi, !p);           yma -= is(yma, !p);           zmi += is(zmi, !p);           zma -= is(zma, !p);           smi += is(smi, !p);           sma -= is(sma, !p);           if (xma + ymi + zmi < smi) {             if (xma + yma + zmi < smi) {               ansx = xma;               ansy = yma;               ansz = smi - ansx - ansy;             } else {               ansx = xma;               ansz = zmi;               ansy = smi - ansx - ansz;             }           } else {             ansy = ymi;             ansz = zmi;             ansx = smi - ymi - zmi;           }         }         return true;       }     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> T;     while (T--) {       cin >> N;       for (int i = 0; i < N; i++) {         cin >> X[i] >> Y[i] >> Z[i];       }       long long lo = 0;       long long hi = 3.1e18;       while (lo != hi) {         long long mid = (lo + hi) / 2;         if (go(mid)) {           hi = mid;         } else {           lo = mid + 1;         }       }       go(lo);       cout << (ansy + ansz) / 2 <<     << (ansx + ansz) / 2 <<                << (ansx + ansy) / 2 <<   n ;     }     cout.flush();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[4];   int aux[100010];   int next(int x) {     if (x == 0) {       if (arr[1] > 0)         return 1;       else         return -1;     }     if (x == 1) {       if (arr[0] > 0)         return 0;       else if (arr[2] > 0)         return 2;       else         return -1;     }     if (x == 2) {       if (arr[1] > 0)         return 1;       else if (arr[3] > 0)         return 3;       else         return -1;     }     if (x == 3) {       if (arr[2] > 0)         return 2;       else         return -1;     }   }   int arrini[4];   int n;   void ok() {     cout <<  YES n ;     for (int i = 0; i < n; i++) cout << aux[i] <<    ;     cout <<   n ;   }   bool tenta(int ini) {     for (int i = 0; i < 4; i++) arr[i] = arrini[i];     arr[ini]--;     aux[0] = ini;     for (int i = 1; i < n; i++) {       int nex = next(aux[i - 1]);       if (nex == -1) return false;       aux[i] = nex;       arr[nex]--;     }     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> arrini[0] >> arrini[1] >> arrini[2] >> arrini[3];     for (int i = 0; i < 4; i++) arr[i] = arrini[i];     n = arr[0] + arr[1] + arr[2] + arr[3];     if (arrini[0] > 0) {       if (tenta(0)) {         ok();         return 0;       }     }     if (arrini[1] > 0) {       if (tenta(1)) {         ok();         return 0;       }     }     if (arrini[2] > 0) {       if (tenta(2)) {         ok();         return 0;       }     }     if (arrini[3] > 0) {       if (tenta(3)) {         ok();         return 0;       }     }     cout <<  NO n ;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 25;   const long long LL_INF = 1ll << 61;   int main() {     int n;     scanf( %d , &n);     vector<int> count(3, 0);     for (int i = 0; i < n; i++) {       int num;       scanf( %d , &num);       count[num]++;     }     if (count[1] == 0) {       for (int i = 0; i < count[2]; i++) printf( 2  );       printf(  n );     } else {       if (count[2] == 0) {         for (int i = 0; i < count[1]; i++) printf( 1  );         printf(  n );       } else {         printf( 2 1  );         count[2]--;         count[1]--;         for (int i = 0; i < count[2]; i++) printf( 2  );         for (int i = 0; i < count[1]; i++) printf( 1  );         printf(  n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define int               long long   #define pb                push_back   #define ppb               pop_back   #define pf                push_front   #define ppf               pop_front   #define all(x)            (x).begin(),(x).end()   #define uniq(v)           (v).erase(unique(all(v)),(v).end())   #define sz(x)             (int)((x).size())   #define fr                first   #define sc                second   #define pii               pair<int,int>   #define rep(i,a,b)        for(int i=a;i<b;i++)   #define mem1(a)           memset(a,-1,sizeof(a))   #define mem0(a)           memset(a,0,sizeof(a))   #define ppc               __builtin_popcount   #define ppcll             __builtin_popcountll      template<typename T1, typename T2>istream& operator>>(istream& in, pair<T1, T2> &a) {in >> a.fr >> a.sc; return in;}   template<typename T1, typename T2>ostream& operator<<(ostream& out, pair<T1, T2> a) {out << a.fr <<     << a.sc; return out;}   template<typename T, typename T1>T amax(T &a, T1 b) {if (b > a)a = b; return a;}   template<typename T, typename T1>T amin(T &a, T1 b) {if (b < a)a = b; return a;}      const long long INF = 1e18;   const int32_t M = 1e9 + 7;   const int32_t MM = 998244353;      const int N = 0;         void solve() {       int n, m, k;    cin >> n >> m >> k;    int fl = 0;    int sum = 1;    sum = 1 * (m - 1) + m * (n - 1);          if (sum == k)     cout <<  YES n ;    else     cout <<  NO n ;      }         signed main() {    ios_base::sync_with_stdio(false);    cin.tie(0); cout.tie(0);   #ifndef ONLINE_JUDGE    freopen( input.txt ,  r , stdin);    freopen( output.txt ,  w , stdout);   #endif    int t = 1;    cin >> t;    while (t--) solve();    return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename... As>   struct tpl : public std::tuple<As...> {     using std::tuple<As...>::tuple;     tpl() {}     tpl(std::tuple<As...> const& b) { std::tuple<As...>::operator=(b); }     template <typename T = tuple<As...>>     typename tuple_element<0, T>::type const& x() const {       return get<0>(*this);     }     template <typename T = tuple<As...>>     typename tuple_element<0, T>::type& x() {       return get<0>(*this);     }     template <typename T = tuple<As...>>     typename tuple_element<1, T>::type const& y() const {       return get<1>(*this);     }     template <typename T = tuple<As...>>     typename tuple_element<1, T>::type& y() {       return get<1>(*this);     }     template <typename T = tuple<As...>>     typename tuple_element<2, T>::type const& z() const {       return get<2>(*this);     }     template <typename T = tuple<As...>>     typename tuple_element<2, T>::type& z() {       return get<2>(*this);     }     template <typename T = tuple<As...>>     typename tuple_element<3, T>::type const& w() const {       return get<3>(*this);     }     template <typename T = tuple<As...>>     typename tuple_element<3, T>::type& w() {       return get<3>(*this);     }   };   using lli = long long int;   using llu = long long unsigned;   using pii = tpl<int, int>;   using piii = tpl<int, int, int>;   using piiii = tpl<int, int, int, int>;   using vi = vector<int>;   using vii = vector<pii>;   using viii = vector<piii>;   using vvi = vector<vi>;   using vvii = vector<vii>;   using vviii = vector<viii>;   template <class T>   using min_queue = priority_queue<T, vector<T>, greater<T>>;   template <class T>   using max_queue = priority_queue<T>;   template <size_t... I>   struct my_index_sequence {     using type = my_index_sequence;     static constexpr array<size_t, sizeof...(I)> value = {{I...}};   };   namespace my_index_sequence_detail {   template <typename I, typename J>   struct concat;   template <size_t... I, size_t... J>   struct concat<my_index_sequence<I...>, my_index_sequence<J...>>       : my_index_sequence<I..., (sizeof...(I) + J)...> {};   template <size_t N>   struct make_index_sequence       : concat<typename make_index_sequence<N / 2>::type,                typename make_index_sequence<N - N / 2>::type>::type {};   template <>   struct make_index_sequence<0> : my_index_sequence<> {};   template <>   struct make_index_sequence<1> : my_index_sequence<0> {};   }  // namespace my_index_sequence_detail   template <class... A>   using my_index_sequence_for =       typename my_index_sequence_detail::make_index_sequence<sizeof...(A)>::type;   template <class T, size_t... I>   void print_tuple(ostream& s, T const& a, my_index_sequence<I...>) {     using swallow = int[];     (void)swallow{0, (void(s << (I == 0 ?    :  ,  ) << get<I>(a)), 0)...};   }   template <class T>   ostream& print_collection(ostream& s, T const& a);   template <class... A>   ostream& operator<<(ostream& s, tpl<A...> const& a);   template <class... A>   ostream& operator<<(ostream& s, tuple<A...> const& a);   template <class A, class B>   ostream& operator<<(ostream& s, pair<A, B> const& a);   template <class T, size_t I>   ostream& operator<<(ostream& s, array<T, I> const& a) {     return print_collection(s, a);   }   template <class T>   ostream& operator<<(ostream& s, vector<T> const& a) {     return print_collection(s, a);   }   template <class T, class U>   ostream& operator<<(ostream& s, multimap<T, U> const& a) {     return print_collection(s, a);   }   template <class T>   ostream& operator<<(ostream& s, multiset<T> const& a) {     return print_collection(s, a);   }   template <class T, class U>   ostream& operator<<(ostream& s, map<T, U> const& a) {     return print_collection(s, a);   }   template <class T>   ostream& operator<<(ostream& s, set<T> const& a) {     return print_collection(s, a);   }   template <class T>   ostream& print_collection(ostream& s, T const& a) {     s <<  [ ;     for (auto it = begin(a); it != end(a); ++it) {       s << *it;       if (it != prev(end(a))) s <<    ;     }     return s <<  ] ;   }   template <class... A>   ostream& operator<<(ostream& s, tpl<A...> const& a) {     s <<  ( ;     print_tuple(s, a, my_index_sequence_for<A...>{});     return s <<  ) ;   }   template <class... A>   ostream& operator<<(ostream& s, tuple<A...> const& a) {     s <<  ( ;     print_tuple(s, a, my_index_sequence_for<A...>{});     return s <<  ) ;   }   template <class A, class B>   ostream& operator<<(ostream& s, pair<A, B> const& a) {     return s <<  (  << get<0>(a) <<  ,   << get<1>(a) <<  ) ;   }   namespace std {   namespace {   template <class T>   inline void hash_combine(size_t& seed, T const& v) {     seed ^= hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);   }   template <class Tuple, size_t Index = tuple_size<Tuple>::value - 1>   struct HashValueImpl {     static void apply(size_t& seed, Tuple const& tuple) {       HashValueImpl<Tuple, Index - 1>::apply(seed, tuple);       hash_combine(seed, get<Index>(tuple));     }   };   template <class Tuple>   struct HashValueImpl<Tuple, 0> {     static void apply(size_t& seed, Tuple const& tuple) {       hash_combine(seed, get<0>(tuple));     }   };   }  // namespace   template <typename... TT>   struct hash<tuple<TT...>> {     size_t operator()(tuple<TT...> const& tt) const {       size_t seed = 0;       HashValueImpl<tuple<TT...>>::apply(seed, tt);       return seed;     }   };   template <typename... TT>   struct hash<tpl<TT...>> {     size_t operator()(tpl<TT...> const& tt) const {       size_t seed = 0;       HashValueImpl<tuple<TT...>>::apply(seed, tt);       return seed;     }   };   }  // namespace std   struct wavelet_tree {     int lo = 0, hi = 0;     wavelet_tree *l = 0, *r = 0;     vector<int> b;     wavelet_tree() = default;     ~wavelet_tree() {       if (l) delete l;       if (r) delete r;     }     wavelet_tree(vector<int> A)         : wavelet_tree(begin(A), end(A), *min_element(begin(A), end(A)),                        *max_element(begin(A), end(A))) {}     wavelet_tree(vector<lli> A)         : wavelet_tree(begin(A), end(A), *min_element(begin(A), end(A)),                        *max_element(begin(A), end(A))) {}     template <typename IT>     wavelet_tree(IT from, IT to, int lo_, int hi_) {       lo = lo_;       hi = hi_;       int mi = lo + (hi - lo) / 2;       auto f = [&](int x) { return x <= mi; };       b.reserve(distance(from, to) + 1);       b.push_back(0);       for (auto it = from; it != to; ++it) b.push_back(b.back() + f(*it));       auto mit = stable_partition(from, to, f);       if (lo == hi || from == to) return;       l = new wavelet_tree(from, mit, lo, mi);       r = new wavelet_tree(mit, to, mi + 1, hi);     }     void swap(int i, int si, int sj) {       if (si == sj) return;       if (lo == hi) {         return;         assert(0);       } else {         int mi = lo + (hi - lo) / 2;         if (si <= mi && sj <= mi) {           l->swap(b[i], si, sj);         } else if (si > mi && sj > mi) {           r->swap(i - b[i], si, sj);         } else if (si <= mi) {           b[i + 1] -= 1;         } else {           b[i + 1] += 1;         }       }     }     int kth(int l, int r, int k) {       assert(l <= r);       assert(k < r - l + 1);       if (lo == hi) return lo;       int inleft = b[r + 1] - b[l];       if (k < inleft)         return this->l->kth(b[l], b[r + 1] - 1, k);       else         return this->r->kth(l - b[l], r - b[r + 1], k - inleft);     }     int cnt(int l, int r, int y) {       if (l > r) return 0;       if (lo == hi) {         if (lo == y) {           return b[r + 1] - b[l];         } else {           return 0;         }       } else {         int mi = lo + (hi - lo) / 2;         if (y <= mi) {           return this->l->cnt(b[l], b[r + 1] - 1, y);         } else {           return this->r->cnt(l - b[l], r - b[r + 1], y);         }       }     }     int allR(int l, int r) {       if (l > r) return 0;       return r - l + 1;     }     int cntR(int l, int r, int y) {       if (l > r) return 0;       if (hi <= y) return r - l + 1;       if (y < lo) return 0;       int mi = lo + (hi - lo) / 2;       if (y <= mi) {         return this->l->cntR(b[l], b[r + 1] - 1, y);       } else {         return this->l->allR(b[l], b[r + 1] - 1) +                this->r->cntR(l - b[l], r - b[r + 1], y);       }     }   };   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, q;     cin >> n >> q;     map<int, map<int, int>> data;     vi ps;     for (lli i = 0; i < (lli)(n); ++i) {       int p;       cin >> p;       ps.push_back(p - 1);     }     wavelet_tree wt(ps);     auto q0 = [&](int x, int y) -> int {       if (x < 0 || y < 0) return 0;       return wt.cntR(0, x, y);     };     auto query = [&](int x1, int y1, int x2, int y2) -> int {       if (x2 < x1) return 0;       if (y2 < y1) return 0;       return wt.cntR(x1, x2, y2) - (y1 == 0 ? 0 : wt.cntR(x1, x2, y1 - 1));     };     set<tpl<int, int, int, int>> ss;     for (lli i = 0; i < (lli)(3); ++i)       for (lli j = 0; j < (lli)(3); ++j)         for (lli i2 = 0; i2 < (lli)(3); ++i2)           for (lli j2 = 0; j2 < (lli)(3); ++j2)             if (make_tuple(i, j) != make_tuple(i2, j2)) {               if ((i <= 1 && 1 <= i2) || (i2 <= 1 && 1 <= i)) {                 if ((j <= 1 && 1 <= j2)) {                   if (!ss.count(make_tuple(i2, j2, i, j)))                     ss.insert(make_tuple(i, j, i2, j2));                 }               }             }     for (lli q_ = 0; q_ < (lli)(q); ++q_) {       int x1, y1, x2, y2;       cin >> x1 >> y1 >> x2 >> y2;       --x1;       --y1;       --x2;       --y2;       int T[3][3] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};       for (lli i = 0; i < (lli)(3); ++i) {         for (lli j = 0; j < (lli)(3); ++j) {           int a, b, c, d;           if (i == 0) {             a = 0;             b = x1 - 1;           }           if (i == 1) {             a = x1;             b = x2;           }           if (i == 2) {             a = x2 + 1;             b = n - 1;           }           if (j == 0) {             c = 0;             d = y1 - 1;           }           if (j == 1) {             c = y1;             d = y2;           }           if (j == 2) {             c = y2 + 1;             d = n - 1;           }           T[i][j] = query(a, c, b, d);         }       }       lli inside = T[1][1];       lli ans = (inside * (inside - 1)) / 2;       for (auto s : ss) {         int i, j, i2, j2;         tie(i, j, i2, j2) = s;         ans += (lli)((lli)T[i][j] * (lli)T[i2][j2]);       }       cout << ans <<   n ;     }     cout << flush;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int t;     cin >> t;     while (t--) {       int n, g[105], sum = 0, s = 0;       cin >> n;       for (register int i = 0; i < n; i++)         cin >> g[i], g[i] == 0 ? sum++, g[i]++ : 0, s += g[i];       if (s == 0) sum++;       cout << sum << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     int setb = 0;     int t[1000][1000];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> t[i][j];       }     }     int q;     cin >> q;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         setb += t[i][j] * t[j][i];       }     }     bool anss = setb % 2;     while (q--) {       char c;       cin >> c;       if (c ==  1 ) {         int idx;         cin >> idx;         anss ^= 1;       } else if (c ==  2 ) {         int idx;         cin >> idx;         anss ^= 1;       } else {         cout << anss;       }     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   stack<int> stk;   vector<pair<int, int> > edge[500010];   vector<pair<int, int> > w[500010];   int a[500010], b[500010], c[500010], fa[500010], rk[500010];   bool ans[500010];   int n, m, q;   int Find(int x) {     while (x != fa[x]) x = fa[x];     return x;   }   void Union(int x, int y, bool flag) {     x = Find(x);     y = Find(y);     if (rk[x] < rk[y]) swap(x, y);     if (flag) stk.push(y);     fa[y] = x;     if (rk[x] == rk[y]) ++rk[x];   }   void undo() {     while (!stk.empty()) {       fa[stk.top()] = stk.top();       stk.pop();     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) fa[i] = i;     for (int i = 1; i <= m; ++i) {       scanf( %d%d%d , &a[i], &b[i], &c[i]);       edge[c[i]].push_back(make_pair(a[i], b[i]));     }     scanf( %d , &q);     for (int i = 1; i <= q; ++i) {       int k;       scanf( %d , &k);       while (k--) {         int x;         scanf( %d , &x);         w[c[x]].push_back(make_pair(i, x));       }       ans[i] = true;     }     for (int i = 1; i < 500010; ++i) {       int last = -1;       for (auto &j : w[i])         if (ans[j.first]) {           int o = j.first, k = j.second;           if (o != last) undo(), last = o;           int x = a[k], y = b[k];           if (Find(x) == Find(y))             ans[o] = false;           else             Union(x, y, true);         }       undo();       for (auto &j : edge[i])         if (Find(j.first) != Find(j.second)) Union(j.first, j.second, false);     }     for (int i = 1; i <= q; ++i) puts(ans[i] ?  YES  :  NO );   }


#include <bits/stdc++.h>   using namespace std;   char board[3][3];   int cross, nought;   bool cross_win() {     if (board[0][0] ==  X  && board[0][1] ==  X  && board[0][2] ==  X )       return true;     if (board[1][0] ==  X  && board[1][1] ==  X  && board[1][2] ==  X )       return true;     if (board[2][0] ==  X  && board[2][1] ==  X  && board[2][2] ==  X )       return true;     if (board[0][0] ==  X  && board[1][0] ==  X  && board[2][0] ==  X )       return true;     if (board[0][1] ==  X  && board[1][1] ==  X  && board[2][1] ==  X )       return true;     if (board[0][2] ==  X  && board[1][2] ==  X  && board[2][2] ==  X )       return true;     if (board[0][0] ==  X  && board[1][1] ==  X  && board[2][2] ==  X )       return true;     if (board[0][2] ==  X  && board[1][1] ==  X  && board[2][0] ==  X )       return true;     return false;   }   bool nought_win() {     if (board[0][0] ==  0  && board[0][1] ==  0  && board[0][2] ==  0 )       return true;     if (board[1][0] ==  0  && board[1][1] ==  0  && board[1][2] ==  0 )       return true;     if (board[2][0] ==  0  && board[2][1] ==  0  && board[2][2] ==  0 )       return true;     if (board[0][0] ==  0  && board[1][0] ==  0  && board[2][0] ==  0 )       return true;     if (board[0][1] ==  0  && board[1][1] ==  0  && board[2][1] ==  0 )       return true;     if (board[0][2] ==  0  && board[1][2] ==  0  && board[2][2] ==  0 )       return true;     if (board[0][0] ==  0  && board[1][1] ==  0  && board[2][2] ==  0 )       return true;     if (board[0][2] ==  0  && board[1][1] ==  0  && board[2][0] ==  0 )       return true;     return false;   }   int main() {     for (int i = 0; i < 3; i++)       for (int j = 0; j < 3; j++) {         cin >> board[i][j];         if (board[i][j] ==  X ) cross++;         if (board[i][j] ==  0 ) nought++;       }     if (cross - nought > 1 || nought > cross) {       printf( illegal );       return 0;     }     if (cross_win()) {       if (nought >= cross)         printf( illegal );       else         printf( the first player won );       return 0;     }     if (nought_win()) {       if (cross > nought)         printf( illegal );       else         printf( the second player won );       return 0;     }     if (cross + nought == 9) {       printf( draw );       return 0;     }     if (cross - nought == 1) {       printf( second );       return 0;     }     if (cross == nought) {       printf( first );       return 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double a, d, l, e;   int n;   int main() {     scanf( %lf %lf , &a, &d);     scanf( %d , &n);     l = n * d + .5;     e = d;     double pos = 0, fa = 4 * a;     for (int i = 0; i < n; i++) {       pos = fmod(pos + e, fa);       if (pos <= a)         printf( %.10lf %.10lf n , pos, 0.);       else if (pos <= 2 * a)         printf( %.10lf %.10lf n , a, pos - a);       else if (pos <= 3 * a)         printf( %.10lf %.10lf n , a - (pos - 2 * a), a);       else         printf( %.10lf %.10lf n , 0., a - (pos - 3 * a));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void FAST_IO(string filein =   , string fileout =   , string fileerr =   ) {     if (fopen(filein.c_str(),  r )) {       freopen(filein.c_str(),  r , stdin);       freopen(fileout.c_str(),  w , stdout);     }     cin.tie(0), cout.tie(0)->sync_with_stdio(0);   }   void Hollwo_Pelw();   signed main() {     FAST_IO( hollwo_pelw.inp ,  hollwo_pelw.out );     int testcases = 1;     for (int test = 1; test <= testcases; test++) {       Hollwo_Pelw();     }     return 0;   }   const int N = 14, inf = 2e9;   inline bool smin(int &a, int b) { return a > b ? a = b, 1 : 0; }   int n, m, adj[N][N];   int path[N][N][1 << N], dp[1 << N];   int tr[1 << N], ps[1 << N], pe[1 << N];   void Hollwo_Pelw() {     cin >> n >> m;     for (int i = 0, u, v; i < m; i++)       cin >> u >> v, --u, --v, adj[u][v] = adj[v][u] = 1;     memset(path, -1, sizeof path);     for (int mask = 0; mask < 1 << n; mask++) {       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           if (mask >> i & 1) continue;           if (mask >> j & 1) continue;           if (__builtin_popcount(mask) == 1 && i == j) continue;           if ((i == j || adj[i][j]) && !mask) {             path[i][j][mask] = i;           } else {             for (int k = 0; k < n; k++) {               if ((mask >> k & 1) && path[i][k][mask ^ (1 << k)] >= 0 &&                   adj[k][j]) {                 path[i][j][mask] = k;                 break;               }             }           }         }       }     }     for (int mask = 1; mask < (1 << n); mask++) {       if (__builtin_popcount(mask) == 1) {         dp[mask] = 0;       } else {         dp[mask] = inf;         for (int sub = mask; sub; sub = (sub - 1) & mask) {           int nmask = mask ^ sub;           for (int i = 0; i < n; i++) {             for (int j = 0; j < n; j++) {               if ((nmask >> i & 1) && (nmask >> j & 1) && path[i][j][sub] >= 0) {                 if (smin(dp[mask], dp[nmask] + __builtin_popcount(sub) + 1))                   tr[mask] = sub, ps[mask] = i, pe[mask] = j;               }             }           }         }       }     }     cout << dp[(1 << n) - 1] <<   n ;     int cur = (1 << n) - 1;     while (__builtin_popcount(cur) > 1) {       int nxt = tr[cur], i = ps[cur], j = pe[cur];       cur ^= tr[cur];       do {         int k = path[i][j][nxt];         cout << k + 1 <<     << j + 1 <<   n ;         nxt ^= 1 << k, j = k;       } while (i != j);     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> adj[1000005];   char op[1000005];   bool A[1000005][2], val[1000005];   void dfs(int u) {     if (op[u] ==  I ) return;     dfs(adj[u][0]);     if (op[u] ==  N ) {       val[u] = !val[adj[u][0]];       return;     }     dfs(adj[u][1]);     if (op[u] ==  A )       val[u] = val[adj[u][0]] and val[adj[u][1]];     else if (op[u] ==  O )       val[u] = val[adj[u][0]] or val[adj[u][1]];     else       val[u] = val[adj[u][0]] xor val[adj[u][1]];   }   void dfs2(int u, int p) {     if (u == 1)       A[1][1 - val[1]] = 1 - val[1];     else {       if (op[p] ==  N )         A[u][1 - val[u]] = A[p][val[u]];       else {         int v;         if (adj[p][0] == u)           v = adj[p][1];         else           v = adj[p][0];         if (op[p] ==  A )           A[u][1 - val[u]] = A[p][val[v] and (1 - val[u])];         else if (op[p] ==  O )           A[u][1 - val[u]] = A[p][val[v] or (1 - val[u])];         else           A[u][1 - val[u]] = A[p][val[v] xor (1 - val[u])];       }     }     for (auto x : adj[u]) dfs2(x, u);   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, i, u, v;     string s;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> s;       op[i] = s[0];       if (s ==  AND  or s ==  OR  or s ==  XOR ) {         cin >> u >> v;         adj[i].push_back(u);         adj[i].push_back(v);       } else if (s ==  NOT ) {         cin >> u;         adj[i].push_back(u);       } else {         cin >> u;         val[i] = u;       }     }     dfs(1);     for (i = 1; i <= n; i++) A[i][val[i]] = val[1];     dfs2(1, 0);     for (i = 1; i <= n; i++)       if (op[i] ==  I ) cout << A[i][1 - val[i]];     return 0;   }


#include<bits/stdc++.h>   using namespace std;   int T,n,m,flag,k,a[110],b[110],ans[300];   int main()   {    scanf( %d ,&T);    while (T--) {     scanf( %d%d%d ,&k,&n,&m);     for (int i=1;i<=n;i++) scanf( %d ,&a[i]);     for (int i=1;i<=m;i++) scanf( %d ,&b[i]);     flag=1;     for (int i=1,j=1;i<=n||j<=m;) {      if ((a[i]>k||i>n)&&(b[j]>k||j>m)) {       flag=0;       break;      }      while (a[i]<=k&&i<=n) {       ans[i+j-1]=a[i];       if (a[i]==0) k++;       i++;      }      while (b[j]<=k&&j<=m) {       ans[i+j-1]=b[j];       if (b[j]==0) k++;       j++;      }     }     if (flag) {      for (int i=1;i<=n+m;i++) printf( %d  ,ans[i]);      printf(  n );     } else {      printf( -1 n );     }    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool X[1000001], vis[1000001];   int main() {     int n;     while (scanf( %d , &n) == 1) {       vector<int> V;       int x;       for (int i = 0; i < n; i++) {         scanf( %d , &x);         X[x] = true;         V.push_back(x);       }       deque<int> Q;       for (int i = 1; i < 1000001; i++)         if (!X[i] && !X[1000001 - i]) Q.push_front(i), Q.push_back(1000001 - i);       printf( %d n , n);       for (int i = 0; i < V.size(); i++) {         if (vis[V[i]]) continue;         if (!X[1000001 - V[i]])           printf( %d n , 1000001 - V[i]);         else {           printf( %d %d n , Q.front(), Q.back());           vis[1000001 - V[i]] = true;           Q.pop_front();           Q.pop_back();         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int a[100001], parent[100001], sz[100001], p[(100001 / 320 + 1)],       mx[(100001 / 320 + 1)], h[(100001 / 320 + 1)][100001];   bool isBlockDirty[(100001 / 320 + 1)];   int Find(int i) {     if (i == parent[i])       return i;     else {       parent[i] = Find(parent[i]);       return parent[i];     }   }   void Move(int k, int s, int d) {     int h1 = h[k][s], h2 = h[k][d];     h[k][s] = -1;     if (h1 == -1) return;     if (h2 == -1) {       a[h1] += (d - s);       h[k][d] = h1;     } else {       parent[h1] = h2;       sz[h2] += sz[h1];     }   }   void Print(int n) {     for (int i = 0; i < n; ++i) {       int j = Find(i);       int k = i / 320;       printf( %d %d %d %d %d %d n , i, j, a[j], p[k], mx[k], a[j] + p[k]);     }     printf(  n n );   }   void DestroyBlockDSU(int k) {     if (isBlockDirty[k]) return;     for (int l = k * 320, r = min(l + 320, 100001), i = l; i < r; ++i) {       int j = Find(i);       a[i] = a[j];       h[k][a[i]] = -1;     }     for (int l = k * 320, r = min(l + 320, 100001), i = l; i < r; ++i) {       a[i] += p[k];       parent[i] = i;       sz[i] = 1;     }     mx[k] = 0;     p[k] = 0;     isBlockDirty[k] = 1;   }   void BuildBlockDSU(int k) {     mx[k] = 0;     p[k] = 0;     for (int l = k * 320, r = min(l + 320, 100001), i = l; i < r; ++i) {       if (h[k][a[i]] == -1)         h[k][a[i]] = i;       else {         int j = h[k][a[i]];         parent[i] = j;         ++sz[j];       }       mx[k] = max(mx[k], a[i]);     }     isBlockDirty[k] = 0;   }   void PreProcess(int n) {     for (int i = 0; i < (100001 / 320 + 1); ++i)       for (int j = 0; j < 100001; ++j) h[i][j] = -1;     for (int k = 0; k * 320 < n; ++k) isBlockDirty[k] = 1;     for (int i = 0; i < n; ++i) {       parent[i] = i;       sz[i] = 1;     }   }   void UpdateInBlock(int k, int l, int r, int x) {     DestroyBlockDSU(k);     for (int i = l; i <= r; ++i) {       if (a[i] > x) a[i] -= x;     }   }   void UpdateBlock(int k, int x) {     if (isBlockDirty[k]) BuildBlockDSU(k);     if (x >= mx[k]) return;     if (2 * x < mx[k]) {       for (int l = 1 - p[k], r = x - p[k], i = l; i <= r; ++i) Move(k, i, i + x);       p[k] -= x;       mx[k] -= x;     } else {       for (int l = x + 1 - p[k], r = mx[k] - p[k], i = l; i <= r; ++i)         Move(k, i, i - x);       int _mx = x - p[k];       for (; h[k][_mx] == -1; --_mx)         ;       mx[k] = _mx + p[k];     }   }   void Update(int l, int r, int x) {     int lk = l / 320, rk = r / 320;     if (lk == rk)       UpdateInBlock(lk, l, r, x);     else {       for (int k = lk; k <= rk; ++k) {         int i = max(k * 320, l), j = min((k + 1) * 320 - 1, r);         if (j - i + 1 < 320)           UpdateInBlock(k, i, j, x);         else           UpdateBlock(k, x);       }     }   }   int QueryInBlock(int k, int l, int r, int x) {     int ans = 0;     for (int i = l; i <= r; ++i) {       int j = Find(i);       ans += (a[j] + p[k] == x);     }     return ans;   }   int QueryBlock(int k, int x) {     if (x - p[k] >= 100001) return 0;     if (isBlockDirty[k]) BuildBlockDSU(k);     int i = h[k][x - p[k]];     if (i == -1) return 0;     int ans = sz[i];     return ans;   }   int Query(int l, int r, int x) {     int lk = l / 320, rk = r / 320;     if (lk == rk)       return QueryInBlock(lk, l, r, x);     else {       int ans = 0;       for (int k = lk; k <= rk; ++k) {         int i = max(k * 320, l), j = min((k + 1) * 320 - 1, r);         if (j - i + 1 < 320)           ans += QueryInBlock(k, i, j, x);         else           ans += QueryBlock(k, x);       }       return ans;     }   }   int main() {     int n, q;     scanf( %d%d , &n, &q);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     PreProcess(n);     while (q--) {       int t, l, r, x;       scanf( %d%d%d%d , &t, &l, &r, &x);       --l, --r;       if (t == 1) {         Update(l, r, x);       } else         printf( %d n , Query(l, r, x));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, h, m, k;   vector<long long int> freight;   int workingTrains(long long int time) {     if (time - k >= 0) {       return n - (lower_bound(freight.begin(), freight.end(), time) -                   upper_bound(freight.begin(), freight.end(), time - k));     } else {       return upper_bound(freight.begin(), freight.end(),                          (time - k + m / 2) % (m / 2)) -              lower_bound(freight.begin(), freight.end(), time);     }   }   void solve(int test_index) {     cin >> n >> h >> m >> k;     freight.resize(n);     vector<long long int> raw(n);     for (int i = 0; i < n; i++) {       long long int hh, mm;       cin >> hh >> mm;       freight[i] = (hh * m + mm) % (m / 2);       raw[i] = freight[i];     }     sort(freight.begin(), freight.end());     long long int t = freight[0], works = workingTrains(freight[0]);     for (int time : freight) {       long long int w = workingTrains(time);       if (works < w) {         works = w;         t = time;       }     }     cout << n - works <<     << t <<   n ;     for (int i = 0; i < n; i++) {       if (t - k < 0) {         if (raw[i] < t || raw[i] > (t - k + m / 2) % (m / 2)) {           cout << i + 1 <<    ;         }       } else {         if (raw[i] > t - k && raw[i] < t) {           cout << i + 1 <<    ;         }       }     }     cout <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int num_tests = 1;     for (int test_index = 1; test_index <= num_tests; test_index++) {       solve(test_index);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void optimizeIO() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   int main() {     optimizeIO();     int n, t;     cin >> n >> t;     string s1, s2, s3;     cin >> s1 >> s2;     s3 = s1;     int sa = 0;     vector<int> v, v2;     for (typeof(n) i = 0; i < n; i++) {       if (s1[i] == s2[i]) {         sa++;         v.push_back(i);       } else         v2.push_back(i);     }     if (n - sa < 2 * (n - t - sa))       cout <<  -1 n ;     else {       if ((n - t) < sa) {         int i1 = 0, i2 = 0;         int dd = n - t;         for (typeof(n) i = 0; i < n; i++) {           if (v[i1] == i && dd) {             s3[i] = s1[i];             dd--;             i1++;           } else {             if (abs(s1[i] - s2[i]) > 1) {               s3[i] = min(s1[i], s2[i]) + 1;             } else {               if (max(s1[i], s2[i]) ==  z )                 s3[i] =  a ;               else                 s3[i] =  z ;             }           }         }       } else {         int i1 = 0;         int dd = n - t, c = 0;         int d1 = n - t - sa, d2 = n - t - sa;         for (typeof(n) i = 0; i < n; i++) {           if (i1 < int((v).size())) {             if (v[i1] == i) {               s3[i] = s1[i];               i1++;               continue;             }           }           if (d1) {             s3[i] = s1[i];             d1--;             continue;           }           if (d2) {             s3[i] = s2[i];             d2--;             continue;           }           if (d1 == 0 && d2 == 0) {             if (abs(s1[i] - s2[i]) > 1) {               s3[i] = min(s1[i], s2[i]) + 1;             } else {               if (max(s1[i], s2[i]) ==  z )                 s3[i] =  a ;               else                 s3[i] =  z ;             }           }         }       }       cout << s3 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100100;   const int BIT = 17;   int n, m;   int P[N];   int pot2[33];   set<int> S[18];   set<int>::iterator it;   long long sol;   inline int find(int bit, int pos) {     if (S[bit].empty()) return 0;     it = S[bit].lower_bound(pos);     if (it == S[bit].begin()) return 0;     it--;     return *it + 1;   }   inline int find2(int bit, int pos) {     if (S[bit].empty()) return n - 1;     it = S[bit].lower_bound(pos);     if (it == S[bit].end()) return n - 1;     return *it - 1;   }   inline void load() {     pot2[0] = 1;     for (int i = 1; i <= BIT; i++) pot2[i] = (pot2[i - 1] << 1);     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &P[i]);       x = P[i];       for (int j = BIT; j >= 0; j--) {         if (x & (1 << j)) {           sol += (long long)pot2[j] * (i - find(j, i) + 1);         } else           S[j].insert(i);       }     }   }   inline void print() {     printf( SADRZAJ NA MJESTU == %d n , 1);     for (set<int>::iterator it = S[0].begin(); it != S[0].end(); it++) {       printf( %d  , *it);     }     printf(  n );     system( pause );   }   inline void solve() {     for (; m; m--) {       int pos, val;       scanf( %d %d , &pos, &val);       pos--;       for (int j = BIT; j >= 0; j--) {         if (val & (1 << j)) {           if ((P[pos] & (1 << j)) == 0) {             S[j].erase(pos);             sol += (long long)pot2[j] * (pos - find(j, pos) + 1) *                    (find2(j, pos) - pos + 1);           }         } else {           if ((P[pos] & (1 << j))) {             int gore = pos - find(j, pos) + 1;             int dole = find2(j, pos) - pos;             sol -= (long long)pot2[j] * dole * gore;             sol -= (long long)pot2[j] * gore;             S[j].insert(pos);           }         }       }       P[pos] = val;       cout << sol << endl;     }   }   int main(void) {     load();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 65536 + 10;   int n, deg[Maxn], s[Maxn];   vector<pair<int, int> > ans;   set<pair<int, int> > mys;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d%d , &deg[i], &s[i]);       mys.insert(make_pair(deg[i], i));     }     while (!mys.empty()) {       pair<int, int> p = *mys.begin();       mys.erase(p);       if (p.first > 0) {         ans.push_back(make_pair(p.second, s[p.second]));         mys.erase(make_pair(deg[s[p.second]], s[p.second]));         deg[s[p.second]]--;         s[s[p.second]] ^= p.second;         mys.insert(make_pair(deg[s[p.second]], s[p.second]));       }     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++)       printf( %d %d  n , ans[i].first, ans[i].second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   const double eps = 1e-10;   int main() {     int n;     scanf( %d , &n);     int feet, inches;     inches = n / 3;     if (n - inches * 3 > 1) inches++;     feet = inches / 12;     inches %= 12;     cout << feet <<     << inches << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005, mod = 1e9 + 7, M = 100;   int n, m, k;   int q[N][6], a[N][6], r[6], f[6], e[6];   inline void inq(int id, int x) {     while (f[id] <= e[id] && a[x][id] >= a[q[e[id]][id]][id]) e[id]--;     q[++e[id]][id] = x;   }   inline void outq(int id, int x) {     if (q[f[id]][id] <= x) f[id]++;   }   inline int jug() {     int sum = 0;     for (int i = 1; i <= m; i++) {       sum += a[q[f[i]][i]][i];     }     return sum > k;   }   inline int read() {     int x = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x;   }   int main() {     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         a[i][j] = read();       }     }     for (int i = 1; i <= m; i++) f[i] = 0, e[i] = -1;     int res = 0;     int pre = 1;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         inq(j, i);       }       while (pre <= i && jug()) {         for (int j = 1; j <= m; j++) outq(j, pre);         pre++;       }       if (res < i - pre + 1) {         res = i - pre + 1;         for (int j = 1; j <= m; j++) r[j] = a[q[f[j]][j]][j];       }     }     for (int i = 1; i <= m; i++) {       cout << r[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1555;   const int dx[4] = {0, 0, 1, -1};   const int dy[4] = {1, -1, 0, 0};   int n, m;   template <typename T>   inline T mod(const T& lhs, const T& rhs) {     T _lhs = lhs;     while (_lhs < 0) {       _lhs += rhs;     }     return _lhs % rhs;   }   char gra[MAXN][MAXN];   bool used[MAXN][MAXN];   pair<int, int> visited[MAXN][MAXN];   queue<pair<int, int> > Q;   bool bfs(int x, int y) {     pair<int, int> now(x, y);     Q.push(now);     visited[now.first][now.second] = now;     used[x][y] = 1;     while (!Q.empty()) {       now = Q.front();       Q.pop();       for (int i = 0; i < 4; i++) {         int tx = dx[i] + now.first, ty = dy[i] + now.second;         int rx = mod(tx, n), ry = mod(ty, m);         if (gra[rx][ry] ==  # ) {           continue;         }         if (!used[rx][ry]) {           used[rx][ry] = 1;           Q.push(pair<int, int>(tx, ty));           visited[rx][ry] = pair<int, int>(tx, ty);         } else {           if (visited[rx][ry].first != tx || visited[rx][ry].second != ty) {             return true;           }         }       }     }     return false;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %s , gra[i]);     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (gra[i][j] ==  S ) {           if (bfs(i, j)) {             puts( Yes );           } else {             puts( No );           }           return 0;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T MAX(T a, T b) {     return a > b ? a : b;   }   template <class T>   T MIN(T a, T b) {     return a < b ? a : b;   }   template <class T1>   void deb(T1 p) {     cout <<  Debugging:   << p << endl;   }   template <class T1, class T2>   void deb(T1 p, T2 q) {     cout <<  Debugging:   << p <<   t  << q << endl;   }   template <class T1, class T2, class T3>   void deb(T1 p, T2 q, T3 r) {     cout <<  Debugging:   << p <<   t   << q <<   t   << r << endl;   }   template <class T1, class T2, class T3, class T4>   void deb(T1 p, T2 q, T3 r, T4 s) {     cout <<  Debugging:   << p <<   t   << q <<   t   << r <<   t   << s << endl;   }   long long int POOW(int b, int p) {     if (p == 0) return 1;     return b * POOW(b, p - 1);   }   const int xx[] = {0, 0, 1, -1, -1, 1, -1, 1};   const int yy[] = {1, -1, 0, 0, 1, 1, -1, -1};   const int kx[] = {-2, -1, 1, 2, 2, 1, -1, -2};   const int ky[] = {1, 2, 2, 1, -1, -2, -2, -1};   int main() {     char mat[105][105];     int i, j, m, sum, res = 0, ar[105], n, k;     scanf( %d , &n);     getchar();     for (i = 0; i < n; i++) gets(mat[i]);     res = sum = 0;     for (i = 0; i < n; i++) {       sum = 0;       for (j = 0; j < n; j++) {         for (k = 0; k < n; k++) {           if (mat[i][k] == mat[j][k])             ;           else {             break;           }         }         if (k == n) sum++;       }       res = max(res, sum);     }     sum = 0;     for (i = 0; i < n; i++) {       for (j = k = 0; j < n; j++) {         if (mat[i][j] ==  1 ) ++k;       }       if (k == n) sum++;     }     if (res == 0) res = max(res, sum);     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( inline , 2)   using namespace std;   const long long N = 5005;   const long long inf = 1e18;   long long n, hd[N], nxt[N << 1], to[N << 1], w[N << 1], tot = 1;   long long sz[N << 1];   long long aa[N << 1], eg[N << 1];   void add(long long a, long long b, long long c) {     nxt[++tot] = hd[a], to[tot] = b, w[tot] = c;     hd[a] = tot;   }   long long dfs1(long long u, long long fe, long long d) {     long long re = d;     for (long long i = hd[u]; i; i = nxt[i])       if (i != fe) re += dfs1(to[i], i ^ 1, d + w[i]);     return eg[fe] = re;   }   long long dfs2(long long u, long long fe) {     long long re = 1;     for (long long i = hd[u]; i; i = nxt[i])       if (i != fe) re += dfs2(to[i], i ^ 1);     sz[fe ^ 1] = n - re;     return sz[fe] = re;   }   void solve(long long rt) {     memset(eg, 0, sizeof eg);     long long sum = dfs1(rt, 0, 0);     for (long long i = 2; i <= tot; ++i) aa[i] = min(aa[i], sum - eg[i]);   }   long long zz[N];   long long wi[N], wo[N], bb[N << 1];   void dfs3(long long u, long long fe) {     zz[u] = 1;     wi[u] = 0, wo[u] = 0;     for (long long i = hd[u]; i; i = nxt[i])       if (i != fe) {         dfs3(to[i], i ^ 1);         zz[u] += zz[to[i]];         wi[u] += wi[to[i]];         wo[u] += wo[to[i]] + zz[to[i]] * w[i];         wi[u] -= (wo[to[i]] + zz[to[i]] * w[i]) * zz[to[i]];       }     wi[u] += wo[u] * zz[u];     bb[fe] = wi[u];   }   signed main() {     memset(aa, 0x3f, sizeof aa);     cin >> n;     for (long long i = 1; i <= n - 1; ++i) {       long long x, y, z;       cin >> x >> y >> z;       add(x, y, z);       add(y, x, z);     }     for (long long i = 1; i <= n; ++i) dfs3(i, 0);     for (long long i = 1; i <= n; ++i) solve(i);     dfs2(1, 0);     long long ans = 1e18;     for (long long i = 1; i <= n - 1; ++i) {       long long r = i << 1, s = i << 1 | 1;       ans = min(ans, 1LL * w[r] * sz[r] * sz[s] + aa[r] * sz[r] + aa[s] * sz[s] +                          bb[r] + bb[s]);     }     cout << ans << endl;   }


#include <iostream>   #include <algorithm>   using namespace std;   typedef long long ll;   const ll mod = 1e9+7;   const int SZ = 1e5+10;      ll fact[SZ];   void buildFact(){       fact[0] = 1;       for(int i = 1; i < SZ; i++){           fact[i] = fact[i-1] * i;           fact[i] %= mod;       }   }      ll powe(ll x, ll p){       ll ans = 1;       for(; p > 0; x = (x*x)%mod, p >>= 1){           if (p&1){ ans *= x; ans %= mod; }       }       return ans;   }      ll modinv(ll n){       return powe(n, mod-2);   }      ll choose(ll n, ll k){       if (k > n){ return 0; }              ll ans = fact[n];       ll den = fact[n-k] * fact[k]; den %= mod;       ans *= modinv(den); ans %= mod;              return ans;   }      int main(){       buildFact();              int t; cin >> t;       while (t--){           int n, k; cin >> n >> k;           ll ans = 1;                      for(ll p = 1; n-(k-1)*(p-1) >= p-1; p++){               ans += choose(n-(k-1)*(p-1), p) * modinv(choose(n, p));               ans %= mod;           }                      cout << ans <<   n ;       }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long N, P;     cin >> N >> P;     vector<long long> l(N), r(N);     for (long long i = 0; i < N; ++i) cin >> l[i] >> r[i];     double exp_val = 0;     for (long long i = 0; i < N; ++i) {       long long j = (i + 1) % N;       double tot = (r[i] - l[i] + 1) * (r[j] - l[j] + 1);       double a = floor(((double)r[i]) / P);       double b = ceil(((double)l[i]) / P);       double c = a - b + 1;       double e = floor(((double)r[j]) / P);       double f = ceil(((double)l[j]) / P);       double g = e - f + 1;       double good = (c * (r[j] - l[j] + 1)) + (g * (r[i] - l[i] + 1)) - c * g;       exp_val += good * 2000 / tot;     }     cout << fixed << setprecision(9) << exp_val << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   int a[100010], b[100010];   int main() {     int n, k, m;     scanf( %d%d , &n, &k);     int val = 1;     for (int i = 0; i < k; i++) val *= 10;     m = n / k;     for (int i = 0; i < m; i++) scanf( %d , &a[i]);     for (int i = 0; i < m; i++) scanf( %d , &b[i]);     long long ans = 1;     for (int i = 0; i < m; i++) {       int t = (val - (val % a[i])) / a[i];       if (val % a[i]) t++;       int num = (a[i] - (val / 10 * b[i]) % a[i]) % a[i];       if ((val / 10) <= num) {         ans = ans * t % mod;         continue;       }       int tt = ((val / 10 - num) - ((val / 10 - num) % a[i])) / a[i];       if ((val / 10 - num) % a[i]) tt++;       ans = ans * (t - tt) % mod;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, s, i, a, b, t, j, v, f, c;     int candy = -1, d;     scanf( %d%d , &n, &s);     s = s * 100;     while (n--) {       scanf( %d%d , &a, &b);       d = (a * 100) + b;       if (d <= s) {         f = s - d;         c = f % 100;         if (c > candy) candy = c;       }     }     if (c != -1)       printf( %d , candy);     else       printf( -1 );   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 3;   const int M = 26;   char s1[N], s2[N];   int z1[N][M], z2[N][M];   int n;   bool check(int l1, int r1, int l2, int r2) {     int l, i, t1, t2;     for (i = 0; i < M; ++i) {       t1 = z1[r1 - 1][i];       if (l1) t1 -= z1[l1 - 1][i];       t2 = z2[r2 - 1][i];       if (l2) t2 -= z2[l2 - 1][i];       if (t1 != t2) return false;     }     l = r1 - l1;     if (l & 1) {       for (i = 0; i < l; ++i)         if (s1[l1 + i] != s2[l2 + i]) return false;       return true;     }     l >>= 1;     if (check(l1, l1 + l, l2, l2 + l) && check(l1 + l, r1, l2 + l, r2))       return true;     if (check(l1, l1 + l, l2 + l, r2) && check(l1 + l, r1, l2, l2 + l))       return true;     return false;   }   int main() {     if (0) {       freopen( input.txt ,  w , stdout);       int n, i;       n = 8192;       for (i = 0; i < n; ++i) printf( a );       printf(  n );       for (i = 0; i < n; ++i) printf( a );       printf(  n );       return 0;     }     int i, j;     scanf( %s , s1);     scanf( %s , s2);     n = strlen(s1);     ++z1[0][s1[0] -  a ];     ++z2[0][s2[0] -  a ];     for (i = 1; i < n; ++i) {       for (j = 0; j < M; ++j) z1[i][j] += z1[i - 1][j], z2[i][j] += z2[i - 1][j];       ++z1[i][s1[i] -  a ];       ++z2[i][s2[i] -  a ];     }     printf( %s n , (check(0, n, 0, n)) ?  YES  :  NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 1e6 + 5;   int dp[N][2];   int main() {     int n, x;     scanf( %d , &n);     dp[0][0] = dp[0][1] = 1;     for (int i = 1; i <= n; ++i) {       scanf( %d , &x);       for (int j = 1; j * j <= x; ++j) {         if (x % j) continue;         dp[j][1] = (dp[j][1] + dp[j - 1][0]) % mod;         if (j * j != x) dp[x / j][1] = (dp[x / j][1] + dp[x / j - 1][0]) % mod;       }       for (int j = 1; j * j <= x; ++j) {         if (x % j) continue;         dp[j][0] = dp[j][1] % mod;         if (j * j != x) dp[x / j][0] = dp[x / j][1] % mod;       }     }     int sum = 0;     for (int i = 1; i <= n; ++i) {       sum = sum + dp[i][0];       sum %= mod;     }     printf( %d n , sum);   }


#include <bits/stdc++.h>   using namespace std;   int n, ans[110];   int main() {     scanf( %d , &n);     for (int i = n; i > 0; i--) {       printf( ?  );       for (int j = 1; j < n; j++) printf( 1  );       printf( %d n , i);       fflush(stdout);       int k;       scanf( %d , &k);       if (k) {         ans[n] = n - i + 1;         ans[k] = n;         break;       }     }     if (!ans[n]) ans[n] = n;     for (int i = ans[n] + 1; i <= n; i++) {       printf( ?  );       for (int j = 1; j < n; j++) printf( 1  );       printf( %d n , i - ans[n] + 1);       fflush(stdout);       int k;       scanf( %d , &k);       ans[k] = i;     }     for (int i = 1; i < ans[n]; i++) {       printf( ?  );       for (int j = 1; j < n; j++) printf( %d  , ans[n] - i + 1);       printf( 1 n );       fflush(stdout);       int k;       scanf( %d , &k);       ans[k] = i;     }     printf( !  );     for (int i = 1; i <= n; i++) printf( %d  , ans[i]);     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     bool o[100];     int n, k1, k2;     int a[100];     int b[100];     for (int j = 0; j < t; j++) {       cin >> n >> k1 >> k2;       for (int i = 0; i < k1; i++) cin >> a[i];       for (int i = 0; i < k2; i++) cin >> b[i];       o[j] = 0;       for (int i = 0; i < k1; i++)         if (a[i] == n) o[j] = 1;     }     for (int j = 0; j < t; j++) {       if (o[j])         cout <<  YES n ;       else         cout <<  NO n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7, N = 3e5 + 7, M = 998244353;   vector<int> G[N], add[N], del[N];   long long f[N], fi[N], inv[N];   int cans[41], dp[1 << 20][21];   int C(int n, int k) { return f[n] * fi[k] % M * fi[n - k] % M; }   void ADD(int& a, int b) {     a += b;     if (a >= M) a -= M;   }   signed main() {     std::ios::sync_with_stdio(0);     std::cin.tie(0);     ;     f[0] = 1;     for (int i = 1; i < N; i++) f[i] = f[i - 1] * i % M;     inv[1] = 1;     for (int i = 2; i < N; i++) inv[i] = M - M / i * inv[M % i] % M;     fi[0] = 1;     for (int i = 1; i < N; i++) fi[i] = fi[i - 1] * inv[i] % M;     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       int l, r;       cin >> l >> r;       add[l].push_back(i);       del[r + 1].push_back(i);     }     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       G[u].push_back(i);       G[v].push_back(i);     }     long long ans = 0, cnt = 0, cnt1 = 0;     dp[0][0] = cans[0] = 1;     for (int i = 1; i <= n; i++) {       bool change = false;       for (int j : add[i]) {         if (G[j].size()) {           int mask = 0;           for (int k : G[j]) mask |= 1 << k;           for (int k = 0; k < (1 << m); k++)             for (int l = 1; l <= 20; l++)               if ((k & mask) == mask) ADD(dp[k][l], dp[k ^ mask][l - 1]);           change = true;           cnt1++;         } else           cnt++;       }       for (int j : del[i]) {         if (G[j].size()) {           int mask = 0;           for (int k : G[j]) mask |= 1 << k;           for (int k = 0; k < (1 << m); k++)             for (int l = 1; l <= 20; l++)               if ((k & mask) == mask)                 ADD(dp[k][l],                     M - (dp[k ^ mask][l - 1] ? dp[k ^ mask][l - 1] : M));           change = true;           cnt1--;         } else           cnt--;       }       if (change) {         memset(cans, 0, sizeof cans);         for (int mask = 0; mask < (1 << m); mask++)           for (int j = 0; j <= 20; j++) ADD(cans[j], dp[mask][j]);       }       for (int j = 0; j <= cnt1; j++) {         if (i - j < 0 || i - j > cnt) continue;         ans = (ans + (long long)C(cnt, i - j) * cans[j]) % M;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int e[1010][1010];   int main(void) {     int n, a, b;     scanf( %d%d%d , &n, &a, &b);     if (a > 1 && b > 1) {       printf( NO n );       return 0;     }     int x = n - max(a, b) + 1;     if (x <= 0 || ((n == 2 || n == 3) && x == n)) {       printf( NO n );       return 0;     }     printf( YES n );     for (int i = 0; i < x - 1; i++) e[i][i + 1] = e[i + 1][i] = 1;     if (b != 1)       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++)           if (i != j) e[i][j] = 1 - e[i][j];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) printf( %d , e[i][j]);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   const long long INF = 1000000000;   template <class T>   inline void read(T &x) {     char c;     int flag = 1;     while ((c = getchar()) <  0  || c >  9 )       if (c ==  - ) flag *= -1;     x = c -  0 ;     while ((c = getchar()) >=  0  && c <=  9 ) x = x * 10 + c -  0 ;     x *= flag;     return;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, q;     cin >> q;     map<long long, long long> dp;     while (q--) {       long long op, u, v;       cin >> op >> u >> v;       if (op == 1) {         long long w;         cin >> w;         while (u ^ v) {           if (u < v) swap(u, v);           dp[u] += w, u /= 2;         }       } else {         long long ans = 0;         while (u ^ v) {           if (u < v) swap(u, v);           ans += dp[u], u /= 2;         }         cout << ans << endl;       }     }   }


#include <bits/stdc++.h>   int main(int argc, char const *argv[]) {     int T;     scanf( %d , &T);     while (T--) {       int n, m;       scanf( %d%d , &n, &m);       std::vector<short> vertices(3 * n, 0);       std::vector<int> edges;       for (int i = 0; i < m; i++) {         int u, v;         scanf( %d%d , &u, &v);         if (!vertices[u - 1] && !vertices[v - 1]) {           vertices[u - 1] = 1;           vertices[v - 1] = 1;           edges.push_back(i + 1);         }       }       if (edges.size() >= n) {         printf( Matching n );         for (int i = 0; i < n; i++) printf( %d n , edges[i]);       } else {         printf( IndSet n );         for (int i = 0, cnt = 0; i < 3 * n && cnt < n; i++) {           if (!vertices[i]) {             cnt++;             printf( %d n , i + 1);           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int L, R, i;   } q[100001];   bool cmp(node x, node y) {     if (x.L / 555 != y.L / 555) {       return x.L / 555 < y.L / 555;     }     return x.R < y.R;   }   map<int, int> mpp;   int ans = 0, I;   int arr[100000 + 1], ct[100001], arr2[100001];   void add(int p) {     ct[arr2[p]]++;     if (ct[arr2[p]] == arr[p]) {       ans++;     }     if (ct[arr2[p]] == arr[p] + 1) ans--;   }   void rem(int p) {     if (ct[arr2[p]] == arr[p]) ans--;     if (ct[arr2[p]] == arr[p] + 1) ans++;     ct[arr2[p]]--;   }   int main() {     int n, m;     cin >> n >> m;     vector<pair<int, int> > V;     for (int i = 1; i <= n; i++) {       cin >> arr[i];       V.push_back(make_pair(arr[i], i));     }     sort(V.begin(), V.end());     int r = 0;     for (int i = 0; i < V.size(); i++) {       if (i && V[i].first != V[i - 1].first) r++;       arr2[V[i].second] = r;     }     int x, y;     for (int i = 0; i < m; i++) {       cin >> q[i].L >> q[i].R;       q[i].i = i;     }     sort(q, q + m, cmp);     x = q[0].L, y = q[0].R;     for (int i = x; i <= y; i++) {       ct[arr2[i]]++;       if (ct[arr2[i]] == arr[i]) ans++;       if (ct[arr2[i]] == arr[i] + 1) ans--;     }     int out[m];     out[q[0].i] = ans;     for (I = 1; I < m; I++) {       int l = q[I].L, r = q[I].R;       while (x < l) {         rem(x);         x++;       }       while (x > l) {         x--;         add(x);       }       while (y < r) {         y++;         add(y);       }       while (y > r) {         rem(y);         y--;       }       out[q[I].i] = ans;     }     for (int i = 0; i < m; i++) {       cout << out[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-10;   const int inf = 1 << 28;   int in() {     int x;     scanf( %d , &x);     return x;   }   long long In() {     long long x;     cin >> x;     return x;   }   double inreal() {     double x;     scanf( %lf , &x);     return x;   }   string instr() {     char buf[1001];     scanf( %s , buf);     return (string)buf;   }   struct UF {     vector<int> p, r;     UF(int n) {       n++;       p.resize(n, ~0), r.resize(n, 0);     }     int root(int x) { return ~p[x] ? p[x] = root(p[x]) : x; }     bool conn(int x, int y) {       x = root(x), y = root(y);       if (x == y) return 0;       if (r[x] < r[y])         p[x] = y;       else {         p[y] = x;         if (r[x] == r[y]) r[x]++;       }       return 1;     }     bool same(int x, int y) { return root(x) == root(y); }   };   const long long M = 1000000009LL;   long long resget(long long x) {     x = x - 1;     if (x < 0) return M - 1;     return x;   }   int main() {     int i, j, k, n = in(), m = in(), u, v;     UF uf(n);     long long res = 1;     for ((i) = (0); (i) < (int)(m); (i)++) {       u = in() - 1, v = in() - 1;       if (uf.conn(u, v)) {         cout << resget(res) << endl;       } else {         res = res * 2 % M;         cout << resget(res) << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, n, m;   long long a, k, ak;   char c;   unordered_map<long long, bool> ma;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> t;     for (int ti = 1; ti <= t; ++ti) {       ma.clear();       cin >> n >> m;       k = (1ll << m) - n;       for (int i = 1; i <= n; ++i) {         a = 0;         for (int j = m - 1; j >= 0; --j) {           cin >> c;           a |= (c ==  1  ? (1ll << j) : 0ll);         }         ma[a] = 1;       }       a = (k - 1) / 2;       ak = k = a + 1;       for (pair<long long, bool> tw : ma) {         if (tw.first <= a) --ak;       }       while (ak < k) {         if (!ma[++a]) ++ak;       }       for (int i = m - 1; i >= 0; --i) {         cout << (a & (1ll << i) ? 1 : 0);       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool flag;   long long Max = -1e18, tpMax = -1e18, dep[600005], a[600005];   int n, m, sz[600005], In[600005], TOT, LA[600005], NE[600005 << 1],       EN[600005 << 1];   long long LE[600005 << 1];   void Link(int x, int y, int z) {     EN[++TOT] = y;     LE[TOT] = z;     NE[TOT] = LA[x];     LA[x] = TOT;     EN[++TOT] = x;     LE[TOT] = z;     NE[TOT] = LA[y];     LA[y] = TOT;   }   void pre_dfs(int x, int fa) {     if (x == n) In[x] = x;     int i, y;     sz[x] = 1;     long long tp = -1e18, ttp = -1e18;     for (i = LA[x]; i; i = NE[i]) {       y = EN[i];       if (y == fa) continue;       dep[y] = dep[x] + LE[i];       pre_dfs(y, x);       sz[x] += sz[y];       if (In[y])         In[x] = y;       else         a[x] = LE[i];       if (a[y] && In[y]) tp = max(tp, a[y] - dep[y]);       if (In[y]) ttp = max(ttp, a[y] - dep[y]);     }     if (sz[x] - sz[In[x]] > 2) flag = 1;     if (x == n && sz[x] > 2) flag = 1;     if (In[x]) {       Max = max(Max, a[x] + dep[x] + max(tpMax, tp));       if (a[x]) Max = max(Max, a[x] + dep[x] + ttp);       for (i = LA[x]; i; i = NE[i]) {         y = EN[i];         if (y == fa) continue;         if (In[y]) tpMax = max(tpMax, a[y] - dep[y]);       }     }   }   int main() {     int i, j, k, x, y, z;     long long t;     scanf( %d%d , &n, &m);     for (i = 1; i < n; i++) {       scanf( %d%d%d , &x, &y, &z);       Link(x, y, z);     }     pre_dfs(1, 0);     for (i = 1; i <= m; i++) {       scanf( %I64d , &t);       if (flag || t + Max >= 0)         printf( %I64d n , dep[n]);       else         printf( %I64d n , dep[n] + t + Max);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void pfill(T* pst, const T* ped, T val) {     for (; pst != ped; *(pst++) = val)       ;   }   const double pi = acos(-1);   const double eps = 0;   typedef class Point {    public:     int x, y, deg, id;     Point() : x(0), y(0), deg(0), id(0) {}     Point(Point p, int ndeg) : x(p.x), y(p.y), deg(ndeg), id(p.id) {}     Point(int x, int y, int deg) : x(x), y(y), deg(deg), id(0) {}   } Point;   typedef class Event {    public:     int val, id;     bool add;     double theta;     Event() {}     Event(int val, int id, bool add, double theta)         : val(val), id(id), add(add), theta(theta) {}     bool operator<(Event e) const { return theta < e.theta; }   } Event;   const int N = 6e3 + 6;   int T;   int n, m;   int rs[N];   int tp = 0;   bool onleft[N];   Event events[N << 1];   vector<Point> ps;   inline void init() {     scanf( %d%d , &n, &m);     ps.clear();     ps = vector<Point>(n + m);     for (int i = 0; i < m; i++) scanf( %d , rs + i);     for (int i = 0; i < n; i++)       scanf( %d%d , &ps[i].x, &ps[i].y), ps[i].deg = 0, ps[i].id = i + 1;     for (int i = 0; i < m; i++)       scanf( %d%d , &ps[i + n].x, &ps[i + n].y), ps[i + n].deg = rs[i],                                                         ps[i + n].id = i + 1;   }   void solve(vector<Point>& ps) {     int r = 0, mxid = -1;     for (int i = 0; i < (signed)ps.size(); i++)       if (ps[i].deg > r) r = ps[i].deg, mxid = i;     if (r == 1) {       int cnt = 0;       for (int i = 0; i < (signed)ps.size(); i++)         if (!ps[i].deg) mxid = i, cnt++;       assert(cnt == 1 || ps.size() == 1);       for (int i = 0; i < (signed)ps.size(); i++)         if (i ^ mxid) printf( %d %d n , ps[i].id, ps[mxid].id);       return;     }     int dx, dy;     double theta;     tp = 0;     int sum = 0;     for (int i = 0; i < (signed)ps.size(); i++) {       if (i == mxid) continue;       dx = ps[i].x - ps[mxid].x, dy = ps[i].y - ps[mxid].y;       theta = atan2(dy, dx);       if (theta > 0 || fabs(theta) < eps) {         sum += ps[i].deg - 1, onleft[i] = true;         events[tp++] = Event(1 - ps[i].deg, i, false, theta);       } else         events[tp++] = Event(ps[i].deg - 1, i, true, theta + pi);     }     sort(events, events + tp);     for (int i = 0; i < tp && (sum < 1 - r || sum > -1); i++) {       sum += events[i].val;       onleft[events[i].id] = events[i].add;     }     assert(sum >= 1 - r && sum <= -1);     vector<Point> pl, pr;     for (int i = 0; i < (signed)ps.size(); i++) {       if (i == mxid) continue;       if (onleft[i])         pl.push_back(ps[i]);       else         pr.push_back(ps[i]);     }     pfill(onleft, onleft + ps.size(), false);     pl.push_back(Point(ps[mxid], -sum));     pr.push_back(Point(ps[mxid], r + sum));     solve(pl);     solve(pr);   }   inline void solve() {     puts( YES );     solve(ps);   }   int main() {     scanf( %d , &T);     while (T--) {       init();       solve();     }     return 0;   }