#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   long long dp[31][31][51];   long long calc(long long x, long long y, long long k) {     if (dp[x][y][k] || !k || x * y == k) return dp[x][y][k];     long long ans = 1e9;     for (long long i = 1; 2 * i <= x; i++) {       for (long long j = 0; j <= k; j++) {         ans = min(ans, y * y + calc(i, y, j) + calc(x - i, y, k - j));       }     }     for (long long i = 1; 2 * i <= y; i++) {       for (long long j = 0; j <= k; j++) {         ans = min(ans, x * x + calc(x, i, j) + calc(x, y - i, k - j));       }     }     return dp[x][y][k] = ans;   }   void solve() {     long long t;     cin >> t;     while (t--) {       long long n, m, k;       cin >> n >> m >> k;       cout << calc(n, m, k) <<   n ;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long tests;     tests = 1;     for (long long i = 0; i < tests; i++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)2e5 + 45;   const int inf = 0x3f3f3f3f;   void ttf() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   int z[N], p[N];   void solve() {     string s;     cin >> s;     int n = (int)s.length();     z[0] = n;     for (int i = 1, l = 0, r = 0; i < n; ++i) {       if (i <= r) z[i] = min(r - i + 1, z[i - l]);       while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];       if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;     }     for (int i = 0; i < n; ++i) {       p[z[i]]++;     }     for (int i = n - 1; i >= 1; --i) {       p[i] += p[i + 1];     }     vector<pair<int, int> > v;     for (int i = 0; i < n; ++i) {       if (z[i] + i == n) {         v.push_back(make_pair(z[i], p[z[i]]));       }     }     cout << ((int)(v.size())) << endl;     reverse(v.begin(), v.end());     for (int i = 0; i < ((int)(v.size())); ++i)       cout << v[i].first <<     << v[i].second << endl;   }   int main() {     ttf();     int t = 1;     for (int i = 1; i <= t; i++) {       solve();     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   const int MOD = 1e9 + 7;   vector<int> v;   long long f[301][N];   int a[N];   int main() {     for (int i = 1; i <= 300; i++) {       f[i][0] = 1;       for (int j = 1; j < N; j++) {         f[i][j] = f[i][j - 1] * i % MOD;       }     }     int n, x, sum;     while (scanf( %d , &n) != EOF) {       for (int i = 1; i <= n; i++) {         scanf( %d , &x);         a[x]++;       }       for (int i = 100000; i > 1; i--) a[i - 1] += a[i];       long long ans = 1;       for (int i = 2; i <= 100000; i++) {         if (a[i] == 0) continue;         v.clear();         for (int j = 1; j * j <= i; j++) {           if (i % j == 0) {             v.push_back(j);             if (j != i / j) v.push_back(i / j);           }         }         sort(v.begin(), v.end());         int len = v.size();         long long ret1 = 1, ret2 = 1;         sum = 0;         for (int j = len - 1; j >= 0; j--) {           if (a[v[j]] <= sum) continue;           ret1 = ret1 * f[j + 1][a[v[j]] - sum] % MOD;           sum = a[v[j]];         }         sum = 0;         for (int j = len - 2; j >= 0; j--) {           if (a[v[j]] <= sum) continue;           ret2 = ret2 * f[j + 1][a[v[j]] - sum] % MOD;           sum = a[v[j]];         }         ans = ((ans + ret1 - ret2) % MOD + MOD) % MOD;       }       printf( %I64d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M, cnt[101];   int main() {     int N, M, cnt[101] = {0};     scanf( %d%d , &N, &M);     for (int i = 0; i < N; i++) {       int t;       scanf( %d , &t);       int now = M - t;       int ans = i;       for (int j = 1; j <= 100; j++) {         int get = min(now / j, cnt[j]);         now -= get * j;         ans -= get;       }       cnt[t]++;       printf( %d%c , ans, i == N - 1 ? 10 : 32);     }   }


#include <bits/stdc++.h>   std::vector<long long> G[100001];   std::vector<long long> psn[100001];   std::vector<long long> arr[100001][20];   long long par[100001], lvl[100001];   long long P[100001][20];   void dfs_visit(long long s, long long p) {     if (p != -1) {       par[s] = p;       lvl[s] = 1 + lvl[p];     }     for (long long i = 0, j = (long long)G[s].size(); i < j; i++) {       if (G[s][i] != p) dfs_visit(G[s][i], s);     }     return;   }   std::vector<long long> merger(std::vector<long long> left,                                 std::vector<long long> right) {     std::vector<long long> res;     long long n1 = (long long)left.size(), n2 = (long long)right.size();     long long i = 0, j = 0, k = 0;     while (i != n1 && j != n2 && k != 10) {       if (left[i] < right[j]) {         res.push_back(left[i]);         i++;       } else if (left[i] > right[j]) {         res.push_back(right[j]);         j++;       } else {         res.push_back(left[i]);         i++;         j++;       }       k++;     }     while (i != n1 && k != 10) {       res.push_back(left[i]);       i++;       k++;     }     while (j != n2 && k != 10) {       res.push_back(right[j]);       j++;       k++;     }     return res;   }   void ST_build(long long n) {     for (long long i = 1; i <= n; i++) {       for (long long j = 0; (1 << j) <= n; j++) P[i][j] = -1;     }     for (long long i = 1; i <= n; i++) {       P[i][0] = par[i];       arr[i][0] = merger(psn[i], psn[par[i]]);     }     for (long long j = 1; (1 << j) <= n; j++) {       for (long long i = 1; i <= n; i++) {         if (P[i][j - 1] != -1) {           P[i][j] = P[P[i][j - 1]][j - 1];           arr[i][j] = merger(arr[i][j - 1], arr[P[i][j - 1]][j - 1]);         }       }     }     return;   }   std::vector<long long> LCA_find(long long p, long long q) {     std::vector<long long> res = merger(psn[p], psn[q]);     if (lvl[p] < lvl[q]) {       long long tmp = p;       p = q;       q = tmp;     }     long long lx = 0;     for (lx = 1; (1 << lx) <= lvl[p]; lx++)       ;     lx--;     for (long long i = lx; i >= 0; i--) {       if ((lvl[p] - (1 << i)) >= lvl[q]) {         res = merger(res, arr[p][i]);         p = P[p][i];       }     }     if (p == q) return res;     for (long long i = lx; i >= 0; i--) {       if ((P[p][i] != -1) && (P[p][i] != P[q][i])) {         res = merger(res, arr[p][i]);         res = merger(res, arr[q][i]);         p = P[p][i];         q = P[q][i];       }     }     res = merger(res, arr[p][0]);     res = merger(res, arr[q][0]);     return res;   }   int main(void) {     std::ios_base::sync_with_stdio(false);     std::cin.tie(NULL);     std::cout.tie(NULL);     long long n, m, q;     std::cin >> n >> m >> q;     for (long long i = 0; i < n - 1; i++) {       long long s, d;       std::cin >> s >> d;       G[s].push_back(d);       G[d].push_back(s);     }     for (long long i = 1; i <= m; i++) {       long long t;       std::cin >> t;       if ((long long)psn[t].size() < 10) psn[t].push_back(i);     }     dfs_visit(1, -1);     ST_build(n);     while (q--) {       long long v, u, a;       std::cin >> v >> u >> a;       std::vector<long long> ans = LCA_find(v, u);       a = std::min(a, (long long)ans.size());       std::cout << a <<    ;       for (long long i = 0; i < a; i++) std::cout << ans[i] <<    ;       std::cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[10001];   int main() {     int test;     cin >> test;     while (test--) {       int n;       cin >> n;       vector<int> ans1, ans2;       for (int i = 0; i < 2 * n; i++) cin >> arr[i];       vector<pair<int, int> > vp;       for (int i = 0; i < 2 * n; i++) {         if (arr[i] % 2 == 0)           ans2.push_back(i + 1);         else           ans1.push_back(i + 1);       }       for (int i = 1; i < ans2.size(); i += 2)         vp.push_back({ans2[i], ans2[i - 1]});       for (int i = 1; i < ans1.size(); i += 2)         vp.push_back({ans1[i], ans1[i - 1]});       for (int i = 0; i < n - 1; i++)         cout << vp[i].first <<     << vp[i].second <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n, d;       cin >> n >> d;       long long int a[n];       for (long long int i = 0; i < n; i++) cin >> a[i];       long long int ans = a[0];       for (long long int i = 1; i < n; i++) {         if (d > 0) ans += min((d / i), a[i]);         d -= a[i] * i;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     ll t;     cin >> t;     for (ll i = 0; i < t; i++) {       ll n;       cin >> n;       vector<ll> in(n);       vector<ll> count(n + 1);       for (ll i = 0; i < n; i++) {         cin >> in[i];         count[in[i]]++;       }       vector<ll> ops;       while (true) {         ll mex = 0;         while (count[mex] > 0) mex++;         if (mex < n) {           ops.push_back(mex);           count[in[mex]]--;           in[mex] = mex;           count[mex]++;         } else {           ll j = 0;           while (in[j] == j) j++;           if (j >= n) break;           ops.push_back(j);           count[in[j]]--;           in[j] = mex;           count[mex]++;         }       }       cout << (ll)(ops).size() << endl;       for (ll x : ops) {         cout << x + 1 <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void amin(T &x, U y) {     if (y < x) x = y;   }   template <typename T, typename U>   inline void amax(T &x, U y) {     if (x < y) x = y;   }   struct UnionFind {     vector<int> data;     UnionFind(int size_) : data(size_, -1) {}     bool unionSet(int x, int y) {       x = root(x);       y = root(y);       if (x != y) {         if (data[y] < data[x]) swap(x, y);         data[x] += data[y];         data[y] = x;       }       return x != y;     }     bool findSet(int x, int y) { return root(x) == root(y); }     int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }     int size(int x) { return -data[root(x)]; }   };   struct Edge {     int x, y;     int w;     Edge() {}     Edge(int x_, int y_, int w_) : x(x_), y(y_), w(w_) {}   };   bool operator<(const Edge &a, const Edge &b) { return a.w < b.w; }   vector<vector<int> > g;   vector<long long> dist;   vector<vector<int> > d;   void dfs(int i, int p, long long t) {     dist[i] = t;     for (typeof((g[i]).begin()) j = ((g[i]).begin()); j != (g[i]).end(); ++j)       if (*j != p) dfs(*j, i, t + d[i][*j]);   }   int main() {     int n;     scanf( %d , &n);     d.assign(n, vector<int>(n));     for (int(i) = 0; (i) < (int)(n); ++(i))       for (int(j) = 0; (j) < (int)(n); ++(j)) scanf( %d , &d[i][j]);     bool ok = true;     for (int(i) = 0; (i) < (int)(n); ++(i))       for (int(j) = 0; (j) < (int)(i); ++(j)) {         ok &= d[i][j] == d[j][i];         ok &= d[i][j] > 0;       }     for (int(i) = 0; (i) < (int)(n); ++(i)) ok &= d[i][i] == 0;     if (!ok) {       puts( NO );       return 0;     }     vector<Edge> edges;     edges.reserve(n * (n - 1) / 2);     for (int(i) = 0; (i) < (int)(n); ++(i))       for (int(j) = 0; (j) < (int)(i); ++(j))         edges.push_back(Edge(i, j, d[i][j]));     sort(edges.begin(), edges.end());     UnionFind uf(n);     g.assign(n, vector<int>());     for (int i = 0; i < (int)edges.size(); i++) {       int x = edges[i].x, y = edges[i].y;       if (uf.unionSet(x, y)) {         g[x].push_back(y);         g[y].push_back(x);       }     }     dist.resize(n);     for (int(i) = 0; (i) < (int)(n); ++(i)) {       dfs(i, -1, 0);       for (int(j) = 0; (j) < (int)(n); ++(j)) ok &= dist[j] == d[i][j];     }     puts(ok ?  YES  :  NO );     return 0;   }


