#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5, M = 2e4 + 5, inf = 0x3f3f3f3f, mod = 1e9 + 7;   void Print(int *a, int n) {     for (int i = 1; i < n; i++) printf( %d  , a[i]);     printf( %d n , a[n]);   }   int e[N], nt[N];   void Gnt(string a, int *nt) {     int k = 0, p = 0, n = (int)a.size();     nt[0] = n;     for (int i = 1; i < n; i++) {       if (i + nt[i - k] < p)         nt[i] = nt[i - k];       else {         if (i >= p) p = i;         while (p < n && a[p] == a[p - i]) p++;         nt[i] = p - i;         k = i;       }     }   }   void Exd(string a, string b, int *e, int *nt) {     int k = 0, p = 0, n = (int)a.size(), m = (int)b.size();     Gnt(b, nt);     for (int i = 0; i < n; i++) {       if (i + nt[i - k] < p)         e[i] = nt[i - k];       else {         if (i >= p) p = i;         while (p < n && p - i < m && a[p] == b[p - i]) p++;         e[i] = p - i;         k = i;       }     }   }   int cycle(string a) {     int n = a.size();     Gnt(a, nt);     int t = n;     for (int i = 1; i < n; i++)       if (i + nt[i] == n) {         t = n % i ? n : i;         break;       }     return t;   }   string a, b;   int k, dp[N][2];   int main() {     ios::sync_with_stdio(false), cin.tie(0);     cin >> a >> b >> k;     dp[0][a != b] = 1;     int n = (int)a.size();     a = a + a;     Exd(a, b, e, nt);     int x = 0, len = (int)b.size();     for (int i = 0; i < n; i++) {       if (e[i] >= len) x++;     }     int y = n - x;     for (int i = 1; i <= k; i++) {       dp[i][0] = (1LL * x * dp[i - 1][1] + 1LL * (x - 1) * dp[i - 1][0]) % mod;       dp[i][1] = (1LL * y * dp[i - 1][0] + 1LL * (y - 1) * dp[i - 1][1]) % mod;     }     printf( %d n , dp[k][0]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> gr[50005];   int parent[50005];   void dfs(int src, int par) {     parent[src] = par;     for (auto nbr : gr[src]) {       if (nbr != par) dfs(nbr, src);     }   }   int main() {     int n, x, y;     cin >> n >> x >> y;     for (int i = 1; i <= n; i++) {       if (i == x) continue;       int p;       cin >> p;       gr[i].push_back(p);       gr[p].push_back(i);     }     dfs(y, 0);     for (int i = 1; i <= n; i++) {       if (i == y) continue;       cout << parent[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int casos;     cin >> casos;     while (casos > 0) {       int a, b;       cin >> a >> b;       if (a > b) {         int dif = a - b;         b -= dif;         a -= dif * 2;       } else if (b > a) {         int dif = b - a;         a -= dif;         b -= dif * 2;       }       if (a % 3 == 0 && a == b && a >= 0) {         printf( YES n );       } else {         printf( NO n );       }       casos--;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[100005], is[100005], isn[100005], N, used[100005];   vector<int> v;   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       char t;       int ind;       cin >> t >> ind;       a[i] = ind;       if (t ==  + )         is[ind]++;       else {         a[i] *= -1;         isn[ind]++;         N++;       }     }     for (int i = 1; i <= n; i++)       if (is[i] + N - isn[i] == m) {         v.push_back(i);         used[i] = 1;       }     if (v.size() == 1) {       for (int i = 1; i <= n; i++)         if (a[i] == v[0] || (a[i] < 0 && -a[i] != v[0]))           cout <<  Truth  << endl;         else           cout <<  Lie  << endl;     } else {       for (int i = 1; i <= n; i++)         if (a[i] > 0 && !used[a[i]])           cout <<  Lie  << endl;         else if (a[i] < 0 && !used[-a[i]])           cout <<  Truth  << endl;         else           cout <<  Not defined  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool solved;   const int MX = 1500000;   int cache_map[1 << 22];   int nxt;   int cache[MX][22];   void check_solution(vector<int>& g, vector<int>& sol, int n) {     int mask(0);     int ind(nxt);     nxt += 1;     if (nxt == MX) nxt = 0;     if (((int)sol.size()) != 1) {       for (int i(0), _l((int)(((int)sol.size())) - 1); i <= _l; ++i)         mask |= (1 << sol[i]);       int mask_prev = mask ^ (1 << sol.back());       int ind_prev(cache_map[mask_prev]);       memcpy(cache[ind], cache[ind_prev], 22 * sizeof(int));     } else {       mask |= (1 << sol.back());       for (int i(0), _l((int)(n)-1); i <= _l; ++i) cache[ind][i] = g[i];     }     cache_map[mask] = ind;     int v(sol.back());     for (int j(0), _l((int)(n)-1); j <= _l; ++j) {       if ((cache[ind][v] & (1 << j)) != 0) {         cache[ind][j] |= cache[ind][v];       }     }     int need((1 << n) - 1);     for (int i(0), _l((int)(n)-1); i <= _l; ++i)       if (cache[ind][i] != need) return;     printf( %d n , ((int)sol.size()));     for (int i(0), _l((int)(((int)sol.size())) - 1); i <= _l; ++i)       printf( %d%c , sol[i] + 1, i + 1 == ((int)sol.size()) ?   n  :    );     solved = true;   }   void try_solve(vector<int>& g, int n, int k, vector<int>& cur, int ind) {     if (solved) return;     if (((int)cur.size()) == k) {       check_solution(g, cur, n);     } else {       if (ind == n) return;       cur.push_back(ind);       try_solve(g, n, k, cur, ind + 1);       cur.pop_back();       if (solved) return;       try_solve(g, n, k, cur, ind + 1);     }   }   void solve() {     nxt = 0;     int n, m;     scanf( %d%d , &n, &m);     vector<int> g(n);     for (int i(0), _l((int)(n)-1); i <= _l; ++i) {       g[i] |= (1 << i);     }     for (int i(0), _l((int)(m)-1); i <= _l; ++i) {       int a, b;       scanf( %d%d , &a, &b);       --a, --b;       g[a] |= (1 << b);       g[b] |= (1 << a);     }     if (m == n * (n - 1) / 2) {       puts( 0 );       return;     }     solved = false;     vector<int> s;     for (int i(1), _l(n); i <= _l; ++i) {       try_solve(g, n, i, s, 0);       if (solved) break;     }   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100009;   int n;   long long a[N];   void print_ans(int l, int r, vector<long long>& v) {     cout << l <<     << r <<   n ;     for (long long vv : v) {       cout << vv <<    ;     }     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     vector<long long> fst;     fst.push_back(-a[0]);     a[0] = 0;     print_ans(1, 1, fst);     if (n == 1) {       vector<long long> zero = {0};       print_ans(1, 1, zero);       print_ans(1, 1, zero);       return 0;     }     vector<long long> scd;     for (int i = 1; i < n; ++i) {       long long md = a[i] % n;       if (md < 0) md += n;       long long nm = md * (n - 1);       scd.push_back(nm);       a[i] += nm;     }     print_ans(2, n, scd);     vector<long long> all;     for (int i = 0; i < n; ++i) {       assert(a[i] % n == 0);       all.push_back(-a[i]);     }     print_ans(1, n, all);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long f = n * (n - 1) * (n - 2) * (n - 3) * (n - 4);     cout << (f / 120) * ((n * n) - (4 * n) + 37) / 42;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, x;   vector<long long> a;   void ans() {     for (int i = 0; i < n; i++) {       cout << a[i] <<    ;     }     exit(0);   }   int main(int argc, char* argv[]) {     srand((unsigned int)time(NULL));     cin >> n >> k >> x;     a.resize(n);     int ch = 1;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] < 0) {         ch *= -1;       }     }     if (ch == 1) {       set<pair<long long, int> > s;       for (int i = 0; i < n; i++) {         if (a[i] >= 0) {           s.insert({abs(-1 - a[i]), i});         } else {           s.insert({abs(1 - a[i]), i});         }       }       auto q = *s.begin();       int id = q.second;       if (a[id] >= 0) {         while (a[id] >= 0) {           a[id] -= x;           k--;           if (k == 0) {             ans();           }         }       } else {         while (a[id] <= 0) {           a[id] += x;           k--;           if (k == 0) {             ans();           }         }       }     }     set<pair<long long, int> > s;     for (int i = 0; i < n; i++) {       s.insert({abs(a[i]), i});     }     while (k > 0) {       auto q = *s.begin();       s.erase(s.begin());       int id = q.second;       if (a[id] >= 0) {         a[id] += x;       } else {         a[id] -= x;       }       k--;       s.insert({abs(a[id]), id});     }     ans();   }


#include <bits/stdc++.h>   using namespace std;   int t;   long long n;   int main() {     cin >> t;     while (t--) {       cin >> n;       long long num;       for (long long i = 1; i < n; i++) {         if (i * i > n) {           num = i - 1;           break;         } else if (i * i == n) {           num = i;           break;         }       }       long long out = 0;       if (n == 1) {         out = 0;       } else if (n == 2) {         out = 1;       } else if (num * num == n) {         out = (num - 1) * 2;       } else if (num * (num + 1) >= n) {         out = 2 * num - 1;       } else {         out = 2 * num;       }       cout << to_string(out) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<int> v(n), v1(m);     for (int i = 0; i < n; ++i) {       cin >> v[i];     }     for (int i = 0; i < m; ++i) {       cin >> v1[i];     }     vector<int> ans;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (v[i] == v1[j]) {           ans.push_back(v[i]);           break;         }       }     }     for (auto i : ans) {       cout << i <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, d;   int main() {     cin >> n >> d;     int m;     cin >> m;     for (int i = 1; i <= m; i++) {       int x, y;       cin >> x >> y;       puts((d <= x + y && x + y <= 2 * n - d && -d <= x - y && x - y <= d)                ?  YES                 :  NO );     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int x[2600], y[2600];   string a[60];   bool valid(int y, int x1, int y1, int x, int x2, int y2) {     for (int i = min(x1, x2); i <= max(x1, x2); i++) {       if (a[i][y] !=  B ) {         return false;       }     }     for (int i = min(y1, y2); i <= max(y1, y2); i++) {       if (a[x][i] !=  B ) {         return false;       }     }     return true;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     int k = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       for (int j = 0; j < m; j++) {         if (a[i][j] ==  B ) {           x[k] = i;           y[k] = j;           k++;         }       }     }     for (int i = 0; i < k; i++) {       for (int j = i + 1; j < k; j++) {         if (valid(y[i], x[i], y[i], x[j], x[j], y[j])) {           continue;         }         if (valid(y[j], x[i], y[i], x[i], x[j], y[j])) {           continue;         }         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAX_N = 1e5 + 5;   long long n, val;   pair<pair<long long, long long>, pair<long long, long long> > edge[MAX_N];   long long par[MAX_N];   long long len[MAX_N];   vector<long long> h;   vector<long long> ans;   vector<pair<long long, long long> > G[MAX_N];   vector<long long> rot, ver;   long long P[MAX_N];   long long down[MAX_N];   long long up[MAX_N];   bool mark[MAX_N];   long long root(long long v) {     return (par[v] == v ? v : par[v] = root(par[v]));   }   void cheak(long long tmp, long long id) {     if (val < tmp) {       val = tmp;       ans.clear();     }     if (val == tmp) ans.push_back(id);   }   long long dfs1(long long v, long long p) {     P[v] = p;     down[v] = len[v];     mark[v] = true;     for (pair<long long, long long> u : G[v])       if (!mark[u.first]) down[v] += dfs1(u.first, v);     return down[v];   }   void dfs2(long long v, long long uval) {     up[v] = uval;     for (pair<long long, long long> u : G[v])       if (u.first != P[v]) dfs2(u.first, uval + down[v] - down[u.first]);   }   void dfs3(long long v) {     for (pair<long long, long long> u : G[v])       if (u.first != P[v]) {         dfs3(u.first);         cheak(up[u.first] * down[u.first], u.second);       }   }   void calc() {     for (long long id : h) {       ver.push_back(root(edge[id].second.first));       ver.push_back(root(edge[id].second.second));     }     sort(ver.begin(), ver.end());     ver.resize(unique(ver.begin(), ver.end()) - ver.begin());     for (long long id : h) {       G[root(edge[id].second.first)].push_back(           {root(edge[id].second.second), edge[id].first.second});       G[root(edge[id].second.second)].push_back(           {root(edge[id].second.first), edge[id].first.second});     }     for (long long v : ver)       if (!mark[v]) {         rot.push_back(v);         dfs1(v, v);       }     for (long long v : rot) dfs2(v, 0);     for (long long v : rot) dfs3(v);     rot.clear();     for (long long v : ver) {       G[v].clear();       mark[v] = false;     }     ver.clear();   }   int main() {     ios::sync_with_stdio(false), cin.tie(0);     cin >> n;     for (long long i = 0; i < n - 1; i++) {       long long v, u, d;       cin >> edge[i].second.first >> edge[i].second.second >> edge[i].first.first;       edge[i].first.second = i + 1;       edge[i].second.first--, edge[i].second.second--;     }     sort(edge, edge + n - 1);     for (long long i = 0; i < n; i++) {       par[i] = i;       len[i] = 1;     }     h.push_back(0);     for (long long i = 1; i < n - 1; i++) {       if (edge[i].first.first != edge[i - 1].first.first) {         calc();         for (long long id : h) {           len[root(edge[id].second.second)] += len[root(edge[id].second.first)];           par[root(edge[id].second.first)] = root(edge[id].second.second);         }         h.clear();       }       h.push_back(i);     }     calc();     cout << 2 * val <<     << ans.size() <<   n ;     sort(ans.begin(), ans.end());     for (long long u : ans) cout << u <<    ;     return 0;   }


