#include <bits/stdc++.h> n using namespace std; n int m, n; n int R[1005]; n map<int, int> cnt; n long long bell[1005][1005]; n void geneBell() { n   bell[0][0] = 1; n   for (int i = 1; i < m + 2; i++) { n     bell[i][0] = bell[i - 1][i - 1]; n     for (int j = 1; j <= i; j++) { n       bell[i][j] = (bell[i][j - 1] + bell[i - 1][j - 1]) % 1000000007; n     } n   } n } n int main() { n   cin >> m >> n; n   geneBell(); n   string tmp; n   for (int i = 0; i < n; i++) { n     cin >> tmp; n     for (int j = 0; j < m; j++) { n       R[j] = R[j] * 10 + tmp[j] -  0 ; n     } n   } n   for (int i = 0; i < m; i++) { n     cnt[R[i]]++; n   } n   map<int, int>::iterator it; n   long long ans = 1; n   for (it = cnt.begin(); it != cnt.end(); ++it) { n     if ((it->second) > 0) { n       ans = (ans * bell[it->second][0]) % 1000000007; n     } n   } n   cout << ans; 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   int n, a, b; n   cin >> n >> a >> b; n   if (a + b > n - 1 || a == n - 1 && n > 1) n     cout << -1 << endl; n   else { n     if (n == 1) n       cout << 1 << endl; n     else { n       cout << 1 <<    ; n       n--; n       int c; n       n -= (a + b); n       for (int i = 1; i <= b; i++) { n         c = 1 << i; n         cout << c <<    ; n       } n       while (n > 0) { n         cout << c <<    ; n         n--; n       } n       while (a > 0) { n         c++; n         cout << c <<    ; n         a--; n       } n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   int t; n   cin >> t; n   while (t--) { n     int a, b, c, d; n     cin >> a >> b >> c >> d; n     cout << max(a + b, c + d) << endl; n   } n } n


#include <bits/stdc++.h> n using std ::max; n using std ::min; n const int maxx = 300000 + 25; n int n, m, x, y, z, k, num; n int cnt, ans, tot; n int front, back, kr; n int cur[maxx]; n std ::priority_queue<int, std ::vector<int>, std ::greater<int> > quq; n class Node { n  public: n   int x; n   int y; n   int id; n }; n Node a[maxx]; n bool cmp(Node a, Node b) { return a.x == b.x ? a.y < b.y : a.x < b.x; } n int main() { n   scanf( %d%d , &n, &k); n   for (int i = (1), i_END = (n); i <= (i_END); ++i) { n     scanf( %d%d , &a[i].x, &a[i].y); n     a[i].id = i; n   } n   std ::sort(a + 1, a + n + 1, cmp); n   for (int i = (1), i_END = (n); i <= (i_END); ++i) { n     quq.push(a[i].y); n     tot++; n     if (tot > k) { n       quq.pop(); n       tot--; n     } n     if (tot == k) { n       if (quq.top() - a[i].x + 1 > ans) { n         ans = quq.top() - a[i].x + 1; n         front = a[i].x; n         back = quq.top(); n       } n     } n   } n   printf( %d n , ans); n   if (ans == 0) { n     for (int i = (1), i_END = (k); i <= (i_END); ++i) printf( %d  , i); n     putchar(10); n     return 0; n   } n   for (int i = (1), i_END = (n); i <= (i_END); ++i) { n     if (front >= a[i].x && a[i].y >= back) { n       printf( %d  , a[i].id); n       kr++; n     } n     if (kr == k) break; n   } n   putchar(10); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   for (int k = 0; k < t; k++) { n     int x, y, d = 0; n     cin >> x >> y; n     if (x >= y || x > 3) { n       cout <<  YES  << endl; n       d = 1; n     } n     if (d == 0) { n       if (x == 1) { n         cout <<  NO  << endl; n       } else { n         if (y > 3) { n           cout <<  NO  << endl; n         } else { n           cout <<  YES  << endl; n         } n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int mx = 0, i, n, m, d, h, ld, lh; n   cin >> n >> m; n   for (i = 0; i < m; i++) { n     cin >> d >> h; n     if (i == 0) { n       ld = d; n       lh = h; n       mx = lh + ld - 1; n       continue; n     } n     if (abs(h - lh) > d - ld) { n       cout <<  IMPOSSIBLE ; n       return 0; n     } n     if (h - lh < 0) n       mx = max(mx, lh + (d - ld - abs(h - lh)) / 2); n     else n       mx = max(mx, h + (d - ld - abs(h - lh)) / 2); n     ld = d; n     lh = h; n   } n   mx = max(mx, lh + n - ld); n   cout << mx; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string bad; n int k, ans = 0; n struct node { n   node *edges[26]; n   node() { n     for (int i = 0; i < 26; i++) edges[i] = NULL; n   } n }; n void insert(node *trie, string s) { n   for (int i = 0; i < s.size(); i++) { n     if (trie->edges[s[i] -  a ] == NULL) trie->edges[s[i] -  a ] = new node(); n     trie = trie->edges[s[i] -  a ]; n   } n } n void dfs(node *trie, int b) { n   if (b <= k) ans++; n   for (int i = 0; i < 26; i++) { n     if (trie->edges[i]) { n       int add = 0; n       if (bad[i] ==  0 ) add++; n       dfs(trie->edges[i], b + add); n     } n   } n } n int main() { n   string s; n   cin >> s >> bad >> k; n   node *root = new node(); n   string t =   ; n   for (int i = s.size() - 1; i >= 0; i--) { n     t = s[i] + t; n     insert(root, t); n   } n   dfs(root, 0); n   cout << ans - 1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int l, ans; n string s; n char t[1000005]; n int cal(string s) { n   int l = s.size(), p = 0, q = 0, cnt1 = 0, flag = 0; n   char ch; n   for (int i = 0; i < l; i++) { n     ch = (q & 1) ?  R  :  L ; n     if (s[i] ==  X ) { n       q++; n     } else { n       if (s[i] == ch) { n         p++; n         q++; n         flag = 0; n       } else { n         p++; n         q += 2; n         cnt1 += flag; n         flag = !flag; n       } n     } n   } n   if (q & 1) { n     q++; n     cnt1 += flag; n   } n   if (p * 2 > q) { n     p -= cnt1; n     q -= cnt1 * 2; n   } n   return (long long)p * 100000000 / q; n } n int main() { n   s =   ; n   scanf( %s , &t); n   l = strlen(t); n   for (int i = 0; i < l; i++) { n     if (i > 0 && t[i] == t[i - 1] && t[i] !=  X ) { n       s +=  X ; n     } n     s += t[i]; n   } n   if (s[0] == s[s.size() - 1] && s[0] !=  X ) { n     ans = max(cal(s +  X ), cal( X  + s)); n   } else { n     ans = cal(s); n   } n   printf( %d.%.06d n , ans / 1000000, ans % 1000000); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename V> n ostream &operator<<(ostream &out, const pair<T, V> x) { n   out <<  {  << x.first <<   :   << x.second <<  } ; n   return out; n } n template <typename T> n ostream &operator<<(ostream &out, const set<T> x) { n   for (auto &it : x) { n     out << it <<    ; n   } n   return out; n } n template <typename T> n ostream &operator<<(ostream &out, const multiset<T> x) { n   for (auto &it : x) { n     out << it <<    ; n   } n   return out; n } n template <typename T, typename V> n ostream &operator<<(ostream &out, const map<T, V> x) { n   for (auto &it : x) { n     out <<  [  << it.first <<  ]  n         <<   =   << it.second <<   n ; n   } n   return out; n } n template <typename T> n ostream &operator<<(ostream &out, const vector<T> x) { n   for (int i = 0; i < x.size() - 1; ++i) { n     out << x[i] <<    ; n   } n   out << x.back(); n   return out; n } n template <typename T> n ostream &operator<<(ostream &out, const vector<vector<T> > x) { n   for (int i = 0; i < x.size() - 1; ++i) { n     out <<  [  << i <<  ]  n         <<   = {  << x[i] <<  } n ; n   } n   out <<  [  << x.size() - 1 <<  ]  n       <<   = {  << x.back() <<  } n ; n   return out; n } n const int N = 1e6 + 5; n const int MOD = 1e9 + 7; n const int INF = 1e9; n vector<vector<char> > a, ans; n vector<vector<int> > cnt, dst; n int n, m; n long long get(long long x1, long long y1, long long x2, long long y2) { n   --x1, --y1; n   if (x1 < 0 || y1 < 0) return 0; n   return cnt[x2][y2] - cnt[x1][y2] - cnt[x2][y1] + cnt[x1][y1]; n } n queue<pair<long long, long long> > qu; n void bfs(long long x) { n   while (!qu.empty()) { n     pair<long long, long long> cr = qu.front(); n     qu.pop(); n     for (int i = -1; i <= 1; ++i) { n       for (int j = -1; j <= 1; ++j) { n         if (dst[cr.first + i][cr.second + j] == 0) { n           if (cr.first + i <= 0 || cr.first + i > n || cr.second + j <= 0 || n               cr.second + j > m) n             continue; n           dst[cr.first + i][cr.second + j] = dst[cr.first][cr.second] + 1; n           qu.push({cr.first + i, cr.second + j}); n         } n       } n     } n   } n } n bool solve(long long x) { n   while (!qu.empty()) qu.pop(); n   long long sz = 2 * x + 1; n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) { n       ans[i][j] =  . ; n       dst[i][j] = 0; n       long long c = get(i - sz + 1, j - sz + 1, i, j); n       if (c == sz * sz) ans[i - x][j - x] =  X ; n       if (i >= x && j >= x && ans[i - x][j - x] ==  X ) { n         qu.push({i - x, j - x}); n         dst[i - x][j - x] = 1; n       } n     } n   } n   if (qu.empty()) return false; n   bfs(x); n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) { n       if (a[i][j] ==  X  && dst[i][j] > x + 1) return false; n     } n   } n   return true; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   a.resize(n + 2, vector<char>(m + 2)); n   ans.resize(n + 2, vector<char>(m + 2)); n   cnt.resize(n + 2, vector<int>(m + 2)); n   dst.resize(n + 2, vector<int>(m + 2)); n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) { n       cin >> a[i][j]; n       cnt[i][j] = n           cnt[i][j - 1] + cnt[i - 1][j] - cnt[i - 1][j - 1] + (a[i][j] ==  X ); n     } n   } n   int l = 0, r = INF; n   while (r - l > 1) { n     int mid = (l + r) >> 1; n     if (solve(mid)) { n       l = mid; n     } else { n       r = mid; n     } n   } n   if (solve(r)) n     cout << r; n   else if (solve(l)) n     cout << l; n   cout <<   n ; n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) { n       cout << ans[i][j]; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dpo[2010][15], dpe[2010][15], a[2010], b[2010]; n long long combe[15], combo[15]; n long long f[2010], c[2010]; n long long nck(long long n, long long k) { n   if (n < k) return 0; n   long long ret = (f[n] * c[k]) % 998244353; n   return (ret * c[n - k]) % 998244353; n } n long long pwr(long long b, long long e) { n   b %= 998244353; n   if (e == 0) return 1; n   if (e == 1) return b; n   return (pwr(b * b, e / 2) * pwr(b, e % 2)) % 998244353; n } n int conv(string str) { n   int dir = 1, ret = 0; n   for (auto x : str) ret += dir * (x - 48), dir *= -1; n   ret %= 11; n   if (ret < 0) ret += 11; n   return ret; n } n int main() { n   ios_base::sync_with_stdio(false); n   f[0] = c[0] = 1; n   for (int i = 1; i < 2010; i++) (f[i] = f[i - 1] * i) %= 998244353; n   c[2010 - 1] = pwr(f[2010 - 1], 998244353 - 2); n   for (int i = 2010 - 2; i; i--) (c[i] = c[i + 1] * (i + 1)) %= 998244353; n   int T; n   cin >> T; n   while (T--) { n     int n; n     string str; n     int otot = 0, etot = 0, ocnt = 0, ecnt = 0; n     cin >> n; n     for (int i = 0; i < n; i++) { n       cin >> str; n       if (str.length() % 2) n         a[ocnt++] = conv(str); n       else n         b[ecnt++] = conv(str); n     } n     etot = accumulate(b, b + ecnt, 0) % 11; n     if (ocnt == 0) { n       cout << (etot ? 0 : f[n]) << endl; n       continue; n     } n     for (int i = 0; i <= ecnt; i++) fill(dpe[i], dpe[i] + 15, 0); n     dpe[0][0] = 1; n     for (int i = 0; i < ecnt; i++) n       for (int j = i; j >= 0; j--) n         for (int rem = 0; rem < 11; rem++) n           (dpe[j + 1][(rem + b[i]) % 11] += dpe[j][rem]) %= 998244353; n     fill(combe, combe + 11, 0); n     for (int i = 0; i <= ecnt; i++) { n       long long r = f[i] * f[ecnt - i] % 998244353 * n                     nck(ocnt / 2 + i, ocnt / 2) % 998244353 * n                     nck((ocnt + 1) / 2 - 1 + ecnt - i, (ocnt + 1) / 2 - 1) % n                     998244353; n       for (int rpos = 0; rpos < 11; rpos++) { n         int rneg = (rpos - etot) % 11; n         if (rneg < 0) rneg += 11; n         (combe[(rpos + rneg) % 11] += r * dpe[i][rpos]) %= 998244353; n       } n     } n     otot = accumulate(a, a + ocnt, 0) % 11; n     for (int i = 0; i <= ocnt; i++) fill(dpo[i], dpo[i] + 15, 0); n     dpo[0][0] = 1; n     for (int i = 0; i < ocnt; i++) n       for (int j = i; j >= 0; j--) n         for (int rem = 0; rem < 11; rem++) n           (dpo[j + 1][(rem + a[i]) % 11] += dpo[j][rem]) %= 998244353; n     fill(combo, combo + 11, 0); n     { n       int i = (ocnt + 1) / 2; n       long long r = f[i] * f[ocnt - i] % 998244353; n       for (int rpos = 0; rpos < 11; rpos++) { n         int rneg = (rpos - otot) % 11; n         if (rneg < 0) rneg += 11; n         (combo[(rpos + rneg) % 11] += r * dpo[i][rpos]) %= 998244353; n       } n     } n     long long res = 0; n     for (int i = 0; i < 11; i++) n       (res += combo[i] * combe[(11 - i) % 11]) %= 998244353; n     cout << res << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n int n; n int res = 0; n int r[10]; n int v[10]; n int main() { n   int t; n   cin >> t; n   while (t--) { n     long long x = 1; n     int n; n     cin >> n; n     for (int i = 3; i <= n * 2; i++) { n       x = x * i % mod; n     } n     cout << x << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n int a[105]; n map<int, bool> q; n int main() { n   while (~scanf( %d %d , &n, &k)) { n     q.clear(); n     for (int i = 0; i < k; i++) scanf( %d , &a[i]); n     int t = 1; n     int t2 = n; n     for (int i = 0; i < k; i++) { n       int t3 = (a[i] %= t2); n       while (t3--) { n         t++; n         if (t > n) t = 1; n         if (q[t]) t3++; n       } n       printf( %d%c , t, i == k - 1 ?   n  :    ); n       q[t] = 1; n       t++; n       if (t > n) t = 1; n       while (q[t]) { n         t++; n         if (t > n) t = 1; n       } n       t2--; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool comp(int x, int y) { return x > y; } n int main() { n   int t = 1; n   cin >> t; n   int n; n   while (t--) { n     cin >> n; n     if (n == 1 || n == 2) { n       cout << 1 <<   n ; n       continue; n     } n     if (n & 1) n       cout << n / 2 + 1 <<   n ; n     else n       cout << n / 2 <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int num; n   cin >> num; n   for (int i = 1; i <= 2 * sqrt(num); i++) { n     int x = (i * (i + 1)) / 2; n     int tmp = num - x; n     int st = 1, en = 2 * sqrt(num); n     while (st <= en) { n       int mid = st + (en - st) / 2; n       int y = (mid * (mid + 1)) / 2; n       if (y == tmp) { n         cout <<  YES  << endl; n         return 0; n       } else if (y < tmp) { n         st = mid + 1; n       } else { n         en = mid - 1; n       } n     } n   } n   cout <<  NO  << endl; n } n


