#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,unroll-loops ) n #pragma GCC target( avx,avx2,fma ) n using namespace std; n const long long sz = 3e3 + 10, mod = 998244353; n char s[sz], t[sz]; n long long dp[sz][sz]; n long long solve(long long l, long long r) { n   if (l > r) return 1; n   long long &ret = dp[l][r]; n   if (ret != -1) return ret; n   long long rt = 0, idx = r - l + 1; n   if (s[idx] == t[r] || t[r] ==  $ ) rt = (rt + solve(l, r - 1)) % mod; n   if (s[idx] == t[l] || t[l] ==  $ ) rt = (rt + solve(l + 1, r)) % mod; n   return ret = rt; n } n int main() { n   scanf( %s , s + 1); n   scanf( %s , t + 1); n   long long n = strlen(s + 1), m = strlen(t + 1); n   long long m2 = m; n   while (m2 < n) t[++m2] =  $ ; n   memset(dp, -1, sizeof(dp)); n   long long tot = 0; n   for (long long i = m; i <= n; i++) tot = (tot + solve(1, i)) % mod; n   cout << tot << endl; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n; n   scanf( %d , &n); n   printf( %d 0 0 , n); n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, d, t; n int a[1000005], b[1000005], c[1000005]; n char ch[1000005], ans[1000005]; n void mul(int* a, int* b) { n   for (int i = 0; i < n; ++i) { n     c[i] = b[a[i]]; n   } n   for (int i = 0; i < n; ++i) { n     a[i] = c[i]; n   } n } n int main() { n   scanf( %s , ch); n   n = strlen(ch); n   scanf( %d , &t); n   while (t--) { n     scanf( %d%d , &k, &d); n     int now = 0; n     for (int i = 0; i < d; ++i) { n       for (int j = i; j < k; j += d) { n         a[j] = now++; n       } n     } n     for (int i = k; i < n; ++i) { n       a[i] = i; n     } n     for (int i = 0; i < n; ++i) { n       a[i] = (a[i] - 1 + n) % n; n     } n     for (int i = 0; i < n; ++i) { n       b[i] = i; n     } n     now = (n - k + 1); n     while (now) { n       if (now & 1) { n         mul(b, a); n       } n       mul(a, a); n       now >>= 1; n     } n     for (int i = 0; i < n; ++i) { n       ans[(b[i] + n - k + 1) % n] = ch[i]; n     } n     for (int i = 0; i < n; ++i) { n       ch[i] = ans[i]; n     } n     printf( %s n , ch); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long M[110000 * 4]; n long long lazy[110000 * 4]; n void down(int x) { n   if (lazy[x] != -1) { n     M[x * 2] = max(M[x * 2], lazy[x]); n     M[x * 2 + 1] = max(M[x * 2 + 1], lazy[x]); n     lazy[x * 2] = max(lazy[x], lazy[x * 2]); n     lazy[x * 2 + 1] = max(lazy[x], lazy[x * 2 + 1]); n     lazy[x] = -1; n   } n } n void up(int x) { M[x] = max(M[x * 2], M[x * 2 + 1]); } n void cover(int now, int l, int r, int x, int y, long long v) { n   down(now); n   if (x <= l && r <= y) { n     M[now] = v; n     lazy[now] = v; n     return; n   } n   int mid = (l + r) >> 1; n   if (x <= mid) cover(now * 2, l, mid, x, y, v); n   if (y > mid) cover(now * 2 + 1, mid + 1, r, x, y, v); n   up(now); n } n long long ask(int now, int l, int r, int x, int y) { n   down(now); n   if (x <= l && r <= y) return M[now]; n   int mid = (l + r) >> 1; n   long long res = 0; n   if (x <= mid) res = max(res, ask(now * 2, l, mid, x, y)); n   if (y > mid) res = max(res, ask(now * 2 + 1, mid + 1, r, x, y)); n   return res; n } n int main() { n   memset(lazy, -1, sizeof lazy); n   int n, m; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     int v; n     scanf( %d , &v); n     cover(1, 1, n, i, i, v); n   } n   scanf( %d , &m); n   for (int i = 1; i <= m; i++) { n     int w, h; n     scanf( %d%d , &w, &h); n     long long res = ask(1, 1, n, 1, w); n     printf( %I64d n , res); n     cover(1, 1, n, 1, w, h + res); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void fre() { n   freopen( c://test//input.in ,  r , stdin); n   freopen( c://test//output.out ,  w , stdout); n } n template <class T1, class T2> n inline void gmax(T1 &a, T2 b) { n   if (b > a) a = b; n } n template <class T1, class T2> n inline void gmin(T1 &a, T2 b) { n   if (b < a) a = b; n } n const int N = 4040, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f; n int n, m; n int y, x; n int ln[1010], ls[1010]; n vector<int> a[N]; n int p[N]; n bool e[N]; n int hungary(int x) { n   e[x] = 1; n   for (int i = a[x].size() - 1; ~i; i--) { n     int y = a[x][i]; n     if (p[y] == -1) { n       p[y] = x; n       return 1; n     } n   } n   for (int i = a[x].size() - 1; ~i; i--) { n     int y = a[x][i]; n     if (!e[p[y]] && hungary(p[y])) { n       p[y] = x; n       return 1; n     } n   } n   return 0; n } n void ins(int x, int y) { a[x].push_back(y); } n int main() { n   while (~scanf( %d%d , &n, &m)) { n     memset(ln, 1, sizeof(ln)); n     memset(ls, 1, sizeof(ls)); n     int n2 = n * 2; n     int n3 = n * 3; n     int n4 = n * 4; n     for (int i = 1; i <= n4; ++i) a[i].clear(); n     for (int i = 1; i <= m; ++i) { n       scanf( %d%d , &y, &x); n       ln[y] = 0; n       ls[x] = 0; n     } n     for (int i = 2; i < n; ++i) n       if (ln[i]) { n         ins(i, i + n); n         ins(i + n, i); n         if (ls[i]) { n           ins(i, i + n2); n           ins(i + n2, i); n         } n         if (ls[n + 1 - i]) { n           ins(i, i + n3); n           ins(i + n3, i); n         } n         if (ls[n + 1 - i]) { n           ins(i + n, i + n3); n           ins(i + n3, i + n); n         } n         if (ls[n + 1 - i]) { n           ins(i + n, n + 1 - i + n2); n           ins(n + 1 - i + n2, i + n); n         } n       } n     for (int j = 2; j < n; ++j) n       if (ls[j]) { n         ins(n + n + j, n + n + n + j); n         ins(n + n + n + j, n + n + j); n       } n     memset(p, -1, sizeof(p)); n     int ans = 0; n     for (int i = 1; i <= n4; i++) { n       memset(e, 0, sizeof(e)); n       if (hungary(i)) ans++; n     } n     ans /= 2; n     if (n & 1) { n       if (ln[n / 2 + 1] && ls[n / 2 + 1]) --ans; n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> vv[3001]; n int graf[3001][3001]; n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     int f, t; n     cin >> f >> t; n     vv[f].push_back(t); n     graf[f][t] = 1; n   } n   long long ans(0); n   for (int a = 1; a <= n; a++) n     for (int c = 1; c <= n; c++) { n       if (a == c) continue; n       int cnt(0); n       for (int i = 0; i < vv[a].size(); i++) { n         int b = vv[a][i]; n         if (graf[b][c]) { n           cnt++; n         } n       } n       ans += 1LL * cnt * (cnt - 1) / 2; n     } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = LLONG_MAX; n const long long base = 1e9; n const double PI = acos(-1); n const long long MOD = 1e9 + 7; n const long long N = 1e5 + 10; n int main() { n   ios_base ::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n; n   cin >> n; n   long long a[n]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   if (a[0] != 0) { n     cout <<  1  << endl; n     return 0; n   } n   long long mx = 0; n   for (int i = 1; i < n; i++) { n     mx = max(mx, a[i - 1]); n     if (a[i] - mx > 1) { n       cout << i + 1 << endl; n       return 0; n     } n   } n   cout <<  -1  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 755, M = 10000005; n char s[M]; n bool e[N][N]; n int n; n struct ACAutomaton { n   int trie[M][2], id[M], idx, pos[M], fa[M]; n   void ins(char *s, int t) { n     int cur = 0, l = strlen(s + 1); n     for (int i = 1; i <= l; i++) { n       if (!trie[cur][s[i] -  a ]) trie[cur][s[i] -  a ] = ++idx, fa[idx] = cur; n       cur = trie[cur][s[i] -  a ]; n     } n     id[cur] = t; n     pos[t] = cur; n   } n   int fail[M]; n   void build_fail() { n     queue<int> q; n     for (int i = 0; i < 2; i++) n       if (trie[0][i]) q.push(trie[0][i]); n     while (!q.empty()) { n       int nd = q.front(); n       q.pop(); n       for (int i = 0; i < 2; i++) n         if (trie[nd][i]) n           fail[trie[nd][i]] = trie[fail[nd]][i], q.push(trie[nd][i]); n         else n           trie[nd][i] = trie[fail[nd]][i]; n     } n   } n   int f[M]; n   int getf(int v) { return f[v] == v ? v : f[v] = getf(f[v]); } n   void build_tr() { n     for (int i = 1; i <= idx; i++) f[i] = id[i] ? i : fail[i]; n     for (int i = 1; i <= n; i++) { n       int p = pos[i]; n       if (id[getf(fail[p])]) e[i][id[getf(fail[p])]] = 1; n       p = fa[pos[i]]; n       while (p) { n         if (id[p]) { n           e[i][id[p]] = 1; n           break; n         } n         if (id[getf(p)]) e[i][id[getf(p)]] = 1; n         p = fa[p]; n       } n     } n   } n } t; n int mat[N], mat2[N]; n bool vis[N]; n int find(int pos) { n   if (vis[pos]) return 0; n   vis[pos] = 1; n   for (int i = 1; i <= n; i++) n     if (e[pos][i] && (!mat[i] || find(mat[i]))) { n       mat[i] = pos; n       return 1; n     } n   return 0; n } n bool vis1[N], vis2[N]; n void dfs(int pos) { n   if (vis1[pos]) return; n   vis1[pos] = 1; n   for (int i = 1; i <= n; i++) n     if (e[pos][i] && mat2[pos] != i && !vis2[i]) { n       vis2[i] = 1; n       if (mat[i]) dfs(mat[i]); n     } n } n int ans[N], idx; n int main() { n   ios::sync_with_stdio(false); n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> (s + 1), t.ins(s, i); n   t.build_fail(); n   t.build_tr(); n   for (int k = 1; k <= n; k++) n     for (int i = 1; i <= n; i++) n       for (int j = 1; j <= n; j++) e[i][j] |= e[i][k] & e[k][j]; n   for (int i = 1; i <= n; i++) memset(vis, 0, sizeof(vis)), find(i); n   for (int i = 1; i <= n; i++) n     if (mat[i]) mat2[mat[i]] = i; n   for (int i = 1; i <= n; i++) n     if (!mat2[i]) dfs(i); n   for (int i = 1; i <= n; i++) n     if (vis1[i] && !vis2[i]) ans[++idx] = i; n   cout << idx << endl; n   for (int i = 1; i <= idx; i++) cout << ans[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n int n, ans, lst[5010][2]; n int comp(const void *a, const void *b) { n   int x = ((int *)a)[0] - ((int *)b)[0]; n   if (x) return x; n   return ((int *)a)[1] - ((int *)b)[1]; n } n int main() { n   int i; n   scanf( %d , &n); n   for (i = 1; i <= n; i++) scanf( %d%d , &lst[i][0], &lst[i][1]); n   qsort(lst + 1, n, sizeof(lst[0]), comp); n   for (i = 1; i <= n; i++) { n     if (lst[i][1] >= ans) n       ans = lst[i][1]; n     else n       ans = lst[i][0]; n   } n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n int ATTENTION() { n http: n   return 0; n } n using namespace std; n const int iinf = 0x7fffffff; n const long long linf = ~(1LL << 63); n template <typename T> n inline T gcd(T a, T b) { n   if (a < 0) return gcd(-a, b); n   if (b < 0) return gcd(a, -b); n   if (a < b) return gcd(b, a); n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long qpow(long long a, long long n, long long mod) { n   a %= mod; n   long long ans = 1LL; n   while (n) { n     if (n & 1) ans = (ans * a % mod); n     a = (a * a % mod); n     n >>= 1; n   } n   return ans; n } n inline long long rev(long long a, long long p) { return qpow(a, p - 2, p); } n template <typename T> n inline void BPS(T* DST, T* SRC, int N, int s = 0) { n   DST[s] = SRC[s]; n   for (int i = 1; i < N; i++) DST[s + i] = DST[s + i - 1] + SRC[s + i]; n } n inline int in() { n   int x; n   cin >> x; n   return x; n } n inline void tic() {} n inline void toc() {} n bitset<100000001> is_prime; n int n, A, B, C, D; n void unset_prime(unsigned int v) { is_prime.reset(v / 3); } n unsigned int f(unsigned int x) { n   return ((((unsigned int)A * x + (unsigned int)B)) * x + (unsigned int)C) * x + n          (unsigned int)D; n } n int main() { n   scanf( %u%u%u%u%u , &n, &A, &B, &C, &D); n   is_prime.set(); n   unsigned int res = 0; n   unsigned int t = n; n   unsigned int p2 = 2; n   unsigned int fp = f(2); n   while (t >= p2) { n     res += t / p2 * fp; n     p2 *= 2; n   } n   p2 = 3; n   fp = f(3); n   while (t >= p2) { n     res += t / p2 * fp; n     p2 *= 3; n   } n   for (unsigned int i = 5; i <= n; i += 2) { n     if (is_prime[i / 3] == 0) { n       if (i % 3 == 1) i += 2; n       continue; n     } n     for (unsigned int j = 5 * i, k = 5; j <= n; j += 2 * i, k += 2) { n       unset_prime(j); n       if (k % 3 == 1) { n         k += 2; n         j += 2 * i; n       } n     } n     t = n; n     long long pi = i; n     fp = f(i); n     while (t >= pi) { n       res += t / pi * fp; n       pi *= i; n     } n     if (i % 3 == 1) i += 2; n   } n   printf( %u n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dx[4] = {0, 0, 1, -1}; n int dy[4] = {1, -1, 0, 0}; n const int mod = (int)1e9 + 7; n long long INF64 = 3e18; n void smxl(long long &a, long long b) { n   if (a < b) a = b; n } n void smnl(long long &a, long long b) { n   if (a > b) a = b; n } n void adsl(long long &a, long long b) { n   a += b; n   if (a >= mod) a -= mod; n } n void misl(long long &a, long long b) { n   a -= b; n   if (a >= mod) a -= mod; n   if (a < 0) a += mod; n } n void smx(long long &a, long long b) { n   if (a < b) a = b; n } n void smn(long long &a, long long b) { n   if (a > b) a = b; n } n void ads(long long &a, long long b) { n   a += b; n   if (a >= mod) a -= mod; n } n void mis(long long &a, long long b) { n   a -= b; n   if (a >= mod) a -= mod; n   if (a < 0) a += mod; n } n long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); } n long long egcd(long long a, long long b, long long &x, long long &y) { n   if (a == 0) { n     x = 0; n     y = 1; n     return b; n   } n   long long x1, y1; n   long long d = egcd(b % a, a, x1, y1); n   x = y1 - (b / a) * x1; n   y = x1; n   return d; n } n long long mbinp(long long a, long long b) { n   a %= mod; n   if (b == 0) return 1; n   long long ans = mbinp(a, b / 2); n   long long tmp = (ans * ans) % mod; n   if (b % 2) return ((tmp * a) % mod); n   return ((tmp) % mod); n } n long long C(int n, int m) { n   long long ret = 1; n   for (int i = 1; i <= m; i++) { n     ret *= (n - i + 1); n     ret /= i; n   } n   return ret; n } n long long binp(long long a, int b) { n   long long res = 1; n   while (b) { n     if (b & 1) { n       if (res < INF64 / a) n         res *= a; n       else n         return INF64; n     } n     if (b > 1) { n       if (a < INF64 / a) n         a *= a; n       else n         return INF64; n     } n     b >>= 1; n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n; n   cin >> n; n   vector<int> primes(100, 0); n   vector<int> mu(100, 0); n   for (int i = 2; i < 100; i++) { n     if (primes[i] == 0) { n       mu[i]++; n       for (int j = 2 * i; j < 100; j += i) { n         primes[j] = 1; n         if (mu[j] != -1) mu[j]++; n       } n       for (int z = i * i; z < 100; z += i * i) mu[z] = -1; n     } n   } n   mu[1] = 2; n   vector<pair<long long, int> > all(n); n   for (int i = 0; i < n; i++) { n     cin >> all[i].first; n     all[i].second = i; n   } n   sort(all.rbegin(), all.rend()); n   vector<long long> poss(62); n   for (int i = 3; i < 62; i++) n     poss[i] = (long long)ceil(pow((long double)1e18, 1.0 / i)); n   vector<long long> ans(n); n   for (int i = 0; i < n; i++) { n     long long skr = -1; n     long long low = 0; n     long long hi = 1e9 + 10; n     while (low <= hi) { n       long long mid = (low + hi) / 2; n       if (mid * mid <= all[i].first) { n         if (mid > skr) skr = mid; n         low = mid + 1; n       } else n         hi = mid - 1; n     } n     poss[1] = all[i].first; n     poss[2] = skr; n     for (int j = 3; j < 62; j++) { n       while (poss[j] > 0 && binp(poss[j], j) > all[i].first) poss[j]--; n     } n     long long out = 0; n     for (int j = 1; j < 62; j++) { n       out += (poss[j] - 1) * (mu[j] == -1 ? 0 : (mu[j] % 2 == 1 ? -1 : 1)); n     } n     ans[all[i].second] = out; n   } n   for (int i = 0; i < n; i++) cout << ans[i] <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int t; n   cin >> t; n   long long int i; n   while (t--) { n     string a, b, c; n     cin >> a >> b >> c; n     long long int n = a.length(), f = 0; n     for (i = 0; i < n; i++) { n       if (a[i] != c[i] && b[i] != c[i]) { n         cout <<  NO n ; n         f = 1; n         break; n       } else if (a[i] == c[i]) n         swap(b[i], c[i]); n       else n         swap(a[i], c[i]); n     } n     if (f != 1) cout <<  YES n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[200005]; n int main() { n   long long k, sum, subs, di; n   int i, n, rel; n   cin >> n >> k; n   int n1 = n; n   for (i = 1; i <= n; i++) cin >> a[i]; n   i = 1; n   sum = 0; n   rel = 1; n   while (1) { n     if (i > n1) break; n     subs = (n - rel) * a[i] * (rel - 1); n     di = sum - subs; n     if (di < k) { n       n--; n       rel--; n       printf( %d n , i); n     } else { n       sum = sum + a[i] * (rel - 1); n     } n     i++; n     rel++; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 500 + 10; n const int INF = 0x3f3f3f3f; n const int mod = 1000000007; n int n, m; n int a[maxn][maxn], b[maxn][maxn]; n int main() { n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       cin >> a[i][j]; n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       cin >> b[i][j]; n       a[i][j] ^= b[i][j]; n     } n   } n   int flag = 0; n   for (int i = 1; i <= n; i++) { n     int tm = 0; n     for (int j = 1; j <= m; j++) { n       tm += a[i][j]; n     } n     if (tm % 2) flag = 1; n   } n   for (int i = 1; i <= m; i++) { n     int tm = 0; n     for (int j = 1; j <= n; j++) { n       tm += a[j][i]; n     } n     if (tm % 2) flag = 1; n   } n   if (flag) n     cout <<  No n ; n   else n     cout <<  Yes n ; n   return 0; n } n


