#include <iostream>   #include <algorithm>   #include <vector>   using namespace std;   typedef vector<int> vi;   int n,a[300010],res[300010],gtm[300010];   vi  L,R,rm;   void solve() {    cin >> n;    for (int i = 0; i < n; i++) cin >> a[i];    L.assign(n,0); R.assign(n,0);    rm.assign(n + 1, 0);    L[0] = 0;     for (int i = 1; i < n; i++) {     if (a[i] > a[i - 1]) L[i] = i;     else {      int j = L[i - 1];      while (j > 0 && a[j - 1] >= a[i]) j = L[j - 1];      L[i] = j;     }    }    R[n - 1] = n - 1;    for (int i = n - 2; i >= 0; i--) {     if (a[i] > a[i + 1]) R[i] = i;     else {      int j = R[i + 1];      while (j < n - 1 && a[j + 1] >= a[i]) j = R[j + 1];      R[i] = j;     }    }    for (int i = 0; i < n; i++) {     int x = R[i] - L[i] + 1;     rm[a[i]] = max(rm[a[i]], x);    }        gtm[1] = rm[1];    for (int i = 2; i <= n; i++) {     gtm[i] = min(gtm[i - 1], rm[i]);    }       for (int i = n; i >= 1; i--) {     int k = n - i + 1;     res[k] = (gtm[i] >= k);    }    for (int i = 1; i <= n; i++) cout << res[i];    cout << endl;   }   int main()   {    int t; cin >> t;    while(t--) solve();   // system( pause );       return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool need[8000010], rem[8000010];   int n, k, b[8000010], sum[8000010], minl = (int)1e9, out;   vector<int> ans;   int main() {     scanf( %d%d , &k, &n);     for (int i = 1; i <= k; i++) scanf( %d , &sum[i]), sum[i] += sum[i - 1];     for (int i = 1; i <= n; i++) scanf( %d , &b[i]), minl = min(b[i], minl);     for (int i = 1; i <= k; i++) ans.push_back(minl - sum[i]);     for (int i = 0; i < ans.size(); i++) {       for (int j = 1; j <= n; j++) need[b[j] + 4000000] = 1;       int x = ans[i], tot = 0;       if (rem[x] == 1) continue;       rem[x] = 1;       for (int j = 1; j <= k; j++) {         tot += need[x + sum[j] + 4000000];         need[x + sum[j] + 4000000] = 0;       }       if (tot == n) out++;     }     cout << out << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed long long int a, b;   long long int a1, b1, y, s;   int main() {     cin >> a >> b >> s;     if (a >= 0)       a1 = a;     else       a1 = 0 - a;     if (b >= 0)       b1 = b;     else       b1 = 0 - b;     y = a1 + b1;     if (y - s == 0 || (y - s) % 2 == 0) {       if (s >= y)         cout <<  Yes ;       else         cout <<  No ;     } else       cout <<  No ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     while (T--) {       int S;       cin >> S;       string str;       cin >> str;       for (int i = 0; i < S; i++) cout << str[S - 1];       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   const int INF = (int)1e9;   const long long LINF = (long long)1e18;   const long double PI = acos((long double)-1);   const long double EPS = 1e-9;   long long gcd(long long a, long long b) {     long long r;     while (b) {       r = a % b;       a = b;       b = r;     }     return a;   }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   long long fpow(long long n, long long k, int p = MOD) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   void addmod(int& a, int val, int p = MOD) {     if ((a = (a + val)) >= p) a -= p;   }   void submod(int& a, int val, int p = MOD) {     if ((a = (a - val)) < 0) a += p;   }   int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }   int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }   int arr[2000005] = {0};   int foo(int n) {     int maxsize = -1, startindex;     int sumleft[n];     int min, max;     int i;     sumleft[0] = ((arr[0] == 0) ? -1 : 1);     min = arr[0];     max = arr[0];     for (i = 1; i < n; i++) {       sumleft[i] = sumleft[i - 1] + ((arr[i] == 0) ? -1 : 1);       if (sumleft[i] < min) min = sumleft[i];       if (sumleft[i] > max) max = sumleft[i];     }     int hash[max - min + 1];     for (i = 0; i < max - min + 1; i++) hash[i] = -1;     for (i = 0; i < n; i++) {       if (sumleft[i] == 0) {         maxsize = i + 1;         startindex = 0;       }       if (hash[sumleft[i] - min] == -1)         hash[sumleft[i] - min] = i;       else {         if ((i - hash[sumleft[i] - min]) > maxsize) {           maxsize = i - hash[sumleft[i] - min];           startindex = hash[sumleft[i] - min] + 1;         }       }     }     if (maxsize == -1) maxsize = 0;     return maxsize;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     string s;     cin >> s;     for (int i = 0; i < n; i++) {       if (s[i] ==  1 ) arr[i] = 1;     }     cout << foo(n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int pow1(long long int a, long long int b,                      long long int m = 1000000007) {     if (b == 0)       return 1ll;     else if (b == 1)       return a;     else {       long long int x = pow1(a, b / 2, m);       x *= x;       x %= m;       if (b % 2) {         x *= a;         x %= m;       }       return x;     }   }   template <class avgType>   avgType avg(avgType a, avgType b) {     return (a + b) / 2;   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());   int randInt() { return rng() % INT_MAX; }   long long int randLL() { return rng64() % LLONG_MAX; }   vector<int> hashmods = {1000000007, 1000000009, 1000000021,                           1000000033, 1000000087, 1000000093};   long long int n, k, a[110000], t;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> t;     while (t--) {       cin >> n >> k;       int pres = 0;       for (int i = 1; i <= n; i++) {         cin >> a[i];         pres += (a[i] == k);       }       if (pres == 0) {         cout <<  no n ;         continue;       }       if (n == 1) {         cout <<  yes n ;         continue;       } else if (n == 2 and a[1] >= k and a[2] >= k) {         cout <<  yes n ;         continue;       }       int yes = 0, less = 0, more = 0, presk = 0;       for (int i = 1; i <= n - 2; i++) {         int m = (a[i] >= k) + (a[i + 1] >= k) + (a[i + 2] >= k);         if (m >= 2) {           yes++;         }       }       cout << (yes ?  yes n  :  no n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ans[1500], t, i, j, v[1100];     memset(v, 0, sizeof(v));     for (i = 2; i * i <= 1100; i++) {       if (v[i] == 0) {         for (j = i + i; j <= 1100; j += i) v[j] = 1;       }     }     while (scanf( %d , &n) != EOF) {       if (n == 1)         printf( 0 n );       else {         t = 0;         for (j = 2; j <= n; j++) {           if (v[j] == 0) {             for (i = j; i <= n; i *= j) {               ans[t] = i;               t++;             }           }         }         printf( %d n , t);         for (i = 0; i < t - 1; i++) printf( %d  , ans[i]);         printf( %d n , ans[t - 1]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int M = 1000000007;   long long int mod(long long int x) { return (x % M + M) % M; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, t, c, ans = 0, g = 0, cnt = 0;     cin >> n >> t >> c;     long long int arr[n];     for (long long int i = 0; i < n; ++i) {       cin >> arr[i];     }     for (long long int i = 0; i < n; i++) {       g++;       if (arr[i] > t) {         g = 0;       } else {         if (g >= c) ans += 1;       }     }     cout << ans << endl;     cerr << fixed << setprecision(10);     cerr <<  time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool upmin(T &x, T y) {     return y < x ? x = y, 1 : 0;   }   template <typename T>   inline bool upmax(T &x, T y) {     return x < y ? x = y, 1 : 0;   }   const long double eps = 1e-11;   const long double pi = acos(-1);   const long long oo = 1 << 30;   const long long loo = 1ll << 62;   const long long mods = 998244353;   const long long MAXN = 200005;   const long long INF = 0x3f3f3f3f;   inline long long read() {     long long f = 1, x = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + (c ^ 48);       c = getchar();     }     return x * f;   }   long long Ans[1005], num = 0;   long long solve(long long x, long long y) {     if (!y) return x;     Ans[++num] = x / y;     long long t = solve(y, x % y);     return t;   }   signed main() {     long long x = read(), y = read();     if (solve(x, y) != 1) {       puts( Impossible );       return 0;     }     Ans[num]--;     for (long long i = 1; i <= num; i++)       if (Ans[i] > 0) printf( %lld , Ans[i]), putchar(66 - (i & 1));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m, i, j, k, d;     cin >> n >> m;     vector<int> arr(101, 0);     for (i = 0; i < m; i++) {       int no;       cin >> no;       arr[no]++;     }     for (d = m; d >= 1; d--) {       vector<int> cc(arr);       int k = 0;       for (i = 0; i < cc.size(); i++) {         if (cc[i] >= d) {           k += (floor(cc[i] / d));         }       }       if (k >= n) {         cout << d << endl;         return 0;       }     }     cout << 0 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   constexpr int N = 5002;   constexpr int mod = 1e9 + 7;   string x, y;   int n, m;   int cache[N][N];   int dp(int a, int b) {     if (b == m) return 0;     int &rv = cache[a][b];     if (~rv) return rv;     rv = dp(a, b + 1);     if (x[a] == y[b]) rv += 1 + dp(a + 1, b + 1), rv %= mod;     return rv;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cin >> x >> y;     n = x.size(), m = y.size();     memset(cache, -1, sizeof cache);     dp(0, 0);     int result = 0;     for (int i = 0; i < n; i++) result += dp(i, 0), result %= mod;     cout << result << endl;   }


