#include <stdio.h> n #include <sys/time.h> n  n #define N 100000 n #define Q 100000 n #define A 100000 n #define B 2154 /* B = floor(Q^(2/3)) = floor(N^(2/3)) */ n #define INF 0x3f3f3f3f n  n int min(int a, int b) { return a < b ? a : b; } n  n unsigned int X; n  n void srand_() { n  struct timeval tv; n  n  gettimeofday(&tv, NULL); n  X = tv.tv_sec ^ tv.tv_usec; n  if (X % 2 == 0) n   X++; n } n  n int rand_() { n  return (X *= 3) >> 1; n } n  n int tt[Q], ll[Q], rr[Q], kk[Q], ans[Q]; n  n int compare(int h1, int h2) { n  return h1 / B != h2 / B ? h1 / B - h2 / B : (ll[h1] / B != ll[h2] / B ? ll[h1] / B - ll[h2] / B : rr[h1] - rr[h2]); n } n  n void sort(int *hh, int l, int r) { n  while (l < r) { n   int i = l, j = l, k = r, h = hh[l + rand_() % (r - l)], tmp; n  n   while (j < k) { n    int c = compare(hh[j], h); n  n    if (c == 0) n     j++; n    else if (c < 0) { n     tmp = hh[i], hh[i] = hh[j], hh[j] = tmp; n     i++, j++; n    } else { n     k--; n     tmp = hh[j], hh[j] = hh[k], hh[k] = tmp; n    } n   } n   sort(hh, l, i); n   l = k; n  } n } n  n int kk_[N + 1], prev[N + 1], next[N + 1]; n  n void incr(int i) { n  if (next[i] != i + 1) { n   prev[i + 1] = i, next[i + 1] = next[i]; n   next[i] = i + 1; n   if (next[i + 1] != -1) n    prev[next[i + 1]] = i + 1; n  } n  kk_[i + 1]++; n  if (--kk_[i] == 0) { n   if (prev[i] != -1) n    next[prev[i]] = next[i]; n   if (next[i] != -1) n    prev[next[i]] = prev[i]; n  } n } n  n void decr(int i) { n  if (prev[i] != i - 1) { n   next[i - 1] = i, prev[i - 1] = prev[i]; n   prev[i] = i - 1; n   if (prev[i - 1] != -1) n    next[prev[i - 1]] = i - 1; n  } n  kk_[i - 1]++; n  if (--kk_[i] == 0) { n   if (prev[i] != -1) n    next[prev[i]] = next[i]; n   if (next[i] != -1) n    prev[next[i]] = prev[i]; n  } n } n  n int solve(int k) { n  int ans, i, j; n  n  ans = INF; n  for (i = next[0], j = 0; i != -1; i = next[i]) { n   while (next[j] != -1 && k > 0) n    k -= kk_[j = next[j]]; n   if (k > 0) n    break; n   ans = min(ans, j - i); n   k += kk_[i]; n  } n  return ans == INF ? -1 : ans; n } n  n int main() { n  static int aa[N], aa_[N], old[Q], new_[Q], hh[Q], cnt[A + 1]; n  int n, q, q_, h, h_, i, l, r; n  n  srand_(); n  scanf( %d%d , &n, &q); n  for (i = 0; i < n; i++) n   scanf( %d , &aa[i]), aa_[i] = aa[i]; n  q_ = 0; n  for (h = 0; h < q; h++) { n   scanf( %d , &tt[h]); n   if (tt[h] == 1) { n    scanf( %d%d%d , &ll[h], &rr[h], &kk[h]), ll[h]--, rr[h]--; n    hh[q_++] = h; n   } else { n    int a; n  n    scanf( %d%d , &i, &a), i--; n    ll[h] = rr[h] = i, old[h] = aa_[i], new_[h] = aa_[i] = a; n   } n  } n  sort(hh, 0, q_); n  kk_[0] = INF, prev[0] = next[0] = -1; n  for (h_ = 0, h = 0, l = 0, r = -1; h_ < q_; h_++) { n   int h1 = hh[h_], l1 = ll[h1], r1 = rr[h1]; n  n   while (h < h1) { n    if (tt[h] == 2) { n     i = ll[h]; n     if (l <= i && i <= r) n      decr(cnt[aa[i]]--); n     aa[i] = new_[h]; n     if (l <= i && i <= r) n      incr(cnt[aa[i]]++); n    } n    h++; n   } n   while (h > h1) { n    h--; n    if (tt[h] == 2) { n     i = ll[h]; n     if (l <= i && i <= r) n      decr(cnt[aa[i]]--); n     aa[i] = old[h]; n     if (l <= i && i <= r) n      incr(cnt[aa[i]]++); n    } n   } n   while (l > l1) n    incr(cnt[aa[--l]]++); n   while (r < r1) n    incr(cnt[aa[++r]]++); n   while (l < l1) n    decr(cnt[aa[l++]]--); n   while (r > r1) n    decr(cnt[aa[r--]]--); n   ans[h1] = solve(kk[h1]); n  } n  for (h = 0; h < q; h++) n   if (tt[h] == 1) n    printf( %d n , ans[h]); n  return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long c0, c1, n; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n long long lls[31]; n long long comb(long long a, long long b) { n   long long s = 1, x, g; n   for (long long i = 0; ++i <= b; lls[i] = i) n     ; n   for (long long i = -1; ++i < b;) { n     x = a + b - i; n     for (long long j = 0; ++j <= b;) { n       g = gcd(lls[j], x); n       x /= g; n       lls[j] /= g; n     } n     if (x > 2147483647 / s) return 2147483647; n     s *= x; n   } n   return s; n } n bool check(long long x) { n   long long tmp = x / c0 + x / c1 + 1; n   if (tmp > n) return 1; n   for (long long i = 0; ++i <= 26;) { n     for (long long j = i - 1; (++j) * c0 + i * c1 <= x;) n       if ((tmp += comb(j, i)) > n) return 1; n     for (long long j = i; (++j) * c1 + i * c0 <= x;) n       if ((tmp += comb(j, i)) > n) return 1; n   } n   return 0; n } n void work(long long x, long long &tmp, long long &ans) { n   tmp = x / c0 + x / c1 + 1; n   ans = ((x / c0) * (x / c0 + 1) * c0 + (x / c1) * (x / c1 + 1) * c1) >> 1; n   long long c; n   for (long long i = 1; i <= 26; ++i) { n     for (long long j = i; j * c0 + i * c1 <= x; ++j) { n       c = comb(j, i); n       tmp += c; n       ans += c * (j * c0 + i * c1); n     } n     for (long long j = i + 1; j * c1 + i * c0 <= x; ++j) { n       c = comb(j, i); n       tmp += c; n       ans += c * (j * c1 + i * c0); n     } n   } n } n int main() { n   scanf( %lld%lld%lld , &n, &c0, &c1); n   --n, c0 > c1 && (swap(c0, c1), 1); n   if (!c0) { n     printf( %lld n , n * c1); n     return 0; n   } n   long long l = 0, r = c1 * 26, mid; n   while (l <= r) { n     mid = (l + r) >> 1; n     if (check(mid)) n       r = mid - 1; n     else n       l = mid + 1; n   } n   long long c, s; n   work(l - 1, c, s); n   s += (n - c) * l + n * (c0 + c1); n   printf( %lld n , s); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100 + 5; n int grid[maxn][maxn]; n int main() { n   int n, ans = 0; n   scanf( %d , &n); n   for (int i = 0, x1, x2, y1, y2; i < n; i++) { n     scanf( %d%d%d%d , &x1, &y1, &x2, &y2); n     ans += (x2 - x1 + 1) * (y2 - y1 + 1); n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n const long long MAX = 2e9 + 7; n const long long mod = 1e9 + 7; n const long long maxn = 1e3 + 7; n int n; n string s[maxn]; n set<string> ss; n int jude(string s) { n   set<char> q; n   int a = s.size(); n   for (int i = 0; i < s.size(); i++) q.insert(s[i]); n   if (q.size() == a) n     return 1; n   else n     return 0; n } n int main() { n   cin >> n; n   int k = 0; n   for (int i = 0; i < n; i++) { n     cin >> s[i]; n     sort(s[i].begin(), s[i].end()); n     s[i].erase(unique(s[i].begin(), s[i].end()), s[i].end()); n     int flag = 1; n     if (jude(s[i])) ss.insert(s[i]); n   } n   cout << ss.size() << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n std::mt19937 rnd( n     (int)std::chrono::steady_clock::now().time_since_epoch().count()); n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n const int MAXN = 300000; n struct Res { n   int with, without, best; n }; n int n; n vector<int> adj[MAXN]; n Res dfs(int at, int par) { n   int nch = ((int)(adj[at]).size()) - (par != -1 ? 1 : 0); n   Res ret; n   ret.with = 1; n   ret.without = nch; n   ret.best = 0; n   int without1 = 0, without2 = 0; n   int any1 = 0, any2 = 0; n   for (int i = (0); i < (((int)(adj[at]).size())); ++i) { n     int to = adj[at][i]; n     if (to == par) continue; n     Res sub = dfs(to, at); n     ret.with = max(ret.with, sub.without + 1); n     ret.without = max(ret.without, max(sub.with, sub.without) + nch - 1); n     ret.best = max(ret.best, sub.best); n     int anyc = max(sub.with, sub.without); n     if (anyc > any1) n       any2 = any1, any1 = anyc; n     else if (anyc > any2) n       any2 = anyc; n     int withoutc = sub.without; n     if (withoutc > without1) n       without2 = without1, without1 = withoutc; n     else if (withoutc > without2) n       without2 = withoutc; n   } n   ret.best = max(ret.best, max(ret.with, ret.without)); n   if (nch >= 2) n     ret.best = max(ret.best, max(without1 + without2 + 1, n                                  any1 + any2 + ((int)(adj[at]).size()) - 2)); n   return ret; n } n int solve() { return dfs(0, -1).best; } n void run() { n   scanf( %d , &n); n   for (int i = (0); i < (n - 1); ++i) { n     int a, b; n     scanf( %d%d , &a, &b); n     --a, --b; n     adj[a].push_back(b), adj[b].push_back(a); n   } n   printf( %d n , solve()); n } n int main() { n   run(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<int, int> mp; n int main() { n   long long n; n   int k, cnt = 0; n   scanf( %lld %d , &n, &k); n   for (int i = 0; i < 63; i++) { n     if (n >> i & 1) { n       mp[i] = 1; n       ++cnt; n     } n   } n   if (cnt > k) return puts( No ), 0; n   puts( Yes ); n   int st, pre; n   for (int i = 62; i >= -62; i--) { n     if (mp[i] + cnt <= k) { n       pre = i - 1; n       mp[i - 1] += 2 * mp[i]; n       cnt += mp[i]; n       mp[i] = 0; n     } else n       break; n   } n   int x; n   for (int i = -62; i < 62; i++) { n     if (mp.count(i)) { n       x = i; n       break; n     } n   } n   vector<int> v; n   int res = k - cnt; n   if (res > 0) { n     --mp[x]; n     for (int i = 1; i <= res; i++) v.push_back(x - i); n     v.push_back(x - res); n   } n   for (int i = -62; i < 62; i++) n     for (int j = 0, y = mp[i]; j < y; j++) v.push_back(i); n   sort(v.begin(), v.end(), greater<int>()); n   for (int i = 0; i < v.size(); i++) n     printf( %d%c , v[i],    n [i == v.size() - 1]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n char s[1024][1024]; n inline bool u(int i, int j) { n   return 0 <= i && i < n && 0 <= j && j <= m && s[i][j] ==  . ; n } n int p[1024 * 1024], c[1024 * 1024]; n bool b[1024][1024]; n int sid(int x) { n   int y, z = x; n   for (; (y = p[z]) != z; z = y) n     ; n   for (; x != z; x = y) { n     y = p[x]; n     p[x] = z; n   } n   return x; n } n int f(int x, int y) { return sid(x * m + y); } n bool bad(int i, int j) { n   return u(i, j) && !u(i - 1, j) && !u(i + 1, j) && !u(i, j - 1) && n          !u(i, j + 1); n } n void unite(int i, int j) { n   c[i] += c[j]; n   p[j] = i; n } n vector<int> adj[1024 * 1024]; n void updc(int i) { n   if (c[i] < 0) { n     int z = 0; n     for (int j : adj[i]) n       if (c[j] >= 0) z |= 1 << (c[j] -  0 ); n     c[i] =  0  + __builtin_ctz(~z); n   } n } n int main() { n   cin >> n >> m; n   for (int i(0); i < n; ++i) scanf( %s , s[i]); n   for (int i(0); i < n; ++i) n     for (int j(0); j < m; ++j) { n       if (!u(i, j)) continue; n       p[i * m + j] = i * m + j; n       c[i * m + j] = 1; n       if (bad(i, j)) { n         puts( -1 ); n         return 0; n       } n     } n   for (int i(0); i < n; ++i) n     for (int j(0); j < m; ++j) n       if (u(i, j) && !b[i][j]) { n         int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1}; n         for (int k(0); k < 4; ++k) { n           int x = i + dx[k], y = j + dy[k]; n           if (u(x, y) && !b[x][y]) { n             b[i][j] = b[x][y] = true; n             unite(f(i, j), f(x, y)); n             break; n           } n         } n       } n   for (int i(0); i < n; ++i) { n     for (int j(0); j < m; ++j) n       if (u(i, j) && !b[i][j]) { n         int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1}; n         for (int k(0); k < 4; ++k) { n           int x = i + dx[k], y = j + dy[k]; n           if (u(x, y) && c[f(x, y)] + c[f(i, j)] <= 5) { n             unite(f(x, y), f(i, j)); n             b[i][j] = true; n             break; n           } n         } n       } n   } n   for (int i(0); i < n; ++i) n     for (int j(0); j < m; ++j) n       if (u(i, j)) { n         if (u(i + 1, j) && f(i, j) != f(i + 1, j)) { n           adj[f(i, j)].push_back(f(i + 1, j)); n           adj[f(i + 1, j)].push_back(f(i, j)); n         } n         if (u(i, j + 1) && f(i, j) != f(i, j + 1)) { n           adj[f(i, j)].push_back(f(i, j + 1)); n           adj[f(i, j + 1)].push_back(f(i, j)); n         } n         c[f(i, j)] = -1; n       } n   for (int i(0); i < n; ++i) n     for (int j(0); j < m; ++j) n       if (u(i, j)) { n         updc(f(i, j)); n         s[i][j] = c[f(i, j)]; n       } n   for (int i(0); i < n; ++i) puts(s[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t; n long long x, b; n void run(int a) { n   if (a < 10) n     x += a; n   else { n     x += a - a % 10; n     run(a / 10 + a % 10); n   } n } n int main() { n   cin >> t; n   int s[10005]; n   for (int i = 0; i < t; i++) cin >> s[i]; n   for (int i = 0; i < t; i++) { n     x = 0; n     run(s[i]); n     cout << x << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:102400000,102400000 ) n const int MOD = 1000000007; n const int N = 1E5 + 15; n const int maxn = 2e5 + 14; n const int INF = (1 << 30) - 1; n const int letter = 130; n const double pi = acos(-1.0); n const double eps = 1e-8; n using namespace std; n inline int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n int n, q; n long long a[N], b[N]; n long long L[N], R[N]; n int s[N], top; n void solve(int l, int r) { n   int cnt = 0; n   for (int i = l; i < r; i++) b[++cnt] = a[i]; n   b[0] = INF; n   b[cnt + 1] = INF; n   s[top = 0] = 0; n   for (int i = 1; i <= cnt + 1; i++) { n     if (b[i] <= b[s[top]]) n       s[++top] = i; n     else { n       while (top >= 0 && b[s[top]] < b[i]) R[s[top]] = i - s[top], top--; n       s[++top] = i; n     } n   } n   s[top = 0] = cnt + 1; n   for (int i = cnt; i >= 0; i--) { n     if (b[i] < b[s[top]]) n       s[++top] = i; n     else { n       while (top >= 0 && b[s[top]] <= b[i]) L[s[top]] = s[top] - i, top--; n       s[++top] = i; n     } n   } n   long long ans = 0; n   for (int i = 1; i <= cnt; i++) { n     ans += L[i] * R[i] * b[i]; n   } n   printf( %I64d n , ans); n } n int main() { n   int x, y; n   scanf( %d%d , &n, &q); n   for (int i = 1; i <= n; i++) scanf( %I64d , a + i); n   for (int i = 1; i < n; i++) a[i] = abs(a[i + 1] - a[i]); n   while (q--) { n     scanf( %d%d , &x, &y); n     solve(x, y); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n = 0, m = 0, k = 0, arr[101], seg[100001][3]; n   long long sum = 0; n   cin >> n >> m >> k; n   for (int i = 0; i < m; i++) cin >> seg[i][0] >> seg[i][1] >> seg[i][2]; n   for (int i = 0; i < k; i++) cin >> arr[i]; n   for (int i = 0; i < k; i++) { n     for (int j = 0; j < m; j++) { n       if (arr[i] < seg[j][0] || arr[i] > seg[j][1]) continue; n       sum += (arr[i] - seg[j][0]) + seg[j][2]; n     } n   } n   cout << sum; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t n, s, ans = -1, x, y; n int main() { n   cin >> n >> s; n   while (n--) { n     cin >> x >> y; n     if (x < s || (x == s && !y)) ans = max(ans, !y ? 0 : 100 - y); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   long double x, y; n   node(long double X = 0.0, long double Y = 0.0) { x = X, y = Y; } n } que[200005]; n int n, k; n int t[200005], head, tail; n long double s[200005], a[200005], b[200005], f[2][200005]; n long double K(node, node); n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , t + i); n     s[i] = s[i - 1] + t[i]; n     a[i] = a[i - 1] + s[i] / t[i]; n     b[i] = b[i - 1] + 1.0 / t[i]; n   } n   int now = 1, lst = 0; n   for (int i = 1; i <= n; ++i) f[now][i] = 9999999999999999; n   for (int p = 1; p <= k; ++p) { n     swap(now, lst); n     head = tail = 0; n     que[tail++] = node(0, 0); n     for (int i = 1; i <= n; ++i) { n       while (head + 1 < tail) n         if (K(que[head], que[head + 1]) < b[i]) n           ++head; n         else n           break; n       f[now][i] = que[head].y - que[head].x * b[i] + a[i]; n       node tmp(s[i], f[lst][i] - a[i] + s[i] * b[i]); n       while (head < tail - 1) n         if (K(que[tail - 1], que[tail - 2]) > K(que[tail - 2], tmp)) n           --tail; n         else n           break; n       que[tail++] = tmp; n     } n   } n   printf( %.10lf , (double)f[now][n]); n   return 0; n } n long double K(node x, node y) { return (x.y - y.y) / (x.x - y.x); } n


