#include <bits/stdc++.h> n using namespace std; n const double E = 1e-10; n const int inf = (int)1e9; n const int maxn = 1010; n int LIM = 60 * 12; n int a[maxn]; n int b[maxn], bc = 0; n int t[maxn]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %d , a + i); n   sort(a, a + n); n   int sum = 10; n   for (int i = 0; i < n; i++) { n     if (sum + a[i] > LIM) break; n     sum += a[i]; n     b[bc++] = a[i]; n   } n   t[0] = 10; n   for (int i = 0; i < bc; i++) t[i + 1] = t[i] + b[i]; n   int res = 0; n   for (int i = 0; i <= bc; i++) n     if (t[i] > LIM / 2) res += t[i] - (LIM / 2); n   printf( %d %d n , bc, res); n   return 0; n } n


#include <bits/stdc++.h> n #include <unordered_map> n #include <unordered_set> n using namespace std; n #define endl   n  n #define ll long long n #define sz(s) (int)(s.size()) n #define INF 0x3f3f3f3f3f3f3f3fLL n #define all(v) v.begin(),v.end() n #define watch(x) cout<<(#x)<<  =  <<x<<endl n const int dr[] { -1, -1, 0, 1, 1, 1, 0, -1 }; n const int dc[] { 0, 1, 1, 1, 0, -1, -1, -1 }; n #if __cplusplus >= 201402L n template<typename T> n vector<T> create(size_t n) { n  return vector<T>(n); n } n template<typename T, typename ... Args> n auto create(size_t n, Args ... args) { n  return vector<decltype(create<T>(args...))>(n, create<T>(args...)); n } n #endif n void run() { n  ios::sync_with_stdio(false); n  cin.tie(NULL); n  cout.tie(NULL); n #ifndef ONLINE_JUDGE n  freopen( input.in ,  r , stdin); n #else n  //freopen( groups.in ,  r , stdin); n #endif n } n const int N = 1e5 + 9; n int l[N], r[N]; n ll dp[N][2]; n vector<vector<int>> adj; n ll dfs(int node, int par, bool b) { n  ll &rt = dp[node][b]; n  if (~rt) n   return rt; n  rt = 0; n  int myVal = (b ? r[node] : l[node]); n  for (int ch : adj[node]) n   if (ch != par) n    rt += max(dfs(ch, node, 0) + abs(l[ch] - myVal), n      dfs(ch, node, 1) + abs(r[ch] - myVal)); n  return rt; n } n  n int main() { n  run(); n  int T; n  cin >> T; n  while (T--) { n   int n; n   cin >> n; n   memset(dp, -1, (sizeof dp[0]) * (n + 1)); n   for (int i = 1; i <= n; i++) n    cin >> l[i] >> r[i]; n   adj = vector<vector<int>>(n + 1); n   for (int i = 1; i < n; i++) { n    int u, v; n    cin >> u >> v; n    adj[u].push_back(v); n    adj[v].push_back(u); n   } n   cout << max(dfs(1, -1, 0), dfs(1, -1, 1)) << endl; n  } n } n


#include <bits/stdc++.h> n using namespace std; n long n, k; n long ans[1000010]; n int main() { n   cin >> n >> k; n   if ((k > n) || ((k <= n) && (k == 1) && (n != 1))) { n     cout <<  -1  << endl; n     return 0; n   } n   if ((n == 1) && (k == 1)) { n     cout <<  a  << endl; n     return 0; n   } n   if (!(n & 1)) { n     ans[1] = 97; n     ans[2] = 98; n     long c(96 + k); n     for (long i = n; i >= n - (k - 2) + 1; --i) ans[i] = c--; n     cout <<  ab ; n     for (long i = 1; i <= ((n - k) / 2); ++i) cout <<  ab ; n     if (k & 1) cout <<  a ; n     for (long i = (n - (k - 2) + 1); i <= n; ++i) cout << char(ans[i]); n     cout << endl; n   } else { n     ans[1] = 97; n     ans[2] = 98; n     long c(96 + k); n     for (long i = n; i >= n - (k - 2) + 1; --i) ans[i] = c--; n     cout <<  ab ; n     for (long i = 1; i <= ((n - k) / 2); ++i) cout <<  ab ; n     if (!(k & 1)) cout <<  a ; n     for (long i = (n - (k - 2) + 1); i <= n; ++i) cout << char(ans[i]); n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int x[110], y[110], n, epsilon, k; n double dist[110], p[110], mem[110][110]; n double solve(int idx, int k) { n   if (k == 0) return 1; n   if (idx == n) return 0; n   double& res = mem[idx][k]; n   if (res != -1) return res; n   res = p[idx] * solve(idx + 1, k - 1); n   res += (1 - p[idx]) * solve(idx + 1, k); n   return res; n } n bool binary(double r) { n   for (int i = 0; i < n; i++) { n     if (dist[i] <= r) n       p[i] = 1; n     else n       p[i] = exp(1 - dist[i] * dist[i] / (r * r)); n   } n   for (int i = 0; i < n + 1; i++) n     for (int j = 0; j < k + 1; j++) mem[i][j] = -1; n   double res = solve(0, k); n   return ((1 - res) * 1000 <= epsilon); n } n int main() { n   ios::sync_with_stdio(false); n   int x0, y0; n   cin >> n >> k >> epsilon; n   cin >> x0 >> y0; n   for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; n   for (int i = 0; i < n; i++) dist[i] = hypot(x[i] - x0, y[i] - y0); n   double mid, low = 0, high = 1000000; n   while (abs(low - high) > 1e-9) { n     mid = (low + high) / 2; n     if (binary(mid)) n       high = mid; n     else n       low = mid; n   } n   printf( %.15lf n , (low + high) / 2); n   return 0; n } n


#include <bits/stdc++.h> n const long long int MAX = 1e12; n using namespace std; n const int alpha = 26; n void solve() { n   int n; n   cin >> n; n   vector<int> arr(n); n   for (auto &it : arr) cin >> it; n   for (int i = 0; i < n; i++) { n     while (arr[i] % 2 == 0) arr[i] /= 2; n     while (arr[i] % 3 == 0) arr[i] /= 3; n   } n   if (count(arr.begin(), arr.end(), arr[0]) == n) n     cout <<  YES ; n   else n     cout <<  NO ; n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<string> ans; n string f =  1 ; n bool sort2(string &a, string &b) { n   if (a.size() == b.size()) { n     return a < b; n   } n   return a.size() < b.size(); n } n void calc(string s) { n   if (s.size() >= 11) { n     return; n   } n   ans.push_back(s); n   s +=  1 ; n   calc(s); n   s.pop_back(); n   s +=  0 ; n   calc(s); n   s.pop_back(); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   string l = to_string(n); n   calc(f); n   int ans2 = 0; n   sort(ans.begin(), ans.end(), sort2); n   for (int i = 0; i < ans.size(); i++) { n     if (ans[i].size() > l.size()) { n       break; n     } else if (ans[i].size() == l.size()) { n       if (l >= ans[i]) { n         ans2++; n       } else { n         break; n       } n     } else { n       ans2++; n     } n   } n   cout << ans2 <<   n ; n } n


#include <bits/stdc++.h> n int n, cnt; n char ch[100005], tmp; n int main() { n   scanf( %d , &n); n   scanf( %s , ch + 1); n   for (int i = 1; i <= n; i++) n     if (ch[i] != tmp) { n       if (tmp != 0) { n         if ((tmp ==  o  || tmp ==  e ) && cnt == 2) n           printf( %c%c , tmp, tmp); n         else { n           if (tmp ==  a  || tmp ==  e  || tmp ==  i  || tmp ==  o  || n               tmp ==  u  || tmp ==  y ) n             printf( %c , tmp); n           else n             for (int j = 1; j <= cnt; j++) putchar(tmp); n         } n       } n       tmp = ch[i]; n       cnt = 1; n     } else n       cnt++; n   if ((tmp ==  o  || tmp ==  e ) && cnt == 2) n     printf( %c%c , tmp, tmp); n   else { n     if (tmp ==  a  || tmp ==  e  || tmp ==  i  || tmp ==  o  || tmp ==  u  || n         tmp ==  y ) n       printf( %c , tmp); n     else n       for (int j = 1; j <= cnt; j++) putchar(tmp); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a[100005], i, j, m, n, ans = 0, pos = 1; n   cin >> n; n   for (i = 1; i <= n; i++) cin >> a[i]; n   for (i = 3; i <= n;) { n     if (a[i] == a[i - 1] + a[i - 2]) { n       while (a[i] == a[i - 1] + a[i - 2] && i <= n) { n         i++; n       } n       ans = max(i - pos, ans); n       pos = i - 2; n     } else n       i++, pos = i - 2; n   } n   cout << max(ans, min(n, 2)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int ms = 2005, me = 4005; n int adj[ms], to[me], ant[me], z = 0, idx[ms], path[ms], bridge[me], ind, n                               vis[ms]; n int s[ms], l[ms], ans; n bool dfs(int v, int end) { n   if (vis[v]) n     return false; n   else if (v == end) n     return path[v] = true; n   vis[v] = 1; n   for (int e = adj[v]; e > -1; e = ant[e]) { n     path[v] = path[v] || dfs(to[e], end); n   } n   return path[v]; n } n int dfs2(int v, int par = -1) { n   int low = idx[v] = ind++; n   for (int i = adj[v]; i > -1; i = ant[i]) { n     if (idx[to[i]] == -1) { n       int temp = dfs2(to[i], v); n       if (temp > idx[v] && path[to[i]] && path[v]) ans++; n       low = min(low, temp); n     } else if (to[i] != par) n       low = min(low, idx[to[i]]); n   } n   return low; n } n void add(int a, int b) { n   to[z] = b; n   ant[z] = adj[a]; n   adj[a] = z++; n   swap(a, b); n   to[z] = b; n   ant[z] = adj[a]; n   adj[a] = z++; n } n int main() { n   cin.tie(0); n   cin.sync_with_stdio(false); n   int n, m; n   cin >> n >> m; n   z = 0; n   memset(adj, -1, sizeof adj); n   for (int i = 0; i < m; i++) { n     int a, b; n     cin >> a >> b; n     add(a, b); n   } n   int k; n   cin >> k; n   for (int i = 0; i < k; i++) { n     cin >> s[i] >> l[i]; n   } n   for (int i = 0; i < k; i++) { n     ans = 0; n     memset(idx, -1, sizeof idx); n     ind = 0; n     memset(bridge, 0, sizeof bridge); n     memset(vis, 0, sizeof vis); n     memset(path, 0, sizeof path); n     dfs(s[i], l[i]); n     dfs2(s[i]); n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int l, r, mx, pre, suf; n }; n vector<node> T; n vector<pair<int, int> > ht; n int n, m, a[100055], root[100055], first, second, z; n int init(int l, int r) { n   int ind = T.size(); n   if (l == r) { n     T.push_back({-1, -1, 1, 1, 1}); n     return ind; n   } n   int mid = (l + r) >> 1; n   T.push_back({-1, -1, r - l + 1, r - l + 1, r - l + 1}); n   T[ind].l = init(l, mid); n   T[ind].r = init(mid + 1, r); n   return ind; n } n int update(int k, int l, int r, int tar) { n   int ind = T.size(); n   if (l == r) { n     T.push_back({-1, -1, 0, 0, 0}); n     return ind; n   } n   int mid = (l + r) >> 1, left, right; n   T.push_back({-1, -1, 0, 0, 0}); n   if (tar <= mid) { n     left = update(T[k].l, l, mid, tar); n     right = T[k].r; n   } else if (tar > mid) { n     left = T[k].l; n     right = update(T[k].r, mid + 1, r, tar); n   } n   T[ind] = {left, right, n             max(max(T[left].mx, T[right].mx), T[left].suf + T[right].pre), n             T[left].pre, T[right].suf}; n   if (T[left].pre == mid - l + 1) T[ind].pre = T[left].pre + T[right].pre; n   if (T[right].suf == r - mid) T[ind].suf = T[right].suf + T[left].suf; n   return ind; n } n node longest(int k, int l, int r, int tl, int tr) { n   if (tl <= l && r <= tr) { n     return T[k]; n   } n   int mid = (l + r) >> 1; n   if (mid < tl) return longest(T[k].r, mid + 1, r, tl, tr); n   if (tr <= mid) return longest(T[k].l, l, mid, tl, tr); n   node rans = longest(T[k].r, mid + 1, r, mid + 1, tr); n   node lans = longest(T[k].l, l, mid, tl, mid); n   node ret = (node){0, 0, 0, 0, 0}; n   ret.mx = max(max(rans.mx, lans.mx), lans.suf + rans.pre); n   ret.pre = lans.pre; n   if (lans.pre == mid - tl + 1) ret.pre = lans.pre + rans.pre; n   ret.suf = rans.suf; n   if (rans.suf == tr - mid) ret.suf = rans.suf + lans.suf; n   return ret; n } n void DEBUG(int k, int l, int r) { n   if (l == r) return; n   int mid = (l + r) >> 1; n   DEBUG(T[k].l, l, mid); n   DEBUG(T[k].r, mid + 1, r); n } n int main() { n   T.reserve(1000000); n   scanf( %d , &n); n   ht.push_back({0, 0}); n   for (int i = 1; i <= n; i++) { n     scanf( %d , a + i); n     ht.push_back({a[i], i}); n   } n   sort(ht.begin(), ht.end()); n   root[1] = init(1, n); n   for (int i = 2; i <= n; i++) n     root[i] = update(root[i - 1], 1, n, ht[i - 1].second); n   for (int i = 1; i <= n; i++) { n   } n   scanf( %d , &m); n   while (m--) { n     scanf( %d%d%d , &first, &second, &z); n     int l = 1, r = n + 1; n     while (l < r - 1) { n       int mid = (l + r) >> 1; n       node res = longest(root[mid], 1, n, first, second); n       if (res.mx >= z) n         l = mid; n       else n         r = mid; n     } n     printf( %d n , ht[l]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, q, x, y, xx, yy; n long long read() { n   long long x = 0; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) ch = getchar(); n   while (ch >=  0  && ch <=  9 ) { n     x = (x << 3) + (x << 1) + ch -  0 ; n     ch = getchar(); n   } n   return x; n } n struct BIT { n   long long c[1005][1005]; n   long long ask(int x, int y) { n     long long ans = 0; n     for (; x; x -= x & -x) n       for (int i = y; i; i -= i & -i) ans ^= c[x][i]; n     return ans; n   } n   void modify(int x, int y, long long v) { n     for (; x <= (n + 1); x += x & -x) n       for (int i = y; i <= (n + 1); i += i & -i) c[x][i] ^= v; n   } n } t[2][2]; n long long v; n int main() { n   n = read(); n   q = read(); n   while (q--) { n     int op = read(); n     x = read(); n     y = read(); n     xx = read(); n     yy = read(); n     if (op == 2) { n       v = read(); n       t[x & 1][y & 1].modify((x + 1) >> 1, (y + 1) >> 1, v); n       t[x & 1][(yy + 1) & 1].modify((x + 1) >> 1, (yy + 2) >> 1, v); n       t[(xx + 1) & 1][y & 1].modify((xx + 2) >> 1, (y + 1) >> 1, v); n       t[(xx + 1) & 1][(yy + 1) & 1].modify((xx + 2) >> 1, (yy + 2) >> 1, v); n     } else { n       long long v1 = t[(x - 1) & 1][(y - 1) & 1].ask(x >> 1, y >> 1); n       long long v2 = t[(x - 1) & 1][yy & 1].ask(x >> 1, (yy + 1) >> 1); n       long long v3 = t[xx & 1][(y - 1) & 1].ask((xx + 1) >> 1, y >> 1); n       long long v4 = t[xx & 1][yy & 1].ask((xx + 1) >> 1, (yy + 1) >> 1); n       printf( %lld n , v1 ^ v2 ^ v3 ^ v4); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0), cout.tie(0); n   int t; n   cin >> t; n   for (int i = 0; i < t; i++) { n     long long a, b; n     long long uns = 0; n     cin >> a >> b; n     uns = abs(a - b) / 5; n     if (abs(a - b) % 5 == 1) uns++; n     if (abs(a - b) % 5 == 2) uns += 1; n     if (abs(a - b) % 5 == 3) uns += 2; n     if (abs(a - b) % 5 == 4) uns += 2; n     cout << uns << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int v[1000005]; n long long int l[1000005]; n long long int r[1000005]; n int main(void) { n   int n, m; n   int sum; n   scanf(  %d %d , &n, &m); n   for (int i = 0; i < n; i++) { n     scanf(  %d , &v[i]); n   } n   l[0] = 0; n   sum = 0; n   for (int i = 1; i < n; i++) { n     sum++; n     int trip = (sum + m - 1) / m; n     l[i] = l[i - 1] + 1LL * trip * (v[i] - v[i - 1]); n   } n   r[n - 1] = 0; n   sum = 0; n   for (int i = n - 2; i >= 0; i--) { n     sum++; n     int trip = (sum + m - 1) / m; n     r[i] = r[i + 1] + 1LL * trip * (v[i + 1] - v[i]); n   } n   long long int res = l[0] + r[0]; n   for (int i = 0; i < n; i++) { n     res = min(res, l[i] + r[i]); n   } n   printf( %lld n , 2 * res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long g[222222][2]; n int f[222222], p[222222][2], n, i; n long long dfs(int x, int k, int z) { n   if (x < 1 || x > n) return 0; n   if (g[x][z] == -1 || p[x][z] == k) return -1; n   if (p[x][z]) return g[x][z]; n   long long ans = 0; n   p[x][z] = k; n   if (z) n     ans = dfs(x + f[x], k, z ^ 1); n   else n     ans = dfs(x - f[x], k, z ^ 1); n   if (ans == -1) n     return g[x][z] = -1; n   else n     return g[x][z] = ans + f[x]; n } n int main() { n   scanf( %d , &n); n   for (i = 2; i <= n; i++) scanf( %d , f + i); n   for (i = 1; i < n; i++) { n     f[1] = i; n     p[1][1] = 0; n     g[1][1] = 0; n     printf( %I64d n , dfs(1, i, 1)); n   } n   return 0; n } n


