#include <bits/stdc++.h>   typedef struct acv {     int x, y;     int l;     int mark;   } node;   int abs(int a) { return a > 0 ? a : -a; }   int main() {     int m, n;     while (scanf( %d %d , &n, &m) != EOF) {       int i, j;       node nail[505];       int rod[505], sign[505] = {0};       for (i = 1; i <= n; i++) {         scanf( %d %d , &nail[i].x, &nail[i].y);         nail[i].mark = 0;       }       for (i = 1; i <= m; i++) scanf( %d , &rod[i]);       int leng1, leng2;       for (i = 1; i <= n; i++) {         if (i == 1) {           leng1 = nail[1].x - nail[n].x + nail[1].y - nail[n].y;           leng2 = nail[1].x - nail[2].x + nail[1].y - nail[2].y;         } else if (i == n) {           leng1 = nail[n].x - nail[1].x + nail[n].y - nail[1].y;           leng2 = nail[n].x - nail[n - 1].x + nail[n].y - nail[n - 1].y;         } else {           leng1 = nail[i].x - nail[i - 1].x + nail[i].y - nail[i - 1].y;           leng2 = nail[i].x - nail[i + 1].x + nail[i].y - nail[i + 1].y;         }         nail[i].l = abs(leng1) + abs(leng2);       }       int temp[505], flag = 1;       for (i = 1; i <= m; i++) sign[i] = 0;       for (i = 1; i <= n; i++) {         int k = 1;         if (nail[i].mark == 0) {           k = 0;           int kr = 1;           for (j = 1; j <= m; j++) {             if (nail[i].l == rod[j] && sign[j] == 0) {               kr = 0;               sign[j] = 1;               nail[i].mark = 1;               temp[i] = j;               if (i == 1) {                 nail[2].mark = 1;                 nail[n].mark = 1;               } else if (i == n) {                 nail[1].mark = 1;                 nail[n - 1].mark = 1;               } else {                 nail[i + 1].mark = 1;                 nail[i - 1].mark = 1;               }               break;             }           }           if (kr) temp[i] = -1;         }         if (k) temp[i] = -1;       }       for (i = 1; i <= n; i++)         if (nail[i].mark == 0) flag = 0;       if (flag == 0) {         for (i = 1; i <= n; i++) {           nail[i].mark = 0;           temp[i] = 0;         }         for (i = 1; i <= m; i++) sign[i] = 0;         for (i = 2; i <= n; i++) {           int k = 1;           if (nail[i].mark == 0) {             k = 0;             int kr = 1;             for (j = 1; j <= m; j++) {               if (nail[i].l == rod[j] && sign[j] == 0) {                 kr = 0;                 sign[j] = 1;                 nail[i].mark = 1;                 temp[i] = j;                 if (i == n) {                   nail[1].mark = 1;                   nail[n - 1].mark = 1;                 } else {                   nail[i + 1].mark = 1;                   nail[i - 1].mark = 1;                 }                 break;               }             }             if (kr) temp[i] = -1;           }           if (k) temp[i] = -1;         }       }       for (i = 1; i <= n; i++)         if (nail[i].mark == 0) flag = 0;       if (flag == 0)         printf( NO n );       else {         printf( YES n );         for (i = 1; i <= n; i++) {           printf( %d , temp[i]);           if (i == n)             printf(  n );           else             printf(   );         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long s = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) f *= c ==  -  ? -1 : 1, c = getchar();     while (c >=  0  && c <=  9 ) s = s * 10 + c -  0 , c = getchar();     return s * f;   }   struct edge {     int from, nxt, to;     long long val;   };   struct graph {     edge e[1000005 << 1];     int head[2000005], ind[2000005], tot;     inline void addedge(int u, int v, long long w) {       ind[v]++;       e[++tot] = (edge){u, head[u], v, w}, head[u] = tot;     }   } G;   class SCC : public graph {     stack<int> s;     int pre[2000005], low[2000005], dfn;     bool vis[2000005];     void dfs(int u) {       pre[u] = low[u] = ++dfn;       s.push(u);       for (int i = head[u]; i; i = e[i].nxt) {         int v = e[i].to;         if (!pre[v])           dfs(v), low[u] = min(low[u], low[v]);         else if (!scc[v])           low[u] = min(low[u], pre[v]);       }       if (low[u] == pre[u]) {         int x;         cnt++;         do x = s.top(), s.pop(), scc[x] = cnt;         while (x != u);       }     }       public:     int cnt, scc[2000005];     inline void tarjan(int n) {       for (int i = 1; i <= n; i++)         if (!pre[i]) dfs(i);     }     inline void init() {       memset(head, 0, sizeof(head));       memset(pre, 0, sizeof(pre));       memset(low, 0, sizeof(low));       memset(scc, 0, sizeof(scc));       tot = dfn = cnt = 0;       while (!s.empty()) s.pop();     }   } G1;   inline long long calc(long long x) {     long long t = sqrt(2 * x + 0.25) - 0.5;     return x + t * x - (t + 1) * (t + 2) * t / 6;   }   int n, m, s;   long long val[2000005], dis[2000005];   bool vis[2000005];   queue<int> q;   int main() {     n = read(), m = read();     for (register int i = (1); i <= (m); i++) {       int u = read(), v = read();       long long w = read();       G1.addedge(u, v, w);     }     G1.tarjan(n);     s = G1.scc[read()];     for (register int i = (1); i <= (m); i++) {       edge e = G1.e[i];       int u = G1.scc[e.from], v = G1.scc[e.to];       if (u == v)         val[u] += calc(e.val);       else         G.addedge(u, v, e.val);     }     int N = G1.cnt;     memset(dis, -1, sizeof(dis));     q.push(s), dis[s] = val[s], vis[s] = 1;     while (!q.empty()) {       int u = q.front();       q.pop();       vis[u] = 0;       for (int i = G.head[u]; i; i = G.e[i].nxt) {         edge e = G.e[i];         int v = e.to;         if (dis[v] < dis[u] + e.val + val[v]) {           dis[v] = dis[u] + e.val + val[v];           if (!vis[v]) q.push(v), vis[v] = 1;         }       }     }     for (register int i = (1); i <= (N); i++) dis[0] = max(dis[0], dis[i]);     cout << dis[0];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double d[100100];   int s[1010];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n, m, h, sum(0);     cin >> n >> m >> h;     h--;     for (int i = 0; i < m; i++) {       cin >> s[i];       sum += s[i];     }     if (sum < n) {       cout << -1 << endl;       return 0;     }     if (s[h] == 1 || n == 1) {       cout << 0 << endl;       return 0;     }     d[0] = 1;     for (int j = 0; j < sum - s[h]; j++) {       for (int t = n - 1; t >= 0; t--) {         double p1 = (double)(n - t) / (double)(sum - j - 1);         double p2 = (double)(n - t - 1) / (double)(sum - j - 1);         if (p2 <= 1)           d[t] *= (1 - p2);         else           d[t] = 0;         if (p1 <= 1 && t) d[t] += d[t - 1] * p1;       }     }     double ans(0);     for (int j = max(0, n - s[h]); j < n - 1; j++) {       ans += d[j];     }     cout << fixed << setprecision(10) << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     while (a && b) a > b ? a %= b : b %= a;     return a + b;   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   long long fast_exp(long long base, long long exp) {     long long res = 1;     while (exp > 0) {       if (exp % 2 == 1)         res = ((res % 1000000007) * (base % 1000000007)) % 1000000007;       base = ((base % 1000000007) * (base % 1000000007)) % 1000000007;       exp /= 2;     }     return res % 1000000007;   }   const int INF = INT_MAX;   const long long INFL = LLONG_MAX;   map<int, int> Z;   const int size = 3e5 + 9;   int ptr[size];   int main() {     std::ios::sync_with_stdio(0);     cin.tie(0);     int n, q;     cin >> n >> q;     int unread = 0;     vector<pair<int, int> > unr;     int cnt = 0, i = 0;     while (q--) {       cnt++;       int t, x;       cin >> t >> x;       if (t == 1) {         unread++;         unr.push_back(pair<int, int>(x, cnt));         Z[x]++;       } else if (t == 2) {         unread -= Z[x];         Z[x] = 0;         ptr[x] = cnt;       } else {         while (i < x) {           if (unr[i].second >= ptr[unr[i].first]) {             unread--;             ptr[unr[i].first] = unr[i].second;             Z[unr[i].first]--;           }           i++;         }       }       cout << unread <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char a[1000100], ans[3000], s[3000], ans1[3000];   int tmp, p, i, len1, len12, len2, lens, k, o;   bool flag;   bool smaller() {     for (int i = 1; i <= len2; i++)       if (ans1[i] > ans[i])         return false;       else if (ans1[i] < ans[i])         return true;     return false;   }   bool ok1(int i) {     for (int j = k; j >= 1; j--) {       if (a[(j - 1) * len2 + i] != s[(j - 1) * p + tmp]) return false;     }     return true;   }   bool ok2(int i) {     if (k * len2 + i > len1) return false;     if (k * p + tmp > lens) return false;     return (a[k * len2 + i] == s[k * p + tmp]);   }   int main() {     gets(a + 1);     gets(s + 1);     scanf( %d , &len12);     len1 = strlen(a + 1);     lens = strlen(s + 1);     if (len12 > len1)       len2 = len1;     else       len2 = len12;     for (i = 1; i <= len2; i++) ans[i] =  2 ;     flag = false;     k = len1 / len2;     for (o = 0; o <= len2; o++)       if ((lens - o) % k == 0 && o <= (lens - o) / k) {         for (i = 1; i <= len2; i++) ans1[i] =  0 ;         p = (lens - o) / k, tmp = p;         for (i = len2; i >= 1 && tmp > 0; i--)           if (tmp > o) {             if (ok1(i) && k * len2 + i > len1) {               ans1[i] =  1 ;               tmp--;             }           } else if (ok2(i) && ok1(i)) {             ans1[i] =  1 ;             tmp--;           }         if (tmp == 0) {           if (smaller()) {             for (i = 1; i <= len2; i++) ans[i] = ans1[i];             flag = true;           }         }       }     if (flag) {       for (i = 1; i <= len2; i++) printf( %c , ans[i]);       for (i = len2 + 1; i <= len12; i++) printf( 0 );     } else       printf( 0 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int N, M;     cin >> N >> M;     vector<pair<string, int> > A(N);     for (int i = 0; i < N; i++) {       string S;       cin >> S;       for (int j = 1; j < S.size(); j += 2) S[j] =  Z  - (S[j] -  A );       A[i] = make_pair(S, i + 1);     }     sort(A.begin(), A.end());     for (int i = 0; i < N; i++) cout << A[i].second << (i + 1 == N ?   n  :    );   }


