#include <bits/stdc++.h>   using namespace std;   std::mt19937 rnd(       (int)std::chrono::steady_clock::now().time_since_epoch().count());   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   const int MOD = 1000000007;   void inc(int& a, int b) {     if ((a += b) >= MOD) a -= MOD;   }   void dec(int& a, int b) { inc(a, MOD - b); }   int qx, qy, xdim, ydim;   int inv[6 + 1];   int calcformula(int x, int y) {     int ret = max(max((x + 1) / 2, (y + 1) / 2), (x + y + 2) / 3);     if (ret % 2 != (x + y) % 2) ++ret;     return ret;   }   int calc(int x, int y) {     if (x == 1 && y == 0 || x == 0 && y == 1) return 3;     if (x == 1 && y == 1) return xdim > 3 || ydim > 3 ? 4 : 0;     if (x == 2 && y == 2) return 4;     if (x == 3 && y == 0 && xdim == 4 || x == 0 && y == 3 && ydim == 4) return 5;     return calcformula(x, y);   }   int divup(int num, int den) {     if (den < 0) num = -num, den = -den;     return num >= 0 ? (num + den - 1) / den : num / den;   }   int divdn(int num, int den) {     if (den < 0) num = -num, den = -den;     return num >= 0 ? num / den : (num - den + 1) / den;   }   int makesamepar(int a, int b) {     if ((a & 1) != (b & 1)) ++a;     return a;   }   int cnt(int lo, int hi) { return hi - lo + 1; }   int sum(int lo, int hi) {     return (long long)(lo + hi) * (hi - lo + 1) / 2 % MOD;   }   int sumsq(int n) {     return (long long)n * (n + 1) % MOD * (2 * n + 1) % MOD * inv[6] % MOD;   }   int sumsq(int lo, int hi) {     int ret = 0;     inc(ret, sumsq(hi));     if (lo != 0) dec(ret, sumsq(lo - 1));     return ret;   }   int calcsumstupid(int xlim, int ylim) {     int ret = 0;     for (int x = (0); x <= (xlim); ++x)       for (int y = (0); y <= (ylim); ++y) inc(ret, calc(x, y));     return ret;   }   int calcsum(int xlim, int ylim) {     int ret = 0;     for (int dx = (0); dx < (12); ++dx)       if (dx <= xlim)         for (int dy = (0); dy < (6); ++dy)           if (dy <= ylim) {             int A = (xlim - dx) / 12, B = (ylim - dy) / 6,                 D = divup(divup(dx, 2) - divup(dx + dy, 3), 2) - 1,                 E = makesamepar(divup(dx, 2), dx + dy);             int cur = 0;             {               int xlo = max(0, B - D), xhi = A, ylo = 0, yhi = B;               if (xlo <= xhi && ylo <= yhi) {                 cur = (cur + (long long)cnt(xlo, xhi) * cnt(ylo, yhi) % MOD * E) %                       MOD;                 cur = (cur + (long long)cnt(ylo, yhi) * sum(xlo, xhi) % MOD * 6) %                       MOD;               }             }             {               int xlo = max(0, -D), xhi = min(A, B - D - 1);               if (xlo <= xhi) {                 cur = (cur + (long long)cnt(xlo, xhi) * E % MOD * (D + 1)) % MOD;                 cur = (cur + (long long)sum(xlo, xhi) * E) % MOD;                 cur = (cur + (long long)sum(xlo, xhi) * 6 % MOD * (D + 1)) % MOD;                 cur = (cur + (long long)sumsq(xlo, xhi) * 6) % MOD;               }             }             inc(ret, cur);           }     for (int dx = (0); dx < (12); ++dx)       if (dx <= xlim)         for (int dy = (0); dy < (6); ++dy)           if (dy <= ylim) {             int A = (xlim - dx) / 12, B = (ylim - dy) / 6,                 C = divup(divup(dx, 2) - divup(dx + dy, 3), 2),                 D = divup(dx + dy, 3) - divup(dy, 2),                 E = makesamepar(divup(dx + dy, 3), dx + dy);             int cur = 0;             {               int xlo = max(0, divup(B - D, 4)), xhi = A, ylo = 0, yhi = B;               if (xlo <= xhi && ylo <= yhi) {                 cur = (cur + (long long)cnt(xlo, xhi) * cnt(ylo, yhi) % MOD * E) %                       MOD;                 cur = (cur + (long long)cnt(ylo, yhi) * sum(xlo, xhi) % MOD * 4) %                       MOD;                 cur = (cur + (long long)cnt(xlo, xhi) * sum(ylo, yhi) % MOD * 2) %                       MOD;               }             }             {               int xlo = max(0, divup(-D, 4)), xhi = min(A, divup(B - D, 4) - 1);               if (xlo <= xhi) {                 cur = (cur + (long long)cnt(xlo, xhi) * E % MOD * (D + 1)) % MOD;                 cur = (cur + (long long)sum(xlo, xhi) * E % MOD * 4) % MOD;                 cur = (cur + (long long)sumsq(xlo, xhi) * 16) % MOD;                 cur = (cur + (long long)sum(xlo, xhi) * (D + 1) % MOD * 4) % MOD;                 cur = (cur + (long long)sumsq(xlo, xhi) * 16) % MOD;                 cur = (cur + (long long)sum(xlo, xhi) * (2 * D + 1) % MOD * 4) %                       MOD;                 cur = (cur + (long long)cnt(xlo, xhi) * D % MOD * (D + 1)) % MOD;               }             }             {               int xlo = max(0, max(B - C + 1, divup(B - D, 4))), xhi = A, ylo = 0,                   yhi = B;               if (xlo <= xhi && ylo <= yhi) {                 cur = (cur -                        (long long)cnt(xlo, xhi) * cnt(ylo, yhi) % MOD * E % MOD +                        MOD) %                       MOD;                 cur = (cur -                        (long long)cnt(ylo, yhi) * sum(xlo, xhi) % MOD * 4 % MOD +                        MOD) %                       MOD;                 cur = (cur -                        (long long)cnt(xlo, xhi) * sum(ylo, yhi) % MOD * 2 % MOD +                        MOD) %                       MOD;               }             }             {               int xlo = max(0, max(1 - C, divup(C - D - 1, 3))),                   xhi = min(A, B - C);               if (xlo <= xhi) {                 cur = (cur - (long long)cnt(xlo, xhi) * E % MOD * C % MOD + MOD) %                       MOD;                 cur = (cur - (long long)sum(xlo, xhi) * E % MOD + MOD) % MOD;                 cur = (cur - (long long)sumsq(xlo, xhi) * 4 % MOD + MOD) % MOD;                 cur = (cur - (long long)sum(xlo, xhi) * C % MOD * 4 % MOD + MOD) %                       MOD;                 cur = (cur - (long long)sumsq(xlo, xhi) % MOD + MOD) % MOD;                 cur = (cur - (long long)sum(xlo, xhi) * (2 * C - 1) % MOD + MOD) %                       MOD;                 cur = (cur - (long long)cnt(xlo, xhi) * (C - 1) % MOD * C % MOD +                        MOD) %                       MOD;               }             }             {               int xlo = max(0, divup(-D, 4)),                   xhi = min(A, min(divup(B - D, 4) - 1, divup(C - D - 1, 3) - 1));               if (xlo <= xhi) {                 cur = (cur - (long long)cnt(xlo, xhi) * E % MOD * (D + 1) % MOD +                        MOD) %                       MOD;                 cur = (cur - (long long)sum(xlo, xhi) * E % MOD * 4 % MOD + MOD) %                       MOD;                 cur = (cur - (long long)sumsq(xlo, xhi) * 16 % MOD + MOD) % MOD;                 cur = (cur - (long long)sum(xlo, xhi) * (D + 1) % MOD * 4 % MOD +                        MOD) %                       MOD;                 cur = (cur - (long long)sumsq(xlo, xhi) * 16 % MOD + MOD) % MOD;                 cur = (cur -                        (long long)sum(xlo, xhi) * (2 * D + 1) % MOD * 4 % MOD +                        MOD) %                       MOD;                 cur = (cur - (long long)cnt(xlo, xhi) * D % MOD * (D + 1) % MOD +                        MOD) %                       MOD;               }             }             inc(ret, cur);           }     for (int dx = (0); dx < (6); ++dx)       if (dx <= xlim)         for (int dy = (0); dy < (12); ++dy)           if (dy <= ylim) {             int A = (xlim - dx) / 6, B = (ylim - dy) / 12,                 C = divdn(divup(dx + dy, 3) - divup(dy, 2), 2) + 1,                 E = makesamepar(divup(dy, 2), dx + dy);             int cur = 0;             {               int xlo = 0, xhi = min(A, -C), ylo = 0, yhi = B;               if (xlo <= xhi && ylo <= yhi) {                 cur = (cur + (long long)cnt(xlo, xhi) * cnt(ylo, yhi) % MOD * E) %                       MOD;                 cur = (cur + (long long)cnt(xlo, xhi) * sum(ylo, yhi) % MOD * 6) %                       MOD;               }             }             {               int xlo = max(0, -C + 1), xhi = min(A, B - C);               if (xlo <= xhi) {                 cur = (cur + (long long)cnt(xlo, xhi) * E % MOD * (B - C + 1)) %                       MOD;                 cur = (cur - (long long)sum(xlo, xhi) * E % MOD + MOD) % MOD;                 cur = (cur + (long long)cnt(xlo, xhi) * (C + B) % MOD *                                  (B - C + 1) % MOD * 3) %                       MOD;                 cur = (cur -                        (long long)sum(xlo, xhi) * (2 * C - 1) % MOD * 3 % MOD +                        MOD) %                       MOD;                 cur = (cur - (long long)sumsq(xlo, xhi) * 3 % MOD + MOD) % MOD;               }             }             inc(ret, cur);           }     vector<pair<int, int>> special;     special.push_back(make_pair(1, 0));     special.push_back(make_pair(0, 1));     special.push_back(make_pair(1, 1));     special.push_back(make_pair(3, 0));     special.push_back(make_pair(0, 3));     special.push_back(make_pair(2, 2));     for (int i = (0); i < (((int)(special).size())); ++i) {       int x, y;       tie(x, y) = special[i];       if (x <= xlim && y <= ylim) {         dec(ret, calcformula(x, y));         inc(ret, calc(x, y));       }     }     return ret;   }   void precalc() {     inv[1] = 1;     for (int i = (2); i <= (6); ++i)       inv[i] = (long long)(MOD - MOD / i) * inv[MOD % i] % MOD;   }   int solve() {     int ret = 0;     inc(ret, calcsum(xdim - 1, ydim - 1));     dec(ret, calcsum(xdim - 1, qy - 1));     dec(ret, calcsum(qx - 1, ydim - 1));     inc(ret, calcsum(qx - 1, qy - 1));     return ret;   }   void run() {     scanf( %d%d%d%d , &qx, &qy, &xdim, &ydim);     --qx, --qy;     printf( %d n , solve());   }   void verifycalc() {     for (xdim = 3; xdim <= 20; ++xdim)       for (ydim = 3; ydim <= 20; ++ydim) {         vector<vector<int>> d(xdim, vector<int>(ydim, INT_MAX));         queue<pair<int, int>> q;         d[0][0] = 0, q.push(make_pair(0, 0));         while (!q.empty()) {           int x, y;           tie(x, y) = q.front();           q.pop();           for (int dx = (-2); dx <= (+2); ++dx)             for (int dy = (-2); dy <= (+2); ++dy)               if (dx * dx + dy * dy == 5) {                 int nx = x + dx, ny = y + dy;                 if (nx < 0 || nx >= xdim || ny < 0 || ny >= ydim) continue;                 if (d[nx][ny] == INT_MAX)                   d[nx][ny] = d[x][y] + 1, q.push(make_pair(nx, ny));               }         }         for (int x = (0); x < (xdim); ++x)           for (int y = (0); y < (ydim); ++y)             if (d[x][y] == INT_MAX) {               assert(xdim == 3 && ydim == 3 && x == 1 && y == 1);               d[x][y] = 0;             }         for (int x = (0); x < (xdim); ++x)           for (int y = (0); y < (ydim); ++y) assert(d[x][y] == calc(x, y));         printf( done (%d,%d) n , xdim, ydim);       }   }   void verifysum() {     for (xdim = 3; xdim <= 100; ++xdim) {       for (ydim = 3; ydim <= 100; ++ydim)         for (int dx = (1); dx <= (min(xdim, 3)); ++dx)           for (int dy = (1); dy <= (min(ydim, 3)); ++dy) {             int have = calcsum(xdim - dx, ydim - dy);             int want = calcsumstupid(xdim - dx, ydim - dy);             assert(have == want);           }       printf( done xdim=%d n , xdim);     }   }   int main() {     precalc();     int ncase;     scanf( %d , &ncase);     for (int i = (1); i <= (ncase); ++i) run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     char t[n + 1];     scanf( %s , t);     int i = 0, k = 1;     while (t[i] !=   0 ) {       printf( %c , t[i]);       i = i + k;       k++;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long INFF = 0x3f3f3f3f3f3f3f3fll;   const long long M = 1e9 + 7;   const long long maxn = 1e6 + 7;   const double pi = acos(-1.0);   const double eps = 0.00000001;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   template <typename T>   inline T abs(T a) {     return a > 0 ? a : -a;   }   template <typename T>   inline T powMM(T a, T b) {     T ret = 1;     for (; b; b >>= 1ll, a = (long long)a * a % M)       if (b & 1) ret = (long long)ret * a % M;     return ret;   }   int A[maxn];   map<int, int> S;   vector<int> del, ini[2], have[2];   int cnt[2], ans;   int main() {     int n, m, i, j;     scanf( %d%d , &n, &m);     m = min(m, n * 2);     for (i = 1; i <= n; i++) scanf( %d , &A[i]);     for (i = 1; i <= n; i++) {       if (S.count(A[i])) {         del.push_back(i);         ans++;       } else {         S[A[i]] = i, cnt[A[i] & 1]++;         ini[A[i] & 1].push_back(i);       }     }     for (i = 0; i < 2; i++) {       sort(ini[i].begin(), ini[i].end());       for (j = 0; j < (int)ini[i].size() - n / 2; j++) {         S.erase(A[ini[i][j]]);         cnt[i]--;         ans++;         del.push_back(ini[i][j]);       }     }     j = 0;     for (i = 1; i <= m; i++) {       if (!S.count(i)) {         if (cnt[i & 1] != n / 2) {           cnt[i & 1]++;           A[del[j++]] = i;         }       }     }     if (cnt[0] != n / 2 || cnt[1] != n / 2) return 0 * puts( -1 );     printf( %d n , ans);     for (i = 1; i <= n; i++) printf( %d  , A[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, mn, mx, ans = 0;     cin >> n >> a;     mn = mx = a;     for (int i = 1; i < n; i++) {       cin >> a;       if (a < mn) {         mn = a;         ans++;       }       if (a > mx) {         mx = a;         ans++;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   inline int gi() {     char tmp = getchar();     int ans = 0, flag = 1;     while (!isdigit(tmp)) {       if (tmp ==  - ) flag = -1;       tmp = getchar();     }     while (isdigit(tmp)) {       ans = ans * 10 + tmp -  0 ;       tmp = getchar();     }     return ans * flag;   }   inline void in(int &x) { x = gi(); }   inline void in2(int &x, int &y) { in(x), in(y); }   inline void in3(int &x, int &y, int &z) { in(x), in(y), in(z); }   inline void in4(int &x, int &y, int &z, int &a) { in3(x, y, z), in(a); }   inline void smax(int &x, int y) { x = max(x, y); }   inline void smin(int &x, int y) { x = min(x, y); }   int lowbit(int x) { return x & -x; }   const int N = 1002000;   int C[N], n, maxx;   void Add(int x, int v) {     while (x <= maxx) {       smax(C[x], v);       x += lowbit(x);     }   }   int Query(int x) {     int ans = 0;     while (x) {       smax(ans, C[x]);       x -= lowbit(x);     }     return ans;   }   struct Nod {     int x, y;   } Node[N];   bool cmp(Nod a, Nod b) {     if (a.y != b.y) return a.y < b.y;     return a.x < b.x;   }   signed main() {     int n = gi();     for (int i = (int)(1); i <= (int)(n); ++i) {       Node[i].x = gi();       Node[i].y = i - Node[i].x;       smax(maxx, Node[i].x);     }     sort(Node + 1, Node + n + 1, cmp);     int ans = 0;     for (int i = (int)(1); i <= (int)(n); ++i) {       if (Node[i].y < 0) continue;       int g = Query(Node[i].x - 1);       Add(Node[i].x, g + 1);       smax(ans, g + 1);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     map<string, string> hh;     map<string, string>::iterator it;     int n;     string a, b, c;     cin >> n;     while (n--) {       cin >> a >> b;       it = hh.find(a);       if (it == hh.end())         hh[b] = a;       else {         c = it->second;         hh.erase(it);         hh[b] = c;       }     }     cout << hh.size() << endl;     for (it = hh.begin(); it != hh.end(); it++)       cout << it->second <<     << it->first << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, c[23][23], d[23], u[23];   int main() {     scanf( %d%d , &n, &m);     for (int xt, yt, i = 1; i <= m; ++i) {       scanf( %d%d , &xt, &yt);       if (c[xt][yt] || xt == yt) continue;       ++d[xt], ++d[yt];       c[xt][yt] = c[yt][xt] = 1;     }     for (int j, co, p, mint, i = 1; i <= n; ++i) {       fill(u, u + n + 1, 0);       co = 0;       for (j = i; !u[j]; j = p) {         mint = n + n;         p = j;         u[j] = 1;         ++co;         for (int k = 1; k <= n; ++k)           if (!u[k] && c[j][k] && (d[k] < mint || d[k] == mint && k < p))             p = k, mint = d[k];       }       if (co == n) {         puts( Yes );         return 0;       }     }     puts( No );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<pair<int, int> > v;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       v.push_back(make_pair(a, i));     }     sort(v.begin(), v.end());     int cur = 0;     vector<int> ans;     for (int i = 0; i < v.size() && cur + v[i].first <= k; i++) {       cur += v[i].first;       ans.push_back(v[i].second);     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) {       cout << ans[i] + 1 <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   bool Check(char x) {     if (x <=  3  && x >=  1 )       return true;     else       return false;   }   int main() {     char s[1000];     cin >> s;     char x;     for (int i = 0; i < strlen(s); ++i) {       for (int j = i + 1; j < strlen(s); ++j) {         if (s[j] < s[i] && Check(s[i]) && Check(s[j])) {           x = s[i];           s[i] = s[j];           s[j] = x;         }       }     }     for (int i = 0; i < strlen(s); i++) {       cout << s[i];     }     return 0;   }


