#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 10; n const long long mm = 1e9 + 7; n int ch[maxn][27], fail[maxn]; n long long cnt[maxn]; n long long s[maxn], len[maxn]; n int slink[maxn]; n int dif[maxn]; n char sp[maxn]; n long long g[maxn]; n int last, sz, n; n int newnode(int x) { n   for (int i = 0; i < 26; ++i) { n     ch[sz][i] = 0; n   } n   cnt[sz] = 0; n   len[sz] = x; n   return sz++; n } n void init() { n   sz = 0; n   newnode(0); n   newnode(-1); n   last = 0, n = 0; n   fail[0] = 1; n   fail[1] = 0; n   s[0] = -1; n } n int getfail(int u) { n   while (s[n - len[u] - 1] != s[n]) u = fail[u]; n   return u; n } n int pos[maxn]; n void add(int c) { n   s[++n] = c; n   int u = getfail(last); n   if (!ch[u][c]) { n     int np = newnode(len[u] + 2); n     fail[np] = ch[getfail(fail[u])][c]; n     ch[u][c] = np; n     dif[np] = len[np] - len[fail[np]]; n     if (dif[np] == dif[fail[np]]) { n       slink[np] = slink[fail[np]]; n     } else n       slink[np] = fail[np]; n   } n   last = ch[u][c]; n   pos[last] = n; n   cnt[last]++; n } n void count() { n   for (int i = sz - 1; i >= 0; --i) { n     cnt[fail[i]] += cnt[i]; n   } n } n long long dp[maxn]; n char dsp[maxn]; n int main() { n   init(); n   dsp[0] =  a ; n   scanf( %s , dsp + 1); n   int le = strlen(dsp + 1); n   int j = 0; n   for (int i = 1; i <= le; ++i) { n     sp[++j] = dsp[i]; n     sp[++j] = dsp[le - i + 1]; n   } n   dp[0] = 1; n   for (int i = 1; i <= le; ++i) { n     add(sp[i] -  a ); n     for (int j = last; j >= 2; j = slink[j]) { n       g[j] = dp[i - len[slink[j]] - dif[j]]; n       if (dif[j] == dif[fail[j]]) g[j] = (g[j] % mm + g[fail[j]] % mm) % mm; n       if (i % 2 == 0) dp[i] = (dp[i] % mm + g[j] % mm) % mm; n     } n   } n   cout << dp[n] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<vector<long long>> a; n   bool tr = true; n   for (long long l, r, i = 0; i < n; i++) { n     cin >> l >> r; n     a.push_back({l, r}); n   } n   sort(a.begin(), a.end(), n        [](const vector<long long>& a, const vector<long long>& b) -> bool { n          if (a[0] == b[0]) { n            return a[1] < b[1]; n          } else { n            return a[0] < b[0]; n          } n        }); n   long long f = -1, s = -1; n   for (long long i = 0; i < n; i++) { n     if (tr && a[i][0] > f) { n       f = a[i][1]; n     } else if (tr && a[i][0] > s) { n       s = a[i][1]; n     } else { n       tr = false; n     } n   } n   if (tr) { n     cout <<  YES  << endl; n   } else { n     cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long cdiv(long long a, long long b) { n   return a / b + ((a ^ b) > 0 && a % b); n } n long long fdiv(long long a, long long b) { n   return a / b - ((a ^ b) < 0 && a % b); n } n void solve() { n   long long int n; n   cin >> n; n   vector<long long int> v(n); n   map<long long int, long long int> mp; n   for (long long int i = 0; i < n; i++) { n     long long int x; n     cin >> x; n     v[i] = x % 3; n     mp[v[i]]++; n   } n   long long int ans = mp[0]; n   long long int c = min(mp[1], mp[2]); n   ans = ans + c; n   mp[1] = mp[1] - c; n   mp[2] = mp[2] - c; n   ans = ans + mp[1] / 3 + mp[2] / 3; n   cout << ans; n   cout << endl; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int t = 1; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100005; n int a[N]; n int main() { n   int n; n   long long sum = 0; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     sum += a[i] - 1; n     if (sum % 2 == 1) n       printf( 1 n ); n     else n       printf( 2 n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int OO = 1e8 + 10; n const int MOD = 1e9 + 7; n const int MAX = 2e5 + 1; n const double EPS = (1e-9); n map<int, bool> mp; n int main() { n   int n, x, y, l, last, ans; n   bool f1 = 0, f2 = 0, f3 = 0; n   cin >> n >> l >> x >> y; n   for (int i = 0; i < n; i++) { n     int a; n     cin >> a; n     mp[a] = 1; n   } n   for (auto it = mp.begin(); it != mp.end(); it++) { n     if (mp.count(it->first + (x - y)) && it->first + x <= l) n       f3 = 1, ans = it->first + x; n     if (mp.count(it->first - (x - y)) && it->first - x >= 0) n       f3 = 1, ans = it->first - x; n     if (mp.count(it->first + x + y)) f3 = 1, ans = it->first + x; n     if (mp.count(it->first + x)) f1 = 1; n     if (mp.count(it->first + y)) f2 = 1; n   } n   if (f1 && f2) return cout <<  0 n , 0; n   if (f3) return cout <<  1 n  << ans <<   n , 0; n   if (f1) return cout <<  1 n  << y <<   n , 0; n   if (f2) return cout <<  1 n  << x <<   n , 0; n   return cout <<  2 n  << x <<     << y <<   n , 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 100; n int vis[N]; n int p[N]; n int sum[N]; n int main() { n   int t = 0; n   for (int i = 2; i <= 1000010; i++) { n     if (vis[i] == 0) p[++t] = i; n     for (int j = 1; j <= t && (i * p[j] <= 1000010); j++) { n       vis[i * p[j]] = 1; n       if (i % p[j] == 0) { n         break; n       } n     } n   } n   for (int i = 1; i <= 1000010; i++) { n     if (vis[i] == 0) { n       sum[i] = 1 + sum[i - 1]; n     } else { n       sum[i] = sum[i - 1]; n     } n   } n   int k; n   scanf( %d , &k); n   while (k--) { n     double n; n     scanf( %lf , &n); n     int q = (int)n; n     int w = (int)sqrt(n); n     printf( %d n , sum[q] - sum[w] + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[110000], b[110000]; n struct Node { n   int a, b; n } node[110000]; n int main() { n   int i, j, h; n   int n, m, T; n   int cas = 1; n   int x, y; n   while (scanf( %d%d%d%d , &n, &m, &x, &y) != EOF) { n     for (i = 1; i <= n; i++) { n       scanf( %d , &a[i]); n     } n     for (j = 1; j <= m; j++) { n       scanf( %d , &b[j]); n     } n     int k = 0; n     for (i = 1, j = 1; i <= n && j <= m; i++) { n       if (b[j] - y > a[i]) continue; n       while (b[j] + x < a[i] && j <= m) { n         j++; n       } n       if (j > m) break; n       if (b[j] - y <= a[i]) { n         k++; n         node[k].a = i; n         node[k].b = j; n         j++; n       } n     } n     printf( %d n , k); n     for (i = 1; i <= k; i++) { n       printf( %d %d n , node[i].a, node[i].b); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n const long long N = 2e5 + 5; n const long long INF = (1LL << 62); n const long double pi = 3.14159265359; n void SRAND() { n   auto duration = std::chrono::system_clock::now().time_since_epoch(); n   auto millis = n       std::chrono::duration_cast<std::chrono::milliseconds>(duration).count(); n   srand(millis); n } n long long n, k, u[N], p[N], ans, x, y; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> k; n   for (long long i = 1; i <= n; i++) cin >> u[i]; n   for (long long i = n; i >= 1; i--) { n     p[i] = (u[i] == 1 ? p[i + 1] + 1 : 0); n   } n   for (long long i = 1; i <= n; i++) { n     x = u[i]; n     y = u[i]; n     if (x == y * k) ans++; n     for (long long j = i + 1; j <= n; j++) { n       if (u[j] == 1) { n         if (x % k == 0 && (x - k * y) / k >= 1 && (x - k * y) / k <= p[j]) n           ans++; n         y += p[j]; n         j += p[j] - 1; n         continue; n       } n       if (x >= INF / u[j]) break; n       x *= u[j]; n       y += u[j]; n       if (x == y * k) ans++; n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> Ans; n int N, M, K; n struct Edge { n   int u, v, w, id; n } e1[100005], e2[100005]; n int M1, M2; n bool Comparew(Edge a, Edge b) { n   if (a.w == b.w) { n     if (a.u == 1 || a.v == 1) n       return 1; n     else n       return 0; n   } else { n     if (a.w < b.w) n       return 1; n     else n       return 0; n   } n } n int parent[100005]; n int Find(int x) { n   if (parent[x] < 0) n     return x; n   else n     parent[x] = Find(parent[x]); n   return parent[x]; n } n int check; n bool Union(int x1, int x2) { n   x2 = x2; n   x1 = Find(x1); n   x2 = Find(x2); n   x1 = x1; n   if (x1 == x2) return 0; n   if (parent[x1] > parent[x2]) { n     int c = x1; n     x1 = x2; n     x2 = c; n   } n   x1 = x1; n   parent[x1] += parent[x2]; n   x2 = x2; n   parent[x2] = x1; n   return 1; n } n bool F = true; n int mid; n int k; n bool mark[100005]; n int s[100005]; n void Solve() { n   for (int i = 0; i < N + 1; i++) parent[i] = -1; n   for (int i = 0; i < N + 1; i++) mark[i] = 0; n   int count = N - 1, l1 = 0, l2 = 0; n   k = 0; n   while ((count && F) && (M1 > l1 || M2 > l2)) { n     if (M1 > l1 && (!(l2 ^ M2) || e1[l1].w + mid < e2[l2].w) && F) { n       if (Union(e1[l1].u, e1[l1].v)) { n         count--; n         F = true; n         k++; n         F = false; n         mark[e1[l1].id] = 1; n         F = true; n       } n       l1++; n     } else if (M2 > l2 && (!(l1 ^ M1) || e1[l1].w + mid >= e2[l2].w)) { n       if (Union(e2[l2].u, e2[l2].v)) { n         l1++; n         count--; n         l1--; n       } n       l2++; n     } n   } n   if (count && F) { n     cout <<  -1  << endl; n     exit(0); n   } n } n void Imps() { n   for (int i = 0; i < N + 1; i++) parent[i] = -1; n   int count = N - 1, l1 = 0, l2 = 0; n   while (count && F && (M1 > l1 || M2 > l2)) { n     if (M1 > l1 && M2 > l2 && F && e1[l1].w + mid == e2[l2].w && check && F && n         !mark[e1[l1].id]) { n       if (Union(e1[l1].u, e1[l1].v)) { n         l2++; n         s[count--] = e1[l1].id; n         l2--; n         check--; n       } n       l1++; n     } else if (F && M1 > l1 && (!(l2 ^ M2) || e1[l1].w + mid < e2[l2].w)) { n       if (Union(e1[l1].u, e1[l1].v)) { n         l2++; n         s[count--] = e1[l1].id; n         l2--; n       } n       l1++; n     } else if (M2 > l2 && (l1 == M1 || e1[l1].w + mid >= e2[l2].w)) { n       if (Union(e2[l2].u, e2[l2].v)) { n         l1--; n         s[count--] = e2[l2].id; n         l1++; n       } n       l2++; n     } n   } n } n int main() { n   scanf( %d%d%d , &N, &M, &K); n   if (N == 1) { n     if (K) n       cout <<  -1  << endl; n     else n       cout <<  0  << endl; n     return 0; n   } n   int chek = 0; n   if (!K || chek || K >= N) { n     cout <<  -1  << endl; n     return 0; n   } n   M1 = 0; n   chek++; n   M2 = 0; n   for (int i = 1; i <= M; i++) { n     int fr, to, we; n     cin >> fr >> to >> we; n     Ans.push_back(we); n     if (fr > to) { n       int temp = fr; n       fr = to; n       to = temp; n     } n     if (fr == 1 && F) { n       e1[M1].u = fr; n       e1[M1].v = to; n       e1[M1].w = we; n       e1[M1].id = i; n       M1++; n     } else { n       e2[M2].u = fr; n       e2[M2].v = to; n       e2[M2].w = we; n       e2[M2].id = i; n       M2++; n     } n   } n   sort(e1, e1 + M1, Comparew); n   sort(e2, e2 + M2, Comparew); n   int lef = -1e5 - 1; n   int rit = 1e5 + 1; n   while (lef < rit) { n     mid = lef + rit >> 1; n     Solve(); n     if (k <= K) { n       lef++; n       rit = mid; n       lef--; n     } else { n       rit++; n       lef = mid + 1; n       rit--; n     } n   } n   mid = lef; n   if (F) { n     check = 0; n   } n   Solve(); n   check = K - k; n   Imps(); n   if (check && F && (lef == -1e5 - 1 || rit == 1e5 + 1)) { n     cout <<  -1  << endl; n     return 0; n   } n   cout << N - 1 << endl; n   for (int i = 1; i < N; i++) cout << s[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long f(vector<int> x, int k) { n   long long ret = 0; n   sort(x.begin(), x.end()); n   for (int i = x.size() - 1; i >= 0; i -= k) { n     ret += x[i] * 2; n   } n   return ret; n } n void solve() { n   int n, k, mx = 0; n   cin >> n >> k; n   vector<int> x(n), a, b; n   for (int i = 0; i < n; i++) { n     cin >> x[i]; n     mx = max(mx, abs(x[i])); n     if (x[i] < 0) n       a.push_back(-x[i]); n     else n       b.push_back(x[i]); n   } n   cout << f(a, k) + f(b, k) - mx << endl; n } n int main() { n   int tt = 1; n   cin >> tt; n   while (tt--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n struct cube { n   int ind, val, h; n }; n int rcount[101]; n int compare1(cube a, cube b) { return a.val < b.val; } n int compare2(cube a, cube b) { return a.ind < b.ind; } n int main() { n   int n; n   scanf( %d , &n); n   vector<cube> v; n   vector<int> one, two; n   for (int i = 0; i < n * 2; i++) { n     cube c; n     c.ind = i; n     c.h = 0; n     scanf( %d , &c.val); n     v.push_back(c); n   } n   sort(v.begin(), v.end(), compare1); n   int size1 = 0, size2 = 0, color = 1, repeat = 0, repeatcount = 0; n   for (int i = 0; i < n * 2; i++) { n     v[i].h = 0; n     if (repeatcount >= 2 && repeat == v[i].val) n       rcount[v[i].val]++; n     else { n       if (repeat == v[i].val) n         repeatcount++; n       else n         repeatcount = 1; n       repeat = v[i].val; n       color *= -1; n       v[i].h = color; n       if (color < 0) n         size1++; n       else n         size2++; n     } n   } n   printf( %d n , size1 * size2); n   sort(v.begin(), v.end(), compare2); n   for (int i = 0; i < n * 2; i++) { n     if (v[i].h == 0) { n       if (size1 > size2) { n         v[i].h = 1; n         size2++; n       } else { n         v[i].h = -1; n         size1++; n       } n     } n     printf( %d  , (v[i].h < 0) ? 1 : 2); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int iinf = 1e9 + 7; n const long long linf = 1ll << 40; n const double dinf = 1e10; n void scf(int &x) { n   bool f = 0; n   x = 0; n   char c = getchar(); n   while ((c <  0  || c >  9 ) && c !=  - ) c = getchar(); n   if (c ==  - ) { n     f = 1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   if (f) x = -x; n   return; n } n void scf(int &x, int &y) { n   scf(x); n   return scf(y); n } n void scf(int &x, int &y, int &z) { n   scf(x); n   scf(y); n   return scf(z); n } n const int N = 2e5 + 1000; n const int Q = 3e5 + 1000; n int n; n long long a[N], dlt[2][N]; n inline long long MIN(long long a, long long b) { return a < b ? a : b; } n struct seg_tree { n   long long num[N << 2], lazy[N << 2]; n   inline int L(int i) { return i << 1; } n   inline int R(int i) { return (i << 1) | 1; } n   inline void update(int i) { n     num[i] = MIN(num[L(i)], num[R(i)]); n     return; n   } n   inline void push_down(int i) { n     if (lazy[i]) { n       int l = L(i), r = R(i); n       num[l] += lazy[i]; n       num[r] += lazy[i]; n       lazy[l] += lazy[i]; n       lazy[r] += lazy[i]; n       lazy[i] = 0; n     } n     return; n   } n   inline void modify(int a, int b, long long x, int l = 0, int r = N - 1, n                      int k = 1) { n     if (a == l && b == r) { n       num[k] += x; n       lazy[k] += x; n       return; n     } n     int mid = l + r >> 1; n     push_down(k); n     if (a > mid) n       modify(a, b, x, mid + 1, r, R(k)); n     else if (b <= mid) n       modify(a, b, x, l, mid, L(k)); n     else { n       modify(a, mid, x, l, mid, L(k)); n       modify(mid + 1, b, x, mid + 1, r, R(k)); n     } n     return update(k); n   } n   inline long long query(int a, int b, int l = 0, int r = N - 1, int k = 1) { n     if (a == l && b == r) return num[k]; n     int mid = l + r >> 1; n     push_down(k); n     if (a > mid) return query(a, b, mid + 1, r, R(k)); n     if (b <= mid) return query(a, b, l, mid, L(k)); n     return MIN(query(a, mid, l, mid, L(k)), n                query(mid + 1, b, mid + 1, r, R(k))); n   } n   inline void build(const bool &f, int l = 0, int r = N - 1, int k = 1) { n     if (l == r) { n       num[k] = dlt[f][l]; n       return; n     } n     int mid = l + r >> 1; n     build(f, l, mid, L(k)); n     build(f, mid + 1, r, R(k)); n     return update(k); n   } n   inline void builda(int l = 0, int r = N - 1, int k = 1) { n     if (l == r) { n       num[k] = (l >= 1 && l <= n) ? a[l] : linf; n       return; n     } n     int mid = l + r >> 1; n     builda(l, mid, L(k)); n     builda(mid + 1, r, R(k)); n     return update(k); n   } n } sta, st[2]; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < N; i++) dlt[0][i] = dlt[1][i] = linf; n   for (int i = 1; i <= n; i++) n     scanf( %I64d , a + i), dlt[i & 1][i] = a[i] - a[i - 1]; n   for (int i = 3; i <= n; i += 2) dlt[1][i] += dlt[1][i - 2]; n   for (int i = 4; i <= n; i += 2) dlt[0][i] += dlt[0][i - 2]; n   st[0].build(0); n   st[1].build(1); n   sta.builda(); n   int q; n   scanf( %d , &q); n   for (int i = 0; i < q; i++) { n     int op, l, r, l1, r1; n     scanf( %d%d%d , &op, &l, &r); n     l++; n     r++; n     l1 = l + 1; n     r1 = r + 1; n     bool L = l & 1, R = r & 1, L1 = l1 & 1, R1 = r1 & 1; n     if (op == 1) { n       long long x; n       scanf( %I64d , &x); n       sta.modify(l, r, x); n       st[L].modify(l, n, x); n       if (r < n) st[R1].modify(r1, n, -x); n       continue; n     } n     long long al = sta.query(l, l), ar = sta.query(r, r); n     if (!al || !ar) { n       puts( 0 ); n       continue; n     } n     if (!sta.query(l, r)) { n       puts( 0 ); n       continue; n     } n     if (l == r) { n       if (al != 1) n         puts( 0 ); n       else n         puts( 1 ); n       continue; n     } n     if (l + 1 == r) { n       if (al == ar) n         puts( 1 ); n       else n         puts( 0 ); n       continue; n     } n     st[L1].modify(l1, n, 1ll); n     st[R].modify(r, n, -1ll); n     r1 = r - 1; n     long long s1 = st[0].query(l1, r1), s2 = st[1].query(l1, r1); n     if (L1) n       s2 -= st[1].query(l - 1, l - 1), s1 -= st[0].query(l, l); n     else { n       if (l > 1) s1 -= st[0].query(l - 1, l - 1); n       s2 -= st[1].query(l, l); n     } n     if (L) n       s2 += al; n     else n       s1 += al; n     if (s1 <= 0 || s2 <= 0) n       puts( 0 ); n     else { n       long long t = st[R].query(r, r); n       if (R == L) n         t -= st[R].query(l, l); n       else if (l > 1) n         t -= st[R].query(l - 1, l - 1); n       if (L == R) t += al; n       if (!t) n         puts( 1 ); n       else n         puts( 0 ); n     } n     st[L1].modify(l1, n, -1ll); n     st[R].modify(r, n, 1ll); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( fast-math ) n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC diagnostic ignored  -Woverflow  n using namespace std; n const short INF16 = ~(1 << 15); n const int INF32 = 2e9 + 11; n const int SZ = 4e5 + 11; n const int SZ2 = int(1e6 + 11); n const int mod = 998244353; n const int mod2 = 998244353; n const int PIVO = 2e5 + 11; n const long long INF64 = 8e18; n const long long P1 = 53; n const long long P2 = 47; n const long double eps = 1e-10; n const long double PI = acosl(-1); n inline long long MOD(long long x) { n   x %= mod, x += mod; n   return x % mod; n } n inline long long MOD(long long x, long long m) { n   x %= m, x += m; n   return x % m; n } n inline long long T(int x) { return 1ll * x * (x + 1) >> 1; } n inline long long TT(int x) { return 1ll * x * (x + 1) * (x + 2) / 6; } n inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n inline long long lcm(long long a, long long b) { return a * b / gcd(a, b); } n long long fpow(long long a, long long b, long long mod) { n   if (!b) return 1; n   if (b == 1) return a % mod; n   if (b & 1) return fpow(a, b ^ 1, mod) * a % mod; n   long long d = fpow(a, b >> 1, mod); n   return d * d % mod; n } n long long fpow(long long a, long long b) { n   if (!b) return 1; n   if (b == 1) return a; n   if (b & 1) return fpow(a, b ^ 1) * a; n   long long d = fpow(a, b >> 1); n   return d * d; n } n void Solve(int num_test) { n   int n, m; n   cin >> n >> m; n   vector<int> a(n), b(m); n   vector<vector<int>> kek(n); n   for (int &i : a) cin >> i; n   for (int &i : b) cin >> i; n   for (int i = 0; i < n; i++) n     for (int j : b) kek[i].push_back(a[i] & j); n   for (int mask = 0; mask < (1 << 9); mask++) { n     bool ny = 1; n     for (int i = 0; i < n; i++) { n       bool loc = 0; n       for (int x : kek[i]) n         if ((mask | x) == mask) { n           loc = 1; n           break; n         } n       if (!loc) { n         ny = 0; n         break; n       } n     } n     if (ny) { n       cout << mask << endl; n       return; n     } n   } n } n signed main() { n   ios_base::sync_with_stdio(NULL); n   cin.tie(NULL); n   cout.tie(NULL); n   cout << fixed << setprecision(10); n   srand(time(NULL)); n   int test = 1; n   for (int i = 1; i <= test; i++) Solve(i); n } n


