#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n int add(int a, int b) { n   a += b; n   if (a >= MOD) a -= MOD; n   return a; n } n int sub(int a, int b) { n   a -= b; n   if (a < 0) a += MOD; n   return a; n } n char S[1 << 20]; n int B[1 << 20], W[1 << 20], X[1 << 20]; n int func(int a, int b, char c) { n   if (a > b) return 0; n   int *p = (c ==  B  ? B : (c ==  W  ? W : X)); n   return p[b] - p[a - 1]; n } n int noBW[1 << 20][2]; n int onlyW[1 << 20][2]; n int onlyB[1 << 20][2]; n int noW[1 << 20][2]; n int pow2[1 << 20]; n int main() { n   int n, k; n   scanf( %d%d%s , &n, &k, &S[1]); n   if (2 * k > n) { n     puts( 0 ); n     return 0; n   } n   for (int i = 1; i <= n; ++i) { n     B[i] = B[i - 1] + !!(S[i] ==  B ); n     W[i] = W[i - 1] + !!(S[i] ==  W ); n     X[i] = X[i - 1] + !!(S[i] ==  X ); n   } n   if (k == 1) { n     int res = 0; n     if (func(1, n,  B ) == 0) res++; n     if (func(1, n,  W ) == 0) res++; n     for (int i = 1; i + 1 <= n; ++i) n       if (func(1, i,  B ) == 0 && func(i + 1, n,  W ) == 0) res++; n     int tmp = 1; n     for (int i = 1; i <= n; ++i) n       if (S[i] ==  X ) tmp = add(tmp, tmp); n     printf( %d n , sub(tmp, res)); n     return 0; n   } n   noBW[0][0] = noBW[0][1] = 1; n   if (S[1] !=  W ) noBW[1][0] = 1; n   if (S[1] !=  B ) noBW[1][1] = 1; n   for (int i = 2; i <= n; ++i) { n     if (S[i] !=  W ) { n       noBW[i][0] = add(noBW[i][0], add(noBW[i - 1][0], noBW[i - 1][1])); n       if (i >= k && func(i - k + 1, i - 1,  W ) == 0) n         noBW[i][0] = sub(noBW[i][0], noBW[i - k][1]); n     } n     if (S[i] !=  B ) { n       noBW[i][1] = add(noBW[i][1], add(noBW[i - 1][0], noBW[i - 1][1])); n       if (i >= k && func(i - k + 1, i - 1,  B ) == 0) n         noBW[i][1] = sub(noBW[i][1], noBW[i - k][0]); n     } n   } n   for (int i = 1; i <= n; ++i) { n     if (S[i] !=  W ) { n       onlyW[i][0] = add(onlyW[i][0], add(onlyW[i - 1][0], onlyW[i - 1][1])); n       if (i >= k && func(i - k + 1, i - 1,  W ) == 0) n         onlyW[i][0] = sub(onlyW[i][0], onlyW[i - k][1]); n       onlyB[i][0] = add(onlyB[i][0], add(onlyB[i - 1][0], onlyB[i - 1][1])); n       if (i >= k && func(i - k + 1, i - 1,  W ) == 0) n         onlyB[i][0] = add(onlyB[i][0], noBW[i - k][1]); n     } n     if (S[i] !=  B ) { n       onlyB[i][1] = add(onlyB[i][1], add(onlyB[i - 1][0], onlyB[i - 1][1])); n       if (i >= k && func(i - k + 1, i - 1,  B ) == 0) n         onlyB[i][1] = sub(onlyB[i][1], onlyB[i - k][0]); n       onlyW[i][1] = add(onlyW[i][1], add(onlyW[i - 1][0], onlyW[i - 1][1])); n       if (i >= k && func(i - k + 1, i - 1,  B ) == 0) n         onlyW[i][1] = add(onlyW[i][1], noBW[i - k][0]); n     } n   } n   noW[n + 1][0] = 1; n   for (int i = n; i >= 1; --i) { n     if (S[i] !=  W ) { n       noW[i][0] = add(noW[i][0], add(noW[i + 1][0], noW[i + 1][1])); n     } n     if (S[i] !=  B ) { n       noW[i][1] = add(noW[i][1], add(noW[i + 1][0], noW[i + 1][1])); n       if (i + k <= n + 1 && func(i, i + k - 1,  B ) == 0) n         noW[i][1] = sub(noW[i][1], noW[i + k][0]); n     } n   } n   pow2[0] = 1; n   for (int i = 1; i <= n; ++i) pow2[i] = add(pow2[i - 1], pow2[i - 1]); n   int res = 0; n   res = add(res, add(noBW[n][0], noBW[n][1])); n   res = add(res, add(onlyW[n][0], onlyW[n][1])); n   res = add(res, add(onlyB[n][0], onlyB[n][1])); n   for (int i = n - k + 1; i >= 1; --i) n     if (func(i, i + k - 1,  W ) == 0) n       res = add(res, (long long)onlyW[i - 1][1] * n                          add(noW[i + k][0], noW[i + k][1]) % MOD); n   printf( %d n , sub(pow2[func(1, n,  X )], res)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1e9 + 7; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n, m, x; n   cin >> n >> m >> x; n   x--; n   if (n > m) { n     cout << 0 << endl; n     return 0; n   } n   vector<vector<long long>> dp(n + 1, vector<long long>(n + 1, 0)); n   dp[0][0] = 1; n   for (int i = 0; i < m; i++) { n     vector<vector<long long>> ndp(n + 1, vector<long long>(n + 1, 0)); n     for (int j = 0; j <= n; j++) n       for (int k = 0; j + k <= n; k++) { n         if (i != x) (ndp[j][k] += dp[j][k]) %= mod; n         if (j + k + 1 <= n) (ndp[j + 1][k] += dp[j][k]) %= mod; n         if (i != x && j) (ndp[j - 1][k + 1] += dp[j][k]) %= mod; n         if (j + k + 1 <= n) (ndp[j][k + 1] += dp[j][k]) %= mod; n       } n     swap(dp, ndp); n   } n   long long ans = dp[0][n]; n   for (int i = 1; i <= n; i++) (ans *= i) %= mod; n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k; n int s; n struct DSU { n   int p[505]; n   void init() { n     for (int i = 1; i <= n; i++) p[i] = i; n   } n   int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); } n   int count() { n     int count = 0; n     for (int i = 1; i <= n; i++) n       if (p[i] == i) count++; n     return count; n   } n   void link(int a, int b) { p[find(a)] = find(b); } n } L[10050], R[10050]; n DSU hebing(DSU L, DSU R) { n   DSU a = L; n   for (int i = 1; i <= n; i++) a.link(i, R.find(i)); n   return a; n } n int l[10050], r[10050]; n int main() { n   cin >> n >> m; n   L[0].init(); n   for (int i = 1; i <= m; i++) { n     cin >> l[i]; n     cin >> r[i]; n     L[i] = L[i - 1]; n     L[i].link(l[i], r[i]); n   } n   R[m + 1].init(); n   for (int i = m; i >= 1; i--) { n     R[i] = R[i + 1]; n     R[i].link(l[i], r[i]); n   } n   cin >> k; n   while (k--) { n     int x1, y1; n     cin >> x1 >> y1; n     DSU h = hebing(L[x1 - 1], R[y1 + 1]); n     cout << h.count() << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   map<int, int, greater<int>> input; n   map<int, int, greater<int>> output; n   map<int, int, greater<int>> input_reverse; n   map<int, int, greater<int>> output_reverse; n   int N; n   scanf( %d , &N); n   ; n   int i = N; n   int index = 1; n   while (i--) { n     int x; n     scanf( %d , &x); n     input[index] = x; n     input_reverse[x] = index++; n   } n   index = 1; n   while (N--) { n     int x; n     scanf( %d , &x); n     output[index] = x; n     output_reverse[x] = index++; n   } n   map<int, int, greater<int>>::iterator it1; n   int val = 0; n   int count_val = 0; n   it1 = input.begin(); n   while (!input.empty()) { n     int x = (*it1).second; n     if (x != (*(output.begin())).second) { n       val = val + count_val + 1; n       count_val = 0; n     } else { n       count_val++; n     } n     it1++; n     input.erase((*(input_reverse.find(x))).second); n     output.erase((*(output_reverse.find(x))).second); n   } n   printf( %d n , val); n } n


