#include <bits/stdc++.h>   template <typename T>   class IntegerIterator {    public:     using value_type = T;     using difference_type = std::ptrdiff_t;     using pointer = T *;     using reference = T;     using iterator_category = std::input_iterator_tag;     explicit IntegerIterator(T value) : value(value) {}     IntegerIterator &operator++() {       ++value;       return *this;     }     IntegerIterator operator++(int) {       IntegerIterator copy = *this;       ++value;       return copy;     }     IntegerIterator &operator--() {       --value;       return *this;     }     IntegerIterator operator--(int) {       IntegerIterator copy = *this;       --value;       return copy;     }     T operator*() const { return value; }     bool operator==(IntegerIterator rhs) const { return value == rhs.value; }     bool operator!=(IntegerIterator rhs) const { return !(*this == rhs); }       private:     T value;   };   template <typename T>   class IntegerRange {    public:     IntegerRange(T begin, T end) : begin_(begin), end_(end) { ; }     IntegerIterator<T> begin() const { return IntegerIterator<T>(begin_); }     IntegerIterator<T> end() const { return IntegerIterator<T>(end_); }       private:     T begin_;     T end_;   };   template <typename T>   class ReversedIntegerRange {     using IteratorType = std::reverse_iterator<IntegerIterator<T>>;       public:     ReversedIntegerRange(T begin, T end) : begin_(begin), end_(end) { ; }     IteratorType begin() const {       return IteratorType(IntegerIterator<T>(begin_));     }     IteratorType end() const { return IteratorType(IntegerIterator<T>(end_)); }       private:     T begin_;     T end_;   };   template <typename T>   IntegerRange<T> range(T to) {     return IntegerRange<T>(0, to);   }   template <typename T>   IntegerRange<T> range(T from, T to) {     return IntegerRange<T>(from, to);   }   template <typename T>   IntegerRange<T> inclusiveRange(T to) {     return IntegerRange<T>(0, to + 1);   }   template <typename T>   IntegerRange<T> inclusiveRange(T from, T to) {     return IntegerRange<T>(from, to + 1);   }   template <typename T>   ReversedIntegerRange<T> downrange(T from) {     return ReversedIntegerRange<T>(from, 0);   }   template <typename T>   ReversedIntegerRange<T> downrange(T from, T to) {     return ReversedIntegerRange<T>(from, to);   }   template <typename T>   ReversedIntegerRange<T> inclusiveDownrange(T from) {     return ReversedIntegerRange<T>(from + 1, 0);   }   template <typename T>   ReversedIntegerRange<T> inclusiveDownrange(T from, T to) {     return ReversedIntegerRange<T>(from + 1, to);   }   using namespace std;   class CYouAreGivenAWASDString {    public:     void solve(std::istream &in, std::ostream &out) {       int t;       in >> t;       while (t--) {         string str;         in >> str;         int n = str.size();         vector<int> maxx1(n + 1), minx1(n + 1), maxy1(n + 1), miny1(n + 1),             maxx2(n + 1), maxy2(n + 1), minx2(n + 1), miny2(n + 1);         int x = 0, y = 0;         for (int i : range(n)) {           if (str[i] ==  W ) {             y++;           } else if (str[i] ==  S ) {             y--;           } else if (str[i] ==  A ) {             x--;           } else {             x++;           }           minx1[i + 1] = min(minx1[i], x);           maxx1[i + 1] = max(maxx1[i], x);           miny1[i + 1] = min(miny1[i], y);           maxy1[i + 1] = max(maxy1[i], y);         }         minx2[n] = maxx2[n] = x;         miny2[n] = maxy2[n] = y;         for (int i : downrange(n)) {           if (str[i] ==  W ) {             y--;           } else if (str[i] ==  S ) {             y++;           } else if (str[i] ==  A ) {             x++;           } else {             x--;           }           minx2[i] = min(minx2[i + 1], x);           maxx2[i] = max(maxx2[i + 1], x);           miny2[i] = min(miny2[i + 1], y);           maxy2[i] = max(maxy2[i + 1], y);         }         long long res =             (long long)(maxx1[n] - minx1[n] + 1) * (maxy1[n] - miny1[n] + 1);         for (int i : inclusiveRange(0, n)) {           for (int j : range(4)) {             int dx = 0, dy = 0;             if (j % 2 == 0) {               if (j / 2) {                 dx = 1;               } else {                 dx = -1;               }             } else {               if (j / 2) {                 dy = 1;               } else {                 dy = -1;               }             }             int maxX = max(maxx1[i], maxx2[i] + dx),                 minX = min(minx1[i], minx2[i] + dx),                 maxY = max(maxy1[i], maxy2[i] + dy),                 minY = min(miny1[i], miny2[i] + dy);             res = min(res, (long long)(maxX - minX + 1) * (maxY - minY + 1));           }         }         out << res <<   n ;       }     }     void setup() {}   };   int main() {     std::ios_base::sync_with_stdio(false);     CYouAreGivenAWASDString solver;     solver.setup();     std::istream &in(std::cin);     std::ostream &out(std::cout);     in.tie(nullptr);     out << std::fixed;     out.precision(20);     solver.solve(in, out);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int a = 1, l = -1, r = -1;     string s;     for (int i = 1; i <= 30; i++) {       cout <<  ?   << (1 << i) <<     << (1 << (i - 1)) << endl;       cin >> s;       if (s ==  x ) {         continue;       } else {         l = (1 << (i - 1)) + 1;         r = (1 << i);         break;       }     }     if (r == 2) {       cout <<  ! 2  << endl;       return;     } else if (l == -1) {       cout <<  ! 1  << endl;       return;     }     int GUESS1 = r;     l = 0, r = r >> 1;     int md, ans;     while (l < r) {       md = (l + r) >> 1;       cout <<  ?   << GUESS1 <<     << md << endl;       cin >> s;       if (s ==  x ) {         l = md + 1;         ans = md;       } else {         r = md;       }     }     cout <<  !   << GUESS1 - ans << endl;   }   int32_t main() {     string now;     while (cin >> now) {       if (now ==  end ) break;       solve();     }     return 0;   }


