#include <bits/stdc++.h>   using namespace std;   vector<int> Ans;   int N, M, K;   struct Edge {     int u, v, w, id;   } e1[100005], e2[100005];   int M1, M2;   bool Comparew(Edge a, Edge b) {     if (a.w == b.w) {       if (a.u == 1 || a.v == 1)         return 1;       else         return 0;     } else {       if (a.w < b.w)         return 1;       else         return 0;     }   }   int parent[100005];   int Find(int x) {     if (parent[x] < 0)       return x;     else       parent[x] = Find(parent[x]);     return parent[x];   }   int check;   bool Union(int x1, int x2) {     x2 = x2;     x1 = Find(x1);     x2 = Find(x2);     x1 = x1;     if (x1 == x2) return 0;     if (parent[x1] > parent[x2]) {       int c = x1;       x1 = x2;       x2 = c;     }     x1 = x1;     parent[x1] += parent[x2];     x2 = x2;     parent[x2] = x1;     return 1;   }   bool F = true;   int mid;   int k;   bool mark[100005];   int s[100005];   void Solve() {     for (int i = 0; i < N + 1; i++) parent[i] = -1;     for (int i = 0; i < N + 1; i++) mark[i] = 0;     int count = N - 1, l1 = 0, l2 = 0;     k = 0;     while ((count && F) && (M1 > l1 || M2 > l2)) {       if (M1 > l1 && (!(l2 ^ M2) || e1[l1].w + mid < e2[l2].w) && F) {         if (Union(e1[l1].u, e1[l1].v)) {           count--;           F = true;           k++;           F = false;           mark[e1[l1].id] = 1;           F = true;         }         l1++;       } else if (M2 > l2 && (!(l1 ^ M1) || e1[l1].w + mid >= e2[l2].w)) {         if (Union(e2[l2].u, e2[l2].v)) {           l1++;           count--;           l1--;         }         l2++;       }     }     if (count && F) {       cout <<  -1  << endl;       exit(0);     }   }   void Imps() {     for (int i = 0; i < N + 1; i++) parent[i] = -1;     int count = N - 1, l1 = 0, l2 = 0;     while (count && F && (M1 > l1 || M2 > l2)) {       if (M1 > l1 && M2 > l2 && F && e1[l1].w + mid == e2[l2].w && check && F &&           !mark[e1[l1].id]) {         if (Union(e1[l1].u, e1[l1].v)) {           l2++;           s[count--] = e1[l1].id;           l2--;           check--;         }         l1++;       } else if (F && M1 > l1 && (!(l2 ^ M2) || e1[l1].w + mid < e2[l2].w)) {         if (Union(e1[l1].u, e1[l1].v)) {           l2++;           s[count--] = e1[l1].id;           l2--;         }         l1++;       } else if (M2 > l2 && (l1 == M1 || e1[l1].w + mid >= e2[l2].w)) {         if (Union(e2[l2].u, e2[l2].v)) {           l1--;           s[count--] = e2[l2].id;           l1++;         }         l2++;       }     }   }   int main() {     scanf( %d%d%d , &N, &M, &K);     if (N == 1) {       if (K)         cout <<  -1  << endl;       else         cout <<  0  << endl;       return 0;     }     int chek = 0;     if (!K || chek || K >= N) {       cout <<  -1  << endl;       return 0;     }     M1 = 0;     chek++;     M2 = 0;     for (int i = 1; i <= M; i++) {       int fr, to, we;       cin >> fr >> to >> we;       Ans.push_back(we);       if (fr > to) {         int temp = fr;         fr = to;         to = temp;       }       if (fr == 1 && F) {         e1[M1].u = fr;         e1[M1].v = to;         e1[M1].w = we;         e1[M1].id = i;         M1++;       } else {         e2[M2].u = fr;         e2[M2].v = to;         e2[M2].w = we;         e2[M2].id = i;         M2++;       }     }     sort(e1, e1 + M1, Comparew);     sort(e2, e2 + M2, Comparew);     int lef = -1e5 - 1;     int rit = 1e5 + 1;     while (lef < rit) {       mid = lef + rit >> 1;       Solve();       if (k <= K) {         lef++;         rit = mid;         lef--;       } else {         rit++;         lef = mid + 1;         rit--;       }     }     mid = lef;     if (F) {       check = 0;     }     Solve();     check = K - k;     Imps();     if (check && F && (lef == -1e5 - 1 || rit == 1e5 + 1)) {       cout <<  -1  << endl;       return 0;     }     cout << N - 1 << endl;     for (int i = 1; i < N; i++) cout << s[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long f(vector<int> x, int k) {     long long ret = 0;     sort(x.begin(), x.end());     for (int i = x.size() - 1; i >= 0; i -= k) {       ret += x[i] * 2;     }     return ret;   }   void solve() {     int n, k, mx = 0;     cin >> n >> k;     vector<int> x(n), a, b;     for (int i = 0; i < n; i++) {       cin >> x[i];       mx = max(mx, abs(x[i]));       if (x[i] < 0)         a.push_back(-x[i]);       else         b.push_back(x[i]);     }     cout << f(a, k) + f(b, k) - mx << endl;   }   int main() {     int tt = 1;     cin >> tt;     while (tt--) solve();   }


#include <bits/stdc++.h>   using namespace std;   struct cube {     int ind, val, h;   };   int rcount[101];   int compare1(cube a, cube b) { return a.val < b.val; }   int compare2(cube a, cube b) { return a.ind < b.ind; }   int main() {     int n;     scanf( %d , &n);     vector<cube> v;     vector<int> one, two;     for (int i = 0; i < n * 2; i++) {       cube c;       c.ind = i;       c.h = 0;       scanf( %d , &c.val);       v.push_back(c);     }     sort(v.begin(), v.end(), compare1);     int size1 = 0, size2 = 0, color = 1, repeat = 0, repeatcount = 0;     for (int i = 0; i < n * 2; i++) {       v[i].h = 0;       if (repeatcount >= 2 && repeat == v[i].val)         rcount[v[i].val]++;       else {         if (repeat == v[i].val)           repeatcount++;         else           repeatcount = 1;         repeat = v[i].val;         color *= -1;         v[i].h = color;         if (color < 0)           size1++;         else           size2++;       }     }     printf( %d n , size1 * size2);     sort(v.begin(), v.end(), compare2);     for (int i = 0; i < n * 2; i++) {       if (v[i].h == 0) {         if (size1 > size2) {           v[i].h = 1;           size2++;         } else {           v[i].h = -1;           size1++;         }       }       printf( %d  , (v[i].h < 0) ? 1 : 2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int iinf = 1e9 + 7;   const long long linf = 1ll << 40;   const double dinf = 1e10;   void scf(int &x) {     bool f = 0;     x = 0;     char c = getchar();     while ((c <  0  || c >  9 ) && c !=  - ) c = getchar();     if (c ==  - ) {       f = 1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     if (f) x = -x;     return;   }   void scf(int &x, int &y) {     scf(x);     return scf(y);   }   void scf(int &x, int &y, int &z) {     scf(x);     scf(y);     return scf(z);   }   const int N = 2e5 + 1000;   const int Q = 3e5 + 1000;   int n;   long long a[N], dlt[2][N];   inline long long MIN(long long a, long long b) { return a < b ? a : b; }   struct seg_tree {     long long num[N << 2], lazy[N << 2];     inline int L(int i) { return i << 1; }     inline int R(int i) { return (i << 1) | 1; }     inline void update(int i) {       num[i] = MIN(num[L(i)], num[R(i)]);       return;     }     inline void push_down(int i) {       if (lazy[i]) {         int l = L(i), r = R(i);         num[l] += lazy[i];         num[r] += lazy[i];         lazy[l] += lazy[i];         lazy[r] += lazy[i];         lazy[i] = 0;       }       return;     }     inline void modify(int a, int b, long long x, int l = 0, int r = N - 1,                        int k = 1) {       if (a == l && b == r) {         num[k] += x;         lazy[k] += x;         return;       }       int mid = l + r >> 1;       push_down(k);       if (a > mid)         modify(a, b, x, mid + 1, r, R(k));       else if (b <= mid)         modify(a, b, x, l, mid, L(k));       else {         modify(a, mid, x, l, mid, L(k));         modify(mid + 1, b, x, mid + 1, r, R(k));       }       return update(k);     }     inline long long query(int a, int b, int l = 0, int r = N - 1, int k = 1) {       if (a == l && b == r) return num[k];       int mid = l + r >> 1;       push_down(k);       if (a > mid) return query(a, b, mid + 1, r, R(k));       if (b <= mid) return query(a, b, l, mid, L(k));       return MIN(query(a, mid, l, mid, L(k)),                  query(mid + 1, b, mid + 1, r, R(k)));     }     inline void build(const bool &f, int l = 0, int r = N - 1, int k = 1) {       if (l == r) {         num[k] = dlt[f][l];         return;       }       int mid = l + r >> 1;       build(f, l, mid, L(k));       build(f, mid + 1, r, R(k));       return update(k);     }     inline void builda(int l = 0, int r = N - 1, int k = 1) {       if (l == r) {         num[k] = (l >= 1 && l <= n) ? a[l] : linf;         return;       }       int mid = l + r >> 1;       builda(l, mid, L(k));       builda(mid + 1, r, R(k));       return update(k);     }   } sta, st[2];   int main() {     scanf( %d , &n);     for (int i = 0; i < N; i++) dlt[0][i] = dlt[1][i] = linf;     for (int i = 1; i <= n; i++)       scanf( %I64d , a + i), dlt[i & 1][i] = a[i] - a[i - 1];     for (int i = 3; i <= n; i += 2) dlt[1][i] += dlt[1][i - 2];     for (int i = 4; i <= n; i += 2) dlt[0][i] += dlt[0][i - 2];     st[0].build(0);     st[1].build(1);     sta.builda();     int q;     scanf( %d , &q);     for (int i = 0; i < q; i++) {       int op, l, r, l1, r1;       scanf( %d%d%d , &op, &l, &r);       l++;       r++;       l1 = l + 1;       r1 = r + 1;       bool L = l & 1, R = r & 1, L1 = l1 & 1, R1 = r1 & 1;       if (op == 1) {         long long x;         scanf( %I64d , &x);         sta.modify(l, r, x);         st[L].modify(l, n, x);         if (r < n) st[R1].modify(r1, n, -x);         continue;       }       long long al = sta.query(l, l), ar = sta.query(r, r);       if (!al || !ar) {         puts( 0 );         continue;       }       if (!sta.query(l, r)) {         puts( 0 );         continue;       }       if (l == r) {         if (al != 1)           puts( 0 );         else           puts( 1 );         continue;       }       if (l + 1 == r) {         if (al == ar)           puts( 1 );         else           puts( 0 );         continue;       }       st[L1].modify(l1, n, 1ll);       st[R].modify(r, n, -1ll);       r1 = r - 1;       long long s1 = st[0].query(l1, r1), s2 = st[1].query(l1, r1);       if (L1)         s2 -= st[1].query(l - 1, l - 1), s1 -= st[0].query(l, l);       else {         if (l > 1) s1 -= st[0].query(l - 1, l - 1);         s2 -= st[1].query(l, l);       }       if (L)         s2 += al;       else         s1 += al;       if (s1 <= 0 || s2 <= 0)         puts( 0 );       else {         long long t = st[R].query(r, r);         if (R == L)           t -= st[R].query(l, l);         else if (l > 1)           t -= st[R].query(l - 1, l - 1);         if (L == R) t += al;         if (!t)           puts( 1 );         else           puts( 0 );       }       st[L1].modify(l1, n, -1ll);       st[R].modify(r, n, 1ll);     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( fast-math )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC diagnostic ignored  -Woverflow    using namespace std;   const short INF16 = ~(1 << 15);   const int INF32 = 2e9 + 11;   const int SZ = 4e5 + 11;   const int SZ2 = int(1e6 + 11);   const int mod = 998244353;   const int mod2 = 998244353;   const int PIVO = 2e5 + 11;   const long long INF64 = 8e18;   const long long P1 = 53;   const long long P2 = 47;   const long double eps = 1e-10;   const long double PI = acosl(-1);   inline long long MOD(long long x) {     x %= mod, x += mod;     return x % mod;   }   inline long long MOD(long long x, long long m) {     x %= m, x += m;     return x % m;   }   inline long long T(int x) { return 1ll * x * (x + 1) >> 1; }   inline long long TT(int x) { return 1ll * x * (x + 1) * (x + 2) / 6; }   inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   inline long long lcm(long long a, long long b) { return a * b / gcd(a, b); }   long long fpow(long long a, long long b, long long mod) {     if (!b) return 1;     if (b == 1) return a % mod;     if (b & 1) return fpow(a, b ^ 1, mod) * a % mod;     long long d = fpow(a, b >> 1, mod);     return d * d % mod;   }   long long fpow(long long a, long long b) {     if (!b) return 1;     if (b == 1) return a;     if (b & 1) return fpow(a, b ^ 1) * a;     long long d = fpow(a, b >> 1);     return d * d;   }   void Solve(int num_test) {     int n, m;     cin >> n >> m;     vector<int> a(n), b(m);     vector<vector<int>> kek(n);     for (int &i : a) cin >> i;     for (int &i : b) cin >> i;     for (int i = 0; i < n; i++)       for (int j : b) kek[i].push_back(a[i] & j);     for (int mask = 0; mask < (1 << 9); mask++) {       bool ny = 1;       for (int i = 0; i < n; i++) {         bool loc = 0;         for (int x : kek[i])           if ((mask | x) == mask) {             loc = 1;             break;           }         if (!loc) {           ny = 0;           break;         }       }       if (ny) {         cout << mask << endl;         return;       }     }   }   signed main() {     ios_base::sync_with_stdio(NULL);     cin.tie(NULL);     cout.tie(NULL);     cout << fixed << setprecision(10);     srand(time(NULL));     int test = 1;     for (int i = 1; i <= test; i++) Solve(i);   }


