#include <bits/stdc++.h> n using namespace std; n int n, m, cnt[10], sta[10], g[10][10], f[10][10], pru[10], deg[10], tag[10]; n char s[10]; n int cal(int x) { n   int res = 0; n   while (x) { n     res++; n     x /= 10; n   } n   return res; n } n int read() { n   scanf( %s , s); n   int res = 0; n   for (int i = 0; s[i]; i++) res++; n   return res; n } n bool hall() { n   for (int i = 1; i <= m; i++) n     for (int j = i; j <= m; j++) f[i][j] = g[i][j]; n   for (int i = 1; i <= m; i++) deg[i] = 1; n   for (int i = 1; i <= m - 2; i++) deg[pru[i]]++; n   for (int i = 1; i <= m - 2; i++) { n     bool ok = 0; n     for (int j = 1; j <= m; j++) { n       if (deg[j] == 1) { n         ok = 1; n         deg[pru[i]]--; n         deg[j]--; n         if (f[min(pru[i], j)][max(pru[i], j)] == 0) return 0; n         f[min(pru[i], j)][max(pru[i], j)]--; n         break; n       } n     } n     if (!ok) return 0; n   } n   int x, y; n   for (int i = 1; i <= m; i++) { n     if (deg[i] == 1) { n       x = i; n       break; n     } n   } n   for (int i = 1; i <= m; i++) { n     if (deg[i] == 1) y = i; n   } n   if (f[x][y] == 0) return 0; n   f[x][y]--; n   int tmp; n   for (int i = 1; i < 1 << m; i++) { n     tmp = 0; n     for (int j = 0; j < m; j++) n       if (i & (1 << j)) tmp += cnt[j + 1] - 1; n     for (int j = 0; j < m; j++) n       for (int k = j; k < m; k++) n         if (((1 << j) & i) || (i & (1 << k))) tmp -= f[j + 1][k + 1]; n     if (tmp > 0) return 0; n   } n   return 1; n } n bool hall_() { n   int tmp; n   for (int i = 1; i < 1 << m; i++) { n     tmp = 0; n     for (int j = 0; j < m; j++) n       if (i & (1 << j)) tmp += cnt[j + 1]; n     for (int j = 0; j < m; j++) n       for (int k = j; k < m; k++) n         if (((1 << j) & i) || (i & (1 << k))) tmp -= g[j + 1][k + 1]; n     if (tmp > 0) return 0; n   } n   return 1; n } n void print() { n   for (int i = 1; i <= m; i++) deg[i] = 1; n   for (int i = 1; i <= m - 2; i++) deg[pru[i]]++; n   for (int i = 1; i <= m - 2; i++) { n     for (int j = 1; j <= m; j++) { n       if (deg[j] == 1) { n         deg[pru[i]]--; n         deg[j]--; n         g[min(pru[i], j)][max(pru[i], j)]--; n         printf( %d %d n , sta[pru[i]], sta[j]); n         break; n       } n     } n   } n   int x, y; n   for (int i = 1; i <= m; i++) { n     if (deg[i] == 1) { n       x = i; n       break; n     } n   } n   for (int i = 1; i <= m; i++) { n     if (deg[i] == 1) y = i; n   } n   g[x][y]--; n   printf( %d %d n , sta[x], sta[y]); n   n -= m; n   for (int i = 1; i <= m; i++) tag[i] = sta[i], sta[i]--, cnt[i]--; n   for (int i = 1; i <= m; i++) { n     while (cnt[i] != 0) { n       for (int j = 1; j <= m; j++) { n         if (g[min(i, j)][max(i, j)]) { n           g[min(i, j)][max(i, j)]--; n           cnt[i]--; n           if (hall_()) { n             printf( %d %d n , sta[i], tag[j]); n             sta[i]--; n             break; n           } n           cnt[i]++; n           g[min(i, j)][max(i, j)]++; n         } n       } n     } n   } n } n void dfs(int x) { n   if (x == m - 2 + 1) { n     if (hall()) { n       print(); n       exit(0); n     } n     return; n   } n   for (int i = 1; i <= m; i++) { n     pru[x] = i; n     dfs(x + 1); n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i < n; i++) { n     int x = read(), y = read(); n     if (x > y) swap(x, y); n     g[x][y]++; n   } n   for (int i = 1; i <= n; i++) { n     m = cal(i); n     cnt[m]++; n     sta[m] = i; n   } n   if (m == 1) { n     for (int i = 1; i < n; i++) printf( %d %d n , i, n); n     return 0; n   } n   dfs(1); n   puts( -1 ); n } n


#include <bits/stdc++.h> n using namespace std; n const int MaxN = 2000005; n int n, t; n long long sum[MaxN]; n int nums[MaxN]; n int main() { n   scanf( %d , &n); n   t = 0; n   for (int i = 1; i <= n; ++i) { n     long long ns; n     scanf( %lld , &ns); n     int nn = 1; n     while (t && ns * nums[t] <= sum[t] * nn) { n       ns += sum[t]; n       nn += nums[t]; n       --t; n     } n     nums[++t] = nn; n     sum[t] = ns; n   } n   for (int i = 1; i <= t; ++i) { n     double val = (double)sum[i] / nums[i]; n     for (int j = 1; j <= nums[i]; ++j) printf( %.10lf n , val); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n int q, a, b, c; n vector<array<int, 3>> v; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   for (int a = 1; a <= 10e4; ++a) { n     for (int b = a; b <= 10e4; b += a) { n       for (int c = b; c <= 10e4; c += b) v.push_back({a, b, c}); n     } n   } n   cin >> q; n   while (q--) { n     cin >> a >> b >> c; n     array<int, 4> ans = {30000, 0, 0, 0}; n     for (auto x : v) { n       int ma = abs(a - x[0]) + abs(b - x[1]) + abs(c - x[2]); n       if (ma < ans[0]) ans = {ma, x[0], x[1], x[2]}; n     } n     cout << ans[0] <<   n  << ans[1] <<     << ans[2] <<     << ans[3] <<   n ; n   } n } n


#include <bits/stdc++.h> n const int N = 3200; n using namespace std; n int n, l; n int a[N][3], b[N][3]; n int dp[N][105][3]; n void add(int &a, int &b) { n   a += b; n   if (a >= 1000000007) a -= 1000000007; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n >> l; n   for (int i = 1; i <= n; i++) { n     cin >> a[i][0] >> b[i][0]; n     a[i][1] = b[i][0]; n     b[i][1] = a[i][0]; n   } n   for (int i = 1; i <= n; i++) { n     dp[a[i][0]][i][0] += 1; n     if (a[i][0] != b[i][0]) dp[b[i][0]][i][1] += 1; n   } n   for (int i = 1; i <= l; i++) { n     for (int cur = 1; cur <= n; cur++) { n       for (int rot1 = 0; rot1 <= 1; rot1++) { n         for (int to = 1; to <= n; to++) { n           if (to != cur) n             for (int rot2 = 0; rot2 <= 1; rot2++) { n               if (a[to][0] == b[to][0] && rot2 == 1) continue; n               if (b[cur][rot1] == a[to][rot2]) n                 add(dp[i + a[to][rot2]][to][rot2], dp[i][cur][rot1]); n             } n         } n       } n     } n   } n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j <= 1; j++) { n       add(ans, dp[l][i][j]); n     } n   } n   cout << ans << endl; n   cin.get(); n   cin.get(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 3e3 + 3; n int p[MAX], cycle[MAX], nocycles, n, m; n void dfs(int v) { n   cycle[v] = nocycles; n   if (cycle[p[v]] == 0) dfs(p[v]); n } n void gen() { n   nocycles = 1; n   memset(cycle, 0, sizeof cycle); n   for (int i = 1; i < n + 1; i++) n     if (not cycle[i]) dfs(i), nocycles++; n } n vector<pair<int, int> > ans; n int main() { n   scanf( %d , &n); n   for (int i = 1; i < n + 1; i++) { n     scanf( %d , p + i); n   } n   cin >> m; n   gen(); n   int cur = n - nocycles + 1; n   if (cur < m) { n     int idx = 2; n     while (cur != m) { n       int comp = cycle[p[idx]]; n       if (comp == cycle[p[1]]) { n         idx++; n         continue; n       } n       ans.push_back(pair<int, int>(1, idx)); n       for (int i = idx; i < n + 1; i++) n         if (cycle[i] == comp) cycle[i] = cycle[p[1]]; n       cur++, idx++; n     } n   } else if (cur > m) { n     int idx = 1, loop = 1; n     while (cur != m) { n       if (p[idx] == idx) { n         idx++; n         continue; n       } n       for (int i = idx + 1; i < n + 1; i++) n         if (cycle[p[i]] == cycle[p[idx]]) { n           ans.push_back(pair<int, int>(idx, i)); n           swap(p[idx], p[i]); n           break; n         } n       cur--; n       gen(); n       loop++; n       assert(loop <= n + 10); n     } n   } n   cout << ans.size() << endl; n   for (int i = 0; i < ans.size(); i++) { n     printf( %d %d  , ans[i].first, ans[i].second); n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long fuck = 4e17; n long long n, arr[100010]; n vector<long long> ans; n bool chk(long long x) { n   vector<int> diffs; n   for (int i = 0; i + 1 < n; i++) { n     long long next = arr[i + 1]; n     if (arr[i] <= x) next = min(arr[i + 1], x); n     long long d = next - arr[i]; n     if (diffs.size() == 0) n       diffs.push_back(d); n     else if (diffs[0] != d) n       return false; n   } n   return true; n } n int main() { n   scanf( %lld , &n); n   for (int i = 0; i < n; i++) scanf( %lld , &arr[i]); n   sort(arr, arr + n); n   if (n == 1) { n     printf( -1 ); n     return 0; n   } n   if (n == 2) { n     long long d = arr[1] - arr[0]; n     ans.push_back(arr[0] - d); n     ans.push_back(arr[1] + d); n     if (!(d & 1)) ans.push_back(arr[1] - d / 2); n   } else { n     long long prev = arr[1] - arr[0], another = fuck, pos; n     for (int i = 2; i < n; i++) { n       long long d = arr[i] - arr[i - 1]; n       if (d != prev && d != another && another != fuck) { n         printf( 0 ); n         return 0; n       } n       if (d != prev) { n         pos = i; n         another = arr[i] - arr[i - 1]; n       } n     } n     if (another == fuck) { n       ans.push_back(arr[0] - prev); n       ans.push_back(arr[n - 1] + prev); n     } else { n       if (prev == 2ll * another) n         ans.push_back(arr[1] - another); n       else if (another == prev * 2ll) n         ans.push_back(arr[pos] - prev); n     } n   } n   set<long long> res; n   for (int i = 0; i < ans.size(); i++) n     if (chk(ans[i])) res.insert(ans[i]); n   printf( %d n , res.size()); n   for (set<long long>::iterator it = res.begin(); it != res.end(); it++) n     printf( %lld  , *it); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int SEED = chrono::steady_clock::now().time_since_epoch().count(); n mt19937 rng(SEED); n const int B = 3000; n struct Query { n   int l, r, t, idx, bl, br; n   Query(int l, int r, int t, int idx) n       : l(l), r(r), t(t), idx(idx), bl(l / B), br(r / B) {} n   bool operator<(const Query &q) const { n     return tuple<int, int, int>(bl, br, t) < n            tuple<int, int, int>(q.bl, q.br, q.t); n   } n }; n const int MAX = 100005; n int cnt[MAX], v[MAX], ocur[2 * MAX]; n vector<pair<int, int> > updateForward, updateBackward; n void add(int pos) { n   int x = v[pos]; n   cnt[ocur[x]]--; n   cnt[++ocur[x]]++; n } n void remove(int pos) { n   int x = v[pos]; n   cnt[ocur[x]]--; n   cnt[--ocur[x]]++; n } n void applyUpdate(pair<int, int> upd, int l, int r) { n   auto [pos, val] = upd; n   if (l <= pos && pos <= r) remove(pos); n   v[pos] = val; n   if (l <= pos && pos <= r) add(pos); n } n int getAns() { n   int res = 0; n   while (cnt[res]) res++; n   return res; n } n vector<int> MO(vector<Query> queries) { n   cnt[0] = 0x3f3f3f3f; n   int l = 0, r = -1, t = 0; n   vector<int> ans(queries.size()); n   sort(queries.begin(), queries.end()); n   for (auto q : queries) { n     while (t < q.t) applyUpdate(updateForward[t++], l, r); n     while (q.t < t) applyUpdate(updateBackward[--t], l, r); n     while (q.l < l) add(--l); n     while (r < q.r) add(++r); n     while (l < q.l) remove(l++); n     while (q.r < r) remove(r--); n     ans[q.idx] = getAns(); n   } n   return ans; n } n void create_queries(vector<pair<int, int> > updates) { n   int n = updates.size(); n   for (int i = 0; i < n; i++) { n     auto [pos, val] = updates[i]; n     updateForward.emplace_back(pos, val); n     updateBackward.emplace_back(pos, v[pos]); n     v[pos] = val; n   } n   for (int i = n - 1; i >= 0; i--) { n     auto [pos, val] = updateBackward[i]; n     v[pos] = val; n   } n } n map<int, int> mp; n int compress(int x) { n   if (!mp.count(x)) mp[x] = mp.size(); n   return mp[x]; n } n void test_case() { n   int n, q, type, l, r, x; n   cin >> n >> q; n   for (int i = 0; i < n; i++) { n     cin >> x; n     v[i] = compress(x); n   } n   vector<pair<int, int> > updates; n   vector<Query> queries; n   for (int i = 0; i < q; i++) { n     cin >> type >> l >> r; n     if (type == 1) n       queries.emplace_back(l - 1, r - 1, updates.size(), queries.size()); n     if (type == 2) updates.emplace_back(l - 1, compress(r)); n   } n   create_queries(updates); n   vector<int> res = MO(queries); n   for (auto x : res) cout << x << endl; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int t = 1; n   for (int i = 1; i <= t; i++) { n     test_case(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n const int INF = 1000000001; n const long long LINF = 1000000000000000001LL; n struct ITree { n   vector<vector<long long>> T; n   int p = 1; n   int par(int x) { return (x - 1) / 2; } n   ITree(vector<long long> &E) { n     int n = (int)(E).size(); n     while (p < n) p *= 2; n     T.resize(2 * p - 1); n     for (int i = (0); i <= (n - 1); ++i) { n       int v = i + p - 1; n       T[v].push_back(E[i]); n       while (v) { n         v = par(v); n         T[v].push_back(E[i]); n       } n     } n     for (int i = (0); i <= ((int)(T).size() - 1); ++i) n       sort(T[i].begin(), T[i].end()); n   } n   int Count(int v, long long valL, long long valR) { n     return upper_bound(T[v].begin(), T[v].end(), valR) - n            lower_bound(T[v].begin(), T[v].end(), valL); n   } n   int Query(int l, int r, long long valL, long long valR) { n     if (l > r) return 0; n     l += p - 1; n     r += p - 1; n     int ans = Count(l, valL, valR); n     if (l < r) ans += Count(r, valL, valR); n     while (par(l) != par(r)) { n       if (l % 2 == 1) ans += Count(l + 1, valL, valR); n       if (r % 2 == 0) ans += Count(r - 1, valL, valR); n       l = par(l); n       r = par(r); n     } n     return ans; n   } n }; n void dfs(int v, vector<vector<pair<int, int>>> &g, vector<long long> &depth, n          vector<int> &in, vector<int> &out, int &t) { n   in[v] = ++t; n   for (auto &e : g[v]) { n     int u = e.first, len = e.second; n     depth[u] = depth[v] + len; n     dfs(u, g, depth, in, out, t); n   } n   out[v] = t; n } n vector<int> solve(int n, vector<int> &a, vector<vector<pair<int, int>>> &g) { n   vector<long long> depth(n, 0); n   vector<int> in(n), out(n); n   int t = -1; n   dfs(0, g, depth, in, out, t); n   vector<long long> value(n); n   for (int i = (0); i <= (n - 1); ++i) { n     value[in[i]] = depth[i] - a[i]; n   } n   ITree tree(value); n   vector<int> ans(n); n   for (int i = (0); i <= (n - 1); ++i) { n     ans[i] = tree.Query(in[i] + 1, out[i], -LINF, depth[i]); n   } n   return ans; n } n int main() { n   ios_base::sync_with_stdio(0); n   int n; n   cin >> n; n   vector<int> a(n); n   for (int i = (0); i <= (n - 1); ++i) { n     cin >> a[i]; n   } n   vector<vector<pair<int, int>>> g(n); n   for (int i = (1); i <= (n - 1); ++i) { n     int p, len; n     cin >> p >> len; n     p--; n     g[p].push_back({i, len}); n   } n   vector<int> ans = solve(n, a, g); n   for (int i = (0); i <= (n - 1); ++i) { n     cout << ans[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename S, typename T> n ostream& operator<<(ostream& out, pair<S, T> const& p) { n   out <<  (  << p.first <<  ,   << p.second <<  ) ; n   return out; n } n template <typename T> n ostream& operator<<(ostream& out, vector<T> const& v) { n   long long l = v.size(); n   for (long long i = 0; i < l - 1; i++) out << v[i] <<    ; n   if (l > 0) out << v[l - 1]; n   return out; n } n template <typename T> n void trace(const char* name, T&& arg1) { n   cout << name <<   :   << arg1 <<   n ; n } n template <typename T, typename... Args> n void trace(const char* names, T&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cout.write(names, comma - names) <<   :   << arg1 <<   |  ; n   trace(comma + 1, args...); n } n int n, m; n int a[200], b[200]; n vector<int> ans; n bool check(int no) { n   for (int i = 0; i < n; i++) { n     if (a[i] <= no and b[i] >= no) { n       return true; n     } n   } n   return false; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     cin >> a[i] >> b[i]; n   } n   int c = 0; n   for (int i = 1; i <= m; i++) { n     if (check(i) == false) { n       c++; n       ans.push_back(i); n     } n   } n   cout << c <<   n ; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n class trip { n  public: n   long long first; n   long long second; n   long long third; n   trip() {} n }; n bool comp1(trip a, trip b) { n   if (a.first == b.first) { n     if (a.second == b.second) { n       return a.third < b.third; n     } n     return a.second < b.second; n   } n   return a.first < b.first; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t; n   t = 1; n   while (t--) { n     long long n; n     cin >> n; n     vector<trip> v; n     for (int i = 0; i < n; i++) { n       trip p; n       cin >> p.first >> p.second; n       p.third = i + 1; n       v.push_back(p); n     } n     long long k; n     cin >> k; n     vector<pair<long long, long long> > r; n     for (int i = 0; i < k; i++) { n       pair<long long, long long> p; n       cin >> p.first; n       p.second = i + 1; n       r.push_back(p); n     } n     sort((v).begin(), (v).end(), comp1); n     sort((r).begin(), (r).end()); n     vector<pair<long long, long long> > ans; n     long long sum = 0; n     for (int i = 0; i < k; i++) { n       long long mx = 0; n       long long in = -1; n       for (int j = 0; j < n; j++) { n         if (v[j].first > r[i].first) { n           break; n         } else { n           if (v[j].second > mx) { n             mx = v[j].second; n             in = j; n           } n         } n       } n       if (in != -1) { n         sum += v[in].second; n         pair<long long, long long> p; n         p.first = v[in].third; n         p.second = r[i].second; n         ans.push_back(p); n         v[in].second = -1; n       } n     } n     cout << ans.size() <<     << sum <<   n ; n     for (int i = 0; i < ans.size(); i++) { n       cout << ans[i].first <<     << ans[i].second <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n set<int> vis; n vector<int> ans; n map<int, int> d; n int main() { n   int n, m; n   cin >> n >> m; n   queue<int> q; n   int count = 0; n   for (int i = 0; i < n; i++) { n     int x; n     scanf( %d , &x); n     q.push(x); n     vis.insert(x); n     d[x] = 0; n   } n   long long int res = 0; n   while (count < m) { n     int now = q.front(); n     q.pop(); n     if (d[now] != 0) { n       res += d[now]; n       ans.push_back(now); n       count++; n     } n     if (vis.find(now - 1) == vis.end()) { n       q.push(now - 1); n       vis.insert(now - 1); n       d[now - 1] = d[now] + 1; n     } n     if (vis.find(now + 1) == vis.end()) { n       q.push(now + 1); n       vis.insert(now + 1); n       d[now + 1] = d[now] + 1; n     } n   } n   printf( %lld n , res); n   for (int i = 0; i < ans.size(); i++) { n     printf( %d  , ans[i]); n   } n   int zz = 0; n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long T = 0, n, t, a; n long long mu10(int b) { n   long long c = 1; n   for (int i = 1; i <= b; i++) c = c * 10; n   return c; n } n long long solve(long long c) { n   int m = 1; n   long long T = 0; n   while (T < c) { n     T += ((mu10(m)) - (mu10(m - 1))) * m; n     a = mu10(m) - 1; n     m++; n   } n   m -= 1; n   long long b = (T - c); n   long long d = a - (b / m); n   if (b % m == 0) n     return d % 10; n   else { n     d /= mu10(b % m); n     return d % 10; n   } n } n int main() { n   cin >> n; n   cout << solve(n); n   return 0; n } n


