#include <bits/stdc++.h>   using namespace std;   pair<long long int, long long int> operator+(       pair<long long int, long long int> p0,       pair<long long int, long long int> p1) {     return pair<long long int, long long int>(p0.first + p1.first,                                               p0.second + p1.second);   }   pair<long long int, long long int> operator-(       pair<long long int, long long int> p0,       pair<long long int, long long int> p1) {     return pair<long long int, long long int>(p0.first - p1.first,                                               p0.second - p1.second);   }   vector<long long int> E[100005];   vector<pair<long long int, long long int> > ans;   long long int type[100005];   long long int used[100005];   pair<long long int, long long int> dp[2][100005];   long long int bef[100005];   long long int parent[100005];   pair<long long int, long long int> recur(long long int pos) {     used[pos] = true;     dp[0][pos] = make_pair(0, 0);     for (long long int i = 0;          i < ((long long int)(((long long int)(E[pos]).size()))); ++i)       dp[0][pos] = dp[0][pos] + recur(E[pos][i]);     dp[1][pos] = dp[0][pos];     bef[pos] = -1;     for (long long int i = 0;          i < ((long long int)(((long long int)(E[pos]).size()))); ++i) {       pair<long long int, long long int> tmp =           dp[0][pos] - dp[1][E[pos][i]] + dp[0][E[pos][i]] + make_pair(1, 0);       if (type[pos] != type[E[pos][i]]) tmp.second++;       if (dp[1][pos] < tmp) {         bef[pos] = E[pos][i];         dp[1][pos] = tmp;       }     }     return dp[1][pos];   }   void dump(long long int pos, bool ok,             vector<pair<long long int, long long int> > &root) {     for (long long int i = 0;          i < ((long long int)(((long long int)(E[pos]).size()))); ++i) {       if (ok && bef[pos] == E[pos][i]) root.push_back(make_pair(pos, E[pos][i]));       dump(E[pos][i], !(ok && bef[pos] == E[pos][i]), root);     }   }   pair<long long int, long long int> cal(long long int pos) {     for (; !used[pos]; pos = parent[pos]) used[pos] = true;     vector<pair<long long int, long long int> > root;     pair<long long int, long long int> res = make_pair(0, 0);     for (long long int i = 0; i < ((long long int)(2)); ++i) {       long long int par = parent[pos];       E[par].erase(find(E[par].begin(), E[par].end(), pos));       pair<long long int, long long int> tmp = recur(pos);       if (res < tmp) {         res = tmp;         root.clear();         dump(pos, true, root);       }       E[par].push_back(pos);       pos = par;     }     for (long long int i = 0;          i < ((long long int)(((long long int)(root).size()))); ++i)       ans.push_back(root[i]);     return res;   }   int main() {     pair<long long int, long long int> res =         pair<long long int, long long int>(0, 0);     long long int n, a;     cin >> n;     for (long long int i = 0; i < ((long long int)(n)); ++i) parent[i] = i;     for (long long int i = 0; i < ((long long int)(n)); ++i) {       cin >> parent[i] >> type[i];       parent[i]--;       E[parent[i]].push_back(i);     }     for (long long int i = 0; i < ((long long int)(n)); ++i)       if (!used[i]) res = res + cal(i);     cout << res.first <<     << res.second << endl;     for (long long int i = 0;          i < ((long long int)(((long long int)(ans).size()))); ++i)       cout << ans[i].first + 1 <<     << ans[i].second + 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   void fastIO() {     std::ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   template <typename T, typename U>   inline void mnze(T &x, U y) {     if (y < x) x = y;   }   template <typename T, typename U>   inline void mxze(T &x, U y) {     if (x < y) x = y;   }   void _scan(int &x) { scanf( %d , &x); }   void _scan(long long &x) { scanf( %lld , &x); }   void _scan(double &x) { scanf( %lf , &x); }   void _scan(char &x) { scanf(  %c , &x); }   void _scan(char *x) { scanf( %s , x); }   template <typename T>   void _scan(vector<T> &v) {     for (int i = 0; i < (int)v.size(); i++) _scan(v[i]);   }   void scan() {}   template <typename T, typename... U>   void scan(T &head, U &...tail) {     _scan(head);     scan(tail...);   }   template <typename T>   void _dbg(const char *sdbg, T h) {     cerr << sdbg <<  =  << h <<   n ;   }   template <typename T, typename... U>   void _dbg(const char *sdbg, T h, U... t) {     while (*sdbg !=  , ) cerr << *sdbg++;     cerr <<  =  << h <<  , ;     _dbg(sdbg + 1, t...);   }   long long MOD = 1e9 + 7;   inline long long Msum(long long x) { return x; }   template <typename... Rest>   inline long long Msum(long long x, Rest... rest) {     return (x + Msum(rest...)) % MOD;   }   inline long long Mprod(long long x) { return x; }   template <typename... Rest>   inline long long Mprod(long long x, Rest... rest) {     return x * Mprod(rest...) % MOD;   }   inline long long Mnorm(long long x) { return (x % MOD + MOD) % MOD; }   inline long long Msq(long long x) { return (x * x) % MOD; }   inline long long Mpot(long long x, long long e) {     if (!e) return 1;     return Msq(Mpot(x, e >> 1)) * (e & 1 ? x : 1) % MOD;   }   const int MAXN = 2e3 + 3;   char g[MAXN][MAXN];   int x[MAXN][MAXN];   int R, C;   int main() {     scan(R, C);     for (int r = 0; r < R; r++) scan(g[r]);     for (int r = R - 1; r > -1; r--) {       for (int c = 0; c < C; c++) {         x[r][c] = 1;         char cc = g[r][c];         if (r + 2 >= R) continue;         if (g[r + 1][c] != cc) continue;         if (g[r + 2][c] != cc) continue;         if (c - 1 < 0) continue;         if (g[r + 1][c - 1] != cc) continue;         if (c + 1 >= C) continue;         if (g[r + 1][c + 1] != cc) continue;         x[r][c] = min(x[r + 2][c], min(x[r + 1][c - 1], x[r + 1][c + 1])) + 1;       }     }     long long ans = 0;     for (int r = R - 1; r > -1; r--)       for (int c = 0; c < C; c++) {         ans += x[r][c];       }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int inf = (1e9) + 7;   int mod = 998244353;   int c(int num, int div) { return (num + div - 1) / div; }   int main() {     int n, k;     scanf( %d %d , &n, &k);     int nr = 2 * n;     int ng = 5 * n;     int nb = 8 * n;     printf( %d n , c(nr, k) + c(ng, k) + c(nb, k));   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 50;   const double eps = 1e-10;   const int max_index = 62;   const int inf = 0x3f3f3f3f;   const int MOD = 1e9 + 7;   inline int read() {     char c = getchar();     while (!isdigit(c)) c = getchar();     int x = 0;     while (isdigit(c)) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x;   }   int N, n, m, K;   long long dp[55][55][1110];   long long C[55][55];   int main() {     scanf( %d%d , &N, &K);     n = m = 0;     for (int i = 0; i < N; i++) {       int x = read();       if (x == 50)         n++;       else         m++;     }     for (int i = 0; i <= 50; i++) C[i][0] = 1, C[i][i] = 1;     for (int i = 0; i <= 50; i++) {       for (int j = 1; j < i; j++) {         C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;       }     }     dp[n][m][0] = 1;     for (int k = 1; k < 200 && dp[0][0][k - 1] == 0; k++) {       bool flag = 0;       for (int i = 0; i <= n; i++) {         for (int j = 0; j <= m; j++) {           if (k & 1) {             for (int a = 0; a * 50 <= K && a + i <= n; a++) {               for (int b = 0; b * 100 + a * 50 <= K && b + j <= m; b++) {                 if (a == 0 && b == 0) continue;                 long long tmp = dp[i + a][j + b][k - 1] * C[i + a][a] % MOD *                                 C[j + b][b] % MOD;                 dp[i][j][k] = (dp[i][j][k] + tmp) % MOD;               }             }           } else {             for (int a = 0; a * 50 <= K && a <= i; a++) {               for (int b = 0; b * 100 + a * 50 <= K && b <= j; b++) {                 if (a == 0 && b == 0) continue;                 long long tmp = dp[i - a][j - b][k - 1] * C[n - i + a][a] % MOD *                                 C[m - j + b][b] % MOD;                 dp[i][j][k] = (dp[i][j][k] + tmp) % MOD;               }             }           }         }       }     }     int k = 0;     while (dp[0][0][k] == 0 && k < 200) k++;     if (k >= 200)       puts( -1 n0 );     else       cout << k <<   n  << dp[0][0][k] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename _T>   inline void read(_T &f) {     f = 0;     _T fu = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) {         fu = -1;       }       c = getchar();     }     while (c >=  0  && c <=  9 ) {       f = (f << 3) + (f << 1) + (c & 15);       c = getchar();     }     f *= fu;   }   template <typename T>   void print(T x) {     if (x < 0) putchar( - ), x = -x;     if (x < 10)       putchar(x + 48);     else       print(x / 10), putchar(x % 10 + 48);   }   template <typename T>   void print(T x, char t) {     print(x);     putchar(t);   }   const int N = 1e5 + 5, B = 310;   vector<int> pos[N * 2], big;   unordered_map<int, int> id;   int a[N], lc[N * 40], rc[N * 40], sum[N * 40], rt[N * 2], root[B + 5],       tag[N * 2], rub[N * 40];   int n, m, tot, cnt_id, top;   inline int newNode() {     if (top) {       int u = rub[top];       --top;       lc[u] = rc[u] = 0;       return u;     }     return ++tot;   }   void add(int &u, int l, int r, int x, int y) {     if (!u) u = newNode();     sum[u] += y;     if (l == r) {       if (!sum[u]) rub[++top] = u, u = 0;       return;     }     int mid = (l + r) >> 1;     if (mid >= x)       add(lc[u], l, mid, x, y);     else       add(rc[u], mid + 1, r, x, y);     if (!sum[u]) rub[++top] = u, u = 0;   }   int query(int u, int l, int r, int x) {     if (!u) return 0;     if (r <= x) return sum[u];     int mid = (l + r) >> 1, ans = query(lc[u], l, mid, x);     if (mid + 1 <= x) ans += query(rc[u], mid + 1, r, x);     return ans;   }   void add(int x, int y) {     if (!id.count(x)) id[x] = ++cnt_id;     x = id[x];     add(rt[x], 1, n, y, 1);     if (!tag[x] && (int)pos[x].size() + 1 > B) {       for (int i = 0; i <= B; i++) add(root[i], 1, n, pos[x][i], -1);       tag[x] = 1;       big.push_back(x);     }     if (tag[x]) return;     pos[x].push_back(y);     int tmp = (int)pos[x].size() - 1;     while (tmp && pos[x][tmp - 1] > pos[x][tmp]) {       add(root[tmp - 1], 1, n, pos[x][tmp - 1], -1);       add(root[tmp], 1, n, pos[x][tmp - 1], 1);       swap(pos[x][tmp - 1], pos[x][tmp]);       --tmp;     }     add(root[tmp], 1, n, y, 1);   }   void del(int x, int y) {     x = id[x];     add(rt[x], 1, n, y, -1);     if (tag[x]) return;     int tmp = lower_bound(pos[x].begin(), pos[x].end(), y) - pos[x].begin();     add(root[tmp], 1, n, y, -1);     while (tmp < (int)pos[x].size() - 1) {       add(root[tmp + 1], 1, n, pos[x][tmp + 1], -1);       add(root[tmp], 1, n, pos[x][tmp + 1], 1);       swap(pos[x][tmp], pos[x][tmp + 1]);       ++tmp;     }     pos[x].pop_back();   }   int main() {     read(n);     for (int i = 1; i <= n; i++) read(a[i]), add(a[i], i);     read(m);     while (m--) {       int opt;       read(opt);       if (opt == 1) {         int x, y;         read(y);         read(x);         del(a[x], x);         a[x] = y;         add(a[x], x);       }       if (opt == 2) {         int x, y;         read(x);         read(y);         if (x == 1)           print(a[y],   n );         else if (x & 1) {           int rk = query(rt[id[a[y]]], 1, n, y), ans = 0;           if (rk <= B + 1) ans += query(root[rk - 1], 1, n, y);           for (int i = 0; i < (int)big.size(); i++) {             int id = big[i];             ans += (query(rt[id], 1, n, y) >= rk);           }           print(ans,   n );         } else {           print(query(rt[id[a[y]]], 1, n, y),   n );         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1100000000000000000;   void solve() {     long long n, k;     cin >> n >> k;     long long a[n];     for (long long i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     long long dp[k + 5][k + 5];     memset(dp, 0, sizeof(dp));     long long x = n % k, c = (n + k - 1) / k, s = n / k;     ;     long long y = k - x;     for (long long i = 0; i <= x; i++)       for (long long j = 0; j <= y; j++) dp[i][j] = inf;     dp[0][0] = 0;     for (long long i = 0; i <= x; i++) {       if (i)         for (long long j = 0; j <= y; j++) {           long long idx = (i - 1) * c + s * j;           dp[i][j] = min(dp[i][j], abs(a[idx + c - 1] - a[idx]) + dp[i - 1][j]);         }       for (long long j = 1; j <= y; j++) {         long long idx = i * c + s * (j - 1);         dp[i][j] = min(dp[i][j], abs(a[idx + s - 1] - a[idx]) + dp[i][j - 1]);       }     }     cout << dp[x][y];   }   signed main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr);     long long T = 1;     while (T--) {       solve();       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100005], ans[100005];   int main() {     int n, a1, a2, num = 0, gg = 0, t = 0;     cin >> n;     bool ty = true, zz = true;     for (int i = 1; i <= n - 1; ++i) {       cin >> a1 >> a2;       a[a1]++;       a[a2]++;     }     for (int i = 1; i <= n; ++i) {       if (a[i] > 2) {         num++;         gg = i;       }       if (num > 1) {         ty = false;         break;       } else if (a[i] == 1) {         ans[i] = i;         t++;       }     }     if (!ty) {       cout <<  No  << endl;     } else {       cout <<  Yes  << endl;       if (num == 1) {         cout << t << endl;         for (int i = 1; i <= n; ++i) {           if (ans[i] != 0) {             cout << gg <<     << ans[i] << endl;           }         }       } else {         cout << 1 << endl;         for (int i = 1; i <= n; ++i) {           if (ans[i] != 0 && zz) {             cout << ans[i] <<    ;             zz = false;           } else if (ans[i] != 0 && !zz) {             cout << ans[i] << endl;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<pair<long long, int> > v;   vector<int> lef, rig;   long long pitaj(int t, int a, int b, int c) {     long long res;     cout << 3 - t <<     << a <<     << b <<     << c << endl;     cin >> res;     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     int ind = 2;     for (int i = 3; i <= n; i++) {       if (pitaj(1, 1, i, ind) == 1) ind = i;     }     for (int i = 2; i <= n; i++) {       if (i == ind) continue;       v.push_back({pitaj(2, 1, ind, i), i});     }     sort(v.begin(), v.end());     for (int i = 1; i < v.size(); i++) {       if (pitaj(1, 1, v[i - 1].second, v[i].second) == 1) {         lef.push_back(v[i - 1].second);       } else {         rig.push_back(v[i - 1].second);       }     }     lef.push_back(v.back().second);     cout << 0 <<     << 1 <<     << ind <<    ;     for (int i = 0; i < lef.size(); i++) cout << lef[i] <<    ;     for (int i = (int)rig.size() - 1; i >= 0; i--) cout << rig[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   const double eps = 1e-06;   int main() {     double t, s, q;     scanf( %lf%lf%lf , &t, &s, &q);     double v = (q - 1.0) / q;     int cnt = 1;     while (true) {       s = s / (1 - v);       if (s > t - eps) break;       cnt++;     }     printf( %d n , cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x, a, b, mx = 2500, Mx = -2500, my = 2500, My = -2500, ans;   int main() {     cin >> x;     for (int i = 1; i <= x; i++) {       cin >> a >> b;       mx = min(mx, a);       Mx = max(Mx, a);       my = min(my, b);       My = max(My, b);     }     if (x == 1 || mx == Mx || my == My) {       cout << -1 << endl;     } else {       ans = (Mx - mx) * (My - my);       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f;   int main() {     int n, a, x, b, y;     cin >> n >> a >> x >> b >> y;     while (a != x && b != y) {       a++;       if (a > n) a = 1;       b--;       if (b < 1) b = n;       if (a == b) {         printf( YES );         return 0;       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ans;   int a, b, c, d, e, f, g;   int main() {     scanf( %d%d%d%d%d%d , &a, &b, &c, &d, &e, &f);     if (e > f) ans += min(a, d);     a -= ans, d -= ans;     ans *= e;     g = min(min(b, c), d);     ans += f * g;     b -= g, c -= g, d -= g;     ans += e * min(a, d);     printf( %lld , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n & 1) {       cout <<  Ehab ;     } else {       cout <<  Mahmoud ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   const int M = 1e7 + 1;   ;   const long long INF = 2e9 + 10;   const long long MOD = 1000 * 1000 * 1000 + 7;   const long double EPS = 1e-9;   int a[N];   bool prime(int x) {     for (int i = 2; i < (int)sqrt(x) + 1; ++i)       if (x % i == 0) return false;     return true;   }   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     if (prime(n))       cout << 1;     else if (prime(n - 2))       cout << 2;     else if (n % 2 == 0)       cout << 2;     else       cout << 3;   }