#include <bits/stdc++.h>   using i64 = long long;   std::vector<std::vector<int>> read_tree1(int v) {     std::vector<std::vector<int>> graph(v);     while (v-- > 1) {       int x, y;       std::cin >> x >> y;       graph[x - 1].push_back(y - 1);       graph[y - 1].push_back(x - 1);     }     return graph;   }   template <class T>   std::pair<T, T> ext_euclid(T a, T b) {     if (b == 0) {       return {a > 0 ? +1 : -1, 0};     } else {       auto res = ext_euclid(b, a % b);       return {res.second, res.first - a / b * res.second};     }   }   template <class T>   T mod_inv(T num, T mod) {     num = (num % mod + mod) % mod;     T res = ext_euclid(num, mod).first;     return res < 0 ? res + mod : res;   }   int main() {     std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0);     const i64 MOD = 998244353;     int n;     std::cin >> n;     auto tree = read_tree1(n);     std::function<std::tuple<i64, i64, i64>(int, int)> dfs =         [&](int cur, int prv) -> std::tuple<i64, i64, i64> {       std::vector<std::tuple<i64, i64, i64>> nxts;       for (int nxt : tree[cur])         if (nxt != prv) {           nxts.push_back(dfs(nxt, cur));         }       i64 prod = 1;       for (const auto& [f, g, h] : nxts) {         prod = prod * (f + h) % MOD;       }       i64 F = 1, G = 1, H = 0;       for (const auto& [f, g, h] : nxts) {         F = F * f % MOD;         G = G * (f + h) % MOD;         H = (H + g * mod_inv(f + h, MOD)) % MOD;       }       H = H * prod % MOD;       F = (F + H) % MOD;       return {F, G, H};     };     std::cout << std::get<0>(dfs(0, -1)) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MAXN = 2e5 + 5;   int n, k, d, ansL = 1, ansR = 1, top1, top2, flag, pos;   int a[MAXN], st1[MAXN], st2[MAXN];   map<int, int> lst;   namespace SegmentTree {   struct Tree {     int l, r;     int w, tag;   } tree[MAXN << 2];   void update(int k) { tree[k].w = min(tree[k << 1].w, tree[k << 1 | 1].w); }   void apply(int k, int val) {     tree[k].w += val;     tree[k].tag += val;   }   void down(int k) {     if (tree[k].tag != 0) {       apply(k << 1, tree[k].tag);       apply(k << 1 | 1, tree[k].tag);       tree[k].tag = 0;     }   }   void Build(int k, int l, int r) {     tree[k].l = l;     tree[k].r = r;     if (l == r) {       tree[k].w = l;       return;     }     int mid = (l + r) >> 1;     Build(k << 1, l, mid);     Build(k << 1 | 1, mid + 1, r);     update(k);   }   void Modify(int k, int l, int r, int val) {     if (tree[k].l >= l && tree[k].r <= r) {       apply(k, val);       return;     }     down(k);     int mid = (tree[k].l + tree[k].r) >> 1;     if (l <= mid) Modify(k << 1, l, r, val);     if (r > mid) Modify(k << 1 | 1, l, r, val);     update(k);   }   void Delete(int k, int x) {     if (tree[k].l == tree[k].r) {       tree[k].w = 0;       return;     }     down(k);     int mid = (tree[k].l + tree[k].r) >> 1;     if (x <= mid)       Delete(k << 1, x);     else       Delete(k << 1 | 1, x);     update(k);   }   int Find(int k, int x) {     if (tree[k].l == tree[k].r) return tree[k].l;     down(k);     if (tree[k << 1].w <= x)       return Find(k << 1, x);     else       return Find(k << 1 | 1, x);   }   void Query(int k, int l, int r, int x) {     if (tree[k].l >= l && tree[k].r <= r) {       if (tree[k].w <= x) {         flag = 1;         pos = Find(k, x);       }       return;     }     down(k);     int mid = (tree[k].l + tree[k].r) >> 1;     if (l <= mid && !flag) Query(k << 1, l, r, x);     if (r > mid && !flag) Query(k << 1 | 1, l, r, x);   }   }  // namespace SegmentTree   int main() {     scanf( %d%d%d , &n, &k, &d);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       a[i] += INF;     }     if (d == 0) {       for (int i = 1; i <= n; i++) {         int l = i;         while (a[i] == a[i + 1] && i < n) i += 1;         if (i - l + 1 > ansR - ansL + 1) {           ansL = l;           ansR = i;         }       }       printf( %d %d n , ansL, ansR);       return 0;     }     SegmentTree::Build(1, 1, n);     int L = 1;     for (int R = 1; R <= n; R++) {       int tmp = L;       if (a[R] % d == a[R - 1] % d)         L = max(lst[a[R]] + 1, L);       else         L = R;       lst[a[R]] = R;       while (tmp < L) {         SegmentTree::Delete(1, tmp);         tmp += 1;       }       while (top1 && st1[top1] >= L && a[st1[top1]] >= a[R]) {         SegmentTree::Modify(1, max(L, st1[top1 - 1] + 1), st1[top1],                             a[st1[top1]] / d);         top1 -= 1;       }       SegmentTree::Modify(1, max(L, st1[top1] + 1), R, -a[R] / d);       st1[++top1] = R;       while (top2 && st2[top2] >= L && a[st2[top2]] <= a[R]) {         SegmentTree::Modify(1, max(L, st2[top2 - 1] + 1), st2[top2],                             -a[st2[top2]] / d);         top2 -= 1;       }       SegmentTree::Modify(1, max(L, st2[top2] + 1), R, a[R] / d);       st2[++top2] = R;       flag = 0;       pos = 0;       SegmentTree::Query(1, L, R, k + R);       if (R - pos + 1 > ansR - ansL + 1) {         ansL = pos;         ansR = R;       }     }     printf( %d %d n , ansL, ansR);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void printArray(vector<T> arr) {     for (T a : arr) cout << a <<    ;     cout <<   n ;   }   void printVerdict(bool verdict) { cout << (verdict ?  YES  :  NO ) <<   n ; }   vector<long long> findPrime(long long n) {     vector<long long> ret;     for (int i = 2; i * i <= n && ret.empty(); i++) {       if (n % i == 0) ret.push_back(i);     }     if (ret.empty()) return {};     for (int i = 2; i * i <= n / ret.front(); i++) {       if ((n / ret.front()) % i == 0 && i != ret.front()) {         ret.push_back(i);         break;       }     }     ret.push_back((n / ret.front()) / ret.back());     if (ret.back() == ret[0] || ret.back() == ret[1]) return {};     return ret;   }   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       long long n;       cin >> n;       bool verdict = true;       vector<long long> ret = findPrime(n);       if (ret.empty()) verdict = false;       printVerdict(verdict);       if (verdict) printArray(ret);     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   const long long M = 1e9 + 9;   int n, x, y;   pair<int, int> pos[N];   map<pair<int, int>, int> mp;   set<int> q;   long long ans;   int children(int x, int y) {     int ret = 0;     for (int dx = -1; dx <= 1; dx++) {       map<pair<int, int>, int>::iterator c = mp.find(make_pair(x + dx, y - 1));       if (c != mp.end()) ret++;     }     return ret;   }   void update(int x, int y) {     map<pair<int, int>, int>::iterator p = mp.find(make_pair(x, y));     if (p == mp.end()) return;     for (int dx = -1; dx <= 1; dx++) {       map<pair<int, int>, int>::iterator c = mp.find(make_pair(x + dx, y + 1));       if (c != mp.end() && children(x + dx, y + 1) == 1) {         q.erase(p->second);         return;       }     }     q.insert(p->second);   }   void insert(int x, int y, int z) {     pos[z].first = x;     pos[z].second = y;     mp[make_pair(x, y)] = z;   }   void remove(int x, int y) {     mp.erase(make_pair(x, y));     for (int dx = -1; dx <= 1; dx++) {       update(x + dx, y + 1);       update(x + dx, y - 1);     }     for (int dx = -2; dx <= 2; dx++) {       update(x + dx, y);     }   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x >> y;       insert(x, y, i);     }     for (int i = 0; i < n; i++) {       update(pos[i].first, pos[i].second);     }     for (int act = 0; !q.empty(); act++) {       set<int>::iterator it;       if ((act & 1) == 0) {         it = --q.end();       } else {         it = q.begin();       }       ans = ans * n + (*it);       ans %= M;       remove(pos[*it].first, pos[*it].second);       q.erase(it);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long UNDEF = -1;   const long long INF = 1e18;   template <typename T>   inline bool chkmax(T &aa, T bb) {     return aa < bb ? aa = bb, true : false;   }   template <typename T>   inline bool chkmin(T &aa, T bb) {     return aa > bb ? aa = bb, true : false;   }   long long cross(const pair<long long, long long> &a,                   const pair<long long, long long> &b,                   const pair<long long, long long> &c) {     return (b.first - a.first) * (c.second - a.second) -            (b.second - a.second) * (c.first - a.first);   }   vector<pair<long long, long long> > convexHullAllowStraightEdges(       vector<pair<long long, long long> > points) {     if (points.size() <= 1) return points;     sort(points.begin(), points.end());     vector<pair<long long, long long> > h;     for (auto p : points) {       while (h.size() >= 2 && cross(h.end()[-2], h.back(), p) > 0) h.pop_back();       h.push_back(p);     }     reverse(points.begin(), points.end());     int upper = h.size();     for (auto p : points) {       while (h.size() > upper && cross(h.end()[-2], h.back(), p) > 0)         h.pop_back();       h.push_back(p);     }     h.resize(h.size() - 1 - (h[0] == h[1]));     return h;   }   static char stdinBuffer[1024];   static char *stdinDataEnd = stdinBuffer + sizeof(stdinBuffer);   static const char *stdinPos = stdinDataEnd;   void readAhead(size_t amount) {     size_t remaining = stdinDataEnd - stdinPos;     if (remaining < amount) {       memmove(stdinBuffer, stdinPos, remaining);       size_t sz = fread(stdinBuffer + remaining, 1,                         sizeof(stdinBuffer) - remaining, stdin);       stdinPos = stdinBuffer;       stdinDataEnd = stdinBuffer + remaining + sz;       if (stdinDataEnd != stdinBuffer + sizeof(stdinBuffer)) *stdinDataEnd = 0;     }   }   long long readInt() {     readAhead(16);     long long x = 0;     bool neg = false;     while (*stdinPos ==     || *stdinPos ==   n ) ++stdinPos;     if (*stdinPos ==  - ) {       ++stdinPos;       neg = true;     }     while (*stdinPos >=  0  && *stdinPos <=  9 ) {       x *= 10;       x += *stdinPos -  0 ;       ++stdinPos;     }     return neg ? -x : x;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long n = readInt(), m = readInt();     long long ox = readInt(), oy = readInt();     set<pair<long long, long long> > vmin, vmax;     for (long long i = 0; i < n; i++) {       long long x = readInt(), y = readInt();       vmax.insert(make_pair(x, y));     }     long long xhi = 0, yhi = 0;     for (long long i = 0; i < m; i++) {       long long x = readInt(), y = readInt();       vmin.insert(make_pair(x, y));       chkmax(xhi, x);       chkmax(yhi, y);     }     set<pair<long long, long long> > toch;     for (auto &w : vmin) toch.insert(w);     for (auto &w : vmax) toch.insert(w);     toch.insert(make_pair(0, 0));     toch.insert(make_pair(xhi, 0));     toch.insert(make_pair(0, yhi));     vector<pair<long long, long long> > vtoch;     for (auto &w : toch) vtoch.push_back(w);     vector<pair<long long, long long> > ch = convexHullAllowStraightEdges(vtoch);     for (auto &w : ch) {       if (vmax.find(w) != vmax.end()) {         printf( Max n );         return 0;       }     }     printf( Min n );   }


