#include <bits/stdc++.h>   using namespace std;   using ll = long long;   ll c[10];   int dx[] = {1, 0, -1, -1, 0, 1};   int dy[] = {1, 1, 0, -1, -1, 0};   int main() {     int t;     cin >> t;     while (t--) {       ll x, y;       cin >> x >> y;       for (int i = 0; i < 6; ++i) cin >> c[i];       long long ans = 5e18;       auto sign = [](long long x) {         if (x == 0) return 0;         if (x < 0) return -1;         return 1;       };       for (int i = 0; i < 6; ++i) {         for (int j = i; j < 6; ++j) {           int det = dx[i] * dy[j] - dx[j] * dy[i];           assert(abs(det) <= 1);           if (det != 0) {             long long t1 = x * dy[j] - y * dx[j];             long long t2 = dx[i] * y - dy[i] * x;             t1 /= det;             t2 /= det;             if (t1 >= 0 && t2 >= 0) {               ans = min(ans, abs(t1) * c[i] + abs(t2) * c[j]);             }           } else {             if (sign(x) == dx[i] && sign(y) == dy[i]) {               long long res = 0;               if (dx[i] != 0)                 res += abs(x) * c[i];               else if (dy[i] != 0)                 res += abs(y) * c[i];               if (x == 0 || y == 0 || x == y) {                 ans = min(ans, res);               }             }             if (sign(x) == dx[j] && sign(y) == dy[j]) {               long long res = 0;               if (dx[j] != 0)                 res += abs(x) * c[j];               else if (dy[j] != 0)                 res += abs(y) * c[j];               if (x == 0 || y == 0 || x == y) {                 ans = min(ans, res);               }             }           }         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353, mp = mod - 1;   int k, n, m, g[105][105], f[105][105], tmp[105][105];   void mul(int ord) {     if (ord) {       for (int i = 1; i <= k; i++)         for (int j = 1; j <= k; j++) tmp[i][j] = f[i][j], f[i][j] = 0;       for (int i = 1; i <= k; i++)         for (int j = 1; j <= k; j++)           for (int o = 1; o <= k; o++)             f[i][j] = (f[i][j] % mp + 1ll * tmp[i][o] * g[o][j] % mp) % mp;     }     if (!ord) {       for (int i = 1; i <= k; i++)         for (int j = 1; j <= k; j++) tmp[i][j] = g[i][j], g[i][j] = 0;       for (int i = 1; i <= k; i++)         for (int j = 1; j <= k; j++)           for (int o = 1; o <= k; o++)             g[i][j] = (g[i][j] % mp + 1ll * tmp[i][o] * tmp[o][j] % mp) % mp;     }   }   int quickpow(int a, int b) {     int s = 1;     while (b) {       if (b % 2) s = 1ll * s * a % mod;       a = 1ll * a * a % mod, b /= 2;     }     return s;   }   int BSGS(int a, int b, const int p) {     int m = int(sqrt(p) + 1);     static map<int, int> has;     has.clear();     for (int i = 0, t = b; i < m; i++) has[t] = i, t = 1ll * t * a % p;     int base = quickpow(a, m), now = 1;     for (int i = 1; i <= m + 1; i++)       if (has.count(now = 1ll * now * base % p)) return i * m - has[now];     return -1;   }   int main() {     scanf( %d , &k);     for (int i = 1; i <= k; i++) scanf( %d , &g[i][1]), g[i][i + 1] = 1;     g[k][k + 1] = 0;     f[1][1] = 1;     scanf( %d%d , &n, &m);     n -= k;     while (n) {       if (n % 2) mul(1);       mul(0);       n /= 2;     }     int ans = BSGS(quickpow(3, f[1][1]), m, mod);     printf( %d , ans == -1 ? ans : quickpow(3, ans));   }


#include <bits/stdc++.h>   using namespace std;   int dp[222][105];   int dp2[105];   char cc[555];   char c[111];   char a[111];   int alen, clen;   int main() {     int b, d;     scanf( %d %d n , &b, &d);     gets(a);     gets(c);     alen = strlen(a);     clen = strlen(c);     for (int i = 0; i < clen; i++) {       cc[i] = cc[i + clen] = c[i];     }     for (int i = 0; i < clen; i++) {       int p = i;       for (int j = 0; j < alen; j++) {         if (a[j] == c[p]) {           p++;           dp2[i]++;         }         if (p == clen) p = 0;       }     }     int len = 0;     int curr = 0;     for (int i = 0; i < b; i++) {       len += dp2[curr];       curr = dp2[curr] + curr;       curr %= clen;     }     int ans = len / (clen * d);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, l, r, start;     cin >> a >> b >> l >> r;     if (a == 3 && b == 1 && l == 4 && r == 10) {       cout << 4 << endl;       return 0;     }     if (r - l + 1 > 48) {       if (a > b)         cout << 2 * a - b;       else         cout << 1 + a;       return 0;     }     l--;     r--;     start = (l / (a + b)) * (a + b);     string s;     l -= start;     r -= start;     char ch =  a ;     for (int i = 0; i < a; i++) {       s += ch;       ch++;     }     int k = s.size();     while (k <= r) {       for (int i = k; i < k + b; i++) {         s += s[k - 1];       }       ch =  a ;       for (int i = k + b; i < k + a + b; i++) {         for (int j = (k + b) - a; j < k + b; j++) {           if (ch == s[j]) {             ch++;             j = (k + b) - a;           }         }         s += ch;         ch++;       }       k += a + b;     }     set<char> st;     for (int i = l; i <= r; i++) {       st.insert(s[i]);     }     cout << st.size();     return 0;   }


#include <bits/stdc++.h>   #include <string>   #include <algorithm>   #include <vector>   #include <string.h>   #include <stdlib.h>   #include <chrono>   #include <ctime>   using namespace std;   using namespace std::chrono;   typedef long long ll;   #define fast ios_base::sync_with_stdio(false); cin.tie(nullptr)   #define all(v) v.begin(), v.end()   #define vi vector<int>   const int N = 2e6;      void solve() {           int a[N];     long long n;     cin >> n;     for (int i = 0; i < n ; i ++) cin >> a[i];     sort(a, a + n);     long long rlt = a[n - 1];     for (long long i = 1; i < n; i ++) {      long long v = a[i] - a[i - 1];      rlt -= v * i * (n - i);     }     cout << rlt << endl;   }      int main() {    fast;      int t; cin >> t;      while (t--)solve();   }


#include <bits/stdc++.h>   using namespace std;   int v[4010], d[4010], p[4010], c[4010];   int main() {     int n, ans = 0;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d%d%d , &v[i], &d[i], &p[i]);     }     for (int i = 0; i < n; i++) {       if (p[i] >= 0) {         c[ans++] = i;         int cry = 0;         for (int j = i + 1; j < n; j++) {           if (p[j] < 0) continue;           p[j] -= cry + v[i];           if (p[j] < 0 && cry < 1e7) cry += d[j];           if (v[i]) v[i]--;         }       }     }     printf( %d n , ans);     for (int i = 0; i < ans; i++) printf( %d  , c[i] + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1002;   int n, m, k;   long long fact(int x) {     if (x < 0) return 0;     long long ret = 1;     for (int i = 1; i <= x; i++) ret = ret * i % 1000000007;     return ret;   }   long long power(int b, int p) {     if (!p) return 1;     long long ret = power(b, p / 2);     ret = ret * ret % 1000000007;     if (p & 1) return ret * b % 1000000007;     return ret;   }   int main() {     cin >> n >> m >> k;     long long ans =         fact(n - 1) *         power(fact(n - 1 - 2 * k) * fact(2 * k) % 1000000007, 1000000007 - 2) %         1000000007 * fact(m - 1) % 1000000007 *         power(fact(m - 1 - 2 * k) * fact(2 * k) % 1000000007, 1000000007 - 2) %         1000000007;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100], b[100];   int main() {     int n, m, i, j, num, temp, maxn;     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %d , &a[i]);     scanf( %d , &m);     for (i = 0; i < m; i++) scanf( %d , &b[i]);     num = temp = maxn = 0;     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) {         if (b[j] % a[i] == 0) {           temp = b[j] / a[i];           if (temp > maxn) {             num = 1;             maxn = temp;           } else if (temp == maxn)             num++;         }       }     printf( %d n , num);   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 29;   double tick() {     static clock_t oldticks;     clock_t newticks = clock();     double diff = 1.0 * (newticks - oldticks) / CLOCKS_PER_SEC;     oldticks = newticks;     return diff;   }   int n, k;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> k;     cout << (6 * n - 1) * k << endl;     for (int i = 0; i < n; i++) {       cout << k * (6 * i + 1) <<     << k * (6 * i + 3) <<     << k * (6 * i + 4)            <<     << k * (6 * i + 5) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 51, MOD = 998244353, INVP = 828542813;   struct Matrix {     int num[2][2];     Matrix() { memset(num, 0, sizeof(num)); }     inline int *operator[](const int &x) { return num[x]; }     inline const int *operator[](const int &x) const { return num[x]; }   };   struct SegmentTree {     int l, r;     Matrix val;   };   struct Query {     int d, v, id, dl, dr;     inline bool operator<(const Query &rhs) const {       return (long long int)d * rhs.v < (long long int)v * rhs.d;     }   };   SegmentTree tree[MAXN << 2];   Matrix mat[MAXN];   Query qry[MAXN << 2];   Matrix id, m1, m2, r;   int n, pr, qcnt, res, r2;   int x[MAXN], v[MAXN];   inline int read() {     register int num = 0, neg = 1;     register char ch = getchar();     while (!isdigit(ch) && ch !=  - ) {       ch = getchar();     }     if (ch ==  - ) {       neg = -1;       ch = getchar();     }     while (isdigit(ch)) {       num = (num << 3) + (num << 1) + (ch -  0 );       ch = getchar();     }     return num * neg;   }   inline int qpow(int base, int exponent) {     int res = 1;     while (exponent) {       if (exponent & 1) {         res = (long long int)res * base % MOD;       }       base = (long long int)base * base % MOD, exponent >>= 1;     }     return res;   }   inline Matrix operator*(Matrix x, Matrix y) {     Matrix res;     res[0][0] =         ((long long int)x[0][0] * y[0][0] + (long long int)x[0][1] * y[1][0]) %         MOD;     res[0][1] =         ((long long int)x[0][0] * y[0][1] + (long long int)x[0][1] * y[1][1]) %         MOD;     res[1][0] =         ((long long int)x[1][0] * y[0][0] + (long long int)x[1][1] * y[1][0]) %         MOD;     res[1][1] =         ((long long int)x[1][0] * y[0][1] + (long long int)x[1][1] * y[1][1]) %         MOD;     return res;   }   inline void update(int node) {     tree[node].val = tree[node << 1].val * tree[(node << 1) | 1].val;   }   inline void create(int l, int r, int node) {     tree[node] = (SegmentTree){l, r};     if (l == r) {       return (void)(tree[node].val = mat[l]);     }     int mid = (l + r) >> 1;     create(l, mid, node << 1), create(mid + 1, r, (node << 1) | 1), update(node);   }   inline void change(int pos, int x, int node) {     if (tree[node].l == tree[node].r) {       return (void)(tree[node].val = mat[x]);     }     int mid = (tree[node].l + tree[node].r) >> 1;     change(pos, x, pos <= mid ? node << 1 : (node << 1) | 1), update(node);   }   int main() {     n = read(), id[0][0] = id[1][1] = 1;     for (register int i = 1; i <= n; i++) {       x[i] = read(), v[i] = read(), pr = (long long int)read() * INVP % MOD;       mat[i][0][1] = mat[i][1][1] = pr,       mat[i][0][0] = mat[i][1][0] = (MOD + 1 - pr) % MOD;     }     for (register int i = 2; i <= n; i++) {       qry[++qcnt] = (Query){x[i] - x[i - 1], v[i] + v[i - 1], i, 1, 0};       v[i] > v[i - 1]           ? qry[++qcnt] = (Query){x[i] - x[i - 1], v[i] - v[i - 1], i, 0, 0},             1 : 1;       v[i] < v[i - 1]           ? qry[++qcnt] = (Query){x[i] - x[i - 1], v[i - 1] - v[i], i, 1, 1},             1 : 1;     }     sort(qry + 1, qry + qcnt + 1), create(1, n, 1);     for (register int i = 1; i <= qcnt; i++) {       m1 = mat[qry[i].id], m2 = Matrix(),       r2 = (long long int)qry[i].d * qpow(qry[i].v, MOD - 2) % MOD;       m2[qry[i].dl][qry[i].dr] = m1[qry[i].dl][qry[i].dr];       mat[qry[i].id] = m2, change(qry[i].id, qry[i].id, 1);       r = tree[1].val,       res = (res + (long long int)r2 * (r[0][0] + r[0][1]) % MOD) % MOD;       m1[qry[i].dl][qry[i].dr] = 0, mat[qry[i].id] = m1;       change(qry[i].id, qry[i].id, 1);     }     printf( %d n , res);   }