#include <bits/stdc++.h> n using namespace std; n const int fx[] = {+1, -1, +0, +0}, fy[] = {+0, +0, +1, -1}; n const long long mod = 1e9 + 7, INF = 1e18, mx = 1e6; n int Case = 1, cas = 0; n long long n, A[mx], Sum; n int main() { n   ios_base ::sync_with_stdio(0), cin.tie(0); n   ; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> A[i]; n     Sum += A[i]; n   } n   if (Sum % 3) n     cout << 0 << endl; n   else { n     long long Ans = 0, taken = 0, milse = 0; n     long long target = Sum / 3; n     for (int i = 1; i < n; i++) { n       taken += A[i]; n       if (taken == target + target) Ans += milse; n       if (taken == target) milse++; n     } n     cout << Ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k, t, ma, sum = 0; n   std::string s[1000]; n   cin >> n >> k; n   for (int i = 0; i < n; i++) cin >> s[i]; n   for (int i = 0; i < k; i++) { n     cin >> t; n     ma = 1; n     map<char, int> m; n     for (int j = 0; j < n; j++) m[s[j][i]]++; n     for (map<char, int>::iterator it = m.begin(); it != m.end(); it++) n       ma = max(ma, it->second); n     sum += ma * t; n   } n   cout << sum; n } n


#include <bits/stdc++.h> n #pragma optimise GCC(-O2) n using namespace std; n mt19937_64 rang( n     chrono::high_resolution_clock::now().time_since_epoch().count()); n int rng(int lim) { n   uniform_int_distribution<int> uid(0, lim - 1); n   return uid(rang); n } n long long INF = LLONG_MAX; n const long long M = 1000000007; n long long powm(long long, long long); n long long foo(long long a) { n   long long ct = 1; n   long long tp = a; n   while (tp > 0) { n     tp -= ct; n     ct++; n   } n   return ct; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   string s; n   cin >> s; n   long long hr = 0; n   long long mn = 0; n   hr += 10 * (s[0] -  0 ); n   hr += (s[1] -  0 ); n   mn += 10 * (s[3] -  0 ); n   mn += (s[4] -  0 ); n   long long a; n   cin >> a; n   mn += a; n   long long ex = mn / 60; n   mn = mn % 60; n   hr += ex; n   hr %= 24; n   if (hr > 9 && mn > 9) cout << hr <<  :  << mn; n   if (hr > 9 && mn <= 9) cout << hr <<  :  <<  0  << mn; n   if (hr <= 9 && mn > 9) cout <<  0  << hr <<  :  << mn; n   if (hr <= 9 && mn <= 9) cout <<  0  << hr <<  :  <<  0  << mn; n } n long long powm(long long a, long long b) { n   long long res = 1; n   while (b) { n     if (b & 1) res = (res * a) % M; n     a = (a * a) % M; n     b >>= 1; n   } n   return res; n } n


#include <bits/stdc++.h> n using namespace std; n using int64 = long long; n using ld = double; n const int MAXN = 1e5 + 1; n vector<int> G[MAXN], comp[MAXN], suf_freq[MAXN]; n vector<int64> suf_sum[MAXN]; n int comp_cnt, comp_ind[MAXN], p[MAXN], dp1[MAXN], dp2[MAXN], dp[MAXN], n     diameter[MAXN]; n void max_self(int &a, int b) { a = max(a, b); } n void dfs1(int u) { n   comp_ind[u] = comp_cnt; n   comp[comp_cnt].emplace_back(u); n   for (int v : G[u]) n     if (!comp_ind[v]) { n       p[v] = u; n       dfs1(v); n       if (dp1[u] <= dp1[v] + 1) { n         dp2[u] = dp1[u]; n         dp1[u] = dp1[v] + 1; n       } else n         max_self(dp2[u], dp1[v] + 1); n     } n } n void dfs2(int u, int dist) { n   dp[u] = max(dp1[u], dist); n   max_self(diameter[comp_cnt], dp[u]); n   for (int v : G[u]) n     if (v != p[u]) { n       if (dp1[u] == dp1[v] + 1) n         dfs2(v, max(dp2[u], dist) + 1); n       else n         dfs2(v, max(dp1[u], dist) + 1); n     } n } n ld solve(int x, int y) { n   if (x == y) return -1; n   if (comp[x].size() > comp[y].size()) swap(x, y); n   int D = max(diameter[x], diameter[y]); n   ld sum = 0; n   for (int d = 0; d <= diameter[x]; ++d) { n     int64 freq = suf_freq[x][d]; n     if (d < diameter[x]) freq -= suf_freq[x][d + 1]; n     if (freq == 0) continue; n     int suf = max(0, min(D - d - 1, diameter[y])); n     sum += freq * suf_sum[y][suf]; n     sum += freq * suf_freq[y][suf] * (d + 1); n     int rest = comp[y].size() - suf_freq[y][suf]; n     sum += freq * rest * D; n   } n   return sum / ((ld)comp[x].size() * comp[y].size()); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   int N, M, Q; n   cin >> N >> M >> Q; n   for (int i = 0; i < M; ++i) { n     int u, v; n     cin >> u >> v; n     G[u].emplace_back(v); n     G[v].emplace_back(u); n   } n   for (int u = 1; u <= N; ++u) n     if (!comp_ind[u]) { n       ++comp_cnt; n       dfs1(u); n       dfs2(u, 0); n       suf_sum[comp_cnt] = vector<int64>(diameter[comp_cnt] + 1); n       suf_freq[comp_cnt] = vector<int>(diameter[comp_cnt] + 1); n       for (int v : comp[comp_cnt]) { n         suf_sum[comp_cnt][dp[v]] += dp[v]; n         ++suf_freq[comp_cnt][dp[v]]; n       } n       for (int d = diameter[comp_cnt] - 1; d >= 0; --d) { n         suf_sum[comp_cnt][d] += suf_sum[comp_cnt][d + 1]; n         suf_freq[comp_cnt][d] += suf_freq[comp_cnt][d + 1]; n       } n     } n   map<pair<int, int>, ld> sol; n   cout << fixed << setprecision(8); n   for (int q = 0; q < Q; ++q) { n     int u, v; n     cin >> u >> v; n     u = comp_ind[u], v = comp_ind[v]; n     pair<int, int> p{u, v}; n     auto it = sol.find(p); n     if (it != sol.end()) n       cout << it->second <<   n ; n     else { n       ld ans = solve(u, v); n       sol[p] = sol[make_pair(v, u)] = ans; n       cout << ans <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline void read(T& x) { n   bool fu = 0; n   char c; n   for (c = getchar(); c <= 32; c = getchar()) n     ; n   if (c ==  - ) fu = 1, c = getchar(); n   for (x = 0; c > 32; c = getchar()) x = x * 10 + c -  0 ; n   if (fu) x = -x; n }; n template <class T> n inline void read(T& x, T& y) { n   read(x); n   read(y); n } n template <class T> n inline void read(T& x, T& y, T& z) { n   read(x); n   read(y); n   read(z); n } n inline char getc() { n   char c; n   for (c = getchar(); c <= 32; c = getchar()) n     ; n   return c; n } n const int D = 360360; n long long A, B, C; n int n, i, j, k, l, p; n int f[761000]; n int dp(long long A, long long B) { n   int i, j; n   memset(f, 127, sizeof(f)); n   f[B - A] = 0; n   for (i = B - A; i >= 1; i--) { n     long long x = A + i; n     f[i - 1] = min(f[i - 1], f[i] + 1); n     for (j = 2; j <= k; j++) n       if (x - (x % j) >= A) n         f[x - (x % j) - A] = min(f[x - (x % j) - A], f[i] + 1); n   } n   return f[0]; n } n int main() { n   cin >> B >> A >> k; n   long long t1 = (A - 1) / D, t2 = (B - 1) / D, ans, ci = dp(0, D); n   if (t1 == t2) n     ans = dp(A, B); n   else n     ans = dp(A, (t1 + 1) * D) + dp(t2 * D, B) + ci * (t2 - t1 - 1); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n, x = 0, y = 0, p = 0, q = 0; n     cin >> n; n     bool ans = true; n     for (int i = 1; i <= n; i++) { n       cin >> p >> q; n       if (p < x || q < y) n         ans = false; n       else if (q - y > p - x) n         ans = false; n       x = p; n       y = q; n     } n     if (ans == true) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long int power(long long int x, long long int y, long long int p) { n   long long int res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n long long int modInverse(long long int n, long long int p) { n   return power(n, p - 2, p); n } n struct point { n   long long int x, y; n }; n void bfs(long long int node, vector<long long int> adj[], vector<bool> &visit, n          vector<long long int> &dis) { n   queue<long long int> q; n   visit[node] = true; n   dis[node] = 0; n   q.push(node); n   while (!q.empty()) { n     long long int s = q.front(); n     q.pop(); n     for (auto u : adj[s]) { n       if (visit[u]) continue; n       visit[u] = true; n       dis[u] = dis[s] + 1; n       q.push(u); n     } n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long int tests; n   cin >> tests; n   for (long long int gg = 0; gg < tests; gg++) { n     long long int n, a, b, da, db; n     cin >> n >> a >> b >> da >> db; n     vector<long long int> adj[n + 1]; n     for (long long int i = 0; i < n - 1; i++) { n       long long int x, y; n       cin >> x >> y; n       adj[x].push_back(y); n       adj[y].push_back(x); n     } n     vector<bool> visit(n + 1, false); n     vector<long long int> dis(n + 1, 0); n     bfs(a, adj, visit, dis); n     if (dis[b] <= da) { n       cout <<  Alice n ; n       continue; n     } n     if (db > 2 * da) { n       long long int m1 = *max_element(dis.begin(), dis.end()), node1 = 0; n       for (long long int i = 1; i < n + 1; i++) { n         if (dis[i] == m1) { n           node1 = i; n           break; n         } n       } n       visit.assign(n + 1, false); n       dis.assign(n + 1, 0); n       bfs(node1, adj, visit, dis); n       long long int dia = *max_element(dis.begin(), dis.end()); n       if (dia > 2 * da) { n         cout <<  Bob n ; n       } else { n         cout <<  Alice n ; n       } n     } else { n       cout <<  Alice n ; n     } n   } n } n


