#include <bits/stdc++.h>   using namespace std;   const int MXN = 2e5 + 5;   int x[MXN];   int y[MXN];   int d[MXN];   int xr[MXN];   int par[MXN];   int siz[MXN];   int sol[MXN];   int type[MXN];   int basis[30];   stack<pair<int *, int>> stk;   vector<array<int, 3>> st[2 << 18];   void change(int &ref, int val) {     stk.push({&ref, ref});     ref = val;   }   array<int, 2> get(int x) {     int len = 0;     while (par[x]) {       len ^= xr[x];       x = par[x];     }     return {x, len};   }   void join(int x, int y, int d) {     auto [px, xrx] = get(x);     auto [py, xry] = get(y);     if (px == py) {       int cycle = xrx ^ d ^ xry;       for (int i = 29; i >= 0; --i) {         if (cycle >> i & 1) {           if (basis[i]) {             cycle ^= basis[i];           } else {             change(basis[i], cycle);             break;           }         }       }     } else {       if (siz[px] < siz[py]) {         swap(px, py);       }       change(siz[px], siz[px] + siz[py]);       change(xr[py], xrx ^ d ^ xry);       change(par[py], px);     }   }   void dfs(int lo, int hi, int nd = 0) {     int sz = stk.size();     for (auto [x, y, d] : st[nd]) {       join(x, y, d);     }     if (lo + 1 == hi) {       sol[lo] ^= get(x[lo])[1];       sol[lo] ^= get(y[lo])[1];       for (int i = 29; i >= 0; --i) {         sol[lo] = min(sol[lo], sol[lo] ^ basis[i]);       }     } else {       int mid = (lo + hi) / 2;       dfs(lo, mid, 2 * nd + 1);       dfs(mid, hi, 2 * nd + 2);     }     while (sz < (int)stk.size()) {       auto [ptr, val] = stk.top();       *ptr = val;       stk.pop();     }   }   void add(int l, int r, array<int, 3> e, int lo, int hi, int nd = 0) {     if (l <= lo && hi <= r) return st[nd].push_back(e);     int mid = (lo + hi) / 2;     if (l < mid) add(l, r, e, lo, mid, 2 * nd + 1);     if (mid < r) add(l, r, e, mid, hi, 2 * nd + 2);   }   int main() {     ios::sync_with_stdio(0), cin.tie(0);     int n, m;     cin >> n >> m;     map<array<int, 2>, array<int, 2>> mp;     for (int i = 0; i < m; ++i) {       int x, y, d;       cin >> x >> y >> d;       mp[{x, y}] = {0, d};     }     int q;     cin >> q;     int sz = 0;     for (int i = 0; i < q; ++i) {       cin >> type[i] >> x[i] >> y[i];       if (type[i] == 1) cin >> d[i];       sz += type[i] == 3;     }     int cq = 0;     for (int i = 0; i < q; ++i) {       if (type[i] == 1) {         mp[{x[i], y[i]}] = {cq, d[i]};       } else if (type[i] == 2) {         auto [pq, d] = mp[{x[i], y[i]}];         mp.erase({x[i], y[i]});         if (pq < cq) add(pq, cq, {x[i], y[i], d}, 0, sz);       } else {         x[cq] = x[i];         y[cq] = y[i];         cq++;       }     }     for (auto [a, b] : mp) {       if (b[0] < sz) add(b[0], sz, {a[0], a[1], b[1]}, 0, sz);     }     for (int i = 1; i <= n; ++i) {       siz[i] = 1;     }     dfs(0, sz);     for (int i = 0; i < sz; ++i) {       cout << sol[i] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int ans = 0;     while (n--) {       string t;       cin >> t;       int c = k;       for (char x : t)         if (x ==  4  || x ==  7 ) c--;       if (c >= 0) ans++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, neg, zero;     cin >> x;     int arr[x];     for (int i = 0; i < x; i++) cin >> arr[i];     sort(arr, arr + x);     if (arr[x - 1] <= 0) {       cout <<  1             <<     << arr[0] << endl;       cout <<  2             <<     << arr[1] <<     << arr[2] << endl;       for (int i = 3; i < x; i++) {         if (i == 3)           cout << x - i <<     << arr[3];         else           cout <<     << arr[i];       }     } else {       for (int i = 0; i < x; i++) {         if (arr[i] < 0)           neg = i;         else if (arr[i] == 0)           zero = i;       }       cout <<  1   << arr[0] << endl;       cout << x - zero - 1 <<    ;       for (int i = zero + 1; i < x; i++) cout << arr[i] <<    ;       cout << endl;       cout << zero;       for (int i = 1; i <= zero; i++) cout <<     << arr[i];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   const char c[3][4] = { RGB ,  GBR ,  BRG };   int sum[3][N];   char s[N];   int main() {     int n, k, T;     scanf( %d , &T);     while (T--) {       scanf( %d%d , &n, &k);       sum[0][0] = sum[1][0] = sum[2][0] = 0;       scanf( %s , s);       if (k == 1) {         printf( 0 n );         continue;       }       for (int i = 0; i < 3; i++) {         for (int j = 0; j < n; j++) {           if (s[j] != c[i][j % 3]) {             sum[i][j + 1] = sum[i][j] + 1;           } else {             sum[i][j + 1] = sum[i][j];           }         }       }       int ans = N;       for (int p = 0; p < 3; p++) {         for (int i = 1; i + k - 1 <= n; i++) {           int j = i + k - 1;           ans = min(ans, sum[p][j] - sum[p][i - 1]);         }       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2005;   char s[N];   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n, k;       scanf( %d%d , &n, &k);       scanf( %s , s);       getchar();       vector<int> cnt(27, 0);       for (int i = 0; i < n; ++i) ++cnt[s[i] -  a ];       for (int len = n; len >= 1; --len) {         vector<int> circ, c_cnt, used(len, 0);         for (int i = 0; i < len; ++i) {           if (used[i]) continue;           used[i] = 1;           int j = (i + k) % len;           circ.push_back(1);           while (!used[j]) {             used[j] = 1;             circ.back()++;             j = (j + k) % len;           }         }         c_cnt = cnt;         sort(circ.begin(), circ.end());         sort(c_cnt.begin(), c_cnt.end());         int ok = 1;         while (!circ.empty()) {           if (circ.back() > c_cnt.back()) {             ok = 0;             break;           } else {             c_cnt.back() -= circ.back();             circ.pop_back();             sort(c_cnt.begin(), c_cnt.end());           }         }         if (ok) {           printf( %d n , len);           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const double eps = 1e-9;   const int inf = 2000000000;   const long long infLL = 90000000000000000;   inline bool checkBit(long long n, int i) { return n & (1LL << i); }   inline long long setBit(long long n, int i) {     return n | (1LL << i);     ;   }   inline long long resetBit(long long n, int i) { return n & (~(1LL << i)); }   int dx[] = {0, 0, +1, -1};   int dy[] = {+1, -1, 0, 0};   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   inline bool isLeapYear(long long year) {     return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);   }   inline void normal(long long &a) {     a %= 1000000007;     (a < 0) && (a += 1000000007);   }   inline long long modMul(long long a, long long b) {     a %= 1000000007, b %= 1000000007;     normal(a), normal(b);     return (a * b) % 1000000007;   }   inline long long modAdd(long long a, long long b) {     a %= 1000000007, b %= 1000000007;     normal(a), normal(b);     return (a + b) % 1000000007;   }   inline long long modSub(long long a, long long b) {     a %= 1000000007, b %= 1000000007;     normal(a), normal(b);     a -= b;     normal(a);     return a;   }   const int MX = 101000;   int tree[21][4 * MX], lazy[21][4 * MX], a[MX];   long long arr[21];   void build(int node, int l, int r, int val) {     if (l == r) {       if (checkBit(a[l], val)) tree[val][node] = 1;       return;     }     int mid = (l + r) / 2;     build(node * 2, l, mid, val);     build(node * 2 + 1, mid + 1, r, val);     tree[val][node] = tree[val][node * 2] + tree[val][node * 2 + 1];     ;   }   void update(int node, int l, int r, int b, int e, int val) {     if (lazy[val][node]) {       tree[val][node] = (r - l + 1) - tree[val][node];       if (l != r) lazy[val][node * 2] ^= 1, lazy[val][node * 2 + 1] ^= 1;       lazy[val][node] = 0;     }     if (l > e || r < b) return;     if (l >= b && r <= e) {       tree[val][node] = (r - l + 1) - tree[val][node];       if (l != r) lazy[val][node * 2] ^= 1, lazy[val][node * 2 + 1] ^= 1;       return;     }     int mid = (l + r) / 2;     update(node * 2, l, mid, b, e, val);     update(node * 2 + 1, mid + 1, r, b, e, val);     tree[val][node] = tree[val][node * 2] + tree[val][node * 2 + 1];   }   int query(int node, int l, int r, int b, int e, int val) {     if (lazy[val][node]) {       tree[val][node] = (r - l + 1) - tree[val][node];       if (l != r) lazy[val][node * 2] ^= 1, lazy[val][node * 2 + 1] ^= 1;       lazy[val][node] = 0;     }     if (l > e || r < b) return 0;     if (l >= b && r <= e) return tree[val][node];     int mid = (l + r) / 2;     return query(node * 2, l, mid, b, e, val) +            query(node * 2 + 1, mid + 1, r, b, e, val);   }   int main() {     for (int i = 1, j = 0; j < 21; ++j, i *= 2) arr[j] = i;     int n;     scanf( %d , &n);     ;     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     for (int i = 0; i < 21; ++i) build(1, 0, n - 1, i);     int m;     scanf( %d , &m);     ;     while (m--) {       int t;       scanf( %d , &t);       if (t == 1) {         int l, r;         scanf( %d%d , &l, &r);         long long ans = 0LL;         for (int i = 0; i < 21; ++i)           ans += arr[i] * query(1, 0, n - 1, l - 1, r - 1, i);         printf( %lld n , ans);       } else {         int l, r, x;         scanf( %d%d%d , &l, &r, &x);         for (int i = 0; i < 21; ++i)           if (checkBit(x, i)) update(1, 0, n - 1, l - 1, r - 1, i);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, i, x, y, res;   vector<int> g[200200], o[200200];   bool u[3][200200], w[200200], ok = true;   char r[200200];   void dfs(int i, int z) {     u[z][i] = true;     w[i] = true;     for (int j = 0; j < g[i].size(); j++) {       int k = g[i][j];       if (w[k]) ok = false;       if (!u[z][k]) dfs(k, z);     }     w[i] = false;   }   void ofs(int i, int z) {     u[z][i] = true;     for (int j = 0; j < o[i].size(); j++) {       int k = o[i][j];       if (!u[z][k]) ofs(k, z);     }   }   int main() {     scanf( %d%d , &n, &m);     for (i = 0; i < m; i++) {       scanf( %d%d , &x, &y);       g[x].push_back(y);       o[y].push_back(x);     }     for (i = 1; ok && i <= n; i++)       if (!u[0][i]) dfs(i, 0);     if (!ok) {       puts( -1 );       return 0;     }     memset(u, 0, sizeof(u));     for (i = 1; i <= n; i++)       if (!u[0][i] && !u[1][i] && !u[2][i]) {         dfs(i, 0);         ofs(i, 0);         r[i - 1] =  A ;         res++;       } else {         r[i - 1] =  E ;         if (!u[1][i]) dfs(i, 1);         if (!u[2][i]) ofs(i, 2);       }     printf( %d n , res);     puts(r);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7, lim = 1e7 + 10, key = 1010;   int v[lim], r[lim], d[lim];   int main() {     int n, m, q;     scanf( %d%d%d , &n, &m, &q);     for (long long i = 1, _b = (n); i <= _b; i++)       for (long long j = 1, _b = (m); j <= _b; j++) scanf( %d , v + key * i + j);     for (long long i = 0, _b = (n); i <= _b; i++)       for (long long j = 0, _b = (m); j <= _b; j++) {         r[key * i + j] = key * i + (j + 1);         d[key * i + j] = key * (i + 1) + j;       }     int _a, _b, _c, _d, h, w;     int x, y, x0, y0;     for (long long i = 0, _n = (q); i < _n; i++) {       scanf( %d%d%d%d%d%d , &_a, &_b, &_c, &_d, &h, &w);       x0 = 0;       while (--_a) x0 = d[x0];       while (--_b) x0 = r[x0];       y0 = 0;       while (--_c) y0 = d[y0];       while (--_d) y0 = r[y0];       x = x0, y = y0;       for (long long j = 0, _n = (h); j < _n; j++)         x = d[x], y = d[y], swap(r[x], r[y]);       for (long long j = 0, _n = (w); j < _n; j++)         x = r[x], y = r[y], swap(d[x], d[y]);       x = x0, y = y0;       for (long long j = 0, _n = (w); j < _n; j++)         x = r[x], y = r[y], swap(d[x], d[y]);       for (long long j = 0, _n = (h); j < _n; j++)         x = d[x], y = d[y], swap(r[x], r[y]);     }     x0 = 0;     for (long long i = 0, _n = (n); i < _n; i++) {       x0 = d[x0];       x = x0;       for (long long j = 0, _n = (m); j < _n; j++) x = r[x], printf( %d  , v[x]);       putchar(  n );     }     return 0;   }