#include <bits/stdc++.h>   namespace Factor {   const int N = 1010000;   int64_t C, fac[10010], n, mut, a[1001000];   int T, cnt, i, l, prime[N], p[N], psize, _cnt;   int64_t _e[100], _pr[100];   std::vector<int64_t> d;   inline int64_t mul(int64_t a, int64_t b, int64_t p) {     if (p <= 1000000000)       return a * b % p;     else if (p <= 1000000000000ll)       return (((a * (b >> 20) % p) << 20) + (a * (b & ((1 << 20) - 1)))) % p;     else {       return (int64_t)((__int128_t)a * b % p);     }   }   void prime_table() {     int i, j, tot, t1;     for (i = 1; i <= psize; i++) p[i] = i;     for (i = 2, tot = 0; i <= psize; i++) {       if (p[i] == i) prime[++tot] = i;       for (j = 1; j <= tot && (t1 = prime[j] * i) <= psize; j++) {         p[t1] = prime[j];         if (i % prime[j] == 0) break;       }     }   }   void init(int ps) {     psize = ps;     prime_table();   }   int64_t powl(int64_t a, int64_t n, int64_t p) {     int64_t ans = 1;     for (; n; n >>= 1) {       if (n & 1) ans = mul(ans, a, p);       a = mul(a, a, p);     }     return ans;   }   bool witness(int64_t a, int64_t n) {     int t = 0;     int64_t u = n - 1;     for (; ~u & 1; u >>= 1) t++;     int64_t x = powl(a, u, n), _x = 0;     for (; t; t--) {       _x = mul(x, x, n);       if (_x == 1 && x != 1 && x != n - 1) return 1;       x = _x;     }     return _x != 1;   }   bool miller(int64_t n) {     if (n < 2) return 0;     if (n <= psize) return p[n] == n;     if (~n & 1) return 0;     for (int j = 0; j <= 7; j++)       if (witness(rand() % (n - 1) + 1, n)) return 0;     return 1;   }   int64_t gcd(int64_t a, int64_t b) {     int64_t ret = 1;     while (a != 0) {       if ((~a & 1) && (~b & 1))         ret <<= 1, a >>= 1, b >>= 1;       else if (~a & 1)         a >>= 1;       else if (~b & 1)         b >>= 1;       else {         if (a < b) std::swap(a, b);         a -= b;       }     }     return ret * b;   }   int64_t rho(int64_t n) {     for (;;) {       int64_t X = rand() % n, Y, Z, T = 1, *lY = a, *lX = lY;       int tmp = 20;       C = rand() % 10 + 3;       X = mul(X, X, n) + C;       *(lY++) = X;       lX++;       Y = mul(X, X, n) + C;       *(lY++) = Y;       for (; X != Y;) {         int64_t t = X - Y + n;         Z = mul(T, t, n);         if (Z == 0) return gcd(T, n);         tmp--;         if (tmp == 0) {           tmp = 20;           Z = gcd(Z, n);           if (Z != 1 && Z != n) return Z;         }         T = Z;         Y = *(lY++) = mul(Y, Y, n) + C;         Y = *(lY++) = mul(Y, Y, n) + C;         X = *(lX++);       }     }   }   void _factor(int64_t n) {     for (int i = 0; i < cnt; i++) {       if (n % fac[i] == 0) n /= fac[i], fac[cnt++] = fac[i];     }     if (n <= psize) {       for (; n != 1; n /= p[n]) fac[cnt++] = p[n];       return;     }     if (miller(n))       fac[cnt++] = n;     else {       int64_t x = rho(n);       _factor(x);       _factor(n / x);     }   }   void dfs(int64_t x, int dep) {     if (dep == _cnt)       d.push_back(x);     else {       dfs(x, dep + 1);       for (int i = 1; i <= _e[dep]; i++) dfs(x *= _pr[dep], dep + 1);     }   }   void norm() {     std::sort(fac, fac + cnt);     _cnt = 0;     for (int i = 0; i < cnt; ++i)       if (i == 0 || fac[i] != fac[i - 1])         _pr[_cnt] = fac[i], _e[_cnt++] = 1;       else         _e[_cnt - 1]++;   }   std::vector<int64_t> getd() {     d.clear();     dfs(1, 0);     return d;   }   std::vector<int64_t> factor(int64_t n) {     cnt = 0;     _factor(n);     norm();     return getd();   }   std::vector<std::pair<int64_t, int64_t>> factorG(int64_t n) {     cnt = 0;     _factor(n);     norm();     std::vector<std::pair<int64_t, int64_t>> d;     for (int i = 0; i < _cnt; ++i) d.emplace_back(_pr[i], _e[i]);     return d;   }   bool is_primitive(int64_t a, int64_t p) {     assert(miller(p));     std::vector<std::pair<int64_t, int64_t>> D = factorG(p - 1);     for (int i = 0; i < D.size(); ++i)       if (powl(a, (p - 1) / D[i].first, p) == 1) return 0;     return 1;   }   }  // namespace Factor   int64_t powll(int64_t a, int64_t n) {     int64_t ans = 1;     for (; n; n >>= 1) {       if (n & 1) ans = ans * a;       a = a * a;     }     return ans;   }   int64_t mul(int64_t x, int64_t y, int64_t m) {     x %= m;     y %= m;     assert(x >= 0 && y >= 0);     int64_t d = ((long double)x * y / m);     d = x * y - d * m;     if (d >= m) d -= m;     if (d < 0) d += m;     return d;   }   int64_t Inv(int64_t q, int64_t m) {     if (q == 0) return 0;     assert(q >= 0);     int64_t a1 = m, b1 = 0, a2 = q, b2 = 1, a3, b3, t;     while (a2 != 1) {       t = a1 / a2, a3 = a1 - t * a2, b3 = b1 - mul(t, b2, m), a1 = a2, a2 = a3,       b1 = b2, b2 = b3;       if (b2 < 0) b2 += m;     }     return b2;   }   int main() {     Factor::init(500000);     int64_t m, x;     std::cin >> m >> x;     auto factors = Factor::factor(m);     int64_t ans = 0;     for (int64_t n : factors) {       int64_t a = x % n;       auto for_phi = Factor::factorG(n);       int64_t phi = n;       for (auto pr : for_phi) {         phi -= phi / pr.first;       }       auto pfac = Factor::factorG(phi);       int64_t t = phi;       for (auto& i : pfac) {         t /= powll(i.first, i.second);         int64_t a1 = Factor::powl(a, t, n);         while (a1 != 1) {           a1 = Factor::powl(a1, i.first, n);           t = mul(t, i.first, n);         }       }       ans += phi / t;     }     std::cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n;   struct point {     double x, y;   } a, b, t, q[100010];   struct wxz {     double d1, d2;   } f[100010];   double ans, delta1[100010], delta2[100010], delta;   double dist(point u, point v) {     return sqrt((u.x - v.x) * (u.x - v.x) + (u.y - v.y) * (u.y - v.y));   }   bool vis[100010];   int main() {     scanf( %lf%lf%lf%lf%lf%lf , &a.x, &a.y, &b.x, &b.y, &t.x, &t.y);     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lf%lf , &q[i].x, &q[i].y);     for (int i = 1; i <= n; i++) ans += 2 * dist(t, q[i]);     for (int i = 1; i <= n; i++) f[i].d1 = dist(a, q[i]) - dist(t, q[i]);     for (int i = 1; i <= n; i++) f[i].d2 = dist(b, q[i]) - dist(t, q[i]);     double delta = 1e18, dd1 = 1e18, dd2 = 1e18;     for (int i = 1; i <= n; i++) {       delta = min(delta, min(dd1 + f[i].d2, dd2 + f[i].d1));       dd1 = min(dd1, f[i].d1), dd2 = min(dd2, f[i].d2);     }     printf( %lf n , ans + min(delta, min(dd1, dd2)));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool vis[105][105];   int main() {     int n;     scanf( %d , &n);     int m;     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       int x;       scanf( %d , &x);       vis[1][x] = true;     }     for (int i = 2; i <= n; i++) {       int m;       scanf( %d , &m);       for (int j = 1; j <= m; j++) {         int x;         scanf( %d , &x);         if (vis[i - 1][x]) vis[i][x] = true;       }     }     for (int i = 1; i <= 100; i++)       if (vis[n][i]) printf( %d  , i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, n, k;   double jumlah, x[101], y[101];   int main() {     scanf( %d %d , &n, &k);     for (i = 1; i <= n; ++i) {       scanf( %lf %lf , &x[i], &y[i]);     }     for (i = 1; i < n; ++i) {       jumlah += sqrt(((x[i] - x[i + 1]) * (x[i] - x[i + 1])) +                      ((y[i] - y[i + 1]) * (y[i] - y[i + 1])));     }     jumlah = ((jumlah / 50) * k);     printf( %.9lf n , jumlah);   }


#include <bits/stdc++.h>   using namespace std;   long long a[20], b[20];   long long ans = 0;   void print() {     for (int i = 0; i < 14; i++) cout << b[i] <<    ;     cout << endl;   }   int main() {     for (int i = 0; i < 14; i++) cin >> a[i];     for (int i = 0; i < 14; i++) {       if (a[i]) {         for (int j = 0; j < 14; j++) b[j] = a[j];         long long score = 0;         long long tmp = b[i];         b[i] = 0;         for (int j = 0; j < 14; j++) b[j] += tmp / 14;         for (int j = 1; j <= tmp % 14; j++) b[(i + j) % 14]++;         for (int j = 0; j < 14; j++)           if (b[j] % 2 == 0) score += b[j];         ans = max(ans, score);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int maxn = 1e6 + 7;   long long t, n, k, temp;   int main(int argc, char* argv[]) {     cin >> t;     while (t--) {       cin >> n >> k;       long long cnt = 0;       while (n > 0) {         if (n % k != 0) {           cnt += n % k;           n -= n % k;         } else {           cnt++;           n /= k;         }       }       cout << cnt << endl;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     long long n, x;     int q, i;     scanf( %lld %i , &n, &q);     while (q--) {       scanf( %lld , &x);       while (!(x & 1)) {         x += (n - (x >> 1));       }       printf( %lld n , (x + 1) / 2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[111111], b[111111], n, m, k;   int main() {     while (scanf( %d%d%d , &n, &m, &k) != EOF) {       for (int i = 1; i <= n; i++) scanf( %d , &a[i]);       for (int i = 1; i <= m; i++) scanf( %d , &b[i]);       sort(a + 1, a + 1 + n);       sort(b + 1, b + 1 + m);       bool yes = 0;       for (int i = 0; i <= max(n, m); i++) {         if (n - i < 1 || m - i < 1) break;         if (a[n - i] > b[m - i]) {           yes = 1;           printf( YES n );           break;         }       }       if (yes) continue;       if (n > m)         printf( YES n );       else         printf( NO n );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       if (s.size() % 2)         cout <<  NO n ;       else {         string word1 =   , word2 =   ;         for (int i = 0; i < s.size() / 2; i++) word1 += s[i];         for (int i = s.size() / 2; i < s.size(); i++) word2 += s[i];         if (word1 == word2)           cout <<  YES n ;         else           cout <<  NO n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int MOD = 100, MAX = 1e6 + 5;   const long long INF = 1e18 + 5;   int main() {     string s;     cin >> s;     long long n = (s[1] -  0 ) + (s[3] -  0 ) * 10 + (s[4] -  0 ) * 100 +                   (s[2] -  0 ) * 1000 + (s[0] -  0 ) * 10000;     long long Ans = 1;     for (int i = 0; i < 5; i++) {       Ans = (Ans * n) % 100000;     }     string x = to_string(Ans);     reverse(x.begin(), x.end());     while (x.size() != 5) {       x +=  0 ;     }     reverse(x.begin(), x.end());     cout << x << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long M = 1e10;   set<long long> s;   void bt(long long x) {     if (x >= M) return;     s.insert(x);     bt(x * 10 + 4);     bt(x * 10 + 7);   }   int main() {     bt(0);     int l, r;     cin >> l >> r;     long long c = 0;     for (set<long long>::iterator it = s.begin(); it != s.end(); it++) {       if (*it >= l) {         if (r <= *it) {           c += (r - l + 1) * *it;           break;         } else           c += (*it - l + 1) * *it;         l = *it + 1;       }     }     cout << c << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e5 + 5;   int n;   pair<int, int> a[MAX];   struct par {     int a, b;     par(int a, int b) : a(a), b(b) {}     bool operator<(const par &p) const { return b < p.b; }   };   multiset<par> s;   multiset<int> sizes;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i].first);       a[i].second = i;     }     sort(a + 1, a + n + 1);     int best = 1, opt = a[n].first + 1;     for (int i = 1; i <= n; i++) {       if (!sizes.empty()) {         auto x = sizes.begin();         auto y = sizes.rbegin();         int v = a[i - 1].first + 1;         if (*x == *y) {           if ((int)sizes.size() > best) {             best = sizes.size();             opt = v;           } else if ((int)sizes.size() == best && a[i].first < opt)             opt = v;         }       }       auto u = s.upper_bound(par(0, a[i].second));       par intervalo = par(a[i].second, a[i].second);       vector<par> del;       if (u != s.end()) {         auto o = *u;         if (o.a - 1 == a[i].second) {           del.push_back(o);           intervalo.b = o.b;         }       }       if (u != s.begin()) {         u--;         auto o = *u;         if (o.b + 1 == a[i].second) {           del.push_back(o);           intervalo.a = o.a;         }       }       for (auto o : del) {         s.erase(s.find(o));         int sz = o.b - o.a + 1;         sizes.erase(sizes.find(sz));       }       s.insert(intervalo);       sizes.insert(intervalo.b - intervalo.a + 1);     }     printf( %d n , opt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, h;   int main() {     cin >> n >> h;     for (int i = 1; i < n; i++) {       double h1 = h * sqrt(1.0 * i / n);       printf( %.12llf  , h1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void dbs(string str, T t) {     cerr << str <<   :   << t <<   n ;   }   template <class T, class... S>   void dbs(string str, T t, S... s) {     long long idx = str.find( , );     cerr << str.substr(0, idx) <<   :   << t <<  ,  ;     dbs(str.substr(idx + 1), s...);   }   template <class S, class T>   ostream& operator<<(ostream& os, const pair<S, T>& p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <class T>   ostream& operator<<(ostream& os, const vector<T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class T>   ostream& operator<<(ostream& os, const set<T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class S, class T>   ostream& operator<<(ostream& os, const map<S, T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class T>   void prc(T a, T b) {     cerr <<  [ ;     for (T i = a; i != b; ++i) {       if (i != a) cerr <<  ,  ;       cerr << *i;     }     cerr <<  ] n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t, i, j, k, n, m, q;     long long x, y, l, r;     string s;     long long len;     cin >> len;     cin >> s;     vector<long long> pos(len + 7, -1);     long long cur = 1;     for (i = 0; i < len; i++) {       if (s[i] ==  8 ) {         pos[cur++] = i;       }     }     long long moves = (len - 11) / 2;     cur = min(cur - 1, moves);     dbs( cur, pos[cur], pos[cur + 1] , cur, pos[cur], pos[cur + 1]);     if (pos[cur + 1] == -1 || pos[cur + 1] - (cur) > moves) {       cout <<  NO  << endl;     } else {       cout <<  YES  << endl;     }     return 0;   }