#include <bits/stdc++.h>   using namespace std;   #define ll long long   const int N = 3e5+10, oo = 1e9+10;   void solve() {    int n;    cin >> n;    vector<ll> a(n+1);    ll ans = 0;    vector<ll> answers;    answers.reserve(n-1);    for(int i = 1; i <= n; ++i) {     cin >> a[i];     ans += a[i];    }    answers.push_back(ans);    vector<vector<ll>> edges(n+1);    vector<ll> deg(n+1);    for(int i = 0; i < n - 1; ++i) {     ll u, v;     cin >> u >> v;     ++deg[u];     ++deg[v];    }    vector<ll> can_take;    for(int i = 1; i <= n; ++i) {     for(int x = 0; x < deg[i] - 1; ++x) {      can_take.push_back(a[i]);     }    }    sort(can_take.begin(), can_take.end());    while(answers.size() < n - 1) {     answers.push_back(can_take.back() + answers.back());     can_take.pop_back();    }    assert(answers.size() == n - 1);    for(ll x : answers) {     cout << x <<    ;    }    cout <<   n ;   }   int main() {    ios::sync_with_stdio(0); cin.tie(0);    int T = 1;    cin >> T;    while(T--) {     solve();    }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       long long n, one = 0, z = 0;       string s, s1;       cin >> n >> s;       if (n == 1) {         cout << s << endl;         continue;       }       for (long long i = 0; i < s.length(); i++) {         if (s[i] ==  1 )           one++;         else {           z++;         }       }       if (z > one) {         for (int i = 0; i < n; i++) {           s1 +=  0 ;         }       } else {         for (int i = 0; i < n; i++) {           s1 +=  1 ;         }       }       cout << s1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > graph;   vector<int> AL;   vector<int> visited;   void dfs(int u) {     visited[u] = 1;     for (auto v : graph[u]) {       if (!visited[v]) {         dfs(v);       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int tc;     cin >> tc;     while (tc--) {       int n;       cin >> n;       string a, b;       cin >> a >> b;       AL.assign(20, 0);       graph.assign(20, vector<int>());       visited.assign(20, 0);       for (int i = 0; i < n; i++) {         if (a[i] != b[i]) {           AL[a[i] -  a ] |= 1 << (b[i] -  a );           graph[a[i] -  a ].push_back(b[i] -  a );           graph[b[i] -  a ].push_back(a[i] -  a );         }       }       int numCC = 0;       for (int i = 0; i < 20; i++) {         if (!visited[i]) {           dfs(i);           numCC++;         }       }       int ans = 0;       vector<bool> c(1 << 20);       c[0] = true;       for (int mask = 0; mask < (1 << 20); mask++) {         if (c[mask]) {           ans = max(ans, __builtin_popcount(mask));           for (int i = 0; i < 20; i++) {             if (((~mask >> i) & 1) && (AL[i] & mask) == 0) {               c[mask | (1 << i)] = true;             }           }         }       }       cout << 2 * 20 - ans - numCC << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( unroll-loops,no-stack-protector )   #pragma GCC target( sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const int MOD = 1e9 + 7;   const int INF32 = 1 << 30;   const long long INF64 = 1LL << 60;   const long double pi = acos(-1);   long long gcd(long long a, long long b) { return (!b ? a : gcd(b, a % b)); }   long long lcm(long long a, long long b) { return a * b / gcd(a, b); }   long long mul(long long a, long long b) { return a * b % MOD; }   long long modpow(long long b, long long i) {     long long s = 1;     while (i) {       if (i % 2) s = (s * b) % MOD;       b = (b * b) % MOD;       i /= 2;     }     return s;   }   long long inv(long long a) { return modpow(a, MOD - 2); }   void solve() {     int xa, ya, xb, yb;     cin >> xa >> ya >> xb >> yb;     cout << (xa + ya <= max(xb, yb) || (xa <= xb && ya <= yb) ?  Polycarp                                                                :  Vasiliy );   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = (int)1e6 + 10;   const int mod = (int)1e9 + 7;   const int inf = (1 << 30) - 1;   int n, m, q;   int a[maxn];   int good[maxn];   vector<int> g[maxn];   int p[maxn];   int dx[] = {-1, 1, 0, 0};   int dy[] = {0, 0, -1, 1};   char dir[] = { U ,  D ,  L ,  R };   int u[maxn];   int T;   int b[maxn];   char c[maxn];   bool dfs(int v) {     if (u[v] == T) return false;     u[v] = T;     for (int to : g[v]) {       if (p[to] == -1) {         p[to] = v;         p[v] = to;         return true;       }     }     for (int to : g[v]) {       if (good[p[to]] > 0) {         p[p[to]] = -1;         p[to] = v;         p[v] = to;         return true;       }     }     for (int to : g[v]) {       if (dfs(p[to])) {         p[to] = v;         p[v] = to;         return true;       }     }     return false;   }   void solve() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i * m + j];         good[i * m + j] = 0;         g[i * m + j].clear();         p[i * m + j] = -1;         u[i * m + j] = 0;       }     }     T = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         for (int k = 0; k < 4; k++) {           int x = i + dx[k];           int y = j + dy[k];           if (x >= 0 && x < n && y >= 0 && y < m) {             if (a[i * m + j] > a[x * m + y]) {               good[i * m + j] = 1;             } else if (a[i * m + j] == a[x * m + y]) {               g[i * m + j].emplace_back(x * m + y);             }           }         }       }     }     vector<int> li;     for (int i = 0; i < n * m; i++) {       if (good[i] == 0) {         li.emplace_back(i);       }     }     while (true) {       int ok = false;       T++;       for (int i = 0; i < li.size(); i++) {         if (p[li[i]] == -1 && dfs(li[i])) {           ok = true;         }       }       if (!ok) break;     }     for (int i = 0; i < n * m; i++) {       if (good[i]) continue;       if (p[i] == -1) {         cout <<  NO n ;         return;       }     }     cout <<  YES n ;     for (int i = 0; i < n * m; i++) {       if (p[i] == -1) {         for (int k = 0; k < 4; k++) {           int x = i / m + dx[k];           int y = i % m + dy[k];           if (x >= 0 && x < n && y >= 0 && y < m) {             if (a[i] > a[x * m + y]) {               b[i] = a[i] - a[x * m + y];               c[i] = dir[k];             }           }         }       } else {         for (int k = 0; k < 4; k++) {           int x = i / m + dx[k];           int y = i % m + dy[k];           if (x >= 0 && x < n && y >= 0 && y < m) {             if (a[i] == a[x * m + y] && p[i] == x * m + y) {               if (i < x * m + y) {                 b[i] = 1;               } else {                 b[i] = a[i] - 1;               }               c[i] = dir[k];             }           }         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cout << b[i * m + j] <<    ;       }       cout <<   n ;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cout << c[i * m + j] <<    ;       }       cout <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     cout.tie();     int t = 1;     cin >> t;     for (int i = 1; i <= t; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const N = 400010;   int const M = 1001000;   int n, m;   struct edges {     int u, next;   } e[M];   int p[N], idx;   void addedge(int u, int v) { e[idx].u = v, e[idx].next = p[u], p[u] = idx++; }   void init() {     idx = 0;     memset(p, (0xff), sizeof p);   }   int key[N];   int sz[N];   int dep[N];   void dfs(int u, int d, int pre = -1) {     sz[u] = 1;     dep[u] = d;     for (int i = p[u]; ~i; i = e[i].next) {       int v = e[i].u;       if (v != pre) {         dfs(v, d + 1, u);         sz[u] += sz[v];       }     }     for (int i = p[u]; ~i; i = e[i].next) {       int v = e[i].u;       if (v != pre) {         if (sz[v] + sz[v] > n) key[u] = v;       }     }     if (pre != -1 && sz[u] + sz[u] < n) key[u] = pre;   }   int dp[N];   int dpu[N];   void dfs1(int u, int pre = -1) {     for (int i = p[u]; ~i; i = e[i].next) {       int v = e[i].u;       if (v != pre) {         dfs1(v, u);         dp[u] = max(dp[u], dp[v]);       }     }     if (sz[u] + sz[u] <= n) dp[u] = sz[u];   }   void dfs2(int u, int pre = -1) {     int m1 = dpu[u], m2 = 0;     for (int i = p[u]; ~i; i = e[i].next) {       int v = e[i].u;       if (v != pre) {         dp[u] = max(dp[u], dp[v]);         if (dp[v] >= m1) {           m2 = m1;           m1 = dp[v];         } else if (dp[v] >= m2) {           m2 = dp[v];         }       }     }     for (int i = p[u]; ~i; i = e[i].next) {       int v = e[i].u;       if (v != pre) {         int rem = n - sz[v];         if (rem + rem <= n)           dpu[v] = rem;         else {           if (dp[v] == m1)             dpu[v] = max(dpu[v], m2);           else             dpu[v] = max(dpu[v], m1);         }         dfs2(v, u);       }     }   }   int main() {     scanf( %d , &n);     init();     for (int i = 0; i < (n - 1); ++i) {       int a, b;       scanf( %d%d , &a, &b);       addedge(a, b);       addedge(b, a);     }     dfs(1, 0);     dfs1(1);     dfs2(1);     for (int i = 1; i <= (n); ++i) {       if (key[i] == 0)         printf( 1  );       else {         bool ok = 0;         int u = key[i];         if (dep[u] > dep[i]) {           int rem = sz[u] - dp[u];           if (rem + rem <= n) ok = 1;         } else {           int t = dpu[i];           int rem = n - sz[i];           if ((rem - t) * 2 <= n) ok = 1;         }         if (ok)           printf( 1  );         else           printf( 0  );       }     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5010;   struct SA {     bool _t[N * 2];     int _s[N * 2], _sa[N * 2], _c[N * 2], x[N], _p[N], _q[N * 2], hei[N], r[N];     int operator[](int i) { return _sa[i]; }     void build(int *s, int n, int m) {       memcpy(_s, s, sizeof(int) * n);       sais(_s, _sa, _p, _q, _t, _c, n, m);       mkhei(n);     }     void mkhei(int n) {       for (int i = 0; i < int(n); i++) r[_sa[i]] = i;       hei[0] = 0;       for (int i = 0; i < int(n); i++)         if (r[i]) {           int ans = i > 0 ? max(hei[r[i - 1]] - 1, 0) : 0;           while (_s[i + ans] == _s[_sa[r[i] - 1] + ans]) ans++;           hei[r[i]] = ans;         }     }     void sais(int *s, int *sa, int *p, int *q, bool *t, int *c, int n, int z) {       bool uniq = t[n - 1] = true, neq;       int nn = 0, nmxz = -1, *nsa = sa + n, *ns = s + n, lst = -1;       memset((c), 0, z * sizeof(*(c)));       for (int i = 0; i < int(n); i++) uniq &= ++c[s[i]] < 2;       for (int i = 0; i < int(z - 1); i++) c[i + 1] += c[i];       if (uniq) {         for (int i = 0; i < int(n); i++) sa[--c[s[i]]] = i;         return;       }       for (int i = n - 2; i >= 0; i--)         t[i] = (s[i] == s[i + 1] ? t[i + 1] : s[i] < s[i + 1]);       memset((sa), 0, n * sizeof(*(sa)));       memcpy(x, c, sizeof(int) * z);       for (int i = (1); i <= int(n - 1); i++)         if (t[i] && !t[i - 1]) sa[--x[s[i]]] = p[q[i] = nn++] = i;       memcpy(x + 1, c, sizeof(int) * (z - 1));       for (int i = 0; i < int(n); i++)         if (sa[i] && !t[sa[i] - 1]) sa[x[s[sa[i] - 1]]++] = sa[i] - 1;       memcpy(x, c, sizeof(int) * z);       for (int i = n - 1; i >= 0; i--)         if (sa[i] && t[sa[i] - 1]) sa[--x[s[sa[i] - 1]]] = sa[i] - 1;       ;       for (int i = 0; i < int(n); i++)         if (sa[i] && t[sa[i]] && !t[sa[i] - 1]) {           neq = lst < 0 || memcmp(s + sa[i], s + lst,                                   (p[q[sa[i]] + 1] - sa[i]) * sizeof(int));           ns[q[lst = sa[i]]] = nmxz += neq;         }       sais(ns, nsa, p + nn, q + n, t + n, c + z, nn, nmxz + 1);       memset((sa), 0, n * sizeof(*(sa)));       memcpy(x, c, sizeof(int) * z);       for (int i = nn - 1; i >= 0; i--) sa[--x[s[p[nsa[i]]]]] = p[nsa[i]];       memcpy(x + 1, c, sizeof(int) * (z - 1));       for (int i = 0; i < int(n); i++)         if (sa[i] && !t[sa[i] - 1]) sa[x[s[sa[i] - 1]]++] = sa[i] - 1;       memcpy(x, c, sizeof(int) * z);       for (int i = n - 1; i >= 0; i--)         if (sa[i] && t[sa[i] - 1]) sa[--x[s[sa[i] - 1]]] = sa[i] - 1;       ;     }   } sa;   int H[N], SA[N];   void suffix_array(int *ip, int len) {     ip[len++] = 0;     sa.build(ip, len, 128);     for (int i = 0; i < len; i++) {       H[i] = sa.hei[i + 1];       SA[i] = sa._sa[i + 1];     }   }   int n, k, v[N];   char c[N];   void init() {     scanf( %s , c);     scanf( %d , &k);     n = strlen(c);     for (int i = 0; i < n; i++) v[i] = c[i] -  a  + 1;     v[n] = 0;     suffix_array(v, n);   }   bool gt[N][N], pp[N][N];   bool go(int l, int r) {     if (l > r) return true;     if (gt[l][r]) return pp[l][r];     gt[l][r] = true;     if (c[l] != c[r]) return false;     return pp[l][r] = go(l + 2, r - 2);   }   void solve() {     for (int i = 0; i < n; i++)       for (int j = i; j < n; j++) go(i, j);     for (int i = 0; i < n; i++)       for (int j = H[i]; SA[i] + j < n; j++) {         if (!pp[SA[i]][SA[i] + j]) continue;         int tlen = j + 1;         for (int ii = i; ii < n; ii++) {           if (ii > i) tlen = min(tlen, H[ii]);           if (tlen < j + 1) break;           k--;           if (k == 0) {             for (int u = SA[i]; u <= SA[i] + j; u++) putchar(c[u]);             puts(  );             exit(0);           }         }       }   }   int main() {     init();     solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     for (int i = 0; i < t; i++) {       long long n, k;       cin >> n >> k;       if (n < k * k) {         cout <<  NO  <<   n ;       } else if (n % 2 != k % 2) {         cout <<  NO  <<   n ;       } else {         cout <<  YES  <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char save[550][550];   int n, m;   bool vis[550][550];   int dir[4][2] = {-1, 0, 0, 1, 1, 0, 0, -1};   int ans;   bool iscan(int x, int y) {     if (x < 1 || x > n || y < 1 || y > m) return false;     return true;   }   struct Rec {     char k;     int x, y;   } rec[1100000];   void dfs(int x, int y) {     int xx, yy;     for (int i = 0; i < 4; i++) {       xx = x + dir[i][0], yy = y + dir[i][1];       if (iscan(xx, yy)) {         if (save[xx][yy] !=  . ) continue;         if (vis[xx][yy]) continue;         vis[xx][yy] = true;         ans++;         rec[ans].k =  B , rec[ans].x = xx, rec[ans].y = yy;         dfs(xx, yy);         ans++;         rec[ans].k =  D , rec[ans].x = xx, rec[ans].y = yy;         ans++;         rec[ans].k =  R , rec[ans].x = xx, rec[ans].y = yy;       }     }   }   int main() {     while (scanf( %d%d , &n, &m) != EOF) {       for (int i = 1; i <= n; i++) scanf( %s , save[i] + 1);       memset(vis, false, sizeof(vis));       ans = 0;       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++) {           if (save[i][j] ==  .  && !vis[i][j]) {             vis[i][j] = true;             ans++;             rec[ans].k =  B , rec[ans].x = i, rec[ans].y = j;             dfs(i, j);           }         }       printf( %d n , ans);       for (int i = 1; i <= ans; i++)         printf( %c %d %d n , rec[i].k, rec[i].x, rec[i].y);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k, i, j, t;     char c;     string s;     cin >> k;     for (i = 1; i < k; i++) {       for (j = 1; j < k; j++) {         if (j > 1) {           cout <<    ;         }         t = i * j;         s =   ;         while (t > 0) {           c = t % k +  0 ;           s = c + s;           t /= k;         }         cout << s;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mxn = 2000;   int x[mxn];   int main() {     int n, a, b;     cin >> n >> a >> b;     for (int(i) = (0); (i) < (n); (i)++) cin >> x[i];     sort(x, x + n);     cout << x[n - a] - x[n - a - 1];   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   const double EPS = 1e-9;   const int maxn = (int)1e5 + 9;   int n, q, t[maxn], k[maxn], d[maxn];   int x[150];   int ans[maxn];   void Solve() {     while (cin >> n >> q) {       for (int i = (1); i <= (q); i++) cin >> t[i] >> k[i] >> d[i];       memset(ans, (-1), sizeof(ans));       for (int i = (1); i <= (q); i++) {         int f = 0, nt = 0;         for (int j = (1); j <= (n); j++) {           if (x[j] <= t[i]) {             nt++;           }           if (nt == k[i]) {             f = 1;             break;           }         }         if (f) {           int pp = 0, nt = 0;           for (int j = (1); j <= (n); j++) {             if (x[j] <= t[i]) {               x[j] = t[i] + d[i];               nt++;               pp += j;             }             if (nt == k[i]) break;           }           ans[i] = pp;         }       }       for (int i = (1); i <= (q); i++) {         cout << (ans[i]) << endl;         ;       }     }   }   int main() {     iostream::sync_with_stdio(false), cin.tie(0), cout.tie(0);     Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       sort(s.begin(), s.end());       if (s[0] == s[s.size() - 1])         cout << -1 <<   n ;       else         cout << s <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int dfs(const vector<vector<array<int, 3>>>& edges, vector<int>& ans,           vector<int>& s, vector<char>& used, int v) {     used[v] = true;     int sum = 0;     for (auto& w : edges[v]) {       if (!used[w[0]]) {         int d = dfs(edges, ans, s, used, w[0]);         ans[w[1]] = -d * w[2];         sum += d;       }     }     return sum - s[v];   }   int main() {     std::ios::sync_with_stdio(false);     int n, m;     cin >> n;     vector<int> s(n);     for (int i = 0; i < n; ++i) {       cin >> s[i];     }     cin >> m;     if (n == 1) {       cout << (s[0] == 0 ?  Possible  :  Impossible );       return 0;     }     vector<vector<array<int, 3>>> edges(n);     vector<int> ans(m);     for (int i = 0; i < m; ++i) {       int x, y;       cin >> x >> y;       --x;       --y;       edges[x].push_back({y, i, 1});       edges[y].push_back({x, i, -1});     }     vector<char> used(n);     if (dfs(edges, ans, s, used, 0) == 0) {       cout <<  Possible n ;       for (int i : ans) {         cout << i << endl;       }     } else {       cout <<  Impossible ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int p, int q) { return q == 0 ? p : gcd(q, p % q); }   int main() {     int n, num[35][35], sumh[35], suml[35];     cin >> n;     memset(sumh, 0, sizeof(sumh));     memset(suml, 0, sizeof(suml));     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         cin >> num[i][j];       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         sumh[i] += num[i][j];         suml[i] += num[j][i];       }     }     int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (suml[j] > sumh[i]) {           ans++;         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, sx, sy, dx, dy;   string s[1022];   bool vis[1002][1002][5][5];   bool f(int i, int j, int dir, int steps) {     if (i < 0 || j < 0 || i == n || j == m || steps > 2 || s[i][j] ==  *  ||         (dir != -1 && vis[i][j][dir][steps]))       return false;     if (dir != -1) vis[i][j][dir][steps] = 1;     if (i == dx && j == dy && steps <= 2) return true;     if (dir == -1) {       return f(i + 1, j, 2, steps) || f(i - 1, j, 0, steps) ||              f(i, j + 1, 1, steps) || f(i, j - 1, 3, steps);     } else {       if (dir == 0)         return f(i + 1, j, 2, steps + 1) || f(i - 1, j, 0, steps) ||                f(i, j + 1, 1, steps + 1) || f(i, j - 1, 3, steps + 1);       if (dir == 1)         return f(i + 1, j, 2, steps + 1) || f(i - 1, j, 0, steps + 1) ||                f(i, j + 1, 1, steps) || f(i, j - 1, 3, steps + 1);       if (dir == 2)         return f(i + 1, j, 2, steps) || f(i - 1, j, 0, steps + 1) ||                f(i, j + 1, 1, steps + 1) || f(i, j - 1, 3, steps + 1);       if (dir == 3)         return f(i + 1, j, 2, steps + 1) || f(i - 1, j, 0, steps) ||                f(i, j + 1, 1, steps + 1) || f(i, j - 1, 3, steps);     }     return false;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> s[i];       for (int j = 0; j < s[i].size(); j++) {         if (s[i][j] ==  S ) {           sx = i;           sy = j;         }         if (s[i][j] ==  T ) {           dx = i;           dy = j;         }       }     }     memset(vis, 0, sizeof(vis));     if (f(sx, sy, -1, 0))       cout <<  YES n ;     else       cout <<  NO n ;   }