#include <bits/stdc++.h>   int a[128][128], v[128], cor[128], bucket[128];   int m, n;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; ++i) {       scanf( %d , &v[i]);       cor[i] = 1;       for (int j = 2; j <= n; ++j) {         int x;         scanf( %d , &x);         if (x > v[i]) {           v[i] = x;           cor[i] = j;         }       }     }     for (int i = 1; i <= m; ++i) {       bucket[cor[i]]++;     }     int rez = bucket[1];     int cand = 1;     for (int i = 2; i <= n; ++i) {       if (bucket[i] > rez) {         rez = bucket[i];         cand = i;       }     }     printf( %d n , cand);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Mo = 998244353;   const int N = 2e5 + 50;   const int md = 998244353;   inline void add(int &x, int y) {     x += y;     if (x >= md) {       x -= md;     }   }   inline void sub(int &x, int y) {     x -= y;     if (x < 0) {       x += md;     }   }   inline int mul(int x, int y) { return (long long)x * y % md; }   inline int power(int x, int y) {     int res = 1;     for (; y; y >>= 1, x = mul(x, x)) {       if (y & 1) {         res = mul(res, x);       }     }     return res;   }   inline int inv(int a) {     a %= md;     if (a < 0) {       a += md;     }     int b = md, u = 0, v = 1;     while (a) {       int t = b / a;       b -= t * a;       swap(a, b);       u -= t * v;       swap(u, v);     }     if (u < 0) {       u += md;     }     return u;   }   namespace ntt {   int base = 1, root = -1, max_base = -1;   vector<int> rev = {0, 1}, roots = {0, 1};   void init() {     int temp = md - 1;     max_base = 0;     while (temp % 2 == 0) {       temp >>= 1;       ++max_base;     }     root = 2;     while (true) {       if (power(root, 1 << max_base) == 1 &&           power(root, 1 << max_base - 1) != 1) {         break;       }       ++root;     }   }   void ensure_base(int nbase) {     if (max_base == -1) {       init();     }     if (nbase <= base) {       return;     }     assert(nbase <= max_base);     rev.resize(1 << nbase);     for (int i = 0; i < 1 << nbase; ++i) {       rev[i] = rev[i >> 1] >> 1 | (i & 1) << nbase - 1;     }     roots.resize(1 << nbase);     while (base < nbase) {       int z = power(root, 1 << max_base - 1 - base);       for (int i = 1 << base - 1; i < 1 << base; ++i) {         roots[i << 1] = roots[i];         roots[i << 1 | 1] = mul(roots[i], z);       }       ++base;     }   }   void dft(vector<int> &a) {     int n = a.size(), zeros = __builtin_ctz(n);     ensure_base(zeros);     int shift = base - zeros;     for (int i = 0; i < n; ++i) {       if (i < rev[i] >> shift) {         swap(a[i], a[rev[i] >> shift]);       }     }     for (int i = 1; i < n; i <<= 1) {       for (int j = 0; j < n; j += i << 1) {         for (int k = 0; k < i; ++k) {           int x = a[j + k], y = mul(a[j + k + i], roots[i + k]);           a[j + k] = (x + y) % md;           a[j + k + i] = (x + md - y) % md;         }       }     }   }   vector<int> multiply(vector<int> a, vector<int> b) {     int need = a.size() + b.size() - 1, nbase = 0;     while (1 << nbase < need) {       ++nbase;     }     ensure_base(nbase);     int sz = 1 << nbase;     a.resize(sz);     b.resize(sz);     bool equal = a == b;     dft(a);     if (equal) {       b = a;     } else {       dft(b);     }     int inv_sz = inv(sz);     for (int i = 0; i < sz; ++i) {       a[i] = mul(mul(a[i], b[i]), inv_sz);     }     reverse(a.begin() + 1, a.end());     dft(a);     a.resize(need);     return a;   }   }  // namespace ntt   using ntt::multiply;   vector<int> &operator*=(vector<int> &a, const vector<int> &b) {     if (min(a.size(), b.size()) < 128) {       vector<int> c = a;       a.assign(a.size() + b.size() - 1, 0);       for (int i = 0; i < c.size(); ++i) {         for (int j = 0; j < b.size(); ++j) {           add(a[i + j], mul(c[i], b[j]));         }       }     } else {       a = multiply(a, b);     }     return a;   }   vector<int> operator*(const vector<int> &a, const vector<int> &b) {     vector<int> c = a;     return c *= b;   }   int val[26], p[26];   char s[N], t[N];   long long ans[N];   vector<int> A, B, C;   int a[5][N], b[5][N];   int main(int argc, const char *argv[]) {     srand((unsigned)time(0));     for (int i = 0; i < 26; i++) {       val[i] = rand() % Mo;       int x;       scanf( %d , &x);       p[x - 1] = i;     }     scanf( %s , s);     int ls = (int)strlen(s);     scanf( %s , t);     int lt = (int)strlen(t);     for (int i = 0; i < lt; i++) {       int id = t[i] -  a ;       long long u = val[id], v = val[p[id]];       a[4][i] = 1;       a[3][i] = (-2 * u - 2 * v) % Mo;       a[2][i] = (u * u % Mo + v * v % Mo + 4 * u * v % Mo) % Mo;       a[1][i] = -2 * u * v % Mo * (u + v) % Mo;       a[0][i] = u * u % Mo * v % Mo * v % Mo;       for (int j = 0; j < 5; j++) {         if (a[j][i] < 0) {           a[j][i] += Mo;         }       }     }     for (int i = 0; i < ls; i++) {       int id = s[i] -  a ;       long long u = val[id];       b[0][i] = 1;       for (int j = 1; j < 5; j++) {         b[j][i] = u * b[j - 1][i] % Mo;       }     }     for (int i = 0; i < 5; i++) {       A = std::vector<int>(a[i], a[i] + lt);       reverse(b[i], b[i] + ls);       B = std::vector<int>(b[i], b[i] + ls);       C = A * B;       for (int j = ls - 1; j < lt; j++) {         ans[j] += C[j];       }     }     for (int j = ls - 1; j < lt; j++) {       putchar(ans[j] % Mo == 0 ?  1  :  0 );     }     putchar(10);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct v3 {     int x, y, z, i;     v3 cross(const v3& rhs) {       return {y * rhs.z - z * rhs.y, -(x * rhs.z - z * rhs.x),               x * rhs.y - y * rhs.x};     }     long long dot(const v3& rhs) { return x * rhs.x + y * rhs.y + z * rhs.z; }   };   vector<pair<int, int> > ans;   v3 pts[111111];   int pidx[6][111111];   bool chk(int n, int k) {     if (n <= k) {       for (int i = 0; i < n; i++) ans.push_back({pidx[k][i] + 1, -1});       return true;     }     if (k == 0) return false;     int mdel = -1, ma, mb, nn = 0;     for (int i = 0; i < 100; i++) {       int a = rand() % n;       int b = rand() % (n - 1);       if (b >= a) b++;       v3 pt = pts[pidx[k][a]].cross(pts[pidx[k][b]]);       if (pt.z == 0) continue;       int del = 0;       for (int j = 0; j < n; j++) {         if (pt.dot(pts[pidx[k][j]]) == 0LL) del++;       }       if (del > mdel) {         nn = 0;         for (int j = 0; j < n; j++) {           if (pt.dot(pts[pidx[k][j]]) != 0LL) pidx[k - 1][nn++] = pidx[k][j];         }         mdel = del;         ma = pidx[k][a] + 1, mb = pidx[k][b] + 1;       }     }     if (mdel == -1) return false;     ans.push_back({ma, mb});     if (chk(nn, k - 1)) return true;     ans.pop_back();     return false;   }   int N, K;   int main() {     srand(unsigned(time(0)));     scanf( %d%d , &N, &K);     for (int i = 0; i < N; i++) {       scanf( %d%d%d , &pts[i].x, &pts[i].y, &pts[i].z);       pidx[K][i] = i;     }     if (chk(N, K)) {       printf( YES n );       printf( %d n , (int)ans.size());       for (auto it : ans) {         printf( %d %d n , it.first, it.second);       }     } else {       printf( NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const int mod = 998244353;   void reduce(int &a) { a += a >> 31 & mod; }   int Mod(int x) { return x >= mod ? x - mod : x; }   long long read() {     long long x = 0;     int f = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -1;     for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);     return x * f;   }   void print(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) print(x / 10);     putchar(x % 10 +  0 );   }   int qpow(int a, int b) {     int ans = 1;     for (; b; b >>= 1, a = (long long)a * a % mod)       if (b & 1) ans = (long long)ans * a % mod;     return ans;   }   const int N = 800010, G = 3, Gi = 332748118, inv2 = 499122177, img = 86583718;   int rev[N], ul[N], gg[20][N];   int G_init() {     for (int i = 0; i < 20; i++) {       int *G = gg[i];       G[0] = 1;       const int gi = G[1] = qpow(3, (mod - 1) / (1 << i + 1));       for (int j = 2; j < (1 << i); j++) G[j] = (long long)G[j - 1] * gi % mod;     }     return 0;   }   int I = G_init();   void NTT(int *a, const int n, const int type) {     for (int i = 0; i < n; i++)       if (i < rev[i]) swap(a[i], a[rev[i]]);     int lim = log(n) / log(2) + 0.5;     for (int k = 1; k <= lim; k++) {       const int l = 1 << k, m = l >> 1, *G = gg[k - 1];       for (int *p = a; p != a + n; p += l)         for (int i = 0; i < m; i++) {           const int t = (long long)p[i + m] * G[i] % mod;           reduce(p[i + m] = p[i] - t), reduce(p[i] += t - mod);         }     }     if (~type) return;     const int inv = qpow(n, mod - 2);     for (int i = 0; i < n; i++) a[i] = (long long)a[i] * inv % mod;     reverse(a + 1, a + n);   }   void calc_rev(int &n, int &lim, const int m) {     n = 1, lim = 0;     while (n < m) n <<= 1, lim++;     for (int i = 1; i < n; i++)       rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << lim - 1);   }   void Mul(const int *a, const int *b, int *c, const int m1, const int m2) {     static int x[N], y[N];     int n, lim;     calc_rev(n, lim, m1 + m2);     for (int i = 0; i < m1; i++) x[i] = a[i];     for (int i = m1; i < n; i++) x[i] = 0;     for (int i = 0; i < m2; i++) y[i] = b[i];     for (int i = m2; i < n; i++) y[i] = 0;     NTT(x, n, 1), NTT(y, n, 1);     for (int i = 0; i < n; i++) c[i] = (long long)x[i] * y[i] % mod;     NTT(c, n, -1);     for (int i = m1 + m2 - 1; i < n; i++) c[i] = 0;   }   void Inv(const int *a, int *b, const int len) {     static int c[N];     if (len == 1) {       b[0] = qpow(a[0], mod - 2);       return;     }     Inv(a, b, len + 1 >> 1);     int n, lim;     calc_rev(n, lim, len << 1);     for (int i = 0; i < n; i++) c[i] = a[i];     for (int i = len; i < n; i++) c[i] = 0;     NTT(c, n, 1), NTT(b, n, 1);     for (int i = 0; i < n; i++)       b[i] = (2 - (long long)c[i] * b[i] % mod + mod) * b[i] % mod;     NTT(b, n, -1);     for (int i = len; i < n; i++) b[i] = 0;   }   void Der(const int *a, int *b, const int len) {     for (int i = 1; i < len; i++) b[i - 1] = (long long)a[i] * i % mod;     b[len - 1] = 0;   }   void Inte(const int *a, int *b, const int len) {     for (int i = len - 1; i; i--)       b[i] = (long long)a[i - 1] * qpow(i, mod - 2) % mod;     b[0] = 0;   }   void Ln(const int *a, int *b, const int len) {     static int c[N], inv[N];     memset(inv, 0, len << 4);     Der(a, c, len), Inv(a, inv, len);     Mul(c, inv, c, len, len), Inte(c, b, len);   }   void Exp(const int *a, int *b, const int len) {     static int c[N];     if (len == 1) {       b[0] = 1;       return;     }     Exp(a, b, len + 1 >> 1);     int lim, n;     calc_rev(n, lim, len << 1);     Ln(b, c, len);     for (int i = 0; i < len; i++) reduce(c[i] = a[i] - c[i]);     c[0]++;     for (int i = len; i < n; i++) c[i] = 0;     Mul(b, c, b, len, len);     for (int i = len; i < n; i++) b[i] = 0;   }   void Power(const int *a, int *b, const int len, const char *k, int m = -1) {     int m1 = 0, m2 = 0, m3 = 0;     if (~m)       m1 = m2 = m3 = m;     else {       int l = strlen(k);       for (int i = 0; i < l; i++) {         m1 = ((long long)m1 * 10 + (k[i] ^ 48)) % mod;         m2 = ((long long)m2 * 10 + (k[i] ^ 48)) % (mod - 1);       }       for (int i = 0; i < min(6, l); i++) m3 = m3 * 10 + (k[i] ^ 48);       if (a[0] == 0 && m3 >= len) {         for (int i = 0; i < len; i++) b[i] = 0;         return;       }     }     static int x[N], c[N];     long long t = 0;     while (!a[t]) t++;     for (int i = 0; i < len; i++) x[i] = a[i + t];     t = t * m1;     const int res = qpow(x[0], m2), inv = qpow(x[0], mod - 2);     for (int i = 0; i < len; i++) x[i] = (long long)x[i] * inv % mod;     Ln(x, b, len);     for (int i = 0; i < len; i++) b[i] = (long long)b[i] * m1 % mod;     Exp(b, c, len);     for (int i = 0; i < len; i++) c[i] = (long long)c[i] * res % mod;     for (int i = 0; i < t; i++) b[i] = 0;     for (long long i = t; i < len; i++) b[i] = c[i - t];   }   int fac[N], ifac[N];   void init(int n) {     fac[0] = 1;     for (int i = 1; i <= n; i++) fac[i] = (long long)fac[i - 1] * i % mod;     ifac[n] = qpow(fac[n], mod - 2);     for (int i = n; i; i--) ifac[i - 1] = (long long)ifac[i] * i % mod;   }   int n, m, t1[N], t2[N], S[N];   int H[N], H1[N], H2[N], inv[N];   int ans[N];   int main() {     n = read(), m = n + 2;     init(n + 2);     for (int i = 0; i < n + 1; i++) t1[i] = mod - ifac[i + 2];     Inv(t1, S, n + 1);     for (int i = 0; i < n; i++) S[i] = S[i + 1];     memset(t1, 0, sizeof(t1));     t1[0] = t1[1] = 1;     Ln(t1, t2, m + 2);     for (int i = 0; i < m + 1; i++) t1[i] = t2[i + 1];     Inv(t1, H, m + 1);     Power(H, H1, m + 1,   , n + 1);     Der(H, t1, m + 1);     Mul(t1, H1, H2, m + 1, m + 1);     for (int i = 0; i < m; i++) t1[i] = mod - H[i + 1];     Inv(t1, inv, m);     Mul(H1, inv, H1, m, m), Mul(H2, inv, H2, m, m), Mul(H2, inv, H2, m + 1, m);     int invn = qpow(n + 1, mod - 2);     for (int k = 0; k < n; k++) {       int m = n - k + 1;       reduce(S[k] -=              ((long long)H1[n - m + 2] * m + H2[n - m + 2]) % mod * invn % mod);     }     S[0]--;     memset(t1, 0, sizeof(t1)), memset(t2, 0, sizeof(t2));     for (int i = 0; i < n; i++)       if (i & 1)         t1[n - i - 1] = mod - ifac[i];       else         t1[n - i - 1] = ifac[i];     for (int i = 0; i < n; i++) t2[i] = (long long)S[i] * fac[i] % mod;     Mul(t1, t2, ans, n, n);     for (int i = 0; i < n; i++)       print((long long)ans[i + n - 1] * ifac[i] % mod * fac[n] % mod),           putchar(   );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void pisz(int n) { printf( %d n , n); }   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] <<    ;     return s;   }   namespace karkkainen {   inline bool leq(int a1, int a2, int b1, int b2) {     return (a1 < b1 || (a1 == b1 && a2 <= b2));   }   inline bool leq(int a1, int a2, int a3, int b1, int b2, int b3) {     return (a1 < b1 || (a1 == b1 && leq(a2, a3, b2, b3)));   }   static void radixPass(int *a, int *b, int *r, int n, int K) {     vector<int> c(K + 1, 0);     for (int(i) = 0; (i) < (n); ++(i)) c[r[a[i]]]++;     int sum = 0;     for (int(i) = (0); (i) <= (K); ++i) {       int t = c[i];       c[i] = sum;       sum += t;     }     for (int(i) = 0; (i) < (n); ++(i)) b[c[r[a[i]]]++] = a[i];   }   void suffixArray(int *s, int *SA, int n, int K) {     int n0 = (n + 2) / 3, n1 = (n + 1) / 3, n2 = n / 3, n02 = n0 + n2;     int *s12 = new int[n02 + 3];     s12[n02] = s12[n02 + 1] = s12[n02 + 2] = 0;     int *SA12 = new int[n02 + 3];     SA12[n02] = SA12[n02 + 1] = SA12[n02 + 2] = 0;     int *s0 = new int[n0];     int *SA0 = new int[n0];     for (int i = 0, j = 0; i < n + (n0 - n1); i++)       if (i % 3 != 0) s12[j++] = i;     radixPass(s12, SA12, s + 2, n02, K);     radixPass(SA12, s12, s + 1, n02, K);     radixPass(s12, SA12, s, n02, K);     int name = 0, c0 = -1, c1 = -1, c2 = -1;     for (int(i) = 0; (i) < (n02); ++(i)) {       if (s[SA12[i]] != c0 || s[SA12[i] + 1] != c1 || s[SA12[i] + 2] != c2) {         name++;         c0 = s[SA12[i]];         c1 = s[SA12[i] + 1];         c2 = s[SA12[i] + 2];       }       if (SA12[i] % 3 == 1) {         s12[SA12[i] / 3] = name;       } else {         s12[SA12[i] / 3 + n0] = name;       }     }     if (name < n02) {       suffixArray(s12, SA12, n02, name);       for (int(i) = 0; (i) < (n02); ++(i)) s12[SA12[i]] = i + 1;     } else {       for (int(i) = 0; (i) < (n02); ++(i)) SA12[s12[i] - 1] = i;     }     for (int i = 0, j = 0; i < n02; ++i)       if (SA12[i] < n0) s0[j++] = 3 * SA12[i];     radixPass(s0, SA0, s, n0, K);     int p = 0, t = n0 - n1;     for (int(k) = 0; (k) < (n); ++(k)) {       int i = (SA12[t] < n0 ? SA12[t] * 3 + 1 : (SA12[t] - n0) * 3 + 2);       int j = SA0[p];       if (SA12[t] < n0 ? leq(s[i], s12[SA12[t] + n0], s[j], s12[j / 3])                        : leq(s[i], s[i + 1], s12[SA12[t] - n0 + 1], s[j],                              s[j + 1], s12[j / 3 + n0])) {         SA[k] = i;         t++;         if (t == n02) {           for (k++; p < n0; p++, k++) SA[k] = SA0[p];         }       } else {         SA[k] = j;         p++;         if (p == n0) {           for (k++; t < n02; t++, k++)             SA[k] = (SA12[t] < n0 ? SA12[t] * 3 + 1 : (SA12[t] - n0) * 3 + 2);         }       }     }     delete[] s12;     delete[] SA12;     delete[] SA0;     delete[] s0;   }   };  // namespace karkkainen   struct SuffixArray {     int *sa, *lcp, *revsa;     SuffixArray(int *arr, bool with_lcp, int n) {       if (n <= 1) {         sa = new int[5];         sa[0] = 0;       } else {         sa = new int[n + 3];         arr[n] = arr[n + 1] = arr[n + 2] = 0;         karkkainen::suffixArray(arr, sa, n, *max_element(arr, arr + n));       }       if (with_lcp) {         lcp = new int[n + 3];         vector<int> rank(n + 3);         for (int(i) = 0; (i) < (n); ++(i)) rank[sa[i]] = i;         for (int i = 0, k = 0; i < n; i++) {           if (k > 0) k--;           if (rank[i] == n - 1) {             lcp[n - 1] = -1;             k = 0;             continue;           }           int j = sa[rank[i] + 1];           while (arr[i + k] == arr[j + k]) k++;           lcp[rank[i]] = k;         }       } else {         lcp = NULL;       }       revsa = new int[n + 3];       for (int(i) = 0; (i) < (n); ++(i)) revsa[sa[i]] = i;     }     ~SuffixArray() {       delete[] sa;       if (lcp != NULL) delete[] lcp;     }   };   template <typename T, typename Aug>   struct AugTreap {     struct Node {       T v;       int pr;       Node *le, *ri;       Aug al, ag;     };     Node *root;     AugTreap() : root(0) {}     inline static void recalc(Node *&n) {       Aug left = n->le ? n->le->ag + n->al : n->al;       n->ag = n->ri ? left + n->ri->ag : left;     }     inline void rotle(Node *&n) {       Node *syn = n->le;       n->le = syn->ri;       syn->ri = n;       n = syn;       recalc(n->ri);       recalc(n);     }     inline void rotri(Node *&n) {       Node *syn = n->ri;       n->ri = syn->le;       syn->le = n;       n = syn;       recalc(n->le);       recalc(n);     }     void insert_aux(Node *&n, const T &x, const Aug &aug) {       if (!n) {         n = new Node;         n->v = x;         n->pr = rand();         n->le = n->ri = 0;         n->al = n->ag = aug;       } else if (x < n->v) {         insert_aux(n->le, x, aug);         if (n->pr > n->le->pr)           rotle(n);         else           recalc(n);       } else if (x > n->v) {         insert_aux(n->ri, x, aug);         if (n->pr > n->ri->pr)           rotri(n);         else           recalc(n);       } else {         n->al = n->al + aug;         recalc(n);       }     }     void insert(const T &x, const Aug &aug) { insert_aux(root, x, aug); }     Aug sumgeq_aux(const T &x, Node *n) {       if (!n) return Aug();       if (x > n->v) return sumgeq_aux(x, n->ri);       if (x < n->v) {         Aug left = sumgeq_aux(x, n->le) + n->al;         return n->ri ? left + n->ri->ag : left;       }       return n->ri ? n->al + n->ri->ag : n->al;     }     Aug sumgeq(const T &x) { return sumgeq_aux(x, root); }     Aug sumleq_aux(const T &x, Node *n) {       if (!n) return Aug();       if (x < n->v) return sumleq_aux(x, n->le);       if (x > n->v) {         Aug right = n->al + sumleq_aux(x, n->ri);         return n->le ? n->le->ag + right : right;       }       return n->le ? n->le->ag + n->al : n->al;     }     Aug sumleq(const T &x) { return sumleq_aux(x, root); }     Aug sumbetween_aux(const T &x, const T &y, Node *n) {       if (!n) return Aug();       if (y < n->v) return sumbetween_aux(x, y, n->le);       if (x > n->v) return sumbetween_aux(x, y, n->ri);       return sumgeq_aux(x, n->le) + n->al + sumleq_aux(y, n->ri);     }     Aug sumbetween(const T &x, const T &y) { return sumbetween_aux(x, y, root); }     struct None {};     T minsubtreequery(Node *n, Aug sum) const {       if (n->le) {         Aug sum2 = sum + n->le->ag;         if (enough(sum2)) {           return minsubtreequery(n->le, sum);         }         sum = sum2;       }       sum = sum + n->al;       if (enough(sum)) return n->v;       return minsubtreequery(n->ri, sum);     }     T minquery(const T &s) const {       vector<Node *> roots;       Node *n = root;       while (n) {         if (n->v < s) {           n = n->ri;         } else if (n->v > s) {           roots.push_back(n);           n = n->le;         } else {           roots.push_back(n);           break;         }       }       Aug sum;       for (int(i) = (((int)((roots).size())) - 1); (i) >= (0); --i) {         sum = sum + roots[i]->al;         if (enough(sum)) {           return roots[i]->v;         }         if (roots[i]->ri) {           Aug sum2 = sum + roots[i]->ri->ag;           if (enough(sum2)) {             return minsubtreequery(roots[i]->ri, sum);           }           sum = sum2;         }       }       throw None();     }     T revminsubtreequery(Node *n, Aug sum) const {       if (n->ri) {         Aug sum2 = n->ri->ag + sum;         if (enough(sum2)) {           return revminsubtreequery(n->ri, sum);         }         sum = sum2;       }       sum = n->al + sum;       if (enough(sum)) return n->v;       return revminsubtreequery(n->le, sum);     }     T revminquery(const T &s) const {       vector<Node *> roots;       Node *n = root;       while (n) {         if (n->v > s) {           n = n->le;         } else if (n->v < s) {           roots.push_back(n);           n = n->ri;         } else {           roots.push_back(n);           break;         }       }       Aug sum;       for (int(i) = (((int)((roots).size())) - 1); (i) >= (0); --i) {         sum = roots[i]->al + sum;         if (enough(sum)) {           return roots[i]->v;         }         if (roots[i]->le) {           Aug sum2 = roots[i]->le->ag + sum;           if (enough(sum2)) {             return revminsubtreequery(roots[i]->le, sum);           }           sum = sum2;         }       }       throw None();     }   };   struct IntMin {     int x;     IntMin(int y = 1001001001) : x(y) {}     inline IntMin operator+(const IntMin &s) const { return IntMin(min(x, s.x)); }     operator int() const { return x; }   };   struct tree {     int sz;     vector<vector<int> > V;     tree(vector<int> val) {       int n = ((int)((val).size()));       for (sz = 1; sz < n; sz *= 2)         ;       V.assign(2 * sz, vector<int>());       for (int(i) = 0; (i) < (n); ++(i)) V[sz + i].push_back(val[i]);       for (int(i) = (sz - 1); (i) >= (1); --i) {         V[i].resize(((int)((V[2 * i]).size())) + ((int)((V[2 * i + 1]).size())));         merge(V[2 * i].begin(), V[2 * i].end(), V[2 * i + 1].begin(),               V[2 * i + 1].end(), V[i].begin());       }     }     int query(int b, int e, int x) { return get(sz + b, sz + e + 1, x); }     int ile(int v, int x) {       return upper_bound(V[v].begin(), V[v].end(), x) - V[v].begin();     }     int get(int p, int q, int x) {       if (p + 1 == q) return ile(p, x);       if (p & 1) return ile(p, x) + get(p + 1, q, x);       if (q & 1) return ile(q - 1, x) + get(p, q - 1, x);       return get(p / 2, q / 2, x);     }   };   int inp[200009];   int word[200009];   int ans[200009];   int newword[200009];   int prog;   bool enough(const IntMin &s) { return s.x < prog; }   int main() {     int(n);     scanf( %d , &(n));     for (int(i) = 0; (i) < (n); ++(i)) {       scanf( %d , inp + i);     }     for (int(i) = 0; (i) < (n - 1); ++(i)) {       word[i] = inp[i + 1] - inp[i];     }     word[n - 1] = INT_MAX;     for (int(i) = 0; (i) < (n - 1); ++(i)) {       word[n + i] = -word[i];     }     int len = 2 * n - 1;     map<int, int> mapa;     int now = 1;     for (int(i) = 0; (i) < (len); ++(i)) mapa[word[i]] = now++;     for (int(i) = 0; (i) < (len); ++(i)) newword[i] = mapa[word[i]];     SuffixArray sa(newword, 1, len);     AugTreap<int, IntMin> lcpTreap;     for (int(i) = 0; (i) < (len - 1); ++(i)) lcpTreap.insert(i, sa.lcp[i]);     lcpTreap.insert(-1, 0);     lcpTreap.insert(len - 1, 0);     vector<int> vec(len, 1001001001);     for (int(i) = 0; (i) < (len); ++(i)) vec[sa.revsa[i]] = i;     tree polpr(vec);     int(queries);     scanf( %d , &(queries));     for (int(query) = 0; (query) < (queries); ++(query)) {       int(l), (r);       scanf( %d %d , &(l), &(r));       --l;       --r;       if (l == r) {         ans[query] = n - 1;       } else {         int indexInSa = sa.revsa[n + l];         prog = r - l;         int a = lcpTreap.revminquery(indexInSa - 1) + 1;         int b = lcpTreap.minquery(indexInSa);         ans[query] = 0;         if (r + 1 <= n - 2) {           ans[query] += polpr.query(a, b, n - 2) - polpr.query(a, b, r);         }         if (0 <= l - (r - l + 1)) {           ans[query] += polpr.query(a, b, l - (r - l + 1));         }       }     }     for (int(query) = 0; (query) < (queries); ++(query)) pisz(ans[query]);   }


