#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cout << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   const int MAXN = 100005;   const int SQRTN = 1003;   const int LOGN = 22;   const double PI = acos(-1);   const int INF = 1e9;   const int MOD = 1000000007;   const int FMOD = 998244353;   const double eps = 1e-8;   void solvethetestcase();   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     for (int testcase = 1; testcase < t + 1; testcase++) {       solvethetestcase();     }   }   int n, m;   vector<pair<int, int> > adj[MAXN];   bitset<MAXN> vis;   double ans[MAXN];   bool flag = 1;   int par[MAXN], dep[MAXN];   int pw[MAXN];   int sm[MAXN];   map<int, int> freq;   vector<int> cc;   void dfs(int u, double val) {     ans[u] = val;     for (auto v : adj[u]) {       if (par[v.first] == u and v.first != u) {         dfs(v.first, v.second - val);       }     }   }   void bfs(int root) {     dep[root] = 0;     par[root] = root;     sm[root] = 0;     queue<int> q;     q.push(root);     while (q.size()) {       int u = q.front();       q.pop();       vis[u] = 1;       cc.push_back(u);       for (auto v : adj[u]) {         if (dep[v.first] == MAXN) {           par[v.first] = u;           pw[v.first] = v.second;           dep[v.first] = 1 + dep[u];           if (dep[u] % 2 == 0)             sm[v.first] = sm[u] + v.second;           else             sm[v.first] = sm[u] - v.second;           q.push(v.first);         }       }     }     double minoddshit = INF, maxoddshit = -INF;     freq.clear();     for (auto u : cc) {       freq[sm[u]]++;       for (auto v : adj[u]) {         if (v.first != u and (dep[v.first] + 1 == dep[u] or par[v.first] == u))           continue;         if (dep[v.first] == dep[u]) {           double val;           if (dep[u] % 2 == 0) {             val = (double)(sm[v.first] - sm[u] + v.second) / (double)2 +                   (double)sm[u];           } else {             val = (double)(sm[v.first] - sm[u] - v.second) / (double)2 +                   (double)sm[u];           }           minoddshit = min(minoddshit, val);           maxoddshit = max(maxoddshit, val);           if (minoddshit + eps < maxoddshit) {             flag = 0;             return;           }         } else {           if (dep[u] % 2 == 1) {             if (sm[u] - v.second == sm[v.first]) continue;             flag = 0;             return;           } else {             if (sm[u] + v.second == sm[v.first]) continue;             flag = 0;             return;           }         }       }     }     if (minoddshit != INF) {       dfs(root, minoddshit);       return;     }     int neg = 0, zer = 0, pos = 0, cur = 0;     for (auto x : freq) {       if (x.first == 0)         zer += x.second;       else if (x.first > 0)         pos += x.second;       else         neg += x.second;     }     while (pos + zer < neg) {       pos += zer;       cur--;       zer = freq[cur];       neg -= zer;     }     while (neg + zer < pos) {       neg += zer;       cur++;       zer = freq[cur];       pos -= zer;     }     dfs(root, cur);   }   void solvethetestcase() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v, w;       cin >> u >> v >> w;       adj[u].push_back({v, w});       adj[v].push_back({u, w});     }     for (int i = 1; i < n + 1; i++) {       sort(adj[i].begin(), adj[i].end());       for (int j = 0; j + 1 < adj[i].size(); j++) {         if (adj[i][j].first == adj[i][j + 1].first and             adj[i][j].second != adj[i][j + 1].second) {           cout <<  NO n ;           return;         }       }     }     for (int i = 1; i < n + 1; i++) dep[i] = MAXN;     for (int i = 1; i < n + 1; i++) {       if (!vis[i]) {         bfs(i);         cc.clear();         if (!flag) break;       }     }     if (!flag) {       cout <<  NO n ;     } else {       cout <<  YES n ;       for (int i = 1; i < n + 1; i++) cout << ans[i] <<    ;       cout <<   n ;     }   }


#include <bits/stdc++.h>   template <typename T>   T pow(T a, T b, long long m) {     T ans = 1;     while (b > 0) {       if (b % 2 == 1) ans = (ans * a) % m;       b /= 2;       a = (a * a) % m;     }     return ans % m;   }   using namespace std;   const long long N = 2e5 + 77;   string s;   void sol() {     long long n;     cin >> n;     vector<long long> A(30, 0);     for (long long(i) = (0); (i) < (n); (i)++) {       cin >> s;       for (long long(j) = (0); (j) < ((long long)s.size()); (j)++)         A[s[j] -  a ]++;     }     for (long long(i) = (0); (i) < ((long long)A.size()); (i)++)       if (A[i] % n != 0) {         cout <<  NO  <<   n ;         return;       }     cout <<  YES  <<   n ;   }   int32_t main() {     long long t;     cin >> t;     while (t--) sol();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100050;   int item[MAXN];   int main() {     int dcnt;     while (scanf( %d , &dcnt) == 1) {       int discount = MAXN;       for (int i = 0; i < dcnt; i++) {         int tmp;         scanf( %d , &tmp);         discount = min(discount, tmp);       }       int icnt;       scanf( %d , &icnt);       for (int i = 1; i <= icnt; i++) scanf( %d , &item[i]);       sort(item + 1, item + 1 + icnt, greater<int>());       long long cost = 0;       long long dealed = 0, cur = 0;       while (dealed < icnt) {         if (cur == discount) {           cur = 0;           dealed += 2;         }         cost += item[++dealed];         cur++;       }       printf( %lld n , cost);     }   }


#include <bits/stdc++.h>   int main() {     int n, m;     scanf( %d%d , &n, &m);     int min_row = n, max_row = 0, min_col = m, max_col = 0;     char S[105][105];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf(  %c , &S[i][j]);         if (S[i][j] ==  * ) {           min_row = std::min(min_row, i), max_row = std::max(max_row, i),           min_col = std::min(min_col, j), max_col = std::max(max_col, j);         }       }     }     for (int i = min_row; i <= max_row; i++, putchar(  n )) {       for (int j = min_col; j <= max_col; j++) {         printf( %c , S[i][j]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   long long n, sum;   int a[maxn], ans[maxn];   int main() {     scanf( %I64d%I64d , &n, &sum);     long long tot = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       tot += a[i];     }     for (int i = 1; i <= n; i++) {       if (a[i] > sum - n + 1) ans[i] += a[i] - (sum - n + 1);       if (sum - 1 > tot - a[i]) ans[i] += sum - 1 - (tot - a[i]);     }     for (int i = 1; i <= n; i++) printf( %d%c , ans[i], i == n ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MX = 300005;   long long a[MX], b[MX];   int32_t main() {     long long n, p, k;     cin >> n >> p >> k;     for (long long i = 0; i < n; i++) {       cin >> a[i];       b[i] =           (((a[i] * a[i]) % p) * ((a[i] * a[i]) % p) - (k * a[i]) + (k * p)) % p;     }     cout << endl;     sort(b, b + n);     long long j = 0, sum = 0;     for (long long i = 0; i < n; i = j) {       while (b[i] == b[j] && j < n) {         j++;       }       long long num = j - i;       sum += (num * (num - 1)) / 2;     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, h, g, n;     scanf( %lld , &t);     while (t--) {       scanf( %lld %lld , &h, &g);       n = 1ll << h;       pair<long long, long long> p[n - 1];       for (long long i = 1; i < n; i++)         scanf( %lld , &p[i - 1].first), p[i - 1].second = i;       sort(p, p + n - 1);       bool f[n * 2], ans[n];       for (long long i = 1; i < n; i++) {         if (i < (1ll << g))           f[i] = true;         else           f[i] = false;         ans[i] = false;       }       long long s = 0;       for (auto e : p) {         long long c = e.second;         while (c > 0) {           if (f[c] && !f[c * 2] && !f[c * 2 + 1]) {             ans[e.second] = true, f[c] = false, s += e.first;             break;           }           c /= 2;         }       }       printf( %lld n , s);       for (long long i = n - 1; i > 0; i--)         if (!ans[i]) printf( %lld  , i);       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const int inf = 0x3f3f3f3f;   const double eps = 1e-15;   const long long INF = (1LL << 60);   const int N = 200000 + 100;   int xis[N << 1];   bool vis[N << 1];   struct QUE {     bool flag;     int x, y;   } que[N];   struct SegTree {     int l, r;     int val;   } tree[2][N << 2];   int use[N << 2];   int k;   void pushup(int p) {     tree[k][p].val = min(tree[k][p << 1].val, tree[k][p << 1 | 1].val);   }   void build(int p, int l, int r) {     tree[k][p].l = l;     tree[k][p].r = r;     if (l == r) {       tree[k][p].val = inf;       return;     }     int mid = (l + r) >> 1;     build(p << 1, l, mid);     build(p << 1 | 1, mid + 1, r);     pushup(p);   }   void update(int p, int pos, int val) {     if (tree[k][p].l == tree[k][p].r) {       tree[k][p].val = val;       return;     }     int mid = (tree[k][p].l + tree[k][p].r) >> 1;     if (pos <= mid) {       update(p << 1, pos, val);     } else {       update(p << 1 | 1, pos, val);     }     pushup(p);   }   int tar, val, pos;   int query(int p, int l, int r) {     if (l <= tree[k][p].l && tree[k][p].r <= r) {       return tree[k][p].val;     }     int mid = (tree[k][p].l + tree[k][p].r) >> 1;     if (r <= mid) {       return query(p << 1, l, r);     } else if (l > mid) {       return query(p << 1 | 1, l, r);     } else {       return min(query(p << 1, l, mid), query(p << 1 | 1, mid + 1, r));     }   }   void work1(int l, int r) {     int L = l, R = r, mid;     while (L <= R) {       mid = (L + R) >> 1;       int v = query(1, mid, r);       if (v <= tar) {         L = mid + 1;         pos = mid;         val = v;       } else {         R = mid - 1;       }     }   }   void work2(int l, int r) {     int L = l, R = r, mid;     while (L <= R) {       mid = (L + R) >> 1;       int v = query(1, l, mid);       if (v <= tar) {         R = mid - 1;         pos = mid;         val = v;       } else {         L = mid + 1;       }     }   }   char op[4];   int ret;   int main() {     int n, q;     while (~scanf( %d%d , &n, &q)) {       ret = 0;       memset(vis, 0, sizeof(vis));       for (int i = 1; i <= q; ++i) {         scanf( %d%d%s , &que[i].x, &que[i].y, op);         if (op[0] ==  U ) {           que[i].flag = 0;         } else {           que[i].flag = 1;         }         swap(que[i].x, que[i].y);         xis[++ret] = que[i].x;       }       sort(xis + 1, xis + 1 + ret);       ret = unique(xis + 1, xis + 1 + ret) - xis - 1;       k = 0;       build(1, 1, ret);       k = 1;       build(1, 1, ret);       for (int i = 1; i <= q; ++i) {         int x = que[i].x;         int y = que[i].y;         int ans = 0;         int indx = lower_bound(xis + 1, xis + 1 + ret, x) - xis;         if (vis[indx]) {           printf( 0 n );           continue;         }         val = inf;         vis[indx] = 1;         if (que[i].flag == 0) {           tar = y;           if (indx == 1) {             ans = x;           } else {             k = 0;             work1(1, indx - 1);             if (val <= tar) {               ans = x - xis[pos];             } else {               ans = x;             }           }           k = 1;           update(1, indx, x - ans + 1);         } else {           tar = x;           if (indx == ret) {             ans = y;           } else {             k = 1;             work2(indx + 1, ret);             if (val <= tar) {               ans = y - (n + 1 - xis[pos]);             } else {               ans = y;             }           }           k = 0;           update(1, indx, y - ans + 1);         }         printf( %d n , ans);       }     }     return 0;   }