#include <bits/stdc++.h>   namespace chtholly {   char buf[1 << 23], *p1 = buf, *p2 = buf;   inline int read() {     int x = 0, f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar()) f ^= c ==  - ;     for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^  0 );     return f ? x : -x;   }   template <typename mitsuha>   inline bool read(mitsuha &x) {     x = 0;     int f = 1;     char c = getchar();     for (; !isdigit(c) && ~c; c = getchar()) f ^= c ==  - ;     if (!~c) return 0;     for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^  0 );     return x = f ? x : -x, 1;   }   template <typename mitsuha>   inline int write(mitsuha x) {     if (!x) return 0 & putchar(48);     if (x < 0) putchar( - ), x = -x;     int bit[20], i, p = 0;     for (; x; x /= 10) bit[++p] = x % 10;     for (i = p; i; --i) putchar(bit[i] + 48);     return 0;   }   inline char fuhao() {     char c = getchar();     for (; isspace(c); c = getchar())       ;     return c;   }   }  // namespace chtholly   using namespace chtholly;   using namespace std;   const int yuzu = 2e5;   typedef int fuko[yuzu | 10];   vector<int> lj[yuzu | 10];   fuko a;   int zxy;   int dfs(int u, int lxy, int fa = 0) {     if (a[u] % lxy) return 0;     for (; a[u] % lxy == 0; a[u] /= lxy)       ;     vector<int> v;     for (int i : lj[u])       if (i ^ fa) v.push_back(dfs(i, lxy, u));     sort(v.begin(), v.end(), greater<int>());     int llx = 1;     if (v.size()) llx += v[0];     if (v.size() > 1) zxy = max(zxy, llx + v[1]);     return zxy = max(zxy, llx), llx;   }   int main() {     int i, j, n = read(), u, v;     for (i = 1; i <= n; ++i) a[i] = read();     for (i = 1; i < n; ++i) {       read(u), read(v);       lj[u].push_back(v);       lj[v].push_back(u);     }     for (i = 1; i <= n; ++i) {       for (j = 2; j * j <= a[i]; ++j)         if (a[i] % j == 0) dfs(i, j);       if (a[i] > 1) dfs(i, a[i]);     }     write(zxy), puts(  );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     while (T--) {       long long a, b, c, d;       cin >> a >> b >> c >> d;       if (c <= d) {         if (a <= b * c)           cout << a << endl;         else {           cout << -1 << endl;         }       } else {         long long len = c % d ? c / d + 1 : c / d;         long long ans = 0;         long long x = (b * d + 2 * a) / 2 / b / d;         x = min(x, len);         ans = a * x - x * (x - 1) / 2 * b * d;         x++;         x = min(x, len);         ans = max(ans, a * x - x * (x - 1) / 2 * b * d);         if (a > b * c)           cout << -1 << endl;         else {           ans = max(ans, a * len - (len - 1) * len / 2 * d * b);           cout << ans << endl;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int flag = 0;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int num, num1;       string str;       cin >> str >> num >> num1;       if (num >= 2400 && (num1 - num) > 0) {         flag = 1;         break;       }     }     if (flag)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int limite = 100005;   pair<int, int> maximo[limite];   void inserta(int pos, int val) {     pair<int, int> valor(val, pos);     for (; pos < limite; pos += pos & -pos) maximo[pos] = max(maximo[pos], valor);   }   int computamaximo(int pos) {     pair<int, int> maxi(0, 0);     for (; pos > 0; pos -= pos & -pos) maxi = max(maxi, maximo[pos]);     return maxi.second;   }   int n;   int a[limite];   long long int sr[limite];   long long int sol = 0;   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i < n; i++) cin >> a[i];     for (int i = n - 1; i >= 1; i--) {       if (a[i] == n)         sr[i] = n - i;       else {         int jmin = computamaximo(a[i]);         sr[i] = a[i] - i + sr[jmin] - (a[i] - jmin) + (n - a[i]);       }       sol += sr[i];       inserta(i, a[i]);     }     cout << sol << endl;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const long long inf = 1e9;   const int MAXM = 1048800;   const int MAXN = 1e7 + 1;   bool visit[MAXM];   int a[MAXM];   int k;   vector<int> v;   int main() {     int n, i, j, k;     cin >> n;     n *= 2;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int ans = INT_MAX, cnt = 0;     sort(a, a + n);     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         v.clear();         cnt = 0;         for (int k = 0; k < n; k++) {           if (k == i or k == j) continue;           v.push_back(a[k]);         }         int nn = v.size();         for (int k = 0; k < nn; k += 2) {           cnt += v[k + 1] - v[k];         }         ans = min(ans, cnt);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     vector<pair<string, int>> v;     priority_queue<int, vector<int>, greater<int>> pq;     for (int i = 0; i < n; ++i) {       string s;       cin >> s;       int x;       if (s !=  removeMin ) {         cin >> x;         v.push_back({s, x});       } else         v.push_back({s, INT_MIN});     }     vector<pair<string, int>> ans;     for (int i = 0; i < n; ++i) {       if (v[i].first ==  insert )         ans.push_back({v[i].first, v[i].second}), pq.push(v[i].second);       else if (v[i].first ==  getMin ) {         int val = v[i].second;         if (pq.empty()) {           ans.push_back({ insert , val});           pq.push(val);         }         while (!pq.empty() && val > pq.top()) {           ans.push_back({ removeMin , INT_MIN});           pq.pop();         }         if (!pq.empty() && val < pq.top()) {           ans.push_back({ insert , val});           pq.push(val);         } else if (pq.empty()) {           ans.push_back({ insert , val});           pq.push(val);         }         ans.push_back({ getMin , val});       } else {         if (pq.empty()) {           ans.push_back({ insert , 0});           pq.push(0);         }         ans.push_back({ removeMin , INT_MIN});         pq.pop();       }     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); ++i) {       if (ans[i].first ==  removeMin )         cout << ans[i].first << endl;       else         cout << ans[i].first <<     << ans[i].second << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> parent;   vector<int> Rank;   vector<int> Count;   int root(int v) {     if (parent[v] == v) return v;     return parent[v] = root(parent[v]);   }   bool DSU(int a, int b) {     a = root(a);     b = root(b);     if (a != b) {       if (Rank[b] > Rank[a]) swap(a, b);       Rank[a] += Rank[b];       Count[a] += Count[b];       parent[b] = a;       return true;     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m, k;     cin >> n >> m >> k;     vector<pair<long long int, pair<int, int> > > Edges(m);     parent.resize(n + 1);     for (int i = 1; i <= n; i++) parent[i] = i;     Rank.resize(n + 1, 1);     Count.resize(n + 1, 0);     for (int i = 0; i < k; i++) {       int a;       cin >> a;       Count[a] = 1;     }     for (int i = 0; i < m; i++) {       int a, b;       long long int w;       cin >> a >> b >> w;       Edges[i] = make_pair(w, make_pair(a, b));     }     sort(Edges.begin(), Edges.end());     long long int last = -1;     for (int i = 0; i < m; i++) {       int a = Edges[i].second.first;       int b = Edges[i].second.second;       long long int w = Edges[i].first;       if (a != b) {         DSU(a, b);         if (last == -1 && Count[root(a)] == k) {           last = w;         }       }     }     for (int i = 0; i < k; i++) {       cout << last <<    ;     }     return 0;   }