#include <bits/stdc++.h>   using namespace std;   inline int readint() {     int a;     cin >> a;     return a;   }   int toInt(string &s) {     const static int Mod = 998244353;     const static long long bas = 29;     int res = 0;     for (int i = 0, n = s.length(); i < n; ++i)       res = (res * bas + s[i] -  a  + 1) % Mod;     return res;   }   const int MaxN = 100005;   vector<int> v[MaxN];   map<int, int> *dp[MaxN];   int siz[MaxN], son[MaxN];   void build(int x) {     siz[x] = 1, son[x] = x;     for (auto y : v[x]) {       dp[y] = dp[x] + 1, build(y);       if (siz[y] >= siz[son[x]]) son[x] = y;       siz[x] += siz[y];     }   }   int val[MaxN];   void calc(int x, bool f) {     if (f)       dp[x][0][val[x]]++;     else {       dp[x][0][val[x]]--;       if (dp[x][0][val[x]] == 0) dp[x][0].erase(val[x]);     }     for (auto y : v[x]) calc(y, f);   }   vector<pair<int, int> > query[MaxN];   int ans[MaxN];   void dfs(int x, bool f) {     for (auto y : v[x])       if (y != son[x]) dfs(y, false);     if (son[x] != x) dfs(son[x], true);     for (auto y : v[x])       if (y != son[x]) calc(y, true);     dp[x][0][val[x]]++;     for (auto t : query[x]) {       int dep = t.first;       int id = t.second;       ans[id] = dp[x][dep].size();     }     if (not f) calc(x, false);   }   map<int, int> cnt[MaxN];   bool root[MaxN];   int main() {     int n = readint();     string s;     int fa;     for (int i = 1; i <= n; ++i) {       cin >> s >> fa;       if (!fa)         root[i] = true;       else         v[fa].push_back(i);       val[i] = toInt(s);     }     for (int i = 1; i <= n; ++i)       if (root[i]) dp[i] = cnt, build(i);     int T = readint();     pair<int, int> p;     for (int i = 1, a, b; i <= T; ++i) {       a = readint();       b = readint();       if (dp[a] + b >= cnt + MaxN) continue;       p.first = b;       p.second = i;       query[a].push_back(p);     }     for (int i = 1; i <= n; ++i)       if (root[i]) dfs(i, false);     for (int i = 1; i <= T; ++i) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, m, count, x;     while (scanf( %d %d , &n, &m) == 2) {       x = 0;       count = 0;       while (n != 0) {         count++;         if (count % m == 0) x = 1;         n = (n - 1) + x;         x = 0;       }       printf( %d n , count);     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000 )   #pragma GCC optimize( O3 )   using namespace std;   const long long N = 1e5 + 10;   const long long mod = 1e9 + 7;   const long long INF = 1e18;   const long long inf = -1e18;   const long long M = 1e6;   int n, x, y, a[5 * N];   bool us[1000010];   int used[1000010];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL), cout.tie(NULL);     cin >> n >> x >> y;     for (int i = 1; i <= n; i++) {       cin >> a[i];       used[a[i]]++;     }     long long ans = INF;     for (int i = 2; i <= 1000000; i++) {       if (us[i] == 0) {         long long s = used[i];         for (int j = i + i; j <= 1000000; j += i) {           us[j] = 1;           s += used[j];         }         if ((n - s) * min(x, y) >= ans) continue;         long long cnt = 0;         for (int j = 1; j <= n; j++) {           if (a[j] % i != 0) {             long long t = a[j] % i;             cnt += min(1ll * x, 1ll * (i - t) * y);           }         }         ans = min(ans, 1ll * cnt);       }     }     cout << ans;     cin.get(), cin.get();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void doit(long long int a[], long long int i, long long int sz) {     long long int x;     x = i + sz - 1;     a[i] = x;     for (i++; i <= x; i++) a[i] = i - 1;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, a, b, x, y, i, z;     cin >> n >> a >> b;     long long int arr[n + 1];     i = 0;     while (i * a <= n) {       x = n - i * a;       if (x % b == 0) break;       i++;     }     if (i * a > n) {       cout << -1 <<   n ;       return 0;     }     y = x / b;     x = i;     for (i = 0; i < x; i++) doit(arr, i * a + 1, a);     for (i = 0; i < y; i++) doit(arr, x * a + i * b + 1, b);     for (i = 1; i <= n; i++) cout << arr[i] <<    ;     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1E6 + 5, K = 1E6 + 5, INF = 1E9 + 7;   int n, k, c, v, ans = 0, dsu[K];   char s[N];   vector<int> adj[N];   struct node {     int l, r, xo;     node(int _l = 0, int _r = 0, int _xo = 0) : l(_l), r(_r), xo(_xo) {}     int get() { return min(l, r); }     inline void operator+=(node oth) {       l = min(INF, l + oth.l);       r = min(INF, r + oth.r);     }   } val[K];   pair<int, int> trace(int u) {     if (dsu[u] < 0) {       return {u, 0};     } else {       pair<int, int> tmp = trace(dsu[u]);       dsu[u] = tmp.first;       val[u].xo ^= tmp.second;       return {dsu[u], val[u].xo};     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> k >> (s + 1);     for (int i = 1; i <= k; i++) {       dsu[i] = -1;       val[i] = node(1, 0, 0);       cin >> c;       while (c--) {         cin >> v;         adj[v].push_back(i);       }     }     for (int i = 1; i <= n; i++) {       int typ = (s[i] -  0 ) ^ 1;       if (ans != -1) {         if (adj[i].size() == 1) {           pair<int, int> u = trace(adj[i][0]);           ans -= val[u.first].get();           val[u.first] += node((u.second == typ) * INF, (u.second != typ) * INF);           ans += val[u.first].get();         } else if (adj[i].size() == 2) {           pair<int, int> u = trace(adj[i][0]);           pair<int, int> v = trace(adj[i][1]);           if (u.first != v.first) {             ans -= val[u.first].get() + val[v.first].get();             if (dsu[u.first] > dsu[v.first]) {               swap(u, v);             }             if (u.second ^ v.second ^ typ) {               swap(val[v.first].l, val[v.first].r);               val[v.first].xo = 1;             }             dsu[u.first] += dsu[v.first];             dsu[v.first] = u.first;             val[u.first] += val[v.first];             ans += val[u.first].get();           }         }       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int q, n, i, j, k, t;     long long int a[3];     cin >> t;     long long int area[5];     while (t--) {       long long int a, b, x, y;       cin >> a >> b >> x >> y;       area[1] = (b - y - 1) * a;       area[2] = (y)*a;       area[3] = (a - x - 1) * b;       area[4] = (x)*b;       long long int ans = -1;       for (i = 1; i <= 4; i++) {         ans = max(ans, area[i]);       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int rem = 10;   set<char> st;   int main() {     string s;     cin >> s;     long long ans = 1;     int zeroes = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] >=  0  && s[i] <=  9 ) continue;       if (s[i] ==  ? ) {         if (i == 0)           ans *= 9;         else           zeroes += 1;       } else {         if (st.count(s[i])) continue;         st.insert(s[i]);         if (i == 0)           ans *= 9;         else           ans *= rem;         rem--;       }     }     cout << ans;     while (zeroes) {       cout <<  0 ;       zeroes--;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e6 + 5;   const int MACX = (int)1e9 + 7;   const int dx[] = {1, -1, 0, 0};   const int dy[] = {0, 0, 1, -1};   long long n, a[N], b[N], c[N];   multiset<long long> ms, ms2;   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       ms.insert(a[i]);     }     for (int i = 1; i < n; i++) {       cin >> b[i];       ms.erase(ms.find(b[i]));       ms2.insert(b[i]);     }     for (int i = 1; i < n - 1; i++) {       cin >> c[i];       ms2.erase(ms2.find(c[i]));     }     cout << *ms.begin() <<     << *ms2.begin();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool debug = 0;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   string direc =  RDLU ;   long long ln, lk, lm;   void etp(bool f = 0) {     puts(f ?  YES  :  NO );     exit(0);   }   void addmod(int &x, int y, int mod = 1000000007) {     assert(y >= 0);     x += y;     if (x >= mod) x -= mod;     assert(x >= 0 && x < mod);   }   void et() {     puts( -1 );     exit(0);   }   long long fastPow(long long x, long long y, int mod = 1000000007) {     long long ans = 1;     while (y > 0) {       if (y & 1) ans = (x * ans) % mod;       x = x * x % mod;       y >>= 1;     }     return ans;   }   long long gcd1(long long x, long long y) {     long long z = y;     while (x % y != 0) {       z = x % y;       x = y;       y = z;     }     return z;   }   const int B = 165;   int nxt[41005][10], cnt;   bool vis[20][41005];   unordered_map<bitset<B>, int> id;   bitset<B> rid[41005];   long long dp[20][10][41005];   void init() {     bitset<B> bs;     bs.reset();     bs[0] = 1;     id[bs] = ++cnt;     rid[cnt] = bs;     vis[0][1] = 1;     for (int(i) = 1; (i) <= (int)(19); (i)++) {       for (int u = 1; u <= cnt; u++)         if (vis[i - 1][u]) {           for (int(j) = 0; (j) < (int)(10); (j)++) {             if (nxt[u][j] == 0) {               if (j == 0)                 nxt[u][j] = u;               else {                 bs.reset();                 bs |= rid[u] >> j;                 bs |= rid[u] << j;                 for (int k = 1; k < j; k++)                   if (rid[u][k]) bs[j - k] = 1;                 if (id.count(bs))                   nxt[u][j] = id[bs];                 else {                   id[bs] = ++cnt;                   rid[cnt] = bs;                   nxt[u][j] = cnt;                 }               }             }             vis[i][nxt[u][j]] = 1;           }         }     }     for (int(i) = 1; (i) <= (int)(cnt); (i)++) {       int j = 0;       for (; j < 10; j++)         if (rid[i][j] == 1) break;       for (; j < 10; j++) dp[0][j][i] = 1;     }     for (int(i) = 1; (i) <= (int)(19); (i)++) {       for (int(k) = 1; (k) <= (int)(cnt); (k)++)         if (vis[19 - i][k]) {           for (int(j) = 0; (j) < (int)(10); (j)++)             for (int(l) = 0; (l) < (int)(10); (l)++) {               dp[i][l][k] += dp[i - 1][l][nxt[k][j]];             }         }     }   }   long long cal(long long x, int k) {     if (x == 0) return 1;     vector<int> bs;     while (x) {       bs.push_back(x % 10);       x /= 10;     }     long long ans = 0;     int u = 1;     for (int i = (int)bs.size() - 1; ~i; i--) {       for (int j = 0; j < bs[i] + (i == 0); j++) ans += dp[i][k][nxt[u][j]];       u = nxt[u][bs[i]];     }     return ans;   }   void fmain(int ID) {     init();     scanf( %d , &n);     for (int(i) = 1; (i) <= (int)(n); (i)++) {       long long l, r;       scanf( %lld%lld%d , &l, &r, &k);       printf( %lld n , cal(r, k) - cal(l - 1, k));     }   }   int main() {     int t = 1;     for (int(i) = 1; (i) <= (int)(t); (i)++) {       fmain(i);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, d, b;   long long a[500005], c[500005];   long long x, xx;   void read(long long &x) {     x = 0;     long long k = 1;     char c = getchar();     while ((c !=  - ) && (c <  0  || c >  9 )) c = getchar();     if (c ==  - ) k = -1, c = getchar();     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     x = x * k;   }   void write(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   void init() { freopen( f.in ,  r , stdin); }   long long sum(long long x, long long y) {     if (x < 1) x = 1;     if (y > n) y = n;     return c[y] - c[x - 1];   }   int main() {     read(n), read(d), read(b);     for (long long i = 1; i <= n; i++) {       read(a[i]);       c[i] = c[i - 1] + a[i];     }     for (long long i = 1; i <= n / 2; i++) {       if (sum(1, i + i * d) >= (x + 1) * b) x++;       if (sum(n - i - i * d + 1, n) >= (xx + 1) * b) xx++;     }     write(max(n / 2 - x, n / 2 - xx));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   pair<int, int> a[N];   int n;   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i].first >> a[i].second;     sort(a, a + n);     int ans = 0;     int mxb = -1;     for (int i = 0; i < n; ++i) {       if (a[i].second < mxb)         ++ans;       else         mxb = a[i].second;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > pts;   vector<pair<int, int> > rods1;   vector<pair<int, int> > rods2;   vector<int> r1;   vector<int> r2;   vector<int> rr1;   vector<int> rr2;   bool cmp(const pair<int, int> &a, const pair<int, int> &b) {     return a.first < b.first;   }   inline int m_dist(pair<int, int> a, pair<int, int> b) {     return abs(a.first - b.first) + abs(a.second - b.second);   }   int main() {     ios::sync_with_stdio(0);     int n, m;     int a, b, r;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a >> b;       pts.push_back(make_pair(a, b));     }     for (int i = 0; i < m; i++) {       cin >> r;       rods1.push_back({r, i});       rods2.push_back({r, i});     }     sort(rods1.begin(), rods1.end());     sort(rods2.begin(), rods2.end());     for (int i = 0; i < n - 1; i += 2) {       r1.push_back(m_dist(pts[i], pts[i + 1]) +                    m_dist(pts[i + 1], pts[(i + 2) % n]));       r2.push_back(m_dist(pts[(i - 1 + n) % n], pts[i % n]) +                    m_dist(pts[i % n], pts[(i + 1) % n]));     }     bool check1 = true;     for (auto r : r1) {       auto fr =           lower_bound(rods1.begin(), rods1.end(), pair<int, int>(r, 0), cmp);       if (fr == rods1.end() || r != (*fr).first) {         check1 = false;         break;       } else {         rr1.push_back((*fr).second);         rods1.erase(fr);       }     }     bool check2 = true;     for (auto r : r2) {       auto fr =           lower_bound(rods2.begin(), rods2.end(), pair<int, int>(r, 0), cmp);       if (fr == rods2.end() || r != (*fr).first) {         check2 = false;         break;       } else {         rr2.push_back((*fr).second);         rods2.erase(fr);       }     }     if (check1 || check2) {       cout <<  YES n ;       if (check1) {         for (auto e : rr1) {           cout <<  -1  <<     << e + 1 <<    ;         }       } else {         for (auto e : rr2) {           cout << e + 1 <<     <<  -1  <<    ;         }       }     } else {       cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int a, b, c = 0, e, i, n;       cin >> n;       vector<char> v;       char s[n + 1];       cin >> s;       for (i = 0; i < n; i++) {         if ((s[i] -  0 ) % 2 != 0) {           c++;           v.push_back(s[i]);           if (c == 2) break;         }       }       if (c < 2)         cout <<  -1 n ;       else {         for (i = 0; i < 2; i++) cout << v[i];         cout <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const int inf = 0x3f3f3f3f;   const int Minf = 0x7f7f7f7f;   const long long INF = 0x3f3f3f3f3f3f3f3fll;   const long long MINF = 0x7f7f7f7f7f7f7f7fll;   const int N = 1e6 + 50;   long long val[N], fa[N];   int pp[N], ps[N];   int to[N][2], cnt[N * 2];   int main() {     long long n, k;     scanf( %lld%lld , &n, &k);     for (int i = (2); i <= n; ++i)       scanf( %lld%lld , &fa[i], &val[i]), val[i] ^= val[fa[i]];     long long ans = 0;     for (int j = (62); j >= 0; --j) {       int tot = 0;       long long num = 0;       for (int i = (1); i <= n; ++i) {         int d = (val[i] >> j) & 1;         if (to[pp[i]][d] == 0) to[pp[i]][d] = ++tot;         cnt[to[pp[i]][d]]++;         pp[i] = to[pp[i]][d];       }       for (int i = (1); i <= n; ++i) {         int d = (val[i] >> j) & 1;         num += cnt[to[ps[i]][d]];       }       int flag = 0;       if (num < k) k -= num, ans |= (1ll << j), flag = 1;       for (int i = (1); i <= n; ++i) {         int d = (val[i] >> j) & 1;         ps[i] = to[ps[i]][d ^ flag];       }       memset(to, 0, sizeof to);       memset(cnt, 0, sizeof cnt);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int powr(long long int a, long long int b) {     long long int res = 1;     while (b) {       if (b % 2) res = (a * res) % 1000000007;       a = (a * a) % 1000000007;       b /= 2;     }     return res;   }   void extentded_eucledian(long long int a, long long int b, long long int &ex,                            long long int &ey) {     if (b == 0) {       ex = 1;       ey = 0;       return;     }     extentded_eucledian(b, a % b, ex, ey);     swap(ex, ey);     ey -= (a / b) * ex;   }   bool cmp(pair<pair<long long int, long long int>, long long int> &a,            pair<pair<long long int, long long int>, long long int> &b) {     if (a.first.first != b.first.first) return (a.first.first < b.first.first);     return (a.first.second < b.first.second);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int tc = 1;     cin >> tc;     while (tc--) {       long long int n;       cin >> n;       vector<pair<pair<long long int, long long int>, long long int>> vec;       vector<long long int> ans(n);       for (long long int i = 0; i < n; ++i) {         long long int x, y;         cin >> x >> y;         vec.push_back(make_pair(make_pair(x, y), i));       }       sort(vec.begin(), vec.end(), cmp);       long long int curr = 1, maxr = vec[0].first.second, wasn1 = 1, wasn2 = 1;       ans[vec[0].second] = 1;       stack<long long int> s;       for (long long int i = 1; i < n; ++i) {         if (maxr >= vec[i].first.first)           s.push(vec[i].second);         else {           while (!s.empty()) {             long long int tmp = s.top();             s.pop();             ans[tmp] = curr;           }           curr = 3 - curr;           s.push(vec[i].second);         }         maxr = max(maxr, vec[i].first.second);       }       while (!s.empty()) {         long long int tmp = s.top();         s.pop();         ans[tmp] = curr;       }       for (long long int i : ans)         if (i == 1) wasn1 = 0;       for (long long int i : ans)         if (i == 2) wasn2 = 0;       if (wasn1 || wasn2)         cout <<  -1 n ;       else {         for (auto lstelem : ans) cout << lstelem <<    ;         cout <<    n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long int n, t;     cin >> n >> t;     long int arr[n + 1];     bool visited[n + 1];     for (long int i = 1; i < n; i++) {       cin >> arr[i];       visited[i] = false;     }     long int i = 1;     while (visited[i] == false && i != t && i != n) {       visited[i] = true;       i = i + arr[i];     }     if (i == t) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double find(int x, int y) { return (sqrt(x * x + y * y)); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int r, d;     int t;     cin >> r >> d;     cin >> t;     int c = 0;     while (t--) {       int x, y, q;       cin >> x >> y >> q;       double l;       l = find(x, y);       int a = r - d;       int b = a + d;       if (l - q >= a && l + q <= r) c++;     }     cout << c << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5;   const int MAXR = 1;   const int MAXC = 1;   const int INF = (int)1e9;   priority_queue<int, vector<int>, greater<int>> q1;   priority_queue<int, vector<int>, less<int>> q2;   int arr[MAXN];   vector<pair<int, int>> v(MAXN);   vector<vector<int>> adjl(MAXN);   queue<int> q;   set<pair<int, int>> s;   int n;   int x4[] = {-1, 0, 1, 0};   int y4[] = {0, 1, 0, -1};   void createGraph() {     while (!q.empty()) {       int vn = q.front();       q.pop();       pair<int, int> p = v[vn];       int deg = p.first;       int xs = p.second;       if (deg == 0) continue;       if (adjl[vn].size() == deg) continue;       int cxs = 0;       for (int j = 0; j < adjl[vn].size(); ++j) {         cxs ^= adjl[vn][j];       }       int ns = xs ^ cxs;       ;       adjl[vn].push_back(ns);       ;       adjl[ns].push_back(vn);       if (v[ns].first - adjl[ns].size() == 1) {         q.push(ns);       }     };   }   void createEdgeSet() {     for (int i = 0; i < adjl.size(); ++i) {       for (int j = 0; j < adjl[i].size(); ++j) {         int src = i;         int dest = adjl[i][j];         pair<int, int> p1 = make_pair(src, dest);         pair<int, int> p2 = make_pair(dest, src);         if (s.find(p1) == s.end() && s.find(p2) == s.end()) {           s.insert(p1);         }       }     };   }   int main(void) {     ios::sync_with_stdio(false);     cin >> n;     v.resize(n);     adjl.resize(n);     int d, sv;     for (int i = 0; i < n; ++i) {       cin >> d >> sv;       v[i] = make_pair(d, sv);       if (d == 1) {         q.push(i);       }     };     createGraph();     createEdgeSet();     cout << s.size() << endl;     for (set<pair<int, int>>::iterator it = s.begin(); it != s.end(); it++) {       pair<int, int> p = *it;       cout << p.first <<     << p.second << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int a, b;     cin >> a >> b;     if (a == b) {       cout << (a * 10) <<     << (b * 10) + 1;     } else if (a + 1 == b) {       cout << (min(a, b) * 10) + 9 <<     << (max(a, b) * 10);     } else if (a == 9 && b == 1) {       cout << a <<     << b * 10;     } else       cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:256000000 )   struct __ {     __() {       ios_base::sync_with_stdio(false);       cin.tie(NULL);     }   } _;   template <typename I>   inline void in(I l, I r) {     while (l != r) cin >> *l, ++l;   }   template <typename I>   inline void out(I l, I r, char D =    ) {     if (l != r) {       cout << *l;       while (++l != r) cout << D << *l;     }     cout <<   n ;   }   struct debug_t {     template <typename T>     debug_t& operator<<(const T& value) {       return *this;     }   } debug;   namespace DSU {   vector<int> parent, rank;   void init(int n) {     parent = vector<int>(n);     rank = vector<int>(n, 0);     for (int i = 0; i < (n); ++i) parent[i] = i;   }   int find(int v) {     if (parent[v] != v) return parent[v] = find(parent[v]);     return v;   }   int merge(int a, int b) {     a = find(a);     b = find(b);     if (a == b) return a;     if (rank[a] > rank[b]) swap(a, b);     parent[a] = b;     if (rank[a] == rank[b]) ++rank[b];     return b;   }   }  // namespace DSU   vector<int> mx_dist;   pair<int, int> find_far(vector<vector<int> >& g, int v, int p = -1) {     pair<int, int> result = make_pair(0, v);     for (int i = 0; i < (static_cast<int>((g[v]).size())); ++i) {       int nxt = g[v][i];       if (nxt != p) {         pair<int, int> nxt_result = find_far(g, nxt, v);         nxt_result.first += 1;         result = max(result, nxt_result);       }     }     return result;   }   int get_color_value(vector<vector<int> >& g, int v) {     int n = static_cast<int>((g).size());     pair<int, int> f;     f = find_far(g, v);     f = find_far(g, f.second);     return f.first;   }   void calc_mx_dist(vector<vector<int> >& g) {     int n = static_cast<int>((g).size());     vector<int> used(n, 0);     for (int i = 0; i < (n); ++i) {       int color = DSU::find(i);       if (!used[color]) {         used[color] = 1;         mx_dist[color] = get_color_value(g, i);       }     }   }   void req(int x, int y) {     x = DSU::find(x);     y = DSU::find(y);     if (x != y) {       int result = (mx_dist[x] + 1) / 2 + (mx_dist[y] + 1) / 2 + 1;       int res = DSU::merge(x, y);       mx_dist[res] = max(result, max(mx_dist[x], mx_dist[y]));     }   }   int main() {     int n, m, q;     while (cin >> n >> m >> q) {       DSU::init(n);       mx_dist = vector<int>(n, 0);       vector<vector<int> > g = vector<vector<int> >(n);       while (m--) {         int a, b;         cin >> a >> b;         --a;         --b;         g[a].push_back(b);         g[b].push_back(a);         DSU::merge(a, b);       }       calc_mx_dist(g);       while (q--) {         int code, a, b;         cin >> code >> a;         --a;         if (code == 1)           cout << mx_dist[DSU::find(a)] <<   n ;         else {           cin >> b;           --b;           req(a, b);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     long long coins = 0;     vector<long long> arr(n);     for (int i = 0; i < n; i++) cin >> arr[i];     int i = 0, j = 0;     while (i < n && j < n) {       while (i < n && arr[i] <= 0) i++;       while (j < n && (arr[j] >= 0 || j < i)) j++;       if (i >= n || j >= n) break;       long long x = min(abs(arr[i]), abs(arr[j]));       arr[i] -= x;       arr[j] += x;     }     for (int i = 0; i < n; i++) {       if (arr[i] > 0) coins += arr[i];     }     cout << coins <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T mabs(const T &a) {     return a < 0 ? -a : a;   }   int n, m, p, bss;   vector<int> a, b;   map<int, int> bCounts;   vector<int> checkPos(int sp) {     vector<int> res;     map<int, int> aCounts;     int wrongCounts = bss;     for (int i = (0), ei = (m); i < ei; i++) {       int cp = sp + i * p;       if (cp >= n) return res;       int aVal = a[cp];       int cac = aCounts[aVal];       int nac = cac + 1;       if (cac == bCounts[aVal])         wrongCounts++;       else if (nac == bCounts[aVal])         wrongCounts--;       aCounts[aVal] = nac;     }     int moved = 0;     while (1) {       if (wrongCounts == 0) res.push_back(sp + moved * p);       int curExc = a[sp + moved * p];       int curIncIdx = sp + (moved + m) * p;       if (curIncIdx >= n) break;       int curInc = a[curIncIdx];       {         int cac = aCounts[curExc];         int nac = cac - 1;         if (cac == bCounts[curExc])           wrongCounts++;         else if (nac == bCounts[curExc])           wrongCounts--;       }       if (wrongCounts < 0) throw 1;       aCounts[curExc]--;       {         int cac = aCounts[curInc];         int nac = cac + 1;         if (cac == bCounts[curInc])           wrongCounts++;         else if (nac == bCounts[curInc])           wrongCounts--;       }       if (wrongCounts < 0) throw 1;       aCounts[curInc]++;       moved++;     }     return res;   }   void run() {     scanf( %d%d%d , &n, &m, &p);     for (int i = (0), ei = (n); i < ei; i++) {       int cur;       scanf( %d , &cur);       a.push_back(cur);     }     for (int i = (0), ei = (m); i < ei; i++) {       int cur;       scanf( %d , &cur);       b.push_back(cur);       bCounts[cur]++;     }     bss = bCounts.size();     vector<int> res;     for (int i = (0), ei = (p); i < ei; i++) {       vector<int> cur = checkPos(i);       for (int j = (0), ej = (cur.size()); j < ej; j++) res.push_back(cur[j]);     }     sort((res).begin(), (res).end());     printf( %d n , (int)res.size());     for (int i = (0), ei = (res.size()); i < ei; i++) {       printf( %d  , res[i] + 1);     }   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, count_zero = 0, count_max = 0;     cin >> n >> m;     int data[n][m];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> data[i][j];         count_max += data[i][j];         if (data[i][j] == 0) {           count_zero++;         }       }     }     for (int i = n - 2; i >= 1; i--) {       for (int j = m - 2; j >= 1; j--) {         int h_d = data[i][j + 1] - data[i][j - 1],             v_d = data[i + 1][j] - data[i - 1][j];         if (data[i][j] == 0 && h_d > 1 && v_d > 1) {           data[i][j] = min(data[i + 1][j] - 1, data[i][j + 1] - 1);           count_max += data[i][j];         } else if (h_d <= 1 || v_d <= 1) {           cout <<  -1 ;           return 0;         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 1; j < m; j++) {         if (data[i][j] <= data[i][j - 1]) {           cout <<  -1 ;           return 0;         }       }     }     for (int i = 0; i < m; i++) {       for (int j = 1; j < n; j++) {         if (data[j][i] <= data[j - 1][i]) {           cout <<  -1 ;           return 0;         }       }     }     cout << count_max;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000;   vector<int> a[maxn];   bool flag[maxn];   int ans[maxn];   int n;   bool judge(int x, int y) {     int cnt = 0;     memset(flag, false, sizeof(flag));     for (int i = 0; i < (int)a[x].size(); i++) {       flag[a[x][i]] = true;     }     for (int i = 0; i < (int)a[y].size(); i++) {       if (flag[a[y][i]] == false) return false;     }     return true;   }   int main() {     while (cin >> n) {       for (int i = 1; i <= n; i++) a[i].clear();       for (int i = 1; i <= n; i++) {         int m;         cin >> m;         while (m--) {           int x;           cin >> x;           a[i].push_back(x);         }       }       for (int i = 1; i <= n; i++) ans[i] = 1;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           if (i == j) continue;           if (judge(i, j)) {             ans[i] = 0;             break;           }         }       }       for (int i = 1; i <= n; i++) {         if (ans[i])           puts( YES );         else           puts( NO );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long int n;     cin >> n;     int event, police = 0, ans = 0;     for (int i = 0; i < n; i++) {       cin >> event;       if (event == -1) {         if (police == 0)           ans++;         else           police--;       } else         police += event;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5000 + 10;   int n, a[N], dp[N][N][2];   int calc(int i, int rem, bool isLess) {     if (rem == 0) return 0;     if (i >= n) return 2e9;     int &ret = dp[i][rem][isLess];     if (ret != -1) return ret;     ret = 2e9;     if (isLess) {       if (i != n - 1) {         int h = a[i + 1];         int extra = max(h - a[i] + 1, 0);         h -= extra;         ret = min(ret, extra + calc(i + 2, rem - 1, h < a[i + 2]));         if (i != n - 2) {           int h = a[i + 1];           int extra = max(h - a[i + 2] + 1, 0);           h -= extra;           ret = min(ret, extra + calc(i + 2, rem - (h < a[i]), h < a[i + 2]));         }         ret = min(ret, calc(i + 1, rem, a[i] < a[i + 1]));         if (a[i] >= a[i + 1])           ret = min(ret, (a[i] - a[i + 1] + 1) + calc(i + 1, rem, true));       } else         ret = min(ret, calc(i + 1, rem - 1, false));     } else {       if (i != n - 1) {         ret = min(ret, calc(i + 1, rem, a[i] < a[i + 1]));         if (a[i] >= a[i + 1])           ret = min(ret, (a[i] - a[i + 1] + 1) + calc(i + 1, rem, true));       }     }     return ret;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , a + i);     memset(dp, -1, sizeof dp);     int k = (n + 1) / 2;     for (int i = 1; i <= k; ++i) printf( %d  , calc(0, i, true));     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long int modInverse(long long int a, long long int m) {     return power(a, m - 2, m);   }   long long int f(long long int y) {     long double x = -1 + sqrt(1 + 8 * (y + 0.0));     long long int ret = x / 2;     return ret;   }   vector<long long int> v[101];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int b;     cin >> b;     long long int cnt = 0;     for (long long int i = 1; i * i <= b; i++) {       if (b % i == 0) {         if (b / i == i)           cnt++;         else           cnt += 2;       }     }     cout << cnt <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int res[51][51];   int main() {     scanf( %d , &n);     for (int i = 0; i < n * (n - 1) / 2 - 1; i++) {       int a, b;       scanf( %d%d , &a, &b);       res[a][b] = 1;       res[b][a] = -1;     }     int q1, q2;     for (int i = 1; i < n + 1; i++)       for (int j = i + 1; j < n + 1; j++) {         if (res[i][j] == 0) {           q1 = i;           q2 = j;         }       }     for (int i = 1; i < n + 1; i++) {       if (i != q1 && i != q2 && res[q1][i] > res[q2][i]) {         printf( %d %d , q1, q2);         return 0;       }       if (i != q1 && i != q2 && res[q1][i] < res[q2][i]) {         printf( %d %d , q2, q1);         return 0;       }     }     printf( %d %d , q2, q1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > Div[5 * int(1e5 + 100)];   int a[2 * int(1e5 + 100)];   bool Have[2 * int(1e5 + 100)];   int calc[5 * int(1e5 + 100)];   int root[5 * int(1e5 + 100)];   int val = 1;   void Prime(int x) {     int u = x;     root[x] = 1;     for (int i = 2; i <= sqrt(x); i++)       if (x % i == 0) {         Div[u].push_back(pair<int, int>(i, 1));         while (x % i == 0) x /= i;         root[u] *= i;       }     if (x > 1) {       Div[u].push_back(pair<int, int>(x, 1));       root[u] *= x;     }   }   void Generate(int x, int n, int maxnumber, int number, int pos) {     if (number > maxnumber) {       Div[x].push_back(pair<int, int>(val, maxnumber));       return;     }     for (int j = pos; j <= n - (maxnumber - number); j++) {       val *= Div[x][j].first;       Generate(x, n, maxnumber, number + 1, j + 1);       val /= Div[x][j].first;     }   }   int main() {     for (int i = 2; i <= 5e5; i++) {       Prime(i);       if (i != root[i]) Div[i].clear();     }     for (int i = 2; i <= 5e5; i++)       if (i == root[i]) {         int n = Div[i].size();         for (int j = 2; j <= n; j++) Generate(i, n - 1, j, 1, 0);       }     int n, q;     cin >> n >> q;     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     int Size = 0;     long long ans = 0;     for (int i = 1; i <= q; i++) {       int x, base;       scanf( %d , &x);       x--;       if (!Have[x]) {         Have[x] = true;         base = 1;         ans += 1ll * Size;         Size++;       } else {         Have[x] = false;         base = -1;         Size--;         ans -= 1ll * Size;       }       for (int j = 0; j < Div[root[a[x]]].size(); j++) {         int base2;         if (Div[root[a[x]]][j].second % 2 == 1)           base2 = -1;         else           base2 = 1;         if (base == -1) calc[Div[root[a[x]]][j].first]--;         ans = ans + (1ll * base * base2 * calc[Div[root[a[x]]][j].first]);         if (base == 1) calc[Div[root[a[x]]][j].first]++;       }       printf( %I64d n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   map<float, int> mp;   float cnt[200005];   int main() {     int m;     cin >> m;     for (int i = 1; i <= m; i++) {       char s1, s2, s3, s4;       int a, b, c;       cin >> s1 >> a >> s2 >> b >> s3 >> s4 >> c;       cnt[i] = (((a + b) * 1.0) / c);       mp[cnt[i]]++;     }     for (int i = 1; i <= m; i++) {       if (i == m)         cout << mp[cnt[i]] << endl;       else         cout << mp[cnt[i]] <<    ;     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   int a, b, c, d, i, j, n, m, k, ans, T;   char str[200003];   int p[22], cs[22][22], dp[1 << 22];   pair<int, int> cur[26];   int main() {     scanf( %d%d%d , &n, &k, &T);     scanf( %s , str);     for (int _n((k)-1), i(0); i <= _n; i++) scanf( %d , &p[i]);     for (int _n((k)-1), i(0); i <= _n; i++)       for (int _n((k)-1), j(0); j <= _n; j++) scanf( %d , &cs[i][j]);     cur[0] = make_pair(-1, -1);     int were = 0;     for (int i = (n - 1), _b = (0); i >= _b; i--) {       int mask = 0, t = str[i] -  A ;       were |= 1 << t;       for (int _n((k)-1), j(0); j <= _n; j++) {         if (cur[j].first == -1) break;         dp[mask] += cs[t][cur[j].second];         dp[mask | 1 << t] -= cs[t][cur[j].second];         dp[mask | 1 << cur[j].second] -= cs[t][cur[j].second];         dp[mask | (1 << t) | (1 << cur[j].second)] += cs[t][cur[j].second];         mask |= 1 << cur[j].second;         if (cur[j].second == t) break;       }       for (int _n((k)-1), j(0); j <= _n; j++) {         if (cur[j].first == -1 || cur[j].second == t) {           bool tt = 0;           if (cur[j].first == -1) tt = 1;           cur[j] = make_pair(i, t);           for (int z = (j - 1), _b = (0); z >= _b; z--) swap(cur[z], cur[z + 1]);           if (tt) cur[j + 1] = make_pair(-1, -1);           break;         }       }     }     ans = 0;     for (int _n((k)-1), i(0); i <= _n; i++) {       for (int _n((were)-1), mask(0); mask <= _n; mask++) {         if ((mask & were) != mask) continue;         if (mask & 1 << i) dp[mask] += dp[mask ^ 1 << i];       }     }     for (int _n((were)-1), mask(0); mask <= _n; mask++) {       if ((mask & were) != mask) continue;       c = dp[mask];       for (int _n((k)-1), i(0); i <= _n; i++)         if (mask & 1 << i) c += p[i];       if (c <= T) ++ans;     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int n, m, p = 1000000;   bool checkDias(int a, const vector<unsigned long long int> &v) {     for (int i = p; i < n + 1; i += 1) {       unsigned long long int d = i / a;       unsigned long long int r = i % a;       if (v[i] >= (unsigned long long int)m + r * (d + 1) * d / 2 +                       (a - r) * d * (d - 1) / 2)         return true;     }     return false;   }   int main() {     cin >> n >> m;     vector<int> vect(n);     vector<unsigned long long int> sumasparciales(n + 1, 0);     for (int i = 0; i < n; i += 1) {       cin >> vect[i];     }     sort(vect.begin(), vect.end(), greater<int>());     for (int i = 0; i < n; i += 1) {       sumasparciales[i + 1] = sumasparciales[i] + vect[i];       if (sumasparciales[i + 1] >= m && i + 1 < p) p = i + 1;     }     if (sumasparciales[n] < m) {       cout << -1 << endl;       return 0;     }     int i = 1;     int j = m;     int minimo = m + 10;     while (i <= j) {       int nepe = (i + j) / 2;       if (checkDias(nepe, sumasparciales)) {         j = nepe - 1;         minimo = min(minimo, nepe);       } else         i = nepe + 1;     }     cout << minimo << endl;   }


