#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 10; n int a[maxn]; n set<int> S; n long long qpow(long long a, long long b, long long mod) { n   long long ret = 1LL; n   while (b) { n     if (b & 1) ret = ret * a % mod; n     a = a * a % mod; n     b >>= 1; n   } n   return ret; n } n long long inv(long long x, long long mod) { return qpow(x, mod - 2, mod); } n int main(void) { n   int n, m; n   scanf( %d %d , &m, &n); n   if (n + n < m) { n     for (int i = 1; i <= n; i++) scanf( %d , a + i), S.insert(a[i]); n     if (n == 1) { n       printf( %d 0 n , a[1]); n       return 0; n     } n     int kd = (a[2] - a[1] + m) % m; n     int cnt = 0; n     for (int i = 1; i <= n; i++) { n       int nxt = (a[i] + kd) % m; n       if (S.find(nxt) != S.end()) cnt++; n     } n     int k = n - cnt; n     if (!k) { n       printf( %d %d n , a[1], kd); n       return 0; n     } n     int d = (long long)kd * inv(k, m) % m; n     cnt = 0; n     for (int i = 0; i < n; i++) n       if (S.find((a[1] - (long long)i * d % m + m) % m) != S.end()) cnt++; n     if (cnt == n) { n       printf( %I64d %d n , (a[1] - (long long)(n - 1) * d % m + m) % m, d); n       return 0; n     } n     for (int i = 1; i < n; i++) { n       if (S.find((a[1] + (long long)(i - n) * d % m + m) % m) != S.end()) cnt--; n       if (S.find((a[1] + (long long)i * d % m + m) % m) != S.end()) cnt++; n       if (cnt == n) { n         printf( %I64d %d n , (a[1] + (long long)(i - n + 1) * d % m + m) % m, n                d); n         return 0; n       } n     } n     puts( -1 ); n   } else { n     for (int i = 0; i < m; i++) S.insert(i); n     for (int i = 1; i <= n; i++) scanf( %d , a + i), S.erase(a[i]); n     n = m - n; n     set<int>::iterator it = S.begin(); n     for (int i = 1; i <= n; i++) a[i] = *(it++); n     if (n == 0) { n       printf( 0 1 n ); n       return 0; n     } n     if (n == 1) { n       printf( %d 1 n , (a[1] + n) % m); n       return 0; n     } n     int kd = (a[2] - a[1] + m) % m; n     int cnt = 0; n     for (int i = 1; i <= n; i++) { n       int nxt = (a[i] + kd) % m; n       if (S.find(nxt) != S.end()) cnt++; n     } n     int k = n - cnt; n     if (!k) { n       printf( %d %d n , (a[1] + (long long)n * kd) % m, kd); n       return 0; n     } n     int d = (long long)kd * inv(k, m) % m; n     cnt = 0; n     for (int i = 0; i < n; i++) n       if (S.find((a[1] - (long long)i * d % m + m) % m) != S.end()) cnt++; n     if (cnt == n) { n       printf( %I64d %d n , n              (a[1] - (long long)(n - 1) * d % m + m + (long long)n * d) % m, d); n       return 0; n     } n     for (int i = 1; i < n; i++) { n       if (S.find((a[1] + (long long)(i - n) * d % m + m) % m) != S.end()) cnt--; n       if (S.find((a[1] + (long long)i * d % m + m) % m) != S.end()) cnt++; n       if (cnt == n) { n         printf( n              %I64d %d n , n             (a[1] + (long long)(i - n + 1) * d % m + m + (long long)n * d) % m, n             d); n         return 0; n       } n     } n     puts( -1 ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x, y, z; n   cin >> x >> y >> z; n   int t = x * y / z; n   t = (int)sqrt(t); n   x = x / t; n   z = y / t; n   y = t; n   cout << 4 * x + 4 * z + 4 * y <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e17; n const long long MOD = 1000000007; n const long long MAX = 4000001; n const long double eps = 1E-14; n long long max(long long a, long long b) { n   if (a > b) { n     return a; n   } n   return b; n } n long long min(long long a, long long b) { n   if (a > b) { n     return b; n   } n   return a; n } n long long gcd(long long a, long long b) { n   if (b == 0) { n     return a; n   } n   if (a < b) { n     return gcd(b, a); n   } n   return gcd(b, a % b); n } n long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n struct edge { n   long long ind; n   long long fr; n   long long to; n   long long d; n }; n class mint { n   long long x; n  n  public: n   mint(long long x = 0) : x((x % MOD + MOD) % MOD) {} n   mint operator-() const { return mint(-x); } n   mint& operator+=(const mint& a) { n     if ((x += a.x) >= MOD) x -= MOD; n     return *this; n   } n   mint& operator-=(const mint& a) { n     if ((x += MOD - a.x) >= MOD) x -= MOD; n     return *this; n   } n   mint& operator*=(const mint& a) { n     (x *= a.x) %= MOD; n     return *this; n   } n   mint operator+(const mint& a) const { n     mint res(*this); n     return res += a; n   } n   mint operator-(const mint& a) const { n     mint res(*this); n     return res -= a; n   } n   mint operator*(const mint& a) const { n     mint res(*this); n     return res *= a; n   } n   mint pow(long long t) const { n     if (!t) return 1; n     mint a = pow(t >> 1); n     a *= a; n     if (t & 1) a *= *this; n     return a; n   } n   mint inv() const { return pow(MOD - 2); } n   mint& operator/=(const mint& a) { return (*this) *= a.inv(); } n   mint operator/(const mint& a) const { n     mint res(*this); n     return res /= a; n   } n   friend ostream& operator<<(ostream& os, const mint& m) { n     os << m.x; n     return os; n   } n }; n mint pw(mint a, long long b) { n   if (b == 0) { n     return 1; n   } n   mint ret = pw(a, b >> 1); n   ret *= ret; n   if (b & 1) { n     ret *= a; n   } n   return ret; n } n int main() { n   long long T; n   cin >> T; n   for (long long t = 1; t <= T; t++) { n     long long N; n     cin >> N; n     vector<long long> a(N + 1); n     for (long long i = 1; i <= N; i++) cin >> a[i]; n     long long S = 0; n     for (long long i = 1; i <= N; i++) S += a[i]; n     if (S % N != 0) { n       cout << -1 << endl; n     } else { n       S = S / N; n       vector<pair<long long, long long>> rem; n       for (long long i = 2; i <= N; i++) { n         long long x = 0; n         if (a[i] % i != 0) { n           x = i - a[i] % i; n         } n         rem.push_back({x, i}); n       } n       sort(rem.begin(), rem.end()); n       vector<pair<pair<long long, long long>, long long>> ans; n       for (long long k = 0; k < N - 1; k++) { n         auto p = rem[k]; n         if (p.first > a[1]) { n           break; n         } n         ans.push_back({{1, p.second}, p.first}); n         a[1] -= p.first; n         a[p.second] += p.first; n         ans.push_back({{p.second, 1}, a[p.second] / p.second}); n         a[1] += a[p.second]; n         a[p.second] = 0; n       } n       for (long long i = 2; i <= N; i++) { n         if (a[i] == 0) { n           continue; n         } n         ans.push_back({{i, 1}, a[i] / i}); n         a[1] += a[i] / i * i; n         a[i] %= i; n       } n       bool b = 1; n       for (long long i = 2; i <= N; i++) { n         if (a[i] > S) { n           cout << -1 << endl; n           b = 0; n           break; n         } n         ans.push_back({{1, i}, S - a[i]}); n       } n       if (b) { n         cout << ans.size() << endl; n         for (auto p : ans) { n           cout << p.first.first <<     << p.first.second <<     << p.second n                << endl; n         } n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   map<char, long long> mp1, mp2; n   mp1[ v ] = 1; n   mp1[ < ] = 2; n   mp1[ ^ ] = 3; n   mp1[ > ] = 4; n   mp2[ v ] = 1; n   mp2[ > ] = 2; n   mp2[ ^ ] = 3; n   mp2[ < ] = 4; n   char a, b; n   long long n; n   cin >> a >> b; n   cin >> n; n   n = n % 4; n   long long one, two; n   one = (mp1[a] + n) % 4; n   if (one == 0) one = 4; n   two = (mp2[a] + n) % 4; n   if (two == 0) two = 4; n   long long f1 = 0, f2 = 0; n   if (one == mp1[b]) f1 = 1; n   if (two == mp2[b]) f2 = 1; n   if (f1 == 1 && f2 == 0) { n     cout <<  cw  << endl; n     return 0; n   } else if (f1 == 0 && f2 == 1) { n     cout <<  ccw  << endl; n     return 0; n   } n   cout <<  undefined  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 2e5 + 10; n int inf = (int)3e15; n int mod = (int)1e9 + 7; n int sz = 500, timer = 0; n vector<int> gr[MAX]; n int n, q, odd[MAX], even[MAX], h[MAX], tin[MAX], tout[MAX], mus[MAX], o[MAX]; n vector<pair<int, int>> tmp; n void calc(int v, int p) { n   tin[v] = ++timer; n   h[v] = h[p] + 1; n   for (auto u : gr[v]) { n     if (u != p) calc(u, v); n   } n   tout[v] = ++timer; n } n void dfs_rebuild(int v, int p) { n   odd[v] += even[p]; n   even[v] += odd[p]; n   for (auto u : gr[v]) { n     if (u != p) dfs_rebuild(u, v); n   } n } n void rebuild() { n   for (int i = 1; i <= n; i++) { n     even[i] = 0; n     odd[i] = 0; n   } n   for (int i = 0; i < tmp.size(); i++) mus[tmp[i].first] += tmp[i].second; n   for (int i = 1; i <= n; i++) even[i] = mus[i]; n   tmp.clear(); n   dfs_rebuild(1, 0); n } n void out_val(int v) { n   int ans = even[v] - odd[v] + o[v]; n   for (int i = 0; i < tmp.size(); i++) { n     int u = tmp[i].first; n     int val = tmp[i].second; n     if (tin[u] <= tin[v] && tout[u] >= tout[v]) { n       if ((h[v] - h[u]) % 2 == 1) n         ans -= val; n       else n         ans += val; n     } n   } n   cout << ans <<   n ; n } n void solve() { n   cin >> n >> q; n   for (int i = 1; i <= n; i++) { n     cin >> o[i]; n   } n   for (int i = 0; i < n - 1; i++) { n     int a, b; n     cin >> a >> b; n     gr[a].push_back(b); n     gr[b].push_back(a); n   } n   calc(1, 0); n   for (int i = 0; i < q; i++) { n     int a; n     cin >> a; n     if (a == 1) { n       int b, c; n       cin >> b >> c; n       tmp.push_back({b, c}); n       if (tmp.size() == 2000) rebuild(); n     } else { n       int c; n       cin >> c; n       out_val(c); n     } n   } n } n int main() { n   ios::sync_with_stdio(0); n   int q; n   q = 1; n   while (q--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T1, typename T2> n istream &operator>>(istream &is, vector<pair<T1, T2>> &v) { n   for (pair<T1, T2> &t : v) is >> t.first >> t.second; n   return is; n } n template <typename T> n istream &operator>>(istream &is, vector<T> &v) { n   for (T &t : v) is >> t; n   return is; n } n template <typename T> n ostream &operator<<(ostream &os, const vector<T> &v) { n   for (const T &t : v) { n     os << t <<    ; n   } n   os <<   n ; n   return os; n } n double pi = acos(-1.0); n long long md = 1000000007; n long long abst(long long a) { return a < 0 ? -a : a; } n struct HASH { n   size_t operator()(const pair<long long, long long> &x) const { n     return (size_t)x.first * 37U + (size_t)x.second; n   } n }; n struct custom_hash { n   static uint64_t splitmix64(uint64_t x) { n     x += 0x9e3779b97f4a7c15; n     x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; n     x = (x ^ (x >> 27)) * 0x94d049bb133111eb; n     return x ^ (x >> 31); n   } n   size_t operator()(uint64_t x) const { n     static const uint64_t FIXED_RANDOM = n         chrono::steady_clock::now().time_since_epoch().count(); n     return splitmix64(x + FIXED_RANDOM); n   } n }; n long long Pow(long long n, long long x) { n   long long ans = 1; n   while (x > 0) { n     if (x & 1) ans = (ans * n) % md; n     n = (n * n) % md; n     x = x >> 1; n   } n   return ans; n } n vector<long long> fact, inv; n void inverse(long long n) { n   inv.resize(n + 1); n   inv[0] = 1; n   for (long long i = 1; i <= n; i++) inv[i] = Pow(fact[i], md - 2); n } n void factorial(long long n) { n   fact.resize(n + 1); n   fact[0] = 1; n   for (long long i = 1; i <= n; i++) fact[i] = (fact[i - 1] * i) % md; n } n long long max(long long a, long long b) { return a > b ? a : b; } n long long min(long long a, long long b) { return a < b ? a : b; } n void solve() { n   long long n; n   cin >> n; n   vector<long long> v(n); n   cin >> v; n   vector<long long> ans(2 * n); n   vector<long long> vis(2 * n + 1, -1); n   for (long long i = 0; i < n; i++) { n     ans[2 * i] = v[i]; n     vis[v[i]] = 1; n   } n   long long ptr; n   for (long long i = 1; i < 2 * n; i += 2) { n     ptr = -1; n     for (long long j = 1; j <= 2 * n; j++) n       if (vis[j] == -1 && j > ans[i - 1]) { n         ptr = j; n         break; n       } n     if (ptr == -1) { n       cout << -1 <<   n ; n       return; n     } n     ans[i] = ptr; n     vis[ptr] = 1; n   } n   cout << ans; n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t = 1; n   cin >> t; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long int; n const int N = 2e5 + 10; n int n, k, a[N], b[N], idx[N], kp = -1; n char lc =  a  - 1, res[N]; n int main() { n   ios_base::sync_with_stdio(false), cout.tie(nullptr), cin.tie(nullptr); n   cin >> n >> k; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     idx[a[i]] = i; n   } n   for (int i = 0; i < n; i++) { n     cin >> b[i]; n   } n   for (int i = 0; i < n; i++) { n     if (kp < i && k > 0) { n       lc++; n       k--; n     } n     res[b[i]] = lc; n     kp = max(kp, idx[b[i]]); n   } n   if (k == 0) { n     cout <<  YES n  << (res + 1); n   } else { n     cout <<  NO n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int k, n, root, par[100005]; n vector<int> v[100005]; n bool vis[100005], fr; n void findroot(int u, int l) { n   int i; n   if (v[u].size() == 1 && l == 2 * k) { n     fr = true; n     root = u; n   } n   for (i = 0; i < v[u].size(); i++) { n     if (fr) break; n     if (!vis[v[u][i]]) { n       vis[v[u][i]] = true; n       par[v[u][i]] = u; n       findroot(v[u][i], l + 1); n     } n   } n } n void dfs(int u, int l) { n   int i; n   if (v[u].size() == 1 && l != k) fr = true; n   if (u != root && l != k && v[u].size() < 4) fr = true; n   for (i = 0; i < v[u].size(); i++) { n     if (fr) break; n     if (!vis[v[u][i]]) { n       vis[v[u][i]] = true; n       dfs(v[u][i], l + 1); n     } n   } n } n int main() { n   int i, x, y, leaf, cnt = 0; n   cin >> n >> k; n   for (i = 0; i < n - 1; i++) { n     cin >> x >> y; n     v[x].push_back(y); n     v[y].push_back(x); n   } n   if (n == 1) { n     cout <<  No n ; n     return 0; n   } n   for (i = 1; i <= n; i++) n     if (v[i].size() == 1) { n       leaf = i; n       break; n     } n   memset(vis, false, sizeof(vis)); n   vis[leaf] = true; n   fr = false; n   findroot(leaf, 0); n   if (!fr) { n     cout <<  No n ; n     return 0; n   } n   while (cnt != k) { n     root = par[root]; n     cnt++; n   } n   if (v[root].size() < 3) { n     cout <<  No n ; n     return 0; n   } n   memset(vis, false, sizeof(vis)); n   vis[root] = true; n   fr = false; n   dfs(root, 0); n   if (fr) { n     cout <<  No n ; n   } else n     cout <<  Yes n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct T { n   int lz, sz; n   int v[2], t[2], f1[2], f2[2]; n   T(int x = 1) { n     lz = 0, sz = x; n     for (int i = 0; i < 2; i++) { n       v[i] = f1[i] = x; n       t[i] = f2[i] = 0; n     } n   } n   void upd() { n     for (int i = 0; i < 2; i++) t[i] ^= 1; n     swap(v[0], v[1]); n     lz ^= 1; n   } n   friend T operator+(T l, T r) { n     T ret(0); n     T c[2] = {l, r}; n     int first = 0, g = 0; n     for (int i = 0; i < 2; i++) ret.v[i] = 0; n     for (int i = 0; i < 2; i++) { n       first += c[i].f1[!i]; n       g ^= c[i].t[!i]; n       ret.sz += c[i].sz; n       ret.t[i] = c[i].t[i]; n       if (c[i].f1[i] == c[i].sz) { n         if (c[i].t[i] == c[!i].t[i]) { n           ret.f1[i] = c[i].f1[i] + c[!i].f1[i]; n           ret.f2[i] = c[!i].f2[i]; n         } else { n           ret.f1[i] = c[i].f1[i]; n           ret.f2[i] = c[!i].f1[i]; n         } n       } else { n         ret.f1[i] = c[i].f1[i]; n         ret.f2[i] = c[i].f2[i]; n         ret.f2[i] += n             (ret.f1[i] + ret.f2[i] == c[i].sz && c[i].t[i] != c[!i].t[i]) * n             c[!i].f1[i]; n       } n       for (int j = 0; j < 2; j++) n         ret.v[j] = max({ret.v[j], ret.f1[i], ret.f2[i], c[i].v[j]}); n     } n     if (g) { n       ret.v[c[0].t[1]] = max(ret.v[c[0].t[1]], first); n     } else { n       for (int i = 0; i < 2; i++) { n         int j = !i ^ c[i].t[!i]; n         ret.v[j] = max(ret.v[j], first + c[i].f2[!i]); n       } n     } n     return ret; n   } n }; n struct segTree { n   int l, r; n   segTree *c[2]; n   T val; n   segTree(int a, int b) { n     l = a, r = b; n     val.sz = r - l + 1; n     if (l != r) { n       int mid = (l + r) / 2; n       c[0] = new segTree(l, mid); n       c[1] = new segTree(mid + 1, r); n       val = c[0]->val + c[1]->val; n     } n   } n   T add(int a, int b) { n     if (b < l || r < a) return T(0); n     if (a <= l && r <= b) { n       val.upd(); n       return val; n     } n     T ret[2]; n     for (int i = 0; i < 2; i++) { n       if (val.lz) c[i]->val.upd(); n       ret[i] = c[i]->add(a, b); n     } n     val = c[0]->val + c[1]->val; n     return ret[0] + ret[1]; n   } n }; n const int mxn = 500000; n int n, q; n segTree tre(1, mxn); n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> q; n   for (int i = 1; i <= n; i++) { n     char c; n     cin >> c; n     if (c ==  < ) tre.add(i, i); n   } n   while (q--) { n     int l, r; n     cin >> l >> r; n     cout << tre.add(l, r).v[0] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, M, Q, Sum, op[100005], X[100005], Y[100005], Ans[100005], Mp[1005][1005], n     Lh[1005], Ln[1005]; n int lnk[100005], nxt[100005], son[100005], tot; n bool vis[100005], Num[1005]; n inline int read() { n   int N = 0; n   char ch = getchar(); n   while (ch >  9  || ch <  0 ) ch = getchar(); n   while (ch >=  0  && ch <=  9 ) N = N * 10 + ch -  0 , ch = getchar(); n   return N; n } n inline void add(int x, int y) { n   son[++tot] = y; n   nxt[tot] = lnk[x]; n   lnk[x] = tot; n } n inline void fz(int x) { n   Sum += Ln[X[x]] - Lh[X[x]]; n   Num[X[x]] ^= 1; n   swap(Ln[X[x]], Lh[X[x]]); n } n inline void work(int x) { n   if (op[x] == 1 && !(Mp[X[x]][Y[x]] ^ Num[X[x]])) n     Mp[X[x]][Y[x]] ^= 1, Lh[X[x]]++, Ln[X[x]]--, Sum++, vis[x] = 1; n   if (op[x] == 2 && Mp[X[x]][Y[x]] ^ Num[X[x]]) n     Mp[X[x]][Y[x]] ^= 1, Lh[X[x]]--, Ln[X[x]]++, Sum--, vis[x] = 1; n   if (op[x] == 3) fz(x); n } n inline void rework(int x) { n   if (op[x] == 1 && vis[x]) Mp[X[x]][Y[x]] ^= 1, Lh[X[x]]--, Ln[X[x]]++, Sum--; n   if (op[x] == 2 && vis[x]) Mp[X[x]][Y[x]] ^= 1, Lh[X[x]]++, Ln[X[x]]--, Sum++; n   if (op[x] == 3) fz(x); n } n void DFS(int x) { n   work(x); n   Ans[x] = Sum; n   for (int i = lnk[x]; i; i = nxt[i]) DFS(son[i]); n   rework(x); n } n int main() { n   N = read(); n   M = read(); n   Q = read(); n   for (int i = 1; i <= Q; i++) { n     op[i] = read(); n     X[i] = read(); n     if (op[i] <= 2) Y[i] = read(); n     if (op[i] == 4) n       add(X[i], i); n     else n       add(i - 1, i); n   } n   for (int i = 1; i <= N; i++) Ln[i] = M; n   DFS(0); n   for (int i = 1; i <= Q; i++) printf( %d n , Ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int K; n long long p[21], a[21], aLeft[21]; n long long N, Nq3; n long long minArea = 3000000000000000000LL; n long long ansA, ansB, ansC; n long long curA; n long long leftMul[21]; n long long BCq, BC, nowBest; n void dfs2(int cur, long long carry) { n   if (carry * leftMul[cur] < BCq) return; n   if (carry > nowBest) return; n   if (carry >= BCq) { n     nowBest = carry; n     return; n   } n   if (cur == K + 1) return; n   dfs2(cur + 1, carry); n   for (int i = 1; i <= aLeft[cur]; i++) { n     carry *= p[cur]; n     dfs2(cur + 1, carry); n   } n } n void calc(long long _curA) { n   nowBest = 3000000000000000000LL; n   curA = _curA; n   BC = N / curA; n   double each = sqrt(double(BC)); n   if (curA * 2 * each + BC > minArea + 10) return; n   leftMul[K + 1] = 1; n   for (int i = K; i >= 1; i--) { n     leftMul[i] = leftMul[i + 1]; n     for (int j = 1; j <= aLeft[i]; j++) leftMul[i] *= p[i]; n   } n   BCq = sqrt(double(BC - 1)); n   while (BCq * BCq < BC) BCq++; n   dfs2(1, 1); n   long long curB = nowBest, curC = BC / curB; n   if (curA * (curB + curC) + BC < minArea) { n     minArea = curA * (curB + curC) + BC; n     ansA = curA; n     ansB = curB; n     ansC = curC; n   } n } n void dfs(int cur, long long carry) { n   if (cur == K + 1) n     calc(carry); n   else { n     aLeft[cur] = a[cur]; n     dfs(cur + 1, carry); n     for (int i = 1; i <= a[cur]; i++) { n       carry *= p[cur]; n       if (carry > Nq3) return; n       aLeft[cur] = a[cur] - i; n       dfs(cur + 1, carry); n     } n   } n } n void solve() { n   minArea = 3000000000000000000LL; n   for (int iteration = 1; iteration <= K; iteration++) n     for (int i = 1; i < K; i++) n       if (p[i] < p[i + 1]) { n         swap(p[i], p[i + 1]); n         swap(a[i], a[i + 1]); n       } n   N = 1; n   for (int i = 1; i <= K; i++) n     for (int j = 1; j <= a[i]; j++) N *= p[i]; n   Nq3 = pow(double(N - 1), 1 / 3.0); n   while (Nq3 * Nq3 * Nq3 < N) Nq3++; n   dfs(1, 1); n   cout << 2 * minArea <<     << ansA <<     << ansB <<     << ansC << endl; n } n int main() { n   ios ::sync_with_stdio(false); n   int TestCase; n   cin >> TestCase; n   for (int CaseID = 1; CaseID <= TestCase; CaseID++) { n     cin >> K; n     for (int i = 1; i <= K; i++) cin >> p[i] >> a[i]; n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<int, string> > vc[100010]; n vector<string> vc1[100010]; n bool comp(pair<int, string> a, pair<int, string> b) { n   return a.first > b.first; n } n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     string s; n     int a, b; n     cin >> s >> a >> b; n     vc[a].push_back(make_pair(b, s)); n   } n   for (int i = 1; i <= m; i++) { n     sort(vc[i].begin(), vc[i].end(), comp); n   } n   for (int i = 1; i <= m; i++) { n     if (vc[i].size() == 2) { n       for (int j = 0; j < vc[i].size(); j++) { n         vc1[i].push_back(vc[i][j].second); n       } n     } else if (vc[i].size() == 1) { n       for (int j = 0; j < vc[i].size(); j++) { n         vc1[i].push_back(vc[i][j].second); n       } n     } else if (vc[i].size() > 2) { n       if (vc[i][1].first == vc[i][2].first) { n         vc1[i].push_back( ? ); n       } else { n         for (int j = 0; j < 2; j++) { n           vc1[i].push_back(vc[i][j].second); n         } n       } n     } n   } n   for (int i = 1; i <= m; i++) { n     for (int j = 0; j < vc1[i].size(); j++) { n       cout << vc1[i][j]; n       if (j < vc1[i].size() - 1) cout <<    ; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long int maxn = 1e6 + 1; n const long long int modn = 1e9 + 7; n long long int T, len, num, gav, ver, x, maxi, sum, fir, sec, out, th; n vector<long long int> vec[maxn]; n bool is_use[maxn]; n long long int all[maxn]; n void dfs(long long int x) { n   is_use[x] = true; n   sum++; n   for (int i = 0; i < vec[x].size(); i++) { n     ver = vec[x][i]; n     if (is_use[ver] == false) dfs(ver); n   } n   return; n } n int main() { n   std::ios_base::sync_with_stdio(false); n   cin >> len >> num >> gav; n   for (int i = 1; i <= gav; i++) cin >> all[i]; n   for (int i = 1; i <= num; i++) { n     cin >> fir >> sec; n     vec[fir].push_back(sec); n     vec[sec].push_back(fir); n   } n   for (int i = 1; i <= gav; i++) { n     sum = 0; n     dfs(all[i]); n     out += (sum * (sum - 1)) / 2; n     maxi = max(maxi, sum); n   } n   sum = 0; n   for (int i = 1; i <= len; i++) { n     if (is_use[i] == false) sum++; n   } n   out += (sum * (sum - 1)) / 2 + sum * maxi; n   cout << out - num; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, x = 0, y = 0; n   cin >> n >> m; n   x = max(m, n); n   for (int a = 0; a <= x; a++) { n     for (int b = 0; b <= x; b++) { n       if ((a * a) + b == n && (b * b) + a == m) { n         y++; n       } n     } n   } n   cout << y << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long POW(long long a, long long b) { n   if (b == 0) return 1; n   if (b == 1) return a; n   if (b & 1) return (a * POW(a, b - 1)) % 1000000007; n   long long t = POW(a, b / 2); n   return (t * t) % 1000000007; n } n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n int dx[] = {0, -1, 1, 0}, dy[] = {1, 0, 0, -1}; n int ddx[] = {0, 0, 1, 1, 1, -1, -1, -1}, ddy[] = {1, -1, 1, 0, -1, 1, 0, -1}; n map<int, int> M; n map<int, int>::iterator it, it2; n int main() { n   int n, q; n   scanf( %d%d , &n, &q); n   M[0] = 0; n   M[1000000007] = 1000000007; n   M[1] = n; n   int ans = n; n   while (q--) { n     int l, r, k; n     scanf( %d%d%d , &l, &r, &k); n     if (k == 1) { n       it = M.upper_bound(r); n       it--; n       while (it != M.begin()) { n         it2 = it; n         it--; n         int L = it2->first, R = it2->second; n         if (l <= R) { n           M.erase(it2); n           ans -= R - L + 1; n         } n         if (L <= r && R > r) { n           M[r + 1] = R; n           ans += R - r; n         } n         if (L < l && R >= l) { n           M[L] = l - 1; n           ans += l - L; n         } n         if (L <= l) break; n       } n     } else { n       it = M.upper_bound(r); n       it--; n       int L = 1000000007, R = -1; n       while (it != M.begin()) { n         it2 = it; n         it--; n         if (it2->second < l) break; n         L = min(L, it2->first), R = max(R, it2->second); n         ans -= it2->second - it2->first + 1; n         M.erase(it2); n       } n       M[min(l, L)] = max(r, R); n       ans += max(r, R) - min(l, L) + 1; n     } n     printf( %d n , ans); n   } n } n


