#include <bits/stdc++.h> n using namespace std; n int N, M; n long long ans, add[400009], sum[400009]; n set<pair<int, pair<int, int> > > segm; n int mod(int x) { n   if (x < 0) return -x; n   return x; n } n void split(int nod, int l1, int l2) { n   if (add[nod] == 0) return; n   int f1 = nod << 1, f2 = (nod << 1) + 1; n   sum[f1] += 1LL * add[nod] * l1, sum[f2] += 1LL * add[nod] * l2; n   add[f1] += add[nod], add[f2] += add[nod]; n   add[nod] = 0; n } n void U(int nod, int st, int dr, int x, int y, int val) { n   if (x <= st && dr <= y) { n     add[nod] += val; n     sum[nod] += 1LL * val * (dr - st + 1); n     return; n   } n   int mij = (st + dr) >> 1; n   split(nod, mij - st + 1, dr - mij); n   if (x <= mij) U(nod << 1, st, mij, x, y, val); n   if (y > mij) U((nod << 1) + 1, mij + 1, dr, x, y, val); n   sum[nod] = sum[nod << 1] + sum[(nod << 1) + 1]; n } n void Q(int nod, int st, int dr, int x, int y) { n   if (x <= st && dr <= y) { n     ans += sum[nod]; n     return; n   } n   int mij = (st + dr) >> 1; n   split(nod, mij - st + 1, dr - mij); n   if (x <= mij) Q(nod << 1, st, mij, x, y); n   if (y > mij) Q((nod << 1) + 1, mij + 1, dr, x, y); n } n void Update(int L, int R, int val) { n   set<pair<int, pair<int, int> > >::iterator it = segm.lower_bound( n                                                  make_pair(L, make_pair(0, 0))), n                                              it2; n   if (it->second.first < L) { n     int A = it->second.first, B = it->first, C = it->second.second; n     if (B > R) { n       U(1, 1, N, L, R, mod(val - C)); n       segm.erase(it); n       segm.insert(make_pair(L - 1, make_pair(A, C))); n       segm.insert(make_pair(B, make_pair(R + 1, C))); n       segm.insert(make_pair(R, make_pair(L, val))); n       return; n     } n     U(1, 1, N, L, B, mod(val - C)); n     segm.erase(it); n     segm.insert(make_pair(L - 1, make_pair(A, C))); n     it = segm.lower_bound(make_pair(L, make_pair(0, 0))); n   } n   while (1) { n     if (it == segm.end()) break; n     if (it->second.first > R) break; n     if (it->first > R) { n       int A = it->second.first, B = it->first, C = it->second.second; n       U(1, 1, N, A, R, mod(val - C)); n       segm.erase(it); n       segm.insert(make_pair(B, make_pair(R + 1, C))); n       break; n     } n     it2 = it, it2++; n     U(1, 1, N, it->second.first, it->first, mod(val - it->second.second)); n     segm.erase(it); n     it = it2; n   } n   segm.insert(make_pair(R, make_pair(L, val))); n } n int main() { n   scanf( %d %d , &N, &M); n   for (int i = 1; i <= N; i++) segm.insert(make_pair(i, make_pair(i, i))); n   while (M--) { n     int tip, a, b, c; n     scanf( %d , &tip); n     if (tip == 1) { n       scanf( %d %d %d , &a, &b, &c); n       Update(a, b, c); n     } else { n       scanf( %d %d , &a, &b), ans = 0LL; n       Q(1, 1, N, a, b); n       printf( %I64d n , ans); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n set<int> q; n const int maxn = 360; n int main() { n   int t, n; n   scanf( %d , &t); n   while (t--) { n     scanf( %d , &n); n     int num = 360 / (180 - n); n     int ans = 0; n     if (num * (180 - n) != 360) num++; n     for (int i = num; i <= 360; i++) { n       if ((n * i) % 180 != 0) continue; n       ans = i; n       if (ans != 0) break; n     } n     if (ans == 0) n       printf( -1 n ); n     else n       printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = (int)1e9; n const double INF = 1e12, EPS = 1e-9; n const int B = 2000; n const int dy[] = {-1, 0, 1, 0}, dx[] = {0, -1, 0, 1}; n int h, w, q; n int qs[100000][4]; n char in[100010][12], dir[256]; n int dp[100010 * 12], vis[100010][12]; n inline int to(int y, int x) { n   int &res = dp[y * 12 + x]; n   if (res != -1) return res; n   if (y == 0 || x == 0 || x == w + 1) return res = y * 12 + x; n   res = -2; n   int d = dir[in[y][x]]; n   return res = to(y + dy[d], x + dx[d]); n } n int main() { n   dir[ < ] = 1; n   dir[ ^ ] = 0; n   dir[ > ] = 3; n   scanf( %d%d%d , &h, &w, &q); n   for (int i = 0; i < (int)h; i++) scanf( %s , in[i + 1] + 1); n   for (int i = 0; i < (int)q; i++) { n     char c, d; n     int y, x; n     scanf(  %c%d%d , &c, &y, &x); n     qs[i][0] = c ==  A ; n     qs[i][1] = y; n     qs[i][2] = x; n     if (c ==  C ) { n       scanf(  %c , &d); n       qs[i][3] = d; n     } n   } n   memset(vis, -1, sizeof(vis)); n   for (int it = 0; it < (int)q; it++) { n     if (it % B == 0) { n       memset(dp, -1, sizeof(dp)); n       for (int i = it; i < it + B && i < q; i++) n         if (qs[i][0] == 0) { n           int y = qs[i][1], x = qs[i][2]; n           dp[y * 12 + x] = y * 12 + x; n         } n     } n     int y = qs[it][1], x = qs[it][2]; n     if (!qs[it][0]) { n       in[y][x] = (char)qs[it][3]; n       continue; n     } n     while (1) { n       if (x == 0 || x == w + 1 || y == 0) { n         printf( %d %d n , y, x); n         break; n       } n       if (vis[y][x] == it) { n         puts( -1 -1 ); n         break; n       } n       vis[y][x] = it; n       int ny = to(y, x), nx; n       if (ny < 0) { n         puts( -1 -1 ); n         break; n       } n       nx = ny % 12; n       ny /= 12; n       if (nx == 0 || nx == w + 1 || ny == 0) { n         printf( %d %d n , ny, nx); n         break; n       } n       int d = dir[in[ny][nx]]; n       y = ny + dy[d]; n       x = nx + dx[d]; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = 350; n const long long PHI = (long long)998244352; n const long long INF = 0x3f3f3f3f; n const long long LINF = 0x3f3f3f3f3f3f3f3f; n const long long MOD = (long long)998244353; n const long long OVER_FLOW = 0x7fffffff; n const long long LOVER_FLOW = 0x7fffffffffffffff; n long long n; n struct op { n   long long x1, y1, x2, y2; n }; n long long vis[MAXN][MAXN]; n vector<op> res; n string str; n void add(long long x1, long long y1, long long x2, long long y2) { n   res.push_back((op){x1, y1, x2, y2}); n   vis[x2][y2]++; n } n void move(long long x1, long long y1, bool x) { n   if (x) { n     if (x1 != 1) { n       add(x1, y1, 1, y1); n     } else { n       add(x1, y1, 1, y1 == 1 ? 2 : 1); n     } n   } else { n     if (x1 != 2) { n       add(x1, y1, 2, y1); n     } else { n       add(x1, y1, 2, y1 == 1 ? 2 : 1); n     } n   } n } n int main() { n   ios::sync_with_stdio(false); n   long long m; n   cin >> n >> m; n   for (long long i = 1; i <= n; i++) { n     for (long long j = 1; j <= m; j++) { n       cin >> str; n       for (long long k = str.size() - 1; k >= 0; k--) { n         move(i, j, str[k] ==  1 ); n       } n     } n   } n   for (long long i = 1; i <= 2; i++) { n     for (long long j = 2; j <= m; j++) { n       while (vis[i][j]) { n         add(i, j, i, 1); n         vis[i][j]--; n       } n     } n   } n   long long cnt = res.size(); n   memset(vis, 0, sizeof vis); n   for (long long i = 1; i <= n; i++) { n     for (long long j = 1; j <= m; j++) { n       cin >> str; n       for (auto k : str) { n         move(i, j, k ==  1 ); n       } n     } n   } n   for (long long i = 1; i <= 2; i++) { n     for (long long j = 2; j <= m; j++) { n       while (vis[i][j]) { n         add(i, j, i, 1); n         vis[i][j]--; n       } n     } n   } n   cout << res.size() <<   n ; n   for (long long i = 0; i < cnt; i++) { n     cout << res[i].x1 <<     << res[i].y1 <<     << res[i].x2 <<     n          << res[i].y2 <<   n ; n   } n   for (long long i = res.size() - 1; i >= cnt; i--) { n     cout << res[i].x2 <<     << res[i].y2 <<     << res[i].x1 <<     n          << res[i].y1 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n long long k, L, R, a[2222222], b[2222222], ans, sum[2222222]; n int n, r; n long long min(long long a, long long b) { return a < b ? a : b; } n long long max(long long a, long long b) { return a > b ? a : b; } n bool check(long long x) { n   long long ans = 0, now = 0; n   memset(b, 0, sizeof(b)); n   for (int i = 1; i <= n; i++) { n     now += b[i]; n     if (a[i] + now < x) n       ans += x - a[i] - now, b[i + 2 * r + 1] -= x - a[i] - now, n           now += x - a[i] - now; n     if (ans > k) return 0; n   } n   return 1; n } n int main() { n   scanf( %d%d%lld , &n, &r, &k); n   L = 2e18; n   for (int i = 1; i <= n; i++) n     scanf( %lld , &sum[i]), L = min(L, sum[i]), sum[i] += sum[i - 1]; n   for (int i = 1; i <= n; i++) n     a[i] = sum[min(i + r, n)] - sum[max(0, i - r - 1)]; n   R = 1e20; n   while (L <= R) { n     long long mid = L + R >> 1; n     if (check(mid)) n       L = mid + 1, ans = mid; n     else n       R = mid - 1; n   } n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int n; n   cin >> n; n   vector<long long> a(n); n   vector<int> nx(n); n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   map<long long, int> mp; n   long long sig = 0; n   for (int i = 0; i < 3 * n; i++) { n     int ri = (i % n); n     nx[mp[sig]] = ri; n     mp[sig] = ri; n     sig += a[ri]; n   } n   int res = n; n   for (int i = 0; i < n; i++) { n     int len = 1, p = nx[i]; n     if (p == -1) { n       continue; n     } n     nx[i] = -1; n     while (p != i) { n       len++; n       int np = nx[p]; n       nx[p] = -1; n       p = np; n     } n     res = min(n - len, res); n   } n   cout << res <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, t; n   cin >> n >> t; n   long long int A[n]; n   for (long long int i = 0; i < n; i++) { n     cin >> A[i]; n   } n   long long int cnt = 0; n   long long int sum = 0; n   long long int i = 0; n   long long int j = 0; n   for (i = 0; i < n; i++) { n     sum += A[i]; n     if (sum <= t) { n       cnt++; n     } else { n       sum -= A[j]; n       j++; n     } n   } n   cout << cnt << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int nnext[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; n long long gcd(long long x, long long y) { return !y ? x : gcd(y, x % y); } n int main() { n   int n, m, k, idx, x, y, now, have, array[350][350]; n   cin >> n >> m >> k, x = y = 1, idx = now = have = 0; n   vector<vector<pair<int, int> > > ans(k); n   while (k) { n     if (k == 1) { n       if (y > m) n         x++, y = m, now = 1; n       else if (!y) n         x++, y = 1, now = 0; n       ans[idx].push_back(make_pair(x, y)), have++; n       if (have == n * m) break; n       if (!now) n         y++; n       else n         y--; n       continue; n     } else { n       ans[idx].push_back(make_pair(x, y)), have++; n       if (!now) n         y++; n       else n         y--; n       if (y > m) n         x++, y = m, now = 1; n       else if (!y) n         x++, y = 1, now = 0; n     } n     if (ans[idx].size() == 2) idx++, k--; n   } n   for (int i = 0; i < int(ans.size()); i++) { n     cout << ans[i].size() <<    ; n     for (int j = 0; j < int(ans[i].size()); j++) n       cout << ans[i][j].first <<     << ans[i][j].second <<    ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long BINF = 9e18, LINF = 2e9, mod = 998244353, P = 179, n                 Q = 1791791791; n const long long MAXN = 1e4 + 7; n long long a[MAXN], b[MAXN], c[MAXN]; n vector<pair<long long, long long>> g[MAXN]; n bool cmp(vector<pair<long long, long long>> &a, n          vector<pair<long long, long long>> &b) { n   return a.size() < b.size(); n } n struct way { n   long long a, b, c; n }; n vector<way> ways; n long long h[MAXN]; n long long c1[MAXN], c2[MAXN]; n long long f[MAXN]; n long long tin[MAXN], tout[MAXN]; n long long par[MAXN]; n long long timer = 0; n void dfs(long long v, long long p = -1, long long pc = -1) { n   par[v] = p; n   h[v] = (p == -1 ? 0 : h[p] + 1); n   tin[v] = timer++; n   if (g[v].size() == 1 && p != -1) { n     long long u, c; n     for (pair<long long, long long> e : g[v]) n       if (e.first != p) u = e.first, c = e.second; n     if (pc != c) { n       cout <<  NO ; n       exit(0); n     } n     dfs(u, p, pc); n     return; n   } n   for (pair<long long, long long> e : g[v]) { n     if (e.first == p) continue; n     dfs(e.first, v, e.second); n     if (c1[v] == -1) n       c1[v] = f[e.first]; n     else if (c2[v] == -1) n       c2[v] = f[e.first]; n     f[v] = f[e.first]; n   } n   tout[v] = timer++; n   if (p != -1) ways.push_back(way{p, v, pc}); n   if (g[v].size() == 0) f[v] = c1[v] = c2[v] = v; n } n void dfsd(long long v, long long p = -1) { n   long long ps = -1; n   for (long long i = 0; i < g[v].size(); ++i) { n     if (g[v][i].first == p) n       ps = i; n     else n       dfsd(g[v][i].first, v); n   } n   if (ps != -1) g[v].erase(g[v].begin() + ps); n } n vector<way> answ; n void add(long long a, long long b, long long c) { n   if (a == b) return; n   answ.push_back({a, b, c}); n } n long long lca(long long a, long long b) { n   if (h[a] < h[b]) swap(a, b); n   while (h[a] > h[b]) a = par[a]; n   while (a != b) a = par[a], b = par[b]; n   return a; n } n long long dist(long long a, long long b) { n   return h[a] + h[b] - 2 * h[lca(a, b)]; n } n void solve() { n   long long n; n   cin >> n; n   fill(c1, c1 + n, -1); n   fill(c2, c2 + n, -1); n   for (long long i = 0; i < n - 1; ++i) { n     cin >> a[i] >> b[i] >> c[i]; n     --a[i]; n     --b[i]; n     g[a[i]].push_back({b[i], c[i]}); n     g[b[i]].push_back({a[i], c[i]}); n   } n   long long root = min_element(g, g + n, cmp) - g; n   dfsd(root, -1); n   dfs(root); n   for (way w : ways) { n     if (h[w.a] > h[w.b]) swap(w.a, w.b); n     long long lul = c1[w.a]; n     if (dist(lul, w.b) != dist(lul, w.a) + dist(w.a, w.b)) lul = c2[w.a]; n     if (lul == -1) lul = root; n     add(c1[w.b], c2[w.b], -(w.c / 2)); n     add(root, lul, -(w.c / 2)); n     add(root, c1[w.b], w.c / 2); n     add(lul, c2[w.b], w.c / 2); n   } n   cout <<  YES n ; n   cout << answ.size() <<   n ; n   for (way w : answ) cout << w.a + 1 <<     << w.b + 1 <<     << w.c <<   n ; n   return; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cout.precision(40); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 202000; n int n, m; n struct edge { n   int u, v, w; n } edges[maxn]; n int pre[maxn]; n vector<edge> vec; n int found(int x) { n   int rx = x; n   while (pre[rx] != rx) rx = pre[rx]; n   while (pre[x] != rx) { n     int tmp = pre[x]; n     pre[x] = rx; n     x = tmp; n   } n   return rx; n } n int cmp(edge alpha, edge beta) { return alpha.w < beta.w; } n void read() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; i++) n     scanf( %d%d%d , &edges[i].u, &edges[i].v, &edges[i].w); n   sort(edges + 1, edges + m + 1, cmp); n } n void work() { n   int ans = 0; n   for (int i = 1; i <= n; i++) pre[i] = i; n   for (int i = 1; i <= m;) { n     int j = i; n     vec.clear(); n     while (edges[i].w == edges[j].w) { n       if (found(edges[j].u) == found(edges[j].v)) { n         j++; n         continue; n       } n       vec.push_back(edges[j]); n       j++; n     } n     for (int k = 0; k < vec.size(); k++) { n       if (found(vec[k].u) == found(vec[k].v)) n         ans++; n       else n         pre[found(vec[k].u)] = found(vec[k].v); n     } n     i = j; n   } n   printf( %d n , ans); n } n int main() { n   read(); n   work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = (1 << 18) + 100; n const int maxnode = maxn << 2; n int n, ai[maxn + 5]; n int ls[maxnode + 5], rs[maxnode + 5]; n int re[maxnode + 5], sp[maxnode + 5]; n long long sum[maxnode + 5]; n void Build(int x, int l, int r) { n   re[x] = sp[x] = 0; n   ls[x] = x << 1, rs[x] = x << 1 | 1; n   if (l == r) { n     sum[x] = ai[l]; n     return; n   } n   int &lson = ls[x], &rson = rs[x], mid = (l + r) >> 1; n   Build(lson, l, mid); n   Build(rson, mid + 1, r); n   sum[x] = sum[lson] + sum[rson]; n } n void Replace(int d, int x, int l, int r, int p, int v) { n   if (l == r) { n     sum[x] = v; n     return; n   } n   int &lson = ls[x], &rson = rs[x], mid = (l + r) >> 1; n   if (re[x] >> d & 1) { n     re[x] ^= (1 << d), sp[x] ^= (1 << d), re[lson] ^= (1 << (d + 1)), n         re[rson] ^= (1 << (d + 1)); n   } n   if (sp[x] >> d & 1) { n     sp[x] ^= (1 << d), swap(lson, rson); n   } n   re[lson] ^= re[x], re[rson] ^= re[x], re[x] = 0; n   sp[lson] ^= sp[x], sp[rson] ^= sp[x], sp[x] = 0; n   if (p <= mid) n     Replace(d + 1, lson, l, mid, p, v); n   else n     Replace(d + 1, rson, mid + 1, r, p, v); n   sum[x] = sum[lson] + sum[rson]; n } n long long Sum(int d, int x, int l, int r, int ll, int rr) { n   if (ll <= l && r <= rr) return sum[x]; n   int &lson = ls[x], &rson = rs[x], mid = (l + r) >> 1; n   long long res = 0; n   if (re[x] >> d & 1) { n     re[x] ^= (1 << d), sp[x] ^= (1 << d), re[lson] ^= (1 << (d + 1)), n         re[rson] ^= (1 << (d + 1)); n   } n   if (sp[x] >> d & 1) { n     sp[x] ^= (1 << d), swap(lson, rson); n   } n   re[lson] ^= re[x], re[rson] ^= re[x], re[x] = 0; n   sp[lson] ^= sp[x], sp[rson] ^= sp[x], sp[x] = 0; n   if (ll <= mid) res += Sum(d + 1, lson, l, mid, ll, rr); n   if (mid < rr) res += Sum(d + 1, rson, mid + 1, r, ll, rr); n   return res; n } n int main() { n   int _; n   scanf( %d%d , &n, &_); n   int pn = n; n   n = (1 << n); n   for (int i = 1; i <= n; ++i) scanf( %d , ai + i); n   Build(1, 1, n); n   while (_--) { n     int o, x, k, l, r; n     scanf( %d , &o); n     if (o == 1) { n       scanf( %d%d , &x, &k); n       Replace(0, 1, 1, n, x, k); n     } else if (o == 2) { n       scanf( %d , &k); n       k = pn - k; n       re[1] ^= (1 << k); n     } else if (o == 3) { n       scanf( %d , &k); n       k = pn - 1 - k; n       sp[1] ^= (1 << k); n     } else { n       scanf( %d%d , &l, &r); n       long long ans = Sum(0, 1, 1, n, l, r); n       printf( %lld n , ans); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct deal { n   long num_person; n   long num_shoue; n   vector<deal> *d; n  n  public: n   deal(long _p, long _s, vector<deal> *_d) { n     num_person = _p; n     num_shoue = _s; n     d = _d; n   } n   deal(long _p, long _s) { n     num_person = _p; n     num_shoue = _s; n     d = NULL; n   } n }; n long n, m; n vector<vector<long long>> d1; n map<long, vector<long long>> people; n map<long, vector<long>> num_people; n map<long, long long> shoes; n map<long, long> num_shoes; n long long max(long long a, long long b) { return a > b ? a : b; } n int main() { n   scanf( %d , &n); n   shoes = map<long, long long>(); n   num_shoes = map<long, long>(); n   long size, money; n   for (long i = 0; i < n; i++) { n     scanf( %d%d , &money, &size); n     shoes[size] = money; n     num_shoes[size] = i; n   } n   scanf( %d , &m); n   people = map<long, vector<long long>>(); n   for (long i = 0; i < m; i++) { n     scanf( %d%d , &money, &size); n     if (!people.count(size)) { n       people[size] = vector<long long>(2, 0); n       num_people[size] = vector<long>(2, -1); n     } n     if (people[size][0] < money) { n       people[size][1] = people[size][0]; n       num_people[size][1] = num_people[size][0]; n       people[size][0] = money; n       num_people[size][0] = i; n     } else if (people[size][1] < money) { n       people[size][1] = money; n       num_people[size][1] = i; n     } n   } n   map<long, vector<long long>>::iterator i = people.begin(); n   long money2; n   size = -10; n   d1 = vector<vector<long long>>(m, vector<long long>(2, 0)); n   long k = 0; n   vector<deal> *p10 = new vector<deal>(); n   vector<deal> *p11 = new vector<deal>(); n   vector<deal> *pp10; n   vector<deal> *pp11; n   long size10 = 0; n   long size11 = 0; n   long psize10; n   long psize11; n   long prev_size; n   for (i = people.begin(); i != people.end(); i++) { n     psize10 = size10; n     psize11 = size11; n     pp10 = p10; n     pp11 = p11; n     p10 = new vector<deal>(); n     p10->reserve(3); n     p11 = new vector<deal>(); n     p11->reserve(3); n     prev_size = size; n     size = i->first; n     money = i->second[0]; n     money2 = i->second[1]; n     if (prev_size + 1 < size) { n       p10->push_back(deal(-1, -1, pp11)); n       p11->push_back(deal(-1, -1, pp11)); n       size10 = psize11; n       size11 = psize11; n       if (shoes[size] > 0 && shoes[size] <= money) { n         d1[k][0] = shoes[size]; n         p10->push_back(deal(num_people[size][0], num_shoes[size])); n         size10++; n       } else n         d1[k][0] = 0; n       d1[k][1] = 0; n       if (shoes[size] > 0 && shoes[size + 1] > 0) { n         long cost, cost2; n         bool p = 0; n         if (shoes[size] > shoes[size + 1]) { n           cost = shoes[size]; n           cost2 = shoes[size + 1]; n           p = 0; n         } else { n           cost = shoes[size + 1]; n           cost2 = shoes[size]; n           p = 1; n         } n         if (money >= cost) { n           d1[k][1] += cost; n           if (!p) { n             p11->push_back(deal(num_people[size][0], num_shoes[size])); n             size11++; n           } else { n             p11->push_back(deal(num_people[size][0], num_shoes[size + 1])); n             size11++; n           } n           if (money2 >= cost2) { n             d1[k][1] += cost2; n             if (!p) { n               p11->push_back(deal(num_people[size][1], num_shoes[size + 1])); n               size11++; n             } else { n               p11->push_back(deal(num_people[size][1], num_shoes[size])); n               size11++; n             } n           } n         } else { n           if (money >= cost2) { n             d1[k][1] += cost2; n             if (!p) { n               p11->push_back(deal(num_people[size][0], num_shoes[size + 1])); n               size11++; n             } else { n               p11->push_back(deal(num_people[size][0], num_shoes[size])); n               size11++; n             } n           } n         } n       } else { n         if (shoes[size] > 0 && shoes[size] <= money) { n           d1[k][1] = shoes[size]; n           p11->push_back(deal(num_people[size][0], num_shoes[size])); n           size11++; n         } n         if (shoes[size + 1] > 0 && shoes[size + 1] <= money) { n           d1[k][1] = shoes[size + 1]; n           p11->push_back(deal(num_people[size][0], num_shoes[size + 1])); n           size11++; n         } n       } n       if (k != 0) { n         d1[k][0] += d1[k - 1][1]; n         d1[k][1] += d1[k - 1][1]; n       } n     } else { n       long cost = 0; n       if (shoes[size] > 0 && shoes[size] <= money) cost = shoes[size]; n       d1[k][0] = max(d1[k - 1][0] + cost, d1[k - 1][1]); n       if (d1[k - 1][0] + cost > d1[k - 1][1]) { n         p10->push_back(deal(-1, -1, pp10)); n         if (cost) { n           p10->push_back(deal(num_people[size][0], num_shoes[size])); n           size10++; n         } n       } else { n         p10->push_back(deal(-1, -1, pp11)); n       } n       cost = 0; n       long cost2 = 0; n       if (shoes[size] > 0 && shoes[size + 1] > 0) { n         if (shoes[size] > shoes[size + 1]) { n           if (shoes[size] <= money) { n             cost = shoes[size]; n             if (shoes[size + 1] <= money2) cost2 = shoes[size + 1]; n           } else { n             if (shoes[size + 1] <= money) { n               cost2 = shoes[size + 1]; n             } n           } n         } else { n           if (shoes[size + 1] <= money) { n             cost2 = shoes[size + 1]; n             if (shoes[size] <= money2) cost = shoes[size]; n           } else { n             if (shoes[size] <= money) { n               cost = shoes[size]; n             } n           } n         } n       } else { n         if (shoes[size] > 0 && shoes[size] <= money) cost = shoes[size]; n         if (shoes[size + 1] > 0 && shoes[size + 1] <= money) n           cost2 = shoes[size + 1]; n       } n       long cost3 = 0; n       if (shoes[size + 1] > 0 && shoes[size + 1] <= money) n         cost3 = shoes[size + 1]; n       d1[k][1] = 0; n       d1[k][1] = max(d1[k - 1][0] + cost + cost2, d1[k - 1][1] + cost3); n       if (d1[k - 1][0] + cost + cost2 > d1[k - 1][1] + cost3) { n         p11->push_back(deal(-1, -1, pp10)); n         if (cost != 0 && cost2 != 0) { n           if (cost > cost2) { n             p11->push_back(deal(num_people[size][0], num_shoes[size])); n             p11->push_back(deal(num_people[size][1], num_shoes[size + 1])); n             size11++; n             size11++; n           } else { n             p11->push_back(deal(num_people[size][0], num_shoes[size + 1])); n             p11->push_back(deal(num_people[size][1], num_shoes[size])); n             size11++; n             size11++; n           } n         } else { n           if (cost) { n             p11->push_back(deal(num_people[size][0], num_shoes[size])); n             size11++; n           } n           if (cost2) { n             p11->push_back(deal(num_people[size][0], num_shoes[size + 1])); n             size11++; n           } n         } n       } else { n         p11->push_back(deal(-1, -1, pp11)); n         if (cost3) { n           p11->push_back(deal(num_people[size][0], num_shoes[size + 1])); n           size11++; n         } n       } n     } n     k++; n   } n   printf( %I64d n , d1[k - 1][1]); n   printf( %d n , size11); n   vector<deal> *p; n   p = p11; n   while ((*p).size() != 0) { n     for (int j = 1; j < (*p).size(); j++) { n       if ((*p)[j].num_person + 1 < 0) break; n       printf( %d %d n , (*p)[j].num_person + 1, (*p)[j].num_shoue + 1); n     } n     p = (*p)[0].d; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int ckmax(int &a, int b) { return a < b ? a = b, 1 : 0; } n inline int ckmin(int &a, int b) { return a > b ? a = b, 1 : 0; } n struct matrix { n   double x[128][128]; n   double *operator[](int a) { return x[a]; } n   void clear() { memset(x, 0, sizeof(x)); } n   void reset() { n     clear(); n     for (int i = 0; i < 128; ++i) x[i][i] = 1; n   } n } p, a, ans; n matrix operator*(matrix &a, matrix &b) { n   p.clear(); n   for (int i = 0; i < 128; i++) n     for (int j = 0; j < 128; j++) n       for (int k = 0; k < 128; k++) p[i][j] += a[i][k] * b[k][j]; n   return p; n } n int n, x; n double pos[128]; n int main() { n   scanf( %d%d , &n, &x); n   for (int i = 0; i <= x; ++i) scanf( %lf , &pos[i]); n   a.clear(); n   for (int i = 0; i < 128; ++i) n     for (int j = 0; j < 128; ++j) a[i][j] = pos[i ^ j]; n   ans.reset(); n   for (; n; n >>= 1, a = a * a) n     if (n & 1) ans = ans * a; n   printf( %.10f n , 1.0 - double(ans[0][0])); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   ; n   int n, value; n   char str[200]; n   cin >> n; n   vector<int> v; n   for (int i = 0; i < n; i++) { n     cin >> str; n     if (strcmp(str,  add ) == 0) { n       cin >> value; n       v.insert(lower_bound(v.begin(), v.end(), value), value); n     } else if (strcmp(str,  del ) == 0) { n       cin >> value; n       v.erase(lower_bound(v.begin(), v.end(), value)); n     } else if (strcmp(str,  sum ) == 0) { n       long long sum = 0; n       for (int j = 2; j < v.size(); j += 5) { n         sum += v[j]; n       } n       cout << sum << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline bool read(T &x) { n   int c = getchar(); n   int sgn = 1; n   while ((~c && c <  0 ) || c >  9 ) { n     if (c ==  - ) sgn = -1; n     c = getchar(); n   } n   for (x = 0; ~c &&  0  <= c && c <=  9 ; c = getchar()) x = x * 10 + c -  0 ; n   x *= sgn; n   return ~c; n } n int X[] = {-1, 0, 1, 0}; n int Y[] = {0, 1, 0, -1}; n int main() { n   int n; n   read(n); n   int win = 2; n   for (int i = 1; i <= n; i++) { n     int a; n     read(a); n     if (a % 2 == 0) { n       win = (win == 2) ? 1 : 2; n     } n     printf( %d n , win); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 200010; n set<pair<long long, long long> > st; n int resp[maxn]; n struct island { n   long long ini, fim; n } isl[maxn]; n struct event { n   long long type, val, ini; n   event() { type = 0, val = 0, ini = 0; } n   event(long long a, long long b, long long c) { n     type = a; n     val = b; n     ini = c; n   } n } e[2 * maxn]; n bool cmp(event a, event b) { n   if (a.ini == b.ini && a.type == b.type) return a.val < b.val; n   if (a.ini == b.ini) return a.type < b.type; n   return a.ini < b.ini; n } n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   long long al, bl; n   int siz = 0; n   for (int i = 0; i < n; i++) { n     long long a, b; n     scanf( %I64d %I64d , &a, &b); n     if (i != 0) { n       isl[i - 1].fim = b - al; n       isl[i - 1].ini = a - bl; n       int atual = i - 1; n       e[siz++] = event(1, atual, isl[i - 1].ini); n     } n     al = a; n     bl = b; n   } n   for (int i = 0; i < m; i++) { n     long long q; n     scanf( %I64d , &q); n     e[siz++] = event(2, i, q); n   } n   sort(e, e + siz, cmp); n   for (int i = 0; i < siz; i++) { n     if (e[i].type == 1) { n       st.insert(make_pair(isl[e[i].val].fim, e[i].val)); n     } else { n       set<pair<long long, long long> >::iterator it = n           st.lower_bound(make_pair(e[i].ini, -1LL)); n       if (it != st.end()) { n         resp[it->second] = e[i].val; n         st.erase(it); n       } n     } n   } n   int ok = 1; n   if (!st.empty()) ok = 0; n   if (ok) { n     puts( Yes ); n     for (int i = 0; i < n - 1; i++) { n       printf( %d  , resp[i] + 1); n     } n     printf(  n ); n   } else { n     puts( No ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a[10000], i, sum = 0; n   scanf( %d , &n); n   for (i = 0; i < n; i++) { n     scanf( %d , &a[i]); n   } n   int maxv = a[0]; n   int minv = a[0]; n   for (i = 1; i < n; ++i) { n     if (maxv < a[i]) { n       maxv = a[i]; n       sum++; n     } else if (minv > a[i]) { n       minv = a[i]; n       sum++; n     } n   } n   printf( %d n , sum); n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int s[505][505]; n int main() { n   scanf( %d%d , &n, &m); n   char c = getchar(); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       c = getchar(); n       if (c ==  S ) n         s[i][j] = 0; n       else if (c ==  W ) n         s[i][j] = 1; n       else n         s[i][j] = 2; n     } n     getchar(); n   } n   bool f = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       if (s[i][j] == 1) { n         if (i > 1 && s[i - 1][j] == 0) f = 1; n         if (j > 1 && s[i][j - 1] == 0) f = 1; n         if (i < n && s[i + 1][j] == 0) f = 1; n         if (j < m && s[i][j + 1] == 0) f = 1; n       } n     } n   } n   if (f) { n     printf( No n ); n     return 0; n   } n   printf( Yes n ); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       if (s[i][j] == 0) { n         printf( S ); n       } else if (s[i][j] == 1) n         printf( W ); n       else n         printf( D ); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n, i, j, c = 0, p, q, f = 0; n   scanf( %d , &n); n   scanf( %d , &p); n   int a[p]; n   for (i = 0; i < p; i++) scanf( %d , &a[i]); n   scanf( %d , &q); n   int b[q]; n   for (i = 0; i < q; i++) scanf( %d , &b[i]); n   for (i = 1; i <= n; i++) { n     f = 0; n     for (j = 0; j < p; j++) { n       if (a[j] == i) { n         c++; n         f++; n       } n     } n     if (f == 0) { n       for (j = 0; j < q; j++) { n         if (b[j] == i) { n           c++; n         } n       } n     } n   } n   if (n == c) n     printf( I become the guy. n ); n   else n     printf( Oh, my keyboard! n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1000018; n char str[2][510000], text[1010000]; n int n, ans[1010000], num_node, fail[1010000], nxt[1010000], len[1010000], n     to[1010000][26], path[1010000], pa[1010000]; n int dl[1010000], last, save[1010000], ie[1010000]; n void init() { n   num_node = 2; n   fail[0] = 1; n   len[1] = -1; n   len[0] = 0; n   nxt[0] = 1; n   last = 0; n } n int get_fail(int id, int pos) { n   while (pos - len[id] - 1 < 1 || text[pos - len[id] - 1] != text[pos]) n     id = fail[id]; n   return id; n } n void add_letter(int pos) { n   int cur = get_fail(last, pos); n   if (!to[cur][text[pos] -  a ]) { n     len[num_node] = len[cur] + 2; n     fail[num_node] = to[get_fail(fail[cur], pos)][text[pos] -  a ]; n     dl[num_node] = len[num_node] - len[fail[num_node]]; n     if (dl[num_node] == dl[fail[num_node]]) n       nxt[num_node] = nxt[fail[num_node]]; n     else n       nxt[num_node] = fail[num_node]; n     to[cur][text[pos] -  a ] = num_node++; n   } n   last = to[cur][text[pos] -  a ]; n } n int main() { n   scanf( %s%s , str[0], str[1]); n   n = strlen(str[0]); n   int i, j, s, p, q; n   for (i = 0; i < n; i++) { n     text[2 * i] = str[0][i]; n     text[2 * i + 1] = str[1][i]; n   } n   n *= 2; n   for (i = n - 1; i >= 0; i--) text[i + 1] = text[i]; n   init(); n   for (i = 1; i <= n; i++) { n     add_letter(i); n     ans[i] = inf; n     for (j = last; len[j] > 0; j = nxt[j]) { n       save[j] = ans[i - len[nxt[j]] - dl[j]]; n       path[j] = i - len[nxt[j]] - dl[j]; n       if (dl[j] == dl[fail[j]]) { n         if (save[j] > save[fail[j]]) { n           save[j] = save[fail[j]]; n           path[j] = path[fail[j]]; n         } n       } n       if (!(i & 1)) { n         if (ans[i] > save[j] + 1) { n           ans[i] = save[j] + 1; n           pa[i] = path[j]; n         } n       } n     } n     if (!(i & 1) && text[i] == text[i - 1]) { n       if (ans[i] > ans[i - 2]) { n         ans[i] = ans[i - 2]; n         pa[i] = i - 2; n       } n     } n   } n   if (ans[n] == inf) n     puts( -1 ); n   else { n     printf( %d n , ans[n]); n     int id = n; n     while (id > 0) { n       if (pa[id] + 2 != id) printf( %d %d n , pa[id] / 2 + 1, id / 2); n       id = pa[id]; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double EPS = 1e-9; n const double INF = 1e6; n const double PI = atan2(0, -1); n const int maxn = 550; n inline int sgn(double x) { n   if (fabs(x) < EPS) return 0; n   return x < 0 ? -1 : 1; n } n inline int iseq(double x, double y) { return sgn(x - y) == 0; } n struct Point { n   double x, y; n   Point(double x = 0, double y = 0) : x(x), y(y) {} n   double Angle() { return atan2(y, x); } n }; n inline Point operator+(Point A, Point B) { return Point(A.x + B.x, A.y + B.y); } n inline Point operator-(Point A, Point B) { return Point(A.x - B.x, A.y - B.y); } n inline Point operator*(double x, Point A) { return Point(x * A.x, x * A.y); } n inline double operator*(Point A, Point B) { return A.x * B.x + A.y * B.y; } n inline double operator%(Point A, Point B) { return A.x * B.y - A.y * B.x; } n inline double Length2(Point A) { return A * A; } n inline double Length(Point A) { return sqrt(A * A); } n inline double Distance2(Point A, Point B) { return Length2(A - B); } n inline double Distance(Point A, Point B) { return Length(A - B); } n inline bool operator==(Point A, Point B) { return iseq(Distance(A, B), 0); } n inline bool operator<(Point A, Point B) { n   return iseq(A.x, B.x) ? sgn(A.y - B.y) == -1 : sgn(A.x - B.x) == -1; n } n struct Line { n   Point P, Q; n   Line() {} n   Line(Point A, Point B) { n     P = A; n     Q = B; n   } n   Point Direction() { return Q - P; } n }; n inline int IsOnLine(Point P, Line l) { return sgn((l.P - P) % (l.Q - P)) == 0; } n inline int IsOnSegment(Point P, Line l) { n   if (P == l.P || P == l.Q) return 1; n   return sgn((l.P - P) % (l.Q - P)) == 0 && sgn((l.P - P) * (l.Q - P)) <= 0; n } n inline bool IsSegmentOverlap(Line A, Line B) { n   if (iseq(A.Direction() % B.Direction(), 0)) n     return IsOnSegment(A.P, B) + IsOnSegment(A.Q, B) + IsOnSegment(B.P, A) + n                IsOnSegment(B.Q, A) >= n            2; n   else n     return false; n } n inline bool IsSegmentIntersected(Line A, Line B) { n   if (IsOnSegment(A.P, B) || IsOnSegment(A.Q, B)) return true; n   if (IsOnSegment(B.P, A) || IsOnSegment(B.Q, A)) return true; n   int sgn1 = sgn((A.P - B.P) % B.Direction()), n       sgn2 = sgn((A.Q - B.P) % B.Direction()); n   int sgn3 = sgn((B.P - A.P) % A.Direction()), n       sgn4 = sgn((B.Q - A.P) % A.Direction()); n   return sgn1 * sgn2 == -1 && sgn3 * sgn4 == -1; n } n inline Point getLineIntersection(Line A, Line B) { n   Point v = A.Direction(), w = B.Direction(); n   Point u = B.P - A.P; n   return A.P + ((w % u) / (w % v)) * v; n } n int n; n vector<Point> Rect[maxn]; n double area1, area2; n inline double getPolygonArea(const vector<Point> &A) { n   double ans = 0; n   for (auto j = 1u; j + 1 < A.size(); ++j) n     ans += (A[j] - A[0]) % (A[j] - A[0]) * 0.5; n   return ans; n } n inline bool IsInPolygon(Point P, const vector<Point> &A) { n   double area1 = getPolygonArea(A), area2 = 0.0; n   for (auto j = 0u; j + 1 < A.size(); ++j) n     area2 += (A[j] - P) % (A[j + 1] - P) * 0.5; n   return iseq(area1, area2); n } n inline bool IsPolygonOverlap(vector<Point> P[], int i, int j) { n   int sgn = 1; n   for (auto k = 0u; k < P[i].size(); ++k) n     if (!IsInPolygon(P[i][k], P[j])) { n       sgn = 0; n       break; n     } n   if (!sgn) return false; n   if (iseq(getPolygonArea(P[i]), getPolygonArea(P[j]))) return i < j; n   return true; n } n struct info { n   Point P; n   double ang; n   int delta; n   info() {} n   info(Point x, double y, int z) { n     P = x; n     ang = y; n     delta = z; n   } n }; n inline int operator<(const info &A, const info &B) { n   if (iseq(A.ang, B.ang)) n     return A.delta > B.delta; n   else n     return A.ang < B.ang; n } n inline double getPosition(Point P, Line l) { n   return ((P - l.P) * l.Direction()) / (l.Direction() * l.Direction()); n   return (P.x - l.P.x) / (l.Q.x - l.P.x); n } n double ans[maxn]; n double getAreaUnion(vector<Point> P[], int n, double *ans) { n   for (int i = 1; i <= n; ++i) ans[i] = 0.0; n   static vector<pair<double, int>> PointList; n   double aans = 0; n   for (int i = 1; i <= n; ++i) n     for (auto j = 0u; j + 1 < P[i].size(); ++j) { n       Line A(P[i][j], P[i][j + 1]); n       PointList.clear(); n       for (int k = 1; k <= n; ++k) n         if (i != k) n           for (auto w = 0u; w + 1 < P[k].size(); ++w) { n             Line B(P[k][w], P[k][w + 1]); n             int p1 = sgn((B.P - A.P) % A.Direction()); n             int p2 = sgn((B.Q - A.P) % A.Direction()); n             if (!p1 && !p2) { n               if (i < k && sgn(A.Direction() * B.Direction()) == 1) { n                 PointList.push_back( n                     make_pair(min(1.0, max(getPosition(B.P, A), 0.0)), -1)); n                 PointList.push_back( n                     make_pair(min(1.0, max(getPosition(B.Q, A), 0.0)), 1)); n               } n             } else { n               Point tp = getLineIntersection(A, B); n               if (p1 >= 0 && p2 < 0) n                 PointList.push_back( n                     make_pair(min(1.0, max(getPosition(tp, A), 0.0)), -1)); n               if (p1 < 0 && p2 >= 0) n                 PointList.push_back( n                     make_pair(min(1.0, max(getPosition(tp, A), 0.0)), 1)); n             } n           } n       PointList.push_back(make_pair(0.0, 1)); n       PointList.push_back(make_pair(1.0, -1)); n       sort(PointList.begin(), PointList.end()); n       double S0 = A.P % A.Q * 0.5; n       double lst = 0; n       int now = 0; n       for (auto l = 0u, r = 0u; l < PointList.size();) { n         ans[now] += S0 * (PointList[l].first - lst); n         lst = PointList[l].first; n         for (r = l + 1; r < PointList.size() && iseq(PointList[r].first, lst); n              ++r) n           ; n         for (auto w = l; w < r; ++w) now += PointList[w].second; n         l = r; n       } n     } n   return ans[1]; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= 4; ++j) { n       Point P; n       scanf( %lf%lf , &P.x, &P.y); n       Rect[i].push_back(P); n     } n     if (sgn((Rect[i][1] - Rect[i][0]) % (Rect[i][2] - Rect[i][0])) == -1) n       reverse(Rect[i].begin(), Rect[i].end()); n     area1 += (Rect[i][1] - Rect[i][0]) % (Rect[i][3] - Rect[i][0]); n     Rect[i].push_back(Rect[i][0]); n   } n   area2 = getAreaUnion(Rect, n, ans); n   printf( %.10lf n , area1 / area2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long n; n   cin >> n; n   vector<long long> arr(n); n   for (long long i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   sort(arr.begin(), arr.end()); n   if (arr[n - 1] == 1) { n     arr[n - 1] = 2; n   } else { n     arr[n - 1] = 1; n   } n   sort(arr.begin(), arr.end()); n   for (long long i = 0; i < n; i++) { n     cout << arr[i] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long int power(long long int x, long long int y) { n   if (y == 0) return 1; n   if (y & 1) return (x * power(x, y - 1)) % 1000000007; n   long long int t = power(x, y / 2); n   return (t * t) % 1000000007; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   string s; n   cin >> s; n   set<int> arr[26]; n   int n = (int)s.size(); n   for (int i = 0; i < n; i++) arr[s[i] -  a ].insert(i); n   string mk =  Mike n ; n   string ann =  Ann n ; n   bool found = false; n   for (int i = 0; i < n; i++) { n     found = false; n     for (int j = 0; j < s[i] -  a ; j++) { n       auto itr = arr[j].lower_bound(0); n       if (itr != arr[j].end() && *itr < i) { n         found = true; n         break; n       } n     } n     if (true == found) n       cout << ann; n     else n       cout << mk; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int N = 1000010; n const int inf = 0x3f3f3f3f; n using namespace std; n int n, m; n int c[N]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < m; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     c[a]++; n     c[b]++; n   } n   if (n < 3) return puts( 0 ), 0; n   long long ret = 0; n   for (int i = 1; i <= n; i++) ret += 1ll * c[i] * (n - 1 - c[i]); n   ret /= 2; n   cout << (1ll * n * (n - 1) * (n - 2) / 6 - ret) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long int; n using dd = double; n using pii = pair<int, int>; n using pll = pair<ll, ll>; n ll INFLL = (ll)2e18, MOD = 1e9 + 7; n const int INF = 0x6f6f6f6f; n vector<vector<ll>> adj; n vector<int> vis; n int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, n     dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0}; n inline ll mexp(ll x, ll n, ll m) { n   ll res = 1; n   while (n) { n     if (n & 1) res = (res * x) % m; n     n >>= 1; n     x = ((x % m) * (x % m)) % m; n   } n   return res; n } n inline bool ispow2(ll x) { return x && (!(x & (x - 1))); } n inline ll gcd(ll x, ll y) { n   pll p{x, y}; n   while (p.second) p = {p.second, p.first % p.second}; n   return p.first; n } n int main(void) { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cout << fixed; n   cerr << fixed; n   cout << setprecision(10); n   cerr << setprecision(3); n   mt19937 genr(chrono::high_resolution_clock::now().time_since_epoch().count()); n   int n; n   cin >> n; n   vector<int> seq(n + 1); n   map<int, int> m; n   for (int i = 0; i < n; ++i) { n     int t; n     cin >> t; n     m[t] = i + 1; n   } n   int ct = 1; n   for (auto& e : m) seq[e.second] = ct++; n   m.clear(); n   vector<ll> tree(n + 1, 0); n   auto sum = [&](int pos) { n     ll ret = 0; n     while (pos) { n       ret += tree[pos]; n       pos -= pos & -pos; n     } n     return ret; n   }; n   auto upd = [&](int pos, ll val) { n     while (pos <= n) { n       tree[pos] += val; n       pos += pos & -pos; n     } n   }; n   ll ans = 0; n   for (int i = 1; i <= n; ++i) { n     ll gr = sum(n) - sum(seq[i]); n     ll le = seq[i] - 1 - sum(seq[i] - 1); n     ans += gr * le; n     upd(seq[i], 1); n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<long long, int> > H[1000007]; n long long n, val[1000005], ans, cnt[1000005]; n int S[1000005]; n int m, up[1000005], p[1000005], len, b[1000005], mp[1000005]; n void prepare() { n   int i, j; n   b[1] = 1; n   for (i = 2; i < 1000005; i++) { n     if (!b[i]) p[++len] = i; n     for (j = 1; j <= len; j++) { n       if (1LL * i * p[j] >= 1000005) break; n       b[1LL * i * p[j]] = 1; n       if (i % p[j] == 0) break; n     } n   } n   for (i = 1; i < 1000005; i++) S[i] = S[i - 1] + (!b[i]); n   for (i = 1; i <= len; i++) mp[p[i]] = i; n   for (i = 1000005 - 1; i >= 1; i--) mp[i] = mp[i] ? mp[i] : mp[i + 1]; n } n int SQRT(long long n) { n   int p = (int)(sqrt(n)); n   while (1LL * p * p <= n) p++; n   return p; n } n long long find(long long x, int t) { n   int i, u = x % 1000007, p; n   for (i = 0; i < H[u].size(); i++) n     if (H[u][i].first == x) break; n   p = H[u][i].second; n   return t > up[p] ? cnt[p] + up[p] - t : cnt[p]; n } n long long Pi(int t) { return cnt[t] + up[t] - 1; } n void update(int t) { n   long long i, x = val[t], l = n / (x + 1) + 1, r = n / x; n   r = min(r, (long long)(sqrt(n))); n   for (i = l; i <= r; i++) n     if (!b[i]) ans += Pi(t) - S[i]; n } n int main() { n   long long i, j = 1, q = 1; n   long long x = 0; n   cin >> n; n   prepare(), m = 1; n   for (i = 1; 1LL * p[i] * p[i] * p[i] <= n; i++) ans++; n   for (i = 1; i <= n; i = n / (val[m++]) + 1) val[m] = n / i; n   m--, sort(val + 1, val + m + 1); n   for (i = 1; i <= m; i++) n     H[val[i] % 1000007].push_back(pair<long long, int>(val[i], i)); n   for (i = 1; i <= m; i++) up[i] = mp[SQRT(val[i])]; n   for (i = 1; i <= up[m]; i++) { n     for (j = m; j >= q; j--) { n       if (i != 1) { n         x = find(val[j] / p[i - 1], i - 1); n         cnt[j] = cnt[j] - x - 1; n       } else n         cnt[j] = val[j] - 1; n     } n     while (q <= m && i == up[q]) update(q++); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(0); n   long long n, i, j, k, l, m, arr[100010], arr1[100010], x, y; n   double a, b, c, d, p, t; n   cin >> n; n   for (i = 0; i < n; i++) cin >> arr[i]; n   sort(arr, arr + n); n   reverse(arr, arr + n); n   arr1[0] = arr[0]; n   for (i = 1; i < n; i++) arr1[i] = arr1[i - 1] + arr[i]; n   m = 9999999999; n   for (i = 0; i < n - 1; i++) n     m = min(abs(abs(arr1[n - 1] - arr1[i]) - arr1[i]) + 1, m); n   cout << m; n } n