#include <cstdio>   #include <algorithm>   #define ll long long int   using namespace std;   const int MAX = 1e7+10;   int t, c;   int ans[MAX];   int prime[MAX], pcount;   bool vis[MAX];   ll d[MAX], f[MAX];   void eular() {       for (int i = 1; i <= MAX; i++) ans[i] = MAX;       ans[1] = 1;       for (int i = 2; i < MAX; i++) {           if (!vis[i]) {               vis[i] = 1;               prime[pcount++] = i;               d[i] = f[i] = i + 1;               if (ans[i + 1] > i) ans[i + 1] = i;           }           for (int j = 0; j < pcount && (ll)prime[j] * i < MAX; j++) {               vis[prime[j] * i] = 1;               if (i % prime[j] == 0) {                   f[prime[j] * i] = f[i] * prime[j] + 1;                   d[prime[j] * i] = d[i] / f[i] * f[prime[j] * i];               } else {                   f[prime[j] * i] = f[prime[j]];                   d[prime[j] * i] = d[i] * f[prime[j] * i];               }               if (d[prime[j] * i] < MAX && ans[d[prime[j] * i]] > prime[j] * i) ans[d[prime[j] * i]] = prime[j] * i;               if (i % prime[j] == 0) break;           }       }   }   int main() {       eular();       scanf( %d , &t);       while(t--) {           scanf( %d , &c);           if (ans[c] != MAX) printf( %d n , ans[c]);           else printf( -1 n );       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   int n, arr[N], arr2[N], seg[4 * N], lazy[4 * N];   inline void fix(int s, int e, int idx) {     seg[idx] += lazy[idx];     if (s != e) {       lazy[(idx << 1)] += lazy[idx];       lazy[(idx << 1) + 1] += lazy[idx];     }     lazy[idx] = 0;   }   int build(int s, int e, int idx) {     if (s == e) return seg[idx] = arr2[s];     return seg[idx] = max(build(s, ((s + e) >> 1), (idx << 1)),                           build(((s + e) >> 1) + 1, e, (idx << 1) + 1));   }   int l, r, val;   inline int update(int s, int e, int idx) {     fix(s, e, idx);     if (s > r || e < l) return seg[idx];     if (s >= l && e <= r) {       lazy[idx] += val;       fix(s, e, idx);       return seg[idx];     }     return seg[idx] = max(update(s, ((s + e) >> 1), (idx << 1)),                           update(((s + e) >> 1) + 1, e, (idx << 1) + 1));   }   int s, e, idx, mid;   inline int Lower_bound(int val) {     s = 0, e = n, idx = 1;     while (true) {       fix(s, e, idx);       if (s == e) return s;       mid = ((s + e) >> 1);       fix(s, mid, (idx << 1));       fix(mid + 1, e, (idx << 1) + 1);       if (seg[(idx << 1)] >= val) {         idx = (idx << 1);         e = mid;       } else {         idx = (idx << 1) + 1;         s = mid + 1;       }     }     assert(false);   }   int Idx;   inline int get() {     s = 0, e = n, idx = 1;     while (true) {       fix(s, e, idx);       if (s == e) return seg[idx];       mid = ((s + e) >> 1);       if (Idx <= mid) {         idx = (idx << 1);         e = mid;       } else {         idx = (idx << 1) + 1;         s = mid + 1;       }     }     assert(false);   }   int tmp1, tmp2, tmp3, tmp4, tmp5;   int tmp7 = 0, tmp8 = 0;   void check2(int cur) {     for (int i = 1; i <= 4 * (n + 1); i++) seg[i] = lazy[i] = 0;     arr[n] = cur;     for (int i = 0; i <= n; i++) {       arr2[i] = arr[i];     }     sort(arr2, arr2 + n + 1);     build(0, n, 1);     tmp7 = 0;     for (int i = n; i >= 0; i--) {       Idx = i;       tmp1 = get();       if (tmp1 <= 0) {         tmp7 -= tmp1;         continue;       }       if (i - tmp1 < 0) {         l = 0, r = i - 1, val = -1;         update(0, n, 1);         tmp7 -= (i - tmp1);         continue;       }       Idx = i - tmp1;       tmp2 = get();       tmp3 = Lower_bound(tmp2);       Idx = i - 1;       tmp4 = get();       if (tmp2 == tmp4) {         l = tmp3;         r = tmp3 + tmp1 - 1;         val = -1;         update(0, n, 1);       } else {         tmp5 = Lower_bound(tmp2 + 1);         l = tmp5;         r = i - 1;         val = -1;         update(0, n, 1);         l = tmp3;         r = l + (tmp5 - (i - tmp1)) - 1;         val - 1;         update(0, n, 1);       }     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &arr[i]);     }     check2(0);     tmp8 = tmp7;     check2(n);     tmp7 = n - tmp7;     if (tmp7 < tmp8) {       puts( -1 );       return 0;     }     for (int i = tmp8; i <= tmp7; i += 2) {       printf( %d  , i);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 6;   int n, Arr[6];   int solve(int rem, int mask) {     if (mask == ((1 << MX) - 1)) return 0;     int Ans = 50;     for (int i = 0; i < MX; i++) {       if (!(mask & (1 << i))) {         if (rem < Arr[i])           Ans = min(Ans, 1 + solve(n - Arr[i], mask | (1 << i)));         else           Ans = min(Ans, solve(rem - Arr[i], mask | (1 << i)));       }     }     return Ans;   }   int main() {     scanf( %d %d %d , &n, &Arr[0], &Arr[2]);     Arr[1] = Arr[3] = Arr[4] = Arr[0];     Arr[5] = Arr[2];     printf( %d n , solve(0, 0));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int in() {     int x, y;     y = scanf( %d , &x);     return x;   }   const int MAXN = 2e6 + 10;   int n, p[MAXN], sec[MAXN], pt[MAXN];   string s;   int nxt[MAXN], prv[MAXN];   int d[MAXN][2];   bool ok(int mid, int sz) {     memset(d, 0, sizeof(d));     d[0][0] = d[0][1] = 1;     for (int i = 1; i <= n; i++) {       if (s[i - 1] ==  . )         d[i][0] = d[i - 1][0];       else if (s[i - 1] ==  P )         d[i][0] = d[i - 1][1];       else {         int xx = prv[i - 1];         if (~xx && xx + mid >= i - 1) {           d[i][0] |= d[xx][0];           int temp = prv[xx];           if (~temp && temp + mid >= i - 1) {             int t = max(0, xx - mid);             int temp2 = 0;             if (t && nxt[t - 1] < temp) temp2 = 1;             d[i][0] |= d[t][temp2];           }         }       }       int xx = nxt[i - 1];       if (xx < n) {         int temp = max(0, xx - mid);         temp = min(temp, i);         int temp2 = 0;         if (temp && nxt[temp - 1] < xx) temp2 = 1;         d[i][1] |= d[temp][temp2];       }     }     return d[n][0];   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> s;     int sz = 0, c = 0;     for (int i = 0; i < n; i++)       if (s[i] ==  P )         sec[sz++] = i;       else if (s[i] ==  * )         c++;     int mn = 1e9, mx = -1;     for (int i = 0; i < n; i++) {       p[i + 1] = p[i];       if (s[i] ==  * ) {         p[i + 1]++;         mn = min(mn, i);         mx = max(mx, i);       }     }     int last = n;     for (int i = n - 1; ~i; i--) {       nxt[i] = last;       if (s[i] ==  P ) last = i;     }     last = -1;     for (int i = 0; i < n; i++) {       prv[i] = last;       if (s[i] ==  P ) last = i;     }     memcpy(pt, p, sizeof(p));     if (sz == 1) {       if (mn > sec[0])         cout << c <<     << mx - sec[0] <<   n ;       else if (mx < sec[0])         cout << c <<     << sec[0] - mn <<   n ;       else {         if (p[sec[0]] > c - p[sec[0]])           cout << p[sec[0]] <<      << sec[0] - mn <<   n ;         else if (p[sec[0]] < c - p[sec[0]])           cout << c - p[sec[0]] <<     << mx - sec[0] <<   n ;         else           cout << p[sec[0]] <<     << min(sec[0] - mn, mx - sec[0]) <<   n ;       }     } else {       int lo = 0, hi = n - 1;       while (hi - lo > 1) {         int mid = hi + lo >> 1;         if (ok(mid, sz))           hi = mid;         else           lo = mid;       }       cout << c <<     << hi <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e15;   int n, B, c0[5010], c1[5010];   vector<int> e[5010];   vector<long long> f[5010], g[5010];   void combine(vector<long long>& a, const vector<long long>& b) {     int la = a.size(), lb = b.size(), lc = la + lb - 1;     vector<long long> c(lc);     for (int i = 0; i < lc; ++i) c[i] = inf;     for (int i = 0; i < la; ++i)       for (int j = 0; j < lb; ++j) c[i + j] = min(c[i + j], a[i] + b[j]);     a = c;   }   void dfs(int x) {     vector<long long> a, b;     a.push_back(0);     b.push_back(0);     for (int v : e[x]) {       dfs(v);       combine(a, f[v]);       combine(b, g[v]);     }     f[x].push_back(0);     for (int i = 0; i < a.size(); ++i) {       f[x].push_back(a[i] + c0[x]);     }     g[x] = b;     g[x].push_back(inf);     for (int i = 0; i < b.size(); ++i) {       g[x][i + 1] = min(g[x][i + 1], b[i] + c1[x]);     }     for (int i = 0; i < b.size(); ++i) {       f[x][i] = min(f[x][i], g[x][i]);     }   }   int main() {     scanf( %d%d , &n, &B);     for (int i = 1; i <= n; ++i) {       scanf( %d%d , &c1[i], &c0[i]);       c0[i] = c1[i] - c0[i];       int fa;       if (i != 1) scanf( %d , &fa), e[fa].push_back(i);     }     dfs(1);     int ans = 0;     for (int i = 0; i < f[1].size(); ++i)       if (f[1][i] <= B) ans = i;     for (int i = ans + 1; i <= (int)g[1].size() - 1; ++i)       if (g[1][i] <= B) ans = i;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct keep {     int pos;     int apples;   };   keep inp[1000];   bool cmp(keep x, keep y) {     if (x.pos < y.pos) return 1;     return 0;   }   int main() {     int n;     cin >> n;     int l = 0, r = 0;     int sum = 0;     for (int i = 0; i < n; i++) {       cin >> inp[i].pos >> inp[i].apples;       inp[i].pos < 0 ? l++ : r++;       sum += inp[i].apples;     }     sort(inp, inp + n, cmp);     if (l == 0) {       cout << inp[0].apples;       return 0;     }     if (r == 0) {       cout << inp[n - 1].apples;       return 0;     }     if (l - r == 1 || r - l == 1 || l == r) {       cout << sum << endl;       return 0;     }     if (l > r) {       int ans = 0;       int c = 0;       int i;       for (i = n - 1; inp[i].pos > 0; i--) {         ans += inp[i].apples;         c++;       }       int cc = 1;       for (; cc <= c + 1; i--) {         ans += inp[i].apples;         cc++;       }       cout << ans;       return 0;     }     if (r > l) {       int ans = 0;       int c = 0;       int i;       for (i = 0; inp[i].pos < 0; i++) {         ans += inp[i].apples;         c++;       }       int cc = 1;       for (; cc <= c + 1; i++) {         ans += inp[i].apples;         cc++;       }       cout << ans;       return 0;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     long int n, k, i, *a, *b, t, max, j;     scanf( %ld , &t);     while (t--) {       scanf( %ld , &n);       a = (long int *)malloc(n * sizeof(long int));       b = (long int *)malloc(n * sizeof(long int));       for (i = 0; i < n; i++) {         scanf( %ld , &a[i]);         b[a[i] - 1] = i;       }       max = n - 1;       if (b[0] != 0) k = b[0] - 1;       for (j = 0, i = 0; j < n - 1; j++) {         if (b[i] == max) {           max = k;           k = b[i + 1] - 1;           i++;         } else {           if (b[i + 1] != b[i] + 1)             break;           else             i++;         }       }       if (j == n - 1)         printf( Yes n );       else         printf( No n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300010;   const int INF = 1e9 + 7;   struct node {     int x, y;   } p[maxn];   int s[maxn];   int dis(int i, int j) { return abs(p[i].x - p[j].x) + abs(p[i].y - p[j].y); }   int main() {     int n, top, i, num, ans, maxx, maxy, minx, miny, tmp, j, pos1, pos2, k;     scanf( %d , &n);     maxx = -INF;     maxy = -INF;     minx = INF;     miny = INF;     for (i = 1; i <= n; i++) {       scanf( %d%d , &p[i].x, &p[i].y);       maxx = max(maxx, p[i].x);       maxy = max(maxy, p[i].y);       minx = min(minx, p[i].x);       miny = min(miny, p[i].y);     }     top = 0;     for (i = 1; i <= n; i++) {       if (p[i].x == minx || p[i].x == maxx || p[i].y == miny || p[i].y == maxy)         s[++top] = i;     }     ans = 0;     num = unique(s + 1, s + top + 1) - s - 1;     for (i = 1; i <= num; i++) {       for (j = i + 1; j <= num; j++) {         pos1 = s[i];         pos2 = s[j];         for (k = 1; k <= n; k++) {           if (k == pos1 || k == pos2) continue;           tmp = dis(pos1, pos2) + dis(pos1, k) + dis(k, pos2);           ans = max(ans, tmp);         }       }     }     for (i = 3; i <= n; i++) {       if (i == 3) {         printf( %d  , ans);         continue;       }       printf( %d  , 2 * (maxx - minx + maxy - miny));     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, k;     cin >> n >> k;     vector<int> arr(k);     for (int i = 0; i < k; i++) {       arr[i] = i + 1;     }     vector<string> allPos;     do {       string s =   ;       for (int x : arr) {         s += (x +  0 );       }       allPos.emplace_back(s);     } while (next_permutation((arr).begin(), (arr).end()));     vector<string> v(n), tempV(n);     for (int i = 0; i < n; i++) {       cin >> v[i];       tempV[i] = v[i];     }     int ans = INT_MAX;     for (string current : allPos) {       vector<int> temp(n);       int index = 0;       for (char ch : current) {         for (int i = 0; i < n; i++) {           tempV[i][index] = v[i][ch -  0  - 1];         }         index++;       }       for (int i = 0; i < n; i++) {         temp[i] = stoi(tempV[i]);       }       ans = min(ans, *max_element((temp).begin(), (temp).end()) -                          *min_element((temp).begin(), (temp).end()));     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 4e5 + 5;   int vis[MAX];   vector<int> adj[MAX];   vector<vector<int> > trip;   void dfs(int x) {     vis[x] = 1;     for (auto u : adj[x]) {       if (!vis[u]) {         for (auto v1 : adj[x]) {           for (auto v2 : adj[u]) {             if (!vis[v1] && !vis[v2] && v1 == v2) {               vector<int> triplet;               triplet.push_back(x);               triplet.push_back(u);               triplet.push_back(v1);               trip.push_back(triplet);             }           }         }       }     }   }   int main() {     int n, m, x, y, minm = 1e9 + 9;     cin >> n >> m;     memset(vis, 0, sizeof(vis));     for (int i = 0; i < m; i++) {       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     for (int i = 0; i < n; i++) {       if (!vis[i]) dfs(i);     }     for (auto v : trip) {       minm = min(minm, (int)(adj[v[0]].size() + adj[v[1]].size() +                              adj[v[2]].size() - 6));     }     if (!trip.empty())       cout << minm << endl;     else       cout << -1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   int v1[10], v2[10];   int main() {     memset(v1, 0, sizeof(v1));     memset(v2, 0, sizeof(v2));     int n;     scanf( %d , &n);     for (int i = 0, a; i < n; i++) {       scanf( %d , &a);       v1[a]++;     }     for (int i = 0, a; i < n; i++) {       scanf( %d , &a);       v2[a]++;     }     int ans = 0;     bool flag = true;     for (int i = 1; i <= 5 && flag; i++) {       if ((v1[i] + v2[i]) & 1) {         flag = false;       }       ans += abs(v1[i] - v2[i]) / 2;     }     if (flag)       printf( %d n , ans / 2);     else {       printf( -1 n );     }     return 0;   }