#include <bits/stdc++.h>   const int N = 200200;   using namespace std;   int n, k, s, t;   int c[N];   int v[N];   vector<int> g;   bool f(int x) {     long long cnt = s + s;     for (int i = 0; i + 1 < g.size(); i++) {       if (g[i + 1] - g[i] > x) return false;       int l = x - (g[i + 1] - g[i]);       cnt -= min(g[i + 1] - g[i], l);     }     return cnt <= t;   }   int main() {     ios_base::sync_with_stdio(0);     scanf( %d%d%d%d , &n, &k, &s, &t);     for (int i = 1; i <= n; i++) scanf( %d%d , &c[i], &v[i]);     g.push_back(0);     g.push_back(s);     for (int i = 1; i <= k; i++) {       int x;       scanf( %d , &x);       g.push_back(x);     }     sort(g.begin(), g.end());     int l = 0, r = 1e9 + 1;     while (l < r) {       int m = (l + r) / 2;       if (f(m))         r = m;       else         l = m + 1;     }     int ans = 1e9 + 1;     for (int i = 1; i <= n; i++)       if (v[i] >= l) ans = min(ans, c[i]);     if (ans == 1e9 + 1) ans = -1;     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int n, t, k, ret;   int a[N];   int sum[N];   int main() {     scanf( %d%d%d , &n, &t, &k);     int all = 0;     sum[0] = 1;     a[0] = 1;     for (int i = 1; i <= t; i++) {       scanf( %d , &a[i]);       sum[i] = sum[i - 1] + a[i];       if (a[i] < a[i - 1]) ret += a[i - 1] - a[i];     }     if (ret + a[t] > k || n - t < k) {       printf( -1 n );       return 0;     }     printf( %d n , n);     int fa = 1, now = 2;     int need = n - t - k;     for (int i = 1; i <= t; i++) {       while (now <= sum[i]) {         printf( %d %d n , fa, now);         if (fa != sum[i - 1] && now != sum[i] && need > 0) {           fa++;           need--;         }         now++;       }       fa = sum[i - 1] + 1;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, m, r0;     cin >> a >> b >> m >> r0;     int step = 0;     map<int, int> smap;     smap[r0] = 0;     while (true) {       r0 = r0 * a + b;       r0 %= m;       step++;       if (smap.find(r0) != smap.end()) {         cout << step - smap[r0];         break;       }       smap[r0] = step;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const int maxn = 100000 + 10;   struct Point {     double x, y;     Point() {}     Point(double x, double y) : x(x), y(y) {}   } inter;   struct Line {     int a, b, c, id;     Line() {}     Line(int a, int b, int c, int id) : a(a), b(b), c(c), id(id) {}   } e[maxn];   struct Node {     int x, y;     Node() {}     Node(int x, int y) : x(x), y(y) {}   } ans[10];   int n, k, cnt, tot, pos;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   inline int dcmp(double x) {     if (fabs(x) < eps) return 0;     return x < 0 ? -1 : 1;   }   bool judge(int l, int r) {     if (dcmp((double)e[l].a * e[r].b - (double)e[r].a * e[l].b) == 0) return 0;     inter = Point(((double)e[l].b * e[r].c - (double)e[l].c * e[r].b) /                       ((double)e[l].a * e[r].b - (double)e[r].a * e[l].b),                   ((double)e[l].a * e[r].c - (double)e[l].c * e[r].a) /                       ((double)e[l].b * e[r].a - (double)e[l].a * e[r].b));     return 1;   }   int main() {     n = read(), k = read();     for (int i = 1, a, b, c; i <= n; i++) {       a = read(), b = read(), c = read();       e[i] = Line(a, b, c, i);     }     cnt = n;     bool exis = 1;     while (cnt) {       if (k >= cnt) {         ans[++tot] = Node(e[cnt].id, -1);         cnt--;         continue;       }       for (pos = 1; pos <= 100; pos++) {         int a = rand() % cnt + 1, b = rand() % cnt + 1, sz = 0;         if (!judge(a, b)) continue;         for (int i = 1; i <= cnt; i++)           if (dcmp((double)e[i].a * inter.x + (double)e[i].b * inter.y +                    e[i].c) == 0)             sz++;         if (sz * k >= cnt) {           ans[++tot] = Node(e[a].id, e[b].id);           break;         }       }       if (pos > 100) {         exis = 0;         break;       }       for (int i = cnt; i >= 1; i--)         if (dcmp((double)e[i].a * inter.x + (double)e[i].b * inter.y +                  (double)e[i].c) == 0) {           swap(e[i], e[cnt]);           cnt--;         }       k--;     }     if (!exis)       puts( NO );     else {       puts( YES );       printf( %d n , tot);       for (int i = 1; i <= tot; i++) printf( %d %d n , ans[i].x, ans[i].y);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 3.14159265389793238462643383279502884197169;   const long long MOD = 1e9 + 7;   const int MAXN = 1e6 + 5;   const int oo = 1e9;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t, p;     cin >> t;     while (t--) {       cin >> p;       cout << 2 <<     << p - 1 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long double pi = 2 * acos(0.0);   long long infinity = std::numeric_limits<long long>::max();   long long binary_search(long long dp[], long long n, long long p) {     long long l, r, mid;     l = 0;     r = n - 1;     sort(dp, dp + n);     while (l <= r && l >= 0 && l <= n - 1 && r >= 0 && r <= n - 1) {       mid = (l + r) / 2;       if (dp[mid] >= p) {         r = mid - 1;       } else {         l = mid + 1;       }     }     return l;   }   struct order {     long long l, r;   };   bool compare(order o1, order o2) {     if (o1.l == o2.l)       return (o1.r < o2.r);     else       return (o1.l < o2.l);   }   bool check(order o1, order o2) { return (o1.r < o2.l); }   int main() {     long long t;     cin >> t;     while (t--) {       long long r, c, k, num_R = 0, i, j;       cin >> r >> c >> k;       char A[r][c];       for (i = 0; i < r; ++i)         for (j = 0; j < c; ++j) {           cin >> A[i][j];           num_R += (A[i][j] ==  R );         }       long long x = ceil((double)num_R / (double)k), a, b, c1 = 0, x_count = 0,                 y_count = 0;       char req = 48;       b = x * k - num_R;       a = k - b;       long long a1 = a, b1 = b, l = 0, f = 0;       for (i = 0; i < r; ++i) {         if (i % 2 == 0)           j = 0;         else           j = c - 1;         while ((i % 2 == 0 && j < c) || (i % 2 == 1 && j >= 0)) {           if (A[i][j] !=  R )             A[i][j] = req;           else {             A[i][j] = req;             ++c1;             if (c1 == x * a) {               c1 = 0;               x = x - 1;               a = b;               if (l == 1 || a == 0) {                 f = 1;                 break;               }               if (a != 0) ++req;               ++l;             } else if (c1 % x == 0) {               ++req;             }           }           if (i % 2 == 0)             ++j;           else             --j;           if (req == 58)             req = 65;           else if (req == 91)             req = 97;         }         if (f == 1) {           break;         }       }       for (i = 0; i < r; ++i) {         for (j = 0; j < c; ++j) {           if (A[i][j] !=  . )             cout << A[i][j];           else             cout << req;         }         cout <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double x, y, a, b, t;     while (cin >> a >> b) {       int n;       cin >> n;       double p = 1e18;       for (int i = 0; i < n; i++) {         cin >> x >> y >> t;         p = min(p, hypot((x - a), (y - b)) / t);       }       printf( %.20lf , p);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   long long a, b[100100], p[100100];   bool check(int num) {     long long gongfei = 0LL;     for (int i = n - num + 1; i <= n; i++) {       int j = i - (n - num);       if (b[i] < p[j]) {         gongfei += p[j] - b[i];       }     }     if (gongfei > a) return false;     return true;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m >> a;     for (int i = 1; i <= n; i++) {       cin >> b[i];     }     for (int i = 1; i <= m; i++) {       cin >> p[i];     }     sort(b + 1, b + n + 1);     sort(p + 1, p + m + 1);     int le = -1, ri = min(n, m) + 1;     int res = 0;     while (le + 1 < ri) {       int mi = (le + ri) / 2;       if (check(mi)) {         le = mi;       } else {         ri = mi;       }     }     long long tot = 0;     for (int i = 1; i <= le; i++) tot += p[i];     cout << le <<     << max(tot - a, 0LL) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10, P = 1e9 + 7;   int qpow(int a, int n) {     int ans = 1;     for (; n; a = a * (int64_t)a % P, n >>= 1)       if (n & 1) ans = ans * (int64_t)a % P;     return ans;   }   int fac[N], ifac[N], f[N];   int C(int n, int m) {     if (m > n) return 0;     return fac[n] * (int64_t)ifac[m] % P * ifac[n - m] % P;   }   int main() {     fac[0] = 1;     for (int i = 1; i < N; ++i) fac[i] = fac[i - 1] * (int64_t)i % P;     ifac[N - 1] = qpow(fac[N - 1], P - 2);     for (int i = N - 2; i >= 0; --i) ifac[i] = ifac[i + 1] * (i + 1ll) % P;     int n, m, k;     cin >> n >> m >> k;     if (m == 1) return cout << qpow(k, n) << endl, 0;     for (int i = 1; i <= min(n, k); ++i) {       for (int j = i; j >= 0; --j) {         int ret = (int64_t)C(i, j) * qpow(j, n) % P;         if (j % 2 == i % 2)           f[i] = (f[i] + ret) % P;         else           f[i] = (f[i] - ret) % P;       }     }     int ans = 0;     if (m == 2) {       for (int i = 1; i <= n; ++i) {         ans = (ans + C(k, i) * (int64_t)C(k, i) % P * f[i] % P * f[i]) % P;       }     } else {       for (int i = 1; i <= min(n, k); ++i) {         for (int j = 1; j <= i; ++j) {           ans = (ans + C(k, i) * (int64_t)C(i, j) % P * C(k - i, i - j) % P *                            f[i] % P * f[i] % P * qpow(j, n * (m - 2))) %                 P;         }       }     }     if (ans < 0) ans += P;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int t;     cin >> t;     while (t--) {       long long int n, m, x, y;       cin >> n >> m >> x >> y;       string s[n];       for (int a = 0; a < n; a++) cin >> s[a];       if (y > (2 * x)) y = 2 * x;       long long int xx, yy, zz, ans = 0;       for (int a = 0; a < n; a++) {         for (int b = 0; b < m; b++) {           if (s[a][b] ==  . ) {             if (b == m - 1)               ans += x;             else if (s[a][b + 1] ==  . ) {               ans += y;               b++;             } else               ans += x;           }         }       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n;   long long x[1005], y[1005];   set<pair<pair<long long, long long>, pair<long long, long long> > > S;   map<pair<long long, long long>, long long> mp;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main(void) {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> x[i] >> y[i];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i >= j) continue;         int s = i, t = j;         pair<pair<long long, long long>, pair<long long, long long> > l;         if (x[s] == x[t]) {           l = make_pair(make_pair(1, 0), make_pair(x[s], 1));         } else {           if (x[s] > x[t]) swap(s, t);           long long dx = x[t] - x[s], dy = y[t] - y[s];           long long d = gcd(abs(dx), abs(dy));           dx /= d, dy /= d;           l.first = make_pair(dy, dx);           long long bunsi = (dx * y[s] - dy * x[s]), bunbo = dx;           d = gcd(abs(bunsi), abs(bunbo));           bunsi /= d, bunbo /= d;           l.second = make_pair(bunsi, bunbo);         }         S.insert(l);       }     }     long long lnum = S.size();     for (auto it = S.begin(); it != S.end(); it++) mp[it->first]++;     long long ans = 0;     for (auto it = mp.begin(); it != mp.end(); it++) {       ans += it->second * (it->second - 1) / 2;     }     cout << lnum * (lnum - 1) / 2 - ans << endl;     return 0;   }


