#include <bits/stdc++.h> n using namespace std; n using SI = set<int>; n using ULL = unsigned long long; n using LL = long long; n using VI = vector<int>; n using LD = long double; n using PULL = pair<ULL, ULL>; n using UI = unsigned int; n using PLL = pair<LL, LL>; n using PDD = pair<LD, LD>; n using MII = map<int, int>; n using TDD = pair<PDD, LD>; n using TLL = pair<PLL, LL>; n using PII = pair<int, int>; n using TII = pair<PII, int>; n using QDD = pair<PDD, PDD>; n using QII = pair<PII, PII>; n using QLL = pair<PLL, PLL>; n using STII = set<TII>; n using VTII = vector<TII>; n using MTII = map<TII, TII>; n using MITII = map<int, TII>; n using UMITII = unordered_map<int, TII>; n using SQII = set<QII>; n using VQII = vector<QII>; n using MQII = map<QII, QII>; n using MIQII = map<int, QII>; n using UMIQII = unordered_map<int, QII>; n using SLL = set<LL>; n using VLL = vector<LL>; n using MLL = map<LL, LL>; n using MILL = map<int, LL>; n using UMILL = unordered_map<int, LL>; n using SULL = set<ULL>; n using VULL = vector<ULL>; n using MULL = map<ULL, ULL>; n using MIULL = map<int, ULL>; n using UMIULL = unordered_map<int, ULL>; n using SPULL = set<PULL>; n using VPULL = vector<PULL>; n using MPULL = map<PULL, PULL>; n using MIPULL = map<int, PULL>; n using UMIPULL = unordered_map<int, PULL>; n using SQLL = set<QLL>; n using VQLL = vector<QLL>; n using MQLL = map<QLL, QLL>; n using MIQLL = map<int, QLL>; n using UMIQLL = unordered_map<int, QLL>; n using SLD = set<LD>; n using VLD = vector<LD>; n using MLD = map<LD, LD>; n using MILD = map<int, LD>; n using UMILD = unordered_map<int, LD>; n using SPDD = set<PDD>; n using VPDD = vector<PDD>; n using MPDD = map<PDD, PDD>; n using MIPDD = map<int, PDD>; n using UMIPDD = unordered_map<int, PDD>; n using SVI = set<VI>; n using VVI = vector<VI>; n using MVI = map<VI, VI>; n using MIVI = map<int, VI>; n using UMIVI = unordered_map<int, VI>; n using STLL = set<TLL>; n using VTLL = vector<TLL>; n using MTLL = map<TLL, TLL>; n using MITLL = map<int, TLL>; n using UMITLL = unordered_map<int, TLL>; n using SUI = set<UI>; n using VUI = vector<UI>; n using MUI = map<UI, UI>; n using MIUI = map<int, UI>; n using UMIUI = unordered_map<int, UI>; n using SPII = set<PII>; n using VPII = vector<PII>; n using MPII = map<PII, PII>; n using MIPII = map<int, PII>; n using UMIPII = unordered_map<int, PII>; n using SPLL = set<PLL>; n using VPLL = vector<PLL>; n using MPLL = map<PLL, PLL>; n using MIPLL = map<int, PLL>; n using UMIPLL = unordered_map<int, PLL>; n using SSI = set<SI>; n using VSI = vector<SI>; n using MSI = map<SI, SI>; n using MISI = map<int, SI>; n using UMISI = unordered_map<int, SI>; n using SVVI = set<VVI>; n using VVVI = vector<VVI>; n using MVVI = map<VVI, VVI>; n using MIVVI = map<int, VVI>; n using UMIVVI = unordered_map<int, VVI>; n using UMII = unordered_map<int, int>; n ULL randULL() { n   return ((ULL)rand()) ^ ((ULL)rand() << 15) ^ ((ULL)rand() << 30) ^ n          ((ULL)rand() << 45) ^ ((ULL)rand() << 60); n } n using STDD = set<TDD>; n using VTDD = vector<TDD>; n using MTDD = map<TDD, TDD>; n using MITDD = map<int, TDD>; n using UMITDD = unordered_map<int, TDD>; n using SQDD = set<QDD>; n using VQDD = vector<QDD>; n using MQDD = map<QDD, QDD>; n using MIQDD = map<int, QDD>; n using UMIQDD = unordered_map<int, QDD>; n int popc(int x) { return __builtin_popcount(x); } n int popc(UI x) { return __builtin_popcount(x); } n int popc(LL x) { return __builtin_popcountll(x); } n int popc(ULL x) { return __builtin_popcountll(x); } n int ctz(int x) { return __builtin_ctz(x); } n int ctz(UI x) { return __builtin_ctz(x); } n int ctz(LL x) { return __builtin_ctzll(x); } n int ctz(ULL x) { return __builtin_ctzll(x); } n int clz(int x) { return __builtin_clz(x); } n int clz(UI x) { return __builtin_clz(x); } n int clz(LL x) { return __builtin_clzll(x); } n int clz(ULL x) { return __builtin_clzll(x); } n int bit_parity(int x) { return __builtin_parity(x); } n int bit_parity(UI x) { return __builtin_parity(x); } n int bit_parity(LL x) { return __builtin_parityll(x); } n int bit_parity(ULL x) { return __builtin_parityll(x); } n template <class T, class U> n bool one_of(T x, U y) { n   return x == y; n } n template <class T, class U, class... V> n bool one_of(T x, U y, V... z) { n   return x == y || one_of(x, z...); n } n template <class T> n bool diff(T _) { n   return true; n } n template <class T, class... U> n bool diff(T x, U... y) { n   return !one_of(x, y...) && diff(y...); n } n template <class T, class U> n bool equal(T x, U y) { n   return x == y; n } n template <class T, class U, class... V> n bool equal(T x, U y, V... z) { n   return x == y && equal(x, z...); n } n template <class T, class U> n bool in_order(T x, U y) { n   return x <= y; n } n template <class T, class U, class... V> n bool in_order(T x, U y, V... z) { n   return x <= y && in_order(y, z...); n } n template <class T, class U> n bool in_strorder(T x, U y) { n   return x < y; n } n template <class T, class U, class... V> n bool in_strorder(T x, U y, V... z) { n   return x < y && in_strorder(y, z...); n } n template <class T> n void swap3(T &x, T &y, T &z) { n   swap(x, y); n   swap(x, z); n } n template <class T> n pair<T, T> dup(T x) { n   return make_pair(x, x); n } n template <class T> n pair<pair<T, T>, T> thrice(T x) { n   return make_pair(make_pair(x, x), x); n } n template <class T> n pair<pair<T, T>, pair<T, T>> fourfold(T x) { n   return make_pair(make_pair(x, x), make_pair(x, x)); n } n template <class T, class U, class V> n T safvec(const vector<T> &v, int i, U low, V high) { n   if (i < 0) return low; n   if (i >= ((int)(v).size())) return high; n   return v[i]; n } n template <class T, class U> n T safar(T *a, int i, U low) { n   if (i < 0) return low; n   return a[i]; n } n template <class T, class U, class V> n auto med(const T &a, const U &b, const V &c) -> decltype(1 ? a : (1 ? b : c)) { n   return my_min(my_max(a, b), my_max(my_min(a, b), c)); n } n namespace std { n template <class T, class U> n struct hash<pair<T, U>> { n   size_t operator()(const pair<T, U> &a) const { n     return (hash<T>()(a.first) * 1420343LL ^ hash<U>()(a.second) * 923275LL) % n            1463984161; n   } n }; n }  // namespace std n template <class T, class U> n auto my_min(const U &x, const T &y) -> decltype(1 ? x : y) { n   return x < y ? x : y; n } n template <class T, class U> n bool mini(U &x, T y) { n   if (y < x) { n     x = y; n     return true; n   } n   return false; n } n template <class T, class U, class V> n auto my_min(const T &a, const U &b, const V &c) n     -> decltype(1 ? a : (1 ? b : c)) { n   return my_min(a, my_min(b, c)); n } n template <class T, class U, class V, class W> n auto my_min(const T &a, const U &b, const V &c, const W &d) n     -> decltype(1 ? a : (1 ? b : (1 ? c : d))) { n   return my_min(a, my_min(b, c, d)); n } n template <class T, class U> n auto my_max(const U &x, const T &y) -> decltype(1 ? x : y) { n   return x > y ? x : y; n } n template <class T, class U> n bool maxi(U &x, T y) { n   if (y > x) { n     x = y; n     return true; n   } n   return false; n } n template <class T, class U, class V> n auto my_max(const T &a, const U &b, const V &c) n     -> decltype(1 ? a : (1 ? b : c)) { n   return my_max(a, my_max(b, c)); n } n template <class T, class U, class V, class W> n auto my_max(const T &a, const U &b, const V &c, const W &d) n     -> decltype(1 ? a : (1 ? b : (1 ? c : d))) { n   return my_max(a, my_max(b, c, d)); n } n template <class T> n T brange(int l, int r) { n   return ~(~((T)0) << (r - l + 1)) << l; n } n template <class T> n T brange(int l, int r, int second) { n   return (brange<T>(l, l + (r - l) / second * second - 1) / n           brange<T>(0, second - 1)) | n          ((T)1 << (l + (r - l) / second * second)); n } n template <class T> n auto O2kQ(T x, int i, int j) n     -> vector<typename remove_reference<decltype(*x.end())>::type> { n   vector<typename remove_reference<decltype(*x.end())>::type> ans; n   for (auto c : x) n     if ((--i < 0) & (j-- >= 0)) ans.push_back(c); n   return ans; n } n template <class T> n vector<T> O2kQ(const T *x, int i, int j) { n   vector<T> ans; n   for (int _ = i; _ <= (int)(j); _++) ans.push_back(x[_]); n   return ans; n } n int CON_BOUND = 10; n string E0ms() { return   ; } n template <class T> n string E0ms(T x) { n   stringstream os; n   os << boolalpha << x; n   return os.str(); n } n template <class T, class... U> n string E0ms(T x, U... y) { n   return E0ms(x) +  ,   + E0ms(y...); n } n string SqC6(bool x) { return x ?  true  :  false ; } n template <class T> n typename enable_if<is_integral<T>::value, string>::type SqC6(T r) { n   string a; n   for (int i = 8 * sizeof(T) - 1; i >= (int)(0); i--) { n     if (i % 5 == 4) a +=  . ; n     a +=  0  + !!(((T)1 << i) & r); n   } n   return a; n } n template <class T, class C> n string SqC6(pair<T, C>); n template <class T> n auto SqC6(T x) -> decltype(x.end(), string()) { n   string a =   ; n   for (auto c : x) { n     if (((int)(a).size())) a +=  ,  ; n     a += SqC6(c); n   } n   return  {  + a +  }_  + to_string(((int)(x).size())); n } n template <class T, class C> n string SqC6(pair<T, C> x) { n   return  <  + SqC6(x.first) +  ,   + SqC6(x.second) +  > ; n } n template <class T, int N> n T &arrp(T a[][N], PII x) { n   return a[x.first][x.second]; n } n const int mod = 1e9 + 7; n LL mpow(LL b, int e) { n   LL ans = 1; n   while (e) { n     if (e & 1) ans = ans * b % mod; n     b = b * b % mod; n     e /= 2; n   } n   return ans; n } n struct zet_p { n   int v; n   int get() { return v; } n   zet_p(LL x = 0) { v = x % mod; } n   zet_p operator+(zet_p x) { return (v + x.v) % mod; } n   zet_p operator-(zet_p x) { return v - x.v; } n   zet_p operator*(zet_p x) { return v * 1ll * x.v; } n   zet_p operator/(zet_p a) { return v * mpow(a.v, mod - 2); } n }; n const bool deb = false; n struct frac_mod { n   int n, d; n   frac_mod(int x = 0) { n     n = x % mod; n     d = 1; n   } n   frac_mod(int x, int y) { n     n = x; n     d = y; n   } n   frac_mod operator+(frac_mod x) { n     return {(int)((x.d * 1ll * n + d * 1ll * x.n) % mod), x.d * d % mod}; n   } n   frac_mod operator-(frac_mod x) { n     return {(int)((n * 1ll * x.d - x.n * 1ll * d) % mod), x.d * d % mod}; n   } n   frac_mod operator*(frac_mod x) { n     return {(int)((n * (LL)x.n) % mod), (int)((d * (LL)x.d) % mod)}; n   } n   frac_mod operator/(frac_mod x) { n     return {(int)(n * (LL)x.d % mod), (int)(d * (LL)x.n % mod)}; n   } n   int get() { n     int ans = n * mpow(d, mod - 2) % mod; n     if (ans < 0) ans += mod; n     return ans; n   } n }; n template <class T> n typename enable_if<is_arithmetic<T>::value, frac_mod>::type operator+( n     frac_mod x, T y) { n   return x + frac_mod(y); n } n template <class T> n typename enable_if<is_arithmetic<T>::value, frac_mod>::type operator+( n     T x, frac_mod y) { n   return frac_mod(x) + y; n } n template <class T> n frac_mod &operator+=(frac_mod &x, T y) { n   return x = x + y; n } n template <class T> n typename enable_if<is_arithmetic<T>::value, frac_mod>::type operator-( n     frac_mod x, T y) { n   return x - frac_mod(y); n } n template <class T> n typename enable_if<is_arithmetic<T>::value, frac_mod>::type operator-( n     T x, frac_mod y) { n   return frac_mod(x) - y; n } n template <class T> n frac_mod &operator-=(frac_mod &x, T y) { n   return x = x - y; n } n template <class T> n typename enable_if<is_arithmetic<T>::value, frac_mod>::type operator*( n     frac_mod x, T y) { n   return x * frac_mod(y); n } n template <class T> n typename enable_if<is_arithmetic<T>::value, frac_mod>::type operator*( n     T x, frac_mod y) { n   return frac_mod(x) * y; n } n template <class T> n frac_mod &operator*=(frac_mod &x, T y) { n   return x = x * y; n } n template <class T> n typename enable_if<is_arithmetic<T>::value, frac_mod>::type operator/( n     frac_mod x, T y) { n   return x / frac_mod(y); n } n template <class T> n typename enable_if<is_arithmetic<T>::value, frac_mod>::type operator/( n     T x, frac_mod y) { n   return frac_mod(x) / y; n } n template <class T> n frac_mod &operator/=(frac_mod &x, T y) { n   return x = x / y; n } n template <class T, class C> n ostream &operator<<(ostream &ans, pair<T, C> x) { n   return ans <<  <  << x.first <<  ,   << x.second <<  > ; n } n template <class T> n auto operator<<(ostream &o, T x) -> n     typename enable_if<!is_same<T, string>::value, decltype(x.end(), o)>::type { n   o <<  { ; n   int i = 0; n   for (auto c : x) { n     if (i++ == ((int)(x).size()) - 1 || ((int)(x).size()) < CON_BOUND + 2 || n         i < CON_BOUND) { n       if (i - 1 && n           (i != ((int)(x).size()) || ((int)(x).size()) < CON_BOUND + 2)) n         o <<  ,  ; n       o << c; n     } n     if (i == CON_BOUND && ((int)(x).size()) > CON_BOUND + 1) o <<   ...  ; n   } n   return o <<  }_  << x.size(); n } n string b7Pe(string x) { n   int dep = 0; n   for (char c : x) { n     for (char d :  ([{ ) n       if (c == d) dep++; n     for (char d :  }]) ) n       if (c == d) dep--; n     for (char d :  +-*/%^<>=&|?, ) n       if (c == d && !dep) return  (  + x +  ) ; n   } n   return x; n } n template <class T, class U> n pair<U, T> pinv(pair<T, U> x) { n   return make_pair(x.second, x.first); n } n template <class T> n struct Wt71 { n   T c; n   int l, r, L, R; n }; n template <class T> n ostream &operator<<(ostream &o, Wt71<T> M) { n   o <<   n ; n   for (int i = M.l; i <= (int)(M.r); i++) { n     o <<      << i <<  : |  ; n     for (int j = M.L; j <= (int)(M.R); j++) { n       o << M.c[i][j] << ((j - M.L + 1) % 5 ?     :  ;  ); n     } n     o <<   n ; n   } n   return o; n } n template <class T> n Wt71<T> q9cX(T a, int i, int j, int k, int q) { n   return {a, i, j, k, q}; n } n int primes[] = {2,   3,   5,   7,   11,  13,  17,  19,  23,  29,  31,  37,  41, n                 43,  47,  53,  59,  61,  67,  71,  73,  79,  83,  89,  97,  101, n                 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, n                 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, n                 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, n                 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, n                 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, n                 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, n                 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, n                 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, n                 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, n                 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, n                 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997}, n     big_primes[] = {1307533217, 1336158883, 1339172111, 1367797777, 1376837461, n                     1399436671, 1426555723, 1440115249, 1444635091, 1489833511, n                     1553111299, 1562150983, 1587763421, 1610362631, 1652547823, n                     1666107349, 1700759471, 1782116627, 1797182767, 1810742293, n                     1818275363, 1892099449, 1904152361, 1919218501, 1940311097, n                     1944830939, 1968936763, 1977976447, 1985509517, 1990029359}, n     gens[] = {1,   2,   3,   5,   2,   11,  3,   14,  19,  11,  17,  32,  30, n               34,  29,  19,  34,  31,  63,  33,  5,   63,  53,  58,  40,  83, n               21,  18,  99,  33,  106, 40,  85,  109, 40,  77,  91,  120, 105, n               91,  79,  53,  182, 10,  184, 48,  48,  150, 168, 72,  65,  46, n               31,  216, 101, 134, 163, 147, 93,  42,  69,  7,   151, 308, 112, n               12,  227, 185, 214, 305, 163, 234, 154, 316, 3,   11,  233, 390, n               271, 173, 82,  407, 13,  135, 414, 391, 177, 293, 426, 432, 337, n               281, 385, 103, 95,  152, 12,  371, 390, 77,  532, 34,  287, 73, n               308, 493, 258, 549, 528, 411, 12,  283, 614, 596, 622, 309, 91, n               511, 287, 433, 585, 123, 2,   170, 183, 341, 459, 322, 333, 337, n               507, 718, 82,  517, 396, 315, 565, 48,  362, 617, 776, 425, 584, n               231, 578, 395, 127, 27,  506, 435, 727, 659, 697, 385, 290, 109, n               430, 422, 344, 849, 513, 453, 852, 920, 152, 482, 653, 271}, n     big_gens[] = {661761153,  1315209189, 235649158,  80905954,  861543922, n                   677870461,  332266749,  1192707557, 820697698, 93737534, n                   1395132003, 176849700,  1113502216, 860516128, 1543755630, n                   328298286,  1219407972, 1407392293, 733053145, 400000570, n                   1081174233, 847228024,  1516266762, 83276926,  500618997, n                   44975430,   47827763,   1411328206, 151880843, 19696955}; n LL vbig_primes[] = { n     1223771071LL,         2557943639LL,         4625922079LL, n     8465729693LL,         16196062793LL,        32628322457LL, n     64355194333LL,        128143942897LL,       256728067087LL, n     512368953949LL,       1024440714547LL,      2048302681847LL, n     4096121499499LL,      8192933500519LL,      16384652744209LL, n     32768255472209LL,     65536007832649LL,     131072225217863LL, n     262144391360893LL,    524288060819213LL,    1048576249040491LL, n     2097152266756471LL,   4194304028438527LL,   8388608209001387LL, n     16777216572671047LL,  33554432072300339LL,  67108864903274897LL, n     134217728402776373LL, 268435456069367221LL, 536870912016065747LL}; n const int inf = 1e9, NONE = -1; n const LL llinf = 3e18; n const char *sc2 =  %d%d , *sc3 =  %d%d%d , *sc4 =  %d%d%d%d , *pr2 =  %d %d n , n            *pr3 =  %d %d %d n , *pr4 =  %d %d %d %d n ; n VI factor(int x) { n   VI ans; n   for (int p = 2; p * p <= x; ++p) n     while (x % p == 0) { n       ans.push_back(p); n       x /= p; n     } n   if (x > 1) ans.push_back(x); n   return ans; n } n template <class T, class B, class C, class D> n auto operator+(pair<T, B> x, pair<C, D> y) n     -> pair<decltype(x.first + y.first), decltype(x.second + y.second)> { n   return make_pair(x.first + y.first, x.second + y.second); n } n template <class T, class B, class C> n auto operator+(pair<T, B> x, C y) n     -> pair<decltype(x.first + y), decltype(x.second + y)> { n   return make_pair(x.first + y, x.second + y); n } n template <class T, class C, class D> n auto operator+(T x, pair<C, D> y) n     -> pair<decltype(x + y.first), decltype(x + y.second)> { n   return make_pair(x + y.first, x + y.second); n } n template <class T, class B, class C, class D> n auto operator-(pair<T, B> x, pair<C, D> y) n     -> pair<decltype(x.first - y.first), decltype(x.second - y.second)> { n   return make_pair(x.first - y.first, x.second - y.second); n } n template <class T, class B, class C> n auto operator-(pair<T, B> x, C y) n     -> pair<decltype(x.first - y), decltype(x.second - y)> { n   return make_pair(x.first - y, x.second - y); n } n template <class T, class C, class D> n auto operator-(T x, pair<C, D> y) n     -> pair<decltype(x - y.first), decltype(x - y.second)> { n   return make_pair(x - y.first, x - y.second); n } n template <class T, class B, class C, class D> n auto operator/(pair<T, B> x, pair<C, D> y) n     -> pair<decltype(x.first / y.first), decltype(x.second / y.second)> { n   return make_pair(x.first / y.first, x.second / y.second); n } n template <class T, class B, class C> n auto operator/(pair<T, B> x, C y) n     -> pair<decltype(x.first / y), decltype(x.second / y)> { n   return make_pair(x.first / y, x.second / y); n } n template <class T, class C, class D> n auto operator/(T x, pair<C, D> y) n     -> pair<decltype(x / y.first), decltype(x / y.second)> { n   return make_pair(x / y.first, x / y.second); n } n template <class T, class B, class C, class D> n auto operator*(pair<T, B> x, pair<C, D> y) n     -> pair<decltype(x.first * y.first), decltype(x.second * y.second)> { n   return make_pair(x.first * y.first, x.second * y.second); n } n template <class T, class B, class C> n auto operator*(pair<T, B> x, C y) n     -> pair<decltype(x.first * y), decltype(x.second * y)> { n   return make_pair(x.first * y, x.second * y); n } n template <class T, class C, class D> n auto operator*(T x, pair<C, D> y) n     -> pair<decltype(x * y.first), decltype(x * y.second)> { n   return make_pair(x * y.first, x * y.second); n } n template <class T, class B, class C, class D> n auto operator%(pair<T, B> x, pair<C, D> y) n     -> pair<decltype(x.first % y.first), decltype(x.second % y.second)> { n   return make_pair(x.first % y.first, x.second % y.second); n } n template <class T, class B, class C> n auto operator%(pair<T, B> x, C y) n     -> pair<decltype(x.first % y), decltype(x.second % y)> { n   return make_pair(x.first % y, x.second % y); n } n template <class T, class C, class D> n auto operator%(T x, pair<C, D> y) n     -> pair<decltype(x % y.first), decltype(x % y.second)> { n   return make_pair(x % y.first, x % y.second); n } n template <class T, class B, class C, class D> n auto operator&(pair<T, B> x, pair<C, D> y) n     -> pair<decltype(x.first & y.first), decltype(x.second & y.second)> { n   return make_pair(x.first & y.first, x.second & y.second); n } n template <class T, class B, class C> n auto operator&(pair<T, B> x, C y) n     -> pair<decltype(x.first & y), decltype(x.second & y)> { n   return make_pair(x.first & y, x.second & y); n } n template <class T, class C, class D> n auto operator&(T x, pair<C, D> y) n     -> pair<decltype(x & y.first), decltype(x & y.second)> { n   return make_pair(x & y.first, x & y.second); n } n template <class T, class B, class C, class D> n auto operator|(pair<T, B> x, pair<C, D> y) n     -> pair<decltype(x.first | y.first), decltype(x.second | y.second)> { n   return make_pair(x.first | y.first, x.second | y.second); n } n template <class T, class B, class C> n auto operator|(pair<T, B> x, C y) n     -> pair<decltype(x.first | y), decltype(x.second | y)> { n   return make_pair(x.first | y, x.second | y); n } n template <class T, class C, class D> n auto operator|(T x, pair<C, D> y) n     -> pair<decltype(x | y.first), decltype(x | y.second)> { n   return make_pair(x | y.first, x | y.second); n } n template <class T, class B, class C, class D> n auto operator^(pair<T, B> x, pair<C, D> y) n     -> pair<decltype(x.first ^ y.first), decltype(x.second ^ y.second)> { n   return make_pair(x.first ^ y.first, x.second ^ y.second); n } n template <class T, class B, class C> n auto operator^(pair<T, B> x, C y) n     -> pair<decltype(x.first ^ y), decltype(x.second ^ y)> { n   return make_pair(x.first ^ y, x.second ^ y); n } n template <class T, class C, class D> n auto operator^(T x, pair<C, D> y) n     -> pair<decltype(x ^ y.first), decltype(x ^ y.second)> { n   return make_pair(x ^ y.first, x ^ y.second); n } n template <class T, class B, class C, class D> n auto operator&&(pair<T, B> x, pair<C, D> y) n     -> pair<decltype(x.first && y.first), decltype(x.second && y.second)> { n   return make_pair(x.first && y.first, x.second && y.second); n } n template <class T, class B, class C> n auto operator&&(pair<T, B> x, C y) n     -> pair<decltype(x.first && y), decltype(x.second && y)> { n   return make_pair(x.first && y, x.second && y); n } n template <class T, class C, class D> n auto operator&&(T x, pair<C, D> y) n     -> pair<decltype(x && y.first), decltype(x && y.second)> { n   return make_pair(x && y.first, x && y.second); n } n template <class T, class B, class C, class D> n auto operator||(pair<T, B> x, pair<C, D> y) n     -> pair<decltype(x.first || y.first), decltype(x.second || y.second)> { n   return make_pair(x.first || y.first, x.second || y.second); n } n template <class T, class B, class C> n auto operator||(pair<T, B> x, C y) n     -> pair<decltype(x.first || y), decltype(x.second || y)> { n   return make_pair(x.first || y, x.second || y); n } n template <class T, class C, class D> n auto operator||(T x, pair<C, D> y) n     -> pair<decltype(x || y.first), decltype(x || y.second)> { n   return make_pair(x || y.first, x || y.second); n } n template <class T, class B> n pair<T, B> &operator++(pair<T, B> &x) { n   ++x.first, ++x.second; n   return x; n } n template <class T, class B> n pair<T, B> operator++(pair<T, B> &x, int _) { n   return make_pair(x.first++, x.second++); n } n template <class T, class B> n pair<T, B> &operator--(pair<T, B> &x) { n   --x.first, --x.second; n   return x; n } n template <class T, class B> n pair<T, B> operator--(pair<T, B> &x, int _) { n   return make_pair(x.first--, x.second--); n } n template <class T, class B, class C, class D> n pair<T, B> &operator+=(pair<T, B> &x, pair<C, D> y) { n   x.first += y.first; n   x.second += y.second; n   return x; n } n template <class T, class B, class C> n pair<T, B> &operator+=(pair<T, B> &x, C y) { n   x.first += y; n   x.second += y; n   return x; n } n template <class T, class B, class C, class D> n pair<T, B> &operator-=(pair<T, B> &x, pair<C, D> y) { n   x.first -= y.first; n   x.second -= y.second; n   return x; n } n template <class T, class B, class C> n pair<T, B> &operator-=(pair<T, B> &x, C y) { n   x.first -= y; n   x.second -= y; n   return x; n } n template <class T, class B, class C, class D> n pair<T, B> &operator*=(pair<T, B> &x, pair<C, D> y) { n   x.first *= y.first; n   x.second *= y.second; n   return x; n } n template <class T, class B, class C> n pair<T, B> &operator*=(pair<T, B> &x, C y) { n   x.first *= y; n   x.second *= y; n   return x; n } n template <class T, class B, class C, class D> n pair<T, B> &operator/=(pair<T, B> &x, pair<C, D> y) { n   x.first /= y.first; n   x.second /= y.second; n   return x; n } n template <class T, class B, class C> n pair<T, B> &operator/=(pair<T, B> &x, C y) { n   x.first /= y; n   x.second /= y; n   return x; n } n template <class T, class B, class C, class D> n pair<T, B> &operator%=(pair<T, B> &x, pair<C, D> y) { n   x.first %= y.first; n   x.second %= y.second; n   return x; n } n template <class T, class B, class C> n pair<T, B> &operator%=(pair<T, B> &x, C y) { n   x.first %= y; n   x.second %= y; n   return x; n } n template <class T, class B, class C, class D> n pair<T, B> &operator^=(pair<T, B> &x, pair<C, D> y) { n   x.first ^= y.first; n   x.second ^= y.second; n   return x; n } n template <class T, class B, class C> n pair<T, B> &operator^=(pair<T, B> &x, C y) { n   x.first ^= y; n   x.second ^= y; n   return x; n } n template <class T, class B, class C, class D> n pair<T, B> &operator&=(pair<T, B> &x, pair<C, D> y) { n   x.first &= y.first; n   x.second &= y.second; n   return x; n } n template <class T, class B, class C> n pair<T, B> &operator&=(pair<T, B> &x, C y) { n   x.first &= y; n   x.second &= y; n   return x; n } n template <class T, class B, class C, class D> n pair<T, B> &operator|=(pair<T, B> &x, pair<C, D> y) { n   x.first |= y.first; n   x.second |= y.second; n   return x; n } n template <class T, class B, class C> n pair<T, B> &operator|=(pair<T, B> &x, C y) { n   x.first |= y; n   x.second |= y; n   return x; n } n template <class T, class B> n auto operator*(pair<T, B> x) n     -> pair<typename remove_reference<decltype(*x.first)>::type, n             typename remove_reference<decltype(*x.second)>::type> { n   return make_pair(*x.first, *x.second); n } n template <class T, class B> n auto operator~(pair<T, B> x) n     -> pair<typename remove_reference<decltype(~x.first)>::type, n             typename remove_reference<decltype(~x.second)>::type> { n   return make_pair(~x.first, ~x.second); n } n template <class T, class B> n auto operator!(pair<T, B> x) n     -> pair<typename remove_reference<decltype(!x.first)>::type, n             typename remove_reference<decltype(!x.second)>::type> { n   return make_pair(!x.first, !x.second); n } n template <class T, class B> n auto operator-(pair<T, B> x) n     -> pair<typename remove_reference<decltype(-x.first)>::type, n             typename remove_reference<decltype(-x.second)>::type> { n   return make_pair(-x.first, -x.second); n } n template <class T> n typename enable_if<is_arithmetic<T>::value, zet_p>::type operator+(zet_p x, n                                                                    T y) { n   return x + zet_p(y); n } n template <class T> n typename enable_if<is_arithmetic<T>::value, zet_p>::type operator+(T x, n                                                                    zet_p y) { n   return zet_p(x) + y; n } n template <class T> n zet_p &operator+=(zet_p &x, T y) { n   return x = x + y; n } n template <class T> n typename enable_if<is_arithmetic<T>::value, zet_p>::type operator-(zet_p x, n                                                                    T y) { n   return x - zet_p(y); n } n template <class T> n typename enable_if<is_arithmetic<T>::value, zet_p>::type operator-(T x, n                                                                    zet_p y) { n   return zet_p(x) - y; n } n template <class T> n zet_p &operator-=(zet_p &x, T y) { n   return x = x - y; n } n template <class T> n typename enable_if<is_arithmetic<T>::value, zet_p>::type operator*(zet_p x, n                                                                    T y) { n   return x * zet_p(y); n } n template <class T> n typename enable_if<is_arithmetic<T>::value, zet_p>::type operator*(T x, n                                                                    zet_p y) { n   return zet_p(x) * y; n } n template <class T> n zet_p &operator*=(zet_p &x, T y) { n   return x = x * y; n } n template <class T> n typename enable_if<is_arithmetic<T>::value, zet_p>::type operator/(zet_p x, n                                                                    T y) { n   return x / zet_p(y); n } n template <class T> n typename enable_if<is_arithmetic<T>::value, zet_p>::type operator/(T x, n                                                                    zet_p y) { n   return zet_p(x) / y; n } n template <class T> n zet_p &operator/=(zet_p &x, T y) { n   return x = x / y; n } n void jGB4A(); n const int MN = 1e5 + 44; n SPII best[MN]; n void add(SPII &se, PII val) { n   ; n   auto pre = se.upper_bound(make_pair(val.first, inf)); n   pre--; n   if (pre->second > val.second) { n     ; n     return; n   } n   while (pre != se.end() && pre->second <= val.second) { n     if (pre->first >= val.first) n       se.erase(pre++); n     else n       pre++; n   } n   se.insert(val); n   ; n } n int main() { n   SPII test; n   for (int i = 0; i < (int)(10); i++) test.insert(make_pair(i * 3, i * 3)); n   add(test, make_pair(6, 6)); n   add(test, make_pair(6, 7)); n   add(test, make_pair(6, 6)); n   add(test, make_pair(0, 7)); n   ; n   ; n   ; n   ; n   cerr << setprecision(10); n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= (int)(n); i++) { n     best[i].insert(make_pair(-inf, 0)); n   } n   for (int i = 0; i < (int)(m); i++) { n     int a, b, x; n     scanf( %d%d%d , &a, &b, &x); n     auto it = best[a].upper_bound(make_pair(x, -inf)); n     ; n     ; n     it--; n     ; n     add(best[b], make_pair(x, it->second + 1)); n   } n   int ans = 0; n   for (int i = 1; i <= (int)(n); i++) { n     auto l = best[i].end(); n     l--; n     maxi(ans, l->second); n   } n   printf( %d n , ans); n   jGB4A(); n } n void jGB4A() { n #pragma GCC diagnostic ignored  -Woverflow  n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   ; n   while (deb && getchar() != EOF) n     ; n   exit(0); n } n