#include <bits/stdc++.h>   using namespace std;   static const int INF = 500000000;   template <class T>   void debug(T a, T b) {     for (; a != b; ++a) cerr << *a <<    ;     cerr << endl;   }   string s[2005];   int n, K;   int lcp[2005];   int prof[2005][2005];   struct uf {     int par[2005];     vector<int> dp[2005];     void init(int n) {       for (int i = 0; i < n; ++i) {         dp[i].resize(2);       }       memset(par, -1, sizeof(par));     }     int root(int a) {       if (par[a] == -1) return a;       return par[a] = root(par[a]);     }     void unite(int a, int b, int lb) {       a = root(a);       b = root(b);       vector<int> tmp(dp[a].size() + dp[b].size() - 1);       for (int i = 0; i < dp[a].size(); ++i)         for (int j = 0; j < dp[b].size(); ++j)           tmp[i + j] = max(tmp[i + j], dp[a][i] + dp[b][j] + lb * i * j);       par[a] = b;       dp[b] = tmp;       dp[a].clear();     }   };   uf u;   int used[2005];   int main() {     scanf( %d%d , &n, &K);     for (int i = 0; i < n; ++i) cin >> s[i];     sort(s, s + n);     u.init(n);     for (int i = 0; i < n - 1; ++i) {       int& t = lcp[i];       for (t = 0;            t < s[i].size() && t < s[i + 1].size() && s[i][t] == s[i + 1][t]; ++t)         ;     }     for (int i = 0; i < n - 1; ++i) {       int tallest = -1, ind;       for (int j = 0; j < n - 1; ++j)         if (used[j] == 0 && tallest < lcp[j]) {           tallest = lcp[j];           ind = j;         }       used[ind] = 1;       u.unite(ind, ind + 1, tallest);     }     printf( %d n , u.dp[u.root(0)][K]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int arr[n + 10];     for (int i = 1; i <= n; i++) scanf( %d , &arr[i]);     int start, end;     start = 1;     int pos_1 = -1, pos_2 = -1;     int cnt = 0;     int t = 0;     for (int i = 1; i <= n;) {       pos_1 = -1;       pos_2 = -1;       start = i;       for (int j = start; j <= n; j++) {         if (arr[j] != -1) {           pos_1 = j;           break;         }       }       if (pos_1 != -1) {         for (int j = pos_1 + 1; j <= n; j++)           if (arr[j] != -1) {             pos_2 = j;             break;           }         if (pos_2 == -1) {           cnt++;           break;         }         t++;         if (arr[pos_1] == arr[pos_2]) {           start = pos_2 + 1;           for (int j = pos_2 + 1; j <= n; j++)             if (arr[j] == -1 || arr[j] == arr[pos_1])               start = j + 1;             else {               start = j;               break;             }           cnt++;         } else {           long long val = (arr[pos_2] - arr[pos_1]);           int d = pos_2 - pos_1;           if (val % d == 0) {             int yes = val / d;             val = arr[pos_1];             yes *= (-1);             for (int j = pos_1 - 1; j >= start; j--) {               val += yes;               if (val <= 0) {                 cnt++;                 start = pos_2;                 goto End;               }               if (arr[j] != -1 && arr[j] != val) {                 cnt++;                 start = pos_2;                 goto End;               }             }             val = arr[pos_2];             yes *= (-1);             start = -1;             for (int j = pos_2 + 1; j <= n; j++) {               val += yes;               if (val <= 0) {                 start = j;                 break;               }               if (arr[j] != -1 && arr[j] != val) {                 start = j;                 break;               }             }             if (start == -1) start = n + 1;             cnt++;           } else {             cnt += 1;             start = pos_2;           }         }       } else {         cnt++;         break;       }     End:;       i = start;     }     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct bign {     int len, s[109];     bign() {       memset(s, 0, sizeof(s));       len = 1;     }     bign(int num) { *this = num; }     bign(const char *num) { *this = num; }     bign operator=(const int num) {       char s[109];       sprintf(s,  %d , num);       *this = s;       return *this;     }     bign operator=(const char *num) {       for (int i = 0; num[i] ==  0 ; num++)         ;       len = strlen(num);       for (int i = 0; i < len; i++) s[i] = num[len - i - 1] -  0 ;       return *this;     }     bign operator+(const bign &b) const {       bign c;       c.len = 0;       for (int i = 0, g = 0; g || i < max(len, b.len); i++) {         int x = g;         if (i < len) x += s[i];         if (i < b.len) x += b.s[i];         c.s[c.len++] = x % 10;         g = x / 10;       }       return c;     }     bign operator+=(const bign &b) {       *this = *this + b;       return *this;     }     void clean() {       while (len > 1 && !s[len - 1]) len--;     }     bign operator*(const bign &b) {       bign c;       c.len = len + b.len;       for (int i = 0; i < len; i++) {         for (int j = 0; j < b.len; j++) {           c.s[i + j] += s[i] * b.s[j];         }       }       for (int i = 0; i < c.len; i++) {         c.s[i + 1] += c.s[i] / 10;         c.s[i] %= 10;       }       c.clean();       return c;     }     bign operator*=(const bign &b) {       *this = *this * b;       return *this;     }     bign operator-(const bign &b) {       bign c;       c.len = 0;       for (int i = 0, g = 0; i < len; i++) {         int x = s[i] - g;         if (i < b.len) x -= b.s[i];         if (x >= 0)           g = 0;         else {           g = 1;           x += 10;         }         c.s[c.len++] = x;       }       c.clean();       return c;     }     bign operator-=(const bign &b) {       *this = *this - b;       return *this;     }     bign operator/(const bign &b) {       bign c, f = 0;       for (int i = len - 1; i >= 0; i--) {         f = f * 10;         f.s[0] = s[i];         while (f >= b) {           f -= b;           c.s[i]++;         }       }       c.len = len;       c.clean();       return c;     }     bign operator/=(const bign &b) {       *this = *this / b;       return *this;     }     bign operator%(const bign &b) {       bign r = *this / b;       r = *this - r * b;       return r;     }     bign operator%=(const bign &b) {       *this = *this % b;       return *this;     }     bool operator<(const bign &b) {       if (len != b.len) return len < b.len;       for (int i = len - 1; i >= 0; i--) {         if (s[i] != b.s[i]) return s[i] < b.s[i];       }       return false;     }     bool operator>(const bign &b) {       if (len != b.len) return len > b.len;       for (int i = len - 1; i >= 0; i--) {         if (s[i] != b.s[i]) return s[i] > b.s[i];       }       return false;     }     bool operator==(const bign &b) { return !(*this > b) && !(*this < b); }     bool operator!=(const bign &b) { return !(*this == b); }     bool operator<=(const bign &b) { return *this < b || *this == b; }     bool operator>=(const bign &b) { return *this > b || *this == b; }     string str() const {       string res =   ;       for (int i = 0; i < len; i++) res = char(s[i] +  0 ) + res;       return res;     }   };   map<int, bool> mp;   const int MAX = 5e4 + 5;   int n, m, Tot, tot;   int a[MAX], b[MAX], pm[MAX], pim[MAX];   bool use[MAX];   void dfs(int n, int I = 0, int tot = 0, int qwq = 0) {     if (qwq == n - 1) {       printf( YES n );       printf( %d n , tot);       for (int i = 0; i < tot; ++i) printf( %d %d n , a[i], b[i]);       exit(0);     }     if (mp[qwq]) return;     mp[qwq] = 1;     for (int i = I + 1; i <= Tot; ++i) {       if (i == Tot) {         int qaq = min((int)((long long)(n - 1 - qwq) * pm[i] / n), pm[i] - 1);         if (qwq + n / pm[i] * qaq != n - 1)           continue;         else           a[tot] = qaq, b[tot] = pm[i], dfs(n, i, tot + 1, qwq + n / pm[i] * qaq);       } else {         for (int j = min((int)((long long)(n - 1 - qwq) * (long long)pm[i] /                                (long long)n),                          pm[i] - 1);              j >= 1; --j)           if (qwq + n / pm[i] * j <= n - 1)             a[tot] = j, b[tot] = pm[i], dfs(n, i, tot + 1, qwq + n / pm[i] * j);           else             break;       }     }   }   bool look(int x) {     if (x == 1) return 0;     if (x == 2) return 1;     for (int i = 2; i <= sqrt(x); ++i)       if (x % i == 0) return 0;     return 1;   }   void ss(int *pm) {     use[1] = 1;     for (int i = 2; i <= m; ++i) {       if (!use[i]) pm[++tot] = i;       for (int j = 1; j <= tot && pm[j] * i <= m; ++j) {         use[i * pm[j]] = 1;         if (i % pm[j] == 0) break;       }     }   }   bool work(int x) {     int a = n;     while (a % x == 0) a /= x;     return a == 1;   }   int main() {     scanf( %d , &n), m = sqrt(n);     if (n % 2 == 0 && (n / 2) % 2 == 1 && n != 2) {       cout <<  YES  << endl <<  2  << endl <<  1 2  << endl;       cout << (n / 2 - 1) / 2 <<     << n / 2 << endl;       return 0;     }     if (look(n)) return printf( NO ), 0;     ss(pim);     for (int i = 1; i <= tot; ++i)       if (work(pim[i])) return printf( NO ), 0;     for (int i = 2; i <= m; ++i)       if (n % i == 0) {         pm[++Tot] = i;         if (i != n / i) pm[++Tot] = n / i;       }     if (Tot + 2 < 4) return printf( NO ), 0;     sort(pm + 1, pm + 1 + Tot), dfs(n);     return printf( NO ), 0;   }   istream &operator>>(istream &in, bign &x) {     string s;     in >> s;     x = s.c_str();     return in;   }   ostream &operator<<(ostream &out, const bign &x) {     out << x.str();     return out;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long N = 5e5;   long long id[N], a[N], pos[N];   int main() {     ios_base::sync_with_stdio(false);     long long n, t, m, l, k, ans, i, j, res = 0, fl;     t = 1;     long long x;     while (t--) {       long long o;       cin >> n >> m >> k;       for (i = 0; i < n; i++) {         cin >> a[i];         pos[a[i]] = i;       }       long long ct = 1;       j = 0;       for (o = 0;; o += k) {         for (i = o; i < o + k; ++i) id[a[i]] = ct;         ct++;         if (i > n) break;       }       for (i = 0; i < m; i++) {         cin >> x;         res += id[x];         if (pos[x] > 0) {           long long p = pos[x];           long long val = a[p - 1];           swap(id[x], id[val]);           swap(a[p], a[p - 1]);           pos[x] = p - 1;           pos[val] = p;         }       }       cout << res <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   signed main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long maxai = 0;       multiset<long long> a;       for (long long i = 0; i < n; i++) {         long long ai;         cin >> ai;         a.insert(ai);         if (ai > maxai) maxai = ai;       }       while (maxai != 1 && a.size()) {         long long br = 0;         for (long long i = 1; i <= maxai / 2; i++) {           if (maxai % i != 0) continue;           for (long long k = 1; k < 1010; k++) {             if (k * maxai / i > 1010) break;             long long count = a.count(k * maxai / i);             if (count) {               br = 1;               for (long long j = 0; j < count; j++) cout << k * maxai / i <<    ;               a.erase(k * maxai / i);               maxai = gcd(maxai, k * maxai / i);               break;             }           }           if (br) break;         }         if (!br) break;       }       for (multiset<long long>::iterator i = a.begin(); i != a.end(); i++)         cout << *i <<    ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long Gcd(long long a, long long b) {     if (a % b == 0) return b;     return Gcd(b, a % b);   }   long long Max(long long a, long long b) {     if (a > b) return a;     return b;   }   long long Min(long long a, long long b) {     if (a < b) return a;     return b;   }   long long gcdExtended(long long a, long long b, long long *x, long long *y) {     if (a == 0) {       *x = 0, *y = 1;       return b;     }     long long x1, y1;     long long gcd = gcdExtended(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     return gcd;   }   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long modInverse(long long a, long long m) {     long long x, y;     long long g = gcdExtended(a, m, &x, &y);     if (g != 1)       return -1;     else {       long long res = (x % m + m) % m;       return res;     }   }   vector<int> primeFactors(int n) {     vector<int> v;     while (n % 2 == 0) {       v.push_back(2);       n = n / 2;     }     for (int i = 3; i <= sqrt(n); i = i + 2) {       while (n % i == 0) {         v.push_back(i);         n = n / i;       }     }     if (n > 2) v.push_back(n);     return v;   }   long long C[2001][2000];   void binomialCoeff(long long n, long long k) {     long long i, j;     for (i = 0; i <= n; i++) {       for (j = 0; j <= k; j++) {         if (j == 0 || j == i)           C[i][j] = 1;         else           C[i][j] = (C[i - 1][j - 1] % 1000000007 + C[i - 1][j] % 1000000007) %                     1000000007;       }     }   }   long long spf[100010];   void sieve() {     spf[1] = 1;     for (int i = 2; i < 100010; i++) spf[i] = i;     for (int i = 4; i < 100010; i += 2) spf[i] = 2;     for (int i = 3; i * i < 100010; i++) {       if (spf[i] == i) {         for (int j = i * i; j < 100010; j += i)           if (spf[j] == j) spf[j] = i;       }     }   }   long long binarySearch(long long arr[], long long l, long long r, long long x) {     if (r >= l) {       long long mid = l + (r - l) / 2;       if (arr[mid] == x) return mid;       if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x);       return binarySearch(arr, mid + 1, r, x);     }     return -1;   }   const long long N = 100000;   long long n;   long long tree[2 * N];   void build(long long arr[]) {     for (long long i = 0; i < n; i++) {       tree[n + i] = arr[i];     }     for (long long i = n - 1; i > 0; --i) {       tree[i] = tree[i << 1] + tree[i << 1 | 1];     }   }   void updateTreeNode(long long p, long long value) {     tree[p + n] = value;     p = p + n;     for (long long i = p; i > 1; i >>= 1) {       tree[i >> 1] = tree[i] + tree[i ^ 1];     }   }   long long query(long long l, long long r) {     long long res = 0;     for (l += n, r += n; l < r; l >>= 1, r >>= 1) {       if (l & 1) {         res += tree[l++];       }       if (r & 1) {         res += tree[--r];       }     }     return res;   }   void dfs(std::vector<long long> v[], long long s, bool visited[]) {     visited[s] = true;     for (long long i = 0; i < v[s].size(); ++i) {       if (!visited[v[s][i]]) {         dfs(v, v[s][i], visited);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string x69;     cin >> x69;     long long n = x69.length();     char s[n + 1];     for (int i = 0, _n = (n); i < _n; i++) {       s[i + 1] = x69[i];     }     long long ev = 0;     long long od = 0;     long long ao = 0;     long long ae = 0;     long long bo = 0;     long long be = 0;     for (int i = (1), _b = (n); i <= _b; i++) {       if (s[i] ==  a ) {         if (i % 2) {           od += ao + 1;           ev += ae;         } else {           od += ae + 1;           ev += ao;         }         if (i % 2)           ao++;         else           ae++;       }       if (s[i] ==  b ) {         if (i % 2) {           od += bo + 1;           ev += be;         } else {           od += be + 1;           ev += bo;         }         if (i % 2)           bo++;         else           be++;       }     }     cout << ev <<     << od << endl;     return 0;   }