#include <bits/stdc++.h> n namespace FastIO { n bool IOerror = 0; n inline char nc() { n   static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000; n   if (p1 == pend) { n     p1 = buf; n     pend = buf + fread(buf, 1, 100000, stdin); n     if (pend == p1) { n       IOerror = 1; n       return -1; n     } n   } n   return *p1++; n } n inline bool blank(char ch) { n   return ch ==     || ch ==   n  || ch ==   r  || ch ==   t ; n } n template <class T> n inline bool read(T &x) { n   bool sign = 0; n   char ch = nc(); n   x = 0; n   for (; blank(ch); ch = nc()) n     ; n   if (IOerror) return false; n   if (ch ==  - ) sign = 1, ch = nc(); n   for (; ch >=  0  && ch <=  9 ; ch = nc()) x = x * 10 + ch -  0 ; n   if (sign) x = -x; n   return true; n } n template <class T, class... U> n bool read(T &h, U &...t) { n   return read(h) && read(t...); n } n };  // namespace FastIO n using namespace std; n using namespace FastIO; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n const int INF = 0x3f3f3f3f; n const int N = 1e5 + 10; n struct node { n   int l, r, sum; n   bitset<1010> f; n } tree[N * 15]; n int root[N], cnt; n int n, m, q; n bitset<1010> base; n void ins(int &x, int pre, int l, int r, int i, int j, int op) { n   x = ++cnt; n   tree[x] = tree[pre]; n   if (l == r) { n     if (op == 1) tree[x].f.set(j); n     if (op == 2) tree[x].f.reset(j); n     if (op == 3) tree[x].f ^= base; n     tree[x].sum = tree[x].f.count(); n     return; n   } n   int mid = (l + r) / 2; n   if (i <= mid) n     ins(tree[x].l, tree[pre].l, l, mid, i, j, op); n   else n     ins(tree[x].r, tree[pre].r, mid + 1, r, i, j, op); n   tree[x].sum = tree[tree[x].l].sum + tree[tree[x].r].sum; n   return; n } n signed main() { n   read(n, m, q); n   for (int i = 1; i <= m; i++) base.set(i); n   for (int i = 1; i <= q; i++) { n     int op, x, y; n     read(op); n     if (op <= 2) { n       read(x, y); n       ins(root[i], root[i - 1], 1, n, x, y, op); n     } n     if (op == 3) { n       read(x); n       ins(root[i], root[i - 1], 1, n, x, 0, op); n     } n     if (op == 4) { n       read(x); n       root[i] = root[x]; n     } n     printf( %d n , tree[root[i]].sum); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long L[100005]; n long long P[100005][40]; n long long T[100005]; n vector<long long> graph[100005]; n long long mx = 0, hh; n void dfs(long long src, long long par) { n   if (src == -1) n     L[par] = 0; n   else n     L[par] = L[src] + 1; n   if (mx < L[par]) { n     hh = par; n     mx = max(mx, L[par]); n   } n   T[par] = src; n   long long len = graph[par].size(); n   for (long long i = 0; i < (long long)graph[par].size(); i++) { n     long long v = graph[par][i]; n     if (v != src) { n       dfs(par, v); n     } n   } n } n void dfs1(long long src, long long par) { n   if (src == -1) n     L[par] = 0; n   else n     L[par] = L[src] + 1; n   if (mx < L[par]) { n     hh = par; n     mx = max(mx, L[par]); n   } n   long long len = graph[par].size(); n   for (long long i = 0; i < (long long)graph[par].size(); i++) { n     long long v = graph[par][i]; n     if (v != src) { n       dfs1(par, v); n     } n   } n } n int main() { n   long long i, j, n, m, t, a, b, c, d, e, f, x, y; n   scanf( %lld , &t); n   for (long long cz = 0; cz < t; cz++) { n     scanf( %lld%lld%lld%lld%lld , &n, &a, &b, &c, &d); n     for (i = 0; i < n - 1; i++) { n       scanf( %lld%lld , &x, &y); n       graph[x].push_back(y); n       graph[y].push_back(x); n     } n     mx = 0; n     dfs(-1, a); n     long long cc, dd; n     cc = L[b]; n     for (i = 0; i <= n; i++) { n       L[i] = 0; n     } n     mx = 0; n     dfs1(-1, hh); n     if (c * 2 >= min(d, mx) || cc <= c) { n       printf( Alice n ); n     } else n       printf( Bob n ); n     for (i = 0; i <= n; i++) { n       graph[i].clear(); n       L[i] = 0; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n int size(T &a) { n   return (int)a.size(); n } n template <typename T> n T sqr(T a) { n   return a * a; n } n const int INF = int(1e9); n struct pt { n   int cnt; n   long long sumr; n   long long suml; n   long long f; n   int pr; n   int x; n   int lefm; n   int rim; n   pt *L, *R; n }; n const int MAXN = int(1e5); n pt buf[MAXN * 2]; n int sz = 0; n pt *init(int x) { n   buf[sz].cnt = 1; n   buf[sz].L = buf[sz].R = NULL; n   buf[sz].x = x; n   buf[sz].pr = (rand() << 20) + rand(); n   buf[sz].suml = 0; n   buf[sz].sumr = 0; n   buf[sz].f = 0; n   buf[sz].lefm = buf[sz].rim = x; n   return &buf[sz++]; n } n int getcnt(pt *p) { return p == NULL ? 0 : p->cnt; } n int getlefm(pt *p) { return p == NULL ? 2 * INF : p->lefm; } n int getrim(pt *p) { return p == NULL ? -2 * INF : p->rim; } n long long getf(pt *p) { return p == NULL ? 0 : p->f; } n long long getsuml(pt *p) { return p == NULL ? 0 : p->suml; } n long long getsumr(pt *p) { return p == NULL ? 0 : p->sumr; } n void update(pt *&p) { n   if (p == NULL) return; n   p->cnt = getcnt(p->L) + getcnt(p->R) + 1; n   p->lefm = min(getlefm(p->L), p->x); n   p->rim = max(getrim(p->R), p->x); n   int n1 = getcnt(p->L); n   int n2 = getcnt(p->R); n   p->f = getf(p->L) + getf(p->R); n   p->f += getsumr(p->L) + (long long)n1 * (p->x - getrim(p->L)); n   p->f += getsuml(p->R) + (long long)n2 * (getlefm(p->R) - p->x); n   p->f += (long long)n1 * n2 * ((p->x - getrim(p->L)) + (getlefm(p->R) - p->x)); n   p->f += getsumr(p->L) * n2 + getsuml(p->R) * n1; n   p->suml = getsuml(p->L) + (p->x - p->lefm) + getsuml(p->R) + n             (long long)(n2 ? (getlefm(p->R) - p->lefm) : 0) * n2; n   p->sumr = getsumr(p->R) + (p->rim - p->x) + getsumr(p->L) + n             (long long)(n1 ? (p->rim - getrim(p->L)) : 0) * n1; n } n void merge(pt *a, pt *b, pt *&p) { n   if (a == NULL) { n     p = b; n   } else if (b == NULL) { n     p = a; n   } else if (a->pr < b->pr) { n     merge(a, b->L, b->L); n     p = b; n     update(p); n   } else { n     merge(a->R, b, a->R); n     p = a; n     update(p); n   } n } n void split(pt *t, pt *&a, pt *&b, int by) { n   if (t == NULL) { n     a = b = NULL; n   } else { n     if (t->x <= by) { n       split(t->R, t->R, b, by); n       a = t; n       update(a); n     } else { n       split(t->L, a, t->L, by); n       b = t; n       update(b); n     } n   } n } n int curx[MAXN]; n void remove(pt *&t, int x) { n   pt *p, *q; n   pt *a, *b; n   split(t, p, q, x); n   split(p, a, b, x - 1); n   merge(a, q, t); n } n void insert(pt *&t, pt *i) { n   pt *p, *q; n   split(t, p, q, i->x); n   merge(p, i, t); n   merge(t, q, t); n } n long long query(pt *&t, int l, int r) { n   pt *p, *q, *a, *b; n   split(t, p, q, r); n   split(p, a, b, l - 1); n   long long res = getf(b); n   merge(a, b, t); n   merge(t, q, t); n   return res; n } n int main() { n   ios_base::sync_with_stdio(false); n   int n; n   cin >> n; n   for (int i = (0); i < (n); ++i) cin >> curx[i]; n   pt *root = NULL; n   for (int i = (0); i < (n); ++i) { n     insert(root, init(curx[i])); n   } n   int q; n   cin >> q; n   for (int iter = (0); iter < (q); ++iter) { n     int t; n     cin >> t; n     if (t == 1) { n       int p, d; n       cin >> p >> d; n       --p; n       remove(root, curx[p]); n       curx[p] += d; n       insert(root, init(curx[p])); n     } else { n       int l, r; n       cin >> l >> r; n       cout << query(root, l, r) <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int const N = 200001; n int main() { n   long long n, k, d; n   scanf( %lld%lld%lld , &n, &k, &d); n   if (d < k) return puts( NO ), 0; n   long long dv = d / k; n   if (dv + 1 > n || (dv + (d % k == 0 ? 0 : 2)) > n) return puts( NO ), 0; n   vector<long long> an; n   puts( YES ); n   if (d % k == 0) { n     for (int j = 0; j < k; ++j) { n       if (j & 1) n         printf( 1  ); n       else n         printf( %lld  , 1ll + dv); n     } n     return 0; n   } n   long long lst = 1; n   for (int j = 0; j < (d % k); ++j) { n     if (j & 1) n       printf( 1  ), lst = 1ll; n     else n       printf( %lld  , 2ll + dv), lst = 2ll + dv; n   } n   for (int j = 0; j < k - (d % k); ++j) { n     if (j & 1) n       printf( %lld  , lst); n     else n       printf( %lld  , lst - dv >= 1 ? lst - dv : lst + dv); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int s, x; n   cin >> s >> x; n   long long int i, c = 1, f = 0; n   long long int a = (s - x) / 2; n   if ((s - x) % 2 != 0) n     cout << 0; n   else { n     for (i = 0; i < 64; i++) { n       long long int x1 = ((x >> i) & 1); n       long long int a1 = ((a >> i) & 1); n       if (x1 == 0 && a1 == 1) f = 1; n       if (x1 == 1 && a1 == 0) c = c * 2; n       if (x1 == 1 && a1 == 1) { n         f = 1; n         c = 0; n       } n     } n     if (f == 1) n       cout << c; n     else n       cout << (c - 2); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, t, n, m, a[105], ans[105] = {0}; n   cin >> n >> m; n   for (__typeof(0) i = 0; i <= m - 1; i++) cin >> a[i]; n   for (__typeof(0) i = 0; i <= m - 1; i++) { n     int tem = a[i]; n     for (int j = tem; j <= n; j++) { n       if (ans[j] == 0) ans[j] = a[i]; n     } n   } n   for (__typeof(1) i = 1; i <= n; i++) cout << ans[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MX = 100000 + 10; n long long n, arr[MX]; n struct node { n   long long bit_[3]; n   node() { memset(bit_, 0, sizeof(bit_)); } n }; n vector<node> tree; n void add(long long inode, long long ptr, long long num) { n   if (ptr < 0) return; n   long long q = (num >> ptr) & 1; n   if (tree[inode].bit_[q] == 0) { n     tree.push_back(node()); n     tree[inode].bit_[q] = (int)tree.size() - 1; n   } n   add(tree[inode].bit_[q], ptr - 1, num); n } n long long find_fit(long long x) { n   int ptr = 45; n   long long nd = 0; n   long long sol = 0; n   while (ptr >= 0) { n     sol *= 2; n     long long q = !((x >> ptr) & 1); n     if (q == 1) { n       if (tree[nd].bit_[1] != 0) { n         nd = tree[nd].bit_[1]; n         sol++; n       } else n         nd = tree[nd].bit_[0]; n     } else { n       if (tree[nd].bit_[0] != 0) n         nd = tree[nd].bit_[0]; n       else { n         nd = tree[nd].bit_[1]; n         sol++; n       } n     } n     ptr--; n   } n   return sol; n } n int main() { n   tree.push_back(node()); n   cin >> n; n   long long q = 0; n   add(0, 45, 0); n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n     q ^= arr[i]; n     add(0, 45, q); n   } n   q = 0; n   long long ans = 0; n   for (int i = n - 1; i >= 0; i--) { n     q ^= arr[i]; n     long long p = find_fit(q); n     ans = max(ans, p ^ q); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   long long y, z; n   long long x; n   int choice; n }; n node g[2000001]; n int cmp(node head, node a) { n   if (head.y != a.y) return head.y < a.y; n   if (head.z != a.z) return head.z < a.z; n   return head.x > a.x; n } n struct info { n   int choice; n   long long x; n } f[2000001]; n int m, n; n int has = 0; n struct self { n   int x, y, z; n } s[33]; n long long ans; n int choicex, choicey; n int ipow(int i, int k) { n   if (k == 0) return 1; n   return i * ipow(i, k - 1); n } n int bs(long long y, long long z) { n   int l = 1, r = has, mid, ret = 0; n   while (l <= r) { n     mid = (l + r) >> 1; n     if (g[mid].y > y || (g[mid].y == y && g[mid].z >= z)) { n       ret = mid; n       r = mid - 1; n     } else n       l = mid + 1; n   } n   if (g[ret].y == y && g[ret].z == z) n     return ret; n   else n     return 0; n } n void rep(int i, int u) { n   if (i == 1) { n     int t = u % 3; n     if (t == 0) printf( LM n ); n     if (t == 1) printf( LW n ); n     if (t == 2) printf( MW n ); n     return; n   } n   rep(i - 1, u / 3); n   int t = u % 3; n   if (t == 0) printf( LM n ); n   if (t == 1) printf( LW n ); n   if (t == 2) printf( MW n ); n } n void p(int i, int u) { n   while (i <= m) { n     int t = u % 3; n     u /= 3; n     i++; n     if (t == 0) printf( LM n ); n     if (t == 1) printf( LW n ); n     if (t == 2) printf( MW n ); n   } n } n void print(int l, int r) { n   rep(n, l); n   p(n + 1, r); n } n int main() { n   ans = -1e14; n   scanf( %d , &m); n   for (int i = 1; i <= m; i++) scanf( %d%d%d , &s[i].x, &s[i].y, &s[i].z); n   if (m % 2 == 0) n     n = m / 2; n   else n     n = m / 2 + 1; n   for (int i = 0; i < ipow(3, n); i++) { n     int v = i; n     long long x = 0, y = 0, z = 0; n     for (int j = n; j >= 1; j--) { n       int k = v % 3, li = j; n       long long a = x, b = y; n       if (k == 0) { n         x += s[li].x; n         y += s[li].y; n       } n       if (k == 1) { n         x += s[li].x; n         z += s[li].z; n       } n       if (k == 2) { n         y += s[li].y; n         z += s[li].z; n       } n       v /= 3; n     } n     y -= x; n     z -= x; n     has++; n     g[has].x = x; n     g[has].y = y; n     g[has].z = z; n     g[has].choice = i; n   } n   sort(g + 1, g + has + 1, cmp); n   for (int i = 0; i < ipow(3, m - n); i++) { n     int v = i; n     long long x = 0, y = 0, z = 0; n     for (int j = n + 1; j <= m; j++) { n       int k = v % 3, li = j; n       if (k == 0) { n         x += s[li].x; n         y += s[li].y; n       } n       if (k == 1) { n         x += s[li].x; n         z += s[li].z; n       } n       if (k == 2) { n         y += s[li].y; n         z += s[li].z; n       } n       v /= 3; n     } n     y -= x; n     z -= x; n     int pos = bs(-y, -z); n     if (pos != 0) n       if (g[pos].x + x > ans) { n         ans = g[pos].x + x; n         choicex = g[pos].choice; n         choicey = i; n       } n   } n   if (ans != -1e14) n     print(choicex, choicey); n   else n     printf( Impossible n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int test; n   cin >> test; n   while (test--) { n     int n, m; n     cin >> n >> m; n     string S; n     cin >> S; n     vector<int> P(m); n     vector<int> cnt(n); n     for (int i = 0; i < m; i++) { n       cin >> P[i]; n       cnt[0]++; n       cnt[P[i]]--; n     } n     vector<int> res(26); n     for (int i = 0; i < n; i++) res[S[i] -  a ]++; n     res[S[0] -  a ] += cnt[0]; n     for (int i = 1; i < n; i++) { n       cnt[i] += cnt[i - 1]; n       res[S[i] -  a ] += cnt[i]; n     } n     for (int i = 0; i < 26; i++) cout << res[i] <<     << flush; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100005; n struct node { n   long long x, s[8]; n   int id; n } a[N]; n int n, p, t; n long long f[N][(1 << 8) + 5]; n bool cmp(node a, node b) { return a.x > b.x; } n int main() { n   scanf( %d%d%d , &n, &p, &t); n   for (int i = 1; i <= n; i++) { n     scanf( %lld , &a[i].x); n     a[i].id = i; n   } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= p; j++) scanf( %lld , &a[i].s[j]); n   sort(a + 1, a + n + 1, cmp); n   memset(f, -1, sizeof(f)); n   f[0][0] = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j < (1 << p); j++) { n       f[i][j] = f[i - 1][j]; n       int sum = 0; n       for (int k = 0; k < p; k++) n         if (j & (1 << k)) sum++; n       int tmp = i - 1 - sum; n       if (tmp < t && f[i - 1][j] != -1) f[i][j] += a[i].x; n       for (int k = 0; k < p; k++) { n         if (((j & (1 << k))) && f[i - 1][j ^ (1 << k)] != -1) n           f[i][j] = max(f[i][j], f[i - 1][j ^ (1 << k)] + a[i].s[k + 1]); n       } n     } n   } n   printf( %lld , f[n][(1 << p) - 1]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const long long LINF = 0x3f3f3f3f3f3f3f3fLL; n long long N, L, v1, v2, k; n long long d; n pair<double, double> get_it(double mid) { n   double end = mid * v2; n   double pass = mid; n   for (int i = 1; i < d; i++) { n     double add = (end - pass * v1) / (v2 + v1); n     end = (pass + add) * v1 + mid * v2; n     pass += add + mid; n   } n   return {pass, end}; n } n bool check(double mid) { return (get_it(mid).second >= L); } n void test_case() { n   cin >> N >> L >> v1 >> v2 >> k; n   d = (N + k - 1) / k; n   double l = 0, r = INF; n   for (int i = 0; i < 100; i++) { n     double m = l + (r - l) / 2; n     if (check(m)) n       r = m; n     else n       l = m; n   } n   cout << fixed << setprecision(10); n   cout << get_it(l).first <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int tt = 1; n   while (tt--) { n     test_case(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int cd(int a, int b) { return a - a / b; } n int main() { n   int cnt1, cnt2, x, y; n   cin >> cnt1 >> cnt2 >> x >> y; n   long long int l = 1, r = 1000000000009; n   while (l < r) { n     int mid = l + (r - l) / 2; n     if (cnt1 <= cd(mid, x) && cnt2 <= cd(mid, y) && n         cnt1 + cnt2 <= cd(mid, x * y)) n       r = mid; n     else n       l = mid + 1; n   } n   cout << r; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const ll inf = 1e18; n template <typename T> n void printvector(const vector<T>& foo) { n   for (auto el : foo) cout << el <<    ; n   cout << endl; n } n bool calc(vector<int>& permuration, const vector<vector<int>>& sets, n           vector<bool>& used) { n   if (permuration.size() == sets.size() + 1) { n     for (auto el : permuration) cout << el <<    ; n     cout <<   n ; n     return true; n   } n   if (permuration.empty()) { n     for (int i = 0; i < sets.size(); i++) { n       permuration.push_back(sets[i][0]); n       permuration.push_back(sets[i][1]); n       used[i] = true; n       if (calc(permuration, sets, used)) return true; n       swap(permuration[0], permuration[1]); n       if (calc(permuration, sets, used)) return true; n       used[i] = false; n       permuration.pop_back(); n       permuration.pop_back(); n     } n   } n   vector<int> last_elements; n   for (size_t next = 0; next < sets.size(); next++) { n     if (used[next]) continue; n     const auto& row = sets[next]; n     if (row.size() > permuration.size() + 1) break; n     while (last_elements.size() < row.size() - 1) { n       last_elements.push_back( n           permuration[permuration.size() - last_elements.size() - 1]); n     } n     sort(last_elements.begin(), last_elements.end()); n     vector<int> diff; n     set_difference(row.begin(), row.end(), last_elements.begin(), n                    last_elements.end(), back_inserter(diff)); n     if (diff.size() > 1) continue; n     used[next] = true; n     permuration.push_back(diff[0]); n     if (calc(permuration, sets, used)) return true; n     used[next] = false; n     permuration.pop_back(); n     return false; n   } n   return false; n } n int main() { n   int test; n   cin >> test; n   while (test--) { n     int n; n     cin >> n; n     vector<vector<int>> sets(n - 1); n     for (auto& row : sets) { n       int k; n       cin >> k; n       row.resize(k); n       for (auto& el : row) cin >> el; n     } n     sort(sets.begin(), sets.end(), n          [](const vector<int>& a, const vector<int>& b) { n            return a.size() < b.size(); n          }); n     vector<int> permutation; n     vector<bool> used(n, false); n     calc(permutation, sets, used); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 110000; n int len, k, n; n long long a[N]; n long long resolve() { n   int pK = k; n   set<pair<long long, int>> av; n   set<pair<long long, int>> changed; n   long long sumP = 0; n   for (int i = 0; i < len; i++) { n     av.insert({a[i], i}); n     sumP += a[i]; n   } n   while (true) { n     if (!av.size()) break; n     auto lowest = *av.begin(); n     if (lowest.first >= 0) break; n     if (pK == 0) break; n     av.erase(av.begin()); n     changed.insert({-lowest.first, lowest.second}); n     sumP -= lowest.first; n     sumP += (-lowest.first); n     pK--; n   } n   long long best = sumP; n   for (int i = 1; i <= n - len; i++) { n     if (av.count({a[i - 1], i - 1})) { n       av.erase(av.find({a[i - 1], i - 1})); n       sumP -= a[i - 1]; n     } else { n       changed.erase(changed.find({-a[i - 1], i - 1})); n       sumP -= (-a[i - 1]); n       pK++; n     } n     int j = i + len - 1; n     av.insert({a[j], j}); n     sumP += a[j]; n     while (pK > 0) { n       if (av.size()) { n         auto x = *av.begin(); n         if (x.first < 0) { n           av.erase(av.begin()); n           changed.insert({-x.first, x.second}); n           sumP -= x.first; n           sumP += (-x.first); n           pK--; n         } else n           break; n       } else n         break; n     } n     while (pK == 0) { n       if (!av.size() || !changed.size()) break; n       auto x = *av.begin(); n       auto y = *changed.begin(); n       if (x.first > 0) break; n       if (x.first * -1 > y.first) { n         changed.erase(changed.begin()); n         av.erase(av.begin()); n         changed.insert({x.first * -1, x.second}); n         av.insert({y.first * -1, y.second}); n         sumP -= y.first; n         sumP += (-y.first); n         sumP -= x.first; n         sumP += (-x.first); n       } else n         break; n     } n     best = max(best, sumP); n   } n   return best; n } n int main() { n   scanf( %d %d , &n, &len); n   for (int i = 0; i < n; i++) scanf( %lld , a + i); n   scanf( %d , &k); n   long long ans = resolve(); n   for (int i = 0; i < n; i++) a[i] *= -1; n   ans = max(ans, resolve()); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n, k, l, c, d, p, nl, np; n   cin >> n >> k >> l >> c >> d >> p >> nl >> np; n   long long totlime = c * d; n   long long totdrink = k * l; n   totdrink = totdrink / nl; n   long long totsalt = p / np; n   long long mn = min(totlime, totdrink); n   mn = min(mn, totsalt); n   cout << mn / n <<   n ; n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, ans, v[1009], m, c[1009]; n vector<int> e; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> v[i]; n   for (int i = 2; i <= n; i++) { n     if (v[i] == 0 and v[i - 1] == 1 and v[i + 1] == 1) c[++m] = i + 1; n   } n   ans = m; n   for (int i = 1; i < m; i++) { n     if (c[i] + 2 == c[i + 1]) { n       ans--; n       c[i] = -1e9, c[i + 1] - 1e9; n       i++; n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int n, ys, ans; n int main() { n   cin >> n; n   ys = 0; n   ans = 0; n   for (int i = n; i > 0; i /= 8) { n     ys = i % 8; n     if (ys == 1) ans++; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using INT = long long; n using pii = pair<int, int>; n const int mod = 1e9 + 7; n int power(int a, int n, int mod, int ans = 1) { n   for (; n; n >>= 1, a = (INT)a * a % mod) n     if (n & 1) ans = (INT)ans * a % mod; n   return ans; n } n int fac[3000111], rev[3000111]; n int dp[3000111]; n int C(int n, int k) { n   if (k < 0 or k > n) return 0; n   return (INT)fac[n] * rev[k] % mod * rev[n - k] % mod; n } n void pre() { n   for (int i = fac[0] = rev[0] = 1; i < 3000111; i++) { n     fac[i] = (INT)fac[i - 1] * i % mod; n   } n   rev[3000111 - 1] = power(fac[3000111 - 1], mod - 2, mod); n   for (int i = 3000111 - 2; i >= 0; i--) n     rev[i] = (INT)rev[i + 1] * (i + 1) % mod; n } n int main() { n   pre(); n   int n, q; n   cin >> n >> q; n   dp[0] = n; n   for (int i = 1; i <= n; i++) { n     dp[1] = (dp[1] + 3 * i) % mod; n     dp[2] = (C(i * 3, 2) + dp[2]) % mod; n   } n   int r3 = power(3, mod - 2, mod); n   for (int i = 3; i <= 3 * n; i++) { n     dp[i] = (C(3 * n, i - 2) + 3LL * C(3 * n, i - 1) + 3LL * C(3 * n, i) + n              C(3 * n, i + 1) - 3LL * dp[i - 1] - dp[i - 2]) % n             mod; n     dp[i] = (INT)dp[i] * r3 % mod; n     if (dp[i] < 0) dp[i] += mod; n   } n   while (q--) { n     int x; n     scanf( %d , &x); n     printf( %d n , dp[x]); n   } n   return 0; n } n


#include <bits/stdc++.h> n int a[(1 << 22) + 1]; n int n, m; n bool vis[(1 << 22) + 1][2]; n bool yes[(1 << 22) + 1]; n int mask; n void dfs(int now, int p) { n   if (vis[now][p]) return; n   vis[now][p] = true; n   if (p == 0) n     dfs(now, 1); n   else { n     for (int j = 0; j < n; j++) { n       int jj = 1 << j; n       if (!(jj & now)) dfs(now | jj, 1); n     } n     if (yes[now ^ mask]) dfs(now ^ mask, 0); n   } n } n int main() { n   scanf( %d%d , &n, &m); n   int ans = 0; n   for (int i = 0; i < (1 << n); i++) yes[i] = vis[i][0] = vis[i][1] = false; n   for (int i = 0; i < m; i++) { n     scanf( %d , &a[i]); n     yes[a[i]] = true; n   } n   mask = (1 << n) - 1; n   for (int i = 0; i < m; i++) { n     if (!vis[a[i]][0]) { n       ans++; n       dfs(a[i], 0); n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 3030; n int head[MAX_N], current, n, siz[MAX_N][MAX_N], fa[MAX_N][MAX_N]; n long long f[MAX_N][MAX_N]; n struct edge { n   int to, nxt; n } edges[MAX_N << 1]; n void addpath(int src, int dst) { n   edges[current].to = dst, edges[current].nxt = head[src]; n   head[src] = current++; n } n void dfs(int u, int org) { n   siz[org][u] = 1; n   for (int i = head[u]; i != -1; i = edges[i].nxt) n     if (edges[i].to != fa[org][u]) n       fa[org][edges[i].to] = u, dfs(edges[i].to, org), n       siz[org][u] += siz[org][edges[i].to]; n } n long long dp(int u, int v) { n   if (u == v) return 0; n   if (f[u][v]) return f[u][v]; n   return (f[u][v] = max(dp(u, fa[u][v]), dp(v, fa[v][u])) + n                     1LL * siz[u][v] * siz[v][u]); n } n int main() { n   memset(head, -1, sizeof(head)); n   scanf( %d , &n); n   for (int i = 1, u, v; i <= n - 1; i++) n     scanf( %d%d , &u, &v), addpath(u, v), addpath(v, u); n   for (int i = 1; i <= n; i++) dfs(i, i); n   long long ans = 0; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) ans = max(ans, dp(i, j)); n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n template <class T> n inline void read(T &x) { n   x = 0; n   register char c = getchar(); n   register bool f = 0; n   while (!isdigit(c)) f ^= c ==  - , c = getchar(); n   while (isdigit(c)) x = x * 10 + c -  0 , c = getchar(); n   if (f) x = -x; n } n template <class T> n inline void print(T x) { n   if (x < 0) putchar( - ), x = -x; n   if (x > 9) print(x / 10); n   putchar(x % 10 +  0 ); n } n template <class T> n inline void print(T x, char c) { n   print(x), putchar(c); n } n template <class T> n inline T gcd(T n, T m) { n   return m ? gcd(m, n % m) : n; n } n template <const int N> n struct Prime : std::vector<int> { n   Prime() { n     std::vector<bool> vis(N); n     for (int i = 2; i < N; i++) { n       if (!vis[i]) this->push_back(i); n       for (int j : *this) { n         if (i * j >= N) break; n         vis[i * j] = true; n         if (!(i % j)) break; n       } n     } n   } n }; n const int N = 1e5 + 10, M = 1e7 + 10; n int n, k, A, B, C, a[N], deg[N], v[N][8], l[N], f[M]; n Prime<10000> prime; n std::vector<int> pos; n std::unordered_map<int, int> primeid; n void affect(int *v, int l, int x) { n   std::function<void(int, int)> dfs = [&](int i, int s) { n     if (i == l) { n       if (s != 1) f[s] += x; n       return; n     } n     dfs(i + 1, s); n     dfs(i + 1, s * v[i]); n   }; n   dfs(0, 1); n } n int query(int *v, int l) { n   int res = 0; n   std::function<void(int, int)> dfs = [&](int i, int s) { n     if (i == l) { n       res += s < 0 ? -f[-s] : f[s]; n       return; n     } n     dfs(i + 1, s); n     dfs(i + 1, s * -v[i]); n   }; n   dfs(0, -1); n   return res; n } n int main() { n   read(n), read(k); n   for (int i = 1; i <= n; i++) read(a[i]); n   for (int i = 0; i < prime.size(); i++) primeid[prime[i]] = i; n   for (int x, i = 1; i <= n; i++) { n     x = a[i]; n     for (int j = 0; prime[j] * prime[j] <= x; j++) n       if (x % prime[j] == 0) { n         v[i][l[i]++] = prime[j]; n         while (x % prime[j] == 0) x /= prime[j]; n       } n     if (x != 1) v[i][l[i]++] = x; n   } n   for (int i = 1; i <= n; i++) affect(v[i], l[i], 1); n   for (int i = 1; i <= n; i++) deg[i] = query(v[i], l[i]) - 1; n   for (int i = 1; i <= n; i++) affect(v[i], l[i], -1); n   int fulldeg = 0; n   for (int i = 1; i <= n; i++) fulldeg += deg[i] == n - 1; n   if (fulldeg >= k) { n     for (int i = 1; i <= n; i++) n       if (deg[i] == n - 1) pos.push_back(i); n   } else { n     for (int i = 1; i <= n; i++) n       if (n - 1 - deg[i] >= 2) { n         A = i; n         for (int j = 1; j <= n; j++) n           if (j != A && gcd(a[i], a[j]) == 1) { n             if (!B) { n               B = j; n               continue; n             } n             if (!C) { n               C = j; n               continue; n             } n             break; n           } n         break; n       } n     if (A) { n       if (!(B && C)) n         printf( Assert: Passing [%s] in LINE %d n , __FUNCTION__, 120), exit(0); n       auto getp = [&](int cur) { n         std::vector<int> res; n         for (int i = 1; i <= n && res.size() < cur; i++) n           if (i != A && i != B && i != C) { n             res.push_back(i); n           } n         return res; n       }; n       auto solve = [&](int cur) { n         int res = 0; n         std::vector<int> p = getp(cur); n         for (int i : p) affect(v[i], l[i], 1); n         for (int i : p) deg[i] = query(v[i], l[i]) - 1; n         for (int i : p) affect(v[i], l[i], -1); n         for (int i : p) res += deg[i] != cur - 1; n         return res; n       }; n       int l = 1, r = n - 3, mid, res = -1; n       while (l <= r) { n         mid = (l + r) >> 1; n         solve(mid) + 3 >= k ? (res = mid, r = mid - 1) : (l = mid + 1); n       } n       if (!(~res)) n         printf( Assert: Passing [%s] in LINE %d n , __FUNCTION__, 144), exit(0); n       int now = solve(res); n       std::vector<int> p = getp(res); n       for (int i : p) n         if (deg[i] != res - 1) pos.push_back(i); n       if (pos.size() < k) pos.push_back(A); n       if (pos.size() < k) pos.push_back(B); n       if (pos.size() < k) pos.push_back(C); n     } else { n       uint64_t all = 0; n       std::vector<int> match(n + 1); n       std::vector<uint64_t> hsh(n + 1); n       std::map<uint64_t, int> map; n       std::map<int, uint64_t> sta; n       std::mt19937_64 rng( n           20040725 ^ n           std::chrono::steady_clock::now().time_since_epoch().count()); n       for (int i = 1; i <= n; i++) n         hsh[i] = rng(), all ^= hsh[i], map[hsh[i]] = i; n       for (int i = 1; i <= n; i++) n         for (int x = 1; x < (1 << l[i]); x++) { n           int s = 1; n           for (int j = 0; j < l[i]; j++) n             if ((x >> j) & 1) s *= v[i][j]; n           sta[s] ^= hsh[i]; n         } n       for (int i = 1; i <= n; i++) n         if (deg[i] == n - 2) { n           uint64_t tem = all; n           for (int x = 1; x < (1 << l[i]); x++) { n             int s = 1; n             for (int j = 0; j < l[i]; j++) n               if ((x >> j) & 1) s *= v[i][j]; n             tem ^= sta[s]; n           } n           match[i] = map[tem]; n         } n       for (int i = 1; i <= n; i++) n         if (!match[i] || i < match[i]) pos.push_back(i); n     } n   } n   if (!(pos.size() >= k)) n     printf( Assert: Passing [%s] in LINE %d n , __FUNCTION__, 186), exit(0); n   for (int i = 0; i < k; i++) print(pos[i],    n [i + 1 == k]); n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = (int)1e9; n const int toN = 58; n int pn, p[10000]; n int n, a[10000], omask[10000]; n int dp[110][1 << 18]; n int ans[110][1 << 18]; n bool isPrime(int n) { n   if (n == 2) return true; n   for (int i = 2; i * i <= n; ++i) n     if (n % i == 0) return false; n   return true; n } n int main() { n   pn = 0; n   for (int i = 2; i <= toN; ++i) n     if (isPrime(i)) p[pn++] = i; n   cin >> n; n   for (int i = 0; i < n; ++i) cin >> a[i]; n   for (int i = 0; i <= n; ++i) { n     for (int m = 0; m < (1 << pn); ++m) dp[i][m] = inf; n   } n   dp[0][0] = 0; n   for (int i = 1; i <= toN; ++i) { n     omask[i] = 0; n     for (int j = 0; j < pn; ++j) n       if (i % p[j] == 0) omask[i] |= (1 << j); n   } n   for (int m = 0; m < (1 << pn); ++m) { n     for (int j = 1; j <= toN; ++j) n       if ((omask[j] & m) == 0) { n         for (int i = 0; i < n; ++i) n           if (dp[i][m] < inf) { n             int nm = (m | omask[j]); n             if (dp[i + 1][nm] > dp[i][m] + abs(j - a[i])) { n               dp[i + 1][nm] = dp[i][m] + abs(j - a[i]); n               ans[i + 1][nm] = j; n             } n           } n       } n   } n   int v = 0; n   for (int m = 0; m < (1 << pn); ++m) n     if (dp[n][v] > dp[n][m]) v = m; n   vector<int> ansv; n   for (int i = n; i >= 1; --i) { n     ansv.push_back(ans[i][v]); n     v = v - omask[ans[i][v]]; n   } n   reverse((ansv).begin(), (ansv).end()); n   for (__typeof(ansv.begin()) it = ansv.begin(); it != ansv.end(); ++it) n     cout << *it <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 5; n const int INF = 0x3f3f3f3f; n int dp[N]; n struct node { n   int v, id; n } a[N][2]; n void up1(int sta, int cost, int i) { n   if (a[sta][0].v > cost) { n     a[sta][1] = a[sta][0]; n     a[sta][0] = {cost, i}; n   } else if (a[sta][1].v > cost) { n     a[sta][1] = {cost, i}; n   } n } n int num = -1, now, cs; n pair<int, int> ans; n void up2(node x, node y, int sta) { n   if (x.v == INF || y.v == INF) return; n   now = x.v + y.v; n   if (dp[sta] > num || (dp[sta] == num && cs > now)) { n     num = dp[sta]; n     cs = now; n     ans = {x.id, y.id}; n   } n } n int main() { n   int k, n, m, sta, v, cost; n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &k); n     sta = 0; n     for (int j = 1; j <= k; j++) { n       scanf( %d , &v); n       sta |= 1 << (v - 1); n     } n     dp[sta]++; n   } n   int mx = 0; n   for (int i = 0; i < 9; i++) { n     for (int j = (1 << 9) - 1; j >= 0; j--) { n       if ((1 << i) & j) dp[j] = dp[j] + dp[j ^ (1 << i)]; n       mx = max(mx, dp[j]); n     } n   } n   for (int j = 0; j < (1 << 9); j++) a[j][0].v = a[j][1].v = INF; n   for (int i = 1; i <= m; i++) { n     scanf( %d %d , &cost, &k); n     sta = 0; n     for (int j = 1; j <= k; j++) { n       scanf( %d , &v); n       sta |= 1 << (v - 1); n     } n     up1(sta, cost, i); n   } n   for (int i = 0; i < (1 << 9); i++) { n     for (int j = 0; j < (1 << 9); j++) { n       if (i == j) n         up2(a[i][0], a[i][1], i); n       else n         up2(a[i][0], a[j][0], i | j); n     } n   } n   printf( %d %d n , ans.first, ans.second); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n double vb, vs; n double x[105]; n double tagx, tagy; n double cal(int p) { return sqrt((x[p] - tagx) * (x[p] - tagx) + tagy * tagy); } n int cmp(double x) { n   if (x < (-1e-6)) n     return -1; n   else if (x > 1e-6) n     return 1; n   else n     return 0; n } n int main() { n   scanf( %d%lf%lf , &n, &vb, &vs); n   for (int i = 0; i < n; i++) scanf( %lf , &x[i]); n   scanf( %lf%lf , &tagx, &tagy); n   double ans = (double)(0x3f3f3f3f); n   int pos; n   double min_cal; n   for (int i = 1; i < n; i++) { n     double time = (x[i] / vb) + (cal(i) / vs); n     if (cmp(time - ans) == -1) { n       ans = time; n       pos = i; n       min_cal = cal(i); n     } else if (cmp(time - ans) == 0) { n       if (cmp(cal(i) - min_cal) == -1) { n         ans = time; n         pos = i; n         min_cal = cal(i); n       } n     } n   } n   printf( %d n , pos + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 998244353; n int add(int a, int b) { n   a += b; n   return a >= mod ? a - mod : a; n } n int sub(int a, int b) { n   a -= b; n   return a < 0 ? a + mod : a; n } n int mul(int a, int b) { return (long long)a * b % mod; } n int qpow(int a, int b) { n   int ret = 1; n   for (; b; b >>= 1, a = mul(a, a)) n     if (b & 1) ret = mul(ret, a); n   return ret; n } n const int inv2 = qpow(2, mod - 2); n const int N = 1e6 + 5; n int n; n int hed[N], cnt, to[N], nxt[N]; n inline void adde(int u, int v) { n   ++cnt; n   to[cnt] = v, nxt[cnt] = hed[u]; n   hed[u] = cnt; n } n int f[N][2]; n int ans = 0; n inline void dfs(int x, int pre) { n   int way0 = 1; n   for (int i = hed[x]; i; i = nxt[i]) { n     int v = to[i]; n     if (v == pre) continue; n     dfs(v, x); n     way0 = mul(way0, add(mul(inv2, f[v][0]), f[v][1])); n   } n   int way1 = sub(1, way0); n   f[x][0] = way0; n   f[x][1] = way1; n   ans = add(ans, way1); n } n int main() { n   cin >> n; n   for (int i = 1; i < n; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     adde(u, v), adde(v, u); n   } n   dfs(1, 0); n   cout << mul(ans, qpow(2, n)) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n const int MAXN = 2000 + 5; n int dp[MAXN][MAXN] = {0}; n int previous[MAXN] = {0}; n void calculatePrevious(const string &s, const string &p) { n   int sSize = s.length(); n   int pSize = p.length(); n   for (int i = 0; i < sSize; ++i) { n     previous[i] = -2; n     int currentP = pSize - 1; n     int currentS = i; n     while (currentP >= 0 && currentS >= 0) { n       while (currentS >= 0 && s[currentS] != p[currentP]) { n         currentS--; n       } n       if (currentS >= 0) { n         currentP--; n         currentS--; n       } n     } n     if (currentP == -1) { n       previous[i] = currentS; n     } n   } n } n int main() { n   string s, p; n   cin >> s >> p; n   int sSize = s.length(); n   int pSize = p.length(); n   calculatePrevious(s, p); n   for (int i = 1; i <= sSize; ++i) { n     for (int j = 0; j < sSize; ++j) { n       dp[i][j] = dp[i - 1][j]; n       if (j > 0) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1]); n       int prev = previous[i - 1]; n       if (prev != -2) { n         int toDelete = (i - 1) - prev - pSize; n         int newDelete = j - toDelete; n         int newIndex = prev + 1; n         if (newDelete >= 0 && newIndex >= newDelete) { n           dp[i][j] = max(dp[i][j], 1 + dp[newIndex][newDelete]); n         } n       } n     } n   } n   for (int i = 0; i < sSize; ++i) cout << dp[sSize][i] <<    ; n   cout << 0 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, j, i = 0, count = 0, max = 100000000; n   string s1, s2; n   cin >> n >> m >> s1 >> s2; n   vector<int> a, b; n   while (i + n <= m) { n     count = 0; n     for (j = 0; j < n; j++) { n       if (s1[j] != s2[i + j]) { n         a.push_back(j + 1); n         count++; n       } n     } n     if (count < max) { n       max = count; n       b = a; n     } n     i++; n     a.clear(); n   } n   cout << max << endl; n   for (i = 0; i < max; i++) cout << b[i] <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline void proc_status() { n   ifstream t( /proc/self/status ); n   cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) n        << endl; n } n template <typename T> n inline bool chkmin(T &a, const T &b) { n   return a > b ? a = b, 1 : 0; n } n template <typename T> n inline bool chkmax(T &a, const T &b) { n   return a < b ? a = b, 1 : 0; n } n template <typename T> n inline T read() { n   register T sum(0), fg(1); n   register char ch(getchar()); n   for (; !isdigit(ch); ch = getchar()) n     if (ch ==  - ) fg = -1; n   for (; isdigit(ch); ch = getchar()) sum = sum * 10 -  0  + ch; n   return sum * fg; n } n const int MOD = (int)1e9 + 7; n const int MAXN = (int)1e6; n int n; n char s0[MAXN + 5]; n inline void input() { scanf( %s , s0 + 1), n = strlen(s0 + 1); } n namespace PAM { n const int MAX_NODE = MAXN * 2, alpha = 26; n int fail[MAX_NODE + 5], trans[MAX_NODE + 5][alpha], nxt[MAX_NODE + 5], cnt; n int len[MAX_NODE + 5], delta[MAX_NODE + 5]; n int rt0, rt1, lst; n int S[MAX_NODE + 5], N = 0; n inline void init() { n   S[0] = -1; n   cnt = 1, lst = 0; n   memset(trans[0], 0, sizeof trans[0]); n   memset(trans[1], 0, sizeof trans[1]); n   len[0] = 0, len[1] = -1; n   fail[0] = 1; n } n inline int new_node(int l) { n   len[++cnt] = l; n   fail[cnt] = 0; n   memset(trans[cnt], 0, sizeof trans[cnt]); n   return cnt; n } n inline int extend(int ch) { n   int p = lst; n   S[++N] = ch; n   while (S[N - len[p] - 1] != S[N]) p = fail[p]; n   int np = -1; n   if (!trans[p][ch]) { n     np = new_node(len[p] + 2); n     int t = fail[p]; n     while (S[N - len[t] - 1] != S[N]) t = fail[t]; n     fail[np] = trans[t][ch]; n     delta[np] = len[np] - len[fail[np]]; n     nxt[np] = delta[np] == delta[fail[np]] ? nxt[fail[np]] : fail[np]; n     trans[p][ch] = np; n   } else n     np = trans[p][ch]; n   return lst = np; n } n }  // namespace PAM n inline void solve() { n   static int s[MAXN + 5]; n   for (int i = 1; i <= n / 2; ++i) { n     s[i * 2 - 1] = s0[i] -  a ; n     s[i * 2] = s0[n - i + 1] -  a ; n   } n   static int nd[MAXN + 5]; n   PAM::init(); n   for (int i = 1; i <= n; ++i) nd[i] = PAM::extend(s[i]); n   static int f[MAXN + 5], g[MAXN + 5]; n   f[0] = 1; n   for (int i = 1; i <= n; ++i) n     for (int p = nd[i]; p; p = PAM::nxt[p]) { n       g[p] = f[i - PAM::len[PAM::nxt[p]] - PAM::delta[p]]; n       if (PAM::delta[p] == PAM::delta[PAM::fail[p]]) n         (g[p] += g[PAM::fail[p]]) %= MOD; n       if (i % 2 == 0) (f[i] += g[p]) %= MOD; n     } n   printf( %d n , (f[n] + MOD) % MOD); n } n int main() { n   input(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-6; n const int INF = 0x3f3f3f3f, N = 2000005, M = 2000005, MOD = 1e9 + 7; n int sgn(double x) { return x < -eps ? -1 : (x < eps ? 0 : 1); } n int Rand(int x) { return rand() * rand() % x + 1; } n vector<int> G[N]; n int dep[N]; n double ans = 0; n void dfs(int x, int _fa, int _dep) { n   dep[x] = _dep; n   ans += 1. / dep[x]; n   for (auto v : G[x]) n     if (v != _fa) { n       dfs(v, x, _dep + 1); n     } n } n int Solve() { n   int n; n   cin >> n; n   for (int i = 1; i < n; i++) { n     int u, v; n     cin >> u >> v; n     G[u].push_back(v), G[v].push_back(u); n   } n   dfs(1, 0, 1); n   cout << fixed << setprecision(12) << ans << endl; n   return 0; n } n void Pre() {} n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0), cout.tie(0); n   Pre(); n   while (Solve()) n     ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:50000000 ) n using namespace std; n int tt[1000000], kix[1000000], num[1000000], degree[1000000], black[1000000], n     fix[1000000]; n vector<int> q, g[1000000]; n int pirveli, p, i, j, n, m, k, a, b; n int par[100005][20]; n long long ans[1000000]; n void go(int x, int prev = -1) { n   fix[x] = 1; n   q.push_back(x); n   for (int i = 0; i < g[x].size(); i++) { n     int nxt = g[x][i]; n     if (nxt == prev) continue; n     if (fix[nxt] == 0) { n       go(nxt, x); n       continue; n     } n     if (num[nxt] != -1) continue; n     for (int j = q.size() - 1; j >= 0; j--) { n       num[q[j]] = nxt; n       if (q[j] == nxt) break; n     } n   } n   q.pop_back(); n } n void DFS(int v, int prev, int deg, int raod) { n   kix[v] = 1; n   degree[v] = deg; n   if (tt[v] != 1) raod++; n   black[v] = raod; n   par[v][0] = num[prev]; n   for (int j = 1; j <= 19; j++) n     if (par[v][j - 1] == -1) n       par[v][j] = -1; n     else n       par[v][j] = par[par[v][j - 1]][j - 1]; n   for (int i = 0; i < g[v].size(); i++) { n     int nxt = g[v][i]; n     if (nxt == prev) continue; n     DFS(nxt, v, deg + 1, raod); n   } n } n int LCA(int a, int b) { n   for (int i = 18; i >= 0; i--) { n     if (degree[a] - (1 << i) >= degree[b]) { n       a = par[a][i]; n     } n   } n   if (a == b) return a; n   for (int i = 18; i >= 0; i--) { n     if (par[a][i] != par[b][i]) { n       a = par[a][i]; n       b = par[b][i]; n     } n   } n   return par[a][0]; n } n int main() { n   cin >> n >> m; n   for (i = 0; i < m; i++) { n     cin >> a >> b; n     a--; n     b--; n     g[a].push_back(b); n     g[b].push_back(a); n   } n   for (i = 0; i < n; i++) num[i] = -1; n   go(0); n   for (i = 0; i <= n; i++) n     for (j = 0; j <= 20; j++) par[i][j] = -1; n   for (i = 0; i < n; i++) { n     if (num[i] == -1 || num[i] == i) continue; n     for (j = 0; j < g[i].size(); j++) g[num[i]].push_back(g[i][j]); n   } n   for (i = 0; i < n; i++) n     if ((num[i] == -1 || num[i] == i)) { n       for (j = 0; j < g[i].size(); j++) { n         int nxt = g[i][j]; n         if (num[nxt] == i) { n           g[i][j] = g[i].back(); n           g[i].pop_back(); n           j--; n         } else if (num[nxt] == -1) n           continue; n         else n           g[i][j] = num[nxt]; n       } n     } n   if (num[0] == -1) n     pirveli = 0; n   else n     pirveli = num[0]; n   for (i = 0; i < n; i++) n     if (num[i] == -1) { n       num[i] = i; n       tt[i] = 1; n     } n   DFS(pirveli, -1, 0, 0); n   ans[0] = 1; n   for (i = 1; i <= n; i++) ans[i] = ans[i - 1] * 2 % 1000000007; n   cin >> k; n   while (k--) { n     cin >> a >> b; n     a = num[a - 1]; n     b = num[b - 1]; n     if (degree[a] < degree[b]) swap(a, b); n     p = LCA(a, b); n     p = num[p]; n     cout << ans[black[a] + black[b] - 2 * black[p] + (tt[p] == 0)] << endl; n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n const long long HASH = 1e16 + 7; n const long long INF = 1e9; n long long tavan(long long a, long long b) { n   return b ? (tavan(a * a, b >> 1) * (b & 1 ? a : 1)) : 1; n } n long long gcd(long long a, long long b) { n   return (a < b) ? gcd(b, a) : ((a % b == 0) ? b : gcd(b, a % b)); n } n bool isprime(long long x) { n   for (long long i = 2; i <= sqrt(x); i++) n     if (!(x % i)) return false; n   return true; n } n ifstream fin( input.txt ); n ofstream fout( output.txt ); n long long n, a[1100]; n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int t = 0; t < n + 1000; t++) { n     bool ex = 1; n     for (int i = 0; i < n; i++) { n       if (i % 2 == 0) n         a[i]++; n       else n         a[i]--; n       if (a[i] == n) a[i] = 0; n       if (a[i] == -1) a[i] = n - 1; n       if (a[i] != i) ex = 0; n     } n     if (ex) { n       cout <<  YES ; n       return 0; n     } n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Maxl = 26; n const int Maxn = 30005; n const int Maxstr = 200005; n const int Inf = 2000000007; n char str[Maxstr]; n int t; n int n, m, k; n int freq[Maxl]; n bool dp[Maxn]; n int res; n int main() { n   scanf( %d , &t); n   while (t--) { n     scanf( %d %d %d , &n, &m, &k); n     scanf( %s , str); n     fill(freq, freq + Maxl, 0); n     for (int i = 0; i < k; i++) freq[str[i] -  A ]++; n     res = Inf; n     int mx = max(n, m); n     for (int i = 0; i < Maxl; i++) { n       int tot = 0; n       for (int j = 0; j < Maxl; j++) n         if (j != i) tot += freq[j]; n       int mn = tot; n       fill(dp, dp + mx + 1, false); n       dp[0] = true; n       for (int j = 0; j < Maxl; j++) n         if (j != i) n           for (int l = mx; l >= 0; l--) n             if (dp[l]) n               if (l + freq[j] > mx) n                 mn = min(mn, l + freq[j]); n               else n                 dp[l + freq[j]] = true; n       for (int l = 0; l <= mx; l++) n         if (dp[l]) { n           int a = l, b = tot - l; n           int mya = max(0, n - a), myb = max(0, m - b); n           if (mya + myb <= freq[i]) res = min(res, mya * myb); n           mya = max(0, n - b), myb = max(0, m - a); n           if (mya + myb <= freq[i]) res = min(res, mya * myb); n         } n       int a = mn, b = tot - mn; n       int mya = max(0, n - a), myb = max(0, m - b); n       if (mya + myb <= freq[i]) res = min(res, mya * myb); n       mya = max(0, n - b), myb = max(0, m - a); n       if (mya + myb <= freq[i]) res = min(res, mya * myb); n     } n     printf( %d n , res); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace { n void Solve(int) { n   const set<string> bins = { AND ,  OR ,  XOR }; n   int n; n   cin >> n; n   vector<string> type(n); n   vector<int> lef(n, -1), rig(n, -1); n   for (int i = 0, __i = n; i < __i; ++i) { n     cin >> type[i] >> lef[i]; n     if (type[i] !=  IN ) --lef[i]; n     if (bins.count(type[i])) { n       cin >> rig[i]; n       --rig[i]; n     } n   } n   auto eval = [](const string& t, bool a, bool b) { n     if (t ==  AND ) n       return a and b; n     else if (t ==  OR ) n       return a or b; n     else n       return (bool)(a ^ b); n   }; n   vector<bool> val(n), flip(n); n   function<void(int)> dfs1 = [&](int at) { n     if (type[at] ==  IN ) { n       val[at] = lef[at]; n     } else { n       dfs1(lef[at]); n       if (bins.count(type[at])) { n         dfs1(rig[at]); n         val[at] = eval(type[at], val[lef[at]], val[rig[at]]); n       } else { n         val[at] = !val[lef[at]]; n       } n     } n   }; n   dfs1(0); n   function<void(int)> dfs2 = [&](int at) { n     if (type[at] ==  IN ) n       flip[at] = true; n     else if (type[at] ==  NOT ) { n       flip[at] = true; n       dfs2(lef[at]); n     } else { n       if (val[at] != eval(type[at], val[lef[at]] ^ 1, val[rig[at]])) { n         flip[at] = true; n         dfs2(lef[at]); n       } n       if (val[at] != eval(type[at], val[lef[at]], val[rig[at]] ^ 1)) { n         flip[at] = true; n         dfs2(rig[at]); n       } n     } n   }; n   dfs2(0); n   for (int i = 0, __i = n; i < __i; ++i) n     if (type[i] ==  IN ) cout << (val[0] ^ flip[i]); n   cout <<   n ; n } n void Init() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n } n }  // namespace n int32_t main() { n   Init(); n   int tests = 1; n   for (int test = 1, __test = tests + 1; test < __test; ++test) Solve(test); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 100000 + 1; n const int INF = numeric_limits<int>::max() / 2; n pair<int, int> P[MAX_N]; n pair<int, int> prefix[MAX_N], suffix[MAX_N]; n int N; n long long square(int first) { return 1LL * first * first; } n bool valid(long long M) { n   long long bestY, bestXY; n   int i = 1, j = 1; n   while (i <= N) { n     while (square(P[i].first - P[j].first) > M) j++; n     assert(j <= i); n     assert(square(P[i].first - P[j].first) <= M); n     int maxY = -INF; n     int minY = INF; n     bool changed = false; n     if (j > 1) { n       changed = true; n       minY = min(minY, prefix[j - 1].first); n       maxY = max(maxY, prefix[j - 1].second); n     } n     if (i < N) { n       changed = true; n       minY = min(minY, suffix[i + 1].first); n       maxY = max(maxY, suffix[i + 1].second); n     } n     if (changed) { n       bestY = square(maxY - minY); n       bestXY = max(square(maxY), square(minY)) + n                max(square(P[i].first), square(P[j].first)); n     } else n       bestY = 0, bestXY = 0; n     if (bestY <= M && bestXY <= M) return true; n     i++; n   } n   return false; n } n void makePrefixSuffix() { n   pair<int, int> p = {INF, -INF}; n   for (int i = 1; i <= N; ++i) { n     p.first = min(p.first, P[i].second); n     p.second = max(p.second, P[i].second); n     prefix[i] = p; n   } n   p = {INF, -INF}; n   for (int i = N; i >= 1; i--) { n     p.first = min(p.first, P[i].second); n     p.second = max(p.second, P[i].second); n     suffix[i] = p; n   } n } n long long binarySearch() { n   long long l = 0; n   long long r = 1LL * INF * INF >> 1; n   long long sol = -1; n   while (l <= r) { n     long long m = (l + r) / 2; n     if (valid(m)) { n       sol = m; n       r = m - 1; n     } else n       l = m + 1; n   } n   return sol; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> N; n   for (int i = 1; i <= N; ++i) cin >> P[i].first >> P[i].second; n   sort(P + 1, P + N + 1); n   makePrefixSuffix(); n   long long sol1 = binarySearch(); n   for (int i = 1; i <= N; ++i) swap(P[i].first, P[i].second); n   sort(P + 1, P + N + 1); n   makePrefixSuffix(); n   long long sol2 = binarySearch(); n   cout << min(sol1, sol2) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> a[100010]; n int y[100010], res[100010]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     int num; n     scanf( %d%d , &num, &y[i]); n     res[i] = 0; n     for (int k = 1; k * k <= num; k++) n       if (num % k == 0) { n         a[k].push_back(i); n         res[i]++; n         if (k * k != num) { n           a[num / k].push_back(i); n           res[i]++; n         } n       } n   } n   for (int i = 1; i <= 100000; i++) n     for (int j = 1; j < a[i].size(); j++) n       if (a[i][j] - a[i][j - 1] <= y[a[i][j]]) res[a[i][j]]--; n   for (int i = 0; i < n; i++) printf( %d n , res[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct P { n   long long first, second, sum; n   P(long long first = 0, long long second = 0, long long sum = 0) n       : first(first), second(second), sum(sum) {} n   bool operator<(const P &b) const { return first < b.first; } n }; n const long long MAX_V = 500100; n const long long MAX_LOG_V = 25; n vector<long long> G[MAX_V]; n long long root, V; n long long parent[MAX_LOG_V][MAX_V]; n long long depth[MAX_V], ans[MAX_V]; n struct vertex { n   long long v, di; n   vertex(long long v, long long di = 0) : v(v), di(di) {} n   bool operator<(const vertex &b) const { return di < b.di; } n }; n vector<vertex> depVec[MAX_V]; n long long dfs_index = 0; n void dfs(long long v, long long p, long long d) { n   parent[0][v] = p; n   depth[v] = d; n   depVec[d].push_back(vertex(v, ++dfs_index)); n   for (long long i = 0; i < G[v].size(); i++) n     if (G[v][i] != p) dfs(G[v][i], v, d + 1); n } n void init() { n   dfs(root, -1, 1); n   for (long long k = 0; k + 1 < MAX_LOG_V; k++) n     for (long long v = 1; v <= V; v++) { n       if (parent[k][v] < 0) n         parent[k + 1][v] = -1; n       else n         parent[k + 1][v] = parent[k][parent[k][v]]; n     } n } n long long lca(long long u, long long v) { n   if (depth[u] > depth[v]) swap(u, v); n   for (long long k = 0; k < MAX_LOG_V; k++) { n     if ((depth[v] - depth[u]) >> k & 1) v = parent[k][v]; n     if (depth[v] == depth[u]) break; n   } n   if (u == v) return u; n   for (long long k = MAX_LOG_V - 1; k >= 0; k--) { n     if (parent[k][u] != parent[k][v]) { n       u = parent[k][u]; n       v = parent[k][v]; n     } n   } n   return parent[0][u]; n } n void solve(const vector<vertex> &vec) { n   vector<P> stk(vec.size() + 1, P(0)); n   long long sn = 0; n   long long d = depth[lca(vec[0].v, vec[1].v)]; n   stk[sn++] = P(d, 1, d); n   ans[vec[1].v] += stk[0].sum; n   for (long long i = 2; i < vec.size(); i++) { n     long long d = depth[lca(vec[i - 1].v, vec[i].v)]; n     if (d < 0) { n       cout <<  d =   << d << endl; n     } n     long long x = n         lower_bound(stk.begin(), stk.begin() + sn, P(d, -1)) - stk.begin(); n     if (x == sn) { n       stk[sn] = P(d, stk[sn - 1].second + 1, stk[sn - 1].sum + d); n       sn++; n     } else { n       long long cnt = stk[sn - 1].second - (x > 0 ? stk[x - 1].second : 0) + 1; n       if (cnt < 0) { n         cout <<  stk[sn-1].second =   << stk[sn - 1].second << endl; n         cout <<  x =   << x << endl; n         cout <<  sn =   << sn << endl; n         cout <<  ~ =   << (x > 0 ? stk[x - 1].second : 0) << endl; n       } n       stk[x] = n           P(d, stk[sn - 1].second + 1, (x > 0 ? stk[x - 1].sum : 0) + d * cnt); n       sn = x + 1; n     } n     ans[vec[i].v] += stk[sn - 1].sum; n     if (stk[sn - 1].sum < 0) { n       cout <<  vec[i].v =   << vec[i].v << endl; n       for (long long j = 0; j < sn; j++) n         cout <<  stk[  << j <<  ] =   << stk[sn - 1].first <<     n              << stk[sn - 1].second <<     << stk[sn - 1].sum << endl; n       exit(0); n     } n   } n } n int main() { n   std::ios::sync_with_stdio(false); n   std::cin.tie(0); n   cin >> V; n   for (long long i = 1; i <= V; i++) { n     long long p; n     cin >> p; n     if (p == 0) n       root = i; n     else n       G[p].push_back(i); n   } n   init(); n   for (long long i = 2; i <= V; i++) { n     if (depVec[i].empty()) break; n     if (depVec[i].size() > 1) { n       sort(depVec[i].begin(), depVec[i].end()); n       solve(depVec[i]); n       reverse(depVec[i].begin(), depVec[i].end()); n       solve(depVec[i]); n     } n     for (auto j : depVec[i]) { n       ans[j.v] += ans[parent[0][j.v]] + depth[j.v] - 1; n     } n   } n   for (long long i = 1; i <= V; i++) { n     cout << ans[i] << (i == V ?   n  :    ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int Inf = 1e9 + 7; n int dp[107][107]; n int par[107][107]; n string t =  .,!?  ; n bool check(char c) { return t.find(c) == string::npos; } n void solve() { n   int t; n   cin >> t; n   for (int k = 0; k < t; k++) { n     int n; n     cin >> n; n     vector<string> users; n     for (int i = 0; i < n; i++) { n       string p; n       cin >> p; n       users.push_back(p); n     } n     sort(users.begin(), users.end()); n     map<string, int> id; n     for (int i = 0; i < n; i++) id[users[i]] = i; n     memset(dp, 0, sizeof(dp)); n     for (int i = 0; i < n; i++) dp[0][i] = 1; n     memset(par, -1, sizeof(par)); n     int m; n     cin >> m; n     string buf; n     getline(cin, buf); n     vector<string> message; n     for (int i = 0; i < m; i++) { n       string buf; n       getline(cin, buf); n       int pos = buf.find( : ); n       string user = buf.substr(0, pos); n       string msg = buf.substr(pos + 1); n       message.push_back(msg); n       vector<string> w; n       int p = 0, l = msg.size(); n       while (p < l) { n         while (p < l && !check(msg[p])) p++; n         int q = p; n         while (q < l && check(msg[q])) q++; n         string word = msg.substr(p, q - p); n         if (word !=   ) w.push_back(word); n         p = q; n       } n       int uid = id.count(user) == 0 ? -1 : id[user]; n       if (uid == -1) { n         for (int j = 0; j < n; j++) { n           if (find(w.begin(), w.end(), users[j]) != w.end()) continue; n           for (int jj = 0; jj < n; jj++) { n             if (dp[i][jj] == 1 && (i == 0 || j != jj)) { n               dp[i + 1][j] = 1; n               par[i + 1][j] = jj; n             } n           } n         } n       } else { n         for (int jj = 0; jj < n; jj++) { n           if (dp[i][jj] == 1 && (i == 0 || uid != jj)) { n             dp[i + 1][uid] = 1; n             par[i + 1][uid] = jj; n           } n         } n       } n     } n     vector<string> res; n     for (int i = 0; i < n; i++) n       if (dp[m][i] == 1) { n         int p = i, q = m; n         while (q > 0) { n           res.push_back(users[p]); n           p = par[q][p]; n           q--; n         } n       } n     if (res.empty()) { n       cout <<  Impossible  <<   n ; n     } else { n       reverse(message.begin(), message.end()); n       for (int i = m - 1; i >= 0; --i) { n         ostringstream oss; n         oss << res[i]; n         oss <<  : ; n         oss << message[i]; n         cout << oss.str() <<   n ; n       } n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cout.precision(9); n   cout << fixed; n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, m; n   cin >> n >> m; n   long long f = 1; n   for (long long i = 0; i < 100000; i++) { n     n += (n % m); n     if (n % m == 0) { n       f = 0; n       break; n     } n   } n   if (!f) 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 long long mod = 998244353; n const long long N = 2e5; n const long long inf = 1e18; n template <typename... T> n void read(T&... args) { n   ((cin >> args), ...); n } n template <typename... T> n void write(T&&... args) { n   ((cout << args <<    ), ...); n } n template <typename... T> n void writeline(T&&... args) { n   ((cout << args <<    ), ...); n   cout <<   n ; n } n long long add(long long a, long long b) { n   long long res = (a + b) % mod; n   return (res < 0) ? res + mod : res; n } n long long mul(long long a, long long b) { n   long long res = (a * 1LL * b) % mod; n   return (res < 0) ? res + mod : res; n } n string binary(long long x) { n   string res =   ; n   for (long long i = 0; i < 32; i++) res += (1 << i & x) ?  1  :  0 ; n   return res; n } n long long in(long long x, long long y, long long z) { n   if (y > z) swap(y, z); n   return (x >= y && x <= z); n } n long long valid(long long x, long long sum) { n   long long s = 0; n   while (x) { n     s += x % 10; n     x /= 10; n   } n   return s == sum; n } n void solve() { n   long long n; n   cin >> n; n   if (n == 1) { n     cout << -1; n     return; n   } n   writeline(n, n + 1, n * (n + 1)); n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   long long data = 0, w = 1; n   char ch = 0; n   while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar(); n   if (ch ==  - ) w = -1, ch = getchar(); n   while (ch >=  0  && ch <=  9 ) data = data * 10 + ch -  0 , ch = getchar(); n   return data * w; n } n long long n, c, p[1000005], a[1000005]; n int main() { n   n = read(), c = read(); n   for (long long i = 1; i <= n; i++) p[i] = read(); n   long long sum = 0, ans = 0; n   for (long long i = 1; i <= n; i++) { n     long long s = read(); n     a[i] = s - p[i] + c * (n - i); n     sum += p[i]; n   } n   ans = sum; n   sort(a + 1, a + n + 1); n   for (long long i = 1; i <= n; i++) n     sum += a[i] - (i - 1) * c, ans = min(ans, sum); n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, used[100003], m[100003]; n string s, ans =  INFINITE ; n void DFS(int v) { n   if (used[v] == 1) { n     ans =  INFINITE ; n     return; n   } n   used[v] = 1; n   if (s[v] ==  < ) { n     if (v - m[v] > 0) n       DFS(v - m[v]); n     else { n       ans =  FINITE ; n       return; n     } n   } else { n     if (v + m[v] <= n) n       DFS(v + m[v]); n     else { n       ans =  FINITE ; n       return; n     } n   } n } n int main() { n   cin >> n >> s; n   s =     + s; n   for (int k = 1; k <= n; k++) cin >> m[k]; n   DFS(1); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n int main() { n   ll t; n   cin >> t; n   while (t--) { n     ll n, m, k; n     cin >> n >> m >> k; n     k--; n     k--; n     if (m > n * (n - 1) / 2 || m < n - 1) { n       cout <<  nO  <<   n ; n       continue; n     } n     if (k > 1) { n       if (m > n - 2) { n         cout <<  yEs  <<   n ; n       } else n         cout <<  nO  <<   n ; n     } else if (k == 1) { n       if (m == n * (n - 1) / 2) { n         cout <<  yEs  <<   n ; n       } else n         cout <<  nO  <<   n ; n     } else if (k == 0) { n       if (n == 1) n         cout <<  yEs  <<   n ; n       else n         cout <<  nO  <<   n ; n     } else n       cout <<  nO  <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 10005; n vector<int> g[M]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n - 1; i++) { n     int a, b; n     scanf( %d %d , &a, &b); n     g[a].push_back(b); n     g[b].push_back(a); n   } n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j < g[i].size(); j++) { n       int v = g[i][j]; n       ans += ((int)g[v].size()) - 1; n     } n   } n   cout << ans / 2; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long fac[1000001]; n int main() { n   long long n, ans = 0, c = 0, mx = 0, tmp, tmp2, lg; n   cin >> n; n   for (long long i = 2; i < n; i++) { n     tmp = n / i; n     tmp = tmp * (tmp + 1) / 2 - 1; n     ans += (tmp * 4); n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n int N; n char c[2000000]; n int numWays() { n   if (N == 1) { n     if (c[0] ==  * ) n       return 1; n     else if (c[0] ==  0 ) n       return 1; n     else if (c[0] ==  ? ) n       return 2; n     else n       return 0; n   } n   if (c[0] ==  2 ) return 0; n   if (c[N - 1] ==  2 ) return 0; n   for (int i = 0; i < N; i++) { n     if (c[i] ==  0 ) { n       if (i > 0) { n         if (c[i - 1] ==  ? ) n           c[i - 1] =  - ; n         else if (c[i - 1] ==  * ) n           return 0; n       } n       if (i + 1 < N) { n         if (c[i + 1] ==  ? ) n           c[i + 1] =  - ; n         else if (c[i + 1] ==  * ) n           return 0; n       } n     } n   } n   for (int i = 0; i < N; i++) { n     int max = (i > 0) + ((i + 1) < N); n     if (c[i] ==  0  + max) { n       if (i > 0) { n         if (c[i - 1] ==  ? ) n           c[i - 1] =  * ; n         else if (c[i - 1] !=  * ) n           return 0; n       } n       if (i + 1 < N) { n         if (c[i + 1] ==  ? ) n           c[i + 1] =  * ; n         else if (c[i + 1] !=  * ) n           return 0; n       } n     } n   } n   for (int i = 1; i + 1 < N; i++) { n     if (c[i] ==  1 ) { n       int numq = (c[i - 1] ==  ? ) + (c[i + 1] ==  ? ); n       int numm = (c[i - 1] ==  * ) + (c[i + 1] ==  * ); n       int numf = 2 - numm - numq; n       if (numq == 0) { n         if (numf != 1) return 0; n       } else if (numq == 1) { n         if (numm == 0) { n           if (c[i - 1] ==  ? ) n             c[i - 1] =  * ; n           else if (c[i + 1] ==  ? ) n             c[i + 1] =  * ; n           else n             assert(false); n         } else if (numm == 1) { n           if (c[i - 1] ==  ? ) n             c[i - 1] =  - ; n           else if (c[i + 1] ==  ? ) n             c[i + 1] =  - ; n           else n             assert(false); n         } else n           assert(false); n       } n     } n   } n   for (int i = N - 2; i > 0; i--) { n     if (c[i] ==  1 ) { n       int numq = (c[i - 1] ==  ? ) + (c[i + 1] ==  ? ); n       int numm = (c[i - 1] ==  * ) + (c[i + 1] ==  * ); n       int numf = 2 - numm - numq; n       if (numq == 0) { n         if (numf != 1) return 0; n       } else if (numq == 1) { n         if (numm == 0) { n           if (c[i - 1] ==  ? ) n             c[i - 1] =  * ; n           else if (c[i + 1] ==  ? ) n             c[i + 1] =  * ; n           else n             assert(false); n         } else if (numm == 1) { n           if (c[i - 1] ==  ? ) n             c[i - 1] =  - ; n           else if (c[i + 1] ==  ? ) n             c[i + 1] =  - ; n           else n             assert(false); n         } else n           assert(false); n       } n     } n   } n   int res = 1; n   for (int i = 0; i < N; i++) { n     if (c[i] ==  ?  && (i == 0 || c[i - 1] !=  1 )) { n       res *= 2; n       if (res >= MOD) res -= MOD; n     } n   } n   return res; n } n int main() { n   cin >> c; n   N = strlen(c); n   cout << numWays() <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n constexpr int Mod = 998244353; n int n, x, y; n int gr[200005]; n long long sol; n int main() { n   cin >> n; n   sol = n; n   for (int i = 1; i < n; ++i) { n     cin >> x >> y; n     gr[x]++; n     gr[y]++; n     sol = 1LL * sol * gr[x] % Mod * gr[y] % Mod; n   } n   cout << sol <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3e5 + 10; n int n, x, trie[2][31 * maxn], cnt[31 * maxn], a[maxn], tot = 1; n inline void insert(int x) { n   int p = 1, t; n   for (int i = 31; i >= 0; i--) { n     t = (1 << i) & x ? 1 : 0; n     if (!trie[t][p]) trie[t][p] = ++tot; n     p = trie[t][p]; n     cnt[p]++; n   } n } n inline int get_max(int x) { n   int p = 1, t, res = 0; n   for (int i = 31; i >= 0; i--) { n     t = (1 << i) & x ? 1 : 0; n     if (trie[t][p] && cnt[trie[t][p]]) { n       p = trie[t][p]; n     } else { n       p = trie[t ^ 1][p]; n       res |= (1 << i); n     } n     cnt[p]--; n   } n   return res; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &x); n     insert(x); n   } n   for (int i = 1; i <= n; i++) { n     printf( %d%c , get_max(a[i]), i == n ?   n  :    ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string a, b, s; n   cin >> s; n   vector<string> g; n   for (long long i = 0; i < s.length(); i++) { n     a += s[i]; n     if (s[i] !=  a ) { n       b += s[i]; n     } n     if (a.length() + b.length() == s.length()) { n       break; n     } n   } n   if (s == a + b) { n     cout << a; n   } else { n     cout <<  :(  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   cin >> n; n   if (n % 2 == 0) { n     cout << 2; n   } else n     cout << 1; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9; n inline int read() { n   int X = 0, w = 0; n   char ch = 0; n   while (!isdigit(ch)) { n     w |= ch ==  - ; n     ch = getchar(); n   } n   while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar(); n   return w ? -X : X; n } n int n, m; n int dx[4][5] = { n     {2, 1, 0, 0, 0}, {1, 0, 0, 0, -1}, {0, 0, 0, -1, -2}, {1, 0, 0, 0, -1}}; n int dy[4][5] = { n     {0, 0, -1, 0, 1}, {0, 0, 1, 2, 0}, {-1, 0, 1, 0, 0}, {0, -2, -1, 0, 0}}; n char maze[9][9]; n int ans = -1; n char as[9][9]; n bool check(int x, int y, int dir, char c) { n   for (int i = 0; i < 5; i++) { n     int nx = x + dx[dir][i]; n     int ny = y + dy[dir][i]; n     if (nx < 0 or nx >= n or ny < 0 or ny >= m) { n       return 0; n     } n     if (!(c ==  .  or maze[nx][ny] ==  . )) { n       return 0; n     } n   } n   for (int i = 0; i < 5; i++) { n     int nx = x + dx[dir][i]; n     int ny = y + dy[dir][i]; n     maze[nx][ny] = c; n   } n   return 1; n } n void dfs(int x, int y, char c) { n   if (x == n) { n     if (c -  A  > ans) { n       ans = c -  A ; n       for (int i = 0; i < n; i++) { n         for (int j = 0; j < m; j++) { n           as[i][j] = maze[i][j]; n         } n       } n     } n     return; n   } n   if ((n - x) * m / 5 + c -  A  <= ans) { n     return; n   } n   if (y == m) { n     dfs(x + 1, 0, c); n     return; n   } n   for (int i = 0; i < 4; i++) { n     if (check(x, y, i, c)) { n       dfs(x, y + 1, c + 1); n       check(x, y, i,  . ); n     } n   } n   dfs(x, y + 1, c); n } n int main() { n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       maze[i][j] =  . ; n     } n   } n   dfs(0, 0,  A ); n   printf( %d n , ans); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       printf( %c , as[i][j]); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class c> n struct rge { n   c b, e; n }; n template <class c> n rge<c> range(c i, c j) { n   return rge<c>{i, j}; n } n template <class c> n auto dud(c* x) -> decltype(cerr << *x, 0); n template <class c> n char dud(...); n struct debug { n   template <class c> n   debug& operator<<(const c&) { n     return *this; n   } n }; n const double EPS = 1e-4; n void solve() { n   int n; n   cin >> n; n   vector<long long> a(n); n   vector<pair<long long, long long>> diff(n); n   for (long long i = 0; i < int(n); i++) cin >> a[i]; n   for (long long i = 0; i < int(n); i++) diff[i] = {a[i] - i, i}; n   sort(diff.begin(), diff.end()); n   long long curr_sum = 0, res = 0; n   for (long long i = 1; i < n; ++i) { n     if (curr_sum == 0LL && diff[i].first == diff[i - 1].first) { n       curr_sum += (a[diff[i].second] + a[diff[i - 1].second]); n     } else if (diff[i].first == diff[i - 1].first) { n       curr_sum += a[diff[i].second]; n     } else { n       curr_sum = 0; n     } n     res = max(res, curr_sum); n   } n   for (long long i = 0; i < int(n); i++) res = max(res, a[i]); n   cout << res; n   debug() <<   [  n           <<  diff  n               :   n           << (diff) <<  ]  ; n } n int main() { n   std::ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const long double pi = 3.14159265359; n template <typename T> n T abs(T x) { n   return x > 0 ? x : -x; n } n template <typename T> n T sqr(T x) { n   return x * x; n } n const long long mod = 1000000007; n struct matr { n   int maxn; n   int n; n   long long a[1 << 7][1 << 7]; n   matr(int _n) { n     maxn = 1 << _n; n     n = _n; n     for (int i = 0; i < maxn; i++) n       for (int j = 0; j < maxn; j++) a[i][j] = 0; n   } n   matr operator*(const matr &other) const { n     matr res(n); n     long long mod2 = mod * mod; n     for (int i = 0; i < maxn; i++) n       for (int j = 0; j < maxn; j++) { n         for (int h = 0; h < maxn; h++) { n           res.a[i][j] += (a[i][h] * other.a[h][j]); n           if (res.a[i][j] >= mod2) res.a[i][j] -= mod2; n         } n         res.a[i][j] %= mod; n       } n     return res; n   } n   vector<long long> operator*(const vector<long long> &row) { n     vector<long long> res(maxn); n     for (int i = 0; i < maxn; i++) { n       for (int j = 0; j < maxn; j++) { n         res[i] += (a[i][j] * row[j]) % mod; n       } n       res[i] %= mod; n     } n     return res; n   } n }; n matr gen(int n) { n   if (n == 1) { n     matr res(n); n     res.a[0][1] = 1; n     res.a[0][0] = 1; n     res.a[1][0] = 1; n     return res; n   } n   matr res(7); n   for (int _left = 0; _left < (1 << n); _left++) { n     for (int mid = 0; mid < (1 << (n - 1)); mid++) { n       int cmid = (mid << 1) | 1 | (1 << n); n       for (int _right = 0; _right < (1 << n); _right++) { n         bool bad = false; n         for (int j = 0; j < n && !bad; j++) { n           bad |= bool(_left & (1 << j)) && bool(_right & (1 << j)) && n                  bool(cmid & (1 << j)) && bool(cmid & (1 << (j + 1))); n         } n         if (!bad) { n           res.a[_right][_left]++; n         } n       } n     } n   } n   return res; n } n int main() { n   vector<long long> ans(1 << 7); n   ans[1] = 1; n   for (int i = 1; i <= 7; i++) { n     int n; n     cin >> n; n     matr x(7), res(7); n     x = gen(i); n     for (int j = 0; j < (1 << i); j++) n       for (int h = 0; h < (1 << i); h++) res.a[j][h] = j == h; n     while (n) { n       if (n & 1) res = res * x; n       x = x * x; n       n >>= 1; n     } n     ans = res * ans; n     if (i == 7) break; n     for (int j = 0; j < (1 << i); j++) { n       ans[j | (1 << i)] = ans[j]; n       ans[j] = 0; n     } n   } n   cout << ans[(1 << 7) - 1] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long Inf = 1000000000000000000ll; n const int inf = 1000000000; n vector<long long> pri, fac; n long long m, x, ans; n void getpri(long long t, vector<long long>& v) { n   v.clear(); n   for (long long i = 2; i * i <= t; ++i) { n     if (t % i) continue; n     v.push_back(i); n     while (t % i == 0) t /= i; n   } n   if (t != 1) v.push_back(t); n   sort(v.begin(), v.end()); n } n long long Euler(long long t) { n   long long res = t; n   for (int i = 0; i < pri.size(); ++i) n     if (t % pri[i] == 0) res = res / pri[i] * (pri[i] - 1); n   return res; n } n long long mul(long long x, long long y, long long mod) { n   long long res = 0; n   while (y) { n     if (y & 1) (res += x) >= mod && (res -= mod); n     (x <<= 1) >= mod && (x -= mod); n     y >>= 1ll; n   } n   return res; n } n long long qpow(long long b, long long p, long long mod) { n   long long res = 1ll; n   b %= mod; n   while (p) { n     if (p & 1ll) res = mul(b, res, mod); n     b = mul(b, b, mod); n     p >>= 1ll; n   } n   return res; n } n void work(long long md) { n   long long f_d = Euler(md); n   long long l_d = f_d; n   if (l_d > 1) { n     for (int j = 0; j < fac.size(); ++j) n       while (l_d % fac[j] == 0 && qpow(x, l_d / fac[j], md) == 1) l_d /= fac[j]; n   } n   ans += f_d / l_d; n } n int main() { n   scanf( %lld%lld , &m, &x); n   getpri(m, pri); n   long long eul = Euler(m); n   if (eul > 1) n     getpri(eul, fac); n   else n     fac.push_back(1); n   for (long long i = 1; i * i <= m; ++i) { n     if (m % i) continue; n     work(i); n     if (i * i != m) work(m / i); n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, char *argv[]) { n   long long n, k; n   cin >> n >> k; n   long long altura = ceil((long double)k / n); n   cout << altura; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T, class V> n ostream& operator<<(ostream& s, pair<T, V> a) { n   s << a.first <<     << a.second; n   return s; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   long long int T = 1; n   cin >> T; n   for (long long int qq = 1; qq <= T; qq++) { n     long long int n; n     string a, b; n     cin >> n >> a >> b; n     vector<long long int> ans; n     long long int f = 0, l = n - 1, r = 0; n     for (int i = n - 1; i >= 0; i--) { n       if (b[i] -  0  != ((a[l] -  0 ) ^ f)) { n         if (a[l] != a[r]) a[r] = (a[r] -  0 ) ^ 1 +  0 , ans.push_back(1); n         f ^= 1; n         ans.push_back(i + 1); n         swap(l, r); n       } n       if (l > r) n         l--; n       else n         l++; n     } n     cout << ans.size(); n     for (auto x : ans) cout <<     << x; n     cout << endl; n   } n } n