#include <bits/stdc++.h> n using namespace std; n const int MXN = 1e5 + 1; n int n, dp[MXN], k[MXN], ans = 1, rg[MXN], res, maxi; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> k[i]; n     dp[k[i]] += dp[k[i] - 1] + 1; n   } n   for (int i = 1; i <= n; i++) { n     if (dp[k[i]] > maxi) { n       maxi = dp[k[i]]; n     } n   } n   cout << n - maxi; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void base() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     int a, b; n     cin >> a >> b; n     if (a > b) swap(a, b); n     if (a * 2 < b) n       cout <<  NO n ; n     else { n       int dif = b - a; n       if (a - dif >= 0 && b - 2 * dif >= 0 && (a - dif) % 3 == 0) { n         cout <<  YES n ; n       } else { n         cout <<  NO n ; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class c> n struct rge { n   c b, e; n }; n template <class c> n rge<c> range(c i, c j) { n   return rge<c>{i, j}; n } n template <class c> n auto dud(c* x) -> decltype(cerr << *x, 0); n template <class c> n char dud(...); n struct debug { n   template <class c> n   debug& operator<<(const c&) { n     return *this; n   } n }; n long long int power(long long int x, long long int y, n                     long long int mod = 1000000007) { n   long long int ret = 1; n   x = x % mod; n   while (y) { n     if (y & 1) ret = (ret * x) % mod; n     y = y >> 1; n     x = (x * x) % mod; n   } n   return ret % mod; n } n long long int isprime(long long int x) { n   for (long long int i = 2; i * i <= x; i++) n     if (x % i == 0) return 0; n   return 1; n } n void solve() { n   long long int n, k; n   cin >> n >> k; n   if (n <= k) { n     cout << 1 << endl; n     return; n   } n   vector<long long int> fact; n   for (long long int i = 1; i * i <= n; i++) { n     if (n % i == 0) { n       if (i <= k) fact.push_back(i); n       if ((n / i) <= k) fact.push_back(n / i); n     } n   } n   sort(fact.begin(), fact.end()); n   cout << n / fact.back() << endl; n } n signed main() { n   long long int t; n   cin >> t; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int main(void) { n   char sav[200]; n   scanf( %s , sav); n   int flag = 0; n   int len = strlen(sav); n   for (int i = 0; i < len; i++) { n     if (sav[i] ==  1 ) n       continue; n     else if (sav[i] ==  4 ) { n       if (i - 1 >= 0 && sav[i - 1] ==  1 ) n         continue; n       else if (i - 1 >= 0 && sav[i - 1] ==  4 ) { n         if (i - 2 >= 0 && sav[i - 2] ==  1 ) n           continue; n         else n           flag = 1; n       } else n         flag = 1; n     } else n       flag = 1; n   } n   if (flag) n     cout <<  NO  << endl; n   else n     cout <<  YES  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T1, class T2, class T3> n bool _IN(T1 x, T2 y, T3 z) { n   return x <= y && x >= z || x <= z && x >= y; n } n unsigned long long gcd(unsigned long long a, unsigned long long b) { n   if (!b) return a; n   while (b ^= a ^= b ^= a %= b) n     ; n   return a; n } n extern const long long mod; n long long ksm(long long a, long long b) { n   long long res = 1; n   a %= mod; n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n   } n   return res; n } n char DATaJNTFnlmAoya[2]; n double PDlaQLoCkCjCKyr; n bool S(char* a) { return scanf( %s , a) == 1; } n bool S(int& a) { return scanf( %d , &a) == 1; } n bool S(bool& a) { return scanf( %d , &a) == 1; } n bool S(unsigned& a) { return scanf( %u , &a) == 1; } n bool S(float& a) { return scanf( %f , &a) == 1; } n bool S(double& a) { return scanf( %lf , &a) == 1; } n bool S(long long& a) { return scanf( %I64d , &a) == 1; } n bool S(unsigned long long& a) { return scanf( %I64u , &a) == 1; } n bool S(long double& a) { n   if (scanf( %lf , &PDlaQLoCkCjCKyr) == -1) return 0; n   a = PDlaQLoCkCjCKyr; n   return 1; n } n bool S(char& a) { n   if (scanf( %1s , DATaJNTFnlmAoya) == -1) return 0; n   a = *DATaJNTFnlmAoya; n   return 1; n } n bool SL(char* a) { n   a[0] = 0; n   while (gets(a) && !a[0]) n     ; n   return a[0]; n } n void _P(const int& x) { printf( %d , x); } n void _P(const bool& x) { printf( %d , x); } n void _P(const unsigned& x) { printf( %u , x); } n void _P(const char& x) { printf( %c , x); } n void _P(const char* x) { printf( %s , x); } n void _P(const string& x) { printf( %s , x.c_str()); } n void _P(const long long& x) { printf( %I64d , x); } n void _P(const unsigned long long& x) { printf( %I64u , x); } n void _P(const float& x) { printf( %.2f , x); } n void _P(const double& x) { printf( %.2f , x); } n void _P(const long double& x) { printf( %.2f , (double)x); } n template <class T1, class T2> n bool S(T1& a, T2& b) { n   return S(a) + S(b) == 2; n } n template <class T1, class T2, class T3> n bool S(T1& a, T2& b, T3& c) { n   return S(a) + S(b) + S(c) == 3; n } n template <class T1, class T2, class T3, class T4> n bool S(T1& a, T2& b, T3& c, T4& d) { n   return S(a) + S(b) + S(c) + S(d) == 4; n } n template <class T1, class T2, class T3, class T4, class T5> n bool S(T1& a, T2& b, T3& c, T4& d, T5& e) { n   return S(a) + S(b) + S(c) + S(d) + S(e) == 5; n } n template <class T1> n void P(const T1& a) { n   _P(a); n   putchar(   ); n } n template <class T1, class T2> n void P(const T1& a, const T2& b) { n   _P(a); n   putchar(   ); n   _P(b); n   putchar(   ); n } n template <class T1> n void PN(const T1& a) { n   _P(a); n   puts(  ); n } n template <class T1, class T2> n void PN(const T1& a, const T2& b) { n   _P(a); n   putchar(   ); n   _P(b); n   puts(  ); n } n template <class T1, class T2, class T3> n void PN(const T1& a, const T2& b, const T3& c) { n   _P(a); n   putchar(   ); n   _P(b); n   putchar(   ); n   _P(c); n   puts(  ); n } n template <class T1, class T2, class T3, class T4> n void PN(const T1& a, const T2& b, const T3& c, const T4& d) { n   _P(a); n   putchar(   ); n   _P(b); n   putchar(   ); n   _P(c); n   putchar(   ); n   _P(d); n   puts(  ); n } n template <class T1, class T2, class T3, class T4, class T5> n void PN(const T1& a, const T2& b, const T3& c, const T4& d, const T5& e) { n   _P(a); n   putchar(   ); n   _P(b); n   putchar(   ); n   _P(c); n   putchar(   ); n   _P(d); n   putchar(   ); n   _P(e); n   puts(  ); n } n template <class T> n void PA(T* a, int n) { n   for (long long i = 0, pJNwFPtlXiwFoIv = (n - 1); i < pJNwFPtlXiwFoIv; i++) n     _P(a[i]), putchar(   ); n   PN(a[n - 1]); n } n template <class T> n void PA(const T& x) { n   for (__typeof((x).begin()) it = (x).begin(), CluhxSchFuDeugk = (x).end(); n        it != CluhxSchFuDeugk; it++) { n     _P(*it); n     if (it == --x.end()) n       puts(  ); n     else n       putchar(   ); n   } n } n int kase; n const double pi = 4 * atan(1); n const double ep = 1e-9; n const int INF = 0x3f3f3f3f; n const long long INFL = 0x3f3f3f3f3f3f3f3fll; n const long long mod = 1000000007; n template <long long mod, long long lim, int MAX_D> n struct Hash_set { n   struct node { n     string x; n     node* next; n     node(node* a = 0, const string& b =   ) : next(a), x(b) {} n     void add(const string& a) { n       erase(a); n       next = new node(next, a); n     } n     bool find(const string& a) { n       node* cur = next; n       while (cur) { n         if (cur->x == a) return 1; n         cur = cur->next; n       } n       return 0; n     } n     void clear() { n       while (next) { n         node* tmp = next->next; n         delete next; n         next = tmp; n       } n     } n     void erase(const string& a) { n       node *cur = next, *p = this; n       while (cur) { n         if (cur->x == a) { n           node* tmp = cur; n           p->next = cur->next; n           delete cur; n           cur = p->next; n         } n         if (!cur) break; n         p = cur; n         cur = cur->next; n       } n     } n   }; n   long long* d; n   node* ha; n   Hash_set() { n     ha = new node[mod]; n     d = new long long[MAX_D]; n     d[0] = 1; n     for (int i = 1; i < MAX_D; i++) d[i] = d[i - 1] * lim % mod; n   } n   ~Hash_set() { n     for (int i = 0; i < mod; i++) ha[i].clear(); n     delete[] ha; n     delete[] d; n   } n   long long hash(const string& x) { n     long long res = 0; n     for (int i = 0; i < x.size(); i++) res = (res + x[i] * d[i]) % mod; n     return res; n   } n   bool find(const string& x, int h = -1) { n     if (h == -1) h = hash(x); n     return ha[h].find(x); n   } n   void insert(const string& x, int h = -1) { n     if (h == -1) h = hash(x); n     ha[h].add(x); n   } n   void erase(const string& x, int h = -1) { n     if (h == -1) h = hash(x); n     ha[h].erase(x); n   } n   void clear() { n     for (int i = 0; i < mod; i++) ha[i].clear(); n   } n   int convert(long long h, int where, char from, char to) { n     return ((h + ((long long)to - from) * d[where]) % mod + mod) % mod; n   } n }; n char bf[600005]; n Hash_set<600011, 311, 600000> x; n bool OK() { n   S(bf); n   string cur = bf; n   long long ha = x.hash(cur); n   for (long long i = 0, pJNwFPtlXiwFoIv = (cur.size()); i < pJNwFPtlXiwFoIv; n        i++) { n     char c = cur[i]; n     for (long long j = ( a ), alVDbhLBoMEGSwA = ( c ); j <= alVDbhLBoMEGSwA; n          j++) { n       if (j == c) continue; n       cur[i] = j; n       long long ch = x.convert(ha, i, c, j); n       if (x.find(cur, ch)) return 1; n     } n     cur[i] = c; n   } n   return 0; n } n int main() { n   ; n   int n, m; n   S(n, m); n   while (n--) { n     S(bf); n     x.insert(bf); n   } n   while (m--) { n     puts(OK() ?  YES  :  NO ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline T bigmod(T p, T e, T M) { n   long long ret = 1; n   for (; e > 0; e >>= 1) { n     if (e & 1) ret = (ret * p) % M; n     p = (p * p) % M; n   } n   return (T)ret; n } n template <class T> n inline T gcd(T a, T b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n template <class T> n inline T modinverse(T a, T M) { n   return bigmod(a, M - 2, M); n } n int Set(int N, int pos) { return N = N | (1 << pos); } n int Reset(int N, int pos) { return N = N & ~(1 << pos); } n bool Chkbit(int N, int pos) { return (bool)(N & (1 << pos)); } n int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; n int dx[] = {1, 0, -1, 0}; n int dy[] = {0, 1, 0, -1}; n const double eps = 1e-6; n int n, m, k; n int vis[2000005]; n int achhe[2000005]; n int main() { n   cin >> n >> m >> k; n   for (int i = 1; i <= m; i++) { n     int x; n     scanf( %d , &x); n     vis[x] = 1; n   } n   int ans = 1; n   int fl = 0; n   achhe[1] = 1; n   for (int i = 1; i <= k; i++) { n     int x, y; n     scanf( %d %d , &x, &y); n     if (fl == 0) { n       if (achhe[x]) { n         achhe[x] = 0; n         achhe[y] = 1; n         if (vis[y]) { n           fl = 1; n           ans = y; n         } else n           ans = y; n       } else if (achhe[y]) { n         achhe[y] = 0; n         achhe[x] = 1; n         if (vis[x]) { n           fl = 1; n           ans = x; n         } else n           ans = x; n       } else { n         int nothing; n       } n     } n   } n   if (vis[1]) { n     cout <<  1  << endl; n     return 0; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n; n void solve() { n   cin >> n; n   long long x, y, a, b; n   cout <<  YES n ; n   for (long long i = 1; i <= (n); ++i) { n     cin >> x >> y >> a >> b; n     cout << 2 * (x & 1) + (y & 1) + 1; n     cout <<   n ; n   } n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   solve(); n   return 0; n } n