#include <bits/stdc++.h>   using namespace std;   map<pair<int, int>, int> mp;   vector<int> res, low, b;   int ask(int l, int r) {     if (l == r) return -1;     if (l > r) swap(l, r);     if ((res[l] | res[r]) == (low[l] | low[r])) return res[l] | res[r];     auto it = mp.find(make_pair(l, r));     if (it != mp.end()) return it->second;     printf( ? %d %d n , l, r);     fflush(stdout);     int x;     scanf( %d , &x);     mp[make_pair(l, r)] = x;     res[l] &= x;     res[r] &= x;     for (auto p : mp) {       low[p.first.first] |= p.second ^ res[p.first.second];       low[p.first.second] |= p.second ^ res[p.first.first];     }     return x;   }   int n;   void answer() {     printf( ! );     for (int i = 1; i <= n; ++i) {       printf(  %d , res[i]);     }     printf(  n );     fflush(stdout);     exit(0);   }   int main() {     scanf( %d , &n);     int full = (1 << 18) - 1;     res.assign(n + 1, full);     low.assign(n + 1, 0);     int cnt = 4269 - n * 2;     srand(time(0));     int p = -1, q = -1;     while (cnt-- > 0) {       int x = (rand() % n) + 1;       int y = (rand() % n) + 1;       while (x == y) {         y = (rand() % n) + 1;       }       ask(x, y);       bool found = false;       for (int i = 1; i <= n; ++i) {         for (int j = i + 1; j <= n; ++j) {           if (res[i] & res[j]) continue;           p = i;           q = j;           found = true;         }       }       if (found) break;     }     if (p != -1 && q != -1) {       for (int i = 1; i <= n; ++i) {         ask(i, p);         ask(i, q);       }       answer();     }     int zero = -1;     while (true) {       vector<int> cand;       for (int i = 1; i <= n; ++i) {         if (low[i]) continue;         cand.emplace_back(i);       }       sort(cand.begin(), cand.end(), [](int l, int r) {         return __builtin_popcount(res[l]) < __builtin_popcount(res[r]);       });       for (int x : cand) {         ask(x, cand[0]);       }       zero = -1;       for (int x : cand) {         if (res[x] == 0) {           zero = x;           break;         }       }       if (zero != -1) break;     }     for (int i = 1; i <= n; ++i) {       ask(zero, i);     }     answer();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n, k;     cin >> n >> k;     if (k < (n * n + n) / 2) return cout << -1, 0;     long long t = k;     k -= (n * n + n) / 2;     long long a[n + 1];     for (long long i = 1; i <= n; i++) a[i] = i;     for (long long i = 1; i <= n / 2; i++) {       if (k - (n + 1 - 2 * i) > 0) {         swap(a[i], a[n - i + 1]);         k -= (n + 1 - 2 * i);       } else {         swap(a[i], a[i + k]);         cout << t << endl;         for (long long i = 1; i <= n; i++) cout << i <<    ;         cout << endl;         for (long long i = 1; i <= n; i++) cout << a[i] <<    ;         return 0;       }     }     cout << t - k << endl;     for (long long i = 1; i <= n; i++) cout << i <<    ;     cout << endl;     for (long long i = 1; i <= n; i++) cout << a[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   string s;   long long dp[1000001][7];   long long f(int idx, int la = 6) {     if (idx == s.size()) {       if (la == 2) return 0;       if (la == 1) return 0;       return 1;     }     if (dp[idx][la] != -1) return dp[idx][la];     long long res = 0;     if (s[idx] !=  ? ) {       char c = s[idx];       if (la == 0) {         if (c ==  0 )           res = f(idx + 1, 0);         else if (c ==  1 )           res = f(idx + 1, 1);       } else if (la == 1) {         if (c ==  * ) res = f(idx + 1, 4);       } else if (la == 2) {         if (c ==  * ) res = f(idx + 1, 4);       } else if (la == 3) {         if (c ==  0 )           res = f(idx + 1, 0);         else if (c ==  1 )           res = f(idx + 1, 1);       } else if (la == 4) {         if (c ==  2 )           res = f(idx + 1, 2);         else if (c ==  1 )           res = f(idx + 1, 3);         else if (c ==  * )           res = f(idx + 1, 4);       } else {         if (c ==  1 ) res = f(idx + 1, 1);         if (c ==  0 ) res = f(idx + 1, 0);         if (c ==  * ) res = f(idx + 1, 4);       }     } else if (la == 0) {       res += f(idx + 1, 0);       res %= mod;       res += f(idx + 1, 1);       res %= mod;     } else if (la == 1 || la == 2) {       res = f(idx + 1, 4);     } else if (la == 3) {       res += f(idx + 1, 0);       res %= mod;       res += f(idx + 1, 1);       res %= mod;     } else if (la == 4) {       res = f(idx + 1, 2);       res %= mod;       res += f(idx + 1, 3);       res %= mod;       res += f(idx + 1, 4);       res %= mod;     } else {       res += f(idx + 1, 0);       res %= mod;       res += f(idx + 1, 1);       res %= mod;       res += f(idx + 1, 4);       res %= mod;     }     return dp[idx][la] = res;   }   int main() {     memset(dp, -1, sizeof dp);     ios::sync_with_stdio(false);     cin >> s;     cout << f(0);   }