#include <bits/stdc++.h>   const int inf = 0x3f3f3f3f, Inf = 0x7fffffff;   const long long INF = 0x7fffffffffffffff;   const double eps = 1e-10;   unsigned int seed = 19260817;   const unsigned int _RAND_MAX_ = 4294967295u;   __inline__ __attribute__((always_inline)) unsigned int Rand() {     return seed = seed * 998244353u + 1000000007u;   }   template <typename _Tp>   _Tp gcd(const _Tp &a, const _Tp &b) {     return (!b) ? a : gcd(b, a % b);   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) _Tp abs(const _Tp &a) {     return a >= 0 ? a : -a;   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) _Tp max(const _Tp &a, const _Tp &b) {     return a < b ? b : a;   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) _Tp min(const _Tp &a, const _Tp &b) {     return a < b ? a : b;   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) void chmax(_Tp &a, const _Tp &b) {     (a < b) && (a = b);   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) void chmin(_Tp &a, const _Tp &b) {     (b < a) && (a = b);   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) bool _cmp(const _Tp &a,                                                       const _Tp &b) {     return abs(a - b) <= eps;   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) void read(_Tp &x) {     register char ch(getchar());     bool f(false);     while (ch < 48 || ch > 57) f |= ch == 45, ch = getchar();     x = ch & 15, ch = getchar();     while (ch >= 48 && ch <= 57)       x = (((x << 2) + x) << 1) + (ch & 15), ch = getchar();     if (f) x = -x;   }   template <typename _Tp, typename... Args>   __inline__ __attribute__((always_inline)) void read(_Tp &t, Args &...args) {     read(t);     read(args...);   }   __inline__ __attribute__((always_inline)) int read_str(char *s) {     register char ch(getchar());     while (ch ==     || ch ==   r  || ch ==   n ) ch = getchar();     register char *tar = s;     *tar = ch, ch = getchar();     while (ch !=     && ch !=   r  && ch !=   n  && ch != EOF)       *(++tar) = ch, ch = getchar();     return tar - s + 1;   }   const int N = 300005;   const int mod = 1000000007;   const long long inv2 = 500000004;   struct matrix {     long long a, b, c, d, e, f;     __inline__ __attribute__((always_inline)) matrix operator*(         const matrix &o) const {       return (matrix){a * o.a % mod,                       (b * o.a + c * o.b) % mod,                       c * o.c % mod,                       (d * o.a + e * o.b + f * o.d) % mod,                       (e * o.c + f * o.e) % mod,                       f * o.f % mod};     }   } I;   __inline__ __attribute__((always_inline)) matrix get1(long long x) {     return (matrix){1ll, x * inv2 % mod, inv2, 0, x * inv2 % mod, 1ll};   }   __inline__ __attribute__((always_inline)) matrix get2(long long x) {     return (matrix){1ll, mod - x, 2ll, (x * x) % mod * inv2 % mod, mod - x, 1ll};   }   int t[N << 1];   int a[N];   int b[N << 1];   struct seg_tr {     struct Node {       int ls, rs;       matrix val;     } f[N << 2];     int node_cnt;     __inline__ __attribute__((always_inline)) void PushUp(int x) {       f[x].val = f[f[x].ls].val * f[f[x].rs].val;     }     int build(int l, int r) {       int cur = ++node_cnt;       if (l == r) {         matrix res(I), a = get1(t[l]);         while (b[l]) res = res * a, --b[l];         f[cur].val = res;         return cur;       }       int mid = (l + r) >> 1;       f[cur].ls = build(l, mid);       f[cur].rs = build(mid + 1, r);       PushUp(cur);       return cur;     }     void Update1(int l, int r, int pos, int cur) {       if (l == r) {         f[cur].val = f[cur].val * get1(t[l]);         return;       }       int mid = (l + r) >> 1;       if (pos <= mid)         Update1(l, mid, pos, f[cur].ls);       else         Update1(mid + 1, r, pos, f[cur].rs);       PushUp(cur);     }     void Update2(int l, int r, int pos, int cur) {       if (l == r) {         f[cur].val = f[cur].val * get2(t[l]);         return;       }       int mid = (l + r) >> 1;       if (pos <= mid)         Update2(l, mid, pos, f[cur].ls);       else         Update2(mid + 1, r, pos, f[cur].rs);       PushUp(cur);     }     __inline__ __attribute__((always_inline)) long long Query() {       return f[1].val.d;     }   } tr;   int Q[N][2];   int main() {     I = (matrix){1ll, 0ll, 1ll, 0ll, 0ll, 1ll};     int n;     read(n);     int pos = 0;     for (int i = 1; i <= n; ++i) {       read(a[i]);       t[++pos] = a[i];     }     int q;     read(q);     for (int i = 1; i <= q; ++i) {       read(Q[i][0], Q[i][1]);       t[++pos] = Q[i][1];     }     std::sort(t + 1, t + pos + 1);     pos = std::unique(t + 1, t + pos + 1) - t - 1;     for (int i = 1; i <= n; ++i) {       a[i] = std::lower_bound(t + 1, t + pos + 1, a[i]) - t;       ++b[a[i]];     }     tr.build(1, pos);     printf( %lld n , tr.Query());     for (int i = 1; i <= q; ++i) {       Q[i][1] = std::lower_bound(t + 1, t + pos + 1, Q[i][1]) - t;       tr.Update2(1, pos, a[Q[i][0]], 1);       tr.Update1(1, pos, Q[i][1], 1);       a[Q[i][0]] = Q[i][1];       printf( %lld n , tr.Query());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct $ {     $() {       ios_base::sync_with_stdio(false);       cin.tie(NULL);     }   } $;   const int Maxn = 202005;   class BIT {     int *tree, sz;       public:     BIT() {       sz = 202005;       tree = new int[sz + 1];     }     BIT(int N) {       sz = N;       tree = new int[N + 1];     }     ~BIT() { delete[] tree; }     void update(int idx, int Val) {       if (idx < 1 || idx > sz) return;       while (idx <= sz) {         tree[idx] += Val;         idx += idx & -idx;       }     }     int read(int idx) {       int Sum = 0;       while (idx > 0) {         Sum += tree[idx];         idx -= (idx & -idx);       }       return Sum;     }     int rangeSum(int l, int r) {       int Ret = read(r) - read(l - 1);       Ret = max(0, Ret);       return Ret;     }     int readSingle(int idx) {       int sum = tree[idx];       if (idx > 0) {         int z = idx - (idx & -idx);         idx--;         while (idx != z) {           sum -= tree[idx];           idx -= (idx & -idx);         }       }       return sum;     }   };   int T1[Maxn], T2[Maxn];   int main() {     int n, k, a, b, q, type, d, val;     cin >> n >> k >> a >> b >> q;     BIT B1, B2;     while (q--) {       cin >> type;       if (type == 1) {         cin >> d >> val;         if (T1[d] < a) {           int temp = min(val, a - T1[d]);           T1[d] += temp;           B1.update(d, temp);         }         if (T2[d] < b) {           int temp = min(val, b - T2[d]);           T2[d] += temp;           B2.update(d, temp);         }       } else {         cin >> d;         int Ans = 0;         Ans = B2.rangeSum(1, d - 1);         int z = B1.rangeSum(min(d + k, Maxn - 1), Maxn - 1);         Ans += z;         cout << Ans << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3fffffff;   const int SINF = 0x7fffffff;   const long long LINF = 0x3fffffffffffffff;   const long long SLINF = 0x7fffffffffffffff;   const int MAXN = 65;   const int MAXB = 10;   const int MAXS = (1 << 10) + 7;   int q;   int b;   long long l, r;   int a[MAXN];   long long dp[MAXB + 3][MAXN][MAXS];   void init();   void input();   void inputq();   void work();   long long getans(long long x);   int main() {     init();     input();     work();   }   void init() {     ios::sync_with_stdio(false);     for (int i = 2; i <= MAXB; ++i) {       int ms = (1 << i);       dp[i][0][0] = 1;       for (int j = 1; j < MAXN; ++j) {         for (int k = 0; k < ms; ++k) {           for (int x = 0; x < i; ++x) {             dp[i][j][k ^ (1 << x)] += dp[i][j - 1][k];           }         }       }     }   }   void input() { scanf( %d , &q); }   void inputq() { scanf( %d%I64d%I64d , &b, &l, &r); }   void work() {     for (int i = 0; i < q; ++i) {       inputq();       printf( %I64d n , getans(r) - getans(l - 1));     }   }   long long getans(long long x) {     if (!x) return 0;     int n = 0;     for (long long t = x; t; t /= b) {       a[n++] = t % b;     }     long long ans = 0;     int beg, ns = 0;     for (int i = n - 1; i >= 0; --i) {       beg = (i == n - 1) ? 1 : 0;       for (int j = beg; j < a[i]; ++j) {         ans += dp[b][i][ns ^ (1 << j)];       }       ns ^= (1 << a[i]);     }     if (!ns) ++ans;     for (int i = n - 2; i >= 0; --i) {       for (int j = 1; j < b; ++j) ans += dp[b][i][1 << j];     }     return ans;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e3 + 7;   const int mod = 1e9 + 7;   map<int, int> mp;   int n, x, ma, ans;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &x);       mp[x]++;     }     for (auto p : mp) {       int x = p.first, y = p.second;       for (int i = 1; i <= 20; i++) {         if ((y >> i) & 1) {           mp[x + i]++;           mp[x] -= (1 << i);         }       }     }     for (auto p : mp) {       int x = p.first, y = p.second;       for (int i = 1; i <= 20; i++) {         if ((y >> i) & 1) {           mp[x + i]++;           mp[x] -= (1 << i);         }       }     }     for (auto p : mp) {       int x = p.first, y = p.second;       ;       if (y != 0) {         ans++;         ma = max(ma, x);       }     }     printf( %d n , ma + 1 - ans);   }


#include<iostream>   #include<cstdio>   #include<fstream>   #include<algorithm>   #include<vector>   #include<map>   #include<set>   #include<queue>   #include<bitset>   #include<cmath>   #include<cstring>   #include<cstdlib>   using namespace std;   typedef long long LL;   typedef double DB;   const int N = 222222;   const int W = 1111111;   int n,m,q,a[N],b[N];   LL sa,sb;   int w=1e6+1,t[W];   LL g[W];   multiset<int> A,B;   multiset<int>::iterator it;   void ad(int x,int y){    int z=x*y;    x++;    while(x<=w){     t[x]+=y;     g[x]+=z;     x+=x&-x;    }   }   void qu(int x,int&y,LL&z){    x++;    while(x){     y+=t[x];     z+=g[x];     x-=x&-x;    }   }   LL ansb(int p){    int o=min(*A.begin(),*B.begin());    if(p<=o)     return sa-(LL)p*n-sb+(LL)p*m;    int x=0;    LL y=0;    qu(p,x,y);    return sa-(LL)o*n-sb+(LL)p*(m-x)+y;   }   LL ansa(int p){    int o=min(*A.begin(),*B.begin());    if(p<=o)     return ansb(p);    return ansb(p)-(p-o);   }   int main()   {    int i,x,y,o;    LL s;    scanf( %d%d%d ,&n,&m,&q);    for(i=1;i<=n;i=i+1){     scanf( %d ,a+i);     sa+=a[i];     A.insert(a[i]);    }    for(i=1;i<=m;i=i+1){     scanf( %d ,b+i);     sb+=b[i];     ad(b[i],1);     B.insert(b[i]);    }    while(q--){     scanf( %d%d ,&i,&x);     if(i<=2){      scanf( %d ,&y);      if(i==1){       A.erase(A.find(a[x]));       sa-=a[x];       A.insert(y);       sa+=y;       a[x]=y;      }      else{       B.erase(B.find(b[x]));       sb-=b[x];       ad(b[x],-1);       B.insert(y);       sb+=y;       ad(y,1);       b[x]=y;      }     }     else{      s=max(ansb(*B.begin()-x),ansb(*B.rbegin()-x));      s=max(s,max(ansa(*A.begin()-x),ansa(*A.rbegin()-x)));      o=min(*A.begin(),*B.begin());      it=A.lower_bound(o+x);      if(it!=A.end())       s=max(s,ansa(*it-x));      if(it!=A.begin()){       it--;       s=max(s,ansa(*it-x));      }      it=A.lower_bound(*B.rbegin()+x);      if(it!=A.end())       s=max(s,ansa(*it-x));      if(it!=A.begin()){       it--;       s=max(s,ansa(*it-x));      }      printf( %lld n ,s);     }    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   const long long N = 200005;   int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};   int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   long long powb(long long a, long long b) {     long long res = 1;     a;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a;       a = a * a;     }     return res;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   void test() {     int n, k;     cin >> n >> k;     vector<int> a(n), b(k), inda(n), vis(n);     set<pair<int, int> > s;     for (int i = 0; i < n; i++) {       cin >> a[i];       a[i]--;       inda[a[i]] = i;       s.insert({i, a[i]});     }     for (int i = 0; i < k; i++) {       cin >> b[i];       b[i]--;       vis[b[i]] = 1;     }     long long ans = 1;     for (int i = 0; i < k; i++) {       int idx = inda[b[i]];       auto pos = s.find({idx, a[idx]});       int inc = 0;       if (pos != s.begin()) {         if (vis[(*(prev(pos))).second] == 0) {           inc++;         }       }       if (next(pos) != s.end()) {         if (vis[(*(next(pos))).second] == 0) inc++;       }       (ans *= 1LL * inc) %= mod;       vis[b[i]] = 0;     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     while (t--) {       test();     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1e7 + 10;   int n, fac[MAX_N], pri[MAX_N], pri_n, fac_cnt[MAX_N], phi[MAX_N];   long long ans;   void init() {     scanf( %d , &n);     for (int i = 2; i <= n; i++) {       if (!fac[i]) {         phi[i] = (fac[i] = pri[++pri_n] = i) - 1;         fac_cnt[i] = 1;       }       for (int j = 1; j <= pri_n && pri[j] * i <= n && pri[j] <= fac[i]; j++) {         fac[pri[j] * i] = pri[j];         fac_cnt[pri[j] * i] = fac_cnt[i] + (pri[j] == fac[i] ? 0 : 1);         phi[pri[j] * i] = phi[i] * (pri[j] - (pri[j] == fac[i] ? 0 : 1));       }     }   }   long long get_pair_suc() {     long long suc = 0;     for (int i = 2; i <= n; i++)       if (i * 2 <= n || fac[i] != i) suc++;     return suc * (suc - 1) / 2;   }   long long get_pair_1() {     long long res = 0;     for (int i = 2; i <= n; i++) res += i - 1 - phi[i];     return res;   }   long long get_pair_2() {     static int pref_fac[MAX_N];     int pref_pri = 0;     long long res = 0;     for (int i = 2; i <= n; i++) {       if (fac[i] == i)         pref_pri++;       else         res += phi[i] - (pref_pri - fac_cnt[i]) - 1;     }     for (int i = 2; i <= n; i++) pref_fac[fac[i]]++;     for (int i = 2; i <= n; i++) pref_fac[i] += pref_fac[i - 1];     for (int i = 2; i <= n; i++) {       if (fac[i] != i) continue;       int lim = n / fac[i];       res += pref_fac[lim];       for (int j = i; j <= n; j += i)         if (fac[j] <= lim) res--;     }     for (int i = 2; i <= n; i++)       if (fac_cnt[i] == 2 && fac[i / fac[i]] == i / fac[i]) res--;     return res;   }   void solve() {     long long pair_suc = get_pair_suc();     long long pair_1 = get_pair_1();     long long pair_2 = get_pair_2();     long long pair_3 = pair_suc - pair_1 - pair_2;     long long ans = pair_1 * 1 + pair_2 * 2 + pair_3 * 3;     printf( %lld n , ans);   }   int main() {     init();     solve();   }