#include <bits/stdc++.h> n #pragma warning(disable : 4996) n #pragma GCC optimize(3) n template <typename T> n T min(T x, T y) { n   return x < y ? x : y; n } n template <typename T> n T max(T x, T y) { n   return x > y ? x : y; n }; n const int INF = 1000000000; n const int MAXN = 100005; n const int B = 500; n int N, M, Q; n int low[MAXN]; n std::vector<int> V[MAXN], ID[MAXN], up[MAXN]; n int ans[MAXN]; n int f[MAXN]; n void solve() { n   static int mx[MAXN][25]; n   for (int l = 1, r; l <= N; l = r + 1) { n     r = min(l + B - 1, N); n     for (int i = l; i <= r; i++) { n       f[i] = i; n       for (int j = l; j <= i; j++) n         if (f[j] >= low[i] && low[i] >= j) f[j] = i; n       for (int j = 0; j < V[i].size(); j++) { n         if (V[i][j] >= l) { n           ans[ID[i][j]] = f[V[i][j]]; n           continue; n         } n         ans[ID[i][j]] = f[V[i][j]]; n         for (int k = l; k <= i; k++) n           if (low[k] >= V[i][j] && low[k] <= ans[ID[i][j]]) ans[ID[i][j]] = k; n       } n     } n     memset(mx, 0, sizeof(mx)); n     memset(f, 0, sizeof(f)); n     for (int i = r; i >= 1; i--) { n       f[i] = i; n       for (int j = 0; j < up[i].size(); j++) { n         if (up[i][j] > r) continue; n         int t = 0; n         while (1 << t <= up[i][j] - i) t++; n         t--; n         f[i] = max(f[i], max(mx[i + 1][t], mx[up[i][j] - (1 << t) + 1][t])); n       } n       mx[i][0] = f[i]; n       for (int j = 1; j < 25; j++) n         mx[i][j] = max(mx[i][j - 1], mx[min(r, i + (1 << (j - 1)))][j - 1]); n     } n   } n   for (int i = 1; i <= Q; i++) printf( %d n , ans[i]); n } n void init() { n   int l, r; n   scanf( %d %d , &N, &M); n   for (int i = 1; i <= M; i++) { n     scanf( %d %d , &l, &r); n     if (l == r) continue; n     low[r] = l; n     up[l].push_back(r); n   } n   scanf( %d , &Q); n   for (int i = 1; i <= Q; i++) { n     scanf( %d %d , &l, &r); n     V[r].push_back(l); n     ID[r].push_back(i); n   } n } n int main() { n   init(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   string a; n   cin >> a; n   if (n & 1) { n     cout <<  :( ; n     return 0; n   } n   int cnt1 = 1; n   int cnt2 = 1; n   if (a[0] ==  ) ) { n     cout <<  :( ; n     return 0; n   } n   a[0] =  ( ; n   if (a.back() ==  ( ) { n     cout <<  :( ; n     return 0; n   } n   a[a.size() - 1] =  ) ; n   for (int i = 1; i < a.size(); ++i) n     if (a[i] ==  ( ) ++cnt1; n   if (cnt1 > n / 2) { n     cout <<  :( ; n     return 0; n   } n   for (int i = 0; i < a.size(); ++i) { n     if (a[i] ==  ? ) { n       ++cnt1; n       a[i] =  ( ; n     } n     if (cnt1 == n / 2) break; n   } n   if (cnt1 < n / 2) { n     cout <<  :( ; n     return 0; n   } n   for (int i = 0; i < a.size(); ++i) n     if (a[i] ==  ? ) a[i] =  ) ; n   stack<int> s; n   for (int i = 0; i < a.size(); ++i) { n     if (a[i] ==  ( ) n       s.push(a[i]); n     else { n       if (s.empty()) { n         cout <<  :( ; n         return 0; n       } else { n         s.pop(); n         if (s.empty() && i != a.size() - 1) { n           cout <<  :( ; n           return 0; n         } n       } n     } n   } n   if (!s.empty()) { n     cout <<  :( ; n     return 0; n   } n   for (int i = 0; i < a.size(); ++i) cout << a[i]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a, cnt; n int fans = 1, r2; n string b, c, d, n; n struct Node { n   string s1; n   string s2; n   int jyh1 = -1; n } nd[107]; n int find(string x) { n   int ress = -1; n   for (int i = 0; i < cnt; i++) { n     if (nd[i].s1 == x) ress = i; n   } n   return ress; n } n int getans(int x, int re, int xx, int yy) { n   int ccnt = 0; n   int lev = 3; n   if (nd[x].jyh1 == -1) { n     for (int i = 0; i < nd[x].s2.length();) { n       if (nd[x].s2[i] ==  ( ) { n         ccnt++; n         i += 2; n         continue; n       } else if (nd[x].s2[i] ==  ) ) { n         ccnt--; n         i += 2; n         continue; n       } else if (isdigit(nd[x].s2[i])) { n         while (isdigit(nd[x].s2[i]) && i < nd[x].s2.length()) i++; n         i++; n         continue; n       } else if ((nd[x].s2[i] ==  +  || nd[x].s2[i] ==  - ) && ccnt == 0) { n         lev = min(1, lev); n         i += 2; n         continue; n       } else if ((nd[x].s2[i] ==  *  || nd[x].s2[i] ==  / ) && ccnt == 0) { n         lev = min(2, lev); n         i += 2; n         continue; n       } else { n         string got =   ; n         int l = i - 2; n         while (nd[x].s2[i] !=     && i < nd[x].s2.length()) { n           got += nd[x].s2[i]; n           i++; n         } n         if (find(got) == -1) { n           i++; n           continue; n         } else { n           int tg = getans(find(got), x, l, i + 1); n           if (ccnt == 0) lev = min(r2, lev); n           fans = min(fans, tg); n           i++; n           continue; n         } n       } n     } n     nd[x].jyh1 = lev; n   } n   lev = nd[x].jyh1; n   r2 = lev; n   if (lev == 3) return 1; n   if (lev == 1 && n       (nd[re].s2[xx] ==  -  || nd[re].s2[xx] ==  *  || nd[re].s2[xx] ==  /  || n        nd[re].s2[yy] ==  *  || nd[re].s2[yy] ==  / )) n     return 0; n   else if (lev == 1) n     return 1; n   if (lev == 2 && nd[re].s2[xx] ==  / ) n     return 0; n   else if (lev == 2) n     return 1; n } n int main() { n   cin >> a; n   getline(cin, b); n   for (int i = 0; i <= a; i++) { n     c =   ; n     d =   ; n     n =   ; n     getline(cin, b); n     for (int j = 1; j < b.length(); j++) { n       if (b[j] ==  e  && b[j - 1] ==  n ) { n         j++; n         while (b[j] ==    ) j++; n         while (b[j] !=    ) { n           n += b[j]; n           j++; n         } n         b.erase(0, j); n         break; n       } n     } n     for (int j = 0; j < b.length(); j++) { n       if (b[j] !=    ) d += b[j]; n     } n     b = d; n     b =     + b; n     for (int j = 1; j < b.length(); j++) { n       if (((b[j - 1] ==  +  || b[j - 1] ==  -  || b[j - 1] ==  *  || n             b[j - 1] ==  /  || b[j - 1] ==  (  || b[j - 1] ==  ) ) && n            b[j] !=    ) || n           ((b[j] ==  +  || b[j] ==  -  || b[j] ==  *  || b[j] ==  /  || n             b[j] ==  (  || b[j] ==  ) ) && n            b[j - 1] !=    )) n         c +=    , c += b[j]; n       else n         c += b[j]; n     } n     if (i == a) n =  MaIN ; n     nd[cnt].s1 = n; n     nd[cnt].s2 = c; n     cnt++; n   } n   nd[cnt].s1 =   ; n   nd[cnt].s2 =  ( MaIN ) ; n   cnt++; n   getans(cnt - 2, cnt - 1, 0, 7); n   if (fans == 1) n     cout <<  OK  << endl; n   else n     cout <<  Suspicious  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, x, a[3000], b[3000], qmi[3000], ymi[3000]; n string s; n int main() { n   iostream::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     cin >> a[i + 1]; n     a[i + 1] += a[i]; n   } n   for (int j = 0; j < m; j++) { n     cin >> b[j + 1]; n     b[j + 1] += b[j]; n   } n   cin >> x; n   for (int l = 1; l <= n; l++) { n     qmi[l] = x + 1; n     for (int j = 0; j + l <= n; j++) { n       qmi[l] = min(qmi[l], a[j + l] - a[j]); n     } n   } n   for (int l = 1; l <= m; l++) { n     ymi[l] = x + 1; n     for (int j = 0; j + l <= m; j++) { n       ymi[l] = min(ymi[l], b[j + l] - b[j]); n     } n   } n   int ans = 0; n   for (int l = 1; l <= n; l++) { n     for (int xl = 1; xl <= m; xl++) { n       if (qmi[l] <= x / ymi[xl]) { n         ans = max(ans, l * xl); n       } n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long i, n, k, sum = 0; n   bool flag = false; n   set<long long> S; n   scanf( %I64d%I64d , &n, &k); n   for (i = 1; i <= sqrt(n); i++) { n     if (n % i == 0) { n       S.insert(i); n       S.insert(n / i); n     } n   } n   if (S.size() >= k) flag = true; n   if (flag) { n     set<long long>::iterator it; n     it = S.begin(); n     while (k--) { n       it++; n     } n     it--; n     cout << *it; n   } else n     cout << -1; n   return 0; n } n