#include <bits/stdc++.h>   const long double ACOSPI = (acosl(-1.0));   using namespace std;   int main() {     int n = 0;     int i = 0;     int x = 0;     long long ans = 0;     map<int, long long> m;     int a = 0;     cin >> n >> x;     for (i = 0; i < n; i++) {       cin >> a;       ans += m[a];       m[x ^ a]++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }   int toInt(char xx) { return xx -  0 ; }   char toChar(int xx) { return xx +  0 ; }   int isDigit(char xx) { return ( 0  <= xx && xx <=  9 ); }   bool isCharacter(char xx) {     return (( a  <= xx && xx <=  z ) || ( A  <= xx && xx <=  Z ));   }   void swapInt(int &x, int &y) {     x = x ^ y;     y = x ^ y;     x = x ^ y;   }   const int dx[4] = {-1, 1, 0, 0};   const int dy[4] = {0, 0, -1, 1};   const int Mod = 9901;   const int maxn = 1e5 + 10;   int exitInput = 0;   int n;   int a[maxn], b[maxn], p[maxn];   void read() {     cin >> n;     int i;     for (i = 1; i <= n; ++i) {       cin >> a[i];     }     for (i = 1; i <= n; ++i) {       cin >> b[i];     }     for (i = 1; i <= n; ++i) {       p[a[i]] = b[i];     }   }   void init() {}   void solve() {     cout << p[1];     int i;     for (i = 2; i <= n; ++i) {       cout <<     << p[i];     }     cout << endl;   }   int main() {     ios_base::sync_with_stdio(0);     int ntest = 1;     int itest = 1;     for (itest = 1; itest <= ntest; ++itest) {       read();       if (exitInput) {         break;       }       init();       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Dev {     int p;     int e;     long double t;   } d[100000];   int n, p;   bool fun(long double midTime) {     long double energy = 0, t;     for (int i = 0; i < n; i++) {       t = midTime - d[i].t;       if (t > 0) energy += t * d[i].p;     }     return midTime * p >= energy;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> p;     long long sumPow = 0;     for (int i = 0; i < n; i++) {       cin >> d[i].p >> d[i].e;       d[i].t = (double)d[i].e / d[i].p;       sumPow += d[i].p;     }     if (sumPow <= p) {       cout << -1 << endl;       return 0;     }     long double minTime = 0;     long double maxTime = 1e18;     long double midTime;     for (int i = 0; i < 80; i++) {       midTime = (minTime + maxTime) / 2;       if (fun(midTime))         minTime = midTime;       else         maxTime = midTime;     }     if (midTime > 1e18 - 100)       cout << -1 << endl;     else       cout << midTime << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> build_z(const vector<int>& a) {     int n = (int)(a).size();     vector<int> z(n);     int l = 0, r = 0;     for (int i = 1; i < n; i++) {       z[i] = max(0, min(z[i - l], r - i));       while (i + z[i] < n && a[z[i]] == a[z[i] + i]) z[i]++;       if (i + z[i] > r) l = i, r = i + z[i];     }     return z;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0);     int n, m;     cin >> n >> m;     vector<int> a(n), b(m);     for (int i = 0; i < (int)(n); i++) cin >> a[i];     for (int i = 0; i < (int)(m); i++) cin >> b[i];     auto get_diff = [&](vector<int> a) {       vector<int> ret;       for (int i = 1; i < (int)(a).size(); i++) ret.push_back(a[i] - a[i - 1]);       return ret;     };     auto da = get_diff(a), db = get_diff(b);     vector<int> com = db;     com.push_back(1e9 + 7);     for (int i : da) com.push_back(i);     auto z = build_z(com);     int cnt = 0;     for (int i = m - 1; i < (int)(z).size(); i++) cnt += (z[i] == m - 1);     cout << cnt <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int i, a[n];     for (i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     i = 1;     while (a[i] == a[0]) {       i++;     }     if (i < n)       cout << a[i];     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int INF = 1e9 + 10;   int n, D[2020][2020];   int add(int& x, int y) { return x = (x + y) % MOD; }   int main() {     scanf( %d , &n);     int ans = 0;     D[0][0] = 1;     for (int i = 1; i <= 2 * n; i++) {       for (int j = 0; j <= i; j++) {         if (j > 0) add(D[i][j], D[i - 1][j - 1]);         add(D[i][j], D[i - 1][j + 1]);         if (i % 2 && 2 * n - i >= j) add(ans, D[i][j]);       }     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class abio {     static const unsigned BUF_SZ = 65536;     FILE *istream, *ostream;     char ibuf[BUF_SZ], obuf[BUF_SZ];     bool reached_eof;     size_t ip, isz;     size_t op, osz;     inline void clear_ibuf(void) { ip = isz = 0u; }     inline void clear_obuf(void) { op = osz = 0u; }     inline void clear_buffer(void) {       reached_eof = false;       clear_ibuf();       clear_obuf();     }     inline size_t read_buffer(void) {       isz = fread(ibuf, sizeof(char), BUF_SZ, istream);       ip = 0;       return isz;     }     inline size_t write_buffer(void) {       if (osz) {         size_t ret = fwrite(obuf + op, sizeof(char), osz - op, ostream);         op += ret;         if (op == osz) clear_obuf();         return ret;       }       return 0;     }     inline abio &reach_eof(void) {       reached_eof = true;       return (*this);     }       public:     static const char endl =   n ;     abio(FILE *input = stdin, FILE *output = stdout) {       this->istream = input;       this->ostream = output;       clear_buffer();     }     abio(const char *input, const char *output) {       this->istream = fopen(input,  r );       this->istream = fopen(output,  w+ );       clear_buffer();     }     ~abio(void) {       write_buffer();       fclose(istream);       fclose(ostream);     }     operator bool() const { return (!reached_eof); }     inline int getchar(void) {       if (0 == isz || isz == ip) read_buffer();       if (0 == isz || isz == ip) return EOF;       return ibuf[ip++];     }     inline int putchar(int ch) {       if (osz == BUF_SZ) write_buffer();       if (osz == BUF_SZ) return EOF;       return (obuf[osz++] = ch);     }     abio &read_int(int &x) {       int flag = 0, ch = getchar();       if (EOF == ch) return (this->reach_eof());       x = 0;       while ((EOF != ch) && (( -  != ch) && ((ch <  0 ) || (ch >  9 ))))         ch = getchar();       if (EOF == ch) return (this->reach_eof());       if ( -  == ch) {         flag = 1;         ch = getchar();       }       for (; (((ch >=  0 ) && (ch <=  9 ))); ch = getchar()) {         x *= 10;         x += (ch -  0 );       }       if (flag) x *= (-1);       return (*this);     }     abio &read_ll(long long int &x) {       int flag = 0, ch = getchar();       if (EOF == ch) return (this->reach_eof());       x = 0ll;       while ((EOF != ch) && (( -  != ch) && ((ch <  0 ) || (ch >  9 ))))         ch = getchar();       if (EOF == ch) return (this->reach_eof());       if ( -  == ch) {         flag = 1;         ch = getchar();       }       for (; (((ch >=  0 ) && (ch <=  9 ))); ch = getchar()) {         x *= (10ll);         x += (ch -  0 );       }       if (flag) x *= (-1);       return (*this);     }     abio &read_s(char *s, const char interrupt =    ) {       int ch = getchar();       while ((EOF != ch) && (ch <  !  || ch >  ~ )) ch = getchar();       if (EOF == ch) return (this->reach_eof());       for (; (EOF != ch) && (interrupt != ch) && (ch >=     && ch <=  ~ );            ch = getchar())         (*s++) = ch;       (*s) = 0;       return (*this);     }     abio &write_int(int x, char append = 0) {       int d[20], nd = 0;       if (0 == x) putchar( 0 );       if (x < 0) {         putchar( - );         x = -x;       }       while (x) {         d[nd++] = x % 10;         x /= 10;       }       while (nd--) putchar( 0  + d[nd]);       if (append) putchar(append);       return (*this);     }     abio &write_ll(long long int x, char append = 0) {       int d[20], nd = 0;       if (0 == x) putchar( 0 );       if (x < 0) {         putchar( - );         x = -x;       }       while (x) {         d[nd++] = x % 10;         x /= 10;       }       while (nd--) putchar( 0  + d[nd]);       if (append) putchar(append);       return (*this);     }     abio &write_s(const char *s, char append = 0) {       while (*s) putchar(*s++);       if (append) putchar(append);       return (*this);     }     abio &operator>>(char &ch) {       ch = getchar();       if (EOF == ch) return (this->reach_eof());       return (*this);     }     abio &operator>>(int &x) { return read_int(x); }     abio &operator>>(long long int &x) { return read_ll(x); }     abio &operator>>(char *s) { return read_s(s); }     abio &operator<<(const char ch) {       putchar(ch);       return (*this);     }     abio &operator<<(const int x) { return write_int(x); }     abio &operator<<(const long long int x) { return write_ll(x); }     abio &operator<<(const char *s) { return write_s(s); }   } io;   int n, s[100005];   int main() {     io >> n;     if (n > 26 || n < 2) {       io <<  Yes n  << io.endl;       return 0;     }     while (n--) {       char c;       io >> c;       s[c -  a ]++;       if (s[c -  a ] > 1) {         io <<  Yes n  << io.endl;         return 0;       }     }     io <<  No n  << io.endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int f[300000];   int a[40];   int add(int a, int b) { return (a + b >= m) ? a + b - m : a + b; }   void inc(int& a, int b) { a = (a + b >= m) ? a + b - m : a + b; }   int main(void) {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %d , &a[i]), a[i] %= m;     for (int i = 0, len = n / 2; i < (1 << len); i++) {       int t = 0;       for (int j = 0; j < len; j++)         if (i & (1 << j)) inc(t, a[j]);       f[i] = t;     }     sort(f, f + (1 << n / 2));     int cnt = unique(f, f + (1 << n / 2)) - f;     int ans = f[cnt - 1];     for (int i = 0, len = n - n / 2; i < (1 << len); i++) {       int t = 0;       for (int j = 0; j < len; j++)         if (i & (1 << j)) inc(t, a[j + n / 2]);       ans = max(ans, t);       int pos = lower_bound(f, f + cnt, m - 1 - t) - f;       for (int j = max(0, pos - 1); j <= pos + 1; j++) {         ans = max(ans, add(t, f[j]));       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int q;     cin >> q;     for (int d = 0; d < q; d++) {       string s, t;       cin >> s >> t;       int n = s.size();       int m = t.size();       n = n % 2;       m = m % 2;       int y = abs(n - m);       int j = 0;       for (int i = y; i < s.size(); i++) {         if (s[i] == t[j]) {           j++;         } else {           i++;         }         if (j == t.size()) {           break;         }       }       if (j == t.size()) {         cout <<  YES  <<   n ;         ;       } else {         cout <<  NO  <<   n ;         ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 110;   int a[N], b[N];   int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i <= n; i++) scanf( %d , &a[i]);     for (int i = 0; i <= m; i++) scanf( %d , &b[i]);     if (n > m) {       if (a[0] * b[0] > 0)         puts( Infinity );       else         puts( -Infinity );     } else if (n < m) {       printf( 0/1 n );     } else {       if (a[0] > 0 && b[0] > 0 || a[0] < 0 && b[0] < 0) {         a[0] = abs(a[0]);         b[0] = abs(b[0]);         int t = gcd(a[0], b[0]);         a[0] /= t;         b[0] /= t;         printf( %d/%d n , a[0], b[0]);       } else {         a[0] = abs(a[0]);         b[0] = abs(b[0]);         int t = gcd(a[0], b[0]);         a[0] /= t;         b[0] /= t;         printf( -%d/%d n , a[0], b[0]);       }     }     return 0;   }


