#include <bits/stdc++.h> n namespace my_std { n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n template <typename T> n inline T rnd(T first, T second) { n   return uniform_int_distribution<T>(first, second)(rng); n } n template <typename T> n inline bool chkmax(T &x, T y) { n   return x < y ? x = y, 1 : 0; n } n template <typename T> n inline bool chkmin(T &x, T y) { n   return x > y ? x = y, 1 : 0; n } n template <typename T> n inline void read(T &t) { n   t = 0; n   char f = 0, ch = getchar(); n   double d = 0.1; n   while (ch >  9  || ch <  0 ) f |= (ch ==  - ), ch = getchar(); n   while (ch <=  9  && ch >=  0 ) t = t * 10 + ch - 48, ch = getchar(); n   if (ch ==  . ) { n     ch = getchar(); n     while (ch <=  9  && ch >=  0 ) t += d * (ch ^ 48), d *= 0.1, ch = getchar(); n   } n   t = (f ? -t : t); n } n template <typename T, typename... Args> n inline void read(T &t, Args &...args) { n   read(t); n   read(args...); n } n char __sr[1 << 21], __z[20]; n int __C = -1, __zz = 0; n inline void Ot() { fwrite(__sr, 1, __C + 1, stdout), __C = -1; } n inline void print(int x) { n   if (__C > 1 << 20) Ot(); n   if (x < 0) __sr[++__C] =  - , x = -x; n   while (__z[++__zz] = x % 10 + 48, x /= 10) n     ; n   while (__sr[++__C] = __z[__zz], --__zz) n     ; n   __sr[++__C] =   n ; n } n void file() {} n inline void chktime() {} n long long ksm(long long x, int y) { n   long long ret = 1; n   for (; y; y >>= 1, x = x * x) n     if (y & 1) ret = ret * x; n   return ret; n } n }  // namespace my_std n using namespace my_std; n int n, T, _cnt; n pair<int, int> D[403030 >> 1]; n int _w[403030 >> 1]; n void init() { n   static int first[403030], second[403030], p[403030], _l[403030], _r[403030]; n   for (int i = (1); i <= (n); i++) n     read(first[i], second[i]), chkmax(first[i], 0); n   int m = 0, K = 0; n   for (int i = (1); i <= (n); i++) n     if (second[i] >= first[i] && second[i] - first[i] < 2 * T - 2) n       p[++m] = first[i], p[++m] = second[i], ++K, _l[K] = first[i], n       _r[K] = second[i]; n     else if (second[i] >= first[i]) n       ++_cnt; n   sort(p + 1, p + m + 1); n   m = unique(p + 1, p + m + 1) - p - 1; n   n = K; n   for (int i = (1); i <= (n); i++) first[i] = _l[i], second[i] = _r[i]; n   for (int i = (1); i <= (n); i++) n     first[i] = lower_bound(p + 1, p + m + 1, first[i]) - p, n     second[i] = lower_bound(p + 1, p + m + 1, second[i]) - p; n   long long dt = p[1]; n   p[1] = 0; n   for (int i = (2); i <= (m); i++) n     if ((p[i] -= dt) > p[i - 1] + 2ll * T) n       dt += p[i] - (p[i - 1] + 2 * T), p[i] = p[i - 1] + 2 * T; n   for (int i = (1); i <= (n); i++) n     D[i] = make_pair(p[first[i]], p[second[i]] + 1); n   sort(D + 1, D + n + 1); n   for (int i = (1); i <= (n); i++) { n     int second = D[i].second; n     int x = lower_bound(D + 1, D + n + 1, make_pair(second, -1)) - D; n     ++_w[i], --_w[x]; n   } n   for (int i = (1); i <= (n); i++) _w[i] += _w[i - 1]; n } n vector<pair<int, int> > Dec[403030 << 1]; n struct hh { n   int tp, ti, first, second; n   hh(int a, int b, int c, int d) { tp = a, ti = b, first = c, second = d; } n   const bool operator<(const hh &a) const { n     return ti == a.ti ? tp < a.tp : ti < a.ti; n   } n }; n vector<hh> op[403030 << 1]; n vector<pair<int, int> > inc[403030 << 1]; n const int Tree = 403030 * 35; n int ch[Tree][2], mx[Tree], cc; n int root[403030 << 1]; n void add(int &k, int first, int second, int x, int y, int w) { n   if (!k) return; n   int kk = k; n   k = ++cc; n   ch[k][0] = ch[kk][0], ch[k][1] = ch[kk][1], mx[k] = mx[kk]; n   if (x <= first && second <= y) return mx[k] += w, void(); n   int tg = mx[k] - max(mx[ch[k][0]], mx[ch[k][1]]), mid = (first + second) >> 1; n   if (x <= mid) add(ch[k][0], first, mid, x, y, w); n   if (y > mid) add(ch[k][1], mid + 1, second, x, y, w); n   mx[k] = tg + max(mx[ch[k][0]], mx[ch[k][1]]); n } n int query(int k, int first, int second, int x, int y) { n   if (!k) return -1e7; n   if (x <= first && second <= y) return mx[k]; n   int tg = mx[k] - max(mx[ch[k][0]], mx[ch[k][1]]), mid = (first + second) >> 1, n       res = -1e7; n   if (x <= mid) chkmax(res, query(ch[k][0], first, mid, x, y)); n   if (y > mid) chkmax(res, query(ch[k][1], mid + 1, second, x, y)); n   return res + tg; n } n void modify(int &k, int first, int second, int x, int w) { n   int kk = k; n   k = ++cc; n   mx[k] = mx[kk], ch[k][0] = ch[kk][0], ch[k][1] = ch[kk][1]; n   if (first == second) return chkmax(mx[k], w), void(); n   int mid = (first + second) >> 1; n   int tg = (ch[k][0] || ch[k][1]) ? mx[k] - max(mx[ch[k][0]], mx[ch[k][1]]) : 0; n   w -= tg; n   if (x <= mid) n     modify(ch[k][0], first, mid, x, w); n   else n     modify(ch[k][1], mid + 1, second, x, w); n   mx[k] = max(mx[ch[k][0]], mx[ch[k][1]]) + tg; n } n vector<pair<int, int> > V[3]; n void rebuild(int k, int first, int second, int tg, int tp) { n   if (!k) return; n   if (first == second) return V[tp].push_back(make_pair(first, tg + mx[k])); n   int mid = (first + second) >> 1; n   tg += mx[k] - max(mx[ch[k][0]], mx[ch[k][1]]); n   rebuild(ch[k][0], first, mid, tg, tp), n       rebuild(ch[k][1], mid + 1, second, tg, tp); n } n void Rebuild(int second) { n   int first = max(0, second - 2); n   for (int i = (0); i <= (2); i++) V[i].clear(); n   for (int i = (first); i <= (second); i++) n     rebuild(root[i], 0, T - 1, 0, i - first); n   cc = 0; n   for (int i = (first); i <= (second); i++) { n     root[i] = 0; n     for (auto t : V[i - first]) modify(root[i], 0, T - 1, t.first, t.second); n   } n } n int main() { n   file(); n   read(n, T); n   init(); n   for (int i = (1); i <= (n); i++) { n     op[D[i].first / T].push_back(hh(i, D[i].first % T, 0, 0)); n     if (D[i].second - D[i].first > T) { n       auto add = [&](int first, int second, int re) { n         Dec[first / T].push_back( n             make_pair(first % T, (second % T == 0 ? T : second % T))), n             op[re / T].push_back(hh(-1, re % T, first, second)); n       }; n       int first = D[i].first, second = D[i].second - T; n       if (first % T < second % T || second % T == 0) n         add(first, second, D[i].second); n       else n         add(first, first - first % T + T, D[i].second), n             add(second - second % T, second, D[i].second); n     } n     int first = D[i].first, second = D[i].second; n     while (first - first % T + T <= second) n       inc[first / T].push_back(make_pair(first % T, T)), n           first = first - first % T + T; n     if (first < second) n       inc[first / T].push_back(make_pair(first % T, second % T)); n   } n   mx[0] = -1e7; n   const int RE = n / 10; n   int ti = 0; n   for (int i = (0); i <= (4 * n); i++) { n     if (i) root[i] = root[i - 1]; n     for (auto p : inc[i]) { n       add(root[i], 0, T - 1, p.first, p.second - 1, 1); n       if ((++ti) > RE) ti = 0, Rebuild(i); n     } n     sort(op[i].begin(), op[i].end()); n     for (auto p : op[i]) { n       ++ti; n       if (p.tp == -1) n         add(root[p.first / T], 0, T - 1, p.first % T, n             (p.second % T == 0 ? T - 1 : p.second % T - 1), 1); n       else { n         int x = p.ti, w = 0; n         if (i > 0) chkmax(w, query(root[i - 1], 0, T - 1, 0, x)); n         if (i > 1) chkmax(w, mx[root[i - 2]]); n         modify(root[i], 0, T - 1, x, w + _w[p.tp]); n       } n       if (ti > RE) ti = 0, Rebuild(i); n     } n     for (auto p : Dec[i]) { n       add(root[i], 0, T - 1, p.first, p.second - 1, -1); n       if ((++ti) > RE) ti = 0, Rebuild(i); n     } n   } n   cout << max(0, mx[root[n * 4]]) + _cnt; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 2000 + 10; n int n, k, a[MAX_N], dp[MAX_N]; n bool check(int x) { n   for (int i = 0; i < n; i++) { n     dp[i] = 1; n     for (int j = i - 1; ~j; j--) n       if (abs(a[i] - a[j]) <= 1LL * (i - j) * x) dp[i] = max(dp[i], dp[j] + 1); n     if (n - dp[i] <= k) return true; n   } n   return false; n } n int main() { n   ios_base ::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); n   cin >> n >> k; n   for (int i = 0; i < n; i++) cin >> a[i]; n   int L = -1, R = 2e9 + 10; n   while (L + 1 < R) { n     int mid = (1LL * L + R) >> 1; n     check(mid) ? R = mid : L = mid; n   } n   cout << R << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n enum actions { JUMP1, UP1, DOWN1, JUMP2, UP2, DOWN2, NONE }; n int n, x; n vector<vector<int> > v(6); n bool wut(int state, int i, actions last, int water) { n   if (water - 1 >= i) return false; n   if (state == 1) { n     if (n < 50000) { n       if (v[JUMP1][i] == 1) { n         bool isTrue = wut(2, i + x, JUMP1, water + 1); n         if (isTrue == false) n           v[JUMP1][i] = 0; n         else n           return true; n       } else if (v[JUMP1][i] == 2) n         return true; n     } n     if (v[UP1][i] == 1 && last != DOWN1) { n       bool isTrue = wut(state, i + 1, UP1, water + 1); n       if (isTrue == false) n         v[UP1][i] = 0; n       else n         return true; n     } else if (v[UP1][i] == 2) n       return true; n     if (v[DOWN1][i] == 1 && last != UP1) { n       bool isTrue = wut(state, i - 1, DOWN1, water + 1); n       if (isTrue == false) n         v[DOWN1][i] = 0; n       else n         return true; n     } n     if (n >= 50000) { n       if (v[JUMP1][i] == 1) { n         bool isTrue = wut(2, i + x, JUMP1, water + 1); n         if (isTrue == false) n           v[JUMP1][i] = 0; n         else n           return true; n       } else if (v[JUMP1][i] == 2) n         return true; n     } n   } else { n     if (n < 50000) { n       if (v[JUMP2][i] == 1) { n         bool isTrue = wut(1, i + x, JUMP2, water + 1); n         if (isTrue == false) n           v[JUMP2][i] = 0; n         else n           return true; n       } else if (v[JUMP2][i] == 2) n         return true; n     } n     if (v[UP2][i] == 1 && last != DOWN2) { n       bool isTrue = wut(state, i + 1, UP2, water + 1); n       if (isTrue == false) n         v[UP2][i] = 0; n       else n         return true; n     } else if (v[UP2][i] == 2) n       return true; n     if (v[DOWN2][i] == 1 && last != UP2) { n       bool isTrue = wut(state, i - 1, DOWN2, water + 1); n       if (isTrue == false) n         v[DOWN2][i] = 0; n       else n         return true; n     } n     if (n >= 50000) { n       if (v[JUMP2][i] == 1) { n         bool isTrue = wut(1, i + x, JUMP2, water + 1); n         if (isTrue == false) n           v[JUMP2][i] = 0; n         else n           return true; n       } else if (v[JUMP2][i] == 2) n         return true; n     } n   } n   return false; n } n int main() { n   cin >> n >> x; n   string first; n   string second; n   cin >> first; n   cin >> second; n   for (int i = 0; i < 6; i++) v[i].assign(n, 0); n   for (int i = 0; i < first.size(); i++) { n     if (first[i] !=  X ) { n       if (i != first.size() - 1 && first[i + 1] !=  X ) v[UP1][i] = 1; n       if (i > 0 && first[i - 1] !=  X ) v[DOWN1][i] = 1; n       if (i + x < first.size() && second[i + x] !=  X ) v[JUMP1][i] = 1; n       if (i == first.size() - 1) v[UP1][i] = 2; n       if (i + x >= first.size()) v[JUMP1][i] = 2; n     } n     if (second[i] !=  X ) { n       if (i != second.size() - 1 && second[i + 1] !=  X ) v[UP2][i] = 1; n       if (i > 0 && second[i - 1] !=  X ) v[DOWN2][i] = 1; n       if (i + x < second.size() && first[i + x] !=  X ) v[JUMP2][i] = 1; n       if (i == second.size() - 1) v[UP2][i] = 2; n       if (i + x >= second.size()) v[JUMP2][i] = 2; n     } n   } n   if (wut(1, 0, NONE, 0)) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, ans; n struct aa { n   int l, r; n   int v; n }; n bool operator<(aa a, aa b) { return a.r < b.r; } n inline aa qwq(int l, int r, int v) { n   aa a; n   a.l = l; n   a.r = r; n   a.v = v; n   return a; n } n set<aa> s; n int read() { n   register int x = 0, ch = getchar(); n   while (!isdigit(ch)) ch = getchar(); n   while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar(); n   return x; n } n void wt() { n   for (set<aa>::iterator i = s.begin(); i != s.end(); i++) { n     cout << i->l <<     << i->r <<     << i->v <<   n ; n   } n   cout <<  ------ n ; n } n void spliT(set<aa>::iterator i, int x) { n   int l = i->l; n   int r = i->r; n   int v = i->v; n   if (x >= r) return; n   if (x < l) return; n   s.erase(i); n   s.insert(qwq(l, x, v)); n   s.insert(qwq(x + 1, r, v)); n   if (v == 1) ans++; n } n void mergE(set<aa>::iterator i) { n   int l = i->l, r = i->r, v = i->v; n   set<aa>::iterator j = i, k = i; n   if (l != 1) { n     j--; n     if (j->v == v) { n       l = j->l; n       s.erase(j); n       if (v == 1) ans--; n     } n   } n   if (r != n) { n     k++; n     if (k->v == v) { n       r = k->r; n       s.erase(k); n       if (v == 1) ans--; n     } n   } n   s.erase(i); n   s.insert(qwq(l, r, v)); n } n void Ass(int l, int r) { n   set<aa>::iterator x = s.lower_bound((aa){0, l - 1, 0}); n   if (l != 1) spliT(x, l - 1); n   set<aa>::iterator y = s.lower_bound((aa){0, r, 0}); n   spliT(y, r); n   x = s.lower_bound((aa){0, l, 0}); n   y = s.lower_bound((aa){0, r + 1, 0}); n   for (set<aa>::iterator i = x; i != y; i++) { n     if (i->v == 1) ans--; n   } n   s.erase(x, y); n   s.insert(qwq(l, r, 1)); n   ans++; n   x = s.lower_bound((aa){0, l, 0}); n   mergE(x); n } n signed main() { n   n = 1000000005; n   cin >> m; n   s.insert(qwq(1, n, 0)); n   for (int i = 1; i <= m; i++) { n     int l, r; n     l = read(); n     r = read(); n     r--; n     Ass(l, r); n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 0x3f3f3f3f3f3f3f3f; n const long long MAXN = 1e5 + 7; n const long long MAXM = 1e5 + 7; n const long long MOD = 1e9 + 7; n const double eps = 1e-6; n const double pi = acos(-1.0); n long long a[200005]; n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) scanf( %lld , &a[i]); n   sort(a + 1, a + 1 + n); n   long long ans = 0x3f3f3f3f; n   for (int i = 1; i <= n / 2; i++) ans = min(ans, a[i + n / 2] - a[i]); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   map<pair<int, int>, int> mp; n   map<int, int> mp1; n   vector<pair<int, int>> v; n   for (int i = 0; i < m; i++) { n     int x, y; n     cin >> x >> y; n     mp1[x]++; n     mp1[y]++; n     mp[{x, y}]++; n     mp[{y, x}]++; n   } n   bool f = 0; n   for (int i = 1; i <= n; i++) { n     v.push_back({mp1[i], i}); n   } n   sort(v.begin(), v.end()); n   for (int i = 0; i < v.size(); i++) { n     if (f) break; n     for (int j = i - 1; j > -1 && v[i].first + v[j].first >= m; j--) { n       int x = v[i].second, y = v[j].second; n       int ans = 0; n       ans += mp1[x]; n       ans += mp1[y]; n       ans -= mp[{x, y}]; n       if (ans >= m) { n         f = 1; n         break; n       } n     } n   } n   if (f) n     cout <<  YES ; n   else n     cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   vector<long long> a; n   vector<int> pos; n   for (int i = n; i > 0; i--) { n     long long p; n     cin >> p; n     if (p == 0) continue; n     a.push_back(p); n     pos.push_back(i); n   } n   reverse(a.begin(), a.end()); n   reverse(pos.begin(), pos.end()); n   if (a.empty()) { n     cout << string(n,  0 ); n     return 0; n   } n   int sz = a.size(); n   vector<int> last_id(sz); n   for (int i = sz - 1; i >= 0; i--) { n     if (i < sz - 1 && a[i] == a[i + 1]) n       last_id[i] = last_id[i + 1]; n     else n       last_id[i] = i; n   } n   auto get_sum = [&](int l, int r) { n     return 1LL * r * (r + 1) / 2 - 1LL * (l - 1) * l / 2; n   }; n   auto solve = [&](long long sum, int l, int r) { n     vector<pair<int, int>> res; n     if (sum == 0) return res; n     if (l > r) { n       res = {{-1, -1}}; n       return res; n     } n     if (sum < 0 || sum > get_sum(l, r)) { n       res = {{-1, -1}}; n       return res; n     } n     if (sum == get_sum(l, r)) { n       res.emplace_back(l, r); n       return res; n     } n     int lo = 0, hi = r - l + 1; n     while (hi - lo > 1) { n       int mid = (hi + lo) >> 1; n       if (sum >= get_sum(l, l + mid - 1)) n         lo = mid; n       else n         hi = mid; n     } n     int st = lo; n     if (sum > get_sum(r - st + 1, r)) { n       res = {{-1, -1}}; n       return res; n     } n     int skip = r - (l + st - 1); n     long long add = sum - get_sum(l, l + st - 1); n     int cnt = add / skip; n     pair<int, int> a = {l, l + st - 1 - cnt}; n     pair<int, int> b = {r - cnt + 1, r}; n     if (add > skip * cnt) { n       int c = a.second; n       a.second--; n       c += add - 1LL * skip * cnt; n       res.push_back({c, c}); n     } n     if (a.first <= a.second) res.push_back(a); n     if (b.first <= b.second) res.push_back(b); n     return res; n   }; n   auto check = [&](vector<pair<int, int>> foo) { n     return !(foo.size() == 1 && foo[0] == make_pair(-1, -1)); n   }; n   vector<long long> supose(n + 1); n   for (int i = n; i > 0; i--) { n     int p = lower_bound(pos.begin(), pos.end(), i) - pos.begin(); n     if (pos[p] == i) n       supose[i] = a[p]; n     else n       supose[i] = a[p] - 1; n   } n   vector<bool> dp(n + 1); n   vector<int> par(n + 1); n   vector<vector<pair<int, int>>> aux_seg(n + 1); n   vector<int> last_true(sz); n   int go_from = pos.back(); n   auto add = [&](int from, int to, int l, int r) { n     long long sum = supose[from] - from; n     if (to <= n) sum -= supose[to]; n     auto foo = solve(sum, l, r); n     if (check(foo)) { n       dp[from] = true; n       par[from] = to; n       aux_seg[from] = foo; n     } n   }; n   for (int cur = go_from; cur > 0; cur--) { n     int p = lower_bound(pos.begin(), pos.end(), cur) - pos.begin(); n     if (pos[p] == cur && p < sz - 1) { n       if (a[p] == a[p + 1]) continue; n       if (a[p] == a[p + 1] - 1) { n         int np = last_id[p + 1]; n         if (np == sz - 1 || dp[pos[np + 1]]) { n           int l = pos[np] + 1; n           int r = np == sz - 1 ? n : pos[np + 1] - 1; n           add(cur, r + 1, l, r); n         } n         if (last_true[np]) { n           int l = pos[np] + 1; n           int r = last_true[np] - 1; n           add(cur, r + 1, l, r); n         } n       } n     } n     int np = last_id[p]; n     if (np == sz - 1 || dp[pos[np + 1]]) { n       int l = pos[np] + 1; n       int r = np == sz - 1 ? n : pos[np + 1] - 1; n       add(cur, r + 1, l, r); n     } n     if (last_true[np]) { n       int l = pos[np] + 1; n       int r = last_true[np] - 1; n       add(cur, r + 1, l, r); n     } n     if (pos[p] != cur && p && !last_true[p - 1] && dp[cur]) { n       last_true[p - 1] = cur; n     } n   } n   string res(n + 1,  0 ); n   long long bound = -1; n   for (int i = 1; i <= n; i++) { n     if (dp[i] && (bound == -1 || supose[i] == bound - 1)) { n       while (i <= n) { n         res[i] =  1 ; n         for (auto foo : aux_seg[i]) { n           for (int j = foo.first; j <= foo.second; j++) res[j] =  1 ; n         } n         i = par[i]; n       } n       break; n     } n     if (pos[0] == i) { n       bound = a[0]; n     } n   } n   res.erase(res.begin()); n   reverse(res.begin(), res.end()); n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, p; n char a[20000]; n int b[20000]; n int main() { n   cin >> n >> p; n   scanf( %s , a); n   memset(b, -1, sizeof(b)); n   for (int i = 0; i < n; ++i) { n     if (a[i] ==  . ) { n       if (i - p >= 0 && b[i - p] != -1) { n         b[i] = b[i - p] ^ 1; n       } n     } else { n       b[i] = a[i] -  0 ; n       ; n       if (i - p >= 0 && b[i - p] == -1) { n         b[i - p] = b[i] ^ 1; n       } n     } n   } n   for (int i = 0; i < n; ++i) { n     if (b[i] == -1) { n       if (i - p >= 0) n         b[i] = b[i - p] ^ 1; n       else n         b[i] = 0; n     } n   } n   int fg = 0; n   for (int i = 0; i < n; ++i) { n     if (i + p >= n) continue; n     if (b[i] != b[i + p]) fg = 1; n   } n   if (fg == 0) n     puts( No ); n   else { n     for (int i = 0; i < n; ++i) { n       printf( %d , b[i]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   char com[200]; n   char *p; n   int man = 0; n   int sum = 0; n   int i; n   int word; n   while (scanf( %c , com) == 1) { n     i = 1; n     while ((com[i] = getchar()) !=   n ) i++; n     com[i] =   0 ; n     word = 0; n     if (com[0] ==  + ) { n       man++; n       continue; n     } n     if (com[0] ==  - ) { n       man--; n       continue; n     } n     p = strchr(com,  : ); n     p += 1; n     while (*(p++) !=   0 ) { n       word++; n     } n     sum += word * man; n   } n   printf( %d , sum); n } n


