#include <bits/stdc++.h>   using namespace std;   bool sBs(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   long long SUMD(long long n);   long long BS(vector<pair<long long, long long> > &PS, long long s, long long e,                long long ser);   long long MI(long long a, long long m);   long long P[101LL + 1];   void Sieve(int n = 101LL);   long long Powb(long long b, long long n, long long m);   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long q = 1, t;     cin >> q;     t = q;     while (q--) {       long long i, j, n, m, k, l = 0, r = 0, a = 0, b = 0, c = 0, d = 0, e, g = 1,                                p, u, v, w, x, y, flag = 1;       cin >> n >> x;       long long ans = 0;       vector<long long> V(n);       for (i = 0; i < n; i++) cin >> V[i];       sort(V.rbegin(), V.rend());       for (i = 0; i < n; i++) {         if (V[i] * (i - l + 1) >= x) {           ans += 1;           l = i + 1;         }       }       cout << ans <<   n ;     }     return 0;   }   long long Powb(long long b, long long n, long long m) {     if (n == 0) return 1LL;     if (n == 1) return b;     long long temp = Powb(b, n / 2, m);     if (n % 2 == 0) {       return (temp * temp) % m;     } else {       return (b * ((temp * temp) % m)) % m;     }   }   long long SUMD(long long n) {     long long sum = 0;     while (n > 0) {       sum += n % 10;       n = n / 10;     }     return sum;   }   long long BS(vector<pair<long long, long long> > &PS, long long s, long long e,                long long ser) {     if (s > e) return s;     long long mid = (s + e) / 2;     if (PS[mid].first == ser) {       return mid;     } else if (PS[mid].first > ser) {       return BS(PS, s, mid - 1, ser);     } else       return BS(PS, mid + 1, e, ser);   }   long long MI(long long a, long long m) {     long long m0 = m;     long long y = 0, x = 1;     if (m == 1) return 0;     while (a > 1) {       long long q = a / m;       long long t = m;       m = a % m, a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) x += m0;     return x;   }   void Sieve(int n) {     for (int i = 1; i <= n; i++) P[i] = i;     for (long long i = 2; i * i <= n; i++) {       if (P[i] == i) {         for (long long j = i * i; j <= n; j += i) {           if (P[j] == j) P[j] = i;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   struct point {     int x, y, ind;   };   vector<point> fd[200200];   vector<point> bd[200200];   long long out[100100];   int main() {     scanf( %d%d%d , &n, &m, &k);     memset(out, -1, sizeof out);     for (int i = 0, x, y; i < k; ++i) {       scanf( %d%d , &x, &y);       fd[x - y + m].push_back({x, y, i});       bd[x + y].push_back({x, y, i});     }     int x = 0, y = 0, dx = 1, dy = 1;     long long t = 0;     while (true) {       if (dx == dy) {         int l = x - y + m;         for (int i = 0; i < (int)fd[l].size(); ++i) {           point &p = fd[l][i];           if (out[p.ind] != -1) continue;           long long dfx = x - p.x;           out[p.ind] = t + abs(dfx);         }       } else {         int l = x + y;         for (int i = 0; i < (int)bd[l].size(); ++i) {           point &p = bd[l][i];           if (out[p.ind] != -1) continue;           long long dfx = x - p.x;           out[p.ind] = t + abs(dfx);         }       }       int mh, mv;       if (dx == 1)         mh = n - x;       else         mh = x;       if (dy == 1)         mv = m - y;       else         mv = y;       if (mh < mv) {         if (dx == 1)           x = n;         else           x = 0;         t += mh;         y += mh * dy;         dx *= -1;       } else if (mh > mv) {         if (dy == 1)           y = m;         else           y = 0;         t += mv;         x += mv * dx;         dy *= -1;       } else {         break;       }     }     for (int i = 0; i < k; ++i) printf( %I64d n , out[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1000000001;   const long long maxg = 4444444444LL;   vector<long long> g;   void recurs(int d, int len, long long z) {     if (d == len)       g.push_back(z);     else {       recurs(d + 1, len, z * 10 + 4);       recurs(d + 1, len, z * 10 + 7);     }   }   long long a[1000];   long long f[100];   long long fact(int n) {     if (n > 50) return inf;     if (f[n] != 0) return f[n];     if (n == 1 || n == 0) return f[n] = 1;     return f[n] = min(inf, n * min(inf, (fact(n - 1))));   }   bool good(int a) {     if (a == 0) return false;     while (a > 0) {       if (!(a % 10 == 4 || a % 10 == 7)) return false;       a /= 10;     }     return true;   }   int main() {     for (int ll = 1; ll <= 9; ll++) {       recurs(0, ll, 0);     }     g.push_back(maxg);     long long n, k;     cin >> n >> k;     if (fact(n) < k) {       cout << -1 << endl;       return 0;     }     long long p = 1;     long long m = n - 1;     while (fact(n - m) + 1 <= k) m--;     long long s = n - m;     for (int i = 1; i <= s; i++) a[i] = m + i;     while (p < k) {       for (int i = 1;; i++) {         if (fact(i + 1) + p > k) {           p += fact(i);           for (int j = s - i + 1;; j++) {             if (a[j] > a[s - i]) {               swap(a[j], a[s - i]);               break;             }           }           break;         }       }     }     long long ans = 0;     for (int i = 0; i < int(g.size()); i++) {       if (g[i] <= m) ans = i + 1;     }     for (int i = 1; i <= s; i++) {       if (good(i + m) && good(a[i])) ans++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e3 + 5;   int main() {     int x1, y1, x2, y2;     while (~scanf( %d%d%d%d , &x1, &y1, &x2, &y2)) {       long long x = x2 - x1 + 1;       long long y = y2 - y1 + 2;       long long s = x * y / 2 - x / 2;       printf( %lld n , s);     }   }


