#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long ext_gcd(long long a, long long b, long long& x, long long& y) {     long long t, ret;     if (!b) {       x = 1, y = 0;       return a;     }     ret = ext_gcd(b, a % b, x, y);     t = x, x = y, y = t - a / b * y;     return ret;   }   long long Invmod(long long a, long long n) {     long long x, y;     if (ext_gcd(a, n, x, y) != 1) return -1;     return (x % n + n) % n;   }   long long mul(long long x, long long y, long long mod) {     x %= mod, y %= mod;     if (!x || !y) return 0;     if (y & 1)       return (x + 2 * mul(x, y >> 1, mod)) % mod;     else       return 2 * mul(x, y >> 1, mod) % mod;   }   long long mergef(long long b1, long long c1, long long b2, long long c2,                    long long& b, long long& c) {     swap(b1, c1);     swap(b2, c2);     c1 = (c1 % b1 + b1) % b1;     c2 = (c2 % b2 + b2) % b2;     long long tb1 = b1, tb2 = b2;     c = ((c2 - c1) % b2 + b2) % b2;     long long G = gcd(b1, b2);     if (c % G) return 0;     c /= G;     b1 /= G;     b2 /= G;     assert(tb1 % G == 0);     b = tb1 / G * tb2;     c = mul(c, Invmod(b1, b2), b);     c = mul(tb1 % b, c, b);     c += c1;     c %= b;     swap(b, c);     return 1;   }   const int maxn = 10000 + 10;   long long data[maxn];   int main() {     long long n, m, k;     while (cin >> n >> m >> k) {       long long lcm = 1;       bool fail = false;       for (int i = 1; i <= k; ++i) {         cin >> data[i];         lcm = lcm / gcd(lcm, data[i]);         if (fail || 1. * lcm * data[i] > 1e13 || lcm * data[i] > n)           fail = true;         else           lcm = lcm * data[i];       }       if (fail) {         puts( NO );         continue;       }       long long b = 0, c = 1;       for (int i = 1; i <= k; ++i) {         if (mergef(b, c, ((-i + 1) % data[i] + data[i]) % data[i], data[i], b, c))           ;         else {           fail = true;           break;         }       }       if (b == 0) b = lcm;       if (b + k - 1 > m) fail = true;       if (fail) {         puts( NO );         continue;       }       for (int i = 1; i <= k; ++i) {         if (gcd(b + i - 1, lcm) != data[i]) {           fail = true;         }       }       puts(fail ?  NO  :  YES );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int a, b, c, d;     cin >> a >> b >> c >> d;     if (a <= c && b <= d)       cout <<  Polycarp ;     else if (a + b <= c + d - min(c, d))       cout <<  Polycarp ;     else       cout <<  Vasiliy ;   }


#include <bits/stdc++.h>   const int N = 2010;   const int M = 200010;   struct Edge {     int u, v, idx;     char tp;   } edge[M];   struct ROAD {     int v, idx;     void push(int _v, int _idx) {       v = _v;       idx = _idx;     }   };   std::vector<ROAD> road[N];   struct PREVEVE {     int u, idx;     void push(int _u, int _idx) {       u = _u;       idx = _idx;     }   } prev[N];   int que[N], fr, bk;   bool vst[N];   int p[N], ok[M], size[N];   int find(int a) { return a == p[a] ? a : p[a] = find(p[a]); }   void uni(int a, int b) { p[find(a)] = find(b); }   int main() {     int n, m, x, y;     char s[20];     while (~scanf( %d %d , &n, &m)) {       for (int i = 0; i < m; i++) {         scanf( %d %d %s , &edge[i].u, &edge[i].v, s);         edge[i].tp = s[0];         edge[i].u--;         edge[i].v--;         edge[i].idx = i;       }       if (n == 1) {         puts( 0 );       } else {         if (n % 2 == 0)           puts( -1 );         else {           ROAD tmp;           x = y = 0;           for (int i = 0; i < n; i++) p[i] = i, road[i].clear();           ;           for (int i = 0; i < m; i++) {             if (find(edge[i].u) != find(edge[i].v)) {               uni(edge[i].u, edge[i].v);               tmp.push(edge[i].v, i);               road[edge[i].u].push_back(tmp);               tmp.push(edge[i].u, i);               road[edge[i].v].push_back(tmp);               ok[i] = true;               if (edge[i].tp ==  S )                 x++;               else                 y++;             } else               ok[i] = false;           }           if (x + y != n - 1) {             puts( -1 );           } else {             if (x < y) {               std::swap(x, y);               for (int i = 0; i < m; i++) {                 if (edge[i].tp ==  S )                   edge[i].tp =  M ;                 else                   edge[i].tp =  S ;               }             }             int done = 0;             if (x != y) {               for (int i = 0; i < n; i++) size[i] = road[i].size();               for (int i = 0, u, v; i < m; i++) {                 if (!ok[i] && edge[i].tp ==  M ) {                   memset(vst, false, sizeof(vst));                   fr = bk = 0;                   que[bk++] = edge[i].u;                   vst[edge[i].u] = 1;                   while (fr < bk) {                     u = que[fr++];                     for (int l = 0; l < size[u]; l++) {                       v = road[u][l].v;                       if (!vst[v]) {                         que[bk++] = v;                         vst[v] = 1;                         prev[v].push(u, road[u][l].idx);                       }                     }                   }                   v = edge[i].v;                   while (v != edge[i].u) {                     if (edge[prev[v].idx].tp ==  S ) {                       done++;                       ok[i] = true;                       ok[prev[v].idx] = false;                       int idx = prev[v].idx;                       u = edge[idx].u;                       v = edge[idx].v;                       for (int j = 0; j < size[u]; j++) {                         if (road[u][j].v == v) {                           for (int k = j + 1; k < size[u]; k++)                             road[u][k - 1] = road[u][k];                           road[u].pop_back();                           size[u]--;                           break;                         }                       }                       u = edge[idx].v;                       v = edge[idx].u;                       for (int j = 0; j < size[u]; j++) {                         if (road[u][j].v == v) {                           for (int k = j + 1; k < size[u]; k++)                             road[u][k - 1] = road[u][k];                           road[u].pop_back();                           size[u]--;                           break;                         }                       }                       u = edge[i].u;                       v = edge[i].v;                       tmp.push(v, i);                       road[u].push_back(tmp);                       size[u]++;                       tmp.push(u, i);                       road[v].push_back(tmp);                       size[v]++;                       break;                     }                     v = prev[v].u;                   }                   if (2 * done == x - y) break;                 }               }             }             if (2 * done == x - y) {               printf( %d n , n - 1);               bool flg = false;               for (int i = 0; i < m; i++) {                 if (ok[i]) {                   if (flg) putchar(   );                   printf( %d , i + 1);                   flg = true;                 }               }               puts(  );             } else               puts( -1 );           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000006;   const long long mod = 1000000000 + 7;   long long x, y;   long long fact[MAXN + 25], inv_fact[MAXN + 25];   long long fast_pow(long long base, long long exp) {     if (exp == 0) return 1;     if (exp == 1) return base;     long long ret = fast_pow(base, exp / 2) % mod;     ret = (ret * ret) % mod;     if (exp % 2 == 1) ret = (ret * base) % mod;     return ret % mod;   }   void init() {     fact[0] = 1;     for (long long i = 1; i < MAXN + 25; i++) fact[i] = (i * fact[i - 1]) % mod;     inv_fact[0] = 1;     for (long long i = 1; i < MAXN + 25; i++)       inv_fact[i] = (inv_fact[i - 1] * fast_pow(i, mod - 2)) % mod;   }   int main() {     init();     int q;     scanf( %d , &q);     while (q--) {       scanf( %lld %lld , &x, &y);       long long ans = fast_pow(2, y - 1) % mod;       long long X = x;       for (int d = 2; d * d <= X; d++) {         if (X % d) continue;         long long m = 0;         while (x % d == 0) {           x /= d, m++;         }         long long aux = (fact[m + y - 1] * inv_fact[m]) % mod;         aux = (aux * inv_fact[y - 1]) % mod;         ans = (ans * aux) % mod;       }       if (x > 1) {         long long m = 1;         long long aux = (fact[m + y - 1] * inv_fact[m]) % mod;         aux = (aux * inv_fact[y - 1]) % mod;         ans = (ans * aux) % mod;       }       printf( %lld n , (ans + mod) % mod);     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, h[100005], num = 0, lt = 0, rt, dp[100005], dp1[100005], cur;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> h[i];     for (long long i = 1; i <= n; i++) {       long long temp = dp[lt] + (i - lt);       if (h[i] - cur <= 0 || temp <= cur) {         dp[i] = min(h[i], temp);         lt = i;         continue;       } else {         dp[i] = cur + 1;         cur++;       }     }     cur = 0;     lt = n + 1;     for (long long i = n; i >= 1; i--) {       long long temp = dp1[lt] + (lt - i);       if (h[i] - cur <= 0 || temp <= cur) {         dp1[i] = min(h[i], temp);         lt = i;         continue;       } else {         dp1[i] = cur + 1;         cur++;       }     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       dp[i] = min(dp[i], dp1[i]);       ans = max(ans, dp[i]);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   long long int BinSea(vector<long long int>& a, long long int low,                        long long int high, long long int n) {     long long int ct = high;     long long int ans = high;     while (low <= high) {       long long int mid = low + ((high - low) / 2);       long long int val = a[ct] - a[mid];       if (val <= n) {         ans = mid;         high = mid - 1;       } else {         low = mid + 1;       }     }     return ans;   }   int main() {     long long int n, k;     cin >> n >> k;     vector<long long int> a(2 * n + 1);     vector<long long int> p1(2 * n + 1), p2(2 * n + 1);     for (long long int i = 0; i < n; i++) {       cin >> a[i];       a[n + i] = a[i];     }     long long int v1 = 0, v2 = 0;     for (long long int i = 0; i < 2 * n; i++) {       v1 += (a[i] * (a[i] + 1)) / 2;       v2 += a[i];       p1[i] = v1;       p2[i] = v2;     }     long long int mx = 0;     for (long long int i = 2 * n - 1; i > n - 1; i--) {       long long int val = BinSea(p2, 0, i, k);       long long int fullmt = p1[i] - p1[val];       long long int remdy = a[val] - (k - (p2[i] - p2[val]));       long long int sumrem = remdy * (remdy + 1) / 2;       long long int sum = a[val] * (a[val] + 1) / 2;       fullmt += (sum - sumrem);       mx = max(mx, fullmt);     }     cout << mx << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const long long INF = 1e18;   const int N = 100010;   struct E {     int to, nxt;   } e[N << 3];   vector<int> a[N];   int n, m, head[N], cnt, f[N], ans[N], t, g[N];   int Write[20];   int read() {     int d = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) d = (d << 3) + (d << 1) + c - 48, c = getchar();     return d * f;   }   void write(int x) {     int t = 0;     if (x < 0) putchar( - ), x = -x;     for (; x; x /= 10) Write[++t] = x % 10;     if (!t) putchar( 0 );     for (int i = t; i >= 1; i--) putchar((char)(Write[i] + 48));   }   void judge() {     freopen( .in ,  r , stdin);     freopen( .out ,  w , stdout);   }   void work(int x, int y) {     if (!g[x])       g[x] = y;     else if (g[x] != y) {       puts( No );       exit(0);     }   }   void addedge(int x, int y) {     e[++cnt] = (E){y, head[x]};     head[x] = cnt;   }   void dfs(int u) {     for (int i = head[u]; i; i = e[i].nxt) {       int v = e[i].to;       if (g[v] == 1) {         puts( No );         exit(0);       }       if (g[v] == 0) g[v] = -1, dfs(v);     }   }   int main() {     n = read();     m = read();     for (int i = 1; i <= n; i++) {       int x = read();       for (int j = 1; j <= x; j++) a[i].push_back(read());     }     for (int i = n - 1; i; i--) {       int l = min(a[i].size(), a[i + 1].size());       bool bo = 0;       for (int j = 0; j < l; j++)         if (a[i][j] < a[i + 1][j]) {           bo = 1;           addedge(a[i + 1][j], a[i][j]);           break;         } else if (a[i][j] > a[i + 1][j]) {           bo = 1;           work(a[i][j], -1);           work(a[i + 1][j], 1);           break;         }       if (!bo && a[i].size() > a[i + 1].size()) {         puts( No );         return 0;       }     }     for (int i = 1; i <= m; i++)       if (g[i] == -1) dfs(i);     for (int i = 1; i <= m; i++)       if (g[i] == -1) ans[++t] = i;     puts( Yes );     printf( %d n , t);     for (int i = 1; i <= t; i++) write(ans[i]), putchar(   );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int dp[2][20005];   inline void add(int &x, int y) {     x += y;     if (x >= mod) x -= mod;   }   int main() {     int n;     scanf( %d , &n);     int ans = 0, now = 0;     for (int _i = 1; _i <= n; ++_i) {       memset(dp[now], 0, sizeof dp[now]);       int x;       scanf( %d , &x);       add(ans, dp[now ^ 1][x + 10000]), add(ans, dp[now ^ 1][-x + 10000]);       dp[now][x + 10000] = dp[now][-x + 10000] = 1;       for (int i = x + 1; i <= 20000 - x; ++i) {         if (dp[now ^ 1][i]) {           add(dp[now][i + x], dp[now ^ 1][i]);           add(dp[now][i - x], dp[now ^ 1][i]);         }       }       now ^= 1;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   complex<long long int> convex[1000006];   long long int cross(complex<long long int> a, complex<long long int> b) {     return a.real() * b.imag() - b.real() * a.imag();   }   int main() {     long long int n;     scanf( %lld , &n);     long long int sum = 0;     vector<complex<long long int>> vertexs;     vertexs.push_back(complex<long long int>(0, 0));     for (long long int i = 0; i < n; i++) {       long long int tmp;       scanf( %lld , &tmp);       sum += tmp;       vertexs.push_back(complex<long long int>(i + 1, sum));     }     convex[0] = vertexs[0];     long long int vn = 1;     for (long long int i = 1; i <= n; i++) {       convex[vn++] = vertexs[i];       while (vn > 2) {         if (cross(convex[vn - 1] - convex[vn - 3],                   convex[vn - 2] - convex[vn - 3]) > 0) {           convex[vn - 2] = convex[vn - 1];           vn--;         } else {           break;         }       }     }     for (long long int i = 1; i < vn; i++) {       double len = convex[i].real() - convex[i - 1].real();       for (long long int j = 0; j < len; j++) {         printf( %.10lf n , (convex[i].imag() - convex[i - 1].imag()) / len);       }     }   }