#include <bits/stdc++.h>   template <class T>   void read(T &a) {     a = 0;     char x = getchar();     bool f = 0;     for (; x <  0  || x >  9 ; x = getchar()) f |= x ==  - ;     for (; x >=  0  && x <=  9 ; x = getchar()) a = (a << 3) + (a << 1) + x -  0 ;     if (f) a = -a;   }   template <class T, class... Args>   void read(T &a, Args &...args) {     read(a);     read(args...);   }   using namespace std;   const int N = 2e5 + 5;   int n;   int f[N], lim;   pair<int, int> d[N];   bool cmp(pair<int, int> a, pair<int, int> b) {     if (a.first ^ b.first) {       return a.first < b.first;     }     return a.second > b.second;   }   int main() {     read(n);     for (int i = 1; i <= n; ++i) {       read(d[i].first);       d[i].second = i;     }     sort(d + 1, d + n + 1, cmp);     int lim = 0;     for (int i = 1; i <= n; ++i) {       int c = d[i].second - d[i].first;       if (c < 0) continue;       if (lim == 0) {         f[++lim] = c;         continue;       }       if (c >= f[lim]) {         f[++lim] = c;         continue;       }       int l = 1, r = lim + 1;       while (l < r - 1) {         int mid = l + r >> 1;         if (f[mid] <= c) {           l = mid;         } else {           r = mid;         }       }       if (f[l] > c) {         f[l] = c;       } else if (l != lim) {         f[l + 1] = c;       }     }     printf( %d n , lim);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mo = 998244353;   long long bin_fun(long long chto, long long vkak) {     if (vkak == 0) return 1;     if (vkak == 1) return chto;     if (vkak % 2 == 0)       return bin_fun(chto * chto % mo, vkak / 2);     else       return (bin_fun(chto * chto % mo, vkak / 2) * chto) % mo;   }   int main() {     long long a, s, d, i, j, k;     cin >> a;     vector<long long> v1;     for (i = 0; i < a * 2; i++) {       cin >> s;       v1.push_back(s);     }     sort(v1.begin(), v1.end());     long long sum = 0;     for (i = 0; i < a; i++) sum = (sum + abs(v1[a * 2 - i - 1] - v1[i])) % mo;     long long ch1 = 1, ch2 = 1;     for (i = a + 1; i <= a * 2; i++) {       ch1 = (ch1 * i) % mo;     }     for (i = 1; i <= a; i++) {       long long t = bin_fun(i, mo - 2);       ch2 = (ch2 * t) % mo;     }     long long otv = (ch1 * ch2) % mo;     cout << (otv * sum) % mo;   }


#include <bits/stdc++.h>   using namespace std;   int x, y, z, X, Y, Z, A, B, C, D, E, F;   int main() {     cin >> X >> Y >> Z >> x >> y >> z >> A >> B >> C >> D >> E >> F;     cout << A * (Y < 0) + B * (Y > y) + C * (Z < 0) + D * (Z > z) + E * (X < 0) +                 F * (X > x)          <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   inline char gc() { return getchar(); }   template <class T>   int read(T &ans) {     ans = 0;     char ch = gc();     T f = 1;     while (!isdigit(ch)) {       if (ch == EOF) return -1;       if (ch ==  - ) f = -1;       ch = gc();     }     while (isdigit(ch)) ans = ans * 10 + ch -  0 , ch = gc();     ans *= f;     return 1;   }   template <class T1, class T2>   int read(T1 &a, T2 &b) {     return read(a) != EOF && read(b) != EOF ? 2 : EOF;   }   template <class T1, class T2, class T3>   int read(T1 &a, T2 &b, T3 &c) {     return read(a, b) != EOF && read(c) != EOF ? 3 : EOF;   }   const int Maxn = 1100000;   const int inf = 0x3f3f3f3f;   int n, m, D, to[Maxn], nxt[Maxn], first[Maxn], tot = 1;   int vis[Maxn], d[Maxn], u, v, cnt;   queue<int> q;   vector<int> vi[Maxn];   inline void add(int u, int v) {     to[tot] = v;     nxt[tot] = first[u];     first[u] = tot++;     to[tot] = u;     nxt[tot] = first[v];     first[v] = tot++;   }   void dfs(int root) {     vis[root] = cnt;     for (int i = first[root]; i; i = nxt[i])       if (!vis[to[i]]) dfs(to[i]);   }   signed main() {     read(n, m, D);     for (int i = 1; i <= m; i++) {       read(u, v);       add(u, v);       d[u]++;       d[v]++;     }     if (d[1] >= D && D) {       vis[1] = ++cnt;       for (int i = first[1]; i; i = nxt[i])         if (vis[to[i]])           vi[vis[to[i]]].push_back(to[i]);         else           cnt++, dfs(to[i]), vi[cnt].push_back(to[i]);       if (cnt - 1 > D)         puts( NO );       else {         memset(vis, 0, sizeof(vis));         vis[1] = 1;         puts( YES );         for (int i = 2; i <= cnt; i++)           printf( 1 %d n , vi[i][0]), vis[vi[i][0]] = 1, q.push(vi[i][0]);         D -= cnt - 1;         for (int i = 2; i <= cnt; i++) {           for (int j = 1; j < vi[i].size(); j++) {             if (!D) break;             D--;             printf( 1 %d n , vi[i][j]);             vis[vi[i][j]] = 1;             q.push(vi[i][j]);           }         }         while (!q.empty()) {           int now = q.front();           q.pop();           for (int i = first[now]; i; i = nxt[i])             if (!vis[to[i]]) {               vis[to[i]] = 1;               printf( %d %d n , now, to[i]);               q.push(to[i]);             }         }       }     } else       puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct note {     int a, b, x;   } a[100005 * 2];   long long ansa, ansb;   int n;   int tot;   bool cmp(note i, note j) { return i.x > j.x; }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       long long a1, b, c, d;       scanf( %I64d%I64d%I64d%I64d , &a1, &b, &c, &d);       if (a1 <= d && b <= c) continue;       if (a1 + b > c + d) {         a[++tot].a = a1;         a[tot].b = b;         a[tot].x = a1 + b;         a[++tot].a = c;         a[tot].b = d;         a[tot].x = c + d;       } else {         if (a1 > d) {           ansa += a1;           ansb += d;         } else {           ansa += c;           ansb += b;         }       }     }     sort(a + 1, a + tot + 1, cmp);     for (int i = 1; i <= tot; i++) {       if (i % 2 == 1)         ansa += a[i].a;       else         ansb += a[i].b;     }     printf( %I64d , ansa - ansb);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n % 2 == 0) {       cout <<  NO ;     } else {       cout <<  YES n ;       int i = 1;       int a[2 * n];       for (int j = 0; j < n; j++) {         a[j] = i;         if (j % 2 == 0) {           a[j + n] = i + 1;           i += 3;         } else {           a[j + n] = i - 1;           i++;         }       }       for (int j = 0; j < 2 * n; j++) {         cout << a[j] <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j, ans = 0;     cin >> n;     pair<int, int> p[n];     int ab, be, le, ri;     for (i = 0; i < n; i++) {       int r, s;       cin >> r >> s;       p[i] = make_pair(r, s);     }     for (i = 0; i < n; i++) {       ab = 0, be = 0, le = 0, ri = 0;       for (j = 0; j < n; j++) {         if (i == j) {           continue;         }         if (p[i].first == p[j].first) {           if (p[i].second < p[j].second) {             ab++;           } else {             be++;           }         }         if (p[i].second == p[j].second) {           if (p[i].first < p[j].first) {             ri++;           } else {             le++;           }         }         if (ab > 0 && be > 0 && le > 0 && ri > 0) {           ans++;           break;         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>       using namespace std;       #define endl   n    #define ll long long   #define fr(i,s,e) for(ll i=s;i<=e;i++)   #define rfr(i,s,e) for(ll i=s;i>=e;i--)   #define f(x,m) for(auto x : m)   #define ff first   #define ss second   #define pb push_back   #define pp pop_back   #define pf push_front   #define ppf pop_front   #define m_p make_pair   #define mod 1000000007   #define TIME cerr<< Time Taken: <<(float)clock()/CLOCKS_PER_SEC*1000<< ms <<endl       const ll INF = (1LL << 60) - 1;       int main()   {       #ifndef ONLINE_JUDGE    freopen( ../input-output/input.txt ,  r , stdin);    freopen( ../input-output/output.txt ,  w , stdout);   #endif    ios_base::sync_with_stdio(false);       cin.tie(NULL);        int t;    cin>>t;    while(t--){     ll r,b,d;     cin>>r>>b>>d;     int noPackets=min(r,b);     r=max(r,b)-min(r,b);     // cout<<r<<   ;     if(noPackets==0){      cout<< NO n ;      continue;     }     ll maxdiff=r/noPackets;     if(r%noPackets) maxdiff++;     // cout<<maxdiff<<endl;     if(maxdiff<=d) cout<< YES n ;     else cout<< NO n ;    }        TIME;    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, i, j, r[55];   long long m, f[55];   void solve(int n, int p, long long m) {     if (n == 0) return;     for (int i = 1; i <= n && i <= 2; i++) {       if (m <= f[n - i]) {         solve(n - i, p + i, m);         for (int j = p + i; j <= N; j++) r[j] += i;         for (int j = p + i - 1, k = 1; j >= p; j--, k++) r[j] = k;         break;       } else         m -= f[n - i];     }   }   int main() {     cin >> N >> m;     for (f[0] = i = 1; i <= N; i++)       for (j = 1; j <= i && j <= 2; j++) f[i] = min(m + 1, f[i] + f[i - j]);     solve(N, 1, m);     for (i = 1; i <= N; i++) printf( %d%c , r[i], i == N ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll MOD = 1e9 + 7, N = 1e5 + 10;   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     ll a[3];     cin >> a[0] >> a[1] >> a[2];     cout <<  First  << endl;     vector<ll> b(3);     iota(b.begin(), b.end(), 0);     sort(b.begin(), b.end(), [&](ll u, ll v) { return a[u] < a[v]; });     sort(a, a + 3);     cout << 2 * a[2] - a[1] - a[0] << endl;     ll x;     cin >> x;     --x;     if (x == -1) return 0;     if (x == b[0]) {       cout << a[2] - a[1] << endl;       cin >> x;       return 0;     } else if (x == b[1]) {       cout << a[2] - a[0] << endl;       cin >> x;       return 0;     }     cout << 6 * a[2] - 3 * a[1] - 3 * a[0] << endl;     cin >> x;     --x;     if (x == -1) return 0;     if (x == b[0]) {       cout << 3 * a[2] - a[0] - a[1] - a[1] << endl;       cin >> x;       return 0;     }     cout << 3 * a[2] - a[0] - a[1] - a[0] << endl;     cin >> x;     return 0;   }


#include <bits/stdc++.h>   const long long RXD = 1e9 + 7;   const long long N = 1e5 + 1000;   using namespace std;   long long C[N][110], a[N], s[N][110], n, m, l, r, K;   long long read() {     long long x = 0, f = 1, c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return x * f;   }   int main() {     C[0][0] = 1;     for (long long i = 1; i <= 100100; i++)       for (long long j = 0; j <= i && j <= 105; j++)         C[i][j] = (j == 0) ? 1 : (C[i - 1][j] + C[i - 1][j - 1]) % RXD;     n = read();     m = read();     for (long long i = 1; i <= n; i++) a[i] = read();     for (long long i = 1; i <= m; i++) {       l = read();       r = read();       K = read();       for (long long i = 0; i <= K; i++) s[l][i] = (s[l][i] + C[K][K - i]) % RXD;       for (long long i = 0; i <= K; i++)         s[r + 1][i] = (s[r + 1][i] - C[K + r + 1 - l][K - i] + RXD) % RXD;     }     for (long long i = 1; i <= n; i++)       for (long long j = 101; j; j--)         s[i + 1][j - 1] = ((s[i + 1][j - 1] + s[i][j]) % RXD + s[i][j - 1]) % RXD;     for (long long i = 1; i <= n; i++)       printf( %d  , ((a[i] + s[i][0]) % RXD + RXD) % RXD);   }