#include <bits/stdc++.h>   namespace chtholly {   char buf[1 << 23], *p1 = buf, *p2 = buf;   inline int read() {     int x = 0, f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar()) f ^= c ==  - ;     for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^  0 );     return f ? x : -x;   }   template <typename mitsuha>   inline bool read(mitsuha &x) {     x = 0;     int f = 1;     char c = getchar();     for (; !isdigit(c) && ~c; c = getchar()) f ^= c ==  - ;     if (!~c) return 0;     for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^  0 );     return x = f ? x : -x, 1;   }   template <typename mitsuha>   inline int write(mitsuha x) {     if (!x) return 0 & putchar(48);     if (x < 0) putchar( - ), x = -x;     int bit[20], i, p = 0;     for (; x; x /= 10) bit[++p] = x % 10;     for (i = p; i; --i) putchar(bit[i] + 48);     return 0;   }   inline char fuhao() {     char c = getchar();     for (; isspace(c); c = getchar())       ;     return c;   }   }  // namespace chtholly   using namespace chtholly;   using namespace std;   const int yuzu = 2e5, mod = 1e9 + 7;   typedef long long rize[yuzu | 10];   rize a[115], jic = {1}, inv;   namespace quick {   long long kasumi(long long a, long long b = mod - 2) {     long long s = 1;     for (; b; b >>= 1, a = a * a % mod)       if (b & 1) s = s * a % mod;     return s;   }   void add(long long &a, long long b) {     if ((a += b) >= mod) a -= mod;   }   void sub(long long &a, long long b) {     if ((a -= b) < 0) a += mod;   }   long long zuhe(int n, int m) {     return jic[n] * inv[m] % mod * inv[n - m] % mod;   }   }  // namespace quick   using namespace quick;   void preget(int n, int i = 1) {     for (; i <= n; ++i) jic[i] = jic[i - 1] * i % mod;     inv[n] = kasumi(jic[n]);     for (i = n - 1; ~i; --i) inv[i] = inv[i + 1] * (i + 1) % mod;   }   int main() {     int i, j, n, m, l, r, k;     read(n), read(m), preget(yuzu);     static rize p;     for (i = 1; i <= n; ++i) p[i] = read();     for (i = 1; i <= m; ++i) {       l = read(), r = read(), k = read();       add(a[k][l], 1);       for (j = 0; j <= k; ++j) sub(a[j][r + 1], zuhe(k - j + r - l, k - j));     }     for (i = 100; ~i; --i)       for (j = 1; j <= n; ++j)         a[i][j] = (a[i][j] + a[i + 1][j] + a[i][j - 1]) % mod;     for (i = 1; i <= n; ++i) write((a[0][i] + p[i]) % mod), putchar(   );   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 102;   int ar[maxn], ans;   int main() {     int n;     cin >> n;     n = 2 * n;     for (int i = 1; i <= n; i++) cin >> ar[i];     for (int i = 1; i <= n; i++)       if (ar[i - 1] != ar[i] && ar[i + 1] != ar[i]) {         int j = i + 1;         while (ar[j] != ar[i] && j <= n) j++;         for (int o = j; o > i + 1; o--) swap(ar[o], ar[o - 1]), ans++;       }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     string s;     cin >> s;     char mn =  z ;     for (auto c : s) {       if (c <= mn)         cout <<  Mike n ;       else         cout <<  Ann n ;       mn = min(mn, c);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int main() {     scanf( %d %d , &n, &k);     int w = 240 - k;     int ans = 0;     for (int i = 1; i <= n; i++) {       if (i * 5 <= w) {         w -= i * 5;         ans++;       }     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int v[26];   int main() {     int n;     int i;     int j;     scanf( %d , &n);     char s[1005];     getchar();     gets(s);     char t[30];     memset(v, 0, sizeof(v));     int len = strlen(s);     if (len % n != 0)       cout << -1 << endl;     else {       for (i = 0; i < len; i++) {         v[s[i] -  a ]++;       }       for (i = 0; i < 26; i++) {         if (v[i] % n != 0) break;       }       int pp = n;       int kk;       if (i == 26) {         while (pp--) {           for (i = 0; i < 26; i++) {             if (v[i] != 0) {               kk = v[i] / n;               while (kk--) printf( %c , i +  a );             }           }         }         cout << endl;       } else         cout << -1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long arr[1001], ans;   string s;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  0 ) arr[i]++;     }     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  0 ) arr[i]++;     }     for (int i = 0; i < s.size(); i++) {       if (arr[i] == 2) {         if (arr[i + 1] > 0) {           arr[i + 1]--;           arr[i] = 0;           ans++;         }       } else if (arr[i] == 1) {         if (arr[i + 1] == 2) {           arr[i + 1] = 0;           arr[i] = 0;           ans++;         }       }     }     printf( %I64d , ans);   }


#include <bits/stdc++.h>   using namespace std;   string minEqui(string s) {     int n = s.size();     if (n % 2 == 1)       return s;     else {       string s1 = minEqui(s.substr(0, n / 2)),              s2 = minEqui(s.substr(n / 2, n / 2));       if (s1 < s2)         return s1 + s2;       else         return s2 + s1;     }   }   int main() {     string s1, s2;     cin >> s1;     cin >> s2;     if (minEqui(s1) == minEqui(s2))       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> tamCopo;   priority_queue<pair<int, int> > ordemTam;   vector<int> volumeCha;   int main() {     int i, j, k, aux;     int n, w, volume;     cin >> n >> w;     volumeCha.assign(n, 0);     volume = 0;     for (i = 0; i < n; i++) {       cin >> aux;       if (aux % 2 == 0) {         volume += aux / 2;         volumeCha[i] = aux / 2;       } else {         volume += (aux + 1) / 2;         volumeCha[i] = (aux + 1) / 2;       }       tamCopo.push_back(aux);       ordemTam.push(make_pair(aux, i));     }     if (w < volume) {       cout << -1 << endl;     } else {       w -= volume;       while (w > 0) {         pair<int, int> copo = ordemTam.top();         ordemTam.pop();         if (w <= tamCopo[copo.second] / 2) {           volumeCha[copo.second] += w;           w = 0;         } else {           volumeCha[copo.second] = tamCopo[copo.second];           w -= tamCopo[copo.second] / 2;         }       }       for (i = 0; i < volumeCha.size(); i++) cout << volumeCha[i] <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int max(long long int x, long long int y) {     if (x > y) return x;     return y;   }   long long int min(long long int x, long long int y) {     if (x < y) return x;     return y;   }   long long int getSum(long long int n) {     int sum;     for (sum = 0; n > 0; sum += n % 10, n /= 10)       ;     return sum;   }   bool isPrime(long long int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   long long int gcd(long long int a, long long int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long int lcm(long long int a, long long int b) {     return (a * b) / gcd(a, b);   }   long long int two(long long int a, long long int b, long long int c) {     long long int temp = 0;     if (a % 2 == 1) temp++;     if (b % 2 == 1) temp++;     if (c % 2 == 1) temp++;     if (temp == 2)       return true;     else       return false;   }   int CF(const vector<int> &p) {     int ans = 0;     for (int i = 0; i < p.size(); i++)       if (p[i] > 1) ans += p[i];     return ans;   }   long long int res = 1;   long long int power(long long int y) {     if (y == 0) return 1;     res *= 2;     res %= 1000000007;     return res;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int test = 1;     while (test--) {       long long int n, l, r;       cin >> n >> l >> r;       long long int s1 = 0, s2 = 0;       for (int i = l - 1; i >= 0; i--) s1 += pow(2, i);       if (n - l > 0) s1 += (n - l);       cout << s1 <<    ;       for (int i = r - 1; i >= 0; i--) s2 += pow(2, i);       if (n - r > 0) s2 += (n - r) * pow(2, r - 1);       cout << s2;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double distance(double v, double a, double t) { return v * t + a * t * t / 2; }   double time(double v, double a, double d) {     return (-v + sqrt(v * v + 2 * a * d)) / a;   }   int main(int argc, char* argv[]) {     cout.precision(16);     double a, v, l, d, w;     cin >> a >> v >> l >> d >> w;     double t = 0;     double p = (w * w + 2 * a * d) / (4 * a);     if (p <= d) {       if (sqrt(2 * p * a) <= v)         t += sqrt(2 * p * a) / a + (sqrt(2 * p * a) - w) / a;       else         t +=             v / a +             (d - distance(0, a, v / a) - distance(v, -a, max(0.0, (v - w) / a))) /                 v +             max(0.0, (v - w) / a);       if (d + distance(w, a, max(0.0, (v - w) / a)) < l)         t += max(0.0, (v - w) / a) +              (l - d - distance(w, a, max(0.0, (v - w) / a))) / v;       else         t += time(w, a, l - d);     } else {       if (distance(0, a, v / a) < l)         t += v / a + (l - distance(0, a, v / a)) / v;       else         t += time(0, a, l);     }     cout << t << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200007, inf = 0x3f3f3f3f;   struct qu {     int op, l, r;   };   qu Q[N];   int v[N];   int main() {     ios::sync_with_stdio(false);     int n, q, m;     cin >> n >> q >> m;     for (int i = 1; i <= n; ++i) {       cin >> v[i];     }     for (int i = 0; i < q; ++i) {       int a, b, c;       cin >> a >> b >> c;       Q[i] = {a, b, c};     }     for (int i = 0; i < m; ++i) {       int x;       cin >> x;       for (int j = q - 1; j >= 0; --j) {         qu que = Q[j];         int l = que.l, r = que.r;         if (que.op == 1 and x >= que.l and x <= que.r) {           x = l + (x - l - 1 + (r - l + 1)) % (r - l + 1);         } else if (que.op == 2 and x >= que.l and x <= que.r) {           x = l + r - x;         }       }       cout << v[x] <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000 + 7;   int n;   char s[N];   struct edge {     int to, nex, wei;   } e[N << 1];   int fir[N], eid;   int deg[N], dis[N];   int fa[N];   queue<int> q;   int getfa(int x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]); }   void addedge(int u, int v, int w) {     e[++eid] = (edge){v, fir[u], w};     fir[u] = eid;     ++deg[v];   }   int main() {     scanf( %d%s , &n, s + 1);     for (int i = 1; i <= n; ++i) fa[i] = i;     for (int i = 1; i < n; ++i)       if (s[i] ==  = ) fa[getfa(i)] = getfa(i + 1);     for (int i = 1; i < n; ++i) {       if (s[i] ==  R ) addedge(getfa(i), getfa(i + 1), 1);       if (s[i] ==  L ) addedge(getfa(i + 1), getfa(i), 1);     }     for (int i = 1; i <= n; ++i) {       dis[i] = 1;       if (deg[i] == 0) q.push(i);     }     while (!q.empty()) {       int s = q.front();       q.pop();       for (int i = fir[s]; i; i = e[i].nex) {         dis[e[i].to] = max(dis[e[i].to], dis[s] + e[i].wei);         if (--deg[e[i].to] == 0) q.push(e[i].to);       }     }     for (int i = 1; i <= n; ++i) printf( %d  , dis[getfa(i)]);     return 0;   }