#include<bits/stdc++.h> n #define ll long long n using namespace std; n int main() n { n     ios_base::sync_with_stdio(0);cin.tie(NULL); n  int t; n  cin>>t; n  while(t--) n  { n   ll n,x; n   ll min=0,max=0,s=0; n   cin>>n>>x; n   ll a[n]; n   for(ll i=0;i<n;i++) n   { n    cin>>a[i]; n    s+=a[i]; n    if(a[i]%x==0) n             max+=(a[i]/x); n             else n             max+=((a[i]/x)+1); n         } n       if(s%x==0) n             min+=(s/x); n             else n             min+=((s/x)+1); n   cout<<min<<   <<max<<endl; n  } n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n using namespace chrono; n const long long int MOD = 1000000007; n const long long int MAXN = 100005; n long long int k, dp[MAXN]; n long long int recurse(long long int n) { n   if (n == 0) return 1; n   if (dp[n] != -1) return dp[n]; n   long long int ans = 0; n   if (n >= k) { n     ans = (ans + recurse(n - k)) % MOD; n   } n   if (n > 0) { n     ans = (ans + recurse(n - 1)) % MOD; n   } n   return (dp[n] = ans); n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int t; n   cin >> t >> k; n   long long int a, b; n   memset(dp, -1, sizeof(dp)); n   dp[0] = 0; n   for (long long int i = 1; i < 100001; ++i) { n     dp[i] = recurse(i); n   } n   for (long long int i = 1; i < 100001; ++i) { n     dp[i] = (dp[i] + dp[i - 1]) % MOD; n   } n   while (t--) { n     cin >> a >> b; n     cout << ((MOD + dp[b] - dp[a - 1])) % MOD << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long getint() { n   long long _x = 0, _tmp = 1; n   char _tc = getchar(); n   while ((_tc <  0  || _tc >  9 ) && _tc !=  - ) _tc = getchar(); n   if (_tc ==  - ) _tc = getchar(), _tmp = -1; n   while (_tc >=  0  && _tc <=  9 ) _x *= 10, _x += (_tc -  0 ), _tc = getchar(); n   return _x * _tmp; n } n long long mypow(long long _a, long long _x, long long _mod) { n   if (_x == 0) return 1ll; n   long long _tmp = mypow(_a, _x / 2, _mod); n   _tmp = (_tmp * _tmp) % _mod; n   if (_x & 1) _tmp = (_tmp * _a) % _mod; n   return _tmp; n } n inline long long add(long long _x, long long _y, n                      long long _mod = 1000000007ll) { n   long long _ = _x + _y; n   if (_ >= _mod) _ -= _mod; n   return _; n } n inline long long sub(long long _x, long long _y, n                      long long _mod = 1000000007ll) { n   long long _ = _x - _y; n   if (_ < 0) _ += _mod; n   return _; n } n inline long long mul(long long _x, long long _y, n                      long long _mod = 1000000007ll) { n   long long _ = _x * _y; n   if (_ >= _mod) _ %= _mod; n   return _; n } n inline bool equal(double _x, double _y) { n   return _x > _y - 1e-9 && _x < _y + 1e-9; n } n int __ = 1, _cs; n int n, k; n vector<int> v; n void build() {} n void init() { n   n = getint(); n   k = getint(); n   for (int i = 1; i <= n; i++) v.push_back(getint()); n   sort((v).begin(), (v).end()); n   v.resize(unique((v).begin(), (v).end()) - v.begin()); n } n int dp[1001 * 1001]; n void solve() { n   for (int i = 1; i <= (v.back() - v[0]) * k; i++) { n     dp[i] = 1001 * 1001; n     for (size_t j = 1; j < v.size(); j++) n       if (v[j] - v[0] > i) n         break; n       else n         dp[i] = min(dp[i], dp[i - v[j] + v[0]] + 1); n   } n   for (int i = 0; i <= (v.back() - v[0]) * k; i++) n     if (dp[i] <= k) printf( %d  , i + v[0] * k); n   puts(  ); n } n int main() { n   build(); n   while (__--) { n     init(); n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i, j, k; n   string s; n   while (cin >> n >> s) { n     int sum = 0; n     int left = 0, right = 0, up = 0, down = 0; n     for (i = 0; i < n; i++) { n       if (s[i] ==  R ) { n         if (left == 1) { n           sum++; n           left = 0; n           up = 0; n           down = 0; n         } n         right = 1; n       } else if (s[i] ==  L ) { n         if (right == 1) { n           sum++; n           right = 0; n           up = 0; n           down = 0; n         } n         left = 1; n       } else if (s[i] ==  U ) { n         if (down == 1) { n           sum++; n           down = 0; n           left = 0; n           right = 0; n         } n         up = 1; n       } else if (s[i] ==  D ) { n         if (up == 1) { n           sum++; n           up = 0; n           left = 0; n           right = 0; n         } n         down = 1; n       } n     } n     cout << sum + 1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,unroll-loops ) n #pragma GCC target(   n      sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2 ) n using namespace std; n mt19937 mrnd(time(0)); n const int INF = 1000000007; n const long long INF_LL = 1152921504606846977; n void solve() { n   int n, m; n   cin >> n >> m; n   vector<set<int>> g(n); n   for (int i = 0; i < m; ++i) { n     int u, v; n     cin >> u >> v; n     --u, --v; n     if (u > v) swap(u, v); n     g[u].insert(v); n   } n   set<int> dead; n   for (int i = 0; i < n; ++i) { n     if (!g[i].empty()) { n       dead.insert(i); n     } n   } n   int q; n   cin >> q; n   auto upd = [&](int node) { n     if (g[node].empty()) { n       dead.erase(node); n     } else { n       dead.insert(node); n     } n   }; n   for (int i = 0; i < q; ++i) { n     int z, u, v; n     cin >> z; n     if (z == 1) { n       cin >> u >> v; n       --u, --v; n       if (u > v) swap(u, v); n       g[u].insert(v); n       upd(u), upd(v); n     } else if (z == 2) { n       cin >> u >> v; n       --u, --v; n       if (u > v) swap(u, v); n       g[u].erase(v); n       upd(u), upd(v); n     } else { n       cout << n - int(dead.size()) <<   n ; n     } n   } n } n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout << fixed << setprecision(20); n   int tests = 1; n   while (tests--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, mostleft = 1000000000, mostright = 0, ans = -1; n   int l[100000], r[100000]; n   bool bo_l[100000], bo_r[100000]; n   cin >> n; n   for (int i = 0; i < n; i++) { n     bo_l[i] = false; n     bo_r[i] = false; n   } n   for (int i = 0; i < n; i++) { n     cin >> l[i] >> r[i]; n     mostleft = min(mostleft, l[i]); n     mostright = max(mostright, r[i]); n   } n   for (int i = 0; i < n; i++) { n     if (mostleft == l[i]) bo_l[i] = true; n     if (mostright == r[i]) bo_r[i] = true; n   } n   for (int i = 0; i < n; i++) { n     if (bo_l[i] && bo_r[i]) ans = i + 1; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxN = 200005; n const unsigned long long HA = 41793404541; n int n, m; n int a[maxN], b[maxN]; n unsigned long long fac[maxN], pre[maxN], nxt[maxN]; n int ansn, ans[maxN]; n bool check(int l, int r) { n   return pre[r] - pre[l - 1] * fac[r - l + 1] == n          nxt[l] - nxt[r + 1] * fac[r - l + 1]; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); n   for (int i = 1; i < n; ++i) b[i] = a[i + 1] - a[i]; n   fac[0] = 1; n   for (int i = 1; i <= n; ++i) fac[i] = fac[i - 1] * HA; n   for (int i = 1; i <= n; ++i) n     pre[i] = pre[i - 1] * HA + (unsigned long long)b[i]; n   for (int i = n - 1; i; --i) n     nxt[i] = nxt[i + 1] * HA + (unsigned long long)b[i]; n   for (int i = 1; i <= n; ++i) { n     bool pd = true; n     if (i != 1) pd &= check(1, i - 1); n     if (i != n) { n       pd &= (a[1] + a[i] == a[i + 1] + a[n] - m); n       if (i != n - 1) pd &= check(i + 1, n - 1); n     } n     if (pd) ans[++ansn] = (a[1] + a[i]) % m; n   } n   printf( %d n , ansn); n   sort(ans + 1, ans + ansn + 1); n   for (int i = 1; i <= ansn; ++i) printf( %d  , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000000; n int f[N], sz[N], ak, Ak, n, m, ans[N]; n struct data { n   int a, b, c, d, e; n   data(int a = 0, int b = 0, int c = 0, int d = 0, int e = 0) n       : a(a), b(b), c(c), d(d), e(e) {} n } S[N]; n struct edge { n   int x, y, z, id; n   bool operator<(const edge& e) const { return z < e.z; } n } e[N], ee[N]; n int find(int x) { return x == f[x] ? x : find(f[x]); } n void me(int x, int y) { n   int X = find(x), Y = find(y); n   if (X == Y) return; n   S[Ak++] = data(X, Y, sz[X], sz[Y], ak); n   if (sz[X] & 1 & sz[Y]) ak -= 2; n   if (sz[X] > sz[Y]) swap(X, Y); n   f[X] = Y; n   sz[Y] += sz[X]; n } n void pop(int tt) { n   while (Ak > tt) { n     data haha = S[--Ak]; n     ak = haha.e; n     f[haha.a] = haha.a; n     f[haha.b] = haha.b; n     sz[haha.a] = haha.c; n     sz[haha.b] = haha.d; n   } n } n void solve(int l, int r, int x, int y) { n   if (x > y) return; n   if (l == r) { n     for (int i = x; i <= y; i++) ans[i] = l; n     return; n   } n   int mid = (l + r) >> 1, t = y + 1, tt = Ak; n   for (int i = l; i <= mid; i++) n     if (ee[i].id < x) me(ee[i].x, ee[i].y); n   for (int i = x; i <= y; i++) { n     if (e[i].z <= mid) me(e[i].x, e[i].y); n     if (ak == 0) { n       t = i; n       break; n     } n   } n   pop(tt); n   for (int i = x; i < t; i++) n     if (e[i].z < l) me(e[i].x, e[i].y); n   solve(l, mid, t, y); n   pop(tt); n   for (int i = l; i <= mid; i++) n     if (ee[i].id < x) me(ee[i].x, ee[i].y); n   solve(mid + 1, r, x, t - 1); n   pop(tt); n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) f[i] = i, sz[i] = 1; n   ak = n; n   for (int i = 1; i <= m; i++) { n     scanf( %d%d%d , &e[i].x, &e[i].y, &e[i].z); n     e[i].id = i; n     ee[i] = e[i]; n   } n   sort(ee + 1, ee + 1 + m); n   for (int i = 1; i <= m; i++) e[ee[i].id].z = i; n   solve(1, m + 1, 1, m); n   ee[m + 1].z = -1; n   for (int i = 1; i <= m; i++) printf( %d n , ee[ans[i]].z); n   return 0; n } n


