#include <bits/stdc++.h>   using namespace std;   const int maxn = 200;   int mn[maxn << 2], lazy[maxn << 2], gs[maxn << 2];   void push(int rt) {     if (lazy[rt] == 1000000000) return;     lazy[rt << 1] = lazy[rt << 1 | 1] = lazy[rt];     mn[rt << 1] = mn[rt << 1 | 1] = lazy[rt];     gs[rt << 1] = gs[rt << 1 | 1] = lazy[rt];     lazy[rt] = 1000000000;   }   void update(int l, int r, int rt, int ql, int qr, int v) {     if (ql <= l && qr >= r)       lazy[rt] = v, mn[rt] = gs[rt] = v;     else {       push(rt);       int mid = l + r >> 1;       if (ql <= mid) update(l, mid, rt << 1, ql, qr, v);       if (qr > mid) update(mid + 1, r, rt << 1 | 1, ql, qr, v);       mn[rt] = min(mn[rt << 1], mn[rt << 1 | 1]);     }   }   int query(int l, int r, int rt, int ql, int qr) {     if (ql <= l && qr >= r) return mn[rt];     push(rt);     int mid = l + r >> 1, ret = 1e9;     if (ql <= mid) ret = query(l, mid, rt << 1, ql, qr);     if (qr > mid) ret = min(ret, query(mid + 1, r, rt << 1 | 1, ql, qr));     return ret;   }   int Pv(int l, int r, int rt, int p) {     if (l == r) return gs[rt];     push(rt);     int mid = l + r >> 1;     if (p <= mid)       return Pv(l, mid, rt << 1, p);     else       return Pv(mid + 1, r, rt << 1 | 1, p);   }   int sum[maxn], a[maxn];   void build(int l, int r, int rt) {     lazy[rt] = 1000000000;     if (l == r)       mn[rt] = gs[rt] = sum[l];     else {       int mid = l + r >> 1;       build(l, mid, rt << 1);       build(mid + 1, r, rt << 1 | 1);       mn[rt] = min(mn[rt << 1], mn[rt << 1 | 1]);     }   }   int vis[maxn];   using pii = pair<int, int>;   pii her[maxn];   vector<int> ans;   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= m; ++i) cin >> her[i].first >> her[i].second;     for (int i = 1; i <= n; ++i) cin >> a[i];     int pos = -1;     for (int i = 1; i <= n; ++i) {       sum[0] = 0;       sum[n + 1] = 0;       int tp = a[i];       for (int i = 1; i <= n; ++i) vis[i] = 0;       for (int j = 1; j < i; ++j) sum[j] = sum[j - 1] + a[j];       for (int j = n; j > i; --j) sum[j] = sum[j + 1] + a[j];       sum[i] = 0;       build(1, n, 1);       while (true) {         int cnt = 0;         for (int j = 1; j <= m; ++j) {           if (vis[j]) continue;           auto h = her[j];           int S = 0, ps = Pv(1, n, 1, h.first);           if (h.first <= i - 1) S = query(1, n, 1, h.first, i - 1) - ps;           if (h.first >= i + 1) S = query(1, n, 1, i + 1, h.first) - ps;           if (h.second + S >= 0) {             if (h.first <= i - 1) S = Pv(1, n, 1, i - 1) - ps;             if (h.first >= i + 1) S = Pv(1, n, 1, i + 1) - ps;             if (h.second + S + a[i] >= 0) {               a[i] = 0;               vis[j] = 1;               cnt++;               ans.push_back(j);               if (h.first <= i - 1) update(1, n, 1, h.first, i - 1, ps);               if (h.first >= i + 1) update(1, n, 1, i + 1, h.first, ps);             }           }         }         if (!cnt) break;       }       if (ans.size() == m) {         pos = i;         break;       }       a[i] = tp;       ans.clear();     }     cout << pos << endl;     for (auto &u : ans) cout << u <<    ;     puts(  );     return 0;   }


#include <bits/stdc++.h>   const double PI = 3.1415926535897932384626433;   const int KL = 1e5 + 10;   const long long MOD = 1e9 + 7;   using namespace std;   struct point {     long double x, y;     void go(long long x1, long long y1) {       x = x1;       y = y1;     }     void read() { cin >> x >> y; }     point operator-(point b) { return point{x - b.x, y - b.y}; }     point operator+(point b) { return point{x + b.x, y + b.y}; }   };   long double fnd_angle(point p) {     long double len = sqrt(p.x * p.x + p.y * p.y);     long double angle = acos(fabs(p.x) / len);     if (p.y < 0) {       if (p.x >= 0)         angle = 2 * PI - angle;       else         angle += PI;     } else if (p.x < 0)       angle = PI - angle;     return angle;   }   int n, k;   vector<point> A;   vector<pair<long double, long double>> a, b;   multiset<long double> s;   bool ok(long double mid) {     if (k <= 0) return 1;     a.clear();     b.clear();     for (int i = 0; i < n; i++) {       long double dis = sqrt(A[i].x * A[i].x + A[i].y * A[i].y);       if (dis > 2 * mid) continue;       long double angle = fnd_angle(A[i]);       long double angle2 = acos(dis / (2.0 * mid));       a.push_back({angle - angle2, 2 * angle2});       b.push_back({angle + angle2, -2.0 * angle2});     }     sort(a.begin(), a.end());     sort(b.begin(), b.end());     reverse(b.begin(), b.end());     int sz = a.size();     for (int i = 0; i < sz; i++) a.push_back({a[i].first + 2 * PI, a[i].second});     for (int i = 0; i < sz; i++) b.push_back({b[i].first - 2 * PI, b[i].second});     int mx = 0;     s.clear();     for (int i = 0; i < a.size(); i++) {       while (s.size() > 0 && *s.begin() < a[i].first) s.erase(s.begin());       if (s.size() + 1 >= k) return 1;       s.insert(a[i].first + a[i].second);     }     s.clear();     for (int i = 0; i < b.size(); i++) {       while (s.size() > 0 && *(--s.end()) > b[i].first) s.erase(--s.end());       if (s.size() + 1 >= k) return 1;       s.insert(b[i].first + b[i].second);     }     return 0;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     for (int i = 1; i <= n; i++) {       point pp;       pp.read();       if (pp.x == 0 && pp.y == 0) {         k--;         continue;       }       A.push_back(pp);     }     n = A.size();     long double lo = 0.0, hi = 2e5;     int cnt = 33;     while (cnt--) {       long double mid = (lo + hi) / 2.0;       if (ok(mid))         hi = mid;       else         lo = mid;     }     cout << fixed << setprecision(8) << lo <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int MOD = 998244353;   long long int power(long long int x, unsigned long long int y) {     long long res = 1, m = y + 2;     x %= m;     while (y > 0) {       if (y & 1) res = res * x % m;       x = x * x % m;       y >>= 1;     }     return res;   }   long long int modInverse(long long int a, long long int m = MOD) {     return power(a, m - 2);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     while (t--) {       long long int n, i, j;       cin >> n;       long long int a[n];       for (i = 0; i < n; i++) cin >> a[i];       long long int p[n + 1];       p[0] = 1;       for (i = 1; i < n + 1; i++) {         p[i] = 100 * p[i - 1] % MOD;       }       long long int dp[n], x = 1;       for (i = 0; i < n; i++) {         dp[i] = x * (100 - a[i]) % MOD;         x *= a[i];         x %= MOD;         dp[i] *= p[n - i - 1];         dp[i] %= MOD;       }       long long int dp1[n];       for (i = 0; i < n; i++) dp1[i] = dp[i] * (i + 1) % MOD;       long long int s1 = n;       for (i = 0; i < n; i++) s1 *= a[i], s1 %= MOD;       long long int s2 = 0;       for (i = 0; i < n; i++) s2 += dp1[i], s2 %= MOD;       long long int s3 = 0;       for (i = 0; i < n; i++) s3 += dp[i], s3 %= MOD;       s3 = p[n] - s3;       while (s3 < 0) s3 += MOD;       s2 += s1;       s2 %= MOD;       cout << s2 * modInverse(s3) % MOD;     }     cerr <<  Time Taken:  << (float)clock() / CLOCKS_PER_SEC * 1000 <<  ms           <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<int> prime(n + 1, 0);     vector<int> div(n + 1, 0);     prime[1] = 1;     for (long long i = 2; i <= n; i++) {       if (!prime[i]) {         for (long long j = i; j <= n; j += i) {           prime[j] = i;         }       }     }     for (int i = 0; i < m; i++) {       int flag;       int x;       char c;       cin >> c >> x;       if (c ==  + ) {         if (div[prime[x]] == x) {           cout <<  Already on  << endl;         } else {           flag = 0;           for (long long i = x; i > 1; i /= prime[i]) {             if (div[prime[i]]) {               flag = div[prime[i]];             }           }           if (flag) {             cout <<  Conflict with   << flag << endl;           } else {             for (long long i = x; i > 1; i /= prime[i]) {               div[prime[i]] = x;             }             if (x == 1) {               div[1] = 1;             }             cout <<  Success  << endl;           }         }       } else {         if (div[prime[x]] != x) {           cout <<  Already off  << endl;         } else {           for (long long i = x; i > 1; i /= prime[i]) {             div[prime[i]] = 0;           }           if (x == 1) {             div[1] = 0;           }           cout <<  Success  << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int query(const vector<int> &S, int v, const vector<int> &T) {     if (S.empty() || T.empty()) return 0;     cout << S.size() <<   n ;     for (int i = 0; i < (int)S.size(); i++)       cout << S[i] + 1 << (i < (int)S.size() - 1 ?     :   n );     cout << T.size() <<   n ;     for (int i = 0; i < (int)T.size(); i++)       cout << T[i] + 1 << (i < (int)T.size() - 1 ?     :   n );     cout << v + 1 <<   n ;     cout << flush;     int answer;     cin >> answer;     return answer;   }   int query(int s, int v, const vector<int> &T) {     return query(vector<int>(1, s), v, T);   }   int N, root;   vector<int> parent;   vector<int> subtree_size;   int main() {     ios::sync_with_stdio(false);     cin >> N;     root = 0;     parent.assign(N, -1);     subtree_size.assign(N, -1);     vector<int> non_root;     for (int i = 0; i < N; i++)       if (i != root) non_root.push_back(i);     for (int i = 0; i < N; i++)       if (i != root) subtree_size[i] = query(root, i, non_root);     subtree_size[root] = N;     vector<int> sorted;     for (int i = 0; i < N; i++) sorted.push_back(i);     sort(sorted.begin(), sorted.end(),          [&](int a, int b) { return subtree_size[a] < subtree_size[b]; });     for (int i = 0; i < N; i++) {       int v = sorted[i];       vector<int> missing_parent;       for (int j = 0; j < i; j++)         if (parent[sorted[j]] < 0) missing_parent.push_back(sorted[j]);       int remaining = query(root, v, missing_parent);       int high = (int)missing_parent.size();       while (remaining > 0) {         int low = 0;         while (low < high) {           int mid = (low + high + 1) / 2;           if (query(root, v,                     vector<int>(missing_parent.begin(),                                 missing_parent.begin() + mid)) == remaining)             high = mid - 1;           else             low = mid;         }         int child = missing_parent[low];         parent[child] = v;         remaining--;       }     }     cout <<  ANSWER  <<   n ;     for (int i = 0; i < N; i++)       if (parent[i] >= 0) cout << i + 1 <<     << parent[i] + 1 <<   n ;     cout << flush;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     if (false) {       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);     }     int n;     cin >> n;     vector<int> v(n + 1, -1);     int xx = 1048576;     long long sum = 0;     for (int i = n; i > 0; i--) {       if (v[i] >= 0) {         continue;       }       while (xx / 2 > i) {         xx /= 2;       }       int a = i ^ (xx - 1);       v[i] = a;       v[a] = i;       sum += (a + i) * 2;     }     if (v[0] < 0) {       v[0] = 0;     }     cout << sum << endl;     for (int i = 0; i <= n; i++) {       if (i > 0) {         cout <<    ;       }       cout << v[i];     }     cout << endl;     if (false) {       fclose(stdin);       fclose(stdout);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 150007;   const double eps = 1e-8;   int n;   double l, r, mid, sm[N], mxp[N], mnp[N];   struct note {     double p, t, c;     int id;   } a[N], b[N];   int cmp(note x, note y) { return x.c > y.c; }   int cmp0(note x, note y) { return x.p < y.p; }   int check() {     double mxv = 0;     for (int i = 1, j, lb, rb; i <= n; i = j) {       j = i;       while (j <= n && a[j].c == a[i].c) ++j;       lb = i, rb = j - 1;       for (int k = i; k < j; ++k) {         mnp[a[k].id] = a[k].p * (1 - mid * sm[rb] / sm[n]);         mxp[a[k].id] = a[k].p * (1 - mid * (sm[lb - 1] + a[k].t) / sm[n]);       }     }     for (int i = 1, j; i <= n; i = j) {       j = i;       while (j <= n && b[j].p == b[i].p) ++j;       for (int k = i; k < j; ++k)         if (mxv > mnp[b[k].id]) return 0;       for (int k = i; k < j; ++k) mxv = max(mxv, mxp[b[k].id]);     }     return 1;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %lf , &a[i].p), a[i].id = i;     for (int i = 1; i <= n; ++i) scanf( %lf , &a[i].t), a[i].c = a[i].p / a[i].t;     memcpy(b, a, sizeof(a));     sort(b + 1, b + n + 1, cmp0);     sort(a + 1, a + n + 1, cmp);     for (int i = 1; i <= n; ++i) sm[i] = sm[i - 1] + a[i].t;     l = 0, r = 1;     while (r - l > eps) {       mid = (l + r) / 2;       if (check())         l = mid;       else         r = mid;     }     printf( %.7lf n , l);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string tostr(int n) {     stringstream rr;     rr << n;     return rr.str();   }   long long qpow(long long n, long long k) {     long long ans = 1;     while (k) {       if (k & 1) ans = ans * n;       n = n * n;       k >>= 1;     }     return ans;   }   const int mod = 1e9 + 7;   const int mxn = 1e5 + 9;   const int eps = 1e-9;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL);     int i, j, k, l, st;     vector<char> v;     string s, p;     cin >> s;     if (s[0] ==  - )       st = 1, cout <<  ( ;     else       st = 0;     cout <<  $ ;     p = s.substr(st);     if (p.find( . ) == -1)       for (i = p.size() - 1; i >= 0; i--) {         v.push_back(p[i]);         if ((p.size() - i) % 3 == 0 && i != 0) v.push_back( , );       }     else       for (i = p.find( . ) - 1; i >= 0; i--) {         v.push_back(p[i]);         if ((p.find( . ) - i) % 3 == 0 && i != 0) v.push_back( , );       }     reverse(v.begin(), v.end());     for (auto c : v) cout << c;     cout <<  . ;     if (p.find( . ) == -1)       cout <<  00 ;     else {       cout << p[p.find( . ) + 1];       if (p[p.find( . ) + 2] !=   0 )         cout << p[p.find( . ) + 2];       else         cout <<  0 ;     }     if (st == 1) cout <<  ) ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e3 + 1;   int dp[N][N];   bool palid[N][N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     string s;     cin >> s;     int n = s.size();     for (int d = 0; d < n; d++)       for (int i = 0; i < n; i++) {         int j = i + d;         if (j >= n) continue;         palid[i][j] = (s[i] == s[j]);         if (i + 1 <= j - 1) palid[i][j] &= palid[i + 1][j - 1];       }     for (int d = 0; d < n; d++)       for (int i = 0; i < n; i++) {         int j = i + d;         if (j >= n) continue;         dp[i][j] = palid[i][j];         if (i + 1 <= j) dp[i][j] += dp[i + 1][j];         if (i <= j - 1) dp[i][j] += dp[i][j - 1];         if (i + 1 <= j - 1) dp[i][j] -= dp[i + 1][j - 1];       }     int q;     cin >> q;     for (int i = 0; i < q; i++) {       int l, r;       cin >> l >> r;       l--;       r--;       cout << dp[l][r] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, flag;   int ar[101][101], ars[101][101], c[101][101], q[101][101];   int fu() {     int y = 1;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (ars[i][j] != c[i][j]) y = 0;     return y;   }   void f() {     flag = max(flag, fu());     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) q[i][j] = c[j][n - i - 1];     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) c[i][j] = q[i][j];     flag = max(flag, fu());     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) q[i][j] = c[j][n - i - 1];     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) c[i][j] = q[i][j];     flag = max(flag, fu());     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) q[i][j] = c[j][n - i - 1];     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) c[i][j] = q[i][j];     flag = max(flag, fu());   }   int main() {     cin >> n;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         char a;         cin >> a;         if (a ==  X )           ar[i][j] = 0;         else           ar[i][j] = 1;         c[i][j] = ar[i][j];       }     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         char a;         cin >> a;         if (a ==  X )           ars[i][j] = 0;         else           ars[i][j] = 1;       }     f();     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) c[i][j] = ar[n - i - 1][j];     f();     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) c[i][j] = ar[i][n - j - 1];     f();     if (flag) {       cout <<  Yes ;     } else       cout <<  No ;     return 0;   }