#include <bits/stdc++.h> n int a[100001], p[100001], N, Q; n int T[2100001], ls[2100001], rs[2100001], n, root[100001]; n int end[100001], steps[100001]; n int build(int l, int r) { n   int p = ++n; n   T[p] = r - l + 1; n   if (l < r) { n     int m = l + r >> 1; n     ls[p] = build(l, m); n     rs[p] = build(m + 1, r); n   } n   return p; n } n int get_kth(int p, int x) { n   int l = 1, r = N; n   while (l < r) { n     int m = l + r >> 1; n     if (x <= T[ls[p]]) n       p = ls[p], r = m; n     else n       x -= T[ls[p]], p = rs[p], l = m + 1; n   } n   return l; n } n int P(int p, int x, int w) { n   int l = 1, r = N, root; n   T[root = ++n] = T[p] + w; n   while (l < r) { n     int m = l + r >> 1; n     if (x <= m) n       ls[n] = n + 1, rs[n] = rs[p], p = ls[p], r = m; n     else n       rs[n] = n + 1, ls[n] = ls[p], p = rs[p], l = m + 1; n     T[++n] = T[p] + w; n   } n   return root; n } n int G(int p, int x) { n   int l = 1, r = N, ans = 0; n   while (l < r) { n     int m = l + r >> 1; n     if (x <= m) n       p = ls[p], r = m; n     else n       ans += T[ls[p]], p = rs[p], l = m + 1; n   } n   return ans + T[p]; n } n int main() { n   scanf( %d%d , &N, &Q); n   for (int i = 1; i <= N; i++) scanf( %d , a + i); n   end[0] = a[1] - 1; n   steps[0] = 0; n   for (int i = 1; i < N; i++) { n     int add = (a[i + 1] - end[i - 1] - 1) / i; n     end[i] = end[i - 1] + i * add; n     steps[i] = steps[i - 1] + add; n   } n   for (int i = 2; i <= N; i++) p[i] = (p[i - 1] + a[i] - a[i - 1]) % (i - 1); n   root[N] = build(1, N); n   for (int i = N; i; i--) { n     p[i] = get_kth(root[i], p[i] + 1); n     root[i - 1] = P(root[i], p[i], -1); n   } n   while (Q--) { n     int x, k; n     scanf( %d%d , &x, &k); n     if (x < a[1]) { n       printf( %d n , x); n       continue; n     } n     int belong = std::lower_bound(end + 1, end + N, x) - end; n     k += steps[belong - 1] + (x - end[belong - 1] - 1) / belong + 1; n     int ord = (x - end[belong - 1] - 1) % belong + 1; n     ord = get_kth(root[belong], ord); n     belong = std::lower_bound(steps + 1, steps + N, k) - steps; n     printf( %lld n , end[belong - 1] + n                          (long long)(k - steps[belong - 1] - 1) * belong + n                          G(root[belong], ord)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c, d, x, y, x1, y1; n   cin >> a >> b >> c >> d; n   x = (3 * a) / 10; n   x1 = (a - (a / 250) * c); n   int m = max(x, x1); n   y = (3 * b) / 10; n   y1 = (b - (b / 250) * d); n   int m1 = max(y, y1); n   if (m < m1) n     cout <<  Vasya  << endl; n   else if (m1 < m) n     cout <<  Misha  << endl; n   else n     cout <<  Tie  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 50; n const int MOD = 1e9 + 9; n int n, k, a, b, c, d, m, L, R, tot = 1; n pair<int, int> cities[MAXN]; n struct TreeNode { n   int x, l, r, lson, rson; n   pair<int, int> v; n } tree[MAXN]; n int newNode(int &x) { return x = ++tot; } n pair<int, int> calc(pair<int, int> l, pair<int, int> r) { n   return {l.second + r.second, max(l.first + r.second, l.second + r.first) + 1}; n } n void build(int o, int l, int r) { n   int max_y = -1, max_id = l; n   for (int i = l; i <= r; i++) { n     if (cities[i].second > max_y) { n       max_y = cities[i].second; n       max_id = i; n     } n   } n   tree[o].l = cities[l].first; n   tree[o].r = cities[r].first; n   tree[o].x = cities[max_id].first; n   if (l < max_id) build(newNode(tree[o].lson), l, max_id - 1); n   if (max_id < r) build(newNode(tree[o].rson), max_id + 1, r); n   tree[o].v = calc(tree[tree[o].lson].v, tree[tree[o].rson].v); n } n pair<int, int> query(int o, int l, int r) { n   if (o == 0 || l > tree[o].r || r < tree[o].l) return {-1, 0}; n   if (l <= tree[o].l && tree[o].r <= r) return tree[o].v; n   if (r < tree[o].x) return query(tree[o].lson, l, r); n   if (l > tree[o].x) return query(tree[o].rson, l, r); n   return calc(query(tree[o].lson, l, r), query(tree[o].rson, l, r)); n } n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 0; i < k; i++) { n     scanf( %d%d , &cities[i].first, &cities[i].second); n   } n   scanf( %d%d%d%d , &a, &b, &c, &d); n   for (int i = k; i < n; i++) { n     cities[i].first = (1LL * a * cities[i - 1].first + b) % MOD; n     cities[i].second = (1LL * c * cities[i - 1].second + d) % MOD; n   } n   sort(cities, cities + n); n   tree[0].v = {-1, 0}; n   build(1, 0, n - 1); n   scanf( %d , &m); n   while (m--) { n     scanf( %d%d , &L, &R); n     printf( %d n , query(1, L, R).second); n   } n } n