#include <bits/stdc++.h> n const int SIZE_N = (1000 + 10); n const int SIZE_M = (SIZE_N); n const int SIZE_K = (500000 + 10); n int n, m, k; n int mat[SIZE_N][SIZE_M]; n int mx[SIZE_M], my[SIZE_N]; n int main(void) { n   scanf( %d%d%d , &n, &m, &k); n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) scanf( %d , &mat[i][j]); n   for (int i = 1; i <= n; ++i) my[i] = i; n   for (int i = 1; i <= m; ++i) mx[i] = i; n   for (; k > 0; --k) { n     char typ[10]; n     int a, b; n     scanf( %s , typ); n     scanf( %d%d , &a, &b); n     if (typ[0] ==  c ) { n       std::swap(mx[a], mx[b]); n     } else if (typ[0] ==  r ) { n       std::swap(my[a], my[b]); n     } else if (typ[0] ==  g ) { n       printf( %d n , mat[my[a]][mx[b]]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std; n vector<int> adj[100005]; n vector<int>::iterator it; n int con[100005]; n bool visited[100005]; n int bfs(int root) { n   int j, i, u, v, mn = 10000000, temp; n   queue<int> Q; n   Q.push(root); n   visited[root] = true; n   while (!Q.empty()) { n     u = Q.front(); n     Q.pop(); n     for (i = 0; i < adj[u].size(); i++) { n       v = adj[u][i]; n       if (!visited[v]) { n         Q.push(v); n         visited[v] = true; n       } else { n         for (j = 0; j < adj[u].size(); j++) { n           if (adj[u][j] != v) { n             it = lower_bound(adj[v].begin(), adj[v].end(), adj[u][j]); n             if (it != adj[v].end() && ((*it) == adj[u][j])) { n               temp = con[u] + con[v] + con[adj[u][j]] - 6; n               if (temp < mn) mn = temp; n             } n           } n         } n       } n     } n   } n   return mn; n } n int main() { n   int j, t, i, t1, t2, n, m, ans; n   t = 1; n   while (t--) { n     scanf( %d , &n); n     scanf( %d , &m); n     memset(visited, 0, sizeof(visited)); n     for (i = 0; i < m; i++) { n       scanf( %d%d , &t1, &t2); n       adj[t1].push_back(t2); n       adj[t2].push_back(t1); n     } n     for (i = 1; i <= n; i++) { n       sort(adj[i].begin(), adj[i].end()); n     } n     for (i = 1; i <= n; i++) { n       con[i] = adj[i].size(); n     } n     ans = 10000000; n     for (i = 1; i <= n; i++) { n       if (!visited[i]) { n         t1 = bfs(i); n         if (t1 < ans) ans = t1; n       } n     } n     if (ans == 10000000) n       printf( -1 n ); n     else n       printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int BIT[100005]; n int v[100005], n, i, mayor, lol, cosaMenor = 1000005; n int contMayor, numMenor; n bool record[100005]; n int buenos; n void add(int pos) { n   while (pos > 0) { n     BIT[pos]++; n     pos -= pos & (-pos); n   } n } n int query(int pos) { n   int sum = 0; n   while (pos <= n) { n     sum += BIT[pos]; n     pos += pos & (-pos); n   } n   return sum; n } n int cont[100005]; n int main() { n   scanf( %d , &n); n   for (i = 1; i <= n; i++) scanf( %d , &v[i]); n   for (i = 1; i <= n; i++) { n     if (query(v[i]) == 1) n       cont[mayor]++; n     else { n       if (query(v[i]) > 1) { n         cosaMenor = min(cosaMenor, v[i]); n       } else { n         record[v[i]] = true; n         buenos++; n       } n     } n     add(v[i]); n     mayor = max(mayor, v[i]); n   } n   for (i = 1; i <= n; i++) { n     if (buenos + cont[i] - (record[i] ? 1 : 0) > contMayor) { n       contMayor = buenos + cont[i] - (record[i] ? 1 : 0); n       numMenor = i; n     } else { n       if (buenos + cont[i] - (record[i] ? 1 : 0) == contMayor) n         numMenor = min(numMenor, i); n     } n   } n   if (contMayor == 0) n     printf( %d , cosaMenor > n ? 1 : cosaMenor); n   else n     printf( %d , numMenor); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int f[10]; n   for (int i = 0; i < 10; i++) { n     f[i] = 0; n   } n   for (int i = 0; i < 6; i++) { n     int tem; n     cin >> tem; n     f[tem]++; n   } n   int leg; n   int flag = 0; n   for (int i = 0; i < 10; i++) { n     if (f[i] >= 4) { n       flag = 1; n       f[i] = f[i] - 4; n       break; n     } n   } n   if (flag == 0) { n     cout <<  Alien n ; n     return 0; n   } n   int h = 0, b = 0; n   for (int i = 0; i < 10; i++) { n     if (f[i] != 0) { n       h = i; n       f[i] = f[i] - 1; n     } n   } n   for (int i = 0; i < 10; i++) { n     if (f[i] != 0) { n       b = i; n     } n   } n   if (h == b) { n     cout <<  Elephant n ; n   } else { n     cout <<  Bear n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline T sqr(T a) { n   return a * a; n }; n template <typename T> n void dprint(T begin, T end) { n   for (auto i = begin; i != end; i++) cerr << (*i) <<    ; n   cerr <<   n ; n }; n const int maxn = 500 + 5; n int n, step[maxn * 2]; n string ans; n pair<int, int> loc[maxn * 2]; n bool query(int r1, int c1, int r2, int c2) { n   cout <<  ?   << r1 <<     << c1 <<     << r2 <<     << c2 << endl; n   cout.flush(); n   cin >> ans; n   return ans ==  YES ; n } n int main() { n   scanf( %d , &n); n   loc[0] = pair<int, int>(1, 1); n   for (int i = 0; i < n - 1; i++) { n     if (query(loc[i].first + 1, loc[i].second, n, n)) { n       loc[i + 1] = pair<int, int>(loc[i].first + 1, loc[i].second); n       step[i] = 0; n       continue; n     } n     if (query(loc[i].first, loc[i].second + 1, n, n)) { n       loc[i + 1] = pair<int, int>(loc[i].first, loc[i].second + 1); n       step[i] = 1; n       continue; n     } n   } n   loc[2 * n - 2] = pair<int, int>(n, n); n   for (int i = 2 * n - 2; i > n; i--) { n     if (query(loc[i - n].first, loc[i - n].second, loc[i].first, n               loc[i].second - 1)) { n       loc[i - 1] = pair<int, int>(loc[i].first, loc[i].second - 1); n       step[i - 1] = 1; n       continue; n     } n     if (query(loc[i - n].first, loc[i - n].second, loc[i].first - 1, n               loc[i].second)) { n       loc[i - 1] = pair<int, int>(loc[i].first - 1, loc[i].second); n       step[i - 1] = 0; n       continue; n     } n   } n   if (loc[n].first == loc[n - 1].first + 1) n     step[n - 1] = 0; n   else n     step[n - 1] = 1; n   cout <<  !  ; n   for (int i = 0; i < 2 * n - 2; i++) n     if (step[i] == 0) n       cout <<  D ; n     else n       cout <<  R ; n   cout << endl; n   cout.flush(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x, t, u, v; n   vector<long long> b; n   vector<pair<long long, long long> > a; n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     scanf( %d%d , &x, &t); n     a.push_back(make_pair(x, t)); n   } n   scanf( %d , &v); n   a.push_back(make_pair(0, 0)); n   for (int i = 0; i < a.size(); ++i) n     a[i] = make_pair(a[i].first + v * a[i].second, n                      -(a[i].first - v * a[i].second)); n   sort(a.rbegin(), a.rend()); n   u = v = 0; n   for (int i = 0; i < a.size(); ++i) { n     x = -a[i].second; n     t = upper_bound(b.begin(), b.end(), x) - b.begin(); n     if (t == b.size()) n       b.push_back(x); n     else n       b[t] = x; n     if (a[i] == make_pair(0ll, 0ll)) n       u = max(u, t); n     else n       v = max(v, t + 1); n   } n   printf( %d %d n , u, v); n   return 0; n } n