#include <bits/stdc++.h> n int prime[20000000 + 1] = {0}; n int palin[20000000 + 1] = {0}; n bool check[20000000 + 1] = {1, 1, 0}; n void primecheck() { n   for (int i = 2; i <= 20000000; i++) { n     if (check[i]) { n       prime[i] = prime[i - 1]; n       continue; n     } n     prime[i] = prime[i - 1] + 1; n     for (int j = 2; j * i <= 20000000; j++) check[j * i] = true; n   } n } n void palincheck() { n   for (int i = 1; i <= 20000000; i++) { n     int j = i; n     int counter = 0; n     while (j > 0) { n       counter = counter * 10 + j % 10; n       j = j / 10; n     } n     if (i == counter) n       palin[i] = palin[i - 1] + 1; n     else n       palin[i] = palin[i - 1]; n   } n } n int main() { n   primecheck(); n   palincheck(); n   int p, q; n   int left, right, mid; n   left = 1, right = 20000000; n   mid = (left + right) / 2; n   scanf( %d %d , &p, &q); n   for (int i = 20000000; i >= 1; i--) n     if ((long long int)q * prime[i] <= (long long int)p * palin[i]) { n       printf( %d n , i); n       return 0; n     } n   return 0; n } n


#include <bits/stdc++.h> n using db = double; n int read() { n   int x; n   scanf( %d , &x); n   return x; n } n const int N = 50007; n const db eps = 1e-10; n db x, y, k[N], b[N], ans; n int n, c, t[N * 2], las[N], L[N * 2], R[N * 2]; n struct node { n   db ang; n   int id; n } a[N * 2]; n db sqr(db a) { return a * a; } n void add(int p, int v) { n   for (; p <= c; p += p & -p) t[p] += v; n } n int ask(int p) { n   int s = 0; n   for (; p; p ^= p & -p) s += t[p]; n   return s; n } n int check(db r) { n   db A, B, C, D, X, Y; n   int s = 0; n   c = 0; n   for (int i = 1; i <= n; ++i) { n     A = sqr(k[i]) + 1, B = -2 * x + 2 * k[i] * (b[i] - y), n     C = sqr(x) + sqr(b[i] - y) - sqr(r); n     if (B * B + eps <= 4 * A * C) continue; n     D = sqrt(sqr(B) - 4 * A * C), A *= 2; n     X = (D - B) / A, Y = k[i] * X + b[i], a[++c] = {atan2(Y - y, X - x), i}; n     X = (-D - B) / A, Y = k[i] * X + b[i], a[++c] = {atan2(Y - y, X - x), i}; n   } n   std::sort(a + 1, a + c + 1, n             [](const node& a, const node& b) { return a.ang < b.ang; }); n   for (int i = 1, id; i <= c; ++i) n     las[id = a[i].id] ? s += ask(i) - ask(las[id]), add(las[id], -1), n         las[id] = 0   : (add(i, 1), las[id] = i); n   return s; n } n int pre[100010], nxt[100010], lst; n db cal(int i, int j) { n   db X = (b[j] - b[i]) / (k[i] - k[j]), Y = X * k[i] + b[i]; n   return sqrt(sqr(X - x) + sqr(Y - y)); n } n int main() { n   db l = 0; n   int m, s = 0; n   n = read(), x = read() / 1000.0, y = read() / 1000.0, m = read(); n   for (int i = 1; i <= n; ++i) k[i] = read() / 1000.0, b[i] = read() / 1000.0; n   for (db r = 1e13, mid, i = 100; i > 0; --i) n     check(mid = (l + r) / 2) < m ? l = mid : r = mid; n   check(l); n   for (int i = 1, j = 0, p; i <= c; ++i) n     if (las[a[i].id]) { n       for (p = j; p > las[a[i].id]; p = L[p]) ++s, ans += cal(a[i].id, a[p].id); n       R[L[p]] = R[p], L[R[p]] = L[p]; n       if (p == j) j = L[j]; n     } else n       R[j] = i, L[i] = j, j = i, las[a[i].id] = i; n   printf( %.10lf , ans + l * (m - s)); n } n