#include <bits/stdc++.h>   using namespace std;   void readi(int &x) {     int v = 0, f = 1;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = v * 10 + c -  0 ;     while (isdigit(c = getchar())) v = v * 10 + c -  0 ;     x = v * f;   }   void readll(long long &x) {     long long v = 0ll, f = 1ll;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = v * 10 + c -  0 ;     while (isdigit(c = getchar())) v = v * 10 + c -  0 ;     x = v * f;   }   void readc(char &x) {     char c;     while ((c = getchar()) ==    )       ;     x = c;   }   void writes(string s) { puts(s.c_str()); }   void writeln() { writes(  ); }   void writei(int x) {     if (!x) putchar( 0 );     char a[25];     int top = 0;     while (x) {       a[++top] = (x % 10) +  0 ;       x /= 10;     }     while (top) {       putchar(a[top]);       top--;     }   }   void writell(long long x) {     if (!x) putchar( 0 );     char a[25];     int top = 0;     while (x) {       a[++top] = (x % 10) +  0 ;       x /= 10;     }     while (top) {       putchar(a[top]);       top--;     }   }   int fa[100005], n, m, i, j, x;   set<int> s;   int find(int x) {     if (fa[x] == x) return x;     return fa[x] = find(fa[x]);   }   int main() {     cin >> n;     for (i = 1; i <= n; i++) fa[i] = i;     for (i = 1; i <= n; i++) {       cin >> x;       fa[find(x)] = find(i);     }     for (i = 1; i <= n; i++) s.insert(find(i));     cout << s.size();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int toInt(string s) {     int v;     istringstream sin(s);     sin >> v;     return v;   }   template <class T>   string toString(T x) {     ostringstream sout;     sout << x;     return sout.str();   }   vector<string> form(string a, char s) {     a += s;     vector<string> v;     string b;     for (int i = (0); i < (int)(a.size()); ++i) {       if (a[i] == s) {         v.push_back(b);         b =   ;       } else         b += a[i];     }     return v;   }   vector<int> formint(string a, char s) {     vector<int> v;     vector<string> w = form(a, s);     for (int i = (0); i < (int)(w.size()); ++i) v.push_back(toInt(w[i]));     return v;   }   const int mod = 1000000007;   int aa[2048];   int bb[2048];   int pows(int a, int b) {     if (b == 0) return 1;     int k = pows(a, b / 2);     k = ((long long)k * k) % mod;     if (b % 2 == 1) k = ((long long)k * a) % mod;     return k;   }   int divs(int a, int b) { return (((long long)a) * pows(b, mod - 2)) % mod; }   int combi(int a, int b) {     int res = 1;     if (a / 2 < b) b = a - b;     for (int i = a, j = 0; j < b; i--, j++) res = (((long long)res) * i) % mod;     for (int i = 2; i <= b; i++) res = divs(res, i);     return res;   }   int main(void) {     int n, k;     cin >> n >> k;     for (int i = (0); i < (int)(n); ++i) cin >> aa[i];     if (k == 0) {       for (int i = (0); i < (int)(n); ++i) {         if (i > 0) cout <<    ;         cout << aa[i];       }       cout << endl;       return 0;     }     for (int i = (0); i < (int)(n); ++i) bb[i] = combi(k + i - 1, i);     for (int i = (0); i < (int)(n); ++i) {       if (i != 0) cout <<    ;       int res = 0;       for (int j = (0); j < (int)(i + 1); ++j) {         res = (res + ((long long)aa[j] * bb[i - j]) % mod) % mod;       }       cout << res;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   template <class T>   void setmax(T &a, T b) {     if (a < b) a = b;   }   template <class T>   void setmin(T &a, T b) {     if (b < a) a = b;   }   using namespace std;   void read(long long &x) { scanf( %lld , &x); }   void read(long long &x, long long &y) { scanf( %lld %lld , &x, &y); }   void read(long long &x, long long &y, long long &z) {     scanf( %lld %lld %lld , &x, &y, &z);   }   void read(long long &x, long long &y, long long &z, long long &w) {     scanf( %lld %lld %lld %lld , &x, &y, &z, &w);   }   void read(vector<long long> &oneD) {     for (long long i = 0; i < oneD.size(); i++) {       read(oneD[i]);     }   }   void read(vector<vector<long long> > &twoD) {     for (long long i = 0; i < twoD.size(); i++) {       read(twoD[i]);     }   }   void write(vector<long long> &oneD) {     for (long long i = 0; i < oneD.size(); i++) {       printf( %lld  , oneD[i]);     }     printf(  n );   }   void write(vector<vector<long long> > &twoD) {     for (long long i = 0; i < twoD.size(); i++) {       write(twoD[i]);     }   }   void write(vector<pair<long long, long long> > &oneDP) {     for (long long(i) = 0; (i) < (oneDP.size()); ++(i)) {       printf( %lld %lld n , oneDP[i].first, oneDP[i].second);     }     cout <<   n ;   }   void write(map<long long, long long> &mpp) {     for (map<long long, long long>::iterator it = mpp.begin(); it != mpp.end();          it++) {       cout << it->first <<   :   << it->second <<   n ;     }     cout <<   n ;   }   bool cmp(const pair<long long, long long> &a,            const pair<long long, long long> &b) {     if (a.first == b.first) return (a.second >= b.second);     return (a.first < b.first);   }   long long A[100005];   vector<long long> seive;   vector<long long> primes;   void Seive() {     const long long maxn = 100005;     seive.resize(maxn);     for (long long(i) = 0; (i) < (maxn); ++(i)) seive[i] = 1;     for (long long i = 2; i * i < maxn; i++) {       if (seive[i] == 1) {         for (long long j = i * i; j < maxn; j += i) {           seive[j] = 0;         }       }     }     primes.push_back(2);     for (long long i = 3; i < maxn; i += 2) {       if (seive[i]) primes.push_back(i);     }   }   void printprime(long long l, long long r) {     if (l < 2) l = 2;     bool isprime[r - l + 1];     for (long long(i) = 0; (i) < (r - l + 1); ++(i)) isprime[i] = true;     for (int i = 0; primes[i] * primes[i] <= r; i++) {       long long base = (l / primes[i]) * primes[i];       if (base < l) {         base = base + primes[i];       }       for (long long j = base; j <= r; j += primes[i]) {         isprime[j - l] = false;       }       if (base == primes[i]) isprime[base - l] = true;     }     for (int i = 0; i < r - l + 1; i++) {       if (isprime[i] == true) cout << i + l <<   n ;     }   }   long long isprime(long long N) {     if (N < 2 || (!(N & 1) && N != 2)) return 0;     for (long long i = 3; i * i <= N; i += 2) {       if (!(N % i)) return 0;     }     return 1;   }   long long mulmod(long long a, long long b, long long mod) {     long long res = 0;     a = a % mod;     while (b > 0) {       if (b % 2 == 1) res = (res + a) % mod;       a = (a * 2) % mod;       b /= 2;     }     return res % mod;   }   long long power(long long x, long long y, long long m) {     long long int res = 1;     x = x % m;     while (y > 0) {       if (y & 1) res = mulmod(res, x, m);       y = y >> 1;       x = mulmod(x, x, m);     }     return res;   }   long long modinv(long long x, long long mod = 1000000007) {     return power(x, mod - 2, mod);   }   long long B[100001];   long long C[100001];   long long D[100001];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long a, b, c, d;     long long k, l, m, n, p, q, r, s, t, x, y;     cin >> n;     vector<pair<long long, long long> > v(n);     long long mx1 = 0, mx2 = 0;     long long s1 = 0, s2 = 0;     for (long long(i) = 0; (i) < (n); ++(i)) {       cin >> A[i] >> B[i];     }     sort(A, A + n);     sort(B, B + n);     for (long long(i) = 0; (i) < (n); ++(i)) {       mx1 += max(A[i], B[i]);     }     mx1 += n;     cout << mx1 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long double EPS = 1e-6;   const int INF = (int)(INT_MAX - 100);   const long long mod = (int)(1e+9 + 7);   const int N = (int)(1e5);   int main() {     int n, s;     cin >> n >> s;     char d;     int p, k;     map<int, int, greater<int> > C;     map<int, int> V;     for (int i = 0; i < n; i++) {       cin >> d >> p >> k;       if (d ==  B )         C[p] += k;       else         V[p] += k;     }     k = 0;     vector<pair<int, int> > ans;     for (pair<int, int> x : V) {       if (k == s) break;       k++;       ans.push_back({x.first, x.second});     }     reverse(ans.begin(), ans.end());     for (pair<int, int> x : ans)       cout <<  S   << x.first <<     << x.second <<   n ;     k = 0;     for (pair<int, int> x : C) {       if (k == s) break;       k++;       cout <<  B   << x.first <<     << x.second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<string> V;     for (int i = 0; i < 4; ++i) {       string s;       cin >> s;       V.push_back(s);     }     bool pos = false;     for (int r = 0; r < 3; ++r) {       for (int c = 0; c < 3; ++c) {         int dots = 0, nums = 0;         dots += (V[r][c] ==  . );         nums += (V[r][c] !=  . );         dots += (V[r][c + 1] ==  . );         nums += (V[r][c + 1] !=  . );         dots += (V[r + 1][c] ==  . );         nums += (V[r + 1][c] !=  . );         dots += (V[r + 1][c + 1] ==  . );         nums += (V[r + 1][c + 1] !=  . );         if (dots >= 3 || nums >= 3) pos = true;       }     }     cout << (pos ?  YES  :  NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[1010];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d%d , &a[i].second, &a[i].first);       if (a[i].first < a[i].second) swap(a[i].first, a[i].second);     }     sort(a, a + n);     vector<int> ans;     int last = INT_MIN;     for (int i = 0; i < n; ++i)       if (a[i].second > last) {         ans.push_back(a[i].first);         last = a[i].first;       }     printf( %d n , (int)ans.size());     for (int c : ans) printf( %d  , c);     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   long long cd, w, a, b, kq = 0, mod = 1e9 + 7, fact[1000001], sf[1000001],                          p[1000001];   void inp() { cin >> cd >> w >> a >> b; }   long long bigmod(long long hat, long long base) {     if (hat == 0) return 1;     long long k = bigmod(hat / 2, base);     if (hat % 2 == 1) return k * k % mod * base % mod;     return k * k % mod;   }   void create() {     p[0] = fact[0] = sf[0] = 1;     for (long long i = 1; i <= 1000000; i++) {       fact[i] = fact[i - 1] * i % mod;       sf[i] = bigmod(mod - 2, fact[i]);       p[i] = p[i - 1] * w % mod;     }   }   long long C(long long k, long long n) {     if (k > n) return 0;     return fact[n] * sf[k] % mod * sf[n - k] % mod;   }   long long A(long long k, long long n) {     if (k > n) return 0;     return C(k, n) * fact[k] % mod;   }   long long cayley(long long k, long long n) {     if (n == k) return 1;     return k * bigmod(n - k - 1, n) % mod;   }   long long get(long long node) {     return A(node, cd - 2) * cayley(node + 2, cd) % mod * p[cd - node - 2] % mod *            C(node, w - 1) % mod;   }   void do_it() {     create();     for (long long i = 0; i <= cd - 2; i++) kq += get(i), kq %= mod;     cout << kq;   }   int main() {     inp();     do_it();   }