#include <bits/stdc++.h>   int main() {     int a, b, c, count = 0, i, j;     scanf( %d%d%d , &a, &b, &c);     if ((a == c) || (b == c)) {       count++;     } else {       for (i = 0; i <= c; i += a) {         for (j = 0; j <= c; j += b) {           if ((i + j) == c) {             count++;             break;           }         }       }     }     if (count != 0) {       printf( Yes );     } else {       printf( No );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <const int mod, const int modPhi>   struct Mint {     int v;     Mint() { v = 0; }     Mint(int x) {       v = x % mod;       if (v < 0) v += mod;     }     Mint(long long x) {       v = x % mod;       if (v < 0) v += mod;     }     friend bool operator==(const Mint &a, const Mint &b) { return a.v == b.v; }     friend bool operator!=(const Mint &a, const Mint &b) { return a.v != b.v; }     friend bool operator<(const Mint &a, const Mint &b) { return a.v < b.v; }     friend bool operator<=(const Mint &a, const Mint &b) { return a.v <= b.v; }     friend bool operator>(const Mint &a, const Mint &b) { return a.v > b.v; }     friend bool operator>=(const Mint &a, const Mint &b) { return a.v >= b.v; }     Mint &operator+=(const Mint &a) {       v += a.v;       if (v >= mod) v -= mod;       return *this;     }     Mint &operator-=(const Mint &a) {       v -= a.v;       if (v < 0) v += mod;       return *this;     }     Mint &operator*=(const Mint &a) {       v = (1LL * v * a.v) % mod;       return *this;     }     Mint operator-() { return Mint(-v); }     Mint &operator++() { return *this += 1; }     Mint &operator--() { return *this -= 1; }     friend Mint operator+(Mint a, const Mint b) { return a += b; }     friend Mint operator-(Mint a, const Mint b) { return a -= b; }     friend Mint operator*(Mint a, const Mint b) { return a *= b; }     friend Mint min(Mint a, Mint b) { return (a < b ? b : a); }     friend Mint max(Mint a, Mint b) { return (a > b ? a : b); }     friend Mint pow(Mint a, long long b) {       Mint res = 1;       while (b > 0) {         if (b & 1) {           res *= a;         }         a *= a, b >>= 1;       }       return res;     }     friend Mint inv(const Mint &a) { return pow(a, modPhi - 1); }     Mint operator/=(const Mint &a) {       *this *= inv(a);       return *this;     }     friend Mint operator/(Mint a, const Mint b) { return a /= b; }     friend istream &operator>>(istream &in, Mint &a) { return in >> a.v; }     friend ostream &operator<<(ostream &out, Mint a) { return out << a.v; }   };   const int mod = 1e9 + 7;   using mint = Mint<mod, mod - 1>;   mint k;   mint pp = 1;   int moves = 0;   void move(int &x, int &del, int b) {     if (x == b) del = -1;     if (x == 1) del = 1;     x += del;   }   int move1(int x, int del, int b) {     if (x == b) del = -1;     if (x == 1) del = 1;     x += del;     return x;   }   void testCase() {     int n, m, rb, cb, rd, cd;     mint p;     cin >> n >> m >> rb >> cb >> rd >> cd;     cin >> p;     p /= mint(100);     int delr = 1, delc = 1;     if (rb == rd || cb == cd)       k += mint(pp) * mint(p) * mint(moves), pp *= (1 - p);     moves++;     int initr = rb;     int initc = cb;     move(rb, delr, n);     move(cb, delc, m);     int initr1 = rb;     int initc1 = cb;     while (true) {       if (rb == rd || cb == cd)         k += mint(pp) * mint(p) * mint(moves), pp *= (1 - p);       moves++;       move(rb, delr, n);       move(cb, delc, m);       if (rb == initr && cb == initc && move1(rb, delr, n) == initr1 &&           move1(cb, delc, m) == initc1)         break;     }     mint ans = mint(k + moves * pp) / mint(1 - pp);     cout << ans <<   n ;     moves = 0;     pp = 1;     k = 0;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int tc;     cin >> tc;     while (tc--) {       testCase();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, i, j, a, b, k;     vector<vector<bool> > M;     cin >> n;     m = 5;     M.resize(m);     for (i = 0; i < m; i++) M[i].resize(m);     for (i = 0; i < n; i++) {       cin >> a >> b;       a--;       b--;       M[a][b] = M[b][a] = true;     }     for (i = 0; i < m - 2; i++)       for (j = i + 1; j < m - 1; j++)         for (k = j + 1; k < m; k++)           if (M[i][j] == M[i][k] && M[i][j] == M[j][k]) {             cout <<  WIN ;             return 0;           }     cout <<  FAIL ;     return 0;   }


#include <bits/stdc++.h>   int main(void) {     int n, i;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       if ((i % 2) != 0) {         printf( I hate );         if (i == n) {           printf(  it );           break;         }       } else {         printf( I love );         if (i == n) {           printf(  it );           break;         }       }       printf(  that  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool IO_FILE = 0;   ifstream ifs( input.txt );   ofstream ofs( output.txt );   int main() {     if (IO_FILE) {       cin.rdbuf(ifs.rdbuf());       cout.rdbuf(ofs.rdbuf());     }     int n, m;     cin >> n >> m;     char *s = new char[m];     bool res = 1;     char prev =  E ;     for (int i = 0; i < n; i++) {       cin >> s;       char p = s[0];       res = 1;       if (prev !=  E  && p == prev) {         res = 0;         break;       }       for (int j = 1; j < m; j++)         if (!(res = s[j] == p)) break;       if (!res) break;       prev = p;     }     cout << (res ?  YES  :  NO );   }