#include <bits/stdc++.h>   using namespace std;   inline char nc() {     static char buf[1000000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)                ? EOF                : *p1++;   }   template <typename T>   inline void read(T& sum) {     char ch = nc();     T tf = 0;     sum = 0;     while ((ch <  0  || ch >  9 ) && (ch !=  - )) ch = nc();     tf = ((ch ==  - ) && (ch = nc()));     while (ch >=  0  && ch <=  9 ) sum = sum * 10 + (ch - 48), ch = nc();     (tf) && (sum = -sum);   }   template <typename T>   inline void write(T x) {     if (x == 0) {       putchar( 0 );       return;     }     char F[200];     T tmp = x > 0 ? x : -x;     if (x < 0) putchar( - );     T cnt = 0;     while (tmp > 0) {       F[cnt++] = tmp % 10 +  0 ;       tmp /= 10;     }     while (cnt > 0) putchar(F[--cnt]);   }   template <typename T>   T gcd(T a, T b) {     if (!a || !b) return max(a, b);     while (b ^= a ^= b ^= a %= b)       ;     return a;   }   template <typename T>   T C(T m, T n) {     if (n > m) return 0;     if (n == 0 || m == 1 || m == n) return 1;     return C(m - 1, n - 1) + C(m - 1, n);   }   template <typename T>   void exgcd(T a, T b, T& d, T& x, T& y) {     if (!b) {       d = a;       x = 1;       y = 0;     } else {       exgcd(b, a % b, d, y, x);       y -= x * (a / b);     }   }   template <typename T>   T niyuan(T a, T p) {     T d, x, y;     exgcd(a, p, d, x, y);     return d == 1 ? (x + p) % p : -1;   }   template <typename T>   T extgcd(T a, T b, T& x, T& y) {     if (b) {       T r = extgcd(b, a % b, y, x);       y -= x * (a / b);       return r;     } else {       x = 1;       y = 0;       return a;     }   }   template <typename T>   T ax_bmodM(T a, T b, T M) {     T x, y, r = extgcd(a, M, x, y);     if (b % r)       return -1;     else       x = (x + M) % M * b / r;     return x % (M / r);   }   template <typename T>   inline T dmod(const string& s, T mod) {     T len = s.size();     T ans = 0;     for (T i = 0; i < len; i++)       ans = (int)(((long long)ans * 10 + s[i] -  0 ) % mod);     return ans;   }   template <typename T>   inline T ksc(T a, T b, T mod) {     T ans = 0;     while (b > 0) {       if (b & 1) ans = (ans + a) % mod;       a = (a + a) % mod;       b >>= 1;     }     return ans;   }   template <typename T>   inline T ksm(T x, T n, T mod) {     T ans = 1;     while (n > 0) {       if (n & 1) ans = ans * x % mod;       x = x * x % mod;       n >>= 1;     }     return ans;   }   template <typename T>   inline T mod_jia(T a, T b, T mod) {     return (a % mod + b % mod) % mod;   }   template <typename T>   inline T mod_jian(T a, T b, T mod) {     return (a % mod + mod - b % mod) % mod;   }   template <typename T>   inline T mod_cheng(T a, T b, T mod) {     return ((a % mod) * (b % mod)) % mod;   }   template <typename T>   inline T mod_chu(T a, T b, T p) {     b = ksm(b, p - 2, p);     return a * b % p;   }   template <typename T>   inline void rmqmin(T f[][20], T n) {     for (int i = 1; i <= n; i++) cin >> f[i][0];     for (int j = 1; j <= 20; j++)       for (int i = 1; i <= n; i++)         if (i + (1 << j) - 1 <= n)           f[i][j] = min(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]);   }   template <typename T>   inline T zymin(T f[][20], T z, T y) {     int x = int(log(y - z + 1) / log(2));     return min(f[z][x], f[y - (1 << x) + 1][x]);   }   template <typename T>   inline void rmqmax(T f[][20], T n) {     for (int i = 1; i <= n; i++) cin >> f[i][0];     for (int j = 1; j <= 20; j++)       for (int i = 1; i <= n; i++)         if (i + (1 << j) - 1 <= n)           f[i][j] = max(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]);   }   template <typename T>   inline T zymax(T f[][20], T z, T y) {     int x = int(log(y - z + 1) / log(2));     return max(f[z][x], f[y - (1 << x) + 1][x]);   }   template <typename T>   inline void stgcd(T f[][20], T n) {     for (int i = 1; i <= n; i++) cin >> f[i][0], f[i + n][0] = f[i][0];     for (int j = 1; j <= 20; j++) {       for (int i = 1; i + (1 << j) - 1 <= 2 * n; i++) {         f[i][j] = __gcd(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]);       }     }   }   template <typename T>   inline T qgcd(T f[][20], T z, T y) {     int x = int(log(y - z + 1) / log(2));     return __gcd(f[z][x], f[y - (1 << x) + 1][x]);   }   template <typename T>   inline T rotatex(T x, T y, T ang, T ox = 0, T oy = 0) {     return (x - ox) * cos(ang) - (y - oy) * sin(ang) + ox;   }   template <typename T>   inline T rotatey(T x, T y, T ang, T ox = 0, T oy = 0) {     return (x - ox) * sin(ang) + (y - oy) * cos(ang) + oy;   }   vector<int> l, y;   char s[200005];   pair<int, int> p[200005];   int a[200005], ans[200005];   bool cmp(int x, int y) { return a[x] < a[y]; }   void solve() {     l.clear();     y.clear();     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       p[i] = make_pair(a[i], i);     }     cin >> (s + 1);     for (int i = 1; i <= n; ++i) {       if (s[i] ==  1 )         y.push_back(i);       else         l.push_back(i);     }     int xx = 0;     int long long = l.size();     int yy = y.size();     sort(y.begin(), y.end(), cmp);     sort(l.begin(), l.end(), cmp);     for (auto& i : l) ans[i] = ++xx;     for (auto& i : y) ans[i] = ++xx;     for (int i = 1; i <= n; ++i) cout << ans[i] <<    ;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int _t;     cin >> _t;     while (_t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-6;   const long long mod = 1000000007ll;   const long long mod1 = 1000000009ll;   const long long mod2 = 1100000009ll;   const double PI = 3.14159265359;   const long long MX = 1000000000000ll;   int INF = 2147483645;   long long INFINF = (long long)1e18;   using namespace std;   template <class T>   T Max2(T a, T b) {     return a < b ? b : a;   }   template <class T>   T Min2(T a, T b) {     return a < b ? a : b;   }   template <class T>   T Max3(T a, T b, T c) {     return Max2(Max2(a, b), c);   }   template <class T>   T Min3(T a, T b, T c) {     return Min2(Min2(a, b), c);   }   template <class T>   T Max4(T a, T b, T c, T d) {     return Max2(Max2(a, b), Max2(c, d));   }   template <class T>   T Min4(T a, T b, T c, T d) {     return Min2(Min2(a, b), Max2(c, d));   }   template <class T>   void swap(T &a, T &b) {     T c = b;     b = a;     a = c;   }   long long bit_count(long long _x) {     long long _ret = 0;     while (_x) {       if (_x % 2 == 1) _ret++;       _x /= 2;     }     return _ret;   }   long long bit(long long _mask, long long _i) {     return (_mask & (1 << _i)) == 0 ? 0 : 1;   }   long long powermod(long long _a, long long _b, long long _m) {     long long _r = 1;     while (_b) {       if (_b % 2 == 1) _r = (_r * _a) % _m;       _b /= 2;       _a = (_a * _a) % _m;     }     return _r;   }   long long add(long long a, long long b, long long m) {     long long x = a + b;     while (x >= m) x -= m;     return x;   }   long long sub(long long a, long long b, long long m) {     long long x = a - b;     while (x < 0) x += m;     return x;   }   long long mul(long long a, long long b, long long m) {     long long x = a * b;     x %= m;     return x;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int q, n;     cin >> q;     for (int i = 0; i < int(q); i++) {       cin >> n;       vector<int> a(n);       for (int i = 0; i < int(n); i++) {         cin >> a[i];       }       sort(a.begin(), a.end());       int f = 0;       for (int i = 0; i < int(n - 1); i++) {         if (a[i + 1] - a[i] == 1) {           f = 1;           break;         }       }       if (f)         cout << 2 << endl;       else         cout << 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool check(int c1, int c2, int c3, int v1, int v2, int v3, int m) {     return (c1 >= v1 && c1 <= 2 * v1 && c2 >= v2 && c2 <= 2 * v2 && c3 >= v3 &&             c3 <= 2 * v3 && 2 * m >= c3 && 2 * m < c2 && c3 < c2 && c2 < c1 &&             m <= c3);   }   int main() {     int v1, v2, v3, m;     cin >> v1 >> v2 >> v3 >> m;     for (int i = 1; i <= 200; i++) {       for (int j = i + 1; j <= 200; j++) {         for (int k = j + 1; k <= 200; k++) {           if (check(k, j, i, v1, v2, v3, m)) {             cout << k << endl;             cout << j << endl;             cout << i << endl;             return 0;           }         }       }     }     cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B, typename C>   struct triple {     A X;     B Y;     C Z;     triple(A a = 0, B b = 0, C c = 0) : X(a), Y(b), Z(c) {}   };   template <typename A, typename B, typename C>   triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0) {     return triple<A, B, C>(a, b, c);   }   template <typename A, typename B, typename C>   bool operator<(const triple<A, B, C>& a, const triple<A, B, C>& b) {     if (a.X != b.X) return a.X < b.X;     if (a.Y != b.Y) return a.Y < b.Y;     return a.Z < b.Z;   }   template <typename T, typename SS>   ostream& operator<<(ostream& ofs, const pair<T, SS>& p) {     ofs <<  (   << p.first <<   ,   << p.second <<   ) ;     return ofs;   }   template <typename T>   void print(T a) {     for (auto i : a) cout << i <<    ;     cout <<   n ;   }   template <typename T>   T max(T a, T b, T c) {     return max(a, max(b, c));   }   template <typename T>   T min(T a, T b, T c) {     return min(a, max(b, c));   }   vector<vector<long long> > g;   vector<long long> h;   vector<long long> p;   void dfs(long long v, long long hh = 0, long long pp = -1) {     h[v] = hh;     for (auto to : g[v])       if (to != pp) {         p[to] = v;         dfs(to, hh + 1, v);       }   }   signed main() {     srand(time(NULL));     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(false);     long long n;     cin >> n;     g.resize(n);     p.resize(n);     h.resize(n);     for (long long _ = 0; _ < (n - 1); _++) {       long long x, y;       cin >> x >> y;       x--, y--;       g[x].push_back(y);       g[y].push_back(x);     }     dfs(0);     set<pair<long long, long long> > need;     for (long long i = 0; i < n; i++)       if (h[i] > 2) need.insert(make_pair(-h[i], i));     long long ans = 0;     while (need.size()) {       long long x = need.begin()->second;       long long y = p[x];       if (need.count(make_pair(-h[y], y))) need.erase(make_pair(-h[y], y));       for (auto to : g[y])         if (need.count(make_pair(-h[to], to))) need.erase(make_pair(-h[to], to));       ans++;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   bool comp[30000];   int P[30000];   int seive(int n, int* P) {     int p, q, K = 0;     comp[1] = true;     char even = 1;     for (p = 2; p * p <= n; p += 2) {       if (!comp[p]) {         for (q = p * p; q <= n; q += p * (2 - even)) comp[q] = true;       }       if (p == 2) --p, even = 0;     }     for (int i = (1); i <= (n); ++i)       if (!comp[i]) P[K++] = i;     return K;   }   int muls[30000];   int has[30000];   int main() {     int K;     cin >> K;     int lim = 2 * K * K;     int least = (K + 1) / 2;     vector<int> ans;     ans.push_back(1);     int max_added = 0;     int L = seive(5 * K, P);     for (int l = 0; l < L && ((int)ans.size()) < K; ++l) {       for (int l2 = 0; l2 < (l); ++l2) {         has[l2] = 0;         for (int i = 0; i < (((int)ans.size())); ++i)           if (!(ans[i] % P[l2])) ++has[l2];       }       int p = P[l];       set<int> tmp;       for (long long q = p; q <= lim; q *= p) {         for (int i = 0; i < ((int)ans.size()) && (ans[i] % p); ++i) {           long long new_num = 1ll * q * ans[i];           if (new_num <= lim) {             tmp.insert(new_num);           }         }       }       set<int>::iterator it = tmp.begin();       for (int i = 0; it != tmp.end() && i < least; ++it) {         int v = *it;         assert(!(v % p));         for (int j = 0; j < (l); ++j)           if (!(v % P[j])) ++has[j];         if (((int)ans.size()) < K) {           ans.push_back(v);         } else {           bool found = false;           for (int j = (K - 1); j >= (0); --j) {             int w = ans[j];             bool good = true;             for (int h = (0); h <= (l); ++h) {               int& pr = P[h];               if (!(w % pr)) {                 if (has[h] <= least) {                   good = false;                   break;                 }               }             }             if (good) {               for (int h = (0); h <= (l - 1); ++h) {                 int& pr = P[h];                 if (!(w % pr)) {                   has[h]--;                 }               }               assert(ans[j] % p);               ans[j] = v;               found = true;               break;             }           }           assert(found);           assert(ans.size() == K);         }         ++i;       }       assert(((int)ans.size()) <= K);     }     assert(((int)ans.size()) == K);     sort(ans.begin(), ans.end());     ans.erase(unique(ans.begin(), ans.end()), ans.end());     assert(((int)ans.size()) == K);     for (int l = 0; l < (L); ++l) {       int cnt = 0;       for (int i = 0; i < ((int)ans.size()); ++i)         if (!(ans[i] % P[l])) {           ++cnt;         }       assert(cnt == 0 || cnt >= least);     }     for (int i = 0; i < (((int)ans.size())); ++i) assert(ans[i] <= lim);     for (int i = 0; i < (K); ++i) {       if (i > 0) printf(   );       printf( %d , ans[i]);     }     printf(  n );   }