#include <bits/stdc++.h>   using namespace std;   struct ASDF {     ASDF& operator,(int& a) {       scanf( %d , &a);       return *this;     }     ASDF& operator,(long int& a) {       scanf( %ld , &a);       return *this;     }     ASDF& operator,(long long int& a) {       scanf( %lld , &a);       return *this;     }     ASDF& operator,(char& c) {       scanf( %c , &c);       return *this;     }     ASDF& operator,(double& d) {       scanf( %lf , &d);       return *this;     }     template <typename T>     ASDF& operator,(T& a) {       cin >> a;       return *this;     }   } asdf;   template <typename T>   ostream& operator<<(ostream& output, vector<T>& v) {     output <<  [  ;     if (int(v.size())) {       output << v[0];     }     for (int i = 1; i < int(v.size()); i++) {       output <<  ,   << v[i];     }     output <<   ] ;     return output;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& output, pair<T1, T2>& p) {     output <<  (   << p.first <<  ,   << p.second <<   ) ;     return output;   }   int main() {     int n, k;     vector<int> v;     cin >> n >> k;     v.resize(n);     for (int i = 0; i < n; i++) cin >> v[i];     long long sum = 0;     for (int i = 0; i < n; i++) {       if (k > 0 && v[i] < 0) {         v[i] = -v[i];         k--;       }     }     if (k & 1) {       sort(v.begin(), v.end());       v[0] = -v[0];     }     for (int i = 0; i < n; i++) sum += v[i];     cout << sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, k;   long long read() {     long long s = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       s = s * 10 + ch -  0 ;       ch = getchar();     }     return s * f;   }   long long cnt = 0;   struct trie {     long long ch[26];     long long fail;     long long tail;   } t[10010];   long long f(char c) {     if (c ==  A ) return 0;     if (c ==  C ) return 1;     if (c ==  T )       return 2;     else       return 3;   }   void insert(string s) {     long long l = s.size();     long long nw = 0;     for (long long i = 0, iend = l - 1; i <= iend; ++i) {       if (t[nw].ch[f(s[i])] == 0) {         t[nw].ch[f(s[i])] = ++cnt;       }       nw = t[nw].ch[f(s[i])];     }     t[nw].tail = l;   }   void bfs() {     queue<long long> q;     for (long long i = 0, iend = 25; i <= iend; ++i) {       if (t[0].ch[i]) {         t[t[0].ch[i]].fail = 0;         q.push(t[0].ch[i]);       }     }     while (!q.empty()) {       long long nw = q.front();       q.pop();       for (long long i = 0, iend = 25; i <= iend; ++i) {         if (t[nw].ch[i] != 0) {           t[t[nw].ch[i]].fail = t[t[nw].fail].ch[i];           t[t[nw].ch[i]].tail =               max(t[t[nw].ch[i]].tail, t[t[t[nw].ch[i]].fail].tail);           q.push(t[nw].ch[i]);         } else {           t[nw].ch[i] = t[t[nw].fail].ch[i];         }       }     }   }   const long long inf = 1e16;   long long dp[1010][1010][11];   const long long mod = 1e9 + 9;   signed main() {     n = read(), m = read();     long long l = 0;     for (long long i = 1, iend = m; i <= iend; ++i) {       string s;       cin >> s;       long long ss = s.size();       l = max(l, ss);       insert(s);     }     bfs();     dp[0][0][0] = 1;     for (long long i = 0, iend = n - 1; i <= iend; ++i) {       for (long long j = 0, jend = cnt; j <= jend; ++j) {         long long v;         for (long long k = 0, kend = l; k <= kend; ++k) {           v = dp[i][j][k];           if (v) {             for (long long p = 0, pend = 3; p <= pend; ++p) {               long long nw = t[j].ch[p];               if (t[nw].tail > k)                 (dp[i + 1][nw][0] += v) %= mod;               else if (k < l)                 (dp[i + 1][nw][k + 1] += v) %= mod;             }           }         }       }     }     long long ans = 0;     for (long long i = 0, iend = cnt; i <= iend; ++i) {       (ans += dp[n][i][0]) %= mod;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   template <typename S, typename T>   inline bool smin(S &l, T r) {     return r < l ? l = r, 1 : 0;   }   template <typename S, typename T>   inline bool smax(S &l, T r) {     return l < r ? l = r, 1 : 0;   }   constexpr int MOD = 1e9 + 7;   template <typename S>   inline S mod(S &l) {     return l = (l % MOD + MOD) % MOD;   }   template <typename S, typename T>   inline S add(S &l, T r) {     return mod(l += r);   }   void fileIO(string s) {     freopen((s +  .in ).c_str(),  r , stdin);     freopen((s +  .out ).c_str(),  w , stdout);   }   constexpr int N = 1e5 + 10;   constexpr int SQ = 780;   int n, k;   vector<int> vec[N];   int bias, dp[2][SQ], pd[2];   inline void input() {     cin >> n >> k;     for (int i = 0; i < k; i++) {       int x, y;       cin >> x >> y;       vec[y].push_back(n - x + 1);     }   }   inline void faze_0() {     for (int i = 1; i < n + 1; i++) {       sort(vec[i].begin(), vec[i].end());       while (vec[i].size() && vec[i].back() >= SQ - 2) {         bias++;         vec[i].pop_back();       }     }   }   inline void faze_1() {     memset(dp[0], 63, sizeof(dp));     dp[0][0] = 0;     for (int i = 1; i < n + 1; i++) {       int me = i & 1, num = 0;       pd[me] = 1e9;       for (int j = min(n - i + 1, SQ - 2); ~j; j--) {         dp[me][j] = num * 3 + min(dp[me ^ 1][j + 1],                                   pd[me ^ 1] + (j ? 2 : 0) + j * (j + 1) / 2);         smin(pd[me], dp[me][j]);         if (vec[i].size() && vec[i].back() == j) {           num++;           vec[i].pop_back();         }       }     }   }   int main() {     input();     faze_0();     faze_1();     cout << 3 * bias + pd[n & 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       long long a, b, k;       cin >> a >> b >> k;       if (k % 2 == 0)         cout << a * (k / 2) - b * (k / 2) <<   n ;       else         cout << a * (k / 2 + 1) - b * (k / 2) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int cnt[7];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, i, a, x;     bool test = true;     vector<pair<long long int, pair<long long int, long long int>>> v;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a;       cnt[a]++;     }     x = n / 3;     if (cnt[1] + cnt[2] + cnt[3] + cnt[4] + cnt[6] != n) test = false;     if (cnt[1] == x && test) {       for (i = 1; i <= x; i++) {         if (cnt[4] > 0) {           if (cnt[2] > 0) {             v.push_back({1, {2, 4}});             cnt[2]--;             cnt[4]--;           } else {             test = false;             break;           }         } else if (cnt[3] > 0) {           if (cnt[6] > 0) {             v.push_back({1, {3, 6}});             cnt[3]--;             cnt[6]--;           } else {             test = false;             break;           }         } else if (cnt[2] > 0) {           if (cnt[6] > 0) {             v.push_back({1, {2, 6}});             cnt[2]--;             cnt[6]--;           } else {             test = false;             break;           }         }       }     } else       test = false;     if (test && cnt[2] == 0 && cnt[6] == 0 && cnt[3] == 0 && cnt[4] == 0) {       for (i = 0; i < v.size(); i++)         cout << v[i].first <<     << v[i].second.first <<                  << v[i].second.second << endl;     } else       cout <<  -1  << endl;     return 0;   }


/*#pragma GCC target ( avx2 )   #pragma GCC optimization ( O3 )   #pragma GCC optimization ( unroll-loops )   */      #include<bits/stdc++.h>   using namespace std;   void __print(int x) {cerr << x;}   void __print(long x) {cerr << x;}   void __print(long long x) {cerr << x;}   void __print(unsigned x) {cerr << x;}   void __print(unsigned long x) {cerr << x;}   void __print(unsigned long long x) {cerr << x;}   void __print(float x) {cerr << x;}   void __print(double x) {cerr << x;}   void __print(long double x) {cerr << x;}   void __print(char x) {cerr <<      << x <<     ;}   void __print(const char *x) {cerr <<     << x <<    ;}   void __print(const string &x) {cerr <<     << x <<    ;}   void __print(bool x) {cerr << (x ?  true  :  false );}      template<typename T, typename V>   void __print(const pair<T, V> &x) {cerr <<  { ; __print(x.first); cerr <<  , ; __print(x.second); cerr <<  } ;}   template<typename T>   void __print(const T &x) {int f = 0; cerr <<  { ; for (auto &i: x) cerr << (f++ ?  ,  :   ), __print(i); cerr <<  } ;}   void _print() {cerr <<  ] n ;}   template <typename T, typename... V>   void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr <<  ,  ; _print(v...);}   #ifndef ONLINE_JUDGE   #define debug(x...) cerr <<  [  << #x <<  ] = [ ; _print(x)   #else   #define debug(x...)   #endif      #define ll long long   #define f first   #define s second   #define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);   typedef pair<ll , pair<ll, ll> > pi;   int pow(int x,int y){       int res=1;       while(y){           if(y&1) res*=x;           y>>=1;           x*=x;       }       return res;   }      struct Compare {       constexpr bool operator()(pi const & a,                                 pi const & b) const noexcept       { return a.first < b.first || (a.first == b.first && a.second.first > b.second.first); }       };   void prefix_function( string s,ll arr[] )   {        long long border=0; arr[0]=0;       for(long long i=1;i<s.size();i++)       {         while(border>0 && s[i]!=s[border])           border=arr[border-1];                if(s[i]==s[border])            border++;         else          border=0;                  arr[i]=border;       }   }//send mod-2 for a^-1 if mod is a prime number      ll mod=998244353;   ll add( ll a , ll b)   {       return (((a%mod)+(b%mod))%mod);   }   ll mul(ll a,ll b)   {     return (((a%mod)*(b%mod))%mod);   }   ll binpow(ll a, ll b) {       ll res = 1;       while (b) {           if (b & 1) res = mul(res, a);           a = mul(a, a);           b >>= 1;       }       return res;   }   ll subs(ll a,ll b)   {       return (((a%mod)-(b%mod)+mod)%mod);   }   ll dv(ll a,ll b)   {       ll inv=binpow(b,mod-2);       return mul(a,inv);   }      ll dsu_arr[100000];   ll dsu_sz[100000];   void dsu(ll n)   {       for(ll i=0;i<=n;i++)       {           dsu_arr[i]=i;           dsu_sz[i]=1;       }   }   ll find(ll x)   {        ll root=x;       while (root!=dsu_arr[root])       {           root=dsu_arr[root];       }       while(x!=dsu_arr[x])       {           dsu_arr[x]=root;           x=dsu_arr[x];       }       return root;   }   ll merge(ll x,ll y)   {       ll root1=find(x);       ll root2=find(y);              if(root1==root2)       return 0ll;           if(dsu_sz[x]>dsu_sz[y]){       dsu_arr[root2]=root1;       dsu_sz[root1]+=dsu_sz[root2];       }       else       {            dsu_sz[root2]+=dsu_sz[root1];           dsu_arr[root1]=root2;       }       return 1ll;   }   /*   vector<ll>adj[100005];   bool vis[100005];   ll dist[100005];   void bfs(ll c)   {     vis[c]=true;     dist[c]=0;     queue<ll>q;     q.push(c);   while(!q.empty())   {       ll x=q.front();       q.pop();             for(ll i=0;i<adj[x].size();i++)       {           ll y=adj[x][i];           if(!vis[y])           {               vis[y]=true;               dist[y]=dist[x]+1;                              q.push(y);           }       }       }   }   */      int main()   {       Fast    ll test;    cin>>test;    while(test--)    {        ll n;        cin>>n;        vector<ll>sura,mura,dp;        for(ll i=0;i<n;i++)        {            ll  k;            cin>>k;            if(i%2)            sura.push_back(k);            else{            mura.push_back(k);            dp.push_back(0ll);            }           }        ll ans=1000000000000000000,ans2=0;        ll mn=100000000000;        ll sum=0;              for(ll i=0;i<mura.size();i++)        {          sum+=mura[i];          mn=min(mn,mura[i]);          dp[i]=(sum-mn)+(mn*(n-i));        //  cout<<dp[i]<<   ;           }        dp.push_back(100000000000000000);       // cout<<endl;              mn=100000000000;        sum=0;         for(ll i=0;i<sura.size();i++)        {          sum+=sura[i];          mn=min(mn,sura[i]);          ll x=(sum-mn)+(mn*(n-i));               ans=min(ans,min(dp[i],dp[i+1])+x);                    }        cout<<ans<<  n ;                  }         }