#include <bits/stdc++.h> n using namespace std; n static const double PI = acos(-1.0); n static const double EPS = 1e-9; n long long n; n long long a[200010]; n long long dp[200010][2]; n inline bool border(long long x) { return 0 <= x && x < n; } n long long dfs(long long x, long long step) { n   if (dp[x][step] != -1) return dp[x][step]; n   dp[x][step] = -2; n   if (step == 0) { n     if (!border(x + a[x])) { n       return dp[x][step] = a[x]; n     } else { n       long long y = dfs(x + a[x], 1); n       if (y == -2) n         return dp[x][step] = -2; n       else n         return dp[x][step] = y + a[x]; n     } n   } else if (step == 1) { n     if (!border(x - a[x])) { n       return dp[x][step] = a[x]; n     } else { n       long long y = dfs(x - a[x], 0); n       if (y == -2) n         return dp[x][step] = -2; n       else n         return dp[x][step] = y + a[x]; n     } n   } n } n int main() { n   int i, j; n   cin >> n; n   for (i = 1; i < n; ++i) cin >> a[i]; n   for (i = 0; i < n; ++i) n     for (j = 0; j < 2; ++j) dp[i][j] = -1; n   for (i = 1; i < n; ++i) n     for (j = 0; j < 2; ++j) dfs(i, j); n   for (i = 1; i < n; ++i) { n     if (dp[i][1] == -2) n       puts( -1 ); n     else n       printf( %I64d n , dp[i][1] + i); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, t; n   cin >> n >> t; n   n--; n   t--; n   int arr[n]; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   for (int i = 0; i <= n; i) { n     if (i == t) { n       cout <<  YES n ; n       return 0; n     } else { n       if (i < n) n         i += arr[i]; n       else n         break; n     } n   } n   cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   int n; n   vector<int> pl; n   vector<int> sum; n   int a; n   int otv = 0; n   cin >> n; n   int m = pow(2, n + 1) - 2; n   pl.push_back(0); n   for (int i = 1; i <= m; ++i) { n     cin >> a; n     pl.push_back(a); n   } n   for (int j = n; j > 0; j--) n     for (int i = pow(2, j); i < pow(2, j + 1) - 1; i += 2) { n       pl[i / 2 - 1] += max(pl[i - 1], pl[i]); n       otv += abs(pl[i - 1] - pl[i]); n     } n   cout << otv; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int CONST =  z  -  a  + 1; n struct Node { n   Node() { n     chars.resize(CONST); n     for (int i = 0; i < CONST; i++) chars[i].reset(nullptr); n   } n   vector<unique_ptr<Node> > chars; n }; n int prefix(Node* node, const string& word, int index) { n   while (true) { n     if (index == word.size()) return word.size(); n     char c = word[index]; n     if (node->chars[c -  a ].get() == nullptr) return index + 1; n     node = node->chars[c -  a ].get(); n     ++index; n   } n } n void add(Node* node, const string& word, int index) { n   while (true) { n     if (index == word.size()) return; n     char c = word[index]; n     if (node->chars[c -  a ].get() == nullptr) n       node->chars[c -  a ].reset(new Node()); n     node = node->chars[c -  a ].get(); n     index++; n   } n } n int main() { n   int k; n   cin >> k; n   string T; n   cin >> T; n   for (int i = 0; i < T.size(); ++i) { n     for (int j = 1; j < T.size(); j++) { n       for (int l = i; l <= i + j * 4; l += j) { n         if (l < T.size() && T[l] ==  * ) { n           if (l == i + j * 4) { n             cout <<  yes  << endl; n             return 0; n           } n         } else { n           break; n         } n       } n     } n   } n   cout <<  no  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class A> n void pr(A a) { n   cout << a; n   cout <<   n ; n } n template <class A, class B> n void pr(A a, B b) { n   cout << a <<    ; n   pr(b); n } n template <class A, class B, class C> n void pr(A a, B b, C c) { n   cout << a <<    ; n   pr(b, c); n } n template <class A, class B, class C, class D> n void pr(A a, B b, C c, D d) { n   cout << a <<    ; n   pr(b, c, d); n } n template <class A> n void PR(A a, long long n) { n   for (long long i = (long long)(0); i < (long long)(n); i++) { n     if (i) cout <<    ; n     cout << a[i]; n   } n   cout <<   n ; n } n long long check(long long n, long long m, long long x, long long y) { n   return x >= 0 && x < n && y >= 0 && y < m; n } n const long long MAX = 1e9 + 7, MAXL = 1LL << 61, dx[4] = {-1, 0, 1, 0}, n                 dy[4] = {0, 1, 0, -1}; n void Main() { n   int T; n   cin >> T; n   while (T--) { n     long long n; n     string s; n     cin >> n >> s; n     long long ans = n; n     for (long long i = (long long)(0); i < (long long)(n); i++) { n       if (s[i] ==  1 ) { n         ans = max(ans, (i + 1) * 2); n         ans = max(ans, (n - i) * 2); n       } n     } n     pr(ans); n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   Main(); 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   int n, m, i; n   cin >> n >> m; n   map<int, int> mp; n   for (i = 0; i < 3; i++) { n     int t; n     cin >> t; n     if (i == 0) mp[t] = 1; n     if (i == 1) mp[t] = 2; n     if (i == 2) mp[t] = 3; n   } n   for (i = 1; i < m; i++) { n     int a, b, c; n     cin >> a >> b >> c; n     if (mp[a] == 0 && mp[b] == 0 && mp[c] == 0) { n       mp[a] = 1; n       mp[b] = 2; n       mp[c] = 3; n     } else { n       if (mp[a] != 0) { n         int cur = b; n         for (int j = 1; j <= 3; j++) { n           if (mp[a] != j) { n             mp[cur] = j; n             cur = c; n           } n         } n       } else if (mp[b] != 0) { n         int cur = a; n         for (int j = 1; j <= 3; j++) { n           if (mp[b] != j) { n             mp[cur] = j; n             cur = c; n           } n         } n       } else { n         int cur = a; n         for (int j = 1; j <= 3; j++) { n           if (mp[c] != j) { n             mp[cur] = j; n             cur = b; n           } n         } n       } n     } n   } n   for (i = 1; i <= n; i++) { n     cout << mp[i] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, x, res, p[(1 << 20)]; n int main() { n   for (cin >> n; n--;) scanf( %d , &x), p[x]++; n   for (int i = 0; i < (1 << 20); i++) res += p[i] & 1, p[i + 1] += p[i] / 2; n   cout << res << endl; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void trace(T a) { n   cout << a <<   n ; n } n template <typename T, typename... Args> n void trace(T a, Args... args) { n   cout << a <<    ; n   trace(args...); n } n int recNum = 0; n void prTabs() { n   for (int i = 0; i < recNum; i++) cout <<       ; n } n template <typename... Args> n void recInit(Args... args) { n   prTabs(); n   trace( rec( , args...,  ) ); n   recNum++; n } n template <typename T> n void recEnd(T a) { n   prTabs(); n   trace( -> , a); n   recNum--; n } n int n, m, a, b, c; n map<int, int> s; n map<int, int> sa; n int li[500001]; n int freq[2][2000002]; n int k; n int main() { n   memset(freq, 0, sizeof freq); n   scanf( %d %d %d %d , &m, &k, &n, &b); n   for (int i = 1; i <= m; i++) { n     scanf( %d , li + i); n   } n   for (int i = 0; i < b; i++) { n     scanf( %d , &a); n     if (s.count(a)) { n       s[a]++; n     } else { n       s[a] = 1; n     } n   } n   int il = 0, ir = 0; n   for (int i = 0; i < n; i++) { n     int dacerto = true; n     while (ir < m - ((n - 1 - i) * k)) { n       freq[1][li[++ir]]++; n     } n     while (il < k * i) { n       freq[0][li[++il]]++; n     } n     for (map<int, int>::iterator it = s.begin(); it != s.end(); it++) { n       if (freq[1][it->first] - freq[0][it->first] < it->second) { n         dacerto = false; n         break; n       } n     } n     if (!dacerto) continue; n     printf( %d n , m - (n * k)); n     int falta = k - b; n     for (int j = k * i + 1; j <= m - ((n - 1 - i) * k); j++) { n       if (sa[li[j]] < s[li[j]]) { n         sa[li[j]]++; n       } else if (falta) { n         sa[li[j]]++; n         falta--; n       } else { n         printf( %d  , j); n       } n     } n     printf(  n ); n     return 0; n   } n   printf( -1 n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int infinity = 9e18; n bool possible(long long int x1, long long int x2, long long int y1, n               long long int y2, long long int n, long long int m, string s, n               long long int dx, long long int dy) { n   long long int a = m / n; n   long long int b = m % n; n   x1 += a * dx; n   y1 += a * dy; n   for (int i = 0; i < b; i++) { n     if (s[i] ==  U ) y1++; n     if (s[i] ==  D ) y1--; n     if (s[i] ==  R ) x1++; n     if (s[i] ==  L ) x1--; n   } n   if ((abs(y1 - y2) + abs(x1 - x2)) <= m) return 1; n   return 0; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int x1, x2, y1, y2, n; n   cin >> x1 >> y1 >> x2 >> y2 >> n; n   string s; n   cin >> s; n   long long int dx = 0, dy = 0; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  U ) dy++; n     if (s[i] ==  D ) dy--; n     if (s[i] ==  R ) dx++; n     if (s[i] ==  L ) dx--; n   } n   long long int st = 0, end = 1e18; n   while (st < end) { n     long long int mid = (end + st) / 2; n     if (possible(x1, x2, y1, y2, n, mid, s, dx, dy)) { n       end = mid; n     } else { n       st = mid + 1; n     } n   } n   if (st == 1e18) n     cout << -1; n   else n     cout << st; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 5; n vector<int> g[N], gr[N]; n bool used[N]; n vector<int> order, component; n pair<int, int> edge[N]; n int par[N]; n vector<int> v[N]; n int f(int i) { n   if (par[i] != i) par[i] = f(par[i]); n   return par[i]; n } n void merge(int a, int b) { n   a = f(a), b = f(b); n   if (a == b) return; n   par[a] = b; n } n void dfs1(int v) { n   used[v] = true; n   for (size_t i = 0; i < g[v].size(); ++i) n     if (!used[g[v][i]]) dfs1(g[v][i]); n   order.push_back(v); n } n void dfs2(int v) { n   used[v] = true; n   component.push_back(v); n   for (size_t i = 0; i < gr[v].size(); ++i) n     if (!used[gr[v][i]]) dfs2(gr[v][i]); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n, m; n     cin >> n >> m; n     for (int i = 1; i <= n; i++) n       g[i].clear(), gr[i].clear(), par[i] = i, v[i].clear(); n     order.clear(); n     component.clear(); n     for (int i = 1; i <= n; i++) used[i] = false; n     for (int i = 0; i <= m - 1; i++) { n       int a, b; n       cin >> a >> b; n       edge[i] = make_pair(a, b); n       g[a].push_back(b); n       gr[b].push_back(a); n     } n     for (int i = 1; i <= n; ++i) n       if (!used[i]) dfs1(i); n     for (int i = 1; i <= n; i++) used[i] = false; n     for (int i = 0; i < n; ++i) { n       int v = order[n - 1 - i]; n       if (!used[v]) { n         dfs2(v); n         int sz = component.size(); n         for (int i = 0; i <= sz - 1; i++) merge(component[0], component[i]); n         component.clear(); n       } n     } n     for (int i = 1; i <= n; i++) v[i].clear(); n     set<int> s; n     for (int i = 1; i <= n; i++) { n       s.insert(f(i)); n     } n     if (s.size() == 1) { n       cout <<  No n ; n     } else { n       for (int i = 0; i <= m - 1; i++) { n         if (f(edge[i].first) == f(edge[i].second)) continue; n         v[f(edge[i].first)].push_back(f(edge[i].second)); n       } n       set<int> s1; n       for (int i = 1; i <= n; i++) { n         if (v[f(i)].size() == 0) { n           for (int j = 1; j <= n; j++) { n             if (f(i) == f(j)) s1.insert(j); n           } n           break; n         } n       } n       cout <<  Yes n ; n       cout << s1.size() <<     << n - s1.size(); n       cout <<   n ; n       for (__typeof(s1.begin()) it = s1.begin(); it != s1.end(); it++) { n         cout << *it; n         cout <<    ; n       } n       cout <<   n ; n       for (int i = 1; i <= n; i++) { n         if (!(s1.find(i) != s1.end())) { n           cout << i; n           cout <<    ; n         } n       } n       cout <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n double first[10005], second[10005], w, u, v; n double eps = 1e-9; n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(NULL), cout.tie(NULL); n   cin >> n >> w >> u >> v; n   for (int i = 0; i < n; i++) cin >> first[i] >> second[i]; n   double ans = w / v; n   int fl = 0; n   for (int i = 0; i < n; i++) { n     if (first[i] > eps) fl = 1; n   } n   if (!fl) { n     cout << fixed << setprecision(15) << ans; n     return 0; n   } n   fl = 0; n   for (int i = 0; i < n; i++) { n     if (first[i] < eps) { n       fl = 1; n       break; n     } n     if (w - second[i] < eps) continue; n     double ti = first[i] / u; n     double hi = second[i] / v; n     if (hi - ti < eps) continue; n     fl = 1; n     break; n   } n   if (!fl) { n     cout << fixed << setprecision(15) << ans; n     return 0; n   } n   for (int i = 0; i < n; i++) { n     if (first[i] < eps) continue; n     if (w - second[i] < eps) continue; n     double j = first[i] / u; n     if (second[i] - w > eps) continue; n     double f = second[i] / v; n     if (f - j > eps) j = f; n     j += (w - second[i]) / v; n     ans = max(ans, j); n   } n   cout << fixed << setprecision(15) << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[110]; n bool a[10]; n int main() { n   int x, y, pow = 1, t, k, b = 0; n   gets(s); n   k = strlen(s); n   for (int i = 0; i < k; i++) { n     for (int j = 0; j < 8; j++) a[j] = 0; n     x = (int)s[i]; n     for (int j = 0; j < 8; j++) { n       if (x % 2 == 1) n         a[j] = 1; n       else n         a[j] = 0; n       x /= 2; n     } n     t = 0; n     pow = 1; n     for (int j = 7; j >= 0; j--) { n       t += pow * a[j]; n       pow *= 2; n     } n     y = (256 - t + b) % 256; n     b = t; n     cout << y << endl; n   } n   scanf(   ); n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int pow2[50]; n int l[50]; n int level(long long p) { n   long long comp = 1; n   int ans = 0; n   while (comp <= p) { n     comp <<= 1; n     ans++; n   } n   return ans - 1; n } n bool ispow2(long long p) { n   long long comp = 1; n   while (comp < p) { n     comp <<= 1; n   } n   return comp == p; n } n bool viable(int cnt) { n   int le[50]; n   for (int i = 0; i < 50; i++) le[i] = l[i]; n   int slot[50]; n   for (int i = 0; i < 50; i++) slot[i] = 0; n   for (int i = 0; i < 50; i++) { n     if (i == 0) { n       if (pow2[i] > cnt) { n         slot[i] = cnt; n         le[i] += pow2[i] - cnt; n       } else { n         slot[i] = pow2[i]; n       } n     } else { n       if (pow2[i] > slot[i - 1]) { n         slot[i] = slot[i - 1]; n         le[i] += pow2[i] - slot[i]; n       } else { n         slot[i] = pow2[i]; n       } n     } n   } n   int sum = 0; n   for (int i = 49; i >= 0; i--) { n     sum += le[i]; n     if (sum > slot[i]) return false; n   } n   return true; n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     long long a; n     cin >> a; n     if (ispow2(a)) n       pow2[level(a)]++; n     else n       l[level(a)]++; n   } n   if (!viable(pow2[0])) { n     cout << -1 << endl; n     return 0; n   } n   int ansl = pow2[0]; n   while (ansl > 1 && viable(ansl - 1)) ansl--; n   for (int i = ansl; i <= pow2[0]; i++) { n     if (viable(i)) cout << i <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 5; n long long n, l[MAXN], r[MAXN], vall[MAXN], valr[MAXN], pos[MAXN], d[MAXN], n     tree[4 * MAXN], ind[MAXN]; n bool validl[MAXN], validr[MAXN], dead; n pair<long long, long long> sortr[MAXN]; n void computeleft() { n   l[0] = -1, r[0] = 1, r[n + 1] = -1, l[n + 1] = n; n   for (int i = 1; i <= n; ++i) l[i] = i - 1, r[i] = i + 1; n   validl[0] = 1, vall[0] = 2 * d[0]; n   for (int i = 1; i <= n + 1; ++i) { n     queue<int> drop; n     if ((i > 1) && (pos[r[i - 1]] - pos[l[i - 1]] > 2 * d[i - 1])) n       drop.push(i - 1); n     while (!drop.empty()) { n       int t = drop.front(); n       drop.pop(); n       int lt = l[t], rt = r[t]; n       r[lt] = r[t]; n       l[rt] = l[t]; n       if (lt != 0) { n         if (pos[r[lt]] - pos[l[lt]] > 2 * d[lt]) drop.push(lt); n       } n       if (rt != i) { n         if (pos[r[rt]] - pos[l[rt]] > 2 * d[rt]) drop.push(rt); n       } n     } n     if (2 * d[i] - (pos[i] - pos[l[i]]) > 0) validl[i] = 1; n     vall[i] = 2 * d[i] + pos[l[i]]; n   } n   if (r[0] != n + 1) { n     cout <<  0.0 n ; n     exit(0); n   } n } n void computeright() { n   l[0] = -1, r[0] = 1, r[n + 1] = -1, l[n + 1] = n; n   for (int i = 1; i <= n; ++i) l[i] = i - 1, r[i] = i + 1; n   validr[n + 1] = 1, valr[n + 1] = pos[n + 1] - 2 * d[n + 1]; n   for (int i = n; i >= 1; --i) { n     queue<int> drop; n     if ((i < n) && (pos[r[i + 1]] - pos[l[i + 1]] > 2 * d[i + 1])) n       drop.push(i + 1); n     while (!drop.empty()) { n       int t = drop.front(); n       drop.pop(); n       int lt = l[t], rt = r[t]; n       r[lt] = r[t]; n       l[rt] = l[t]; n       if (lt != i) { n         if (pos[r[lt]] - pos[l[lt]] > 2 * d[lt]) drop.push(lt); n       } n       if (rt != n + 1) { n         if (pos[r[rt]] - pos[l[rt]] > 2 * d[rt]) drop.push(rt); n       } n     } n     if (2 * d[i] - (pos[r[i]] - pos[i]) > 0) validr[i] = 1; n     valr[i] = pos[r[i]] - 2 * d[i]; n   } n } n void init(int l = 0, int r = n, int node = 1) { n   if (l == r) { n     tree[node] = 1e9 + 5; n     return; n   } n   int mid = (l + r) / 2; n   init(l, mid, 2 * node); n   init(mid + 1, r, 2 * node + 1); n   tree[node] = min(tree[2 * node], tree[2 * node + 1]); n } n int findmin(int a, int b, int l = 0, int r = n, int node = 1) { n   if (a == l && b == r) return tree[node]; n   int mid = (l + r) / 2; n   if (b <= mid) return findmin(a, b, l, mid, 2 * node); n   if (a >= mid + 1) return findmin(a, b, mid + 1, r, 2 * node + 1); n   return min(findmin(a, mid, l, mid, 2 * node), n              findmin(mid + 1, b, mid + 1, r, 2 * node + 1)); n } n void upd(int v, int x, int l = 0, int r = n, int node = 1) { n   if (l == r) { n     tree[node] = x; n     return; n   } n   int mid = (l + r) / 2; n   if (v <= mid) n     upd(v, x, l, mid, 2 * node); n   else n     upd(v, x, mid + 1, r, 2 * node + 1); n   tree[node] = min(tree[2 * node], tree[2 * node + 1]); n } n void findans() { n   for (int i = 0; i <= n; ++i) n     sortr[i] = pair<long long, long long>(valr[i + 1], i + 1); n   sort(sortr, sortr + n + 1); n   for (int i = 0; i <= n; ++i) ind[sortr[i].second] = i; n   init(); n   long long best = 1e9 + 5; n   for (int i = n; i >= 0; --i) { n     if (validr[i + 1]) upd(ind[i + 1], pos[i + 1]); n     if (!validl[i]) continue; n     int lo = -1, hi = n; n     while (lo != hi) { n       int mid = (lo + hi + 1) / 2; n       if (sortr[mid].first > vall[i]) n         hi = mid - 1; n       else n         lo = mid; n     } n     if (lo != -1) best = min(best, findmin(0, lo) - pos[i]); n   } n   cout << fixed << setprecision(1) << 0.5 * best << endl; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   for (int i = 0; i < n + 2; ++i) cin >> pos[i]; n   d[0] = d[n + 1] = 1LL * 1000000 * 1000000 + 5; n   for (int i = 1; i <= n; ++i) cin >> d[i]; n   computeleft(); n   computeright(); n   findans(); n } n