#include <bits/stdc++.h>   const long long int inf = 9e18;   const long double pi = 2 * acos(0.0);   using namespace std;   long long int power(long long int a, long long int n) {     if (n == 0) {       return 1;     }     long long int p = power(a, n / 2) % 998244353;     p = (p * p) % 998244353;     if (n % 2 == 1) {       p = (p * a) % 998244353;     }     return p;   }   long long int gcd(long long int a, long long int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   int isprime(long long int n) {     for (long long int i = 2; i <= sqrt(n); i++) {       if (n % i == 0) {         return 0;       }     }     return 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       if (n >= 15) {         n = n % 14;         if (n <= 6 && n >= 1) {           cout <<  YES                 <<   n ;         } else {           cout <<  NO                 <<   n ;         }       } else {         cout <<  NO               <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   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;   }   vector<int> v;   signed main() {     int n = read(), k = read() % 64, x = read();     for (int i = 1, x; i <= n; i++) x = read(), v.push_back(x);     while (k--) {       sort(v.begin(), v.end());       for (int i = 0; i < n; i += 2) v[i] ^= x;     }     sort(v.begin(), v.end());     printf( %d %d n , v[n - 1], v[0]);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s;     int temp;     long long sol = 0;     cin >> s;     if ((s[0] -  0 ) % 4 == 0) {       sol++;     }     for (int a = s.length() - 1; a > 0; a--) {       temp = (s[a] -  0 ) + 10 * (s[a - 1] -  0 );       if (temp % 4 == 0) {         sol += a;       }       if ((s[a] -  0 ) % 4 == 0) {         sol++;       }     }     cout << sol <<   n ;     cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int s[200010], univ[200010];   int n, k, n_univ;   vector<int> edges[200010];   bool visited[200010];   int dist[200010];   int getSum(int node) {     int sum = univ[node];     visited[node] = true;     for (auto e : edges[node]) {       if (!visited[e]) sum += getSum(e);     }     s[node] = sum;     return sum;   }   int dfs(int node) {     visited[node] = true;     for (auto e : edges[node]) {       if (visited[e]) continue;       if (s[e] * 2 > n_univ) {         return dfs(e);       }     }     return node;   }   long long getAns(int centroid) {     queue<pair<int, int> > q;     memset(visited, 0, sizeof(visited));     q.push(make_pair(centroid, 0));     visited[centroid] = true;     while (!q.empty()) {       pair<int, int> node = q.front();       q.pop();       dist[node.first] = node.second;       for (int e : edges[node.first]) {         if (!visited[e]) {           visited[e] = true;           q.push(make_pair(e, node.second + 1));         }       }     }     long long sum = 0;     for (int i = 0; i < n; i++) {       if (univ[i]) sum += dist[i];     }     return sum;   }   int main() {     cin >> n >> k;     n_univ = k + k;     for (int i = 0; i < n_univ; i++) {       int x;       cin >> x;       x--;       univ[x] = 1;     }     for (int i = 0; i < n - 1; i++) {       int v1, v2;       cin >> v1 >> v2;       v1--;       v2--;       edges[v1].push_back(v2);       edges[v2].push_back(v1);     }     getSum(0);     memset(visited, 0, sizeof(visited));     cout << getAns(dfs(0)) << endl;   }


