#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   long long solve(long long l, long long r, long long x) {     long long res = 0;     for (int i = 1; i <= 62; i++) {       long long p = (1LL << i) - 1;       long long val = (x ^ p);       if (l <= p && p <= r) {         res = max(res, val);       }       if (l <= val && val <= r) {         res = max(res, p);       }     }     return res;   }   int main() {     long long l, r;     cin >> l >> r;     if (l == r) {       cout << 0;     } else if (r - l <= 1000) {       long long m = 0;       for (long long i = l; i <= r; i++) {         for (long long j = l; j <= r; j++) {           m = max(m, i ^ j);         }       }       cout << m;     } else {       long long a = solve(l, r, l);       long long b = solve(l, r, r);       cout << max(a, b);     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   inline bool check(vector<long long>& prev, long long x) {     long long sz = prev.size();     for (long long i = 0; i < sz; i += x) {       long long j = min(i + x - 1, sz - 1);       if (prev[j] - i > k) return false;     }     return true;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> k;     vector<long long> a(n);     for (long long i = 0; i < n; i++) cin >> a[i];     sort(a.begin(), a.end());     long long sz = a.back() + 10;     vector<long long> cnt(sz, 0);     for (long long i : a) cnt[i]++;     vector<long long> prev(sz, 0);     for (long long i = 1; i < sz; i++) {       if (cnt[i] > 0)         prev[i] = i;       else         prev[i] = prev[i - 1];     }     long long hi = a.front();     for (long long i = hi; i >= 1; i--) {       if (check(prev, i)) {         cout << i << endl;         break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char Start;   int n, m;   char S[400005], T[400005];   int fa[400005], tr[400005][26], len[400005], rt[400005], pos[400005], tot, last;   vector<int> G[400005];   void ins(int c, bool debug = 0) {     if (tr[last][c]) {       int p = last, q = tr[last][c];       if (len[q] != len[p] + 1) {         int v = ++tot;         memcpy(tr[v], tr[q], sizeof tr[q]);         fa[v] = fa[q], len[v] = len[p] + 1;         for (; ~p && tr[p][c] == q; p = fa[p]) tr[p][c] = v;         fa[q] = v;       }     } else {       int u = ++tot, p = last, q;       len[u] = len[p] + 1;       for (; ~p && !tr[p][c]; p = fa[p]) tr[p][c] = u;       if (p == -1)         fa[u] = 0;       else if (len[q = tr[p][c]] == len[p] + 1)         fa[u] = q;       else {         int v = ++tot;         memcpy(tr[v], tr[q], sizeof tr[q]);         fa[v] = fa[q], len[v] = len[p] + 1;         for (; ~p && tr[p][c] == q; p = fa[p]) tr[p][c] = v;         fa[q] = fa[u] = v;       }     }   }   int lc[400005 * 30], rc[400005 * 30], mx[400005 * 30], mxp[400005 * 30];   void upd(int u) {     if (mx[lc[u]] >= mx[rc[u]])       mx[u] = mx[lc[u]], mxp[u] = mxp[lc[u]];     else       mx[u] = mx[rc[u]], mxp[u] = mxp[rc[u]];   }   void ins(int &u, int l, int r, int p) {     if (!u) u = ++tot, mxp[u] = l;     if (l == r) return (void)(mx[u]++);     int m = l + r >> 1;     p <= m ? ins(lc[u], l, m, p) : ins(rc[u], m + 1, r, p);     upd(u);   }   void merge(int &u, int l, int r) {     if (!l || !r) return (void)(u = l + r);     u = ++tot;     if (lc[l] || rc[l]) {       merge(lc[u], lc[l], lc[r]), merge(rc[u], rc[l], rc[r]);       upd(u);     } else {       mx[u] = mx[l] + mx[r], mxp[u] = mxp[l];     }   }   pair<int, int> qry(int u, int l, int r, int ql, int qr) {     if (ql > r || l > qr || !u || ql > qr) return make_pair(0, 0x3f3f3f3f);     if (ql <= l && r <= qr) return make_pair(mx[u], mxp[u]);     int m = l + r >> 1;     pair<int, int> r1 = qry(lc[u], l, m, ql, qr),                    r2 = qry(rc[u], m + 1, r, ql, qr);     if (r1.first >= r2.first)       return r1;     else       return r2;   }   int f[400005], g[400005], ps[400005];   void dfs(int u) {     for (int v : G[u]) {       dfs(v), merge(rt[u], rt[u], rt[v]);       if (!ps[u]) ps[u] = ps[v];     }   }   int ans;   void dfs2(int u) {     ans = max(ans, f[u]);     for (int v : G[u]) {       if (!u || qry(rt[g[u]], 1, n, ps[v] - len[v] + len[g[u]], ps[v] - 1).first)         f[v] = f[u] + 1, g[v] = v;       else         f[v] = f[u], g[v] = g[u];       dfs2(v);     }   }   char End;   int main() {     scanf( %d , &n);     scanf( %s , S + 1);     fa[0] = -1;     for (int i = (1), LIM = (n); i <= LIM; i++)       ins(S[i] -  a ), last = tr[last][S[i] -  a ], ps[last] = i;     for (int i = (1), LIM = (tot); i <= LIM; i++) {       G[fa[i]].push_back(i);       if (ps[i]) ins(rt[i], 1, n, ps[i]);     }     dfs(0);     dfs2(0);     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000000 + 7;   int main() {     ios::sync_with_stdio(0);     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     long long n;     cin >> n;     if (n < 3) {       cout << -1;       return 0;     }     for (int i = n; i >= 1; i--) {       cout << i <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool prime(int n) {     if (n % 2 == 0) return false;     for (int i = 3; i * i <= n; i += 2)       if (n % i == 0) return false;     return true;   }   int r(int n) {     int div = 1;     int ans = 0;     while (div <= n) {       ans *= 10;       ans += ((n / div) % 10);       div *= 10;     }     return ans;   }   int main() {     int n;     cin >> n;     int cont = 0;     int i = 11;     while (cont < n) {       if (prime(i)) {         int x = r(i);         if (x != i && prime(x)) {           cont++;           if (cont == n) cout << i <<   n ;         }       }       i++;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 998244353;   long long add(long long x, long long y, long long CMOD = MOD) {     return (x + y + CMOD + CMOD) % CMOD;   }   long long mult(long long x, long long y, long long CMOD = MOD) {     return add(x, 0) * add(y, 0) % CMOD;   }   long long fast_expo(long long x, long long y, long long CMOD = MOD) {     if (x == 0) return 0;     if (y == 0) return 1;     long long ans = fast_expo(x, y / 2, CMOD);     ans = mult(ans, ans, CMOD);     if (y & 1) ans = mult(ans, x, CMOD);     return ans;   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   long long gen(long long x, long long y) {     if (x == y) return x;     return x + rng() % (y - x + 1);   }   const int TAM = 2e5 + 100;   const long long INF = LLONG_MAX / 4;   long long fact[TAM];   long long ifact[TAM];   long long n, m;   void pre() {     fact[0] = 1;     for (int i = 1; i < TAM; i++) fact[i] = mult(fact[i - 1], i);     for (int i = 0; i < TAM; i++) ifact[i] = fast_expo(fact[i], MOD - 2);   }   long long comb(long long x, long long y) {     return mult(fact[x], mult(ifact[y], ifact[x - y]));   }   int main() {     pre();     cin >> n >> m;     if (n == 2) {       puts( 0 );       return 0;     }     long long ans = 0;     for (long long x = n - 1; x <= m; x++) {       long long factor = mult(comb(x - 2, n - 3), fast_expo(2, n - 3));       ans = add(ans, mult(x - 1, factor));     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int sign(long long x) { return x < 0 ? -1 : x > 0 ? 1 : 0; }   struct point {     long long x, y;     point(long long a = 0, long long b = 0) : x(a), y(b) {}     point operator-(point q) { return point(x - q.x, y - q.y); }     long long operator%(point q) { return x * q.y - y * q.x; }   };   point T[1001];   long long piso(long long A, long long B) {     if (B < 0) A = -A, B = -B;     if (A >= 0)       return A / B;     else       return -((-A + B - 1) / B);   }   long long techo(long long A, long long B) {     if (B < 0) A = -A, B = -B;     if (A >= 0)       return (A + B - 1) / B;     else       return A / B;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %lld %lld , &T[i].x, &T[i].y);     if (T[2].y > T[0].y) {       for (int i = 0; i < n; i++) T[i].y = -T[i].y;       swap(T[0], T[1]);       reverse(T + 2, T + n);     }     T[n] = T[0];     long long y = T[0].y;     bool sirve = true;     long long le = T[0].x, ri = T[1].x;     for (int i = 2; i < n; i++) {       long long der = T[1].x;       long long izq = T[0].x;       for (int j = 2; j < i; j++)         if (abs(y - T[j].y) < abs(y - T[i].y)) {           long long A = T[j].y - T[i].y;           long long B = T[i].x - T[j].x;           long long C = T[i].x * A + T[i].y * B;           der = min(der, piso(C - B * y, A));         }       if (i - 1 > 1)         if (T[i].y == T[i - 1].y && T[i - 2].y > T[i].y &&             sign((T[i] - T[i - 1]) % (T[i] - T[i - 2])) <= 0)           sirve = false;       for (int j = i + 1; j < n; j++)         if (abs(y - T[j].y) < abs(y - T[i].y)) {           long long A = T[j].y - T[i].y;           long long B = T[i].x - T[j].x;           long long C = T[i].x * A + T[i].y * B;           izq = max(izq, techo(C - B * y, A));         }       if (i + 1 < n)         if (T[i].y == T[i + 1].y && T[i + 2].y > T[i].y &&             sign((T[i] - T[i + 1]) % (T[i] - T[i + 2])) >= 0)           sirve = false;       if (der < izq)         sirve = false;       else if (ri < izq || der < le)         sirve = false;       else {         le = max(izq, le);         ri = min(der, ri);       }     }     int res = ri - le + 1;     if (!sirve) res = 0;     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long oo = 1e18;   const long long MOD = 998244353;   const long long MAXN = 2e5 + 100;   long long qpow(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = res * a % MOD;       a = a * a % MOD;       b /= 2;     }     return res;   }   long long inv(long long x) { return qpow(x, MOD - 2); }   long long fact[MAXN];   long long C(long long n, long long k) {     return fact[n] * inv(fact[k] * fact[n - k] % MOD) % MOD;   }   long long N, K;   long long arr[MAXN];   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     fact[0] = 1;     for (long long i = 1; i < MAXN; i++) fact[i] = fact[i - 1] * i % MOD;     cin >> N >> K;     long long cont = 0;     for (long long i = 0; i < N; i++) {       cin >> arr[i];     }     for (long long i = 0; i < N; i++) {       if (arr[i] != arr[(i + 1) % N]) {         cont++;       }     }     long long res = 0;     for (long long i = 1; i <= cont; i++) {       long long tp = qpow(2, i);       if (i % 2 == 0) tp = (tp + MOD - C(i, i / 2)) % MOD;       tp = tp * inv(2) % MOD;       tp = tp * qpow(K - 2, cont - i) % MOD;       tp = tp * C(cont, i) % MOD;       res = (res + tp) % MOD;     }     res = res * qpow(K, N - cont) % MOD;     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int str[26][1505];   int ans[26][1505];   int main(int argc, char *argv[]) {     int n;     scanf( %d , &n);     getchar();     char c;     for (int i = 0; i < n; i++) {       c = getchar();       str[c -  a ][i]++;     }     for (int i = 0; i < 26; i++) {       for (int j = 1; j < n; j++) {         str[i][j] = str[i][j - 1] + str[i][j];       }     }     int total, m;     for (int i = 0; i < 26; i++) {       for (int j = 0; j < n; j++) {         for (int k = j; k < n; k++) {           if (j == 0) {             total = str[i][k];           } else {             total = str[i][k] - str[i][j - 1];           }           m = k - j + 1 - total;           if (ans[i][m] < k - j + 1) {             ans[i][m] = k - j + 1;           }         }       }     }     for (int i = 0; i < 26; i++) {       for (int j = 1; j <= n; j++) {         ans[i][j] = ans[i][j] < ans[i][j - 1] ? ans[i][j - 1] : ans[i][j];       }     }     int q;     scanf( %d , &q);     int num;     while ((q--) > 0) {       scanf( %d %c , &num, &c);       printf( %d n , ans[c -  a ][num]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double s = 0, n;     cin >> n;     while (n > 0) {       s += (1 / n);       n--;     }     cout << s << endl;   }


