#include <bits/stdc++.h>   using namespace std;   map<char, long long int> cou;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long int n;     cin >> n;     while (n--) {       string s;       cin >> s;       cou[s[0]]++;     }     long long int ans = 0;     for (map<char, long long int>::iterator it = cou.begin(); it != cou.end();          it++) {       long long int req = it->second;       long long int f = (req + 1) / 2;       long long int s = req / 2;       ans = ans + (f * (f - 1)) / 2 + (s * (s - 1)) / 2;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mark[1 << 22];   int is[1 << 22];   int a[1 << 22];   int n, m;   int tot;   void dfs(int x) {     if (mark[x]) return;     mark[x] = 1;     if (is[x]) dfs(tot ^ x);     for (int j = 0; j < n; j++) {       if (x >> j & 1) {         dfs(x ^ (1 << j));       }     }   }   signed main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d , &a[i]);       is[a[i]] = 1;     }     tot = (1 << n) - 1;     int ans = 0;     for (int i = 1; i <= m; i++) {       if (mark[a[i]]) continue;       mark[a[i]] = 1;       ans++;       dfs(tot ^ a[i]);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 5e5 + 7;   const long long INF = 1e17 + 7;   long long h[N], t[N], f[N][2], pos[N], w[N];   long long n, num = 0;   struct edge {     long long v, next;   } e[N * 2];   struct pir {     long long a, b;   } p[N];   bool cmp(pir x, pir y) { return (x.b - x.a) < (y.b - y.a); }   void add(long long x, long long y) {     e[num] = (edge){y, pos[x]};     pos[x] = num++;   }   void dfs(long long x, long long fa) {     long long cnt = 0, s1 = 0, s0 = 0, hh = 0, ss = 0;     for (long long i = pos[x]; ~i; i = e[i].next) {       if (e[i].v == fa) continue;       hh = 1;       dfs(e[i].v, x);       if (h[e[i].v] > h[x]) s1++, ss += f[e[i].v][1];       if (h[e[i].v] < h[x]) s0++, ss += f[e[i].v][0];     }     if (!hh) {       f[x][0] = f[x][1] = t[x];       return;     }     w[0] = 0;     for (long long i = pos[x]; ~i; i = e[i].next) {       if (e[i].v != fa && h[e[i].v] == h[x]) {         w[0] += f[e[i].v][0];         p[++cnt] = (pir){f[e[i].v][0], f[e[i].v][1]};       }     }     sort(p + 1, p + cnt + 1, cmp);     for (long long i = 1; i <= cnt; i++) w[i] = w[i - 1] + p[i].b - p[i].a;     f[x][0] = f[x][1] = INF;     for (long long i = 0; i <= cnt + 1 - 1; i++) {       f[x][0] =           min(f[x][0], w[i] + max(cnt - i + s0, i + s1 + (x != 1)) * t[x] + ss);       f[x][1] =           min(f[x][1], w[i] + max(cnt - i + s0 + (x != 1), i + s1) * t[x] + ss);     }   }   int main() {     scanf( %I64d , &n);     memset(pos, -1, sizeof(pos));     for (long long i = 1; i <= n; i++) scanf( %I64d , &t[i]);     for (long long i = 1; i <= n; i++) scanf( %I64d , &h[i]);     for (long long i = 1; i <= n - 1; i++) {       long long x, y;       scanf( %I64d%I64d , &x, &y);       add(x, y);       add(y, x);     }     dfs(1, 0);     printf( %I64d n , f[1][0]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i = 0;     ios_base::sync_with_stdio(false);     cin.tie(NULL);     vector<int> ans;     int n;     int m;     cin >> n >> m;     int a[110];     int b[20];     memset(a, 0, sizeof a);     memset(b, 0, sizeof b);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < m; i++) {       int t;       cin >> t;       b[t] = 1;     }     for (int i = 0; i < n; i++) {       if (b[a[i]] == 1) ans.push_back(a[i]);     }     for (int i = 0; i < ans.size(); i++) {       cout << ans[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, vet[202020], cap[202020];   set<long long> s;   int main() {     scanf( %lld , &n);     for (long long i = 1; i <= n; i++) scanf( %lld , &cap[i]), s.insert(i);     scanf( %lld , &m);     long long op, x, p, k;     while (m--) {       scanf( %lld , &op);       if (op == 1) {         scanf( %lld %lld , &p, &x);         for (auto it = s.lower_bound(p); it != s.end() && x; it = s.erase(it)) {           long long id = *it;           if (cap[id] - vet[id] > x) {             vet[id] += x;             break;           }           x -= cap[id] - vet[id];           vet[id] = cap[id];         }       } else {         scanf( %lld , &k);         printf( %lld n , vet[k]);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 15, maxx = 10;   long long a[maxn], b[maxn], c[maxn];   void Init() {     for (int i = 1; i <= maxx; i++) {       long long x = i, l = 1, r = 0;       while (x--) l *= 10, r = r * 10 + 9;       l /= 10;       a[i] = (r - l + 1) * i;       b[i] = b[i - 1] + a[i];       c[i] = c[i - 1] + (b[i - 1] + i + b[i]) * (r - l + 1) / 2;     }   }   int main() {     ios::sync_with_stdio(0);     Init();     long long t, n, pos;     cin >> t;     while (t--) {       cin >> n;       pos = lower_bound(c + 1, c + maxx + 1, n) - c;       n = n - c[pos - 1];       long long l = 1, r = 0, x = pos, t = b[pos - 1];       while (x--) l *= 10, r = 10 * r + 9;       l /= 10;       long long L = l;       while (l <= r) {         long long mid = (l + r) >> 1;         long long cnt = mid - L + 1;         if ((2 * t + pos + cnt * pos) * cnt / 2 >= n)           r = mid - 1;         else           l = mid + 1;       }       long long cnt = l - L;       n -= (2 * t + pos + cnt * pos) * cnt / 2;       pos = lower_bound(b + 1, b + maxx + 1, n) - b;       n -= b[pos - 1];       int ans = 1;       for (int i = 1; i < pos; i++) ans *= 10;       t = (n - 1) / pos;       n -= t * pos;       ans += t;       n = pos - n;       while (n--) ans /= 10;       cout << ans % 10 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool flag;   int n, a[1010], vis[2010], T;   pair<int, int> ans[5];   void read(int &x) {     char ch = getchar();     int mark = 1;     for (; ch !=  -  && (ch <  0  || ch >  9 ); ch = getchar())       ;     if (ch ==  - ) mark = -1, ch = getchar();     for (x = 0; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch - 48;     x *= mark;   }   bool check(int step) {     for (int i = 1; i <= n; i++)       if (a[i] != i) return 0;     return 1;   }   void rev(int *a, int l, int r) {     for (int i = 0; i <= (r - l - 1) / 2; i++) swap(a[i + l], a[r - i]);   }   int expect() {     int ans = 1;     for (int i = 2; i <= n; i++)       if (abs(a[i] - a[i - 1]) != 1) ans++;     return ans;   }   void dfs(int step) {     if (check(step - 1)) {       printf( %d n , step - 1);       for (int i = step - 1; i; i--)         printf( %d %d n , ans[i].first, ans[i].second);       flag = 1;       return;     }     if (step > 3) return;     int c[1010];     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++)         if (abs(a[i - 1] - a[j]) == 1 || abs(a[i] - a[j + 1]) == 1) {           for (int k = i; k <= j; k++) c[k] = a[k];           rev(a, i, j);           if (expect() <= (3 - step) * 2 + 1) {             ans[step] = make_pair(i, j);             dfs(step + 1);             if (flag) return;           }           for (int k = i; k <= j; k++) a[k] = c[k];         }     }   }   int main() {     read(n);     for (int i = 1; i <= n; i++) read(a[i]);     a[n + 1] = n + 1;     dfs(1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool test(long long k, long long x, long long n, long long m, long long p1,             long long l1, long long r1, long long p2, long long l2,             long long r2) {     if (p1 * 2 + l1 + r1 > n) return false;     if (p2 * 2 + l2 + r2 > m) return false;     for (long long i = 0; i < k - 2; i++) {       long long p3 = p1 + p2 + (r1 * l2);       long long l3 = l1;       long long r3 = r2;       l1 = l2;       r1 = r2;       p1 = p2;       l2 = l3;       r2 = r3;       p2 = p3;       if (p2 > x) return false;     }     return p2 == x;   }   string build(long long n, long long p, long long l, long long r) {     string s(n,  X );     if (l) s[0] =  C ;     if (r) s[n - 1] =  A ;     for (long long i = 0; i < p; i++) {       s[l + i * 2] =  A ;       s[l + i * 2 + 1] =  C ;     }     return s;   }   signed main() {     ios::sync_with_stdio(false);     long long k, x, n, m;     cin >> k >> x >> n >> m;     for (long long p1 = 0; p1 <= n / 2; p1++) {       for (long long l1 = 0; l1 <= 1; l1++) {         for (long long r1 = 0; r1 <= 1; r1++) {           for (long long p2 = 0; p2 <= m / 2; p2++) {             for (long long l2 = 0; l2 <= 1; l2++) {               for (long long r2 = 0; r2 <= 1; r2++) {                 if (test(k, x, n, m, p1, l1, r1, p2, l2, r2)) {                   string s1 = build(n, p1, l1, r1);                   string s2 = build(m, p2, l2, r2);                   cout << s1 <<   n  << s2 <<   n ;                   return 0;                 }               }             }           }         }       }     }     cout <<  Happy new year! n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize 2   using namespace std;   const int N = 2e4 + 9;   struct stree {     int l, r, lazy, sum;   } t[N << 2];   int dp[20005];   inline void pushdown(int now) {     int lazy = t[now].lazy;     if (!lazy) return;     if (t[now].l != t[now].r)       t[now * 2].lazy += lazy, t[now * 2 + 1].lazy += lazy;     t[now].sum += lazy;     t[now].lazy = 0;   }   inline void build(int now, int l, int r) {     t[now].l = l, t[now].r = r, t[now].lazy = 0;     if (l == r) {       t[now].sum = dp[l];       return;     }     int mid = (l + r) / 2;     build(now * 2, l, mid), build(now * 2 + 1, mid + 1, r);     t[now].sum = max(t[now * 2].sum, t[now * 2 + 1].sum);   }   inline void change(int now, int l, int r, int d) {     if (l > r) return;     pushdown(now);     if (t[now].l == l && t[now].r == r) {       t[now].lazy += d;       return;     }     pushdown(now);     if (t[now * 2].r >= r)       change(now * 2, l, r, d);     else if (t[now * 2 + 1].l <= l)       change(now * 2 + 1, l, r, d);     else       change(now * 2, l, t[now * 2].r, d),           change(now * 2 + 1, t[now * 2 + 1].l, r, d);     pushdown(now);     if (t[now].l != t[now].r)       pushdown(now * 2), pushdown(now * 2 + 1),           t[now].sum = max(t[now * 2].sum, t[now * 2 + 1].sum);   }   inline int query(int now, int l, int r) {     pushdown(now);     if (l > r) return 0;     if (t[now].l == l && t[now].r == r) return t[now].sum;     if (t[now * 2].r >= r)       return query(now * 2, l, r);     else if (t[now * 2 + 1].l <= l)       return query(now * 2 + 1, l, r);     else       return max(query(now * 2, l, t[now * 2].r),                  query(now * 2 + 1, t[now * 2 + 1].l, r));   }   int qzh[55][20005], a[55][20005], cf[20005];   int main() {     int n, m, k;     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> a[i][j];         qzh[i][j] = qzh[i][j - 1] + a[i][j];       }     }     int ans = 0;     for (int i = 1; i <= n; i++) {       if (i != 1) {         for (int j = 1; j <= k; j++) dp[j] -= qzh[i][k] - qzh[i][j - 1];       }       build(1, 1, m);       memset(dp, 0, sizeof dp);       for (int j = 1; j <= m - k + 1; j++) {         dp[j] = query(1, 1, m) - qzh[i][j - 1] - qzh[i + 1][j - 1] +                 qzh[i][j + k - 1] + qzh[i + 1][j + k - 1];         if (i != 1)           change(1, max(1, j - k + 1), min(m, j), a[i][j]),               change(1, max(1, j + 1), min(m, j + k), -a[i][j + k]);         ans = max(ans, dp[j]);       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double eps = 1e-6;   template <class T>   T gcd(T a, T b) {     if (!b) return a;     return gcd(b, a % b);   }   const int maxn = 1e6 + 10;   int n, m;   int phi[maxn];   int a[maxn];   int get(int x) {     int res = x;     for (long long i = 2; i * i <= x; i++) {       if (x % i == 0) {         res = res / i * (i - 1);         while (x % i == 0) x /= i;       }     }     if (x > 1) res = res / x * (x - 1);     return res;   }   int qpow(int b, int n, int mod) {     int res = 1;     while (n) {       if (n & 1) res = 1LL * res * b >= mod ? 1LL * res * b % mod + mod : res * b;       b = 1LL * b * b >= mod ? 1LL * b * b % mod + mod : b * b;       n >>= 1;     }     return res;   }   int solve(int l, int r, int k) {     if (phi[k] == 1) return 1;     if (l == r) {       if (a[l] < phi[k])         return a[l];       else         return a[l] % phi[k] + phi[k];     } else       return qpow(a[l], solve(l + 1, r, k + 1), phi[k]);   }   int main() {     scanf( %d , &n);     scanf( %d , &phi[0]);     while (phi[m] != 1) {       phi[m + 1] = get(phi[m]);       m++;     }     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     int q;     scanf( %d , &q);     for (int i = 0; i < q; i++) {       int l, r;       scanf( %d , &l);       scanf( %d , &r);       int ans = solve(l, r, 0) % phi[0];       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long M = 1000000007;   long long bigMod(long long n, long long power, long long mod = M) {     if (power == 0) return 1;     if (power == 1)       return n % mod;     else if (power % 2 == 0) {       long long v = bigMod(n, power / 2, mod);       return ((v % mod) * (v % mod)) % mod;     } else {       long long v = bigMod(n, power - 1, mod) % mod;       return ((v % mod) * (n % mod)) % mod;     }   }   int main() {     long long n;     scanf( %lld , &n);     long long number = bigMod(2, n);     cout << ((number * (number + 1)) / 2) % M << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3005;   int n, a[N];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , a + i);     }     int ans = 0;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < i; ++j) {         if (a[j] > a[i]) {           ++ans;         }       }     }     printf( %.12f n , (double)(ans / 2 * 4 + ans % 2));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, K;   int pover[64000];   int ipover[64000];   int dt[503][503];   int lsum[2][503][503];   const int mod = 1000000007;   int main() {     scanf( %d%d , &n, &K);     int maxval = 0;     pover[0] = 1;     for (int i = 1; i < 64000; i++) {       pover[i] = (pover[i - 1] * (long long)2) % mod;     }     ipover[0] = 1;     for (int i = 1; i < 64000; i++) {       ipover[i] = (ipover[i - 1] * (long long)500000004) % mod;     }     for (int j = 0; j <= 0; j++) {       dt[0][j] = 1;     }     for (int k = 0; k <= n; k++) {       long long ksum = 0;       for (int j = 0; j < k; j++) {         long long mul = pover[(k - j) * (n - k + 1)];         ksum = (ksum + dt[0][j] * mul) % mod;         lsum[1][j][k] = ksum;       }     }     for (int i = 1; i <= K; i++) {       int ci = i % 2;       for (int j = 1; j <= n; j++) {         for (int k = 1; k <= j; k++) {           long long baseCnt = lsum[ci][k - 1][j];           long long tot = baseCnt * ipover[j - k + 1] % mod;           dt[i][j] = (dt[i][j] + tot) % mod;         }       }       int ni = 1 - i % 2;       memset(lsum[ni], 0, sizeof(lsum[0]));       for (int k = 0; k <= n; k++) {         long long ksum = 0;         for (int j = 0; j < k; j++) {           long long mul = pover[(k - j) * (n - k + 1)];           ksum = (ksum + dt[i][j] * mul) % mod;           lsum[ni][j][k] = ksum;         }       }     }     long long ans = 0;     for (int i = 0; i <= n; i++) {       ans += dt[K][i];       ans %= mod;     }     ans %= mod;     printf( %d n , (int)ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int d[1005], s[1005], sufmax[1005], mxpos[1005], pred[1005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, k;     cin >> n >> k;     ++n;     for (int i = 1; i < n; ++i) cin >> d[i];     for (int i = 1; i < n; ++i) cin >> s[i];     for (int i = n - 1; i >= 1; --i) {       if (s[i] > sufmax[i + 1]) {         mxpos[i] = i;         sufmax[i] = s[i];       } else {         mxpos[i] = mxpos[i + 1];         sufmax[i] = sufmax[i + 1];       }     }     for (int i = 1; i < n; ++i) pred[i] = pred[i - 1] + d[i];     int tott = 0, oil = s[1];     for (int i = 1; i < n;) {       int j = i;       do {         oil -= d[j];         ++j;         while (oil < 0) tott += k, oil += s[i];         oil += s[j];       } while (s[j] < s[i] && j < n);       i = j;     }     cout << tott + pred[n - 1] << endl;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( O3 )   #pragma GCC target( avx,avx2,sse,sse2,sse3,sse4,popcnt,fma )   #pragma GCC optimize( unroll-loops )   const long long int MAXN = 2e5 + 5;   const long long int mod = 1000000007;   const long long int N = 200005;   void solve() {     map<pair<int, int>, vector<int>> mpX, mpY;     int n, m, k;     cin >> n >> m >> k;     vector<int> xec(n), yec(m);     map<int, int> haveX, haveY;     for (int i = 0; i < n; i++) {       cin >> xec[i], haveX[xec[i]] += 1;     }     for (int i = 0; i < m; i++) {       cin >> yec[i], haveY[yec[i]] += 1;     }     for (int i = 0; i < k; i++) {       int x, y;       cin >> x >> y;       if (haveX[x] && haveY[y]) continue;       if (haveX[x]) {         int idx = lower_bound(yec.begin(), yec.end(), y) - yec.begin();         mpX[{yec[idx - 1], yec[idx]}].push_back(x);       }       if (haveY[y]) {         int idx = lower_bound(xec.begin(), xec.end(), x) - xec.begin();         mpY[{xec[idx - 1], xec[idx]}].push_back(y);       }     }     long long int ans = 0;     for (auto [a, b] : mpX) {       sort(b.begin(), b.end());       map<int, int> mpTemp;       int total = b.size();       for (auto x : b) {         mpTemp[x] += 1;       }       for (auto [c, d] : mpTemp) {         ans += (long long int)d * (long long int)(total - d);       }     }     for (auto [a, b] : mpY) {       sort(b.begin(), b.end());       map<int, int> mpTemp;       int total = b.size();       for (auto y : b) {         mpTemp[y] += 1;       }       for (auto [c, d] : mpTemp) {         ans += (long long int)d * (long long int)(total - d);       }     }     cout << ans / 2ll <<   n ;     return;   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, c0, c1, h;       cin >> n >> c0 >> c1 >> h;       string s;       cin >> s;       int o = 0, z = 0;       for (int i = 0; i < n; i++) {         if (s[i] ==  1 )           o++;         else           z++;       }       int ans = 0;       if (c0 < c1) {         if (c0 + h <= c1)           ans = z * c0 + o * (c0 + h);         else           ans = z * c0 + o * c1;       } else {         if (c1 + h <= c0)           ans = c1 * o + z * (c1 + h);         else           ans = c1 * o + c0 * z;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( O3 )   #pragma GCC optimize( O2 )   #pragma GCC optimize( inline )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   #pragma GCC optimize( unroll-loops )   using namespace std;   const int INF = 1e9 + 7;   int n;   vector<int> G[55];   double dp[55][55][55][55];   int vis[55][55];   double tmp[55][55];   long long C[55][55];   double cpro[55][55][55][55];   void merge_dp(int asz, double a[][55], int bsz, double b[][55],                 double ret[][55]) {     for (int i = 0; i <= asz + bsz; i++)       for (int j = 0; j <= asz + bsz; j++) ret[i][j] = 0;     for (int ia = 0; ia <= asz; ia++)       for (int ja = 0; ja <= asz; ja++)         for (int ib = 0; ib <= bsz; ib++)           for (int jb = 0; jb <= bsz; jb++) {             if (ia == 0 && ib == 0) {               ret[ia + ib][0] = a[ia][0] * b[ib][0];               continue;             }             for (int jt = ja + jb; jt <= asz + bsz; jt++)               ret[ia + ib][jt] +=                   a[ia][ja] * b[ib][jb] *                   (cpro[jt][ja][asz][bsz] + cpro[jt][jb][bsz][asz]) /                   C[asz + bsz][asz];           }   }   int dfs(int v, int par) {     if (vis[v][par]) return vis[v][par];     int tsz = 0;     dp[v][par][0][0] = 1.0;     for (int i = 0; i < (int)(G[v].size()); i++) {       int u = G[v][i];       if (u == par) continue;       int csz = dfs(u, v);       merge_dp(tsz, dp[v][par], csz, dp[u][v], tmp);       tsz += csz;       for (int j = 0; j <= tsz; j++)         for (int k = 0; k <= tsz; k++) dp[v][par][j][k] = tmp[j][k];     }     if (par > 0) {       for (int i = 0; i <= tsz; i++)         for (int j = 0; j <= tsz; j++) {           tmp[i][j] = dp[v][par][i][j];           dp[v][par][i][j] *= 1 - 1.0 * j / (tsz + 1);         }       for (int i = 0; i <= tsz; i++)         for (int j = 0; j <= tsz; j++)           for (int k = j; k <= tsz; k++)             dp[v][par][i + 1][k + 1] += tmp[i][j] * (1.0 / (tsz + 1));       tsz++;     }     return vis[v][par] = tsz;   }   double aa[55];   double gen_ans(int v) {     dfs(v, 0);     memset(aa, 0, sizeof(aa));     for (int i = 0; i <= n; i++)       for (int j = 0; j <= n; j++) aa[i] += dp[v][0][i][j];     for (int i = n; i >= 0; i--)       for (int j = n; j > i; j--) aa[i] -= C[j][i] * aa[j];     double ret = 0.0, t = 1.0;     for (int i = 0; i <= n; i++) {       ret = ret + aa[i] * t;       t *= 0.5;     }     return ret;   }   void init_C() {     C[0][0] = 1;     for (int i = 1; i <= (int)(n); i++) {       C[i][0] = 1;       for (int j = 1; j <= (int)(n); j++) C[i][j] = C[i - 1][j] + C[i - 1][j - 1];     }     for (int a = 0; a <= n; a++)       for (int b = 0; a + b <= n; b++)         for (int ja = 0; ja <= a; ja++)           for (int jt = ja; jt <= a + b; jt++)             if (ja > 0)               cpro[jt][ja][a][b] = C[jt - 1][ja - 1] * C[a + b - jt][a - ja];             else               cpro[jt][ja][a][b] = 0;   }   int main() {     scanf( %d , &n);     init_C();     for (int i = 0; i < (int)(n - 1); i++) {       int u, v;       scanf( %d%d , &u, &v);       G[u].push_back(v);       G[v].push_back(u);     }     for (int i = 1; i <= (int)(n); i++) printf( %.8lf n , gen_ans(i));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 500010;   int m, k, n, s, a[maxn], b[maxn], c[maxn], maxx, tong[maxn], ansl, ansr,       vis[maxn];   bool check(int l, int r) {     memcpy(c, tong, sizeof(c));     for (int i = l; i <= r; i++) c[a[i]]--;     for (int i = 1; i <= maxx; i++)       if (c[i] > 0) {         return false;       }     return true;   }   void gen(int l, int r) {     int temp = l - (min(n - 1, (l - 1) / k) * k + 1);     temp += max(0, r - l + 1 - k);     if (temp <= m - n * k) {       printf( %d n , temp);       int num = 0;       for (int i = min(n - 1, (l - 1) / k) * k + 1; i < l; i++) {         printf( %d  , i);         num++;       }       int num2 = 0;       memset(c, 0, sizeof(c));       for (int i = l; i <= r; i++)         if (c[a[i]] + 1 <= tong[a[i]]) {           vis[i] = 1;           c[a[i]]++;           num2++;         }       num2 = r - l + 1 - num2;       num += num2;       for (int i = l; i <= r; i++)         if (!vis[i] && num > temp) {           num--;           vis[i] = 1;         }       for (int i = l; i <= r; i++)         if (!vis[i]) printf( %d  , i);       exit(0);     }   }   void solve(int x) {     memset(c, 0, sizeof(c));     int cur = m;     for (int i = x; i <= m; i++) c[a[i]]++;     for (int i = x - 1; i >= 1; i--) {       c[a[i]]++;       while (cur > i) {         if (c[a[cur]] - 1 >= tong[a[cur]] &&             c[a[cur - 1]] + 1 >= tong[a[cur - 1]]) {           c[a[cur]]--;           cur--;         } else           break;       }       gen(i, cur);     }   }   int main() {     scanf( %d%d%d%d , &m, &k, &n, &s);     for (int i = 1; i <= m; i++) scanf( %d , &a[i]);     for (int i = 1; i <= s; i++) {       scanf( %d , &b[i]);       maxx = max(maxx, b[i]);       tong[b[i]]++;     }     int l = 1, r = m, res = 0;     while (l <= r) {       int mid = (l + r) >> 1;       if (check(mid, m)) {         res = mid;         l = mid + 1;       } else         r = mid - 1;     }     if (res) {       gen(res, m);       solve(res);       puts( -1 );     } else       puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2005;   bool can = 1;   char arr[N][N];   int n, m, vis[N][N], dp[N][N];   bool valid(pair<int, int> a) {     return min(a.first, a.second) > -1 && a.first < n && a.second < m &&            arr[a.first][a.second] !=  # ;   }   pair<int, int> get_next(pair<int, int> a) {     if (arr[a.first][a.second] ==  < ) return {a.first, a.second - 1};     if (arr[a.first][a.second] ==  > ) return {a.first, a.second + 1};     if (arr[a.first][a.second] ==  ^ ) return {a.first - 1, a.second};     return {a.first + 1, a.second};   }   void dfs(pair<int, int> u) {     vis[u.first][u.second] = 1;     pair<int, int> c = get_next(u);     if (valid(c)) {       if (vis[c.first][c.second] == 0)         dfs(c);       else if (vis[c.first][c.second] == 1) {         can = 0;         return;       }     }     vis[u.first][u.second] = 2;   }   bool go(pair<int, int> u) {     vis[u.first][u.second] = 1;     pair<int, int> c = get_next(u);     bool ret = 1;     if (valid(c)) {       if (vis[c.first][c.second] == 0)         ret &= go(c);       else         ret = 0;     }     return ret;   }   int solve(pair<int, int> u) {     if (!valid(u)) return 0;     if (~dp[u.first][u.second]) return dp[u.first][u.second];     pair<int, int> c = get_next(u);     return dp[u.first][u.second] = solve(c) + 1;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     memset(dp, -1, sizeof(dp));     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) cin >> arr[i][j];     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j)         if (!vis[i][j] && valid({i, j})) dfs({i, j});     if (can) {       vector<pair<int, pair<int, int>>> v;       for (int i = 0; i < n; ++i)         for (int j = 0; j < m; ++j) v.push_back({solve({i, j}), {i, j}});       sort(v.rbegin(), v.rend());       if (v.size() == 1 || v[0].first == 0)         cout << v[0].first;       else {         int ans1 = v[0].first, ans2 = v[0].first - 1;         memset(vis, 0, sizeof(vis));         go(v[0].second);         for (int i = 1; i < v.size(); ++i) {           if (v[i].first < v[i - 1].first) break;           if (go(v[i].second)) {             ans2 = ans1;             break;           }         }         cout << ans1 + ans2;       }     } else       cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1.01e9;   const double eps = 1e-9;   const int N = 1e5 + 10;   int t[N];   int mem[N];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; (i) < (n); ++i) scanf( %d , &t[i]);     int s = 0;     for (int i = 0; (i) < (n); ++i) {       int v = s + 20;       if (i) {         int l = lower_bound(t, t + i, t[i] - 90 + 1) - t;         v = min(v, mem[l] + 50);       }       if (i) {         int l = lower_bound(t, t + i, t[i] - 1440 + 1) - t;         v = min(v, mem[l] + 120);       }       mem[i + 1] = v;       printf( %d n , v - s);       s = v;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y;     scanf( %d %d , &x, &y);     long long ans = 0;     for (int val = 1; val <= x; ++val) {       ans += (int)floor((y - (5 - (val % 5))) / 5.0) + 1;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double PI = 3.14159265359;   const long long MOD = (long long)1e9 + 7;   const long long MAXN = (long long)1e5 + 10;   const long long INF = (long long)9223372036854775;   const long double EPS = (long double)1e-8;   long long par[MAXN], sz[MAXN], ln[MAXN], pw[MAXN];   pair<pair<long long, long long>, long long> a[MAXN];   long long get_par(long long node) {     if (node == par[node]) return node;     par[node] = get_par(par[node]);     return par[node];   }   void merge(long long a, long long b) {     long long x = get_par(a);     long long y = get_par(b);     if (x == y) return;     ln[y] += ln[x];     sz[y] += sz[x];     par[x] = y;   }   bool CMPx(pair<pair<long long, long long>, long long> a,             pair<pair<long long, long long>, long long> b) {     return a.first.first < b.first.first;   }   bool CMPy(pair<pair<long long, long long>, long long> a,             pair<pair<long long, long long>, long long> b) {     return a.first.second < b.first.second;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     for (int i = 0; i < MAXN; i++) par[i] = i;     pw[0] = 1;     for (int i = 1; i < MAXN; i++) pw[i] = (pw[i - 1] * 2ll) % MOD;     fill(sz, sz + MAXN, 1);     long long n;     scanf( %lld , &n);     for (int i = 0; i < n; i++) {       scanf( %lld%lld , &a[i].first.first, &a[i].first.second);       a[i].second = i;     }     sort(a, a + n, CMPx);     ln[get_par(a[0].second)]++;     for (int i = 1; i < n; i++) {       if (a[i].first.first == a[i - 1].first.first) {         merge(a[i].second, a[i - 1].second);       } else {         ln[get_par(a[i].second)]++;       }     }     sort(a, a + n, CMPy);     ln[get_par(a[0].second)]++;     for (int i = 1; i < n; i++) {       if (a[i].first.second == a[i - 1].first.second) {         merge(a[i].second, a[i - 1].second);       } else {         ln[get_par(a[i].second)]++;       }     }     long long ans = 1;     for (int i = 0; i < n; i++) {       if (par[i] == i) {         if (ln[i] <= sz[i]) {           ans *= pw[ln[i]];         } else {           ans *= (pw[ln[i]] - 1);         }         ans %= MOD;       }     }     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, l = 0;     char a;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a;       if (a -  0  == 1)         l++;       else         l--;     }     cout << abs(l);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long offset[1000];   vector<pair<long long, int> > x[1000];   long long v[500005];   int bucketsize = 700;   inline int bucket(int x) { return x / bucketsize; }   int buckets, n;   inline int bstart(int x) {     if (x == buckets + 1) {       return n + 1;     }     return x * bucketsize;   }   void resort(int buc) {     x[buc].clear();     int l = bstart(buc), r = bstart(buc + 1);     for (int j = l; j < r; j++) {       x[buc].push_back({v[j], j});     }     sort(x[buc].begin(), x[buc].end());   }   int main() {     int q;     scanf( %d %d , &n, &q);     buckets = bucket(n);     for (int i = 1; i <= n; i++) {       int k;       scanf( %d , &k);       v[i] = k;       x[bucket(i)].push_back({v[i], i});     }     for (int i = 0; i <= buckets; i++) {       resort(i);     }     for (int qq = 0; qq < q; qq++) {       int t;       scanf( %d , &t);       if (t == 1) {         int l, r, dd;         scanf( %d %d %d , &l, &r, &dd);         long long d = dd;         int lbucket0 = bucket(l);         int lbucket1 = lbucket0 + 1;         int rbucket = bucket(r);         int lstart1 = bstart(lbucket1);         for (int j = lbucket1; j < rbucket; j++) {           offset[j] += d;         }         if (lbucket0 == rbucket) {           for (int j = l; j <= r; j++) v[j] += d;           resort(lbucket0);         } else {           for (int j = l; j < lstart1; j++) v[j] += d;           for (int j = bstart(rbucket); j <= r; j++) v[j] += d;           resort(lbucket0);           resort(rbucket);         }       } else {         int yy;         scanf( %d , &yy);         long long y = yy;         vector<pair<long long, int> >::iterator it;         int l = 0, r = -1;         for (int i = 0; i <= buckets; i++) {           if (y - offset[i] <= 0) continue;           pair<long long, int> search = {y - offset[i], 0};           it = lower_bound(x[i].begin(), x[i].end(), search);           if (it == x[i].end()) continue;           if (it->first == y - offset[i]) {             l = it->second;             break;           }         }         for (int i = buckets; i >= 0; i--) {           if (y - offset[i] <= 0) continue;           pair<long long, int> search = {y - offset[i] + 1, 0};           it = lower_bound(x[i].begin(), x[i].end(), search);           if (it == x[i].begin()) continue;           it--;           if (it->first == y - offset[i]) {             r = it->second;             break;           }         }         printf( %d n , r - l);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     while (T--) {       int a, b, n;       cin >> a >> b >> n;       if (n % 3 == 0)         cout << a << endl;       else if (n % 3 == 1)         cout << b << endl;       else         cout << (a ^ b) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a;   int tab[105];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= m; i++) {       cin >> a;       tab[a]--;     }     sort(tab + 1, tab + 1 + 100);     {}     for (int wynik = 1; wynik <= 101; wynik++) {       int ile = 0;       for (int i = 1; i <= 100; i++) {         ile += (-tab[i]) / wynik;       }       if (ile < n) {         printf( %d n , wynik - 1);         return 0;       }     }     puts( 0 );     return 0;   }