#include <bits/stdc++.h>   template <typename T>   struct xgcd_s {     T m, n, gcd;   };   template <typename T>   xgcd_s<T> xgcd(T a, T b) {     T m[] = {1, 0}, n[] = {0, 1}, q[] = {0, 0};     for (int i = 0;; i ^= 1) {       m[i] -= m[i ^ 1] * q[i];       n[i] -= n[i ^ 1] * q[i];       if (!b) return xgcd_s<T>{m[i], n[i], a};       q[i] = a / b;       a %= b;       std::swap(a, b);     }   }   template <unsigned M()>   struct _intmod {    private:     struct _p {       unsigned x;     };     _intmod(_p x) { n = x.x; }       public:     unsigned n;     _intmod() { n = 0; }     _intmod(int x) { n = x < 0 ? M() + x % (int)M() : x % M(); }     _intmod(unsigned x) { n = x % M(); }     _intmod(long x) { n = unsigned(x < 0 ? M() + x % (long)M() : x % M()); }     _intmod(unsigned long x) { n = x % M(); }     _intmod(long long x) {       n = unsigned(x < 0 ? M() + x % (long long)M() : x % M());     }     _intmod(unsigned long long x) { n = x % M(); }     _intmod operator+(_intmod b) const { return {n + b.n}; }     _intmod operator*(_intmod b) const {       return {_p{unsigned((unsigned long long)n * b.n % M())}};     }     _intmod operator-(_intmod b) const {       return {_p{n >= b.n ? n - b.n : M() + n - b.n}};     }     _intmod operator-() const { return {_p{n ? M() - n : 0U}}; }     _intmod& operator+=(_intmod b) { return (*this = *this + b); }     _intmod& operator-=(_intmod b) { return (*this = *this - b); }     _intmod& operator/=(_intmod b) { return (*this = *this / b); }     _intmod& operator*=(_intmod b) { return (*this = *this * b); }     static _intmod mulinv(_intmod n) {       xgcd_s<signed> x = xgcd<signed>(n.n, M());       (void)0;       return x.m;     }     _intmod operator/(_intmod b) const { return *this * mulinv(b); }     bool operator==(_intmod b) const { return n == b.n; }     bool operator!=(_intmod b) const { return n != b.n; }     explicit operator int() const { return n; }   };   template <unsigned M()>   std::ostream& operator<<(std::ostream& o, _intmod<M> n) {     return o << n.n;   }   template <unsigned M()>   std::istream& operator>>(std::istream& i, _intmod<M>& n) {     long long x;     i >> x;     n = x;     return i;   }   template <unsigned M>   unsigned intmod_unsignedconst() {     static_assert(M > 0 && M < (1U << 31),  modulus bad );     return M;   }   template <unsigned* M>   unsigned intmod_unsignedptr() {     return *M;   }   template <unsigned M>   using intmod = _intmod<intmod_unsignedconst<M> >;   template <unsigned* M>   using intmodv = _intmod<intmod_unsignedptr<M> >;   static_assert(std::is_trivially_copyable<intmod<3> >::value,   );   using namespace std;   using I = intmod<998244353>;   I topGroupSizeP[2001][2001];   I favoritePow[2001];   I upsetPow[2001];   I expGames[2001];   I rrGames[2001];   int main() {     int n, a, b;     cin >> n >> a >> b;     I favoriteP = I(a) / b;     I upsetP = I(1) - favoriteP;     favoritePow[0] = upsetPow[0] = 1;     for (int i = 1; i <= n; i++) favoritePow[i] = favoriteP * favoritePow[i - 1];     for (int i = 1; i <= n; i++) upsetPow[i] = upsetP * upsetPow[i - 1];     for (int i = 1; i <= n; i++) rrGames[i] = i * (i - 1) / 2;     for (int m = 1; m <= n; m++) {       I notAllTiedP = 0;       for (int tgSize = 1; tgSize < m; tgSize++) {         I tgSizeP = topGroupSizeP[m - 1][tgSize] * favoritePow[tgSize];         I superiorGroupExcludingLastP;         if (tgSize == 1)           superiorGroupExcludingLastP = 1;         else if (tgSize == 3)           superiorGroupExcludingLastP =               topGroupSizeP[m - 1][1] * topGroupSizeP[m - 2][1];         else           superiorGroupExcludingLastP = topGroupSizeP[m - 1][tgSize - 1] /                                         topGroupSizeP[tgSize - 1][tgSize - 1];         tgSizeP += superiorGroupExcludingLastP * topGroupSizeP[tgSize][tgSize] *                    upsetPow[m - tgSize];         notAllTiedP += tgSizeP;         topGroupSizeP[m][tgSize] = tgSizeP;       }       topGroupSizeP[m][m] = I(1) - notAllTiedP;     }     expGames[1] = 0;     for (int m = 2; m <= n; m++) {       I costExcludingAllTied = 0;       for (int tgSize = 1; tgSize < m; tgSize++)         costExcludingAllTied +=             topGroupSizeP[m][tgSize] *             (expGames[tgSize] + expGames[m - tgSize] - rrGames[m - tgSize]);       I allTiedP = topGroupSizeP[m][m];       costExcludingAllTied /= I(1) - allTiedP;       I allTiedCost = rrGames[m] / (I(1) - allTiedP);       expGames[m] = costExcludingAllTied + allTiedCost;     }     cout << expGames[n];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int m, k, d;   void print(int a, int b) {     printf( %d %d n , a, b);     a += d, b += d;     printf( %d %d n , a, b);   }   int main() {     cin >> k;     if (k % 2 == 0) {       cout <<  NO ;       return 0;     }     cout <<  YES  << endl;     d = 4 * k - 2, m = (k * d) / 2;     cout << d <<     << m << endl;     d /= 2;     cout << 1 <<     << 1 + d << endl;     for (int i = 2; i <= k; i++) print(1, i);     for (int i = 2; i <= k; i++)       for (int j = k + 1; j <= 2 * k - 1; j++) print(i, j);     for (int i = 0; i < (k / 2); i++) print(k + 1 + 2 * i, k + 2 + 2 * i);     return 0;   }


#include <bits/stdc++.h>   const long long int mod = 9999999999999983;   long long int primes[6] = {1125899906842597, 1495921043, 1005985879,                              1495921043,       1005985879, 1495921043};   using namespace std;   vector<string> vect;   long long int level[1000009];   vector<string> vt[1000009];   map<string, long long int> mp;   void printWords(string str) {     string word;     stringstream iss(str);     while (iss >> word) vect.push_back(word);   }   int main() {     int start_s = clock();     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int i, j, k, n, m, store, mxlevel = 0;     stack<long long int> stk;     string str, str1;     cin >> str;     for (i = 0; i < str.size(); i++) {       if (str[i] ==  , ) str[i] =    ;     }     printWords(str);     for (i = 0; i < vect.size(); i++) {       str1 = vect[i];       if (str1[0] -  0  >= 0 && str1[0] -  0  <= 9) {         string s = str1;         stringstream geek(s);         long long int number = 0;         geek >> number;         if (number != 0) stk.push(number);         continue;       }       if (stk.size() == 0)         level[i] = 0;       else {         level[i] = stk.size();         store = stk.top();         stk.pop();         if (store - 1 != 0) stk.push(store - 1);         if (store - 1 == 0 && vect[i + 1] !=  0 ) stk.push(0);         if (store - 1 == 0 && vect[i + 1] ==  0 ) {           while (stk.size() > 0) {             if (stk.top() == 0)               stk.pop();             else               break;           }         }       }     }     for (i = 0; i < vect.size(); i++) {       str1 = vect[i];       if (str1[0] -  0  >= 0 && str1[0] -  0  <= 9) {         continue;       } else {         mxlevel = max(mxlevel, level[i]);         vt[level[i]].push_back(vect[i]);       }     }     cout << mxlevel + 1 <<   n ;     for (i = 0; i < mxlevel + 1; i++) {       for (j = 0; j < vt[i].size(); j++) {         cout << vt[i][j] <<    ;       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int a[100005];   long long s[100005], b[100005];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) scanf( %d , a + i);     sort(a, a + n);     s[0] = a[0];     b[n] = 0;     for (int i = 1; i <= n; ++i) s[i] = s[i - 1] + a[i];     for (int i = n - 1; i >= 0; --i) b[i] = b[i + 1] + a[i];     long long ll = 0, rr = n;     for (int i = 0; i < n; ++i) {       ll += (a[i] * (i + 1LL) - s[i] + b[i] - a[i] * (n - i + 0LL) + a[i]);     }     long long g = gcd(ll, rr);     cout << ll / g <<     << rr / g << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, count = 0;     vector<int> vect, keep;     cin >> n;     while (n != 0) {       keep.push_back(n % 10);       n = n / 10;       ++count;     }     reverse(keep.begin(), keep.end());     for (auto itr = keep.begin(); itr != keep.end(); itr++) {       int num = pow(10, count - 1);       int k;       vector<int>::iterator itc;       for (itc = vect.begin(), k = *itr; itc != vect.end() && k > 0; itc++, k--) {         *itc = *itc + num;       }       if (k > 0) {         while (k--) {           vect.push_back(num);         }       }       count--;     }     cout << vect.size() << endl;     for (auto itr = vect.begin(); itr != vect.end(); itr++) cout << *itr <<    ;     cout << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1010;   set<int> X, Y;   int n, m;   char st[maxn][maxn], sz[maxn][maxn];   bool fill(int x1, int y1, int x2, int y2) {     int i;     for (i = x1; i <= x2; ++i) {       if (st[i][y1] ==  . ) return 0;       if (st[i][y2] ==  . ) return 0;       sz[i][y1] = sz[i][y2] =  # ;     }     for (i = y1; i <= y2; ++i) {       if (st[x1][i] ==  . ) return 0;       if (st[x2][i] ==  . ) return 0;       sz[x1][i] = sz[x2][i] =  # ;     }     return true;   }   int main() {     int i, j;     scanf( %d %d n , &n, &m);     for (i = 1; i <= n; ++i) scanf( %s , st[i] + 1);     for (i = 1; i <= n; ++i)       for (j = 1; j <= m; ++j) {         if (st[i][j - 1] ==  #  && st[i][j] ==  #  && st[i][j + 1] ==  # )           X.insert(i);         if (st[i - 1][j] ==  #  && st[i][j] ==  #  && st[i + 1][j] ==  # )           Y.insert(j);       }     if (X.size() > 4) X.erase(++ ++X.begin(), -- --X.end());     if (Y.size() > 4) Y.erase(++ ++Y.begin(), -- --Y.end());     for (set<int>::iterator x1 = X.begin(); x1 != X.end(); ++x1)       for (set<int>::iterator x2 = X.begin(); x2 != X.end(); ++x2)         for (set<int>::iterator x3 = X.begin(); x3 != X.end(); ++x3)           for (set<int>::iterator x4 = X.begin(); x4 != X.end(); ++x4)             for (set<int>::iterator y1 = Y.begin(); y1 != Y.end(); ++y1)               for (set<int>::iterator y2 = Y.begin(); y2 != Y.end(); ++y2)                 for (set<int>::iterator y3 = Y.begin(); y3 != Y.end(); ++y3)                   for (set<int>::iterator y4 = Y.begin(); y4 != Y.end(); ++y4)                     if (*x1 + 1 < *x2 && *x3 + 1 < *x4 && *y1 + 1 < *y2 &&                         *y3 + 1 < *y4) {                       memset(sz,  . , sizeof(sz));                       if (fill(*x1, *y1, *x2, *y2) && fill(*x3, *y3, *x4, *y4)) {                         bool ok = true;                         for (i = 1; i <= n; ++i)                           for (j = 1; j <= m; ++j)                             if (st[i][j] != sz[i][j]) ok = false;                         if (ok) {                           printf( YES n );                           printf( %d %d %d %d n , *x1, *y1, *x2, *y2);                           printf( %d %d %d %d n , *x3, *y3, *x4, *y4);                           return 0;                         }                       }                     }     printf( NO n );     return 0;   }