#include <bits/stdc++.h>   struct {     inline operator int() {       int x;       return scanf( %d , &x), x;     }     inline operator long long() {       long long x;       return scanf( %lld , &x), x;     }     template <class T>     inline void operator()(T &x) {       x = *this;     }     template <class T, class... A>     inline void operator()(T &x, A &...a) {       x = *this;       this->operator()(a...);     }   } read;   const int maxn = 120005;   long long his[maxn << 2];   int min[maxn << 2], tot[maxn << 2], mot[maxn << 2], pat[maxn << 2];   void modi(int now, int x) {     min[now] += x;     mot[now] += x;   }   void pass(int now, int x) {     his[now] += 1ll * tot[now] * x;     pat[now] += x;   }   void push(int now) {     if (mot[now]) {       modi((now << 1), mot[now]);       modi((now << 1 | 1), mot[now]);       mot[now] = 0;     }     if (pat[now]) {       if (min[(now << 1)] == min[now]) pass((now << 1), pat[now]);       if (min[(now << 1 | 1)] == min[now]) pass((now << 1 | 1), pat[now]);       pat[now] = 0;     }   }   void modify(int now, int L, int R, int l, int r, int x) {     if (r < L or l > R) return;     if (l <= L and R <= r) return modi(now, x);     push(now);     int M = (L + R) >> 1;     modify((now << 1), L, M, l, r, x);     modify((now << 1 | 1), M + 1, R, l, r, x);     his[now] = his[(now << 1)] + his[(now << 1 | 1)];     min[now] = std::min(min[(now << 1)], min[(now << 1 | 1)]);     tot[now] = 0;     if (min[(now << 1)] == min[now]) tot[now] += tot[(now << 1)];     if (min[(now << 1 | 1)] == min[now]) tot[now] += tot[(now << 1 | 1)];   }   long long query(int now, int L, int R, int l, int r) {     if (r < L or l > R) return 0;     if (l <= L and R <= r) return his[now];     push(now);     int M = (L + R) >> 1;     return query((now << 1), L, M, l, r) + query((now << 1 | 1), M + 1, R, l, r);   }   void build(int now, int L, int R) {     min[now] = L;     tot[now] = 1;     if (L == R) return;     int M = (L + R) >> 1;     build((now << 1), L, M);     build((now << 1 | 1), M + 1, R);   }   void test(int now, int L, int R) {     if (L == R) {       fprintf(stderr,   %d , min[now]);       return;     }     push(now);     int M = (L + R) >> 1;     test((now << 1), L, M);     test((now << 1 | 1), M + 1, R);     if (now == 1) fprintf(stderr,   n );   }   int a[maxn];   long long ans[maxn];   int st1[maxn], sp1;   int st2[maxn], sp2;   std::vector<std::pair<int, int> > v[maxn];   int main() {     int n = read;     for (int i = 1; i <= n; i++) read(a[i]);     int q = read;     for (int i = 1; i <= q; i++) {       int l = read, r = read;       v[r].push_back(std::pair<int, int>(l, i));     }     build(1, 1, n);     for (int r = 1; r <= n; r++) {       while (sp2 and a[st2[sp2]] > a[r])         modify(1, 1, n, st2[sp2 - 1] + 1, st2[sp2], a[st2[sp2]]), --sp2;       st2[++sp2] = r;       modify(1, 1, n, st2[sp2 - 1] + 1, st2[sp2], -a[st2[sp2]]);       while (sp1 and a[st1[sp1]] < a[r])         modify(1, 1, n, st1[sp1 - 1] + 1, st1[sp1], -a[st1[sp1]]), --sp1;       st1[++sp1] = r;       modify(1, 1, n, st1[sp1 - 1] + 1, st1[sp1], a[st1[sp1]]);       modi(1, -1);       pass(1, 1);       for (std::pair<int, int> p : v[r])         ans[p.second] = query(1, 1, n, p.first, r);     }     for (int i = 1; i <= q; i++) printf( %lld n , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   int n, a[26];   char pal[111111];   inline bool is_pal(int k, int can) {     vector<int> odd(0);     for (int i = 0; i < n; ++i) {       if (a[i] % k) return 0;       if (a[i] % (2 * k)) odd.push_back(i);     }     if ((int)(odd).size() > 1) return 0;     if ((int)(odd).size() == 1 && !can) return 0;     int pos = 0;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < a[i] / (2 * k); ++j) {         pal[pos++] =  a  + i;       }     }     if ((int)(odd).size()) pal[pos++] =  a  + odd[0];     for (int i = n - 1; i >= 0; --i) {       for (int j = 0; j < a[i] / (2 * k); ++j) {         pal[pos++] =  a  + i;       }     }     pal[pos] = 0;     return 1;   }   inline void die(int ans, int reps, char middle) {     printf( %d n , ans);     for (int i = 0; i < reps; ++i) {       printf( %s , pal);       if (middle !=  ! ) printf( %c , middle);     }     printf(  n );     exit(0);   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);     }     for (int ans = 111111; ans > 1; --ans) {       if (ans % 2 == 1) {         for (int let = 0; let < n; ++let) {           if (a[let] >= ans) {             a[let] -= ans;             if (is_pal(ans, 0)) {               die(ans, ans,  a  + let);             }             a[let] += ans;           }         }       } else {         for (int let = 0; let < n; ++let) {           if (is_pal(ans / 2, 0)) {             die(ans, ans / 2,  ! );           }         }       }     }     if (is_pal(1, 1)) {       die(1, 1,  ! );     }     printf( 0 n );     for (int i = 0; i < n; ++i) {       for (int j = 0; j < a[i]; ++j) {         printf( %c ,  a  + i);       }     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     scanf( %d %d , &n, &k);     char c[200005];     scanf( %s , c);     int ok[26];     memset(ok, 0, sizeof(ok));     for (int i = 0; i < k; i++) {       char cc;       scanf(  %c , &cc);       ok[cc -  a ] = 1;     }     long long cnt = 0;     long long ans = 0;     for (int i = 0; c[i] != 0; i++) {       if (ok[c[i] -  a ])         cnt++;       else {         ans += cnt * (cnt + 1) / 2;         cnt = 0;       }     }     ans += cnt * (cnt + 1) / 2;     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   string s, t;   int l[200005], r[200005];   int dp[30][200005];   void gd() {     cout <<  No ;     exit(0);   }   bool check(int lr, int rl, int c) {     return ((lr ? dp[c][lr - 1] : 0) - (rl ? dp[c][rl - 1] : 0) > 0);   }   int main() {     ios_base::sync_with_stdio(0);     cin >> s >> t;     s =  *  + s;     int n = (int)s.size();     int m = (int)t.size();     for (int i = 1; i < n; ++i) {       l[i] = l[i - 1];       if (s[i] == t[l[i]]) ++l[i];     }     for (int i = n - 1; i; --i) {       r[i] = r[i + 1];       if (s[i] == t[m - 1 - r[i]]) ++r[i];     }     if (l[n - 1] != m || r[1] != m) gd();     for (int i = 0; i < 26; ++i)       for (int j = 0; j < m; ++j) {         char c = i +  a ;         dp[i][j] = (j ? dp[i][j - 1] : 0) + (t[j] == c);       }     for (int i = 1; i < n; ++i) {       int rg = m - r[i];       int lg = l[i];       if (rg > lg || !check(lg, rg, s[i] -  a )) gd();     }     cout <<  Yes ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M, K;   int color[200002];   vector<int> edge[200002];   int id[200002];   int ite = 1;   int siz[200002];   map<int, int> m[200002];   int ans;   void dfs(int a) {     if (id[a]) {       return;     }     id[a] = ite;     for (int i = 0; i < edge[a].size(); i++) {       dfs(edge[a][i]);     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     if (fopen( cf731c.in ,  r )) {       freopen( cf731c.in ,  r , stdin);       freopen( cf731c.out ,  w , stdout);     }     cin >> N >> M >> K;     for (int i = 0; i < N; i++) {       cin >> color[i];     }     for (int i = 0; i < M; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       edge[a].push_back(b);       edge[b].push_back(a);     }     for (int i = 0; i < N; i++) {       if (id[i] == 0) {         dfs(i);         ite++;       }     }     for (int i = 0; i < N; i++) {       siz[id[i]]++;       m[id[i]][color[i]]++;     }     for (int i = 1; i < ite; i++) {       int mx = -1;       for (auto it = m[i].begin(); it != m[i].end(); it++) {         mx = max(mx, it->second);       }       ans += (siz[i] - mx);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class A, class B>   ostream &operator<<(ostream &out, const pair<A, B> &a) {     return out <<  (  << a.first <<  ,  << a.second <<  ) ;   }   template <class A>   ostream &operator<<(ostream &out, const vector<A> &a) {     for (const A &it : a) out << it <<    ;     return out;   }   template <class A, class B>   istream &operator>>(istream &in, pair<A, B> &a) {     return in >> a.first >> a.second;   }   template <class A>   istream &operator>>(istream &in, vector<A> &a) {     for (A &i : a) in >> i;     return in;   }   ifstream cinn( in.txt );   ofstream coutt( out.txt );   int poww(const int &a, int b, const int &m = (1000000007)) {     if (b == 0) return 1;     int x = poww(a, b / 2, m);     x = x * x % m;     if (b & 1) x = x * a % m;     return x;   }   int ceil(const int &a, const int &b) { return (a - 1) / b + 1; }   int primes[5000005];   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     for (int i = 2; i < 5000005; i++) {       if (primes[i]) continue;       for (int j = i; j < 5000005; j += i) {         int in = j;         while (in % i == 0) {           in /= i;           primes[j]++;         }       }     }     for (int i = 1; i < 5000005; i++) primes[i] += primes[i - 1];     int t;     cin >> t;     while (t--) {       int a, b;       cin >> a >> b;       cout << primes[a] - primes[b] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   string s;   const int MAXN = 100005;   int tz[4 * MAXN], tx[4 * MAXN], ty[4 * MAXN];   int cntz(int v, int tl, int tr, int l, int r) {     if (l > r) return 0;     if (tl == l && r == tr) return tz[v];     int tm = (tl + tr) / 2;     return cntz(2 * v, tl, tm, l, min(tm, r)) +            cntz(2 * v + 1, tm + 1, tr, max(tm + 1, l), r);   }   int cnty(int v, int tl, int tr, int l, int r) {     if (l > r) return 0;     if (tl == l && r == tr) return ty[v];     int tm = (tl + tr) / 2;     return cnty(2 * v, tl, tm, l, min(tm, r)) +            cnty(2 * v + 1, tm + 1, tr, max(tm + 1, l), r);   }   int cntx(int v, int tl, int tr, int l, int r) {     if (l > r) return 0;     if (tl == l && r == tr) return tx[v];     int tm = (tl + tr) / 2;     return cntx(2 * v, tl, tm, l, min(tm, r)) +            cntx(2 * v + 1, tm + 1, tr, max(tm + 1, l), r);   }   void buildz(int v, int tl, int tr) {     if (tl == tr)       tz[v] = (s[tl] ==  z );     else {       int tm = (tl + tr) / 2;       buildz(2 * v, tl, tm);       buildz(2 * v + 1, tm + 1, tr);       tz[v] = tz[2 * v] + tz[2 * v + 1];     }   }   void buildy(int v, int tl, int tr) {     if (tl == tr)       ty[v] = (s[tl] ==  y );     else {       int tm = (tl + tr) / 2;       buildy(2 * v, tl, tm);       buildy(2 * v + 1, tm + 1, tr);       ty[v] = ty[2 * v] + ty[2 * v + 1];     }   }   void buildx(int v, int tl, int tr) {     if (tl == tr)       tx[v] = (s[tl] ==  x );     else {       int tm = (tl + tr) / 2;       buildx(2 * v, tl, tm);       buildx(2 * v + 1, tm + 1, tr);       tx[v] = tx[2 * v] + tx[2 * v + 1];     }   }   int main() {     cin >> s;     int n, l = s.length();     buildz(1, 0, l - 1);     buildy(1, 0, l - 1);     buildx(1, 0, l - 1);     cin >> n;     for (int i = 0, a, b; i < n; ++i) {       cin >> a >> b;       int z = cntz(1, 0, l - 1, a - 1, b - 1);       int y = cnty(1, 0, l - 1, a - 1, b - 1);       int x = cntx(1, 0, l - 1, a - 1, b - 1);       int t = min(x, min(y, z));       z -= t;       y -= t;       x -= t;       if (b - a + 1 <= 2 || (z <= 1 && x <= 1 && y <= 1))         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   const long long mod = 1e9 + 7;   const long long N = 222;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   long long n, k;   vector<long long> adj[N];   long long dp[N][N], dp2[N][N], a[N];   void input() {     cin >> n >> k;     k++;     for (long long i = (1); i <= (n); i++) cin >> a[i];     for (long long i = (1); i <= (n - 1); i++) {       long long x, y;       cin >> x >> y;       ;       adj[x].push_back(y);       adj[y].push_back(x);     }   }   void dfs(long long cur = 1, long long prev = 0) {     for (long long i : adj[cur])       if (i != prev) dfs(i, cur);     for (long long p = (k); p >= (0); p--) {       if (p >= (k + 1) / 2) {         long long mx = -inf;         for (long long i : adj[cur])           if (i != prev) {             dp2[cur][p] += dp2[i][p - 1];             mx = max(mx, dp[i][p - 1] - dp2[i][p - 1]);           }         dp[cur][p] = dp2[cur][p] + mx;       } else {         long long mx = -inf;         if (!p) mx = a[cur];         for (long long i : adj[cur])           if (i != prev) {             dp[cur][p] += dp2[i][(k - p) - 1];             if (p) mx = max(mx, dp[i][p - 1] - dp2[i][(k - p) - 1]);           }         dp[cur][p] += mx;         dp2[cur][p] = max(dp[cur][p], dp2[cur][p + 1]);       }     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     input();     dfs();     cout << dp2[1][0];   }