#include <bits/stdc++.h>   const long long MAXN = 80000 + 5;   std::vector<long long> G[MAXN];   long long n;   long long sz[MAXN], fa[MAXN];   inline void dfs1(long long v, long long faa = 0) {     sz[v] = 1;     fa[v] = faa;     for (auto x : G[v]) {       if (x == faa) continue;       dfs1(x, v);       sz[v] += sz[x];     }   }   long long ans = 0ll;   inline long long C(long long x) { return 1ll * x * (x - 1) / 2; }   signed main() {     scanf( %lld , &n);     for (register long long i = 1; i <= n - 1; ++i) {       long long u, v;       scanf( %lld%lld , &u, &v);       G[u].push_back(v);       G[v].push_back(u);     }     dfs1(1);     ans = C(n) * C(n);     for (register long long i = 1; i <= n; ++i) {       long long num2 = C(sz[i]), num1 = C(n);       for (auto x : G[i]) {         if (x == fa[i]) {           num1 -= C(n - sz[i]);           continue;         }         num2 -= C(sz[x]);         num1 -= C(sz[x]);       }       ans -= (2ll * num1 * num2 - num2 * num2);     }     std::cout << ans << std::endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int a[N], n;   int dp[N];   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     for (int i = 1; i <= n; ++i) {       dp[i] = dp[i - 1] + 20;       for (int j = i - 1; j > 0; j--) {         if (a[i] - a[j] < 90)           dp[i] = min(dp[i], dp[j - 1] + 50);         else if (a[i] - a[j] < 1440)           dp[i] = min(dp[i], dp[j - 1] + 120);         else           break;       }       cout << dp[i] - dp[i - 1] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const int N = 1000000 + 5;   const int K = 26 + 5;   char s[N], t[N];   int ns[K], nt[K], ans[K];   int main() {     scanf( %s %s , s, t);     for (int i = 0; t[i]; ++i) {       nt[t[i] -  a ]++;     }     int cnt = 0;     for (int i = 0; s[i]; ++i) {       if (s[i] !=  ? )         ns[s[i] -  a ]++;       else         cnt++;     }     while (1) {       int c = 0;       for (int i = 0; i < 26; ++i) {         if (nt[i]) c += max(0, nt[i] - ns[i]);       }       if (cnt < c) break;       for (int i = 0; i < 26; ++i) {         if (nt[i]) {           ans[i] += max(0, nt[i] - ns[i]);           ns[i] = max(0, ns[i] - nt[i]);         }       }       cnt -= c;     }     int k = 0;     for (int i = 0; s[i]; ++i) {       if (s[i] ==  ? ) {         while (k < 26 && ans[k] <= 0) k++;         if (k < 26) ans[k]--;         printf( %c ,  a  + (k < 26 ? k : 0));       } else {         printf( %c , s[i]);       }     }     printf(  n );   }


#include <bits/stdc++.h>   const long long INF = 0x3f3f3f3f3f3f3f3fLL;   const int inf = 0x3f3f3f3f;   const int mod = 1e9 + 7;   const double eps = 1e-6;   template <class T>   inline void read(T& x) {     int sign = 1;     char c = getchar();     x = 0;     while (c >  9  || c <  0 ) {       if (c ==  - ) sign = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     x *= sign;   }   using namespace std;   const int maxn = 5e6 + 10;   unsigned long long ji = 1;   long long dp[maxn];   unsigned long long prehash[maxn], sufhash[maxn];   char s[maxn];   inline int val(char x) {     if (x >=  0  && x <=  9 ) return x -  0 ;     if (x >=  a  && x <=  z ) return x -  a  + 10;     if (x >=  A  && x <=  Z ) return x -  Z  + 36;   }   int main() {     scanf( %s , s + 1);     int len = 0;     for (int i = 1; s[i]; ++i) s[i] = val(s[i]);     for (int i = 1; s[i]; ++i) prehash[i] = prehash[i - 1] * 131 + 1ll * s[i];     for (int i = 1; s[i]; ++i) {       sufhash[i] = sufhash[i - 1] + 1ll * s[i] * ji;       ji *= 131;     }     long long res = 0;     for (int i = 1; s[i]; ++i) {       if (prehash[i] == sufhash[i]) {         dp[i] = dp[i >> 1] + 1;       }       res += dp[i];     }     printf( %lld n , res);   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-10;   pair<double, double> za, zb, zc, zd;   pair<double, double> a, b, c, d, e;   pair<double, double> A, B, C, D;   double cha(pair<double, double> a, pair<double, double> b,              pair<double, double> c) {     return (b.first - a.first) * (c.second - a.second) -            (b.second - a.second) * (c.first - a.first);   }   pair<double, double> jiao(pair<double, double> a, pair<double, double> b,                             pair<double, double> c, pair<double, double> d) {     double t1 = cha(a, c, b), t2 = cha(a, b, d), t3 = cha(c, a, d),            t4 = cha(c, d, b);     return make_pair((c.first * t2 + d.first * t1) / (t1 + t2),                      (c.second * t2 + d.second * t1) / (t1 + t2));   }   void work(pair<double, double> a, pair<double, double> b,             pair<double, double> &c, pair<double, double> &d) {     c = make_pair((a.first + b.first) / 2, (a.second + b.second) / 2);     d = make_pair(c.first + b.second - a.second, c.second + a.first - b.first);   }   bool get(pair<double, double> a, pair<double, double> b,            pair<double, double> c) {     work(a, b, za, zb), work(b, c, zc, zd);     d = make_pair(b.first + zd.first - zc.first,                   b.second + zd.second - zc.second);     d = jiao(b, d, za, zb);     e = jiao(za, zb, zc, zd);     A = make_pair(2 * d.first - e.first, 2 * d.second - e.second);     B = make_pair(2 * b.first - A.first, 2 * b.second - A.second);     C = make_pair(2 * c.first - B.first, 2 * c.second - B.second);     D = make_pair(2 * a.first - A.first, 2 * a.second - A.second);     return cha(A, B, C) * cha(B, C, D) - eps > 0 &&            cha(B, C, D) * cha(C, D, A) - eps > 0 &&            cha(C, D, A) * cha(D, A, B) - eps > 0;   }   int main() {     int t;     for (scanf( %d , &t); t--;) {       scanf( %lf%lf%lf%lf%lf%lf , &a.first, &a.second, &b.first, &b.second,             &c.first, &c.second);       if (fabs(cha(a, b, c)) - eps < 0) {         printf( NO n );         continue;       }       if (get(a, b, c) || get(a, c, b) || get(b, a, c)) {         printf( YES n );         printf( %.9f %.9f  , A.first, A.second);         printf( %.9f %.9f  , B.first, B.second);         printf( %.9f %.9f  , C.first, C.second);         printf( %.9f %.9f n , D.first, D.second);       } else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200009;   long long N, M;   long long Max[MAXN], A[MAXN];   long long maxLL(long long num1, long long num2) {     return (num1 > num2 ? num1 : num2);   }   void Update(int x, long long nh) {     for (int i = x; i <= N; i += (i & (-i))) Max[i] = maxLL(Max[i], nh);   }   long long Find(int x) {     long long ret = 0;     for (int i = x; i >= 1; i -= (i & (-i))) ret = maxLL(ret, Max[i]);     return ret;   }   int main() {     cin >> N;     for (int i = 1; i <= N; i++) Max[i] = 0;     for (int i = 1; i <= N; i++) {       cin >> A[i];       Update(i, A[i]);     }     cin >> M;     for (int i = 1; i <= M; i++) {       long long Xx, Yy;       cin >> Xx >> Yy;       long long Ans = Find(Xx);       Update(1, Ans + Yy);       cout << Ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<long double, int> > v;   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       long double x, y;       cin >> x >> y;       v.push_back(make_pair(atan2(y, x), i));     }     sort(v.begin(), v.end());     v.push_back(v[0]);     if (v.back().first < 0.0)       v.back().first = (2 * acos(0.0) + v.back().first + 2 * acos(0.0));     long double ans = 1e18;     int id1, id2;     for (int i = 1; i < (int)v.size(); i++) {       long double x = fabs(v[i].first - v[i - 1].first);       if (x < ans) {         ans = x;         id1 = v[i].second;         id2 = v[i - 1].second;       }     }     cout << id1 <<     << id2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 10;   int main() {     int n;     cin >> n;     int an[n];     vector<int> p;     vector<pair<int, int> > st;     int i = 0;     for (int a = 0; a < n * 2; a++) {       char sy;       cin >> sy;       if (sy ==  + ) {         p.push_back(i++);         st.push_back({0, 1});       } else {         int x;         scanf( %d , &x);         if (st.size() and x > st.back().first) {           int su = 0;           while (st.size() and st.back().first < x) {             su += st.back().second;             st.pop_back();           }           su--;           if (su) st.push_back({x, su});           an[p.back()] = x;           p.pop_back();         } else {           cout <<  NO ;           return 0;         }       }     }     cout <<  YES n ;     for (int a = 0; a < n; a++) printf( %d  , an[a]);   }