#include <bits/stdc++.h> n const int MAXN = 1000000; n int N; n long long Ans; n std::vector<int> G[MAXN + 5]; n long long Val[MAXN + 5]; n int Size[MAXN + 5]; n int Fa[MAXN + 5], Dep[MAXN + 5]; n void Dfs(int u, int fa, int dep) { n   Size[u] = 1; n   Fa[u] = fa; n   Dep[u] = dep; n   for (int i = 0; i < int(G[u].size()); i++) { n     int v = G[u][i]; n     if (v != fa) { n       Dfs(v, u, dep + 1); n       Size[u] += Size[v]; n       Val[u] += (long long)Size[v] * Size[v]; n     } n   } n   Val[u] += (long long)(N - Size[u]) * (N - Size[u]); n   Ans -= Val[u]; n } n int Pa[MAXN + 5], Num[MAXN + 5]; n int Find(int u) { return Pa[u] == u ? u : Pa[u] = Find(Pa[u]); } n long long In1(int u) { n   return (long long)(N - Num[u]) * (N - Num[u]) * Num[u] - Val[u] * Num[u]; n } n long long In2(int u) { n   return (long long)Num[u] * (Num[u] - 1) * 2 * (N - Num[u]); n } n long long In3(int u) { n   return std::max((long long)Num[u] * (Num[u] - 1) * (Num[u] - 2), 0ll); n } n void Merge(int u, int v) { n   Ans -= In1(u) + In2(u) + In3(u); n   Ans -= In1(v) + In2(v) + In3(v); n   Pa[v] = u, Num[u] += Num[v]; n   Val[u] += Val[v] - (long long)Size[v] * Size[v] - n             (long long)(N - Size[v]) * (N - Size[v]); n   Ans += In1(u) + In2(u) + In3(u); n } n int main() { n   scanf( %d , &N); n   for (int i = 1; i < N; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     G[u].push_back(v), G[v].push_back(u); n   } n   Ans = (long long)N * (N - 1) * (N - 1); n   Dfs(1, 0, 0); n   printf( %lld n , Ans); n   for (int i = 1; i <= N; i++) Pa[i] = i, Num[i] = 1; n   int Q; n   scanf( %d , &Q); n   while (Q--) { n     int u, v; n     scanf( %d%d , &u, &v); n     u = Find(u), v = Find(v); n     while (u != v) { n       if (Dep[u] < Dep[v]) std::swap(u, v); n       int anc = Find(Fa[u]); n       Merge(anc, u), u = anc; n     } n     printf( %lld n , Ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mo = 998244353; n const double PI = acos(-1.0); n template <typename _T> n _T Fabs(_T x) { n   return x < 0 ? -x : x; n } n template <typename _T> n void read(_T &x) { n   _T f = 1; n   x = 0; n   char s = getchar(); n   while (s >  9  || s <  0 ) { n     if (s ==  - ) f = -1; n     s = getchar(); n   } n   while ( 0  <= s && s <=  9 ) { n     x = (x << 3) + (x << 1) + (s ^ 48); n     s = getchar(); n   } n   x *= f; n } n int n, b[400005 * 2], totx, d[400005 * 2], toty, ans; n bool vis[400005]; n set<int> st[400005 << 2]; n int maxx[400005 << 2], minn[400005 << 2]; n struct ming { n   int ax, ay, bx, by; n } s[400005]; n struct node { n   int l, r, val; n }; n vector<node> vec[400005]; n void updata(int rt, bool fg) { n   if (fg) n     maxx[rt] = minn[rt] = 0; n   else n     maxx[rt] = max(maxx[rt << 1], maxx[rt << 1 | 1]), n     minn[rt] = min(minn[rt << 1], minn[rt << 1 | 1]); n   if (!st[rt].empty()) { n     int t = *st[rt].rbegin(); n     if (vis[t]) n       minn[rt] = max(minn[rt], t); n     else n       maxx[rt] = max(maxx[rt], t); n   } n   if (minn[rt] > maxx[rt]) maxx[rt] = 0; n } n void insert(int rt, int l, int r, int al, int ar, int aw) { n   if (al <= l && r <= ar) { n     if (aw > 0) n       st[rt].insert(aw); n     else n       st[rt].erase(-aw); n     updata(rt, l == r); n     return; n   } n   int mid = l + r >> 1; n   if (al <= mid) insert(rt << 1, l, mid, al, ar, aw); n   if (ar > mid) insert(rt << 1 | 1, mid + 1, r, al, ar, aw); n   updata(rt, 0); n } n signed main() { n   read(n); n   for (int i = 1; i <= n; i++) n     read(s[i].ax), read(s[i].ay), read(s[i].bx), read(s[i].by); n   for (int i = 1; i <= n; i++) b[++totx] = s[i].ax, b[++totx] = s[i].bx; n   sort(b + 1, b + totx + 1); n   totx = unique(b + 1, b + totx + 1) - b - 1; n   for (int i = 1; i <= n; i++) n     s[i].ax = lower_bound(b + 1, b + totx + 1, s[i].ax) - b, n     s[i].bx = lower_bound(b + 1, b + totx + 1, s[i].bx) - b; n   for (int i = 1; i <= n; i++) d[++toty] = s[i].ay, d[++toty] = s[i].by; n   sort(d + 1, d + toty + 1); n   toty = unique(d + 1, d + toty + 1) - d - 1; n   for (int i = 1; i <= n; i++) n     s[i].ay = lower_bound(d + 1, d + toty + 1, s[i].ay) - d, n     s[i].by = lower_bound(d + 1, d + toty + 1, s[i].by) - d - 1; n   for (int i = 1; i <= n; i++) n     vec[s[i].ax].push_back((node){s[i].ay, s[i].by, i}), n         vec[s[i].bx].push_back((node){s[i].ay, s[i].by, -i}); n   for (int i = 1; i <= totx; i++) { n     int siz = vec[i].size(); n     for (int j = 0; j < siz; j++) n       insert(1, 1, toty, vec[i][j].l, vec[i][j].r, vec[i][j].val); n     while (maxx[1]) n       vis[maxx[1]] = 1, insert(1, 1, toty, s[maxx[1]].ay, s[maxx[1]].by, 0), n       ans++; n   } n   printf( %d n , ans + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T abs(T x) { n   return x > 0 ? x : -x; n } n int n, m; n int a[1 << 20]; n int t[1 << 20]; n void upd(int v, int val) { n   v += 1 << n; n   t[v] = val; n   v /= 2; n   bool cur = 0; n   while (v > 0) { n     if (cur == 0) n       t[v] = t[2 * v] | t[2 * v + 1]; n     else n       t[v] = t[2 * v] ^ t[2 * v + 1]; n     v /= 2; n     cur ^= 1; n   } n } n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 0; i < 1 << n; ++i) scanf( %d , &a[i]); n   memset((t), (0), sizeof(t)); n   bool cur = 1; n   for (int h = 1 << n; h > 0; h /= 2) { n     for (int v = h; v < 2 * h; ++v) n       if (h == 1 << n) n         t[v] = a[v - h]; n       else n         t[v] = cur == 0 ? t[2 * v] | t[2 * v + 1] : t[2 * v] ^ t[2 * v + 1]; n     cur ^= 1; n   } n   while (m--) { n     int p, b; n     scanf( %d %d , &p, &b); n     upd(p - 1, b); n     printf( %d n , t[1]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int a[200]; n map<int, int> Map; n int cnt[20]; n int main() { n   for (int i = 0; i <= 11; i++) Map[1 << i] = i; n   int _; n   for (scanf( %d , &_); _; _--) { n     scanf( %d , &n); n     for (int i = 0; i < 12; i++) cnt[i] = 0; n     for (int i = 1; i <= n; i++) { n       scanf( %d , &a[i]); n       if (a[i] > 2048) continue; n       cnt[Map[a[i]]]++; n     } n     for (int i = 0; i <= 10; i++) { n       cnt[i + 1] += cnt[i] / 2; n     } n     if (cnt[11]) n       puts( YES ); n     else n       puts( NO ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e18; n long long prime[16] = {2,  3,  5,  7,  11, 13, 17, 19, n                        23, 29, 31, 37, 41, 43, 47, 53}; n long long n, ans; n void DFS(int x, int limit, long long num, long long cnt) { n   if (cnt > n) return; n   if (cnt == n && num < ans) ans = num; n   for (int i = 1; i <= limit; i++) { n     if (ans / prime[x] < num) break; n     num *= prime[x]; n     DFS(x + 1, i, num, cnt * (i + 1)); n   } n } n int main() { n   scanf( %lld , &n); n   ans = INF; n   DFS(0, 64, 1, 1); n   printf( %lld n , ans); n } n


#include<bits/stdc++.h> n         using namespace std; n  n         #define ios ios_base::sync_with_stdio(false);cin.tie(NULL); n         #define ll long long int n         #define max3(a,b,c) max(max((a),(b)),(c)) n         #define max4(a,b,c,d) max(max((a),(b)),max((c),(d))) n         #define min3(a,b,c) min(min((a),(b)),(c)) n         #define min4(a,b,c,d) min(min((a),(b)),min((c),(d))) n         #define all(v) v.begin(),v.end() n         #define rall(v) v.rbegin(),v.rend() n         typedef pair<int,int> pii; n         typedef pair<ll,ll> pll; n         const long double PI = 3.14159265358979323846264338; n         const long long INF = 1000000000000000000; n         const long long INF1 = 1000000000; n         const long long MOD = 1000000007; n     //    int v[INF],m[INF]; n   n  n  ll fun(ll n){ n    int b=0; n    while(n>0){ n        b+=n%10; n        n/=10; n    } n    return b; n  } n         int main(){ n       ios n       int t; n       cin>>t; n       while(t--){ n       ll n; n       cin>>n; n       if(n%2050==0){ n               ll sum=n/2050; n               ll ans = fun(sum); n               cout<<ans<<endl; n       } n       else{ n           cout<<-1<<endl; n       } n        n       } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   long long n; n   cin >> n; n   long long k1 = 0, k2 = 1023; n   for (long long i = 0; i < n; i++) { n     long long k; n     char c; n     cin >> c >> k; n     if (c ==  | ) { n       k1 |= k; n       k2 |= k; n     } n     if (c ==  ^ ) { n       k1 ^= k; n       k2 ^= k; n     } n     if (c ==  & ) { n       k1 &= k; n       k2 &= k; n     } n   } n   cout << 2 << endl; n   cout <<  |   << (k1 ^ (k2 ^ 1023)) << endl <<  ^   << (k2 ^ 1023); n   return 0; n } n


#include <bits/stdc++.h> n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   std::cout << name <<   :   << arg1 <<   n ; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   std::cout.write(names, comma - names) <<   :   << arg1 <<   |  ; n   __f(comma + 1, args...); n } n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long i, j, n, m, k, cnt = 0, ans = 0, t = 1; n   cin >> n; n   long long a[n]; n   for (i = 0; i < n; i++) cin >> a[i]; n   priority_queue<long long, vector<long long>, greater<long long> > pq; n   for (i = 0; i < n; i++) { n     if (!pq.empty() && pq.top() < a[i]) { n       ans += (a[i] - pq.top()); n       pq.pop(); n       pq.push(a[i]); n     } n     pq.push(a[i]); n   } n   return cout << ans, 0; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename base_type, base_type _MOD> n struct IntMod { n   static const int INVERSE_CACHE_SIZE = (1 << 20); n   static base_type MOD; n   static void set_mod(base_type new_mod) { MOD = new_mod; } n   base_type n; n   IntMod(long long d = 0) { n = (d >= 0 ? d % MOD : (d % MOD + MOD) % MOD); } n   virtual ~IntMod() = default; n   IntMod operator-() const { return build(n == 0 ? 0 : MOD - n); } n   IntMod& operator+=(IntMod a) { n     n = (n >= MOD - a.n ? n - MOD + a.n : n + a.n); n     return *this; n   } n   IntMod& operator-=(IntMod a) { n     n = (n >= a.n) ? n - a.n : n - a.n + MOD; n     return *this; n   } n   IntMod& operator*=(IntMod a) { n     *this = *this * a; n     return *this; n   } n   IntMod& operator/=(IntMod a) { n     *this = *this / a; n     return *this; n   } n   static IntMod build(base_type n) { n     IntMod L; n     L.n = n; n     return L; n   } n   static base_type inverse_cache[INVERSE_CACHE_SIZE]; n   static bool inverse_cache_ready; n   friend IntMod inverse(IntMod n) { return build(inverse_internal(n.n)); } n   static base_type inverse_internal(base_type n) { n     if (!inverse_cache_ready) { n       inverse_cache_ready = true; n       inverse_cache[0] = 0; n       inverse_cache[1] = 1; n       for (int n = 2; n < INVERSE_CACHE_SIZE; ++n) n         inverse_cache[n] = n             (MOD - n              (base_type)((long long)inverse_cache[MOD % n] * (MOD / n) % MOD)); n     } n     return n < INVERSE_CACHE_SIZE n                ? inverse_cache[n] n                : MOD - (base_type)((long long)inverse_internal(MOD % n) * n                                    (MOD / n) % MOD); n   } n   friend bool operator==(IntMod a, IntMod b) { return a.n == b.n; } n   friend bool operator!=(IntMod a, IntMod b) { return a.n != b.n; } n   friend IntMod operator+(IntMod a, IntMod b) { n     return build(a.n >= MOD - b.n ? a.n - MOD + b.n : a.n + b.n); n   } n   friend IntMod operator-(IntMod a, IntMod b) { n     return build(a.n >= b.n ? a.n - b.n : a.n - b.n + MOD); n   } n   friend IntMod operator*(IntMod a, IntMod b) { n     return build( n         static_cast<base_type>(static_cast<long long>(a.n) * b.n % MOD)); n   } n   friend IntMod operator/(IntMod a, IntMod b) { return a * inverse(b); } n   friend IntMod xpow(IntMod p, long long e) { n     if (e <= 0) return IntMod(1); n     IntMod L = IntMod(1); n     while (e) { n       if (e & 1) L *= p; n       p *= p; n       e >>= 1; n     } n     return L; n   } n   friend ostream& operator<<(ostream& os, const IntMod& p) { n     os << p.n; n     return os; n   } n   friend istream& operator>>(istream& is, IntMod& p) { n     is >> p.n; n     return is; n   } n }; n template <typename base_type, base_type _MOD> n base_type IntMod<base_type, _MOD>::inverse_cache[INVERSE_CACHE_SIZE]; n template <typename base_type, base_type _MOD> n bool IntMod<base_type, _MOD>::inverse_cache_ready; n template <typename base_type, base_type _MOD> n base_type IntMod<base_type, _MOD>::MOD = _MOD; n template <typename T, typename U> n ostream& operator<<(ostream& os, const pair<T, U>& p) { n   os << p.first <<     << p.second << endl; n   return os; n } n template <typename T> n ostream& operator<<(ostream& os, const vector<T>& vec) { n   for (const auto& v : vec) os << v <<    ; n   return os; n } n long long SQRT(long long x) { n   long long ret = sqrt(x) + 5; n   while (1) { n     if (ret * ret <= x) break; n     ret--; n   } n   return ret; n } n const int maxm = 1e5 + 5; n const int maxn = 2; n const long long MOD = 1e9 + 7; n using Int = IntMod<int, MOD>; n struct Matrix { n   Int m[maxn][maxn]; n   bool empty() { n     for (int i = 0; i < maxn; i++) n       for (int j = 0; j < maxn; j++) n         if (m[i][j] != (i == j)) return false; n     return true; n   } n   void clear() { n     for (int i = 0; i < maxn; i++) n       for (int j = 0; j < maxn; j++) m[i][j] = (i == j); n   } n   friend Matrix operator*(const Matrix& a, const Matrix& b) { n     Matrix c; n     for (int i = 0; i < maxn; i++) n       for (int j = 0; j < maxn; j++) c.m[i][j] = 0; n     for (int i = 0; i < maxn; i++) n       for (int j = 0; j < maxn; j++) n         for (int k = 0; k < maxn; k++) c.m[i][j] += a.m[i][k] * b.m[k][j]; n     return c; n   } n   friend Matrix pow(Matrix a, long long n) { n     Matrix res; n     for (int i = 0; i < maxn; i++) n       for (int j = 0; j < maxn; j++) res.m[i][j] = (i == j); n     while (n) { n       if (n & 1) res = res * a; n       n >>= 1; n       a = a * a; n     } n     return res; n   } n } bs4, E; n struct Vector { n   Int m[maxn]; n   void clear() { n     for (int i = 0; i < maxn; i++) m[i] = 0; n   } n   friend Vector operator*(const Vector& a, const Matrix& b) { n     Vector c; n     c.clear(); n     for (int i = 0; i < maxn; i++) n       for (int j = 0; j < maxn; j++) c.m[i] += a.m[j] * b.m[i][j]; n     return c; n   } n   friend Vector operator+(const Vector& a, const Vector& b) { n     Vector c; n     for (int i = 0; i < maxn; i++) c.m[i] = a.m[i] + b.m[i]; n     return c; n   } n } I; n Int calc(int idx) { n   if (idx <= 1) n     return 1; n   else { n     Matrix p = pow(bs4, idx - 2); n     return p.m[1][0] + p.m[1][1]; n   } n } n struct node { n   Vector val; n   Matrix lazy; n   int l, r; n } tree[maxm * 8]; n void push_down(int root) { n   if (!tree[root].lazy.empty()) { n     tree[root * 2 + 1].val = tree[root * 2 + 1].val * tree[root].lazy; n     tree[root * 2 + 2].val = tree[root * 2 + 2].val * tree[root].lazy; n     tree[root * 2 + 1].lazy = tree[root * 2 + 1].lazy * tree[root].lazy; n     tree[root * 2 + 2].lazy = tree[root * 2 + 2].lazy * tree[root].lazy; n     tree[root].lazy.clear(); n   } n } n void push_up(int root) { n   tree[root].val = tree[root * 2 + 1].val + tree[root * 2 + 2].val; n } n void build(int root, int l, int r) { n   tree[root].l = l; n   tree[root].r = r; n   tree[root].lazy.clear(); n   if (l == r) { n     int x; n     scanf( %d , &x); n     tree[root].val.m[0] = calc(x); n     tree[root].val.m[1] = calc(x + 1); n     return; n   } n   int mid = (l + r) / 2; n   build(root * 2 + 1, l, mid); n   build(root * 2 + 2, mid + 1, r); n   push_up(root); n } n void change(int root, int l, int r, const Matrix& val) { n   int op = tree[root].l; n   int ed = tree[root].r; n   if (op > ed) return; n   push_down(root); n   if (op == l && ed == r) { n     tree[root].val = tree[root].val * val; n     tree[root].lazy = tree[root].lazy * val; n     return; n   } n   int mid = (op + ed) / 2; n   if (r <= mid) n     change(root * 2 + 1, l, r, val); n   else if (l > mid) n     change(root * 2 + 2, l, r, val); n   else { n     change(root * 2 + 1, l, mid, val); n     change(root * 2 + 2, mid + 1, r, val); n   } n   push_up(root); n } n Vector sum(int root, int l, int r) { n   int op = tree[root].l; n   int ed = tree[root].r; n   if (op > ed) return I; n   push_down(root); n   if (op == l && ed == r) return tree[root].val; n   int mid = (op + ed) / 2; n   if (r <= mid) n     return sum(root * 2 + 1, l, r); n   else if (l > mid) n     return sum(root * 2 + 2, l, r); n   return sum(root * 2 + 1, l, mid) + sum(root * 2 + 2, mid + 1, r); n } n int main() { n   bs4.m[0][0] = 0; n   bs4.m[0][1] = 1; n   bs4.m[1][0] = 1; n   bs4.m[1][1] = 1; n   E.clear(); n   I.clear(); n   int n, q, op, l, r, val; n   scanf( %d%d , &n, &q); n   build(0, 1, n); n   while (q--) { n     scanf( %d%d%d , &op, &l, &r); n     if (op == 1) { n       scanf( %d , &val); n       change(0, l, r, pow(bs4, val)); n     } else n       printf( %d n , sum(0, l, r).m[0].n); n   } n   return 0; n } n