#include<bits/stdc++.h> n #define ll long long n #define F first n #define S second n #define endl   n  n using namespace std; n const ll mod=1e9+7; n const int N=5+3e5; n const int INF=1e9; n ll a[3][N],s[3],n[3]; n int x[3]= {0,1,2}; n int main() n { n #ifdef LOCAL n     freopen( input.in ,  r , stdin); n #endif n     ll m1,m2,ans=-1e18; n     cin>>n[0]>>n[1]>>n[2]; n     for(int i=0; i<n[0]; ++i) n     { n         cin>>a[0][i]; n         s[0]+=a[0][i]; n     } n     for(int i=0; i<n[1]; ++i) n     { n         cin>>a[1][i]; n         s[1]+=a[1][i]; n     } n     for(int i=0; i<n[2]; ++i) n     { n         cin>>a[2][i]; n         s[2]+=a[2][i]; n     } n  n     sort(a[0],a[0]+n[0]); n     sort(a[1],a[1]+n[1]); n     sort(a[2],a[2]+n[2]); n  n     do n     { n         m1=a[x[1]][0]-(s[x[0]]-a[x[0]][n[x[0]]-1]+s[x[2]]-a[x[2]][0]); n         m2=a[x[2]][0]-(s[x[1]]-a[x[1]][0]); n         if(m1>m2) n             swap(m1,m2); n         if(m2>=0) n             ans=max(ans,a[x[0]][n[x[0]]-1]-(m1-m2)); n         else n             ans=max(ans,a[x[0]][n[x[0]]-1]-m1-m2); n     } n     while(next_permutation(x,x+3)); n     cout<<ans<<  n ; n  n  n  n  n  n  n  n  n } n