#include <bits/stdc++.h> n using namespace std; n int in() { n   int n; n   scanf( %d , &n); n   return n; n } n long long Lin() { n   long long n; n   scanf( %lld , &n); n   return n; n } n double Din() { n   double n; n   scanf( %lf , &n); n   return n; n } n const long long inf = (long long)1e17; n const long long mod = (long long)1e9 + 7; n const int N = 5e5 + 5; n struct trie { n   trie* node[2]; n   int cnt; n   trie() { n     node[0] = node[1] = NULL; n     cnt = 0; n   } n }; n void add(trie* root, long long x, bool ck) { n   for (int i = 1; i <= 18; i++) { n     int p = (x % 2 == 1); n     x /= 10; n     if (root->node[p] == NULL) root->node[p] = new trie; n     root = root->node[p]; n   } n   ck ? root->cnt++ : root->cnt--; n } n int query(trie* root, string s) { n   reverse(s.begin(), s.end()); n   while (s.size() < 18) s.push_back( 0 ); n   for (int i = 0; i < 18; i++) { n     int p = s[i] -  0 ; n     if (root->node[p] == NULL) return 0; n     root = root->node[p]; n   } n   return root->cnt; n } n int solve() { n   int q = in(); n   trie* root = new trie; n   while (q--) { n     string ck; n     long long x; n     cin >> ck; n     if (ck ==  + ) { n       x = Lin(); n       add(root, x, true); n     } else if (ck ==  - ) { n       x = Lin(); n       add(root, x, false); n     } else { n       string s; n       cin >> s; n       printf( %d n , query(root, s)); n     } n   } n   return 0; n } n int main() { n   int test = 1, tc = 0; n   while (test--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(void) { n   int n, k; n   cin >> n >> k; n   int r[257] = {}; n   for (int i = 0; i < 257; i++) { n     r[i] = -1; n   } n   int p; n   for (int i = 0; i < n; i++) { n     cin >> p; n     if (r[p] == -1) { n       for (int j = (p - k + 1 >= 0) ? p - k + 1 : 0; j <= p; j++) { n         if (r[j] == -1) { n           for (int x = j; x <= p; x++) { n             if (r[x] != -1) break; n             r[x] = j; n           } n           break; n         } else if (r[j + 1] == -1 && r[j] + k - 1 >= p) { n           for (int x = j + 1; x <= p; x++) { n             r[x] = r[j]; n           } n           break; n         } n       } n     } n     cout << r[p] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n; n   cin >> n; n   int arr[n]; n   for (int i = 0; i < n; i++) cin >> arr[i]; n   int i = n / 2 - 1, j = n / 2; n   sort(arr, arr + n); n   int x = 0; n   int ans[n]; n   if (n % 2) ans[0] = arr[n / 2], x++, j++; n   for (; i >= 0 && j < n; i--, j++) { n     ans[x++] = arr[i]; n     ans[x++] = arr[j]; n   } n   for (int i = 0; i < n; i++) cout << ans[i] <<    ; n   cout << endl; n } n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1); n void test_case() { n   int n; n   cin >> n; n   cout << fixed << setprecision(10) << (1 / tan(PI / (2 * n))) <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int tc; n   cin >> tc; n   for (int tt = 1; tt <= tc; ++tt) { n     test_case(); n   } n   return 0; n } n