#include <bits/stdc++.h>   const double EPS = 1e-24;   const long long int MOD = 1000000007ll;   const double PI = 3.14159265359;   int INF = 2147483645;   long long int INFINF = 9223372036854775807;   template <class T>   T Max2(T a, T b) {     return a < b ? b : a;   }   template <class T>   T Min2(T a, T b) {     return a < b ? a : b;   }   template <class T>   T Max3(T a, T b, T c) {     return Max2(Max2(a, b), c);   }   template <class T>   T Min3(T a, T b, T c) {     return Min2(Min2(a, b), c);   }   template <class T>   T Max4(T a, T b, T c, T d) {     return Max2(Max2(a, b), Max2(c, d));   }   template <class T>   T Min4(T a, T b, T c, T d) {     return Min2(Min2(a, b), Max2(c, d));   }   using namespace std;   int n;   int a[110];   int main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     reverse(a, a + n);     int sum = 0, cur = 0;     for (int i = 0; i < n; i++) sum += a[i];     int cnt = 0;     while (cur <= sum / 2) cur += a[cnt++];     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n, m, a, b;       cin >> n >> m >> a >> b;       a--;       b--;       vector<vector<int> > graph(n);       for (int i = 0; i < m; i++) {         int u, v;         cin >> u >> v;         u--;         v--;         graph[u].push_back(v);         graph[v].push_back(u);       }       int x = 0;       vector<bool> vis(n);       function<void(int)> dfs = [&](int u) {         vis[u] = true;         for (int v : graph[u]) {           if (vis[v] || v == x) continue;           dfs(v);         }       };       x = b;       dfs(a);       int cnta = count(vis.begin(), vis.end(), false) - 1;       fill(vis.begin(), vis.end(), false);       x = a;       dfs(b);       int cntb = count(vis.begin(), vis.end(), false) - 1;       cout << (long long)cnta * cntb <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const int M = 0x3f3f3f3f;   long long n, m, k, q, h;   int ld[N], rd[N];   vector<long long> p;   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cin >> n >> m >> k >> q;     vector<vector<long long> > vec(n + 1);     memset(ld, 0x3f, sizeof(ld));     memset(rd, 0x3f, sizeof(rd));     while (k--) {       int x, y;       cin >> x >> y;       vec[x].push_back(y);     }     int f = !vec[1].empty();     vector<vector<long long> > tp = move(vec);     for (int i = 1; i <= n; ++i)       if (!tp[i].empty()) {         h = i;         sort(tp[i].begin(), tp[i].end());         vec.push_back(tp[i]);       }     long long l = (vec[0].back() << 1) - vec[0][0] - 1, r = vec[0].back() - 1,               lp = vec[0][0], rp = vec[0].back();     while (q--) {       int pos;       cin >> pos;       p.push_back(pos);     }     sort(p.begin(), p.end());     for (int i = 1; i <= m; ++i) {       auto tmp = lower_bound(p.begin(), p.end(), i);       if (tmp != p.end())         rd[i] = *tmp - i;       else         rd[i] = M;       tmp = upper_bound(p.begin(), p.end(), i);       if (tmp != p.begin())         ld[i] = i - *(tmp - 1);       else         ld[i] = M;     }     q = vec.size();     if (!f) l = r = rd[1], lp = rp = rd[1] + 1;     for (int i = f; i < q; ++i) {       vector<pair<long long, long long> > pos;       if (ld[lp] ^ M) pos.push_back(make_pair(lp - ld[lp], l + ld[lp]));       if (rd[lp] ^ M) pos.push_back(make_pair(lp + rd[lp], l + rd[lp]));       if (ld[rp] ^ M) pos.push_back(make_pair(rp - ld[rp], r + ld[rp]));       if (rd[rp] ^ M) pos.push_back(make_pair(rp + rd[rp], r + rd[rp]));       l = r = 1e18, lp = vec[i][0], rp = vec[i].back();       for (auto j : pos) {         if (j.first >= rp)           l = min(l, j.second + j.first - lp);         else           l = min(l, j.second + rp - j.first + rp - lp);         if (j.first <= lp)           r = min(r, j.second + rp - j.first);         else           r = min(r, j.second + j.first - lp + rp - lp);       }     }     cout << min(l, r) + h - 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string a;     cin >> a;     char vowels[5] = { a ,  e ,  i ,  o ,  u };     for (int i = 0; i < a.size() - 1; ++i) {       bool flag = false;       for (int k = 0; k < 5; ++k) {         if (a[i] == vowels[k]) {           flag = true;           break;         }       }       if (a[i] ==  n ) flag = true;       if (flag) {         continue;       }       for (int k = 0; k < 5; ++k) {         if (a[i + 1] == vowels[k]) {           flag = true;           break;         }       }       if (flag == false) {         cout <<  NO  << endl;         return 0;       }     }     int n = a.size();     bool flag = false;     for (int k = 0; k < 5; ++k) {       if (a[n - 1] == vowels[k]) {         flag = true;         break;       }     }     if (a[n - 1] ==  n ) flag = true;     if (flag == true)       cout <<  YES  << endl;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   const long long Inf = 0x3f3f3f3f3f3f3f3f;   int n, x, y, z, cnt, tot, head[maxn], vis[maxn];   long long res, r[maxn], l[maxn], l0[maxn], r0[maxn], sum[maxn], ans1,       ans2 = Inf, f[maxn], cir[maxn];   struct Edge {     int to, next, w;   } e[maxn << 1];   void add(int u, int v, int w) {     e[++cnt].to = v;     e[cnt].w = w;     e[cnt].next = head[u];     head[u] = cnt;   }   int fnd(int u, int fa = -1) {     if (vis[u]) return u;     vis[u] = -1;     for (int i = head[u]; i; i = e[i].next) {       int v = e[i].to;       if (v != fa) {         res = fnd(v, u);         if (res)           return cir[++tot] = u, sum[tot] = e[i].w, vis[u] = 1,                  res == u ? 0 : res;       }     }     return 0;   }   void dfs(int u, int fa = -1) {     for (int i = head[u]; i; i = e[i].next) {       int v = e[i].to;       if (vis[v] != 1 && v != fa) {         dfs(v, u);         ans1 = max(ans1, f[u] + f[v] + e[i].w);         f[u] = max(f[u], f[v] + e[i].w);       }     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d%d , &x, &y, &z);       add(x, y, z);       add(y, x, z);     }     fnd(1);     sum[0] = 0;     for (int i = 1; i <= tot; i++) {       dfs(cir[i]);       sum[i] += sum[i - 1];     }     res = l[0] = l0[0] = -Inf;     for (int i = 1; i <= tot; i++) {       l0[i] = max(l0[i - 1], f[cir[i]] + sum[i] + res);       l[i] = max(l[i - 1], f[cir[i]] + sum[i]);       res = max(res, f[cir[i]] - sum[i]);     }     res = r[tot + 1], r0[tot + 1] = -Inf;     for (int i = tot; i >= 1; i--) {       r0[i] = max(r0[i + 1], f[cir[i]] - sum[i] + res);       r[i] = max(r[i + 1], f[cir[i]] + sum[tot] - sum[i]);       res = max(res, f[cir[i]] + sum[i]);     }     for (int i = 1; i <= tot; i++) {       ans2 = min(ans2, max(l[i - 1] + r[i], max(l0[i - 1], r0[i])));     }     printf( %lld n , max(ans1, ans2));     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   bool Finish_read;   template <class T>   inline void read(T &x) {     Finish_read = 0;     x = 0;     int f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       if (ch == EOF) return;       ch = getchar();     }     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     x *= f;     Finish_read = 1;   }   template <class T>   inline void print(T x) {     if (x / 10 != 0) print(x / 10);     putchar(x % 10 +  0 );   }   template <class T>   inline void writeln(T x) {     if (x < 0) putchar( - );     x = abs(x);     print(x);     putchar(  n );   }   template <class T>   inline void write(T x) {     if (x < 0) putchar( - );     x = abs(x);     print(x);     putchar(   );   }   int main() {     int n;     scanf( %d , &n);     int t = sqrt(n);     if (n % t) {       for (int i = n / t * t + 1; i <= n; i++) printf( %d  , i);     }     for (int i = n / t; i >= 1; i--)       for (int j = (i - 1) * t + 1; j <= i * t; j++) printf( %d  , j);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, a;     cin >> n >> m >> a;     cout << (n / a + (n % a != 0)) * (m / a + (m % a != 0));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200100;   int n, b;   queue<pair<int, int> > q;   long long ans[MAXN];   int main() {     scanf( %d%d , &n, &b);     long long available = 0;     memset(ans, 0xff, sizeof ans);     for (int i = 0, t, d; i < n; ++i) {       scanf( %d%d , &t, &d);       while (!q.empty() && available <= t) {         ans[q.front().first] = available += q.front().second;         q.pop();       }       available = max(available, (long long)t);       if ((int)q.size() < b) {         q.push(make_pair(i, d));       }     }     while (!q.empty()) {       ans[q.front().first] = available += q.front().second;       q.pop();     }     for (int i = 0; i < n; ++i) {       printf( %lld%c , ans[i],    n [i + 1 == n]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x[3], l;     scanf( %d%d%d%d , x, x + 1, x + 2, &l);     long long ans = 1LL * (l + 3) * (l + 2) * (l + 1) / 6;     for (int i = 0; i < 3; i++)       for (int lx = 0; lx <= l; lx++) {         int xx = min(l - lx, x[i] + lx - x[(i + 1) % 3] - x[(i + 2) % 3]);         if (xx >= 0) ans -= 1LL * (2 + xx) * (1 + xx) / 2;       }     cout << ans << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3010;   int a[MAXN], b[MAXN], c[MAXN];   int d[MAXN][2];   int main() {     int n;     while (~scanf( %d , &n)) {       for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);       for (int i = 1; i <= n; ++i) scanf( %d , &b[i]);       for (int i = 1; i <= n; ++i) scanf( %d , &c[i]);       d[1][0] = b[1];       d[1][1] = a[1];       for (int i = 2; i <= n; ++i) {         d[i][0] = max(d[i - 1][0] + b[i], d[i - 1][1] + c[i]);         d[i][1] = max(d[i - 1][0] + a[i], d[i - 1][1] + b[i]);       }       printf( %d n , d[n][1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, l, a[110], s, x, len;   int main() {     cin >> n >> l;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] > s) s = a[i];     }     for (int i = l; i <= s; i++) {       for (int j = 1; j <= n; j++) x += a[j] / i;       if (len < i * x) len = i * x;       x = 0;     }     cout << len << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <int MOD_>   struct modnum {     static constexpr int MOD = MOD_;     static_assert(MOD_ > 0,  MOD must be positive );       private:     using ll = long long;     int v;     static int minv(int a, int m) {       a %= m;       assert(a);       return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);     }       public:     modnum() : v(0) {}     modnum(ll v_) : v(int(v_ % MOD)) {       if (v < 0) v += MOD;     }     explicit operator int() const { return v; }     friend std::ostream& operator<<(std::ostream& out, const modnum& n) {       return out << int(n);     }     friend std::istream& operator>>(std::istream& in, modnum& n) {       ll v_;       in >> v_;       n = modnum(v_);       return in;     }     friend bool operator==(const modnum& a, const modnum& b) {       return a.v == b.v;     }     friend bool operator!=(const modnum& a, const modnum& b) {       return a.v != b.v;     }     modnum inv() const {       modnum res;       res.v = minv(v, MOD);       return res;     }     friend modnum inv(const modnum& m) { return m.inv(); }     modnum neg() const {       modnum res;       res.v = v ? MOD - v : 0;       return res;     }     friend modnum neg(const modnum& m) { return m.neg(); }     modnum operator-() const { return neg(); }     modnum operator+() const { return modnum(*this); }     modnum& operator++() {       v++;       if (v == MOD) v = 0;       return *this;     }     modnum& operator--() {       if (v == 0) v = MOD;       v--;       return *this;     }     modnum& operator+=(const modnum& o) {       v += o.v;       if (v >= MOD) v -= MOD;       return *this;     }     modnum& operator-=(const modnum& o) {       v -= o.v;       if (v < 0) v += MOD;       return *this;     }     modnum& operator*=(const modnum& o) {       v = int(ll(v) * ll(o.v) % MOD);       return *this;     }     modnum& operator/=(const modnum& o) { return *this *= o.inv(); }     friend modnum operator++(modnum& a, int) {       modnum r = a;       ++a;       return r;     }     friend modnum operator--(modnum& a, int) {       modnum r = a;       --a;       return r;     }     friend modnum operator+(const modnum& a, const modnum& b) {       return modnum(a) += b;     }     friend modnum operator-(const modnum& a, const modnum& b) {       return modnum(a) -= b;     }     friend modnum operator*(const modnum& a, const modnum& b) {       return modnum(a) *= b;     }     friend modnum operator/(const modnum& a, const modnum& b) {       return modnum(a) /= b;     }   };   template <typename T>   T pow(T a, long long b) {     assert(b >= 0);     T r = 1;     while (b) {       if (b & 1) r *= a;       b >>= 1;       a *= a;     }     return r;   }   template <int M>   string to_string(modnum<M> x) {     return to_string(int(x));   }   using num = modnum<998244353>;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int m, n, k;     cin >> m >> n >> k;     vector<num> p2(max(m, n) + 1);     for (int i = 0; i <= max(m, n); i++) p2[i] = i ? p2[i - 1] * 2 : 1;     map<pair<int, int>, int> cells;     vector<int> rowTypeCnt(4), colTypeCnt(4);     rowTypeCnt[0] = m;     colTypeCnt[0] = n;     vector<vector<int>> rowCnt(m, vector<int>(2));     vector<vector<int>> colCnt(n, vector<int>(2));     auto getRowType = [&](int x) {       int res = 0;       for (int i = 0; i < 2; i++)         if (rowCnt[x][i]) res |= 1 << i;       return res;     };     auto getColType = [&](int x) {       int res = 0;       for (int i = 0; i < 2; i++)         if (colCnt[x][i]) res |= 1 << i;       return res;     };     auto remove = [&](int x, int y) {       if (!cells.count({x, y})) return;       rowTypeCnt[getRowType(x)]--;       colTypeCnt[getColType(y)]--;       int v = cells[{x, y}];       cells.erase({x, y});       rowCnt[x][(x + y + v) & 1]--;       colCnt[y][(x + y + v) & 1]--;       rowTypeCnt[getRowType(x)]++;       colTypeCnt[getColType(y)]++;     };     auto add = [&](int x, int y, int v) {       rowTypeCnt[getRowType(x)]--;       colTypeCnt[getColType(y)]--;       rowCnt[x][(x + y + v) & 1]++;       colCnt[y][(x + y + v) & 1]++;       cells[{x, y}] = v;       rowTypeCnt[getRowType(x)]++;       colTypeCnt[getColType(y)]++;     };     while (k--) {       int x, y, op;       cin >> x >> y >> op;       remove(--x, --y);       if (op >= 0) add(x, y, op);       if (rowTypeCnt[3] && colTypeCnt[3])         cout << 0 <<   n ;       else if (rowTypeCnt[3])         cout << p2[colTypeCnt[0]] <<   n ;       else if (colTypeCnt[3])         cout << p2[rowTypeCnt[0]] <<   n ;       else if (rowTypeCnt[0] == m)         cout << p2[m] + p2[n] - 2 <<   n ;       else         cout << p2[rowTypeCnt[0]] + p2[colTypeCnt[0]] -                     (rowTypeCnt[1] == 0 || rowTypeCnt[2] == 0)              <<   n ;     }   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     long long n, m, p;     cin >> n >> m >> p;     long long a;     long long b;     long long u = 0, v = 0;     for (long long i = 1; i <= n; i++) {       cin >> a;       if (u == 0 && a % p != 0) {         u = i;       }     }     for (long long i = 1; i <= m; i++) {       cin >> b;       if (v == 0 && b % p != 0) {         v = i;       }     }     cout << u + v - 2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n, k;     cin >> n >> k;     vector<int> *dist = new vector<int>[n];     int len = 0;     for (int i = 0; i < n; i++) {       int d;       cin >> d;       dist[d].push_back(i);       len = max(len, d);     }     if (dist[0].size() != 1) {       cout << -1;       return 0;     }     for (int i = 1; i <= len; i++) {       if (dist[i].empty() ||           dist[i].size() > (long long)dist[i - 1].size() * (k - (i != 1))) {         cout << -1;         return 0;       }     }     cout << n - 1 << endl;     for (int i = 1; i <= len; i++) {       int counter = 0;       int index = 0;       for (int child : dist[i]) {         if (counter == k - (i != 1)) {           counter = 0;           index++;         }         cout << dist[i - 1][index] + 1 <<     << child + 1 << endl;         counter++;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, n;     cin >> a >> b >> n;     bool aa = 0, bb = 1;     if (a < b) swap(a, b), swap(aa, bb);     for (int i = 0; i < a - (n + 1) / 2 - (n % 2 == 0); i++) cout << aa;     for (int i = 0; i < (n + 1) / 2; i++) cout << aa << bb;     for (int i = 0; i < b - (n + 1) / 2; i++) cout << bb;     if (n % 2 == 0) cout << aa;   }