#include <bits/stdc++.h> n long long INF = (long long)1e18; n struct node { n   int n; n   double rat; n }; n bool operator<(const node& n1, const node& n2) { return n1.rat > n2.rat; } n std::vector<int> edge[100010]; n int ch[100010], ne[100010]; n int main() { n   int x, a, b, k, n, m, q, t, num, in = 0, to, i; n   double d, s; n   scanf( %d%d%d , &n, &m, &q); n   for (k = 1; k <= q; k++) { n     scanf( %d , &x); n     ch[x] = -1; n   } n   for (k = 1; k <= m; k++) { n     scanf( %d%d , &a, &b); n     edge[a].push_back(b); n     edge[b].push_back(a); n   } n   double max = -1; n   std::priority_queue<node> PQ; n   for (k = 1; k <= n; k++) { n     if (ch[k] == -1) continue; n     t = 0; n     for (i = 0; i < edge[k].size(); i++) { n       int j = edge[k][i]; n       if (ch[j] == 0) t++; n     } n     ne[k] = t; n     PQ.push(node{k, (double)t / (double)edge[k].size()}); n   } n   num = n - q; n   in = 1; n   while (num != 0) { n     a = PQ.top().n; n     d = PQ.top().rat; n     PQ.pop(); n     if (ch[a] != 0) continue; n     ch[a] = in++; n     if (d > max) { n       max = d; n       to = in; n     } n     num--; n     for (i = 0; i < edge[a].size(); i++) { n       int j = edge[a][i]; n       if (ch[j] != 0) continue; n       ne[j]--; n       s = (double)ne[j] / (double)edge[j].size(); n       PQ.push(node{j, s}); n     } n   } n   int ans = 0; n   for (k = 1; k <= n; k++) { n     if (ch[k] >= to - 1) ans++; n   } n   printf( %d n , ans); n   for (k = 1; k <= n; k++) { n     if (ch[k] >= to - 1) printf( %d  , k); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a[404040]; n inline void solve() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , a + i); n   int N = 0; n   for (int i = 1, j = 1; i <= n; i = j) { n     for (; j <= n && a[i] == a[j]; j++) n       ; n     a[++N] = j - i; n   } n   int s2 = 0, i2 = 2; n   for (; i2 <= N && s2 <= a[1]; i2++) s2 += a[i2]; n   i2--; n   int sum = a[1] + s2; n   int s3 = 0, i3 = i2 + 1; n   for (; i3 <= N && (sum + a[i3]) * 2 <= n; i3++) sum += a[i3], s3 += a[i3]; n   i3--; n   if (a[1] < s3) n     printf( %d %d %d n , a[1], s2, s3); n   else n     puts( 0 0 0 ); n } n int main() { n   int t; n   scanf( %d , &t); n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n long long pw(int x, int y, int z) { n   if (y == 0) return 1 % z; n   long long a = pw(x, y / 2, z); n   if (y % 2 == 0) n     return (a * a) % z; n   else n     return (((a * a) % z) * x % z) % z; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     vector<vector<long long>> arr(n, vector<long long>(2)); n     for (int i = 0; i < n; ++i) cin >> arr[i][0] >> arr[i][1]; n     map<long long, long long> l, r; n     for (int i = 0; i < n; ++i) { n       l[arr[i][0]]++; n       r[arr[i][1]]++; n     } n     sort(arr.begin(), arr.end()); n     long long ans = (n * (n - 1) * (n - 2)) / 6; n     sort(arr.begin(), arr.end()); n     for (int i = 0; i < n; ++i) { n       long long curl = arr[i][0]; n       long long nos = l[curl]; n       long long othel = 0; n       if (nos >= 2) { n         for (int j = i; j < i + nos; ++j) { n           othel += (r[arr[j][1]] - 1); n         } n       } n       ans -= ((nos - 1) * othel); n       i += nos - 1; n     } n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct info { n   long long tp, ii, jj, qn, nxt, prv; n } d; n long long cn[1002][1002], n, m; n long long rev[1003], cnt[1003], tot, an[100003]; n long long vis[100002]; n long long par[100002]; n vector<info> v[100005]; n long long go(long long nd, long long pr, long long j, long long dec) { n   vis[nd] = 1; n   long long s, i, r, is, dtot; n   info cd; n   an[nd] = tot; n   dtot = tot; n   if (v[nd].size() == 0) { n     cd = v[pr][j]; n     if (cd.tp == 1) { n       if (dec) { n         cn[cd.ii][cd.jj] = cn[cd.ii][cd.jj] ^ 1LL; n         cnt[cd.ii]--; n         tot--; n       } n     } else if (cd.tp == 2) { n       if (dec) { n         cn[cd.ii][cd.jj] = cn[cd.ii][cd.jj] ^ 1LL; n         cnt[cd.ii]++; n         tot++; n       } n     } else if (cd.tp == 3) { n       rev[cd.ii]--; n       tot -= cnt[cd.ii]; n       cnt[cd.ii] = m - cnt[cd.ii]; n       tot += cnt[cd.ii]; n     } n     return 1; n   } n   for (i = 0; i <= v[nd].size() - 1; i++) { n     is = 0; n     cd = v[nd][i]; n     if (cd.tp == 4) { n       an[cd.qn] = dtot; n       continue; n     } n     if (cd.tp == 1) { n       if (rev[cd.ii] % 2) { n         if (cn[cd.ii][cd.jj]) { n           cn[cd.ii][cd.jj] = 0; n           is = 1; n           tot++; n           cnt[cd.ii]++; n         } n       } else { n         if (!cn[cd.ii][cd.jj]) { n           cn[cd.ii][cd.jj] = 1; n           is = 1; n           tot++; n           cnt[cd.ii]++; n         } n       } n       r = go(cd.qn, nd, i, is); n     } else if (cd.tp == 2) { n       if (rev[cd.ii] % 2) { n         if (!cn[cd.ii][cd.jj]) { n           is = 1; n           cn[cd.ii][cd.jj] = 1; n           cnt[cd.ii]--; n           tot--; n         } n       } else { n         if (cn[cd.ii][cd.jj]) { n           cn[cd.ii][cd.jj] = 0; n           is = 1; n           tot--; n           cnt[cd.ii]--; n         } n       } n       r = go(cd.qn, nd, i, is); n     } else if (cd.tp == 3) { n       rev[cd.ii]++; n       tot -= cnt[cd.ii]; n       cnt[cd.ii] = m - cnt[cd.ii]; n       tot += cnt[cd.ii]; n       r = go(cd.qn, nd, i, dec); n     } n   } n   if (pr == -1) return 1; n   cd = v[pr][j]; n   if (cd.tp == 1) { n     if (dec) { n       cn[cd.ii][cd.jj] = cn[cd.ii][cd.jj] ^ 1LL; n       cnt[cd.ii]--; n       tot--; n     } n   } else if (cd.tp == 2) { n     if (dec) { n       cn[cd.ii][cd.jj] = cn[cd.ii][cd.jj] ^ 1LL; n       cnt[cd.ii]++; n       tot++; n     } n   } else if (cd.tp == 3) { n     rev[cd.ii]--; n     tot -= cnt[cd.ii]; n     cnt[cd.ii] = m - cnt[cd.ii]; n     tot += cnt[cd.ii]; n   } n   return 1; n } n int main() { n   ios_base::sync_with_stdio(0); n   long long int i, j, x, cnt = 0, y, k, g, flg, q, cnd; n   cin >> n >> m >> q; n   cnd = 0; n   for (i = 1; i <= q; i++) { n     par[i] = -1; n   } n   for (i = 1; i <= q; i++) { n     cin >> k; n     d.tp = k; n     if (k == 4) { n       cin >> y; n       cnd = y; n       d.nxt = -1; n       d.qn = i; n       if (par[y] != -1) n         cnd = par[i] = par[y]; n       else n         cnd = par[i] = y; n       v[cnd].push_back(d); n     } else if (k == 1 || k == 2) { n       cin >> x >> y; n       d.ii = x; n       d.jj = y; n       d.qn = i; n       d.prv = cnd; n       v[cnd].push_back(d); n       cnd = i; n     } else if (k == 3) { n       cin >> x; n       d.ii = x; n       d.qn = i; n       d.prv = cnd; n       v[cnd].push_back(d); n       cnd = i; n     } n   } n   x = go(0, -1, 0, 0); n   for (i = 1; i <= q; i++) { n     cout << an[i] << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long int> v, primev; n int prime[2750150]; n map<long long int, long long int> mp; n void FindPrime() { n   long long int n = 2750140; n   for (long long int i = 4; i <= n; i += 2) { n     prime[i] = true; n   } n   prime[1] = true; n   for (long long int i = 3; i * i <= n; i += 2) { n     if (!prime[i]) { n       for (long long int j = 2; i * j <= n; j++) { n         prime[i * j] = true; n       } n     } n   } n   primev.push_back(2); n   prime[2] = 2; n   int c = 3; n   for (long long int i = 3; i <= n; i = i + 2) { n     if (!prime[i]) { n       prime[i] = c; n       c++; n       primev.push_back(i); n     } n   } n } n long long int divisor(long long int a) { n   long long int chk = sqrt(a + 1); n   for (long long int i = 0; primev[i] <= chk; i++) { n     if (a % primev[i] == 0) { n       long long int res = a / primev[i]; n       return res; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long int a, b, c, d, e, i, j, test; n   FindPrime(); n   cin >> a; n   for (i = 0; i < a * 2; i++) { n     cin >> b; n     mp[b]++; n     v.push_back(b); n   } n   sort(v.rbegin(), v.rend()); n   for (i = 0; i < v.size(); i++) { n     if (mp[v[i]] > 0) { n       if (prime[v[i]] != 1) { n         long long int id = prime[v[i]]; n         id--; n         cout << id <<    ; n         mp[id]--; n         mp[v[i]]--; n       } else { n         long long int id = divisor(v[i]); n         cout << v[i] <<    ; n         mp[id]--; n         mp[v[i]]--; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n const int N = 1e6; n const int M = 2e5 + 10; n const int mod = 1e9 + 7; n long long n, a[M], cnt[N], cnt2[N], sol[N]; n long long brzo_stepenovanje(long long x, long long k) { n   if (k == 0) return 1; n   if (k == 1) return x; n   if (k % 2) n     return (x * brzo_stepenovanje((x * x) % mod, k / 2)) % mod; n   else n     return brzo_stepenovanje((x * x) % mod, k / 2) % mod; n } n int main() { n   scanf( %lld , &n); n   for (int i = 1; i <= n; i++) cnt[i] = 0, cnt2[i] = 0; n   for (int i = 1; i <= n; i++) { n     scanf( %lld , &a[i]); n     cnt2[a[i]]++; n   } n   for (int i = 2; i <= N; i++) n     for (int j = i; j <= N; j += i) { n       cnt[i] += cnt2[j]; n     } n   for (int i = 1; i <= N; i++) sol[i] = 0; n   for (int i = 2; i <= N; i++) n     sol[i] = (cnt[i] * brzo_stepenovanje(2, cnt[i] - 1)) % mod; n   for (int i = N / 2; i >= 2; i--) n     for (int j = i + i; j <= N; j += i) { n       sol[i] -= sol[j]; n       if (sol[i] < 0) sol[i] += mod; n     } n   long long ans = 0; n   for (int i = 2; i <= N; i++) { n     ans += (sol[i] * i) % mod; n     ans %= mod; n   } n   printf( %lld , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   string name; n   vector<struct node *> sub; n }; n typedef struct node *NODE; n class cf56c { n  public: n   int ans = 0; n   void solve(std::istream &in, std::ostream &out) { n     string s; n     int n; n     in >> s; n     n = s.length(); n     stack<struct node *> stk; n     int p = 0; n     string word; n     while (s[p] >=  A  && s[p] <=  Z ) { n       word += s[p]; n       p++; n     } n     NODE root = new struct node; n     root->name = word; n     stk.push(root); n     while (p < n) { n       string t; n       NODE latest = stk.top(); n       if (s[p] ==  ,  || s[p] ==  : ) { n         p++; n         while (s[p] >=  A  && s[p] <=  Z  && p < n) { n           t += s[p]; n           p++; n         } n         NODE child = new struct node; n         child->name = t; n         latest->sub.push_back(child); n         stk.push(child); n       } n       if (s[p] ==  . ) { n         stk.pop(); n         p++; n       } n     } n     unordered_map<string, int> visited; n     dfs(root, visited); n     out << ans; n   } n   void dfs(NODE root, unordered_map<string, int> visited) { n     string employee = root->name; n     vector<NODE> children = root->sub; n     ans += visited[employee]; n     visited[employee]++; n     for (auto &i : children) { n       dfs(i, visited); n     } n   } n }; n int main() { n   ios_base::sync_with_stdio(false); n   cf56c solver; n   std::istream &in(std::cin); n   std::ostream &out(std::cout); n   solver.solve(in, out); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int a, b, c, d; n   scanf( %d%d%d%d , &a, &b, &c, &d); n   int ans = 0; n   if (a == b) { n     ans++; n   } else if (b == c) { n     ans++; n   } else if (b == d) { n     ans++; n   } n   if (a == c) { n     ans++; n   } else if (c == d) { n     ans++; n   } n   if (a == d) { n     ans++; n   } n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Node { n   int l, r, x, id; n } a[1000005]; n bool operator<(const Node& t1, const Node& t2) { n   if (t1.l != t2.l) return t1.l < t2.l; n   if (t1.x != t2.x) return t1.x > t2.x; n   if (t1.r != t2.r) return t1.l < t2.r; n   return t1.x > t2.x; n } n struct Node1 { n   Node1(int a, int b, int c) { n     r = a; n     x = b; n     id = c; n   } n   int r, x, id; n }; n bool operator<(const Node1& t1, const Node1& t2) { n   if (t1.r != t2.r) return t1.r < t2.r; n   return t1.id < t2.id; n } n set<Node1> iset; n int ans[100005]; n int main() { n   int n, m; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i].l >> a[i].r; n     a[i].x = -1; n     a[i].id = i; n   } n   cin >> m; n   for (int i = 0; i < m; i++) { n     cin >> a[i + n].l >> a[i + n].r >> a[i + n].x; n     a[n + i].id = i + 1; n   } n   sort(a, a + m + n); n   for (int i = 0; i < m + n; i++) { n     if (a[i].x != -1) n       iset.insert(Node1(a[i].r, a[i].x, a[i].id)); n     else { n       set<Node1>::iterator it = iset.lower_bound(Node1(a[i].r, 0, 0)); n       if (it != iset.end()) { n         Node1 t = *it; n         iset.erase(it); n         ans[a[i].id] = t.id; n         t.x--; n         if (t.x != 0) iset.insert(t); n       } else { n         cout <<  NO  << endl; n         return 0; n       } n     } n   } n   cout <<  YES  << endl; n   for (int i = 0; i < n - 1; i++) cout << ans[i] <<    ; n   cout << ans[n - 1] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int ntests; n   cin >> ntests; n   while (ntests--) { n     int n, k, a, b; n     cin >> k >> n >> a >> b; n     if (k <= 1ll * n * b) n       cout << -1 << endl; n     else { n       long long x = (k - 1ll * n * b - 1) / (a - b); n       if (x > n) x = n; n       cout << x << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long tree[100002] = {0}; n long long findcf(long long ind) { n   long long sum = 0; n   while (ind > 0) { n     sum += tree[ind]; n     ind -= (ind & (-ind)); n   } n   return sum; n } n void update(long long ind, long long val) { n   while (ind <= 100000) { n     tree[ind] += val; n     ind += (ind & (-ind)); n   } n } n void incFreqFromTo(long long a, long long b, long long delta) { n   update(a, delta); n   update(b + 1, -delta); n } n long long getFreqAt(long long index) { return findcf(index); } n int main() { n   ios::sync_with_stdio(false); n   long long t, i, j, n, m, x; n   cin >> n >> m; n   for (i = 1; i <= n; ++i) { n     cin >> t; n     incFreqFromTo(i, i, t); n   } n   for (i = 0; i < m; ++i) { n     cin >> t; n     if (t == 1) { n       cin >> j >> x; n       incFreqFromTo(j, j, x - getFreqAt(j)); n     } else if (t == 2) { n       cin >> x; n       incFreqFromTo(1, n, x); n     } else { n       cin >> j; n       cout << getFreqAt(j) <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct LINE { n   int start; n   int end; n }; n int ans = 0; n vector<int> res; n string shift(string s, int p1, int p2) { n   char t; n   for (int f = p2; f > p1; f--) { n     ans++; n     res.push_back(f); n     t = s[f]; n     s[f] = s[f - 1]; n     s[f - 1] = t; n   } n   return s; n } n int main() { n   string s, t; n   int a1[27]; n   int a2[27]; n   for (int i = 0; i < 27; i++) { n     a2[i] = 0; n     a1[i] = 0; n   } n   getline(std::cin, s); n   getline(std::cin, s); n   getline(std::cin, t); n   for (int i = 0; i < s.length(); i++) { n     a1[((int)s[i]) - 97]++; n   } n   for (int i = 0; i < t.length(); i++) { n     a2[((int)t[i]) - 97]++; n   } n   for (int i = 0; i < 27; i++) { n     if (a1[i] != a2[i]) { n       cout << -1; n       return 0; n     } n   } n   for (int i = 0; i < s.length(); i++) { n     if (s[i] == t[i]) continue; n     int a = s.find(t[i], i); n     s = shift(s, i, a); n   } n   cout << ans <<   n ; n   for (int i = 0; i < res.size(); i++) { n     cout << res[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int i; n char s[100005]; n int main() { n   scanf( %s , s); n   int l = strlen(s); n   for (i = 0; i < l; i++) { n     if (s[i] == s[l - 1 - i]) continue; n     return 0 * printf( NO n ); n   } n   for (i = 0; i < l; i++) { n     if (s[i] ==  A  || s[i] ==  H  || s[i] ==  I  || s[i] ==  M  || n         s[i] ==  O  || s[i] ==  T  || s[i] ==  U  || s[i] ==  V  || n         s[i] ==  W  || s[i] ==  X  || s[i] ==  Y ) n       continue; n     return 0 * printf( NO n ); n   } n   printf( YES n ); n } n