#include <bits/stdc++.h> n struct node { n   char a; n   struct node *left; n   struct node *right; n }; n int main() { n   int t, len; n   char ch[205]; n   struct node *p, *q, *r[26]; n   scanf( %d , &t); n   getchar(); n   while (t--) { n     int flag = 0; n     scanf( %s , ch); n     len = strlen(ch); n     for (int i = 0; i < 26; i++) r[i] = NULL; n     for (int i = 0; i < len; i++) { n       if (r[ch[i] -  a ] == NULL) { n         p = (struct node *)malloc(sizeof(struct node)); n         p->a = ch[i]; n         p->left = NULL; n         p->right = NULL; n         r[ch[i] -  a ] = p; n         if (i > 0) { n           if (r[ch[i - 1] -  a ]->left == NULL) { n             r[ch[i - 1] -  a ]->left = p; n             p->right = r[ch[i - 1] -  a ]; n           } else if (r[ch[i - 1] -  a ]->right == NULL) { n             r[ch[i - 1] -  a ]->right = p; n             p->left = r[ch[i - 1] -  a ]; n           } else { n             printf( NO n ); n             flag = 1; n             break; n           } n         } n       } else { n         if (r[ch[i] -  a ]->left != r[ch[i - 1] -  a ] && n             r[ch[i] -  a ]->right != r[ch[i - 1] -  a ]) { n           printf( NO n ); n           flag = 1; n           break; n         } n       } n     } n     if (flag == 1) continue; n     printf( YES n ); n     for (int i = 0; i < 26; i++) { n       if (r[i] != NULL) { n         q = r[i]; n         while (q->left != NULL) q = q->left; n         while (q != NULL) { n           printf( %c , q->a); n           q = q->right; n         } n         break; n       } n     } n     for (int i = 0; i < 26; i++) n       if (r[i] == NULL) printf( %c , i +  a ); n     printf(  n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = int(2e6); n int n; n bool used[N + 7]; n int main() { n   cin >> n; n   for (int i = 2; i * i <= N; ++i) { n     if (!used[i]) { n       for (int z = i * i; z <= N; z = z + i) used[z] = true; n     } n   } n   int cnt = 0; n   for (int i = 2; i <= N; ++i) n     if (!used[i]) { n       printf( %d  , i); n       ++cnt; n       if (cnt == n) return 0; n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long const M = 2e5 + 10, M2 = 1e5 + 10, mod = 1e9 + 7, inf = 1e9 + 10; n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n; n   cin >> n; n   long long tmp = 1; n   for (long long i = 1;; i++) { n     if (tmp - 1 >= n) return cout << i - 1, 0; n     tmp *= 2; n   } n } n