#include <bits/stdc++.h>   char s[100005], stack[100005], ss;   int main() {     long long n, k, now, i, i2, l, plus = 0, kid, pos;     scanf( %lld %lld , &n, &k);     for (i = 1; i <= k; i++) {       scanf( %lld , &now);       plus = 0;       ss = 0;       kid = n;       while (kid / 2 + plus + 1 != now) {         if (kid / 2 + plus + 1 < now) {           stack[++ss] =  R ;           plus += kid / 2 + 1;           kid /= 2;         } else {           stack[++ss] =  L ;           kid /= 2;         }       }       now = kid;       scanf( %s , s);       l = strlen(s);       for (i2 = 0; i2 < l; i2++) {         if (s[i2] ==  R ) {           if (now == 1) continue;           plus += now / 2 + 1;           now /= 2;           stack[++ss] =  R ;         } else if (s[i2] ==  L ) {           if (now == 1) continue;           now /= 2;           stack[++ss] =  L ;         } else {           if (now == n) continue;           if (stack[ss] ==  R ) plus -= now + 1;           now = now * 2 + 1;           ss--;         }       }       printf( %lld n , plus + now / 2 + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 10;   const int MAXM = 4e6 + 10;   const long long MOD = 1e9 + 7;   const long long INF = 0x3f3f3f3f;   const unsigned long long BASE = 233;   const int base = 5;   mt19937_64 mt(time(0));   char rubbish[110];   bool GETDATA;   inline long long read() {     long long x = 0, f = 1;     char ch;     do {       ch = getchar();       if (ch ==  - ) f = -1;     } while (ch <  0  || ch >  9 );     do {       x = x * 10 + ch - 48;       ch = getchar();     } while (ch >=  0  && ch <=  9 );     return x * f;   }   inline void write(long long x, char con =   n ) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) write(x / 10, 0);     putchar(x % 10 +  0 );     if (con) {       printf( %c , con);     }   }   long long N, M, K, Q;   long long a[MAXN];   char s[MAXN][110];   int sz[MAXN];   vector<int> es[30];   vector<pair<int, int> > tot;   vector<int> topsort;   bool occ[30];   bool vis[30];   int ord[30];   void dfs(int u) {     vis[u] = true;     for (auto v : es[u]) {       if (!vis[v]) {         dfs(v);       }     }     topsort.push_back(u);   }   void init() {     for (int i = 0; i < 30; i++) {       es[i].clear();       occ[i] = false;       vis[i] = false;     }     tot.clear();     topsort.clear();   }   void solve() {     long long ans = 0;     int now;     int id;     N = read();     M = read();     init();     for (int i = 0; i < N; i++) {       now = read();       for (int j = 0; j < M; j++) {         id = now * N + j;         scanf( %s , s[id]);         for (sz[id] = 0; s[id][sz[id]] !=   0 ; sz[id]++) {           occ[s[id][sz[id]] -  a ] = true;         }       }     }     for (int i = 1, j; i < N * M; i++) {       now = min(sz[i - 1], sz[i]);       for (j = 0; j < now; j++) {         if (s[i - 1][j] != s[i][j]) {           break;         }       }       if (j < now) {         es[s[i][j] -  a ].push_back(s[i - 1][j] -  a );         tot.push_back(pair<int, int>{s[i][j] -  a , s[i - 1][j] -  a });       } else if (sz[i - 1] > sz[i]) {         printf( IMPOSSIBLE n );         return;       }     }     for (int i = 0; i < 26; i++) {       if (occ[i] && !vis[i]) {         dfs(i);       }     }     for (int i = 0; i < topsort.size(); i++) {       ord[topsort[i]] = i;     }     for (auto x : tot) {       if (ord[x.first] < ord[x.second]) {         printf( IMPOSSIBLE n );         return;       }     }     for (auto ch : topsort) {       printf( %c , ch +  a );     }     printf(  n );   }   int main() {     int T;     T = 1;     for (int t = 1; t <= T; t++) {       GETDATA = false;       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ts, kk = 1;   template <class T>   inline T _sq(T a) {     return a * a;   }   template <class T, class X>   inline T _pow(T a, X y) {     T z = 1;     for (int i = 1; i <= y; i++) {       z *= a;     }     return z;   }   template <class T>   inline T _gcd(T a, T b) {     a = _abs(a);     b = _abs(b);     if (!b) return a;     return _gcd(b, a % b);   }   template <class T>   inline T _lcm(T a, T b) {     a = _abs(a);     b = _abs(b);     return (a / _gcd(a, b)) * b;   }   template <class T>   inline T _extended(T a, T b, T &x, T &y) {     a = _abs(a);     b = _abs(b);     T g, x1, y1;     if (!b) {       x = 1;       y = 0;       g = a;       return g;     }     g = _extended(b, a % b, x1, y1);     x = y1;     y = x1 - (a / b) * y1;     return g;   }   template <class T, class X>   inline bool getbit(T a, X i) {     T t = 1;     return ((a & (t << i)) > 0);   }   template <class T, class X>   inline T setbit(T a, X i) {     T t = 1;     return (a | (t << i));   }   template <class T, class X>   inline T resetbit(T a, X i) {     T t = 1;     return (a & (~(t << i)));   }   template <class T, class X>   inline T togglebit(T a, X i) {     T t = 1;     return (a ^ (t << i));   }   template <class T, class X, class Y>   inline T _bigmod(T n, X m, Y mod) {     unsigned long long ret = 1, a = n % mod;     while (m) {       if (m & 1) ret = (ret * a) % mod;       m >>= 1;       a = (a * a) % mod;     }     ret %= mod;     return (T)ret;   }   template <class T, class Y>   inline T _modinv(T n, Y mod) {     return _bigmod(n, mod - 2, mod);   }   int main() {     int n, cnt = 0;     ;     double x, tot = 0.0, ans, add;     cin >> n;     for (int i = 1; i <= n + n; i++) {       cin >> x;       add = (x - (int)x);       tot += add;       if (add == 0.0) cnt++;     }     tot -= n;     while (cnt-- > 0 && tot < -.5) tot += 1.0;     tot = fabs(tot);     cout << setprecision(3) << fixed << tot << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const int maxn = 1007;   long long dp[maxn][maxn][4];   char s[maxn];   int T, k;   long long dfs(int pos, int dis, int ok, int limit) {     if (pos == -1) {       return ok;     }     if (!limit && dp[pos][dis][ok] != -1) return dp[pos][dis][ok];     int up = limit ? s[pos] -  0  : 9;     long long res = 0;     for (int i = 0; i <= up; i++) {       if (i != 4 && i != 7)         res = (res + dfs(pos - 1, max(0, dis - 1), ok, limit && (i == up))) % MOD;       else         res = (res + dfs(pos - 1, k, ok || dis, limit && (i == up))) % MOD;     }     if (!limit) dp[pos][dis][ok] = res;     return res;   }   int check(int len) {     int pre = -1;     for (int i = 0; i < len; i++) {       if (s[i] ==  4  || s[i] ==  7 ) {         if (pre != -1 && i - pre <= k) return 1;         pre = i;       }     }     return 0;   }   int main() {     memset(dp, -1, sizeof(dp));     scanf( %d%d , &T, &k);     while (T--) {       scanf( %s , s);       int len = strlen(s);       for (int i = 0; i < len / 2; i++) swap(s[i], s[len - 1 - i]);       long long ans = (dfs(len - 1, 0, 0, true) - check(len) + MOD) % MOD;       scanf( %s , s);       len = strlen(s);       for (int i = 0; i < len / 2; i++) swap(s[i], s[len - 1 - i]);       ans = (dfs(len - 1, 0, 0, true) - ans + MOD) % MOD;       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   clock_t time_p = clock();   void timer() {     time_p = clock() - time_p;     cerr <<  Execution Time:   << (double)(time_p) / CLOCKS_PER_SEC <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, k, r = 2, g = 5, b = 8, cnt = 0, tot = 0;     cin >> n >> k;     r *= n;     g *= n;     b *= n;     if (r % k)       cnt += (r / k + 1);     else       cnt += r / k;     if (g % k)       cnt += (g / k + 1);     else       cnt += g / k;     if (b % k)       cnt += (b / k + 1);     else       cnt += b / k;     cout << cnt;     timer();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e3 + 6.66;   const int MAXM = 2e3 + 6.66;   const long long MOD = 1e9 + 7;   long long dp[MAXN][MAXM];   long long dp1[MAXN][MAXM];   long long par[MAXN][MAXM];   long long par2[MAXN][MAXM];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m;     cin >> n >> m;     for (int sz = 0; sz < m - 1; sz++) dp[0][sz] = 1;     for (int i = 1; i <= n; i++) {       for (int j = 0; j < m - 1; j++) {         if (i == 1) {           dp[i][j] = 1;           dp1[i][j] = 1;           par[i][j] = j + 1;           par2[i][j] = par2[i][j - 1] + j + 1;           continue;         }         dp1[i][j] = (1 + ((2 + j) * par[i - 1][j - 1]) % MOD * 1LL -                      par2[i - 1][j - 1] * 1LL + MOD) %                     MOD;         dp[i][j] =             (1 + ((2 + j) * par[i - 1][j]) % MOD - par2[i - 1][j] + MOD) % MOD;         par[i][j] = (par[i][j - 1] + dp[i][j]) % MOD;         par2[i][j] = (par2[i][j - 1] + (1LL * (j + 1LL) * dp[i][j]) % MOD) % MOD;       }     }     long long ans = 0LL;     for (int t = 0; t < n; t++)       for (int sz = 0; sz < m - 1; sz++) {         ans = (ans +                (((m - sz - 1LL) * 1LL * dp[t + 1][sz]) % MOD * dp1[n - t][sz]) %                    MOD) %               MOD;       }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long i, n, m, a[1000001], t1, t2, sum;   int main() {     cin >> n >> m;     for (i = 0; i < m; i++) {       scanf( %I64d %I64d , &t1, &t2);       a[t1]++;       a[t2]++;     }     for (i = 1; i <= n; i++) sum += a[i] * (n - 1LL - a[i]);     sum /= 2LL;     cout << n * (n - 1LL) * (n - 2LL) / 6LL - sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000;   set<pair<long long, long long> > q;   long long prod(pair<long long, long long> a, pair<long long, long long> b) {     return a.first * b.second - a.second * b.first;   }   bool check(pair<long long, long long> a, pair<long long, long long> b,              pair<long long, long long> c) {     return (prod({b.first - a.first, b.second - a.second},                  {c.first - a.first, c.second - a.second}) > 0);   }   const long double eps = 1e-12;   void addPoint(long long x, long long y) {     while (q.size()) {       auto it = q.lower_bound({x, 0});       if (it != q.end() && it->first == x) {         if (it->second > y)           q.erase(it);         else           return;       } else         break;     }     auto it1 = q.lower_bound({x, 0});     if (it1 != q.end()) {       if (it1->second <= y) return;       auto it2 = q.lower_bound({x, 0});       it2--;       if (!check(*it2, {x, y}, *it1)) return;     }     while (q.size() > 1) {       auto it1 = q.lower_bound({x, 0});       if (it1 == q.end()) break;       auto it2 = q.upper_bound(*it1);       if (it2 == q.end()) break;       if (!check({x, y}, *it1, *it2))         q.erase(it1);       else         break;     }     while (q.size()) {       auto it1 = q.lower_bound({x, 0});       if (it1 == q.begin()) break;       it1--;       if (it1 == q.begin()) break;       auto it2 = q.lower_bound({x, 0});       it2--;       it2--;       if (!check(*it2, *it1, {x, y}))         q.erase(it1);       else         break;     }     q.insert({x, y});   }   long long maxx = 0, yy = 0;   long double f(long double x) {     if ((long double)q.rbegin()->first + eps < x) return 1e14;     pair<int, int> it1 = *q.lower_bound({(long long)(x - eps), 0});     if (abs(it1.first - x) < eps) return it1.second;     auto kek = q.lower_bound({(long long)(x - eps), 0});     kek--;     pair<int, int> it2 = *kek;     long double X = it1.first, Y = it1.second, XX = it2.first, YY = it2.second;     long double a = YY - Y, b = X - XX, c = -a * X - b * Y;     return (-a * x - c) / b;   }   int main() {     ios::sync_with_stdio(0);     int qq;     long long m;     cin >> qq >> m;     int j = 0;     q.insert({0, 0});     int k = 0;     for (int i = 1; i <= qq; i++) {       int k, a, b;       cin >> k >> a >> b;       if (k == 1) {         long long x = (a + j) % MOD + 1;         long long y = (b + j) % MOD + 1;         if (x > maxx) {           maxx = x;           yy = y;         } else if (x == maxx)           yy = min(yy, y);         addPoint(x, y);       } else {         k++;         long long t = (a + j) % MOD + 1;         long long h = (b + j) % MOD + 1;         long long x = (h + t - 1) / t;         auto it1 = q.lower_bound({x, 0});         bool ok = 0;         if (it1 != q.end()) {           auto it2 = prev(it1);           long long a = it1->second - it2->second, b = it2->first - it1->first,                     c = -it1->first * a - it1->second * b;           if (b < 0) a *= -1, b *= -1, c *= -1;           if (-a * h - c * t <= m * b) ok = true;         }         if (ok) {           j = i;           cout <<  YES n ;         } else           cout <<  NO n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200005;   int N, M, K;   int A[MAXN];   int B[MAXN];   set<int> adj[MAXN];   int deg[MAXN];   set<pair<int, int> > st;   bool inGraph[MAXN];   int ans[MAXN];   void update(int x) {     if (!inGraph[x]) return;     set<pair<int, int> >::iterator it = st.find(make_pair(deg[x], x));     st.erase(it);     deg[x]--;     st.insert(make_pair(deg[x], x));   }   void fix() {     while (!st.empty() && st.begin()->first < K) {       int cur = st.begin()->second;       st.erase(st.begin());       inGraph[cur] = false;       for (auto nxt : adj[cur]) {         adj[nxt].erase(cur);         update(nxt);       }       adj[cur].clear();     }   }   int main() {     scanf( %d %d %d , &N, &M, &K);     for (int i = 0; i < M; i++) {       scanf( %d %d , &A[i], &B[i]);       deg[A[i]]++;       deg[B[i]]++;       adj[A[i]].insert(B[i]);       adj[B[i]].insert(A[i]);     }     for (int i = 1; i <= N; i++) {       st.insert(make_pair(deg[i], i));       inGraph[i] = true;     }     for (int i = M - 1; i >= 0; i--) {       fix();       ans[i] = st.size();       adj[A[i]].erase(B[i]);       adj[B[i]].erase(A[i]);       if (inGraph[B[i]]) update(A[i]);       if (inGraph[A[i]]) update(B[i]);     }     for (int i = 0; i < M; i++) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( avx2 )   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long k;     cin >> k;     long long pref = 0;     vector<long long> poww10(17);     poww10[0] = 1;     for (int i = 1; i < 17; i++) {       poww10[i] = poww10[i - 1] * 10;     }     for (int len = 1; len <= 15; len++) {       if (pref + len * (poww10[len] - poww10[len - 1]) >= k) {         k -= pref;         long long l = 0, r = poww10[len] - poww10[len - 1];         while (l + 1 < r) {           long long mid = (l + r) / 2;           if (len * mid < k) {             l = mid;           } else {             r = mid;           }         }         k -= len * l;         cout << to_string(poww10[len - 1] + l)[k - 1] <<   n ;         return 0;       }       pref += len * (poww10[len] - poww10[len - 1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int l, r, x, y;   vector<int> primes;   int cnt(int idx, int a, int b) {     if (idx == primes.size()) return a >= l && a <= r && b >= l && b <= r;     return cnt(idx + 1, a * primes[idx], b) + cnt(idx + 1, a, b * primes[idx]);   }   int main() {     cin >> l >> r >> x >> y;     if (y % x) return puts( 0 );     y /= x;     for (int i = 2; i * i <= y; i++) {       int v = 1;       while (y % i == 0) y /= i, v *= i;       if (v > 1) primes.push_back(v);     }     if (y > 1) primes.push_back(y);     cout << cnt(0, x, x);   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());   const ld pi = acos(0) * 2;   template <typename T>   inline void read(T &x) {     char c;     bool nega = 0;     while ((!isdigit(c = getchar())) && (c !=  - ))       ;     if (c ==  - ) {       nega = 1;       c = getchar();     }     x = c - 48;     while (isdigit(c = getchar())) x = x * 10 + c - 48;     if (nega) x = -x;   }   template <typename T>   inline void writep(T x) {     if (x > 9) writep(x / 10);     putchar(x % 10 + 48);   }   template <typename T>   inline void write(T x) {     if (x < 0) {       putchar( - );       x = -x;     }     writep(x);   }   template <typename T>   inline void writeln(T x) {     write(x);     putchar(  n );   }   int n, m;   int r[500001];   int root(int u) {     if (r[u] < 0) return u;     return r[u] = root(r[u]);   }   bool unite(int u, int v) {     u = root(u);     v = root(v);     if (u == v) return 0;     if (r[u] > r[v]) swap(u, v);     r[u] += r[v];     r[v] = u;     return 1;   }   int main() {     read(n);     read(m);     for (int i = (1); i <= (n); i++) r[i] = -1;     for (int i = (1); i <= (m); i++) {       int k;       read(k);       int v = -1;       int u;       for (int i = (1); i <= (k); i++) {         read(u);         if (v != -1)           unite(u, v);         else           v = u;       }     }     for (int i = (1); i <= (n); i++) {       write(-r[root(i)]);       putchar(   n [i == n]);     }   }