#include <bits/stdc++.h>   using namespace std;   int n, s, T, ans;   int ar[101];   bool ok[301];   int dp[301][301];   int res[301][301];   int tmp[301][301];   int ways[24][301][301];   vector<int> v;   int main() {     scanf( %d%d , &n, &T);     for (int i = 1; i <= n; i++) {       scanf( %d , &ar[i]);       ok[ar[i]] = true;     }     for (int i = 1; i < 301; i++)       if (ok[i]) v.push_back(i);     s = v.size();     for (int h = 0; h < s; h++) {       int head = v[h];       dp[head][head] = 1;       for (int i = 1; i <= n; i++) {         int mx = dp[head][ar[i]];         for (int j = 1; j <= ar[i]; j++)           if (dp[head][j]) mx = max(mx, dp[head][j] + 1);         dp[head][ar[i]] = mx;       }     }     for (int i = 1; i < 301; i++)       for (int j = 1; j < 301; j++) ways[0][i][j] = max(dp[i][j] - 1, 0);     for (int kd = 1; (1 << kd) <= T; kd++)       for (int i = 0; i < s; i++)         for (int j = i; j < s; j++)           for (int k = i; k <= j; k++) {             int vi = v[i];             int vj = v[j];             int vk = v[k];             ways[kd][vi][vj] = max(ways[kd][vi][vj],                                    ways[kd - 1][vi][vk] + ways[kd - 1][vk][vj]);           }     for (int kd = 0; (1 << kd) <= T; kd++)       if (T & (1 << kd)) {         memset(tmp, 0, sizeof(tmp));         for (int i = 0; i < s; i++)           for (int j = i; j < s; j++)             for (int k = i; k <= j; k++) {               int vi = v[i];               int vj = v[j];               int vk = v[k];               tmp[vi][vj] = max(tmp[vi][vj], res[vi][vk] + ways[kd][vk][vj]);             }         for (int i = 0; i < s; i++)           for (int j = 0; j < s; j++) res[v[i]][v[j]] = tmp[v[i]][v[j]];       }     for (int i = 0; i < s; i++)       for (int j = 0; j < s; j++) ans = max(ans, res[v[i]][v[j]]);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   int main(void) {     char s[1001];     scanf( %s , s);     if (s[0] > 64 && s[0] < 91)       printf( %s , s);     else {       s[0] -= 32;       for (int i = 0; i < strlen(s); i++) printf( %c , s[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, h;   bool ok(long long x) {     long long ans = 0;     if (x >= 2e9) return 1;     if (x <= h)       ans = x * (x + 1) / 2;     else {       ans = h * (h + 1) / 2 + (x - h) * h;       long long high = x - h - 1;       long long t1 = high / 2, t2 = high - t1;       ans += t1 * (t1 + 1) / 2 + t2 * (t2 + 1) / 2;     }     if (ans >= n)       return 1;     else       return 0;   }   int main() {     cin >> n >> h;     long long l = 1, r = 1e18 + 1;     long long mid = (l + r) / 2;     while (l < r) {       mid = (l + r) / 2;       if (ok(mid))         r = mid;       else         l = mid + 1;     }     printf( %lld n , l);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long double mm = 0;   int xs[4];   int ys[4];   int mxs[4];   int mys[4];   int used[1001][1001];   long double di(int x1, int y1, int x2, int y2) {     return sqrt(abs((long double)x1 - (long double)x2) *                     abs((long double)x1 - (long double)x2) +                 abs((long double)y1 - (long double)y2) *                     abs((long double)y1 - (long double)y2));   }   int n, m;   void dfs(int x, int y, int d, long double ma) {     if (x < 0 || y < 0) return;     if (x > n || y > m) return;     if (used[x][y]) return;     used[x][y] = 1;     xs[d] = x;     ys[d] = y;     if (d == 3) {       if (ma > mm) {         mm = ma;         for (int i = 0; i < 4; i++) {           mxs[i] = xs[i];           mys[i] = ys[i];         }       }       used[x][y] = 0;       return;     }     for (int i = 0; i < 4; i++) {       for (int ii = 0; ii < 4; ii++) {         dfs(i, ii, d + 1, ma + di(x, y, i, ii));       }     }     for (int i = 0; i < 4; i++) {       for (int ii = 0; ii < 4; ii++) {         dfs(n - i, m - ii, d + 1, ma + di(x, y, n - i, m - ii));       }     }     used[x][y] = 0;   }   int main() {     cin >> n >> m;     for (int i = 0; i < 4; i++) {       for (int ii = 0; ii < 4; ii++) {         dfs(i, ii, 0, 0);       }     }     for (int i = 0; i < 4; i++) {       cout << mxs[i] <<     << mys[i] << endl;     }   }