#include <bits/stdc++.h> n bool pr[3001]; n int prm[3001]; n using namespace std; n void primes() { n   int i, j; n   for (i = 0; i < 3001; i++) pr[i] = true; n   pr[0] = false; n   pr[1] = false; n   for (i = 2; i <= sqrt(3000); i++) { n     if (pr[i]) { n       for (j = i; i * j <= 3001; j += 1) { n         pr[i * j] = false; n       } n     } n   } n } n int main() { n   primes(); n   int n, i, k = 0, j, ans = 0; n   cin >> n; n   for (i = 0; i < 3001; i++) { n     if (pr[i]) prm[k++] = i; n   } n   for (j = 6; j <= n; j++) { n     int ct = 0; n     for (i = 0; prm[i] <= j; i++) { n       if (i >= k) break; n       if (j % prm[i] == 0) ct++; n     } n     if (ct == 2) ans++; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int chk[300004][3]; n int visit[300004]; n vector<int> vec[300004]; n vector<pair<int, int>> vecp; n void dfs(int x) { n   visit[x] = 1; n   for (int i = 0; i < vec[x].size(); i++) { n     if (visit[vec[x][i]] == 0) { n       dfs(vec[x][i]); n       chk[x][0] += chk[vec[x][i]][0]; n       chk[x][1] += chk[vec[x][i]][1]; n       chk[x][2] += chk[vec[x][i]][2]; n       vecp.push_back({chk[vec[x][i]][1], chk[vec[x][i]][2]}); n     } n   } n } n int main() { n   int a, b, c, d, e, m = 0; n   cin >> a; n   int r = 0, bl = 0; n   for (int i = 1; i <= a; i++) { n     cin >> b; n     if (b == 1) n       r++; n     else if (b == 2) n       bl++; n     chk[i][b]++; n   } n   for (int i = 1; i < a; i++) { n     cin >> b >> c; n     vec[b].push_back(c); n     vec[c].push_back(b); n   } n   dfs(1); n   for (int i = 0; i < vecp.size(); i++) { n     int red = vecp[i].first; n     int blue = vecp[i].second; n     int redo = r - red; n     int blueo = bl - blue; n     if (red >= 1 && blue == 0 && blueo >= 1 && redo == 0) { n       m++; n     } else if (red == 0 && blue >= 1 && blueo == 0 && redo >= 1) { n       m++; n     } n   } n   cout << m << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1011; n const long long INF = 5e16; n namespace IO { n inline long long read() { n   long long x = 0; n   bool f = 0; n   char ch = getchar(); n   for (; !isdigit(ch); ch = getchar()) f ^= (ch ==  - ); n   for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48); n   return f ? -x : x; n } n inline void write(long long x) { n   if (x < 0) putchar( - ), x = -x; n   if (x > 9) write(x / 10); n   putchar(x % 10 | 48); n } n inline void wrn(long long x) { n   write(x); n   putchar(   ); n } n inline void wln(long long x) { n   write(x); n   putchar(  n ); n } n inline void wlnn(long long x, long long y) { n   wrn(x); n   wln(y); n } n }  // namespace IO n using namespace IO; n namespace Cesare { n long long x, k, p; n double Ans = 0, f[N][N]; n int main() { n   x = read(), k = read(), p = read(); n   double Mul = p * 0.01, Add = 1.0 - Mul; n   for (register int i = 0; i <= k; ++i) n     for (register int j = x + i; !(j & 1); j >>= 1) ++f[0][i]; n   for (register int i = (1); i <= (k); ++i) n     for (register int j = (0); j <= (k); ++j) { n       if (j) f[i][j - 1] += f[i - 1][j] * Add; n       if (k >= (j << 1)) f[i][j << 1] += (f[i - 1][j] + 1) * Mul; n     } n   return printf( %.12lf n , f[k][0]), 0; n } n }  // namespace Cesare n int main() { return Cesare::main(); } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int q, l, k, n, m, a, b, c, sum = 0; n   cin >> l >> k; n   a = l * 2; n   b = l * 5; n   c = l * 8; n   sum = ((a / k) + (b / k) + (c / k)); n   if (a % k != 0) sum++; n   if (b % k != 0) sum++; n   if (c % k != 0) sum++; n   cout << sum << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int h, w; n int get(int x, int y) { n   if (!y) return x; n   if (x == h) return h + y; n   if (y == w) return h + w + (h - x); n   return h + w + h + (w - y); n } n vector<pair<long long, long long> > get(int h, int w, int x, int a, int b) { n   vector<pair<long long, long long> > ans; n   if (a <= 0 && b <= 0) return ans; n   if (a >= w && b >= w) return ans; n   if (x >= h || x <= 0) return ans; n   if (a > 0 && a < w && b > 0 && b < w) return ans; n   int fl = 0; n   if (a > b) swap(a, b), fl = 1; n   if (a <= 0 && b >= w) { n     ans.push_back(pair<long long, long long>(x, 0)); n     ans.push_back(pair<long long, long long>(x, w)); n   } else if (a > 0) n     ans.push_back(pair<long long, long long>(x, w)); n   else n     ans.push_back(pair<long long, long long>(x, 0)); n   if (fl) reverse(ans.begin(), ans.end()); n   return ans; n } n int x[120005], y[120005]; n bool vis[120005]; n vector<int> e[120005]; n void add(int x, int y) { n   e[x].push_back(y); n   e[y].push_back(x); n } n void dfs(int x) { n   vis[x] = 1; n   for (int i = 0; i < e[x].size(); i++) n     if (!vis[e[x][i]]) dfs(e[x][i]); n } n int main() { n   int x1, x2, y1, y2; n   scanf( %d%d%d%d , &x1, &y1, &x2, &y2); n   swap(y1, y2); n   x1 *= 2; n   x2 *= 2; n   y1 *= 2; n   y2 *= 2; n   h = x2 - x1, w = y2 - y1; n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d%d , &x[i], &y[i]); n     x[i] *= 2; n     y[i] *= 2; n     x[i] -= x1; n     y[i] -= y1; n   } n   int fl = 0; n   for (int i = 0; i < n; i++) n     if (x[i] < 0 || y[i] < 0 || x[i] > h || y[i] > w) { n       rotate(x, x + i, x + n); n       rotate(y, y + i, y + n); n       fl = 1; n       break; n     } n   if (!fl) return puts( 1 ), 0; n   x[n] = x[0]; n   y[n] = y[0]; n   int cnt = 0; n   vector<pair<long long, int> > vec; n   for (int i = 0; i < n; i++) n     if (x[i] == x[i + 1]) { n       vector<pair<long long, long long> > tmp = get(h, w, x[i], y[i], y[i + 1]); n       for (int j = 0; j < tmp.size(); j++) n         vec.push_back( n             pair<long long, int>(get(tmp[j].first, tmp[j].second), cnt++)); n     } else { n       vector<pair<long long, long long> > tmp = get(w, h, y[i], x[i], x[i + 1]); n       for (int j = 0; j < tmp.size(); j++) n         vec.push_back( n             pair<long long, int>(get(tmp[j].second, tmp[j].first), cnt++)); n     } n   if (!vec.size()) { n     int a = h / 2, b = w / 2; n     double ang = 0; n     for (int i = 0; i < n; i++) n       ang += atan2((x[i] - a) * (y[i + 1] - b) - (y[i] - b) * (x[i + 1] - a), n                    (x[i] - a) * (x[i + 1] - a) + (y[i] - b) * (y[i + 1] - b)); n     printf( %d , abs(ang) <= 1 ? 0 : 1); n     return 0; n   } n   for (int i = 0; i < vec.size(); i += 2) add(vec[i].second, vec[i + 1].second); n   sort(vec.begin(), vec.end()); n   for (int i = 0; i < vec.size(); i++) n     if (vec[i].second == 0) { n       rotate(vec.begin(), vec.begin() + i, vec.end()); n       break; n     } n   rotate(vec.begin(), vec.begin() + 1, vec.end()); n   for (int i = 0; i < vec.size(); i += 2) add(vec[i].second, vec[i + 1].second); n   int ans = 0; n   for (int i = 0; i < cnt; i++) n     if (!vis[i]) dfs(i), ans++; n   printf( %d , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int sum[1000100]; n int main() { n   string a, b; n   cin >> a >> b; n   int cnt = 0; n   for (int i = 0; i < b.size(); i++) { n     if (b[i] ==  1 ) cnt++; n   } n   sum[0] = a[0] -  0 ; n   for (int i = 1; i < a.size(); i++) { n     sum[i] = sum[i - 1] + a[i] -  0 ; n   } n   int l = 0, r = b.size() - 1; n   int ans = 0; n   while (r < a.size()) { n     if (cnt % 2 == 0 && (sum[r] - sum[l] + a[l] -  0 ) % 2 == 0) { n       ans++; n     } else if (cnt % 2 != 0 && (sum[r] - sum[l] + a[l] -  0 ) % 2 != 0) { n       ans++; n     } n     l++; n     r++; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[100010], b[100010]; n int main(int argc, char *argv[]) { n   int n; n   long long t, Sum = 0; n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     scanf( %lld , &t); n     Sum += t; n   } n   for (int i = 1; i <= n; ++i) scanf( %lld , &b[i]); n   sort(b + 1, b + 1 + n); n   if (Sum <= (b[n] + b[n - 1])) n     puts( YES ); n   else n     puts( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long infl = 0x3f3f3f3f3f3f3f3fLL; n const long long infi = 0x3f3f3f3f; n const long long mod = infl; n long long mygcd(long long a, long long b) { n   if (b == 0) { n     return a; n   } n   return mygcd(b, a % b); n } n long long mypow(long long a, long long b) { n   long long res = 1; n   while (b) { n     if (b & 1) res = (res * a) % mod; n     a = (a * a) % mod; n     b >>= 1; n   } n   return res; n } n void solve() { n   long long n, d; n   cin >> n >> d; n   vector<long long> pro(n); n   for (long long i = 1; i < n - 1; i++) { n     cin >> pro[i]; n   } n   vector<vector<long long>> gr(n); n   for (long long i = 0; i < n; i++) { n     long long x, y; n     cin >> x >> y; n     gr[i] = {x, y}; n   } n   auto isok = [&](long long x) { n     vector<long long> best(n, -1); n     best[0] = x; n     queue<long long> q; n     q.push(0); n     while (q.size()) { n       long long front = q.front(); n       q.pop(); n       for (long long i = 1; i < n; i++) { n         if (i == front) { n           continue; n         } n         long long need = n             d * (abs(gr[front][0] - gr[i][0]) + abs(gr[front][1] - gr[i][1])); n         if (need > best[front]) { n           continue; n         } n         long long new_best = best[front] - need + pro[i]; n         if (new_best > best[i]) { n           best[i] = new_best; n           q.push(i); n         } n       } n     } n     if (best[n - 1] == -1) { n       return false; n     } n     return true; n   }; n   long long l = 0; n   long long r = infi; n   while (l < r) { n     long long m = (l + r) / 2; n     if (isok(m)) { n       r = m; n     } else { n       l = m + 1; n     } n   } n   cout << r <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cout << fixed << setprecision(20); n   cin.tie(NULL); n   long long t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double inf = 1.0 / 0.0; n const double pi = 2 * acos(0.0); n map<char, int> tab, tab1; n char x; n int main() { n   tab1[ Q ] = 9; n   tab[ q ] = 9; n   tab1[ R ] = 5; n   tab[ r ] = 5; n   tab1[ B ] = 3; n   tab[ b ] = 3; n   tab1[ P ] = 1; n   tab[ p ] = 1; n   tab1[ N ] = 3; n   tab[ n ] = 3; n   tab1[ K ] = 0; n   tab[ k ] = 0; n   ios_base::sync_with_stdio(false); n   int b = 0, w = 0; n   for (int i = 0; i < 8; i++) { n     for (int j = 0; j < 8; j++) { n       x = getchar(); n       if (tab.count(x) != 0) { n         b += tab[x]; n       } else if (tab1.count(x) != 0) { n         w += tab1[x]; n       } n     } n     getchar(); n   } n   if (b > w) n     cout <<  Black n ; n   else if (w > b) n     cout <<  White n ; n   else n     cout <<  Draw n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = n     3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342; n const int MR = 1e5 + 10; n const long long inf = 1e18; n long long dp[21][MR]; n int A[21][MR]; n int a[MR]; n int freq[MR], gp, gk; n long long cost; n long long ile(int b, int e) { n   while (gp > b) { n     cost += freq[a[gp - 1]]; n     freq[a[gp - 1]]++; n     gp--; n   } n   while (gp < b) { n     freq[a[gp]]--; n     cost -= freq[a[gp]]; n     gp++; n   } n   while (gk > e) { n     freq[a[gk - 1]]--; n     cost -= freq[a[gk - 1]]; n     gk--; n   } n   while (gk < e) { n     cost += freq[a[gk]]; n     freq[a[gk]]++; n     gk++; n   } n   return cost; n } n void compute(int k, int l, int r, int Al, int Ar) { n   if (l >= r) return; n   assert(Al <= Ar); n   int m = (l + r) / 2; n   dp[k][m] = inf; n   for (int i = (max(Al, A[k - 1][m])); i < (min(Ar + 1, m)); ++i) { n     long long cnt = ile(i + 1, m + 1); n     if (dp[k][m] > dp[k - 1][i] + cnt) { n       dp[k][m] = dp[k - 1][i] + cnt; n       A[k][m] = i; n     } n   } n   compute(k, l, m, Al, A[k][m]); n   compute(k, m + 1, r, A[k][m], Ar); n } n int main() { n   int n, k; n   scanf( %d%d , &n, &k); n   for (int i = (1); i <= (n); ++i) scanf( %d , &a[i]); n   gp = 1; n   gk = 1; n   for (int i = (1); i <= (n); ++i) { n     dp[1][i] = ile(1, i + 1); n     A[1][i] = 0; n   } n   for (int i = (2); i <= (k); ++i) compute(i, i, n + 1, i - 1, n); n   cout << dp[k][n] << endl; 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 long long Pow[25][505], n, V, ans, B; n long long val[505]; n void dfs2(long long i, long long b, long long a) { n   if ((double)b * b > V / a) { n     return; n   } n   if (i > n) { n     B = max(B, b); n     return; n   } n   for (register long long j = val[i]; j >= 0; --j) { n     dfs2(i + 1, b * Pow[i][j], a); n   } n } n long long ansA, ansB, ansC; n void dfs1(long long i, long long a) { n   if ((double)a * a * a > V) { n     return; n   } n   if (i > n) { n     const long long t = V / a; n     long long Smax = 4 * a * sqrt(t) + 2 * t; n     if (Smax >= ans) return; n     B = 0, dfs2(1, 1, a); n     long long c = V / a / B, Ans = (a * B + B * c + c * a) << 1; n     if (Ans < ans) { n       ans = Ans; n       ansA = a, ansB = B, ansC = c; n     } n     return; n   } n   for (register long long j = val[i]; j >= 0; --j) { n     val[i] -= j; n     dfs1(i + 1, a * Pow[i][j]); n     val[i] += j; n   } n } n int main() { n   long long T; n   cin >> T; n   while (T--) { n     cin >> n; n     V = 1; n     for (register long long i = 1; i <= n; ++i) { n       long long a, b; n       cin >> a >> b; n       val[i] = b; n       Pow[i][0] = 1; n       for (register long long j = 1; j <= b; ++j) { n         Pow[i][j] = Pow[i][j - 1] * a; n       } n       V *= Pow[i][b]; n     } n     ans = 1ll << 62; n     dfs1(1, 1); n     cout << ans <<     << ansA <<     << ansB <<     << ansC << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ii = pair<int, int>; n using vi = vector<int>; n const double PI = acos(-1); n const double EPS = 1e-9; n int main() { n   ios_base::sync_with_stdio(0); n   int n, m; n   cin >> n >> m; n   int mt[n][m]; n   int ans = 0; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> mt[i][j]; n       if (j == 0) { n         ans ^= mt[i][j]; n       } n     } n   } n   if (ans > 0) { n     cout <<  TAK n ; n     for (int i = 0; i < n; i++) { n       cout << 1; n       if (i == n - 1) n         cout << endl; n       else n         cout <<    ; n     } n   } else { n     ii res(-1, -1); n     for (int i = 0; i < n; i++) { n       for (int j = 1; j < m; j++) { n         int kk = ans ^ mt[i][0] ^ mt[i][j]; n         if (kk > 0) { n           res.first = i; n           res.second = j; n         } n       } n     } n     int aa = ans ^ 1 ^ 0; n     if (res.first >= 0) n       ans = ans ^ mt[res.first][0] ^ mt[res.first][res.second]; n     if (ans > 0) { n       cout <<  TAK n ; n       for (int i = 0; i < n; i++) { n         if (i == res.first) n           cout << res.second + 1; n         else n           cout << 1; n         if (i == n - 1) n           cout << endl; n         else n           cout <<    ; n       } n     } else { n       cout <<  NIE n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long int> prm(1000010, 1); n long long int P = 1e9 + 7; n long long int M = 998244353; n char adjlist[1001][1001]; n bool visited[1000001] = {false}; n long double pi = 3.14159265358979323846264338327950; n map<int, int> visit; n map<int, set<int>> g; n int cc = 0; n vector<pair<int, int>> moves = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; n int lps[1000000]; n vector<pair<int, int>> final_set; n bool comp(const pair<long long int, long long int> &a, n           const pair<long long int, long long int> &b) { n   if (a.first == b.first) return a.second > b.second; n   return a.first < b.first; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int n, m, s, f; n   cin >> n >> m >> s >> f; n   bool flag = true; n   long long int curr = s; n   if (s > f) flag = false; n   long long int i, j; n   long long int t, x, y; n   bool mflag = false; n   long long int back = 0; n   string str =   ; n   for (i = 0; i < m; i++) { n     if (i == 0) n       back = 0; n     else n       back = t; n     cin >> t >> x >> y; n     if (curr == f) continue; n     if (t - 1 != back) { n       while (back + 1 < t) { n         if (flag == false) { n           str.push_back( L ); n           curr--; n         } else { n           str.push_back( R ); n           curr++; n         } n         if (curr == f) break; n         back++; n       } n     } n     if (curr == f) continue; n     if (flag == false) { n       if (curr < x || curr - 1 > y) { n         str.push_back( L ); n         curr--; n         continue; n       } else { n         str.push_back( X ); n         continue; n       } n     } else { n       if (curr > y || curr + 1 < x) { n         str.push_back( R ); n         curr++; n         continue; n       } else { n         str.push_back( X ); n         continue; n       } n     } n   } n   if (curr != f) { n     if (flag == false) { n       for (i = curr; i > f; i--) str.push_back( L ); n     } else { n       for (i = curr; i < f; i++) str.push_back( R ); n     } n   } n   cout << str <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rnd; n const long long maxn = 2e6 + 5; n const long long mod = 1e9 + 7; n long long fac[maxn]; n long long inv[maxn]; n vector<char> prime(maxn, true); n long long spf[maxn]; n long long binpow(long long a, long long b) { n   if (b == 0) return 1; n   if (b == 1) return a % mod; n   if (b == 2) return (a * a) % mod; n   if (b % 2 == 0) return binpow((a * a) % mod, b / 2); n   if (b % 2 == 1) return (a * binpow((a * a) % mod, b / 2)) % mod; n } n void buildprimes() { n   prime[0] = prime[1] = false; n   for (long long i = 2; i < maxn; ++i) { n     if (prime[i]) { n       spf[i] = i; n       if (i * 1ll * i < maxn) { n         for (long long j = i * i; j < maxn; j += i) { n           prime[j] = false; n           spf[j] = i; n         } n       } n     } n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   fac[1] = fac[0] = 1; n   for (long long i = 2; i < maxn; i++) { n     fac[i] = (fac[i - 1] * i) % mod; n   } n   for (long long i = 1; i < maxn; i++) { n     inv[i] = binpow(fac[i], mod - 2); n   } n   buildprimes(); n   int q; n   cin >> q; n   while (q--) { n     int x, y; n     cin >> x >> y; n     if (y == 1) { n       cout <<  1 n ; n       continue; n     } n     long long ans = 1; n     ans = binpow(2, y - 1); n     while (x > 1) { n       long long cur = 0; n       long long p = spf[x]; n       while (x % p == 0) { n         x /= p; n         cur++; n       } n       long long C = (((fac[cur + y - 1] * inv[y - 1]) % mod) * inv[cur]) % mod; n       ans = (ans * C) % mod; n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   string t =   ; n   for (int i = 0; i < s.length(); i++) { n     if (s[i] !=  a  && s[i] !=  e  && s[i] !=  i  && s[i] !=  o  && n         s[i] !=  u  && s[i] !=  y  && s[i] !=  Y  && s[i] !=  A  && n         s[i] !=  E  && s[i] !=  I  && s[i] !=  O  && s[i] !=  U ) { n       t += s[i]; n     } n   } n   string p =   ; n   for (int i = 0; i < t.length(); i++) { n     char c = t[i]; n     if (isupper(c)) { n       p += tolower(c); n     } else { n       p += c; n     } n   } n   string l =   ; n   for (int i = 0; i < p.length(); i++) { n     l +=  . ; n     l += p[i]; n   } n   cout << l; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   string s; n   for (int i = 1; i < 1000000 && s.size() < 1000; i++) { n     char val[20]; n     sprintf(val,  %d , i); n     s += val; n   } n   int n; n   cin >> n; n   cout << s[n - 1]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5; n const double EPS = 1e-8; n int a[MAXN], b[MAXN]; n int n, p; n bool f(double T) { n   double have = p * T; n   for (int i = 0; i < n; ++i) { n     if (a[i] * T > b[i] + EPS) have += b[i] - a[i] * T; n   } n   return have > 0.0 + EPS; n } n int main() { n   cin >> n >> p; n   long long sum = 0; n   for (int i = 0; i < n; ++i) { n     cin >> a[i] >> b[i]; n     sum += a[i]; n   } n   if (sum <= p) { n     cout << -1; n     return 0; n   } n   double left = 0, right = 1e10; n   for (int i = 0; i < 80; ++i) { n     double middle = (left + right) / 2; n     if (f(middle)) n       left = middle; n     else n       right = middle; n   } n   cout << fixed; n   cout.precision(10); n   cout << left; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   long long mn, mx, n, m; n   cin >> n >> m; n   mx = n - m; n   mx++; n   mx = (mx * (mx - 1)) / 2; n   mn = n / m; n   long long temp = n / m; n   if (n % m != 0) { n     mn = (n % m) * ((mn * (mn + 1)) / 2); n     m -= (n % m); n     mn += m * ((temp * (temp - 1)) / 2); n   } else n     mn = m * ((temp * (temp - 1)) / 2); n   cout << mn <<     << mx << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int i, n; n   cin >> n; n   for (i = 1;; ++i) { n     if ((i * (i + 1)) / 2 >= n) break; n   } n   cout << n - (i * (i - 1)) / 2; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count()); n const int N = 765; n const long long inf = (long long)4e18; n long long dp[N][N]; n long long f[N]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   int n, m; n   cin >> n >> m; n   long long a[n]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (int i = 0; i < N; i++) { n     for (int j = 0; j < N; j++) { n       dp[i][j] = -inf; n     } n   } n   dp[n][0] = 0; n   for (int i = n - 1; i >= 0; i--) { n     for (int j = 0; j <= n; j++) { n       dp[i][j] = min(a[i] + dp[i + 1][j], a[i]); n       if (j > 0) { n         dp[i][j] = max(dp[i][j], dp[i + 1][j - 1]); n       } n     } n   } n   for (int j = 0; j <= n; j++) f[j] = dp[0][j]; n   long long b; n   for (int i = 1; i <= m; i++) { n     cin >> b; n     for (int i = 0; i <= n; i++) { n       if (b + f[i] >= 0) { n         cout << i <<   n ; n         break; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = (int)2e5 + 10, L = 4, INF = (int)1e9; n struct State { n   int fa, len, tr[L], w[L]; n } SAM[MAXN]; n char t[MAXN]; n vector<int> l[MAXN]; n int m, tot; n unsigned long long a[L], b[L][L], c[L][L]; n unsigned long long n; n int Build(int pre, int id) { n   int cp = ++tot; n   SAM[cp].len = SAM[pre].len + 1; n   for (; !SAM[pre].tr[id] && pre; SAM[pre].tr[id] = cp, pre = SAM[pre].fa) n     ; n   if (pre) n     if (SAM[pre].len + 1 == SAM[SAM[pre].tr[id]].len) n       SAM[cp].fa = SAM[pre].tr[id]; n     else { n       int tp = SAM[pre].tr[id]; n       ++tot, SAM[tot].len = SAM[pre].len + 1, SAM[tot].fa = SAM[tp].fa; n       memcpy(SAM[tot].tr, SAM[tp].tr, sizeof(SAM[tot].tr)); n       SAM[cp].fa = SAM[tp].fa = tot; n       for (; pre && SAM[pre].tr[id] == tp; n            SAM[pre].tr[id] = tot, pre = SAM[pre].fa) n         ; n     } n   else n     SAM[cp].fa = 1; n   return cp; n } n void init() { n   cin >> n; n   scanf( %s , t + 1); n   m = strlen(t + 1); n   tot = 1; n   for (int i = 1, p = 1; i <= m; ++i) p = Build(p, t[i] -  A ); n   for (int i = 1; i <= tot; ++i) { n     for (int j = 0; j < L; ++j) n       if (!SAM[i].tr[j]) n         SAM[i].w[j] = 1; n       else n         SAM[i].w[j] = INF; n     l[SAM[i].len].push_back(i); n   } n   for (int i = m; i >= 0; --i) n     for (int j = 0; j < (int)l[i].size(); ++j) n       for (int k = 0; k < L; ++k) n         if (SAM[l[i][j]].tr[k]) n           for (int p = 0; p < L; ++p) { n             int first = l[i][j]; n             SAM[first].w[p] = n                 min(SAM[first].w[p], SAM[SAM[first].tr[k]].w[p] + 1); n           } n } n void mul(unsigned long long a[][L], unsigned long long b[][L], n          unsigned long long c[][L]) { n   static unsigned long long w[L][L]; n   for (int i = 0; i < L; ++i) n     for (int j = 0; j < L; ++j) w[i][j] = n + 1; n   for (int i = 0; i < L; ++i) n     for (int j = 0; j < L; ++j) n       for (int k = 0; k < L; ++k) w[i][j] = min(w[i][j], b[i][k] + c[k][j]); n   for (int i = 0; i < L; ++i) n     for (int j = 0; j < L; ++j) a[i][j] = w[i][j]; n } n void Pow(unsigned long long a[][L], unsigned long long b) { n   static unsigned long long d[L][L]; n   for (int i = 0; i < L; ++i) n     for (int j = 0; j < L; ++j) d[i][j] = n + 1; n   for (int i = 0; i < L; ++i) d[i][i] = 0; n   for (; b; mul(a, a, a), b /= 2) n     if (b & 1) mul(d, d, a); n   memcpy(a, d, sizeof(d)); n } n unsigned long long check(unsigned long long k) { n   memcpy(b, c, sizeof(b)); n   Pow(b, k - 2); n   unsigned long long Tohka = n + 1; n   for (int i = 0; i < L; ++i) n     for (int j = 0; j < L; ++j) Tohka = min(Tohka, a[i] + b[i][j]); n   return Tohka; n } n unsigned long long Find(unsigned long long l, unsigned long long r) { n   while (l <= r) { n     unsigned long long mid = (l + r) >> 1; n     if (check(mid) > n) n       r = mid - 1; n     else n       l = mid + 1; n   } n   return r; n } n void solve() { n   for (int i = 0; i < L; ++i) a[i] = max(SAM[1].w[i], 1); n   for (int i = 0; i < L; ++i) n     for (int j = 0; j < L; ++j) c[i][j] = max(SAM[SAM[1].tr[i]].w[j], 1); n   if (n == 1) n     puts( 1 ); n   else n     cout << Find(2, n) << endl; n } n int main() { n   init(); n   solve(); n   fclose(stdin); n   fclose(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 20; n int a[MAXN]; n int main() { n   int k; n   scanf( %d , &k); n   for (int i = 1; i <= 12; i++) { n     scanf( %d , &a[i]); n   } n   sort(a + 1, a + 13); n   int tot = 0, ans = 0; n   for (int i = 12; i >= 1; i--) { n     if (tot >= k) { n       break; n     } n     tot += a[i]; n     ans++; n   } n   if (tot < k) { n     printf( -1 n ); n   } else { n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   switch (n) { n     case 1: n       cout << n * 2 << endl; n       break; n     case 2: n       cout << n + 1 << endl; n       break; n     case 3: n       cout << n - 2 << endl; n       break; n     case 4: n       cout << n / 2 << endl; n       break; n     case 5: n       cout << n / n << endl; n       break; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 2e5; n int main() { n   int n; n   cin >> n; n   int f = 0, z = 0; n   for (int i = 0; i < n; i++) { n     int val; n     scanf( %d , &val); n     if (val == 5) n       f++; n     else n       z++; n   } n   int mx = 0; n   for (int i = 0; i <= f; i++) n     if ((5 * i) % 9 == 0) mx = i; n   if (!z) n     cout << -1; n   else { n     if (!mx) n       cout << 0; n     else { n       for (int i = 0; i < mx; i++) cout << 5; n       for (int i = 0; i < z; i++) cout << 0; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1 << 30; n long long m, r; n signed main() { n   double ans = 0; n   scanf( %d%d , &m, &r); n   for (long long i = 1; i <= m; i++) { n     double sum = 2 * r; n     if (i - 1 != 0) { n       sum += 2 * r + sqrt(2) * r; n       if (i - 1 >= 2) { n         sum += r * (i - 1) * (i - 2) + (i - 2) * 2 * sqrt(2) * r; n       } n     } n     if (m - i != 0) { n       sum += 2 * r + sqrt(2) * r; n       if (m - i >= 2) { n         sum += r * (m - i - 0) * (m - i - 1) + (m - i - 1) * 2 * sqrt(2) * r; n       } n     } n     ans += sum; n   } n   printf( %.8f n , ans / (m * m)); n   return 0; n } n