#include <bits/stdc++.h> n using namespace std; n int n; n char in[100005]; n int main() { n   scanf( %d %s , &n, in); n   for (int i = 1; i < n; i++) { n     if (in[i] == in[i - 1]) { n       for (int j = i;; j++) { n         in[j] = 1 - (in[j] -  0 ) +  0 ; n         if (in[j + 1] != in[j]) break; n       } n       break; n     } n   } n   char prv =  2 ; n   int cnt = 0; n   for (int i = 0; i < n; i++) n     if (in[i] != prv) { n       prv = in[i]; n       cnt++; n     } n   printf( %d , cnt); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7, maxn = 1e6 + 6; n int n, m, k, x, res = 1, fact[maxn]; n map<vector<int>, int> f; n vector<int> a[maxn]; n int main() { n   fact[0] = 1; n   for (int i = 1; i < maxn; ++i) fact[i] = 1LL * fact[i - 1] * i % mod; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &k); n     for (int j = 1; j <= k; ++j) { n       scanf( %d , &x); n       a[x].push_back(i); n     } n   } n   for (int i = 1; i <= m; ++i) sort(a[i].begin(), a[i].end()), ++f[a[i]]; n   for (map<vector<int>, int>::iterator it = f.begin(); it != f.end(); ++it) { n     res = 1LL * res * fact[it->second] % mod; n   } n   printf( %d , res); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, a[100], b[100], i; n   cin >> t; n   string s1, s2; n   while (t--) { n     set<char> track; n     string s3 =   , s4; n     int flag = 0; n     cin >> s1 >> s2; n     if (s1.size() > s2.size()) { n       cout <<  NO  << endl; n       continue; n     } n     s4 = s1; n     sort(s4.begin(), s4.end()); n     for (i = 0; s1[i]; i++) track.insert(s1[i]); n     for (i = 0; i <= s2.size() - s1.size(); i++) { n       int cnt = 0, k = i; n       s3 =   ; n       for (int j = 0; j < s1.size(); j++) { n         s3 += s2[k++]; n       } n       sort(s3.begin(), s3.end()); n       if (s4 == s3) { n         cout <<  YES  << endl; n         flag = 1; n         break; n       } n     } n     if (flag == 0) cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 5, M = 5e5 + 5; n bool vis[N]; n int q[N], tot, fa[N]; n int n, m, k, head[N], ne[M << 1], to[M << 1], cnt, d[N]; n inline int read() { n   int x, f = 1; n   char ch; n   while (!(isdigit(ch = getchar()))) ch ==  -  ? f = -1 : f; n   x = ch ^ 48; n   while ((isdigit(ch = getchar()))) x = (x << 1) + (x << 3) + (ch ^ 48); n   return f * x; n } n inline void ins(int x, int y) { n   ne[++cnt] = head[x]; n   head[x] = cnt; n   to[cnt] = y; n } n inline void dfs(int x) { n   vis[x] = 1; n   if (d[x] >= (n + k - 1) / k) { n     puts( PATH ); n     printf( %d n , d[x]); n     while (x) printf( %d  , x), x = fa[x]; n     exit(0); n   } n   bool pd = 0; n   for (int i = head[x]; i; i = ne[i]) { n     if (fa[x] == to[i] || vis[to[i]]) continue; n     fa[to[i]] = x; n     d[to[i]] = d[x] + 1; n     pd = 1; n     dfs(to[i]); n   } n   if (!pd) q[++tot] = x; n } n int main() { n   n = read(); n   m = read(); n   k = read(); n   for (int i = 1; i <= m; i++) { n     int x = read(), y = read(); n     ins(x, y); n     ins(y, x); n   } n   d[1] = 1; n   dfs(1); n   puts( CYCLES ); n   for (int j = 1; j <= k; j++) { n     int x = q[j], y = 0, z = 0; n     for (int i = head[x]; i; i = ne[i]) { n       if (fa[x] == to[i]) continue; n       if (!y) n         y = to[i]; n       else n         z = to[i]; n     } n     int res = d[x] - d[y] + 1; n     if (res % 3) { n       printf( %d n , res); n       while (x != y) { n         printf( %d  , x); n         x = fa[x]; n       } n       printf( %d n , y); n       continue; n     } n     res = d[x] - d[z] + 1; n     if (res % 3) { n       printf( %d n , res); n       while (x != z) { n         printf( %d  , x); n         x = fa[x]; n       } n       printf( %d n , z); n       continue; n     } n     if (d[y] < d[z]) swap(y, z); n     res = d[y] - d[z] + 2; n     printf( %d n , res); n     while (y != z) { n       printf( %d  , y); n       y = fa[y]; n     } n     printf( %d %d n , z, x); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 5; n const int INF = 2e9; n const int MOD = 1e9 + 7; n int main() { n   vector<int> RES; n   string S =   ; n   cin >> S; n   int N = S.size(), last = -1, depth = 0; n   for (int i = 0; i < N; i++) { n     if (S[i] ==  ( ) n       depth++; n     else { n       if (S[i] ==  # ) last = i; n       depth--; n     } n     if (depth < 0) return printf( -1 ), 0; n   } n   int val = depth; n   depth = 0; n   for (int i = 0; i < N; i++) { n     if (S[i] ==  ( ) n       depth++; n     else { n       int removeIt = (i == last && S[i] ==  #  ? val : 0) + 1; n       depth -= removeIt; n       if (S[i] ==  # ) RES.push_back(removeIt); n     } n     if (depth < 0) return printf( -1 ), 0; n   } n   for (int i = 0; i < RES.size(); i++) printf( %i n , RES[i]); n   return 0; n } n