#include <bits/stdc++.h>   using namespace std;   vector<long long int> facts;   vector<long long int> inv_facts;   long long int c(long long int n, long long int p) {     if (p < 0 || n < p) return 0;     return (facts[n] * inv_facts[p]) % 1000000007 * inv_facts[n - p] % 1000000007;   }   long long int pow_mod(long long int x, long long int n) {     if (n == 0) return 1;     if (n & 1) return x * pow_mod(x, n - 1) % 1000000007;     long long int tmp = pow_mod(x, n / 2);     return tmp * tmp % 1000000007;   }   int main(int argc, char* argv[]) {     ios_base::sync_with_stdio(false);     long long int X, Y, N;     cin >> X >> Y >> N;     facts.push_back(1);     inv_facts.push_back(1);     long long int maxF = X + Y + 1;     for (long long int n = 1; n <= maxF; ++n) {       long long int f = facts[n - 1] * n % 1000000007;       facts.push_back(f);       inv_facts.push_back(pow_mod(f, 1000000007 - 2));     }     vector<pair<long long int, long long int> > xys;     for (long long int n = 0; n < N; ++n) {       long long int x, y;       cin >> x >> y;       xys.push_back(make_pair(x - 1, y - 1));     }     xys.push_back(make_pair(X - 1, Y - 1));     sort(xys.begin(), xys.end());     vector<long long int> dp(N + 1);     for (long long int n = 0; n <= N; ++n) {       long long int x = xys[n].first, y = xys[n].second;       long long int tmp = c(x + y, y);       for (long long int m = 0; m < N; ++m) {         long long int xm = xys[m].first, ym = xys[m].second;         if (xm <= x && ym <= y)           tmp = (tmp + 1000000007 -                  dp[m] * c(x - xm + y - ym, x - xm) % 1000000007) %                 1000000007;       }       dp[n] = tmp;     }     cout << dp[N] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000005, md = 998244353;   int n, i, j, k, e, p[N], lmt, len, rt[N], ome[N], rome[N], g[N], h[N], w1[N],       w2[N], inv[N];   long long a[N], b[N], w, xxj[65];   inline void Read(long long &x) {     char c;     while ((c = getchar()) <  0  || c >  9 )       ;     x = c -  0 ;     while ((c = getchar()) >=  0  && c <=  9 ) x = x * 10 + c -  0 ;   }   void ntt(int a[N], bool t) {     for (int i = 0; i < len; ++i)       if (i < rt[i]) swap(a[i], a[rt[i]]);     for (int l = 2; l <= len; l <<= 1) {       int m = l >> 1;       for (int i = 0; i < len; i += l)         for (int j = 0; j < m; ++j) {           int w = 1ll * (t ? ome[len / l * j] : rome[len / l * j]) *                   a[i + j + m] % md;           a[i + j + m] = (a[i + j] - w + md) % md;           a[i + j] = (a[i + j] + w) % md;         }     }     if (!t)       for (int i = 0; i < len; ++i) a[i] = 1ll * a[i] * inv[len] % md;   }   void merge(int l, int r) {     if (l == r) {       p[l] = 2;       return;     }     int mid = (l + r) / 2, i;     merge(l, mid);     merge(mid + 1, r);     lmt = 0;     while ((1 << lmt) <= r - l + 1) ++lmt;     len = 1 << lmt;     ome[0] = rome[0] = 1;     for (i = 1; i < len; ++i) {       rt[i] = 0;       for (j = 0; j < lmt; ++j)         if ((1 << j) & i) rt[i] |= 1 << (lmt - j - 1);       ome[i] = 1ll * ome[i - 1] * w1[len] % md,       rome[i] = 1ll * rome[i - 1] * w2[len] % md;     }     for (i = 0; i < len; ++i) g[i] = h[i] = 0;     for (i = l; i <= mid; ++i) g[i - l] = p[i];     for (i = mid + 1; i <= r; ++i) h[i - mid - 1] = p[i];     ntt(g, true);     ntt(h, true);     for (i = 0; i < len; ++i) g[i] = 1ll * g[i] * h[i] % md;     ntt(g, false);     for (i = 0; i < len; ++i) {       g[i + 1] += g[i] / 10;       g[i] %= 10;     }     for (i = l; i <= r; ++i) p[i] = g[i - l];   }   inline int pw(int a, int b) {     int rtn = 1;     while (b) {       if (b & 1) rtn = 1ll * rtn * a % md;       a = 1ll * a * a % md;       b >>= 1;     }     return rtn;   }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; ++i) {       Read(a[i]);       Read(b[i]);       b[i] ^= a[i];       w ^= a[i];     }     e = 0;     for (i = 1; i <= n; ++i) {       for (j = 60; j >= 0; --j)         if ((1ll << j) & b[i]) {           if (!xxj[j]) {             xxj[j] = b[i];             break;           }           b[i] ^= xxj[j];         }       if (b[i] == 0) ++e;     }     for (j = 60; j >= 0; --j)       if ((1ll << j) & w) {         if (!xxj[j]) {           printf( 1/1 );           return 0;         }         w ^= xxj[j];       }     if (n - e == 0) {       printf( 0/1 );       return 0;     }     for (i = 1; i <= 2 * (n - e); ++i) {       w1[i] = pw(3, (md - 1) / i), w2[i] = pw(w1[i], md - 2);       if (i == 1)         inv[i] = 1;       else         inv[i] = 1ll * inv[md % i] * (md - md / i) % md;     }     merge(1, n - e);     for (i = n - e; p[i] == 0; --i)       ;     for (; i >= 2; --i) printf( %d , p[i]);     printf( %d/ , p[i] - 1);     for (i = n - e; p[i] == 0; --i)       ;     for (; i >= 1; --i) printf( %d , p[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp[5005][15], oo = 1e5;   char str[5005];   int solve(int i, int s) {     if (str[i] == 0 and s == 2) {       return 0;     } else if (str[i] == 0 and s != 2) {       return oo;     } else if (~dp[i][s]) {       return dp[i][s];     } else {       int ans = 0;       if (s == 0) {         if (str[i] ==  a ) {           ans = min(solve(i + 1, s), solve(i + 1, 1));         } else {           ans = min(solve(i + 1, s) + 1, solve(i + 1, 1));         }       } else if (s == 1) {         if (str[i] ==  b ) {           ans = min(solve(i + 1, s), solve(i + 1, 2));         } else {           ans = min(solve(i + 1, s) + 1, solve(i + 1, 2));         }       } else if (s == 2) {         if (str[i] ==  a ) {           ans = solve(i + 1, s);         } else {           ans = solve(i + 1, s) + 1;         }       }       return dp[i][s] = ans;     }   }   int main() {     scanf(  %s , str);     memset(dp, -1, sizeof dp);     if (str[1] == 0) {       printf( 1 n );     } else {       printf( %d n , strlen(str) - solve(0, 0));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   int cnt[maxn][26];   int dif[26];   int getAns() {     int cc = 0;     for (int i = 0; i < 26; ++i)       if (dif[i]) {         ++cc;       }     return cc;   }   int main() {     string s;     cin >> s;     int len = s.length();     for (int i = 1; i <= len; ++i) {       for (int k = 0; k < 26; ++k) cnt[i][k] = cnt[i - 1][k];       ++cnt[i][s[i - 1] -  a ];     }     int q;     cin >> q;     while (q--) {       int l, r;       cin >> l >> r;       --l;       for (int i = 0; i < 26; ++i) dif[i] = cnt[r][i] - cnt[l][i];       int tot = getAns();       if (tot == 1) {         if (r - l == 1)           cout <<  YES  << endl;         else           cout <<  NO  << endl;       } else if (tot == 2) {         if (s[l] != s[r - 1])           cout <<  YES  << endl;         else           cout <<  NO  << endl;       } else {         cout <<  YES  << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   inline int add(int a, int b) {     a += b;     if (a >= mod) a -= mod;     return a;   }   inline int mult(int a, int b) {     long long t = 1ll * a * b;     if (t >= mod) t %= mod;     return t;   }   int k, dp[1010][1010];   int main() {     scanf( %d , &k);     dp[1][0] = dp[1][1] = 1;     for (int p = 1; p < k; p++) {       for (int i = 0; i <= (p >= 10 ? k : min(k, 1 << p)); i++) {         for (int j = 0; i + j <= (p >= 10 ? k : min(k, (1 << (p + 1)))); j++) {           int tmp = mult(dp[p][i], dp[p][j]);           dp[p + 1][i + j] = add(dp[p + 1][i + j], tmp);           dp[p + 1][i + j + 1] = add(dp[p + 1][i + j + 1], tmp);           dp[p + 1][i + j] = add(dp[p + 1][i + j], mult(tmp, mult(i + j, 2)));           if (i + j)             dp[p + 1][i + j - 1] =                 add(dp[p + 1][i + j - 1], mult(tmp, mult(i + j, i + j - 1)));         }       }     }     printf( %d n , dp[k][1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 3e5 + 5;   int a[M], b[M], c, lst[M], sl[M], ans[M];   struct D {     int p1, p, s;   };   queue<D> q;   int read() {     int s = 0, t = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) t = -1;     for (; isdigit(ch); ch = getchar()) s = s * 10 + ch -  0 ;     return s * t;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) a[i] = read();     for (int i = 1; i <= n; i++) b[i] = read();     int h = n;     q.push({n, n, 0});     while (!q.empty()) {       int p1 = q.front().p1, p = q.front().p, s = q.front().s;       q.pop();       if (!p) {         c = s;         break;       }       for (int i = h - 1; i >= p - a[p]; i--)         lst[i] = p1, q.push({i, i + b[i], s + 1}), h = i;     }     if (!c) return printf( -1 ), 0;     printf( %d n , c);     for (int i = 1, x = 0; i <= c; i++, x = lst[x]) ans[i] = x;     for (int i = c; i; i--) printf( %d  , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   const int E4 = 1e4 + 2;   const int E5 = 1e5 + 2;   const int E6 = 1e6 + 2;   const int MOD = 1e9 + 7;   const int INF = 1e9 + 8;   const double eps = 1e-12;   const double pi = 3.14159265359;   const long long INFL = 1ll * INF * INF;   void getTime(double sub = 0.0) {     cout <<  Time :   << fixed << clock() * 1.0 / CLOCKS_PER_SEC - sub <<   n ;   }   double getClock() { return clock() * 1.0 / CLOCKS_PER_SEC; }   long long pw(long long a, long long n, long long K = MOD) {     return (n ? (pw(((a % K) * (a % K)) % K, n / 2ll, K) *                  ((n & 1ll) ? (a % K) : 1ll)) %                     K               : 1ll);   }   int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   int lcm(int a, int b) { return a * (b / gcd(a, b)); }   long long lcm(long long a, long long b) { return (b / gcd(a, b)) * a; }   int fact(int n) { return n > 0 ? n * fact(n - 1) : 1; }   long long fact(long long n) { return n > 0 ? n * fact(n - 1) : 1; }   int choose(int k, int n) {     if (k > n) return 0;     k = (n - k > k ? n - k : k);     if (k == 0) return 1;     int R = n;     for (int i = 2; i <= k; i++) {       R = R * (n - i + 1) / i;     }     return R;   }   long long choose(long long k, long long n) {     if (k > n) return 0;     k = (n - k > k ? n - k : k);     if (k == 0) return 1;     int R = n;     for (int i = 2; i <= k; i++) {       R = R * (n - i + 1) / i;     }     return R;   }   int lowbit(int m) { return m & (-m); }   int hibit(int m) {     for (int i = 30; i >= 0; i--)       if ((1 << i) & m) return i;     return 0;   }   long long hibit(long long m) {     for (int i = 62; i >= 0; i--)       if ((1ll << i) & m) return i;     return 0;   }   int getbit(int x, int b) { return (x >> b) & 1; }   long long getbit(long long x, int b) { return (x >> b) & 1; }   int setbit(int x, int b) { return x | (1 << b); }   void _setbit(int &x, int b) { x = setbit(x, b); }   long long setbit(long long x, int b) { return x | (1ll << b); }   void _setbit(long long &x, int b) { x = setbit(x, b); }   int unsetbit(int x, int b) { return x & ((~0) - (1 << b)); }   void _unsetbit(int &x, int b) { x = unsetbit(x, b); }   int bitcnt(int x) {     x = x - ((x >> 1) & 0x55555555);     x = (x & 0x33333333) + ((x >> 2) & 0x33333333);     return ((x + (x >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;   }   long long bitcnt(long long x) {     int p1 = (x >> 32) & ((1ll << 32) - 1);     int p2 = x & ((1ll << 32) - 1);     return bitcnt(p1) + bitcnt(p2);   }   string bin(int x, int len = -1) {     if (len == -1) {       len = hibit(x) + 1;     }     string res =   ;     for (int i = len - 1; i >= 0; i--) res.push_back(getbit(x, i) +  0 );     return res;   }   string bin(long long x, int len = -1) {     if (len == -1) {       len = hibit(x) + 1;     }     string res =   ;     for (int i = len - 1; i >= 0; i--) res.push_back(getbit(x, i) +  0 );     return res;   }   int zerocnt(int x) { return hibit(x) - bitcnt(x) + 1; }   int zerocnt(long long x) { return hibit(x) - bitcnt(x) + 1; }   struct IO {     IO operator>>(int &n) const {       n = 0;       bool sign = 0;       int a = getchar();       while (a <  0  || a >  9 ) {         if (a ==  - ) {           sign = 1;           a = getchar();           break;         }         a = getchar();       }       while (a >=  0  && a <=  9 ) {         n = (n << 1) + (n << 3) + a -  0 ;         a = getchar();       }       if (sign) n = ~(n - 1);       return *this;     }     IO operator>>(long long &n) {       n = 0;       bool sign = 0;       char c = getchar();       while (c <  0  || c >  9 ) {         if (c ==  - ) sign = true;         c = getchar();       }       while (c >=  0  && c <=  9 ) {         n = n * 10 + c - 48;         c = getchar();       }       if (sign) n = ~(n - 1);       return *this;     }     IO operator>>(double &x) const {       scanf( %lf , &x);       return *this;     }     IO operator>>(char &x) const {       do {         x = getchar();       } while (x ==     || x ==   n );       return *this;     }     IO operator>>(string &s) const {       cin >> s;       return *this;     }     IO operator<<(const int x) const {       printf( %d , x);       return *this;     }     IO operator<<(const double x) const {       printf( %lf , x);       return *this;     }     IO operator<<(const char x) const {       putchar(x);       return *this;     }     IO operator<<(const long long x) const {       cout << x;       return *this;     }     IO operator<<(string x) {       printf( %s , (x.c_str()));       return *this;     }   } in, out;   namespace Input {   template <template <typename, typename...> class Container, typename T>   void cinv(Container<T> &a, int n) {     for (int i = 0; i < n; i++) {       T t;       cin >> t;       a.push_back(t);     }   }   template <typename T>   void cinv(T *ptr, int len) {     for (int i = 0; i < len; i++) {       in >> *(ptr + i);     }   }   template <typename T>   void cinv(T A, int n, int m) {     for (int i = 0; i < n; i++) {       cinv(A[i], m);     }   }   }  // namespace Input   namespace Output {   void split(char A) {     if (A !=  0 ) {       putchar(A);     }   }   template <typename T>   void Print(T A, char sp =  0 ) {     out << A;     split(sp);   }   template <typename T1, typename T2>   void Print(pair<T1, T2> A, char sp =  0 ) {     cout <<  (  << A.first <<  ,  << A.second <<  ) ;     split(sp);   }   template <typename T>   void Print(T A[], int len, char sp =    ) {     for (int i = 0; i < len; i++) {       out << A[i];       split(sp);     }   }   template <typename T>   void Print(T *A, int n, int m, char nsp =    , char sp =   n ) {     for (int i = 0; i < n; i++) {       Print(A[i], m, nsp);       split(sp);     }   }   template <template <typename, typename...> class Container, typename T>   void Print(Container<T> C, char sp =    ) {     for (auto i : C) {       Print(i);       split(sp);     }   }   template <typename T>   void Print(stack<T> A, char sp =    ) {     while (A.size()) {       Print(A.top());       split(sp);       A.pop();     }   }   template <template <typename, typename...> class Container, typename T1,             typename T2>   void Print(Container<T1, T2> C, char sp =    ) {     for (auto i : C) {       Print(i);       split(sp);     }   }   template <typename T>   void Printl(T A) {     Print(A,   n );   }   }  // namespace Output   using namespace Output;   using namespace Input;   int x;   int o;   int n;   int e;   int r;   int z;   int main() {     string s;     cin >> x >> s;     for (auto i : s) {       if (i ==  o ) {         o++;       }       if (i ==  n ) {         n++;       }       if (i ==  e ) {         e++;       }       if (i ==  r ) {         r++;       }       if (i ==  z ) {         z++;       }     }     for (int i = 0; i < n; i++) {       cout << 1 <<    ;     }     for (int i = 0; i < z; i++) {       cout << 0 <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> dp;   int l[305], c[305];   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> l[i];     for (int i = 0; i < n; i++) cin >> c[i];     dp[0] = 0;     for (int i = 0; i < n; i++) {       for (auto x : dp) {         int a = gcd(x.first, l[i]);         if (dp.count(a))           dp[a] = min(dp[a], x.second + c[i]);         else           dp[a] = x.second + c[i];       }     }     if (dp.count(1))       cout << dp[1] << endl;     else       cout << -1 << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   using uint = unsigned int;   using ll = long long;   using ull = unsigned long long;   constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }   int bsr(int x) { return 31 - __builtin_clz(x); }   template <class T>   using V = vector<T>;   template <class T>   using VV = V<V<T>>;   template <class T>   T pow(T x, ll n) {     T r = 1;     while (n) {       if (n & 1) r *= x;       x *= x;       n >>= 1;     }     return r;   }   template <uint MD>   struct ModInt {     uint v;     ModInt() : v{0} {}     ModInt(ll v) : v{normS(v % MD + MD)} {}     static uint normS(const uint &x) { return (x < MD) ? x : x - MD; };     static ModInt make(const uint &x) {       ModInt m;       m.v = x;       return m;     }     ModInt operator+(const ModInt &r) const { return make(normS(v + r.v)); }     ModInt operator-(const ModInt &r) const { return make(normS(v + MD - r.v)); }     ModInt operator*(const ModInt &r) const { return make((ull)v * r.v % MD); }     ModInt &operator+=(const ModInt &r) { return *this = *this + r; }     ModInt &operator-=(const ModInt &r) { return *this = *this - r; }     ModInt &operator*=(const ModInt &r) { return *this = *this * r; }     static ModInt inv(const ModInt &x) { return pow(ModInt(x), MD - 2); }   };   using Mint = ModInt<TEN(9) + 7>;   const int MD = 1001001;   int factor[MD];   void first() {     fill(begin(factor), end(factor), -1);     for (int i = 2; i < MD; i++) {       if (factor[i] != -1) continue;       for (int j = i; j < MD; j += i) {         factor[j] = i;       }     }   }   int main() {     first();     V<int> id2v[300];     map<V<int>, int> vs;     int id[MD];     for (int i = 1; i < MD; i++) {       map<int, int> mp;       int x = i;       while (factor[x] != -1) {         mp[factor[x]]++;         x /= factor[x];       }       V<int> v;       for (auto p : mp) {         v.push_back(p.second);       }       sort(begin(v), end(v));       if (vs.count(v)) {         id[i] = vs[v];       } else {         int nid = int(vs.size());         vs[v] = nid;         id[i] = nid;         id2v[nid] = v;       }     }     int C = vs.size();     static Mint to1[MD][25], to0[MD][25];     to0[0][0] = 1;     for (int i = 1; i < 30; i++) {       to1[0][i] = 1;     }     for (int i = 1; i < MD; i++) {       Mint sm0, sm1;       for (int j = 0; j < 25; j++) {         sm0 += to0[i - 1][j];         sm1 += to1[i - 1][j];         to0[i][j] = sm0;         to1[i][j] = sm1;       }     }     int q;     scanf( %d , &q);     for (int i = 0; i < q; i++) {       int r, n;       scanf( %d %d , &r, &n);       V<int> v = id2v[id[n]];       Mint co[11];       co[0] = 1;       int nw = 1;       for (int d : v) {         for (int i = nw; i >= 0; i--) {           co[i] = co[i] * to0[r][d];           if (i) co[i] += co[i - 1] * to1[r][d];         }         nw++;       }       Mint ans = 0;       for (int i = 0; i < 11; i++) {         ans += co[i] * Mint(1 << i);       }       printf( %d n , ans.v);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cross(const complex<int>& a, const complex<int>& b) {     return a.real() * b.imag() - a.imag() * b.real();   }   int hypot2(const complex<int>& a) {     return a.real() * a.real() + a.imag() * a.imag();   }   int N;   vector<complex<int> > pt;   vector<complex<int> > hull(const vector<complex<int> >& p) {     int n = p.size(), k = 0;     if (n < 3) return p;     vector<complex<int> > h(2 * n);     for (int i = 0; i < n; ++i) {       while (k >= 2 && cross(h[k - 1] - h[k - 2], p[i] - h[k - 2]) <= 0) --k;       h[k++] = p[i];     }     for (int i = n - 2, e = k + 1; i >= 0; --i) {       while (k >= e && cross(h[k - 1] - h[k - 2], p[i] - h[k - 2]) <= 0) --k;       h[k++] = p[i];     }     h.resize(k);     h.pop_back();     return h;   }   bool with_one(const complex<int>& o, int m) {     vector<complex<int> > p;     copy_if(pt.begin(), pt.end(), back_inserter(p),             [&](const complex<int>& a) { return hypot2(a - o) >= m; });     auto h = hull(p);     switch (h.size()) {       case 0:       case 1:         return false;       case 2:         return hypot2(h[1] - h[0]) >= m;     }     int n = h.size();     auto nx = [&](int i) { return i + 1 == n ? 0 : i + 1; };     auto cal = [&](int i) { return h[nx(i)] - h[i]; };     for (int i = 0, j = 0; i < n; ++i) {       while (cross(cal(i), cal(j)) >= 0) {         j = nx(j);         if (hypot2(h[j] - h[i]) >= m) return true;       }     }     return false;   }   bool ok(int m) {     for (const complex<int>& p : pt) {       if (with_one(p, m)) return true;     }     return false;   }   int main() {     cout.precision(20);     cout << fixed;     cin >> N;     for (int i = 0, x, y; i < N; ++i) {       cin >> x >> y;       pt.push_back({x, y});     }     sort(pt.begin(), pt.end(), [](const complex<int>& a, const complex<int>& b) {       return a.real() < b.real() || a.real() == b.real() && a.imag() < b.imag();     });     int l = 0, h = 1e9;     while (l + 1 < h) {       int m = (l + h) / 2;       if (ok(m))         l = m;       else         h = m;     }     cout << sqrt(l) / 2 <<   n ;     return 0;   }