#include <bits/stdc++.h> n const long long INF = (long long)1e18 + 2; n using namespace std; n void solve(); n void fastIO() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n } n int main() { n   fastIO(); n   solve(); n } n void solve() { n   int n, m; n   cin >> n >> m; n   char a[n][m]; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) cin >> a[i][j]; n   int rs = 200, re = -1, cs = 200, ce = -1; n   bool flag = true; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (a[i][j] ==  B ) { n         if (i < rs) rs = i; n         if (i > re) re = i; n         if (j < cs) cs = j; n         if (j > ce) ce = j; n         flag = false; n       } n     } n   } n   if (flag) { n     cout << 1; n     return; n   } n   int x = re - rs + 1; n   int y = ce - cs + 1; n   int mx = max(x, y); n   if (n < mx || m < mx) { n     cout << -1; n     return; n   } n   int ans = 0; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (a[i][j] ==  B ) ans++; n     } n   } n   cout << (mx * mx - ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b; n   cin >> a >> b; n   if (b % a) { n     cout << -1 <<   n ; n   } else { n     int x = b / a; n     int ans = 0; n     while (x % 2 == 0) { n       ans++; n       x /= 2; n     } n     while (x % 3 == 0) { n       ans++; n       x /= 3; n     } n     if (x != 1) { n       cout << -1 << endl; n     } else { n       cout << ans << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, nn = 0, nm = 0, dr[5069], dh[10069], pd[5069], pr[5069], fq[10069], n              sbt[10069], sm = 0, z = 1e18; n vector<pair<long long, long long>> fz[5069], al[10069]; n pair<long long, long long> sk[5069]; n vector<long long> pst[5069]; n bitset<10069> vtd; n void ae(long long x, long long y, long long w) { n   al[x].push_back({y, w}); n   al[y].push_back({x, w}); n } n void bd(long long x) { n   long long i, sz = al[x].size(), l; n   vtd[x] = 1; n   sbt[x] = fq[x]; n   for (i = 0; i < sz; i++) { n     l = al[x][i].first; n     if (!vtd[l]) { n       bd(l); n       sbt[x] += sbt[l]; n     } n   } n } n void dfs(long long x) { n   long long i, sz = al[x].size(), l, w; n   vtd[x] = 1; n   z = min(z, sm); n   for (i = 0; i < sz; i++) { n     l = al[x][i].first; n     w = al[x][i].second; n     if (!vtd[l]) { n       nn += sbt[x] - sbt[l]; n       sm += w * (nn - (n - nn)); n       dfs(l); n       sm -= w * (nn - (n - nn)); n       nn -= sbt[x] - sbt[l]; n     } n   } n } n int main() { n   long long i, j, k, l, w, ll, c, p = 0, sz, bg, lca; n   for (i = 2; i <= 5000; i++) { n     if (fz[i].empty()) { n       p++; n       for (j = i; j <= 5000; j += i) { n         for (c = 0, k = j; k % i == 0; k /= i, c++) n           ; n         fz[j].push_back({p, c}); n         dr[j] += c; n       } n     } n   } n   nm = 5000; n   for (i = 1; i <= 5000; i++) { n     sz = fz[i].size(); n     lca = dh[i - 1]; n     if (sz) { n       bg = fz[i][sz - 1].first; n       for (j = 1; j < bg; j++) { n         lca -= pd[j]; n       } n     } n     for (j = 0; j < sz; j++) { n       l = fz[i][j].first; n       w = fz[i][j].second; n       pd[l] += w; n     } n     dh[i] = dh[i - 1] + dr[i]; n     l = 0; n     for (; nn && sk[nn].second >= lca; nn--) { n       l = sk[nn].first; n     } n     if (l) { n       nn++; n       sk[nn] = {l, lca}; n       sz = pst[l].size(); n       if (lca < dh[pst[l][sz - 1]]) { n         nm++; n         dh[nm] = lca; n         pst[l].push_back(nm); n         sz++; n       } n       pr[i] = pst[l][sz - 1]; n     } n     nn++; n     sk[nn] = {i, dh[i]}; n     pst[i].push_back(i); n   } n   for (i = 1; i <= 5000; i++) { n     sz = pst[i].size(); n     for (j = 0; j < sz; j++) { n       l = pst[i][j]; n       if (j) { n         ae(ll, l, dh[ll] - dh[l]); n       } n       ll = l; n     } n     if (pr[i]) { n       ae(pst[i][sz - 1], pr[i], dh[pst[i][sz - 1]] - dh[pr[i]]); n     } n   } n   scanf( %lld , &n); n   for (i = 0; i < n; i++) { n     scanf( %lld , &k); n     k += !k; n     fq[k]++; n     sm += dh[k]; n   } n   bd(1); n   vtd.reset(); n   nn = 0; n   dfs(1); n   printf( %lld n , z); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t, n, i, j, k; n   double p, q, m; n   cin >> n >> m; n   p = pow(1.000000011, m); n   q = n * p; n   printf( %.12lf , q); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100005], in[100005]; n int main() { n   int n, m; n   scanf( %d , &n); n   int i, j; n   for (i = 0; i < n; i++) { n     scanf( %d , &in[i]); n     in[i] = ++a[in[i]]; n   } n   for (i = 2; i <= 100000; i++) n     if (a[i] > a[i - 1]) break; n   if (i <= 100000) n     printf( -1 n ); n   else { n     printf( %d n , a[1]); n     for (i = 0; i < n; i++) printf( %d%c , in[i],    n [i == n - 1]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200005; n struct ST { n   int l, r, mx, c; n } t[N << 2]; n int n, k, m, nn, tot, R, sum; n int ls[N], rs[N], a[N], rk[N], sa[N], h[N], tp[N], tax[N], f[N][18], lg[N], n     tag[N], len[N], num[N]; n long long ans[N]; n char s[N]; n void rsort() { n   int i; n   for (i = 0; i <= m; i++) tax[i] = 0; n   for (i = 1; i <= n; i++) tax[rk[tp[i]]]++; n   for (i = 1; i <= m; i++) tax[i] += tax[i - 1]; n   for (i = n; i >= 1; i--) sa[tax[rk[tp[i]]]--] = tp[i]; n } n void suffix() { n   int i; n   for (i = 1; i <= n; i++) rk[i] = a[i], tp[i] = i; n   m = tot; n   rsort(); n   for (int w = 1, p = 0; p < n; w += w, m = p) { n     p = 0; n     for (i = n - w + 1; i <= n; i++) tp[++p] = i; n     for (i = 1; i <= n; i++) n       if (sa[i] > w) tp[++p] = sa[i] - w; n     rsort(); n     swap(rk, tp); n     rk[sa[1]] = p = 1; n     for (i = 2; i <= n; i++) n       if (tp[sa[i]] == tp[sa[i - 1]] && tp[sa[i] + w] == tp[sa[i - 1] + w]) n         rk[sa[i]] = p; n       else n         rk[sa[i]] = ++p; n   } n } n void height() { n   int i, j = 0, k = 0; n   for (i = 1; i <= n; i++) rk[sa[i]] = i; n   for (i = 1; i <= n; i++) { n     if (k) k--; n     if (rk[i] == 1) continue; n     j = sa[rk[i] - 1]; n     while (a[j + k] == a[i + k]) k++; n     h[rk[i]] = k; n   } n } n void build(int k, int l, int r) { n   t[k].l = l; n   t[k].r = r; n   t[k].mx = 0; n   t[k].c = 0; n   if (l == r) return; n   int mid = (l + r) >> 1; n   build(k << 1, l, mid); n   build(k << 1 | 1, mid + 1, r); n } n void add(int k, int w) { n   t[k].mx = max(t[k].mx, w); n   t[k].c = max(t[k].c, w); n } n void pushdown(int k) { n   if (t[k].c) { n     add(k << 1, t[k].c); n     add(k << 1 | 1, t[k].c); n     t[k].c = 0; n   } n } n void modify(int k, int L, int R, int w) { n   if (L <= t[k].l && t[k].r <= R) { n     add(k, w); n     return; n   } n   pushdown(k); n   int mid = (t[k].l + t[k].r) >> 1; n   if (L <= mid) modify(k << 1, L, R, w); n   if (R > mid) modify(k << 1 | 1, L, R, w); n } n int query(int k, int p) { n   if (t[k].l == t[k].r) return t[k].mx; n   pushdown(k); n   int mid = (t[k].l + t[k].r) >> 1; n   if (p <= mid) n     return query(k << 1, p); n   else n     return query(k << 1 | 1, p); n } n void init() { n   int i, j; n   for (i = 1; i <= n; i++) f[i][0] = h[i]; n   for (i = 1; i <= n; i++) lg[i] = log2(i); n   for (i = 1; i <= 17; i++) n     for (j = 1; j + (1 << i) - 1 <= n; j++) n       f[j][i] = min(f[j][i - 1], f[j + (1 << i - 1)][i - 1]); n } n int rmq(int l, int r) { n   l = rk[l]; n   r = rk[r]; n   if (l > r) swap(l, r); n   l++; n   if (l > r) return len[sa[r]]; n   int d = lg[r - l + 1]; n   return min(f[l][d], f[r - (1 << d) + 1][d]); n } n void solve() { n   int i, l1, r1 = 0, l2 = 0, r2 = 0; n   build(1, 1, n); n   for (l1 = 1; l1 <= n; l1++) { n     if (!tag[sa[l1]]) continue; n     if (l1 > 1) { n       num[tag[sa[l1 - 1]]]--; n       if (!num[tag[sa[l1 - 1]]] && tag[sa[l1 - 1]]) sum--; n     } n     while (r1 < n && sum < k) { n       r1++; n       if (!num[tag[sa[r1]]] && tag[sa[r1]]) sum++; n       num[tag[sa[r1]]]++; n     } n     if (sum < k) break; n     modify(1, l1, r1, rmq(sa[l1], sa[r1])); n     if (l2 > 0) n       for (i = r2 + 1; i <= r1; i++) modify(1, i, i, rmq(sa[l2], sa[i])); n     l2 = l1; n     r2 = r1; n   } n   if (r2 < n && l2 > 0) n     for (i = r2 + 1; i <= n; i++) modify(1, i, i, rmq(sa[l2], sa[i])); n } n int main() { n   int i, j; n   scanf( %d%d , &nn, &k); n   tot = 26; n   for (i = 1; i <= nn; i++) { n     scanf( %s , s + 1); n     m = strlen(s + 1); n     ls[i] = n + 1; n     for (j = 1; j <= m; j++) { n       a[++n] = s[j] -  a  + 1; n       tag[n] = i; n       len[n] = m - j + 1; n     } n     rs[i] = n; n     if (i < nn) a[++n] = ++tot; n     if (k == 1) ans[i] = 1ll * m * (m + 1) / 2; n   } n   if (k == 1) { n     for (i = 1; i <= nn; i++) printf( %I64d  , ans[i]); n     return 0; n   } n   a[0] = -1; n   a[n + 1] = 1000000000; n   suffix(); n   height(); n   init(); n   solve(); n   for (i = 1; i <= n; i++) n     if (tag[sa[i]]) ans[tag[sa[i]]] += 1ll * query(1, i); n   for (i = 1; i <= nn; i++) printf( %I64d n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<int>> arr(5, vector<int>(200005)); n int main() { n   int t, n, i, ans, a, b, c, d, e, m, j, s, curr; n   string s1; n   cin >> t; n   while (t--) { n     cin >> n; n     for (i = 0; i < n; i++) { n       cin >> s1; n       a = 0; n       b = 0; n       c = 0; n       d = 0; n       e = 0; n       m = s1.size(); n       for (j = 0; j < m; j++) { n         if (s1[j] ==  a ) n           a++; n         else if (s1[j] ==  b ) n           b++; n         else if (s1[j] ==  c ) n           c++; n         else if (s1[j] ==  d ) n           d++; n         else if (s1[j] ==  e ) n           e++; n       } n       arr[0][i] = a - (m - a); n       arr[1][i] = b - (m - b); n       arr[2][i] = c - (m - c); n       arr[3][i] = d - (m - d); n       arr[4][i] = e - (m - e); n     } n     for (i = 0; i < 5; i++) n       sort(arr[i].begin(), arr[i].begin() + n, greater<int>()); n     ans = 0; n     for (i = 0; i < 5; i++) { n       curr = 0; n       j = 0; n       s = 0; n       while (j < n && arr[i][j] > 0) { n         s += arr[i][j]; n         curr++; n         j++; n       } n       while (j < n && (s + arr[i][j]) > 0) { n         s += arr[i][j]; n         curr++; n         j++; n       } n       ans = max(ans, curr); n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, j, k, l, m, n, f, t; n   string s, s1, s3, s4; n   while (cin >> s) { n     s1 = s; n     k = 0; n     for (i = 0; i < s.size(); i++) { n       k += s[i] -  0 ; n     } n     k = k % 3; n     if (k == 0) { n       cout << s << endl; n     } else if (k == 1) { n       f = 0; n       for (i = s.size() - 1; i >= 0; i--) { n         if ((s[i] -  0 ) % 3 == 1) { n           s.erase(s.begin() + i); n           f = 1; n           break; n         } n       } n       if (f == 0) { n         t = 0; n         for (i = s.size() - 1; i >= 0; i--) { n           if ((s[i] -  0 ) % 3 == 2) { n             s.erase(s.begin() + i); n             t++; n           } n           if (t == 2) { n             f = 1; n             break; n           } n         } n         if (t != 2 || s ==   ) { n           cout << -1 << endl; n         } else { n           t = 0; n           s3 = s; n           for (i = 0; i < s.size(); i++) { n             if (s[i] ==  0 ) { n               s.erase(s.begin() + i); n               i--; n             } else { n               break; n             } n           } n           if (s ==    && s3.size() > 0) n             cout << 0 << endl; n           else n             cout << s << endl; n         } n       } else { n         t = 0; n         for (i = s1.size() - 1; i >= 0; i--) { n           if ((s1[i] -  0 ) % 3 == 2) { n             s1.erase(s1.begin() + i); n             t++; n           } n           if (t == 2) { n             break; n           } n         } n         if (t == 2) { n           s3 = s; n           for (i = 0; i < s.size(); i++) { n             if (s[i] ==  0 ) { n               s.erase(s.begin() + i); n               i--; n             } else { n               break; n             } n           } n           for (i = 0; i < s1.size(); i++) { n             if (s1[i] ==  0 ) { n               s1.erase(s1.begin() + i); n               i--; n             } else { n               break; n             } n           } n           if (s == s1 && s ==    && s3.size() > 0) { n             cout << 0 << endl; n           } else if (s == s1 && s ==   ) { n             cout << -1 << endl; n           } else if (s.size() > s1.size()) { n             cout << s << endl; n           } else { n             cout << s1 << endl; n           } n         } else { n           if (s ==   ) { n             cout << -1 << endl; n           } else { n             t = 0; n             s3 = s; n             for (i = 0; i < s.size(); i++) { n               if (s[i] ==  0 ) { n                 s.erase(s.begin() + i); n                 i--; n               } else { n                 break; n               } n             } n             if (s ==    && s3.size() > 0) n               cout << 0 << endl; n             else n               cout << s << endl; n           } n         } n       } n     } else if (k == 2) { n       f = 0; n       for (i = s.size() - 1; i >= 0; i--) { n         if ((s[i] -  0 ) % 3 == 2) { n           s.erase(s.begin() + i); n           f = 1; n           break; n         } n       } n       if (f == 0) { n         t = 0; n         for (i = s.size() - 1; i >= 0; i--) { n           if ((s[i] -  0 ) % 3 == 1) { n             s.erase(s.begin() + i); n             t++; n           } n           if (t == 2) { n             f = 1; n             break; n           } n         } n         if (t != 2 || s ==   ) { n           cout << -1 << endl; n         } else { n           t = 0; n           s3 = s; n           for (i = 0; i < s.size(); i++) { n             if (s[i] ==  0 ) { n               s.erase(s.begin() + i); n               i--; n             } else { n               break; n             } n           } n           if (s ==    && s3.size() > 0) n             cout << 0 << endl; n           else n             cout << s << endl; n         } n       } else { n         t = 0; n         for (i = s1.size() - 1; i >= 0; i--) { n           if ((s1[i] -  0 ) % 3 == 1) { n             s1.erase(s1.begin() + i); n             t++; n           } n           if (t == 2) { n             break; n           } n         } n         if (t == 2) { n           s3 = s; n           for (i = 0; i < s.size(); i++) { n             if (s[i] ==  0 ) { n               s.erase(s.begin() + i); n               i--; n             } else { n               break; n             } n           } n           for (i = 0; i < s1.size(); i++) { n             if (s1[i] ==  0 ) { n               s1.erase(s1.begin() + i); n               i--; n             } else { n               break; n             } n           } n           if (s == s1 && s ==    && s3.size() > 0) { n             cout << 0 << endl; n           } else if (s == s1 && s ==   ) { n             cout << -1 << endl; n           } else if (s.size() > s1.size()) { n             cout << s << endl; n           } else { n             cout << s1 << endl; n           } n         } else { n           if (s ==   ) { n             cout << -1 << endl; n           } else { n             t = 0; n             s3 = s; n             for (i = 0; i < s.size(); i++) { n               if (s[i] ==  0 ) { n                 s.erase(s.begin() + i); n                 i--; n               } else { n                 break; n               } n             } n             if (s ==    && s3.size() > 0) n               cout << 0 << endl; n             else n               cout << s << endl; n           } n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e9; n int c2i(char c) { n   if (c <=  9 ) return c -  0 ; n   return c -  A  + 10; n } n long long conv(string num, int base) { n   long long res = 0; n   for (int i = 0; i < (int)num.length(); i++) { n     if (c2i(num[i]) >= base) return INF; n     res = res * base + c2i(num[i]); n   } n   return res; n } n int main() { n   string inp, h, m; n   cin >> inp; n   for (int i = 0; i < (int)inp.length(); i++) n     if (inp[i] ==  : ) inp[i] =    ; n   istringstream sin(inp); n   sin >> h >> m; n   vector<int> res; n   for (int base = 2; base <= 100; base++) n     if (conv(h, base) < 24 && conv(m, base) < 60) res.push_back(base); n   if (res.empty()) n     cout << 0 << endl; n   else if (res.back() == 100) n     cout << -1 << endl; n   else { n     for (int i = 0; i < (int)res.size(); i++) cout << res[i] <<    ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n int n; n int m; n int a, b; n long long fast_mod_pow(long long a, long long b) { n   long long res = 1; n   a %= mod; n   while (b) { n     if (b & 1) { n       res = (res * a) % mod; n     } n     a = (a * a) % mod; n     b >>= 1; n   } n   return res; n } n const int MAXN = 1000005; n long long fac[MAXN]; n long long invfact[MAXN]; n int main() { n   cin >> n >> m >> a >> b; n   long long ans = 0; n   fac[0] = 1; n   fac[1] = 1; n   for (int i = 2; i < MAXN; i++) { n     fac[i] = fac[i - 1] * i; n     fac[i] %= mod; n   } n   invfact[MAXN - 1] = fast_mod_pow(fac[MAXN - 1], mod - 2); n   for (int i = MAXN - 2; i >= 0; i--) { n     invfact[i] = (invfact[i + 1] * (i + 1)) % mod; n   } n   for (int i = 1; i <= m; i++) { n     if (i > n - 1) break; n     long long temp = 1; n     temp *= fac[m - 1]; n     temp %= mod; n     temp *= invfact[m - i]; n     temp %= mod; n     temp *= invfact[i - 1]; n     temp %= mod; n     temp *= fac[n - 2]; n     temp %= mod; n     temp *= invfact[n - i - 1]; n     temp %= mod; n     if ((n - i - 1) == 0) { n       ans += temp; n       ans %= mod; n       continue; n     } n     temp *= fast_mod_pow((long long)m, (long long)(n - i - 1)); n     temp %= mod; n     temp *= (i + 1); n     temp %= mod; n     temp *= fast_mod_pow((long long)n, (long long)(n - i - 2)); n     temp %= mod; n     ans += temp; n     ans %= mod; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool comp(pair<float, int> a, pair<float, int> b) { n   if (a.first > b.first) n     return true; n   else if (a.first == b.first) n     return a.second < b.second; n   else n     return false; n } n inline istream& skip_endl(istream& is) { n   return is.ignore(numeric_limits<streamsize>::max(),   n ); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   long double t1, t2, k, a, b, h1, h2; n   cin >> n >> t1 >> t2 >> k; n   vector<pair<long double, int>> heights; n   for (int i = 1; i <= n; i++) { n     cin >> a >> b; n     h1 = (a * t1) - (a * t1 * (k / 100.0)) + (b * t2); n     h2 = (b * t1) - (b * t1 * (k / 100.0)) + (a * t2); n     heights.push_back(make_pair(max(h1, h2), i)); n   } n   sort(heights.begin(), heights.end(), comp); n   for (auto h : heights) { n     cout << fixed << setprecision(2) << h.second; n     cout <<     << h.first <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937_64 rd(787); n int a[500010]; n int cnt[500010]; n unsigned long long has[500010]; n unsigned long long val[500010]; n list<int> vec[500010]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   auto t = clock(); n   auto now_time = [&] { return (clock() - t) / (double)CLOCKS_PER_SEC; }; n   int n; n   cin >> n; n   unsigned long long anss = 1e18; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   while (now_time() < 4) { n     for (int i = 1; i <= n; i++) val[i] = rd(), vec[i].clear(); n     unsigned long long ans = 0; n     map<unsigned long long, int> mp; n     mp[0]++; n     int pre = 0; n     for (int i = 1; i <= n; i++) { n       int tmp = a[i]; n       has[i] = has[i - 1] + val[tmp], cnt[tmp]++, vec[tmp].push_back(i); n       if (cnt[tmp] % 3 == 0) { n         has[i] -= 3 * val[tmp]; n       } n       mp[has[i]]++; n       if (vec[tmp].size() > 3) { n         int now = vec[tmp].front(); n         vec[tmp].pop_front(); n         for (; pre < now; pre++) { n           mp[has[pre]]--; n         } n       } n       ans += mp[has[i]] - 1; n     } n     anss = min(ans, anss); n     break; n   } n   cout << anss << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int N; n vector<int> V; n bool solve(int n); n int main() { n   ios_base::sync_with_stdio(false); n   int i, st, dr, mid; n   cin >> N; n   V.resize(N); n   for (i = 0; i < N; ++i) { n     cin >> V[i]; n   } n   sort(V.begin(), V.end()); n   st = 1; n   dr = N; n   while (st < dr) { n     mid = (st + dr) / 2; n     if (solve(mid)) { n       dr = mid; n     } else { n       st = mid + 1; n     } n   } n   cout << dr <<   n ; n   return 0; n } n bool solve(int n) { n   int i, j, nr; n   vector<int> piles; n   piles.resize(n, 101); n   j = 0; n   for (i = N - 1; i >= 0; --i) { n     nr = 0; n     while (piles[j] == 0) { n       ++j; n       ++nr; n       if (j == n) j = 0; n       if (nr == n + 1) break; n     } n     if (nr == n + 1) break; n     piles[j] = min(piles[j] - 1, V[i]); n     ++j; n     if (j == n) j = 0; n   } n   if (i == -1) { n     return true; n   } n   return false; n } n