#include <bits/stdc++.h> n const long long mod = 1000000007; n const int maxn = 100000; n using namespace std; n int main() { n   long long n, k; n   scanf( %I64d , &n); n   scanf( %I64d , &k); n   vector<long long> fib(n + 1); n   fib[1] = 1; n   for (int i = 2; i < n + 1; i++) fib[i] = fib[i - 1] + fib[i - 2]; n   for (int i = 0; i < n; i++) { n     if (fib[n - i] < k) { n       cout << i + 2 <<     << i + 1 <<    ; n       k -= fib[n - i]; n       i++; n     } else n       cout << i + 1 <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, const char* argv[]) { n   int n; n   cin >> n; n   int x = 0; n   for (int i = 1; i < n; i++) { n     if (n % i == 0) { n       x++; n     } n   } n   cout << x; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n [[maybe_unused]] const int MAX = INT32_MAX, MIN = -INT32_MAX, n                            maxInd = 1E6 + 1E5 + 1; n [[maybe_unused]] bool directed = true, end_now = false; n bool possible = false; n int n, k; n struct node_data_structure { n   int pre = 0, post = 0; n   bool visited = false, processed = false; n } nodes[maxInd]; n vector<int> graph[maxInd]; n void insert_graph(int pre, int post) { n   graph[pre].push_back(post); n   nodes[pre].post++; n   nodes[post].pre++; n   if (!directed) { n     graph[post].push_back(pre); n     nodes[post].post++; n     nodes[pre].pre++; n   } n } n [[maybe_unused]] void undoVisit() { n   for (auto &i : nodes) { n     i.visited = false; n     i.processed = false; n   } n   end_now = false; n } n void dfs(int u, int ac = 1) { n   if (end_now) return; n   if (u > 1E6) { n     if (u - 1E6 < ac) return; n     if (u - 1E6 + k > n || u - 1E6 == n) { n       end_now = true; n       possible = true; n       return; n     } n   } else { n     if (u < ac) return; n     if (u + k > n || u == n) { n       end_now = true; n       possible = true; n       return; n     } n   } n   nodes[u].visited = true; n   for (int v : graph[u]) { n     if (!nodes[v].visited) { n       dfs(v, ac + 1); n     } n   } n   nodes[u].processed = true; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   string s1, s2; n   cin >> n >> k >> s1 >> s2; n   for (int i = 1; i < n; i++) { n     if (i + k <= n) { n       if (s1[i - 1] ==  -  && s2[i - 1 + k] ==  - ) { n         insert_graph(i, 1E6 + i + k); n       } n       if (s2[i - 1] ==  -  && s1[i - 1 + k] ==  - ) { n         insert_graph(1E6 + i, i + k); n       } n     } n     if (s1[i] ==  -  && s1[i - 1] ==  - ) { n       insert_graph(i, i + 1); n       insert_graph(i + 1, i); n     } n     if (s2[i] ==  -  && s2[i - 1] ==  - ) { n       insert_graph(1E6 + i, 1E6 + i + 1); n       insert_graph(1E6 + i + 1, 1E6 + i); n     } n   } n   dfs(1); n   possible ? cout <<  YES  << endl : cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n long long mul(long long a, long long b) { return a * b % mod; } n long long add(long long a, long long b) { n   long long res = a + b; n   if (res >= mod) { n     res -= mod; n   } n   return res; n } n const long long MAXN = 1e6 + 5; n vector<long long> fact(MAXN); n vector<long long> fact_obr(MAXN); n vector<long long> pow_n(MAXN); n vector<long long> pow_m(MAXN); n long long n; n long long m; n long long fast_pow(long long a, long long b) { n   if (b == 0) { n     return 1; n   } else { n     if (b % 2 == 1) { n       return mul(fast_pow(a, b - 1), a); n     } else { n       long long res = fast_pow(a, b / 2); n       return mul(res, res); n     } n   } n } n void pre_calc() { n   fact[0] = 1; n   fact_obr[0] = fast_pow(fact[0], mod - 2); n   pow_n[0] = 1; n   pow_m[0] = 1; n   for (long long i = 1; i < MAXN; ++i) { n     fact[i] = mul(fact[i - 1], i); n     fact_obr[i] = fast_pow(fact[i], mod - 2); n     pow_n[i] = mul(pow_n[i - 1], n); n     pow_m[i] = mul(pow_m[i - 1], m); n   } n } n long long A(long long n, long long k) { return mul(fact[n], fact_obr[n - k]); } n long long C(long long n, long long k) { n   if (k > n) { n     return 0; n   } n   if (n == 0 && k != 0) { n     return 0; n   } n   return mul(A(n, k), fact_obr[k]); n } n long long f(long long y) { n   if (y == n) { n     return 1; n   } n   return mul(y, pow_n[n - y - 1]); n } n int32_t main() { n   cin >> n >> m; n   pre_calc(); n   long long ans = 0; n   for (long long edges = 1; edges < n; ++edges) { n     long long _add = 1; n     _add = mul(_add, A(n - 2, edges - 1)); n     _add = mul(_add, f(edges + 1)); n     _add = mul(_add, C(m - 1, edges - 1)); n     _add = mul(_add, pow_m[n - edges - 1]); n     ans = add(ans, _add); n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n struct creature { n   long long hp, dmg; n   long long div; n   bool operator<(const creature& rhs) const { return div > rhs.div; } n }; n int n, a, b; n creature in[200050]; n long long ans = 0; n int it, use; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cin >> n >> a >> b; n   for (int i = 0; i < n; ++i) { n     cin >> in[i].hp >> in[i].dmg; n     in[i].div = in[i].hp - in[i].dmg; n   } n   sort(in, in + n); n   use = b; n   for (int i = 0; i < n; ++i) { n     if (use && in[i].hp > in[i].dmg) { n       in[i].dmg = in[i].hp; n       --use; n     } n     ans += in[i].dmg; n   } n   it = b - use; n   int icur = it - 1; n   in[n] = {0, 0, 0}; n   long long dx = 0; n   if (b && a) n     for (int i = 0; i < n; ++i) { n       long long tmp = (in[i].hp << a) - in[i].dmg; n       if (use) n         dx = dx > tmp ? dx : tmp; n       else if (i < it) n         dx = tmp > dx ? tmp : dx; n       else n         dx = (tmp - in[icur].div > dx) ? tmp - in[icur].div : dx; n     } n   cout << ans + dx; n   return 0; n } n