#include <bits/stdc++.h>   using namespace std;   long long n;   long long m;   long long t;   void solve() {}   struct point {     long long x, y;   };   bool isSquare(point a, point b, point c, point d) {     long long dist1 =         (long long)(b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y);     long long dist2 =         (long long)(b.x - c.x) * (b.x - c.x) + (b.y - c.y) * (b.y - c.y);     long long dist3 =         (long long)(c.x - d.x) * (c.x - d.x) + (c.y - d.y) * (c.y - d.y);     long long dist4 =         (long long)(a.x - d.x) * (a.x - d.x) + (a.y - d.y) * (a.y - d.y);     return dist1 == dist2 && dist1 == dist3 && dist1 == dist4;   }   bool noZeroArea(point a, point b, point c, point d) {     long long dist1 =         (long long)(b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y);     long long dist2 =         (long long)(b.x - c.x) * (b.x - c.x) + (b.y - c.y) * (b.y - c.y);     long long dist3 =         (long long)(c.x - d.x) * (c.x - d.x) + (c.y - d.y) * (c.y - d.y);     long long dist4 =         (long long)(a.x - d.x) * (a.x - d.x) + (a.y - d.y) * (a.y - d.y);     if (dist1 > 0 && dist2 > 0 && dist3 > 0 && dist4 > 0) return true;     return false;   }   long long IsOrthogonal(point a, point b, point c) {     return (b.x - a.x) * (b.x - c.x) + (b.y - a.y) * (b.y - c.y) == 0;   }   long long IsRectangle(point a, point b, point c, point d) {     return IsOrthogonal(a, b, c) && IsOrthogonal(b, c, d) &&            IsOrthogonal(c, d, a) && noZeroArea(a, b, c, d);   }   long long IsRectangleAnyOrder(point a, point b, point c, point d) {     return IsRectangle(a, b, c, d) || IsRectangle(b, c, a, d) ||            IsRectangle(c, a, b, d);   }   long long IsSquareAnyOrder(point a, point b, point c, point d) {     return (IsRectangle(a, b, c, d) && isSquare(a, b, c, d)) ||            (IsRectangle(b, c, a, d) && isSquare(b, c, a, d)) ||            (IsRectangle(c, a, b, d) && isSquare(c, a, b, d));   }   int main() {     ios_base::sync_with_stdio(false);     point pt[10];     for (int i = 1; i <= 8; i++) {       long long x, y;       cin >> x >> y;       pt[i].x = x;       pt[i].y = y;     }     int mtints[] = {1, 2, 3, 4, 5, 6, 7, 8};     sort(mtints, mtints + 8);     do {       if (IsSquareAnyOrder(pt[mtints[0]], pt[mtints[1]], pt[mtints[2]],                            pt[mtints[3]]) &&           IsRectangleAnyOrder(pt[mtints[4]], pt[mtints[5]], pt[mtints[6]],                               pt[mtints[7]])) {         cout <<  YES  << endl;         cout << mtints[0] <<     << mtints[1] <<     << mtints[2] <<                  << mtints[3] << endl;         cout << mtints[4] <<     << mtints[5] <<     << mtints[6] <<                  << mtints[7] << endl;         return 0;       }     } while (next_permutation(mtints, mtints + 8));     cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Edge {     int to, w, type;     Edge() {}     Edge(int _to, int _w, int _type) : to(_to), w(_w), type(_type) {}     bool operator<(const Edge other) { return type < other.type; }   };   const long long N = 1e5 + 5, oo = 1e18;   long long n, m, k, dist[N], res;   int deg[N];   vector<Edge> adj[N];   bool mark[N];   int main(int argc, char const *argv[]) {     ios_base::sync_with_stdio(0);     cin.tie(0);     clock_t tStart = clock();     cin >> n >> m >> k;     for (long long huy = 0, _n = (m); huy < _n; huy++) {       long long u, v, w;       cin >> u >> v >> w;       adj[u].push_back(Edge(v, w, 0));       adj[v].push_back(Edge(u, w, 0));     }     for (long long nene = 0, _n = (k); nene < _n; nene++) {       long long v, t;       cin >> v >> t;       adj[1].push_back(Edge(v, t, 1));       adj[v].push_back(Edge(1, t, 1));     }     set<pair<long long, long long> > pq;     pq.clear();     pq.insert(pair<long long, long long>(0, 1));     for (long long i = (2), _b = (n); i <= _b; i++) dist[i] = oo;     while (!pq.empty()) {       pair<long long, long long> front = *(pq.begin());       long long d = front.first, u = front.second;       pq.erase(pq.begin());       if (d > dist[u]) continue;       for (Edge e : adj[u])         if (dist[u] + e.w < dist[e.to]) {           dist[e.to] = dist[u] + e.w;           pq.insert(pair<long long, long long>(dist[e.to], e.to));         }     }     for (long long u = (1), _b = (n); u <= _b; u++)       for (Edge e : adj[u]) {         if (dist[u] + e.w == dist[e.to]) {           deg[e.to]++;         }       }     res = k;     for (long long u = (1), _b = (n); u <= _b; u++)       for (Edge e : adj[u]) {         if (e.type == 1 && dist[u] + e.w == dist[e.to]) {           if (deg[e.to] == 1) res--;           deg[e.to]--;         }       }     cout << res <<   n ;     fprintf(stderr,  Time taken: %.2fs n ,             (double)(clock() - tStart) / CLOCKS_PER_SEC);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, d;   bool b;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       cin >> n >> d;       b = false;       if (d <= n) {         cout <<  YES n ;         continue;       }       for (long long x = 1; x * x <= d; x++) {         long long X = x + 1;         long long D = 0;         D = d / X;         if (d % X != 0) {           D++;         }         long long sol = x + (D);         if (sol <= n) {           cout <<  YES n ;           b = true;           break;         }       }       if (b == false) {         cout <<  NO n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int64_t n;   int64_t numbers[200000];   int64_t exists[200000 + 1];   struct Node {     int64_t l, r, sum;     Node *left, *right;     int64_t first, last;   };   deque<Node> nodes;   Node *root;   Node *newNode() {     nodes.emplace_back();     return &nodes.back();   }   Node *fillNode(int64_t first, int64_t last) {     if (first >= last) {       return nullptr;     }     int64_t mid = (first + (last - first) / 2);     Node *result = newNode();     result->first = first;     result->last = last;     result->l = first;     result->r = last - 1;     if (first + 1 != last) {       result->left = fillNode(first, mid);       result->right = fillNode(mid, last);     } else {       result->left = nullptr;       result->right = nullptr;     }     result->sum = 0;     if (!result->left && !result->right) {       result->sum = result->l;     } else {       if (result->left) {         result->sum += result->left->sum;       }       if (result->right) {         result->sum += result->right->sum;       }     }     return result;   }   void fixup(Node *node, Node *parent) {     if (node->r <= parent->l) {       node->sum = (node->last - node->first) * parent->l;       node->l = node->r = parent->l;     }   }   int64_t update(Node *node, int64_t first, int64_t last, int64_t size,                  Node *parent) {     if (first >= node->last || last <= node->first) return 0;     if (parent) fixup(node, parent);     if (node->l >= size) return 0;     if (first <= node->first && node->last <= last && node->r <= size) {       int64_t new_sum = (node->last - node->first) * size;       int64_t result = new_sum - node->sum;       node->sum = new_sum;       node->l = size;       node->r = size;       return result;     }     int64_t sum_from_child = 0;     if (node->left) {       sum_from_child += update(node->left, first, last, size, node);     }     if (node->right) {       int64_t res = update(node->right, first, last, size, node);       sum_from_child += res;     }     if (node->left) {       if (node->left->l > node->l) {       }       node->l = max(node->l, node->left->l);     }     if (node->right) {       if (node->right->r > node->r) {       }       node->r = max(node->r, node->right->r);     }     node->sum += sum_from_child;     return sum_from_child;   }   int64_t set_from(int64_t first, int64_t last) {     if (first >= last) return 0;     int64_t barSize = last;     int64_t barIdx = first;     int64_t res = update(root, barIdx, n, barSize, nullptr);     return res;   }   int main() {     std::ios_base::sync_with_stdio(false);     cin >> n;     root = fillNode(0, n);     fill(begin(exists), end(exists), -1);     for (int64_t i = 0; i < n; ++i) {       cin >> numbers[i];       exists[numbers[i]] = i;     }     int64_t result = 0;     for (int64_t gcd = 200000; gcd >= 1; --gcd) {       std::vector<int64_t> idxs;       for (int64_t i = gcd; i <= 200000; i += gcd) {         if (exists[i] >= 0) idxs.push_back(exists[i]);       }       if (idxs.size() < 2) continue;       nth_element(begin(idxs), begin(idxs) + 2, end(idxs));       int64_t x1 = idxs[0];       int64_t x2 = idxs[1];       if (x1 > x2) swap(x1, x2);       nth_element(begin(idxs), begin(idxs) + idxs.size() - 2, end(idxs));       int64_t x3 = idxs[idxs.size() - 2];       int64_t x4 = idxs[idxs.size() - 1];       if (x3 > x4) swap(x3, x4);       result += gcd * set_from(0, x3);       result += gcd * set_from(x2 + 1, n);       result += gcd * set_from(x1 + 1, x4);     }     cout << result << endl;   }