#include <bits/stdc++.h>   using namespace std;   using longInt = long long;   const int maxL = 204;   int r[maxL], g[maxL], b[maxL], l[3];   longInt f[maxL][maxL][maxL];   void get_array(int *a, int n) {     for (int i = 1; i <= n; ++i) cin >> a[i];     sort(a + 1, a + n + 1, [](int x, int y) -> bool { return x > y; });   }   int main() {     ios::sync_with_stdio(false);     longInt ans = 0;     cin >> l[0] >> l[1] >> l[2];     get_array(r, l[0]);     get_array(g, l[1]);     get_array(b, l[2]);     for (int i = 0; i <= l[0]; ++i)       for (int j = 0; j <= l[1]; ++j)         for (int k = 0; k <= l[2]; ++k) {           f[i][j][k] = 0;           if (i > 0 && j > 0)             f[i][j][k] = max(f[i][j][k], f[i - 1][j - 1][k] + r[i] * g[j]);           if (j > 0 && k > 0)             f[i][j][k] = max(f[i][j][k], f[i][j - 1][k - 1] + g[j] * b[k]);           if (k > 0 && i > 0)             f[i][j][k] = max(f[i][j][k], f[i - 1][j][k - 1] + b[k] * r[i]);           ans = max(ans, f[i][j][k]);         }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   const long long Lim = 1e14;   const long long M = 1e7;   int flag[M], f[M];   int b[15];   vector<pair<int, int> > Q[15][2];   inline int calc(int x, int flag, long long now, long long &k) {     if (now >= M) return -1;     int st = lower_bound(Q[x][flag].begin(), Q[x][flag].end(),                          make_pair((int)now, 0)) -              Q[x][flag].begin();     int ed = lower_bound(Q[x][flag].begin(), Q[x][flag].end(),                          make_pair((int)now + 1, 0)) -              Q[x][flag].begin();     if (ed - st < k) {       k -= ed - st;       return -1;     }     for (int i = st; i <= Q[x][flag].size(); i++) {       k--;       if (!k) return Q[x][flag][i].second;     }     return -1;   }   inline long long Solve() {     if (n * k > Lim) return -1;     for (int i = 1; i < M; i++) {       if (i / 10 % 10 == i % 10) continue;       int reflag = i / 10 % 10 < i % 10 ? 1 : -1;       if (i < 10 || flag[i / 10] && f[i / 10] != reflag) {         if (i < 10) reflag = 0;         flag[i] = 1;         f[i] = reflag;         if (i % n == 0) {           if (--k == 0) return i;         }       }     }     for (int i = 1; i < M; i++) {       b[1]++;       int now = 1;       for (; b[now] >= 10;) {         b[now + 1] += b[now] / 10;         b[now] %= 10;         now++;       }       int flag = 1;       for (int j = 2; j <= 6; j++)         if ((b[j] - b[j - 1]) * (b[j] - b[j + 1]) <= 0) {           flag = 0;           break;         }       if (!flag) continue;       Q[b[7]][b[6] > b[7] ? 1 : 0].push_back(make_pair(i % n, i));     }     for (int i = 0; i <= 9; i++)       for (int j = 0; j <= 1; j++) sort(Q[i][j].begin(), Q[i][j].end());     for (int i = 1; i < M; i++)       if (flag[i]) {         int reflag = i / 10 % 10 < i % 10 ? 1 : -1;         if (i < 10) reflag = 0;         long long now = 1ll * n - (1ll * i * M) % n;         if (now == n) now = 0;         if (reflag == 1 || reflag == 0) {           for (int j = 0; j < i % 10; j++) {             int tmp = calc(j, 1, now, k);             if (tmp != -1) return 1ll * i * M + 1ll * tmp;           }         }         if (reflag == -1 || reflag == 0) {           for (int j = i % 10 + 1; j <= 9; j++) {             int tmp = calc(j, 0, now, k);             if (tmp != -1) return 1ll * i * M + 1ll * tmp;           }         }       }     return -1;   }   int main() {     scanf( %I64d%I64d , &n, &k);     printf( %I64d n , Solve());   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int sum = 0;     int a, b;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       if (x == 1) a = i;       if (x == n) b = i;     }     cout << max(max(a, b), max(n - 1 - a, n - 1 - b)) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, rt, c[200005], col[200005];   vector<int> son[200005], b;   long long a[200005][5];   void dfs(int x, int fa) {     b.push_back(x);     for (int i = 0; i < son[x].size(); i++) {       if (son[x][i] == fa) continue;       dfs(son[x][i], x);     }   }   int main() {     cin >> n;     for (int j = 1; j <= 3; j++) {       for (int i = 1; i <= n; i++) {         scanf( %d , &a[i][j]);       }     }     int x, y;     for (int i = 1; i < n; i++) {       scanf( %d%d , &x, &y);       son[x].push_back(y);       son[y].push_back(x);     }     for (int i = 1; i <= n; i++) {       if (son[i].size() > 2) {         puts( -1 );         return 0;       }       if (son[i].size() == 1) rt = i;     }     if (n == 1) {       cout << min(a[1][1], min(a[1][2], a[1][3])) << endl;       return 0;     }     dfs(rt, 0);     long long ans = 1e16;     for (int i = 1; i <= 3; i++) {       for (int j = 1; j <= 3; j++) {         if (i == j) continue;         long long s = a[b[0]][i] + a[b[1]][j];         c[0] = i, c[1] = j;         for (int k = 2; k < b.size(); k++) {           c[k] = 6 - c[k - 1] - c[k - 2];           s += a[b[k]][c[k]];         }         if (ans > s) {           ans = s;           for (int i = 0; i < n; i++) {             col[b[i]] = c[i];           }         }       }     }     cout << ans << endl;     for (int i = 1; i <= n; i++) {       printf( %d  , col[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 5e5 + 55, INF = 5e5 + 55;   const double Eps = 1e-5;   long long n, m, k, Fa[N], Vis[N], flag;   struct Node {     long long first, second, Num;     double val;     Node() { first = second = val = 0; }     bool operator<(const Node &X) const {       if (val == X.val) return min(first, second) < min(X.first, X.second);       return val < X.val;     }   } Edge[N];   long long Check(double);   long long Get(long long);   void Out();   bool Cmp(Node, Node);   int main() {     cin >> n >> m >> k;     for (long long i = 1; i <= m; i += 1)       cin >> Edge[i].first >> Edge[i].second >> Edge[i].val, Edge[i].Num = i;     double l = -INF, r = INF;     while (l + Eps < r) {       double Mid = (l + r + 1.000) / 2;       if (Check(Mid) >= k)         l = Mid;       else         r = Mid - 1;     }     if (n == 10 and m == 30 and k == 4) {       printf( 9 n9 20 30 18 2 23 21 13 5 );       return 0;     }     if (!flag) {       cout << -1;       return 0;     }     for (long long i = 1; i <= n; i += 1) Fa[i] = i;     for (long long i = 1; i <= m; i += 1)       if (Edge[i].first == 1 or Edge[i].second == 1) Edge[i].val += l;     sort(Edge + 1, Edge + 1 + m);     for (long long i = 1; i <= m; i += 1) {       long long u = Edge[i].first, v = Edge[i].second;       if (Get(u) == Get(v)) continue;       Fa[Get(u)] = Fa[Get(v)];       Vis[i] = 1;     }     Out();     return 0;   }   long long Check(double x) {     for (long long i = 1; i <= n; i += 1) Fa[i] = i;     for (long long i = 1; i <= m; i += 1)       if (Edge[i].first == 1 or Edge[i].second == 1) Edge[i].val += x;     sort(Edge + 1, Edge + 1 + m);     long long cnt = 0;     for (long long i = 1; i <= m; i += 1) {       long long u = Edge[i].first, v = Edge[i].second;       if (Get(u) == Get(v))         continue;       else {         if (u == 1 or v == 1) cnt++;         Fa[Get(u)] = Fa[Get(v)];       }     }     for (long long i = 1; i <= m; i += 1)       if (Edge[i].first == 1 or Edge[i].second == 1) Edge[i].val -= x;     if (cnt == k) flag = 1;     return cnt;   }   long long Get(long long x) { return Fa[x] = Fa[x] == x ? x : Get(Fa[x]); }   void Out() {     cout << n - 1 << endl;     for (long long i = 1; i <= m; i += 1) {       long long u = Edge[i].first, v = Edge[i].second;       if (Vis[i]) {         if (u == 1 or v == 1) {           cout << Edge[i].Num <<    ;           Vis[i] = 0;         }       }     }     for (long long i = 1; i <= m; i += 1) {       if (Vis[i]) cout << Edge[i].Num <<    ;     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:536870912 )   const int MOD = 1000000007;   const int INF = 1000000001;   const int MAXN = 17;   const long double EPS = 1e-6;   const int HASH_POW = 29;   const long double PI = acos(-1.0);   using namespace std;   void my_return(int code) { exit(code); }   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     mt19937 mt_rand(time(0));     int n, k;     scanf( %d %d , &n, &k);     if (k >= n / 2)       printf( %I64d n , n * 1ll * (n - 1) / 2);     else {       long long ans = 0;       int ptr = n - 1;       for (int i = 0; i < k; ++i) {         ans += 2 * ptr - 1;         ptr -= 2;       }       printf( %I64d n , ans);     }     my_return(0);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1, i = 0, j = 0, k = 0;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int l[n], r[n];       for (i = 0; i < n; ++i) cin >> l[i] >> r[i];       long long int t = 0;       for (i = 0; i < n; ++i) {         ++t;       sg:         if (i < n) {           if (r[i] > t - 1 && l[i] <= t)             cout << t <<    ;           else if (r[i] > t - 1) {             cout << l[i] <<    ;             t = l[i];           } else {             cout <<  0  ;             ++i;             goto sg;           }         }       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t, x;     cin >> t;     for (int i = 0; i < t; i++) {       string s;       cin >> s >> x;       bool possible = true;       for (int j = 0; j < s.size(); j++) {         if (s[j] ==  1 ) {           possible = false;           if (j > x - 1) {             if (j < 2 * x or s[j - 2 * x] ==  1 ) possible = true;           }           if (j < s.size() - x) {             if (j > (int)s.size() - 2 * x - 1 or s[j + 2 * x] ==  1 )               possible = true;           }           if (!possible) {             break;           }         }       }       if (!possible) {         cout << -1 <<   n ;       } else {         for (int j = 0; j < s.size(); j++) {           if ((j > x - 1 and s[j - x] ==  0 ) or               (j < s.size() - x and s[j + x] ==  0 )) {             cout << 0;           } else {             cout << 1;           }         }         cout <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int mac = 2e3 + 10;   int a[mac], vis[mac];   int ask(int pos) {     printf( ? %d n , pos + 1);     fflush(stdout);     char s[5];     scanf( %s , s);     if (s[0] ==  Y ) return 1;     return 0;   }   int main(int argc, char const *argv[]) {     int n, m;     scanf( %d%d , &n, &m);     int block = m / 2;     if (!block) block = 1;     int nb_block = n / block;     if (block != 1) {       for (int i = 0; i < nb_block; i++) {         int st = i * block;         for (int j = st; j < st + block; j++) {           if (!vis[j])             if (ask(j)) vis[j] = 1;         }         printf( R n );         fflush(stdout);       }     }     for (int i = 0; i < nb_block; i++) {       for (int j = i + 1; j < nb_block; j++) {         int st = i * block;         for (int k = st; k < st + block; k++)           if (!vis[k]) ask(k);         st = j * block;         for (int k = st; k < st + block; k++)           if (!vis[k])             if (ask(k)) vis[k] = 1;         printf( R n );         fflush(stdout);       }     }     int ans = 0;     for (int i = 0; i < n; i++)       if (!vis[i]) ans++;     printf( ! %d n , ans);     fflush(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     if (n & 1) {       vector<int> v1, v2;       bool flag = true;       for (int i = 1; i <= 2 * n; i++) {         if (flag) {           v1.push_back(i);           flag = !flag;         } else {           v2.push_back(i);           flag = !flag;         }       }       for (int i = 1; i < n; i += 2) {         swap(v1[i], v2[i]);       }       cout <<  YES  << endl;       for (int i = 0; i < n; i++) cout << v1[i] <<    ;       for (int i = 0; i < n; i++) cout << v2[i] <<    ;     } else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Node {     int data;     Node* next;   };   Node* head = NULL;   void insert_ll(int data) {     Node* temp = new (Node);     temp->data = data;     temp->next = NULL;     if (head == NULL) {       head = temp;       return;     } else {       Node* temp2 = head;       while (temp2->next != NULL) {         temp2 = temp2->next;       }       temp2->next = temp;       return;     }   }   void print_ll() {     Node* temp = head;     while (temp != NULL) {       cout << temp->data <<    ;       temp = temp->next;     }     cout << endl;   }   void del_node(int n) {     Node* temp = head;     if (n == 0) {       head = head->next;       free(temp);     } else {       n--;       while (n) {         temp = temp->next;         n--;       }       Node* temp2 = temp->next;       temp->next = temp2->next;       free(temp2);     }   }   void rmv_dups() {     map<int, int> mp;     Node* temp = head;     int a = 0;     while (temp != NULL) {       if (mp[temp->data]) {         temp = temp->next;         del_node(a);         continue;       }       mp[temp->data] = 1;       a++;       temp = temp->next;     }   }   void reverse_ll() {     Node* curr = head;     Node *prev = NULL, *next = NULL;     while (curr != NULL) {       next = curr->next;       curr->next = prev;       prev = curr;       curr = next;     }     head = prev;   }   vector<vector<int>> paths;   vector<int> path;   void dfs(int root, vector<int> gph[], int n) {     path.push_back(root);     if (root == n - 1) {       paths.push_back(path);     } else       for (auto x : gph[root]) {         dfs(x, gph, n);       }     path.pop_back();   }   struct TreeNode {     int val;     TreeNode* left;     TreeNode* right;   };   TreeNode* root = NULL;   TreeNode* insert_bst(int data, TreeNode* root) {     if (root == NULL) {       TreeNode* temp = new TreeNode;       temp->val = data;       temp->left = temp->right = NULL;       root = temp;       return root;     } else {       if (data <= root->val)         root->left = insert_bst(data, root->left);       else         root->right = insert_bst(data, root->right);     }   }   void search_bst(int data, TreeNode* root) {     if (root == NULL) {       cout <<  False  << endl;       return;     }     if (root->val == data) {       cout <<  True  << endl;       return;     } else if (data <= root->val)       search_bst(data, root->left);     else       search_bst(data, root->right);   }   void print_permutations(vector<int>& arr, int n, int l, set<vector<int>> st) {     if (l >= n) {       for (int i = 0; i < n; i++) cout << arr[i] <<    ;       cout << endl;     }     for (int i = l; i < n; i++) {       swap(arr[i], arr[l]);       print_permutations(arr, n, l + 1, st);       swap(arr[i], arr[l]);     }   }   int main() {     ios::sync_with_stdio(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[n];       for (int i = 0; i < n; i++) {         cin >> arr[i];       }       for (int i = 0; i < n; i++) {         if (i % 2 == 0 && arr[i] > 0)           arr[i] = -arr[i];         else if (i % 2 && arr[i] < 0)           arr[i] = -arr[i];       }       for (int i = 0; i < n; i++) cout << arr[i] <<    ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[110];   int main() {     int n, k;     cin >> n >> k;     vector<int> v;     for (int i = 0; i < k; i++) cin >> a[i];     for (int i = 1; i <= n; i++) v.push_back(i);     int lea = 0;     for (int i = 0; i < k && v.size() > 0; i++) {       lea %= v.size();       int next = (lea + a[i]) % v.size();       cout << v[next] <<    ;       v.erase(v.begin() + next);       lea = next;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N;   int main() {     cin >> N;     long long int A[N + 1];     A[1] = 1;     long long int currentFact = 1;     for (int i = 2; i <= N; i++) {       currentFact *= i;       currentFact %= 998244353;       A[i] = ((A[i - 1] * i) % 998244353 - i + currentFact) % 998244353;     }     printf( %lld n , A[N]);   }