#include <bits/stdc++.h> n using LL = long long; n const int kN = 200000 + 5; n const int kLog = 19; n const LL inf = 3e14; n std::vector<std::pair<int, int>> edges[kN]; n int n, m, s; n LL dist[kN]; n int plca[kLog][kN], depth[kN]; n int sz[kN]; n int get_lca(int a, int b) { n   if (depth[a] < depth[b]) std::swap(a, b); n   for (int i = 0; i < kLog; ++i) n     if (depth[a] - depth[b] >> i & 1) a = plca[i][a]; n   if (a == b) return a; n   for (int i = kLog - 1; i >= 0; --i) n     if (plca[i][a] != plca[i][b]) a = plca[i][a], b = plca[i][b]; n   return plca[0][a]; n } n int main() { n   scanf( %d%d%d , &n, &m, &s); n   s--; n   for (int i = 0; i < m; ++i) { n     int u, v, w; n     scanf( %d%d%d , &u, &v, &w); n     u--; n     v--; n     edges[u].emplace_back(w, v); n     edges[v].emplace_back(w, u); n   } n   std::priority_queue<std::pair<LL, int>> pq; n   std::fill(dist, dist + n, inf); n   dist[s] = 0; n   pq.emplace(0, s); n   std::vector<int> order; n   while (!pq.empty()) { n     LL tmp; n     int u; n     std::tie(tmp, u) = pq.top(); n     pq.pop(); n     if (-tmp != dist[u]) continue; n     order.emplace_back(u); n     int lca = -1; n     for (auto e : edges[u]) { n       if (dist[e.second] > dist[u] + e.first) { n         dist[e.second] = dist[u] + e.first; n         pq.emplace(-dist[e.second], e.second); n       } else if (dist[e.second] + e.first == dist[u]) { n         if (lca == -1) n           lca = e.second; n         else n           lca = get_lca(lca, e.second); n       } n     } n     plca[0][u] = lca; n     depth[u] = lca == -1 ? 0 : depth[lca] + 1; n     for (int i = 1; i < kLog; ++i) n       plca[i][u] = plca[i - 1][u] == -1 ? -1 : plca[i - 1][plca[i - 1][u]]; n   } n   int result = 0; n   std::fill(sz, sz + n, 1); n   for (int i = (int)order.size() - 1; i > 0; --i) { n     int u = order[i]; n     sz[plca[0][u]] += sz[u]; n     result = std::max(result, sz[u]); n   } n   printf( %d n , result); n } n