#include <bits/stdc++.h> n int n, m, seg[300005], lazy[300005], d[200005], l[200005], r[200005], q[200005]; n bool b = 1; n void update(int root, int lo, int hi, int l, int r, int val) { n   if (lazy[root]) { n     seg[root] |= lazy[root]; n     if (lo ^ hi) { n       lazy[root * 2 + 1] |= lazy[root]; n       lazy[root * 2 + 2] |= lazy[root]; n     } n     lazy[root] = 0; n   } n   if (lo >= l && hi <= r) { n     seg[root] |= val; n     if (lo ^ hi) { n       lazy[root * 2 + 1] |= val; n       lazy[root * 2 + 2] |= val; n     } n   } else if (lo > r || hi < l) n     return; n   else { n     update(root * 2 + 1, lo, (lo + hi) / 2, l, r, val); n     update(root * 2 + 2, (lo + hi) / 2 + 1, hi, l, r, val); n   } n } n int query(int root, int lo, int hi, int l, int r) { n   if (lazy[root]) { n     seg[root] |= lazy[root]; n     if (lo ^ hi) { n       lazy[root * 2 + 1] |= lazy[root]; n       lazy[root * 2 + 2] |= lazy[root]; n     } n     lazy[root] = 0; n   } n   if (lo >= l && hi <= r) { n     if (lo == hi) d[lo] = seg[root]; n     return seg[root]; n   } else if (lo > r || l > hi) n     return -1; n   else n     return query(root * 2 + 1, lo, (lo + hi) / 2, l, r) & n            query(root * 2 + 2, (lo + hi) / 2 + 1, hi, l, r); n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < m; i++) { n     scanf( %d%d%d , l + i, r + i, q + i); n     update(0, 0, n - 1, l[i] - 1, r[i] - 1, q[i]); n   } n   for (int i = 0; i < m && b; i++) n     b = query(0, 0, n - 1, l[i] - 1, r[i] - 1) == q[i]; n   if (b) { n     printf( YES n ); n     for (int i = 0; i < n; i++) n       printf( %d%c , d[i] ? d[i] : query(0, 0, n - 1, i, i), n              i + 1 < n ? 32 : 10); n   } else n     printf( NO n ); n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 1e5 + 1; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int n; n   cin >> n; n   vector<long long int> v(n); n   for (int i = 0; i < n; i++) { n     cin >> v[i]; n   } n   long long int s, t; n   cin >> s >> t; n   long long int sum1 = 0; n   for (int i = min(s, t) - 1; i < max(s, t) - 1; i++) { n     sum1 += v[i]; n   } n   long long int sum2 = 0; n   for (int i = max(s, t) - 1;; i = (i + 1) % n) { n     if (i == min(s, t) - 1) break; n     sum2 += v[i]; n   } n   cout << min(sum1, sum2) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-8; n const int mod = 1000000007; n const double PI = acos(-1.0); n int dx[4] = {0, 0, 1, -1}; n int dy[4] = {1, -1, 0, 0}; n int n, m; n long long ans; n int a[100005]; n int b[2000]; n int c[2000]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n, k, x; n   cin >> n >> k >> x; n   for (int i = 0; i < n; i++) { n     int num; n     cin >> num; n     b[num]++; n   } n   for (int i = 0; i < k; i++) { n     int cnt = 1; n     memset(c, 0, sizeof(c)); n     for (int j = 0; j <= 1111; j++) { n       if (b[j]) { n         if ((cnt & 1)) { n           c[j ^ x] += (b[j] + 1) / 2; n           c[j] += b[j] / 2; n         } else { n           c[j ^ x] += b[j] / 2; n           c[j] += (b[j] + 1) / 2; n         } n         cnt += b[j]; n       } n     } n     for (int j = 0; j <= 1111; j++) b[j] = c[j]; n   } n   int ans1 = 0, ans2 = 0x3f3f3f3f; n   for (int j = 0; j <= 1111; j++) n     if (b[j]) { n       ans1 = max(ans1, j); n       ans2 = min(ans2, j); n     } n   cout << ans1 <<     << ans2 << endl; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 10; n const int maxm = 500 * 500 + 10; n const int inf = 1e9; n const long long mod = 1e9 + 7; n int getint() { n   char c; n   while ((c = getchar()) && !(c >=  0  && c <=  9 ) && c !=  - ) n     ; n   int ret = c -  0 , sgn = 0; n   if (c ==  - ) sgn = 1, ret = 0; n   while ((c = getchar()) && c >=  0  && c <=  9 ) ret = ret * 10 + c -  0 ; n   if (sgn) ret = -ret; n   return ret; n } n vector<int> g[maxn], h[maxn]; n int cnt; n int vis[maxn]; n void dfs(int u) { n   vis[u] = 1; n   h[cnt].push_back(u); n   int sz = g[u].size(); n   for (int i = 0; i < sz; i++) { n     int v = g[u][i]; n     if (vis[v]) continue; n     dfs(v); n   } n } n int main() { n   int n; n   while (scanf( %d , &n) == 1) { n     int i; n     for (i = 1; i <= n; i++) g[i].clear(), h[i].clear(); n     for (i = 1; i <= n; i++) { n       int x = getint(); n       g[i].push_back(x), g[x].push_back(i); n     } n     memset(vis, 0, sizeof(vis)); n     cnt = 0; n     for (int i = 1; i <= n; i++) { n       if (!vis[i]) { n         cnt++; n         dfs(i); n       } n     } n     int flag = 0, ff = 1; n     int center1 = -1, center2 = -1; n     for (int i = 1; i <= cnt; i++) { n       int sz = h[i].size(); n       if (sz == 1) center1 = i, flag = 1; n       if (sz == 2) center2 = i, flag = 1; n       if (sz >= 3 && sz & 1) { n         ff = 0; n       } n     } n     if (center1 == -1 && center2 == -1) { n       puts( NO ); n       continue; n     } else if (center1 == -1 && !ff) { n       puts( NO ); n       continue; n     } n     puts( YES ); n     if (center1 != -1) { n       int u = h[center1][0]; n       for (int i = 1; i <= cnt; i++) n         if (i != center1) { n           int sz = h[i].size(); n           for (int j = 0; j < sz; j++) { n             printf( %d %d n , u, h[i][j]); n           } n         } n     } else { n       int u = h[center2][0], v = h[center2][1]; n       printf( %d %d n , u, v); n       for (int i = 1; i <= cnt; i++) n         if (i != center2) { n           int sz = h[i].size(); n           for (int j = 0; j < sz; j++) { n             if (j & 1) { n               printf( %d %d n , u, h[i][j]); n             } else n               printf( %d %d n , v, h[i][j]); n           } n         } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n const long long N = 1e5 + 10; n long long power(long long a, long long b) { n   long long ret = 1; n   while (b) { n     if (b & 1) ret *= a; n     a *= a; n     if (ret >= MOD) ret %= MOD; n     if (a >= MOD) a %= MOD; n     b >>= 1; n   } n   return ret; n } n long long invmod(long long x) { return power(x, MOD - 2); } n long long dp[55][2]; n long long a[55]; n long long n; n long long go(long long pos, long long check) { n   if (pos == n + 1) return 0; n   if (dp[pos][check] != -1) return dp[pos][check]; n   long long ans = 0; n   if (check == 0) { n     ans += max(a[pos] + go(pos + 1, check ^ 1), go(pos + 1, check)); n   } else { n     ans += min(go(pos + 1, check ^ 1), a[pos] + go(pos + 1, check)); n   } n   dp[pos][check] = ans; n   return ans; n } n long long go1(long long pos, long long check) { n   if (pos == n + 1) return 0; n   if (dp[pos][check] != -1) return dp[pos][check]; n   long long ans = 0; n   if (check == 0) { n     ans += min(go1(pos + 1, check ^ 1), a[pos] + go1(pos + 1, check)); n   } else { n     ans += max(a[pos] + go1(pos + 1, check ^ 1), go1(pos + 1, check)); n   } n   dp[pos][check] = ans; n   return ans; n } n int32_t main() { n   cin >> n; n   long long sum = 0; n   for (long long i = 1; i <= n; i++) { n     cin >> a[i]; n     sum += a[i]; n   } n   memset(dp, -1, sizeof(dp)); n   long long k = go1(1, 0); n   cout << k <<     << sum - k << endl; n } n