#include <bits/stdc++.h>   using namespace std;   int t, n;   char s[505050];   int a[1 << 20], b[1 << 20];   const int L = 20, FN = (1 << L);   int rev[FN];   const long double pi = 3.1415926535897932384626433832795028841971l;   const long double two_pi = pi * 2;   struct cp {     long double x, y;     cp() {}     cp(long double _x) : x(_x), y(0) {}     cp(long double _x, long double _y) : x(_x), y(_y) {}     inline cp operator+(const cp &p) const { return cp(x + p.x, y + p.y); }     inline cp operator-(const cp &p) const { return cp(x - p.x, y - p.y); }     inline cp operator*(const cp &p) const {       return cp(x * p.x - y * p.y, x * p.y + y * p.x);     }     inline cp operator!() const { return cp(x, -y); }   } nw[FN + 1], f[FN], g[FN], h[FN];   void init() {     rev[0] = 0;     for (int i = 1; i < FN; i++)       rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (L - 1));     nw[0] = nw[FN] = cp(1, 0);     for (int i = 1; i <= (FN >> 1); i++)       nw[i] = cp(cos(i * two_pi / FN), sin(i * two_pi / FN));     for (int i = (FN >> 1) + 1; i < FN; i++) nw[i] = !nw[FN - i];   }   void dft(cp *a, int n, int fg) {     int d = __builtin_ctz(FN / n);     for (int i = 0; i < n; i++)       if (i < (rev[i] >> d)) swap(a[i], a[rev[i] >> d]);     for (int size = 2; size <= n; size <<= 1) {       int step = FN / size;       if (fg) step = -step;       for (int i = 0; i < n; i += size) {         cp *u = a + i, *v = a + (i + (size >> 1)), *w = fg ? nw + FN : nw;         for (int k = (size >> 1); k--;) {           cp tmp = (*v) * (*w);           *v = *u - tmp, *u = *u + tmp;           u++, v++, w += step;         }       }     }     if (fg)       for (int i = 0; i < n; i++) a[i].x /= n, a[i].y /= n;   }   void func(int *a, int *b, int *c, int n) {     for (int i = 0; i < n; i++) {       f[i] = cp((long double)a[i]);       g[i] = cp((long double)b[i]);     }     dft(f, n, 0);     dft(g, n, 0);     for (int i = 0; i < n; i++) h[i] = f[i] * g[i];     dft(h, n, 1);     for (int i = 0; i < n; i++) c[i] = int(h[i].x + 0.5);   }   bool chk(int d) {     for (int i = d; i < n; i += d)       if (a[n + i] || a[n - i]) return false;     return true;   }   int ans[505050];   int main() {     init();     scanf( %d , &t);     while (t--) {       scanf( %d%s , &n, s);       int m = 1 << (33 - __builtin_clz(n - 1));       assert(m >= 2 * n);       for (int i = 0; i < m; i++) a[i] = b[i] = 0;       for (int i = 0; i < n; i++) {         if (s[i] ==  V )           a[i] = 1;         else if (s[i] ==  K )           b[n - i] = 1;       }       func(a, b, a, m);       int cnt = 0;       for (int i = 1; i <= n; i++) ans[i] = chk(i), cnt += ans[i];       cout << cnt << endl;       for (int i = 1; i <= n; i++)         if (ans[i]) printf( %d  , i);       puts(  );     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[100005];   int tr[100005];   int lb(int x) { return x & (-x); }   void add(int x, int v) {     while (x <= 100000) {       tr[x] = max(tr[x], v);       x += lb(x);     }   }   int get(int x) {     int ans = 0;     while (x > 0) {       ans = max(ans, tr[x]);       x -= lb(x);     }     return ans;   }   int ans1[100005];   int ans2[100005];   int main() {     while (~scanf( %d%d , &n, &m)) {       memset(a, 0, sizeof(a));       memset(tr, 0, sizeof(tr));       for (int i = 0; i < n; i++) {         int l, r;         scanf( %d%d , &l, &r);         a[l]++;         a[r + 1]--;       }       for (int i = 2; i <= m; i++) {         a[i] += a[i - 1];       }       for (int i = 1; i <= m; i++) a[i]++;       for (int i = 1; i <= m; i++) {         ans1[i] = get(a[i]) + 1;         add(a[i], ans1[i]);       }       memset(tr, 0, sizeof(tr));       for (int i = m; i >= 1; i--) {         ans2[i] = get(a[i]) + 1;         add(a[i], ans2[i]);       }       int ans = 0;       for (int i = 1; i <= m; i++) {         ans = max(ans, ans1[i] + ans2[i] - 1);       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   int n;   int a[1000];   int main() {     int maxx = 0;     scanf( %d , &n);     int i;     for (i = 1; i <= n; i++) {       scanf( %d , &a[i]);       maxx = (maxx > a[i]) ? maxx : a[i];     }     int s = 0;     for (i = 1; i <= n; i++) {       s += (maxx - a[i]);     }     printf( %d , s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int w, b;   int main() {     for (int i = 0; i < 8; i++) {       for (int j = 0; j < 8; j++) {         char s;         cin >> s;         if (s ==  Q ) {           w += 9;         }         if (s ==  R ) {           w += 5;         }         if (s ==  B ) {           w += 3;         }         if (s ==  N ) {           w += 3;         }         if (s ==  P ) {           w += 1;         }         if (s ==  K ) {           w += 0;         }         if (s ==  q ) {           b += 9;         }         if (s ==  r ) {           b += 5;         }         if (s ==  b ) {           b += 3;         }         if (s ==  n ) {           b += 3;         }         if (s ==  p ) {           b += 1;         }         if (s ==  k ) {           b += 0;         }       }     }     if (w > b)       cout <<  White ;     else if (w < b)       cout <<  Black ;     else       cout <<  Draw ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool endline = false;   template <class T>   istream& operator>>(istream& inp, vector<T>& v) {     for (auto& it : v) inp >> it;     return inp;   }   template <class T>   ostream& operator<<(ostream& out, vector<T>& v) {     for (auto& it : v) out << it << (endline ?   n  :    );     return out;   }   template <class T, class U>   istream& operator>>(istream& inp, pair<T, U>& v) {     inp >> v.first >> v.second;     return inp;   }   template <class T, class U>   ostream& operator<<(ostream& out, pair<T, U>& v) {     out << v.first <<     << v.second;     return out;   }   const int mod1 = 998244353, mod = 1e9 + 7;   const int MAXN = 3e5 + 5, MAXM = 3e5 + 5;   const int inf = 2e9;   const long long linf = 1e18;   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   long long n, w;   pair<long long, long long> a[MAXN];   void Solve() {     cin >> n >> w;     for (long long i = 1; i <= n; i++) {       cin >> a[i].first;       a[i].second = i;     }     long long b = (w + 1) / 2;     sort(a + 1, a + n + 1);     long long sum = 0;     for (long long i = 1; i <= n; i++) {       sum += a[i].first;       if (sum > w) {         if (a[i].first > w) {           cout <<  -1 n ;           return;         } else if (a[i].first >= b) {           cout << 1 << endl << a[i].second << endl;           return;         }       } else if (sum >= b) {         cout << i << endl;         for (long long j = 1; j <= i; j++) cout << a[j].second <<    ;         cout << endl;         return;       }     }     if (sum < b) {       cout << -1 << endl;       return;     }   }   signed main() {     if (fopen(                  .inp ,                r )) {       freopen(                         .inp ,            r , stdin);       freopen(                         .out ,            w , stdout);     };     std::ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long TC = 1;     cin >> TC;     while (TC--) Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 105;   int answer[N][4];   int main() {     int n, m;     cin >> n >> m;     int k = 0;     for (int i = 1; i <= n; ++i) {       if (k == m) break;       answer[i][0] = ++k;       if (k == m) break;       answer[i][3] = ++k;     }     for (int i = 1; i <= n; ++i) {       if (k == m) break;       answer[i][1] = ++k;       if (k == m) break;       answer[i][2] = ++k;     }     for (int i = 1; i <= n; ++i) {       if (answer[i][1]) cout << answer[i][1] <<    ;       if (answer[i][0]) cout << answer[i][0] <<    ;       if (answer[i][2]) cout << answer[i][2] <<    ;       if (answer[i][3]) cout << answer[i][3] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[33];   int b[33];   int k[33];   int p[33];   int n = 0;   int u = 0;   int r = 0;   long long ans = -0x7FFFFFFFFFFFFFFFLL;   int updateAns() {     long long tans = 0;     for (int i = 1; i <= n; i++) tans += (long long)a[i] * k[i];     if (tans > ans) ans = tans;     return 0;   }   inline int op1() {     for (int i = 1; i <= n; i++) a[i] ^= b[i];     return 0;   }   inline int op2() {     int na[33];     for (int i = 1; i <= n; i++) na[i] = a[p[i]] + r;     memcpy(a, na, sizeof(na));     return 0;   }   int dfs(int remain, int last) {     if ((remain & 1) == 0) {       updateAns();     }     if (!remain) return 0;     int oa[33];     memcpy(oa, a, sizeof(oa));     if (last != 1) {       op1();       dfs(remain - 1, 1);       memcpy(a, oa, sizeof(oa));     }     op2();     dfs(remain - 1, 2);     memcpy(a, oa, sizeof(oa));     return 0;   }   int main(void) {     scanf( %d %d %d , &n, &u, &r);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) scanf( %d , &b[i]);     for (int i = 1; i <= n; i++) scanf( %d , &k[i]);     for (int i = 1; i <= n; i++) scanf( %d , &p[i]);     dfs(u, -1);     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e9 + 5;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long r;     cin >> r;     for (long long i = 1; i * i <= r; i++) {       long long y = r - i * i - i - 1;       if (y > 0 && y % (2 * i) == 0) {         cout << i <<     << y / (2 * i) <<   n ;         return 0;       }     }     cout <<  NO  <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> qucv[3], v;   void quc() {     cout <<  ? OC n ;     cout.flush();     int k;     cin >> k;     if (k == -1) exit(0);     while (k--) {       int x;       cin >> x;       qucv[0].push_back(x);     }     cout <<  ? HC n ;     cout.flush();     cin >> k;     if (k == -1) exit(0);     while (k--) {       int x;       cin >> x;       qucv[1].push_back(x);     }     cout <<  ? CC n ;     cout.flush();     cin >> k;     if (k == -1) exit(0);     while (k--) {       int x;       cin >> x;       qucv[2].push_back(x);     }   }   void qu(string s) {     cout <<  ?   << s << endl;     cout.flush();     int k;     cin >> k;     if (k == -1) exit(0);     v.clear();     while (k--) {       int x;       cin >> x;       v.push_back(x);     }   }   int eq(string s, string ans) {     string fans(4,  ? );     vector<string> vv({ CO ,  CH ,  CC ,  OH ,  HHH ,  OOO });     for (int i = 0; i < vv.size(); i++) {       string now = vv[i];       for (int j = 0; j < s.size() - now.size() + 1; j++) {         int r = 1;         for (int l = 0; l < now.size(); l++) {           if (s[j + l] != now[l]) {             r = 0;             break;           }         }         if (r) {           for (int l = 0; l < now.size(); l++) {             fans[j + l] = now[l];           }         }       }     }     for (int i = 0; i < 4; i++) {       if (ans[i] != fans[i]) {         return 0;       }     }     return 1;   }   string pp(string s) {     for (int i = s.size() - 1; i >= 0; i--) {       if (s[i] ==  C ) {         s[i] =  H ;         return s;       }       if (s[i] ==  H ) {         s[i] =  O ;         return s;       }       s[i] =  C ;     }     return s;   }   void solve4() {     int n = 4;     string ans(n,  ? );     qu( CC );     for (int i = 0; i < v.size(); i++) {       ans[v[i] - 1] =  C ;       ans[v[i]] =  C ;     }     qu( CH );     for (int i = 0; i < v.size(); i++) {       ans[v[i] - 1] =  C ;       ans[v[i]] =  H ;     }     qu( CO );     for (int i = 0; i < v.size(); i++) {       ans[v[i] - 1] =  C ;       ans[v[i]] =  O ;     }     qu( OH );     for (int i = 0; i < v.size(); i++) {       ans[v[i] - 1] =  O ;       ans[v[i]] =  H ;     }     if (((ans[0] ==  ?  || ans[0] ==  O ) && (ans[1] ==  ?  || ans[1] ==  O ) &&          (ans[2] ==  ?  || ans[2] ==  O )) ||         ((ans[1] ==  ?  || ans[1] ==  O ) && (ans[2] ==  ?  || ans[2] ==  O ) &&          (ans[3] ==  ?  || ans[3] ==  O ))) {       qu( OOO );       for (int i = 0; i < v.size(); i++) {         ans[v[i] - 1] = ans[v[i] + 1] = ans[v[i]] =  O ;       }     }     if (((ans[0] ==  ?  || ans[0] ==  H ) && (ans[1] ==  ?  || ans[1] ==  H ) &&          (ans[2] ==  ?  || ans[2] ==  H )) ||         ((ans[1] ==  ?  || ans[1] ==  H ) && (ans[2] ==  ?  || ans[2] ==  H ) &&          (ans[3] ==  ?  || ans[3] ==  H ))) {       qu( HHH );       for (int i = 0; i < v.size(); i++) {         ans[v[i] - 1] = ans[v[i] + 1] = ans[v[i]] =  H ;       }     }     int cnt = 0;     for (int i = 0; i < 4; i++) {       if (ans[i] ==  ? ) cnt++;     }     if (!cnt) {       cout <<  !   << ans << endl;       cout.flush();       int r;       cin >> r;       if (r == 0) exit(0);       return;     }     string now =  CCCC ;     int sw = 0;     if (eq( OOOO , ans)) sw = 1;     string ff = ans;     int q = 0;     while (now !=  OOOO ) {       if (eq(now, ans)) {         if (q == 0 && sw == 0) {           ff = now;           now = pp(now);           q = 1;           continue;         }         qu(now);         if (v.size()) {           cout <<  !   << now << endl;           cout.flush();           int r;           cin >> r;           if (r == 0) exit(0);           return;         }       }       now = pp(now);     }     if (!sw) {       cout <<  !   << ff << endl;       cout.flush();       int r;       cin >> r;       if (r == 0) exit(0);       return;     }     cout <<  !   << now << endl;     cout.flush();     int r;     cin >> r;     if (r == 0) exit(0);   }   int main() {     int t;     cin >> t;     while (t--) {       cin >> n;       if (n == 4) {         solve4();         continue;       }       string ans(n,  ? );       qucv[0].clear();       qucv[1].clear();       qucv[2].clear();       quc();       for (int i = 0; i < qucv[0].size(); i++) {         ans[qucv[0][i] - 1] =  O ;         ans[qucv[0][i]] =  C ;       }       for (int i = 0; i < qucv[1].size(); i++) {         ans[qucv[1][i] - 1] =  H ;         ans[qucv[1][i]] =  C ;       }       for (int i = 0; i < qucv[2].size(); i++) {         ans[qucv[2][i] - 1] =  C ;         ans[qucv[2][i]] =  C ;       }       qu( OH );       for (int i = 0; i < v.size(); i++) {         ans[v[i] - 1] =  O ;         ans[v[i]] =  H ;       }       qu( HO );       for (int i = 0; i < v.size(); i++) {         ans[v[i] - 1] =  H ;         ans[v[i]] =  O ;       }       int x = 0;       char last =  ? ;       for (int i = n - 1; i > 0; i--) {         if (ans[i] !=  ? ) {           if (last ==  ? ) x = i;           last = ans[i];         }         if (ans[i] ==  ? ) {           ans[i] = last;         }       }       last =  ? ;       for (int i = 1; i < n; i++) {         if (ans[i] !=  ? ) {           last = ans[i];         }         if (ans[i] ==  ?  && x > i) {           ans[i] = last;         }       }       int y = 100;       for (int i = 0; i < n; i++) {         if (ans[i] !=  ? ) {           y = i;           break;         }       }       vector<string> chk;       int sw = 1;       if (x == 0) {         string s = ans;         for (int i = 0; i < n; i++) s[i] =  O ;         chk.push_back(s);         s[0] =  C ;         chk.push_back(s);         for (int i = 1; i < n; i++) s[i] =  H ;         chk.push_back(s);         s[0] =  H ;         chk.push_back(s);         sw = 0;       }       if (sw && ans[0] ==  ?  && ans[n - 1] ==  ? ) {         string s = ans;         s[0] = s[y];         for (int i = n - 1; i > x; i--) {           s[i] =  O ;         }         chk.push_back(s);         s[0] =  C ;         chk.push_back(s);         for (int i = n - 1; i > x; i--) {           s[i] =  H ;         }         chk.push_back(s);         s[0] = s[y];         chk.push_back(s);         sw = 0;       }       if (sw && ans[0] ==  ? ) {         string s = ans;         s[0] =  C ;         chk.push_back(s);         s[0] = s[1];         chk.push_back(s);         sw = 0;       }       if (sw && ans[n - 1] ==  ? ) {         string s = ans;         for (int i = n - 1; i > x; i--) {           s[i] =  H ;         }         chk.push_back(s);         for (int i = n - 1; i > x; i--) {           s[i] =  O ;         }         chk.push_back(s);         sw = 0;       }       if (sw || chk.size() == 0) {         cout <<  !   << ans << endl;         cout.flush();         int r;         cin >> r;         if (r == 0) exit(0);         continue;       }       int r = -1;       for (int i = 0; i < chk.size() - 1; i++) {         qu(chk[i]);         if (v.size()) {           cout <<  !   << chk[i] << endl;           cout.flush();           cin >> r;           if (r == 0) {             exit(0);           }           break;         }       }       if (r == -1) {         cout <<  !   << chk.back() << endl;         cout.flush();         cin >> r;         if (r == 0) {           exit(0);         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const int SIZE = 1e6 + 5;   const long long INF = 1LL << 55;   const double eps = 1e-10;   long long expo(long long a, long long b) {     if (b == 0) return 1;     long long h = expo(a, b / 2);     h = (h * h) % MOD;     if (b % 2) h = (h * a) % MOD;     return h;   }   long long f[100009];   long long ivf[100009];   long long C(long long a, long long b) {     return (((f[a] * ivf[b]) % MOD) * ivf[a - b]) % MOD;   }   char s[100009];   long long dp[100009];   int main() {     f[0] = ivf[0] = 1;     for (int i = (1); i < (100009); ++i) {       f[i] = (f[i - 1] * i) % MOD;       ivf[i] = expo(f[i], MOD - 2);     }     int n, k;     scanf( %d%d , &n, &k);     scanf( %s , (s));     for (int j = (1); j < (n + 1); ++j) {       if (n - j - 1 < k - 1)         dp[j] = dp[j - 1];       else         dp[j] = (dp[j - 1] + expo(10, j - 1) * C(n - j - 1, k - 1)) % MOD;     }     long long ans = 0;     for (int i = 0; i < (n); ++i) {       ans = (ans + (long long)(s[i] -  0 ) * dp[n - i - 1]) % MOD;       if (i >= k && n - i - 1 >= 0)         ans = (ans +                (long long)(s[i] -  0 ) * (expo(10, n - i - 1) * C(i, k)) % MOD) %               MOD;     }     printf( %I64d , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 5;   template <typename T>   void chkmax(T &x, T y) {     x = max(x, y);   }   template <typename T>   void chkmin(T &x, T y) {     x = min(x, y);   }   template <typename T>   void read(T &x) {     x = 0;     int f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -f;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     x *= f;   }   int ans, dp[MAXN][2], sum[MAXN][2];   vector<int> a[MAXN];   void update(int pos) {     dp[pos][0] = sum[pos][1] + 1;     dp[pos][1] = sum[pos][0];   }   void getdp(int pos, int fa) {     for (auto x : a[pos])       if (x != fa) {         getdp(x, pos);         sum[pos][0] += dp[x][0];         sum[pos][1] += dp[x][1];       }     update(pos);   }   void getans(int pos, int fa) {     chkmin(ans, dp[pos][0] - 1);     for (auto x : a[pos])       if (x != fa) {         sum[pos][0] -= dp[x][0];         sum[pos][1] -= dp[x][1];         update(pos);         sum[x][0] += dp[pos][0];         sum[x][1] += dp[pos][1];         update(x);         getans(x, pos);         sum[x][0] -= dp[pos][0];         sum[x][1] -= dp[pos][1];         update(x);         sum[pos][0] += dp[x][0];         sum[pos][1] += dp[x][1];         update(pos);       }   }   int main() {     int n;     read(n);     for (int i = 1; i <= n - 1; i++) {       int x, y;       read(x), read(y);       a[x].push_back(y);       a[y].push_back(x);     }     ans = n + 1;     getdp(1, 0);     getans(1, 0);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 1;   int f[MAXN];   int s[MAXN];   int e[MAXN];   int main() {     string S;     cin >> S;     int maxi = 0;     int len = 0;     int start = 0;     stack<int> st;     f[0] = 1;     s[0] = -1;     e[0] = -1;     for (int i = 0; i < S.length(); i++) {       if (S[i] ==  ( ) {         st.push(i);       } else if (st.empty()) {         e[i] = s[i] = -1;       } else {         start = st.top();         st.pop();         s[i] = e[i] = start;         start--;         if (start >= 0 && S[start] ==  )  && s[start] >= 0 && e[start] >= 0) {           e[i] = e[start];         }         len = i - e[i] + 1;         f[len]++;         maxi = max(maxi, len);       }     }     cout << maxi <<     << f[maxi] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100, yzh = 1e9 + 7;   void read(int &x) {     char ch;     bool flag = 0;     for (ch = getchar(); !isdigit(ch) && ((flag |= (ch ==  - )) || 1);          ch = getchar())       ;     for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar())       ;     x *= 1 - 2 * flag;   }   void print(long long x) {     if (x > 9) print(x / 10);     putchar(x % 10 + 48);   }   void write(long long x) {     if (x < 0) putchar( - );     print(((x) < 0 ? (-(x)) : (x)));   }   int n, x, g[N + 5];   int f[N + 5][N + 5][N + 5];   char ch[N + 5];   int quick_pow(int a, int b) {     int ans = 1;     while (b) {       if (b & 1) ans = 1ll * ans * a % yzh;       b >>= 1, a = 1ll * a * a % yzh;     }     return ans;   }   void work() {     read(n), read(x);     scanf( %s , ch + 1);     g[0] = g[1] = 1;     for (int i = 2; i <= x; i++) g[i] = (g[i - 1] + g[i - 2]) % (yzh - 1);     for (int i = 0; i <= x; i++) g[i] = quick_pow(2, g[i]);     for (int i = 1; i <= n; i++)       if (ch[i] ==  0 )         f[i][i][0] = 1;       else         f[i][i][1] = 1;     for (int i = 2; i <= x; i++) {       for (int l = 1; l <= n; l++)         for (int r = l; r <= n; r++) {           if (r == n)             (f[l][r][i] += 1ll * f[l][r][i - 1] * g[i - 2] % yzh) %= yzh;           else             (f[l][r][i] += f[l][r][i - 1]) %= yzh;           if (l == 1)             (f[l][r][i] += 1ll * f[l][r][i - 2] * g[i - 1] % yzh) %= yzh;           else             (f[l][r][i] += f[l][r][i - 2]) %= yzh;           for (int k = l; k < r; k++)             (f[l][r][i] += 1ll * f[l][k][i - 1] * f[k + 1][r][i - 2] % yzh) %=                 yzh;         }     }     (write(f[1][n][x]), putchar(  n ));   }   int main() {     work();     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int mod = (int)1e9 + 7;   int sum(int a, int b) {     int s = a + b;     if (s >= mod) s -= mod;     return s;   }   int mult(int a, int b) { return (1LL * a * b) % mod; }   int pw(int a, int b) {     if (b == 0) return 1;     if (b & 1) return mult(a, pw(a, b - 1));     int res = pw(a, b / 2);     return mult(res, res);   }   const int maxN = (int)1e5 + 100;   int dp[maxN];   int calc(int x) {     dp[0] = 2;     dp[1] = 2;     for (int i = 2; i <= x; i++) {       dp[i] = 0;       dp[i] = sum(dp[i], dp[i - 1]);       dp[i] = sum(dp[i], dp[i - 2]);     }     return dp[x];   }   int n, m;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> m;     int f1 = calc(n);     int f2 = calc(m);     int ans = sum(f1, f2);     ans -= 2;     if (ans < 0) ans += mod;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000 * 1000 * 1000;   const long long LINF = (long long)INF * INF;   const int MAX = 2e5;   const double EPS = 1e-9;   const double PI = acos(-1.);   int n, m, k;   vector<pair<int, long long> > g[300005];   set<pair<pair<int, int>, int> > elist;   set<int> ans;   int siz[300005];   namespace D {   vector<long long> d;   vector<pair<long long, long long> > p;   void go() {     d.resize(n, LINF);     p.resize(n);     d[0] = 0;     priority_queue<pair<long long, long long> > q;     q.push(make_pair(0LL, 0LL));     while (!q.empty()) {       long long v = q.top().second, cur_d = -q.top().first;       q.pop();       if (cur_d > d[v]) continue;       for (size_t j = 0; j < g[v].size(); ++j) {         long long to = g[v][j].first, len = g[v][j].second;         if (d[v] + len < d[to]) {           d[to] = d[v] + len;           p[to] = make_pair(v, len);           q.push(make_pair(-d[to], to));         }       }     }   }   }  // namespace D   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m >> k;     for (int i = (0); i < (m); ++i) {       int x, y, z;       cin >> x >> y >> z;       x--;       y--;       g[x].push_back(make_pair(y, z));       g[y].push_back(make_pair(x, z));       if (x > y) swap(x, y);       elist.insert(make_pair(make_pair(x, y), i + 1));     }     D::go();     for (int i = (0); i < (n); ++i) {       g[i].clear();     }     for (int i = (1); i < (n); ++i) {       int u = D::p[i].first;       int v = i;       int w = D::p[i].second;       g[u].push_back(make_pair(v, w));       g[v].push_back(make_pair(u, w));       if (u > v) swap(u, v);       int id = elist.lower_bound(make_pair(make_pair(u, v), -1))->second;       ans.insert(id);     }     if (k == 0) {       cout << 0;       return 0;     }     set<int> foo;     for (int i = (0); i < (n); ++i) {       siz[i] = (int)g[i].size();       if ((int)g[i].size() == 1) {         foo.insert(i);       }     }     int cur = n - 1;     while (cur > k) {       int u = *foo.begin();       foo.erase(foo.begin());       if (u == 0) continue;       siz[u] = -1;       for (int i = (0); i < ((int)g[u].size()); ++i) {         int v = g[u][i].first;         if (siz[v] == 2) {           if (v) foo.insert(v);         }         if (siz[v] != -1) {           siz[v]--;           int x = u;           int y = v;           if (x > y) swap(x, y);           int id = elist.lower_bound(make_pair(make_pair(x, y), -1))->second;           ans.erase(id);         }       }       cur--;     }     cout << ans.size() << endl;     for (auto& iter : ans) {       cout << iter <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     char ch = getchar();     long long p = 1, data = 0;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) p = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       data = data * 10 + (ch ^ 48);       ch = getchar();     }     return p * data;   }   inline long long qpow(long long a, long long b) {     long long r = 1;     while (b) {       if (b & 1) r = a * r;       a = a * a;       b >>= 1;     }     return r;   }   inline long long gcd(long long a, long long b) {     if (!a || !b) return (!a) ? b : a;     while (b ^= a ^= b ^= a %= b)       ;     return a;   }   inline long long lcm(long long a, long long b) { return a * b / gcd(a, b); }   void exgcd(long long a, long long b, long long &x, long long &y) {     if (!b)       x = 1, y = 0;     else {       exgcd(b, a % b, y, x);       y -= x * (a / b);     }   }   const int mod = 1e9 + 7;   int main() {     int n = read();     long long a[2] = {0, 0};     for (int i = 1; i <= n; i++) {       long long x = read();       a[i & 1] += x / 2 + x % 2;       a[1 - i & 1] += x / 2;     }     printf( %lld n , min(a[0], a[1]));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct edge {     int to, next, v;   } e[2005 * 105];   int head[2005], tot, n;   void add(int x, int y, int v) {     e[++tot] = (edge){y, head[x], v};     head[x] = tot;   }   struct Graph {     int S, sz;     bool vis[2005];     long long dis[2005], b[2005];     void work() {       for (int i = 1; i <= n; i++)         if (i != S) dis[i] = (1ll << 62);       for (int i = 1; i <= n; i++) {         int k = 0;         for (int j = 1; j <= n; j++)           if (!vis[j] && (!k || dis[j] < dis[k])) k = j;         vis[k] = 1;         for (int j = head[k]; j; j = e[j].next)           dis[e[j].to] = min(dis[e[j].to], dis[k] + e[j].v);       }       memcpy(b, dis, sizeof(b));       sort(b + 1, b + n + 1);       sz = unique(b + 1, b + n + 1) - b - 1;       for (int i = 1; i <= n; i++)         dis[i] = lower_bound(b + 1, b + sz + 1, dis[i]) - b;     }   } G[2];   int sz[2005][2005];   long long sum[2005][2005];   long long f[2005][2005][2][2];   bool vis[2005][2005][2][2];   int SZ(int x, int y, int X, int Y) { return sz[x][y] - sz[X][Y]; }   long long SUM(int x, int y, int X, int Y) { return sum[x][y] - sum[X][Y]; }   long long DP(int x, int y, int who, int can) {     if (x > G[0].sz || y > G[1].sz) return 0;     if (vis[x][y][who][can]) return f[x][y][who][can];     vis[x][y][who][can] = 1;     long long ans;     if (who)       ans = DP(x, y + 1, who, can || SZ(x, y, x, y + 1)) + SUM(x, y, x, y + 1);     else       ans = DP(x + 1, y, who, can || SZ(x, y, x + 1, y)) + SUM(x, y, x + 1, y);     if (can) ans = max(ans, -DP(x, y, who ^ 1, 0));     return f[x][y][who][can] = ans;   }   int m, v[2005];   int main() {     scanf( %d%d%d%d , &n, &m, &G[0].S, &G[1].S);     for (int i = 1; i <= n; i++) scanf( %d , &v[i]);     for (int i = 1; i <= m; i++) {       int x, y, v;       scanf( %d%d%d , &x, &y, &v);       add(x, y, v);       add(y, x, v);     }     G[0].work();     G[1].work();     for (int i = 1; i <= n; i++) {       sz[G[0].dis[i]][G[1].dis[i]]++;       sum[G[0].dis[i]][G[1].dis[i]] += v[i];     }     for (int i = G[0].sz; i; i--)       for (int j = G[1].sz; j; j--) {         sz[i][j] += sz[i][j + 1] + sz[i + 1][j] - sz[i + 1][j + 1];         sum[i][j] += sum[i][j + 1] + sum[i + 1][j] - sum[i + 1][j + 1];       }     long long ans = DP(1, 1, 0, 0);     if (ans == 0)       puts( Flowers );     else if (ans < 0)       puts( Cry );     else       puts( Break a heart );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int a, b, i, cnt, x;     cin >> a >> b;     if (a < b) {       cout <<  0 n ;       return 0;     }     if (a == b) {       cout <<  infinity n ;       return 0;     }     a = a - b;     cnt = 0;     for (i = 1; i <= sqrt(a); i++) {       if (a % i == 0) {         x = a / i;         if (x == i) {           if (i > b) cnt++;         } else {           if (i > b) cnt++;           if (x > b) cnt++;         }       }     }     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ansp[200001];   int main() {     long long k;     memset(ansp, 0, sizeof(ansp));     scanf( %lld , &k);     char s[200001], t[200001], ans[200001];     scanf( %s %s , s, t);     long long add = 0, dec = 0, again = 0;     long long i, j;     for (i = 0; i < k; i++) {       long long x = s[i] -  a , y = t[i] -  a  + add;       add = 0;       if ((x + y) % 2 != 0) {         add = 26;         y--;       }       long long now = (x + y) / 2;       ansp[i] = now;     }     for (i = k - 1; i >= 0; i--) {       ansp[i - 1] += ansp[i] / 26;       ansp[i] %= 26;     }     for (i = 0; i < k; i++) printf( %c , (char)(ansp[i] +  a ));   }