#include <bits/stdc++.h> n int main() { n   int i, n; n   scanf( %d , &n); n   for (i = 0; i < n; i++) { n     long long int x; n     long long int k, y; n     scanf( %I64d %I64d , &k, &x); n     y = x + 9 * (k - 1); n     printf( %I64d , y); n     printf(  n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int q; n   cin >> q; n   for (int i = 0; i < q; ++i) { n     int n; n     cin >> n; n     set<int> st; n     for (int j = 0; j < n; ++j) { n       int x; n       cin >> x; n       st.insert(x); n     } n     int ans = 0; n     int mx = *st.rbegin(); n     if (mx % 2 == 0 && mx % 3 == 0 && mx % 5 == 0) { n       if (st.count(mx / 2) && st.count(mx / 3) && st.count(mx / 5)) { n         ans = max(ans, mx / 2 + mx / 3 + mx / 5); n       } n     } n     vector<int> res; n     while (!st.empty() && int(res.size()) < 3) { n       int x = *st.rbegin(); n       st.erase(prev(st.end())); n       bool ok = true; n       for (auto it : res) ok &= (it % x != 0); n       if (ok) res.push_back(x); n     } n     ans = max(ans, accumulate(res.begin(), res.end(), 0)); n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, a, b, w, start = 0, k; n long long int MAX = 1e18; n vector<vector<int> > wait(100005); n vector<vector<pair<int, int> > > adj(100005); n void binarySearch(int v, long long int& d) { n   if (v == n - 1 or wait[v].size() == 0) { n     return; n   } n   int low = 0, high = wait[v].size() - 1, mid; n   while (low <= high) { n     mid = (low + high) >> 1; n     if (wait[v][mid] == d) { n       ++d; n       ++mid; n       while (mid <= wait[v].size() - 1 and n              wait[v][mid] == wait[v][mid - 1] + 1) { n         ++d; n         ++mid; n       } n       return; n     } else if (wait[v][mid] > d) { n       high = mid - 1; n     } else { n       low = mid + 1; n     } n   } n   return; n } n int main(void) { n   ios ::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> m; n   for (int i = 0; i <= m - 1; ++i) { n     cin >> a >> b >> w; n     --a; n     --b; n     adj[a].push_back({b, w}); n     adj[b].push_back({a, w}); n   } n   for (int i = 0; i <= n - 1; ++i) { n     cin >> k; n     for (int j = 1; j <= k; ++j) { n       cin >> w; n       wait[i].emplace_back(w); n     } n   } n   set<pair<long long int, int> > s; n   vector<long long int> dist(n, MAX); n   vector<int> present(n, 1); n   dist[start] = 0; n   s.insert({dist[start], start}); n   while (!s.empty()) { n     auto c = *(s.begin()); n     s.erase(c); n     int v = c.second; n     present[v] = 0; n     binarySearch(v, dist[v]); n     for (auto e : adj[v]) { n       int u = e.first; n       w = e.second; n       if (present[u] and dist[u] > dist[v] + 1LL * w) { n         s.erase({dist[u], u}); n         dist[u] = dist[v] + 1LL * w; n         s.insert({dist[u], u}); n       } n     } n   } n   if (dist[n - 1] == MAX) { n     cout << -1 << endl; n   } else { n     cout << dist[n - 1] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool *Seive(long long n, bool *p) { n   memset(p, 1, sizeof(p)); n   long long i, j; n   for (i = 2; i <= n; i++) { n     if (p[i] == 1) n       for (j = i * i; j <= n; j += i) { n         p[j] = 0; n       } n   } n   p[1] = 0; n   return p; n } n long long gcd(long long a, long long b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n long long modexp(long long x, long long y) { n   if (y == 0) n     return 1; n   else if (y % 2 == 0) { n     return modexp((x * x) % (long long)(1e9 + 7), y / 2); n   } else { n     return (x * modexp((x * x) % (long long)(1e9 + 7), (y - 1) / 2)) % n            (long long)(1e9 + 7); n   } n } n long long fact(long long n) { n   long long f = 1; n   for (long long i = 2; i <= n; i++) { n     f = (i % (long long)(1e9 + 7) * f % (long long)(1e9 + 7)) % n         (long long)(1e9 + 7); n   } n   return f; n } n long long nCr(long long n, long long r) { n   return (fact(n) * modexp((fact(n - r) * fact(r)) % (long long)(1e9 + 7), n                            (long long)(1e9 + 7) - 2)) % n          (long long)(1e9 + 7); n } n void showlist(list<int> g) { n   list<int>::iterator it; n   for (it = g.begin(); it != g.end(); ++it) cout << *it <<    ; n   cout <<   n ; n } n bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) { n   return (a.first > b.first); n } n struct Point { n   int x, y; n }; n long long overlappingArea(long long x3, long long x4, long long x5, n                           long long x6, long long y3, long long y4, n                           long long y5, long long y6) { n   long long area1 = abs(x3 - x4) * abs(y3 - y4); n   long long area2 = abs(x5 - x6) * abs(y5 - y6); n   long long areaI = (min(x4, x6) - max(x3, x5)) * (min(y4, y6) - max(y3, y5)); n   if (areaI <= 0) areaI = 0; n   return (area1 + area2 - areaI); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long a, x1, x2, y1, y2, x3, x4, x5, x6, y3, y4, y5, y6; n   cin >> x1 >> y1 >> x2 >> y2; n   cin >> x3 >> y3 >> x4 >> y4; n   if (x4 > x2) { n     x4 = x2; n   } n   if (x3 < x1) { n     x3 = x1; n   } n   if (y4 > y2) { n     y4 = y2; n   } n   if (y3 < y1) { n     y3 = y1; n   } n   cin >> x5 >> y5 >> x6 >> y6; n   if (x6 > x2) { n     x6 = x2; n   } n   if (x5 < x1) { n     x5 = x1; n   } n   if (y6 > y2) { n     y6 = y2; n   } n   if (y5 < y1) { n     y5 = y1; n   } n   a = 0; n   if ((x4 - x3 <= 0 || y4 - y3 <= 0) && (x6 - x5 <= 0 || y6 - y5 <= 0)) n     ; n   else if (x4 - x3 <= 0 || y4 - y3 <= 0) { n     a = (x6 - x5) * (y6 - y5); n   } else if (x6 - x5 <= 0 || y6 - y5 <= 0) { n     a = (x4 - x3) * (y4 - y3); n   } else { n     a = overlappingArea(x3, x4, x5, x6, y3, y4, y5, y6); n   } n   if (a == (x2 - x1) * (y2 - y1)) { n     cout <<  NO  << endl; n   } else { n     cout <<  YES  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e+7; n const int N = 1e5 + 5; n long long pwr(long long x, long long y); n long long a[N]; n vector<long long> v; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long n, m, k; n   cin >> n >> m >> k; n   for (int i = 0; i < m; i++) { n     cin >> a[i]; n     v.push_back(a[i]); n   } n   long long ans = 0, l = k; n   long long cur = 0, pre = 0; n   while (pre < m) { n     cur = (upper_bound(v.begin(), v.end(), l) - v.begin()); n     if (cur == pre) { n       long long po = (v[cur] - l) / k; n       l += (long long)(po + bool((v[cur] - l) % k)) * k; n     } else { n       l += (cur - pre); n       ans++; n     } n     pre = cur; n   } n   cout << ans << endl; n   return 0; n } n long long pwr(long long x, long long y) { n   long long ans = 1; n   x = x % mod; n   while (y > 0) { n     if (y & 1) ans = (x * (ans % mod)) % mod; n     x = (x * x) % mod; n     y = y / 2; n   } n   return ans % mod; n } n


#include <bits/stdc++.h> n using namespace std; n long long b[60005], c[60005]; n signed main() { n   long long a; n   scanf( %lld , &a); n   long long MIN = LLONG_MAX / 3, MAX = 0; n   for (long long d = 0; d < a; d++) { n     scanf( %lld , &b[d]); n     MIN = min(MIN, b[d]); n     MAX = max(MAX, b[d]); n   } n   for (long long d = 0; d < a; d++) { n     scanf( %lld , &c[d]); n   } n   double s = MIN, g = MAX; n   for (long long i = 0; i < 10000; i++) { n     double k = (s + g) / 2; n     double n = -1; n     bool t = false; n     for (long long j = 0; j < a; j++) { n       double m = abs(k - b[j]) / (double)c[j]; n       if (m > n) { n         if (b[j] > k) n           t = true; n         else n           t = false; n         n = m; n       } n     } n     if (i == 9999) { n       printf( %.15lf n , n); n     } n     if (t) n       s = k; n     else n       g = k; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a[101], b[101], c[101], i; n   cin >> n; n   for (i = 0; i < n; i++) cin >> a[i]; n   for (i = 0; i < n; i++) cin >> b[i]; n   for (i = 0; i < n; i++) n     if (a[i] <= b[i]) c[i] = 1; n   int bs = 0, rc = 0, sett; n   for (i = 0; i < n; i++) n     if (a[i] > b[i]) n       rc++; n     else if (a[i] < b[i]) n       bs++; n   if (rc == 0) n     cout <<  -1 ; n   else n     cout << bs / rc + 1; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, k; n   cin >> n >> k; n   vector<long long> a; n   vector<long long> b; n   long long sum; n   if (k + 1 < n) { n     sum = k + 1; n     b.push_back(sum); n   } else { n     for (long long i = 0; i < n; i++) { n       cout << n <<    ; n     } n     return 0; n   } n   for (long long i = 0; i < n; i++) { n     long long te; n     cin >> te; n     te--; n     a.push_back(te); n   } n   for (long long i = 1; i < n; i++) { n     long long re = 0; n     if (a[i] > -1) { n       if (a[i] + k > i) { n         if (a[i] + k < n) { n           re = a[i] + k - i; n         } else { n           re = n - i - 1; n         } n       } n       if (a[i] + k < i) { n         sum = 1; n       } else { n         sum = 0; n       } n       if (sum) { n         if (i - k > a[i] + k) { n           sum += k; n         } else { n           sum += i - 1 - (a[i] + k); n         } n       } n       sum += b[a[i]]; n     } else { n       sum = 1; n       if (i - k > -1) { n         sum += k; n       } else { n         sum += i; n       } n     } n     if (i + k < n) { n       sum += k - re; n     } else { n       sum += n - 1 - i - re; n     } n     b.push_back(sum); n   } n   for (long long i = 0; i < n; i++) { n     cout << b[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   long long int a[n]; n   for (int i = 0; i < n; i++) { n     scanf( %lld , &a[i]); n   } n   int m; n   cin >> m; n   long long int b[m]; n   for (int i = 0; i < m; i++) { n     scanf( %lld , &b[i]); n   } n   int i = 0, j = 0, ans = 0; n   while (i < n && j < m) { n     if (a[i] == b[j]) { n       i++; n       j++; n       ans++; n     } else if (a[i] > b[j]) { n       j++; n       if (j < m) { n         b[j] += b[j - 1]; n       } n     } else { n       i++; n       if (i < n) { n         a[i] += a[i - 1]; n       } n     } n   } n   if (i != n || j != m) { n     ans = -1; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n, h, a, b, t, f; n   int t1, f1, t2, f2; n   int sum; n   while (~scanf( %d%d%d%d%d , &n, &h, &a, &b, &t)) { n     while (t--) { n       sum = 0; n       scanf( %d%d%d%d , &t1, &f1, &t2, &f2); n       if (t1 > t2) { n         f = t1; n         t1 = t2; n         t2 = f; n       } n       if (f1 > f2) { n         f = f1; n         f1 = f2; n         f2 = f; n       } n       if (t1 == t2) n         sum = f2 - f1; n       else if (f1 > b && f2 > b) n         sum = (f1 - b) + (f2 - b) + t2 - t1; n       else if (f1 < a && f2 < a) n         sum = (a - f1) + (a - f2) + t2 - t1; n       else n         sum = f2 - f1 + t2 - t1; n       printf( %d n , sum); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 1, LOGN = 20; n vector<pair<int, long long> > adj[N]; n long long a[N], dis[N]; n int lca[N][LOGN]; n int upd[N]; n void dfs1(int u, long long d = 0, int par = 0) { n   dis[u] = d; n   lca[u][0] = par; n   for (int i = 1; i < LOGN; i++) lca[u][i] = lca[lca[u][i - 1]][i - 1]; n   long long del = dis[u] - a[u]; n   int v = u; n   for (int i = LOGN - 1; i >= 0; i--) { n     if (dis[lca[v][i]] >= del) v = lca[v][i]; n   } n   if (v != 0) { n     v = lca[v][0]; n     upd[v]--; n   } n   for (auto& ch : adj[u]) { n     dfs1(ch.first, d + ch.second, u); n     upd[u] += upd[ch.first]; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < n - 1; i++) { n     int p, w; n     cin >> p >> w; n     adj[p - 1].emplace_back(i + 1, w); n   } n   fill(upd, upd + n, 1); n   dfs1(0); n   for (int i = 0; i < n; i++) cout << upd[i] - 1 <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 7; n const int inf = INT_MAX; n const long long inff = 1e18; n const long long mod = 1e9 + 7; n int n, m, x, y; n int a[maxn], p[maxn]; n int b[maxn]; n int dp1[maxn], dp2[maxn]; n vector<int> v; n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     cin >> x >> y; n     p[x]++; n     p[y + 1]--; n   } n   for (int i = 1; i <= m; i++) a[i] = a[i - 1] + p[i], b[m - i + 1] = a[i]; n   for (int i = 1; i <= m; i++) { n     auto now = upper_bound((v).begin(), (v).end(), a[i]); n     if (now == v.end()) n       v.push_back(a[i]); n     else n       v[now - v.begin()] = a[i]; n     dp1[i] = ((int)(v).size()); n   } n   v.clear(); n   for (int i = 1; i <= m; i++) { n     auto now = upper_bound((v).begin(), (v).end(), b[i]); n     if (now == v.end()) n       v.push_back(b[i]); n     else n       v[now - v.begin()] = b[i]; n     dp2[i] = ((int)(v).size()); n   } n   int ans = 0; n   for (int i = 0; i <= m; i++) ans = max(ans, dp1[i] + dp2[m - i]); n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e6 + 10; n const long long int md = 1e9 + 7; n long long int n, fac[MAXN], invf[MAXN]; n inline long long int inv(long long int a, long long int b = 1e9 + 5ll) { n   long long int k = 1ll; n   while (b) { n     if (b & 1) k = (k * a) % md; n     a = (a * a) % md; n     b /= 2ll; n   } n   return k; n } n inline long long int ch(long long int a, long long int b) { n   return ((((invf[b] * invf[a - b]) % md) * fac[a]) % md); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   fac[0] = 1ll; n   invf[0] = 1ll; n   cin >> n; n   for (long long int i = 1ll; i < MAXN; i++) n     fac[i] = (fac[i - 1] * i) % md, invf[i] = inv(fac[i]); n   long long int ans = inv(2ll, 2ll * n + 1ll); n   ans--; n   ans = (ans + md) % md; n   long long int bad = 0ll; n   for (long long int i = n + 1; i <= 2ll * n; i++) { n     long long int tmp = (2ll * ch(i - 1ll, n)) % md; n     tmp += ((2ll * bad) % md); n     tmp %= md; n     ans = (((ans - tmp) % md) + md) % md; n     bad = tmp; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool seen[100005], x[100005]; n vector<int> g[100005], ans; n inline void add(int u) { ans.push_back(u + 1), x[u] ^= 1; } n void dfs(int u, int p) { n   seen[u] = true; n   add(u); n   for (auto v : g[u]) n     if (v != p && !seen[v]) dfs(v, u), add(u); n   if (x[u]) { n     if (p != -1) n       add(p), add(u); n     else n       x[u] = 0, ans.pop_back(); n   } n } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (auto i = (0); i < m; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     u--, v--; n     g[u].push_back(v), g[v].push_back(u); n   } n   for (auto i = (0); i < n; i++) scanf( %d , x + i); n   for (auto i = (0); i < n; i++) n     if (x[i]) { n       dfs(i, -1); n       break; n     } n   for (auto i = (0); i < n; i++) n     if (x[i]) { n       printf( -1 ); n       return 0; n     } n   printf( %d n , ans.size()); n   for (auto u : ans) printf( %d  , u); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool compare(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } n int main() { n   int maxz, tempbuff, tempbuff2; n   cin >> maxz; n   vector<pair<int, int>> z; n   for (int i = 0; i < maxz; i++) { n     cin >> tempbuff >> tempbuff2; n     z.push_back(make_pair(tempbuff, tempbuff2)); n   } n   sort(z.begin(), z.end(), compare); n   for (int i = 0; i < maxz - 1; i++) { n     if (z[i].first > z[i + 1].first) { n       cout <<  Happy Alex ; n       return 0; n     } n   } n   cout <<  Poor Alex ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n template <typename T> n T sqr(T a) { n   return a * a; n } n template <typename T> n int sign(T a) { n   if (a == 0) return 0; n   return (a > 0 ? 1 : -1); n } n template <typename T1, typename T2> n T2 sum_mod(T1 x, T2 MOD) { n   if (x < 0) x += MOD; n   if (x >= MOD) x -= MOD; n   return x; n } n template <typename T1, typename T2> n T2 mul_mod(T1 x, T2 MOD) { n   if (x < 0) return (abs(x) % MOD == 0 ? 0 : MOD - abs(x) % MOD); n   return x % MOD; n } n template <typename T> n bool uax(T& a, const T b) { n   if (a < b) { n     a = b; n     return true; n   } n   return false; n } n template <typename T> n bool uin(T& a, const T b) { n   if (a > b) { n     a = b; n     return true; n   } n   return false; n } n template <typename T1, typename T2> n istream& operator>>(istream& in, pair<T1, T2>& p) { n   in >> p.first >> p.second; n   return in; n } n template <typename T1, typename T2> n ostream& operator<<(ostream& out, pair<T1, T2>& p) { n   out << p.first <<     << p.second; n   return out; n } n const int LOG = 18; n const int N = (int)1e5 + 7; n const int MAXN = (int)2e3 + 7; n const int MOD = (int)998244353; n const int INF = (int)1e9 + 7; n const int CONST = 300; n const long long LINF = (int64_t)2e15; n const long double PI = 3.1415926535897932384626433832795; n const long double EPS = 1; n string a[3]; n vector<int> zfunc(const string& a, const string& b) { n   string s = a +  #  + b; n   int n = (int)s.size(); n   vector<int> z(n); n   int l = 0, r = 0; n   for (int i = 1; i < n; i++) { n     if (i <= r) z[i] = min(z[i - l], r - i + 1); n     while (i + z[i] < n && s[z[i]] == s[i + z[i]]) z[i]++; n     if (i + z[i] > r) l = i, r = i + z[i] - 1; n   } n   return z; n } n string unite(const string& a, const string& b) { n   auto v = zfunc(b, a); n   string res = a; n   for (int i = (int)b.size() + 1; i <= (int)a.size() + (int)b.size(); i++) { n     if (v[i] >= (int)b.size()) return res; n     if (v[i] + i == (int)a.size() + (int)b.size() + 1) { n       res += b.substr(v[i], (int)b.size() - v[i]); n       return res; n     } n   } n   return a + b; n } n int get(const string& a, const string& b, const string& c) { n   string s = unite(a, b); n   s = unite(s, c); n   return (int)s.size(); n } n int main() { n   double start = clock(); n   cout << fixed << setprecision(20); n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> a[0] >> a[1] >> a[2]; n   vector<int> perm = {0, 1, 2}; n   int ans = INF; n   do { n     uin(ans, get(a[perm[0]], a[perm[1]], a[perm[2]])); n   } while (next_permutation(perm.begin(), perm.end())); n   cout << ans; n } n