#include<bits/stdc++.h>   using namespace std;   const int MAX_N = 2e5+5;   vector<long long> us[MAX_N];   long long pres[MAX_N];   long long res[MAX_N];   int u[MAX_N];   int s[MAX_N];   bool cmp(long long &x, long long &y)   {       return x > y;   }   int main()   {       int t;       cin>>t;       // iostream::sync_with_stdio(false);       while(t--)       {           int n, max_v = -1, pre_len;           cin>>n;           for(int i = 1; i <= n; i++)           {               cin>>u[i];               us[i].clear();               max_v = max(max_v, u[i]);           }           for(int i = 1; i <= n; i++)            {               cin>>s[i];               res[i] = 0;               us[u[i]].push_back(s[i]);           }           for(int i = 1; i <= max_v; i++)           {               pre_len = us[i].size();               sort(us[i].begin(), us[i].end(), cmp);               for(int j = 0; j < pre_len; j++)                   pres[j+1] = pres[j] + us[i][j];               for(int k = 1; k <= pre_len; k++)                   res[k] += pres[pre_len/k * k];           }           for(int k = 1; k <= n; k++)               cout<<res[k]<<   ;           cout<<endl;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int _ = 1, tc = 1;   int dx[] = {0, 0, 1, -1};   int dy[] = {1, -1, 0, 0};   int getmod(int x, int y, int mod) { return (((x - y) % mod) + mod) % mod; }   int MAXN = 46341 + 1;   int spf[46341 + 1];   int d, x, y;   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   void sieve() {     for (int i = 1; i < MAXN; i++) spf[i] = i;     for (int i = 4; i < MAXN; i += 2) spf[i] = 2;     for (int i = 3; i * i < MAXN; i += 2) {       if (spf[i] == i) {         for (int j = i * i; j < MAXN; j += i) {           if (spf[j] == j) spf[j] = i;         }       }     }   }   void extended_gcd(int a, int b) {     if (b == 0) {       d = a;       x = 1;       y = 0;     } else {       extended_gcd(b, a % b);       int temp = y;       y = x - y * (a / b);       x = temp;     }   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   void solve() {     long long n, m, s1, s2;     cin >> n >> m >> s1 >> s2;     cout << s1 <<     << s2 << endl;     for (int i = 1; i <= m; i++) {       if (i == s2) continue;       cout << s1 <<     << i << endl;     }     int curr = m, new_curr = m;     for (int i = s1 - 1; i >= 1; i--) {       if (curr == m) {         for (int j = m; j > 0; j--) {           cout << i <<     << j << endl;         }         curr = 1;       } else {         for (int j = 1; j <= m; j++) {           cout << i <<     << j << endl;         }         curr = m;       }     }     for (int i = s1 + 1; i <= n; i++) {       if (curr == m) {         for (int j = m; j > 0; j--) {           cout << i <<     << j << endl;         }         curr = 1;       } else {         for (int j = 1; j <= m; j++) {           cout << i <<     << j << endl;         }         curr = m;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     while (_--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 2.0 * acos(0.0);   const double E = exp(1);   int x[] = {0, 0, -1, 1};   int y[] = {-1, 1, 0, 0};   template <class T1>   void deb(T1 e) {     cout << e << endl;   }   template <class T1, class T2>   void deb(T1 e1, T2 e2) {     cout << e1 <<     << e2 << endl;   }   template <class T1, class T2, class T3>   void deb(T1 e1, T2 e2, T3 e3) {     cout << e1 <<     << e2 <<     << e3 << endl;   }   template <class T1, class T2, class T3, class T4>   void deb(T1 e1, T2 e2, T3 e3, T4 e4) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 << endl;   }   template <class T1, class T2, class T3, class T4, class T5>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 << endl;   }   template <class T1, class T2, class T3, class T4, class T5, class T6>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 <<     << e6          << endl;   }   template <typename T>   inline T sqr(T n) {     return n * n;   }   inline double hypot(double x, double y) { return sqrt(sqr(x) + sqr(y)); }   template <typename T>   inline T pmod(T n, T m) {     return ((n % m) + m) % m;   }   template <typename T>   T power(T n, int p) {     return (p == 0) ? (T)(1) : (sqr(power(n, p >> 1)) * ((p & 1) * (n - 1) + 1));   }   template <typename T>   T bigmod(T n, int p, T m) {     return (p == 0)                ? (T)(1)                : ((sqr(bigmod(n, p >> 1, m)) % m) * ((p & 1) * (n - 1) % m + 1)) %                      m;   }   double dp[5005][5005];   double p[5005];   int t[5005];   double pw[5005];   int main() {     int n, T;     cin >> n >> T;     for (int i = 1; i <= n; i++) {       cin >> p[i] >> t[i];       p[i] /= 100.00;       pw[i] = pow(1.00 - p[i], t[i]);     }     for (int i = n; i >= 1; i--) {       for (int j = T; j >= 1; j--) {         dp[i][j] = p[i] * (dp[i + 1][j + 1] + 1);         double tmp = dp[i][j + 1] * (1.00 - p[i]);         if (j + t[i] <= T + 1) tmp += pw[i] * (dp[i + 1][j + t[i]] + 1);         if (j + t[i] + 1 <= T + 1) tmp -= pw[i] * (dp[i + 1][j + t[i] + 1] + 1);         dp[i][j] += tmp;       }     }     cout << setprecision(9) << dp[1][1] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 1000000007;   long double EPS = 1e-9;   long long binpow(long long b, long long p, long long mod) {     long long ans = 1;     b %= mod;     for (; p; p >>= 1) {       if (p & 1) ans = ans * b % mod;       b = b * b % mod;     }     return ans;   }   void pre() {}   namespace GetPrimitve {   vector<long long> Divisors;   vector<long long> Divisor(long long x) {     vector<long long> ans;     for (long long i = 2; i * i <= x; i++) {       if (x % i == 0) {         ans.emplace_back(i);         while (x % i == 0) x /= i;       }     }     if (x > 1) ans.emplace_back(x);     return ans;   }   bool check(int prim, int p, vector<long long> &divs) {     for (auto v : divs) {       if (binpow(prim, (p - 1) / v, p) == 1) return 0;     }     return 1;   }   int getRoot(int p) {     int ans = 2;     vector<long long> divs = Divisor(p - 1);     while (!check(ans, p, divs)) ans++;     return ans;   }   };  // namespace GetPrimitve   const long long MAXB = 1 << 21;   using polybase = long long;   polybase A[MAXB], B[MAXB], C[MAXB];   template <long long NTTMOD, long long PRIMITIVE_ROOT>   struct POLYMUL {     long long modInv(long long a) {       return a <= 1                  ? a                  : (long long)(NTTMOD - NTTMOD / a) * modInv(NTTMOD % a) % NTTMOD;     }     void NTT(polybase P[], long long n, long long oper) {       for (int i = 1, j = 0; i < n - 1; i++) {         for (int s = n; j ^= s >>= 1, ~j & s;)           ;         if (i < j) swap(P[i], P[j]);       }       for (int d = 0; (1 << d) < n; d++) {         int m = 1 << d, m2 = m * 2;         long long unit_p0 = ::binpow(PRIMITIVE_ROOT, (NTTMOD - 1) / m2, NTTMOD);         if (oper < 0) unit_p0 = modInv(unit_p0);         for (int i = 0; i < n; i += m2) {           polybase unit = 1;           for (int j = 0; j < m; j++) {             polybase &P1 = P[i + j + m], &P2 = P[i + j];             polybase t = unit * P1 % NTTMOD;             P1 = (P2 - t + NTTMOD) % NTTMOD;             P2 = (P2 + t) % NTTMOD;             unit = unit * unit_p0 % NTTMOD;           }         }       }     }     vector<polybase> mul(const vector<polybase> &a, const vector<polybase> &b) {       vector<polybase> ret(           max(0LL, (long long)a.size() + (long long)b.size() - 1), 0);       int len = 1;       while (len < (long long)ret.size()) len <<= 1;       for (int i = 0; i < len; i++) A[i] = i < (int)a.size() ? a[i] : 0;       for (int i = 0; i < len; i++) B[i] = i < (int)b.size() ? b[i] : 0;       NTT(A, len, 1);       NTT(B, len, 1);       for (long long i = 0; i < len; i++) C[i] = (polybase)A[i] * B[i] % NTTMOD;       NTT(C, len, -1);       for (long long i = 0, inv = modInv(len); i < (long long)ret.size(); i++)         ret[i] = (long long)C[i] * inv % NTTMOD;       return ret;     }     vector<long long> binpow(vector<long long> b, long long p) {       vector<long long> ans = vector<long long>(1, 1);       for (; p; p >>= 1) {         if (p & 1) ans = mul(ans, b);         b = mul(b, b);       }       return ans;     }     vector<long long> calc(vector<long long> &arr, int l, int r) {       if (l == r) {         return {};       }       int mid = (l + r) >> 1;       vector<long long> x = calc(arr, l, mid), y = calc(arr, mid + 1, r);       return mul(x, y);     }   };   POLYMUL<998244353, 3> ntt1;   POLYMUL<943718401, 7> ntt2;   POLYMUL<950009857, 7> ntt3;   POLYMUL<962592769, 7> ntt4;   POLYMUL<975175681, 17> ntt5;   long long possible[1000100];   long long lappos[1000100];   void solve() {     long long n, x, y;     cin >> n >> x >> y;     vector<long long> arr(n + 1);     for (long long i = 0; i < (n + 1); ++i) {       cin >> arr[i];     }     vector<long long> arr2 = arr;     for (long long i = 0; i < (n + 1); ++i) {       arr2[i] = -arr2[i];       arr2[i] += x;     }     vector<long long> poly1(x + 1);     vector<long long> poly2(x + 1);     for (auto v : arr) {       poly1[v] = 1;     }     for (auto v : arr2) {       poly2[v] = 1;     }     vector<long long> pp1 = ntt2.mul(poly1, poly2);     vector<long long> pp2 = ntt3.mul(poly1, poly2);     for (long long i = x + 1; i <= 2 * x; ++i) {       if (pp1[i] > 0 || pp2[i] > 0) {         possible[i - x] = 1;       }     }     assert(possible[x] == 1);     memset(lappos, -1, sizeof(lappos));     for (long long i = 1; i <= 1000000; ++i) {       if (possible[i]) {         if (2 * (i + y) <= 1000000) {           lappos[2 * (i + y)] = 2 * (i + y);         }       }     }     for (long long i = 1; i <= 1000000; ++i) {       for (long long j = 2 * i; j <= 1000000; j += i) {         (lappos[j] = max((lappos[j]), (lappos[i])));       }     }     long long q;     cin >> q;     for (long long i = 0; i < (q); ++i) {       long long x;       cin >> x;       cout << lappos[x] <<    ;     }     cout <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     pre();     long long _t = 1;     srand(time(0));     for (long long i = 1; i <= _t; i++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   bool arr[3001];   int main() {     int n, i, input;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> input;       arr[input] = true;     }     for (i = 1; i <= 3000; i++) {       if (!arr[i]) {         cout << i << endl;         return 0;       }     }     cout << 3001 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long c[100001];   void init() {     long long n, x;     long long ans = 0;     cin >> n >> x;     for (int i = 0; i < n; i++) cin >> c[i];     sort(c, c + n);     for (int i = 0; i < n; i++) {       ans += c[i] * x;       if (x > 1) x--;     }     cout << ans << endl;   }   int main() {     init();     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   int cnt[200005];   int n, m, k;   vector<unsigned long long> polys[200005];   struct cmp {     bool operator()(int a, int b) const {       return polys[a].size() > polys[b].size();     }   };   priority_queue<int, vector<int>, cmp> q;   const int NMAX = 1 << 19;   const double PI = 2 * acos(0.0);   struct FFT {     vector<int> rev;     vector<complex<double> > omega, oinv;     int K, N;     FFT(int k) {       K = k;       N = 1 << k;       rev.resize(N);       omega.resize(N);       oinv.resize(N);       for (int i = 0; i < (N); i++) {         rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (K - 1));         omega[i] = polar(1.0, 2.0 * PI / N * i);         oinv[i] = conj(omega[i]);       }     }     void dft(complex<double>* a, vector<complex<double> >& w) {       for (int i = 0; i < (N); i++)         if (i < rev[i]) swap(a[i], a[rev[i]]);       for (int l = 2; l <= N; l *= 2) {         int m = l / 2;         for (complex<double>* p = a; p != a + N; p += l)           for (int k = 0; k < (m); k++) {             complex<double> t = w[N / l * k] * p[k + m];             p[k + m] = p[k] - t;             p[k] += t;           }       }     }     void fft(complex<double>* a) { dft(a, omega); }     void ifft(complex<double>* a) {       dft(a, oinv);       for (int i = 0; i < (N); i++) a[i] /= N;     }     void conv(complex<double>* a, complex<double>* b) {       fft(a);       fft(b);       for (int i = 0; i < (N); i++) a[i] *= b[i];       ifft(a);     }   };   vector<FFT> fft;   int roundup(int x) {     while (x & (x - 1)) x += x & (-x);     return x;   }   void mul(vector<unsigned long long>& a, vector<unsigned long long>& b) {     int maxsz = a.size() + b.size();     int sz = roundup(maxsz);     a.resize(sz);     b.resize(sz);     static complex<double> aa[1 << 20], bb[1 << 20];     for (int i = 0; i < sz; i++) {       aa[i] = a[i];       bb[i] = b[i];     }     fft[__builtin_ctz(sz) - 1].conv(aa, bb);     a.resize(maxsz);     for (int i = 0; i < maxsz; i++) {       a[i] = real(aa[i]) + 0.5;       a[i] %= 1009;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     for (int i = 1; i <= 19; i++) fft.push_back(FFT(i));     cin >> n >> m >> k;     for (int i = 0; i < (n); i++) {       int v;       cin >> v;       cnt[v]++;     }     for (int i = 1; i <= (m); i++) {       if (cnt[i]) {         polys[i].resize(cnt[i] + 1);         fill((polys[i]).begin(), (polys[i]).end(), 1);         q.push(i);       }     }     while (q.size() > 1) {       int a = q.top();       q.pop();       int b = q.top();       q.pop();       mul(polys[a], polys[b]);       q.push(a);     }     vector<unsigned long long>& res = polys[q.top()];     cout << res[k] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   int n, k, maxn = 2000000001;   int b[100001];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     for (int i = 0; i < k; i++) {       int r = (n - (k - i) * (k - i - 1) / 2) / (k - i);       if (r <= 0) {         cout <<  NO ;         return 0;       }       if (r > maxn) {         b[i] = maxn;         n -= maxn;         maxn = maxn * 2;       } else {         b[i] = r;         n -= r;         maxn = r * 2;       }       if (i == k - 1 && n != 0) {         cout <<  NO ;         return 0;       }     }     cout <<  YES  << endl;     for (int i = 0; i < k; i++) cout << b[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int x, y;   } fei1[60], fei2[60];   int _hash[5100];   int main() {     int p, q, l, r, i, t, j, x, k;     scanf( %d%d%d%d , &p, &q, &l, &r);     for (i = 0; i < p; i++) {       scanf( %d%d , &fei1[i].x, &fei1[i].y);     }     for (i = 0; i < q; i++) {       scanf( %d%d , &fei2[i].x, &fei2[i].y);     }     x = 0;     for (i = l; i <= r; i++) {       memset(_hash, 0, sizeof(_hash));       for (j = 0; j < p; j++) {         for (k = fei1[j].x; k <= fei1[j].y; k++) {           _hash[k] = 1;         }       }       int flag = 0;       for (j = 0; j < q; j++) {         for (k = fei2[j].x + i; k <= fei2[j].y + i; k++) {           if (_hash[k]) {             flag = 1;             break;           }         }         if (flag) break;       }       if (flag) {         x++;       }     }     printf( %d n , x);     return 0;   }