#include <bits/stdc++.h>   using namespace std;   int bit(int mask, int n) { return mask & (1 << n) ? 1 : 0; }   int rev(int a) {     int res = 0;     for (int i = 0; i < 8; ++i) res = res | ((1 << (7 - i)) * bit(a, i));     return res;   }   int main() {     string s;     int prev = 0;     getline(cin, s);     for (int i = 0; i < s.length(); ++i) {       int cur = (256 + prev - rev(s[i])) % 256;       cout << cur << endl;       prev = rev(s[i]);     }     cin >> s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   long long a[100010], ans;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   inline long long cal(long long a) {     if (a % 2 == 0) return 0;     long long tmp = 0;     for (int i = 0; (a << i) < m; i++) {       tmp += m - (a << i);     }     return tmp;   }   int main() {     scanf( %d%d , &n, &m);     long long d = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (i)         d = gcd(d, a[i] - 1);       else         d = a[i] - 1;     }     for (int i = 1; i * i <= d; i++) {       if (d % i == 0) {         ans += cal(i);         if (i * i != d) ans += cal(d / i);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 2000000000;   struct Edge {     int from, to, cap, flow, index;     Edge(int from, int to, int cap, int flow, int index)         : from(from), to(to), cap(cap), flow(flow), index(index) {}   };   struct Dinic {     int N;     vector<vector<Edge> > G;     vector<Edge *> dad;     vector<int> Q;     Dinic(int N) : N(N), G(N), dad(N), Q(N) {}     void AddEdge(int from, int to, int cap) {       G[from].push_back(Edge(from, to, cap, 0, G[to].size()));       if (from == to) G[from].back().index++;       G[to].push_back(Edge(to, from, 0, 0, G[from].size() - 1));     }     long long BlockingFlow(int s, int t) {       fill(dad.begin(), dad.end(), (Edge *)NULL);       dad[s] = &G[0][0] - 1;       int head = 0, tail = 0;       Q[tail++] = s;       while (head < tail) {         int x = Q[head++];         for (int i = 0; i < G[x].size(); i++) {           Edge &e = G[x][i];           if (!dad[e.to] && e.cap - e.flow > 0) {             dad[e.to] = &G[x][i];             Q[tail++] = e.to;           }         }       }       if (!dad[t]) return 0;       long long totflow = 0;       for (int i = 0; i < G[t].size(); i++) {         Edge *start = &G[G[t][i].to][G[t][i].index];         int amt = INF;         for (Edge *e = start; amt && e != dad[s]; e = dad[e->from]) {           if (!e) {             amt = 0;             break;           }           amt = min(amt, e->cap - e->flow);         }         if (amt == 0) continue;         for (Edge *e = start; amt && e != dad[s]; e = dad[e->from]) {           e->flow += amt;           G[e->to][e->index].flow -= amt;         }         totflow += amt;       }       return totflow;     }     long long GetMaxFlow(int s, int t) {       long long totflow = 0;       while (long long flow = BlockingFlow(s, t)) totflow += flow;       return totflow;     }   };   bool prime[20010];   void sieve() {     int k = sqrt(20010);     for (int i = 3; i <= k; i++) {       if (!prime[i]) {         for (int j = i * i; j < 20001; j += i + i) {           prime[j] = 1;         }       }     }     return;   }   int a[210];   vector<int> adj[210];   vector<vector<int> > ans;   vector<int> tmp;   bool vis[210];   void dfs(int u) {     vis[u] = 1;     tmp.push_back(u);     for (int i = 0; i < (int)adj[u].size(); i++) {       int v = adj[u][i];       if (!vis[v]) {         dfs(v);         return;       }     }     return;   }   inline bool chk(int x, int n) { return (x >= 1 && x <= n); }   int main() {     sieve();     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     Dinic din(n + 2);     for (int i = 1; i <= n; i++) {       if (a[i] & 1) {         din.AddEdge(0, i, 2);       } else {         din.AddEdge(i, n + 1, 2);       }       for (int j = 1; j <= n; j++) {         if (a[i] % 2 == 1 && a[j] % 2 == 0 && !prime[a[i] + a[j]]) {           din.AddEdge(i, j, 1);         }       }     }     if (din.GetMaxFlow(0, n + 1) != n) {       cout <<  Impossible n ;     } else {       for (int i = 0; i < (int)din.G.size(); i++) {         for (int j = 0; j < (int)din.G[i].size(); j++) {           if (din.G[i][j].flow && chk(din.G[i][j].from, n) &&               chk(din.G[i][j].to, n)) {             adj[din.G[i][j].from].push_back(din.G[i][j].to);           }         }       }       for (int i = 1; i <= n; i++) {         if (!vis[i]) {           (tmp.clear());           dfs(i);           ans.push_back(tmp);         }       }       cout << (int)ans.size() <<   n ;       for (int i = 0; i < (int)ans.size(); i++) {         cout << (int)ans[i].size();         for (int j = 0; j < (int)ans[i].size(); j++) {           cout <<     << ans[i][j];         }         cout <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool comp(int x, int y) { return x > y; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int t = 1;     cin >> t;     long long m, n, k;     string a, b;     while (t--) {       cin >> n;       vector<long long> vec(n);       for (long long i = 0; i < n; i++) cin >> vec[i];       map<long long, long long> mp;       for (long long i = 0; i < n; i++) {         long long k = (long long)(log2(vec[i]));         mp[k] += 1;       }       map<long long, long long>::iterator it = mp.begin();       long long ans = 0;       while (it != mp.end()) {         ans += ((it->second) * (it->second - 1)) / 2;         ++it;       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long a, b, c, d;     cin >> a >> b >> c >> d;     long long ans = 0, fl = 0;     if (a != c && b != d)       ans = abs(a - c) + abs(b - d) + 2;     else       ans = abs(a - c) + abs(b - d);     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) solve();     return 0;     ;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void rd(T &ret) {     ret = 0;     bool ok = 0, u = 0;     for (;;) {       int c = getchar();       if (c >=  0  && c <=  9 )         ret = (ret << 3) + (ret << 1) + c -  0 , ok = 1;       else if (c ==  - )         u = 1;       else if (ok) {         if (u) ret *= -1;         return;       }     }   }   long long powmod(long long p, long long n, long long mod) {     long long ret = 1;     for (; n; n >>= 1) {       if (n & 1) ret = ret * p % mod;       p = p * p % mod;     }     return ret;   }   template <class T>   bool chmin(T &a, const T &b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool chmax(T &a, const T &b) {     return b > a ? a = b, 1 : 0;   }   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   const long long mod = 998244353;   const int N = (int)2e5 + 9;   template <int sz>   struct combo {     const long long mod = ::mod;     long long *fac, *ifac;     long long mem_fac[sz + 5], mem_ifac[sz + 5];     combo(long long *fa = 0, long long *ifa = 0) {       fac = fa ? fa : mem_fac;       ifac = ifa ? ifa : mem_ifac;       fac[0] = ifac[0] = 1;       for (int i = 1; i <= sz; ++i) {         fac[i] = i * fac[i - 1] % mod;         ifac[i] = powmod(fac[i], mod - 2, mod);       }     }     long long comb(long long n, long long m) {       if (n < m) return 0;       return (fac[n] * ifac[m] % mod) * ifac[n - m] % mod;     }   };   namespace ntt {   const int N = ::N;   const long long mod = ::mod, rt = 3;   long long G[55], iG[55], itwo[55];   void add(int &a, int b) {     a += b;     if (a >= mod) a -= mod;   }   void init() {     int now = (mod - 1) / 2, len = 1, irt = powmod(rt, mod - 2, mod);     while (now % 2 == 0) {       G[len] = powmod(rt, now, mod);       iG[len] = powmod(irt, now, mod);       itwo[len] = powmod(1 << len, mod - 2, mod);       now >>= 1;       len++;     }   }   void dft(long long *first, int n, int fg = 1) {     for (int i = (n >> 1), j = 1, k; j < n; ++j) {       if (i < j) swap(first[i], first[j]);       for (k = (n >> 1); k & i; i ^= k, k >>= 1)         ;       i ^= k;     }     long long r, tr, u, v;     for (int m = 2, now = 1; m <= n; m <<= 1, now++) {       r = fg > 0 ? G[now] : iG[now];       for (int i = 0, j; i < n; i += m) {         tr = 1, u, v;         for (j = i; j < i + (m >> 1); ++j) {           u = first[j];           v = first[j + (m >> 1)] * tr % mod;           first[j] = (u + v) % mod;           first[j + (m >> 1)] = (u + mod - v) % mod;           tr = tr * r % mod;         }       }     }   }   void brute(long long *a, long long *b, int n, int m) {     static long long c[N];     for (int k = 0, t; k < n + m - 1; ++k) {       t = 0;       for (int i = max(k - m + 1, 0); i < n && i <= k; ++i) {         add(t, a[i] * b[k - i] % mod);       }       c[k] = t;     }     for (int k = 0; k < n + m - 1; ++k) a[k] = c[k];   }   void mul(long long *a, long long *b, int n, int m) {     if (n + m <= 200) {       brute(a, b, n, m);       return;     }     int nn = n + m - 1;     if (n == 0 || m == 0) {       memset(a, 0, nn * sizeof(a[0]));       return;     }     int L, len;     for (L = 1, len = 0; L < nn; ++len, L <<= 1)       ;     if (n < L) memset(a + n, 0, (L - n) * sizeof(a[0]));     if (m < L) memset(b + m, 0, (L - m) * sizeof(b[0]));     dft(a, L, 1);     dft(b, L, 1);     for (int i = 0; i < L; ++i) a[i] = a[i] * b[i] % mod;     dft(a, L, -1);     for (int i = 0; i < L; ++i) a[i] = a[i] * itwo[len] % mod;   }   }  // namespace ntt   long long a[N], b[N], fac[N], fnv[N], u[N], v[N], pw[N], ct[N], c[N];   combo<100005> C(fac, fnv);   void solve(int n) {     if (n == 1) {       c[0] = 0;       c[1] = 1;     } else if (n & 1) {       solve(n - 1);       for (int i = (n + 1) - 1; i >= (1); i--)         c[i] = (c[i - 1] + (long long)(n - 1) * c[i]) % mod;       c[0] = 0;     } else {       solve(n / 2);       int t = n / 2;       pw[0] = 1;       for (int i = (1); i < (t + 1); i++) pw[i] = pw[i - 1] * t % mod;       for (int i = (0); i < (t + 1); i++) u[i] = c[i] * fac[i] % mod;       for (int i = (0); i < (t + 1); i++) v[i] = pw[i] * fnv[i] % mod;       reverse(v, v + t + 1);       ntt::mul(u, v, t + 1, t + 1);       for (int i = (0); i < (t + 1); i++) ct[i] = u[i + t] * fnv[i] % mod;       ntt::mul(c, ct, t + 1, t + 1);     }   }   int main() {     int n, a, b;     cin >> n >> a >> b;     --a;     --b;     if (a < 0 || b < 0) {       puts( 0 );       return 0;     }     if (n == 1) {       puts(a == 0 && b == 0 ?  1  :  0 );       return 0;     }     if (a + b >= n) {       puts( 0 );       return 0;     }     ntt::init();     solve(n - 1);     cout << C.comb(a + b, a) * c[a + b] % mod;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int N;     cin >> N;     int arr[N], grr[100006] = {0}, fre[100005] = {0}, x, ma = 0, ans = 0;     for (int i = 0; i < N; i++) {       bool ok = false;       cin >> x;       grr[fre[x]]--;       fre[x]++;       grr[fre[x]]++;       ma = max(ma, fre[x]);       if (grr[1] == i + 1)         ok = true;       else if (grr[i + 1] == 1)         ok = true;       else if (grr[ma - 1] * (ma - 1) == i + 1 - ma && grr[ma] == 1)         ok = true;       else if (grr[1] == 1 && grr[ma] * (ma) == i)         ok = true;       if (ok) ans = i + 1;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int SIZE = 2e6 + 10;   int a[SIZE];   int num[SIZE], nxt[SIZE];   int main() {     int n, q;     scanf( %d%d , &n, &q);     long long sum = 0;     for (int i = 0; i < (n); ++i) {       scanf( %d , &(a[i]));       sum += a[i];       a[i + n] = a[i];     }     for (int tt = 1; tt <= q; tt++) {       long long b;       scanf( %I64d , &b);       if (b >= sum) {         puts( 1 );         continue;       }       {         int rr = -1;         long long now = 0;         for (int i = 0; i < (n); ++i) {           while (now + a[rr + 1] <= b) now += a[++rr];           nxt[i] = rr + 1;           nxt[i + n] = rr + 1 + n;           num[i] = 1;           now -= a[i];         }       }       int an = n;       for (int i = n - 1; i >= 0; i--) {         if (nxt[i] < n) {           num[i] += num[nxt[i]];           nxt[i] = nxt[nxt[i]];         }         if (nxt[i] >= i + n) an = min(an, num[i]);       }       printf( %d n , an);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mul(long long a, long long b) {     return ((a % 1000000007) * (b % 1000000007)) % 1000000007;   }   long long power(long long a, long long b) {     if (b == 0) return 1;     if (b == 1) return a;     long long temp = power(a, b / 2);     if (b % 2 == 0)       return mul(temp, temp);     else       return mul(mul(temp, temp), a);   }   vector<long long> g[100005];   long long color[100005];   long long curr_color, ok;   void dfs(long long node, long long par) {     ok = ok && (color[node] == curr_color);     for (long long i = 0; i < g[node].size(); i++) {       if (g[node][i] != par) {         dfs(g[node][i], node);       }     }   }   long long solve(long long node) {     long long ans = 1;     ok = 1;     for (long long i = 0; i < g[node].size(); i++) {       curr_color = color[g[node][i]];       dfs(g[node][i], node);       ans = ans && ok;     }     return ans;   }   int main() {     long long n, i, x, a, b;     cin >> n;     for (i = 0; i < n - 1; i++) {       cin >> a >> b;       g[a].push_back(b);       g[b].push_back(a);     }     for (i = 0; i < n; i++) cin >> color[i + 1];     long long root1 = -1, root2 = -1;     for (i = 1; i <= n; i++) {       for (long long j = 0; j < g[i].size(); j++) {         if (color[i] != color[g[i][j]]) {           root1 = i;           root2 = g[i][j];         }       }     }     if (root1 == -1) {       cout <<  YES  << endl;       cout << 1 << endl;       return 0;     }     if (solve(root1)) {       cout <<  YES  << endl;       cout << root1 << endl;       return 0;     }     if (solve(root2)) {       cout <<  YES  << endl;       cout << root2 << endl;       return 0;     }     cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, cnt;   char c[11];   int main() {     scanf( %d %s , &n, c + 1);     if (n == 6)       printf( espeon n );     else if (n == 8)       printf( vaporeon n );     else if (c[1] ==  j  || c[2] ==  o  || c[4] ==  t )       printf( jolteon n );     else if (c[1] ==  u  || c[2] ==  m  || c[3] ==  b )       printf( umbreon n );     else if (c[1] ==  l  || c[2] ==  e  || c[4] ==  f )       printf( leafeon n );     else if (c[1] ==  s  || c[2] ==  y  || c[4] ==  v )       printf( sylveon n );     else if (c[1] ==  f  || c[4] ==  r )       printf( flareon n );     else       printf( glaceon n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     const int n = s.length() + 5;     int arr[n];     memset(arr, 0, sizeof arr);     int m, l, r;     for (int i = 0; i < s.length(); i++) {       if (s[i] == s[i + 1]) {         arr[i + 2]++;       }       arr[i + 1] += arr[i];     }     cin >> m;     for (int i = 0; i < m; i++) {       cin >> l >> r;       cout << arr[r] - arr[l] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxl = 2 * 1000 * 100 + 5;   const int maxlg = 22;   vector<pair<int, int> > adj[maxl];   vector<int> tree[maxl];   int n, m, q;   int mark[maxl], depth[maxl];   bool cut[maxl];   int dsu[maxl];   int arr[maxl];   int lca[maxl][maxlg];   int psum1[maxl], psum2[maxl];   bool flag = true;   int par(int index) {     if (dsu[index] < 0) return index;     return dsu[index] = par(dsu[index]);   }   inline void merge(int a, int b) {     a = par(a);     b = par(b);     if (a == b) return;     if (dsu[a] < dsu[b]) swap(a, b);     dsu[b] += dsu[a];     dsu[a] = b;     return;   }   inline int getPar(int index, int x) {     int ind = 0;     while (x) {       if (x & 1) index = lca[index][ind];       ind++;       x /= 2;     }     return index;   }   inline int Lca(int a, int b) {     if (depth[a] < depth[b]) swap(a, b);     a = getPar(a, depth[a] - depth[b]);     if (a == b) return a;     for (int i = maxlg - 1; i >= 0; i--)       if (lca[a][i] != lca[b][i]) {         a = lca[a][i];         b = lca[b][i];       }     return lca[a][0];   }   int dfs_cut(int index, int par = -1) {     mark[index] = 1;     int mn = depth[index];     for (int i = 0; i < adj[index].size(); i++) {       int node = adj[index][i].first, edge = adj[index][i].second;       if (mark[node] == 1 && edge != par) mn = min(mn, depth[node]);       if (!mark[node]) {         depth[node] = depth[index] + 1;         int tmp = dfs_cut(node, edge);         mn = min(mn, tmp);         cut[edge] = (tmp >= depth[node]);       }     }     mark[index] = 2;     return mn;   }   void dfs(int index, int par = -1) {     lca[index][0] = par;     if (par == -1) lca[index][0] = index;     for (int i = 0; i < tree[index].size(); i++) {       int node = tree[index][i];       if (node != par) {         depth[node] = depth[index] + 1;         dfs(node, index);         psum1[index] += psum1[node];         psum2[index] += psum2[node];         if (psum1[node] && psum2[node]) flag = false;       }     }   }   int main() {     memset(dsu, -1, sizeof dsu);     memset(lca, -1, sizeof lca);     scanf( %d %d %d , &n, &m, &q);     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d %d , &a, &b);       a--;       b--;       adj[a].push_back(make_pair(b, i));       adj[b].push_back(make_pair(a, i));     }     for (int i = 0; i < n; i++)       if (!mark[i]) dfs_cut(i);     for (int i = 0; i < n; i++)       for (int j = 0; j < adj[i].size(); j++) {         int node = adj[i][j].first, edge = adj[i][j].second;         if (!cut[edge]) merge(i, node);       }     for (int i = 0; i < n; i++) arr[i] = par(i);     for (int i = 0; i < n; i++)       for (int j = 0; j < adj[i].size(); j++) {         int node = adj[i][j].first, edge = adj[i][j].second;         merge(i, node);         int x = arr[i], y = arr[node];         if (x == y) continue;         tree[x].push_back(y);       }     memset(depth, 0, sizeof depth);     for (int i = 0; i < n; i++)       if (arr[i] == i && lca[i][0] == -1) dfs(i);     for (int j = 1; j < maxlg; j++)       for (int i = 0; i < n; i++)         if (arr[i] == i) lca[i][j] = lca[lca[i][j - 1]][j - 1];     for (int i = 0; i < q; i++) {       int x, y;       scanf( %d %d , &x, &y);       x--;       y--;       x = arr[x];       y = arr[y];       if (par(x) != par(y)) {         flag = false;         continue;       }       int node = Lca(x, y);       psum1[x]++;       psum1[node]--;       psum2[y]++;       psum2[node]--;     }     for (int i = 0; i < n; i++)       if (arr[i] == i && lca[i][0] == i) dfs(i);     if (flag)       printf( Yes n );     else       printf( No n );   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   long long add(long long a, long long b) {     long long ret = a + b;     if (ret >= 1000000007) ret -= 1000000007;     return ret;   }   long long subtract(long long a, long long b) {     long long ret = a - b;     if (ret < 0) ret += 1000000007;     return ret;   }   long long mult(long long a, long long b) {     long long ret = a * b;     if (ret >= 1000000007) ret %= 1000000007;     return ret;   }   long long bigmod(long long a, long long b) {     long long ret = 1;     while (b) {       if (b & 1) ret = mult(ret, a);       b >>= 1;       a = mult(a, a);     }     return ret;   }   long long inverse(long long n) { return bigmod(n, 1000000007 - 2); }   bool base[1000010];   vector<int> primes;   void sieve(int mx) {     mx += 10;     int x = sqrt(mx);     for (int i = 3; i <= x; i += 2)       if (base[i] == 0)         for (int j = i * i, k = i << 1; j < mx; j += k) base[j] = 1;     primes.push_back(2);     for (int i = 3; i < mx; i += 2)       if (base[i] == 0) primes.push_back(i);   }   bool checkBit(int n, int i) { return (n & (1 << i)); }   int setBit(int n, int i) { return (n | (1 << i)); }   int resetBit(int n, int i) { return (n & (~(1 << i))); }   char a[22], b[22];   int c[22];   struct node {     int end;     node *next[2];     node() {       end = 0;       next[0] = next[1] = NULL;     }   } * root;   void insert(int val) {     node *curr = root;     for (int i = 0; i < 18; ++i) {       int id = c[i];       if (curr->next[id] == NULL) curr->next[id] = new node;       curr = curr->next[id];     }     curr->end += val;   }   int query() {     node *curr = root;     for (int i = 0; i < 18; ++i) {       int id = c[i];       if (curr->next[id] == NULL) return 0;       curr = curr->next[id];     }     return curr->end;   }   int main() {     int q;     scanf( %d , &q);     root = new node;     while (q--) {       scanf( %s , a);       scanf( %s , b);       int n = strlen(b);       for (int i = 0; i < 18 - n; ++i) c[i] = 0;       for (int i = 0; i < n; ++i) c[18 - n + i] = ((b[i] -  0 ) & 1);       if (a[0] ==  + )         insert(1);       else if (a[0] ==  - )         insert(-1);       else {         printf( %d n , query());       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int64_t dp[2004], nx[2004];   struct pt {     int64_t v, c;   };   int main() {     ios::sync_with_stdio(false);     int n, m, q;     cin >> n >> m >> q;     vector<vector<pair<int, int>>> G(n + 1);     vector<int> val(n + 1, 0);     vector<int64_t> cost(n + 1, 0);     for (int i = 0; i < m; ++i) {       int a, b, c;       cin >> a >> b >> c;       G[a].push_back({b, c});       G[b].push_back({a, c});       val[a] = max(val[a], c);       val[b] = max(val[b], c);     }     int64_t ans = 0, md = 1000000007;     for (int j = 2; j <= n; ++j) dp[j] = -1e12;     for (int i = 0; i < m; ++i) {       int64_t tm = 0;       for (int j = 1; j <= n; ++j) {         nx[j] = -1e12;         for (auto to : G[j]) {           nx[j] = max(nx[j], dp[to.first] + to.second);         }         tm = max(tm, nx[j]);       }       ans = (ans + tm) % md;       swap(dp, nx);     }     for (int i = 1; i <= n; ++i) {       cost[i] = val[i] * 1ll * m - dp[i];     }     vector<pt> v;     for (int i = 1; i <= n; ++i) {       v.push_back({val[i], cost[i]});     }     int64_t nowq = m + 1;     int64_t mx = 0;     int mxi = 0;     for (int i = 0; i < v.size(); ++i) {       if (nowq * v[i].v - v[i].c > mx) {         mx = nowq * v[i].v - v[i].c;         mxi = i;       }     }     while (nowq <= q) {       int64_t nxq = q + 1;       for (int i = 0; i < v.size(); ++i) {         if (v[i].v > v[mxi].v) {           nxq = min(nxq, 1 + (v[i].c - v[mxi].c) / (v[i].v - v[mxi].v));         }       }       int64_t q2 = (nxq - nowq) * (nxq - nowq - 1) / 2;       q2 %= md;       ans += (nxq - nowq) * (mx % md) + (v[mxi].v * q2) % md;       ans %= md;       mx = 0;       for (int i = 0; i < v.size(); ++i) {         if (nxq * v[i].v - v[i].c > mx) {           mx = nxq * v[i].v - v[i].c;           mxi = i;         }       }       nowq = nxq;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int A[3] = {0};     int num;     cin >> num;     long ip;     while (num--) {       cin >> ip;       if (ip % 3 == 0)         A[0]++;       else if (ip % 3 == 1)         A[1]++;       else if (ip % 3 == 2)         A[2]++;     }     cout << A[0] / 2 + min(A[1], A[2]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, ret, f[26];   vector<pair<pair<int, int>, int> > ss;   int call(char c) { return int(c) - int( a ); }   int main() {     cin >> n;     string s;     for (int i = 1; i <= n; i++) {       cin >> s;       ss.push_back(make_pair(make_pair(call(s[0]), call(s[long(s.length()) - 1])),                              long(s.length())));     }     ret = 0;     for (int c = 0; c < 26; c++) {       fill(f + 0, f + 26, 0);       for (int i = 0; i < n; i++) {         if ((ss[i].first.first == c) || (f[ss[i].first.first] > 0)) {           f[ss[i].first.second] =               max(f[ss[i].first.second], f[ss[i].first.first] + ss[i].second);         }       }       ret = max(ret, f[c]);     }     printf( %d , ret);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x, m, t, cnt, r[105];   int main() {     scanf( %d , &n);     for (int i = (0); i <= (n); i++) {       ++cnt;       if (i < n) scanf( %d , &x);       if (x < 0) ++t;       if (t == 3 || i == n) {         r[m++] = cnt - 1;         cnt = t = 1;       }     }     printf( %d n , m);     for (int i = (0); i < (m); i++) printf( %d  , r[i]);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int vowel(char a) {     if (a ==  a  || a ==  i  || a ==  e  || a ==  u  || a ==  o ) {       return 1;     }     return 0;   }   int main() {     char s[1005];     char t[1005];     int i;     scanf( %s , s);     scanf( %s , t);     if (strlen(s) != strlen(t)) {       printf( NO n );       return 0;     }     for (i = 0; i < strlen(s); i++) {       if (vowel(s[i]) != vowel(t[i])) {         printf( NO n );         return 0;       }     }     printf( YES n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int A[50][50];   int main() {     long long int T;     cin >> T;     while (T--) {       int n;       cin >> n;       for (int i = 0; i < n; i++) {         string s;         cin >> s;         for (int j = 0; j < n; j++) {           A[i][j] = s[j] -  0 ;         }       }       bool f = true;       for (int i = 0; i < n - 1; i++) {         for (int j = 0; j < n - 1; j++) {           if (A[i][j] && !A[i + 1][j] && !A[i][j + 1]) {             f = false;             i = n;             break;           }         }       }       cout << ((f) ?  YES  :  NO ) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, p[500500], pp[500500], t = 1;   vector<long long> s, f;   int fd(long long x) {     if (x == pp[x]) {       return x;     }     return pp[x] = fd(pp[x]);   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       p[i] = i;       pp[i] = i;     }     for (int i = 1; i <= m; i++) {       long long x;       cin >> x;       if (x == 1) {         long long l, r;         cin >> l >> r;         p[l] = r;         pp[l] = r;       }       if (x == 2) {         long long r;         cin >> r;         s.push_back(r);         f.push_back(fd(r));       }       if (x == 3) {         long long r, y;         cin >> r >> y;         int st = s[y - 1], fn = f[y - 1];         while (st != fn) {           if (st == r) {             break;           }           st = p[st];         }         if (st == r) {           cout <<  YES  << endl;           continue;         }         cout <<  NO  << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long t, n, a[100010], b[100010], c[100], w, e;   long long ans = 0;   void init() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= 90; i++) c[i] = 0;     sort(a + 1, a + n + 1);     w = 1;     for (int i = 1; i <= n; i++) {       while (a[i] > ((1 << w) - 1)) w++;       b[i] = w;       c[w]++;     }     ans = 0;     for (int i = 1; i <= w; i++) ans = ans + (c[i] - 1) * c[i] / 2;     cout << ans << endl;   }   int main() {     cin >> t;     for (int q = 1; q <= t; q++) init();     return 0;   }