#include <bits/stdc++.h> n  n /* n ios_base::sync_with_stdio(0); n cin.tie(0); n cout.tie(0); n int t; n cin >> t; n while(t--) solve(); n */ n using namespace std; n  n typedef long long ll; n typedef long double ld; n  n int magic(vector<int> &a, int del){ n     auto it = lower_bound(a.begin(), a.end(), del); n     if(it == a.end()) return -1; n     return *it; n } n  n void solve(){ n     int n; n     cin >> n; n     vector<int> a(n); n     map<int, int> mp; n     for(int i = 0;i < n;i++){ n         cin >> a[i]; n         mp[a[i]] = i + 1; n     } n     //sort(a.begin(), a.end()); n     int ans = 0; n     for(int i = 2;i <= 2 * n;i++){ n         for(int j = 2;j * j <= i;j++){ n             if(i % j == 0){ n                 int v1 = j, v2 = i / j; n                 if(mp[v1] == 0 || mp[v2] == 0 || (mp[v1] == mp[v2])) continue; n                 if(mp[v1] + mp[v2] == i) ans++; n                 //cout << v1 <<     << v2 <<   n  n             } n         } n  n         if(mp[i] != 0 && mp[1] != 0){ n             if(mp[i] + mp[1] == i) ans++; n         } n     } n  n     cout << ans <<   n ; n } n  n int main(){ n     ios_base::sync_with_stdio(0); n     cin.tie(0); n     cout.tie(0); n     int t; n     cin >> t; n     while(t--) solve(); n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long int i, j, n, m, k; n   cin >> n; n   long long int a[n]; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n   } n   cin >> m; n   long long int b[m]; n   for (i = 0; i < m; i++) { n     cin >> b[i]; n   } n   sort(a, a + n); n   sort(b, b + m); n   long long int c = 0; n   for (i = 0; i < n; i++) { n     for (j = 0; j < m; j++) { n       if (abs(a[i] - b[j]) <= 1) { n         b[j] = 1005; n         c++; n         break; n       } n     } n   } n   cout << c << endl; n   return; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int tst, t = 1; n   for (tst = 1; tst <= t; tst++) { n     solve(); 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   int n; n   cin >> n; n   vector<long long> a(n); n   for (long long& v : a) cin >> v; n   vector<long long> p(n); n   for (long long& v : p) cin >> v; n   int m; n   cin >> m; n   vector<long long> b(m); n   for (long long& v : b) cin >> v; n   vector<long long> cost(m + 1); n   for (int i = 0; i < n; i++) { n     int j = lower_bound(b.begin(), b.end(), a[i]) - b.begin(); n     if (j == m) n       cost[m] += p[i]; n     else if (p[i] < 0) { n       cost[j] += p[i]; n     } n   } n   vector<long long> dp(m + 1, 1e18); n   dp[0] = 0; n   for (int i = 0; i < n; i++) { n     int j = lower_bound(b.begin(), b.end(), a[i]) - b.begin(); n     if (j == m) continue; n     if (b[j] == a[i]) { n       long long take_cost = 0; n       if (p[i] < 0) take_cost = -p[i]; n       dp[j + 1] = min(dp[j + 1], dp[j] + cost[j] + take_cost); n     } n     if (p[i] > 0) { n       cost[j] += p[i]; n     } n   } n   if (dp[m] > 1e17) { n     cout <<  NO  << endl; n     return 0; n   } n   cout <<  YES  << endl; n   cout << dp[m] + cost[m] << endl; n } n