#include <bits/stdc++.h>   int s, k;   long long f[1000], res[1000];   int main() {     scanf( %d %d , &s, &k);     f[0] = 0;     f[1] = 1;     int i;     for (i = 2; f[i - 1] <= s; i++)       for (int j = 1; i - j > 0 && j <= k; j++) f[i] += f[i - j];     int cnt = 0;     for (i = i - 1; i >= 0; i--)       if (f[i] <= s) {         s -= f[i];         res[cnt++] = f[i];       }     printf( %d n , cnt);     for (int i = 0; i < cnt; i++) printf( %d  , res[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int w, h, h1, w1, h2, w2;     cin >> w >> h >> w1 >> h1 >> w2 >> h2;     for (int i = h; i >= 0; i--) {       w += i;       if (i == h1) w -= w1;       if (i == h2) w -= w2;       if (w < 0) w = 0;     }     cout << w << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, cnt, num, sub_d[(2600)], d[(2600)], root, cut[(2600)], t;   char s[55][55];   bool mark[(2600)], p, cycle;   vector<long long> e[(2600)];   void dfs(long long x, long long par = 0) {     bool tmp = 0;     if (!t) cnt++;     mark[x] = 1;     sub_d[x] = d[x];     for (int i = 0; i < e[x].size(); i++) {       if (mark[e[x][i]] && e[x][i] != par) cycle = 1;       if (!mark[e[x][i]]) {         d[e[x][i]] = d[x] + 1;         dfs(e[x][i], x);         sub_d[x] = min(sub_d[x], sub_d[e[x][i]]);         if (sub_d[e[x][i]] >= d[x]) tmp = 1;       } else if (e[x][i] != par)         sub_d[x] = min(sub_d[x], d[e[x][i]]);     }     cut[x] += tmp;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> s[i][j];         if (s[i][j] ==  # ) num++;       }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         for (int p = -1; p <= 1; p++)           for (int q = -1; q <= 1; q++)             if ((!p ^ !q) && i + p >= 0 && j + q >= 0 && i + p < n && j + q < m &&                 s[i][j] ==  #  && s[i + p][j + q] ==  # )               e[i * m + j].push_back((i + p) * m + j + q);     for (int i = 0; i < n * m && t < 2; i++)       if (s[i / m][i % m] ==  # ) {         for (int j = 0; j < n * m; j++) mark[j] = d[j] = sub_d[j] = 0;         root = i;         dfs(i);         t++;       }     for (int i = 0; i < n * m; i++)       if (cut[i] == 2) p = 1;     if (p)       cout << 1;     else if (cnt != num)       cout << 0;     else if (cycle)       cout << 2;     else       cout << -1;     return 0;   }


#include <bits/stdc++.h>   using ll = long long int;   int main() {     int n, m;     std::cin >> n >> m;     std::vector<std::vector<int>> matr1(n);     std::vector<std::vector<int>> matr2(n);     std::vector<std::vector<int>> matr_min(n);     std::vector<std::vector<int>> matr_max(n);     for (int i = 0; i < n; i++) {       matr1[i].resize(m);       matr2[i].resize(m);       matr_min[i].resize(m);       matr_max[i].resize(m);     }     for (int i = 0; i < n; i++) {       for (auto &it : matr1[i]) {         std::cin >> it;       }     }     for (int i = 0; i < n; i++) {       for (auto &it : matr2[i]) {         std::cin >> it;       }     }     for (int i = 0; i < n; i++) {       for (int z = 0; z < m; z++) {         matr_min[i][z] = std::min(matr1[i][z], matr2[i][z]);         matr_max[i][z] = std::max(matr1[i][z], matr2[i][z]);       }     }     for (int i = 0; i < n; i++) {       for (int z = 0; z < m; z++) {         if (z - 1 >= 0 && matr_min[i][z - 1] >= matr_min[i][z]) {           std::cout <<  Impossible  << std::endl;           return 0;         }         if (i - 1 >= 0 && matr_min[i - 1][z] >= matr_min[i][z]) {           std::cout <<  Impossible  << std::endl;           return 0;         }         if (z - 1 >= 0 && matr_max[i][z - 1] >= matr_max[i][z]) {           std::cout <<  Impossible  << std::endl;           return 0;         }         if (i - 1 >= 0 && matr_max[i - 1][z] >= matr_max[i][z]) {           std::cout <<  Impossible  << std::endl;           return 0;         }       }     }     std::cout <<  Possible  << std::endl;   }


#include <bits/stdc++.h>   using namespace std;   int ans[15];   int n, q;   string in;   string tmp;   void go(int l, int r) {     tmp =     + in.substr(l - 1, r - l + 1);     string::iterator cp = tmp.begin() + 1;     int dp = 1;     while (cp != tmp.begin() && cp != tmp.end()) {       if (*cp >=  0  && *cp <=  9 ) {         ans[*cp -  0 ]++;         *cp -= 1;         if (*cp ==  0  - 1) {           tmp.erase(cp);           if (dp == -1) cp--;         } else           cp += dp;       } else {         if (*cp ==  < )           dp = -1;         else           dp = 1;         if (*(cp + dp) ==  <  || *(cp + dp) ==  > ) {           tmp.erase(cp);           if (dp == -1) cp--;         } else           cp = cp + dp;       }     }   }   int main() {     scanf( %d %d , &n, &q);     cin >> in;     for (int tt = 0; tt < q; tt++) {       int l, r;       memset(ans, 0, sizeof(ans));       scanf( %d %d , &l, &r);       go(l, r);       for (int i = 0; i < 10; i++) printf( %d  , ans[i]);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string to_string(char c) { return string(1, c); }   string to_string(bool b) { return b ?  true  :  false ; }   string to_string(const char* s) { return (string)s; }   string to_string(string s) { return s; }   template <class A>   string to_string(complex<A> c) {     stringstream ss;     ss << c;     return ss.str();   }   string to_string(vector<bool> v) {     string res =  { ;     for (int i = 0; i < (int)v.size(); i++) res += char( 0  + v[i]);     res +=  } ;     return res;   }   template <size_t SZ>   string to_string(bitset<SZ> b) {     string res =   ;     for (size_t i = 0; i < SZ; i++) res += char( 0  + b[i]);     return res;   }   template <class A, class B>   string to_string(pair<A, B> p);   template <class T>   string to_string(T v) {     bool fst = 1;     string res =  { ;     for (const auto& x : v) {       if (!fst) res +=  ,  ;       fst = 0;       res += to_string(x);     }     res +=  } ;     return res;   }   template <class A, class B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   void DBG() { cerr <<  ]  << endl; }   template <class H, class... T>   void DBG(H h, T... t) {     cerr << to_string(h);     if (sizeof...(t)) cerr <<  ,  ;     DBG(t...);   }   inline void test_case() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int l = a[0];     int r = a[n - 1];     n = a.size();     int negah = 0;     for (int& i : a) {       if (i < negah) {         cout <<  NO  <<   n ;         return;       }       if (i > l && i - l > negah) {         negah = i - l;         i -= l;       } else {         l = min(l, i - negah);         i -= l;       }     }     reverse((a).begin(), (a).end());     for (int& i : a) {       r = min(r, i);       i = max(i - r, 0);     }     if (count((a).begin(), (a).end(), 0) == (int)a.size()) {       cout <<  YES  <<   n ;     } else {       cout <<  NO  <<   n ;     }   }   int main() {     ios::sync_with_stdio(0);     int tt;     cin >> tt;     while (tt--) {       test_case();     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   string s[] = { Mahmoud ,  Ehab };   int main() {     cin >> n;     cout << s[n % 2];   }