#include <bits/stdc++.h>   using namespace std;   long long int n, m;   long long int power(long long int a, long long int b) {     if (b == 0) return 1;     long long int sr = power(a, b >> 1);     long long int r = sr * sr;     if (b & 1) r = a * r;     return r;   }   void solve() {     long long int z = power(2, 0);     cin >> n;     vector<long long int> v(n);     long long int ans = 0;     long long int p = 1;     for (long long int i = 0; i < n; i++) cin >> v[i];     sort(v.begin(), v.end());     long long int count = 0;     for (long long int i = 0; i < n; i++) {       if (v[i] >= z) {         ans += (count * (count - 1) / 2);         while (v[i] >= z) {           z = power(2, p);           p++;         }         count = 0;       }       count++;     }     ans += (count * (count - 1) / 2);     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int x;     cin >> x;     for (long long int i = 1; i <= x; i++) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 5e5 + 5;   long long n, m;   vector<vector<long long> > g(N, vector<long long>());   vector<long long> d(N, 0), last(N, -1);   vector<long long> path;   long long k = 0;   vector<bool> in_path(N, 0);   vector<pair<long long, long long> > pairs;   long long p = 0;   void dfs(long long v, long long l) {     d[v] = l;     if (last[l] != -1) {       pairs.push_back({last[l] + 1, v + 1});       last[l] = -1;       p++;     } else {       last[l] = v;     }     for (auto u : g[v]) {       if (d[u] == 0) {         dfs(u, l + 1);         if (in_path[u]) {           path.push_back(v + 1);           k++;           in_path[v] = 1;         }       }     }     if (d[v] >= (n + 1) / 2 && !in_path[v] && k == 0) {       path.push_back(v + 1);       k++;       in_path[v] = 1;     }   }   void solve() {     cin >> n >> m;     for (long long i = 0; i < m; ++i) {       long long u, v;       cin >> u >> v;       u--;       v--;       g[u].push_back(v);       g[v].push_back(u);     }     dfs(0, 1);     if (k >= (n + 1) / 2) {       cout <<  PATH n ;       cout << k <<   n ;       for (long long i = 0; i < k; ++i) {         cout << path[i] <<    ;       }       cout <<   n ;     } else {       cout <<  PAIRING n ;       cout << p <<   n ;       for (long long i = 0; i < p; ++i) {         cout << pairs[i].first <<     << pairs[i].second <<   n ;       }     }     for (long long i = 0; i <= n; ++i) {       g[i].clear();       d[i] = 0;       last[i] = -1;       in_path[i] = 0;     }     path.clear();     pairs.clear();     k = 0;     p = 0;   }   signed main() {     ios_base::sync_with_stdio(false);     long long t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     char ch = getchar();     int f = 0, x = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) x = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       f = (f << 1) + (f << 3) + ch -  0 ;       ch = getchar();     }     return f * x;   }   int ch[2000005][2], fa[2000005], w[2000005], mark[2000005];   int f[2000005], top, s[2000005], n, k, m;   bool rev[2000005];   bool isroot(int x) { return ch[fa[x]][0] != x && ch[fa[x]][1] != x; }   void pushdown(int x) {     if (rev[x]) {       rev[ch[x][0]] ^= 1;       rev[ch[x][1]] ^= 1;       swap(ch[x][0], ch[x][1]);       rev[x] = 0;     }     if (mark[x]) {       mark[ch[x][0]] = min(mark[ch[x][0]], mark[x]);       mark[ch[x][1]] = min(mark[ch[x][1]], mark[x]);       w[ch[x][0]] = min(w[ch[x][0]], mark[x]);       w[ch[x][1]] = min(w[ch[x][1]], mark[x]);       mark[x] = 2000000000;     }   }   void rotate(int x) {     int y = fa[x], z = fa[y], l, r;     if (ch[y][0] == x)       l = 0;     else       l = 1;     r = l ^ 1;     if (!isroot(y)) {       if (ch[z][0] == y)         ch[z][0] = x;       else         ch[z][1] = x;     }     fa[y] = x;     fa[x] = z;     fa[ch[x][r]] = y;     ch[y][l] = ch[x][r];     ch[x][r] = y;   }   void splay(int x) {     top = 0;     s[++top] = x;     for (int i = x; !isroot(i); i = fa[i]) s[++top] = fa[i];     while (top) pushdown(s[top--]);     while (!isroot(x)) {       int y = fa[x], z = fa[y];       if (!isroot(y)) {         if (ch[z][0] == y ^ ch[y][0] == x)           rotate(x);         else           rotate(y);       }       rotate(x);     }   }   void access(int x) {     for (int t = 0; x; t = x, x = fa[x]) {       splay(x);       ch[x][1] = t;     }   }   void makeroot(int x) {     access(x);     splay(x);     rev[x] ^= 1;   }   void link(int x, int y) {     makeroot(x);     fa[x] = y;   }   int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }   void dfs(int x) {     if (ch[x][0] && !isroot(ch[x][0])) {       mark[ch[x][0]] = min(mark[ch[x][0]], mark[x]);       w[ch[x][0]] = min(w[ch[x][0]], mark[x]);       dfs(ch[x][0]);     }     if (ch[x][1] && !isroot(ch[x][1])) {       mark[ch[x][1]] = min(mark[ch[x][1]], mark[x]);       w[ch[x][1]] = min(w[ch[x][1]], mark[x]);       dfs(ch[x][1]);     }   }   int main() {     memset(w, 0x7f7f7f7f, sizeof(w));     memset(mark, 0x7f7f7f7f, sizeof(mark));     n = read();     k = read();     m = read();     for (int i = 1; i <= n; i++) {       f[i] = i;     }     for (int i = 1; i <= k; i++) {       int u = read(), v = read();       link(u, n + i);       link(n + i, v);       f[find(u)] = find(v);     }     for (int i = 1; i <= m; i++) {       int u = read(), v = read(), w1 = read();       int fu = find(u), fv = find(v);       if (fu == fv) {         makeroot(u);         access(v);         splay(v);         mark[v] = min(mark[v], w1);         w[v] = min(w[v], w1);       } else {         link(u, i + k + n);         link(i + k + n, v);         f[fu] = fv;       }     }     long long ans = 0;     for (int i = 1; i <= n + k + m; i++) {       if (isroot(i)) {         dfs(i);       }     }     for (int i = 1; i <= k; i++) {       if (w[i + n] >= 2000000000) {         puts( -1 );         return 0;       }       ans += w[i + n];     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   bool check(string cards, int a, int b) {     bool isValid = false;     for (int j = 0; j < b && !isValid; j++) {       int shift = 0;       isValid = true;       for (int i = 0; i < a; i++, shift += b) {         if (cards[shift + j] !=  X ) {           isValid = false;           break;         }       }     }     return isValid;   }   int main() {     int t;     vector<string> ways;     cin >> t;     for (int i = 0; i < t; i++) {       string cards;       cin >> cards;       if (check(cards, 1, 12)) ways.push_back( 1x12 );       if (check(cards, 2, 6)) ways.push_back( 2x6 );       if (check(cards, 3, 4)) ways.push_back( 3x4 );       if (check(cards, 4, 3)) ways.push_back( 4x3 );       if (check(cards, 6, 2)) ways.push_back( 6x2 );       if (check(cards, 12, 1)) ways.push_back( 12x1 );       cout << ways.size() <<    ;       vector<string>::iterator itr = ways.begin();       for (; itr != ways.end(); itr++) cout << *itr <<    ;       cout << endl;       ways.clear();     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 1e9 + 9;   const long long inf = 1e18 + 18;   const int max6 = 1e6 + 6;   const int modx = 1e9 + 123;   const int mody = 997;   const int base = 137;   int t[max6];   int n, k;   bool ok(int l, int r) {     int cnt = 0;     for (int i = l; i <= r; ++i) cnt += t[i] == 1;     if (cnt) return false;     int cur = 0;     for (int i = r + 1; i <= n; ++i) {       if (t[i] == 2)         cur++;       else         cur = 0;       if (cur > k) return false;     }     for (int i = 1; i < l; ++i) {       if (t[i] == 2)         cur++;       else         cur = 0;       if (cur > k) return false;     }     return true;   }   int main() {     cin >> n >> k;     string s;     cin >> s;     for (int i = 1; i <= n; ++i)       if (s[i - 1] ==  Y )         t[i] = 1;       else if (s[i - 1] ==  N )         t[i] = 2;       else if (s[i - 1] ==  ? )         t[i] = 3;     int res = 0;     for (int i = 1; i <= n; ++i)       if (i == 1 || t[i - 1] == 1 || t[i - 1] == 3) {         int j = i + k - 1;         if (j == n || t[j + 1] == 1 || t[j + 1] == 3)           if (ok(i, j)) res = 1;       }     cout << (res ?  YES  :  NO );   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void read(T &x) {     x = 0;     char c = getchar();     int f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = x * 10 + c -  0 ;       c = getchar();     }     x *= f;   }   template <class T>   inline void umin(T &x, T y) {     x = x < y ? x : y;   }   template <class T>   inline void umax(T &x, T y) {     x = x > y ? x : y;   }   inline unsigned int R() {     static unsigned int seed = 416;     return seed ^= seed >> 5, seed ^= seed << 17, seed ^= seed >> 13;   }   const int N = 266666;   const double inf = 1e9, eps = 1e-6;   int n, m, fa[N], top[N], dep[N], sz[N], son[N], dfn[N], idfn[N], num;   vector<int> e[N];   double ans = inf, cur;   struct dot {     double x, y;     dot(double X = 0, double Y = 0) {       x = X;       y = Y;     }   };   vector<pair<dot, dot> > mrk[N];   dot a[N], b[N];   int len;   pair<double, int> ev[N];   bool cmp1(pair<double, int> a, pair<double, int> b) {     return a.first != b.first ? a.first < b.first : a.second > b.second;   }   inline double gety(int i) {     return a[i].x == b[i].x                ? a[i].y                : a[i].y + (cur - a[i].x) / (b[i].x - a[i].x) * (b[i].y - a[i].y);   }   struct node {     int u;     bool operator<(const node &a) const {       return gety(u) != gety(a.u) ? gety(u) < gety(a.u) : u < a.u;     }   };   set<node> Set;   dot operator-(dot a, dot b) { return dot(a.x - b.x, a.y - b.y); }   double Cross(dot a, dot b) { return a.x * b.y - a.y * b.x; }   bool isin(dot p, dot a, dot b) {     return p.x >= min(a.x, b.x) - eps && p.x <= max(a.x, b.x) + eps &&            p.y >= min(a.y, b.y) - eps && p.y <= max(a.y, b.y) + eps;   }   double Abs(double x) { return x > 0 ? x : -x; }   bool on_line(dot p, dot a, dot b) { return Abs(Cross(p - a, b - a)) <= eps; }   double getlen(dot a) { return sqrt(a.x * a.x + a.y * a.y); }   void print(int i) {     printf( %lf %lf %lf %lf n , a[i].x, a[i].y, b[i].x, b[i].y);   }   double getans(int i, int j) {     if (i == j) return inf;     if (getlen(b[i] - a[i]) > getlen(b[j] - a[j])) swap(i, j);     if (getlen(b[i] - a[i]) <= eps) {       if (isin(a[i], a[j], b[j]) && on_line(a[i], a[j], b[j])) return a[i].x;       return inf;     }     dot A = a[i], B = b[i], C = a[j], D = b[j], u = B - A, v = D - C;     if (Abs(Cross(u, v)) <= eps) {       if (Abs(gety(i) - gety(j)) <= eps && cur >= A.x - eps && cur <= B.x + eps &&           cur >= C.x - eps && cur <= D.x + eps) {         return cur;       }       return inf;     }     double k = (Cross(D, v) - Cross(A, v)) / Cross(u, v);     dot p(A.x + k * u.x, A.y + k * u.y);     if (isin(p, A, B) && isin(p, C, D) && on_line(p, A, B) && on_line(p, C, D))       return A.x + k * u.x;     return inf;   }   void upd(int i) {     set<node>::iterator it = Set.lower_bound((node){i});     if (it != Set.end()) umin(ans, getans(i, (*it).u));     if (it != Set.begin()) it--, umin(ans, getans(i, (*it).u));   }   void dfs1(int u, int Fa, int Dep) {     fa[u] = Fa;     dep[u] = Dep;     sz[u] = 1;     for (register int i = (0); i <= (((int)e[u].size()) - 1); i++)       if (e[u][i] != Fa) {         dfs1(e[u][i], u, Dep + 1), sz[u] += sz[e[u][i]];         if (sz[e[u][i]] > sz[son[u]]) son[u] = e[u][i];       }   }   void dfs2(int u, int Top) {     top[u] = Top;     dfn[u] = ++num;     idfn[num] = u;     if (son[u]) dfs2(son[u], Top);     for (register int i = (0); i <= (((int)e[u].size()) - 1); i++)       if (e[u][i] != fa[u] && e[u][i] != son[u]) dfs2(e[u][i], e[u][i]);   }   int getlca(int u, int v) {     while (top[u] != top[v]) {       if (dep[top[u]] < dep[top[v]]) swap(u, v);       u = fa[top[u]];     }     return dep[u] < dep[v] ? u : v;   }   int getpath(int u, int v, double t, int xs, double c) {     while (top[u] != top[v]) {       int x = fa[top[u]];       mrk[top[u]].push_back(make_pair(           dot(t, dfn[u]),           dot(t + xs * (dep[u] - dep[x]) / c, dfn[u] - (dep[u] - dep[x]))));       t += xs * (dep[u] - dep[x]) / c;       u = fa[top[u]];     }     return u;   }   int main() {     read(n);     read(m);     for (register int i = (1); i <= (n - 1); i++) {       int u, v;       read(u);       read(v);       e[u].push_back(v);       e[v].push_back(u);     }     dfs1(1, 0, 0);     dfs2(1, 1);     for (register int i = (1); i <= (m); i++) {       int T, C, u, v;       read(T);       read(C);       read(u);       read(v);       double t = T, c = C;       int lca = getlca(u, v);       int ori = u;       v = getpath(v, lca, t + (dep[u] + dep[v] - 2 * dep[lca]) * 1.0 / c, -1, c);       u = getpath(u, lca, t, 1, c);       t += (dep[ori] - dep[u]) * 1.0 / c;       if (dep[u] >= dep[v])         mrk[top[u]].push_back(make_pair(             dot(t, dfn[u]), dot(t + (dep[u] - dep[v]) * 1.0 / c, dfn[v])));       else         mrk[top[u]].push_back(make_pair(             dot(t, dfn[u]), dot(t + (dep[v] - dep[u]) * 1.0 / c, dfn[v])));     }     for (register int t = (1); t <= (n); t++)       if (((int)mrk[t].size())) {         Set.clear();         len = 0;         for (register int i = (0); i <= (((int)mrk[t].size()) - 1); i++)           len++, a[len] = mrk[t][i].first, b[len] = mrk[t][i].second;         for (register int i = (1); i <= (len); i++)           if (a[i].x > b[i].x) swap(a[i], b[i]);         for (register int i = (1); i <= (len); i++)           ev[2 * i - 1] = make_pair(a[i].x, i), ev[2 * i] = make_pair(b[i].x, -i);         sort(ev + 1, ev + len * 2 + 1, cmp1);         for (register int i = (1); i <= (len * 2); i++) {           if ((cur = ev[i].first) >= ans) break;           if (ev[i].second > 0) {             set<node>::iterator it = Set.insert((node){ev[i].second}).first, pre,                                 nxt;             pre = it;             nxt = it;             nxt++;             if (it != Set.begin()) {               pre--;               umin(ans, getans((*pre).u, (*it).u));             }             if (nxt != Set.end()) {               umin(ans, getans((*nxt).u, (*it).u));             }           } else {             set<node>::iterator it = Set.find((node){-ev[i].second}), it1, it2;             it1 = it, it2 = it;             it2++;             if (it != Set.begin() && it2 != Set.end()) {               it1--;               umin(ans, getans((*it1).u, (*it2).u));             }             Set.erase(it);           }         }       }     if (ans < 1e8)       printf( %.9lf n , ans);     else       puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> m;   int main() {     int a, t, n, i, j, k, l, mn = INT_MAX, mx = 0;     cin >> n >> k;     int cnt = 0;     int ans = 0;     for (int i = 0; i < n; i++) {       cin >> a;       mn = min(mn, a);       m[a]++;     }     int p = mn;     while (p < k) {       ans++;       mn = INT_MAX;       for (int i = k - 1; i >= p; i--) {         if (m[i] > 0) m[i]--, m[i + 1]++;         if (m[i] > 0) mn = min(mn, i);         if (m[i + 1] > 0) mn = min(mn, i + 1);       }       p = mn;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long double PI = 3.141592653589793238;   const double EPS = 1e-6;   void solve() {     long long r, g, b, w;     cin >> r >> g >> b >> w;     long long total = r + g + b + w;     long long odd = 0;     odd = r % 2 + g % 2 + b % 2 + w % 2;     long long col = r && g && b;     if (odd <= 1 || odd == 4 || (odd == 3 && col))       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long tc;     cin >> tc;     while (tc--) {       solve();     }     return 0;   }