#include <bits/stdc++.h> n using namespace std; n const int K = 103, N = 30005; n double f[K], sum[K]; n double pr[N][K]; n double mem[N][K]; n int main() { n   string s; n   cin >> s; n   int n, H; n   cin >> n >> H; n   H++; n   if (s ==  Bob ) { n     cout << n << endl; n     return 0; n   } n   for (int i = 1; i <= H; i++) { n     if (i == H) n       f[i] = pow(2, -(i - 1)); n     else n       f[i] = pow(2, -i); n     sum[i] = sum[i - 1] + f[i]; n   } n   for (int i = 1; i <= n; i++) n     for (int t = 1; t <= H; t++) n       mem[i][t] = pow(sum[t], i - 1) - pow(sum[t - 1], i - 1); n   memset(pr, 0, sizeof pr); n   pr[1][0] = 1; n   for (int i = 2; i <= n; i++) { n     for (int h = 1; h <= H; h++) { n       double leftbigger = 1 - pow(sum[h], i - 1); n       double rightbigger = 1 - pow(sum[h], n - i); n       double skipped = leftbigger * rightbigger; n       double dd = skipped * f[h]; n       pr[i][0] += dd; n       double sm = dd; n       for (int t = 1; t < h; t++) { n         double left = mem[i][t]; n         pr[i][t] += left * f[h]; n         sm += left * f[h]; n       } n       pr[i][h] += f[h] - sm; n     } n   } n   double ans = 1; n   for (int i = 1; i <= n; i++) n     for (int h = 1; h <= H; h++) ans += pr[i][h] * pow(2, h - 1); n   cout << setprecision(15) << ans << endl; n } n


#include <bits/stdc++.h> n int p[100100]; n void solve(int n, int m) { n   int i, j, k, x, s = 0, l = 0, r = n; n   for (i = 0; i < 100100; i++) p[i] = 0; n   for (i = 0; i <= n; i++) p[i] = i; n   for (k = 0; k < m; k++) { n     scanf( %d , &x); n     if (x == 1) { n       scanf( %d , &x); n       if (s == 0) { n         if (2 * x <= r - l) { n           for (i = l + x; i <= l + 2 * x; i++) n             p[i] = p[i] - p[2 * l + 2 * x - i]; n           l += x; n         } else { n           for (i = l + x; i >= 2 * l + 2 * x - r; i--) n             p[i] = p[i] + n - p[2 * l + 2 * x - i]; n           r -= r - l - x; n           s = 1; n         } n       } else { n         if (2 * x <= r - l) { n           x = r - l - x; n           for (i = l + x; i >= 2 * l + 2 * x - r; i--) n             p[i] = p[i] + n - p[2 * l + 2 * x - i]; n           r -= r - l - x; n         } else { n           x = r - l - x; n           for (i = l + x; i <= l + 2 * x; i++) n             p[i] = p[i] - p[2 * l + 2 * x - i]; n           l += x; n           s = 0; n         } n       } n     } else { n       scanf( %d%d , &i, &j); n       if (s == 0) { n         printf( %d n , p[j + l] - p[i + l]); n       } else { n         printf( %d n , p[r - i] - p[r - j]); n       } n     } n   } n } n int main() { n #pragma comment(linker,  /STACK:134217728 ) n   int n, m; n   while (scanf( %d%d , &n, &m) != EOF) { n     solve(n, m); n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:100000000 ) n #pragma GCC ostarimize( O500 ) n using namespace std; n const bool db = false; n set<pair<int, int>> s; n int a[200100]; n int main() { n   int n, k, q; n   scanf( %d %d %d n , &n, &k, &q); n   for (int i = 1; i <= n; i++) scanf( %d  , &a[i]); n   scanf(  n ); n   int type, num; n   set<pair<int, int>>::iterator it; n   while (q--) { n     scanf( %d %d n , &type, &num); n     if (type == 1) { n       s.insert({-a[num], num}); n       if (s.size() > k) { n         it = s.end(); n         it--; n         s.erase(it); n       } n     } else { n       if (s.count({-a[num], num})) n         puts( YES ); n       else n         puts( NO ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b; n   cin >> a >> b; n   cout << (a + b); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Point { n   long long x, y; n   int id; n   Point() {} n   Point(long long a, long long b, int c) : x(a), y(b), id(c) {} n   Point operator-(Point b) { return Point(x - b.x, y - b.y, 0); } n   bool operator<(const Point &b) const { n     return (x != b.x) ? x < b.x : y < b.y; n   } n }; n long long cross(Point x, Point y) { return x.x * y.y - x.y * y.x; } n bool in[2005]; n int gethull(Point *p, int n, int s, bool v) { n   static Point st[2005], hull[2005]; n   int top = 0, cnt = 0; n   for (int i = 1; i <= n; i++) { n     while (top > 1 && cross(p[i] - st[top], st[top] - st[top - 1]) >= 0) top--; n     st[++top] = p[i]; n   } n   for (int i = 1; i < top; i++) hull[++cnt] = st[i]; n   top = 0; n   for (int i = 1; i <= n; i++) { n     while (top > 1 && cross(p[i] - st[top], st[top] - st[top - 1]) <= 0) top--; n     st[++top] = p[i]; n   } n   for (int i = top; i > 1; i--) hull[++cnt] = st[i]; n   for (int i = 1; i <= cnt; i++) n     if (hull[i].id == s) { n       in[hull[i].id] = 1; n       return (v) ? hull[(i - 1 + cnt - 1) % cnt + 1].id : hull[i % cnt + 1].id; n     } n } n Point p[2005], q[2005]; n char str[2005]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     p[i] = Point(x, y, i); n   } n   scanf( %s , str + 1); n   str[n - 1] =  L ; n   sort(p + 1, p + n + 1); n   int cur = p[1].id; n   for (int i = 1; i < n; i++) { n     int cnt = 0; n     for (int j = 1; j <= n; j++) n       if (!in[p[j].id]) q[++cnt] = p[j]; n     printf( %d  , cur); n     cur = gethull(q, cnt, cur, (str[i] ==  R )); n   } n   printf( %d n , cur); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n const int N = 1e6 + 5; n int n, m, k; n bool vis[N]; n int main() { n   ios::sync_with_stdio(false); n   cin >> n >> m >> k; n   int h; n   for (int i = 1; i <= m; i++) { n     cin >> h; n     vis[h] = 1; n   } n   bool fg = 0; n   int bone = 1; n   if (vis[bone]) fg = 1; n   for (int i = 1; i <= k; i++) { n     int u, v; n     cin >> u >> v; n     if ((u == bone || v == bone) && !fg) { n       bone = (bone == u) ? v : u; n       if (vis[bone]) fg = 1; n     } n   } n   cout << bone << endl; n   return 0; n } n