#include <bits/stdc++.h> n double Pow(double x, int n) { n   double ans = 1; n   for (; n; n >>= 1) { n     if (n & 1) ans *= x; n     x *= x; n   } n   return ans; n } n int main() { n   int n, m; n   double ans = 0; n   scanf( %d%d , &m, &n); n   for (int i = 1; i < m; i++) ans += Pow((double)i / (double)m, n); n   ans = (double)m - ans; n   printf( %lf n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int i, j, m, n, c; n   cin >> n >> c; n   int ar[n]; n   for (i = 0; i < n; i++) { n     cin >> ar[i]; n   } n   long long int l = 1, h = n, mid; n   long long int co = 0, res1 = 0, res2 = 0; n   while (l <= h) { n     co = 0; n     mid = (l + h) / 2; n     vector<long long int> v(n); n     for (i = 0; i < n; i++) { n       v[i] = ar[i] + mid * (i + 1); n     } n     sort(v.begin(), v.end()); n     for (i = 0; i < mid; i++) { n       co = co + v[i]; n     } n     if (co > c) n       h = mid - 1; n     else if (co <= c) n       l = mid + 1, res1 = co, res2 = mid; n   } n   cout << res2 <<     << res1; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); n const int N = 19; n int g[N]; n unsigned long long dp[1 << N][N + 1]; n unsigned long long ok[1 << N]; n unsigned long long slen[N + 1][1 << N]; n unsigned long long cur[N + 1][1 << N]; n unsigned long long val[1 << N]; n unsigned long long ans[1 << N]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       char c; n       cin >> c; n       if (c ==  1 ) { n         g[i] |= (1 << j); n       } n     } n   } n   for (int i = 0; i < n; i++) { n     dp[1 << i][i] = 1; n   } n   for (int mask = 0; mask < (1 << n); mask++) { n     for (int i = 0; i < n; i++) { n       int cands = g[i] & (~mask); n       for (int j = 0; j < n; j++) { n         if ((cands >> j) & 1) { n           dp[mask | (1 << j)][j] += dp[mask][i]; n         } n       } n       ok[mask] += dp[mask][i]; n     } n   } n   for (int len = 1; len <= n; len++) { n     for (int mask = 0; mask < (1 << n); mask++) { n       if (__builtin_popcount(mask) == len) { n         slen[len][mask] += ok[mask]; n       } n     } n     for (int i = 0; i < n; i++) { n       for (int mask = 0; mask < (1 << n); mask++) { n         if ((mask >> i) & 1) { n           slen[len][mask] += slen[len][mask ^ (1 << i)]; n         } n       } n     } n   } n   map<vector<int>, vector<int> > ok; n   for (int mask = 0; mask < (1 << (n - 1)); mask++) { n     int x = 0; n     vector<int> t; n     while (x < n) { n       int len = 1; n       while ((mask >> x) & 1) { n         x++; n         len++; n       } n       t.push_back(len); n       x++; n     } n     sort(t.begin(), t.end()); n     ok[t].push_back(mask); n   } n   vector<int> a; n   for (int mask = 0; mask < (1 << n); mask++) val[mask] = 1; n   function<void(int, int)> f = [&](int s, int last) { n     if (s == n) { n       unsigned long long ret = 0; n       int x = (1 << n) - 1; n       for (int mask = 0; mask < (1 << n); mask++) { n         if (__builtin_popcount(mask) % 2 == 0) n           ret += val[x ^ mask]; n         else n           ret -= val[x ^ mask]; n       } n       for (auto c : ok[a]) { n         ans[c] += ret; n       } n       return; n     } n     if (s + last > n) { n       return; n     } n     for (int mask = 0; mask < (1 << n); mask++) { n       cur[s][mask] = val[mask]; n     } n     for (int i = last; s + i <= n; i++) { n       if (s + i != n && s + i + i > n) continue; n       a.push_back(i); n       for (int mask = 0; mask < (1 << n); mask++) { n         val[mask] *= slen[i][mask]; n       } n       f(s + i, i); n       for (int mask = 0; mask < (1 << n); mask++) { n         val[mask] = cur[s][mask]; n       } n       a.pop_back(); n     } n   }; n   f(0, 1); n   for (int i = 0; i < (n - 1); i++) { n     for (int mask = 0; mask < (1 << (n - 1)); mask++) { n       if (!((mask >> i) & 1)) { n         ans[mask] -= ans[mask + (1 << i)]; n       } n     } n   } n   for (int mask = 0; mask < (1 << (n - 1)); mask++) { n     cout << ans[mask] <<    ; n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-5; n struct line { n   double x, y, vx, vy; n   void read() { n     double t1, t2; n     cin >> t1 >> x >> y >> t2 >> vx >> vy; n     vx = (vx - x) / (t2 - t1); n     vy = (vy - y) / (t2 - t1); n     x -= vx * t1; n     y -= vy * t1; n   } n } L[1005]; n struct vec { n   double x, y; n } b[1005]; n double cross(const vec &a, const vec &b) { return a.x * b.y - a.y * b.x; } n double a[1005]; n int tot; n bool cmp(const vec a, const vec b) { n   if (fabs(cross(a, b)) < eps) { n     if (fabs(a.x - b.x) < eps) return a.y < b.y; n     return a.x < b.x; n   } n   return cross(a, b) < 0; n } n int main() { n   ios::sync_with_stdio(0); n   int N; n   cin >> N; n   int ans = 0; n   double px, py, pvx, pvy, t; n   for (int i = 1; i <= N; i++) L[i].read(); n   for (int i = 1; i <= N; i++) { n     tot = 0; n     for (int j = 1; j <= N; j++) n       if (i != j) { n         px = L[j].x - L[i].x; n         py = L[j].y - L[i].y; n         pvx = L[j].vx - L[i].vx; n         pvy = L[j].vy - L[i].vy; n         t = 0; n         if (!((fabs(pvx) < eps))) n           t = px / pvx; n         else if (!(fabs(pvy) < eps)) n           t = py / pvy; n         if (fabs(px - t * pvx) < eps && fabs(py - t * pvy) < eps) { n           a[++tot] = t; n           b[tot].x = pvx, b[tot].y = pvy; n         } n       } n     sort(a + 1, a + tot + 1); n     int cnt = 0; n     for (int j = 1; j <= tot; j++) { n       if (fabs(a[j] - a[j - 1]) < eps) n         cnt++; n       else n         cnt = 1; n       ans = max(ans, cnt); n     } n     sort(b + 1, b + tot + 1, cmp); n     cnt = 0; n     for (int j = 1; j <= tot; j++) { n       if (fabs(cross(b[j], b[j - 1])) < eps) { n         if (fabs(b[j].x - b[j - 1].x) > eps || fabs(b[j].y - b[j - 1].y) > eps) n           cnt++; n       } else n         cnt = 1; n       ans = max(ans, cnt); n     } n   } n   cout << ans + 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int A = 26; n const int maxn = 5e3 + 5; n const long long mod = 1e9 + 7; n char s[maxn]; n int n; n int nxt[maxn][A]; n long long fat[maxn], inv[maxn]; n long long dp[maxn][maxn]; n string t; n void fillNxtTable() { n   t = s; n   t =  $  + t; n   int last[A]; n   fill(last, last + A, n + 1); n   for (int i = n; i >= 0; i--) { n     for (int j = 0; j < A; j++) nxt[i][j] = last[j]; n     if (i) last[t[i] -  a ] = i; n   } n } n long long exp(long long a, long long b) { n   long long result = 1; n   while (b) { n     if (b & 1) result = (result * a) % mod; n     a = (a * a) % mod; n     b >>= 1; n   } n   return result; n } n void preComputeBinomial() { n   fat[0] = 1; n   inv[0] = 1; n   for (int i = 1; i < maxn; i++) { n     fat[i] = (fat[i - 1] * i) % mod; n     inv[i] = exp(fat[i], mod - 2); n   } n } n long long C(int n, int k) { n   if (k < 0) return 0; n   return (((fat[n] * inv[n - k]) % mod) * inv[k]) % mod; n } n long long solve(int pos, int k) { n   if (pos > n) return 0; n   long long &ans = dp[pos][k]; n   if (ans != -1) return ans; n   ans = C(n - 1, k - 1); n   for (int i = 0; i < A; i++) { n     if ((t[pos] -  a ) != i) { n       ans = (ans + solve(nxt[pos][i], k + 1)); n     } n   } n   ans %= mod; n   return ans; n } n int main() { n   scanf( %d , &n); n   scanf( %s , s); n   fillNxtTable(); n   preComputeBinomial(); n   memset(dp, -1, sizeof(dp)); n   printf( %lld n , solve(0, 0)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int nbElems, nbAuto; n bitset<2000> autos[2000]; n bitset<2000> inverse[2000]; n int main() { n   scanf( %d%d , &nbElems, &nbAuto); n   vector<pair<int, int> > paires; n   for (int iPaire = 0; iPaire < nbAuto; iPaire++) { n     int pos, elem; n     scanf( %d%d , &pos, &elem); n     autos[pos - 1][elem - 1] = true; n     paires.push_back(make_pair(pos - 1, elem - 1)); n   } n   for (int iElem = 0; iElem < nbElems; iElem++) { n     inverse[iElem][iElem] = 1; n   } n   for (int iLigne = 0; iLigne < nbElems; iLigne++) { n     if (!autos[iLigne][iLigne]) { n       for (int iAutre = iLigne + 1; iAutre < nbElems; iAutre++) { n         if (autos[iAutre][iLigne]) { n           autos[iLigne] ^= autos[iAutre]; n           inverse[iLigne] ^= inverse[iAutre]; n           break; n         } n       } n     } n     for (int iAutre = 0; iAutre < nbElems; iAutre++) { n       if (iAutre != iLigne && autos[iAutre][iLigne]) { n         autos[iAutre] ^= autos[iLigne]; n         inverse[iAutre] ^= inverse[iLigne]; n       } n     } n   } n   for (int iPaire = 0; iPaire < nbAuto; iPaire++) { n     if (inverse[paires[iPaire].second][paires[iPaire].first]) { n       printf( NO n ); n     } else { n       printf( YES n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, a[100005], tot = 0, tmp; n int main() { n   ios_base::sync_with_stdio(NULL); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   for (long long i = 1; i <= m; i++) { n     cin >> a[i]; n     if (i + a[i] - 1 > n) { n       cout << -1 << endl; n       return 0; n     } n     tot += a[i]; n   } n   if (tot < n) { n     cout << -1 << endl; n     return 0; n   } n   cout << 1; n   tot -= a[1]; n   n--; n   for (long long i = 2; i <= m; i++) { n     if (tot > n) { n       cout <<     << i; n       tot -= a[i]; n       n--; n     } else { n       cout <<     << i + n - tot; n       tmp = i + n - tot + a[i]; n       for (long long j = i + 1; j <= m; j++) { n         cout <<     << tmp; n         tmp += a[j]; n       } n       cout << endl; n       return 0; n     } n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, mod, s, s1, s2; n inline long long get(long long id, long long rem, long long l, long long r, n                      long long b, long long e, long long x) { n   if (e < l || r < b) { n     return 0; n   } n   if (b <= l && r <= e) { n     if (x < rem) { n       return 0; n     } n     s = (x - rem) / (1LL << id); n     s1 = s; n     s2 = s + 1; n     if (s % 2 == 0) { n       s1 /= 2; n     } else { n       s2 /= 2; n     } n     return (((s + 1) % mod) * (rem % mod) % mod + n             ((1LL << id) % mod) * (s1 % mod) % mod * (s2 % mod) % mod) % n            mod; n   } n   long long lrem = rem, rrem = rem + (1LL << id); n   if (rem == 0) { n     rrem = 0; n     lrem = (1LL << id); n   } n   return (get(id + 1, lrem, l, (l + r) / 2, b, e, x) + n           get(id + 1, rrem, (l + r) / 2 + 1, r, b, e, x)) % n          mod; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long m, l, r, u, v; n   cin >> n >> m >> mod; n   while (m--) { n     cin >> l >> r >> u >> v; n     cout << (get(0, 0, 1, n, l, r, min(n, v)) - n              get(0, 0, 1, n, l, r, min(n + 1, u) - 1) + mod) % n                 mod n          << endl; n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n, m; n   cin >> m >> n; n   map<int, vector<pair<int, int>>> matrix; n   vector<int> cnt(n, m), mag(m, n); n   int cnt2 = m; n   for (int i = 0; i < m; ++i) { n     for (int j = 0; j < n; ++j) { n       int a; n       cin >> a; n       matrix[a].push_back(make_pair(j, i)); n     } n   } n   int ans = -1; n   for (auto &elem : matrix) { n     ans = elem.first; n     bool ok = 1; n     for (auto &pr : elem.second) { n       int i = pr.first, j = pr.second; n       --cnt[i]; n       --mag[j]; n       if (cnt[i] == 0) { n         ok = 0; n         break; n       } n       if (mag[j] == 1) --cnt2; n     } n     if (!ok || cnt2 == 0) break; n   } n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cout.tie(0); n   cin.tie(0); n   srand(time(NULL)); n   int tt = 1; n   cin >> tt; n   while (tt--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int up_div(int a, int b) { return a / b + (a % b != 0); } n int down_div(int a, int b) { return a / b; } n int main() { n   int a, b; n   cin >> a >> b; n   int res = 0; n   for (int k = 1; k <= a + b; ++k) { n     int d = (a + b) / k; n     int min_k = k; n     int max_k = (a + b) / d; n     res += (up_div(a, d + 1) <= down_div(a, d) && n             up_div(b, d + 1) <= down_div(b, d)) * n            (min(down_div(a, d) + down_div(b, d), max_k) - n             max(up_div(a, d + 1) + up_div(b, d + 1), min_k) + 1); n     k = max_k; n   } n   cout << res <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n const long long inf = 10e17 + 9; n const long double p = acos(-1); n int n, x; n vector<int> v[200009]; n int dis1[200009]; n int dis2[200009]; n void dfs1(int node, int p, int k) { n   dis1[node] = k; n   for (int i = 0; i < v[node].size(); i++) { n     int u = v[node][i]; n     if (u != p) dfs1(u, node, k + 1); n   } n } n void dfs2(int node, int p, int k) { n   dis2[node] = k; n   for (int i = 0; i < v[node].size(); i++) { n     int u = v[node][i]; n     if (u != p) dfs2(u, node, k + 1); n   } n } n int main() { n   cin >> n >> x; n   x--; n   for (int i = 0; i < n - 1; i++) { n     int a, b; n     cin >> a >> b, a--, b--; n     v[a].push_back(b), v[b].push_back(a); n   } n   dfs1(0, 0, 0); n   dfs2(x, x, 0); n   int mx = 0; n   for (int i = 0; i < n; i++) { n     int x = 0; n     if (dis2[i] < dis1[i]) x = dis1[i]; n     mx = max(mx, x); n   } n   cout << mx * 2 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 10; n long long m, n, t, a1, b1, cnta, cntb, b[maxn]; n struct point { n   long long x, y; n   point(long long x = 0, long long y = 0) : x(x), y(y) {} n   bool operator<(const point& p) const { n     return x < p.x || (x == p.x && y < p.y); n   } n } a[maxn]; n int main() { n   cin >> m; n   while (m--) { n     cnta = cntb = 0; n     cin >> n >> t >> a1 >> b1; n     for (long long i = 1; i <= n; i++) { n       cin >> b[i]; n       if (b[i]) n         cntb++; n       else n         cnta++; n     } n     for (long long i = 1; i <= n; i++) { n       long long x; n       cin >> x; n       a[i] = point(x, b[i]); n     } n     a[n + 1] = point(t + 1, 0); n     sort(a + 1, a + n + 2); n     long long ans = 0, cnt1 = 0, cnt2 = 0; n     for (int i = 1; i <= n + 1; i++) { n       long long sum = cnt1 * a1 + cnt2 * b1, res = a[i].x - sum - 1; n       if (res >= 0) { n         long long ta = min(cnta - cnt1, res / a1); n         res -= ta * a1; n         long long tb = min(cntb - cnt2, res / b1); n         ans = max(ans, cnt1 + cnt2 + ta + tb); n       } n       long long cnt = i; n       while (cnt <= n + 1 && a[cnt].x == a[i].x) { n         if (a[cnt].y) n           cnt2++; n         else n           cnt1++; n         cnt++; n       } n       i = cnt - 1; n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n const int N = 1e3 + 10; n const double eps = 1e-5; n int n; n struct Tarr { n   long long tarr[N][N]; n   Tarr() { n     for (int i = 0; i < N; i++) { n       for (int j = 0; j < N; j++) { n         tarr[i][j] = 0; n       } n     } n   } n   static int lowbit(int x) { return x & -x; } n   void add(int x, int y, long long val) { n     while (x <= n) { n       int p = y; n       while (p <= n) { n         tarr[x][p] ^= val; n         p += lowbit(p); n       } n       x += lowbit(x); n     } n   } n   long long query(int x, int y) { n     long long res = 0; n     while (x) { n       int p = y; n       while (p) { n         res ^= tarr[x][p]; n         p -= lowbit(p); n       } n       x -= lowbit(x); n     } n     return res; n   } n }; n Tarr an, ai, aj, aij; n long long query(int x, int y) { n   return (((x + 1) * (y + 1) % 2) * an.query(x, y)) ^ n          (((x + 1) % 2) * ai.query(x, y)) ^ (((y + 1) % 2) * aj.query(x, y)) ^ n          aij.query(x, y); n } n long long query(int x1, int y1, int x2, int y2) { n   return query(x2, y2) ^ query(x1 - 1, y2) ^ query(x2, y1 - 1) ^ n          query(x1 - 1, y1 - 1); n } n void add(int x, int y, long long val) { n   an.add(x, y, val); n   ai.add(x, y, (y % 2) * val); n   aj.add(x, y, (x % 2) * val); n   aij.add(x, y, (x * y % 2) * val); n } n void add(int x1, int y1, int x2, int y2, long long val) { n   add(x1, y1, val); n   add(x1, y2 + 1, val); n   add(x2 + 1, y1, val); n   add(x2 + 1, y2 + 1, val); n } n int main() { n   std::ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int m; n   cin >> n >> m; n   for (int i = 1; i <= m; i++) { n     int op; n     cin >> op; n     if (op == 2) { n       int x1, y1, x2, y2; n       long long v; n       cin >> x1 >> y1 >> x2 >> y2 >> v; n       add(x1, y1, x2, y2, v); n     } else { n       int x1, y1, x2, y2; n       cin >> x1 >> y1 >> x2 >> y2; n       cout << query(x1, y1, x2, y2) <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, hd, el; n char s[1000]; n struct E { n   char tag; n   int p[26]; n } e[1000000]; n void ins() { n   int i, j, k, l; n   for (i = 0, l = hd; s[i]; i++) { n     if (!e[l].p[s[i] -  a ]) e[l].p[s[i] -  a ] = el++; n     l = e[l].p[s[i] -  a ]; n   } n } n void dfs(int ei) { n   int i, j, c[5] = {0, 0, 0, 0, 0}; n   for (i = j = 0; i < 26; i++) { n     if (e[ei].p[i]) { n       j = 1; n       dfs(e[ei].p[i]); n       c[e[e[ei].p[i]].tag]++; n     } n   } n   if (!j) n     e[ei].tag = 1; n   else if (c[4] || (c[1] && c[2])) n     e[ei].tag = 3; n   else if (c[1]) n     e[ei].tag = 2; n   else if (c[2]) n     e[ei].tag = 1; n   else n     e[ei].tag = 4; n } n void init() { n   int i, j, k, l; n   hd = el = 0; n   el++; n   scanf( %d%d , &n, &m); n   for (i = 0; i < n; i++) { n     scanf( %s , s); n     ins(); n   } n   dfs(hd); n } n void solve() { n   if (e[hd].tag == 1 || e[hd].tag == 4) n     puts( Second ); n   else if (e[hd].tag == 3) n     puts( First ); n   else if (m & 1) n     puts( First ); n   else n     puts( Second ); n } n int main() { n   init(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int tree[10000][2]; n int lights; n void mark(int node, int l) { n   int p = node / 2; n   if (p == 0) return; n   tree[p][node % 2] = min(tree[p][node % 2], lights - l); n   mark(p, l); n } n int cont[10000]; n int main() { n   cin.tie(0); n   ios_base::sync_with_stdio(0); n   memset(tree, -1, sizeof(tree)); n   int n, a, p; n   cin >> n; n   int lim = (1 << (n + 1)) - 1; n   for (int i = 2; i <= lim; ++i) { n     cin >> a; n     p = i / 2; n     tree[p][i % 2] = a; n   } n   lights = 0; n   queue<int> Q; n   Q.push(1); n   Q.push(0); n   while (!Q.empty()) { n     int u = Q.front(); n     Q.pop(); n     int l = Q.front(); n     Q.pop(); n     if (tree[u][0] == -1) { n       lights = max(lights, l); n       cont[u] = l; n       continue; n     } n     Q.push(2 * u); n     Q.push(tree[u][0] + l); n     Q.push(2 * u + 1); n     Q.push(tree[u][1] + l); n     tree[u][0] = tree[u][1] = 0x3fffffff; n   } n   for (int i = 1 << n; i <= lim; ++i) mark(i, cont[i]); n   int ans = 0; n   Q.push(1); n   Q.push(0); n   while (!Q.empty()) { n     int u = Q.front(); n     Q.pop(); n     int l = Q.front(); n     Q.pop(); n     if (tree[u][0] == -1) continue; n     ans += tree[u][0] + tree[u][1] - 2 * l; n     Q.push(2 * u); n     Q.push(tree[u][0]); n     Q.push(2 * u + 1); n     Q.push(tree[u][1]); n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     vector<int> a(n), ans; n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n     } n     auto cyc = [&](int idx) { n       swap(a[idx + 2], a[idx]); n       swap(a[idx + 1], a[idx + 2]); n       ans.push_back(idx); n     }; n     if (n == 3) { n       if (!is_sorted(a.begin(), a.end())) cyc(0); n       if (!is_sorted(a.begin(), a.end())) cyc(0); n     } n     for (int i = 0; i + 2 < n; i++) { n       vector<pair<int, int>> b(n); n       for (int j = 0; j < n; j++) { n         b[j] = {a[j], j}; n       } n       sort(b.begin(), b.end()); n       if (i < b[i].second) { n         for (int k = b[i].second - 2; k >= i; k -= 2) { n           cyc(k); n         } n         if ((b[i].second - i) & 1) { n           cyc(i); n           cyc(i); n         } n       } n     } n     if (a[n - 2] > a[n - 1]) { n       int x = -1; n       for (int i = 0; i + 2 < n; i++) { n         if (a[i] == a[i + 1]) { n           x = i; n         } n       } n       if (x != -1) { n         for (int i = x; i < n - 4; i++) { n           cyc(i); n         } n         cyc(n - 3); n         cyc(n - 4); n         for (int i = n - 5; i >= x; i--) { n           cyc(i); n           cyc(i); n         } n       } n     } n     if (a[n - 2] > a[n - 1]) cyc(n - 3); n     if (is_sorted(a.begin(), a.end()) && ans.size() <= n * n) { n       cout << ans.size() <<   n ; n       for (auto i : ans) cout << i + 1 <<    ; n       cout <<   n ; n     } else { n       cout << -1 <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e5 + 7; n vector<long long> v[N]; n long long vis[N], prt[N], bip[N], cs, ce; n void dfs(long long ver, long long par) { n   bip[ver] = (!bip[par]); n   vis[ver] = 1; n   prt[ver] = par; n   for (auto it : v[ver]) { n     if (vis[it] == 2 || it == par) continue; n     if (vis[it] == 1) { n       cs = it; n       ce = ver; n       break; n     } n     dfs(it, ver); n   } n   vis[ver] = 2; n } n int32_t main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   long long n, m, k; n   cin >> n >> m >> k; n   for (long long i = (long long)(1); i <= (long long)(m); i++) { n     long long x, y; n     cin >> x >> y; n     if (x > k || y > k) continue; n     v[x].push_back(y); n     v[y].push_back(x); n   } n   for (long long i = (long long)(1); i <= (long long)(k); i++) { n     if (vis[i]) continue; n     dfs(i, 0); n   } n   if (cs) { n     cout << 2 <<   n ; n     vector<long long> ans; n     while (cs != ce) { n       ans.push_back(ce); n       ce = prt[ce]; n     } n     ans.push_back(ce); n     cout << ans.size() <<   n ; n     for (auto it : ans) cout << it <<    ; n   } else { n     cout << 1 <<   n ; n     long long kk = k / 2 + k % 2; n     long long tmp = count(bip + 1, bip + k + 1, 0); n     if (tmp >= kk) { n       for (long long i = (long long)(1); i <= (long long)(k); i++) { n         if (kk > 0 && bip[i] == 0) { n           cout << i <<    ; n           kk--; n         } n       } n     } else { n       for (long long i = (long long)(1); i <= (long long)(k); i++) { n         if (kk > 0 && bip[i]) { n           cout << i <<    ; n           kk--; n         } n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, l; n   cin >> n >> l; n   double a[n]; n   for (int i = 0; i < n; i++) cin >> a[i]; n   sort(&a[0], &a[n]); n   float x = a[0] - 0; n   float y = l - a[n - 1]; n   for (int i = 0; i < n - 1; i++) a[i] = (a[i + 1] - a[i]) / 2; n   if (x > y) n     a[n - 1] = x; n   else n     a[n - 1] = y; n   sort(&a[0], &a[n]); n   cout << std::fixed << a[n - 1]; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 2; n const int mod = 100003; n const int INF = 0x3f3f3f; n int n, m, x, y; n int vis[N]; n struct node { n   int x, r, i, v; n } tar[N]; n bool cmp1(node &x, node &y) { return x.x < y.x; } n bool cmp2(node &x, node &y) { return x.i < y.i; } n int find(int x) { n   int l, mid, r; n   l = 1, r = n; n   while (r - l > 1) { n     mid = (l + r) / 2; n     if (tar[mid].x == x) return mid; n     if (tar[mid].x < x) l = mid; n     if (tar[mid].x > x) r = mid; n   } n   return l; n } n bool chk(int p, int x, int y) { n   if ((tar[p].x - x) * (tar[p].x - x) + y * y <= tar[p].r * tar[p].r) n     return true; n   else n     return false; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n; n   memset(vis, 0, sizeof(vis)); n   ; n   for (int i = 1; i <= n; i++) { n     cin >> tar[i].x >> tar[i].r; n     tar[i].v = -1; n     tar[i].i = i; n   } n   sort(tar + 1, tar + 1 + n, cmp1); n   cin >> m; n   int pos; n   int sum = 0; n   for (int i = 1; i <= m; i++) { n     cin >> x >> y; n     pos = find(x); n     if (tar[pos - 1].v == -1 && chk(pos - 1, x, y)) { n       tar[pos - 1].v = i; n       sum++; n     } n     if (tar[pos].v == -1 && chk(pos, x, y)) { n       tar[pos].v = i; n       sum++; n     } n     if (tar[pos + 1].v == -1 && chk(pos + 1, x, y)) { n       tar[pos + 1].v = i; n       sum++; n     } n   } n   sort(tar + 1, tar + 1 + n, cmp2); n   cout << sum << endl; n   for (int i = 1; i <= n; i++) { n     cout << tar[i].v <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   if (s[1] ==  1 ) { n     if (s[0] ==  a  || s[0] ==  h ) { n       cout <<  3  << endl; n     } else { n       cout <<  5  << endl; n     } n   } else if (s[1] ==  8 ) { n     if (s[0] ==  a  || s[0] ==  h ) { n       cout <<  3  << endl; n     } else { n       cout <<  5  << endl; n     } n   } else { n     if (s[0] ==  a  || s[0] ==  h ) { n       cout <<  5  << endl; n     } else { n       cout <<  8  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Point { n   double x, y; n   Point() {} n   Point(double a, double b) { x = a, y = b; } n }; n const double eps = 1e-10; n Point operator+(Point A, Point B) { return Point(A.x + B.x, A.y + B.y); } n Point operator-(Point A, Point B) { return Point(A.x - B.x, A.y - B.y); } n Point operator*(Point A, double p) { return Point(A.x * p, A.y * p); } n Point operator/(Point A, double p) { return Point(A.x / p, A.y / p); } n bool operator<(const Point &a, const Point &b) { n   return a.x < b.x || (a.x == b.x && a.y < b.y); n } n int dcmp(double x) { n   if (fabs(x) < eps) n     return 0; n   else n     return x < 0 ? -1 : 1; n } n bool operator==(const Point &a, const Point &b) { n   return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0; n } n double Dot(Point A, Point B) { return A.x * B.x + A.y * B.y; } n double Length(Point A) { return sqrt(Dot(A, A)); } n double Angle(Point A, Point B) { n   return acos(Dot(A, B) / Length(A) / Length(B)); n } n double Cross(Point A, Point B) { return A.x * B.y - A.y * B.x; } n double Area2(Point A, Point B, Point C) { return Cross(B - A, C - A); } n Point Rotate(Point A, double rad) { n   return Point(A.x * cos(rad) - A.y * sin(rad), n                A.x * sin(rad) + A.y * cos(rad)); n } n Point Jd(Point P, Point v, Point Q, Point w) { n   Point u = P - Q; n   double t = Cross(w, u) / Cross(v, w); n   return P + v * t; n } n double Dtl(Point P, Point A, Point B) { n   Point v1 = B - A, v2 = P - A; n   return fabs(Cross(v1, v2)) / Length(v1); n } n double Dts(Point P, Point A, Point B) { n   if (A == B) return Length(P - A); n   Point v1 = B - A, v2 = P - A, v3 = P - B; n   if (dcmp(Dot(v1, v2) < 0)) n     return Length(v2); n   else if (dcmp(Dot(v1, v3)) > 0) n     return Length(v3); n   else n     return fabs(Cross(v1, v2)) / Length(v1); n } n Point Gjp(Point P, Point A, Point B) { n   Point v = B - A; n   return A + v * (Dot(v, P - A)) / (Dot(v, v)); n } n bool Spi(Point a1, Point a2, Point b1, Point b2) { n   double c1 = Cross(a2 - a1, b1 - a1), c2 = Cross(a2 - a1, b2 - a1), n          c3 = Cross(b2 - b1, a1 - b1), c4 = Cross(b2 - b1, a2 - a1); n   return dcmp(c1) * dcmp(c2) < 0 && dcmp(c3) * dcmp(c4) < 0; n } n bool Onseg(Point p, Point a1, Point a2) { n   return dcmp(Cross(a1 - p, a2 - p)) == 0 && dcmp(Dot(a1 - p, a2 - p)) < 0; n } n double Parea(Point *p, int n) { n   double area = 0; n   for (int i = 1; i <= n; i++) area += Cross(p[i] - p[0], p[i + 1] - p[0]); n   return area / 2; n } n bool cmp(Point a, Point b) { n   if (fabs(a.x - b.x) > eps) n     return a.x + eps < b.x; n   else n     return a.y + eps < b.y; n } n struct Circle { n   Point o; n   double r; n   Circle() {} n   Circle(Point _o, double _r) { o = _o, r = _r; } n   friend vector<Point> operator&(const Circle &c1, const Circle &c2) { n     double d = Length(c1.o - c2.o); n     if (d > c1.r + c2.r + eps || d < fabs(c1.r - c2.r) - eps) n       return vector<Point>(); n     double dt = (c1.r * c1.r - c2.r * c2.r) / d, d1 = (d + dt) / 2.0; n     Point dir = (c2.o - c1.o) / d, pcrs = c1.o + dir * d1; n     dt = sqrt(max(0.0, c1.r * c1.r - d1 * d1)); n     swap(dir.x, dir.y), dir.x = -dir.x; n     return vector<Point>{pcrs + dir * dt, pcrs - dir * dt}; n   } n } p[10]; n int f[10], rk[10], n; n int find(int x) { n   if (f[x] != x) n     return f[x] = find(f[x]); n   else n     return x; n } n void merge(int i, int j) { n   int x = find(i), y = find(j); n   if (rk[x] > rk[y]) n     f[y] = x; n   else { n     f[x] = y; n     if (rk[x] == rk[y]) rk[y]++; n   } n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) f[i] = i, rk[i] = 0; n   for (int i = 1; i <= n; i++) cin >> p[i].o.x >> p[i].o.y >> p[i].r; n   int e = 0, v = 0, c = 0; n   vector<Point> all; n   for (int i = 1; i <= n; i++) { n     vector<Point> tmp1; n     for (int j = 1; j <= n; j++) { n       if (j == i) continue; n       vector<Point> tmp2 = p[i] & p[j]; n       if (tmp2.size()) merge(i, j); n       tmp1.insert(tmp1.end(), tmp2.begin(), tmp2.end()); n       all.insert(all.end(), tmp2.begin(), tmp2.end()); n     } n     sort(tmp1.begin(), tmp1.end(), cmp); n     e += unique(tmp1.begin(), tmp1.end()) - tmp1.begin(); n   } n   sort(all.begin(), all.end(), cmp); n   v += unique(all.begin(), all.end()) - all.begin(); n   set<int> st; n   for (int i = 1; i <= n; i++) { n     st.insert(find(i)); n   } n   cout << e - v + st.size() + 1 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n struct Node { n   int l, r, b, No; n   bool operator<(const Node &t) const { n     if (b != t.b) return b < t.b; n     return r < t.r; n   } n }; n const int N = 200005; n const int M = 1000005; n int n, Q; n int seq[N]; n Node q[N]; n int cnt[M]; n long long ans[N]; n long long &cal(int x, int &l, int &r, long long &ret) { n   int L = q[x].l, R = q[x].r; n   while (l > L) { n     --l; n     int t = seq[l]; n     ret += 2LL * cnt[t] * t + t; n     cnt[t]++; n   } n   while (r < R) { n     ++r; n     int t = seq[r]; n     ret += 2LL * cnt[t] * t + t; n     cnt[t]++; n   } n   while (l < L) { n     int t = seq[l]; n     ret += -2LL * cnt[t] * t + t; n     ++l; n     cnt[t]--; n   } n   while (r > R) { n     int t = seq[r]; n     ret += -2LL * cnt[t] * t + t; n     --r; n     cnt[t]--; n   } n   return ret; n } n void solve() { n   int B = (int)sqrt(1.0 * n); n   memset(cnt, 0, sizeof(cnt)); n   for (int i = 1; i <= Q; ++i) { n     scanf( %d %d , &q[i].l, &q[i].r); n     q[i].b = q[i].l / B; n     q[i].No = i; n   } n   sort(q + 1, q + 1 + Q); n   int l = q[1].l, r = q[1].r; n   long long ret = 0; n   for (int i = l; i <= r; ++i) { n     int t = seq[i]; n     ret += 2LL * cnt[t] * t + t; n     cnt[t]++; n   } n   ans[q[1].No] = ret; n   for (int i = 2; i <= Q; ++i) { n     ans[q[i].No] = cal(i, l, r, ret); n   } n   for (int i = 1; i <= Q; ++i) { n     printf( %I64d n , ans[i]); n   } n } n int main() { n   while (scanf( %d %d , &n, &Q) != EOF) { n     for (int i = 1; i <= n; ++i) { n       scanf( %d , &seq[i]); n     } n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     string s; n     cin >> s; n     int l = s.length(); n     vector<int> v(26, 0); n     for (int i = 0; i < l; i++) { n       if (s[i] == s[i + 1]) { n         i++; n       } else { n         v[s[i] -  a ] = 1; n       } n     } n     for (int i = 0; i < 26; i++) { n       if (v[i]) { n         cout << (char)(i +  a ); n       } n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void __print(int x) {cerr << x;} n void __print(long x) {cerr << x;} n void __print(long long x) {cerr << x;} n void __print(unsigned x) {cerr << x;} n void __print(unsigned long x) {cerr << x;} n void __print(unsigned long long x) {cerr << x;} n void __print(float x) {cerr << x;} n void __print(double x) {cerr << x;} n void __print(long double x) {cerr << x;} n void __print(char x) {cerr <<      << x <<     ;} n void __print(const char *x) {cerr <<     << x <<    ;} n void __print(const string &x) {cerr <<     << x <<    ;} n void __print(bool x) {cerr << (x ?  true  :  false );} n  n template<typename T, typename V> n void __print(const pair<T, V> &x) {cerr <<  { ; __print(x.first); cerr <<  , ; __print(x.second); cerr <<  } ;} n template<typename T> n void __print(const T &x) {int f = 0; cerr <<  { ; for (auto &i: x) cerr << (f++ ?  ,  :   ), __print(i); cerr <<  } ;} n void _print() {cerr <<  ] n ;} n template <typename T, typename... V> n void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr <<  ,  ; _print(v...);} n #ifndef ONLINE_JUDGE n #define debug(x...) cerr <<  [  << #x <<  ] = [ ; _print(x) n #else n #define debug(x...) n #endif n  n #define ll long long int n const int mod = 1000000007; n int mpow(int b, int e); n  n void solve(){ n  int n; cin>>n;  n  vector<int> even, odd;  n  for(int i=0; i<n;i++){ n   int x; cin>>x;  n   if(x&1) odd.push_back(x);  n   else even.push_back(x);  n  } n  n  for(auto i:odd) cout<<i<<   ;  n  for(auto i:even) cout<<i<<   ;  n  cout<<endl; n  n } n  n int main(){ n     ios_base::sync_with_stdio(false); n     cin.tie(0);cout.tie(0); n     int t=1; n     cin>>t; n     for(int tt=1; tt<=t; tt++){ n         //cout <<  Case # <<tt<< :  ; n         solve(); n     } n     return 0; n } n  n //modular exponentiation n int mpow(int base, int exp) { n   base %= mod; n   int result = 1; n   while (exp > 0) { n     if (exp & 1) result = ((ll)result * base) % mod; n     base = ((ll)base * base) % mod; n     exp >>= 1; n   } n   return result; n }