#include <bits/stdc++.h>   int main() {     char n[101], a[4] =  127 , b[6] =  32767 , c[11] =  2147483647 ,                  d[20] =  9223372036854775807 ;     int i, l, count, mark;     while (~scanf( %s , n)) {       l = strlen(n);       if (l < 3) {         printf( byte n );         continue;       }       if (l == 3) {         mark = 1;         for (i = 0; i < l; i++) {           if (n[i] > a[i]) break;           if (n[i] < a[i]) {             mark = 0;             break;           }           if (i == l - 1) {             if (n[i] == a[i]) mark = 0;           }         }         if (mark == 0)           printf( byte n );         else           printf( short n );         continue;       }       if (l == 4) {         printf( short n );         continue;       }       if (l == 5) {         mark = 1;         for (i = 0; i < l; i++) {           if (n[i] > b[i]) break;           if (n[i] < b[i]) {             mark = 0;             break;           }           if (i == l - 1) {             if (n[i] == b[i]) mark = 0;           }         }         if (mark == 0)           printf( short n );         else           printf( int n );         continue;       }       if (l <= 9) {         printf( int n );         continue;       }       if (l == 10) {         mark = 1;         for (i = 0; i < l; i++) {           if (n[i] > c[i]) break;           if (n[i] < c[i]) {             mark = 0;             break;           }           if (i == l - 1) {             if (n[i] == c[i]) mark = 0;           }         }         if (mark == 0)           printf( int n );         else           printf( long n );         continue;       }       if (l < 19) {         printf( long n );         continue;       }       if (l == 19) {         mark = 1;         for (i = 0; i < l; i++) {           if (n[i] > d[i]) break;           if (n[i] < d[i]) {             mark = 0;             break;           }           if (i == l - 1) {             if (n[i] == d[i]) mark = 0;           }         }         if (mark == 0)           printf( long n );         else           printf( BigInteger n );         continue;       }       printf( BigInteger n );     }   }