#include <bits/stdc++.h>   using namespace std;   vector<int> d[2], f;   vector<vector<bool> > nab;   int n, len = -1;   const int INF = 1 << 29;   int calc(vector<bool> &a, vector<bool> &b) {     vector<bool> c(a.size() + b.size() + 1);     for (int i = 0; i < b.size(); ++i) c[i] = b[i];     for (int i = b.size(); i < c.size(); ++i) c[i + 1] = a[i - (int)b.size()];     vector<int> p(c.size());     p[0] = 0;     for (int i = 1; i < p.size(); ++i) {       int j = p[i - 1];       while (j > 0 && (c[i] != c[j] || i == b.size() || j == b.size()))         j = p[j - 1];       if (c[i] == c[j] && !(i == b.size() || j == b.size())) j++;       p[i] = j;     }     return p[c.size() - 1];   }   vector<vector<int> > p;   inline int suf(vector<bool> &a, int &l) {     int ans = 0;     for (int i = len - l; i < len; ++i) ans |= ((int)a[i] << (i + l - len));     return ans;   }   inline int pref(vector<bool> &a, int &l) {     int ans = 0;     for (int i = 0; i < l; ++i) ans |= ((int)a[i] << i);     return ans;   }   int main() {     cin.sync_with_stdio(0);     cin >> n;     nab.resize(n);     d[0].resize(n + 1);     d[1].resize(n + 1);     string str;     for (int i = 0; i < n; ++i) {       cin >> str;       if (len == -1) len = str.size();       nab[i].resize(len);       for (int j = 0; j < len; ++j) nab[i][j] = (str[j] ==  0  ? 0 : 1);     }     p.resize(len + 1, vector<int>(1 << len, -1));     d[0][0] = d[1][0] = 0;     p[0][0] = 1;     vector<int> f(n);     f[0] = len;     for (int i = 1; i < n; ++i) f[i] = f[i - 1] + len - calc(nab[i - 1], nab[i]);     int suffix[len + 1], prefix[len + 1];     d[1][1] = d[0][1] = len;     int bestp, bestd, now;     for (int i = 2; i <= n; ++i) {       d[0][i] = min(d[0][i - 1], d[1][i - 1]) + f[i - 1] - f[i - 2];       d[1][i] = INF;       for (int j = 1; j <= len; ++j) {         suffix[j] = suf(nab[i - 2], j);         prefix[j] = pref(nab[i - 1], j);       }       bestp = p[0][0];       d[1][i] = d[1][bestp] + f[i - 2] - f[bestp - 1] + len;       for (int j = 1; j <= len; ++j) {         int &pp = p[j][prefix[j]];         if (pp != -1) {           now = d[1][pp] + f[i - 2] - f[pp - 1] + len - j;           if (now < d[1][i]) {             d[1][i] = now;             bestp = pp;           }         }       }       if (d[1][i] < d[1][p[0][0]] + f[i - 1] - f[p[0][0] - 1]) p[0][0] = i;       for (int j = 1; j <= len; ++j) {         int &ps = p[j][suffix[j]];         if (ps == -1 || (d[1][i] < d[1][ps] + f[i - 1] - f[ps - 1])) ps = i;       }     }     cout << min(d[1][n], d[0][n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     x = 0;     int f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     x *= f;   }   inline void judge() {     freopen( in.txt ,  r , stdin);     freopen( out.txt ,  w , stdout);   }   const int maxn = 200005;   int n, Q, s[maxn], m[maxn], t[maxn], l[maxn], r[maxn], R[maxn];   set<pair<pair<int, int>, int> > res;   namespace seg {   long long suma[maxn << 5], sumb[maxn << 5];   int ls[maxn << 5], rs[maxn << 5], tot;   inline void update(int x) {     suma[x] = suma[ls[x]] + suma[rs[x]];     sumb[x] = sumb[ls[x]] + sumb[rs[x]];   }   inline void add(int x, int &y, int place, int va, int vb, int l, int r) {     y = ++tot;     suma[y] = suma[x];     sumb[y] = sumb[x];     ls[y] = ls[x];     rs[y] = rs[x];     suma[y] += va;     sumb[y] += vb;     if (l == r) {       return;     }     int md = (l + r) >> 1;     if (place <= md)       add(ls[x], ls[y], place, va, vb, l, md);     else       add(rs[x], rs[y], place, va, vb, md + 1, r);   }   inline long long queryA(int x, int l, int r, int lq, int rq) {     if (!x) return 0;     if (lq <= l && r <= rq) return suma[x];     long long res = 0;     int md = (l + r) >> 1;     if (lq <= md) res += queryA(ls[x], l, md, lq, rq);     if (rq > md) res += queryA(rs[x], md + 1, r, lq, rq);     return res;   }   inline long long queryB(int x, int l, int r, int lq, int rq) {     if (!x) return 0;     if (lq <= l && r <= rq) return sumb[x];     long long res = 0;     int md = (l + r) >> 1;     if (lq <= md) res += queryB(ls[x], l, md, lq, rq);     if (rq > md) res += queryB(rs[x], md + 1, r, lq, rq);     return res;   }   }  // namespace seg   int qtot = 0;   int root[maxn];   inline long long query(int l, int r, int tme) {     tme = min(tme, 99999);     return seg::queryA(root[r], 0, 100001, 0, tme) -            seg::queryA(root[l - 1], 0, 100001, 0, tme) +            1ll *                (seg::queryB(root[r], 0, 100001, tme + 1, 100001) -                 seg::queryB(root[l - 1], 0, 100001, tme + 1, 100001)) *                tme;   }   int main() {     read(n);     for (int i = (1); i <= (n); i++) read(s[i]), read(m[i]), read(R[i]);     for (int i = (1); i <= (n); i++) res.insert(make_pair(make_pair(i, i), -1));     read(Q);     for (int i = (1); i <= (Q); i++) read(t[i]), read(l[i]), read(r[i]);     for (int i = (1); i <= (n); i++) {       if (R[i] == 0) {         seg::add(root[i - 1], root[i], 100001, 0, R[i], 0, 100001);         continue;       }       int t = floor((long double)m[i] / R[i] + 0.99999999);       assert(1ll * t * R[i] >= m[i]);       assert(1ll * (t - 1) * R[i] < m[i]);       seg::add(root[i - 1], root[i], t, m[i], R[i], 0, 100001);     }     for (int i = (1); i <= (Q); i++) {       long long ans = 0;       set<pair<pair<int, int>, int> >::iterator it =           res.upper_bound(make_pair(make_pair(l[i], n + 1), 1));       vector<set<pair<pair<int, int>, int> >::iterator> rubi;       rubi.clear();       it--;       if (it->first.first < l[i]) {         res.insert(make_pair(make_pair(it->first.first, l[i] - 1), it->second));       }       int tmp1 = it->first.second, tmp2 = it->second;       res.erase(it);       res.insert(make_pair(make_pair(l[i], tmp1), tmp2));       it = res.upper_bound(make_pair(make_pair(l[i], n + 1), 1));       it--;       for (;;) {         if (it->second == -1) {           assert(it->first.first == it->first.second);           ans += min(               (long long)m[it->first.first],               (long long)s[it->first.first] + 1ll * R[it->first.first] * t[i]);         } else {           ans += query(it->first.first, min(it->first.second, r[i]),                        t[i] - it->second);           long long res = 0;         }         rubi.push_back(it);         if (it->first.second > r[i]) {           res.insert(               make_pair(make_pair(r[i] + 1, it->first.second), it->second));           break;         }         if (it->first.second == r[i]) break;         it++;       }       for (set<pair<pair<int, int>, int> >::iterator x : rubi) res.erase(x);       res.insert(make_pair(make_pair(l[i], r[i]), t[i]));       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;      void solve(){       int n;       cin >> n;       vector<int64_t> X;       vector<int64_t> Y;       int x,y;       for (int i = 0; i < n; i++){           cin >> x >> y;           X.push_back(x);           Y.push_back(y);       }       sort(X.begin(),X.end());               sort(Y.begin(),Y.end());               int64_t res;       if (n%2 == 0){           res = (X.at(n/2)-X.at(n/2-1)+1)*(Y.at(n/2)-Y.at(n/2-1)+1);       } else {           res = 1;       }       cout << res << endl;       return;   }      int main() {       int t;       cin >> t;       while (t){           solve();           t--;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   void input() {     freopen( in.txt ,  r , stdin);     freopen( out.txt ,  w , stdout);   }   const int N = 1e6 + 10;   vector<int> G[N];   int in[N], n, cnt[3], vis[N];   void dfs(int x, int flag) {     cnt[flag]++;     vis[x] = 1;     for (int i = 0; i < G[x].size(); i++) {       int u = G[x][i];       if (vis[u]) continue;       dfs(u, (flag + 1) % 2);     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n - 1; i++) {       int u, v;       cin >> u >> v;       G[u].push_back(v);       G[v].push_back(u);     }     dfs(1, 1);     cout << min(cnt[0], cnt[1]) - 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   int main() {     int n, k;     scanf( %d %d , &n, &k);     int cnt = 0, a[100];     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     for (int i = 0; i < n; i++) {       if (a[i] >= a[k - 1] && a[i] > 0) cnt++;     }     printf( %d , cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n = 0;   vector<int> v;   int flag[2010];   int countt = 0;   int k = 0;   int maxt = 0;   int main() {     cin >> n;     cin >> k;     for (int i = 0; i < n; i++) {       int kari = 0;       cin >> kari;       v.push_back(kari);       if (i == 0) {         maxt = kari;       } else {         maxt = max(maxt, kari);       }     }     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         vector<int> u;         vector<int> d;         u.clear();         d.clear();         int sum = 0;         for (int jj = 0; jj < n; jj++) {           if (jj < i || j < jj) {             d.push_back(v[jj]);           } else {             sum += v[jj];             u.push_back(v[jj]);           }         }         sort(u.begin(), u.end());         sort(d.begin(), d.end());         maxt = max(maxt, sum);         {           int ii = 0;           int jj = d.size() - 1;           for (; ii < u.size() && jj >= 0 && ii < k; ii++, jj--) {             sum -= u[ii];             sum += d[jj];             maxt = max(maxt, sum);           }         }       }     }     cout << maxt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int64_t k = 0;   inline bool equals(string& s1, int64_t i1, int64_t j1, string& s2, int64_t i2,                      int64_t j2) {     if (j1 != j2) {       return false;     }     auto x = j1;     for (int64_t i = 0; i < x; i++) {       if (s1[i1 + i] != s2[i2 + i]) {         return false;       }     }     return true;   }   bool equivilant(string& s1, int64_t i1, int64_t j1, string& s2, int64_t i2,                   int64_t j2) {     if (equals(s1, i1, j1, s2, i2, j2)) {       return true;     }     if (j1 != j2 || j1 % 2 == 1) {       return false;     }     auto x = j1 / 2;     if (equivilant(s1, i1, x, s2, i2, x) &&         equivilant(s1, i1 + x, x, s2, i2 + x, x)) {       return true;     }     if (equivilant(s1, i1, x, s2, i2 + x, x) &&         equivilant(s1, i1 + x, x, s2, i2, x)) {       return true;     }     return false;   }   int main() {     ios::sync_with_stdio(false);     string s1;     cin >> s1;     string s2;     cin >> s2;     if (equivilant(s1, 0, s1.size(), s2, 0, s2.size())) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct QUERY {     int query, time, number;   };   void update(vector<map<int, int> > &tree, int v, int tl, int tr, int &pos,               int query, int value) {     if (pos < tl || pos > tr) return;     if (query == 1)       tree[v][value]++;     else if (query == 2)       tree[v][value]--;     if (tr != tl) {       update(tree, 2 * v, tl, (tr + tl) / 2, pos, query, value);       update(tree, 2 * v + 1, (tr + tl) / 2 + 1, tr, pos, query, value);     }   }   int sum(vector<map<int, int> > &tree, int v, int tl, int tr, int i, int j,           int value) {     if (i > tr || j < tl) return 0;     if (i <= tl && j >= tr) return tree[v][value];     int sum1 = sum(tree, 2 * v, tl, (tr + tl) / 2, i, j, value);     int sum2 = sum(tree, 2 * v + 1, (tr + tl) / 2 + 1, tr, i, j, value);     return sum1 + sum2;   }   int main() {     int n;     cin >> n;     vector<QUERY> a(n + 1);     vector<int> num(n + 1);     vector<int> t(n + 1);     for (int i = 1; i <= n; ++i) {       cin >> a[i].query >> a[i].time >> a[i].number;       num[i] = a[i].number;       t[i] = a[i].time;     }     sort(num.begin(), num.end());     num.erase(unique(num.begin(), num.end()), num.end());     sort(t.begin(), t.end());     t.erase(unique(t.begin(), t.end()), t.end());     map<int, int> help;     for (unsigned int i = 1; i < num.size(); ++i) {       help.insert(make_pair(num[i], i));     }     for (int i = 1; i <= n; ++i) {       a[i].number = help[a[i].number];     }     help.clear();     for (unsigned int i = 1; i < t.size(); ++i) {       help.insert(make_pair(t[i], i));     }     for (int i = 1; i <= n; ++i) {       a[i].time = help[a[i].time];     }     int len = t.size() - 1;     int tree_size = 4 * len;     vector<map<int, int> > tree(tree_size);     for (int i = 1; i <= n; ++i) {       if (a[i].query != 3)         update(tree, 1, 1, len, a[i].time, a[i].query, a[i].number);       else         cout << sum(tree, 1, 1, len, 1, a[i].time, a[i].number) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100000 + 10;   int n;   int a[N];   long long query(int l, int r) {     vector<pair<long long, long long> > stack;     long long ret = 0;     long long cur = 0;     for (int i = l + 1; i <= r; ++i) {       long long diff = abs(a[i] - a[i - 1]);       long long tot = 1;       for (; stack.size();) {         if (stack.back().first <= diff) {           tot += stack.back().second;           cur -= stack.back().first * stack.back().second;           stack.pop_back();         } else {           break;         }       }       stack.push_back(make_pair(diff, tot));       cur += diff * tot;       ret += cur;     }     return ret;   }   void solve() {     int q;     cin >> n >> q;     for (int i = 0; i < n; ++i) {       scanf( %d , a + i);     }     for (; q--;) {       int l, r;       scanf( %d%d , &l, &r);       --l, --r;       cout << query(l, r) << endl;     }   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long s, k;   long long a[5000];   long long ans[5000];   int t;   int dfs(int n, int m) {     if (n == 0) {       if (t == 1) {         cout << 2 << endl;         cout << 0 <<     << ans[0] << endl;       } else {         cout << t << endl;         for (int i = t - 1; i >= 0; i--) cout << ans[i] <<    ;         cout << endl;       }       exit(0);     }     for (int i = m; i >= 0; i--) {       if (n >= a[i]) {         ans[t++] = a[i];         dfs(n - a[i], i - 1);         t--;       }     }   }   int main() {     cin >> s >> k;     int m = 0;     a[0] = 1;     for (int i = 1; a[i - 1] < s; i++) {       for (int j = i - 1; j >= 0 && j >= i - k; j--) a[i] += a[j];       m = i;     }     if (a[m] > s) m--;     dfs(s, m);   }