#include <bits/stdc++.h>   using namespace std;   struct fenwick {     long long n, fen[100005];     void resize(int _n) {       n = _n + 1;       memset(fen, 0, sizeof fen);     }     int query(int ind) {       ind++;       int ans = 0;       while (ind >= 1) {         ans += fen[ind];         ind -= ind & -ind;       }       return ans;     }     void update(int ind, int val) {       ind++;       while (ind <= n) {         fen[ind] += val;         ind += ind & -ind;       }     }     int query(int l, int r) { return query(r) - query(l - 1); }   };   const int maxn = 100001;   int n, l, w, x, y, sz[maxn];   long long res;   bool blocked[maxn];   vector<pair<int, int> > c, v[maxn];   fenwick tree;   void dfs(int node, int pnode, int curw, int curl) {     c.push_back(make_pair(curw, curl));     for (auto &i : v[node])       if (i.first != pnode && !blocked[i.first])         dfs(i.first, node, curw + i.second, curl + 1);   }   long long solve(int node, int curw, int curl) {     long long ret = 0;     c.clear();     dfs(node, 0, curw, curl);     sort(c.begin(), c.end());     for (auto &i : c) tree.update(i.second, 1);     for (int i = 0, j = c.size() - 1; i < c.size(); i++) {       while (i <= j && c[i].first + c[j].first > w)         tree.update(c[j--].second, -1);       if (j < i) break;       tree.update(c[i].second, -1);       ret += tree.query(l - c[i].second);     }     return ret;   }   int dfsz(int node, int pnode) {     sz[node] = 1;     for (auto &i : v[node])       if (i.first != pnode && !blocked[i.first]) sz[node] += dfsz(i.first, node);     return sz[node];   }   int find(int node, int pnode, int n) {     for (auto &i : v[node])       if (i.first != pnode && !blocked[i.first] && 2 * sz[i.first] > n)         return find(i.first, node, n);     return node;   }   void decompose(int node) {     int centroid = find(node, 0, dfsz(node, 0));     blocked[centroid] = 1;     res += solve(centroid, 0, 0);     for (auto &i : v[centroid])       if (!blocked[i.first])         res -= solve(i.first, i.second, 1), decompose(i.first);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> l >> w;     tree.resize(n + 1);     for (int i = 2; i <= n && cin >> x >> y; i++) {       v[i].push_back(make_pair(x, y));       v[x].push_back(make_pair(i, y));     }     decompose(1);     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1e6 + 5;   int arr[MAX_N];   int vis[MAX_N];   void solve() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &arr[i]);       vis[i] = 0;     }     vector<int> stk;     for (int i = 1; true; i = i - arr[i]) {       if (vis[i]) {         vector<int> ans;         for (int j = stk.size() - 1; j >= 0; j--) {           ans.push_back(stk[j]);           if (stk[j] == i) break;         }         printf( %d n , (int)ans.size());         for (int u : ans) {           printf( %d  , u);         }         printf(  n );         return;       } else {         vis[i] = 1;         stk.push_back(i);       }     }   }   int main() {     int testc;     scanf( %d , &testc);     for (int i = 0; i < testc; i++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     long long n;     cin >> n;     set<long long> st;     for (long long i = 1; i * i <= n; i++) {       if (n % i == 0) {         long long a = n / gcd(n, i);         st.insert(((a * (a - 1)) / 2) * (n / a) + a);         long long m = (n / i);         long long b = n / gcd(n, m);         st.insert(((b * (b - 1)) / 2) * (n / b) + b);       }     }     for (auto e : st) cout << e <<    ;     return 0;   }


#include <bits/stdc++.h>   int mat[500][500];   int N, K;   int main() {     scanf( %d%d , &N, &K);     int Cnt = 1;     int sum = 0;     for (int i = 0; i < N; i++) {       for (int j = 0; j < K - 1; j++) {         mat[i][j] = Cnt++;       }     }     for (int i = 0; i < N; i++) {       for (int j = K - 1; j < N; j++) {         mat[i][j] = Cnt++;       }     }     for (int i = 0; i < N; i++) {       sum += mat[i][K - 1];     }     printf( %d n , sum);     for (int i = 0; i < N; i++) {       for (int j = 0; j < N; j++) {         printf( %d  , mat[i][j]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   bool visited[2][maxn];   int d[2][maxn];   string s[2];   int main() {     int n, k;     cin >> n >> k;     cin >> s[0] >> s[1];     int dx[3] = {0, 0, 1};     int dy[3] = {1, -1, k};     queue<pair<bool, int>> q;     q.push(make_pair(0, 0));     visited[0][0] = 1;     while (q.size()) {       pair<bool, int> k = q.front();       q.pop();       bool x = k.first;       int y = k.second;       for (int i = 0; i < 3; i++) {         bool xx = x ^ dx[i];         int yy = y + dy[i];         if (yy >= n) {           cout <<  YES  << endl;           exit(0);         }         if (yy >= 0 && s[xx][yy] ==  -  && !visited[xx][yy] && yy > d[x][y]) {           q.push(make_pair(xx, yy));           visited[xx][yy] = 1;           d[xx][yy] = d[x][y] + 1;         }       }     }     cout <<  NO  << endl;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   unordered_set<int> dict;   int main() {     long long a, b, x;     cin >> x >> a >> b;     if (a % x != 0) {       a += x - (a % x + x) % x;     }     if (a > b) {       cout << 0 << endl;     } else {       cout << (b - a + x) / x << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int a, b, n;     cin >> n >> a >> b;     vector<int> A(n);     for (int &x : A) cin >> x;     sort(A.begin(), A.end());     if (A[b] - A[b - 1] == 0) {       cout <<  0 n ;       return;     }     cout << A[b] - A[b - 1] <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     solve();   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     register int x = 0, t = 1;     register char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) t = -1, ch = getchar();     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch - 48, ch = getchar();     return x * t;   }   int n, m, top, first[301000], dep[301000];   struct mona {     int nxt, en;   } s[301000 << 1];   inline void Insert(int x, int y) {     s[++top] = (mona){first[x], y}, first[x] = top;   }   inline void Dfs(int k, int fa) {     dep[k] = dep[fa] + 1;     for (register int i = first[k]; i; i = s[i].nxt) {       int en = s[i].en;       if (en == fa) continue;       Dfs(en, k);     }     return;   }   int cnt, rt[301000], Min[301000], ls[301000], rs[301000];   pair<long long, int> val[301000];   long long lz[301000], ans;   inline int New(pair<long long, int> x) {     int t = ++cnt;     val[t] = x, Min[t] = 1;     return t;   }   inline void Pushlz(int x, long long w) { val[x].first += w, lz[x] += w; }   inline void Pushdown(int x) {     if (!lz[x]) return;     if (ls[x]) Pushlz(ls[x], lz[x]);     if (rs[x]) Pushlz(rs[x], lz[x]);     lz[x] = 0;   }   inline int Merge(int u, int v) {     if (!u || !v) return u | v;     int t;     if (val[u] < val[v])       Pushdown(u), rs[u] = Merge(rs[u], v), t = u;     else       Pushdown(v), rs[v] = Merge(u, rs[v]), t = v;     if (Min[ls[t]] < Min[rs[t]]) swap(ls[t], rs[t]);     Min[t] = Min[rs[t]] + 1;     return t;   }   inline void Dfs2(int k, int fa) {     for (register int i = first[k]; i; i = s[i].nxt) {       int en = s[i].en;       if (en == fa) continue;       Dfs2(en, k), rt[k] = Merge(rt[k], rt[en]);     }     while (rt[k] && val[rt[k]].second >= dep[k])       rt[k] = Merge(ls[rt[k]], rs[rt[k]]);     if (!rt[k] && k != 1) puts( -1 ), exit(0);     ans += val[rt[k]].first, Pushlz(rt[k], -val[rt[k]].first);   }   int main() {     n = read(), m = read();     for (register int i = 1; i < n; ++i) {       int x = read(), y = read();       Insert(x, y), Insert(y, x);     }     Dfs(1, 0);     for (register int i = 1; i <= m; ++i) {       int x = read(), y = read();       long long w = read();       if (dep[x] < dep[y]) swap(x, y);       rt[x] = Merge(rt[x], New(make_pair(w, dep[y])));     }     Dfs2(1, 0), printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x;     while (cin >> n) {       x = n - 10;       if (x <= 0 || x > 11)         cout << 0 << endl;       else if (x == 10)         cout << 15 << endl;       else         cout << 4 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, u, r;   int a[35];   int b[35];   int k[35];   int p[35];   int op[35];   int tmpa[35];   int tmmmma[35];   long long dfs(int index, const int ta[]) {     if (index == u) {       long long res = 0;       for (int i = (0); i < ((n)); ++i) res += (long long)ta[i] * k[i];       return res;     }     int tta[35];     long long res = -(((long long)1) << 62);     if (index == 0 || op[index - 1] != 0) {       op[index] = 0;       for (int i = (0); i < ((n)); ++i) tta[i] = ta[i] ^ b[i];       res = max(res, dfs(index + 1, tta));     }     op[index] = 1;     for (int i = (0); i < ((n)); ++i) tta[i] = ta[p[i]] + r;     res = max(res, dfs(index + 1, tta));     if ((u - index) % 2 == 0) {       long long tmp = 0;       for (int i = (0); i < ((n)); ++i) tmp += (long long)ta[i] * k[i];       res = max(res, tmp);     }     return res;   }   int main(void) {     cin >> n >> u >> r;     for (int i = (0); i < ((n)); ++i) cin >> a[i];     for (int i = (0); i < ((n)); ++i) cin >> b[i];     for (int i = (0); i < ((n)); ++i) cin >> k[i];     for (int i = (0); i < ((n)); ++i) cin >> p[i];     for (int i = (0); i < ((n)); ++i) --p[i];     cout << dfs(0, a) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, sx, sy, x, y;     cin >> n >> sx >> sy;     vector<pair<long long int, long long int> > v;     v.push_back({sx, sy + 1});     v.push_back({sx, sy - 1});     v.push_back({sx + 1, sy});     v.push_back({sx - 1, sy});     vector<long long int> answer(4, 0);     for (long long int i = 1; i <= n; i++) {       cin >> x >> y;       long long int mnx = min(sx, x);       long long int mxx = max(sx, x);       long long int mny = min(sy, y);       long long int mxy = max(sy, y);       for (int j = 0; j < 4; j++) {         if (v[j].first >= mnx && v[j].first <= mxx && v[j].second >= mny &&             v[j].second <= mxy) {           answer[j]++;         }       }     }     long long int ans = 0;     for (int i = 0; i < 4; i++) ans = max(ans, answer[i]);     cout << ans << endl;     for (int i = 0; i < 4; i++) {       if (answer[i] == ans && v[i].first <= 1e9 && v[i].second <= 1e9 &&           v[i].first >= 0 && v[i].second >= 0) {         cout << v[i].first <<     << v[i].second << endl;         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long sum = 1;       long long sum1 = 0;       long long sum2 = 0;       long long cnt1 = 0;       long long cnt2 = 0;       long long res = 0;       long long flag = 0;       long long n;       cin >> n;       long long bm = n;       string s;       string su;       while (n--) {         cin >> s;         su += s;       }       long long len = su.length();       sort(su.begin(), su.end());       for (long long i = 0; i < len - 1; i++) {         if (su[i] == su[i + 1]) {           sum += 1;         } else {           if (sum % bm == 0) {             sum = 1;           } else {             cout <<  NO  << endl;             ;             flag = 1;             break;           }         }       }       if (sum % bm != 0 && flag == 0) {         cout <<  NO  << endl;         ;       } else if (flag == 0) {         cout <<  YES  << endl;         ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long double eps = (long double)1e-9;   const long double PI = (long double)acos(-1.0);   const int inf = 1e9 + 5;   const long long linf = 1e18L + 5;   const int mod = 1e9 + 7;   void solve() {     int n, q, r, c;     cin >> n >> q;     unordered_set<int> s[3];     set<pair<int, int> > p;     pair<int, int> pr;     for (int i = 0; i < q; ++i) {       cin >> r >> c;       if (s[r].count(c)) {         s[r].erase(c);         for (int j : {c - 1, c, c + 1}) {           if (j < 1 || j > n) continue;           if (r == 1)             pr = {c, j};           else             pr = {j, c};           auto it = p.find(pr);           if (it != p.end()) p.erase(it);         }       } else {         s[r].insert(c);         for (int j : {c - 1, c, c + 1}) {           if (j < 1 || j > n) continue;           if (r == 1)             pr = {c, j};           else             pr = {j, c};           if (s[3 - r].count(j)) p.insert(pr);         }       }       cout << ((int)(p).size() ?  no  :  yes ) <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int test = 1;     while (test--) {       solve();       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 260;   int m, n, mx[N][10], g[N][26], sl[N], L[N];   char a[N][N];   int kq;   unsigned long long o[N], A[N], B[N], pw[N], P[N];   unsigned long long get(int l, int r) { return A[r] - A[l - 1] * pw[r - l + 1]; }   unsigned long long Get(int l, int r) { return B[l] - B[r + 1] * pw[r - l + 1]; }   unsigned long long GET(int l, int r) {     int tg = L[r - l + 1];     return max(mx[l][tg], mx[r - (1 << tg) + 1][tg]);   }   int main() {     ios_base::sync_with_stdio(0);     cin >> m >> n;     pw[0] = 1;     P[0] = 1;     for (int i = 1, _c = 250; i <= _c; ++i) {       pw[i] = pw[i - 1] * 257;       L[i] = log2(i);     }     for (int i = 1, _c = 25; i <= _c; ++i) P[i] = P[i - 1] * 267;     for (int i = 1, _c = m; i <= _c; ++i)       for (int j = 1, _c = n; j <= _c; ++j) cin >> a[i][j];     for (int l = 1, _c = n; l <= _c; ++l)       for (int r = l, _c = n; r <= _c; ++r) {         if (l == r) {           memset(o, 0, sizeof(o));           memset(g, 0, sizeof(g));           memset(sl, 0, sizeof(sl));         }         for (int i = 1, _c = m; i <= _c; ++i) {           int x = a[i][r] -  a ;           g[i][x]++;           if (g[i][x] % 2)             sl[i]++;           else             sl[i]--;           if (sl[i] > 1)             mx[i][0] = 1;           else             mx[i][0] = 0;           o[i] = o[i] + P[x] * x;         }         for (int j = 1, _c = log2(m); j <= _c; ++j)           for (int i = 1, _c = m; i <= _c; ++i)             mx[i][j] = max(mx[i][j - 1], mx[i + (1 << (j - 1))][j - 1]);         for (int i = 1, _c = m; i <= _c; ++i) A[i] = A[i - 1] * 257 + o[i];         for (int i = m, _c = 1; i >= _c; --i) B[i] = B[i + 1] * 257 + o[i];         for (int i = 1, _c = m; i <= _c; ++i)           if (!mx[i][0]) {             int l = i, r = min(m, i + (i - 1)), tg = i;             while (l <= r) {               int mid = (l + r) / 2;               if (get(i, mid) == Get(2 * i - mid, i) && !GET(i, mid)) {                 tg = mid;                 l = mid + 1;               } else                 r = mid - 1;             }             kq += (tg - i + 1);           }         for (int i = 2, _c = m; i <= _c; ++i)           if (!mx[i][0] && !mx[i - 1][0] && o[i] == o[i - 1]) {             int l = i, r = min(m, i + (i - 2)), tg = i;             while (l <= r) {               int mid = (l + r) / 2;               if (get(i, mid) == Get(2 * i - 1 - mid, i - 1) && !GET(i, mid)) {                 tg = mid;                 l = mid + 1;               } else                 r = mid - 1;             }             kq += (tg - i + 1);           }       }     cout << kq;   }