#include <bits/stdc++.h> n using namespace std; n bool G[100005]; n bool use[100005]; n int top[100005]; n int Top[100005]; n char R[100005]; n int num[100005]; n int main() { n   int m, n, Len = 0, useLen = 0; n   char str[10]; n   memset(G, true, sizeof(G)); n   memset(use, false, sizeof(use)); n   scanf( %d%d , &n, &m); n   int number = 0, last = 0; n   for (int i = 0; i < m; i++) { n     scanf( %s %d , str, &num[i]); n     R[i] = str[0]; n   } n   for (int i = 0; i < m; i++) { n     int a; n     str[0] = R[i]; n     a = num[i]; n     if (str[0] ==  + ) { n       if (number != 0 || (Len != 0 && use[a] == false)) G[a] = false; n       last = a; n       number++; n     } n     if (str[0] ==  - ) { n       if (use[a] == false) { n         for (int i = Len - 1; i >= useLen; i--) { n           G[Top[i]] = false; n         } n         useLen = Len; n         if (number != 0 || (i != m - 1 && a != num[i + 1])) G[a] = false; n       } else { n         if (number > 1 || (number == 1 && i != m - 1 && num[i + 1] != a)) n           G[a] = false; n         number--; n       } n     } n     if (use[a] == false) { n       Top[Len++] = a; n       use[a] = true; n     } n   } n   int sum = 0; n   for (int i = 1; i <= n; i++) n     if (G[i]) { n       top[sum++] = i; n     } n   printf( %d n , sum); n   if (sum > 0) { n     for (int i = 0; i < sum - 1; i++) printf( %d  , top[i]); n     printf( %d n , top[sum - 1]); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /stack:32000000 ) n using namespace std; n const int INF = 2147483647; n const long long LLINF = 9223372036854775807LL; n const int maxn = 300100; n struct state { n   int len, link; n   map<char, int> next; n   int cnt[3]; n   state() { memset(cnt, 0, sizeof(cnt)); } n }; n const int MAXLEN = 300100; n state st[MAXLEN * 2]; n int sz, last; n void sa_init() { n   sz = last = 0; n   st[0].len = 0; n   st[0].link = -1; n   ++sz; n } n int KK; n vector<int> states[maxn]; n void sa_extend(char c) { n   int cur = sz++; n   st[cur].len = st[last].len + 1; n   if (c >=  a  && c <=  z ) st[cur].cnt[KK] = 1; n   int p; n   for (p = last; p != -1 && !st[p].next.count(c); p = st[p].link) n     st[p].next[c] = cur; n   if (p == -1) n     st[cur].link = 0; n   else { n     int q = st[p].next[c]; n     if (st[p].len + 1 == st[q].len) n       st[cur].link = q; n     else { n       int clone = sz++; n       st[clone].len = st[p].len + 1; n       st[clone].next = st[q].next; n       st[clone].link = st[q].link; n       for (; p != -1 && st[p].next[c] == q; p = st[p].link) n         st[p].next[c] = clone; n       st[q].link = st[cur].link = clone; n     } n   } n   last = cur; n } n const int mod = 1000000007; n struct num { n   int x; n   num() : x(0) {} n   num(int x) : x(x) {} n   num operator+(const num& o) const { n     num res(x + o.x); n     if (res.x >= mod) res.x -= mod; n     return res; n   } n   num operator-(const num& o) const { n     num res(x - o.x); n     if (res.x < 0) res.x += mod; n     return res; n   } n   num operator*(const num& o) const { return num(x * (long long)o.x % mod); } n }; n num add[maxn]; n num ans[maxn]; n int main() { n   string s1, s2, s3; n   cin >> s1 >> s2 >> s3; n   sa_init(); n   KK = 0; n   for (int i = 0; i < int((s1).size()); ++i) sa_extend(s1[i]); n   sa_extend( A ); n   KK = 1; n   for (int i = 0; i < int((s2).size()); ++i) sa_extend(s2[i]); n   sa_extend( B ); n   KK = 2; n   for (int i = 0; i < int((s3).size()); ++i) sa_extend(s3[i]); n   sa_extend( C ); n   for (int i = 0; i < sz; ++i) states[st[i].len].push_back(i); n   for (int ii = maxn - 1; ii >= 1; --ii) { n     for (int i = 0; i < int((states[ii]).size()); ++i) { n       int curst = states[ii][i]; n       for (int iter = 0; iter < 3; ++iter) n         st[st[curst].link].cnt[iter] += st[curst].cnt[iter]; n     } n   } n   for (int i = 1; i < sz; ++i) { n     num curres = num(st[i].cnt[0]) * num(st[i].cnt[1]) * num(st[i].cnt[2]); n     add[st[i].len] = add[st[i].len] + curres; n     int lf = st[st[i].link].len; n     add[lf] = add[lf] - curres; n   } n   num cr(0); n   for (int i = maxn - 1; i >= 0; --i) { n     cr = cr + add[i]; n     ans[i] = cr; n   } n   int to = min(int((s1).size()), min(int((s2).size()), int((s3).size()))); n   for (int i = 0; i < to; ++i) printf( %d  , ans[i + 1].x); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int modmulti(long long int a, long long int b, long long int m) { n   return ((a % m) * (b % m)) % m; n } n long long int gcd(long long int a, long long int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long int power(long long int x, long long int y, long long int m) { n   if (y == 0) return 1; n   long long int p = power(x, y / 2, m) % m; n   p = (p * p) % m; n   return (y % 2 == 0) ? p : (x * p) % m; n } n long long int power2(long long int x, long long int y) { n   if (y == 0) return 1; n   long long int p = power2(x, y / 2); n   p = (p * p); n   return (y % 2 == 0) ? p : (x * p); n } n bool cmp(pair<long long int, long long int>& a, n          pair<long long int, long long int>& b) { n   if (a.first == b.first) n     return (a.second < b.second); n   else n     return (a.first > b.first); n } n long long int bin(vector<long long int> a, long long int left, n                   long long int right, long long int x) { n   long long int mid = left + (right - left) / 2; n   if (a[mid] == x) return mid; n   if (left <= right) { n     if (a[mid] < x) n       return bin(a, mid + 1, right, x); n     else if (a[mid] > x) n       return bin(a, left, mid - 1, x); n   } n   return -1; n } n long long int findclosest(long long int n) { n   long long int i; n   for (i = 0; i <= 64; i++) { n     if (power2(2, i) <= n) n       continue; n     else n       break; n   } n   return power2(2, i - 1); n } n long long int get_signi(long long int n) { n   while (n >= 10) { n     n = n / 10; n   } n   return n; n } n long long int get_digits(long long int n) { n   long long int i = 0; n   while (n >= 10) { n     n = n / 10; n     i++; n   } n   return i; n } n bool is_palindrome(string t) { n   for (int i = 0; i < t.size() / 2; i++) { n     if (t[i] != t[t.size() - i - 1]) return false; n   } n   return true; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   string second; n   cin >> second; n   string t =   ; n   long long int last_index = 0, i, j; n   for (i = 0; i < 26; i++) { n     for (j = last_index; j < second.size(); j++) { n       if (second[j] ==  a  + 25 - i) { n         t += second[j]; n         last_index = j; n       } n     } n   } n   cout << t <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAX = 2500000000; n const int inf = 123456789; n const double EPS = 1e-9; n const double PI = 2 * asin(1.0); n const long long mod = 1e9 + 7; n int double_cmp(double x, double y = 0, double tol = EPS) { n   return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1; n } n const int N = 3e5; n int n; n int t[2 * N][2]; n void modify(int p, int value, int q) { n   for (t[p += n][q] += value; p > 1; p >>= 1) n     t[p >> 1][q] = t[p][q] + t[p ^ 1][q]; n } n int query(int l, int r, int q) { n   int res = 0; n   for (l += n, r += n; l < r; l >>= 1, r >>= 1) { n     if (l & 1) res += t[l++][q]; n     if (r & 1) res += t[--r][q]; n   } n   return res; n } n int main() { n   scanf( %d , &n); n   int k; n   scanf( %d , &k); n   int a, b; n   scanf( %d%d , &a, &b); n   int q; n   scanf( %d , &q); n   a -= b; n   for (int i = 0; i < q; ++i) { n     int s; n     scanf( %d , &s); n     if (s == 1) { n       int x, y; n       scanf( %d%d , &x, &y); n       int aux = min(b - t[x + n][0], y); n       int aux2 = max(0, min(a - t[x + n][1], y - aux)); n       modify(x, aux, 0); n       modify(x, aux2, 1); n     } else { n       int x; n       scanf( %d , &x); n       long long saida = n           query(1, x, 0) + query(x + k, n + 1, 1) + query(x + k, n + 1, 0); n       cout << saida << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n; n bool benar; n string ans, st; n int main() { n   scanf( %d , &n); n   vector<string> data; n   while (cin >> st) data.push_back(st); n   if (data[0] ==  int ) { n     if (data.size() == 1) n       printf( %s n , data[0].c_str()); n     else n       printf( Error occurred n ); n   } else { n     vector<int> q; n     q.push_back(0); n     benar = true; n     ans =  pair< ; n     for (int i = 1; i < data.size(); i++) { n       if (data[i] ==  pair ) { n         if (q.size() == 0) { n           benar = false; n           break; n         } n         ans +=  pair< ; n         q[q.size() - 1]++; n         q.push_back(0); n       } else { n         if (q.size() == 0) { n           benar = false; n           break; n         } n         ans +=  int ; n         q[q.size() - 1]++; n         while (q.size()) { n           if (q[q.size() - 1] == 2) { n             ans +=  > ; n             q.pop_back(); n           } else n             break; n         } n         if (q.size()) n           if (q[q.size() - 1] == 1) ans +=  , ; n       } n     } n     if (q.size()) benar = false; n     if (benar) n       printf( %s n , ans.c_str()); n     else n       printf( Error occurred n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long int bexp(long long int a, long long int b, long long int mod) { n   long long int res = 1; n   while (b) { n     if (b & 1) res = (res * a) % mod; n     a = (a * a) % mod; n     b >>= 1; n   } n   return res; n } n long long int gcd(long long int a, long long int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n const long long int N = 1000010; n const long long int mod = 1e9 + 7; n struct comp { n   bool operator()(const pair<long long int, long long int> a, n                   const pair<long long int, long long int> b) const { n     return a.second > b.second; n   } n }; n long long int dp[N] = {}, prime[N] = {}; n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.precision(10); n   long long int t; n   cin >> t; n   dp[1] = 1; n   prime[1] = 1; n   long long int cnt = 1; n   for (long long int i = 2; i < N; ++i) { n     if (prime[i] == 0) { n       cnt++; n       for (long long int j = i * i; j < N; j += i) { n         prime[j] = 1; n       } n     } n     long long int k = sqrt(i); n     if (k * k == i && prime[k] == 0) { n       cnt--; n     } n     dp[i] = cnt; n   } n   for (long long int i = 0; i < t; ++i) { n     long long int n; n     cin >> n; n     cout << dp[n] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n float r, p, m; n float a[100 * 1000]; n int main() { n   cin >> m >> r; n   p = r * sqrt(2); n   a[0] = 2 * r; n   a[1] = 2 * r + p; n   for (int i = (2), _end = (m); i < _end; ++i) { n     a[i] = 2 * p; n     a[i] += 2 * r * (i - 1); n   } n   float sum = 0; n   sum += a[0] * m; n   for (int i = (1), _end = (m); i < _end; ++i) { n     sum += 2 * (m - i) * a[i]; n   } n   sum = sum / (m * m); n   printf( %.9f n , sum); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using lli = long long; n using ld = long double; n mt19937 rnd(time(nullptr)); n lli GCD(lli a, lli b) { n   if (b == 0) return a; n   return GCD(b, a % b); n } n lli LCM(lli a, lli b) { return a / GCD(a, b) * b; } n inline void Solve() { n   lli n = 0; n   cin >> n; n   vector<lli> data(n); n   for (auto &it : data) { n     cin >> it; n     while (it % 2 == 0) it /= 2; n     while (it % 3 == 0) it /= 3; n   } n   for (lli i = 1; i < n; i++) { n     if (data[i] != data[i - 1]) { n       cout <<  No ; n       return; n     } n   } n   cout <<  Yes ; n } n signed main() { n   cout << fixed << setprecision(20); n   Solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, m, k; n   cin >> n >> m >> k; n   long long int b[n]; n   memset(b, 0, sizeof(b)); n   vector<pair<long long int, long long int> > a; n   for (int i = 0; i < n; i++) { n     long long int x; n     cin >> x; n     a.push_back(make_pair(x, i)); n   } n   sort(a.begin(), a.end()); n   reverse(a.begin(), a.end()); n   long long int sum = 0; n   for (int i = 0; i < k * m; i++) { n     b[a[i].second] = 1; n     sum += a[i].first; n   } n   long long int l = 0, p = 0; n   cout << sum << endl; n   for (int i = 0; i < n; i++) { n     l = l + b[i]; n     if (l == m) { n       p++; n       cout << i + 1 <<    ; n       l = 0; n     } n     if (p == k - 1) break; n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   vector<vector<pair<int, string> > > rg(m, vector<pair<int, string> >(1)); n   for (int i = 0; i < n; i++) { n     string sn; n     int r, s; n     cin >> sn; n     scanf( %d %d , &r, &s); n     rg[r - 1].push_back(make_pair(s, sn)); n   } n   for (int i = 0; i < m; i++) { n     rg[i][0] = make_pair(-10,  xD ); n     sort(rg[i].begin(), rg[i].end()); n     reverse(rg[i].begin(), rg[i].end()); n     cout << (rg[i][1].first == rg[i][2].first n                  ?  ?  n                  : string(rg[i][0].second +     + rg[i][1].second)) n          << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1000000007; n long long POW(long long a, long long b, long long MMM = MOD) { n   long long ret = 1; n   for (; b; b >>= 1, a = (a * a) % MMM) n     if (b & 1) ret = (ret * a) % MMM; n   return ret; n } n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n long long lcm(long long a, long long b) { n   if (a == 0 || b == 0) return a + b; n   return a * (b / gcd(a, b)); n } n int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; n int ddx[] = {0, 0, 1, 1, 1, -1, -1, -1}, ddy[] = {1, -1, 1, 0, -1, 1, 0, -1}; n vector<int> v[2]; n vector<pair<int, int> > ans; n int main() { n   v[0].push_back(0); n   v[1].push_back(0); n   int n; n   scanf( %d , &n); n   for (int(i) = (1); (i) <= (n); (i) += (1)) { n     int x; n     scanf( %d , &x); n     v[x - 1].push_back(i); n   } n   for (int(t) = (1); (t) <= (n); (t) += (1)) { n     int cnt[2] = {0}; n     int now = 0, last = -1; n     while (1) { n       int p1 = upper_bound(v[0].begin(), v[0].end(), now) - v[0].begin() - 1; n       int p2 = upper_bound(v[1].begin(), v[1].end(), now) - v[1].begin() - 1; n       if (p1 + t >= v[0].size() && p2 + t >= v[1].size()) break; n       int t1 = 987654321, t2 = 987654321; n       if (p1 + t < v[0].size()) t1 = v[0][p1 + t]; n       if (p2 + t < v[1].size()) t2 = v[1][p2 + t]; n       if (t1 < t2) { n         cnt[0]++; n         last = 0; n         now = t1; n       } else { n         cnt[1]++; n         last = 1; n         now = t2; n       } n     } n     if (now == n) { n       if (cnt[0] > cnt[1] && last == 0) ans.push_back(make_pair(cnt[0], t)); n       if (cnt[0] < cnt[1] && last == 1) ans.push_back(make_pair(cnt[1], t)); n     } n   } n   sort(ans.begin(), ans.end()); n   printf( %d n , ans.size()); n   for (auto a : ans) printf( %d %d n , a.first, a.second); n } n