#include <bits/stdc++.h> n using namespace std; n string s, t; n int l = 0, r = 0; n int main() { n   cin >> s >> t; n   while (s[l] !=  | ) l++; n   r = s.size() - l - 1; n   int dif; n   if (l > r) n     dif = t.size() - (l - r); n   else n     dif = t.size() - (r - l); n   if (dif < 0 || dif & 1) { n     cout <<  Impossible  << endl; n     return 0; n   } n   if (l < r) { n     reverse(s.begin(), s.end()); n     int i = 0; n     while (l < r) { n       s += t[i]; n       i++; n       l++; n     } n     while (i < t.size()) { n       s += t[i]; n       i++; n       s = t[i] + s; n       i++; n     } n     reverse(s.begin(), s.end()); n     cout << s << endl; n     return 0; n   } n   int i = 0; n   while (r < l) { n     s += t[i]; n     i++; n     r++; n   } n   while (i < t.size()) { n     s += t[i]; n     i++; n     s = t[i] + s; n     i++; n   } n   cout << s << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long fib[100]; n void init() { n   fib[0] = 1, fib[1] = 2; n   for (int i = 2; i <= 85; i++) fib[i] = fib[i - 1] + fib[i - 2]; n } n int w[100]; n int dp[100][2]; n void solve(long long x) { n   memset(w, 0, sizeof(w)); n   memset(dp, 0, sizeof(dp)); n   int num = 0; n   for (int i = 85; i >= 0; i--) { n     if (x >= fib[i]) { n       x -= fib[i]; n       w[num++] = i; n     } n   } n   num--; n   dp[0][1] = 1; n   dp[0][0] = w[num] >> 1; n   int i = 0; n   while (num > 0) { n     num--; n     dp[i + 1][0] = dp[i][0] * ((w[num] - w[num + 1]) >> 1) + n                    dp[i][1] * ((w[num] - w[num + 1] - 1) >> 1); n     dp[i + 1][1] = dp[i][0] + dp[i][1]; n     i++; n   } n   cout << dp[i][0] + dp[i][1] << endl; n } n int main() { n   ios::sync_with_stdio(false); n   init(); n   int t; n   cin >> t; n   while (t--) { n     long long x; n     cin >> x; n     solve(x); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a, s, d, n; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a >> s; n     if (s - a >= 2) d++; n   } n   cout << d; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000005; n int n, t1, t2, cnt; n vector<int> mem[N]; n int imp[N], hgt[N], res[N]; n int p[N], noww[2 * N], goal[2 * N]; n void link(int f, int t) { n   noww[++cnt] = p[f]; n   goal[cnt] = t, p[f] = cnt; n } n void DFS(int nde, int fth) { n   for (int i = p[nde]; i; i = noww[i]) n     if (goal[i] != fth) { n       DFS(goal[i], nde); n       if (hgt[nde] <= hgt[goal[i]]) n         hgt[nde] = hgt[goal[i]] + 1, imp[nde] = goal[i]; n     } n   if (!imp[nde]) n     mem[nde].push_back(1); n   else { n     swap(mem[nde], mem[imp[nde]]), res[nde] = res[imp[nde]]; n     for (int i = p[nde]; i; i = noww[i]) n       if (goal[i] != fth && goal[i] != imp[nde]) { n         int s1 = mem[nde].size(), s2 = mem[goal[i]].size(); n         for (int j = 0; j < s2; j++) { n           mem[nde][s1 - s2 + j] += mem[goal[i]][j]; n           if (mem[nde][res[nde]] <= mem[nde][s1 - s2 + j]) n             res[nde] = s1 - s2 + j; n         } n       } n     mem[nde].push_back(1); n     if (mem[nde][res[nde]] == 1) res[nde] = mem[nde].size() - 1; n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i < n; i++) { n     scanf( %d%d , &t1, &t2); n     link(t1, t2), link(t2, t1); n   } n   DFS(1, 0); n   for (int i = 1; i <= n; i++) printf( %d n , hgt[i] - res[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (!isdigit(ch)) f = ch ==  -  ? -1 : f, ch = getchar(); n   while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar(); n   return x * f; n } n const int N = 200050; n int sta[3][N], f[3][N], F[3]; n int n, m, s, e; n int pos[N]; n void dp() { n   for (int t = 0; t < 3; t++) n     for (int i = sta[t][0] - 1; i >= 1; i--) n       f[t][i] = f[t][i + 1] + max(sta[t][i + 1] - sta[t][i] - s, 0); n } n int binary_search(int t, int x) { n   int ret, l = 1, r = sta[t][0], mid; n   while (l <= r) { n     mid = l + r >> 1; n     if (sta[t][mid] >= x) n       ret = mid, r = mid - 1; n     else n       l = mid + 1; n   } n   return ret; n } n int main() { n   pos[0] = e = read(), s = read(), n = read(), m = read(); n   for (int i = 0; i < 3; i++) sta[i][++sta[i][0]] = pos[0]; n   for (int i = 1, tp; i <= n; i++) { n     tp = read(), pos[i] = read(); n     if (pos[i] >= e) continue; n     switch (tp) { n       case 3: n         sta[2][++sta[2][0]] = pos[i]; n       case 2: n         sta[1][++sta[1][0]] = pos[i]; n       case 1: n         sta[0][++sta[0][0]] = pos[i]; n     } n   } n   sort(sta[0] + 1, sta[0] + sta[0][0] + 1), n       sort(sta[1] + 1, sta[1] + sta[1][0] + 1), n       sort(sta[2] + 1, sta[2] + sta[2][0] + 1); n   dp(); n   for (int i = 1, x; i <= m; i++) { n     x = read(); n     for (int t = 0; t < 3; t++) { n       int y = binary_search(t, x); n       F[t] = f[t][y] + max(sta[t][y] - x - s, 0); n     } n     if (F[0] > 0) n       printf( -1 -1 n ); n     else n       printf( %d %d n , F[1], F[2] - F[1]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct ans { n   int s, t; n }; n const int nmax = 100006; n int n, v[nmax], s1[nmax], s2[nmax], rasp, acts, fp1[nmax], fp2[nmax]; n ans vrasp[nmax]; n bool ver; n int compar(ans a, ans b) { n   if (a.t != b.t) n     return a.t < b.t; n   else n     return a.s < b.s; n } n int main() { n   int player_unu = 0; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> v[i]; n     s1[i] = s1[i - 1]; n     s2[i] = s2[i - 1]; n     if (v[i] == 1) { n       s1[i]++; n       fp1[s1[i]] = i; n     } else { n       s2[i]++; n       fp2[s2[i]] = i; n     } n   } n   if (v[n] == 2) n     for (int i = 1; i <= n; i++) { n       v[i] = 3 - v[i]; n       swap(s1[i], s2[i]); n       swap(fp1[i], fp2[i]); n     } n   for (int i = n; i > 0; i--) { n     if (s1[n] - s1[i - 1] > s2[n] - s2[i - 1] && v[i] == 1) { n       acts = s1[n] - s1[i - 1]; n       int nrs1 = 0, nrs2 = 0, pozact = i; n       ver = 0; n       for (int j = 0; j < n;) { n         if (s1[j] + acts > s1[n] && s2[j] + acts > s2[n]) { n           ver = 1; n           break; n         } n         if (s2[j] + acts > s2[n]) { n           nrs1++; n           j = fp1[s1[j] + acts]; n           continue; n         } n         if (s1[j] + acts > s1[n]) { n           nrs2++; n           j = fp2[s2[j] + acts]; n           continue; n         } n         if (fp1[s1[j] + acts] < fp2[s2[j] + acts]) { n           nrs1++; n           j = fp1[s1[j] + acts]; n         } else { n           nrs2++; n           j = fp2[s2[j] + acts]; n         } n       } n       if (ver == 0 && nrs1 > nrs2) { n         vrasp[rasp].s = acts; n         vrasp[rasp].t = nrs1; n         rasp++; n       } n     } n   } n   sort(vrasp, vrasp + rasp, compar); n   cout << rasp <<   n ; n   for (int i = 0; i < rasp; i++) n     cout << vrasp[i].t <<     << vrasp[i].s <<   n ; n   return player_unu; n } n