#include<bits/stdc++.h>   using namespace std;      //MACROS   #define ll long long   #define f(i,a,b) for(i=a;i<b;i++)   #define MOD 1000000007   #define pb push_back   #define mp make_pair   #define INF (int)1e9   #define deb(x) cout <<  >  << #x <<   :   << x << endl;   #define cjam(t,x) cout <<  Case #  << t <<   :   << x << endl;   #define newl cout<<endl;   #define print(x) for(auto y:x) cout<<y<<   ; newl;   //MACROS      // DECIMAL TO BINARY CONVERSION   string toBinary(ll n)   {       string r;       while(n!=0) {r=(n%2==0 ? 0 : 1 )+r; n/=2;}       return r;   }      // SEGMENT TREE   struct segtree   {       int size;       vector<ll> sums;          void init(int n)       {           size = 1;           while(size<n) size*=2;           sums.assign(2*size, 0LL);          }          void set(int i, int v, int x, int lx, int rx)       {           if(rx-lx == 1) sums[x] = v;              else           {               int m = (lx+rx)/2;                  if(i<m)               {                   set(i, v, 2*x+1, lx, m);               }               else               {                   set(i, v, 2*x+2, m, rx);               }               sums[x] = sums[2*x+1] + sums[2*x+2];           }                  }          void set(int i, int v)       {           set(i ,v, 0, 0, size);       }             ll sum(ll l, ll r, ll x, ll lx, ll rx)       {           if(l>=rx || r<=lx) return(0);           if(l<=lx && r>=rx) return(sums[x]);              ll m = (lx+rx)/2;              ll s1 = sum(l, r, 2*x+1, lx, m);           ll s2 = sum(l, r, 2*x+2, m, rx);              return(s1+s2);       }          ll sum(ll l, ll r)       {           return(sum(l, r, 0, 0, size));        }          };         //GRAPH   struct graph   {       bool vis[100000];       vector<ll> adj[100000];          void edge(int a, int b)       {           adj[a].push_back(b);           adj[b].push_back(a);       }          void dfs(ll s)       {           int i;           vis[s] = 1;           cout<<s<<   ;           f(i,0,adj[s].size())           {               if(vis[adj[s][i]] == 0)                   dfs(adj[s][i]);           }       }   };         //BINARY SEARCH   ll bsearch(ll arr[], ll n, ll x)   {       ll l=0, h=n-1;       while(l<=h)       {           ll m = (l+h)/2;           if(arr[m]==x)           {               return(m);           }           else if(arr[m]<x)           {               l = m+1;           }           else           {               h = m-1;           }       }       return(-1);   }      //nCr in Constant Time   ll const mod = 1e9+7;   ll power(ll a, ll b)   {       ll res = 1;       while(b)       {           if(b&1)               res = (res * a) % mod;           a = (a * a) % mod;           b /= 2;       }       return res;   }      ll inverse(ll x){       return power(x,mod-2);   }      ll const N = 1e6+55;   ll fact[N], ifact[N];      void precompute()   {       fact[0] = 1;       for(ll i=1; i<N; i++)           fact[i] = (fact[i-1] * i) % mod;              ifact[N-1] = inverse(fact[N-1]);       for(ll i=N-2; i>=0; i--)           ifact[i] = ((i+1) * ifact[i+1]) % mod;   }      ll ncr(ll n, ll r)   {       if(r<0 or r>n) return 0;       if(n == r) return 1;          ll res = (fact[n] * ifact[n-r]) % mod;       res = (res * ifact[r]) % mod;       return res;   }      int sieve[100001];      void prime()   {       int i,j;       std::fill_n(sieve, 100000, 1);       for(i=2;i*i<=100000;i++)       {           if(sieve[i])           {               for(j=i*i;j<=100000;j+=i)               {                   sieve[j] = 0;               }           }       }   }         //////////////////////////   ///////DRIVER CODE////////   //////////////////////////      int main()   {       #ifndef ONLINE_JUDGE       freopen( input.txt , r , stdin);       freopen( output.txt , w , stdout);       #endif          ll x,y,z,n,m,q,tt,t,i,j,k;          cin>>tt;       t=tt;       while(tt--)       {           cin>>n;           std::vector<ll> v;           ll f = 1;           f(i,0,2*n)           {               cin>>x;               if(x&1) f = 0;               v.pb(x);           }                         set<ll> s(v.begin(), v.end());              if(f==0)           {               cout<< NO <<endl;               continue;           }                 if(s.size()!=n)           {               cout<< NO <<endl;               continue;           }              ll sum = 0;              f = 1;              auto it = s.rbegin();              f(i,0,n)           {               x = *(it++);               y = (x-sum)/(2*(n-i));               z = (x-sum)%(2*(n-i));               sum+=2*y;                  if(y<=0 or z>0)               {                   f = 0;                   break;               }              }              if(f) cout<< YES <<endl;           else cout<< NO <<endl;                              }      }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007, inf = 1000000000;   const int N = 100010;   inline int read() {     char ch;     while (!isdigit(ch = getchar()))       ;     int x = ch -  0 ;     while (isdigit(ch = getchar())) x = (x << 1) + (x << 3) + ch -  0 ;     return x;   }   int n, cnt;   int a[N], last[N];   long long f[N][2];   struct edge {     int to, next;   } e[N << 1];   void insert(int u, int v) {     e[++cnt].to = v;     e[cnt].next = last[u];     last[u] = cnt;     e[++cnt].to = u;     e[cnt].next = last[v];     last[v] = cnt;   }   void dfs(int x, int fa) {     long long t1, t2;     if (a[x] == 1) f[x][1] = 1;     f[x][0] = f[x][1] ^ 1;     for (int i = last[x]; i; i = e[i].next)       if (e[i].to != fa) {         int y = e[i].to;         dfs(y, x);         t1 = f[x][0] * (f[y][0] + f[y][1]);         t2 = (f[x][1] * (f[y][0] + f[y][1]) + f[x][0] * f[y][1]);         f[x][0] = t1 % mod;         f[x][1] = t2 % mod;       }   }   int main() {     n = read();     for (int i = 1; i < n; i++) insert(read(), i);     for (int i = 0; i < n; i++) a[i] = read();     dfs(0, 0);     cout << f[0][1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     string str;     cin >> str;     vector<int> arr;     for (int i = 0; i < str.size(); i++) {       if (str[i] ==  . ) arr.push_back(i + 1);     }     for (int i = 0; i + 1 < arr.size(); i++) {       if (arr[i] + k < arr[i + 1]) {         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[200001];   int main() {     long long t, m = 0, i, n, k, ans;     ;     scanf( %lld%lld , &n, &k);     for (i = 0; i < n; i++) scanf( %lld , &a[i]);     sort(a, a + n);     for (i = (n + 1) / 2; i < n; i++) {       t = m;       m += (a[i] - a[i - 1]) * (i - (n - 1) / 2);       if (m > k) {         ans = a[i - 1] + (k - t) / (i - (n - 1) / 2);         break;       }     }     if (i == n) ans = (k - m) / (n - (n - 1) / 2) + a[n - 1];     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int n, a[4000005], t[4000005];   long long ans, now;   int k;   template <class T>   inline T Max(T a, T b) {     return a > b ? a : b;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , a + i);     int fu = 0, zh = 0;     for (int i = 1; i <= n; ++i) {       int qwq = a[i] - i;       now += qwq < 0 ? -qwq : qwq;       if (i == n) continue;       if (qwq <= 0)         ++fu;       else         ++t[a[i] - i], ++zh;     }     ans = now;     int las = n;     for (int i = 1; i < n; ++i) {       now += -zh + fu - (n - a[las]) + a[las] - 1;       fu += t[i];       zh -= t[i];       if (a[las] != 1) --fu, ++zh;       ++t[i + a[las] - 1];       if (now < ans) ans = now, k = i;       --las;     }     printf( %lld %d n , ans, k);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void dbvar() { cerr <<  ]  << endl; }   template <class H, class... T>   void dbvar(H h, T... t) {     cerr << to_string(h);     if (sizeof...(t)) cerr <<  ,  ;     dbvar(t...);   }   const int INF = (int)(1e9);   const long long int INFL = (long long int)(1e18);   const long double pi = acos(-1.0);   const int dx[4] = {-1, 0, 1, 0};   const int dy[4] = {0, 1, 0, -1};   long long int power(long long int n, long long int m) {     if (m == 0) return 1;     long long int val = power(n, m / 2);     if (m % 2 == 0)       return (val * val);     else       return ((val * val) * n);   }   long long int powermod(long long int n, long long int m, long long int _MOD) {     if (m == 0) return 1;     long long int val = powermod(n, m / 2, _MOD);     val %= _MOD;     if (m % 2 == 0)       return (val * val) % _MOD;     else       return (((val * val) % _MOD) * n) % _MOD;   }   const int mxN = 2e5 + 100;   vector<int> tree[mxN];   int depth[mxN], subtree[mxN], ans[mxN];   void dfs(int v, int p) {     depth[v] = depth[p] + 1;     subtree[v] = 1;     for (auto x : tree[v]) {       if (x != p) {         dfs(x, v);         subtree[v] += subtree[x];       }     }     ans[v] = subtree[v] - depth[v];   }   void solve() {     int n, k;     cin >> n >> k;     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       tree[x].push_back(y);       tree[y].push_back(x);     }     depth[0] = 0;     dfs(1, 0);     sort(ans + 1, ans + n + 1, greater<int>());     long long int res = 0;     for (int i = 1; i <= n - k; i++) res += ans[i];     cout << res <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     int t = 1;     for (int i = 1; i <= t; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, test, len;     string s;     cin >> test;     while (test--) {       cin >> s;       len = s.length();       if (s[len - 2] ==  p  && s[len - 1] ==  o ) {         cout <<  FILIPINO  << endl;       } else if (s[len - 4] ==  d  && s[len - 3] ==  e  && s[len - 2] ==  s  &&                  s[len - 1] ==  u ) {         cout <<  JAPANESE  << endl;       } else if (s[len - 4] ==  m  && s[len - 3] ==  a  && s[len - 2] ==  s  &&                  s[len - 1] ==  u ) {         cout <<  JAPANESE  << endl;       } else {         cout <<  KOREAN  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b;     cin >> n >> a >> b;     string s;     cin >> s;     for (int cnt1 = 0; cnt1 <= n / a; ++cnt1) {       for (int cnt2 = 0; cnt2 <= n / b; ++cnt2)         if (a * cnt1 + b * cnt2 == n) {           cout << cnt1 + cnt2 << endl;           for (int i = 0; i < cnt1; ++i) {             for (int j = 0; j < a; ++j) cout << s[j];             cout << endl;             s.erase(0, a);           }           for (int i = 0; i < cnt2; ++i) {             for (int j = 0; j < b; ++j) cout << s[j];             cout << endl;             s.erase(0, b);           }           return 0;         }     }     cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int n;   int a[N];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int ans;     for (int i = 30; i >= 0; i--) {       int flag = 0;       for (int j = 0; j < n; j++) {         if ((a[j] >> i) & 1) {           flag++;           ans = j;         }       }       if (flag == 1) {         break;       }     }     cout << a[ans] <<    ;     for (int i = 0; i < n; i++) {       if (i != ans) {         cout << a[i] <<    ;       }     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> A(n), B(n);     vector<int> Ai(n - 1), Bi(n - 1);     int t = 0;     for (int i = 0; i < n; ++i) {       cin >> A[i];       if (A[i] != 0) {         Ai[t] = A[i];         t++;       }     }     t = 0;     for (int i = 0; i < n; ++i) {       cin >> B[i];       if (B[i] != 0) {         Bi[t] = B[i];         t++;       }     }     int i0 = 0;     for (int i = 0; i < n - 1; ++i) {       if (Bi[i] == Ai[0]) {         i0 = i;         break;       }     }     for (int i = 0; i < n - 1; ++i) {       if (Bi[(i + i0) % (n - 1)] != Ai[i]) {         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};   bool ckmin(int& a, int b) { return b < a ? a = b, true : false; }   bool ckmax(int& a, int b) { return b > a ? a = b, true : false; }   const long long linf = 4000000000000000000LL;   const long long inf = 1000000007;   const long double pi = 3.1415926535;   void pv(vector<int> a) {     for (auto& x : a) cout << x <<    ;     cout <<   n ;   }   void pv(vector<long long> a) {     for (auto& x : a) cout << x <<    ;     cout <<   n ;   }   void pv(vector<vector<int> > a) {     for (int i = (0); i < (int(a.size())); ++i) {       cout << i <<   n ;       pv(a[i]);       cout <<   n ;     }   }   void pv(vector<vector<long long> > a) {     for (int i = (0); i < (int(a.size())); ++i) {       cout << i <<   n ;       pv(a[i]);     }     cout <<   n ;   }   void pv(vector<string> a) {     for (auto& x : a) cout << x <<   n ;     cout <<   n ;   }   void setIO(string second) {     ios_base::sync_with_stdio(0);     cin.tie(0);     if (int(second.size())) {       freopen((second +  .in ).c_str(),  r , stdin);       if (second !=  test1 ) freopen((second +  .out ).c_str(),  w , stdout);     }   }   int main() {     setIO(  );     int n;     cin >> n;     vector<long long> a(n);     for (auto& x : a) cin >> x;     vector<int> count(60);     for (int i = (0); i < (n); ++i) {       int ans = 0;       while (!(a[i] & 1)) {         ans++;         a[i] >>= 1;       }       a[i] <<= ans;       count[ans]++;     }     int index = max_element(count.begin(), count.end()) - count.begin();     cout << n - count[index] <<   n ;     if (index == 0) {       for (int i = (0); i < (n); ++i) {         if (a[i] & 1)           ;         else           cout << a[i] <<    ;       }       return 0;     }     for (int i = (0); i < (n); ++i) {       if ((((a[i] >> index) & 1)) && !((a[i] >> index - 1) & 1)) {       } else {         cout << a[i] <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   int main() {     scanf( %lld %lld , &n, &k);     vector<long long> prime;     for (int i = 2; i <= n; ++i) {       if (!prime.size()) {         prime.push_back(i);         continue;       }       bool isPrime = true;       for (int j = 0; j < prime.size(); ++j) {         long long now = prime[j];         if (now * now > i) break;         if (!(i % now)) {           isPrime = false;           break;         }       }       if (isPrime) prime.push_back(i);     }     vector<int> ans;     for (int i = 0; i < prime.size(); ++i) {       while (!(n % prime[i]) && k > 1 && n > 1) {         ans.push_back(prime[i]);         --k;         n /= prime[i];       }     }     if (n == 1) {       puts( -1 );       return 0;     }     ans.push_back(n);     --k;     for (int i = 0; i < ans.size(); ++i)       printf( %d%c , ans[i],    n [i + 1 == ans.size()]);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 85 - 69;   long long int a[maxn], su[maxn], dp[maxn];   int n;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 1; i < n; i++) cin >> a[i];     for (int i = n - 1; i > 0; i--) {       su[i] = su[i + 1] + a[i] - (a[i] & 1);       if (a[i] == 1) su[i] = 0;     }     dp[0] = 0;     long long int sum = 0, ans = 0;     for (int i = 1; i < n; i++) {       sum += a[i] - (a[i] & 1);       if (a[i] == 1) sum = 0;       dp[i] = max(dp[i - 1] + a[i] - (a[i] % 2 == 0), sum);       ans = max(ans, dp[i] + su[i + 1]);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF64 = 1e18;   clock_t time_p = clock();   void time() {     time_p = clock() - time_p;     cerr <<  Time Taken :   << (float)(time_p) / CLOCKS_PER_SEC <<   n ;   }   void doc() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   int main() {     fast();     string s;     cin >> s;     long long i, j;     long long n = s.length();     long long m = 0, idx = -1, x = 0, y = 0;     for (i = 0; i < n; i++) {       if (s[i] ==  ( ) {         x++;         y = 0;         for (j = i + 1; j < n; j++) {           if (s[j] ==  ) ) y++;         }         if (y >= x) {           if (x > m) {             m = x;             idx = i;           }         }       }     }     vector<long long> ans;     for (i = 0; i <= idx; i++)       if (s[i] ==  ( ) ans.emplace_back(i + 1);     for (i = n - 1, j = 0; i >= 0 and j < m; i--)       if (s[i] ==  ) ) {         ans.emplace_back(i + 1);         j++;       }     sort(ans.begin(), ans.end());     if (ans.size() == 0) {       cout <<  0 ;       exit(0);     }     cout <<  1  << endl << ans.size() << endl;     for (auto i : ans) cout << i <<    ;     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n = 0, m = 1, i = 0, j = 0, k = 0, x = 0;     int area[51][51] = {0};     cin >> n;     for (i = 0; i < n; i++)       for (x = 0; x < n; x++) cin >> area[i][x];     for (i = 0; i < n; i++)       for (x = 0; x < n; x++)         if (area[i][x] != 1) {           m = 1;           for (j = 0; j < n; j++) {             if (j == i) continue;             for (k = 0; k < n; k++) {               if (k == x) continue;               if (area[i][x] == area[j][x] + area[i][k]) {                 m = 0;                 break;               }             }             if (m == 0) break;           }           if (m == 1) {             cout <<  NO  << endl;             return 0;           }         }     cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 205;   const long long modulo = 1000000007;   struct point {     long long x, y;   };   point operator-(point A, point B) {     point C;     C.x = A.x - B.x;     C.y = A.y - B.y;     return C;   }   bool operator==(point A, point B) { return (A.x == B.x && A.y == B.y); }   long long cross(point A, point B) { return (A.x * B.y - A.y * B.x); }   long long dot(point A, point B) { return (A.x * B.x + A.y * B.y); }   struct Line {     long long A, B, C;     Line(point P, point R) {       A = R.y - P.y;       B = P.x - R.x;       C = (P.y * R.x) - (P.x * R.y);     }   };   long long sgn(long long x) {     if (x > 0) return 1;     if (x < 0) return -1;     if (x == 0) return 0;   }   long long f(Line L, point P) { return sgn(L.A * P.x + L.B * P.y + L.C); }   bool OnSegment(point A, point B, point X) {     if (f(Line(A, B), X) != 0) return false;     if (dot(A - X, B - X) < 0)       return true;     else       return false;   }   bool intersect(point A, point B, point C, point D) {     if (A == C || A == D || B == C || B == D) return false;     if (f(Line(A, B), C) * f(Line(A, B), D) >= 0) return false;     if (f(Line(C, D), A) * f(Line(C, D), B) >= 0) return false;     return true;   }   point a[MAXN];   long long dp[MAXN][MAXN];   int main() {     int N;     cin >> N;     for (int i = 1; i <= N; i++) {       cin >> a[i].x >> a[i].y;     }     a[N + 1] = a[1];     long long Area = 0;     for (int i = 1; i <= N; i++) {       Area += cross(a[i], a[i + 1]);     }     Area = abs(Area);     for (int d = 1; d < N - 1; d++) {       for (int l = 1; l + d <= N; l++) {         int r = l + d;         if (d == 1) {           dp[l][r] = 1;           continue;         } else           dp[l][r] = 0;         bool bad = false;         for (int i = 1; i <= N; i++) {           if (i != l && i != r && OnSegment(a[l], a[r], a[i])) bad = true;         }         if (bad) continue;         for (int i = 1; i <= N; i++) {           int next = i + 1;           if (next == N + 1) next = 1;           if (intersect(a[l], a[r], a[i], a[next])) bad = true;         }         if (bad) continue;         long long AreaX = 0, AreaY = 0;         for (int i = l; i <= r; i++) {           int next = i + 1;           if (next == r + 1) next = l;           AreaX += cross(a[i], a[next]);         }         int j = 1;         while (j <= N) {           int next;           if (j == l)             next = r;           else             next = j + 1;           if (next == N + 1) next = 1;           AreaY += cross(a[j], a[next]);           j = next;           if (j == 1) j = N + 1;         }         if (Area != abs(AreaX) + abs(AreaY)) continue;         for (int i = l + 1; i < r; i++) {           dp[l][r] += (dp[l][i] * dp[i][r]) % modulo;           dp[l][r] = dp[l][r] % modulo;         }       }     }     dp[1][N] = 0;     for (int i = 2; i < N; i++) {       dp[1][N] += (dp[1][i] * dp[i][N]) % modulo;       dp[1][N] = dp[1][N] % modulo;     }     cout << dp[1][N] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 50;   const int maxm = 1e6 + 50;   const double eps = 1e-10;   const int max_index = 62;   const int inf = 0x3f3f3f3f;   const int MOD = 1e9 + 7;   inline int read() {     char c = getchar();     while (!isdigit(c)) c = getchar();     int x = 0;     while (isdigit(c)) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x;   }   const int offset = 2000;   struct Point {     int x, y;     Point(int x = 0, int y = 0) : x(x), y(y) {}     bool operator<(const Point &rhs) const {       if (x == rhs.x) return y < rhs.y;       return x < rhs.x;     }   } P[205];   std::vector<int> G[maxm];   int n, m;   int dis[maxm], vis[maxm];   int get(int x, int y) { return x * m + y; }   int ans = 0;   void dfs(int u) {     vis[u] = 1;     int res = 0;     for (int i = 0; i < G[u].size(); i++) {       int v = G[u][i];       if (vis[v]) {         puts( Poor Inna! );         exit(0);       }       if (!dis[v]) dfs(v);       res = max(res, dis[v]);     }     dis[u] = res + 1;     vis[u] = 0;   }   int dir[4][2] = {0, -1, -1, 0, 0, 1, 0, -1};   char mp[1005][1005];   bool judge(char x, char y) {     bool ok = 0;     ok |= (x ==  D  && y ==  I );     ok |= (x ==  I  && y ==  M );     ok |= (x ==  M  && y ==  A );     ok |= (x ==  A  && y ==  D );     return ok;   }   int main() {     n = read(), m = read();     for (int i = 0; i < n; i++) scanf( %s , mp[i]);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         int u = get(i, j);         for (int k = 0; k < 2; k++) {           int dx = i + dir[k][0], dy = j + dir[k][1];           if (dx < 0 || dy < 0) continue;           int v = get(dx, dy);           if (judge(mp[dx][dy], mp[i][j])) {             G[v].push_back(u);           } else if (judge(mp[i][j], mp[dx][dy])) {             G[u].push_back(v);           }         }       }     }     for (int i = 0; i < m * n; i++) {       int x = i / m, y = i % m;       if (mp[x][y] !=  D ) continue;       dfs(i);       ans = max(ans, dis[i]);     }     if (ans < 4)       puts( Poor Dima! );     else       printf( %d n , ans / 4);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   int add(int a, int b) {     a += b;     return a >= mod ? a - mod : a;   }   const int MN = 1000011;   int f[MN][2], n;   inline void Main() {     f[0][0] = f[0][1] = 1;     scanf( %d , &n);     for (register int i = (1), _c = (n); i <= _c; i++)       for (register int j = (0), _c = (1); j <= _c; j++)         if (f[i - 1][j]) {           (f[i][j] = add(f[i][j], f[i - 1][j]));           if (j != i % 2) (f[i][i % 2] = add(f[i][i % 2], f[i - 1][j]));         }     register int ans = add(add(f[n][0], f[n][1]), mod - 2);     printf( %d n , ans);   }   int main() {     Main();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, s, ans, tot, tot1, tot2;   int siz[200010], du[200010], dep[200010], fa[200010][18];   int q[200010], head[200010], head1[200010], head2[200010], power[18];   bool v[200010];   long long dis[200010];   struct Map {     int r, len, next;   } line[600010];   struct Map_sp {     int r, next;   } line1[600010], line2[600010];   void add(int x, int y, int len) {     tot++;     line[tot].r = y;     line[tot].len = len;     line[tot].next = head[x];     head[x] = tot;   }   void add1(int x, int y) {     tot1++;     line1[tot1].r = y;     line1[tot1].next = head1[x];     head1[x] = tot1;   }   void add2(int x, int y) {     tot2++;     line2[tot2].r = y;     line2[tot2].next = head2[x];     head2[x] = tot2;   }   void spfa() {     for (int i = 1; i <= n; i++) dis[i] = 1e18;     int hd = 0, tl = 0;     q[tl++] = s, dis[s] = 0, v[s] = true;     while (hd != tl) {       int x = q[hd];       for (int i = head[x]; i; i = line[i].next) {         int rx = line[i].r, len = line[i].len;         if (dis[x] + len < dis[rx]) {           dis[rx] = dis[x] + len;           if (!v[rx]) {             v[rx] = true;             q[tl++] = rx;             if (tl == 200010) tl = 0;           }         }       }       v[x] = false;       hd++;       if (hd == 200010) hd = 0;     }   }   void build(int x) {     v[x] = true;     for (int i = head[x]; i; i = line[i].next) {       int rx = line[i].r;       if (dis[x] + line[i].len == dis[rx]) {         add1(x, rx), add2(rx, x);         du[rx]++;         if (!v[rx]) build(rx);       }     }   }   void dfs(int x) {     siz[x] = 1;     for (int i = head[x]; i; i = line[i].next) {       int rx = line[i].r;       dfs(rx);       siz[x] += siz[rx];     }     if (x != s) ans = max(ans, siz[x]);   }   int lca(int x, int y) {     if (dep[x] < dep[y]) swap(x, y);     int tmp = dep[x] - dep[y];     for (int i = 0; power[i] <= tmp; i++)       if (tmp & power[i]) x = fa[x][i];     if (x == y) return x;     for (int i = 17; i >= 0; i--)       if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];     return fa[x][0];   }   void topo() {     int hd = 1, tl = 0;     q[++tl] = s, dep[s] = 1;     while (hd <= tl) {       int x = q[hd];       for (int i = head1[x]; i; i = line1[i].next) {         int rx = line1[i].r;         du[rx]--;         if (!du[rx]) {           q[++tl] = rx;           int LCA = 0;           for (int j = head2[rx]; j; j = line2[j].next)             if (!LCA)               LCA = line2[j].r;             else               LCA = lca(LCA, line2[j].r);           add(LCA, rx, 0);           fa[rx][0] = LCA;           dep[rx] = dep[LCA] + 1;           for (int j = 1; j <= 17; j++) fa[rx][j] = fa[fa[rx][j - 1]][j - 1];         }       }       hd++;     }   }   inline int read() {     int x = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) ch = getchar();     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x;   }   int main() {     power[0] = 1;     for (int i = 1; i <= 17; i++) power[i] = power[i - 1] << 1;     n = read(), m = read(), s = read();     for (int i = 1; i <= m; i++) {       int u = read(), v = read(), w = read();       add(u, v, w), add(v, u, w);     }     spfa();     build(s);     tot = 0;     memset(head, 0, sizeof(head));     topo();     dfs(s);     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int pri[200050];   int que[200050];   int ans[200050];   int l[200050];   int r[200050];   int main() {     int n;     while (scanf( %d , &n) != EOF) {       for (int i = 1; i <= n; i++) {         scanf( %d , &pri[i]);         ans[i] = 0;         l[i] = r[i] = 1;       }       int s = 1, e = 0;       for (int i = 1; i <= n; i++) {         while (s <= e && pri[que[e]] >= pri[i]) {           l[i] = i - que[e] + l[que[e]];           e--;         }         que[++e] = i;       }       s = 1, e = 0;       for (int i = n; i >= 1; i--) {         while (s <= e && pri[que[e]] >= pri[i]) {           r[i] = r[que[e]] + que[e] - i;           e--;         }         que[++e] = i;       }       for (int i = 1; i <= n; i++) {         ans[l[i]] = max(ans[l[i]], pri[i]);         ans[r[i]] = max(ans[r[i]], pri[i]);         ans[r[i] + l[i] - 1] = max(ans[r[i] + l[i] - 1], pri[i]);       }       for (int i = n - 1; i >= 1; i--) {         ans[i] = max(ans[i], ans[i + 1]);       }       for (int i = 1; i <= n; i++)         if (i == 1)           printf( %d , ans[i]);         else           printf(  %d , ans[i]);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 37;   long long int c[1037][1037];   int main() {     for (int i = 0; i < 1037; i++) {       c[i][0] = 1;       for (int j = 1; j < i + 1; j++) {         c[i][j] = c[i - 1][j - 1] + c[i - 1][j];       }     }     int n, k;     cin >> n >> k;     int pole[5] = {0, 0, 1, 2, 9};     long long int vys = 1;     for (int i = 2; i < k + 1; i++) {       vys += c[n][i] * pole[i];     }     cout << vys << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   using lim = numeric_limits<T>;   const int maxn = 2e5;   int table[maxn * 2 + 2];   int find(int i) {     if (table[i] == i)       return i;     else       return table[i] = find(table[i]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     for (int i = 0; i < 2 * maxn + 2; i++) table[i] = i;     int n, m, q;     cin >> n >> m >> q;     int ans = n + m - 1;     while (q--) {       int x, y;       cin >> x >> y;       x = find(x);       y = find(y + n);       if (x == y) continue;       ans--;       table[x] = y;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   struct trio {     int64_t first, second, trd;     friend ostream &operator<<(ostream &o, trio &a) {       o <<  (  << a.first <<  ,  << a.second <<  ,  << a.trd <<  ) ;       return o;     }   };   template <typename T>   inline T max() {     return numeric_limits<T>::max();   }   template <typename T>   inline T gcd(T a, T b) {     return b == 0 ? a : gcd(b, a % b);   }   template <typename T>   inline void get(T &&v) {     cin >> v;   }   template <typename T, typename... Args>   inline void get(T &&v, Args &&...args) {     cin >> v;     get(args...);   }   template <typename T>   inline void put(T &&v) {     cout << v <<   n ;   }   template <typename T, typename... Args>   inline void put(T &&v, Args &&...args) {     cout << v <<    ;     put(args...);   }   template <typename T>   inline void putc(T &&a, const string s =    ) {     {       for (auto &v : a) cout << v << s;     }     cout <<   n ;   }   ostream &operator<<(ostream &out, pair<int32_t, int32_t> &a) {     out <<  (  << a.first <<  ,  << a.second <<  ) ;     return out;   }   ostream &operator<<(ostream &out, pair<int64_t, int64_t> &a) {     out <<  (  << a.first <<  ,  << a.second <<  ) ;     return out;   }   vector<int32_t> primes;   inline void calc_primes(int32_t lmt) {     vector<char> s(lmt);     primes.push_back(2);     for (int32_t i = 3; i < lmt; i += 2) {       if (s[i]) continue;       primes.push_back(i);       for (int32_t j = i + (i << 1); j < lmt; j += (i << 1)) s[j] = 1;     }   }   inline vector<pair<int32_t, int32_t> > factorize(int32_t n) {     vector<pair<int32_t, int32_t> > a;     int32_t cnt = __builtin_ctzl(n);     a.push_back({2, cnt});     n >>= cnt;     for (auto &d : primes) {       cnt = 0;       while (n % d == 0) n /= d, cnt++;       a.push_back({d, cnt});       if (n == 1) break;     }     if (n != 1) a.push_back({n, 1});     return a;   }   int64_t mod = 1e9 + 9;   inline int64_t mmul(int64_t a, int64_t n) {     if (a < 0) a += mod;     if (n < 0) n += mod;     int64_t r = 0;     while (n) {       if (n & 1) r = (r + a) % mod;       a = (a + a) % mod;       n >>= 1;     }     return r;   }   inline int64_t mpow(int64_t a, int64_t n) {     if (a < 0) a += mod;     if (n < 0) n += mod;     int64_t r = 1;     while (n) {       if (n & 1) r = mmul(r, a);       a = mmul(a, a);       n >>= 1;     }     return r;   }   int main() {     {       ios_base::sync_with_stdio(false);       cin.tie(nullptr);       cout << setprecision(20);     };     int64_t n, a, b, k;     get(n, a, b, k);     int64_t inv_a = mpow(a, mod - 2);     int64_t aa = mpow(a, n);     int64_t bb = 1;     int64_t z = 0;     for (int64_t i = 0; i < k; ++i) {       char c;       cin >> c;       int64_t sgn = (c ==  +  ? 1 : -1);       z = (z + sgn * mmul(aa, bb)) % mod;       aa = mmul(aa, inv_a);       bb = mmul(bb, b);     }     int64_t q = mmul(bb, mpow(inv_a, k));     int64_t s = 0, t = (n + 1) / k;     if (q == 1)       s = t;     else       s = mmul((mod + 1 - mpow(q, t)), mpow(mod + 1 - q, mod - 2));     z = mmul(z, s);     if (z < 0) z += mod;     put(z);     return 0;   }