#include <bits/stdc++.h>   const int N = 1e3 + 10;   using namespace std;   int a[N], b[N], c[N];   char str1[N], str2[N], str3[N];   int main() {     int tc;     cin >> tc;     while (tc--) {       long long n, k, sum{0}, suma{0}, sumb{0};       cin >> n >> k;       for (int i = 0; i < n; ++i) {         cin >> a[i];         suma += a[i];       }       for (int i = 0; i < n; ++i) {         cin >> b[i];         sumb += b[i];       }       if (k > 0) {         for (int i = 0; i < n; ++i) {           for (int j = i; j < n - 1; ++j) {             if (a[i] >= a[j + 1]) swap(a[i], a[j + 1]);             if (b[i] <= b[j + 1]) swap(b[i], b[j + 1]);           }         }         for (int i = 0; i < k; ++i) {           if (a[i] < b[i]) swap(a[i], b[i]);         }         for (int i = 0; i < n; ++i) {           sum += a[i];         }         cout << sum <<   n ;       } else         cout << suma <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[3], b[3];   int main() {     int n, m;     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       int c;       cin >> c;       a[c % 2]++;     }     for (int j = 1; j <= m; ++j) {       int c;       cin >> c;       b[c % 2]++;     }     cout << min(a[1], b[0]) + min(b[1], a[0]) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n1, n2, k1, k2;     cin >> n1 >> n2 >> k1 >> k2;     if (n1 > n2) {       cout <<  First  << endl;       return 0;     }     if (n2 > n1) {       cout <<  Second  << endl;       return 0;     }     if (k1 < k2) {       cout <<  Second  << endl;       return 0;     }     if (k2 < k1) {       cout <<  Second  << endl;       return 0;     }     if (n1 == n2 && k1 == k2) {       cout <<  Second  << endl;       return 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005, maxl = 200005, maxsg = 60;   int n, f, SG, cnt, maxx;   int p[maxl], c[maxl], sg[maxl], A[maxn], B[maxn];   bitset<maxl> ok, have[maxsg];   void sieve(int n) {     c[1] = 1;     for (int i = 2; i <= n; i++) {       if (c[i] == 0) p[++cnt] = i, ok[i] = 1;       for (int j = 1; j <= cnt; j++) {         if (i * p[j] > n) break;         c[i * p[j]] = 1;         if (c[i] == 0) ok[i * p[j]] = 1;         if (i % p[j] == 0) break;       }     }   }   int main() {     scanf( %d%d , &n, &f);     for (int i = 1; i <= n; i++) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       A[i] = y - x - 1, B[i] = z - y - 1;       maxx = max(maxx, max(A[i], B[i]));     }     sieve(maxx), ok[f] = 0, have[0] = ok;     for (int i = 1; i <= maxx; i++) {       while (have[sg[i]][i]) sg[i]++;       have[sg[i]] |= (ok << i);     }     for (int i = 1; i <= n; i++) SG ^= sg[A[i]] ^ sg[B[i]];     if (SG == 0)       puts( Bob nAlice );     else       puts( Alice nBob );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void logf(istream_iterator<string> it) {}   template <typename T, typename... Args>   void logf(istream_iterator<string> it, T a, Args... args) {     cout << *it <<  =  << a <<    ;     logf(++it, args...);   }   const double PI = acos(-1);   void solve() {     string s;     cin >> s;     ;     reverse(s.begin(), s.end());     int ans = 0;     int car = 0;     function<void(int)> inc = [&](int idx) {       if (idx == s.size())         s +=  1 ;       else {         if (s[idx] ==  1 ) {           s[idx] =  0 ;           inc(idx + 1);         } else           s[idx] =  1 ;       }     };     for (size_t i = 0; i + 1 < s.size(); i++) {       if (s[i] ==  1 ) {         inc(i);         ans++;       }       if (i + 1 < s.size()) ans++;     }     cout << ans << endl;   }   int main() {     cin.tie(nullptr);     std::ios::sync_with_stdio(false);     solve();   }