#include <bits/stdc++.h>   int cmp(const void *a, const void *b) { return (*(int *)a - *(int *)b); }   long long int mod;   void f(long long int p) {     long long ans = 1, n = 3;     while (p) {       if (p & 1) ans = (ans * n) % mod;       n = (n * n) % mod;       p = p >> 1;     }     ans--;     while (ans < 0) ans += mod;     printf( %lld , ans);   }   int main() {     long long int n;     scanf( %lld%lld , &n, &mod);     f(n);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:128777216 )   const int null = 0;   using namespace std;   template <class T>   int size(const T &a) {     return int(a.size());   }   template <class T>   T abs(const T &a) {     return (a < 0 ? -a : a);   }   template <class T>   T sqr(const T &a) {     return a * a;   }   const double pi = acos(-1.0);   const int max_n = 2048;   char s[max_n][max_n];   struct Res {     int r, c;     int d;     int moves;     Res() { moves = -1; }   } dp[max_n][max_n];   bool was[max_n][max_n];   Res &calc(int r, int c, int d = -1) {     Res &res = dp[r][c];     if (res.moves >= 0) {       return res;     }     if (was[r][c]) {       cout << -1 << endl;       exit(0);     }     was[r][c] = true;     switch (s[r][c]) {       case  # :         res.moves = 0;         res.d = -1;         res.r = r;         res.c = c;         break;       case  > :         res = calc(r, c + 1, 1);         res.moves++;         if (res.moves == 1) {           res.d = 1;         }         break;       case  < :         res = calc(r, c - 1, 2);         res.moves++;         if (res.moves == 1) {           res.d = 2;         }         break;       case  ^ :         res = calc(r - 1, c, 3);         res.moves++;         if (res.moves == 1) {           res.d = 3;         }         break;       case  v :         res = calc(r + 1, c, 4);         res.moves++;         if (res.moves == 1) {           res.d = 4;         }         break;     }     return res;   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %s , s[i]);     }     int res = 0;     Res best;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         Res cur = calc(i, j);         if (cur.moves > best.moves) {           best = cur;         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         Res cur = dp[i][j];         if (cur.moves + best.moves > res &&             (cur.d != best.d || cur.r != best.r || cur.c != best.c ||              cur.moves != best.moves)) {           res = cur.moves + best.moves;         }       }     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int T, x;   char str[100005], ans[100005];   char usd[100005];   int main() {     scanf( %d , &T);     while (T--) {       scanf( %s , str + 1);       scanf( %d , &x);       int n = strlen(str + 1);       for (int i = 1; i <= n; ++i) {         if (str[i] ==  0 ) {           if (i + x <= n) ans[i + x] =  0 ;           if (i - x >= 1) ans[i - x] =  0 ;         }       }       for (int i = 1; i <= n; ++i)         if (!ans[i]) ans[i] =  1 ;       for (int i = 1; i <= n; ++i) {         if (i - x >= 1 && ans[i - x] ==  1 )           usd[i] =  1 ;         else if (i + x <= n && ans[i + x] ==  1 )           usd[i] =  1 ;         else           usd[i] =  0 ;       }       bool flag = true;       for (int i = 1; i <= n; ++i)         if (usd[i] != str[i]) {           flag = false;           break;         }       if (!flag)         printf( -1 n );       else         printf( %s n , ans + 1);       for (int i = 1; i <= n; ++i) ans[i] = 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 998244353;   signed main() {     cin.tie(0)->sync_with_stdio(0);     long long n, m;     cin >> n >> m;     vector<long long> pw(n + 1);     pw[0] = 1;     for (long long i = 1; i <= n; i++) pw[i] = 2 * pw[i - 1] % MOD;     long long _ = n;     vector<long long> basis;     for (long long i = 0; i < n; i++) {       long long a;       cin >> a;       for (auto x : basis) a = min(a, a ^ x);       if (a) {         long long id = 0;         while (id < (long long)basis.size() && basis[id] > a) ++id;         basis.insert(basis.begin() + id, a);       }     }     n = basis.size();     vector<long long> ans(2 * m + 1, 0);     if (n <= 20) {       for (long long mask = 0; mask < (1ll << n); mask++) {         long long val = 0;         for (long long i = 0; i < n; i++)           if (mask & (1ll << i)) val ^= basis[i];         ans[__builtin_popcountll(val)]++;       }     } else {       vector<bool> good(m);       for (auto x : basis)         for (long long i = m - 1; i >= 0; i--)           if (x & (1ll << i)) {             good[i] = 1;             break;           }       for (long long i = 0; i < n; i++)         for (long long j = i + 1; j < n; j++)           basis[i] = min(basis[i], basis[i] ^ basis[j]);       vector<long long> stuff(n, 0);       for (long long i = 0; i < n; i++) {         long long cnt = 0;         for (long long j = 0; j < m; j++)           if (!good[j]) {             if (basis[i] & (1ll << j)) stuff[i] += (1ll << cnt);             cnt++;           }       }       vector<vector<vector<long long>>> dp(           n, vector<vector<long long>>(n + 1,                                        vector<long long>((1ll << (m - n)), 0)));       dp[0][1][stuff[0]] = dp[0][0][0] = 1;       for (long long i = 1; i < n; i++)         for (long long j = 0; j <= n; j++)           for (long long k = 0; k < (1ll << (m - n)); k++) {             dp[i][j][k] = dp[i - 1][j][k];             if (j) dp[i][j][k] += dp[i - 1][j - 1][k ^ stuff[i]];           }       for (long long i = 0; i <= n; i++)         for (long long j = 0; j < (1ll << (m - n)); j++)           ans[i + __builtin_popcount(j)] += dp[n - 1][i][j];     }     for (long long i = 0; i <= m; i++)       cout << (ans[i] % MOD) * pw[_ - n] % MOD <<    ;     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     while (t--) {       int N;       scanf( %d , &N);       vector<int> a(N + 1);       vector<int> b(N + 1);       int sum = 0;       for (int i = 1; i <= N; ++i) {         scanf( %d , &a[i]);         sum += a[i];         b[i] = a[i];       }       if (sum % N != 0) {         printf( -1 n );         continue;       }       vector<vector<int>> ans;       for (int i = 2; i <= N; ++i) {         if (a[i] % i == 0) {           b[i] -= a[i];           b[1] += a[i];           ans.push_back({i, 1, a[i] / i});         } else {           int m = i - a[i] % i;           b[1] -= m;           b[i] += m;           ans.push_back({1, i, m});           ans.push_back({i, 1, (a[i] + m) / i});           b[i] -= (a[i] + m);           b[1] += (a[i] + m);         }       }       for (int i = 2; i <= N; ++i) {         b[1] -= sum / N;         b[i] += sum / N;         ans.push_back({1, i, sum / N});       }       printf( %d n , (int)ans.size());       for (vector<int>& v : ans) {         printf( %d %d %d n , v[0], v[1], v[2]);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int a[200000];   int b[200000];   int c[200001];   int t[200001];   vector<int> x;   vector<int> ans;   int add(int r, int cr, int d) {     if (c[r] == t[r]) cr--;     t[r] += d;     if (c[r] == t[r]) cr++;     return cr;   }   int main() {     int n, m, p, i, j;     scanf( %d %d %d , &n, &m, &p);     for (i = 0; i < n; i++) scanf( %d , &a[i]);     for (i = 0; i < m; i++) {       scanf( %d , &b[i]);       x.push_back(b[i]);     }     x.push_back(1000000001);     sort(x.begin(), x.end());     x.erase(unique(x.begin(), x.end()), x.end());     int k = x.size();     for (i = 0; i < n; i++) {       int pos = lower_bound(x.begin(), x.end(), a[i]) - x.begin();       if (a[i] == x[pos])         a[i] = pos;       else         a[i] = k - 1;     }     for (i = 0; i < k; i++) {       c[i] = 0;       t[i] = 0;     }     for (i = 0; i < m; i++) {       int pos = lower_bound(x.begin(), x.end(), b[i]) - x.begin();       c[pos]++;     }     int cr = 1;     long long d = (long long)p * (m - 1);     for (i = 0; i < p; i++) {       if (i + d >= n) continue;       for (j = 0; j < m; j++) cr = add(a[i + p * j], cr, 1);       if (cr == k) ans.push_back(i);       j = i + p * m;       while (j < n) {         cr = add(a[j], cr, 1);         cr = add(a[j - p * m], cr, -1);         if (cr == k) ans.push_back(j - p * (m - 1));         j += p;       }       int l = j - p;       for (j = 0; j < m; j++) cr = add(a[l - p * j], cr, -1);     }     sort(ans.begin(), ans.end());     printf( %d n , ans.size());     for (i = 0; i < ans.size(); i++) printf( %d  , ans[i] + 1);     puts(  );     return 0;   }


#include <bits/stdc++.h>   class Counter {    public:     Counter(std::vector<size_t> perm1, std::vector<size_t> perm2)         : size_(perm1.size()) {       std::vector<size_t> inv2(size_, 0);       for (size_t i = 0; i < size_; ++i) {         inv2[perm2[i]] = i;       }       auto& points = perm1;       for (size_t x = 0; x < size_; ++x) {         points[x] = inv2[perm1[x]];       }       size_t nextPowOfTwo = 1;       while (nextPowOfTwo < size_) nextPowOfTwo <<= 1;       segTree_.resize(2 * nextPowOfTwo - 1);       build(points, 0, 0, size_ - 1);     }     int count(size_t minX, size_t maxX, size_t minY, size_t maxY) {       return countAux(0, 0, size_ - 1, minX, maxX, minY, maxY);     }       private:     void build(const std::vector<size_t>& points, int vertex, int from, int to) {       if (from == to) {         segTree_[vertex].push_back(points[from]);       } else {         int middle = from + (to + 1 - from) / 2;         build(points, 2 * vertex + 1, from, middle - 1);         build(points, 2 * vertex + 2, middle, to);         const auto& left = segTree_[2 * vertex + 1];         const auto& right = segTree_[2 * vertex + 2];         segTree_[vertex].reserve(left.size() + right.size());         std::merge(left.begin(), left.end(), right.begin(), right.end(),                    std::back_inserter(segTree_[vertex]));       }     }     int countAux(int vertex, int from, int to, int minX, int maxX, int minY,                  int maxY) {       if (maxX < minX) {         return 0;       }       if (from == minX && to == maxX) {         const auto& range = segTree_[vertex];         auto it1 = std::lower_bound(range.begin(), range.end(), minY);         auto it2 = std::lower_bound(range.begin(), range.end(), maxY + 1);         return it2 - it1;       }       int middle = from + (to + 1 - from) / 2;       int countLeft = countAux(2 * vertex + 1, from, middle - 1, minX,                                std::min(maxX, middle - 1), minY, maxY);       int countRight = countAux(2 * vertex + 2, middle, to,                                 std::max(minX, middle), maxX, minY, maxY);       return countLeft + countRight;     }       private:     size_t size_;     std::vector<std::vector<int>> segTree_;   };   int main() {     size_t size;     ::scanf( %lu , &size);     auto readPerm = [](size_t size) {       std::vector<size_t> perm;       perm.reserve(size);       for (size_t i = 0; i < size; ++i) {         size_t elem;         ::scanf( %lu , &elem);         --elem;         perm.push_back(elem);       }       return perm;     };     auto perm1 = readPerm(size);     auto perm2 = readPerm(size);     Counter counter(std::move(perm1), std::move(perm2));     size_t nQueries;     ::scanf( %lu , &nQueries);     size_t x = 0;     auto f = [&](size_t z) { return (z + x - 1) % size; };     for (size_t i = 0; i < nQueries; ++i) {       size_t a, b, c, d;       ::scanf( %lu %lu %lu %lu , &a, &b, &c, &d);       size_t count = counter.count(std::min(f(a), f(b)), std::max(f(a), f(b)),                                    std::min(f(c), f(d)), std::max(f(c), f(d)));       std::cout << count <<   n ;       x = count + 1;     }   }