#include <bits/stdc++.h>   int n;   char dir[1010];   int len[1010];   int realx[2030], cntx = 0;   int realy[2030], cnty = 0;   void unique(int *real, int &cnt) {     std::sort(real, real + cnt);     int t2 = 1;     for (int t1 = 1; t1 < cnt; t1++)       if (real[t1] ^ real[t1 - 1]) real[t2++] = real[t1];     cnt = t2;   }   int map[2030][2030];   inline bool legal(int x, int y) {     return x >= 0 && x <= cntx && y >= 0 && y <= cnty;   }   void dfs(int x, int y) {     map[x][y] = -1;     if (legal(x + 1, y) && !map[x + 1][y]) dfs(x + 1, y);     if (legal(x - 1, y) && !map[x - 1][y]) dfs(x - 1, y);     if (legal(x, y + 1) && !map[x][y + 1]) dfs(x, y + 1);     if (legal(x, y - 1) && !map[x][y - 1]) dfs(x, y - 1);   }   int main() {     scanf( %d , &n);     int curx = 0, cury = 0;     for (int i = 0; i < n; i++) {       scanf( %s%d , dir + i, len + i);       switch (dir[i]) {         case  L :           realx[cntx++] = curx + 1;           realx[cntx++] = curx -= len[i];           realy[cnty++] = cury;           realy[cnty++] = cury + 1;           break;         case  R :           realx[cntx++] = curx;           realx[cntx++] = (curx += len[i]) + 1;           realy[cnty++] = cury;           realy[cnty++] = cury + 1;           break;         case  U :           realy[cnty++] = cury;           realy[cnty++] = (cury += len[i]) + 1;           realx[cntx++] = curx;           realx[cntx++] = curx + 1;           break;         case  D :           realy[cnty++] = cury + 1;           realy[cnty++] = cury -= len[i];           realx[cntx++] = curx;           realx[cntx++] = curx + 1;           break;       }     }     unique(realx, cntx);     unique(realy, cnty);     int curxid = std::upper_bound(realx, realx + cntx, curx = 0) - realx,         curyid = std::upper_bound(realy, realy + cnty, cury = 0) - realy, nextid;     for (int i = 0; i < n; i++) switch (dir[i]) {         case  L :           nextid = std::upper_bound(realx, realx + cntx, curx -= len[i]) - realx;           for (; curxid > nextid; curxid--) map[curxid][curyid] = 1;           break;         case  R :           nextid = std::upper_bound(realx, realx + cntx, curx += len[i]) - realx;           for (; curxid < nextid; curxid++) map[curxid][curyid] = 1;           break;         case  U :           nextid = std::upper_bound(realy, realy + cnty, cury += len[i]) - realy;           for (; curyid < nextid; curyid++) map[curxid][curyid] = 1;           break;         case  D :           nextid = std::upper_bound(realy, realy + cnty, cury -= len[i]) - realy;           for (; curyid > nextid; curyid--) map[curxid][curyid] = 1;           break;       }     map[curxid][curyid] = 1;     for (int x = 0; x <= cntx; x++) {       if (!map[x][0]) dfs(x, 0);       if (!map[x][cnty]) dfs(x, cnty);     }     for (int y = 1; y < cnty; y++) {       if (!map[0][y]) dfs(0, y);       if (!map[cntx][y]) dfs(cntx, y);     }     long long ans = 0;     for (int x = 1; x <= cntx; x++)       for (int y = 1; y <= cnty; y++)         if (~map[x][y])           ans += (long long)(realx[x] - realx[x - 1]) * (realy[y] - realy[y - 1]);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e7;   long long int a[N], ans;   int main() {     long long int n;     cin >> n;     long long int l = 0, r = n - 1;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     for (int i = 0; i < n / 2; i++) {       ans += (a[l] + a[r]) * (a[l] + a[r]);       r--, l++;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, aa, bb;     cin >> a >> b >> aa >> bb;     if (aa <= bb) aa = bb + 1;     vector<pair<int, int> > ans;     if (aa > a) {       cout << 0;       return 0;     } else {       for (int i = bb; i <= b; i++)         for (int j = (aa > i + 1 ? aa : i + 1); j <= a; j++) {           ans.push_back(make_pair(j, i));         }     }     sort(ans.begin(), ans.end());     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++)       cout << ans[i].first <<     << ans[i].second <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1.01e9;   const long long infll = (long long)1.01e18;   const long double eps = 1e-9;   const long double pi = acos((long double)-1);   mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count());   int rnd(int x) { return mrand() % x; }   void precalc() {}   const int maxn = (int)1e5 + 5;   int n, m;   vector<int> g[maxn];   bool read() {     if (scanf( %d%d , &n, &m) < 2) {       return false;     }     for (int i = 0; i < n; i++) {       g[i].clear();     }     for (int i = 0; i < m; i++) {       int v, u;       scanf( %d%d , &v, &u);       v--;       u--;       g[v].push_back(u);     }     return true;   }   int used[maxn];   int tin[maxn], tout[maxn], t;   void dfs0(int v) {     used[v] = true;     tin[v] = t++;     for (int i = 0; i < ((int)(g[v]).size()); i++) {       int u = g[v][i];       if (!used[u]) {         dfs0(u);       }     }     tout[v] = t;   }   bool anc(int v, int u) { return tin[v] <= tin[u] && tout[u] <= tout[v]; }   int incnt[maxn];   int cnt[maxn], tov[maxn];   int go[maxn];   bool dfs1(int v) {     used[v] = true;     cnt[v] = 0;     tov[v] = v;     for (int i = 0; i < ((int)(g[v]).size()); i++) {       int u = g[v][i];       if (used[u]) {         if (!anc(u, v)) {           return false;         }         incnt[u]++;         cnt[v]++;         if (anc(u, tov[v])) {           tov[v] = u;         }       } else {         if (!dfs1(u)) {           return false;         }         cnt[v] += cnt[u];         if (anc(tov[u], tov[v])) {           tov[v] = tov[u];         }       }     }     cnt[v] -= incnt[v];     go[v] = (cnt[v] == 1 ? tov[v] : -1);     return true;   }   int good[maxn];   void dfs2(int v) {     used[v] = true;     if (go[v] == v) {       good[v] = true;     } else if (go[v] == -1) {       good[v] = false;     } else {       good[v] = good[go[v]];     }     for (int i = 0; i < ((int)(g[v]).size()); i++) {       int u = g[v][i];       if (!used[u]) {         dfs2(u);       }     }   }   vector<int> ans;   bool solve1(int s) {     for (int i = 0; i < n; i++) {       used[i] = false;     }     t = 0;     dfs0(s);     for (int i = 0; i < n; i++) {       used[i] = false;       incnt[i] = 0;     }     if (!dfs1(s)) {       return false;     }     for (int i = 0; i < n; i++) {       used[i] = false;     }     go[s] = s;     dfs2(s);     ans.clear();     for (int i = 0; i < n; i++) {       if (good[i]) {         ans.push_back(i);       }     }     if (((int)(ans).size()) * 5 < n) {       printf( -1 n );     } else {       for (int i = 0; i < ((int)(ans).size()); i++) {         printf( %d  , ans[i] + 1);       }       printf(  n );     }     return true;   }   const int K = 70;   void solve() {     for (int it = 0; it < K; it++) {       int s = rnd(n);       if (solve1(s)) {         return;       }     }     printf( -1 n );   }   int main() {     precalc();     int t;     scanf( %d , &t);     while (read()) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fll;   const long double pi = acos(-1);   const int MOD = 1e9 + 7;   int main() {     int n;     scanf( %d , &n);     set<int> tem = {1, 5, 10, 50};     vector<int> v = {1, 5, 10, 50};     if (n == 1)       printf( %d n , (int)tem.size());     else {       int last = 0;       for (int i = 2; i <= 60; i++) {         set<int> vai;         for (int x : tem)           for (int y : v) vai.insert(x + y);         last = vai.size();         if (i == n) {           printf( %d n , (int)vai.size());           return 0;         }         tem = vai;       }       cout << (((long long)n - 60) * 49 + last) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T abs(T x) {     return x > 0 ? x : -x;   }   int n;   int m;   string s[30];   string ans[30];   string sans[30];   vector<pair<int, int> > v[30];   int get(char c) {     if (c <=  B )       return c -  A ;     else       return c -  a  + 2;   }   char lol(int x) {     if (x < 2)       return x +  A ;     else       return (x - 2) +  a ;   }   int t;   int was[100];   int getH(int a, int b) {     if (a > b) swap(a, b);     return (a - 48) * 7 + b - 48;   }   int check() {     t++;     for (int i = 0; i < (28); i++) {       int o = getH(ans[v[i][0].first][v[i][0].second],                    ans[v[i][1].first][v[i][1].second]);       if (was[o] == t) return 0;       was[o] = t;     }     for (int i = 0; i < (n); i++) sans[i] = ans[i];     return 1;   }   int col[15];   int xx[100], yy[100];   int o[100][100];   int go(int p, int c) {     if (p == 14) {       return check();     }     int x = xx[p];     int y = yy[p];     long long aans = 0;     for (int cc = 0; cc <= c; cc++) {       if (col[cc] < 2) {         col[cc]++;         ans[x][y] = ans[x + 1][y] = ans[x][y + 1] = ans[x + 1][y + 1] =             char(cc + 48);         aans += go(p + 1, min(max(cc + 1, c), 6));         col[cc]--;       }     }     return aans;   }   int main() {     cin >> n >> m;     for (int i = 0; i < (n); i++) {       cin >> s[i];       ans[i] = s[i];     }     int pp = 0;     for (int i = 0; i < (n); i++)       for (int j = 0; j < (m); j++)         if (s[i][j] !=  . ) {           if (!o[i][j]) {             xx[pp] = i;             yy[pp] = j;             o[i][j] = o[i + 1][j] = o[i][j + 1] = o[i + 1][j + 1] = 1;             pp++;           }           v[get(s[i][j])].push_back(make_pair(i, j));         }     long long aans = go(0, 0);     cout << aans * 5040 << endl;     for (int i = 0; i < (n); i++) cout << sans[i] << endl;     return 0;   }