#include <bits/stdc++.h>   using namespace std;   struct graph {     int n;     vector<vector<int>> adj;     graph(int n) : n(n), adj(n) {}     void add_edge(int u, int v) { adj[u].push_back(v); }     vector<int> &operator[](int u) { return adj[u]; }   };   vector<vector<int>> scc_gabow(graph &adj) {     int n = adj.n;     vector<vector<int>> scc;     vector<int> S, B, I(n);     function<void(int)> dfs = [&](int u) {       B.push_back(I[u] = S.size());       S.push_back(u);       for (int v : adj[u])         if (!I[v])           dfs(v);         else           while (I[v] < B.back()) B.pop_back();       if (I[u] == B.back()) {         scc.push_back({});         for (B.pop_back(); I[u] < S.size(); S.pop_back()) {           scc.back().push_back(S.back());           I[S.back()] = n + scc.size();         }       }     };     for (int u = 0; u < n; ++u)       if (!I[u]) dfs(u);     return scc;   }   const long long mod = 1000000007;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     vector<long long> a(n);     for (int i = 0; i < n; ++i) cin >> a[i];     graph adj(n);     int m;     cin >> m;     for (int i = 0; i < m; ++i) {       int u, v;       cin >> u >> v;       adj.add_edge(--u, --v);     }     auto scc = scc_gabow(adj);     long long mn = 0, ways = 1;     for (auto &comp : scc) {       long long best = a[comp[0]], total = 0;       for (int u : comp)         if (a[u] == best)           ++total;         else if (a[u] < best)           best = a[u], total = 1;       mn += best;       ways = ways * total % mod;     }     cout << mn <<     << ways <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5005;   short dp[N][N];   int ans[N];   int main() {     string s;     cin >> s;     int n;     n = s.size();     for (int len = 1; len <= n; len++) {       for (int l = 0; l < n - len + 1; l++) {         int r = l + len;         if (len == 1) {           dp[l][r] = 1;           continue;         } else if (len == 2) {           dp[l][r] = (s[l] == s[r - 1] ? 2 : 0);           continue;         }         if (s[l] != s[r - 1] || !dp[l + 1][r - 1]) {           continue;         }         dp[l][r] = 1;         int m = (l + r) >> 1;         if (len & 1) {           if (dp[l][m] && dp[m + 1][r]) {             dp[l][r] = dp[l][m] + 1;           }         } else {           if (dp[l][m] && dp[m][r]) {             dp[l][r] = dp[l][m] + 1;           }         }       }     }     for (int len = 1; len <= n; len++) {       for (int l = 0; l < n - len + 1; l++) {         ans[dp[l][l + len]]++;       }     }     for (int i = n - 1; i >= 1; i--) {       ans[i] += ans[i + 1];     }     for (int i = 1; i <= n; i++) {       cout << ans[i] <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long fastpower(long a, long b, long long n = 1000000007) {     long res = 1;     while (b > 0) {       if ((b & 1) != 0) {         res = (res % n * a % n) % n;       }       a = (a % n * a % n) % n;       b = b >> 1;     }     return res;   }   bool isPrime(long long n) {     if (n <= 3) return n > 1;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i += 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   long long gcd(long long a, long long b) {     long long c = a % b;     while (c != 0) {       a = b;       b = c;       c = a % b;     }     return b;   }   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);     long long t = 1;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long count = 1, i = 0;       while (count <= n) {         i++;         count = i * i;         if (count == n) {           i--;           break;         } else if (count > n) {           i--;           break;         }       }       count = i * i;       long long x = 1, y = i + 1;       for (long long j = count + 1; j <= (i + 1) * (i + 1); j++) {         if (j == n) {           cout << x <<     << y <<   n ;           break;         } else {           if (x >= i + 1) y--;           if (x < i + 1) x++;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool compare(pair<pair<long long int, long long int>, long long int> p1,                pair<pair<long long int, long long int>, long long int> p2) {     return p1.first.first < p2.first.first;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long int i, te, j, x, n, m, k, t, y, a, b, r;     te = 1;     while (te--) {       string s;       cin >> s;       n = s.length();       long long int a[n], c[n], ans = 0, cnt = 0, co = 0;       for (i = 0; i < n; i++) {         if (s[i] ==  o ) co++;         c[i] = co;       }       for (i = n - 1; i >= 0; i--) {         if (s[i] ==  o ) {           ans += cnt;         }         if (s[i] ==  v  && s[i - 1] ==  v  && i >= 1) {           cnt++;         }         a[i] = ans;       }       cnt = 0;       for (i = 0; i <= n - 1; i++) {         if (s[i] ==  v  && s[i + 1] ==  v ) {           cnt += a[i];         }       }       cout << cnt <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       long long l = 0, r = n + 1;       while (r - l > 1) {         long long k = (l + r) >> 1;         if ((long long)(n - k) * (n - k - 1) >= 2LL * k)           l = k;         else           r = k;       }       long long ans = 2 * l;       for (int i = l + 1;            i < n && (long long)i + (long long)(n - i) * (n - i - 1) / 2 > ans;            i++)         ans = (long long)i + (long long)(n - i) * (n - i - 1) / 2;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int countBits(long long mask) {     int res = 0;     while (mask) mask &= (mask - 1), ++res;     return res;   }   string toString(long long n) {     stringstream ss;     ss << n;     return ss.str();   }   long long toNumber(string s) {     stringstream ss;     long long n;     ss << s;     ss >> n;     return n;   }   int n, p[1001], dp[1001];   int main() {     while (cin >> n) {       for (int i = (int)(1), _m = (int)(n + 1); i < _m; ++i) cin >> p[i];       for (int i = (int)(1), _m = (int)(n + 1); i < _m; ++i) {         dp[i] = 1;         if (i != p[i])           for (int j = (int)(p[i]), _m = (int)(i); j < _m; ++j)             dp[i] = (dp[i] + dp[j] + 1) % 1000000007;       }       int res = 0;       for (int i = (int)(1), _m = (int)(n + 1); i < _m; ++i)         res = (res + dp[i] + 1) % 1000000007;       cout << res << endl;     }   }