#include <bits/stdc++.h>   using namespace std;   using pii = pair<int, int>;   int m, n;   pii a[100001];   vector<int> adj[100001];   bool is_chosen[100001];   bool is_visited[100001];   int cnt = 0;   template <typename T>   inline T read() {     T x = 0;     T multiplier = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) {         multiplier = -1;       }       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 3) + (x << 1) + (ch & 15);       ch = getchar();     }     return x * multiplier;   }   void dfs(int u, int prt) {     if (is_chosen[a[u].first] && is_chosen[a[u].second]) {       return;     }     if (is_visited[u]) {       return;     }     is_visited[u] = true;     bool x = is_chosen[a[u].first], y = is_chosen[a[u].second];     if (!x) {       is_chosen[a[u].first] = true;       is_chosen[a[u].second] = true;       for (auto v : adj[a[u].first]) {         if (v != prt) {           dfs(v, u);         }       }     }     if (!y) {       is_chosen[a[u].first] = true;       is_chosen[a[u].second] = true;       for (auto v : adj[a[u].second]) {         if (v != prt) {           dfs(v, u);         }       }     }     is_chosen[a[u].first] = true;     is_chosen[a[u].second] = true;   }   int main() {     n = read<int>(), m = read<int>();     for (int i = 1; i <= m; i++) {       a[i].first = read<int>();       a[i].second = read<int>();     }     sort(a + 1, a + m + 1);     for (int i = 1; i <= m; i++) {       adj[a[i].first].push_back(i);       adj[a[i].second].push_back(i);     }     for (int i = 1; i <= m; i++) {       if (!is_visited[i]) {         dfs(i, -1);       }     }     for (int i = 1; i <= m; i++) {       cnt += !is_visited[i];     }     printf( %d n , cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     long long n;     cin >> n;     long long result = 1;     long long x = n;     for (long long i = 2; i * i <= x; ++i) {       if (n % i == 0) {         result *= i;         while (n % i == 0) n /= i;       }     }     result *= n;     cout << result << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, a[100005], vis[100005], cnt, t;   void Solve() {     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       if (!vis[a[i]]) cnt++;       ++vis[a[i]];       if (cnt == k) {         t = 1;         while (cnt == k) {           --vis[a[t]];           if (!vis[a[t]]) --cnt;           t++;         }         printf( %d %d n , t - 1, i);         return;       }     }     printf( -1 -1 n );   }   int main(void) {     Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[200010];   int n;   bool query(int x) {     int t = -1, l = -1;     for (int i = 0; i < n; i++) {       l--;       if (s[i] ==  . ) continue;       if (s[i] ==  P ) {         if (t == -1) t = i;         int tmp = max(x - (i - t) * 2, (x - (i - t)) / 2);         l = max(tmp, l);         if (i - t > x) return 0;         t = -1;       }       if (s[i] ==  * ) {         if (l >= 0) continue;         if (t == -1) t = i;       }     }     if (t != -1) return 0;     return 1;   }   int bs(int l, int r) {     if (l == r) return l;     int m = (l + r) / 2;     if (query(m))       return bs(l, m);     else       return bs(m + 1, r);   }   int main() {     cin >> n;     scanf( %s , s);     cout << bs(0, n * 2) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, sgn = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) sgn = -1;     for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);     return x * sgn;   }   const int N = 1e5 + 10;   int n;   long long ans1, ans2;   struct line {     int x, y, l, r;   } seg[N];   bool cmp1(line a, line b) { return a.x < b.x; }   bool cmp2(line a, line b) { return a.y < b.y; }   struct BITT {     int arr[N << 1];     void add(int x, int v = 1) {       for (; x <= (n * 2); x += x & -x) arr[x] += v;       return;     }     int q(int x, int v = 0) {       for (; x; x -= x & -x) v += arr[x];       return v;     }     void clear() { memset(arr, 0, sizeof(arr)); }   } BIT;   int main() {     n = read();     for (int i = 1; i <= n; i++) seg[i].x = read(), seg[i].y = read();     for (int i = 1; i <= n; i++)       if (seg[i].x > seg[i].y) swap(seg[i].x, seg[i].y);     sort(seg + 1, seg + n + 1, cmp1);     for (int i = 1; i <= n; i++) {       seg[i].l += BIT.q(seg[i].x) + BIT.q(n << 1) - BIT.q(seg[i].y);       BIT.add(seg[i].y);     }     BIT.clear();     for (int i = n; i >= 1; i--) {       seg[i].r += BIT.q(seg[i].y);       BIT.add(seg[i].y);     }     BIT.clear();     sort(seg + 1, seg + n + 1, cmp2);     for (int i = n; i >= 1; i--) {       seg[i].l += BIT.q(n << 1) - BIT.q(seg[i].y);       BIT.add(seg[i].x);     }     ans1 = 1ll * n * (n - 1) * (n - 2) / 6;     for (int i = 1; i <= n; i++) {       ans1 -= 1ll * seg[i].l * seg[i].r;       ans2 += 1ll * (seg[i].l + seg[i].r) * (n - seg[i].l - seg[i].r - 1);     }     printf( %lld n , ans1 - ans2 / 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   const long long mod = 1e9 + 7;   void solve();   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long tests = 1;     while (tests--) solve();     return 0;   }   void solve() {     long long n;     cin >> n;     pair<long long, long long> a[n];     for (long long i = 0; i < n; i++) {       cin >> a[i].second;       long long x = a[i].second;       long long cnt = 0;       while (x % 3 == 0) {         x = x / 3;         ++cnt;       }       a[i].first = -cnt;     }     sort(a, a + n);     for (long long i = 0; i < n; i++) {       cout << a[i].second <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   template <class T = int>   inline T readInt();   inline double readDouble();   inline int readUInt();   inline int readChar();   inline void readWord(char *s);   inline bool readLine(char *s);   inline bool isEof();   inline int getChar();   inline int peekChar();   inline bool seekEof();   inline void skipBlanks();   inline std::string readString();   template <class T>   inline void writeInt(T x, char end = 0, int len = -1);   inline void writeChar(int x);   inline void writeWord(const char *s);   inline void writeDouble(double x, int len = 0);   inline void flush();   static struct buffer_flusher_t {     ~buffer_flusher_t() { flush(); }   } buffer_flusher;   using namespace std;   int n, m, l;   const int MAXN = 1e5 + 42;   int h[MAXN];   string pn[MAXN];   string nn[MAXN];   vector<int> z_function(const string &second) {     int n = second.size();     vector<int> z(n, 0);     for (int i = 1, L = 0, R = 1; i < n; ++i) {       z[i] = min(R - i, z[i - L]);       while (i + z[i] < n && second[i + z[i]] == second[z[i]]) ++z[i];       if (i + z[i] + !z[i] > R) L = i, R = i + z[i] + !z[i];     }     return z;   }   inline bool check(const string &pat, const string &rep) {     int len = rep.size();     for (int i = 0; i < n; ++i) {       string second = pat +  #  + pn[i];       auto tz = z_function(second);       vector<int> z;       for (int j = pat.size() + 1; j < tz.size(); ++j) {         z.push_back(tz[j]);       }       bool have = 0;       int pos_st = 0;       for (int j = 0; j < nn[i].size(); ++j) {         if (have) {           if (j - pos_st + 1 <= len) {             if (nn[i][j] != rep[j - pos_st]) return 0;           } else {             if (nn[i][j] != pn[i][j]) return 0;           }         } else if (z[j] == len) {           have = 1;           pos_st = j;           --j;           continue;         } else {           if (nn[i][j] != pn[i][j]) return 0;         }       }     }     return 1;   }   vector<int> same;   vector<int> dif;   inline pair<string, string> get_strs() {     vector<int> lptr;     vector<int> rptr;     for (int sid : dif) {       string pna = pn[sid];       string nna = nn[sid];       lptr.push_back(5000);       rptr.push_back(-1);       for (int i = 0; i < pna.size(); ++i) {         if (pna[i] != nna[i]) {           lptr.back() = min(lptr.back(), i);           rptr.back() = i;         }       }     }     int lp = lptr[0];     int rp = rptr[0];     cerr << lp <<     << rp << endl;     int ss = dif[0];     while (lp > 0) {       bool flag = 1;       for (int i = 1; i < dif.size(); ++i) {         int sid = dif[i];         if (lptr[i] == 0 || !(pn[sid][lptr[i] - 1] == pn[ss][lp - 1] &&                               nn[sid][lptr[i] - 1] == nn[ss][lp - 1])) {           flag = 0;           break;         }         --lptr[i];       }       if (!flag) break;       --lp;     }     while (rp < pn[ss].size() - 1) {       bool flag = 1;       for (int i = 1; i < dif.size(); ++i) {         int sid = dif[i];         if (rptr[i] == pn[sid].size() - 1 ||             !(pn[sid][rptr[i] + 1] == pn[ss][rp + 1] &&               nn[sid][rptr[i] + 1] == nn[ss][rp + 1])) {           flag = 0;           break;         }         ++rptr[i];       }       if (!flag) break;       ++rp;     }     cerr << lp <<     << rp << endl;     return {pn[ss].substr(lp, rp - lp + 1), nn[ss].substr(lp, rp - lp + 1)};   }   int main() {     n = readInt();     int pos = 0;     for (int i = 0; i < n; ++i) {       pn[i] = readString();     }     for (int i = 0; i < n; ++i) {       nn[i] = readString();       if (nn[i] != pn[i]) {         dif.push_back(i);       } else {         same.push_back(i);       }     }     auto [pat, rep] = get_strs();     if (check(pat, rep)) {       writeWord( YES n );       writeWord(pat.c_str());       writeChar(  n );       writeWord(rep.c_str());       writeChar(  n );     } else {       writeWord( NO n );     }   }   static const int buf_size = 4096;   static unsigned char buf[buf_size];   static int buf_len = 0, buf_pos = 0;   inline string readString() {     const int MAX = 1e6 + 42;     static char buf[MAX];     readWord(buf);     return string(buf);   }   inline bool isEof() {     if (buf_pos == buf_len) {       buf_pos = 0, buf_len = fread(buf, 1, buf_size, stdin);       if (buf_pos == buf_len) return 1;     }     return 0;   }   inline int getChar() { return isEof() ? -1 : buf[buf_pos++]; }   inline int peekChar() { return isEof() ? -1 : buf[buf_pos]; }   inline bool seekEof() {     int c;     while ((c = peekChar()) != -1 && c <= 32) buf_pos++;     return c == -1;   }   inline void skipBlanks() {     while (!isEof() && buf[buf_pos] <= 32U) buf_pos++;   }   inline int readChar() {     int c = getChar();     while (c != -1 && c <= 32) c = getChar();     return c;   }   inline int readUInt() {     int c = readChar(), x = 0;     while ( 0  <= c && c <=  9 ) x = x * 10 + c -  0 , c = getChar();     return x;   }   template <class T>   inline T readInt() {     int second = 1, c = readChar();     T x = 0;     if (c ==  - )       second = -1, c = getChar();     else if (c ==  + )       c = getChar();     while ( 0  <= c && c <=  9 ) x = x * 10 + c -  0 , c = getChar();     return second == 1 ? x : -x;   }   inline double readDouble() {     int second = 1, c = readChar();     double x = 0;     if (c ==  - ) second = -1, c = getChar();     while ( 0  <= c && c <=  9 ) x = x * 10 + c -  0 , c = getChar();     if (c ==  . ) {       c = getChar();       double coef = 1;       while ( 0  <= c && c <=  9 ) x += (c -  0 ) * (coef *= 1e-1), c = getChar();     }     return second == 1 ? x : -x;   }   inline void readWord(char *second) {     int c = readChar();     while (c > 32) *second++ = c, c = getChar();     *second = 0;   }   inline bool readLine(char *second) {     int c = getChar();     while (c !=   n  && c != -1) *second++ = c, c = getChar();     *second = 0;     return c != -1;   }   static int write_buf_pos = 0;   static char write_buf[buf_size];   inline void writeChar(int x) {     if (write_buf_pos == buf_size)       fwrite(write_buf, 1, buf_size, stdout), write_buf_pos = 0;     write_buf[write_buf_pos++] = x;   }   inline void flush() {     if (write_buf_pos)       fwrite(write_buf, 1, write_buf_pos, stdout), write_buf_pos = 0;   }   template <class T>   inline void writeInt(T x, char end, int output_len) {     if (x < 0) writeChar( - ), x = -x;     char second[24];     int n = 0;     while (x || !n) second[n++] =  0  + x % 10, x /= 10;     while (n < output_len) second[n++] =  0 ;     while (n--) writeChar(second[n]);     if (end) writeChar(end);   }   inline void writeWord(const char *second) {     while (*second) writeChar(*second++);   }   inline void writeDouble(double x, int output_len) {     if (x < 0) writeChar( - ), x = -x;     int t = (int)x;     writeInt(t), x -= t;     writeChar( . );     for (int i = output_len - 1; i > 0; i--) {       x *= 10;       t = std::min(9, (int)x);       writeChar( 0  + t), x -= t;     }     x *= 10;     t = std::min(9, (int)(x + 0.5));     writeChar( 0  + t);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   const long long INF = 1e9 + 19;   int n;   pair<long long, long long> b[N];   long long T;   void read() {     scanf( %d , &n);     long long w;     scanf( %lld%lld , &T, &w);     n--;     for (int i = 0; i < n; i++) {       scanf( %lld%lld , &b[i].first, &b[i].second);     }   }   void solve() {     sort(b, b + n, greater<pair<long long, long long>>());     multiset<long long> q;     int answer = INF;     int rem = 0;     int cur = 0;     for (;;) {       for (; cur < n && b[cur].first > T; cur++) {         q.insert(b[cur].second - b[cur].first + 1);       }       answer = min(answer, cur - rem);       if (q.empty()) break;       long long x = *q.begin();       if (T >= x) {         T -= x;         rem++;         q.erase(q.begin());       } else         break;     }     cout << answer + 1 << endl;   }   void stress() {}   int main() {     if (1) {       int k = 1;       for (int tt = 0; tt < k; tt++) {         read();         solve();       }     } else {       stress();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout.precision(10);     int n;     cin >> n;     if (n % 2) {       cout <<  black n ;     } else {       cout <<  white n ;       cout << 1 <<     << 2 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 10, inf = 1e18, mod = 1e9 + 7;   long long a[N], b[N], q[N], q2[N];   unordered_map<int, int> mp;   vector<long long> cmp;   struct node {     int l, r, col = 0;     int size() { return r - l; }     int unity(int lq, int rq) { return max(0, min(r, rq) - max(l, lq)); }     bool init(int lq, int rq) { return unity(lq, rq) == size(); }     bool leaf() { return size() == 1; }   };   node seg[4 * N];   void build(int v, int l, int r) {     seg[v].l = l;     seg[v].r = r;     if (seg[v].leaf()) return;     int mid = (l + r) / 2;     build(2 * v, l, mid);     build(2 * v + 1, mid, r);   }   void add(int v, int l, int r, int cl) {     if (!seg[v].unity(l, r)) return;     if (seg[v].init(l, r)) {       seg[v].col = cl;       return;     }     add(v * 2, l, r, cl);     add(v * 2 + 1, l, r, cl);   }   int get(int v, int ind) {     if (!seg[v].unity(ind, ind + 1)) return 0;     if (seg[v].leaf()) {       return seg[v].col;     }     return max(max(get(v * 2, ind), get(v * 2 + 1, ind)), seg[v].col);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> b[i];     long long id = 1;     build(1, 1, n + 1);     for (int i = 0; i < m; i++) {       int tp;       cin >> tp;       if (tp == 1) {         long long x, y, k;         cin >> x >> y >> k;         q[id] = x;         q2[id] = y;         add(1, y, y + k, id);         id++;       } else {         long long ind;         cin >> ind;         long long c = get(1, ind);         if (c == 0)           cout << b[ind] <<   n ;         else {           long long x = q[c], y = q2[c];           cout << a[x + ind - y] <<   n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, x;     cin >> n >> x;     set<long long> s;     long long a;     for (long long i = 0; i < n; i++) {       cin >> a;       s.insert(a);     }     for (auto it = s.begin(); it != s.end(); it++) {       if (*it <= x)         x++;       else {         if (x + 1 == *it) x++;       }     }     cout << x <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long test;     cin >> test;     while (test--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, flow[200100][2], dtion[200100], Eg[200100];   bool vis[200100];   queue<int> q;   struct node {     int v, d, i;     node *next;   } edge[200100 * 2];   node *cnt = &edge[0];   node *adj[200100];   void Addedge(int u, int v, int d, int i) {     node *p = ++cnt;     p->v = v;     p->d = d;     p->i = i;     p->next = adj[u];     adj[u] = p;   }   void Solve() {     int u, v, d;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &Eg[i], &v, &d);       Addedge(Eg[i], v, d, i);       flow[Eg[i]][0] += d;       Addedge(v, Eg[i], d, i);       flow[v][0] += d;     }     q.push(1);     vis[1] = true;     while (!q.empty()) {       u = q.front();       q.pop();       for (node *p = adj[u]; p; p = p->next) {         v = p->v;         d = p->d;         if (vis[v]) continue;         dtion[p->i] = u;         flow[v][1] += d;         flow[v][0] -= d;         if (v != n && flow[v][1] == flow[v][0]) {           vis[v] = true;           q.push(v);         }       }     }     for (int i = 1; i <= m; i++) {       if (dtion[i] == Eg[i])         printf( 0 n );       else         printf( 1 n );     }   }   int main() {     Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   const int maxn = 1e5 + 5;   long long a[15], b[15];   int main() {     for (int i = 0; i < 14; ++i) {       cin >> a[i];     }     long long ans = 0;     for (int i = 0; i < 14; ++i) {       if (a[i] == 0) continue;       for (int j = 0; j < 14; ++j) b[j] = a[j];       b[i] = 0;       for (int j = 0; j < 14; ++j) b[j] += a[i] / 14;       long long tmp = a[i] % 14;       int now = (i + 1) % 14;       while (tmp--) {         ++b[now];         now = (now + 1) % 14;       }       long long ans1 = 0;       for (int j = 0; j < 14; ++j) {         if (b[j] & 1) continue;         ans1 += b[j];       }       ans = max(ans, ans1);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N;     cin >> N;     int arr[N + 1];     for (int i = 0; i < N; i++) {       cin >> arr[i];     }     sort(arr, arr + N);     if (arr[0] != arr[N / 2])       cout <<  Alice  << endl;     else       cout <<  Bob  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ans = 0;   int n;   int tree[10001];   int dp[10001] = {0};   int main() {     cin >> n;     int a[100001];     int tot = pow(2, n + 1) - 2;     for (int i = 2; i <= tot + 1; i++) {       cin >> a[i];     }     tree[0] = 0;     tree[1] = 0;     int ma = 0;     for (int i = 2; i <= pow(2, n + 1) - 1; i++) {       tree[i] = tree[i / 2] + a[i];       ma = max(tree[i], ma);     }     for (int i = n - 1; i >= 1; i--) {       for (int j = pow(2, n); j < pow(2, n + 1); j += pow(2, i)) {         int mi = ma - tree[j];         for (int k = 0; k < pow(2, i); k++) {           mi = min(mi, ma - tree[j + k]);         }         ans += mi;         for (int k = 0; k < pow(2, i); k++) {           tree[j + k] += mi;         }       }     }     for (int i = pow(2, n); i < pow(2, n + 1); i++) {       ans += (ma - tree[i]);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   int mem[2005][2005], n, h, l, r;   int arr[2005];   int f(int inx, int hour) {     if (inx >= n) return 0;     if (mem[inx][hour] != -1) return mem[inx][hour];     int a = f(inx + 1, (hour + arr[inx]) % h);     int b = f(inx + 1, (hour + arr[inx] - 1) % h);     if ((hour + arr[inx]) % h >= l && (hour + arr[inx]) % h <= r) ++a;     if ((hour + arr[inx] - 1) % h >= l && (hour + arr[inx] - 1) % h <= r) {       ++b;     }     return mem[inx][hour] = max(a, b);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> h >> l >> r;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     memset(mem, -1, sizeof mem);     cout << f(0, 0) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, i = 0, d = 2;     cin >> n >> k;     vector<int> v;     while (i < k - 1 && n != 1) {       if (n % d == 0) {         n /= d;         v.push_back(d);         i++;       } else {         d++;       }     }     if (n != 1) v.push_back(n);     if (k != v.size())       cout <<  -1 ;     else {       for (int i = 0; i < k; i++) cout << v[i] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1000000 + 20;   int used[MAX_N];   int a[MAX_N];   int n, k;   int main() {     ios::sync_with_stdio(false);     cin >> n >> k;     for (int i(0); i < int(n); i++) {       int x;       cin >> x;       ++used[x];     }     int sum = 0;     for (int i = 0; i <= 1000000; i++) {       a[i] = sum;       sum += used[i];     }     int ans = 0;     for (int i = 1; i <= 1000000; i++) {       int res = 0, p = min(k, i - 1);       for (int j = i; j < 1000001; j += i) {         int y = min(1000000, j + p);         res += a[y] - a[j] + used[y];       }       if (res == n) ans = max(ans, i);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a;     long long k;     cin >> n >> k;     vector<int> arr(n), c(n);     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     cin >> a;     for (int i = 0; i < n; i++) {       cin >> c[i];     }     set<int> m;     long long ans = 0;     for (int i = 0; i < n; i++) {       m.insert(c[i]);       while (k < arr[i]) {         if (m.empty()) {           cout << -1;           return 0;         }         ans += *(m.begin());         k += a;         m.erase(m.begin());       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int dpr[300005];   int dpl[300005];   int A[300005];   pair<int, int> B[300005];   int fr(int pos) {     if (A[pos] == 0) return pos - 1;     if (pos == n - 1) return n - 1;     if (dpr[pos] != -1) return dpr[pos];     dpr[pos] = fr(pos + 1);     return dpr[pos];   }   int fl(int pos) {     if (A[pos] == 0) return pos + 1;     if (pos == 0) return 0;     if (dpl[pos] != -1) return dpl[pos];     dpl[pos] = fl(pos - 1);     return dpl[pos];   }   int main() {     int k;     cin >> n >> k;     memset(dpl, -1, sizeof dpl);     memset(dpr, -1, sizeof dpr);     int maxx = 0;     int coun = 0;     for (int i = 0; i < n; i++) {       cin >> A[i];       if (A[i] == 0) {         if (coun > maxx) {           maxx = coun;         }         coun = 0;       } else {         coun++;       }     }     if (coun > maxx) maxx = coun;     coun = maxx;     vector<int> C;     for (int i = 0; i < n; i++) {       if (A[i] == 0) {         if (i == 0) {           B[i].first = 0;           B[i].second = fr(i + 1);         } else if (i == n - 1) {           B[i].second = n - 1;           B[i].first = fl(i - 1);         } else {           B[i].first = fl(i - 1);           B[i].second = fr(i + 1);         }         C.push_back(i);       }     }     int sta = 0;     int fin = k - 1;     int a;     int smax = 0;     while ((fin < C.size()) && (k > 0) && (C.size() > 0)) {       a = (C[fin] - C[sta] + 1) + (C[sta] - B[C[sta]].first) +           (B[C[fin]].second - C[fin]);       if (a > maxx) {         maxx = a;         smax = B[C[sta]].first;       }       sta++;       fin++;     }     if ((sta < C.size()) && (C.size() > 0) && (k > 0)) {       a = n - C[sta] + (C[sta] - B[C[sta]].first);       if (a > maxx) {         maxx = a;         smax = B[C[sta]].first;       }     }     cout << maxx << endl;     if (coun != maxx) {       for (int i = smax; i < smax + maxx; i++) {         A[i] = 1;       }     }     for (int i = 0; i < n - 1; i++) {       cout << A[i] <<    ;     }     cout << A[n - 1] << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 ,  unroll-loops )   #pragma GCC target( avx2 )   using namespace std;   inline long long add(long long a, long long b) {     return ((a + b) < 1000000007 ? (a + b) : (a + b - 1000000007));   }   int prime[1000005];   void seive() {     prime[0] = prime[1] = 1;     for (int i = 2; i <= sqrt(1000005); i++) {       if (prime[i]) continue;       for (int j = 2 * i; j <= 1000005; j += i) {         prime[j] = 1;       }     }   }   inline long long sub(long long a, long long b) {     return ((a - b) < 0 ? a - b + 1000000007 : a - b);   }   long long power(long long a, long long b) {     if (b == 0) return 1;     long long y = power(a, b / 2);     y = (y * y) % 1000000007;     if (b & 1) y = (a * y) % 1000000007;     return y;   }   using namespace std;   int main() {     long long n;     cin >> n;     vector<long long> v;     long long fr = 0, tw = 0;     long long a[100005] = {0};     for (long long i = 0; i < n; i++) {       long long x;       cin >> x;       v.push_back(x);       a[x]++;       if (a[x] % 4 == 0) {         fr++;         tw--;       } else if (a[x] % 2 == 0) {         tw++;       }     }     long long q;     cin >> q;     for (long long i = 0; i < q; i++) {       char k;       cin >> k;       long long x;       cin >> x;       if (k ==  - ) {         if (a[x] % 4 == 0) {           fr--;           tw++;         } else if (a[x] % 2 == 0)           tw--;         a[x]--;       } else {         a[x]++;         if (a[x] % 4 == 0) {           fr++;           tw--;         } else if (a[x] % 2 == 0) {           tw++;         }       }       if (fr > 1 || (tw > 1 && fr == 1))         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   map<string, int> f, reff;   int n, m, q, w[13], ans[4097][101];   string s;   string tob(int x) {     string t =   ;     while (x > 0) {       x % 2 == 0 ? t =  0  + t : t =  1  + t;       x /= 2;     }     while (t.length() < n) {       t =  0  + t;     }     return t;   }   int tod(string x) {     int r = 0, v = 1;     for (int i = n - 1; i >= 0; i--) {       if (x[i] ==  1 ) r += v;       v *= 2;     }     return r;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> q;     for (int i = 0; i < n; i++) cin >> w[i];     while (m--) {       getline(cin >> ws, s);       f[s]++;     }     int maxnum = (1 << n) - 1;     for (int i = 0; i <= maxnum; i++) {       string tmp = tob(i);       map<string, int>::iterator j;       for (j = f.begin(); j != f.end(); j++) {         int v = 0;         for (int k = 0; k < n; k++)           if (tmp[k] == j->first[k]) v += w[k];         if (v <= 100) ans[i][v] += j->second;       }     }     for (int i = 0; i <= maxnum; i++)       for (int j = 1; j <= 100; j++) ans[i][j] += ans[i][j - 1];     while (q--) {       int kk;       cin >> ws >> s >> kk;       cout << ans[tod(s)][kk] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   int main(int agrc, char* argv[]) {     int N, M;     scanf( %d %d , &N, &M);     char room[625];     for (int i = 0; i < N * M; i++) scanf(  %c , room + i);     int dp[625];     for (int i = 0; i < M * M; i++) dp[i] = 0;     int best = 0;     for (int r = 0; r < N; r++) {       for (int pl = 0; pl < M; pl++)         for (int pr = pl; pr < M; pr++) {           bool free = true;           for (int i = pl; i <= pr && free; i++) free &= room[M * r + i] ==  0 ;           if (free) {             if (dp[pl * M + pr] == 0) {               dp[pl * M + pr] = 2 + 2 * (pr - pl + 1);             } else {               dp[pl * M + pr] += 2;             }           } else {             dp[pl * M + pr] = 0;           }         }       for (int i = 0; i < M * M; i++)         if (dp[i] > best) best = dp[i];     }     printf( %d n , best);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = (1LL << 60);   priority_queue<long long> pqr, pqc;   int sum_r[1005], sum_c[1005], k, p;   long long row[1000001], col[1000001];   void cal(int cnt, priority_queue<long long> pq, long long res[1000001]) {     long long ans = 0;     for (int i = 1; i <= k; i++) {       long long tmp = pq.top();       pq.pop();       pq.push(tmp - cnt * 1LL * p);       ans += tmp;       res[i] = ans;     }     res[0] = 0;   }   int main() {     int n, m;     scanf( %d%d%d%d , &n, &m, &k, &p);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         int tmp;         scanf( %d , &tmp);         sum_r[i] += tmp;         sum_c[j] += tmp;       }     }     for (int i = 0; i < n; i++) pqr.push(sum_r[i]);     for (int i = 0; i < m; i++) pqc.push(sum_c[i]);     cal(m, pqr, row);     cal(n, pqc, col);     long long ans = -INF;     for (int i = 0; i <= k; i++) {       long long tmp = row[i] + col[k - i] - i * 1LL * (k - i) * p;       if (tmp > ans) ans = tmp;     }     printf( %I64d n , ans);     return 0;   }