#include <bits/stdc++.h>   namespace myland {   using namespace std;   namespace _abbr {   const double EPS(1e-8);   const double PI(acos(-1.0));   const int INF(0x3f3f3f3f);   const long long INFL(0x3f3f3f3f3f3f3f3fll);   const int MOD(1e9 + 7);   }  // namespace _abbr   using namespace _abbr;   namespace _solve {}   using namespace _solve;   namespace _calculate {   bool odd(long long x) { return x & 1; }   bool even(long long x) { return (x & 1) ^ 1; }   bool posi(long long x) { return x > 0; }   bool nega(long long x) { return x < 0; }   bool zero(long long x) { return x == 0; }   bool prime(long long x) {     if (x < 2) return 0;     for (int i = 2; i * i <= x; i++)       if (x % i == 0) return 0;     return 1;   }   long long droot(long long x) { return 1 + (x - 1) % 9; }   long long upd(long long a, long long b) { return a % b ? a / b + 1 : a / b; };   long long random(long long a, long long b) {     return a + rand() * rand() % (b - a + 1);   };   long long bitn(long long x) {     long long c = 0;     while (x) c++, x >>= 1;     return c;   }   template <class T>   T sqr(T x) {     return x * x;   }   long long qpow(long long a, long long n, long long mod = MOD) {     long long res(1);     while (n) {       if (n & 1) (res *= a) %= mod;       (a *= a) %= mod;       n >>= 1;     }     return res % mod;   }   template <class T>   void tomin(T& a, T b) {     if (b < a) a = b;   }   template <class T>   void tomax(T& a, T b) {     if (b > a) a = b;   }   }  // namespace _calculate   using namespace _calculate;   namespace _simple_algo {   long long stol(const string& s) {     long long x = 0;     for (char c : s) x = x * 10 + c - 48;     return x;   }   string ltos(long long x) {     string s =   ;     if (x == 0) return  0 ;     while (x) s = char(x % 10 + 48) + s, x /= 10;     return s;   }   bool pal(const string& s) {     int l = s.size();     for (int i = 0, j = l - 1; i < j; i++, j--)       if (s[i] != s[j]) return 0;     return 1;   }   }  // namespace _simple_algo   using namespace _simple_algo;   namespace _io {   template <class T>   void rd(T& x) {     cin >> x;   }   long long rd() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   void rd(int& x) { x = rd(); }   void rd(long long& x) { x = rd(); }   template <class A, class B>   void rd(A& a, B& b) {     rd(a), rd(b);   }   template <class A, class B>   void rd(pair<A, B>& p) {     cin >> p.first >> p.second;   }   template <class T>   void wt(const T& x) {     cout << x << endl;   }   template <class T>   void wt(const T& x, char c) {     cout << x << c;   }   template <class T>   void wt(const T& x, const string& s) {     cout << x << s;   }   template <class T>   void wt(const T& x, int rnd) {     cout << fixed << setprecision(rnd) << x << endl;   }   template <class A, class B>   void wt(const pair<A, B>& make_pair) {     cout << make_pair.first <<     << make_pair.second << endl;   }   template <class T>   void wt(const vector<T>& vec, int l, int r) {     for (int i = l; i <= r; i++) cout << vec[i] <<    ;     cout << endl;   }   }  // namespace _io   using namespace _io;   }  // namespace myland   using namespace myland;   const int N(2e5 + 5);   long long n, k;   long long a[N], d[N];   int main() {     rd(n, k);     for (int i = 1; i <= n; i++) rd(a[i]), d[a[i] % k]++;     long long ans(0);     for (int i = 0; i <= k - 1; i++) {       if (i == 0 || (k % 2 == 0 && i == k / 2)) {         ans += d[i] / 2 * 2;         continue;       }       long long t(min(d[i], d[k - i]));       d[i] -= t;       d[k - i] -= t;       ans += 2 * t;     }     wt(ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n = 0, a[100001];     long long sum = 0, x = 0, ans = 0;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i], sum += a[i];     sum = sum / n;     for (int i = 0; i < n; i++) x += a[i] - sum, ans += abs(x);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1010;   int vis[N];   vector<int> a[N], tmp;   int main() {     int n;     scanf( %d , &n);     int x = 1;     for (int i = 2; i <= n; i++) {       if (n - (n + i - 1) / i - i + 1 > n - (n + x - 1) / x - x + 1) x = i;     }     int ans = n - (n + x - 1) / x - x + 1;     int cur = 0;     for (int i = 1; i <= n; i++) {       if (i % x == 1) cur++;       a[cur].push_back(i);     }     int cnt = 0;     while (cnt < ans) {       for (int i = 1; i <= cur; i++) {         int sz = a[i].size();         for (int j = 0; j < sz - 1; j++) {           if (!vis[a[i][j]]) {             vis[a[i][j]] = 1;             tmp.push_back(a[i][j]);           }           if (tmp.size() == x) break;         }         if (tmp.size() == x) break;       }       int k = tmp.size();       cnt += k;       printf( %d  , k);       for (int j : tmp) printf( %d  , j);       printf(  n );       fflush(stdout);       tmp.clear();       int pos;       scanf( %d , &pos);       for (int i = 1; i <= k; i++) {         if (vis[pos]) cnt--;         vis[pos] = 0;         pos = pos % n + 1;       }     }     printf( 0 n );     fflush(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     bool a[m + 1];     memset(a, 0, sizeof(a));     for (int i = 1; i <= n; i++) {       int l, r;       cin >> l >> r;       for (int j = l; j <= r; j++) a[j] = 1;     }     vector<int> v;     int res = 0;     for (int i = 1; i <= m; i++) {       if (a[i] == 0) {         res++;         v.push_back(i);       }     }     cout << res << endl;     for (int i = 0; i < v.size(); i++) cout << v[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   struct a1 {     int value, freq;   } arr[101];   bool compare(a1 lhs, a1 rhs) { return lhs.freq > rhs.freq; }   int main() {     int temp = 0, j, n, num = 0, m, i, a[101], ans = 0;     scanf( %d %d , &n, &m);     int b[n], c[n];     memset(a, 0, sizeof(a));     for (i = 0; i < n; i++) {       scanf( %d , &temp);       a[temp]++;     }     temp = 0;     for (i = 1; i <= 100; i++) {       if (a[i] != 0) {         arr[num].freq = a[i];         arr[num++].value = i;       }     }     sort(arr, arr + num, compare);     for (i = 0; i < num; i++) {       j = 0;       while (j < arr[i].freq) {         b[temp++] = arr[i].value;         j++;       }     }     for (i = arr[0].freq; i < n; i++) {       c[i - arr[0].freq] = b[i];     }     for (i = 0; i < arr[0].freq; i++) {       c[n - arr[0].freq + i] = arr[0].value;     }     for (i = 0; i < n; i++) {       if (b[i] != c[i]) ans++;     }     printf( %d n , ans);     for (i = 0; i < n; i++) {       printf( %d %d n , b[i], c[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class A>   void pr(A a) {     cout << a;     cout <<   n ;   }   template <class A, class B>   void pr(A a, B b) {     cout << a <<    ;     pr(b);   }   template <class A, class B, class C>   void pr(A a, B b, C c) {     cout << a <<    ;     pr(b, c);   }   template <class A, class B, class C, class D>   void pr(A a, B b, C c, D d) {     cout << a <<    ;     pr(b, c, d);   }   template <class A>   void PR(A a, long long n) {     for (long long i = (long long)(0); i < (long long)(n); i++) {       if (i) cout <<    ;       cout << a[i];     }     cout <<   n ;   }   long long check(long long n, long long m, long long x, long long y) {     return x >= 0 && x < n && y >= 0 && y < m;   }   const long long MAX = 1e9 + 7, MAXL = 1LL << 61, dx[4] = {-1, 0, 1, 0},                   dy[4] = {0, 1, 0, -1};   void Main() {     int h1, m1, h2, m2;     scanf( %d:%d , &h1, &m1);     scanf( %d:%d , &h2, &m2);     int d = h1 * 60 + m1 + h2 * 60 + m2;     d /= 2;     if (h1 * 60 + m1 > h2 * 60 + m2) d += 12 * 60;     d %= 24 * 60;     printf( %02d:%02d n , d / 60, d % 60);   }   int main() {     Main();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   struct Node {     int a, px, ori, c;   } node[N];   int n, l, r;   bool cmp_px(Node &a, Node &b) { return a.px < b.px; }   bool cmp_ori(Node &a, Node &b) { return a.ori < b.ori; }   int main() {     cin >> n >> l >> r;     int t;     for (int i = 0; i < n; i++) {       cin >> t;       node[i].ori = i;       node[i].a = t * (-1);       node[i].c = l;     }     for (int i = 0; i < n; i++) {       cin >> t;       node[i].px = t;     }     sort(node, node + n, cmp_px);     for (int i = 1; i < n; i++) {       if (node[i].a > node[i - 1].a) continue;       int cha = node[i - 1].a - node[i].a;       node[i].a = node[i].a + cha + 1;       node[i].c += cha + 1;       if (node[i].c > r) {         cout << -1 << endl;         return 0;       }     }     {       sort(node, node + n, cmp_ori);       for (int i = 0; i < n; i++) {         cout << node[i].c <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int sb, eb;     vector<int> box;     cin >> sb;     for (int a = 0; a < sb; a++) {       cin >> eb;       box.push_back(eb);     }     sort(box.begin(), box.end());     for (int a = 0; a < sb; a++) {       cout << box[a] <<    ;     }   }