#include <bits/stdc++.h> n using namespace std; n long long n, k; n long long calc(long long n, long long k) { n   map<long long, long long> l, r; n   l.clear(); n   r.clear(); n   long long cnt[2]; n   cnt[0] = cnt[1] = 0; n   if (k == 1) return n / 2; n   k--; n   l[n / 2] = 1; n   r[n / 2 + (n % 2)] = 1; n   while (1) { n     if ((*l.rbegin()).first / 2 >= (*r.rbegin()).first / 2) { n       if ((*l.rbegin()).second >= k) return calc(n / 2, k + cnt[0]); n       k -= (*l.rbegin()).second; n       cnt[0] += (*l.rbegin()).second; n       l[(*l.rbegin()).first / 2] += (*l.rbegin()).second; n       l[(*l.rbegin()).first / 2 + ((*l.rbegin()).first % 2)] += n           (*l.rbegin()).second; n       l.erase((*l.rbegin()).first); n     } else { n       if ((*r.rbegin()).second >= k) n         return calc(n / 2 + (n % 2), k + cnt[1]) + n / 2; n       k -= (*r.rbegin()).second; n       cnt[1] += (*r.rbegin()).second; n       r[(*r.rbegin()).first / 2] += (*r.rbegin()).second; n       r[(*r.rbegin()).first / 2 + ((*r.rbegin()).first % 2)] += n           (*r.rbegin()).second; n       r.erase((*r.rbegin()).first); n     } n   } n } n int main() { n   cin >> n >> k; n   if (k == 1) { n     cout << 1; n     return 0; n   } n   if (k == 2) { n     cout << n; n     return 0; n   } n   cout << 1 + calc(n - 1, k - 2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int const N = 250000, B = 18; n vector<int> tr1[N + 1], tr2[N + 1]; n int n, dp[N + 1], pa[N + 1][B], gr[N + 1]; n int P(int v) { return gr[v] ? gr[v] = P(gr[v]) : v; } n void pl(int v = 1, int p = 0) { n   dp[v] = dp[p] + 1; n   pa[v][0] = p; n   int k = 1, z; n   while (k < B && (z = pa[v][k - 1])) pa[v][k] = pa[z][k - 1], ++k; n   for (int u : tr1[v]) n     if (u != p) pl(u, v); n } n int lca(int a, int b) { n   if (dp[a] < dp[b]) swap(a, b); n   int d = dp[a] - dp[b], j = 0; n   while (d) { n     if (d & 1) a = pa[a][j]; n     ++j; n     d >>= 1; n   } n   if (a == b) return a; n   for (int i = B - 1; i >= 0; --i) n     if (pa[a][i] != pa[b][i]) a = pa[a][i], b = pa[b][i]; n   return pa[a][0]; n } n void J(int a, int b) { n   printf( %d %d , a, b); n   gr[a] = b; n } n void kl(int a, int b) { n   a = P(a); n   int c = lca(a, b); n   if (c != a) n     J(a, pa[a][0]); n   else { n     for (int i = B - 1; i >= 0; --i) n       if (dp[pa[b][i]] > dp[c] && P(pa[b][i]) != a) b = pa[b][i]; n     J(b, pa[b][0]); n   } n } n void go(int v = 1, int p = 0) { n   for (int u : tr2[v]) n     if (u != p) go(u, v); n   if (p) { n     kl(v, p); n     printf(  %d %d n , v, p); n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i < (int)(n); ++i) { n     int a, b; n     scanf( %d%d , &a, &b); n     tr1[a].push_back(b); n     tr1[b].push_back(a); n   } n   for (int i = 1; i < (int)(n); ++i) { n     int a, b; n     scanf( %d%d , &a, &b); n     tr2[a].push_back(b); n     tr2[b].push_back(a); n   } n   pl(); n   printf( %d n , n - 1); n   go(); n } n