#include <iostream>   #include <cmath>   using namespace std;      int main() {    int t;    cin >> t;    while (t--) {     double n;     cin >> n;     if (sqrt(n / 2) == (int)sqrt(n / 2)) {      cout <<  YES n ;     }     else {      if (sqrt(n / 4) == (int)sqrt(n / 4)) {       cout <<  YES n ;      }      else cout <<  NO n ;     }    }   }


#include <bits/stdc++.h>   using namespace std;   bool cmp(int a, int b) { return a > b; }   int main() {     long long a[100005];     long long b[100005];     int n;     cin >> n;     long long sum = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i];       sum += a[i];     }     for (int i = 1; i <= n; i++) cin >> b[i];     if (n == 2) {       cout <<  YES  << endl;       return 0;     }     if (n == 1 || n == 0) {       cout <<  NO  << endl;       return 0;     }     sort(b + 1, b + n + 1, cmp);     if (b[1] + b[2] >= sum) {       cout <<  YES  << endl;     } else       cout <<  NO  << endl;   }


/*   Miles Morales : When will I know I m ready?   Peter B. Parker : You won t. It s a leap of faith. That s all it is, Miles. A leap of faith.   */   //KEEP IT SIMPLE STUPID      #include <bits/stdc++.h>      #pragma GCC optimize( O3 )   #pragma GCC target( avx )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )      #define ll long long   #define MP make_pair   #define ERR cout <<  ================================================ n    #define fi first   #define se second   #define PB push_back   #define all(x) (x).begin(), (x).end()   #define rall(x) (x).rbegin(), (x).rend()   #define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)   #define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)   #define ford(i, n) for (ll i = (ll)(n)-1; i >= 0; --i)   #define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)   #define print(v)                 for (auto x : v)             {                                cout << x <<    ;        }   #define umin(...) min({__VA_ARGS__})   #define umax(...) max({__VA_ARGS__})   #define MAX(v) *max_element(all(v))   #define MIN(v) *min_element(all(v))   #define SP <<     <<   #define W(t)         ll t;            cin >> t;        while (t--)   #define FIO                                  freopen( input.txt ,  r , stdin);        freopen( output.txt ,  w , stdout);   #define FAST                        ios::sync_with_stdio(0);        cin.tie(0);                     cout.tie(0);      using namespace std;      typedef pair<int, int> pii;   typedef vector<int> vi;   typedef vector<vi> vvi;   typedef vector<ll> vll;   typedef vector<vll> vvll;      const ll INF = 1e18;   const ll NEG_INF = -1 * (1e18);   using namespace std;      void usaco(string prob)   {       freopen((prob +  .in ).c_str(),  r , stdin);       freopen((prob +  .out ).c_str(),  w , stdout);   }      /* Function to check primality in O(sqrt(n)) */   bool prime(int n)   {       if (n < 2)           return false;       for (int x = 2; x * x <= n; x++)       {           if (n % x == 0)               return false;       }       return true;   }      /* Function to get prime factorization of n */   vector<int> getFactors(int n)   {       vector<int> f;       for (int x = 2; x * x <= n; x++)       {           while (n % x == 0)           {               f.push_back(x);               n /= x;           }       }       if (n > 1)           f.push_back(n);       return f;   }      void solve()   {       ll n;       cin >> n;       vll a(n);       forn(i, n) cin >> a[i];       ll r = n;       vll b(n + 1);       ll m = a[0];       for (ll k = 0; k < n; k++)       {           if (a[k] >= m)           {               b[k] = k;               m = a[k];           }           else           {               b[k] = b[k - 1];           }       }       while (r)       {           ll l = b[r - 1];              for (ll i = l; i < r; i++)           {               cout << a[i] <<    ;           }           r = l;       }       // forn(i, n)       // {       //     cout << b[i] <<    ;       // }       cout <<   n ;   }      int main()   {       //FIO       FAST              //usaco( cowlands );              ll TC = 1;       /*    Uncomment when multiple test cases    */          cin >> TC;       for1(tt, TC)       {           solve();       }       return 0;   }      /* stuff you should look for    * int overflow, array bounds    * special cases (n=1?)    * do smth instead of nothing and stay organized    * WRITE STUFF DOWN   */