#include<bits/stdc++.h>   #define rb(a,b,c) for(int a=b;a<=c;++a)   #define rl(a,b,c) for(int a=b;a>=c;--a)   #define LL long long   #define IT iterator   #define PB push_back   #define II(a,b) make_pair(a,b)   #define FIR first   #define SEC second   #define FREO freopen( check.out , w ,stdout)   #define rep(a,b) for(int a=0;a<b;++a)   #define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())   #define random(a) rng()%a   #define ALL(a) a.begin(),a.end()   #define POB pop_back   #define ff fflush(stdout)   #define fastio ios::sync_with_stdio(false)   #define check_min(a,b) a=min(a,b)   #define check_max(a,b) a=max(a,b)   using namespace std;   //inline int read(){   //    int x=0;   //    char ch=getchar();   //    while(ch< 0 ||ch> 9 ){   //        ch=getchar();   //    }   //    while(ch>= 0 &&ch<= 9 ){   //        x=(x<<1)+(x<<3)+(ch^48);   //        ch=getchar();   //    }   //    return x;   //}   const int INF=0x3f3f3f3f;   typedef pair<int,int> mp;   /*}   */   const int MAXN=505;   int t,n,a[MAXN<<1][MAXN];   bool era[MAXN<<1],cho[MAXN<<1];   int cnt[MAXN][MAXN];   int fa[MAXN<<1];   int root(int x){    return fa[x]=(x==fa[x]? x:root(fa[x]));   }   vector<int> g[MAXN<<1];   bool col[MAXN<<1];   bool vis[MAXN<<1];   void dfs(int now){    vis[now]=1;    for(auto it:g[now]){     if(!vis[it]){      col[it]=col[now]^1;      dfs(it);     }    }   }   void solve(){    scanf( %d ,&n);    rb(i,1,n*2) rb(j,1,n) scanf( %d ,&a[i][j]);    memset(era,0,sizeof(era));    memset(vis,0,sizeof(vis));    memset(cho,0,sizeof(cho));    memset(cnt,0,sizeof(cnt));    memset(col,0,sizeof(col));    rb(i,1,n*2) rb(j,1,n) cnt[j][a[i][j]]++;    rb(T,1,n){     mp Tmp=II(-1,-1);     rb(j,1,n){      rb(k,1,n) if(cnt[j][k]==1){       Tmp=II(j,k);       break;      }      if(Tmp.FIR!=-1) break;     }     if(Tmp.FIR==-1) break;     int x;     rb(j,1,2*n){      if(!era[j]&&a[j][Tmp.FIR]==Tmp.SEC){       x=j;       break;      }     }     cho[x]=1;     rb(j,1,2*n) if(!era[j]&&j!=x){      rb(k,1,n) if(j!=x&&a[j][k]==a[x][k]) era[j]=1;      if(era[j]){       rb(k,1,n) cnt[k][a[j][k]]--;      }     }     rb(k,1,n) cnt[k][a[x][k]]--;    }    rb(i,1,n*2) g[i].clear(),fa[i]=i;    rb(i,1,n*2) era[i]|=cho[i];    rb(i,1,n*2) if(!era[i]) rb(j,i+1,n*2) if(!era[j]) {     bool E=0;     rb(k,1,n) if(a[i][k]==a[j][k]){      E=1;      break;     }     if(E){      g[i].PB(j);      g[j].PB(i);      fa[root(i)]=root(j);     }    }    rb(i,1,n*2) if(!era[i]&&!vis[i]) dfs(i);    int ans=1;    vector<int> res;    rb(i,1,n*2){     if(!era[i]&&col[i]==0){      res.PB(i);     }    }    rb(i,1,n*2) if(!era[i]&&root(i)==i) ans=(ans+ans)%998244353;    rb(i,1,2*n) if(cho[i]) res.PB(i);    printf( %d n ,ans);    for(auto it:res){     printf( %d  ,it);    }    puts(  );   }   int main(){    scanf( %d ,&t);    while(t--) solve();    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       long long int a[n];       long long int b[n];       int pos = 1;       for (int i = 0; i < n; ++i) {         cin >> a[i];         b[i] = a[i];       }       sort(b, b + n);       reverse(b, b + n);       for (int i = 0; i < n; i++) {         if (b[i] != a[i]) {           pos = 0;           break;         }         if (i != 0 && b[i] == b[i - 1]) pos = 0;       }       if (!pos)         cout <<  YES               <<   n ;       else         cout <<  NO               <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int N, K;   int a[2210], b[2210];   int cnt[2210];   long long func(void) {     int i, j = N;     int aans = -1, bans = -1, bid = -1;     long long best = (1ll << 60);     for (i = N - 1; i >= 0; i--) {       while (j > i || (j > 0 && cnt[j - 1] > 0)) {         j--;         if (b[j] > 0 && (bid == -1 || b[j] < b[bid])) bid = j;       }       if (a[i] > 0 && bid != -1 && a[i] + b[bid] < best) {         best = a[i] + b[bid];         aans = i;         bans = bid;       }     }     if (aans < bans) {       for (i = aans; i < bans; i++) cnt[i]++;     } else {       for (i = aans - 1; i >= bans; i--) cnt[i]--;     }     a[aans] = b[bans] = 0;     return best;   }   int main(void) {     int i;     cin >> N >> K;     for ((i) = 0; (i) < (int)(N); (i)++) cin >> a[i];     for ((i) = 0; (i) < (int)(N); (i)++) cin >> b[i];     long long ans = 0;     for ((i) = 0; (i) < (int)(K); (i)++) ans += func();     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 2;   const int mod = 998244353;   void inc(int& x, const int& y) { (x += y) >= mod ? x -= mod : 0; }   void dec(int& x, const int& y) { x < y ? x += mod - y : x -= y; }   void cmax(int& x, const int& y) { x = x > y ? x : y; }   int n, k, m;   int l[N], r[N], x[N], pos[N], a[N], f[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> k >> m;     for (int i = 1; i <= m; i++) cin >> l[i] >> r[i] >> x[i];     int ans = 1;     for (int p = 0; p <= k - 1; p++) {       for (int i = 1; i <= n + 1; i++) pos[i] = a[i] = 0;       for (int i = 1; i <= m; i++)         if (x[i] >> p & 1)           ++a[l[i]], --a[r[i] + 1];         else           cmax(pos[r[i] + 1], l[i]);       for (int i = 2; i <= n + 1; i++) a[i] += a[i - 1], cmax(pos[i], pos[i - 1]);       f[0] = 1;       int sum = 1, l = 0;       for (int i = 1; i <= n + 1; i++) {         while (l < pos[i]) dec(sum, f[l]), f[l++] = 0;         f[i] = a[i] ? 0 : sum, inc(sum, f[i]);       }       ans = 1ll * ans * f[n + 1] % mod;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void Solution() {     int n, k;     cin >> n >> k;     int a[n];     vector<int> v;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (5 - a[i] >= k) {         v.push_back(a[i]);       }     }     cout << v.size() / 3 << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     Solution();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, x, y;   long long r;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long binsearch(long long i, long long j, long long w, long long m) {     if (i == j) {       if (i * w <= a && i * m <= b) return i;       return -1;     }     if (i == j - 1) {       if (j * w <= a && j * m <= b) return j;       if (i * w <= a && i * m <= b) return i;       return -1;     }     long long mid = (i + j) / 2;     if (mid * w <= a && mid * m <= b) return binsearch(mid, j, w, m);     return binsearch(i, mid - 1, w, m);   }   int main() {     cin >> a >> b >> x >> y;     r = x / y;     long long h = gcd(x, y);     long long k = binsearch(0, 2000000000, x / h, y / h);     if (k == -1) {       cout << 0 <<     << 0;       return 0;     }     cout << k * (x / h) <<     << k * (y / h);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     int x, y;   };   int n, k, l[1000002], r[1000002];   point a[1000002];   bool cmp(point a, point b) { return a.x < b.x; }   void nhap() {     cin >> n >> k;     for (int i = 1; i <= n; ++i) {       cin >> a[i].x;       l[i] = 0;       r[i] = 0;     }     for (int i = 1; i <= n; ++i) cin >> a[i].y;     sort(a + 1, a + n + 1, cmp);   }   void sol1() {     int cur = 1, st = 1;     l[1] = 1;     for (int i = 2; i <= n; ++i) {       if (a[i].x - a[st].x <= k)         cur++;       else {         while (a[i].x - a[st].x > k) {           ++st;         }         cur = i - st + 1;       }       l[i] = max(l[i - 1], cur);     }   }   void sol2() {     int cur = 1, st = n;     r[n] = 1;     for (int i = n - 1; i >= 1; --i) {       if (a[st].x - a[i].x <= k)         cur++;       else {         while (a[st].x - a[i].x > k) --st;         cur = st - i + 1;       }       r[i] = max(r[i + 1], cur);     }   }   void xuly() {     int kq = 0;     for (int i = 1; i < n; ++i) kq = max(kq, l[i] + r[i + 1]);     if (kq == 0) ++kq;     cout << kq <<   n ;   }   int main(int argc, const char* argv[]) {     int t;     cin >> t;     for (int i = 1; i <= t; ++i) {       nhap();       sol1();       sol2();       xuly();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fre() {     freopen( c://test//input.in ,  r , stdin);     freopen( c://test//output.out ,  w , stdout);   }   template <class T1, class T2>   inline void gmax(T1 &a, T2 b) {     if (b > a) a = b;   }   template <class T1, class T2>   inline void gmin(T1 &a, T2 b) {     if (b < a) a = b;   }   const int N = 1010, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;   int n;   int a[N], b[N];   int main() {     while (~scanf( %d , &n)) {       for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);       sort(a + 1, a + n + 1);       int p = 1;       for (int i = 1; i <= n; i += 2) {         b[i] = a[p++];       }       for (int i = 2; i <= n; i += 2) {         b[i] = a[p++];       }       bool flag = 1;       for (int i = 1; i <= n; i += 2) {         if (i < n) {           if (b[i] > b[i + 1]) flag = 0;         }         if (i > 1) {           if (b[i] > b[i - 1]) flag = 0;         }       }       if (!flag)         puts( Impossible );       else {         for (int i = 1; i <= n; ++i) printf( %d  , b[i]);         puts(  );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   int n, k, a[N];   long long seg[4 * N + 4], dp[N + 1][12];   void update(int p, int l, int r, int indx, long long val) {     if (l == r) {       seg[p] = val;       return;     }     int mid = l + (r - l) / 2;     if (indx <= mid)       update(p * 2, l, mid, indx, val);     else       update(p * 2 + 1, mid + 1, r, indx, val);     seg[p] = seg[p * 2] + seg[p * 2 + 1];   }   long long get(int p, int l, int r, int a, int b) {     if (l >= a && r <= b) {       return seg[p];     }     if (l > b || r < a) {       return 0;     }     int mid = l + (r - l) / 2;     return get(p * 2, l, mid, a, b) + get(p * 2 + 1, mid + 1, r, a, b);   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; ++i) scanf( %d , a + i);     for (int i = 0; i <= N; ++i) dp[i][1] = 1;     for (int j = 2; j <= k + 1; ++j) {       memset(seg, 0, sizeof seg);       for (int i = 0; i < n; ++i) {         dp[i][j] = get(1, 0, n - 1, 1, a[i] - 1);         update(1, 0, n - 1, a[i], dp[i][j - 1]);       }     }     long long ans = 0;     for (int i = 0; i < n; ++i) {       ans += dp[i][k + 1];     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   const long long INF = 0x3f3f3f3f3f3f3f3f;   const long long llinf = (1LL << 61);   const int inf = (1 << 30);   const int nmax = 1e3 + 50;   const int mod = 1e9 + 7;   using namespace std;   int n, m, i, j, a[nmax][nmax], aa[nmax][nmax], b[nmax][nmax], bb[nmax][nmax],       ca[nmax][nmax], cb[nmax][nmax], mn;   char c[nmax][nmax];   vector<pair<pair<int, int>, int> > ans;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cerr.tie(0);     cout.tie(0);     cin >> n >> m;     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) cin >> c[i][j];     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++)         if (c[i][j] ==  * ) a[i][j] = a[i][j - 1] + 1;       for (j = m; j >= 1; j--)         if (c[i][j] ==  * ) aa[i][j] = aa[i][j + 1] + 1;     }     for (i = 1; i <= m; i++) {       for (j = 1; j <= n; j++)         if (c[j][i] ==  * ) b[j][i] = b[j - 1][i] + 1;       for (j = n; j >= 1; j--)         if (c[j][i] ==  * ) bb[j][i] = bb[j + 1][i] + 1;     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) {         if (c[i][j] ==  * ) {           mn = min(min(a[i][j], aa[i][j]), min(b[i][j], bb[i][j]));           if (mn > 1) {             ca[i][j - mn + 1]++;             ca[i][j + mn]--;             cb[i - mn + 1][j]++;             cb[i + mn][j]--;             ans.push_back({{i, j}, mn - 1});           }         }       }     }     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) ca[i][j] += ca[i][j - 1];     for (i = 1; i <= m; i++)       for (j = 1; j <= n; j++) cb[j][i] += cb[j - 1][i];     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++)         if (c[i][j] ==  *  && !ca[i][j] && !cb[i][j])           return cout << -1 << endl, 0;     cout << ans.size() << endl;     for (i = 0; i < ans.size(); i++)       cout << ans[i].first.first <<     << ans[i].first.second <<                << ans[i].second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class trio {    public:     long long first, second, third;   };   long long gcdExtended(long long a, long long b, long long *x, long long *y) {     if (a == 0) {       *x = 0, *y = 1;       return b;     }     long long x1, y1;     long long gcd = gcdExtended(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     return gcd;   }   long long modInverse(long long a, long long m) {     long long x, y;     long long g = gcdExtended(a, m, &x, &y);     long long res = (x % m + m) % m;     return res;   }   long long power(long long x, long long y) {     long long ans = 1, second = x;     while (y) {       if (y & 1) {         ans *= second;         ans %= 1000000007;       }       second *= second;       second %= 1000000007;       y >>= 1;     }     return ans;   }   const long long N = 51;   long long dp1[N];   long long dp3[N];   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     __int128 val = 1;     dp1[0] = 1;     dp1[1] = 1;     dp1[2] = 1;     for (long long i = 3; i < N; ++i) {       val *= (i - 2);       val = min(val, (__int128)1000000000000000001);       dp1[i] = val;     }     dp3[0] = 1;     dp3[1] = 1;     for (long long i = 2; i < N; ++i) {       val = 0;       for (long long j = 1; j < i + 1; ++j) {         val += (__int128)dp3[i - j] * dp1[j];         val = min(val, (__int128)1000000000000000001);       }       dp3[i] = val;     }     long long third;     cin >> third;     while (third--) {       long long n, k;       cin >> n >> k;       long long arr[N] = {0};       if (dp3[n] < k) {         cout << -1 <<   n ;         continue;       }       for (long long i = 1; i <= n;) {         long long len, left, st;         __int128 count;         for (long long j = i; j <= n; ++j) {           len = j - i + 1;           left = n - i - len + 1;           st = j;           count = (__int128)dp1[len] * dp3[left];           count = min(count, (__int128)1000000000000000001);           if (count < k) {             k -= (count);           } else {             break;           }         }         arr[i] = st;         set<long long> available;         for (long long j = i; j < i + len; ++j) {           available.insert(j);         }         available.erase(st);         for (long long j = i + 1; j < i + len; ++j) {           if (j == i + len - 1) {             arr[j] = *(available.begin());             break;           }           for (auto it : available) {             long long cur = it;             while (cur != j && cur) {               cur = arr[cur];             }             if (cur == j) continue;             count = (__int128)dp1[len - (j - i)] * dp3[left];             count = min(count, (__int128)1000000000000000001);             if (count < k) {               k -= (count);             } else {               arr[j] = it;               break;             }           }           available.erase(arr[j]);         }         i += len;       }       for (long long i = 1; i < n + 1; ++i) {         cout << arr[i] <<    ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   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;   }   int cond = (long long)1;   void _main() {     int n, w, m;     scanf( %d%d%d , &n, &w, &m);     int guests = m;     int usedbottles = 0;     int botid = 1;     int fuel = m;     int used = 0;     bool ok = 1;     vector<vector<pair<int, int> > > sol;     for (int i = (0); i < (m); ++i) {       int needfuel = n;       vector<pair<int, int> > result;       while (needfuel > 0) {         if (fuel > 0) {           int use = min(fuel, needfuel);           result.push_back(pair<int, int>(botid, use));           fuel -= use;           needfuel -= use;           ++used;           if (used > 2) ok = 0;           if (fuel == 0) {             botid++;             fuel = m;             used = 0;           }         } else           assert(0);       }       sol.push_back(result);     }     if (!ok) cout <<  NO  << endl;     cout.precision(6);     if (ok) {       cout <<  YES  << endl;       for (int i = (0); i < (m); ++i) {         for (int j = (0); j < ((int)(sol[i]).size()); ++j) {           if (j) cout <<    ;           long double myfuel = (long double)sol[i][j].second * w / m;           cout << fixed << sol[i][j].first <<     << myfuel;         }         cout << endl;       }     }   }   int main(int argc, char **argv) {     string p =  ../gcj/source/  + string(  ) + argv[0][strlen(argv[0]) - 1];     for (int i = (0); i < (argc); ++i)       if (strcmp(argv[i],  1n ) == 0) {         freopen( 1.in ,  r , stdin);       }     for (int i = (0); i < (argc); ++i)       if (strcmp(argv[i],  2n ) == 0) {         freopen( 2.in ,  r , stdin);       }     for (int i = (0); i < (argc); ++i)       if (strcmp(argv[i],  3n ) == 0) {         freopen( 3.in ,  r , stdin);       }     for (int i = (0); i < (argc); ++i)       if (strcmp(argv[i],  4n ) == 0) {         freopen( 4.in ,  r , stdin);       }     for (int i = (0); i < (argc); ++i)       if (strcmp(argv[i],  5n ) == 0) {         freopen( 5.in ,  r , stdin);       }     for (int i = (0); i < (argc); ++i)       if (strcmp(argv[i],  s0 ) == 0) {         freopen((p +  -small-0.in ).c_str(),  r , stdin);         freopen((p +  -small-0.out ).c_str(),  w , stdout);       }     for (int i = (0); i < (argc); ++i)       if (strcmp(argv[i],  s1 ) == 0) {         freopen((p +  -small-1.in ).c_str(),  r , stdin);         freopen((p +  -small-1.out ).c_str(),  w , stdout);       }     for (int i = (0); i < (argc); ++i)       if (strcmp(argv[i],  s2 ) == 0) {         freopen((p +  -small-2.in ).c_str(),  r , stdin);         freopen((p +  -small-2.out ).c_str(),  w , stdout);       }     for (int i = (0); i < (argc); ++i)       if (strcmp(argv[i],  l0 ) == 0) {         freopen((p +  -large-0.in ).c_str(),  r , stdin);         freopen((p +  -large-0.out ).c_str(),  w , stdout);       }     for (int i = (0); i < (argc); ++i)       if (strcmp(argv[i],  q ) == 0) cond = 1 << 30;     _main();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, x;   int a[255];   long long dp[255][255][255];   int main() {     cin >> n >> k >> x;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i <= n; i++)       for (int j = 0; j <= k; j++) {         for (int p = 0; p <= x; p++) {           dp[i][j][p] = -LLONG_MAX;         }       }     dp[0][1][0] = 0;     for (int i = 0; i < n; i++) {       for (int j = 1; j <= k; j++)         for (int choose = 0; choose <= x; choose++) {           if (dp[i][j][choose] == -LLONG_MAX) continue;           if (j != k) {             dp[i + 1][j + 1][choose] =                 max(dp[i + 1][j + 1][choose], dp[i][j][choose]);           }           dp[i + 1][1][choose + 1] =               max(dp[i + 1][1][choose + 1], dp[i][j][choose] + a[i]);         }     }     long long res = -LLONG_MAX;     for (int i = 0; i <= k; i++) res = max(res, dp[n][i][x]);     if (res == -LLONG_MAX) res = -1;     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 11, mod = 998244353;   int ans, n, k, blo, bel[N], f[N], g[N], a[N], L[N], R[N], las[N], bef[N],       lim[N], sum[411][N], Sum[411];   inline void inc(int &x, int y) {     x += y;     if (x >= mod) x -= mod;   }   inline void deal(int l, int r, int x) {     int o = bel[l];     for (register int i = l; i <= r; ++i) {       if (f[i] <= lim[o]) inc(Sum[o], mod - g[i - 1]);       inc(sum[o][f[i]], mod - g[i - 1]);       f[i] += x;       inc(sum[o][f[i]], g[i - 1]);       if (f[i] <= lim[o]) inc(Sum[o], g[i - 1]);     }   }   inline void modify(int l, int r, int x) {     int o;     if (bel[l] == bel[r]) {       deal(l, r, x);       return;     }     o = bel[l];     deal(l, R[o], x);     o = bel[r];     deal(L[o], r, x);     for (register int i = bel[l] + 1; i <= bel[r] - 1; ++i) {       if (x == 1) inc(Sum[i], mod - sum[i][lim[i]]);       lim[i] -= x;       if (x == -1) inc(Sum[i], sum[i][lim[i]]);     }   }   int main() {     scanf( %d%d , &n, &k);     blo = sqrt(n);     for (register int i = 1; i <= n; ++i) {       scanf( %d , a + i), bel[i] = (i - 1) / blo + 1;       las[i] = bef[a[i]];       bef[a[i]] = i;     }     for (register int i = 1; i <= n; ++i) {       if (!L[bel[i]]) L[bel[i]] = i;       R[bel[i]] = i;     }     for (register int i = 1; i <= bel[n]; ++i) lim[i] = k;     g[0] = 1;     for (register int i = 1; i <= n; ++i) {       inc(sum[bel[i]][0], g[i - 1]), inc(Sum[bel[i]], g[i - 1]);       modify(las[i] + 1, i, 1);       if (las[i]) modify(las[las[i]] + 1, las[i], -1);       ans = 0;       for (register int j = 1; j <= bel[i]; ++j) inc(ans, Sum[j]);       g[i] = ans;     }     printf( %d n , g[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using pii = pair<int, int>;   const int N = 1000 + 20;   int n, m, q, part[N][N];   string s[N];   inline int get(int x) { return (__builtin_popcount(x) & 1 ? -1 : +1); }   inline int get(int x, int y) { return get(x) * get(y); }   inline pii calc(int x) {     int a = x / 2, b = x / 2;     if (x & 1) {       if (get(x - 1) == 1)         a++;       else         b++;     }     return pii(a, b);   }   inline pii calc(int x, int y) {     pii p1 = calc(x), p2 = calc(y);     return pii(p1.first * p2.first + p1.second * p2.second,                p1.first * p2.second + p1.second * p2.first);   }   inline int f(int x, int y) {     int res = 0;     int X = x / n, Y = y / m;     x %= n, y %= m;     pii p = calc(X, Y);     res += part[n][m] * p.first + (n * m - part[n][m]) * p.second;     p = calc(X);     if (get(Y) == -1) swap(p.first, p.second);     res += part[n][y] * p.first + (n * y - part[n][y]) * p.second;     p = calc(Y);     if (get(X) == -1) swap(p.first, p.second);     res += part[x][m] * p.first + (x * m - part[x][m]) * p.second;     if (get(X, Y) == 1)       res += part[x][y];     else       res += (x * y - part[x][y]);     return res;   }   int32_t main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m >> q;     for (int i = 0; i < n; i++) {       cin >> s[i];       for (int j = 0; j < m; j++) {         part[i + 1][j + 1] =             (s[i][j] ==  1 ) + part[i][j + 1] + part[i + 1][j] - part[i][j];       }     }     while (q--) {       int x1, hlkhjl, x2, y2;       cin >> x1 >> hlkhjl >> x2 >> y2;       x1--, hlkhjl--;       cout << f(x2, y2) - f(x1, y2) - f(x2, hlkhjl) + f(x1, hlkhjl) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long a, b, m;     long long vx, vy, vz;     cin >> a >> b >> m >> vx >> vy >> vz;     double time = -((double)(m) / (double)(vy));     double xc = (double)(a) / 2.0 + time * vx;     if (xc >= 0) {       long long p = xc / a;       if (p % 2 == 1) {         xc = (p + 1) * a - xc;       } else {         xc -= p * a;       }     } else {       long long p = xc / a;       if (p % 2 == 0) {         xc -= p * a;         xc = -xc;       } else {         xc -= p * a;         xc = -xc;         xc = a - xc;       }     }     double zc = time * vz;     if (zc >= 0) {       long long p = zc / b;       if (p % 2 == 1) {         zc = (p + 1) * b - zc;       } else {         zc -= p * b;       }     } else {       long long p = zc / b;       if (p % 2 == 0) {         zc -= p * b;         zc = -zc;       } else {         zc -= p * b;         zc = -zc;         zc = b - zc;       }     }     printf( %0.12llf %0.12llf , xc, zc);   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 7;   long long a[MAXN];   int n, k, x;   void print() {     for (int i = 1; i <= n; ++i) cout << a[i] <<    ;     exit(0);   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> k >> x;     vector<int> zeros;     int n_pos = 0, n_neg = 0, n_zer = 0;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       if (a[i] > 0) ++n_pos;       if (a[i] < 0) ++n_neg;       if (a[i] == 0) ++n_zer, zeros.push_back(i);     }     if (n_zer) {       if (n_zer > k) print();       if ((n_zer & 1) == (n_neg & 1))         a[zeros.back()] += 1LL * x, zeros.pop_back(), ++n_pos, --k;       for (auto v : zeros) a[v] -= 1LL * x, ++n_neg, --k;     }     set<pair<long long, int> > s;     for (int i = 1; i <= n; ++i) s.insert({abs(a[i]), i});     if ((n_neg & 1) == 0) {       int id = s.begin()->second;       bool save = (a[id] > 0);       s.erase(s.begin());       while (k && (a[id] == 0 || ((a[id] > 0) == save))) {         if (save)           a[id] -= 1LL * x;         else           a[id] += 1LL * x;         --k;       }       if (k == 0) print();       s.insert({abs(a[id]), id});     }     while (k--) {       int id = s.begin()->second;       s.erase(s.begin());       if (a[id] > 0)         a[id] += 1LL * x;       else         a[id] -= 1LL * x;       s.insert({abs(a[id]), id});     }     print();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e6 + 10;   int n, k, count1;   int a[MAX];   int res = 1e19 + 10;   int binary_search1(int x, int l, int r) {     int res = 0;     while (l <= r) {       int mid = (l + r) >> 1;       if (a[mid] <= x) {         res = mid;         l = mid + 1;       } else         r = mid - 1;     }     return res;   }   int binary_search2(int x, int l, int r) {     int res = 0;     while (l <= r) {       int mid = (l + r) >> 1;       if (a[mid] < x) {         l = mid + 1;       } else {         res = mid;         r = mid - 1;       }     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     scanf( %d %d n , &n, &k);     count1 = 0;     for (int i = 1; i <= n; i++) {       char s;       scanf( %c , &s);       if (s ==  0 ) {         a[++count1] = i;       }     }     sort(a + 1, a + 1 + count1);     k += 1;     for (int i = 1; i <= count1 - k + 1; i++) {       int l = i;       int r = k + i - 1;       int pos1 = binary_search1((a[l] + a[r]) >> 1, l, r);       int pos2 = binary_search2((a[l] + a[r]) >> 1, l, r);       if (pos1 != 0) {         res = min(res, max(a[pos1] - a[l], a[r] - a[pos1]));       }       if (pos2 != 0) {         res = min(res, max(a[pos2] - a[l], a[r] - a[pos2]));       }     }     printf( %d , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x7fffffff;   const int Size = 1000 * 1000 + 1;   char buffer[Size];   int solution(int nTest) {     int n, m, K;     scanf( %d%d%d , &n, &m, &K);     vector<string> name;     vector<vector<int> > a, b, c;     for (int i = 0; i < n; i++) {       scanf( %s , buffer);       name.push_back(buffer);       int ta, tb, tc;       vector<int> va, vb, vc;       for (int j = 0; j < m; j++) {         scanf( %d%d%d , &ta, &tb, &tc);         va.push_back(ta);         vb.push_back(tb);         vc.push_back(tc);       }       a.push_back(va);       b.push_back(vb);       c.push_back(vc);     }     int res = 0;     for (int i = 0; i < n; i++) {       for (int k = 0; k < n; k++) {         int t = K;         vector<pair<int, int> > v;         for (int j = 0; j < m; j++) {           v.push_back(make_pair(b[k][j] - a[i][j], j));         }         sort(v.begin(), v.end());         reverse(v.begin(), v.end());         int sum = 0;         for (int j = 0; j < m; j++) {           if (v[j].first >= 0) {             int ct = c[i][v[j].second];             if (t >= ct) {               sum += ct * v[j].first;               t -= ct;             } else {               sum += t * v[j].first;               t = 0;             }           }         }         res = max(res, sum);       }     }     printf( %d n , res);     return 0;   }   int main() {     if (0) {       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);     }     int i = 0, n = 99999;     while (i < n && solution(i)) {       i++;     }     return 0;   }