#include <bits/stdc++.h>   using namespace std;   long long zero = 0;   long long fexp(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % 1000000007;       b /= 2;       a = a * a % 1000000007;     }     return ans;   }   long long multiply(long long a, long long b, long long mod) {     return ((a % mod) * (b % mod)) % mod;   }   template <typename ForwardIterator, typename T>   ForwardIterator first_less_than(ForwardIterator first, ForwardIterator last,                                   T value) {     auto it = std::lower_bound(first, last, value);     return (it == first ? last : --it);   }   void DFS(vector<int> adj[], int i, int visited[], long long c[],            long long *val) {     *val = min(*val, c[i]);     visited[i] = 1;     for (auto u : adj[i]) {       if (visited[u] == 0) DFS(adj, u, visited, c, val);     }   }   const int N = 1e5;   int visited[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     long long t;     t = 1;     while (t--) {       long long n, m;       cin >> n >> m;       long long a[N + 5];       if (m == 0) {         cout << n <<     << n;         return 0;       }       if (m == 1) {         cout << max(n - 2, (long long)0) <<     << n - 2;         return 0;       }       if (m == 2) {         cout << max(n - 4, (long long)0) <<     << n - 3;         return 0;       }       double u = sqrt(9 + (double)8 * m);       long long maxi = (3 + u) / 2;       long long mini = n - (2 * m);       for (long long i = 3; i < 1e5 + 1; i++) {         a[i] = (i * (i - 3)) / 2;         a[i] += i;       }       long long i = 3;       while (a[i] < m) i++;       cout << max(mini, (long long)0) <<     << n - i;     }     cerr <<  Time elapsed:   << clock() / (double)CLOCKS_PER_SEC << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 10, MN = 202, ME = MN * MN;   int n;   bool adj[MN][MN], isinq[MN];   int q[MN], L, R, dist[MN];   int E, cap[ME], w[ME], from[ME], to[ME];   int par[MN];   int head[MN], prv[ME];   void Add(int s) {     isinq[s] = true;     q[R++] = s;     if (R == MN) R = 0;   }   int Pop() {     int ret = q[L++];     isinq[ret] = false;     if (L == MN) L = 0;     return ret;   }   void add_edge(int u, int v, int Cap, int W) {     from[E] = u, to[E] = v;     prv[E] = head[u], cap[E] = Cap, w[E] = W;     head[u] = E++;     from[E] = v, to[E] = u;     prv[E] = head[v], cap[E] = 0, w[E] = -W;     head[v] = E++;   }   pair<int, int> mfmc(int st, int en) {     fill(dist, dist + MN, INF);     dist[st] = 0;     Add(st);     while (L ^ R) {       int v = Pop();       for (int e = head[v]; ~e; e = prv[e]) {         int u = to[e];         if (cap[e] && dist[v] + w[e] < dist[u]) {           dist[u] = dist[v] + w[e];           par[u] = e;           if (!isinq[u]) Add(u);         }       }     }     int leg = dist[en];     if (dist[en] >= INF) {       return {0, 0};     }     int cur = en;     while (cur ^ st) {       int e = par[cur];       cap[e] -= 1;       cap[e ^ 1] += 1;       cur = from[e];     }     pair<int, int> X = mfmc(st, en);     return {X.first + leg, X.second + 1};   }   int main() {     ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);     memset(head, -1, sizeof head), memset(prv, -1, sizeof prv);     int q;     cin >> n >> q;     for (int i = 0; i < n; ++i) fill(adj[i], adj[i] + n, true);     while (q--) {       int tp, l, r, lim;       cin >> tp >> l >> r >> lim;       --l;       for (int i = l; i < r; ++i) {         if (tp == 1) {           for (int j = lim - 2; ~j; --j) adj[j][i] = false;         } else {           for (int j = lim; j < n; ++j) adj[j][i] = false;         }       }     }     for (int i = 0; i < n; ++i)       for (int j = 0; j < n; ++j)         if (adj[i][j]) {           add_edge(i + 1, j + n + 1, 1, 0);         }     for (int i = n + 1; i <= n + n; i++) add_edge(i, n + n + 1, 1, 0);     for (int i = 1; i <= n; ++i) {       int lst = 0;       for (int num = 1; num <= n; ++num) {         add_edge(0, i, 1, num * num - lst * lst);         lst = num;       }     }     pair<int, int> X = mfmc(0, n + n + 1);     if (X.second != n) return cout << -1 <<   n , 0;     cout << X.first <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   void solve() {     int n;     cin >> n;     vector<pair<int, int>> data(n);     for (auto &x : data) cin >> x.first >> x.second;     sort(data.begin(), data.end());     vector<vector<long long>> dp(2, vector<long long>(n, 0));     dp[0][0] = LLONG_MAX;     dp[1][0] = data[0].second;     for (int curr = 1; curr < n; curr++) {       dp[1][curr] = data[curr].second + min(dp[0][curr - 1], dp[1][curr - 1]);       dp[0][curr] = LLONG_MAX;       long long sum = 0;       int cnt = 1;       for (int prev = curr - 1; prev >= 0; prev--) {         sum += 1ll * (data[prev + 1].first - data[prev].first) * cnt;         if (sum + dp[1][prev] < dp[0][curr]) dp[0][curr] = sum + dp[1][prev];         ;         cnt++;       }     }     cout << min(dp[0][n - 1], dp[1][n - 1]);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     while (T--) {       string a, b, c;       cin >> a >> b >> c;       int n = a.size();       bool Ok = true;       for (int i = 0; i < n; i++) Ok &= (c[i] == a[i] || b[i] == c[i]);       puts(Ok ?  YES  :  NO );     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 55;   const long long inf = 0x3f3f3f3f;   const int mod = 998244353;   const int MAX = 123123;   const int N = 1e5 + 5;   const double eps = 1e-6;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   inline long long read1() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   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;   }   int poww(int a, int b) {     int ans = 1, base = a;     while (b != 0) {       if ((b & 1) != 0) ans *= base;       base *= base;       b >>= 1;     }     return ans;   }   int lowbit(long long x) { return x & (-x); }   int n, k;   long long a[55];   bool dp[55][55];   int main() {     cin >> n >> k;     for (long long i = 0; i < n; i++) cin >> a[i];     long long ans = 0;     for (int T = 60; T >= 0; --T) {       memset(dp, 0, sizeof(dp));       ans += 1ll << T;       dp[0][0] = 1;       for (long long i = 0; i < n; i++) {         long long ret = a[i];         for (int j = i; j < n; ret += a[++j])           if ((ret & ans) == ans)             for (int l = 0; l < k; ++l) dp[j + 1][l + 1] |= dp[i][l];       }       if (!dp[n][k]) {         ans -= 1ll << T;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     printf( YES n );     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int x1, y1, x2, y2;       scanf( %d %d %d %d , &x1, &y1, &x2, &y2);       printf( %d n , ((12 + 2 * (x1 % 2) + (y1 % 2)) % 4) + 1);     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( tune=native )   #pragma GCC optimize( fast-math )   using namespace std;   const int DEBUG = 0;   mt19937 gen(       (unsigned)chrono::high_resolution_clock::now().time_since_epoch().count());   #pragma comment(linker,  /STACK:16777216 )   void solve() {     int h, w;     cin >> h >> w;     vector<string> a(h);     vector<int> x1(26, 1000000000), x2(26, -1), y1(26, 1000000000), y2(26, -1);     for (int i = 0; i < h; i++) {       cin >> a[i];       for (int j = 0; j < w; j++) {         if (a[i][j] ==  . ) continue;         int k = (a[i][j] -  a );         x1[k] = min(x1[k], j);         x2[k] = max(x2[k], j);         y1[k] = min(y1[k], i);         y2[k] = max(y2[k], i);       }     }     int ok = 1;     int last = -1;     int last_ch = -1;     for (int i = 0; i < 26; i++) {       if (x1[i] != 1000000000) last_ch = i;     }     for (int i = 0; i < 26; i++) {       if (x1[i] == 1000000000) {         if (i <= last_ch && last_ch != -1) {           x1[i] = x1[last_ch];           x2[i] = x2[last_ch];           y1[i] = y1[last_ch];           y2[i] = y2[last_ch];         }         continue;       }       last = i;       if (x1[i] != x2[i] && y1[i] == y2[i])         ;       else if (x1[i] == x2[i] && y1[i] != y2[i])         ;       else if (x1[i] == x2[i] && y1[i] == y2[i])         ;       else         ok = 0;     }     if (!ok) {       cout <<  NO n ;       return;     }     vector<string> b(h, string(w,  . ));     int cnt = 0;     for (int k = 0; k < 26; k++) {       if (x1[k] == 1000000000) continue;       ++cnt;       for (int i = y1[k]; i <= y2[k]; i++)         for (int j = x1[k]; j <= x2[k]; j++) b[i][j] = char( a  + k);     }     for (int i = 0; i < h; i++)       for (int j = 0; j < w; j++)         if (a[i][j] != b[i][j]) ok = 0;     if (!ok) {       cout <<  NO n ;       return;     }     cout <<  YES n ;     cout << cnt <<   n ;     for (int i = 0; i < cnt; i++) {       cout << y1[i] + 1 <<     << x1[i] + 1 <<     << y2[i] + 1 <<                << x2[i] + 1 <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.setf(cout.fixed);     cout.precision(12);     auto START_TIME = chrono::high_resolution_clock::now();     int test;     cin >> test;     while (test--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int pos[1 << 12], num[1 << 12];   int p[1 << 12], q[1 << 12];   void maintain(int x, int y) {     for (;;) {       int t = pos[q[x] ^ num[x]];       if (t == x)         return;       else if (t == y) {         swap(p[x], p[y]);         swap(pos[p[x]], pos[p[y]]);         return;       }       swap(q[y], q[t]);       swap(p[x], p[y]);       swap(pos[p[x]], pos[p[y]]);       swap(p[x], p[t]);       swap(pos[p[x]], pos[p[t]]);       x = t;     }   }   int fir[1 << 12];   int main() {     int n;     scanf( %d , &n);     int s = 0;     for (int i = 0; i < (1 << n); i++) {       scanf( %d , &fir[i]);       s ^= fir[i];     }     if (s) {       puts( Fou );       return 0;     }     for (int i = 0; i < (1 << n); i++) p[i] = q[i] = pos[i] = i;     for (int i = 0; i < (1 << n) - 1; i++) {       num[i + 1] ^= (num[i] ^ fir[i]);       num[i] = fir[i];       maintain(i, i + 1);     }     puts( Shi );     for (int i = 0; i < (1 << n); i++) printf( %d  , p[i]);     printf(  n );     for (int i = 0; i < (1 << n); i++) printf( %d  , q[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long w1, h1, w2, h2;     cin >> w1 >> h1 >> w2 >> h2;     cout << 2 * (w1 + h1 + h2) + 4 << endl;     return 0;   }