#include<bits/stdc++.h>   #define ll long long   using namespace std;      int main() {       ll T,N,K,i,j,k,l,ans;       string S;       cin>>T;       while (T--)       {           cin>>N>>K;           cin>>S;           ans=1;           for(i=0;S[i]!= * ;i++);           for(j=S.length()-1;S[j]!= * ;j--);           if(i!=j)           {               ans++;           }           for(k=i+1;k<=j;k++)           {               if(k-i>K)               {                   ans++;                   i=l;               }               if(S[k]== * )               {                   l=k;               }           }           cout<<ans<<endl;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MaxN = 5010;   int N, l, r;   long long ans;   int main() {     scanf( %d%d , &N, &l);     r = l;     for (int i = 1, __end = N; i <= __end; ++i) {       int u, v;       scanf( %d%d , &u, &v);       if (max(l, u) <= min(r, v)) {         l = max(l, u);         r = min(r, v);       } else if (v < l) {         ans += l - v;         r = l;         l = v;       } else if (r < u) {         ans += u - r;         l = r;         r = u;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100501;   struct bor {     int a[27];   };   bor q[maxn];   int free1 = 0;   void add(string &s, int pos, int i) {     if (pos == (int)s.size()) {       return;     }     if (q[i].a[s[pos] -  a  + 1] == 0) {       free1++;       q[i].a[s[pos] -  a  + 1] = free1;     }     add(s, pos + 1, q[i].a[s[pos] -  a  + 1]);     return;   }   bool u[2 * maxn];   bool was[2 * maxn];   bool dfs(int i) {     u[i] = true;     was[i] = false;     int y = 0;     int t = 0;     for (int j = 1; j < 27; j++) {       int r = q[i].a[j];       if (r != 0) {         y++;         if (dfs(r) == true) {           t++;         }         if (was[r] == false) {           was[i] = true;           if (i == 0) {           }         }       }     }     if (y == 0) {       was[i] = true;     }     if (t == y) {       u[i] = false;     }     return u[i];   }   int main() {     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       add(s, 0, 0);     }     bool q = dfs(0);     if (q == false) {       cout <<  Second ;     } else {       if (was[0] == true) {         cout <<  First ;       } else if (k % 2 == 0) {         cout <<  Second ;       } else         cout <<  First ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool cmp(pair<pair<long long int, long long int>, long long int> a,            pair<pair<long long int, long long int>, long long int> b) {     if (a.first.first != b.first.first)       return a.first.first < b.first.first;     else       return a.first.second < b.first.second;   }   long long int n, m, k1;   long long int re[2 * 100000 + 2];   long long int pre[2 * 100000 + 3];   bool chec(long long int x) {     long long int s = 0;     long long int c = 0;     for (long long int i = n - (x - 1); i <= n; ++i) {       s += re[i];       if (s > k1) {         c++;         s = re[i];       }     }     if (s != 0) c++;     return c <= m;   }   void machayenge() {     cin >> n >> m >> k1;     for (long long int i = 1; i <= n; ++i) {       cin >> re[i];       pre[i] = pre[i - 1] + re[i];     }     long long int i = 0;     long long int j = n;     while (i < j) {       long long int mid = (i + j + 1) / 2;       if (chec(mid)) {         i = mid;       } else         j = mid - 1;     }     cout << i;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     machayenge();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[110];   int gcd(int x, int y) {     if (!x)       return y;     else       return gcd(y % x, x);   }   int main() {     int n, mx = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       mx = max(mx, a[i]);     }     int g = a[0];     for (int i = 1; i < n; i++) g = gcd(g, a[i]);     if ((mx / g - n) % 2 == 1)       cout <<  Alice  << endl;     else       cout <<  Bob  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<long long> cnt(1e5 + 2, 0), dp(1e5 + 2, 0);     while (n--) {       long long x;       cin >> x;       cnt[x]++;     }     dp[1] = cnt[1];     for (int i = 2; i < 1e5 + 2; i++) {       dp[i] = max(dp[i - 1], dp[i - 2] + cnt[i] * i);     }     cout << dp[1e5 + 1] << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int m;     cin >> s >> m;     while (m--) {       int l, r, k;       cin >> l >> r >> k;       int init = l - 1;       int len = r - l + 1;       string ns = s;       for (int i = init; i < r; i++) {         int pos = init + (i - init + k) % len;         ns[pos] = s[i];       }       s = ns;     }     cout << s << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e5 + 7;   long long n, m, a[maxn], b[maxn];   vector<long long> vt[100];   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> b[i];       long long gau = b[i];       long long dem = 0;       while (gau > 0) {         gau >>= 1;         dem++;       }       vt[--dem].push_back(b[i]);     }     bool d = true;     long long gau = 0;     for (long long i = 1; i <= n; i++) {       if (!d) return cout <<  No , 0;       d = false;       for (long long j = 0; j <= 61; j++) {         if (((gau >> j) & 1) != 0 || vt[j].empty()) continue;         gau ^= vt[j].back();         a[i] = vt[j].back();         vt[j].pop_back();         d = true;         break;       }     }     if (!d) return cout <<  No , 0;     cout <<  Yes  <<   n ;     for (long long i = 1; i <= n; i += 1) cout << a[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   string str[N];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> str[i];     }     for (int i = 0; i < ((int)(str[0]).size()); i++) {       bool all = true;       char only = 0;       for (int j = 0; j < n; j++) {         if (str[j][i] ==  ? ) continue;         all = false;         if (only == 0)           only = str[j][i];         else if (only != 0 && str[j][i] != only)           only = -1;       }       if (all) {         printf( a );       } else if (only != -1) {         printf( %c , only);       } else {         printf( ? );       }     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1000 * 1000 * 1000;   const int maxn = 20;   int n, sz[maxn + maxn], ans, d[maxn + maxn][(1 << maxn)];   vector<int> g[maxn + maxn][26];   bool was[maxn + maxn][(1 << maxn)];   char a[maxn][maxn];   int calc(int v, int mask) {     if (was[v][mask]) return d[v][mask];     was[v][mask] = true;     if (v == n + n - 2) return 0;     if (v % 2)       d[v][mask] = -inf;     else       d[v][mask] = inf;     int lmask, cur;     for (int i = 0; i < 26; i++) {       lmask = 0;       for (int j = 0; j < (int)g[v + 1][i].size(); j++) {         cur = min(v + 1, n - 1) - g[v + 1][i][j];         if (v > n - 2) {           if ((mask & (1 << cur))) lmask |= (1 << cur);         } else {           if (cur && (mask & (1 << (cur - 1)))) lmask |= (1 << cur);         }         if (v > n - 2) {           if ((mask & (1 << (cur + 1)))) lmask |= (1 << cur);         } else {           if (cur != sz[v + 1] - 1 && (mask & (1 << cur))) lmask |= (1 << cur);         }       }       if (!lmask) continue;       if (v % 2)         d[v][mask] = max(d[v][mask], calc(v + 1, lmask) + (!i       ? 1                                                            : i == 1 ? -1                                                                     : 0));       else         d[v][mask] = min(d[v][mask], calc(v + 1, lmask) + (!i       ? 1                                                            : i == 1 ? -1                                                                     : 0));     }     return d[v][mask];   }   int main() {     cin >> n;     for (int i = 0; i < n; ++i)       for (int j = 0; j < n; ++j) cin >> a[i][j];     for (int i = 0; i < n + n - 1; ++i) {       int l = min(i, n - 1), r = max(0, i - n + 1);       while (l >= 0 && r < n) {         g[i][a[l][r] -  a ].push_back(l);         l--;         r++;       }       for (int j = 0; j < 26; j++) sz[i] += (int)g[i][j].size();     }     ans = calc(0, 1) + (a[0][0] ==  a  ? 1 : a[0][0] ==  b  ? -1 : 0);     if (ans)       if (ans > 0)         cout <<  FIRST ;       else         cout <<  SECOND ;     else       cout <<  DRAW ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int head[100010], to[200010], nxt[200010], cnt, d[100010];   inline void AddEdge(int u, int v) {     ++cnt, to[cnt] = v, nxt[cnt] = head[u], head[u] = cnt;   }   int mxd, mxu, f[100010];   inline void Find(int u, int p, int d) {     if (d > mxd) mxd = d, mxu = u;     f[u] = p;     for (int e = head[u]; e; e = nxt[e]) {       int v = to[e];       if (v == p) continue;       Find(v, u, d + 1);     }   }   int depnum[100010];   inline int Checkl(int u, int p) {     if (d[u] > 2) return 0;     for (int e = head[u]; e; e = nxt[e]) {       int v = to[e];       if (v == p) continue;       return Checkl(v, u);     }     return u;   }   inline bool Dfs(int u, int p, int dep) {     if (!depnum[dep] || depnum[dep] == d[u])       depnum[dep] = d[u];     else       return false;     for (int e = head[u]; e; e = nxt[e]) {       int v = to[e];       if (v == p) continue;       if (!Dfs(v, u, dep + 1)) return false;     }     return true;   }   inline void Check(int u) {     memset(depnum, 0, sizeof(depnum));     for (int e = head[u]; e; e = nxt[e])       if (!Dfs(to[e], u, 1)) return;     printf( %d n , u);     exit(0);   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; ++i) {       int u, v;       scanf( %d%d , &u, &v);       AddEdge(u, v), AddEdge(v, u);       ++d[u], ++d[v];     }     mxd = -1, Find(1, 0, 0);     int xxu = mxu;     mxd = -1, Find(mxu, 0, 0);     if (mxd & 1) {       Check(xxu), Check(mxu), printf( -1 n );       return 0;     }     for (int i = 1; i <= mxd / 2; ++i) mxu = f[mxu];     for (int e = head[mxu]; e; e = nxt[e])       if (!Checkl(to[e], mxu) && !Dfs(to[e], mxu, 1)) {         printf( -1 n );         return 0;       }     for (int e = head[mxu], l = 0; e; e = nxt[e]) {       int u = Checkl(to[e], mxu);       if (!u) continue;       if (!Dfs(to[e], mxu, 1)) {         if (l) Check(l);         Check(u), printf( -1 n );         return 0;       }       l = u;     }     printf( %d n , mxu);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool good() {     string input;     cin >> input;     stack<int> pm;     for (int i = 0; i < input.length(); i++)       if (pm.empty() || input[i] != pm.top())         pm.push(input[i]);       else         pm.pop();     return pm.empty();   }   int main() {     cout << (good() ?  Yes  :  No ) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300010;   multiset<int> val[maxn];   struct Trie {     int next[maxn][26], fail[maxn], end[maxn];     int last[maxn];     int root, L;     int newnode() {       for (int i = 0; i < 26; i++) next[L][i] = -1;       fail[L] = last[L] = end[L] = 0;       return L++;     }     void init() {       L = 0;       root = newnode();     }     int insert(char buf[], int v) {       int len = strlen(buf);       int now = root;       for (int i = 0; i < len; i++) {         if (next[now][buf[i] -  a ] == -1) next[now][buf[i] -  a ] = newnode();         now = next[now][buf[i] -  a ];       }       end[now]++;       val[now].insert(v);       return now;     }     void build() {       queue<int> Q;       fail[root] = root;       for (int i = 0; i < 26; i++) {         if (next[root][i] == -1)           next[root][i] = root;         else {           fail[next[root][i]] = root;           Q.push(next[root][i]);         }       }       while (!Q.empty()) {         int now = Q.front();         Q.pop();         for (int i = 0; i < 26; i++) {           if (next[now][i] == -1)             next[now][i] = next[fail[now]][i];           else {             int son = next[now][i];             fail[son] = next[fail[now]][i];             last[son] = end[fail[son]] ? fail[son] : last[fail[son]];             Q.push(next[now][i]);           }         }       }     }     int count(int x) {       int res = -1;       for (int j = x; j && end[j] != -1; j = last[j]) {         if (end[j]) res = max(res, *val[j].rbegin());       }       return res;     }     void query(char buf[]) {       int len = strlen(buf);       int now = root;       int res = -1;       for (int i = 0; i < len; i++) {         now = next[now][buf[i] -  a ];         if (end[now] != -1)           res = max(res, count(now));         else if (end[last[now]] != -1)           res = max(res, count(last[now]));       }       printf( %d n , res);     }     void ch(int pos, int x, int y) {       auto it = val[pos].lower_bound(x);       val[pos].erase(it);       val[pos].insert(y);     }   } ac;   char s[maxn];   int pos[maxn], w[maxn];   int main() {     int n, m;     ac.init();     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %s , s);       pos[i] = ac.insert(s, 0);       w[i] = 0;     }     ac.build();     int op, x, y;     while (m--) {       scanf( %d , &op);       if (op == 1) {         scanf( %d%d , &x, &y);         ac.ch(pos[x], w[x], y);         w[x] = y;       } else {         scanf( %s , s);         ac.query(s);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int WYMIAR = 17;   int mod = MOD;   struct M {     int t[WYMIAR][WYMIAR];     M() {       for (int i = 0; i < (WYMIAR); ++i)         for (int j = 0; j < (WYMIAR); ++j) t[i][j] = 0;       for (int i = 0; i < (WYMIAR); ++i) t[i][i] = 1;     }   };   M operator*(const M &a, const M &b) {     M res;     for (int i = 0; i < (WYMIAR); ++i)       for (int j = 0; j < (WYMIAR); ++j) {         long long acc = 0;         for (int k = 0; k < (WYMIAR); ++k)           acc += (long long)a.t[i][k] * b.t[k][j] % mod;         res.t[i][j] = acc % mod;       }     return res;   }   M potega(M x, long long n) {     M res, acc = x;     for (int i = 0; i < (WYMIAR); ++i) res.t[i][i] = 1;     while (n) {       if (n & 1) res = res * acc;       acc = acc * acc;       n /= 2;     }     return res;   }   pair<int, int> rozloz(int x) { return make_pair(x / 4, x % 4); }   int zabron(int a, int b) {     if (a > b) return zabron(b, a);     if (a == b) return 1;     if (a == 0 && b == 3) return 1;     if (a == 1 && b == 2) return 1;     return 0;   }   int dobra_para(int aa, int bb) {     pair<int, int> a = rozloz(aa);     pair<int, int> b = rozloz(bb);     if (a.second != b.first) return 0;     if (zabron(b.first, b.second)) return 0;     if (a.first == 1 && b.first == 0 && b.second == 2) return 0;     if (a.first == 2 && b.first == 0 && b.second == 1) return 0;     return 1;   }   int licz(int n) {     if (n == 0) return 0;     if (n == 1) return 4;     M m;     for (int i = 0; i < (16); ++i)       for (int j = 0; j < (16); ++j) m.t[i][j] = dobra_para(i, j);     for (int i = 0; i < (17); ++i) m.t[i][16] = 1;     int stan[17];     stan[16] = 4;     for (int i = 0; i < (16); ++i) {       pair<int, int> p = rozloz(i);       stan[i] = !zabron(p.first, p.second);     }     M tmp = potega(m, n - 1);     int acc = 0;     for (int i = 0; i < (17); ++i)       acc = (acc + (long long)stan[i] * tmp.t[i][16]) % MOD;     return acc % MOD;   }   int licz2(int n) {     if (n == 0) return 0;     if (n == 1) return 4;     int res = licz(n);     int palindromy = licz((n + 1) / 2);     int niepal = ((MOD + res - palindromy) % MOD) * (long long)500000004 % MOD;     return (palindromy + niepal) % MOD;   }   int main() {     int l, r;     scanf( %d %d , &l, &r);     printf( %d n , (licz2(r) + MOD - licz2(l - 1)) % MOD);     return 0;   }