#include<bits/stdc++.h>   using namespace std;   typedef long long ll;   int main()   {        int t,n,k;    string x= abc ;    cin>>t;    while(t--)    {     cin>>n>>k;     string s,h;     for(int i=0;i<n-k;i++)     {      s+=x[i%3];     }          char c=x[(n-k)%3];          while(k--)     {      s+=c;     }     cout<<s<<endl;    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       string s =   ;       for (int i = 0;; i++) {         bool flag = 1;         for (int j = i * k; j < (i + 1) * k; j++) {           s += ( a  + j - i * k);           if (j == n - 1) {             flag = 0;             break;           }         }         if (flag == 0) break;       }       cout << s << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   void start() {}   void sober() {     long long int n, x = 0, a = 0, b = 0, y = 0, sum = 0, k = 0, m = 0;     cin >> n >> a >> b;     string s;     cin >> s;     a--, b--;     if (s[a] == s[b])       cout <<  0 n ;     else       cout <<  1 n ;   }   signed main() {     start();     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int t = 1;     while (t--) {       sober();     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   int a[maxn];   unordered_map<int, int> b, c;   unordered_map<int, int>::iterator it, it2;   vector<int> ans;   int main() {     ios_base::sync_with_stdio(0);     int n, m, p;     cin >> n >> m >> p;     int x;     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < m; ++i) {       cin >> x;       it = b.find(x);       if (it == b.end())         b.insert(make_pair(x, 1));       else         ++it->second;     }     for (int q = 0; q < p; ++q) {       int cur = 0;       c.clear();       for (int i = q; i < n; i += p) {         if (1ll * i >= 1ll * m * p) {           it = b.find(a[i - m * p]);           if (it != b.end()) {             it2 = c.find(a[i - m * p]);             if (it2->second <= it->second) --cur;             --it2->second;           }         }         it = b.find(a[i]);         if (it == b.end())           continue;         else {           it2 = c.find(a[i]);           if (it2 == c.end()) it2 = c.insert(make_pair(a[i], 0)).first;           if (it2->second < it->second) ++cur;           ++it2->second;         }         if (cur == m) ans.push_back(i - (m - 1) * p + 1);       }     }     sort(ans.begin(), ans.end());     cout << ans.size() <<   n ;     for (int i : ans) cout << i <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k;     cin >> k;     char s[200];     vector<int> __v;     __v.assign(1000000, 127);     cin >> s;     int n;     cin >> n;     set<int> n_del[ z  -  a  + 1];     set<int>::iterator pos_n_del[ z  -  a  + 1];     for (int i = 0; i < n; i++) {       char c;       int nc;       cin >> nc >> c;       set<int>::iterator it = n_del[c -  a ].begin();       if (n_del[c -  a ].empty() || nc <= *it) {         n_del[c -  a ].insert(nc - 1);         continue;       }       nc -= *it;       int pos = 0;       while (it != n_del[c -  a ].end() && nc > 0) {         set<int>::iterator it0 = it;         it++;         if (it != n_del[c -  a ].end()) {           nc -= *it - *it0 - 1;         }       }       if (nc > 0) {         it--;         pos = *it + nc;       } else         pos = *it + nc - 1;       n_del[c -  a ].insert(pos);     }     for (int i = 0; i <  z  -  a  + 1; ++i) {       pos_n_del[i] = n_del[i].begin();     }     int tSums[ z  -  a  + 1] = {0};     for (int i = 0, len = strlen(s), j = 0; i < len * k; ++i, ++j) {       if (j == len) j = 0;       if (pos_n_del[s[j] -  a ] != n_del[s[j] -  a ].end() &&           *pos_n_del[s[j] -  a ] == tSums[s[j] -  a ]) {         pos_n_del[s[j] -  a ]++;       } else         cout << s[j];       tSums[s[j] -  a ]++;     }     cout << endl;     cerr << __v[rand() % __v.size()];   }


#include <bits/stdc++.h>   using namespace std;   const int dx[4] = {0, 1, -1, 0}, dy[4] = {-1, 0, 0, 1};   int n, m;   char g[60][60];   bool col[60][60][2][4];   bool tmp[60][60][2][4];   bool inrange(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }   void solve(int x, int y, int turn, int dir) {     int nx = x + dx[dir], ny = y + dy[dir];     if (inrange(nx, ny) && g[nx][ny] ==  B  && tmp[nx][ny][turn][dir] == false) {       tmp[nx][ny][turn][dir] = tmp[nx][ny][1][dir] = true;       solve(nx, ny, turn, dir);     }     if (turn == 1) return;     for (int i = 0; i < 4; i++) {       if (i == dir) continue;       nx = x + dx[i], ny = y + dy[i];       if (inrange(nx, ny) && g[nx][ny] ==  B  && tmp[nx][ny][1][i] == false) {         tmp[nx][ny][1][i] = true;         solve(nx, ny, 1, i);       }     }     return;   }   bool check() {     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (g[i][j] ==  B ) {           bool ok = false;           for (int x = 0; x < 2 && !ok; x++)             for (int y = 0; y < 4 && !ok; y++)               if (tmp[i][j][x][y]) ok = true;           if (!ok) return false;         }     return true;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> g[i][j];       }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (g[i][j] ==  B ) {           memset(tmp, false, sizeof(tmp));           for (int k = 0; k < 4; k++)             tmp[i][j][0][k] = tmp[i][j][1][k] = true, solve(i, j, 0, k);           if (!check()) {             cout <<  NO  << endl;             return 0;           }         }     cout <<  YES  << endl;     return 0;   }