#include <bits/stdc++.h>   const int N = 1e5, V = 5;   const unsigned long long MOD = 1ull << 58, INV5 = 14757395258967641293ull;   struct Com {     unsigned long long a[V];     inline void clear() { a[0] = a[1] = a[2] = a[3] = a[4] = 0; }     inline Com() { clear(); }     inline unsigned long long &operator[](int x) { return a[x]; }     inline const unsigned long long &operator[](const int &x) const {       return a[x];     }     inline Com operator+(const Com &b) const {       Com c;       for (int i = 0; i < V; i++) c[i] = a[i] + b[i];       return c;     }     inline Com operator-(const Com &b) const {       Com c;       for (int i = 0; i < V; i++) c[i] = a[i] - b[i];       return c;     }     inline Com operator*(const unsigned long long &b) const {       Com c;       for (int i = 0; i < V; i++) c[i] = a[i] * b;       return c;     }     inline Com operator*(const Com &b) const {       static unsigned long long d[V << 1];       for (int i = 0; i < V; i++)         for (int j = 0; j < V; j++) d[i + j] += a[i] * b[j];       Com c;       for (int i = 0; i < V; i++) c[i] = d[i] + d[i + V], d[i] = d[i + V] = 0;       return c;     }     inline Com &operator+=(const Com &b) { return *this = *this + b; }     inline Com &operator*=(const unsigned long long &b) {       return *this = *this * b;     }     inline Com &operator*=(const Com &b) { return *this = *this * b; }     inline void out() {       printf( (%llu,%llu,%llu,%llu,%llu) n , a[0], a[1], a[2], a[3], a[4]);     }     inline unsigned long long val() { return (a[0] - a[4]) >> 5; }     inline bool operator!=(const Com &b) const {       for (int i = 0; i < V; i++)         if (a[i] != b[i]) return 1;       return 0;     }   } w[2][V << 1], a[N];   inline Com qpow(Com a, int b) {     Com c;     c[0] = 1;     for (; b; b >>= 1, a *= a)       if (b & 1) c *= a;     return c;   }   inline void pre() {     w[0][0][0] = w[1][0][0] = 1;     w[0][1][3] = w[1][1][2] = -1;     for (int i = 2; i < V << 1; i++) {       w[0][i] = w[0][i - 1] * w[0][1], w[1][i] = w[1][i - 1] * w[1][1];     }   }   const int pw[V] = {1, 10, 100, 1000, 10000};   inline void fft(int opt) {     for (int i = 0; i < V; i++)       for (int j = 0; j < N; j++)         if (!((j / pw[i]) % 10)) {           static Com f[V << 1];           for (int a = 0; a < V << 1; a++)             for (int b = 0; b < V << 1; b++) {               f[a] += ::a[j + b * pw[i]] *                       (opt ? w[0][(10 - a * b % 10) % 10] : w[0][a * b % 10]);             }           for (int a = 0; a < V << 1; a++) {             ::a[j + a * pw[i]] = f[a];             f[a].clear();           }         }     if (opt) {       unsigned long long INV = INV5 * INV5 * INV5 * INV5 * INV5;       for (int i = 0; i < N; i++) a[i] *= INV;     }   }   int n;   int main() {     pre();     scanf( %d , &n);     for (int i = 1, x; i <= n; i++) {       scanf( %d , &x);       a[x][0]++;     }     fft(0);     for (int i = 0; i < N; i++) a[i] = qpow(a[i], n);     fft(1);     for (int i = 0; i < n; i++) printf( %llu n , a[i].val() % MOD);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const int maxn = 2e5;   const int INF = 0x7fffffff;   const int mod = 1e9 + 7;   const double eps = 1e-7;   const double Pi = acos(-1.0);   inline int read_int() {     char c;     int ret = 0, sgn = 1;     do {       c = getchar();     } while ((c <  0  || c >  9 ) && c !=  - );     if (c ==  - )       sgn = -1;     else       ret = c -  0 ;     while ((c = getchar()) >=  0  && c <=  9 ) ret = ret * 10 + (c -  0 );     return sgn * ret;   }   inline long long read_ll() {     char c;     long long ret = 0, sgn = 1;     do {       c = getchar();     } while ((c <  0  || c >  9 ) && c !=  - );     if (c ==  - )       sgn = -1;     else       ret = c -  0 ;     while ((c = getchar()) >=  0  && c <=  9 ) ret = ret * 10 + (c -  0 );     return sgn * ret;   }   int n, arr[maxn + 5], res[maxn + 5];   vector<int> dc, ic;   int main() {     n = read_int();     for (int i = 1; i <= n; ++i) arr[i] = read_int();     for (int i = 1; i <= n; ++i) {       if (dc.empty() && ic.empty()) {         if (i < n && arr[i] <= arr[i + 1])           ic.push_back(i);         else           dc.push_back(i);       } else if (dc.empty()) {         int id = ic.back();         if (arr[i] <= arr[id])           dc.push_back(i);         else {           if (i + 1 <= n && arr[i] <= arr[i + 1])             ic.push_back(i);           else             dc.push_back(i);         }       } else if (ic.empty()) {         int id = dc.back();         if (arr[i] >= arr[id])           ic.push_back(i);         else {           if (i + 1 <= n && arr[i] <= arr[i + 1])             ic.push_back(i);           else             dc.push_back(i);         }       } else {         int id1 = ic.back(), id2 = dc.back();         if (arr[i] <= arr[id1] && arr[i] >= arr[id2]) {           cout <<  NO  << endl;           return 0;         } else if (arr[i] > arr[id1] && arr[i] < arr[id2]) {           if (i + 1 <= n && arr[i] <= arr[i + 1])             ic.push_back(i);           else             dc.push_back(i);         } else if (arr[i] > arr[id1])           ic.push_back(i);         else           dc.push_back(i);       }     }     for (int i = 0; i < dc.size(); ++i) res[dc[i]] = 1;     cout <<  YES  << endl;     for (int i = 1; i <= n; ++i) printf( %d%c , res[i],    n [i == n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 505, maxmax = 1000000;   int n, javab[maxn][maxn];   vector<int> v;   int dp(int l, int r) {     int x = maxmax;     if (l == r) {       javab[l][r] = 1;       return 1;     }     if (l == r - 1) {       if (v[r] == v[l]) {         javab[l][r] = 1;         return 1;       } else {         javab[l][r] = 2;         return 2;       }     }     if (javab[l][r - 1] != 0)       x = min(x, javab[l][r - 1] + 1);     else {       x = min(x, dp(l, r - 1) + 1);     }     for (int i = r - 1; i >= l; i--) {       if (v[r] == v[i]) {         if (i == l) {           if (javab[l + 1][r - 1] != 0) {             x = min(x, javab[l + 1][r - 1]);           } else             x = min(x, dp(l + 1, r - 1));           break;         }         if (javab[l][i - 1] != 0) {           if (javab[i][r] != 0) {             x = min(x, javab[l][i - 1] + javab[i][r]);           } else {             x = min(x, javab[l][i - 1] + dp(i, r));           }         } else {           if (javab[i][r] != 0) {             x = min(x, dp(l, i - 1) + javab[i][r]);           } else {             x = min(x, dp(l, i - 1) + dp(i, r));           }         }       }     }     javab[l][r] = x;     return x;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       v.push_back(x);     }     int javab = dp(0, v.size() - 1);     cout << javab;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( no-stack-protector )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( fast-math )   #pragma GCC target( sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native )   using namespace std;   template <typename T>   void uin(T &a, T b) {     if (b < a) {       a = b;     }   }   template <typename T>   void uax(T &a, T b) {     if (b > a) {       a = b;     }   }   const long long N = 100 * 1000 + 228;   vector<long long> g[N];   long long deg[N];   long long h[N], p[N];   void dfs(long long v, long long par = -1) {     h[v] = (par == -1 ? 0 : h[par] + 1);     p[v] = par;     for (long long to : g[v]) {       if (to != par) dfs(to, v);     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long n;     cin >> n;     for (long long i = 0; i < n - 1; ++i) {       long long u, v;       cin >> u >> v;       ++deg[u];       ++deg[v];       g[u].emplace_back(v);       g[v].emplace_back(u);     }     long long root = 1;     for (long long i = 1; i <= n; ++i) {       if (deg[i] > 1) {         root = i;         break;       }     }     dfs(root);     bool even = 0, odd = 0;     for (long long i = 1; i <= n; ++i) {       if (deg[i] == 1) {         if (h[i] & 1)           odd = 1;         else           even = 1;       }     }     long long min_colors = 0;     if (even && odd) {       min_colors = 3;     } else {       min_colors = 1;     }     vector<long long> pars;     long long leafs = 0;     for (long long i = 1; i <= n; ++i) {       if (deg[i] == 1) {         pars.emplace_back(p[i]);         ++leafs;       }     }     sort(pars.begin(), pars.end());     pars.erase(unique(pars.begin(), pars.end()), pars.end());     long long max_colors = (long long)pars.size();     max_colors += (n - 1 - leafs);     cout << min_colors <<     << max_colors <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   const int MAXLEN = 15;   long long dp[MAXLEN + 1][2];   long long dpleq[MAXLEN + 1][2];   inline int conv(char c) {     if (isdigit(c)) return c -  0 ;     if (islower(c)) return c -  a  + 10;     assert(false);   }   long long calc(char* s) {     int slen = strlen(s);     long long ret = 0;     for (int mx = (0); mx < (16); ++mx) {       int pos = mx / 4, off = mx % 4;       if (pos >= slen) continue;       memset(dp, 0, sizeof(dp));       memset(dpleq, 0, sizeof(dpleq));       dp[0][0] = dpleq[0][0] = 1;       for (int i = (0); i < (slen); ++i)         for (int j = (0); j < (2); ++j)           for (int k = (0); k <= (mx); ++k) {             if (i == pos && (k & (1 << off)) == 0) continue;             int nj = j == 1 || k == mx ? 1 : 0;             dp[i + 1][nj] += dp[i][j];             if (k < conv(s[i]))               dpleq[i + 1][nj] += dp[i][j];             else if (k == conv(s[i]))               dpleq[i + 1][nj] += dpleq[i][j];           }       long long cur = dpleq[slen][1];       ret += cur;     }     return ret;   }   void dec(char* s) {     for (int i = 0;; ++i)       if (s[i] ==  0 )         s[i] =  f ;       else {         assert(s[i] !=   0 );         if (s[i] ==  a )           s[i] =  9 ;         else           --s[i];         break;       }     int slen = strlen(s);     while (slen >= 2 && s[slen - 1] ==  0 ) --slen;     s[slen] =   0 ;   }   int nq;   char sl[MAXLEN + 1], sr[MAXLEN + 1];   long long solve() {     reverse(sl, sl + strlen(sl));     reverse(sr, sr + strlen(sr));     long long ret = calc(sr);     if (strcmp(sl,  0 ) != 0) {       dec(sl);       ret -= calc(sl);     }     return ret;   }   void run() {     scanf( %d , &nq);     for (int qi = (0); qi < (nq); ++qi) {       scanf( %s%s , sl, sr);       printf( %lld n , solve());     }   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     int ans = 0;     int score = -1;     for (int i = 0; i < n; i++) {       int sub, subsc = 0;       scanf( %d , &sub);       subsc += sub;       scanf( %d , &sub);       subsc += sub;       scanf( %d , &sub);       subsc += sub;       scanf( %d , &sub);       subsc += sub;       if (subsc > score) {         ans++;       }       if (!i) score = subsc;     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 450, inf = 1e8;   int n1, n2, m, r, b, node, s, t, S, T, a[N], id[N];   char col1[N], col2[N];   int head[N], ce = 1, inq[N], dis[N], maxflow, mincost, need;   struct edge {     int to, nxt, cap, flow, w;   } e[5000];   void lnk(int a, int b, int c, int w) {     e[++ce] = (edge){b, head[a], c, 0, w}, head[a] = ce;     e[++ce] = (edge){a, head[b], 0, 0, -w}, head[b] = ce;   }   bool bfs() {     for (int i = 1; i <= node; ++i) dis[i] = inf, inq[i] = 0;     dis[s] = 0, inq[s] = 1;     queue<int> q;     q.push(s);     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = head[u]; i; i = e[i].nxt) {         int v = e[i].to;         if (e[i].cap > e[i].flow && dis[v] > dis[u] + e[i].w) {           dis[v] = dis[u] + e[i].w;           if (!inq[v]) q.push(v), inq[v] = 1;         }       }       inq[u] = 0;     }     return dis[t] < inf;   }   int dfs(int u, int lim) {     if (u == t) return mincost += dis[t] * lim, lim;     int tag = 0;     inq[u] = 1;     for (int i = head[u]; i; i = e[i].nxt)       if (e[i].cap > e[i].flow && dis[e[i].to] == dis[u] + e[i].w &&           !inq[e[i].to]) {         int d = dfs(e[i].to, min(lim - tag, e[i].cap - e[i].flow));         tag += d, e[i].flow += d, e[i ^ 1].flow -= d;         if (tag == lim) {           inq[u] = 0;           return tag;         }       }     return tag;   }   int main() {     scanf( %d%d%d%d%d , &n1, &n2, &m, &r, &b);     scanf( %s , col1 + 1);     scanf( %s , col2 + 1);     node = n1 + n2, S = ++node, T = ++node, s = ++node, t = ++node;     for (int i = 1; i <= n1; ++i)       if (col1[i] ==  R )         ++a[i], --a[S], lnk(S, i, inf, 0);       else if (col1[i] ==  B )         --a[i], ++a[T], lnk(i, T, inf, 0);       else         lnk(S, i, inf, 0), lnk(i, T, inf, 0);     for (int i = 1; i <= n2; ++i)       if (col2[i] ==  R )         --a[i + n1], ++a[T], lnk(i + n1, T, inf, 0);       else if (col2[i] ==  B )         ++a[i + n1], --a[S], lnk(S, i + n1, inf, 0);       else         lnk(S, i + n1, inf, 0), lnk(i + n1, T, inf, 0);     for (int i = 1; i <= T; ++i)       if (a[i] > 0)         lnk(s, i, a[i], 0), need += a[i];       else if (a[i] < 0)         lnk(i, t, -a[i], 0);     lnk(T, S, inf, 0);     for (int i = 1, u, v; i <= m; ++i)       scanf( %d%d , &u, &v), id[i] = ce + 1, lnk(u, v + n1, 1, r),                              lnk(v + n1, u, 1, b);     while (bfs()) maxflow += dfs(s, inf);     if (maxflow < need) {       puts( -1 );       return 0;     }     printf( %d n , mincost);     for (int i = 1; i <= m; ++i)       if (e[id[i]].flow)         putchar( R );       else if (e[id[i] + 2].flow)         putchar( B );       else         putchar( U );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int search_factor(int n) {     if (n % 2 == 0) {       return n / 2;     } else {       for (int i = (n - 1) / 2; i >= 1; i -= 1) {         if (n % i == 0) return i;       }     }   }   int main() {     int n;     cin >> n;     long long int sum = n;     while (n != 1) {       int res = search_factor(n);       sum += res;       n = res;     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct sTree {     int L, R;     int pl, pr;     long long sum_m;     long long sum_r;   } tree[2000000];   int treeSize;   int s[100009];   int r[100009];   int m[100009];   int BuildTree(int L, int R) {     int cur = treeSize++;     tree[cur].L = L;     tree[cur].R = R;     tree[cur].sum_r = r[L];     if (L < R) {       tree[cur].pl = BuildTree(L, (L + R) / 2);       tree[cur].pr = BuildTree((L + R) / 2 + 1, R);       tree[cur].sum_r = tree[tree[cur].pl].sum_r + tree[tree[cur].pr].sum_r;     }     return cur;   }   int Toggle(int i, int cur) {     tree[treeSize] = tree[cur];     cur = treeSize;     treeSize++;     if (tree[cur].L == tree[cur].R) {       tree[cur].sum_m = m[i];       tree[cur].sum_r = 0;       return cur;     }     if (i <= tree[tree[cur].pl].R)       tree[cur].pl = Toggle(i, tree[cur].pl);     else       tree[cur].pr = Toggle(i, tree[cur].pr);     tree[cur].sum_m = tree[tree[cur].pl].sum_m + tree[tree[cur].pr].sum_m;     tree[cur].sum_r = tree[tree[cur].pl].sum_r + tree[tree[cur].pr].sum_r;     return cur;   }   pair<long long, long long> Get(int L, int R, int cur) {     if (L <= tree[cur].L && R >= tree[cur].R) {       return make_pair(tree[cur].sum_m, tree[cur].sum_r);     }     pair<long long, long long> ans = make_pair(0, 0);     if (L <= tree[tree[cur].pl].R && tree[tree[cur].pl].L <= R) {       pair<long long, long long> tmp = Get(L, R, tree[cur].pl);       ans.first += tmp.first;       ans.second += tmp.second;     }     if (L <= tree[tree[cur].pr].R && tree[tree[cur].pr].L <= R) {       pair<long long, long long> tmp = Get(L, R, tree[cur].pr);       ans.first += tmp.first;       ans.second += tmp.second;     }     return ans;   }   int roots[100001];   long long Calc(int L, int R, int time) {     if (L == R) {       return min((long long)m[L], s[L] + (long long)time * r[L]);     }     pair<long long, long long> tmp = Get(L, R, roots[time]);     return tmp.first + (long long)time * tmp.second;   }   vector<int> ind[100001];   int n;   int fwt[100001];   int fwt_sum(int k) {     int ans = 0;     while (k) {       ans += fwt[k];       k -= k & (-k);     }     return ans;   }   void fwt_add(int k, int d) {     while (k <= n) {       fwt[k] += d;       k += k & (-k);     }   }   int fwt_getKth(int k) {     int ans = 0;     for (int i = 18; i >= 0; i--) {       if (ans + (1 << i) <= n && fwt[ans + (1 << i)] < k) {         ans += (1 << i);         k -= fwt[ans];       }     }     return ans + 1;   }   int lastTime[100001];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d %d %d , &s[i], &m[i], &r[i]);       if (m[i] == 0) r[i] = 0;       if (r[i]) {         ind[m[i] / r[i] + 1].push_back(i);       }     }     roots[0] = BuildTree(1, n);     for (int k = 1; k <= 100000; k++) {       roots[k] = roots[k - 1];       for (int i = 0; i < ind[k].size(); i++)         roots[k] = Toggle(ind[k][i], roots[k]);     }     for (int k = 1; k <= n; k++) {       fwt_add(k, 1);     }     int Q;     scanf( %d , &Q);     while (Q--) {       int time, L, R;       scanf( %d %d %d , &time, &L, &R);       long long ans = 0;       int last, ind = L;       while (ind <= R) {         int cur = fwt_sum(ind);         int next = fwt_getKth(cur + 1) - 1;         cur = fwt_getKth(cur);         ans += Calc(ind, min(R, next), min(time - lastTime[cur], 100000));         s[cur] = 0;         if (cur >= L) fwt_add(cur, -1);         last = lastTime[cur];         ind = next + 1;       }       printf( %I64d n , ans);       fwt_add(L, 1);       lastTime[L] = time;       if (R + 1 <= n && fwt_sum(R + 1) == fwt_sum(R)) {         lastTime[R + 1] = last;         fwt_add(R + 1, 1);       }     }   }