#include <bits/stdc++.h> n void swap(long double& a, long double& b) { n   long double tmp = a; n   a = b, b = tmp; n } n long double solve(long double d, long double r, long double R) { n   const long double EPS = 1e-9L; n   if (d + EPS >= r + R) return 0; n   if (r > R) swap(r, R); n   if (R + EPS >= d + r) return acosl(-1.0) * r * r; n   long double T = 2 * acosl((R * R + d * d - r * r) / (2 * R * d)), n               t = 2 * acosl((r * r + d * d - R * R) / (2 * r * d)); n   return .5 * (R * R * (T - sinl(T)) + r * r * (t - sinl(t))); n } n int main() { n   long double x1, y1, r1, x2, y2, r2; n   scanf( %Lf%Lf%Lf%Lf%Lf%Lf , &x1, &y1, &r1, &x2, &y2, &r2); n   long double dx = x1 - x2, dy = y1 - y2; n   printf( %.20Lf n , solve(sqrtl(dx * dx + dy * dy), r1, r2)); n } n


#include <bits/stdc++.h> n using namespace std; n const long long int inf = 1000000000; n const long long int mod = 1000000000 + 7; n inline void IO() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n inline int dcmp(long double x) { return x < -1e-12 ? -1 : (x > 1e-12); } n template <class T> n inline int CHECK(T MASK, int i) { n   return (MASK >> i) & 1; n } n template <class T> n inline T ON(T MASK, int i) { n   return MASK | (T(1) << i); n } n template <class T> n inline T OFF(T MASK, int i) { n   return MASK & (~(T(1) << i)); n } n template <typename T> n inline int CNT(T MASK) { n   if (numeric_limits<T>::digits <= numeric_limits<unsigned int>::digits) n     return __builtin_popcount(MASK); n   else n     return __builtin_popcountll(MASK); n } n template <class T> n inline int RIGHT(T MASK) { n   return log2(MASK & -MASK); n } n int dx4[] = {0, 0, -1, +1}; n int dy4[] = {+1, -1, 0, 0}; n int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1, 0}; n int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1, 0}; n inline void I(int& a) { scanf( %d , &a); } n inline void I(long long int& a) { scanf( %I64d , &a); } n inline void I(unsigned long long int& a) { scanf( %I64u , &a); } n inline void I(char* a) { scanf( %s , a); } n char Iarr[2000010]; n inline void I(string& a) { n   scanf( %s , Iarr); n   a = Iarr; n } n template <typename T, typename... Args> n void I(T& a, Args&... args) { n   I(a); n   I(args...); n } n inline void OUT(int a) { printf( %d , a); } n inline void OUT(long long int a) { printf( %I64d , a); } n inline void OUT(const char* a) { printf( %s , a); } n inline void OUT(char* a) { printf( %s , a); } n inline void OUT(bool a) { printf( %d , a); } n inline void OUT(string a) { n   for (__typeof(a.end()) it = (a.begin()) - ((a.begin()) > (a.end())); n        it != (a.end()) - ((a.begin()) > (a.end())); n        it += 1 - 2 * ((a.begin()) > (a.end()))) n     printf( %c , *it); n } n inline void OUT(unsigned long long int a) { printf( %I64u , a); } n template <typename T, typename... Args> n void OUT(T a, Args... args) { n   OUT(a); n   OUT(   ); n   OUT(args...); n } n template <typename... Args> n void O(Args... args) { n   OUT(args...); n   OUT(  n ); n } n template <typename T1, typename T2> n inline ostream& operator<<(ostream& os, pair<T1, T2> p) { n   os <<  {  << p.first <<  ,   << p.second <<  } ; n   return os; n } n template <typename T> n inline ostream& operator<<(ostream& os, vector<T>& a) { n   os <<  [ ; n   for (int i = 0; i < (int)a.size(); i++) { n     if (i) os <<  ,  ; n     os << a[i]; n   } n   os <<  ] ; n   return os; n } n void err(istream_iterator<string> it) {} n template <typename T, typename... Args> n void err(istream_iterator<string> it, T a, Args... args) { n   cout << *it <<   =   << a << endl; n   err(++it, args...); n } n const int M = 100010; n vector<pair<long long int, pair<int, int> > > ans[51]; n int n, p; n long double fnl = 0; n void func() { n   for (int i = 1; i <= p; i++) { n     for (pair<long long int, pair<int, int> > pp : ans[i]) { n       long double res = i * pp.first; n       int z = 1; n       int zz = 1; n       int curr = 1; n       while (1) { n         if (res > 0) { n           if (curr != n + 1) n             res /= curr++; n           else if (z != pp.second.first + 1) n             res *= z++; n           else if (zz != pp.second.second + 1) n             res *= zz++; n           else n             break; n         } else { n           if (z != pp.second.first + 1) n             res *= z++; n           else if (zz != pp.second.second + 1) n             res *= zz++; n           else if (curr != n + 1) n             res /= curr++; n           else n             break; n         } n       } n       fnl += res; n     } n   } n } n int main() { n   IO(); n   cin >> n; n   int a[n]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   cin >> p; n   int sum = 0; n   for (int i = 0; i < n; i++) { n     sum += a[i]; n   } n   if (sum <= p) { n     cout << n << endl; n     exit(0); n   } n   for (int i = 0; i < n; i++) { n     vector<int> v; n     for (int j = 0; j < n; j++) { n       if (j != i) v.push_back(a[j]); n     } n     long long int dp[51][51][51] = {0}; n     for (int j = 0; j < n - 1; j++) { n       for (int k = 0; k <= j + 1; k++) { n         for (int l = 0; l <= 50; l++) { n           if (j == 0) { n             if (k == 1 && v[j] == l) n               dp[j][k][l] = 1; n             else if (k == 0 && l == 0) n               dp[j][k][l] = 1; n           } else if (k == 0) { n             if (l == 0) dp[j][k][l] = 1; n           } else { n             dp[j][k][l] = dp[j - 1][k][l]; n             if (v[j] <= l) dp[j][k][l] += dp[j - 1][k - 1][l - v[j]]; n           } n         } n       } n     } n     for (int l = p - a[i] + 1; l <= p; l++) { n       for (int gb = 1; gb <= n; gb++) { n         if (l >= 0) n           if ((n - 1 - gb) > 0 && (n - 2) >= 0) n             ans[gb].push_back( n                 make_pair(dp[n - 2][gb][l], make_pair(gb, n - 1 - gb))); n           else if ((n - 1 - gb) == 0 && (n - 2) >= 0) n             ans[gb].push_back(make_pair(dp[n - 2][gb][l], make_pair(gb, 1))); n         int k = (int)ans[gb].size(); n         if (k != 0) { n         } n       } n     } n   } n   func(); n   cout << setprecision(12) << fixed << fnl << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long d, k, tc, tf, tr, res = 100 * 100 * 100 * 100LL; n   scanf( %lld , &d); n   ; n   scanf( %lld , &k); n   ; n   scanf( %lld , &tc); n   ; n   scanf( %lld , &tf); n   ; n   scanf( %lld , &tr); n   ; n   if (k >= d) return 0 * printf( %lld , d * tc); n   if (k * tc + tr >= k * tf) return 0 * printf( %lld , k * tc + (d - k) * tf); n   long long chk = d / k; n   long long bach_gya = d % k; n   printf( %lld , tr * (chk - 1) + tc * chk * k + n                      min(bach_gya * tc + tr, bach_gya * tf)); n } n