#include <bits/stdc++.h> n using i64 = long long; n int n; n std::vector<std::vector<int>> g; n std::vector<int> sz, d; n int dfs(int v, int p) { n   return sz[v] = n              std::accumulate(g[v].begin(), g[v].end(), 1, [=](int s, int c) { n                return s + (d[c] >= 0 || c == p ? 0 : dfs(c, v)); n              }); n } n int centroid(int v, int p, int t) { n   for (auto c : g[v]) { n     if (d[c] >= 0 || c == p) continue; n     if (2 * sz[c] > t) return centroid(c, v, t); n   } n   return v; n } n void rec(int v, int r) { n   dfs(v, -1); n   int c = centroid(v, -1, sz[v]); n   d[c] = r; n   for (auto e : g[c]) { n     if (d[e] >= 0) continue; n     rec(e, r + 1); n   } n } n int main() { n   scanf( %d , &n); n   g.resize(n); n   sz.resize(n); n   d.resize(n, -1); n   for (int i = 1; i < n; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     --u; n     --v; n     g[u].push_back(v); n     g[v].push_back(u); n   } n   rec(0, 0); n   for (char c : d) printf( %c  ,  A  + c); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int read() { n   int x = 0, f = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while ( 0  <= c && c <=  9 ) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   return x * f; n } n int n, m, cnt, h[200005], X[200005], Y[200005], dep[200005], du[200005], Tot, n     col[200005], ans[200005]; n struct Edge { n   int to, next; n } a[200005 * 2]; n inline void Add(int x, int y) { n   cnt++; n   a[cnt].to = y; n   a[cnt].next = h[x]; n   h[x] = cnt; n } n void dfs(int x, int fa, int ban) { n   dep[x] = dep[fa] + 1; n   int now = 1; n   if (ban == Tot) n     for (int i = h[x]; i; i = a[i].next) { n       int y = a[i].to; n       if (y != fa) { n         ans[y] = now; n         dfs(y, x, now); n         now = min(now + 1, Tot - 1); n         if (!now) now = 1; n       } n     } n   else n     for (int i = h[x]; i; i = a[i].next) { n       int y = a[i].to; n       if (y != fa) { n         if (now == ban) now++; n         ans[y] = now; n         dfs(y, x, now); n         now = min(now + 1, Tot); n       } n     } n } n bool check(int lim) { n   int sum = 0; n   for (int i = 1; i <= n; ++i) sum += (du[i] > lim); n   return sum <= m; n } n int main() { n   n = read(); n   m = read(); n   for (int i = 1; i < n; ++i) { n     int x = read(), y = read(); n     X[i] = x; n     Y[i] = y; n     Add(x, y); n     Add(y, x); n     du[x]++; n     du[y]++; n   } n   int l = 1, r = n, mid; n   while (l <= r) { n     mid = l + r >> 1; n     if (check(mid)) n       r = mid - 1, Tot = mid; n     else n       l = mid + 1; n   } n   dfs(1, 0, 0); n   cout << Tot <<   n ; n   for (int i = 1; i < n; ++i) { n     if (dep[X[i]] > dep[Y[i]]) n       cout << ans[X[i]] <<    ; n     else n       cout << ans[Y[i]] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 123; n const int MINN = 1e3 + 123; n const int mod = 1e9 + 7; n const int INF = 1e9 + 1; n pair<int, int> a[MINN]; n bool cmp(pair<int, int> a, pair<int, int> b) { n   if (a.first < b.first) return 1; n   if (a.first == b.first) n     if (a.second > b.second) return 1; n   return 0; n } n int main() { n   int n, sum; n   cin >> sum >> n; n   for (int i = 1; i <= n; i++) scanf( %d%d , &a[i].first, &a[i].second); n   sort(a + 1, a + n + 1, &cmp); n   for (int i = 1; i <= n; i++) { n     if (sum <= a[i].first) { n       cout <<  NO ; n       return 0; n     } n     sum += a[i].second; n   } n   cout <<  YES ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e5 + 100; n int m, n; n long long sweets[MAXN]; n vector<long long> sol; n long long weightedSum; n long long sums[MAXN]; n int main() { n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     cin >> sweets[i]; n   } n   sort(sweets, sweets + n); n   for (int i = 0; i < n;) { n     for (int j = 0; j < m && i + j < n; j++) { n       sums[j] += sweets[i + j]; n       weightedSum += sums[j]; n       sol.push_back(weightedSum); n     } n     i += m; n   } n   for (int i = 0; i < sol.size(); i++) { n     cout << sol[i] <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct MP { n   long long g[310][310]; n } f[10], nil, tmp, c; n int n, m, x, y, z1, z2, ans; n void U(long long &x, long long y) { x = max(x, y); } n MP CC(MP &f1, MP &f2) { n   MP res = nil; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) { n       for (int k = 1; k <= n; k++) U(res.g[i][j], f1.g[i][k] + f2.g[k][j]); n       U(res.g[i][j], min(f1.g[i][j], f2.g[i][j])); n     } n   return res; n } n bool pd(MP &t) { n   for (int i = 1; i <= n; i++) n     if (t.g[i][i] > 0) return 1; n   return 0; n } n int main() { n   scanf( %d%d , &n, &m); n   memset(nil.g, -38, sizeof nil.g); n   for (int i = 0; i < 10; i++) f[i] = nil; n   for (; m--;) { n     scanf( %d%d%d%d , &x, &y, &z1, &z2); n     f[0].g[x][y] = z1; n     f[0].g[y][x] = z2; n   } n   for (int i = 1; i < 10; i++) { n     f[i] = CC(f[i - 1], f[i - 1]); n     if (pd(f[i])) { n       ans = 1 << i >> 1; n       tmp = f[i - 1]; n       for (int j = i - 2; j >= 0; j--) { n         c = CC(tmp, f[j]); n         if (!pd(c)) { n           tmp = c; n           ans += 1 << j; n         } n       } n       return 0 * printf( %d , ans + 1); n     } n   } n   printf( 0 ); n } n