#include <bits/stdc++.h> n using namespace std; n deque<int> enumeration; n deque<int> cutOrder; n struct Edge { n   Edge(int from, int to, int ind) : from(from), to(to), ind(ind) {} n   int from, to, ind; n   shared_ptr<Edge> nxt = nullptr; n   shared_ptr<Edge> rev = nullptr; n   shared_ptr<Edge> flip = nullptr; n }; n void search(shared_ptr<Edge> e, int end) { n   if (e->flip == nullptr) { n     enumeration.push_back(e->from); n     if (e->to != end) { n       search(e->nxt, end); n     } n   } else { n     search(e->flip->rev->nxt, e->to); n     if (e->to != end) { n       search(e->nxt, end); n     } n   } n   if (e->to == end) { n     cutOrder.push_back(e->ind); n   } n } n auto hashf = [](pair<int, int> p) { return p.first + (p.second << 15); }; n unordered_map<pair<int, int>, shared_ptr<Edge>, decltype(hashf)> edgeSet(1000, n                                                                          hashf); n shared_ptr<Edge> addFlip(shared_ptr<Edge> e) { n   pair<int, int> p(e->from, e->to); n   shared_ptr<Edge> flip = edgeSet[p]; n   if (flip == nullptr) { n     edgeSet[p] = e; n   } else { n     assert(flip->flip == nullptr); n     e->flip = flip; n     flip->flip = e; n   } n   return e; n } n void addTriangle(int a, int b, int c, int i) { n   shared_ptr<Edge> e1, e2, e3, e1r, e2r, e3r; n   e1 = make_shared<Edge>(a, b, i); n   e2 = make_shared<Edge>(b, c, i); n   e3 = make_shared<Edge>(c, a, i); n   e1->nxt = e2; n   e2->nxt = e3; n   e3->nxt = e1; n   e1r = make_shared<Edge>(b, a, i); n   e2r = make_shared<Edge>(c, b, i); n   e3r = make_shared<Edge>(a, c, i); n   e1r->nxt = e3r; n   e2r->nxt = e1r; n   e3r->nxt = e2r; n   e1->rev = e1r; n   e2->rev = e2r; n   e3->rev = e3r; n   e1r->rev = e1; n   e2r->rev = e2; n   e3r->rev = e3; n   addFlip(e1); n   addFlip(e2); n   addFlip(e3); n   addFlip(e1r); n   addFlip(e2r); n   addFlip(e3r); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int t, n; n   cin >> t; n   for (int caseNum = 0; caseNum < t; caseNum++) { n     cin >> n; n     enumeration.clear(); n     cutOrder.clear(); n     edgeSet.clear(); n     for (int i = 1; i <= n - 2; i++) { n       int a, b, c; n       cin >> a >> b >> c; n       addTriangle(a, b, c, i); n     } n     shared_ptr<Edge> e1 = edgeSet.begin()->second; n     search(e1, e1->from); n     for (auto e : enumeration) { n       cout << e <<    ; n     } n     cout <<   n ; n     for (auto e : cutOrder) { n       cout << e <<    ; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int slimes, values; n   vector<int> vec; n   cin >> slimes; n   for (int i = 0; i < slimes; i++) { n     vec.push_back(1); n     while (vec.size() > 1 && vec[vec.size() - 1] == vec[vec.size() - 2]) { n       vec.pop_back(); n       vec[vec.size() - 1] += 1; n     } n   } n   for (int j = 0; j < vec.size(); j++) { n     cout << vec[j] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, x; n   cin >> n >> x; n   long long a[n], b[n]; n   for (int i = 0; i < n; ++i) cin >> a[i]; n   for (int i = 0; i < n; ++i) cin >> b[i]; n   sort(a, a + n, greater<int>()); n   sort(b, b + n); n   long long ans = 0, f, id = 0; n   for (int i = 0; i < n; ++i) { n     f = 0; n     while (id < n) { n       if (a[i] + b[id] >= x) { n         f = 1; n         ++id; n         break; n       } n       ++id; n     } n     if (f) n       ++ans; n     else n       break; n   } n   cout <<  1   << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, r, s1, s2, d; n   cin >> n; n   r = ceil(double(sqrt(n))); n   s1 = r * r; n   s2 = (r - 1) * (r - 1); n   d = s1 - s2; n   d = d / 2; n   d = s1 - d; n   if (n < d) { n     cout << (r * 2) - 1; n   } else { n     cout << r * 2; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n const int inf = 0x3f3f3f3f; n const int maxn = 1e5 + 5; n void Solution() { n   int n; n   cin >> n; n   cout << (n / 2) + 1 <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) Solution(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   long long x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n int n; n int a[2000010]; n int main() { n   while (~scanf( %d , &n)) { n     for (int i = 1; i <= n; i++) a[i] = i; n     for (int k = 2; k <= n; k++) { n       int ed = n + k - 1, rp = n / k + (n % k != 0); n       for (int t = k - 1 + (rp - 1) * k; t >= k - 1; t -= k) { n         swap(a[ed], a[t]); n         ed = t; n       } n     } n     for (int i = n; i <= 2 * n - 1; i++) printf( %d  , a[i]); n     puts(  ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long double EPS = 1e-8; n const long double INF = 1e12; n const long double PI = acos(-1); n struct L : array<complex<long double>, 2> { n   L(const complex<long double>& a, const complex<long double>& b) { n     at(0) = a; n     at(1) = b; n   } n   L() {} n }; n namespace std { n bool operator<(const complex<long double>& a, const complex<long double>& b) { n   return !(abs((a.real()) - (b.real())) < EPS) ? a.real() < b.real() n                                                : a.imag() + EPS < b.imag(); n } n bool operator==(const complex<long double>& a, const complex<long double>& b) { n   return abs(a - b) < EPS; n } n }  // namespace std n long double dot(complex<long double> a, complex<long double> b) { n   return (conj(a) * b).real(); n } n long double cross(complex<long double> a, complex<long double> b) { n   return (conj(a) * b).imag(); n } n bool intersectLP(const L& l, const complex<long double>& p) { n   return abs(cross(l[1] - p, l[0] - p)) < EPS; n } n bool strictItsLS(const L& l, const L& s) { n   return cross(l[1] - l[0], s[0] - l[0]) * cross(l[1] - l[0], s[1] - l[0]) < n          -EPS; n } n bool isParallel(const complex<long double>& a, const complex<long double>& b) { n   return abs(cross(a, b)) < EPS; n } n bool isParallel(const L& a, const L& b) { n   return isParallel(a[1] - a[0], b[1] - b[0]); n } n complex<long double> crosspointLL(const L& l, const L& m) { n   long double A = cross(l[1] - l[0], m[1] - m[0]); n   long double B = cross(l[1] - l[0], l[1] - m[0]); n   return m[0] + B / A * (m[1] - m[0]); n } n long double getarea(const vector<complex<long double> >& poly) { n   long double ret = 0; n   for (int i = 0; i < (int)poly.size(); i++) { n     ret += cross(poly[i], poly[(i + 1) % poly.size()]); n   } n   return ret * 0.5; n } n bool in_corner(const complex<long double>& p, n                const vector<complex<long double> >& v) { n   bool s1 = cross(v[1] - v[0], p - v[0]) > -EPS; n   bool s2 = cross(v[2] - v[1], p - v[1]) > -EPS; n   return (cross(v[1] - v[0], v[2] - v[0]) > -EPS) ? s1 and s2 : s1 or s2; n } n long double solve(vector<complex<long double> >& v, L cut) { n   int n = v.size(); n   complex<long double> cdir = cut[1] - cut[0]; n   vector<complex<long double> > cps; n   for (int i = 0; i < n; i++) { n     L edge(v[i], v[(i + 1) % n]); n     if (strictItsLS(cut, edge) and !isParallel(cut, edge)) { n       cps.push_back(crosspointLL(cut, edge)); n     } n     if (intersectLP(cut, v[i])) { n       vector<complex<long double> > p{v[(i - 1 + n) % n], v[i], v[(i + 1) % n]}; n       if (in_corner(p[1] + cdir, p) != in_corner(p[1] - cdir, p)) { n         cps.push_back(v[i]); n       } n     } n   } n   sort(cps.begin(), cps.end()); n   long double res = 0; n   for (int i = 0; i < (int)cps.size() - 1; i += 2) { n     res += abs(cps[i + 1] - cps[i]); n   } n   return res; n } n int main() { n   int n, m; n   cin >> n >> m; n   vector<complex<long double> > v(n); n   for (int i = 0; i < n; i++) { n     long double x, y; n     cin >> x >> y; n     v[i] = complex<long double>(x, y); n   } n   if (getarea(v) < 0) { n     reverse(v.begin(), v.end()); n   } n   cout << fixed << setprecision(10); n   for (int i = 0; i < m; i++) { n     long double xs, ys, xt, yt; n     cin >> xs >> ys >> xt >> yt; n     cout << solve(v, n                   L(complex<long double>(xs, ys), complex<long double>(xt, yt))) n          << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n const int MAXX = 2e6 + 10; n long long phi(long long n) { n   long long ret = n; n   for (long long i = 2; i * i <= n; i++) { n     if (n % i == 0) { n       while (n % i == 0) n /= i; n       ret -= ret / i; n     } n   } n   if (n > 1) ret -= ret / n; n   return ret; n } n int main() { n   long long n, k; n   scanf( %lld %lld , &n, &k); n   k = (k + 1) / 2; n   long long ans = n; n   while (k--) { n     ans = phi(ans); n     if (ans == 1) break; n   } n   printf( %lld , ans % mod); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2e5 + 7; n const long long inf = 0x3f3f3f3f; n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   long long t; n   cin >> t; n   while (t--) { n     double pi = 3.1415926535897932384626433832795028841971, n; n     cin >> n; n     long long sum = n / 2; n     double x = 0.5 / tan(pi / (n * 2)), y = 0.5 / sin(pi / (n * 2)); n     printf( %.10lf n , x * 2); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool comp(pair<long long, long long> a, pair<long long, long long> b) { n   return a.first > b.first; n } n long long findBest(vector<pair<long long, long long> > &ps, long long x) { n   long long res = 0; n   for (long long i = 0; i < ps.size(); i++) { n     long long num = ps[i].second; n     long long diff = ps[i].first; n     if (x - num >= 0) { n       res += (num * diff); n       x -= num; n     } else { n       res += (x * diff); n       break; n     } n   } n   return res; n } n int main() { n   long long n, s; n   cin >> n >> s; n   vector<pair<long long, long long> > ps; n   long long total = 0; n   long long positives = 0; n   long long pieces = 0; n   for (long long i = 0; i < n; i++) { n     long long num, a, b; n     cin >> num >> a >> b; n     ps.push_back(make_pair(a - b, num)); n     total += num * b; n     pieces += num; n     if (a - b > 0) { n       positives += num; n     } n   } n   sort(ps.begin(), ps.end(), comp); n   long long pizzas = (pieces % s == 0) ? (pieces / s) : (pieces / s + 1); n   long long extra = pizzas * s - pieces; n   long long best = total; n   if (positives > 0) { n     best = max(best, findBest(ps, positives / s * s) + total); n     if (positives % s != 0) { n       long long x = max(positives, (positives / s + 1) * s - extra); n       best = max(best, findBest(ps, x) + total); n     } n   } n   cout << best << endl; n   return 0; n } n