#include <bits/stdc++.h> n using namespace std; n int f[100001], d[40], sor[100001]; n int n, kq; n bool solve(int a, int b, int &x, int &y) { n   if (a % 2 != b % 2) return false; n   y = (a + b) / 2; n   x = (a - b) / 2; n   return true; n } n int main() { n   scanf( %d , &n); n   kq = -1; n   for (int i = 3; i < n + 1; i++) { n     memset(d, false, sizeof(d)); n     for (int j = 2; j * j <= 2 * i; j++) n       if ((2 * i) % j == 0) { n         int x, y; n         if (solve((2 * i) / j, j - 1, x, y)) { n           d[sor[y] ^ sor[x - 1]] = true; n           if (i == n && sor[y] == sor[x - 1]) n             if (kq == -1 || j < kq) kq = j; n         } n       } n     for (int j = 0; j < 40; j++) n       if (!d[j]) { n         f[i] = j; n         sor[i] = sor[i - 1] ^ j; n         if (i == n && f[i] == 0) kq = -1; n         break; n       } n   } n   cout << kq << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 5; n const long long mod = 998244353; n int mp[maxn], a[maxn]; n char s[maxn]; n int main() { n   int T; n   scanf( %d , &T); n   while (T--) { n     int n, x; n     scanf( %d , &n); n     scanf( %d , &x); n     scanf( %s , s + 1); n     int mn = 1e9, mx = -1e9; n     for (int i = (1); i <= (n); i++) { n       if (s[i] ==  0 ) n         a[i] = a[i - 1] + 1; n       else n         a[i] = a[i - 1] - 1; n       mx = max(mx, a[i]), mn = min(mn, a[i]); n     } n     for (int i = (0); i <= (mx - mn); i++) mp[i] = 0; n     for (int i = (1); i <= (n); i++) mp[a[i] - mn]++; n     if (a[n] == 0) { n       if (x < mn || x > mx || mp[x - mn] == 0) { n         if (x != 0) n           puts( 0 ); n         else n           puts( 1 ); n       } else n         puts( -1 ); n       continue; n     } n     if (a[n] > 0) { n       int l = 0, r = 1e9, pos = -1; n       while (l <= r) { n         int mid = l + r >> 1; n         if (x >= 1ll * mid * a[n] + mn && x <= 1ll * mid * a[n] + mx) n           pos = mid, r = mid - 1; n         else if (x < 1ll * mid * a[n] + mn) n           r = mid - 1; n         else n           l = mid + 1; n       } n       long long ans = 0; n       if (pos == -1) n         ans = 0; n       else { n         int mpx = -1; n         for (int i = pos * a[n] + mn; i <= pos * a[n] + mx; i++) { n           if (i <= x) n             mpx++; n           else n             break; n         } n         for (int i = mpx; i >= 0; i -= a[n]) ans += mp[i]; n       } n       if (x == 0) ans++; n       printf( %lld , ans); n       puts(  ); n     } else { n       int l = 0, r = 1e9, pos = -1; n       while (l <= r) { n         int mid = l + r >> 1; n         if (x >= 1ll * mid * a[n] + mn && x <= 1ll * mid * a[n] + mx) n           pos = mid, r = mid - 1; n         else if (x < 1ll * mid * a[n] + mn) n           l = mid + 1; n         else n           r = mid - 1; n       } n       long long ans = 0; n       if (pos == -1) n         ans = 0; n       else { n         int mpx = -1; n         for (int i = pos * a[n] + mn; i <= pos * a[n] + mx; i++) { n           if (i <= x) n             mpx++; n           else n             break; n         } n         for (int i = mpx; i <= mx - mn; i += (-a[n])) ans += mp[i]; n       } n       if (x == 0) ans++; n       printf( %lld , ans); n       puts(  ); n     } n   } n } n


#include<bits/stdc++.h> n using namespace std; n typedef pair<int,int> pi; n const int maxn=1e5+7; n double dp[maxn][10]; n int pre[maxn][10]; n int main() n { n     ios::sync_with_stdio(false); n     cin.tie(nullptr); n     int n,d; n     cin>>n>>d; n     vector<int> a(n+1); n     for(int i=0;i<maxn;i++) for(int j=0;j<10;j++) dp[i][j]=-1e9; n     dp[0][1]=0; n     for(int i=1;i<=n;i++) n     { n         cin>>a[i]; n         double val=log(a[i]); n         for(int j=0;j<10;j++) n         { n             int nxt=j*a[i]%10; n             if(dp[i-1][j]>dp[i][j]) n             { n                 dp[i][j]=dp[i-1][j]; n                 pre[i][j]=j; n             } n             if(dp[i-1][j]+val>dp[i][nxt]) n             { n                 dp[i][nxt]=dp[i-1][j]+val; n                 pre[i][nxt]=j; n             } n         } n     } n     if(dp[n][d]<0) n     { n         cout<<-1<<  n ; n         return 0; n     } n     vector<int> ans; n     int cur=d; n     for(int i=n;i>=1;i--) n     { n         int cc=a[i]%10; n         if((pre[i][cur]*cc)%10==cur) n         { n             cur=pre[i][cur]; n             ans.push_back(a[i]); n         } n     } n     if(ans.size()==0) n     { n         cout<<-1<<  n ; n         return 0; n     } n     cout<<ans.size()<<  n ; n     for(int i=0;i<ans.size();i++) cout<<ans[i]<<   n [i+1==ans.size()]; n  n }


#include <bits/stdc++.h> n using namespace std; n inline char gc() { n   static char buf[100000], *p1 = buf, *p2 = buf; n   return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) n              ? EOF n              : *p1++; n } n inline long long read() { n   long long x = 0; n   char ch = getchar(); n   bool positive = 1; n   for (; !isdigit(ch); ch = getchar()) n     if (ch ==  - ) positive = 0; n   for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ; n   return positive ? x : -x; n } n inline void write(long long a) { n   if (a < 0) { n     a = -a; n     putchar( - ); n   } n   if (a >= 10) write(a / 10); n   putchar( 0  + a % 10); n } n inline void writeln(long long a) { n   write(a); n   puts(  ); n } n inline void wri(long long a) { n   write(a); n   putchar(   ); n } n inline unsigned long long rnd() { n   return ((unsigned long long)rand() << 30 ^ rand()) << 4 | rand() % 4; n } n const int N = 150005; n long double l[N], r[N]; n struct data { n   long long p, t, id; n } a[N], b[N]; n int n; n long long T; n bool cmp(data a, data b) { return a.p < b.p; } n bool cmpt(data a, data b) { n   long long A = (long long)a.t * b.p, B = (long long)b.t * a.p; n   return A == B ? a.p < b.p : A < B; n } n bool check(long double c) { n   long long sum = 0; n   for (int i = 1, j; i <= n; i = j) { n     j = i + 1; n     while (j <= n && a[j].t * a[i].p == a[i].t * a[j].p) j++; n     for (int k = (int)(i); k <= (int)(j - 1); k++) n       r[a[k].id] = (1 - c * (sum + a[k].t) / T) * a[k].p; n     for (int k = (int)(i); k <= (int)(j - 1); k++) sum += a[k].t; n     for (int k = (int)(i); k <= (int)(j - 1); k++) n       l[a[k].id] = (1 - c * sum / T) * a[k].p; n   } n   int dq = n; n   long double mn = 1e100; n   for (int i = (int)(n); i >= (int)(1); i--) { n     while (b[dq].p > b[i].p) { n       mn = min(mn, l[b[dq--].id]); n     } n     if (mn <= r[b[i].id]) return 0; n   } n   return 1; n } n int main() { n   n = read(); n   for (int i = (int)(1); i <= (int)(n); i++) a[a[i].id = i].p = read(); n   for (int i = (int)(1); i <= (int)(n); i++) T += (a[i].t = read()); n   for (int i = (int)(1); i <= (int)(n); i++) b[i] = a[i]; n   sort(a + 1, a + n + 1, cmpt); n   sort(b + 1, b + n + 1, cmp); n   long double l = 0, r = 1; n   for (int i = (int)(1); i <= (int)(80); i++) { n     long double mid = (l + r) / 2; n     if (check(mid)) n       l = mid; n     else n       r = mid; n   } n   printf( %.10f , (double)l); n } n