#include <bits/stdc++.h> n using namespace std; n int o, trues, Bruh, YO; n bool levls[696969]; n int main() { n   int n, X; n   cin >> n; n   for (int a = 0; a < 2; a++) { n     cin >> Bruh; n     for (int AL = 0; AL < Bruh; AL++) { n       cin >> YO; n       levls[YO] = true; n     } n   } n   for (int x = 1; x <= n; x++) { n     if (levls[x] == true) trues++; n   } n   if (trues == n) n     cout <<  I become the guy.  << endl; n   else n     cout <<  Oh, my keyboard!  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n const int N = 1000040; n long long fact[N], invf[N]; n vector<long long> primes; n long long add(long long x, long long y) { return (x + y) % mod; } n long long mul(long long x, long long y) { return (x % mod) * (y % mod) % mod; } n long long powll(long long x, long long y) { n   long long res = 1LL; n   while (y) { n     if (y & 1LL) res *= x; n     res %= mod; n     x = (x * x) % mod; n     y >>= 1LL; n   } n   return res; n } n long long divll(long long x, long long y) { n   return (x * powll(y, mod - 2)) % mod; n } n long long nPr(long long n, long long r) { n   if (n < r || r < 0) return 0; n   return mul(fact[n], invf[n - r]); n } n long long nCr(long long n, long long r) { n   if (n < r || r < 0) return 0; n   return mul(mul(fact[n], invf[r]), invf[n - r]); n } n long long solve() { n   long long x, y; n   scanf( %lld %lld , &x, &y); n   vector<long long> c; n   for (long long p : primes) { n     int k = 0; n     while (x % p == 0) { n       k++; n       x /= p; n     } n     if (k) c.push_back(k); n   } n   if (x > 1) c.push_back(1); n   long long ret = powll(2, y - 1); n   for (long long a : c) { n     ret = (ret * nCr(y + a - 1, a)) % mod; n   } n   return ret; n } n int main() { n   int q; n   cin >> q; n   fact[0] = invf[0] = 1; n   for (int i = 1; i <= N - 1; ++i) { n     fact[i] = (fact[i - 1] * i) % mod; n     invf[i] = divll(invf[i - 1], i); n   } n   long long lim = 1000; n   vector<int> check(lim, 1); n   for (int i = 2; i <= lim - 1; ++i) { n     if (!check[i]) continue; n     primes.push_back(i); n     for (int j = 2 * i; j < lim; j += i) check[j] = 0; n   } n   while (q--) { n     printf( %lld n , solve()); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, y; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     long long a[n]; n     for (int i = 0; i < n; i++) cin >> a[i]; n     long long res, mx = 0; n     for (int i = 0; i < n - 1; i++) { n       res = a[i] * a[i + 1]; n       mx = max(res, mx); n     } n     cout << mx << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int main() { n   cin >> n; n   if (n == 0) { n     printf( a ); n     return 0; n   } n   for (char c =  a ; c <=  z  && n; c++) { n     int sum = 0, i; n     for (i = 0; i <= n; i++) { n       n -= i; n       cout << c; n     } n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long mult(long long a, long long b, long long mod) { n   if (b == 0) return 0; n   if (b % 2 == 1) return (mult(a, b - 1, mod) + a) % mod; n   return (mult(a, b / 2, mod) * 2) % mod; n } n inline long long BinPow(long long a, long long b, long long mod) { n   if (b == 0) return 1; n   if (b == 1) return a; n   if (b % 2 == 1) return (mult(BinPow(a, b - 1, mod), a, mod)) % mod; n   long long res = BinPow(a, b / 2, mod); n   return mult(res, res, mod); n } n int n, m, k, w, kol, kol1, w1, sum1; n char a[150][140][130]; n int sum; n int main() { n   cin >> n >> m >> k; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       for (int t = 1; t <= k; t++) cin >> a[i][j][t]; n   for (int l = 1; l <= n; l++) n     for (int j = 1; j <= m; j++) n       for (int t = 1; t <= k; t++) { n         if (a[l][j][t] ==  1 ) { n           if (a[l - 1][j][t] ==  1 ) n             if (a[l + 1][j][t] ==  1 ) w = 1; n           if (a[l][j - 1][t] ==  1 ) n             if (a[l][j + 1][t] ==  1 ) w = 1; n           if (a[l][j][t - 1] ==  1 ) n             if (a[l][j][t + 1] ==  1 ) w = 1; n           if (a[l - 1][j][t] ==  1 ) { n             if (a[l - 1][j + 1][t] ==  0 ) n               if (a[l][j + 1][t] ==  1 ) w1 = 1; n             if (a[l - 1][j][t + 1] ==  0 ) n               if (a[l][j][t + 1] ==  1 ) w1 = 1; n           } n           if (a[l][j - 1][t] ==  1 ) { n             if (a[l][j - 1][t + 1] ==  0 ) n               if (a[l][j][t + 1] ==  1 ) w1 = 1; n             if (a[l + 1][j - 1][t] ==  0 ) n               if (a[l + 1][j][t] ==  1 ) w1 = 1; n           } n           if (a[l][j][t - 1] ==  1 ) { n             if (a[l][j + 1][t - 1] ==  0 ) n               if (a[l][j + 1][t] ==  1 ) w1 = 1; n             if (a[l + 1][j][t - 1] ==  0 ) n               if (a[l + 1][j][t] ==  1 ) w1 = 1; n           } n           if (w || w1) sum++; n           w1 = w = 0; n         } n       } n   cout << sum; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int setbit(int n, int pos) { return n = n | (1 << pos); } n int resetbit(int n, int pos) { return n = n & ~(1 << pos); } n bool checkbit(int n, int pos) { return (bool)(n & (1 << pos)); } n template <typename T> n T modMul(T x, T y, T mod = 1e9 + 7) { n   x %= mod; n   y %= mod; n   return (x * y) % mod; n } n template <typename T> n T modAdd(T x, T y, T mod = 1e9 + 7) { n   x %= mod; n   y %= mod; n   return (x + y) % mod; n } n template <typename T> n T ext_gcd(T num1, T num2, T &X, T &Y) { n   T r2, r1, q2, q1, x2, x1, y2, y1, x, y, r; n   x2 = 1; n   y2 = 0; n   x1 = 0; n   y1 = 1; n   for (r2 = num1, r1 = num2; r1 != 0; n        y2 = y1, y1 = y, x2 = x1, x1 = x, r2 = r1, r1 = r) { n     q1 = r2 / r1; n     x = x2 - q1 * x1; n     y = y2 - q1 * y1; n     r = r2 % r1; n   } n   X = x2; n   Y = y2; n   return r2; n } n template <typename T> n void print(const T &v) { n   cerr << v <<    ; n } n template <typename T1, typename... T2> n void print(const T1 &first, const T2 &...rest) { n   print(first); n   print(rest...); n } n template <class T> n string to_str(T t) { n   stringstream second; n   second << t; n   return second.str(); n } n template <typename T> n T modPow(T x, T k, T mod = 1e9 + 7) { n   if (k == 0) return (T)1; n   if (k & 1) { n     return ((x % mod) * modPow(x, k - 1, mod) % mod) % mod; n   } else { n     T ret = modPow(x, k / 2, mod); n     ret %= mod; n     return (ret * ret) % mod; n   } n } n template <typename T> n T modInv(T x, T m) { n   return modPow(x, m - 2, m); n } n template <typename T> n void dbg_a(T a[], int n = 10) { n   cerr <<  [  ; n   for (int i = 0; i < n; i++) cerr << a[i] <<    ; n   cerr <<   ]  n        <<   n ; n } n template <typename F, typename S> n ostream &operator<<(ostream &os, const pair<F, S> &p) { n   return os <<  [   << p.first <<  ,   << p.second <<   ] ; n } n template <typename T> n ostream &operator<<(ostream &os, const vector<T> &v) { n   os <<  [  ; n   for (int i = 0; i < v.size(); i++) os << v[i] <<    ; n   return os <<   ] n ; n } n template <typename T> n ostream &operator<<(ostream &os, const map<T, T> &Map) { n   os <<  [  ; n   for (__typeof((Map).begin()) it = (Map).begin(); it != (Map).end(); ++it) n     os <<  [  << (*it).first <<     << (*it).second <<  ]  ; n   return os <<  ] n ; n } n template <typename T> n ostream &operator<<(ostream &os, const set<T> &Set) { n   os <<  [  ; n   for (__typeof((Set).begin()) it = (Set).begin(); it != (Set).end(); ++it) n     os << *it <<    ; n   return os <<   ] n ; n } n const int maxn = (int)2e6 + 123; n const int inf = 0x3f; n const long long mod = (long long)1e9 + 7LL; n int a[maxn]; n void solve() { n   int n, q, cnt = 0, ans = 0, magic = 0; n   vector<int> even, odd; n   string s; n   cin >> s; n   for (int i = 0; i < s.size(); i++) { n     int x = s[i] -  0 ; n     if (x & 1) n       odd.push_back(x); n     else n       even.push_back(x); n   } n   reverse(odd.begin(), odd.end()); n   reverse(even.begin(), even.end()); n   for (int i = 0; i < s.size(); i++) { n     if (odd.size() == 0) { n       cout << even.back(); n       even.pop_back(); n     } else if (even.size() == 0) { n       cout << odd.back(); n       odd.pop_back(); n     } else { n       if (even.back() < odd.back()) { n         cout << even.back(); n         even.pop_back(); n       } else { n         cout << odd.back(); n         odd.pop_back(); n       } n     } n   } n   cout <<   n ; n } n int main() { n   ios ::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t = 1, c = 0; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T max(T a, T b, T c) { n   return max(a, max(b, c)); n } n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   long long a, b, c; n   cin >> a >> b >> c; n   cout << 2 * min(a + c, min(b + c, (a + b + c) / 2)) <<   n ; 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   int x, y, z; n   cin >> x >> y >> z; n   if (x > y) { n     if (x > y + z) n       cout <<  + ; n     else n       cout <<  ? ; n   } else if (x < y) { n     if (y > x + z) n       cout <<  - ; n     else n       cout <<  ? ; n   } else if (z != 0) n     cout <<  ? ; n   else n     cout << 0; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = (int)2e9; n const long long INFL = (long long)9e18; n const int MAXINT = ((~0) ^ (1 << 31)); n const long long MAXLL = ((~0) ^ ((long long)1 << 63)); n template <class T> n inline T pow2(T a) { n   return a * a; n } n template <class T> n inline bool mineq(T& a, T b) { n   return (a > b) ? (a = b, true) : false; n } n template <class T> n inline bool maxeq(T& a, T b) { n   return (a < b) ? (a = b, true) : false; n } n const int maxn = (int)2222; n ; n char grid[maxn][maxn]; n int v[maxn][maxn], h[maxn][maxn], t[maxn][maxn], n, m; n long long ans0() { n   long long ans = 0; n   for (int i = 2; i < (int)(n); i++) { n     ans += (v[i][m] == 0); n   } n   return ans; n } n long long ans1() { n   long long ans = 0; n   for (int i = 2; i < (int)(n); i++) { n     for (int j = 2; j < (int)(m); j++) { n       if (grid[i][j] ==  # ) continue; n       ans += (h[i][j] == 0 && v[i][j] == 0); n       ans += (h[i][j] == h[n][j] && v[i][j] == 0); n       ans += (h[i][j] == 0 && v[i][j] == v[i][m]); n       ans += (h[i][j] == h[n][j] && v[i][j] == v[i][m]); n     } n   } n   return ans; n } n long long ans2() { n   long long ans = 0; n   int up[maxn] = {}, down[maxn] = {}; n   for (int i = 2; i < (int)(n); i++) { n     int l = 2, r; n     while (l < m) { n       if (grid[i][l] ==  # ) { n         l++; n         continue; n       } n       r = l; n       while (r < m && v[i][l] == v[i][r]) r++; n       for (int j = l; j < (int)(r); j++) { n         up[j] = (h[i][j] == 0); n         down[j] = (h[i][j] == h[n][j]); n         if (j - 2 >= l) ans += up[j] * up[j - 2] + down[j] * down[j - 2]; n         if (j - 1 >= l) ans += up[j] * down[j - 1] + down[j] * up[j - 1]; n         if (j != l) up[j] += up[j - 1]; n         if (j != l) down[j] += down[j - 1]; n       } n       l = r; n     } n   } n   return ans; n } n void pre() { n   for (int i = 1; i < (int)(n + 1); i++) { n     for (int j = 1; j < (int)(m + 1); j++) { n       v[i][j] = v[i][j - 1] + (grid[i][j] ==  # ); n       h[i][j] = h[i - 1][j] + (grid[i][j] ==  # ); n     } n   } n } n void reversegrid() { n   for (int i = 1; i < (int)(n + 1); i++) n     for (int j = 1; j < (int)(m + 1); j++) t[j][i] = grid[i][j]; n   for (int i = 1; i < (int)(m + 1); i++) n     for (int j = 1; j < (int)(n + 1); j++) grid[i][j] = t[i][j]; n   swap(n, m); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> m; n   for (int i = 1; i < (int)(n + 1); i++) n     for (int j = 1; j < (int)(m + 1); j++) cin >> grid[i][j]; n   pre(); n   long long ans = ans0() + ans1() + ans2(); n   reversegrid(); n   pre(); n   cout << ans + ans0() + ans2(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, h, m; n   int mo, md, ho, hd; n   string t; n   cin >> t; n   n = t.size(); n   m = (t[n - 2] -  0 ) * 10 + t[n - 1] -  0 ; n   h = (t[n - 5] -  0 ) * 10 + t[n - 4] -  0 ; n   for (;;) { n     m = (m + 1) % 60; n     if (m == 0) { n       h = (h + 1) % 24; n     } n     ho = h % 10; n     hd = h / 10; n     mo = m % 10; n     md = m / 10; n     if (hd == mo && ho == md) { n       cout << hd << ho <<  :  << md << mo << endl; n       break; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   cin.tie(NULL); n   int n; n   cin >> n; n   priority_queue<int, vector<int>, greater<int>> servers; n   priority_queue<pair<int, int>, vector<pair<int, int>>, n                  greater<pair<int, int>>> n       pq; n   for (int i = 0; i < n; i++) { n     servers.push(i + 1); n   } n   int q, t, k, d; n   cin >> q; n   for (int i = 0; i < q; i++) { n     cin >> t >> k >> d; n     while (pq.empty() == false) { n       pair<int, int> top = pq.top(); n       if (top.first < t) { n         servers.push(top.second); n         pq.pop(); n       } else { n         break; n       } n     } n     if (servers.size() >= k) { n       int total = 0, serverId; n       int endTime = t + d - 1; n       for (int j = 0; j < k; j++) { n         serverId = servers.top(); n         servers.pop(); n         total += serverId; n         pq.push(make_pair(endTime, serverId)); n       } n       cout << total <<   n ; n     } else { n       cout <<  -1 n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n const int maxn = 1e5, maxm = 1e5, maxCell = 1e5; n const int maxv = maxCell + 4, maxe = maxCell * 4 + 4 * maxCell; n const int inf = std::numeric_limits<int>::max() / 2; n namespace Network { n struct GraphInfo { n   int vertex, source, sink; n }; n struct Edge { n   int from, to; n   mutable int flow; n   const Edge *pre, *rev; n } ed[maxe * 2 + 10], *end = ed; n const Edge *head[maxv + 10], *cur[maxv + 10]; n int exceed[maxv + 10], dep[maxv + 10]; n enum class EdgeType { Normal, Required }; n inline void addGraphEdge(const int from, const int to, const int flow) { n   new (end) Edge{from, to, flow, head[from], end + 1}; n   head[from] = end++; n   new (end) Edge{to, from, 0, head[to], end - 1}; n   head[to] = end++; n } n template <EdgeType et> n inline void addUnitEdge(const int from, const int to) { n   if constexpr (et == EdgeType::Required) { n     --exceed[from]; n     ++exceed[to]; n   } else n     addGraphEdge(from, to, 1); n } n bool bfs(const int n, const int source, const int sink) { n   std::queue<int> q; n   std::fill(dep, dep + n, inf); n   q.push(source); n   dep[source] = 0; n   while (!q.empty()) { n     const int cur = q.front(); n     q.pop(); n     for (const Edge *i = head[cur]; i; i = i->pre) n       if (i->flow && dep[i->to] == inf) { n         dep[i->to] = dep[cur] + 1; n         q.push(i->to); n       } n   } n   return dep[sink] != inf; n } n int dfs(const int x, const int cap, const int sink) { n   if (x == sink || !cap) return cap; n   int rst = cap; n   for (; cur[x]; cur[x] = cur[x]->pre) { n     const Edge *i = cur[x]; n     if (i->flow && dep[i->to] == dep[x] + 1) { n       const int d = dfs(i->to, std::min(rst, i->flow), sink); n       i->flow -= d; n       i->rev->flow += d; n       rst -= d; n       if (!rst) break; n     } n   } n   return cap - rst; n } n int dinic(const GraphInfo gi) { n   int ret = 0; n   while (bfs(gi.vertex, gi.source, gi.sink)) { n     std::memcpy(cur, head, sizeof(cur[0]) * gi.vertex); n     ret += dfs(gi.source, inf, gi.sink); n   } n   return ret; n } n bool hasSolution(const int virtSource) { n   for (const Edge *i = head[virtSource]; i; i = i->pre) n     if (i->flow) return false; n   return true; n } n void init(const int n) { n   end = ed; n   std::memset(head, 0, sizeof(head[0]) * (n + 2)); n   std::memset(exceed, 0, sizeof(exceed[0]) * (n + 2)); n } n int findMatch(const int v, const int limit) { n   for (const Edge *i = head[v]; i; i = i->pre) n     if (!i->flow && i->to < limit) return i->to; n   return limit; n } n bool boundMaxFlow(const GraphInfo gi) { n   const int virtSource = gi.vertex, virtSink = virtSource + 1; n   addGraphEdge(gi.sink, gi.source, inf); n   for (int i = 0; i < gi.vertex; ++i) n     if (exceed[i] > 0) n       addGraphEdge(virtSource, i, exceed[i]); n     else if (exceed[i] < 0) n       addGraphEdge(i, virtSink, -exceed[i]); n   dinic(GraphInfo{virtSink + 1, virtSource, virtSink}); n   return hasSolution(virtSource); n } n }  // namespace Network n int n, m; n enum Direction { Left, Right, Down, Up, None }; n const Direction reverse[]{Right, Left, Up, Down, None}; n struct Step { n   int dx, dy; n   inline bool operator==(const Step s) const { n     return dx == s.dx && dy == s.dy; n   } n }; n const Step step[]{{0, -1}, {0, 1}, {1, 0}, {-1, 0}}; n const char directionName[] = { L ,  R ,  D ,  U }; n struct Position { n   int x, y; n   inline static Position fromId(const int id) { n     const div_t d = div(id, m); n     return Position{d.quot, d.rem}; n   } n   inline Position operator+(const struct Step s) const { n     return Position{x + s.dx, y + s.dy}; n   } n   inline Step operator-(const Position r) const { n     return Step{x - r.x, y - r.y}; n   } n   inline bool isValid() const { return x >= 0 && y >= 0 && x < n && y < m; } n   inline int id() const { return x * m + y; } n }; n struct Cell { n   Direction next; n   int sum, val; n } cell[maxCell + 10]; n namespace GraphBuilder { n template <bool rev, Network::EdgeType type> n inline void linkVertex(const int from, const int to) { n   if constexpr (rev) n     Network::addUnitEdge<type>(to, from); n   else n     Network::addUnitEdge<type>(from, to); n } n template <bool toSink> n inline void linkCell(const Position pos, const int endpoint) { n   using Network::EdgeType; n   const int cid = pos.id(); n   Cell &cur = cell[cid]; n   cur.next = Direction::None; n   for (int k = 0; k < 4; ++k) n     if (const auto nxt = pos + step[k]; nxt.isValid()) { n       const int nextId = nxt.id(); n       if (cell[nextId].sum < cur.sum) n         cur.next = static_cast<Direction>(k); n       else if (!toSink && cell[nextId].sum == cur.sum) n         Network::addUnitEdge<EdgeType::Normal>(cid, nextId); n     } n   if (cur.next == Direction::None) n     linkVertex<toSink, EdgeType::Required>(endpoint, cid); n   else n     linkVertex<toSink, EdgeType::Normal>(endpoint, cid); n } n inline bool isLinkSink(const Position &p) { n   return (p.x & 0x01) ^ (p.y & 0x01); n } n static Network::GraphInfo build(const int n, const int m) { n   const int source = n * m, sink = source + 1; n   Network::init(sink + 1); n   for (int i = 0; i < n; ++i) n     for (Position pos{i, 0}; pos.y < m; ++pos.y) n       if (isLinkSink(pos)) n         linkCell<true>(pos, sink); n       else n         linkCell<false>(pos, source); n   return Network::GraphInfo{sink + 1, source, sink}; n } n }  // namespace GraphBuilder n void construct(const int n, const int m) { n   const int lim = n * m; n   for (int i = 0, cid = 0; i < n; ++i) n     for (Position pos{i, 0}; pos.y < m; ++pos.y, ++cid) n       if (Cell &cur = cell[cid]; cur.next != Direction::None) n         cur.val = cur.sum - cell[(pos + step[cur.next]).id()].sum; n   for (int i = 0, cid = 0; i < n; ++i) n     for (Position pos{i, 0}; pos.y < m; ++pos.y, ++cid) n       if (!GraphBuilder::isLinkSink(pos)) n         if (const int nxt = Network::findMatch(cid, lim); nxt < lim) { n           Cell &cur = cell[cid]; n           const int typ = n               std::find(step, step + 4, Position::fromId(nxt) - pos) - step; n           cur.val = cur.sum - 1; n           cur.next = static_cast<Direction>(typ); n           cell[nxt].val = 1; n           cell[nxt].next = reverse[typ]; n         } n } n template <class Func> n void printMatrix(const int n, const int m, Func fun) { n   const Cell *ptr = cell; n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j, ++ptr) std::cout << fun(*ptr) <<    ; n     std::cout.put(  n ); n   } n } n void solve() { n   std::cin >> n >> m; n   for (Cell *i = cell; i < cell + n * m; ++i) std::cin >> i->sum; n   if (!Network::boundMaxFlow(GraphBuilder::build(n, m))) n     std::cout <<  NO n ; n   else { n     construct(n, m); n     std::cout <<  YES n ; n     printMatrix(n, m, [](const Cell &i) { return i.val; }); n     printMatrix(n, m, [](const Cell &i) { return directionName[i.next]; }); n   } n } n int main() { n   std::ios::sync_with_stdio(false); n   int t; n   std::cin >> t; n   for (int i = t; i; --i) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   int i = k - 1; n   while (n % i != 0) { n     i--; n   } n   cout << n / i * k + i << endl; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> v[30]; n string s[100010]; n char aver[300010]; n long long f(int p, int ch, int si) { n   int mi = 99999999; n   if (v[ch].size() == 0) return s[si].size(); n   for (int i = 0; i < v[ch].size(); i++) mi = min(mi, abs(p - v[ch][i])); n   return mi; n } n int main() { n   long long n, k; n   cin >> n >> k; n   cin >> aver; n   for (int i = 1; i <= n; i++) cin >> s[i]; n   for (long long i = 0; i < k; i++) v[aver[i] -  a ].push_back(i); n   for (int i = 1; i <= n; i++) { n     long long F = 0; n     for (int j = 0; j < s[i].size(); j++) { n       if (s[i][j] != aver[j]) { n         F += f(j, s[i][j] -  a , i); n       } n     } n     cout << F << endl; n   } n } n