#include <bits/stdc++.h> n const long long oo = 2 * 1000 * 1000 * 1000; n const int _cnt = 1000 * 1000; n const int _p = 1000 * 1000 * 1000 + 7; n long long o(long long x) { return x % _p; } n int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } n int lcm(int a, int b) { return a * b / gcd(a, b); } n using namespace std; n void file_put() { n   freopen( filename.in ,  r , stdin); n   freopen( filename.out ,  w , stdout); n } n struct squaretype { n   int x, r; n }; n string st; n int a[1000], n, m; n bool check(string st) { n   for (int i = 0; i < st.length(); i++) n     if (st[i] != st[0]) return false; n   return true; n } n int main() { n   scanf( %d%d , &n, &m); n   cin.ignore(); n   for (int i = 1; i <= n; i++) { n     getline(cin, st); n     if (check(st)) { n       a[i] = st[0]; n       continue; n     } n     printf( NO n ); n     return 0; n   } n   for (int i = 2; i <= n; i++) n     if (a[i] == a[i - 1]) { n       printf( NO n ); n       return 0; n     } n   printf( YES n ); n   return 0; n } n


#include <bits/stdc++.h> n const int N = 1e6 + 6, mod = 1e9 + 7; n int n, sum[3]; n inline int read() { n   int s = 0, f = 1; n   char ch; n   for (; ch <  0  || ch >  9 ; ch = getchar()) n     if (ch ==  - ) f = -1; n   for (; ch >=  0  && ch <=  9 ; ch = getchar()) n     s = (s << 1) + (s << 3) + ch -  0 ; n   return s * f; n } n inline int add(int a, int b) { return (a += b) >= mod ? a - mod : a; } n inline int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; } n inline int mul(int a, int b) { return 1LL * a * b % mod; } n inline void Add(int &a, int b) { a = add(a, b); } n inline void Sub(int &a, int b) { a = sub(a, b); } n inline void Mul(int &a, int b) { a = mul(a, b); } n inline int quickpow(int a, int b) { n   int re = 1; n   while (b) { n     if (b & 1) Mul(re, a); n     b >>= 1; n     Mul(a, a); n   } n   return re; n } n int fac[N + 1], inv[N + 1], f[N + 1]; n inline void input() { n   fac[0] = 1; n   for (int i = 1; i <= N; ++i) fac[i] = mul(fac[i - 1], i); n   inv[N] = quickpow(fac[N], mod - 2); n   for (int i = N; i >= 1; --i) inv[i - 1] = mul(inv[i], i); n   f[0] = f[1] = 1, f[2] = 2; n   for (int i = 3; i <= N; ++i) f[i] = add(mul(f[i - 2], (i - 1)), f[i - 1]); n } n inline int C(int n, int m) { n   if (n < m || n < 0 || m < 0) return 0; n   return mul(fac[n], mul(inv[m], inv[n - m])); n } n int main() { n   input(); n   for (int _ = 1; _; --_) { n     n = read(); n     sum[1] = sum[2] = 0; n     for (int i = 1; i <= n; ++i) ++sum[read()]; n     printf( %d n , mul(mul(fac[n], inv[sum[1]]), f[sum[1]])); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 200001; n long long par[N], siz[N]; n long long f(long long n) { n   if (n == par[n]) n     return n; n   else n     return par[n] = f(par[n]); n } n void u(long long a, long long b) { n   a = f(a); n   b = f(b); n   if (a != b) { n     if (siz[a] < siz[b]) swap(a, b); n     par[b] = a; n     siz[a] += siz[b]; n   } n } n void solve() { n   long long n; n   cin >> n; n   string s[n + 1]; n   for (long long i = 1; i <= n; i++) { n     cin >> s[i]; n     par[i] = i; n     siz[i] = 1; n   } n   for (char c =  a ; c <=  z ; c++) { n     vector<long long> v; n     for (long long i = 1; i <= n; i++) { n       for (long long j = 0; j < s[i].length(); j++) { n         if (s[i][j] == c) v.push_back(i); n       } n     } n     for (long long i = 1; i < v.size(); i++) u(v[i], v[i - 1]); n   } n   set<long long> se; n   for (long long i = 1; i <= n; i++) { n     long long x = f(i); n     se.insert(x); n   } n   cout << se.size() <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void _print(long long t) { cerr << t; } n void _print(int t) { cerr << t; } n void _print(string t) { cerr << t; } n void _print(char t) { cerr << t; } n void _print(long double t) { cerr << t; } n void _print(double t) { cerr << t; } n void _print(unsigned long long t) { cerr << t; } n template <class T, class V> n void _print(pair<T, V> p); n template <class T> n void _print(vector<T> v); n template <class T> n void _print(set<T> v); n template <class T, class V> n void _print(map<T, V> v); n template <class T> n void _print(multiset<T> v); n template <class T, class V> n void _print(pair<T, V> p) { n   cerr <<  { ; n   _print(p.first); n   cerr <<  , ; n   _print(p.second); n   cerr <<  } ; n } n template <class T> n void _print(vector<T> v) { n   cerr <<  [  ; n   for (T i : v) { n     _print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n template <class T> n void _print(set<T> v) { n   cerr <<  [  ; n   for (T i : v) { n     _print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n template <class T> n void _print(multiset<T> v) { n   cerr <<  [  ; n   for (T i : v) { n     _print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n template <class T, class V> n void _print(map<T, V> v) { n   cerr <<  [  ; n   for (auto i : v) { n     _print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n int gcd(int a, int b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n bool isprime(long long a) { n   if (a <= 1) return false; n   if (a == 2 || a == 3) return true; n   if (a % 2 == 0 || a % 3 == 0) return false; n   for (int i = 5; i * i <= a; i += 6) { n     if (a % i == 0 || a % (i + 2) == 0) return false; n   } n   return true; n } n void sieve(vector<bool> &isprimesieve) { n   isprimesieve[0] = isprimesieve[1] = false; n   for (int i = 2; i * i <= 1000000; i++) { n     if (isprimesieve[i]) { n       for (int j = i * i; j <= 1000000; j += i) { n         isprimesieve[j] = false; n       } n     } n   } n } n bool isperfectsq(long long a) { return (sqrt(a) - (int)sqrt(a) == 0); } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t = 0; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     string s; n     cin >> s; n     bool flag = false; n     for (int i = 0; i < n; i++) { n       if (s[i] ==  0 ) { n         flag = true; n         if (i >= n / 2) { n           cout << 1 <<     << i + 1 <<     << 1 <<     << i <<   n ; n           break; n         } else { n           cout << i + 1 <<     << n <<     << i + 2 <<     << n <<   n ; n           break; n         } n       } n     } n     if (!flag) { n       cout << 1 <<     << n - 1 <<     << 2 <<     << n <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-8; n const double pi = acos(-1.0); n const long long INF = 0x3f3f3f3f3f3f3f3f; n const int inf = 0x3f3f3f3f; n const long long mod = 1e9 + 7; n const int N = 1e5 + 10; n struct zz { n   long long x, y; n } a[N]; n bool check(zz z1, zz z2, zz y1, zz y2) { n   if ((z1.y - z2.y) * (y1.x - y2.x) == (z1.x - z2.x) * (y1.y - y2.y)) n     return true; n   else n     return false; n } n long long dis(zz z1, zz z2) { n   return (z1.x - z2.x) * (z1.x - z2.x) + (z1.y - z2.y) * (z1.y - z2.y); n } n bool check(int n) { n   while (n % 2 == 0) { n     n /= 2; n   } n   if (n == 1) n     return true; n   else n     return false; n } n void solve() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i].x >> a[i].y; n   } n   if (n & 1) { n     cout <<  NO  << endl; n     return; n   } n   int flag = 1; n   for (int i = 0; i < n / 2; i++) { n     if (!check(a[i], a[i + 1], a[i + n / 2], a[(i + n / 2 + 1) % n])) { n       flag = 0; n       break; n     } n   } n   if (flag && n == 4) { n     cout <<  YES  << endl; n     return; n   } n   long long r = dis(a[1], a[0]); n   for (int i = 0; i < n / 2; i++) { n     if (dis(a[i], a[(i + 1) % n]) != n         dis(a[i + n / 2], a[(i + n / 2 + 1) % n])) { n       flag = 0; n       break; n     } n   } n   if (flag) n     cout <<  Yes  << endl; n   else n     cout <<  NO  << endl; n } n int main() { n   ios::sync_with_stdio(false); n   int t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int k, r, shovel = 1; n   cin >> k >> r; n   while ((k % 10) * shovel % 10 != r && (k % 10) * shovel % 10) shovel++; n   cout << shovel; n } n


#include <bits/stdc++.h> n const int INF = 1 << 29; n int cmp(const void* a, const void* b); n long long maxv(long long a, long long b); n long long minv(long long a, long long b); n long long gcd(long long u, long long v); n int main() { n   char s[] =  aeiou ; n   long long k, n, m; n   scanf( %lld , &k); n   if (k <= 24) { n     printf( -1 n ); n     return 0; n   } n   for (long long i = 5; i <= k; i++) { n     if (k % i != 0) continue; n     n = i; n     m = k / i; n     if (m < 5) { n       printf( -1 n ); n       return 0; n     } n     break; n   } n   for (long long i = 0; i < (n); i++) { n     for (long long j = 0; j < (m); j++) { n       printf( %c , s[(i + j) % 5]); n     } n   } n } n int cmp(const void* a, const void* b) { n   if (*(long long*)a - *(long long*)b < 0) return -1; n   if (*(long long*)a - *(long long*)b > 0) return 1; n   return 0; n } n long long maxv(long long a, long long b) { n   if (a > b) return a; n   return b; n } n long long minv(long long a, long long b) { n   if (a < b) return a; n   return b; n } n long long gcd(long long u, long long v) { n   if (v == 0) return u; n   return gcd(v, u % v); n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const double eps = 1e-9; n const int Mod = 1e9 + 7; n const int MaxN = 2e5 + 5; n char s[MaxN]; n int a[MaxN]; n int l[MaxN], r[MaxN]; n bool cmp(int x, int y) { return x > y; } n int main() { n   int n, k; n   scanf( %d %d , &n, &k); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   scanf( %s , s + 1); n   int len = 0; n   for (int i = 1; i <= n; i++) { n     if (i == 1) { n       l[++len] = 1; n       continue; n     } n     if (s[i] == s[i - 1]) continue; n     r[len] = i - 1; n     l[++len] = i; n   } n   r[len] = n; n   for (int i = 1; i <= len; i++) { n     sort(a + l[i], a + r[i] + 1, cmp); n   } n   long long ans = 0LL, cnt = 1; n   for (int i = 1; i <= n; i++) { n     if (s[i] == s[i - 1]) n       cnt++; n     else n       cnt = 1; n     if (cnt > k) continue; n     ans += (long long)a[i]; n   } n   printf( %lld n , ans); n   return 0; n } n


#include<bits/stdc++.h> n #define pb push_back n #define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) n #define ll long long n #define pii pair<int,int> n #define pll pair<ll,ll> n #define f first n #define s second n #define int long long n #define sz(x) (ll)(x.size()) n using namespace std; n  n  n const int mod = 1e9+7; n  n int expo_pow(int x,int y){ n  if(y == 0) return 1; n   y=y%(mod-1); n   x%=mod; n   if(y==0) y=mod-1; n   int res=1; n   while(y){ n     if(y&1) res=(res*x)%mod; n     x=(x*x)%mod; n     y>>=1;  n   } n   return res; n } n  n ll add() n { n     return 0; n } n  n template <typename T, typename... Types> n T add(T var1, Types... var2){ n     return (((((ll)(var1)) % mod + (ll)(add(var2...))) % mod) + mod) % mod; n } n  n ll mul(){ n     return 1; n } n  n template <typename T, typename... Types> n T mul(T var1, Types... var2){ n     return (((ll)(var1)) % mod * (ll)(mul(var2...))) % mod; n } n  n void solve(){ n   int n,x; n   cin >> n >> x; n   int mn = 0; n   int sum = 0; n   for (int i = 0; i < n; ++i) { n     int tmp; n     cin >> tmp; n     sum += tmp; n     mn += (tmp + x- 1)/x; n   } n  n   cout << (sum + x-1)/x <<     << mn <<   n ; n } n  n  n signed main(){ n   fast; n   int test = 1; n   cin>>test; n   int i=1; n   while(test--){ n     solve(); n   } n } n  n  n  n


#include <bits/stdc++.h> n using namespace std; n int fastio() { n   ios_base::sync_with_stdio(false); n   cout << fixed << setprecision(10); n   cin.tie(nullptr); n   return 0; n } n int __fastio = fastio(); n void __print(int x) { cerr << x; } n void __print(long x) { cerr << x; } n void __print(long long x) { cerr << x; } n void __print(unsigned x) { cerr << x; } n void __print(unsigned long x) { cerr << x; } n void __print(unsigned long long x) { cerr << x; } n void __print(float x) { cerr << x; } n void __print(double x) { cerr << x; } n void __print(long double x) { cerr << x; } n void __print(char x) { cerr <<      << x <<     ; } n void __print(const char *x) { cerr <<     << x <<    ; } n void __print(const string &x) { cerr <<     << x <<    ; } n void __print(bool x) { cerr << (x ?  true  :  false ); } n template <typename T, typename V> n void __print(const pair<T, V> &x) { n   cerr <<  { ; n   __print(x.first); n   cerr <<  , ; n   __print(x.second); n   cerr <<  } ; n } n template <typename T> n void __print(const T &x) { n   int f = 0; n   cerr <<  { ; n   for (auto i : x) cerr << (f++ ?  ,  :   ), __print(i); n   cerr <<  } ; n } n void _print() { cerr <<  ] n ; } n template <typename T, typename... V> n void _print(T t, V... v) { n   __print(t); n   if (sizeof...(v)) cerr <<  ,  ; n   _print(v...); n } n void solve() { n   int n; n   cin >> n; n   map<int, pair<int, int>> line; n   for (int i = 0; i < n; i++) { n     int x, r; n     cin >> x >> r; n     line[x] = {r, i}; n   } n   vector<int> res(n, -1); n   int m; n   cin >> m; n   int x, y; n   auto inCircle = [](int x, int y, int x2, int r) { n     long long dx = x - x2, dy = y, r2 = 1LL * r * r; n     return dx * dx + dy * dy <= r2; n   }; n   for (int j = 1; j <= m; j++) { n     cin >> x >> y; n     auto it = line.lower_bound(x); n     if (it != line.end()) { n       auto [x1, k] = *it; n       auto [r, idx] = k; n       if (res[idx] == -1 && inCircle(x, y, x1, r)) res[idx] = j; n     } n     if (it != line.begin()) { n       --it; n       auto [x1, k] = *it; n       auto [r, idx] = k; n       if (res[idx] == -1 && inCircle(x, y, x1, r)) res[idx] = j; n     } n   } n   int hit = n - count(res.begin(), res.end(), -1); n   cout << hit <<   n ; n   for (int i = 0; i < n; i++) cout << res[i] <<    n [i == n - 1]; n } n int main() { n   int t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> vt; n int n; n inline bool judge(int i) { n   int ans = i; n   while (i) { n     ans += i % 10; n     i /= 10; n   } n   return ans == n; n } n int main(void) { n   std::ios::sync_with_stdio(false); n   cin.tie(0); n   while (cin >> n) { n     vt.clear(); n     for (int i = max(n - 81, 1); i <= n; ++i) n       if (judge(i)) vt.push_back(i); n     cout << vt.size() << endl; n     for (auto it : vt) cout << it << endl; n   } n } n