#include<bits/stdc++.h> n using namespace std; n  n int check(vector<long long> a) { n  for (int i = 0; i + 1 < a.size(); i++) { n   if (a[i] > a[i + 1]) { n    return 0; n   } n   a[i + 1] -= a[i]; n   a[i] = 0; n  } n  if (a.back() == 0) n   return 1; n  return 0; n } n  n void solve() { n  int n; n  cin >> n; n  vector<long long> a(n); n  for (int i = 0; i < n; i++) { n   cin >> a[i]; n  } n  if (check(a)) { n   cout <<  YES n ; n   return; n  } n  if (n == 1) { n   cout <<  NO n ; n   return; n  } n  swap(a[0], a[1]); n  if (check(a)) { n   cout <<  YES n ; n   return; n  } n  swap(a[0], a[1]); n  swap(a[n - 2], a[n - 1]); n  if (check(a)) { n   cout <<  YES n ; n   return; n  } n  swap(a[n - 2], a[n - 1]); n  vector<long long> p(n), s(n); n  vector<long long> b = a; n  p[0] = b[0]; n  for (int i = 1; i < n; i++) { n   if (p[i - 1] == -1 || b[i - 1] > b[i]) { n    p[i] = -1; n   } else { n    b[i] -= b[i - 1]; n    b[i - 1] = 0; n    p[i] = b[i]; n   } n  } n  b = a; n  s[n - 1] = b[n - 1]; n  for (int i = n - 2; i >= 0; i--) { n   if (s[i + 1] == -1 || b[i + 1] > b[i]) { n    s[i] = -1; n   } else { n    b[i] -= b[i + 1]; n    b[i + 1] = 0; n    s[i] = b[i]; n   } n  } n  for (int i = 1; i + 2 < n; i++) { n   vector<long long> c = {p[i - 1], a[i], a[i + 1], s[i + 2]}; n   if (p[i - 1] == -1 || s[i + 2] == -1) { n    continue; n   } n   swap(c[1], c[2]); n   if (check(c)) { n    cout <<  YES n ; n    return; n   } n  } n  cout <<  NO n ; n } n  n int main() { n  ios_base::sync_with_stdio(false); n  cin.tie(0); n  cout.tie(0); n  int t; n  cin >> t; n  while (t--) { n   solve(); n  } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 7; n set<int> a[N], b[N]; n int maxa[N << 2], minb[N << 2]; n int badv = 0; n bool bad(int v, int l, int r) { n   if (l == r) { n     return a[l].size() && b[l].size() && *a[l].rbegin() >= *b[l].begin(); n   } else { n     return maxa[v * 2 + 2] >= minb[v * 2 + 1]; n   } n } n void relax(int v) { n   maxa[v] = max(maxa[v * 2 + 1], maxa[v * 2 + 2]); n   minb[v] = min(minb[v * 2 + 1], minb[v * 2 + 2]); n } n void upd_a(int v, int l, int r, int x, int y) { n   if (l == r) { n     badv -= bad(v, l, r); n     if (a[x].find(y) == a[x].end()) n       a[x].insert(y); n     else n       a[x].erase(y); n     if (a[x].empty()) n       maxa[v] = -N; n     else n       maxa[v] = *a[x].rbegin(); n     badv += bad(v, l, r); n     return; n   } n   badv -= bad(v, l, r); n   int m = (l + r) >> 1; n   if (x <= m) n     upd_a(v * 2 + 1, l, m, x, y); n   else n     upd_a(v * 2 + 2, m + 1, r, x, y); n   relax(v); n   badv += bad(v, l, r); n } n void upd_b(int v, int l, int r, int x, int y) { n   if (l == r) { n     badv -= bad(v, l, r); n     if (b[x].find(y) == b[x].end()) n       b[x].insert(y); n     else n       b[x].erase(y); n     if (b[x].empty()) n       minb[v] = N; n     else n       minb[v] = *b[x].begin(); n     badv += bad(v, l, r); n     return; n   } n   badv -= bad(v, l, r); n   int m = (l + r) >> 1; n   if (x <= m) n     upd_b(v * 2 + 1, l, m, x, y); n   else n     upd_b(v * 2 + 2, m + 1, r, x, y); n   relax(v); n   badv += bad(v, l, r); n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   for (int i = 0; i < (N << 2); ++i) { n     maxa[i] = -N; n     minb[i] = N; n   } n   int n, m, q; n   cin >> n >> m >> q; n   while (q--) { n     int x, y; n     cin >> x >> y; n     --x; n     --y; n     if (x & 1) { n       upd_a(0, 0, N, x / 2, y / 2); n     } else { n       upd_b(0, 0, N, x / 2, y / 2); n     } n     if (badv == 0) n       cout <<  YES  <<   n ; n     else n       cout <<  NO  <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c; n   cin >> a >> b >> c; n   long long ans = 0; n   for (int i = 1; i < min(b, c); i++) { n     ans += a; n     a++; n   } n   ans *= 2; n   for (int i = min(b, c); i <= max(b, c); i++) { n     ans += a; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int N = 1e5; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int tc = 1; n   for (long long int T = 1; T <= tc; T++) { n     long long int n; n     cin >> n; n     string s; n     cin >> s; n     long long int cnt = 0, flag = 0; n     for (long long int i = 0; i < n - 1; i++) { n       if (s[i] == s[i + 1] and s[i] !=  ? ) { n         flag = 1; n         break; n       } n     } n     if (flag) { n       cout <<  No n ; n       return 0; n     } n     if (s[0] ==  ?  or s[n - 1] ==  ? ) { n       cout <<  Yes n ; n       return 0; n     } n     long long int tot = 0, ok = 0; n     char start =  $ , end =  $ ; n     for (long long int i = 0; i < n; i++) { n       if (s[i] !=  ?  and flag == 0) { n         start = s[i]; n       } else if (s[i] ==  ? ) { n         cnt++; n         flag = 1; n       } else { n         end = s[i]; n         if (cnt == 1) { n           if (start == end) { n             ok = 1; n             break; n           } n         } else { n           ok = 1; n           break; n         } n         start = end; n         cnt = 0; n         flag = 0; n       } n     } n     if (ok) n       cout <<  Yes n ; n     else n       cout <<  No n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int bs(vector<int>& a, int que) { n   auto it = lower_bound(a.begin(), a.end(), que); n   if (*it == que) { n     return it - a.begin(); n   } n   return -1; n } n bool isprime(int x) { n   if (x == 2) return true; n   if (x < 2) return false; n   for (int i = 2; i * i <= x; i++) n     if (x % i == 0) return false; n   if (x == 0) return false; n   return true; n } n int main() { n   int n; n   cin >> n; n   int a[10001]; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   vector<int> sol; n   sol.push_back(a[n]); n   for (int i = n; i >= 2; i--) { n     if (a[i] == 1) { n       sol.push_back(a[i - 1]); n     } n   } n   reverse(sol.begin(), sol.end()); n   cout << sol.size() << endl; n   for (int i = 0; i <= sol.size() - 1; i++) { n     cout << sol[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int n, k; n   cin >> n >> k; n   set<long long int> s; n   map<long long int, long long int> mp; n   long long int x; n   for (long long int i = 0; i < n; i++) { n     cin >> x; n     s.insert(x); n     mp[x] = i + 1; n   } n   if (s.size() < k) { n     cout <<  NO  << endl; n     return 0; n   } else { n     cout <<  YES  << endl; n     map<long long int, long long int>::iterator it; n     long long int c = 0; n     for (it = mp.begin(); it != mp.end(); it++) { n       if (c != k) { n         cout << it->second <<    ; n         c++; n       } else n         break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char a[2000][1000]; n int main() { n   int n, s; n   cin >> n; n   int nowx = 0, nowy = 1000; n   int miny = 1000, maxy = 1000; n   for (int i = 0; i < n; i++) { n     cin >> s; n     for (int j = nowx; j < nowx + s; j++) n       if (i % 2 == 0) n         a[nowy][j] =  / , maxy = max(maxy, nowy++); n       else n         a[--nowy][j] =     , miny = min(miny, nowy); n     nowx += s; n   } n   for (int i = maxy; i >= miny; i--, cout << endl) n     for (int j = 0; j < nowx; j++) n       if (a[i][j]) n         cout << a[i][j]; n       else n         cout <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   priority_queue<pair<unsigned long long int, int> > matches; n   unsigned long long int n; n   int m; n   unsigned long long int a; n   int b; n   unsigned long long int max = 0; n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     cin >> a >> b; n     pair<int, unsigned long long int> d; n     d.first = b; n     d.second = a; n     matches.push(d); n   } n   while (matches.size() != 0 && m != 0) { n     pair<int, unsigned long long int> d = matches.top(); n     if (d.second > n) { n       max += n * d.first; n       n = 0; n     } else { n       max += d.second * d.first; n       n -= d.second; n     } n     matches.pop(); n   } n   cout << max << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int v[2][1000000 + 10]; n void solve(int n, int p) { n   if (n == 0) { n     v[p][0] = 0; n     return; n   } n   if (!(n & (n + 1))) { n     for (int i = 0; i <= n; ++i) { n       v[p][i] = n - i; n     } n   } else { n     int two = 1; n     while (two * 2 < n + 1) two *= 2; n     solve(n - two, p ^ 1); n     for (int i = 0; i <= n - two; ++i) { n       v[p][i] = two + v[p ^ 1][i]; n     } n     int cur = two; n     for (int i = two; i <= n; ++i) { n       --cur; n       v[p][i] = cur; n     } n     for (int i = n - two + 1; i < two; ++i) { n       --cur; n       v[p][i] = cur; n     } n   } n } n int main() { n   cin >> n; n   long long s = 0; n   for (int i = 0; i <= n; ++i) s += i; n   cout << s + s << endl; n   solve(n, 0); n   for (int i = 0; i <= n; ++i) { n     printf( %d  , v[0][i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   int n; n   scanf( %d , &n); n   vector<int> game(n + 1); n   game[0] = game[1] = game[2] = 0; n   vector<int> res(n + 1, -1); n   for (int i = 3; i <= n; i++) { n     int ok[300001]; n     memset(ok, 0, sizeof(0)); n     for (int j = 2; i - (j * (j - 1)) / 2 >= 0; j++) { n       int x = i - ((j) * (j - 1)) / 2; n       if (x % j == 0) { n         x /= j; n         int Xor = 0; n         for (int k = 0; k < j; k++) { n           Xor ^= game[x + k]; n         } n         ok[Xor] = i; n         if (Xor == 0 && res[i] == -1) { n           res[i] = j; n         } n       } n     } n     int r = 0; n     while (ok[r] == i) r++; n     game[i] = r; n     if (game[i] == 0) res[i] = -1; n   } n   printf( %d n , res[n]); n } n