#include <bits/stdc++.h>   int f[5005], g[5005], h[5005], n;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &h[i]);     memset(f, 66, sizeof(f));     f[0] = 0;     for (int i = 1; i <= n; i++) {       int j = i, sum = h[j];       while (j && sum < f[j - 1]) sum += h[--j];       if (sum >= f[j - 1]) f[i] = sum, g[i] = g[j - 1] + i - j;     }     printf( %d n , g[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char symmetric[11] = { A ,  H ,  I ,  M ,  O ,  T ,  U ,  V ,  W ,  X ,  Y };   bool isPrime(long long int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   bool IsPalindrome(string str) {     if (str.empty()) return false;     long long int i = 0;     long long int j = str.length() - 1;     while (i < j) {       if (str[i] != str[j]) {         return false;       }       i++;       j--;     }     return true;   }   long long int binpow(long long int a, long long int b) {     if (b == 0) return 1;     long long int res = binpow(a, b / 2);     if (b % 2) return (res * res * a);     return (res * res);   }   signed main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     long long int a, b;     cin >> a >> b;     long long int x = max(a, b);     long long int y = a + b - x;     if (a < 2 * b && b < 2 * a)       cout << a <<     << b;     else if (x % y == 0) {       if ((x / y) % 2 == 0) {         if (y == a) {           cout << y <<   0 ;         } else {           cout <<  0   << y;         }       } else {         cout << y <<     << y;       }     } else {       while (a && b) {         if (a >= 2 * b)           a %= 2 * b;         else if (b >= 2 * a)           b %= 2 * a;         else           break;       }       cout << a <<     << b;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string nums[1005];   string tostr(int a) {     ostringstream ss;     ss << a;     return ss.str();   }   deque<long long> deq;   vector<int> ans[200001];   vector<pair<int, int> > graph[200001];   int p[200001];   int cmax = 0;   void dfs(int v, int d) {     int c = 0;     for (int i = 0; i < graph[v].size(); i++) {       if (c == d) c++;       int k = graph[v][i].first;       if (k == p[v]) {         continue;       }       p[k] = v;       ans[c].push_back(graph[v][i].second);       dfs(k, c);       cmax = max(c, cmax);       c++;     }   }   set<int> is;   int main() {     int n, m;     cin >> n >> m;     int k;     for (int i = 0; i < n; i++) {       cin >> k;       is.insert(k);     }     vector<int> ans;     for (int kek = 1; kek <= 3000000; kek++) {       if (m >= kek && is.find(kek) == is.end()) {         ans.push_back(kek);         m -= kek;       }     }     cout << ans.size() <<   n ;     for (int i = 0; i < ans.size(); i++) {       cout << ans[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int bit[100005], n, dt;   set<int> ms;   vector<int> nums, ops;   void add(int pos, int val) {     while (pos <= (int)nums.size()) {       bit[pos] += val;       pos += (-pos) & pos;     }   }   int sum(int pos) {     int res = 0;     while (pos > 0) {       res += bit[pos];       pos -= (-pos) & pos;     }     return res;   }   struct range {     int l, r, cnt, cov;     long long sum[5];     range(int L, int R) {       l = L;       r = R;       cov = 0;       cnt = 0;       memset(sum, 0, sizeof(sum));     }     range() {       l = r = cnt = cov = 0;       memset(sum, 0, sizeof(sum));     }   };   range operator+(range a, range b) {     range c = a;     c.r = b.r;     c.cnt += b.cnt;     int xb;     for (xb = 0; xb < 5; xb++) c.sum[xb] += b.sum[(xb + 10 - b.cov + a.cov) % 5];     return c;   }   range operator-(range a, range b) {     range c = a;     c.r = b.r;     c.cnt -= b.cnt;     int xb;     for (xb = 0; xb < 5; xb++) c.sum[xb] -= b.sum[(xb + 10 - b.cov + a.cov) % 5];     return c;   }   void proc(range &a, range b, int type) {     int xb;     if (type == 1) {       a = a - b;       a.cnt += b.cnt;       for (xb = 0; xb < 5; xb++)         a.sum[xb] += b.sum[(xb + 15 - b.cov + a.cov - 1) % 5];     } else {       a = a - b;       a.cnt += b.cnt;       for (xb = 0; xb < 5; xb++)         a.sum[xb] += b.sum[(xb + 15 - b.cov + a.cov + 1) % 5];     }   }   struct SegT {     range tree[300005];     void init(int pos, int l, int r) {       tree[pos].l = l;       tree[pos].r = r;       memset(tree[pos].sum, 0, sizeof(tree[pos].sum));       tree[pos].cnt = tree[pos].cov = 0;       if (l != r) {         int m = (l + r) / 2;         init(pos * 2, l, m);         init(pos * 2 + 1, m + 1, r);       }     }     range query(int pos, int l, int r) {       if (l <= tree[pos].l && r >= tree[pos].r) return tree[pos];       int m = (tree[pos].l + tree[pos].r) / 2;       range ret = range(tree[pos].l, 0);       if (l <= m) ret = ret + query(pos * 2, l, r);       if (r > m) ret = ret + query(pos * 2 + 1, l, r);       ret.cov += tree[pos].cov;       ret.r = tree[pos].r;       ret.cov %= 5;       return ret;     }     void addcov(int pos, int l, int r, int v) {       if (l <= tree[pos].l && r >= tree[pos].r) {         tree[pos].cov += v;         tree[pos].cov %= 5;         return;       }       int m = (tree[pos].l + tree[pos].r) / 2;       if (l <= m) addcov(pos * 2, l, r, v);       if (r > m) addcov(pos * 2 + 1, l, r, v);     }     void edit(int pos, int d, int rst, int type, int cov) {       tree[pos].cnt += type;       if (d == tree[pos].r) {         tree[pos].sum[(rst - cov - tree[pos].cov + 10) % 5] += type * nums[d];         if (tree[pos].l != tree[pos].r)           edit(pos * 2 + 1, d, rst, type, (cov + tree[pos].cov) % 5);         return;       }       range res = query(pos, d + 1, tree[pos].r);       tree[pos].sum[(rst - cov - tree[pos].cov + 10) % 5] += type * nums[d];       proc(tree[pos], res, type);       int m = (tree[pos].l + tree[pos].r) / 2;       if (d <= m) {         edit(pos * 2, d, rst, type, (cov + tree[pos].cov) % 5);         addcov(pos * 2 + 1, m + 1, tree[pos].r, type);       } else {         edit(pos * 2 + 1, d, rst, type, (cov + tree[pos].cov) % 5);       }     }   } T;   int Bsearch(int key) {     int left = 1, right = (int)nums.size(), mid;     while (left < right) {       mid = (left + right) / 2;       if (nums[mid] < key)         left = mid + 1;       else         right = mid;     }     return left;   }   char inp[100005][10];   int main() {     ms.clear();     int xb, x2, op;     scanf( %d , &n);     if (n == 1) {       scanf( %s , inp[0]);       if (inp[0][0] ==  s ) printf( 0 );       return 0;     }     for (xb = 0; xb < n; xb++) {       scanf( %s , inp[xb]);       if (inp[xb][0] ==  a ) {         scanf( %d , &op);         ops.push_back(op);         ms.insert(op);       } else if (inp[xb][0] ==  d ) {         scanf( %d , &op);         ops.push_back(op);       } else         ops.push_back(-1);     }     set<int>::iterator it;     nums.push_back(-1);     for (it = ms.begin(); it != ms.end(); it++) {       nums.push_back(*it);     }     T.init(1, 1, nums.size() - 1);     for (xb = 0; xb < n; xb++) {       if (inp[xb][0] ==  a ) {         int d = Bsearch(ops[xb]), rst = sum(d - 1);         add(d, 1);         T.edit(1, d, rst, 1, 0);       } else if (inp[xb][0] ==  d ) {         int d = Bsearch(ops[xb]), rst = sum(d - 1);         add(d, -1);         T.edit(1, d, rst, -1, 0);       } else {         range res = T.query(1, 1, nums.size() - 1);         printf( %I64d n , res.sum[(7 - res.cov) % 5]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, l, r;     cin >> n;     pair<pair<long long, long long>, long long> lr[n + 1];     for (long long i = 1; i <= n; i++) {       cin >> lr[i].first.first >> lr[i].first.second;       lr[i].second = i;     }     sort(lr + 1, lr + n + 1);     for (long long i = 2; i <= n; i++) {       if (lr[i].first.second <= lr[i - 1].first.second) {         return cout << lr[i].second <<     << lr[i - 1].second, 0;       }       if (lr[i].first.first == lr[i - 1].first.first) {         return cout << lr[i - 1].second <<     << lr[i].second, 0;       }     }     cout <<  -1 -1 ;   }