#include <bits/stdc++.h> n int min(int a, int b) { return a < b ? a : b; } n int max(int a, int b) { return a > b ? a : b; } n unsigned int X; n void srand_() { n   struct timeval tv; n   gettimeofday(&tv, NULL); n   X = tv.tv_sec ^ tv.tv_usec | 1; n } n int rand_() { return (X *= 3) >> 1; } n int *ej[1000], eo[1000]; n void append(int i, int j) { n   int o = eo[i]++; n   if (o >= 2 && (o & o - 1) == 0) n     ej[i] = (int *)realloc(ej[i], o * 2 * sizeof *ej[i]); n   ej[i][o] = j; n } n int aa[1000], bb[1000], ii[1000], n; n int compare(int i, int j) { return aa[i] != aa[j] ? aa[i] - aa[j] : i - j; } n void sort(int *ii, int l, int r) { n   while (l < r) { n     int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp; n     while (j < k) { n       int c = compare(ii[j], i_); n       if (c == 0) n         j++; n       else if (c < 0) { n         tmp = ii[i], ii[i] = ii[j], ii[j] = tmp; n         i++, j++; n       } else { n         k--; n         tmp = ii[j], ii[j] = ii[k], ii[k] = tmp; n       } n     } n     sort(ii, l, i); n     l = k; n   } n } n char visited[1000]; n int qu[1000], cnt; n int i_; n void dfs1(int i) { n   int o; n   if (visited[i] || compare(i, i_) > 0) return; n   visited[i] = 1; n   qu[cnt++] = i; n   for (o = eo[i]; o--;) { n     int j = ej[i][o]; n     dfs1(j); n   } n } n char add[1000]; n int cc[1000][1000]; n void dfs2(int p, int i, int c) { n   int o; n   for (o = eo[i]; o--;) { n     int j = ej[i][o]; n     if (j != p) { n       if (compare(j, i_) > 0) n         cc[i_][j] = max(cc[i_][j], c); n       else n         dfs2(i, j, min(c + bb[j], 0x3f3f3f3f)); n     } n   } n } n int dp[1000]; n int solve(int s) { n   int g; n   memset(dp, 0, n * sizeof *dp), dp[0] = s; n   for (g = 0; g < n; g++) { n     int i_ = ii[g], x = dp[i_], j; n     if (x == 0) continue; n     for (j = 0; j < n; j++) n       if (compare(i_, j) < 0 && cc[i_][j] != -1) { n         int c = add[i_] ? min(x + cc[i_][j], 0x3f3f3f3f) n                         : min(s + cc[i_][j], 0x3f3f3f3f); n         if (c >= aa[j]) dp[j] = max(dp[j], min(c + bb[j], 0x3f3f3f3f)); n       } n   } n   return dp[ii[n - 1]] > 0; n } n int main() { n   int t; n   srand_(); n   scanf( %d , &t); n   while (t--) { n     static int qu_[1000], dd[1000], pp[1000]; n     int m, g, h, i, j, o, cnt_, lower, upper; n     scanf( %d%d , &n, &m); n     aa[0] = 0; n     for (i = 1; i < n; i++) scanf( %d , &aa[i]), aa[i]++; n     for (i = 1; i < n; i++) scanf( %d , &bb[i]); n     for (i = 0; i < n; i++) ej[i] = (int *)malloc(2 * sizeof *ej[i]), eo[i] = 0; n     for (h = 0; h < m; h++) { n       scanf( %d%d , &i, &j), i--, j--; n       append(i, j), append(j, i); n     } n     for (i = 0; i < n; i++) ii[i] = i; n     sort(ii, 0, n); n     for (g = 0; g < n; g++) { n       i_ = ii[g]; n       memset(visited, 0, n * sizeof *visited), cnt = 0; n       memset(cc[i_], -1, n * sizeof *cc[i_]); n       dfs1(0); n       if (visited[i_]) { n         int tree, p; n         memset(dd, 0, n * sizeof *dd); n         memset(pp, -1, n * sizeof *pp); n         for (h = 0; h < cnt; h++) { n           i = qu[h]; n           for (o = eo[i]; o--;) { n             j = ej[i][o]; n             if (visited[j]) dd[i]++; n           } n         } n         cnt_ = 0; n         for (h = 0; h < cnt; h++) { n           i = qu[h]; n           if (dd[i] == 1) qu_[cnt_++] = i; n         } n         while (cnt_) { n           i = qu_[--cnt_]; n           dd[i] = -1; n           for (o = eo[i]; o--;) { n             j = ej[i][o]; n             if (dd[j] > 0) { n               pp[i] = j; n               if (--dd[j] == 1) qu_[cnt_++] = j; n             } n           } n         } n         tree = 1; n         for (h = 0; h < cnt; h++) { n           i = qu[h]; n           if (dd[i] > 0) { n             tree = 0; n             break; n           } n         } n         p = -1, i = 0; n         while (i != -1 && dd[i] <= 0 && i != i_) p = i, i = pp[i]; n         add[i_] = 1; n         if (dd[i_] <= 0 && i != i_) n           dfs2(pp[i_], i_, 0); n         else if (tree) n           dfs2(p, i_, 0); n         else { n           int c; n           add[i_] = 0; n           c = 0; n           for (i = 0; i != -1 && dd[i] <= 0; i = pp[i]) n             c = min(c + bb[i], 0x3f3f3f3f); n           for (h = 0; h < cnt; h++) { n             i = qu[h]; n             if (dd[i] > 0) c = min(c + bb[i], 0x3f3f3f3f); n           } n           for (p = -1, i = 0; i != -1 && dd[i] <= 0; p = i, i = pp[i]) n             for (o = eo[i]; o--;) { n               j = ej[i][o]; n               if (compare(j, i_) > 0) n                 cc[i_][j] = max(cc[i_][j], c); n               else if (j != pp[i] && j != p) n                 dfs2(i, j, min(c + bb[j], 0x3f3f3f3f)); n             } n           for (h = 0; h < cnt; h++) { n             i = qu[h]; n             if (dd[i] > 0) n               for (o = eo[i]; o--;) { n                 j = ej[i][o]; n                 if (compare(j, i_) > 0) n                   cc[i_][j] = max(cc[i_][j], c); n                 else if (pp[j] == i && j != p) n                   dfs2(i, j, min(c + bb[j], 0x3f3f3f3f)); n               } n           } n         } n       } n     } n     lower = 0, upper = 0x3f3f3f3f; n     while (upper - lower > 1) { n       int s = (lower + upper) / 2; n       if (solve(s)) n         upper = s; n       else n         lower = s; n     } n     printf( %d n , upper); n     for (i = 0; i < n; i++) free(ej[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MIN = numeric_limits<long long>::min(); n class WindowHeap { n  public: n   WindowHeap() {} n   long long top() { n     if (_i >= _h.size()) return MIN; n     return _h[_i].first; n   } n   void erase(int idx) { n     if (!_h.empty() && _h[_i].second == idx) ++_i; n   } n   void insert(long long val, int idx) { n     if (val == MIN) return; n     while (!_h.empty() && val > _h.rbegin()->first) _h.pop_back(); n     if (_h.empty() || val < _h.rbegin()->first) n       _h.emplace_back(val, idx); n     else n       _h.rbegin()->second = idx; n     if (_i >= _h.size()) _i = _h.size() - 1; n   } n  n  private: n   vector<pair<long long, int>> _h; n   size_t _i; n }; n int main() { n   int n, k, x; n   cin >> n >> k >> x; n   vector<int> a(n); n   for (int& ai : a) cin >> ai; n   vector<long long> dp(n + 1, MIN); n   dp[0] = 0; n   for (int xi = 0; xi < x; ++xi) { n     WindowHeap wh; n     for (int i = n - 1; i > max(n - k, -1); --i) { n       wh.insert(dp[i], i); n     } n     for (int i = n; i > xi; --i) { n       if (i - k >= 0) wh.insert(dp[i - k], i - k); n       long long p = wh.top(); n       if (p > MIN) dp[i] = p + a[i - 1]; n       wh.erase(i - 1); n     } n     dp[xi] = MIN; n   } n   long long best = -1; n   for (int i = n; i > n - k; --i) best = max(best, dp[i]); n   cout << best << endl; n   return 0; n } n


#include <bits/stdc++.h> n long double read() { n   int x; n   scanf( %d , &x); n   return x / 1000.0L; n } n const long double eps = 1e-9, Eps = 1e-7; n const int N = 1e5 + 5, V = 4e7 + 5; n int n, m, q, rb[N], vol, stc[V]; n std::pair<int, int> p[N]; n long double k, ox, oy, a[N], b[N], cx[N], cy[N]; n long double ans, dis[N], s[N], t[N], tb[N]; n struct FenwickTree { n   int f[N]; n   void reset(int n) { memset(f, 0, (n + 1) * 4); } n   void modify(int u, int x) { n     for (int i = u; i <= m; i += i & -i) { n       f[i] += x; n     } n   } n   int query(int u) { n     int res = 0; n     for (int i = u; i >= 1; i ^= i & -i) { n       res += f[i]; n     } n     return res; n   } n   int query(int l, int r) { n     if (l >= r) { n       return 0; n     } n     return query(r) - query(l); n   } n } tr; n long double get(int i, int j) { n   long double x = (b[i] - b[j]) / (a[j] - a[i]), y = a[i] * x + b[i]; n   return std::sqrt((x - ox) * (x - ox) + (y - oy) * (y - oy)); n } n bool check(long double k, bool typ) { n   int res = 0; n   m = 0; n   for (int i = 0; i < n; i++) { n     long double x = cx[i] - ox, y = cy[i] - oy; n     if (dis[i] > k * k - eps) { n       continue; n     } n     if (std::abs(dis[i]) < eps) { n       s[i] = std::atan2(a[i], 1); n       t[i] = std::atan2(-a[i], -1); n     } else { n       long double z = std::sqrt(k * k / dis[i] - 1); n       s[i] = std::atan2(y - x * z, x + y * z); n       t[i] = std::atan2(y + x * z, x - y * z); n     } n     if (s[i] > t[i]) { n       std::swap(s[i], t[i]); n     } n     s[i] += eps; n     t[i] -= eps; n     tb[m++] = s[i]; n     tb[m++] = t[i]; n   } n   std::sort(tb, tb + m); n   for (int i = 0; i < n; i++) { n     if (dis[i] > k * k - eps) { n       p[i] = {m, i}; n       continue; n     } n     p[i] = {std::upper_bound(tb, tb + m, s[i]) - tb - 1, i}; n     rb[i] = std::upper_bound(tb, tb + m, t[i]) - tb; n   } n   std::sort(p, p + n); n   if (!typ) { n     tr.reset(m); n     for (int i = 0; i < n; i++) { n       if (p[i].first == m) { n         break; n       } n       res += tr.query(p[i].first, rb[p[i].second]); n       tr.modify(rb[p[i].second], 1); n       if (res >= q) { n         return false; n       } n     } n   } else { n     for (int i = 0; i < n; i++) { n       if (p[i].first == m) { n         break; n       } n       for (; vol > 0 && rb[stc[vol]] <= p[i].first; vol--) n         ; n       stc[++vol] = p[i].second; n       for (int i = vol - 1; i > 0; i--) { n         if (rb[stc[i]] > rb[stc[i + 1]]) { n           break; n         } n         double tmp = get(stc[i], stc[i + 1]); n         ans += tmp; n         res++; n         std::swap(stc[i], stc[i + 1]); n       } n     } n     ans += (q - res) * k; n   } n   return true; n } n int main() { n   scanf( %d , &n); n   ox = read(); n   oy = read(); n   scanf( %d , &q); n   int pass = 0; n   for (int i = 0; i < n; i++) { n     a[i] = read(); n     b[i] = read(); n     if (std::abs(a[i]) < eps) { n       cx[i] = ox; n       cy[i] = b[i]; n     } else { n       long double _a = -1 / a[i], _b = oy - _a * ox; n       cx[i] = (_b - b[i]) / (a[i] - _a); n       cy[i] = a[i] * cx[i] + b[i]; n     } n     dis[i] = (ox - cx[i]) * (ox - cx[i]) + (oy - cy[i]) * (oy - cy[i]); n     if (dis[i] < eps) { n       pass++; n     } n   } n   if (pass * (pass - 1ll) / 2 >= q) { n     printf( 0.000000 n ); n     return 0; n   } n   for (long double l = Eps, r = 21e8, mid; l <= r;) { n     mid = (l + r) / 2; n     if (check(mid, false)) { n       l = mid + Eps; n       k = mid; n     } else { n       r = mid - Eps; n     } n   } n   check(k, true); n   printf( %.6f n , (double)ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n vector<int> v[100000]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   map<int, int> m; n   for (int i = 0; i < n; i++) { n     int a; n     cin >> a; n     for (int j = 2; j <= sqrt(a); j++) { n       if (a % j == 0) { n         m[j]++; n         while (a % j == 0) a /= j; n       } n     } n     if (a != 1) m[a]++; n   } n   int ans = 1; n   for (auto i : m) ans = max(ans, i.second); n   cout << ans; n   return 0; n } n


#include <iostream> n #include <queue> n #include <algorithm> n #include <cstring> n #include <cmath> n #include <vector> n using namespace std; n typedef long long LL; n const LL mod = 1e9 + 7; n const int N = 1e6 + 10; n  n LL l[N], r[N]; n LL c[N], a[N], b[N]; n int main() n { n  int T;cin >> T; n  while (T--) n  { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++)scanf( %lld ,&c[i]); n   for (int i = 1; i <= n; i++)scanf( %lld , &a[i]); n   for (int i = 1; i <= n; i++)scanf( %lld , &b[i]); n  n   LL res = 0; n   for (int i = 1; i < n;i++) n   { n    LL t = abs(a[i+1] - b[i+1]); n    LL t2 = abs(a[i + 1] - b[i + 1]); n     n    l[i] =t+1; n    if (a[i+1] != b[i+1]&&i>1) n     l[i] = max(l[i], l[i - 1] + c[i] - t + 1); n    res = max(res, l[i] + c[i + 1]); n     n   } n  n   cout << res << endl; n  } n }