#include <bits/stdc++.h>   using namespace std;   const int N = 2004;   int dp[N], dq[N], a[N], n;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) {       dp[i] = 1;       for (int j = 1; j < i; j++)         if (a[i] >= a[j]) dp[i] = max(dp[i], dp[j] + 1);     }     for (int i = n; i >= 1; i--) {       dq[i] = 1;       for (int j = n; j > i; j--)         if (a[i] <= a[j]) dq[i] = max(dq[i], dq[j] + 1);     }     int ans = dp[n];     for (int i = 1; i <= n; i++) ans = max(ans, dp[i] + dq[i + 1]);     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 3.14159265358979323846;   const double eps = (1e-9);   int dcmp(double x, double y) { return fabs(x - y) <= eps ? 0 : x < y ? -1 : 1; }   int n, m;   int mem[200000];   int minMoves(int x) {     if (x == m) return 0;     int& ret = mem[x];     if (ret != -1) return ret;     ret = (1 << 20);     if (x < m) ret = min(ret, 1 + minMoves(x * 2));     if (x > 1) ret = min(ret, 1 + minMoves(x - 1));     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     memset(mem, -1, sizeof(mem));     cin >> n >> m;     cout << minMoves(n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, f, k;     cin >> a >> b >> f >> k;     int now = b;     int ret = 0;     for (int i = 1; i <= k; i++) {       if (i % 2 == 1) {         if (now < f) {           return puts( -1 ), 0;         }         if (i == k) {           if (now < a) {             ret++;           }           if (b < a - f) {             return puts( -1 ), 0;           }         } else {           if (now < a + a - f) {             ret++;             now = b - (a - f);           } else {             now = now - a;           }         }       } else {         if (now < a - f) {           return puts( -1 ), 0;         }         if (i == k) {           if (now < a) {             ret++;           }           if (b < f) {             return puts( -1 ), 0;           }         } else {           if (now < a + f) {             ret++;             now = b - f;           } else {             now = now - a;           }         }       }     }     cout << ret << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef struct SPoint {     double X, Y;     SPoint(double X = 0, double Y = 0) : X(X), Y(Y) {}     double abs() { return sqrt(X * X + Y * Y); }     double sqrAbs() { return X * X + Y * Y; }   } TPoint;   TPoint operator-(const TPoint& shl, const TPoint& shr) {     return TPoint(shl.X - shr.X, shl.Y - shr.Y);   }   istream& operator>>(istream& is, TPoint& getPoint) {     return is >> getPoint.X >> getPoint.Y;   }   const int MAX_POINT = 5;   const double ESP = 1e-8;   double squareOfRect;   TPoint outRect[MAX_POINT], inRect[MAX_POINT];   double squareOf(const TPoint& A, const TPoint& B, const TPoint& C) {     double a = (B - C).abs();     double b = (C - A).abs();     double c = (A - B).abs();     double p = (a + b + c) / 2;     return sqrt(p * (p - a) * (p - b) * (p - c));   }   bool inSide(const TPoint& checkPoint) {     double minX = 100, minY = 100, maxX = -100, maxY = -100;     for (int i = 1; i <= 4; ++i) minX = min(minX, outRect[i].X);     for (int i = 1; i <= 4; ++i) minY = min(minY, outRect[i].Y);     for (int i = 1; i <= 4; ++i) maxX = max(maxX, outRect[i].X);     for (int i = 1; i <= 4; ++i) maxY = max(maxY, outRect[i].Y);     if (checkPoint.X < minX || checkPoint.X > maxX || checkPoint.Y < minY ||         checkPoint.Y > maxY)       return false;     double square = 0;     for (int i = 1; i <= 4; ++i)       square += squareOf(checkPoint, outRect[i], outRect[i - 1]);     return abs(square - squareOfRect) < ESP;   }   void checker() {     outRect[0] = outRect[4];     squareOfRect = (outRect[0] - outRect[1]).sqrAbs();     for (int i = 1; i <= 4; ++i)       if (inSide(inRect[i])) cout <<  YES n , exit(0);     TPoint center((inRect[1].X + inRect[3].X) / 2,                   (inRect[1].Y + inRect[3].Y) / 2);     if (inSide(center)) cout <<  YES n , exit(0);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     for (int i = 1; i <= 4; ++i) cin >> outRect[i];     for (int i = 1; i <= 4; ++i) cin >> inRect[i];     checker();     swap(inRect, outRect);     checker();     cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 7;   int a[MAXN], n, p, lim = 0;   bool check(int val) {     for (int i = 1; i <= n; ++i)       if (val + i - 1 < a[i]) return 0;     return 1;   }   bool valid(int val) {     int sta = 0;     for (int i = 0; i < n; ++i) {       while (sta + 1 <= n && val + i >= a[sta + 1]) ++sta;       if (sta - i >= p) return 0;     }     return 1;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> p;     for (int i = 1; i <= n; ++i) cin >> a[i], lim = max(lim, a[i]);     sort(a + 1, a + 1 + n);     int l = 0, r = lim, sta = -1;     while (l <= r) {       int mid = (l + r) >> 1;       if (check(mid))         sta = mid, r = mid - 1;       else         l = mid + 1;     }     l = sta, r = lim;     int fin = sta - 1;     while (l <= r) {       int mid = (l + r) >> 1;       if (valid(mid))         fin = mid, l = mid + 1;       else         r = mid - 1;     }     cout << fin - sta + 1 <<   n ;     for (int i = sta; i <= fin; ++i) cout << i <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     long long p = 1000000000;     vector<int> a;     a.resize(n);     long long fib[100];     fib[0] = 1;     fib[1] = 1;     for (long long i = 2; i < 100; i++) fib[i] = (fib[i - 1] + fib[i - 2]) % p;     for (int i = 0; i < n; i++) cin >> a[i];     long long t, x, y;     for (int i = 0; i < m; i++) {       cin >> t >> x >> y;       if (t == 1) {         x--;         a[x] = y;       } else {         x--;         y--;         long long res = 0;         for (long long j = 0; j + x <= y; j++) {           res += a[x + j] * fib[j];           res = res % p;         }         cout << res << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a;     cin >> n;     long long arr[n], sum[n], ans[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];       sum[i] = arr[i];       if (i > 0) sum[i] += sum[i - 1];     }     sort(arr, arr + n);     for (int i = 0; i < n; i++) {       ans[i] = arr[i];       if (i > 0) ans[i] += ans[i - 1];     }     int m;     cin >> m;     for (int i = 0; i < m; i++) {       int a, b, c;       cin >> a >> b >> c;       b--;       c--;       if (a == 1) {         if (b != 0) {           cout << (sum[c] - sum[b - 1]) << endl;         } else           cout << sum[c] << endl;       } else {         if (b != 0) {           cout << (ans[c] - ans[b - 1]) << endl;         } else           cout << ans[c] << endl;       }     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   class BigInt {    public:     int sign;     string s;     BigInt() : s(  ) {}     BigInt(string x) { *this = x; }     BigInt(int x) { *this = to_string(x); }     BigInt negative() {       BigInt x = *this;       x.sign *= -1;       return x;     }     BigInt normalize(int newSign) {       for (int a = s.size() - 1; a > 0 && s[a] ==  0 ; a--)         s.erase(s.begin() + a);       sign = (s.size() == 1 && s[0] ==  0  ? 1 : newSign);       return *this;     }     void operator=(string x) {       int newSign = (x[0] ==  -  ? -1 : 1);       s = (newSign == -1 ? x.substr(1) : x);       reverse(s.begin(), s.end());       this->normalize(newSign);     }     bool operator==(const BigInt& x) const {       return (s == x.s && sign == x.sign);     }     bool operator<(const BigInt& x) const {       if (sign != x.sign) return sign < x.sign;       if (s.size() != x.s.size())         return (sign == 1 ? s.size() < x.s.size() : s.size() > x.s.size());       for (int a = s.size() - 1; a >= 0; a--)         if (s[a] != x.s[a]) return (sign == 1 ? s[a] < x.s[a] : s[a] > x.s[a]);       return false;     }     bool operator<=(const BigInt& x) const { return (*this < x || *this == x); }     bool operator>(const BigInt& x) const {       return (!(*this < x) && !(*this == x));     }     bool operator>=(const BigInt& x) const { return (*this > x || *this == x); }     BigInt operator+(BigInt x) {       BigInt curr = *this;       if (curr.sign != x.sign) return curr - x.negative();       BigInt res;       for (int a = 0, carry = 0; a < s.size() || a < x.s.size() || carry; a++) {         carry += (a < curr.s.size() ? curr.s[a] -  0  : 0) +                  (a < x.s.size() ? x.s[a] -  0  : 0);         res.s += (carry % 10 +  0 );         carry /= 10;       }       return res.normalize(sign);     }     BigInt operator-(BigInt x) {       BigInt curr = *this;       if (curr.sign != x.sign) return curr + x.negative();       int realSign = curr.sign;       curr.sign = x.sign = 1;       if (curr < x) return ((x - curr).negative()).normalize(-realSign);       BigInt res;       for (int a = 0, borrow = 0; a < s.size(); a++) {         borrow = (curr.s[a] - borrow - (a < x.s.size() ? x.s[a] :  0 ));         res.s += (borrow >= 0 ? borrow +  0  : borrow +  0  + 10);         borrow = (borrow >= 0 ? 0 : 1);       }       return res.normalize(realSign);     }     BigInt operator*(BigInt x) {       BigInt res( 0 );       for (int a = 0, b = s[a] -  0 ; a < s.size(); a++, b = s[a] -  0 ) {         while (b--) res = (res + x);         x.s.insert(x.s.begin(),  0 );       }       return res.normalize(sign * x.sign);     }     BigInt operator/(BigInt x) {       if (x.s.size() == 1 && x.s[0] ==  0 ) x.s[0] /= (x.s[0] -  0 );       BigInt temp( 0 ), res;       for (int a = 0; a < s.size(); a++) res.s +=  0 ;       int newSign = sign * x.sign;       x.sign = 1;       for (int a = s.size() - 1; a >= 0; a--) {         temp.s.insert(temp.s.begin(),  0 );         temp = temp + s.substr(a, 1);         while (!(temp < x)) {           temp = temp - x;           res.s[a]++;         }       }       return res.normalize(newSign);     }     BigInt operator%(BigInt x) {       if (x.s.size() == 1 && x.s[0] ==  0 ) x.s[0] /= (x.s[0] -  0 );       BigInt res( 0 );       x.sign = 1;       for (int a = s.size() - 1; a >= 0; a--) {         res.s.insert(res.s.begin(),  0 );         res = res + s.substr(a, 1);         while (!(res < x)) res = res - x;       }       return res.normalize(sign);     }     string toString() const {       string ret = s;       reverse(ret.begin(), ret.end());       return (sign == -1 ?  -  :   ) + ret;     }     BigInt toBase10(int base) {       BigInt exp(1), res( 0 ), BASE(base);       for (int a = 0; a < s.size(); a++) {         int curr = (s[a] <  0  || s[a] >  9  ? (toupper(s[a]) -  A  + 10)                                              : (s[a] -  0 ));         res = res + (exp * BigInt(curr));         exp = exp * BASE;       }       return res.normalize(sign);     }     BigInt toBase10(int base, BigInt mod) {       BigInt exp(1), res( 0 ), BASE(base);       for (int a = 0; a < s.size(); a++) {         int curr = (s[a] <  0  || s[a] >  9  ? (toupper(s[a]) -  A  + 10)                                              : (s[a] -  0 ));         res = (res + ((exp * BigInt(curr) % mod)) % mod);         exp = ((exp * BASE) % mod);       }       return res.normalize(sign);     }     string convertToBase(int base) {       BigInt ZERO(0), BASE(base), x = *this;       string modes =  0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ ;       if (x == ZERO) return  0 ;       string res =   ;       while (x > ZERO) {         BigInt mod = x % BASE;         x = x - mod;         if (x > ZERO) x = x / BASE;         res = modes[stoi(mod.toString())] + res;       }       return res;     }     BigInt toBase(int base) { return BigInt(this->convertToBase(base)); }     friend ostream& operator<<(ostream& os, const BigInt& x) {       os << x.toString();       return os;     }   };   const double EPS = (1e-5);   int dcmp(double a, double b) { return fabs(a - b) <= EPS ? 0 : a < b ? -1 : 1; }   struct line {     double a, b, c;   };   long long binpowmod(long long a, long long b, long long m) {     a %= m;     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res;   }   long long binpow(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a;       a = a * a;       b >>= 1;     }     return res;   }   int findXOR(int n) {     switch (n % 4) {       case 0:         return n;       case 1:         return 1;       case 2:         return n + 1;       case 3:         return 0;     }   }   int rangeXOR(int l, int r) { return (findXOR(l - 1) ^ findXOR(r)); }   int getbit(int mask, int bit) { return (mask & (1 << bit)); }   void setbit(int& mask, int bit, int val) {     if (val)       mask |= (1 << bit);     else       mask &= ~(1 << bit);   }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   const int N = 1e5 + 10;   const int M = 500 + 10;   const int MOD = 998244353;   const long long INF = 1e15 + 100;   void solve() {     int n;     cin >> n;     vector<int> cnt(1e5 + 1);     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       vector<int> divisors;       int mx = 0;       for (int i = 1; i * i <= x; ++i) {         if (x % i == 0) {           if (i != 1) {             mx = max(mx, cnt[i] + 1);             divisors.push_back(i);           }           if (x / i != i) {             mx = max(mx, cnt[x / i] + 1);             divisors.push_back(x / i);           }         }       }       for (int i = 0; i < (int)divisors.size(); ++i) cnt[divisors[i]] = mx;     }     int ans = *max_element(cnt.begin(), cnt.end());     cout << max(1, ans) <<   n ;   }   int main(void) {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int tc = 1;     while (tc--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int ans, n, m;     cin >> n >> m;     ans = (n * m) / 2;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   const double PI = acos(-1.0);   const double e = exp(1.0);   const int INF = 0x7fffffff;   ;   template <class T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <class T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <class T>   inline T Min(T a, T b) {     return a < b ? a : b;   }   template <class T>   inline T Max(T a, T b) {     return a > b ? a : b;   }   bool cmpbig(int a, int b) { return a > b; }   bool cmpsmall(int a, int b) { return a < b; }   using namespace std;   int cnt, n;   int vis_line[110];   int vis[110][3];   void dfs(int j, int pos) {     if (j >= 3) {       cnt = min(cnt, pos);       return;     }     if (pos >= cnt) return;     for (int i = 0; i < n; i++) {       if (!vis_line[i]) {         vis_line[i] = 1;         dfs(j + 1, pos + vis[i][j]);         vis_line[i] = 0;       }     }   }   int main() {     int m;     while (~scanf( %d%d , &n, &m)) {       char str[110][110];       int i, j;       memset(vis, 9999, sizeof(vis));       memset(vis_line, 0, sizeof(vis_line));       for (i = 0; i < n; i++) {         scanf( %s , str[i]);         for (j = 0; j < m; j++) {           if (str[i][j] >=  a  && str[i][j] <=  z )             vis[i][0] = min(vis[i][0], min(j, m - j));           else if (str[i][j] <=  9  && str[i][j] >=  0 )             vis[i][1] = min(vis[i][1], min(j, m - j));           else             vis[i][2] = min(vis[i][2], min(j, m - j));         }       }       cnt = INF;       dfs(0, 0);       printf( %d n , cnt);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct edge {     long long a, b, index;     long long u, v;   };   bool compare(edge i, edge j) {     if (i.a == j.a) return i.b > j.b;     return i.a < j.a;   }   bool compare2(edge i, edge j) { return i.index < j.index; }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, m;     cin >> n >> m;     edge a[m];     for (long long i = 0; i < m; i++) {       cin >> a[i].a >> a[i].b;       a[i].index = i;     }     long long suc = 0, unsuc = 0;     sort(a, a + m, compare);     long long u1 = 2, v1 = 3;     for (long long i = 0; i < m; i++) {       if (a[i].b == 1) {         a[i].u = 1;         a[i].v = suc + 2;         suc++;       } else {         unsuc++;         long long edges = ((suc + 1) * (suc)) / 2 - (suc);         if (edges < unsuc) {           cout << -1 <<   n ;           return 0;         }         a[i].u = u1;         a[i].v = v1;         if (u1 + 1 == v1) {           u1 = 2;           v1++;         } else {           u1++;         }       }     }     sort(a, a + m, compare2);     for (long long i = 0; i < m; i++) cout << a[i].u <<     << a[i].v <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1086;   const int MAXT = 1586;   const long long R = 1000000;   struct query {     long long ts, tl;     long double ss, sl, p;     query() {}     query(long double _ss, long double _sl, long long _ts, long long _tl,           long double _p)         : ss(_ss), sl(_sl), ts(_ts), tl(_tl), p(_p) {}     void init() {       cin >> ss >> sl >> ts >> tl >> p;       ss *= R, sl *= R;     }   } Q[MAXN];   pair<long double, long double> dp[MAXN][MAXT];   inline bool cmp(const query &a, const query &b) {     return a.tl * (1 - b.p) * a.p < b.tl * (1 - a.p) * b.p;   }   void update(pair<long double, long double> &a,               pair<long double, long double> b) {     if (b.first > a.first || a.first == b.first && a.second > b.second) a = b;   }   int main() {     int i, j;     int m, n;     scanf( %d%d , &n, &m);     for (i = 0; i < n; ++i) Q[i].init();     sort(Q, Q + n, cmp);     for (i = 0; i < n; ++i)       for (j = 0; j <= m; ++j) dp[i][j].first = dp[i][j].second = -1;     dp[0][0].first = dp[0][0].second = 0;     for (i = 0; i < n; ++i) {       long long ts = Q[i].ts, tl = Q[i].tl;       long double ss = Q[i].ss, sl = Q[i].sl, p = Q[i].p;       for (j = 0; j <= m; ++j)         if (dp[i][j].first != -1) {           long double cs = dp[i][j].first, cp = dp[i][j].second;           update(dp[i + 1][j], dp[i][j]);           if (j + ts <= m)             update(dp[i + 1][j + ts],                    pair<long double, long double>(cs + ss, cp + ts));           if (j + ts + tl <= m)             update(dp[i + 1][j + ts + tl],                    pair<long double, long double>(                        cs + ss + (1 - p) * sl, ts + (j + tl) * (1 - p) + p * cp));         }     }     pair<long double, long double> res(0, 0);     for (i = 0; i <= m; ++i) update(res, dp[n][i]);     cout << setprecision(20) << res.first / R <<     << res.second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, d;     cin >> n;     unordered_set<int> s;     int mx = n;     int c = 0;     for (int i = 0; i < n; i++) {       cin >> d;       if (d == mx) {         for (int i = 0; i < c; i++) cout <<   n ;         cout << mx;         c = 0;         int k = mx - 1;         while (s.find(k) != s.end()) {           cout <<     << k;           s.erase(k);           k--;         }         cout <<   n ;         mx = k;       } else {         s.insert(d);         c++;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double n, h;   char c[10];   double ans;   double ksm(double x, long long y) {     double maretu = 1.0;     for (; y; y >>= 1) {       if (y & 1) {         maretu *= x;       }       x *= x;     }     return maretu;   }   int main() {     scanf( %s , c);     if (c[0] ==  A ) {       scanf( %lf%lf , &n, &h);       ans = n;       for (double i = 1; i <= h; ++i) {         for (double j = 1; j <= n; ++j) {           ans +=               (n - j) * (1.0 / (double)(1LL << (long long)(2 * i))) *               ksm(1.0 - (1.0 / (double)(1LL << (long long)i)),                   (long long)(j - 1.0)) *               ((double)(1LL << ((long long)i)) -                (double)(1LL << (long long)(i - 1)) *                    (1.0 + (j - 1.0) / ((double)(1LL << (long long)(i)) - 1.0)));         }       }       printf( %.10lf , ans);     } else {       scanf( %lf%lf , &n, &h);       printf( %lf , n);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxm = 2e5 + 5;   vector<long long> g[maxm];   long long mark[maxm];   long long p[maxm];   long long c[maxm];   long long ans;   long long n;   void solve(long long x) {     vector<long long> s;     while (!mark[x]) {       s.push_back(x);       mark[x] = 1;       x = p[x];     }     long long len = s.size();     for (long long i = 1; i <= len; i++) {       if (len % i == 0) {         for (long long j = 0; j < i; j++) {           long long ok = 1;           for (long long k = j; k + i < len; k += i) {             if (c[s[k]] != c[s[k + i]]) {               ok = 0;               break;             }           }           if (ok) {             ans = min(ans, i);             return;           }         }       }     }   }   signed main() {     long long T;     cin >> T;     while (T--) {       cin >> n;       ans = n;       for (long long i = 1; i <= n; i++) cin >> p[i];       for (long long i = 1; i <= n; i++) cin >> c[i];       for (long long i = 1; i <= n; i++) mark[i] = 0;       for (long long i = 1; i <= n; i++)         if (!mark[i]) solve(i);       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = s.size();     int pref = 0;     int kol = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  # ) kol++;       if (s[i] ==  ( )         pref++;       else         pref--;       if (pref < 0) {         cout <<  -1 ;         return 0;       }     }     string t;     int sz = 0;     int r = 0;     while (sz < kol) {       if (s[r] ==  # ) {         sz++;         t +=  ) ;         if (sz == kol) {           for (int j = 0; j < pref; j++) t +=  ) ;         }       } else {         t += s[r];       }       r++;     }     while (r < n) {       t += s[r];       r++;     }     n = t.size();     int preff = 0;     for (int i = 0; i < n; i++) {       if (t[i] ==  ( )         preff++;       else         preff--;       if (preff < 0) {         cout <<  -1 ;         return 0;       }     }     for (int i = 0; i < kol - 1; i++) {       cout << 1 << endl;     }     cout << pref + 1;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, long long> dist;   int main() {     long long n, m;     cin >> n >> m;     long long x;     queue<long long> q;     for (long long i = 0; i < n; i++) {       cin >> x;       dist[x] = 0;       q.push(x);     }     long long total = 0;     vector<long long> ans;     while (!q.empty()) {       x = q.front();       q.pop();       if (dist[x] != 0) {         ans.push_back(x);         total += (dist[x]);         if (ans.size() == m) break;       }       if (dist.find(x - 1) == dist.end()) {         q.push(x - 1);         dist[x - 1] = dist[x] + 1;       }       if (dist.find(x + 1) == dist.end()) {         q.push(x + 1);         dist[x + 1] = dist[x] + 1;       }     }     cout << total <<   n ;     for (long long i = 0; i < ans.size(); i++) {       cout << ans[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class qry {    public:     int l, r, idx;     qry(int l, int r, int idx) : l(l), r(r), idx(idx) {}   };   int a[500001], n, m, res[500001];   vector<qry> q;   int getans(vector<int> b) {     int res = 0;     for (int i = 0; i < b.size(); i++) {       if ((res ^ b[i]) > res) res ^= b[i];     }     return res;   }   void ins(vector<int>& b, int x) {     for (int i = 0; i < b.size(); i++) {       if ((b[i] ^ x) < x) x ^= b[i];     }     if (!x) return;     int t = 31 - __builtin_clz(x);     for (int i = 0; i < b.size(); i++) {       if (b[i] & (1 << t)) b[i] ^= x;     }     b.push_back(x);   }   vector<int> merge(vector<int>& a, vector<int>& b) {     vector<int> ret = a;     for (int i = 0; i < b.size(); i++) ins(ret, b[i]);     return ret;   }   void solve(vector<qry>& q, int L, int R) {     if (q.empty()) return;     if (q.size() <= 3 || R - L <= 3) {       for (int i = 0; i < q.size(); i++) {         int l = q[i].l, r = q[i].r;         vector<int> bs;         for (int j = l; j <= r; j++) ins(bs, a[j]);         res[q[i].idx] = getans(bs);       }       return;     }     vector<qry> l, r, my;     int mid = (L + R) / 2;     for (int i = 0; i < q.size(); i++) {       if (q[i].r <= mid)         l.push_back(q[i]);       else if (q[i].l >= mid + 1)         r.push_back(q[i]);       else         my.push_back(q[i]);     }     solve(l, L, mid);     solve(r, mid + 1, R);     sort(my.begin(), my.end(), [](const qry& i, const qry& j) {       if (i.l != j.l)         return i.l > j.l;       else         return i.r < j.r;     });     vector<int> lb;     int cur = 0, pt = mid;     vector<vector<int> > rb;     vector<int> t;     for (int i = mid + 1; i <= R; i++) {       ins(t, a[i]);       rb.push_back(t);     }     while (cur < my.size()) {       bool found = false;       while (my[cur].l <= pt) {         found = true;         ins(lb, a[pt--]);       }       res[my[cur].idx] = getans(merge(lb, rb[my[cur].r - mid - 1]));       cur++;     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       int l, r;       scanf( %d %d , &l, &r);       q.push_back(qry(l, r, i));     }     solve(q, 1, n);     for (int i = 1; i <= m; i++) printf( %d n , res[i]);     return 0;   }