#include <bits/stdc++.h> n using namespace std; n int A[100005], P[100005]; n int other_end[100005]; n long long ans[100005], seg[100005]; n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; ++i) scanf( %d , &A[i]); n   for (int i = 1; i <= n; ++i) scanf( %d , &P[i]); n   long long res = 0; n   for (int i = n; i >= 1; --i) { n     ans[i] = res; n     int pos = P[i]; n     long long sum = A[pos]; n     int l = pos, r = pos; n     if (other_end[pos - 1] != 0) { n       l = other_end[pos - 1]; n       sum += seg[l]; n     } n     if (other_end[pos + 1] != 0) { n       sum += seg[pos + 1]; n       r = other_end[pos + 1]; n     } n     other_end[l] = r; n     other_end[r] = l; n     seg[l] = sum; n     if (sum > res) res = sum; n   } n   for (int i = 1; i <= n; ++i) cout << ans[i] << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker, ”/ STACK : 38777216“ n using namespace std; n const int N = 100005; n const int inf = 1000 * 1000 * 1000; n const int mod = 1000 * 1000 * 1000 + 7; n string s; n int a, b, c, d, t; n int main() { n   cin >> t >> s; n   if (t % 4 != 0) { n     cout <<  ===  << endl; n     return 0; n   } n   t /= 4; n   for (int i = 0; i < 4 * t; i++) { n     if (s[i] ==  A ) a++; n     if (s[i] ==  C ) b++; n     if (s[i] ==  G ) c++; n     if (s[i] ==  T ) d++; n   } n   if (a > t || b > t || c > t || d > t) { n     cout <<  ===  << endl; n     return 0; n   } n   a = t - a; n   b = t - b; n   c = t - c; n   d = t - d; n   for (int i = 0; i < 4 * t; i++) { n     if (s[i] !=  ? ) continue; n     if (a > 0) { n       s[i] =  A ; n       a--; n       continue; n     } n     if (b > 0) { n       s[i] =  C ; n       b--; n       continue; n     } n     if (c > 0) { n       s[i] =  G ; n       c--; n       continue; n     } n     s[i] =  T ; n     d--; n   } n   cout << s << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int degree; n   int xorsum; n }; n struct Edge { n   int src, des; n }; n struct node virtex[100000]; n vector<struct Edge> edge; n vector<struct Edge>::iterator it; n queue<int> que; n int main() { n   struct Edge temp; n   int n, d, s, i, src, des; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> virtex[i].degree >> virtex[i].xorsum; n   } n   for (i = 0; i < n; i++) { n     if (virtex[i].degree == 1) { n       que.push(i); n     } n   } n   while (!que.empty()) { n     src = que.front(); n     que.pop(); n     if (virtex[src].degree == 1) { n       des = virtex[src].xorsum; n       temp.src = src; n       temp.des = des; n       edge.push_back(temp); n       virtex[des].degree--; n       virtex[des].xorsum ^= src; n       if (virtex[des].degree == 1) { n         que.push(des); n       } n     } n   } n   cout << edge.size() << endl; n   it = edge.begin(); n   while (it != edge.end()) { n     cout << it->src <<     << it->des << endl; n     it++; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000010; n int cnt[N]; n int a, b, n; n void genPrime() { n   for (int i = 2; i < N; ++i) cnt[i] = 1; n   for (int i = 2; i <= 1000; ++i) n     if (cnt[i]) n       for (int j = i * i; j < N; cnt[j] = 0, j += i) n         ; n   for (int i = 1; i < N; ++i) cnt[i] += cnt[i - 1]; n } n bool chk(int x) { n   for (int i = a; i + x - 1 <= b; ++i) { n     int j = i + x - 1; n     if (cnt[j] - cnt[i - 1] < n) return false; n   } n   return true; n } n int main() { n   int i, j, k; n   genPrime(); n   scanf( %d%d%d , &a, &b, &n); n   if (cnt[b] - cnt[a - 1] < n) { n     printf( -1 n ); n     return 0; n   } n   int low = 1, up = b - a + 1; n   while (up > low) { n     int mid = (up + low) / 2; n     if (chk(mid)) n       up = mid; n     else n       low = mid + 1; n   } n   printf( %d n , up); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 20; n int n; n int a[N]; n int b[N]; n vector<string> ans; n int get(int s, int e) { n   int res = 0; n   for (int i = s; i < e; ++i) { n     res = res * 10 + b[i]; n   } n   return res; n } n string getstr(int x, int y, int z, int l) { n   string s =   ; n   for (int i = 0; i < x; ++i) { n     s += b[i] +  0 ; n   } n   s +=  . ; n   for (int i = x; i < y; ++i) { n     s += b[i] +  0 ; n   } n   s +=  . ; n   for (int i = y; i < z; ++i) { n     s += b[i] +  0 ; n   } n   s +=  . ; n   for (int i = z; i < l; ++i) { n     s += b[i] +  0 ; n   } n   return s; n } n int check(int x, int y, int z, int l) { n   if (x > 3) return 0; n   if (y - x > 3) return 0; n   if (z - y > 3) return 0; n   if (l - z > 3) return 0; n   if (b[0] == 0 && x != 1 || b[x] == 0 && y - x != 1 || n       b[y] == 0 && z - y != 1 || b[z] == 0 && l - z != 1) { n     return 0; n   } n   int num[4] = {get(0, x), get(x, y), get(y, z), get(z, l)}; n   for (int i = 0; i < 4; ++i) { n     if (num[i] < 0 || num[i] >= 256) { n       return 0; n     } n   } n   return 1; n } n int cntsplit(int l) { n   int res = 0; n   for (int i = 1; i < l; ++i) { n     if (i - 0 > 3) break; n     for (int j = i + 1; j < l && j <= i + 3; ++j) { n       if (j - i > 3) break; n       for (int k = j + 1; k < l && k <= j + 3; ++k) { n         if (k - j > 3) break; n         if (check(i, j, k, l)) { n           ans.push_back(getstr(i, j, k, l)); n           ++res; n         } n       } n     } n   } n   return res; n } n int cnt(int d) { n   int l = 2 * d; n   int res = 0; n   for (int i = 0; i < d; ++i) { n     b[l - i - 1] = b[i]; n   } n   res += cntsplit(l); n   --l; n   for (int i = 0; i < d - 1; ++i) { n     b[l - i - 1] = b[i]; n   } n   res += cntsplit(l); n   return res; n } n void dfs(int d, int msk) { n   if (msk == (1 << n) - 1) { n     cnt(d); n   } n   if (d >= 6) return; n   for (int i = 0; i < n; ++i) { n     b[d] = a[i]; n     dfs(d + 1, msk | (1 << i)); n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     scanf( %d , a + i); n   } n   if (n > 6) { n     puts( 0 ); n     return 0; n   } n   dfs(0, 0); n   printf( %d n , ans.size()); n   for (int i = 0; i < ans.size(); ++i) { n     printf( %s n , ans[i].c_str()); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5e3 + 9; n const int M = 5e4 + 9; n long long read() { n   long long x = 0, op = 1; n   char c = getchar(); n   while (!isdigit(c)) { n     if (c ==  - ) op = -1; n     c = getchar(); n   } n   while (isdigit(c)) x = x * 10 + c - 48, c = getchar(); n   return x * op; n } n signed main() { n   int T = read(); n   while (T--) { n     int n = read(); n     if (n & 1) n--; n     cout << n / 2 + 1 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int fx[8] = {0, -1, -1, -1, 0, 1, 1, 1}; n const int fy[8] = {1, 1, 0, -1, -1, -1, 0, 1}; n const int maxn = 310; n int vis[maxn][maxn][8][30]; n int v[maxn][maxn]; n int step[40]; n queue<pair<int, int> > q; n pair<int, int> mkstate(int x, int y, int d, int t) { n   return make_pair(x * 10000 + y, d * 10000 + t); n } n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> step[i]; n   while (!q.empty()) q.pop(); n   q.push(mkstate(155, 155, 0, 0)); n   vis[155][155][0][0] = true; n   while (!q.empty()) { n     pair<int, int> t = q.front(); n     q.pop(); n     int x = t.first / 10000; n     int y = t.first % 10000; n     int d = t.second / 10000; n     int th = t.second % 10000; n     for (int i = 0; i < step[th]; i++) { n       v[x + fx[d] * i][y + fy[d] * i] = 1; n     } n     int nx = x + fx[d] * (step[th] - 1); n     int ny = y + fy[d] * (step[th] - 1); n     int d1 = (d + 1) % 8; n     int x1 = nx + fx[d1]; n     int y1 = ny + fy[d1]; n     int d2 = (d - 1 + 8) % 8; n     int x2 = nx + fx[d2]; n     int y2 = ny + fy[d2]; n     pair<int, int> t1 = mkstate(x1, y1, d1, th + 1); n     pair<int, int> t2 = mkstate(x2, y2, d2, th + 1); n     if (th + 1 < n && !vis[x1][y1][d1][th + 1]) { n       q.push(t1); n       vis[x1][y1][d1][th + 1] = true; n     } n     if (th + 1 < n && !vis[x2][y2][d2][th + 1]) { n       q.push(t2); n       vis[x2][y2][d2][th + 1] = true; n     } n   } n   int ans = 0; n   for (int i = 0; i < maxn; i++) { n     for (int j = 0; j < maxn; j++) { n       if (v[i][j]) ans++; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void exitall() { n   cout << -1; n   exit(0); n } n int main() { n   ios::sync_with_stdio(false); n   int n; n   long long d; n   cin >> n >> d; n   vector<long long> v(n); n   for (int i = 0; i < n; ++i) { n     cin >> v[i]; n   } n   long long mx = 0; n   int ans = 0; n   int lst = -1; n   long long b = 0; n   for (int i = 0; i < n; ++i) { n     if (v[i] == 0) { n       if (lst >= 0) { n         if (b >= 0) continue; n         if (-b <= d - mx) { n           mx -= b; n           b = 0; n         } else { n           ans++; n           b = 0; n           lst = i; n           mx = 0; n         } n       } else { n         if (b < 0) { n           ans++; n           b = 0; n           mx = 0; n           lst = i; n         } n       } n     } else n       mx = max(mx, b = b + v[i]); n     if (b > d) { n       cout << -1; n       return 0; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<pair<int, int> > v; n   for (int i = (int)0; i < (int)(n); i++) { n     int second = 0; n     int a; n     for (int j = (int)0; j < (int)(4); j++) { n       cin >> a; n       second += a; n     } n     v.push_back(make_pair(-second, i)); n   } n   sort(v.begin(), v.end()); n   for (int i = (int)0; i < (int)(n); i++) n     if (v[i].second == 0) cout << i + 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[10000]; n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     cin >> s; n     bool t = 0; n     for (int i = 1; s[i]; ++i) { n       if (!isdigit(s[i]) && isdigit(s[i - 1])) { n         t = 1; n         break; n       } n     } n     if (t == 0) { n       int c = 0, j; n       for (j = 0; !isdigit(s[j]); ++j) { n         c = 26 * c + s[j] -  A  + 1; n       } n       int r = 0; n       for (; s[j]; ++j) { n         r = 10 * r + s[j] -  0 ; n       } n       cout <<  R  << r <<  C  << c << endl; n     } else { n       int r = 0; n       int j; n       for (j = 1; isdigit(s[j]); ++j) { n         r = r * 10 + s[j] -  0 ; n       } n       int c = 0; n       for (++j; s[j]; ++j) { n         c = 10 * c + s[j] -  0 ; n       } n       int z = 0; n       while (c) { n         s[z++] = c % 26 +  A  - 1; n         if (s[z - 1] <  A ) { n           s[z - 1] =  Z ; n           c = c - 26; n         } n         c = c / 26; n       } n       for (int k = z - 1; k >= 0; --k) putchar(s[k]); n       cout << r << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 5000; n vector<int> edge[MAX + 5]; n int p[MAX + 5], c[MAX + 5], lft[MAX + 5], used[MAX + 5], vis[MAX + 5], n     cp[MAX + 5], ans[MAX + 5]; n int n, m, d, mex, dfn; n bool dfs(int x) { n   for (int i = 0; i < edge[x].size(); i++) { n     int j = edge[x][i]; n     if (used[j] != dfn) { n       used[j] = dfn; n       if (cp[j] == -1 || dfs(cp[j])) { n         cp[j] = x; n         return true; n       } n     } n   } n   return false; n } n int main() { n   memset(cp, -1, sizeof(cp)); n   int i; n   scanf( %d%d , &n, &m); n   for (i = 1; i <= n; i++) scanf( %d , &p[i]); n   for (i = 1; i <= n; i++) scanf( %d , &c[i]); n   scanf( %d , &d); n   for (i = 1; i <= d; i++) { n     scanf( %d , &lft[i]); n     vis[lft[i]] = 1; n   } n   for (i = 1; i <= n; i++) { n     if (!vis[i]) edge[p[i]].push_back(c[i]); n   } n   for (i = d, mex = -1, dfn = 1; i >= 1; i--) { n     while (dfs(mex + 1)) { n       mex++; n       dfn++; n     } n     ans[i] = mex + 1; n     dfn++; n     edge[p[lft[i]]].push_back(c[lft[i]]); n   } n   for (i = 1; i <= d; i++) { n     printf( %d n , ans[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s[] = { zero ,     one ,      two ,        three ,     four , n                  five ,     six ,      seven ,      eight ,     nine , n                  ten ,      eleven ,   twelve ,     thirteen ,  fourteen , n                  fifteen ,  sixteen ,  seventeen ,  eighteen ,  nineteen }; n   string c[] = {  ,        ,       twenty ,   thirty ,  forty , n                  fifty ,  sixty ,  seventy ,  eighty ,  ninety }; n   int n; n   cin >> n; n   if (n < 20) { n     cout << s[n]; n   } else { n     if (n % 10 == 0) n       cout << c[n / 10]; n     else n       cout << c[n / 10] <<  -  << s[n % 10]; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 3e4, SQN = 3e2; n map<int, int> dst_idx, idx_dst; n int n, d, dp[MAXN + 3][SQN + 3], a[MAXN + 3], max_idx; n int fazdp(int idx, int li) { n   if (dp[idx][li] != -1) return dp[idx][li]; n   int di = idx_dst[li]; n   int ret = 0; n   for (int i = -1; i <= 1; i++) { n     int dd = di + i; n     if (dst_idx.find(dd) == dst_idx.end() || dd <= 0 || idx + dd > max_idx) n       continue; n     int iidx = idx + dd; n     ret = max(ret, fazdp(iidx, dst_idx[dd])); n   } n   return dp[idx][li] = a[idx] + ret; n } n int main() { n   for (int i = 0; i < MAXN + 3; i++) n     for (int j = 0; j < SQN + 3; j++) dp[i][j] = -1; n   scanf( %d %d , &n, &d); n   for (int i = 1; i <= n; i++) { n     int aux; n     scanf( %d , &aux); n     max_idx = max(max_idx, aux); n     a[aux]++; n   } n   int cnt = 0; n   for (int i = max(1, d - SQN); i <= min(max_idx, d + SQN); i++) { n     dst_idx[i] = cnt; n     idx_dst[cnt] = i; n     cnt++; n   } n   printf( %d , a[0] + fazdp(d, dst_idx[d])); n } n


#include <bits/stdc++.h> n using namespace std; n long long int d[400001], num[400001]; n int decr[400001], inc[400001]; n priority_queue<pair<long long int, int>, vector<pair<long long int, int> >, n                greater<pair<long long int, int> > > n     H1; n priority_queue<pair<long long int, int> > H2; n int main() { n   int i; n   int t, m; n   long long int n, k, p, o; n   scanf( %d , &t); n   while (t--) { n     scanf( %I64d %d %I64d , &n, &m, &k), o = 0; n     for (i = 0; i < m; i++) scanf( %I64d , &p), d[i] = p - o, o = p; n     d[m++] = n - o, k += m; n     long long int l = 1, r = n; n     while (l < r) { n       long long int mid = (l + r) / 2; n       long long int s = 0; n       for (i = 0; i < m; i++) s += (d[i] + mid - 1) / mid; n       if (s > k) n         l = mid + 1; n       else n         r = mid; n     } n     long long int s = 0; n     for (i = 0; i < m; i++) num[i] = (d[i] + r - 1) / r, s += num[i]; n     for (i = 0; i < m; i++) { n       if ((s < k) && ((d[i] + num[i] - 1) / num[i] == r)) { n         long long int x = (d[i] - 1) / (r - 1) - num[i] + 1; n         x = min(x, k - s); n         num[i] += x, s += x; n       } n       l = min(l, d[i] / num[i]); n     } n     long long int ans = r - l; n     for (i = 0; i < m; i++) n       H1.push(make_pair(d[i] / num[i], i)), n           H2.push(make_pair(d[i] / (num[i] + 1), i)); n     fill(decr, decr + m, 0), fill(inc, inc + m, 0); n     int tt = 10 * m; n     while (tt--) { n       while (d[H1.top().second] / num[H1.top().second] != H1.top().first) n         H1.pop(); n       while (d[H2.top().second] / (num[H2.top().second] + 1) != H2.top().first) n         H2.pop(); n       int u = H1.top().second, v = H2.top().second; n       H1.pop(), H2.pop(); n       if (u == v) break; n       num[u]--, num[v]++; n       decr[u] = 1, inc[v] = 1; n       if (decr[u] && inc[u]) break; n       if (decr[v] && inc[v]) break; n       if (num[u] == 0) break; n       r = max(r, (d[u] + num[u] - 1) / num[u]); n       H1.push(make_pair(d[u] / num[u], u)); n       if (d[u] / num[u] != d[u] / (num[u] + 1)) n         H2.push(make_pair(d[u] / (num[u] + 1), u)); n       if (d[v] / num[v] != d[v] / (num[v] - 1)) n         H1.push(make_pair(d[v] / num[v], v)); n       H2.push(make_pair(d[v] / (num[v] + 1), v)); n       while (d[H1.top().second] / num[H1.top().second] != H1.top().first) n         H1.pop(); n       ans = min(ans, r - H1.top().first); n     } n     printf( %I64d n , ans); n     while (!H1.empty()) H1.pop(); n     while (!H2.empty()) H2.pop(); n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   std::ios::sync_with_stdio(false); n   std::cin.tie(nullptr); n   int a; n   std::cin >> a; n   int d[6]; n   for (int i = 0; i < 6; ++i) d[i] = a >> i & 1; n   std::cout << (d[0] << 4 | d[1] << 1 | d[2] << 3 | d[3] << 2 | d[4] | n                 d[5] << 5) n             <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, a, b, c, d, ans1, ans2, ans3; n   cin >> t; n   while (t--) { n     ans1 = 0; n     ans2 = 0; n     ans3 = 0; n     cin >> a >> b >> c >> d; n     ans1 = a / b; n     ans2 = (c - 1) / b; n     ans3 = d / b; n     ans1 -= ans3; n     ans1 += ans2; n     cout << ans1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char a[50][50]; n int main() { n   int n, m; n   cin >> n >> m; n   for (int j = 0; j < m; j++) a[0][j] =  # ; n   for (int j = 0; j < m - 1; j++) a[1][j] =  . ; n   a[1][m - 1] =  # ; n   for (int i = 2; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (i % 2 == 0) n         a[i][j] =  # ; n       else { n         if (j == 0 && a[i - 2][0] ==  . ) n           a[i][j] =  # ; n         else if (j == m - 1 && a[i - 2][m - 1] ==  . ) n           a[i][j] =  # ; n         else n           a[i][j] =  . ; n       } n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) cout << a[i][j]; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, number; n   cin >> n; n   int arr[n + 1]; n   bool marcado[n + 1]; n   memset(marcado, 0, sizeof marcado); n   for (int i = 1; i <= n; i++) { n     cin >> number; n     if (!marcado[number] && number <= n) { n       marcado[number] = true; n       arr[i] = number; n     } else n       arr[i] = 0; n   } n   int i, j; n   for (i = 1, j = 1; i <= n; i++) { n     if (arr[i] != 0) { n       cout << arr[i] <<    ; n     } else { n       while (marcado[j]) j++; n       cout << j++ <<    ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, tmp, k, gbd; n   cin >> n; n   k = 1; n   while (k < 10) { n     tmp = pow(2, k - 1) * (pow(2, k) - 1); n     if (n % tmp == 0) gbd = tmp; n     k++; n   } n   cout << gbd; n } n


