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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


#include <bits/stdc++.h> n using namespace std; n const int M = 5555; n const int N = 205; n int col[2][M][N]; n void dfs(int p, int x, int y, int c0, int c1) { n   int t = col[p ^ 1][y][c0]; n   col[p][x][c0] = y; n   col[p ^ 1][y][c0] = x; n   if (!t) { n     col[p ^ 1][y][c1] = 0; n     return; n   } n   dfs(p ^ 1, y, t, c1, c0); n } n int n, m, k, s; n int sz[2][N], id[2][N]; n int Id[M][M], ans[M]; n int main() { n   scanf( %d%d%d%d , &n, &m, &k, &s); n   if (s == 1) { n     puts( 0 ); n     for (int i = (int)(1); i <= (int)(k); i++) printf( 1  ); n     return 0; n   } n   int nd = 0, mx = 0; n   for (int i = (int)(1); i <= (int)(n); i++) sz[0][i] = s; n   for (int i = (int)(1); i <= (int)(m); i++) sz[1][i] = s; n   for (int i = (int)(1); i <= (int)(k); i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     if (sz[0][x] == s) sz[0][x] = 0, id[0][x] = ++nd; n     sz[0][x]++; n     x = id[0][x]; n     if (sz[1][y] == s) sz[1][y] = 0, id[1][y] = ++nd; n     sz[1][y]++; n     y = id[1][y]; n     Id[x][y] = i; n     int c0 = 1, c1 = 1; n     for (; col[0][x][c0]; c0++) n       ; n     for (; col[1][y][c1]; c1++) n       ; n     mx = max(mx, max(c0, c1)); n     if (c0 == c1) { n       col[0][x][c0] = y; n       col[1][y][c0] = x; n     } else n       dfs(0, x, y, c0, c1); n   } n   int mn = 0; n   for (int i = (int)(1); i <= (int)(n); i++) mn += (sz[0][i] != s); n   for (int i = (int)(1); i <= (int)(m); i++) mn += (sz[1][i] != s); n   printf( %d n , mn); n   for (int i = (int)(1); i <= (int)(nd); i++) n     for (int j = (int)(1); j <= (int)(mx); j++) n       if (col[0][i][j]) ans[Id[i][col[0][i][j]]] = j; n   for (int i = (int)(1); i <= (int)(k); i++) printf( %d  , ans[i]); n } n


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


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


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


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


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


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


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


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


#include <bits/stdc++.h> n using namespace std; n bool a[2][100010]; n int n, q, nr, x, y; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> q; n   for (int i = 1; i <= q; i++) { n     cin >> x >> y; n     x--; n     if (a[x][y]) n       nr -= a[(x + 1) % 2][y - 1] + a[(x + 1) % 2][y] + a[(x + 1) % 2][y + 1], n           a[x][y] = 0; n     else n       nr += a[(x + 1) % 2][y - 1] + a[(x + 1) % 2][y] + a[(x + 1) % 2][y + 1], n           a[x][y] = 1; n     if (!nr) n       cout <<  YES n ; n     else n       cout <<  NO n ; n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, t, cont[8] = {0}, i; n   cin >> n; n   for (int i = 0; i < n && cin >> t; i++) cont[t]++; n   if (cont[1] != n / 3 || cont[5] + cont[7] || cont[4] > cont[2] || n       cont[3] > cont[6] || cont[2] + cont[3] != cont[4] + cont[6]) n     cout << -1; n   else { n     for (i = 0; i < cont[3]; i++) cout << 1 <<     << 3 <<     << 6 << endl; n     for (i = 0; i < cont[4]; i++) cout << 1 <<     << 2 <<     << 4 << endl; n     for (i = 0; i < cont[2] - cont[4]; i++) n       cout << 1 <<     << 2 <<     << 6 << endl; n   } n   return 0; n } n


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


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


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