#include <bits/stdc++.h>   using namespace std;   string second[100];   int x[100], y[100];   vector<int> a, b;   bool u[100][100];   bool uu[100][100];   bool ux[100], uy[100];   int n, m;   void dfs(int x, int y) {     ux[x] = uy[y] = true;     u[x][y] = true;     for (int i = 0; i < n; i++)       if (second[i][y] ==  #  && !u[i][y]) dfs(i, y);     for (int j = 0; j < m; j++)       if (second[x][j] ==  #  && !u[x][j]) dfs(x, j);   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> second[i];     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (second[i][j] ==  #  && !u[i][j]) {           for (int i = 0; i < n; i++) ux[i] = false;           for (int i = 0; i < m; i++) uy[i] = false;           dfs(i, j);           a.clear();           b.clear();           for (int i = 0; i < n; i++)             if (ux[i]) a.push_back(i);           for (int j = 0; j < m; j++)             if (uy[j]) b.push_back(j);           for (int i = 0; i < n; i++)             for (int j = 0; j < m; j++) uu[i][j] = false;           for (int i = 0; i < a.size(); i++)             for (int j = 0; j < b.size(); j++) {               uu[a[i]][b[j]] = true;             }           for (int i = 0; i < n; i++)             for (int j = 0; j < m; j++) {               if (ux[i] && second[i][j] ==  #  && !uu[i][j]) {                 cout <<  No ;                 return 0;               }               if (second[i][j] ==  .  && uu[i][j]) {                 cout <<  No ;                 return 0;               }             }         }     cout <<  Yes ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int x, y;   };   vector<node> answer;   int dis[1000005], a[1000005], pre[1000005];   bool prime[1000005];   void getprime() {     for (int i = 2; i < 1000005 - 5; i++) {       if (!prime[i]) {         for (int j = i * 2; j < 1000005 - 5; j += i) {           prime[j] = true;         }       }     }     int maxx = 2;     for (int i = 2; i < 1000005 - 5; i++) {       if (prime[i] == false) maxx = i;       pre[i] = maxx;     }   }   int main() {     getprime();     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       dis[a[i]] = i;     }     int t = 0;     for (int i = 1; i <= n; i++) {       if (a[i] == i) continue;       int j = dis[i];       while (j != i) {         int k = pre[j - i + 1];         k = j - k + 1;         node q;         q.x = k, q.y = j;         answer.push_back(q);         swap(dis[a[j]], dis[a[k]]);         swap(a[j], a[k]);         j = k;       }     }     printf( %d n , answer.size());     for (int i = 0; i < answer.size(); i++) {       printf( %d %d n , answer[i].x, answer[i].y);     }   }