#include <bits/stdc++.h>   using namespace std;   std::vector<long long> digit(long long num) {     string str, s;     std::vector<long long> v;     str = to_string(num);     for (int i = 0; i < str.size(); ++i) {       s = str[i];       v.push_back(stoi(s));     }     return v;   }   void solve() {     long long num, best;     cin >> num;     std::vector<long long> arr(num + 11);     std::vector<long long> d;     arr[0] = 0;     for (int i = 1; i < 10; ++i) {       arr[i] = 1;     }     for (int i = 10; i <= num; ++i) {       best = 2000000000000000000;       d = digit(i);       for (auto y : d) {         if (y != 0) {           best = min(best, arr[i - y] + 1);         }       }       arr[i] = best;     }     cout << arr[num] << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int tt = 1;     while (tt--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int T;     cin >> T;     while (T--) {       string s[9];       for (long long int i = 0; i < 9; i++) {         cin >> s[i];       }       for (long long int i = 0; i < 9; i++) {         for (long long int j = 0; j < 9; j++) {           if (s[i][j] ==  3 ) s[i][j] =  1 ;         }       }       for (long long int i = 0; i < 9; i++) {         cout << s[i] <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     long long l = 1, k = n, cnt = 0, h = n, ans = 0;     while (l <= h) {       long long mid = l + (h - l) / 2;       k = n;       cnt = 0;       while (k > 0) {         if (k >= mid) {           k = k - mid;           cnt += mid;           k = k - (k / 10);         } else {           cnt += k;           break;         }       }       if (cnt >= (n + 1) / 2) {         ans = mid;         h = mid - 1;       } else {         l = mid + 1;       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long l1, l2, r1, r2, k;   int main() {     cin >> l1 >> r1 >> l2 >> r2 >> k;     if (l2 > r1 || r2 < l1) {       cout << 0 <<   n ;       return 0;     }     long long l, r;     if (r1 < r2) {       r = r1;     } else {       r = r2;     }     if (l1 > l2) {       l = l1;     } else {       l = l2;     }     long long flag = 0;     if (k >= l && k <= r) {       flag = 1;     }     cout << r - l - flag + 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, w1[555][555], w2[555][555], w3[555][555], gl, Pre[300011], anslen;   char ch;   struct AnsNode {     int x, y, z;     void init(int _x, int _y, int _z) { x = _x, y = _y, z = _z; }   } Ans[1000111];   struct Node {     int x, y;     void init(int _x, int _y) { x = _x, y = _y; }   } gg[300011];   void Read(int &res) {     for (ch = getchar(); ch !=  .  && ch !=  # ; ch = getchar())       ;     res = (ch ==  . );   }   void Work(int nowx, int nowy) {     int i, dx, dy;     gg[gl = 1].init(nowx, nowy);     w2[nowx][nowy] = 1;     for (i = 1; i <= gl; ++i) {       dx = gg[i].x, dy = gg[i].y;       if (dx > 1 && w1[dx - 1][dy] && w2[dx - 1][dy] == 0) {         w2[dx - 1][dy] = 1;         gg[++gl].init(dx - 1, dy);         Pre[gl] = i;       }       if (dx < n && w1[dx + 1][dy] && w2[dx + 1][dy] == 0) {         w2[dx + 1][dy] = 1;         gg[++gl].init(dx + 1, dy);         Pre[gl] = i;       }       if (dy > 1 && w1[dx][dy - 1] && w2[dx][dy - 1] == 0) {         w2[dx][dy - 1] = 1;         gg[++gl].init(dx, dy - 1);         Pre[gl] = i;       }       if (dy < m && w1[dx][dy + 1] && w2[dx][dy + 1] == 0) {         w2[dx][dy + 1] = 1;         gg[++gl].init(dx, dy + 1);         Pre[gl] = i;       }     }     for (i = gl; i > 1; --i) {       dx = gg[Pre[i]].x, dy = gg[Pre[i]].y;       if (w3[dx][dy] == 0) {         Ans[++anslen].init(1, dx, dy);         w3[dx][dy] = 1;       }       if (w3[gg[i].x][gg[i].y] == 1) Ans[++anslen].init(0, gg[i].x, gg[i].y);       if (w3[gg[i].x][gg[i].y] < 2) Ans[++anslen].init(2, gg[i].x, gg[i].y);       w3[gg[i].x][gg[i].y] = 2;     }     if (w3[dx][dy] == 0) {       Ans[++anslen].init(1, nowx, nowy);       w3[nowx][nowy] = 1;     }   }   int main() {     int i, j;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; ++i)       for (j = 1; j <= m; ++j) Read(w1[i][j]);     memset(w2, 0, sizeof(w2));     memset(w3, 0, sizeof(w3));     anslen = 0;     for (i = 1; i <= n; ++i)       for (j = 1; j <= m; ++j)         if (w2[i][j] == 0 && w1[i][j] != 0) Work(i, j);     cout << anslen << endl;     for (i = 1; i <= anslen; ++i) {       if (Ans[i].x == 0)         printf( D %d %d n , Ans[i].y, Ans[i].z);       else if (Ans[i].x == 1)         printf( B %d %d n , Ans[i].y, Ans[i].z);       else         printf( R %d %d n , Ans[i].y, Ans[i].z);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char c = getchar();     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) f = -1;     for (; c >=  0  && c <=  9 ; c = getchar()) x = x * 10 + c -  0 ;     return x * f;   }   int n;   char a[1000010], b[1000010];   int fail[1000010];   int main() {     n = read();     scanf( %s , b + 1);     scanf( %s , a + 1);     n--;     for (int i = (1); i <= (n); i++)       if (a[i] ==  N )         a[i] =  S ;       else if (a[i] ==  S )         a[i] =  N ;       else if (a[i] ==  E )         a[i] =  W ;       else if (a[i] ==  W )         a[i] =  E ;     reverse(a + 1, a + n + 1);     int j = 0;     for (int i = (2); i <= (n); i++) {       for (; j && a[j + 1] != a[i]; j = fail[j])         ;       fail[i] = (a[j + 1] == a[i]) ? ++j : j;     }     j = 0;     for (int i = (1); i <= (n); i++) {       for (; j && a[j + 1] != b[i]; j = fail[j])         ;       if (a[j + 1] == b[i]) j++;     }     if (j)       printf( NO n );     else       printf( YES n );   }