#include <bits/stdc++.h> n using namespace std; n int n, A, B; n long long toi(string s) { n   istringstream is(s); n   long long x; n   is >> x; n   return x; n } n string tos(long long t) { n   stringstream st; n   st << t; n   return st.str(); n } n long long F[1000005], FP[1000005]; n bool f(long long x) { n   while (x > 0) { n     if (x % 10 != A && x % 10 != B) return 0; n     x /= 10; n   } n   return 1; n } n long long pow(long long a, long long b, long long c) { n   long long x = 1, y = a; n   while (b > 0) { n     if (b & 1) x = (x * y) % c; n     y = (y * y) % c; n     b >>= 1; n   } n   return x; n } n int main() { n   F[0] = 1; n   for (int i = 1; i < 1000005; ++i) { n     F[i] = i * F[i - 1]; n     if (F[i] >= 1000000007) F[i] %= 1000000007; n   } n   FP[1000005 - 1] = pow(F[1000005 - 1], 1000000007 - 2, 1000000007); n   for (int i = 1000005 - 2; i >= 0; --i) { n     FP[i] = FP[i + 1] * (i + 1); n     if (FP[i] >= 1000000007) FP[i] %= 1000000007; n   } n   while (cin >> A >> B >> n) { n     long long cnt = 0; n     for (int i = 0; i <= n; ++i) n       if (f(i * A + (n - i) * B)) { n         long long num = F[n], den = FP[i] * FP[n - i]; n         if (den >= 1000000007) den %= 1000000007; n         num *= den; n         if (num >= 1000000007) num %= 1000000007; n         cnt += num; n         if (cnt >= 1000000007) cnt -= 1000000007; n       } n     cout << cnt << endl; n   } n } n


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


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


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


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


#include <bits/stdc++.h> n using namespace std; n set<int> E[100005]; n vector<int> L[100005]; n int True = 0; n int vst[100005]; n int main() { n   int n, m, h, t, i, u, v, _h, _t, j, k; n   cin >> n >> m >> h >> t; n   for (i = 0; i < (m); i++) { n     scanf( %d%d , &u, &v); n     L[u].push_back(v); n     L[v].push_back(u); n     E[u].insert(v); n     E[v].insert(u); n   } n   for (i = (1); i <= (n); i++) { n     u = i; n     if (((int)(E[u]).size()) < h + 1) continue; n     for (j = 0; j < (((int)(L[i]).size())); j++) { n       v = L[i][j]; n       if (((int)(E[u]).size()) + ((int)(E[v]).size()) < h + t + 2) continue; n       if (((int)(E[v]).size()) < t + 1) continue; n       bool sp = 0; n       if (((int)(E[u]).size()) > ((int)(E[v]).size())) { n         swap(u, v); n         sp = 1; n       } n       set<int>::iterator it = E[u].begin(); n       _h = 0; n       vector<int> cmn; n       True++; n       for (k = 0; k < (((int)(L[u]).size())); k++) vst[L[u][k]] = True; n       for (k = 0; k < (((int)(L[v]).size())); k++) { n         if (vst[L[v][k]] == True) { n           _h++; n           cmn.push_back(L[v][k]); n         } n       } n       if (sp) swap(u, v); n       if (((int)(E[u]).size()) + ((int)(E[v]).size()) - _h < h + t + 2) n         continue; n       printf( YES n ); n       printf( %d %d n , u, v); n       it = E[u].begin(); n       while (it != E[u].end()) { n         if (E[v].find(*it) == E[v].end()) { n           if (*it == v) { n             it++; n             continue; n           } n           h--; n           printf( %d  , *it); n         } n         if (!h) break; n         it++; n       } n       while (h--) { n         printf( %d  , cmn[((int)(cmn).size()) - 1]); n         cmn.pop_back(); n       } n       printf(  n ); n       it = E[v].begin(); n       while (it != E[v].end()) { n         if ((E[u].find(*it) == E[u].end())) { n           if (*it == u) { n             it++; n             continue; n           } n           t--; n           printf( %d  , *it); n         } n         if (!t) break; n         it++; n       } n       while (t--) { n         printf( %d  , cmn[((int)(cmn).size()) - 1]); n         cmn.pop_back(); n       } n       printf(  n ); n       return 0; n     } n   } n   printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const int mod2 = 1e9 + 9; n inline int pow_(long long a, int n, int p = mod) { n   int r = 1; n   while (n) { n     if (n & 1) r = r * a % p; n     n >>= 1; n     a = a * a % p; n   } n   return r; n } n int main(void) { n   int n, l; n   long long s; n   cin >> n >> l >> s; n   int w[n + 1], p[n + 1]; n   memset(p, 0, sizeof(p)); n   memset(w, 0, sizeof(w)); n   for (int i = 1; i <= n; i++) cin >> w[i]; n   for (int i = 2; i <= n; i++) cin >> p[i]; n   bool done[n + 1]; n   memset(done, false, sizeof(done)); n   for (int i = 1; i <= n; i++) n     if (w[i] > s) return 0 * printf( -1 n ); n   int ans = 0; n   for (int i = n; i >= 1; i--) { n     if (done[i]) continue; n     ans++; n     int cur = i; n     int L = l; n     long long S = s; n     while (cur and L > 0 and S >= w[cur]) { n       done[cur] = true; n       S -= w[cur]; n       L--; n       cur = p[cur]; n     } n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int x, y, n, m, i, k, ans; n string s[30], s1[30]; n int main() { n   cin >> n >> m; n   for (i = 0; i < n; i++) { n     cin >> s[i]; n   } n   for (i = 0; i < m; i++) { n     cin >> s1[i]; n   } n   cin >> k; n   for (i = 0; i < k; i++) { n     cin >> x; n     if (x % n == 0) n       cout << s[n - 1]; n     else n       cout << s[x % n - 1]; n     if (x % m == 0) n       cout << s1[m - 1]; n     else n       cout << s1[x % m - 1]; n     cout << endl; n   } n } n