#include <bits/stdc++.h> n #pragma GCC optimize  O3,no-stack-protector  n using namespace std; n const int MAXN = 1e5 + 7; n vector<int> G[MAXN]; n bool blo[MAXN]; n short odw[MAXN]; n bool tried[MAXN]; n int n, m; n bool dfs(int v) { n   if (blo[v] == true) return false; n   odw[v] = 1; n   for (auto w : G[v]) { n     if (odw[w] == 0) { n       if (dfs(w)) return true; n     } else if (odw[w] == 1) { n       for (int i = 1; i <= n; i++) { n         if (odw[i] != 1) tried[i] = true; n       } n       return true; n     } n   } n   odw[v] = 2; n   return false; n } n bool check() { n   for (int i = 1; i <= n; i++) { n     odw[i] = 0; n   } n   for (int i = 1; i <= n; i++) { n     if (!odw[i]) { n       if (dfs(i)) return false; n     } n   } n   return true; n } n inline double elapsed() { return clock() / (double)CLOCKS_PER_SEC; } n int main(int argc, char **argv) { n   srand(15061994); n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     int a, b; n     cin >> a >> b; n     G[a].emplace_back(b); n   } n   vector<int> KAN; n   for (int i = 1; i <= n; i++) { n     KAN.push_back(i); n   } n   random_shuffle(KAN.begin(), KAN.end()); n   for (int i = 0; elapsed() <= 0.95 and i < int(KAN.size()); i++) { n     blo[KAN[i]] = true; n     if (!tried[KAN[i]] and check()) { n       cout << KAN[i] <<   n ; n       exit(0); n     } n     blo[KAN[i]] = false; n   } n   cout << -1 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1000000000; n const int mod = 1e9 + 7; n long long power(int a, long long b) { n   if (b == 0LL) return 1LL; n   long long tmp = power(a, b / 2); n   if (b & 1LL) return (tmp * tmp % mod) * a % mod; n   return tmp * tmp % mod; n } n int main() { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   int n; n   cin >> n; n   cout << 6 * power(4, (1LL << n) - 2) % mod; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> E[101000]; n vector<long long> L[101000]; n int n, Count[101000], Num[101000], cnt, par[101000], pp[18][101000]; n long long Mod = 1000000007, D[101000], D2[101000], T[101000], T2[101000], n           pL[101000], DL[101000]; n int Dep[101000]; n void DFS(int a, int pp) { n   Num[a] = ++cnt; n   int i, x, y; n   x = Num[a]; n   Count[x]++; n   par[x] = Num[pp]; n   for (i = 0; i < E[a].size(); i++) { n     if (pp != E[a][i]) { n       DFS(E[a][i], a); n       y = Num[E[a][i]]; n       pL[y] = L[a][i]; n       Count[x] += Count[y]; n       D[x] = (D[x] + D[y] + L[a][i] * Count[y]) % Mod; n       D2[x] = (D2[x] + D2[y] + L[a][i] * L[a][i] % Mod * Count[y] + n                2 * L[a][i] * D[y]) % n               Mod; n     } n   } n } n void Pro() { n   int i, p; n   long long X, Y; n   T[1] = D[1]; n   for (i = 2; i <= n; i++) { n     p = par[i]; n     DL[i] = DL[p] + pL[i]; n     Dep[i] = Dep[p] + 1; n     X = Count[i]; n     Y = n - Count[i]; n     T[i] = (T[p] + (Y - X + Mod) % Mod * pL[i]) % Mod; n   } n } n void Pro2() { n   int i; n   long long Gap1, Gap2, X, Y, p; n   T2[1] = D2[1]; n   for (i = 2; i <= n; i++) { n     p = par[i]; n     X = Count[i], Y = n - Count[i]; n     Gap1 = ((T[i] - D[i] - pL[i] * Y % Mod + Mod * 2) % Mod * 2 * pL[i] + n             pL[i] * pL[i] % Mod * Y) % n            Mod; n     Gap2 = (D[i] * 2 * pL[i] % Mod + pL[i] * pL[i] % Mod * X) % Mod; n     T2[i] = (T2[p] + Gap1 - Gap2 + Mod) % Mod; n   } n } n void PrePro() { n   int i, j; n   for (i = 1; i <= n; i++) pp[0][i] = par[i]; n   for (i = 0; i < 17; i++) { n     for (j = 1; j <= n; j++) { n       pp[i + 1][j] = pp[i][pp[i][j]]; n     } n   } n } n int LCA(int a, int b) { n   if (Dep[a] < Dep[b]) return LCA(b, a); n   int d = Dep[a] - Dep[b], i = 0; n   while (d) { n     if (d & 1) a = pp[i][a]; n     d >>= 1; n     i++; n   } n   for (i = 17; i >= 0; i--) { n     if (pp[i][a] != pp[i][b]) { n       a = pp[i][a], b = pp[i][b]; n     } n   } n   if (a != b) a = pp[0][a], b = pp[0][b]; n   return a; n } n long long dist(int a, int b) { n   int ppp = LCA(a, b); n   return (DL[a] + DL[b] - DL[ppp] * 2 + Mod * 2) % Mod; n } n long long Solve2(int a, int b) { n   long long d = dist(a, b); n   long long r = (D2[b] + 2 * d * D[b] % Mod + d * d % Mod * Count[b]) % Mod; n   return (r * 2 - T2[a] + Mod) % Mod; n } n long long Solve1(int a, int b) { n   long long d = dist(a, b); n   long long r = n       ((T2[b] - D2[b] + Mod) % Mod + (T[b] - D[b] + Mod) % Mod * 2 * d % Mod + n        d * d % Mod * (n - Count[b])) % n       Mod; n   return (T2[a] - r * 2 + Mod * 2) % Mod; n } n void Output() { n   int Q, a, b; n   scanf( %d , &Q); n   while (Q--) { n     scanf( %d%d , &a, &b); n     a = Num[a], b = Num[b]; n     if (LCA(a, b) == b) { n       printf( %lld n , Solve1(a, b)); n     } else { n       printf( %lld n , Solve2(a, b)); n     } n   } n } n int main() { n   int i, a, b, c; n   scanf( %d , &n); n   for (i = 1; i < n; i++) { n     scanf( %d%d%d , &a, &b, &c); n     E[a].push_back(b); n     E[b].push_back(a); n     L[a].push_back(c); n     L[b].push_back(c); n   } n   DFS(1, 0); n   Pro(); n   Pro2(); n   PrePro(); n   Output(); n   return 0; n } n