#include <bits/stdc++.h>   const long long mod = 998244853;   long long C[5050][5050], n, m, g[5050], ans;   signed main() {     scanf( %lld%lld , &n, &m);     for (long long i = 0; i <= n + m; i++) {       C[i][0] = 1;       for (long long j = 1; j <= i; j++)         C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;     }     for (long long i = 0; i <= n; i++)       if (i <= n - m)         g[i] = C[n + m][n];       else         g[i] = C[n + m][m + i];     for (long long i = 0; i <= n; i++)       (ans += i * ((g[i] - g[i + 1] + mod) % mod) % mod) %= mod;     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 2147383647;   const double pi = 2 * acos(0.0);   const double eps = 1e-9;   struct debugger {     template <typename T>     debugger& operator,(const T& v) {       cerr << v <<    ;       return *this;     }   } dbg;   inline long long gcd(long long a, long long b) {     a = ((a) < 0 ? -(a) : (a));     b = ((b) < 0 ? -(b) : (b));     while (b) {       a = a % b;       swap(a, b);     }     return a;   }   int ext_gcd(int a, int b, int& x, int& y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     int x1, y1;     int d = ext_gcd(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return d;   }   inline long long modInv(int a, int m) {     int x, y;     ext_gcd(a, m, x, y);     if (x < 0) x += m;     return x;   }   inline long long power(long long a, long long p) {     long long res = 1, x = a;     while (p) {       if (p & 1) res = (res * x);       x = (x * x);       p >>= 1;     }     return res;   }   inline long long bigmod(long long a, long long p, long long m) {     long long res = 1, x = a % m;     while (p) {       if (p & 1) res = (res * x) % m;       x = (x * x) % m;       p >>= 1;     }     return res;   }   char buf[60][30];   long long mask[1 << 20];   int m;   double q;   double memo[1 << 20];   int done[1 << 20];   double dp(int mk) {     int pop = 0;     if (mask[mk]) pop = __builtin_popcountll(mask[mk]);     int pop2 = __builtin_popcountll(mk);     if (pop <= 1) return 0;     if (done[mk]) return memo[mk];     double p = 1.0 / (m - pop2);     double res = 0;     for (int i = (0); i <= (m - 1); ++i) {       if (mk & (1 << i)) continue;       res += p * dp(mk | (1 << i));       long long x = mask[mk | (1 << i)];       x = x ^ mask[mk];       x = __builtin_popcountll(x);       res += p * x * q * (pop2 + 1);     }     done[mk] = 1;     return memo[mk] = res;   }   int main() {     int n;     scanf( %d , &n);     q = 1.0 / n;     for (int i = (0); i <= (n - 1); ++i) {       scanf( %s , &buf[i][0]);     }     m = strlen(&buf[0][0]);     for (int i = (0); i <= (n - 1); ++i) {       for (int j = (i + 1); j <= (n - 1); ++j) {         int tmask = 0;         for (int k = (0); k <= (m - 1); ++k) {           if (buf[i][k] == buf[j][k]) tmask |= (1LL << k);         }         mask[tmask] |= (1LL << i);         mask[tmask] |= (1LL << j);       }     }     int limit = 1 << m;     for (int i = (limit - 1); i >= (0); --i) {       for (int k = (0); k <= (m - 1); ++k) {         if (i & (1 << k)) {           mask[i ^ (1 << k)] |= mask[i];         }       }     }     double res = dp(0);     printf( %.10lf n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using vint = vector<int>;   using pint = pair<int, int>;   using vpint = vector<pint>;   template <typename A, typename B>   inline void chmin(A& a, B b) {     if (a > b) a = b;   }   template <typename A, typename B>   inline void chmax(A& a, B b) {     if (a < b) a = b;   }   template <class A, class B>   ostream& operator<<(ostream& ost, const pair<A, B>& p) {     ost <<  {  << p.first <<  ,  << p.second <<  } ;     return ost;   }   template <class T>   ostream& operator<<(ostream& ost, const vector<T>& v) {     ost <<  { ;     for (int i = 0; i < v.size(); i++) {       if (i) ost <<  , ;       ost << v[i];     }     ost <<  } ;     return ost;   }   inline int topbit(unsigned long long x) {     return x ? 63 - __builtin_clzll(x) : -1;   }   inline int popcount(unsigned long long x) { return __builtin_popcountll(x); }   inline int parity(unsigned long long x) { return __builtin_parity(x); }   const int INF = 1001001001;   const int X = 30000;   int N, D;   int cnt[33333];   const int B = 300;   int dp[X + 1][B];   map<int, int> dp2[X + 1];   signed main() {     cin >> N >> D;     for (int i = 0; i < (N); i++) {       int p;       cin >> p;       cnt[p]++;     }     fill_n(*dp, (X + 1) * B, -INF);     if (D >= B) {       dp2[D][D] = 0;     } else {       dp[D][D] = 0;     }     int ans = 0;     for (int i = D; i <= X; i++) {       for (int j = 1; j < B; j++) {         if (dp[i][j] == -INF) continue;         dp[i][j] += cnt[i];         chmax(ans, dp[i][j]);         for (int k = -1; k <= 1; k++) {           int d = j + k;           if (d <= 0 || i + d > X) continue;           if (d < B)             chmax(dp[i + d][d], dp[i][j]);           else             chmax(dp2[i + d][d], dp[i][j]);         }       }       for (auto& p : dp2[i]) {         p.second += cnt[i];         int j = p.first;         chmax(ans, p.second);         for (int k = -1; k <= 1; k++) {           int d = j + k;           if (d <= 0 || i + d > X) continue;           if (d < B)             chmax(dp[i + d][d], p.second);           else             chmax(dp2[i + d][d], p.second);         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cout << x; }   void __print(long x) { cout << x; }   void __print(long long x) { cout << x; }   void __print(unsigned x) { cout << x; }   void __print(unsigned long x) { cout << x; }   void __print(unsigned long long x) { cout << x; }   void __print(float x) { cout << x; }   void __print(double x) { cout << x; }   void __print(long double x) { cout << x; }   void __print(char x) { cout <<      << x <<     ; }   void __print(const char *x) { cout <<     << x <<    ; }   void __print(const string &x) { cout <<     << x <<    ; }   void __print(bool x) { cout << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cout <<  { ;     __print(x.first);     cout <<  , ;     __print(x.second);     cout <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cout <<  { ;     for (auto &i : x) cout << (f++ ?  ,  :   ), __print(i);     cout <<  } ;   }   void _print() { cout <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cout <<  ,  ;     _print(v...);   }   const int N = 3e6 + 1;   bool prime[N];   int Div[N], num[N];   void sieve(int n) {     vector<int> is_prime(n + 1, 1);     for (int i = 2; i * i <= n; i++)       if (is_prime[i])         for (int j = i + i; j <= n; j += i) is_prime[j] = 0;     int cnt = 1;     for (int i = 2; i <= n; i++)       if (is_prime[i]) prime[i] = 1, num[i] = cnt++;   }   void Divisors() {     for (int i = 1; i < N; i++) {       for (int j = i + i; j < N; j += i) {         Div[j] = i;       }     }   }   void solve() {     int n;     cin >> n;     vector<int> a(2 * n), ans;     map<int, int> m;     for (int i = 0; i <= 2 * n - 1; i++) cin >> a[i], m[a[i]]++;     sort(a.rbegin(), a.rend());     for (int i = 0; i <= 2 * n - 1; i++) {       if (m[a[i]]) {         int x = a[i];         if (prime[x]) {           int y = num[x];           m[x]--, m[y]--;           ans.push_back(y);         } else {           m[a[i]]--, m[Div[x]]--;           ans.push_back(x);         }       }     }     for (auto i : ans) cout << i <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     sieve(N);     Divisors();     int T = 1;     while (T--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n;   void exgcd(long long a, long long b, long long& x, long long& y) {     if (b == 0) {       x = 1;       y = 0;       return;     }     exgcd(b, a % b, x, y);     long long p = x - a / b * y;     x = y;     y = p;   }   long long dv(long long a, long long b) {     if (b == 0) return 8e18;     long long u = a / b - 2;     while ((u + 1) * b <= a) ++u;     return u;   }   long long wo(long long p, long long q, long long k, long long b) {     if (k < p) return -1;     k -= p;     long long ua = min(p, k);     if (b <= ua)       ;     else       return -1;     if (n < 900000) {       for (int w = n; w >= 0; --w) {         long long u = w + n, t = (k - ua) / u - 2;         while (u * t < k - ua || t < 0) ++t;         while (u * t <= k - b) {           long long A = k - u * t, B = w - A;           if (b <= A && A <= ua)             ;           else             throw  GG ;           if (0 <= B && B <= q) return w;           ++t;         }       }       return -1;     }     long long aa = -1;     for (long long t = 0; n * t <= k; ++t) {       long long A = t + 1, B = t, C = k - n * t;       if (C == 0) {         if (b <= 0) {           if (t == 0)             aa = max(aa, q);           else             aa = max(aa, 0LL);         }         continue;       }       long long a0, b0;       exgcd(A, B, a0, b0);       a0 *= C;       b0 *= C;       if (B == 0) {         if (b <= a0 && a0 <= p)           ;         else           continue;       }       long long k = min(dv(a0 - b, B), dv(q - b0, A));       if (a0 - k * B <= ua && b0 + k * A >= 0)         ;       else         continue;       aa = max(aa, a0 + b0 + k);     }     return aa;   }   int main() {     long long l, r, k;     cin >> n >> l >> r >> k;     long long g = r - l + 1;     if (g <= 0) g += n;     long long ans = -1;     ans = max(ans, wo(g, n - g, k, 0));     ans = max(ans, wo(g, n - g, k + 1, 1));     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int tt;     cin >> tt;     while (tt--) {       int n;       cin >> n;       cout << (1ll * ((n - 1) / 2) * (((n - 1) / 2) + 1) *                (2 * ((n - 1) / 2) + 1) * 8) /                   6            <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void winter_is_coming() {     std::ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);   }   double k, arr[10001];   int n;   double check(double md, double k) {     double sum = 0;     for (int i = 0; i < n; i++)       if (arr[i] > md) {         double x = arr[i] - md;         sum += (x - (x * k / 100));       } else if (arr[i] < md) {         double x = md - arr[i];         sum -= x;       }     return sum;   }   int main() {     winter_is_coming();     int t = 100;     double mx = 0;     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> arr[i], mx = max(mx, arr[i]);     double lo, hi, md, ans = 0;     lo = 0, hi = 1000;     while (t--) {       md = (lo + hi) / 2;       double z = check(md, k);       if (z >= 0) {         ans = md;         lo = md;       } else         hi = md;     }     cout << fixed << setprecision(9) << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b, c;     cin >> a >> b;     if (a.size() > b.size()) {       for (int i = b.size(); i < a.size(); i++) c +=  0 ;       b = c + b;     }     if (a.size() < b.size()) {       for (int i = a.size(); i < b.size(); i++) c +=  0 ;       a = c + a;     }     for (int i = 0; i < a.size(); i++) {       if (a[i] > b[i]) {         cout <<  >  << endl;         return 0;       } else if (a[i] < b[i]) {         cout <<  <  << endl;         return 0;       }     }     cout <<  =  << endl;     return 0;   }