#include <bits/stdc++.h> n const int MAXN = 1e9 + 7; n const int INF = 1e9 + 7; n const signed long long MOD = 1e9 + 7; n using namespace std; n bool comp1(signed long long a, signed long long b) { return (sin(a) < sin(b)); } n signed long long binpow(signed long long a, signed long long b) { n   signed long long res = 1; n   while (b) { n     if (b & 1) res = (res * a); n     a = (a * a); n     b >>= 1; n   } n   return res; n } n signed long long phi(signed long long n) { n   signed long long result = n; n   for (signed long long i = 2; i * i <= n; ++i) n     if (n % i == 0) { n       while (n % i == 0) n /= i; n       result -= result / i; n     } n   if (n > 1) result -= result / n; n   return result; n } n signed long long gcd(signed long long a, signed long long b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t; n   cin >> t; n   for (size_t jj = 0; jj < t; jj++) { n     signed long long n, k; n     cin >> n >> k; n     vector<signed long long> mas(n); n     signed long long mx = -1e9 - 47; n     for (size_t i = 0; i < n; i++) { n       cin >> mas[i]; n       mx = max(mx, mas[i]); n     } n     signed long long mx1 = -1e9 - 47; n     for (size_t i = 0; i < n; i++) { n       mas[i] = mx - mas[i]; n       mx1 = max(mx1, mas[i]); n     } n     k--; n     if (k % 2) { n       for (size_t i = 0; i < n; i++) { n         mas[i] = mx1 - mas[i]; n       } n     } n     for (size_t i = 0; i < n; i++) { n       cout << mas[i] <<    ; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<int, int> > ans; n bool is_prime(int v) { n   if (v == 1 || v == 0) return 0; n   for (int i = 2; i * i <= v; i++) { n     if (v % i == 0) return 0; n   } n   return 1; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long n; n   cin >> n; n   long long cnt = n - 1; n   ans.push_back(make_pair(n, 1)); n   for (int i = 2; i <= n; i++) { n     ans.push_back(make_pair(i, i - 1)); n   } n   for (int i = 1; i <= n / 2; i++) { n     if (is_prime(ans.size())) break; n     ans.push_back(make_pair(i, i + n / 2)); n     ++cnt; n   } n   cout << ans.size() << endl; n   for (int i = 0; i < ans.size(); i++) { n     cout << ans[i].first <<     << ans[i].second << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e9 + 7; n const int N = 3e5 + 10; n int flag[N]; n set<int> s[N]; n int a[N]; n int pos[N]; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     pos[a[i]] = i; n   } n   while (m--) { n     int x, y; n     scanf( %d%d , &x, &y); n     if (x == a[n]) continue; n     if (y == a[n]) { n       flag[x] = 1; n     } n     s[x].emplace(y); n   } n   int ans = n; n   for (int i = n - 1; i > 0; i--) { n     if (flag[a[i]]) { n       int cnt = 0; n       for (auto& x : s[a[i]]) { n         if (pos[x] < i) continue; n         if (pos[x] >= ans) continue; n         cnt++; n       } n       if (cnt != ans - i - 1) n         flag[a[i]] = 0; n       else { n         for (int j = i; j < ans; j++) { n           int x = a[j], y = a[j + 1]; n           swap(a[j], a[j + 1]); n           swap(pos[x], pos[y]); n         } n         ans--; n       } n     } n   } n   printf( %d n , n - ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rd(time(0)); n vector<long long> v(100010), val(100010), con[100010], st(100010, 0), n     en(100010, 0), d(100010, 0); n pair<long long, long long> t[20][100010]; n long long cur = 0; n void dfs(long long node, long long par, long long dep) { n   st[node] = ++cur; n   d[st[node]] = dep; n   for (auto i : con[node]) { n     if (i != par) dfs(i, node, dep + 1); n   } n   en[node] = cur; n } n void build(long long c, long long l, long long r) { n   if (l == r) n     t[c][l] = {d[l], val[l]}; n   else { n     long long mid = (l + r) / 2; n     build(c + 1, l, mid); n     build(c + 1, mid + 1, r); n     long long i = l, j = mid + 1, k = l; n     while (i <= mid && j <= r) { n       if (t[c + 1][i].first < t[c + 1][j].first) n         t[c][k++] = t[c + 1][i++]; n       else n         t[c][k++] = t[c + 1][j++]; n     } n     while (i <= mid) t[c][k++] = t[c + 1][i++]; n     while (j <= r) t[c][k++] = t[c + 1][j++]; n     for (i = l + 1; i <= r; i++) n       t[c][i].second = min(t[c][i].second, t[c][i - 1].second); n   } n } n long long query(long long c, long long l, long long r, long long l1, n                 long long r1, long long k) { n   if (r1 < l || l1 > r) return 1000000007; n   if (l >= l1 && r <= r1) { n     pair<long long, long long> temp = {k, 1000000007}; n     long long w = upper_bound(t[c] + l, t[c] + r + 1, temp) - (t[c]); n     if (w == l) return 1000000007; n     return t[c][w - 1].second; n   } else { n     long long mid = (l + r) / 2; n     return min(query(c + 1, l, mid, l1, r1, k), n                query(c + 1, mid + 1, r, l1, r1, k)); n   } n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, r, m, l, x, k; n   cin >> n >> r; n   for (long long i = 1; i < n + 1; i++) cin >> v[i]; n   for (long long i = 0; i < n - 1; i++) { n     long long u, v; n     cin >> u >> v; n     con[u].push_back(v); n     con[v].push_back(u); n   } n   dfs(r, -1, 0); n   for (long long i = 1; i <= n; i++) val[st[i]] = v[i]; n   build(1, 1, cur); n   cin >> m; n   l = 0; n   while (m--) { n     cin >> x >> k; n     x = (x + l) % n + 1; n     k = (k + l) % n; n     l = query(1, 1, cur, st[x], en[x], k + d[st[x]]); n     cout << l << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct edge { n   short to, cap, rev; n   edge(int _a = 0, int _b = 0, int _c = 0) { n     to = _a; n     cap = _b; n     rev = _c; n   } n }; n int S, T; n int dist[30010]; n int cur[30010]; n vector<edge> adj[30010]; n int q[30010]; n int hd, tl; n inline void addedge(int u, int v, int cap) { n   adj[u].push_back(edge(v, cap, adj[v].size())); n   adj[v].push_back(edge(u, 0, adj[u].size() - 1)); n } n int dfs(int i, short fl) { n   if (i == T) return fl; n   short lf = fl; n   for (int &j = cur[i]; ~j; --j) { n     edge &e = adj[i][j]; n     if (e.cap && dist[e.to] == dist[i] + 1) { n       short d = dfs(e.to, min(lf, e.cap)); n       e.cap -= d; n       adj[e.to][e.rev].cap += d; n       lf -= d; n       if (!lf) return fl; n     } n   } n   dist[i] = -1; n   return fl - lf; n } n int Dinic() { n   int res = 0; n   while (true) { n     memset(dist, 0, sizeof(dist)); n     dist[q[hd = tl = 0] = S] = 1; n     while (hd <= tl) { n       int i = q[hd++]; n       cur[i] = adj[i].size() - 1; n       for (int j = cur[i]; ~j; --j) { n         edge &e = adj[i][j]; n         if (e.cap && !dist[e.to]) { n           dist[e.to] = dist[i] + 1; n           q[++tl] = e.to; n         } n       } n     } n     if (!dist[T]) break; n     int fl; n     while (fl = dfs(S, 10000)) res += fl; n   } n   return res; n } n int bel[5010]; n int tpe[5010]; n int main(void) { n   int n, m; n   scanf( %d%d , &n, &m); n   S = 0; n   T = 30000; n   vector<pair<pair<int, int>, int> > v; n   for (int i = 1; i <= 8191; ++i) { n     addedge(n + i, n + (i << 1), 10000); n     addedge(n + i, n + (i << 1 | 1), 10000); n   } n   for (int i = 1; i <= n; ++i) { n     int a, b, c; n     scanf( %d%d , &tpe[i], &a); n     switch (tpe[i]) { n       case 0: { n         while (a--) { n           scanf( %d , &b); n           addedge(i, b + 8191 + n, 1); n         } n         break; n       } n       case 1: { n         scanf( %d , &b); n         v.push_back(make_pair(make_pair(a, b), i)); n         int l = a + 8191, r = b + 8191; n         while (l <= r) { n           if (l & 1) addedge(i, n + l, 1), l++; n           if (!(r & 1)) addedge(i, n + r, 1), r--; n           l >>= 1; n           r >>= 1; n         } n         break; n       } n       case 2: { n         scanf( %d%d , &b, &c); n         addedge(i, a + 8191 + n, 1); n         addedge(i, b + 8191 + n, 1); n         addedge(i, c + 8191 + n, 1); n         break; n       } n     } n   } n   sort(v.begin(), v.end()); n   for (int i = 1; i <= n; ++i) { n     if (tpe[i] != 2) { n       addedge(S, i, 1); n     } n   } n   for (int i = 1; i <= n; ++i) { n     if (tpe[i] == 2) { n       addedge(S, i, 2); n     } n   } n   for (int i = 1; i <= m; ++i) { n     addedge(n + 8191 + i, T, 1); n   } n   printf( %d n , Dinic()); n   for (int i = 1; i <= m; ++i) { n     for (int j = adj[i + 8191 + n].size() - 1; ~j; --j) { n       edge &e = adj[i + 8191 + n][j]; n       if (e.cap && e.to != T) { n         bel[i] = e.to; n       } n     } n   } n   multiset<pair<pair<int, int>, int> > s; n   int pnt = 0, vs = v.size(); n   for (int i = 1; i <= m; ++i) { n     if (bel[i] <= n && tpe[bel[i]] != 1) continue; n     while (pnt < vs && v[pnt].first.first <= i) { n       s.insert(make_pair(make_pair(v[pnt].first.second, v[pnt].first.first), n                          v[pnt].second)); n       ++pnt; n     } n     while (!s.empty() && s.begin()->first.first < i) s.erase(s.begin()); n     if (!s.empty()) bel[i] = s.begin()->second, s.erase(s.begin()); n   } n   for (int i = 1; i <= m; ++i) { n     if (bel[i]) printf( %d %d n , bel[i], i); n   } n   return 0; n } n