#include <bits/stdc++.h>   const long long N = 3000006;   using namespace std;   const long long MOD = 1000000007LL;   template <typename T>   T gcd(T a, T b) {     if (a == 0) return b;     return gcd(b % a, a);   }   template <typename T>   T power(T x, T y, long long m = MOD) {     T ans = 1;     while (y > 0) {       if (y & 1LL) ans = (ans * x) % m;       y >>= 1LL;       x = (x * x) % m;     }     return ans % m;   }   long long prime[N];   long long a[N], f[N];   int32_t main() {     memset(prime, 1, sizeof(prime));     prime[1] = 0;     for (long long i = 2; i < N; i++) {       if (!prime[i]) continue;       for (long long j = i * i; j < N; j += i) prime[j] = 0;     }     long long n;     cin >> n;     for (long long(i) = (0); i < (n); i++) {       cin >> a[i];       ++f[a[i]];     }     long long maxi = 0;     if (n == 1) {       cout <<  1  <<   n ;       cout << a[0];       return 0;     }     for (long long(i) = (0); i < (n); i++) {       if (a[i] == 1) continue;       if (prime[a[i] + 1] && f[1]) {         cout << f[1] + 1 <<   n ;         for (long long(i) = (0); i < (f[1]); i++) cout <<  1  ;         cout << a[i];         return 0;       }     }     if (f[1] >= 2) {       cout << f[1] <<   n ;       for (long long(i) = (0); i < (f[1]); i++) cout <<  1  ;       return 0;     }     for (long long(i) = (0); i < (n - 1); i++) {       for (long long(j) = (i + 1); j < (n); j++) {         if (prime[a[i] + a[j]]) {           cout <<  2  <<   n ;           cout << a[i] <<     << a[j];           return 0;         }       }     }     cout <<  1  <<   n ;     cout << a[0];   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 9;   char s[MAXN];   map<char, char> mp;   int main(int argc, char const *argv[]) {     int n, m;     scanf( %d%d , &n, &m);     scanf( %s , s);     int present = 0;     for (int i = 0; i < n; i++) {       present |= (1 << (s[i] -  a ));     }     for (char c =  a ; c <=  z ; c++)       if (present & (1 << (c -  a ))) {         mp[c] = c;       }     char one, two;     for (int i = 0; i < m; i++) {       scanf(  %c %c , &one, &two);       if (one == two) {         continue;       }       for (auto &it : mp) {         if (it.second == one)           it.second = two;         else if (it.second == two)           it.second = one;       }     }     for (int i = 0; i < n; i++)       if (mp.count(s[i])) {         s[i] = mp[s[i]];       }     puts(s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = (int)1e6 + 17;   const int MOD = (int)1e9 + 7;   const long long oo = (long long)1e18 + 7;   const int INF = (int)999999999;   const int N = (int)1e5 + 17;   const int di[4] = {-1, 0, 1, 0};   const int dj[4] = {0, 1, 0, -1};   inline long long IN() {     long long x = 0, ch = getchar(), f = 1;     while (!isdigit(ch) && (ch !=  - ) && (ch != EOF)) ch = getchar();     if (ch ==  - ) {       f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return x * f;   }   inline void OUT(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x >= 10)       OUT(x / 10), putchar(x % 10 +  0 );     else       putchar(x +  0 );   }   double d, h, v, e, ans;   int main() {     cin >> d >> h >> v >> e;     ans = e - ((4 * v) /                (3.14159265358979323846264338327950288419716939937510 * d * d));     h = -h;     if (ans > -1e4 && ans < 0)       cout <<  YES  << endl << fixed << setprecision(10) << (h / ans);     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target(         avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   long long MOD = 1e9 + 7;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0),         cout << fixed << setprecision(20);     long long t;     cin >> t;     while (t--) {       long long n, p;       cin >> n >> p;       vector<pair<long long, long long> > ans;       for (int i = 0; i < 2 * n + p; i++) {         ans.push_back({i % n, (i + i / n + 1) % n});       }       for (auto i : ans) {         cout << i.first + 1 <<     << i.second + 1 <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   struct scroll {     int pow;     int dmg;     int loc;     bool operator<(const scroll& a) const {       if (dmg > a.dmg)         return true;       else if (dmg == a.dmg && pow < a.pow)         return true;       else         return false;     }   };   struct used_scrollr {     int num;     int time;     bool operator<(const used_scrollr& a) const { return time < a.time; }   };   int main() {     int N, max, reg;     scanf( %d%d%d , &N, &max, &reg);     scroll ary[N];     bool used_scroll[N];     int used_time[N];     for (int i = 0; i < N; ++i) {       int x, y;       scanf( %d%d , &x, &y);       ary[i] = (scroll){x, y, i + 1};       used_scroll[i] = false;     }     sort(ary, ary + N);     int time = 0;     int used_scrolls = 0;     int current_hp = max;     int drain = 0;     while (true) {       current_hp -= drain;       if (current_hp + reg < max)         current_hp += reg;       else         current_hp = max;       if (current_hp <= 0) {         time++;         break;       }       bool used_a_scroll = false;       for (int i = 0; i < N; ++i) {         if (used_scroll[i] == false &&             (((current_hp * 100) / max) +                  ((current_hp * 100) % max == 0 ? 0 : 1) <=              ary[i].pow)) {           used_time[i] = time;           drain += ary[i].dmg;           used_scroll[i] = true;           used_scrolls++;           used_a_scroll = true;           break;         }       }       if ((reg - drain) >= 0 && used_a_scroll == false) break;       time++;     }     if (current_hp <= 0) {       printf( YES n );       printf( %d %d n , time - 1, used_scrolls);       used_scrollr ary2[used_scrolls];       int cnt = 0;       for (int i = 0; i < N; ++i)         if (used_scroll[i])           ary2[cnt++] = (used_scrollr){ary[i].loc, used_time[i]};       sort(ary2, ary2 + used_scrolls);       for (int i = 0; i < used_scrolls; ++i)         printf( %d %d n , ary2[i].time, ary2[i].num);     } else {       printf( NO n );     }   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 100000;   const long long oops = 1LL << 60;   class Ball {    public:     long long value, color;   } arr[MAXN + 5];   long long colorBest[MAXN + 5];   long long n;   void addToTopTwo(vector<pair<long long, int> >& toptwo, long long best,                    long long color) {     if (toptwo.size() != 2)       toptwo.push_back(make_pair(best, color));     else {       long long c, c2;       bool khalas = 0;       for (c = 0; c < 2; c++)         if (toptwo[c].second == color) {           toptwo[c].first = max(toptwo[c].first, best);           khalas = 1;         }       if (!khalas) {         if (toptwo[0].first > toptwo[1].first) {           if (toptwo[1].first < best) toptwo[1] = make_pair(best, color);         } else {           if (toptwo[0].first < best) toptwo[0] = make_pair(best, color);         }       }     }     return;   }   int main() {     long long c, c2;     long long qs;     scanf( %I64d%I64d , &n, &qs);     for (c = 0; c < n; c++) scanf( %I64d , &arr[c].value);     for (c = 0; c < n; c++) scanf( %I64d , &arr[c].color);     for (long long loops = 0; loops < qs; loops++) {       for (c = 0; c <= n; c++) {         colorBest[c] = -oops;       }       long long a, b;       scanf( %I64d%I64d , &a, &b);       long long ret = -oops;       vector<pair<long long, int> > toptwo;       for (c = 0; c < n; c++) {         long long best = b * (long long)arr[c].value;         if (colorBest[arr[c].color] != -oops)           best = max(best, colorBest[arr[c].color] + a * (long long)arr[c].value);         for (c2 = 0; c2 < toptwo.size(); c2++)           if (toptwo[c2].second != arr[c].color)             best = max(best, toptwo[c2].first + b * (long long)arr[c].value);         colorBest[arr[c].color] = max(colorBest[arr[c].color], best);         addToTopTwo(toptwo, best, arr[c].color);         ret = max(ret, best);       }       printf( %I64d n , max(ret, 0LL));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void adskiy_razgon() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   const int mxN = 1e+9 + 7;   const long long INF = 1e+18 + 7;   long long nod(long long a, long long b) {     if (b > a) {       swap(a, b);     }     while (b > 0) {       a %= b;       swap(a, b);     }     return a;   }   long long nok(long long a, long long b) { return a * b / nod(a, b); }   void sp(long long a, double b) { cout << fixed << setprecision(a) << b; }   long long binpow(long long a, long long n) {     if (n == 0) {       return 1;     }     if (n % 2 == 1) {       return binpow(a, n - 1) * a;     } else {       long long b = binpow(a, n / 2);       return b * b;     }   }   void solve() {     int n, m, t;     cin >> n >> m >> t;     cout << ((n - m) * t + m - 1) / m;   }   int main() {     adskiy_razgon();     long long t = 1;     for (int i = 1; i <= t; ++i) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   class SegmentTree {    private:     vector<ll> aint;     vector<ll> lazy;       public:     SegmentTree(int n) {       aint.resize(1 + 4 * n);       lazy.resize(1 + 4 * n);     }     void cleannode(int node, int from, int to) {       int mid = (from + to) / 2;       if (from < to) {         lazy[node * 2] += lazy[node];         lazy[node * 2 + 1] += lazy[node];       }       aint[node] = aint[node] + lazy[node];       lazy[node] = 0;     }     void computenode(int node, int from, int to) {       if (from < to) {         int mid = (from + to) / 2;         aint[node] = max(aint[node * 2], aint[node * 2 + 1]);       }     }     void update(int node, int from, int to, int x, int y, ll val) {       cleannode(node, from, to);       if (from == x && to == y) {         lazy[node] += val;         cleannode(node, from, to);       } else {         int mid = (from + to) / 2;         cleannode(node * 2, from, mid);         cleannode(node * 2 + 1, mid + 1, to);         if (x <= mid)           update(node * 2, from, mid, x, (((mid) < (y)) ? (mid) : (y)), val);         if (mid + 1 <= y)           update(node * 2 + 1, mid + 1, to, (((mid + 1) < (x)) ? (x) : (mid + 1)),                  y, val);         computenode(node, from, to);       }     }     ll query(int node, int from, int to, int x, int y) {       cleannode(node, from, to);       if (from == x && to == y)         return aint[node];       else {         int mid = (from + to) / 2;         if (x <= mid && y <= mid)           return query(node * 2, from, mid, x, y);         else if (mid + 1 <= x && mid + 1 <= y)           return query(node * 2 + 1, mid + 1, to, x, y);         else           return max(query(node * 2, from, mid, x, mid),                      query(node * 2 + 1, mid + 1, to, mid + 1, y));       }     }   };   int const nmax = 200000;   int v[1 + nmax];   vector<pair<int, int>> g[1 + nmax];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> v[i];     for (int i = 1; i <= m; i++) {       int x, y, cost;       cin >> x >> y >> cost;       g[y].push_back({x, cost});     }     SegmentTree aint(n);     for (int i = 1; i <= n; i++) {       ll result = aint.query(1, 0, n, 0, i - 1);       aint.update(1, 0, n, i, i, result);       aint.update(1, 0, n, 0, i - 1, -v[i]);       for (int h = 0; h < g[i].size(); h++) {         int x = g[i][h].first, cost = g[i][h].second;         aint.update(1, 0, n, 0, x - 1, cost);       }     }     cout << aint.query(1, 0, n, 0, n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 333;   int main() {     int n, a1, a2, a3, b1, b2, b3;     cin >> n >> a1 >> b1 >> a2 >> b2 >> a3 >> b3;     int c1 = b1, c2 = b2, c3 = b3;     while (c1 + c2 + c3 > n) {       if (c3 > a3)         c3--;       else if (c2 > a2)         c2--;       else if (c1 > a1)         c1--;     }     cout << c1 <<     << c2 <<     << c3 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, i;     cin >> n >> k;     vector<pair<long long, long long>> v;     vector<long long> inp, p;     vector<long long>::iterator it;     map<long long, long long> m;     for (i = 0; i < n; i++) {       long long x;       cin >> x;       v.push_back(make_pair(x, 0));       inp.push_back(x);     }     for (i = 0; i < n; i++) cin >> v[i].second;     sort(v.begin(), v.end());     int t = 0, u = 0;     long long sum = 0;     for (i = 0; i < n; i++) {       if (t < k) {         for (it = p.begin(); it != p.end(); it++) {           if (v[i].second >= *it) {             p.insert(it, v[i].second);             t++;             break;           }         }         if (it == p.end()) {           p.push_back(v[i].second);           t++;         }         sum += v[i].second;         m[v[i].first] = sum;       } else {         if (u == 1) {           for (it = p.begin(); it != p.end(); it++) {             if (v[i - 1].second >= *it) {               p.insert(it, v[i - 1].second);               sum += v[i - 1].second;               sum -= p.back();               p.pop_back();               break;             }           }         }         m[v[i].first] = sum + v[i].second;         if (u == 0) u = 1;       }     }     for (i = 0; i < n; i++) {       cout << m[inp[i]] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> pref_sum_a;   vector<long long> pref_sum_b;   signed main() {     long long n;     cin >> n;     if (n == 2) {       cout << 3 << endl;       cout << 2 <<     << 1 <<     << 2 << endl;     }     if (n == 3) {       cout << 4 << endl;       cout << 2 <<     << 1 <<     << 3 <<     << 2 << endl;     }     if (n == 4) {       cout << 6 << endl;       cout << 1 <<     << 3 <<     << 2 <<     << 4 <<     << 1 <<     << 3            << endl;     }     if (n > 4) {       cout << n + n / 2 << endl;       for (long long t = 2; t <= n; t += 2) {         cout << t <<    ;       }       for (long long g = 1; g <= n; g += 2) {         cout << g <<    ;       }       for (long long t = 2; t <= n; t += 2) {         cout << t <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int64_t exp(int64_t a, int64_t b) {     if (b == 0) return 1;     int64_t c = exp(a, b / 2);     c = c * c;     if (b % 2 == 1) c = c * a;     return c;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     int64_t ans = 0;     for (int i = 0; i < n; i++) {       int64_t k, a;       cin >> k >> a;       if (a == 1) {         ans = max(ans, k + 1);         continue;       }       int64_t x = 0;       for (int64_t b = 16; b >= 1; b /= 2) {         while (exp(4, b + x) < a) x += b;       }       ans = max(ans, k + x + 1);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 100 * 1000 + 5;   const int INF = 1000 * 1000 * 1000 + 7;   const long long LINF = 1LL * INF * INF;   const int MOD = INF;   const double PI = acos(-1.);   int main() {     ios_base::sync_with_stdio(0);     int n, p;     cin >> n >> p;     int ans = INF;     for (int k = (1); k < (200); ++k) {       long long tmp = n - k * p;       long long x = tmp;       if (tmp < 0) continue;       int cnt = 0;       while (tmp) {         cnt += tmp % 2;         tmp /= 2;       }       if (cnt <= k && k <= x) ans = min(ans, k);     }     if (ans == INF) ans = -1;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int get_index(int i, int j, int k) { return i * 4 + j * 2 + k; }   int diff(int i, int j) { return i != j; }   pair<int, string> input() {     int n;     cin >> n;     string s;     cin >> s;     return make_pair(n, s);   }   int work2(int n, string s) {     int first_diff = 1;     for (; first_diff < n; first_diff++) {       if (s[first_diff - 1] != s[first_diff]) break;     }     if (first_diff == n) return (n + 2) / 3;     s = s.substr(first_diff, n - first_diff) + s.substr(0, first_diff);     int start = 0;     int ans = 0;     for (int i = 1; i < n; i++) {       if (s[i] != s[i - 1]) {         ans += (i - start) / 3;         start = i;       }     }     ans += (n - start) / 3;     return ans;   }   void work() {     pair<int, string> in = input();     int n = in.first;     string s = in.second;     cout << work2(n, s) << endl;   }   int main() {     int t;     cin >> t;     while (t--) {       work();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, s;     cin >> n;     vector<int> x(n);     for (int i = 0; i < n; i++) cin >> x[i];     sort(x.begin(), x.end());     k = n / 2;     s = x[k] - x[0];     for (int i = 1; i < n - k; i++) {       s = min(s, x[k + i] - x[i]);     }     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     long long cnt[1001] = {};     for (long long i = 0; i < n; ++i) {       long long x;       cin >> x;       cnt[x]++;       if (cnt[x] > (n + 1) / 2) {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 0x3ffffffffffff;   int main() {     long long T;     scanf( %lld , &T);     while (T--) {       long long k, n, a, b;       scanf( %lld%lld%lld%lld , &k, &n, &a, &b);       k -= b * n;       if (k <= 0)         printf( -1 n );       else         printf( %lld n , min(n, (k - 1) / (a - b)));     }   }