#include<bits/stdc++.h>   using namespace std;      typedef long long ll;   typedef long double ld;   typedef string ss ;   typedef pair<int, int> pi;   typedef pair<ll,ll> pl;   typedef vector<int> vi;   typedef vector<ll> vl;      #define mp make_pair   #define pb push_back            void solve(){          ll n,k=0,q=0;          string s;         cin >> n >> k ;         ll x[n],y[n];         for(int i=0 ; i<n ; i++){             cin >> x[i] >> y[i];         }         bool ok=false;         for(int i=0 ; i<n ; i++){             for(int j=0 ; j<n ; j++){               if(abs(x[i]-x[j]) + abs(y[i]-y[j]) <= k){                 q++;               }               if(q==n) ok=true;         } q=0;         }         cout << (ok ?  1 n  :  -1 n ) ;                  }               int main() {       ios_base::sync_with_stdio(0); cin.tie(0);       int t=1;       cin >> t;       while(t--)        solve();       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 17;   int N, Q;   int main() {     ios_base::sync_with_stdio(false);     cin >> Q;     while (Q--) {       cin >> N;       long long mx;       cin >> mx;       long long diff = 0;       while (--N) {         long long x;         cin >> x;         mx = max(mx, x);         diff = max(diff, mx - x);       }       long long ans = 0;       while (diff) {         ans++;         diff >>= 1;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, p;   string msg, s[100001], h =  <3 ;   int sub(int &i, string &w) {     int k = 0;     for (; k < w.length() && i < msg.length(); i++) {       if (w[k] == msg[i]) {         ++k;       }     }     return k == w.length();   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s[i];     }     cin >> msg;     int j = 0, o = 1;     for (int i = 0; o && i < n; i++) {       if (!sub(j, h)) {         o = 0;       }       if (o && !sub(j, s[i])) {         o = 0;       }     }     if (!sub(j, h)) {       o = 0;     }     if (o) {       cout <<  yes             <<   n ;     } else {       cout <<  no             <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int OO = 1e9;   const double EPS = 1e-9;   const int MX = 1e6 + 5;   int p = 1299709, n, m, u, v;   vector<vector<int>> adj(MX);   unsigned long long pPw[MX], M = 1000000009, Hash[MX];   int main() {     ios::sync_with_stdio(false);     cout.precision(10);     cin.tie(0);     pPw[0] = 1;     for (int i = 1; i < MX; ++i) pPw[i] = p * pPw[i - 1];     cin >> n >> m;     for (int i = 0; i < m; ++i) {       cin >> u >> v;       for (int I = 0; I < 1; ++I) {         Hash[u] += pPw[v];         Hash[v] += pPw[u];       }     }     map<unsigned long long, int> hashes;     for (int i = 1; i <= n; ++i) {       ++hashes[Hash[i]];     }     unsigned long long ans = 0;     for (auto& pr : hashes) {       ans += pr.second * 1LL * (pr.second - 1) / 2;     }     hashes.clear();     for (int i = 1; i <= n; ++i) {       ++hashes[Hash[i] + pPw[i]];     }     for (auto& pr : hashes) {       ans += pr.second * 1LL * (pr.second - 1) / 2;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[200], ans[200];   int v[1000001];   int main() {     int T, n;     cin >> T;     while (T--) {       memset(v, 0, sizeof v);       scanf( %d , &n);       for (int i = 1; i <= n; i++) scanf( %d , &a[i]);       sort(a + 1, a + n + 1);       for (int i = 1; i <= n; i++) {         for (int j = i; j <= n; j++) v[a[j] - a[i]] = 1;       }       memset(ans, 0, sizeof ans);       ans[1] = 1;       int len = 2;       for (int j = 1; j <= 1e6; j++) {         int tag = 1;         for (int k = 1; k < len; k++) {           if (v[j - ans[k]]) {             tag = 0;             break;           }         }         if (tag) ans[len++] = j;         if (len > n) break;       }       int tag = 1;       for (int i = 1; i <= n; i++)         if (ans[i] == 0) tag = 0;       if (tag) {         puts( YES );         for (int i = 1; i <= n; i++) printf( %d%c , ans[i], i == n ?   n  :    );       } else         puts( NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   istream& operator>>(istream& is, vector<T>& v) {     for (T& x : v) is >> x;     return is;   }   template <class T>   ostream& operator<<(ostream& os, const vector<T>& v) {     if (!v.empty()) {       os << v.front();       for (int i = 1; i < v.size(); ++i) os <<     << v[i];     }     return os;   }   const int N = 100010, L = 17;   int n, ns, nt, cnt;   int dist[N], ds[N], dt[N], ts[N], tt[N];   pair<int, int> cs[N], ct[N], c[N], de[N], des[N], det[N];   int ss[N], st[N];   bool vis[N];   vector<pair<int, int>> g[N];   int prs[N][L], prt[N][L];   bool tag;   void dfs(int u) {     vis[u] = true;     for (const auto& pr : g[u]) {       int v, w;       tie(v, w) = pr;       if (!vis[v]) {         dist[v] = dist[u] + w;         dfs(v);       }     }   }   pair<int, int> decomp(int u) {     if (tag)       for (int i = 1; i < L; ++i) prt[u][i] = prt[prt[u][i - 1]][i - 1];     else       for (int i = 1; i < L; ++i) prs[u][i] = prs[prs[u][i - 1]][i - 1];     pair<int, int> ret(0, u);     vis[u] = true;     for (const auto& pr : g[u]) {       int v, w;       tie(v, w) = pr;       if (!vis[v]) {         if (tag)           prt[v][0] = u;         else           prs[v][0] = u;         dist[v] = dist[u] + w;         auto cur = decomp(v);         cur.first += w;         if (cur > ret) {           if (ret.first) c[++cnt] = ret;           ret = cur;         } else           c[++cnt] = cur;       }     }     return de[u] = ret;   }   int s, t;   int query(int x, int y) {     if (ds[x] > dt[x]) {       if (y >= ns) return ss[ns];       if (ts[x] <= y) return ss[y];       int ret = ss[y] + ds[x] + des[x].first;       for (int i = L - 1; i >= 0; --i)         if (ts[prs[x][i]] > y) x = prs[x][i];       x = prs[x][0];       return ret - ds[x] - min(des[x].first, cs[y].first);     }     if (y >= nt) return st[nt];     if (tt[x] <= y) return st[y];     int ret = st[y] + dt[x] + det[x].first;     for (int i = L - 1; i >= 0; --i)       if (tt[prt[x][i]] > y) x = prt[x][i];     x = prs[x][0];     return ret - dt[x] - min(det[x].first, ct[y].first);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int q;     cin >> n >> q;     for (int rep = 1; rep < n; ++rep) {       int u, v, w;       cin >> u >> v >> w;       g[u].emplace_back(v, w);       g[v].emplace_back(u, w);     }     dfs(1);     s = max_element(dist + 1, dist + n + 1) - dist;     memset(vis, 0, sizeof(vis));     dist[s] = 0;     auto diam = decomp(s);     t = diam.second;     c[++cnt] = diam;     sort(c + 1, c + cnt + 1, greater<pair<int, int>>());     copy(c + 1, c + cnt + 1, cs + 1);     copy(dist + 1, dist + n + 1, ds + 1);     copy(de + 1, de + n + 1, des + 1);     ns = cnt;     cnt = 0;     memset(vis, 0, sizeof(vis));     dist[t] = 0;     tag = true;     diam = decomp(t);     c[++cnt] = diam;     sort(c + 1, c + cnt + 1, greater<pair<int, int>>());     copy(c + 1, c + cnt + 1, ct + 1);     copy(dist + 1, dist + n + 1, dt + 1);     copy(de + 1, de + n + 1, det + 1);     nt = cnt;     for (int i = 1; i <= ns; ++i) ss[i] = ss[i - 1] + cs[i].first;     for (int i = 1; i <= nt; ++i) st[i] = st[i - 1] + ct[i].first;     fill(ts + 1, ts + n + 1, -1);     ts[s] = 0;     for (int i = 1; i <= ns; ++i) {       int u = cs[i].second;       while (ts[u] == -1) {         ts[u] = i;         u = prs[u][0];       }     }     fill(tt + 1, tt + n + 1, -1);     tt[t] = 0;     for (int i = 1; i <= nt; ++i) {       int u = ct[i].second;       while (tt[u] == -1) {         tt[u] = i;         u = prt[u][0];       }     }     int ans = 0;     while (q--) {       int x, y;       cin >> x >> y;       x = (x + ans - 1) % n + 1;       y = (y + ans - 1) % n + 1;       cout << (ans = query(x, y * 2 - 1)) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char c[503][503];   vector<pair<int, int> > v[503][503];   int main() {     int n, m, k;     cin >> n >> m >> k;     int s = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> c[i][j];         if (c[i][j] ==  . ) s++;       }     }     pair<int, int> st;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (c[i][j] ==  . ) {           st.first = i;           st.second = j;           if (c[i - 1][j] == c[i][j]) {             v[i][j].push_back(make_pair(i - 1, j));           }           if (c[i + 1][j] == c[i][j]) {             v[i][j].push_back(make_pair(i + 1, j));           }           if (c[i][j - 1] == c[i][j]) {             v[i][j].push_back(make_pair(i, j - 1));           }           if (c[i][j + 1] == c[i][j]) {             v[i][j].push_back(make_pair(i, j + 1));           }         }       }     }     queue<pair<int, int> > q;     q.push(st);     int num = s - k;     if (num) {       c[st.first][st.second] =  q ;       num--;     }     while (!q.empty()) {       pair<int, int> tp = q.front();       q.pop();       for (pair<int, int> kom : v[tp.first][tp.second]) {         if (c[kom.first][kom.second] ==  .  && num > 0) {           c[kom.first][kom.second] =  q ;           num--;           q.push(make_pair(kom.first, kom.second));         }       }     }     for (int i = 1; i < n + 1; i++) {       for (int j = 1; j <= m; j++) {         if (c[i][j] ==  q )           cout <<  . ;         else if (c[i][j] ==  .  && k)           cout <<  X ;         else           cout << c[i][j];       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 32, M = 2e5 + 10;   int q[N], qz[M];   bool insert(int x) {     for (int i = N - 1; i >= 0; --i) {       if ((x >> i) & 1) {         if (!q[i]) {           q[i] = x;           return true;         } else           x ^= q[i];       }     }     return false;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &qz[i]);     for (int i = 1; i <= n; ++i) qz[i] ^= qz[i - 1];     int ans = 0;     if (!qz[n]) return printf( -1 n ), 0;     for (int i = n; i >= 1; --i) {       if (insert(qz[i])) ans++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int n, a[N], b[N], c[N];   multiset<int> S;   multiset<int>::iterator it;   int main() {     std::ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i], c[a[i]] = i;     for (int i = 0; i < n; i++) cin >> b[i];     for (int i = 0; i < n; i++) {       int t = i - c[b[i]];       S.insert(t);     }     vector<int> r;     for (int i = 0; i < n; i++) {       int t = 1000000;       it = S.lower_bound(i);       if (it != S.end()) t = min(t, *(it)-i);       if (it != S.begin()) t = min(t, i - *(--it));       r.push_back(t);       S.erase(S.find(i - c[b[i]]));       S.insert(n - c[b[i]] + i);     }     for (int i = 0; i < r.size(); i++) cout << r[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     long long n, i, j;     cin >> n;     vector<long long> v(n / 2);     for (i = 0; i < v.size(); i++) {       cin >> v[i];     }     sort(v.begin(), v.end());     long long mn = LLONG_MAX;     j = 1;     long long ans = 0;     for (i = 0; i < v.size(); i++) {       ans += abs(j - v[i]);       j += 2;     }     mn = ans;     reverse(v.begin(), v.end());     ans = 0;     j = n;     for (i = 0; i < v.size(); i++) {       ans += abs(j - v[i]);       j -= 2;     }     cout << min(mn, ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const unsigned long long hash1 = 201326611;   const double eps = 1e-8;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const int inf = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   const int N = 255;   const int M = 12;   const int dif = 26;   const double PI = acos(-1.0);   inline void Mod(long long& x) {     if (x >= mod) x -= mod;   }   void BinaryBitset(int n) { cout << bitset<sizeof(int) * 4>(n) << endl; }   int n, m;   long long c[N][N], m0[N], m1[N], dp[N][N];   void init(int n) {     m0[0] = m1[0] = 1;     for (int i = 1; i <= n; i++) {       m0[i] = m0[i - 1] * m % mod;       m1[i] = m1[i - 1] * (m - 1) % mod;     }     c[1][0] = 1;     c[1][1] = 1;     c[0][0] = 1;     for (int i = 1; i <= n; i++) c[i][0] = 1, c[i][i] = 1;     for (int i = 2; i <= n; i++) {       for (int j = 1; j < n; j++) {         c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;       }     }   }   int main() {     scanf( %d%d , &n, &m);     init(n);     for (int i = 1; i <= n; i++) dp[1][i] = c[n][i] * m1[n - i] % mod;     for (int i = 2; i <= n; i++) {       for (int j = 0; j <= n; j++) {         for (int k = 0; k <= j; k++) {           dp[i][j] = (dp[i][j] + c[n - k][j - k] * dp[i - 1][k] % mod *                                      m1[n - j] % mod * m0[k] % mod) %                      mod;           if (j == k)             dp[i][j] =                 ((dp[i][j] - m1[n] * dp[i - 1][k] % mod + mod) % mod + mod) % mod;         }       }     }     printf( %lld n , dp[n][n]);   }