#include<bits/stdc++.h> n using namespace std; n #define pi acos(-1) n #define printfl   printf( %f n ,f) n #define printd   printf( %lf n ,d) n #define printi   printf( %d n ,p) n #define printl   printf( %ld n ,l) n #define printll   printf( %lld n ,ll) n #define case cout<< Case  <<TEST<< :   n #define forcase   for(int TEST=1;TEST<=test;TEST++) n #define max3(a,b,c) max((a,b),c) n #define min3(a,b,c) min((a,b),c) n #define newl printf(  n ) n #define printd1d2 printf( %lf %lf n ,d1, d2) n #define ll long long int n void solve() n { n     ll n,q;cin>>n>>q; n     string s;cin>>s; n     map <ll,ll> mp; n     ll indx=1; n     for (ll i = 1; i <=26; i++) n         { n             mp[i-1]=i; n              n         } n    ll sum[n+1]; n    sum[0]=0; n    ll l=1; n    for (ll i = 0; i < s.size(); i++) n        { n            sum[l]=sum[l-1]+mp[s[i]- a ]; n            l++; n        } n        n    for (ll i = 0; i < q; i++) n        { n            ll c,d;cin>>c>>d; n            cout<<sum[d]-sum[c-1]<<endl; n        } n      // cout<<sum[13]<<endl; n                  n } n int main() n { n     ios_base::sync_with_stdio(false); n     cin.tie(NULL); n   int test; n  // cin>>test; n   //forcase n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod_factorial[100005]; n long long mod_inv_factorial[100005]; n long long binpow(long long a, long long b) { n   long long res = 1LL; n   while (b) { n     if (b & 1) { n       res = (res * a); n     } n     a = (a * a); n     b >>= 1; n   } n   return res; n } n long long binpowmod(long long a, long long b, long long p) { n   long long res = 1LL; n   while (b) { n     if (b & 1) { n       res = (res * 1LL * a) % 1000000007; n     } n     a = (a * 1LL * a) % 1000000007; n     b >>= 1; n   } n   return res; n } n long long mod_inverse(long long a) { n   return binpowmod(a, 1000000007 - 2, 1000000007); n } n void precomputefact() { n   mod_factorial[0] = 1; n   for (int i = 1; i <= 1e5; i++) { n     mod_factorial[i] = (i * 1LL * mod_factorial[i - 1]) % 1000000007; n   } n   mod_inv_factorial[0] = 1; n   for (int i = 1; i <= 1e5; i++) { n     mod_inv_factorial[i] = n         ((mod_inv_factorial[i - 1]) * 1LL * mod_inverse(i)) % 1000000007; n   } n } n long long modbinomial(long long n, long long k, long long p) { n   long long ans = mod_factorial[n] * mod_inv_factorial[n - k] % 1000000007 * n                   mod_inv_factorial[k] % 1000000007; n   return ans; n } n void solve() { n   int n; n   cin >> n; n   vector<pair<int, int>> temp; n   function<bool(pair<int, int>, pair<int, int>)> comp = [](pair<int, int> a, n                                                            pair<int, int> b) { n     if (a.first < b.first) { n       return true; n     } else if (a.first == b.first) { n       if (a.second > b.second) { n         return true; n       } n     } n     return false; n   }; n   for (int i = 0; i < n; i++) { n     int l, r; n     cin >> l >> r; n     temp.push_back(make_pair(l, r)); n   } n   sort(temp.begin(), temp.end(), comp); n   for (int i = 0; i < temp.size(); i++) { n     int f = temp[i].first; n     int s = temp[i].second; n     if (f == s) { n       cout << f <<     << s <<     << f <<   n ; n     } else { n       if (f == temp[i + 1].first) { n         cout << f <<     << s <<     << temp[i + 1].second + 1 <<   n ; n       } else if (s == temp[i + 1].second) { n         cout << f <<     << s <<     << temp[i + 1].first - 1 <<   n ; n       } n     } n   } n   cout <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long testcase; n   cin >> testcase; n   while (testcase--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   bool discount_flag = true; n   int num_of_session; n   cin >> num_of_session; n   vector<int> num_of_teams(200001); n   for (int i = 0; i < num_of_session; i++) cin >> num_of_teams[i]; n   for (int i = 0; i < num_of_session; i++) n     if (num_of_teams[i] % 2 == 1) n       if (i != num_of_session - 1 and num_of_teams[i + 1] > 0) { n         num_of_teams[i + 1] -= 1; n         num_of_teams[i] = 0; n       } else if (num_of_teams[i + 1] == 0) n         discount_flag = false; n       else if (i == num_of_session) n         discount_flag = false; n   if (discount_flag) 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 fact(vector<int> x, long long t) { n   if (t == 1) return 1; n   vector<long long> num(x.begin(), x.end()); n   stringstream s; n   string tmp; n   s << t; n   s >> tmp; n   int count = 0; n   for (int i = 0; i < num.size(); i++) { n     stringstream ss; n     string temp; n     ss << num[i]; n     ss >> temp; n     bool flag = false; n     for (int j = 0; j < temp.size(); j++) { n       for (int k = 0; k < tmp.size(); k++) n         if (temp[j] == tmp[k]) { n           count++; n           flag = true; n           break; n         } n       if (flag) break; n     } n   } n   return count; n } n int main() { n   long long n; n   cin >> n; n   long long t = n; n   vector<int> factors; n   long long i; n   factors.push_back(1); n   for (i = 2; i < sqrt(n); i++) { n     if (n % i == 0) { n       factors.push_back(n / i); n       factors.push_back(i); n     } n   } n   if (i * i == n) { n     factors.push_back(i); n   } n   factors.push_back(n); n   cout << fact(factors, t); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void optimise() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n } n long long int mod = 998244353; n long long int inf = 1e18 + 6; n void normalize(long long int &a) { a = (a + mod) % mod; } n long long int modmul(long long int a, long long int b) { n   a = a % mod; n   b = b % mod; n   normalize(a); n   normalize(b); n   return (a * b) % mod; n } n long long int modadd(long long int a, long long int b) { n   a = a % mod; n   b = b % mod; n   normalize(a); n   normalize(b); n   return (a + b) % mod; n } n long long int modsub(long long int a, long long int b) { n   a = a % mod; n   b = b % mod; n   normalize(a); n   normalize(b); n   return (a - b + mod) % mod; n } n long long int me(long long int x, long long int n) { n   x %= mod; n   if (n == 0) return 1; n   long long int u = me(x, n / 2) % mod; n   u = (u * u) % mod; n   if (n % 2) u = (u * x) % mod; n   return u; n } n long long int me1(long long int x, long long int n) { n   if (n == 0) return 1; n   long long int u = me1(x, n / 2); n   u = u * u; n   if (n % 2) u = u * x; n   return u; n } n inline long long int modInv(long long int a) { return me(a, mod - 2); } n inline long long int modDiv(long long int a, long long int b) { n   return modmul(a, modInv(b)); n } n long long int __gcd(long long int a, long long int b) { n   if (b == 0) n     return a; n   else n     return __gcd(b, a % b); n } n const long long int N = 1e6 + 1; n vector<long long int> G[N]; n void solve() { n   long long int n; n   cin >> n; n   long long int a[n + 1]; n   long long int sum[n + 1]; n   sum[0] = 0; n   for (long long int i = 1; i <= n; ++i) { n     cin >> a[i]; n     sum[i] = sum[i - 1] + a[i]; n   } n   map<long long int, vector<pair<long long int, long long int> > > m; n   for (long long int i = 1; i <= n; i++) { n     for (long long int j = 1; j + i - 1 <= n; j++) { n       long long int sum1 = sum[i + j - 1] - sum[j - 1]; n       m[sum1].push_back({j + i - 1, j}); n     } n   } n   long long int max1 = 0; n   long long int ans = -1; n   for (auto i = m.begin(); i != m.end(); i++) { n     sort(m[i->first].begin(), m[i->first].end()); n     long long int j1 = 0; n     long long int r = 0; n     long long int sum1 = i->first; n     for (auto j = m[sum1].begin(); j != m[sum1].end(); j++) { n       if (j->second > r) { n         j1++; n         r = j->first; n       } n     } n     if (j1 > max1) { n       ans = sum1; n       max1 = j1; n     } n   } n   cout << max1 <<   n ; n   long long int r = 0; n   for (auto k1 = m[ans].begin(); k1 != m[ans].end(); k1++) { n     if (k1->second > r) { n       cout << k1->second <<     << k1->first <<   n ; n       r = k1->first; n     } n   } n } n signed main() { n   optimise(); n   long long int t; n   t = 1; n   while (t--) { n     solve(); n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   long long int a[n + 2]; n   vector<long long int> pre(n + 2); n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   sort(a + 1, a + n + 1); n   for (int i = 1; i <= n; i++) { n     pre[i] = pre[i - 1] + a[i]; n   } n   int left = 1; n   int num = -1, occur = -1; n   for (int i = 1; i <= n; i++) { n     while ((a[i] * (i - left + 1) - (pre[i] - pre[left - 1])) > k) left++; n     if (occur < (i - left + 1)) { n       occur = i - left + 1; n       num = a[i]; n     } n   } n   cout << occur <<     << num << endl; n } n