#include <bits/stdc++.h> n struct M { n   int p, b; n }; n struct F { n   const int p, i; n   int r, c; n   F(int p, int t, int i) : p(p), i(i), r(p + t), c(0) {} n   int t() { return r - p; } n }; n void solve(std::vector<F> &fs, std::vector<M> &ms) { n   std::multimap<int, int> ms_landed; n   std::map<int, F *> fs_active; n   { n     std::vector<F *> fs_sort; n     fs_sort.reserve(fs.size()); n     for (int i = 0; i < fs.size(); i++) fs_sort.push_back(&fs[i]); n     std::sort(fs_sort.begin(), fs_sort.end(), n               [](const F *lhs, const F *rhs) { return lhs->p < rhs->p; }); n     fs_active.insert({fs_sort[0]->p, fs_sort[0]}); n     int curr = fs_sort[0]->r; n     for (int i = 1; i < fs_sort.size(); i++) { n       F &f = *fs_sort[i]; n       if (f.r > curr) { n         int l = std::max(curr + 1, f.p); n         curr = f.r; n         fs_active.insert({l, &f}); n       } n     } n   } n   auto update = [&](F &f, std::map<int, F *>::iterator &f_succ, const int &b) { n     f.c++; n     f.r += b; n     while (f_succ != fs_active.end()) { n       int l_succ = f_succ->first; n       int r_succ = f_succ->second->r; n       if (f.r < r_succ) { n         if (f.r >= l_succ) { n           f_succ = fs_active.insert(fs_active.erase(f_succ), n                                     {f.r + 1, f_succ->second}); n         } n         break; n       } n       f_succ = fs_active.erase(f_succ); n     } n   }; n   for (const M &m : ms) { n     auto f_it = --fs_active.upper_bound(m.p); n     const int l = f_it->first; n     F &f = *f_it->second; n     if (l <= m.p && m.p <= f.r) { n       update(f, ++f_it, m.b); n       auto m_it = ms_landed.lower_bound(l); n       while (m_it != ms_landed.end()) { n         M m{m_it->first, m_it->second}; n         if (l <= m.p && m.p <= f.r) { n           update(f, f_it, m.b); n           m_it = ms_landed.erase(m_it); n         } else { n           break; n         } n       } n     } else { n       ms_landed.insert({m.p, m.b}); n     } n   } n   for (F &f : fs) { n     printf( %d %d n , f.c, f.t()); n   } n } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   std::vector<F> fs; n   fs.reserve(n); n   std::vector<M> ms; n   ms.reserve(m); n   for (int i = 0; i < n; i++) { n     int p, t; n     scanf( %d%d , &p, &t); n     fs.push_back({p, t, i}); n   } n   for (int i = 0; i < m; i++) { n     int p, b; n     scanf( %d%d , &p, &b); n     ms.push_back({p, b}); n   } n   solve(fs, ms); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string text; n map<int, int> cache; n string to_bin(int v) { n   string res =   ; n   for (int i = 128; i >= 1; i /= 2) { n     if (v - i >= 0) { n       res +=  1 ; n       v -= i; n     } else { n       res +=  0 ; n     } n   } n   return move(res); n } n int reverse_bin(int v) { n   if (cache.count(v)) { n     return cache[v]; n   } n   int res = 0; n   string bin = to_bin(v); n   for (int i = 0, k = 1; i < 8; ++i, k *= 2) { n     if (bin[i] ==  1 ) { n       res += k; n     } n   } n   cache[res] = v; n   cache[v] = res; n   return res; n } n int intercal(int prev, int ch) { n   int rprev = reverse_bin(prev); n   int rch = reverse_bin(ch); n   return (256 - rch + rprev) % 256; n } n int main() { n   getline(cin, text); n   cout << intercal(0, (int)text[0]) << endl; n   for (int i = 1; i < text.size(); ++i) { n     cout << intercal((int)text[i - 1], (int)text[i]) << endl; 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, i, j, k, p, c, x, m, a, b, d, y, t; n   cin >> t; n   while (t--) { n     cin >> n >> a >> b >> c >> d; n     x = (a - b) * n; n     y = (a + b) * n; n     if ((y < (c - d)) || (x > (c + d))) n       cout <<  No  << endl; n     else n       cout <<  Yes  << endl; n   } n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /stack:200000000 ] n #pragma GCC optimize( Ofast ] n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ] n using namespace std; n long long int n, k; n map<vector<pair<long long int, long long int>>, long long int> mp; n vector<pair<long long int, long long int>> get(long long int num) { n   vector<pair<long long int, long long int>> pr; n   for (long long int i = 2; i * i <= num; i++) { n     long long int cnt = 0; n     while (num % i == 0) { n       cnt++; n       num /= i; n     } n     if (cnt % k > 0) pr.push_back({i, cnt % k}); n   } n   if (num > 1) { n     pr.push_back({num, 1}); n     num /= num; n   } n   sort(pr.begin(), pr.end()); n   return pr; n } n signed main() { n   cin >> n >> k; n   vector<long long int> a(n); n   for (long long int i = 0; i < n; i++) cin >> a[i]; n   mp[get(a[0])]++; n   long long int ans = 0; n   for (long long int i = 1; i < n; i++) { n     long long int num = a[i]; n     auto pr = get(num); n     vector<pair<long long int, long long int>> pr2; n     for (auto& i : pr) { n       if ((k - i.second) % k > 0) pr2.push_back({i.first, k - i.second}); n     } n     ans += mp[pr2]; n     mp[pr]++; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<int> > g; n bool flag[100003]; n int down[100003]; n int max1[100003]; n int max2[100003]; n int up[100003]; n void dfs(int x) { n   flag[x] = true; n   int i; n   for (i = 0; i < g[x].size(); i++) { n     if (!flag[g[x][i]]) { n       dfs(g[x][i]); n       if (down[g[x][i]] + 1 > max1[x]) { n         max2[x] = max1[x]; n         max1[x] = down[g[x][i]] + 1; n       } else if (down[g[x][i]] + 1 > max2[x]) n         max2[x] = down[g[x][i]] + 1; n     } n   } n   down[x] = max1[x]; n } n void dfs2(int x) { n   flag[x] = true; n   int i; n   int res; n   for (i = 0; i < g[x].size(); i++) { n     if (!flag[g[x][i]]) { n       if (down[g[x][i]] + 1 > max1[x] - 1) n         res = max2[x]; n       else n         res = max1[x]; n       up[g[x][i]] = max(up[x] + 1, res + 1); n       dfs2(g[x][i]); n     } n   } n } n int n, m, d; n int main() { n   scanf( %d %d %d , &n, &m, &d); n   g.resize(n); n   int x, y; n   int i; n   for (i = 0; i < n; i++) max1[i] = max2[i] = up[i] = down[i] = -2000000000; n   for (i = 0; i < m; i++) { n     scanf( %d , &x); n     x--; n     down[x] = 0; n     up[x] = 0; n     max1[x] = 0; n   } n   for (i = 0; i < n - 1; i++) { n     scanf( %d %d , &x, &y); n     x--; n     y--; n     g[x].push_back(y); n     g[y].push_back(x); n   } n   dfs(0); n   for (i = 0; i < n; i++) flag[i] = false; n   dfs2(0); n   int ans = 0; n   for (i = 0; i < n; i++) n     if (down[i] < d + 1 && up[i] < d + 1) ans++; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, flag = 0; n int matrix[2505][2505]; n int parent[2505]; n vector<int> graph[2505]; n int vis[2505], num[2505]; n struct Edge { n   int u, v, w; n   Edge() {} n   Edge(int u, int v, int w) : u(u), v(v), w(w) {} n }; n vector<Edge> edge; n bool cmp(const Edge &a, const Edge &b) { return a.w < b.w; } n void init() { n   for (int i = 1; i <= 2505; i++) parent[i] = i; n } n void input() { n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       scanf( %d , &matrix[i][j]); n       if (i == j && matrix[i][j] != 0) flag = 1; n       if (i > j && matrix[i][j] != matrix[j][i]) flag = 1; n       if (i < j) edge.push_back(Edge(i, j, matrix[i][j])); n     } n   } n } n int findfather(int x) { n   if (x == parent[x]) return x; n   return parent[x] = findfather(parent[x]); n } n void Union(int x, int y) { n   int rx = findfather(x); n   int ry = findfather(y); n   if (rx > ry) swap(rx, ry); n   if (rx != ry) parent[ry] = rx; n } n void Krukal() { n   sort(edge.begin(), edge.end(), cmp); n   int cnt = 0; n   for (int i = 0; i < edge.size(); i++) { n     int u = edge[i].u; n     int v = edge[i].v; n     int ru = findfather(u); n     int rv = findfather(v); n     if (ru != rv) { n       graph[u].push_back(v); n       graph[v].push_back(u); n       cnt++; n       Union(u, v); n     } n     if (cnt == n - 1) break; n   } n } n void dfs(int u, int fa, int tmp) { n   vis[u] = 1; n   for (int i = 0; i < graph[u].size(); i++) { n     int k = graph[u][i]; n     if (vis[k]) continue; n     if (k == fa) continue; n     num[k] = max(tmp, matrix[u][k]); n     dfs(k, u, num[k]); n   } n } n int main() { n   scanf( %d , &n); n   init(); n   input(); n   if (flag) { n     printf( NOT MAGIC n ); n     return 0; n   } n   Krukal(); n   for (int i = 1; i <= n; i++) { n     memset(vis, 0, sizeof(vis)); n     dfs(i, -1, 0); n     for (int j = i + 1; j <= n; j++) { n       if (num[j] != matrix[i][j]) { n         flag = 1; n         break; n       } n     } n     if (flag) break; n   } n   if (flag) n     printf( NOT MAGIC n ); n   else n     printf( MAGIC n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int already = 0; n   int n, k; n   cin >> n >> k; n   int ans = 0; n   for (int i = 0; i < k; ++i) { n     int cnt; n     cin >> cnt; n     int first; n     cin >> first; n     if (first == 1) { n       int good = 1; n       already = 1; n       --ans; n       while (good < cnt) { n         cin >> first; n         if (first == good + 1) { n           ++good; n           already = good; n           --ans; n         } else { n           ++good; n           break; n         } n       } n       ans += cnt; n       while (good < cnt) { n         cin >> first; n         ++good; n       } n     } else { n       ans += (cnt - 1); n       for (int j = 1; j < cnt; ++j) cin >> first; n     } n   } n   ans += (n - already); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long t, x, y, p, q; n bool check(long long mid) { n   long long pp = p * mid; n   long long qq = q * mid; n   if (pp - x < 0 || qq - y < 0) return false; n   return (pp - x <= qq - y); n } n int main() { n   scanf( %lld , &t); n   while (t--) { n     scanf( %lld %lld %lld %lld , &x, &y, &p, &q); n     if (x * q == p * y) { n       printf( 0 n ); n       continue; n     } n     long long lo = 1, hi = 2000000000; n     while (lo + 1 < hi) { n       long long mid = (lo + hi) / 2LL; n       if (check(mid)) n         hi = mid; n       else n         lo = mid; n     } n     if (check(lo)) hi = lo; n     if (check(hi)) n       printf( %lld n , hi * q - y); n     else n       printf( -1 n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, i, x; n   cin >> t; n   while (t--) { n     int angle; n     cin >> angle; n     x = 360 % (180 - angle); n     if (x == 0) { n       cout <<  YES  << endl; n     } else n       cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long M = 1e9 + 7; n const int N = 3e5 + 7; n const int K = 5e3 + 7; n int n, k; n int a[N]; n int dp[K][K]; n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   sort(a + 1, a + n + 1); n   int top = (n + k - 1) / k; n   int low = n / k; n   int ctop = n % k; n   int clow = k - ctop; n   for (int i = 0; i < K; i++) n     for (int j = 0; j < K; j++) dp[i][j] = -1; n   dp[0][0] = 0; n   for (int i = 0; i <= ctop; i++) n     for (int j = 0; j <= clow; j++) n       if (i || j) { n         dp[i][j] = 2e9 + 7; n         int pnt = i * top + j * low; n         if (j) dp[i][j] = dp[i][j - 1] + a[pnt] - a[pnt - low + 1]; n         if (i) n           dp[i][j] = min(dp[i][j], dp[i - 1][j] + a[pnt] - a[pnt - top + 1]); n       } n   cout << dp[ctop][clow]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int h1, t1, h2, t2, ansh, anst; n   scanf( %2d:%2d , &h1, &t1); n   scanf( %2d:%2d , &h2, &t2); n   if (t1 < t2) { n     h1--, t1 += 60; n   } n   anst = t1 - t2; n   ansh = h1 - h2; n   if (ansh < 0) ansh += 24; n   printf( %02d:%02d n , ansh, anst); n   return 0; n } n