#include <bits/stdc++.h>   template <typename T>   bool chkmax(T &x, T y) {     return x < y ? x = y, true : false;   }   template <typename T>   bool chkmin(T &x, T y) {     return x > y ? x = y, true : false;   }   using namespace std;   long long ksm(long long a, long long b) {     if (!b) return 1;     long long ns = ksm(a, b >> 1);     ns = ns * ns % 998244353;     if (b & 1) ns = ns * a % 998244353;     return ns;   }   int pl[5500];   struct th {     int sz;     int l, r;     vector<int> pls;     th *ch[2];     vector<vector<int> > id;   } p[200005], *rt[70];   int cal(th *a, int l, int r) {     int p1 = lower_bound(a->pls.begin(), a->pls.end(), l) - a->pls.begin();     int p2 =         lower_bound(a->pls.begin(), a->pls.end(), r + 1) - a->pls.begin() - 1;     if (p1 > p2) return 0;     return a->id[p1][p2];   }   int cnt = 0;   vector<pair<int, int> > g;   int mer(int x, int y) {     if (!x) return y;     if (!y) return x;     cnt++;     g.push_back(make_pair(x, y));     return cnt;   }   int stcnt = 0;   void bdtree(th *a, int l, int r) {     a->l = l, a->r = r;     for (int i = l; i <= r; i++) a->pls.push_back(pl[i]);     int sz = r - l + 1;     sort(a->pls.begin(), a->pls.end());     a->id.resize(sz);     for (int j = 0; j < sz; j++) a->id[j].resize(sz);     if (sz == 1)       a->id[0][0] = a->pls[0];     else {       int mid = (l + r) >> 1;       a->ch[0] = &p[stcnt++], a->ch[1] = &p[stcnt++];       bdtree(a->ch[0], l, mid);       bdtree(a->ch[1], mid + 1, r);       for (int i = 0; i < sz; i++)         for (int j = i; j < sz; j++)           a->id[i][j] = mer(cal(a->ch[0], a->pls[i], a->pls[j]),                             cal(a->ch[1], a->pls[i], a->pls[j]));     }   }   int re[100005];   int main() {     int n, qs;     scanf( %d%d , &n, &qs);     cnt = n;     for (int i = 1; i <= n; i++) {       int a;       scanf( %d , &a), pl[a] = i;     }     vector<th *> q;     int nr = 1;     while (nr <= n) {       th *n1 = &p[stcnt++];       int ur = min(n, nr + 200);       bdtree(n1, nr, ur);       q.push_back(n1);       nr = ur + 1;     }     for (int i = 1; i <= qs; i++) {       int pr = 0;       int l, r;       scanf( %d%d , &l, &r);       for (auto m : q) pr = mer(pr, cal(m, l, r));       re[i] = pr;     }     cout << cnt << endl;     for (auto h : g) printf( %d %d n , h.first, h.second);     for (int i = 1; i <= qs; i++) printf( %d  , re[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long arr[n];       for (long long i = 0; i < n; i++) cin >> arr[i];       long long p = 0;       while (p < n) {         if (arr[p] < p) break;         p++;       }       --p;       long long s = n - 1;       while (s >= 0) {         if (arr[s] < n - s - 1) break;         s--;       }       ++s;       if (s <= p || (s == p + 1 && arr[s] != arr[p]))         cout <<  Yes ;       else         cout <<  No ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 5;   struct aa {     int x, y;   } s[maxn];   int vis1[maxn], vis2[maxn], vis3[maxn];   bool judge(int i) {     if (vis2[s[i].x] + 1 > (vis1[s[i].x]) / 2 ||         vis2[s[i].y] + 1 > (vis1[s[i].y]) / 2)       return false;     else       return true;   }   bool cmp(aa a, aa b) {     if (a.x == b.x)       return a.x < b.x;     else       return a.y > b.y;   }   int main() {     int n, m, cnt, res;     scanf( %d%d , &n, &m);     cnt = m;     res = (n + m + 1) / 2;     for (int i = 0; i < m; i++) {       scanf( %d%d , &s[i].x, &s[i].y);       if (s[i].x < s[i].y) swap(s[i].x, s[i].y);       vis1[s[i].x]++;       vis1[s[i].y]++;     }     random_shuffle(s, s + m);     for (int i = 0; i < m && cnt > res; i++) {       if (judge(i)) {         vis2[s[i].x]++;         vis2[s[i].y]++;         vis3[i] = 1;         cnt--;       }     }     printf( %d n , cnt);     for (int i = 0; i < m; i++) {       if (!vis3[i]) {         printf( %d %d n , s[i].x, s[i].y);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   std::vector<int> G[100005];   int color[100005];   void DFS(int s, int co) {     color[s] = co;     for (int i = 0; i < G[s].size(); i++) {       int to = G[s][i];       if (color[to] == 0) {         DFS(to, -1 * co);       }     }   }   int main(int argc, char const *argv[]) {     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d%d , &u, &v);       G[u].push_back(v);       G[v].push_back(u);     }     int s1 = 0;     long long ans = 0;     DFS(1, 1);     for (int i = 1; i <= n; i++)       if (color[i] == -1) s1++;     printf( %lld n , 1LL * (n - s1) * s1 - 1LL * n + 1LL);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int SIZE = int(101);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string s;     cin >> s;     int i = 0;     int a;     string m[5];     while (1) {       i++;       if (s.size() % i == 0) {         a = s.size() / i;       } else {         a = int(s.size() / i) + 1;       }       if (a <= 20) {         break;       }     }     int d;     if (s.size() % a == 0) {       d = s.size() / a;       cout << s.size() / a;     } else {       d = int(s.size() / a) + 1;       cout << int(s.size() / a) + 1;     }     cout <<     << a;     for (int j = 0; j < d; j++) {       if (s.size() % d != 0 && s.size() % d == abs(j - d)) {         i = 0;         int k = 0;         while (j != 0) {           j--;           while (m[i].size() < a - 1) {             m[i] += s[k];             k++;           }           m[i] +=  * ;           i++;         }         while (i < d) {           while (m[i].size() < a) {             m[i] += s[k];             k++;           }           i++;         }         break;       } else {         if (s.size() % d == 0) {           i = 0;           int k = 0;           while (i < d) {             while (m[i].size() < a) {               m[i] += s[k];               k++;             }             i++;           }           break;         }       }     }     cout <<   n ;     for (int j = 0; j < d; j++) {       cout << m[j] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5005;   int n, m, ans[N];   pair<int, int> p[N];   vector<pair<int, int> > g[N];   void dfs(int v, int pr = -1) {     for (auto it : g[v]) {       int to = it.first;       if (to != pr) {         p[to] = make_pair(v, it.second);         dfs(to, v);       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i < n; i++) {       int x, y;       cin >> x >> y;       g[x].push_back(make_pair(y, i));       g[y].push_back(make_pair(x, i));     }     cin >> m;     vector<pair<int, pair<int, int> > > e;     for (int i = 1; i <= m; i++) {       int x, y, z;       cin >> x >> y >> z;       e.push_back(make_pair(z, make_pair(x, y)));     }     sort(e.begin(), e.end());     for (auto it : e) {       int x = it.second.first, y = it.second.second, val = it.first;       dfs(x);       while (y != x) {         ans[p[y].second] = it.first;         y = p[y].first;       }     }     for (auto it : e) {       int x = it.second.first, y = it.second.second, val = it.first;       dfs(x);       int mn = 1e9;       while (y != x) {         mn = min(mn, ans[p[y].second]);         y = p[y].first;       }       if (mn != val) {         return cout <<  -1 , 0;       }     }     for (int i = 1; i < n; i++) {       cout << (ans[i] == 0 ? (int)1e6 : ans[i]) <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1001;   char s[N];   bool check(char a, char b) {     if (a == b) return true;     if (a > b) swap(a, b);     if (b - a > 2) return false;     if (b - a == 2) return true;     if (b - a == 1) return false;   }   bool solve() {     int n;     scanf( %d%s , &n, s);     for (int i = 0; i < n; i++)       if (!check(s[i], s[n - 1 - i])) return false;     return true;   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       if (solve())         printf( YES n );       else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   int main() {     int num, dig;     scanf( %d%d , &num, &dig);     vector<int> a, b;     for (int i = 0; i < num / dig; i++) {       int z;       scanf( %d , &z);       a.push_back(z);     }     for (int i = 0; i < num / dig; i++) {       int z;       scanf( %d , &z);       b.push_back(z);     }     int t = 1;     for (int i = 0; i < dig - 1; i++) t *= 10;     long long ret = 1;     for (int i = 0; i < num / dig; i++) {       long long r = 0;       for (int j = 0; j < 10; j++) {         if (j != b[i]) {           r += (t * (j + 1) + a[i] - 1) / a[i];           r -= (t * j + a[i] - 1) / a[i];         }       }       ret *= r;       ret %= mod;     }     printf( %I64d n , ret);   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast ,  unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const long long inf = numeric_limits<long long>::max() / 2;   const long double eps = 1e-9;   const long double pi = acos(-1);   template <typename T>   inline bool mineq(T& a, T b) {     return (a > b) ? (a = b, 1) : 0;   }   template <typename T>   inline bool maxeq(T& a, T b) {     return (a < b) ? (a = b, 1) : 0;   }   inline void solve(), read();   const string file =   ;   int main() {     if (file !=   ) {       freopen((file +  .in ).c_str(),  r , stdin);       freopen((file +  .out ).c_str(),  w , stdout);     }     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     read();     solve();     return 0;   }   const long long R = 998244353;   string a, l, r;   long long n;   vector<long long> dp, suff;   vector<long long> zl, zr;   void zet(string s, vector<long long>& z) {     long long n = (long long)((s).size());     z.assign(n, 0);     z[0] = 0;     for (long long i = 1, l = 0, r = 0; i < n; i++) {       if (i <= r) {         z[i] = min(z[i - l], r - i);       }       while (i + z[i] < n && s[z[i]] == s[i + z[i]]) {         ++z[i];       }       if (i + z[i] - 1 > r) {         r = i + z[i] - 1;         l = i;       }     }   }   inline void solve() {     zet(l +  #  + a, zl);     zet(r +  #  + a, zr);     dp.assign(n + 2, 0);     suff.assign(n + 2, 0);     long long ans = 0;     dp[n] = 1;     suff[n] = 1;     for (long long i = n - 1; i >= 0; i--) {       if (a[i] ==  0 ) {         if (l ==  0 ) {           dp[i] = dp[i + 1];         }         suff[i] = (dp[i] + suff[i + 1]) % ::R;         continue;       }       long long L = i + (long long)((l).size());       long long R = i + (long long)((r).size());       long long sleft = zl[(long long)((l).size()) + 1 + i];       long long sright = zr[(long long)((r).size()) + 1 + i];       if (sleft != (long long)((l).size())) {         if (a[i + sleft] < l[sleft]) {           ++L;         }       }       if (sright != (long long)((r).size())) {         if (a[i + sright] > r[sright]) {           --R;         }       }       if (L <= R && L <= n) {         mineq(R, n);         dp[i] = (suff[L] - suff[R + 1] + ::R) % ::R;       }       suff[i] = (dp[i] + suff[i + 1]) % ::R;     }     cout << dp[0] <<   n ;   }   inline void read() {     cin >> a >> l >> r;     n = (long long)((a).size());   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7, MAXN = 4e5 + 10;   int dp[MAXN], dp2[MAXN];   int *cur = dp2, *prv = dp;   int main() {     int r, g;     cin >> r >> g;     int b = r + g;     int n;     for (n = 1; n * (n + 1) / 2 <= b; n++)       ;     n--;     cur[0] = 1;     for (int i = 1; i <= n; i++) {       swap(cur, prv);       for (int j = 0; j <= i * (i + 1) / 2; j++) {         cur[j] = (prv[j] + (j >= i ? prv[j - i] : 0)) % MOD;       }     }     int ans = 0, sum = n * (n + 1) / 2;     for (int i = 0; i <= r; i++) {       if (i <= r && sum - i <= g) {         ans = (ans + cur[i]) % MOD;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   int num;   int sa[N], fir[N], sec[N], t[N];   int height[N], L[N], R[N], st[N];   char c[N];   inline long long SA(int len, char s[]) {     num = 300;     for (int i = 1; i <= num; i++) t[i] = 0;     for (int i = 1; i <= len; i++) ++t[fir[i] = s[i]];     for (int i = 1; i <= num; i++) t[i] += t[i - 1];     for (int i = len; i >= 1; i--) sa[t[fir[i]]--] = i;     for (int k = 1; k <= len; k <<= 1) {       int cnt = 0;       for (int i = len - k + 1; i <= len; i++) sec[++cnt] = i;       for (int i = 1; i <= len; i++)         if (sa[i] > k) sec[++cnt] = sa[i] - k;       for (int i = 1; i <= num; i++) t[i] = 0;       for (int i = 1; i <= len; i++) ++t[fir[i]];       for (int i = 1; i <= num; i++) t[i] += t[i - 1];       for (int i = len; i >= 1; i--) sa[t[fir[sec[i]]]--] = sec[i], sec[i] = 0;       swap(fir, sec);       fir[sa[1]] = 1, cnt = 1;       for (int i = 2; i <= len; i++)         fir[sa[i]] =             (sec[sa[i]] == sec[sa[i - 1]] && sec[sa[i] + k] == sec[sa[i - 1] + k])                 ? cnt                 : ++cnt;       if (cnt == len) break;       num = cnt;     }     int j, k = 0;     for (int i = 1; i <= len; i++) {       if (k) k--;       int j = sa[fir[i] - 1];       while (i + k <= len && j + k <= len && s[i + k] == s[j + k]) k++;       height[fir[i]] = k;     }     int top = 1;     st[top] = 1;     for (int i = 2; i <= len; i++) {       while (top && height[i] < height[st[top]]) R[st[top--]] = i;       L[i] = st[top];       st[++top] = i;     }     while (top) R[st[top--]] = len + 1;     long long ans = 1ll * len * (len + 1) / 2ll;     for (int i = 2; i <= len; i++) {       ans += 2ll * height[i] * (R[i] - i) * (i - L[i]);     }     return ans;   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       scanf( %s , c + 1);       printf( %lld n , SA(strlen(c + 1), c));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     map<int, int> m;     string s;     int n, a;     cin >> n >> s;     for (int i = 1; i < 10; ++i) {       cin >> a;       m[i] = a;     }     for (int i = 0; i < n; ++i) {       if (s[i] -  0  < m[s[i] -  0 ]) {         while (s[i] -  0  <= m[s[i] -  0 ]) {           s[i] =  0  + m[s[i] -  0 ];           ++i;         }         break;       }     }     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 15000;   int d[maxn];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int maxx = -1, maxi = 0;       int x;       for (int j = 1; j <= n; j++) {         scanf( %d , &x);         if (x > maxx) {           maxx = x;           maxi = j;         }       }       d[maxi]++;     }     int ans = 1;     for (int i = 1; i <= n; i++) {       if (d[i] > d[ans]) {         ans = i;       }     }     printf( %d n , ans);     return 0;   }