#include <bits/stdc++.h> n char a[1111]; n int main() { n   int i, j, k, l, s, flag; n   while (~scanf( %s , a + 2)) { n     a[0] = a[1] =  0 ; n     s = 0; n     l = strlen(a); n     flag = 0; n     for (i = 0; i < l - 2; i++) { n       if (flag) break; n       for (j = i + 1; j < l - 1; j++) { n         if (flag) break; n         for (k = j + 1; k < l; k++) { n           s = (a[i] -  0 ) * 100 + (a[j] -  0 ) * 10 + a[k] -  0 ; n           if (s % 8 == 0) { n             flag = 1; n             break; n           } n         } n       } n     } n     if (flag) n       printf( YES n%d n , s); n     else n       printf( NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 510; n const int INF = 0x3f3f3f3f; n const int MOD = (int)1e9 + 7; n int n; n long long ans; n void dfs(int a, int b, int c) { n   if (a == n) { n     ++ans; n     return; n   } n   for (int i = 0; i < n; ++i) { n     if (b & (1 << i)) continue; n     if (c & (1 << ((a + i) % n))) continue; n     dfs(a + 1, b | (1 << i), c | (1 << ((a + i) % n))); n   } n   return; n } n int main() { n   cin >> n; n   if (n % 2 == 0) { n     cout << 0 << endl; n     return 0; n   } n   if (n == 15) { n     cout << 150347555 << endl; n     return 0; n   } n   dfs(0, 0, 0); n   for (int i = 1; i <= n; ++i) { n     ans = (ans * i) % MOD; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c; n   while (cin >> a >> b >> c) { n     if (b == a / 2 && c == a / 2) n       cout <<  NO  << endl; n     else if (b == a / 2 && c == a / 2 + 1) n       cout <<  NO  << endl; n     else if (b == a / 2 + 1 && c == a / 2 + 1) n       cout <<  NO  << endl; n     else if (b == a / 2 + 1 && c == a / 2) n       cout <<  NO  << endl; n     else n       cout <<  YES  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a[100000], p[100000], i, ans = 0, price = INT_MAX; n   scanf( %d , &n); n   for (i = 0; i < n; i++) scanf( %d %d , &a[i], &p[i]); n   for (i = 0; i < n; i++) { n     price = min(price, p[i]); n     ans += (a[i] * price); n   } n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool used[1005]; n vector<int> v; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n, k, a, b, c, d; n   cin >> n >> k >> a >> b >> c >> d; n   if (n == 4 or k <= n) { n     cout << -1; n     return 0; n   } n   used[a] = used[b] = used[c] = used[d] = true; n   for (int i = 1; i <= n; i++) { n     if (!used[i]) { n       v.push_back(i); n     } n   } n   cout << a <<     << c <<     << v[0] <<     << d <<    ; n   for (int i = 1; i <= n - 5; i++) { n     cout << v[i] <<    ; n   } n   cout << b <<   n ; n   cout << c <<     << a <<     << v[0] <<     << b <<    ; n   for (int i = n - 5; i >= 1; i--) { n     cout << v[i] <<    ; n   } n   cout << d; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, h, m, i, j, x, y, z, ans; n   cin >> n >> h >> m; n   long long int a[n + 10]; n   for (i = 1; i <= n; i++) { n     a[i] = h; n   } n   for (i = 1; i <= m; i++) { n     cin >> x >> y >> z; n     for (j = x; j <= y; j++) { n       a[j] = min(a[j], z); n     } n   } n   ans = 0; n   for (i = 1; i <= n; i++) { n     ans += a[i] * a[i]; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n char jz[1000006][5]; n int cnt2 = 0, cnt3 = 0, dp[1000006][8]; n int cal(int x) { n   int ans = 0; n   while (x > 0) { n     if (x & 1) ans++; n     x /= 2; n   } n   return ans; n } n bool check_3(int x, int y) { n   int sum = cal(x / 2) + cal(y / 2); n   if (sum % 2 == 0) return false; n   if (x >= 4) x -= 4; n   if (y >= 4) y -= 4; n   sum = cal(x) + cal(y); n   if (sum % 2 == 0) return false; n   return true; n } n bool check_2(int x, int y) { n   if ((cal(x) + cal(y)) % 2 == 0) return false; n   return true; n } n int change(int x, int y) { return cal(x ^ y); } n struct s3 { n   int x; n   vector<int> v; n } a3[10], a2[5]; n int main() { n   memset(dp, 0x3f3f3f3f, sizeof(dp)); n   cin >> n >> m; n   if (n > 3 && m > 3) { n     cout << -1; n     return 0; n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       if (m >= 4) n         cin >> jz[j][i]; n       else if (m < 4) n         cin >> jz[i][j]; n     } n     getchar(); n   } n   if (m >= 4) swap(n, m); n   if (m == 1) { n     cout << 0; n     return 0; n   } else if (m == 2) { n     for (int i = 0; i < 4; i++) n       for (int j = 0; j < 4; j++) { n         if (check_2(i, j)) { n           a2[i].v.push_back(j); n         } n       } n     if (n == 1) { n       cout << 0; n       return 0; n     } n     int num1 = 0; n     for (int i = 1; i <= m; i++) { n       num1 *= 2; n       if (jz[1][i] ==  1 ) num1++; n     } n     for (int i = 2; i <= n; i++) { n       int num = 0; n       for (int l = 1; l <= m; l++) { n         num *= 2; n         if (jz[i][l] ==  1 ) num++; n       } n       if (i == 2) { n         for (int j = 0; j < 4; j++) { n           for (int k = 0; k < a2[j].v.size(); k++) n             dp[i][j] = min(dp[i][j], change(j, num) + change(a2[j].v[k], num1)); n         } n       } else { n         for (int j = 0; j < 4; j++) { n           for (int k = 0; k < a2[j].v.size(); k++) n             dp[i][j] = min(dp[i][j], dp[i - 1][a2[j].v[k]] + change(j, num)); n         } n       } n     } n     int ans = 2100000000; n     for (int i = 0; i < 4; i++) ans = min(ans, dp[n][i]); n     cout << ans; n   } else if (m == 3) { n     for (int i = 0; i <= 7; i++) { n       for (int j = 0; j <= 7; j++) { n         if (check_3(i, j)) { n           a3[i].x = i; n           a3[i].v.push_back(j); n         } n       } n     } n     int num1 = 0; n     for (int i = 1; i <= m; i++) { n       num1 *= 2; n       if (jz[1][i] ==  1 ) num1++; n     } n     if (n == 1) { n       cout << 0; n       return 0; n     } n     for (int i = 2; i <= n; i++) { n       int num = 0; n       for (int l = 1; l <= m; l++) { n         num *= 2; n         if (jz[i][l] ==  1 ) num++; n       } n       if (i == 2) { n         for (int j = 0; j < 8; j++) n           for (int k = 0; k < a3[j].v.size(); k++) { n             dp[i][j] = min(dp[i][j], change(j, num) + change(a3[j].v[k], num1)); n           } n       } else { n         for (int j = 0; j < 8; j++) n           for (int k = 0; k < a3[j].v.size(); k++) { n             dp[i][j] = min(dp[i][j], dp[i - 1][a3[j].v[k]] + change(j, num)); n           } n       } n     } n     int ans = 2100000000; n     for (int i = 0; i < 8; i++) ans = min(ans, dp[n][i]); n     cout << ans; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, q, p; n long long* pt; n long long a[200000], k, sum = 0LL; n int main() { n   cin >> n >> q; n   for (int i = (0); i < (n); i++) { n     cin >> a[i]; n     if (i) a[i] += a[i - 1]; n   } n   for (int i = (0); i < (q); i++) { n     cin >> k; n     sum += k; n     pt = upper_bound(a, a + n, sum); n     p = pt - a; n     if (p == n) { n       p = 0; n       sum = 0LL; n     } n     cout << n - p <<   n ; n   } n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n inline bool chmax(int& a, int b) { n   if (a < b) { n     a = b; n     return true; n   } n   return false; n } n constexpr int B = 210; n int q, n, e, i, j, ans, res, l, r, val, x, mid; n void solve() { n   cin >> n; n   vector<vector<int>> sum(n + 1, vector<int>(B, 0)); n   for (i = 0; i < n; i++) { n     for (j = 0; j < B; j++) sum[i + 1][j] = sum[i][j]; n     cin >> e; n     sum[i + 1][e]++; n   } n   ans = 0; n   for (x = 0; x < B; x++) { n     res = 0; n     l = 0; n     r = n; n     val = 0; n     while (l < r) { n       mid = 0; n       while (l < n and sum[l][x] < val) l++; n       while (0 < r and sum[n][x] - sum[r][x] < val) r--; n       if (r <= l) break; n       for (i = 0; i < B; i++) chmax(mid, sum[r][i] - sum[l][i]); n       chmax(res, mid + sum[l][x] + sum[l][x]); n       val++; n     } n     chmax(ans, res); n   } n   cout << ans <<   n ; n   return; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cin >> q; n   while (q--) { n     cin >> n; n     vector<vector<int>> sum(n + 1, vector<int>(B, 0)); n     for (i = 0; i < n; i++) { n       for (j = 0; j < B; j++) sum[i + 1][j] = sum[i][j]; n       cin >> e; n       sum[i + 1][e]++; n     } n     ans = 0; n     for (x = 0; x < B; x++) { n       res = 0; n       l = 0; n       r = n; n       val = 0; n       while (l < r) { n         mid = 0; n         while (l < n and sum[l][x] < val) l++; n         while (0 < r and sum[n][x] - sum[r][x] < val) r--; n         if (r < l) break; n         for (i = 0; i < B; i++) chmax(mid, sum[r][i] - sum[l][i]); n         chmax(res, mid + sum[l][x] + sum[l][x]); n         val++; n       } n       chmax(ans, res); n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int maxn = 100000 + 5; n using namespace std; n int main() { n   int n, a[maxn]; n   cin >> n; n   bool flag = false; n   for (int i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   for (int i = 2; i < n; i++) { n     int x = a[i], y = a[i - 1]; n     int z = a[i - 2]; n     if ((y + z) > x && (x - y) < z) flag = true; n   } n   if (flag) n     cout <<  YES ; n   else n     cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const ll MOD = 998244353; n const ll MX = 3e5 + 5; n ll fct[MX] = {1}, inv[MX] = {1}; n ll power(ll a, ll b, ll p = 1) { n   if (b == 0) return 1; n   ll res = power(a, b / 2) % MOD; n   if (b & 1) { n     return (((res * res) % MOD) * a) % MOD; n   } else { n     return (((res * res) % MOD) * 1) % MOD; n   } n } n void func() { n   ll i; n   fct[1] = 1; n   for (i = 2; i < MX; i++) { n     fct[i] = fct[i - 1] * i; n     fct[i] %= MOD; n   } n   for (i = 1; i < MX; i++) { n     inv[i] = power(fct[i], MOD - 2); n   } n } n int main() { n   func(); n   ll n, i, k; n   cin >> n >> k; n   vector<pair<ll, ll>> vt; n   for (i = 0; i < n; i++) { n     ll l, r; n     cin >> l >> r; n     vt.push_back({l, -1}); n     vt.push_back({r, 1}); n   } n   sort(vt.begin(), vt.end()); n   ll cur = 0, ans = 0; n   for (i = 0; i < vt.size(); i++) { n     if (vt[i].second < 0) { n       cur++; n     } else { n       cur--; n       if (cur >= k - 1) n         ans += (((fct[cur] * inv[k - 1]) % MOD) * inv[cur - k + 1]) % MOD; n       ans %= MOD; n     } n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100][100], n, row[55][100005], col[55][100005]; n bool valid(int i, int j) { n   for (int k = 0; k < n; k++) { n     if (k == i) continue; n     int x = a[i][j] - a[k][j]; n     if (x > 0 && row[i][x] && (x != a[i][j] || row[i][x] > 1)) return 1; n   } n   return 0; n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) { n       scanf( %d , &a[i][j]); n       row[i][a[i][j]]++; n       col[j][a[i][j]]++; n     } n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) n       if (a[i][j] != 1 && !valid(i, j)) { n         printf( No n ); n         return 0; n       } n   printf( Yes n ); n } n