#include <bits/stdc++.h>   using namespace std;   int n, q;   int m;   int lastans;   int a[1000][700];   int b[100100];   int sz[1000];   short int cnt[1000][100100];   void remake() {     int pos = 0;     for (int i = 0; i <= m; i++) {       sz[i] = 0;       for (int j = 0; j < 700; a[i][j] = 0, j++) {         if (a[i][j] == -1 || a[i][j] == 0) continue;         cnt[i][a[i][j]]--;         b[pos] = a[i][j];         pos++;       }     }     for (int i = 0; i < n; i++) {       a[i / 333][i % 333] = b[i];       cnt[i / 333][b[i]]++;       sz[i / 333]++;     }   }   int find(int it, int pos) {     int i = 0;     pos--;     while (pos || a[it][i] == -1) {       if (a[it][i] == -1) pos++;       pos--;       i++;     }     int res = a[it][i];     a[it][i] = -1;     return res;   }   void update(int it, int pos, int k) {     pos--;     int t = sz[it] - pos;     int i = 0;     while (pos || a[it][i] == -1) {       if (a[it][i] == -1) pos++;       pos--;       i++;     }     int buf = a[it][i];     a[it][i] = k;     while (t) {       i++;       if (buf != -1) t--;       swap(a[it][i], buf);     }   }   int solve(int r, int k) {     int res = 0;     int pos = 0;     int it = 0;     while (it <= m && sz[it] <= r) {       r -= sz[it];       res += cnt[it][k];       it++;     }     int i = 0;     while (pos < r) {       if (a[it][i] == -1 || a[it][i] == 0) {         i++;         continue;       }       res += (a[it][i] == k);       i++;       pos++;     }     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i / 333][i % 333];       cnt[i / 333][a[i / 333][i % 333]]++;       sz[i / 333]++;     }     m = (n - 1) / 333 + 1;     cin >> q;     while (q--) {       int type, l, r, k;       cin >> type >> l >> r;       l = (l + lastans - 1) % n + 1;       r = (r + lastans - 1) % n + 1;       if (l > r) swap(l, r);       if (type == 1) {         int it = 0;         int pos = 0;         while (pos < l) {           pos += sz[it];           it++;         }         if (pos >= l) {           it--;           pos -= sz[it];         }         int p1 = pos;         int w = it;         it = 0;         pos = 0;         while (pos < r) {           pos += sz[it];           it++;         }         if (pos >= r) {           it--;           pos -= sz[it];         }         k = find(it, r - pos);         cnt[w][k]++;         cnt[it][k]--;         sz[w]++;         sz[it]--;         update(w, l - p1, k);         if (sz[w] > 2 * 333) remake();       } else {         cin >> k;         k = (k + lastans - 1) % n + 1;         lastans = solve(r, k) - solve(l - 1, k);         printf( %d n , lastans);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-11;   const int INFINITE = 0x3f3f3f3f;   template <class T>   inline void checkmin(T &a, T b) {     if (b < a) a = b;   }   template <class T>   inline void checkmax(T &a, T b) {     if (b > a) a = b;   }   template <class T>   inline T sqr(T x) {     return x * x;   }   template <class T>   inline T lowbit(T n) {     return (n ^ (n - 1)) & n;   }   template <class T>   inline int countbit(T n) {     return (n == 0) ? 0 : (1 + countbit(n & (n - 1)));   }   typedef vector<int> VI;   typedef vector<VI> VII;   typedef vector<string> VS;   int dx[4] = {1, 0, 0, -1};   int dy[4] = {0, 1, -1, 0};   bool isright(int x1, int y1, int x2, int y2, int x3, int y3) {     int l12 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);     int l23 = (x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3);     int l31 = (x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1);     if (l12 == 0 || l23 == 0 || l31 == 0) return false;     return (l12 + l23 == l31 || l12 + l31 == l23 || l23 + l31 == l12);   }   int main() {     ios::sync_with_stdio(false);     int p[3][2];     cin >> p[0][0] >> p[0][1] >> p[1][0] >> p[1][1] >> p[2][0] >> p[2][1];     if (isright(p[0][0], p[0][1], p[1][0], p[1][1], p[2][0], p[2][1])) {       cout <<  RIGHT n ;       return 0;     }     for (int n = (int)(0); n < (int)(3); n++)       for (int i = (int)(0); i < (int)(4); i++) {         p[n][0] += dx[i], p[n][1] += dy[i];         if (isright(p[0][0], p[0][1], p[1][0], p[1][1], p[2][0], p[2][1])) {           cout <<  ALMOST n ;           return 0;         }         p[n][0] -= dx[i], p[n][1] -= dy[i];       }     cout <<  NEITHER n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll mod = 998244353;   int n, m, t[1 << 19];   struct segTree {     struct {       ll kk, bk, kb, bb;     } a[1 << 20];     void upd(int p, int l, int r) {       int mid = l + r >> 1, v = t[mid] == 1 ? 9 - t[mid + 1] : 0;       a[p].kk = a[p * 2].kb * a[p * 2 + 1].bk % mod;       if (l < mid && mid + 1 < r)         (a[p].kk += a[p * 2].kk * a[p * 2 + 1].kk % mod * v) %= mod;       a[p].bk = a[p * 2].bb * a[p * 2 + 1].bk % mod;       if (mid + 1 < r)         (a[p].bk += a[p * 2].bk * a[p * 2 + 1].kk % mod * v) %= mod;       a[p].kb = a[p * 2].kb * a[p * 2 + 1].bb % mod;       if (l < mid) (a[p].kb += a[p * 2].kk * a[p * 2 + 1].kb % mod * v) %= mod;       a[p].bb = a[p * 2].bb * a[p * 2 + 1].bb % mod;       (a[p].bb += a[p * 2].bk * a[p * 2 + 1].kb % mod * v) %= mod;     }     void build(int p = 1, int l = 1, int r = n) {       if (l == r) {         a[p] = {1, 1, 1, t[l] + 1};         return;       }       int mid = l + r >> 1;       build(p * 2, l, mid);       build(p * 2 + 1, mid + 1, r);       upd(p, l, r);     }     void ins(int x, int p = 1, int l = 1, int r = n) {       if (l == r) {         a[p] = {1, 1, 1, t[l] + 1};         return;       }       int mid = l + r >> 1;       if (x <= mid)         ins(x, p * 2, l, mid);       else         ins(x, p * 2 + 1, mid + 1, r);       upd(p, l, r);     }   } tr;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       char c;       scanf(  %c , &c);       t[i] = c -  0 ;     }     tr.build();     while (m--) {       int p, v;       scanf( %d%d , &p, &v);       t[p] = v;       tr.ins(p);       printf( %lld n , tr.a[1].bb);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[1111];   int b[1111];   int c[1111];   int vis[1111];   int pos[5];   int cntp;   int main() {     scanf( %d , &n);     bool flag = 0;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       vis[a[i]]++;     }     for (int i = 1; i <= n; ++i) {       scanf( %d , &b[i]);       if (a[i] != b[i]) {         pos[++cntp] = i;       }     }     int dvis;     for (int i = 1; i <= n; ++i)       if (!vis[i]) {         dvis = i;         break;       }     if (cntp == 1) {       a[pos[1]] = dvis;     } else {       if (b[pos[1]] == dvis && vis[a[pos[1]]] > 1)         a[pos[1]] = dvis;       else         a[pos[2]] = dvis;     }     for (int i = 1; i <= n; ++i) printf( %d  , a[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   struct hhh {     long long x;     long long y;     long long v;   } c[1000001];   bool operator<(hhh a, hhh b) {     return (a.v != b.v ? a.v > b.v : (a.x != b.x ? a.x > b.x : a.y > b.y));   }   vector<hhh> v;   long long n, m, a, b, h[1001][1001], g[1001][1001], mi[1001][1001],       minf[1001][1001], k;   bool f[1001][1001];   long long pre[3][1001][1001];   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   bool check(hhh t) {     if (f[t.x][t.y]) {       return 0;     }     for (long long i = max(t.x - a + 1, (long long)1); i <= t.x + a - 1; i++) {       for (long long j = max(t.y - b + 1, (long long)1); j <= t.y + b - 1; j++) {         f[i][j] = 1;       }     }     return 1;   }   int main() {     n = read();     m = read();     a = read();     b = read();     for (long long i = 1; i <= (n); i++) {       for (long long j = 1; j <= (m); j++) {         h[i][j] = read();       }     }     for (long long i = 1; i <= (n); i++) {       for (long long j = 1; j <= (m); j++) {         pre[1][i][j] = pre[1][i][j - 1] + h[i][j];         pre[2][i][j] = pre[2][i - 1][j] + h[i][j];       }     }     for (long long i = 1; i <= (a); i++) {       g[1][1] += pre[1][i][b];     }     for (long long i = 2; i <= m - b + 1; i++) {       g[1][i] = g[1][i - 1] + pre[2][a][i + b - 1] - pre[2][a][i - 1];     }     for (long long i = 2; i <= n - a + 1; i++) {       for (long long j = 1; j <= (m - b + 1); j++) {         g[i][j] = g[i - 1][j] + pre[1][i + a - 1][j + b - 1] -                   pre[1][i + a - 1][j - 1] - pre[1][i - 1][j + b - 1] +                   pre[1][i - 1][j - 1];       }     }     for (long long i = 1; i <= (n); i++) {       long long s = 1;       long long t = 0;       long long que[1001];       que[0] = INF;       for (long long j = 1; j <= (m); j++) {         while (s <= t && h[i][que[t]] >= h[i][j]) {           t--;         }         que[++t] = j;         if (j - b >= 0) {           mi[i][j - b + 1] = h[i][que[s]];         }         if (que[s] == j - b + 1) {           s++;         }       }     }     for (long long j = 1; j <= (m - b + 1); j++) {       long long s = 1;       long long t = 0;       long long que[1001];       que[0] = INF;       for (long long i = 1; i <= (n); i++) {         while (s <= t && mi[que[t]][j] >= mi[i][j]) {           t--;         }         que[++t] = i;         if (i - a >= 0) {           minf[i - a + 1][j] = mi[que[s]][j];         }         if (que[s] == i - a + 1) {           s++;         }       }     }     for (long long i = 1; i <= (n - a + 1); i++) {       for (long long j = 1; j <= (m - b + 1); j++) {         g[i][j] -= a * b * minf[i][j];         hhh t;         t.x = i;         t.y = j;         t.v = g[i][j];         v.push_back(t);       }     }     make_heap(v.begin(), v.end());     while (!v.empty()) {       hhh t = v.front();       pop_heap(v.begin(), v.end());       v.pop_back();       if (check(t)) {         c[++k] = t;       }     }     cout << k << endl;     for (long long i = 1; i <= (k); i++) {       printf( %I64d %I64d %I64d n , c[i].x, c[i].y, c[i].v);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   struct Aho {     enum { ALPHA = 30 };     struct Node {       int p = -1, link = -1, superLink = -1;       int next[ALPHA], go[ALPHA];       bool leaf = false;       vector<int> leaves;       char ch;       Node(int p = -1, char c =  $ ) : p(p), ch(c) {         fill(begin(next), end(next), -1);         fill(begin(go), end(go), -1);       }     };     vector<Node> nodes;     void insert(string &s, int id) {       int v = 0;       for (char ch : s) {         int c = ch -  a ;         if (nodes[v].next[c] == -1) {           Node aux = Node(v, ch);           nodes[v].next[c] = (int)nodes.size();           nodes.push_back(aux);         }         v = nodes[v].next[c];       }       nodes[v].leaf = true;       nodes[v].leaves.push_back(id);     }     int go(int v, char ch) {       int c = ch -  a ;       if (nodes[v].go[c] == -1) {         if (nodes[v].next[c] != -1) {           nodes[v].go[c] = nodes[v].next[c];         } else {           if (v == 0)             nodes[v].go[c] = 0;           else             nodes[v].go[c] = go(nodes[v].link, ch);         }       }       return nodes[v].go[c];     }     Aho(vector<string> &vs) {       Node root = Node();       nodes.push_back(root);       int id = 0;       for (auto s : vs) insert(s, id++);       queue<int> fila;       nodes[0].link = 0;       for (int &v : nodes[0].next) {         if (v != -1) {           fila.push(v);           nodes[v].link = 0;         } else           v = 0;       }       while (!fila.empty()) {         int v = fila.front();         fila.pop();         for (int u : nodes[v].next) {           if (u != -1) {             int c = nodes[u].ch -  a ;             int fail = nodes[v].link;             while (nodes[fail].next[c] == -1) {               fail = nodes[fail].link;             }             fail = nodes[fail].next[c];             for (int id : nodes[fail].leaves) {               nodes[u].leaves.push_back(id);             }             nodes[u].link = fail;             fila.push(u);           }         }       }     }     int find(int idx, int p) {       if (idx != p and (nodes[idx].leaf or idx == 0)) return idx;       if (nodes[idx].superLink == -1) {         nodes[idx].superLink = find(nodes[idx].link, p);       }       return nodes[idx].superLink;     }     vector<vector<int> > findAll(string s, int n) {       vector<vector<int> > res(n + 5);       int idx = 0;       for (int i = 0; i < (int)s.size(); i++) {         char ch = s[i];         idx = go(idx, ch);         for (int id : nodes[idx].leaves) res[i].push_back(id);       }       return res;     }   };   string s;   string ss[100005];   int n;   int k[100005];   int32_t main() {     cin.tie(NULL);     cout.tie(NULL);     ios_base::sync_with_stdio(0);     cin >> s >> n;     vector<string> vs;     for (int i = 0; i < n; i++) {       cin >> k[i] >> ss[i];       vs.push_back(ss[i]);     }     Aho ac = Aho(vs);     auto res = ac.findAll(s, (int)s.size());     vector<vector<int> > pos(n + 5);     for (int i = 0; i < (int)res.size(); i++) {       for (int idx : res[i]) {         pos[idx].push_back(i);       }     }     for (int i = 0; i < n; i++) {       int res = 0x3f3f3f3f;       if ((int)pos[i].size() < k[i]) {         cout << -1 <<   n ;         continue;       }       for (int j = 0; j + k[i] <= (int)pos[i].size(); j++) {         res = min(res, pos[i][k[i] + j - 1] - pos[i][j] + (int)ss[i].size());       }       cout << res <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, s1;     int m;     cin >> s;     cin >> m;     int l, r, k, i, j, d, ind;     while (m--) {       cin >> l >> r >> k;       --l;       --r;       d = r - l + 1;       s1 = s.substr(l, d);       for (i = l; i <= r; ++i) {         ind = (i - l + k) % d + l;         s[ind] = s1[i - l];       }     }     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 100005;   const long long p = 1e9 + 7;   long long a[maxn], n, x, sum;   long long st[maxn], top;   vector<long long> v;   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   inline long long qpow(long long x, long long y) {     long long res = 1;     while (y) {       if (y & 1) res = (res * x % p) % p;       x = (x % p * x % p) % p;       y >>= 1;     }     return res % p;   }   signed main() {     n = read();     x = read();     for (long long i = 1; i <= n; i++) a[i] = read(), sum += a[i];     for (long long i = 1; i <= n; i++) st[++top] = sum - a[i];     sort(st + 1, st + n + 1);     reverse(st + 1, st + n + 1);     while (1) {       long long res = st[top], cnt = 0;       while (top > 0 && res == st[top]) cnt++, top--;       if (cnt % x) {         printf( %d , qpow(x, min(sum, res)));         return 0;       } else {         cnt /= x;         for (long long i = 1; i <= cnt; i++) st[++top] = res + 1;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct NODE {     char name[102];     int to;   };   struct TRIE {     vector<NODE> fold, file;   };   TRIE trie[5][10010];   int cnt[5];   int ans_file, ans_fold;   int track(int index, int tar, int &layer) {     int i, j, count = 0;     if (trie[index][tar].fold.size() < 1) {       return trie[index][tar].file.size();     } else {       for (i = 0, j = trie[index][tar].fold.size(); i < j; ++i) {         count += track(index, trie[index][tar].fold[i].to, layer);       }       layer += trie[index][tar].fold.size();       return (count + trie[index][tar].file.size());     }   }   int main() {     int i, j, index, now;     char in[102], *p;     NODE tmp;     memset(trie, 0, sizeof(trie));     memset(cnt, 0, sizeof(cnt));     while (scanf( %s , in) != EOF) {       p = strtok(in,  :  );       if (p[0] ==  C )         index = 0;       else if (p[0] ==  D )         index = 1;       else if (p[0] ==  E )         index = 2;       else if (p[0] ==  F )         index = 3;       else if (p[0] ==  G )         index = 4;       now = 0;       p = strtok(NULL,    );       while (p != NULL) {         for (i = 0, j = strlen(p); i < j; ++i)           if (p[i] ==  . ) break;         if (i == j) {           for (i = 0, j = trie[index][now].fold.size(); i < j; ++i)             if (!strcmp(trie[index][now].fold[i].name, p)) break;           if (i == j) {             strcpy(tmp.name, p);             tmp.to = ++cnt[index];             trie[index][now].fold.push_back(tmp);             now = cnt[index];           } else {             now = trie[index][now].fold[i].to;           }         } else {           strcpy(tmp.name, p);           trie[index][now].file.push_back(tmp);         }         p = strtok(NULL,    );       }     }     for (i = 0, ans_file = 0, ans_fold = 0; i < 5; ++i) {       for (j = 0, now = trie[i][0].fold.size(); j < now; ++j) {         index = 0;         ans_file = max(ans_file, track(i, trie[i][0].fold[j].to, index));         ans_fold = max(ans_fold, index);       }     }     printf( %d %d n , ans_fold, ans_file);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int T[2 * 10010];   vector<int> G[6010];   vector<int> S[6010];   int P[6010];   int C[6010];   map<int, int> M;   bool V[6010];   int mx;   int n = 6010;   void modify(int p, int value) {     for (T[p += n] = value; p > 1; p >>= 1) T[p >> 1] = max(T[p], T[p ^ 1]);   }   int query(int l, int r) {     int res = 0;     for (l += n, r += n; l < r; l >>= 1, r >>= 1) {       if (l & 1) res = max(res, T[l++]);       if (r & 1) res = max(res, T[--r]);     }     return res;   }   void dfs(int u) {     V[u] = true;     int val = 1 + query(0, P[u]);     S[P[u]].push_back(val);     modify(P[u], val);     mx = max(mx, val);     for (int i = 0; i < G[u].size(); i++) {       int v = G[u][i];       if (!V[v]) {         dfs(v);       }     }     S[P[u]].pop_back();     if (!S[P[u]].empty()) {       modify(P[u], S[P[u]].back());     } else {       modify(P[u], 0);     }   }   int main() {     ios::sync_with_stdio(false);     int N;     cin >> N;     for (int i = 1; i <= N; i++) {       cin >> P[i];       C[i] = P[i];     }     for (int i = 0; i < N - 1; i++) {       int u, v;       cin >> u >> v;       G[u].push_back(v);       G[v].push_back(u);     }     sort(C + 1, C + N + 1);     int count = 1;     M[C[1]] = 1;     for (int i = 2; i <= N; i++) {       if (C[i] != C[i - 1]) {         count++;         M[C[i]] = count;       }     }     for (int i = 1; i <= N; i++) {       P[i] = M[P[i]];     }     for (int i = 1; i <= N; i++) {       dfs(i);       memset(V, false, sizeof V);     }     cout << mx <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt[200001], n, par;   vector<int> adj[200001];   vector<pair<int, int> > v;   void count(int h, int p) {     cnt[h]++;     for (auto it : adj[h])       if (it ^ p) {         count(it, h);         cnt[h] += cnt[it];       }   }   int ct(int h, int p) {     for (auto it : adj[h])       if (it ^ p) {         if (cnt[it] > n / 2) return ct(it, h);       }     par = p;     return h;   }   vector<pair<int, pair<int, int> > > res;   void dfs(int h, int p) {     for (auto it : adj[h])       if (it ^ p) {         dfs(it, h);       }     v.push_back({h, p});   }   void f(int h, int p) {     v.clear();     dfs(h, p);     v.pop_back();     int t = h;     for (auto it : v) {       res.push_back({p, {t, it.first}});       res.push_back({it.first, {it.second, h}});       t = it.first;     }     res.push_back({p, {t, h}});   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       adj[x].push_back(y);       adj[y].push_back(x);     }     count(1, 0);     int cen = ct(1, 0), cen2 = 0;     for (auto it : adj[cen])       if (par != it && 2 * cnt[it] == n) cen2 = it;     for (auto it : adj[cen])       if (it != cen2) f(it, cen);     for (auto it : adj[cen2])       if (it != cen) f(it, cen2);     printf( %d n , res.size());     for (auto it : res)       printf( %d %d %d n , it.first, it.second.first, it.second.second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool f[10];   char s[100005];   int main() {     int n, i, j;     scanf( %d , &n);     scanf( %s , s);     for (i = 0; i < n; i++) {       if (s[i] ==  L ) {         for (j = 0; j < 10; j++)           if (!f[j]) break;         f[j] = 1;       } else if (s[i] ==  R ) {         for (j = 9; j >= 0; j--)           if (!f[j]) break;         f[j] = 1;       } else {         f[s[i] -  0 ] = 0;       }     }     for (i = 0; i < 10; i++) printf( %d , f[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> pr;   bool isp[1001];   void p() {     memset(isp, true, sizeof isp);     isp[0] = isp[1] = false;     for (int i = 2; i < 1001; ++i) {       if (!isp[i]) continue;       pr.push_back(i);       for (int j = 2 * i; j < 1001; j += i) isp[j] = false;     }   }   int main() {     p();     string s;     cin >> s;     int n = s.length();     bool ans = 0;     set<int> st;     for (int i = 0; i < pr.size(); ++i) {       if (pr[i] > n / 2) break;       for (int j = 1; pr[i] * j <= n; ++j) st.insert(pr[i] * j);     }     int cnt[26], mx = 0, ch = -1;     memset(cnt, 0, sizeof cnt);     for (int i = 0; i < n; ++i) {       cnt[s[i] -  a ]++;       if (mx < cnt[s[i] -  a ]) {         mx = cnt[s[i] -  a ];         ch = s[i];       }     }     if (mx >= st.size()) {       cout <<  YES  << endl;       string ans = s;       for (int i = 0; i < n; ++i) ans[i] =    ;       for (set<int>::iterator it = st.begin(); it != st.end(); ++it)         ans[*it - 1] = ch;       cnt[ch -  a ] -= st.size();       int idx = 0;       for (int i = 0; i < 26; ++i)         for (int j = 0; j < cnt[i]; ++j) {           while (ans[idx] !=    ) ++idx;           ans[idx] = i +  a ;         }       cout << ans << endl;     } else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t[6000020][2], tt;   void ins(long long x) {     int p = 0;     for (int i = 40; i--;) {       if (!t[p][x >> i & 1]) t[p][x >> i & 1] = ++tt;       p = t[p][x >> i & 1];     }   }   long long qy(long long x) {     long long z = 0;     int p = 0;     for (int i = 40; i--;) {       if (t[p][~x >> i & 1])         z += 1LL << i, p = t[p][~x >> i & 1];       else         p = t[p][x >> i & 1];     }     return z;   }   int n;   long long a[100020];   long long ans;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %I64d , a + i);     long long w = 0;     ins(w);     for (int i = 0; i < n; i++) ins(w ^= a[i]);     for (int i = 0; i < n; i++) ans = max(ans, qy(w ^= a[i]));     printf( %I64d , ans);   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const int MAXN = 5e2 + 10;   int n, m;   long long adj[MAXN][MAXN];   long long adj_[MAXN][MAXN];   int ans[MAXN][MAXN];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     memset(adj, 63, sizeof(adj));     memset(adj_, 63, sizeof(adj_));     for (int i = 0; i < m; i++) {       int u, v, l;       cin >> u >> v >> l;       adj[u][v] = adj[v][u] = l;       adj_[u][v] = adj_[v][u] = l;     }     for (int i = 1; i <= n; i++) adj[i][i] = 0;     for (int k = 1; k <= n; k++)       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++)           adj[i][j] = min(adj[i][j], adj[i][k] + adj[j][k]);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         for (int k = 1; k <= n; k++)           if (adj_[k][j] < 1e9 && (adj[i][k] + adj_[k][j]) == adj[i][j])             ans[i][j]++;     for (int i = 1; i < n; i++)       for (int j = i + 1; j <= n; j++) {         int answer = 0;         for (int k = 1; k <= n; k++)           if ((adj[i][k] + adj[k][j]) == adj[i][j]) answer += ans[i][k];         cout << answer <<    ;       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ask(int i, int j) {     cout <<  ?   << i <<     << j << endl;     fflush(stdout);     int val;     cin >> val;     return val;   }   int main() {     int n;     cin >> n;     int a[n + 1];     int index = 1, i, x, y;     for (int i = 2; i <= n; i++) {       x = ask(index, i);       y = ask(i, index);       if (x > y) {         a[index] = x;         index = i;       } else if (y > x) {         a[i] = y;       }     }     a[index] = n;     cout <<  !  ;     for (i = 1; i <= n; i++) cout << a[i] <<    ;     cout <<   n ;     fflush(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   long long n, m, s, t;   long long pos[maxn], T[maxn];   long long cal(long long x) {     if (s < m)       s += t;     else       s -= t;     t--;     return (s % n + n) % n;   }   int main() {     cin >> n >> m >> s >> t;     s--;     while (t % n) s = cal(s);     long long temp = t / n;     long long tick = 0;     while (temp--) {       if (pos[s]) {         temp %= tick - T[s];         s = pos[s];       } else {         T[s] = tick;         long long tmp = s;         t = n;         for (int i = 1; i <= n; i++) s = cal(s);         pos[tmp] = s;         tick++;       }     }     cout << s + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       for (long long i = 1; i <= n; i++) {         cout << 1 <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   bool done[1010];   int l[1010], r[1010], ans[1010];   int main() {     int n, i, j, k;     scanf( %d , &n);     int rem = n;     for (i = 0; i < n; i++) {       scanf( %d , &l[i]);       done[i] = 0;     }     for (i = 0; i < n; i++) scanf( %d , &r[i]);     int maxx = n;     while (1) {       set<int> S;       bool over = 1;       for (i = 0; i < n; i++) {         if (done[i] == 0) {           over = 0;           if (l[i] == 0 and r[i] == 0) {             S.insert(i);           }         }       }       if (over) break;       int sz = S.size();       if (sz == 0) {         cout <<  NO  << endl;         return 0;       }       set<int>::iterator it;       for (it = S.begin(); it != S.end(); it++) {         int idx = *it;         ans[idx] = maxx;         for (j = idx - 1; j >= 0; j--) {           if (done[j] == 0 and S.find(j) == S.end()) {             if (r[j] == 0) {               cout <<  NO  << endl;               return 0;             }             r[j]--;           }         }         for (j = idx + 1; j < n; j++) {           if (done[j] == 0 and S.find(j) == S.end()) {             if (l[j] == 0) {               cout <<  NO  << endl;               return 0;             }             l[j]--;           }         }       }       for (it = S.begin(); it != S.end(); it++) {         done[*it] = 1;       }       maxx--;     }     cout <<  YES  << endl;     for (i = 0; i < n; i++) cout << ans[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int ans;   bool one, two, three;   vector<int> v;   int main() {     scanf( %d , &n);     while (one == false || two == false || three == false) {       for (int i = 1; i <= n; i++) {         if (!one) {           if (i % 2 == 0) {             ans++;             v.push_back(i);           }           if ((n % 2 == 0 && i == n) || (n % 2 != 0 && i == n - 1)) {             one = true;             break;           }         } else if (!two) {           if (i % 2 != 0) {             ans++;             v.push_back(i);           }           if ((n % 2 != 0 && i == n) || (n % 2 == 0 && i == n - 1)) {             two = true;             break;           }         } else if (!three) {           if (i % 2 == 0) {             ans++;             v.push_back(i);           }           if ((n % 2 == 0 && i == n) || (n % 2 != 0 && i == n - 1)) {             three = true;             goto A;           }         }       }     }   A:     printf( %d n , ans);     for (int i = 0; i < v.size(); i++) {       printf( %d  , v[i]);     }   }