#include <bits/stdc++.h>      #define ll long long   #define db double   #define str string   #define pii pair<int, int>   #define pll pair<ll, ll>   #define pdd pair<db, db>   #define fi first   #define se second      #define vc vector<char>   #define vvc vector<vc>   #define vi vector<int>   #define vvi vector<vi>   #define vvvi vector<vvi>   #define vvvvi vector<vvvi>   #define vll vector<ll>   #define vvll vector<vll>   #define vvvll vector<vvll>   #define vvvvll vector<vvvll>   #define vs vector<str>   #define vvs vector<vs>   #define vdb vector<db>   #define vvdb vector<vdb>   #define vpii vector<pii>   #define vvpii vector<vpii>   #define vpll vector<pll>   #define vvpll vector<vpll>   #define vpdd vector<pdd>   #define vvpdd vector<vpdd>   #define vb vector<bool>   #define vvb vector<vb>   #define rep(i, a, b) for (int i = (a); i < int(b); i++)   #define repi(i, a, b) for (int i = (a); i <= int(b); i++)      #define edg pair<ll, pair<pii, int>>   #define U se.fi.fi   #define V se.fi.se   #define W fi   #define I se.se   #define vedg vector<edg>         using namespace std;   ll INF = LONG_LONG_MAX / 2;   int inf = INT_MAX / 2;   ll mod = 1000000000 + 7;      template <typename T, typename L>   void read(vector<T> & _data, L _size, int _shift) {       _data.resize(_size + _shift);       for (ll i = _shift; i < _size + _shift; i++)           cin >> _data[i];   }      template <typename T, typename L>   void read(vector<vector<T>> & _data, L _rows, L _cols, int _shiftRows, int _shiftCols) {       _data.resize(_rows + _shiftRows);       for (ll i = 0; i < _rows + _shiftRows; i++)           _data[i].resize(_cols + _shiftCols);       for (ll i = _shiftRows; i < _rows + _shiftRows; i++)           for (ll j = _shiftCols; j < _cols + _shiftCols; j++)               cin >> _data[i][j];   }      template <typename T>   void write(vector<T> & _data, ll _shift) {       for (ll i = _shift; i < _data.size(); i++)           cout << _data[i] <<    ;       cout << endl;   }         //TODO: SOLUTION   ll n, m;   ll gr[600][600];   ll dists[600][600];   bool been[600];      void clear() {       rep(i, 0, 600) {           rep(j, 0, 600) {               gr[i][j] = 0;               dists[i][j] = INF / 2;           }       }   }      void clearbeen() {       rep(i, 0, 600) {           been[i] = false;       }   }      void dijkstra(ll src) {          rep(i, 0, n) {           if (gr[src][i] != 0) {               dists[src][i] = gr[src][i];           }       }          for (int q = 0; q < n; q++) {              ll mind = INF;           ll x = 0;              rep(i, 0, n) {               if (!been[i] && dists[src][i] < mind) {                   mind = dists[src][i];                   x = i;               }           }              been[x] = true;           for (int y = 0; y < n; y++) {               if (gr[x][y] != 0) {                   if (been[(y + dists[src][x]) % n])                       continue;                   dists[src][(y + dists[src][x]) % n] = min(dists[src][(y + dists[src][x]) % n], dists[src][x] + gr[x][y]);               }           }              dists[src][(x + 1) % n] = min(dists[src][(x + 1) % n], dists[src][x] + 1);       }   }         void solve() {       cin >> n >> m;          clear();          rep(i, 0, m) {           ll a, b, c; cin >> a >> b >> c;           gr[a][b] = c;       }          rep(i, 0, n) {           clearbeen();           dijkstra(i);       }       rep(i, 0, n) {           rep(j, 0, n) {               if (i == j)                   cout <<  0  ;               else                   cout << dists[i][j] <<    ;           }           cout << endl;       }   }         int main() {          ios::sync_with_stdio(false);       // TODO: Set value of this variable manually       bool _multipleTestCases = false;          if (_multipleTestCases) {           ll t; cin >> t;           while (t--)               solve();       }       else {           solve();       }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long l[200010];   int n;   long long teste(long long x) {     if (x <= 1) return n;     long long res = 0;     for (int i = 0; i < n; i++) {       if (l[i] < x)         res += x - (l[i] % x);       else         res += min(l[i] % x, x - (l[i] % x));     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int i = 0; i < n; i++) cin >> l[i];     long long res = n;     for (int i = 0; i < 20; i++) {       int p = rand() * rand() % n;       long long t = l[p];       vector<long long> factors;       for (int j = 2; j <= sqrt(t); j++) {         while (t % j == 0) {           t /= j;           factors.push_back(j);         }       }       if (t > 1) factors.push_back(t);       t = l[p] - 1;       for (int j = 2; j <= sqrt(t); j++) {         while (t % j == 0) {           t /= j;           factors.push_back(j);         }       }       if (t > 1) factors.push_back(t);       t = l[p] + 1;       for (int j = 2; j <= sqrt(t); j++) {         while (t % j == 0) {           t /= j;           factors.push_back(j);         }       }       if (t > 1) factors.push_back(t);       sort(factors.begin(), factors.end());       for (int j = 0; j < (int)factors.size(); j++) {         if (j and factors[j] == factors[j - 1]) continue;         res = min(res, teste(factors[j]));       }     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s, t;     cin >> s >> t;     vector<int> f1(26);     vector<int> f2(26);     for (int i = 0; i < n; i++) {       f1[s[i] - 97]++;       f2[t[i] - 97]++;     }     int f = 0;     for (int i = 0; i < 26; i++) {       if (f1[i] != f2[i]) {         f = 1;         break;       }     }     if (f == 1)       cout <<  -1  << endl;     else {       int cou = 0;       vector<int> v;       for (int i = 0; i < n; i++) {         if (s[i] == t[i]) continue;         int c = 0;         for (int j = i + 1; j < n; j++) {           if (t[i] == s[j]) {             c++;             break;           }           c++;         }         char x = s[i];         s[i] = s[i + c];         s[i + c] = x;         for (int k = 1; k < c; k++) {           v.push_back(i + k);         }         v.push_back(i + c);         for (int k = 1; k < c; k++) {           v.push_back(i + c - k);         }         cou = cou + 2 * c - 1;       }       cout << cou << endl;       for (int i = 0; i < cou; i++) cout << v[i] <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const char letters[] = { A ,  G ,  C ,  T };   const int NMAX = 3e5 + 5;   int N, M;   int A, G, C, T;   int best;   vector<vector<int> > a, b;   vector<int> prm, bestprm;   int fqlin[NMAX][2][4], fqcol[NMAX][2][4];   char gletter() {     char ch = getchar();     while (ch <  A  ||  Z  < ch) ch = getchar();     return ch;   }   int main() {     scanf( %d%d n , &N, &M);     a.resize(N + 1);     for (int i = 1; i <= N; i++) {       a[i].resize(M + 1);       for (int j = 1; j <= M; j++) {         char ch = gletter();         if (ch ==  A )           a[i][j] = 0;         else if (ch ==  G )           a[i][j] = 1;         else if (ch ==  C )           a[i][j] = 2;         else if (ch ==  T )           a[i][j] = 3;         fqlin[i][j % 2][a[i][j]]++;         fqcol[j][i % 2][a[i][j]]++;       }     }     best = -1;     int who = -1;     for (int i = 0; i < 4; i++) prm.push_back(i);     do {       {         int cost = 0;         A = prm[0], G = prm[1], C = prm[2], T = prm[3];         cost += fqcol[1][1][A] + fqcol[1][0][C] + fqcol[2][1][G] + fqcol[2][0][T];         for (int i = 3; i <= M; i++) {           if (i % 2 == 0)             cost += max(fqcol[i][1][G] + fqcol[i][0][T],                         fqcol[i][0][G] + fqcol[i][1][T]);           else             cost += max(fqcol[i][1][A] + fqcol[i][0][C],                         fqcol[i][0][A] + fqcol[i][1][C]);         }         if (cost > best) {           best = cost;           bestprm = prm;           who = 0;         }       }       {         int cost = 0;         A = prm[0], G = prm[1], C = prm[2], T = prm[3];         cost += fqlin[1][1][A] + fqlin[2][1][C] + fqlin[1][0][G] + fqlin[2][0][T];         for (int i = 3; i <= N; i++) {           if (i % 2 == 0)             cost += max(fqlin[i][1][C] + fqlin[i][0][T],                         fqlin[i][0][C] + fqlin[i][1][T]);           else             cost += max(fqlin[i][1][A] + fqlin[i][0][G],                         fqlin[i][0][A] + fqlin[i][1][G]);         }         if (cost > best) {           best = cost;           bestprm = prm;           who = 1;         }       }     } while (next_permutation(prm.begin(), prm.end()));     b = a;     prm = bestprm;     if (who == 0) {       A = prm[0], G = prm[1], C = prm[2], T = prm[3];       b[1][1] = A, b[2][1] = C, b[1][2] = G, b[2][2] = T;       for (int i = 3; i <= M; i++) {         if (i % 2 == 1) {           if (fqcol[i][1][A] + fqcol[i][0][C] > fqcol[i][0][A] + fqcol[i][1][C])             b[1][i] = A, b[2][i] = C;           else             b[1][i] = C, b[2][i] = A;         } else {           if (fqcol[i][1][G] + fqcol[i][0][T] > fqcol[i][0][G] + fqcol[i][1][T])             b[1][i] = G, b[2][i] = T;           else             b[1][i] = T, b[2][i] = G;         }       }       for (int i = 3; i <= N; i++)         for (int j = 1; j <= M; j++) b[i][j] = b[i - 2][j];     } else {       A = prm[0], G = prm[1], C = prm[2], T = prm[3];       b[1][1] = A, b[2][1] = C, b[1][2] = G, b[2][2] = T;       for (int i = 3; i <= N; i++) {         if (i % 2 == 1) {           if (fqlin[i][1][A] + fqlin[i][0][G] > fqlin[i][0][A] + fqlin[i][1][G])             b[i][1] = A, b[i][2] = G;           else             b[i][1] = G, b[i][2] = A;         } else {           if (fqlin[i][1][C] + fqlin[i][0][T] > fqlin[i][0][C] + fqlin[i][1][T])             b[i][1] = C, b[i][2] = T;           else             b[i][1] = T, b[i][2] = C;         }       }       for (int i = 3; i <= M; i++)         for (int j = 1; j <= N; j++) b[j][i] = b[j][i - 2];     }     for (int i = 1; i <= N; i++, printf(  n ))       for (int j = 1; j <= M; j++) printf( %c , letters[b[i][j]]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Lem {     int m, v, id;     bool operator<(Lem b) const { return m < b.m || (m == b.m && v < b.v); }   };   int n, k, h;   Lem a[(100000 + 10)];   bool can(double t) {     int j = k;     for (int i(n - 1), _l(0); i >= _l; --i) {       if (j > 0 && (double)j * h / a[i].v - t <= -1e-10) j--;     }     return j == 0;   }   void putAns(double t) {     int ans[(100000 + 10)];     int j = k;     for (int i(n - 1), _l(0); i >= _l; --i) {       if (j > 0 && (double)j * h / a[i].v - t <= -1e-10) ans[--j] = a[i].id;     }     for (int i(0), _n(k - 1); i < _n; ++i) printf( %d  , ans[i]);     printf( %d n , (ans[k - 1]));   }   int main() {     scanf( %d , &(n)), scanf( %d , &(k)), scanf( %d , &(h));     for (int i(0), _n(n); i < _n; ++i) scanf( %d , &(a[i].m)), a[i].id = i + 1;     for (int i(0), _n(n); i < _n; ++i) scanf( %d , &(a[i].v));     sort(a, a + n);     double l = 1e-10, r = 1e10;     int cnt = 100;     while (cnt--) {       double mid = (l + r) / 2.0;       if (can(mid))         r = mid;       else         l = mid;     }     putAns(r);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void maxtt(T& t1, T t2) {     t1 = max(t1, t2);   }   template <typename T>   void mintt(T& t1, T t2) {     t1 = min(t1, t2);   }   bool debug = 0;   int n, m, k;   string direc =  URDL ;   const long long MOD2 = (long long)1000000007 * (long long)1000000007;   long long ln, lk, lm;   void etp(bool f = 0) {     puts(f ?  YES  :  NO );     exit(0);   }   void addmod(int& x, int y, int mod = 1000000007) {     assert(y >= 0);     x += y;     if (x >= mod) x -= mod;     assert(x >= 0 && x < mod);   }   void et(int x = -1) {     printf( %d n , x);     exit(0);   }   long long fastPow(long long x, long long y, int mod = 1000000007) {     long long ans = 1;     while (y > 0) {       if (y & 1) ans = (x * ans) % mod;       x = x * x % mod;       y >>= 1;     }     return ans;   }   long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }   int d[2][135][135];   int xa, ya, xb, yb;   int dx[8] = {1, 2, 2, 1, -1, -2, -2, -1}, dy[8] = {2, 1, -1, -2, -2, -1, 1, 2};   void bfs(int x, int y, int w) {     queue<pair<int, int> > q;     q.push({x, y});     d[w][x][y] = 0;     while (!q.empty()) {       auto t = q.front();       q.pop();       for (int(k) = 0; (k) < (int)(8); (k)++) {         int nx = t.first + dx[k], ny = t.second + dy[k];         if (nx >= 1 && nx <= n && ny >= 1 && ny <= m &&             d[w][nx][ny] > d[w][t.first][t.second] + 1) {           d[w][nx][ny] = d[w][t.first][t.second] + 1;           q.push({nx, ny});         }       }     }   }   int ox, oy;   inline void dfs(int x, int y, int w) {     for (int(k) = 0; (k) < (int)(8); (k)++) {       int nx = x + dx[k], ny = y + dy[k];       if (nx == ox && ny == oy) {         cout << nx <<     << ny << endl;         exit(0);       }     }     for (int(k) = 0; (k) < (int)(8); (k)++) {       int nx = x + dx[k], ny = y + dy[k];       if (d[w][nx][ny] < d[w][x][y]) {         cout << nx <<     << ny << endl;         cin >> ox >> oy;         dfs(nx, ny, w);         return;       }     }   }   void fmain(int tid) {     cin >> n >> m >> xa >> ya >> xb >> yb;     for (int(i) = 0; (i) < (int)(2); (i)++)       for (int(j) = 0; (j) < (int)(135); (j)++)         for (int(k) = 0; (k) < (int)(135); (k)++) d[i][j][k] = (1000000000);     bfs(n / 2, m / 2, 0);     bfs(n / 2 + 1, m / 2, 1);     int u = d[0][xa][ya], v = d[0][xb][yb], p = d[1][xa][ya], q = d[1][xb][yb];     if ((xa + ya + xb + yb) % 2 == 0) {       if (q < u) {         cout <<  BLACK  << endl;         cin >> ox >> oy;         dfs(xb, yb, 1);       } else if (v < u + 1) {         cout <<  BLACK  << endl;         cin >> ox >> oy;         dfs(xb, yb, 0);         dfs(n / 2, m / 2, 1);       } else {         cout <<  WHITE  << endl;         ox = xb;         oy = yb;         dfs(xa, ya, 0);       }     } else {       if (u <= q) {         cout <<  WHITE  << endl;         ox = xb;         oy = yb;         dfs(xa, ya, 0);       } else if (p <= q + 1) {         cout <<  WHITE  << endl;         ox = xb;         oy = yb;         dfs(xa, ya, 1);         dfs(n / 2 + 1, m / 2, 0);       } else {         cout <<  BLACK  << endl;         cin >> ox >> oy;         dfs(xb, yb, 1);       }     }   }   int main() {     int t = 1;     for (int(i) = 1; (i) <= (int)(t); (i)++) {       fmain(i);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = (long long)1000 * 1000 * 1000 + 9;   const int maxn = 1000 * 100 + 1;   int n, m, r[maxn], parent[maxn];   long long javab = 1;   int par(int x) {     if (x == parent[x]) return x;     return parent[x] = par(parent[x]);   }   bool merge(int x, int y) {     x = par(x);     y = par(y);     if (x == y) return true;     if (r[x] < r[y]) swap(x, y);     parent[y] = x;     r[x] += r[y];     return false;   }   int main() {     ios::sync_with_stdio(false);     int x, y;     cin >> n >> m;     for (int i = 0; i < n; i++) {       parent[i] = i;       r[i] = 1;     }     for (int i = 0; i < m; i++) {       cin >> x >> y;       x--;       y--;       if (merge(x, y) == true) {         javab *= 2;         javab %= mod;       }       cout << javab - 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k25 = 0, k50 = 0, n;     cin >> n;     bool f = 1;     for (int i = 0; i < n; i++) {       int q;       cin >> q;       if (q == 25)         k25++;       else if (q == 50) {         if (k25) {           k25--;           k50++;         } else           f = 0;       } else {         if (k50 && k25) {           k25--;           k50--;         } else if (k25 >= 3)           k25 -= 3;         else           f = 0;       }     }     if (f)       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, a, b = 0;     cin >> x;     for (int i = 1; i <= x; i++) {       int k = 1;       while (i * k <= x) {         if (i * i * k > x && k < x) {           a = i * k;           b = i;           break;         } else           k = k + 1;       }     }     if (b == 0)       cout << -1;     else       cout << a <<     << b;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200000 + 10;   int a[maxn];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       a[x] = i;     }     int x = 0;     for (int i = 0; i < n; i++) {       int m;       scanf( %d , &m);       int t = a[m] - x;       if (t < 0) {         printf( 0  );       } else {         printf( %d  , t);         x = a[m];       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long a[n + 2];       map<long long, long long> m;       for (long long i = 1; i <= 1000; i++) {         m[i] = 0;       }       for (long long i = 0; i < n; i++) {         cin >> a[i];         m[a[i]]++;       }       vector<pair<long long, long long>> v;       for (auto i : m) {         v.push_back({i.first, i.second});       }       long long d = 0;       sort(v.rbegin(), v.rend());       for (long long i = 0; i < v.size(); i++) {         d += v[i].second;         if (d >= v[i].first) {           cout << v[i].first << endl;           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x, frq, ans[25][25];   map<int, int> mp;   priority_queue<pair<int, int> > pq;   priority_queue<pair<int, set<pair<int, int> > > > mat;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n * n; ++i) cin >> x, ++mp[x];     for (auto it : mp) pq.push({it.second, it.first});     for (int i = 0; i < (n + 1) / 2; ++i) {       for (int j = 0; j < (n + 1) / 2; ++j) {         set<pair<int, int> > temp;         temp.insert({i, j});         temp.insert({n - i - 1, j});         temp.insert({i, n - j - 1});         temp.insert({n - i - 1, n - j - 1});         mat.push({temp.size(), temp});       }     }     while (mat.size()) {       set<pair<int, int> > temp = mat.top().second;       x = pq.top().second, frq = pq.top().first, mat.pop(), pq.pop();       if (frq < temp.size()) return cout <<  NO , 0;       for (auto it : temp) ans[it.first][it.second] = x, --frq;       pq.push({frq, x});     }     cout <<  YES n ;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) cout << ans[i][j] <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXI = numeric_limits<int>::max() / 2;   const int MINI = numeric_limits<int>::min() / 2;   const long long MAXL = numeric_limits<long long>::max() / 2;   const long long MINL = numeric_limits<long long>::min() / 2;   int cnt[2][2];   long long pro(long long s, int &s1, int &s2) {     while (s % 2 == 0) {       ++s1;       s /= 2;     }     while (s % 3 == 0) {       ++s2;       s /= 3;     }     return s;   }   int solve(int &s1, int &s2, int t, long long &a, long long &b) {     int ans = 0;     while (s1 > t) {       --s1;       ++s2;       ++ans;       if (a % 3 == 0)         a = a * 2 / 3;       else         b = b * 2 / 3;     }     return ans;   }   int solve(int &s1, int &s2, long long &a, long long &b) {     int ans = 0;     while (s1 > s2) {       --s1;       ++ans;       if (a % 2 == 0)         a /= 2;       else         b /= 2;     }     return ans;   }   int main(int argc, char *argv[]) {     long long a, b, c, d, s, t;     cin >> a >> b >> c >> d;     s = a * b;     t = c * d;     if (pro(s, cnt[0][0], cnt[0][1]) != pro(t, cnt[1][0], cnt[1][1]))       cout << -1 << endl;     else {       int ans = cnt[0][1] > cnt[1][1]                     ? solve(cnt[0][1], cnt[0][0], cnt[1][1], a, b)                     : solve(cnt[1][1], cnt[1][0], cnt[0][1], c, d);       ans += cnt[0][0] > cnt[1][0] ? solve(cnt[0][0], cnt[1][0], a, b)                                    : solve(cnt[1][0], cnt[0][0], c, d);       cout << ans << endl;       cout << a <<     << b << endl;       cout << c <<     << d << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007LL;   long long powmod(long long b, long long e, long long m) {     if (!e) return 1;     long long r = powmod(b, e / 2, m);     return ((r * r) % m * ((e & 1) ? b : 1)) % m;   }   string s;   long long k;   int main() {     cin >> s >> k;     long long cum = 0;     for (int i = s.size() - 1; i >= 0; i--) {       if (s[i] ==  5  || s[i] ==  0 ) cum += powmod(2, i, mod);       if (cum >= mod) cum -= mod;     }     long long len = s.size();     long long num = powmod(2, len * k, mod);     num = (num - 1 + mod) % mod;     long long den = (powmod(2, s.size(), mod) - 1 + mod) % mod;     long long show = (num * powmod(den, mod - 2, mod)) % mod;     long long opa = (cum * show) % mod;     cout << opa << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int mode, t;   const int INF = 1e9 + 7;   void solve() {     int n, k;     cin >> n >> k;     string s;     cin >> s;     int rot = 0;     if (s[0] == s[n - 1]) {       int start = -1;       for (int i = 0; i < n - 1; i++) {         if (s[i] != s[i + 1]) {           start = i + 1;           break;         }       }       if (start < 0) {         cout << s << endl;         return;       }       rotate(s.begin(), s.begin() + start, s.end());       rot = start;     }     vector<int> sizes;     char prev = s[0];     int size = 0;     for (char c : s) {       if (c == prev) {         size++;       } else {         sizes.push_back(size);         prev = c;         size = 1;       }     }     sizes.push_back(size);     int groups = sizes.size();     vector<int> dist(groups, INF);     for (int i = 0; i < 2 * groups; i++) {       if (sizes[i % groups] > 1) {         dist[i % groups] = 0;       } else {         dist[i % groups] =             min(dist[i % groups], 1 + dist[(i - 1 + groups) % groups]);       }     }     for (int i = 2 * groups - 1; i >= 0; i--) {       dist[i % groups] =           min(dist[i % groups], 1 + dist[(i + 1 + groups) % groups]);     }     vector<char> answer(n);     int i = 0;     char curr = s[0];     for (int group_no = 0; group_no < groups; group_no++) {       if (sizes[group_no] > 1) {         for (int rep = 0; rep < sizes[group_no]; rep++) {           answer[i] = curr;           i++;         }       } else {         if (k <= dist[group_no]) {           if (k % 2) {             answer[i] =  B  +  W  - curr;           } else {             answer[i] = curr;           }         } else {           if (dist[group_no] % 2) {             answer[i] =  B  +  W  - curr;           } else {             answer[i] = curr;           }         }         i++;       }       curr =  B  +  W  - curr;     }     rotate(answer.begin(), answer.begin() + n - rot, answer.end());     for (char c : answer) {       cout << c;     }     cout << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     mode = 0;     if (mode == 0) {       solve();     } else {       cin >> t;       while (t--) {         solve();       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, l, v1, v2, k;   int main() {     cin >> n >> l >> v1 >> v2 >> k;     long double T = 0;     long double S = l, t1, t2, d;     int m = ((n + k - 1) / k);     S = S / ((long double)(m) - ((long double)(m - 1) * (v2 - v1)) / (v2 + v1));     t1 = S / v2;     t2 = (S * (v2 - v1)) / (v2 + v1) / v2;     T = t1 * m + t2 * (m - 1);     cout << fixed << setprecision(15) << T;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x7fffffff;   int main() {     int n;     cin >> n;     int sum = 0;     int zero = 0;     for (int i = 0; i < 2 * n; i++) {       int x;       scanf( %*d.%d , &x);       sum += x;       if (x == 0) zero++;     }     int ans = INF;     for (int k = 0; k <= n; k++) {       if (k + zero < n) continue;       ans = min(ans, abs(k * 1000 - sum));     }     printf( %d.%03d n , ans / 1000, ans % 1000);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 998244353;   long long pwr(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % MOD;       b >>= 1, a = a * a % MOD;     }     return ans;   }   long long inv(long long a) { return pwr(a, MOD - 2); }   template <class T, int SZ>   struct BIT {     T bit[SZ + 1];     BIT() { memset(bit, 0, sizeof bit); }     void upd(int k, T val) {       for (; k <= SZ; k += (k & -k)) bit[k] += val;     }     T query(int k) {       T temp = 0;       for (; k > 0; k -= (k & -k)) temp += bit[k];       return temp;     }     T query(int l, int r) { return query(r) - query(l - 1); }   };   BIT<long long, 1 << 18> b1;   BIT<long long, 1 << 18> b2;   map<int, bool> m;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, cnt = 0, ans = 0, k;     cin >> n;     long long a[n];     for (int i = 0; i < n; ++i) {       cin >> a[i];       if (a[i] == -1)         ++cnt;       else {         m[a[i]] = 1;       }     }     ans += ((cnt * (cnt - 1)) % MOD * inv((long long)4)) % MOD;     for (int i = 0; i < n; ++i) {       if (a[i] != -1) {         b1.upd(a[i], 1LL);         ans += b1.query(a[i] + 1, n);         ans %= MOD;       }     }     for (int i = 1; i <= n; ++i) {       if (!m[i]) b2.upd(i, 1LL);     }     long long left[n], right[n], t = 0;     for (int i = 0; i < n; ++i) {       left[i] = t;       t += (a[i] == -1);     }     t = 0;     for (int i = n - 1; i >= 0; --i) {       right[i] = t;       t += (a[i] == -1);     }     for (int i = 0; i < n; ++i) {       if (a[i] != -1) {         k = (left[i] * b2.query(a[i], n)) % MOD;         k = (k * inv(cnt)) % MOD;         ans += k;         k = (right[i] * b2.query(1, a[i])) % MOD;         k = (k * inv(cnt)) % MOD;         ans += k;         ans %= MOD;       }     }     cout << ans % MOD <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const INF = 100000;   int p[INF + 1];   int M[INF + 1];   int main() {     memset(p, -1, sizeof(p));     memset(M, -1, sizeof(M));     set<pair<int, int> > S;     int n, x, k;     cin >> n;     while (n--) {       cin >> x >> k;       if (p[k] < x) {         p[k] = x;         M[k] = max(M[k], x);         S.insert(pair<int, int>(x, k));       } else {         if (S.find(pair<int, int>(x, k)) != S.end())           continue;         else {           cout <<  NO ;           return 0;         }       }     }     long long cmp = 0;     for (int i = 0; i <= INF; i++) cmp += (M[i] + 1);     if (cmp == S.size())       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   #define LOG(FMT...) fprintf(stderr, FMT);   #define rep(i, j, k) for(int i = j; i <= k; ++ i)   #define per(i, j, k) for(int i = j; i >= k; -- i)   using namespace std;   #define fs first   #define sc second   #define pb push_back   #define mp make_pair   typedef pair<int, int> pii;   typedef double db;   typedef long long ll;   typedef long double ldb;   typedef unsigned int uint;   typedef unsigned long long ull;   mt19937 mt(std::chrono::system_clock::now().time_since_epoch().count());   uniform_int_distribution<ll> ran(0, 1ll << 62);   void ucin() { ios::sync_with_stdio(0); cin.tie(0); }   // uniform_real_distribution<double> dbran;   template<class T> inline void chkmax(T &x, const T &y) { if(x < y) x = y; }   template<class T> inline void chkmin(T &x, const T &y) { if(x > y) x = y; }   inline ll sqr(ll x) { return x * x; }   inline ll cub(ll x) { return x * x * x; }      const int N = 4e5 + 10;   const int mod = 1e9 + 7;   int n, k;   int qpow(int a, int b) {     int ans = 1;     for(; b >= 1; b >>= 1, a = (ll)a * a % mod)       if(b & 1) ans = (ll)ans * a % mod;     return ans;   }   int fac[N], fav[N];    int C(int n, int m) {     return n < 0 || n < m ? 0 : (ll)fac[n] * fav[m] % mod * fav[n - m] % mod;   }   int iC(int n, int m) {     return n < m ? 0 : (ll)fav[n] * fac[m] % mod * fac[n - m] % mod;   }   void binom(int n) {     fac[0] = 1;     rep(i, 1, n) fac[i] = (ll)fac[i - 1] * i % mod;     fav[n] = qpow(fac[n], mod - 2);     per(i, n, 1) fav[i - 1] = (ll)fav[i] * i % mod;   }   int main() {     binom(2e5);     int test;     scanf( %d , &test);     while(test --) {       scanf( %d%d , &n, &k);       int ans = 1;       rep(i, 1, n - 1) {         if(n - 1 - (i - 1) * k < 0) break ;         ans = (ans + 1ll * C(n - 1 - (i - 1) * k + i + 1 - 1, i + 1 - 1) * iC(n, i)) % mod;       }       printf( %d n , ans);     }     return 0;   }   //choose i[0,n-1], x_{1,...,i}, 1111 (i+1空), x_1 >= 0, x_{2,..i} >= k,x_{i+1} >= 0,  sum = n-1


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     vector<long long> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     set<pair<long long, int>> all;     for (int i = 0; i < n; i++) {       all.insert({a[i], i});     }     vector<pair<long long, int>> res;     while (!all.empty()) {       pair<long long, int> prev = *all.begin();       all.erase(all.begin());       if (all.empty()) {         res.push_back(prev);         break;       }       pair<long long, int> next = *all.begin();       all.erase(all.begin());       if (next.first != prev.first) {         res.push_back(prev);         all.insert(next);       } else {         all.insert({prev.first * 2LL, next.second});       }     }     sort(res.begin(), res.end(),          [&](pair<long long, int> a, pair<long long, int> b) {            return a.second < b.second;          });     cout << res.size() <<   n ;     for (auto p : res) {       cout << p.first <<    ;     }     cout <<   n ;     return;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int t = 1;     for (int i = 1; i <= t; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, m, min, max;     scanf( %d %d %d %d , &n, &m, &min, &max);     int arr[m];     for (int i = 0; i < m; i++) {       scanf( %d , &arr[i]);     }     int chmin = 0, chmax = 0, wrong = 0;     for (int i = 0; i < m; i++) {       if (arr[i] == min) chmin = 1;       if (arr[i] == max) chmax = 1;       if (arr[i] > max || arr[i] < min) wrong = 1;     }     if (wrong == 1)       printf( Incorrect n );     else if (chmin == 1 && chmax == 1)       printf( Correct n );     else if (chmin == 1 || chmax == 1) {       if (n - m >= 1)         printf( Correct n );       else         printf( Incorrect n );     } else {       if (n - m >= 2)         printf( Correct n );       else if (n - m >= 1 && min == max)         printf( Correct n );       else         printf( Incorrect n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     map<string, string> map1;     for (int i = 0; i < n; ++i) {       string t1, t2;       cin >> t1 >> t2;       map1[t2] = t1;     }     for (int j = 0; j < m; ++j) {       string t1, t2, t3;       cin >> t1 >> t2;       for (int i = 0; i < t2.size() - 1; ++i) {         t3 += t2[i];       }       cout << t1 <<     << t2 <<   #  << map1[t3] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long a[100000], i, n, m, k;   set<int> s;   int main() {     cin >> n >> k;     for (i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     s.insert(a[0]);     for (i = 1; i < n; i++) {       m = s.size();       if (a[i] % k != 0) {         s.insert(a[i]);       } else {         s.insert(a[i] / k);         if (m != s.size()) {           s.erase(a[i] / k);           s.insert(a[i]);         }       }     }     cout << s.size();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10;   long long a[3][N];   int p[3][N];   int n;   map<long long, int> mp;   map<pair<int, int>, int> f;   int solve(int x, int y) {     if (p[0][x] == -1 && p[1][y] == -1 && p[2][min(x, y)] == -1) return 0;     pair<int, int> cnt(x, y);     if (f.count(cnt)) return f[cnt];     int ret = 0;     if (p[0][x] != -1 && p[0][x] >= p[1][y])       ret = max(ret, solve(p[0][x], y) + 1);     else if (p[1][y] != -1)       ret = max(ret, solve(x, p[1][y]) + 1);     int z = min(x, y);     if (p[2][z] != -1) ret = max(ret, solve(p[2][z], p[2][z]) + 1);     return f[cnt] = ret;   }   int main() {     scanf( %d , &n);     for (int i(1); i <= (n); ++i) scanf( %lld , &a[0][i]);     for (int i(1); i <= (n); ++i) scanf( %lld , &a[1][i]);     for (int i(1); i <= (n); ++i) a[2][i] = a[0][i] + a[1][i];     for (int i(0); i <= (2); ++i)       for (int j(1); j <= (n); ++j) a[i][j] += a[i][j - 1];     for (int i(0); i <= (2); ++i) {       mp.clear();       mp[0] = 0;       p[i][0] = -1;       for (int j(1); j <= (n); ++j) {         p[i][j] = mp.count(a[i][j]) ? mp[a[i][j]] : -1;         p[i][j] = max(p[i][j], p[i][j - 1]);         mp[a[i][j]] = j;       }     }     return 0 * printf( %d n , solve(n, n));   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const int maxm = 100005;   int x[maxm], xr[maxm];   int main() {     int n, i, j, k, sum, m, cnt = 0, ans, t;     int x1, x2, y;     scanf( %d%d , &n, &m);     for (i = 0; i < n; i++) scanf( %d , &x[i]);     ans = t = 0;     sort(x, x + n);     for (i = 1; i <= m; i++) {       scanf( %d%d%d , &x1, &x2, &y);       if (x1 == 1) {         xr[t++] = x2;         if (x2 == INF) ans++;       }     }     sort(xr, xr + t);     ans += n;     i = 0, j = 0;     cnt = t;     while (i < n) {       while (j < t && xr[j] < x[i]) {         --cnt;         ++j;       }       ans = min(ans, cnt + i);       if (ans == 0) break;       ++i;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   const int N = 1e3 + 10;   int len[N];   int h[N];   int cost[N];   int main() {     memset((cost), (0x3f), sizeof(cost));     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       int a, b;       cin >> a >> b >> h[i];       len[i] = (a + b) * 2;     }     int m;     cin >> m;     while (m--) {       int we, hi, p;       cin >> hi >> we >> p;       for (int i = 1; i <= n; i++) {         if (hi >= h[i]) {           int o = hi / h[i] * we;           cost[i] = min(cost[i], (len[i] + o - 1) / o * p);         }       }     }     long long ans = 0;     for (int i = 1; i <= n; i++) ans += cost[i];     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   #define pb push_back   using namespace std;   const int N = 3e5 + 5;   vector<int> G[N], G0[N];   long long day;   int cur, n, pv, pt, a[N], fa[N], dep[N];   int prv[N], pst[N], np[N], bp[N], ep[N];   void Build(int u) {    for(int v : G0[u]) {     if(v == fa[u]) continue;     fa[v] = u;     dep[v] = dep[u] + 1;     Build(v);     G[u].pb(v);     }    sort(G[u].begin(), G[u].end(), [](int x, int y){ return a[x] < a[y]; });   }   void Dfs1(int u) {    for(int v : G[u]) Dfs1(v);    pst[u] = ++pt;    ep[pt] = u;   }   bool Find(int u, int v) {    if(u == v) return true;    if(u == 1) return false;     return Find(fa[u], v);   }   void Back(int u) {    if(u == 1) return;    swap(a[u], a[fa[u]]);    day++;    Back(fa[u]);    }   void Dfs2(int u) {    if(a[u] < cur) return;    prv[u] = pv;    bp[pv++] = u;    for(int v : G[u]) Dfs2(v);   }   void Dfs3(int u) {    prv[u] = ++pv;    for(int v : G[u]) Dfs3(v);   }   int main() {    ios::sync_with_stdio(false);    cin >> n;    for(int i = 1; i <= n; i++) {     cin >> a[i];     np[a[i]] = i;     }    for(int i = 1; i < n; i++) {     int u, v;     cin >> u >> v;     G0[u].pb(v);     G0[v].pb(u);    }    Build(1);    Dfs1(1);    if(a[1] == 1) {     Dfs3(1);     for(int i = 1; i <= n; i++) {      if(prv[i] != a[i]) {       cout <<  NO n ;       return 0;      }     }     cout <<  YES n0 n ;     for(int i = 1; i <= n; i++) cout << prv[i] <<    ;     return 0;     }    cur = a[1] - 1;    if(!Find(ep[cur], np[cur])) {     cout <<  NO n ;     return 0;    }    Back(np[cur]);    for(int i = 1; i <= n; i++) np[a[i]] = i;    for(int i = 1; i < cur; i++) {     if(np[i] != ep[i]) {      cout <<  NO n ;      return 0;     }    }    pv = cur;    Dfs2(1);    for(int i = cur; i <= n; i++) {     if(np[i] != bp[i]) {      cout <<  NO n ;      return 0;     }    }    cout <<  YES n ;    for(int i = 1; i < cur; i++) day += dep[np[i]];    cout << day << endl;    pv = 0;    Dfs3(1);    for(int i = 1; i <= n; i++) cout << prv[i] <<    ;    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n, w;     cin >> n >> w;     vector<int> a(n), b(n);     for (int& v : a) cin >> v;     for (int& v : b) cin >> v;     double l = 0, r = 2e9;     for (int t = 0; t < 500; t++) {       double m = (l + r) / 2;       double now = m;       for (int i = 0; i < n && now >= 0; i++) {         now -= (w + now) / a[i];         if (now < 0) break;         now -= (w + now) / b[(i + 1) % n];       }       if (now >= 0)         r = m;       else         l = m;     }     if (r == 2e9)       cout << -1 <<   n ;     else       cout << fixed << setprecision(10) << r <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int N;   set<pair<int, int>> E[202020];   signed long long ntot[202020];   int vis[202020];   vector<pair<int, signed long long>> V;   map<pair<int, int>, int> M;   vector<signed long long> chi[202020];   void dfs(int cur, signed long long tot) {     if (vis[cur]) return;     vis[cur] = 1;     V.push_back({cur, tot});     for (auto& e : E[cur]) dfs(e.first, tot + e.second);   }   signed long long X[202020], L[202020];   signed long long Rdia[202020], Rma[202020];   signed long long Ldia[202020], Lma[202020];   signed long long tma;   void solve() {     int i, j, k, l, r, x, y;     string s;     cin >> N;     for (i = 0; i < (N); i++) {       cin >> x >> y >> r;       E[x - 1].insert({y - 1, r});       E[y - 1].insert({x - 1, r});       M[{x - 1, y - 1}] = M[{y - 1, x - 1}] = r;     }     queue<int> Q;     for (i = 0; i < (N); i++)       if (E[i].size() == 1) Q.push(i);     while (Q.size()) {       int cur = Q.front();       Q.pop();       auto r = *E[cur].begin();       E[cur].clear();       int tar = r.first;       int co = r.second;       E[tar].erase({cur, co});       chi[cur].push_back(0);       chi[cur].push_back(0);       sort((chi[cur].begin()), (chi[cur].end()));       reverse((chi[cur].begin()), (chi[cur].end()));       tma = max(tma, chi[cur][0] + chi[cur][1]);       chi[tar].push_back(chi[cur][0] + co);       ntot[cur] = -1;       if (E[tar].size() == 1) Q.push(tar);     }     for (i = 0; i < (N); i++)       if (ntot[i] >= 0) {         chi[i].push_back(0);         chi[i].push_back(0);         sort((chi[i].begin()), (chi[i].end()));         reverse((chi[i].begin()), (chi[i].end()));         tma = max(tma, chi[i][0] + chi[i][1]);         ntot[i] = chi[i][0];       }     for (i = 0; i < (N); i++)       if (ntot[i] >= 0) {         dfs(i, 0);         break;       }     int C = V.size();     for (i = 0; i < (C); i++) {       X[i] = V[i].second;       L[i] = ntot[V[i].first];     }     signed long long tot = V.back().second + M[{V[0].first, V.back().first}];     signed long long mi = 1LL << 60;     signed long long RR = 0, LL = 1LL << 60;     for (i = C - 1; i >= 0; i--) {       Rma[i] = max(Rma[i + 1], tot - X[i] + L[i]);       Rdia[i] = max({Rdia[i + 1], RR - X[i] + L[i], L[i]});       RR = max(RR, X[i] + L[i]);     }     for (i = 0; i < (C); i++) {       Lma[i] = max(i ? Lma[i - 1] : 0, X[i] + L[i]);       Ldia[i] = max({i ? Ldia[i - 1] : 0, X[i] + L[i] - LL, L[i]});       LL = min(LL, X[i] - L[i]);       if (i == C - 1) {         mi = min(mi, Ldia[i]);       } else {         mi = min(mi, max({Ldia[i], Rdia[i + 1], Lma[i] + Rma[i + 1]}));       }     }     cout << max(tma, mi) << endl;   }   int main(int argc, char** argv) {     string s;     int i;     if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);     for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s +=   n ;     for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool cmp(long long a, long long b) { return (a > b); }   long long ceil(const long long &a, const long long &b) {     if (a % b == 0) return a / b;     return a / b + 1;   }   long long mod = 1000000007;   const long long N = 105;   string s;   long long n1;   long long res;   long long dp[N][60][2][2 * N];   long long solve(long long i, long long k, long long cnt = 0,                   long long z = 100) {     if (i == n1) {       if (k % 2 == 0) {         res = max(res, abs(z - 100));       }       return 0;     }     if (dp[i][k][cnt][z] != -1) {       return dp[i][k][cnt][z];     }     long long k1 = 0, k2 = 0;     if (s[i] ==  F ) {       if (k > 0) {         if (cnt % 2 == 0) {           k1 = 1 + solve(i + 1, k, 0, z + 1);           k2 = solve(i + 1, k - 1, 1, z);         } else {           k1 = -1 + solve(i + 1, k, 1, z - 1);           k2 = solve(i + 1, k - 1, 0, z);         }       } else {         if (cnt % 2 == 0) {           k1 = 1 + solve(i + 1, k, 0, z + 1);         } else {           k1 = -1 + solve(i + 1, k, 1, z - 1);         }       }     } else {       if (k > 0) {         if (cnt % 2 == 0) {           k1 = solve(i + 1, k, 1, z);           k2 = 1 + solve(i + 1, k - 1, 0, z + 1);         } else {           k1 = solve(i + 1, k, 0, z);           k2 = -1 + solve(i + 1, k - 1, 1, z - 1);         }       } else {         if (cnt % 2 == 0) {           k1 = solve(i + 1, k, 1, z);         } else {           k1 = solve(i + 1, k, 0, z);         }       }     }     return dp[i][k][cnt][z] = max(abs(k1), abs(k2));   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> s >> n;     n1 = s.size();     memset(dp, -1, sizeof(dp));     long long x = solve(0, n);     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool s[] = {1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1,               0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0};   int main() {     string str;     cin >> str;     for (int x = 0; x < str.length() / 2; x++) {       if (str[x] != str[str.length() - 1 - x]) {         cout <<  NO  << endl;         return 0;       }     }     for (int x = 0; x < str.length(); x++) {       if (!s[str[x] -  A ]) {         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e6 + 5;   int n;   long long int a[MAX], BIT[MAX];   void update(int idx, long long int val) {     for (; idx <= n; idx += (idx & (-idx))) {       BIT[idx] += val;     }   }   long long int sum(int idx) {     idx--;     long long int sumi = 0;     for (; idx > 0; idx -= (idx & (-idx))) {       sumi += BIT[idx];     }     return sumi;   }   int main() {     scanf( %d , &n);     int l[n], r[n];     map<long long int, int> make_pair;     for (int i = 0; i < n; i++) {       scanf( %I64d , &a[i]);       make_pair[a[i]]++;       l[i] = make_pair[a[i]];     }     make_pair.clear();     for (int i = n - 1; i >= 0; i--) {       make_pair[a[i]]++;       r[i] = make_pair[a[i]];     }     long long int ans = 0;     for (int i = n - 1; i >= 0; i--) {       ans += sum(l[i]);       update(r[i], 1);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, sumk;     cin >> n >> k;     k--;     int out[500][500];     sumk = 0;     int current = n * n;     for (int i = 0; i < n; ++i) {       for (int j = n - 1; j >= k; --j) {         out[i][j] = current;         if (j == k) {           sumk += current;         }         current--;       }     }     for (int i = 0; i < n; ++i) {       for (int j = k - 1; j >= 0; --j) {         out[i][j] = current;         current--;       }     }     cout << sumk << endl;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         cout << out[i][j] <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double EPS = 1E-9;   const int INF = (int)1E9;   int deg[2005];   long long w[2005][2005];   int main() {     int N, K;     long long sum = 0, x;     cin >> N >> K;     memset(deg, 0, sizeof(deg));     for (int i = 0; i < (N); i++) {       for (int j = (i + 1); j <= (N - 1); j++) {         scanf( %I64d , &w[i][j]);         if (w[i][j] != -1) {           deg[i]++;           deg[j]++;         }       }     }     for (int i = 0; i < (N); i++) {       for (int j = (i + 1); j <= (N - 1); j++) {         if (w[i][j] != -1) {           if (K == 1 || K == N - 1) {             sum += w[i][j] * 2;           } else {             sum += w[i][j] * (deg[i] + deg[j] - 2);           }         }       }     }     cout << sum / (K == 2 ? N * (N - 1) / 2 : N) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5 * 1e5 + 5;   const int M = 2e6 + 5;   vector<int> a[M], b[M];   vector<int> c[M], d[M];   int vis[M];   int n, w, cnt;   int main() {     scanf( %d%d , &n, &w);     w--;     for (int i = 1; i <= n; i++) {       int k;       scanf( %d , &k);       a[i].resize(k);       for (int j = 0; j < k; j++) {         int g;         scanf( %d , &g);         a[i][j] = g - 1;       }     }     for (int i = 1; i < n; i++) {       int up = min(a[i].size(), a[i + 1].size());       bool flag = false;       for (int j = 0; j < up; j++) {         if (a[i][j] > a[i + 1][j]) {           b[a[i][j]].push_back(a[i + 1][j]);           flag = true;           break;         } else if (a[i][j] < a[i + 1][j]) {           b[a[i][j]].push_back(a[i + 1][j]), flag = true;           break;         }       }       if (!flag && a[i].size() > a[i + 1].size()) {         puts( -1 );         return 0;       }     }     for (int i = 0; i < 1e6; i++) {       if (!b[i].size()) continue;       int mx = -1, mn = 1e6 + 5, mx2 = -1, mn2 = 1e6 + 5, add = w - i + 1;       for (int j : b[i]) {         mx = max(mx, j);         mn = min(mn, j);         mx2 = max(mx2, (j + add) % (w + 1));         mn2 = min(mn2, (j + add) % (w + 1));       }       cnt++;       if (mn > i) {         c[0].push_back(cnt);         d[w - mx].push_back(cnt);         c[w - i + 1].push_back(cnt);         d[2 * w - mx].push_back(cnt);       } else {         c[add].push_back(cnt);         d[add + w - mx2].push_back(cnt);       }     }     int ans = 0;     for (int i = 0; i < 1e6; i++) {       for (int j : c[i]) {         if (!vis[j]) ans++;         vis[j]++;       }       if (ans == cnt) {         printf( %d n , i);         return 0;       }       for (int j : d[i]) {         if (vis[j] == 1) ans--;         vis[j]--;       }     }     puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename U, typename V>   void Min(U &a, const V &b) {     if (a > b) a = b;   }   template <typename U, typename V>   void Max(U &a, const V &b) {     if (a < b) a = b;   }   template <typename U, typename V>   void add(U &a, const V &b) {     a = (a + b) % 1000000007;   }   template <typename U>   U gcd(U a, U b) {     if (a == 0) return b;     if (b == 0) return a;     if (a >= b)       return gcd(a % b, b);     else       return gcd(a, b % a);   }   int pow(int a, int b) {     int ans = 1;     while (b) {       if (b & 1) ans = 1LL * ans * a % 1000000007;       a = 1LL * a * a % 1000000007;       b >>= 1;     }     return ans;   }   int pow(int a, int b, int c) {     int ans = 1;     while (b) {       if (b & 1) ans = 1LL * ans * a % c;       a = 1LL * a * a % c;       b >>= 1;     }     return ans;   }   char s[2005];   vector<pair<int, int> > ans;   void solve(int l, int r, int K) {     if (l > r) return;     if (s[l] !=  ( ) {       for (int i = r + 1 - 1; i >= l + 1; i--)         if (s[i] ==  ( ) {           reverse(s + l, s + i + 1);           ans.push_back({l, i});           break;         }     }     if (s[r] !=  ) ) {       for (int i = l + 1; i < r; i++)         if (s[i] ==  ) ) {           reverse(s + i, s + r + 1);           ans.push_back({i, r});           break;         }     }     if (l + 1 == r) return;     if (K == 0) {       int m = (l + r + 1) >> 1;       int k = r - 1;       for (int i = l + 1; i < m; i++)         if (s[i] !=  ( ) {           while (k > i && s[k] ==  ) ) k--;           reverse(s + i, s + k + 1);           ans.push_back({i, k});         }     } else {       if (s[l + 1] !=  ) ) {         for (int i = l + 2; i < r; i++)           if (s[i] ==  ) ) {             reverse(s + l + 1, s + i + 1);             ans.push_back({l + 1, i});             break;           }       }       solve(l, l + 1, 1);       solve(l + 2, r, K - 1);     }   }   int main() {     int T, i, j, k, m, ca = 0, n, K;     scanf( %d , &T);     while (T--) {       scanf( %d%d%s , &n, &K, s);       K--;       ans.clear();       solve(0, n - 1, K);       printf( %d n , int(ans.size()));       for (auto &o : ans) printf( %d %d n , o.first + 1, o.second + 1);     }   }


#include <bits/stdc++.h>   int n, m;   std::vector<std::pair<int, int> > a[2];   void normalize(std::vector<std::pair<int, int> >& v) {     if (v.empty()) {       return;     }     std::sort((v).begin(), (v).end());     int k = 1;     for (int i = 1; i < ((int)(v).size()); i++) {       if (v[i].first != v[i - 1].first) {         v[k++] = v[i];       } else {         v[k - 1].second += v[i].second;       }     }     v.erase(v.begin() + k, v.end());   }   int calc(std::vector<std::pair<int, int> >& a,            std::vector<std::pair<int, int> >& b) {     if (((int)(a).size()) == 0) {       return 0;     }     int max = a.back().first - a.front().first;     for (int i = 0; i < ((int)(b).size()); i++) {       if (b[i].first <= a.front().first) {         max = std::max(max, n - (a.front().first - b[i].first));       }       if (b[i].first >= a.back().first) {         max = std::max(max, n - (b[i].first - a.back().first));       }     }     std::vector<std::pair<int, int> >::iterator itr =         std::lower_bound((b).begin(), (b).end(), std::make_pair(a[0].first, 0));     if (itr != b.end() && itr->first <= a.back().first) {       max = n;     }     return max;   }   long long binom(int n) { return 1LL * n * (n - 1) * (n - 2) / 6; }   long long COUNT(std::vector<std::pair<int, int> >& a,                   std::vector<std::pair<int, int> >& b, int max) {     if (calc(a, b) < max) {       return 0LL;     }     long long ways = 0;     int sum = 0, cnt = 0;     for (int i = 0; i < ((int)(a).size()); i++) {       sum += a[i].second;     }     for (int i = 0; i < ((int)(b).size()); i++) {       cnt += b[i].second;     }     std::vector<int> suffix(((int)(a).size()) + 1, 0);     for (int i = ((int)(a).size()) - 1; i >= 0; i--) {       suffix[i] = suffix[i + 1] + a[i].second;     }     if (a.back().first - a.front().first == max) {       ways += binom(sum);       ways -= binom(sum - a.front().second) + binom(sum - a.back().second);       ways += binom(sum - a.front().second - a.back().second);       ways += 1LL * a.front().second * a.back().second * cnt;     }     if (((int)(b).size()) > 0) {       for (int i = 0; i < ((int)(b).size()); i++) {         if (b[i].first < a.front().first) {           int tmp = n - (a.front().first - b[i].first);           if (tmp == max) {             ways +=                 1LL * a.front().second * (a.front().second - 1) / 2 * b[i].second;             ways +=                 1LL * a.front().second * (sum - a.front().second) * b[i].second;           }         }         if (b[i].first > a.back().first) {           int tmp = n - (b[i].first - a.back().first);           if (tmp == max) {             ways +=                 1LL * a.back().second * (a.back().second - 1) / 2 * b[i].second;             ways += 1LL * a.back().second * (sum - a.back().second) * b[i].second;           }         }       }       if (max == n) {         for (int i = 0; i < ((int)(b).size()); i++) {           std::vector<std::pair<int, int> >::iterator itr = std::lower_bound(               (a).begin(), (a).end(), std::make_pair(b[i].first, 0));           int p = 0, q = 0, r = 0;           p = suffix[0] - suffix[itr - a.begin()];           int t = itr - a.begin();           itr = std::lower_bound((a).begin(), (a).end(),                                  std::make_pair(b[i].first + 1, 0));           q = suffix[t] - suffix[itr - a.begin()];           r = suffix[0] - p - q;           ways += 1LL * q * p * b[i].second;           ways += 1LL * q * r * b[i].second;           ways += 1LL * p * r * b[i].second;           ways += 1LL * q * (q - 1) / 2 * b[i].second;         }       }     }     return ways;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int s, f;       scanf( %d%d , &s, &f);       a[s].push_back(std::make_pair(f, 1));     }     normalize(a[0]);     normalize(a[1]);     int max = std::max(calc(a[0], a[1]), calc(a[1], a[0]));     if (max == 0) {       std::cout << binom(m) << std::endl;     } else {       std::cout << COUNT(a[0], a[1], max) + COUNT(a[1], a[0], max) << std::endl;     }   }


#include <bits/stdc++.h>   using namespace std;   bool SR(int &x) { return scanf( %d , &x) == 1; }   bool SR(long long &x) { return scanf( %lld , &x) == 1; }   bool SR(double &x) { return scanf( %lf , &x) == 1; }   bool SR(char *s) { return scanf( %s , s) == 1; }   bool RI() { return true; }   template <typename I, typename... T>   bool RI(I &x, T &...tail) {     return SR(x) && RI(tail...);   }   void SP(const int x) { printf( %d , x); }   void SP(const long long x) { printf( %lld , x); }   void SP(const double x) { printf( %.16lf , x); }   void SP(const char *s) { printf( %s , s); }   void PL() { puts(  ); }   template <typename I, typename... T>   void PL(const I x, const T... tail) {     SP(x);     if (sizeof...(tail)) putchar(   );     PL(tail...);   }   const int maxn = 4e6 + 6;   struct Dsu {     int par[maxn], clc;     void init(int siz) {       clc = siz;       for (int i = 0; i < int(siz); i++) par[i] = i;     }     int find(int x) { return x == par[x] ? x : par[x] = find(par[x]); }     void merge(int a, int b) {       if (find(a) == find(b)) return;       par[find(a)] = find(b);       clc--;     }   } dsu;   int n, m;   void read() { RI(n, m); }   void build() {     int tot = n + m + n + m - 4;     dsu.init(tot);     int pt = 0;     for (int i = 0; i < int(tot / 2); i++) {       dsu.merge(i, pt--);       if (pt < 0) pt += tot;     }     pt = n - 1;     for (int i = (n - 1); i <= int(n - 1 + tot / 2 - 1); i++) {       dsu.merge(i, pt--);       if (pt < 0) pt += tot;     }   }   void sol() { PL(dsu.clc); }   int main() {     read();     build();     sol();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const N = 13;   int n, m, q;   long long dp[N][1 << N];   struct lca {     int u, v, c;   };   struct edge {     int u, v;   };   vector<edge> edges;   vector<lca> lcas;   inline bool valid(int mask, int sub, int u, int v) {     if (!(mask & (1 << u)) || !(mask & (1 << v))) return false;     if (bool(sub & (1 << u)) == bool(sub & (1 << v))) return false;     return true;   }   inline bool ok(int root, int child, int mask, int sub) {     for (auto ed : edges) {       int u = ed.u, v = ed.v;       if (!valid(mask, sub, u, v)) continue;       if (root == v) swap(u, v);       if (root != u || child != v) return false;     }     for (auto l : lcas) {       int u = l.u, v = l.v, c = l.c;       if (!valid(mask, sub, u, v)) continue;       if (c != root) return false;     }     return true;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> q;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       x--, y--;       edges.push_back({x, y});     }     for (int i = 0; i < q; i++) {       int x, y, c;       cin >> x >> y >> c;       x--, y--, c--;       if (x == y && x != c) return cout <<  0 n , 0;       lcas.push_back({x, y, c});     }     for (int i = 0; i < n; i++) dp[i][1 << i] = 1;     for (int mask = 1; mask < (1 << n); mask++) {       for (int root = 0; root < n; root++) {         if (!(mask & (1 << root))) continue;         int p = -1;         for (int i = 0; i < n; i++)           if ((mask & (1 << i)) && i != root) p = i;         if (p == -1) continue;         for (int sub = mask & (mask - 1); sub > 0; sub = (sub - 1) & mask) {           if ((sub & (1 << root)) || !(sub & (1 << p))) continue;           for (int child = 0; child < n; child++)             if (ok(root, child, mask, sub))               dp[root][mask] += dp[child][sub] * dp[root][mask ^ sub];         }       }     }     cout << dp[0][(1 << n) - 1] << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 101000;   int fa[maxn], sz[maxn], c[maxn];   int fd(int f) { return fa[f] == f ? f : fa[f] = fd(fa[f]); }   int n, m, f[maxn];   bool isok(int x) {     while (x) {       int d = x % 10;       if (d != 4 && d != 7) return false;       x /= 10;     }     return true;   }   void bp(int v, int w) {     for (int i = n; i >= v; --i) f[i] = min(f[i], f[i - v] + w);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) fa[i] = i;     for (int i = 1; i <= m; ++i) {       int u, v;       scanf( %d%d , &u, &v);       fa[fd(u)] = fd(v);     }     for (int i = 1; i <= n; ++i) sz[fd(i)]++;     for (int i = 1; i <= n; ++i) c[sz[i]]++, f[i] = 1e9;     for (int i = 1; i <= n; ++i)       if (c[i]) {         for (int s = 1; s <= c[i]; s <<= 1) bp(s * i, s), c[i] -= s;         bp(c[i] * i, c[i]);       }     int ans = 1e9;     for (int i = 1; i <= n; ++i)       if (isok(i)) ans = min(ans, f[i]);     printf( %d n , ans == 1e9 ? -1 : ans - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);     int n, x, y;     cin >> n >> x >> y;     int a[n];     for (int j = 0; j < n; j++) cin >> a[j];     if (x > y) {       cout << n;       return 0;     }     int count = 0;     for (int j = 0; j < n; j++) {       if (a[j] <= x) count++;     }     cout << (count + 1) / 2;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g[100001];   long long v[100001];   pair<long long, long long> r[100001];   int mark[100001];   void dfs(int s) {     mark[s] = 1;     r[s] = pair<long long, long long>(0, 0);     for (int i = 0; i < g[s].size(); i++) {       if (!mark[g[s][i]]) {         dfs(g[s][i]);         r[s].first = min(r[s].first, r[g[s][i]].first);         r[s].second = max(r[s].second, r[g[s][i]].second);       }     }     long long k = v[s] - r[s].first - r[s].second;     if (k > 0)       r[s].second = r[s].second + k;     else       r[s].first += k;   }   int main() {     int n;     memset(mark, 0, sizeof mark);     cin >> n;     int a, b;     for (int i = 0; i < n - 1; i++) {       cin >> a >> b;       g[a - 1].push_back(b - 1);       g[b - 1].push_back(a - 1);     }     for (int i = 0; i < n; i++) cin >> v[i];     dfs(0);     long long ans = -r[0].first + r[0].second;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, grid[2500][2500], R[10005], C[10005];   vector<pair<long long, pair<long long, long long> > > A, B;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (long long i = 0; i < n; i++)       for (long long j = 0; j < n; j++)         cin >> grid[i][j], R[i + j] += grid[i][j], C[i - j + 5000] += grid[i][j];     long long Min = (long long)1e18;     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < n; j++) {         long long Z = R[i + j] + C[i - j + 5000] - grid[i][j];         Min = min(Min, Z);         if (B.size() < 5000 || Z >= Min)           B.push_back(make_pair(R[i + j] + C[i - j + 5000] - grid[i][j],                                 make_pair(i, j)));       }     }     sort(B.begin(), B.end());     reverse(B.begin(), B.end());     long long a, b, x, y;     long long Max = 0;     for (long long i = 0; i < min((long long)B.size(), 5000LL); i++) {       for (long long j = 0; j < min((long long)B.size(), 3000LL); j++) {         if (B[i].first + B[j].first >= Max &&             ((B[i].second.first + B[i].second.second - B[j].second.first +               B[j].second.second)) %                 2 &&             ((B[i].second.first - B[i].second.second -               (B[j].second.first - B[j].second.second))) %                 2) {           a = B[i].second.first, b = B[i].second.second;           x = B[j].second.first, y = B[j].second.second;           Max = B[i].first + B[j].first;         }       }     }     cout << Max << endl;     cout << a + 1 <<     << b + 1 <<     << x + 1 <<     << y + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     long long now = 0;     long long mx = -1;     while (true) {       long long rem = (n - (now * 7));       if (rem < 0) {         break;       } else {         if (rem % 4 == 0) {           mx = max(mx, now);         }       }       now++;     }     if (mx == -1) {       cout << -1;       return 0;     } else {       long long four = n - (mx * 7);       four /= 4;       for (long long i = 0; i < four; i++) {         cout << 4;       }       for (long long i = 0; i < mx; i++) {         cout << 7;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int a[100005];   int Gcd(int x, int y) {     if (y == 0) return x;     return Gcd(y, x % y);   }   int main(void) {     int n, i, ans;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + n + 1);     ans = 0;     for (i = 1; i <= n; i++) ans = Gcd(ans, a[i]);     if (((a[n] / ans) - (n - 1)) % 2)       printf( Bob n );     else       printf( Alice n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     char mat[n][n];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> mat[i][j];       }     }     char a = mat[0][0];     char b = mat[0][1];     if (a == b) {       cout <<  NO  << endl;       return 0;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if ((i == j || i == (n - j - 1)) && mat[i][j] != a) {           cout <<  NO  << endl;           return 0;         } else if ((!(i == j || i == (n - j - 1)) && mat[i][j] != b)) {           cout <<  NO  << endl;           return 0;         }       }     }     cout <<  YES  << endl;   }


#include <bits/stdc++.h>   long long prod_dig(long long n) {     long long prod = 1;     int a;     while (n) {       a = n % 10;       if (a) {         prod *= a;       }       n /= 10;     }     return prod;   }   int arr[10][1000000 + 1];   int main() {     int t;     for (int i = 1; i <= 1000000; i++) {       t = i;       while (t / 10) {         t = prod_dig(t);       }       for (int j = 0; j < 10; j++) {         arr[j][i] = arr[j][i - 1];       }       arr[t][i]++;     }     int Q, l, r, x, key;     scanf( %d , &Q);     while (Q--) {       scanf( %d%d%d , &l, &r, &key);       printf( %d n , arr[key][r] - arr[key][l - 1]);     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T Abs(T a) {     return a > 0 ? a : -a;   }   void split(string s, string seps, vector<string> &res, bool doEmpty = false) {     int start = 0;     res.clear();     for (int i = 0; i < s.size(); i++) {       if (seps.find(s[i]) != string::npos) {         if (doEmpty || i - start > 0) res.push_back(s.substr(start, i - start));         start = i + 1;       }     }     if (doEmpty || s.size() - start > 0)       res.push_back(s.substr(start, s.size() - start));   }   string Union(vector<string> s, int start = 0) {     string res;     for (int i = start; i < s.size(); i++) res.append(s[i]);     return res;   }   int main() {     string s;     int n;     cin >> s >> n;     vector<string> b(n);     vector<int> fn(s.size());     for (int i = 0; i < n; i++) cin >> b[i];     for (int i = 0; i < n; i++) {       int k = 0;       while (k < s.length()) {         int r = s.find(b[i], k);         if (r == s.npos) break;         fn[r + b[i].size() - 1] = max(fn[r + b[i].size() - 1], r + 1);         k = r + 1;       }     }     int best = 0;     int bi = 0;     int cur = 0;     int ci = 0;     for (int i = 0; i < s.length(); i++) {       if (fn[i]) {         int lci = ci;         ci = -1;         int g = fn[i];         int j = i;         while (j >= g) {           g = max(g, fn[j]);           ci = j;           j--;         }         if (ci == -1) ci = i + 1;         cur = i - ci;       }       cur++;       if (cur > best) {         best = cur;         bi = ci;       }     }     cout << best <<     << bi;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t > 0) {       string s1, s2;       cin >> s1 >> s2;       long long int f = 0;       if (s1.length() > s2.length()) {         cout <<  NO  << endl;         f = -1;       } else {         long long int i = 0, j = 0;         while (i < s1.length() || j < s2.length()) {           if (s2[j] == s1[i] && s2[j + 1] == s1[i + 1]) {             j++;             i++;           } else if (s2[j] == s1[i])             j++;           else if (s2[j] == s1[i + 1] && j > 0)             i++;           else {             cout <<  NO  << endl;             f = -1;             break;           }         }         if (f != -1) cout <<  YES  << endl;       }       t--;     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     bool f = 0;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = 1;     for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);     if (f) x = -x;   }   template <typename F>   inline void write(F x, char ed =   n ) {     static short st[30];     short tp = 0;     if (x < 0) putchar( - ), x = -x;     do st[++tp] = x % 10, x /= 10;     while (x);     while (tp) putchar( 0  | st[tp--]);     putchar(ed);   }   template <typename T>   inline void Mx(T &x, T y) {     x < y && (x = y);   }   template <typename T>   inline void Mn(T &x, T y) {     x > y && (x = y);   }   const int N = 105;   const int P = 1e9 + 7;   long long dp[N][N][2], f[N][2], siz[N];   int h[N], ne[N << 1], to[N << 1], tot;   inline void add(int x, int y) { ne[++tot] = h[x], to[h[x] = tot] = y; }   void dfs(int x, int fa) {     dp[x][0][0] = dp[x][0][1] = siz[x] = 1;     for (int i = h[x], y; i; i = ne[i]) {       if ((y = to[i]) == fa) continue;       dfs(y, x);       memcpy(f, dp[x], sizeof(f));       memset(dp[x], 0, sizeof(dp[x]));       for (int j = 0; j < siz[x] + siz[y]; j++) {         for (int k = 0; k <= min(siz[x] - 1, (long long)j); k++) {           dp[x][j][0] = (dp[x][j][0] + f[k][0] * dp[y][j - k][1]) % P;           dp[x][j][1] = (dp[x][j][1] + f[k][1] * dp[y][j - k][1]) % P;           if (j != k) {             dp[x][j][0] = (dp[x][j][0] + f[k][0] * dp[y][j - k - 1][0]) % P;             dp[x][j][1] = (dp[x][j][1] + f[k][1] * dp[y][j - k - 1][0] +                            f[k][0] * dp[y][j - k - 1][1]) %                           P;           }         }       }       siz[x] += siz[y];     }   }   long long fpw(long long x, long long mi) {     long long res = 1;     for (; mi; mi >>= 1, x = x * x % P)       if (mi & 1) res = res * x % P;     return res;   }   long long mi[N], C[N][N], n;   int main() {     read(n);     for (int i = 1, x, y; i < n; i++) read(x), read(y), add(x, y), add(y, x);     dfs(1, 0);     mi[0] = fpw(n, P - 2) % P;     for (int i = 1; i <= n; i++) mi[i] = mi[i - 1] * n % P;     C[0][0] = 1;     for (int i = 1; i <= n; i++) {       C[i][0] = 1;       for (int j = 1; j <= n; j++) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % P;     }     for (int i = 0; i <= n - 1; i++)       dp[1][i][1] = dp[1][i][1] * mi[n - i - 1] % P;     for (int i = 0; i <= n - 1; i++) {       long long ans = 0;       for (int k = i; k <= n - 1; k++)         if ((k - i) & 1)           ans -= C[k][i] * dp[1][k][1] % P;         else           ans += C[k][i] * dp[1][k][1] % P;       write(((ans % P) + P) % P,    );     }     return 0;   }


#include<bits/stdc++.h>   using namespace std;       #define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)   mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());   #define endl              n    #define mp              make_pair   #define pb              push_back   #define ins             insert   #define lb              lower_bound   #define ub              upper_bound   #define ff              first   #define ss              second   #define sz(x)           (ll)(x).size()   #define vi              vector<int>   #define mt              make_tuple   #define mii             map<int,int>   #define um              unordered_map<int,int>   #define pii             pair<int,int>     #define maxpq           priority_queue<int>   #define minpq           priority_queue<int,vi,greater<int>>   #define setbits(x)      __builtin_popcountll(x)   #define ps(x,y)         fixed<<setprecision(y)<<x   #define all(x)          x.begin(), x.end()   #define allr(x)         rbegin(x), rend(x)   #define w(x)            int x; cin>>x; while(x--)     #define goog(tno)       cout <<  Case #  << tno << :     #define trace(x)        cerr<<#x<< :  <<x<<   <<endl;       typedef long double ld;   #define ll  long long int   #define ull unsigned ll   const int MOD = 1000000007;   const ll INF = 1e18;   const ld pi =3.14159265359;    // const int mod = 1000003;       template <class T> ll maxpower(T a , T b){ll ans = 0;while(a > 0 && a % b == 0){ans++;a /= b;}return ans;}   template <class T> T mceil(T a, T b){if(a % b == 0) return a/b; else return a/b + 1;}       //---------------------------------------------------------------------------   // cin>> vector<T>   template <class T> istream &operator>>(istream &in, vector<T> &a){for (auto &i : a)cin >> i;return in;}   // cout << vector<T>   template <class T> ostream &operator<<(ostream &ostream, const vector<T> &c){for (auto &it : c) cout << it <<    ;return ostream;}   //---------------------------------------------------------------------------       void __print(int x) {cerr << x;}   void __print(long x) {cerr << x;}   void __print(long long x) {cerr << x;}   void __print(unsigned x) {cerr << x;}   void __print(unsigned long x) {cerr << x;}   void __print(unsigned long long x) {cerr << x;}   void __print(float x) {cerr << x;}   void __print(double x) {cerr << x;}   void __print(long double x) {cerr << x;}   void __print(char x) {cerr <<      << x <<     ;}   void __print(const char *x) {cerr <<     << x <<    ;}   void __print(const string &x) {cerr <<     << x <<    ;}   void __print(bool x) {cerr << (x ?  true  :  false );}       template<typename T, typename V>   void __print(const pair<T, V> &x) {cerr <<  { ; __print(x.first); cerr <<  , ; __print(x.second); cerr <<  } ;}   template<typename T>   void __print(const T &x) {int f = 0; cerr <<  { ; for (auto &i: x) cerr << (f++ ?  ,  :   ), __print(i); cerr <<  } ;}   void _print() {cerr <<  ] n ;}   template <typename T, typename... V>   void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr <<  ,  ; _print(v...);}       #ifndef ONLINE_JUDGE   #define debug(x...) cerr <<  [  << #x <<  ] = [ ; _print(x)   #else   #define debug(x...)   #endif      int main(){       FIO;       w(t){           ll n;           cin>>n;              ll sum = 0;              for(ll i=0;i<n;i++){               ll x;               cin>>x;                  sum += x;           }              cout<<sum%n*(n-sum%n)<<endl;       }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010, M = 1505, mod = 1e9 + 7;   inline int qpow(int x, int y = mod - 2) {     int res = 1;     for (; y; y >>= 1, x = 1ll * x * x % mod)       if (y & 1) res = 1ll * res * x % mod;     return res;   }   int fac[N], inv[N];   inline int C(int x, int y) {     if (y < 0 || y > x) return 0;     return 1ll * fac[x] * inv[y] % mod * inv[x - y] % mod;   }   void C_init(int n) {     fac[0] = 1;     for (int i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % mod;     inv[n] = qpow(fac[n]);     for (int i = n - 1; ~i; i--) inv[i] = inv[i + 1] * (i + 1ll) % mod;   }   int n, m, p, np, k, B[M];   int pre_b[M], pre_bl[M];   void init() {     int a, b;     cin >> n >> m >> a >> b >> k;     p = 1ll * a * qpow(b) % mod, np = (1 - p + mod) % mod;     C_init(k);     for (int i = 0; i <= min(m - 1, k); ++i)       B[i] = 1ll * C(k, i) * qpow(p, i) % mod * qpow(np, k - i) % mod;     for (int i = 1; i <= m; ++i) pre_b[i] = (pre_b[i - 1] + B[i - 1]) % mod;   }   inline void add(int &x, int y) {     x += y;     if (x >= mod) x -= mod;   }   inline void sub(int &x, int y) {     x -= y;     if (x < 0) x += mod;   }   int L[M], F = 1;   void trans() {     static int S[M];     for (int i = 1; i <= m; ++i)       pre_bl[i] = (pre_bl[i - 1] + 1ll * B[i - 1] * L[i]) % mod;     for (int x = 1; x <= m; ++x)       S[x] = 1ll * B[m - x] *              (1ll * (F - L[m - x + 1] + mod) * pre_b[x] % mod - pre_bl[x] + mod) %              mod;     F = 0;     for (int i = 1; i <= m; ++i)       L[i] = (L[i - 1] + S[i - 1]) % mod, F = (F + S[i]) % mod;   }   int main() {     init();     while (n--) trans();     cout << F << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 5;   const long long L = 1e18 + 18;   int Z;   struct edge {     int s;     int t;     long long W;     int ind;     edge(int a, int b, long long c, int I) {       s = a;       t = b;       W = c;       ind = I;     }   };   struct cmp {     bool operator()(edge a, edge b) { return a.W > b.W; }   };   long long odl[N];   vector<edge> G[N];   vector<pair<long long, long long> > D[N];   void dfs(int v, int oj, int k);   int main() {     Z = 0;     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     for (long long i = 1; i <= n; i++) odl[i] = L;     for (long long i = 1; i <= m; i++) {       long long a, b, c;       scanf( %lld%lld%lld , &a, &b, &c);       G[a].push_back(edge(a, b, c, i));       G[b].push_back(edge(b, a, c, i));     }     priority_queue<edge, vector<edge>, cmp> kol;     odl[1] = 0;     for (auto z : G[1]) kol.push(z);     while (!kol.empty()) {       edge X = kol.top();       kol.pop();       if (odl[X.t] < L) continue;       odl[X.t] = X.W;       D[X.s].push_back(make_pair(X.t, X.ind));       for (auto z : G[X.t]) {         if (odl[z.t] > X.W + z.W) {           kol.push(edge(z.s, z.t, z.W + X.W, z.ind));         }       }     }     k = min(k, n - 1);     printf( %d n , k);     dfs(1, 1, k);     if (k > 0) printf(  n );   }   void dfs(int v, int oj, int k) {     for (auto z : D[v]) {       if (z.first == oj) continue;       if (Z >= k) break;       printf( %lld  , z.second);       Z++;       dfs(z.first, v, k);     }   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   template <typename T, size_t N>   int SIZE(const T (&t)[N]) {     return N;   }   template <typename T>   int SIZE(const T &t) {     return t.size();   }   string to_string(const string s, int x1 = 0, int x2 = 1e9) {     return     + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) :   ) +    ;   }   string to_string(const char *s) { return to_string((string)s); }   string to_string(const bool b) { return (b ?  true  :  false ); }   string to_string(const char c) { return string({c}); }   template <size_t N>   string to_string(const bitset<N> &b, int x1 = 0, int x2 = 1e9) {     string t =   ;     for (int __iii__ = min(x1, SIZE(b)), __jjj__ = min(x2, SIZE(b) - 1);          __iii__ <= __jjj__; ++__iii__) {       t += b[__iii__] +  0 ;     }     return     + t +    ;   }   template <typename A, typename... C>   string to_string(const A(&v), int x1 = 0, int x2 = 1e9, C... coords);   int l_v_l_v_l = 0, t_a_b_s = 0;   template <typename A, typename B>   string to_string(const pair<A, B> &p) {     l_v_l_v_l++;     string res =  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;     l_v_l_v_l--;     return res;   }   template <typename A, typename... C>   string to_string(const A(&v), int x1, int x2, C... coords) {     int rnk = rank<A>::value;     string tab(t_a_b_s,    );     string res =   ;     bool first = true;     if (l_v_l_v_l == 0) res +=   n ;     res += tab +  [ ;     x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v));     auto l = begin(v);     advance(l, x1);     auto r = l;     advance(r, (x2 - x1) + (x2 < SIZE(v)));     for (auto e = l; e != r; e = next(e)) {       if (!first) {         res +=  ,  ;       }       first = false;       l_v_l_v_l++;       if (e != l) {         if (rnk > 1) {           res +=   n ;           t_a_b_s = l_v_l_v_l;         };       } else {         t_a_b_s = 0;       }       res += to_string(*e, coords...);       l_v_l_v_l--;     }     res +=  ] ;     if (l_v_l_v_l == 0) res +=   n ;     return res;   }   void dbgm() { ; }   template <typename Heads, typename... Tails>   void dbgm(Heads H, Tails... T) {     cerr << to_string(H) <<   |  ;     dbgm(T...);   }   const long long mod = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cerr <<  ...............Console is yours! :).................           <<   n ;     long long n;     int m;     cin >> n >> m;     string num = to_string(n);     int l = num.length();     long long dp[1 << l][m];     memset(dp, 0, sizeof(dp));     long long fac = 1;     int count[10];     memset(count, 0, sizeof(count));     for (int i = 0; i < l; i++) fac *= ++count[num[i] -=  0 ];     dp[0][0] = 1;     for (int i = 0; i < 1 << l; i++) {       for (int j = 0; j < l; j++) {         if (!(i & (1 << j)) && (i || num[j])) {           for (int k = 0; k < m; k++)             dp[i | (1 << j)][(k * 10 + num[j]) % m] += dp[i][k];         }       }     }     cout << dp[(1 << l) - 1][0] / fac <<   n ;     cerr <<  ......^_^.....           <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using Int = long long;   template <typename T1, typename T2>   inline void chmin(T1 &a, T2 b) {     if (a > b) a = b;   }   template <typename T1, typename T2>   inline void chmax(T1 &a, T2 b) {     if (a < b) a = b;   }   struct FastIO {     FastIO() {       cin.tie(0);       ios::sync_with_stdio(0);     }   } fastio_beet;   signed main() {     Int n;     cin >> n;     vector<Int> bs(n);     for (Int i = 0; i < n; i++) cin >> bs[i];     map<Int, Int> sum;     for (Int i = 0; i < n; i++) sum[bs[i] - i] += bs[i];     Int ans = 0;     for (auto p : sum) chmax(ans, p.second);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int LOG = 22;   int32_t main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     vector<int> tab(n);     vector<int> dp(1 << LOG);     vector<pair<int, int> > samples(1 << LOG, {-1, -1});     auto update = [&](int a, int i) {       if (i == -1) return;       if (samples[a].first != -1) samples[a].second = i;       samples[a].first = i;     };     for (int i = 0; i < n; i++) {       cin >> tab[i];       dp[tab[i]]++;       update(tab[i], i);     }     for (int i = 0; i < LOG; i++) {       for (int m = 0; m < (1 << LOG); m++) {         if (m & (1 << i)) {           dp[m] += dp[m ^ (1 << i)];           update(m, samples[m ^ (1 << i)].first);           update(m, samples[m ^ (1 << i)].second);         }       }     }     for (int i = 0; i < n; i++) {       int a = tab[i] ^ ((1 << LOG) - 1);       if (samples[a].first == i)         cout << (samples[a].second == -1 ? -1 : tab[samples[a].second]) <<    ;       else         cout << (samples[a].first == -1 ? -1 : tab[samples[a].first]) <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int s, x1, x2, t1, t2, p, d;   int main() {     cin >> s >> x1 >> x2 >> t1 >> t2 >> p >> d;     int t = 0, flag1 = 0, flag2 = 0;     while (flag1 == 0 || flag2 == 0) {       if (flag1) {         if (p == x2) break;       } else if (p == x1)         flag1 = 1;       if (p == 0 || p == s) d = -d;       p += d;       t++;     }     cout << min(t * t1, abs(x1 - x2) * t2) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   void run(istream &cin, ostream &cout) {     int n, m;     cin >> n >> m;     string a, b;     cin >> a >> b;     int diff = n - m;     if (diff > 0) {       b = string(diff,  0 ) + b;     } else {       a = string(-diff,  0 ) + a;     }     n = max(n, m);     vector<long long> suff(n);     for (int i = 0; i < n; i++) {       suff[i] = (b[i] ==  1 );       if (i > 0) {         suff[i] += suff[i - 1];       }     }     long long pw = 1, ans = 0;     for (int i = n - 1; i >= 0; i--) {       if (a[i] ==  1 ) {         ans = (ans + pw * suff[i] % mod) % mod;       }       pw = pw * 2 % mod;     }     cout << ans;   }   int main() {     cin.tie(0);     ios::sync_with_stdio(0);     run(cin, cout);     return 0;   }


#include <bits/stdc++.h>   int n, m, k;   int kex[101][101] = {0};   int main() {     scanf( %d%d%d , &n, &m, &k);     int i;     int x, y;     int have = 0;     for (i = 0; i < k; i++) {       scanf( %d%d , &x, &y);       if (x <= 5 || x >= n - 4 || y <= 5 || y >= m - 4) have = 1;     }     if (have)       printf( YES );     else       printf( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int testcases;     cin >> testcases;     while (testcases) {       int n, s, t;       cin >> n >> s >> t;       if (s > t)         cout << (s - (s + t - n) + 1) <<   n ;       else         cout << (t - (s + t - n) + 1) <<   n ;       testcases--;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma G++ optimize(2)   using namespace std;   const int MAX_N = 1e5 + 5;   long long n, k;   long long a[MAX_N], b[MAX_N];   bool use[MAX_N];   long long cal(int i, long long x) { return a[i] - 3 * x * x + 3 * x - 1; }   long long check(long long delta) {     long long sum = 0;     for (register int i = 1; i <= n; ++i) {       if (cal(i, 1) < delta) {         b[i] = 0, use[i] = false;         continue;       }       long long l = 1, r = a[i], mid, ans;       while (l <= r) {         mid = (l + r) >> 1;         if (cal(i, mid) >= delta)           l = mid + 1, ans = mid;         else           r = mid - 1;       }       b[i] = ans;       use[i] = (cal(i, ans) == delta);       sum += ans;     }     return sum;   }   int main() {     scanf( %lld , &n), scanf( %lld , &k);     for (register int i = 1; i <= n; ++i) scanf( %lld , &a[i]);     long long l = -4e18, r = 1e9, mid, ans;     while (l <= r) {       mid = (l + r) >> 1;       if (check(mid) >= k)         l = mid + 1, ans = mid;       else         r = mid - 1;     }     k -= check(ans);     for (int i = 1; i <= n && k < 0; i++)       if (use[i] && b[i]) ++k, --b[i];     for (register int i = 1; i <= n; ++i)       printf( %lld%c , b[i], i == n ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   int n;   long long k;   int a[N];   int main() {     cin >> n >> k;     k -= n * 1LL * (n + 1) / 2;     if (k < 0) {       printf( -1 n );       return 0;     }     iota(a + 1, a + n + 1, 1);     reverse(a + 1, a + n + 1);     long long added = 0;     for (int i = 1; i <= n / 2; i++) added += a[i] - i;     long long diff = max(0LL, added - k);     printf( %lld n , n * 1LL * (n + 1) / 2 + added - diff);     for (int i = 1; i <= n / 2; i++) {       if (diff >= a[i] - i) {         diff -= (a[i] - i);         swap(a[i], a[n + 1 - i]);       }     }     if (diff == 1) {       if (n % 2 == 1) {         a[n / 2] = n / 2 + 1;         a[n / 2 + 1] = n / 2;         a[n / 2 + 2] = n / 2 + 2;       } else {         a[n / 2 - 1] = n / 2;         a[n / 2] = n / 2 - 1;         a[n / 2 + 1] = n / 2 + 2;         a[n / 2 + 2] = n / 2 + 1;       }     }     for (int i = 1; i <= n; i++) printf( %d  , i);     printf(  n );     for (int i = 1; i <= n; i++) printf( %d  , a[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<pair<double, string> > p(6);     p[0].first = 6 % 6;     p[0].second =  1/1 ;     p[1].first = 5 % 6;     p[1].second =  5/6 ;     p[2].first = 4 % 6;     p[2].second =  2/3 ;     p[3].first = 3 % 6;     p[3].second =  1/2 ;     p[4].first = 2 % 6;     p[4].second =  1/3 ;     p[5].first = 1 % 6;     p[5].second =  1/6 ;     vector<int> x(2);     for (int i = 0; i < 2; i++) cin >> x[i];     sort(x.begin(), x.end());     double prob = (7 - x[1]) % 6;     for (int i = 0; i < 6; i++) {       if (p[i].first == prob && x[1] <= 6) {         cout << p[i].second << endl;         return 0;       }     }     cout <<  0/1  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, b;   string a, c;   int main() {     cin >> n;     int l = -2e9, r = 2e9;     for (; n--;) {       cin >> a >> b >> c;       if (a ==  >  && c ==  Y  || a ==  <=  && c ==  N )         l = max(l, b + 1);       else if (a ==  >=  && c ==  Y  || a ==  <  && c ==  N )         l = max(l, b);       else if (a ==  <  && c ==  Y  || a ==  >=  && c ==  N )         r = min(r, b - 1);       else         r = min(r, b);     }     if (l > r)       puts( Impossible );     else       printf( %d , l);   }