#include <bits/stdc++.h> n using namespace std; n int n, w; n double tmp; n vector<double> a; n vector<double> boy; n vector<double> girl; n double volume; n double base; n int main() { n   cin >> n >> w; n   for (int i = 0; i < (2 * n); i++) { n     cin >> tmp; n     a.push_back(tmp); n   } n   sort(a.begin(), a.end()); n   girl.assign(a.begin(), a.begin() + n); n   boy.assign(a.begin() + n, a.end()); n   if (boy[0] / 2 > girl[0]) n     base = girl[0]; n   else n     base = boy[0] / 2; n   volume = (3 * base * n); n   if (volume > w) volume = w; n   cout << fixed << setprecision(10) << volume; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int kase, ks = 0; n   int i, j, k; n   int n; n   int arr[1000]; n   string s; n   cin >> n; n   for (i = 1; i < n + 1; i++) cin >> arr[i]; n   int q; n   cin >> q; n   int x, y; n   while (q--) { n     cin >> x >> y; n     if (x > 1) arr[x - 1] += (y - 1); n     if (x < n) arr[x + 1] += (arr[x] - y); n     arr[x] = 0; n   } n   for (i = 1; i < n + 1; i++) cout << arr[i] << endl; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; ++i) printf( %d , i % 2); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3000 + 12; n int p[maxn]; n int Et[maxn]; n int mark[maxn][maxn]; n queue<pair<int, int> > act; n void input(int n) { n   for (int i = 0; i < n; i++) cin >> p[i]; n } n void solve(int n, int k) { n   int sef = 0; n   bool yek = 0; n   for (int j = n - 1; j >= 0; j--) { n     if (p[j] == 0) sef++; n     if (p[j] == 100) yek = 1; n     if (sef == n - j) Et[j] = 1; n     if (yek) Et[j] = 2; n   } n   act.push(make_pair(0, 1)); n   mark[0][1] = 0; n   int ans = 0; n   int x = 0, y = 1; n   while (act.size() && mark[x][y] <= k) { n     pair<int, int> a = act.front(); n     x = a.first, y = a.second; n     if (mark[x][y] <= k) ans++; n     if (Et[y] != 1 && p[x] != 0 && y + 2 <= n + 1 && n         mark[y + 1][y + 2] > mark[x][y] + 1) n       act.push(make_pair(y + 1, y + 2)), mark[y + 1][y + 2] = mark[x][y] + 1; n     if (Et[y] != 2 && p[x] != 0 && y + 1 <= n && n         mark[x][y + 1] > mark[x][y] + 1) n       act.push(make_pair(x, y + 1)), mark[x][y + 1] = mark[x][y] + 1; n     if (Et[y] != 1 && p[x] != 100 && y + 1 <= n && n         mark[y][y + 1] > mark[x][y] + 1) n       act.push(make_pair(y, y + 1)), mark[y][y + 1] = mark[x][y] + 1; n     act.pop(); n   } n   cout << ans; n } n int main() { n   int n, k; n   cin >> n >> k; n   input(n); n   memset(mark, 31, sizeof mark); n   solve(n, k); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using lli = long long; n using pii = pair<int, int>; n using pll = pair<lli, lli>; n template <typename T> n using Vector = vector<vector<T>>; n template <typename T> n using Prior = priority_queue<T>; n template <typename T> n using prior = priority_queue<T, vector<T>, greater<T>>; n const lli mod = 1E9 + 7; n void solve() { n   lli x, len; n   string s; n   cin >> x >> s; n   len = s.size(); n   for (int i = 1; i <= x; ++i) { n     if (s.size() < x) { n       if (s[i - 1] ==  2 ) s += s.substr(i, s.size() - i); n       if (s[i - 1] ==  3 ) n         s += s.substr(i, s.size() - i) + s.substr(i, s.size() - i); n       len = s.size(); n     } else { n       if (s[i - 1] ==  2 ) len = (2 * len - i) % mod; n       if (s[i - 1] ==  3 ) len = (3 * len - 2 * i) % mod; n     } n   } n   cout << (len < 0 ? len + mod : len) <<   n ; n } n int main() { n   int t = 1; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, min = 1000; n   scanf( %d %d , &n, &m); n   vector<int> v(m); n   for (int i = 0; i < m; i++) scanf( %d , &v[i]); n   sort(v.begin(), v.end()); n   for (int i = 0; n + i - 1 < m; i++) { n     if (min > v[n + i - 1] - v[i]) min = v[n + i - 1] - v[i]; n   } n   printf( %d , min); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int N = 100005; n char s[N]; n int n, a[N], pre[N][26], suf[N][26]; n int f[N][26], g[N], mem[27]; n inline int mex(int st) { return __builtin_ctz(~st); } n int calc(int l, int r, int c, int fl) { n   if (l > r) return 0; n   if (~mem[c]) return mem[c]; n   int st = 0; n   for (int j = 0; j < 26; j++) { n     int ll = suf[l][j], rr = pre[r][j]; n     if (rr >= l) n       st |= 1 << (g[rr] ^ g[ll] ^ (!fl ? f[ll - 1][c] : calc(l, ll - 1, j, 1)) ^ n                   (fl ? f[r][j] : calc(rr + 1, r, j, 0))); n   } n   return mem[c] = mex(st); n } n int main() { n   ios::sync_with_stdio(false); n   cin >> (s + 1); n   n = strlen(s + 1); n   for (int i = 1; i <= n; i++) a[i] = s[i] -  a ; n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j < 26; j++) pre[i][j] = pre[i - 1][j]; n     pre[i][a[i]] = i; n   } n   for (int j = 0; j < 26; j++) suf[n + 1][j] = n + 1; n   for (int i = n; i > 0; --i) { n     for (int j = 0; j < 26; j++) suf[i][j] = suf[i + 1][j]; n     suf[i][a[i]] = i; n   } n   for (int i = 1; i <= n; i++) { n     g[i] = f[i - 1][a[i]] ^ g[pre[i - 1][a[i]]]; n     memset(mem, -1, sizeof(mem)); n     for (int j = 0; j < 26; j++) f[i][j] = calc(pre[i][j] + 1, i, j, 0); n   } n   int q; n   cin >> q; n   while (q--) { n     int l, r; n     cin >> l >> r; n     memset(mem, -1, sizeof(mem)); n     if (calc(l, r, 26, 1)) n       puts( Alice ); n     else n       puts( Bob ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9 + 7; n template <class C> n inline void mini(C& a4, C b4) { n   a4 = min(a4, b4); n } n template <class C> n inline void maxi(C& a4, C b4) { n   a4 = max(a4, b4); n } n int n, v, e; n int a[307], b[307]; n vector<int> GG[307], G[307]; n bool del[307], vis[307]; n int xx[1000007], yy[1000007], dd[1000007], moves; n long long int go(int x) { n   long long int res = a[x] - b[x]; n   vis[x] = true; n   for (__typeof((GG[x]).begin()) i = (GG[x]).begin(); i != (GG[x]).end(); ++i) n     if (!vis[*i]) { n       G[x].push_back(*i); n       G[*i].push_back(x); n       res += go(*i); n     } n   return res; n } n void push(int x, int o, int lim, bool down) { n   for (__typeof((G[x]).begin()) i = (G[x]).begin(); i != (G[x]).end(); ++i) n     if (*i != o && !del[*i]) { n       push(*i, x, INF, down); n       int can = lim; n       int l = x, r = *i; n       if (!down) swap(l, r); n       mini(can, a[l]); n       mini(can, v - a[r]); n       lim -= can; n       if (can > 0) { n         a[l] -= can; n         a[r] += can; n         xx[moves] = l; n         yy[moves] = r; n         dd[moves] = can; n         moves++; n       } n     } n } n int main() { n   std::ios_base::sync_with_stdio(0); n   cout << setprecision(15) << fixed; n   cin >> n >> v >> e; n   for (int i = (1); i <= (n); i++) cin >> a[i]; n   for (int i = (1); i <= (n); i++) cin >> b[i]; n   while (e--) { n     int x, y; n     cin >> x >> y; n     GG[x].push_back(y); n     GG[y].push_back(x); n   } n   for (int i = (1); i <= (n); i++) n     if (!vis[i]) n       if (go(i) != 0) { n         cout <<  NO  << endl; n         return 0; n       } n   bool ok; n   do { n     ok = false; n     for (int i = (1); i <= (n); i++) n       if (!del[i]) { n         int deg = 0; n         for (__typeof((G[i]).begin()) j = (G[i]).begin(); j != (G[i]).end(); n              ++j) n           deg += !del[*j]; n         if (deg != 1) continue; n         if (a[i] != b[i]) push(i, i, abs(a[i] - b[i]), a[i] > b[i]); n         del[i] = true; n         ok = true; n         break; n       } n   } while (ok); n   cout << moves << endl; n   for (int i = 0; i < (moves); i++) n     cout << xx[i] <<     << yy[i] <<     << dd[i] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename U> n std::pair<T, U> operator+(const std::pair<T, U>& l, const std::pair<T, U>& r) { n   return {l.first + r.first, l.second + r.second}; n } n typedef void (*callback_function)(void); n const long long ZERO = 0LL; n const long long INF64 = 1e18; n const long long INF32 = 1e9; n const long long MOD = 1e9 + 7; n const long double PI = acos(-1.0L); n const long double EPS = static_cast<long double>(1e-9); n const long long N = 1e6 + 7; n long long n, a[N], del; n void input() { n   cin >> n; n   for (long long i = (1); i <= (n); i++) { n     cin >> a[i]; n   } n } n void solve() { n   map<long long, long long> mp; n   for (long long i = (1); i <= (n); i++) { n     while (mp[a[i]]) { n       a[mp[a[i]]] = 0; n       mp[a[i]] = 0; n       a[i] *= 2; n       del++; n     } n     mp[a[i]] = i; n   } n } n void output() { n   cout << n - del << endl; n   for (long long i = (1); i <= (n); i++) { n     if (a[i]) cout << a[i] <<    ; n   } n   cout << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(); n   { n     input(); n     solve(); n     output(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, a[200002], v1, v2, ans[200002], mx, subtr[200002]; n vector<long long> g[200002]; n void dfs(int v, int d, int p) { n   ans[1] += a[v] * d; n   for (int to : g[v]) { n     if (to == p) continue; n     dfs(to, d + 1, v); n   } n } n void dfs2(int v, int p) { n   long long curr = a[v]; n   for (int to : g[v]) { n     if (to == p) continue; n     dfs2(to, v); n     curr += subtr[to]; n   } n   subtr[v] = curr; n } n void dfs3(int v, int p) { n   for (int to : g[v]) { n     if (to == p) continue; n     ans[to] = ans[v] + subtr[1] - 2 * subtr[to]; n     dfs3(to, v); n   } n   mx = max(mx, ans[v]); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= n - 1; i++) { n     cin >> v1 >> v2; n     g[v1].push_back(v2); n     g[v2].push_back(v1); n   } n   dfs(1, 0, -1); n   dfs2(1, -1); n   dfs3(1, -1); n   cout << mx; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void read(int& x) { n   bool fu = 0; n   char c; n   for (c = getchar(); c <= 32; c = getchar()) n     ; n   if (c ==  - ) fu = 1, c = getchar(); n   for (x = 0; c > 32; c = getchar()) x = x * 10 + c -  0 ; n   if (fu) x = -x; n }; n char getc() { n   char c; n   for (c = getchar(); c <= 32; c = getchar()) n     ; n   return c; n } n const int N = 100010; n const int inf = 1000000000; n int n, m, d, i, j, k, l, p, x, y, ans; n bool have[N]; n int edge, e[N * 2], b[N * 2], fir[N], last[N]; n void clear() { n   edge = 0; n   memset(fir, -1, sizeof(fir)); n   memset(b, -1, sizeof(b)); n } n void adde(int x, int y) { n   e[edge] = y; n   if (fir[x] == -1) n     fir[x] = edge; n   else n     b[last[x]] = edge; n   last[x] = edge++; n } n int st[N], ed[N], ti, fa[N], dep[N], home[N]; n void dfs(int i) { n   st[i] = ++ti; n   home[ti] = i; n   int k; n   for (k = fir[i]; k >= 0; k = b[k]) n     if (e[k] != fa[i]) { n       fa[e[k]] = i; n       dep[e[k]] = dep[i] + 1; n       dfs(e[k]); n     } n   ed[i] = ti; n } n int key[N * 4], add[N * 4]; n void padd(int i, int s) { n   add[i] += s; n   key[i] += s; n } n void pdown(int i) { n   if (add[i]) padd(i * 2, add[i]), padd(i * 2 + 1, add[i]), add[i] = 0; n } n void upd(int i) { key[i] = max(key[i * 2], key[i * 2 + 1]); } n void build(int i, int x, int y) { n   if (x != y) { n     build(i * 2, x, (x + y) / 2); n     build(i * 2 + 1, (x + y) / 2 + 1, y); n     upd(i); n   } else n     key[i] = (have[home[x]]) ? dep[home[x]] : -inf; n } n void find(int i, int x, int y, int l, int r, int s) { n   if (y < l || x > r) return; n   if (x >= l && y <= r) { n     padd(i, s); n     return; n   } n   pdown(i); n   find(i * 2, x, (x + y) / 2, l, r, s); n   find(i * 2 + 1, (x + y) / 2 + 1, y, l, r, s); n   upd(i); n } n void doit(int l, int r, int s) { n   find(1, 1, n, l, r, s); n   if (l > 1) find(1, 1, n, 1, l - 1, -s); n   if (r < n) find(1, 1, n, r + 1, n, -s); n } n void go(int i) { n   if (key[1] <= d) ans++; n   int k; n   for (k = fir[i]; k >= 0; k = b[k]) n     if (e[k] != fa[i]) { n       doit(st[e[k]], ed[e[k]], -1); n       go(e[k]); n       doit(st[e[k]], ed[e[k]], 1); n     } n } n int main() { n   read(n); n   read(m); n   read(d); n   for (i = 1; i <= m; i++) read(x), have[x] = 1; n   clear(); n   for (i = 1; i <= n - 1; i++) read(x), read(y), adde(x, y), adde(y, x); n   dfs(1); n   build(1, 1, n); n   go(1); n   printf( %d n , ans); n   scanf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:667772160 ) n using namespace std; n struct __isoff { n   __isoff() { n     if (0) freopen( input.txt ,  r , stdin), freopen( output.txt ,  w , stdout); n     srand( C  +  T  +  A  +  C  +  Y  +  M  +  B  +  A ); n   } n   ~__isoff() {} n } __osafwf; n const unsigned long long p1 = 31; n const unsigned long long p2 = 29; n const double eps = 1e-8; n const double pi = acos(-1.0); n const int infi = 1e9 + 7; n const long long inf = 1e18 + 7; n const long long dd = 7e5 + 7; n const long long mod = 1e9 + 7; n const long long mod2 = 1e6 + 3; n long long fac[dd], ifac[dd]; n long long pows(long long x, int p) { n   if (p == 0) return 1; n   if (p % 2) return pows(x, p - 1) * x % mod2; n   x = pows(x, p / 2); n   return x * x % mod2; n } n long long cnk(long long a, long long b) { n   return fac[a] * ifac[b] % mod2 * ifac[a - b] % mod2; n } n const int fd = 1e3 + 7; n int H[dd], IH[dd], dp[fd]; n int main() { n   fac[0] = ifac[0] = 1; n   for (int i = 1; i < dd; i++) { n     fac[i] = fac[i - 1] * i % mod2; n     ifac[i] = ifac[i - 1] * pows(i, mod2 - 2) % mod2; n   } n   int c, h, w; n   cin >> c >> w >> h; n   { n     H[0] = 1; n     for (int i = 1; i < dd; i++) { n       H[i] = (H[i - 1] * h) % mod2; n     } n     IH[0] = 1; n     for (int i = 1; i < dd; i++) { n       IH[i] = (IH[i - 1] * pows(h, mod2 - 2)) % mod2; n     } n   } n   dp[0] = 1; n   deque<long long> G; n   G.push_back(1); n   G.push_back(1); n   long long t = h + 1; n   for (int i = 1; i <= c; i++) { n     if (0) { n       long long p = 1; n       for (int j = i - 1, l = 0; j >= -1 && l <= w; j--, l++) { n         long long t = 1; n         if (j >= 0) { n           t = dp[j]; n         } n         dp[i] = (dp[i] + t * p) % mod2; n         p = (p * h) % mod2; n       } n     } n     { n       G.push_back(t); n       t = (t * h + t) % mod2; n       if (G.size() > w + 1) { n         t = ((t - G.front() * H[w + 1]) % mod2 + mod2) % mod2; n         G.pop_front(); n       } n     } n   } n   cout << G.back(); n } n


#include <bits/stdc++.h> n using namespace std; n int expo(int x, int y) { n   int res = 1; n   while (y) { n     if (y % 2) res = (res * x % 1000000007) % 1000000007; n     x = (x * x) % 1000000007; n     y /= 2; n   } n   return res; n } n bool isPrime(long long n) { n   if (n <= 1) return false; n   if (n <= 3) return true; n   if (n % 2 == 0 || n % 3 == 0) return false; n   for (long long i = 5; i * i <= n; i = i + 6) n     if (n % i == 0 || n % (i + 2) == 0) return false; n   return true; n } n long long nextPrime(long long N) { n   if (N <= 1) return 2; n   long long prime = N; n   bool found = false; n   while (!found) { n     prime++; n     if (isPrime(prime)) found = true; n   } n   return prime; n } n long long cl(long long n, long long d) { return (n + d - 1) / d; } n long long binToDec(string s) { return bitset<64>(s).to_ullong(); } n string decToBin(long long a) { return bitset<64>(a).to_string(); } n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long lcm(long long a, long long b) { return (a * b) / (gcd(a, b)); } n void print(pair<long long, long long> a) { n   cout << a.first <<     << a.second; n   cout << endl; n   ; n } n void print(long long a) { n   cout << a; n   cout << endl; n } n void print(std::vector<long long> a) { n   for (auto i : a) cout << i <<    ; n   cout << endl; n   ; n } n void print(string s) { n   cout << s; n   cout << endl; n   ; n } n void printr(std::vector<long long> a, long long start, long long end) { n   for (long long i = start; i < end; i++) cout << a[i] <<    ; n   cout << endl; n   ; n } n void print(long long a, long long b) { cout << a <<     << b; } n void amax(long long &a, long long b) { a = max(a, b); } n void amin(long long &a, long long b) { a = min(a, b); } n long long madd(long long a, long long b) { n   return ((a % 1000000007) + (b % 1000000007)) % 1000000007; n } n long long mmul(long long a, long long b) { n   return ((a % 1000000007) * (b % 1000000007)) % 1000000007; n } n long long msub(long long a, long long b) { n   return ((a % 1000000007) - (b % 1000000007) + 1000000007) % 1000000007; n } n long long fpow(long long x, long long y, long long p = 1000000007) { n   x %= p; n   long long sum = 1; n   while (y) { n     if (y & 1) sum = sum * x; n     sum %= p; n     y = y >> 1; n     x = x * x; n     x %= p; n   } n   return sum; n } n bool isPerSquare(long double a) { n   if (a < 0) return false; n   long long sr = sqrt(a); n   return (sr * sr == a); n } n bool isPalindrome(string str) { n   long long low = 0, high = long long(str.size()) - 1; n   while (low < high) { n     if (str[low] != str[high]) return false; n     low++, high--; n   } n   return true; n } n void solve() { n   long long n; n   cin >> n; n   ; n   vector<set<long long>> vp(n + 1); n   for (__typeof(n + 1) i = (1) - ((1) > (n + 1)); n        i != (n + 1) - ((1) > (n + 1)); i += 1 - 2 * ((1) > (n + 1))) { n     long long x; n     cin >> x; n     ; n     set<long long> temp; n     for (__typeof(x) i = (0) - ((0) > (x)); i != (x) - ((0) > (x)); n          i += 1 - 2 * ((0) > (x))) { n       long long y; n       cin >> y; n       ; n       temp.insert(y); n     } n     vp[i] = temp; n   } n   vector<vector<long long>> dependent(n + 1); n   set<long long> books; n   for (long long i = 1; i <= n; i++) { n     for (auto j : vp[i]) { n       dependent[j].push_back(i); n     } n   } n   long long ans = 1; n   for (long long i = 1; i <= n; i++) { n     if (long long(vp[i].size()) == 0) { n       books.insert(i); n     } n   } n   long long rem = 0; n   while (long long(books.size())) { n     bool added = false, erased = false; n     std::vector<long long> add; n     auto i = *books.begin(); n     while (1) { n       if (!added && long long(dependent[i].size()) && dependent[i][0] < i) { n         added = true; n         ans++; n       } n       for (long long j = 0; j < long long(dependent[i].size()); j++) { n         vp[dependent[i][j]].erase(i); n         if (long long(vp[dependent[i][j]].size()) == 0) { n           books.insert(dependent[i][j]); n         } n       } n       dependent[i].clear(); n       rem++; n       books.erase(i); n       if (rem == n) { n         print(ans); n         return; n       } n       if (books.upper_bound(i) == books.end()) { n         break; n       } else { n         i = *books.upper_bound(i); n       } n     } n   } n   print(-1); n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long t; n   cin >> t; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const long long int N = 2e5 + 5; n void solve() { n   long long int n, i, j, ans = 0; n   cin >> n; n   long long int a[n]; n   for (auto &x : a) { n     cin >> x; n   }; n   map<long long int, long long int> cnt; n   for (i = 0; i < n; i++) { n     for (j = i + 1; j < n; j++) { n       cnt[a[i] + a[j]]++; n       ans = max(ans, cnt[a[i] + a[j]]); n     } n   } n   cout << ans <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL); n   long long int t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, s[3010], c[3010], ans = 1e10; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> s[i]; n   for (int i = 0; i < n; i++) cin >> c[i]; n   for (int i = 0; i < n; i++) { n     long long min1 = 1e10, min2 = 1e10; n     for (int j = 0; j < i; j++) { n       if (s[j] < s[i]) min1 = min(min1, c[j]); n     } n     for (int j = i; j < n; j++) { n       if (s[j] > s[i]) min2 = min(min2, c[j]); n     } n     ans = min(ans, min1 + c[i] + min2); n   } n   if (ans >= 1e10) n     puts( -1 ); n   else n     cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   unordered_map<string, string> d; n   for (int i = 0; i < m; i++) { n     string x, y; n     cin >> x >> y; n     if ((int)x.size() > (int)y.size()) swap(x, y); n     d[y] = d[x] = x; n   } n   for (int i = 0; i < n; i++) { n     string x; n     cin >> x; n     cout << d[x] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int h; n long long n; n long long dfs(int d, long long n, int lr) { n   if (d == h) return 0; n   long long tmp = 1ll << (h - d - 1); n   if (!lr && n <= tmp) return dfs(d + 1, n, !lr) + 1; n   if (!lr && n > tmp) return (tmp << 1) + dfs(d + 1, n - tmp, 0); n   if (lr && n <= tmp) return (tmp << 1) + dfs(d + 1, n, lr); n   if (lr && n > tmp) return dfs(d + 1, n - tmp, 0) + 1; n } n int main() { n   cin >> h >> n; n   cout << dfs(0, n, 0) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline T abs(T t) { n   return t < 0 ? -t : t; n } n const long long modn = 1000000007; n inline long long mod(long long x) { return x % modn; } n const int MAXN = 100010; n int n, s[MAXN]; n int main() { n   scanf( %d , &n); n   printf( %d , n / 5 + (n % 5 != 0)); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   int n, i = 0; n   cin >> n >> s; n   std::vector<int> v(n); n   std::vector<bool> cycle(n); n   for (int i = 0; i < n; i++) cin >> v[i]; n   for (i = 0; i < n;) { n     if (i <= -1 || i >= n) break; n     if (cycle[i] == true) n       break; n     else { n       cycle[i] = true; n       if (s[i] ==  < ) n         i -= v[i]; n       else n         i += v[i]; n     } n   } n   if (i <= -1 || i >= n) n     cout <<  FINITE n ; n   else n     cout <<  INFINITE n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 10; n long long int inf = -1e15; n long long int seg[maxn << 2], lazy[maxn << 2]; n int n, m, p; n vector<long long int> espadas, armaduras; n vector<pair<int, int> > monstros[maxn]; n void update(int x, long long int val) { n   seg[x] += val; n   lazy[x] += val; n } n void propaga(int x) { n   if (!lazy[x]) return; n   update(x * 2, lazy[x]); n   update(x * 2 + 1, lazy[x]); n   lazy[x] = 0; n } n void add(int i, int j, int x, int l, int r, int val) { n   if (i >= j || l >= r || i >= r || j <= l) return; n   if (i >= l && j <= r) { n     update(x, val); n     return; n   } n   propaga(x); n   int md = (i + j) >> 1; n   add(i, md, x * 2, l, r, val); n   add(md, j, x * 2 + 1, l, r, val); n   seg[x] = max(seg[x * 2], seg[x * 2 + 1]); n } n void build(int i, int j, int no) { n   int l = 2 * no; n   int r = l + 1; n   if (i + 1 == j) { n     if (armaduras[i]) n       seg[no] = -armaduras[i]; n     else n       seg[no] = inf; n     return; n   } n   int mid = (i + j) >> 1; n   build(i, mid, l); n   build(mid, j, r); n   seg[no] = max(seg[l], seg[r]); n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0); n   long long int ans = inf; n   espadas.resize(maxn); n   armaduras.resize(maxn); n   cin >> n >> m >> p; n   int atk, def; n   long long int gold; n   for (int i = 1; i <= n; i++) { n     cin >> atk >> gold; n     atk--; n     if (!espadas[atk]) n       espadas[atk] = gold; n     else n       espadas[atk] = min(espadas[atk], gold); n   } n   for (int i = 1; i <= m; i++) { n     cin >> def >> gold; n     if (!armaduras[def]) n       armaduras[def] = gold; n     else n       armaduras[def] = min(armaduras[def], gold); n   } n   build(1, maxn, 1); n   for (int i = 1; i <= p; i++) { n     cin >> def >> atk >> gold; n     monstros[def].push_back(pair<int, int>(atk, gold)); n   } n   for (int i = 0; i <= maxn - 1; i++) { n     for (auto a : monstros[i]) add(1, maxn, 1, a.first + 1, maxn, a.second); n     if (espadas[i]) ans = max(ans, seg[1] - espadas[i]); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int cnt2 = 0; n int en = 0; n struct Dinic { n   static const int MXN = 100000; n   struct Edge { n     int v, f, re; n     Edge(int a, int b, int c) : v(a), f(b), re(c) {} n   }; n   int n, s, t, level[MXN]; n   vector<Edge> E[MXN]; n   void init(int _n, int _s, int _t) { n     n = _n; n     s = _s; n     t = _t; n     for (int i = 0; i <= n; i++) E[i].clear(); n   } n   void add_edge(int u, int v, int f, int flag = 0) { n     en += 2; n     if (flag) { n       E[u].push_back(Edge(v, f, E[v].size())); n       E[v].push_back(Edge(u, f, E[u].size() - 1)); n     } else { n       E[u].push_back(Edge(v, f, E[v].size())); n       E[v].push_back(Edge(u, 0, E[u].size() - 1)); n     } n   } n   bool BFS() { n     memset(level, -1, sizeof(level)); n     queue<int> que; n     que.push(s); n     level[s] = 0; n     while (!que.empty()) { n       int u = que.front(); n       que.pop(); n       for (auto &it : E[u]) { n         cnt2++; n         if (it.f > 0 && level[it.v] == -1) { n           level[it.v] = level[u] + 1; n           que.push(it.v); n         } n       } n     } n     return level[t] != -1; n   } n   int DFS(int u, int nf) { n     if (u == t) return nf; n     int res = 0; n     for (auto &it : E[u]) { n       cnt2++; n       if (it.f > 0 && level[it.v] == level[u] + 1) { n         int tf = DFS(it.v, min(nf, it.f)); n         res += tf; n         nf -= tf; n         it.f -= tf; n         E[it.v][it.re].f += tf; n         if (nf == 0) return res; n       } n     } n     if (!res) level[u] = -1; n     return res; n   } n   int flow(int res = 0) { n     while (BFS()) { n       res += DFS(s, 2147483647); n     } n     return res; n   } n } flow; n int vis[100005]; n bool dfs(int first) { n   if (vis[first]) return false; n   if (first == 0) return true; n   vis[first] = 1; n   for (auto &it : flow.E[first]) { n     cnt2++; n     if (it.f && dfs(it.v)) { n       it.f--; n       flow.E[it.v][it.re].f++; n       return true; n     } n   } n   return false; n } n bool dfs2(int first) { n   if (vis[first]) return false; n   if (first == flow.t) return true; n   vis[first] = 1; n   for (auto &it : flow.E[first]) { n     cnt2++; n     if (it.f && dfs2(it.v)) { n       it.f--; n       flow.E[it.v][it.re].f++; n       return true; n     } n   } n   return false; n } n void solve() { n   int n; n   scanf( %d , &n); n   int a[205][205]; n   flow.init(n * n * 2 + 2, 0, n * n * 2 + 1); n   int X[4] = {0, 0, -1, 1}; n   int Y[4] = {1, -1, 0, 0}; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       scanf( %d , &a[i][j]); n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if (a[i][j] != -1) { n         flow.add_edge(i * n + j + 1, i * n + j + n * n + 1, 1000000, 1); n         for (int k = 0; k < 4; k++) { n           int first = X[k] + i, second = Y[k] + j; n           if (first >= 0 && first < n && second >= 0 && second < n && n               a[first][second] != -1 && n               (a[i][j] == 0 || a[first][second] == 0)) { n             flow.add_edge(i * n + j + 1, first * n + second + n * n + 1, 1); n           } n         } n       } n     } n   } n   vector<pair<int, pair<int, int> > > v; n   for (int i = 1; i < n - 1; i++) { n     v.push_back(make_pair(a[0][i], make_pair(0, i))); n     flow.add_edge(n * n + i + 1, n * n * 2 + 1, 1); n     v.push_back(make_pair(a[n - 1][i], make_pair(n - 1, i))); n     flow.add_edge(n * n + i + (n - 1) * n + 1, n * n * 2 + 1, 1); n     v.push_back(make_pair(a[i][0], make_pair(i, 0))); n     flow.add_edge(n * n + i * n + 1, n * n * 2 + 1, 1); n     v.push_back(make_pair(a[i][n - 1], make_pair(i, n - 1))); n     flow.add_edge(n * n + i * n + n - 1 + 1, n * n * 2 + 1, 1); n   } n   long long ans = 0; n   for (int i = 0; i < n - 1; i++) { n     ans += abs(a[0][i + 1] - a[0][i]); n     ans += abs(a[i][0] - a[i + 1][0]); n     ans += abs(a[n - 1][i] - a[n - 1][i + 1]); n     ans += abs(a[i][n - 1] - a[i + 1][n - 1]); n   } n   sort(v.begin(), v.end()); n   long long now = 0; n   long long last = 0; n   int tot = 0; n   int cnt = 0; n   for (auto it : v) { n     fill(vis, vis + 100005, 0); n     while (dfs2(0)) { n       now++; n       fill(vis, vis + 100005, 0); n     } n     ans += now * (it.first - last); n     last = it.first; n     int first = it.second.first * n + it.second.second + 1; n     flow.add_edge(0, first, 1); n     for (auto &it : flow.E[first + n * n]) { n       if (it.v == n * n * 2 + 1) { n         if (it.f == 1) { n           it.f = 0; n         } else { n           flow.E[it.v][it.re].f = 0; n           now--; n           fill(vis, vis + 100005, 0); n           dfs(first + n * n); n         } n       } n     } n   } n   printf( %lld n , ans); n } n int main() { n   int t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxn = 1e7; n const long long maxm = 1e7; n const long long INF = 0x3f3f3f3f; n const long long mod = 1e9 + 7; n long long uu[maxn]; n int main() { n   long long n, a, b; n   cin >> n >> a >> b; n   for (long long i = 0; i < n; i++) scanf( %lld , &uu[i]); n   long long ans = -1; n   long long mxb = b; n   for (long long i = 0; i < n; i++) { n     if (a == 0 && b == 0) { n       ans = i; n       break; n     } n     if (uu[i] == 0) { n       if (b > 0) n         b--; n       else n         a--; n     } n     if (uu[i] == 1) { n       if (b == mxb) { n         b--; n       } else if (a > 0) { n         a--; n         b++; n         if (b > mxb) b = mxb; n       } else n         b--; n     } n   } n   if (ans == -1) ans = n; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = (int)1e8; n int n, m; n char s[22][22]; n int x[22][22], dp[1 << 20], state[30], sum[30], maxN[30]; n vector<int> sta[22]; n vector<int> cost[22]; n int bit[1 << 20]; n void initialIt() { n   for (int i = 0; i < 20; i++) { n     bit[1 << i] = i; n   } n   for (int i = 0; i < m; i++) { n     memset(state, 0, sizeof(state)); n     memset(sum, 0, sizeof(sum)); n     memset(maxN, 0, sizeof(maxN)); n     for (int j = 0; j < n; j++) { n       int ch = (int)s[j][i] -  a ; n       state[ch] |= 1 << j; n       sum[ch] += x[j][i]; n       maxN[ch] = max(maxN[ch], x[j][i]); n     } n     for (int j = 0; j < 26; j++) { n       for (int k = 0; k < n; k++) n         if ((state[j] >> k) & 1) { n           sta[k].push_back(state[j]); n           cost[k].push_back(sum[j] - maxN[j]); n         } n     } n   } n   for (int i = 0; i < n; i++) { n     int minCost = INF; n     for (int j = 0; j < m; j++) { n       minCost = min(minCost, x[i][j]); n     } n     sta[i].push_back(1 << i); n     cost[i].push_back(minCost); n   } n } n int lowBit(int x) { return x & (-x); } n void calcIt() { n   for (int i = 0; i < (1 << n); i++) { n     dp[i] = INF; n   } n   dp[0] = 0; n   for (int i = 0; i < (1 << n); i++) { n     int curI = bit[lowBit(i)], curS = i; n     for (int j = 0; j < (int)cost[curI].size(); j++) { n       int C = cost[curI][j], S = sta[curI][j]; n       int preS = curS - (curS & S); n       if (dp[preS] + C < dp[curS]) { n         dp[curS] = dp[preS] + C; n       } n     } n   } n   int final = (1 << n) - 1; n   printf( %d n , dp[final]); n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) { n     scanf( %s , s[i]); n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       scanf( %d , &x[i][j]); n     } n   } n   initialIt(); n   calcIt(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, n; n   char s[200050]; n   map<int, map<int, int>> vis, cnt; n   scanf( %d , &t); n   while (t--) { n     vis.clear(); n     cnt.clear(); n     int l = -5, r = 0x3f3f3f3f; n     scanf( %d%s , &n, s); n     int x = 0, y = 0; n     vis[x][y] = 1; n     cnt[x][y] = 0; n     for (int i = 0; i < n; i++) { n       if (s[i] ==  L ) { n         x -= 1; n       } else if (s[i] ==  R ) { n         x += 1; n       } else if (s[i] ==  D ) { n         y -= 1; n       } else { n         y += 1; n       } n       if (vis[x][y] && i - cnt[x][y] < r - l) { n         l = cnt[x][y] + 1; n         r = i + 1; n       } n       cnt[x][y] = i + 1; n       vis[x][y] = 1; n     } n     if (l != -5) n       printf( %d %d n , l, r); n     else n       printf( -1 n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long sz(char *a) { n   long i = 0; n   while (*(a + i) !=   0 ) i++; n   return i; n } n int main() { n   char *a = (char *)malloc(sizeof(char) * 1000001); n   char *b = (char *)malloc(sizeof(char) * 1000001); n   scanf( %1000000s , a); n   scanf( %1000000s , b); n   long a_size = sz(a); n   long b_size = sz(b); n   long j, i, a_adj, b_adj; n   for (i = 0; i < a_size; i++) n     if (a[i] !=  0 ) break; n   a_size -= i; n   a_adj = i; n   i = 0; n   for (i = 0; i < b_size; i++) n     if (b[i] !=  0 ) break; n   b_size -= i; n   b_adj = i; n   if (a_size > b_size) { n     printf( > n ); n     return 0; n     ; n   } n   if (b_size > a_size) { n     printf( < n ); n     return 0; n     ; n   } n   for (i = a_adj, j = b_adj; i <= a_size + a_adj, j <= b_size + b_adj; n        i++, j++) { n     if (a[i] > b[j]) { n       printf( > n ); n       return 0; n       ; n     } n     if (a[i] < b[j]) { n       printf( < n ); n       return 0; n       ; n     } n   } n   printf( = n ); n   free(a); n   free(b); n   return 0; n   ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000000; n int aa[N + 1]; n int main() { n   int n; n   cin >> n; n   long long ans = 0; n   for (int i = 0; i <= n; i++) aa[i] = i; n   int n_ = n; n   for (int h = 20; n_ > 0;) { n     while (h >= 0 && (n_ & 1 << h) == 0) h--; n     int m = n_ - ((1 << h) - 1); n     reverse(aa + n_ - m * 2 + 1, aa + n_ + 1); n     n_ -= m * 2; n     ans += m * 2LL * ((1 << h + 1) - 1); n   } n   cout << ans <<   n ; n   for (int i = 0; i <= n; i++) cout << aa[i] <<    ; n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   using namespace std; n   int q; n   cin >> q; n   while (q--) { n     long long n; n     cin >> n; n     int len = 0; n     char num[40] = {0}; n     while (n) { n       num[len] = n % 3 +  0 ; n       n /= 3; n       len++; n     } n     int x; n     for (x = len - 1; x >= 0; x--) { n       if (num[x] ==  2 ) { n         break; n       } n     } n     if (x >= 0) { n       for (int i = 0; i <= x; i++) { n         num[i] =  0 ; n       } n       if (num[x + 1]) { n         num[x + 1]++; n       } else { n         num[x + 1] =  1 ; n       } n       for (int i = x + 1; i < len; i++) { n         if (num[i] ==  2 ) { n           num[i] =  0 ; n           if (num[i + 1]) { n             num[i + 1]++; n           } else { n             num[i + 1] =  1 ; n           } n         } n       } n     } n     long long m = 0, t = 1; n     for (int i = 0; num[i]; i++) { n       m += t * (num[i] -  0 ); n       t *= 3; n     } n     cout << m << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   char a[5][5]; n   for (int i = 0; i < 3; i++) { n     for (int j = 0; j < 3; j++) scanf( %c , &a[i][j]); n     getchar(); n   } n   int flag = 0; n   for (int i = 0; i < 3; i++) n     for (int j = 0; j < 3; j++) { n       if (a[i][j] != a[2 - i][2 - j]) flag = 1; n     } n   if (flag == 0) n     printf( YES n ); n   else n     printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5010; n int n; n int a[maxn], f[maxn]; n long long b[maxn]; n int main() { n   int i, ans = 0, j; n   long long w; n   scanf( %d , &n); n   for (i = 1; i <= n; ++i) { n     scanf( %I64d , &w); n     while (w % 2 == 0) ++a[i], w /= 2; n     b[i] = w; n   } n   for (i = 1; i <= n; ++i) { n     for (j = 1; j < i; ++j) n       if ((a[i] == a[j] + i - j || a[i] < i - j) && b[j] % b[i] == 0) n         f[i] = max(f[i], f[j]); n     ans = max(ans, ++f[i]); n   } n   printf( %d , n - ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n using pi = pair<int, int>; n using pl = pair<ll, ll>; n using pld = pair<ld, ld>; n using vi = vector<int>; n using vl = vector<ll>; n using vb = vector<bool>; n using vld = vector<ld>; n using vs = vector<string>; n using vpi = vector<pi>; n using vpl = vector<pl>; n using vpld = vector<pld>; n int clz(unsigned long long N) { return N ? 63 - __builtin_clzll(N) : -1; } n int arr[300010]; n int acum[300010]; n int n, q; n void solvetask() { n   cin >> n >> q; n   for (int i = 0; i < n; i++) { n     char c; n     cin >> c; n     if (c ==  + ) n       arr[i] = (i & 1) ? -1 : 1; n     else n       arr[i] = (i & 1) ? 1 : -1; n   } n   for (int i = 1; i <= n; i++) acum[i] = acum[i - 1] + arr[i - 1]; n   while (q--) { n     int l, r; n     cin >> l >> r; n     int soma = acum[r] - acum[l - 1]; n     if (soma == 0) n       cout <<  0 n ; n     else if (abs(soma) % 2 == 1) n       cout <<  1 n ; n     else n       cout <<  2 n ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int t = 1; n   cin >> t; n   while (t--) solvetask(); n } n