#include <bits/stdc++.h>   using namespace std;   int A[10000][2];   int main() {     int N, M, K;     cin >> N >> M >> K;     int cur = 0;     for (int i = 0; i < M; i++)       for (int j = (i + 1); j < M; j++) {         A[cur][K] = i + 1;         A[cur][1 - K] = j + 1;         cur++;       }     cout << cur << endl;     for (int i = 0; i < cur; i++) cout << A[i][0] <<     << A[i][1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MAXN = 1e6 + 5;   long long a[MAXN], b[MAXN];   int main() {     int x;     cin >> x;     for (int i = 1; i <= x; i++)       for (int j = 1; j <= x; j++) {         if (i * j > x && (i / j) < x && (i % j == 0)) {           cout << i <<     << j << endl;           return 0;         }       }     cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxN = 1e5 + 10;   const long long MOD = 1e9 + 17;   long long s, t, n, m;   long long d[2][maxN];   vector<pair<long long, long long> > g[maxN], h[maxN];   vector<pair<pair<long long, long long>, long long> > edge;   long long dp[2][maxN];   void dij0(long long source) {     fill(d[0], d[0] + maxN, 1e18 + 10);     d[0][source] = 0;     dp[0][source] = 1;     set<pair<long long, long long> > s;     s.insert(make_pair(d[0][source], source));     while (!s.empty()) {       long long v = s.begin()->second;       s.erase(s.begin());       for (long long i = 0; i < g[v].size(); i++) {         long long u = g[v][i].first, w = g[v][i].second;         if (d[0][u] > d[0][v] + w) {           dp[0][u] = dp[0][v] % MOD;           s.erase(make_pair(d[0][u], u));           d[0][u] = d[0][v] + w;           s.insert(make_pair(d[0][u], u));         } else if (d[0][u] == d[0][v] + w)           dp[0][u] += dp[0][v], dp[0][u] %= MOD;       }     }   }   void dij1(long long source) {     fill(d[1], d[1] + maxN, 1e18 + 10);     d[1][source] = 0;     dp[1][source] = 1;     set<pair<long long, long long> > s;     s.insert(make_pair(d[1][source], source));     while (!s.empty()) {       long long v = s.begin()->second;       s.erase(s.begin());       for (long long i = 0; i < h[v].size(); i++) {         long long u = h[v][i].first, w = h[v][i].second;         if (d[1][u] > d[1][v] + w) {           dp[1][u] = dp[1][v] % MOD;           s.erase(make_pair(d[1][u], u));           d[1][u] = d[1][v] + w;           s.insert(make_pair(d[1][u], u));         } else if (d[1][u] == d[1][v] + w)           dp[1][u] += dp[1][v], dp[1][u] %= MOD;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m >> s >> t;     s--;     t--;     for (long long i = 0; i < m; i++) {       long long v, u, w;       cin >> v >> u >> w;       v--, u--;       g[v].push_back(make_pair(u, w));       h[u].push_back(make_pair(v, w));       edge.push_back(make_pair(make_pair(v, u), w));     }     dij0(s);     dij1(t);     for (long long i = 0; i < m; i++) {       long long v = edge[i].first.first, u = edge[i].first.second;       long long w = edge[i].second;       if (d[0][v] + w + d[1][u] == d[0][t]) {         if ((dp[0][v] * dp[1][u]) % MOD == dp[0][t]) {           cout <<  YES  <<   n ;           continue;         }       }       if (d[0][v] + d[1][u] + 1 < d[0][t]) {         cout <<  CAN   << d[0][v] + w + d[1][u] - d[0][t] + 1 <<   n ;         continue;       }       cout <<  NO  <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, b, c, d, i, j, k, l, arr[26], max = 1;     long long int dp[1005], len[1005];     for (i = 0; i < 1005; i++) dp[i] = 0;     cin >> a;     string s;     cin >> s;     for (i = 0; i < 26; i++) cin >> arr[i];     dp[0] = 1;     dp[1] = 1;     len[0] = 0;     for (i = 2; i <= a; i++) {       int t = 0;       l = 99999;       j = i + 1;       while (j > 1) {         j--;         t++;         if (l > arr[s[j - 1] - 97]) l = arr[s[j - 1] - 97];         if (l >= t) {           dp[i] += dp[j - 1];         } else {           if (i - j > max) max = i - j;           len[i] = j;           break;         }         if (j == 1) {           if (max < i) max = i;         }         len[i] = 0;       }       dp[i] = dp[i] % 1000000007;     }     int ss = 1;     i = a;     while (len[i] != 0) {       i = len[i];       ss++;     }     cout << dp[a] << endl;     cout << max << endl;     cout << ss << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef struct {     long long v;     long long c;   } double_pair;   struct line {     long long k, b;     line() {}     line(long long _k, long long _b) : k(_k), b(_b) {}     long long Solve(long long val) {       long long _a = val - b, _b = k;       if (_a % _b == 0)         return _a / _b;       else         return _a / _b + 1;     }     long long f(long long x) { return k * x + b; }   };   double_pair D[300000];   int n;   line St[300000];   int top;   long long X[300000], s;   long long intersection(line a, line b) {     long long _a = a.b - b.b, _b = b.k - a.k;     if (_a % _b == 0)       return _a / _b;     else       return _a / _b + 1;   }   bool slope_compare(double_pair d1, double_pair d2) {     return ((d1.c < d2.c) || (d1.c == d2.c && d1.v > d2.v));   }   bool check(long long x, long long _s) {     if (x > X[top - 1]) return x >= St[top].Solve(_s);     int pos = lower_bound(X + 1, X + top, x) - X;     if (X[pos] == x) pos++;     return x >= St[pos].Solve(_s);   }   long long chat(long long _s) {     long long l = 0, r = _s, mid;     while (l + 1 < r) {       mid = (l + r) >> 1;       if (check(mid, _s))         r = mid;       else         l = mid;     }     return r;   }   void find_hull() {     St[++top] = line(D[0].v, -D[0].c);     long long i1, i2;     for (int i = 1; i < n; ++i) {       long long x0 = chat(D[i].c);       long long p = lower_bound(X + 1, X + top, x0) - X;       long long y0 =           St[p + (X[p] == x0)].k * x0 + St[p + (X[p] == x0)].b - D[i].c;       line tmp(D[i].v, y0 - x0 * D[i].v);       while (top >= 2 && (((i1 = intersection(tmp, St[top])) <=                                (i2 = intersection(St[top], St[top - 1])) ||                            (i1 == i2 && tmp.f(i1) >= St[top].f(i1)))))         --top;       St[++top] = tmp;       X[top - 1] = intersection(St[top], St[top - 1]);     }   }   int main() {     cin >> n >> s;     for (int i = 1; i <= n; i++) cin >> D[i].v >> D[i].c;     sort(D + 1, D + n + 1, slope_compare);     int tmp_n = n, maxv = 0;     n = 0;     for (int i = 1; i <= tmp_n; i++) {       if (maxv >= D[i].v) continue;       maxv = D[i].v;       D[n++] = D[i];     }     find_hull();     cout << chat(s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 123457;   int n, m, S, A, D, R, h[N];   vector<int> adj[N];   bool is[N];   bool dfs(int v, int par = 0) {     h[v] = h[par] + 1;     bool c = is[v];     if (c && h[v] >= D) D = h[v], R = v;     if (c && h[v] == D && v < S) S = v;     for (int i = 0; i < adj[v].size(); ++i)       if (adj[v][i] != par) c |= dfs(adj[v][i], v);     if (c) ++A;     return c;   }   int main() {     cin >> n >> m;     int a, b;     for (int i = 0; i < n - 1; ++i) {       cin >> a >> b;       adj[a].push_back(b), adj[b].push_back(a);     }     h[0] = -1;     memset(is, false, sizeof(is));     S = 0, A = 0, D = 0;     for (int i = 0; i < m; ++i) {       cin >> R;       is[R] = true;     }     dfs(R);     dfs(R);     S = N;     dfs(R), dfs(R);     cout << S << endl << (A - 4) / 2 - D << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MD = 1000000007;   long long A[100000 + 1], dp[100000 + 1];   long long exp(long long a, long long b) {     long long r = 1;     while (b > 0) {       if (b & 1) r = r * a;       b /= 2;       a = a * a;     }     return r;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t, n, i, s, j, p, m, x, y, k, q;     string s1;     map<long long, long long> mp;     for (i = 0; i <= 32; i++) mp.insert({exp(2, i), i});     cin >> n >> m;     for (long long i = 1; i <= n; i++) {       cin >> x;       A[mp[x]]++;     }     while (m--) {       cin >> x;       p = 0;       for (i = 32; i >= 0; --i) {         k = min(x / exp(2, i), A[i]);         p += k;         x -= k * exp(2, i);       }       if (x != 0)         cout <<  -1 n ;       else         cout << p <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int server, temp;     int a, b;     a = 0;     b = 0;     int sum1, sum2;     sum1 = 0;     sum2 = 0;     for (int i = 0; i < n; i++) {       cin >> server;       if (server == 1) {         cin >> temp;         a++;         sum1 += temp;       } else {         cin >> temp;         b++;         sum2 += temp;       }       cin >> temp;     }     if (sum1 / a >= 5)       cout <<  LIVE  << endl;     else       cout <<  DEAD  << endl;     if (sum2 / b >= 5)       cout <<  LIVE  << endl;     else       cout <<  DEAD  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1 << 30;   const long long linf = 1LL << 60;   const int maxn = 100 + 5;   int A[maxn];   bool used[maxn];   vector<int> Q;   vector<vector<int> > B;   vector<int> C;   int n, k, m, q;   long double anal() {     long double res = 0;     for (int i = 0; i < m; ++i) {       res += (long double)A[B.back()[i] - 1];       used[B.back()[i] - 1] = 1;     }     res /= (long double)m;     return res;   }   int main() {     long double _min = inf;     long double _max = -1;     cin >> n >> k;     for (int i = 0; i < n; ++i) cin >> A[i];     m = n / k;     Q.reserve(m);     cin >> q;     for (int i = 0; i < q; ++i) {       Q.clear();       for (int j = 0; j < m; ++j) {         int x;         cin >> x;         Q.push_back(x);       }       sort((Q).begin(), (Q).end());       bool _new = 1;       for (int j = 0; j < B.size(); ++j) {         if (B[j][0] == Q[0]) {           _new = 0;           break;         }       }       if (_new) {         B.push_back(Q);         long double _res = anal();         if (_min > _res) _min = _res;         if (_max < _res) _max = _res;       }     }     if ((int)(B).size() < k) {       C.reserve(n);       for (int i = 0; i < n; ++i) {         if (!used[i]) C.push_back(A[i]);       }       sort((C).begin(), (C).end());       long double res = 0;       for (int i = 0; i < m; ++i) {         res += (long double)C[i];       }       res /= (long double)m;       if (_min > res) _min = res;       if (_max < res) _max = res;       res = 0;       for (int i = (int)(C).size() - 1; i >= (int)(C).size() - m; --i) {         res += (long double)C[i];       }       res /= (long double)m;       if (_min > res) _min = res;       if (_max < res) _max = res;     }     cout.setf(ios::fixed);     cout.precision(8);     cout << _min <<     << _max <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const double eps = 1e-4;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const int inf = 0x3f3f3f3f;   const int maxn = 1e5 + 7;   const int maxm = 1e6 + 7;   const double pi = acos(-1.0);   long long a[maxn];   long long b[maxn], c[maxn];   int main() {     int n;     scanf( %d , &n);     ;     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     for (int i = 1; i < n; i++) {       int tmp = a[i] - a[i + 1];       if (tmp < 0) tmp = -tmp;       if (i % 2 == 1) {         b[i] = tmp;         c[i] = -tmp;       } else {         b[i] = -tmp;         c[i] = tmp;       }     }     long long sum = 0;     long long mx1 = -1, mx2 = -1;     for (int i = 1; i < n; i++) {       sum += b[i];       mx1 = max(mx1, sum);       if (sum < 0) {         sum = 0;         if (i % 2 == 1) i--;       }     }     sum = 0;     for (int i = 2; i < n; i++) {       sum += c[i];       mx2 = max(mx2, sum);       if (sum < 0) {         sum = 0;         if (i % 2 == 0) i--;       }     }     cout << max(mx1, mx2) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s;     cin >> n >> s;     vector<int> spareIndices;     vector<bool> LetterPresent(n);     for (int i = 0, j = s.length() - 1; i < (s.length() + 1) / 2; ++i, --j) {       if (s[i] != s[j]) {         if (s[i] ==  ? ) {           s[i] = s[j];           LetterPresent[s[i] -  a ] = true;           continue;         }         if (s[j] ==  ? ) {           s[j] = s[i];           LetterPresent[s[i] -  a ] = true;           continue;         }         cout <<  IMPOSSIBLE ;         return 0;       }       if (s[i] ==  ? ) {         spareIndices.push_back(i);         continue;       }       LetterPresent[s[i] -  a ] = true;     }     vector<char> unused_letters;     for (int i = 0; i < LetterPresent.size(); ++i) {       if (!LetterPresent[i]) unused_letters.push_back( a  + i);     }     if (unused_letters.size() > spareIndices.size()) {       cout <<  IMPOSSIBLE ;       return 0;     }     int a = spareIndices.size() - unused_letters.size();     int i = 0;     for (; i < a; ++i) {       s[spareIndices[i]] = s[s.size() - 1 - spareIndices[i]] =  a ;     }     for (; i < spareIndices.size(); ++i) {       s[spareIndices[i]] = s[s.size() - 1 - spareIndices[i]] =           unused_letters[i - a];     }     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   char s[1000001], t[1000001];   long long z[1000001], c[1000001];   int main() {     int n, k;     scanf( %d%d%s%s , &n, &k, s + 1, t + 1);     if (k == 1) {       printf( %d n , k * n);       return 0;     }     int o = 1;     while (o <= n && s[o] == t[o]) o++;     if (o > n) {       printf( %d n , n);       return 0;     }     long long ans = n + (n - o + 1);     k -= 2;     o++;     while (o <= n) {       if (s[o] ==  a ) z[n - o + 1]++;       if (t[o] ==  b ) z[n - o + 1]++;       o++;     }     for (int i = n; i; i--) {       z[i] += c[i];       c[i - 1] += c[i];       int kk = min(1ll * k, z[i]);       ans += 1ll * i * kk;       k -= kk;       c[i - 1] += kk;     }     printf( %I64d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int n;   string s;   long long rights[1000010], lefts[1000010], mins[1000010];   long long suml[1000010], sumr[1000010];   int min(int a, int b) { return a < b ? a : b; }   int main() {     scanf( %d , &n);     cin >> s;     lefts[0] = 0;     rights[n - 1] = 0;     for (int i = 1; i < n; i++) {       if (s[i - 1] ==  U ) lefts[i]++;       lefts[i] += lefts[i - 1];     }     for (int i = n - 2; i >= 0; i--) {       if (s[i + 1] ==  D ) rights[i]++;       rights[i] += rights[i + 1];     }     for (int i = 0; i < n; i++)       mins[i] = min(lefts[i] + (s[i] ==  U  ? 1 : 0),                     rights[i] + (s[i] ==  D  ? 1 : 0));     long long t = 0;     queue<long long> q;     for (int i = 0; i < n; i++) {       t += q.size();       if (q.size() <= mins[i]) {         suml[i] = t;       } else {         while (q.size() > mins[i]) {           t -= i - q.front();           q.pop();         }         suml[i] = t;       }       if (s[i] ==  U ) q.push(i);     }     while (!q.empty()) q.pop();     t = 0;     for (int i = n - 1; i >= 0; i--) {       t += q.size();       if (q.size() <= mins[i]) {         sumr[i] = t;       } else {         while (q.size() > mins[i]) {           t -= q.front() - i;           q.pop();         }         sumr[i] = t;       }       if (s[i] ==  D ) q.push(i);     }     for (long long i = 0; i < n; i++) {       if (rights[i] > lefts[i]) {         cout << sumr[i] * 2 + suml[i] * 2 + i + 1 <<    ;       } else if (rights[i] < lefts[i]) {         cout << sumr[i] * 2 + suml[i] * 2 + n - i <<    ;       } else {         if (s[i] ==  D )           cout << sumr[i] * 2 + suml[i] * 2 + i + 1 <<    ;         else           cout << sumr[i] * 2 + suml[i] * 2 + n - i <<    ;       }     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 2e5 + 5;   vector<int> v(MX);   struct Q {     int t, l, r;   };   vector<Q> qs(MX);   int n, q, m, p;   int main() {     cin >> n >> q >> m;     for (int i = 1; i <= n; i++) cin >> v[i];     for (int i = 1; i <= q; i++) cin >> qs[i].t >> qs[i].l >> qs[i].r;     while (m--) {       cin >> p;       for (int i = q; i > 0; i--) {         if (p < qs[i].l || p > qs[i].r) continue;         if (qs[i].t == 1) {           p--;           if (p < qs[i].l) p = qs[i].r;         } else           p = qs[i].r - (p - qs[i].l);       }       cout << v[p] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<string> v;   int main(void) {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       char s[50];       scanf( %s , &s);       v.push_back((string)s);     }     int res = 0;     while (true) {       int ok = 1;       for (int i = 0; i < n; i++)         if (v[i][res] != v[0][res]) {           printf( %d n , res);           return 0;         }       res++;     }     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     long long t;     cin >> t;     while (t--) {       long long a, b;       cin >> a >> b;       if (a == b) {         if (a == 0)           cout << 0 <<   n ;         else           cout << 1 <<   n ;       } else if ((a + b) % 2)         cout << -1 <<   n ;       else         cout << 2 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, carry = 0, flag = 1;     cin >> n;     int ar[n];     for (i = 0; i < n; i++) {       cin >> ar[i];       if (ar[i] == 0 && carry == 1) {         flag = 0;       }       if (ar[i] % 2 == 0 && carry == 0) {         continue;       }       if (i == (n - 1)) {         if (ar[i] % 2 == 0 && carry == 1) {           cout <<  NO n ;           return 0;         }         if (ar[i] % 2 == 1 && carry == 0) {           cout <<  NO n ;           return 0;         }       }       if (ar[i] % 2 == 1 && carry == 1) {         carry = 0;         continue;       }       carry = 1;     }     if (flag == 0) {       cout <<  NO n ;       return 0;     }     cout <<  YES n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-12;   struct P {     double x, y;     P(double x = 0, double y = 0) : x(x), y(y){};   } a, b, c, o, p;   P operator+(P a, P b) { return P(a.x + b.x, a.y + b.y); }   P operator*(P a, double b) { return P(a.x * b, a.y * b); }   inline double dis(P a, P b) {     return sqrt(((a.x - b.x) * (a.x - b.x)) + ((a.y - b.y) * (a.y - b.y)));   }   inline void read(P &a) { scanf( %lf%lf , &a.x, &a.y); }   double t1, t2, l, r, m, m1, m2, ab, bc, ac, ap;   double Calc(double k) {     p = b * (1 - k) + c * k;     ap = dis(a, p);     if (ap + bc * (1 + k) < t1 && ap + bc * (1 - k) < t2)       return min(t1 - bc * (1 + k), t2 - bc * (1 - k));     double l = 0, r = 1;     for (int i = 0; i < 100; ++i) {       m = (l + r) * 0.5;       o = a * (1 - m) + p * m;       if (ap * m + dis(o, b) + bc < t1 && ap * m + dis(o, c) < t2)         l = m;       else         r = m;     }     return (l + r) * 0.5 * ap;   }   int main() {     scanf( %lf%lf , &t1, &t2);     read(a);     read(c);     read(b);     ab = dis(a, b);     bc = dis(b, c);     ac = dis(a, c);     t1 += ab + bc + eps;     t2 += ac + eps;     if (ab + bc < t2) {       printf( %.10lf n , min(t1, t2));       return 0;     }     l = 0, r = 1;     for (int i = 0; i < 100; ++i) {       m1 = (l + l + r) / 3;       m2 = (l + r + r) / 3;       if (Calc(m1) < Calc(m2))         l = m1;       else         r = m2;     }     printf( %.10lf n , Calc((l + r) * .5));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve(istream& in, ostream& out) {     int n;     in >> n;     int res = n % 2 ? 0 : 1LL << (n / 2);     out << res << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     std::istream& in(std::cin);     std::ostream& out(std::cout);     solve(in, out);   }


