#include <bits/stdc++.h> n using namespace std; n namespace Fread { n const int MAXN = 1 << 20; n char buffer[MAXN], *S, *T; n inline char getchar() { n   if (S == T) { n     T = (S = buffer) + fread(buffer, 1, MAXN, stdin); n     if (S == T) return EOF; n   } n   return *S++; n } n }  // namespace Fread n inline int read() { n   int f = 1, x = 0; n   char ch = Fread::getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = -1; n     ch = Fread::getchar(); n   } n   while (isdigit(ch)) { n     x = x * 10 + ch -  0 ; n     ch = Fread::getchar(); n   } n   return x * f; n } n inline long long readll() { n   long long f = 1, x = 0; n   char ch = Fread::getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = -1; n     ch = Fread::getchar(); n   } n   while (isdigit(ch)) { n     x = x * 10 + ch -  0 ; n     ch = Fread::getchar(); n   } n   return x * f; n } n const int MAXN = 1e6 + 10, N = 1e6 + 1, INF = 0x3f3f3f3f; n int n, q, a[MAXN]; n struct SegmentTree { n   int val[MAXN << 2], cnt[MAXN << 2], tag[MAXN << 2]; n   void push_down(int p) { n     if (tag[p]) { n       val[p << 1] += tag[p]; n       tag[p << 1] += tag[p]; n       val[p << 1 | 1] += tag[p]; n       tag[p << 1 | 1] += tag[p]; n       tag[p] = 0; n     } n   } n   void push_up(int p) { n     if (val[p << 1] == val[p << 1 | 1]) { n       val[p] = val[p << 1]; n       cnt[p] = cnt[p << 1] + cnt[p << 1 | 1]; n     } else if (val[p << 1] < val[p << 1 | 1]) { n       val[p] = val[p << 1]; n       cnt[p] = cnt[p << 1]; n     } else { n       val[p] = val[p << 1 | 1]; n       cnt[p] = cnt[p << 1 | 1]; n     } n   } n   void modify1(int p, int l, int r, int ql, int qr, int x) { n     if (ql <= l && qr >= r) { n       tag[p] += x; n       val[p] += x; n       return; n     } n     push_down(p); n     int mid = (l + r) >> 1; n     if (ql <= mid) modify1(p << 1, l, mid, ql, qr, x); n     if (qr > mid) modify1(p << 1 | 1, mid + 1, r, ql, qr, x); n     push_up(p); n   } n   void modify2(int p, int l, int r, int pos, int x) { n     if (l == r) { n       cnt[p] += x; n       assert(cnt[p] < 2); n       return; n     } n     push_down(p); n     int mid = (l + r) >> 1; n     if (pos <= mid) n       modify2(p << 1, l, mid, pos, x); n     else n       modify2(p << 1 | 1, mid + 1, r, pos, x); n     push_up(p); n   } n   int query(int p, int l, int r, int ql, int qr) { n     if (ql <= l && qr >= r) return val[p] == 1 ? cnt[p] : 0; n     int mid = (l + r) >> 1, res = 0; n     if (ql <= mid) res = query(p << 1, l, mid, ql, qr); n     if (qr > mid) res += query(p << 1 | 1, mid + 1, r, ql, qr); n     return res; n   } n   SegmentTree() {} n } T; n int main() { n   n = read(); n   q = read(); n   for (int i = 1; i <= n; ++i) a[i] = read(); n   a[0] = N; n   a[n + 1] = 0; n   for (int i = 0; i <= n; ++i) { n     if (a[i] != a[i + 1]) n       T.modify1(1, 0, N, min(a[i], a[i + 1]) + 1, max(a[i], a[i + 1]), 1); n     if (i) T.modify2(1, 0, N, a[i], 1); n   } n   while (q--) { n     int i = read(), x = read(); n     T.modify2(1, 0, N, a[i], -1); n     if (a[i] != a[i - 1]) { n       T.modify1(1, 0, N, min(a[i], a[i - 1]) + 1, max(a[i], a[i - 1]), -1); n     } n     if (a[i] != a[i + 1]) { n       T.modify1(1, 0, N, min(a[i], a[i + 1]) + 1, max(a[i], a[i + 1]), -1); n     } n     a[i] = x; n     if (a[i] != a[i - 1]) { n       T.modify1(1, 0, N, min(a[i], a[i - 1]) + 1, max(a[i], a[i - 1]), 1); n     } n     if (a[i] != a[i + 1]) { n       T.modify1(1, 0, N, min(a[i], a[i + 1]) + 1, max(a[i], a[i + 1]), 1); n     } n     T.modify2(1, 0, N, a[i], 1); n     printf( %d n , T.query(1, 0, N, 1, N - 1)); n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int N = 5e5 + 5; n int su[N], lst[N], n, i, a, lim; n long long ans; n pair<int, int> b[N]; n int xb; n inline int calc(int k) { n   int i, j; n   long long s = 0, ans = -1, x, y, z; n   xb = 0; n   for (i = 0; i * k < N; ++i) { n     s += 1ll * i * (su[min(N - 1, (i + 1) * k - 1)] - (i ? su[i * k - 1] : 0)); n     x = lst[min(N - 1, (i + 1) * k)]; n     if (x && x >= i * k) { n       y = su[x] - su[x - 1] > 1 ? x : lst[x]; n       if (y >= i * k) b[++xb] = make_pair(i, y - i * k); n       b[++xb] = make_pair(i, x - i * k); n     } n   } n   for (i = 1; i <= xb; ++i) { n     z = 2 * s - b[i].second; n     x = z <= 0 ? 0 : (z - 1) / (k + 2) + 1; n     if (x <= b[i].first) ans = max(ans, s - x); n   } n   y = -1; n   if (k == 7) { n     ++k, --k; n   } n   for (i = xb; i; --i) { n     if (y >= 0) { n       z = s - min(1ll * b[i].second, y); n       x = z <= 0 ? 0 : (z - 1) / (k + 2) + 1; n       if (x <= b[i].first) ans = max(ans, s - x * 2); n     } n     y = max(y, 1ll * b[i].second); n   } n   y = -1; n   for (i = xb; i; --i) { n     if (b[i].first < b[xb].first) { n       z = s - 1 - b[i].second; n       x = z <= 0 ? 0 : (z - 1) / (k + 2) + 1; n       if (x <= b[i].first) ans = max(ans, s - x * 2 - 1); n     } n     if (y >= 0) { n       z = s + 1 + k - y; n       x = z <= 0 ? 0 : (z - 1) / (k + 2) + 1; n       if (x <= b[i].first) ans = max(ans, s - x * 2 + 1); n     } n     y = max(y, 1ll * b[i].second); n   } n   return ans == -1 ? lim : (ans < 2 ? 0 : ans); n } n int main() { n   scanf( %d , &n); n   for (i = 0; i < n; ++i) scanf( %d , &a), ++su[a]; n   for (i = 1; i < N; ++i) lst[i] = su[i - 1] ? i - 1 : lst[i - 1]; n   a = lst[N - 1]; n   lim = max(a / 2, su[a] > 1 ? a : lst[a]); n   for (i = 1; i < N; ++i) su[i] += su[i - 1]; n   for (i = 2; i < N; ++i) ans = max(ans, 1ll * i * calc(i)); n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> s[200050 * 4]; n pair<int, int> li[200050]; n int n, m, st, qu[200050][3], fa[200050], sg[200050]; n inline int Read() { n   int x = 0; n   char y; n   bool z = 0; n   do y = getchar(), z |= y ==  - ; n   while (y <  0  || y >  9 ); n   do x = x * 10 + y -  0 , y = getchar(); n   while (y >=  0  && y <=  9 ); n   return z ? -x : x; n } n void Pretreat() { n   int now = 0; n   for (int i = 1; i <= n; i++) n     if (qu[i][0] == 1) n       li[++now].first = qu[i][1], li[now].second = i, n       li[++now].first = qu[i][2], li[now].second = -i; n   sort(li + 1, li + now + 1); n   li[0].first = int(1e9); n   for (int i = 1; i <= now; i++) { n     st += li[i].first != li[i - 1].first; n     if (li[i].second < 0) n       qu[-li[i].second][2] = st; n     else n       qu[li[i].second][1] = st; n   } n   return; n } n int Find(int x) { return fa[x] == x ? x : (fa[x] = Find(fa[x])); } n inline void Update(int x, int y) { n   qu[0][1] = min(qu[0][1], x); n   qu[0][2] = max(qu[0][2], y); n } n void Merge(int x, int y, int z, int o) { n   int i = x + y >> 1, j = z << 1; n   while (!s[z].empty()) { n     int k = Find(s[z].back()); n     s[z].pop_back(); n     if (k == m) continue; n     Update(qu[sg[k]][1], qu[sg[k]][2]); n     fa[k] = m; n   } n   if (x == y) return; n   if (o <= i) n     Merge(x, i, j, o); n   else n     Merge(i + 1, y, j + 1, o); n } n void Modify(int x, int y, int z, int o, int p) { n   int i = x + y >> 1, j = z << 1; n   if (x == o && y == p) { n     s[z].push_back(m); n     return; n   } n   if (p <= i) n     Modify(x, i, j, o, p); n   else if (o > i) n     Modify(i + 1, y, j + 1, o, p); n   else n     Modify(x, i, j, o, i), Modify(i + 1, y, j + 1, i + 1, p); n } n int main() { n   n = Read(); n   for (int i = 1; i <= n; i++) n     qu[i][0] = Read(), qu[i][1] = Read(), qu[i][2] = Read(); n   Pretreat(); n   for (int i = 1; i <= n; i++) n     if (qu[i][0] == 1) { n       m++; n       sg[fa[m] = m] = i; n       qu[0][1] = qu[i][1]; n       qu[0][2] = qu[i][2]; n       Merge(1, st, 1, qu[i][1]); n       Merge(1, st, 1, qu[i][2]); n       qu[i][1] = qu[0][1]; n       qu[i][2] = qu[0][2]; n       if (qu[i][1] < qu[i][2] - 1) Modify(1, st, 1, qu[i][1] + 1, qu[i][2] - 1); n     } else { n       int k = sg[Find(qu[i][1])], l = sg[Find(qu[i][2])]; n       if (k == l || (qu[k][1] > qu[l][1] && qu[k][1] < qu[l][2]) || n           (qu[k][2] > qu[l][1] && qu[k][2] < qu[l][2])) n         puts( YES ); n       else n         puts( NO ); n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int tu(int val) { return (1 << val); } n bool iset(int mask, int id) { n   if ((mask & tu(id)) != 0) return true; n   return false; n } n void doset(int &mask, int id) { mask |= tu(id); } n void dounset(int &mask, int id) { mask = mask & (~tu(id)); } n template <typename T> n string tos(T a) { n   stringstream ss; n   string ret; n   ss << a; n   ss >> ret; n   return ret; n } n const int LM = (1 << 19); n int AR[3 * LM], N; n inline void add(int pos, int val) { n   pos += LM - 1; n   AR[pos] += val; n   while (pos /= 2) AR[pos] = AR[pos + pos] + AR[pos + pos + 1]; n } n inline int get(int l, int r, int L = 1, int R = LM, int v = 1) { n   if (r < L || l > R) return 0; n   if (l <= L && R <= r) return AR[v]; n   const int mid = (L + R) / 2; n   return get(l, r, L, mid, v + v) + get(l, r, mid + 1, R, v + v + 1); n } n int main() { n   int q; n   while (cin >> N >> q) { n     memset(AR, 0, sizeof AR); n     ; n     int opt, oa, ob, l, r, lf, rt, dir; n     l = 1, r = N; n     dir = 1; n     for (int i = 1; i <= N; i++) add(i, 1); n     for (int(qq) = (0); (qq) < (q); (qq)++) { n       scanf( %d , &opt); n       if (opt == 1) { n         scanf( %d , &oa); n         int len = abs(l - r) + 1; n         lf = l + (dir * oa) - dir; n         rt = lf + dir; n         if (2 * oa <= len) { n           for (int(loop) = (0); (loop) < (oa); (loop)++) { n             int v = get(lf, lf); n             add(rt, v); n             lf -= dir; n             rt += dir; n           } n           l += oa * dir; n         } else { n           oa = len - oa; n           for (int(loop) = (0); (loop) < (oa); (loop)++) { n             int v = get(rt, rt); n             add(lf, v); n             lf -= dir; n             rt += dir; n           } n           r -= oa * dir; n           swap(l, r); n           dir *= -1; n         } n       } else { n         scanf( %d %d , &oa, &ob); n         ob--; n         int ra = l + oa * dir, rb = l + ob * dir; n         if (ra > rb) swap(ra, rb); n         printf( %d n , get(ra, rb)); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n, k; n   cin >> n >> k; n   set<pair<int, int>> s; n   map<int, int> m; n   int temp; n   for (int i = 0; i < n; i++) { n     cin >> temp; n     if (s.size() < k && (!m.count(temp))) { n       s.insert({i + 1, temp}); n       m[temp] = i + 1; n     } n     if (!m.count(temp) || (!s.count({m[temp], temp}))) { n       s.insert({i + 1, temp}); n       m[temp] = i + 1; n       s.erase(*s.begin()); n     } n   } n   int ar[k + 10]; n   int c = 0; n   for (auto u : s) { n     ar[c] = u.second; n     c++; n   } n   cout << c <<   n ; n   for (int i = c - 1; i >= 0; i--) { n     cout << ar[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int a, b; n   cin >> a >> b; n   a--; n   string l = to_string(a); n   string r = to_string(b); n   long long int ans1; n   if (l.length() == 1) { n     ans1 = a; n   } else { n     if (l[0] <= l[(l.length() - 1)]) { n       ans1 = (a / 10) + 9; n     } else { n       ans1 = (a / 10) + 8; n     } n   } n   long long int ans2; n   if (r.length() == 1) { n     ans2 = b; n   } else { n     if (r[0] <= r[(r.length() - 1)]) { n       ans2 = (b / 10) + 9; n     } else { n       ans2 = (b / 10) + 8; n     } n   } n   cout << ans2 - ans1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 200001; n const int mod = 998244353; n int n, m; n int sum[maxn << 2]; n int y[maxn], x; n int vis[maxn]; n int fac[maxn << 1], rfac[maxn << 1]; n int mul(int a, int b) { return 1LL * a * b % mod; } n int qpow(int a, int q) { n   int res = 1; n   while (q) { n     if (q & 1) res = mul(res, a); n     q >>= 1; n     a = mul(a, a); n   } n   return res; n } n void init() { n   fac[0] = 1; n   int n = maxn * 2; n   for (int i = 1; i < n; ++i) { n     fac[i] = mul(fac[i - 1], i); n   } n   rfac[n - 1] = qpow(fac[n - 1], mod - 2); n   for (int i = n - 2; i >= 0; --i) { n     rfac[i] = mul(rfac[i + 1], i + 1); n   } n } n void pushup(int rt) { sum[rt] = sum[(rt << 1)] + sum[(rt << 1 | 1)]; } n void build(int rt, int l, int r) { n   if (l == r) { n     sum[rt] = 1; n     return; n   } n   int mid = (l + r) / 2; n   build((rt << 1), l, mid); n   build((rt << 1 | 1), mid + 1, r); n   pushup(rt); n } n int query(int rt, int l, int r, int val) { n   if (l == r) { n     return l; n   } n   int mid = (l + r) >> 1; n   if (val <= sum[(rt << 1)]) return query((rt << 1), l, mid, val); n   return query((rt << 1 | 1), mid + 1, r, val - sum[(rt << 1)]); n } n void update(int rt, int l, int r, int pos, int val) { n   if (l == r) { n     sum[rt] = val; n     return; n   } n   int mid = (l + r) >> 1; n   if (pos <= mid) n     update((rt << 1), l, mid, pos, val); n   else n     update((rt << 1 | 1), mid + 1, r, pos, val); n   pushup(rt); n } n int C(int a, int b) { return mul(mul(fac[a], rfac[b]), rfac[a - b]); } n int main() { n   int t; n   scanf( %d , &t); n   init(); n   int len = maxn - 1; n   build(1, 1, len); n   while (t--) { n     scanf( %d%d , &n, &m); n     for (int i = 0; i < m; ++i) { n       scanf( %d%d , &x, &y[i]); n     } n     memset(vis, 0, sizeof(vis)); n     int c = 0; n     vector<int> ve; n     for (int i = m - 1; i >= 0; --i) { n       int p = query(1, 1, len, y[i]); n       int q = query(1, 1, len, y[i] + 1); n       update(1, 1, len, p, 0); n       if (!vis[q]) { n         vis[q] = 1; n         ++c; n       } n       ve.push_back(p); n     } n     printf( %d n , C(2 * n - c - 1, n)); n     for (auto u : ve) { n       update(1, 1, len, u, 1); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 5; n const int M = 1e9 + 7; n long long a[N]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long d; n   cin >> a[0] >> a[1] >> a[2] >> d; n   sort(a, a + 3); n   cout << max(0ll, a[0] - a[1] + d) + max(0ll, a[1] + d - a[2]); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     long long n, k; n     cin >> n >> k; n     if (k == n) { n       cout <<  Alice n ; n       continue; n     } n     if (k > n || k % 3 != 0) { n       if (n % 3 == 0) { n         cout <<  Bob n ; n       } else { n         cout <<  Alice n ; n       } n       continue; n     } n     long long z = n % (k + 1); n     if (z % 3 == 0 && z != k) { n       cout <<  Bob n ; n     } else { n       cout <<  Alice n ; n     } n   } n   return 0; n } n


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