#include <bits/stdc++.h>   using namespace std;   int dij[4444][4444];   int x[4444], y[4444];   int num[4444];   int main(void) {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d%d , &x[i], &y[i]);       dij[x[i]][y[i]] = dij[y[i]][x[i]] = 1;       num[x[i]]++;       num[y[i]]++;     }     int flag = 0;     int ans = 99999999;     for (int i = 0; i < m; i++) {       for (int j = 1; j <= n; j++) {         if (dij[x[i]][j] && dij[j][y[i]]) {           if (ans > num[x[i]] + num[j] + num[y[i]]) {             ans = num[x[i]] + num[j] + num[y[i]];             flag = 1;           }         }       }     }     if (flag == 0) {       puts( -1 );       return 0;     } else       printf( %d n , ans - 6);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<int> atk, def, ciel;     for (int i = 0; i < n; i++) {       string s;       int x;       cin >> s >> x;       if (s ==  ATK )         atk.push_back(x);       else         def.push_back(x);     }     for (int i = 0; i < m; i++) {       int x;       cin >> x;       ciel.push_back(x);     }     sort(atk.begin(), atk.end());     sort(def.begin(), def.end());     sort(ciel.begin(), ciel.end());     int flag = 1;     if (n >= m) flag = 0;     int ans = 0, i = m - 1, j = 0, sum = 0;     while (i >= 0 && j < atk.size()) {       if (atk[j] > ciel[i]) {         break;       }       sum += max(0, ciel[i] - atk[j]);       ans = max(ans, sum);       i--;       j++;     }     i = m - 1;     j = def.size() - 1;     int ans1 = 0, ans2 = 0;     while (i >= 0 && j >= 0) {       if (ciel[i] <= def[j]) {         flag = 0;         break;       }       i--;       j--;     }     i = 0;     vector<int> temp;     if (flag) {       j = 0;       while (i < m && j < def.size()) {         while (ciel[i] <= def[j]) {           temp.push_back(ciel[i]);           i++;           if (i == m) break;         }         i++;         j++;       }     }     while (i < m) {       temp.push_back(ciel[i]);       i++;     }     j = 0;     i = 0;     sum = 0;     int flag2 = 1;     int ans3 = 0;     while (i < temp.size() && j < atk.size()) {       while (temp[i] < atk[j]) {         ans3 += temp[i];         i++;         if (i == temp.size()) break;       }       if (i == temp.size()) break;       ans1 += temp[i] - atk[j];       i++;       j++;     }     while (i < temp.size()) {       ans3 += temp[i];       i++;     }     if (flag && j == atk.size()) ans1 += ans3;     i = temp.size() - 1;     j = 0;     while (i >= 0 && j < atk.size()) {       if (atk[j] > temp[i]) {         flag2 = 0;         break;       }       sum += max(0, temp[i] - atk[j]);       ans2 = max(ans2, sum);       i--;       j++;     }     if (flag2 && flag) {       while (i >= 0) {         ans2 += temp[i];         i--;       }     }     cout << max(ans1, ans) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const string pocetno =  0000000000 ;   const string oznake =  RGBYW ;   const int maxn = 105;   int N, razlicite, sol = maxn * maxn;   vector<pair<int, int> > V;   set<string> S;   void rijesi() {     for (int maska = 0; maska < (1 << 10) + 1; maska++) {       S.clear();       int tmp = 0;       for (int i = 0; i < 10; i++)         if (maska & (1 << i)) tmp++;       for (int i = 0; i < N; i++) {         string stanje = pocetno;         for (int j = 0; j < 5; j++) {           if (maska & (1 << j) && V[i].first == j) stanje[j] =  1 ;           if (maska & (1 << (j + 5)) && V[i].second == j) stanje[j + 5] =  1 ;         }         S.insert(stanje);       }       if (S.size() == razlicite) sol = min(sol, tmp);     }     printf( %d n , sol);   }   void ucitaj() {     scanf( %d , &N);     for (int i = 0; i < N; i++) {       string s;       cin >> s;       V.push_back(make_pair(oznake.find(s[0]), s[1] -  0  - 1));       S.insert(s);     }     razlicite = S.size();   }   int main(void) {     ucitaj();     rijesi();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int fx[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};   const int fxx[8][2] = {{0, 1}, {0, -1}, {1, 0},  {-1, 0},                          {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};   template <typename T, typename TT>   ostream& operator<<(ostream& s, pair<T, TT> t) {     return s <<  (  << t.first <<  ,  << t.second <<  ) ;   }   template <typename T>   ostream& operator<<(ostream& s, vector<T> t) {     for (int i = 0; i < ((int)(t.size())); i++)       s << t[i] << (i == ((int)(t.size())) - 1 ?   n  :    );     return s;   }   int start, finish, mid;   string answer;   int main() {     cin >> answer;     while (answer ==  start ) {       start = 0;       finish = 1;       while (true) {         cout <<  ?   << start <<     << finish << endl;         cin >> answer;         if (answer ==  x ) {           break;         }         start = finish;         finish <<= 1;       }       while (start < finish - 1) {         mid = (start + finish + 1) >> 1;         cout <<  ?   << start <<     << mid << endl;         cin >> answer;         if (answer[0] ==  x )           finish = mid;         else           start = mid;       }       cout <<  !   << finish << endl;       cin >> answer;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v(2 << n);     int size = 2 << n;     for (int i = (2); i < (int)(size); ++i) cin >> v[i];     int ans = 0;     for (int i = size - 1; i >= 2; i -= 2) {       v[i / 2] += max(v[i], v[i - 1]);       ans += abs(v[i] - v[i - 1]);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, A, B, C, T;   int temp[1005];   int main() {     cin >> n >> A >> B >> C >> T;     long long ans = 0;     for (int i = 1; i <= n; i++) cin >> temp[i];     ans = n * A;     if (C > B) {       for (int i = 1; i <= n; i++) ans += (C - B) * (T - temp[i]);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100100;   const long long MOD = 1000000007;   const double EBS = 1e-7;   int dX[] = {0, 0, 1, -1};   int dY[] = {1, -1, 0, 0};   long long GCD(long long num, long long ones) {     return !ones ? num : GCD(ones, num % ones);   }   const int L = 17;   vector<int> adj[N];   vector<int> Root;   vector<int> level[N];   int depth[N], ID[N], rID[N], dp[L + 1][N], currID = 1, n, m, k, WantedNode;   void dfs(int cur, int par) {     dp[0][cur] = par;     ID[cur] = currID++;     rID[ID[cur]] = cur;     level[depth[cur]].push_back(ID[cur]);     for (auto x : adj[cur])       if (x != par) depth[x] = depth[cur] + 1, dfs(x, cur);   }   inline int getKthAncestor(int u, int k) {     int d = depth[u] - k;     for (int j = L; j >= 0; --j) {       int nu = dp[j][u];       if (!nu) continue;       if (depth[nu] == d)         return nu;       else if (depth[nu] > d)         u = nu;     }     return 0;   }   inline int BSL(int d) {     int l = 0, r = (level[d].size()) - 1, mid;     while (l < r) {       mid = l + (r - l) / 2;       int node = getKthAncestor(rID[level[d][mid]], k);       node = ID[node];       if (node >= WantedNode)         r = mid;       else         l = mid + 1;     }     return r;   }   inline int BSR(int d) {     int l = 0, r = (level[d].size()) - 1, mid;     while (l < r) {       mid = l + (r - l + 1) / 2;       int node = getKthAncestor(rID[level[d][mid]], k);       node = ID[node];       if (node <= WantedNode)         l = mid;       else         r = mid - 1;     }     return l;   }   int main() {     scanf( %d , &n);     int p, v;     for (int i = 0; i < n; ++i) {       scanf( %d , &p);       if (p)         adj[p].push_back(i + 1), adj[i + 1].push_back(p);       else         Root.push_back(i + 1);     }     for (auto x : Root) dfs(x, 0);     for (int j = 1; j <= L; ++j)       for (int i = 0; i < N; ++i)         dp[j][i] = (dp[j - 1][i] == -1 ? -1 : dp[j - 1][dp[j - 1][i]]);     scanf( %d , &m);     while (m--) {       scanf( %d , &v);       scanf( %d , &k);       WantedNode = getKthAncestor(v, k);       if (WantedNode) {         WantedNode = ID[WantedNode];         printf( %d  , BSR(depth[v]) - BSL(depth[v]));       } else         printf( 0  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M;   long long Ans;   struct rec {     int w, h, s, k;     rec() {}     rec(int a, int b, int c, int i) {       w = a;       h = b;       s = c;       k = i;     }   } P[1010], Q[1010];   int vis[1010];   bool cmp_h(const rec &a, const rec &b) { return a.h > b.h; }   bool cmp_s(const rec &a, const rec &b) { return a.s > b.s; }   long long sumw(int maxh) {     long long sum = 0;     int cnt = 0;     for (int i = 1; i <= N; ++i) {       if (P[i].h <= maxh) break;       int s = 1e10;       if (P[i].w <= maxh && cnt < M) {         ++cnt;         vis[P[i].k] = maxh;         s = P[i].h;       }       sum += s;     }     for (int i = 1; i <= N; ++i)       if (vis[Q[i].k] != maxh) {         int s = Q[i].w;         if (Q[i].w <= maxh && cnt < M && s > Q[i].h) {           ++cnt;           vis[Q[i].k] = maxh;           s = Q[i].h;         }         sum += s;       }     return sum;   }   int main() {     scanf( %d , &N);     M = N / 2;     for (int i = 1; i <= N; ++i) {       int w, h;       scanf( %d%d , &w, &h);       Q[i] = P[i] = rec(w, h, w - h, i);     }     sort(P + 1, P + N + 1, cmp_h);     sort(Q + 1, Q + N + 1, cmp_s);     Ans = 1e9;     for (int hi = 1; hi <= 1000; ++hi) {       Ans = min(Ans, (long long)hi * sumw(hi));     }     printf( %lld n , Ans);   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int ans = 0;     char ch = getchar();     while (!isdigit(ch)) {       ch = getchar();     }     while (isdigit(ch)) {       ans = (ans << 3) + (ans << 1) + (ch ^ 48), ch = getchar();     }     ans = ans + 0 + 0;     return ans;   }   int first[100005], n, cnt, dep[100005];   double ans = 0;   struct edge {     int v, next;   } e[100005 << 1];   inline void add(int u, int v) {     e[++cnt].v = v, e[cnt].next = first[u], first[u] = cnt;   }   inline void dfs(int p, int fa) {     for (int i = first[p]; i; i = e[i].next) {       int v = e[i].v;       if (v == fa) continue;       dep[v] = dep[p] + 1, dfs(v, p);     }   }   int main() {     n = read();     for (int i = 1; i < n; ++i) {       int u = read(), v = read();       add(u, v), add(v, u);     }     dep[1] = 1, dfs(1, 1);     for (int i = 1; i <= n; ++i) ans += 1.0 / (1.0 * dep[i]);     printf( %.20lf , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     vector<int> answer;     if (n == 1000000) {       cout <<  1 n1000000 n ;     } else {       while (n) {         int p = n;         string w;         while (p) {           if (p % 10 == 0) {             w.insert(w.begin(),  0 );           } else {             w.insert(w.begin(),  1 );           }           p = p / 10;         }         int x = atoi(&w[0]);         answer.push_back(x);         n = n - x;       }       cout << answer.size() <<   n ;       for (int i = 0; i < answer.size(); i++) {         cout << answer[i] <<    ;       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 505;   long long d[N][N];   long long g[N][N];   int per[N];   long long ans[N];   int n;   void upd(int q) {     for (int j = q; j < N; j++) {       g[per[q]][per[j]] = d[per[q]][per[j]];       g[per[j]][per[q]] = d[per[j]][per[q]];     }     for (int j = q; j <= n; j++) {       for (int i = q; i <= n; i++) {         g[per[q]][per[j]] =             min(g[per[q]][per[j]], g[per[q]][per[i]] + g[per[i]][per[j]]);       }     }     for (int j = q; j <= n; j++) {       for (int i = q; i <= n; i++) {         g[per[j]][per[q]] =             min(g[per[j]][per[q]], g[per[j]][per[i]] + g[per[i]][per[q]]);       }     }     for (int i = q; i <= n; i++) {       for (int j = q; j <= n; j++) {         g[per[i]][per[j]] =             min(g[per[i]][per[j]], g[per[i]][per[q]] + g[per[q]][per[j]]);       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         cin >> d[i][j];         g[i][j] = (i != j) * (int)(1e9 + 9);       }     }     for (int i = 1; i <= n; i++) {       cin >> per[i];     }     for (int i = n; i >= 1; i--) {       upd(i);       for (int j = i; j <= n; j++) {         for (int z = i; z <= n; z++) {           ans[i] += g[per[j]][per[z]];         }       }     }     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void splay(int &v) {     v = 0;     char c = 0;     int p = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) p = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       v = (v << 3) + (v << 1) + c -  0 ;       c = getchar();     }     v *= p;   }   struct Edge {     int to, next;     int col;   } edge[200010];   int first[100010], size;   void addedge(int x, int y, int z) {     size++;     edge[size].to = y;     edge[size].next = first[x];     first[x] = size;     edge[size].col = z;   }   int n, m, tmp;   bool f, flag;   int cnt = 100001, ans[100010], p[100010];   int C[100010];   bool vis[100010];   int ff[100010], sum;   void dfs(int now, int col) {     ff[++sum] = now;     vis[now] = 1;     C[now] = col;     if (C[now]) tmp++;     for (int u = first[now]; u; u = edge[u].next) {       if (vis[edge[u].to]) {         if (edge[u].col) {           if (C[edge[u].to] == C[now]) f = 0;         } else {           if (C[edge[u].to] != C[now]) f = 0;         }       } else {         dfs(edge[u].to, col ^ edge[u].col);       }     }   }   void get() {     f = 1;     int _cnt = 0;     memset(vis, 0, sizeof vis);     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         sum = 0;         tmp = 0;         dfs(i, 0);         if (f && tmp <= sum - tmp) {           for (int i = 1; i <= sum; i++) {             if (C[ff[i]]) {               p[++_cnt] = ff[i];             }           }         }         if (f && sum - tmp < tmp) {           for (int i = 1; i <= sum; i++) {             if (!C[ff[i]]) {               p[++_cnt] = ff[i];             }           }         }       }     }     if (f) {       if (_cnt <= cnt) {         for (int i = 1; i <= _cnt; i++) {           ans[i] = p[i];         }         cnt = _cnt;         flag = true;       }     }   }   int main() {     splay(n), splay(m);     for (int i = 1; i <= m; i++) {       int x, y, z;       char op[5];       splay(x), splay(y), scanf( %s , op);       if (op[0] ==  B )         z = 0;       else         z = 1;       addedge(x, y, z), addedge(y, x, z);     }     get();     for (int i = 1; i <= size; i++) {       edge[i].col ^= 1;     }     get();     if (flag) {       printf( %d n , cnt);       for (int i = 1; i <= cnt; i++) {         printf( %d  , ans[i]);       }     } else       puts( -1 );   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int dp[N][310], c[N][310], lst[N], a[N], b[N];   vector<int> v[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m, s, e;     cin >> n >> m >> s >> e;     for (int i = 0; i < n; i++) {       cin >> a[i + 1];     }     for (int i = 0; i < m; i++) {       cin >> b[i + 1];       v[b[i + 1]].push_back(i + 1);     }     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= 300; j++) {         dp[i][j] = -1;       }       lst[i] = -1;     }     lst[0] = 0;     for (int i = 1; i <= n; i++) {       for (int j = min(300, n); j >= 1; j--) {         if (lst[j - 1] == -1 || v[a[i]].size() == 0) continue;         if (v[a[i]].back() <= lst[j - 1]) continue;         int ind = upper_bound(v[a[i]].begin(), v[a[i]].end(), lst[j - 1]) -                   v[a[i]].begin();         dp[i][j] = v[a[i]][ind];         c[i][j] = e * j + dp[i][j] + i;         if (lst[j] == -1)           lst[j] = v[a[i]][ind];         else           lst[j] = min(v[a[i]][ind], lst[j]);       }     }     int ans = n;     for (int i = n; i >= 0; i--) {       if (lst[i] != -1) {         ans = i;         break;       }     }     for (int j = ans; j >= 1; j--) {       int k = 1000000000;       for (int i = 1; i <= n; i++) {         if (dp[i][j] != -1) {           k = min(k, c[i][j]);         }       }       if (k <= s) {         cout << j;         return 0;       }     }     cout << 0;   }