#include <bits/stdc++.h>   using namespace std;   long long mi, mx, n, ta, tb, tc;   void C(long long x, long long y, long long z) {     ta = (x + 1) * (y + 2) * (z + 2);     if (ta > mx) mx = ta;     if (ta < mi) mi = ta;   }   int main() {     long long a, b, c, d, uu;     uu = 1000000;     scanf( %I64d , &n);     int k = (int)sqrt(double(n));     mx = -999;     mi = uu * uu * uu;     for (int i = 1; i <= k; i++) {       if (n % i == 0) {         a = i;         b = n / i;         int kk = (int)sqrt(double(b));         for (int j = 1; j <= kk; j++)           if (b % j == 0) {             c = b / j;             d = j;             C(a, c, d);             C(c, a, d);             C(d, a, c);           }       }     }     printf( %I64d %I64d n , mi - n, mx - n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long expo(long long a, long long b, long long m) {     long long result = 1;     while (b) {       if (b & 1) {         result = (result * a) % m;       }       b = (b >> 1) % m;       a = (a * a) % m;     }     return result;   }   double expof(double a, int b) {     double result = 1;     while (b) {       if (b & 1) {         result = (result * a);       }       b = (b >> 1);       a = (a * a);     }     return result;   }   bool comp(pair<long long, long long> a, pair<long long, long long> b) {     if (a.second < b.second) return true;   }   int main() {     long long m, n, t, c, l, x;     vector<pair<long long, pair<long long, long long> > > p;     vector<long long> v;     cin >> m;     long long ans = 0;     for (int i = 0; i < m; ++i) {       cin >> t;       if (t == 1) {         cin >> x;         ans++;         v.push_back(ans);         p.push_back(make_pair(1, make_pair(x, 0)));       } else {         cin >> l >> c;         ans += c * l;         v.push_back(ans);         p.push_back(make_pair(2, make_pair(l, c)));       }     }     cin >> n;     long long q[100005];     for (int i = 0; i < n; ++i) {       cin >> q[i];     }     for (int i = 0; i < n; ++i) {       x = q[i];       vector<long long>::iterator it = upper_bound(v.begin(), v.end(), x);       long long ix = it - v.begin();       ix--;       if (v[ix] == x) {         if (p[ix].first == 1) {           cout << p[ix].second.first <<    ;           continue;         } else {           x = p[ix].second.first;         }       } else {         if ((x - v[ix]) % p[ix + 1].second.first == 0) {           x = p[ix + 1].second.first;         } else           x = (x - v[ix]) % p[ix + 1].second.first;       }       while (1) {         vector<long long>::iterator it = upper_bound(v.begin(), v.end(), x);         long long ix = it - v.begin();         ix--;         if (v[ix] == x) {           if (p[ix].first == 1) {             cout << p[ix].second.first <<    ;             break;           } else {             x = p[ix].second.first;             continue;           }         }         if ((x - v[ix]) % p[ix + 1].second.first == 0) {           x = p[ix + 1].second.first;         } else           x = (x - v[ix]) % p[ix + 1].second.first;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MAXN = 200005;   const int MOD = 1e9 + 9;   vector<int> g[MAXN];   int n, m, q, ans;   int rows[MAXN];   bool vist[MAXN];   pair<int, int> samp[MAXN];   void dfs(int st) {     if (vist[st]) return;     vist[st] = 1;     for (int i = 0; i < g[st].size(); i++) {       dfs(g[st][i]);     }   }   void buildG() {     sort(samp, samp + q);     for (int i = 1; i < q; ++i) {       int r = samp[i].first, c = samp[i].second;       int rl = samp[i - 1].first, cl = samp[i - 1].second;       if (r == rl) {         g[c].push_back(cl);         g[cl].push_back(c);       }     }   }   int main() {     scanf( %d %d %d , &n, &m, &q);     for (int i = 0; i < q; ++i) {       int r, c;       scanf( %d %d , &r, &c);       r--;       c--;       rows[r] = 1;       samp[i] = {r, c};     }     buildG();     for (int i = 0; i < m; ++i) {       if (!vist[i]) {         ans++;         dfs(i);       }     }     ans--;     for (int i = 1; i < n; ++i) rows[i] += rows[i - 1];     ans += n - rows[n - 1];     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     const long maxSteps = 1000000000;     long n, m;     cin >> n >> m;     long x, y;     cin >> x >> y;     int k;     cin >> k;     long long total = 0;     while (k--) {       long dx = 0, dy = 0;       cin >> dx >> dy;       long stepsX = maxSteps, stepsY = maxSteps;       if (dx > 0) {         stepsX = (n - x) / dx;       } else if (dx < 0) {         stepsX = (x - 1) / -dx;       }       if (dy > 0) {         stepsY = (m - y) / dy;       } else if (dy < 0) {         stepsY = (y - 1) / -dy;       }       long stepsnum = 0;       if (stepsY > 0 && stepsX > 0) {         stepsnum = min(stepsX, stepsY);       }       x += stepsnum * dx;       y += stepsnum * dy;       total += stepsnum;     }     cout << total;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int l, r;     scanf( %d%d , &l, &r);     if (l == r)       printf( %d n , l);     else       puts( 2 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   const int inf = 2000000000;   const long long infLL = 9000000000000000000;   template <typename first, typename second>   ostream &operator<<(ostream &os, const pair<first, second> &p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  { ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  } ;   }   template <typename T>   ostream &operator<<(ostream &os, const set<T> &v) {     os <<  [ ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  , ;       os << *it;     }     return os <<  ] ;   }   template <typename T>   ostream &operator<<(ostream &os, const multiset<T> &v) {     os <<  [ ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  ] ;   }   template <typename first, typename second>   ostream &operator<<(ostream &os, const map<first, second> &v) {     os <<  [ ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << it->first <<   =   << it->second;     }     return os <<  ] ;   }   void faltu() { cerr <<   n ; }   template <typename T>   void faltu(T a[], int n) {     for (int i = 0; i < n; ++i) cerr << a[i] <<    ;     cerr <<   n ;   }   template <typename T, typename... hello>   void faltu(T arg, const hello &...rest) {     cerr << arg <<    ;     faltu(rest...);   }   const int mx = 2e5 + 5;   vector<int> adjlist[mx];   int n;   bool isleaf[mx];   int deg[mx];   struct info {     int leaf, child, dist;   };   bool cmp(const info &lhs, const info &rhs) { return lhs.dist > rhs.dist; }   vector<info> dp[mx];   void dfs(int u, int par) {     vector<info> store;     store.push_back({u, u, 0});     for (auto v : adjlist[u]) {       if (v == par) continue;       dfs(v, u);       info temp = dp[v][0];       ++temp.dist;       temp.child = v;       store.push_back(temp);     }     sort(store.begin(), store.end(), cmp);     while (store.size() > 3) store.pop_back();     dp[u] = store;   }   int ans = 0;   vector<int> vec;   void dfs2(int u, int par) {     if (dp[u].size() >= 3) {       if (ans < dp[u][0].dist + dp[u][1].dist + dp[u][2].dist) {         ans = dp[u][0].dist + dp[u][1].dist + dp[u][2].dist;         vec.clear();         vec.push_back(dp[u][0].leaf);         vec.push_back(dp[u][1].leaf);         vec.push_back(dp[u][2].leaf);       }     }     for (auto v : adjlist[u]) {       if (v == par) continue;       for (int i = 0; i < dp[u].size(); ++i) {         if (dp[u][i].child == v) continue;         info temp = dp[u][i];         temp.child = u;         ++temp.dist;         dp[v].push_back(temp);         sort(dp[v].begin(), dp[v].end(), cmp);         dfs2(v, u);         break;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (int i = 0; i < n - 1; ++i) {       int a, b;       cin >> a >> b;       adjlist[a].push_back(b);       adjlist[b].push_back(a);       ++deg[a];       ++deg[b];     }     for (int i = 1; i <= n; ++i) {       if (deg[i] == 1) isleaf[i] = 1;     }     dfs(1, 0);     dfs2(1, 0);     cout << ans <<   n ;     for (int i = 0; i < vec.size(); ++i) cout << vec[i] <<    ;     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   struct edge {     int link, next;   } e[100010];   int n, k, f[50010][510], h[100010], jud[50010], tt = 0;   long long ans[50010], tot;   void addEdge(int x, int y) {     tt++;     e[tt].link = y;     e[tt].next = h[x];     h[x] = tt;   }   void dfs(int x) {     jud[x] = 1;     f[x][0] = 1;     for (int i = h[x]; i != 0; i = e[i].next)       if (jud[e[i].link] == 0) {         int y = e[i].link;         dfs(y);         for (int j = 0; j < k; j++)           ans[x] = ans[x] + 1LL * f[x][j] * f[y][k - j - 1];         for (int j = 0; j < k; j++) f[x][j + 1] += f[y][j];       }     tot += ans[x];     return;   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       addEdge(a, b);       addEdge(b, a);     }     memset(jud, 0, sizeof(jud));     dfs(1);     cout << tot << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int st[100100][20];   vector<int> graph[100100], ind[100100];   int lev[100100];   int t[100100], l[100100], lg[100100];   int s[100100];   void blg(int n) {     lg[0] = -1;     for (int i = 0; i < n; ++i) lg[i + 1] = lg[i] + !(i & (i + 1));   }   void dfs(int u, int p, int l) {     st[u][0] = p;     for (int i = 1; (1 << i) <= l; ++i) st[u][i] = st[st[u][i - 1]][i - 1];     lev[u] = l;     for (int v : graph[u])       if (v != p) dfs(v, u, l + 1);   }   int getParent(int u, int d) {     if (lev[u] < d) return -1;     for (int i = d; i; i -= i & -i) u = st[u][lg[i & -i]];     return u;   }   int LCA(int u, int v) {     if (lev[u] < lev[v]) v = getParent(v, lev[v] - lev[u]);     if (lev[u] > lev[v]) u = getParent(u, lev[u] - lev[v]);     int r = lev[u], l = 0, m;     while (l < r) {       m = (l + r) / 2;       if (getParent(u, m) == getParent(v, m))         r = m;       else         l = m + 1;     }     return getParent(u, l);   }   int solve(int u, int p) {     int y = l[u] - t[u];     for (int j = 0; j < graph[u].size(); ++j) {       int v = graph[u][j];       if (v != p) {         y += s[ind[u][j]] = solve(v, u);       }     }     return y;   }   int main() {     int n, k, x, y;     cin >> n;     blg(n);     for (int i = 1; i < n; ++i) {       scanf( %d%d , &x, &y);       graph[x].push_back(y), graph[y].push_back(x);       ind[x].push_back(i);       ind[y].push_back(i);     }     dfs(1, 1, 0);     cin >> k;     while (k--) {       scanf( %d%d , &x, &y);       t[LCA(x, y)] += 2;       l[x]++, l[y]++;     }     solve(1, 0);     for (int i = 1; i < n; ++i) cout << s[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 2;   const long long mod = 998244353;   long long fpow(long long a, long long b) {     if (b == 0) return 1;     long long cur = fpow(a, b >> 1);     cur *= cur;     cur %= mod;     if (b & 1) cur *= a;     return cur % mod;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m, L, R;     cin >> n >> m >> L >> R;     long long dif = R - L + 1;     long long par = 0, impar = 0;     if (L & 1)       impar = dif >> 1ll, par = dif - impar;     else       par = dif >> 1ll, impar = dif - par;     if (n * m & 1)       cout << fpow(par + impar, n * m) <<   n ;     else       cout << ((((fpow(par + impar, n * m) + fpow(par - impar, n * m)) *                  fpow(2, mod - 2)) %                 mod) +                mod) %                   mod            <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool tomax(T &x, T y) {     if (x < y) return x = y, 1;     return 0;   }   template <class T>   bool tomin(T &x, T y) {     if (x > y) return x = y, 1;     return 0;   }   int A[400005], n, K;   int cnt[400005], B[400005], res;   void Add(int x, int v) {     if (cnt[x] == 0 && v > 0) res++;     if (cnt[x] == 1 && v < 0) res--;     cnt[x] += v;   }   bool Check() {     int p = log2(res);     if (1.0 * pow(2, p) != 1.0 * res) p++;     return 1LL * p * n <= 8LL * K;   }   bool check(int x) {     if (x == n) return 1;     memset(cnt, 0, sizeof(cnt));     x = n - x;     res = 0;     for (int i = 1; i <= x; i++) Add(A[i], 1);     if (Check()) return 1;     for (int i = x + 1; i <= n; i++) {       Add(A[i - x], -1), Add(A[i], 1);       if (Check()) return 1;     }     return 0;   }   int main() {     cin >> n >> K;     for (int i = 1; i <= n; i++) scanf( %d , &A[i]), B[i] = A[i];     sort(B + 1, B + 1 + n);     int len = unique(B + 1, B + 1 + n) - B - 1;     for (int i = 1; i <= n; i++) A[i] = lower_bound(B + 1, B + 1 + len, A[i]) - B;     sort(A + 1, A + 1 + n);     int L = 0, R = n, ans = 0;     while (L <= R) {       int mid = L + R >> 1;       if (check(mid))         ans = mid, R = mid - 1;       else         L = mid + 1;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   const double PI = atan(1) * 4;   const double E = exp(1);   const int oo = 1e9;   const int eps = 1e-9;   using namespace std;   bool vo(char c) {     return (c ==  a  or c ==  e  or c ==  i  or c ==  o  or c ==  u );   }   int main() {     ios::sync_with_stdio(0);     string s;     cin >> s;     bool b = true;     for (int i = 0; i < ((int)((s).size())) and b; i++) {       if ((!vo(s[i]) and s[i] !=  n ) and           (i + 1 >= ((int)((s).size())) or !vo(s[i + 1])))         b = false;     }     if (b)       cout <<  YES n ;     else       cout <<  NO n ;   }


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