#include <bits/stdc++.h> n using ll = long long; n using namespace std; n int n, k, a[110]; n int main() { n   ios::sync_with_stdio(false); n   cin >> n >> k; n   for (int i = 0; i < k; ++i) cin >> a[i]; n   vector<int> s; n   for (int i = 1; i <= n; ++i) s.push_back(i); n   int curr_leader = 0; n   for (int i = 0; i < k; ++i) { n     int elim = (curr_leader + a[i]) % n; n     cout << s[elim] <<    ; n     s.erase(s.begin() + elim); n     curr_leader = elim; n     n--; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n, k; n   string s; n   cin >> k; n   vector<long long> cnt(10, 0); n   for (long long i = 0; i < 4; i++) { n     cin >> s; n     for (long long j = 0; s[j]; j++) { n       if (s[j] >=  0  && s[j] <=  9 ) cnt[s[j] -  0 ]++; n     } n   } n   for (long long i = 0; i < 10; i++) { n     if (cnt[i] > 2 * k) { n       cout <<  NO ; n       return; n     } n   } n   cout <<  YES ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long t = 1, n, a, b, m; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 2; n long long gcd(long long a, long long b) { n   if (b > a) { n     return gcd(b, a); n   } n   if (b == 0) { n     return a; n   } n   return gcd(b, a % b); n } n long long expo(long long a, long long b, long long mod) { n   long long res = 1; n   while (b > 0) { n     if (b & 1) res = (res * a) % mod; n     a = (a * a) % mod; n     b = b >> 1; n   } n   return res; n } n long long mminvprime(long long a, long long b) { return expo(a, b - 2, b); } n vector<long long> sieve(int n) { n   int* arr = new int[n + 1](); n   vector<long long> vect; n   for (int i = 2; i <= n; i++) n     if (arr[i] == 0) { n       vect.push_back(i); n       for (int j = 2 * i; j <= n; j += i) arr[j] = 1; n     } n   return vect; n } n long long mod_add(long long a, long long b, long long m) { n   a = a % m; n   b = b % m; n   return (((a + b) % m) + m) % m; n } n long long mod_mul(long long a, long long b, long long m) { n   a = a % m; n   b = b % m; n   return (((a * b) % m) + m) % m; n } n long long mod_sub(long long a, long long b, long long m) { n   a = a % m; n   b = b % m; n   return (((a - b) % m) + m) % m; n } n long long mod_div(long long a, long long b, long long m) { n   a = a % m; n   b = b % m; n   return (mod_mul(a, mminvprime(b, m), m) + m) % m; n } n int fact[N]; n void precalc() { n   fact[0] = 1; n   for (int i = 1; i < N; i++) { n     fact[i] = mod_mul(fact[i - 1], i, 1000000007); n   } n } n long long mod(long long x) { n   return ((x % 1000000007 + 1000000007) % 1000000007); n } n long long inv(long long x) { return expo(x, 1000000007 - 2, 1000000007); } n long long divide(long long a, long long b) { n   return mod_mul(a, inv(b), 1000000007); n } n long long nCr(long long n, long long r) { n   return divide(fact[n], mod_mul(fact[r], fact[n - r], 1000000007)); n } n long long computeXOR(long long n) { n   if (n % 4 == 0) return n; n   if (n % 4 == 1) return 1; n   if (n % 4 == 2) return n + 1; n   return 0; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     int a, b; n     cin >> a >> b; n     int pXor; n     if (a % 4 == 1) { n       pXor = a - 1; n     } else if (a % 4 == 2) { n       pXor = 1; n     } else if (a % 4 == 3) { n       pXor = a; n     } else { n       pXor = 0; n     } n     if (pXor == b) { n       cout << a <<   n ; n     } else if ((pXor ^ b) != a) { n       cout << a + 1 <<   n ; n     } else { n       cout << a + 2 <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200005; n const int INF = 0x3f3f3f3f; n int d, n, m; n struct Sta { n   int x, p; n   Sta() {} n   Sta(int x, int p) : x(x), p(p) {} n   void read() { scanf( %d%d , &x, &p); } n   bool operator<(const Sta& c) const { return x < c.x; } n } p[N]; n struct Node { n   int Min, Minid; n } node[N << 2]; n void pushup(int x) { n   node[x].Min = min(node[(x << 1)].Min, node[(x << 1) | 1].Min); n   if (node[x].Min == node[(x << 1) | 1].Min) n     node[x].Minid = node[(x << 1) | 1].Minid; n   if (node[x].Min == node[(x << 1)].Min) node[x].Minid = node[(x << 1)].Minid; n } n void build(int L = 1, int R = m, int x = 1) { n   if (L == R) { n     node[x].Min = p[L].p; n     node[x].Minid = L; n     return; n   } n   int mid = (L + R) >> 1; n   build(L, mid, (x << 1)); n   build(mid + 1, R, (x << 1) | 1); n   pushup(x); n } n int Min, Minid; n void getMin(int l, int r, int L = 1, int R = m, int x = 1) { n   if (L >= l && R <= r) { n     if (Min > node[x].Min) { n       Min = node[x].Min; n       Minid = node[x].Minid; n     } n     return; n   } n   int mid = (L + R) >> 1; n   if (l <= mid) getMin(l, r, L, mid, (x << 1)); n   if (r > mid) getMin(l, r, mid + 1, R, (x << 1) | 1); n } n long long solve() { n   int s = 0; n   long long ans = 0; n   int yu = 0; n   while (s < m) { n     int v = upper_bound(p + s + 1, p + m + 1, Sta(p[s].x + n, 0)) - p - 1; n     if (v == s) return -1; n     Min = INF; n     getMin(s + 1, v); n     if (Min > p[s].p) { n       ans += 1LL * (n - yu) * p[s].p; n       yu = n; n       yu -= p[Minid].x - p[s].x; n       s = Minid; n     } else { n       for (int j = s + 1; j <= Minid; j++) { n         if (p[j].p <= p[s].p) { n           int dis = p[j].x - p[s].x; n           if (yu >= dis) { n             yu -= dis; n           } else { n             ans += 1LL * (dis - yu) * p[s].p; n             yu = 0; n           } n           s = j; n           break; n         } n       } n     } n   } n   return ans; n } n int main() { n   scanf( %d%d%d , &d, &n, &m); n   p[0] = Sta(0, 0); n   for (int i = 1; i <= m; i++) p[i].read(); n   p[++m] = Sta(d, 0); n   sort(p, p + m + 1); n   build(); n   printf( %lld n , solve()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k, ans = 0, odd = 0, ev = 0; n   cin >> n; n   int a[n + 1]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i] & 1) n       odd++; n     else n       ev++; n   } n   if (n == 1) { n     if (odd) n       cout <<  Yes ; n     else n       cout <<  No ; n     return 0; n   } n   if (a[0] % 2 == 0 || a[n - 1] % 2 == 0) { n     cout <<  No ; n   } else { n     if (n & 1) { n       if (odd >= 2) n         cout <<  Yes ; n       else n         cout <<  No ; n     } else { n       cout <<  No ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long n, long long m) { return m == 0 ? n : gcd(m, n % m); } n long long lcm(long long n, long long m) { return (m * n) / gcd(n, m); } n long long dx[] = {1, 0}; n long long dy[] = {0, 1}; n const long long inf = 1e9 + 10; n const long long INF = 1e18; n long long const N = 2e5 + 10; n long long const M = 5100; n double const PI = acos(-1); n long long const MOD = 998244353; n long long Check(long long n, long long pos) { return n & (1 << pos); } n long long Set(long long n, long long pos) { return n |= (1 << pos); } n long long n, m; n vector<pair<long long, long long> > store; n vector<long long> k; n long long visit[N]; n bool check(long long now) { n   memset(visit, 0, sizeof(visit)); n   pair<long long, long long> pt = {now, n}; n   auto it = upper_bound((store.begin()), (store.end()), pt); n   it--; n   long long pos = it - store.begin(); n   vector<pair<long long, long long> > apes; n   for (long long i = pos; i >= 0; i--) { n     long long day = store[i].first; n     long long type = store[i].second; n     if (visit[type] == 0) { n       apes.push_back({day, type}); n       visit[type] = 1; n     } n   } n   reverse((apes.begin()), (apes.end())); n   long long taka = 0; n   long long extra = 0; n   long long lastDay = 0; n   for (long long i = 0; i < (long long)apes.size(); i++) { n     long long day = apes[i].first; n     lastDay = day; n     long long type = apes[i].second; n     if (i == 0) n       taka += day; n     else n       taka += day - apes[i - 1].first; n     if (k[type] <= taka) n       taka -= k[type]; n     else { n       extra += k[type] - taka; n       taka = 0; n     } n   } n   taka += now - lastDay; n   for (long long i = 0; i < n; i++) { n     if (visit[i] == 0) extra += k[i]; n   } n   extra <<= 1; n   if (taka >= extra) n     return true; n   else n     return false; n } n int32_t main() { n   cin >> n >> m; n   k.resize(n); n   for (long long i = 0; i < n; i++) { n     cin >> k[i]; n   } n   for (long long i = 0; i < m; i++) { n     long long day, type; n     cin >> day >> type; n     type--; n     store.push_back({day, type}); n   } n   sort((store.begin()), (store.end())); n   long long res = 1; n   long long left = 1, right = 1e11; n   while (left <= right) { n     long long mid = (left + right) >> 1; n     if (check(mid)) { n       res = mid; n       right = mid - 1; n     } else { n       left = mid + 1; n     } n   } n   cout << res <<   n ; n } n