#include <bits/stdc++.h> n int n; n int a[105], l[105]; n int id[105]; n int dp[105][105][2]; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < (int)(n); ++i) scanf( %d %d , &a[i], &l[i]); n   for (int i = 0; i < (int)(n); ++i) id[i] = i; n   std::sort(id, id + n, [&](int x, int y) { return a[x] < a[y]; }); n   dp[0][0][0] = 0; n   for (int i = 0; i < (int)(n); ++i) { n     for (int j = 0; j < (int)(i + 1); ++j) { n       for (int k = 0; k < (int)(2); ++k) { n         int mj = -1, mk = -1; n         for (int nj = i; nj < n; ++nj) { n           for (int nk = 0; nk < (int)(2); ++nk) { n             if (mj == -1 || n                 a[id[mj]] + mk * l[id[mj]] < a[id[nj]] + nk * l[id[nj]]) n               mj = nj, mk = nk; n             dp[nj + 1][mj + 1][mk] = std::max( n                 dp[nj + 1][mj + 1][mk], n                 dp[i][j][k] + a[id[mj]] + mk * l[id[mj]] - n                     std::max( n                         (j ? a[id[j - 1]] + k * l[id[j - 1]] : -0x3f3f3f3f), n                         a[id[nj]] - (!nk) * l[id[nj]])); n           } n         } n       } n     } n   } n   int ans = 0; n   for (int j = 0; j < (int)(n + 1); ++j) n     for (int k = 0; k < (int)(2); ++k) { n       ans = std::max(ans, dp[n][j][k]); n     } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 111, K = 26; n int n; n string name[MAX]; n namespace G { n struct V : vector<int> { n   V() : odw(false) {} n   bool odw; n   int wyj; n }; n V g[K]; n void krawedz(char a, char b) { n   g[int(a) - int( a )].push_back(int(b) - int( a )); n } n int t = 0; n stack<int> stos; n void dfs(int v) { n   g[v].odw = true; n   for (int i = 0; i < ((int((g[v]).size()))); i++) { n     int u = g[v][i]; n     if (!g[u].odw) dfs(u); n   } n   stos.push(v); n   g[v].wyj = t++; n } n bool poprawne_sortowanie() { n   for (int v = 0; v < (K); v++) n     for (int i = 0; i < ((int((g[v]).size()))); i++) { n       int u = g[v][i]; n       if (g[v].wyj < g[u].wyj) return false; n     } n   return true; n } n bool sortowanie_topologiczne() { n   for (int i = 0; i < (K); i++) n     if (!g[i].odw) dfs(i); n   return poprawne_sortowanie(); n } n void wypisz_sortowanie() { n   assert((int((stos).size())) == 26); n   while (!stos.empty()) { n     cout << char(int( a ) + stos.top()); n     stos.pop(); n   } n   cout <<   n ; n } n }  // namespace G n void wczytaj_dane() { n   cin >> n; n   for (int i = 0; i < (n); i++) cin >> name[i]; n } n int roznica(const string& a, const string& b) { n   int m = min((int((a).size())), (int((b).size()))); n   for (int i = 0; i < (m); i++) n     if (a[i] != b[i]) return i; n   return -1; n } n bool porownuj(const string& a, const string& b) { n   int i = roznica(a, b); n   if (i == -1) return (int((a).size())) < (int((b).size())); n   G::krawedz(a[i], b[i]); n   return true; n } n void zrob_test() { n   wczytaj_dane(); n   for (int i = 0; i < (n - 1); i++) n     if (!porownuj(name[i], name[i + 1])) { n       cout <<  Impossible n ; n       return; n     } n   if (G::sortowanie_topologiczne()) n     G::wypisz_sortowanie(); n   else n     cout <<  Impossible n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   zrob_test(); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n vector<int> v[200005]; n int CR, n, k, sz[200005], target[200005], cented[200005]; n void getsize(int now, int pre) { n   sz[now] = (target[now] == 1); n   for (int i = 0; i < v[now].size(); i++) { n     int next = v[now][i]; n     if (next == pre || cented[next]) continue; n     getsize(next, now); n     sz[now] += sz[next]; n   } n } n int getcent(int now, int pre, int R) { n   for (int i = 0; i < v[now].size(); i++) { n     int next = v[now][i]; n     if (next == pre || cented[next]) continue; n     if (sz[next] > sz[R] / 2) return getcent(next, now, R); n   } n   return now; n } n priority_queue<pair<int, int> > pq; n int centdfs(int now) { n   getsize(now, -1); n   int cc = getcent(now, -1, now); n   cented[cc] = 1; n   if (CR == -1) CR = cc; n   return cc; n } n int gcnt = 0; n vector<int> tmp[200005]; n void go(int now, int pre) { n   if (target[now]) tmp[gcnt].push_back(now); n   for (int i = 0; i < v[now].size(); i++) { n     int next = v[now][i]; n     if (next == pre) continue; n     go(next, now); n   } n } n int main() { n   CR = -1; n   scanf( %d %d , &n, &k); n   for (int a, b, i = 0; i < n - 1; i++) { n     scanf( %d %d , &a, &b); n     v[a].push_back(b); n     v[b].push_back(a); n   } n   for (int i = 1; i <= k; i++) { n     for (int t, j = 0; j < 2; j++) { n       scanf( %d , &t); n       target[t] = 1; n     } n   } n   centdfs(1); n   printf( 1 n%d n , CR); n   for (int i = 0; i < v[CR].size(); i++) { n     ++gcnt; n     go(v[CR][i], CR); n     if (tmp[gcnt].empty()) continue; n     pq.push(make_pair((int)tmp[gcnt].size(), gcnt)); n   } n   while (!pq.empty()) { n     pair<int, int> p = pq.top(); n     pq.pop(); n     if ((int)pq.size() == 0) { n       printf( %d %d %d n , tmp[p.second].back(), CR, CR); n       break; n     } n     pair<int, int> p2 = pq.top(); n     pq.pop(); n     printf( %d %d %d n , tmp[p.second].back(), tmp[p2.second].back(), CR); n     tmp[p.second].pop_back(); n     tmp[p2.second].pop_back(); n     if (--p.first != 0) { n       pq.push(p); n     } n     if (--p2.first != 0) { n       pq.push(p2); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 100005; n vector<int> A, B[MAX], C, D; n int visited[MAX]; n int n, m; n void DFS(int u) { n   visited[u] = 1; n   C.push_back(u); n   for (int i = 0; i < B[u].size(); i++) { n     int current = B[u][i]; n     if (visited[current] == 0) DFS(current); n   } n } n int main() { n   int n; n   scanf( %d , &n); n   A.clear(); n   for (int i = 0; i <= n; i++) visited[i] = 0; n   string s; n   for (int i = 0; i < n; i += 1) { n     int val; n     cin >> val; n     A.push_back(val); n   } n   for (int i = 0; i < MAX; i++) B[i].clear(); n   for (int i = 0; i < n; i++) { n     cin >> s; n     for (int j = 0; j < n; j++) { n       if (s[j] ==  1 ) { n         B[i + 1].push_back(j + 1); n         B[j + 1].push_back(i + 1); n       } n     } n   } n   for (int i = 1; i <= n; i++) { n     C.clear(); n     D.clear(); n     if (visited[i] == 0) { n       DFS(i); n       for (int j = 0; j < C.size(); j++) { n         D.push_back(A[C[j] - 1]); n       } n       sort(C.begin(), C.end()); n       sort(D.begin(), D.end()); n       for (int j = 0; j < C.size(); j++) { n         A[C[j] - 1] = D[j]; n       } n     } n   } n   for (int i = 0; i < A.size(); i++) printf( %d  , A[i]); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, s, ans = 0, f[2 * 200005]; n inline int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); } n int main() { n   scanf( %d%d%d , &n, &m, &s); n   for (register int i = 1; i <= m + n; i++) f[i] = i; n   for (register int i = 1; i <= s; i++) { n     register int a, b; n     scanf( %d%d , &a, &b), b += n; n     f[find(b)] = find(a); n   } n   for (register int i = 1; i <= n + m; i++) n     if (f[i] == i) ans++; n   printf( %d , ans - 1); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(3,  Ofast ,  inline ) n const double eps = 1e-7; n const int maxn = 3e5 + 10; n const int prime[15] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37}; n const int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1}; n int spgcd(int a, int b) { n   while (b ^= a ^= b ^= a %= b) n     ; n   return a; n } n inline int mul(int a, int b, int p) { return (long long)a * b % p; } n template <typename T> n void scan(T &x) { n   x = 0; n   bool _ = 0; n   T c = getchar(); n   _ = c == 45; n   c = _ ? getchar() : c; n   while (c < 48 || c > 57) c = getchar(); n   for (; c < 48 || c > 57; c = getchar()) n     ; n   for (; c > 47 && c < 58; c = getchar()) x = (x << 3) + (x << 1) + (c & 15); n   x = _ ? -x : x; n } n template <typename T> n void printn(T n) { n   bool _ = 0; n   _ = n < 0; n   n = _ ? -n : n; n   char snum[65]; n   int i = 0; n   do { n     snum[i++] = n % 10 + 48; n     n /= 10; n   } while (n); n   --i; n   if (_) putchar(45); n   while (i >= 0) putchar(snum[i--]); n } n template <typename First, typename... Ints> n void scan(First &arg, Ints &...rest) { n   scan(arg); n   scan(rest...); n } n template <typename T> n void print(T n) { n   printn(n); n   putchar(10); n } n template <typename First, typename... Ints> n void print(First arg, Ints... rest) { n   printn(arg); n   putchar(32); n   print(rest...); n } n using namespace std; n map<int, int> mp; n void solve() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     int l, r; n     cin >> l >> r; n     mp[l]++, mp[r]--; n   } n   int ans = 0, id = 1; n   int sum = 0; n   for (auto i : mp) { n     sum += i.second; n     if (sum > ans) { n       ans = sum; n       id = i.first; n     } n   } n   cout << id <<     << ans << endl; n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int sz = (1 << 22); n bool ar[sz], us[2][sz]; n int n, m, bg; n void dfs(int v, int t) { n   us[t][v] = 1; n   if (t == 0) { n     if (us[1][bg ^ v] == 0) dfs(bg ^ v, 1); n   } else { n     if (ar[v] and us[0][v] == 0) dfs(v, 0); n     for (int i = 0; i < n; i++) { n       if (v & (1 << i)) { n         int ne = v - (1 << i); n         if (us[1][ne] == 0) dfs(ne, 1); n       } n     } n   } n } n int main() { n   int an = 0; n   cin >> n >> m; n   bg = (1 << n) - 1; n   for (int a = 0; a < m; a++) { n     int x; n     scanf( %d , &x); n     ar[x] = 1; n   } n   for (int a = 0; a < (1 << n); a++) { n     if (ar[a] and us[0][a] == 0) { n       dfs(a, 0), an++; n     } n   } n   cout << an; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n long long a[50]; n long long inv[50]; n long long Finv[50]; n long long n, s; n void init() { n   inv[1] = 1; n   for (int i = 2; i <= 50; i++) { n     inv[i] = (mod - mod / i) * inv[mod % i] % mod; n   } n   Finv[0] = 1; n   for (int i = 1; i <= 50; i++) { n     Finv[i] = Finv[i - 1] % mod * inv[i] % mod; n   } n } n long long C(long long n, long long m) { n   if (n < 0 || m < 0 || m > n) return 0; n   long long res = 1; n   for (long long i = n; i > n - m; i--) { n     res = (i % mod * res) % mod; n   } n   res = res % mod * Finv[m] % mod; n   return res % mod; n } n int main() { n   init(); n   cin >> n >> s; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   long long res = 0; n   for (long long i = 0; i < (1ll << n); i++) { n     long long tmp = s; n     long long cnt = 0; n     for (long long j = 0; j < n; j++) { n       if ((1ll << j) & i) { n         tmp -= a[j] + 1; n         cnt++; n       } n     } n     if (tmp < 0) continue; n     if (cnt & 1) { n       res = (((res - C(tmp + n - 1, n - 1)) % mod + mod) % mod) % mod; n     } else { n       res = (res + C(tmp + n - 1, n - 1) % mod) % mod; n     } n   } n   cout << res << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int N; n   cin >> N; n   if (N % 2 == 0) n     cout << -1 << endl; n   else { n     for (int i = 0; i < N; i++) cout << i << (i == N - 1 ?   n  :    ); n     for (int i = 0; i < N; i++) n       cout << ((long long)(N - 2) * i) % N << (i == N - 1 ?   n  :    ); n     for (int i = 0; i < N; i++) n       cout << ((long long)(N - 2) * i + i) % N << (i == N - 1 ?   n  :    ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int sqrt_maxn = 505; n const int maxsqrt_n = 205; n const int maxn = 100005; n int a[maxn]; n struct node { n   int val; n   node* next; n   node* front; n }; n node* front[maxsqrt_n]; n node* rail[maxsqrt_n]; n int dp[maxsqrt_n][maxn]; n node* new_node() { n   static node a[200005]; n   static int top = 0; n   return &a[top++]; n } n void insert_node(int x, int y) { n   node* t = new_node(); n   t->val = y; n   t->next = front[x]; n   if (front[x] != 0) front[x]->front = t; n   t->front = 0; n   front[x] = t; n } n void trans_inside(int x, int y) { n   register int j = x / sqrt_maxn; n   register int i; n   register node* t1 = front[j]; n   for (i = j * sqrt_maxn; i <= x; i++) { n     t1 = t1->next; n   } n   register node* t2 = t1; n   for (; i <= y; i++) { n     t2 = t2->next; n   } n   t1->front->next = t2; n   t2->front->next = t2->next; n   t2->next->front = t2->front; n   t2->front = t1->front; n   t2->next = t1; n   t1->front = t2; n } n void trans(int x, int y) { n   register int jx = x / sqrt_maxn; n   register int i; n   register node* t1 = front[jx]; n   for (i = jx * sqrt_maxn; i <= x; i++) { n     t1 = t1->next; n   } n   int jy = y / sqrt_maxn; n   register node* t2 = front[jy]; n   for (i = jy * sqrt_maxn; i <= y; i++) { n     t2 = t2->next; n   } n   t1->front->next = t2; n   t2->front->next = t2->next; n   t2->next->front = t2->front; n   t2->front = t1->front; n   t2->next = t1; n   t1->front = t2; n   dp[jx][t2->val]++; n   dp[jy][t2->val]--; n   for (i = jx; i < jy; i++) { n     t1 = front[i + 1]->next; n     t2 = rail[i]->front; n     t1->front->next = t2; n     t2->front->next = t2->next; n     t2->next->front = t2->front; n     t2->front = t1->front; n     t2->next = t1; n     t1->front = t2; n     dp[i + 1][t2->val]++; n     dp[i][t2->val]--; n   } n } n int calc_inside(int x, int y, int val) { n   int j = x / sqrt_maxn; n   int i; n   node* t1 = front[j]; n   for (i = j * sqrt_maxn; i <= x; i++) { n     t1 = t1->next; n   } n   register int ans = 0; n   for (; i <= y; i++) { n     if (t1->val == val) ans++; n     t1 = t1->next; n   } n   if (t1->val == val) ans++; n   return ans; n } n int calc(int x, int y, int val) { n   int j = x / sqrt_maxn; n   int i; n   node* t1 = front[j]; n   for (i = j * sqrt_maxn; i <= x; i++) { n     t1 = t1->next; n   } n   int ans = 0; n   for (; t1->val != -2;) { n     if (t1->val == val) ans++; n     t1 = t1->next; n   } n   int jy = y / sqrt_maxn; n   for (i = j + 1; i < jy; i++) { n     ans += dp[i][val]; n   } n   t1 = front[jy]; n   for (i = jy * sqrt_maxn; i <= y; i++) { n     t1 = t1->next; n     if (t1->val == val) ans++; n   } n   return ans; n } n int main() { n   fprintf(stderr,  %d n , clock()); n   int n; n   scanf( %d , &n); n   int i; n   for (i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     a[i]--; n   } n   memset(dp, 0, sizeof(dp)); n   for (i = 0; i < n; i += sqrt_maxn) { n     register int temp = i / sqrt_maxn; n     front[temp] = 0; n     int j; n     insert_node(temp, -2); n     rail[temp] = front[temp]; n     for (j = i + sqrt_maxn - 1; j >= i; j--) { n       if (j >= n) continue; n       insert_node(temp, a[j]); n       dp[temp][a[j]]++; n     } n     insert_node(temp, -1); n   } n   int lastans = 0; n   int q; n   scanf( %d , &q); n   for (i = 0; i < q; i++) { n     int oper; n     scanf( %d , &oper); n     if (oper == 1) { n       int x, y; n       scanf( %d%d , &x, &y); n       x = (x - 1 + lastans) % n; n       y = (y - 1 + lastans) % n; n       if (x > y) swap(x, y); n       if (x == y) continue; n       if (x / sqrt_maxn == y / sqrt_maxn) { n         trans_inside(x, y); n       } else { n         trans(x, y); n       } n     } else { n       int x, y, z; n       scanf( %d%d%d , &x, &y, &z); n       x = (x - 1 + lastans) % n; n       y = (y - 1 + lastans) % n; n       z = (z - 1 + lastans) % n; n       if (x > y) swap(x, y); n       if (x / sqrt_maxn == y / sqrt_maxn) { n         lastans = calc_inside(x, y, z); n       } else { n         lastans = calc(x, y, z); n       } n       printf( %d n , lastans); n     } n   } n   fprintf(stderr,  %d n , clock()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 998244353; n const int M = 80; n const int N = 4100; n long long c[M][M], m; n struct Tree { n   struct Node { n     int ne, to; n   } e[2 * N]; n   int vis[N], tot = 0, he[N], sz[N], mx[N], q[N], n, rp, mn; n   long long step[M], f[N][M], g[N][M], tmp[M], ans[M]; n   void add(int x, int y) { n     e[++tot].ne = he[x]; n     he[x] = tot; n     e[tot].to = y; n   } n   void addedge(int x, int y) { n     add(x, y); n     add(y, x); n   } n   void dfs1(int x, int fa) { n     int i, y; n     sz[x] = 1; n     mx[x] = 0; n     for (i = he[x]; i; i = e[i].ne) { n       y = e[i].to; n       if ((!vis[y]) && (y != fa)) { n         dfs1(y, x); n         sz[x] += sz[y]; n         if (sz[y] > mx[x]) mx[x] = sz[y]; n       } n     } n   } n   void dfsrt(int now, int x, int fa, int &rt) { n     int i, y; n     mx[x] = max(mx[x], sz[now] - sz[x]); n     if (mx[x] < mn) { n       mn = mx[x]; n       rt = x; n     } n     for (i = he[x]; i; i = e[i].ne) { n       y = e[i].to; n       if ((!vis[y]) && (y != fa)) dfsrt(now, y, x, rt); n     } n   } n   void dfs2(int x, int fa) { n     int i, y; n     q[++rp] = x; n     for (i = he[x]; i; i = e[i].ne) { n       y = e[i].to; n       if ((!vis[y]) && (y != fa)) dfs2(y, x); n     } n   } n   void divide(int x) { n     int rt, i, j, k, y; n     mn = n; n     dfs1(x, 0); n     dfsrt(x, x, 0, rt); n     vis[rt] = 1; n     for (i = he[rt]; i; i = e[i].ne) n       if (!vis[e[i].to]) divide(e[i].to); n     vis[rt] = 0; n     rp = 0; n     dfs2(rt, 0); n     memset(step, 0, sizeof(step)); n     for (i = he[rt]; i; i = e[i].ne) { n       y = e[i].to; n       if (!vis[y]) n         for (j = 0; j <= m - 2; j++) n           step[j + 2] = (step[j + 2] + f[y][j]) % mod; n     } n     memset(f[rt], 0, sizeof(f[rt])); n     f[rt][0] = 1; n     for (i = 1; i <= m; i++) n       for (j = 2; j <= i; j++) n         f[rt][i] = (f[rt][i] + f[rt][i - j] * step[j]) % mod; n     for (i = 2; i <= rp; i++) { n       memset(tmp, 0, sizeof(tmp)); n       for (j = 2; j <= m; j++) n         for (k = 0; k <= j - 2; k++) n           tmp[j] = (tmp[j] + g[q[i]][k] * f[rt][j - k - 2]) % mod; n       for (j = 2; j <= m; j++) n         for (k = 0; k <= j - 2; k++) n           f[q[i]][j] = (f[q[i]][j] + g[q[i]][k] * tmp[j - k]) % mod; n     } n     for (i = 1; i <= rp; i++) memset(g[q[i]], 0, sizeof(g[q[i]])); n     g[x][0] = 1; n     for (i = 1; i <= m; i++) n       for (j = 1; j <= rp; j++) n         for (k = he[q[j]]; k; k = e[k].ne) { n           y = e[k].to; n           if (!vis[y]) g[q[j]][i] = (g[q[j]][i] + g[y][i - 1]) % mod; n         } n   } n   void solve() { n     divide(1); n     for (int i = 0; i <= m; i++) n       for (int j = 1; j <= n; j++) ans[i] = (ans[i] + f[j][i]) % mod; n   } n } tr1, tr2; n int main() { n   int i, j, k, x, y; n   long long out; n   scanf( %d%d%d , &tr1.n, &tr2.n, &m); n   for (i = 1; i < tr1.n; i++) { n     scanf( %d%d , &x, &y); n     tr1.addedge(x, y); n   } n   for (i = 1; i < tr2.n; i++) { n     scanf( %d%d , &x, &y); n     tr2.addedge(x, y); n   } n   for (i = 0; i <= m; i++) c[i][0] = 1; n   for (i = 1; i <= m; i++) n     for (j = 1; j <= i; j++) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod; n   tr1.solve(); n   tr2.solve(); n   out = 0; n   for (i = 0; i <= m; i++) n     out = (out + (c[m][i] * tr1.ans[i]) % mod * tr2.ans[m - i]) % mod; n   printf( %I64d n , out); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct trie { n   struct tree { n     long long al[26]; n     bool ex; n   } nxt[100005]; n   long long cnt, dep[100005]; n   void insert(char *s) { n     long long l = strlen(s), rt = 0; n     for (register long long i = 0; i < l; i++) { n       long long c = s[i] -  a ; n       if (!nxt[rt].al[c]) nxt[rt].al[c] = ++cnt, dep[cnt] = dep[rt] + 1; n       rt = nxt[rt].al[c]; n     } n     nxt[rt].ex = 1; n   } n } tr; n priority_queue<long long> q[100005]; n long long n, ans = 0; n char s[100005]; n template <typename T> n inline void read(T &x) { n   T c = getchar(), f = 0; n   for (; c < 48 || 57 < c; c = getchar()) n     if (c ==  - ) f = 1; n   for (x = 0; 48 <= c && c <= 57; c = getchar()) n     x = (x << 3) + (x << 1) + (c ^ 48); n   if (f) x = -x; n } n template <typename T> n inline void print(T x) { n   if (x < 0) x = -x, putchar( - ); n   if (x > 9) print(x / 10); n   putchar(x % 10 + 48); n } n inline void merge(long long x, long long y) { n   while (!q[y].empty()) q[x].push(q[y].top()), q[y].pop(); n } n void dfs(long long x) { n   for (register long long i = 0; i < 26; i++) n     if (tr.nxt[x].al[i]) dfs(tr.nxt[x].al[i]); n   for (register long long i = 0; i < 26; i++) n     if (tr.nxt[x].al[i]) merge(x, tr.nxt[x].al[i]); n   if (!x) return; n   if (tr.nxt[x].ex) n     ans += tr.dep[x], q[x].push(tr.dep[x]); n   else n     ans -= q[x].top() - tr.dep[x], q[x].pop(), q[x].push(tr.dep[x]); n } n signed main() { n   scanf( %lld , &n); n   for (register long long i = 1; i <= n; i++) scanf( %s , s), tr.insert(s); n   dfs(0), printf( %lld , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5; n int n, T, ans; n int t[N]; n priority_queue<int> pq; n int main() { n   scanf( %d%d , &n, &T); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &t[i]); n     t[i] = t[i] > i ? t[i] - i : 0; n   } n   for (int i = 1; i <= n; ++i) { n     pq.push(t[i]); n     while ((long long)pq.top() + i >= T && !pq.empty()) { n       pq.pop(); n     } n     ans = max(ans, (int)pq.size()); n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int a, b, i, j, c = 0; n   int fil, col; n   scanf( %d , &a); n   scanf( %d , &b); n   char myChar; n   int aux[2][3]; n   for (i = 0; i < a; i++) { n     for (j = 0; j < b; j++) { n       scanf(  %c , &myChar); n       if (myChar ==  * ) { n         aux[0][c] = i + 1; n         aux[1][c] = j + 1; n         c++; n       } n     } n   } n   for (i = 0; i < 2; i++) { n     for (j = i + 1; j < 3; j++) { n       if (aux[0][i] == aux[0][j]) { n         aux[0][i] = -1; n         aux[0][j] = -1; n       } n       if (aux[1][i] == aux[1][j]) { n         aux[1][i] = -1; n         aux[1][j] = -1; n       } n     } n   } n   for (i = 0; i < 3; i++) { n     if (aux[0][i] != -1) { n       fil = aux[0][i]; n     } n     if (aux[1][i] != -1) { n       col = aux[1][i]; n     } n   } n   printf( %d %d , fil, col); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n const char nl =   n ; n const int MX = 100001; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   int t; n   cin >> t; n   for (int tt = 0; tt < (t); tt++) { n     int n; n     cin >> n; n     for (int i = 0; i < (n); i++) cout <<  1  ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const ll INF = 1e18 + 1; n const ll mod = 1e9 + 7; n vector<vector<ll> > adj; n vector<ll> desc, max_n; n ll gmnc = INF; n void print_vec(vector<ll> vec) { n   for (int i = 0; i < vec.size(); ++i) { n     cout << vec[i] <<    ; n   } n   cout << endl; n } n ll desc_cnt(ll curr, ll par) { n   ll cnt = 1; n   for (auto it : adj[curr]) { n     if (it != par) { n       cnt += desc_cnt(it, curr); n     } n   } n   desc[curr] = cnt; n   return cnt; n } n void max_neigh_cnt(ll curr, ll par) { n   ll mnc = -INF; n   mnc = max(mnc, desc[1] - desc[curr]); n   for (auto it : adj[curr]) { n     if (it != par) { n       mnc = max(mnc, desc[it]); n     } n   } n   gmnc = min(gmnc, mnc); n   max_n[curr] = mnc; n   for (auto it : adj[curr]) { n     if (it != par) { n       max_neigh_cnt(it, curr); n     } n   } n } n int main() { n   cin.tie(0); n   ios_base::sync_with_stdio(0); n   ll t; n   cin >> t; n   while (t--) { n     ll n; n     cin >> n; n     adj.clear(); n     desc.clear(); n     max_n.clear(); n     gmnc = INF; n     adj.resize(n + 1); n     desc.resize(n + 1); n     max_n.resize(n + 1); n     for (int i = 1; i <= n - 1; ++i) { n       ll x, y; n       cin >> x >> y; n       adj[x].push_back(y); n       adj[y].push_back(x); n     } n     desc_cnt(1, 1); n     max_neigh_cnt(1, 1); n     vector<ll> cn; n     for (int i = 1; i <= n; ++i) { n       if (max_n[i] == gmnc) { n         cn.push_back(i); n       } n     } n     pair<ll, ll> e1, e2; n     if (cn.size() > 1) { n       for (auto it : adj[cn[0]]) { n         if (it != cn[1]) { n           e1 = make_pair(cn[0], it); n           e2 = make_pair(cn[1], it); n           break; n         } n       } n     } else { n       e1 = make_pair(cn[0], adj[cn[0]][0]); n       e2 = e1; n     } n     cout << e1.first <<     << e1.second << endl; n     cout << e2.first <<     << e2.second << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n char s[400010]; n int a[200]; n vector<int> S; n vector<int> d, q; n int main() { n   int n; n   scanf( %d %s , &n, s); n   for (int i = 0; i < n; i++) a[s[i]]++; n   int p = 0; n   for (int i = 0; i < 128; i++) { n     if (a[i] % 2) p++, a[i]--, S.push_back(i); n     if (a[i]) { n       d.push_back(i); n       q.push_back(a[i]); n     } n   } n   if (p == 0) { n     int cn = 0; n     for (int i = 0; i < 128; i++) { n       while (a[i]) s[cn++] = i, a[i] -= 2; n     } n     for (int i = 0; i < cn; i++) s[cn + i] = s[cn - i - 1]; n     s[n] =   0 ; n     printf( 1 n%s n , s); n   } else { n     int Min = n; n     for (int i = 1; i * i <= n; i++) { n       if (n % i == 0) { n         if (i % 2 && n / i >= p && (n / i - p) % 2 == 0) Min = min(Min, n / i); n         if (n / i % 2 && i >= p && (i - p) % 2 == 0) Min = min(Min, i); n       } n     } n     printf( %d n , Min); n     int L = n / Min; n     int pi = L / 2; n     int now = 0; n     for (int i = 0; i < Min; i++) { n       int x = pi + i * L; n       if (S.size() > i) n         s[x] = S[i]; n       else { n         while (!q[now]) now++; n         s[x] = d[now]; n         S.push_back(d[now]); n         S.push_back(d[now]); n         q[now] -= 2; n       } n       for (int i = 0; i < L / 2; i++) { n         while (!q[now]) now++; n         s[x - i - 1] = d[now]; n         s[x + i + 1] = d[now]; n         q[now] -= 2; n       } n     } n     for (int i = 0; i < n; i++) { n       printf( %c , s[i]); n       if (i % L == L - 1 && i != n - 1) printf(   ); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6, SZ = 800, INF = 1 << 29; n const long long LINF = (1LL << 60), mod = 1e9 + 7; n const long double eps = 1e-8, PI = acos(-1.0); n inline int dcmp(double x, double y = 0.0) { return abs(x - y) < eps; } n template <typename Type> n inline Type ru(Type &v) { n   static char READ_DATA; n   static int SIGNAL_INPUT = 1; n   while ((READ_DATA = getchar()) <  0  || READ_DATA >  9 ) n     if (READ_DATA ==  - ) n       SIGNAL_INPUT = -1; n     else if (READ_DATA == EOF) n       return EOF; n   v = READ_DATA -  0 ; n   while ((READ_DATA = getchar()) >=  0  && READ_DATA <=  9 ) n     v = v * 10 + READ_DATA -  0 ; n   v *= SIGNAL_INPUT; n   return v; n } n template <typename A, typename B> n inline int ru(A &x, B &y) { n   if (ru(x) == EOF) return EOF; n   ru(y); n   return 2; n } n template <typename A, typename B, typename C> n inline int ru(A &x, B &y, C &z) { n   if (ru(x) == EOF) return EOF; n   ru(y); n   ru(z); n   return 3; n } n long long gcd(long long a, long long b) { n   a = abs(a); n   b = abs(b); n   while (b) { n     a %= b; n     swap(a, b); n   } n   return a; n } n const int maxn = 1e6 + 5; n int n, a[maxn], m, d[maxn], id[maxn]; n int cmp(const int &i, const int &j) { return d[(i + 1) / 2] > d[(j + 1) / 2]; } n int main() { n   ru(n); n   for (int i = 1; i <= n; i++) { n     ru(d[i]); n   } n   for (int i = 1; i < 2 * n; i += 2) { n     a[++m] = i; n   } n   sort(a + 1, a + m + 1, cmp); n   for (int i = 2; i <= m; i++) { n     printf( %d %d n , a[i - 1], a[i]); n   } n   for (int i = 1; i <= n; i++) { n     int j = (a[i] + 1) / 2; n     if (i + d[j] - 1 <= m) { n       printf( %d %d n , 2 * j, a[i + d[j] - 1]); n       if (i + d[j] - 1 == m) { n         a[++m] = 2 * j; n       } n     } else { n       printf( %d %d n , 2 * j, a[i - d[j] + 1]); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int kq = 0; n     vector<pair<int, int> > res; n     int n, k; n     cin >> n >> k; n     vector<bool> used(2 * n + 1, false); n     for (int i = 1; i <= k; i++) { n       int u, v; n       cin >> u >> v; n       res.push_back({min(u, v), max(u, v)}); n       used[u] = true; n       used[v] = true; n     } n     vector<int> conlai; n     for (int i = 1; i <= 2 * n; i++) { n       if (!used[i]) conlai.push_back(i); n     } n     int len = n - k; n     for (int i = 0; i < len; i++) { n       res.push_back({conlai[i], conlai[i + len]}); n     } n     for (int i = 0; i < res.size(); i++) { n       for (int j = i + 1; j < res.size(); j++) { n         int a = (res[j].first - res[i].first) * (res[j].second - res[i].first); n         int b = n             (res[j].first - res[i].second) * (res[j].second - res[i].second); n         if (a * b < 0) { n           kq++; n         } n       } n     } n     cout << kq << endl; n   } n } n