#include <bits/stdc++.h>   const int mod = 1000000007;   const int gmod = 3;   const int inf = 1039074182;   const double eps = 1e-9;   const long long llinf = 2LL * inf * inf;   template <typename T1, typename T2>   inline void chmin(T1 &x, T2 b) {     if (b < x) x = b;   }   template <typename T1, typename T2>   inline void chmax(T1 &x, T2 b) {     if (b > x) x = b;   }   inline void chadd(int &x, int b) {     x += b - mod;     x += (x >> 31 & mod);   }   template <typename T1, typename T2>   inline void chadd(T1 &x, T2 b) {     x += b;     if (x >= mod) x -= mod;   }   template <typename T1, typename T2>   inline void chmul(T1 &x, T2 b) {     x = 1LL * x * b % mod;   }   template <typename T1, typename T2>   inline void chmod(T1 &x, T2 b) {     x %= b, x += b;     if (x >= b) x -= b;   }   template <typename T>   inline T mabs(T x) {     return (x < 0 ? -x : x);   }   using namespace std;   using namespace std;   template <typename T>   ostream &operator<<(ostream &cout, vector<T> vec) {     cout <<  { ;     for (int i = 0; i < (int)vec.size(); i++) {       cout << vec[i];       if (i != (int)vec.size() - 1) cout <<  , ;     }     cout <<  } ;     return cout;   }   template <typename T1, typename T2>   ostream &operator<<(ostream &cout, pair<T1, T2> p) {     cout <<  (  << p.first <<  ,  << p.second <<  ) ;     return cout;   }   template <typename T, typename T2>   ostream &operator<<(ostream &cout, set<T, T2> s) {     vector<T> t;     for (auto x : s) t.push_back(x);     cout << t;     return cout;   }   template <typename T, typename T2>   ostream &operator<<(ostream &cout, multiset<T, T2> s) {     vector<T> t;     for (auto x : s) t.push_back(x);     cout << t;     return cout;   }   template <typename T>   ostream &operator<<(ostream &cout, queue<T> q) {     vector<T> t;     while (q.size()) {       t.push_back(q.front());       q.pop();     }     cout << t;     return cout;   }   template <typename T1, typename T2, typename T3>   ostream &operator<<(ostream &cout, map<T1, T2, T3> m) {     for (auto &x : m) {       cout <<  Key:   << x.first <<     <<  Value:   << x.second << endl;     }     return cout;   }   template <typename T1, typename T2>   void operator+=(pair<T1, T2> &x, const pair<T1, T2> y) {     x.first += y.first;     x.second += y.second;   }   template <typename T1, typename T2>   pair<T1, T2> operator+(const pair<T1, T2> &x, const pair<T1, T2> &y) {     return make_pair(x.first + y.first, x.second + y.second);   }   template <typename T1, typename T2>   pair<T1, T2> operator-(const pair<T1, T2> &x, const pair<T1, T2> &y) {     return make_pair(x.first - y.first, x.second - y.second);   }   template <typename T1, typename T2>   pair<T1, T2> operator-(pair<T1, T2> x) {     return make_pair(-x.first, -x.second);   }   template <typename T>   vector<vector<T>> operator~(vector<vector<T>> vec) {     vector<vector<T>> v;     int n = vec.size(), m = vec[0].size();     v.resize(m);     for (int i = 0; i < m; i++) {       v[i].resize(n);     }     for (int i = 0; i < m; i++) {       for (int j = 0; j < n; j++) {         v[i][j] = vec[j][i];       }     }     return v;   }   void print0x(int x) {     std::vector<int> vec;     while (x) {       vec.push_back(x & 1);       x >>= 1;     }     std::reverse(vec.begin(), vec.end());     for (int i = 0; i < (int)vec.size(); i++) {       std::cout << vec[i];     }     std::cout <<    ;   }   template <typename T>   void print0x(T x, int len) {     std::vector<int> vec;     while (x) {       vec.push_back(x & 1);       x >>= 1;     }     reverse(vec.begin(), vec.end());     for (int i = (int)vec.size(); i < len; i++) {       putchar( 0 );     }     for (size_t i = 0; i < vec.size(); i++) {       std::cout << vec[i];     }     std::cout <<    ;   }   vector<string> vec_splitter(string s) {     s +=  , ;     vector<string> res;     while (!s.empty()) {       res.push_back(s.substr(0, s.find( , )));       s = s.substr(s.find( , ) + 1);     }     return res;   }   void debug_out(vector<string> __attribute__((unused)) args,                  __attribute__((unused)) int idx,                  __attribute__((unused)) int LINE_NUM) {     cerr << endl;   }   template <typename Head, typename... Tail>   void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {     if (idx > 0)       cerr <<  ,  ;     else       cerr <<  Line(  << LINE_NUM <<  )  ;     stringstream ss;     ss << H;     cerr << args[idx] <<   =   << ss.str();     debug_out(args, idx + 1, LINE_NUM, T...);   }   template <int mod>   struct ModInt {     int x;     ModInt() { x = 0; }     ModInt(int _x) {       x = _x % mod;       if (x < 0) x += mod;     }     ModInt(long long _x) {       x = _x % mod;       if (x < 0) x += mod;     }     ModInt<mod> &operator++() {       ++x;       if (x == mod) x = 0;       return *this;     }     ModInt<mod> operator++(int) {       int t = x;       x++;       if (x == mod) x = 0;       return t;     }     ModInt<mod> &operator--() {       --x;       if (x == -1) x += mod;       return *this;     }     ModInt<mod> operator--(int) {       int t = x;       x--;       if (x == -1) x += mod;       return t;     }     ModInt<mod> operator-() const { return ModInt<mod>((x == 0 ? 0 : mod - x)); }   };   template <int mod>   inline int mabs(const ModInt<mod> &a) {     return a.x;   }   template <int mod>   bool operator==(const ModInt<mod> &a, const ModInt<mod> &b) {     return a.x == b.x;   }   template <int mod>   bool operator==(ModInt<mod> a, int x) {     return (a.x == x);   }   template <int mod>   bool operator!=(const ModInt<mod> &a, const ModInt<mod> &b) {     return (a.x != b.x);   }   template <int mod>   bool operator!=(ModInt<mod> a, int x) {     return (a.x != x);   }   template <int mod>   inline ModInt<mod> operator+(ModInt<mod> a, int b) {     a.x += b;     if (a.x >= mod) a.x -= mod;     return a;   }   template <int mod>   inline ModInt<mod> operator+(ModInt<mod> a, ModInt<mod> b) {     int tmp = a.x + b.x;     if (tmp >= mod) tmp -= mod;     return tmp;   }   template <int mod>   inline ModInt<mod> operator-(ModInt<mod> a, ModInt<mod> b) {     int tmp = a.x - b.x;     if (tmp < 0) tmp += mod;     return tmp;   }   template <int mod>   inline ModInt<mod> operator-(ModInt<mod> a, int b) {     return a - (ModInt<mod>)b;   }   template <int mod>   inline void operator-=(ModInt<mod> &a, ModInt<mod> b) {     a.x -= b.x;     a.x += (a.x >> 31 & mod);   }   template <int mod, typename T>   inline void operator-=(ModInt<mod> &a, const T &b) {     a.x -= b;     a.x += (a.x >> 31 & mod);   }   template <int mod>   inline ModInt<mod> operator*(const ModInt<mod> &a, const ModInt<mod> &b) {     return 1LL * a.x * b.x % mod;   }   template <int mod>   inline ModInt<mod> operator*(const ModInt<mod> &a, const int &b) {     return 1LL * a.x * b % mod;   }   template <int mod>   inline void operator*=(ModInt<mod> &a, const ModInt<mod> &b) {     a.x = 1LL * a.x * b.x % mod;   }   template <int mod, typename T>   inline void operator*=(ModInt<mod> &a, const T &b) {     a = a * b;   }   template <int mod>   inline void operator+=(ModInt<mod> &a, const ModInt<mod> &b) {     a.x += b.x;     if (a.x >= mod) a.x -= mod;   }   template <int mod, typename T>   void operator+=(ModInt<mod> &a, const T &b) {     a.x += b;     if (a.x >= mod) a.x -= mod;   }   template <int mod>   inline ModInt<mod> mod_inv(ModInt<mod> x) {     int m = mod - 2;     ModInt<mod> basic = x;     x = 1;     while (m) {       if (m & 1) x *= basic;       m >>= 1;       basic *= basic;     }     return x;   }   template <int mod>   ModInt<mod> operator/(ModInt<mod> a, ModInt<mod> b) {     return a * mod_inv(b);   }   template <int mod>   ModInt<mod> operator/(ModInt<mod> a, int b) {     return a * mod_inv((ModInt<mod>)b);   }   template <int mod>   void operator/=(ModInt<mod> &a, int b) {     a *= mod_inv(ModInt<mod>(b));   }   template <int mod>   void operator/=(ModInt<mod> &a, ModInt<mod> b) {     a = a / b;   }   template <int mod>   inline ModInt<mod> operator^(ModInt<mod> basic, int x) {     ModInt<mod> res = 1;     while (x) {       if (x & 1) res *= basic;       basic *= basic;       x >>= 1;     }     return res;   }   template <int mod>   istream &operator>>(istream &cin, ModInt<mod> &x) {     cin >> x.x;     x.x %= mod;     if (x.x < 0) x.x += mod;     return cin;   }   template <int mod>   ostream &operator<<(ostream &cout, ModInt<mod> x) {     cout << x.x;     return cout;   }   template <int mod, int g, int LogN>   struct NTT {     using Int = ModInt<mod>;     static const int MaxN = (1 << LogN);     int w[MaxN + 5];     int fastpow(int basic, int x) {       int res = 1;       while (x) {         if (x & 1) res = 1LL * res * basic % mod;         basic = 1LL * basic * basic % mod;         x >>= 1;       }       return res;     }     int inv[MaxN + 5];     int buf[MaxN + 5];     int ww[MaxN + 5];     inline void ntt(vector<int> &v, int rev, int lg) {       int n = (1 << lg);       memset(buf, 0, sizeof(int) * n);       v.resize(n, 0);       for (int i = 0; i < n; i++) {         inv[i] = (inv[i >> 1] >> 1) | ((i & 1) << (lg - 1));       }       for (int i = 0; i < n; i++) {         buf[i] = v[inv[i]];       }       int lvl = LogN;       int *ba, *bb, *wa, *wb;       int tmp;       for (int b = 1; b < n; b *= 2) {         lvl--;         for (int i = 0; i < b * 2; i++)           ww[i] = (rev ? w[MaxN - (i << lvl)] : w[i << lvl]);         for (int i = 0; i < n; i += b * 2) {           ba = buf + i;           bb = buf + i + b;           wa = ww;           wb = ww + b;           for (int j = 0; j < b; j++) {             tmp = 1LL * *wa * *bb % mod;             *bb = *ba - tmp;             *ba += tmp;             *ba -= mod;             *ba += ((*ba) >> 31 & mod);             *bb += ((*bb) >> 31 & mod);             ba++;             bb++;             wa++;             wb++;           }         }       }       int t = fastpow(n, mod - 2);       if (rev) {         for (int i = 0; i < (1 << lg); i++) {           buf[i] = 1LL * buf[i] * t % mod;         }       }       for (int i = 0; i < (1 << lg); i++) v[i] = buf[i];     }     void multiply(vector<int> a, vector<int> b, vector<int> &c) {       int n = (int)a.size() + b.size() - 1;       if (min(a.size(), b.size()) <= 60) {         c.clear();         c.resize(max(0, n), 0);         for (int i = 0; i < (int)a.size(); i++) {           for (int j = 0; j < (int)b.size(); j++) {             c[i + j] = (1LL * a[i] * b[j] + c[i + j]) % mod;           }         }         while (c.size() && c.back() == 0) c.pop_back();       }       int nn = 1, lg = 0;       while (nn < n) {         nn <<= 1;         lg++;       }       c.resize(nn);       a.resize(nn, 0);       b.resize(nn, 0);       ntt(a, 0, lg);       ntt(b, 0, lg);       for (int i = 0; i < nn; i++) {         c[i] = 1LL * a[i] * b[i] % mod;       }       ntt(c, 1, lg);       while (c.size() && c.back() == 0) c.pop_back();     }     void sqr(vector<int> &a) {       int n = (int)a.size() + a.size() - 1;       int nn = 1, lg = 0;       while (nn < n) {         nn <<= 1;         lg++;       }       a.resize(nn, 0);       ntt(a, 0, lg);       for (int i = 0; i < nn; i++) {         a[i] = 1LL * a[i] * a[i] % mod;       }       ntt(a, 1, lg);       while (a.size() && a.back() == 0) a.pop_back();     }     vector<Int> multiply(const vector<Int> &a, const vector<Int> &b) {       vector<int> ta(a.size()), tb(b.size());       for (int i = 0; i < (int)a.size(); i++) ta[i] = a[i].x;       for (int i = 0; i < (int)b.size(); i++) tb[i] = b[i].x;       vector<int> tc;       multiply(ta, tb, tc);       vector<Int> c(tc.size());       for (int i = 0; i < (int)c.size(); i++) c[i].x = tc[i];       return c;     }     NTT() {       w[0] = 1;       int ur = fastpow(g, (mod - 1) >> LogN);       for (int i = 1; i <= MaxN; i++) {         w[i] = 1LL * w[i - 1] * ur % mod;       }     }   };   using namespace std;   int n, k;   int fac[30005];   int ifac[30005];   inline int fastpow(long long basic, int x) {     long long res = 1;     while (x) {       if (x & 1) (res *= basic) %= mod;       (basic *= basic) %= mod;       x >>= 1;     }     return res;   }   vector<int> Ex;   vector<int> Ex1;   inline int fastpow(long long basic, int x, int mod) {     long long res = 1;     while (x) {       if (x & 1) (res *= basic) %= mod;       (basic *= basic) %= mod;       x >>= 1;     }     return res;   }   template <int mod>   struct MTT {     NTT<998244353, 3, 17> ntt1;     NTT<469762049, 3, 17> ntt2;     NTT<1004535809, 3, 17> ntt3;     static const int p1 = 998244353;     static const int p2 = 469762049;     static const int p3 = 1004535809;     vector<int> c1, c2, c3;     inline void multiply(vector<int> a, vector<int> b, vector<int> &c) {       ntt1.multiply(a, b, c1);       ntt2.multiply(a, b, c2);       ntt3.multiply(a, b, c3);       c.clear();       int n = max({c1.size(), c2.size(), c3.size()});       c1.resize(n, 0);       c2.resize(n, 0);       c3.resize(n, 0);       c.resize(n);       for (int i = 0; i < n; i++) {         int x = c1[i];         int y = c2[i];         int z = c3[i];         long long t =             (1LL * (x - y + p1) * fastpow(p2, p1 - 2, p1) % p1 * p2 + y);         c[i] = (1LL * ((z - t) % p3 + p3) % p3 * fastpow(p2, p3 - 2, p3) % p3 *                     fastpow(p1, p3 - 2, p3) % p3 * p1 % mod * p2 % mod +                 t % mod) %                mod;       }     }   };   MTT<mod> mtt;   inline void multiply(vector<int> a, vector<int> b, vector<int> &c) {     mtt.multiply(a, b, c);   }   inline vector<int> replacex(vector<int> x, int len) {     int v = fastpow(2, len);     for (int i = 0; i < x.size(); i++) {       x[i] = 1LL * x[i] * fastpow(v, i) % mod;     }     return x;   }   vector<int> fastpow(int n) {     vector<int> res;     res.push_back(1);     int len = 0;     for (int i = 14; i >= 0; i--) {       if ((1 << i) & n) multiply(replacex(res, 1), Ex1, res), len++;       if (i) multiply(replacex(res, len), res, res), len <<= 1;       if (res.size() > k) res.resize(k + 1);     }     return res;   }   int main() {     fac[0] = 1;     for (int i = 1; i <= 30000; i++) fac[i] = 1LL * fac[i - 1] * i % mod;     for (int i = 0; i <= 30000; i++) ifac[i] = fastpow(fac[i], mod - 2);     long long _n;     cin >> _n >> k;     if (_n > k) {       cout << 0 << endl;       exit(0);     };     n = _n;     for (int i = 0; i <= k; i++) Ex.push_back(ifac[i]);     Ex1 = Ex;     Ex1[0] = 0;     vector<int> v = fastpow(n);     multiply(v, Ex, v);     cout << 1LL * v[k] * fac[k] % mod << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200010;   const int INF = 1;   const double eps = 1e-10;   int N, M, T = INF, Cases = 0;   int arr[MAXN];   char a[MAXN], b[MAXN];   long long zeros[MAXN], ones[MAXN];   int main() {     while (T-- && gets(a + 1) && gets(b + 1)) {       a[0] = b[0] =  ? ;       N = strlen(a) - 1;       M = strlen(b) - 1;       memset(ones, 0, sizeof(ones));       memset(zeros, 0, sizeof(zeros));       for (int i = 1; i <= M; i++) {         if (b[i] ==  1 )           ones[i] = ones[i - 1] + 1, zeros[i] = zeros[i - 1];         else           ones[i] = ones[i - 1], zeros[i] = zeros[i - 1] + 1;       }       int sp = M - N;       long long ans = 0;       for (int i = 1; i <= N; i++) {         int j = i + sp;         if (a[i] ==  0 )           ans += ones[j] - ones[i - 1];         else           ans += zeros[j] - zeros[i - 1];       }       printf( %I64d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   namespace io {   const int L = (1 << 20) + 1;   char buf[L], *S, *T, c;   char getchar() {     if (__builtin_expect(S == T, 0)) {       T = (S = buf) + fread(buf, 1, L, stdin);       return (S == T ? EOF : *S++);     }     return *S++;   }   int inp() {     int x = 0, f = 1;     char ch;     for (ch = getchar(); !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -1;     for (; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar())       ;     return x * f;   }   unsigned inpu() {     unsigned x = 0;     char ch;     for (ch = getchar(); !isdigit(ch); ch = getchar())       ;     for (; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar())       ;     return x;   }   long long inp_ll() {     long long x = 0;     int f = 1;     char ch;     for (ch = getchar(); !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -1;     for (; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar())       ;     return x * f;   }   char B[25], *outs = B + 20, *outr = B + 20;   template <class T>   inline void print(register T a, register char x = 0) {     if (x) *--outs = x, x = 0;     if (!a)       *--outs =  0 ;     else       while (a) *--outs = (a % 10) + 48, a /= 10;     if (x) *--outs = x;     fwrite(outs, outr - outs, 1, stdout);     outs = outr;   }   };  // namespace io   using io ::inp;   using io ::inp_ll;   using io ::inpu;   using io ::print;   using i32 = int;   using i64 = long long;   using u8 = unsigned char;   using u32 = unsigned;   using u64 = unsigned long long;   using f64 = double;   using f80 = long double;   long long power(long long a, long long b, long long p) {     if (!b) return 1;     long long t = power(a, b / 2, p);     t = t * t % p;     if (b & 1) t = t * a % p;     return t;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   template <class T>   inline void freshmin(T &a, const T &b) {     if (a > b) a = b;   }   template <class T>   inline void freshmax(T &a, const T &b) {     if (a < b) a = b;   }   const int MAXN = 100000;   const int DEG = 5;   const int BASE = 10;   const int MAXP = 10000000;   const int MOD = 1000000007;   const f80 MI = f80(1) / MOD;   const long long INF = 10000000000000000LL;   const long long inf = 5000000000000LL;   int n;   int modBASE[1111], modDEG[1111];   template <class T>   struct node {     T v[DEG];     node(T c = 0, int k = 0) {       for (int i = 0; i < DEG; ++i) v[i] = 0;       v[k] = c;     }     node &operator+=(const node &A) {       for (int i = 0; i < DEG; ++i) v[i] += A.v[i];       return *this;     }     friend node operator*(const node &A, const node &B) {       node ret;       for (int i = 0; i < DEG; ++i)         for (int j = 0; j < DEG; ++j) ret.v[modDEG[i + j]] += A.v[i] * B.v[j];       return ret;     }     node &operator*=(const node &A) { return *this = *this * A; }     node shl(int shift) {       node ret;       for (int i = 0; i < DEG; ++i)         ret.v[modDEG[i + shift]] = (shift & 1) ? -v[i] : v[i];       return ret;     }   };   template <class T, class V>   T power(T a, V n) {     if (n == 0) return 1;     T t = power(a, n / 2);     t = t * t;     if (n & 1) t = t * a;     return t;   }   node<u64> a[MAXN];   void fft(bool inv = 0) {     int shift = inv ? BASE - 1 : 1;     for (int step = 1; step < MAXN; step *= BASE) {       for (int offset = 0; offset < MAXN; ++offset) {         if (offset / step % BASE != 0) continue;         node<u64> to[BASE];         for (int i = 0; i < BASE; ++i)           for (int j = 0; j < BASE; ++j)             to[i] += a[offset + j * step].shl(modBASE[i * j * shift]);         for (int i = 0; i < BASE; ++i) a[offset + i * step] = to[i];       }     }   }   int main() {     for (int i = 0; i < 1111; ++i) {       modBASE[i] = i % BASE;       modDEG[i] = i % DEG;     }     n = inp();     for (int i = 1; i <= n; ++i) a[inp()] += 1;     fft();     for (int i = 0; i < MAXN; ++i) a[i] = power(a[i], n);     fft(1);     for (int i = 0; i < n; ++i) {       u64 ans = a[i].v[0] - a[i].v[4];       ans >>= 5;       ans *= 6723469279985657373ULL;       print(ans & ((1ULL << 58) - 1),   n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int SIZE = 1000;   long long a, b, p, x;   long long qpow(long long x, long long y, long long MOD) {     long long res = 1;     while (y) {       if (y & 1) res = (res * x) % MOD;       x = (x * x) % MOD;       y = y >> 1;     }     return res;   }   int main() {     scanf( %lld%lld%lld%lld , &a, &b, &p, &x);     long long ans = 0;     for (long long i = 1; i < p; i++) {       long long tp = qpow(a, i, p);       long long invt = qpow(tp, p - 2, p);       long long invp = qpow(p - 1, p - 2, p);       long long y = ((b * invt - i + p) % p * invp) % p;       long long ty = (x - i) / (p - 1);       if (i + y * (p - 1) > x) continue;       long long anst = (ty - y) / p + 1;       ans = ans + anst;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const int mod = 1e9 + 7;   long long int powmod(long long int a, long long int b) {     long long int res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   int nxt() {     int x;     scanf( %d , &x);     return x;   }   class FenwickTree {    public:     vector<int> ft;     FenwickTree(int n) { ft.assign(n + 1, 0); }     int rsq(int b) {       int sum = 0;       for (; b; b -= (b & (-b))) sum += ft[b];       return sum;     }     int rsq(int a, int b) { return rsq(b) - (a == 1 ? 0 : rsq(a - 1)); }     void adjust(int k, int v) {       for (; k < (int)ft.size(); k += (k & (-k))) ft[k] += v;     }   };   void cnt(int l, int r) {}   void add(int l) {}   void rmv(int l) {}   int main() {     long long int n, k;     cin >> n >> k;     vector<int> a(n), b(n);     for (int i = 0; i < n; i++) {       a[i] = nxt();       b[i] = a[i];     }     sort((b).begin(), (b).end());     for (int i = 0; i < n; i++) {       a[i] = lower_bound((b).begin(), (b).end(), a[i]) - b.begin() + 1;     }     FenwickTree ft(n), ft2(n);     long long int cnt = 0;     for (int i = 0; i < n; i++) {       cnt += (long long int)ft2.rsq(a[i] + 1, n);       ft2.adjust(a[i], 1);     }     if (cnt <= k) {       printf( %lld n , n * (n - 1) / 2);       return 0;     }     int pr = 0;     long long int tmp = cnt;     cnt = 0;     for (int i = 0; i < n; i++) {       tmp += ft.rsq(a[i] + 1, n);       tmp += ft2.rsq(a[i] - 1);       ft.adjust(a[i], 1);       while (tmp > k && pr <= n - 1) {         tmp -= ft.rsq(a[pr] + 1, n);         tmp -= ft2.rsq(a[pr] - 1);         ft2.adjust(a[pr], -1);         pr++;       }       cnt += max(0LL, n - pr);     }     printf( %lld n , cnt);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx )   using namespace std;   using ll = int64_t;   const size_t kBuben = 10;   const int kNone = -1;   struct Pair {     int value, count;   };   struct ByValue {     inline bool operator()(const Pair& a, const Pair& b) const {       return a.value < b.value;     }   };   struct ByCount {     inline bool operator()(const Pair& a, const Pair& b) const {       if (a.count != b.count) return a.count > b.count;       return a.value < b.value;     }   };   struct Segment {     Segment* l;     Segment* r;     array<Pair, kBuben> top;     int len, middle, value_to_push;     Segment(int length) {       l = r = nullptr;       len = length;       clear();     }     inline void clear() {       value_to_push = kNone;       top.fill(Pair{kNone, 0});     }     inline void assign(int value) {       clear();       top[0] = Pair{value, len};       value_to_push = value;     }     inline void rebuild(const Segment& a, const Segment& b) {       array<Pair, 2 * kBuben> result;       array<Pair, kBuben> add;       size_t add_count = 0;       result.fill(Pair{kNone, 0});       add.fill(Pair{kNone, 0});       copy(a.top.begin(), a.top.end(), result.begin());       sort(result.begin(), result.end(), ByValue());       for (const auto& segment : b.top) {         auto it = lower_bound(result.begin(), result.end(), segment, ByValue());         if (it == result.end() || it->value != segment.value) {           add[add_count++] = segment;         } else {           it->count += segment.count;         }       }       copy(add.begin(), add.begin() + add_count, result.begin());       sort(result.begin(), result.end(), ByCount());       copy(result.begin(), result.begin() + kBuben, top.begin());     }   };   Segment* root;   inline bool push(Segment* current) {     if (current->value_to_push != kNone) {       current->l->assign(current->value_to_push);       current->r->assign(current->value_to_push);       current->value_to_push = kNone;       return true;     } else {       return false;     }   }   inline int get_rand(int l, int r) { return l + (rand() % (r - l + 1)); }   Segment* build(int l, int r, const vector<int>& values) {     Segment* current = new Segment(r - l + 1);     if (l == r) {       current->assign(values[l]);     } else {       int m = (l + r) / 2;       current->middle = m;       current->l = build(l, m, values);       current->r = build(m + 1, r, values);       current->rebuild(*current->l, *current->r);     }     return current;   }   void assign(Segment* current, int l, int r, int tl, int tr, int value) {     if (l == tl && r == tr) {       current->assign(value);     } else {       push(current);       int m = current->middle;       if (tl <= m) assign(current->l, l, m, tl, min(m, tr), value);       if (tr > m) assign(current->r, m + 1, r, max(m + 1, tl), tr, value);       current->rebuild(*current->l, *current->r);     }   }   bool get(Segment* current, int l, int r, int tl, int tr, vector<Pair>& bests) {     if (l == tl && r == tr) {       for (const auto& p : current->top) {         bests.push_back(p);       }       return false;     } else {       bool pushed = push(current);       int m = current->middle;       if (tl <= m) pushed |= get(current->l, l, m, tl, min(m, tr), bests);       if (tr > m) pushed |= get(current->r, m + 1, r, max(m + 1, tl), tr, bests);       if (pushed) current->rebuild(*current->l, *current->r);       return pushed;     }   }   int main() {     srand(1224);     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n, m, P;     cin >> n >> m >> P;     int k = 100 / P;     vector<int> values(n);     for (int i = 0; i < n; i++) {       cin >> values[i];     }     root = build(0, n - 1, values);     vector<Pair> bests;     vector<Pair> result;     for (int i = 0; i < m; i++) {       int type, l, r, id;       cin >> type >> l >> r;       --l, --r;       if (type == 1) {         cin >> id;         assign(root, 0, n - 1, l, r, id);       } else {         bests.clear();         get(root, 0, n - 1, l, r, bests);         sort(bests.begin(), bests.end(), ByValue());         result.clear();         int i = 0;         while (i < bests.size()) {           int j = i, cnt = 0;           while (j < bests.size() && bests[i].value == bests[j].value) {             cnt += bests[j].count;             ++j;           }           result.push_back(Pair{bests[i].value, cnt});           i = j;         }         sort(result.begin(), result.end(), ByCount());         result.resize(k);         cout << k;         for (const auto& x : result) {           cout <<     << x.value;         }         cout <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   const int maxn = 1e5 + 15;   const int inf = 1e9;   const int maxe = 200000;   vector<int> vec[maxn];   int small[maxn];   int same[maxn];   int a[maxn];   int N;   void init(int n) {     for (int i = 1; i <= n; i++)       for (int j = i; j <= n; j += i) vec[j].push_back(i);     for (int i = 1; i <= n; i++) {       small[i] = lower_bound(a, a + N, i) - a;       same[i] = upper_bound(a, a + N, i) - a - small[i];     }   }   long long powmod(long long a, long long b, long long mod) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % mod;       a = a * a % mod;       b = b / 2;     }     return ans;   }   int main() {     int maxx = 0;     ;     scanf( %d , &N);     for (int i = 0; i < N; i++) {       scanf( %d , &a[i]);       maxx = max(maxx, a[i]);     }     sort(a, a + N);     init(maxx);     long long sum = 1;     for (int i = maxx; i > 1; i--) {       long long ans = 1;       int len = vec[i].size();       for (int j = 0; j < len - 1; j++) {         int now = vec[i][j];         int next = vec[i][j + 1];         int cnt = small[next] - small[now];         ans = ans * powmod(j + 1, cnt, mod) % mod;       }       int cnt = N - small[vec[i][len - 1]];       ans = ans *             ((powmod(len, cnt, mod) - powmod(len - 1, cnt, mod) + mod) % mod) %             mod;       sum = (sum + ans) % mod;     }     printf( %lld n , sum);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 100;   vector<int> v[maxn];   int childsNo[maxn];   double expected_finish_time[maxn];   void dfs_calc_number_of_childs(int vert, int par) {     for (int i = 0; i < v[vert].size(); i++) {       int child = v[vert][i];       if (child != par) {         dfs_calc_number_of_childs(child, vert);         childsNo[vert] += childsNo[child];       }     }     childsNo[vert] += 1;   }   void dfs_calc_expected_finish_time(int vert, int par) {     for (int i = 0; i < v[vert].size(); i++) {       int child = v[vert][i];       if (child != par) {         expected_finish_time[child] =             expected_finish_time[vert] + 1 +             (childsNo[vert] - childsNo[child] - 1) / 2.0;         dfs_calc_expected_finish_time(child, vert);       }     }   }   int main() {     int n;     cin >> n;     for (int i = 2; i <= n; i++) {       int p;       cin >> p;       v[p].push_back(i);       v[i].push_back(p);     }     dfs_calc_number_of_childs(1, -1);     expected_finish_time[1] = 1;     dfs_calc_expected_finish_time(1, -1);     for (int i = 1; i <= n; i++) cout << expected_finish_time[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char op;   char s[200100];   int n;   int ans;   char c;   int tam;   set<char> good, bad;   set<char>::iterator it;   bool ok = false;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf(  %c %s , &op, s);       tam = strlen(s);       if (!ok) {         if (op ==  . ) {           for (int j = 0; j < tam; ++j) {             good.insert(s[j]);             if (bad.count(s[j])) {               bad.erase(s[j]);             }           }         }         if (op ==  ! ) {           if (bad.size() == 0) {             for (int j = 0; j < tam; ++j) {               if (!good.count(s[j])) {                 bad.insert(s[j]);               }             }             for (char j =  a ; j <=  z ; ++j) {               if (!bad.count(j)) {                 good.insert(j);               }             }           } else {             set<char> aux;             for (int j = 0; j < tam; ++j) {               aux.insert(s[j]);             }             vector<char> rem;             for (it = bad.begin(); it != bad.end(); ++it) {               if (!aux.count(*it)) {                 rem.push_back(*it);               }             }             for (int i = 0; i < rem.size(); ++i) {               bad.erase(rem[i]);               good.insert(rem[i]);             }             for (char j =  a ; j <=  z ; ++j) {               if (!bad.count(j) && !aux.count(j)) {                 good.insert(j);               }             }           }         }         if (op ==  ? ) {           good.insert(s[0]);           if (bad.count(s[0])) {             bad.erase(s[0]);           }         }         if (bad.size() == 1) {           ok = true;           c = *bad.begin();         } else if (good.size() == 25) {           for (char j =  a ; j <=  z ; ++j) {             if (!good.count(j)) {               ok = true;               c = j;               break;             }           }         }       } else {         if (op ==  ! ) ans++;         if (op ==  ?  && i < n - 1) ans++;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int x[5001];   int ans[5001][5001];   int init() {     int i, j;     for (i = 1; i <= n; i++) ans[i][1] = x[i];     for (j = 2; j <= n; j++) {       for (i = 1; i + j - 1 <= n; i++)         ans[i][j] = ans[i][j - 1] ^ ans[i + 1][j - 1];     }     for (j = 2; j <= n; j++)       for (i = 1; i + j - 1 <= n; i++)         ans[i][j] = max(max(ans[i][j], ans[i][j - 1]), ans[i + 1][j - 1]);     return 0;   }   int main() {     int i;     cin >> n;     for (i = 1; i <= n; i++) cin >> x[i];     init();     int j, k, p, q;     cin >> k;     while (k--) {       cin >> p >> q;       cout << ans[p][q - p + 1] << endl;     }     return 0;   }