#include <bits/stdc++.h>   using namespace std;   int arr[2010], money, mn, mx, ans;   vector<pair<int, int> > tmp;   int main() {     int n, b;     cin >> n >> b;     for (int i = 0; i < n; i++) {       cin >> arr[i];       tmp.push_back(make_pair(arr[i], i));     }     sort(tmp.rbegin(), tmp.rend());     for (int i = 0; i < n; i++) {       mx = tmp[i].first, mn = 1e8;       for (int j = 0; j < tmp[i].second; j++) {         mn = min(mn, arr[j]);       }       money = b / mn;       money *= mx;       money += (b % mn);       ans = max(ans, money);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   bool comp(string s, string t, vector<int> rows) {     int i = 0;     int m = s.size();     while (i < m &&            (s[i] == t[i] || (find(rows.begin(), rows.end(), i) != rows.end())))       i++;     if (i == m) return false;     return s[i] < t[i];   }   int main() {     int n, m;     cin >> n >> m;     vector<string> table(n);     for (int i = 0; i < n; i++) cin >> table[i];     vector<int> rows;     for (int j = 0; j < m; j++) {       for (int i = 1; i < n; i++) {         int k = i - 1;         if (comp(table[i], table[k], rows)) {           for (int l = 0; l < m; l++) {             if (find(rows.begin(), rows.end(), l) != rows.end()) continue;             if (table[i][l] < table[k][l]) {               rows.push_back(l);               break;             }           }         }       }     }     cout << rows.size() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long p = 1000000007;   int q[200005][3];   int n, cnt = 1;   vector<int> c[200005];   int v[200005];   int l[200005];   int r[200005];   int f[200005];   long long rev[200005];   void eec_solve(long long& a, const long long x, long long& b,                  const long long y) {     if (y == 0) {       a = 1;       b = 0;       return;     }     long long q = x / y, r = x % y, c = 0, d = 0;     eec_solve(c, y, d, r);     a = d;     b = c - a * q;   }   int solve_lr(int ind, int cur) {     l[ind] = cur;     int tmp = 1;     for (int i = 0; i < c[ind].size(); ++i) tmp += solve_lr(c[ind][i], cur + tmp);     r[ind] = cur + tmp - 1;     return tmp;   }   struct seg {     long long v, c;   };   seg segt[800005];   void init(int x, int ll, int rr) {     segt[x].v = 0;     segt[x].c = 1;     if (ll != rr) {       segt[x].v = 0;       segt[x].c = 1;       int k = (ll + rr) / 2;       init(x * 2, ll, k);       init(x * 2 + 1, k + 1, rr);     }   }   void insert(int ind, int v) {     int x = 1, ll = 1, rr = cnt, k;     long long cum = v;     while (ll != rr) {       k = (ll + rr) / 2;       if (ind <= k) {         x = x * 2;         rr = k;       } else {         x = x * 2 + 1;         ll = k + 1;       }     }     while (x > 0) {       segt[x].v = (segt[x].v + cum) % p;       cum = (cum * segt[x].c) % p;       x = x / 2;     }   }   void change(int x, int ll, int rr, int i, int j, int cc) {     if ((ll == i) && (rr == j)) {       segt[x].c = (((segt[x].c * rev[cc]) % p) * (cc + 1)) % p;       return;     }     int k = (ll + rr) / 2;     if (i <= k) change(x * 2, ll, k, i, min(k, j), cc);     if (j > k) change(x * 2 + 1, k + 1, rr, max(i, k + 1), j, cc);     segt[x].v =         (segt[x * 2].v * segt[x * 2].c + segt[x * 2 + 1].v * segt[x * 2 + 1].c) %         p;   }   long long sum(int x, int ll, int rr, int i, int j) {     if ((ll == i) && (rr == j)) return (segt[x].v * segt[x].c) % p;     int k = (ll + rr) / 2;     long long res = 0;     if (i <= k) res += sum(x * 2, ll, k, i, min(k, j));     if (j > k) res += sum(x * 2 + 1, k + 1, rr, max(i, k + 1), j);     return ((res % p) * segt[x].c) % p;   }   long long getC(int ind) {     long long res = 1;     int x = 1, ll = 1, rr = cnt, k;     while (ll != rr) {       res = (res * segt[x].c) % p;       k = (ll + rr) / 2;       if (ind <= k) {         x = x * 2;         rr = k;       } else {         x = x * 2 + 1;         ll = k + 1;       }     }     res = (res * segt[x].c) % p;     return res;   }   int main() {     cin >> v[1] >> n;     for (int i = 0; i < n; ++i) {       cin >> q[i][0] >> q[i][1];       if (q[i][0] == 1) {         cin >> q[i][2];         v[++cnt] = q[i][2];         c[q[i][1]].push_back(cnt);         f[cnt] = q[i][1];         q[i][2] = c[q[i][1]].size();       }     }     for (int i = 1; i <= cnt; ++i) {       eec_solve(rev[i], i, rev[i + 1], p);       rev[i] = ((rev[i] % p) + p) % p;     }     solve_lr(1, 1);     init(1, 1, cnt);     insert(1, v[1]);     int new_cnt = 1;     for (int i = 0; i < n; ++i)       if (q[i][0] == 1) {         ++new_cnt;         insert(l[new_cnt], v[new_cnt]);         change(1, 1, cnt, l[q[i][1]], r[q[i][1]], q[i][2]);       } else {         long long res = sum(1, 1, cnt, l[q[i][1]], r[q[i][1]]);         if (q[i][1] != 1) {           long long x = getC(l[f[q[i][1]]]);           long long ta, tb;           eec_solve(ta, x, tb, p);           ta = ((ta % p) + p) % p;           res = (res * ta) % p;         }         cout << res << endl;       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int o[101];   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int e;       cin >> e;       if (e % 7 == 0) {         o[i] = e / 7;       } else {         o[i] = e / 7 + 1;       }     }     for (int i = 0; i < t; i++) {       cout << o[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   int n, m, col[maxn];   set<int> s;   set<int>::iterator t[maxn];   int main() {     while (~scanf( %d %d , &n, &m)) {       s.clear();       for (int i = 1; i <= n; i++) s.insert(i);       int cnt = 0;       while (m--) {         int l, r, c;         scanf( %d %d %d , &l, &r, &c);         cnt = 0;         for (auto it = s.lower_bound(l); *it <= r && it != s.end(); it++) {           if (*it != c) {             col[*it] = c;             t[cnt++] = it;           }         }         for (int i = 0; i < cnt; i++) {           s.erase(t[i]);         }       }       for (int i = 1; i <= n; i++) {         printf( %d  , col[i]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d%d , &n, &m);     vector<int> mp(32);     vector<int> A(m);     for (int i = 0; i < n; i++) {       int no;       scanf( %d , &no);       for (int ii = 0; ii < 31; ii++)         if (no & (1 << ii)) mp[ii]++;     }     for (int i = 0; i < m; i++) scanf( %d , &A[i]);     sort(A.begin(), A.end());     int res = 0;     for (int i = 0; i < A.size(); i++) {       for (int ii = A[i]; ii < 31; ii++)         if (mp[ii] > 0) {           res++;           mp[ii]--;           for (int iii = A[i]; ii != A[i] && iii < ii; iii++) mp[iii]++;           break;         }     }     printf( %d n , res);   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e2 + 7;   const long long nol = 0;   long long n;   string g, s;   void vkoshp() {     cin >> n;     while (n >= 2) {       g +=  1 ;       n -= 2;     }     if (n == 1) {       s +=  7 ;       g.erase(g.begin());       s += g;       g = s;     }     cout << g;   }   int main() {     cout.tie(NULL);     cin.tie(NULL);     ios_base::sync_with_stdio(0);     long long t = 1;     while (t--) vkoshp();   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   const long long int N = 1e5 + 5;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int i, j, tc;     cin >> tc;     while (tc--) {       long long int n, w;       cin >> n >> w;       long long int a[n];       for (i = 0; i < n; i++) {         cin >> a[i];       }       vector<long long int> v;       for (i = 0; i < n; i++) {         if (a[i] <= w && a[i] >= (w + 1) / 2) {           v.push_back(i + 1);           break;         }       }       if (v.size() == 1) {         cout << 1 <<   n ;         cout << v[0] <<   n ;         continue;       }       long long int sum = 0;       for (i = 0; i < n; i++) {         if (a[i] <= w) {           sum += a[i];           v.push_back(i + 1);           if (sum >= (w + 1) / 2) break;         }       }       if (sum >= (w + 1) / 2 && sum <= w) {         cout << v.size() <<   n ;         for (i = 0; i < v.size(); i++) cout << v[i] <<    ;         cout <<   n ;       } else         cout << -1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   constexpr long long N = 600500;   constexpr long long D = 2000010;   constexpr long double EPS = 1e-8;   ofstream fout;   ifstream fin;   int flag = -1;   long long n, m, k;   vector<vector<int> > v;   vector<int> h;   vector<int> was;   bool comp(int a, int b) { return h[a] > h[b]; }   multiset<int, bool (*)(int, int)> s(comp);   void dfs(int x) {     int o = 0;     was[x] = 1;     for (auto &y : (v[x])) {       if (!was[y]) {         dfs(y);         o = max(o, h[y]);       }     }     h[x] = o + 1;   }   void dfs1(int x) {     was[x] = 1;     int u, m = -1;     for (auto &y : (v[x])) {       if (!was[y]) {         if (h[y] > m) {           m = h[y];           u = y;         }       }     }     if (m == -1) return;     for (auto &y : (v[x])) {       if (!was[y]) {         if (y == u) {           dfs1(y);         } else {           s.insert(y);         }       }     }   }   void solve() {     long long a, b;     cin >> n >> k;     s.clear();     v.clear();     h.clear();     was.clear();     v.resize(n);     h.resize(n);     was.resize(n);     for (long long i = 0; i < (n - 1); i++) {       cin >> a >> b;       a--;       b--;       v[a].push_back(b);       v[b].push_back(a);     }     dfs(0);     s.insert(0);     fill(was.begin(), was.end(), 0);     a = k;     k = 0;     while (k < a && !s.empty()) {       k++;       int x = *s.begin();       s.erase(s.begin());       dfs1(x);     }     long long mx = -((long long)1e15);     long long e = count(was.begin(), was.end(), 1);     if (k < a) {       for (long long i = (k); i < (a + 1); i++) {         mx = max(mx, (e - i) * (i));       }     } else {       mx = ((long long)1e15);       long long p = count(was.begin(), was.end(), 0);       for (long long i = (0); i < (p + 1); i++) {         mx = min(mx, (e - a + (p - i)) * (a - i));       }     }     cout << mx <<   n ;   }   signed main(signed argc, char *argv[]) {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout.precision(14);     cout.fixed;     srand(time(0));     fout.precision(14);     fout.fixed;     int tt = 1;     while (tt--) {       solve();     }     fout.close();     fin.close();   }