#include <bits/stdc++.h>   using namespace std;   map<string, int> M;   map<int, string> MM;   vector<int> adj[20];   int n, m;   bool val(vector<int> &v) {     for (int i = 0; i < v.size(); i++) {       for (int j = 0; j < v.size(); j++) {         if (i == j) continue;         for (int k = 0; k < adj[v[i]].size(); k++) {           if (v[j] == adj[v[i]][k]) return 0;         }       }     }     return 1;   }   void solve() {     int maxi = 0;     vector<int> v, sol;     for (int i = 0; i < (1 << n); i++) {       v.clear();       for (int j = 0; j < n; j++) {         if (i & (1 << j)) v.push_back(j);       }       if (val(v)) {         if (v.size() > maxi) {           maxi = v.size();           sol = v;         }       }     }     cout << maxi << endl;     vector<string> name;     for (int i = 0; i < sol.size(); i++) name.push_back(MM[sol[i]]);     sort(name.begin(), name.end());     for (int i = 0; i < name.size(); i++) cout << name[i] << endl;   }   int main() {     cin >> n >> m;     string s, s1;     for (int i = 0; i < n; i++) {       cin >> s;       M[s] = i;       MM[i] = s;     }     for (int i = 0; i < m; i++) {       cin >> s >> s1;       adj[M[s]].push_back(M[s1]);     }     solve();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e4, INF = int(1e9) + 1, mod = 1e9 + 7;   const long long BIG = 1e16;   int n, d, a[N + 5], dp[N + 5][250 * 2 + 5];   bool w[N + 5][250 * 2 + 5];   int rec(int v, int l) {     if (v > N) {       return 0;     }     int l1 = l - (d - 250);     if (w[v][l1]) return dp[v][l1];     int ans = 0;     for (int i = -1; i <= 1; i++) {       if (l + i) ans = max(ans, rec(v + l + i, l + i));     }     w[v][l1] = 1;     ans += a[v];     return dp[v][l1] = ans;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> d;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       a[x]++;     }     cout << rec(d, d);   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (1 << 29);   const int INFF = 0x7fffffff;   const long long LINF = (1ll << 60);   const long long LINFF = 0x7fffffffffffffff;   const long double PI = 3.14159265359;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   long long rnd(long long a, long long b) {     return uniform_int_distribution<long long>(a, b)(rng);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string a, b;       cin >> a >> b;       bool ans = true;       bool change[300][300] = {};       for (int i = 0; i < n; i++) {         if (a[i] != b[i] && a[i] > b[i]) ans = false;         if (a[i] != b[i]) change[a[i]][b[i]] = true;       }       int cnt = 0;       for (int c =  a ; c <=  t ; c++) {         for (int d = c + 1; d <=  t ; d++) {           if (change[c][d] == 0) continue;           cnt += change[c][d];           for (int e = d + 1; e <=  t ; e++) {             change[d][e] += change[c][e];           }           break;         }       }       if (ans == false) cnt = -1;       cout << cnt <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unordered_set<string> has_handle;   unordered_set<string> is_new;   unordered_map<string, string> handle;   vector<string> handles_new;   vector<string> handles_old;   void solve(string old) {     if (is_new.count(old)) return;     handles_old.push_back(old);     string temp;     while (true) {       temp = handle[old];       if (has_handle.count(temp) == 0) break;       old = temp;     }     handles_new.push_back(temp);   }   int main() {     int q;     cin >> q;     string old_handle[q], new_handle[q];     for (int i = 0; i < q; i++) {       cin >> old_handle[i] >> new_handle[i];       has_handle.insert(old_handle[i]);       is_new.insert(new_handle[i]);       handle[old_handle[i]] = new_handle[i];     }     for (int i = 0; i < q; i++) solve(old_handle[i]);     int cnt = handles_new.size();     cout << cnt << endl;     for (int i = 0; i < cnt; i++)       cout << handles_old[i] <<     << handles_new[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int i, j, n;     set<long long int> s;     cin >> n;     for (i = 0; i < n; i++) {       cin >> j;       if (j != 0) {         s.insert(j);       }     }     cout << s.size() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[200000 + 1];   struct info {     int sum, prop;   } t[3 * 200000 + 3];   void build(int node, int b, int e) {     if (b >= e) {       if (b == e) t[node].sum = a[b];       return;     }     int left = node << 1;     int right = left | 1;     int mid = (b + e) >> 1;     build(left, b, mid);     build(right, mid + 1, e);     t[node].sum = t[left].sum + t[right].sum;   }   void update(int node, int b, int e, int i, int j) {     if (i > e || j < b) return;     if (b > e) return;     if (b >= i && e <= j) {       t[node].sum += ((e - b + 1) * 1);       t[node].prop += 1;       return;     }     int left = node << 1;     int right = left | 1;     int mid = (b + e) >> 1;     update(left, b, mid, i, j);     update(right, mid + 1, e, i, j);     t[node].sum = t[left].sum + t[right].sum + (e - b + 1) * t[node].prop;   }   int query(int node, int b, int e, int pos, int carry = 0) {     if (pos < b || e < pos) return 0;     if (b > e) return 0;     if (b == pos && pos == e) return t[node].sum + carry * (e - b + 1);     int left = node << 1;     int right = left | 1;     int mid = (b + e) >> 1;     int p1 = query(left, b, mid, pos, carry + t[node].prop);     int p2 = query(right, mid + 1, e, pos, carry + t[node].prop);     return p1 + p2;   }   int chk[200000 + 1];   int main() {     int n, k, q, i, l, r;     cin >> n >> k >> q;     for (i = 0; i < n; i++) {       scanf( %d %d , &l, &r);       update(1, 1, 200000, l, r);     }     for (i = 1; i <= 200000; i++) {       if (query(1, 1, 200000, i) >= k) chk[i] = 1;     }     for (i = 1; i <= 200000; i++) chk[i] += chk[i - 1];     for (i = 0; i < q; i++) {       scanf( %d %d , &l, &r);       cout << chk[r] - chk[l - 1] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct RTC {};   const int maxn = 123456 + 5;   int n;   int root;   bool humans[maxn];   vector<int> g_tmp[maxn], g[maxn];   ;   bool cut(int u, int p = -1) {     bool ret = humans[u];     for (int v : g_tmp[u]) {       if (v == p) continue;       if (cut(v, u)) {         ret = true;         g[u].push_back(v);       }     }     return ret;   }   int cnt[maxn];   int deep[maxn];   void count(int u) {     cnt[u] = 1;     deep[u] = 0;     for (int v : g[u]) {       count(v);       cnt[u] += cnt[v];       deep[u] = max(deep[u], 1 + deep[v]);     }   }   int maxlen = -1, id = -1;   void solve(int u, int up) {     if (humans[u]) {       int res = max(deep[u], up);       if (res > maxlen) {         maxlen = res;         id = u;       } else if (res == maxlen) {         id = min(id, u);       }     }     if (((int)(g[u]).size()) > 0) {       int down_v = 0;       for (int i = 1; i < ((int)(g[u]).size()); i++)         if (deep[g[u][i]] > deep[g[u][down_v]]) down_v = i;       if (up >= (deep[g[u][down_v]] + 1)) {         for (int v : g[u]) solve(v, up + 1);       } else {         for (int i = 0; i < (((int)(g[u]).size())); i++) {           if (i == down_v) continue;           solve(g[u][i], deep[g[u][down_v]] + 2);         }         int second_down_v = -1;         for (int i = 0; i < (((int)(g[u]).size())); i++) {           if (i == down_v) continue;           if (second_down_v == -1 || deep[g[u][i]] > deep[g[u][second_down_v]])             second_down_v = i;         }         if (second_down_v == -1 || up >= (deep[g[u][second_down_v]] + 1))           solve(g[u][down_v], up + 1);         else           solve(g[u][down_v], deep[g[u][second_down_v]] + 2);       }     }   }   int N;   int main() {     int m;     scanf( %d %d , &n, &m);     for (int i = 0; i < (n - 1); i++) {       int u, v;       scanf( %d %d , &u, &v);       g_tmp[u].push_back(v);       g_tmp[v].push_back(u);     }     while (m--) {       int u;       scanf( %d , &u);       humans[u] = true;       root = u;     }     cut(root);     count(root);     N = cnt[root];     solve(root, 0);     int arcos = N - 1;     printf( %d n%d n , id, 2 * arcos - maxlen);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   long long get(long long x, long long y) {     if (x <= y * 2) return 0;     long long s1 = 1, s2 = 0, p1 = x, p2 = x - 1, ans = 0;     while (p2 >= y * 2) {       if (p2 == y * 2) return s1 + ans;       ans += s1 + s2;       if (p1 & 1)         s1 = s1 * 2 + s2;       else         s2 = s2 * 2 + s1;       p1 /= 2;       p2 = p1 - 1;     }     return ans;   }   long long solve(long long l, long long r, long long x, long long k) {     long long mid = (l + r) / 2;     if (k == 1) return mid;     long long X = get(mid - l, x), Y = get(r - mid, x + 1);     if (k > X + Y + 1) return solve(mid + 1, r, x, k - X - 1);     return solve(l, mid - 1, x, k - Y - 1);   }   signed main() {     scanf( %lld%lld , &n, &k);     if (k == 1) {       puts( 1 );       return 0;     }     if (k == 2) {       printf( %lld n , n);       return 0;     }     n -= 2;     k -= 2;     long long l = 0, r = n;     while (l < r) {       long long mid = (l + r + 1) / 2;       if (get(n, mid) < k)         r = mid - 1;       else         l = mid;     }     printf( %lld n , 1 + solve(1, n, l, k));   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 2e5 + 5;   long long int a[maxN], b[maxN];   int n;   void solve() {     cin >> n;     set<pair<long long int, int>> s;     int count = n;     for (int i = 0; i < n; i++) {       b[i] = 1;       cin >> a[i];       s.insert({a[i], i});     }     while (!s.empty()) {       auto it1 = *(s.begin());       s.erase(s.begin());       if (s.empty()) break;       auto it2 = *(s.begin());       if (it1.first == it2.first) {         count--;         s.erase(s.begin());         s.insert({2 * it2.first, it2.second});         a[it2.second] = 2 * it2.first;         b[it1.second] = 0;       }     }     cout << count << endl;     for (int i = 0; i < n; i++) {       if (b[i]) cout << a[i] <<    ;     }   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     srand(chrono::high_resolution_clock::now().time_since_epoch().count());     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n;       scanf( %d , &n);       vector<int> a(n);       for (int i = 0; (i) < (int)(n); (i)++) {         scanf( %d , &a[i]);       }       queue<int> que;       vector<int> ans;       for (int i = 0; (i) < (int)(n); (i)++) {         if (i == 0 || a[i - 1] < a[i]) {           ans.push_back(a[i]);           int prev = (i == 0 ? 0 : a[i - 1]);           prev++;           while (prev != a[i]) {             que.push(prev);             prev++;           }         } else {           if (que.empty()) {             printf( -1 n );             goto end;           }           ans.push_back(que.front());           que.pop();         }       }       assert(ans.size() == n);       for (int i = 0; (i) < (int)(n); (i)++) {         printf( %d%c , ans[i], i == n - 1 ?   n  :    );       }     end:;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[307][307];   inline bool check(const int& i, const int& j) {     return i >= 0 && i < n && j >= 0 && j < m;   }   int cnt_neighbors(const int& i, const int& j) {     int res = 0;     if (check(i - 1, j)) res++;     if (check(i, j + 1)) res++;     if (check(i + 1, j)) res++;     if (check(i, j - 1)) res++;     return res;   }   int main() {     int tc;     scanf( %d , &tc);     while (tc--) {       scanf( %d %d , &n, &m);       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) scanf( %d , &a[i][j]);       bool flag = 1;       for (int i = 0; i < n && flag; i++)         for (int j = 0; j < m && flag; j++) {           int tmp = cnt_neighbors(i, j);           if (a[i][j] > tmp)             flag = 0;           else             a[i][j] = tmp;         }       if (flag) {         puts( YES );         for (int i = 0; i < n; i++) {           for (int j = 0; j < m; j++) printf( %d  , a[i][j]);           puts(  );         }       } else         puts( NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000 + 2;   double x[4], y[4], r[4];   double dx, dy;   double Fun(double dx, double dy) {     double ap[4];     for (int i = 0; i < 3; i++) {       ap[i] =           sqrt(((x[i] - dx) * (x[i] - dx)) + ((y[i] - dy) * (y[i] - dy))) / r[i];     }     double res = 0.0;     for (int i = 0; i < 3; i++) {       res += ((ap[i] - ap[(i + 1) % 3]) * (ap[i] - ap[(i + 1) % 3]));     }     return res;   }   int main() {     dx = dy = 0.0;     for (int i = 0; i < 3; i++) {       scanf( %lf%lf%lf , &x[i], &y[i], &r[i]);       dx += x[i] / 3;       dy += y[i] / 3;     }     double i = 1.0;     while (i > 1e-5) {       if (Fun(dx + i, dy) < Fun(dx, dy))         dx += i;       else if (Fun(dx - i, dy) < Fun(dx, dy))         dx -= i;       else if (Fun(dx, dy + i) < Fun(dx, dy))         dy += i;       else if (Fun(dx, dy - i) < Fun(dx, dy))         dy -= i;       else         i *= 0.75;     }     if (Fun(dx, dy) < 1e-5) printf( %.5lf %.5lf n , dx, dy);     return 0;   }