#include <bits/stdc++.h>   using namespace std;   void rd(long long &x) { scanf( %lld , &x); }   void rd(long long &x, long long &y) { scanf( %lld%lld , &x, &y); }   void rd(long long &x, long long &y, long long &z) {     scanf( %lld%lld%lld , &x, &y, &z);   }   void rd(long long &x, long long &y, long long &z, long long &s) {     scanf( %lld%lld%lld%lld , &x, &y, &z, &s);   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  { ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  } ;   }   template <typename T>   ostream &operator<<(ostream &os, const set<T> &v) {     os <<  [ ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  ] ;   }   void faltu() { cerr << endl; }   template <typename T>   void faltu(T a[], int n) {     for (int i = 0; i < n; ++i) cerr << a[i] <<    ;     cerr << endl;   }   template <typename T, typename... hello>   void faltu(T arg, const hello &...rest) {     cerr << arg <<    ;     faltu(rest...);   }   string s;   const long long N = 2e5 + 5;   long long n, m, cnt[N], mx[N][2];   bool visit[N];   pair<long long, long long> dp[N];   pair<long long, long long> back(long long pos) {     if (pos >= n) return make_pair(0LL, 0LL);     if (visit[pos]) return dp[pos];     visit[pos] = 1;     pair<long long, long long> &r = dp[pos];     r = back(pos + 1);     if (mx[pos][0] == m) {       pair<long long, long long> q = back(pos + m);       q.first++;       q.second += cnt[pos + m - 1];       if (pos) q.second -= cnt[pos - 1];       if (q.first > r.first || (q.first == r.first && q.second < r.second)) r = q;     }     return r;   }   int main() {     rd(n);     cin >> s;     rd(m);     for (long long i = 0; i < (n); i++) {       cnt[i] = (s[i] ==  ? );       if (i) cnt[i] += cnt[i - 1];     }     for (int i = n; i < N; i++) cnt[i] = cnt[i - 1];     for (int i = n - 1; i >= 0; i--) {       if (s[i] ==  a ) {         mx[i][0] = min(mx[i + 1][1] + 1, m);         mx[i][1] = 0;       } else if (s[i] ==  b ) {         mx[i][1] = min(mx[i + 1][0] + 1, m);         mx[i][0] = 0;       } else {         mx[i][0] = min(mx[i + 1][1] + 1, m);         mx[i][1] = min(mx[i + 1][0] + 1, m);       }     }     pair<long long, long long> p = back(0);     cout << (long long)p.second;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int tc = 0;   long long a, b, c, d;   inline long long sum(long long i) {     return -a * i + b * (d - 1) * i + i * (i - 1) / 2 * b * d;   }   inline long long calc(long long i) {     if (i < 0) return 0;     long long ans = 0;     if (i < (c + 1) / d) {       ans = min(ans, sum(i) - a + i * b);     } else {       i = (c + 1) / d;       ans = min(ans, sum(i) - a + (i - 1) * b + (c + 1 % d > 0) * b);       ans = min(ans, sum(i));       ans = min(ans, -a);     }     return ans;   }   inline void solve() {     ++tc;     scanf( %lld%lld%lld%lld , &a, &b, &c, &d);     if (c < d) {       if (b * c >= a)         printf( %lld n , a);       else         puts( -1 );     } else {       long long i = floor(-(-a + b * (d - 1) + b - 1.0 * b * d / 2) / (b * d));       i = max(i, 0ll);       long long dmg =           (-a + b * (d - 1) + b * d * ((c + 1) / d - 1) + ((c + 1) % d) * b);       long long ans = 0;       if (dmg < 0) {         puts( -1 );       } else {         ans = min(ans, calc(i - 1));         ans = min(ans, calc(i));         ans = min(ans, calc(i + 1));         ans = min(ans, calc(i + 2));         printf( %lld n , -ans);       }     }     return;   }   int main() {     int T;     for (scanf( %d , &T); T--; solve())       ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int m, n;   int a[110][110], b[110][110];   template <typename T>   inline void chkmax(T &x, T y) {     x = max(x, y);   }   template <typename T>   inline void chkmin(T &x, T y) {     x = min(x, y);   }   template <typename T>   inline void read(T &x) {     T f = 1;     x = 0;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -f;     for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c -  0 ;     x *= f;   }   int main() {     read(m);     read(n);     memset(a, 255, sizeof(a));     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= n; j++) {         read(b[i][j]);         if (b[i][j] == 0) {           for (int k = 1; k <= n; k++) a[i][k] = 0;           for (int k = 1; k <= m; k++) a[k][j] = 0;         }       }     }     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= n; j++) {         if (a[i][j] == -1) a[i][j] = 1;       }     }     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= n; j++) {         int res = 0;         for (int k = 1; k <= n; k++) res |= a[i][k];         for (int k = 1; k <= m; k++) res |= a[k][j];         if (res != b[i][j]) {           printf( NO n );           return 0;         }       }     }     printf( YES n );     for (int i = 1; i <= m; i++) {       for (int j = 1; j < n; j++) {         printf( %d  , a[i][j]);       }       printf( %d n , a[i][n]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct DT {     int l, r, x;   };   DT qr[300005];   int n, m, ans[300005], tree[4 * 300005];   void update(int nd, int b, int e, int l, int r, int v) {     if (r < l || l < 1 || r > n) return;     if (b > r || e < l) return;     if (tree[nd] != 0 && b != e) {       tree[2 * nd] = tree[nd];       tree[2 * nd + 1] = tree[nd];       tree[nd] = 0;     }     if (b >= l && e <= r) {       tree[nd] = v;       return;     }     int md = (b + e) / 2;     update(2 * nd, b, md, l, r, v);     update(2 * nd + 1, md + 1, e, l, r, v);   }   int query(int nd, int b, int e, int x, int v) {     if (b == e) {       if (v == 0)         return tree[nd];       else         return v;     }     int md = (b + e) / 2;     if (v == 0) v = tree[nd];     if (x <= md)       return query(2 * nd, b, md, x, v);     else       return query(2 * nd + 1, md + 1, e, x, v);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= m; i++) {       cin >> qr[i].l >> qr[i].r >> qr[i].x;     }     for (int i = m; i >= 1; i--) {       int l, r, x;       l = qr[i].l;       r = qr[i].r;       x = qr[i].x;       if (x >= l && x <= r) {         update(1, 1, n, l, x - 1, x);         update(1, 1, n, x + 1, r, x);       } else {         update(1, 1, n, l, r, x);       }     }     for (int i = 1; i <= n; i++) {       ans[i] = query(1, 1, n, i, 0);     }     for (int i = 1; i <= n; i++) {       if (i < n)         cout << ans[i] <<    ;       else         cout << ans[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   const int INF = 1000000009;   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(nullptr);     int a, b;     cin >> a >> b;     if ((a || b) && max(a, b) - min(a, b) < 2) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<pair<int, int>, int> > v;   int a[(int)(1e5 + 50)];   string s;   void solve() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       s += (char)(x +  0 );     }     for (int i = 0; i < s.size();) {       int st = i, len = 0;       char c = s[i];       while (i < s.size() && c == s[i]) {         len++;         i++;       }       v.push_back(make_pair(make_pair(st, len), (int)(c -  0 )));     }     int len = v.size();     if (v[len - 1].second == 1 ||         (v[len - 1].first.second == 2 && v[len - 1].second == 0 && len < 3)) {       printf( NO );       return;     }     printf( YES n );     string ans;     if (v[len - 1].first.second == 2) {       for (int i = 0; i < len - 3; i++) {         char toAdd = (char)(v[i].second +  0 );         for (int j = 0; j < v[i].first.second; j++) {           ans += toAdd;           ans +=  -> ;         }       }       for (int j = 0; j < v[len - 3].first.second - 1; j++) {         ans +=  0 ;         ans +=  -> ;       }       ans +=  (0->( ;       for (int i = 0; i < v[len - 2].first.second; i++) {         ans +=  1 ;         ans +=  -> ;       }       ans +=  0))->0 ;       cout << ans;       return;     }     if (v[len - 1].first.second % 2 == 0) {       ans +=  ( ;       for (int i = 0; i < v[len - 1].first.second - 3; i++) {         ans +=  0-> ;       }       ans +=  (0->0) ;       ans +=  ->0 ;       ans +=  ) ;     } else {       ans +=  ( ;       for (int i = 0; i < v[len - 1].first.second - 1; i++) {         ans +=  0-> ;       }       ans +=  0 ;       ans +=  ) ;     }     if (len - 1 == 0) {       cout << ans;       return;     }     reverse(ans.begin(), ans.end());     ans +=  >- ;     ans +=  )1 ;     for (int i = 0; i < v[len - 2].first.second - 1; i++) {       ans +=  >-1 ;     }     ans +=  ( ;     for (int i = len - 3; i >= 0; i--) {       ans +=  >- ;       char toAdd = (char)(v[i].second +  0 );       int curlen = v[i].first.second;       for (int j = 0; j < curlen - 1; j++) {         ans += toAdd;         ans +=  >- ;       }       ans += toAdd;     }     reverse(ans.begin(), ans.end());     cout << ans;   }   int main() {     int t = 1;     for (int i = 1; i <= t; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NMAX = 755;   const long long INF = 1LL << 62;   long long dp[NMAX][NMAX];   int main() {     cin.sync_with_stdio(false);     int n, m;     cin >> n >> m;     vector<int> v(n);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     for (int i = n - 1; i >= 0; i--) {       for (int j = 0; j <= n - i; j++) {         if (j) {           dp[i][j] = dp[i + 1][j - 1];         } else {           dp[i][j] = INF;         }         if (v[i] >= 0) {           dp[i][j] = min(dp[i][j], max(0LL, dp[i + 1][j] - v[i]));         } else {           dp[i][j] = min(dp[i][j], dp[i + 1][j] - v[i]);         }       }     }     for (; m; m--) {       long long x;       cin >> x;       int l = 0;       int r = n;       int ans = n;       while (l <= r) {         int mi = (l + r) / 2;         if (dp[0][mi] <= x) {           ans = mi;           r = mi - 1;         } else {           l = mi + 1;         }       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n;     cin >> n;     long long int k;     cin >> k;     vector<long long int> arr(n, 0);     long long int cnt = 0;     for (int i = 0; i < n; ++i) {       cin >> arr[i];       long long int var = 0;       while (arr[i] > 0) {         long long int rem = arr[i] % 10;         if (rem == 4 || rem == 7) {           var++;         }         arr[i] /= 10;       }       if (var > k) {         cnt++;       }     }     cout << n - cnt <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   bool Max(T1& a, T2 b) {     return a < b ? a = b, 1 : 0;   }   template <typename T1, typename T2>   bool Min(T1& a, T2 b) {     return a > b ? a = b, 1 : 0;   }   const int N = 1000001;   bool prime[N];   vector<long long> pri;   vector<pair<long long, long long> > nv, sv;   long long n, m, s;   long long ans;   void rec(long long i, long long prod) {     if (i == sv.size()) {       ans++;       return;     }     auto cur = sv[i];     for (int j = 0; j < (cur.second + 1); ++j) {       rec(i + 1, prod);       if ((prod *= cur.first) > n) break;     }   }   long long pow(long long a, long long p) {     long long ret = 1;     while (p) {       if (p & 1) ret *= a;       a *= a;       p >>= 1;     }     return ret;   }   void solve() {     long long v;     n = 1;     for (int i = 0; i < (3); ++i) {       cin >> v;       n *= v;     }     m = 1;     for (int i = 0; i < (3); ++i) {       cin >> v;       m *= v;     }     s = 2;     for (int i = 0; i < (3); ++i) {       cin >> v;       s *= v;     }     long long ts = s, tn = n;     nv.clear();     sv.clear();     for (auto& e : pri) {       if (e * e > ts) break;       long long cnt = 0;       while (ts % e == 0) {         cnt++;         ts /= e;       }       if (cnt) sv.emplace_back(e, cnt);     }     if (ts > 1) sv.emplace_back(ts, 1);     for (auto& e : pri) {       if (e * e > tn) break;       long long cnt = 0;       while (tn % e == 0) {         cnt++;         tn /= e;       }       if (cnt) nv.emplace_back(e, cnt);     }     if (tn > 1) nv.emplace_back(tn, 1);     ans = 0;     rec(0, 1);     sv.emplace_back(N, 1);     vector<long long> tmp;     long long i = 0;     for (auto& e : nv) {       while (sv[i].first < e.first) i++;       if (sv[i].first > e.first) {         tmp.emplace_back(e.first);       } else {         if (sv[i].second < e.second)           tmp.emplace_back(pow(e.first, sv[i].second + 1));         i++;       }     }     long long sz = tmp.size();     for (int sub = 0; sub < (1 << sz); ++sub) {       long long t = 1;       bool add = 1;       for (int i = 0; i < (sz); ++i)         if ((sub >> i) & 1) {           t *= tmp[i];           add ^= 1;         }       if (add)         ans += m / t;       else         ans -= m / t;     }     cout << ans <<   n ;   }   void init() {     for (int i = 2; i <= (N - 1); ++i)       if (!prime[i]) {         pri.emplace_back(i);         for (long long j = (long long)i * i; j < N; j += i) prime[j] = 1;       }   }   int main(void) {     ios::sync_with_stdio(false);     cin.tie(0);     cout.setf(ios::fixed);     cout.precision(20);     init();     int TC = 1;     cin >> TC;     for (int TI = 1; TI <= (TC); ++TI) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void test_case() {     int n;     long long k;     cin >> n >> k;     int l, r[2] = {-1, -1};     long long curr[2] = {k, k}, ans[2] = {0, 0}, monsters;     for (int i = 0; i < n; i++) {       int old_r[2] = {r[0], r[1]}, tmp_r;       long long old_curr[2] = {curr[0], curr[1]}, old_ans[2] = {ans[0], ans[1]};       cin >> l >> tmp_r >> monsters;       ans[0] = -1;       for (int j = 0; j < 2; j++) {         if (old_ans[j] == -1) continue;         if (old_curr[j] + (tmp_r - l) * k < monsters) continue;         if (ans[0] != -1 && ans[0] < old_ans[j] + monsters) continue;         ans[0] = old_ans[j] + monsters;         if (old_curr[j] >= monsters) {           r[0] = l;           curr[0] = old_curr[j] - monsters;         } else {           int turns = (monsters - old_curr[j] + k - 1) / k;           r[0] = l + turns;           curr[0] = k * turns + old_curr[j] - monsters;         }       }       ans[1] = -1;       for (int j = 0; j < 2; j++) {         if (old_ans[j] == -1) continue;         if ((tmp_r - l + 1) * k < monsters) continue;         if (old_r[j] == l) continue;         if (ans[1] != -1 && ans[1] <= old_ans[j] + old_curr[j] + monsters)           continue;         ans[1] = old_ans[j] + old_curr[j] + monsters;         int turns = (monsters + k - 1) / k;         r[1] = l + turns - 1;         curr[1] = k * turns - monsters;       }     }     if (ans[0] == -1)       cout << ans[1] <<   n ;     else if (ans[1] == -1)       cout << ans[0] <<   n ;     else       cout << min(ans[0], ans[1]) <<   n ;   }   int main(void) {     ios::sync_with_stdio(0);     cin.tie(0);     int Case = 1;     for (int i = 0; i < Case; i++) {       test_case();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   int vis[maxn];   vector<int> e[maxn];   vector<int> w[maxn];   int a[maxn];   int ans;   void add_edge(int u, int v, int ww) {     e[u].push_back(v);     e[v].push_back(u);     w[u].push_back(ww);     w[v].push_back(ww);   }   void dfs(int num, int l, int c) {     if (l > a[num] && c != 1) {       c = 1;     }     if (c == 1) {       ans++;     }     vis[num] = 1;     int cc = e[num].size();     for (int i = 0; i < cc; i++) {       if (!vis[e[num][i]]) {         if (l < 0) l = 0;         vis[e[num][i]] = 1;         dfs(e[num][i], l + w[num][i], c);       }     }   }   int main() {     memset(vis, 0, sizeof(vis));     int n;     scanf( %d , &n);     ans = 0;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 2; i <= n; i++) {       int u = i, v, ww;       scanf( %d%d , &v, &ww);       add_edge(u, v, ww);     }     ans = 0;     dfs(1, 0, 0);     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;      #define ll int   #define vl vector<long long>   #define fr(i,a,n) for(ll i=a; i<n; i++)   #define all(x) x.begin(), x.end()      int32_t main(){    ios_base::sync_with_stdio(false);    cin.tie(NULL);    cout.tie(NULL);    ll t; cin>>t;    while(t--){     ll n, x=0, z[4];     cin>>n;     for(ll i=0; i<4; i++) cin>>z[i];     for(ll i=0; i<=15; i++){      ll a=0, b=0, c=0, d=0;      if(i&1) a++;      if(i&2) b++;      if(i&4) c++;      if(i&8) d++;      if(z[0]-a-b<=n-2 && z[0]>=a+b) x++;      if(z[1]-c-b<=n-2 && z[1]>=c+b) x++;      if(z[2]-c-d<=n-2 && z[2]>=c+d) x++;      if(z[3]-a-d<=n-2 && z[3]>=a+d) x++;      if(x==4) break;      else x=0;     }     if(x==4) cout<< Yes n ;     else cout<< No n ;    }    }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   bool et[N];   int n;   int mob[N];   vector<int> d[N];   int cnt[N];   bool get(int x) {     int coprime = 0;     for (auto p : d[x]) coprime += cnt[p] * mob[p];     return coprime > 0;   }   void update(int x, int val) {     for (auto p : d[x]) cnt[p] += val;   }   int main() {     for (int i = 1; i < N; i++) {       for (int j = i; j < N; j += i) d[j].push_back(i);       if (i == 1)         mob[i] = 1;       else if ((i / d[i][1]) % d[i][1] == 0)         mob[i] = 0;       else         mob[i] = -mob[i / d[i][1]];     }     cin >> n;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       et[x] = 1;     }     for (int i = 1; i < N; i++) {       for (auto x : d[i])         if (i != x) et[x] |= et[i];     }     long long ans = 0;     stack<int> s;     for (int i = N - 1; i >= 1; i--) {       if (et[i] == 0) continue;       while (get(i) > 0) {         ans = max(ans, 1LL * i * s.top());         update(s.top(), -1);         s.pop();       }       update(i, 1);       s.push(i);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N, X, Y;     cin >> N >> X >> Y;     int p = ceil(Y / 100.0 * N);     cout << max(p - X, 0) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int i, j, count_star, diff, res = 0, n;     cin >> s;     n = s.size();     for (i = 0; i < n; i++) {       diff = count_star = 0;       for (j = i; j < n; j++) {         if (s[j] ==  ( )           diff++;         else if (s[j] ==  ) )           diff--;         else {           count_star++;           diff--;         }         if (diff < 0) {           count_star--;           if (count_star < 0)             break;           else             diff += 2;         }         if (diff == 0 && (j - i + 1) % 2 == 0) res++;       }     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int P;   int g1() {     double p = rand() / 32767.0, s = 0, g = 1;     for (int k = 0;; k++) {       if (k) g *= k;       double c = pow(P, k) * exp(-P) / g;       s += c;       if (p <= s) return k;     }   }   int g2() {     double p = rand() / 32767.0, s = 0;     for (int k = 0; k <= P + P; k++) {       s += 1.0 / (2 * P + 1);       if (p <= s) return k;     }     return P + P;   }   int main() {     int v;     scanf( %d , &v);     while (v--) {       vector<int> vs;       for (int i = 0; i < 250; i++) {         int x;         scanf( %d , &x);         vs.push_back(x);       }       double avr = 0, ss = 0;       for (int i = 0; i < 250; i++) avr += (double)vs[i];       avr /= 250;       int mx = 0;       for (int i = 0; i < 250; i++)         ss += (vs[i] - avr) * (vs[i] - avr), mx = max(mx, vs[i]);       ss /= avr;       if (ss < 500)         printf( %d n , int(avr + 0.5));       else         printf( %d n , int(mx / 2.0 + 0.5));     }   }


#include <bits/stdc++.h>   using namespace std;   unsigned gcd(unsigned a, unsigned b) {     unsigned r;     do {       r = a % b;       a = b;       b = r;     } while (r > 0);     return a;   }   unsigned arr[705];   bool dp[705][705][2];   bool en[705][705][2];   unsigned g[705][705];   bool f(int l, int r, int rm) {     if (en[l][r][rm]) return dp[l][r][rm];     en[l][r][rm] = true;     if (l == r)       dp[l][r][rm] = g[l][l - 1 + 2 * rm] > 1;     else {       dp[l][r][rm] |= (g[l - 1 + rm * (r - l + 2)][l] > 1) && f(l + 1, r, 0);       dp[l][r][rm] |= (g[l - 1 + rm * (r - l + 2)][r] > 1) && f(l, r - 1, 1);       for (int curs = 1; curs < r - l; curs++)         dp[l][r][rm] |= (g[l - 1 + rm * (r - l + 2)][l + curs] > 1) &&                         f(l, l + curs - 1, 1) && f(l + curs + 1, r, 0);     }     return dp[l][r][rm];   }   void init(int n) {     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) g[i][j] = gcd(arr[i], arr[j]);   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &arr[i]);     init(n);     if (f(1, n - 1, 0)) {       printf( Yes n );       return 0;     }     if (f(0, n - 2, 1)) {       printf( Yes n );       return 0;     }     for (int i = 1; i < n - 1; i++) {       if (f(0, i - 1, 1) && f(i + 1, n - 1, 0)) {         printf( Yes n );         return 0;       } else         continue;     }     printf( No n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void __dbg() { cout << endl; }   template <typename Arg, typename... Args>   void __dbg(Arg A, Args... B) {     cout <<     << A;     __dbg(B...);   }   const int inf = INT_MAX;   const int ninf = INT_MIN;   const int mod = 1e9 + 7;   const int maxN = 1e6 + 2;   int main() {     int n;     scanf( %d , &n);     map<pair<int, int>, int> ma;     vector<int> x(n), y(n);     for (int i = 0; i < n; i++) {       scanf( %d , &x[i]);       scanf( %d , &y[i]);     }     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         int cx = x[i] + x[j];         int cy = y[i] + y[j];         ma[{cx, cy}]++;       }     }     long long ans = 0;     for (auto it : ma) {       ans += it.second * 1LL * (it.second - 1) / 2;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int p[111];   int main() {     int n, a = 0, b = 0, c = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> p[i];       if (i < 3 && i == 1 || i % 3 == 1) {         a = a + p[i];       } else if (i < 3 && i == 2 || i % 3 == 2) {         b = b + p[i];       } else if (i % 3 == 0) {         c = c + p[i];       }     }     if (max(a, max(b, c)) == a) {       cout <<  chest ;     } else if (max(a, max(b, c)) == b) {       cout <<  biceps ;     } else if (max(a, max(b, c)) == c) {       cout <<  back ;     }   }


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