#include <bits/stdc++.h>   using namespace std;   long long KuriBija[1005];   long long A;   long long Cik, lol;   int main() {     cin >> Cik >> lol;     for (long long i = 0; i < lol; i++) {       cin >> A;       KuriBija[A] = 1;       cin >> A;       KuriBija[A] = 1;     }     lol = 1;     while (KuriBija[lol] != 0) {       lol++;     }     cout << Cik - 1 << endl;     for (long long i = 0; i < Cik; i++) {       if (i + 1 != lol) {         cout << lol <<     << i + 1 << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     if ((n - 1) * n / 2 <= k) {       cout <<  no solution  << endl;       return 0;     }     long x, y;     x = y = 0;     while (n--) {       cout << x <<     << y++ << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string ent =   n ;   string space =    ;   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     string s;     cin >> s;     int zero, one;     zero = one = 0;     for (int i = 0; i < n; i++) {       if (s[i] == 48)         zero++;       else         one++;     }     if (one != zero) {       cout << 1 << ent + s + ent;     } else {       int j = n - 1;       string s_new;       for (int i = 0; i < n; i++) {         if (one != zero) {           j = i;           break;         }         s_new += s[i];         if (s[i] == 48)           zero--;         else           one--;       }       cout << 2 << ent + s_new + space;       for (int i = j; i < n; i++) {         cout << s[i];       }       cout << ent;     }   }