#include <bits/stdc++.h> n using namespace std; n int options[] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; n int main(void) { n   string s; n   cin >> s; n   int total = 1; n   for (int i = 0; i < 2; ++i) { n     total *= options[s[i] -  0 ]; n   } n   cout << total << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[512]; n int main() { n   int n, t; n   scanf( %d , &t); n   while (t--) { n     scanf( %d , &n); n     for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n     vector<int> ans; n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j < n - 1; j++) { n         if (a[j] > a[j + 1]) { n           swap(a[j], a[j + 2]); n           swap(a[j], a[j + 1]); n           ans.emplace_back(j); n           ans.emplace_back(j); n         } else if (a[j + 1] > a[j + 2]) { n           swap(a[j], a[j + 1]); n           swap(a[j], a[j + 2]); n           ans.emplace_back(j); n         } n       } n     } n     int i; n     for (i = 2; i <= n; i++) n       if (a[i] < a[i - 1]) break; n     if (i <= n) n       printf( -1 n ); n     else { n       printf( %d n , ans.size()); n       for (int x : ans) printf( %d  , x); n       ; n       printf(  n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long dx[] = {-1, -1, -1, 0, 0, 1, 1, 1}; n long long dy[] = {-1, 0, 1, -1, 1, -1, 0, 1}; n const long double pi = 3.141592653589; n const long long mod = 1000000007; n const long long maxn = 1e5 + 5; n template <typename T> n void printv(const vector<T>& v) { n   for (auto i : v) cout << i <<    ; n   cout <<   n ; n } n template <typename T> n void printv(const vector<pair<T, T>>& v) { n   for (auto p : v) cout <<  (  << p.first <<  ,  << p.second <<  ), ; n   cout <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false), cin.tie(nullptr); n   long long n; n   string s; n   cin >> n >> s; n   long long open = 0, closed = 0; n   for (auto i : s) { n     if (i ==  ( ) n       open++; n     else n       closed++; n   } n   if ((n & 1) || (open != closed)) n     cout << -1 <<   n ; n   else { n     long long ans = 0; n     long long ck = 0; n     for (auto i : s) { n       if (i ==  ( ) n         ck++; n       else { n         ck--; n         if (ck < 0) { n           ans += 2; n         } n       } n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100010; n int n; n struct Data { n   int s, id; n   bool operator<(const Data &a) const { return s < a.s; } n } da[N]; n int a[N], b[N]; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     int s; n     scanf( %d , &s); n     da[i] = Data{s, i}; n   } n   sort(da, da + n); n   for (int i = 0; i < (n + 2) / 3; i++) { n     a[da[i].id] = i; n     b[da[i].id] = da[i].s - i; n   } n   int x = (n + 2) / 3; n   for (int i = x; i < min(x + x, n); i++) { n     a[da[i].id] = 0; n     b[da[i].id] = da[i].s; n   } n   for (int i = x + x; i < n; i++) { n     a[da[i].id] = da[i].s - (n - i - 1); n     b[da[i].id] = n - i - 1; n   } n   puts( YES ); n   for (int i = 0; i < n; i++) { n     printf( %d%c , a[i],    n [i == n - 1]); n   } n   for (int i = 0; i < n; i++) { n     printf( %d%c , b[i],    n [i == n - 1]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   vector<pair<long long, long long> > arr; n   long long n = s.length(); n   for (int i = 0; i < n; i++) { n     for (int j = 1; i + (2 * j) < n; j++) { n       if (s[i] == s[i + j] && s[i] == s[i + (2 * j)]) { n         arr.push_back(make_pair(i + (2 * j), i)); n         break; n       } n     } n   } n   sort(arr.begin(), arr.end()); n   long long cnt = 0; n   for (int i = 0, j = 0; i < n; i++) { n     while (j < arr.size() && arr[j].second < i) j++; n     if (j == arr.size()) break; n     cnt += (n - arr[j].first); n   } n   cout << cnt << endl; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 10, mod = 998244353; n int n, m, x, y; n vector<int> e[2][N]; n inline void adde(int x, int y, int o) { e[o][x].push_back(y); } n inline int read() { n   char ch = getchar(); n   int x = 0, f = 1; n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = (x << 1) + (x << 3) -  0  + ch; n     ch = getchar(); n   } n   return x * f; n } n void write(int x) { n   if (x < 0) { n     putchar( - ); n     x = -x; n   } n   if (x > 9) write(x / 10); n   putchar(x % 10 +  0 ); n   return; n } n int dis[19][N]; n bool vis[19][N]; n queue<pair<int, int> > q; n int spfa() { n   memset(dis, 63, sizeof(dis)); n   q.push(pair<int, int>(0, 1)); n   dis[0][1] = 0; n   while (!q.empty()) { n     int u = q.front().second, k = q.front().first; n     q.pop(); n     vis[k][u] = 0; n     for (int v : e[k & 1][u]) { n       if (dis[k][v] > dis[k][u] + 1) { n         dis[k][v] = dis[k][u] + 1; n         if (!vis[k][v]) vis[k][v] = 1, q.push(pair<int, int>(k, v)); n       } n     } n     if (k < 18) { n       if (dis[k + 1][u] > dis[k][u] + (1 << k)) { n         dis[k + 1][u] = dis[k][u] + (1 << k); n         if (!vis[k + 1][u]) vis[k + 1][u] = 1, q.push(pair<int, int>(k + 1, u)); n       } n     } n   } n   int res = 1e9 + 7; n   for (int i = 0; i <= 18; ++i) res = min(res, dis[i][n]); n   return res; n } n queue<int> Q, tmp; n int diss[N]; n inline int qbit(int x) { n   int res = 1, t = 2; n   for (; x; x >>= 1) n     x & 1 ? (res = 1ll * res * t % mod) : 1, t = 1ll * t * t % mod; n   return res; n } n int main() { n   n = read(), m = read(); n   for (int i = 1; i <= m; ++i) { n     x = read(), y = read(); n     adde(x, y, 0), adde(y, x, 1); n   } n   int ans = spfa(); n   if (ans < 1e9) return write(ans), 0; n   memset(diss, 63, sizeof(diss)); n   diss[1] = 0, Q.push(1), tmp.push(1); n   for (int k = 0;; ++k) { n     while (!Q.empty()) { n       int u = Q.front(); n       Q.pop(); n       if (u == n) return write((qbit(k) - 1 + diss[u]) % mod), 0; n       for (int v : e[k & 1][u]) n         if (diss[v] > diss[u] + 1) n           diss[v] = diss[u] + 1, Q.push(v), tmp.push(v); n     } n     while (!tmp.empty()) Q.push(tmp.front()), tmp.pop(); n   } 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   long long t; n   cin >> t; n   while (t--) { n     int n, m; n     cin >> n >> m; n     vector<string> v(n); n     for (int i = 0; i < n; i++) cin >> v[i]; n     int c = 0; n     string ans =  -1 , temp; n     for (int i = 0; i < m; i++) { n       temp = v[0]; n       for (char j =  a ; j <=  z ; j++) { n         temp[i] = j; n         for (int k = 0; k < n; k++) { n           c = 0; n           for (int l = 0; l < m; l++) n             if (v[k][l] != temp[l]) c++; n           if (c > 1) break; n         } n         if (c <= 1) { n           ans = temp; n           break; n         } n       } n       if (ans !=  -1 ) break; n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-6; n const double INF = DBL_MAX; n bool iszero(const double a) { return fabs(a) <= eps; } n double sqr(const double a) { return a * a; } n int sgn(const double a) { n   if (a < -eps) return -1; n   return (a > eps); n } n int cmp(const double a, const double b) { return sgn(a - b); } n int inint() { n   int t; n   scanf( %d , &t); n   return t; n } n const int N = 4010; n const long long p = 1e9 + 7; n struct ll { n   long long l; n   ll(long long a = 0) : l(a % p) {} n   ll operator+(ll a) { return (l + a.l) % p; } n   ll operator+=(ll a) { n     l = (l + a.l) % p; n     return *this; n   } n   ll operator+(long long a) { return ll((l + a) % p); } n   ll operator+=(long long a) { n     l = (l + a) % p; n     return *this; n   } n   ll operator*(ll a) { return ll((l * a.l) % p); } n   ll operator*(long long a) { return ll((l * a) % p); } n   ll operator=(long long a) { n     l = a % p; n     return *this; n   } n   ll operator=(ll a) { n     l = a.l % p; n     return *this; n   } n   long long operator*() { return l; } n }; n ll C[N][N]; n void init() { n   for (int i = 0; i < N; i++) C[i][0] = 1; n   for (int i = 1; i < N; i++) n     for (int j = 1; j <= i; j++) C[i][j] = C[i - 1][j - 1] + C[i - 1][j]; n } n ll a[N][N], bell[N], cnt[N]; n void init2() { n   a[0][0] = bell[0] = 1; n   a[1][1] = bell[1] = 1; n   for (int i = 2; i < N; i++) { n     a[i][1] = a[i - 1][i - 1]; n     for (int j = 2; j <= i; j++) a[i][j] = a[i][j - 1] + a[i - 1][j - 1]; n     bell[i] = a[i][i]; n   } n } n void solve() { n   int n = inint(); n   ll ans; n   for (int i = 0; i < n; i++) ans += bell[i] * C[n][i]; n   cout << (*ans) << endl; n } n int main() { n   init(); n   init2(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s; n int g, t, n; n int main() { n   cin >> n >> n; n   cin >> s; n   int l = s.size(); n   for (int i = 0; i < l; i++) { n     if (s[i] ==  T ) n       t = i; n     else if (s[i] ==  G ) n       g = i; n   } n   if (g < t) swap(g, t); n   int i; n   if ((g - t) % n != 0) { n     cout <<  NO ; n     return 0; n   } n   for (i = t; i <= g; i += n) { n     if (s[i] ==  # ) { n       cout <<  NO ; n       return 0; n     } n   } n   cout <<  YES ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> me; n long long sum(long long x) { return (x * (x + 1)) / 2; } n int main() { n   int k; n   string s; n   cin >> k >> s; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] ==  1 ) { n       me.push_back(i); n     } n   } n   long long ans = 0, cnt = 0, idx = -1; n   if (k == 0) { n     for (int i = 0; i < s.size(); i++) { n       if (s[i] ==  1 ) { n         ans += sum(cnt); n         cnt = 0; n       } else { n         cnt++; n       } n     } n     ans += sum(cnt); n   } else { n     long long fst = -1; n     for (int i = 0; i < me.size(); i++) { n       long long idx = me[i]; n       cnt = 0; n       if ((i + k - 1) == me.size() - 1) { n         ans += ((idx - fst) * (s.size() - me[i + k - 1])); n       } else if (i + k - 1 < me.size() - 1) { n         ans += ((idx - fst) * (me[i + k] - me[i + k - 1])); n       } n       fst = me[i]; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void test_case() { n   const int N = 55; n   int n, x, y, m = 0; n   cin >> n; n   int arr[N][N] = {0}; n   map<int, pair<int, int>> pos; n   deque<int> ci, sally; n   vector<pair<pair<int, int>, pair<int, int>>> ans; n   for (int k = 0; k < n; ++k) { n     cin >> x; n     ci.push_back(x); n   } n   int k = 0; n   for (auto z : ci) { n     for (int j = 0; j < z; ++j) { n       cin >> arr[k][j]; n       sally.push_back(arr[k][j]); n       pos[arr[k][j]] = {k, j}; n     } n     k++; n   } n   sort(sally.begin(), sally.end()); n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < ci.front(); ++j) { n       if (pos[sally.front()].first == i && pos[sally.front()].second == j) n         sally.pop_front(); n       else { n         m++; n         ans.push_back( n             {{pos[sally.front()].first, pos[sally.front()].second}, {i, j}}); n         pos[arr[i][j]] = {pos[sally.front()].first, pos[sally.front()].second}; n         arr[pos[sally.front()].first][pos[sally.front()].second] = arr[i][j]; n         sally.pop_front(); n       } n     } n     ci.pop_front(); n   } n   cout << m << endl; n   for (auto x : ans) { n     cout << x.first.first + 1 <<     << x.first.second + 1 <<     n          << x.second.first + 1 <<     << x.second.second + 1 << endl; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   int t = 1; n   while (t--) { n     test_case(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char str[210], in[10]; n int cnt[10], r[10]; n int main() { n   scanf( %s %s , in, str); n   int l = strlen(in); n   for (int i = 0; i < l; i++) { n     if (in[i] ==  9 ) n       cnt[6]++; n     else if (in[i] ==  5 ) n       cnt[2]++; n     else n       cnt[in[i] -  0 ]++; n   } n   l = strlen(str); n   for (int i = 0; i < l; i++) { n     if (str[i] ==  9 ) n       r[6]++; n     else if (str[i] ==  5 ) n       r[2]++; n     else n       r[str[i] -  0 ]++; n   } n   int ans = 0x7fffffff; n   for (int i = 0; i <= 9; i++) { n     if (cnt[i] == 0) continue; n     ans = min(ans, r[i] / cnt[i]); n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, r = 0; n   cin >> n; n   string s; n   cin >> s; n   for (int i = 0; i < n - 1; i++) { n     if (s[i] == s[i + 1]) r++; n   } n   cout << r; n   return 0; n } n


#include<bits/stdc++.h> n #include<iostream> n #include<string> n #include<cmath> n #include<cstdio> n #include<cctype> n #include<cstring> n #include<iomanip> n #include<cstdlib> n #include<ctime> n #include<set> n #include<map> n #include<utility> n #include<queue> n #include<vector> n #include<stack> n #include<sstream> n #include<algorithm> n #define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++) n #define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--) n #define rep(i,n)for(int i=0,_n=n;i<n;i++) n #define ll long long n #define pii pair<int,int> n #define vi vector<int> n #define vpii vector<pii> n #define p_q priority_queue n #define m_p make_pair n #define pb push_back n #define ld long double n #define F first n #define S second n #define ull unsigned long long n #define mod 1000000007 n #define md 998244353 n #define x1 XZVJDFADSPFOE n #define y1 GASDIJSLDAEJF n #define x2 DFDAJKVOHKWIW n #define y2 PSFSAODSXVNMQ n #define LLINF 0x3f3f3f3f3f3f3f3fLL n #define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++) n using namespace std; n inline void read(int &x) n { n  short negative=1; n     x=0; n     char c=getchar(); n     while(c< 0  || c> 9 ) n     { n   if(c== - ) n    negative=-1; n   c=getchar(); n  } n     while(c>= 0  && c<= 9 ) n         x=(x<<3)+(x<<1)+(c^48),c=getchar(); n     x*=negative; n } n ll qpow(ll n,ll k){ n  ll ans=1; n  while(k){ n   if(k%2){ n    ans*=n; n    ans%=mod; n   } n   n*=n; n   n%=mod; n   k/=2; n  } n  return ans; n } n string iots(int n) n { n  string s=  ; n  while(n) n  { n   int now=n%10; n   s+=now+ 0 ; n   n/=10; n  } n  reverse(s.begin(),s.end()); n  return s; n } n int stoi(string s) n { n  int n=0; n  rep(i,s.size()) n  { n   n*=10; n   n+=s[i]- 0 ; n  } n  return n; n } n int n; n int p[100100]; n int pr[100100]; n int suf[100100]; n //pr[i]->i山峰左边能到的最远的地方 suf[i]右边  n int main() n { n  ios::sync_with_stdio(0); n  cin>>n; n  rep(i,n)cin>>p[i];  n  pr[0]=0; n  forn(i,1,n-1) n  { n   if(p[i]>p[i-1]) n   { n    pr[i]=pr[i-1];  n   }  n   else  n   { n    pr[i]=i; n   } n  } n  suf[n-1]=n-1; n  fore(i,n-2,0) n  { n   if(p[i]>p[i+1]) n   { n    suf[i]=suf[i+1]; n   } n   else n   { n    suf[i]=i; n   } n  } n  int mx=0; n  rep(i,n) n  { n   if(pr[i]==i||suf[i]==i)continue; n   if(i-pr[i]==suf[i]-i) n   { n    mx=max(mx,i-pr[i]); n   } n  } n  int ans=0; n  rep(i,n) n  { n   if(pr[i]==i||suf[i]==i)continue; n   if(i-pr[i]==suf[i]-i&&i-pr[i]==mx) n   { n    ans++; n   } n  } n  int cnt=0; n  rep(i,n) n  { n   if(i-pr[i]==mx)cnt++; n   if(suf[i]-i==mx)cnt++; n   }  n  if(mx==0||mx%2==1||cnt>=3) n  { n   cout<<0<<endl; n   return 0; n  } n  if(ans==1) cout<<1<<endl; n  else cout<<0<<endl; n  return 0; n } n //特判判全 n //循环边界 n //精度足够 n //注意初值 n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   while (a) b %= a, swap(a, b); n   return b; n } n char x[1000005], y[1000005]; n int aux[1000005][26]; n int main() { n   long long n, m; n   cin >> n >> m; n   scanf( %s %s , x, y); n   int lenx = strlen(x), leny = strlen(y); n   long long mdc = gcd(lenx, leny); n   long long mmc = lenx / mdc * leny; n   long long diff = mmc; n   for (int i = (0); i < (leny); ++i) ++aux[i % mdc][y[i] -  a ]; n   for (int i = (0); i < (lenx); ++i) diff -= aux[i % mdc][x[i] -  a ]; n   cout << diff * (n * lenx / mmc) << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:1000000000 ) n #pragma GCC optimize( Ofast,no-stack-protector ) n using namespace std; n const int maxn = (int)3e5 + 10, mod = 998244353; n int add(int x, int y) { n   x += y; n   if (x >= mod) { n     x -= mod; n   } n   return x; n } n int sub(int x, int y) { n   x -= y; n   if (x < 0) { n     x += mod; n   } n   return x; n } n int mul(int x, int y) { return (long long)x * y % mod; } n int my_pow(int x, int y) { n   int ans = 1; n   for (; y; y >>= 1, x = mul(x, x)) { n     if (y & 1) { n       ans = mul(ans, x); n     } n   } n   return ans; n } n pair<int, int> dp[maxn]; n int v[maxn]; n int res[maxn]; n int main() { n   int m; n   cin >> m; n   int n = 0; n   int ps = 0; n   for (int i = 0; i < m; i++) { n     scanf( %d , &v[i]); n     n += v[i]; n     if (v[i] > v[ps]) { n       ps = i; n     } n   } n   dp[1] = make_pair(1, 0); n   dp[0] = make_pair(1, 0); n   int rn = my_pow(n, mod - 2); n   int rm = my_pow(m - 1, mod - 2); n   for (int i = 1; i < n; i++) { n     int p1 = mul(i, rn); n     int p2 = sub(1, p1); n     int p3 = mul(p2, rm); n     int p4 = mul(p2, mul(m - 2, rm)); n     pair<int, int> cur = make_pair(0, sub(0, mul(i, rn))); n     cur.first = add(cur.first, add(sub(0, mul(dp[i - 1].first, p1)), n                                    mul(dp[i].first, sub(1, p4)))); n     cur.second = add(cur.second, add(sub(0, mul(dp[i - 1].second, p1)), n                                      mul(dp[i].second, sub(1, p4)))); n     cur.first = mul(cur.first, my_pow(p3, mod - 2)); n     cur.second = mul(cur.second, my_pow(p3, mod - 2)); n     dp[i + 1] = cur; n   } n   pair<int, int> cur = dp[n]; n   cur.first += mul(m - 1, dp[0].first); n   cur.second += mul(m - 1, dp[0].second); n   int x = mul(sub(0, cur.second), my_pow(cur.first, mod - 2)); n   for (int i = 0; i <= n; i++) { n     res[i] = add(mul(dp[i].first, x), dp[i].second); n   } n   int tot = 0; n   for (int i = 0; i < m; i++) { n     tot = add(tot, res[v[i]]); n   } n   cout << tot << endl; n } n