#include <bits/stdc++.h> n using namespace std; n int s, a, n; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   while (n--) cin >> a, s += abs(a); n   cout << s; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, ans = -1000001; n int main() { n   cin >> n; n   float a; n   for (int i = 1; i <= n; i++) { n     cin >> a; n     if (floor(sqrt(a)) != sqrt(a)) { n       ans = max(ans, (int)a); n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int n, i, j, s = 0, min1 = INT_MAX, min2 = INT_MIN, od = 0; n   cin >> n; n   long long int a[n + 5]; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i] >= 0) { n       if (a[i] % 2) od++, min1 = min(min1, a[i]); n       s += a[i]; n     } else { n       if (a[i] % 2) min2 = max(min2, a[i]); n     } n   } n   if (s % 2 == 0) { n     if (min1 == INT_MAX) n       cout << s + min2 <<   n ; n     else if (min2 == INT_MIN) n       cout << s - min1 <<   n ; n     else { n       long long int x = s - min1; n       long long int y = s + min2; n       cout << max(x, y) <<   n ; n     } n   } else n     cout << s <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n long long int gcd(long long int a, long long int b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n int main() { n   long long int n, x, ans, ans1, y; n   cin >> y; n   n = (long long int)sqrt((double)y); n   for (long long int i = n; i > 0; i--) { n     if (y % i == 0) { n       x = y / i; n       if (gcd(i, x) == 1) { n         ans = i; n         ans1 = x; n         break; n       } n     } n   } n   if (y != 1) n     cout << ans <<     << ans1 << endl; n   else n     cout << 1 <<     << 1 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n ostream& operator<<(ostream& os, const vector<T>& v) { n   for (T i : v) os << i <<    ; n   return os; n } n template <class T> n ostream& operator<<(ostream& os, const set<T>& v) { n   for (T i : v) os << i <<    ; n   return os; n } n template <class T, class S> n ostream& operator<<(ostream& os, const pair<T, S>& v) { n   os << v.first <<     << v.second; n   return os; n } n template <class T, class S> n ostream& operator<<(ostream& os, const unordered_map<T, S>& v) { n   for (auto i : v) os <<  (  << i.first <<  =>  << i.second <<  )  <<    ; n   return os; n } n #pragma GCC optimize( O3 ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC target(   n      avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n const long long inf = 1e18; n const long long mod = 1e9 + 7; n void fast() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n } n clock_t time_p = clock(); n void starboy1299() { n   time_p = clock() - time_p; n   cerr <<  Time Taken :   << (float)(time_p) / CLOCKS_PER_SEC <<   n ; n } n const long long N = 5e5 + 5; n void solve() { n   long long n, p; n   cin >> n >> p; n   for (long long i = 1; i <= 32; i++) { n     long long val = n - p * i; n     long long temp = __builtin_popcount(val); n     if (temp <= i and val >= i) { n       cout << i <<   n ; n       return; n     } n   } n   cout << -1 <<   n ; n } n int32_t main() { n   fast(); n   long long t = 1; n   for (long long i = 1; i <= t; i++) { n     solve(); n   } n   starboy1299(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x, k, ans = 0; n   cin >> n >> k; n   if (n < 3) { n     cout << 0; n     return 0; n   } n   for (int i = 0; i < n; ++i) { n     cin >> x; n     if (5 - x >= k) ans++; n   } n   cout << ans / 3; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int arr[4]; n   for (int i = 0; i < 4; i++) cin >> arr[i]; n   string strips; n   cin >> strips; n   int n = strips.length(); n   int cal = 0; n   for (int i = 0; i < n; i++) { n     if (strips[i] ==  1 ) n       cal += arr[0]; n     else if (strips[i] ==  2 ) n       cal += arr[1]; n     else if (strips[i] ==  3 ) n       cal += arr[2]; n     else if (strips[i] ==  4 ) n       cal += arr[3]; n   } n   cout << cal; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void Kinishinaide() { n   ios_base::sync_with_stdio(0); n   cin.tie(0), cout.tie(0); n } n const long long N = 1e2 + 7; n const long long Mod = 1e9 + 7; n const long long Inf = 1e18 + 7; n int M, L; n long long Aq[N]; n long long dp[N], Ans; n int main() { n   Kinishinaide(); n   cin >> M >> L; n   memset(dp, Inf, sizeof(dp)); n   for (int i = 0; i < M; i++) { n     cin >> Aq[i]; n     if (i) { n       dp[i] = min(Aq[i], (dp[i - 1] << 1)); n     } else { n       dp[i] = Aq[i]; n     } n   } n   long long Sum = false, Ans = Inf; n   for (int i = M - 1; i >= 0; i--) { n     Sum += 1LL * (L / (1 << i)) * dp[i]; n     L = L % (1 << i); n     Ans = min(Ans, Sum + 1LL * (L > 0) * dp[i]); n   } n   cout << Ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int dx[] = {1, 0, -1, 0}; n const int dy[] = {0, -1, 0, 1}; n const double EPS = 1e-9; n const int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; n const int daysleap[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; n int main() { n   int n, k; n   cin >> n >> k; n   vector<int> A(n); n   for (unsigned int i = 0; i < (n); i++) cin >> A[i]; n   sort(A.begin(), A.end()); n   vector<int> B = A; n   unique(B.begin(), B.end()); n   reverse(B.begin(), B.end()); n   vector<int> C = B; n   for (unsigned int i = 0; i < (B.size()); i++) { n     C[i] = count(A.begin(), A.end(), B[i]); n   } n   int kk = 0; n   for (unsigned int i = 0; i < (B.size()); i++) { n     kk += C[i]; n     if (kk == k) { n       cout << B[i] <<     << B[i] << endl; n       return 0; n     } n   } n   cout << -1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long power(long long a, long long b) { n   long long x = 1, y = a; n   while (b > 0) { n     if (b % 2) { n       x = (x * y) % 1000000007; n     } n     y = (y * y) % 1000000007; n     b /= 2; n   } n   return x % 1000000007; n } n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   long long int t = 1, n, m, i, j, k, sum = 0; n   while (t--) { n     cin >> n; n     vector<long long int> v(n); n     for (i = 0; i < n; i++) cin >> v[i]; n     sort((v).begin(), (v).end()); n     for (i = 1; i < n; i++) { n       v[i] += v[i - 1]; n     } n     for (i = 1; i < n; i++) { n       sum = (sum + (power(2, i - 1) * n                     ((v[n - 1] - v[i - 1] - v[n - i - 1]) % 1000000007)) % n                        1000000007) % n             1000000007; n       sum = sum % 1000000007; n     } n     cout << sum; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( -O3 ) n using namespace std; n const long long N = 1e6 + 5; n const long long MAX = 1e7 + 9; n long long binarySearch(long long arr[], long long l, long long r, long long x) { n   if (r >= l) { n     long long mid = l + (r - l) / 2; n     if (arr[mid] == x) return mid; n     if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x); n     return binarySearch(arr, mid + 1, r, x); n   } n   return -1; n } n void pairsort(long long a[], long long b[], long long n) { n   pair<long long, long long> pairt[n]; n   for (long long i = 0; i < n; i++) { n     pairt[i].first = a[i]; n     pairt[i].second = b[i]; n   } n   sort(pairt, pairt + n); n   for (long long i = 0; i < n; i++) { n     a[i] = pairt[i].first; n     b[i] = pairt[i].second; n   } n } n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long isprime(long long n) { n   if (n < 2) return 0; n   if (n < 4) return 1; n   if (n % 2 == 0 or n % 3 == 0) return 0; n   for (long long i = 5; i * i <= n; i += 6) n     if (n % i == 0 or n % (i + 2) == 0) return 0; n   return 1; n } n long long C(long long n, long long r) { n   if (r > n - r) r = n - r; n   long long ans = 1; n   for (long long i = 1; i <= r; i++) { n     ans *= n - r + i; n     ans /= i; n   } n   return ans; n } n long long mod = 1e9 + 7; n long long modexpo(long long x, long long p) { n   long long res = 1; n   x = x % mod; n   while (p) { n     if (p % 2) res = res * x; n     p >>= 1; n     x = x * x % mod; n     res %= mod; n   } n   return res; n } n long long countDistinct(long long arr[], long long n) { n   sort(arr, arr + n); n   long long res = 0; n   for (long long i = 0; i < n; i++) { n     while (i < n - 1 && arr[i] == arr[i + 1]) i++; n     res++; n   } n   return res; n } n long long int2Bin(string s) { n   reverse(s.begin(), s.end()); n   long long b = 1; n   long long x = 0; n   for (long long i = 0; i < s.length(); ++i) { n     if (s[i] ==  1 ) x += b; n     b *= 2; n     ; n   } n   return x; n } n long long getSum(long long n) { n   long long sum; n   for (sum = 0; n > 0; sum += n % 10, n /= 10) n     ; n   return sum; n } n long long nex(long long i) { return (i / 10 + 1) * 10 - i; } n bool up[N]; n long long a[N], ind, leave[11]; n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     pair<long long, long long> a[n]; n     long long i; n     for (i = 0; i < n; i++) { n       long long x; n       cin >> x; n       a[i].first = x; n       a[i].second = i; n     } n     sort(a, a + n); n     long long ans = 2 * n; n     for (i = 1; i < n; i++) { n       if (a[i].first == a[i - 1].first) n         ans = min(ans, a[i].second - a[i - 1].second + 1); n     } n     if (ans == 2 * n) n       cout <<  -1 n ; n     else n       cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e6 + 5; n int n; n char str[N]; n vector<int> g[N]; n inline void init() { n   scanf( %d , &n); n   for (int i = 1, u, v; i < n; i++) { n     scanf( %d%d , &u, &v); n     g[u].push_back(v); n     g[v].push_back(u); n   } n   scanf( %s , str + 1); n   for (int i = 1; i <= n; i++) { n     if (str[i] ==  W ) { n       g[i].push_back(++n); n       g[n].push_back(i); n       g[n].push_back(n + 1); n       g[n + 1].push_back(n); n       g[n].push_back(n + 2); n       g[n + 2].push_back(n); n       n = n + 2; n     } n   } n } n int dfs(int p, int fa, int dest) { n   if (p == dest) { n     return 1; n   } n   for (auto e : g[p]) { n     if (e ^ fa) { n       int ret = dfs(e, p, dest); n       if (~ret) { n         return ret ^ 1; n       } n     } n   } n   return -1; n } n vector<int> d3; n inline void solve() { n   d3.clear(); n   for (int i = 1; i <= n; i++) { n     if (g[i].size() >= 4) { n       puts( White ); n       return; n     } n     if (g[i].size() == 3) { n       d3.push_back(i); n       int _cnt = 0; n       for (auto e : g[i]) { n         if (g[e].size() >= 2) { n           _cnt++; n         } n       } n       if (_cnt >= 2) { n         puts( White ); n         return; n       } n     } n   } n   if (d3.size() >= 3) { n     puts( White ); n     return; n   } n   if (d3.size() == 2) { n     puts((dfs(d3[0], 0, d3[1])) ? ( White ) : ( Draw )); n   } else { n     puts( Draw ); n   } n } n inline void clear() { n   for (int i = 1; i <= n; i++) { n     g[i].clear(); n   } n } n int T; n int main() { n   scanf( %d , &T); n   while (T--) { n     init(); n     solve(); n     clear(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1e9 + 7; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   int test = 1; n   cin >> test; n   while (test--) { n     string s; n     cin >> s; n     int a = -1, b = -1, c = -1; n     int ans = s.size(); n     for (int i = 0; i < s.size(); i++) { n       if (s[i] ==  1 ) n         a = i; n       else if (s[i] ==  2 ) n         b = i; n       else n         c = i; n       if (a != -1 && b != -1 && c != -1) { n         int x = min(a, min(b, c)); n         int y = max(a, max(b, c)); n         ans = min(ans, y - x + 1); n       } n     } n     if (a != -1 && b != -1 && c != -1) n       cout << ans <<   n ; n     else n       cout << 0 <<   n ; n   } n   return 0; n } n