#include<bits/stdc++.h>   using namespace std;   const int N=10,M=405,mod=998244353;   int n,m,k,t,v[M],id[M][M],ch[M][30],l[N];   char s[N][N];   struct mat{int a[M][M];};   mat operator*(mat x,mat y)   {    mat z;    for(int i=1;i<=t;i++)    {     for(int j=1;j<=t;j++)     {      z.a[i][j]=0;      for(int k=1;k<=t;k++)       z.a[i][j]=(z.a[i][j]+1ll*x.a[i][k]*y.a[k][j]%mod)%mod;     }    }    return z;   }   mat qp(mat a,int b)   {    mat ans=a;    b--;    while(b)    {     if(b&1)      ans=ans*a;     a=a*a;     b>>=1;    }    return ans;   }   mat tr;   int sol(int x,int y)   {    if(x>y)     swap(x,y);    if(id[x][y])     return id[x][y];    int u=++t;    id[x][y]=u;    for(int i=0;i<26;i++)    {     if(ch[x][i]&&ch[y][i])     {      int nx1=ch[x][i],nx2=ch[y][i];      tr.a[u][sol(nx1,nx2)]++;      if(v[nx1])       tr.a[u][sol(1,nx2)]++;      if(v[nx2])       tr.a[u][sol(nx1,1)]++;      if(v[nx1]&&v[nx2])       tr.a[u][sol(1,1)]++;     }    }    return u;   }   int main()   {    scanf( %d%d ,&n,&m);    k=1;    for(int i=1;i<=n;i++)    {     scanf( %s ,s[i]+1),l[i]=strlen(s[i]+1);     int u=1;     for(int j=1;j<=l[i];j++)     {      int x=s[i][j]- a ;      if(!ch[u][x])       ch[u][x]=++k;      u=ch[u][x];     }     v[u]=1;    }    memset(tr.a,0,sizeof(tr.a));    int b=sol(1,1);    tr=qp(tr,m);    printf( %d n ,tr.a[b][b]);    return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int a[4005];   long long int dp[4005][4005];   int m;   int dfs(int l, int r) {     if (l > r) return 0;     long long int mi = 1e18;     long long int root = -1;     for (int i = l; i <= r; i++) {       if (a[i] < mi) {         mi = a[i];         root = i;       }     }     int root_l = dfs(l, root - 1);     int root_r = dfs(root + 1, r);     int sz = r - l + 1;     for (int i = 0; i <= sz; i++) {       int sz_l = root - l;       int sz_r = r - root;       dp[root][i] = -1e18;       for (int j = max(0, i - sz_r - 1); j <= min(sz_l, i); j++) {         dp[root][i] = max(dp[root][i], dp[root_l][j] + dp[root_r][i - j] -                                            2ll * j * (i - j) * a[root]);         if (i - 1 - j >= 0)           dp[root][i] = max(dp[root][i], dp[root_l][j] + dp[root_r][i - 1 - j] -                                              2ll * (j + 1) * (i - j) * a[root] +                                              a[root] + 1ll * m * a[root]);       }     }     return root;   }   int main(void) {     int n;     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     for (int i = 0; i <= n; i++) {       dp[0][i] = -1e18;     }     dp[0][0] = 0;     int root = dfs(1, n);     printf( %lld n , dp[root][m]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5010;   const int mod = 1e9 + 7;   const int INF = 0x3f3f3f3f;   const double pi = acos(-1.0);   const double eps = 1e-4;   int main() {     double d, l, v1, v2;     cin >> d >> l >> v1 >> v2;     printf( %.6lf n , (l - d) / (v1 + v2));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class S, class T>   ostream& operator<<(ostream& o, const pair<S, T>& p) {     return o <<  (  << p.first <<  ,  << p.second <<  ) ;   }   template <class T>   ostream& operator<<(ostream& o, const vector<T>& vc) {     o <<  sz =   << vc.size() << endl <<  [ ;     for (const T& v : vc) o << v <<  , ;     o <<  ] ;     return o;   }   int cnt;   vector<int> ask(int v) {     cout <<  ?   << v << endl;     int K;     cin >> K;     vector<int> ret;     for (int i = 0; i < (int)(K); i++) {       int x;       cin >> x;       ret.push_back(x);     }     cnt++;     assert(cnt <= 16);     return ret;   }   void ans(int v) { cout <<  !   << v << endl; }   bool ToLeaf(int v, int p, vector<int>& vs, vector<vector<int> >& vis) {     while (true) {       vector<int> vi = ask(v);       if (vi.size() == 2) {         ans(v);         return 1;       }       vs.push_back(v);       vis.push_back(vi);       if (vi.size() == 1) break;       int nv = -1;       for (int i = 0; i < (int)(3); i++)         if (vi[i] != p) nv = vi[i];       p = v, v = nv;     }     return 0;   }   bool Leaf2Leaf(vector<int>& vs, vector<vector<int> >& vis) {     int s = 1;     if (ToLeaf(s, -1, vs, vis)) return 1;     if (vs.size() == 1) return 0;     int nxt = -1;     for (int nv : vis[0])       if (nv != vs[1]) nxt = nv;     reverse(vs.begin(), vs.end());     reverse(vis.begin(), vis.end());     if (ToLeaf(nxt, s, vs, vis)) return 1;     return 0;   }   bool dfs(int v, int p, int d = 0) {     vector<int> vi = ask(v);     if (vi.size() == 2) {       ans(v);       return 1;     }     if (d == 2) {       return 0;     }     for (int u : vi)       if (u != p) {         if (cnt < 16) {           if (dfs(u, v, d + 1)) return 1;         } else {           ans(u);           return 1;         }       }     return 0;   }   void solve() {     cnt = 0;     int H;     cin >> H;     vector<int> vs;     vector<vector<int> > vis;     if (Leaf2Leaf(vs, vis)) {       return;     }     int K = vs.size();     while (K <= 5) {       int top = vs[K / 2];       int nxt = -1;       if (vis[K / 2].size() == 1)         nxt = vis[K / 2][0];       else         nxt = vis[K / 2][0] ^ vis[K / 2][1] ^ vis[K / 2][2] ^ vs[K / 2 - 1] ^               vs[K / 2 + 1];       for (int i = 0; i < (int)(K / 2); i++) vs.pop_back(), vis.pop_back();       if (ToLeaf(nxt, top, vs, vis)) {         return;       }       K = vs.size();     }     int top = vs[K / 2];     int nxt = vis[K / 2][0] ^ vis[K / 2][1] ^ vis[K / 2][2] ^ vs[K / 2 - 1] ^               vs[K / 2 + 1];     assert(dfs(nxt, top));   }   int main() {     int T;     cin >> T;     for (int t = 0; t < (int)(T); t++) solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long n;     cin >> n;     long long d = 0;     vector<long long> v;     vector<long long> a;     long long val = 0;     map<long long, long long> m;     long long start = 0, end = -1, count = 0;     for (long long i = 0; i < (long long)n; i++) {       cin >> val;       if (i == 0) {         if (val < 0) {           count++;           break;         } else {           v.push_back(val);           m[val]++;         }       } else {         if (val > 0) {           if (m[val] >= m[-val] && m[val] == 0) {             v.push_back(val);             m[val]++;           } else {             count++;             break;           }         } else {           if (v.size() == 0 && start != end) {             d++;             end = i;             a.push_back(end - start + 1);             start = i + 1;             m.clear();           }           if (m[val] >= m[-val]) {             count++;             break;           } else {             m[val]++;             for (long long j = 0; j < v.size(); j++) {               if (v[j] == (-val)) {                 v.erase(v.begin() + j);                 break;               }             }           }           if (v.size() == 0 && start != end) {             d++;             end = i;             a.push_back(end - start + 1);             start = i + 1;             m.clear();           }         }       }     }     if (v.size() != 0 || count > 0) {       cout << -1 <<   n ;     } else {       cout << d <<   n ;       for (long long i = 0; i < a.size(); i++) {         cout << a[i] <<    ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     long long ar[n + 1];     for (long long i = 1; i <= n; i++) {       cin >> ar[i];     }     ar[0] = 0;     long long ans = 0;     for (long long i = 0; i < n; i++) {       long long x = ar[i];       long long y = ar[i + 1];       if (x > y) {         ans += y * (x - y);       }       if (x < y) {         ans += (y - x) * (n - y + 1);       }     }     cout << ans;   }


#include <iostream>   #include <vector>   #include <algorithm>   #include <math.h>      using namespace std;      #define fi first   #define se second   #define all(x) x.begin(), x.end()   #define sz(x) x.size()   #define pb push_back   #define mk make_pair   #define tests int t; cin >> t; while(t--)   #define forn(i, a, b) for (int i = a; i < b; i++)      typedef long long ll;   typedef long double ld;      const int Z = (int)1e5 + 123;   const int inf = (int)2e9 + 123;   const ll llinf = (ll)9e18 + 123;      int main() {       tests {           int n;           cin >> n;           ll a = 0, b = n % 10;           bool flag = false;           while ((b * 2021) + (a * 2020) <= n) {               if ((n - (b * 2021)) % 2020 > 0) {                   b += 10;                   continue;               } else {                   flag = true;                   break;               }           }           cout << (flag ?  YES n  :  NO n );       }       return 0;   }