#include <bits/stdc++.h> n int main() { n   int t, a, b, i, temp; n   scanf( %d , &t); n   for (i = 1; i <= t; i++) { n     scanf( %d %d , &a, &b); n     if (b > a) { n       temp = a; n       a = b; n       b = temp; n     } n     while ((a * a) < 2 * a * b) { n       a++; n     } n     printf( %d n , a * a); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long a[222222], b[222222], c[222222], d[222222]; n set<long long> st; n set<long long>::iterator it; n map<long long, long long> sp2; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n, m, k, x, s, i; n   cin >> n >> m >> k; n   cin >> x >> s; n   for (i = 1; i <= m; i++) { n     cin >> a[i]; n   } n   for (i = 1; i <= m; i++) { n     cin >> b[i]; n   } n   for (i = 1; i <= k; i++) { n     cin >> c[i]; n   } n   for (i = 1; i <= k; i++) { n     cin >> d[i]; n     st.insert(d[i]); n     sp2[d[i]] = c[i]; n   } n   long long ans = n * x; n   long long rem; n   long long temp; n   for (i = 1; i <= m; i++) { n     if (b[i] <= s) { n       temp = 0; n       rem = s - b[i]; n       it = st.upper_bound(rem); n       if (it != st.begin()) { n         it--; n         temp += sp2[*it]; n       } n       if (temp >= n) n         ans = 0; n       else n         ans = min(ans, (n - temp) * a[i]); n     } n   } n   temp = 0; n   it = st.upper_bound(s); n   if (it != st.begin()) { n     it--; n     temp += sp2[*it]; n   } n   if (temp >= n) n     ans = 0; n   else n     ans = min(ans, (n - temp) * x); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF32 = 0x3f3f3f3f; n const double EPS = 1.0e-8; n const double PI = acos(-1.0); n struct Point { n   double x, y; n   Point(double _x = 0, double _y = 0) { n     x = _x; n     y = _y; n   } n   friend Point operator+(const Point &a, const Point &b) { n     return Point(a.x + b.x, a.y + b.y); n   } n   friend Point operator-(const Point &a, const Point &b) { n     return Point(a.x - b.x, a.y - b.y); n   } n   friend double operator^(const Point &a, const Point &b) { n     return a.x * b.y - a.y * b.x; n   } n   friend bool operator==(const Point &a, const Point &b) { n     return fabs(a.x - b.x) < EPS && fabs(a.y - b.y) < EPS; n   } n }; n struct V { n   Point start, end; n   V(Point _start = Point(0, 0), Point _end = Point(0, 0)) { n     start = _start; n     end = _end; n   } n }; n Point Basic; n set<Point> Set; n double Distance(Point a, Point b) { n   return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); n } n bool operator<(Point a, Point b) { n   a = a - Basic; n   b = b - Basic; n   double Ang1 = atan2(a.y, a.x), Ang2 = atan2(b.y, b.x); n   double Len1 = Distance(a, Point(0.0, 0.0)), n          Len2 = Distance(b, Point(0.0, 0.0)); n   if (fabs(Ang1 - Ang2) < EPS) return Len1 < Len2; n   return Ang1 < Ang2; n } n set<Point>::iterator Pre(set<Point>::iterator it) { n   if (it == Set.begin()) it = Set.end(); n   return --it; n } n set<Point>::iterator Nxt(set<Point>::iterator it) { n   ++it; n   return it == Set.end() ? Set.begin() : it; n } n int Query(Point p) { n   set<Point>::iterator it = Set.lower_bound(p); n   if (it == Set.end()) it = Set.begin(); n   return ((p - *(Pre(it))) ^ (*(it) - *(Pre(it)))) < EPS; n } n void Insert(Point p) { n   if (Query(p)) return; n   Set.insert(p); n   set<Point>::iterator it = Nxt(Set.find(p)); n   while (Set.size() > 3 && ((p - *(Nxt(it))) ^ (*(it) - *(Nxt(it)))) < EPS) { n     Set.erase(it); n     it = Nxt(Set.find(p)); n   } n   it = Pre(Set.find(p)); n   while (Set.size() > 3 && ((p - *(it)) ^ (*(it) - *(Pre(it)))) > -EPS) { n     Set.erase(it); n     it = Pre(Set.find(p)); n   } n } n int main() { n   int q; n   scanf( %d , &q); n   Basic = Point(0, 0); n   int oper; n   Point a, str[5]; n   for (int i = 1; i <= 3; ++i) { n     scanf( %d%lf%lf , &oper, &str[i].x, &str[i].y); n     Basic = Basic + str[i]; n   } n   Basic.x /= 3.0; n   Basic.y /= 3.0; n   q -= 3; n   for (int i = 1; i <= 3; ++i) { n     Set.insert(str[i]); n   } n   while (q--) { n     scanf( %d%lf%lf , &oper, &a.x, &a.y); n     if (oper == 1) { n       Insert(a); n     } else { n       if (Query(a)) n         printf( YES n ); n       else n         printf( NO n ); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n; n vector<array<int, 2>> v, good; n long long f(int x, int y) { n   return abs(v[x][0] - v[y][0]) + abs(v[x][1] - v[y][1]); n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0); n   cin >> n; n   v.resize(n); n   long long ans = 0; n   for (int i = 0; i < n; i++) { n     cin >> v[i][0] >> v[i][1]; n   } n   int min_x = -1, max_x = -1, min_y = -1, max_y = -1; n   for (int i = 0; i < n; i++) { n     if (min_x == -1 || v[i][0] < v[min_x][0]) { n       min_x = i; n     } n     if (max_x == -1 || v[i][0] > v[max_x][0]) { n       max_x = i; n     } n     if (min_y == -1 || v[i][1] < v[min_y][1]) { n       min_y = i; n     } n     if (max_y == -1 || v[i][1] > v[max_y][1]) { n       max_y = i; n     } n     ans += f(i, (i + 1) % n); n   } n   if (n == 3) { n     return cout << ans, 0; n   } n   set<int> st; n   st.insert(min_x), st.insert(max_x), st.insert(min_y), st.insert(max_y); n   for (int i : st) good.push_back(v[i]); n   long long ans3 = 0; n   if ((int)(good).size() < 4) { n     ans3 = ans; n   } else { n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < 4; j++) { n         for (int k = j + 1; k < 4; k++) { n           long long cur = 0; n           cur += abs(good[j][0] - v[i][0]) + abs(good[j][1] - v[i][1]); n           cur += abs(good[j][0] - good[k][0]) + abs(good[j][1] - good[k][1]); n           cur += abs(good[k][0] - v[i][0]) + abs(good[k][1] - v[i][1]); n           ans3 = max(ans3, cur); n         } n       } n     } n   } n   cout << ans3 <<    ; n   for (int i = 4; i <= n; i++) { n     cout << ans <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long base = 7; n const long long maxn = 1e6 + 9; n const long long inf = 1e9 + 7; n queue<long long> l[30], r[30], l1, r1, lf, rf; n vector<pair<long long, long long> > res; n long long n, i; n string a, b; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> a >> b; n   a =     + a; n   b =     + b; n   for (i = 1; i <= n; i++) { n     if (a[i] !=  ? ) n       l[a[i] -  a ].push(i); n     else n       l1.push(i); n   } n   for (i = 1; i <= n; i++) { n     if (b[i] !=  ? ) n       r[b[i] -  a ].push(i); n     else n       r1.push(i); n   } n   for (i = 0; i <= 27; i++) { n     while (true) { n       if (!l[i].empty() && !r[i].empty()) { n         res.push_back(make_pair(l[i].front(), r[i].front())); n         l[i].pop(); n         r[i].pop(); n       } else { n         while (!l[i].empty()) { n           lf.push(l[i].front()); n           l[i].pop(); n         } n         while (!r[i].empty()) { n           rf.push(r[i].front()); n           r[i].pop(); n         } n         break; n       } n     } n   } n   while (true) { n     if (!lf.empty() && !r1.empty()) { n       res.push_back(make_pair(lf.front(), r1.front())); n       lf.pop(); n       r1.pop(); n     } else n       break; n   } n   while (true) { n     if (!rf.empty() && !l1.empty()) { n       res.push_back(make_pair(l1.front(), rf.front())); n       rf.pop(); n       l1.pop(); n     } else n       break; n   } n   while (true) { n     if (!r1.empty() && !l1.empty()) { n       res.push_back(make_pair(l1.front(), r1.front())); n       r1.pop(); n       l1.pop(); n     } else n       break; n   } n   cout << res.size() <<   n ; n   for (i = 0; i < res.size(); i++) n     cout << res[i].first <<     << res[i].second <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   cin.sync_with_stdio(false); n   int ans, cnt, k; n   string str; n   while (cin >> str >> k) { n     ans = 0; n     cnt = 0; n     int len = str.length(); n     for (int i = len - 1; i >= 0; i--) { n       if (str[i] ==  0 ) { n         ans++; n       } n     } n     if (ans < k) { n       cout << len - 1 << endl; n     } else { n       for (int i = len - 1; i >= 0; i--) { n         if (str[i] !=  0 ) { n           cnt++; n         } else { n           k--; n         } n         if (k == 0) { n           break; n         } n       } n       cout << cnt << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int b, d, ans, l, h; n char a[105], c[105]; n bool letter[30]; n int lena, lenc; n int ll[105], yy[105]; n char aa[105 * 105]; n inline int ok() { n   memset(letter, 0, sizeof(letter)); n   for (char *p = a; *p; ++p) letter[*p -  a ] = 1; n   for (char *p = c; *p; ++p) n     if (letter[*p -  a ] == 0) return 0; n   return 1; n } n inline int init() { n   for (int i = 0; i < 105; ++i) strcpy(aa + i * lena, a); n   for (int i = 0; i < lena; ++i) { n     char *p = aa + i, *q = c; n     while (*p && *q) { n       while (*p && *p != *q) ++p; n       if (*p != *q) return 0; n       ++p, ++q; n     } n     if (*q != 0) return 0; n     ll[i] = p - (aa + i); n     yy[i] = (p - aa) % lena; n   } n   return 1; n } n inline int test(int p) { n   p = p * d; n   long long pos = 0; n   long long vst[105], cnt[105]; n   memset(vst, -1, sizeof(vst)); n   for (int i = 0; i < p; ++i) { n     if (pos >= lena * b) return 0; n     if (vst[pos % lena] > -1) { n       long long tmp = pos - vst[pos % lena]; n       long long tem = i - cnt[pos % lena]; n       pos += tmp * ((p - i) / tem); n       i = (p - i) / tem * tem + i - 1; n       memset(vst, -1, sizeof(vst)); n       continue; n     } n     if (i) { n       vst[pos % lena] = pos; n       cnt[pos % lena] = i; n     } n     pos += ll[pos % lena]; n   } n   if (pos - 1 >= lena * b) return 0; n   return 1; n } n int main(int argc, char **argv) { n   scanf( %d%d , &b, &d); n   scanf( %s%s , a, c); n   lena = strlen(a), lenc = strlen(c); n   if (!ok() || !init()) n     puts( 0 ); n   else { n     ans = 0, l = 1, h = lena * b / (lenc * d); n     while (l <= h) { n       int mid = (l + h) >> 1; n       if (test(mid)) n         ans = mid, l = mid + 1; n       else n         h = mid - 1; n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include<bits/stdc++.h> n #define pb push_back n #define mk make_pair n #define ll long long n #define ss second n #define ff first n #define pll pair<ll,ll> n #define vll vector<ll> n #define mll map<ll,ll> n #define mod 1000000007 n #define w(x) ll x; cin>>x; while(x--) n #define ps(x,y) fixed<<setprecision(y)<<x; n #define fo(i, j, k, in) for (ll i=j ; i<k ; i+=in) n #define re(i, j) fo(i, 0, j, 1) n #define pi 3.1415926535897932384626433832795 n #define all(cont) cont.begin(), cont.end() n #define countbit(x) __builtin_popcount(x) n #define mod 1000000007 n #define lo lower_bound n #define de(n) ll n;cin>>n; n #define def(a,n) ll n;cin>>n;ll a[n];re(i,n){cin>>a[i];} n #define defi(a,n,k) ll n;cin>>n; ll k;cin>>k;ll a[n];re(i,n){cin>>a[i];} n #define deb(x) cout<<#x<< = <<x<<endl; n #define tr(it,a) for(auto it=a.begin();it!=a.end();it++) n #define nl cout<<endl; n  n using namespace std; n  n  n  n int main() n { n ios_base::sync_with_stdio(0); n cin.tie(0); n      n         int n; n         cin>>n; n         int x[2]={1,-1}; n  n         int y[2]={1,-1}; n         pair<int,int> p; n         p.first=0; n         p.second=0; n         int a1=n/2; n         int a2=n-n/2; n         if(n%2!=0){ n             int c=a2+1; n             int d=(a1+1); n             ll ans=1ll*2*(c*d); n             cout<<ans<<endl; n         } n         else{ n             int c=a2+1; n             int d=a1+1; n             ll ans=1ll*c*d; n             cout<<ans<<endl; n         } n        n  n          n  n          n          n  n      n  n  n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void __print(int x) { cerr << x; } n void __print(long x) { cerr << x; } n void __print(long long x) { cerr << x; } n void __print(unsigned x) { cerr << x; } n void __print(unsigned long x) { cerr << x; } n void __print(unsigned long long x) { cerr << x; } n void __print(float x) { cerr << x; } n void __print(double x) { cerr << x; } n void __print(long double x) { cerr << x; } n void __print(char x) { cerr <<      << x <<     ; } n void __print(const char *x) { cerr <<     << x <<    ; } n void __print(const string &x) { cerr <<     << x <<    ; } n void __print(bool x) { cerr << (x ?  true  :  false ); } n template <typename T, typename V> n void __print(const pair<T, V> &x) { n   cerr <<  { ; n   __print(x.first); n   cerr <<  , ; n   __print(x.second); n   cerr <<  } ; n } n template <typename T> n void __print(const T &x) { n   int f = 0; n   cerr <<  { ; n   for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i); n   cerr <<  } ; n } n void _print() { cerr <<  ] n ; } n template <typename T, typename... V> n void _print(T t, V... v) { n   __print(t); n   if (sizeof...(v)) cerr <<  ,  ; n   _print(v...); n } n inline long long int GCD(long long int x, long long int y) { n   if (x < y) swap(x, y); n   if (x == 0) return y; n   if (y == 0) return x; n   return GCD(x % y, y); n } n long long int phi(long long int n) { n   long long int result = n; n   for (long long int i = 2; i * i <= n; i++) { n     if (n % i == 0) { n       while (n % i == 0) n /= i; n       result -= result / i; n     } n   } n   if (n > 1) result -= result / n; n   return result; n } n long long int power(long long int x, long long int n, long long int mod) { n   long long int res = 1; n   x %= mod; n   while (n) { n     if (n & 1) { n       res = ((res * x) % mod + mod) % mod; n     } n     x = ((x * x) % mod + mod) % mod; n     n >>= 1; n   } n   return res; n } n long long int A[105][105]; n long long int row[105], col[105], fr[105] = {0}, fc[105] = {0}, cr = 0, cc = 0; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   long long int n, m; n   cin >> n >> m; n   for (long long int i = 1; i <= n; i++) { n     for (long long int j = 1; j <= m; j++) { n       cin >> A[i][j]; n       row[i] += A[i][j]; n       col[j] += A[i][j]; n     } n   } n   while (1) { n     bool f = true; n     for (long long int i = 1; i <= n; i++) { n       if (row[i] < 0) { n         f = false; n         fr[i] ^= 1; n         cr--; n         if (fr[i]) cr += 2; n         for (long long int j = 1; j <= m; j++) { n           row[i] -= (2 * A[i][j]); n           col[j] -= (2 * A[i][j]); n           A[i][j] = -A[i][j]; n         } n       } n     } n     for (long long int j = 1; j <= m; j++) { n       if (col[j] < 0) { n         f = false; n         fc[j] ^= 1; n         cc--; n         if (fc[j]) cc += 2; n         for (long long int i = 1; i <= n; i++) { n           row[i] -= (2 * A[i][j]); n           col[j] -= (2 * A[i][j]); n           A[i][j] = -A[i][j]; n         } n       } n     } n     if (f) break; n   } n   cout << cr <<    ; n   for (long long int i = 1; i <= n; i++) { n     if (fr[i]) cout << i <<    ; n   } n   cout << endl; n   cout << cc <<    ; n   for (long long int j = 1; j <= m; j++) { n     if (fc[j]) cout << j <<    ; n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100010; n const int MAXV = 100010; n const int MAXT = 333; n int a[MAXN], n; n int b[MAXN], m; n int s, e; n vector<int> ind[MAXV]; n int p[MAXN][MAXT]; n int main() { n   scanf( %d%d%d%d , &n, &m, &s, &e); n   for (int i = int(0); i <= int((MAXV)-1); ++i) ind[i].clear(); n   for (int i = int(1); i <= int(n); ++i) n     scanf( %d , a + i), ind[a[i]].push_back(i); n   for (int i = int(1); i <= int(m); ++i) scanf( %d , b + i); n   int mt = s / e; n   int ans = 0; n   for (int t = int(1); t <= int(mt); ++t) p[0][t] = n + 1; n   p[0][0] = 0; n   for (int j = int(1); j <= int(m); ++j) { n     for (int t = int(0); t <= int(mt); ++t) p[j][t] = p[j - 1][t]; n     for (int t = int(0); t <= int(mt - 1); ++t) { n       vector<int>::iterator it = n           lower_bound(ind[b[j]].begin(), ind[b[j]].end(), p[j - 1][t] + 1); n       if (it != ind[b[j]].end()) p[j][t + 1] = min(p[j][t + 1], *it); n     } n     for (int t = int(1); t <= int(mt); ++t) { n       int i = p[j][t]; n       if (i > n) break; n       int rest = s - (i + j); n       int cnt = rest / e; n       ans = max(ans, min(cnt, t)); n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int Tea; n   int Index; n   friend bool operator<(const node& a, const node& b) { return a.Tea > b.Tea; } n } D[105]; n int main() { n   int i, n, w, Ans[105]; n   scanf( %d%d , &n, &w); n   for (i = 0; i < n; i++) { n     scanf( %d , &D[i].Tea); n     D[i].Index = i; n   } n   sort(D, D + n); n   int Judge = 0; n   for (i = 0; i < n; i++) Judge += (D[i].Tea + 1) / 2; n   if (Judge > w) n     printf( -1 n ); n   else { n     w -= Judge; n     for (i = 0; i < n; i++) Ans[D[i].Index] = (D[i].Tea + 1) / 2; n     for (i = 0; i < n && w; i++) { n       if (w >= D[i].Tea - Ans[D[i].Index]) n         w -= D[i].Tea - Ans[D[i].Index], Ans[D[i].Index] = D[i].Tea; n       else n         Ans[D[i].Index] += w, w = 0; n     } n     for (i = 0; i < n; i++) { n       if (i) printf(   ); n       printf( %d , Ans[i]); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n, s, k = 0; n   scanf( %d %d , &n, &s); n   while (s > 0) { n     s -= n; n     k++; n   } n   printf( %d , k); n   return 0; n } n