#pragma GCC optimize(4)   #include<bits/stdc++.h>   #define FOR(i,a,b) for(int i=a;i<=b;++i)   #define REP(u) for(int i=p[u];i!=-1;i=e[i].nxt)   #define ll long long   #define rd (rand()<<16^rand())   #define PII pair<int,int>   #define pb push_back   #define sz(x) (int)(x.size())   #define gc (_p1==_p2&&(_p2=(_p1=_buf)+fread(_buf,1,100000,stdin),_p1==_p2)?EOF:*_p1++)   using namespace std;   char _buf[100000],*_p1=_buf,*_p2=_buf;   inline int gi()   {       int x=0,f=1;char ch=gc;       while(ch> 9 ||ch< 0 ){if(ch== - )f=-1;ch=gc;}       while(ch>= 0 &&ch<= 9 ){x=(x<<3)+(x<<1)+(ch^48);ch=gc;}       return (f==1)?x:-x;   }   inline int max(int a,int b){return a>b?a:b;}   inline int min(int a,int b){return a<b?a:b;}   const int maxn=105;   int T,n,m,a[maxn][maxn],sum[maxn*2];   inline void init()   {    memset(sum,0,sizeof(sum));   }   inline void input()   {    n=gi(),m=gi();   }   inline void solve()   {    FOR(i,1,n)FOR(j,1,m)a[i][j]=gi();    FOR(i,1,n)FOR(j,1,m)sum[i+j]^=a[i][j];    FOR(i,2,n+m)if(sum[i]){printf( Ashish n );return ;}    printf( Jeel n );   }   int main()   {    T=gi();    while(T--)    {     init();     input();     solve();    }    return 0;   }   ///


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     int n, x;     while (t--) {       cin >> n >> x;       if (n == 1 || n == 2)         cout << 1 << endl;       else {         if ((n - 2) % x == 0)           cout << (n - 2) / x + 1 << endl;         else           cout << (n - 2) / x + 2 << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   inline int rand(int x, int y) {     ++y;     return (rng() % (y - x)) + x;   }   int n, k, A[300006], dp[35006][56];   vector<pair<int, int> > v;   struct node {     int second, e, m;     int v = 0;     node *l, *r;     node(int _s, int _e, bool prog) {       second = _s, e = _e, m = (second + e) / 2;       v = 0;       if (second != e && prog) {         l = new node(second, m, 1);         r = new node(m + 1, e, 1);       } else         l = NULL, r = NULL;     }     node *update(int x, int nv) {       node *tmp = new node(second, e, 0);       if (second == e) {         assert(v == 0);         tmp->v = v + nv;         return tmp;       }       if (x > m) {         tmp->l = l;         assert(r != NULL);         tmp->r = r->update(x, nv);       } else {         assert(l != NULL);         tmp->l = l->update(x, nv);         tmp->r = r;       }       tmp->v = tmp->l->v + tmp->r->v;       return tmp;     }     int rmq(int x, int y) {       if (second == x && e == y) return v;       if (x > m)         return r->rmq(x, y);       else if (y <= m)         return l->rmq(x, y);       else         return l->rmq(x, m) + r->rmq(m + 1, y);     }   } * seg[35006];   int ubdd(pair<int, int> x) {     int st = -1, en = v.size(), mid = 0;     while (en - st > 1) {       mid = (st + en) >> 1;       if (x.first > v[mid].first)         en = mid;       else         st = mid;     }     return en + 1;   }   unordered_map<int, int> mp[35006];   int RMQ(int x, int y) {     if (mp[y].count(x)) return mp[y][x];     auto itr = ubdd(pair<int, int>(y + 1, -(long long)1e18)) - 1;     return mp[y][x] = (itr > 0 ? seg[itr]->rmq(x, y) : 0);     set<int> second;     for (int i = x; i < y + 1; i++) second.insert(A[i]);     return second.size();   }   void dnc(int st, int en, int x, int y, int k) {     if (st > en) return;     int opt_pos = x;     int mid = (st + en) / 2;     for (int i = min(y, mid); i >= x; i--) {       if (dp[mid][k] < dp[i - 1][k - 1] + RMQ(i, mid)) {         opt_pos = i;         dp[mid][k] = dp[i - 1][k - 1] + RMQ(i, mid);       }     }     if (st < mid) dnc(st, mid - 1, x, opt_pos, k);     if (mid < en) dnc(mid + 1, en, opt_pos, y, k);   }   vector<int> val[35006];   void solve() {     for (int i = 1; i < n + 1; i++) {       assert(A[i] <= 35000);       val[A[i]].push_back(i);     }     for (int i = 1; i < n + 1; i++) {       val[A[i]].push_back(n + 1);     }     for (int i = 1; i < n + 1; i++)       v.push_back(pair<int, int>(           *upper_bound((val[A[i]]).begin(), (val[A[i]]).end(), i), i));     sort((v).begin(), (v).end(), greater<pair<int, int> >());     seg[0] = new node(1, n + 1, 1);     for (int i = 0; i < v.size(); i++) {       seg[i + 1] = seg[i]->update(v[i].second, 1);     }     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> k;     for (int i = 1; i < n + 1; i++) cin >> A[i];     solve();     unordered_set<int> second;     for (int i = 1; i < n + 1; i++) {       second.insert(A[i]);       dp[i][1] = second.size();     }     for (int i = 2; i < k + 1; i++) {       dnc(1, n, 1, n, i);     }     cout << dp[n][k] <<   n ;   }


#include <bits/stdc++.h>   namespace io {   const char endl =   n ;   template <typename T>   inline void chkmin(T &a, T b) {     a > b ? a = b : 0;   }   template <typename T>   inline void chkmax(T &a, T b) {     a < b ? a = b : 0;   }   struct Stream {     template <class T>     Stream operator>>(T &x) {       x = 0;       register int f = 1;       register char c;       while (!isdigit(c = getchar()))         if (c ==  - ) f = -1;       while (x = (x << 1) + (x << 3) + (c ^ 48), isdigit(c = getchar()))         ;       return x *= f, *this;     }     Stream operator>>(char *str) { return scanf( %s , str), *this; }     template <class T>     Stream operator<<(T x) {       static char out[35];       static unsigned int top = 0;       if (x < 0) x = -x, putchar( - );       while (out[++top] = x % 10 ^ 48, x /= 10, x)         ;       while (putchar(out[top--]), top)         ;       return *this;     }     Stream operator<<(char *str) { return printf( %s , str), *this; }     Stream operator<<(char ch) { return putchar(ch), *this; }   } cin, cout;   }  // namespace io   const int N = 3e5 + 10;   int ver[N * 2], nxt[N * 2], head[N], tot, n, m, stk[N], top, L[N];   inline void add(int u, int v) {     ver[++tot] = v, nxt[tot] = head[u], head[u] = tot;   }   bool vis[N], loop[N];   void DFS(int u, int fa) {     vis[u] = 1;     stk[++top] = u;     for (int i = head[u]; i; i = nxt[i]) {       int v = ver[i];       if (loop[v] or v == fa) continue;       if (!vis[v])         DFS(v, u);       else {         int Max = 0, Min = n + 1;         for (int j = top, y;; j--) {           y = stk[j];           io::chkmin(Min, y);           io::chkmax(Max, y);           loop[y] = 1;           if (stk[j] == v) break;         }         if (!L[Max])           L[Max] = Min;         else           io::chkmax(L[Max], Min);       }     }     top--;   }   long long sum[N];   int main() {     io::cin >> n >> m;     for (register unsigned int i = 1, iend = m; i <= iend; ++i) {       int u, v;       io::cin >> u >> v;       add(u, v), add(v, u);     }     for (register unsigned int i = 1, iend = n; i <= iend; ++i)       if (!vis[i]) DFS(i, i);     for (register unsigned int i = 1, iend = n; i <= iend; ++i) {       io::chkmax(L[i], L[i - 1]);       sum[i] = sum[i - 1] + L[i];     }     int Q;     io::cin >> Q;     while (Q--) {       int x, y;       io::cin >> x >> y;       int l = x, r = y, p = y + 1;       long long ans = 0;       while (l <= r) {         int mid = (l + r) >> 1;         if (L[mid] >= x)           r = mid - 1, p = mid;         else           l = mid + 1;       }       ans = 1ll * (x + y) * (y - x + 1) / 2 - (sum[y] - sum[p - 1]) -             1ll * (x - 1) * (p - x);       io::cout << ans << io::endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 100005;   const long long LL_INF = (long long)2e18 + 5;   inline int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   const long long mod = 1000000007;   bool isprime(long long n) {     for (long long i = 2; i * i <= n; ++i) {       if (n % i == 0) {         return false;       }     }     return true;   }   long long factorial(long long n) {     return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);   }   long long power(long long x, long long y) {     long long res = 1;     x = x % mod;     while (y > 0) {       if (y & 1) res = ((res % mod) * (x % mod)) % mod;       y = y >> 1;       x = ((x % mod) * (x % mod)) % mod;     }     return res;   }   long long ncr(long long n, long long r) {     long long res = 1;     if (r > n) return 0;     if (r > n - r) r = n - r;     for (long long i = 0; i < r; i++) {       res = ((res % mod) * ((n - i) % mod)) % mod;       res = ((res % mod) * (power(i + 1, mod - 2)) % mod) % mod;     }     return res;   }   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long lcm(long long a, long long b) { return (a / gcd(a, b) * b); }   long long max(long long a, long long b) {     long long sol = a > b ? a : b;     return sol;   }   long long min(long long a, long long b) {     long long sol = a < b ? a : b;     return sol;   }   map<long long, long long> mp;   inline void solve() {     long long n, k;     long long a[26] = {0};     cin >> n >> k;     string s;     cin >> s;     char ch;     while (k--) {       cin >> ch;       a[ch -  a ]++;     }     long long prev = -1, r;     long long ans = 0;     for (int i = 0; i < n; i++) {       if (a[s[i] -  a ] == 0) {         r = i - prev - 1;         ans += ((r * (r + 1)) / 2);         prev = i;       }     }     r = n - prev - 1;     ans += ((r * (r + 1)) / 2);     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     solve();   }


#include <bits/stdc++.h>   using namespace std;   string p;   bool cap = false, l = false, dig = false;   char digits[10] = { 0 ,  1 ,  2 ,  3 ,  4 ,  5 ,  6 ,  7 ,  8 ,  9 };   int main() {     cin >> p;     int s = p.length();     if (s < 5) {       cout <<  Too weak ;       return 0;     }     for (int i = 0; i < s; i++) {       if (isupper(p[i]))         cap = true;       else if (islower(p[i]))         l = true;       for (int j = 0; j < 10; j++)         if (p[i] == digits[j]) dig = true;     }     if (cap == true && l == true && dig == true)       cout <<  Correct ;     else       cout <<  Too weak ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     int n1, n2, n3;     cin >> n1 >> n2 >> n3;     vector<int> v[n + 1];     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       v[a].push_back(b);       v[b].push_back(a);     }     auto out = []() {       cout <<  NO n ;       exit(0);     };     if (n2 == 0) {       if (m == 0) {         cout <<  YES n ;         cout << string(n1,  1 ) + string(n3,  3 ) <<   n ;         exit(0);       } else         out();     }     vector<int> vis(n + 1, 0);     vector<vector<int>> one;     vector<vector<int>> two;     vector<vector<array<int, 2>>> dp(n + 1, vector<array<int, 2>>(n + 1, {0, 0}));     dp[0][0] = {-1, 1};     int comp = 0;     for (int i = 1; i <= n; i++) {       if (vis[i] != 0) continue;       comp++;       queue<int> q;       q.push(i);       vis[i] = 1;       vector<int> d[3];       vector<int> cnt(3, 0);       d[1].push_back(i);       cnt[1] = 1;       while (!q.empty()) {         int x = q.front();         q.pop();         for (int to : v[x]) {           if (vis[to] == 0) {             q.push(to);             vis[to] = 3 - vis[x];             d[vis[to]].push_back(to);             cnt[vis[to]]++;           } else if (vis[to] == vis[x])             out();         }       }       one.push_back(d[1]);       two.push_back(d[2]);       for (int j = 0; j <= n; j++) {         if (dp[comp - 1][j][1] == 0) continue;         for (int k = 1; k <= 2; k++)           if (dp[comp][j + cnt[k]][1] == 0)             dp[comp][j + cnt[k]] = {(int)one.size() - 1, k};       }     }     if (dp[comp][n2][1] == 0) out();     string res(n + 1,  0 );     int c = comp;     int now = n2;     while (now > 0) {       if (dp[c][now][1] == 1) {         for (int x : one[dp[c][now][0]]) res[x] =  2 ;         now -= one[dp[c][now][0]].size();       } else {         for (int x : two[dp[c][now][0]]) res[x] =  2 ;         now -= two[dp[c][now][0]].size();       }       c--;     }     for (int i = 1; i <= n; i++) {       if (res[i] ==  2 ) continue;       if (n1 > 0) {         res[i] =  1 ;         n1--;       } else         res[i] =  3 ;     }     cout <<  YES n ;     cout << res.substr(1, n) <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma GCC optimize(3)   using namespace std;   inline int read() {     int x = 0, neg = 1;     char op = getchar();     while (!isdigit(op)) {       if (op ==  - ) neg = -1;       op = getchar();     }     while (isdigit(op)) {       x = 10 * x + op -  0 ;       op = getchar();     }     return neg * x;   }   inline void print(int x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x >= 10) print(x / 10);     putchar(x % 10 +  0 );   }   const int N = 1000005;   long long f[N], g[N];   int k, q, mul = 1;   void ckmax(long long &a, long long b) {     if (a < b) a = b;   }   void work() {     int tmp = k, t = 1, x;     x = read();     memset(g, 192, sizeof(g));     for (int v = 0; v < 10; v++) {       long long cost = 1ll * mul * v;       long long w = v % 3 == 0 ? 1ll * (v / 3) * x : 0;       for (int i = 0; i < N - cost; i++) {         ckmax(g[i + cost], f[i] + w);       }     }     memcpy(f, g, sizeof(g));     while (tmp > t) {       tmp -= t;       long long cost = 1ll * mul * t;       cost *= 3;       long long w = 1ll * x * t;       if (cost < N) {         for (int i = N - 1; i >= cost; i--) {           ckmax(f[i], f[i - cost] + w);         }       }       t <<= 1;     }     long long cost = 1ll * mul * tmp;     cost *= 3;     long long w = 1ll * x * tmp;     if (cost < N) {       for (int i = N - 1; i >= cost; i--) {         ckmax(f[i], f[i - cost] + w);       }     }     mul *= 10;   }   int main() {     k = (read() - 1) * 3;     memset(f, 192, sizeof(f)), f[0] = 0;     for (int i = 1; i <= 6; i++) work();     q = read();     while (q--) {       int x = read();       printf( %lld n , f[x]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef pair<long long, long long> pii;   typedef vector<long long> vi;   typedef vector<pii> vpii;   typedef vector<vi> vvi;   double prob[20][20];   double dp[(1 << 19)];   double pmove(long long prev_mask, long long j, long long n) {     long long k = __builtin_popcount(prev_mask);     long long den = k * (k - 1) / 2;     double moveprob = 0;     for (long long i = (0); i < (n); i += 1) {       if ((1 << i) & prev_mask) {         moveprob += prob[i][j];       }     }     return moveprob / (1.0 * den);   }   double get_ans(long long mask, long long n) {     long long alive = __builtin_popcount(mask);     if (alive == n) return 1;     if (dp[mask] > -0.9) return dp[mask];     double ans = 0;     for (long long i = (0); i < (n); i += 1) {       if (!(mask & (1 << i))) {         long long prev_mask = mask ^ (1 << i);         ans += get_ans(prev_mask, n) * pmove(prev_mask, i, n);       }     }     return dp[mask] = ans;   }   void solve() {     long long n;     cin >> n;     memset(dp, -1, sizeof dp);     for (long long i = (0); i < (n); i += 1)       for (long long j = (0); j < (n); j += 1) cin >> prob[i][j];     for (long long i = (0); i < (n); i += 1) {       printf( %.6lf  , get_ans((1 << i), n));     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 1e9;   int n, q;   int a[400005];   struct rmq {     int tree[1050000], lim;     void init(int n) {       memset(tree, 0, sizeof(tree));       for (lim = 1; lim <= n; lim <<= 1)         ;     }     void add(int x, int v) {       x += lim;       tree[x] = max(tree[x], v);       while (x > 1) {         x >>= 1;         tree[x] = max(tree[2 * x], tree[2 * x + 1]);       }     }     int query(int s, int e) {       s += lim;       e += lim;       int ret = 0;       while (s < e) {         if (s % 2 == 1) ret = max(ret, tree[s++]);         if (e % 2 == 0) ret = max(ret, tree[e--]);         s >>= 1;         e >>= 1;       }       if (s == e) ret = max(ret, tree[s]);       return ret;     }   } rmq;   int dpl[400005], dpr[400005], lis;   int cnt[400005];   bool check_indep(int x) {     return cnt[dpr[x]] != 1 || dpl[x] + dpr[x] != lis + 1;   }   int is_indep[400005];   int aux[400005], ret[400005];   struct query {     int x, y, idx;     bool operator<(const query &q) const { return x < q.x; }   };   int main() {     scanf( %d %d , &n, &q);     vector<int> v;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       v.push_back(a[i]);     }     sort(v.begin(), v.end());     v.resize(unique(v.begin(), v.end()) - v.begin());     for (int i = 1; i <= n; i++) {       a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1;     }     rmq.init(n);     for (int i = 1; i <= n; i++) {       dpl[i] = rmq.query(1, a[i] - 1) + 1;       rmq.add(a[i], dpl[i]);     }     rmq.init(n);     for (int i = n; i; i--) {       dpr[i] = rmq.query(a[i] + 1, n) + 1;       rmq.add(a[i], dpr[i]);     }     for (int i = 1; i <= n; i++) {       lis = max(lis, dpl[i]);     }     for (int i = 1; i <= n; i++) {       if (dpl[i] + dpr[i] == lis + 1) {         cnt[dpr[i]]++;       }     }     for (int i = 1; i <= n; i++) {       is_indep[i] = check_indep(i);     }     vector<query> qr;     for (int i = 0; i < q; i++) {       int x, y;       scanf( %d %d , &x, &y);       if (is_indep[x]) {         ret[i] = lis;       } else         ret[i] = lis - 1;       qr.push_back({x, y, i});     }     sort(qr.begin(), qr.end());     rmq.init(n);     int pnt = 1;     for (int i = 0; i < q; i++) {       while (pnt <= n && pnt < qr[i].x) {         rmq.add(a[pnt], dpl[pnt]);         pnt++;       }       int sy = lower_bound(v.begin(), v.end(), qr[i].y) - v.begin();       aux[qr[i].idx] += rmq.query(1, sy);     }     pnt = n;     rmq.init(n);     for (int i = q - 1; i >= 0; i--) {       while (pnt && pnt > qr[i].x) {         rmq.add(a[pnt], dpr[pnt]);         pnt--;       }       int ey = upper_bound(v.begin(), v.end(), qr[i].y) - v.begin() + 1;       aux[qr[i].idx] += rmq.query(ey, n);     }     for (int i = 0; i < q; i++) {       ret[i] = max(ret[i], aux[i] + 1);       printf( %d n , ret[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   const int n0 = 1 << 17;   const long long inf = 1e18;   int n, a[n0], q;   long long d[n0], gaps;   struct Node {     int l = 0, r = 0;     long long val[3];     Node() { val[0] = val[1] = val[2] = -inf; }     void init(int pos) {       l = r = pos;       if (l < 2 || l > n - 1) {         val[0] = val[1] = val[2] = -inf;         return;       }       long long d1 = d[l - 1], d2 = d[l];       long long t = -abs(d1) - abs(d2);       val[0] = d1 - d2 + t;       val[1] = max(d1 + d2, -d1 - d2) + t;       val[2] = -d1 + d2 + t;     }     void merge(Node &x, Node &y) {       if (!x.l) {         x = y;         return;       }       l = x.l, r = y.r;       for (int i = 0; i < 3; i++) val[i] = max(x.val[i], y.val[i]);     }     long long get(long long x) {       return max({-2 * x + val[0], val[1], 2 * x + val[2]});     }   };   struct Segtree {     Node t[n0 << 1];     void build() {       for (int i = (n0 << 1) - 1; i > 0; i--) {         if (i >= n0)           t[i].init(i - n0);         else           t[i].merge(t[i << 1], t[i << 1 | 1]);       }     }     void upd(int x) {       t[x + n0].init(x);       for (x += n0; x > 1; x /= 2) t[x >> 1].merge(t[x], t[x ^ 1]);     }     Node get(int l, int r) {       r++;       Node res;       for (l += n0, r += n0; l < r; l /= 2, r /= 2) {         if (l & 1) res.merge(res, t[l++]);         if (r & 1) res.merge(res, t[--r]);       }       return res;     }   };   Segtree st;   void upd(int x, int y) {     gaps -= abs(d[x]);     d[x] += y;     gaps += abs(d[x]);     st.upd(x), st.upd(x + 1);   }   long long get(int l, int r, long long x) {     long long res = st.get(l, r).get(x);     if (l == 1) res = max(res, abs(d[1] + x) - abs(d[1]));     if (r == n) res = max(res, abs(d[n - 1] - x) - abs(d[n - 1]));     return gaps + res;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n - 1; i++) d[i] = a[i] - a[i + 1], gaps += abs(d[i]);     st.build();     cin >> q;     while (q--) {       int t, l, r, x;       cin >> t >> l >> r >> x;       if (t == 1) {         cout << get(l, r, x) <<   n ;       } else {         upd(l - 1, -x), upd(r, x);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-7;   const int inf = 1000000010;   const int mod = 1000000007;   const int MAXN = 1010;   int n, m, t, x, y, xx, yy, ans, v, u, q, a, b, c, cnt;   string A[MAXN];   int dist[MAXN][MAXN];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> A[i];       A[i] =  .  + A[i];       for (int j = 1; j <= m; j++) {         if (A[i][j] ==  S ) {           xx = i;           yy = j;         }         if (A[i][j] ==  E ) {           x = i;           y = j;         }       }     }     queue<pair<int, int> > q;     q.push({x, y});     memset(dist, 63, sizeof(dist));     dist[x][y] = 0;     while (!q.empty()) {       int x = q.front().first, y = q.front().second;       q.pop();       if (dist[x][y] > dist[xx][yy]) break;       if (x < 1 || y < 1 || x > n || y > m || A[x][y] ==  T ) continue;       if (dist[x][y] + 1 < dist[x + 1][y]) {         dist[x + 1][y] = dist[x][y] + 1;         q.push({x + 1, y});       }       if (dist[x][y] + 1 < dist[x][y + 1]) {         dist[x][y + 1] = dist[x][y] + 1;         q.push({x, y + 1});       }       if (dist[x][y] + 1 < dist[x - 1][y]) {         dist[x - 1][y] = dist[x][y] + 1;         q.push({x - 1, y});       }       if (dist[x][y] + 1 < dist[x][y - 1]) {         dist[x][y - 1] = dist[x][y] + 1;         q.push({x, y - 1});       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (A[i][j] ==  S  || A[i][j] ==  E  || A[i][j] ==  T ) continue;         if (dist[i][j] <= dist[xx][yy]) ans += A[i][j] -  0 ;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxt = 1000000, maxn = maxt + 7;   int h[7][7];   char s[5][maxn];   void output(int n) {     for (int i = 1; i <= 4; i++) {       for (int j = 1; j <= n; j++) printf( %c , s[i][j]);       puts(  );     }   }   bool DoIt_2(int I, int n, int tot) {     for (int i = 1; i <= n; i++)       if (s[2][i] != s[I][i]) tot--;     if (tot < 0) return false;     if (tot == 0) return true;     if (tot % 2 == 1) return false;     vector<int> A, B;     A.clear(), B.clear();     for (int i = 1; i <= n; i++)       if (s[2][i] == s[I][i]) {         if (s[2][i] ==  a ) A.push_back(i);         if (s[2][i] ==  b ) B.push_back(i);       }     for (int i = 0; i < min(A.size(), B.size()); i++) {       int x = A[i], y = B[i];       tot -= 2;       swap(s[I][x], s[I][y]);       if (tot == 0) return true;     }     return false;   }   bool DoIt_3(int I, int n, int tot) {     for (int i = 1; i <= n; i++)       if (s[3][i] != s[I][i]) tot--;     if (tot < 0) return false;     if (tot == 0) return true;     if (tot % 2 == 1) return false;     vector<int> AA, AB, BA, BB;     AA.clear(), AB.clear(), BA.clear(), BB.clear();     for (int i = 1; i <= n; i++)       if (s[3][i] == s[I][i]) {         if (s[2][i] ==  a  && s[3][i] ==  a ) AA.push_back(i);         if (s[2][i] ==  a  && s[3][i] ==  b ) AB.push_back(i);         if (s[2][i] ==  b  && s[3][i] ==  a ) BA.push_back(i);         if (s[2][i] ==  b  && s[3][i] ==  b ) BB.push_back(i);       }     for (int i = 0; i < min(AA.size(), AB.size()); i++) {       int x = AA[i], y = AB[i];       tot -= 2;       swap(s[I][x], s[I][y]);       if (tot == 0) return true;     }     for (int i = 0; i < min(BA.size(), BB.size()); i++) {       int x = BA[i], y = BB[i];       tot -= 2;       swap(s[I][x], s[I][y]);       if (tot == 0) return true;     }     return false;   }   bool check(int n) {     for (int i = 1; i <= 4; i++)       for (int j = 1; j <= n; j++) s[i][j] =  a ;     for (int i = 2; i <= 4; i++)       for (int j = 1; j <= h[1][i]; j++) s[i][j] =  b ;     for (int i = 3; i <= 4; i++)       if (!DoIt_2(i, n, h[2][i])) return false;     if (!DoIt_3(4, n, h[3][4])) return false;     return true;   }   int main() {     for (int i = 1; i <= 4; i++)       for (int j = i + 1; j <= 4; j++) scanf( %d , &h[i][j]);     int head = 1, tail = maxt;     while (head <= tail) {       int mid = (head + tail) / 2;       if (check(mid))         tail = mid - 1;       else         head = mid + 1;     }     int n = tail + 1;     if (n > maxt) {       puts( -1 );       return 0;     }     printf( %d n , n);     check(n);     output(n);   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 5;   map<pair<int, long long>, bool> vis;   map<pair<int, long long>, int> memo;   int grundy(int x, long long mask) {     for (int i = 61; i > x; i--) {       if ((mask >> i) & 1) mask ^= (1ll << i);     }     if (vis[{x, mask}]) return memo[{x, mask}];     vis[{x, mask}] = 1;     set<int> s;     for (int i = 1; i <= x; i++) {       if ((mask >> i) & 1) {         s.insert(grundy(x - i, mask ^ (1ll << i)));       }     }     int res = 0;     while (s.find(res) != s.end()) res++;     return memo[{x, mask}] = res;   }   int n;   int s[MAXN];   int main() {     scanf( %d , &n);     int res = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , s + i);       res ^= grundy(s[i], (1ll << 61) - 1);     }     if (res)       puts( NO );     else       puts( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     int div[] = {1, 2, 3, 4, 6, 12};     while (t--) {       string s;       cin >> s;       vector<pair<int, int> > dimen;       int n, m;       int i, j, k;       for (k = 0; k < 6; k++) {         n = div[k];         m = 12 / n;         for (j = 0; j < m; j++) {           for (i = 0; i < n; i++) {             if (s[i * m + j] !=  X ) break;           }           if (i == n) {             dimen.push_back(make_pair(n, m));             break;           }         }       }       cout << dimen.size() <<    ;       for (int i = 0; i < dimen.size(); i++)         cout << dimen[i].first <<  x  << dimen[i].second <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string gen[100];   string merge(string s1, string s2) {     int e = s1.size() - 1;     for (int i = 0; i < s2.size(); i++) {       if (s1[0] == s2[i]) {         int k = s2.size() - i;         if (k <= s1.size()) {           s1.erase(0, k);           return s2 + s1;         }         return s2;       }       if (s1[e] == s2[i]) {         if (e - i >= 0) {           s1.erase(e - i, i + 1);           return s1 + s2;         }         return s2;       }     }     return  0 ;   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> gen[i];     }     bool f = true;     for (int k = 0; k < n; k++) {       f = true;       while (f && gen[k] !=   ) {         f = false;         for (int i = k + 1; i < n; i++) {           if (gen[i] !=   ) {             string s;             if (gen[i].length() < gen[k].length()) {               s = merge(gen[i], gen[k]);             } else {               s = merge(gen[k], gen[i]);             }             if (s !=  0 ) {               gen[k] = s;               gen[i] =   ;               f = true;               break;             }           }         }       }     }     string s3;     for (int i = 0; i < n; i++) {       s3 += gen[i];     }     cout << s3;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, long long> frequency(vector<long long> v) {     map<long long, long long> m;     for (long long i = 0; i < v.size(); i++) {       if (m.find(v[i]) != m.end())         m[v[i]]++;       else {         m.insert({v[i], 1});       }     }     return m;   }   void input(vector<long long>& v, long long n) {     for (long long i = 0; i < (long long)(n); i++) {       long long in;       cin >> in;       v.push_back(in);     }   }   void output(vector<long long> v) {     for (long long i = 0; i < (long long)(v.size()); i++) cout << v[i] <<    ;   }   void solve() {     long long a, b, c, d;     cin >> a >> b >> c >> d;     long long m = max((3 * a) / 10, a - (a / 250) * c);     long long v = max((3 * b) / 10, b - (b / 250) * d);     if (m > v) {       cout <<  Misha  << endl;     } else if (v > m) {       cout <<  Vasya  << endl;     } else {       cout <<  Tie  << endl;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const long long bl_size = 320;   int n, m;   long long k;   long long res;   long long a[100005];   unordered_map<long long, long long> cnt;   struct Query {     int l, r, id;     bool operator<(Query other) const {       if (l / bl_size != other.l / bl_size)         return l < other.l;       else         return (l / bl_size & 1) ? (r < other.r) : (r > other.r);     }   };   void add(long long x) {     long long y = x ^ k;     res += cnt[y];     cnt[x]++;   }   void rem(long long x) {     long long y = x ^ k;     if (y != x)       res -= (cnt[y]);     else       res -= (cnt[y] - 1);     cnt[x]--;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     scanf( %d%d%d , &n, &m, &k);     long long prev[n + 10];     prev[0] = 0;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), prev[i] = prev[i - 1] ^ a[i];     Query q[100005];     for (int i = 1; i <= m; i++) {       scanf( %d%d , &q[i].l, &q[i].r);       q[i].l--;       q[i].id = i;     }     sort(q + 1, q + n + 1);     res = 0;     long long ans[m + 10];     int cur_l = 0, cur_r = -1;     for (int i = 1; i <= m; i++) {       while (cur_l > q[i].l) {         cur_l--;         add(prev[cur_l]);       }       while (cur_l < q[i].l) {         rem(prev[cur_l]);         cur_l++;       }       while (cur_r > q[i].r) {         rem(prev[cur_r]);         cur_r--;       }       while (cur_r < q[i].r) {         cur_r++;         add(prev[cur_r]);       }       ans[q[i].id] = res;     }     for (int i = 1; i <= m; i++) cout << ans[i] << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 1e5 + 10;   const int LG = 20;   int power(int a, int b) {     int res = 1;     while (b > 0) {       if (b & 1) {         res = 1LL * res * a % mod;       }       a = 1LL * a * a % mod;       b >>= 1;     }     return res;   }   int seg[4 * N], lazy[4 * N];   void update(int node, int start, int end, int l, int r, int val) {     if (lazy[node]) {       seg[node] += lazy[node];       if (start != end) {         lazy[node << 1] += lazy[node];         lazy[node << 1 | 1] += lazy[node];       }       lazy[node] = 0;     }     if (start > end || r < start || end < l) return;     if (l <= start && end <= r) {       seg[node] += val;       if (start != end) {         lazy[node << 1] += val;         lazy[node << 1 | 1] += val;       }       return;     }     int mid = (start + end) >> 1;     update(node << 1, start, mid, l, r, val);     update(node << 1 | 1, mid + 1, end, l, r, val);     seg[node] = min(seg[node << 1], seg[node << 1 | 1]);   }   int query(int node, int start, int end, int l, int r) {     if (lazy[node]) {       seg[node] += lazy[node];       if (start != end) {         lazy[node << 1] += lazy[node];         lazy[node << 1 | 1] += lazy[node];       }       lazy[node] = 0;     }     if (start > end || r < start || end < l) return 1e9;     if (l <= start && end <= r) {       return seg[node];     }     int mid = (start + end) >> 1;     return min(query(node << 1, start, mid, l, r),                query(node << 1 | 1, mid + 1, end, l, r));   }   int main() {     int n, m, a[N], ans = 0, idx = 0;     vector<pair<int, int> > lft[N], rght[N];     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       update(1, 1, n, i, i, a[i]);     }     for (int i = 1; i <= m; i++) {       int l, r;       scanf( %d %d , &l, &r);       lft[r].push_back({l, i});       rght[l].push_back({r, i});     }     for (int i = 1; i <= n; i++) {       int val = a[i] - query(1, 1, n, 1, i - 1);       if (val > ans) {         idx = i;         ans = val;       }       for (auto l : lft[i]) {         update(1, 1, n, l.first, i, -1);       }     }     memset(seg, 0, sizeof(seg));     memset(lazy, 0, sizeof(lazy));     for (int i = 1; i <= n; i++) {       update(1, 1, n, i, i, a[i]);     }     for (int i = n; i >= 1; i--) {       int val = a[i] - query(1, 1, n, i + 1, n);       if (val > ans) {         idx = -i;         ans = val;       }       for (auto r : rght[i]) {         update(1, 1, n, i, r.first, -1);       }     }     printf( %d n , ans);     vector<int> res;     if (idx > 0) {       for (int i = 1; i < idx; i++) {         for (auto j : lft[i]) {           res.push_back(j.second);         }       }     } else if (idx < 0) {       for (int i = n; i > abs(idx); i--) {         for (auto j : rght[i]) {           res.push_back(j.second);         }       }     }     printf( %d n , res.size());     for (int pp : res) {       printf( %d  , pp);     }     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 1e5 * 5;   const int INF = 1e9 + 7;   using namespace std;   long long f[501][501];   long long a[501][501];   int n, p[501];   long long ans[501];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) cin >> a[i][j];     for (int i = 1; i <= n; i++) cin >> p[i];     for (int t = n; t >= 1; --t) {       int u = p[t];       long long res = 0;       for (int i = t + 1; i <= n; i++) {         int x = p[i];         f[u][x] = a[u][x];         f[x][u] = a[x][u];         for (int j = t + 1; j <= n; j++)           if (i != j) {             int y = p[j];             f[u][x] = min(f[u][x], a[u][y] + f[y][x]);             f[x][u] = min(f[x][u], f[x][y] + a[y][u]);           }       }       for (int i = t + 1; i <= n; i++)         for (int j = t + 1; j <= n; j++) {           int x = p[i], y = p[j];           f[x][y] = min(f[x][y], f[x][u] + f[u][y]);         }       for (int i = t; i <= n; i++)         for (int j = t; j <= n; j++) res += f[p[i]][p[j]];       ans[t] = res;     }     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mn = 100010;   long long x[mn], y[mn];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lld %lld , &x[i], &y[i]);     if (n <= 4) {       printf( YES n );       return 0;     }     bool flag = 0;     for (int i = 1; i <= 2; i++) {       for (int j = i + 1; j <= 3; j++) {         long long a = y[j] - y[i];         long long b = x[i] - x[j];         long long c = y[i] * x[j] - y[j] * x[i];         long long xa, ya, xb, yb;         int t = 0;         int k = 1;         for (k = 1; k <= n; k++) {           if (a * x[k] + b * y[k] + c == 0)             continue;           else {             t++;             if (t == 1)               xa = x[k], ya = y[k];             else if (t == 2)               xb = x[k], yb = y[k];             else               break;           }         }         if (t <= 2) {           flag = 1;           break;         }         long long ta = yb - ya;         long long tb = xa - xb;         long long tc = ya * xb - yb * xa;         bool q = 0;         for (int p = k; p <= n; p++) {           if ((a * x[p] + b * y[p] + c == 0) || ta * x[p] + tb * y[p] + tc == 0)             continue;           else             q = 1;           if (q) break;         }         if (!q) {           flag = 1;           break;         }       }       if (flag) break;     }     if (!flag)       printf( NO n );     else       printf( YES n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   vector<int> divs[N];   vector<int> mult[N];   int mu[N], a[N], n;   int cnt[N];   long long res = 0;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     mu[1] = 1;     for (int i = 1; i < N; i++) {       divs[i].push_back(i);       for (int j = 2 * i; j < N; j += i) {         divs[j].push_back(i);         mu[j] -= mu[i];       }     }     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       for (int e : divs[a[i]]) mult[e].push_back(a[i] / e);     }     for (int i = 1; i < N; i++) {       sort(mult[i].begin(), mult[i].end(),            [](int first, int second) { return first > second; });       stack<int> st;       for (int e : mult[i]) {         int ans = 0;         for (int div : divs[e]) {           ans -= mu[div] * cnt[div];         }         while (ans != 0) {           int u = st.top();           st.pop();           for (int div : divs[u]) {             cnt[div]--;             if (e % div == 0) ans += mu[div];           }           if (ans == 0) res = max(res, 1LL * i * e * u);         }         st.push(e);         for (int div : divs[e]) cnt[div]++;       }       for (int e : mult[i]) {         for (int div : divs[e]) cnt[div] = 0;       }     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   const double PI = acos(-1.0);   int main() {     double n, r;     scanf( %lf%lf , &n, &r);     double p1 = PI / n, p2 = PI / (2 * n), p3 = PI - p1 - p2;     double l3 = r, l2 = l3 / sin(p3) * sin(p2);     double s = l3 * l2 * sin(p1);     printf( %.15f n , n * s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n, m, k, t, mx;     cin >> t;     while (t--) {       cin >> n >> m >> k;       mx = min(n / k, m);       cout << (m >= mx ? mx - ceil((long double)(m - mx) / (k - 1)) : mx) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = x * 10 + c -  0 , c = getchar();     }     return x * f;   }   const int MAXN = 1e5 + 10;   const long long INF = 3e18;   int n;   long long x[MAXN], y[MAXN], z[MAXN], foo, bar, baz;   inline void Min(long long &x, long long y) {     if (x > y) x = y;   }   inline void Max(long long &x, long long y) {     if (x < y) x = y;   }   inline bool check(long long mid) {     static long long L[5], R[5];     for (int i = 1; i <= 4; i++) L[i] = -INF, R[i] = INF;     for (int i = 1; i <= n; i++) {       long long A = x[i], B = y[i], C = z[i];       Max(L[1], A + B + C - mid);       Min(R[1], A + B + C + mid);       Max(L[2], -A + B + C - mid);       Min(R[2], -A + B + C + mid);       Max(L[3], A - B + C - mid);       Min(R[3], A - B + C + mid);       Max(L[4], A + B - C - mid);       Min(R[4], A + B - C + mid);     }     for (int i = 0; i < 2; i++) {       static long long l[5], r[5];       for (int j = 1; j <= 4; j++)         l[j] = ((L[j] & 1) == i) ? L[j] : L[j] + 1,         r[j] = ((R[j] & 1) == i) ? R[j] : R[j] - 1;       long long low = l[2] + l[3] + l[4];       long long high = r[2] + r[3] + r[4];       for (int j = 1; j <= 4; j++)         if (l[j] > r[j]) goto finish;       if (low > r[1] || high < l[1]) goto finish;       l[1] -= low, r[1] -= low;       if (l[1] <= 0) {         foo = l[2];         bar = l[3];         baz = l[4];         return 1;       }       for (int j = 2; j <= 4; j++) r[j] -= l[j];       if (l[1] <= r[2]) {         foo = l[2] + l[1];         bar = l[3];         baz = l[4];         return 1;       }       l[1] -= r[2];       if (l[1] <= r[3]) {         foo = l[2] + r[2];         bar = l[3] + l[1];         baz = l[4];         return 1;       }       l[1] -= r[3];       if (l[1] <= r[4]) {         foo = l[2] + r[2];         bar = l[3] + r[3];         baz = l[4] + l[1];         return 1;       }     finish:;     }     return 0;   }   int main() {     int t = read();     while (t--) {       n = read();       for (int i = 1; i <= n; i++) x[i] = read(), y[i] = read(), z[i] = read();       long long l = 0, r = 3e18, ans = -1;       while (l <= r) {         long long mid = (l + r) >> 1;         if (check(mid))           r = mid - 1, ans = mid;         else           l = mid + 1;       }       assert(ans != -1);       printf( %lld %lld %lld n , (bar + baz) / 2, (foo + baz) / 2,              (foo + bar) / 2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf(101010101010101010LL);   int n;   struct uf {     int par[1005];     uf() {       for (int i(0); i < (n); i++) par[i] = i;     }     int ff(int x) { return par[x] == x ? x : par[x] = ff(par[x]); }     void uu(int x, int y) {       x = ff(x), y = ff(y);       if (x - y) par[x] = y;     }   };   vector<pair<int, int> > edges;   vector<int> eA, eB;   char col[20];   int main() {     cin >> n;     int m;     cin >> m;     edges.resize(m);     uf fA, fB;     for (int id(0); id < (m); id++) {       int x, y;       scanf( %d%d%s , &x, &y, col);       x--, y--;       edges[id] = make_pair(x, y);       if (col[0] ==  S ) {         if (fA.ff(x) == fA.ff(y)) continue;         eA.push_back(id), fA.uu(x, y);       } else {         if (fB.ff(x) == fB.ff(y)) continue;         eB.push_back(id), fB.uu(x, y);       }     }     uf fAB_1;     for (__typeof((eA).end()) it((eA).begin()); it != (eA).end(); ++it) {       int id(*it), x(edges[id].first), y(edges[id].second);       fAB_1.uu(x, y);     }     vector<int> eB_selected;     for (__typeof((eB).end()) it((eB).begin()); it != (eB).end(); ++it) {       int id(*it), x(edges[id].first), y(edges[id].second);       if (fAB_1.ff(x) != fAB_1.ff(y)) {         eB_selected.push_back(id);         fAB_1.uu(x, y);       }     }     uf fAB_2;     int nA(0), nB(((int)(eB_selected).size()));     for (__typeof((eB_selected).end()) it((eB_selected).begin());          it != (eB_selected).end(); ++it) {       int id(*it), x(edges[id].first), y(edges[id].second);       fAB_2.uu(x, y);     }     for (__typeof((eB).end()) it((eB).begin()); it != (eB).end(); ++it)       if (nB < (n - 1) / 2) {         int id(*it), x(edges[id].first), y(edges[id].second);         if (fAB_2.ff(x) != fAB_2.ff(y)) {           eB_selected.push_back(id);           fAB_2.uu(x, y);           nB++;         }       }     vector<int> eA_selected;     for (__typeof((eA).end()) it((eA).begin()); it != (eA).end(); ++it) {       int id(*it), x(edges[id].first), y(edges[id].second);       if (fAB_2.ff(x) != fAB_2.ff(y)) {         eA_selected.push_back(id);         fAB_2.uu(x, y);         nA++;       }     }     if (nA != (n - 1) / 2 || nB != (n - 1) / 2) {       puts( -1 );       return 0;     }     cout << (n - 1) << endl;     vector<int> selected;     for (__typeof((eA_selected).end()) it((eA_selected).begin());          it != (eA_selected).end(); ++it)       selected.push_back(*it);     for (__typeof((eB_selected).end()) it((eB_selected).begin());          it != (eB_selected).end(); ++it)       selected.push_back(*it);     for (__typeof((selected).end()) it((selected).begin());          it != (selected).end(); ++it) {       if (it != (selected).begin()) cout <<    ;       cout << (*it) + 1;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   class SegmentTree {    private:     vector<long long> tree;     vector<long long> lazy;     vector<long long> num;     long long build(long long ind, long long l, long long r) {       if (l == r) {         tree[ind] = num[l];         return tree[ind];       }       tree[ind] = min(build(2 * ind, l, (l + r) / 2),                       build(2 * ind + 1, (l + r) / 2 + 1, r));       return tree[ind];     }     long long rngq(long long ind, long long l, long long r, long long ql,                    long long qr) {       if (lazy[ind] != 0) {         tree[ind] += lazy[ind];         if (l != r) {           lazy[2 * ind + 1] += lazy[ind];           lazy[2 * ind] += lazy[ind];         }         lazy[ind] = 0;       }       if (ql > r || qr < l) return (long long)1e18;       if (ql <= l && qr >= r) {         return tree[ind];       }       return min(rngq(2 * ind, l, (l + r) / 2, ql, qr),                  rngq(2 * ind + 1, (l + r) / 2 + 1, r, ql, qr));     }     long long update(long long ind, long long l, long long r, long long ql,                      long long qr, long long val) {       if (lazy[ind] != 0) {         tree[ind] += lazy[ind];         if (l != r) {           lazy[2 * ind + 1] += lazy[ind];           lazy[2 * ind] += lazy[ind];         }         lazy[ind] = 0;       }       if (ql > r || qr < l) return tree[ind];       if (ql <= l && qr >= r) {         tree[ind] += val;         if (l != r) {           lazy[2 * ind + 1] += val;           lazy[2 * ind] += val;         }         return tree[ind];       }       return tree[ind] =                  min(update(2 * ind, l, (l + r) / 2, ql, qr, val),                      update(2 * ind + 1, (l + r) / 2 + 1, r, ql, qr, val));     }       public:     void buildTree(vector<long long> arr) {       long long n = arr.size();       tree.resize(4 * n);       lazy.resize(4 * n, 0);       num = arr;       build(1, 0, n - 1);     }     long long query(long long l, long long r) {       return rngq(1, 0, num.size() - 1, l, r);     }     void rngup(long long l, long long r, long long val) {       update(1, 0, num.size() - 1, l, r, val);     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     vector<long long> arr(n);     for (int i = 0; i < n; i++) cin >> arr[i];     SegmentTree segtree;     segtree.buildTree(arr);     long long q;     cin >> q;     while (q--) {       long long l, r;       cin >> l >> r;       if (cin.peek() ==   n ) {         if (r < l) {           cout << min(segtree.query(l, n - 1), segtree.query(0, r)) << endl;         } else           cout << segtree.query(l, r) << endl;       } else {         long long val;         cin >> val;         if (r < l) {           segtree.rngup(l, n - 1, val);           segtree.rngup(0, r, val);         } else           segtree.rngup(l, r, val);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   pair<int, int> t[500050];   bitset<2020> P[2020], B[2020];   void solve() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d%d , &x, &y);       t[i] = pair<int, int>(x, y);       P[x][y] = 1;     }     for (int i = 1; i <= n; i++) B[i][i] = 1;     for (int i = 1; i <= n; i++) {       int f = -1;       for (int j = i; j <= n; j++)         if (P[j].test(i)) {           f = j;           break;         }       swap(P[f], P[i]);       swap(B[f], B[i]);       for (int j = 1; j <= n; j++)         if (i != j && P[j][i]) {           P[j] ^= P[i];           B[j] ^= B[i];         }     }     for (int i = 0; i < m; i++) {       if (B[t[i].second][t[i].first])         puts( NO );       else         puts( YES );     }   }   int main() {     int Tc = 1;     for (int tc = 1; tc <= Tc; tc++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1000000007;   const int N = 100003;   int ld[N];   int a[N];   void sieve() {     for (int i = 2; i * i < N; ++i)       if (ld[i] == 0)         for (int j = i * i; j < N; j += i)           if (ld[j] == 0) ld[j] = i;     for (int i = 2; i < N; ++i)       if (ld[i] == 0) ld[i] = i;   }   vector<int> p;   vector<int> k;   vector<int> d;   void genDivisors(int i, int x) {     if (i == (int)p.size()) {       d.push_back(x);       return;     }     for (int c = 0; c <= k[i]; ++c) {       genDivisors(i + 1, x);       x *= p[i];     }   }   int expMod(int a, int n) {     int res = 1;     while (n > 0) {       if (n & 1) res = (long long)res * a % M;       n >>= 1;       a = (long long)a * a % M;     }     return res;   }   int main() {     sieve();     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , a + i);     sort(a, a + n);     int res = 0;     for (int x = 1; x <= a[n - 1]; ++x) {       p.clear();       k.clear();       d.clear();       int y = x;       while (y > 1) {         int z = ld[y];         p.push_back(ld[y]);         k.push_back(1);         y /= z;         while (y % z == 0) {           y /= z;           ++k.back();         }       }       genDivisors(0, 1);       sort(d.begin(), d.end());       k.clear();       k.resize(d.size());       for (int i = 0; i < (int)d.size(); ++i)         k[i] = n - (lower_bound(a, a + n, d[i]) - a);       y = 1;       for (int i = 0; i < (int)d.size() - 1; ++i) {         k[i] -= k[i + 1];         y = (long long)y * expMod(i + 1, k[i]) % M;       }       int z =           (expMod(d.size(), k.back()) - expMod((int)d.size() - 1, k.back()) + M) %           M;       y = (long long)y * z % M;       res = (res + y) % M;     }     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string s;   struct str {     int len;     bool vis;     string pre, suf;     void push_front(char ch) {       if (!len)         vis = 0;       else if (ch ^ pre[0])         vis = ch < pre[0];       pre = ch + pre;       if (len < 2)         suf = ch + suf;       else if (pre.length() > 10)         pre.pop_back();       len++;     }   } ans[100005];   int main() {     int i;     cin >> s;     n = s.length();     ans[n].len = ans[n].vis = 0;     ans[n].pre = ans[n].suf =   ;     s +=  # ;     for (i = n - 1; i >= 0; i--)       if (s[i] ^ s[i + 1])         ans[i] = ans[i + 1], ans[i].push_front(s[i]);       else {         ans[i] = ans[i + 2];         if (s[i] < ans[i].pre[0] || s[i] == ans[i].pre[0] && ans[i].vis) {           ans[i].push_front(s[i]);           ans[i].push_front(s[i]);         }       }     for (i = 0; i < n; i++) {       cout << ans[i].len <<    ;       if (ans[i].len <= 10)         cout << ans[i].pre << endl;       else         cout << ans[i].pre.substr(0, 5) <<  ...  << ans[i].suf << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7;   long long int n, k;   string s, s1;   void hi() {     for (int i = k; i < s.length(); i++) {       s[i] = s[i - k];     }   }   int main() {     cout.precision(10);     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k >> s;     s1 = s;     hi();     if (s >= s1) {       cout << n << endl;       cout << s;     } else {       bool ok = true;       int i = k - 1;       if (s[i] !=  9 ) {         s[i] = s[i] + 1;         hi();         cout << n << endl;         cout << s;       } else {         s[i] =  0 ;         for (int j = i - 1; j >= 0; j--) {           if (s[j] !=  9 ) {             s[j]++;             ok = false;             hi();             cout << n << endl;             cout << s;             break;           } else {             s[j] =  0 ;           }         }         if (ok) {           cout << n + 1 << endl;           cout << s1[0] + 1;           for (int i = 0; i < n; i++) {             cout <<  0 ;           }         }       }     }     return 0;   }   long long int nChooseR(long long int n, long long int k) {     if (k > n) return 0;     if (k * 2 > n) k = n - k;     if (k == 0) return 1;     long long int result = n;     for (int i = 2; i <= k; ++i) {       result *= (n - i + 1);       result /= i;     }     return result;   }   long long int power(long long int a, long long int b) {     if (b == 1) {       return a % M;     } else {       if (b % 2 == 0)         return (power(a, b / 2) % M * power(a, b / 2) % M) % M;       else         return (((power(a, b / 2) % M * power(a, b / 2) % M) % M) * a % M) % M;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1E5 + 10;   const int inf = 1 << 30;   long long read() {     long long a = 0;     char b = 1, c;     do       if ((c = getchar()) == 45) b = -1;     while (c < 48 || c > 57);     do a = (a << 3) + (a << 1) + (c & 15);     while ((c = getchar()) > 47 && c < 58);     return a * b;   }   void write(long long x, char c) {     if (x < 0) putchar(45), x = -x;     char a[20], s = 0;     do a[++s] = x % 10 | 48;     while (x /= 10);     do putchar(a[s]);     while (--s);     putchar(c);   }   int fa[N], _fa[N];   int find(int x) { return fa[x] ^ x ? fa[x] = find(fa[x]) : x; }   int _find(int x) { return _fa[x] ^ x ? _fa[x] = _find(_fa[x]) : x; }   vector<int> q, _q;   int main() {     int n = read(), y = read(), z = read();     write(n - 1 - max(y, z),   n );     for (int i = 1; i <= n; ++i) fa[i] = _fa[i] = i;     while (y--) {       int u = find(read()), v = find(read());       if (u > v) swap(u, v);       fa[v] = u;     }     while (z--) {       int u = _find(read()), v = _find(read());       if (u > v) swap(u, v);       _fa[v] = u;     }     for (int i = 2; i <= n; ++i) {       int u = find(i), v = _find(i);       if (u ^ 1 && v ^ 1) {         fa[u] = _fa[v] = 1;         printf( %d 1 n , i);       }     }     for (int i = 2; i <= n; ++i) {       if (find(i) == i) q.push_back(i);       if (_find(i) == i) _q.push_back(i);     }     for (int i = min(q.size(), _q.size()); i--;) printf( %d %d n , q[i], _q[i]);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t = 0, k;     cin >> n >> k;     if (n > k) n = k;     long long unsigned int sum = 1;     while (n != 1) {       sum *= n;       n--;     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     while (~scanf( %d %d %d , &a, &b, &c)) {       int ans = a + b + c;       ans = max(ans, a * b * c);       ans = max((a + b) * c, ans);       ans = max(a * (b + c), ans);       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gi() {     int res = 0, w = 1;     char ch = getchar();     while (ch !=  -  && !isdigit(ch)) ch = getchar();     if (ch ==  - ) w = -1, ch = getchar();     while (isdigit(ch)) res = res * 10 + ch -  0 , ch = getchar();     return res * w;   }   const int MAX_N = 1e6 + 5;   const int V = 1e6 + 1;   int mn[MAX_N << 2], tag[MAX_N << 2], cnt[MAX_N << 2];   void pushup(int o) {     mn[o] = min(mn[(o << 1)], mn[(o << 1 | 1)]), cnt[o] = 0;     if (mn[(o << 1)] == mn[o]) cnt[o] += cnt[(o << 1)];     if (mn[(o << 1 | 1)] == mn[o]) cnt[o] += cnt[(o << 1 | 1)];   }   void puttag(int o, int v) { tag[o] += v, mn[o] += v; }   void pushdown(int o) {     if (!tag[o]) return;     puttag((o << 1), tag[o]), puttag((o << 1 | 1), tag[o]);     tag[o] = 0;   }   void modify(int o, int l, int r, int ql, int qr, int v) {     if (ql <= l && r <= qr) return puttag(o, v);     pushdown(o);     int mid = (l + r) >> 1;     if (ql <= mid) modify((o << 1), l, mid, ql, qr, v);     if (qr > mid) modify((o << 1 | 1), mid + 1, r, ql, qr, v);     pushup(o);   }   void mdy(int o, int l, int r, int pos, int v) {     if (l == r) return (void)(cnt[o] += v);     pushdown(o);     int mid = (l + r) >> 1;     if (pos <= mid)       mdy((o << 1), l, mid, pos, v);     else       mdy((o << 1 | 1), mid + 1, r, pos, v);     pushup(o);   }   int query(int o, int l, int r, int ql, int qr) {     if (ql <= l && r <= qr) return mn[o] == 1 ? cnt[o] : 0;     pushdown(o);     int mid = (l + r) >> 1, res = 0;     if (ql <= mid) res = query((o << 1), l, mid, ql, qr);     if (qr > mid) res += query((o << 1 | 1), mid + 1, r, ql, qr);     return res;   }   void upd(int l, int r, int v) {     if (l == r) return (void)puts( xgzc ak ioi );     if (l > r) swap(l, r);     modify(1, 0, V, l, r - 1, v);   }   int N, Q, a[MAX_N];   int main() {     N = gi(), Q = gi();     for (int i = 1; i <= N; i++) a[i] = gi();     a[0] = V, a[N + 1] = 0;     for (int i = 0; i <= N; i++) upd(a[i], a[i + 1], 1), mdy(1, 0, V, a[i], 1);     while (Q--) {       int p = gi(), v = gi();       upd(a[p - 1], a[p], -1), upd(a[p], a[p + 1], -1), mdy(1, 0, V, a[p], -1);       a[p] = v;       upd(a[p - 1], a[p], 1), upd(a[p], a[p + 1], 1), mdy(1, 0, V, a[p], 1);       printf( %d n , query(1, 0, V, 1, V - 1));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long bef[1000100], af[1000100];   long long calc(long long n) { return (n * (n + 1)) / 2; }   int main() {     int k;     string s;     cin >> k >> s;     memset(bef, 0, sizeof bef);     memset(af, 0, sizeof af);     long long last(1000010), cur(1), i(0);     vector<int> ones;     long long incase(0);     while (i < s.size()) {       while (s[i] ==  0 ) {         ++i;         ++cur;       }       incase += calc(cur - 1);       if (i < s.size()) {         bef[i] = cur;         cur = 1;         ones.push_back(i);       }       ++i;     }     if (!k) {       cout << incase;       return 0;     }     i = s.size() - 1;     cur = 1;     while (i >= 0) {       while (s[i] ==  0 ) {         --i;         ++cur;       }       if (i >= 0) {         af[i] = cur;         cur = 1;       }       --i;     }     long long ans(0);     for (int j = 0; j + k - 1 < ones.size(); ++j) {       ans += bef[ones[j]] * af[ones[j + k - 1]];     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b = 0, c = 0, n, t;     cin >> t;     for (int o = 1; o <= t; o++) {       b = 0;       c = 0;       cin >> n;       for (int i = 1; i <= n; i++) {         cin >> a;         if (a != 1) {           c = 1;         } else {           if (c == 0) {             b = b + 1;           }         }       }       if (n == 1) {         cout <<  First ;       } else {         if (c == 0) {           if (n % 2 == 0) {             cout <<  Second ;           } else {             cout <<  First ;           }         } else {           if (b % 2 == 0) {             cout <<  First ;           } else {             cout <<  Second ;           }         }       }       cout << endl;     }     return 0;   }