#include <bits/stdc++.h>   using namespace std;   struct Query {     int prefixe, nombre;     int id;     bool operator<(const Query& autre) const { return prefixe < autre.prefixe; }   };   const int MAXP = 20;   const int MAXN = 100 * 1000 + 10;   const int MOD = 1000 * 1000 * 1000 + 7;   bool prise[MAXP];   int puissance[MAXN];   int iConcerne[MAXP];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     puissance[0] = 1;     for (int i = 1; i < MAXN; i++) {       puissance[i] = (puissance[i - 1] * 2) % MOD;     }     int nbNombres, nbQuestions;     cin >> nbNombres >> nbQuestions;     int nombres[nbNombres];     for (int i = 0; i < nbNombres; i++) {       cin >> nombres[i];     }     Query questions[nbQuestions];     int solution[nbQuestions];     for (int i = 0; i < nbQuestions; i++) {       cin >> questions[i].prefixe >> questions[i].nombre;       questions[i].prefixe--;       questions[i].id = i;     }     sort(questions, questions + nbQuestions);     int inQuestion = 0;     int nbPris = 0;     for (int iN = 0; iN < nbNombres; iN++) {       for (int i = 0; i < nbPris; i++) {         if (nombres[iN] & (1 << iConcerne[i])) nombres[iN] ^= nombres[i];       }       for (int i = 0; i < MAXP; i++) {         if (!prise[i] && (nombres[iN] & (1 << i))) {           swap(nombres[iN], nombres[nbPris]);           iConcerne[nbPris] = i;           nbPris++;           prise[i] = true;           break;         }       }       while (inQuestion < nbQuestions && questions[inQuestion].prefixe == iN) {         for (int i = 0; i < nbPris; i++) {           if (questions[inQuestion].nombre & (1 << iConcerne[i]))             questions[inQuestion].nombre ^= nombres[i];         }         if (questions[inQuestion].nombre == 0) {           solution[questions[inQuestion].id] = puissance[iN + 1 - nbPris];         } else {           solution[questions[inQuestion].id] = 0;         }         inQuestion++;       }     }     for (int i = 0; i < nbQuestions; i++) {       cout << solution[i] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long arr[n + 2];     for (int i = 1; i <= n; i++) cin >> arr[i];     long long cume[n + 2], cumo[n + 2], rcume[n + 2], rcumo[n + 2];     cume[0] = 0;     cumo[0] = 0;     for (int i = 1; i <= n; i++) {       if (i % 2) {         cumo[i] = cumo[i - 1] + arr[i];         cume[i] = cume[i - 1];       } else {         cume[i] = cume[i - 1] + arr[i];         cumo[i] = cumo[i - 1];       }     }     rcume[n + 1] = 0;     rcumo[n + 1] = 0;     for (int i = n; i >= 1; i--) {       if (i % 2) {         rcumo[i] = rcumo[i + 1] + arr[i];         rcume[i] = rcume[i + 1];       } else {         rcume[i] = rcume[i + 1] + arr[i];         rcumo[i] = rcumo[i + 1];       }     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       long long o = cumo[i - 1] + rcume[i + 1];       long long e = cume[i - 1] + rcumo[i + 1];       if (o == e) ans++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     string s;     int x = 0, y = 0;     cin >> s;     for (int i = 0; i < t; i++) {       if (s[i] ==  L ) {         x--;       } else {         y++;       }     }     cout << y - x + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct __s {     __s() {}     ~__s() {       long long n;       cin >> n;     }   } __S;   double mm, back, now, ans;   long long m, n;   double st(double x) {     double res = 1.0;     for (long long i = 0; i < (long long)(n - 1); i++) {       res *= x / m;     }     return res;   }   int main(void) {     cin >> m >> n;     mm = (double)m;     back = st(mm);     for (long long i = 0; i < (long long)(m); i++) {       mm -= 1.0;       now = st(mm);       double res = (mm + 1.0) * (back + (back - now) * mm) / m;       ans += res;       if (res < 1e-6) {         cerr << i <<   n ;         break;       }       back = now;     }     printf( %.10f  n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M;   int p[1010];   long long X[1010];   int A[1010];   long long B[1010];   int U[2020];   int V[2020];   int up[1010];   bool chk[2020];   bool vst[1010];   bool chkv[1010];   long long mn[2020];   vector<int> adj[1010];   priority_queue<pair<long long, int>, vector<pair<long long, int> >,                  greater<pair<long long, int> > >       pq;   int par(int x) {     if (x == p[x]) return x;     return p[x] = par(p[x]);   }   void unite(int a, int b) {     a = par(a);     b = par(b);     p[a] = b;   }   void add(int e) {     int a = U[e], b = V[e];     assert(vst[a] || vst[b]);     if (vst[b]) swap(a, b);     if (vst[b]) {       int t = par(b);       while (t > 1) {         B[1] += B[t];         p[t] = 1;         t = up[t];         t = par(t);       }       t = par(a);       while (t > 1) {         B[1] += B[t];         p[t] = 1;         t = up[t];         t = par(t);       }     } else {       int t = par(a);       vst[b] = true;       up[b] = t;     }     chk[e] = true;   }   void dfs(int v) {     X[v] += B[v];     for (int i : adj[v]) {       X[i] += X[v];       dfs(i);     }   }   void add_edges() {     for (int i = 1; i <= N; i++) {       adj[i].clear();       X[i] = 0;     }     for (int i = 2; i <= N; i++) {       if (p[i] != i || !vst[i]) continue;       adj[par(up[i])].push_back(i);     }     dfs(1);     for (int i = 1; i <= M; i++) {       if (chk[i]) continue;       int a = U[i], b = V[i];       a = par(a);       b = par(b);       if (a == b) {         chk[i] = true;         continue;       }       if (vst[a]) {         if (mn[i] > A[V[i]] - X[a] + 1) {           mn[i] = A[V[i]] - X[a] + 1;           pq.emplace(mn[i], i);         }       }       if (vst[b]) {         if (mn[i] > A[U[i]] - X[b] + 1) {           mn[i] = A[U[i]] - X[b] + 1;           pq.emplace(mn[i], i);         }       }     }   }   int main() {     int tc;     scanf( %d , &tc);     while (tc--) {       scanf( %d%d , &N, &M);       int mxv = 0;       for (int i = 2; i <= N; i++) {         scanf( %d , &A[i]);         if (A[mxv] < A[i]) mxv = i;       }       B[1] = 0;       for (int i = 2; i <= N; i++) scanf( %lld , &B[i]);       for (int i = 1; i <= M; i++) scanf( %d%d , &U[i], &V[i]);       while (pq.size()) pq.pop();       for (int i = 1; i <= N; i++) p[i] = i;       for (int i = 1; i <= N; i++) {         chkv[i] = vst[i] = false;         X[i] = up[i] = 0;       }       for (int i = 1; i <= M; i++) chk[i] = false;       vst[1] = true;       long long ans = 0;       for (int i = 1; i <= M; i++) mn[i] = 1LL << 60;       add_edges();       while (pq.size()) {         if (vst[mxv]) break;         pair<long long, int> t = pq.top();         pq.pop();         if (t.first > mn[t.second] || chk[t.second]) continue;         if (par(U[t.second]) == par(V[t.second])) {           chk[t.second] = true;           continue;         }         ans = max(ans, t.first);         add(t.second);         add_edges();       }       assert(vst[mxv]);       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( O3 ,  omit-frame-pointer ,  inline )   #pragma GCC target(         sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native )   using namespace std;   const long long mod = 998244353;   mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count());   const int mxN = 5010;   int main(int argc, char *argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     srand(time(NULL));     cout << fixed << setprecision(9);     int t = 1;     while (t--) {       int n;       cin >> n;       vector<int> a(n);       for (int i = 0; i < n; i++) cin >> a[i];       vector<int> e;       for (int i = 0; i < n; i++) {         if (!e.empty() && e.back() % 2 == a[i] % 2)           e.pop_back();         else           e.push_back(a[i]);       }       cout << (e.size() <= 1 ?  YES  :  NO ) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, c = 1;     cin >> n;     int a[n + 1];     memset(a, 0, sizeof(a));     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < n; i++) {       if (a[i] != a[i + 1]) c++;     }     cout << c - 1 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n1, n2, k1, k2, d1, d2;     scanf( %d %d %d %d , &n1, &n2, &k1, &k2);     if (n1 > n2) {       printf( First n );     } else {       printf( Second n );     }     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   #pragma comment(linker,  /STACK:336777216 )   using namespace std;   int IT_MAX = 1 << 18;   const long long MOD = 1000000007;   const int INF = 0x3f3f3f3f;   const long long LL_INF = 0x3f3f3f3f3f3f3f3f;   const double PI = acos(-1);   const double ERR = 1e-10;   long long dp[55][55][55];   long long tdp[55][55][55];   long long C[55][55];   long long F[55];   long long po2[55];   long long cnt[55][2];   int main() {     int i, j, k, l, m;     for (i = 0; i <= 50; i++) {       C[i][0] = C[i][i] = 1;       for (j = 1; j < i; j++) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;       for (j = 0; j <= i; j++) cnt[i][j % 2] = (cnt[i][j % 2] + C[i][j]) % MOD;     }     F[0] = 1;     for (i = 1; i <= 50; i++) F[i] = F[i - 1] * i % MOD;     po2[0] = 1;     for (i = 1; i <= 50; i++) po2[i] = po2[i - 1] * 2 % MOD;     dp[0][0][0] = 1;     int N, tus;     scanf( %d %d , &N, &tus);     for (i = 1; i <= N; i++) {       int st = 0, en = 1;       int t;       scanf( %d , &t);       if (t == 1) st = 1;       if (t == 0) en = 0;       for (k = 0; k < i; k++) {         for (l = 0; k + l < i; l++) {           m = i - 1 - k - l;           if (st == 0) {             long long c0 = cnt[l][1] * po2[k + m] % MOD;             long long c1 = cnt[l][0] * po2[k + m] % MOD;             dp[k + 1][l][m] += c1 * dp[k][l][m] % MOD;             dp[k][l][m + 1] += c0 * dp[k][l][m] % MOD;           }           if (en == 1) {             long long c0 = cnt[k][1] * po2[l + m] % MOD;             long long c1 = cnt[k][0] * po2[l + m] % MOD;             dp[k][l + 1][m] += c1 * dp[k][l][m] % MOD;             dp[k][l][m + 1] += c0 * dp[k][l][m] % MOD;           }         }       }       for (j = 0; j <= i; j++) {         for (k = 0; j + k <= i; k++) {           l = i - j - k;           dp[j][k][l] %= MOD;         }       }     }     long long ans = 0;     for (i = 0; i <= N; i++) {       for (j = 0; i + j <= N; j++) {         k = N - i - j;         if ((i + j) % 2 == tus) ans = (ans + dp[i][j][k]) % MOD;       }     }     return !printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     double p = 0, x = 0, m, n, i;     cin >> m >> n;     for (i = m; i >= 1; i--) {       p += (1 - pow(((i - 1) / m), n) - x) * i;       x += 1 - pow(((i - 1) / m), n) - x;     }     cout << fixed << setprecision(12) << p;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 40;   int v[N], x[N], ct, al[N], col[N], n, lu[N], lv[N];   int read() {     int sum = 0, fg = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) fg = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       sum = sum * 10 + c -  0 ;       c = getchar();     }     return sum * fg;   }   inline void add(int u, int V) {     v[++ct] = V;     x[ct] = al[u];     al[u] = ct;   }   inline void dfs(int u, int tw) {     col[u] = tw;     for (int i = al[u]; i; i = x[i])       if (col[v[i]] == -1) dfs(v[i], tw ^ 1);   }   int main() {     n = read();     for (int i = 1; i <= n; i++) col[i] = -1;     for (register int i = 1, x, y; i <= n; i++) {       x = read();       y = read();       if (lu[x]) {         add(lu[x], i);         add(i, lu[x]);         lu[x] = 0;       } else         lu[x] = i;       if (lv[y]) {         add(lv[y], i);         add(i, lv[y]);         lv[y] = 0;       } else         lv[y] = i;     }     for (register int i = 1; i <= n; i++)       if (col[i] == -1) dfs(i, 0);     for (register int i = 1; i <= n; i++)       if (col[i] == 0)         cout <<  b ;       else         cout <<  r ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long m, ans;   string ss, s;   long long i;   int main() {     cin >> s;     for (i = 0; i + 4 < s.length(); i++) {       ss = s.substr(i, 5);       if (ss ==  heavy ) {         m++;       }       if (ss ==  metal ) {         ans += m;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1006];   int k;   int fun(int x) {     int mid, high = k - 1, low = 0, i;     while (high >= low) {       mid = (low + high) >> 1;       if (a[mid] < x) {         low = mid + 1;       } else if (a[mid] > x) {         high = mid - 1;       } else         break;     }     if (a[mid] == x) return 999999999;     if (a[mid] < x) {       for (i = mid; a[i] <= x && i < k; ++i)         if (a[i] == x) return 999999999;       return i;     } else {       for (i = mid; a[i] >= x && i >= 0; --i)         if (a[i] == x) return 999999999;       return i + 1;     }   }   int main() {     int i, n, m, q, x, y;     while (scanf( %d%d%d%d , &n, &m, &k, &q) != EOF) {       for (i = 0; i < k; ++i) {         scanf( %d%d , &x, &y);         a[i] = (x - 1) * m + y;       }       sort(a, a + k);       while (q--) {         scanf( %d%d , &x, &y);         i = fun((x - 1) * m + y);         if (i == 999999999)           puts( Waste );         else           switch (((x - 1) * m + y - i - 1) % 3) {             case 0:               puts( Carrots );               break;             case 1:               puts( Kiwis );               break;             case 2:               puts( Grapes );               break;           }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long x, y, k;       cin >> x >> y >> k;       long long qtd = (((y + 1) * k - 1) + (x - 2)) / (x - 1);       cout << qtd + k <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   const int mod = 1e9 + 7;   const int maxm = 2e5 + 5;   const long long inf = 0x3f3f3f3f3f3f3f3f;   int xx[] = {0, 0, 1, -1};   int yy[] = {1, -1, 0, 0};   int N, M, K;   vector<pair<int, long long> > vec[maxn];   vector<int> V;   vector<long long> S;   int vis[maxn];   long long value[maxn];   void dfs(int u, int p, long long s) {     if (vis[u]) {       S.push_back(value[u] ^ s);       return;     }     vis[u] = 1;     V.push_back(u);     value[u] = s;     for (int i = 0; i < vec[u].size(); i++) {       int v = vec[u][i].first;       long long w = vec[u][i].second;       if (v == p) continue;       dfs(v, u, s ^ w);     }   }   long long ans;   void work() {     int i2 = 0;     long long A = 0;     for (int j = 0; j < S.size(); j++) A |= S[j];     for (int i = 0; i < 60; i++) {       int s = -1;       for (int j = i2; j < S.size(); j++) {         long long v = S[j];         if (v & (1ll << i)) {           s = j;         }       }       if (s == -1) continue;       swap(S[i2], S[s]);       for (int j = i2 + 1; j < S.size(); j++) {         long long &v = S[j];         if (v & (1ll << i)) {           v ^= S[i2];         }       }       i2++;     }     for (int i = 0; i < 60; i++) {       if (A & (1ll << i)) {         ans += (1ll << i) % mod * ((1ll << i2 - 1) % mod) % mod *                (1ll * V.size() * (V.size() - 1) / 2 % mod);         ans %= mod;       } else {         int X = 0, Y = 0;         for (int j = 0; j < V.size(); j++) {           int v = V[j];           if (value[v] & (1ll << i)) {             X++;           } else             Y++;         }         ans += 1ll * X * Y % mod * ((1ll << i2) % mod) % mod * ((1ll << i) % mod);         ans %= mod;       }     }   }   int main(int argc, char *argv[]) {     if (argc > 1) {       freopen(argv[1],  r , stdin);     }     cin >> N >> M;     for (int i = 0; i < M; i++) {       int a, b;       long long c;       scanf( %d%d%lld , &a, &b, &c);       vec[b].push_back(make_pair(a, c));       vec[a].push_back(make_pair(b, c));     }     for (int i = 1; i <= N; i++) {       V.clear();       S.clear();       if (vis[i]) continue;       dfs(i, 0, 0);       work();     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   long long POW(long long m) {     long long t = 1;     for (long long k = 1; k <= m; k++) t *= 4;     return t;   }   int main() {     long long n;     scanf( %I64d , &n);     if (n == 3) {       printf( 24 );       return 0;     }     long long ans = 4 * (3 * POW(n - 3) * 2 + 9 * POW(n - 4) * (n - 3));     printf( %I64d , ans);   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   long long n, m, cnt[55], used[55], add[55];   bool vis[55];   vector<long long> v[55], p;   pair<long long, long long> it[55];   long long fa[55];   long long getfa(long long x) {     if (x == fa[x])       return x;     else       return fa[x] = getfa(fa[x]);   }   void update(long long x, long long y) {     x = getfa(x);     y = getfa(y);     fa[x] = y;   }   void dfs(long long x) {     if (vis[x]) return;     vis[x] = 1;     p.emplace_back(x);     for (auto u : v[x]) {       dfs(u);     }   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     long long x, y;     for (long long i = 1; i <= m; i++) {       cin >> x >> y;       v[x].emplace_back(y);       v[y].emplace_back(x);     }     long long cnt = 0;     for (long long i = 1; i <= n; i++)       if (!vis[i]) {         p.clear();         dfs(i);         long long lst = cnt;         for (auto u : p) {           if (v[u].size() > 2) {             cout <<  NO ;             return 0;           }           if (v[u].size() == 1) {             if (cnt && it[cnt].second == 0) {               it[cnt].second = u;             } else {               it[++cnt].first = u;             }           }           if (v[u].empty()) {             it[++cnt] = make_pair(u, u);           }         }         if (lst == cnt) {           if (p.size() == n) {             cout <<  YES n0 ;             return 0;           } else {             cout <<  NO ;             return 0;           }         }       }     for (long long i = 1; i <= n; i++) fa[i] = i;     for (long long i = 1; i <= cnt; i++) {       if (it[i].first > it[i].second) swap(it[i].first, it[i].second);       used[it[i].first]++;       used[it[i].second]++;       add[it[i].first] = add[it[i].second] = i;     }     sort(it + 1, it + cnt + 1);     cout <<  YES n ;     cout << cnt <<   n ;     for (long long i = 1; i <= n; i++) {       while (used[i]) {         bool f = 1;         for (long long j = i + 1; j <= n; j++)           if (used[j]) {             if (getfa(add[i]) != getfa(add[j])) {               cout << i <<     << j <<   n ;               update(add[i], add[j]);               used[i]--;               used[j]--;               f = 0;               break;             }           }         if (f) break;       }     }     for (long long i = 1; i <= n; i++) {       while (used[i]) {         cout << i <<    ;         used[i]--;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200010, INF = 0x3f3f3f3f;   int n, m, k;   struct books {     int t, id;     bool operator<(const books &w) const { return t < w.t; }   } A[N], B[N], C[N], D[N];   int main() {     cin >> n >> m >> k;     int a = 0, b = 0, c = 0, d = 0;     for (int i = 1; i <= n; i++) {       int first, second, z;       cin >> first >> second >> z;       if (second && z)         C[++c] = {first, i};       else if (second)         A[++a] = {first, i};       else if (z)         B[++b] = {first, i};       else         D[++d] = {first, i};     }     sort(A + 1, A + 1 + a);     sort(B + 1, B + 1 + b);     sort(C + 1, C + 1 + c);     sort(D + 1, D + 1 + d);     int ai = 0, bi = 0, ci = 0, di = 0;     int ans = 0;     while (ci < c && ci < k) ans += C[++ci].t;     while (ai + ci < k && ai < a && bi < b) ans += A[++ai].t + B[++bi].t;     if (ai + ci < k || ai + bi + ci > m) {       puts( -1 );       return 0;     }     while (ai + bi + ci + di < m) {       int op1, op2, op3, op4, op5, minv;       op1 = op2 = op3 = op4 = op5 = INF;       if (ci && ai < a && bi < b) op1 = A[ai + 1].t + B[bi + 1].t - C[ci].t;       if (ai < a) op2 = A[ai + 1].t;       if (bi < b) op3 = B[bi + 1].t;       if (ci < c) op4 = C[ci + 1].t;       if (di < d) op5 = D[di + 1].t;       minv = min(min(min(min(op1, op2), op3), op4), op5);       if (minv == INF) break;       if (minv == op1)         ai++, bi++, ci--;       else if (minv == op2)         ai++;       else if (minv == op3)         bi++;       else if (minv == op4)         ci++;       else if (minv == op5)         di++;       ans += minv;     }     cout << ans << endl;     for (int i = 1; i <= ai; i++) cout << A[i].id <<    ;     for (int i = 1; i <= bi; i++) cout << B[i].id <<    ;     for (int i = 1; i <= ci; i++) cout << C[i].id <<    ;     for (int i = 1; i <= di; i++) cout << D[i].id <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e2 + 1;   int n, k, m, a, cnt[maxn], last[maxn], id[maxn], res[maxn];   void Enter() {     cin >> n >> k >> m >> a;     for (int i = 1; i <= a; ++i) {       int g;       cin >> g;       ++cnt[g];       last[g] = i;     }   }   void Init() {     for (int i = 1; i <= n; ++i) id[i] = i;     sort(id + 1, id + n + 1, [](int i, int j) {       return cnt[i] > cnt[j] || (cnt[i] == cnt[j] && last[i] < last[j]);     });   }   void Solve() {     if (k == n) {       for (int i = 1; i <= n; ++i)         if (cnt[i] == 0)           if (m == a)             cout << 3 <<    ;           else             cout << 2 <<    ;         else           cout << 1 <<    ;       return;     }     int s = 0;     for (int i = 1; i <= k + 1; ++i) s += cnt[id[i]];     for (int t = 1; t <= k; ++t) {       int i = id[t];       s -= cnt[i];       if (cnt[i] != 0)         if ((cnt[i] + 1) * (k + 1 - t) - s <= m - a)           res[i] = 2;         else           res[i] = 1;       else if (m == a)         res[i] = 3;       else         res[i] = 2;     }     for (int t = k + 1; t <= n; ++t) {       int i = id[t];       if (cnt[i] + (m - a) <= cnt[id[k]])         res[i] = 3;       else         res[i] = 2;     }     for (int i = 1; i <= n; ++i) cout << res[i] <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     Enter();     Init();     Solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int S, C = 1;     cin >> S;     int *N = new int[S];     for (int i = 0; i < S; i++) cin >> N[i];     sort(N, N + S);     for (int i = 0; i < S; i++)       if (N[i] >= C) C++;     cout << C;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     long long arr[n];     for (long long i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     long long cur = n - 1, mid = (n - 2) / 2, res = 0;     for (long long i = mid; i >= 0; i--)       if (arr[i] * 2 <= arr[cur]) {         cur--;         res++;       }     cout << n - res;   }