#include <bits/stdc++.h> n int main() { n   long n, k, x, a, y; n   scanf( %ld %ld , &n, &k); n   a = n; n   x = n; n   while (x >= k) { n     y = x % k; n     x = x / k; n     a = a + x; n     x = x + y; n   } n   printf( %ld n , a); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename U> n inline void smin(T &a, U b) { n   if (a > b) a = b; n } n template <typename T, typename U> n inline void smax(T &a, U b) { n   if (a < b) a = b; n } n int power(int a, int b, int m, int ans = 1) { n   for (; b; b >>= 1, a = 1LL * a * a % m) n     if (b & 1) ans = 1LL * ans * a % m; n   return ans; n } n const int maxn = 110; n int a[maxn]; n int arr[maxn * maxn]; n int cat[maxn * maxn][maxn]; n map<set<int>, int> mp; n int top; n int recure(set<int> s) { n   if (s.empty()) return 0; n   if (mp.count(s)) return mp[s]; n   int d = *(--s.end()); n   int vis[maxn]; n   memset(vis, 0, sizeof(vis)); n   for (int i = 1; i <= d; i++) { n     set<int> res; n     for (set<int>::iterator it = s.begin(); it != s.end(); it++) { n       if (*it < i) n         res.insert(*it); n       else if (*it > i) n         res.insert(*it - i); n     } n     vis[recure(res)] = 1; n   } n   int g; n   for (int i = 0; i < maxn; i++) n     if (!vis[i]) { n       g = i; n       break; n     } n   mp[s] = g; n   return g; n } n int main() { n   int n, Num = 0; n   cin >> n; n   for (int i = 0; i < n; i++) scanf( %d , &a[i]); n   for (int i = 0; i < n; i++) { n     long long num = 1ll * a[i]; n     for (int j = 2; 1ll * j * j <= num; j++) { n       if (num % j) continue; n       while (num % j == 0) num /= j; n       arr[Num++] = j; n     } n     if (num > 1) { n       arr[Num++] = (int)num; n     } n   } n   sort(arr, arr + Num); n   Num = unique(arr, arr + Num) - arr; n   for (int i = 0; i < n; i++) { n     long long num = 1ll * a[i]; n     for (int j = 2; 1ll * j * j <= num; j++) { n       if (num % j) continue; n       int cnt = 0; n       while (num % j == 0) num /= j, cnt++; n       int t = lower_bound(arr, arr + Num, j) - arr; n       cat[t][cnt] = 1; n     } n     if (num > 1) { n       int t = lower_bound(arr, arr + Num, (int)num) - arr; n       cat[t][1] = 1; n     } n   } n   int ok = 0; n   for (int i = 0; i < Num; i++) { n     set<int> res; n     res.clear(); n     for (int j = 1; j < maxn; j++) { n       if (cat[i][j]) res.insert(j); n     } n     ok ^= recure(res); n   } n   if (ok) n     puts( Mojtaba ); n   else n     puts( Arpa ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 505; n int n, now, siz[N], f[N]; n bool vis[N]; n vector<int> g, ans[N]; n inline bool cmp(int x, int y) { return siz[x] < siz[y]; } n void divide(int l, int r) { n   if (l > r) return; n   cout << 1 << endl << 1 << endl << r - l + 1 << endl; n   for (int i = l; i <= r; ++i) cout << g[i] <<    ; n   cout << endl << now << endl; n   int x, mid = (l + r) >> 1; n   cin >> x; n   if (!x) return; n   if (l == r) return vis[g[l]] = 1, ans[now].push_back(g[l]); n   divide(l, mid), divide(mid + 1, r); n } n int main() { n   cin >> n, siz[1] = n; n   for (int i = 2; i <= n; ++i) { n     cout << 1 << endl << 1 << endl << n - 1 << endl; n     for (int j = 2; j <= n; ++j) cout << j <<    ; n     cout << endl << i << endl; n     cin >> siz[i]; n   } n   for (int i = 1; i <= n; ++i) f[i] = i; n   sort(f + 1, f + n + 1, cmp); n   for (int i = 1; i <= n; ++i) { n     now = f[i]; n     divide(0, g.size() - 1); n     for (unsigned i = 0; i < g.size(); ++i) n       if (vis[g[i]]) g.erase(g.begin() + i--); n     g.push_back(now); n   } n   cout <<  ANSWER  << endl; n   for (int i = 1; i <= n; ++i) n     for (int j : ans[i]) cout << i <<     << j << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k; n long long c[100006], freq[100006], people[100006], h[100006]; n long long catche[5005][505]; n long long dp(long long left, long long pep) { n   if (left == 0 || pep == 0) return 0; n   long long &ans = catche[left][pep]; n   if (ans != -1) return ans; n   ans = 0; n   for (long long j = 1; j <= min(left, k); j++) { n     ans = max(ans, h[j] + dp(left - j, pep - 1)); n   } n   return ans; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> n >> k; n   long long ans = 0; n   long long i, j; n   for (i = 1; i <= (n * k); i++) { n     long long x; n     cin >> x; n     freq[x]++; n   } n   for (i = 1; i <= n; i++) { n     long long x; n     cin >> x; n     people[x]++; n   } n   for (i = 1; i <= k; i++) { n     cin >> h[i]; n   } n   for (i = 1; i <= 100005; i++) { n     if (!people[i]) { n       continue; n     } n     for (j = 0; j <= freq[i]; j++) { n       for (long long kk = 0; kk <= people[i]; kk++) { n         catche[j][kk] = -1; n       } n     } n     ans += dp(freq[i], people[i]); n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int N = 100005; n void solve() { n   long long int m, n; n   cin >> n >> m; n   long long int count = 0; n   for (long long int i = 1; i <= n; i++) { n     count += (m + i % 5) / 5; n   } n   cout << count << endl; n   return; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n bool uin(T &a, T b) { n   if (a > b) { n     a = b; n     return true; n   } n   return false; n } n template <class T> n bool uax(T &a, T b) { n   if (a < b) { n     a = b; n     return true; n   } n   return false; n } n const int MAXN = 1100000; n vector<int> lft[MAXN], rgt[MAXN]; n int leftf[MAXN], anyf[MAXN]; n int lc[MAXN], rc[MAXN]; n char s[10]; n struct TNode { n   int left, right; n   int L, R; n   int maxk; n   TNode(int L = -1, int R = -1) : left(-1), right(-1), L(L), R(R), maxk(-1e9) {} n }; n const int MAXT = 2100000; n TNode t[MAXT]; n int tc = 0; n int buildTree(int L, int R) { n   int node = tc++; n   t[node] = TNode(L, R); n   if (R - L == 1) return node; n   int M = (L + R) / 2; n   t[node].left = buildTree(L, M); n   t[node].right = buildTree(M, R); n   return node; n } n int getMax(int node, int L, int R) { n   if (max(L, t[node].L) >= min(R, t[node].R)) return -1e9; n   if (L <= t[node].L && t[node].R <= R) return t[node].maxk; n   return max(getMax(t[node].left, L, R), getMax(t[node].right, L, R)); n } n void setMax(int node, int i, int x) { n   if (i >= t[node].R || i < t[node].L) return; n   if (i == t[node].L && i + 1 == t[node].R) { n     t[node].maxk = x; n     return; n   } n   setMax(t[node].left, i, x); n   setMax(t[node].right, i, x); n   t[node].maxk = max(t[t[node].left].maxk, t[t[node].right].maxk); n } n bool buildAns(int l, int r) { n   if (anyf[l] > r) return false; n   for (int x : rgt[l]) { n     if (x <= leftf[l]) return false; n   } n   if (leftf[l] == l) { n     lc[l] = -1; n     if (r == l) return true; n     rc[l] = l + 1; n     return buildAns(l + 1, r); n   } n   lc[l] = l + 1; n   if (!buildAns(lc[l], leftf[l])) return false; n   if (leftf[l] == r) return true; n   rc[l] = leftf[l] + 1; n   return buildAns(rc[l], r); n } n void print(int v) { n   if (v == -1) return; n   print(lc[v]); n   printf( %d  , v + 1); n   print(rc[v]); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.precision(10); n   cout << fixed; n   int N, C; n   scanf( %d%d , &N, &C); n   bool ok = true; n   int root = buildTree(0, N); n   for (int i = 0; i < (int)(C); ++i) { n     int x, y; n     scanf( %d%d%s , &x, &y, s); n     --x; n     --y; n     ok &= x < y; n     if (s[0] ==  L ) n       lft[x].push_back(y); n     else n       rgt[x].push_back(y); n   } n   if (!ok) { n     cout <<  IMPOSSIBLE n ; n     return 0; n   } n   for (int i = (int)(N)-1; i >= 0; --i) { n     leftf[i] = anyf[i] = i; n     for (int x : lft[i]) { n       uax(leftf[i], getMax(root, i, x + 1)); n     } n     for (int x : rgt[i]) { n       uax(anyf[i], getMax(root, i, x + 1)); n     } n     uax(anyf[i], leftf[i]); n     setMax(root, i, anyf[i]); n   } n   for (int i = 0; i < (int)(N); ++i) lc[i] = rc[i] = -1; n   if (!buildAns(0, N - 1)) { n     cout <<  IMPOSSIBLE n ; n     return 0; n   } n   print(0); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int cnt[15]; n string a[100009]; n const long long mod = 998244353LL; n int main() { n   int i, len1, len2, n, j; n   long long p, sum, val; n   cin >> n; n   for (i = 1; i <= n; i++) { n     cin >> a[i]; n     reverse(a[i].begin(), a[i].end()); n     cnt[a[i].size()]++; n   } n   for (i = 1, val = 0; i <= n; i++) { n     len2 = a[i].size(); n     for (len1 = 1; len1 <= 10; len1++) { n       sum = 0; n       if (len1 < len2) { n         for (j = 0, p = 1; j < len1; j++) { n           sum += p * (a[i][j] - 48); n           p = (p * 10LL) % mod; n           sum += p * (a[i][j] - 48); n           p = (p * 10LL) % mod; n         } n         for (j = len1; j < len2; j++) { n           sum += p * (a[i][j] - 48); n           sum += p * (a[i][j] - 48); n           p = (p * 10LL) % mod; n         } n       } else { n         for (j = 0, p = 1; j < len2; j++) { n           sum += p * (a[i][j] - 48); n           p = (p * 10LL) % mod; n           sum += p * (a[i][j] - 48); n           p = (p * 10LL) % mod; n         } n       } n       val += (sum % mod) * cnt[len1]; n       val %= mod; n     } n   } n   cout << val <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, size_t N> n int SIZE(const T (&t)[N]) { n   return N; n } n template <typename T> n int SIZE(const T(&t)) { n   return t.size(); n } n string to_string(char b) { return     + string({b}) +    ; } n string to_string(bool b) { return (b ?  true  :  false ); } n string to_string(const string &t, int x1 = 0, int x2 = 1e9) { n   string ret =   ; n   for (int i = min(x1, SIZE(t)), _i = min(x2, SIZE(t) - 1); i <= _i; ++i) { n     ret += t[i]; n   } n   return     + ret +    ; n } n string to_string(const char *t) { n   string ret(t); n   return to_string(ret); n } n template <size_t N> n string to_string(const bitset<N> &t, int x1 = 0, int x2 = 1e9) { n   string ret =   ; n   for (int i = min(x1, SIZE(t)), _i = min(x2, SIZE(t) - 1); i <= _i; ++i) { n     ret += t[i] +  0 ; n   } n   return     + ret +    ; n } n template <typename T, typename... Coords> n string to_string(const T(&t), int x1 = 0, int x2 = 1e9, Coords... C); n template <typename T, typename S> n string to_string(const pair<T, S>(&t)) { n   return  (  + to_string(t.first) +  ,   + to_string(t.second) +  ) ; n } n template <typename T, typename... Coords> n string to_string(const T(&t), int x1, int x2, Coords... C) { n   string ret =  [ ; n   x1 = min(x1, SIZE(t)); n   auto e = begin(t); n   advance(e, x1); n   for (int i = x1, _i = min(x2, SIZE(t) - 1); i <= _i; ++i) { n     ret += (i != x1 ?  ,   :   ) + to_string(*e, C...); n     e = next(e); n   } n   return ret +  ] ; n } n void dbgm() { ; } n template <typename T, typename... S> n void dbgm(T t, S... s) { n   cout << to_string(t) <<   |  ; n   dbgm(s...); n } n void dbgs() { ; } n template <typename T, typename... S> n void dbgs(T t, S... s) { n   cout << t <<    ; n   dbgs(s...); n } n const long long N = 2e5 + 3, M = 1e9 + 7; n int v[N], h[N]; n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 1, _i = n; i <= _i; ++i) { n     int x; n     cin >> x; n     v[i] = x; n   } n   sort(v + 1, v + 1 + n); n   int pt = 0, hans = 0; n   for (int i = 1, _i = m; i <= _i; ++i) { n     int x1, x2, y; n     cin >> x1 >> x2 >> y; n     if (x1 == 1) { n       if (x2 == 1e9) { n         hans++; n       } else { n         h[++pt] = x2; n       } n     } n   } n   m = pt; n   sort(h + 1, h + 1 + m, greater<int>()); n   int j = n; n   int ans = 1e9; n   for (int i = 1, _i = m + 1; i <= _i; ++i) { n     while (v[j] > h[i]) { n       --j; n     } n     ans = min(ans, j + max(i - 1, 0)); n   } n   dbgs(ans + hans); n } n