#include <bits/stdc++.h> n using namespace std; n const int N = 20; n const int V = (1 << 20) + 10; n const int P = 1000000007; n int Pow(int x, int y) { n   int ret = 1; n   while (y) { n     if (y & 1) ret = (long long)ret * x % P; n     x = (long long)x * x % P; n     y /= 2; n   } n   return ret; n } n void utf(int *a, int l, int r) { n   if (l + 1 != r) { n     int mid = (l + r) / 2; n     for (int i = 0; i < mid - l; i++) { n       a[l + i] -= a[mid + i]; n       if (a[l + i] < 0) a[l + i] += P; n     } n     utf(a, l, mid); n     utf(a, mid, r); n   } n } n void tf(int *a, int l, int r) { n   if (l + 1 != r) { n     int mid = (l + r) / 2; n     tf(a, l, mid); n     tf(a, mid, r); n     for (int i = 0; i < mid - l; i++) { n       if (((l + i) & (mid + i)) != (l + i)) n         while (1) n           ; n       a[l + i] += a[mid + i]; n       if (a[l + i] >= P) a[i + l] -= P; n     } n   } n } n int cnt[V], q[V]; n int n, x, pro[V]; n int pt[V]; n int main() { n   pt[0] = 1; n   for (int i = 1; i < (1 << N); i++) pt[i] = pt[i - 1] * 2 % P; n   while (~scanf( %d , &n)) { n     memset(cnt, 0, sizeof(cnt)); n     for (int i = 0; i < n; i++) { n       scanf( %d , &x); n       cnt[x]++; n     } n     tf(cnt, 0, (1 << N)); n     for (int i = 0; i < (1 << N); i++) pro[i] = pt[cnt[i]]; n     utf(pro, 0, (1 << N)); n     printf( %d n , pro[0]); n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n, i, j, ans = 0; n   char c[101]; n   scanf( %d , &n); n   scanf( %s , c); n   int l; n   for (l = 1; l <= n; l++) { n     for (i = 0; i < n - 4 * l; i++) { n       if (c[i] ==  *  && c[i + l] ==  *  && c[i + 2 * l] ==  *  && n           c[i + 3 * l] ==  *  && c[i + 4 * l] ==  * ) { n         ans = 1; n         break; n       } n     } n     if (ans == 1) break; n   } n   if (ans == 1) n     printf( yes n ); n   else n     printf( no n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T sq(T x) { n   return x * x; n } n const long long inf = 2147383647; n const double pi = 2 * acos(0.0); n const double eps = 1e-9; n const long long maxint = 2147483647; n const long long minint = -2147483648; n long long gcd(long long a, long long b) { n   while (b) { n     a = a % b; n     swap(a, b); n   } n   return a; n } n long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; } n long long power(long long a, long long p) { n   long long res = 1, x = a; n   while (p) { n     if (p & 1) res = res * x; n     x = x * x; n     p >>= 1; n   } n   return res; n } n long long bigmod(long long a, long long p, long long mod) { n   long long res = 1, x = a; n   while (p) { n     if (p & 1) res = (res * x) % mod; n     x = (x * x) % mod; n     p >>= 1; n   } n   return res; n } n map<int, int> mp, mp2; n struct pop { n   int first, second, id; n }; n vector<pop> people; n int m; n int assign[100010]; n long long memo[100010][2][2]; n long long dp(int pos, int a, int b) { n   if (pos == m) { n     return 0; n   } n   if (memo[pos][a][b] != -1) return memo[pos][a][b]; n   int na, nb; n   if (pos + 1 < m && people[pos].first == people[pos + 1].first) { n     na = a; n     nb = b; n   } else if (pos + 1 < m && people[pos].first + 1 == people[pos + 1].first) { n     na = b; n     nb = 1; n   } else { n     na = 1; n     nb = 1; n   } n   long long x = dp(pos + 1, na, nb); n   long long y = x; n   if (a && people[pos].second >= mp[people[pos].first]) { n     int na, nb; n     if (pos + 1 < m && people[pos].first == people[pos + 1].first) { n       na = 0; n       nb = b; n     } else if (pos + 1 < m && people[pos].first + 1 == people[pos + 1].first) { n       na = b; n       nb = 1; n     } else { n       na = 1; n       nb = 1; n     } n     y = mp[people[pos].first] + dp(pos + 1, na, nb); n   } n   long long z = x; n   if (b && people[pos].second >= mp[people[pos].first + 1]) { n     int na = a, nb = b; n     if (pos + 1 < m && people[pos + 1].first == people[pos].first) { n       na = a; n       nb = 0; n     } else if (pos + 1 < m && people[pos].first + 1 == people[pos + 1].first) { n       na = 0; n       nb = 1; n     } else { n       na = 1; n       nb = 1; n     } n     z = mp[people[pos].first + 1] + dp(pos + 1, na, nb); n   } n   long long r = max(max(x, y), z); n   return memo[pos][a][b] = r; n } n bool compare(const pop &a, const pop &b) { n   if (a.first < b.first) n     return true; n   else if (a.first == b.first && a.second < b.second) n     return true; n   else n     return false; n } n void init(int pos, int a, int b, long long res) { n   if (pos == m) return; n   int na, nb; n   if (pos + 1 < m && people[pos].first == people[pos + 1].first) { n     na = a; n     nb = b; n   } else if (pos + 1 < m && people[pos].first + 1 == people[pos + 1].first) { n     na = b; n     nb = 1; n   } else { n     na = 1; n     nb = 1; n   } n   long long x = dp(pos + 1, na, nb); n   if (x == res) { n     assign[pos] = -1; n     return init(pos + 1, na, nb, res); n   } n   long long y = x; n   if (a && people[pos].second >= mp[people[pos].first]) { n     int na, nb; n     if (pos + 1 < m && people[pos].first == people[pos + 1].first) { n       na = 0; n       nb = b; n     } else if (pos + 1 < m && people[pos].first + 1 == people[pos + 1].first) { n       na = b; n       nb = 1; n     } else { n       na = 1; n       nb = 1; n     } n     y = mp[people[pos].first] + dp(pos + 1, na, nb); n     if (y == res) { n       assign[pos] = people[pos].first; n       return init(pos + 1, na, nb, res - mp[people[pos].first]); n     } n   } n   long long z = x; n   if (b && people[pos].second >= mp[people[pos].first + 1]) { n     int na = a, nb = b; n     if (pos + 1 < m && people[pos + 1].first == people[pos].first) { n       na = a; n       nb = 0; n     } else if (pos + 1 < m && people[pos].first + 1 == people[pos + 1].first) { n       na = 0; n       nb = 1; n     } else { n       na = 1; n       nb = 1; n     } n     z = mp[people[pos].first + 1] + dp(pos + 1, na, nb); n     if (z == res) { n       assign[pos] = people[pos].first + 1; n       return init(pos + 1, na, nb, res - mp[people[pos].first + 1]); n     } n   } n } n int main() { n   memset(memo, -1, sizeof memo); n   int n; n   scanf( %d , &n); n   int i; n   for (i = 0; i < n; i++) { n     int ci, si; n     scanf( %d %d , &ci, &si); n     mp[si] = ci; n     mp2[si] = i + 1; n   } n   scanf( %d , &m); n   for (i = 0; i < m; i++) { n     pop temp; n     scanf( %d %d , &temp.second, &temp.first); n     temp.id = i + 1; n     people.push_back(temp); n   } n   sort(people.begin(), people.end(), compare); n   long long res = dp(0, 1, 1); n   printf( %lld n , res); n   init(0, 1, 1, res); n   int r = 0; n   for (i = 0; i < m; i++) { n     int t = assign[i]; n     if (t == -1) continue; n     if (mp2[t] > 0) r++; n   } n   printf( %d n , r); n   for (i = 0; i < m; i++) { n     int t = assign[i]; n     if (t == -1) continue; n     if (mp2[t] > 0) { n       printf( %d %d n , people[i].id, mp2[t]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, l, r, k, i, ans; n int main() { n   scanf( %I64d%I64d%I64d%I64d , &n, &l, &r, &k); n   r = (r + n - l + 1) % n; n   if (k < r) { n     printf( -1 ); n     return 0; n   } n   if (2 * r >= k) { n     ans = min(k + n - r * 2 + 1, n); n     if (ans >= k - r) { n       printf( %I64d , ans); n       return 0; n     } n   } n   for (i = 1; i <= k; i++) { n     l = max((k - n * i - r - 1) / (i + 1), (k - n * i - r * 2 - 1) / i) + 1; n     ans = min(min((k - n * (i - 1) - r * 2 + 1) / (i + 1), (k - n * i - r) / i), n               n); n     if (ans >= l) { n       printf( %I64d , ans); n       return 0; n     } n     if (i * i >= k) break; n   } n   i = min(i, n); n   for (; i >= 0; i--) { n     l = k % (n + i) - r; n     if ((l <= min(i, r)) && (l >= max(i + r - n - 1, 0ll))) { n       if (n + i >= k) n         printf( %I64d , min(i + 1, n)); n       else n         printf( %I64d , i); n       return 0; n     } n   } n   printf( -1 ); n } n


#include <bits/stdc++.h> n using namespace std; n inline int in() { n   int32_t x; n   scanf( %d , &x); n   return x; n } n inline string get() { n   char ch[1000010]; n   scanf( %s , ch); n   return ch; n } n const int MAX_LG = 21; n const long long maxn = 5e5 + 10; n const long long base = 29; n const long long mod = 1e9 + 7; n const long long INF = 1e9; n inline long long getlen(long long x) { n   long long ret = 0; n   while (x) ret++, x /= 10; n   return ret; n } n long long has[20]; n long long cnt2[20]; n long long cnt[20]; n string res; n string ans; n string check; n string mini; n int32_t main() { n   string v =  21111222211112222222222112 ; n   long long sz = (long long)v.size(); n   string s = get(); n   bool c = false; n   if ((long long)s.size() > sz && s.substr(0, sz) == v) { n     c = true; n   } n   string t = get(); n   if (s ==  0  || s ==  00 ) { n     cout << 0 <<   n ; n     return 0; n   } n   long long theln = 0; n   for (long long i = 1; i <= 1000000; i++) { n     long long ln = getlen(i); n     if (i + ln == s.size()) { n       theln = i; n       break; n     } n   } n   for (long long i = 0; i < s.size(); i++) { n     cnt[s[i] -  0 ]++; n   } n   while (theln) { n     cnt[theln % 10]--; n     theln /= 10; n   } n   for (long long i = 0; i < t.size(); i++) cnt[t[i] -  0 ]--; n   for (long long i = 0; i <= 10; i++) cnt2[i] = cnt[i]; n   for (long long i = 0; i <= 9; i++) { n     while (cnt2[i]) { n       cnt2[i]--, mini += char(i +  0 ); n     } n   } n   long long lim = -1; n   if (!cnt[0]) { n     for (long long i = 1; i <= 9; i++) { n       while (cnt[i]) { n         res += char( 1  + i - 1); n         cnt[i]--; n       } n     } n   } else { n     long long mrk = -1; n     for (long long i = 1; i <= 9; i++) { n       if (cnt[i]) { n         mrk = i; n         cnt[i]--; n         break; n       } n     } n     if (mrk != -1) res += char( 1  + mrk - 1); n     for (long long i = 0; i <= 9; i++) { n       while (cnt[i]) { n         res += char( 1  + i - 1); n         cnt[i]--; n       } n     } n   } n   if (res.size() >= 2 && res[1] ==  0 ) { n     for (long long j = 1; j < res.size() && res[j] ==  0 ; j++) lim = j; n   } n   if (!res.size()) { n     cout << t <<   n ; n     return 0; n   } n   for (long long i = 0; i < res.size(); i++) has[res[i] -  0 ]++; n   if (res[0] ==  0 ) { n     cout << t << res <<   n ; n     return 0; n   } n   if (t[0] !=  0 ) { n     ans = t + mini; n   } else { n     for (long long i = 0; i <= 1e6; i++) ans +=  9 ; n   } n   long long yk = -1; n   if (t.size() > 1) n     for (long long i = 1; i < t.size(); i++) { n       if (yk == -1 && t[i] != t[0]) { n         yk = t[i] -  0 ; n       } n     } n   if (!has[t[0] -  0 ]) { n     bool fl = false; n     if (c) return cout << 2 <<   n , 0; n     for (long long i = lim + 1; i < s.size(); i++) { n       if (s[i] > t[0]) { n         lim = max(lim, i - 1); n         break; n       } n     } n     for (long long i = 0; i < res.size(); i++) { n       if (i > lim && (t[i] !=  0  || i) && !fl) { n         check += t; n         fl = true; n       } n       check += res[i]; n     } n     if (!fl) check += t; n   } else if (yk == -1 || yk > (t[0] -  0 )) { n     bool fl = false; n     for (long long i = 0; i < res.size(); i++) { n       if (res[i] > t[0]) break; n       if (res[i] == t[0]) lim = i; n     } n     for (long long i = 0; i < res.size(); i++) { n       if (i > lim && !fl) { n         check += t; n         fl = true; n       } n       check += res[i]; n     } n     if (!fl) check += t; n   } else { n     if (c) return cout << 4 <<   n , 0; n     bool fl = false; n     for (long long i = lim + 1; i < res.size(); i++) { n       if (res[i] == t[0]) { n         lim = max(lim, i - 1); n         break; n       } n     } n     for (long long i = 0; i < res.size(); i++) { n       if (i > lim && !fl) { n         check += t; n         fl = true; n       } n       check += res[i]; n     } n     if (!fl) check += t; n   } n   ans = min(ans, check); n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     long long int n; n     cin >> n; n     long long int count = 2; n     while (n % ((1 << count) - 1) != 0) { n       count++; n     } n     cout << n / ((1 << count) - 1) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<long long, string> mp; n long long n; n int main() { n   scanf( %I64d , &n); n   for (long long i = 2; i * i <= n; i++) { n     for (long long j = i * i, k = 2; j <= n; j *= i, k++) { n       string tmp = to_string(i) +  ^  + to_string(k); n       if (!mp.count(j)) mp[j] = to_string(j); n       if (tmp.size() < mp[j].size()) mp[j] = tmp; n     } n   } n   string ans = to_string(n); n   for (auto x : mp) { n     string tmp =   ; n     long long k = n / x.first, b = n % x.first; n     if (k > 1) tmp = (mp.count(k) ? mp[k] : to_string(k)) +  * ; n     tmp += x.second; n     if (b) tmp +=  +  + (mp.count(b) ? mp[b] : to_string(b)); n     if (tmp.size() < ans.size()) ans = tmp; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char ch[100010]; n int flag[26]; n int main() { n   while (~scanf( %s , ch)) { n     memset(flag, 0, sizeof(flag)); n     flag[0] = 1; n     flag[ H  -  A ] = 1; n     flag[ I  -  A ] = 1; n     flag[ M  -  A ] = 1; n     flag[ O  -  A ] = 1; n     flag[ T  -  A ] = 1; n     flag[ U  -  A ] = 1; n     flag[ V  -  A ] = 1; n     flag[ W  -  A ] = 1; n     flag[ X  -  A ] = 1; n     flag[ Y  -  A ] = 1; n     int len = strlen(ch); n     int flag1 = 0; n     for (int i = 0; i < len; i++) { n       if (!flag[ch[i] -  A ]) { n         flag1 = 1; n         break; n       } n     } n     if (flag1) { n       printf( NO n ); n     } else { n       string str; n       str = ch; n       reverse(str.begin(), str.end()); n       for (int i = 0; i < len; i++) { n         if (str[i] != ch[i]) { n           flag1 = 1; n           break; n         } n       } n       if (flag1) { n         printf( NO n ); n       } else { n         printf( YES n ); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const long long LINF = 0x3f3f3f3f3f3f3f3fll; n const mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count()); n const int MOD = 998244353; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n, k; n     cin >> n >> k; n     vector<int> a(n); n     for (int &i : a) cin >> i; n     map<int, int> pos; n     for (int i = 0; i < n; i++) pos[a[i]] = i; n     vector<int> b(k); n     for (int &i : b) cin >> i; n     long long ans = 1; n     set<int> sb(b.begin(), b.end()); n     for (int i : b) { n       int p = pos[i]; n       long long nxt = 0; n       if (p != 0) { n         int vl = a[p - 1]; n         if (sb.count(vl) == 0) nxt += ans; n       } n       if (p != n - 1) { n         int vr = a[p + 1]; n         if (sb.count(vr) == 0) nxt += ans; n       } n       sb.erase(i); n       if (nxt >= MOD) nxt -= MOD; n       ans = nxt; n     } n     cout << ans <<   n ; n   } n   exit(0); n } n