#include <bits/stdc++.h> n  n using namespace std; n  n #define y1 temp_y1 n #define all(x) x.begin(), x.end() n  n const int N = 3e5 + 5; n  n int n; n  n int lst[N]; n int fa[N]; n  n vector<int> g[N]; n  n int min_leaf = -1; n int ext_cnt = 0; n bool ok = true; n  n void dfs1(int u, int k) { n   for (auto v : g[u]) { n     dfs1(v, k); n   } n   if (ext_cnt < k && lst[u] != ext_cnt) { n     ok = false; n   } n   if (ext_cnt == k) { n     min_leaf = u; n   } n   ++ext_cnt; n } n long long ans = 0; n int seq[N]; n int dfs_cnt = 0; n int siz[N]; n  n void dfs2(int u, int k, int dep) { n   seq[u] = dfs_cnt++; n   if (lst[u] < k) { n     ans += dep; n     siz[u]++; n   }  n   for (auto v : g[u]) { n     dfs2(v, k, dep + 1); n     siz[u] += siz[v]; n   } n   if (lst[u] < k && lst[u] != ext_cnt) { n     ok = false; n   } n   if (lst[u] >= k && siz[u] + seq[u] != lst[u]) { n     ok = false; n   } n   ++ext_cnt; n } n  n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   for (int i = 0; i < n; ++i) { n     cin >> lst[i]; n     --lst[i]; n   } n   for (int i = 0; i < n - 1; ++i) { n     int u, v; n     cin >> u >> v; n     --u; n     --v; n     fa[v] = u; n     g[u].push_back(v); n   } n   for (int i = 0; i < n; ++i) { n     sort(all(g[i]), [&](int x, int y) -> bool { n       return lst[x] < lst[y]; n     }); n   } n    n   if (lst[0] == 0) { n     dfs2(0, 0, 0); n     if (ok) { n       cout <<  YES  << endl; n       cout << 0 << endl; n       for (int i = 0; i < n; ++i) { n  cout << lst[i] + 1 <<    ; n       } n       cout << endl; n       return 0; n     } else { n       cout <<  NO  << endl; n       return 0; n     } n   } n   int v = lst[0] - 1; n   dfs1(0, v); n   int u = min_leaf; n   bool is_find = false; n   fa[0] = -1; n   //cerr << v + 1 <<     << u + 1 <<     << lst[u] + 1 <<endl; n   do { n     if (lst[u] == v) { n       is_find = true; n     } n     if (lst[u] == v && fa[u] != -1) { n       swap(lst[u], lst[fa[u]]); n       ++ans; n     } n     u = fa[u]; n   } while (u != -1); n   if (!is_find) { n     cout <<  NO  << endl; n     return 0; n   } n   ext_cnt = 0; n   dfs2(0, v, 0); n  n   if (ok) { n     cout <<  YES  << endl; n     cout << ans << endl; n     for (int i = 0; i < n; ++i) { n       cout << seq[i] + 1 <<     ; n     } n     cout << endl; n   } else { n     cout <<  NO  << endl; n   } n    n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n vector<pair<int, int>> flowers; n vector<int> first_flowers; n vector<long long> pref_sum; n long long answer; n void In() { n   flowers.clear(); n   pref_sum.clear(); n   first_flowers.clear(); n   answer = LLONG_MIN; n   cin >> n >> m; n   flowers.resize(m); n   for (int i = 0; i < m; i++) cin >> flowers[i].first >> flowers[i].second; n } n long long GetPrefSum(int start_index) { n   return pref_sum.back() - n          ((start_index - 1 >= 0) ? pref_sum[start_index - 1] : 0); n } n void Try(int index) { n   auto range = equal_range(first_flowers.begin(), first_flowers.end(), n                            flowers[index].second); n   int less_or_equal = range.second - first_flowers.begin(); n   int remaining = m - less_or_equal; n   remaining = min(remaining, n); n   int start_index = m - remaining; n   if (index >= start_index) { n     long long result = GetPrefSum(start_index); n     long long left_take = n - remaining; n     result += left_take * flowers[index].second; n     answer = max(answer, result); n   } else { n     long long result = flowers[index].first; n     int really_remaining = m - less_or_equal; n     really_remaining = min(really_remaining, n - 1); n     start_index = m - really_remaining; n     result += GetPrefSum(start_index); n     long long left_take = n - 1 - really_remaining; n     result += left_take * flowers[index].second; n     answer = max(answer, result); n   } n } n void Solve() { n   sort(flowers.begin(), flowers.end()); n   pref_sum.resize(m); n   pref_sum[0] = flowers[0].first; n   for (int i = 1; i < m; i++) pref_sum[i] = flowers[i].first + pref_sum[i - 1]; n   first_flowers.resize(m); n   for (int i = 0; i < m; i++) first_flowers[i] = flowers[i].first; n   for (int i = 0; i < m; i++) Try(i); n } n void Out() { cout << answer <<   n ; } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t = 1; n   cin >> t; n   while (t--) { n     In(); n     Solve(); n     Out(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int digit(long long int n) { n   if (n > 0) return (digit(n / 10) + 1); n   return 0; n } n int main() { n   long long int l, h; n   long long int a[] = {0,      4,       49,       499,       4999,      49999, n                        499999, 4999999, 49999999, 499999999, 4999999999}; n   long long int b[] = {0,      9,       99,       999,       9999,      99999, n                        999999, 9999999, 99999999, 999999999, 9999999999}; n   cin >> l >> h; n   long long int ans = max(a[digit(l)], l); n   ans = min(a[digit(h)], h); n   ans = max(ans, l); n   ans = (long long int)(ans) * (b[digit(ans)] - ans); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mo = 1e9 + 7; n int main() { n   long long a, b, n; n   while (cin >> a >> b) { n     n = b - 1; n     long long ans = 0; n     for (int k = 1; k <= a; ++k) { n       ans = (ans + (((((k * b) % mo) * ((n * (n + 1) / 2) % mo)) % mo + n                      (n * (n + 1) / 2) % mo)) % n                        mo) % n             mo; n     } n     cout << ans % mo << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline T BM(T p, T e, T M) { n   long long int ret = 1; n   for (; e > 0; e >>= 1) { n     if (e & 1) ret = (ret * p) % M; n     p = (p * p) % M; n   } n   return (T)ret; n } n template <class T> n inline T gcd(T a, T b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n template <class T> n inline T MDINV(T a, T M) { n   return BM(a, M - 2, M); n } n template <class T> n inline T PW(T p, T e) { n   long long int ret = 1; n   for (; e > 0; e >>= 1) { n     if (e & 1) ret = (ret * p); n     p = (p * p); n   } n   return (T)ret; n } n template <class T> n string NTS(T Number) { n   stringstream ss; n   ss << Number; n   return ss.str(); n } n template <class T> n T stringtonumber(const string &Text) { n   istringstream ss(Text); n   T result; n   return ss >> result ? result : 0; n } n template <class T> n bool ISLEFT(T a, T b, T c) { n   if (((a.first - b.first) * (b.second - c.second) - n        (b.first - c.first) * (a.second - b.second)) < 0.0) n     return 1; n   else n     return 0; n } n char a[10009]; n int z[10009]; n char ch[5000 + 2]; n int ar[5000 + 2][5000 + 2]; n int res[5000 + 2][5000 + 2]; n void zalgo() { n   int l, r; n   l = r = 0; n   z[0] = strlen(a); n   for (int i = 1; i < z[0]; i++) { n     if (i > r) { n       l = r = i; n       for (int j = i; j < z[0]; j++) { n         if (a[j - i] != a[j]) n           break; n         else n           r = j; n       } n       if (a[i] != a[0]) n         z[i] = 0; n       else n         z[i] = r - l + 1; n     } else { n       int k = i - l; n       if (z[k] < r - i + 1) { n         z[i] = z[k]; n       } else { n         l = i; n         for (int j = r + 1; j < z[0]; j++) { n           if (a[j - l] != a[j]) n             break; n           else n             r = j; n         } n         z[i] = r - l + 1; n       } n     } n   } n } n int dp[5009][5009]; n void update(int x1, int y1, int val) { n   while (y1 <= 5002) { n     dp[x1][y1] = (dp[x1][y1] + val) % 1000000007; n     y1 += (y1 & -y1); n   } n } n int query(int x1, int y1) { n   int sum1 = 0; n   while (y1 > 0) { n     sum1 = (sum1 + dp[x1][y1]) % 1000000007; n     y1 -= (y1 & -y1); n   } n   return sum1; n } n int main() { n   int n; n   scanf( %d , &n); n   scanf( %s , ch + 1); n   for (int i = 1; i <= n; i++) { n     int sz = 0; n     for (int j = i; j <= n; j++) { n       a[sz++] = ch[j]; n     } n     int len = sz; n     for (int j = i + 1; j <= n; j++) { n       a[sz++] = ch[j]; n     } n     a[sz] =   0 ; n     zalgo(); n     for (int j = i + 1; j <= n; j++) { n       ar[i][j] = z[len + (j - i - 1)]; n     } n   } n   res[0][0] = 1; n   for (int i = 1; i <= n; i++) { n     if (ch[i] ==  0 ) continue; n     for (int j = i; j <= n; j++) { n       if (i == 1) n         res[i][j] = 1; n       else { n         int ga = j - i; n         int x = i - 1 - ga; n         int y = i - 1; n         x = max(1, x); n         if (y - x == ga) { n           int in = x; n           int mil = ar[x][i]; n           if (mil < (ga + 1)) { n             if (ch[x + mil] < ch[i + mil]) { n               in = x - 1; n             } n           } n           int sum = query(y, y) - query(y, in); n           if (sum < 0) sum += 1000000007; n           res[i][j] = sum; n         } else { n           int sum = query(y, y) - query(y, x - 1); n           if (sum < 0) sum += 1000000007; n           res[i][j] = sum; n         } n       } n       update(j, i, res[i][j]); n     } n   } n   int su = 0; n   for (int i = 1; i <= n; i++) { n     su = (su + res[i][n]) % 1000000007; n   } n   printf( %d n , su); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 110; n int main() { n   cin.tie(0); n   cout.tie(0); n   ios::sync_with_stdio(false); n   int al, ar, bl, br; n   cin >> al >> ar >> bl >> br; n   if ((al * 2 + 3 > br && br >= al - 1) || (ar * 2 + 3 > bl && bl >= ar - 1)) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int c = 0; n void bfs(map<long long int, vector<long long int> > &map, vector<bool> &visited, n          long long int x) { n   queue<long long int> q; n   q.push(x); n   visited[x] = true; n   while (!q.empty()) { n     long long int y = q.front(); n     q.pop(); n     for (long long int i : map[y]) { n       if (!visited[i]) { n         q.push(i); n         visited[i] = true; n       } n     } n   } n } n int main() { n   long long int x, y, n, m; n   cin >> n >> m; n   map<long long int, vector<long long int> > map; n   std::vector<bool> visited(n + 1, false), visitedf(n + 1, false); n   for (long long int i = 0; i < m; i++) { n     cin >> x >> y; n     map[x].push_back(y); n     map[y].push_back(x); n   } n   if (m != n - 1) { n     cout <<  no ; n     return 0; n   } n   bfs(map, visited, map.begin()->first); n   for (long long int i = 1; i <= n; i++) { n     if (!visited[i]) { n       cout <<  no ; n       return 0; n     } n   } n   cout <<  yes ; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n const int N = (int)2e5 + 100; n const int M = (int)2e6 + 100; n const int inf = (int)1e9 + 100; n int a[N]; n int b[N]; n int t[4 * N]; n map<int, int> m[4 * N]; n void add(int x, int L, int R, int pos, int val) { n   t[x] = min(t[x], val); n   m[x][val]++; n   if (R - L == 1) { n     return; n   } n   int c = (L + R) >> 1; n   if (c > pos) { n     add(2 * x + 1, L, c, pos, val); n   } else { n     add(2 * x + 2, c, R, pos, val); n   } n } n int sum(int x, int L, int R, int l, int r) { n   if (R == r && L == l) { n     return t[x]; n   } n   int c = (L + R) >> 1; n   int o = inf; n   if (c > l) { n     o = sum(2 * x + 1, L, c, l, min(c, r)); n   } n   if (c < r) { n     o = min(o, sum(2 * x + 2, c, R, max(l, c), r)); n   } n   return o; n } n int del(int x, int L, int R, int l, int r, int val) { n   if (R - L == 1) { n     m[x][val]--; n     if (!m[x][val]) m[x].erase(val); n     if (m[x].size()) n       t[x] = m[x].begin()->first; n     else n       t[x] = inf; n     return L; n   } n   int c = (L + R) >> 1; n   int o = -1; n   m[x][val]--; n   if (!m[x][val]) m[x].erase(val); n   if (c > l && m[2 * x + 1].count(val)) { n     o = del(2 * x + 1, L, c, l, min(c, r), val); n   } n   if (c < r && m[2 * x + 2].count(val) && o == -1) { n     o = del(2 * x + 2, c, R, max(l, c), r, val); n   } n   t[x] = min(t[2 * x + 1], t[2 * x + 2]); n   return o; n } n void print(int x, int L, int R) { n   cout << x <<     << L <<     << R <<  :  << t[x] <<   n ; n   for (auto j : m[x]) { n     cout << j.first <<     << j.second <<   n ; n   } n   cout <<   n ; n   if (R - L == 1) return; n   int c = (L + R) >> 1; n   print(2 * x + 1, L, c); n   print(2 * x + 2, c, R); n } n int main() { n   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n   srand(time(0)); n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, M, i; n   cin >> n >> M; n   vector<int> v; n   for ((i) = 0; (i) < (n); (i)++) { n     cin >> a[i]; n     v.push_back(a[i]); n   } n   for ((i) = 0; (i) < (4 * N); (i)++) { n     t[i] = inf; n   } n   for ((i) = 0; (i) < (M); (i)++) { n     cin >> b[i]; n     v.push_back(b[i]); n   } n   sort((v).begin(), (v).end()), n       v.resize(unique((v).begin(), (v).end()) - v.begin()); n   map<int, int> m; n   for ((i) = 0; (i) < (v.size()); (i)++) { n     m[v[i]] = i; n   } n   int R = v.size(); n   for ((i) = 0; (i) < (M); (i)++) { n     int p; n     cin >> p; n     add(0, 0, R, m[b[i]], p); n   } n   int ma = 0; n   vector<pair<int, long long> > g; n   for ((i) = n - 1; (i) >= 0; (i)--) { n     if (a[i] > ma) { n       ma = a[i]; n       g.push_back({i, a[i]}); n     } else { n       g[g.size() - 1].second += a[i]; n     } n   } n   int ans = 0; n   for ((i) = 0; (i) < (g.size()); (i)++) { n     int x = sum(0, 0, R, 0, m[a[g[i].first]] + 1); n     int y; n     while (x != inf && x <= g[i].second) { n       y = del(0, 0, R, 0, m[a[g[i].first]] + 1, x); n       ans++; n       g[i].second -= x; n       x = sum(0, 0, R, 0, m[a[g[i].first]] + 1); n     } n     if (x != inf) { n       y = del(0, 0, R, 0, m[a[g[i].first]] + 1, x); n       add(0, 0, R, y, x - g[i].second); n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n bool custom(pair<int, int> a, pair<int, int> b) { n   if (a.first == b.first) { n     return a.second < b.second; n   } n   return a.first < b.first; n } n bool c1(string a) { n   int dec = 0; n   for (int i = 0; i < a.size() - 1; i++) { n     if (a[i] >= a[i + 1]) { n       dec += (a[i] > a[i + 1]); n     } else { n       dec = 0; n     } n     if (dec == 2) { n       return true; n     } n   } n   return false; n } n bool c2(string b) { n   char ant = b[0]; n   for (auto& first : b) { n     if (ant > first) { n       return true; n     } n     ant = first; n   } n   return false; n } n int main() { n   int k; n   cin >> k; n   int i = 1; n   string first = to_string(i); n   while (k > first.size()) { n     k -= first.size(); n     i++; n     first = to_string(i); n   } n   int c = 0; n   char an = first[0]; n   while (k > 0) { n     an = first[c]; n     c++; n     k--; n   } n   cout << an; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a, b; n vector<vector<int> > adj; n vector<int> col; n queue<int> x, y; n void colorear(int u, int c) { n   col[u] = c; n   for (int v : adj[u]) n     if (col[v] == -1) colorear(v, 1 - c); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   adj = vector<vector<int> >(2 * n + 2); n   for (int i = 0; i < n; i++) { n     cin >> a >> b; n     adj[a].push_back(b); n     adj[b].push_back(a); n     x.push(a); n     y.push(b); n     if (a % 2) { n       adj[a].push_back(a + 1); n       adj[a + 1].push_back(a); n     } n     if (b % 2) { n       adj[b].push_back(b + 1); n       adj[b + 1].push_back(b); n     } n   } n   col = vector<int>(2 * n + 2, -1); n   for (int i = 1; i <= 2 * n; i++) { n     if (col[i] == -1) { n       colorear(i, 0); n     } n   } n   while (n--) { n     cout << col[x.front()] + 1 <<     << col[y.front()] + 1 <<   n ; n     x.pop(); n     y.pop(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n pair<int, int> a[100000]; n int main() { n   int n, k; n   cin >> n >> k; n   for (int i = 0; i < n; i++) { n     int go; n     cin >> go; n     a[i].first = go; n     a[i].second = i; n   } n   sort(a, a + n); n   int an = 0; n   for (int i = 0; i < n; i++) { n     k -= a[i].first; n     if (k < 0) break; n     an++; n   } n   cout << an << endl; n   for (int i = 0; i < an; i++) { n     cout << a[i].second + 1 <<    ; n   } n   cout << endl; n   return 0; n } n