#include <bits/stdc++.h> n int dr[] = {2, 2, -2, -2, 1, -1, 1, -1}; n int dc[] = {1, -1, 1, -1, 2, 2, -2, -2}; n int dr1[] = {0, 0, 1, 1, 1, -1, -1, -1}; n int dc1[] = {1, -1, 1, 0, -1, 0, 1, -1}; n int dr2[] = {0, 0, 1, -1}; n int dc2[] = {1, -1, 0, 0}; n using namespace std; n vector<int> adj[1000005]; n int a[1000005], b[1000005], dp1[1000005]; n long long get(string t) { n   if (t ==  IN ) return 0; n   if (t ==  AND ) return 1; n   if (t ==  XOR ) return 2; n   if (t ==  OR ) return 3; n   if (t ==  NOT ) return 4; n } n long long get1(long long x, long long y, long long v) { n   if (a[v] == 1) return (x & y); n   if (a[v] == 2) return (x ^ y); n   if (a[v] == 3) return (x | y); n } n long long dfs(long long u) { n   if (a[u] == 0) { n     dp1[u] = b[u]; n     return dp1[u]; n   } n   long long i, j; n   if (adj[u].size() == 1) { n     long long p = adj[u][0]; n     long long r = dfs(p) ^ 1; n     dp1[u] = r; n     return r; n   } else { n     long long p = adj[u][0]; n     long long q = adj[u][1]; n     p = dfs(p); n     q = dfs(q); n     long long r; n     if (a[u] == 1) n       r = p & q; n     else if (a[u] == 2) n       r = p ^ q; n     else if (a[u] == 3) n       r = p | q; n     dp1[u] = r; n     return r; n   } n } n int dp[1000005][2][2]; n long long cal(long long x, long long f, long long f1) { n   if (f1 == 0) return (dp1[x] == f); n   if (a[x] == 0) { n     if (b[x] ^ 1 == f) return 1; n     return 0; n   } n   int &r = dp[x][f][f1]; n   if (r != -1) return r; n   r = 0; n   if (adj[x].size() == 1) { n     long long p = adj[x][0]; n     r = cal(p, f ^ 1, f1); n     return r; n   } else { n     long long i, j; n     long long p = adj[x][0]; n     long long q = adj[x][1]; n     for (i = 0; i < 2; i++) { n       for (j = 0; j < 2; j++) { n         long long p1 = get1(i, j, x); n         if (p1 == f) { n           long long r1 = cal(p, i, f1) & cal(q, j, 1 - f1); n           long long r2 = cal(p, i, 1 - f1) & cal(q, j, f1); n           r |= r1; n           r |= r2; n         } n       } n     } n     return r; n   } n } n int mark[1000005]; n void print(long long x, long long f, long long f1) { n   if (a[x] == 0) { n     mark[x] = 1; n     return; n   } n   if (adj[x].size() == 1) { n     long long p = adj[x][0]; n     print(p, f ^ 1, f1); n     return; n   } n   long long i, j; n   long long p = adj[x][0]; n   long long q = adj[x][1]; n   for (i = 0; i < 2; i++) { n     for (j = 0; j < 2; j++) { n       long long p1 = get1(i, j, x); n       if (p1 == f) { n         long long r1 = cal(p, i, f1) & cal(q, j, 1 - f1); n         if (r1 == 1) { n           print(p, i, f1); n         } n         r1 = cal(p, i, 1 - f1) & cal(q, j, f1); n         if (r1 == 1) { n           print(q, j, f1); n         } n       } n     } n   } n } n int main() { n   int n, i, j, x, y; n   while (cin >> n) { n     for (i = 1; i <= n; i++) { n       string t; n       cin >> t; n       a[i] = get(t); n       if (a[i] == 0 || a[i] == 4) { n         cin >> x; n         if (a[i] == 0) n           b[i] = x; n         else n           adj[i].push_back(x); n       } else { n         cin >> x >> y; n         adj[i].push_back(x); n         adj[i].push_back(y); n       } n     } n     long long ans = dfs(1); n     memset(dp, -1, sizeof(dp)); n     long long p = cal(1, ans ^ 1, 1); n     print(1, ans ^ 1, 1); n     for (i = 1; i <= n; i++) { n       if (a[i] == 0) { n         if (mark[i] == 0) n           cout << ans; n         else n           cout << (ans ^ 1); n       } n     } n     cout << endl; n   } n   return 0; n } n


/* n     @uthor: Amit Kumar n     user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces: dr_virus_ ;AtCoder,Hackerearth,Hakerrank: dr_virus; n */ n #include <bits/stdc++.h> n #include <chrono> n using namespace std; n using namespace std::chrono; n //#include <boost/multiprecision/cpp_int.hpp> n //namespace mp = boost::multiprecision; n //#define ln mp::cpp_int; n #define int      long long n #define double   long double n #define uint     unsigned long long n #define endl   n  n #define all(vec) vec.begin(),vec.end() n int google_itr = 1; n #define google(x) cout<< Case # <<x<< :   n #define pi 3.14159265358979323846264338327950L n  n vector<string> vec_splitter(string s) { n         s +=  , ; n         vector<string> res; n         while(!s.empty()) { n                 res.push_back(s.substr(0, s.find( , ))); n                 s = s.substr(s.find( , ) + 1); n         } n         return res; n } n void debug_out( n vector<string> __attribute__ ((unused)) args, n __attribute__ ((unused)) int idx,  n __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }  n template <typename Head, typename... Tail> n void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { n         if(idx > 0) cerr <<  ,  ; else cerr <<  Line(  << LINE_NUM <<  )  ; n         stringstream ss; ss << H; n         cerr << args[idx] <<   =   << ss.str(); n         debug_out(args, idx + 1, LINE_NUM, T...); n } n  n #define XOX n #ifdef XOX n     #define deb(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__) n #else n     #define deb(...) 42 n #endif n  n  n const int mod = 1e9+7; n const int inf = 1e18; n  n  n void virus(){ n         int n; n         cin >> n; n  n         vector <int> arr(n), seq(n); n         for(auto &i:arr) cin >> i; n         iota(all(seq), 0); n  n         partial_sum(all(arr), arr.begin()); n         partial_sum(all(seq), seq.begin()); n  n         for(auto i=0; i<n; i++) { n             if(arr[i] < seq[i]) { n                 cout <<  NO n ; return; n             } n         } n  n         cout <<  YES n ; n } n  n  n int32_t main(){ n     ios_base::sync_with_stdio(false); n     cin.tie(0); n     cout.tie(0); n      n   /*#ifndef ONLINE_JUDGE n     freopen( input.txt , r ,stdin); n     freopen( output.txt , w ,stdout); n     #endif*/ n  n     int t; n     cin >> t; n     while(t--){ n            auto start = system_clock::now(); n            virus(); n            auto stop = system_clock::now(); n            duration<double> duration = (stop - start); n            //cerr <<   nTime:  << fixed << setprecision(10) << (double)duration.count() << sec << endl; n            //your code goes here n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   vector<int> a(5); n   string s; n   long long q = 0; n   for (int i = 1; i < 5; ++i) { n     cin >> a[i]; n   } n   cin >> s; n   for (int i = 0; i < (int)s.size(); ++i) { n     q += a[s[i] -  0 ]; n   } n   cout << q; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9 + 7; n const int maxn = 2e6 + 5; n int n, m, k; n int last[30], dp[maxn]; n char s[maxn]; n int main() { n   scanf( %d%d%s , &n, &k, s + 1); n   m = strlen(s + 1); n   n += m; n   memset(last, -1, sizeof(last)); n   dp[0] = 1; n   for (int i = (1); i <= (n); ++i) { n     if (i <= m) n       if (~last[s[i] -  a ]) n         dp[i] = (dp[i - 1] * 2 % INF + INF - dp[last[s[i] -  a ] - 1]) % INF; n       else n         dp[i] = dp[i - 1] * 2 % INF; n     else { n       int mn = 0; n       for (int j = (0); j < (k); ++j) n         if (last[mn] > last[j]) mn = j; n       if (~last[mn]) n         dp[i] = (dp[i - 1] * 2 % INF + INF - dp[last[mn] - 1]) % INF; n       else n         dp[i] = dp[i - 1] * 2 % INF; n       s[i] = mn +  a ; n     } n     last[s[i] -  a ] = i; n   } n   printf( %d n , dp[n]); n   return 0; n } n


#include <bits/stdc++.h> n using std::cin; n using std::cout; n using std::deque; n using std::endl; n using std::map; n using std::max; n using std::min; n using std::pair; n using std::queue; n using std::sort; n using std::string; n using std::vector; n int main() { n   char last =  b ; n   char x =  b ; n   while ((x = getchar()) != EOF) { n     if (x >=  a  && x <=  z ) { n       last = x -  a  +  A ; n     } else if (x >=  A  && x <=  Z ) { n       last = x; n     } n   } n   if (last ==  A  || last ==  E  || last ==  I  || last ==  O  || last ==  U  || n       last ==  Y ) { n     cout <<  YES ; n   } else { n     cout <<  NO ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   queue<int> q; n   set<int> vals; n   for (int i = 0; i < n; ++i) { n     int id; n     cin >> id; n     if (!vals.count(id)) { n       if (int(q.size()) >= k) { n         int cur = q.front(); n         q.pop(); n         vals.erase(cur); n       } n       vals.insert(id); n       q.push(id); n     } n   } n   vector<int> res; n   while (!q.empty()) { n     res.push_back(q.front()); n     q.pop(); n   } n   reverse(res.begin(), res.end()); n   cout << res.size() << endl; n   for (auto it : res) cout << it <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, l[605], r[605]; n string str, tmp; n stack<string> S; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) cin >> l[i] >> r[i]; n   for (int i = n - 1; i >= 0; i--) { n     if (l[i] == 1) { n       S.push( () ); n       continue; n     } else { n       int lenth = 1; n       tmp =   ; n       while (!S.empty() && lenth < l[i]) { n         tmp = tmp + S.top(); n         lenth += S.top().length(); n         S.pop(); n       } n       tmp =  (  + tmp +  ) ; n       S.push(tmp); n       if (lenth > r[i] || lenth < l[i]) { n         cout <<  IMPOSSIBLE  << endl; n         return 0; n       } n     } n   } n   while (!S.empty()) { n     cout << S.top(); n     S.pop(); n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n struct node { n   int t, n; n } a[200005]; n int cmp(const void* a, const void* b) { n   node* aa = (node*)a; n   node* bb = (node*)b; n   if (aa->n > bb->n) { n     return 1; n   } else if (aa->n == bb->n) { n     return bb->t - aa->t; n   } else { n     return -1; n   } n } n int main() { n   int n, k; n   while (~scanf( %d%d , &n, &k)) { n     int i; n     for (i = 0; i < n; i++) { n       scanf( %d , &a[i].n); n       a[i].t = 1; n     } n     for (i = 0; i < n; i++) { n       scanf( %d , &a[i + n].n); n       a[i + n].n = k - a[i + n].n; n       a[i + n].t = 2; n     } n     int s1 = 0, s2 = 0; n     qsort(a, 2 * n, sizeof(a[0]), cmp); n     for (i = 0; i < 2 * n; i++) { n       if (a[i].t == 2) { n         s2++; n       } else { n         if (s2) { n           s2--; n           s1++; n         } n       } n     } n     printf( 1 %d n , s1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct tree { n   int l, r, c, p; n }; n int n, K, m, r; n long long res, a[10000011], b[10000011]; n bool cmp1(tree a, tree b) { return a.l < b.l; } n bool cmp2(tree a, tree b) { return a.r < b.r; } n void update(int x, int l, int r, int c, int p) { n   if (l == r) { n     a[x] += c, b[x] += 1ll * l * c; n     return; n   } n   int mid = (l + r) >> 1; n   if (p <= mid) n     update(x << 1, l, mid, c, p); n   else n     update(x << 1 | 1, mid + 1, r, c, p); n   a[x] = a[x << 1] + a[x << 1 | 1], b[x] = b[x << 1] + b[x << 1 | 1]; n   return; n } n long long query(int x, int l, int r, int p) { n   if (l == r) { n     if (p <= a[x]) return 1ll * l * p; n     return b[x]; n   } n   int mid = (l + r) >> 1; n   if (a[x << 1] >= p) return query(x << 1, l, mid, p); n   return query(x << 1 | 1, mid + 1, r, p - a[x << 1]) + b[x << 1]; n } n int main() { n   scanf( %d%d%d , &n, &K, &m); n   tree a[m + 1], b[m + 1]; n   for (int i = 1; i <= m; i++) n     scanf( %d%d%d%d , &a[i].l, &a[i].r, &a[i].c, &a[i].p), b[i] = a[i]; n   for (int i = 1; i <= m; i++) r = max(r, a[i].p); n   sort(a + 1, a + m + 1, cmp1); n   sort(b + 1, b + m + 1, cmp2); n   for (int i = 1, j = 1, k = 1; i <= n; i++) { n     while (j <= m && a[j].l == i) update(1, 1, r, a[j].c, a[j].p), j++; n     res += query(1, 1, r, K); n     while (k <= m && b[k].r == i) update(1, 1, r, -b[k].c, b[k].p), k++; n   } n   printf( %lld , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, char* argv[]) { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int k; n   string str; n   cin >> str; n   cin >> k; n   int temp[50]; n   memset(temp, 0, sizeof(temp)); n   int count = 0; n   for (int i = 0; i < str.size(); ++i) { n     if (temp[(int)(str[i] -  a )] == 0) { n       count++; n       temp[str[i] -  a ] = 1; n     } n   } n   if (count >= k) { n     cout <<  0  << endl; n   } else if (k > (int)str.size()) { n     cout <<  impossible  << endl; n   } else { n     cout << k - count << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long inf = 2e18; n long long mod = 1e6; n const long long M = 1e5; n string s; n long long a[M]; n long long bmm(long long a, long long b) { n   if (b == 0) return a; n   return bmm(b, a % b); n } n int main() { n   long long n; n   cin >> n; n   string s =   ; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n     s +=  ? ; n   } n   long long su = 0; n   for (long long i = n - 1; i > -1; i--) { n     if (su > 0) { n       s[i] =  - ; n       su -= a[i]; n     } else { n       s[i] =  + ; n       su += a[i]; n     } n   } n   if (su < 0) n     for (long long i = 0; i < n; i++) n       if (s[i] ==  + ) n         s[i] =  - ; n       else n         s[i] =  + ; n   cout << s; n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, const char *argv[]) { n   int n, m; n   scanf( %d %d , &n, &m); n   int a[n], b[n]; n   map<int, int> mp_a; n   map<int, int> mp_b; n   for (int i = 0; i < n; i++) scanf( %d , &a[i]); n   for (int i = 0; i < n; i++) { n     scanf( %d , &b[i]); n     mp_b[b[i]]++; n   } n   sort(a, a + n); n   int k = a[0]; n   long long ans = 2000000000000000 + 5; n   for (int i = 0; i < n; i++) { n     int x; n     if (b[i] == k) n       x = 0; n     else if (b[i] > k) n       x = b[i] - k; n     else n       x = m - k + b[i]; n     for (int j = 0; j < n; j++) { n       mp_a[(a[j] + x) % m]++; n     } n     bool f = true; n     for (auto &it : mp_a) { n       if (mp_b.find(it.first) != mp_b.end() && mp_b[it.first] == it.second) n         continue; n       else n         f = false; n     } n     if (f) ans = min(ans, (long long)x); n     mp_a.clear(); n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<int, int> > vc, va, vb; n int a[3], b[3], c[3]; n long long n, m, s, p[50], pp[1 << 20]; n void fac(int k, vector<pair<int, int> > &v) { n   int m = sqrt(k); n   for (int i = 2; i <= m; i++) n     if (k % i == 0) { n       int cnt = 0; n       while (k % i == 0) k /= i, cnt++; n       v.push_back(pair<int, int>(i, cnt)); n     } n   if (k > 1) v.push_back(pair<int, int>(k, 1)); n   return; n } n void func(vector<pair<int, int> > &v) { n   sort(v.begin(), v.end()); n   vector<pair<int, int> > w; n   for (auto first : v) { n     if (!w.empty() && w.back().first == first.first) n       w.back().second += first.second; n     else n       w.push_back(first); n   } n   v = w; n   return; n } n long long ans; n void calc(int first, long long up) { n   if (first == vc.size()) { n     ans++; n     return; n   } n   if (up < vc[first].first) { n     ans++; n     return; n   } n   int al = vc[first].second; n   for (int i = 0; i <= al; i++) { n     calc(first + 1, up); n     up /= vc[first].first; n     if (up == 0) break; n   } n   return; n } n int main() { n   int T; n   for (scanf( %d , &T); T--;) { n     scanf( %d %d %d , &a[0], &a[1], &a[2]); n     scanf( %d %d %d , &b[0], &b[1], &b[2]); n     scanf( %d %d %d , &c[0], &c[1], &c[2]); n     long long m = 1ll * b[0] * b[1] * b[2]; n     va.clear(); n     vb.clear(), vc.clear(); n     ans = 0; n     for (int i = 0; i < 3; i++) fac(a[i], va); n     for (int i = 0; i < 3; i++) fac(c[i], vc); n     func(va), func(vc); n     if (vc[0].first == 2) n       vc[0].second++; n     else n       vc.insert(vc.begin(), pair<int, int>(2, 1)); n     n = 1ll * a[0] * a[1] * a[2]; n     m = 1ll * b[0] * b[1] * b[2]; n     calc(0, n); n     int sz = va.size(); n     for (int i = 0; i < sz; i++) { n       int k = n           lower_bound(vc.begin(), vc.end(), pair<int, int>(va[i].first, 0)) - n           vc.begin(); n       int deg = 0; n       if (k < vc.size() && vc[k].first == va[i].first) deg = vc[k].second; n       if (va[i].second > deg) n         vb.push_back(pair<int, int>(va[i].first, deg + 1)); n     } n     sz = vb.size(); n     for (int i = 0; i < sz; i++) { n       int q = vb[i].first, r = vb[i].second; n       p[i] = 1; n       while (r--) p[i] *= q; n     } n     int up = 1 << sz; n     pp[0] = 1; n     for (int i = 1; i < up; i++) { n       int t = __builtin_ctz(i); n       pp[i] = pp[i - (1 << t)] * p[t]; n     } n     for (int i = 0; i < up; i++) { n       int k = __builtin_popcount(i); n       if (k & 1) n         ans -= m / pp[i]; n       else n         ans += m / pp[i]; n     } n     printf( %I64d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long ans[1000005], anss[1000005][10]; n int make(int n) { n   long long g = 1; n   if (n % 10 != 0) g = g * (n % 10); n   n = n / 10; n   while (n > 0) { n     if (n % 10 != 0) g = g * (n % 10); n     n = n / 10; n   } n   return g; n } n long long bit[1000005][11]; n void update(int idx, int val) { n   while (idx <= 1000000) { n     bit[idx][val]++; n     idx += idx & (-idx); n   } n } n long long query(int idx, int val) { n   long long sum = 0; n   while (idx > 0) { n     sum += bit[idx][val]; n     idx -= idx & (-idx); n   } n   return sum; n } n int main() { n   long long int i; n   ans[1] = 1; n   ans[0] = 0; n   for (i = 2; i <= 9; i++) { n     ans[i] = i; n   } n   int k; n   for (int i = 10; i <= 1000000; i++) { n     k = i; n     while (make(k) >= 10) { n       k = make(k); n     } n     k = make(k); n     ans[i] = k; n   } n   for (i = 1; i <= 1000000; i++) { n     update(i, ans[i]); n   } n   int q; n   cin >> q; n   while (q--) { n     int l, r, k; n     cin >> l >> r >> k; n     cout << query(r, k) - query(l - 1, k) << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c = 0, sum = 0, cn = 0, mx = 0; n   char s[101]; n   scanf( %s , s); n   for (b = 0; b <= strlen(s); b++) { n     cn++; n     if (s[b] ==  A  || s[b] ==  E  || s[b] ==  I  || s[b] ==  O  || n         s[b] ==  U  || s[b] ==  Y ) { n       mx = max(cn, mx); n       cn = 0; n     } n     mx = max(mx, cn); n   } n   printf( %d n , mx); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n long long powmod(long long a, long long b) { n   long long res = 1; n   a %= mod; n   assert(b >= 0); n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n   } n   return res; n } n int n, k, m, x, a, b; n long long t, T; n set<pair<int, pair<long long, int>>> wc; n set<pair<long long, pair<int, int>>> rc; n int main() { n   scanf( %d%d%d , &n, &k, &m); n   for (int i = 1; i < k + 1; i++) n     scanf( %d , &x), wc.insert(make_pair(x, make_pair(0, i))); n   for (int i = 0; i < m; i++) { n     scanf( %lld%d%d , &t, &a, &b); n     T = max(T, t); n     while (!rc.empty() && rc.begin()->first <= T) { n       int id = rc.begin()->second.first; n       int pos = rc.begin()->second.second; n       wc.insert(make_pair(pos, make_pair(rc.begin()->first, id))); n       rc.erase(rc.begin()); n     } n     if (wc.empty()) { n       T = max(T, rc.begin()->first); n       while (!rc.empty() && rc.begin()->first <= T) { n         int id = rc.begin()->second.first; n         int pos = rc.begin()->second.second; n         wc.insert(make_pair(pos, make_pair(rc.begin()->first, id))); n         rc.erase(rc.begin()); n       } n     } n     auto rit = wc.lower_bound(make_pair(a, make_pair(0, 0))); n     pair<int, pair<long long, int>> carl, carr; n     if (rit == wc.end()) n       carr = make_pair((1 << 30), make_pair(0, 0)); n     else n       carr = *rit; n     auto lit = wc.lower_bound(make_pair(a + 1, make_pair(0, 0))); n     if (lit == wc.begin()) { n       carl = make_pair(-(1 << 30), make_pair(0, 0)); n     } else { n       --lit; n       int pos = lit->first; n       lit = wc.lower_bound(make_pair(pos, make_pair(0, 0))); n       carl = *lit; n     } n     if (a - carl.first < carr.first - a || n         (a - carl.first == carr.first - a && carl.second < carr.second)) n       swap(carl, carr); n     printf( %d %lld n , carr.second.second, T + abs(carr.first - a) - t); n     wc.erase(carr); n     rc.insert(make_pair(T + abs(carr.first - a) + abs(a - b), n                         make_pair(carr.second.second, b))); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 100; n const double pi = acos(-1); n inline long long read() { n   long long x = 0, f = 1; n   char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) { n     x = x * 10 + ch - 48; n     ch = getchar(); n   } n   return x * f; n } n long long a[maxn], b[maxn], dp[maxn]; n struct Tree { n   long long l, r, maxval; n } tree[maxn * 4]; n void push_up(long long p) { n   tree[p].maxval = max(tree[p * 2].maxval, tree[p * 2 + 1].maxval); n } n void build(long long p, long long l, long long r) { n   tree[p].maxval = 0; n   tree[p].l = l; n   tree[p].r = r; n   if (l == r) { n     return; n   } n   long long mid = (l + r) >> 1; n   build(p * 2, l, mid); n   build(p * 2 + 1, mid + 1, r); n   push_up(p); n } n void modify(long long p, long long l, long long r, long long d) { n   if (l <= tree[p].l && r >= tree[p].r) { n     tree[p].maxval = d; n     return; n   } n   long long mid = (tree[p].l + tree[p].r) >> 1; n   if (l <= mid) modify(p * 2, l, r, d); n   if (r > mid) modify(p * 2 + 1, l, r, d); n   push_up(p); n } n long long query(long long p, long long l, long long r) { n   if (l <= tree[p].l && r >= tree[p].r) { n     return tree[p].maxval; n   } n   long long mid = (tree[p].l + tree[p].r) >> 1; n   long long ans = 0; n   if (l <= mid) ans = max(ans, query(p * 2, l, r)); n   if (r > mid) ans = max(ans, query(p * 2 + 1, l, r)); n   return ans; n } n int main(void) { n   cin.tie(0); n   std::ios::sync_with_stdio(false); n   long long n; n   cin >> n; n   for (long long i = 1; i <= n; i++) { n     long long r, h; n     cin >> r >> h; n     a[i] = r * r * h; n     b[i] = a[i]; n   } n   sort(b + 1, b + 1 + n); n   build(1, 1, n); n   long long ans = 0; n   for (long long i = 1; i <= n; i++) { n     long long tmp = lower_bound(b + 1, b + 1 + n, a[i]) - b; n     dp[i] = max(dp[i], query(1, 1, tmp - 1) + a[i]); n     modify(1, tmp, tmp, dp[i]); n     ans = max(ans, dp[i]); n   } n   cout << fixed << setprecision(10) << (1.0 * ans * pi) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void printprecise(double l, long long int precision) { n   std::cout << std::fixed; n   std::cout << std::setprecision(precision); n   std::cout << l; n } n long long int ncr(long long int n, long long int k) { n   long long int C[n + 1][k + 1]; n   long long int i, j; n   for (i = 0; i <= n; i++) { n     for (j = 0; j <= min(i, k); j++) { n       if (j == 0 || j == i) n         C[i][j] = 1; n       else n         C[i][j] = C[i - 1][j - 1] + C[i - 1][j]; n     } n   } n   return C[n][k]; n } n long long int power_wm(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 power(long long int x, long long int y) { n   long long int res = 1; n   while (y > 0) { n     if (y & 1) res = (res * x); n     y = y >> 1; n     x = (x * x); n   } n   return res; n } n long long int root(long long int x, vector<long long int> &roots) { n   if (roots[x] != x) roots[x] = root(roots[x], roots); n   return roots[x]; n } n void unoin(long long int p, long long int q, vector<long long int> &roots, n            vector<long long int> &rank) { n   long long int rp = root(p, roots); n   long long int rq = root(q, roots); n   if (rank[rq] < rank[rp]) { n     roots[rq] = rp; n   } else if (rank[rp] > rank[rq]) { n     roots[rp] = rq; n   } else { n     roots[rp] = rq; n     rank[rq]++; n   } n } n long long int dig_sum(long long int n) { n   long long int s = 0; n   while (n) { n     s += n % 10; n     n /= 10; n   } n   return s; n } n long long int gcd(long long int a, long long int b) { n   if (a < b) { n     a = a + b; n     b = a - b; n     a = a - b; n   } n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long int toD(long long int x, long long int y, long long int m) { n   return x * m + y % m; n } n pair<long long int, long long int> twoD(long long int p, long long int m) { n   return (make_pair(p / m, p % m)); n } n vector<long long int> dist; n vector<vector<long long int> > g; n void dfs(long long int p) { n   if (dist[p] != -1) { n     return; n   } n   dist[p] = 0; n   long long int maxd = -1; n   for (long long int i = 0; i < g[p].size(); i++) { n     dfs(g[p][i]); n     maxd = max(maxd, dist[g[p][i]]); n   } n   dist[p] = maxd + 1; n } n vector<long long int> fact; n void calfact() { n   fact[0] = 1; n   for (long long int i = 1; i < 1000001; i++) { n     fact[i] = (fact[i - 1] * i) % 998244353; n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int n; n   cin >> n; n   string s; n   cin >> s; n   s =     + s; n   long long int c = 0; n   vector<long long int> last_a(n + 1), last_b(n + 1); n   for (long long int i = 1; i < n + 1; i++) { n     last_b[i] = last_b[i - 1]; n     last_a[i] = last_a[i - 1]; n     if (s[i - 1] ==  A ) { n       last_a[i] = i - 1; n     } else { n       last_b[i] = i - 1; n     } n     if (s[i] ==  A ) { n       c += last_a[i]; n       if (last_b[i] > 0 and last_b[i] < last_a[i]) { n         c--; n       } n     } else { n       c += last_b[i]; n       if (last_a[i] > 0 and last_a[i] < last_b[i]) { n         c--; n       } n     } n   } n   cout << c; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long a, b, i, j, n, t, m; n   cin >> t; n   while (t--) { n     string s; n     cin >> s; n     n = s.size(); n     vector<long long> ans; n     long long count = 0; n     for (i = 0; i < n; i++) { n       if (s[i] ==  1 ) n         count++; n       else { n         ans.push_back(count); n         count = 0; n       } n     } n     if (count != 0) ans.push_back(count); n     long long sum = 0; n     sort(ans.rbegin(), ans.rend()); n     for (i = 0; i < ans.size(); i++) { n       if (i % 2 == 0) sum += ans[i]; n     } n     cout << sum << endl; n   } n } n


#include <bits/stdc++.h> n int main() { n   long long n, m; n   scanf( %lld %lld , &n, &m); n   long long res = 1, p = 2; n   while (m != 0) { n     if (m % 2 != 0) res = res * p % 1000000007; n     p = p * p % 1000000007; n     m >>= 1; n   } n   res--; n   p = res; n   res = 1; n   while (n != 0) { n     if (n % 2 != 0) res = res * p % 1000000007; n     p = p * p % 1000000007; n     n >>= 1; n   } n   printf( %lld , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, a, lev[16], loy[16], suf; n double ret; n double dp[16][(2 << 8)]; n double calc(int pos, int mask) { n   if (pos == n) { n     int need = suf - __builtin_popcount(mask); n     if (need <= 0) n       return 1.0; n     else { n       int b = 0; n       for (int i = 0; i < (n); ++i) n         if (!((mask & (1LL << i)) != 0LL)) b += lev[i]; n       return double(a) / double(a + b); n     } n   } n   double &ret = dp[pos][mask]; n   if (ret != -1) return ret; n   ret = calc(pos + 1, mask) * double(100.0 - loy[pos]) / 100.0 + n         calc(pos + 1, mask + (1 << pos)) * double(loy[pos]) / 100.0; n   return ret; n } n int llamadas = 0; n double calcprob() { n   fill(&dp[0][0], &dp[16][0], -1.0); n   llamadas++; n   return calc(0, 0); n } n void simu(int pos, int candy) { n   if (pos == n) { n     ret = max(ret, calcprob()); n     return; n   } n   int minus = 0; n   simu(pos + 1, candy); n   for (int i = 0; i < (candy); ++i) { n     if (loy[pos] == 100) break; n     minus++; n     loy[pos] += 10; n     simu(pos + 1, candy - i - 1); n   } n   loy[pos] -= minus * 10; n } n int main() { n   cin >> n >> k >> a; n   for (int i = 0; i < (n); ++i) cin >> lev[i] >> loy[i]; n   suf = n / 2 + 1; n   ret = 0.0; n   simu(0, k); n   printf( %.10f n , ret); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long P = 998244353LL; n const int N_MAX = 1e5 + 15; n int A[N_MAX]; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> A[i]; n   long long ans = 0LL; n   bool rem = 1; n   long long q = 1LL; n   while (rem) { n     long long t = 0LL; n     for (int i = 0; i < n; i++) { n       t += (1LL * (A[i] % 10)); n       A[i] /= 10; n       if (A[i] == 0) rem = 0; n     } n     t *= q; n     t %= P; n     q *= 100LL; n     q %= P; n     ans += t; n     ans %= P; n   } n   ans *= 11LL; n   ans %= P; n   ans *= n; n   ans %= P; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int i, j; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int k, n; n   cin >> k; n   long long int maxi = -1; n   for (i = 0; i < k; i++) { n     cin >> n; n     maxi = max(maxi, n); n   } n   if (maxi > 25) n     cout << maxi - 25; n   else n     cout << 0; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5; n const long long INF = 1e9; n long long b[N]; n long long ans[N]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     for (int i = 1; i <= n; ++i) cin >> b[i]; n     long long sum = 0; n     for (int i = 1; i <= n; ++i) sum += b[i]; n     long long x = (long long)n * (n + 1) / 2; n     if (sum % x != 0) { n       cout <<  NO  <<   n ; n     } else { n       sum /= x; n       bool cek = true; n       for (int i = 1; i <= n; ++i) { n         int p = (i + n - 2) % n + 1; n         if ((sum - b[i] + b[p]) % n != 0) cek = false; n         ans[i] = (sum - b[i] + b[p]) / n; n       } n       for (int i = 1; i <= n; ++i) { n         if (ans[i] <= 0 || ans[i] > INF) cek = false; n       } n       if (cek) { n         cout <<  YES  <<   n ; n         for (int i = 1; i <= n; ++i) { n           cout << ans[i]; n           if (i < n) cout <<    ; n         } n         cout <<   n ; n       } else { n         cout <<  NO  <<   n ; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5000 + 10; n const int MOD = 998244353; n long long f[maxn]; n int lim[maxn]; n long long frac[maxn], ifrac[maxn]; n int arr[maxn], b[maxn]; n int n; n long long fpow(long long a, long long b) { n   long long ret = 1; n   while (b) { n     if (b & 1) ret = (ret * a) % MOD; n     a = (a * a) % MOD; n     b >>= 1; n   } n   return ret; n } n void init() { n   frac[0] = 1; n   for (int i = 1; i < maxn; i++) frac[i] = frac[i - 1] * i % MOD; n   ifrac[maxn - 1] = fpow(frac[maxn - 1], MOD - 2); n   for (int i = maxn - 2; i >= 0; i--) ifrac[i] = ifrac[i + 1] * (i + 1) % MOD; n   return; n } n long long A(int a, int b) { n   if (a < b || b < 0) return 0; n   return frac[a] * ifrac[a - b] % MOD; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   init(); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> arr[i]; n     b[i] = arr[i] * 2; n   } n   sort(arr + 1, arr + 1 + n); n   sort(b + 1, b + 1 + n); n   for (int i = 1; i <= n; i++) { n     int dex = upper_bound(b + 1, b + 1 + n, arr[i]) - b; n     --dex; n     lim[i] = dex; n   } n   f[0] = 1; n   lim[0] = -1; n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j <= lim[i]; j++) n       f[i] = (f[i] + f[j] * A(n - 2 - lim[j], lim[i] - lim[j] - 1) % MOD) % MOD; n   } n   if (lim[n] == n - 1) n     cout << f[n] <<   n ; n   else n     cout << 0 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e18; n priority_queue<pair<int, int> > p; n int n; n const int maxn = 1 << 19; n int vis[maxn]; n long long dp[maxn][19]; n int a[maxn], pos, L, sum; n long long ans; n int main() { n   scanf( %d , &n); n   memset(dp, -1, sizeof(dp)); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     if (a[i] == -1) pos = i; n     if (!pos) a[i] = 0; n   } n   a[pos] = 0; n   int tmp = n; n   for (L = 0; 1 << L <= n; L++) n     ; n   for (int j = 1; j <= L; j++) { n     long long Mi = inf; n     if (j == 1) Mi = 0; n     for (int i = n; i > n - j + 1; i--) n       if (dp[i][j - 1] != -1) Mi = min(Mi, dp[i][j - 1]); n     for (int i = n - j + 1; i >= n - sum; i--) { n       dp[i][j] = Mi + a[i]; n       if (dp[i][j - 1] != -1) Mi = min(Mi, dp[i][j - 1]); n     } n     sum += tmp / 2; n     tmp /= 2; n   } n   long long ans = inf; n   for (int i = 1; i <= n; i++) n     if (dp[i][L] != -1) ans = min(ans, dp[i][L]); n   cout << ans <<   n ; n } n


/// Down with The Sickness n #pragma GCC optimize( O3 ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx ) n #pragma GCC optimization ( unroll-loops ) n  n #include  bits/stdc++.h  n using namespace std; n  n using ll = long long; n using ii = pair<int, int>; n  n #define pb push_back n #define F first n #define S second n #define f(i,a,b)  for(int i = a; i < b; i++) n #define all(a)  a.begin(),a.end() n #define rall(a) a.rbegin(),a.rend() n  n mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); n  n const int N = 2e5 + 5, LG = 19, MOD = 1e9 + 7; n vector<int> getF(string s){ n     vector<int> vt(26); n     for(char c : s) n         vt[c -  a ] += 1; n     return vt; n } n vector<int> getLCPArray(vector<pair<string, int>> v) { n     vector<int> ret; n     for(int i = 1, j; i < v.size(); i++){ n         for(j = 0; j < v[i].first.size() && v[i].first[j] == v[i-1].first[j]; j++); n         ret.pb(j); n     } n     return ret; n } n vector<string> out; n void bt(int ind, vector<int> mine, vector<vector<int>> & res) { n     if(ind == out[0].size()) { n         for(auto x : mine) n             for(auto y : mine) n                 res[x][y] = ind; n         return; n     } n     vector<vector<int>> go(26); n     for(auto x : mine) n         go[out[x][ind]- a ].pb(x); n  n     f(i,0,26)if(go[i].size()){ n         f(j,i+1,26)if(go[j].size()){ n             for(auto x : go[i]) n                 for(auto y : go[j]) n                     res[x][y] = res[y][x] = ind; n         } n         bt(ind + 1, go[i], res); n         go[i].clear(); n     } n } n ll solveBig(vector<string> v){ n     int n = v.size(); n     out = v; n     vector<vector<int>> sorted; n     for(int i = 0; i < v.size(); i++) { n         sorted.push_back(vector<int>()); n         sorted.back().push_back(1); n         int sz = v[i].size(); n         for(int j = sz - 2; j >= 0; --j) { n             if(v[i][j] <= v[i][j+1]){ n                 sorted.back().pb(sorted.back().back() + 1); n             }   else { n                 sorted.back().pb(1); n             } n         } n         reverse(all(sorted.back())); n     } n  n     vector<vector<int>> mx1(n,vector<int>(n)), mx2(n,vector<int>(n)); n     vector<int> all;    f(i,0,n) all.pb(i); n     bt(0,all,mx1); n     for(auto & x : out) n         reverse(x.begin(),x.end()); n     bt(0,all,mx2); n     ll ans = 0; n     for(int i = 0; i < v.size(); i++) n     for(int j = i + 1; j < v.size(); j++){ n         int l = mx1[i][j]; n         int r = mx2[i][j]; n         if(l == v[0].size()){ n             continue; n         } n         ///check that either n         ///l is n         int k = max(sorted[i][l], sorted[j][l]); n         if(l + r + k >= v[i].size()) { n             ans += 1; n         }   else { n             ans += 2; n         } n     } n //    cout << ans << endl; n     return ans; n } n vector<vector<int>> sorted; n int ptr; n int trie[N][26]; n int cntFinished[N]; n int cntWalking[N]; n void init(){ n     for(int i = 0; i <= ptr; i++){ n         cntFinished[i] = cntWalking[i] = 0; n         f(j,0,26)trie[i][j] = 0; n     } n     ptr = 0; n } n void ins(string s){ n     int cur = 0; n     cntWalking[0] += 1; n     for(int i = 0; i < s.size(); i++){ n         if(!trie[cur][s[i]- a ]){ n             trie[cur][s[i]- a ] = ++ptr; n         } n         cur = trie[cur][s[i]- a ]; n         cntWalking[cur] += 1; n     } n     cntFinished[cur] += 1; n } n int query(string s){ n     int cur = 0; n     int ans = cntFinished[cur]; n     for(int i = 0; i < s.size(); i++){ n         if(!trie[cur][s[i]- a ]) n             return ans; n         cur = trie[cur][s[i]- a ]; n         ans += cntFinished[cur]; n     } n     return ans + cntWalking[cur] - cntFinished[cur]; n } n ll bt(int ind, vector<int> mine) { n //    cout << ind <<     << mine.size() << endl; n     if(ind == out[0].size())return 0; n     vector<int> go[26]; n     for(auto x : mine) n         go[out[x][ind]- a ].pb(x); n     ll ret = 0; n     init(); n     int cnt =  0; n     for(int i = 0; i < 26; i++)if(go[i].size()) { n         vector<string> toIns; n         for(auto x : go[i]){ n             string lft = out[x].substr(ind+sorted[x][ind]); n             reverse(all(lft)); n             toIns.pb(lft); n             ret += cnt * 2; n             ret -= query(lft); n         } n         for(auto x : toIns) n             ins(x); n         cnt += toIns.size(); n     } n  n     f(i,0,26)if(go[i].size()){ n         ret += bt(ind+1,go[i]); n         go[i].clear(); n     } n  n     return ret; n } n ll solveSmall(vector<string> v){ n     out = v; n     ///sizes are <= 450 n     int n = v.size(); n     for(int i = 0; i < v.size(); i++) { n         sorted.push_back(vector<int>()); n         sorted.back().push_back(1); n         int sz = v[i].size(); n         for(int j = sz - 2; j >= 0; --j) { n             if(v[i][j] <= v[i][j+1]){ n                 sorted.back().pb(sorted.back().back() + 1); n             }   else { n                 sorted.back().pb(1); n             } n         } n         reverse(all(sorted.back())); n     } n     vector<int> all; n     f(i,0,n)all.pb(i); n     return bt(0,all); n  n } n int n; n ll solve(vector<string> v){ n     if(v.size() < 450||n==5001) n         return solveBig(v); n     return solveSmall(v); n } n int main(){ n #ifdef ONLINE_JUDGE n     ios_base::sync_with_stdio(0); n     cin.tie(0); n #endif // ONLINE_JUDGE n     cin >> n; n     vector<string> vs(n); n     map<vector<int>, vector<string>> mp; n     f(i,0,n)    cin >> vs[i], mp[getF(vs[i])].pb(vs[i]); n  n     ll ans = 0, cur = 0; n     for(auto it : mp){ n         auto v= it.second; n         ans += 1337ll * cur * v.size(); n         cur += v.size(); n  n         ans += solve(v); n     } n  n     cout << ans << endl; n  n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 998244353; n int qmul(int a, int b) { n   a = (a % mod + mod) % mod; n   b = (b % mod + mod) % mod; n   int ans = 0; n   while (b) { n     if (b & 1) ans = (ans + a) % mod; n     a = (a << 1) % mod; n     b >>= 1; n   } n   return ans; n } n int qpow(int a, int p) { n   int ans = 1; n   while (p) { n     if (p & 1) ans = qmul(ans, a); n     a = qmul(a, a); n     p >>= 1; n   } n   return ans; n } n int gcd(int a, int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n int main() { n   int n, a, p = 0, q = 1; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a; n     p = qmul((p + q) % mod, 100); n     q = qmul(q, a); n     int r = gcd(p, q); n     p = p / r; n     q = q / r; n   } n   cout << qmul(p, qpow(q, mod - 2)) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 111; n const long double Eps = 1e-6; n int sgn(long double a, long double b = 0) { n   a -= b; n   return (a > Eps) - (a < -Eps); n } n const long double Pi = 4 * atan(1); n struct Point { n   long double x, y; n   Point operator-(Point p) { return {x - p.x, y - p.y}; } n   Point operator+(Point p) { return {x + p.x, y + p.y}; } n   Point operator/(long double d) { return {x / d, y / d}; } n   bool operator<(Point p) const { n     if (sgn(x, p.x) == 0) return sgn(y, p.y) < 0; n     return sgn(x, p.x) < 0; n   } n   Point rot(long double d) { n     long double rx = x * cos(d) - y * sin(d); n     long double ry = x * sin(d) + y * cos(d); n     return {rx, ry}; n   } n   long double len2() { return x * x + y * y; } n   long double len() { return sqrt(len2()); } n   long double dot(Point p) { return x * p.x + y * p.y; } n   long double cross(Point p) { return x * p.y - y * p.x; } n } p[N]; n long double xmul(Point a, Point b, Point c) { return (b - a).cross(c - a); } n Point inter(Point p1, Point p2, Point q1, Point q2) { n   long double u = xmul(p1, p2, q1); n   long double v = xmul(p2, p1, q2); n   long double rx = (q1.x * v + q2.x * u) / (v + u); n   long double ry = (q1.y * v + q2.y * u) / (v + u); n   return {rx, ry}; n } n class Cmp { n  public: n   bool operator()(long double a, long double b) const { return sgn(a, b) < 0; } n }; n int main() { n   ios ::sync_with_stdio(false); n   int n; n   cin >> n; n   set<Point> st; n   for (int i = 0; i < n; i++) { n     cin >> p[i].x >> p[i].y; n     st.insert(p[i]); n   } n   bool found = false; n   long double ans = 0; n   for (int i = 0; i < n; i++) n     for (int j = i + 1; j < n; j++) n       for (int k = j + 1; k < n; k++) { n         if (sgn((p[j] - p[i]).dot(p[k] - p[i])) > 0 && n             sgn((p[k] - p[j]).dot(p[i] - p[j])) > 0 && n             sgn((p[i] - p[k]).dot(p[j] - p[k])) > 0) { n           Point mij = (p[i] + p[j]) / 2; n           Point dij = (p[i] - p[j]).rot(Pi / 2); n           Point mjk = (p[j] + p[k]) / 2; n           Point djk = (p[j] - p[k]).rot(Pi / 2); n           Point o = inter(mij, mij + dij, mjk, mjk + djk); n           bool flag = true; n           for (int r = 0; r < n; r++) n             if (sgn((p[r] - o).len2(), (p[i] - o).len2()) < 0) flag = false; n           if (flag) { n             found = true; n             ans = max(ans, (p[i] - o).len()); n           } n         } n       } n   for (int i = 0; i < n; i++) n     for (int j = i + 1; j < n; j++) { n       Point mij = (p[i] + p[j]) / 2; n       Point dij = (p[j] - p[i]) / 2; n       Point pk = mij + dij.rot(Pi / 2); n       Point ps = mij - dij.rot(Pi / 2); n       if (st.find(pk) != st.end() && st.find(ps) != st.end()) { n         Point &o = mij; n         bool flag = true; n         for (int s = 0; s < n; s++) n           if (sgn((p[s] - o).len2(), (p[i] - o).len2()) < 0) flag = false; n         if (flag) { n           found = true; n           ans = max(ans, (p[i] - o).len()); n         } n       } n     } n   if (!found) n     cout << -1 <<   n ; n   else n     cout << setprecision(6) << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void mf() { freopen( input.in ,  r , stdin); } n int a[1007]; n int n, k; n map<int, int> mm; n queue<int> q; n bool f(map<int, int>& _mm, int x) { return _mm.find(x) != _mm.end(); } n void solve() { n   int m; n   n = 0; n   cin >> k >> m; n   int x; n   for (int i = 1; i <= m; i++) { n     cin >> x; n     x -= k; n     if (!f(mm, x)) { n       mm[x] = 1; n       n++; n       a[n] = x; n       q.push(x); n     } n   } n   while (!f(mm, 0) && !q.empty()) { n     x = q.front(); n     q.pop(); n     for (int i = 1; i <= n; i++) { n       int nx = x + a[i]; n       if (nx > 1000 || nx < -1000) continue; n       if (!f(mm, nx)) { n         mm[nx] = mm[x] + 1; n         q.push(nx); n       } n     } n   } n   if (f(mm, 0)) { n     cout << mm[0]; n   } else { n     cout << -1; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<pair<int, int>, int> > g[100010]; n long long dist[100010]; n bool mark[100010]; n int req[100010]; n void dijkstra(int n) { n   memset(mark, 0, sizeof(mark)); n   priority_queue<pair<long long, long long>, n                  vector<pair<long long, long long> >, n                  greater<pair<long long, long long> > > n       pq; n   pq.push(make_pair(dist[n], n)); n   while (!pq.empty()) { n     int u = pq.top().second; n     pq.pop(); n     if (mark[u]) continue; n     mark[u] = true; n     for (int i = 0; i < g[u].size(); i++) { n       pair<int, int> v = g[u][i].first; n       int t = g[u][i].second; n       if (dist[v.first] > dist[u] + v.second) { n         dist[v.first] = dist[u] + v.second; n         pq.push(make_pair(dist[v.first], v.first)); n         req[v.first] = t; n       } else if (t == -1 && dist[v.first] == dist[u] + v.second) { n         dist[v.first] = dist[u] + v.second; n         req[v.first] = t; n       } n     } n   } n } n int main(int argc, char const *argv[]) { n   for (int i = 0; i < 100010; i++) dist[i] = 1LL << 60; n   int n, m, k; n   scanf( %d%d%d , &n, &m, &k); n   while (m--) { n     int x, y, z; n     scanf( %d%d%d , &x, &y, &z); n     g[x].push_back({{y, z}, -1}); n     g[y].push_back({{x, z}, -1}); n   } n   dist[1] = 0; n   dijkstra(1); n   int ans = 0; n   for (int i = 0; i < k; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     g[1].push_back({{x, y}, i + 1}); n     g[x].push_back({{1, y}, i + 1}); n   } n   dijkstra(1); n   for (int i = 1; i <= n; i++) { n     if (req[i] > 0) ans++; n   } n   ans = k - ans; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int c1, c2, c3, c4; n int a[1111], b[1111]; n int n, m; n int main() { n   while (cin >> c1 >> c2 >> c3 >> c4) { n     cin >> n >> m; n     for (int i = 0; i < n; i++) cin >> a[i]; n     for (int i = 0; i < m; i++) cin >> b[i]; n     int mi = min(c4, 2 * c3); n     int nm = c3; n     for (int i = 0; i < n; i++) nm += min(c1 * a[i], c2); n     mi = min(mi, nm); n     nm = c3; n     for (int i = 0; i < m; i++) nm += min(c1 * b[i], c2); n     mi = min(mi, nm); n     nm = 0; n     for (int i = 0; i < n; i++) nm += min(c1 * a[i], c2); n     for (int i = 0; i < m; i++) nm += min(c1 * b[i], c2); n     mi = min(mi, nm); n     cout << mi << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int t; n   cin >> t; n   while (t--) { n     long long int n, k1, k2, m1 = INT_MIN, m2 = INT_MIN, tmp; n     cin >> n >> k1 >> k2; n     for (long long int i = 0; i < k1; i++) { n       cin >> tmp; n       m1 = max(m1, tmp); n     } n     for (long long int i = 0; i < k2; i++) { n       cin >> tmp; n       m2 = max(m2, tmp); n     } n     if (m1 > m2) { n       cout <<  YES  << endl; n     } else n       cout <<  NO  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1000000007; n long long power(long long x, int y) { n   long long res = 1; n   x = x % mod; n   if (x == 0) return 0; n   while (y > 0) { n     if (y & 1) res = (res * x) % mod; n     y = y >> 1; n     x = (x * x) % mod; n   } n   return res; n } n int modInverse(long long a) { return power(a, mod - 2); } n long long factmod(long long a) { n   long long val = 1; n   while (a > 0) { n     val = (val * a) % mod; n     a--; n   } n   return val; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, m, ans; n   cin >> n >> m; n   ans = (factmod(n + 2 * m - 1) * modInverse(factmod(2 * m)) % mod * n          modInverse(factmod(n - 1) % mod)) % n         mod; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n void err(istream_iterator<string> it) { cout << endl; } n template <typename T, typename... Args> n void err(istream_iterator<string> it, T a, Args... args) { n   cerr << *it <<   =   << a <<    ; n   err(++it, args...); n } n template <typename T> n inline void read(T& x) { n   x = 0; n   T f = 1; n   char ch = getchar(); n   while (!isdigit(ch)) f = (ch ==  - ) ? -1 : 1, ch = getchar(); n   while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); n   x *= f; n } n template <typename T, typename... Args> n inline void read(T& x, Args&... args) { n   read(x), read(args...); n } n constexpr int MAXN = 1e5 + 5, MOD = 1e9 + 7; n int n, cnt; n array<int, MAXN> a; n array<vector<pair<int, int>>, MAXN> p; n vector<int> id[4]; n int main() { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   ; n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   int high = n + 1; n   for (int i = n; i >= 1; i--) { n     if (a[i] == 0) n       continue; n     else if (a[i] == 1) { n       if (high < 1) return cout << -1 <<   n , 0; n       p[i].emplace_back(i, --high), id[1].push_back(i), cnt++; n     } else if (a[i] == 2) { n       if (id[1].size() == 0) return cout << -1 <<   n , 0; n       int tmp = id[1].back(); n       id[1].pop_back(); n       p[i].emplace_back(i, p[tmp][0].second); n       id[2].push_back(i), cnt++; n     } else { n       if (id[3].size()) { n         int tmp = id[3].back(); n         id[3].pop_back(); n         if (high < 1) return cout << -1 <<   n , 0; n         p[i].emplace_back(i, --high); n         p[i].emplace_back(p[tmp][0].first, high); n       } else if (id[2].size()) { n         int tmp = id[2].back(); n         id[2].pop_back(); n         if (high < 1) return cout << -1 <<   n , 0; n         p[i].emplace_back(i, --high); n         p[i].emplace_back(p[tmp][0].first, high); n       } else if (id[1].size()) { n         int tmp = id[1].back(); n         id[1].pop_back(); n         if (high < 1) return cout << -1 <<   n , 0; n         p[i].emplace_back(i, --high); n         p[i].emplace_back(p[tmp][0].first, high); n       } else n         return cout << -1 <<   n , 0; n       id[3].push_back(i); n       cnt += 2; n     } n   } n   cout << cnt <<   n ; n   for (int i = n; i >= 1; i--) n     for (auto& j : p[i]) cout << j.second <<     << j.first <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n const long long MOD = 1e9 + 7; n using namespace std; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long n; n   cin >> n; n   while (n--) { n     long long ci, sum; n     cin >> ci >> sum; n     long long n = sum / ci; n     long long rem = sum % ci; n     long long ans = rem * (pow(n + 1, 2)); n     ci -= rem; n     ans += ci * (pow(n, 2)); n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct data { n   int id, a; n   data() {} n   data(int id, int a) : id(id), a(a) {} n   bool operator<(const data &r) const { return a < r.a; } n } da[100010]; n int n, h; n int main() { n   scanf( %d%d , &n, &h); n   for (int i = 0; i < n; i++) scanf( %d , &da[i].a), da[i].id = i; n   if (n == 2) { n     printf( 0 n ); n     for (int i = 0; i < n; i++) printf( 1  ); n     puts(  ); n     return 0; n   } n   sort(da, da + n); n   int f1 = da[n - 1].a + da[n - 2].a - da[0].a - da[1].a; n   int f2 = max(da[n - 1].a + da[0].a + h, da[n - 1].a + da[n - 2].a) - n            min(da[0].a + da[1].a + h, da[1].a + da[2].a); n   if (f1 <= f2) { n     printf( %d n , f1); n     for (int i = 0; i < n; i++) printf( 1  ); n     puts(  ); n   } else { n     printf( %d n , f2); n     for (int i = 0; i < n; i++) n       if (da[0].id == i) n         printf( 1  ); n       else n         printf( 2  ); n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1605; n int n, m, tot; n int a[MAXN][MAXN]; n int sz[MAXN * MAXN]; n int ans[MAXN * MAXN]; n int cnt[MAXN * MAXN]; n int fa1[MAXN * MAXN]; n int fa2[MAXN * MAXN]; n double v[MAXN][MAXN]; n double t[MAXN][MAXN]; n int getroot(int *fa, int u) { n   return u == fa[u] ? u : fa[u] = getroot(fa, fa[u]); n } n void run() { n   memcpy(t, v, sizeof(t)); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       if (a[i][j]) { n         double sum = 0, cnt = 0; n         for (int k = i - 4; k <= i + 4; k++) n           for (int l = j - 4; l <= j + 4; l++) n             if (k >= 1 && k <= n && l >= 1 && l <= m && n                 (i - k) * (i - k) + (j - l) * (j - l) <= 25) n               sum += t[k][l], cnt++; n         v[i][j] = sum / cnt; n       } n } n void merge(int *fa, int xa, int ya, int xb, int yb) { n   if (!a[xa][ya] || !a[xb][yb]) return; n   fa[getroot(fa, (xa - 1) * m + ya)] = getroot(fa, (xb - 1) * m + yb); n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       fa1[(i - 1) * m + j] = fa2[(i - 1) * m + j] = (i - 1) * m + j; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) scanf( %d , &a[i][j]); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       if (a[i][j]) { n         v[i][j] = 1; n         if (i > 1) merge(fa1, i, j, i - 1, j); n         if (i < n) merge(fa1, i, j, i + 1, j); n         if (j > 1) merge(fa1, i, j, i, j - 1); n         if (j < m) merge(fa1, i, j, i, j + 1); n       } n   run(); n   run(); n   run(); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       if (a[i][j] && v[i][j] < 0.2) { n         if (i > 1 && v[i - 1][j] < 0.2) merge(fa2, i, j, i - 1, j); n         if (i < n && v[i + 1][j] < 0.2) merge(fa2, i, j, i + 1, j); n         if (j > 1 && v[i][j - 1] < 0.2) merge(fa2, i, j, i, j - 1); n         if (j < m && v[i][j + 1] < 0.2) merge(fa2, i, j, i, j + 1); n       } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       if (a[i][j] && v[i][j] < 0.2) sz[getroot(fa2, (i - 1) * m + j)]++; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       if (a[i][j] && v[i][j] < 0.2 && n           getroot(fa2, (i - 1) * m + j) == (i - 1) * m + j && n           sz[(i - 1) * m + j] >= 5) n         cnt[getroot(fa1, (i - 1) * m + j)]++; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       if (a[i][j] && getroot(fa1, (i - 1) * m + j) == (i - 1) * m + j) n         ans[++tot] = cnt[(i - 1) * m + j]; n   sort(ans + 1, ans + tot + 1); n   printf( %d n , tot); n   for (int i = 1; i <= tot; i++) printf( %d  , ans[i]); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5555; n const long long INF = 1e9 + 19; n int n; n int a[N][3]; n bool can[N][3]; n int sumH[3]; n int cando[3]; n void read() { n   scanf( %d , &n); n   vector<vector<int> > tmp; n   tmp.resize(n); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < 3; j++) { n       int x; n       scanf( %d , &x); n       tmp[i].push_back(x); n     } n   } n   sort(tmp.begin() + 1, tmp.end(), [](vector<int> a, vector<int> b) { n     int fa = 0, fb = 0; n     for (auto x : a) fa += x < 0; n     for (auto x : b) fb += x < 0; n     return fa > fb; n   }); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < 3; j++) { n       if (tmp[i][j] < 0) can[i][j] = 1; n       a[i][j] = abs(tmp[i][j]); n     } n } n int sum[3]; n int f[10]; n int cost[10]; n int tmp[3]; n int hack[N]; n int calcScore(int id, int mask, int g1, int g2, int g3) { n   tmp[0] = g1; n   tmp[1] = g2; n   tmp[2] = g3; n   int sum = 0; n   for (int i = 0; i < 3; i++) { n     if (a[id][i] != 0 && (((mask >> i) & 1) == 0)) n       sum += (cost[tmp[i]] / 250) * (250 - a[id][i]); n   } n   return sum; n } n void upd(int& a, int b) { a = min(a, b); } n int preCost[N][3]; n void solve() { n   cost[1] = 500; n   cost[2] = 1000; n   cost[3] = 1500; n   cost[4] = 2000; n   cost[5] = 2500; n   cost[6] = 3000; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < 3; j++) { n       hack[i] |= (can[i][j] << j); n       if (a[i][j] > 0) { n         preCost[i][j] = 2 * (250 - a[i][j]); n       } n     } n   for (int i = 0; i < n; i++) n     for (int j = 0; j < 3; j++) { n       sum[j] += a[i][j] != 0; n       sumH[j] += can[i][j]; n     } n   int total = 0; n   for (int j = 0; j < 3; j++) total += sumH[j]; n   if (total > 90) { n     puts( 1 ); n     return; n   } n   f[0] = n + 1; n   f[1] = n / 2 + 1; n   f[2] = n / 4 + 1; n   f[3] = n / 8 + 1; n   f[4] = n / 16 + 1; n   f[5] = n / 32 + 1; n   f[6] = 0; n   int mainCur = 1; n   for (; mainCur < n && hack[mainCur] > 0; mainCur++) n     ; n   int answer = n; n   for (int g1 = 1; g1 <= 6; g1++) n     for (int g2 = 1; g2 <= 6; g2++) n       for (int g3 = 1; g3 <= 6; g3++) { n         int g[3]; n         g[0] = g1; n         g[1] = g2; n         g[2] = g3; n         int l[3]; n         int r[3]; n         bool flag1 = 1; n         for (int i = 0; i < 3; i++) { n           r[i] = sum[i] - f[g[i]]; n           l[i] = sum[i] - (f[g[i] - 1] - 1); n           r[i] = min(r[i], sumH[i]); n           l[i] = max(0, l[i]); n           if (r[i] < l[i]) { n             flag1 = 0; n           } n         } n         if (!flag1) continue; n         int h0 = r[0]; n         int h1 = r[1]; n         int h2 = r[2]; n         if (h0 < 0 || h1 < 0 || h2 < 0) continue; n         vector<vector<vector<vector<int> > > > dp(mainCur + 1); n         for (int i = 0; i <= mainCur; i++) n           dp[i].resize(h0 + 1, n                        vector<vector<int> >(h1 + 1, vector<int>(h2 + 1, INF))); n         dp[1][0][0][0] = 0; n         int myScore = calcScore(0, 0, g1, g2, g3) + (h0 + h1 + h2) * 100; n         assert(h0 + h1 + h2 <= 90); n         for (int i = 1; i < mainCur; i++) { n           for (int x = 0; x <= h0; x++) n             for (int y = 0; y <= h1; y++) n               for (int z = 0; z <= h2; z++) { n                 if (dp[i][x][y][z] >= INF) continue; n                 for (int mask = 0; mask < 8; mask++) { n                   bool flag = 1; n                   for (int j = 0; j < 3; j++) n                     if (((mask >> j) & 1) == 1 && can[i][j] == 0) flag = 0; n                   if (!flag) continue; n                   int res = calcScore(i, mask, g1, g2, g3); n                   int x1 = x; n                   int y1 = y; n                   int z1 = z; n                   if (((mask >> 0) & 1)) x1++; n                   if (((mask >> 1) & 1)) y1++; n                   if (((mask >> 2) & 1)) z1++; n                   if (x1 > h0 || y1 > h1 || z1 > h2) continue; n                   if (res > myScore) { n                     upd(dp[i + 1][x1][y1][z1], dp[i][x][y][z] + 1); n                   } else { n                     upd(dp[i + 1][x1][y1][z1], dp[i][x][y][z]); n                   } n                 } n               } n         } n         int cc = 0; n         for (int i = mainCur; i < n; i++) { n           assert(hack[i] == 0); n           int res = 0; n           for (int j = 0; j < 3; j++) res += preCost[i][j] * g[j]; n           cc += res > myScore; n         } n         for (int x = l[0]; x <= r[0]; x++) n           for (int y = l[1]; y <= r[1]; y++) n             for (int z = l[2]; z <= r[2]; z++) { n               answer = min(answer, dp[mainCur][x][y][z] + cc); n             } n       } n   printf( %d n , answer + 1); n } n void stress() {} n int main() { n   if (1) { n     int k = 1; n     for (int tt = 0; tt < k; tt++) { n       read(); n       solve(); n     } n   } else { n     stress(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x; n   cin >> n; n   x = (n + 1) / 2; n   string s, even, odd; n   cin >> s; n   for (int i = 0; i < n; i++) { n     if (i % 2 == 0) n       odd.push_back(s[i]); n     else n       even.push_back(s[i]); n   } n   if (n <= 2) { n     cout << s << endl; n   } else { n     if (n % 2 == 0) { n       reverse(odd.begin(), odd.end()); n       for (int i = 0; i < x; i++) { n         odd.push_back(even[i]); n       } n       even = odd; n     } else if (n % 2 == 1) { n       reverse(even.begin(), even.end()); n       for (int i = 0; i < x; i++) { n         even.push_back(odd[i]); n       } n     } n     cout << even << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long modl = 1000000007; n int farr[1000000]; n int pre[1000000]; n int cum[1000000]; n unsigned long long poow(int base, int po); n void swaap(int *a, int *b); n long long gcd(long long a, long long b); n void mul_big_int(string s1, string s2); n int cnt_prime(int n); n int main() { n   cin.tie(0); n   cin.sync_with_stdio(0); n   int n, l, r, cntr = 0, sum = 0, num = 0; n   long long x; n   int maxi = INT_MIN, mini = INT_MAX; n   cin >> n >> l >> r >> x; n   int arr[n]; n   for (int i = 0; i < n; i++) cin >> arr[i]; n   for (int i = 0; i < (1 << n); i++) { n     for (int j = 0; j < n; j++) { n       int r; n       r = i & (1 << j); n       if (r) { n         cntr++; n         sum += arr[j]; n         maxi = max(maxi, arr[j]); n         mini = min(mini, arr[j]); n       } n     } n     if (cntr >= 2) { n       if (sum >= l && sum <= r) { n         if (maxi - mini >= x) num++; n       } n     } n     cntr = 0; n     maxi = INT_MIN; n     mini = INT_MAX; n     sum = 0; n   } n   cout << num <<   n ; n   return 0; n } n unsigned long long poow(int base, int po) { n   if (po == 0) return 1; n   if (po == 1) return base; n   unsigned long long ans = poow(base, po / 2); n   ans = (ans * ans); n   if (po & 1) return (ans * base); n   return ans; n } n void swaap(int *a, int *b) { n   int temp; n   temp = *a; n   *a = *b; n   *b = temp; n } n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n void mul_big_int(string s1, string s2) { n   reverse(s1.begin(), s1.end()); n   reverse(s2.begin(), s2.end()); n   int mul[1000]; n   memset(mul, 0, sizeof(mul)); n   long long ln1 = s1.length(), ln2 = s2.length(); n   for (int i = 0; i < ln1; i++) { n     for (int j = 0; j < ln2; j++) { n       mul[i + j] += ((s1[i] -  0 ) * (s2[j] -  0 )); n     } n   } n   for (int i = 0; i < 1000; i++) { n     mul[i + 1] += mul[i] / 10; n     mul[i] %= 10; n   } n   int i = 999; n   while (i > 0 && mul[i] == 0) i--; n   for (; i >= 0; i--) { n     cout << mul[i]; n   } n   cout << endl; n } n int cnt_prime(int n) { n   vector<bool> prime(n + 1, true); n   prime[0] = false; n   prime[1] = false; n   for (long long i = 2; i * i <= n; i++) { n     if (prime[i]) { n       for (int j = i * i; j <= n; j += i) prime[j] = 0; n     } n   } n   int cntr = 0; n   for (int i = 0; i < (int)prime.size(); i++) { n     if (prime[i]) cntr++; n   } n   return cntr; n } n


#include <bits/stdc++.h> n const long long int INF = 1e15; n using namespace std; n const long long int MAX = 1e7 + 5; n const long long int mod = 1e9 + 7; n long long int gcd(long long int a, long long int b) { n   while (b > 0) { n     a = a % b; n     swap(a, b); n   } n   return a; n } n long long int binpow(long long int a, long long int b) { n   long long int res = 1; n   while (b > 0) { n     if (b % 2 == 1) res = res * a % mod; n     a = a * a % mod; n     b /= 2; n   } n   return res % mod; n } n void solve() { n   long long int n; n   cin >> n; n   long long int ans = 3 * n * n - 2 + 3 * (n - 1) * (n - 1); n   cout << ans <<   n ; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int t = 1; n   for (long long int i = 1; i <= t; i++) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 81; n const int M = 2001; n int n, k, m, ans = 1e9; n int cache[N][2][N][N]; n vector<pair<int, int> > g[N]; n int dp(int idx, int dir, int dist, int taken) { n   if (taken == k) return 0; n   int &ans = cache[idx][dir][dist][taken]; n   if (ans != -1) return ans; n   ans = 1e9; n   for (auto &it : g[idx]) { n     if (abs(it.first - idx) <= dist) { n       if ((it.first - idx > 0 && dir > 0) || (idx - it.first > 0 && dir == 0)) { n         ans = min( n             ans, n             it.second + n                 min(dp(it.first, dir, dist - abs(it.first - idx), taken + 1), n                     dp(it.first, dir ^ 1, abs(it.first - idx) - 1, taken + 1))); n       } n     } n   } n   return ans; n } n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   memset(cache, -1, sizeof(cache)); n   cin >> n >> k >> m; n   for (int i = 1; i <= m; i++) { n     int u, v, c; n     cin >> u >> v >> c; n     g[u].push_back({v, c}); n   } n   for (int i = 1; i <= n; i++) n     ans = min(ans, min(dp(i, 1, n - i, 1), dp(i, 0, i - 1, 1))); n   if (ans > 1e8) ans = -1; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n bool next_n(vector<int> &a) { n   int i = n - 1; n   for (; i >= 0 && a[i] == 5; --i) { n     a[i] = 0; n   } n   if (i == -1) { n     return false; n   } n   ++a[i]; n   return true; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int m; n   cin >> n >> m; n   vector<vector<int>> graph(n); n   int from, to; n   for (int i = 0; i < m; ++i) { n     cin >> from >> to; n     --from; n     --to; n     graph[from].push_back(to); n     graph[to].push_back(from); n   } n   vector<int> ns(n); n   int answ = 0; n   do { n     set<pair<int, int>> ps; n     for (int i = 0; i < n; ++i) { n       for (int j : graph[i]) { n         int a = ns[i]; n         int b = ns[j]; n         if (a > b) { n           swap(a, b); n         } n         ps.emplace(a, b); n       } n     } n     answ = max(answ, (int)ps.size()); n   } while (next_n(ns)); n   cout << answ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename Value> n class feque { n  protected: n   vector<Value> data; n  n  public: n   feque() {} n   feque(const feque &f) { data = f.data; } n   feque(feque &&f) { this->data = move(f.data); } n   feque(initializer_list<Value> list) { data = list; } n   feque &operator=(const feque &f) { n     data = f.data; n     return *this; n   } n   feque &operator=(feque &&f) { n     this->data = move(f.data); n     return *this; n   } n   feque &operator=(initializer_list<Value> list) { n     data = list; n     return *this; n   } n   bool empty() const { return data.empty(); } n   size_t size() { return data.size(); } n   Value &front() { return data.back(); } n   const Value &front() const { return data.back(); } n   Value &back() { return data.front(); } n   const Value &back() const { return data.front(); } n   void push(const Value &value) { data.push_back(value); } n   void pop() { data.pop_back(); } n   typename vector<int>::reverse_iterator begin() { return data.rbegin(); } n   typename vector<int>::reverse_iterator end() { return data.rend(); } n   Value &operator[](const int &index) { return data[data.size() - 1 - index]; } n }; n const int MAX_N = 1e6; n const int ROOT = 1; n int n; n array<vector<int>, MAX_N + 1> adjacency_list; n array<feque<int>, MAX_N + 1> depth_array; n array<int, MAX_N + 1> dominant_index; n void make_adjacent(const int &v, const int &u) { n   adjacency_list[v].push_back(u); n   adjacency_list[u].push_back(v); n } n bool has_child(const int &vertex) { n   return (vertex != ROOT and adjacency_list[vertex].size() > 1) or n          (vertex == ROOT and not adjacency_list[ROOT].empty()); n } n void compute_depth_array(const int &vertex, const int &parent = -1) { n   int deepest_child; n   if (has_child(vertex)) { n     deepest_child = -1; n     for (const int &adjacent : adjacency_list[vertex]) { n       if (adjacent != parent) { n         compute_depth_array(adjacent, vertex); n         if (deepest_child == -1 or n             depth_array[deepest_child].size() < depth_array[adjacent].size()) n           deepest_child = adjacent; n       } n     } n     dominant_index[vertex] = n         (depth_array[deepest_child][dominant_index[deepest_child]] > 1 n              ? dominant_index[deepest_child] + 1 n              : 0); n     swap(depth_array[vertex], depth_array[deepest_child]); n     depth_array[vertex].push(1); n     for (const int &adjacent : adjacency_list[vertex]) { n       if (adjacent != parent and adjacent != deepest_child) { n         for (int depth = 1; depth <= depth_array[adjacent].size(); ++depth) { n           depth_array[vertex][depth] += depth_array[adjacent][depth - 1]; n           if (depth_array[vertex][depth] > n                   depth_array[vertex][dominant_index[vertex]] or n               (depth_array[vertex][depth] == n                    depth_array[vertex][dominant_index[vertex]] and n                depth < dominant_index[vertex])) { n             dominant_index[vertex] = depth; n           } n         } n       } n     } n   } else { n     depth_array[vertex] = {1}; n     dominant_index[vertex] = 0; n   } n } n void optimize_IO() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n } n int main() { n   optimize_IO(); n   cin >> n; n   for (int i = 1; i <= n - 1; ++i) { n     int x, y; n     cin >> x >> y; n     make_adjacent(x, y); n   } n   compute_depth_array(ROOT); n   for (int vertex = 1; vertex <= n; ++vertex) n     cout << dominant_index[vertex] <<    ; n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, char const *argv[]) { n   string input; n   cin >> input; n   int i = 0; n   if (input[0] ==  9 ) ++i; n   for (; i < input.length(); ++i) { n     if (input[i] >=  5 ) { n       input[i] =  0  +  9  - input[i]; n     } n   } n   for (int j = 0; j < input.length(); ++j) { n     cout << input[j]; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char arr[21]; n char brr[21]; n int player1[100]; n int player2[100]; n int main() { n   char z; n   cin >> arr; n   cin >> brr; n   memset(player1, 0, sizeof(player1)); n   memset(player2, 0, sizeof(player2)); n   int n, t, d, i, f, m; n   char p, s; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> t >> p >> d >> s; n     if (p ==  a ) { n       if (player1[d] == 0 && s ==  y ) { n         f = t; n         player1[d]++; n       } else if (s =  r  && player1[d] < 2) { n         cout << brr <<     << d <<     << t <<   n ; n         player1[d] = 5; n       } else if (player1[d] == 1 && s ==  y ) { n         if (t < f) t = f; n         cout << brr <<     << d <<     << t <<   n ; n         player1[d] = 5; n       } n     } else { n       if (player2[d] == 0 && s ==  y ) { n         m = t; n         player2[d]++; n       } else if (s =  r  && player2[d] < 2) { n         cout << arr <<     << d <<     << t <<   n ; n         player2[d] = 5; n       } else if (player2[d] == 1 && s ==  y ) { n         if (m > t) t = m; n         cout << arr <<     << d <<     << t <<   n ; n         player2[d] = 5; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T, class S> n ostream& operator<<(ostream& os, const pair<T, S>& v) { n   return os <<  (  << v.first <<  ,   << v.second <<  ) ; n } n template <class T> n ostream& operator<<(ostream& os, const vector<T>& v) { n   os <<  [ ; n   for (int i = int(0); i <= int((static_cast<int>((v).size())) - 1); ++i) { n     if (i) os <<  ,  ; n     os << v[i]; n   } n   return os <<  ] ; n } n template <class T> n bool setmax(T& _a, T _b) { n   if (_a < _b) { n     _a = _b; n     return true; n   } n   return false; n } n template <class T> n bool setmin(T& _a, T _b) { n   if (_b < _a) { n     _a = _b; n     return true; n   } n   return false; n } n template <class T> n T gcd(T _a, T _b) { n   return _b == 0 ? _a : gcd(_b, _a % _b); n } n int main() { n   int n, k; n   cin >> n >> k; n   if (n <= 3 || (n == 4 && k == 2) || (k != 2 && k != 3)) { n     printf( -1 n ); n   } else { n     if (k == 2) { n       printf( %d n , 3 + (n - 4) * 2); n       printf( 1 2 n ); n       printf( 2 3 n ); n       printf( 3 4 n ); n       for (int i = int(5); i <= int(n); ++i) { n         printf( %d 1 n , i); n         printf( %d 4 n , i); n       } n     } else { n       printf( %d n , 1 + (n - 3) * 2); n       printf( 1 2 n ); n       for (int i = int(4); i <= int(n); ++i) { n         printf( %d 2 n , i); n         printf( %d 3 n , i); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100000]; n char t[1000]; n int main() { n   string s, sa; n   stack<int> sta; n   int i, j; n   while (cin >> sa) { n     s += sa; n   } n   int cnt = 0; n   for (i = 0; i < s.length(); i++) { n     if (s[i] !=  < ) continue; n     i++; n     for (j = 0; i < s.length() && s[i] !=  > ; i++, j++) { n       t[j] = s[i]; n     } n     t[j] =   0 ; n     if (strcmp(t,  table ) == 0) { n       sta.push(0); n     } else if (strcmp(t,  /table ) == 0) { n       a[cnt++] = sta.top(); n       sta.pop(); n     } else if (strcmp(t,  /td ) == 0) { n       sta.top()++; n     } n   } n   sort(a, a + cnt); n   for (i = 0; i < cnt - 1; i++) cout << a[i] <<    ; n   cout << a[i] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<double> > M, I; n vector<vector<double> > M2[15]; n int X[203], Y[203]; n int sz = 0; n map<pair<int, int>, int> mp; n map<pair<pair<int, int>, int>, int> conv; n vector<int> vec[40003]; n int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); } n vector<vector<double> > operator*(vector<vector<double> > A, n                                   vector<vector<double> > B) { n   vector<vector<double> > C = n       vector<vector<double> >(A.size(), vector<double>(B[0].size(), 0)); n   for (int i = 1; i < A.size(); i++) n     for (int j = 1; j < B[0].size(); j++) n       for (int k = 1; k < B.size(); k++) C[i][j] += A[i][k] * B[k][j]; n   return C; n } n vector<vector<double> > pwr(vector<vector<double> > A, int b) { n   if (!b) n     return I; n   else if (b == 1) n     return A; n   else if (b == 2) n     return A * A; n   else if (b & 1) n     return pwr(A, b - 1) * A; n   else n     return pwr(pwr(A, b / 2), 2); n } n void print(vector<vector<double> > X) { n   for (int i = 1; i < X.size(); i++) { n     for (int j = 1; j < X[i].size(); j++) printf( %.8lf  , X[i][j]); n     printf(  n ); n   } n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d %d , &X[i], &Y[i]); n   M.assign(n + 1, vector<double>(n + 1, 0)); n   I.assign(n + 1, vector<double>(n + 1, 0)); n   for (int i = 1; i <= n; i++) { n     I[i][i] = 1; n     mp.clear(); n     for (int j = 1; j <= n; j++) { n       if (j == i) continue; n       int x = X[j] - X[i]; n       int y = Y[j] - Y[i]; n       if (x < 0) x = -x, y = -y; n       pair<int, int> m; n       if (x == 0) n         m = {1, 0}; n       else if (y == 0) n         m = {0, 1}; n       else n         m = {y / gcd(x, abs(y)), x / gcd(x, abs(y))}; n       mp[m]++; n     } n     for (int j = 1; j <= n; j++) { n       if (j == i) continue; n       int x = X[j] - X[i]; n       int y = Y[j] - Y[i]; n       if (x < 0) x = -x, y = -y; n       pair<int, int> m; n       if (x == 0) n         m = {1, 0}; n       else if (y == 0) n         m = {0, 1}; n       else n         m = {y / gcd(x, abs(y)), x / gcd(x, abs(y))}; n       M[i][j] = (1.0 / mp.size()) * 1.0 / (1.0 + mp[m]); n     } n     for (auto x : mp) M[i][i] += (1.0 / mp.size()) * 1.0 / (1.0 + x.second); n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       if (i == j) continue; n       int a = X[j] - X[i]; n       int b = Y[j] - Y[i]; n       if (a < 0) a = -a, b = -b; n       int fpb = gcd(a, abs(b)); n       pair<int, int> m; n       if (a == 0) n         m = {1, 0}; n       else if (b == 0) n         m = {0, 1}; n       else n         m = {b / fpb, a / fpb}; n       if (fpb) { n         a /= fpb; n         b /= fpb; n       } n       int c = a * Y[i] - b * X[i]; n       if (conv.find({m, c}) == conv.end()) { n         conv[{m, c}] = ++sz; n         int idx = conv[{m, c}]; n         for (int k = 1; k <= n; k++) n           if (a * Y[k] == b * X[k] + c) vec[idx].push_back(k); n       } n     } n   } n   M2[0] = M; n   for (int i = 1; i < 15; i++) M2[i] = M2[i - 1] * M2[i - 1]; n   int q; n   scanf( %d , &q); n   while (q--) { n     int x, m; n     scanf( %d %d , &x, &m); n     vector<vector<double> > s = n         vector<vector<double> >(n + 1, vector<double>(2, 0)); n     s[x][1] = 1; n     for (int i = 0; i < 15; i++) n       if ((m - 1) & (1 << i)) s = M2[i] * s; n     double mx = 0; n     for (int i = 1; i <= sz; i++) { n       double sum = 0; n       for (auto j : vec[i]) sum += s[j][1]; n       sum *= 1.0 / vec[i].size(); n       mx = max(mx, sum); n     } n     printf( %.9lf n , mx); n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline T sqr(const T& a) { n   return a * a; n } n template <typename T> n inline int sign(const T& a) { n   return a < 0 ? -1 : a > 0; n } n void task(); n int main() { n   ios_base::sync_with_stdio(0); n   task(); n   return 0; n } n int h, q; n long long int l, r; n vector<pair<long long, long long> > bad; n vector<pair<long long, long long> > ok; n void task() { n   cin >> h >> q; n   long long int start = 1; n   for (int i = 1; i < h; ++i) start *= 2; n   l = start; n   r = start * 2 - 1; n   while (q--) { n     long long int i; n     long long int _l, _r, ans; n     cin >> i >> _l >> _r >> ans; n     while (_l < start) _l *= 2; n     while (_r < start) _r *= 2, ++_r; n     if (ans) { n       if (_l > r || _r < l) { n         cout <<  Game cheated! ; n         return; n       } n       l = max(l, _l); n       r = min(r, _r); n       ok.push_back(pair<long long, long long>{_l, _r}); n     } else { n       bad.push_back(pair<long long, long long>{_l, _r}); n     } n   } n   bad.push_back(pair<long long, long long>{-2, -2}); n   bad.push_back(pair<long long, long long>{4 * start, 4 * start}); n   sort((bad.begin()), (bad.end())); n   vector<pair<long long, long long> > v; n   pair<long long, long long> cur = bad[0]; n   for (int i = 1; i < (int)bad.size(); ++i) { n     pair<long long, long long> x = bad[i]; n     if (x.first <= cur.second + 1) { n       cur.second = max(cur.second, x.second); n     } else { n       v.push_back(cur); n       cur = x; n     } n   } n   v.push_back(cur); n   bad = v; n   vector<pair<long long, long long> > well; n   long long int sum = 0; n   for (int i = 1; i < bad.size(); ++i) { n     long long int ll = max(bad[i - 1].second, l - 1); n     long long int rr = min(r + 1, bad[i].first); n     long long int len = rr - ll - 1; n     if (len > 0) { n       well.push_back(pair<long long, long long>{ll + 1, rr - 1}); n       sum += len; n     } n   } n   if (sum == 0) { n     cout <<  Game cheated! ; n   } else if (sum == 1) { n     assert(well.front().first == well.front().second); n     assert(well.size() == 1); n     cout << well.front().first; n   } else { n     cout <<  Data not sufficient! ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n map<int, int> mp[11]; n const int N = 2e5 + 5; n int ws(int u) { return (int)log10(u) + 1; } n int n, k, a[N], mo[11][N]; n long long ans; n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     mo[0][i] = a[i] % k; n     for (int j = 1; j <= 10; j++) { n       mo[j][i] = (int)(((long long)mo[j - 1][i] * 10) % k); n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= 10; j++) { n       if (mo[j][i]) { n         mp[j][mo[j][i]]++; n       } else { n         mp[j][0]++; n       } n     } n   } n   for (int i = 1; i <= n; i++) { n     int w = ws(a[i]); n     if (mo[0][i]) { n       ans += mp[w][k - mo[0][i]]; n     } else { n       ans += mp[w][0]; n     } n     if ((mo[w][i] + mo[0][i]) % k == 0) { n       ans--; n     } n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int gl, bl, br, gr; n   cin >> gl >> gr >> bl >> br; n   if (br <= (gl + 1) * 2 && br >= gl - 1) { n     cout <<  YES ; n     return 0; n   } n   if (bl <= (gr + 1) * 2 && bl >= gr - 1) { n     cout <<  YES ; n     return 0; n   } n   cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[345678], b[456111], c, n, i, l, s = 0, k = 0, m, j, t, x, y; n string p, q, r, rr; n int main() { n   cin >> n >> m; n   for (i = 0; i < m; i++) { n     a[i] = n / m; n   } n   for (i = 1; i <= n % m; i++) a[i]++; n   for (i = 0; i < m; i++) { n     for (j = 0; j < m; j++) { n       if ((i * i + j * j) % m == 0) { n         s += a[i] * a[j]; n       } n     } n   } n   cout << s << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string str; n   int flag = 1; n   cin >> str; n   int len = str.size(); n   str[len] =  1 ; n   str[len + 1] =  1 ; n   for (int i = 0; i < str.size();) { n     string temp =   ; n     if (str[i] ==  1 ) { n       temp = str[i + 1]; n       if (temp ==  4 ) { n         temp += str[i + 2]; n         if (temp ==  44 ) { n           i += 3; n         } else { n           i += 2; n         } n       } else { n         i++; n       } n     } else { n       flag = 0; n       break; n     } n   } n   if (flag) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxm = 1e6 + 5; n double q[maxm]; n int buf[maxm], len[maxm]; n void run_case() { n   int n; n   cin >> n; n   int top = 0; n   for (int i = 1; i <= n; ++i) cin >> buf[i]; n   q[++top] = buf[1], len[1] = 1; n   for (int i = 2; i <= n; ++i) { n     double now = buf[i]; n     int nowlen = 1; n     while (q[top] > now) { n       now = (now * nowlen + q[top] * len[top]) / (nowlen + len[top]); n       nowlen += len[top--]; n     } n     q[++top] = now, len[top] = nowlen; n   } n   for (int i = 1; i <= top; ++i) n     for (int j = 0; j < len[i]; ++j) cout << q[i] <<   n ; n } n int main() { n   ios::sync_with_stdio(false), cin.tie(0); n   cout.setf(ios_base::showpoint); n   cout.precision(10); n   run_case(); n   cout.flush(); n   return 0; n } n