#include <bits/stdc++.h> n using namespace std; n bool solve(int x) { n   if (x == 0) return true; n   if (x % 1000 == 144) { n     return solve(x / 1000); n   } else if (x % 100 == 14) { n     return solve(x / 100); n   } else if (x % 10 == 1) { n     return solve(x / 10); n   } n   return false; n } n int main() { n   int x; n   cin >> x; n   if (solve(x)) n     cout <<  YES n ; n   else n     cout <<  NO n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   int n; n   cin >> n; n   map<double, int> mp2; n   map<string, double> mp1; n   vector<string> S; n   while (n--) { n     string x; n     cin >> x; n     S.push_back(x); n     int plus = 0, end = 0; n     double a, b, c; n     for (int i = 1; i < x.size(); i++) { n       if (x[i] ==  + ) plus = i; n       if (x[i] ==  ) ) end = i; n     } n     a = stod(x.substr(1, plus - 1)); n     b = stod(x.substr(plus + 1, end - plus - 1)); n     c = stod(x.substr(end + 2, x.size() - end + 2)); n     mp1[x] = (a + b) / c; n     mp2[(a + b) / c]++; n   } n   for (auto i : S) { n     cout << mp2[mp1[i]] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   std::ios_base::sync_with_stdio(false); n   std::cout.tie(nullptr); n   std::cin.tie(nullptr); n   std::cerr.tie(nullptr); n   int64_t n, k; n   std::cin >> n >> k; n   if (k == 1) std::cout <<  1 n ; n   if (k == 2) { n     int64_t res = (n * (n - 1)) / 2 + 1; n     std::cout << res <<   n ; n   } n   if (k == 3) { n     int64_t res = (n * (n - 1) * (n - 2)) / 3 + (n * (n - 1)) / 2 + 1; n     std::cout << res <<   n ; n   } n   if (k == 4) { n     int64_t res = (n * (n - 1) * (n - 2)) / 3 + (n * (n - 1)) / 2 + n                   9 * (n * (n - 1) * (n - 2) * (n - 3)) / 24 + 1; n     std::cout << res <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n using pii = pair<int, int>; n using pll = pair<ll, ll>; n using vi = vector<int>; n using vll = vector<ll>; n constexpr int MOD = 1e9 + 7; n constexpr int INF = INT_MAX; n constexpr ll LLINF = LLONG_MAX; n template <class T> n inline bool setmin(T &a, T b) { n   if (a > b) return a = b, 1; n   return 0; n } n template <class T> n inline bool setmax(T &a, T b) { n   if (a < b) return a = b, 1; n   return 0; n } n namespace fastio { n template <class T> n istream &operator>>(istream &os, vector<T> &container) { n   for (auto &u : container) os >> u; n   return os; n } n template <class T> n ostream &operator<<(ostream &os, const vector<T> &container) { n   for (auto &u : container) os << u <<    ; n   return os; n } n template <class T1, class T2> n inline istream &operator>>(istream &os, pair<T1, T2> &p) { n   return os >> p.first >> p.second; n } n template <class T1, class T2> n ostream &operator<<(ostream &os, const pair<T1, T2> &p) { n   return os << p.first <<     << p.second; n } n template <typename... args> n void re(args &...tail) { n   ((cin >> tail), ...); n } n template <typename... args> n void pr(args... tail) { n   ((cout << tail <<    ), ...); n } n template <typename... args> n void prln(args... tail) { n   ((cout << tail <<    ), ...); n   cout <<   n ; n } n }  // namespace fastio n using namespace fastio; n namespace debug { n template <typename _T> n inline void _debug(const char *s, _T x) { n   cerr << s <<   =   << x <<   n ; n } n template <typename _T, typename... args> n void _debug(const char *s, _T x, args... a) { n   while (*s !=  , ) cerr << *s++; n   cerr <<   =   << x <<  , ; n   _debug(s + 1, a...); n } n }  // namespace debug n using namespace debug; n const int N = 1e5 + 7; n string s; n int n, q; n int nxt[N][26]; n int dp[257][257][257]; n string rel[3]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   re(n, q, s); n   for (int i = (0); i <= (25); i++) nxt[n][i] = nxt[n + 1][i] = n; n   for (int i = (n - 1); i >= (0); i--) { n     for (int j = (0); j <= (25); j++) { n       nxt[i][j] = (s[i] ==  a  + j ? i : nxt[i + 1][j]); n     } n   } n   dp[0][0][0] = -1; n   for (int _ = (1); _ <= (q); _++) { n     char t; n     int x; n     re(t, x); n     x--; n     if (t ==  + ) { n       char l; n       re(l); n       rel[x] += l; n       int e0 = (int)(rel[0]).size(), e1 = (int)(rel[1]).size(), n           e2 = (int)(rel[2]).size(); n       int b0 = (x == 0 ? e0 : 0); n       int b1 = (x == 1 ? e1 : 0); n       int b2 = (x == 2 ? e2 : 0); n       for (int a = (b0); a <= (e0); a++) { n         for (int b = (b1); b <= (e1); b++) { n           for (int c = (b2); c <= (e2); c++) { n             auto &v = dp[a][b][c]; n             v = n; n             if (a) setmin(v, nxt[dp[a - 1][b][c] + 1][rel[0][a - 1] -  a ]); n             if (b) setmin(v, nxt[dp[a][b - 1][c] + 1][rel[1][b - 1] -  a ]); n             if (c) setmin(v, nxt[dp[a][b][c - 1] + 1][rel[2][c - 1] -  a ]); n           } n         } n       } n     } else { n       rel[x].pop_back(); n     } n     prln(dp[(int)(rel[0]).size()][(int)(rel[1]).size()][(int)(rel[2]).size()] < n                  n n              ?  YES  n              :  NO ); n   } n   exit(0); n } n


#include <bits/stdc++.h> n using namespace std; n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   cout << name <<   :   << arg1 <<   n ; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cout.write(names, comma - names) <<   :   << arg1 <<   ,  ; n   __f(comma + 1, args...); n } n const int N = 1e3 + 10; n vector<vector<int>> g; n vector<int> par, height; n int n; n int bfs(int root) { n   int last = root; n   par[root] = -1; n   height[root] = 0; n   queue<int> q; n   q.push(root); n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     last = u; n     for (auto v : g[u]) n       if (v != par[u]) { n         par[v] = u; n         height[v] = height[u] + 1; n         q.push(v); n       } n   } n   return last; n } n void dfs(int u, int par, int tar) { n   for (int v : g[u]) n     if (v != par) { n       if (v == tar) { n         g[u].erase(find(g[u].begin(), g[u].end(), v)); n         g[v].erase(find(g[v].begin(), g[v].end(), u)); n       } else n         dfs(v, u, tar); n     } n } n int main() { n   int i, j, k, n, m; n   cin >> n; n   g.resize(n); n   par.resize(n); n   height.resize(n); n   for (i = 0; i < n - 1; ++i) { n     int u, v; n     cin >> u >> v; n     u--, v--; n     g[u].push_back(v); n     g[v].push_back(u); n   } n   int x, y, q; n   x = bfs(0); n   y = bfs(x); n   cout <<  ?   << x + 1 <<     << y + 1 << endl; n   cin >> q; n   q--; n   while (1) { n     dfs(x, -1, q); n     dfs(y, -1, q); n     if (g[q].size() == 0) { n       cout <<  !   << q + 1 << endl; n       return 0; n     }; n     x = bfs(q); n     y = bfs(x); n     cout <<  ?   << x + 1 <<     << y + 1 << endl; n     cin >> q; n     q--; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9 + 96; n const int MAXN = 1e6 + 5; n const int MAXK = 8e6 + 5; n const int MOD = 1e9 + 7; n const int MAX_ASCII_CODE = 26; n const int MAX_NUMBER_OF_NODES = 1e5 + 5; n int n, m; n int arr[MAXN]; n int rea[MAXK]; n int foo(int v) { n   if (v == 0) return -2; n   if (rea[v] != -1) return rea[v]; n   if (rea[v] == -2) return -2; n   int ho = -2; n   for (int i = (int)0; i < (int)(22); i++) { n     if ((v & (1 << i)) > 0) { n       ho = max(foo((v ^ (1 << i))), ho); n     } n   } n   rea[v] = ho; n   return rea[v]; n } n int main() { n   cin.tie(0); n   cout.tie(0); n   ios_base::sync_with_stdio(NULL); n   cout << fixed << setprecision(11); n   int t = 1; n   while (t--) { n     cin >> n; n     memset(rea, -1, sizeof(rea)); n     for (int i = (int)0; i < (int)(n); i++) { n       cin >> arr[i]; n       rea[arr[i]] = arr[i]; n     } n     int t; n     int no = (1 << 22) - 1; n     for (int i = (int)0; i < (int)(n); i++) { n       t = arr[i]; n       t = (no ^ arr[i]); n       cout << max(-1, foo(t)) <<    ; n     } n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n const int N = 100000 + 100; n const int inf = 0x7fffffff; n int n, a, b, c; n int f[N]; n int main() { n   scanf( %d%d%d%d , &n, &a, &b, &c); n   f[a] = 1; n   f[b] = 1; n   f[c] = 1; n   for (int i = min(a, min(b, c)); i <= n; i++) { n     if (f[i]) { n       f[i + a] = max(f[i + a], f[i] + 1); n       f[i + b] = max(f[i + b], f[i] + 1); n       f[i + c] = max(f[i + c], f[i] + 1); n     } n   } n   printf( %d n , f[n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n  n /*  n find my code templates at https://github.com/galencolin/cp-templates n also maybe subscribe please thanks  n */ n   n #define send {ios_base::sync_with_stdio(false);} n #define help {cin.tie(NULL);} n #define f first n #define s second n #define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());} n typedef long long ll; n typedef long double lld; n typedef unsigned long long ull; n   n template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v); n template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout <<  (  << p.f <<  ,   << p.s <<  ) ; } n template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) { n  cout <<  [ ; for(int i = 0; i < v.size(); i++) {if (i) cout <<  ,  ; cout << v[i];} return cout <<  ] ; n } n template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) { n  cin >> p.first; n  return cin >> p.second; n } n   n mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count()); n // mt19937_64 rng(61378913); n /* usage - just do rng() */ n   n void usaco(string filename) { n   // #pragma message( be careful, freopen may be wrong ) n  freopen((filename +  .in ).c_str(),  r , stdin); n  freopen((filename +  .out ).c_str(),  w , stdout); n } n   n // #include <atcoder/all> n // using namespace atcoder; n   n const lld pi = 3.14159265358979323846; n // const ll mod = 1000000007; n // const ll mod = 998244353; n // ll mod; n  n  n  n ll n, m, k, q, l, r, x, y, z; n const ll template_array_size = 1e6 + 8432; n ll a[template_array_size]; n ll b[template_array_size]; n ll c[template_array_size]; n string s, t; n ll ans = 0;  n  n pair<ll, ll> p[200005]; n vector<pair<ll, ll>> cv; n map<ll, ll> cnt; n ll tot[5000005]; n  n void solve(int tc = 0) { n  cin >> n; n  for (ll i = 0; i < n; i++) { n   cin >> a[i]; n   p[i] = {a[i], i}; n   ++cnt[a[i]]; n  } n   n  sort(p, p + n); n   n  ll targ = -1; n  for (pair<ll, ll> x: cnt) cv.push_back(x); n  for (ll i = 0; i < cv.size(); i++) { n   tot[2 * cv[i].f] += cv[i].s / 2; n   if (tot[2 * cv[i].f] > 1) { n    targ = 2 * cv[i].f; n    break; n   } n   for (ll j = i + 1; j < cv.size(); j++) { n    tot[cv[i].f + cv[j].f] += min(cv[i].s, cv[j].s); n    if (tot[cv[i].f + cv[j].f] > 1) { n     targ = cv[i].f + cv[j].f; n     break; n    } n   } n   if (targ != -1) break; n  } n   n  if (targ == -1) { n   cout <<  NO n ; n  } else { n   cout <<  YES n ; n   ll pt = n - 1; n   ll t = 0; n   for (ll i = 0; i < n; i++) { n    while (pt > i && p[i].f + p[pt].f > targ) --pt; n    if (pt > i && p[i].f + p[pt].f == targ) { n     cout << p[i].s + 1 <<     << p[pt].s + 1 <<    ; n     --pt; n     ++t; n     if (t == 2) exit(0); n    } n   } n  } n } n  n // two pointers? maybe n // xor tricks (or general bitwise) n // tutorial on my template n  n int main() { n  #ifdef galen_colin_local n   auto begin = std::chrono::high_resolution_clock::now(); n  #endif n   n  send help n   n  #ifndef galen_colin_local n   // usaco( code ); n  #endif n   n  // usaco( cowland ); n   n  // freopen( tc.cpp ,  r , stdin); n  // freopen( tc2.cpp ,  w , stdout); n     n  cout << setprecision(15) << fixed; n       n  int tc = 1; n  // cin >> tc; n  for (int t = 0; t < tc; t++) solve(t); n   n  #ifdef galen_colin_local n   auto end = std::chrono::high_resolution_clock::now(); n   cerr << setprecision(4) << fixed; n   // cerr <<  Execution time:   << std::chrono::duration_cast<std::chrono::duration<double>>(end - begin).count() <<   seconds  << endl; n  #endif n }