#include <bits/stdc++.h>   void sc(int &x) { scanf( %d , &x); }   void sc(int &x, int &y) { scanf( %d%d , &x, &y); }   void sc(int &x, int &y, int &z) { scanf( %d%d%d , &x, &y, &z); }   void sc(long long &x) { scanf( %lld , &x); }   void sc(long long &x, long long &y) { scanf( %lld%lld , &x, &y); }   void sc(long long &x, long long &y, long long &z) {     scanf( %lld%lld%lld , &x, &y, &z);   }   void sc(char *x) { scanf( %s , x); }   void sc(char *x, char *y) { scanf( %s%s , x, y); }   void sc(char *x, char *y, char *z) { scanf( %s%s%s , x, y, z); }   void out(int x) { printf( %d n , x); }   void out(long long x) { printf( %lld n , x); }   void out(int x, int y) { printf( %d %d n , x, y); }   void out(long long x, long long y) { printf( %lld %lld n , x, y); }   void out(int x, int y, int z) { printf( %d %d %d n , x, y, z); }   void out(long long x, long long y, long long z) {     printf( %lld %lld %lld n , x, y, z);   }   void ast(long long x, long long l, long long r) { assert(x >= l && x <= r); }   using namespace std;   const int N = 666, mod = 998244353;   int k, a, h, rk[N], srk[N], g[N];   vector<pair<int, int>> l1, l2, r1, r2;   void sol(int l, int r, vector<pair<int, int>> &s1, vector<pair<int, int>> &s2) {     int len = r - l + 1;     int tot = 0;     while (len) {       len /= 2;       tot += len;     }     int up = 1 << tot;     for (int i = 0; i < up; i++) {       int cur = k + 1;       vector<int> vc;       for (int j = l; j <= r; j++) vc.push_back(j);       int s = 0;       int mul = 0;       while (vc.size() > 1) {         vector<int> gc;         for (int j = 0; j < vc.size(); j += 2) {           if (i >> s & 1)             mul = (mul + 1ll * vc[j] * g[cur]) % mod, gc.push_back(vc[j + 1]);           else             mul = (mul + 1ll * vc[j + 1] * g[cur]) % mod, gc.push_back(vc[j]);           s++;         }         vc = gc;         cur--;       }       assert(s == tot);       assert(cur == 2);       assert(vc.size() == 1);       s1.push_back({(mul + 1ll * vc[0] * g[1]) % mod, i});       s2.push_back({(mul + 1ll * vc[0] * g[2]) % mod, i});     }   }   int ans[N];   int cal(int i, int l, int r) {     vector<int> vc;     for (int j = l; j <= r; j++) vc.push_back(j);     int s = 0, cur = k + 1;     while (vc.size() > 1) {       vector<int> gc;       for (int j = 0; j < vc.size(); j += 2) {         if (i >> s & 1)           ans[vc[j]] = rk[cur], gc.push_back(vc[j + 1]);         else           ans[vc[j + 1]] = rk[cur], gc.push_back(vc[j]);         s++;       }       vc = gc;       cur--;     }     return vc[0];   }   void get(vector<pair<int, int>> &l, vector<pair<int, int>> &r, int rkl,            int rkr) {     sort(r.begin(), r.end());     for (pair<int, int> x : l) {       int pos = lower_bound(r.begin(), r.end(),                             make_pair((h + mod - x.first) % mod, 0)) -                 r.begin();       if (pos >= 0 && pos < r.size() &&           r[pos].first == (h + mod - x.first) % mod) {         int a = cal(x.second, 1, 1 << (k - 1)),             b = cal(r[pos].second, (1 << (k - 1)) + 1, 1 << k);         ans[a] = rkl;         ans[b] = rkr;         for (int i = 1; i <= (1 << k); i++)           printf(i == (1 << k) ?  %d n  :  %d  , ans[i]);         exit(0);       }     }   }   void sol(int cas) {     sc(k, a, h);     for (int i = 1; i <= k + 1; i++) rk[i] = i - 2 >= 0 ? (1 << (i - 2)) + 1 : 1;     for (int i = 1; i <= k + 1; i++) {       g[i] = 1;       for (int j = 1; j <= rk[i]; j++) g[i] = 1ll * g[i] * a % mod;     }     sol(1, 1 << (k - 1), l1, l2);     sol((1 << (k - 1)) + 1, 1 << k, r1, r2);     get(l1, r2, 1, 2);     get(l2, r1, 2, 1);     out(-1);   }   int main() {     srand(time(0));     int t = 1, cas = 0;     while (t--) {       sol(++cas);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, q, cnt, k, m, r, ans;   int fa[21][100010], dep[100010], st[100010], ed[100010], h[100010];   int f[100010][310];   int t[100010];   bool vis[100010];   struct node {     int id, num;     bool operator<(const node &T) const { return num < T.num; }   } s[100010];   vector<int> e[100010], Q;   inline void insert(int u, int v) {     e[u].push_back(v);     e[v].push_back(u);   }   int find(int x) {     int sum = 0;     for (; x; x -= (x & -x)) sum += t[x];     return sum;   }   void add(int x, int k) {     for (; x <= n; x += (x & -x)) t[x] += k;   }   void dfs(int x) {     st[x] = ++cnt;     for (int i = 0; i < e[x].size(); i++)       if (fa[0][x] != e[x][i]) {         fa[0][e[x][i]] = x;         dep[e[x][i]] = dep[x] + 1;         dfs(e[x][i]);       }     ed[x] = cnt;   }   int lca(int a, int b) {     int i, kk;     if (dep[a] != dep[b]) {       if (dep[a] < dep[b]) swap(a, b);       i = 0;       kk = 1;       while (kk <= dep[a] - dep[b]) {         i++;         kk <<= 1;       }       while (dep[a] > dep[b]) {         if (kk <= dep[a] - dep[b]) a = fa[i][a];         i--;         kk >>= 1;       }     }     if (a == b) return a;     i = 0;     while (fa[i][a] != fa[i][b]) i++;     while (fa[0][a] != fa[0][b]) {       if (fa[i][a] != fa[i][b]) {         a = fa[i][a];         b = fa[i][b];       }       i--;     }     return fa[0][a];   }   int main() {     int a, b;     scanf( %d%d , &n, &q);     for (int i = 1; i < n; i++) {       scanf( %d%d , &a, &b);       insert(a, b);     }     dfs(1);     f[0][0] = 1ll;     for (int i = 1; i <= 20; i++)       for (int j = 1; j <= n; j++) fa[i][j] = fa[i - 1][fa[i - 1][j]];     while (q--) {       scanf( %d%d%d , &k, &m, &r);       Q.clear();       cnt = ans = 0;       for (int j = 1; j <= k; j++) {         scanf( %d , &a);         Q.push_back(a);         vis[a] = 1;         add(st[a], 1);         add(ed[a] + 1, -1);       }       for (int j = 0; j < k; j++) {         a = Q[j];         b = lca(r, a);         h[a] = find(st[a]) + find(st[r]) - 2 * find(st[b]) + vis[b] - 1;         s[++cnt].id = a;         s[cnt].num = h[a];       }       sort(s + 1, s + 1 + cnt);       for (int i = 0; i <= m; i++) f[1][i] = 0ll;       for (int i = 1; i <= k; i++)         for (int j = 1; j <= m; j++)           f[i][j] = ((long long)f[i - 1][j] * (j - s[i].num) % 1000000007 +                      f[i - 1][j - 1]) %                     1000000007;       for (int j = 1; j <= m; j++) ans = (ans + f[k][j]) % 1000000007;       printf( %d n , ans);       for (int j = 0; j < k; j++) {         a = Q[j];         add(st[a], -1);         add(ed[a] + 1, 1);         vis[a] = 0;       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   using namespace std;   long long binpow(long long base, long long exp, int mod) {     long long res = 1;     while (exp > 0) {       if (exp % 2 == 1) res = (res * base) % mod;       exp = exp >> 1;       base = (base * base) % mod;     }     return res;   }   long long mod(long long x) {     return ((x % 1000000007LL + 1000000007LL) % 1000000007LL);   }   long long add(long long a, long long b) { return mod(mod(a) + mod(b)); }   long long mul(long long a, long long b) { return mod(mod(a) * mod(b)); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int t;     cin >> t;     while (t--) {       long long int n, m;       cin >> n >> m;       long long int maxdiff = -1e18;       long long int maxele = -1e18;       for (int i = 0; i < n; i++) {         long long int l, r;         cin >> l >> r;         maxdiff = max(maxdiff, l - r);         maxele = max(maxele, l);       }       long long int ans = 1;       m -= maxele;       if (m > 0) {         if (maxdiff <= 0) {           ans = -1;         } else {           ans += (m + maxdiff - 1) / maxdiff;         }       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   const double PI = 3.141592653589793238460;   using namespace std;   vector<int> d;   vector<int> l;   vector<int> r;   vector<int> u;   bool isPossibleL(string st) {     for (char ch : st) {       for (int n : l)         if (ch -  0  == n) return false;     }     return true;   }   bool isPossibleR(string st) {     for (char ch : st) {       for (int n : r)         if (ch -  0  == n) return false;     }     return true;   }   bool isPossibleU(string st) {     for (char ch : st) {       for (int n : u)         if (ch -  0  == n) return false;     }     return true;   }   bool isPossibleD(string st) {     for (char ch : st) {       for (int n : d)         if (ch -  0  == n) return false;     }     return true;   }   int main() {     l.push_back(1), l.push_back(4), l.push_back(7), l.push_back(0);     r.push_back(3), r.push_back(6), r.push_back(9), r.push_back(0);     d.push_back(7), d.push_back(0), d.push_back(9);     u.push_back(1), u.push_back(2), u.push_back(3);     int n;     string st;     cin >> n >> st;     if (isPossibleL(st) || isPossibleR(st) || isPossibleU(st) || isPossibleD(st))       cout <<  NO ;     else       cout <<  YES ;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> statues(8);   vector<vector<char>> MAT(8, vector<char>(8));   vector<vector<vector<bool>>> VIS(8,                                    vector<vector<bool>>(8,                                                         vector<bool>(10, false)));   vector<pair<int, int>> moveDir = {{0, 1},  {0, -1}, {1, 0},   {-1, 0}, {1, 1},                                     {-1, 1}, {1, -1}, {-1, -1}, {0, 0}};   bool checkStatues(int r, int c, int level) {     for (int i = 0; i < statues[c].size(); ++i) {       if (statues[c][i] + level < 8 && statues[c][i] + level == r) return false;     }     return true;   }   bool isSafe(int r, int c, int level) {     if (level > 8) level = 8;     if (r < 0 || r >= 8 || c < 0 || c >= 8 || VIS[r][c][level]) return false;     return checkStatues(r, c, level);   }   bool dfs(int r, int c, int level) {     bool canMove = false;     if (level > 8) level = 8;     if (r == 0 && c == 7) return true;     for (int i = 0; i < 9; ++i) {       int newR = r + moveDir[i].first;       int newC = c + moveDir[i].second;       if (isSafe(newR, newC, level + 1) && checkStatues(newR, newC, level)) {         VIS[r][c][level] = true;         canMove = canMove || dfs(newR, newC, level + 1);       }     }     return canMove;   }   int main() {     for (int i = 0; i < 8; ++i) {       for (int j = 0; j < 8; ++j) {         cin >> MAT[i][j];         if (MAT[i][j] ==  S ) statues[j].push_back(i);       }     }     bool canWin = dfs(7, 0, 0);     cout << ((canWin) ?  WIN  :  LOSE ) <<   n ;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   const double eps = 10e-10;   const int mod = 1000000007;   const int maxn = 300005;   const int maxm = 10005;   pair<int, int> ans[maxn];   int main() {     int n, m, a;     while (~scanf( %d%d , &n, &m)) {       priority_queue<pair<int, int> > q;       for (int i = (0); i < (n); i++)         scanf( %d , &a), q.push(make_pair(a, i + 1));       int cnt = 0;       while (!q.empty()) {         stack<pair<int, int> > st;         pair<int, int> cur = q.top();         q.pop();         while (!q.empty() && cur.first) {           pair<int, int> cc = q.top();           q.pop();           if (cc.first >= 1)             cc.first--, cur.first--,                 ans[cnt++] = make_pair(cc.second, cur.second);           if (cc.first) st.push(cc);         }         if (cur.first) break;         while (!st.empty()) q.push(st.top()), st.pop();       }       if (cnt < m / 2) {         puts( No );         continue;       }       printf( Yes n%d n , m / 2);       for (int i = (0); i < (cnt); i++)         printf( %d %d n , ans[i].first, ans[i].second);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M, neg, nsus;   int ar[100002];   int cnt[100002];   int sus[100002];   int main() {     scanf( %d%d , &N, &M);     for (int i = 1; i <= N; i++) {       scanf( %d , &ar[i]);       if (ar[i] > 0)         cnt[ar[i]]++;       else {         cnt[-ar[i]]--;         neg++;       }     }     for (int i = 1; i <= N; i++)       if (cnt[i] + neg == M) {         sus[i] = 1;         nsus++;       }     for (int i = 1; i <= N; i++) {       if ((ar[i] < 0 && !sus[-ar[i]]) || (ar[i] > 0 && sus[ar[i]] && nsus == 1))         printf( Truth n );       else if ((ar[i] < 0 && sus[-ar[i]] && nsus == 1) ||                (ar[i] > 0 && !sus[ar[i]]))         printf( Lie n );       else         printf( Not defined n );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       long long a = 0;       for (int i = 0; i < n; i++) {         int k;         cin >> k;         a += k;       }       if (a == m)         cout <<  YES ;       else         cout <<  NO ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int fib;     cin >> fib;     cout << fib <<     << 0 <<     << 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mx = 1e2 + 10;   const long long mod = 1e9 + 31;   mt19937 mtrand(time(0));   int n, m;   char s[2][1 << 12];   int mp[2][1 << 14];   int f[1 << 15], ans, pr[1 << 15];   int unfd(int x) {     int r = x;     while (r != f[r]) r = f[r];     int t;     while (f[x] != r) t = f[x], f[x] = r, x = t;     return r;   }   void unjoin(int x, int y) {     int fx = unfd(x), fy = unfd(y);     if (fx != fy) {       --ans;       f[fx] = fy;     }   }   int main() {     int num;     cin >> n >> m;     for (int i = 0; i < n; ++i) {       int id = i & 1, nid = id ^ 1;       scanf( %s , s[id]);       num = 0;       for (int j = 0; j < m / 4; ++j) {         if (s[id][j] >=  0  && s[id][j] <=  9 )           num = s[id][j] -  0 ;         else           num = s[id][j] -  A  + 10;         for (int k = 0; k < 4; ++k) {           mp[id][j * 4 + k] = (num >> (3 - k)) & 1;           if (mp[id][j * 4 + k] == 1) ++ans;         }       }       for (int j = m; j < m * 2; ++j) f[j] = j;       if (i > 0) {         for (int j = 0; j < m; ++j) {           if (mp[nid][j] & mp[id][j]) unjoin(j, m + j);         }       }       for (int j = 1; j < m; ++j) {         if (mp[id][j - 1] & mp[id][j]) unjoin(m + j - 1, m + j);       }       for (int j = m; j < m * 2; ++j) {         pr[unfd(j)] = j - m;       }       for (int j = 0; j < m; ++j) {         f[j] = pr[unfd(j + m)];       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 2e5 + 10;   const long long INF = 1e18;   const long long mod = 1e9 + 7;   long long poww(long long a, long long b) {     if (b == 0) return 1;     long long x = poww(a, b / 2) % mod;     if (b & 1)       return (((x * x) % mod) * a) % mod;     else       return (x * x) % mod;   }   long long n, m, k, dis[maxn], mark[maxn], p[maxn], ans1 = 0, ans2 = 0;   vector<long long> g[maxn], g2[maxn];   void bfs(long long v) {     queue<long long> qu;     for (int i = 1; i <= n; i++) {       mark[i] = 0;       dis[i] = INF;     }     mark[v] = 1;     dis[v] = 0;     qu.push(v);     while (qu.size()) {       long long u = qu.front();       qu.pop();       for (auto uu : g2[u]) {         if (!mark[uu]) {           mark[uu] = 1;           dis[uu] = dis[u] + 1;           qu.push(uu);         }       }     }   }   int main() {     std::ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= m; i++) {       long long v, u;       cin >> v >> u;       g[v].push_back(u);       g2[u].push_back(v);     }     cin >> k;     for (int i = 1; i <= k; i++) cin >> p[i];     long long t = p[k];     bfs(t);     for (int i = 1; i < k; i++) {       long long minn = INF, te = 0;       for (auto u : g[p[i]]) {         if (dis[u] < minn) {           minn = dis[u];           te = 1;         } else if (dis[u] == minn)           te++;       }       long long to = p[i + 1];       if (dis[to] > minn) {         ans1++;         ans2++;       } else {         if (te > 1) ans2++;       }     }     cout << ans1 <<     << ans2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int a, b, c, d;       cin >> a >> b >> c >> d;       if (a == 0 || b == 0 || c == 0) {         int cnt = 0;         if (a % 2 == 1) cnt++;         if (b % 2 == 1) cnt++;         if (c % 2 == 1) cnt++;         if (d % 2 == 1) cnt++;         if (cnt < 2)           cout <<  Yes  << endl;         else           cout <<  No  << endl;         continue;       }       int cnt = 0;       if (a % 2 == 1) cnt++;       if (b % 2 == 1) cnt++;       if (c % 2 == 1) cnt++;       if (d % 2 == 1) cnt++;       if (cnt == 1 || cnt == 0)         cout <<  Yes  << endl;       else {         a--;         b--;         c--;         d += 3;         int cnt = 0;         if (a % 2 == 1) cnt++;         if (b % 2 == 1) cnt++;         if (c % 2 == 1) cnt++;         if (d % 2 == 1) cnt++;         if (cnt == 1 || cnt == 0)           cout <<  Yes  << endl;         else           cout <<  No  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, sum = 0;       long long ans = 0;       cin >> n;       char s[n];       cin >> (s + 1);       map<int, int> f;       f[0] = 1;       for (int i = 1; i <= n; i++) {         int tmp = s[i] -  0 ;         sum += tmp;         ans += f[sum - i];         f[sum - i]++;       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, a[300005], b1[500005], b2[500005],       cnt = 0, pl[300005], c[300005], ans = 0, plc[300005], m, d, can[300005], r,       ne[300005];   pair<int, int> p;   pair<int, int> p1;   pair<int, int> p2;   map<pair<int, int>, int> m1;   string s;   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> a[i];       pl[a[i]] = i;       can[i] = 0;       ne[i] = i + 1;     }     for (int i = 0; i < m; i++) {       cin >> b1[i] >> b2[i];       p.first = b1[i];       p.second = b2[i];       m1[p] = 1;       if (b2[i] == a[n]) {         c[cnt] = b1[i];         plc[cnt] = pl[b1[i]];         cnt++;       }     }     sort(plc, plc + cnt);     for (int i = 0; i < cnt; i++) {       c[i] = a[plc[i]];     }     for (int i = cnt - 1; i >= 0; i--) {       d = 1;       r = ne[pl[c[i]]];       while (r < n) {         p1.first = c[i];         p1.second = a[r];         if (m1[p1] == 0) {           d = 0;           break;         }         r = ne[r];       }       if (d) {         ans++;         if (c[i] > 0) {           ne[pl[c[i]] - 1] = ne[pl[c[i]]];         }       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   struct BIT {     int n;     vector<T> dat;     BIT(int n = 0) { initialize(n); }     void initialize(int nin) {       n = nin;       dat.resize(n, 0);     }     T sum(int i) {       T s = 0;       while (i >= 0) {         s += dat[i];         i = (i & (i + 1)) - 1;       }       return s;     }     T sum_between(int i, int j) { return sum(j) - sum(i - 1); }     void plus(int i, T x) {       while (i < n) {         dat[i] += x;         i |= i + 1;       }     }     int lower_bound(T x) {       if (x < 0) return -1;       if (sum(n - 1) < x) return n;       int ret = -1;       int k = 1;       while (2 * k <= n) k <<= 1;       for (; k > 0; k >>= 1) {         if (ret + k < n && dat[ret + k] < x) {           x -= dat[ret + k];           ret += k;         }       }       return ret + 1;     }   };   void solve() {     string S;     cin >> S;     vector<pair<int, int>> D;     for (int i = 0; i < int(S.size()) - 1; i++)       if (S[i] == S[i + 1]) {         D.emplace_back(S[i] -  a , i + 1);       }     int N = D.size();     vector<int> num(26);     BIT<int> bit[26], bit_sum(N);     for (int k = 0; k < 26; k++) bit[k].initialize(N);     for (int i = 0; i < N; i++) {       int al = D[i].first;       num[al]++;       bit[al].plus(i, 1);       bit_sum.plus(i, D[i].second - (i ? D[i - 1].second : 0));     }     int sum = N;     int total = S.size();     vector<pair<int, int>> ans;     while (true) {       int mx_al = max_element(num.begin(), num.end()) - num.begin();       if (num[mx_al] == sum) break;       int fst = bit[mx_al].lower_bound(1);       int r = N, l = -1;       for (int k = 0; k < 26; k++)         if (k != mx_al) {           int pos = bit[k].lower_bound(bit[k].sum(fst) + 1);           r = min(r, pos);         }       if (r == N) {         r = fst;         for (int k = 0; k < 26; k++)           if (k != mx_al) {             int pos = bit[k].lower_bound(bit[k].sum(fst));             l = max(l, pos);           }       } else {         l = bit[mx_al].lower_bound(bit[mx_al].sum(r));       }       int LL = bit_sum.sum(l);       int RR = bit_sum.sum(r);       ans.emplace_back(LL, RR);       bit_sum.plus(l + 1, LL - RR);       total -= RR - LL;       sum -= 2;       num[D[l].first]--;       num[D[r].first]--;       bit[D[l].first].plus(l, -1);       bit[D[r].first].plus(r, -1);     }     for (int i = 0; i < N; i++) {       int s = bit[D[i].first].sum_between(i, i);       if (s > 0) {         int rem = bit_sum.sum(i);         ans.emplace_back(0, rem);         bit_sum.plus(0, -rem);         total -= rem;       }     }     ans.emplace_back(0, total);     printf( %d n , int(ans.size()));     for (auto& p : ans) printf( %d %d n , p.first + 1, p.second);   }   int main() {     int T;     cin >> T;     while (T--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n];     int orig[n];     int product = 1;     int counter = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];       orig[i] = arr[i];       if (arr[i] >= 0) {         arr[i] = -arr[i] - 1;       }       if (arr[i] < 0) {         counter++;       }     }     if (counter % 2 == 0) {       for (int i = 0; i < n; i++) {         cout << arr[i] <<    ;       }     } else {       int maxAbsVal = 0;       int maxIndex = 0;       for (int i = 0; i < n; i++) {         if (abs(arr[i]) >= maxAbsVal) {           maxAbsVal = abs(arr[i]);           maxIndex = i;         }       }       if (arr[maxIndex] == orig[maxIndex]) {         arr[maxIndex] = -arr[maxIndex] - 1;       } else {         arr[maxIndex] = orig[maxIndex];       }       for (int i = 0; i < n; i++) {         cout << arr[i] <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   struct node {     int index, val, team;   };   node ni[N];   int divi[N], rest[N];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       ni[i].index = i;       scanf( %d , &ni[i].val);     }     sort(ni, ni + n, [](const node &a, const node &b) { return a.val < b.val; });     fill(begin(divi), end(divi), -0x3f3f3f3f);     for (int i = 3; i < n; ++i) {       divi[i] = rest[i - 3] + ni[i].val - ni[i - 1].val;       rest[i - 2] = max(divi[i - 2], rest[i - 3]);     }     int k = 1;     for (int i = n - 1; i >= n - 3; --i) {       ni[i].team = k;     }     for (int i = n - 3; i > 0;) {       if (rest[i] == divi[i]) {         ++k;         for (int j = i; j > 0 && j > i - 3; --j) {           ni[j - 1].team = k;         }         i -= 3;       } else {         i -= 1;         ni[i].team = k;       }     }     printf( %d %d n , ni[n - 1].val - ni[0].val - rest[n - 3], k);     sort(ni, ni + n,          [](const node &a, const node &b) { return a.index < b.index; });     for (int i = 0; i < n; ++i) {       printf( %d  , ni[i].team);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, m, i;     float x, max = 0.0;     scanf( %d%d , &n, &m);     int s[n][2];     for (i = 0; i < n; i++) {       scanf( %d%d , &s[i][0], &s[i][1]);       x = (float)(s[i][0]) / s[i][1];       if (max == 0.0) {         max = x;       }       if (max > x) {         max = x;       }     }     x = max * m;     printf( %.8f n , x);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int t, next;   } a[800010];   struct hhhh {     int l, r;   } h[200010];   vector<pair<int, int> > v[400010];   vector<int> g[400010];   long long ans[400010];   int fa[400010], son[400010], dep[400010], top[400010], size[400010];   int fat[400010][20], head[400010], id[400010], c[400010], len[400010], n, m, tt,       tot;   char s[400010];   inline int rd() {     int x = 0;     char ch = getchar();     for (; ch <  0  || ch >  9 ; ch = getchar())       ;     for (; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch -  0 ;     return x;   }   inline void print(long long x) {     static char s[233];     if (!x) {       putchar( 0 );       putchar(  n );       return;     }     int tot = 0;     for (; x; x /= 10) s[++tot] = x % 10 +  0 ;     for (; tot; tot--) putchar(s[tot]);     putchar(  n );   }   inline void add(int x, int y) {     a[++tot].t = y;     a[tot].next = head[x];     head[x] = tot;   }   namespace sam {   int ch[400010][26], fa[400010], len[400010], tot, last;   inline void init() { tot = last = 1; }   inline int insert(int x) {     int p = last, np = ++tot;     len[np] = len[p] + 1;     for (; p && !ch[p][x]; p = fa[p]) ch[p][x] = np;     if (!p)       fa[np] = 1;     else {       int q = ch[p][x];       if (len[q] == len[p] + 1)         fa[np] = q;       else {         int nq = ++tot;         memcpy(ch[nq], ch[q], sizeof(ch[q]));         len[nq] = len[p] + 1;         fa[nq] = fa[q];         fa[q] = fa[np] = nq;         for (; p && ch[p][x] == q; p = fa[p]) ch[p][x] = nq;       }     }     return last = np;   }   inline void build() {     for (int i = 2; i <= tot; i++) add(fa[i], i);   }   }  // namespace sam   inline void dfs1(int x) {     size[x] = 1;     for (int i = head[x]; i; i = a[i].next) {       int t = a[i].t;       if (t == fa[x]) continue;       dep[t] = dep[x] + 1;       fa[t] = x;       dfs1(t);       size[x] += size[t];       if (size[t] > size[son[x]]) son[x] = t;     }   }   inline void dfs2(int x, int tp) {     top[x] = tp;     if (son[x]) dfs2(son[x], tp);     for (int i = head[x]; i; i = a[i].next) {       int t = a[i].t;       if (t == fa[x] || t == son[x]) continue;       dfs2(t, t);     }   }   struct bit {     long long c[200010];     inline void add(int x, long long y) {       for (; x <= n; x += ((x) & (-(x)))) c[x] += y;     }     inline void modify(int l, int r, long long hh) {       add(l, hh);       add(r + 1, -hh);     }     inline long long query(int x) {       long long res = 0;       for (; x > 0; x -= ((x) & (-(x)))) res += c[x];       return res;     }     inline long long query(int l, int r) { return query(r) - query(l - 1); }   } c1, c2, c3, c4, c5;   inline void work() {     int hh = len[fa[c[1]]] + 1;     for (int i = 1; i <= tt; i++) {       int x = c[i];       for (int t : g[x]) {         int k = t + hh - 1;         c1.add(k, 1);         c2.add(k, k);       }     }     for (int i = 1; i <= tt; i++) {       int x = c[i], now = len[x] - hh + 1;       for (pair<int, int> hhh : v[x]) {         int t = hhh.first, now = hhh.second;         int l = h[t].l, r = h[t].r;         ans[t] += c1.query(r - now) * now;         ans[t] += c1.query(r - now + 1, r) * (r + 1) - c2.query(r - now + 1, r);         ans[t] += c3.query(r) + c4.query(r) * r - c5.query(r);       }       for (int t : g[x]) {         int k = t + hh - 1;         c1.add(k, -1);         c2.add(k, -k);         c3.add(k + now, now);         c4.modify(k, k + now - 1, 1);         c5.modify(k, k + now - 1, k - 1);       }     }     for (int i = 1; i <= tt; i++) {       int x = c[i], now = len[x] - hh + 1;       for (int t : g[x]) {         int k = t + hh - 1;         c3.add(k + now, -now);         c4.modify(k, k + now - 1, -1);         c5.modify(k, k + now - 1, -k + 1);         c1.add(t, 1);       }     }     for (int i = 1; i <= tt; i++) {       int x = c[i], now = len[x] - hh + 1;       for (pair<int, int> hhh : v[x]) {         int t = hhh.first, now = hhh.second;         int l = h[t].l, r = h[t].r;         ans[t] -= c1.query(l - 1) * now;         ans[t] -= c2.query(l - 1);       }       for (int t : g[x]) c1.add(t, -1), c2.add(t, now);     }     for (int i = 1; i <= tt; i++)       for (int t : g[c[i]]) c2.add(t, -(len[c[i]] - hh + 1));   }   inline int jump(int x, int y) {     for (int i = 19; ~i; i--)       if (len[fat[x][i]] >= y) x = fat[x][i];     return x;   }   inline void gao() {     for (int i = 1; i <= sam::tot; i++)       if (top[i] == i) {         tt = 0;         for (int j = i; j; j = son[j])           if (j > 1) c[++tt] = j;         work();       }   }   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     m = rd();     sam::init();     for (int i = n; i; i--) id[i] = sam::insert(s[i] -  a );     sam::build();     for (int i = 1; i <= sam::tot; i++) len[i] = sam::len[i];     dfs1(1);     dfs2(1, 1);     for (int i = 1; i <= sam::tot; i++) fat[i][0] = fa[i];     for (int j = 1; j < 20; j++)       for (int i = 1; i <= sam::tot; i++) fat[i][j] = fat[fat[i][j - 1]][j - 1];     for (int i = 1; i <= m; i++) h[i].l = rd(), h[i].r = rd();     for (int i = 1; i <= m; i++) {       int hh = jump(id[h[i].l], h[i].r - h[i].l + 1);       v[hh].push_back(           pair<int, int>(i, (h[i].r - h[i].l + 1) - len[fa[top[hh]]]));       for (int j = fa[top[hh]]; j; j = fa[top[j]])         v[j].push_back(pair<int, int>(i, len[j] - len[fa[top[j]]]));     }     for (int i = 1; i <= n; i++)       for (int j = id[i]; j; j = fa[top[j]]) g[j].push_back(i);     gao();     for (int i = 1; i <= m; i++) print(ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> h;   vector<vector<int> > g;   int h0, v0;   vector<int> val;   int it = 0;   vector<bool> used;   vector<int> treesum, par;   vector<int> treemin;   void update(int v, int l, int r, int ind, int d) {     if (l == r) {       treesum[v] += d;       treemin[v] += d;       return;     }     if (ind <= (r + l) / 2) {       update(v * 2, l, (r + l) / 2, ind, d);     } else {       update(v * 2 + 1, (r + l) / 2 + 1, r, ind, d);     }     treesum[v] = treesum[v * 2] + treesum[v * 2 + 1];     treemin[v] = min(treemin[v * 2], treesum[v * 2] + treemin[v * 2 + 1]);   }   int query(int v, int l, int r, int x) {     if (l == r) {       return l;     }     if (treemin[v * 2] + x < 0) {       return query(v * 2, l, (r + l) / 2, x);     }     return query(v * 2 + 1, (r + l) / 2 + 1, r, treesum[v * 2] + x);   }   void dfs1(int v, int p = -1) {     for (int i = 0; i < g[v].size(); i++) {       int to = g[v][i];       if (to != p) {         val[to] = min(val[v], h[v]);         par[to] = v;         dfs1(to, v);       }     }   }   vector<int> uniq;   int m;   int mass[1000000];   void dfs2(int v) {     mass[++it] = v;     for (int i = 0; i < g[v].size(); i++) {       int to = g[v][i];       if (to != par[v]) {         if (val[to] < h[to]) {           dfs2(to);         }       }     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, k;     cin >> n;     used.resize(n);     g.resize(n);     h.resize(n);     par.resize(n, -1);     val.resize(n);     for (int i = 0; i < n; i++) {       cin >> h[i];       uniq.push_back(h[i]);     }     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       g[a].push_back(b);       g[b].push_back(a);     }     cin >> k;     vector<int> s(k);     for (int i = 0; i < k; i++) {       cin >> s[i];       uniq.push_back(s[i]);     }     sort(uniq.begin(), uniq.end());     m = unique(uniq.begin(), uniq.end()) - uniq.begin();     treesum.resize(4 * m, 0);     treemin.resize(4 * m, 0);     for (int i = 0; i < n; i++) {       h[i] = lower_bound(uniq.begin(), uniq.begin() + m, h[i]) - uniq.begin();     }     for (int i = 0; i < k; i++) {       s[i] = lower_bound(uniq.begin(), uniq.begin() + m, s[i]) - uniq.begin();     }     val[0] = 1e9;     dfs1(0);     for (int i = 0; i < n; i++) {       update(1, 0, m - 1, m - min(val[i], h[i]) - 1, 1);     }     for (int i = 0; i < k; i++) {       update(1, 0, m - 1, m - s[i] - 1, -1);     }     if (treemin[1] >= 0) {       cout << 0;       return 0;     }     int ans = 1e9;     vector<int> b(n);     for (int i = 0; i < n; i++) {       if (h[i] < val[i]) {         it = 0;         dfs2(i);         update(1, 0, m - 1, m - h[i] - 1, -it);         int t = m - query(1, 0, m - 1, 0) - 1;         if (t <= val[i]) {           b[i] = t;           update(1, 0, m - 1, m - t - 1, 1);           for (int j = 2; j <= it; j++) {             b[mass[j]] = min(h[mass[j]], b[par[mass[j]]]);             update(1, 0, m - 1, m - b[mass[j]] - 1, 1);           }           if (treemin[1] >= 0) {             ans = min(ans, uniq[t] - uniq[h[i]]);           }           for (int j = 1; j <= it; j++) {             update(1, 0, m - 1, m - b[mass[j]] - 1, -1);           }         }         update(1, 0, m - 1, m - h[i] - 1, it);       }     }     if (ans == 1e9) {       cout << -1;     } else {       cout << ans;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> l(n), r(n);     for (int i = 0; i < n; i++) {       cin >> l[i] >> r[i];     }     int a = -1, b = -1;     bool ok = true;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (!((l[i] <= l[j] && r[i] <= r[j]) || (l[j] <= l[i] && r[j] <= l[i]))) {           if (a == -1) {             a = i;             b = j;           } else {             if (a == i && j == b)               continue;             else if (a == j && b == i)               continue;             else if (i == a && j != b) {               b = -1;             } else if (i == b && j != a) {               a = i;               b = -1;             } else if (j == a && i != b) {               b = -1;             } else if (j == b && i != a) {               a = j;               b = -1;             } else {               ok = false;             }           }         }       }     }     if (!ok)       cout <<  0 n ;     else if (a == -1 && b == -1) {       cout << n <<   n ;       for (int i = 0; i < n; i++) {         cout << i + 1 <<    ;       }       cout <<   n ;     } else if (b == -1) {       cout <<  1 n  << a + 1 <<   n ;     } else {       if (a > b) swap(a, b);       cout <<  2 n  << a + 1 <<     << b + 1 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int s = 0;     for (int i = 0; i < 5; i++) {       int x;       cin >> x;       s += x;     }     if (s % 5 || !s)       cout <<  -1 ;     else       cout << s / 5;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100000 + 3;   int N, Q, K;   long long a[MAXN], sum[MAXN], save[MAXN];   int main() {     scanf( %d , &N);     memset((save), (-1), sizeof(save));     for (int i = 1; i <= N; ++i) scanf( %lld , &a[i]);     sort(a + 1, a + 1 + N);     for (int i = 1; i <= N; ++i) sum[i] = sum[i - 1] + a[i];     scanf( %d , &Q);     while (Q--) {       scanf( %d , &K);       if (save[K] != -1) {         printf( %lld n , save[K]);         continue;       }       long long ans = 0, deep = 1, deep_size = K, now = N - 1;       while (now > 0) {         long long next = max(0ll, now - deep_size);         ans += (sum[now] - sum[next]) * deep;         ++deep;         now -= deep_size;         deep_size *= K;       }       save[K] = ans;       printf( %lld , ans);       putchar(Q ?     :   n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt;   string s;   stack<int> st;   int main() {     cin >> s;     for (int i = 0; i < s.size(); ++i) {       if (s[i] ==  (  || s[i] ==  [  || s[i] ==  {  || s[i] ==  < ) {         st.push(int(s[i]));       } else {         if (st.empty()) {           cout <<  Impossible ;           return 0;         }         if (st.top() == 40) {           if (int(s[i]) != 41) {             cnt++;           }           if (!st.empty()) st.pop();         } else {           if (st.top() + 2 != int(s[i])) {             cnt++;           }           if (!st.empty()) st.pop();         }       }     }     if (!st.empty()) {       cout <<  Impossible ;       return 0;     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int la, lb, cnt[20], ans[25];   char a[25], b[25];   void find(int v, bool flag) {     if (v > lb) {       for (int i = 1; i <= lb; i++) printf( %d , ans[i]);       exit(0);     }     if (flag && cnt[b[v] -  0 ]) {       cnt[b[v] -  0 ]--;       ans[v] = b[v] -  0 ;       find(v + 1, 1);       ans[v] = 0;       cnt[b[v] -  0 ]++;     }     for (int i = (flag ? b[v] -  0  - 1 : 9); i >= 0; i--)       if (cnt[i]) {         ans[v] = i;         cnt[i]--;         find(v + 1, 0);         ans[v] = 0;         cnt[i]++;       }   }   int main() {     scanf( %s%s , a + 1, b + 1);     la = strlen(a + 1), lb = strlen(b + 1);     for (int i = 1; i <= la; i++) cnt[a[i] -  0 ]++;     if (lb > la) {       lb = la;       for (int i = 1; i <= lb; i++) b[i] =  9 ;     }     find(1, 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, ans, fact[200005];   long long pangkat(long long a, long long b) {     if (b == 0) return 1;     long long temp = pangkat(a, b / 2);     if (b % 2 == 0) return (temp * temp) % 1000000007;     return (((temp * temp) % 1000000007) * a) % 1000000007;   }   long long comb(long long a, long long b) {     long long temp = (fact[b] * fact[a - b]) % 1000000007;     return (fact[a] * pangkat(temp, 1000000007 - 2)) % 1000000007;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     fact[0] = 1;     for (int i = 1; i <= 2 * n; i++) fact[i] = (fact[i - 1] * i) % 1000000007;     ans = 2 * comb(2 * n - 1, n) - n;     cout << ans % 1000000007 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 48;   long long s, x, xCopy, sCopy, pos[MAXN][2], result;   int n, bitS, bitX;   int main() {     cin >> s >> x;     pos[0][0] = 1;     pos[0][1] = 0;     n = 0;     xCopy = x;     sCopy = s;     while (x || s) {       n++;       bitS = s % 2;       bitX = x % 2;       if (bitS == 0 && bitX == 0) {         pos[n][0] = pos[n - 1][0];         pos[n][1] = pos[n - 1][0];       } else {         if (bitS == 0 && bitX == 1) {           pos[n][0] = 0;           pos[n][1] = 2 * pos[n - 1][1];         } else {           if (bitS == 1 && bitX == 0) {             pos[n][0] = pos[n - 1][1];             pos[n][1] = pos[n - 1][1];           } else {             pos[n][0] = 2 * pos[n - 1][0];             pos[n][1] = 0;           }         }       }       s >>= 1;       x >>= 1;     }     result = pos[n][0];     if ((sCopy ^ 0) == xCopy) result -= 2;     cout << result;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 500100;   const int root = 800;   long long lazy[root];   unordered_set<long long> s[root];   long long v[MAXN];   signed main() {     memset(lazy, 0, sizeof lazy);     long long n, m;     scanf( %lld %lld , &n, &m);     for (long long i = 0; i < n; i++)       scanf( %lld , &v[i]), s[i / root].insert(v[i]);     for (long long i = 1; i <= m; i++) {       long long t;       scanf( %lld , &t);       if (t == 1) {         long long l, r, x;         scanf( %lld %lld %lld , &l, &r, &x);         l -= 1, r -= 1;         s[l / root].clear();         for (long long j = (l / root) * root; j < min((l / root + 1) * root, n);              j++) {           if (j >= l && j <= r) v[j] += x;           s[l / root].insert(v[j]);         }         if (l / root == r / root) continue;         for (long long j = l / root + 1; j < r / root; j++) {           lazy[j] += x;         }         s[r / root].clear();         for (long long j = (r / root) * root; j < min((r / root + 1) * root, n);              j++) {           if (j <= r && j >= l) v[j] += x;           s[r / root].insert(v[j]);         }       }       if (t == 2) {         long long y, ini, fim;         scanf( %lld , &y);         bool flag = false;         for (long long j = 0; j < root; j++) {           if (s[j].find(y - lazy[j]) != s[j].end()) {             flag = true;             for (long long k = j * root; k < (j + 1) * root; k++)               if (v[k] == y - lazy[j]) {                 ini = k;                 break;               }             break;           }         }         if (flag == false) {           printf( -1 n );           continue;         }         for (long long j = root - 1; j >= 0; j--) {           if (s[j].find(y - lazy[j]) != s[j].end()) {             flag = true;             for (long long k = min((j + 1) * root - 1, n - 1); k >= j * root;                  k--) {               if (v[k] == y - lazy[j]) {                 fim = k;                 break;               }             }             break;           }         }         printf( %lld n , fim - ini);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i = 0;     char a;     char A[] =  hello ;     while (cin >> a && a !=   n ) {       if (a == A[i]) i++;     }     if (i == 5)       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};   int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};   const int mod = 1e9 + 7;   int dcmp(long double x, long double y) {     return fabs(x - y) <= 1e-12 ? 0 : x < y ? -1 : 1;   }   void fast() {     std::ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);   }   int n;   map<string, int> score;   map<int, vector<pair<string, int> > > ft;   int main() {     fast();     cin >> n;     string s;     int x, mx = 0;     for (int i = 0; i < n; i++) {       cin >> s >> x;       score[s] += x;       ft[score[s]].push_back({s, i});     }     for (auto e : score) {       mx = max(mx, e.second);     }     int mn = 2e9;     string wn =   ;     for (auto &e : ft) {       if (e.first < mx) continue;       for (int i = 0; i < e.second.size(); i++) {         if (score[e.second[i].first] == mx) {           if (mn > e.second[i].second) {             mn = e.second[i].second;             wn = e.second[i].first;           }         }       }     }     cout << wn <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct fenwick {     int N;     vector<int> sum;     void init(int n) {       N = n + 1;       sum.assign(N, 0);     }     void add(int i, int x) {       for (i++; i < N; i += i & -i) {         sum[i] += x;       }     }     int get(int i) {       int tot = 0;       for (i++; i > 0; i -= i & -i) {         tot += sum[i];       }       return tot;     }     int get(int i, int j) { return get(j) - (i > 0 ? get(i - 1) : 0); }   };   fenwick xs;   int lo, hi;   bool flip;   void init(int n, int x) {     xs.init(n);     for (int i = 0; i < n; i++) {       xs.add(i, x);     }     lo = 0;     hi = n - 1;   }   int len() { return hi - lo + 1; }   int get(int i) {     i = !flip ? lo + i : hi - i;     return xs.get(i, i);   }   int get(int i, int j) {     if (!flip) {       i += lo;       j += lo;     } else {       i = hi - i;       j = hi - j;       swap(i, j);     }     return xs.get(i, j);   }   void add(int i, int x) {     i = !flip ? lo + i : hi - i;     xs.add(i, x);   }   void drop(int k) {     if (!flip) {       lo += k;     } else {       hi -= k;     }   }   void dump() {     int n = len();     for (int i = 0; i < n; i++) {       cerr << get(i) <<    ;     }     cerr << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n, q;     cin >> n >> q;     init(n, 1);     while (q--) {       int t, i, j;       cin >> t >> i;       if (t == 1) {         if (i > len() / 2) {           i = len() - i;           flip = !flip;         }         for (int k = 0; i - 1 - k >= 0; k++) {           add(i + k, get(i - 1 - k));         }         drop(i);       } else {         cin >> j;         cout << get(i, j - 1) <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 510000;   int f[maxn];   int n, d, up;   int c[66];   int b[66];   int main() {     cin >> n >> d;     f[0] = 1;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       for (int j = (up += x); j >= x; j--)         if (f[j - x]) f[j] = 1;     }     int num = 0, ans = 0;     while (true) {       int to = ans + d;       while (!f[to] && to > ans) to--;       if (ans == to) break;       ans = to;       num++;     }     cout << ans <<     << num << endl;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   const int MaxN = 100005, NA = -1, MaxC = 0x3F3F3F3F;   int a[MaxN];   int n;   multiset<int, greater<int> > s;   deque<int> d;   int main(void) {     int i, v;     multiset<int>::iterator it;     while (scanf(  %d , &n) != EOF) {       for (i = 0; i < n; i++) scanf(  %d , &a[i]);       s.clear();       for (i = 0; i < n; i++) s.insert(a[i]);       d.clear();       it = s.begin();       d.push_back(*it);       s.erase(it);       for (i = 1; i < n; i++)         if (d.front() > d.back()) {           v = d.front();           it = s.find(v + 1);           if (it != s.end()) {             d.push_front(*it);             s.erase(it);           } else {             it = s.find(v - 1);             if (it != s.end()) {               d.push_front(*it);               s.erase(it);             } else               break;           }         } else {           v = d.back();           it = s.find(v + 1);           if (it != s.end()) {             d.push_back(*it);             s.erase(it);           } else {             it = s.find(v - 1);             if (it != s.end()) {               d.push_back(*it);               s.erase(it);             } else               break;           }         }       if ((int)d.size() == n && abs(d.front() - d.back()) == 1)         printf( YES n );       else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   std::pair<T, U> operator+(const std::pair<T, U>& l, const std::pair<T, U>& r) {     return {l.first + r.first, l.second + r.second};   }   typedef void (*callback_function)(void);   const long long ZERO = 0LL;   const long long INF64 = 1e18;   const int INF32 = 1e9;   const int MOD = 1e9 + 7;   const long double PI = acos(-1.0L);   const long double EPS = static_cast<long double>(1e-9);   long long inv(long long a, long long b) {     if (a != 1) {       return b - (inv(b % a, a) * b) / a;     }     return 1;   }   inline int Pow(int a, int k) {     int s = 1;     for (; k; k >>= 1) {       k& 1 ? s = 1LL * s * a % MOD : 0;       a = 1LL * a * a % MOD;     }     return s;   }   const int N = 1e6 + 7;   void input() {}   char a[N][20];   void solve() {     int n;     scanf( %d , &n);     for (int i = (0); i < (n); i++) {       scanf( %s , a[i]);     }     set<string> st;     for (int i = (n - 1); i >= (0); i--) {       if (!st.count(a[i])) {         printf( %s n , a[i]);         st.insert(a[i]);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     {       input();       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class A, class B>   inline bool mina(A &first, B second) {     return (first > second) ? (first = second, 1) : 0;   }   template <class A, class B>   inline bool maxa(A &first, B second) {     return (first < second) ? (first = second, 1) : 0;   }   const int MAXN = 3e5 + 5;   int in[MAXN];   int N, M;   int pos[MAXN];   pair<int, int> foes[MAXN];   int main() {     scanf( %d %d , &N, &M);     for (int i = 1; i <= N; i++) {       scanf( %d , &in[i]);       pos[in[i]] = i;     }     int a, b;     for (int(i) = 0; (i) < (M); ++(i)) {       scanf( %d %d , &a, &b);       a = pos[a];       b = pos[b];       if (a < b) swap(a, b);       foes[i] = pair<int, int>(a, b);     }     sort(foes, foes + M);     long long ans = 0;     int maxx = 0;     int cur = 0;     for (int i = 1; i <= N; i++) {       while (cur < M && foes[cur].first <= i) {         maxa(maxx, foes[cur].second);         cur++;       }       ans += i - maxx;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   char s[1000000];   char ans[1000000];   int main() {     int i, len, cnt;     char max = 0;     while (scanf( %s , s) != EOF) {       max = 0;       cnt = 1000000 - 1;       len = strlen(s);       for (i = len - 1; i >= 0; i--) {         if (s[i] >= max) {           max = s[i];           ans[cnt--] = s[i];         }       }       for (i = cnt + 1; i < 1000000; i++) printf( %c , ans[i]);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 228;   vector<int> g[MAXN];   vector<bool> vis(MAXN);   int n, m;   int p[MAXN];   int col[MAXN], help[MAXN];   int t[4 * MAXN], lazy[4 * MAXN];   int tin[MAXN], tout[MAXN];   int timer;   void dfs(int v) {     vis[v] = 1;     tin[v] = timer++;     for (int i = 0; i < g[v].size(); i++) {       int to = g[v][i];       if (vis[to] == 0) {         dfs(to);       }     }     tout[v] = timer - 1;   }   void build(int v, int tl, int tr) {     if (tl == tr) {       t[v] = help[tl];       lazy[v] = -1;     } else {       int tm = (tl + tr) >> 1;       build(2 * v, tl, tm);       build(2 * v + 1, tm + 1, tr);       t[v] = t[2 * v] + t[2 * v + 1];       lazy[v] = -1;     }   }   void push(int v, int tl, int tr) {     if (lazy[v] != -1) {       if (lazy[v] % 2 == 1) {         t[v] = (tr - tl + 1) - t[v];       }       if (tl != tr) {         if (lazy[2 * v] == -1) {           lazy[2 * v] = lazy[v];         } else {           lazy[2 * v] += lazy[v];         }         if (lazy[2 * v + 1] == -1) {           lazy[2 * v + 1] = lazy[v];         } else {           lazy[2 * v + 1] += lazy[v];         }       }       lazy[v] = -1;     }   }   void update(int v, int tl, int tr, int l, int r, long long color) {     push(v, tl, tr);     if (l > r) {       return;     }     if (tl == l && tr == r) {       if (lazy[v] == -1) {         lazy[v] = color;       } else {         lazy[v] += color;       }       push(v, tl, tr);       return;     }     int tm = (tl + tr) >> 1;     update(2 * v, tl, tm, l, min(tm, r), color);     update(2 * v + 1, tm + 1, tr, max(tm + 1, l), r, color);     t[v] = t[2 * v] + t[2 * v + 1];   }   long long get(int v, int tl, int tr, int l, int r) {     push(v, tl, tr);     if (l > r) {       return 0;     }     if (tl == l && tr == r) {       return t[v];     }     int tm = (tl + tr) >> 1;     return get(2 * v, tl, tm, l, min(tm, r)) +            get(2 * v + 1, tm + 1, tr, max(tm + 1, l), r);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 1; i < n; i++) {       cin >> p[i];       p[i]--;       g[i].push_back(p[i]);       g[p[i]].push_back(i);     }     for (int i = 0; i < n; i++) {       cin >> col[i];     }     dfs(0);     for (int i = 0; i < n; i++) {       int start = tin[i];       help[start] = col[i];     }     build(1, 0, n - 1);     cin >> m;     for (int i = 0; i < m; i++) {       string a;       int x;       cin >> a >> x;       x--;       if (a ==  get ) {         cout << get(1, 0, n - 1, tin[x], tout[x]) << endl;       } else {         update(1, 0, n - 1, tin[x], tout[x], 1);       }     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int num;     int count = 0, i;     int digitos[10];     scanf( %d , &num);     int aux = num;     for (i = 0; i < 10; i++) digitos[i] = 0;     while (aux != 0) {       digitos[aux % 10] = 1;       aux = aux / 10;     }     if (num == 1) {       printf( 1 n );       return 0;     }     for (i = 1; i * i <= num; i++) {       if (num % i == 0) {         aux = i;         while (aux != 0) {           if (digitos[aux % 10] == 1) {             count++;             break;           }           aux = aux / 10;         }         aux = num / i;         if (aux != i)           while (aux != 0) {             if (digitos[aux % 10] == 1) {               count++;               break;             }             aux = aux / 10;           }       }     }     printf( %d n , count);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, cnt = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       cnt += x;     }     if (cnt * 2 <= n) {       printf( %d n , n / 2);       for (int i = 1; i <= n / 2; i++) printf( 0  );       printf(  n );     } else {       int x = n / 2;       if (x & 1) x++;       printf( %d n , x);       for (int i = 1; i <= x; i++) printf( 1  );       printf(  n );     }     return;   }   int main() {     int t;     scanf( %d , &t);     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct candy {     candy(int t, int h, int m) {       this->type = t;       this->height = h;       this->mass = m;     }     int type;     int height;     int mass;     bool operator<(const candy &c) const { return this->mass < c.mass; }     bool operator>(const candy &c) const { return this->height < c.height; }   };   int amount(int first, vector<candy> &all_candies, int x) {     priority_queue<candy> candies0, candies1;     int all_candies_index = 0;     int max_height = x;     int last_taken = 1 - first;     int amount_taken = 0;     while (true) {       while (all_candies_index < all_candies.size()) {         if (all_candies[all_candies_index].height > max_height) {           break;         }         if (all_candies[all_candies_index].type == 0) {           candies0.push(all_candies[all_candies_index]);         } else {           candies1.push(all_candies[all_candies_index]);         }         all_candies_index++;       }       if (last_taken) {         if (candies0.empty()) {           break;         }         amount_taken++;         max_height += candies0.top().mass;         candies0.pop();         last_taken = 0;       } else {         if (candies1.empty()) {           break;         }         amount_taken++;         max_height += candies1.top().mass;         candies1.pop();         last_taken = 1;       }     }     return amount_taken;   }   int main() {     int n, x;     scanf( %d%d , &n, &x);     vector<candy> all_candies;     for (int i = 0; i < n; ++i) {       int t, h, m;       scanf( %d%d%d , &t, &h, &m);       all_candies.push_back(candy(t, h, m));     }     sort(all_candies.begin(), all_candies.end(), std::greater<candy>());     printf( %d n , max(amount(0, all_candies, x), amount(1, all_candies, x)));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i;     vector<char> v;     string s;     cin >> s;     n = s.size();     char c[n], ch;     i = n;     ch = s[n - 1];     while (i--) {       if (s[i] == ch)         v.push_back(s[i]);       else if (s[i] > ch) {         v.push_back(s[i]);         ch = s[i];       }     }     for (i = v.size(); i > 0; i--) cout << v[i - 1];   }