#include <bits/stdc++.h>   #pragma optimization_level 3   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   using namespace std;   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   int getChar() {     static char buf[1 << 16];     static int pos = 0, size = 0;     if (pos == size) {       pos = 0;       size = (int)fread(buf, sizeof(buf[0]), sizeof(buf) / sizeof(buf[0]), stdin);     }     return buf[pos++];   }   inline int ni() {     char c = getChar();     for (; c ==   n  || c ==    ;) c = getChar();     int o = 0;     for (; c !=     && c !=   n ; c = getChar()) o = o * 10 + c -  0 ;     return o;   }   inline void putChar(int c) {     static char buf[1 << 16];     static int pos = 0;     if (c == EOF || pos == 1 << 16) {       fwrite(buf, sizeof(buf[0]), pos, stdout);       pos = 0;     }     if (c == EOF) return;     buf[pos++] = c;   }   void printInt(int val) {     char buf[7];     int pos = 0;     if (val == 0) buf[pos++] = 48;     for (; val; val /= 10) buf[pos++] = 48 + val % 10;     for (pos--; pos >= 0;) putChar(buf[pos--]);     putChar(  n );   }   const int G = 400002;   int a, OPA = -1;   vector<int> l[G];   int skok[G], o[G], zam[G], GR[G][2], mxd[G], mxp[G], dp[G][2], sz[G];   int CALC(int v, int D) {     mxd[v] = 1;     sz[v] = 1;     int c1 = 0, c2 = 0;     for (int h : l[v]) {       int x = CALC(h, D + 1);       mxd[v] = max(mxd[v], x + 1);       sz[v] += sz[h];       if (x >= c1)         c2 = c1, c1 = x;       else if (x > c2)         c2 = x;     }     mxp[v] = c1 + c2 + 1;     return mxd[v];   }   int eba = 1;   void RIP_PAPA(int v, int p) {     for (int q = 0; q < l[v].size(); q++) {       if (l[v][q] == p) {         l[v].erase(l[v].begin() + q);         break;       }     }     for (int h : l[v]) RIP_PAPA(h, v);   }   void rnm(int v, int p) {     for (int h : l[v])       if (h != p) zam[h] = eba++;     for (int h : l[v])       if (h != p) rnm(h, v);   }   int ST;   int GA(int LEN) {     if (o[LEN] != -1) return o[LEN];     int d1, d2, w, rg;     for (; ST >= 0 && mxp[ST] < OPA;) ST--;     for (int q = ST; q >= 0; q--) {       dp[q][0] = 0;       d1 = d2 = 0, w = GR[q][0], rg = GR[q][1];       for (; w <= rg; w++) {         dp[q][0] += dp[w][0];         if (dp[w][1] >= d1)           d2 = d1, d1 = dp[w][1];         else           d2 = max(d2, dp[w][1]);       }       if (d1 + d2 + 1 < LEN)         dp[q][1] = d1 + 1;       else         dp[q][0]++, dp[q][1] = 0;     }     return o[LEN] = dp[0][0];   }   int main() {     cin.tie(0);     cout.tie(0);     cin.sync_with_stdio(0);     cout.sync_with_stdio(0);     ;     memset(o, -1, sizeof(o));     a = ni();     o[1] = a;     ;     ST = a - 1;     for (int q = 1; q <= a; q++) skok[a / q]++;     for (int &i : skok) i /= 2;     vector<pair<int, int> > reb(a - 1);     for (int q = 0; q < a - 1; q++) {       int x = ni() - 1, y = ni() - 1;       reb[q] = {x, y};       l[x].push_back(y);       l[y].push_back(x);     }     zam[0] = 0;     rnm(0, -1);     for (int q = 0; q < a; q++) l[q].clear();     for (pair<int, int> p : reb) {       l[zam[p.first]].push_back(zam[p.second]);       l[zam[p.second]].push_back(zam[p.first]);     }     RIP_PAPA(0, -1);     for (int q = 0; q < a; q++) {       GR[q][0] = l[q].size() ? l[q][0] : a;       GR[q][1] = l[q].size() ? l[q].back() : q;     }     CALC(0, 1);     int diam = 0;     for (int &i : mxp) diam = max(i, diam);     o[diam] = 1;     for (int q = diam + 1; q <= a; q++) o[q] = 0;     int H = min(a - 1, (int)(sqrt(diam))), U = 1, I = 2;     for (; I <= H; I++) {       o[I] = GA(I);       OPA = I / 2;     }     int tyt;     for (; I <= a;) {       OPA = I / 2;       tyt = GA(I);       int lf = I, rg = min(a + 1, lf + skok[tyt] + 1);       if (tyt == 0) break;       if (tyt == 1) lf = diam, rg = diam + 1;       for (; lf + 1 < rg;) {         int md = (lf + rg) / 2;         if (GA(md) == tyt)           lf = md;         else           rg = md;       }       for (; I < rg; I++) o[I] = tyt;     }     for (int q = 1; q <= a; q++) {       printInt(max(0, o[q]));     }     putChar(EOF);   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, s, e, v, q;   vector<long long> vs, ve;   int32_t main() {     ios::sync_with_stdio(0), cin.tie(0);     cin >> n >> m >> s >> e >> v;     vs.resize(s), ve.resize(e);     for (auto& u : vs) {       cin >> u;     }     for (auto& u : ve) {       cin >> u;     }     cin >> q;     while (q--) {       long long x, y, a, b;       cin >> x >> y >> a >> b;       if (x == a) {         cout << abs(y - b) <<   n ;       } else {         long long ans = 1e18, idx, es = (abs(x - a) + v - 1) / v;         if (y > b) swap(y, b);         idx = lower_bound(vs.begin(), vs.end(), y) - vs.begin();         if (idx < s) {           ans = min(ans, abs(vs[idx] - y) + abs(vs[idx] - b) + abs(x - a));         }         idx--;         if (idx >= 0) {           ans = min(ans, abs(vs[idx] - y) + abs(vs[idx] - b) + abs(x - a));         }         idx = lower_bound(ve.begin(), ve.end(), y) - ve.begin();         if (idx < e) {           ans = min(ans, abs(ve[idx] - y) + abs(ve[idx] - b) + es);         }         idx--;         if (idx >= 0) {           ans = min(ans, abs(ve[idx] - y) + abs(ve[idx] - b) + es);         }         cout << ans <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long w[1000000], w1[100000];   long long t[1000000];   pair<long long, long long> ans;   long long a, b, c, n, m, q, k, x, c1, b1;   long long poww(long long x, long long y) {     if (x == 0) return 0;     if (x == 1) return 1;     if (y == 0) return 1;     if (y == 1) return x;     long long d = poww(x, y / 2);     if (y % 2) return d * d * x;     return d * d;   }   map<long long, long long> M;   vector<long long> v;   int main() {     cin >> a >> b >> c;     for (int i = 1; i <= 1000000; i++) {       a *= 10;       if (a / b == c) return cout << i, 0;       a %= b;     }     cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s =  ROYGBIV ;     long long int n, i;     cin >> n;     for (i = 0; i < n - 3; i++) {       cout << s[i % 4];     }     cout <<  BIV ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s;     cin >> n >> s;     int sum = 100;     bool res = false;     for (int i = 0; i < n; i++) {       int temp1, temp2;       cin >> temp1 >> temp2;       if (temp1 < s) {         res = true;         if (temp2 != 0 && temp2 < sum) sum = temp2;       }       if (temp1 == s && temp2 == 0) res = true;     }     if (res)       cout << 100 - sum;     else       cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dx[8] = {0, -1, 0, 1, 1, -1, -1, 1};   const int dy[8] = {-1, 0, 1, 0, -1, -1, 1, 1};   const long long mod = 1000000007;   const int base = 311;   const int N = 6e5 + 5;   map<long long, vector<pair<int, int>>> e;   int n, m;   long long a[N];   vector<int> dsk[N];   long long pw[N];   int dd[N];   int k;   void dfs(int u, int &d) {     dd[u] = 1;     ++d;     for (int v : dsk[u])       if (!dd[v]) dfs(v, d);   }   void gogo() {     cin >> n >> m >> k;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i <= m; ++i) {       int u, v;       cin >> u >> v;       e[a[u] ^ a[v]].push_back(make_pair(u, v));     }     pw[0] = 1;     for (int i = 1; i <= 6e5; ++i) pw[i] = pw[i - 1] * 2 % mod;     long long ans = pw[k] * pw[n] % mod;     for (auto it : e) {       vector<pair<int, int>> tmp = it.second;       for (pair<int, int> i : tmp) {         dsk[i.first].push_back(i.second);         dsk[i.second].push_back(i.first);       }       vector<int> cnt;       for (pair<int, int> i : tmp) {         int d = 0;         if (!dd[i.first]) {           dfs(i.first, d);           cnt.push_back(d);         }       }       int sum = 0;       for (int i : cnt) sum += i;       long long comp = n - sum + ((int)(cnt).size());       ans = (ans - pw[n] + pw[comp] + mod * mod) % mod;       for (pair<int, int> i : tmp) {         dd[i.first] = dd[i.second] = 0;         dsk[i.first].clear();         dsk[i.second].clear();       }     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     if (fopen( sol                 .inp ,                r )) {       freopen(            sol             .inp ,            r , stdin);       freopen(            sol             .out ,            w , stdout);     }     gogo();   }