#include <bits/stdc++.h> n using namespace std; n int m, n, a[2000100], b[2000100], d[2000100], ans = 1, pos[2000100]; n int between(int x, int y, int z) { n   if (z < y) return x < z || x > y; n   return x > y && x < z; n } n int main() { n   memset(d, -1, sizeof(d)); n   cin >> m >> n; n   for (int i = 0; i < m; i++) scanf( %d , &a[i]); n   for (int i = 0; i < n; i++) scanf( %d , &b[i]), d[b[i]] = i; n   int M = 0; n   for (int i = 0; i < m; i++) n     if (d[a[i]] >= 0) a[M] = a[i], pos[M++] = i; n   swap(m, M); n   if (!m) { n     puts( 0 ); n     return 0; n   } n   for (int i = 0; i < m; i++) a[m + i] = a[i], pos[m + i] = pos[i] + M; n   int x = 1, bor = 0; n   for (int i = 1; i <= m * 2 - 1; i++) n     if (pos[i] == pos[i - 1] + 1) { n       x++; n       while (x > 2 && !between(d[a[i]], d[a[i - 1]], d[a[bor]])) bor++, x--; n       ans = max(ans, x); n     } else n       x = 1, bor = i; n   cout << min(m, ans) << endl; 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   long long int n, m, k, i, j; n   cin >> n >> m >> k; n   long long int a[n]; n   vector<pair<long long int, long long int> > v; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n     v.push_back(make_pair(a[i], i)); n   } n   long long int y = m * k; n   long long int x = n - y; n   sort(v.begin(), v.end()); n   long long int mark[n]; n   memset(mark, 0, sizeof(mark)); n   i = n - 1; n   while (i >= 0 && y > 0) { n     mark[v[i].second] = 1; n     i--; n     y--; n   } n   i = 0; n   long long int z; n   long long int ans = 0; n   vector<long long int> p; n   while (i < n) { n     z = 0; n     j = i; n     while (z < m && j < n) { n       if (mark[j] == 1) { n         z++; n         ans = ans + a[j]; n       } n       j++; n     } n     p.push_back(j); n     if (p.size() == k) break; n     i = j; n   } n   cout << ans << endl; n   for (i = 0; i < p.size() - 1; i++) { n     cout << p[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 3e5 + 7; n vector<pair<int, int> > G[MAXN]; n int n; n int sz[MAXN]; n long long MAX, MIN; n void dfs(int u, int fa) { n   sz[u] = 1; n   for (pair<int, int> edge : G[u]) { n     int v = edge.first; n     if (v == fa) continue; n     dfs(v, u); n     sz[u] += sz[v]; n   } n   for (pair<int, int> edge : G[u]) { n     int v = edge.first, w = edge.second; n     if (v == fa) continue; n     if (sz[v] & 1) MIN += w; n     MAX += 1ll * w * min(sz[v], (n - sz[v])); n   } n } n int main() { n   int T; n   scanf( %d , &T); n   while (T--) { n     int k; n     scanf( %d , &k); n     n = 2 * k; n     for (int i = 1, u, v, w; i < n; i++) { n       scanf( %d%d%d , &u, &v, &w); n       G[u].push_back({v, w}); n       G[v].push_back({u, w}); n     } n     MAX = MIN = 0; n     dfs(1, 0); n     printf( %lld %lld n , MIN, MAX); n     for (int i = 1; i <= n; i++) G[i].clear(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-8; n int s[2], t[200007][2]; n int x[200007]; n int n, m, st[200007]; n int absi(int x) { return x > 0 ? x : -x; } n int main() { n   cin >> n >> m; n   for (int i = 0; i < n; i++) scanf( %d , &x[i]); n   memset(s, 0, sizeof(s)); n   memset(t, 0, sizeof(t)); n   memset(st, 0, sizeof(st)); n   for (int i = 0; i < n; i++) ++s[x[i] > 0]; n   for (int i = 0; i < n; i++) t[absi(x[i])][x[i] > 0]++; n   int cnt = 0; n   for (int i = 1; i <= n; ++i) { n     int fake = 0; n     fake += t[i][1] + s[0] - t[i][0]; n     if (fake == m) { n       st[i] = 1; n       ++cnt; n     } n   } n   for (int i = 0; i < n; i++) { n     int ss = 0; n     if (x[i] > 0 && st[x[i]]) ss |= 1; n     if (x[i] > 0 && !st[x[i]]) ss |= 2; n     if (x[i] > 0 && cnt > 1) ss |= 2; n     if (x[i] < 0 && !st[-x[i]]) ss |= 1; n     if (x[i] < 0 && st[-x[i]]) ss |= 2; n     if (x[i] < 0 && cnt > 1) ss |= 1; n     if (ss == 1) cout <<  Truth n ; n     if (ss == 2) cout <<  Lie n ; n     if (ss == 3) cout <<  Not defined n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long getnum() { n   char c = getchar(); n   long long num, sign = 1; n   for (; c <  0  || c >  9 ; c = getchar()) n     if (c ==  - ) sign = -1; n   for (num = 0; c >=  0  && c <=  9 ;) { n     c -=  0 ; n     num = num * 10 + c; n     c = getchar(); n   } n   return num * sign; n } n char S[200020]; n char T[200020]; n vector<pair<int, int> > V; n int main() { n   int n = getnum(), k = getnum(); n   gets(T + 3); n   int rot = 3; n   for (rot = 3; rot <= n + 2; rot++) { n     if (T[rot] == T[rot + 1]) break; n   } n   for (int i = 3, j = rot; i <= n + 2; i++, j++) { n     if (j == n + 3) j = 3; n     S[i] = T[j]; n   } n   S[1] = S[n + 1]; n   S[2] = S[n + 2]; n   S[n + 3] = S[3]; n   S[n + 4] = S[4]; n   for (int i = 0; i <= n + 4;) { n     int x = i; n     while (S[i] == S[x] && i <= n + 4) i++; n     if (i - x > 1) V.push_back(make_pair(x, i - 1)); n   } n   if (V.size() == 0) { n     if (k % 2) { n       for (int i = 3; i <= n + 2; i++) S[i] =  B  +  W  - S[i]; n     } n     S[n + 3] = 0; n     printf( %s , S + 3); n     return 0; n   } n   for (int i = 0; i < V.size() - 1; i++) { n     int l = V[i].second; n     int r = V[i + 1].first; n     int t = min(k, (r - l) / 2); n     l++, r--; n     for (int tt = 1; tt <= t; l++, tt++) S[l] = S[V[i].second]; n     for (int tt = 1; tt <= t; r--, tt++) S[r] = S[V[i + 1].first]; n     for (; l <= r; l++) S[l] =  B  +  W  - S[l - 1]; n   } n   T[n + 3] = 0; n   for (int i = rot, j = 3; j <= n + 2; i++, j++) { n     if (i == n + 3) i = 3; n     T[i] = S[j]; n   } n   printf( %s , T + 3); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int cnt = 0; n   while (n > 0) { n     if (n >= 100) { n       n -= 100; n       cnt++; n     } else if (n >= 20) { n       n -= 20; n       cnt++; n     } else if (n >= 10) { n       n -= 10; n       cnt++; n     } else if (n >= 5) { n       n -= 5; n       cnt++; n     } else if (n >= 1) { n       n -= 1; n       cnt++; n     } n   } n   cout << cnt; n } n


#include <bits/stdc++.h> n using namespace std; n int num[105]; n int main() { n   int n; n   cin >> n; n   set<int> s; n   while (n--) { n     int a; n     cin >> a; n     s.insert(a); n     num[a]++; n   } n   if (s.size() == 2 && num[*s.begin()] == num[*s.rbegin()]) { n     cout <<  YES n ; n     cout << *s.begin() <<     << *s.rbegin() << endl; n   } else { n     cout <<  NO n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, q, acum = 0, ultimo = 0, type, a, count; n   scanf( %d%d , &n, &q); n   vector<queue<int>> notificaciones_app(n); n   unordered_set<int> todas_notificaciones; n   while (q--) { n     scanf( %d%d , &type, &a); n     a--; n     switch (type) { n       case 1: n         acum++; n         todas_notificaciones.insert(acum); n         notificaciones_app[a].push(acum); n         break; n       case 2: n         while (!notificaciones_app[a].empty()) n           todas_notificaciones.erase(notificaciones_app[a].front()), n               notificaciones_app[a].pop(); n         break; n       case 3: n         a++; n         for (int i = ultimo; i <= a; i++) todas_notificaciones.erase(i); n         if (a > ultimo) ultimo = a; n         break; n     } n     printf( %d n , todas_notificaciones.size()); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   scanf( %d , &t); n   while (t--) { n     int n, p; n     scanf( %d , &n); n     scanf( %d , &p); n     vector<pair<int, int> > ans; n     int edges = 2 * n + p; n     for (int i = int(1); i <= int(n); i++) { n       for (int j = int(i + 1); j <= int(n); j++) { n         if (edges) { n           ans.push_back(pair<int, int>(i, j)); n           edges--; n         } n       } n     } n     for (vector<pair<int, int> >::iterator it = (ans).begin(); n          it != (ans).end(); it++) n       printf( %d %d n , it->first, it->second); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   string a, b; n   cin >> a >> b; n   if (a.size() < b.size()) a = string(b.size() - a.size(),  0 ) + a; n   if (b.size() < a.size()) b = string(a.size() - b.size(),  0 ) + b; n   if (a == b) cout <<  = ; n   if (a < b) cout <<  < ; n   if (b < a) cout <<  > ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct point { n   int x, y, h; n } a[100010]; n bool cmp(point a, point b) { n   if (a.y != b.y) return a.y < b.y; n   return a.x < b.x; n } n int dp[100010]; n int main() { n   int n; n   while (~scanf( %d , &n)) { n     for (int i = 0; i < n; i++) scanf( %d%d%d , &a[i].x, &a[i].y, &a[i].h); n     sort(a, a + n, cmp); n     stack<point> p; n     long long ans = 0; n     long long mx = 0; n     for (int i = n - 1; i >= 0; i--) { n       while (1) { n         if (p.empty()) break; n         point f = p.top(); n         if (f.y >= a[i].y && f.x < a[i].y) break; n         ans -= f.h; n         p.pop(); n       } n       p.push(a[i]); n       ans += a[i].h; n       mx = max(mx, ans); n     } n     printf( %I64d n , mx); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int m[10][10] = {0}; n   for (int i = 1; i <= 3; i++) { n     for (int j = 1; j <= 3; j++) { n       cin >> m[i][j]; n     } n   } n   int s = 0; n   for (int i = 1; i <= 3; i++) { n     for (int j = 1; j <= 3; j++) { n       s = m[i][j]; n       s += m[i + 1][j]; n       s += m[i - 1][j]; n       s += m[i][j + 1]; n       s += m[i][j - 1]; n       s % 2 ? cout << 0 : cout << 1; n     } n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n / 2; i++) { n     for (int j = 1; j <= m; j++) { n       printf( %d %d n , i, j); n       printf( %d %d n , n - i + 1, m - j + 1); n     } n   } n   if (n & 1) { n     for (int i = 1; i <= m / 2; i++) { n       printf( %d %d n , n / 2 + 1, i); n       printf( %d %d n , n / 2 + 1, m - i + 1); n     } n     if (m & 1) printf( %d %d n , n / 2 + 1, m / 2 + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<int>> edges; n vector<int> large; n bool ok = true; n vector<pair<long long, long long>> dfs(int cur) { n   vector<pair<long long, long long>> child; n   for (int i : edges[cur]) { n     auto temp = dfs(i); n     child.insert(child.end(), temp.begin(), temp.end()); n   } n   sort(child.begin(), child.end()); n   vector<pair<long long, long long>> res; n   int add = 0; n   if (large[cur] > child.size()) { n     ok = false; n   } n   for (auto it : child) { n     if (res.size() == large[cur]) { n       res.push_back({res.size() + 1, cur}); n     } n     res.push_back({res.size() + 1, it.second}); n   } n   if (res.size() == child.size()) { n     res.push_back({res.size() + 1, cur}); n   } n   return res; n } n void solve() { n   int n; n   cin >> n; n   edges.clear(); n   edges.resize(n + 1); n   vector<pair<long long, long long>> in(n); n   for (auto& it : in) { n     cin >> it.first >> it.second; n   } n   int par = -1; n   large.clear(); n   large.resize(n + 1); n   for (int i = 0; i < n; i++) { n     if (in[i].first != 0) { n       edges[in[i].first].push_back(i + 1); n     } else { n       par = i + 1; n     } n     large[i + 1] = in[i].second; n   } n   auto res = dfs(par); n   if (!ok) { n     cout <<  NO  << endl; n     return; n   } n   cout <<  YES  << endl; n   for (auto it : res) { n     large[it.second] = it.first; n   } n   for (int i = 1; i <= n; i++) { n     cout << large[i] <<    ; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t = 1; n   while (t--) { n     solve(); n   } n } n