#include <bits/stdc++.h>   int main(int argc, const char* argv[]) {     int n, k;     scanf( %d%d , &n, &k);     if (k > n / 2) k = n / 2;     printf( %I64d n , k * (2 * n - 2 * k - 1ll));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1005, MAXM = 200005;   int n, m, q, f[MAXN][MAXN], head[MAXM], nxt[MAXM], x[MAXM], y[MAXM];   struct Q {     int l, r, s, t;   } s[MAXM];   bool ans[MAXM];   int main() {     scanf( %d%d%d , &n, &m, &q);     for (register int i = 1; i <= m; ++i) scanf( %d%d , x + i, y + i);     for (register int i = 1; i <= q; ++i) {       scanf( %d%d%d%d , &s[i].l, &s[i].r, &s[i].s, &s[i].t);       nxt[i] = head[s[i].r];       head[s[i].r] = i;     }     for (register int u, v, k = 1; k <= m; ++k) {       u = x[k];       v = y[k];       f[u][v] = f[v][u] = k;       for (register int i = 1; i <= n; ++i)         f[u][i] = f[v][i] = max(f[u][i], f[v][i]);       for (register int i = head[k]; i; i = nxt[i])         ans[i] = s[i].l <= f[s[i].t][s[i].s];     }     for (register int i = 1; i <= q; ++i) puts(ans[i] ?  Yes  :  No );   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9;   const long long int INF = (long long int)1e18;   const int N = 100005;   const long long int MOD = 1000000007;   const double EPS = 1e-7;   const double PI = acos(-1.0);   const int dx[] = {+1, -1, +0, +0};   const int dy[] = {+0, +0, +1, -1};   const int hx[] = {-2, -2, -1, -1, +1, +1, +2, +2};   const int hy[] = {+1, -1, +2, -2, +2, -2, +1, -1};   const int fx[] = {-1, +0, +1, +0, +1, +1, -1, -1, +0};   const int fy[] = {+0, -1, +0, +1, +1, -1, +1, -1, +0};   template <typename T>   inline T GCD(T a, T b) {     a = abs(a), b = abs(b);     return !b ? a : GCD(b, a % b);   }   template <typename T>   inline T LCM(T x, T y) {     T g = GCD(x, y);     return x * y / g;   }   template <typename T>   inline T BigMod(T b, T p, T mod) {     T res = 1 % mod, x = b % mod;     while (p) {       if (p & 1) res = (res * x) % mod;       x = (x * x) % mod;       p >>= 1;     }     return res;   }   template <typename T>   inline T ModInv(T val, T mod) {     return BigMod(val, mod - 2, mod);   }   template <typename T>   inline T bigmod(T b, T p, T mod) {     if (p == 0) return 1;     T x = bigmod(b, p / 2, mod);     x = (x * x) % mod;     if (p % 2 == 1) x = (b * x) % mod;     return x;   }   template <typename T>   inline T NumDigit(T num, T base) {     return ((T)(log10((num)) / log10((base)))) + 1;   }   template <typename T>   inline T Power(T b, T p) {     T res = 1, x = b;     while (p) {       if (p & 1) res = (res * x);       x = (x * x);       p >>= 1;     }     return res;   }   template <typename T>   inline T IsPrime(T x) {     if (x < 2) return false;     for (T i = 2; i * i <= x; i++) {       if (x % i == 0) return false;     }     return true;   }   template <typename T>   inline T SumDigit(T x) {     T ret = 0;     while (x) {       ret += x % 10, x /= 10;     }     return ret;   }   int main(int argc, char const *argv[]) {     int n;     scanf( %d , &n);     for (int i = 0; i * 4 <= n; i++) {       for (int j = 0; i * 4 + j * 7 <= n; j++) {         if (4 * i + j * 7 == n) {           for (int m = 1; m <= i; m++) printf( 4 );           for (int m = 1; m <= j; m++) printf( 7 );           return 0;         }       }     }     printf( -1 n );     return 0;   }