#include <bits/stdc++.h>   using namespace std;   double x[1005], y[1005], z[1005], r[1005];   long long int n, m;   int main() {     double res = (1ll << (long long int)(60)), ax, ay, az, vx, vy, vz, R;     cin >> ax >> ay >> az >> vx >> vy >> vz >> R >> n;     for (long long int i = 0; i < ((long long int)(n)); i++) {       cin >> x[0] >> y[0] >> z[0] >> r[0] >> m;       for (long long int j = 0; j < ((long long int)(m)); j++)         cin >> x[j + 1] >> y[j + 1] >> z[j + 1];       for (long long int j = 0; j < ((long long int)(m)); j++)         x[j + 1] += x[0], y[j + 1] += y[0], z[j + 1] += z[0];       for (long long int j = 0; j < ((long long int)(m + 1)); j++) {         double t = -(vx * (ax - x[j]) + vy * (ay - y[j]) + vz * (az - z[j])) /                    ((vx) * (vx) + (vy) * (vy) + (vz) * (vz));         if (t < 0) continue;         if (((vx * t + ax - x[j]) * (vx * t + ax - x[j]) +              (vy * t + ay - y[j]) * (vy * t + ay - y[j]) +              (vz * t + az - z[j]) * (vz * t + az - z[j])) <             (R + r[j]) * (R + r[j]) + 0.0000001) {           double low = 0, high = t;           for (long long int k = 0; k < ((long long int)(100)); k++) {             double mid = (low + high) / 2.0;             if (((vx * mid + ax - x[j]) * (vx * mid + ax - x[j]) +                  (vy * mid + ay - y[j]) * (vy * mid + ay - y[j]) +                  (vz * mid + az - z[j]) * (vz * mid + az - z[j])) <                 (R + r[j]) * (R + r[j]))               high = mid;             else               low = mid;           }           res = min(res, low);         }       }     }     if (res == (1ll << (long long int)(60)))       cout <<  -1  << endl;     else       printf( %0.20lf n , res);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 20;   vector<int> a[N];   vector<int> Q;   int t, x, p, k;   int solve(int n, int p) {     int ret = 0;     Q.clear();     Q.push_back(-1);     vector<int>& f = a[p];     for (int i = 0; i < (int)f.size(); ++i) {       int top = Q.size();       for (int j = 0; j < top; ++j) {         Q.push_back(-1 * f[i] * Q[j]);       }     }     for (int i = 1; i < (int)Q.size(); ++i) {       ret += n / Q[i];     }     return n - ret;   }   int main() {     for (int i = 2; i <= 1000000; ++i) {       if (a[i].size() > 0) continue;       for (int j = i; j <= 1000000; j += i) {         a[j].push_back(i);       }     }     scanf( %d , &t);     while (t--) {       scanf( %d %d %d , &x, &p, &k);       k += solve(x, p);       int lb = 1, ub = 1e9, ans = x;       while (lb <= ub) {         int mid = (lb + ub) / 2;         if (solve(mid, p) >= k) {           ans = mid;           ub = mid - 1;         } else {           lb = mid + 1;         }       }       printf( %d n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool chkmin(T &a, T b) {     return b < a ? a = b, 1 : 0;   }   template <typename T>   inline bool chkmax(T &a, T b) {     return b > a ? a = b, 1 : 0;   }   inline int read() {     int x(0), sgn(1);     char ch(getchar());     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) sgn = -1;     for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);     return x * sgn;   }   void File() {}   int n, m;   const int inf = 0x3f3f3f3f;   template <int Maxn, int Maxm>   struct Dinic {     int Head[Maxn], Next[Maxm], cap[Maxm], to[Maxm], e;     Dinic() { e = 1; }     inline void add_edge(int u, int v, int flow) {       to[++e] = v;       Next[e] = Head[u];       Head[u] = e;       cap[e] = flow;     }     inline void Add(int u, int v, int flow) {       add_edge(u, v, flow);       add_edge(v, u, 0);     }     int S, T, dis[Maxn];     bool Bfs() {       queue<int> Q;       Q.push(S);       memset(dis, 0, sizeof(dis));       dis[S] = 1;       while (!Q.empty()) {         int u = Q.front();         Q.pop();         for (int i = Head[u], v = to[i]; i; v = to[i = Next[i]])           if (cap[i] && !dis[v]) dis[v] = dis[u] + 1, Q.push(v);       }       return dis[T];     }     int cur[Maxn];     int Dfs(int u, int flow) {       if (u == T || !flow) return flow;       int res = 0, f;       for (int &i = cur[u]; i; i = Next[i]) {         int v = to[i];         if (dis[v] == dis[u] + 1 && (f = Dfs(v, min(flow, cap[i])))) {           cap[i] -= f, cap[i ^ 1] += f, res += f;           if (!(flow -= f)) break;         }       }       if (!res) dis[u] = 0;       return res;     }     int Run() {       int sum_flow = 0;       while (Bfs()) memcpy(cur, Head, sizeof(cur)), sum_flow += Dfs(S, inf);       return sum_flow;     }   };   const int N = 5050;   Dinic<(int)1e5, (int)4e5> D;   int tot;   int ans[N], Bef;   template <int Maxn>   struct Segment_Tree {     int id[Maxn];     void Build(int o, int l, int r) {       if (l == r) {         id[o] = l;         return;       }       id[o] = ++tot;       int mid = (l + r) >> 1;       Build(o << 1, l, mid);       Build(o << 1 | 1, mid + 1, r);       D.Add(id[o], id[o << 1], id[o << 1] <= m ? 1 : inf);       D.Add(id[o], id[o << 1 | 1], id[o << 1 | 1] <= m ? 1 : inf);     }     inline void Connect(int o, int l, int r, int ql, int qr, int Id) {       if (ql <= l && r <= qr) {         D.Add(Id, id[o], 2);         return;       }       int mid = (l + r) >> 1;       if (ql <= mid) Connect(o << 1, l, mid, ql, qr, Id);       if (qr > mid) Connect(o << 1 | 1, mid + 1, r, ql, qr, Id);     }     vector<int> find(int o, int l, int r) {       if (l == r) return vector<int>();       vector<int> tmp;       int mid = (l + r) >> 1;       vector<int> ls = find(o << 1, l, mid), rs = find(o << 1 | 1, mid + 1, r);       set_union((ls).begin(), (ls).end(), (rs).begin(), (rs).end(),                 inserter(tmp, tmp.end()));       for (int i = D.Head[id[o]], v = D.to[i]; i; v = D.to[i = D.Next[i]])         if (v <= m && !D.cap[i]) tmp.push_back(v);       for (int i = D.Head[id[o]], v = D.to[i]; i; v = D.to[i = D.Next[i]])         if (D.cap[i] && v > Bef) {           int cur = tmp[tmp.size() - 1];           tmp.pop_back();           ans[cur] = v - Bef;         }       return tmp;     }   };   Segment_Tree<N << 2> T;   vector<int> V1, V2, V3;   int Ref[N], from[N], go[N];   void Get_Ans() {     for (int u : V1) {       for (int i = D.Head[Ref[u]], v = D.to[i]; i; v = D.to[i = D.Next[i]])         if (v <= m && D.cap[i ^ 1]) ans[v] = u;     }     T.find(1, 1, m);     for (int u : V3) {       int flow = D.cap[from[u]];       for (int i = D.Head[Ref[u]], v = D.to[i]; i; v = D.to[i = D.Next[i]])         if (v != D.S && !D.cap[i]) ans[v] = u;       if (flow == 1)         for (int i = D.Head[Ref[u]], v = D.to[i]; i; v = D.to[i = D.Next[i]])           if (v != D.S && D.cap[i]) {             ans[v] = u;             break;           }     }   }   int main() {     File();     n = read(), m = read();     tot = m;     T.Build(1, 1, m);     Bef = tot;     D.S = tot + n + 1;     D.T = tot + n + 2;     for (register int i = (1), iend = (int)(m); i <= iend; ++i)       D.Add(i, D.T, 1), go[i] = D.e - 1;     for (register int i = (1), iend = (int)(n); i <= iend; ++i) {       int opt = read();       D.Add(D.S, Ref[i] = ++tot, 1 + (opt == 2));       from[i] = D.e - 1;       if (opt == 0) {         int k = read();         V1.push_back(i);         while (k--) D.Add(tot, read(), 1);       } else if (opt == 1) {         int l = read(), r = read();         V1.push_back(i);         T.Connect(1, 1, m, l, r, tot);       } else {         int a = read(), b = read(), c = read();         V3.push_back(i);         D.Add(tot, a, 1);         D.Add(tot, b, 1);         D.Add(tot, c, 1);       }     }     printf( %d n , D.Run());     Get_Ans();     for (register int i = (1), iend = (int)(m); i <= iend; ++i)       if (ans[i]) printf( %d %d n , ans[i], i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 2 * acos(0.0);   void solve(void) {     string str;     cin >> str;     int one = 0, zero = 0;     for (int i = 0; i < str.length(); i++) {       if (str[i] ==  1 ) {         one++;         while (i < str.length() && str[i] ==  1 ) i++;         i--;       } else {         zero++;         while (i < str.length() && str[i] ==  0 ) i++;         i--;       }     }     if (one && zero) {       if (zero <= 1)         cout << 1 <<   n ;       else         cout << 2 <<   n ;     } else if (zero)       cout << 1 <<   n ;     else if (one)       cout << 0 <<   n ;   }   int main(void) {     ios::sync_with_stdio(0), cin.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline string tostring(const T &x) {     ostringstream os;     os << x;     return os.str();   }   inline int toint(const string &s) {     istringstream is(s);     int x;     is >> x;     return x;   }   inline int todecimal(string s) {     int a = 0;     for (int i = 0; i < s.size(); i++) a = 2 * a + (s[i] -  0 );     return a;   }   inline string tobinary(int a) {     string s;     while (a != 0) {       s = (char)(a % 2 +  0 ) + s;       a >>= 1;     }     return s;   }   template <typename T>   inline T sqr(T x) {     return x * x;   }   template <typename T>   T gcd(T a, T b) {     return (b == 0) ? abs(a) : gcd(b, a % b);   }   inline int isvowel(char c) {     if (c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u ) return 1;     return 0;   }   inline int isprime(int a) {     for (int i = 2; i * i <= a; i++)       if (!(a % i)) return 0;     return 1;   }   inline void inp(int &n) {     n = 0;     int ch = getchar();     int sign = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) sign = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       n = (n << 3) + (n << 1) + ch -  0 , ch = getchar();     n = n * sign;   }   const int dx4[4] = {0, 0, 1, -1};   const int dy4[4] = {1, -1, 0, 0};   const int dx8[8] = {0, 0, 1, 1, 1, -1, -1, -1};   const int dy8[8] = {1, -1, 0, 1, -1, 1, 0, -1};   class node {    public:     int x, y, z;     node(int a, int b, int c) {       x = a;       y = b;       z = c;     }   };   bool operator<(const node &a, const node &b) { return a.x > b.x; }   bool compare(const node &a, const node &b) { return a.x < b.x; }   const int maxn = 66;   int grid[maxn][maxn];   int n;   void solve() {     memset((grid), (0), sizeof(grid));     grid[0][0] = n;     int moving = 1;     while (moving) {       moving = 0;       for (int i = 0; i < maxn; i++) {         for (int j = 0; j < maxn; j++) {           int x = grid[i][j] / 4;           grid[i + 1][j] += x;           grid[i][j + 1] += x;           if (i) grid[i - 1][j] += x * (i == 1 ? 2 : 1);           if (j) grid[i][j - 1] += x * (j == 1 ? 2 : 1);           grid[i][j] %= 4;           if (x) moving = 1;         }       }     }     int q = 0;     ;     cin >> q;     int x, y;     for (int i = 0; i < q; i++) {       cin >> x >> y;       if (x < 0) x = -x;       if (y < 0) y = -y;       if (x >= maxn || y >= maxn)         cout << 0 << endl;       else         cout << grid[x][y] << endl;     }   }   void input() { cin >> n; }   int main() {     int testcase = 1;     for (int i = 0; i < testcase; i++) {       input();       solve();     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( inline,Ofast , 3)   #pragma GCC optimize(2)   #pragma GCC optimize(3)   #pragma GCC optimize( Ofast )   #pragma GCC optimize( inline )   #pragma GCC optimize( -fgcse )   #pragma GCC optimize( -fgcse-lm )   #pragma GCC optimize( -fipa-sra )   #pragma GCC optimize( -ftree-pre )   #pragma GCC optimize( -ftree-vrp )   #pragma GCC optimize( -fpeephole2 )   #pragma GCC optimize( -ffast-math )   #pragma GCC optimize( -fsched-spec )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( -falign-jumps )   #pragma GCC optimize( -falign-loops )   #pragma GCC optimize( -falign-labels )   #pragma GCC optimize( -fdevirtualize )   #pragma GCC optimize( -fcaller-saves )   #pragma GCC optimize( -fcrossjumping )   #pragma GCC optimize( -fthread-jumps )   #pragma GCC optimize( -funroll-loops )   #pragma GCC optimize( -fwhole-program )   #pragma GCC optimize( -freorder-blocks )   #pragma GCC optimize( -fschedule-insns )   #pragma GCC optimize( inline-functions )   #pragma GCC optimize( -fschedule-insns2 )   #pragma GCC optimize( -fstrict-aliasing )   #pragma GCC optimize( -fstrict-overflow )   #pragma GCC optimize( -falign-functions )   #pragma GCC optimize( -fcse-skip-blocks )   #pragma GCC optimize( -fcse-follow-jumps )   #pragma GCC optimize( -fsched-interblock )   #pragma GCC optimize( -fpartial-inlining )   #pragma GCC optimize( no-stack-protector )   #pragma GCC optimize( -freorder-functions )   #pragma GCC optimize( -findirect-inlining )   #pragma GCC optimize( inline-small-functions )   #pragma GCC optimize( -finline-small-functions )   #pragma GCC optimize( -ftree-switch-conversion )   #pragma GCC optimize( -foptimize-sibling-calls )   #pragma GCC optimize( -fexpensive-optimizations )   #pragma GCC optimize( -funsafe-loop-optimizations )   #pragma GCC optimize( inline-functions-called-once )   #pragma GCC optimize( -fdelete-null-pointer-checks )   using namespace std;   long long n, m, q, fa[1000010], ans, l, r;   struct lujing {     long long u, v, c, id;   } f[1000010];   inline long long read() {     long long w = 0, e = 1;     char ch = getchar();     while (!isdigit(ch)) {       e = ch ==  -  ? -1 : 1;       ch = getchar();     }     while (isdigit(ch)) {       w = (w << 3) + (w << 1) + (ch ^ 48);       ch = getchar();     }     return w * e;   }   long long find(long long x) { return (fa[x] == x) ? x : (fa[x] = find(fa[x])); }   void add(long long x, long long y) {     long long xx = find(x), yy = find(y);     if (xx != yy) fa[xx] = yy;   }   bool pd(long long x, long long y) {     long long xx = find(x), yy = find(y);     if (xx == yy) return true;     return false;   }   bool cmp(lujing x, lujing y) { return x.c > y.c; }   int main() {     n = read();     m = read();     q = read();     for (register int i = 1; i <= m; ++i)       f[i].u = read(), f[i].v = read(), f[i].c = read(), f[i].id = i;     sort(f + 1, f + 1 + m, cmp);     while (q--) {       l = read(), r = read();       ans = -1;       for (register int i = 1; i <= n * 2; ++i) fa[i] = i;       for (register int i = 1; i <= m; ++i) {         if (f[i].id >= l && f[i].id <= r) {           if (pd(f[i].u, f[i].v)) {             ans = f[i].c;             break;           } else {             add(f[i].u + n, f[i].v);             add(f[i].u, f[i].v + n);           }         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, v, pre, rotting, a[4005], b[4005], i, j, bag, collect, day, v2;     while (scanf( %d%d , &n, &v) != EOF) {       day = 0;       bag = 0;       for (i = 0; i < n; i++) {         scanf( %d%d , &a[i], &b[i]);         if (a[i] > day) day = a[i];       }       rotting = 0;       day += 2;       for (i = 1; i < day; i++) {         pre = 0;         for (j = 0; j < n; j++) {           if (a[j] == i) {             pre += b[j];           }         }         if (rotting > v) {           bag += v;           v2 = 0;         } else {           bag += rotting;           v2 = v - rotting;         }         if (pre > v2) {           bag += v2;           pre -= v2;         } else {           bag += pre;           pre = 0;         }         rotting = pre;       }       printf( %d n , bag);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string doen() {     char c;     string waarde;     while (cin.get(c) && c !=   n ) {       waarde += c;     }     int aantal = stoi(waarde);     string iets;     getline(cin, iets);     for (int i = 0; i < iets.length(); i = i + 2) {       if (iets[i] ==  1 ) {         return  HARD ;       }     }     return  EASY ;   }   int main() {     cout << doen();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[110];   int d[110];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d%d , &a[i], &d[i]);     }     int ans = 0;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         if (a[i] >= a[j]) {           if (a[i] < a[j] + d[j] || a[i] + d[i] < a[j]) {             ans++;             if (a[i] + d[i] >= a[j] + d[j]) ans++;           } else if (a[i] + d[i] < a[j] + d[j])             ans++;         } else {           if (a[i] + d[i] >= a[j] || a[i] >= a[j] + d[j]) {             ans++;             if (a[i] + d[i] < a[j] + d[j]) ans++;           } else if (a[i] + d[i] >= a[j] + d[j])             ans++;         }       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   struct {     inline operator int() {       int x;       return scanf( %d , &x), x;     }     inline operator long long() {       long long x;       return scanf( %lld , &x), x;     }     template <class T>     inline void operator()(T &x) {       x = *this;     }     template <class T, class... A>     inline void operator()(T &x, A &...a) {       x = *this;       this->operator()(a...);     }   } read;   const int maxn = 300005;   int l[maxn], r[maxn];   int main() {     int T = read;     while (T--) {       int n = read;       std::fill(l, l + n + 1, 0);       std::fill(r, r + n + 1, 0);       for (int i = 1; i <= n; i++) {         int x = read;         if (!l[x]) l[x] = i;         r[x] = i;       }       int ans = 0, max = 0;       for (int x = 1, y = 0, now = 0; x <= n; x++)         if (l[x]) {           if (r[y] < l[x])             ++now;           else             now = 1;           ++ans;           max = std::max(max, now);           y = x;         }       ans -= max;       printf( %d n , ans);     }   }