#include <bits/stdc++.h>   using namespace std;   template <typename First>   void debug_print_in(First first) {     cerr << first << endl;     return;   }   template <typename First, typename... Rest>   void debug_print_in(First first, Rest... rest) {     cerr << first <<    ;     debug_print_in(rest...);     return;   }   void IN(void) { return; }   template <typename First, typename... Rest>   void IN(First& first, Rest&... rest) {     cin >> first;     IN(rest...);     return;   }   template <typename First>   void OUT(First first) {     cout << first << endl;     return;   }   template <typename First, typename... Rest>   void OUT(First first, Rest... rest) {     cout << first <<    ;     OUT(rest...);     return;   }   template <class t, class u>   t chmax(t& a, u b) {     if (a < b) a = b;     return a;   };   template <class t, class u>   t chmin(t& a, u b) {     if (a > b) a = b;     return a;   };   int popcount(int t) { return __builtin_popcount(t); }   int popcount(long long t) { return __builtin_popcountll(t); }   template <typename T>   void vec_print(vector<T> VEC) {     for (long long i = (long long)0; i < (long long)VEC.size(); ++i) {       cerr << VEC[i] <<    ;     }     cerr << endl;   };   template <typename T>   void mat_print(vector<vector<T>> MAT) {     for (long long i = (long long)0; i < (long long)MAT.size(); ++i) {       for (long long j = (long long)0; j < (long long)MAT[i].size(); ++j) {         cerr << MAT[i][j] <<    ;       }       cerr << endl;     }   };   constexpr int INF = (1 << 30);   constexpr long long INFLL = 1LL << 62;   constexpr long double EPS = 1e-12;   constexpr long long MOD = (long long)((1E+9) + 7);   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     long long n;     IN(n);     vector<long long> a(n);     for (long long i = (long long)0; i < (long long)n; ++i) IN(a[i]);     vector<long long> d1(n, -1);     vector<long long> d2(n, -1);     vector<long long> primes(1, 2);     for (long long i = 3; i * i <= 2E7; i += 2) {       bool flag = true;       for (long long j = 0; primes[j] * primes[j] <= i; ++j) {         if (i % primes[j] == 0) {           flag = false;           break;         }       }       if (flag) {         primes.push_back(i);       }     }     for (long long i = (long long)0; i < (long long)n; ++i) {       for (long long j = 0; primes[j] * primes[j] < a[i]; ++j) {         long long d1_ = primes[j];         if (a[i] % d1_ != 0) continue;         while (a[i] % d1_ == 0) {           a[i] /= d1_;         }         if (a[i] > 1) {           d1[i] = d1_;           d2[i] = a[i];         }         break;       }     }     for (long long i = (long long)0; i < (long long)n; ++i) {       printf( %lld  , d1[i]);     }     printf(  n );     for (long long i = (long long)0; i < (long long)n; ++i) {       printf( %lld  , d2[i]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &x) {     x = 0;     char c = getchar();     bool flag = false;     while (!isdigit(c)) {       if (c ==  - ) flag = true;       c = getchar();     }     while (isdigit(c)) {       x = (x << 1) + (x << 3) + (c ^ 48);       c = getchar();     }     if (flag) x = -x;   }   int n;   int siz[110];   double fac[110], f[110][110], g[110];   struct edge {     int to, nxt;     edge(int a = 0, int b = 0) { to = a, nxt = b; }   } e[110];   int head[110], edge_cnt;   void add(int from, int to) {     e[++edge_cnt] = edge(to, head[from]), head[from] = edge_cnt;   }   double C(int n, int m) { return fac[n] / fac[m] / fac[n - m]; }   void dfs(int x, int fa) {     f[x][0] = siz[x] = 1;     for (int i = head[x]; i; i = e[i].nxt) {       int y = e[i].to;       if (y == fa) continue;       dfs(y, x);       for (int j = 0; j <= siz[y]; ++j)         for (int k = 1; k <= siz[y]; ++k)           f[0][j] += k <= j ? f[y][k - 1] / 2 : f[y][j];       for (int j = siz[x] - 1; j >= 0; --j)         for (int k = siz[y]; k >= 0; --k)           g[j + k] += f[x][j] * f[0][k] * C(j + k, j) *                       C(siz[x] - 1 - j + siz[y] - k, siz[x] - 1 - j);       siz[x] += siz[y];       for (int i = 0; i < siz[x]; ++i) f[x][i] = g[i];       memset(g, 0, sizeof(g)), memset(f[0], 0, sizeof(f[0]));     }   }   int main() {     read(n);     for (int i = 1; i < n; ++i) {       int x, y;       read(x), read(y);       add(x, y), add(y, x);     }     fac[0] = 1;     for (int i = 1; i <= n; ++i) fac[i] = fac[i - 1] * i;     for (int i = 1; i <= n; ++i) {       memset(f, 0, sizeof(f)), dfs(i, 0);       printf( %.10lf n , f[i][n - 1] / fac[n - 1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int sc[1005];     int n, k, p, x, y;     cin >> n >> k >> p >> x >> y;     for (int i = 1; i <= k; i++) {       cin >> sc[i];       x -= sc[i];     }     if (x < 0) {       cout << -1 << endl;     } else {       int i;       int left_cnt = 0;       int rig_cnt = 0;       int equ_y_num = 0;       int half = n / 2;       sort(sc + 1, sc + k + 1);       for (i = 1; i <= k; i++) {         if (sc[i] < y) {           left_cnt++;         } else if (sc[i] == y) {           equ_y_num++;         } else {           rig_cnt++;         }       }       if (left_cnt > half) {         cout << -1 << endl;         return 0;       }       if (rig_cnt + equ_y_num >= (half + 1)) {         int need = n - k;         if (need > x) {           cout << -1 << endl;           return 0;         } else {           int time = n - k;           while (time--) {             cout << 1 <<    ;           }           cout << endl;           return 0;         }       }       int need = half + 1 - rig_cnt - equ_y_num;       need = need * y;       need += half - left_cnt;       if (need > x) {         cout << -1 << endl;         return 0;       } else {         int time = n - k;         int left_time = half - left_cnt;         while ((left_time--)) {           cout << 1 <<    ;           time--;         }         while ((time--)) {           cout << y <<    ;         }         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 505;   vector<int> ans;   struct node {     int val, id;     bool operator<(const node &o) const {       if (val == o.val) return id < o.id;       return val < o.val;     }   };   node a[MAXN], b[MAXN];   void doit(int n) {     for (int i = 1; i <= n - 2; i++) {       int id = i;       for (int j = i; j <= n; j++)         if (a[j] < a[id]) id = j;       for (int j = id; j >= i; j--) {         if (j - 2 >= i) {           ans.push_back(j - 2);           swap(a[j], a[j - 1]);           swap(a[j - 1], a[j - 2]);           j--;         } else if (j - 1 >= i) {           ans.push_back(j - 1);           ans.push_back(j - 1);           swap(a[j], a[j - 1]);           swap(a[j], a[j + 1]);         }       }     }   }   void solve() {     ans.clear();     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i].val);       a[i].id = i;     }     memcpy(b, a, sizeof(a));     doit(n);     if (a[n - 1].val > a[n].val) {       memcpy(a, b, sizeof(a));       bool flag = false;       for (int i = 1; i <= n && !flag; i++)         for (int j = i + 1; j <= n && !flag; j++)           if (a[i].val == a[j].val) {             swap(a[i], a[j]);             flag = true;           }       ans.clear();       doit(n);       if (a[n - 1].val > a[n].val) {         puts( -1 );         return;       }     }     printf( %d n , ans.size());     for (auto v : ans) printf( %d  , v);     puts(  );   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     vector<int> records;     int max = a[0];     records.push_back(0);     int case1 = -1;     int case1_records;     for (int i = 1; i < n; i++) {       if (max < a[i]) {         max = a[i];         records.push_back(i);       } else {         if (case1 == -1) {           case1 = i;         } else {           if (a[case1] > a[i]) {             case1 = i;           }         }       }     }     case1_records = records.size();     records.push_back(n);     int case2 = -1;     int case2_records = -1;     int case2_pos = -1;     for (int i = 0; i < records.size() - 1; i++) {       int left = records[i];       int right = records[i + 1];       int count = 0;       int max = 0;       if (i > 0) {         left = records[i - 1];         max = a[records[i - 1]];       }       for (int j = left + 1; j < right; j++) {         if (j != records[i])           if (max < a[j]) {             max = a[j];             count++;           }       }       if (case2 < count) {         case2 = count;         case2_pos = records[i];       }     }     case2_records = case1_records - 1 + case2;     if (case1 == -1) {       cout << a[case2_pos] << endl;     } else {       if (case1_records < case2_records) {         cout << a[case2_pos] << endl;       } else if (case1_records == case2_records) {         cout << min(a[case1], a[case2_pos]) << endl;       } else {         cout << a[case1] << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( O2,no-stack-protector,unroll-loops,fast-math )   const long long maxn = 1e5 + 10, maxm = 1e6 + 10, lg = 17, mod = 998244353,                   inf = 1e18;   long long n, len, a, b, par[maxn][lg + 1], h[maxn], zuz[maxn], tguz;   pair<long long, long long> mx[maxn][4];   vector<long long> g[maxn];   bool kor[maxn];   void dfd(long long v = 1, long long p = 0) {     h[v] = h[p] + 1;     par[v][0] = p;     for (int i = 1; i <= lg; i++) par[v][i] = par[par[v][i - 1]][i - 1];     fill(mx[v], mx[v] + 4, make_pair(0, v));     for (auto u : g[v])       if (u != p) {         dfd(u, v);         mx[v][0] = mx[u][3];         mx[v][0].first++;         sort(mx[v], mx[v] + 4);       }   }   void dfu(long long v = 1, long long p = 0) {     if (mx[v][1].first >= len) zuz[v]++, tguz++;     for (auto u : g[v])       if (u != p) {         mx[u][0] = (mx[v][3].second == mx[u][3].second ? mx[v][2] : mx[v][3]);         mx[u][0].first++;         sort(mx[u], mx[u] + 4);         dfu(u, v);         zuz[v] += zuz[u];       }   }   long long gup(long long v, long long x) {     for (int i = 0; i <= lg; i++)       if (x >> i & 1) v = par[v][i];     return v;   }   long long lca(long long v, long long u) {     if (h[v] < h[u]) swap(v, u);     v = gup(v, h[v] - h[u]);     if (v == u) return v;     for (int i = lg; i >= 0; i--)       if (par[v][i] != par[u][i]) v = par[v][i], u = par[u][i];     return par[v][0];   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long T;     cin >> T;     while (T--) {       cin >> n >> a >> b;       for (int i = 1; i < n; i++) {         long long v, u;         cin >> v >> u;         g[v].push_back(u), g[u].push_back(v);       }       dfd();       len = h[a] + h[b] - 2 * h[lca(a, b)];       dfu();       while (1) {         long long ms;         for (int i : {3, 2, 1, 0}) {           long long na = mx[a][i].second;           if (h[b] + h[na] - 2 * h[lca(b, na)] == len + mx[a][i].first) {             ms = mx[a][i].first;             a = na;             break;           }         }         long long o = lca(a, b);         if (h[b] - h[o] >= ms)           b = gup(b, ms);         else {           ms -= h[b] - h[o];           b = gup(a, h[a] - (h[o] + ms));         }         if (kor[a]) {           cout <<  NO n ;           break;         }         o = lca(a, b);         if (o == b) {           if (zuz[gup(a, h[a] - h[b] - 1)] < tguz) {             cout <<  YES n ;             break;           }         } else if (zuz[b]) {           cout <<  YES n ;           break;         }         kor[a] = 1;         swap(a, b);       }       for (int i = 1; i <= n; i++) {         g[i].clear(), kor[i] = 0, h[i] = 0, zuz[i] = 0;         memset(par[i], 0, sizeof(par[i]));       }       tguz = 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool visit[4];   long long dfs(vector<long long> &v, vector<char> &chars) {     long long res = LLONG_MAX;     if (v.size() == 1) {       return v.front();     }     for (int i = 0; i < v.size() - 1; i++) {       for (int j = i + 1; j < v.size(); j++) {         vector<long long> tmp = v;         tmp.erase(tmp.begin() + i);         tmp.erase(tmp.begin() + j - 1);         long long r = 0;         if (chars.front() ==  + ) {           r = v[i] + v[j];         } else {           r = v[i] * v[j];         }         tmp.push_back(r);         vector<char> ch = chars;         ch.erase(ch.begin());         res = min(res, dfs(tmp, ch));       }     }     return res;   }   int main() {     vector<long long> v(4);     vector<char> chars(3);     for (int i = 0; i < 4; i++) {       cin >> v[i];     }     for (int i = 0; i < 3; i++) {       cin >> chars[i];     }     cout << dfs(v, chars) << endl;     return 0;   }