#include <bits/stdc++.h> n namespace chtholly { n char buf[1 << 23], *p1 = buf, *p2 = buf; n inline int read() { n   int x = 0, f = 1; n   char c = getchar(); n   for (; !isdigit(c); c = getchar()) f ^= c ==  - ; n   for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^  0 ); n   return f ? x : -x; n } n template <typename mitsuha> n inline bool read(mitsuha &x) { n   x = 0; n   int f = 1; n   char c = getchar(); n   for (; !isdigit(c) && ~c; c = getchar()) f ^= c ==  - ; n   if (!~c) return 0; n   for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^  0 ); n   return x = f ? x : -x, 1; n } n template <typename mitsuha> n inline int write(mitsuha x) { n   if (!x) return 0 & putchar(48); n   if (x < 0) putchar( - ), x = -x; n   int bit[20], i, p = 0; n   for (; x; x /= 10) bit[++p] = x % 10; n   for (i = p; i; --i) putchar(bit[i] + 48); n   return 0; n } n inline char fuhao() { n   char c = getchar(); n   for (; isspace(c); c = getchar()) n     ; n   return c; n } n }  // namespace chtholly n using namespace chtholly; n using namespace std; n const int yuzu = 2e5, mod = 1e9 + 7; n typedef long long rize[yuzu | 10]; n rize a[115], jic = {1}, inv; n namespace quick { n long long kasumi(long long a, long long b = mod - 2) { n   long long s = 1; n   for (; b; b >>= 1, a = a * a % mod) n     if (b & 1) s = s * a % mod; n   return s; n } n void add(long long &a, long long b) { n   if ((a += b) >= mod) a -= mod; n } n void sub(long long &a, long long b) { n   if ((a -= b) < 0) a += mod; n } n long long zuhe(int n, int m) { n   return jic[n] * inv[m] % mod * inv[n - m] % mod; n } n }  // namespace quick n using namespace quick; n void preget(int n, int i = 1) { n   for (; i <= n; ++i) jic[i] = jic[i - 1] * i % mod; n   inv[n] = kasumi(jic[n]); n   for (i = n - 1; ~i; --i) inv[i] = inv[i + 1] * (i + 1) % mod; n } n int main() { n   int i, j, n, m, l, r, k; n   read(n), read(m), preget(yuzu); n   static rize p; n   for (i = 1; i <= n; ++i) p[i] = read(); n   for (i = 1; i <= m; ++i) { n     l = read(), r = read(), k = read(); n     add(a[k][l], 1); n     for (j = 0; j <= k; ++j) sub(a[j][r + 1], zuhe(k - j + r - l, k - j)); n   } n   for (i = 100; ~i; --i) n     for (j = 1; j <= n; ++j) n       a[i][j] = (a[i][j] + a[i + 1][j] + a[i][j - 1]) % mod; n   for (i = 1; i <= n; ++i) write((a[0][i] + p[i]) % mod), putchar(   ); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 102; n int ar[maxn], ans; n int main() { n   int n; n   cin >> n; n   n = 2 * n; n   for (int i = 1; i <= n; i++) cin >> ar[i]; n   for (int i = 1; i <= n; i++) n     if (ar[i - 1] != ar[i] && ar[i + 1] != ar[i]) { n       int j = i + 1; n       while (ar[j] != ar[i] && j <= n) j++; n       for (int o = j; o > i + 1; o--) swap(ar[o], ar[o - 1]), ans++; n     } n   cout << ans << endl; 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   string s; n   cin >> s; n   char mn =  z ; n   for (auto c : s) { n     if (c <= mn) n       cout <<  Mike n ; n     else n       cout <<  Ann n ; n     mn = min(mn, c); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n int main() { n   scanf( %d %d , &n, &k); n   int w = 240 - k; n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     if (i * 5 <= w) { n       w -= i * 5; n       ans++; n     } n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int v[26]; n int main() { n   int n; n   int i; n   int j; n   scanf( %d , &n); n   char s[1005]; n   getchar(); n   gets(s); n   char t[30]; n   memset(v, 0, sizeof(v)); n   int len = strlen(s); n   if (len % n != 0) n     cout << -1 << endl; n   else { n     for (i = 0; i < len; i++) { n       v[s[i] -  a ]++; n     } n     for (i = 0; i < 26; i++) { n       if (v[i] % n != 0) break; n     } n     int pp = n; n     int kk; n     if (i == 26) { n       while (pp--) { n         for (i = 0; i < 26; i++) { n           if (v[i] != 0) { n             kk = v[i] / n; n             while (kk--) printf( %c , i +  a ); n           } n         } n       } n       cout << endl; n     } else n       cout << -1 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long arr[1001], ans; n string s; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> s; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] ==  0 ) arr[i]++; n   } n   cin >> s; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] ==  0 ) arr[i]++; n   } n   for (int i = 0; i < s.size(); i++) { n     if (arr[i] == 2) { n       if (arr[i + 1] > 0) { n         arr[i + 1]--; n         arr[i] = 0; n         ans++; n       } n     } else if (arr[i] == 1) { n       if (arr[i + 1] == 2) { n         arr[i + 1] = 0; n         arr[i] = 0; n         ans++; n       } n     } n   } n   printf( %I64d , ans); n } n


#include <bits/stdc++.h> n using namespace std; n string minEqui(string s) { n   int n = s.size(); n   if (n % 2 == 1) n     return s; n   else { n     string s1 = minEqui(s.substr(0, n / 2)), n            s2 = minEqui(s.substr(n / 2, n / 2)); n     if (s1 < s2) n       return s1 + s2; n     else n       return s2 + s1; n   } n } n int main() { n   string s1, s2; n   cin >> s1; n   cin >> s2; n   if (minEqui(s1) == minEqui(s2)) n     cout <<  YES n ; n   else n     cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> tamCopo; n priority_queue<pair<int, int> > ordemTam; n vector<int> volumeCha; n int main() { n   int i, j, k, aux; n   int n, w, volume; n   cin >> n >> w; n   volumeCha.assign(n, 0); n   volume = 0; n   for (i = 0; i < n; i++) { n     cin >> aux; n     if (aux % 2 == 0) { n       volume += aux / 2; n       volumeCha[i] = aux / 2; n     } else { n       volume += (aux + 1) / 2; n       volumeCha[i] = (aux + 1) / 2; n     } n     tamCopo.push_back(aux); n     ordemTam.push(make_pair(aux, i)); n   } n   if (w < volume) { n     cout << -1 << endl; n   } else { n     w -= volume; n     while (w > 0) { n       pair<int, int> copo = ordemTam.top(); n       ordemTam.pop(); n       if (w <= tamCopo[copo.second] / 2) { n         volumeCha[copo.second] += w; n         w = 0; n       } else { n         volumeCha[copo.second] = tamCopo[copo.second]; n         w -= tamCopo[copo.second] / 2; n       } n     } n     for (i = 0; i < volumeCha.size(); i++) cout << volumeCha[i] <<    ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int max(long long int x, long long int y) { n   if (x > y) return x; n   return y; n } n long long int min(long long int x, long long int y) { n   if (x < y) return x; n   return y; n } n long long int getSum(long long int n) { n   int sum; n   for (sum = 0; n > 0; sum += n % 10, n /= 10) n     ; n   return sum; n } n bool isPrime(long long int n) { n   if (n <= 1) return false; n   if (n <= 3) return true; n   if (n % 2 == 0 || n % 3 == 0) return false; n   for (int i = 5; i * i <= n; i = i + 6) n     if (n % i == 0 || n % (i + 2) == 0) return false; n   return true; n } n long long int gcd(long long int a, long long int b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n long long int lcm(long long int a, long long int b) { n   return (a * b) / gcd(a, b); n } n long long int two(long long int a, long long int b, long long int c) { n   long long int temp = 0; n   if (a % 2 == 1) temp++; n   if (b % 2 == 1) temp++; n   if (c % 2 == 1) temp++; n   if (temp == 2) n     return true; n   else n     return false; n } n int CF(const vector<int> &p) { n   int ans = 0; n   for (int i = 0; i < p.size(); i++) n     if (p[i] > 1) ans += p[i]; n   return ans; n } n long long int res = 1; n long long int power(long long int y) { n   if (y == 0) return 1; n   res *= 2; n   res %= 1000000007; n   return res; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int test = 1; n   while (test--) { n     long long int n, l, r; n     cin >> n >> l >> r; n     long long int s1 = 0, s2 = 0; n     for (int i = l - 1; i >= 0; i--) s1 += pow(2, i); n     if (n - l > 0) s1 += (n - l); n     cout << s1 <<    ; n     for (int i = r - 1; i >= 0; i--) s2 += pow(2, i); n     if (n - r > 0) s2 += (n - r) * pow(2, r - 1); n     cout << s2; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double distance(double v, double a, double t) { return v * t + a * t * t / 2; } n double time(double v, double a, double d) { n   return (-v + sqrt(v * v + 2 * a * d)) / a; n } n int main(int argc, char* argv[]) { n   cout.precision(16); n   double a, v, l, d, w; n   cin >> a >> v >> l >> d >> w; n   double t = 0; n   double p = (w * w + 2 * a * d) / (4 * a); n   if (p <= d) { n     if (sqrt(2 * p * a) <= v) n       t += sqrt(2 * p * a) / a + (sqrt(2 * p * a) - w) / a; n     else n       t += n           v / a + n           (d - distance(0, a, v / a) - distance(v, -a, max(0.0, (v - w) / a))) / n               v + n           max(0.0, (v - w) / a); n     if (d + distance(w, a, max(0.0, (v - w) / a)) < l) n       t += max(0.0, (v - w) / a) + n            (l - d - distance(w, a, max(0.0, (v - w) / a))) / v; n     else n       t += time(w, a, l - d); n   } else { n     if (distance(0, a, v / a) < l) n       t += v / a + (l - distance(0, a, v / a)) / v; n     else n       t += time(0, a, l); n   } n   cout << t << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200007, inf = 0x3f3f3f3f; n struct qu { n   int op, l, r; n }; n qu Q[N]; n int v[N]; n int main() { n   ios::sync_with_stdio(false); n   int n, q, m; n   cin >> n >> q >> m; n   for (int i = 1; i <= n; ++i) { n     cin >> v[i]; n   } n   for (int i = 0; i < q; ++i) { n     int a, b, c; n     cin >> a >> b >> c; n     Q[i] = {a, b, c}; n   } n   for (int i = 0; i < m; ++i) { n     int x; n     cin >> x; n     for (int j = q - 1; j >= 0; --j) { n       qu que = Q[j]; n       int l = que.l, r = que.r; n       if (que.op == 1 and x >= que.l and x <= que.r) { n         x = l + (x - l - 1 + (r - l + 1)) % (r - l + 1); n       } else if (que.op == 2 and x >= que.l and x <= que.r) { n         x = l + r - x; n       } n     } n     cout << v[x] <<    ; n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000 + 7; n int n; n char s[N]; n struct edge { n   int to, nex, wei; n } e[N << 1]; n int fir[N], eid; n int deg[N], dis[N]; n int fa[N]; n queue<int> q; n int getfa(int x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]); } n void addedge(int u, int v, int w) { n   e[++eid] = (edge){v, fir[u], w}; n   fir[u] = eid; n   ++deg[v]; n } n int main() { n   scanf( %d%s , &n, s + 1); n   for (int i = 1; i <= n; ++i) fa[i] = i; n   for (int i = 1; i < n; ++i) n     if (s[i] ==  = ) fa[getfa(i)] = getfa(i + 1); n   for (int i = 1; i < n; ++i) { n     if (s[i] ==  R ) addedge(getfa(i), getfa(i + 1), 1); n     if (s[i] ==  L ) addedge(getfa(i + 1), getfa(i), 1); n   } n   for (int i = 1; i <= n; ++i) { n     dis[i] = 1; n     if (deg[i] == 0) q.push(i); n   } n   while (!q.empty()) { n     int s = q.front(); n     q.pop(); n     for (int i = fir[s]; i; i = e[i].nex) { n       dis[e[i].to] = max(dis[e[i].to], dis[s] + e[i].wei); n       if (--deg[e[i].to] == 0) q.push(e[i].to); n     } n   } n   for (int i = 1; i <= n; ++i) printf( %d  , dis[getfa(i)]); n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n const int MAX_N = 2e5+5; n vector<long long> us[MAX_N]; n long long pres[MAX_N]; n long long res[MAX_N]; n int u[MAX_N]; n int s[MAX_N]; n bool cmp(long long &x, long long &y) n { n     return x > y; n } n int main() n { n     int t; n     cin>>t; n     // iostream::sync_with_stdio(false); n     while(t--) n     { n         int n, max_v = -1, pre_len; n         cin>>n; n         for(int i = 1; i <= n; i++) n         { n             cin>>u[i]; n             us[i].clear(); n             max_v = max(max_v, u[i]); n         } n         for(int i = 1; i <= n; i++)  n         { n             cin>>s[i]; n             res[i] = 0; n             us[u[i]].push_back(s[i]); n         } n         for(int i = 1; i <= max_v; i++) n         { n             pre_len = us[i].size(); n             sort(us[i].begin(), us[i].end(), cmp); n             for(int j = 0; j < pre_len; j++) n                 pres[j+1] = pres[j] + us[i][j]; n             for(int k = 1; k <= pre_len; k++) n                 res[k] += pres[pre_len/k * k]; n         } n         for(int k = 1; k <= n; k++) n             cout<<res[k]<<   ; n         cout<<endl; n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int _ = 1, tc = 1; n int dx[] = {0, 0, 1, -1}; n int dy[] = {1, -1, 0, 0}; n int getmod(int x, int y, int mod) { return (((x - y) % mod) + mod) % mod; } n int MAXN = 46341 + 1; n int spf[46341 + 1]; n int d, x, y; n int gcd(int a, int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n void sieve() { n   for (int i = 1; i < MAXN; i++) spf[i] = i; n   for (int i = 4; i < MAXN; i += 2) spf[i] = 2; n   for (int i = 3; i * i < MAXN; i += 2) { n     if (spf[i] == i) { n       for (int j = i * i; j < MAXN; j += i) { n         if (spf[j] == j) spf[j] = i; n       } n     } n   } n } n void extended_gcd(int a, int b) { n   if (b == 0) { n     d = a; n     x = 1; n     y = 0; n   } else { n     extended_gcd(b, a % b); n     int temp = y; n     y = x - y * (a / b); n     x = temp; n   } n } n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } n void solve() { n   long long n, m, s1, s2; n   cin >> n >> m >> s1 >> s2; n   cout << s1 <<     << s2 << endl; n   for (int i = 1; i <= m; i++) { n     if (i == s2) continue; n     cout << s1 <<     << i << endl; n   } n   int curr = m, new_curr = m; n   for (int i = s1 - 1; i >= 1; i--) { n     if (curr == m) { n       for (int j = m; j > 0; j--) { n         cout << i <<     << j << endl; n       } n       curr = 1; n     } else { n       for (int j = 1; j <= m; j++) { n         cout << i <<     << j << endl; n       } n       curr = m; n     } n   } n   for (int i = s1 + 1; i <= n; i++) { n     if (curr == m) { n       for (int j = m; j > 0; j--) { n         cout << i <<     << j << endl; n       } n       curr = 1; n     } else { n       for (int j = 1; j <= m; j++) { n         cout << i <<     << j << endl; n       } n       curr = m; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   while (_--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = 2.0 * acos(0.0); n const double E = exp(1); n int x[] = {0, 0, -1, 1}; n int y[] = {-1, 1, 0, 0}; n template <class T1> n void deb(T1 e) { n   cout << e << endl; n } n template <class T1, class T2> n void deb(T1 e1, T2 e2) { n   cout << e1 <<     << e2 << endl; n } n template <class T1, class T2, class T3> n void deb(T1 e1, T2 e2, T3 e3) { n   cout << e1 <<     << e2 <<     << e3 << endl; n } n template <class T1, class T2, class T3, class T4> n void deb(T1 e1, T2 e2, T3 e3, T4 e4) { n   cout << e1 <<     << e2 <<     << e3 <<     << e4 << endl; n } n template <class T1, class T2, class T3, class T4, class T5> n void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) { n   cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 << endl; n } n template <class T1, class T2, class T3, class T4, class T5, class T6> n void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) { n   cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 <<     << e6 n        << endl; n } n template <typename T> n inline T sqr(T n) { n   return n * n; n } n inline double hypot(double x, double y) { return sqrt(sqr(x) + sqr(y)); } n template <typename T> n inline T pmod(T n, T m) { n   return ((n % m) + m) % m; n } n template <typename T> n T power(T n, int p) { n   return (p == 0) ? (T)(1) : (sqr(power(n, p >> 1)) * ((p & 1) * (n - 1) + 1)); n } n template <typename T> n T bigmod(T n, int p, T m) { n   return (p == 0) n              ? (T)(1) n              : ((sqr(bigmod(n, p >> 1, m)) % m) * ((p & 1) * (n - 1) % m + 1)) % n                    m; n } n double dp[5005][5005]; n double p[5005]; n int t[5005]; n double pw[5005]; n int main() { n   int n, T; n   cin >> n >> T; n   for (int i = 1; i <= n; i++) { n     cin >> p[i] >> t[i]; n     p[i] /= 100.00; n     pw[i] = pow(1.00 - p[i], t[i]); n   } n   for (int i = n; i >= 1; i--) { n     for (int j = T; j >= 1; j--) { n       dp[i][j] = p[i] * (dp[i + 1][j + 1] + 1); n       double tmp = dp[i][j + 1] * (1.00 - p[i]); n       if (j + t[i] <= T + 1) tmp += pw[i] * (dp[i + 1][j + t[i]] + 1); n       if (j + t[i] + 1 <= T + 1) tmp -= pw[i] * (dp[i + 1][j + t[i] + 1] + 1); n       dp[i][j] += tmp; n     } n   } n   cout << setprecision(9) << dp[1][1] <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n long long MOD = 1000000007; n long double EPS = 1e-9; n long long binpow(long long b, long long p, long long mod) { n   long long ans = 1; n   b %= mod; n   for (; p; p >>= 1) { n     if (p & 1) ans = ans * b % mod; n     b = b * b % mod; n   } n   return ans; n } n void pre() {} n namespace GetPrimitve { n vector<long long> Divisors; n vector<long long> Divisor(long long x) { n   vector<long long> ans; n   for (long long i = 2; i * i <= x; i++) { n     if (x % i == 0) { n       ans.emplace_back(i); n       while (x % i == 0) x /= i; n     } n   } n   if (x > 1) ans.emplace_back(x); n   return ans; n } n bool check(int prim, int p, vector<long long> &divs) { n   for (auto v : divs) { n     if (binpow(prim, (p - 1) / v, p) == 1) return 0; n   } n   return 1; n } n int getRoot(int p) { n   int ans = 2; n   vector<long long> divs = Divisor(p - 1); n   while (!check(ans, p, divs)) ans++; n   return ans; n } n };  // namespace GetPrimitve n const long long MAXB = 1 << 21; n using polybase = long long; n polybase A[MAXB], B[MAXB], C[MAXB]; n template <long long NTTMOD, long long PRIMITIVE_ROOT> n struct POLYMUL { n   long long modInv(long long a) { n     return a <= 1 n                ? a n                : (long long)(NTTMOD - NTTMOD / a) * modInv(NTTMOD % a) % NTTMOD; n   } n   void NTT(polybase P[], long long n, long long oper) { n     for (int i = 1, j = 0; i < n - 1; i++) { n       for (int s = n; j ^= s >>= 1, ~j & s;) n         ; n       if (i < j) swap(P[i], P[j]); n     } n     for (int d = 0; (1 << d) < n; d++) { n       int m = 1 << d, m2 = m * 2; n       long long unit_p0 = ::binpow(PRIMITIVE_ROOT, (NTTMOD - 1) / m2, NTTMOD); n       if (oper < 0) unit_p0 = modInv(unit_p0); n       for (int i = 0; i < n; i += m2) { n         polybase unit = 1; n         for (int j = 0; j < m; j++) { n           polybase &P1 = P[i + j + m], &P2 = P[i + j]; n           polybase t = unit * P1 % NTTMOD; n           P1 = (P2 - t + NTTMOD) % NTTMOD; n           P2 = (P2 + t) % NTTMOD; n           unit = unit * unit_p0 % NTTMOD; n         } n       } n     } n   } n   vector<polybase> mul(const vector<polybase> &a, const vector<polybase> &b) { n     vector<polybase> ret( n         max(0LL, (long long)a.size() + (long long)b.size() - 1), 0); n     int len = 1; n     while (len < (long long)ret.size()) len <<= 1; n     for (int i = 0; i < len; i++) A[i] = i < (int)a.size() ? a[i] : 0; n     for (int i = 0; i < len; i++) B[i] = i < (int)b.size() ? b[i] : 0; n     NTT(A, len, 1); n     NTT(B, len, 1); n     for (long long i = 0; i < len; i++) C[i] = (polybase)A[i] * B[i] % NTTMOD; n     NTT(C, len, -1); n     for (long long i = 0, inv = modInv(len); i < (long long)ret.size(); i++) n       ret[i] = (long long)C[i] * inv % NTTMOD; n     return ret; n   } n   vector<long long> binpow(vector<long long> b, long long p) { n     vector<long long> ans = vector<long long>(1, 1); n     for (; p; p >>= 1) { n       if (p & 1) ans = mul(ans, b); n       b = mul(b, b); n     } n     return ans; n   } n   vector<long long> calc(vector<long long> &arr, int l, int r) { n     if (l == r) { n       return {}; n     } n     int mid = (l + r) >> 1; n     vector<long long> x = calc(arr, l, mid), y = calc(arr, mid + 1, r); n     return mul(x, y); n   } n }; n POLYMUL<998244353, 3> ntt1; n POLYMUL<943718401, 7> ntt2; n POLYMUL<950009857, 7> ntt3; n POLYMUL<962592769, 7> ntt4; n POLYMUL<975175681, 17> ntt5; n long long possible[1000100]; n long long lappos[1000100]; n void solve() { n   long long n, x, y; n   cin >> n >> x >> y; n   vector<long long> arr(n + 1); n   for (long long i = 0; i < (n + 1); ++i) { n     cin >> arr[i]; n   } n   vector<long long> arr2 = arr; n   for (long long i = 0; i < (n + 1); ++i) { n     arr2[i] = -arr2[i]; n     arr2[i] += x; n   } n   vector<long long> poly1(x + 1); n   vector<long long> poly2(x + 1); n   for (auto v : arr) { n     poly1[v] = 1; n   } n   for (auto v : arr2) { n     poly2[v] = 1; n   } n   vector<long long> pp1 = ntt2.mul(poly1, poly2); n   vector<long long> pp2 = ntt3.mul(poly1, poly2); n   for (long long i = x + 1; i <= 2 * x; ++i) { n     if (pp1[i] > 0 || pp2[i] > 0) { n       possible[i - x] = 1; n     } n   } n   assert(possible[x] == 1); n   memset(lappos, -1, sizeof(lappos)); n   for (long long i = 1; i <= 1000000; ++i) { n     if (possible[i]) { n       if (2 * (i + y) <= 1000000) { n         lappos[2 * (i + y)] = 2 * (i + y); n       } n     } n   } n   for (long long i = 1; i <= 1000000; ++i) { n     for (long long j = 2 * i; j <= 1000000; j += i) { n       (lappos[j] = max((lappos[j]), (lappos[i]))); n     } n   } n   long long q; n   cin >> q; n   for (long long i = 0; i < (q); ++i) { n     long long x; n     cin >> x; n     cout << lappos[x] <<    ; n   } n   cout <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   pre(); n   long long _t = 1; n   srand(time(0)); n   for (long long i = 1; i <= _t; i++) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n bool arr[3001]; n int main() { n   int n, i, input; n   cin >> n; n   for (i = 1; i <= n; i++) { n     cin >> input; n     arr[input] = true; n   } n   for (i = 1; i <= 3000; i++) { n     if (!arr[i]) { n       cout << i << endl; n       return 0; n     } n   } n   cout << 3001 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long c[100001]; n void init() { n   long long n, x; n   long long ans = 0; n   cin >> n >> x; n   for (int i = 0; i < n; i++) cin >> c[i]; n   sort(c, c + n); n   for (int i = 0; i < n; i++) { n     ans += c[i] * x; n     if (x > 1) x--; n   } n   cout << ans << endl; n } n int main() { n   init(); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n int cnt[200005]; n int n, m, k; n vector<unsigned long long> polys[200005]; n struct cmp { n   bool operator()(int a, int b) const { n     return polys[a].size() > polys[b].size(); n   } n }; n priority_queue<int, vector<int>, cmp> q; n const int NMAX = 1 << 19; n const double PI = 2 * acos(0.0); n struct FFT { n   vector<int> rev; n   vector<complex<double> > omega, oinv; n   int K, N; n   FFT(int k) { n     K = k; n     N = 1 << k; n     rev.resize(N); n     omega.resize(N); n     oinv.resize(N); n     for (int i = 0; i < (N); i++) { n       rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (K - 1)); n       omega[i] = polar(1.0, 2.0 * PI / N * i); n       oinv[i] = conj(omega[i]); n     } n   } n   void dft(complex<double>* a, vector<complex<double> >& w) { n     for (int i = 0; i < (N); i++) n       if (i < rev[i]) swap(a[i], a[rev[i]]); n     for (int l = 2; l <= N; l *= 2) { n       int m = l / 2; n       for (complex<double>* p = a; p != a + N; p += l) n         for (int k = 0; k < (m); k++) { n           complex<double> t = w[N / l * k] * p[k + m]; n           p[k + m] = p[k] - t; n           p[k] += t; n         } n     } n   } n   void fft(complex<double>* a) { dft(a, omega); } n   void ifft(complex<double>* a) { n     dft(a, oinv); n     for (int i = 0; i < (N); i++) a[i] /= N; n   } n   void conv(complex<double>* a, complex<double>* b) { n     fft(a); n     fft(b); n     for (int i = 0; i < (N); i++) a[i] *= b[i]; n     ifft(a); n   } n }; n vector<FFT> fft; n int roundup(int x) { n   while (x & (x - 1)) x += x & (-x); n   return x; n } n void mul(vector<unsigned long long>& a, vector<unsigned long long>& b) { n   int maxsz = a.size() + b.size(); n   int sz = roundup(maxsz); n   a.resize(sz); n   b.resize(sz); n   static complex<double> aa[1 << 20], bb[1 << 20]; n   for (int i = 0; i < sz; i++) { n     aa[i] = a[i]; n     bb[i] = b[i]; n   } n   fft[__builtin_ctz(sz) - 1].conv(aa, bb); n   a.resize(maxsz); n   for (int i = 0; i < maxsz; i++) { n     a[i] = real(aa[i]) + 0.5; n     a[i] %= 1009; n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   for (int i = 1; i <= 19; i++) fft.push_back(FFT(i)); n   cin >> n >> m >> k; n   for (int i = 0; i < (n); i++) { n     int v; n     cin >> v; n     cnt[v]++; n   } n   for (int i = 1; i <= (m); i++) { n     if (cnt[i]) { n       polys[i].resize(cnt[i] + 1); n       fill((polys[i]).begin(), (polys[i]).end(), 1); n       q.push(i); n     } n   } n   while (q.size() > 1) { n     int a = q.top(); n     q.pop(); n     int b = q.top(); n     q.pop(); n     mul(polys[a], polys[b]); n     q.push(a); n   } n   vector<unsigned long long>& res = polys[q.top()]; n   cout << res[k] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1e9 + 7; n int n, k, maxn = 2000000001; n int b[100001]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> k; n   for (int i = 0; i < k; i++) { n     int r = (n - (k - i) * (k - i - 1) / 2) / (k - i); n     if (r <= 0) { n       cout <<  NO ; n       return 0; n     } n     if (r > maxn) { n       b[i] = maxn; n       n -= maxn; n       maxn = maxn * 2; n     } else { n       b[i] = r; n       n -= r; n       maxn = r * 2; n     } n     if (i == k - 1 && n != 0) { n       cout <<  NO ; n       return 0; n     } n   } n   cout <<  YES  << endl; n   for (int i = 0; i < k; i++) cout << b[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int x, y; n } fei1[60], fei2[60]; n int _hash[5100]; n int main() { n   int p, q, l, r, i, t, j, x, k; n   scanf( %d%d%d%d , &p, &q, &l, &r); n   for (i = 0; i < p; i++) { n     scanf( %d%d , &fei1[i].x, &fei1[i].y); n   } n   for (i = 0; i < q; i++) { n     scanf( %d%d , &fei2[i].x, &fei2[i].y); n   } n   x = 0; n   for (i = l; i <= r; i++) { n     memset(_hash, 0, sizeof(_hash)); n     for (j = 0; j < p; j++) { n       for (k = fei1[j].x; k <= fei1[j].y; k++) { n         _hash[k] = 1; n       } n     } n     int flag = 0; n     for (j = 0; j < q; j++) { n       for (k = fei2[j].x + i; k <= fei2[j].y + i; k++) { n         if (_hash[k]) { n           flag = 1; n           break; n         } n       } n       if (flag) break; n     } n     if (flag) { n       x++; n     } n   } n   printf( %d n , x); n   return 0; n } n


#include <bits/stdc++.h> n int n; n char dir[1010]; n int len[1010]; n int realx[2030], cntx = 0; n int realy[2030], cnty = 0; n void unique(int *real, int &cnt) { n   std::sort(real, real + cnt); n   int t2 = 1; n   for (int t1 = 1; t1 < cnt; t1++) n     if (real[t1] ^ real[t1 - 1]) real[t2++] = real[t1]; n   cnt = t2; n } n int map[2030][2030]; n inline bool legal(int x, int y) { n   return x >= 0 && x <= cntx && y >= 0 && y <= cnty; n } n void dfs(int x, int y) { n   map[x][y] = -1; n   if (legal(x + 1, y) && !map[x + 1][y]) dfs(x + 1, y); n   if (legal(x - 1, y) && !map[x - 1][y]) dfs(x - 1, y); n   if (legal(x, y + 1) && !map[x][y + 1]) dfs(x, y + 1); n   if (legal(x, y - 1) && !map[x][y - 1]) dfs(x, y - 1); n } n int main() { n   scanf( %d , &n); n   int curx = 0, cury = 0; n   for (int i = 0; i < n; i++) { n     scanf( %s%d , dir + i, len + i); n     switch (dir[i]) { n       case  L : n         realx[cntx++] = curx + 1; n         realx[cntx++] = curx -= len[i]; n         realy[cnty++] = cury; n         realy[cnty++] = cury + 1; n         break; n       case  R : n         realx[cntx++] = curx; n         realx[cntx++] = (curx += len[i]) + 1; n         realy[cnty++] = cury; n         realy[cnty++] = cury + 1; n         break; n       case  U : n         realy[cnty++] = cury; n         realy[cnty++] = (cury += len[i]) + 1; n         realx[cntx++] = curx; n         realx[cntx++] = curx + 1; n         break; n       case  D : n         realy[cnty++] = cury + 1; n         realy[cnty++] = cury -= len[i]; n         realx[cntx++] = curx; n         realx[cntx++] = curx + 1; n         break; n     } n   } n   unique(realx, cntx); n   unique(realy, cnty); n   int curxid = std::upper_bound(realx, realx + cntx, curx = 0) - realx, n       curyid = std::upper_bound(realy, realy + cnty, cury = 0) - realy, nextid; n   for (int i = 0; i < n; i++) switch (dir[i]) { n       case  L : n         nextid = std::upper_bound(realx, realx + cntx, curx -= len[i]) - realx; n         for (; curxid > nextid; curxid--) map[curxid][curyid] = 1; n         break; n       case  R : n         nextid = std::upper_bound(realx, realx + cntx, curx += len[i]) - realx; n         for (; curxid < nextid; curxid++) map[curxid][curyid] = 1; n         break; n       case  U : n         nextid = std::upper_bound(realy, realy + cnty, cury += len[i]) - realy; n         for (; curyid < nextid; curyid++) map[curxid][curyid] = 1; n         break; n       case  D : n         nextid = std::upper_bound(realy, realy + cnty, cury -= len[i]) - realy; n         for (; curyid > nextid; curyid--) map[curxid][curyid] = 1; n         break; n     } n   map[curxid][curyid] = 1; n   for (int x = 0; x <= cntx; x++) { n     if (!map[x][0]) dfs(x, 0); n     if (!map[x][cnty]) dfs(x, cnty); n   } n   for (int y = 1; y < cnty; y++) { n     if (!map[0][y]) dfs(0, y); n     if (!map[cntx][y]) dfs(cntx, y); n   } n   long long ans = 0; n   for (int x = 1; x <= cntx; x++) n     for (int y = 1; y <= cnty; y++) n       if (~map[x][y]) n         ans += (long long)(realx[x] - realx[x - 1]) * (realy[y] - realy[y - 1]); n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e7; n long long int a[N], ans; n int main() { n   long long int n; n   cin >> n; n   long long int l = 0, r = n - 1; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   sort(a, a + n); n   for (int i = 0; i < n / 2; i++) { n     ans += (a[l] + a[r]) * (a[l] + a[r]); n     r--, l++; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, aa, bb; n   cin >> a >> b >> aa >> bb; n   if (aa <= bb) aa = bb + 1; n   vector<pair<int, int> > ans; n   if (aa > a) { n     cout << 0; n     return 0; n   } else { n     for (int i = bb; i <= b; i++) n       for (int j = (aa > i + 1 ? aa : i + 1); j <= a; j++) { n         ans.push_back(make_pair(j, i)); n       } n   } n   sort(ans.begin(), ans.end()); n   cout << ans.size() << endl; n   for (int i = 0; i < ans.size(); i++) n     cout << ans[i].first <<     << ans[i].second <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 10005; n short dp[MAXN][MAXN]; n int32_t main() { n   ios::sync_with_stdio(false); n   string s, t; n   cin >> s >> t; n   dp[0][0] = 0; n   int n = s.size(), m = t.size(); n   for (int i = 0; i <= n + 3; i++) n     for (int j = 0; j <= m + 3; j++) dp[i][j] = MAXN; n   dp[0][0] = 0; n   vector<int> prv(n + 1, -1); n   vector<int> wh(2 * n + 1, -1); n   wh[n] = 0; n   for (int i = 1, v = 0; i <= n; i++) { n     v += (s[i - 1] ==  .  ? -1 : 1); n     if (s[i - 1] ==  .  && wh[v + n] != -1) prv[i] = wh[v + n]; n     wh[v + n] = i; n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j <= m; j++) { n       if (j > 0 && s[i - 1] == t[j - 1]) dp[i][j] = dp[i - 1][j - 1]; n       if (s[i - 1] ==  . ) dp[i][j] = dp[i - 1][j + 1]; n       dp[i][j] = min(dp[i][j], (short)(dp[i - 1][j] + 1)); n       if (prv[i] != -1) dp[i][j] = min(dp[i][j], dp[prv[i]][j]); n     } n   } n   cout << dp[n][m] <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = (int)1.01e9; n const long long infll = (long long)1.01e18; n const long double eps = 1e-9; n const long double pi = acos((long double)-1); n mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); n int rnd(int x) { return mrand() % x; } n void precalc() {} n const int maxn = (int)1e5 + 5; n int n, m; n vector<int> g[maxn]; n bool read() { n   if (scanf( %d%d , &n, &m) < 2) { n     return false; n   } n   for (int i = 0; i < n; i++) { n     g[i].clear(); n   } n   for (int i = 0; i < m; i++) { n     int v, u; n     scanf( %d%d , &v, &u); n     v--; n     u--; n     g[v].push_back(u); n   } n   return true; n } n int used[maxn]; n int tin[maxn], tout[maxn], t; n void dfs0(int v) { n   used[v] = true; n   tin[v] = t++; n   for (int i = 0; i < ((int)(g[v]).size()); i++) { n     int u = g[v][i]; n     if (!used[u]) { n       dfs0(u); n     } n   } n   tout[v] = t; n } n bool anc(int v, int u) { return tin[v] <= tin[u] && tout[u] <= tout[v]; } n int incnt[maxn]; n int cnt[maxn], tov[maxn]; n int go[maxn]; n bool dfs1(int v) { n   used[v] = true; n   cnt[v] = 0; n   tov[v] = v; n   for (int i = 0; i < ((int)(g[v]).size()); i++) { n     int u = g[v][i]; n     if (used[u]) { n       if (!anc(u, v)) { n         return false; n       } n       incnt[u]++; n       cnt[v]++; n       if (anc(u, tov[v])) { n         tov[v] = u; n       } n     } else { n       if (!dfs1(u)) { n         return false; n       } n       cnt[v] += cnt[u]; n       if (anc(tov[u], tov[v])) { n         tov[v] = tov[u]; n       } n     } n   } n   cnt[v] -= incnt[v]; n   go[v] = (cnt[v] == 1 ? tov[v] : -1); n   return true; n } n int good[maxn]; n void dfs2(int v) { n   used[v] = true; n   if (go[v] == v) { n     good[v] = true; n   } else if (go[v] == -1) { n     good[v] = false; n   } else { n     good[v] = good[go[v]]; n   } n   for (int i = 0; i < ((int)(g[v]).size()); i++) { n     int u = g[v][i]; n     if (!used[u]) { n       dfs2(u); n     } n   } n } n vector<int> ans; n bool solve1(int s) { n   for (int i = 0; i < n; i++) { n     used[i] = false; n   } n   t = 0; n   dfs0(s); n   for (int i = 0; i < n; i++) { n     used[i] = false; n     incnt[i] = 0; n   } n   if (!dfs1(s)) { n     return false; n   } n   for (int i = 0; i < n; i++) { n     used[i] = false; n   } n   go[s] = s; n   dfs2(s); n   ans.clear(); n   for (int i = 0; i < n; i++) { n     if (good[i]) { n       ans.push_back(i); n     } n   } n   if (((int)(ans).size()) * 5 < n) { n     printf( -1 n ); n   } else { n     for (int i = 0; i < ((int)(ans).size()); i++) { n       printf( %d  , ans[i] + 1); n     } n     printf(  n ); n   } n   return true; n } n const int K = 70; n void solve() { n   for (int it = 0; it < K; it++) { n     int s = rnd(n); n     if (solve1(s)) { n       return; n     } n   } n   printf( -1 n ); n } n int main() { n   precalc(); n   int t; n   scanf( %d , &t); n   while (read()) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const long long LINF = 0x3f3f3f3f3f3f3f3fll; n const long double pi = acos(-1); n const int MOD = 1e9 + 7; n int main() { n   int n; n   scanf( %d , &n); n   set<int> tem = {1, 5, 10, 50}; n   vector<int> v = {1, 5, 10, 50}; n   if (n == 1) n     printf( %d n , (int)tem.size()); n   else { n     int last = 0; n     for (int i = 2; i <= 60; i++) { n       set<int> vai; n       for (int x : tem) n         for (int y : v) vai.insert(x + y); n       last = vai.size(); n       if (i == n) { n         printf( %d n , (int)vai.size()); n         return 0; n       } n       tem = vai; n     } n     cout << (((long long)n - 60) * 49 + last) << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T abs(T x) { n   return x > 0 ? x : -x; n } n int n; n int m; n string s[30]; n string ans[30]; n string sans[30]; n vector<pair<int, int> > v[30]; n int get(char c) { n   if (c <=  B ) n     return c -  A ; n   else n     return c -  a  + 2; n } n char lol(int x) { n   if (x < 2) n     return x +  A ; n   else n     return (x - 2) +  a ; n } n int t; n int was[100]; n int getH(int a, int b) { n   if (a > b) swap(a, b); n   return (a - 48) * 7 + b - 48; n } n int check() { n   t++; n   for (int i = 0; i < (28); i++) { n     int o = getH(ans[v[i][0].first][v[i][0].second], n                  ans[v[i][1].first][v[i][1].second]); n     if (was[o] == t) return 0; n     was[o] = t; n   } n   for (int i = 0; i < (n); i++) sans[i] = ans[i]; n   return 1; n } n int col[15]; n int xx[100], yy[100]; n int o[100][100]; n int go(int p, int c) { n   if (p == 14) { n     return check(); n   } n   int x = xx[p]; n   int y = yy[p]; n   long long aans = 0; n   for (int cc = 0; cc <= c; cc++) { n     if (col[cc] < 2) { n       col[cc]++; n       ans[x][y] = ans[x + 1][y] = ans[x][y + 1] = ans[x + 1][y + 1] = n           char(cc + 48); n       aans += go(p + 1, min(max(cc + 1, c), 6)); n       col[cc]--; n     } n   } n   return aans; n } n int main() { n   cin >> n >> m; n   for (int i = 0; i < (n); i++) { n     cin >> s[i]; n     ans[i] = s[i]; n   } n   int pp = 0; n   for (int i = 0; i < (n); i++) n     for (int j = 0; j < (m); j++) n       if (s[i][j] !=  . ) { n         if (!o[i][j]) { n           xx[pp] = i; n           yy[pp] = j; n           o[i][j] = o[i + 1][j] = o[i][j + 1] = o[i + 1][j + 1] = 1; n           pp++; n         } n         v[get(s[i][j])].push_back(make_pair(i, j)); n       } n   long long aans = go(0, 0); n   cout << aans * 5040 << endl; n   for (int i = 0; i < (n); i++) cout << sans[i] << endl; n   return 0; n } n


#include<bits/stdc++.h> n #define ll long long n using namespace std; n  n int main() { n     ll T,N,K,i,j,k,l,ans; n     string S; n     cin>>T; n     while (T--) n     { n         cin>>N>>K; n         cin>>S; n         ans=1; n         for(i=0;S[i]!= * ;i++); n         for(j=S.length()-1;S[j]!= * ;j--); n         if(i!=j) n         { n             ans++; n         } n         for(k=i+1;k<=j;k++) n         { n             if(k-i>K) n             { n                 ans++; n                 i=l; n             } n             if(S[k]== * ) n             { n                 l=k; n             } n         } n         cout<<ans<<endl; n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n const int MaxN = 5010; n int N, l, r; n long long ans; n int main() { n   scanf( %d%d , &N, &l); n   r = l; n   for (int i = 1, __end = N; i <= __end; ++i) { n     int u, v; n     scanf( %d%d , &u, &v); n     if (max(l, u) <= min(r, v)) { n       l = max(l, u); n       r = min(r, v); n     } else if (v < l) { n       ans += l - v; n       r = l; n       l = v; n     } else if (r < u) { n       ans += u - r; n       l = r; n       r = u; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long read() { n   long long x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n int n, m, ans, ans1, ans2, ans3, ans4; n vector<int> e[5005]; n queue<int> q; n int d[3005][3005]; n int f[3005][3], g[3005][3]; n void get(int x) { n   q.push(x); n   for (int i = 1; i <= n; i++) d[x][i] = 1000000000; n   d[x][x] = 0; n   while (!q.empty()) { n     int t = q.front(); n     q.pop(); n     for (int i = 0; i < e[t].size(); i++) n       if (d[x][e[t][i]] == 1000000000) { n         d[x][e[t][i]] = d[x][t] + 1; n         q.push(e[t][i]); n       } n   } n } n void pre(int x) { n   for (int i = 1; i <= n; i++) { n     int t = i; n     for (int j = 0; j < 3; j++) { n       int p = f[x][j]; n       if (d[p][x] < d[t][x] && d[t][x] != 1000000000) swap(f[x][j], t); n     } n     t = i; n     for (int j = 0; j < 3; j++) { n       int p = g[x][j]; n       if (d[x][p] < d[x][t] && d[x][t] != 1000000000) swap(g[x][j], t); n     } n   } n } n void solve(int u, int v) { n   if (d[u][v] == 1000000000) return; n   for (int i = 0; i < 3; i++) n     for (int j = 0; j < 3; j++) { n       int p1 = f[u][i], p2 = g[v][j]; n       if (p1 == 0 || p2 == 0) continue; n       if (p1 != p2 && p1 != v && p2 != u && n           d[p1][u] + d[u][v] + d[v][p2] > ans) { n         ans = d[p1][u] + d[u][v] + d[v][p2]; n         ans1 = p1, ans2 = u, ans3 = v, ans4 = p2; n       } n     } n } n int main() { n   n = read(); n   m = read(); n   for (int i = 1; i <= m; i++) { n     int u, v; n     u = read(); n     v = read(); n     e[u].push_back(v); n   } n   for (int i = 1; i <= n; i++) get(i); n   for (int i = 1; i <= n; i++) pre(i); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) n       if (i != j) solve(i, j); n   cout << ans1 <<     << ans2 <<     << ans3 <<     << ans4 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100501; n struct bor { n   int a[27]; n }; n bor q[maxn]; n int free1 = 0; n void add(string &s, int pos, int i) { n   if (pos == (int)s.size()) { n     return; n   } n   if (q[i].a[s[pos] -  a  + 1] == 0) { n     free1++; n     q[i].a[s[pos] -  a  + 1] = free1; n   } n   add(s, pos + 1, q[i].a[s[pos] -  a  + 1]); n   return; n } n bool u[2 * maxn]; n bool was[2 * maxn]; n bool dfs(int i) { n   u[i] = true; n   was[i] = false; n   int y = 0; n   int t = 0; n   for (int j = 1; j < 27; j++) { n     int r = q[i].a[j]; n     if (r != 0) { n       y++; n       if (dfs(r) == true) { n         t++; n       } n       if (was[r] == false) { n         was[i] = true; n         if (i == 0) { n         } n       } n     } n   } n   if (y == 0) { n     was[i] = true; n   } n   if (t == y) { n     u[i] = false; n   } n   return u[i]; n } n int main() { n   int n, k; n   cin >> n >> k; n   for (int i = 0; i < n; i++) { n     string s; n     cin >> s; n     add(s, 0, 0); n   } n   bool q = dfs(0); n   if (q == false) { n     cout <<  Second ; n   } else { n     if (was[0] == true) { n       cout <<  First ; n     } else if (k % 2 == 0) { n       cout <<  Second ; n     } else n       cout <<  First ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool cmp(pair<pair<long long int, long long int>, long long int> a, n          pair<pair<long long int, long long int>, long long int> b) { n   if (a.first.first != b.first.first) n     return a.first.first < b.first.first; n   else n     return a.first.second < b.first.second; n } n long long int n, m, k1; n long long int re[2 * 100000 + 2]; n long long int pre[2 * 100000 + 3]; n bool chec(long long int x) { n   long long int s = 0; n   long long int c = 0; n   for (long long int i = n - (x - 1); i <= n; ++i) { n     s += re[i]; n     if (s > k1) { n       c++; n       s = re[i]; n     } n   } n   if (s != 0) c++; n   return c <= m; n } n void machayenge() { n   cin >> n >> m >> k1; n   for (long long int i = 1; i <= n; ++i) { n     cin >> re[i]; n     pre[i] = pre[i - 1] + re[i]; n   } n   long long int i = 0; n   long long int j = n; n   while (i < j) { n     long long int mid = (i + j + 1) / 2; n     if (chec(mid)) { n       i = mid; n     } else n       j = mid - 1; n   } n   cout << i; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(0); n   machayenge(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[110]; n int gcd(int x, int y) { n   if (!x) n     return y; n   else n     return gcd(y % x, x); n } n int main() { n   int n, mx = 0; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     mx = max(mx, a[i]); n   } n   int g = a[0]; n   for (int i = 1; i < n; i++) g = gcd(g, a[i]); n   if ((mx / g - n) % 2 == 1) n     cout <<  Alice  << endl; n   else n     cout <<  Bob  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<long long> cnt(1e5 + 2, 0), dp(1e5 + 2, 0); n   while (n--) { n     long long x; n     cin >> x; n     cnt[x]++; n   } n   dp[1] = cnt[1]; n   for (int i = 2; i < 1e5 + 2; i++) { n     dp[i] = max(dp[i - 1], dp[i - 2] + cnt[i] * i); n   } n   cout << dp[1e5 + 1] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   int m; n   cin >> s >> m; n   while (m--) { n     int l, r, k; n     cin >> l >> r >> k; n     int init = l - 1; n     int len = r - l + 1; n     string ns = s; n     for (int i = init; i < r; i++) { n       int pos = init + (i - init + k) % len; n       ns[pos] = s[i]; n     } n     s = ns; n   } n   cout << s << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxn = 1e5 + 7; n long long n, m, a[maxn], b[maxn]; n vector<long long> vt[100]; n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   for (long long i = 1; i <= n; i++) { n     cin >> b[i]; n     long long gau = b[i]; n     long long dem = 0; n     while (gau > 0) { n       gau >>= 1; n       dem++; n     } n     vt[--dem].push_back(b[i]); n   } n   bool d = true; n   long long gau = 0; n   for (long long i = 1; i <= n; i++) { n     if (!d) return cout <<  No , 0; n     d = false; n     for (long long j = 0; j <= 61; j++) { n       if (((gau >> j) & 1) != 0 || vt[j].empty()) continue; n       gau ^= vt[j].back(); n       a[i] = vt[j].back(); n       vt[j].pop_back(); n       d = true; n       break; n     } n   } n   if (!d) return cout <<  No , 0; n   cout <<  Yes  <<   n ; n   for (long long i = 1; i <= n; i += 1) cout << a[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100005; n string str[N]; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> str[i]; n   } n   for (int i = 0; i < ((int)(str[0]).size()); i++) { n     bool all = true; n     char only = 0; n     for (int j = 0; j < n; j++) { n       if (str[j][i] ==  ? ) continue; n       all = false; n       if (only == 0) n         only = str[j][i]; n       else if (only != 0 && str[j][i] != only) n         only = -1; n     } n     if (all) { n       printf( a ); n     } else if (only != -1) { n       printf( %c , only); n     } else { n       printf( ? ); n     } n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1000 * 1000 * 1000; n const int maxn = 20; n int n, sz[maxn + maxn], ans, d[maxn + maxn][(1 << maxn)]; n vector<int> g[maxn + maxn][26]; n bool was[maxn + maxn][(1 << maxn)]; n char a[maxn][maxn]; n int calc(int v, int mask) { n   if (was[v][mask]) return d[v][mask]; n   was[v][mask] = true; n   if (v == n + n - 2) return 0; n   if (v % 2) n     d[v][mask] = -inf; n   else n     d[v][mask] = inf; n   int lmask, cur; n   for (int i = 0; i < 26; i++) { n     lmask = 0; n     for (int j = 0; j < (int)g[v + 1][i].size(); j++) { n       cur = min(v + 1, n - 1) - g[v + 1][i][j]; n       if (v > n - 2) { n         if ((mask & (1 << cur))) lmask |= (1 << cur); n       } else { n         if (cur && (mask & (1 << (cur - 1)))) lmask |= (1 << cur); n       } n       if (v > n - 2) { n         if ((mask & (1 << (cur + 1)))) lmask |= (1 << cur); n       } else { n         if (cur != sz[v + 1] - 1 && (mask & (1 << cur))) lmask |= (1 << cur); n       } n     } n     if (!lmask) continue; n     if (v % 2) n       d[v][mask] = max(d[v][mask], calc(v + 1, lmask) + (!i       ? 1 n                                                          : i == 1 ? -1 n                                                                   : 0)); n     else n       d[v][mask] = min(d[v][mask], calc(v + 1, lmask) + (!i       ? 1 n                                                          : i == 1 ? -1 n                                                                   : 0)); n   } n   return d[v][mask]; n } n int main() { n   cin >> n; n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < n; ++j) cin >> a[i][j]; n   for (int i = 0; i < n + n - 1; ++i) { n     int l = min(i, n - 1), r = max(0, i - n + 1); n     while (l >= 0 && r < n) { n       g[i][a[l][r] -  a ].push_back(l); n       l--; n       r++; n     } n     for (int j = 0; j < 26; j++) sz[i] += (int)g[i][j].size(); n   } n   ans = calc(0, 1) + (a[0][0] ==  a  ? 1 : a[0][0] ==  b  ? -1 : 0); n   if (ans) n     if (ans > 0) n       cout <<  FIRST ; n     else n       cout <<  SECOND ; n   else n     cout <<  DRAW ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int head[100010], to[200010], nxt[200010], cnt, d[100010]; n inline void AddEdge(int u, int v) { n   ++cnt, to[cnt] = v, nxt[cnt] = head[u], head[u] = cnt; n } n int mxd, mxu, f[100010]; n inline void Find(int u, int p, int d) { n   if (d > mxd) mxd = d, mxu = u; n   f[u] = p; n   for (int e = head[u]; e; e = nxt[e]) { n     int v = to[e]; n     if (v == p) continue; n     Find(v, u, d + 1); n   } n } n int depnum[100010]; n inline int Checkl(int u, int p) { n   if (d[u] > 2) return 0; n   for (int e = head[u]; e; e = nxt[e]) { n     int v = to[e]; n     if (v == p) continue; n     return Checkl(v, u); n   } n   return u; n } n inline bool Dfs(int u, int p, int dep) { n   if (!depnum[dep] || depnum[dep] == d[u]) n     depnum[dep] = d[u]; n   else n     return false; n   for (int e = head[u]; e; e = nxt[e]) { n     int v = to[e]; n     if (v == p) continue; n     if (!Dfs(v, u, dep + 1)) return false; n   } n   return true; n } n inline void Check(int u) { n   memset(depnum, 0, sizeof(depnum)); n   for (int e = head[u]; e; e = nxt[e]) n     if (!Dfs(to[e], u, 1)) return; n   printf( %d n , u); n   exit(0); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i < n; ++i) { n     int u, v; n     scanf( %d%d , &u, &v); n     AddEdge(u, v), AddEdge(v, u); n     ++d[u], ++d[v]; n   } n   mxd = -1, Find(1, 0, 0); n   int xxu = mxu; n   mxd = -1, Find(mxu, 0, 0); n   if (mxd & 1) { n     Check(xxu), Check(mxu), printf( -1 n ); n     return 0; n   } n   for (int i = 1; i <= mxd / 2; ++i) mxu = f[mxu]; n   for (int e = head[mxu]; e; e = nxt[e]) n     if (!Checkl(to[e], mxu) && !Dfs(to[e], mxu, 1)) { n       printf( -1 n ); n       return 0; n     } n   for (int e = head[mxu], l = 0; e; e = nxt[e]) { n     int u = Checkl(to[e], mxu); n     if (!u) continue; n     if (!Dfs(to[e], mxu, 1)) { n       if (l) Check(l); n       Check(u), printf( -1 n ); n       return 0; n     } n     l = u; n   } n   printf( %d n , mxu); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool good() { n   string input; n   cin >> input; n   stack<int> pm; n   for (int i = 0; i < input.length(); i++) n     if (pm.empty() || input[i] != pm.top()) n       pm.push(input[i]); n     else n       pm.pop(); n   return pm.empty(); n } n int main() { n   cout << (good() ?  Yes  :  No ) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 300010; n multiset<int> val[maxn]; n struct Trie { n   int next[maxn][26], fail[maxn], end[maxn]; n   int last[maxn]; n   int root, L; n   int newnode() { n     for (int i = 0; i < 26; i++) next[L][i] = -1; n     fail[L] = last[L] = end[L] = 0; n     return L++; n   } n   void init() { n     L = 0; n     root = newnode(); n   } n   int insert(char buf[], int v) { n     int len = strlen(buf); n     int now = root; n     for (int i = 0; i < len; i++) { n       if (next[now][buf[i] -  a ] == -1) next[now][buf[i] -  a ] = newnode(); n       now = next[now][buf[i] -  a ]; n     } n     end[now]++; n     val[now].insert(v); n     return now; n   } n   void build() { n     queue<int> Q; n     fail[root] = root; n     for (int i = 0; i < 26; i++) { n       if (next[root][i] == -1) n         next[root][i] = root; n       else { n         fail[next[root][i]] = root; n         Q.push(next[root][i]); n       } n     } n     while (!Q.empty()) { n       int now = Q.front(); n       Q.pop(); n       for (int i = 0; i < 26; i++) { n         if (next[now][i] == -1) n           next[now][i] = next[fail[now]][i]; n         else { n           int son = next[now][i]; n           fail[son] = next[fail[now]][i]; n           last[son] = end[fail[son]] ? fail[son] : last[fail[son]]; n           Q.push(next[now][i]); n         } n       } n     } n   } n   int count(int x) { n     int res = -1; n     for (int j = x; j && end[j] != -1; j = last[j]) { n       if (end[j]) res = max(res, *val[j].rbegin()); n     } n     return res; n   } n   void query(char buf[]) { n     int len = strlen(buf); n     int now = root; n     int res = -1; n     for (int i = 0; i < len; i++) { n       now = next[now][buf[i] -  a ]; n       if (end[now] != -1) n         res = max(res, count(now)); n       else if (end[last[now]] != -1) n         res = max(res, count(last[now])); n     } n     printf( %d n , res); n   } n   void ch(int pos, int x, int y) { n     auto it = val[pos].lower_bound(x); n     val[pos].erase(it); n     val[pos].insert(y); n   } n } ac; n char s[maxn]; n int pos[maxn], w[maxn]; n int main() { n   int n, m; n   ac.init(); n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) { n     scanf( %s , s); n     pos[i] = ac.insert(s, 0); n     w[i] = 0; n   } n   ac.build(); n   int op, x, y; n   while (m--) { n     scanf( %d , &op); n     if (op == 1) { n       scanf( %d%d , &x, &y); n       ac.ch(pos[x], w[x], y); n       w[x] = y; n     } else { n       scanf( %s , s); n       ac.query(s); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n const int WYMIAR = 17; n int mod = MOD; n struct M { n   int t[WYMIAR][WYMIAR]; n   M() { n     for (int i = 0; i < (WYMIAR); ++i) n       for (int j = 0; j < (WYMIAR); ++j) t[i][j] = 0; n     for (int i = 0; i < (WYMIAR); ++i) t[i][i] = 1; n   } n }; n M operator*(const M &a, const M &b) { n   M res; n   for (int i = 0; i < (WYMIAR); ++i) n     for (int j = 0; j < (WYMIAR); ++j) { n       long long acc = 0; n       for (int k = 0; k < (WYMIAR); ++k) n         acc += (long long)a.t[i][k] * b.t[k][j] % mod; n       res.t[i][j] = acc % mod; n     } n   return res; n } n M potega(M x, long long n) { n   M res, acc = x; n   for (int i = 0; i < (WYMIAR); ++i) res.t[i][i] = 1; n   while (n) { n     if (n & 1) res = res * acc; n     acc = acc * acc; n     n /= 2; n   } n   return res; n } n pair<int, int> rozloz(int x) { return make_pair(x / 4, x % 4); } n int zabron(int a, int b) { n   if (a > b) return zabron(b, a); n   if (a == b) return 1; n   if (a == 0 && b == 3) return 1; n   if (a == 1 && b == 2) return 1; n   return 0; n } n int dobra_para(int aa, int bb) { n   pair<int, int> a = rozloz(aa); n   pair<int, int> b = rozloz(bb); n   if (a.second != b.first) return 0; n   if (zabron(b.first, b.second)) return 0; n   if (a.first == 1 && b.first == 0 && b.second == 2) return 0; n   if (a.first == 2 && b.first == 0 && b.second == 1) return 0; n   return 1; n } n int licz(int n) { n   if (n == 0) return 0; n   if (n == 1) return 4; n   M m; n   for (int i = 0; i < (16); ++i) n     for (int j = 0; j < (16); ++j) m.t[i][j] = dobra_para(i, j); n   for (int i = 0; i < (17); ++i) m.t[i][16] = 1; n   int stan[17]; n   stan[16] = 4; n   for (int i = 0; i < (16); ++i) { n     pair<int, int> p = rozloz(i); n     stan[i] = !zabron(p.first, p.second); n   } n   M tmp = potega(m, n - 1); n   int acc = 0; n   for (int i = 0; i < (17); ++i) n     acc = (acc + (long long)stan[i] * tmp.t[i][16]) % MOD; n   return acc % MOD; n } n int licz2(int n) { n   if (n == 0) return 0; n   if (n == 1) return 4; n   int res = licz(n); n   int palindromy = licz((n + 1) / 2); n   int niepal = ((MOD + res - palindromy) % MOD) * (long long)500000004 % MOD; n   return (palindromy + niepal) % MOD; n } n int main() { n   int l, r; n   scanf( %d %d , &l, &r); n   printf( %d n , (licz2(r) + MOD - licz2(l - 1)) % MOD); n   return 0; n } n


#include <bits/stdc++.h> n int f[5005], g[5005], h[5005], n; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &h[i]); n   memset(f, 66, sizeof(f)); n   f[0] = 0; n   for (int i = 1; i <= n; i++) { n     int j = i, sum = h[j]; n     while (j && sum < f[j - 1]) sum += h[--j]; n     if (sum >= f[j - 1]) f[i] = sum, g[i] = g[j - 1] + i - j; n   } n   printf( %d n , g[n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char symmetric[11] = { A ,  H ,  I ,  M ,  O ,  T ,  U ,  V ,  W ,  X ,  Y }; n bool isPrime(long long int n) { n   if (n <= 1) return false; n   if (n <= 3) return true; n   if (n % 2 == 0 || n % 3 == 0) return false; n   for (int i = 5; i * i <= n; i = i + 6) n     if (n % i == 0 || n % (i + 2) == 0) return false; n   return true; n } n bool IsPalindrome(string str) { n   if (str.empty()) return false; n   long long int i = 0; n   long long int j = str.length() - 1; n   while (i < j) { n     if (str[i] != str[j]) { n       return false; n     } n     i++; n     j--; n   } n   return true; n } n long long int binpow(long long int a, long long int b) { n   if (b == 0) return 1; n   long long int res = binpow(a, b / 2); n   if (b % 2) return (res * res * a); n   return (res * res); n } n signed main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); n   long long int a, b; n   cin >> a >> b; n   long long int x = max(a, b); n   long long int y = a + b - x; n   if (a < 2 * b && b < 2 * a) n     cout << a <<     << b; n   else if (x % y == 0) { n     if ((x / y) % 2 == 0) { n       if (y == a) { n         cout << y <<   0 ; n       } else { n         cout <<  0   << y; n       } n     } else { n       cout << y <<     << y; n     } n   } else { n     while (a && b) { n       if (a >= 2 * b) n         a %= 2 * b; n       else if (b >= 2 * a) n         b %= 2 * a; n       else n         break; n     } n     cout << a <<     << b; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string nums[1005]; n string tostr(int a) { n   ostringstream ss; n   ss << a; n   return ss.str(); n } n deque<long long> deq; n vector<int> ans[200001]; n vector<pair<int, int> > graph[200001]; n int p[200001]; n int cmax = 0; n void dfs(int v, int d) { n   int c = 0; n   for (int i = 0; i < graph[v].size(); i++) { n     if (c == d) c++; n     int k = graph[v][i].first; n     if (k == p[v]) { n       continue; n     } n     p[k] = v; n     ans[c].push_back(graph[v][i].second); n     dfs(k, c); n     cmax = max(c, cmax); n     c++; n   } n } n set<int> is; n int main() { n   int n, m; n   cin >> n >> m; n   int k; n   for (int i = 0; i < n; i++) { n     cin >> k; n     is.insert(k); n   } n   vector<int> ans; n   for (int kek = 1; kek <= 3000000; kek++) { n     if (m >= kek && is.find(kek) == is.end()) { n       ans.push_back(kek); n       m -= kek; n     } n   } n   cout << ans.size() <<   n ; n   for (int i = 0; i < ans.size(); i++) { n     cout << ans[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int bit[100005], n, dt; n set<int> ms; n vector<int> nums, ops; n void add(int pos, int val) { n   while (pos <= (int)nums.size()) { n     bit[pos] += val; n     pos += (-pos) & pos; n   } n } n int sum(int pos) { n   int res = 0; n   while (pos > 0) { n     res += bit[pos]; n     pos -= (-pos) & pos; n   } n   return res; n } n struct range { n   int l, r, cnt, cov; n   long long sum[5]; n   range(int L, int R) { n     l = L; n     r = R; n     cov = 0; n     cnt = 0; n     memset(sum, 0, sizeof(sum)); n   } n   range() { n     l = r = cnt = cov = 0; n     memset(sum, 0, sizeof(sum)); n   } n }; n range operator+(range a, range b) { n   range c = a; n   c.r = b.r; n   c.cnt += b.cnt; n   int xb; n   for (xb = 0; xb < 5; xb++) c.sum[xb] += b.sum[(xb + 10 - b.cov + a.cov) % 5]; n   return c; n } n range operator-(range a, range b) { n   range c = a; n   c.r = b.r; n   c.cnt -= b.cnt; n   int xb; n   for (xb = 0; xb < 5; xb++) c.sum[xb] -= b.sum[(xb + 10 - b.cov + a.cov) % 5]; n   return c; n } n void proc(range &a, range b, int type) { n   int xb; n   if (type == 1) { n     a = a - b; n     a.cnt += b.cnt; n     for (xb = 0; xb < 5; xb++) n       a.sum[xb] += b.sum[(xb + 15 - b.cov + a.cov - 1) % 5]; n   } else { n     a = a - b; n     a.cnt += b.cnt; n     for (xb = 0; xb < 5; xb++) n       a.sum[xb] += b.sum[(xb + 15 - b.cov + a.cov + 1) % 5]; n   } n } n struct SegT { n   range tree[300005]; n   void init(int pos, int l, int r) { n     tree[pos].l = l; n     tree[pos].r = r; n     memset(tree[pos].sum, 0, sizeof(tree[pos].sum)); n     tree[pos].cnt = tree[pos].cov = 0; n     if (l != r) { n       int m = (l + r) / 2; n       init(pos * 2, l, m); n       init(pos * 2 + 1, m + 1, r); n     } n   } n   range query(int pos, int l, int r) { n     if (l <= tree[pos].l && r >= tree[pos].r) return tree[pos]; n     int m = (tree[pos].l + tree[pos].r) / 2; n     range ret = range(tree[pos].l, 0); n     if (l <= m) ret = ret + query(pos * 2, l, r); n     if (r > m) ret = ret + query(pos * 2 + 1, l, r); n     ret.cov += tree[pos].cov; n     ret.r = tree[pos].r; n     ret.cov %= 5; n     return ret; n   } n   void addcov(int pos, int l, int r, int v) { n     if (l <= tree[pos].l && r >= tree[pos].r) { n       tree[pos].cov += v; n       tree[pos].cov %= 5; n       return; n     } n     int m = (tree[pos].l + tree[pos].r) / 2; n     if (l <= m) addcov(pos * 2, l, r, v); n     if (r > m) addcov(pos * 2 + 1, l, r, v); n   } n   void edit(int pos, int d, int rst, int type, int cov) { n     tree[pos].cnt += type; n     if (d == tree[pos].r) { n       tree[pos].sum[(rst - cov - tree[pos].cov + 10) % 5] += type * nums[d]; n       if (tree[pos].l != tree[pos].r) n         edit(pos * 2 + 1, d, rst, type, (cov + tree[pos].cov) % 5); n       return; n     } n     range res = query(pos, d + 1, tree[pos].r); n     tree[pos].sum[(rst - cov - tree[pos].cov + 10) % 5] += type * nums[d]; n     proc(tree[pos], res, type); n     int m = (tree[pos].l + tree[pos].r) / 2; n     if (d <= m) { n       edit(pos * 2, d, rst, type, (cov + tree[pos].cov) % 5); n       addcov(pos * 2 + 1, m + 1, tree[pos].r, type); n     } else { n       edit(pos * 2 + 1, d, rst, type, (cov + tree[pos].cov) % 5); n     } n   } n } T; n int Bsearch(int key) { n   int left = 1, right = (int)nums.size(), mid; n   while (left < right) { n     mid = (left + right) / 2; n     if (nums[mid] < key) n       left = mid + 1; n     else n       right = mid; n   } n   return left; n } n char inp[100005][10]; n int main() { n   ms.clear(); n   int xb, x2, op; n   scanf( %d , &n); n   if (n == 1) { n     scanf( %s , inp[0]); n     if (inp[0][0] ==  s ) printf( 0 ); n     return 0; n   } n   for (xb = 0; xb < n; xb++) { n     scanf( %s , inp[xb]); n     if (inp[xb][0] ==  a ) { n       scanf( %d , &op); n       ops.push_back(op); n       ms.insert(op); n     } else if (inp[xb][0] ==  d ) { n       scanf( %d , &op); n       ops.push_back(op); n     } else n       ops.push_back(-1); n   } n   set<int>::iterator it; n   nums.push_back(-1); n   for (it = ms.begin(); it != ms.end(); it++) { n     nums.push_back(*it); n   } n   T.init(1, 1, nums.size() - 1); n   for (xb = 0; xb < n; xb++) { n     if (inp[xb][0] ==  a ) { n       int d = Bsearch(ops[xb]), rst = sum(d - 1); n       add(d, 1); n       T.edit(1, d, rst, 1, 0); n     } else if (inp[xb][0] ==  d ) { n       int d = Bsearch(ops[xb]), rst = sum(d - 1); n       add(d, -1); n       T.edit(1, d, rst, -1, 0); n     } else { n       range res = T.query(1, 1, nums.size() - 1); n       printf( %I64d n , res.sum[(7 - res.cov) % 5]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, l, r; n   cin >> n; n   pair<pair<long long, long long>, long long> lr[n + 1]; n   for (long long i = 1; i <= n; i++) { n     cin >> lr[i].first.first >> lr[i].first.second; n     lr[i].second = i; n   } n   sort(lr + 1, lr + n + 1); n   for (long long i = 2; i <= n; i++) { n     if (lr[i].first.second <= lr[i - 1].first.second) { n       return cout << lr[i].second <<     << lr[i - 1].second, 0; n     } n     if (lr[i].first.first == lr[i - 1].first.first) { n       return cout << lr[i - 1].second <<     << lr[i].second, 0; n     } n   } n   cout <<  -1 -1 ; n } n


#include <bits/stdc++.h> n using namespace std; n long long KuriBija[1005]; n long long A; n long long Cik, lol; n int main() { n   cin >> Cik >> lol; n   for (long long i = 0; i < lol; i++) { n     cin >> A; n     KuriBija[A] = 1; n     cin >> A; n     KuriBija[A] = 1; n   } n   lol = 1; n   while (KuriBija[lol] != 0) { n     lol++; n   } n   cout << Cik - 1 << endl; n   for (long long i = 0; i < Cik; i++) { n     if (i + 1 != lol) { n       cout << lol <<     << i + 1 << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   if ((n - 1) * n / 2 <= k) { n     cout <<  no solution  << endl; n     return 0; n   } n   long x, y; n   x = y = 0; n   while (n--) { n     cout << x <<     << y++ << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string ent =   n ; n string space =    ; n int main() { n   ios_base::sync_with_stdio(false); n   int n; n   cin >> n; n   string s; n   cin >> s; n   int zero, one; n   zero = one = 0; n   for (int i = 0; i < n; i++) { n     if (s[i] == 48) n       zero++; n     else n       one++; n   } n   if (one != zero) { n     cout << 1 << ent + s + ent; n   } else { n     int j = n - 1; n     string s_new; n     for (int i = 0; i < n; i++) { n       if (one != zero) { n         j = i; n         break; n       } n       s_new += s[i]; n       if (s[i] == 48) n         zero--; n       else n         one--; n     } n     cout << 2 << ent + s_new + space; n     for (int i = j; i < n; i++) { n       cout << s[i]; n     } n     cout << ent; n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct Query { n   int prefixe, nombre; n   int id; n   bool operator<(const Query& autre) const { return prefixe < autre.prefixe; } n }; n const int MAXP = 20; n const int MAXN = 100 * 1000 + 10; n const int MOD = 1000 * 1000 * 1000 + 7; n bool prise[MAXP]; n int puissance[MAXN]; n int iConcerne[MAXP]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   puissance[0] = 1; n   for (int i = 1; i < MAXN; i++) { n     puissance[i] = (puissance[i - 1] * 2) % MOD; n   } n   int nbNombres, nbQuestions; n   cin >> nbNombres >> nbQuestions; n   int nombres[nbNombres]; n   for (int i = 0; i < nbNombres; i++) { n     cin >> nombres[i]; n   } n   Query questions[nbQuestions]; n   int solution[nbQuestions]; n   for (int i = 0; i < nbQuestions; i++) { n     cin >> questions[i].prefixe >> questions[i].nombre; n     questions[i].prefixe--; n     questions[i].id = i; n   } n   sort(questions, questions + nbQuestions); n   int inQuestion = 0; n   int nbPris = 0; n   for (int iN = 0; iN < nbNombres; iN++) { n     for (int i = 0; i < nbPris; i++) { n       if (nombres[iN] & (1 << iConcerne[i])) nombres[iN] ^= nombres[i]; n     } n     for (int i = 0; i < MAXP; i++) { n       if (!prise[i] && (nombres[iN] & (1 << i))) { n         swap(nombres[iN], nombres[nbPris]); n         iConcerne[nbPris] = i; n         nbPris++; n         prise[i] = true; n         break; n       } n     } n     while (inQuestion < nbQuestions && questions[inQuestion].prefixe == iN) { n       for (int i = 0; i < nbPris; i++) { n         if (questions[inQuestion].nombre & (1 << iConcerne[i])) n           questions[inQuestion].nombre ^= nombres[i]; n       } n       if (questions[inQuestion].nombre == 0) { n         solution[questions[inQuestion].id] = puissance[iN + 1 - nbPris]; n       } else { n         solution[questions[inQuestion].id] = 0; n       } n       inQuestion++; n     } n   } n   for (int i = 0; i < nbQuestions; i++) { n     cout << solution[i] << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   long long arr[n + 2]; n   for (int i = 1; i <= n; i++) cin >> arr[i]; n   long long cume[n + 2], cumo[n + 2], rcume[n + 2], rcumo[n + 2]; n   cume[0] = 0; n   cumo[0] = 0; n   for (int i = 1; i <= n; i++) { n     if (i % 2) { n       cumo[i] = cumo[i - 1] + arr[i]; n       cume[i] = cume[i - 1]; n     } else { n       cume[i] = cume[i - 1] + arr[i]; n       cumo[i] = cumo[i - 1]; n     } n   } n   rcume[n + 1] = 0; n   rcumo[n + 1] = 0; n   for (int i = n; i >= 1; i--) { n     if (i % 2) { n       rcumo[i] = rcumo[i + 1] + arr[i]; n       rcume[i] = rcume[i + 1]; n     } else { n       rcume[i] = rcume[i + 1] + arr[i]; n       rcumo[i] = rcumo[i + 1]; n     } n   } n   long long ans = 0; n   for (int i = 1; i <= n; i++) { n     long long o = cumo[i - 1] + rcume[i + 1]; n     long long e = cume[i - 1] + rcumo[i + 1]; n     if (o == e) ans++; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   string s; n   int x = 0, y = 0; n   cin >> s; n   for (int i = 0; i < t; i++) { n     if (s[i] ==  L ) { n       x--; n     } else { n       y++; n     } n   } n   cout << y - x + 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct __s { n   __s() {} n   ~__s() { n     long long n; n     cin >> n; n   } n } __S; n double mm, back, now, ans; n long long m, n; n double st(double x) { n   double res = 1.0; n   for (long long i = 0; i < (long long)(n - 1); i++) { n     res *= x / m; n   } n   return res; n } n int main(void) { n   cin >> m >> n; n   mm = (double)m; n   back = st(mm); n   for (long long i = 0; i < (long long)(m); i++) { n     mm -= 1.0; n     now = st(mm); n     double res = (mm + 1.0) * (back + (back - now) * mm) / m; n     ans += res; n     if (res < 1e-6) { n       cerr << i <<   n ; n       break; n     } n     back = now; n   } n   printf( %.10f  n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, M; n int p[1010]; n long long X[1010]; n int A[1010]; n long long B[1010]; n int U[2020]; n int V[2020]; n int up[1010]; n bool chk[2020]; n bool vst[1010]; n bool chkv[1010]; n long long mn[2020]; n vector<int> adj[1010]; n priority_queue<pair<long long, int>, vector<pair<long long, int> >, n                greater<pair<long long, int> > > n     pq; n int par(int x) { n   if (x == p[x]) return x; n   return p[x] = par(p[x]); n } n void unite(int a, int b) { n   a = par(a); n   b = par(b); n   p[a] = b; n } n void add(int e) { n   int a = U[e], b = V[e]; n   assert(vst[a] || vst[b]); n   if (vst[b]) swap(a, b); n   if (vst[b]) { n     int t = par(b); n     while (t > 1) { n       B[1] += B[t]; n       p[t] = 1; n       t = up[t]; n       t = par(t); n     } n     t = par(a); n     while (t > 1) { n       B[1] += B[t]; n       p[t] = 1; n       t = up[t]; n       t = par(t); n     } n   } else { n     int t = par(a); n     vst[b] = true; n     up[b] = t; n   } n   chk[e] = true; n } n void dfs(int v) { n   X[v] += B[v]; n   for (int i : adj[v]) { n     X[i] += X[v]; n     dfs(i); n   } n } n void add_edges() { n   for (int i = 1; i <= N; i++) { n     adj[i].clear(); n     X[i] = 0; n   } n   for (int i = 2; i <= N; i++) { n     if (p[i] != i || !vst[i]) continue; n     adj[par(up[i])].push_back(i); n   } n   dfs(1); n   for (int i = 1; i <= M; i++) { n     if (chk[i]) continue; n     int a = U[i], b = V[i]; n     a = par(a); n     b = par(b); n     if (a == b) { n       chk[i] = true; n       continue; n     } n     if (vst[a]) { n       if (mn[i] > A[V[i]] - X[a] + 1) { n         mn[i] = A[V[i]] - X[a] + 1; n         pq.emplace(mn[i], i); n       } n     } n     if (vst[b]) { n       if (mn[i] > A[U[i]] - X[b] + 1) { n         mn[i] = A[U[i]] - X[b] + 1; n         pq.emplace(mn[i], i); n       } n     } n   } n } n int main() { n   int tc; n   scanf( %d , &tc); n   while (tc--) { n     scanf( %d%d , &N, &M); n     int mxv = 0; n     for (int i = 2; i <= N; i++) { n       scanf( %d , &A[i]); n       if (A[mxv] < A[i]) mxv = i; n     } n     B[1] = 0; n     for (int i = 2; i <= N; i++) scanf( %lld , &B[i]); n     for (int i = 1; i <= M; i++) scanf( %d%d , &U[i], &V[i]); n     while (pq.size()) pq.pop(); n     for (int i = 1; i <= N; i++) p[i] = i; n     for (int i = 1; i <= N; i++) { n       chkv[i] = vst[i] = false; n       X[i] = up[i] = 0; n     } n     for (int i = 1; i <= M; i++) chk[i] = false; n     vst[1] = true; n     long long ans = 0; n     for (int i = 1; i <= M; i++) mn[i] = 1LL << 60; n     add_edges(); n     while (pq.size()) { n       if (vst[mxv]) break; n       pair<long long, int> t = pq.top(); n       pq.pop(); n       if (t.first > mn[t.second] || chk[t.second]) continue; n       if (par(U[t.second]) == par(V[t.second])) { n         chk[t.second] = true; n         continue; n       } n       ans = max(ans, t.first); n       add(t.second); n       add_edges(); n     } n     assert(vst[mxv]); n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( unroll-loops ) n #pragma GCC optimize( O3 ,  omit-frame-pointer ,  inline ) n #pragma GCC target(   n      sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native ) n using namespace std; n const long long mod = 998244353; n mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count()); n const int mxN = 5010; n int main(int argc, char *argv[]) { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   srand(time(NULL)); n   cout << fixed << setprecision(9); n   int t = 1; n   while (t--) { n     int n; n     cin >> n; n     vector<int> a(n); n     for (int i = 0; i < n; i++) cin >> a[i]; n     vector<int> e; n     for (int i = 0; i < n; i++) { n       if (!e.empty() && e.back() % 2 == a[i] % 2) n         e.pop_back(); n       else n         e.push_back(a[i]); n     } n     cout << (e.size() <= 1 ?  YES  :  NO ) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i, c = 1; n   cin >> n; n   int a[n + 1]; n   memset(a, 0, sizeof(a)); n   for (i = 0; i < n; i++) cin >> a[i]; n   for (i = 0; i < n; i++) { n     if (a[i] != a[i + 1]) c++; n   } n   cout << c - 1 <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n1, n2, k1, k2, d1, d2; n   scanf( %d %d %d %d , &n1, &n2, &k1, &k2); n   if (n1 > n2) { n     printf( First n ); n   } else { n     printf( Second n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma warning(disable : 4996) n #pragma comment(linker,  /STACK:336777216 ) n using namespace std; n int IT_MAX = 1 << 18; n const long long MOD = 1000000007; n const int INF = 0x3f3f3f3f; n const long long LL_INF = 0x3f3f3f3f3f3f3f3f; n const double PI = acos(-1); n const double ERR = 1e-10; n long long dp[55][55][55]; n long long tdp[55][55][55]; n long long C[55][55]; n long long F[55]; n long long po2[55]; n long long cnt[55][2]; n int main() { n   int i, j, k, l, m; n   for (i = 0; i <= 50; i++) { n     C[i][0] = C[i][i] = 1; n     for (j = 1; j < i; j++) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD; n     for (j = 0; j <= i; j++) cnt[i][j % 2] = (cnt[i][j % 2] + C[i][j]) % MOD; n   } n   F[0] = 1; n   for (i = 1; i <= 50; i++) F[i] = F[i - 1] * i % MOD; n   po2[0] = 1; n   for (i = 1; i <= 50; i++) po2[i] = po2[i - 1] * 2 % MOD; n   dp[0][0][0] = 1; n   int N, tus; n   scanf( %d %d , &N, &tus); n   for (i = 1; i <= N; i++) { n     int st = 0, en = 1; n     int t; n     scanf( %d , &t); n     if (t == 1) st = 1; n     if (t == 0) en = 0; n     for (k = 0; k < i; k++) { n       for (l = 0; k + l < i; l++) { n         m = i - 1 - k - l; n         if (st == 0) { n           long long c0 = cnt[l][1] * po2[k + m] % MOD; n           long long c1 = cnt[l][0] * po2[k + m] % MOD; n           dp[k + 1][l][m] += c1 * dp[k][l][m] % MOD; n           dp[k][l][m + 1] += c0 * dp[k][l][m] % MOD; n         } n         if (en == 1) { n           long long c0 = cnt[k][1] * po2[l + m] % MOD; n           long long c1 = cnt[k][0] * po2[l + m] % MOD; n           dp[k][l + 1][m] += c1 * dp[k][l][m] % MOD; n           dp[k][l][m + 1] += c0 * dp[k][l][m] % MOD; n         } n       } n     } n     for (j = 0; j <= i; j++) { n       for (k = 0; j + k <= i; k++) { n         l = i - j - k; n         dp[j][k][l] %= MOD; n       } n     } n   } n   long long ans = 0; n   for (i = 0; i <= N; i++) { n     for (j = 0; i + j <= N; j++) { n       k = N - i - j; n       if ((i + j) % 2 == tus) ans = (ans + dp[i][j][k]) % MOD; n     } n   } n   return !printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   double p = 0, x = 0, m, n, i; n   cin >> m >> n; n   for (i = m; i >= 1; i--) { n     p += (1 - pow(((i - 1) / m), n) - x) * i; n     x += 1 - pow(((i - 1) / m), n) - x; n   } n   cout << fixed << setprecision(12) << p; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 40; n int v[N], x[N], ct, al[N], col[N], n, lu[N], lv[N]; n int read() { n   int sum = 0, fg = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) fg = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     sum = sum * 10 + c -  0 ; n     c = getchar(); n   } n   return sum * fg; n } n inline void add(int u, int V) { n   v[++ct] = V; n   x[ct] = al[u]; n   al[u] = ct; n } n inline void dfs(int u, int tw) { n   col[u] = tw; n   for (int i = al[u]; i; i = x[i]) n     if (col[v[i]] == -1) dfs(v[i], tw ^ 1); n } n int main() { n   n = read(); n   for (int i = 1; i <= n; i++) col[i] = -1; n   for (register int i = 1, x, y; i <= n; i++) { n     x = read(); n     y = read(); n     if (lu[x]) { n       add(lu[x], i); n       add(i, lu[x]); n       lu[x] = 0; n     } else n       lu[x] = i; n     if (lv[y]) { n       add(lv[y], i); n       add(i, lv[y]); n       lv[y] = 0; n     } else n       lv[y] = i; n   } n   for (register int i = 1; i <= n; i++) n     if (col[i] == -1) dfs(i, 0); n   for (register int i = 1; i <= n; i++) n     if (col[i] == 0) n       cout <<  b ; n     else n       cout <<  r ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long m, ans; n string ss, s; n long long i; n int main() { n   cin >> s; n   for (i = 0; i + 4 < s.length(); i++) { n     ss = s.substr(i, 5); n     if (ss ==  heavy ) { n       m++; n     } n     if (ss ==  metal ) { n       ans += m; n     } n   } n   cout << ans << endl; n   return 0; n } n