#include<bits/stdc++.h> n using namespace std; n #define int      long long n #define f(i,n)         for(int i=0;i<(n);++i) n #define fa(i,a,n)      for(int i=a;i<=(n);++i) n #define fd(i,a,n)      for(int i=a;i>=(n);--i) n #define tc       int t;cin>>t;f(testcase,t) n #define ld    long double n #define pii             pair<int,int> n #define mem(a,i)  memset(a,i,sizeof(a)) n #define all(x)    x.begin(),x.end() n #define tr(c,i)   for(auto i = c.begin(); i != c.end(); i++) n #define present(c,x)  (c.find(x) != c.end()) n #define cpresent(c,x)  (find(allc,x) != c.end()) n #define PI 3.1415926535897932 n void c_p_c() { n  ios_base::sync_with_stdio(false); n  cin.tie(0); cout.tie(0); n } n  n void solve() { n  int n; n  cin >> n; n  int a[n]; n  n  map<int, int> m; n  f(i, n) { n   cin >> a[i]; n   m[a[i]]++; n  n  } n  cout << n - m.begin()->second <<   n ; n } n int32_t main() { n  n  c_p_c(); n  tc n  solve(); n  return 0; n } n  n


#include <bits/stdc++.h> n using namespace std; n void c() { n   int n; n   cin >> n; n   vector<long long> a(n); n   for (int(i) = (0); (i) < (n); ++(i)) cin >> a[i]; n   vector<long long> pf(n, a[0]); n   for (int(i) = (1); (i) < (n); ++(i)) pf[i] = pf[i - 1] ^ a[i]; n   map<long long, vector<pair<long long, long long>>> mp; n } n void b() { n   int n; n   cin >> n; n   vector<int> a(n); n   for (int(i) = (0); (i) < (n); ++(i)) cin >> a[i]; n   int sum = accumulate((a).begin(), (a).end(), 0); n   int best = sum; n   sort((a).begin(), (a).end()); n   for (int(r) = (1); (r) < (n); ++(r)) { n     sum -= a[r]; n     sum -= a[0]; n     for (int d = 1; d * d <= a[r]; d++) { n       if (a[r] % d == 0) { n         best = min(best, sum + a[r] / d + a[0] * d); n         best = min(best, sum + a[r] / (a[r] / d) + a[0] * (a[r] / d)); n       } n     } n     sum += a[r]; n     sum += a[0]; n   } n   cout << best; n } n int main() { n   b(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double mar[100000]; n int main() { n   double ml, rl; n   cin >> ml >> rl; n   double m = ml, r = rl; n   double save = 0; n   if (ml >= 3) n     save += 2 * m * (m - 3) + 2 * (m - 2) + 6; n   else if (ml == 2) n     save += 2; n   save *= (sqrt(2) - 2); n   double ans = m * (m + 1) + m * (m + 1) * (2 * m + 1) / 3 - 2 * (m); n   ans += save; n   ans *= r; n   ans /= (m * m); n   printf( %.10f n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   cin.tie(0); n   cout.tie(0); n   ios_base::sync_with_stdio(0); n   int n, x; n   cin >> n; n   vector<vector<int>> adj(n); n   for (int i = 1; i < n; i++) n     cin >> x, x--, adj[x].push_back(i), adj[i].push_back(x); n   queue<int> q; n   q.push(0); n   map<int, int> depth, count; n   depth[0] = 0; n   count[0]++; n   while (!q.empty()) { n     int cur = q.front(); n     q.pop(); n     for (auto nxt : adj[cur]) n       if (depth.find(nxt) == depth.end()) n         depth[nxt] = depth[cur] + 1, count[depth[nxt]]++, q.push(nxt); n   } n   int ret = 0; n   for (auto it : count) ret += it.second % 2; n   cout << ret << endl; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int i, j, n, k; n   while (scanf( %d %d , &n, &k) == 2) { n     int f, t, max = -2000000000; n     for (i = 0; i < n; i++) { n       scanf( %d %d , &f, &t); n       if (t > k) { n         if ((f - t + k) > max) max = f - t + k; n       } else { n         if (f > max) max = f; n       } n     } n     printf( %d n , max); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   for (int i = 1; i <= t; i++) { n     int n, k, d; n     cin >> n >> k >> d; n     int mn = n; n     int a[n + 10]; n     for (int j = 1; j <= n; j++) cin >> a[j]; n     for (int j = 1; j <= n - d + 1; j++) { n       set<int> s; n       for (int q = j; q <= j + d - 1; q++) s.insert(a[q]); n       int z = s.size(); n       mn = min(mn, z); n     } n     cout << mn <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a, b, numa, numb, ans; n   bool f = 0; n   cin >> n >> a >> b; n   for (int i = 2, cnt = 1; i <= n; i *= 2) { n     numa = a / i; n     if (a % i != 0) numa++; n     numb = b / i; n     if (b % i != 0) numb++; n     if (numa == numb) { n       if (i == n) f = 1; n       ans = cnt; n       break; n     } n     cnt++; n   } n   if (f == 1) n     cout <<  Final!  << endl; n   else n     cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long x[100005], y[112345]; n set<long long> stx, sty; n int main() { n   long long n, m, a, b; n   scanf( %lld %lld , &n, &m); n   long long total = n * n; n   while (m--) { n     scanf( %lld %lld , &a, &b); n     if (x[a] == 0 && y[b] == 0) { n       total = total - 2 * n + stx.size() + sty.size() + 1; n     } else if (x[a] && y[b] == 0) { n       total = total - n + stx.size(); n     } else if (y[b] && x[a] == 0) n       total = total - n + sty.size(); n     x[a] = y[b] = 1; n     stx.insert(a); n     sty.insert(b); n     printf( %lld  , total); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n; n double a[22][22], p[20][(1 << 18) + 10], pc[(1 << 18) + 10], n     sm[20][(1 << 18) + 10]; n int main() { n   while (scanf( %d , &n) != EOF) { n     for (int i = 0; i < n; i++) n       for (int j = 0; j < n; j++) { n         scanf( %lf , &a[i][j]); n       } n     memset(sm, 0, sizeof(sm)); n     for (int mask = 0; mask < (1 << n); mask++) { n       pc[mask] = 0.0; n       for (int bit = 0; bit < n; bit++) { n         if (mask & (1 << bit)) { n           pc[mask]++; n           for (int cara = 0; cara < n; cara++) { n             sm[cara][mask] += a[bit][cara]; n           } n         } n       } n     } n     for (int niv = 0; niv < n; niv++) { n       for (int mask = 0; mask < (1 << n); mask++) { n         if (niv == 0) { n           if (mask == ((1 << n) - 1)) { n             p[niv][mask] = 1.0; n           } else { n             p[niv][mask] = 0.0; n           } n         } else { n           double sum = 0.0; n           for (int bit = 0; bit < n; bit++) { n             if ((mask & (1 << bit)) == 0) { n               sum += p[niv - 1][mask | (1 << bit)] * sm[bit][mask]; n             } n           } n           p[niv][mask] = 2.0 * sum / (pc[mask] * (pc[mask] + 1)); n         } n       } n     } n     for (int i = 0; i < n; i++) { n       printf( %lf%c , p[n - 1][1 << i],    n [i == (n - 1)]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   cerr << name <<   :   << arg1 << std::endl; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cerr.write(names, comma - names) <<   :   << arg1 <<   |  ; n   __f(comma + 1, args...); n } n int main(void) { n   int n; n   scanf( %d , &n); n   int d; n   scanf( %d , &d); n   int h; n   scanf( %d , &h); n   if (d > 2 * h || d < h || (n > 2 && (d <= 1)) || (h < 1)) { n     cout <<  -1 n ; n     return 0; n   } else { n     int it = 1; n     int c = 0; n     while (it <= h) { n       cout << it <<     << it + 1 << endl; n       it++; n       c++; n     } n     if (d != h) { n       if (c < n - 1) { n         cout << 1 <<     << it + 1 << endl; n         c++; n         it += 1; n         d = d - h - 1; n         while (d > 0 && c < n - 1) { n           cout << it <<     << it + 1 << endl; n           it++; n           d--; n           c++; n         } n         while (c < n - 1) { n           cout << 1 <<     << it + 1 << endl; n           it++; n           c++; n         } n       } n     } else { n       if (c < n - 1) { n         cout << 2 <<     << it + 1 << endl; n         c++; n         it += 1; n         d = d - h - 1; n         while (d > 0 && c < n - 1) { n           cout << it <<     << it + 1 << endl; n           it++; n           d--; n           c++; n         } n         while (c < n - 1) { n           cout << 2 <<     << it + 1 << endl; n           it++; n           c++; n         } n       } n     } n   } n   return (0); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5005; n const long long INF = 1e18; n struct node { n   int u, v, w; n   node(int u = 0, int v = 0, int w = 0) : u(u), v(v), w(w) {} n } a[2 * N]; n int fst[N], nxt[2 * N], tot, n, size[N]; n bool vis[N]; n long long ans, sum[N], ans0, mn; n void build(int x, int y, int z) { n   a[tot] = node(x, y, z); n   nxt[tot] = fst[x]; n   fst[x] = tot++; n } n void calc(int x) { n   int y; n   size[x] = 1; n   for (int p = fst[x]; ~p; p = nxt[p]) { n     if (vis[p / 2]) continue; n     vis[p / 2] = 1; n     y = a[p].v; n     calc(y); n     size[x] += size[y]; n     ans += (long long)a[p].w * size[y] * (n - size[y]); n   } n } n void dfs1(int x) { n   int y; n   sum[x] = 0; n   size[x] = 1; n   for (int p = fst[x]; ~p; p = nxt[p]) { n     if (vis[p / 2]) continue; n     vis[p / 2] = 1; n     y = a[p].v; n     dfs1(y); n     sum[x] = (long long)sum[y] + (long long)size[y] * a[p].w; n     size[x] += size[y]; n   } n } n void dfs2(int x, int all) { n   int y; n   for (int p = fst[x]; ~p; p = nxt[p]) { n     if (vis[p / 2]) continue; n     vis[p / 2] = 1; n     y = a[p].v; n     sum[y] = sum[x] - (long long)size[y] * a[p].w + n              (long long)(all - size[y]) * a[p].w; n     mn = min(mn, sum[y]); n     dfs2(y, all); n   } n } n long long work(int x, int i) { n   for (int j = 0; j < n - 1; j++) vis[j] = i == j ? 1 : 0; n   dfs1(x); n   for (int j = 0; j < n - 1; j++) vis[j] = i == j ? 1 : 0; n   mn = sum[x]; n   dfs2(x, size[x]); n   return (long long)(mn - sum[x]) * (n - size[x]); n } n int main() { n   int x, y, z; n   scanf( %d , &n); n   tot = 0; n   memset(fst, -1, sizeof(fst)); n   for (int i = 0; i < n - 1; i++) { n     scanf( %d%d%d , &x, &y, &z); n     x--; n     y--; n     build(x, y, z); n     build(y, x, z); n   } n   ans = 0; n   calc(0); n   ans0 = ans; n   long long tmp; n   for (int i = 0; i < n - 1; i++) { n     tmp = ans0 + work(a[i * 2].u, i) + work(a[i * 2].v, i); n     ans = min(ans, tmp); n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n class DSU { n  public: n   vector<long long> p; n   DSU() {} n   DSU(long long n) { n     p.resize(n + 1); n     for (long long i = 1; i <= n; i++) p[i] = i; n   } n   void join(long long a, long long b) { p[find(b)] = find(a); } n   long long find(long long a) { return a == p[a] ? a : p[a] = find(p[a]); } n   bool check(long long a, long long b) { return find(a) == find(b); } n }; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long n, m; n   cin >> n >> m; n   DSU d(n); n   vector<DSU> D; n   for (long long i = 0; i <= m; i++) D.push_back(d); n   for (long long i = 0; i < m; i++) { n     long long u, v, c; n     cin >> u >> v >> c; n     D[c].join(u, v); n   } n   long long q; n   cin >> q; n   while (q--) { n     long long u, v; n     cin >> u >> v; n     long long ans = 0; n     for (long long i = 1; i <= m; i++) n       if (D[i].check(u, v)) ans++; n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 500004; n int a[N], m, k, s, t, n, sz = 0; n map<int, int> mp, mq; n void add(int n, int val) { n   if (n == -1) return; n   if (val == 1) { n     ++mq[n]; n     if (mq[n] == mp[n]) ++sz; n   } else { n     if (mq[n] == mp[n]) --sz; n     --mq[n]; n   } n } n int main() { n   scanf( %d %d %d %d , &m, &k, &n, &s); n   for (int i = 1; i <= m; i++) scanf( %d , &a[i]); n   for (int i = 1; i <= s; i++) { n     scanf( %d , &t); n     ++mp[t]; n   } n   for (int i = 1; i <= m; i++) n     if (!mp.count(a[i])) a[i] = -1; n   bool ok = 0; n   vector<int> v; n   for (int l = 1, r = 1; l <= m && !ok; l++) { n     for (; r <= m && sz < mp.size(); r++) add(a[r], 1); n     if (sz >= mp.size()) { n       if ((l - 1) / k + (m - r + 1) / k >= n - 1) { n         ok = 1; n         for (int i = l; i < r; i++) { n           if (a[i] != -1 && mp[a[i]] > 0) { n             --mp[a[i]]; n             a[i] = -2; n           } n         } n         for (int i = l; i < r; i++) { n           if (a[i] != -2 && (int)v.size() < r - l - k) v.push_back(i); n         } n         int cnt = (l - 1) % k; n         for (int i = 1; i <= cnt; i++) v.push_back(i); n       } n     } n     add(a[l], -1); n   } n   if (!ok) n     puts( -1 ); n   else { n     printf( %d n , v.size()); n     for (int x : v) printf( %d  , x); n   } n } n


#include <bits/stdc++.h> n using namespace std; n string s[] = { ABSINTH ,  BEER ,     BRANDY ,  CHAMPAGNE ,  GIN ,  RUM , n                SAKE ,     TEQUILA ,  VODKA ,   WHISKEY ,    WINE }; n int main() { n   int n; n   scanf( %d , &n); n   string ss; n   int sol = 0; n   for (int i = 0; i < n; i++) { n     cin >> ss; n     if (isalpha(ss[0])) { n       for (int j = 0; j < 11; j++) n         if (ss == s[j]) { n           sol++; n           break; n         } n     } else { n       int age = 0; n       for (int j = 0; j < ss.length(); j++) { n         age *= 10; n         age += (ss[j] -  0 ); n       } n       if (age < 18) sol++; n     } n   } n   printf( %d n , sol); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma comment(linker,  /STACK:102400000,102400000 ) n const int N = 100005; n long long ans; n int n, a[N], pi; n vector<int> G[N]; n int s[2], flag, cnt[2]; n map<int, int> mp[2]; n void upd(int u, int dep) { n   if ((dep % 2) != (flag % 2)) { n     s[flag ^ 1] ^= a[u]; n     mp[flag ^ 1][a[u]]++; n     ++cnt[flag ^ 1]; n   } else { n     s[flag] ^= a[u]; n     mp[flag][a[u]]++; n     ++cnt[flag]; n   } n } n void dfs(int u, int fa, int dep) { n   if (G[u].size() == 1 && u != 1) { n     if ((dep & 1) && flag == 0) flag ^= 1; n   } n   for (auto to : G[u]) n     if (to != fa) dfs(to, u, dep + 1); n   upd(u, dep); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); n   for (int i = 2; i <= n; ++i) { n     scanf( %d , &pi); n     G[pi].push_back(i); n     G[i].push_back(pi); n   } n   dfs(1, 0, 0); n   if (s[flag] == 0) { n     if (cnt[flag] > 1) ans += 1LL * cnt[flag] * (cnt[flag] - 1) / 2; n     if (cnt[flag ^ 1] > 1) ans += 1LL * cnt[flag ^ 1] * (cnt[flag ^ 1] - 1) / 2; n     for (auto it = mp[flag].begin(); it != mp[flag].end(); ++it) { n       int tmp1 = it->first, tmp2 = it->second, tmp3 = mp[flag ^ 1][tmp1]; n       ans += 1LL * tmp2 * tmp3; n     } n   } else { n     for (auto it = mp[flag].begin(); it != mp[flag].end(); ++it) { n       int tmp1 = it->first, tmp2 = it->second, n           tmp3 = mp[flag ^ 1][s[flag] ^ tmp1]; n       ans += 1LL * tmp2 * tmp3; n     } n   } n   printf( %lld n , ans); n   return 0; n } n