#include <bits/stdc++.h>   const long long MaxN = 1e5 + 50;   template <class t>   inline void read(t &s) {     s = 0;     register long long f = 1;     register char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();     s *= f;     return;   }   template <class t, class... A>   inline void read(t &x, A &...a) {     read(x);     read(a...);   }   template <class t>   inline void write(t x) {     if (x < 0) putchar( - ), x = -x;     long long buf[21], top = 0;     while (x) buf[++top] = x % 10, x /= 10;     if (!top) buf[++top] = 0;     while (top) putchar(buf[top--] ^  0 );     return;   }   inline void setIn(std::string s) {     freopen(s.c_str(),  r , stdin);     return;   }   inline void setOut(std::string s) {     freopen(s.c_str(),  w , stdout);     return;   }   inline void setIO(std::string s =   ) {     setIn(s +  .in );     setOut(s +  .out );     return;   }   template <class t>   inline bool ckmin(t &x, t y) {     if (x > y) {       x = y;       return 1;     }     return 0;   }   template <class t>   inline bool ckmax(t &x, t y) {     if (x < y) {       x = y;       return 1;     }     return 0;   }   inline long long lowbit(long long x) { return x & (-x); }   std::vector<long long> E[MaxN];   long long f[MaxN], g[MaxN], up[MaxN][21], dep[MaxN], s[MaxN][21], to[MaxN],       a[MaxN], n, L, S;   inline void dfs(long long u, long long fa) {     up[u][0] = fa, dep[u] = dep[fa] + 1;     for (auto v : E[u])       if (v != fa) s[v][0] = a[u], dfs(v, u);   }   inline void dfs2(long long u, long long fa) {     f[u] = -1;     for (auto v : E[u])       if (v != fa) dfs2(v, u), ckmax(f[u], f[v] - 1), g[u] += g[v];     if (!~f[u]) f[u] = to[u], ++g[u];   }   signed main(void) {     read(n, L, S);     if (!L) return std::puts( -1 ), 0;     for (long long i = 1; i <= n; ++i) {       read(a[i]);       if (a[i] > S) return std::puts( -1 ), 0;     }     register long long v;     for (long long i = 2; i <= n; ++i)       read(v), E[i].push_back(v), E[v].push_back(i);     dfs(1, 0);     for (long long k = 1; k < 21; ++k)       for (long long i = 1; i <= n; ++i)         up[i][k] = up[up[i][k - 1]][k - 1],         s[i][k] = s[i][k - 1] + s[up[i][k - 1]][k - 1];     for (long long i = 1; i <= n; ++i) {       register long long pos = i, nl = 0, ns = a[i];       for (long long k = 20; ~k; --k)         if (up[pos][k] && nl + (1 << k) < L && ns + s[pos][k] <= S)           nl += (1 << k), ns += s[pos][k], pos = up[pos][k];       to[i] = nl;     }     dfs2(1, 0);     write(g[1]), std::puts(  );     return 0;   }


//SAGAR SINGH   // #pragma GCC optimize( Ofast )   // #pragma GCC target( avx,avx2,fma )   // #pragma GCC optimization( unroll-loops )   #include<bits/stdc++.h>   using namespace std;   #define fastio ios_base::sync_with_stdio;cin.tie(NULL);cout.tie(0);   #define ll long long    #define ld long double    #define rep(i,a,b) for(ll i=a;i<b;i++) //rep(i,0,n)    #define repr(i,a,b) for(ll i=a;i>=b;i--)//repr(i,n-1,0)   #define repit(it,a) for(auto it=(a).begin();it!=(a).end();it++)//repr(i,n,0)   #define vll vector<long long>   #define vpl vector<pair<ll,ll> >   #define sll set<long long>   #define msll multiset<long long>   #define mll map<ll,ll>   #define mmll multimap<ll,ll>   #define all(x) x.begin(),x.end()   #define rall(x) x.rbegin(),x.rend()   #define get(x) getline(cin,x)   #define in(v) for(auto &x:v) cin>>x;   #define out(v) for(auto x:v) {cout<<x<<   ;} cout<<  n ;   #define str string   #define pb  push_back   #define ins insert   #define lb lower_bound   #define ub upper_bound   #define ff first   #define ss second   /*--- bit-stuff ----*/   #define setbits(a) ( __builtin_popcountll(a))   #define right(a) (__builtin_ctzll(a))   #define left(a) (__builtin_clzll(a))   #define parity(a) (__builtin_parityll(a))      #define TRACE   #ifdef TRACE   #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)       template <typename Arg1>       void __f(const char* name, Arg1&& arg1){           cout << name <<   :   << arg1 << endl;           //use cerr if u want to display at the bottom       }       template <typename Arg1, typename... Args>       void __f(const char* names, Arg1&& arg1, Args&&... args){           const char* comma = strchr(names + 1,  , ); cout.write(names, comma - names) <<   :   << arg1<<  |  ;__f(comma+1, args...);       }   #else   #define trace(...)   #endif         const ll mod = 1e9+7;   const ll N = 1e5+1;   const ll INF = 1e18;   const ll NINF = -1e18;         void solve(){      ll n;cin>>n;   vll v(n);in(v);      str s;   rep(i,0,n) s.pb( 0 );      ll cur=0;   ll i=n-1;      while(i>=0){    cur=max({cur,v[i],(ll)0});     if(cur>0) s[i]= 1 ;     else s[i]= 0 ;     i--;     cur--;   }      out(s);                     }      int main(){     ios_base::sync_with_stdio;     cin.tie(NULL);cout.tie(0);     ll t=1;     cin>>t;     while(t--)        solve();        return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long N, K;   int M;   vector<long long> special;   int sol = 0;   int main() {     scanf( %lld %d %lld , &N, &M, &K);     for (int i = 0; i < M; i++) {       long long v;       scanf( %lld , &v);       special.push_back(v);     }     int curr = 0, add = 0;     while (curr < M) {       sol++;       long long v = special[curr];       v--;       v -= (long long)add;       long long page = v / K;       long long en = K + K * page;       long long toAdd = 0;       while (curr < M && special[curr] - add <= en) {         curr++;         toAdd++;       }       add += toAdd;     }     printf( %d n , sol);     return 0;   }