#include<bits/stdc++.h>   #define rep(i,a,b) for(int i=(a);i<(b);++i)   #define per(i,a,b) for(int i=(b)-1;i>=(a);--i)   #define ll long long   #define lb(x) ((x)&-(x))   #define pii pair<int,int>   #define vi vector<int>   #define pb push_back   #define fi first   #define se second   #define de(x) cout<<#x<<  x <<endl   #define LCAFA rep(i,1,20)rep(j,1,n+1)fa[j][i]=fa[fa[j][i-1]][i-1]   #define all(x) x.begin(),x.end()   #define ls(x) x<<1   #define rs(x) x<<1|1   #define pr(x) {for(auto v:x)cout<<v<<   ;cout<<#x<<endl;}   using namespace std;   const int N=3e4+9;   const ll mod=998244353;   const ll Inf=1e18;   /*   inline int add(int a,const int &b){    a+=b;    if(a>=mod)a-=mod;    return a;   }   inline int sub(int a,const int &b){    a-=b;    if(a<0)a+=mod;    return a;   }   inline int mul(const int &a,const int &b){return 1ll*a*b%mod;}   int jie[N],inv[N];   ll quick(ll a,ll b){    ll res=1;    while(b){     if(b&1)res=res*a%mod;     a=a*a%mod;     b>>=1;    }    return res;   }   inline int C(int m,int n){    if(n>m||m<0||n<0)return 0;    return mul(mul(jie[m],inv[n]),inv[m-n]);   }   void pre(){    inv[0]=inv[1]=1,jie[0]=1;    rep(i,2,N)inv[i]=-1ll*mod/i*inv[mod%i]%mod+mod;    rep(i,1,N)inv[i]=mul(inv[i],inv[i-1]),jie[i]=mul(jie[i-1],i);   }   */   ll dp[N][5];   int p[N];   vi s[N];   ll L[N][5][16],R[N][5][16];   int main(){    //pre();    int T;    scanf( %d ,&T);    while(T--){     int n,c,q;     scanf( %d%d%d ,&n,&c,&q);     rep(i,0,n)scanf( %d ,&p[i]);     rep(i,0,c+1)dp[n][i]=1;     per(i,0,n){      rep(j,0,c+1){       dp[i][j]=0;       rep(k,0,j+1){        if(i+k<n)dp[i][j]+=dp[i+k+1][j-k];       }      }     }     rep(i,0,n){      s[i].clear();      rep(j,0,c+1){       if(i+j<n)s[i].pb(j);      }      sort(all(s[i]),[&](int a,int b){return p[i+a]<p[i+b];});     }     int lim=0;     while((1<<lim)<n)++lim;     rep(i,0,n)rep(j,0,c+1)rep(k,0,lim+1)L[i][j][k]=R[i][j][k]=0;     per(i,0,n){      rep(j,0,c+1){       if(i+j>=n)break;       ll sum=0;       for(auto v:s[i]){        if(v>j)continue;        if(v==0)break;        sum+=dp[i+v+1][j-v];       }       L[i][j][0]=sum;       R[i][j][0]=sum+dp[i+1][j];       rep(k,1,lim+1){        if(i+(1<<k)<=n){         L[i][j][k]=L[i][j][k-1]+L[i+(1<<k-1)][j][k-1];         R[i][j][k]=L[i][j][k-1]+R[i+(1<<k-1)][j][k-1];        }       }      }     }     while(q--){      int pos;      ll id;      scanf( %d%lld ,&pos,&id);      if(id>dp[0][c]){       puts( -1 );       continue;      }      --pos;      --id;      int i=0,ans=p[pos],r=c;     // cout<<ans<< ans n ;      int cnt=0;      while(i<n){       ++cnt;       if(cnt>6)return 0;       for(int j=lim;j>=0;--j){        if(i+(1<<j)<=n&&L[i][r][j]<=id&&id<R[i][r][j]){         id-=L[i][r][j];         i+=1<<j;        }       }       if(i==n)break;      // cout<<cnt<<   <<i<<   <<r<<   <<id<< i n ;       for(auto v:s[i]){        if(v>r)continue;        if(id>=dp[i+v+1][r-v]){         id-=dp[i+v+1][r-v];        }        else{        // cout<<v<< v n ;         int i1=i+v;         r-=v;         if(i<=pos&&pos<=i1){          ans=p[i+i1-pos];         }         i=i1+1;         break;        }       }      }       printf( %d n ,ans);     }    }    }   /*   1   3 1 1   1 2 3   2 1      1   6 4 1   6 5 4 3 1 2   3 14      1   20 4 1   16 5 15 14 13 3 17 18 2 20 19 6 4 1 12 8 11 10 9 7   8 1100   */


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > al, dist;   int n, m;   bool done[5000];   vector<int> bfs(const vector<vector<int> >& al, int s) {     queue<int> q;     vector<int> dist(al.size(), INT_MAX);     dist[s] = 0;     q.push(s);     while (!q.empty()) {       int i = q.front();       q.pop();       for (int j : al[i])         if (dist[j] == INT_MAX) {           dist[j] = dist[i] + 1;           q.push(j);         }     }     return dist;   }   int main() {     ios::sync_with_stdio(0);     cin >> n >> m;     int r = n;     al.resize(n);     dist.resize(n);     int i, j;     for (int c = 0; c < m; c++) {       cin >> i >> j;       i--;       j--;       al[i].push_back(j);     }     for (int s = 0; s < n; s++) dist[s] = bfs(al, s);     for (int i = 0; i < n; i++)       if (!done[i]) {         vector<int> comp{i};         done[i] = 1;         bool outgo = 0;         for (int j = 0; j < n; j++)           if (dist[i][j] != INT_MAX && i != j) {             if (dist[j][i] != INT_MAX) {               comp.push_back(j);               done[j] = 1;             } else               outgo = 1;           }         if (!outgo && comp.size() > 1) {           int m = INT_MAX;           for (int c = 0; c < comp.size(); c++)             for (int d = 0; d < comp.size(); d++)               if (c != d)                 m = min(m, dist[comp[c]][comp[d]] + dist[comp[d]][comp[c]]);           r += 998 * m + 1;         }       }     cout << r <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3006;   struct arr {     int x, y, i;   } a[maxn];   int r, c, n, K;   int pos[maxn], L[maxn], R[maxn];   long long ans;   bool cmpx(arr x, arr y) {     if (x.x == y.x) return x.y < y.y;     return x.x < y.x;   }   bool cmpy(arr x, arr y) {     if (x.y == y.y) return x.x < y.x;     return x.y < y.y;   }   int main() {     scanf( %d%d%d%d , &r, &c, &n, &K);     for (int i = 1; i <= n; i++) scanf( %d%d , &a[i].x, &a[i].y);     sort(a + 1, a + n + 1, cmpy);     for (int i = 1; i <= n; i++) a[i].i = i;     sort(a + 1, a + n + 1, cmpx);     for (int i = 1; i <= n; i++) L[i] = i - 1;     for (int i = 1; i <= n; i++) R[i] = i + 1;     for (int i = 1; i <= n; i++) pos[a[i].i] = i;     R[0] = 1;     L[n + 1] = n;     pos[n + 1] = n + 1;     a[n + 1].x = r + 1;     a[n + 1].y = c + 1;     int nn = n;     for (int i = r; i >= 1; i--) {       int t = 0;       long long tmp = 0;       for (int j = 1; j <= n && a[j].x <= i; t = j++)         R[L[a[j].i]] = R[a[j].i], L[R[a[j].i]] = L[a[j].i];       for (int j = i, k = t; j >= 1; ans += tmp, j--) {         for (; a[k].x == j; k--) {           R[L[a[k].i]] = a[k].i;           L[R[a[k].i]] = a[k].i;           int val = 1, lp = a[k].i, rp = a[k].i;           for (; L[lp] && val < K; lp = L[lp], val++)             ;           for (; lp <= a[k].i; lp = R[lp], val--) {             for (; R[rp] <= n && val < K; rp = R[rp], val++)               ;             if (val < K) break;             long long tmp_1 = a[pos[lp]].y - a[pos[L[lp]]].y;             long long tmp_2 = a[pos[R[rp]]].y - a[pos[rp]].y;             tmp += tmp_1 * tmp_2;           }         }       }       while (a[nn].x == i) {         R[L[a[nn].i]] = R[a[nn].i];         L[R[a[nn].i]] = L[a[nn].i];         nn--;       }     }     printf( %lld n , ans);     return 0;   }


/*Allah Vorosha*/   #include<bits/stdc++.h>   #define ll long long   #define ld long double   #define pb push_back   #define in insert   #define rev reverse   #define all(x) (x).begin(),(x).end()   #define all2(x) (x).rbegin(),(x).rend()   #define sz(v) (int)v.size()   #define yes cout <<  YES n    #define no cout <<  NO n ;   #define take for(auto &it : a) cin >> it;   #define vi vector<int>   #define vii vector<pair<int, int > >   #define vl vector<ll>   #define fi first   #define se second   #define l_b lower_bound   #define u_b upper_bound   #define ios ios_base::sync_with_stdio(0);cin.tie();cout.tie();   #define tail cout <<   n       using namespace std;      template<class T> void read(T &x) { cin >> x; }   template<class T, class ...U> void read(T &x, U& ... u) { read(x); read(u...); }   template<class T> void print1(const T &x) { cout << x <<   n ; }   template<class T, class ...U> void print1(const T &x, const U& ... u) { print1(x); print1(u...); }   template<class T> void print2(const T &x) { cout << x <<    ; }   template<class T, class ...U> void print2(const T &x, const U& ... u) { print2(x); print2(u...); }      int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};   //int n, m;      bool valid (int x, int y) {       //return (x >= 0 && x < n && y >= 0 && y < m);   }      bool vis[55][55];      const int N = 1005, mod = 1e9 + 7, M = 5e5 + 5;   const ll inf = 9e18;   int cs = 1;      void solve() {       ll n, c;       read(n, c);       vi a(n);       take;       vi b(n - 1);       for(auto &it : b)           cin >> it;       ll hi = c, low = 1, mid, ans;       while(hi >= low) {           mid = (hi + low) >> 1;           ll day = mid;           ll tk = 0;           bool ok = 0;           for(int i = 0; i < n; i++) {               if(tk + a[i] * day >= c) {                   ok = 1; break;               }               else {                   if(i == n - 1) {                       if(tk + a[i] * day >= c) {                           ok = 1;                           break;                       }                   }                   else {                       if(tk >= b[i]) {                           tk -= b[i];                           day--;                       }                       else {                           ll k = b[i] - tk;                           ll l = k / a[i] + (k % a[i] != 0);                           day -= l + 1;                           tk += l * a[i];                           tk -= b[i];                       }                   }               }               //if(mid == 6) print1(day);               if(day < 0) {                   break;               }           }           if(ok) {               ans = mid;               hi = mid - 1;           }           else {               low = mid + 1;           }       }       cout << ans <<   n ;   }      int main() {       ios;       int tc;       read(tc);       while(tc--)       solve();       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 1;   long long a[N];   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     priority_queue<pair<long long, int>, vector<pair<long long, int>>,                    greater<pair<long long, int>>>         q;     for (int i = 1; i <= n; ++i) {       int x;       cin >> x;       q.push({x, i});     }     long long ans(0);     while (!q.empty()) {       pair<long long, int> p = q.top();       q.pop();       if (q.top().first == p.first && !q.empty()) {         int x = q.top().second;         q.pop();         q.push({p.first * 2, x});       } else {         ans++;         a[p.second] = p.first;       }     }     cout << ans << endl;     for (int i = 1; i <= n; ++i)       if (a[i] != 0) cout << a[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1001000;   const int INF = 1e9;   int n, L, U;   int head[maxn], nxt[maxn << 1], rdc[maxn << 1], w[maxn << 1], tnt;   int prt, rt, asiz;   int siz[maxn], mdep[maxn];   int fdep, gdep;   int f[maxn], g[maxn], fp[maxn], gp[maxn], dta;   int q[maxn], qt, qe;   int ansu, ansv;   vector<int> v[maxn], t[maxn];   bool vis[maxn];   inline int read() {     int res = 0;     char ch = getchar(), ch1 = ch;     while (!isdigit(ch)) ch1 = ch, ch = getchar();     while (isdigit(ch)) res = (res << 3) + (res << 1) + ch -  0 , ch = getchar();     return ch1 ==  -  ? -res : res;   }   bool cmp(int x, int y) { return mdep[rdc[x]] < mdep[rdc[y]]; }   void add(int x, int y, int z) {     nxt[++tnt] = head[x];     head[x] = tnt;     rdc[tnt] = y;     w[tnt] = z;   }   void findrt(int p, int f) {     int res = 0;     siz[p] = 1;     for (register int i = head[p]; i; i = nxt[i])       if (rdc[i] != f && !vis[rdc[i]]) {         findrt(rdc[i], p);         res = max(res, siz[rdc[i]]);         siz[p] += siz[rdc[i]];       }     res = max(res, asiz - siz[p]);     if (res <= (asiz >> 1)) rt = p;   }   void builddfs(int p, int f) {     siz[p] = 1;     for (register int i = head[p]; i; i = nxt[i])       if (rdc[i] != f && !vis[rdc[i]]) {         mdep[rdc[i]] = mdep[p] + 1;         builddfs(rdc[i], p);         siz[p] += siz[rdc[i]];       }     for (register int i = head[p]; i; i = nxt[i])       if (rdc[i] != f && !vis[rdc[i]]) mdep[p] = max(mdep[p], mdep[rdc[i]]);   }   void build(int p) {     vis[p] = true;     mdep[p] = 0;     for (register int i = head[p]; i; i = nxt[i]) {       if (vis[rdc[i]]) continue;       mdep[rdc[i]] = 1;       builddfs(rdc[i], p);       mdep[p] = max(mdep[p], mdep[rdc[i]]);       v[p].push_back(i);     }     sort(v[p].begin(), v[p].end(), cmp);     for (register int i = head[p]; i; i = nxt[i]) {       if (vis[rdc[i]]) continue;       asiz = siz[rdc[i]];       findrt(rdc[i], p);       t[p].push_back(rt);       build(rt);     }     vis[p] = false;   }   void dfs(int p, int f, int dep, int pv) {     if (g[dep] < pv) {       g[dep] = pv;       gp[dep] = p;     }     for (register int i = head[p]; i; i = nxt[i])       if (rdc[i] != f && !vis[rdc[i]])         dfs(rdc[i], p, dep + 1, pv + (w[i] >= dta ? 1 : -1));     gdep = max(gdep, dep);   }   bool check(int p) {     if ((mdep[p] << 1) < L) return false;     bool flag = false;     vis[p] = true;     fp[0] = gp[0] = p;     for (register int i = 0; i < v[p].size() && !flag; ++i) {       dfs(rdc[v[p][i]], p, 1, (w[v[p][i]] >= dta ? 1 : -1));       qt = 1;       qe = 0;       for (register int j = 0, k = min(fdep, U); j <= gdep; ++j) {         while (qt <= qe && q[qt] + j > U) ++qt;         while (j + k >= L && k >= 0) {           while (qt <= qe && f[q[qe]] <= f[k]) --qe;           q[++qe] = k;           --k;         }         if (qt <= qe && g[j] + f[q[qt]] >= 0) {           flag = true;           ansu = gp[j];           ansv = fp[q[qt]];           break;         }       }       fdep = gdep;       while (gdep) {         if (f[gdep] < g[gdep]) {           f[gdep] = g[gdep];           fp[gdep] = gp[gdep];         }         g[gdep] = -INF;         --gdep;       }     }     while (fdep) {       f[fdep] = -INF;       --fdep;     }     if (flag) {       vis[p] = false;       return true;     }     for (register int i = 0; i < t[p].size(); ++i)       if (check(t[p][i])) {         vis[p] = false;         return true;       }     vis[p] = false;     return false;   }   int main() {     n = read();     L = read();     U = read();     for (int i = 1, x, y, z; i < n; ++i) {       x = read();       y = read();       z = read();       add(x, y, z);       add(y, x, z);     }     asiz = n;     findrt(1, 0);     build(prt = rt);     for (register int i = 0; i <= n; ++i) f[i] = g[i] = -INF;     f[0] = g[0] = 0;     int l = -1, r = 1e9;     while (l < r) {       dta = (l + r + 1) >> 1;       if (check(prt))         l = dta;       else         r = dta - 1;     }     dta = l;     check(l);     printf( %d %d n , ansu, ansv);     return 0;   }


#include <bits/stdc++.h>   const double pi = acos(-1.0);   const double eps = 1e-9;   using namespace std;   int k, n1, n2, n3, t1, t2, t3;   void solve() {     cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3;     set<pair<long long, int>> st[3];     for (int i = 1; i <= 1000; i++) {       if (i <= n1) {         st[0].insert({0, i});       }       if (i <= n2) {         st[1].insert({0, i});       }       if (i <= n3) {         st[2].insert({0, i});       }     }     long long ans = 0;     while (k--) {       auto beg0 = *st[0].begin();       auto beg1 = *st[1].begin();       auto beg2 = *st[2].begin();       auto last0 = beg0, last1 = beg1, last2 = beg2;       st[0].erase(beg0);       st[1].erase(beg1);       st[2].erase(beg2);       beg0.first += t1;       beg1.first = max(beg1.first + t2, beg0.first + t2);       beg2.first = max(beg2.first + t3, beg1.first + t3);       ans = max(ans, beg2.first);       beg1.first = beg2.first - t3;       beg0.first = beg1.first - t2;       assert(last0.first <= beg0.first);       assert(last1.first <= beg1.first);       assert(last2.first <= beg2.first);       st[0].insert(beg0);       st[1].insert(beg1);       st[2].insert(beg2);     }     cout << ans << endl;   }   int main() {     ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);     cout.setf(ios::fixed), cout.precision(7);     int step = 1;     for (int i = 1; i <= step; i++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   long long read() {     long long ans = 0, f = 1;     char c = getchar();     while (c >  9  || c <  0 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       ans = ans * 10 + c -  0 ;       c = getchar();     }     return ans * f;   }   const long long N = 2e5 + 5;   long long t, n, m, k, x[N], y[N], ans, mmax[N];   signed main() {     t = read();     while (t--) {       n = read();       k = read();       for (long long i = 1; i <= n; ++i) x[i] = read();       for (long long i = 1; i <= n; ++i) y[i] = read();       sort(x + 1, x + 1 + n);       long long now = 0;       ans = 0;       for (long long i = 1; i <= n; ++i) {         long long len = upper_bound(x + 1, x + 1 + n, x[i] + k) - x - 1;         now = max(now, mmax[i]);         ans = max(ans, len - i + 1 + now);         mmax[len + 1] = max(mmax[len + 1], len - i + 1);       }       for (long long i = 1; i <= n + 1; ++i) mmax[i] = 0;       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dx[4] = {0, 0, -1, 1};   const int dy[4] = {-1, 1, 0, 0};   int i, j, x, y, n, m, e[26], b[510][510], l, ans, flag, xx, yy;   char c, s[100010];   int main() {     scanf( %d%d%d%d , &n, &m, &x, &y);     scanf(  %s , s);     l = strlen(s);     ans = 1;     printf( 1 );     e[ L  -  A ] = 0;     e[ R  -  A ] = 1;     e[ U  -  A ] = 2;     e[ D  -  A ] = 3;     memset(b, 0, sizeof(b));     b[x][y] = 1;     flag = 0;     for (i = 0; i < l; i++) {       xx = x + dx[e[s[i] -  A ]];       yy = y + dy[e[s[i] -  A ]];       if (flag || xx < 1 || xx > n || yy < 1 || yy > m) {         if (i == l - 1) {           printf(  %d n , n * m - ans);           continue;         }         printf(  0 );         continue;       }       x = xx;       y = yy;       if (b[xx][yy] == 1) {         if (i == l - 1) {           printf(  %d n , n * m - ans);           continue;         }         printf(  0 );         continue;       }       ans++;       b[x][y] = 1;       if (i == l - 1) {         printf(  %d n , n * m + 1 - ans);         continue;       }       printf(  1 );     }     puts(  );     return 0;   }


#include<iostream>   #include<cstdio>   #include<cstring>   #include<algorithm>   #include<vector>   using namespace std;   int n,m;   char s[200009],t[200009];   int f[200009],g[200009];   vector<int> p[30];   int main()   {    scanf( %d%d ,&n,&m);    scanf( %s%s ,s+1,t+1);    for(int i=1;i<=n;i++)     s[i]-= a -1;    for(int i=1;i<=m;i++)     t[i]-= a -1;    for(int i=1;i<=n;i++)     p[s[i]].push_back(i);    for(int i=1;i<=m;i++)     f[i]=*upper_bound(p[t[i]].begin(),p[t[i]].end(),f[i-1]);    g[m+1]=n+1;    for(int i=m;i>=1;i--)     g[i]=*(lower_bound(p[t[i]].begin(),p[t[i]].end(),g[i+1])-1);    int ans=0;    for(int i=1;i<=m-1;i++)     ans=max(ans,g[i+1]-f[i]);    printf( %d ,ans);    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long in, temp = 0, t = 0;     int casos;     cin >> casos;     for (int i = 0; i < casos; i++) {       cin >> in;       temp = in * (in + 1) / 2;       for (long long i = 0;; i++) {         if ((1 << i) > in) {           break;         } else {           long long j = 1 << i;           t = t + j;         }       }       temp = temp - 2 * t;       cout << temp << endl;       t = 0;       temp = 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1000000007;   const int N = 105;   int n, m, k, nl, d[N][N], ok;   struct point {     int x, y;     point(){};     point(int x, int y) : x(x), y(y) {}   };   string a[N];   vector<point> l[N * N];   int s[N * N], p[N * N];   void input() {     cin >> n >> m >> k;     getline(cin, a[0]);     for (int i = 0; i < n; i++) {       getline(cin, a[i]);     }   }   int vx[] = {0, 1, 0, -1};   int vy[] = {-1, 0, 1, 0};   int check(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }   void dfs(int x, int y) {     l[nl].push_back(point(x, y));     s[nl]++;     d[x][y] = 1;     for (int k = 0; k < 4; k++) {       int u = x + vx[k];       int v = y + vy[k];       if (!check(u, v)) {         ok = 0;         continue;       }       if (a[u][v] !=  .  || d[u][v]) continue;       dfs(u, v);     }   }   int cmp(int x, int y) { return s[x] < s[y]; }   void solve() {     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  .  && !d[i][j]) {           l[nl].clear();           s[nl] = 0;           p[nl] = nl;           ok = 1;           dfs(i, j);           if (ok) nl++;         }       }     }     sort(p, p + nl, cmp);     int ans = 0;     for (int i = 0; i < nl - k; i++) {       ans += s[p[i]];       for (int j = 0; j < l[p[i]].size(); j++) {         int u = l[p[i]][j].x;         int v = l[p[i]][j].y;         a[u][v] =  * ;       }     }     cout << ans << endl;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cout << a[i][j];       }       cout << endl;     }   }   int main() {     int test = 1;     while (test--) {       input();       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long fpm(long long b, long long e, long long m) {     long long t = 1;     for (; e; e >>= 1, b = b * b % m) e & 1 ? t = t * b % m : 0;     return t;   }   template <class T>   inline bool chkmin(T &a, T b) {     return a > b ? a = b, true : false;   }   template <class T>   inline bool chkmax(T &a, T b) {     return a < b ? a = b, true : false;   }   template <class T>   inline T sqr(T x) {     return x * x;   }   template <class edge>   struct Graph {     vector<vector<edge> > adj;     Graph(int n) {       adj.clear();       adj.resize(n + 5);     }     Graph() { adj.clear(); }     void resize(int n) { adj.resize(n + 5); }     void add(int s, edge e) { adj[s].push_back(e); }     void del(int s, edge e) {       adj[s].erase(find((adj[s]).begin(), (adj[s]).end(), e));     }     int deg(int v) { return adj[v].size(); }     vector<edge> &operator[](int t) { return adj[t]; }   };   struct crd {     long double x, y, z;     void read() { cin >> x >> y >> z; }     void out() { cerr <<  (  << x <<  ,   << y <<  ,   << z <<  ) ; }     crd operator^(crd &w) {       return (crd){y * w.z - w.y * z, z * w.x - w.z * x, x * w.y - y * w.x};     }     long double operator*(crd &w) { return x * w.x + y * w.y + z * w.z; }     crd operator+(crd &w) { return (crd){x + w.x, y + w.y, z + w.z}; }     crd operator-(crd &w) { return (crd){x - w.x, y - w.y, z - w.z}; }     crd operator*(long double &w) { return (crd){x * w, y * w, z * w}; }     long double len() { return sqrt(x * x + y * y + z * z); }   };   crd A, p, O, v;   long double R, r;   long double sphere(crd o, long double r) {     o = o - A;     crd plane = o ^ v;     crd vert = v ^ plane;     long double mindis = o * vert / vert.len();     if (mindis > R + r || o * v < 0) return 1e300;     o.out(), vert.out(), plane.out(), ({});     long double dist = o.len();     long double run =         sqrt(sqr(dist) - sqr(mindis)) - sqrt(sqr(R + r) - sqr(mindis));     return run / v.len();   }   int main() {     ios_base::sync_with_stdio(false);     long double ans = 1e300;     A.read(), v.read();     v.out(), cerr << endl;     int n, m;     cin >> R >> n;     for (int i = 1; i <= n; ++i) {       O.read();       cin >> r >> m;       ans = min(ans, sphere(O, r));       for (; m--;) p.read(), ans = min(ans, sphere(O + p, 0));     }     cout << setprecision(15) << (ans > 1e200 ? -1 : ans) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void ioe() {     freopen( in_3.txt ,  r , stdin);     freopen( out_3.txt ,  w , stdout);     freopen( er_3.txt ,  w , stderr);   }   struct lex_compare {    public:     bool operator()(const pair<long long, long long>& lhs,                     const pair<long long, long long>& rhs) const {       return (lhs.second > rhs.second);     }   };   long long pw(long long a, long long b, long long m) {     if (b == 0) return 1;     long long t = (pw(a, b / 2, m)) % m;     t = (t * t) % m;     if (b % 2 == 0) return t;     return (a * t) % m;   }   long long gc(long long a, long long b) {     if (b == 0) return a;     return gc(b, a % b);   }   vector<string> splt(string x, char w) {     vector<string> v;     string s;     int l = x.length();     for (long long i = 0; i < l; i++) {       if (x[i] == w) {         v.push_back(s);         s =   ;       } else {         s.push_back(x[i]);       }     }     v.push_back(s);     return v;   }   class node {    public:     long long id, a, l;     vector<node*> v;     vector<pair<node*, long long>> vm;     node* prt = NULL;     long long s = -1, x = 0, y = 0;     node(long long x = 0, long long y = 0) {       id = y, a = x, l = 0;       vm.clear(), v.clear();       prt = NULL;       s = -1, x = 0, y = 0;     }     void adn(node* t) { v.push_back(t), l++; }     void adn(node* t, long long x) { vm.push_back({t, x}), l++; }   };   node* nnd(long long a = 0, long long i = 1) {     node* t = new node(a, i);     return t;   }   void solve() {     long long n;     cin >> n;     char a[n][n];     for (long long i = 0; i < n; i++)       for (long long j = 0; j < n; j++) cin >> a[i][j];     long long t = 0;     for (long long i = 0; i < n; i++)       for (long long j = 0; j < n; j++) {         long long x = 0;         if (i > 0 && a[i - 1][j] ==  o ) x++;         if (j > 0 && a[i][j - 1] ==  o ) x++;         if ((i < n - 1) && a[i + 1][j] ==  o ) x++;         if ((j < n - 1) && a[i][j + 1] ==  o ) x++;         if (x % 2 == 1) t++;       }     if (t == 0)       cout <<  YES n ;     else       cout <<  NO n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long t = 1;     long long f = t;     while (f--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   void optimise() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   long long int mod = 998244353;   void normalize(long long int &a) { a = (a + mod) % mod; }   long long int modmul(long long int a, long long int b) {     a = a % mod;     b = b % mod;     normalize(a);     normalize(b);     return (a * b) % mod;   }   long long int modadd(long long int a, long long int b) {     a = a % mod;     b = b % mod;     normalize(a);     normalize(b);     return (a + b) % mod;   }   long long int modsub(long long int a, long long int b) {     a = a % mod;     b = b % mod;     normalize(a);     normalize(b);     return (a - b + mod) % mod;   }   long long int me(long long int x, long long int n) {     x %= mod;     if (n == 0) return 1;     long long int u = me(x, n / 2) % mod;     u = (u * u) % mod;     if (n % 2) u = (u * x) % mod;     return u;   }   long long int me1(long long int x, long long int n) {     if (n == 0) return 1;     long long int u = me1(x, n / 2);     u = u * u;     if (n % 2) u = u * x;     return u;   }   inline long long int modInv(long long int a) { return me(a, mod - 2); }   inline long long int modDiv(long long int a, long long int b) {     return modmul(a, modInv(b));   }   float power(float x, long long int y) {     float temp;     if (y == 0) return 1;     temp = power(x, y / 2);     if (y % 2 == 0)       return temp * temp;     else {       if (y > 0)         return x * temp * temp;       else         return (temp * temp) / x;     }   }   long long int __gcd(long long int a, long long int b) {     if (b == 0)       return a;     else       return __gcd(b, a % b);   }   pair<long long int, long long int> operator+(       pair<long long int, long long int> a,       pair<long long int, long long int> b) {     return {a.first + b.first, a.second + b.second};   }   pair<long long int, long long int> operator-(       pair<long long int, long long int> a,       pair<long long int, long long int> b) {     return {a.first - b.first, a.second - b.second};   }   pair<long long int, long long int> operator*(       pair<long long int, long long int> a,       pair<long long int, long long int> b) {     return {a.first * b.first, a.second * b.second};   }   template <typename T>   ostream &operator<<(ostream &os, const set<T> &v) {     for (auto it : v) os << it <<    ;     return os;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     for (long long int i = 0; i < v.size(); ++i) os << v[i] <<    ;     return os;   }   void solve() {     long long int n, h, reg;     cin >> n >> h >> reg;     set<pair<long long int, long long int>> s;     vector<pair<long long int, pair<long long int, long long int>>> v;     long long int x1 = 0;     for (long long int i = 0; i < n; i++) {       long long int x, y;       cin >> x >> y;       v.push_back({x, {y, i + 1}});       if (x == 100) x1 += y;     }     sort(v.begin(), v.end());     auto k1 = v.end();     k1--;     if (reg >= x1) {       cout <<  NO ;       return;     }     long long int cur = h;     long long int t = 0;     set<long long int> used;     vector<pair<long long int, long long int>> ans;     long long int k = 0;     cout <<  YES           <<   n ;     while (cur > 0) {       for (long long int i = 0; i < v.size(); i++) {         if (used.find(v[i].second.second) == used.end()) {           long long int p = v[i].first;           if (p * h >= 100 * cur) s.insert(v[i].second);         }       }       if (s.size() > 0) {         auto k1 = s.end();         k1--;         ans.push_back({t, k1->second});         k += (k1->first);         t++;         cur -= k;         cur += reg;         if (cur > h) cur = h;         used.insert(k1->second);         s.erase(k1);       } else {         t++;         cur -= k;         cur += reg;         if (cur > h) cur = h;       }     }     cout << t <<     << ans.size() <<   n ;     for (long long int i = 0; i < ans.size(); i++)       cout << ans[i].first <<     << ans[i].second <<   n ;   }   signed main() {     optimise();     long long int t;     t = 1;     cout << fixed << setprecision(3);     while (t--) {       solve();       cout <<   n ;     }     cerr <<   n           <<  Time Elasped :   << 1.0 * clock() / CLOCKS_PER_SEC <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 3.14159265359;   double ans, x, y;   int n, zeros, ones;   int main() {     scanf( %d , &n);     for (int i = 0; i < 2 * n; ++i) {       scanf( %lf , &y);       x -= y - int(y);       if (y == int(y))         ++zeros;       else         ++ones;     }     assert(zeros + ones == 2 * n);     int i = 0;     while (i < min(n, ones) && fabs(x) >= fabs(x + 1)) x += 1.0, ++i;     while (i < n && zeros) ++i, --zeros;     while (i < n) x += 1.0, ++i;     printf( %.3lf , fabs(x));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1000005];   long long dp[1000005];   multiset<int> se;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int i, c, j, k, l, m, n, t, r, cnt;     int flag = 0;     long long ans = 0, an = 0;     t = 1;     while (t--) {       scanf( %d , &n);       scanf( %d , &c);       for (i = 1; i <= n; i++) {         scanf( %d , &a[i]);       }       se.insert(0);       for (i = 1; i < c; i++) {         se.insert(a[i]);         dp[i] = dp[i - 1] + a[i];       }       an = dp[c - 1];       for (i = c; i <= n; i++) {         se.insert(a[i]);         se.erase(se.find(a[i - c]));         an += (a[i] - a[i - c]);         dp[i] = min(dp[i - 1] + a[i], dp[i - c] + an - *se.begin());       }       cout << dp[n] << endl;     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   template <class _T>   inline _T loww(_T n) {     return n & (-n);   }   template <class _T>   inline void swapp(_T &x, _T &y) {     _T t;     t = x, x = y, y = t;   }   template <class _T>   inline _T minn(_T i, _T j) {     return i > j ? j : i;   }   template <class _T>   inline _T maxx(_T i, _T j) {     return i > j ? i : j;   }   template <class _T>   inline _T gcd(_T b, _T c) {     return b && c ? (c ? gcd(c, b % c) : b) : b | c;   }   template <class _T>   inline _T abss(_T b) {     return b > 0 ? b : -b;   }   struct node {     int v, col;   };   node a[500005 << 2];   void DOWN(int l, int r, int dq) {     if (a[dq].col) {       if (l != r) {         a[dq << 1].col = a[dq << 1].v = a[dq << 1 | 1].col = a[dq << 1 | 1].v =             a[dq].col;       }       a[dq].col = 0;     }   }   void UP(int l, int r, int dq) {     DOWN(l, r, dq);     if (a[dq << 1].v == a[dq << 1 | 1].v)       a[dq].v = a[dq << 1].v;     else       a[dq].v = -1;   }   void U(int l, int r, int dq, int b, int c, int v) {     DOWN(l, r, dq);     if (l == r) {       a[dq].v = v;     } else {       if (b <= l && r <= c) {         a[dq].v = a[dq].col = v;       } else {         int mid = (l + r) >> 1;         if (b <= mid) U(l, mid, dq << 1, b, c, v);         if (c > mid) U(mid + 1, r, dq << 1 | 1, b, c, v);         UP(l, r, dq);       }     }   }   int Q(int l, int r, int dq, int b) {     DOWN(l, r, dq);     if (l == r || a[dq].v != -1)       return a[dq].v;     else {       int mid = (l + r) >> 1;       if (b <= mid)         return Q(l, mid, dq << 1, b);       else         return Q(mid + 1, r, dq << 1 | 1, b);     }   }   void build(int l, int r, int dq) {     if (l == r) {       a[dq].col = a[dq].v = 0;     } else {       a[dq].col = a[dq].v = 0;       int mid = (l + r) >> 1;       build(l, mid, dq << 1);       build(mid + 1, r, dq << 1 | 1);     }   }   bool outflag = true;   void out(int b) {     if (outflag)       outflag = false;     else       printf(   );     printf( %d , b);   }   pair<int, int> goal[500005];   int val[500005];   map<int, int> mymap;   int pre[500005], gl = 0;   int en = 0;   int main() {     int n, i, t, js, told, b;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &val[i]);     }     build(1, n, 1);     for (i = 1; i <= n; i++) {       pre[i] = mymap[val[i]];       mymap[val[i]] = i;       t = pre[i];       told = i;       js = 0;       while (t > en) {         if (js++ > 1) break;         if (t + 1 <= told - 1) U(1, n, 1, t + 1, told - 1, val[i]);         b = Q(1, n, 1, t);         if (b != 0) {           goal[gl++] = make_pair(b, val[i]);           en = i;           break;         }         told = t;         t = pre[t];       }       if (js == 3) {         goal[gl++] = make_pair(val[i], val[i]);         en = i;       }     }     printf( %d n , gl * 4);     for (i = 0; i < gl; i++) {       out(goal[i].first);       out(goal[i].second);       out(goal[i].first);       out(goal[i].second);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[200010];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= (n + 1) / 2; i++) {       if (i % 2 == 1) {         int temp;         temp = a[i];         a[i] = a[n + 1 - i];         a[n + 1 - i] = temp;       }     }     for (int i = 1; i < n; i++) printf( %d  , a[i]);     printf( %d n , a[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int inch = n / 3;     if (n % 3 == 2) inch++;     cout << inch / 12 <<     << inch % 12;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 303;   int n;   bool eq[N][N];   int dp[N][N];   string s[N];   int main() {     cin >> n;     int allsum = n - 1;     for (int i = 0; i < n; ++i) {       cin >> s[i];       allsum += s[i].size();     }     for (int i = 0; i < n; ++i) {       eq[i][i] = true;       for (int j = 0; j < i; ++j) eq[i][j] = eq[j][i] = s[i] == s[j];     }     for (int i = n - 1; i >= 0; --i) {       for (int j = n - 1; j >= 0; --j) {         if (eq[i][j]) {           if (i + 1 < n && j + 1 < n)             dp[i][j] = dp[i + 1][j + 1] + 1;           else             dp[i][j] = 1;         }       }     }     int ans = allsum;     for (int i = 0; i < n; ++i) {       int sum = 0;       for (int j = 0; i + j < n; ++j) {         sum += s[i + j].size();         int cnt = 1;         for (int pos = i + j + 1; pos < n; ++pos) {           if (dp[i][pos] > j) {             ++cnt;             pos += j;           }         }         int cur = allsum - sum * cnt + (j + 1) * cnt - j * cnt;         if (cnt > 1 && ans > cur) {           ans = cur;         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int par[21], siz[21];   int root(int a) {     while (a != par[a]) {       a = par[a];     }     return a;   }   void unionn(int a, int b) {     int root_a = root(a);     int root_b = root(b);     if (root_a == root_b) {       return;     }     if (siz[root_a] < siz[root_b]) {       siz[root_b] += siz[root_a];       par[root_a] = root_b;     } else {       siz[root_a] += siz[root_b];       par[root_b] = root_a;     }   }   void init() {     int i;     for (i = 0; i <= 20; i++) {       siz[i] = 1;       par[i] = i;     }   }   int main() {     int t;     cin >> t;     while (t--) {       init();       int n;       cin >> n;       int i;       string s1, s2;       cin >> s1 >> s2;       s1 =  @  + s1;       s2 =  @  + s2;       int flag = 0;       for (i = 1; i <= n; i++) {         if (s1[i] > s2[i]) {           flag = 1;         }       }       if (flag == 1) {         cout <<  -1 n ;         continue;       }       set<int> v[20];       int ans = 0;       for (i = 1; i <= n; i++) {         if (s1[i] != s2[i]) v[s2[i] -  a ].insert(s1[i] -  a );       }       map<pair<int, int>, int> m;       set<int> sp;       for (i = 1; i <= 19; i++) {         if (v[i].size() == 0) {           continue;         }         set<int> sp;         for (auto it = v[i].begin(); it != v[i].end(); it++) {           sp.insert(root(*it));           unionn(*it, i);         }         ans += (int)(sp.size());       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int w[100005];   long long p[100005];   int e[2005];   int edge(int n) {     int ans = n * (n - 1) / 2;     if (!(n & 1)) ans += n / 2 - 1;     return ans;   }   int main() {     int n, m, q;     cin >> n >> m;     for (int i = 0; i < m; i++) cin >> q >> w[i];     sort(w, w + m, greater<int>());     m = min(m, 2005);     while (m >= 2005 || edge(m) > n - 1) m--;     long long ans = 0LL;     for (int i = 0; i < m; i++) ans += w[i];     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   inline int add(int a, int b) {     if ((a += b) >= mod) a -= mod;     return a;   }   inline int mult(int a, int b) {     long long t = 1ll * a * b;     if (t >= mod) t %= mod;     return t;   }   inline int dec(int a, int b) {     if ((a -= b) < 0) a += mod;     return a;   }   inline int power(int a, int b) {     int out = 1;     while (b) {       if (b & 1) out = mult(out, a);       a = mult(a, a);       b >>= 1;     }     return out;   }   int n, a[2510], f[100010], ans, mx, sum;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), sum += a[i];     mx = *max_element(a + 1, a + n + 1);     f[1] = mult(mult(sum - 1, sum - 1), power(sum, mod - 2));     for (int i = 1; i < mx; i++)       f[i + 1] = dec(add(f[i], f[i]),                      add(f[i - 1], mult(sum - 1, power(sum - i, mod - 2))));     for (int i = 1; i <= n; i++) ans = add(ans, f[a[i]]);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int solve(void) {     int n, s;     cin >> n >> s;     set<int> avail;     char c;     for (int i = 0; i < n; i++) {       cin >> c;       avail.insert((int)c -  a  + 1);     }     int cnt = 1;     int ans = *avail.begin();     int prev = ans;     avail.erase(avail.begin());     while (cnt < s) {       if (avail.empty()) return -1;       while (*avail.begin() < prev + 2) {         avail.erase(avail.begin());         if (avail.empty()) return -1;       }       prev = *avail.begin();       ans += prev;       avail.erase(avail.begin());       cnt++;     }     return ans;   }   int main(void) { cout << solve() << endl; }


#include <bits/stdc++.h>   using namespace std;   inline long long mod(long long n, long long m) {     long long ret = n % m;     if (ret < 0LL) ret += m;     return ret;   }   long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }   long long exp(long long a, long long b, long long m) {     if (b == 0LL) return 1LL;     if (b == 1LL) return mod(a, m);     long long k = mod(exp(a, b / 2, m), m);     if (b & 1LL) {       return mod(a * mod(k * k, m), m);     } else       return mod(k * k, m);   }   const long long MAXN = 300100;   long long res[MAXN];   pair<long long, long long> P[MAXN];   long long dist(pair<long long, long long> a, pair<long long, long long> b) {     return abs(a.first - b.first) + abs(a.second - b.second);   }   long long n;   long long dp[MAXN][3][4][4];   const long long inf = 2e9;   long long solve(long long id, long long j, long long xo, long long yo) {     if (j == 3) {       if (xo == 3 && yo == 3) return 0;       return -inf;     }     if (id == n + 1) {       return -inf;     }     long long &x = dp[id][j][xo][yo];     if (x != -1) return x;     x = 0;     long long op0 = solve(id + 1, j, xo, yo);     x = op0;     for (long long it1 = 0; it1 <= 2; it1++) {       for (long long it2 = 0; it2 <= 2; it2++) {         long long sum1 = it1 * P[id].first - (2 - it1) * P[id].first;         long long sum2 = it2 * P[id].second - (2 - it2) * P[id].second;         if (it1 + xo <= 3 && it2 + yo <= 3) {           x = max(x, sum1 + sum2 + solve(id + 1, j + 1, xo + it1, yo + it2));         }       }     }     return x;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> P[i].first >> P[i].second;     }     memset(dp, -1, sizeof(dp));     long long tot = 0;     for (long long i = 1; i <= n; i++) {       tot += dist(P[i], P[(i == n ? 1 : i + 1)]);     }     cout << solve(1, 0, 0, 0) <<    ;     for (long long i = 4; i <= n; i++) cout << tot <<    ;     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int a[200000];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     sort(a, a + n);     int q;     cin >> q;     for (int i = 0; i < q; ++i) {       int m;       cin >> m;       int l = 0, r = n - 1;       while (l <= r) {         int mid = (l + r) / 2;         if (a[mid] > m) {           r = mid - 1;         } else {           l = mid + 1;         }       }       cout << l << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1010;   int n, m;   int g[N][N];   int ans = 0;   inline void Solve(int l, int r, int K, int dep) {     if (l >= r) return;     ans = ((ans) < (dep) ? (dep) : (ans));     int siz = (r - l + 1) / K;     if (!siz) ++siz;     int last = l, cnt = 0;     vector<pair<int, int> > S;     while (last <= r && cnt < K)       ++cnt, Solve(last, cnt == K ? r : min(last + siz - 1, r), K, dep + 1),           S.push_back(make_pair(last, cnt == K ? r : min(last + siz - 1, r))),           last += siz;     cerr <<  Solve(  << l <<  ,  << r <<  ,  << K <<  ,  << dep <<  ) n ;     cerr <<  S:  ;     for (auto x : S) cerr <<  [  << x.first <<  ,  << x.second <<  ]  ;     cerr << endl;     for (register int i = 0; i < (int)S.size(); ++i)       for (register int j = i + 1; j < (int)S.size(); ++j)         for (register int k = S[i].first; k <= S[i].second; ++k)           for (register int l = S[j].first; l <= S[j].second; ++l) g[k][l] = dep;   }   int main() {     scanf( %d%d , &n, &m);     for (register int len = 1; len < n; len *= m) {       ++ans;       for (register int i = 0; i < n; i += len)         for (register int j = 0; j < n; j += len)           if (i != j)             for (register int x = 0; x < len && i + x < n; ++x)               for (register int y = 0; y < len && j + y < n; ++y)                 g[i + x + 1][j + y + 1] = ans;     }     printf( %d n , ans);     for (register int i = 1; i <= n; ++i)       for (register int j = i + 1; j <= n; ++j) printf( %d  , g[i][j]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, l, sum = 0;     cin >> n;     string st;     for (l = 0; l < n; l++) {       cin >> st;       if (st[0] ==  T )         sum = sum + 4;       else if (st[0] ==  C )         sum = sum + 6;       else if (st[0] ==  O )         sum = sum + 8;       else if (st[0] ==  D )         sum = sum + 12;       else         sum = sum + 20;     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   const long long inf = 1000000000;   const long long inf64 = inf * inf;   const double pi = acos(-1.0);   long long Abs(long long x) { return (x >= 0 ? x : -x); }   using namespace std;   bool solve() {     int n;     cin >> n;     vector<vector<long long> > mat(n, vector<long long>(n));     vector<long long> ans(n, 0);     for (int i(0); i < n; i++)       for (int j(0); j < n; j++) cin >> mat[i][j];     for (int i(0); i < n; i++) {       for (int j(0); j < n; j++) {         if (i == j) continue;         ans[j] |= mat[i][j];       }     }     for (int i(0); i < n; i++) cout << ans[i] <<    ;     return true;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b > a) {       return gcd(b, a);     }     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   long long expo(long long a, long long b, long long mod) {     long long res = 1;     while (b > 0) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;       b = b >> 1;     }     return res;   }   vector<int> sieve(int n) {     int *arr = new int[n + 1]();     vector<int> vect;     for (int i = 2; i <= n; i++)       if (arr[i] == 0) {         vect.push_back(i);         for (int j = 2 * i; j <= n; j += i) arr[j] = 1;       }     return vect;   }   void extendgcd(long long a, long long b, long long *v) {     if (b == 0) {       v[0] = 1;       v[1] = 0;       v[2] = a;       return;     }     extendgcd(b, a % b, v);     long long x = v[1];     v[1] = v[0] - v[1] * (a / b);     v[0] = x;     return;   }   long long mminv(long long a, long long b) {     long long arr[3];     extendgcd(a, b, arr);     return arr[0];   }   long long mminvprime(long long a, long long b) { return expo(a, b - 2, b); }   bool revsort(long long a, long long b) { return a > b; }   void swap(int &x, int &y) {     int temp = x;     x = y;     y = temp;   }   long long combination(long long n, long long r, long long m, long long *fact) {     long long val1 = fact[n];     long long val2 = mminvprime(fact[r], m);     long long val3 = mminvprime(fact[n - r], m);     return ((val1 * val2) % m * val3) % m;   }   void dfs(int start, vector<int> *edges, bool *visited, int *blues, int *reds,            int *color, vector<pair<int, int>> &childs) {     if (color[start] == 1) blues[start]++;     if (color[start] == 2) reds[start]++;     visited[start] = true;     for (int i = 0; i < edges[start].size(); i++) {       if (visited[edges[start][i]]) continue;       dfs(edges[start][i], edges, visited, blues, reds, color, childs);       blues[start] += blues[edges[start][i]];       reds[start] += reds[edges[start][i]];       childs.push_back({start, edges[start][i]});     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     int color[n];     int sum1 = 0;     int sum2 = 0;     for (int i = 0; i < n; i++) {       cin >> color[i];       if (color[i] == 1) sum1++;       if (color[i] == 2) sum2++;     }     vector<int> *edges = new vector<int>[n];     vector<int> *ans1 = new vector<int>[n];     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       edges[u].push_back(v);       edges[v].push_back(u);       ans1[u].push_back(1);       ans1[v].push_back(1);     }     int *blues = new int[n]();     int *reds = new int[n]();     bool *visited = new bool[n]();     vector<pair<int, int>> childs;     dfs(0, edges, visited, blues, reds, color, childs);     int ans = 0;     set<pair<int, int>> s;     for (int i = 0; i < childs.size(); i++) {       int x = childs[i].second;       int blue = blues[x];       int red = reds[x];       if (blue == 0 && red == sum2) ans++;       if (red == 0 && blue == sum1) ans++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N;     string team1 =   ;     string team2 =   ;     int team1points = 0;     int team2points = 0;     cin >> N;     while (N--) {       string goalTeam;       cin >> goalTeam;       if (team1 == goalTeam) {         team1points++;       } else if (team2 == goalTeam) {         team2points++;       } else if (team1 ==   ) {         team1 = goalTeam;         team1points++;       } else if (team2 ==   ) {         team2 = goalTeam;         team2points++;       }     }     cout << (team1points > team2points ? team1 : team2) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool possible = 1;   void change(char str[], char mask[]) {     char best[6];     best[0] =   0 ;     for (int i = 0; i < (4); ++i) {       for (int d = 0; d < (10); ++d)         if (!(i == 0 && d == 0)) {           char temp = str[i];           str[i] = (d +  0 );           if (strcmp(str, mask) >= 0) {             if (best[0] ==   0 )               strcpy(best, str);             else if (strcmp(best, str) > 0)               strcpy(best, str);           }           str[i] = temp;         }     }     if (strcmp(best,  2011 ) > 0) possible = 0;     strcpy(str, best);   }   int main() {     int n;     scanf( %d , &n);     char in[1005][6];     for (int i = 0; i < (n); ++i) scanf( %s , in[i]);     change(in[0],  1000 );     possible = 1;     for (int i = (1); i <= (n - 1); ++i) {       change(in[i], in[i - 1]);     }     if (!possible)       puts( No solution );     else {       for (int i = 0; i < (n); ++i) printf( %s n , in[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     cin.sync_with_stdio(0);     int n;     cin >> n;     vector<vector<int> > p(n);     for (int i = 1; i < n; i++) {       int tmp;       cin >> tmp;       p[tmp - 1].push_back(i);     }     int ans = 0;     queue<pair<int, int> > q;     q.push(pair<int, int>(0, 0));     vector<int> tmp(n, 0);     while (q.size()) {       pair<int, int> front = q.front();       int cur = front.first;       int level = front.second;       q.pop();       tmp[level] = !tmp[level];       for (auto it : p[cur]) q.push(pair<int, int>(it, level + 1));     }     for (int i = 0; i < n; i++) ans += tmp[i];     cout << ans << endl;     return 0;   }


#include<bits/stdc++.h>   using namespace std;   int a, b;   bool check(int cnt) {    int cnt6 = cnt/6;    int cnt2 = cnt/2 - cnt6;    int cnt3 = cnt/3 - cnt6;    if(cnt2 <= a) {     cnt6 -= a-cnt2;    }    if(cnt3 <= b) {     cnt6 -= b-cnt3;    }    return cnt6 >= 0;   }   int main() {   #ifdef DEBUG       a = 0, b = 1000000;   #elif not defined(DEBUG)    cin>>a>>b;   #endif    int l = max(a<<1, b*3);    int r = l<<1;    while(l+100<r) {     int mid = (l+r)>>1;     if(check(mid)) r = mid; else l = mid;    }    for(int i = l;i<=r;i++) if(check(i)) {     cout<<i<<endl;     break;    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 5;   const long long MOD = 1e9 + 7;   long long n, ct;   long long a[N], vis[N];   vector<long long> g[N];   void dfs(long long k) {     if (vis[k]) return;     vis[k] = 1;     ct++;     for (auto it : g[k]) dfs(it);   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       g[i].push_back(a[i]);     }     vector<long long> ans;     for (long long i = 1; i <= n; i++) {       if (!vis[i]) {         ct = 0;         dfs(i);         ans.push_back(ct);       }     }     sort(ans.rbegin(), ans.rend());     long long answer = 0;     long long sz = ans.size();     for (long long i = 0; i < sz; i++) {       answer += ans[i] * ans[i];     }     if (sz >= 2) {       answer -= ans[0] * ans[0];       answer -= ans[1] * ans[1];       answer += (ans[0] + ans[1]) * (ans[0] + ans[1]);     }     cout << answer;   }


#include <bits/stdc++.h>   using namespace std;   int mx, cnt, k;   char s[105];   int main() {     while (~scanf(  %s , &s)) {       k = strlen(s);       mx = 0;       for (int i = 0; i < k; i++) {         for (int j = i + 1; j < k; j++) {           cnt = 0;           if (s[i] == s[j]) {             for (int o = 0; o < k; o++) {               if (s[i + o] == s[j + o])                 cnt++;               else                 break;             }           }           if (cnt > mx) mx = cnt;         }       }       printf( %d n , mx);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a >> b;     cout << min(a, b) <<     << (max(a, b) - min(a, b)) / 2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int vis[2005];   int main() {     int n, m, k;     char c;     scanf( %d%d%d , &n, &m, &k);     int ans = 0;     for (int i = 0; i < n; i++) {       getchar();       int temp = 0;       for (int j = 0; j < m; j++) {         scanf( %c , &c);         if (c ==  . ) {           vis[j]++;           temp++;         } else {           vis[j] = 0;           temp = 0;         }         if (temp >= k) ans++;         if (vis[j] >= k && k != 1) ans++;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 300, maxTreeSize = 1 << 10;   struct Tree {    private:     bool active[maxTreeSize];     int Min[maxTreeSize], Max[maxTreeSize], offset;       public:     void resize(int n) {       offset = 1;       while (offset < n) offset *= 2;     }     void add(int v, int val) {       v += offset;       active[v] = true;       Min[v] = Max[v] = val;       while (v > 1) {         v /= 2;         active[v] = true;         if (active[v * 2] and active[v * 2 + 1]) {           Min[v] = min(Min[v * 2], Min[v * 2 + 1]);           Max[v] = max(Max[v * 2], Max[v * 2 + 1]);         } else if (active[v * 2]) {           Min[v] = Min[v * 2];           Max[v] = Max[v * 2];         } else {           Min[v] = Min[v * 2 + 1];           Max[v] = Max[v * 2 + 1];         }       }     }     pair<int, int> query(int val) {       int v = 1;       while (v < offset) {         if (!active[v * 2] or !active[v * 2 + 1]) {           v = active[v * 2] ? v * 2 : v * 2 + 1;           continue;         }         if (val <= Max[v * 2]) {           v = v * 2;           continue;         }         if (Min[v * 2 + 1] <= val) {           v = v * 2 + 1;           continue;         }         int diff1 = abs(Max[v * 2] - val), diff2 = abs(Min[v * 2 + 1] - val);         v = (diff1 <= diff2) ? v * 2 : v * 2 + 1;       }       return make_pair(v - offset, abs(val - Max[v]));     }     void clear() {       for (int i = 1; i < offset * 2; i++) active[i] = false;     }   };   int sumpUp[maxN + 1][maxN + 1], sumpDown[maxN + 1][maxN + 1],       sumpLeft[maxN + 1][maxN + 1], sumpRight[maxN + 1][maxN + 1],       sump1[maxN + 1], sump2[maxN + 1], T[maxN + 1][maxN + 1];   int tp, tu, td, ord_in_tree[maxN + 1];   pair<int, int> temp[maxN];   int cost_of_step(int a, int b) {     if (a == b) return tp;     if (a < b) return tu;     if (a > b) return td;   }   Tree tree;   int main() {     int n, m, ts;     scanf( %d%d%d%d%d%d , &n, &m, &ts, &tp, &tu, &td);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) scanf( %d , &T[i][j]);     }     for (int i = 1; i <= n; i++) {       for (int j = 2; j <= m; j++)         sumpLeft[i][j] = sumpLeft[i][j - 1] + cost_of_step(T[i][j - 1], T[i][j]);       for (int j = m - 1; j > 0; j--)         sumpRight[i][j] =             sumpRight[i][j + 1] + cost_of_step(T[i][j + 1], T[i][j]);     }     for (int j = 1; j <= m; j++) {       for (int i = 2; i <= n; i++)         sumpUp[i][j] = sumpUp[i - 1][j] + cost_of_step(T[i - 1][j], T[i][j]);       for (int i = n - 1; i > 0; i--)         sumpDown[i][j] = sumpDown[i + 1][j] + cost_of_step(T[i + 1][j], T[i][j]);     }     tree.resize(m);     int min_diff = 1000000000;     int i1, j1, i2, j2;     for (int a = 1; a <= n; a++) {       for (int b = a + 2; b <= n; b++) {         for (int j = 1; j <= m; j++) {           sump1[j] = sumpLeft[a][j] + (sumpUp[b][j] - sumpUp[a][j]) +                      sumpRight[b][1] - sumpRight[b][j];           sump2[j] = sumpLeft[a][j] - (sumpDown[a][j] - sumpDown[b][j]) +                      (sumpRight[b][1] - sumpRight[b][j]);           temp[j - 1] = make_pair(sump2[j], j);         }         sort(temp, temp + m);         for (int j = 0; j < m; j++) ord_in_tree[temp[j].second] = j;         tree.add(ord_in_tree[1], sump2[1]);         for (int j = 3; j <= m; j++) {           pair<int, int> res_temp = tree.query(sump1[j] - ts);           if (res_temp.second < min_diff) {             min_diff = res_temp.second;             i1 = a;             j1 = temp[res_temp.first].second;             i2 = b;             j2 = j;           }           tree.add(ord_in_tree[j - 1], sump2[j - 1]);         }         tree.clear();       }     }     printf( %d %d %d %d n , i1, j1, i2, j2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool Caps(string a) {     for (int i = 0; i < a.size(); i++)       if (a.at(i) < 65 && a.at(i) > 90) return false;     return true;   }   int main() {     long long n, cnt = 0;     cin >> n;     while (n > 0) {       int rem = n % 10;       if (rem == 4 || rem == 7) {         cnt++;       }       n /= 10;     }     if (cnt == 4 || cnt == 7)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }