#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     int n, x; n     cin >> n >> x; n     int arr[n]; n     int o, e; n     o = e = 0; n     int i = 0; n     for (int j = 0; j < 10; j++) { n     } n     for (int j = 0; j < 10; j++) { n     } n     for (int j = 0; j < 10; j++) { n     } n     while (i < n) { n       int x; n       cin >> x; n       if (x % 2 == 0) { n         e++; n       } else n         o++; n       i++; n     } n     if (o == 0) n       cout <<  No  << endl; n     else { n       bool pos = false; n       i = 1; n       while (i <= o) { n         if (i > x) break; n         if ((x - i) <= e) { n           pos = true; n           break; n         } n         i = i + 2; n       } n       if (!pos) n         cout <<  No  << endl; n       else n         cout <<  Yes  << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a, mx = 0; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a; n     if (a > mx) mx = a; n   } n   if (mx - 25 > 0) n     cout << mx - 25 << endl; n   else n     cout << 0 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, dp[25][1100000], ans = 1e9; n char num[25][100005]; n int main() { n   cin >> n >> m; n   for (int i = 1; i <= n; ++i) scanf( %s , num[i] + 1); n   for (int i = 1; i <= m; ++i) { n     int t = 0; n     for (int j = 1; j <= n; ++j) t = t * 2 + num[j][i] -  0 ; n     ++dp[0][t]; n   } n   for (int i = 1; i <= n; ++i) n     for (int j = 0; j < 1 << n; ++j) { n       for (int k = 1; k < 1 << n; k <<= 1) n         dp[i][j] = dp[i][j] + dp[i - 1][j ^ k]; n       if (i >= 2) dp[i][j] = dp[i][j] + (i - 2 - n) * dp[i - 2][j]; n       dp[i][j] /= i; n     } n   for (int i = 1; i < 1 << n; ++i) { n     int t = 0; n     for (int j = 0; j <= n; ++j) t += min(j, n - j) * dp[j][i]; n     ans = min(ans, t); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long c, w, v, a, l, pages, days = 1; n   cin >> c >> v >> w >> a >> l; n   pages = v; n   while (pages < c) { n     v += a; n     if (v > w) v = w; n     pages = pages - l + v; n     days++; n   } n   cout << days; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, x, y; n struct node { n   int L, R, e; n   long long int Lsum, Rsum, Ls, Rs; n   int mid() { return (L + R) / 2; } n } a[200005 * 4]; n void BuildTree(int r, int L, int R) { n   a[r].L = L; n   a[r].R = R; n   a[r].e = 0; n   a[r].Lsum = 0; n   a[r].Rsum = 0; n   a[r].Ls = 0; n   a[r].Rs = 0; n   if (L == R) return; n   BuildTree(r << 1 | 1, L, a[r].mid()); n   BuildTree(r << 1, a[r].mid() + 1, R); n   a[r].Lsum = a[r << 1 | 1].Lsum + a[r << 1].Lsum; n   a[r].Rsum = a[r << 1 | 1].Rsum + a[r << 1].Rsum; n   a[r].Ls = a[r << 1 | 1].Ls + a[r << 1].Ls; n   a[r].Rs = a[r << 1 | 1].Rs + a[r << 1].Rs; n } n void Update(int r, int L, int v) { n   if (a[r].L == a[r].R && a[r].L == L) { n     int kk = a[r].e; n     a[r].e += v; n     if (a[r].e >= y && kk < y) { n       a[r].Lsum++; n       a[r].Ls -= kk; n     } n     if (a[r].e >= x && kk < x) { n       a[r].Rs -= kk; n       a[r].Rsum++; n     } n     if (a[r].e < y) a[r].Ls = a[r].e; n     if (a[r].e < x) a[r].Rs = a[r].e; n     return; n   } n   if (L > a[r].mid()) n     Update(r << 1, L, v); n   else n     Update(r << 1 | 1, L, v); n   a[r].Lsum = a[r << 1 | 1].Lsum + a[r << 1].Lsum; n   a[r].Rsum = a[r << 1 | 1].Rsum + a[r << 1].Rsum; n   a[r].Ls = a[r << 1 | 1].Ls + a[r << 1].Ls; n   a[r].Rs = a[r << 1 | 1].Rs + a[r << 1].Rs; n } n long long int Qurry(int r, int L, int R, int b) { n   if (L > R) return 0; n   if (a[r].L == L && a[r].R == R) { n     if (b == 1) n       return a[r].Lsum * y + a[r].Ls; n     else if (b == 2) n       return a[r].Rsum * x + a[r].Rs; n   } n   if (L > a[r].mid()) n     return Qurry(r << 1, L, R, b); n   else if (R <= a[r].mid()) n     return Qurry(r << 1 | 1, L, R, b); n   else { n     long long a1 = Qurry(r << 1 | 1, L, a[r].mid(), b); n     long long a2 = Qurry(r << 1, a[r].mid() + 1, R, b); n     return a1 + a2; n   } n } n int main() { n   int q; n   while (scanf( %d , &n) != EOF) { n     memset(a, 0, sizeof(0)); n     int u, v; n     BuildTree(1, 1, n); n     scanf( %d %d %d %d , &k, &x, &y, &q); n     while (q--) { n       int kk; n       scanf( %d , &kk); n       if (kk == 1) { n         scanf( %d %d , &u, &v); n         Update(1, u, v); n       } else { n         scanf( %d , &u); n         long long int sum1 = Qurry(1, 1, u - 1, 1); n         long long int sum2 = Qurry(1, u + k, n, 2); n         printf( %lld n , sum1 + sum2); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int MOD = 1000000007; n const long long BIG = 1446803456761533460LL; n const int Big = 336860180; n const long long int INF = LONG_LONG_MAX; n const long long int adj4[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; n const long long int adj8[8][2] = {{0, 1},   {0, -1}, {1, 0},  {-1, 0}, n                                   {-1, -1}, {1, -1}, {-1, 1}, {1, 1}}; n long long int clk_ar[10]; n long long int gcd(long long int a, long long int b) { n   return b == 0 ? a : gcd(b, a % b); n } n long long int powMod(long long int a, long long int b) { n   long long int n = 1; n   long long int p = a; n   while (b > 0) { n     if (b % 2 == 1) { n       n *= p; n       n %= MOD; n     } n     p *= p; n     p %= MOD; n     b /= 2; n   } n   return n; n } n long long int modularInverse(long long int a) { return powMod(a, MOD - 2); } n stringstream sss; n const long long int maxn = 150010; n const long long int maxm = 310; n long long int dp[2][maxn]; n long long int ts[maxm]; n long long int ai[maxm]; n void MAIN() { n   long long int n, m, V; n   cin >> n >> m >> V; n   long long int sb = 0; n   for (long long int i = 0; i < (m); ++i) { n     long long int b; n     cin >> ai[i + 1] >> b >> ts[i + 1]; n     --ai[i + 1]; n     sb += b; n   } n   for (long long int i = (1); i < (m + 1); ++i) { n     long long int d = (ts[i] - ts[i - 1]) * V; n     deque<long long int> q; n     for (long long int j = 0; j < (min(d, n)); ++j) { n       while (!q.empty() && dp[i & 1 ^ 1][j] >= dp[i & 1 ^ 1][q.back()]) { n         q.pop_back(); n       } n       q.push_back(j); n     } n     for (long long int j = 0; j < (n); ++j) { n       if (j + d < n) { n         while (!q.empty() && dp[i & 1 ^ 1][j + d] >= dp[i & 1 ^ 1][q.back()]) { n           q.pop_back(); n         } n         q.push_back(j + d); n       } n       dp[i & 1][j] = dp[i & 1 ^ 1][q.front()] - abs(j - ai[i]); n       if (q.front() == j - d) { n         q.pop_front(); n       } n     } n   } n   cout << (sb + *max_element(dp[m & 1], dp[m & 1] + n)) <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cout << fixed << setprecision(10); n   sss << R ( n 50 3 1 n 49 1 1 n 26 1 4 n 6 1 10 n     ) ; n   MAIN(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   int* x = new int[2 * n]; n   int odd = 0; n   int even = n; n   int len = n - 1; n   for (int len = n - 1, i = 1; len > 0; len--, i++) n     if (i % 2 == 1) { n       x[odd] = i; n       x[odd + len] = i; n       odd++; n     } else { n       x[even] = i; n       x[even + len] = i; n       even++; n     } n   x[2 * n - 1] = n; n   if (n % 2 == 0) n     x[even] = n; n   else n     x[odd] = n; n   int s = 0; n   for (int i = 0; i < 2 * n; i++) printf( %d  , x[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool issorted(long long int *arr, int n) { n   int flag = 0; n   for (int i = 1; i < n; i++) { n     if (arr[i - 1] > arr[i]) { n       flag = 1; n       break; n     } n   } n   if (flag == 0) return true; n   flag = 0; n   for (int i = n - 2; i >= 0; i--) { n     if (arr[i + 1] > arr[i]) { n       flag = 1; n       break; n     } n   } n   if (flag == 0) return true; n   return false; n } n int main(void) { n   int n; n   cin >> n; n   long long int arr[n]; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   long long int flag = 0; n   for (int i = 1; i < n; i++) { n     if (arr[i] != arr[i - 1]) { n       flag = 1; n       break; n     } n   } n   if (flag == 0 || n <= 2) n     cout <<  -1  << endl; n   else if (n == 3 && arr[0] == arr[2]) n     cout <<  -1  << endl; n   else { n     flag = 0; n     for (int i = 1; i < n; i++) { n       if (arr[i] != arr[i - 1]) { n         long long int swap = arr[i]; n         arr[i] = arr[i - 1]; n         arr[i - 1] = swap; n         if (!issorted(arr, n)) { n           cout << i + 1 <<     << i << endl; n           break; n         } else { n           swap = arr[i]; n           arr[i] = arr[i - 1]; n           arr[i - 1] = swap; n         } n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int MDA[10000010]; n int MDB[10000010]; n int main() { n   long long a, b, m; n   int i; n   cin >> a >> b >> m; n   for (i = 0; i < (min(m, a + 1)); i++) { n     MDA[i] = (i * 1000000000) % m; n   } n   for (i = 0; i < (min(m, b + 1)); i++) { n     MDB[(i) % m] = 1; n   } n   int ans = 2, mov; n   for (i = 0; i < (min(m, a + 1)); i++) { n     if (MDB[(m - MDA[i]) % m] == 0) { n       ans = 1; n       mov = i; n       break; n     } n   } n   cout << ans; n   if (ans == 1) { n     cout <<    ; n     char str[100]; n     sprintf(str,  %ld , mov); n     string s = str; n     while (s.size() != 9) s =  0  + s; n     cout << s; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n int main() { n   int n, k; n   cin >> n >> k; n   if (k / n > 2) n     cout <<  0 n ; n   else n     cout << n - (k % n) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100010; n int num[maxn]; n map<int, int> mp; n int sum[maxn]; n int main() { n   int n, i, j, k; n   cin >> n; n   for (i = 1; i <= n; i++) cin >> num[i], sum[i] = sum[i - 1] + num[i]; n   int s = 0; n   long long ans = 0; n   for (i = 1; i < n; i++) { n     int tmp = sum[n] - sum[i]; n     if (sum[i] == 2 * tmp) { n       ans += mp[tmp]; n     } n     mp[sum[i]]++; n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int MOD = 1e9 + 7; n int a[100001], n, num, siz = 0, sq; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   vector<int> kill(n, 1); n   stack<int> s; n   s.push(0); n   kill[0] = 1000000000; n   for (int i = 1; i < n; i++) { n     while (!s.empty() && a[i] > a[s.top()]) { n       kill[i] = max(kill[s.top()] + 1, kill[i]); n       s.pop(); n     } n     s.push(i); n   } n   num = 0; n   for (int i = 0; i < n; i++) n     if (kill[i] < 1000000000) num = max(num, kill[i]); n   cout << num; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n int t, n, m, sum; n int fa[1000010], sz[1000010]; n vector<int> vec[1000010]; n int find(int x) { n   if (x == fa[x]) n     return x; n   else n     return fa[x] = find(fa[x]); n } n int main() { n   ios_base::sync_with_stdio(false); n   t = 1; n   while (t--) { n     cin >> n >> m; n     for (int i = 1; i <= m; ++i) { n       vec[i].clear(); n       sz[i] = 0; n       fa[n + i] = n + i; n     } n     for (int i = 1; i <= n; ++i) { n       int x; n       cin >> x; n       sz[x + n]++; n       vec[x + n].push_back(i); n       fa[i] = x + n; n     } n     sum = 0; n     for (int i = 2; i <= n; ++i) { n       if (find(i) == find(i - 1)) { n         sum++; n       } n     } n     cout << n - sum - 1 <<   n ; n     for (int i = 1; i <= m - 1; ++i) { n       int x, y; n       cin >> x >> y; n       int fx = find(x + n), fy = find(y + n); n       if (sz[fx] < sz[fy]) { n         for (int j = 0; j < vec[fx].size(); ++j) { n           if ((vec[fx][j] > 1 && find(vec[fx][j] - 1) == fy)) sum++; n           if ((vec[fx][j] < n && find(vec[fx][j] + 1) == fy)) sum++; n           vec[fy].push_back(vec[fx][j]); n           sz[fy]++; n         } n         sz[fx] = 0; n         fa[fx] = fy; n       } else { n         for (int j = 0; j < vec[fy].size(); ++j) { n           if ((vec[fy][j] > 1 && find(vec[fy][j] - 1) == fx)) sum++; n           if ((vec[fy][j] < n && find(vec[fy][j] + 1) == fx)) sum++; n           vec[fx].push_back(vec[fy][j]); n           sz[fx]++; n         } n         sz[fy] = 0; n         fa[fy] = fx; n       } n       cout << n - sum - 1 <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using std ::vector; n template <typename Tp> n Tp Max(const Tp &a, const Tp &b) { n   return a > b ? a : b; n } n template <typename Tp> n Tp Min(const Tp &a, const Tp &b) { n   return a < b ? a : b; n } n template <typename Tp> n Tp Abs(const Tp &a) { n   return a > 0 ? a : -a; n } n template <typename Tp> n void Read(Tp &x) { n   Tp in = 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     in = in * 10 + ch -  0 ; n     ch = getchar(); n   } n   x = in * f; n } n const int SN = 200000 + 10; n vector<int> G[SN]; n int a[SN], b[SN], c[SN], min[SN], n; n int res0[SN], res1[SN]; n long long ans; n void pre(int u, int fa) { n   for (auto v : G[u]) n     if (v != fa) min[v] = Min(min[v], min[u]); n   for (auto v : G[u]) n     if (v != fa) pre(v, u); n } n void Dfs(int u, int fa) { n   if (b[u] != c[u]) n     if (b[u] == 0) n       res0[u]++; n     else n       res1[u]++; n   for (auto v : G[u]) n     if (v != fa) Dfs(v, u), res1[u] += res1[v], res0[u] += res0[v]; n   int K = Min(res0[u], res1[u]); n   ans += 2LL * K * min[u]; n   res0[u] -= K, res1[u] -= K; n } n int main(int argc, const char *argv[]) { n   Read(n); n   for (int i = 1; i <= n; i++) n     Read(a[i]), Read(b[i]), Read(c[i]), min[i] = a[i]; n   int u, v; n   for (int i = 1; i < n; i++) { n     Read(u), Read(v); n     G[u].push_back(v); n     G[v].push_back(u); n   } n   u = 0, v = 0; n   for (int i = 1; i <= n; i++) { n     if (b[i] == 0) u++; n     if (c[i] == 0) v++; n   } n   if (u != v) { n     printf( -1 n ); n     return 0; n   } n   pre(1, 0); n   Dfs(1, 0); n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = (int)1e9 + 7; n const int MAXN = (int)3e5 + 3; n const int infint = (int)1e9 + 3; n const long long inf = (long long)2e18; n struct node { n   int minf, tedf, mimm, tmimm, mipm, tmipm, min, max, lazymax, lazymin; n   node() { n     minf = infint, tedf = 0; n     mimm = infint, tmimm = 0; n     mipm = infint, tmipm = 0; n     min = infint, max = -infint; n     lazymax = -1, lazymin = -1; n   } n } seg[4 * MAXN]; n void updmax(int node, int st, int en, int x) { n   seg[node].max = x; n   seg[node].mipm = st + seg[node].max, seg[node].tmipm = 1; n   seg[node].minf = seg[node].mimm + seg[node].max, n   seg[node].tedf = seg[node].tmimm; n   seg[node].lazymax = x; n   return; n } n void updmin(int node, int st, int en, int x) { n   seg[node].min = x; n   seg[node].mimm = st - seg[node].min, seg[node].tmimm = 1; n   seg[node].minf = seg[node].mipm - seg[node].min, n   seg[node].tedf = seg[node].tmipm; n   seg[node].lazymin = x; n } n void shift(int node, int st, int en) { n   int mid = (st + en) >> 1; n   if (seg[node].lazymax != -1) n     updmax(node << 1, st, mid, seg[node].lazymax), n         updmax(node << 1 | 1, mid, en, seg[node].lazymax); n   if (seg[node].lazymin != -1) n     updmin(node << 1, st, mid, seg[node].lazymin), n         updmin(node << 1 | 1, mid, en, seg[node].lazymin); n   seg[node].lazymax = seg[node].lazymin = -1; n } n node merge(node a, node b) { n   node c; n   c.min = min(a.min, b.min); n   c.max = max(a.max, b.max); n   c.minf = a.minf, c.tedf = a.tedf; n   if (b.minf < c.minf) n     c.minf = b.minf, c.tedf = b.tedf; n   else if (b.minf == c.minf) n     c.tedf += b.tedf; n   c.mimm = a.mimm, c.tmimm = a.tmimm; n   if (b.mimm < c.mimm) n     c.mimm = b.mimm, c.tmimm = b.tmimm; n   else if (b.mimm == c.mimm) n     c.tmimm += b.tmimm; n   c.mipm = a.mipm, c.tmipm = a.tmipm; n   if (b.mipm < c.mipm) n     c.mipm = b.mipm, c.tmipm = b.tmipm; n   else if (b.mipm == c.mipm) n     c.tmipm += b.tmipm; n   c.lazymax = -1, c.lazymin = -1; n   return c; n } n void updatemax(int node, int st, int en, int l, int r, int x) { n   if (l >= en || st >= r) return; n   if (l <= st && en <= r) { n     updmax(node, st, en, x); n     return; n   } n   int mid = (st + en) >> 1; n   shift(node, st, en); n   updatemax(node << 1, st, mid, l, r, x); n   updatemax(node << 1 | 1, mid, en, l, r, x); n   seg[node] = merge(seg[node << 1], seg[node << 1 | 1]); n } n void updatemin(int node, int st, int en, int l, int r, int x) { n   if (l >= en || st >= r) return; n   if (l <= st && en <= r) { n     updmin(node, st, en, x); n     return; n   } n   int mid = (st + en) >> 1; n   shift(node, st, en); n   updatemin(node << 1, st, mid, l, r, x); n   updatemin(node << 1 | 1, mid, en, l, r, x); n   seg[node] = merge(seg[node << 1], seg[node << 1 | 1]); n } n node emp; n node get(int node, int st, int en, int l, int r) { n   if (l >= en || st >= r) { n     emp.minf = infint, emp.tedf = 0; n     emp.mimm = infint, emp.tmimm = 0; n     emp.mipm = infint, emp.tmipm = 0; n     emp.min = infint, emp.max = -infint; n     emp.lazymax = -1, emp.lazymin = -1; n     return emp; n   } n   if (l <= st && en <= r) return seg[node]; n   int mid = (st + en) >> 1; n   shift(node, st, en); n   return merge(get(node << 1, st, mid, l, r), n                get(node << 1 | 1, mid, en, l, r)); n } n int n, a[MAXN], s[MAXN], g[MAXN]; n int zero[MAXN], oc[MAXN], prv[MAXN]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (int i = 0; i < 4 * MAXN; i++) seg[i] = node(); n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     a[i]--; n   } n   for (int i = 0; i < n; i++) n     if (a[i] == 0) n       zero[i] = i; n     else if (i == 0) n       zero[i] = -1; n     else n       zero[i] = zero[i - 1]; n   memset(oc, -1, sizeof oc); n   for (int i = 0; i < n; i++) { n     prv[i] = oc[a[i]], oc[a[i]] = i; n     if (i) prv[i] = max(prv[i], prv[i - 1]); n   } n   for (int i = 0; i < n; i++) prv[i]++; n   stack<int> S; n   for (int i = 0; i < n; i++) { n     while (!S.empty() && a[S.top()] > a[i]) S.pop(); n     if (S.size()) n       s[i] = S.top(); n     else n       s[i] = -1; n     S.push(i); n   } n   while (S.size()) S.pop(); n   for (int i = 0; i < n; i++) { n     while (!S.empty() && a[S.top()] < a[i]) S.pop(); n     if (S.size()) n       g[i] = S.top(); n     else n       g[i] = -1; n     S.push(i); n   } n   long long ans = 0; n   for (int i = 0; i < n; i++) { n     updatemin(1, 0, n, s[i] + 1, i + 1, a[i]); n     updatemax(1, 0, n, g[i] + 1, i + 1, a[i]); n     if (prv[i] <= zero[i]) { n       node cur = get(1, 0, n, prv[i], zero[i] + 1); n       if (cur.minf == i) ans += cur.tedf; n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1000010; n const int s = 1000000; n int n; n int b[maxn]; n int p[maxn]; n int c[maxn]; n vector<int> ans; n int main() { n   scanf( %d , &n); n   int t; n   for (int i = 0; i < n; ++i) { n     scanf( %d , &t); n     b[t] = 1; n     p[i] = t; n   } n   int l = 1; n   for (int i = 0; i < n; ++i) { n     if (c[p[i]] == 0) { n       if (b[s - p[i] + 1] == 0) { n         ans.push_back(s - p[i] + 1); n         b[s - p[i] + 1] = 1; n       } else { n         while (b[l] || b[s - l + 1]) { n           l++; n         } n         ans.push_back(l); n         b[l] = 1; n         ans.push_back(s - l + 1); n         b[s - l + 1] = 1; n         c[s - p[i] + 1] = 1; n       } n     } n   } n   printf( %ld n , ans.size()); n   for (int i = 0; i < ans.size(); ++i) { n     if (i) printf(   ); n     printf( %d , ans[i]); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e9; n const int MOD = 1e9 + 7; n const int N = 0; n string s; n long long solve(string s) { n   int n = s.length(); n   long long ans = 1988; n   for (auto i = (n - 1); i >= (4); i--) { n     long long mul = 1, add = 0; n     for (auto j = (i); j < (n); j++) { n       mul = 10 * mul; n       add = 10 * add + s[j] -  0 ; n     } n     long long nx = max(mul + ans - add, 0LL) / mul; n     ans = nx * mul + add; n   } n   return ans; n } n int main() { n   int test; n   cin >> test; n   while (test--) { n     cin >> s; n     cout << solve(s) <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n string name[105], body[105]; n int n; n string s; n int d[105]; n map<string, int> macro_id; n int add(string& s, int& ptr); n void go(int k); n int un(string& s, int& ptr) { n   if (s[ptr] ==  ( ) { n     ptr++; n     int r = add(s, ptr); n     if (r & 2) r ^= 2; n     if (r & 4) r ^= 4; n     ptr++; n     return r; n   } n   string id =   ; n   while (ptr < s.size() && (isalpha(s[ptr]) || isdigit(s[ptr]))) { n     id += s[ptr++]; n   } n   if (macro_id.count(id)) { n     int k = macro_id[id]; n     go(k); n     return d[k]; n   } else { n     return 0; n   } n } n int mul(string& s, int& ptr) { n   int ret = un(s, ptr); n   int cnt = 1; n   char last_op =  * ; n   bool f = true; n   while (ptr < s.size() && (s[ptr] ==  *  || s[ptr] ==  / )) { n     if (f && (ret & 2)) { n       ret |= 1; n     } n     f = false; n     last_op = s[ptr]; n     ptr++; n     int next = un(s, ptr); n     if (next & 4) ret |= 4; n     if (next & 1) ret |= 1; n     if (next & 2) ret |= 1; n     if (last_op ==  /  && (next & 4)) ret |= 1; n     cnt++; n   } n   if (cnt > 1) ret |= 4; n   return ret; n } n int add(string& s, int& ptr) { n   int ret = mul(s, ptr); n   int cnt = 1; n   char last_op =  + ; n   while (ptr < s.size() && (s[ptr] ==  +  || s[ptr] ==  - )) { n     last_op = s[ptr]; n     ptr++; n     int next = mul(s, ptr); n     if (next & 2) ret |= 2; n     if (next & 1) ret |= 1; n     if (last_op ==  -  && (next & 2)) ret |= 1; n     cnt++; n   } n   if (cnt > 1) { n     if (ret & 4) ret ^= 4; n     ret |= 2; n   } n   return ret; n } n void go(int k) { n   if (d[k] != -1) { n     return; n   } n   string str = body[k]; n   int ptr = 0; n   int code = add(str, ptr); n   d[k] = code; n } n int main() { n   scanf( %d n , &n); n   for (int i = 0; i < int(n); i++) { n     getline(cin, s); n     while (s[0] ==    ) s.erase(0, 1); n     s.erase(0, 1); n     while (s[0] ==    ) s.erase(0, 1); n     s.erase(0, 7); n     while (s[0] ==    ) s.erase(0, 1); n     int p = s.find(   ); n     name[i] = s.substr(0, p); n     s.erase(0, p + 1); n     for (int j = 0; j < int(s.size()); j++) { n       if (s[j] !=    ) { n         body[i] += s[j]; n       } n     } n     macro_id[name[i]] = i; n   } n   getline(cin, s); n   for (int j = 0; j < int(s.size()); j++) { n     if (s[j] !=    ) { n       body[n] += s[j]; n     } n   } n   for (int i = 0; i < int(n + 1); i++) { n     d[i] = -1; n   } n   go(n); n   if (d[n] & 1) { n     printf( Suspicious n ); n   } else { n     printf( OK n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int NMAX = 200005; n int n; n char str[NMAX]; n int in, allin; n int main() { n   ios_base ::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n; n   cin >> str; n   for (int i = 0; i < n; ++i) n     if (str[i] ==  A ) n       ++allin; n     else if (str[i] ==  I ) n       ++in; n   if (!in) n     cout << allin <<   n ; n   else n     cout << (in == 1 ? 1 : 0) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n int a, b, n; n long long ans; n int chk[10000010]; n int np, pri[10000010]; n int lis[10000010], mon[10000010]; n void go(int now, int poi) { n   lis[now] = 1; n   for (int i = poi; i < np; ++i) { n     long long t = (long long)now * pri[i]; n     if (t > n) break; n     go(t, i + 1); n   } n } n void solve() { n   for (int i = 2; i * i <= n; ++i) n     if (chk[i] == 0) n       for (int j = i * i; j <= n; j += i) chk[j] = 1; n   for (int i = 2; i <= n; ++i) n     if (chk[i] == 0) { n       pri[np] = i; n       ++np; n     } n   go(1, 0); n   for (int i = n, j = -1; i >= 1; --i) { n     if (lis[i] == 1) { n       lis[i] = j; n       j = i; n     } n   } n   for (int i = 1; i != -1; i = lis[i]) { n     for (int j = 1;; ++j) { n       int t = j * j * i; n       if (j * j * i > n) break; n       mon[t] = i; n     } n   } n } n int main(void) { n   scanf( %d%d , &a, &n); n   b = a + n - 1; n   n = b; n   solve(); n   for (int i = a; i <= b; ++i) ans += mon[i]; n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3009; n int box[N], kk; n struct node { n   int t, next; n } e[N << 1]; n int n; n void add(int s, int t) { n   e[kk].t = t, e[kk].next = box[s]; n   box[s] = kk++; n } n int tot; n void pre_dfs(int r, int fa) { n   for (int i = box[r]; i + 1; i = e[i].next) n     if (e[i].t != fa) { n       pre_dfs(e[i].t, r); n       tot += i & 1; n     } n } n int cut; n void dfs(int r, int fa, int now) { n   cut = max(now, cut); n   for (int i = box[r]; i + 1; i = e[i].next) n     if (e[i].t != fa) { n       if (i & 1) n         dfs(e[i].t, r, now + 1); n       else n         dfs(e[i].t, r, max(now - 1, 0)); n     } n } n int main() { n   memset(box, -1, sizeof(box)); n   cin >> n; n   for (int i = 1; i < n; i++) { n     int s, t; n     cin >> s >> t; n     add(s, t); n     add(t, s); n   } n   int ans = N; n   for (int i = 1; i <= n; i++) { n     tot = 0; n     pre_dfs(i, i); n     cut = 0; n     dfs(i, i, 0); n     ans = min(tot - cut, ans); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e3 + 5; n int a[maxn], n, x; n int main() { n   int k; n   cin >> k; n   while (k--) { n     cin >> n >> x; n     int sum = 0; n     bool f = 1, f1 = 0; n     for (int i = 1; i <= n; i++) { n       cin >> a[i]; n       sum += a[i]; n       if (a[i] != x) f = 0; n       if (a[i] == x) f1 = 1; n     } n     if (f == 1) n       cout << 0 << endl; n     else if (sum == n * x || f1 == 1) n       cout << 1 << endl; n     else n       cout << 2 << endl; n   } n   return 0; n } n


#include<bits/stdc++.h> n  n typedef long long ll; n typedef long double ld; n using namespace std; n mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count()); n #define ii for(int i=1;i<=n;++i) n #define ji for(int j=1;j<=n;++j) n #define jj for(int j=1;j<=m;++j) n #define ij for(int i=1;i<=m;++i) n #define all(x) x.begin(),x.end() n #define al(x) x+1,x+1+n n #define asd cout<< ok <<endl; n #define vi vector<int> n #define vvi vector<vector<int>> n #define vl vector<ll> n #define vii vector<pair<int,int>> n #define pc(x) __builtin_popcount(x) n #define pb push_back n  n vector<int> a[200005]; n vector<pair<int,int>> r[200005]; n int cnt[200005]; n inline int read() { n     char c=getchar();int x=0,f=1; n     while(c< 0 ||c> 9 ) {if(c== - ) f=-1;c=getchar();} n     while(c>= 0 &&c<= 9 )x=x*10+c- 0 ,c=getchar(); n     return x*f; n } n int main() { n     int t = read(); n     while(t--) { n         int n = read(); n         int sz = 0; n         for(int i=1;i<=n;++i) a[i].clear(); n         vector<int> aa; n         for(int i=1;i<=n;++i) { n             int x = read(); n             sz += x; n             while(x--) { n                 int y = read(); n                 a[i].push_back(y); n                 aa.push_back(y); n             } n         } n         sort(aa.begin(), aa.end()); n         aa.resize(unique(aa.begin(), aa.end()) - aa.begin()); n         auto f = [&](int x) { n             return lower_bound(aa.begin(), aa.end(), x) - aa.begin() + 1; n         }; n         for(int i=1;i<=n;++i) { n             for(int &j:a[i]) j=f(j); n             sort(all(a[i])); n         } n         int sq = pow(sz, 0.4), ok = 0; n         for(int i=1;i<=n;++i) { n             if(a[i].size() > sq) { n                 for(int j:a[i]) cnt[j]++; n                 for(int j=1;j<=n;++j) { n                     if(i==j) continue; n                     int cnt2=0; n                     for(int k:a[j]) cnt2+=cnt[k]; n                     if(cnt2>1) { n                         printf( %d %d n , i, j); n                         ok=1; n                         break; n                     } n                 } n                 for(int j:a[i]) cnt[j]--; n             } else { n                 for(int j=0;j<a[i].size();++j) { n                     for(int k=j+1;k<a[i].size();++k) { n                         r[a[i][j]].push_back({a[i][k], i}); n                     } n                 } n             } n             if(ok) break; n         } n         if(!ok) { n             for(int i=1;i<=aa.size();++i) { n                 sort(all(r[i])); n                 for(int j=1;j<r[i].size();++j) { n                     if(r[i][j].first == r[i][j-1].first) { n                         ok = 1; n                         printf( %d %d n , r[i][j].second, r[i][j-1].second); n                         break; n                     } n                 } n                 if(ok) break; n             } n         } n         for(int i=1;i<=aa.size();++i) r[i].clear(); n         if(!ok) puts( -1 ); n     } n }


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1010; n int c1, c2; n char str[maxn]; n int main() { n   scanf( %s , str); n   int len = int(strlen(str)); n   for (int i = 0; i < len; i++) { n     int t = str[i] -  0 ; n     if (t == 0) { n       if (!c1) { n         puts( 1 1 ); n       } else n         puts( 3 1 ); n       c1 ^= 1; n     } else { n       if (!c2) { n         puts( 4 3 ); n       } else n         puts( 4 1 ); n       c2 ^= 1; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long labs(long long a) { return a < 0 ? (-a) : a; } n long long max(long long a, long long b) { return a > b ? a : b; } n long long min(long long a, long long b) { return a < b ? a : b; } n const int MAXN = 1005; n const int UNDEF = -1; n const int IMPOS = INT_MAX - 2; n char f[MAXN][MAXN]; n int dph[MAXN], dpv[MAXN]; n int n, m; n int RecV(int i); n int RecH(int j) { n   if (dph[j] != UNDEF) return dph[j]; n   dph[j] = IMPOS; n   for (int i = 0; i < n; i++) { n     if (f[i][j] ==  # ) { n       dph[j] = min(dph[j], RecV(i) + 1); n     } n   } n   return dph[j]; n } n int RecV(int i) { n   if (dpv[i] != UNDEF) return dpv[i]; n   dpv[i] = IMPOS; n   for (int j = 0; j < m; j++) { n     if (f[i][j] ==  # ) { n       dpv[i] = min(dpv[i], RecH(j) + 1); n     } n   } n   return dpv[i]; n } n int main() { n   cin >> n >> m; n   fill(dph, dph + MAXN, UNDEF); n   fill(dpv, dpv + MAXN, UNDEF); n   for (int(i) = 0; (i) < (n); (i)++) { n     cin >> f[i]; n   } n   dpv[n - 1] = 0; n   int res = RecV(0); n   if (res == IMPOS) { n     res = -1; n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[503400], b[477574], c[534567], d, e, i, j, r, m, y, k, l, n, s, z, n     x, t, tt; n string p[3456], q, qq; n map<long long, long long> zz; n int main() { n   cin >> n >> m; n   for (i = 1; i <= n; i++) cin >> p[i]; n   cin >> x; n   q = p[x]; n   a[x] = 1; n   t = q.size(); n   for (i = 1; i < m; i++) { n     cin >> y; n     a[y] = 1; n     if (p[y].size() != t) { n       cout <<  No ; n       return 0; n     } n     for (j = 0; j < t; j++) { n       if (q[j] ==  ? ) continue; n       if (p[y][j] != q[j]) q[j] =  ? ; n     } n   } n   for (i = 1; i <= n; i++) { n     if (a[i] == 1) continue; n     if (p[i].size() != t) continue; n     x = 0; n     for (j = 0; j < t; j++) { n       if (q[j] ==  ? ) continue; n       if (q[j] != p[i][j]) x = 1; n     } n     if (x == 0) { n       cout <<  No ; n       return 0; n     } n   } n   cout <<  Yes  << endl << q; n } n


#include <iostream> n #include <algorithm> n #include <vector> n using namespace std; n typedef vector<int> vi; n int n,a[300010],res[300010],gtm[300010]; n vi  L,R,rm; n void solve() { n  cin >> n; n  for (int i = 0; i < n; i++) cin >> a[i]; n  L.assign(n,0); R.assign(n,0); n  rm.assign(n + 1, 0); n  L[0] = 0;  n  for (int i = 1; i < n; i++) { n   if (a[i] > a[i - 1]) L[i] = i; n   else { n    int j = L[i - 1]; n    while (j > 0 && a[j - 1] >= a[i]) j = L[j - 1]; n    L[i] = j; n   } n  } n  R[n - 1] = n - 1; n  for (int i = n - 2; i >= 0; i--) { n   if (a[i] > a[i + 1]) R[i] = i; n   else { n    int j = R[i + 1]; n    while (j < n - 1 && a[j + 1] >= a[i]) j = R[j + 1]; n    R[i] = j; n   } n  } n  for (int i = 0; i < n; i++) { n   int x = R[i] - L[i] + 1; n   rm[a[i]] = max(rm[a[i]], x); n  } n   n  gtm[1] = rm[1]; n  for (int i = 2; i <= n; i++) { n   gtm[i] = min(gtm[i - 1], rm[i]); n  } n  n  for (int i = n; i >= 1; i--) { n   int k = n - i + 1; n   res[k] = (gtm[i] >= k); n  } n  for (int i = 1; i <= n; i++) cout << res[i]; n  cout << endl; n } n int main() n { n  int t; cin >> t; n  while(t--) solve(); n // system( pause ); n     return 0; n } n  n


#include <bits/stdc++.h> n using namespace std; n bool need[8000010], rem[8000010]; n int n, k, b[8000010], sum[8000010], minl = (int)1e9, out; n vector<int> ans; n int main() { n   scanf( %d%d , &k, &n); n   for (int i = 1; i <= k; i++) scanf( %d , &sum[i]), sum[i] += sum[i - 1]; n   for (int i = 1; i <= n; i++) scanf( %d , &b[i]), minl = min(b[i], minl); n   for (int i = 1; i <= k; i++) ans.push_back(minl - sum[i]); n   for (int i = 0; i < ans.size(); i++) { n     for (int j = 1; j <= n; j++) need[b[j] + 4000000] = 1; n     int x = ans[i], tot = 0; n     if (rem[x] == 1) continue; n     rem[x] = 1; n     for (int j = 1; j <= k; j++) { n       tot += need[x + sum[j] + 4000000]; n       need[x + sum[j] + 4000000] = 0; n     } n     if (tot == n) out++; n   } n   cout << out << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int k, t = 0, tt = 0, j = -1; n int kk; n int main() { n   cin >> k >> kk; n   if (k == 5) { n     cout <<  >...v  << endl; n     cout <<  v.<..  << endl; n     cout <<  ..^..  << endl; n     cout <<  >....  << endl; n     cout <<  ..^.<  << endl; n     cout << 1 <<     << 1; n   } else if (k == 3) { n     cout <<  >vv  << endl; n     cout <<  ^<.  << endl; n     cout <<  ^.<  << endl; n     cout << 1 <<     << 3; n   } else { n     for (int j = 0; j < 100; j++) { n       if (j == 0) { n         for (int i = 0; i < 50; i++) { n           cout <<  > ; n         } n         for (int i = 50; i < 74; i++) { n           cout <<  > ; n           cout <<  . ; n         } n         cout <<  > ; n         cout <<  v ; n       } else if (j == 99) { n         cout <<  ^ ; n         cout <<  . ; n         cout <<  . ; n         cout <<  < ; n         for (int i = 0; i < 23; i++) { n           cout <<  . ; n           cout <<  < ; n         } n         for (int i = 50; i < 100; i++) { n           cout <<  < ; n         } n       } else if (j % 2 == 1) { n         cout <<  ^ ; n         cout <<  v ; n         cout <<  . ; n         cout <<  < ; n         for (int i = 0; i < 23; i++) { n           cout <<  . ; n           cout <<  < ; n         } n         for (int i = 50; i < 100; i++) { n           cout <<  < ; n         } n       } else if (j % 2 == 0) { n         cout <<  ^ ; n         for (int i = 1; i < 50; i++) { n           cout <<  > ; n         } n         for (int i = 50; i < 74; i++) { n           cout <<  . ; n           cout <<  > ; n         } n         cout <<  . ; n         cout <<  v ; n       } n       cout << endl; n     } n     cout << 1 <<     << 1; n   } n } n


#include <bits/stdc++.h> n using namespace std; n signed long long int a, b; n long long int a1, b1, y, s; n int main() { n   cin >> a >> b >> s; n   if (a >= 0) n     a1 = a; n   else n     a1 = 0 - a; n   if (b >= 0) n     b1 = b; n   else n     b1 = 0 - b; n   y = a1 + b1; n   if (y - s == 0 || (y - s) % 2 == 0) { n     if (s >= y) n       cout <<  Yes ; n     else n       cout <<  No ; n   } else n     cout <<  No ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int T; n   cin >> T; n   while (T--) { n     int S; n     cin >> S; n     string str; n     cin >> str; n     for (int i = 0; i < S; i++) cout << str[S - 1]; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = (int)1e9 + 7; n const int INF = (int)1e9; n const long long LINF = (long long)1e18; n const long double PI = acos((long double)-1); n const long double EPS = 1e-9; n long long gcd(long long a, long long b) { n   long long r; n   while (b) { n     r = a % b; n     a = b; n     b = r; n   } n   return a; n } n long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n long long fpow(long long n, long long k, int p = MOD) { n   long long r = 1; n   for (; k; k >>= 1) { n     if (k & 1) r = r * n % p; n     n = n * n % p; n   } n   return r; n } n void addmod(int& a, int val, int p = MOD) { n   if ((a = (a + val)) >= p) a -= p; n } n void submod(int& a, int val, int p = MOD) { n   if ((a = (a - val)) < 0) a += p; n } n int mult(int a, int b, int p = MOD) { return (long long)a * b % p; } n int inv(int a, int p = MOD) { return fpow(a, p - 2, p); } n int arr[2000005] = {0}; n int foo(int n) { n   int maxsize = -1, startindex; n   int sumleft[n]; n   int min, max; n   int i; n   sumleft[0] = ((arr[0] == 0) ? -1 : 1); n   min = arr[0]; n   max = arr[0]; n   for (i = 1; i < n; i++) { n     sumleft[i] = sumleft[i - 1] + ((arr[i] == 0) ? -1 : 1); n     if (sumleft[i] < min) min = sumleft[i]; n     if (sumleft[i] > max) max = sumleft[i]; n   } n   int hash[max - min + 1]; n   for (i = 0; i < max - min + 1; i++) hash[i] = -1; n   for (i = 0; i < n; i++) { n     if (sumleft[i] == 0) { n       maxsize = i + 1; n       startindex = 0; n     } n     if (hash[sumleft[i] - min] == -1) n       hash[sumleft[i] - min] = i; n     else { n       if ((i - hash[sumleft[i] - min]) > maxsize) { n         maxsize = i - hash[sumleft[i] - min]; n         startindex = hash[sumleft[i] - min] + 1; n       } n     } n   } n   if (maxsize == -1) maxsize = 0; n   return maxsize; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   string s; n   cin >> s; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  1 ) arr[i] = 1; n   } n   cout << foo(n); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int pow1(long long int a, long long int b, n                    long long int m = 1000000007) { n   if (b == 0) n     return 1ll; n   else if (b == 1) n     return a; n   else { n     long long int x = pow1(a, b / 2, m); n     x *= x; n     x %= m; n     if (b % 2) { n       x *= a; n       x %= m; n     } n     return x; n   } n } n template <class avgType> n avgType avg(avgType a, avgType b) { n   return (a + b) / 2; n } n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count()); n int randInt() { return rng() % INT_MAX; } n long long int randLL() { return rng64() % LLONG_MAX; } n vector<int> hashmods = {1000000007, 1000000009, 1000000021, n                         1000000033, 1000000087, 1000000093}; n long long int n, k, a[110000], t; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> t; n   while (t--) { n     cin >> n >> k; n     int pres = 0; n     for (int i = 1; i <= n; i++) { n       cin >> a[i]; n       pres += (a[i] == k); n     } n     if (pres == 0) { n       cout <<  no n ; n       continue; n     } n     if (n == 1) { n       cout <<  yes n ; n       continue; n     } else if (n == 2 and a[1] >= k and a[2] >= k) { n       cout <<  yes n ; n       continue; n     } n     int yes = 0, less = 0, more = 0, presk = 0; n     for (int i = 1; i <= n - 2; i++) { n       int m = (a[i] >= k) + (a[i + 1] >= k) + (a[i + 2] >= k); n       if (m >= 2) { n         yes++; n       } n     } n     cout << (yes ?  yes n  :  no n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, ans[1500], t, i, j, v[1100]; n   memset(v, 0, sizeof(v)); n   for (i = 2; i * i <= 1100; i++) { n     if (v[i] == 0) { n       for (j = i + i; j <= 1100; j += i) v[j] = 1; n     } n   } n   while (scanf( %d , &n) != EOF) { n     if (n == 1) n       printf( 0 n ); n     else { n       t = 0; n       for (j = 2; j <= n; j++) { n         if (v[j] == 0) { n           for (i = j; i <= n; i *= j) { n             ans[t] = i; n             t++; n           } n         } n       } n       printf( %d n , t); n       for (i = 0; i < t - 1; i++) printf( %d  , ans[i]); n       printf( %d n , ans[t - 1]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int M = 1000000007; n long long int mod(long long int x) { return (x % M + M) % M; } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int n, t, c, ans = 0, g = 0, cnt = 0; n   cin >> n >> t >> c; n   long long int arr[n]; n   for (long long int i = 0; i < n; ++i) { n     cin >> arr[i]; n   } n   for (long long int i = 0; i < n; i++) { n     g++; n     if (arr[i] > t) { n       g = 0; n     } else { n       if (g >= c) ans += 1; n     } n   } n   cout << ans << endl; n   cerr << fixed << setprecision(10); n   cerr <<  time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline bool upmin(T &x, T y) { n   return y < x ? x = y, 1 : 0; n } n template <typename T> n inline bool upmax(T &x, T y) { n   return x < y ? x = y, 1 : 0; n } n const long double eps = 1e-11; n const long double pi = acos(-1); n const long long oo = 1 << 30; n const long long loo = 1ll << 62; n const long long mods = 998244353; n const long long MAXN = 200005; n const long long INF = 0x3f3f3f3f; n inline long long read() { n   long long f = 1, x = 0; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     x = (x << 3) + (x << 1) + (c ^ 48); n     c = getchar(); n   } n   return x * f; n } n long long Ans[1005], num = 0; n long long solve(long long x, long long y) { n   if (!y) return x; n   Ans[++num] = x / y; n   long long t = solve(y, x % y); n   return t; n } n signed main() { n   long long x = read(), y = read(); n   if (solve(x, y) != 1) { n     puts( Impossible ); n     return 0; n   } n   Ans[num]--; n   for (long long i = 1; i <= num; i++) n     if (Ans[i] > 0) printf( %lld , Ans[i]), putchar(66 - (i & 1)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   std::ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n, m, i, j, k, d; n   cin >> n >> m; n   vector<int> arr(101, 0); n   for (i = 0; i < m; i++) { n     int no; n     cin >> no; n     arr[no]++; n   } n   for (d = m; d >= 1; d--) { n     vector<int> cc(arr); n     int k = 0; n     for (i = 0; i < cc.size(); i++) { n       if (cc[i] >= d) { n         k += (floor(cc[i] / d)); n       } n     } n     if (k >= n) { n       cout << d << endl; n       return 0; n     } n   } n   cout << 0 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using LL = long long; n constexpr int N = 5002; n constexpr int mod = 1e9 + 7; n string x, y; n int n, m; n int cache[N][N]; n int dp(int a, int b) { n   if (b == m) return 0; n   int &rv = cache[a][b]; n   if (~rv) return rv; n   rv = dp(a, b + 1); n   if (x[a] == y[b]) rv += 1 + dp(a + 1, b + 1), rv %= mod; n   return rv; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cin >> x >> y; n   n = x.size(), m = y.size(); n   memset(cache, -1, sizeof cache); n   dp(0, 0); n   int result = 0; n   for (int i = 0; i < n; i++) result += dp(i, 0), result %= mod; n   cout << result << endl; n } n


#include <bits/stdc++.h> n const int inf = 0x3f3f3f3f, Inf = 0x7fffffff; n const long long INF = 0x7fffffffffffffff; n const double eps = 1e-10; n unsigned int seed = 19260817; n const unsigned int _RAND_MAX_ = 4294967295u; n __inline__ __attribute__((always_inline)) unsigned int Rand() { n   return seed = seed * 998244353u + 1000000007u; n } n template <typename _Tp> n _Tp gcd(const _Tp &a, const _Tp &b) { n   return (!b) ? a : gcd(b, a % b); n } n template <typename _Tp> n __inline__ __attribute__((always_inline)) _Tp abs(const _Tp &a) { n   return a >= 0 ? a : -a; n } n template <typename _Tp> n __inline__ __attribute__((always_inline)) _Tp max(const _Tp &a, const _Tp &b) { n   return a < b ? b : a; n } n template <typename _Tp> n __inline__ __attribute__((always_inline)) _Tp min(const _Tp &a, const _Tp &b) { n   return a < b ? a : b; n } n template <typename _Tp> n __inline__ __attribute__((always_inline)) void chmax(_Tp &a, const _Tp &b) { n   (a < b) && (a = b); n } n template <typename _Tp> n __inline__ __attribute__((always_inline)) void chmin(_Tp &a, const _Tp &b) { n   (b < a) && (a = b); n } n template <typename _Tp> n __inline__ __attribute__((always_inline)) bool _cmp(const _Tp &a, n                                                     const _Tp &b) { n   return abs(a - b) <= eps; n } n template <typename _Tp> n __inline__ __attribute__((always_inline)) void read(_Tp &x) { n   register char ch(getchar()); n   bool f(false); n   while (ch < 48 || ch > 57) f |= ch == 45, ch = getchar(); n   x = ch & 15, ch = getchar(); n   while (ch >= 48 && ch <= 57) n     x = (((x << 2) + x) << 1) + (ch & 15), ch = getchar(); n   if (f) x = -x; n } n template <typename _Tp, typename... Args> n __inline__ __attribute__((always_inline)) void read(_Tp &t, Args &...args) { n   read(t); n   read(args...); n } n __inline__ __attribute__((always_inline)) int read_str(char *s) { n   register char ch(getchar()); n   while (ch ==     || ch ==   r  || ch ==   n ) ch = getchar(); n   register char *tar = s; n   *tar = ch, ch = getchar(); n   while (ch !=     && ch !=   r  && ch !=   n  && ch != EOF) n     *(++tar) = ch, ch = getchar(); n   return tar - s + 1; n } n const int N = 300005; n const int mod = 1000000007; n const long long inv2 = 500000004; n struct matrix { n   long long a, b, c, d, e, f; n   __inline__ __attribute__((always_inline)) matrix operator*( n       const matrix &o) const { n     return (matrix){a * o.a % mod, n                     (b * o.a + c * o.b) % mod, n                     c * o.c % mod, n                     (d * o.a + e * o.b + f * o.d) % mod, n                     (e * o.c + f * o.e) % mod, n                     f * o.f % mod}; n   } n } I; n __inline__ __attribute__((always_inline)) matrix get1(long long x) { n   return (matrix){1ll, x * inv2 % mod, inv2, 0, x * inv2 % mod, 1ll}; n } n __inline__ __attribute__((always_inline)) matrix get2(long long x) { n   return (matrix){1ll, mod - x, 2ll, (x * x) % mod * inv2 % mod, mod - x, 1ll}; n } n int t[N << 1]; n int a[N]; n int b[N << 1]; n struct seg_tr { n   struct Node { n     int ls, rs; n     matrix val; n   } f[N << 2]; n   int node_cnt; n   __inline__ __attribute__((always_inline)) void PushUp(int x) { n     f[x].val = f[f[x].ls].val * f[f[x].rs].val; n   } n   int build(int l, int r) { n     int cur = ++node_cnt; n     if (l == r) { n       matrix res(I), a = get1(t[l]); n       while (b[l]) res = res * a, --b[l]; n       f[cur].val = res; n       return cur; n     } n     int mid = (l + r) >> 1; n     f[cur].ls = build(l, mid); n     f[cur].rs = build(mid + 1, r); n     PushUp(cur); n     return cur; n   } n   void Update1(int l, int r, int pos, int cur) { n     if (l == r) { n       f[cur].val = f[cur].val * get1(t[l]); n       return; n     } n     int mid = (l + r) >> 1; n     if (pos <= mid) n       Update1(l, mid, pos, f[cur].ls); n     else n       Update1(mid + 1, r, pos, f[cur].rs); n     PushUp(cur); n   } n   void Update2(int l, int r, int pos, int cur) { n     if (l == r) { n       f[cur].val = f[cur].val * get2(t[l]); n       return; n     } n     int mid = (l + r) >> 1; n     if (pos <= mid) n       Update2(l, mid, pos, f[cur].ls); n     else n       Update2(mid + 1, r, pos, f[cur].rs); n     PushUp(cur); n   } n   __inline__ __attribute__((always_inline)) long long Query() { n     return f[1].val.d; n   } n } tr; n int Q[N][2]; n int main() { n   I = (matrix){1ll, 0ll, 1ll, 0ll, 0ll, 1ll}; n   int n; n   read(n); n   int pos = 0; n   for (int i = 1; i <= n; ++i) { n     read(a[i]); n     t[++pos] = a[i]; n   } n   int q; n   read(q); n   for (int i = 1; i <= q; ++i) { n     read(Q[i][0], Q[i][1]); n     t[++pos] = Q[i][1]; n   } n   std::sort(t + 1, t + pos + 1); n   pos = std::unique(t + 1, t + pos + 1) - t - 1; n   for (int i = 1; i <= n; ++i) { n     a[i] = std::lower_bound(t + 1, t + pos + 1, a[i]) - t; n     ++b[a[i]]; n   } n   tr.build(1, pos); n   printf( %lld n , tr.Query()); n   for (int i = 1; i <= q; ++i) { n     Q[i][1] = std::lower_bound(t + 1, t + pos + 1, Q[i][1]) - t; n     tr.Update2(1, pos, a[Q[i][0]], 1); n     tr.Update1(1, pos, Q[i][1], 1); n     a[Q[i][0]] = Q[i][1]; n     printf( %lld n , tr.Query()); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct $ { n   $() { n     ios_base::sync_with_stdio(false); n     cin.tie(NULL); n   } n } $; n const int Maxn = 202005; n class BIT { n   int *tree, sz; n  n  public: n   BIT() { n     sz = 202005; n     tree = new int[sz + 1]; n   } n   BIT(int N) { n     sz = N; n     tree = new int[N + 1]; n   } n   ~BIT() { delete[] tree; } n   void update(int idx, int Val) { n     if (idx < 1 || idx > sz) return; n     while (idx <= sz) { n       tree[idx] += Val; n       idx += idx & -idx; n     } n   } n   int read(int idx) { n     int Sum = 0; n     while (idx > 0) { n       Sum += tree[idx]; n       idx -= (idx & -idx); n     } n     return Sum; n   } n   int rangeSum(int l, int r) { n     int Ret = read(r) - read(l - 1); n     Ret = max(0, Ret); n     return Ret; n   } n   int readSingle(int idx) { n     int sum = tree[idx]; n     if (idx > 0) { n       int z = idx - (idx & -idx); n       idx--; n       while (idx != z) { n         sum -= tree[idx]; n         idx -= (idx & -idx); n       } n     } n     return sum; n   } n }; n int T1[Maxn], T2[Maxn]; n int main() { n   int n, k, a, b, q, type, d, val; n   cin >> n >> k >> a >> b >> q; n   BIT B1, B2; n   while (q--) { n     cin >> type; n     if (type == 1) { n       cin >> d >> val; n       if (T1[d] < a) { n         int temp = min(val, a - T1[d]); n         T1[d] += temp; n         B1.update(d, temp); n       } n       if (T2[d] < b) { n         int temp = min(val, b - T2[d]); n         T2[d] += temp; n         B2.update(d, temp); n       } n     } else { n       cin >> d; n       int Ans = 0; n       Ans = B2.rangeSum(1, d - 1); n       int z = B1.rangeSum(min(d + k, Maxn - 1), Maxn - 1); n       Ans += z; n       cout << Ans << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3fffffff; n const int SINF = 0x7fffffff; n const long long LINF = 0x3fffffffffffffff; n const long long SLINF = 0x7fffffffffffffff; n const int MAXN = 65; n const int MAXB = 10; n const int MAXS = (1 << 10) + 7; n int q; n int b; n long long l, r; n int a[MAXN]; n long long dp[MAXB + 3][MAXN][MAXS]; n void init(); n void input(); n void inputq(); n void work(); n long long getans(long long x); n int main() { n   init(); n   input(); n   work(); n } n void init() { n   ios::sync_with_stdio(false); n   for (int i = 2; i <= MAXB; ++i) { n     int ms = (1 << i); n     dp[i][0][0] = 1; n     for (int j = 1; j < MAXN; ++j) { n       for (int k = 0; k < ms; ++k) { n         for (int x = 0; x < i; ++x) { n           dp[i][j][k ^ (1 << x)] += dp[i][j - 1][k]; n         } n       } n     } n   } n } n void input() { scanf( %d , &q); } n void inputq() { scanf( %d%I64d%I64d , &b, &l, &r); } n void work() { n   for (int i = 0; i < q; ++i) { n     inputq(); n     printf( %I64d n , getans(r) - getans(l - 1)); n   } n } n long long getans(long long x) { n   if (!x) return 0; n   int n = 0; n   for (long long t = x; t; t /= b) { n     a[n++] = t % b; n   } n   long long ans = 0; n   int beg, ns = 0; n   for (int i = n - 1; i >= 0; --i) { n     beg = (i == n - 1) ? 1 : 0; n     for (int j = beg; j < a[i]; ++j) { n       ans += dp[b][i][ns ^ (1 << j)]; n     } n     ns ^= (1 << a[i]); n   } n   if (!ns) ++ans; n   for (int i = n - 2; i >= 0; --i) { n     for (int j = 1; j < b; ++j) ans += dp[b][i][1 << j]; n   } n   return ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e3 + 7; n const int mod = 1e9 + 7; n map<int, int> mp; n int n, x, ma, ans; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &x); n     mp[x]++; n   } n   for (auto p : mp) { n     int x = p.first, y = p.second; n     for (int i = 1; i <= 20; i++) { n       if ((y >> i) & 1) { n         mp[x + i]++; n         mp[x] -= (1 << i); n       } n     } n   } n   for (auto p : mp) { n     int x = p.first, y = p.second; n     for (int i = 1; i <= 20; i++) { n       if ((y >> i) & 1) { n         mp[x + i]++; n         mp[x] -= (1 << i); n       } n     } n   } n   for (auto p : mp) { n     int x = p.first, y = p.second; n     ; n     if (y != 0) { n       ans++; n       ma = max(ma, x); n     } n   } n   printf( %d n , ma + 1 - ans); n } n


#include<iostream> n #include<cstdio> n #include<fstream> n #include<algorithm> n #include<vector> n #include<map> n #include<set> n #include<queue> n #include<bitset> n #include<cmath> n #include<cstring> n #include<cstdlib> n using namespace std; n typedef long long LL; n typedef double DB; n const int N = 222222; n const int W = 1111111; n int n,m,q,a[N],b[N]; n LL sa,sb; n int w=1e6+1,t[W]; n LL g[W]; n multiset<int> A,B; n multiset<int>::iterator it; n void ad(int x,int y){ n  int z=x*y; n  x++; n  while(x<=w){ n   t[x]+=y; n   g[x]+=z; n   x+=x&-x; n  } n } n void qu(int x,int&y,LL&z){ n  x++; n  while(x){ n   y+=t[x]; n   z+=g[x]; n   x-=x&-x; n  } n } n LL ansb(int p){ n  int o=min(*A.begin(),*B.begin()); n  if(p<=o) n   return sa-(LL)p*n-sb+(LL)p*m; n  int x=0; n  LL y=0; n  qu(p,x,y); n  return sa-(LL)o*n-sb+(LL)p*(m-x)+y; n } n LL ansa(int p){ n  int o=min(*A.begin(),*B.begin()); n  if(p<=o) n   return ansb(p); n  return ansb(p)-(p-o); n } n int main() n { n  int i,x,y,o; n  LL s; n  scanf( %d%d%d ,&n,&m,&q); n  for(i=1;i<=n;i=i+1){ n   scanf( %d ,a+i); n   sa+=a[i]; n   A.insert(a[i]); n  } n  for(i=1;i<=m;i=i+1){ n   scanf( %d ,b+i); n   sb+=b[i]; n   ad(b[i],1); n   B.insert(b[i]); n  } n  while(q--){ n   scanf( %d%d ,&i,&x); n   if(i<=2){ n    scanf( %d ,&y); n    if(i==1){ n     A.erase(A.find(a[x])); n     sa-=a[x]; n     A.insert(y); n     sa+=y; n     a[x]=y; n    } n    else{ n     B.erase(B.find(b[x])); n     sb-=b[x]; n     ad(b[x],-1); n     B.insert(y); n     sb+=y; n     ad(y,1); n     b[x]=y; n    } n   } n   else{ n    s=max(ansb(*B.begin()-x),ansb(*B.rbegin()-x)); n    s=max(s,max(ansa(*A.begin()-x),ansa(*A.rbegin()-x))); n    o=min(*A.begin(),*B.begin()); n    it=A.lower_bound(o+x); n    if(it!=A.end()) n     s=max(s,ansa(*it-x)); n    if(it!=A.begin()){ n     it--; n     s=max(s,ansa(*it-x)); n    } n    it=A.lower_bound(*B.rbegin()+x); n    if(it!=A.end()) n     s=max(s,ansa(*it-x)); n    if(it!=A.begin()){ n     it--; n     s=max(s,ansa(*it-x)); n    } n    printf( %lld n ,s); n   } n  } n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n const long long mod = 998244353; n const long long N = 200005; n int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1}; n int dy[] = {0, -1, 0, 1, 1, -1, 1, -1}; n long long powmod(long long a, long long b) { n   long long res = 1; n   a %= mod; n   assert(b >= 0); n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n   } n   return res; n } n long long powb(long long a, long long b) { n   long long res = 1; n   a; n   assert(b >= 0); n   for (; b; b >>= 1) { n     if (b & 1) res = res * a; n     a = a * a; n   } n   return res; n } n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n void test() { n   int n, k; n   cin >> n >> k; n   vector<int> a(n), b(k), inda(n), vis(n); n   set<pair<int, int> > s; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     a[i]--; n     inda[a[i]] = i; n     s.insert({i, a[i]}); n   } n   for (int i = 0; i < k; i++) { n     cin >> b[i]; n     b[i]--; n     vis[b[i]] = 1; n   } n   long long ans = 1; n   for (int i = 0; i < k; i++) { n     int idx = inda[b[i]]; n     auto pos = s.find({idx, a[idx]}); n     int inc = 0; n     if (pos != s.begin()) { n       if (vis[(*(prev(pos))).second] == 0) { n         inc++; n       } n     } n     if (next(pos) != s.end()) { n       if (vis[(*(next(pos))).second] == 0) inc++; n     } n     (ans *= 1LL * inc) %= mod; n     vis[b[i]] = 0; n   } n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t = 1; n   cin >> t; n   while (t--) { n     test(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 1e7 + 10; n int n, fac[MAX_N], pri[MAX_N], pri_n, fac_cnt[MAX_N], phi[MAX_N]; n long long ans; n void init() { n   scanf( %d , &n); n   for (int i = 2; i <= n; i++) { n     if (!fac[i]) { n       phi[i] = (fac[i] = pri[++pri_n] = i) - 1; n       fac_cnt[i] = 1; n     } n     for (int j = 1; j <= pri_n && pri[j] * i <= n && pri[j] <= fac[i]; j++) { n       fac[pri[j] * i] = pri[j]; n       fac_cnt[pri[j] * i] = fac_cnt[i] + (pri[j] == fac[i] ? 0 : 1); n       phi[pri[j] * i] = phi[i] * (pri[j] - (pri[j] == fac[i] ? 0 : 1)); n     } n   } n } n long long get_pair_suc() { n   long long suc = 0; n   for (int i = 2; i <= n; i++) n     if (i * 2 <= n || fac[i] != i) suc++; n   return suc * (suc - 1) / 2; n } n long long get_pair_1() { n   long long res = 0; n   for (int i = 2; i <= n; i++) res += i - 1 - phi[i]; n   return res; n } n long long get_pair_2() { n   static int pref_fac[MAX_N]; n   int pref_pri = 0; n   long long res = 0; n   for (int i = 2; i <= n; i++) { n     if (fac[i] == i) n       pref_pri++; n     else n       res += phi[i] - (pref_pri - fac_cnt[i]) - 1; n   } n   for (int i = 2; i <= n; i++) pref_fac[fac[i]]++; n   for (int i = 2; i <= n; i++) pref_fac[i] += pref_fac[i - 1]; n   for (int i = 2; i <= n; i++) { n     if (fac[i] != i) continue; n     int lim = n / fac[i]; n     res += pref_fac[lim]; n     for (int j = i; j <= n; j += i) n       if (fac[j] <= lim) res--; n   } n   for (int i = 2; i <= n; i++) n     if (fac_cnt[i] == 2 && fac[i / fac[i]] == i / fac[i]) res--; n   return res; n } n void solve() { n   long long pair_suc = get_pair_suc(); n   long long pair_1 = get_pair_1(); n   long long pair_2 = get_pair_2(); n   long long pair_3 = pair_suc - pair_1 - pair_2; n   long long ans = pair_1 * 1 + pair_2 * 2 + pair_3 * 3; n   printf( %lld n , ans); n } n int main() { n   init(); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n struct ASDF { n   ASDF& operator,(int& a) { n     scanf( %d , &a); n     return *this; n   } n   ASDF& operator,(long int& a) { n     scanf( %ld , &a); n     return *this; n   } n   ASDF& operator,(long long int& a) { n     scanf( %lld , &a); n     return *this; n   } n   ASDF& operator,(char& c) { n     scanf( %c , &c); n     return *this; n   } n   ASDF& operator,(double& d) { n     scanf( %lf , &d); n     return *this; n   } n   template <typename T> n   ASDF& operator,(T& a) { n     cin >> a; n     return *this; n   } n } asdf; n template <typename T> n ostream& operator<<(ostream& output, vector<T>& v) { n   output <<  [  ; n   if (int(v.size())) { n     output << v[0]; n   } n   for (int i = 1; i < int(v.size()); i++) { n     output <<  ,   << v[i]; n   } n   output <<   ] ; n   return output; n } n template <typename T1, typename T2> n ostream& operator<<(ostream& output, pair<T1, T2>& p) { n   output <<  (   << p.first <<  ,   << p.second <<   ) ; n   return output; n } n int main() { n   int n, k; n   vector<int> v; n   cin >> n >> k; n   v.resize(n); n   for (int i = 0; i < n; i++) cin >> v[i]; n   long long sum = 0; n   for (int i = 0; i < n; i++) { n     if (k > 0 && v[i] < 0) { n       v[i] = -v[i]; n       k--; n     } n   } n   if (k & 1) { n     sort(v.begin(), v.end()); n     v[0] = -v[0]; n   } n   for (int i = 0; i < n; i++) sum += v[i]; n   cout << sum << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, k; n long long read() { n   long long s = 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     s = s * 10 + ch -  0 ; n     ch = getchar(); n   } n   return s * f; n } n long long cnt = 0; n struct trie { n   long long ch[26]; n   long long fail; n   long long tail; n } t[10010]; n long long f(char c) { n   if (c ==  A ) return 0; n   if (c ==  C ) return 1; n   if (c ==  T ) n     return 2; n   else n     return 3; n } n void insert(string s) { n   long long l = s.size(); n   long long nw = 0; n   for (long long i = 0, iend = l - 1; i <= iend; ++i) { n     if (t[nw].ch[f(s[i])] == 0) { n       t[nw].ch[f(s[i])] = ++cnt; n     } n     nw = t[nw].ch[f(s[i])]; n   } n   t[nw].tail = l; n } n void bfs() { n   queue<long long> q; n   for (long long i = 0, iend = 25; i <= iend; ++i) { n     if (t[0].ch[i]) { n       t[t[0].ch[i]].fail = 0; n       q.push(t[0].ch[i]); n     } n   } n   while (!q.empty()) { n     long long nw = q.front(); n     q.pop(); n     for (long long i = 0, iend = 25; i <= iend; ++i) { n       if (t[nw].ch[i] != 0) { n         t[t[nw].ch[i]].fail = t[t[nw].fail].ch[i]; n         t[t[nw].ch[i]].tail = n             max(t[t[nw].ch[i]].tail, t[t[t[nw].ch[i]].fail].tail); n         q.push(t[nw].ch[i]); n       } else { n         t[nw].ch[i] = t[t[nw].fail].ch[i]; n       } n     } n   } n } n const long long inf = 1e16; n long long dp[1010][1010][11]; n const long long mod = 1e9 + 9; n signed main() { n   n = read(), m = read(); n   long long l = 0; n   for (long long i = 1, iend = m; i <= iend; ++i) { n     string s; n     cin >> s; n     long long ss = s.size(); n     l = max(l, ss); n     insert(s); n   } n   bfs(); n   dp[0][0][0] = 1; n   for (long long i = 0, iend = n - 1; i <= iend; ++i) { n     for (long long j = 0, jend = cnt; j <= jend; ++j) { n       long long v; n       for (long long k = 0, kend = l; k <= kend; ++k) { n         v = dp[i][j][k]; n         if (v) { n           for (long long p = 0, pend = 3; p <= pend; ++p) { n             long long nw = t[j].ch[p]; n             if (t[nw].tail > k) n               (dp[i + 1][nw][0] += v) %= mod; n             else if (k < l) n               (dp[i + 1][nw][k + 1] += v) %= mod; n           } n         } n       } n     } n   } n   long long ans = 0; n   for (long long i = 0, iend = cnt; i <= iend; ++i) { n     (ans += dp[n][i][0]) %= mod; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename S, typename T> n inline bool smin(S &l, T r) { n   return r < l ? l = r, 1 : 0; n } n template <typename S, typename T> n inline bool smax(S &l, T r) { n   return l < r ? l = r, 1 : 0; n } n constexpr int MOD = 1e9 + 7; n template <typename S> n inline S mod(S &l) { n   return l = (l % MOD + MOD) % MOD; n } n template <typename S, typename T> n inline S add(S &l, T r) { n   return mod(l += r); n } n void fileIO(string s) { n   freopen((s +  .in ).c_str(),  r , stdin); n   freopen((s +  .out ).c_str(),  w , stdout); n } n constexpr int N = 1e5 + 10; n constexpr int SQ = 780; n int n, k; n vector<int> vec[N]; n int bias, dp[2][SQ], pd[2]; n inline void input() { n   cin >> n >> k; n   for (int i = 0; i < k; i++) { n     int x, y; n     cin >> x >> y; n     vec[y].push_back(n - x + 1); n   } n } n inline void faze_0() { n   for (int i = 1; i < n + 1; i++) { n     sort(vec[i].begin(), vec[i].end()); n     while (vec[i].size() && vec[i].back() >= SQ - 2) { n       bias++; n       vec[i].pop_back(); n     } n   } n } n inline void faze_1() { n   memset(dp[0], 63, sizeof(dp)); n   dp[0][0] = 0; n   for (int i = 1; i < n + 1; i++) { n     int me = i & 1, num = 0; n     pd[me] = 1e9; n     for (int j = min(n - i + 1, SQ - 2); ~j; j--) { n       dp[me][j] = num * 3 + min(dp[me ^ 1][j + 1], n                                 pd[me ^ 1] + (j ? 2 : 0) + j * (j + 1) / 2); n       smin(pd[me], dp[me][j]); n       if (vec[i].size() && vec[i].back() == j) { n         num++; n         vec[i].pop_back(); n       } n     } n   } n } n int main() { n   input(); n   faze_0(); n   faze_1(); n   cout << 3 * bias + pd[n & 1] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     long long a, b, k; n     cin >> a >> b >> k; n     if (k % 2 == 0) n       cout << a * (k / 2) - b * (k / 2) <<   n ; n     else n       cout << a * (k / 2 + 1) - b * (k / 2) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int cnt[7]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int n, i, a, x; n   bool test = true; n   vector<pair<long long int, pair<long long int, long long int>>> v; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> a; n     cnt[a]++; n   } n   x = n / 3; n   if (cnt[1] + cnt[2] + cnt[3] + cnt[4] + cnt[6] != n) test = false; n   if (cnt[1] == x && test) { n     for (i = 1; i <= x; i++) { n       if (cnt[4] > 0) { n         if (cnt[2] > 0) { n           v.push_back({1, {2, 4}}); n           cnt[2]--; n           cnt[4]--; n         } else { n           test = false; n           break; n         } n       } else if (cnt[3] > 0) { n         if (cnt[6] > 0) { n           v.push_back({1, {3, 6}}); n           cnt[3]--; n           cnt[6]--; n         } else { n           test = false; n           break; n         } n       } else if (cnt[2] > 0) { n         if (cnt[6] > 0) { n           v.push_back({1, {2, 6}}); n           cnt[2]--; n           cnt[6]--; n         } else { n           test = false; n           break; n         } n       } n     } n   } else n     test = false; n   if (test && cnt[2] == 0 && cnt[6] == 0 && cnt[3] == 0 && cnt[4] == 0) { n     for (i = 0; i < v.size(); i++) n       cout << v[i].first <<     << v[i].second.first <<     n            << v[i].second.second << endl; n   } else n     cout <<  -1  << endl; n   return 0; n } n


/*#pragma GCC target ( avx2 ) n #pragma GCC optimization ( O3 ) n #pragma GCC optimization ( unroll-loops ) n */ n  n #include<bits/stdc++.h> n using namespace std; n void __print(int x) {cerr << x;} n void __print(long x) {cerr << x;} n void __print(long long x) {cerr << x;} n void __print(unsigned x) {cerr << x;} n void __print(unsigned long x) {cerr << x;} n void __print(unsigned long long x) {cerr << x;} n void __print(float x) {cerr << x;} n void __print(double x) {cerr << x;} n void __print(long double x) {cerr << x;} n void __print(char x) {cerr <<      << x <<     ;} n void __print(const char *x) {cerr <<     << x <<    ;} n void __print(const string &x) {cerr <<     << x <<    ;} n void __print(bool x) {cerr << (x ?  true  :  false );} n  n template<typename T, typename V> n void __print(const pair<T, V> &x) {cerr <<  { ; __print(x.first); cerr <<  , ; __print(x.second); cerr <<  } ;} n template<typename T> n void __print(const T &x) {int f = 0; cerr <<  { ; for (auto &i: x) cerr << (f++ ?  ,  :   ), __print(i); cerr <<  } ;} n void _print() {cerr <<  ] n ;} n template <typename T, typename... V> n void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr <<  ,  ; _print(v...);} n #ifndef ONLINE_JUDGE n #define debug(x...) cerr <<  [  << #x <<  ] = [ ; _print(x) n #else n #define debug(x...) n #endif n  n #define ll long long n #define f first n #define s second n #define Fast ios_base::sync_with_stdio(false);cin.tie(NULL); n typedef pair<ll , pair<ll, ll> > pi; n int pow(int x,int y){ n     int res=1; n     while(y){ n         if(y&1) res*=x; n         y>>=1; n         x*=x; n     } n     return res; n }    n struct Compare { n     constexpr bool operator()(pi const & a, n                               pi const & b) const noexcept n     { return a.first < b.first || (a.first == b.first && a.second.first > b.second.first); } n   n }; n void prefix_function( string s,ll arr[] ) n { n      long long border=0; arr[0]=0; n     for(long long i=1;i<s.size();i++) n     { n       while(border>0 && s[i]!=s[border]) n         border=arr[border-1]; n       n      if(s[i]==s[border]) n          border++; n       else n        border=0; n        n       arr[i]=border; n     } n }//send mod-2 for a^-1 if mod is a prime number n  n ll mod=998244353; n ll add( ll a , ll b) n { n     return (((a%mod)+(b%mod))%mod); n } n ll mul(ll a,ll b) n { n   return (((a%mod)*(b%mod))%mod); n } n ll binpow(ll a, ll b) { n     ll res = 1; n     while (b) { n         if (b & 1) res = mul(res, a); n         a = mul(a, a); n         b >>= 1; n     } n     return res; n } n ll subs(ll a,ll b) n { n     return (((a%mod)-(b%mod)+mod)%mod); n } n ll dv(ll a,ll b) n { n     ll inv=binpow(b,mod-2); n     return mul(a,inv); n } n  n ll dsu_arr[100000]; n ll dsu_sz[100000]; n void dsu(ll n) n { n     for(ll i=0;i<=n;i++) n     { n         dsu_arr[i]=i; n         dsu_sz[i]=1; n     } n } n ll find(ll x) n { n      ll root=x; n     while (root!=dsu_arr[root]) n     { n         root=dsu_arr[root]; n     } n     while(x!=dsu_arr[x]) n     { n         dsu_arr[x]=root; n         x=dsu_arr[x]; n     } n     return root; n } n ll merge(ll x,ll y) n { n     ll root1=find(x); n     ll root2=find(y); n      n     if(root1==root2) n     return 0ll; n   n     if(dsu_sz[x]>dsu_sz[y]){ n     dsu_arr[root2]=root1; n     dsu_sz[root1]+=dsu_sz[root2]; n     } n     else n     { n          dsu_sz[root2]+=dsu_sz[root1]; n         dsu_arr[root1]=root2; n     } n     return 1ll; n } n /* n vector<ll>adj[100005]; n bool vis[100005]; n ll dist[100005]; n void bfs(ll c) n { n   vis[c]=true; n   dist[c]=0; n   queue<ll>q; n   q.push(c); n while(!q.empty()) n { n     ll x=q.front(); n     q.pop(); n     n     for(ll i=0;i<adj[x].size();i++) n     { n         ll y=adj[x][i]; n         if(!vis[y]) n         { n             vis[y]=true; n             dist[y]=dist[x]+1; n              n             q.push(y); n         } n     } n   n } n } n */ n  n int main() n { n     Fast n  ll test; n  cin>>test; n  while(test--) n  { n      ll n; n      cin>>n; n      vector<ll>sura,mura,dp; n      for(ll i=0;i<n;i++) n      { n          ll  k; n          cin>>k; n          if(i%2) n          sura.push_back(k); n          else{ n          mura.push_back(k); n          dp.push_back(0ll); n          } n  n      } n      ll ans=1000000000000000000,ans2=0; n      ll mn=100000000000; n      ll sum=0; n     n      for(ll i=0;i<mura.size();i++) n      { n        sum+=mura[i]; n        mn=min(mn,mura[i]); n        dp[i]=(sum-mn)+(mn*(n-i)); n      //  cout<<dp[i]<<   ; n  n      } n      dp.push_back(100000000000000000); n     // cout<<endl; n            mn=100000000000; n      sum=0; n       for(ll i=0;i<sura.size();i++) n      { n        sum+=sura[i]; n        mn=min(mn,sura[i]); n        ll x=(sum-mn)+(mn*(n-i)); n    n        ans=min(ans,min(dp[i],dp[i+1])+x); n        n  n      } n      cout<<ans<<  n ; n       n  n  n  } n  n  n } n  n  n  n     n        n      n          n  n


#include <bits/stdc++.h> n using namespace std; n long long int n, m; n long long int power(long long int a, long long int b) { n   if (b == 0) return 1; n   long long int sr = power(a, b >> 1); n   long long int r = sr * sr; n   if (b & 1) r = a * r; n   return r; n } n void solve() { n   long long int z = power(2, 0); n   cin >> n; n   vector<long long int> v(n); n   long long int ans = 0; n   long long int p = 1; n   for (long long int i = 0; i < n; i++) cin >> v[i]; n   sort(v.begin(), v.end()); n   long long int count = 0; n   for (long long int i = 0; i < n; i++) { n     if (v[i] >= z) { n       ans += (count * (count - 1) / 2); n       while (v[i] >= z) { n         z = power(2, p); n         p++; n       } n       count = 0; n     } n     count++; n   } n   ans += (count * (count - 1) / 2); n   cout << ans <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int x; n   cin >> x; n   for (long long int i = 1; i <= x; i++) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 5e5 + 5; n long long n, m; n vector<vector<long long> > g(N, vector<long long>()); n vector<long long> d(N, 0), last(N, -1); n vector<long long> path; n long long k = 0; n vector<bool> in_path(N, 0); n vector<pair<long long, long long> > pairs; n long long p = 0; n void dfs(long long v, long long l) { n   d[v] = l; n   if (last[l] != -1) { n     pairs.push_back({last[l] + 1, v + 1}); n     last[l] = -1; n     p++; n   } else { n     last[l] = v; n   } n   for (auto u : g[v]) { n     if (d[u] == 0) { n       dfs(u, l + 1); n       if (in_path[u]) { n         path.push_back(v + 1); n         k++; n         in_path[v] = 1; n       } n     } n   } n   if (d[v] >= (n + 1) / 2 && !in_path[v] && k == 0) { n     path.push_back(v + 1); n     k++; n     in_path[v] = 1; n   } n } n void solve() { n   cin >> n >> m; n   for (long long i = 0; i < m; ++i) { n     long long u, v; n     cin >> u >> v; n     u--; n     v--; n     g[u].push_back(v); n     g[v].push_back(u); n   } n   dfs(0, 1); n   if (k >= (n + 1) / 2) { n     cout <<  PATH n ; n     cout << k <<   n ; n     for (long long i = 0; i < k; ++i) { n       cout << path[i] <<    ; n     } n     cout <<   n ; n   } else { n     cout <<  PAIRING n ; n     cout << p <<   n ; n     for (long long i = 0; i < p; ++i) { n       cout << pairs[i].first <<     << pairs[i].second <<   n ; n     } n   } n   for (long long i = 0; i <= n; ++i) { n     g[i].clear(); n     d[i] = 0; n     last[i] = -1; n     in_path[i] = 0; n   } n   path.clear(); n   pairs.clear(); n   k = 0; n   p = 0; n } n signed main() { n   ios_base::sync_with_stdio(false); n   long long t; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int read() { n   char ch = getchar(); n   int f = 0, x = 1; n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) x = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     f = (f << 1) + (f << 3) + ch -  0 ; n     ch = getchar(); n   } n   return f * x; n } n int ch[2000005][2], fa[2000005], w[2000005], mark[2000005]; n int f[2000005], top, s[2000005], n, k, m; n bool rev[2000005]; n bool isroot(int x) { return ch[fa[x]][0] != x && ch[fa[x]][1] != x; } n void pushdown(int x) { n   if (rev[x]) { n     rev[ch[x][0]] ^= 1; n     rev[ch[x][1]] ^= 1; n     swap(ch[x][0], ch[x][1]); n     rev[x] = 0; n   } n   if (mark[x]) { n     mark[ch[x][0]] = min(mark[ch[x][0]], mark[x]); n     mark[ch[x][1]] = min(mark[ch[x][1]], mark[x]); n     w[ch[x][0]] = min(w[ch[x][0]], mark[x]); n     w[ch[x][1]] = min(w[ch[x][1]], mark[x]); n     mark[x] = 2000000000; n   } n } n void rotate(int x) { n   int y = fa[x], z = fa[y], l, r; n   if (ch[y][0] == x) n     l = 0; n   else n     l = 1; n   r = l ^ 1; n   if (!isroot(y)) { n     if (ch[z][0] == y) n       ch[z][0] = x; n     else n       ch[z][1] = x; n   } n   fa[y] = x; n   fa[x] = z; n   fa[ch[x][r]] = y; n   ch[y][l] = ch[x][r]; n   ch[x][r] = y; n } n void splay(int x) { n   top = 0; n   s[++top] = x; n   for (int i = x; !isroot(i); i = fa[i]) s[++top] = fa[i]; n   while (top) pushdown(s[top--]); n   while (!isroot(x)) { n     int y = fa[x], z = fa[y]; n     if (!isroot(y)) { n       if (ch[z][0] == y ^ ch[y][0] == x) n         rotate(x); n       else n         rotate(y); n     } n     rotate(x); n   } n } n void access(int x) { n   for (int t = 0; x; t = x, x = fa[x]) { n     splay(x); n     ch[x][1] = t; n   } n } n void makeroot(int x) { n   access(x); n   splay(x); n   rev[x] ^= 1; n } n void link(int x, int y) { n   makeroot(x); n   fa[x] = y; n } n int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); } n void dfs(int x) { n   if (ch[x][0] && !isroot(ch[x][0])) { n     mark[ch[x][0]] = min(mark[ch[x][0]], mark[x]); n     w[ch[x][0]] = min(w[ch[x][0]], mark[x]); n     dfs(ch[x][0]); n   } n   if (ch[x][1] && !isroot(ch[x][1])) { n     mark[ch[x][1]] = min(mark[ch[x][1]], mark[x]); n     w[ch[x][1]] = min(w[ch[x][1]], mark[x]); n     dfs(ch[x][1]); n   } n } n int main() { n   memset(w, 0x7f7f7f7f, sizeof(w)); n   memset(mark, 0x7f7f7f7f, sizeof(mark)); n   n = read(); n   k = read(); n   m = read(); n   for (int i = 1; i <= n; i++) { n     f[i] = i; n   } n   for (int i = 1; i <= k; i++) { n     int u = read(), v = read(); n     link(u, n + i); n     link(n + i, v); n     f[find(u)] = find(v); n   } n   for (int i = 1; i <= m; i++) { n     int u = read(), v = read(), w1 = read(); n     int fu = find(u), fv = find(v); n     if (fu == fv) { n       makeroot(u); n       access(v); n       splay(v); n       mark[v] = min(mark[v], w1); n       w[v] = min(w[v], w1); n     } else { n       link(u, i + k + n); n       link(i + k + n, v); n       f[fu] = fv; n     } n   } n   long long ans = 0; n   for (int i = 1; i <= n + k + m; i++) { n     if (isroot(i)) { n       dfs(i); n     } n   } n   for (int i = 1; i <= k; i++) { n     if (w[i + n] >= 2000000000) { n       puts( -1 ); n       return 0; n     } n     ans += w[i + n]; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n bool check(string cards, int a, int b) { n   bool isValid = false; n   for (int j = 0; j < b && !isValid; j++) { n     int shift = 0; n     isValid = true; n     for (int i = 0; i < a; i++, shift += b) { n       if (cards[shift + j] !=  X ) { n         isValid = false; n         break; n       } n     } n   } n   return isValid; n } n int main() { n   int t; n   vector<string> ways; n   cin >> t; n   for (int i = 0; i < t; i++) { n     string cards; n     cin >> cards; n     if (check(cards, 1, 12)) ways.push_back( 1x12 ); n     if (check(cards, 2, 6)) ways.push_back( 2x6 ); n     if (check(cards, 3, 4)) ways.push_back( 3x4 ); n     if (check(cards, 4, 3)) ways.push_back( 4x3 ); n     if (check(cards, 6, 2)) ways.push_back( 6x2 ); n     if (check(cards, 12, 1)) ways.push_back( 12x1 ); n     cout << ways.size() <<    ; n     vector<string>::iterator itr = ways.begin(); n     for (; itr != ways.end(); itr++) cout << *itr <<    ; n     cout << endl; n     ways.clear(); n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int oo = 1e9 + 9; n const long long inf = 1e18 + 18; n const int max6 = 1e6 + 6; n const int modx = 1e9 + 123; n const int mody = 997; n const int base = 137; n int t[max6]; n int n, k; n bool ok(int l, int r) { n   int cnt = 0; n   for (int i = l; i <= r; ++i) cnt += t[i] == 1; n   if (cnt) return false; n   int cur = 0; n   for (int i = r + 1; i <= n; ++i) { n     if (t[i] == 2) n       cur++; n     else n       cur = 0; n     if (cur > k) return false; n   } n   for (int i = 1; i < l; ++i) { n     if (t[i] == 2) n       cur++; n     else n       cur = 0; n     if (cur > k) return false; n   } n   return true; n } n int main() { n   cin >> n >> k; n   string s; n   cin >> s; n   for (int i = 1; i <= n; ++i) n     if (s[i - 1] ==  Y ) n       t[i] = 1; n     else if (s[i - 1] ==  N ) n       t[i] = 2; n     else if (s[i - 1] ==  ? ) n       t[i] = 3; n   int res = 0; n   for (int i = 1; i <= n; ++i) n     if (i == 1 || t[i - 1] == 1 || t[i - 1] == 3) { n       int j = i + k - 1; n       if (j == n || t[j + 1] == 1 || t[j + 1] == 3) n         if (ok(i, j)) res = 1; n     } n   cout << (res ?  YES  :  NO ); n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline void read(T &x) { n   x = 0; n   char c = getchar(); n   int f = 1; n   while (!isdigit(c)) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (isdigit(c)) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   x *= f; n } n template <class T> n inline void umin(T &x, T y) { n   x = x < y ? x : y; n } n template <class T> n inline void umax(T &x, T y) { n   x = x > y ? x : y; n } n inline unsigned int R() { n   static unsigned int seed = 416; n   return seed ^= seed >> 5, seed ^= seed << 17, seed ^= seed >> 13; n } n const int N = 266666; n const double inf = 1e9, eps = 1e-6; n int n, m, fa[N], top[N], dep[N], sz[N], son[N], dfn[N], idfn[N], num; n vector<int> e[N]; n double ans = inf, cur; n struct dot { n   double x, y; n   dot(double X = 0, double Y = 0) { n     x = X; n     y = Y; n   } n }; n vector<pair<dot, dot> > mrk[N]; n dot a[N], b[N]; n int len; n pair<double, int> ev[N]; n bool cmp1(pair<double, int> a, pair<double, int> b) { n   return a.first != b.first ? a.first < b.first : a.second > b.second; n } n inline double gety(int i) { n   return a[i].x == b[i].x n              ? a[i].y n              : a[i].y + (cur - a[i].x) / (b[i].x - a[i].x) * (b[i].y - a[i].y); n } n struct node { n   int u; n   bool operator<(const node &a) const { n     return gety(u) != gety(a.u) ? gety(u) < gety(a.u) : u < a.u; n   } n }; n set<node> Set; n dot operator-(dot a, dot b) { return dot(a.x - b.x, a.y - b.y); } n double Cross(dot a, dot b) { return a.x * b.y - a.y * b.x; } n bool isin(dot p, dot a, dot b) { n   return p.x >= min(a.x, b.x) - eps && p.x <= max(a.x, b.x) + eps && n          p.y >= min(a.y, b.y) - eps && p.y <= max(a.y, b.y) + eps; n } n double Abs(double x) { return x > 0 ? x : -x; } n bool on_line(dot p, dot a, dot b) { return Abs(Cross(p - a, b - a)) <= eps; } n double getlen(dot a) { return sqrt(a.x * a.x + a.y * a.y); } n void print(int i) { n   printf( %lf %lf %lf %lf n , a[i].x, a[i].y, b[i].x, b[i].y); n } n double getans(int i, int j) { n   if (i == j) return inf; n   if (getlen(b[i] - a[i]) > getlen(b[j] - a[j])) swap(i, j); n   if (getlen(b[i] - a[i]) <= eps) { n     if (isin(a[i], a[j], b[j]) && on_line(a[i], a[j], b[j])) return a[i].x; n     return inf; n   } n   dot A = a[i], B = b[i], C = a[j], D = b[j], u = B - A, v = D - C; n   if (Abs(Cross(u, v)) <= eps) { n     if (Abs(gety(i) - gety(j)) <= eps && cur >= A.x - eps && cur <= B.x + eps && n         cur >= C.x - eps && cur <= D.x + eps) { n       return cur; n     } n     return inf; n   } n   double k = (Cross(D, v) - Cross(A, v)) / Cross(u, v); n   dot p(A.x + k * u.x, A.y + k * u.y); n   if (isin(p, A, B) && isin(p, C, D) && on_line(p, A, B) && on_line(p, C, D)) n     return A.x + k * u.x; n   return inf; n } n void upd(int i) { n   set<node>::iterator it = Set.lower_bound((node){i}); n   if (it != Set.end()) umin(ans, getans(i, (*it).u)); n   if (it != Set.begin()) it--, umin(ans, getans(i, (*it).u)); n } n void dfs1(int u, int Fa, int Dep) { n   fa[u] = Fa; n   dep[u] = Dep; n   sz[u] = 1; n   for (register int i = (0); i <= (((int)e[u].size()) - 1); i++) n     if (e[u][i] != Fa) { n       dfs1(e[u][i], u, Dep + 1), sz[u] += sz[e[u][i]]; n       if (sz[e[u][i]] > sz[son[u]]) son[u] = e[u][i]; n     } n } n void dfs2(int u, int Top) { n   top[u] = Top; n   dfn[u] = ++num; n   idfn[num] = u; n   if (son[u]) dfs2(son[u], Top); n   for (register int i = (0); i <= (((int)e[u].size()) - 1); i++) n     if (e[u][i] != fa[u] && e[u][i] != son[u]) dfs2(e[u][i], e[u][i]); n } n int getlca(int u, int v) { n   while (top[u] != top[v]) { n     if (dep[top[u]] < dep[top[v]]) swap(u, v); n     u = fa[top[u]]; n   } n   return dep[u] < dep[v] ? u : v; n } n int getpath(int u, int v, double t, int xs, double c) { n   while (top[u] != top[v]) { n     int x = fa[top[u]]; n     mrk[top[u]].push_back(make_pair( n         dot(t, dfn[u]), n         dot(t + xs * (dep[u] - dep[x]) / c, dfn[u] - (dep[u] - dep[x])))); n     t += xs * (dep[u] - dep[x]) / c; n     u = fa[top[u]]; n   } n   return u; n } n int main() { n   read(n); n   read(m); n   for (register int i = (1); i <= (n - 1); i++) { n     int u, v; n     read(u); n     read(v); n     e[u].push_back(v); n     e[v].push_back(u); n   } n   dfs1(1, 0, 0); n   dfs2(1, 1); n   for (register int i = (1); i <= (m); i++) { n     int T, C, u, v; n     read(T); n     read(C); n     read(u); n     read(v); n     double t = T, c = C; n     int lca = getlca(u, v); n     int ori = u; n     v = getpath(v, lca, t + (dep[u] + dep[v] - 2 * dep[lca]) * 1.0 / c, -1, c); n     u = getpath(u, lca, t, 1, c); n     t += (dep[ori] - dep[u]) * 1.0 / c; n     if (dep[u] >= dep[v]) n       mrk[top[u]].push_back(make_pair( n           dot(t, dfn[u]), dot(t + (dep[u] - dep[v]) * 1.0 / c, dfn[v]))); n     else n       mrk[top[u]].push_back(make_pair( n           dot(t, dfn[u]), dot(t + (dep[v] - dep[u]) * 1.0 / c, dfn[v]))); n   } n   for (register int t = (1); t <= (n); t++) n     if (((int)mrk[t].size())) { n       Set.clear(); n       len = 0; n       for (register int i = (0); i <= (((int)mrk[t].size()) - 1); i++) n         len++, a[len] = mrk[t][i].first, b[len] = mrk[t][i].second; n       for (register int i = (1); i <= (len); i++) n         if (a[i].x > b[i].x) swap(a[i], b[i]); n       for (register int i = (1); i <= (len); i++) n         ev[2 * i - 1] = make_pair(a[i].x, i), ev[2 * i] = make_pair(b[i].x, -i); n       sort(ev + 1, ev + len * 2 + 1, cmp1); n       for (register int i = (1); i <= (len * 2); i++) { n         if ((cur = ev[i].first) >= ans) break; n         if (ev[i].second > 0) { n           set<node>::iterator it = Set.insert((node){ev[i].second}).first, pre, n                               nxt; n           pre = it; n           nxt = it; n           nxt++; n           if (it != Set.begin()) { n             pre--; n             umin(ans, getans((*pre).u, (*it).u)); n           } n           if (nxt != Set.end()) { n             umin(ans, getans((*nxt).u, (*it).u)); n           } n         } else { n           set<node>::iterator it = Set.find((node){-ev[i].second}), it1, it2; n           it1 = it, it2 = it; n           it2++; n           if (it != Set.begin() && it2 != Set.end()) { n             it1--; n             umin(ans, getans((*it1).u, (*it2).u)); n           } n           Set.erase(it); n         } n       } n     } n   if (ans < 1e8) n     printf( %.9lf n , ans); n   else n     puts( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<int, int> m; n int main() { n   int a, t, n, i, j, k, l, mn = INT_MAX, mx = 0; n   cin >> n >> k; n   int cnt = 0; n   int ans = 0; n   for (int i = 0; i < n; i++) { n     cin >> a; n     mn = min(mn, a); n     m[a]++; n   } n   int p = mn; n   while (p < k) { n     ans++; n     mn = INT_MAX; n     for (int i = k - 1; i >= p; i--) { n       if (m[i] > 0) m[i]--, m[i + 1]++; n       if (m[i] > 0) mn = min(mn, i); n       if (m[i + 1] > 0) mn = min(mn, i + 1); n     } n     p = mn; n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const long double PI = 3.141592653589793238; n const double EPS = 1e-6; n void solve() { n   long long r, g, b, w; n   cin >> r >> g >> b >> w; n   long long total = r + g + b + w; n   long long odd = 0; n   odd = r % 2 + g % 2 + b % 2 + w % 2; n   long long col = r && g && b; n   if (odd <= 1 || odd == 4 || (odd == 3 && col)) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long tc; n   cin >> tc; n   while (tc--) { n     solve(); n   } n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n typedef long long ll; n int main() n {     n  int t,n,k; n  string x= abc ; n  cin>>t; n  while(t--) n  { n   cin>>n>>k; n   string s,h; n   for(int i=0;i<n-k;i++) n   { n    s+=x[i%3]; n   } n    n   char c=x[(n-k)%3]; n    n   while(k--) n   { n    s+=c; n   } n   cout<<s<<endl; n  } n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n, k; n     cin >> n >> k; n     string s =   ; n     for (int i = 0;; i++) { n       bool flag = 1; n       for (int j = i * k; j < (i + 1) * k; j++) { n         s += ( a  + j - i * k); n         if (j == n - 1) { n           flag = 0; n           break; n         } n       } n       if (flag == 0) break; n     } n     cout << s << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n void start() {} n void sober() { n   long long int n, x = 0, a = 0, b = 0, y = 0, sum = 0, k = 0, m = 0; n   cin >> n >> a >> b; n   string s; n   cin >> s; n   a--, b--; n   if (s[a] == s[b]) n     cout <<  0 n ; n   else n     cout <<  1 n ; n } n signed main() { n   start(); n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long int t = 1; n   while (t--) { n     sober(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 200005; n int a[maxn]; n unordered_map<int, int> b, c; n unordered_map<int, int>::iterator it, it2; n vector<int> ans; n int main() { n   ios_base::sync_with_stdio(0); n   int n, m, p; n   cin >> n >> m >> p; n   int x; n   for (int i = 0; i < n; ++i) cin >> a[i]; n   for (int i = 0; i < m; ++i) { n     cin >> x; n     it = b.find(x); n     if (it == b.end()) n       b.insert(make_pair(x, 1)); n     else n       ++it->second; n   } n   for (int q = 0; q < p; ++q) { n     int cur = 0; n     c.clear(); n     for (int i = q; i < n; i += p) { n       if (1ll * i >= 1ll * m * p) { n         it = b.find(a[i - m * p]); n         if (it != b.end()) { n           it2 = c.find(a[i - m * p]); n           if (it2->second <= it->second) --cur; n           --it2->second; n         } n       } n       it = b.find(a[i]); n       if (it == b.end()) n         continue; n       else { n         it2 = c.find(a[i]); n         if (it2 == c.end()) it2 = c.insert(make_pair(a[i], 0)).first; n         if (it2->second < it->second) ++cur; n         ++it2->second; n       } n       if (cur == m) ans.push_back(i - (m - 1) * p + 1); n     } n   } n   sort(ans.begin(), ans.end()); n   cout << ans.size() <<   n ; n   for (int i : ans) cout << i <<    ; n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int k; n   cin >> k; n   char s[200]; n   vector<int> __v; n   __v.assign(1000000, 127); n   cin >> s; n   int n; n   cin >> n; n   set<int> n_del[ z  -  a  + 1]; n   set<int>::iterator pos_n_del[ z  -  a  + 1]; n   for (int i = 0; i < n; i++) { n     char c; n     int nc; n     cin >> nc >> c; n     set<int>::iterator it = n_del[c -  a ].begin(); n     if (n_del[c -  a ].empty() || nc <= *it) { n       n_del[c -  a ].insert(nc - 1); n       continue; n     } n     nc -= *it; n     int pos = 0; n     while (it != n_del[c -  a ].end() && nc > 0) { n       set<int>::iterator it0 = it; n       it++; n       if (it != n_del[c -  a ].end()) { n         nc -= *it - *it0 - 1; n       } n     } n     if (nc > 0) { n       it--; n       pos = *it + nc; n     } else n       pos = *it + nc - 1; n     n_del[c -  a ].insert(pos); n   } n   for (int i = 0; i <  z  -  a  + 1; ++i) { n     pos_n_del[i] = n_del[i].begin(); n   } n   int tSums[ z  -  a  + 1] = {0}; n   for (int i = 0, len = strlen(s), j = 0; i < len * k; ++i, ++j) { n     if (j == len) j = 0; n     if (pos_n_del[s[j] -  a ] != n_del[s[j] -  a ].end() && n         *pos_n_del[s[j] -  a ] == tSums[s[j] -  a ]) { n       pos_n_del[s[j] -  a ]++; n     } else n       cout << s[j]; n     tSums[s[j] -  a ]++; n   } n   cout << endl; n   cerr << __v[rand() % __v.size()]; n } n


#include <bits/stdc++.h> n using namespace std; n const int dx[4] = {0, 1, -1, 0}, dy[4] = {-1, 0, 0, 1}; n int n, m; n char g[60][60]; n bool col[60][60][2][4]; n bool tmp[60][60][2][4]; n bool inrange(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; } n void solve(int x, int y, int turn, int dir) { n   int nx = x + dx[dir], ny = y + dy[dir]; n   if (inrange(nx, ny) && g[nx][ny] ==  B  && tmp[nx][ny][turn][dir] == false) { n     tmp[nx][ny][turn][dir] = tmp[nx][ny][1][dir] = true; n     solve(nx, ny, turn, dir); n   } n   if (turn == 1) return; n   for (int i = 0; i < 4; i++) { n     if (i == dir) continue; n     nx = x + dx[i], ny = y + dy[i]; n     if (inrange(nx, ny) && g[nx][ny] ==  B  && tmp[nx][ny][1][i] == false) { n       tmp[nx][ny][1][i] = true; n       solve(nx, ny, 1, i); n     } n   } n   return; n } n bool check() { n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) n       if (g[i][j] ==  B ) { n         bool ok = false; n         for (int x = 0; x < 2 && !ok; x++) n           for (int y = 0; y < 4 && !ok; y++) n             if (tmp[i][j][x][y]) ok = true; n         if (!ok) return false; n       } n   return true; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       cin >> g[i][j]; n     } n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) n       if (g[i][j] ==  B ) { n         memset(tmp, false, sizeof(tmp)); n         for (int k = 0; k < 4; k++) n           tmp[i][j][0][k] = tmp[i][j][1][k] = true, solve(i, j, 0, k); n         if (!check()) { n           cout <<  NO  << endl; n           return 0; n         } n       } n   cout <<  YES  << endl; n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n  n typedef long long ll; n typedef long double ld; n typedef string ss ; n typedef pair<int, int> pi; n typedef pair<ll,ll> pl; n typedef vector<int> vi; n typedef vector<ll> vl; n  n #define mp make_pair n #define pb push_back n  n  n  n void solve(){ n        ll n,k=0,q=0; n        string s; n       cin >> n >> k ; n       ll x[n],y[n]; n       for(int i=0 ; i<n ; i++){ n           cin >> x[i] >> y[i]; n       } n       bool ok=false; n       for(int i=0 ; i<n ; i++){ n           for(int j=0 ; j<n ; j++){ n             if(abs(x[i]-x[j]) + abs(y[i]-y[j]) <= k){ n               q++; n             } n             if(q==n) ok=true; n       } q=0; n       } n       cout << (ok ?  1 n  :  -1 n ) ; n        n     n } n  n  n  n  n int main() { n     ios_base::sync_with_stdio(0); cin.tie(0); n     int t=1; n     cin >> t; n     while(t--) n      solve(); n     return 0; n } n  n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3e5 + 17; n int N, Q; n int main() { n   ios_base::sync_with_stdio(false); n   cin >> Q; n   while (Q--) { n     cin >> N; n     long long mx; n     cin >> mx; n     long long diff = 0; n     while (--N) { n       long long x; n       cin >> x; n       mx = max(mx, x); n       diff = max(diff, mx - x); n     } n     long long ans = 0; n     while (diff) { n       ans++; n       diff >>= 1; n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, p; n string msg, s[100001], h =  <3 ; n int sub(int &i, string &w) { n   int k = 0; n   for (; k < w.length() && i < msg.length(); i++) { n     if (w[k] == msg[i]) { n       ++k; n     } n   } n   return k == w.length(); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> s[i]; n   } n   cin >> msg; n   int j = 0, o = 1; n   for (int i = 0; o && i < n; i++) { n     if (!sub(j, h)) { n       o = 0; n     } n     if (o && !sub(j, s[i])) { n       o = 0; n     } n   } n   if (!sub(j, h)) { n     o = 0; n   } n   if (o) { n     cout <<  yes  n          <<   n ; n   } else { n     cout <<  no  n          <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int OO = 1e9; n const double EPS = 1e-9; n const int MX = 1e6 + 5; n int p = 1299709, n, m, u, v; n vector<vector<int>> adj(MX); n unsigned long long pPw[MX], M = 1000000009, Hash[MX]; n int main() { n   ios::sync_with_stdio(false); n   cout.precision(10); n   cin.tie(0); n   pPw[0] = 1; n   for (int i = 1; i < MX; ++i) pPw[i] = p * pPw[i - 1]; n   cin >> n >> m; n   for (int i = 0; i < m; ++i) { n     cin >> u >> v; n     for (int I = 0; I < 1; ++I) { n       Hash[u] += pPw[v]; n       Hash[v] += pPw[u]; n     } n   } n   map<unsigned long long, int> hashes; n   for (int i = 1; i <= n; ++i) { n     ++hashes[Hash[i]]; n   } n   unsigned long long ans = 0; n   for (auto& pr : hashes) { n     ans += pr.second * 1LL * (pr.second - 1) / 2; n   } n   hashes.clear(); n   for (int i = 1; i <= n; ++i) { n     ++hashes[Hash[i] + pPw[i]]; n   } n   for (auto& pr : hashes) { n     ans += pr.second * 1LL * (pr.second - 1) / 2; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[200], ans[200]; n int v[1000001]; n int main() { n   int T, n; n   cin >> T; n   while (T--) { n     memset(v, 0, sizeof v); n     scanf( %d , &n); n     for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n     sort(a + 1, a + n + 1); n     for (int i = 1; i <= n; i++) { n       for (int j = i; j <= n; j++) v[a[j] - a[i]] = 1; n     } n     memset(ans, 0, sizeof ans); n     ans[1] = 1; n     int len = 2; n     for (int j = 1; j <= 1e6; j++) { n       int tag = 1; n       for (int k = 1; k < len; k++) { n         if (v[j - ans[k]]) { n           tag = 0; n           break; n         } n       } n       if (tag) ans[len++] = j; n       if (len > n) break; n     } n     int tag = 1; n     for (int i = 1; i <= n; i++) n       if (ans[i] == 0) tag = 0; n     if (tag) { n       puts( YES ); n       for (int i = 1; i <= n; i++) printf( %d%c , ans[i], i == n ?   n  :    ); n     } else n       puts( NO ); n   } n   return 0; n } n