#include<bits/stdc++.h>   using namespace std;   const int N = 55;      void solve()   {       int n;       int ans=0;       scanf( %d , &n);       for(int i=1;i<=n;i++)       {           int x;           scanf( %d , &x);           if(x!=2)    ans++;       }       cout<<ans<<endl;   }   int  main()   {       int t;       scanf( %d , &t);       while(t--)  solve();       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int work() {     long long n, q;     cin >> n >> q;     while (q--) {       long long x, y;       cin >> x >> y;       if ((x + y) % 2 == 0) {         long long w = 0;         long long a = (x - 1) / 2;         w += a * n;         if (x % 2 == 1) {           w += (y + 1) / 2;         } else {           w += (n + 1) / 2;           w += y / 2;         }         cout << w << endl;       } else {         long long w = (n * n + 1) / 2;         long long a = (x - 1) / 2;         w += a * n;         if (x % 2 == 1) {           w += y / 2;         } else {           w += n / 2;           w += (y + 1) / 2;         }         cout << w << endl;       }     }     return 0;   }   int main() {     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve(void) {     string a, b, c;     cin >> a >> b >> c;     int n = a.length();     for (int i = 0; i < n; i++) {       if (c[i] != a[i] && c[i] != b[i]) {         cout <<  NO n ;         return;       }     }     cout <<  YES n ;   }   int main(void) {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string mapp[105];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> mapp[i];     int sx = 0x3f3f3f3f, sy = 0x3f3f3f3f, ex = 0, ey = 0, cnt = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (mapp[i][j] ==  B ) {           sx = min(sx, i);           sy = min(sy, j);           ex = max(ex, i);           ey = max(ey, j);           cnt++;         }       }     }     if (cnt == 0) {       cout << 1;       return 0;     }     int len = max(ex - sx + 1, ey - sy + 1);     if (len > n || len > m) {       cout << -1;       return 0;     }     cout << len * len - cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int v, s, vs, sv;   void printAns() {     cout <<  vier:   << v <<   sieben:   << s <<   vs:   << vs <<   sv:   << sv          << endl;   }   int main() {     cin >> v >> s >> vs >> sv;     string ans =   ;     bool flag = true;     if (v < vs || s < vs || v < sv || v < sv)       flag = false;     else {       for (int i = 0; i < vs; i++) ans +=  47 ;       v -= vs;       s -= vs;       sv -= (vs - 1);       if (sv > 2 || sv < 0)         flag = false;       else {         if (sv == 1 || sv == 2) {           if (v && sv) {             ans +=  4 ;             v--;             sv--;           }           if (s && sv) {             ans =  7  + ans;             s--;             sv--;           }         }         if (s < 0 || v < 0 || sv != 0)           flag = false;         else {           if (ans.empty()) {             if (s && v)               flag = false;             else if (v)               ans.insert(0, v,  4 );             else if (s)               ans.insert(0, s,  7 );           } else {             for (int i = 0; i < (int)ans.length(); i++) {               if (!v && !s)                 break;               else if (ans[i] ==  4  && v) {                 ans.insert(i, v,  4 );                 v = 0;               }             }             for (int i = ans.length() - 1; i >= 0; i--) {               if (!v && !s)                 break;               else if (ans[i] ==  7  && s) {                 ans.insert(i, s,  7 );                 s = 0;               }             }           }         }       }     }     if (flag)       cout << ans << endl;     else       cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long GCD(long long a, long long b) {     while (b != 0) {       int t = a;       a = b;       b = t % b;     }     return a;   }   inline long long LCM(long long a, long long b) {     if (a == 0 || b == 0) return GCD(a, b);     return a * b / GCD(a, b);   }   inline long long CEIL(long long n, long long d) { return n / d + n % d != 0; }   inline long long ROUND(long long n, long long d) {     return n / d + (long long)((n % d) * 2 >= d);   }   inline long long POW(long long a, long long n) {     if (n < 0) return 0;     long long ret = 1;     while (n) {       if (n % 2) ret *= a;       a = a * a;       n /= 2;     }     return ret;   }   const int MAXN = 101, INF = 100000;   struct node {     node *l, *r, *p;     int bdp[MAXN], mdp[MAXN];     node(node *p = 0) : l(0), r(0), p(p) {       fill(bdp, bdp + MAXN, -INF);       fill(mdp, mdp + MAXN, INF);     }     node *child() {       if (!l)         return l = new node(this);       else         return r = new node(this);     }   } * root, *cur;   int p, m, n, op;   string str;   void input() { cin >> str >> p >> m; }   void dfs(node *u) {     if (!u->l) {       return;     }     node *l = u->l, *r = u->r;     dfs(l), dfs(r);     for (int(i) = (0); (i) < (int)(n + 1); ++(i)) {       for (int(j) = (0); (j) < (int)(i + 1); ++(j)) {         int k = i - j - (op == 1 ? 1 : 0);         if (k >= 0) u->bdp[i] = max(u->bdp[i], l->bdp[j] + r->bdp[k]);         if (k >= 0) u->mdp[i] = min(u->mdp[i], l->mdp[j] + r->mdp[k]);         k = i - j - (op == -1 ? 1 : 0);         if (k >= 0) u->bdp[i] = max(u->bdp[i], l->bdp[j] - r->mdp[k]);         if (k >= 0) u->mdp[i] = min(u->mdp[i], l->mdp[j] - r->bdp[k]);       }     }   }   int solve() {     if (p > m)       n = m, op = -1;     else       n = p, op = 1;     root = cur = new node();     for (int(i) = (0); (i) < (int)(str.size()); ++(i)) {       switch (str[i]) {         case  ( :         case  ? :           cur = cur->child();           break;         case  ) :           cur = cur->p;           break;         default:           cur->bdp[0] = cur->mdp[0] = str[i] -  0 ;           cur = cur->p;       }     }     assert(cur == 0);     dfs(root);     cout << root->bdp[n] <<   n ;     return 0;   }   void execute() { input(), solve(); }   int main(void) {     cin.tie(0);     ios_base::sync_with_stdio(false);     execute();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 205;   int mat[maxn][maxn], tmp[maxn][maxn];   int r[maxn], c[maxn];   int n, m;   void invRow(int row) {     for (int j = 1; j <= m; ++j) {       tmp[row][j] ^= 1;     }   }   void invCol(int col) {     for (int i = 1; i <= n; ++i) {       tmp[i][col] ^= 1;     }   }   bool solve(int x, int y) {     memset(tmp, 0, sizeof(tmp));     memset(r, 0, sizeof(r));     memset(c, 0, sizeof(c));     for (int i = x; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         if (i == x && j < y)           tmp[i][j] = 0;         else           tmp[i][j] = 1;       }     }     for (int i = 1; i <= n; ++i) r[i] = mat[i][1] ^ tmp[i][1] ^ c[1];     for (int j = 1; j <= m; ++j) c[j] = mat[1][j] ^ tmp[1][j] ^ r[1];     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         if ((r[i] ^ c[j]) != (mat[i][j] ^ tmp[i][j])) return false;       }     }     return true;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         scanf( %d , &mat[i][j]);       }     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         if (solve(i, j)) {           puts( YES );           for (int i = 1; i <= n; ++i) printf( %d , r[i]);           putchar(  n );           for (int j = 1; j <= m; ++j) printf( %d , c[j]);           putchar(  n );           return 0;         }       }     }     puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     cin >> a >> b;     long long n, m, i, j, k = 200000;     n = a.size();     m = b.size();     for (i = 1; i <= k; i++) {       if (n - i >= 0 && m - i >= 0) {         if (a[n - i] != b[m - i]) break;       } else         break;     }     cout << (n - i) + 1 + (m - i) + 1;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 500004;   long long p, pos1, pos2, q, x, l, ans = 0, r, y, z, k, n, m, t, d, c = 0,                                     sum = 0;   long long int mn = 0x3f3f3f3f, len, cnt = 1, mx = -1000;   std::vector<int> v[MAX];   string s[10004], s1, s2;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s[i];       m += s[i].size();     }     cin >> s1;     int len = 2 * m / n;     for (int i = 0; i < n; i++) s[i] += s1;     sort(s, s + n);     int a[n];     memset(a, (0), sizeof(a));     for (int i = 0; i < n / 2; i++) {       for (int j = 0; j < n; j++) {         if (!a[j]) {           cout << s[j];           x = s[j].size();           ++a[j];           break;         }       }       for (int j = 0; j < n; j++) {         if (!a[j] and s[j].size() == len - x + 2) {           cout << s[j].substr(0, s[j].size() - 1);           ++a[j];           break;         }       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long a, b, c, n, res;   int main() {     cin >> a >> b >> c >> n;     long s[n + 1];     for (long i = 1; i <= n; ++i) {       cin >> s[i];       if (s[i] > b && s[i] < c) res++;     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int powermod(long long int B, long long int P, long long int M) {     long long int r = 1;     if (B >= M) B %= M;     while (P > 0) {       if ((P & 1) == 1) {         r *= B;         if (r >= M) r %= M;       }       P >>= 1;       B *= B;       if (B >= M) B %= M;     }     return r;   }   long long int modinv(long long int B, long long int M) {     return powermod(B, M - 2, M);   }   int main() {     long long int MOD = 1000000007LL;     long long int A, B, N, x, res = 1;     cin >> A >> B >> N >> x;     if (A == 1) {       res = x + B * (N % MOD);     } else {       long long int An = powermod(A, N, MOD);       res = An * x;       long long int tmp = B * (An - 1) % MOD;       tmp = tmp * modinv(A - 1, MOD) % MOD;       res += tmp;     }     res %= MOD;     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename X, typename Y>   static inline void xmin(X &x, Y y) {     if (y < x) x = y;   }   template <typename X, typename Y>   static inline void xmax(X &x, Y y) {     if (x < y) x = y;   }   long long pw(long long x, long long y, long long md) {     if (!y) return 1;     if (y & 1) return (x * pw(x, y - 1, md)) % md;     long long tmp = pw(x, y / 2, md);     return (tmp * tmp) % md;   }   int n, a[200001], sm[200001], seg[524288];   void ins(int x, int v, int s = 1, int e = n, int i = 1) {     seg[i] += v;     int md = (s + e) / 2;     if (s == e) return;     if (x > md)       ins(x, v, md + 1, e, 2 * i + 1);     else       ins(x, v, s, md, 2 * i);   }   int que(int x, int s = 1, int e = n, int i = 1) {     if (s > x) return 0;     if (e <= x) return seg[i];     int md = (s + e) / 2;     return que(x, s, md, 2 * i) + que(x, md + 1, e, 2 * i + 1);   }   int elt(int x, int s = 1, int e = n, int i = 1) {     if (s == e) return s;     int md = (s + e) / 2;     return seg[2 * i] >= x ? elt(x, s, md, 2 * i)                            : elt(x - seg[2 * i], md + 1, e, 2 * i + 1);   }   void solve() {     cin >> n;     for (int i = 1; i <= n; ++i) cin >> a[i], ins(a[i] + 1, 1);     for (int i = 1; i <= n; ++i) ins(a[i] + 1, -1), sm[i] = que(a[i] + 1);     for (int i = 1; i <= n; ++i) cin >> a[i], ins(a[i] + 1, 1);     for (int i = 1; i <= n; ++i) ins(a[i] + 1, -1), sm[i] += que(a[i] + 1);     for (int i = n; i >= 1; --i)       if (sm[i] > n - i) sm[i] -= n - i + 1, ++sm[i - 1];     for (int i = 1; i <= n; ++i) ins(i, 1);     for (int i = 1; i <= n; ++i) {       sm[i] = elt(sm[i] + 1);       ins(sm[i], -1);     }     for (int i = 1; i <= n; ++i) cout << sm[i] - 1 <<    ;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     int TESTS = 1;     while (TESTS--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool hell(vector<int>& v1, vector<int>& v2) { return v1.size() < v2.size(); }   int main() {     int n;     cin >> n;     vector<vector<int> > f(100);     int a[2 * n + 1];     for (int i = 1; i <= 2 * n; i++) {       cin >> a[i];       f[a[i]].push_back(i);     }     int b[2 * n + 1];     int u = 1;     sort(f.begin() + 10, f.end(), hell);     for (int i = 10; i < 100; i++) {       for (int j = 0; j < f[i].size(); j++) {         b[f[i][j]] = u;         if (u == 1)           u = 2;         else           u = 1;       }     }     int u1 = 0, u2 = 0;     for (int i = 10; i < 100; i++) {       if (f[i].size() == 0) {         continue;       }       if (f[i].size() >= 2) {         u1++;         u2++;       } else {         if (b[f[i][0]] == 1) {           u1++;         } else           u2++;       }     }     cout << (u1 * u2) << endl;     for (int i = 1; i <= 2 * n; i++) {       cout << b[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, v;   int main() {     cin >> n >> v;     int ans = 0;     int p = 1;     int cur = 0;     for (int i = n - 1; i >= 0; i--, p++) {       if (cur >= i) continue;       ans += p * (min(i, v - cur));       cur = cur + min(i, v - cur) - 1;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 810, maxn = 200010;   long long n, m, k, top, cnt, num;   struct wy {     long long x, y, z;   } t[maxn];   inline long long cmp(wy a, wy b) { return a.z < b.z; }   long long b[MAXN], c[MAXN], a[MAXN][MAXN], w[maxn];   inline void discrete() {     sort(b + 1, b + 1 + top);     for (long long i = 1; i <= top; ++i)       if (b[i] != b[i - 1]) c[++cnt] = b[i];   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m >> k;     for (long long i = 1; i <= m; ++i) {       long long x, y, z;       cin >> x >> y >> z;       t[i] = (wy){x, y, z};     }     sort(t + 1, t + 1 + m, cmp);     for (long long i = 1; i <= ((m) > (k) ? (k) : (m)); ++i) {       b[++top] = t[i].x;       b[++top] = t[i].y;     }     discrete();     for (long long i = 1; i <= cnt; ++i)       for (long long j = 1; j <= cnt; ++j) a[i][j] = 20000000000000000ll;     for (long long i = 1; i <= ((m) > (k) ? (k) : (m)); ++i) {       long long x = lower_bound(c + 1, c + 1 + cnt, t[i].x) - c;       long long y = lower_bound(c + 1, c + 1 + cnt, t[i].y) - c;       a[y][x] = a[x][y] = t[i].z;     }     for (long long p = 1; p <= cnt; ++p) {       for (long long i = 1; i <= cnt; ++i)         for (long long j = 1; j <= cnt; ++j) {           a[i][j] =               ((a[i][j]) > (a[i][p] + a[p][j]) ? (a[i][p] + a[p][j]) : (a[i][j]));         }     }     for (long long i = 1; i <= cnt; ++i)       for (long long j = i + 1; j <= cnt; ++j) c[++num] = a[i][j];     sort(c + 1, c + 1 + num);     printf( %lld , c[k]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string n;     int k = 0;     cin >> n;     if (n[0] <=  Z ) {       for (int i = 0; i < n.size(); i++) {         if (n[i] <=  Z ) k++;       }       if (k == n.size()) {         transform(n.begin(), n.end(), n.begin(), (int (*)(int))tolower);         cout << n;       } else         cout << n;     } else {       for (int i = 0; i < n.size(); i++) {         if (n[i] <=  Z ) k++;       }       if (k == n.size() - 1) {         transform(n.begin(), n.end(), n.begin(), (int (*)(int))tolower);         n.at(0) = toupper(n.at(0));         cout << n;       } else         cout << n;     }   }