#include <bits/stdc++.h> n using namespace std; n void init() {} n const int N = 1e6 + 34; n const int INF = 1e9 + 34; n vector<int> ans[2]; n vector<int> es[N]; n int n, m, v1, v2; n int c[N]; n void dfs(int v, int q) { n   if (c[v] && c[v] != q + 1) { n     cout <<  -1 ; n     exit(0); n   } n   if (c[v]) return; n   c[v] = q + 1; n   ans[q].push_back(v + 1); n   for (int w : es[v]) { n     dfs(w, 1 - q); n   } n } n int main() { n   init(); n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     cin >> v1 >> v2; n     v1--; n     v2--; n     es[v1].push_back(v2); n     es[v2].push_back(v1); n   } n   for (int i = 0; i < n; i++) n     if (!c[i]) dfs(i, 0); n   for (int i = 0; i < 2; i++) { n     cout << ans[i].size() <<   n ; n     for (int w : ans[i]) cout << w <<    ; n     cout <<   n ; 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(0); n   cout.tie(0); n   int t = 1; n   while (t--) { n     int n; n     cin >> n; n     long long int a[n + 1]; n     int o = 0, idx, z = 0; n     long long int maxo = -1000000007; n     vector<int> v, v0; n     for (long long int i = 1; i < n + 1; i++) { n       cin >> a[i]; n       if (a[i] < 0) { n         o++; n         if (maxo < a[i]) { n           maxo = a[i]; n           idx = i; n         } n       } n       if (a[i] != 0) n         v.push_back(i); n       else n         v0.push_back(i); n     } n     if (o % 2 == 1) { n       v.erase(find(v.begin(), v.end(), idx)); n       v0.push_back(idx); n       sort(v0.begin(), v0.end()); n     } n     bool ch = 0; n     if (v.size() > 0) { n       for (long long int i = 0; i < v.size() - 1; i++) { n         ch = 1; n         cout <<  1   << v[i] <<     << v[i + 1] <<   n ; n       } n       if (v0.size() > 0) { n         for (long long int i = 0; i < v0.size() - 1; i++) { n           cout <<  1   << v0[i] <<     << v0[i + 1] <<   n ; n         } n         cout <<  2   << v0[v0.size() - 1] <<   n ; n       } n     } else { n       if (idx == n) { n         cout <<  2   << idx <<   n ; n         for (long long int i = 1; i < v0.size() - 1; i++) n           cout <<  1   << v0[i] <<     << v0[i + 1] <<   n ; n       } else { n         for (long long int i = 0; i < v0.size() - 1; i++) n           cout <<  1   << v0[i] <<     << v0[i + 1] <<   n ; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int min(int a, int b) { n   int min = a; n   if (b < a) { n     min = b; n   } n   return min; n } n int main() { n   int a, b, c, ans, min; n   cin >> a; n   cin >> b; n   cin >> c; n   if (a == 1 && b != 1 && c != 1) { n     ans = (a + b) * c; n   } else if (a != 1 && b != 1 && c == 1) { n     ans = a * (b + c); n   } else if (a != 1 && b == 1 && c != 1) { n     if (a < c) { n       ans = (a + b) * c; n     } else { n       ans = a * (b + c); n     } n   } else if (a == 1 && b == 1 && c != 1) { n     ans = (a + b) * c; n   } else if (a != 1 && b == 1 && c == 1) { n     ans = a * (b + c); n   } else if (a == 1 && c == 1) { n     ans = a + b + c; n   } else { n     ans = a * b * c; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n template <typename T, typename U> n ostream& operator<<(ostream& os, const pair<T, U>& p) { n   os << p.first <<     << p.second; n   return os; n } n template <typename T> n ostream& operator<<(ostream& os, const vector<T>& vec) { n   for (int i = 0; i < vec.size(); i++) { n     os << vec[i] << (i + 1 == vec.size() ?    :    ); n   } n   return os; n } n void solve() { n   int h, w; n   cin >> h >> w; n   vector<vector<int>> ans; n   vector<vector<int>> s(h, vector<int>(w)); n   for (int i = 0; (i) < (int)(h); (i)++) { n     string t; n     cin >> t; n     for (int j = 0; (j) < (int)(w); (j)++) { n       s[i][j] = t[j] -  0 ; n     } n   } n   auto exc = [&](int y0, int x0, int y1, int x1, int y2, int x2) { n     s[y0][x0] = s[y0][x0] ^ 1; n     s[y1][x1] = s[y1][x1] ^ 1; n     s[y2][x2] = s[y2][x2] ^ 1; n     vector<int> r = {y0 + 1, x0 + 1, y1 + 1, x1 + 1, y2 + 1, x2 + 1}; n     ans.push_back(r); n   }; n   auto exc2 = [&](int topy, int leftx, int no_use_y, int no_use_x) { n     vector<int> r; n     for (int i = topy; i < topy + 2; i++) { n       for (int j = leftx; j < leftx + 2; j++) { n         if (i != no_use_y || j != no_use_x) { n           r.push_back(i + 1); n           r.push_back(j + 1); n         } n       } n     } n     s[r[0] - 1][r[1] - 1] ^= 1; n     s[r[2] - 1][r[3] - 1] ^= 1; n     s[r[4] - 1][r[5] - 1] ^= 1; n     ans.push_back(r); n   }; n   if ((h & 1) && (w & 1)) { n     if (s[h - 1][w - 1] == 1) { n       exc(h - 1, w - 1, h - 2, w - 1, h - 1, w - 2); n     } n     for (int i = 0; i < h - 1; i += 2) { n       if (s[i][w - 1] == 1) { n         if (s[i + 1][w - 1] == 1) { n           exc(i, w - 1, i + 1, w - 1, i, w - 2); n         } else { n           exc(i, w - 1, i, w - 2, i + 1, w - 2); n         } n       } else { n         if (s[i + 1][w - 1] == 1) { n           exc(i + 1, w - 1, i, w - 2, i + 1, w - 2); n         } n       } n     } n     for (int i = 0; i < w - 1; i += 2) { n       if (s[h - 1][i] == 1) { n         if (s[h - 1][i + 1] == 1) { n           exc(h - 1, i, h - 1, i + 1, h - 2, i); n         } else { n           exc(h - 1, i, h - 2, i, h - 2, i + 1); n         } n       } else { n         if (s[h - 1][i + 1] == 1) { n           exc(h - 1, i + 1, h - 2, i, h - 2, i + 1); n         } n       } n     } n   } else if (h & 1) { n     for (int i = 0; i < w - 1; i += 2) { n       if (s[h - 1][i] == 1) { n         if (s[h - 1][i + 1] == 1) { n           exc(h - 1, i, h - 1, i + 1, h - 2, i); n         } else { n           exc(h - 1, i, h - 2, i, h - 2, i + 1); n         } n       } else { n         if (s[h - 1][i + 1] == 1) { n           exc(h - 1, i + 1, h - 2, i, h - 2, i + 1); n         } n       } n     } n   } else if (w & 1) { n     for (int i = 0; i < h - 1; i += 2) { n       if (s[i][w - 1] == 1) { n         if (s[i + 1][w - 1] == 1) { n           exc(i, w - 1, i + 1, w - 1, i, w - 2); n         } else { n           exc(i, w - 1, i, w - 2, i + 1, w - 2); n         } n       } else { n         if (s[i + 1][w - 1] == 1) { n           exc(i + 1, w - 1, i, w - 2, i + 1, w - 2); n         } n       } n     } n   } n   if (h & 1) h--; n   if (w & 1) w--; n   for (int i = 0; i < h; i += 2) { n     for (int j = 0; j < w; j += 2) { n       while (true) { n         int c = 0; n         for (int ii = i; ii < i + 2; ii++) { n           for (int jj = j; jj < j + 2; jj++) { n             c += (s[ii][jj] == 1); n           } n         } n         if (c == 0) { n           break; n         } else if (c == 1 || c == 3) { n           [&]() { n             for (int ii = i; ii < i + 2; ii++) { n               for (int jj = j; jj < j + 2; jj++) { n                 if (s[ii][jj] == 0) { n                   exc2(i, j, ii, jj); n                   return; n                 } n               } n             } n           }(); n         } else if (c == 2 || c == 4) { n           [&]() { n             for (int ii = i; ii < i + 2; ii++) { n               for (int jj = j; jj < j + 2; jj++) { n                 if (s[ii][jj] == 1) { n                   exc2(i, j, ii, jj); n                   return; n                 } n               } n             } n           }(); n         } n       } n     } n   } n   cout << ans.size() <<   n ; n   for (int i = 0; (i) < (int)(ans.size()); (i)++) { n     cout << ans[i] <<   n ; n   } n } n int main() { n   cin.tie(nullptr); n   ios::sync_with_stdio(false); n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int dx[] = {0, 1, 0, -1}; n const int dy[] = {1, 0, -1, 0}; n inline int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n inline long long read1() { n   long long x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n int ans; n long long w[20], ansa, ansb, ansc; n void dfs(long long a, long long b, long long c, long long nowa, long long nowb, n          long long jin, int nowl, int wei) { n   if (nowl >= ans) return; n   if (!a && !b && !c && !jin) { n     ans = nowl; n     ansa = nowa; n     ansb = nowb; n     return; n   } n   if (!c) { n     int tot = 0; n     long long nw = jin + a + b; n     while (nw) { n       tot++; n       nw /= 10; n     } n     dfs(0, 0, 0, nowa + a * w[wei], nowb + b * w[wei], 0, nowl + tot, wei); n     return; n   } n   if ((a + b + jin) % 10 == c % 10) n     dfs(a / 10, b / 10, c / 10, nowa + a % 10 * w[wei], nowb + b % 10 * w[wei], n         (a % 10 + b % 10 + jin) / 10, nowl, wei + 1); n   else { n     dfs(a * 10 + (c + 10 - b % 10 - jin) % 10, b, c, nowa, nowb, jin, nowl + 1, n         wei); n     dfs(a, b * 10 + (c + 10 - a % 10 - jin) % 10, c, nowa, nowb, jin, nowl + 1, n         wei); n     dfs(a, b, c * 10 + (a + b + jin) % 10, nowa, nowb, jin, nowl + 1, wei); n   } n } n int a, b, c; n int main() { n   scanf( %d+%d=%d , &a, &b, &c); n   w[0] = 1; n   ans = 12; n   for (int i = 1; i <= 18; i++) w[i] = w[i - 1] * 10; n   dfs(a, b, c, 0, 0, 0, 0, 0); n   printf( %I64d+%I64d=%I64d , ansa, ansb, ansa + ansb); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char t[5][13] = { S ,  M ,  L ,  XL ,  XXL }; n char s[13]; n int a[5], p[] = {0, 1, -1, 2, -2, 3, -3, 4, -4}; n int main() { n   for (int i = 0; i < (5); ++i) scanf( %d , &a[i]); n   int n; n   scanf( %d , &n); n   while (n--) { n     scanf( %s , s); n     int x = 0; n     for (int i = 0; i < (5); ++i) n       if (!strcmp(t[i], s)) x = i; n     for (int i = 0; i < (9); ++i) n       if (x + p[i] >= 0 && x + p[i] < 5 && a[x + p[i]]) { n         puts(t[x + p[i]]); n         a[x + p[i]]--; n         break; n       } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100010; n int n, dp[MAXN], ans[MAXN], mx[4 * MAXN], lz[4 * MAXN]; n vector<pair<int, int> > v, id; n void refresh(int pos, int bg, int ed) { n   if (lz[pos] == 0) return; n   int LZ = lz[pos]; n   lz[pos] = 0; n   mx[pos] += LZ; n   if (bg == ed) return; n   lz[2 * pos] += LZ; n   lz[2 * pos + 1] += LZ; n } n void upd(int pos, int bg, int ed, int p, int q, int val) { n   refresh(pos, bg, ed); n   if (q < bg || ed < p) return; n   if (p <= bg && ed <= q) { n     lz[pos] += val; n     refresh(pos, bg, ed); n     return; n   } n   int mid = (bg + ed) >> 1, l = 2 * pos, r = 2 * pos + 1; n   upd(l, bg, mid, p, q, val); n   upd(r, mid + 1, ed, p, q, val); n   mx[pos] = max(mx[l], mx[r]); n } n int qry(int pos, int bg, int ed, int p, int q) { n   refresh(pos, bg, ed); n   if (q < bg || ed < p) return 0; n   if (p <= bg && ed <= q) return mx[pos]; n   int mid = (bg + ed) >> 1, l = 2 * pos, r = 2 * pos + 1; n   return max(qry(l, bg, mid, p, q), qry(r, mid + 1, ed, p, q)); n } n int main() { n   scanf( %d , &n); n   for (int i = 0, x, h; i < n; i++) { n     scanf( %d %d , &x, &h); n     v.push_back(make_pair(x, x + h - 1)); n     id.push_back(make_pair(x, i)); n   } n   sort(v.begin(), v.end()); n   sort(id.begin(), id.end()); n   dp[n - 1] = 1; n   ans[id[n - 1].second] = 1; n   upd(1, 0, n - 1, n - 1, n - 1, 1); n   for (int i = n - 2; i >= 0; i--) { n     int a = v[i].first; n     int b = v[i].second; n     int t = lower_bound(v.begin(), v.end(), make_pair(b + 1, (int)-1e9)) - n             v.begin(); n     t--; n     if (t == i) n       dp[i] = 1; n     else n       dp[i] = qry(1, 0, n - 1, i + 1, t) + 1; n     upd(1, 0, n - 1, i, i, dp[i]); n     upd(1, 0, n - 1, i + 1, n - 1, 1); n     ans[id[i].second] = dp[i]; n   } n   for (int i = 0; i < n; i++) printf( %d  , ans[i]); n   printf(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e3 + 20; n const int MOD = 1e9 + 7; n const int INF = 0x3f3f3f3f; n const long long LLINF = 0x3f3f3f3f3f3f3f3f; n const double PI = acos(-1.0); n const double RATE = 0.995; n const double eps = 1e-4; n int arr[MAXN][MAXN]; n signed main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= n; ++j) { n       scanf( %d , &arr[i][j]); n     } n   } n   int a1a2 = arr[1][2]; n   int a2 = sqrt(1ll * a1a2 * arr[2][3] / arr[1][3]); n   printf( %d  , arr[1][2] / a2); n   printf( %d , a2); n   for (int i = 3; i <= n; ++i) printf(  %d , arr[2][i] / a2); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n; n   cin >> n; n   vector<pair<long long, long long>> ans; n   long long i = 0; n   long long j = 0; n   ans.push_back({0, -1}); n   ans.push_back({-1, 0}); n   ans.push_back({-1, -1}); n   for (long long k = 0; k < n; k++) { n     ans.push_back({i, j}); n     ans.push_back({i, j + 1}); n     ans.push_back({i + 1, j}); n     i++; n     j++; n   } n   ans.push_back({i, j}); n   cout << ans.size() << endl; n   for (long long i = 0; i < ans.size(); i++) n     cout << ans[i].first <<     << ans[i].second << endl; n } n signed main() { n   long long t; n   t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, k; n   cin >> n >> k; n   long long int prices[n]; n   for (long long int i = 0; i < n; i++) { n     cin >> prices[i]; n   } n   long long int minimum = prices[0]; n   long long int ans = 0; n   for (long long int i = 1; i < n; i++) { n     if (prices[i] < minimum) { n       minimum = prices[i]; n     } n   } n   for (long long int i = 0; i < n; i++) { n     prices[i] -= minimum; n   } n   for (long long int i = 0; i < n; i++) { n     if (prices[i] % k != 0) { n       cout << -1 << endl; n       return 0; n     } n   } n   for (long long int i = 0; i < n; i++) { n     ans += prices[i] / k; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10; n char a[N], b[N]; n int n, T; n int ans[N * 2], ct, rev; n int rt, ch[N][2], fa[N], tg[N], col[N], sz[N]; n int get(int x) { return ch[fa[x]][1] == x; } n void pushdown(int x) { n   swap(ch[x][0], ch[x][1]), col[ch[x][0]] ^= 1, col[ch[x][1]] ^= 1, n       tg[ch[x][0]] ^= 1, tg[ch[x][1]] ^= 1; n   tg[x] = 0; n } n int s(int x, int k) { n   if (tg[x]) pushdown(x); n   if (sz[ch[x][0]] >= k) return s(ch[x][0], k); n   if (sz[ch[x][0]] + 1 == k) return x; n   return s(ch[x][1], k - sz[ch[x][0]] - 1); n } n char sc(int k) { return col[s(rt, k)] +  0 ; } n void updata(int x) { sz[x] = sz[ch[x][0]] + sz[ch[x][1]] + 1; } n void rotate(int x) { n   int k = get(x), y = fa[x]; n   ch[y][k] = ch[x][k ^ 1]; n   fa[ch[y][k]] = y; n   if (fa[y]) ch[fa[y]][ch[fa[y]][1] == y] = x; n   fa[x] = fa[y]; n   fa[y] = x; n   ch[x][k ^ 1] = y; n   updata(y); n   updata(x); n } n int q[N], cnt; n void splay(int x) { n   int y; n   q[cnt = 1] = x; n   for (int i = x; fa[i]; i = fa[i]) q[++cnt] = fa[i]; n   for (int i = cnt; i >= 1; i--) n     if (tg[q[i]]) pushdown(q[i]); n   while (fa[x]) { n     y = fa[x]; n     if (fa[y]) rotate(get(x) == get(y) ? y : x); n     rotate(x); n   } n } n void work(int k) { n   if (k == n) { n     col[rt] ^= 1; n     tg[rt] ^= 1; n     return; n   } n   int y = s(rt, k + 1); n   splay(y); n   rt = y; n   col[ch[y][0]] ^= 1, tg[ch[y][0]] ^= 1; n } n void clr() { n   for (int i = 1; i <= n; i++) fa[i] = tg[i] = sz[i] = ch[i][0] = ch[i][1] = 0; n } n int ins(int l, int r) { n   if (l > r) return 0; n   int mid = l + r >> 1; n   col[mid] = a[mid] -  0 ; n   ch[mid][0] = ins(l, mid - 1); n   fa[ch[mid][0]] = mid; n   ch[mid][1] = ins(mid + 1, r); n   fa[ch[mid][1]] = mid; n   sz[mid] = sz[ch[mid][0]] + sz[ch[mid][1]] + 1; n   return mid; n } n int main() { n   scanf( %d , &T); n   while (T--) { n     ct = rev = 0; n     clr(); n     char c; n     int aaa = 1; n     scanf( %d%s%s , &n, a + 1, b + 1); n     rt = ins(1, n); n     for (int i = n; i; i--) n       if ((c = sc(i)) != b[i]) { n         if (sc(1) != c) ans[++ct] = 1, work(1); n         ans[++ct] = i; n         work(i); n       } n     sc(1); n     printf( %d , ct); n     for (int i = 1; i <= ct; i++) printf(  %d , ans[i]); n     puts(  ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n constexpr int N = 2e5 + 10; n int x, y; n string cc; n vector<string> s[10][10]; n bool can(int a, int b) { n   for (auto i : s[a][b]) { n     for (auto j : i) n       if (j ==  . ) return true; n   } n   return false; n } n void color(int a, int b) { n   for (int i = 0; i < 3; i++) { n     for (int j = 0; j < 3; j++) { n       if (s[a][b][i][j] ==  . ) s[a][b][i][j] =  ! ; n     } n   } n } n void call() { n   for (int i = 0; i < 3; i++) { n     for (int j = 0; j < 3; j++) { n       for (int k = 0; k < 3; k++) { n         for (int l = 0; l < 3; l++) { n           if (s[i][j][k][l] ==  . ) s[i][j][k][l] =  ! ; n         } n       } n     } n   } n } n void print() { n   for (int k = 0; k < 3; k++) { n     for (int i = 0; i < 3; i++) { n       for (int j = 0; j < 3; j++) { n         cout << s[k][j][i] <<    ; n       } n       cout <<   n ; n     } n     cout <<   n ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   for (int i = 0; i < 9; i++) { n     for (int j = 0; j < 3; j++) { n       cin >> cc; n       s[i / 3][j].push_back(cc); n     } n   } n   cin >> x >> y; n   x--; n   y--; n   x %= 3; n   y %= 3; n   if (can(x, y)) { n     color(x, y); n     print(); n   } else { n     call(); n     print(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void ifree() { freopen( in ,  r , stdin); } n void ofree() { freopen( out ,  w , stdout); } n double min(double a, double b) { return a < b ? a : b; } n int main() { n   int n, w; n   while (cin >> n >> w) { n     int arr[2 * n]; n     for (int i = 0; i < 2 * n; i++) cin >> arr[i]; n     sort(arr, arr + 2 * n); n     double ans; n     if (2 * arr[0] < arr[n]) n       ans = 3 * n * arr[0]; n     else n       ans = 3 * n * ((double)arr[n]) / 2; n     printf( %lf n , min((double)w, ans)); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long a[102], b[102]; n long long cn[103]; n int main() { n   long long n, m; n   cin >> n >> m; n   long long k; n   memset(a, -1, sizeof(a)); n   for (long long i = 1; i <= m; i++) n     for (long long j = 1; j <= n; j++) { n       cin >> k; n       if (k > a[i]) { n         a[i] = k; n         b[i] = j; n       } n     } n   for (long long i = 1; i <= m; i++) { n     cn[b[i]]++; n   } n   long long mx = 0, win = 1; n   for (long long i = 1; i <= n; i++) { n     if (cn[i] > mx) { n       mx = cn[i]; n       win = i; n     } n   } n   cout << win << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string input; n int main() { n   cin >> input; n   int last = -1; n   for (char i =  z ; i >=  a ; i--) n     for (int j = last + 1; j < input.length(); j++) n       if (input[j] == i) { n         cout << input[j]; n         last = j; n       } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int l[1 << 12]; n int in[1 << 12]; n int sm[1 << 12]; n void go(int now) { n   if (now * 2 > ((1 << n) - 1)) return; n   int a = now * 2; n   int b = now * 2 + 1; n   go(a); n   go(b); n   int al = l[a] + in[a]; n   int bl = l[b] + in[b]; n   l[now] = max(al, bl); n   sm[now] = sm[a] + sm[b] + abs(al - bl); n }; n int main() { n   cin >> n; n   n++; n   for (int i = 2; i <= (1 << n) - 1; i++) { n     cin >> in[i]; n   } n   go(1); n   cout << sm[1] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s, t, sum; n   cin >> s >> t; n   string n = to_string(stoi(s) + stoi(t)); n   s.erase(remove(s.begin(), s.end(),  0 ), s.end()); n   t.erase(remove(t.begin(), t.end(),  0 ), t.end()); n   n.erase(remove(n.begin(), n.end(),  0 ), n.end()); n   if (stoi(s) + stoi(t) == stoi(n)) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6; n const long long oo = 1e18; n long long a[N], w[N], k, n, t, l[N], r[N], res; n string s; n vector<long long> b; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n     t += a[i]; n   } n   cin >> k; n   for (int i = 1; i <= k; ++i) cin >> l[i] >> r[i]; n   sort(l + 1, l + 1 + k); n   sort(r + 1, r + 1 + k); n   int i = 0; n   for (i = k; i >= 1; --i) { n     if (l[i] <= t && t <= r[i]) n       res = t; n     else if (r[i] < t) n       break; n   } n   if (res == 0 && i != k && k != 0) n     res = l[i + 1]; n   else if (res == 0) n     res = -1; n   if (res == 0) res = -1; n   cout << res <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n void test() { n   string s; n   cin >> s; n   const int len = s.size(); n   stack<char> a; n   for (int i = 0; i < len; ++i) { n     if (a.empty()) { n       a.push(s[i]); n     } else if (s[i] ==  B ) { n       a.pop(); n     } else { n       a.push(s[i]); n     } n   } n   cout << a.size() <<   n ; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     test(); n   } n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n #define ll long long int   n #define vi vector<int>  n #define vll vector<ll> n /*int gcd(int a,int b){ n     if(b==0) n         return a; n     else n         return gcd(b,a%b); n } n */ n void solve(){ n     int n; n     cin>>n; n     int a[n]; n     for(int i=0;i<n;i++){ n         cin>>a[i]; n     } n     int cnt=0; n     for(int i=0;i<n;i++){ n         if(a[i]!=i+1) n             cnt=1; n     } n     if(a[0]==n && a[n-1]==1){ n         cout<< 3 <<endl; n         return; n     } n     if(cnt==0){ n         cout<< 0 <<endl; n     } n     else if(a[0]==1 || a[n-1]==n){ n         cout<< 1 <<endl; n         return; n     } n     else n         cout<< 2 <<endl; n  n         n  n } n int main(){ n     cin.tie(NULL); n     #ifndef ONLINE_JUDGE n     freopen( input.txt ,  r , stdin); n     freopen( output.txt ,  w , stdout); n     #endif  n  n     int n; n     cin>>n; n     while(n--){ n         solve(); n     } n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x[100002] = {0}, j, t; n   cin >> n; n   t = n; n   for (int i = 0; i < n; i++) { n     cin >> j; n     x[j] = 1; n     while (t >= 1 && x[t] == 1) { n       cout << t <<    ; n       t--; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e3 + 5; n long long n, m, c, cur, loc; n long long a[N]; n void work() { n   long long lim = c / 2 + c % 2; n   if (cur > lim) { n     for (long long i = n; i >= 1; i--) { n       if (cur > a[i] || !a[i]) { n         loc = i; n         return; n       } n     } n     loc = 1; n     return; n   } else { n     for (long long i = 1; i <= n; i++) { n       if (cur < a[i] || !a[i]) { n         loc = i; n         return; n       } n     } n     loc = n; n     return; n   } n } n bool check() { n   for (long long i = 1; i <= n; i++) { n     if (!a[i]) return 0; n   } n   for (long long i = 2; i <= n; i++) { n     if (a[i] < a[i - 1]) return 0; n   } n   return 1; n } n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> n >> m >> c; n   for (long long i = 1; i <= m; i++) { n     cin >> cur; n     work(); n     a[loc] = cur; n     cout << loc << endl; n     if (check()) { n       return 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n static const double EPS = 1e-13; n int ROUND(double x) { return (int)(x + 0.5); } n bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; } n bool ISEQUAL(double x, double y) { n   return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y))); n } n double SQSUM(double x, double y) { return x * x + y * y; } n template <class T> n bool INRANGE(T x, T a, T b) { n   return a <= x && x <= b; n } n int main() { n   long long n, l, t; n   scanf( %lld %lld %lld n , &n, &l, &t); n   vector<long long> a(n); n   for (int i = 0; i < n; i++) { n     scanf( %lld  n , &a[i]); n   } n   long long count = 0; n   long long base = 2 * t / l; n   long long boundary = (2 * t) % l; n   { n     int x = 1; n     for (int y = 0; y < n - 1; y++) { n       x = max(x, y + 1); n       while (x < n) { n         if (a[x] - a[y] > boundary) { n           break; n         } n         x++; n       } n       count += (x - (y + 1)); n     } n   } n   { n     int x = 1; n     for (int y = 0; y < n - 1; y++) { n       x = max(x, y + 1); n       while (x < n) { n         if (l - (a[x] - a[y]) <= boundary) { n           break; n         } n         x++; n       } n       count += (n - x); n     } n   } n   double ans = 0.0; n   double masu = n * (n - 1) * 0.5; n   ans += (double)base * masu * 2; n   ans += 1.0 * count; n   ans /= 4; n   printf( %.16f n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[5]; n int kiemtra(int x, int y, int z) { n   if (x < y + z && y < z + x && z < x + y) return 1; n   if (x == y + z || y == x + z || z == x + y) return 2; n   return 0; n } n void solve() { n   int i, j, k, x, gan; n   gan = 0; n   for (i = 0; i < 4; i++) n     for (j = 0; j < 4; j++) n       for (k = 0; k < 4; k++) n         if (i != j && j != k && i != k) { n           x = kiemtra(a[i], a[j], a[k]); n           if (x == 1) { n             cout <<  TRIANGLE n ; n             return; n           } n           if (x == 2) gan = 1; n         } n   if (gan == 1) { n     cout <<  SEGMENT n ; n     return; n   } n   cout <<  IMPOSSIBLE n ; n } n void input() { n   int i; n   while (cin >> a[0] >> a[1] >> a[2] >> a[3]) { n     solve(); n   } n } n int main() { n   input(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int MAX(long long int a, long long int b) { n   if (a > b) { n     return a; n   } else { n     return b; n   } n } n int MIN(long long int a, long long int b) { n   if (a < b) { n     return a; n   } else { n     return b; n   } n } n int gcd(long long int a, long long int b) { n   long long int c; n   while (a != 0) { n     c = a; n     a = b % a; n     b = c; n   } n   return b; n } n int main() { n   int n; n   cin >> n; n   cout << (6 * n * (n - 1)) + 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int node_max = 3000; n struct network { n   struct node { n     int v, c, w, b; n     node(int _v = 0, int _c = 0, int _w = 0, int _b = 0) n         : v(_v), c(_c), w(_w), b(_b) {} n   }; n   int n, pre[node_max]; n   vector<node> nd[node_max]; n   void clear() { n     for (int i = 0; i < n; ++i) nd[i].clear(); n     n = 0; n   } n   void insert(int u, int v, int c, int w, bool d = false) { n     n = max(n, max(u, v) + 1); n     nd[u].push_back(node(v, c, w, nd[v].size())); n     nd[v].push_back(node(u, 0, -w, nd[u].size() - 1)); n     if (d) { n       nd[v].push_back(node(u, c, w, nd[u].size())); n       nd[u].push_back(node(v, 0, -w, nd[v].size() - 1)); n     } n   } n   pair<int, int> get_max_flow_min_cost(int src, int dst) { n     pair<int, int> res; n     int flow; n     while ((flow = get_min_path(src, dst)) != 0) { n       res.first += flow; n       for (int i = dst; i != src; i = nd[i][pre[i]].v) { n         res.second += nd[nd[i][pre[i]].v][nd[i][pre[i]].b].w * flow; n         nd[nd[i][pre[i]].v][nd[i][pre[i]].b].c -= flow; n         nd[i][pre[i]].c += flow; n       } n     } n     return res; n   } n   int get_min_path(int src, int dst) { n     int dis[node_max], bfs[node_max]; n     bool visited[node_max] = {}; n     fill(dis, dis + n, INT_MAX); n     visited[src] = true; n     dis[src] = 0; n     bfs[0] = src; n     for (int s = 0, t = 1; s != t; visited[bfs[s]] = 0, s = (s + 1) % n) { n       int v = bfs[s]; n       for (vector<node>::iterator i = nd[v].begin(); i != nd[v].end(); ++i) { n         if (i->c <= 0 || dis[v] + i->w >= dis[i->v]) continue; n         dis[i->v] = dis[v] + i->w; n         pre[i->v] = i->b; n         if (!visited[i->v]) { n           visited[i->v] = true; n           bfs[t] = i->v; n           t = (t + 1) % n; n         } n       } n     } n     if (dis[dst] == INT_MAX) return 0; n     int res = INT_MAX; n     for (int i = dst; i != src; i = nd[i][pre[i]].v) n       res = min(res, nd[nd[i][pre[i]].v][nd[i][pre[i]].b].c); n     return res; n   } n }; n int n, m, s[1024], t[1024], c[1024], ans[1024]; n network g; n bool solve() { n   if (scanf( %d%d , &n, &m) == EOF) return false; n   for (int i = 0; i < n; ++i) scanf( %d%d%d , &s[i], &t[i], &c[i]); n   g.clear(); n   int S = n * 2, T = n * 2 + 2; n   g.insert(S, S + 1, m, 0); n   for (int i = 0; i < n; ++i) { n     g.insert(S + 1, i, 1, 0); n     g.insert(i + n, T, 1, 0); n     g.insert(i, i + n, 1, -c[i]); n     for (int j = 0; j < n; ++j) { n       if (i != j && s[i] + t[i] <= s[j]) { n         g.insert(i + n, j, 1, 0); n       } n     } n   } n   g.get_max_flow_min_cost(S, T); n   for (int i = 0; i < n; ++i) { n     ans[i] = 0; n     for (vector<network::node>::iterator j = g.nd[i].begin(); n          j != g.nd[i].end(); ++j) { n       if (j->v == i + n && j->c == 0) { n         ans[i] = 1; n       } n     } n     printf(i == n - 1 ?  %d n  :  %d  , ans[i]); n   } n   return true; n } n int main() { n   while (solve()) n     ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int a, b; n     cin >> a >> b; n     int c = 2 * min(a, b); n     int d = max(a, b); n     if (c > max(a, b)) { n       cout << c * c << endl; n     } else { n       cout << d * d << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int getint() { n   unsigned int c; n   int x = 0; n   while (((c = getchar()) -  0 ) >= 10) { n     if (c ==  - ) return -getint(); n     if (!~c) exit(0); n   } n   do { n     x = (x << 3) + (x << 1) + (c -  0 ); n   } while (((c = getchar()) -  0 ) < 10); n   return x; n } n const int N = 100111; n struct Bridge { n   struct edge { n     int to, rv; n     edge() {} n     edge(int to, int rv) : to(to), rv(rv) {} n   }; n   int nv, cnt; n   vector<edge> graph[N]; n   int dis[N], low[N], par[N]; n   void init(int v = N) { n     nv = v; n     for (v = 0; v < nv; v++) graph[v].clear(); n   } n   void add_edge(int u, int v) { n     if (u == v) return; n     int tu = graph[u].size(), tv = graph[v].size(); n     graph[u].push_back(edge(v, tv)), graph[v].push_back(edge(u, tu)); n   } n   void proc() { n     cnt = 0; n     fill(dis, dis + nv, ~0); n     for (int u = 0; u < nv; u++) n       if (!~dis[u]) dfs(u, -1, -1); n   } n   void dfs(int u, int p, int pe) { n     dis[u] = low[u] = cnt++, par[u] = p; n     for (int i = 0; i < graph[u].size(); i++) { n       int v = graph[u][i].to; n       if (i == pe) continue; n       if (~dis[v]) { n         low[u] = min(low[u], dis[v]); n       } else { n         dfs(v, u, graph[u][i].rv); n         low[u] = min(low[u], low[v]); n       } n     } n   } n   bool is_bridge(int u, int v) { n     if (dis[u] > dis[v]) swap(u, v); n     return (u == par[v] and dis[v] <= low[v]); n   } n }; n struct UnionFind { n   vector<int> par; n   void init(int n) { par.assign(n, ~0); } n   int root(int x) { return par[x] < 0 ? x : par[x] = root(par[x]); } n   bool connect(int x, int y) { n     x = root(x), y = root(y); n     if (x == y) return 0; n     if (par[y] < par[x]) swap(x, y); n     par[x] += par[y], par[y] = x; n     return 1; n   } n   bool same(int x, int y) { return root(x) == root(y); } n   int size(int x) { return -par[root(x)]; } n }; n int n, m, k; n int us[N], vs[N]; n int as[N], bs[N]; n Bridge brg; n UnionFind uf; n struct LowestCommonAncestor { n   static const int LOGV = 20; n   static const int V = 100111; n   vector<int> graph[V]; n   int par[LOGV][V], dep[V], nv; n   void init(int v) { n     nv = v, memset(par, ~0, sizeof(par)); n     for (v = 0; v < nv; v++) graph[v].clear(); n   } n   void add_edge(int u, int v) { n     graph[u].push_back(v); n     graph[v].push_back(u); n   } n   void dfs(int u, int p, int d) { n     par[0][u] = p, dep[u] = d; n     for (int i = 0; i < graph[u].size(); i++) n       if (p != graph[u][i]) dfs(graph[u][i], u, d + 1); n   } n   void prepare(int root) { n     dfs(root, ~0, 0); n     for (int k = 0; k + 1 < LOGV; k++) n       for (int v = 0; v < nv; v++) { n         if (!~par[k][v]) n           par[k + 1][v] = ~0; n         else n           par[k + 1][v] = par[k][par[k][v]]; n       } n   } n   int get(int u, int v) { n     if (dep[u] > dep[v]) swap(u, v); n     for (int k = 0; k < LOGV; k++) n       if (dep[v] - dep[u] >> k & 1) v = par[k][v]; n     if (u == v) return u; n     for (int k = LOGV - 1; ~k; --k) n       if (par[k][u] != par[k][v]) u = par[k][u], v = par[k][v]; n     return par[0][u]; n   } n }; n LowestCommonAncestor lca; n int name[N]; n int main() { n   int i, j, tcc, tc = 1 << 28; n   for (tcc = 0; tcc < tc; tcc++) { n     n = getint(), m = getint(); n     brg.init(n); n     for (i = 0; i < m; i++) { n       us[i] = getint() - 1; n       vs[i] = getint() - 1; n       brg.add_edge(us[i], vs[i]); n     } n     brg.proc(); n     k = getint(); n     for (i = 0; i < k; i++) { n       as[i] = getint() - 1; n       bs[i] = getint() - 1; n     } n     uf.init(n); n     for (i = 0; i < m; i++) n       if (!brg.is_bridge(us[i], vs[i])) { n         uf.connect(us[i], vs[i]); n       } n     int M = 0; n     for (i = 0; i < n; i++) n       if (uf.root(i) == i) { n         name[i] = M++; n       } n     lca.init(M); n     for (i = 0; i < m; i++) n       if (brg.is_bridge(us[i], vs[i])) { n         int uu = name[uf.root(us[i])]; n         int vv = name[uf.root(vs[i])]; n         lca.add_edge(uu, vv); n       } n     lca.prepare(0); n     for (i = 0; i < k; i++) { n       int uu = name[uf.root(as[i])]; n       int vv = name[uf.root(bs[i])]; n       int a = lca.dep[uu]; n       int b = lca.dep[vv]; n       int c = lca.dep[lca.get(uu, vv)]; n       printf( %d n , a + b - 2 * c); n     } n   } n   return 0; n } n