#include <bits/stdc++.h> n using namespace std; n ifstream fin( fisier.in ); n ofstream fout( fisier.out ); n int v[1000000], minl[1000000], minr[1000000]; n int main() { n   int n, i; n   cin >> n; n   for (i = 1; i <= n; ++i) cin >> v[i]; n   for (i = 1; i <= n; ++i) minl[i] = min(minl[i - 1] + 1, v[i]); n   for (i = n; i >= 1; --i) minr[i] = min(minr[i + 1] + 1, v[i]); n   int res = 0; n   for (i = 1; i <= n; ++i) res = max(res, min(minr[i], minl[i])); n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long dx[] = {1, 0, -1, 0}; n long long dy[] = {0, 1, 0, -1}; n long long gcd(long long x, long long y) { n   if (y == 0) n     return x; n   else n     return gcd(y, x % y); n } n long long expo(long long n, long long m, long long p) { n   long long r = 1; n   n = n % p; n   while (m > 0) { n     if (m % 2) r = (r * n) % p; n     n = (n * n) % p; n     m = m / 2; n   } n   return r % p; n } n bool isPrime(long long n) { n   if (n <= 1) return false; n   if (n <= 3) return true; n   if (n % 2 == 0 || n % 3 == 0) return false; n   for (long long i = 5; i * i <= n; i = i + 6) n     if (n % i == 0 || n % (i + 2) == 0) return false; n   return true; n } n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long t; n   cin >> t; n   long long tc = 1; n   while (t--) { n     long long n; n     cin >> n; n     if (n == 1) { n       cout <<  1337  <<   n ; n     } else if (n == 2) { n       cout <<  11337  <<   n ; n     } else if (n == 3) { n       cout <<  111337  <<   n ; n     } else { n       long long m; n       for (long long i = 1; i <= n; i++) { n         long long x = (i * (i - 1)) / 2; n         if (x > n) { n           m = i - 1; n           break; n         } n       } n       long long r = n - (m * (m - 1)) / 2; n       string ans; n       ans.push_back( 1 ); n       ans.push_back( 3 ); n       ans.push_back( 3 ); n       while (r) { n         ans.push_back( 7 ); n         r--; n       } n       m -= 2; n       while (m) { n         ans.push_back( 3 ); n         m--; n       } n       ans.push_back( 7 ); n       cout << ans <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, x, y, z, k, w, ans; n int A[400], B[400]; n char c[2]; n int main() { n   scanf( %d , &n); n   for (int i = (0); i < (n); i++) { n     scanf( %s%d%d , &c, &x, &y); n     if (c[0] ==  M ) { n       for (int j = (x); j <= (y); j++) A[j]++; n     } else { n       for (int j = (x); j <= (y); j++) B[j]++; n     } n   } n   for (int i = (1); i <= (366); i++) ans = max(ans, min(A[i], B[i])); n   printf( %d n , ans * 2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = (int)1e9; n struct edge { n   int u, v; n   int flow; n   int cost; n   edge() {} n   edge(int u, int v, int f, int c) : u(u), v(v), flow(f), cost(c) {} n }; n struct MinCostMaxFlow { n   int N; n   vector<vector<int> > G; n   vector<edge> E; n   int numEdges; n   vector<int> found, dad; n   vector<int> dist; n   MinCostMaxFlow(int N) : N(N), G(N), found(N), dist(N), dad(N), numEdges(0) {} n   void addEdge(int from, int to, int capacity, int cost) { n     G[from].push_back(numEdges++); n     E.push_back(edge(from, to, capacity, cost)); n     G[to].push_back(numEdges++); n     E.push_back(edge(to, from, 0, int(-1) * cost)); n   } n   bool spfa(int s, int t) { n     fill(dad.begin(), dad.end(), -1); n     fill(dist.begin(), dist.end(), INF); n     fill(found.begin(), found.end(), 0); n     queue<int> Q; n     dist[s] = 0; n     Q.push(s); n     found[s] = true; n     while (!Q.empty()) { n       int u = Q.front(); n       Q.pop(); n       if (u == t) continue; n       for (int i = 0; i < G[u].size(); ++i) { n         edge &pres = E[G[u][i]]; n         int v = pres.v; n         if (pres.flow <= 0) continue; n         if (dist[u] + pres.cost < dist[v]) { n           dad[v] = G[u][i]; n           dist[v] = dist[u] + pres.cost; n           if (!found[v]) Q.push(v), found[v] = true; n         } n       } n       found[u] = false; n     } n     return (dad[t] != -1); n   } n   int dfs(int s, int t) { n     int flow = INF; n     for (int i = dad[t]; i != -1; i = dad[E[i].u]) { n       if (E[i].flow < flow) flow = E[i].flow; n     } n     for (int i = dad[t]; i != -1; i = dad[E[i].u]) { n       E[i].flow -= flow; n       E[i ^ 1].flow += flow; n     } n     return flow; n   } n   pair<int, int> getMaxFlow(int s, int t) { n     int totflow = 0; n     int totcost = 0; n     while (spfa(s, t)) { n       int amt = dfs(s, t); n       totflow += amt; n       totcost += dist[t] * (int)amt; n     } n     return make_pair(totflow, totcost); n   } n }; n int main() { n   int n, m; n   cin >> n >> m; n   vector<int> a(n); n   for (int i = 0; i < n; ++i) cin >> a[i]; n   MinCostMaxFlow mcmf(n * 2 + m + 2); n   for (int i = 0; i < n; ++i) { n     for (int j = i + 1; j < n; ++j) { n       mcmf.addEdge(i + 1, j + n + 1 + m, 1, n                    (a[i] == a[j] ? 0 : __builtin_popcount(a[j]))); n     } n   } n   for (int i = 0; i < m; ++i) { n     for (int j = 0; j < n; ++j) { n       mcmf.addEdge(i + n + 1, j + n + m + 1, 1, __builtin_popcount(a[j])); n     } n     mcmf.addEdge(0, i + n + 1, 1, 0); n   } n   for (int i = 0; i < n; ++i) { n     mcmf.addEdge(0, i + 1, 1, 0); n     mcmf.addEdge(i + n + m + 1, n + m + n + 1, 1, 0); n   } n   pair<int, int> ret = mcmf.getMaxFlow(0, n + n + m + 1); n   vector<int> who(n); n   for (int i = 1; i <= n + m; ++i) { n     for (int c : mcmf.G[i]) { n       edge e = mcmf.E[c]; n       if (e.flow == 0 && e.v != 0) { n         who[e.v - n - m - 1] = i - 1; n         assert(e.u == i); n       } n     } n   } n   vector<int> last(n, -1); n   vector<string> fans; n   for (int i = 0; i < n; ++i) { n     int f = who[i]; n     if (f >= n) { n       stringstream ss; n       ss << (char)(f - n +  a ) <<  =  << a[i] <<    ; n       ss <<  print(  << (char)(f - n +  a ) <<  ) ; n       string tmp; n       ss >> tmp; n       fans.push_back(tmp); n       ss >> tmp; n       fans.push_back(tmp); n       last[i] = f - n; n     } else { n       if (a[who[i]] == a[i]) { n         stringstream ss; n         ss <<  print(  << (char)(last[who[i]] +  a ) <<  ) ; n         string tmp; n         ss >> tmp; n         fans.push_back(tmp); n       } else { n         stringstream ss; n         ss << (char)(last[who[i]] +  a ) <<  =  << a[i] <<    ; n         ss <<  print(  << (char)(last[who[i]] +  a ) <<  ) ; n         string tmp; n         ss >> tmp; n         fans.push_back(tmp); n         ss >> tmp; n         fans.push_back(tmp); n       } n       last[i] = last[who[i]]; n     } n   } n   cout << fans.size() <<     << ret.second <<   n ; n   for (string t : fans) cout << t <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int l, r; n   cin >> l >> r; n   if (l == r) { n     cout << l; n     return 0; n   } n   cout <<  2  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const double EPS = 1e-10; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int ax, ay, bx, by, cx, cy; n   cin >> ax >> ay >> bx >> by >> cx >> cy; n   complex<long double> a(ax, ay), b(bx, by), c(cx, cy); n   long double d1 = abs(b - a), d2 = abs(c - b); n   long double ang1 = arg(b - a), ang2 = arg(c - b); n   cout << ((abs(d1 - d2) < EPS && abs(ang1 - ang2) > EPS) ?  Yes  :  No ) n        << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long a, b, c; n   cin >> a >> b >> c; n   cout << (a / c + (a % c != 0)) * (b / c + (b % c != 0)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline void upmin(T &x, T y) { n   y < x ? x = y : 0; n } n template <typename T> n inline void upmax(T &x, T y) { n   x < y ? x = y : 0; n } n const long double pi = acos(-1); n const int oo = 1 << 30; n const long long OO = 1e18; n const int N = 1e5 + 100; n int gi() { n   int w = 0; n   bool q = 1; n   char c = getchar(); n   while ((c <  0  || c >  9 ) && c !=  - ) c = getchar(); n   if (c ==  - ) q = 0, c = getchar(); n   while (c >=  0  && c <=  9 ) w = w * 10 + c -  0 , c = getchar(); n   return q ? w : -w; n } n int w[N]; n int p[N]; n inline int phi(int n) { n   int ans = n; n   for (int i = 2; i <= n; i++) n     if (!(n % i)) { n       ans = ans / i * (i - 1); n       while (!(n % i)) n /= i; n     } n   return ans; n } n inline int mul(int x, int y, int mod) { n   return 1LL * x * y >= mod ? 1LL * x * y % mod + mod : x * y; n } n inline int qpow(int x, int y, int mod) { n   int ans = 1; n   while (y) { n     if (y & 1) ans = mul(ans, x, mod); n     x = mul(x, x, mod); n     y >>= 1; n   } n   return ans; n } n int main() { n   int n = gi(), i, Q, m, l, r, ans; n   p[0] = gi(); n   for (m = 0; p[m] != 1; p[m + 1] = phi(p[m]), m++) n     ; n   p[m + 1] = 1; n   for (i = 1; i <= n; i++) w[i] = gi(); n   Q = gi(); n   while (Q--) { n     l = gi(), r = gi(); n     ans = 1; n     for (i = min(r - l, m); ~i; i--) ans = qpow(w[i + l], ans, p[i]); n     cout << ans % p[0] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n int a[100006]; n int vis[100006]; n int visyu[100006]; n int main() { n   int n, x; n   scanf( %d%d , &n, &x); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     vis[a[i]]++; n     if (vis[a[i]] == 2) { n       printf( 0 n ); n       return 0; n     } n   } n   int mans = -1; n   for (int i = 1; i <= n; i++) { n     visyu[a[i] & x]++; n     if (visyu[a[i] & x] && vis[a[i] & x] && ((a[i] & x) != a[i])) { n       printf( 1 n ); n       return 0; n     } else if (visyu[a[i] & x] == 2) { n       mans = 2; n     } n   } n   printf( %d n , mans); n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void Read(T &cn) { n   char c; n   int sig = 1; n   while (!isdigit(c = getchar())) n     if (c ==  - ) sig = -1; n   cn = c - 48; n   while (isdigit(c = getchar())) cn = cn * 10 + c - 48; n   cn *= sig; n } n template <typename T> n void Write(T cn) { n   if (cn < 0) { n     putchar( - ); n     cn = 0 - cn; n   } n   int wei = 0; n   T cm = 0; n   int cx = cn % 10; n   cn /= 10; n   while (cn) wei++, cm = cm * 10 + cn % 10, cn /= 10; n   while (wei--) putchar(cm % 10 + 48), cm /= 10; n   putchar(cx + 48); n } n template <typename T> n void Max(T &cn, T cm) { n   cn = cn < cm ? cm : cn; n } n template <typename T> n void Min(T &cn, T cm) { n   cn = cn < cm ? cn : cm; n } n struct qwe { n   long long v, c; n   void getit() { n     Read(v); n     Read(c); n   } n   inline friend bool operator<(qwe a, qwe b) { n     return a.v == b.v ? a.c > b.c : a.v < b.v; n   } n }; n struct xian { n   long long k, b; n   long long suan(long long cn) { return (cn - b + k - 1) / k; } n   void mk(long long cn, long long cm) { n     k = cn; n     b = cm; n   } n }; n qwe a[200100 + 1]; n int n; n long long m; n int xu[200100 + 1], xlen; n long long f[200100 + 1], g[200100 + 1]; n xian zhan[200100 + 1]; n int l, r; n int jiao_z(long long cn, xian A, xian B) { n   return cn * (A.k - B.k) <= (B.b - A.b); n } n int jiao(xian A, xian B, xian C) { n   double db1 = (B.b - A.b), db2 = (C.b - B.b); n   double dk1 = (A.k - B.k), dk2 = (B.k - C.k); n   return db1 * dk2 >= db2 * dk1; n } n long long qiu(int cn, int cm) { n   while (l < r && jiao_z(zhan[l].suan(cn), zhan[l], zhan[l + 1])) l++; n   if (l > r) return -10000000000000000; n   return -zhan[l].suan(cn) * (cm - zhan[l].k) - cn + zhan[l].b; n } n void zeng(int ck, long long cb) { n   xian lin; n   lin.mk(ck, cb); n   while (l < r && jiao(zhan[r - 1], zhan[r], lin)) r--; n   zhan[++r] = lin; n } n int main() { n   Read(n); n   Read(m); n   for (int i = 1; i <= n; i++) a[i].getit(); n   sort(a + 1, a + n + 1); n   xlen = 0; n   for (int i = 1; i <= n; i++) { n     if (a[i].v <= 0) continue; n     while (xlen && a[xu[xlen]].c > a[i].c) xlen--; n     xu[++xlen] = i; n   } n   for (int i = 1; i <= xlen; i++) a[i] = a[xu[i]]; n   n = xlen; n   f[0] = 0; n   a[0].v = a[0].c = 0; n   l = 1; n   r = 0; n   f[1] = 0; n   zeng(a[1].v, f[1]); n   long long ans = (m + a[1].v - 1) / a[1].v; n   for (int i = 2; i <= n; i++) { n     f[i] = qiu(a[i].c, a[i].v); n     zeng(a[i].v, f[i]); n     Min(ans, (m - f[i] + a[i].v - 1) / a[i].v); n   } n   Write(ans); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 400010; n int c[maxn]; n int ans[maxn]; n void upd(int n, int k) { n   n++; n   while (n < maxn) c[n] += k, n += n & (-n); n } n int get(int n) { n   n++; n   int ans = 0; n   while (n) ans += c[n], n -= n & (-n); n   return ans; n } n int BS(int n) { n   int l = 0, r = maxn - 1, mid; n   while (l < r) { n     mid = (l + r) / 2; n     if (get(mid) >= n) n       r = mid; n     else n       l = mid + 1; n   } n   return l; n } n int arr[maxn]; n int a[maxn], b[maxn]; n int main() { n   int n, i, j, k; n   cin >> n; n   for (i = 0; i < n; i++) cin >> a[i]; n   for (i = 0; i < n; i++) cin >> b[i]; n   for (i = 0; i < n; i++) upd(i, 1); n   for (i = 0; i < n; i++) { n     arr[i] += get(a[i]) - 1; n     upd(a[i], -1); n   } n   for (i = 0; i < n; i++) upd(i, 1); n   for (i = 0; i < n; i++) { n     arr[i] += get(b[i]) - 1; n     upd(b[i], -1); n   } n   for (i = n - 1; i >= 0; i--) { n     if (arr[i] <= n - i - 1) n       ; n     else { n       arr[i] %= n - i; n       if (i) arr[i - 1]++; n     } n   } n   for (i = 0; i < n; i++) upd(i, 1); n   for (i = 0; i < n; i++) ans[i] = BS(arr[i] + 1), upd(ans[i], -1); n   for (i = 0; i < n; i++) cout << ans[i] <<    ; n   puts(  ); n } n