#include<bits/stdc++.h>   using namespace std;      typedef pair<int,int> pii;   typedef pair<string,int> psi;   typedef pair<int,string> pis;   typedef array<int,2> aii;   typedef array<int,3> aiii;   typedef array<int,4> aiiii;   typedef unsigned long long ull;   typedef long long int ll;   typedef array<ll,2> all;   typedef array<ll,3> alll;   typedef array<ll,4> allll;      #define pb push_back   #define ff first   #define ss second   #define MAX 200005   #define MOD 1000000007   #define INF 1e9   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   vector<aiii>adj[MAX];   int xMove[] = { 0,1,0,-1,1,1,-1,-1, 2, 2, -2, -2, 1, 1, -1, -1 };   int yMove[] = { 1,0,-1,0,1,-1,1,-1, 1, -1, 1, -1, 2, -2, 2, -2 };   string s;      int dp[MAX][2],n;      int solve(int i, int p)   {       if(i==n)           return 0;       if(dp[i][p]!=-1)           return dp[i][p];          int ans=0;       if(s[i]== 1 )       {           if(p==0)               ans=1+solve(i+1,1);       }       else if(s[i]== 0 )       {           if(p==1)               ans=1+solve(i+1,0);       }       else       {           if(p==0)               ans=1+solve(i+1,1);           else ans=1+solve(i+1,0);       }          return dp[i][p]=ans;   }   int main()   {       //freopen( input.in , r ,stdin);       //freopen( output.txt , w ,stdout);       cin.tie(0),cout.tie(0);       ios_base::sync_with_stdio(0);       cout.setf(ios::fixed);       cout.precision(10);       int TC=1;       int m,k,q;          cin>>TC;       for(int t1=1; t1<=TC; t1++)       {           cin>>s;           n=s.size();           for(int i=0;i<s.size();i++)               dp[i][0]=-1,dp[i][1]=-1;              ll ans=0;           for(int i=0;i<n;i++)           {               if(s[i]== 0 )                   ans+=1+solve(i+1,0);               else if(s[i]== 1 )                   ans+=1+solve(i+1,1);               else ans+=max(1+solve(i+1,0),1+solve(i+1,1));           }              cout<<ans<<  n ;       }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n & 1) {       cout << (n / 2);     } else {       cout << (n / 2) - 1;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int n, m;       cin >> n >> m;       if (n % m == 0)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }