#include <bits/stdc++.h>   using namespace std;   constexpr int MOD = 1000000007;   template <typename T, typename U>   std::istream& operator>>(std::istream& i, pair<T, U>& p) {     i >> p.first >> p.second;     return i;   }   template <typename T>   std::istream& operator>>(std::istream& i, vector<T>& t) {     for (auto& v : t) {       i >> v;     }     return i;   }   template <typename T>   std::ostream& operator<<(std::ostream& o, const vector<T>& t) {     for (size_t i = 0; i < t.size(); ++i) {       o << t[i] <<    n [i == t.size() - 1];     }     return o;   }   template <typename T>   using minheap = priority_queue<T, vector<T>, greater<T>>;   template <typename T>   using maxheap = priority_queue<T, vector<T>, less<T>>;   auto fraclt = [](const std::pair<int, int>& a, const std::pair<int, int>& b) {     return (long long)a.first * b.second < (long long)b.first * a.second;   };   struct cmpfrac {     bool operator()(const std::pair<int, int>& a,                     const std::pair<int, int>& b) const {       return (long long)a.first * b.second < (long long)b.first * a.second;     }   };   template <typename T>   bool in(T a, T b, T c) {     return a <= b && b < c;   }   unsigned int logceil(long long first) {     unsigned int b = 0;     while (first) {       first >>= 1;       ++b;     }     return b;   }   namespace std {   template <typename T, typename U>   struct hash<pair<T, U>> {     hash<T> t;     hash<U> u;     size_t operator()(const pair<T, U>& p) const {       return t(p.first) ^ (u(p.second) << 7);     }   };   }  // namespace std   template <typename T, typename F>   T bsh(T l, T h, const F& f) {     T r = -1, m;     while (l <= h) {       m = (l + h) / 2;       if (f(m)) {         l = m + 1;         r = m;       } else {         h = m - 1;       }     }     return r;   }   template <typename T, typename F>   T bsl(T l, T h, const F& f) {     T r = -1, m;     while (l <= h) {       m = (l + h) / 2;       if (f(m)) {         h = m - 1;         r = m;       } else {         l = m + 1;       }     }     return r;   }   template <typename T>   T gcd(T a, T b) {     if (a < b) swap(a, b);     return b ? gcd(b, a % b) : a;   }   template <typename T>   class vector2 : public vector<vector<T>> {    public:     vector2() {}     vector2(size_t a, size_t b, T t = T())         : vector<vector<T>>(a, vector<T>(b, t)) {}   };   template <typename T>   class vector3 : public vector<vector<vector<T>>> {    public:     vector3() {}     vector3(size_t a, size_t b, size_t c, T t = T())         : vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, t))) {}   };   template <typename T>   struct bounded_priority_queue {     inline bounded_priority_queue(unsigned int X) : A(X), B(0) {}     inline void push(unsigned int L, T V) {       B = max(B, L);       A[L].push(V);     }     inline const T& top() const { return A[B].front(); }     inline void pop() {       A[B].pop();       while (B > 0 && A[B].empty()) --B;     }     inline bool empty() const { return A[B].empty(); }     inline void clear() {       B = 0;       for (auto& a : A) a = queue<T>();     }       private:     vector<queue<T>> A;     unsigned int B;   };   struct UnionFind {     UnionFind(size_t N) : P(N, -1), comp(N) {}     int find(int first) {       while (P[first] >= 0) {         first = P[first];       }       return first;     }     bool united(int first, int second) { return find(first) == find(second); }     bool unite(int first, int second) {       first = find(first);       second = find(second);       if (first == second) {         return false;       }       --comp;       if (P[first] > P[second]) {         swap(first, second);       }       P[first] += P[second];       P[second] = first;       return true;     }     vector<int> P;     size_t comp;   };   unsigned long long mulull(unsigned long long a, unsigned long long z,                             unsigned long long mod) {     __int128 result = ((__int128)a * (__int128)z) % (__int128)mod;     return (unsigned long long)result;   }   pair<unsigned long long, unsigned long long> mulull(unsigned long long a,                                                       unsigned long long b) {     __int128 result = (__int128)a * (__int128)b;     return {(unsigned long long)(result >> 64), (unsigned long long)result};   }   bool fractionGreaterOrEqual(long long a, long long b, long long c,                               long long d) {     if (b < 0) {       b = -b;       a = -a;     }     if (d < 0) {       d = -d;       c = -c;     }     return a < 0 && c < 0 ? mulull(-a, d) <= mulull(-c, b)                           : (a >= 0) && (c < 0 || mulull(a, d) >= mulull(c, b));   }   bool fractionGreaterOrEqual(double a, double b, double c, double d) {     return a / b >= c / d;   }   namespace Envelope {   template <typename T>   struct Line {     T m, b;     mutable function<const Line<T>*()> succ;     bool operator<(const Line& rhs) const {       if (rhs.b != numeric_limits<T>::min()) return m < rhs.m;       const Line* s = succ();       if (!s) return 0;       return b - s->b < (s->m - m) * rhs.m;     }   };   template <typename T>   struct Upper : public multiset<Envelope::Line<T>> {     using parent = multiset<Line<T>>;     bool bad(typename parent::iterator second) {       auto z = next(second);       if (second == parent::begin()) {         return z != parent::end() && second->m == z->m && second->b <= z->b;       } else {         auto first = prev(second);         if (z == parent::end()) {           return second->m == first->m && second->b <= first->b;         } else {           return fractionGreaterOrEqual(first->b - second->b,                                         second->m - first->m, second->b - z->b,                                         z->m - second->m);         }       }     }     void insert_line(T m, T b) {       auto second = parent::insert({m, b});       second->succ = [=] {         return next(second) == parent::end() ? 0 : &*next(second);       };       if (bad(second)) {         parent::erase(second);         return;       }       while (next(second) != parent::end() && bad(next(second)))         parent::erase(next(second));       while (second != parent::begin() && bad(prev(second)))         parent::erase(prev(second));     }     T operator[](T first) const {       auto l = parent::lower_bound({first, numeric_limits<T>::min()});       return l == parent::end() ? numeric_limits<T>::min() : l->m * first + l->b;     }   };   template <typename T>   struct Lower : public Upper<T> {     void insert_line(T m, T b) { Upper<T>::insert_line(-m, -b); }     T operator[](T first) const { return -Upper<T>::operator[](first); }   };   }  // namespace Envelope   struct Sieve : public std::vector<bool> {     explicit Sieve(unsigned int n) : vector<bool>(n + 1, true), n(n) {       at(0) = false;       at(1) = false;       for (unsigned int i = 2; i * i <= n; ++i) {         if (at(i))           for (int j = i * i; j <= n; j += i) (*this)[j] = false;       }     }     vector<int> primes() const {       vector<int> ans;       for (int i = 2; i <= n; ++i)         if (at(i)) ans.push_back(i);       return ans;     }       private:     int n;   };   struct Moebius : public std::vector<std::pair<int, int>> {     explicit Moebius(unsigned int n) : Moebius(n, Sieve{n}.primes()) {}     Moebius(int n, const vector<int>& primes) {       search(-1, 1, 1, n, primes);       std::sort(begin(), end());     }       private:     void search(int i, int first, int second, int n, const vector<int>& primes) {       push_back({first, second});       while (++i < primes.size() && (long long)first * primes[i] <= n)         search(i, first * primes[i], -second, n, primes);     }   };   struct LargePrimes : public vector<int> {     LargePrimes()         : vector<int>{               7,     9,     21,    33,    87,    93,    97,    103,   123,               181,   207,   223,   241,   271,   289,   297,   321,   349,               363,   403,   409,   411,   427,   433,   439,   447,   453,               459,   483,   513,   531,   579,   607,   613,   637,   663,               711,   753,   787,   801,   829,   861,   871,   891,   901,               919,   931,   933,   993,   1011,  1021,  1053,  1087,  1099,               1137,  1161,  1203,  1213,  1237,  1263,  1269,  1273,  1279,               1311,  1329,  1333,  1351,  1371,  1393,  1413,  1447,  1449,               1491,  1501,  1531,  1537,  1539,  1581,  1617,  1621,  1633,               1647,  1663,  1677,  1699,  1759,  1773,  1789,  1791,  1801,               1803,  1819,  1857,  1887,  1917,  1927,  1957,  1963,  1969,               2043,  2089,  2103,  2139,  2149,  2161,  2173,  2187,  2193,               2233,  2239,  2277,  2307,  2359,  2361,  2431,  2449,  2457,               2499,  2571,  2581,  2607,  2631,  2637,  2649,  2667,  2727,               2791,  2803,  2821,  2823,  2827,  2907,  2937,  2989,  3009,               3013,  3051,  3057,  3097,  3111,  3133,  3153,  3157,  3163,               3211,  3241,  3247,  3253,  3267,  3271,  3273,  3283,  3309,               3337,  3351,  3357,  3373,  3379,  3397,  3469,  3471,  3513,               3519,  3559,  3577,  3579,  3601,  3621,  3643,  3651,  3663,               3679,  3709,  3747,  3751,  3769,  3777,  3787,  3793,  3843,               3853,  3871,  3889,  3891,  3909,  3919,  3931,  3951,  3957,               3967,  3987,  3999,  4023,  4059,  4099,  4119,  4123,  4207,               4233,  4249,  4251,  4263,  4321,  4329,  4381,  4389,  4437,               4449,  4459,  4497,  4507,  4519,  4539,  4567,  4569,  4581,               4609,  4611,  4627,  4633,  4647,  4693,  4699,  4717,  4771,               4777,  4783,  4791,  4807,  4839,  4843,  4849,  4857,  4867,               4869,  4891,  4893,  4897,  4927,  4933,  4977,  4981,  5001,               5029,  5053,  5067,  5103,  5133,  5187,  5197,  5203,  5233,               5277,  5287,  5299,  5317,  5329,  5341,  5353,  5361,  5403,               5407,  5437,  5443,  5449,  5451,  5469,  5491,  5527,  5541,               5547,  5583,  5631,  5647,  5683,  5731,  5737,  5751,  5763,               5791,  5823,  5827,  5833,  5847,  5863,  5899,  5907,  5947,               5953,  5959,  5971,  5973,  5991,  5997,  6019,  6027,  6037,               6039,  6061,  6093,  6099,  6127,  6129,  6177,  6193,  6211,               6223,  6229,  6307,  6313,  6331,  6349,  6379,  6393,  6417,               6421,  6457,  6459,  6477,  6541,  6571,  6577,  6583,  6607,               6621,  6661,  6663,  6697,  6717,  6751,  6781,  6837,  6867,               6901,  6957,  6961,  6967,  6981,  7003,  7023,  7027,  7089,               7117,  7137,  7147,  7159,  7191,  7209,  7237,  7243,  7257,               7279,  7321,  7347,  7383,  7389,  7417,  7429,  7447,  7453,               7467,  7479,  7497,  7513,  7521,  7531,  7537,  7557,  7633,               7647,  7651,  7653,  7681,  7707,  7719,  7741,  7759,  7773,               7803,  7819,  7837,  7873,  7887,  7909,  7923,  7927,  7929,               7941,  8041,  8083,  8089,  8101,  8109,  8127,  8173,  8181,               8223,  8257,  8259,  8271,  8277,  8311,  8313,  8343,  8349,               8397,  8403,  8419,  8431,  8439,  8487,  8511,  8557,  8593,               8617,  8637,  8649,  8661,  8671,  8679,  8719,  8727,  8761,               8773,  8791,  8797,  8803,  8811,  8829,  8853,  8899,  8917,               8937,  8967,  9009,  9013,  9063,  9081,  9093,  9099,  9123,               9133,  9163,  9183,  9211,  9223,  9259,  9277,  9279,  9289,               9301,  9321,  9331,  9363,  9399,  9403,  9421,  9441,  9457,               9469,  9487,  9519,  9529,  9531,  9541,  9559,  9561,  9567,               9573,  9579,  9597,  9601,  9609,  9631,  9651,  9667,  9679,               9711,  9733,  9739,  9757,  9789,  9831,  9859,  9867,  9961,               9999,  10029, 10051, 10069, 10101, 10153, 10173, 10189, 10197,               10233, 10243, 10251, 10267, 10281, 10303, 10321, 10327, 10351,               10357, 10381, 10449, 10467, 10483, 10503, 10513, 10549, 10593,               10597, 10611, 10633, 10659, 10699, 10707, 10723, 10747, 10749,               10761, 10773, 10777, 10801, 10833, 10903, 10953, 10969, 10971,               10981, 10987, 11007, 11011, 11071, 11083, 11091, 11107, 11109,               11137, 11149, 11161, 11223, 11239, 11253, 11269, 11277, 11283,               11289, 11301, 11317, 11329, 11371, 11377, 11391, 11421, 11479,               11487, 11497, 11517, 11533, 11539, 11559, 11583, 11601, 11619,               11631, 11659, 11673, 11679, 11707, 11763, 11767, 11769, 11773,               11799, 11811, 11821, 11823, 11847, 11869, 11967, 11983, 11989,               12019, 12037, 12121, 12157, 12177, 12187, 12217, 12219, 12231,               12241, 12253, 12297, 12309, 12333, 12337, 12339, 12361, 12367,               12399, 12411, 12459, 12463, 12483, 12501, 12513, 12523, 12547,               12553, 12577, 12609, 12631, 12649, 12679, 12681, 12703, 12723,               12733, 12747, 12753, 12759, 12799, 12847, 12877, 12891, 12901,               12903, 12927, 12939, 12963, 13011, 13017, 13029, 13039, 13081,               13087, 13089, 13101, 13107, 13137, 13141, 13143, 13153, 13191,               13207, 13213, 13237, 13323, 13369, 13419, 13437, 13447, 13477,               13519, 13537, 13561, 13563, 13587, 13591, 13723, 13741, 13759,               13789, 13801, 13857, 13881, 13897, 13921, 13923, 13939, 13999,               14011, 14073, 14077, 14083, 14097, 14121, 14131, 14143, 14157,               14161, 14167, 14181, 14193, 14209, 14241, 14259, 14271, 14293,               14361, 14391, 14397, 14437, 14529, 14551, 14581, 14583, 14599,               14607, 14611, 14643, 14727, 14761, 14773, 14779, 14791, 14823,               14853, 14881, 14889, 14901, 14931, 14937, 14997, 15031, 15043,               15057, 15063, 15069, 15097, 15103, 15109, 15117, 15141, 15147,               15187, 15199, 15217, 15231, 15253, 15271, 15279, 15283, 15307,               15339, 15349, 15351, 15363, 15369, 15409, 15427, 15447, 15477,               15487, 15553, 15579, 15591, 15649, 15651, 15673, 15693, 15703,               15717, 15727, 15747, 15799, 15811, 15823, 15859, 15889, 15963,               15981, 16009, 16021, 16029, 16047, 16063, 16089, 16093, 16107,               16153, 16167, 16191, 16201, 16231, 16233, 16261, 16267, 16273,               16317, 16323, 16411, 16419, 16431, 16489, 16491, 16513, 16539,               16617, 16621, 16623, 16627, 16651, 16659, 16671, 16711} {       for (int& i : *this) i += 1000000000;     }   };   bool isPrime(long long n) {     for (int p :          {2,   3,   5,   7,   11,  13,  17,  19,  23,  29,  31,  37,  41,  43,           47,  53,  59,  61,  67,  71,  73,  79,  83,  89,  97,  101, 103, 107,           109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181,           191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257})       if (p < n && n % p == 0) return false;     long long d = n - 1, r = 0;     while (d % 2 == 0) {       d /= 2;       r += 1;     }     auto composite = [=](int a) {       long long first = 1, p = a, e = d;       while (e > 0) {         if (e % 2 > 0) {           first = mulull(first, p, n);         }         e /= 2;         p = mulull(p, p, n);       }       if (first == 1 || first == n - 1) return false;       for (int i = 1; i < r; ++i) {         first = mulull(first, first, n);         if (first == 1) return true;         if (first == n - 1) return false;       }       return true;     };     return !(composite(2)) && (n < 2047 || !composite(3)) &&            (n < 1373653 || !composite(5)) && (n < 25326001 || !composite(7)) &&            (n < 3215031751LL || !composite(11)) &&            (n < 2152302898747LL || !composite(13)) &&            (n < 3474749660383LL || !composite(17)) &&            (n < 341550071728321LL || (!composite(19) && !composite(23))) &&            (n < 3825123056546413051LL ||             (!composite(29) && !composite(31) && !composite(37)));   }   class TaskB {    public:     void solve(istream& cin, ostream& cout) {       int N, X, Y;       cin >> N >> X >> Y;       vector<int> C(2000001, 0), PC(2000001, 0);       vector<long long> S(2000001, 0), PS(2000001, 0);       for (int i = 0; i < N; ++i) {         int a;         cin >> a;         C[a]++;         S[a] += a;       }       for (int i = 1; i < 2000001; ++i) {         PC[i] = PC[i - 1] + C[i];         PS[i] = PS[i - 1] + S[i];       }       int maxDiff = X / Y + 1;       long long ans = numeric_limits<long long>::max();       for (int p : Sieve{1000000}.primes()) {         long long cost = 0;         for (int i = p; i - p <= 1000000; i += p) {           cost += Y * ((long long)i * (PC[i] - PC[i - min(maxDiff, p)]) -                        (PS[i] - PS[i - min(p, maxDiff)]));           cost += X * (long long)(PC[i - min(maxDiff, p)] - PC[i - p]);         }         ans = min(ans, cost);       }       cout << ans << endl;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     TaskB solver;     std::istream& in(std::cin);     std::ostream& out(std::cout);     solver.solve(in, out);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, n;     char a[1000][10];     cin >> n;     cin >> a[0];     for (i = 1; i <= n; i++) {       cin >> a[i];     }     if (n % 2 == 0)       cout <<  home ;     else       cout <<  contest ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> v[1010];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       int aux, aux2;       scanf( %d , &aux);       for (int j = 0; j < aux; ++j) {         scanf( %d , &aux2);         v[i].push_back(aux2);       }       sort(v[i].begin(), v[i].end());     }     int r = 0;     for (int i = 0; i < n; ++i) {       int pnt1 = 0, pnt2 = 0;       int pr = (i - 1 + n) % n, ne = (i + 1) % n;       for (int j = 0; j < v[i].size() - 1; ++j) {         int q1 = 0, q2 = 0;         while (pnt1 < v[pr].size() && v[pr][pnt1] < v[i][j]) pnt1++;         while (pnt1 < v[pr].size() && v[pr][pnt1] < v[i][j + 1]) pnt1++, q1++;         while (pnt2 < v[ne].size() && v[ne][pnt2] < v[i][j]) pnt2++;         while (pnt2 < v[ne].size() && v[ne][pnt2] < v[i][j + 1]) pnt2++, q2++;         if (q1 != q2) r++;       }     }     printf( %d n , r);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int b[111111], n;   int check(int k) {     int l = n / k;     for (int i = 0; i < l; i++) {       int ok = 1;       int cur = i;       for (int j = 0; ok && j < k; j++) {         if (!b[cur]) ok = 0;         cur += l;         cur %= n;       }       if (ok) return 1;     }     return 0;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> b[i];     int flag = 0;     for (int i = 3; i <= n; i++) {       if (n % i == 0) {         if (check(i)) flag = 1;       }     }     printf(flag ?  YES n  :  NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double a, b, h;     cin >> a >> b;     h = (b * b - a * a) / (2 * a);     h = h + (1 / 1000000);     cout << fixed << setprecision(13) << h << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int a[3];     int s = 0;     int count = 0;     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < 3; j++) {         cin >> a[j];         if (a[j] == 1) count++;       }       if (count >= 2) s++;       count = 0;     }     cout << s << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void amin(T &a, const T &b) {     if (b < a) a = b;   }   template <class T>   inline void amax(T &a, const T &b) {     if (a < b) a = b;   }   struct Data {     int sx, sy;     int le, ri, to, bo;     bool operator<(const Data &y) const { return sx < y.sx; }   };   int N, Q;   int main() {     scanf( %d%d , &N, &Q);     set<Data> S;     S.insert((Data){1, 1, 1, N, 1, N});     Data seek;     for (int $ = 0, $_len = (Q); $ < $_len; ++$) {       int col, row;       char buf[8], dir;       scanf( %d%d%s , &col, &row, buf);       dir = buf[0];       int ans = 0;       seek.sx = col;       set<Data>::iterator it = S.upper_bound(seek);       if (it != S.begin()) {         it--;         if (it->sx <= col && col <= it->ri) {           Data D = *it;           S.erase(it);           if (dir ==  U ) {             ans = row - D.to + 1;             if (D.sx < col)               S.insert((Data){D.sx, row + 1, D.le, col - 1, D.to, D.bo});             if (col < D.ri)               S.insert((Data){col + 1, D.sy, col + 1, D.ri, D.to, row - 1});           } else {             ans = col - D.le + 1;             if (D.sy < row)               S.insert((Data){col + 1, D.sy, D.le, D.ri, D.to, row - 1});             if (row < D.bo)               S.insert((Data){D.sx, row + 1, D.le, col - 1, row + 1, D.bo});           }         } else {           ans = 0;         }       } else {         ans = 0;       }       printf( %d n , ans);     }     return 0;   }


#include<cstdio>   #include<cstring>   #include<vector>   typedef long long ll;   int main()   {       int t,a[120];       scanf( %d ,&t);       while(t--)       {           int n,u,v;           scanf( %d%d%d ,&n,&u,&v);              for(int i=1;i<=n;i++)           {              scanf( %d ,&a[i]);           }           int j,b=0;           for(j=2;j<=n;j++)           {               if(a[j]==a[j-1]+1||a[j]==a[j-1]-1)                   {b=1;}               if(a[j]>a[j-1]+1||a[j]<a[j-1]-1)               {                   b=2;break;               }           }           if(b==0)              {                  if(u<v)           printf( %d n ,u+v);           else               printf( %d n ,2*v);              }           else if(b==2)           {               printf( 0 n );           }           else           {               if(u>v)printf( %d n ,v);               else printf( %d n ,u);           }       }       return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   inline long long getint() {     long long _x = 0, _tmp = 1;     char _tc = getchar();     while ((_tc <  0  || _tc >  9 ) && _tc !=  - ) _tc = getchar();     if (_tc ==  - ) _tc = getchar(), _tmp = -1;     while (_tc >=  0  && _tc <=  9 ) _x *= 10, _x += (_tc -  0 ), _tc = getchar();     return _x * _tmp;   }   inline long long add(long long _x, long long _y,                        long long _mod = 1000000007LL) {     _x += _y;     return _x >= _mod ? _x - _mod : _x;   }   inline long long sub(long long _x, long long _y,                        long long _mod = 1000000007LL) {     _x -= _y;     return _x < 0 ? _x + _mod : _x;   }   inline long long mul(long long _x, long long _y,                        long long _mod = 1000000007LL) {     _x *= _y;     return _x >= _mod ? _x % _mod : _x;   }   long long mypow(long long _a, long long _x, long long _mod) {     if (_x == 0) return 1LL;     long long _ret = mypow(mul(_a, _a, _mod), _x >> 1, _mod);     if (_x & 1) _ret = mul(_ret, _a, _mod);     return _ret;   }   long long mymul(long long _a, long long _x, long long _mod) {     if (_x == 0) return 0LL;     long long _ret = mymul(add(_a, _a, _mod), _x >> 1, _mod);     if (_x & 1) _ret = add(_ret, _a, _mod);     return _ret;   }   inline bool equal(double _x, double _y) {     return _x > _y - 1e-9 && _x < _y + 1e-9;   }   int __ = 1, _cs;   struct Mat {     int n, a[101][101];     Mat(int _n) {       n = _n;       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++) a[i][j] = 0;     }     Mat operator*(const Mat& he) const {       Mat ret(n);       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++)           for (int k = 0; k < n; k++)             ret.a[i][j] = add(ret.a[i][j], mul(a[i][k], he.a[k][j]));       return ret;     }     Mat operator^(int tms) const {       Mat ret(n), tmp(n);       for (int i = 0; i < n; i++) {         ret.a[i][i] = 1;         for (int j = 0; j < n; j++) tmp.a[i][j] = a[i][j];       }       while (tms > 0) {         if (tms & 1) ret = ret * tmp;         tmp = tmp * tmp;         tms >>= 1;       }       return ret;     }   };   void build() {}   int n, l, m, s[1010101], u[1010101], o[1010101];   void init() {     n = getint();     l = getint();     m = getint();     for (int i = 0; i < n; i++) s[i] = getint();     for (int i = 0; i < n; i++) u[i] = getint();     for (int i = 0; i < n; i++) o[i] = getint();   }   int cnt[111], sc[111], oc[111][111];   void solve() {     Mat tmp(m);     for (int i = 0; i < n; i++) cnt[u[i] % m]++;     for (int i = 0; i < m; i++)       for (int j = 0; j < m; j++) {         int dlt = (i - j + m) % m;         tmp.a[i][j] = cnt[dlt];       }     for (int i = 0; i < n; i++) sc[s[i] % m]++;     for (int i = 0; i < n; i++) oc[u[i] % m][o[i] % m]++;     tmp = tmp ^ (l - 2);     int ans = 0;     for (int i = 0; i < m; i++)       if (sc[i])         for (int j = 0; j < m; j++)           for (int k = 0; k < m; k++) {             if (oc[j][k] == 0) continue;             int tar = (m - (i + j + k) % m) % m;             ans = add(ans, mul(sc[i], mul(oc[j][k], tmp.a[tar][0])));           }     printf( %d n , ans);   }   int main() {     build();     while (__--) {       init();       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string one, two;     map<string, string> m;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> one >> two;       bool found = false;       for (map<string, string>::iterator it = m.begin(); it != m.end(); ++it) {         if (it->second == one) {           it->second = two;           found = true;         }       }       if (!found) {         m.insert(pair<string, string>(one, two));       }     }     cout << m.size() <<   n ;     for (map<string, string>::iterator it = m.begin(); it != m.end(); ++it) {       cout << it->first <<     << it->second <<   n ;     }     cout << flush;     return 0;   }


// Author:  HolyK   // Created: Thu Jul  8 09:48:07 2021   #include <bits/stdc++.h>   #define dbg(a...) fprintf(stderr, a)   template <class T, class U>   inline bool smin(T &x, const U &y) {     return y < x ? x = y, 1 : 0;   }   template <class T, class U>   inline bool smax(T &x, const U &y) {     return x < y ? x = y, 1 : 0;   }      using LL = long long;   using PII = std::pair<int, int>;      int ask(int x) {     std::cout << x << std::endl;     int r;     std::cin >> r;     return r;   }   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     int t;     std::cin >> t;     while (t--) {       int n, k;       std::cin >> n >> k;       if (ask(0)) continue;       for (int i = 1; i < n; i++) {         int x = 0;         for (int j = 1; j <= i; j *= k) {    int u = (i / j - (i - 1) / j) % k;    if (i & 1) u = (k - u) % k;    x += u * j;         }         if (ask(x)) break;       }     }     return 0;   }   /*   0    */


#include <bits/stdc++.h>   using namespace std;   void computeLcp(string &s1, string &s2, int LCP[][5005]) {     for (int i = ((int)s1.size()) - 1; i >= 0; i--) {       for (int j = ((int)s2.size()) - 1; j >= 0; j--) {         if (s1[i] == s2[j]) {           LCP[i][j] = 1 + LCP[i + 1][j + 1];         } else {           LCP[i][j] = 0;         }       }     }   }   int lcp[5005][5005];   int mUA[5005];   int mUB[5005];   int main() {     ios_base::sync_with_stdio(0);     string A, B;     cin >> A >> B;     memset((lcp), (0), sizeof(lcp));     ;     computeLcp(A, A, lcp);     int ans = (1 << 30);     for (int i = 0; i < ((int)A.size()); i++) {       int minUniqueLength = 0;       for (int j = 0; j < ((int)A.size()); j++) {         if (i == j) continue;         minUniqueLength = max(minUniqueLength, lcp[i][j]);       }       minUniqueLength++;       mUA[i] = minUniqueLength;     }     memset((lcp), (0), sizeof(lcp));     ;     computeLcp(B, B, lcp);     for (int i = 0; i < ((int)B.size()); i++) {       int minUniqueLength = 0;       for (int j = 0; j < ((int)B.size()); j++) {         if (i == j) continue;         minUniqueLength = max(minUniqueLength, lcp[i][j]);       }       minUniqueLength++;       mUB[i] = minUniqueLength;     }     memset((lcp), (0), sizeof(lcp));     ;     computeLcp(A, B, lcp);     for (int i = 0; i < ((int)A.size()); i++) {       for (int j = 0; j < ((int)B.size()); j++) {         if (lcp[i][j] >= max(mUA[i], mUB[j])) {           ans = min(ans, max(mUA[i], mUB[j]));         }       }     }     if (ans >= (1 << 30)) ans = -1;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x;   void solve() {     cin >> n >> x;     int left = x - 1;     int right = n - x;     if (left >= right)       cout << (x - 1 == 0 ? 1 : x - 1) << endl;     else       cout << (x + 1 > n ? n : x + 1) << endl;   }   int main() {     ios_base ::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);     ;     int tt;     tt = 1;     for (int i = 1; i <= tt; ++i) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > res;   int n;   int tx[1000000], add[1000000];   void up(int i, int l, int r, int a, int b, int x) {     if (b < l || a > r) return;     if (a <= l && b >= r) {       tx[i] += x;       add[i] += x;       return;     }     int m = (l + r) / 2;     up(2 * i, l, m, a, b, x);     up(2 * i + 1, m + 1, r, a, b, x);     tx[i] = min(tx[2 * i], tx[2 * i + 1]) + add[i];   }   int getmin(int i, int l, int r, int a, int b) {     if (b < l || a > r) return 1000000000;     if (a <= l && b >= r) return tx[i];     int m = (l + r) / 2;     return min(getmin(2 * i, l, m, a, b), getmin(2 * i + 1, m + 1, r, a, b)) +            add[i];   }   void com(int l, int r) {     if (l > r) return;     if (l == r) {       for (int i = 0; i < getmin(1, 1, n, l, l); i++)         res.push_back(make_pair(l, r));       return;     }     int m = getmin(1, 1, n, l, r);     if (m == 0) {       int mid = (l + r) / 2;       int left = l;       int right = r;       while (1) {         mid = (left + right) / 2;         if (getmin(1, 1, n, l, mid) == 0) {           if (getmin(1, 1, n, mid, mid) == 0) {             com(l, mid - 1);             com(mid + 1, r);             return;           } else             right = mid;         } else           left = mid + 1;       }     } else if (m > 0) {       up(1, 1, n, l, r, -m);       for (int i = 0; i < m; i++) res.push_back(make_pair(l, r));       com(l, r);     }   }   int main() {     int k;     scanf( %d , &n);     ;     for (int i = 0; i < n; i++) {       scanf( %d , &k);       ;       up(1, 1, n, i + 1, i + 1, k);     }     com(1, n);     cout << res.size() << endl;     for (int i = 0; i < res.size(); i++)       printf( %d %d n , res[i].first, res[i].second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, ans = 1, res = 1, x, mn = 0, mx = 1e9;   set<int> S;   set<int>::iterator it;   char s[10];   int main() {     scanf( %d , &n);     S.insert(1e9), S.insert(0);     for (int i = 1; i <= n; ++i) {       scanf( %s%d , s, &x);       if (s[1] ==  D )         S.insert(x), res += (x >= mn && x <= mx) ? 1 : 0;       else {         if (x < mn || x > mx) ans = 0;         if (x != mn && x != mx) ans = 2 * ans % 1000000007;         S.erase(x);         res = 1;         it = S.lower_bound(x);         mx = *it;         mn = *(--it);       }     }     printf( %d n , 1ll * ans * res % 1000000007);   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> g[100005];   int dep[100005], f[20][100005], mrk[100005], ans[100005];   map<pair<int, int>, int> mp;   void dfs(int x, int p, int d) {     for (int i = 0; i < g[x].size(); i++)       if (g[x][i] != p) dfs(g[x][i], f[0][g[x][i]] = x, dep[g[x][i]] = d + 1);   }   int dfs2(int x, int p) {     int cnt = 0;     for (int i = 0; i < g[x].size(); i++)       if (g[x][i] != p) {         int num = dfs2(g[x][i], x);         ans[mp[make_pair(x, g[x][i])]] = num;         cnt += num;       }     cnt += mrk[x];     return cnt;   }   int lca(int x, int y) {     if (dep[x] < dep[y]) swap(x, y);     int sub = dep[x] - dep[y];     for (int i = 0; i < 20; i++)       if (sub & (1 << i)) x = f[i][x];     if (x == y) return x;     for (int i = 19; i >= 0; i--)       if (f[i][x] != f[i][y]) {         x = f[i][x];         y = f[i][y];       }     x = f[0][x];     y = f[0][y];     return x;   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       g[x].push_back(y);       g[y].push_back(x);       mp[make_pair(x, y)] = i;       mp[make_pair(y, x)] = i;     }     dfs(1, f[0][1] = 0, dep[1] = 1);     for (int i = 1; i < 20; i++)       for (int j = 1; j <= n; j++) f[i][j] = f[i - 1][f[i - 1][j]];     int q;     scanf( %d , &q);     while (q--) {       int x, y;       scanf( %d%d , &x, &y);       mrk[x]++;       mrk[y]++;       mrk[lca(x, y)] -= 2;     }     dfs2(1, 0);     for (int i = 1; i < n; i++) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const long long INF = 1e18;   const int MAXN = 1e5 + 1;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int b, g, n;     cin >> b >> g >> n;     cout << min(b, min(g, n)) + 1 - max(0, n - max(b, g));     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   int n, l[100100], r[100100];   int rs[100100], dp[2][100100];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> l[i];     for (int i = 1; i <= n; i++) cin >> r[i];     int val = n, cnt = n;     for (int i = 1; i <= n; i++) {       if (l[i] == r[i] && !r[i]) rs[i] = val, cnt--;     }     int cn = 0;     while (cnt && cn <= 10000) {       val--;       for (int i = 1; i <= n; i++) dp[0][i] = dp[0][i - 1] + (rs[i] > 0);       for (int i = n; i; i--) dp[1][i] = dp[1][i + 1] + (rs[i] > 0);       for (int i = 1; i <= n; i++) {         if (!rs[i] && dp[0][i] == l[i] && dp[1][i] == r[i]) rs[i] = val, cnt--;       }       cn++;     }     if (cn >= 10000) return cout <<  NO , 0;     for (int i = 1; i <= n; i++)       if (rs[i] <= 0) return cout <<  NO , 0;     cout <<  YES n ;     for (int i = 1; i <= n; i++) cout << rs[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double dist(int x, int y, int a, int b) {     return sqrt((x - a) * (x - a) + (y - b) * (y - b));   }   int main() {     ios_base::sync_with_stdio(false);     cout.tie(0);     cout << fixed;     cout.precision(10);     int n, m;     cin >> n;     int c, r;     vector<pair<pair<int, int>, int> > arr;     for (int i = 0; i < n; i++) {       cin >> c >> r;       arr.emplace_back(pair<int, int>(c, r), i);     }     sort(arr.begin(), arr.end());     int centre[n];     for (int i = 0; i < n; i++) {       centre[i] = arr[i].first.first;     }     int count[n];     for (int i = 0; i < n; i++) {       count[i] = INT_MAX;     }     cin >> m;     for (int i = 1; i <= m; i++) {       int x, y;       cin >> x >> y;       if (x <= centre[0]) {         if (dist(x, y, arr[0].first.first, 0) <= arr[0].first.second) {           count[0] = min(count[0], i);         }       } else if (x >= arr[n - 1].first.first) {         if (dist(x, y, arr[n - 1].first.first, 0) <= arr[n - 1].first.second) {           count[n - 1] = min(count[n - 1], i);         }       } else {         int pos = upper_bound(centre, centre + n, x) - centre;         if (dist(x, y, arr[pos].first.first, 0) <= arr[pos].first.second) {           count[pos] = min(count[pos], i);         }         if (dist(x, y, arr[pos - 1].first.first, 0) <=             arr[pos - 1].first.second) {           count[pos - 1] = min(count[pos - 1], i);         }       }     }     int sol[n];     int res = 0;     for (int i = 0; i < n; i++) {       sol[arr[i].second] = count[i];       if (count[i] != INT_MAX) {         res++;       }     }     cout << res << (  n );     for (int i = 0; i < n; i++) {       if (sol[i] != INT_MAX) {         cout << sol[i] <<    ;       } else {         cout << -1 <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int p[2001];   int a[2001];   int find(int v) {     if (p[v] != v) p[v] = find(p[v]);     return p[v];   }   void merge(int u, int v) {     int pu = find(u);     int pv = find(v);     p[pu] = pv;   }   int main() {     int n, m, k, i, l, r;     cin >> n >> m >> k;     for (i = 0; i < n; i++) p[i] = i;     for (i = 0; i < n; i++) {       l = i;       r = i + k - 1;       if (r >= n) break;       while (l < r) {         merge(l, r);         l++;         r--;       }     }     for (i = 0; i < n; i++) {       p[i] = find(i);       a[p[i]]++;     }     long long re = 1;     for (i = 0; i < n; i++)       if (a[i] > 0) {         re *= m;         re %= 1000000007;       }     cout << re;     return 0;   }


#include <bits/stdc++.h>   int main() {     long long int n, a, b, i, t;     scanf( %lld %lld %lld , &n, &a, &b);     t = n / a + 1;     for (i = 0; i < t; i++) {       if ((n - (a * i)) % b == 0 && n - (a * i) >= 0) {         printf( YES n%lld %lld , i, (n - (a * i)) / b);         return 0;       }     }     printf( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int max(long long int a, long long int b) {     if (a > b)       return a;     else       return b;   }   long long int min(long long int a, long long int b) {     if (a < b)       return a;     else       return b;   }   const int dx[4] = {-1, 1, 0, 0};   const int dy[4] = {0, 0, -1, 1};   int XX[] = {-1, -1, -1, 0, 0, 1, 1, 1};   int YY[] = {-1, 0, 1, -1, 1, -1, 0, 1};   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     long long int k, i, j, t, a, b, l, r, x, n;     cin >> n >> k;     long long int arr[n];     for (i = 0; i < n; i++) {       cin >> arr[i];     }     sort(arr, arr + n);     long long int maxi = k, count = 0;     for (i = 0; i < n; i++) {       long long int z = ceil(arr[i] * 1.0 / 2);       if (maxi >= z) {         maxi = max(maxi, arr[i]);         continue;       }       while (maxi < z) {         maxi = 2 * maxi;         count++;       }       maxi = max(maxi, arr[i]);     }     cout << count;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &x) {     char c;     bool nega = 0;     while ((!isdigit(c = getchar())) && (c !=  - ))       ;     if (c ==  - ) {       nega = 1;       c = getchar();     }     x = c - 48;     while (isdigit(c = getchar())) x = x * 10 + c - 48;     if (nega) x = -x;   }   template <typename T>   inline void writep(T x) {     if (x > 9) writep(x / 10);     putchar(x % 10 + 48);   }   template <typename T>   inline void write(T x) {     if (x < 0) {       putchar( - );       x = -x;     }     writep(x);   }   template <typename T>   inline void writeln(T x) {     write(x);     putchar(  n );   }   int n, h[300003], dp[300003];   set<int> st[300003];   vector<pair<int, int> > ve;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int i, j;     cin >> n;     for (i = 0; i < n; i++) cin >> h[i];     pair<int, int> t;     ve.push_back({0, h[0]});     for (i = 1; i < n; i++) {       t = ve.back();       while (h[i] <= t.second) {         st[t.first].insert(i);         ve.pop_back();         if (ve.empty()) break;         t = ve.back();       }       ve.push_back({i, h[i]});     }     ve.clear();     ve.push_back({0, h[0]});     for (i = 1; i < n; i++) {       t = ve.back();       while (h[i] >= t.second) {         st[t.first].insert(i);         ve.pop_back();         if (ve.empty()) break;         t = ve.back();       }       ve.push_back({i, h[i]});     }     ve.clear();     ve.push_back({n - 1, h[n - 1]});     for (i = n - 2; i >= 0; i--) {       t = ve.back();       while (h[i] >= t.second) {         st[i].insert(t.first);         ve.pop_back();         if (ve.empty()) break;         t = ve.back();       }       ve.push_back({i, h[i]});     }     ve.clear();     ve.push_back({n - 1, h[n - 1]});     for (i = n - 2; i >= 0; i--) {       t = ve.back();       while (h[i] <= t.second) {         st[i].insert(t.first);         ve.pop_back();         if (ve.empty()) break;         t = ve.back();       }       ve.push_back({i, h[i]});     }     dp[n - 1] = 0;     set<int>::iterator it;     for (i = n - 2; i >= 0; i--) {       dp[i] = 0x3f3f3f3f;       for (it = st[i].begin(); it != st[i].end(); it++) {         dp[i] = ((dp[i]) < (dp[*it] + 1) ? (dp[i]) : (dp[*it] + 1));       }     }     cout << dp[0] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, s = 0, i, x, vs = 0;     vector<int> a;     cin >> n;     for (i = 0; i < n; i++) {       cin >> x;       a.push_back(x);       vs += x;     }     sort(a.begin(), a.end(), std::greater<int>());     if (n == 1)       cout << a[0] << endl;     else if (n == 2)       cout << 2 * vs << endl;     else {       while (a.size() > 1) {         s += vs;         s += a.back();         vs -= a.back();         a.pop_back();       }       s += a[0];       cout << s << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   struct pp {     int val;     int same;   };   vector<pp> with[100005];   vector<int> v[100005];   int color[100005];   int currcolor[100005];   bool ending = false;   void dfs(int parent, int curr) {     if (ending == true) return;     for (int i = 1; i <= with[curr][0].val; i++) {       if (ending == true) return;       if (with[curr][i].val == parent) continue;       int vertex = with[curr][i].val;       if ((currcolor[vertex] != -1) &&           ((currcolor[vertex] + currcolor[curr] + with[curr][i].same) % 2 == 0)) {         cout <<  NO n ;         ending = true;         return;       }       if (currcolor[vertex] != -1) continue;       if (with[curr][i].same == 1)         currcolor[vertex] = currcolor[curr];       else         currcolor[vertex] = 1 - currcolor[curr];       dfs(curr, vertex);     }   }   int main() {     int n, m;     cin >> n >> m;     pp nullpp;     nullpp.val = 0, nullpp.same = 0;     for (int i = 1; i <= m; i++) with[i].push_back(nullpp);     for (int i = 1; i <= n; i++) cin >> color[i];     for (int i = 1; i <= m; i++) {       int k, val;       cin >> k;       for (int j = 1; j <= k; j++) {         cin >> val;         v[val].push_back(i);       }     }     for (int i = 1; i <= n; i++) {       with[v[i][0]][0].val++;       pp ed;       ed.val = v[i][1];       ed.same = color[i];       with[v[i][0]].push_back(ed);       with[v[i][1]][0].val++;       ed.val = v[i][0];       with[v[i][1]].push_back(ed);     }     for (int i = 1; i <= m; i++) currcolor[i] = -1;     for (int i = 1; i <= m; i++)       if (currcolor[i] == -1) {         currcolor[i] = 1;         dfs(-1, i);       }     if (ending == false) cout <<  YES n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int m[N];   int main(void) {     int n, a, b, k;     scanf( %d %d %d %d , &n, &a, &b, &k);     int ans = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &m[i]);       m[i] = m[i] % (a + b);       if (m[i] == 0) {         m[i] = a + b;       }     }     sort(m + 1, m + 1 + n);     for (int i = 1; i <= n; i++) {       int need = m[i] / a;       if (m[i] % a) need++;       if (need > 1) {         k -= need - 1;       }       if (k >= 0) {         ans++;       } else         break;     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int v[55];   double dp[55][55][55];   int main() {     int n, p, sum = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &v[i]);       sum += v[i];     }     scanf( %d , &p);     if (sum <= p) {       printf( %d n , n);       return 0;     }     double ans = 0;     for (int i = 1; i <= n; i++) {       memset(dp, 0, sizeof dp);       dp[0][0][0] = 1;       swap(v[i], v[n]);       for (int j = 1; j < n; j++) {         for (int cnt = 0; cnt < j; cnt++) {           for (int k = 0; k <= p; k++) {             if (k + v[j] <= p)               dp[j][cnt + 1][k + v[j]] += dp[j - 1][cnt][k] * (cnt + 1) / j;             dp[j][cnt][k] += dp[j - 1][cnt][k] * (j - cnt) / j;           }         }       }       for (int cnt = 0; cnt < n; cnt++) {         for (int k = 0; k + v[n] <= p; k++) {           ans += dp[n - 1][cnt][k] / n;         }       }       swap(v[i], v[n]);     }     printf( %.15lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> p;   bool first[5000] = {0};   void gen() {     p.push_back(0);     for (int i = 2; i <= 500; i++) {       if (!first[i]) {         p.push_back(i);         for (int j = 2 * i; j <= 500; j += i) {           first[j] = 1;         }       }     }   }   bool isprime(int x) {     int sz = sqrt(x) + 1;     for (int i = 2; i <= sz; i++) {       if (x % i == 0) return 0;     }     return 1;   }   int main() {     gen();     int n;     cin >> n;     if (n <= 500) {       vector<int> ans;       for (int i = 0; i < p.size(); i++) {         if (p[i] > n) break;         for (int j = 0; j <= i; j++) {           for (int k = 0; k <= j; k++) {             if (p[i] + p[j] + p[k] == n) {               if (p[i]) ans.push_back(p[i]);               if (j) ans.push_back(p[j]);               if (k) ans.push_back(p[k]);               cout << ans.size() <<   n ;               for (auto x : ans) {                 cout << x <<    ;               }               return 0;             }           }         }       }     } else {       vector<int> ans;       for (int i = n; i >= n - 500; i--) {         if (isprime(i)) {           ans.push_back(i);           n -= i;           break;         }       }       for (int i = 0; i < p.size(); i++) {         if (p[i] > n) break;         for (int j = 0; j <= i; j++) {           if (p[i] + p[j] == n) {             if (p[i]) ans.push_back(p[i]);             if (p[j]) ans.push_back(p[j]);             cout << ans.size() <<   n ;             for (auto x : ans) {               cout << x <<    ;             }             return 0;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, i, k;     cin >> n >> k;     if (k == 0) {       cout <<  0 0 ;       return 0;     }     if (n == k)       cout << 0;     else       cout << 1;     cout <<    ;     if (n % 2 == 0) {       long long temp = 3 * k;       if (temp <= n)         cout << 2 * k;       else {         cout << n - k;       }     } else {       long long temp = 3 * k;       if (temp <= n)         cout << 2 * k;       else {         cout << n - k;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a, b;   char seats[200001];   int main() {     scanf( %d%d%d , &n, &a, &b);     scanf( %s , seats);     int ans = 0;     char prev =  . ;     for (int i = 0; i < n; ++i) {       if (seats[i] ==  * ) {         prev =  . ;         continue;       }       if (prev ==  A  && b > 0) {         prev =  B ;         ++ans;         --b;       } else if (prev ==  B  && a > 0) {         prev =  A ;         ++ans;         --a;       } else if (prev ==  .  && a > b) {         prev =  A ;         ++ans;         --a;       } else if (prev ==  .  && b > 0) {         prev =  B ;         ++ans;         --b;       } else         prev =  . ;     }     printf( %d n , ans);     return 0;   }


#include <iostream>   #include <vector>   #include <algorithm>   #include <map>      using namespace std;      const int64_t INF = 1e15;      struct Dinic {    struct Edge {     int v;     int64_t f, c;     Edge(int _v = 0, int64_t _f = 0, int64_t _c = 0): v(_v), f(_f), c(_c) {};    };       int n;    vector<int> idx, dep, qu;    vector<vector<int>> adj;    vector<Edge> edges;       Dinic(int _n): n(_n), idx(_n), dep(_n), adj(_n), edges(0) {}       void addEdge(int u, int v, int64_t c) {     adj[u].push_back((int) edges.size());     edges.emplace_back(v, 0, c);     adj[v].push_back((int) edges.size());     edges.emplace_back(u, 0, 0);    }       bool levelGraph(int s, int t) {     qu.clear();     fill(dep.begin(), dep.end(), n + 1);     fill(idx.begin(), idx.end(), 0);        qu.push_back(s);     dep[s] = 0;     for (int qi = 0; qi < (int) qu.size() && qu.back() != t; ++qi) {      int u = qu[qi];      for (int i : adj[u]) {       auto &e = edges[i];       if (e.f < e.c && dep[u] + 1 < dep[e.v]) {        dep[e.v] = dep[u] + 1;        qu.push_back(e.v);       }      }     }     return dep[t] <= n;    }       int64_t sendFlow(int u, int t, int64_t f) {     if (u == t) return f;     for (int &i = idx[u]; i < (int) adj[u].size(); ++i) {      auto &e = edges[adj[u][i]];      if (e.f < e.c && dep[u] + 1 == dep[e.v]) {       int64_t g = sendFlow(e.v, t, min(f, e.c - e.f));       if (g > 0) {        edges[adj[u][i]].f += g;        edges[adj[u][i] ^ 1].f -= g;        return g;        }      }     }     return 0;    }       int64_t maxFlow(int s, int t) {     while (levelGraph(s, t)) {      while (sendFlow(s, t, INF));     }        int64_t flow = 0;     for (int i : adj[s]) {      flow += edges[i].f;     }     return flow;    }   };      int main() {    ios_base::sync_with_stdio(0);    cin.tie(0);       int n;    map<pair<int, int>, int> a;    auto get = [&](int x, int y) {     auto it = a.find(make_pair(x, y));     return (it == a.end() ? -1 : it->second);    };       cin >> n;    Dinic dinic(n * 2 + 2);    int s = n * 2, t = n * 2 + 1;    int64_t total = 0;    for (int i = 0; i < n; ++i) {     int x, y, w;     cin >> x >> y >> w;     dinic.addEdge(2 * i, 2 * i + 1, w);     total += w;        a[make_pair(x, y)] = i;    }       for (auto rit = a.begin(); rit != a.end(); ++rit) {     int x = rit->first.first, y = rit->first.second, i = rit->second, j;        if (x % 2 == 0 && y % 2 == 0) {      for (int y0 = y - 1; y0 <= y + 1; y0 += 2) {       if (~(j = get(x, y0))) dinic.addEdge(2 * i + 1, 2 * j, INF);      }      for (int x0 = x - 1; x0 <= x + 1; x0 += 2) {       if (~(j = get(x0, y))) dinic.addEdge(2 * j + 1, 2 * i, INF);      }     } else if (x % 2 == 0) {      for (int x0 = x - 1; x0 <= x + 1; x0 += 2) {       if (~(j = get(x0, y))) dinic.addEdge(2 * i + 1, 2 * j, INF);      }     } else if (y % 2 == 0) {      dinic.addEdge(s, 2 * i, INF);     } else {      dinic.addEdge(2 * i + 1, t, INF);     }    }       cout << total - dinic.maxFlow(s, t) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3000020, M = 120;   int L, R, p, ans, tot, cnt, g[N], f[N], P[M];   bool buc[N], vis[M];   void dfs(int k, int res) {     g[++cnt] = res;     for (int i = k; i <= tot; i++) {       if (1ll * P[i] * res <= 1ll * R) dfs(i, res * P[i]);     }   }   signed main() {     memset(f, 0x3f, sizeof(f));     cin >> L >> R >> p;     for (int i = 2; i <= p; i++) {       if (!vis[i]) P[++tot] = i;       for (int j = 1; j <= tot && i * P[j] <= p; j++) {         vis[i * P[j]] = 1;         if (i % P[j] == 0) break;       }     }     dfs(1, 1);     sort(g + 1, g + cnt + 1);     f[1] = 0;     for (int i = 2; i <= p; i++) {       int j = 1;       for (int k = 1; k <= cnt; k++) {         while (j <= cnt && 1ll * g[j] != 1ll * g[k] * i) j++;         if (j == cnt + 1) break;         f[j] = min(f[j], f[k] + 1);         if (f[j] + i <= p && g[j] >= L && !buc[j]) buc[j] = 1, ans++;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       cout << n << endl;     }   }


#include <bits/stdc++.h>   const long long oo = 1e9;   const long long mod = 95542721;   const long long MAX = 1e9;   const long long ARR = 1e5;   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     long long n, m;     set<long long> x, y;     cin >> n >> m;     for (long long i = (0); i < (long long)(m); ++i) {       int a, b;       cin >> a >> b;       x.insert(a), y.insert(b);       cout << (n - x.size()) * (n - y.size()) <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int a, b, x, y;       cin >> a >> b >> x >> y;       if (a == x || b == y) {         cout << abs(x - a) + abs(b - y) <<   n ;         goto v;       } else         cout << abs(a - x) + abs(b - y) + 2 <<   n ;     v:;     }   }


#include <bits/stdc++.h>   using namespace std;   char s[92], sl[10][10], str[10];   bool cmp(char* a, char* b) {     for (int i = 0; i < 10; i++)       if (a[i] != b[i]) return false;     return true;   }   int main() {     scanf( %s , &s);     for (int i = 0; i < 10; i++) scanf( %s , sl[i]);     for (int i = 0; i < 80; i += 10) {       for (int k = 0; k < 10; k++) str[k] = s[i + k];       for (int i = 0; i < 10; i++)         if (cmp(str, sl[i])) {           printf( %d , i);           break;         }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool F = true;   long long sum = 0;   void DFS(int v, int par, vector<vector<int>> &g, vector<long long> &s,            vector<long long> &a) {     if (s[v] == -1) {       if (g[v].size() == 0) return;       long long m = 2e9;       for (int u : g[v]) m = min(s[u], m);       a[v] = m - s[par];       if (a[v] < 0) {         F = false;       }       for (int u : g[v]) a[u] = s[u] - m;     }     sum += a[v];     for (int u : g[v]) DFS(u, v, g, s, a);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     vector<vector<int>> g(n);     vector<long long> s(n), a(n);     for (int i = 1; i < n; ++i) {       int p;       cin >> p;       g[p - 1].push_back(i);     }     for (int i = 0; i < n; ++i) {       cin >> s[i];     }     a[0] = s[0];     DFS(0, 0, g, s, a);     if (!F) {       cout << -1 <<   n ;     } else {       cout << sum <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   struct Data {     int64_t value;     int64_t supports;     int64_t supportedBy;   };   bool isTop(map<pair<int64_t, int64_t>, Data> const& cubes,              pair<int64_t, int64_t> const& pos) {     bool top = true;     for (int64_t i = -1; i <= 1; ++i) {       map<pair<int64_t, int64_t>, Data>::const_iterator f =           cubes.find(pair<int64_t, int64_t>{pos.first + i, pos.second + 1});       if (f != cubes.end()) {         if (f->second.supportedBy <= 1) {           top = false;           break;         }       }     }     return top;   }   int main(int, char**) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int64_t n;     cin >> n;     map<pair<int64_t, int64_t>, Data> cubes;     for (int64_t i = 0; i < n; ++i) {       int64_t x, y;       cin >> x >> y;       cubes.insert(make_pair(pair<int64_t, int64_t>{x, y}, Data{i, 0, 0}));     }     for (auto& p : cubes) {       Data& data = p.second;       pair<int64_t, int64_t> const& pos = p.first;       if (cubes.find(pair<int64_t, int64_t>{pos.first - 1, pos.second - 1}) !=           cubes.end())         data.supportedBy += 1;       if (cubes.find(pair<int64_t, int64_t>{pos.first, pos.second - 1}) !=           cubes.end())         data.supportedBy += 1;       if (cubes.find(pair<int64_t, int64_t>{pos.first + 1, pos.second - 1}) !=           cubes.end())         data.supportedBy += 1;       if (cubes.find(pair<int64_t, int64_t>{pos.first - 1, pos.second + 1}) !=           cubes.end())         data.supports += 1;       if (cubes.find(pair<int64_t, int64_t>{pos.first, pos.second + 1}) !=           cubes.end())         data.supports += 1;       if (cubes.find(pair<int64_t, int64_t>{pos.first + 1, pos.second + 1}) !=           cubes.end())         data.supports += 1;     }     set<pair<int64_t, pair<int64_t, int64_t> > > tops;     for (auto const& p : cubes) {       int64_t value = p.second.value;       pair<int64_t, int64_t> const& pos = p.first;       if (isTop(cubes, pos))         tops.insert(pair<int64_t, pair<int64_t, int64_t> >{value, pos});     }     int64_t result = 0;     bool smallest = false;     while (!tops.empty()) {       set<pair<int64_t, pair<int64_t, int64_t> > >::iterator used;       if (smallest)         used = tops.begin();       else         used = --tops.end();       smallest = !smallest;       result *= n;       result += used->first;       result %= 1000000009l;       pair<int64_t, int64_t> pos = used->second;       cubes.erase(pos);       tops.erase(used);       set<pair<int64_t, pair<int64_t, int64_t> > > update;       for (int64_t i = -1; i <= 1; ++i) {         {           pair<int64_t, int64_t> pm1{pos.first + i, pos.second - 1};           map<pair<int64_t, int64_t>, Data>::iterator fm1 = cubes.find(pm1);           if (fm1 != cubes.end()) {             fm1->second.supports -= 1;             update.insert(                 pair<int64_t, pair<int64_t, int64_t> >{fm1->second.value, pm1});           }         }         {           pair<int64_t, int64_t> pp1{pos.first + i, pos.second + 1};           map<pair<int64_t, int64_t>, Data>::iterator fp1 = cubes.find(pp1);           if (fp1 != cubes.end()) {             fp1->second.supportedBy -= 1;             update.insert(                 pair<int64_t, pair<int64_t, int64_t> >{fp1->second.value, pp1});             if (fp1->second.supportedBy <= 1) {               for (int64_t j = -1; j <= 1; ++j) {                 pair<int64_t, int64_t> sibP{pp1.first + j, pos.second};                 map<pair<int64_t, int64_t>, Data>::iterator sibI =                     cubes.find(sibP);                 if (sibI != cubes.end()) {                   tops.erase(pair<int64_t, pair<int64_t, int64_t> >{                       sibI->second.value, sibP});                 }               }             }           }         }       }       for (auto const& updatePos : update) {         if (isTop(cubes, updatePos.second)) tops.insert(updatePos);       }     }     cout << result << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void remax(T& A, T B) {     if (A < B) A = B;   }   template <class T>   inline void remin(T& A, T B) {     if (A > B) A = B;   }   string ToString(long long num) {     string ret;     do {       ret += ((num % 10) +  0 );       num /= 10;     } while (num);     reverse(ret.begin(), ret.end());     return ret;   }   long long ToNumber(string s) {     long long r = 0, p = 1;     for (int i = s.size() - 1; i >= 0; --i) r += (s[i] -  0 ) * p, p *= 10;     return r;   }   long long Gcd(long long a, long long b) {     while (a %= b ^= a ^= b ^= a)       ;     return b;   }   long long Power(long long base, long long power) {     long long ret = 1;     while (power) {       if (power & 1) ret *= base;       power >>= 1;       base *= base;     }     return ret;   }   long long PowerMod(long long base, long long power, long long mod) {     if (!power) return 1;     if (power & 1) return (base * PowerMod(base, power - 1, mod)) % mod;     return PowerMod((base * base) % mod, power >> 1, mod);   }   int Log(long long num, long long base) {     int ret = 0;     while (num) {       ++ret;       num /= base;     }     return ret;   }   int Count(long long mask) {     int ret = 0;     while (mask) {       if (mask & 1) ++ret;       mask >>= 1;     }     return ret;   }   inline void run() {     int n, k, ans, sum;     scanf( %d%d , &n, &k);     ans = n, sum = (n << 1);     while (true) {       if (sum >= k) break;       if (!n) break;       --ans, ++sum, --n;     }     printf( %d n , ans);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr), cout.tie(nullptr);     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1005;   map<pair<int, int>, int> mapa;   int main() {     int n, h, m;     scanf( %d , &n);     int c = 0;     for (int i = 0; i < n; i++) {       scanf( %d%d , &h, &m);       int x = ++mapa[make_pair(h, m)];       if (x > c) c = x;     }     printf( %d n , c);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1001000;   int n;   void add(long long* a, int x, long long y) {     for (; x <= n; x += x & -x) a[x] += y;   }   long long gsm(long long* a, int x) {     long long ret = 0;     for (; x; x &= x - 1) ret += a[x];     return ret;   }   long long sum0[N], sum1[N];   void mdf(int x, int y) {     add(sum0, x, y);     add(sum1, x, (long long)(1 - x) * y);   }   void modify(int l, int r, int x) {     mdf(l, x);     if (r < n) mdf(r + 1, -x);   }   long long query(int x) { return gsm(sum0, x) * x + gsm(sum1, x); }   vector<int> vec[N];   int q[N], l[N], r[N], a[N], m;   long long ans[N];   void solve() {     for (int i = 1; i <= m; ++i) vec[l[i]].push_back(i);     q[0] = n + 1;     for (int i = n, j = 0; i; --i) {       for (; j && a[q[j]] < a[i]; --j)         ;       modify(i, q[j] - 1, 1);       q[++j] = i;       for (int t : vec[i]) ans[t] += query(r[t]);     }     for (int i = 1; i <= n; ++i) vec[i].clear(), sum0[i] = sum1[i] = 0;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i <= m; ++i) cin >> l[i];     for (int i = 1; i <= m; ++i) cin >> r[i];     solve();     for (int i = 1; i <= m; ++i)       l[i] = n + 1 - l[i], r[i] = n + 1 - r[i], swap(l[i], r[i]);     reverse(a + 1, a + n + 1);     solve();     for (int i = 1; i <= m; ++i)       ans[i] -= r[i] - l[i] + 1, cout << ans[i] <<    n [i == m];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const MAXN = 5e5 + 10;   int n, a[MAXN], ans;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i < n; i++) {       if (a[i] != a[i + 1]) {         int pt = i + 1, tam = 1;         while (a[pt] != a[pt + 1] && pt != n) pt++, tam++;         if (a[i] == a[pt])           for (int j = i; j <= pt; j++) a[j] = a[i];         else {           tam--;           for (int j = i; j <= i + tam / 2; j++) a[j] = a[i];           for (int j = i + tam / 2 + 1; j <= pt; j++) a[j] = a[pt];         }         ans = max(ans, tam / 2);       }     }     printf( %d n , ans);     for (int i = 1; i <= n; i++) printf( %d  , a[i]);     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     cin.sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long n, m;     cin >> n >> m;     vector<long long> v(n);     for (long long i = 0; i < n; i++) cin >> v[i];     vector<long long> dp(n);     dp[0] = v[0];     for (long long i = 1; i < dp.size(); i++) {       dp[i] = v[i] + dp[i - 1];     }     for (long long i = 0; i < n; i++) {       vector<long long> temp;       long long ans = 0;       for (long long j = 0; j < i; j++) {         temp.push_back(v[j]);       }       if (temp.size() > 0) {         sort(temp.rbegin(), temp.rend());       }       long long timereq = v[i];       long long timeleft = m;       long long in = 0;       if (i > 0) {         timeleft = m - dp[i - 1];       }       while (true) {         if (timeleft >= timereq) break;         timeleft = timeleft + temp[in];         in++;         ans++;       }       cout << ans <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m, i, j, k, use[200010], culoare[200010], v[200010], x, y, a;   vector<int> v2[200010];   vector<pair<int, int> > G[200010];   void DF(int nod) {     use[nod] = 1;     for (auto it : G[nod]) {       if (!use[it.first]) {         if (it.second == 1) {           culoare[it.first] = culoare[nod];         } else {           culoare[it.first] = 1 - culoare[nod];         }         DF(it.first);       } else {         if (it.second == 1) {           if (culoare[it.first] != culoare[nod]) {             cout <<  NO ;             exit(0);           }         } else {           if (culoare[it.first] != 1 - culoare[nod]) {             cout <<  NO ;             exit(0);           }         }       }     }   }   int main() {     cin >> n >> m;     for (i = 1; i <= n; i++) cin >> v[i];     for (i = 1; i <= m; i++) {       cin >> x;       for (j = 1; j <= x; j++) {         cin >> a;         v2[a].push_back(i);       }     }     for (i = 1; i <= n; i++) {       G[v2[i][0]].push_back({v2[i][1], v[i]});       G[v2[i][1]].push_back({v2[i][0], v[i]});     }     for (i = 1; i <= m; i++) {       if (!use[i]) {         culoare[i] = 1;         DF(i);       }     }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Tans {     long a;     long b;   };   struct mstr {     long num;     long val;   };   bool operator<(mstr a, mstr b) { return a.val < b.val; }   bool operator>(mstr a, mstr b) { return a.val > b.val; }   bool operator==(mstr a, mstr b) { return a.val == b.val; }   int main() {     long n, s;     cin >> n >> s;     vector<mstr> cards(n);     vector<Tans> ress;     priority_queue<mstr> q;     ress.reserve(n);     for (long i = 0; i < n; i++) {       cin >> cards[i].val;       cards[i].num = i + 1;       if (cards[i].val) q.push(cards[i]);     }     bool f = true;     vector<mstr> temp;     while (q.size() != 0 && f) {       temp.resize(0);       temp.reserve(q.size());       mstr now = q.top();       q.pop();       if (q.size() < now.val)         f = false;       else {         mstr tt;         Tans ttt;         ttt.a = now.num;         while (now.val != 0) {           tt = q.top();           q.pop();           now.val--;           tt.val--;           ttt.b = tt.num;           temp.push_back(tt);           ress.push_back(ttt);         }         for (long j = 0; j < temp.size(); j++)           if (temp[j].val > 0) q.push(temp[j]);       }     }     if (f == false)       cout <<  No ;     else {       cout <<  Yes n  << ress.size() <<   n ;       for (long i = 0; i < ress.size(); i++)         cout << ress[i].a <<     << ress[i].b <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, i, sum = 0;     cin >> n;     long long int a[n];     for (i = 0; i < n; i++) {       cin >> a[i];       sum = sum + a[i];     }     sort(a, a + n);     i = 0;     while (1) {       if (sum % 2 == 0) {         cout << sum;         break;       } else {         if (a[i] % 2 == 1) {           sum = sum - a[i];         } else {           i++;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, *animals, i, j, temp;     bool turn = 0;     cin >> n;     animals = new int[n];     for (i = 0; i < n; i++) cin >> animals[i];     vector<pair<int, int> > segmant;     pair<int, int> seg;     for (i = 0; i < (n - 1); i++) {       if (animals[i] > animals[i + 1]) {         turn = 1;         seg.first = (i + 1);         temp = animals[i];         animals[i] = animals[i + 1];         animals[i + 1] = temp;         i += 2;         for (j = i; j < n - 1; j++) {           if (animals[j] > animals[j + 1]) {             temp = animals[j];             animals[j] = animals[j + 1];             animals[j + 1] = temp;             j++;             continue;           } else {             break;           }         }         seg.second = j;       }       if (turn == true) {         segmant.push_back(seg);         i = -1;         turn = 0;       }     }     for (i = 0; i < segmant.size(); i++) {       cout << segmant[i].first <<     << segmant[i].second << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long LLINF = 1e18 + 7;   const long long INF = 1e9 + 7;   const long long EPS = 1e-9 - 7;   const long long MAX = 1e2 + 7;   const long long MOD = 1e9 + 7;   int n, d, dp[MAX];   string s;   bool can[MAX], flag = false;   int main() {     memset(dp, MAX, sizeof dp);     cin >> n >> d >> s;     for (int i = 0; i < n; i++) {       if (s[i] ==  1 ) {         can[i + 1] = true;       }     }     for (int i = n - 1; i >= 1; i--) {       if (n - i <= d && can[i]) {         flag = true;         dp[i] = 1;       }     }     if (!flag) {       cout << -1 << endl;       return 0;     }     for (int i = n - 1; i >= 1; i--) {       for (int j = i - 1; j >= 1; j--) {         if (i - j <= d && can[j] && can[i]) {           dp[j] = min(dp[j], dp[i] + 1);         }       }     }     if (dp[1] >= n) {       cout << -1 << endl;       return 0;     }     cout << dp[1] << endl;     return 0;   }


/*       Mbak Sana Dong       Mbak Chaeyoung Dong       Mbak Eunha Dong       Mbak Seulgi Dong       Mbak Wendy Dong       Stream https://www.youtube.com/watch?v=LmBYPXGqtss   */   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization ( unroll-loops,O3 )   #include<bits/stdc++.h>   #define ll long long   using namespace std;   int main()   {       int n,m,i,j,k,x,y,ans,curr,temp,q;       int tc;       cin >> tc;       while(tc--) {           string s;           cin >> s;           n = s.length();           s =     + s;           vector<int> cnt(30, 0), vis(30, 0);           for(i=1;i<=n;i++) {               cnt[s[i] -  a ]++;           }              stack<char> st;              for(i=1;i<=n;i++) {               curr = s[i] -  a ;               if(vis[curr]) {                   cnt[curr]--;                   continue;               }                  while(!st.empty() && cnt[st.top() -  a ] > 0 && st.top() < s[i]) {                   vis[st.top() -  a ] = 0;                   st.pop();               }                  st.push(s[i]);               cnt[curr]--;               vis[curr] = 1;           }              string eunha =   ;           while(!st.empty()) {               eunha += st.top();               st.pop();           }              reverse(eunha.begin(), eunha.end());           cout << eunha << endl;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int min(int a, int b) { return a > b ? b : a; }   int main() {     int n, m;     cin >> n >> m;     cout << min(n, m) + 1 << endl;     for (int i = 0; i <= min(n, m); i++)       cout << i <<     << min(n, m) - i << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const int inf = 0x3f3f3f3f;   const long long INF = 0x3f3f3f3f3f3f3f3f;   char buf[1 << 21], *p1 = buf, *p2 = buf;   inline int gc() {     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline int read() {     int ret = 0, f = 0;     char c = gc();     while (!isdigit(c)) {       if (c ==  - ) f = 1;       c = gc();     }     while (isdigit(c)) {       ret = ret * 10 + c - 48;       c = gc();     }     if (f) return -ret;     return ret;   }   int sign(double x) {     if (x > 1e8)       return 1;     else if (x < -1e8)       return -1;     else       return 0;   }   const int maxn = 1e6 + 10;   int a[maxn];   pair<double, int> st[maxn];   double pre[maxn];   int precnt[maxn];   int top;   int erfen(int l, int r, double val) {     while (l + 1 < r) {       int mid = l + r >> 1;       if ((pre[top] - pre[mid - 1] + val) * 1.0 /               (precnt[top] - precnt[mid - 1] + 1) <=           st[mid].first)         r = mid;       else         l = mid;     }     return r;   }   int main() {     int n;     scanf( %d , &n);     for (int i = (1); i <= (n); i++) {       scanf( %d , &a[i]);     }     st[++top] = make_pair(a[1] * 1.0, 1);     pre[top] = a[1];     precnt[top] = 1;     for (int i = (2); i <= (n); i++) {       if (a[i] * 1.0 == st[top].first) {         st[top].second++;         pre[top] += a[i];         precnt[top]++;       } else if (a[i] * 1.0 > st[top].first) {         st[++top] = make_pair(a[i] * 1.0, 1);         pre[top] = pre[top - 1] + a[i];         precnt[top] = precnt[top - 1] + 1;       } else {         int id = erfen(0, top + 1, a[i]);         int cnt = (precnt[top] - precnt[id - 1] + 1);         double tmp = pre[top] - pre[id - 1] + a[i];         double evenly = (pre[top] - pre[id - 1] + a[i]) * 1.0 /                         (precnt[top] - precnt[id - 1] + 1);         top = id;         st[top].first = evenly;         st[top].second = cnt;         pre[top] = pre[top - 1] + tmp;         precnt[top] = precnt[top - 1] + cnt;       }     }     for (int i = (1); i <= (top); i++) {       for (int j = (1); j <= (st[i].second); j++) {         printf( %.9f n , st[i].first);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a, b;   int x[205], y[205], c[205], siz[75], ans[75];   int info[75], Prev[205 << 1], to[205 << 1], cst[205 << 1], cnt_e;   void Node(int u, int v, int ct) {     Prev[++cnt_e] = info[u], info[u] = cnt_e, to[cnt_e] = v, cst[cnt_e] = ct;   }   int F[75], bl[75], cnt;   int Find(int now) {     return (!F[now] || F[now] == now) ? now : F[now] = Find(F[now]);   }   int dp[1 << 18][75];   int main() {     scanf( %d%d%d%d , &n, &m, &a, &b);     for (int i = 1; i <= n; i++) siz[i] = 1;     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &x[i], &y[i], &c[i]);       if (c[i] == a)         if (Find(x[i]) != Find(y[i])) {           siz[Find(y[i])] += siz[Find(x[i])];           F[Find(x[i])] = Find(y[i]);         }       Node(x[i], y[i], c[i]), Node(y[i], x[i], c[i]);     }     for (int i = 1; i <= n; i++)       if (siz[i] > 3 && Find(i) == i)         bl[i] = cnt++;       else if (Find(i) == i)         bl[i] = -1;     for (int i = 1; i <= n; i++)       if (Find(i) != i) bl[i] = bl[Find(i)];     memset(dp, 0x3f, sizeof dp);     memset(ans, 0x3f, sizeof ans);     dp[bl[1] >= 0 ? 1 << bl[1] : 0][1] = 0;     queue<int> q;     for (int i = 0; i < (1 << cnt); i++) {       for (int j = 1; j <= n; j++)         if (dp[i][j] < 0x3f3f3f3f) q.push(j);       for (int now; !q.empty();) {         now = q.front(), q.pop();         for (int j = info[now]; j; j = Prev[j])           if (cst[j] == a ||               (cst[j] == b && bl[to[j]] == -1 && Find(now) != Find(to[j]))) {             if (dp[i][to[j]] > dp[i][now] + cst[j]) {               dp[i][to[j]] = dp[i][now] + cst[j];               q.push(to[j]);             }           } else if (Find(now) != Find(to[j]) && !(i >> bl[to[j]] & 1))             dp[i | (1 << bl[to[j]])][to[j]] =                 min(dp[i | (1 << bl[to[j]])][to[j]], dp[i][now] + cst[j]);       }       for (int j = 1; j <= n; j++)         if (dp[i][j] < 0x3f3f3f3f) ans[j] = min(ans[j], dp[i][j]);     }     for (int i = 1; i <= n; i++) printf( %d%c , ans[i], i == n ?   n  :    );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     vector<pair<int, int>> v(n);     for (auto &x : v) cin >> x.first >> x.second;     if (is_sorted(v.rbegin(), v.rend())) {       bool ok = true;       for (auto x : v)         if (x.first != x.second) ok = false;       if (ok) {         cout <<  maybe n ;         return 0;       }     }     for (auto x : v)       if (x.first != x.second) {         cout <<  rated n ;         return 0;       }     cout <<  unrated n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int inf = (1 << 29) - 1;   int n, m, S, T, ans;   int a[20000], b[20];   struct edge {     int b, len;     edge *nxt, *op;   } e[100000], *le(e);   edge *head[20000];   void add(int u, int v, int w) {     le->b = v, le->len = w, le->nxt = head[u], le->op = le + 1, head[u] = le++;     le->b = u, le->len = 0, le->nxt = head[v], le->op = le - 1, head[v] = le++;   }   edge *cur[20000], *pre[20000];   int low[20000], dis[20000], gap[20000];   void init() {     int g, v, w, k, p, q;     scanf( %d%d%d , &n, &m, &g);     S = 0, T = n + m + 1;     for (int i = 1; i <= (n); ++i) scanf( %d , &a[i]);     for (int i = 1; i <= (n); ++i) {       scanf( %d , &v);       if (a[i])         add(i, T, v);       else         add(S, i, v);     }     for (int i = 1; i <= (m); ++i) {       scanf( %d%d%d , &p, &w, &k);       for (int j = 1; j <= (k); ++j) scanf( %d , &b[j]);       scanf( %d , &q);       ans += w;       if (q) w += g;       if (p) {         for (int j = 1; j <= (k); ++j) add(b[j], n + i, inf);         add(n + i, T, w);       } else {         add(S, n + i, w);         for (int j = 1; j <= (k); ++j) add(n + i, b[j], inf);       }     }   }   int SAP() {     int flow(0);     low[S] = inf, gap[0] = T + 1;     for (int i = (S); i <= (T); ++i) dis[i] = 0, cur[i] = head[i];     edge *i;     int u(S), v;     while (dis[S] < T + 5) {       for (i = cur[u]; i; i = i->nxt)         if (i->len && dis[v = i->b] + 1 == dis[u]) break;       if (i) {         cur[u] = i;         pre[v] = i;         low[v] = min(low[u], i->len);         if ((u = v) == T) {           for (; u != S; u = pre[u]->op->b) {             pre[u]->len -= low[T];             pre[u]->op->len += low[T];           }           flow += low[T];         }       } else {         cur[u] = head[u];         if (--gap[dis[u]] == 0) break;         dis[u] = T + 5;         for (i = cur[u]; i; i = i->nxt)           if (i->len && dis[i->b] + 1 < dis[u]) dis[u] = dis[i->b] + 1;         ++gap[dis[u]];         if (u != S) u = pre[u]->op->b;       }     }     return flow;   }   int main() {     init();     ans -= SAP();     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dist[2005][2005];   char f[2005][2005];   int n, m, r, c, x, y;   int main() {     scanf( %d%d%d%d%d%d , &n, &m, &r, &c, &x, &y);     x = min(x, 10000000);     y = min(y, 10000000);     r--;     c--;     for (int i = 0; i < n; i++) scanf( %s , &f[i]);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) dist[i][j] = 1000000000;     dist[r][c] = 0;     deque<pair<int, pair<int, int> > > que;     que.push_back(make_pair(0, make_pair(r, c)));     while (!que.empty()) {       pair<int, pair<int, int> > p = que.front();       que.pop_front();       if (p.first != dist[p.second.first][p.second.second]) continue;       int X = p.second.first, Y = p.second.second;       int dx[4] = {0, 1, 0, -1};       int dy[4] = {1, 0, -1, 0};       for (int k = 0; k < 4; k++) {         int nx = X + dx[k], ny = Y + dy[k];         if (!(0 <= nx && nx < n && 0 <= ny && ny < m)) continue;         if (f[nx][ny] ==  * ) continue;         int add = (k == 2);         if (dist[nx][ny] > p.first + add) {           dist[nx][ny] = p.first + add;           if (add == 0)             que.push_front(make_pair(p.first + add, make_pair(nx, ny)));           else             que.push_back(make_pair(p.first + add, make_pair(nx, ny)));         }       }     }     int ans = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         int mnx = dist[i][j];         int mny = j + dist[i][j] - c;         if (mnx <= x && mny <= y) ans++;       }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool chkmin(T &a, const T &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T>   inline bool chkmax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   const int oo = 0x3f3f3f3f;   const int maxn = 500100;   int n;   vector<int> chd[maxn + 5];   int fa[maxn + 5];   int dep[maxn + 5];   void dfs(int first) {     for (auto second : chd[first]) dep[second] = dep[first] + 1, dfs(second);   }   struct node {     node *c[2], *p;     int label;     long long sum;     int val;     int sz;     node() : p(NULL), label(0), sum(0), val(0), sz(1) { memset(c, 0, sizeof c); }     void update() {       sum = val;       sz = 1;       for (int i = (0), i_end_ = (2); i < i_end_; ++i)         if (c[i]) sum += c[i]->sum, sz += c[i]->sz;     }     void flag_label(int _label) {       label += _label;       val += _label;       sum += (long long)sz * _label;     }     void push_down() {       if (label) {         for (int i = (0), i_end_ = (2); i < i_end_; ++i)           if (c[i]) c[i]->flag_label(label);         label = 0;       }     }     int get_pos() {       if (!this || !p) return 2;       for (int i = (0), i_end_ = (2); i < i_end_; ++i)         if (p->c[i] == this) return i;       return 2;     }     bool is_root() { return get_pos() >= 2; }     void setc(node *u, const int &v) {       if (this && v < 2) c[v] = u;       if (u) u->p = this;     }     void rotate() {       node *_p = this->p;       bool mark = get_pos();       _p->p->setc(this, _p->get_pos());       _p->setc(c[mark ^ 1], mark);       setc(_p, mark ^ 1);       _p->update();     }     void relax() {       static node *tmp[maxn + 5];       int top = 0;       node *u = this;       while (!u->is_root()) tmp[top++] = u, u = u->p;       u->push_down();       while (top) tmp[--top]->push_down();     }     void splay() {       relax();       for (; !is_root(); rotate())         if (!p->is_root())           ((p->p->c[0] == p) == (p->c[0] == this) ? p : this)->rotate();       update();     }     node *access() {       node *u = this, *v = NULL;       for (; u; v = u, u = u->p) u->splay(), u->setc(v, 1), u->update();       splay();       return v;     }   };   node nd[maxn + 5];   vector<int> all[maxn + 5];   long long ans[maxn + 5];   int main() {     scanf( %d , &n);     for (int i = (0), i_end_ = (n); i < i_end_; ++i) scanf( %d , fa + i), --fa[i];     int rt = -1;     for (int i = (0), i_end_ = (n); i < i_end_; ++i)       if (!~fa[i])         rt = i;       else         chd[fa[i]].push_back(i);     dep[rt] = 0;     dfs(rt);     for (int i = (0), i_end_ = (n); i < i_end_; ++i) {       nd[i].val = 0;       if (~fa[i])         nd[i].p = nd + fa[i];       else         nd[i].p = NULL;     }     for (int i = (0), i_end_ = (n); i < i_end_; ++i) all[dep[i]].push_back(i);     for (int i = (0), i_end_ = (n); i < i_end_; ++i) {       for (auto first : all[i]) {         node *u = nd + first;         u->access();         u->flag_label(1);       }       for (auto first : all[i]) {         node *u = nd + first;         u->access();         ans[first] = u->sum - dep[first] - 1;       }     }     for (int i = (0), i_end_ = (n); i < i_end_; ++i)       printf(            %             ll             d  ,           ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long judge(long long mid) {     long long b;     long long cnt = 0;     for (b = 2;; b++) {       cnt += mid / b / b / b;       if (mid / b / b / b == 0) break;     }     return cnt;   }   int main() {     long long m;     cin >> m;     long long r = 1e16, l = 0;     while (l < r - 1) {       long long mid = (l + r) / 2;       if (judge(mid) >= m)         r = mid;       else         l = mid;     }     if (judge(l) == m)       cout << l << endl;     else if (judge(r) == m)       cout << r << endl;     else       cout <<  -1  << endl;     return 0;   }


#include <bits/stdc++.h>   struct task {     task() : pc(-1), indegree(0), outgoing() {}     int pc;     int indegree;     std::vector<int> outgoing;   };   int solve(int pc, std::vector<task> tasks) {     std::queue<int> todo[3];     for (__decltype((tasks).begin()) t = (tasks).begin(), t_end = (tasks).end();          t != t_end; ++t)       if (t->indegree == 0) todo[t->pc].push(t - tasks.begin());     int time = 0;     for (std::size_t solved = 0; solved < tasks.size(); pc = (pc + 1) % 3) {       while (!todo[pc].empty()) {         int t = todo[pc].front();         for (__decltype((tasks[t].outgoing).begin())                  n = (tasks[t].outgoing).begin(),                  n_end = (tasks[t].outgoing).end();              n != n_end; ++n) {           if (--tasks[*n].indegree == 0) todo[tasks[*n].pc].push(*n);         }         todo[pc].pop();         ++time;         ++solved;       }       ++time;     }     return time - 1;   }   int main() {     int n;     scanf( %d , &n);     std::vector<task> tasks(n);     for (int i = 0; i < n; ++i) {       scanf( %d , &tasks[i].pc);       --tasks[i].pc;     }     for (int i = 0; i < n; ++i) {       int k;       scanf( %d , &k);       while (k--) {         int a;         scanf( %d , &a);         --a;         tasks[a].outgoing.push_back(i);         ++tasks[i].indegree;       }     }     printf( %d n ,            std::min(std::min(solve(0, tasks), solve(1, tasks)), solve(2, tasks)));   }


#include <bits/stdc++.h>   using namespace std;   int N, K;   int h[100005];   bool isok[100005];   int check(int L) {     deque<int> A, B;     int ret = 0;     for (int i = 1; i <= N; ++i) {       while (A.size() && A.front() + L <= i) A.pop_front();       while (B.size() && B.front() + L <= i) B.pop_front();       while (A.size() && h[A.back()] >= h[i]) A.pop_back();       while (B.size() && h[B.back()] <= h[i]) B.pop_back();       A.push_back(i);       B.push_back(i);       if (i >= L) ret += (isok[i - L + 1] = (h[B.front()] - h[A.front()] <= K));     }     return ret;   }   int main() {     while (scanf( %d %d , &N, &K) == 2) {       for (int i = 1; i <= N; ++i) scanf( %d , h + i);       int lo = 1, hi = N + 1, mid;       while (lo + 1 < hi) {         mid = lo + hi >> 1;         if (check(mid))           lo = mid;         else           hi = mid;       }       int s = check(lo);       printf( %d %d n , lo, s);       for (int i = 1; i + lo - 1 <= N; ++i)         if (isok[i]) printf( %d %d n , i, i + lo - 1);     }   }


#include <bits/stdc++.h>   using namespace std;   const int size = 110000, mod = 1000000007, inf = 0x3f3f3f3f;   const double pi = acos(-1.0);   int month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   int nex[2][4] = {0, 1, 0, -1, 1, 0, -1, 0};   long long cal(long long a, int n) {     long long s = 1 % mod;     while (n) {       if (n & 1) s = (s * a) % mod;       a = (a * a) % mod;       n /= 2;     }     return s;   }   int n, ar[size];   long long ans;   vector<int> fac, fac2;   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> ar[i];     sort(ar, ar + n);     for (int i = ar[n - 1]; i >= 1; i--) {       long long t = 1;       fac.clear();       for (int j = 1; j * j <= i; j++)         if (i % j == 0) {           fac.push_back(j);           if (j * j != i) fac.push_back(i / j);         }       sort(fac.begin(), fac.end());       int pre = 0;       for (int j = 1; j < fac.size(); j++) {         int num = lower_bound(ar, ar + n, fac[j]) - ar;         t = t * cal(j, num - pre) % mod;         pre = num;       }       t = t * (cal(fac.size(), n - pre) - cal(fac.size() - 1, n - pre)) % mod;       ans = (ans + t) % mod;     }     cout << (ans + mod) % mod << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n, x;     cin >> n >> x;     int temp, cnt = 0;     for (int i = 0; i < n; i++) {       cin >> temp;       cnt += temp;     }     if ((cnt + n - 1) == x)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void cmin(T &a, T b) {     ((a > b) && (a = b));   }   int cmax(int &a, int b) { return a < b ? a = b, 1 : 0; }   char IO;   template <class T = int>   T rd() {     T s = 0;     int f = 0;     while (!isdigit(IO = getchar())) f |= IO ==  - ;     do s = (s << 1) + (s << 3) + (IO ^  0 );     while (isdigit(IO = getchar()));     return f ? -s : s;   }   const int N = 1e6 + 10, INF = 1e9 + 10;   int n, m, k, T;   int s[N], t[N];   int F[1 << 20], G[1 << 20];   int p[N], a[N], b[N];   int main() {     n = rd(), m = rd(), k = rd();     for (int i = 0, iend = k - 1; i <= iend; ++i) scanf( %1d , s + i);     for (int i = 0, iend = k - 1; i <= iend; ++i) scanf( %1d , t + i);     for (int i = 0, iend = k - 1; i <= iend; ++i) p[i] = i;     memset(F, 63, sizeof F), memset(G, -63, sizeof G);     int S = 0;     for (int i = 0, iend = k - 1; i <= iend; ++i) S |= s[i] << i;     F[S] = 0;     for (int i = 1, iend = n; i <= iend; ++i) {       int x = rd() - 1, y = rd() - 1;       for (int j = 0, jend = k - 1; j <= jend; ++j)         if (p[j] == x) {           x = j;           break;         }       for (int j = 0, jend = k - 1; j <= jend; ++j)         if (p[j] == y) {           y = j;           break;         }       swap(p[x], p[y]);       int S = 0, T = 0;       for (int j = 0, jend = k - 1; j <= jend; ++j) {         S |= s[p[j]] << j;         T |= t[p[j]] << j;       }       cmin(F[S], i), G[T] = i;     }     int ans = 0, l = 1, r = n, c1 = 0, c2 = 0;     for (int i = 0, iend = k - 1; i <= iend; ++i) c1 += s[i], c2 += t[i];     for (int S = (1 << k) - 1, Send = 0; S >= Send; --S) {       if (G[S] - F[S] >= m)         if (cmax(ans, k - (c1 + c2 - 2 * __builtin_popcount(S))))           l = F[S] + 1, r = G[S];       for (int i = 0, iend = k - 1; i <= iend; ++i)         if (S & (1 << i)) {           cmin(F[S ^ (1 << i)], F[S]);           cmax(G[S ^ (1 << i)], G[S]);         }     }     printf( %d n%d %d n , ans, l, r);   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> graph[100005];   vector<pair<long long, long long> > graph_p[100005];   vector<pair<long long, long long> > op;   vector<long long> vis(100005, 0);   long long power(long long x, long long y) {     long long res = 1;     x = x % 1000000009;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = ((res % 1000000009) * (x % 1000000009)) % 1000000009;       y = y >> 1;       x = ((x % 1000000009) * (x % 1000000009)) % 1000000009;     }     return res;   }   void init_graph(long long n, long long m) {     cin >> n >> m;     for (long long i = 1; i <= m; i++) {       long long a, b;       cin >> a >> b;       graph[a].push_back(b);       graph[b].push_back(a);     }   }   void sieve(long long n) {     bool prime[n + 1];     memset(prime, true, sizeof(prime));     for (long long p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (long long i = p * p; i <= n; i += p) prime[i] = false;       }     }   }   long long n, h, l[2000005], r[2000005], ans;   long long sum[2000005], de[2000005];   void we_have_choices() {     cin >> n >> h;     for (long long i = 1; i <= n; i++) {       cin >> l[i] >> r[i];       sum[i] = sum[i - 1] + r[i] - l[i];       if (i == 1)         de[i] = 0;       else         de[i] = de[i - 1] + l[i] - r[i - 1];     }     for (long long i = 1; i <= n; i++) {       long long pos = lower_bound(de + i, de + n + 1, de[i] + h) - de;       ans = max(ans, sum[pos - 1] - sum[i - 1] + h);     }     cout << ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr);     ;     long long t = 1;     while (t--) we_have_choices();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int n, k, a[maxn];   vector<int> ans;   long long sum;   int main() {     ios::sync_with_stdio(false);     cin >> n >> k;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       sum += a[i];     }     int partsum = sum / k;     int tmp = 0, lastpos = 0;     bool flag = false;     for (int i = 1; i <= n; ++i) {       tmp += a[i];       if (tmp == partsum) {         ans.push_back(i - lastpos);         lastpos = i;         tmp = 0;       }       if (tmp >= partsum) {         flag = true;         break;       }     }     if (flag)       cout <<  No  << endl;     else if (ans.size() * partsum != sum)       cout <<  No  << endl;     else {       cout <<  Yes  << endl;       for (auto s : ans) cout << s <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   const int maxm = 300005;   struct segtree {     int tree[30 * maxm], L[30 * maxm], R[30 * maxm];     int sz = 0;     int root[maxm];     int update(int pre, int l, int r, int pos, int val) {       if (l > r || pos < l || pos > r) return pre;       int no = ++sz;       tree[no] = tree[pre];       L[no] = L[pre];       R[no] = R[pre];       if (l == r && l == pos) {         tree[no] += val;         R[no] = L[no] = 0;         return no;       }       int mid = (l + r) >> 1;       L[no] = update(L[pre], l, mid, pos, val);       R[no] = update(R[pre], mid + 1, r, pos, val);       tree[no] = tree[L[no]] + tree[R[no]];       return no;     }     int sum(int no, int l, int r, int pos) {       if (l == r) return 0;       int mid = (l + r) >> 1;       if (pos <= mid) return sum(L[no], l, mid, pos);       return tree[L[no]] + sum(R[no], mid + 1, r, pos);     }     int get(int no, int l, int r, int pos) {       if (l == r) return tree[no];       int mid = (l + r) >> 1;       if (pos <= mid) return get(L[no], l, mid, pos);       return get(R[no], mid + 1, r, pos);     }   } a, b;   map<string, int> mapa;   const int inf = 1e9 + 10;   int main() {     int q;     scanf( %d , &q);     int idx = 1;     for (int i = 1; i <= q; i++) {       char op[15];       scanf( %s , op);       a.root[i] = a.root[i - 1];       b.root[i] = b.root[i - 1];       if (op[0] ==  s ) {         char s[20];         int val;         scanf( %s %d , s, &val);         string t = s;         if (mapa.count(t)) {           int x = a.get(a.root[i], 1, maxn, mapa[t]);           a.root[i] = a.update(a.root[i], 1, maxn, mapa[t], val - x);           if (x != 0) {             b.root[i] = b.update(b.root[i], 1, inf, x, -1);           }           b.root[i] = b.update(b.root[i], 1, inf, val, 1);         } else {           mapa[t] = idx++;           a.root[i] = a.update(a.root[i], 1, maxn, mapa[t], val);           b.root[i] = b.update(b.root[i], 1, inf, val, 1);         }       } else if (op[0] ==  r ) {         char s[20];         scanf( %s , s);         string t = s;         if (mapa.count(t)) {           int x = a.get(a.root[i], 1, maxn, mapa[t]);           a.root[i] = a.update(a.root[i], 1, maxn, mapa[t], -x);           if (x != 0) {             b.root[i] = b.update(b.root[i], 1, inf, x, -1);           }         }       } else if (op[0] ==  q ) {         char s[20];         scanf( %s , s);         string t = s;         if (mapa.count(t)) {           int x = a.get(a.root[i], 1, maxn, mapa[t]);           if (x != 0) {             printf( %d n , b.sum(b.root[i], 1, inf, x));           } else             puts( -1 );         } else           puts( -1 );         fflush(stdout);       } else {         int x;         scanf( %d , &x);         a.root[i] = a.root[i - x - 1];         b.root[i] = b.root[i - x - 1];       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void doRoutine() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   long long int gcd(long long int a, long long int b) {     return b ? gcd(b, a % b) : a;   }   signed main() {     doRoutine();     vector<long long int> a(6);     long long int s = 0;     for (long long int i = 0; i < 6; i++) {       cin >> a[i];       s += a[i];     }     for (long long int i = 0; i < 6; i++) {       for (long long int j = 0; j < 6; j++) {         for (long long int l = 0; l < 6; l++) {           if (i != j && j != l && l != i) {             if (a[i] + a[j] + a[l] == s - a[i] - a[j] - a[l])               return cout <<  YES  <<   n , 0;           }         }       }     }     cout <<  NO  <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dd = (int)2e6 + 7;   int A[dd], cnt[dd];   long long tmp[dd];   pair<int, int> msk[20];   int count2[20], w;   long long pw[20];   long long ans = 0;   void get(int i, long long k) {     if (i == w) {       ans += tmp[k];       return;     }     if (count2[i] == 1) {       get(i + 1, k + pw[i] * msk[i].first);       return;     }     get(i + 1, k + pw[i] * msk[i].first);     get(i + 1, k + pw[i] * msk[i].second);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> w >> n >> m;     for (int i = 0; i < n; ++i) {       cin >> A[i];       cnt[A[i]]++;     }     pw[0] = 1;     for (int i = 1; i <= w; ++i) {       pw[i] = pw[i - 1] * 3;     }     for (int i = 0; i < (1 << w); ++i)       if (cnt[i]) {         for (int j = 0; j < (1 << w); ++j)           if (cnt[j]) {             int k = 0;             for (int l = 0; l < w; ++l) {               int ii = (i >> l) & 1, jj = (j >> l) & 1;               if (ii == jj && ii == 1) {                 k += 2 * pw[l];               }               if (ii != jj) {                 k += pw[l];               }             }             tmp[k] += cnt[i] * cnt[j];           }       }     while (m--) {       string s;       cin >> s;       reverse(s.begin(), s.end());       for (int i = 0; i < w; ++i) {         if (s[i] ==  A ) msk[i] = {0, 1}, count2[i] = 2;         if (s[i] ==  O ) msk[i] = {0, 0}, count2[i] = 1;         if (s[i] ==  X ) msk[i] = {0, 2}, count2[i] = 2;         if (s[i] ==  a ) msk[i] = {2, 2}, count2[i] = 1;         if (s[i] ==  o ) msk[i] = {1, 2}, count2[i] = 2;         if (s[i] ==  x ) msk[i] = {1, 1}, count2[i] = 1;       }       ans = 0;       get(0, 0);       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   ostream& operator<<(ostream& o, const vector<T>& v) {     o <<  [ ;     int b = 0;     for (const auto& a : v) o << (b++ ?  ,   :   ) << a;     o <<  ] ;     return o;   }   template <typename T, typename U>   ostream& operator<<(ostream& o, const pair<T, U>& p) {     o <<  (  << p.first <<  ,   << p.second <<  ) ;     return o;   }   template <typename T>   ostream& operator<<(ostream& o, const set<T>& s) {     o <<  { ;     int b = 0;     for (auto& e : s) o << (b++ ?  ,   :   ) << e;     o <<  } ;     return o;   }   template <typename T, typename U>   ostream& operator<<(ostream& o, const map<T, U>& m) {     o <<  { ;     int b = 0;     for (auto& e : m) o << (b++ ?  ,   :   ) << e;     o <<  } ;     return o;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     bool flag = 0;     vector<int> A(n);     for (auto& a : A) {       cin >> a;       if (a % 2 and flag) {         if (a < 0) {           a = a / 2;         } else {           a = (a + 1) / 2;         }         flag ^= 1;       } else if (a % 2) {         if (a < 0) {           a = (a - 1) / 2;         } else {           a = a / 2;         }         flag ^= 1;       } else {         a = a / 2;       }     }     for (auto& a : A) cout << a << endl;   }