#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n, m, v[100][100], x, y, cnt, ans = 0, dcnt = 1;     vector<int> del;     memset(v, 0, sizeof(v));     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> x >> y;       v[x - 1][y - 1] = 1;       v[y - 1][x - 1] = 1;     }     while (dcnt != 0) {       dcnt = 0;       for (int i = 0; i < n; i++) {         cnt = 0;         for (int j = 0; j < n; j++) cnt += v[i][j];         if (cnt == 1) {           dcnt++;           del.push_back(i);           for (int j = 0; j < n; j++) v[i][j] = 0;         }       }       for (int i = 0; i < n; i++) {         for (unsigned int j = 0; j < del.size(); j++) v[i][del[j]] = 0;       }       if (dcnt > 0) ans++;       del.clear();     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N;   long long dp[2 * 100000 + 10][2], arr[2 * 100000 + 10];   long long Solve(int, bool);   int main() {     scanf( %d , &N);     dp[0][0] = dp[0][1] = dp[1][0] = dp[1][1] = -2;     for (int i = 2; i <= N; i++) {       scanf( %I64d , &arr[i]);       dp[i][0] = dp[i][1] = -2;     }     for (int i = 2; i <= N; i++) Solve(i, 0), Solve(i, 1);     for (int i = 1; i < N; i++)       dp[1 + i][0] != -1 ? printf( %I64d n , dp[1 + i][0] + i) : printf( -1 n );     return 0;   }   long long Solve(int ind, bool f) {     if (ind <= 0 || ind > N) return 0;     if (dp[ind][f] == -3) return -1;     if (dp[ind][f] != -2) return dp[ind][f];     dp[ind][f] = -3;     long long ret, a;     if (f)       a = Solve(ind + arr[ind], 0);     else       a = Solve(ind - arr[ind], 1);     if (a == -1)       ret = -1;     else       ret = a + (long long)arr[ind];     return dp[ind][f] = ret;   }