#include <bits/stdc++.h>   int main() {     int tp, x, ans;     while (~scanf( %d , &x)) {       x = x < 0 ? -x : x, ans = ceil((-1 + sqrt(1 + 8.0 * x)) / 2),       tp = ans * (ans + 1) / 2 - x;       while (tp & 1) ans++, tp += ans;       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     {       int t;       cin >> t;       long long int a[t];       for (int i = 0; i < t; i++) {         cin >> a[i];         if (a[i] % 2 == 0 && a[i] != 0)           cout << a[i] - 1 <<    ;         else           cout << a[i] <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int T, a[260];   int main() {     scanf( %d , &T);     while (T--) {       int s = 0;       int ct = 0;       for (int i = 0; i < 250; i++) {         scanf( %d , &a[i]);         s += a[i];       }       double ave = s / 250.0;       for (int i = 0; i < 250; i++) {         if (fabs(a[i] - ave) <= ave / 2) ct++;       }       if (ct > 250 * 0.75)         printf( poisson n );       else         printf( uniform n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int main() {     int a, b;     while (scanf( %d%d , &a, &b) != EOF) {       int g = gcd(a, b);       int x = -1, y = -1;       for (int dx = 1; dx <= 1000; ++dx)         for (int dy = 1; dy <= 1000; ++dy)           if (dx * dx + dy * dy == g * g) x = dx, y = dy;       if (x == -1 && y == -1)         printf( NO n );       else {         printf( YES n0 0 n );         if (a / g * y == b / g * x) swap(a, b);         printf( %d %d n , a / g * x, a / g * y);         printf( %d %d n , -b / g * y, b / g * x);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char str[200005];   int arr[200005];   int cum[200005];   int main() {     scanf( %s , &str);     int n = strlen(str);     int q, idx;     scanf( %d , &q);     while (q--) {       scanf( %d , &idx);       int l = idx, r = n - idx + 1;       arr[l]++;       arr[r + 1]--;     }     for (int i = 1; i <= n; i++) {       cum[i] = cum[i - 1] + arr[i];     }     for (int i = 0; i < n; i++) {       if (cum[i + 1] % 2 == 0) {         printf( %c , str[i]);       } else {         printf( %c , str[n - i - 1]);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long int n, m;     cin >> n;     cin >> m;     char str[2002][2002];     long int A[10002][2];     long int cnt = 0;     long int i, j;     for (i = 0; i < n; i++) {       cin >> str[i];       for (j = 0; j < m; j++) {         if (str[i][j] ==  w ) {           A[cnt][0] = i;           A[cnt][1] = j;           cnt++;         }       }     }     long int i_min = n, i_max = 0, j_min = m, j_max = 0;     for (i = 0; i < cnt; i++) {       if (A[i][0] < i_min) i_min = A[i][0];       if (A[i][0] > i_max) i_max = A[i][0];       if (A[i][1] < j_min) j_min = A[i][1];       if (A[i][1] > j_max) j_max = A[i][1];     }     long int dim;     long int Idy = -1;     long int Idx = -1;     if (i_max - i_min > j_max - j_min) {       dim = i_max - i_min + 1;       for (i = 0; i < cnt; i++) {         if (A[i][0] != i_max && A[i][0] != i_min) {           Idy = A[i][1];           break;         }       }       if (Idy == -1) {         if (m - j_min > dim)           j_max = j_min + dim - 1;         else {           j_max = m - 1;           j_min = j_max - dim + 1;         }       } else {         if (j_max == j_min) {           if (j_min + dim - 1 < m)             j_max = j_min + dim - 1;           else             j_min = j_max - dim + 1;         } else {           if (Idy == j_min)             j_max = j_min + dim - 1;           else             j_min = j_max - dim + 1;         }       }     } else if (i_max - i_min < j_max - j_min) {       dim = j_max - j_min + 1;       for (i = 0; i < cnt; i++) {         if (A[i][1] != j_max && A[i][1] != j_min) {           Idx = A[i][0];           break;         }       }       if (Idx == -1) {         if (n - i_min > dim)           i_max = i_min + dim - 1;         else {           i_max = n - 1;           i_min = i_max - dim + 1;         }       } else {         if (i_max == i_min) {           if (i_min + dim - 1 < n)             i_max = i_min + dim - 1;           else             i_min = i_max - dim + 1;         } else {           if (Idx == i_min)             i_max = i_min + dim - 1;           else             i_min = i_max - dim + 1;         }       }     }     if (!((i_max < n) && (i_min >= 0) && (j_max < m) && (j_min >= 0))) {       cout <<  -1             <<   n ;       return 0;     }     long int cnt2 = 0;     for (j = j_min; j <= j_max; j++) {       if (str[i_min][j] ==  w )         cnt2++;       else         str[i_min][j] =  + ;       if (i_max == i_min) continue;       if (str[i_max][j] ==  w )         cnt2++;       else         str[i_max][j] =  + ;     }     for (i = i_min + 1; i < i_max; i++) {       if (str[i][j_min] ==  w )         cnt2++;       else         str[i][j_min] =  + ;       if (j_max == j_min) continue;       if (str[i][j_max] ==  w )         cnt2++;       else         str[i][j_max] =  + ;     }     if (cnt == -1) {       for (i = 0; i < 2000; i++) cout <<  w ;       cout << endl;       for (i = 1; i < 2000 - 1; i++) {         cout <<  w ;         for (j = 1; j < 1999; j++) cout <<  . ;         cout <<  w ;         cout << endl;       }       for (i = 0; i < 2000; i++) cout <<  w ;       cout << endl;       return 0;     }     if (cnt != cnt2) {       cout <<  -1 n ;       return 0;     }     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) cout << str[i][j];       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void DBG() { cerr << endl; }   template <class Head, class... Tail>   void DBG(Head H, Tail... T) {     cerr <<     << H;     DBG(T...);   }   using ll = long long;   using ld = long double;   template <class T>   using vec = vector<T>;   template <class... Args>   inline void read(Args&... args) {     ((cin >> args), ...);   }   template <class... Args>   inline void show(Args... args) {     ((cout << args <<    ), ...);   }   template <class T1, class T2>   inline bool ckmin(T1& a, T2 b) {     return a > b ? a = b, 1 : 0;   }   template <class T1, class T2>   inline bool ckmax(T1& a, T2 b) {     return a < b ? a = b, 1 : 0;   }   template <class T>   inline void operator>>(istream& in, vector<T>& v) {     for (auto i = 0; i < int(v.size()); i++) in >> v[i];   }   template <class T>   inline void operator<<(ostream& out, const vector<T>& v) {     for (auto i = 0; i < int(v.size()); i++)       out << v[i] <<    n [i + 1 == int(v.size())];   }   const int MOD = 7340033;   ll dp[31][4][1001];   void solve() {     int n, k;     read(n, k);     function<ll(int, int, int)> F = [&](int part, int idx, int rem) {       if (part == 0 || idx == 4) return rem == 0 ? 1ll : 0ll;       if (idx == 0 && rem == 0) return 1ll;       if (~dp[part][idx][rem]) return dp[part][idx][rem];       ll cnt = 0;       int new_rem = idx == 0 ? rem - 1 : rem;       for (auto i = 0; i < new_rem + 1; i++) {         cnt += F(part, idx + 1, i) * F(part - 1, 0, new_rem - i);         cnt %= MOD;       }       return dp[part][idx][rem] = cnt;     };     int part = 0;     while (n > 1 && n % 2) n /= 2, part++;     cout << F(part, 0, k) <<   n ;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout << fixed << setprecision(12);     cerr << fixed << setprecision(12);     memset(dp, -1, sizeof(dp));     int _ = 1;     cin >> _;     for (auto i = 1; i < _ + 1; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = LONG_MAX;   const long long arr = 1000000;   bool comp(pair<string, long long> a, pair<string, long long> b) {     return a.second > b.second;   }   int main(void) {     long long n;     cin >> n;     vector<pair<long long, long long> > v;     for (int i = 0; i < n + 1; i++) {       long long x, y;       cin >> x >> y;       v.push_back({x, y});     }     long long ans = 0;     for (int i = 1; i < n; i++) {       long long x1 = v[i - 1].first, y1 = v[i - 1].second;       long long x2 = v[i].first, y2 = v[i].second;       long long x3 = v[i + 1].first, y3 = v[i + 1].second;       if (x1 == x2 && y2 > y1) {         if (x3 < x1 && y3 > y1) ans++;       }       if (y1 == y2 && x2 > x1) {         if (x3 > x1 && y3 > y1) ans++;       }       if (x1 == x2 && y2 < y1) {         if (x3 > x1 && y3 < y1) ans++;       }       if (y1 == y2 && x2 < x1) {         if (x3 < x1 && y3 < y1) ans++;       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long Mod = 7 + 1e9;   const long long INF32 = 5 + 2e9;   const long long INF64 = 1 + 1e18;   const long long MAX = 5 + 3e5;   int N, M, ans = 4;   int main() {     cin >> N >> M;     for (int i = 1; i <= N; i++)       for (int j = 1; j <= M; j++) {         bool b;         cin >> b;         if (b && (i == 1 || j == 1 || i == N || j == M)) {           ans = 2;           break;         }       }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   inline void chkmin(T1 &x, T2 y) {     if (x > y) x = y;   }   template <typename T1, typename T2>   inline void chkmax(T1 &x, T2 y) {     if (x < y) x = y;   }   template <typename T, typename U>   inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) {     _out << _p.first <<     << _p.second;     return _out;   }   template <typename T, typename U>   inline istream &operator>>(istream &_in, pair<T, U> &_p) {     _in >> _p.first >> _p.second;     return _in;   }   template <typename T>   inline ostream &operator<<(ostream &_out, const vector<T> &_v) {     if (_v.empty()) {       return _out;     }     _out << _v.front();     for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) {       _out <<     << *_it;     }     return _out;   }   template <typename T>   inline istream &operator>>(istream &_in, vector<T> &_v) {     for (auto &_i : _v) {       _in >> _i;     }     return _in;   }   template <typename T>   inline ostream &operator<<(ostream &_out, const set<T> &_s) {     if (_s.empty()) {       return _out;     }     _out << *_s.begin();     for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {       _out <<     << *_it;     }     return _out;   }   template <typename T>   inline ostream &operator<<(ostream &_out, const multiset<T> &_s) {     if (_s.empty()) {       return _out;     }     _out << *_s.begin();     for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {       _out <<     << *_it;     }     return _out;   }   template <typename T>   inline ostream &operator<<(ostream &_out, const unordered_set<T> &_s) {     if (_s.empty()) {       return _out;     }     _out << *_s.begin();     for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {       _out <<     << *_it;     }     return _out;   }   template <typename T>   inline ostream &operator<<(ostream &_out, const unordered_multiset<T> &_s) {     if (_s.empty()) {       return _out;     }     _out << *_s.begin();     for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {       _out <<     << *_it;     }     return _out;   }   template <typename T, typename U>   inline ostream &operator<<(ostream &_out, const map<T, U> &_m) {     if (_m.empty()) {       return _out;     }     _out <<  (  << _m.begin()->first <<  :   << _m.begin()->second <<  ) ;     for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) {       _out <<  , (  << _it->first <<  :   << _it->second <<  ) ;     }     return _out;   }   template <typename T, typename U>   inline ostream &operator<<(ostream &_out, const unordered_map<T, U> &_m) {     if (_m.empty()) {       return _out;     }     _out <<  (  << _m.begin()->first <<  :   << _m.begin()->second <<  ) ;     for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) {       _out <<  , (  << _it->first <<  :   << _it->second <<  ) ;     }     return _out;   }   const string FILENAME =  input ;   const int MAXN = 100228;   long long gettr(long long A, long long B, long long C) {     if (C < 0) {       return 0;     }     if (A > B) {       swap(A, B);     }     long long p = C / B;     long long k = B / A;     long long d = (C - p * B) / A;     return gettr(B - k * A, A, C - A * (k * p + d + 1)) + (p + 1) * (d + 1) +            k * p * (p + 1) / 2;   }   long long get(long long A, long long cnta, long long B, long long cntb,                 long long C) {     if (C >= A * cnta + B * cntb) {       return cnta * cntb;     }     if (C < 0) {       return 0;     }     return gettr(A, B, C) - gettr(A, B, C - A * cnta) -            gettr(A, B, C - B * cntb) + gettr(A, B, C - A * cnta - B * cntb);   }   int gcd(int a, int b) {     if (a == 0) {       return b;     }     return gcd(b % a, a);   }   int n;   int a[MAXN];   int d[MAXN * 4];   long long cnt[MAXN];   int spusk(int v, int vl, int vr, int l, int x) {     if (d[v] % x == 0) {       return -1;     }     if (vr < l) {       return -1;     }     if (vl == vr) {       return vl;     }     int t = spusk(v * 2, vl, (vl + vr) / 2, l, x);     if (t != -1) {       return t;     }     return spusk(v * 2 + 1, (vl + vr) / 2 + 1, vr, l, x);   }   long long pref[MAXN];   long long prefs[MAXN];   long long check(long long mid) {     long long ans = 0;     for (int i = 1; i < n; i++) {       if (cnt[i] > 0) {         long long s = min(cnt[i], mid / i);         ans += s * (cnt[i] + 1) - s * (s + 1) / 2;       }     }     int uk = 1;     for (int i = 1; i < n; i++) {       if (cnt[i] == 0) {         continue;       }       if (i < uk) {         ans += cnt[i] * (pref[uk - 1] - pref[i]);       }       while (uk < n && prefs[uk] - prefs[i] <= mid) {         if (i < uk && cnt[uk] > 0) {           ans += get(i, cnt[i], uk, cnt[uk],                      mid - (prefs[uk - 1] - prefs[i]) - i - uk);         }         uk++;       }       if (uk == n) {         continue;       }       ans +=           get(i, cnt[i], uk, cnt[uk], mid - (prefs[uk - 1] - prefs[i]) - i - uk);     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     int ss = 1;     while (ss < n) {       ss <<= 1;     }     for (int i = 0; i < n; i++) {       cin >> a[i];       d[ss + i] = a[i];     }     for (int i = ss - 1; i >= 1; i--) {       d[i] = gcd(d[i * 2], d[i * 2 + 1]);     }     for (int i = 0; i < n; i++) {       int cur = i;       int need = 0;       while (cur < n) {         need = gcd(need, a[cur]);         int pos = spusk(1, 1, ss, cur + 1, need) - 1;         if (pos == -2) {           pos = n;         }         cnt[need] += pos - cur;         cur = pos;       }     }     long long m = 1LL * n * (n + 1) / 2;     m = m * (m + 1) / 2;     m = (m + 1) / 2;     n = 100001;     for (int i = 1; i < n; i++) {       pref[i] = pref[i - 1] + cnt[i];       prefs[i] = prefs[i - 1] + cnt[i] * i;     }     long long l = 1, r = prefs[n - 1];     while (l != r) {       long long mid = (l + r) / 2;       if (check(mid) >= m) {         r = mid;       } else {         l = mid + 1;       }     }     cout << r <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = (int)1e9 + 7;   long long int pow(long long int base, long long int exp, int m) {     if (exp == 0)       return 1;     else if (exp == 1)       return base;     long long int root = pow(base, exp >> 1, m);     if ((exp & 1) == 0)       return (root * root) % m;     else       return (((root * root) % m) * base) % m;   }   long long int fact[(int)1e6];   long long int ncr(int n, int r) {     return (((fact[n] * pow(fact[n - r], mod - 2, mod)) % mod) *             pow(fact[r], mod - 2, mod)) %            mod;   }   void solve(long long int *a, int n) {     if (n == 2) {       cout << (a[0] + a[1]) % mod;       return;     }     int last = 1, i, j;     for (i = n; i > 2; i--) {       if (i % 2 == 0) {         last *= -1;       }     }     j = n / 2;     long long int p1 = 0, p2 = 0;     for (i = 0; i < n; i += 2) {       long long int v = ncr(j - 1, i / 2);       v = v * a[i];       v %= mod;       p1 = (p1 + v) % mod;     }     for (i = 1; i < n; i += 2) {       long long int v = ncr(j - 1, i / 2);       v = (v * a[i]) % mod;       p2 = (p2 + v) % mod;     }     p2 *= last;     p1 += p2;     p1 %= mod;     if (p1 < 0) p1 += mod;     cout << p1;   }   int main() {     int t, n, m, i, j, k, l, p;     cin >> n;     fact[0] = 1;     for (i = 1; i < (int)3e5; i++) {       fact[i] = fact[i - 1] * i;       fact[i] %= mod;     }     long long int a[n];     for (int i = 0; i < n; ++i) {       scanf( %lld , a + i);     }     if (n == 1) {       cout << a[0];       return 0;     }     if (n % 2 == 0)       solve(a, n);     else {       long long int tmp[n - 1];       p = 1;       for (i = 0; i < n - 1; i++) {         tmp[i] = a[i] + (p * a[i + 1]);         tmp[i] %= mod;         if (tmp[i] < 0) tmp[i] += mod;         p *= -1;       }       solve(tmp, n - 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> v(n);       for (int i = 0; i < n; i++) cin >> v[i];       int mn = INT_MAX;       int cnt = 0;       for (int i = n - 1; i >= 0; i--) {         if (v[i] > mn) cnt++;         mn = min(mn, v[i]);       }       cout << cnt <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   std::istream& operator>>(std::istream& i, pair<T, U>& p) {     i >> p.first >> p.second;     return i;   }   template <typename T>   std::istream& operator>>(std::istream& i, vector<T>& t) {     for (auto& v : t) {       i >> v;     }     return i;   }   template <typename T, typename U>   std::ostream& operator<<(std::ostream& o, const pair<T, U>& p) {     o << p.first <<     << p.second;     return o;   }   template <typename T>   std::ostream& operator<<(std::ostream& o, const vector<T>& t) {     if (t.empty()) o <<   n ;     for (size_t i = 0; i < t.size(); ++i) {       o << t[i] <<    n [i == t.size() - 1];     }     return o;   }   template <typename T>   using minheap = priority_queue<T, vector<T>, greater<T>>;   template <typename T>   using maxheap = priority_queue<T, vector<T>, less<T>>;   unsigned int logceil(long long first) {     return first ? 8 * sizeof(long long) - __builtin_clzll(first) : 0;   }   namespace std {   template <typename T, typename U>   struct hash<pair<T, U>> {     hash<T> t;     hash<U> u;     size_t operator()(const pair<T, U>& p) const {       return t(p.first) ^ (u(p.second) << 7);     }   };   }  // namespace std   template <typename T, typename F>   T bsh(T l, T h, const F& f) {     T r = -1, m;     while (l <= h) {       m = (l + h) / 2;       if (f(m)) {         l = m + 1;         r = m;       } else {         h = m - 1;       }     }     return r;   }   template <typename F>   double bshd(double l, double h, const F& f, double p = 1e-9) {     unsigned int r = 3 + (unsigned int)log2((h - l) / p);     while (r--) {       double m = (l + h) / 2;       if (f(m)) {         l = m;       } else {         h = m;       }     }     return (l + h) / 2;   }   template <typename T, typename F>   T bsl(T l, T h, const F& f) {     T r = -1, m;     while (l <= h) {       m = (l + h) / 2;       if (f(m)) {         h = m - 1;         r = m;       } else {         l = m + 1;       }     }     return r;   }   template <typename F>   double bsld(double l, double h, const F& f, double p = 1e-9) {     unsigned int r = 3 + (unsigned int)log2((h - l) / p);     while (r--) {       double m = (l + h) / 2;       if (f(m)) {         h = m;       } else {         l = m;       }     }     return (l + h) / 2;   }   template <typename T>   T gcd(T a, T b) {     if (a < b) swap(a, b);     return b ? gcd(b, a % b) : a;   }   template <typename T>   class vector2 : public vector<vector<T>> {    public:     vector2() {}     vector2(size_t a, size_t b, T t = T())         : vector<vector<T>>(a, vector<T>(b, t)) {}   };   template <typename T>   class vector3 : public vector<vector2<T>> {    public:     vector3() {}     vector3(size_t a, size_t b, size_t c, T t = T())         : vector<vector2<T>>(a, vector2<T>(b, c, t)) {}   };   template <typename T>   class vector4 : public vector<vector3<T>> {    public:     vector4() {}     vector4(size_t a, size_t b, size_t c, size_t d, T t = T())         : vector<vector3<T>>(a, vector3<T>(b, c, d, t)) {}   };   template <typename T>   class vector5 : public vector<vector4<T>> {    public:     vector5() {}     vector5(size_t a, size_t b, size_t c, size_t d, size_t e, T t = T())         : vector<vector4<T>>(a, vector4<T>(b, c, d, e, t)) {}   };   class DAlmostAll {    public:     int N;     vector<vector<int>> E;     vector<int> S;     vector<pair<std::pair<int, int>, int>> Ans;     int size(int u, int p) {       S[u] = 1;       for (int v : E[u])         if (v != p) S[u] += size(v, u);       return S[u];     }     void fill(int u, int p, int& cnt, int par, long long mul) {       int mine = cnt;       long long val = (cnt - par) * mul;       val = min(1000000LL, val);       Ans.push_back({{u + 1, p + 1}, val});       cnt++;       for (int v : E[u])         if (v != p) {           fill(v, u, cnt, mine, mul);         }     }     int centroid(int u, int p) {       int m = N - S[u];       for (int v : E[u])         if (v != p) m = max(m, S[v]);       if (2 * m <= N) return u;       for (int v : E[u])         if (v != p && 2 * S[v] > N) return centroid(v, u);       return -1;     }     void solve(istream& cin, ostream& cout) {       cin >> N;       E.resize(N);       for (int i = 0; i < N - 1; ++i) {         int u, v;         cin >> u >> v;         --u;         --v;         E[u].push_back(v);         E[v].push_back(u);       }       S.assign(N, 0);       size(0, -1);       int ctr = centroid(0, -1);       long long mul = 1;       int M = E[ctr].size();       size(ctr, -1);       vector2<bool> B(M + 1, N + 1, false);       B[0][0] = true;       for (int i = 0; i < M; ++i) {         for (int j = 0; j <= N; ++j) {           if (B[i][j]) {             B[i + 1][j] = true;             B[i + 1][j + S[E[ctr][i]]] = true;           }         }       }       for (int i = 0; i <= N; ++i) {         if (B[M][i] && (i + 1) * (N - i - 1) + i >= 2 * N * N / 9) {           vector<bool> Left(M, false);           int first = i;           for (int j = M - 1; j >= 0; --j) {             if (!B[j][first]) {               Left[j] = true;               first -= S[E[ctr][j]];             }           }           int c1 = 1, c2 = 1;           for (int j = 0; j < M; ++j) {             if (Left[j]) {               fill(E[ctr][j], ctr, c1, 0, 1);             } else {               fill(E[ctr][j], ctr, c2, 0, i + 1);             }           }           for (auto a : Ans) {             cout << a <<   n ;           }           break;         }       }     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     DAlmostAll solver;     std::istream& in(std::cin);     std::ostream& out(std::cout);     solver.solve(in, out);     return 0;   }