//#pragma comment(linker,  /STACK:102400000,102400000 )   #include<bits/stdc++.h>   using namespace std;   typedef long long ll;   #define int ll   typedef pair<int,int>pii;   #define ff first   #define ss second   #define debug(x) std:: cerr << #x <<   =   << x << std::endl;   const int maxn=2010,inf=0x3f3f3f3f,mod=1000000007;   const ll INF=0x3f3f3f3f3f3f3f3f;   const double eps=1e-9;   //#define DEBUG//#define lowbit(x) ((x) & -(x))//<<setiosflags(ios::fixed)<<setprecision(9)   void read(){}   template<typename T,typename... T2>inline void read(T &x,T2 &... oth) {    x=0; int ch=getchar(),f=0;    while(ch< 0 ||ch> 9 ){if (ch== - ) f=1;ch=getchar();}    while (ch>= 0 &&ch<= 9 ){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}    if(f)x=-x;    read(oth...);   }   ll a[maxn],dp[maxn][maxn];   ll MAX[maxn][maxn],MIN[maxn][maxn];   int s[maxn][maxn];   signed main(signed argc, char const *argv[])   {    std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);    #ifdef DEBUG     freopen( input.in ,  r , stdin);    // freopen( output.out ,  w , stdout);    #endif    int n;    cin>>n;    for(int i=1;i<=n;i++)     cin>>a[i];    sort(a+1,a+n+1);    memset(dp,INF,sizeof(dp));   // memset(MIN,INF,sizeof(MIN));    for(int i=1;i<=n;i++)    {     dp[i][i]=0;   //  s[i][i]=i;   //  MAX[i][i]=MIN[i][i]=a[i];    }    for(int len=2;len<=n;len++)    {     for(int l=1;l<=n-len+1;l++)     {      int r=l+len-1;      dp[l][r]=min(dp[l][r-1],dp[l+1][r])+a[r]-a[l];   //   fprintf(stderr, [%lld,%lld]=%lld n ,l,r,dp[l][r]);   //   for(int k=s[l][r-1];k<s[l+1][r];k++)   //   {   //    MAX[l][r]=max(MAX[l][k],MAX[k+1][r]);   //    MIN[l][r]=min(MIN[l][k],MIN[k+1][r]);   //    ll now=min(MAX[l][k]-MIN[k+1][r],a[r]-a[l]);   //    if(dp[l][r]>dp[l][k]+dp[k+1][r]+now)   //    {   //     dp[l][r]=dp[l][k]+dp[k+1][r]+now;   //     s[l][r]=k;   //    }   //   }     }    }    cout<<dp[1][n]<<endl;    return 0;   }   /*    * 2021-04-16-23.54.07   */


#include <bits/stdc++.h>   using namespace std;   long long ar[200004];   long long prefix[200004];   long long D[200004];   void calc(long n) {     D[n] = 0;     long long mx = -1000000000000000000;     for (long i = n - 1; i >= 1; i--) {       D[i] = max(mx, prefix[i + 1] - D[i + 1]);       mx = max(mx, D[i]);     }     std::cout << D[1] << endl;   }   int main() {     std::ios::sync_with_stdio(false);     ;     long n;     std::cin >> n;     for (long i = 1; i <= n; i++) {       std::cin >> ar[i];     }     prefix[0] = 0;     for (long i = 1; i <= n; i++) {       prefix[i] = ar[i] + prefix[i - 1];     }     calc(n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, i, u;     cin >> n >> u;     long long int a[n + 2];     bool pos = false;     double res = 0;     for (i = 0; i < n + 1; ++i) {       cin >> a[i];     }     int j = 0;     for (int i = 0; i < n - 2; i++) {       j = max(j, i + 2);       while (j + 1 < n && a[j + 1] - a[i] <= u) j++;       if (a[j] - a[i] <= u) {         res = max(res, (double(a[j] - a[i + 1])) / (double(a[j] - a[i])));         pos = true;       }     }     if (pos)       cout << fixed << setprecision(10) << res;     else       cout <<  -1 ;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 99999;   int d[maxn], s[maxn];   int n;   int m;   queue<int> q;   vector<pair<int, int> > p;   bool inq[maxn];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       scanf( %d %d , &d[i], &s[i]), m += d[i];       if (d[i] == 1) q.push(i);     }     m /= 2;     while (!q.empty()) {       int x = q.front();       q.pop();       if (d[x] <= 0) continue;       int y = s[x];       p.push_back(make_pair(x, y));       s[y] ^= x;       d[y]--;       if (d[y] == 1) q.push(s[x]);     }     printf( %d n , p.size());     for (int i = 0; i < p.size(); i++) printf( %d %d n , p[i].first, p[i].second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[200005];   int b[200005];   long long sum;   int res[200005];   int ge[35];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), sum += a[i];     for (int i = 1; i <= n; i++) scanf( %d , &b[i]), sum += b[i];     if (n == 1 && a[1] != b[1]) {       puts( -1 );       return 0;     }     if (sum % (n * 2) != 0) {       puts( -1 );       return 0;     }     sum = sum / n;     sum = sum / 2;     for (int i = 1; i <= n; i++) {       int tmp = a[i] + b[i] - sum;       if (tmp % n || tmp < 0) {         puts( -1 );         return 0;       }       tmp = tmp / n;       res[i] = tmp;     }     for (int i = 1; i <= n; i++) {       for (int j = 0; j < 30; j++) {         if (res[i] & (1 << j)) ge[j]++;       }     }     for (int i = 1; i <= n; i++) {       long long nowa = 0, nowb = 0;       for (int j = 0; j < 30; j++) {         if (res[i] & (1 << j)) {           nowa += ge[j] * (1 << j);           nowb += 1ll * n * (1 << j);         } else {           nowb += ge[j] * (1 << j);         }       }       if (nowa != a[i] || nowb != b[i]) {         puts( -1 );         return 0;       }     }     for (int i = 1; i < n; i++) printf( %d  , res[i]);     printf( %d n , res[n]);     return 0;   }


#include<bits/stdc++.h>   using namespace std;   #define endl   n    #define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);   #define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);   const int mx=1e5+123;   int arr[mx];   long long x,cnt;   int main()   {       optimize();       int t;       cin>>t;       while(t--){           int n;           cin>>n;              int arr[n];           for(int i=0;i<n;i++)cin>>arr[i];           sort(arr,arr+n);           int i=1,x=arr[1]-arr[0];           while(i<n){               if(arr[i]-arr[i-1]<x)               x=arr[i]-arr[i-1];                  if(arr[i]<=x)i++;               else break;           }           cout<<i<<endl;                  }             return 0;   }