#include <bits/stdc++.h> n using namespace std; n int mobius[500005], prime_cnt[500005], prime[500005], present[500005], n     nums[500005], cnt[500005]; n vector<int> divisors[500005]; n void calc_divisors(int val) { n   int i; n   if (divisors[val].size() > 0) return; n   int foo = sqrt(val); n   for (i = 1; i <= foo; i++) { n     if ((val % i) == 0) { n       divisors[val].push_back(i); n       divisors[val].push_back(val / i); n     } n   } n   if ((foo * foo) == val) { n     int temp = divisors[val].size(); n     divisors[val][temp - 1] = 0; n   } n   return; n } n void calc_mobius() { n   mobius[0] = 0; n   long long int i, j, temp; n   prime[1] = 1; n   mobius[1] = 1; n   for (i = 2; i < 500005; i++) { n     if (prime[i] == 0) { n       for (j = 2 * i; j < 500005; j += i) { n         prime[j] = 1; n         prime_cnt[j]++; n       } n       temp = i * i; n       j = 1; n       while (temp < 500005) { n         mobius[temp] = 0; n         j++; n         temp = j * i * i; n       } n       mobius[i] = -1; n     } else { n       if (mobius[i] == 500005) { n         if ((prime_cnt[i] % 2) == 0) n           mobius[i] = 1; n         else n           mobius[i] = -1; n       } n     } n   } n   return; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   ; n   int i, j, t, n, m, k, l, r, temp, mini, maxi, flag; n   long long int result = 0LL; n   for (i = 0; i < 500005; i++) { n     mobius[i] = 500005; n     prime[i] = 0; n     prime_cnt[i] = 0; n     cnt[i] = 0; n     present[i] = 0; n   } n   calc_mobius(); n   divisors[1].push_back(1); n   divisors[2].push_back(1); n   divisors[2].push_back(2); n   divisors[3].push_back(1); n   divisors[3].push_back(3); n   cin >> n >> m; n   for (i = 1; i <= n; i++) { n     cin >> nums[i]; n     calc_divisors(nums[i]); n   } n   for (i = 0; i < m; i++) { n     cin >> k; n     temp = nums[k]; n     if (present[k] == 0) { n       present[k] = 1; n       for (j = 0; j < divisors[temp].size(); j++) { n         result = result + (long long int)mobius[divisors[temp][j]] * n                               cnt[divisors[temp][j]]; n         cnt[divisors[temp][j]]++; n       } n     } else { n       present[k] = 0; n       for (j = 0; j < divisors[temp].size(); j++) { n         result = result - (long long int)mobius[divisors[temp][j]] * n                               (cnt[divisors[temp][j]] - 1LL); n         cnt[divisors[temp][j]]--; n       } n     } n     cout << result << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a, b, T, i, j, temp, le, ri, mid, ma = 0; n   cin >> n >> a >> b >> T; n   char str[n]; n   cin >> str; n   int r[n], l[n]; n   if (str[0] ==  h ) n     r[0] = 1; n   else n     r[0] = b + 1; n   for (i = 1; i < n; i++) { n     if (str[i] ==  h ) n       r[i] = r[i - 1] + a + 1; n     else n       r[i] = r[i - 1] + a + b + 1; n   } n   if (str[n - 1] ==  h ) n     l[0] = a + 1; n   else n     l[0] = a + b + 1; n   for (i = 1; i < n - 1; i++) { n     if (str[n - 1 - i] ==  h ) n       l[i] = l[i - 1] + a + 1; n     else n       l[i] = l[i - 1] + a + b + 1; n   } n   for (i = 0; i < n; i++) n     if (r[i] <= T) ma = max(ma, i + 1); n   for (i = 0; i < n - 1; i++) { n     temp = l[i]; n     if (temp >= T) continue; n     le = 0; n     ri = n - 1 - i - 1; n     while (ri - le > 1) { n       mid = (le + ri) / 2; n       temp = l[i] + min(i + 1, mid) * a; n       if (temp + r[mid] < T) n         le = mid; n       else n         ri = mid; n     } n     if (l[i] + r[le] + min(i + 1, le) * a <= T) ma = max(ma, i + le + 2); n     if (l[i] + r[ri] + min(i + 1, ri) * a <= T) ma = max(ma, i + ri + 2); n   } n   cout << ma; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const int N = 1e3 + 10; n char s[N], x[N], y[N]; n int n, d; n namespace Trie { n const int M = N * 60; n int ch[M][10], tot = 1, rt = 1, fail[M]; n bool ed[M]; n inline void insert(int l, int r) { n   int now = rt; n   for (int i = l; i <= r; ++i) { n     int v = s[i] -  0 ; n     if (!ch[now][v]) ch[now][v] = ++tot; n     now = ch[now][v]; n   } n   ed[now] = true; n } n inline void getfail() { n   for (int i = 0; i < 10; ++i) ch[0][i] = rt; n   fail[rt] = 0; n   queue<int> q; n   q.push(rt); n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     for (int i = 0; i < 10; ++i) { n       if (!ch[u][i]) n         ch[u][i] = ch[fail[u]][i]; n       else n         fail[ch[u][i]] = ch[fail[u]][i], q.push(ch[u][i]); n     } n   } n } n }  // namespace Trie n using namespace Trie; n int dp[2][N * 50][2][2][2]; n inline void upd(int &x, int y) { x = (x + y >= mod) ? x + y - mod : x + y; } n int main() { n   scanf( %s%s%s , s + 1, x + 1, y + 1); n   n = strlen(s + 1); n   d = strlen(x + 1); n   int nd = d / 2; n   for (int i = 1; i + nd - 1 <= n; ++i) insert(i, i + nd - 1); n   getfail(); n   dp[0][rt][1][1][0] = 1; n   for (int i = 1; i <= d; ++i) { n     int cur = i & 1, last = !cur; n     for (int pos = 0; pos <= tot; ++pos) n       for (int limx = 0; limx <= 1; ++limx) n         for (int limy = 0; limy <= 1; ++limy) n           for (int ok = 0; ok <= 1; ++ok) { n             int &d = dp[last][pos][limx][limy][ok]; n             if (!d) continue; n             int s = limx ? x[i] -  0  : 0, t = limy ? y[i] -  0  : 9; n             for (int c = s; c <= t; ++c) { n               int npos = ch[pos][c]; n               upd(dp[cur][npos][limx && c == x[i] -  0 ] n                     [limy && c == y[i] -  0 ][ok | ed[npos]], n                   d); n             } n             d = 0; n           } n   } n   int ans = 0; n   for (int pos = 0; pos <= tot; ++pos) n     for (int limx = 0; limx <= 1; ++limx) n       for (int limy = 0; limy <= 1; ++limy) n         upd(ans, dp[d & 1][pos][limx][limy][1]); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int inp[105][105]; n int a[105]; n int b[105]; n int temp[105]; n int main() { n   int n, m; n   scanf( %d , &n); n   scanf( %d , &m); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) scanf( %d , &inp[i][j]); n   for (int i = 0; i < m; i++) b[i] = inp[0][i]; n   int up = 0; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) up = max(up, inp[i][j]); n   int prevk = 0; n   for (int i = 1; i <= n - 1; i++) { n     map<int, int> mp; n     for (int j = 0; j < m; j++) { n       temp[j] = inp[i][j] - b[j]; n       mp[temp[j]] = 1; n     } n     int currk = 0; n     if (mp.size() == 2) { n       int f = mp.rbegin()->first; n       int s = mp.begin()->first; n       if (max(f, s) >= 0 && min(f, s) <= 0) n         currk = max(s, f) - min(s, f); n       else n         currk = -1; n     } n     if (mp.size() > 2 || (currk && prevk && currk != prevk) || n         (currk != 0 && currk <= up)) { n       printf( NO n ); n       return 0; n     } n     prevk = max(prevk, currk); n     a[i] = max(mp.rbegin()->first, mp.begin()->first); n   } n   printf( YES n ); n   if (prevk == 0) prevk = 2e9 + 7; n   printf( %d n , prevk); n   for (int i = 0; i < n; i++) n     printf( %d  , (a[i] >= 0) ? a[i] : (a[i] + prevk)); n   cout << endl; n   for (int i = 0; i < m; i++) printf( %d  , b[i]); n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 55, maxm = 9; n int loc[maxn][2], col[maxn]; n char s[maxn][maxn], res[maxn][maxn]; n int num[maxn][maxn], used[maxm][maxm]; n int n, m, ans, cnt; n void dfs(int u, int v) { n   int i, j, x, y; n   if (u > 14) { n     memset(used, 0, sizeof used); n     for (i = 1; i <= 28; ++i) { n       x = col[loc[i][0]]; n       y = col[loc[i][1]]; n       if (used[x][y]) return; n       used[x][y] = used[y][x] = true; n     } n     ++ans; n     if (ans == 1) { n       for (i = 1; i <= n; ++i) n         for (j = 1, res[i][m + 1] =   0 ; j <= m; ++j) n           res[i][j] = num[i][j] ? col[num[i][j]] - 1 +  0  :  . ; n     } n     return; n   } n   if (col[u]) n     dfs(u + 1, v); n   else { n     for (i = u + 1, col[u] = v; i <= 14; ++i) n       if (!col[i]) { n         col[i] = v; n         dfs(u + 1, v + 1); n         col[i] = 0; n       } n     col[u] = 0; n   } n } n int main() { n   int i, j, t; n   scanf( %d%d , &n, &m); n   for (i = 1; i <= n; ++i) scanf( %s , s[i] + 1); n   for (i = 1; i <= n; ++i) n     for (j = 1; j <= m; ++j) n       if (s[i][j] !=  . ) { n         if (!num[i][j]) n           num[i][j] = num[i + 1][j] = num[i][j + 1] = num[i + 1][j + 1] = ++cnt; n         t = s[i][j] <  a  ? s[i][j] -  A  + 27 : s[i][j] -  a  + 1; n         if (!loc[t][0]) n           loc[t][0] = num[i][j]; n         else n           loc[t][1] = num[i][j]; n       } n   dfs(1, 1); n   printf( %I64d n , (long long)ans * 5040); n   for (i = 1; i <= n; ++i) puts(res[i] + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 6; n vector<int> num, low, S, vis; n int cntr, numCC; n int par[N]; n vector<int> adj[N]; n void tarjanSCC(int v) { n   low[v] = num[v] = ++cntr; n   vis[v] = 1; n   S.push_back(v); n   for (auto u : adj[v]) { n     if (num[u] == -1) tarjanSCC(u); n     if (vis[u]) low[v] = min(low[v], low[u]); n   } n   if (low[v] == num[v]) { n     while (1) { n       int u = S.back(); n       S.pop_back(); n       vis[u] = 0; n       par[u] = numCC; n       if (u == v) break; n     } n     numCC++; n   } n } n int u[N], v[N], w[N]; n vector<pair<int, long long>> edge[N]; n long long gain[N], del[N]; n long long sum(long long n) { return n * (n + 1) / 2; } n long long get(int c) { n   long long l = 0, r = c; n   while (l < r) { n     long long mid = (l + r + 1) >> 1; n     if (sum(mid) <= c) { n       l = mid; n     } else { n       r = mid - 1; n     } n   } n   return 1LL * c * (l + 1) - del[l]; n } n long long dp[N]; n long long dfs(int now) { n   if (dp[now] != -1) return dp[now]; n   long long best = 0; n   for (auto it : edge[now]) { n     best = max(best, dfs(it.first) + it.second); n   } n   return dp[now] = best + gain[now]; n } n int main() { n   for (int i = 1; i < N; i++) del[i] = del[i - 1] + sum(i); n   int n, m; n   scanf( %d %d , &n, &m); n   for (int i = 0; i < m; i++) { n     scanf( %d %d %d , u + i, v + i, w + i); n     adj[u[i]].push_back(v[i]); n   } n   int s; n   scanf( %d , &s); n   num.assign(n + 1, -1); n   low.assign(n + 1, 0); n   vis.assign(n + 1, 0); n   cntr = numCC = 0; n   for (int i = 1; i <= n; i++) n     if (num[i] == -1) tarjanSCC(i); n   for (int i = 0; i < m; i++) { n     int a = par[u[i]]; n     int b = par[v[i]]; n     if (a == b) { n       gain[a] += get(w[i]); n     } else { n       edge[a].emplace_back(b, w[i]); n     } n   } n   memset(dp, -1, sizeof(dp)); n   cout << dfs(par[s]) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std; n template <typename T, typename U> n std::istream& operator>>(std::istream& i, pair<T, U>& p) { n   i >> p.first >> p.second; n   return i; n } n template <typename T> n std::istream& operator>>(std::istream& i, vector<T>& t) { n   for (auto& v : t) { n     i >> v; n   } n   return i; n } n template <typename T, typename U> n std::ostream& operator<<(std::ostream& o, const pair<T, U>& p) { n   o << p.first <<     << p.second; n   return o; n } n template <typename T> n std::ostream& operator<<(std::ostream& o, const vector<T>& t) { n   if (t.empty()) o <<   n ; n   for (size_t i = 0; i < t.size(); ++i) { n     o << t[i] <<    n [i == t.size() - 1]; n   } n   return o; n } n template <typename T> n using minheap = priority_queue<T, vector<T>, greater<T>>; n template <typename T> n using maxheap = priority_queue<T, vector<T>, less<T>>; n template <typename T> n bool in(T a, T b, T c) { n   return a <= b && b < c; n } n unsigned int logceil(int x) { n   return (unsigned int)(8 * sizeof(int) - __builtin_clz(x)); n } n namespace std { n template <typename T, typename U> n struct hash<pair<T, U>> { n   hash<T> t; n   hash<U> u; n   size_t operator()(const pair<T, U>& p) const { n     return t(p.x) ^ (u(p.y) << 7); n   } n }; n }  // namespace std n template <typename T> n T gcd(T a, T b) { n   if (a < b) swap(a, b); n   return b ? gcd(b, a % b) : a; n } n template <typename T> n class vector2 : public vector<vector<T>> { n  public: n   vector2() {} n   vector2(size_t a, size_t b, T t = T()) n       : vector<vector<T>>(a, vector<T>(b, t)) {} n }; n template <typename T> n class vector3 : public vector<vector2<T>> { n  public: n   vector3() {} n   vector3(size_t a, size_t b, size_t c, T t = T()) n       : vector<vector2<T>>(a, vector2<T>(b, c, t)) {} n }; n template <typename T> n class vector4 : public vector<vector3<T>> { n  public: n   vector4() {} n   vector4(size_t a, size_t b, size_t c, size_t d, T t = T()) n       : vector<vector3<T>>(a, vector3<T>(b, c, d, t)) {} n }; n template <typename T> n class vector5 : public vector<vector4<T>> { n  public: n   vector5() {} n   vector5(size_t a, size_t b, size_t c, size_t d, size_t e, T t = T()) n       : vector<vector4<T>>(a, vector4<T>(b, c, d, e, t)) {} n }; n void fastIO() { ios::sync_with_stdio(false); } n template <typename T, typename... Args> n T max(T t, Args... args) { n   return max(max<T>(args...), t); n } n template <typename T, typename... Args> n T min(T t, Args... args) { n   return min(min<T>(args...), t); n } n using PLL = pair<long long, unsigned long long>; n class FFooFighters { n  public: n   void solve(std::istream& in, std::ostream& out) { n     fastIO(); n     int n; n     in >> n; n     vector<PLL> a(n); n     in >> a; n     unsigned long long mb = 1; n     unsigned long long res = 0; n     long long ds = 0; n     for (auto p : a) { n       ds += p.first; n     } n     for (int i = 0; i < 64; ++i) { n       long long cs = 0; n       for (auto p : a) { n         if (p.second >= mb && p.second < 2 * mb) { n           ds += p.first; n           long long nmask = p.second & res; n           if (__builtin_popcountll(nmask) % 2 == 1) n             cs -= p.first; n           else n             cs += p.first; n         } n       } n       if (cs != 0 && signbit(ds) == signbit(cs)) { n         res |= mb; n       } n       mb <<= 1; n     } n     out << res << endl; n   } n }; n int main() { n   FFooFighters solver; n   std::istream& in(std::cin); n   std::ostream& out(std::cout); n   solver.solve(in, out); n   return 0; n } n