#include <bits/stdc++.h> n long long int gcd(long long int a, long long int b) { n   return (a ? gcd(b % a, a) : b); n } n inline int two(int n) { return 1 << n; } n inline int test(int n, int b) { return (n >> b) & 1; } n inline void set_bit(int& n, int b) { n |= two(b); } n inline void unset_bit(int& n, int b) { n &= ~two(b); } n inline int last_bit(int n) { return n & (-n); } n inline int ones(int n) { n   int res = 0; n   while (n && ++res) n -= n & (-n); n   return res; n } n long long int modPow(long long int a, long long int b, long long int MOD) { n   long long int x = 1, y = a; n   while (b > 0) { n     if (b % 2 == 1) { n       x = (x * y) % MOD; n     } n     b /= 2; n     y = (y * y) % MOD; n   } n   return x; n } n long long int modInverse(long long int a, long long int p) { n   return modPow(a, p - 2, p); n } n using namespace std; n int main() { n   int n, k, i, from, to; n   long long int crossed_count, ans; n   crossed_count = 0; n   ans = 1; n   scanf( %d , &n); n   scanf( %d , &k); n   k = min(k, n - k); n   from = 0; n   for (int i = (1); i <= (n); i++) { n     to = (from + k) % n; n     if (to < from && to != 0) crossed_count++; n     ans += crossed_count + 1; n     if (to < from) crossed_count++; n     printf( %lld  , ans); n     from = to; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200010; n long long a[N], b[N], p[N], money; n int top, n, m, ans, st[N]; n vector<long long> v[N]; n priority_queue<long long> q; n void get_sale_day() { n   for (int i = 1; i <= n; ++i) { n     while (top && a[i] >= a[st[top]]) --top; n     st[++top] = i; n   } n   for (int i = 1; i <= m; ++i) { n     if (b[i] > a[st[1]]) continue; n     int l = 1, r = top, ans = 0; n     while (l <= r) { n       int mid = (l + r) >> 1; n       if (a[st[mid]] >= b[i]) n         ans = mid, l = mid + 1; n       else n         r = mid - 1; n     } n     v[st[ans]].push_back(p[i]); n   } n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; ++i) scanf( %lld , &a[i]); n   for (int i = 1; i <= m; ++i) scanf( %lld , &b[i]); n   for (int i = 1; i <= m; ++i) scanf( %lld , &p[i]); n   get_sale_day(); n   for (int i = 1; i <= n; ++i) { n     money += a[i]; n     sort(v[i].begin(), v[i].end()); n     for (int j = 0; j < v[i].size(); ++j) n       if (v[i][j] <= money) { n         money -= v[i][j]; n         q.push(v[i][j]); n         ans++; n       } else { n         if (q.empty()) continue; n         long long tmp = q.top(); n         if (tmp > v[i][j]) { n           q.pop(); n           q.push(v[i][j]); n           money += tmp - v[i][j]; n         } n       } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1000000007; n const int Maxn = 500005; n map<long long, int> mp; n vector<pair<int, int> > g[Maxn]; n long long c[Maxn]; n int pw2[Maxn] = {1}, par[Maxn], n, m, k, sz, ans; n int find(int u) { return par[u] == u ? u : par[u] = find(par[u]); } n int main() { n   scanf( %d%d%d , &n, &m, &k); n   for (int i = 1; i <= n; i++) pw2[i] = pw2[i - 1] * 2 % mod; n   for (int i = 1; i <= n; i++) scanf( %lld , &c[i]); n   for (int i = 1; i <= n; i++) par[i] = i; n   for (int x, y; m--;) { n     scanf( %d%d , &x, &y); n     if (!mp[c[x] ^ c[y]]) mp[c[x] ^ c[y]] = ++sz; n     g[mp[c[x] ^ c[y]]].push_back(make_pair(x, y)); n   } n   for (int i = 1; i <= sz; ++i) { n     int s = n; n     for (int j = 0; j < g[i].size(); j++) { n       int x = find(g[i][j].first), y = find(g[i][j].second); n       if (x ^ y) par[x] = y, s--; n     } n     ans = (ans + pw2[s]) % mod; n     for (int j = 0; j < g[i].size(); j++) n       par[g[i][j].first] = g[i][j].first, par[g[i][j].second] = g[i][j].second; n   } n   ans = (ans + (long long)((1ll << k) - sz + mod) % mod * pw2[n] % mod) % mod; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n std::vector<int> dsc[100005]; n int st[5005], fi[5005], vt[5005], nx[5005], mx[5005]; n int a[100005]; n double prob[5005]; n double f[5005][5005 + 5]; n void sx(int l, int r) { n   if (l >= r) return; n   int i = l, j = r; n   int chot = vt[l + rand() % (r - l + 1)]; n   int chot2 = fi[chot]; n   chot = st[chot]; n   while (i <= j) { n     while (st[vt[i]] < chot || (st[vt[i]] == chot && fi[vt[i]] > chot2)) i++; n     while (st[vt[j]] > chot || (st[vt[j]] == chot && fi[vt[j]] < chot2)) j--; n     if (i <= j) { n       if (i < j) { n         int tg = vt[i]; n         vt[i] = vt[j]; n         vt[j] = tg; n       } n       i++; n       j--; n     } n   } n   sx(i, r); n   sx(l, j); n } n void duyet(int ii) { n   int sz = dsc[ii].size(); n   mx[ii] = 0; n   if (sz == 0) { n     for (int i = st[ii]; i <= fi[ii]; i++) n       if (mx[ii] < a[i]) mx[ii] = a[i]; n   } else { n     for (int i = st[ii]; i < st[dsc[ii][0]]; i++) n       if (mx[ii] < a[i]) mx[ii] = a[i]; n     for (int j = 0; j < sz - 1; j++) { n       for (int i = fi[dsc[ii][j]] + 1; i < st[dsc[ii][j + 1]]; i++) n         if (mx[ii] < a[i]) mx[ii] = a[i]; n     } n     for (int i = fi[dsc[ii][sz - 1]] + 1; i <= fi[ii]; i++) n       if (mx[ii] < a[i]) mx[ii] = a[i]; n   } n   for (int i = 0; i < sz; i++) { n     duyet(dsc[ii][i]); n     if (mx[dsc[ii][i]] > mx[ii]) mx[ii] = mx[dsc[ii][i]]; n   } n   if (sz == 0) { n     f[ii][0] = 1 - prob[ii]; n     for (int j = 1; j < 5005; j++) f[ii][j] = 1.0; n   } else { n     double f1, f2; n     for (int j = 0; j < 5005; j++) { n       f1 = f2 = 1.0; n       for (int i = 0; i < sz; i++) { n         int tmp = mx[ii] - mx[dsc[ii][i]] + j; n         if (tmp >= 5005) tmp = 5005 - 1; n         f1 *= f[dsc[ii][i]][tmp]; n         tmp = mx[ii] - mx[dsc[ii][i]] + j - 1; n         if (tmp >= 5005) tmp = 5005 - 1; n         if (tmp < 0) n           f2 = 0; n         else n           f2 *= f[dsc[ii][i]][tmp]; n       } n       if (j > 0) n         f[ii][j] = (1 - prob[ii]) * f1 + prob[ii] * f2; n       else n         f[ii][j] = (1 - prob[ii]) * f1; n     } n   } n } n int main() { n   int n, q; n   scanf( %d%d , &n, &q); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (int i = 1; i <= q; i++) { n     scanf( %d%d%lf , &st[i], &fi[i], &prob[i]); n     vt[i] = i; n   } n   srand(time(NULL)); n   sx(1, q); n   q++; n   st[0] = 1; n   fi[0] = n; n   prob[0] = 0; n   vt[0] = 0; n   nx[0] = 0; n   int topNX = 0; n   for (int i = 1; i <= n; i++) dsc[i].clear(); n   for (int i = 1; i < q; i++) { n     while (fi[vt[nx[topNX]]] < fi[vt[i]]) topNX--; n     dsc[vt[nx[topNX]]].push_back(vt[i]); n     nx[++topNX] = i; n   } n   duyet(0); n   double res = 0.0; n   for (int j = 0; j < 5005; j++) { n     double pp = f[0][j]; n     if (j > 0) pp -= f[0][j - 1]; n     res += pp * (mx[0] + j); n   } n   printf( %.10lf , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxv = 2045; n const long long mod = 1e9 + 7; n const int maxn = 1e6 + 40; n long long fac[maxn], inv[maxn]; n long long qpow(long long a, long long p) { n   long long ans = 1; n   long long xx = a; n   while (p > 0) { n     if (p & 1) ans = (xx * ans) % mod; n     xx = (xx * xx) % mod; n     p >>= 1; n   } n   return ans; n } n void init() { n   fac[0] = 1; n   inv[0] = 1; n   for (long long i = 1; i < maxn; i++) { n     fac[i] = (fac[i - 1] * i) % mod; n     inv[i] = inv[i - 1] * qpow(i, mod - 2) % mod; n   } n } n int h, w, n; n pair<long long, long long> a[maxv]; n long long dp[maxv]; n long long culC(long long a, long long b) { n   return fac[a] * inv[a - b] % mod * inv[b] % mod; n } n long long path(long long sx, long long sy, long long tx, long long ty) { n   return culC(ty - sy + tx - sx, tx - sx); n } n void solve() { n   for (int i = 0; i <= n; i++) { n     long long ans = 0; n     for (int j = 0; j < i; j++) { n       if (a[j].second <= a[i].second) n         ans += path(a[j].first, a[j].second, a[i].first, a[i].second) * dp[j] % n                mod, n             ans %= mod; n     } n     dp[i] = (path(1, 1, a[i].first, a[i].second) - ans) % mod + mod, n     dp[i] %= mod; n   } n } n int main() { n   init(); n   cin >> h >> w >> n; n   for (int i = 0; i < n; i++) { n     int c, r; n     scanf( %d%d , &r, &c); n     a[i].first = r; n     a[i].second = c; n   } n   sort(a, a + n); n   a[n] = pair<long long, long long>(h, w); n   solve(); n   cout << dp[n] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, md, len, i, j, k, prv, c[505][505], dpf[505][505], dpr[505][505]; n long long cur, crst, f[505], rst[505]; n long long sum(long long x) { return (x * (x + 1LL)) / 2; } n int main() { n   scanf( %d%d%d , &n, &m, &md); n   for (i = 0; i <= n; i++) { n     c[i][0] = 1; n     for (j = 1; j <= i; j++) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % md; n   } n   for (i = 0; i < n; i++) n     for (k = 0; k <= i; k++) { n       cur = c[i][k]; n       crst = 0; n       if (k > 0) { n         crst = (crst * f[k - 1] + cur * rst[k - 1]) % md; n         cur = (cur * f[k - 1]) % md; n       } n       if (k < i) { n         crst = (crst * f[i - k - 1] + cur * rst[i - k - 1]) % md; n         cur = (cur * f[i - k - 1]) % md; n       } n       rst[i] = (rst[i] + crst * (i + 2LL) + cur * (sum(k) + sum(i - k))) % md; n       f[i] = (f[i] + (i + 2LL) * cur) % md; n     } n   dpf[0][0] = 1; n   for (i = 1; i <= n; i++) n     for (j = 0; j <= i && j <= m; j++) { n       dpf[i][j] = dpf[i - 1][j]; n       dpr[i][j] = dpr[i - 1][j]; n       for (k = 1; k <= j; k++) { n         prv = i - k; n         if (prv > 0) --prv; n         if (j - k <= prv) { n           dpr[i][j] = (dpr[i][j] + c[j][k] * ((dpr[prv][j - k] * f[k - 1] + n                                                dpf[prv][j - k] * rst[k - 1]) % n                                               md)) % n                       md; n           dpf[i][j] = n               (dpf[i][j] + c[j][k] * ((dpf[prv][j - k] * f[k - 1]) % md)) % md; n         } n       } n     } n   printf( %d n , dpr[n][m]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n constexpr long long int MOD = 1000000007; n constexpr double EPS = 1e-8; n long long int N, M, K, H, W, L, R; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> N; n   vector<int> v(N); n   for (auto &i : v) cin >> i >> i; n   cin >> K; n   for (int i = 0; i < N; i++) { n     if (v[i] >= K) { n       cout << N - i << endl; n       break; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n long long dx[] = {-1, 0, 1, 0}; n long long dy[] = {0, -1, 0, 1}; n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long b, q, l, m; n   cin >> b >> q >> l >> m; n   if (abs(b) > l) { n     cout << 0 <<   n ; n     return 0; n   } n   set<long long> st; n   for (long long i = 0; i < m; i++) { n     long long x; n     cin >> x; n     st.insert(x); n   } n   if (b == 0 || q == 0) { n     if (0 <= l && st.find(0) == st.end()) { n       cout <<  inf n ; n       return 0; n     } else if (abs(b) <= l && st.find(b) == st.end()) { n       cout << 1 <<   n ; n       return 0; n     } else n       cout << 0; n     return 0; n   } n   if (q == 1) { n     if (abs(b) <= l && st.find(b) == st.end()) { n       cout <<  inf n ; n     } else n       cout << 0 <<   n ; n     return 0; n   } else if (q == -1) { n     if (abs(b) <= l && (st.find(b) == st.end() || st.find(-b) == st.end())) { n       cout <<  inf n ; n     } else n       cout << 0 <<   n ; n     return 0; n   } n   vector<long long> v; n   while (abs(b) <= l) { n     if (st.find(b) == st.end()) v.push_back(b); n     b = b * q; n   } n   cout << v.size() <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int k, i; n   cin >> k; n   int a[12]; n   for (i = 0; i < 12; i++) cin >> a[i]; n   sort(a, a + 12); n   int sum = 0, c = 0; n   while (sum < k && i > 0) { n     i--; n     sum = sum + a[i]; n     c++; n   } n   if (sum >= k) n     cout << c; n   else n     cout <<  -1 ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int m; n vector<string> users; n vector<string> msgs; n vector<string> owners(101); n map<string, int> mp; n bool vis[1001][1001]; n int mem[1001][1001]; n void printResults() { n   for (int i = 0; i < msgs.size(); i++) { n     cout << owners[i] << msgs[i].substr(msgs[i].find( : )) << endl; n   } n } n int getSender(string message) { n   if (message[0] ==  ? ) return -1; n   string s =   ; n   for (int i = 0; i < message.size(); i++) { n     if (message[i] ==  : ) break; n     s += message[i]; n   } n   if (mp.find(s) == mp.end()) return -1; n   return mp[s]; n } n int findUser(int u, int ms) { n   if (mem[u][ms] != -1) return mem[u][ms]; n   string message = msgs[ms]; n   string user = users[u]; n   for (int i = 0; i < message.size(); i++) { n     if (i + user.size() - 1 >= message.size()) break; n     int cnt = 0; n     for (int j = 0; j < user.size(); j++) { n       if (message[i + j] == user[j]) n         cnt++; n       else n         break; n     } n     if (cnt == user.size()) { n       if ((i - 1 >= 0) && !(message[i - 1] ==     || message[i - 1] ==  !  || n                             message[i - 1] ==  .  || message[i - 1] ==  ?  || n                             message[i - 1] ==  ,  || message[i - 1] ==  : )) n         continue; n       if ((i + user.size()) < message.size() && n           !(message[i + user.size()] ==     || n             message[i + user.size()] ==  !  || n             message[i + user.size()] ==  .  || n             message[i + user.size()] ==  ?  || n             message[i + user.size()] ==  ,  || message[i + user.size()] ==  : )) n         continue; n       return (mem[u][ms] = 1); n     } n   } n   return (mem[u][ms] = 0); n } n bool solve(int i, int j) { n   if (i >= m) { n     printResults(); n     return true; n   } n   if (vis[i][j]) return false; n   vis[i][j] = true; n   int sender = getSender(msgs[i]); n   if (sender != -1 && sender == j) n     return false; n   else if (sender != -1) { n     owners[i] = users[sender]; n     return solve(i + 1, sender); n   } n   for (int a = 0; a < users.size(); a++) { n     if (!findUser(a, i) && a != j) { n       owners[i] = users[a]; n       if (solve(i + 1, a)) return true; n     } n   } n   return false; n } n int main() { n   cin.sync_with_stdio(); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     users.clear(); n     msgs.clear(); n     mp.clear(); n     memset(vis, 0, sizeof vis); n     memset(mem, -1, sizeof mem); n     int t; n     cin >> t; n     string s; n     for (int j = 0; j < t; j++) { n       cin >> s; n       users.push_back(s); n       mp[s] = j; n     } n     cin >> m; n     for (int j = 0; j < m + 1; j++) { n       string s; n       getline(cin, s); n       msgs.push_back(s); n     } n     if (msgs[0].size() == 0) msgs.erase(msgs.begin()); n     int sender = getSender(msgs[0]); n     if (sender != -1) { n       owners[0] = users[sender]; n       if (!solve(1, sender)) cout <<  Impossible  << endl; n     } else { n       bool flag = false; n       for (int j = 0; j < users.size(); j++) { n         if (!findUser(j, 0)) { n           owners[0] = users[j]; n           if (solve(1, j)) { n             flag = true; n             break; n           } n         } n       } n       if (!flag) cout <<  Impossible  << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int to, nxt, v; n } e[1000005]; n queue<int> que; n int n, m, head[1000005], cnt, l, r, vis[1000005], pre[1000005], tot; n int sum, ans[1000005], ppp, minn = 1023456789, dfn[1000005], id[1000005]; n inline void add(int from, int to, int v) { n   e[++cnt].nxt = head[from]; n   head[from] = cnt; n   e[cnt].to = to; n   e[cnt].v = v; n } n inline int dfs(int p, int val, int fa) { n   pre[p] = tot; n   vis[p] = 1; n   for (int i = head[p]; i; i = e[i].nxt) { n     if (e[i].v > val) { n       if (pre[e[i].to] == tot && !vis[e[i].to]) { n         continue; n       } n       if ((pre[e[i].to] == tot && vis[e[i].to]) || dfs(e[i].to, val, fa)) n         return 1; n     } n   } n   vis[p] = 0; n   return 0; n } n inline void work(int val) { n   for (int i = 1; i <= m; i++) n     if (e[i].v > val) dfn[e[i].to]++; n   for (int i = 1; i <= n; i++) n     if (!dfn[i]) que.push(i); n   while (!que.empty()) { n     int u = que.front(); n     que.pop(); n     id[u] = ++sum; n     for (int i = head[u]; i; i = e[i].nxt) { n       if (e[i].v > val) { n         dfn[e[i].to]--; n         if (!dfn[e[i].to]) que.push(e[i].to); n       } n     } n   } n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; i++) { n     int x, y, z; n     scanf( %d%d%d , &x, &y, &z); n     add(x, y, z); n     r = max(r, z); n   } n   l = 0; n   int fl; n   while (l < r) { n     fl = 0; n     tot++; n     sum = 0; n     int mid = (l + r) >> 1; n     for (int i = 1; i <= n; i++) { n       if (pre[i] != tot && dfs(i, mid, i)) { n         fl = 1; n         break; n       } n     } n     if (!fl) { n       r = mid; n     } else { n       l = mid + 1; n     } n   } n   printf( %d  , r); n   sum = 0; n   work(r); n   for (int i = 1; i <= n; i++) { n     for (int j = head[i]; j; j = e[j].nxt) { n       if (e[j].v <= r) { n         if (id[e[j].to] < id[i]) { n           ans[++ppp] = j; n         } n       } n     } n   } n   printf( %d n , ppp); n   sort(ans + 1, ans + ppp + 1); n   for (int i = 1; i <= ppp; i++) printf( %d  , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void exec() { n   int n, k; n   cin >> n >> k; n   map<int, int> es; n   for (int i = 1; i <= k + 1; i++) { n     string query =  ? ; n     for (int j = 1; j <= k + 1; j++) { n       if (j == i) { n         continue; n       } n       query +=     + to_string(j); n     } n     cout << query << endl; n     int pos, a; n     cin >> pos >> a; n     es[a] += 1; n   } n   int mmax = -1; n   int m = 0; n   for (auto i = es.begin(); i != es.end(); ++i) { n     if (mmax < i->first) { n       mmax = i->first; n       m = i->second; n     } n   } n   cout.flush(); n   cout << ( !   + to_string(m)) << endl; n } n void solve() { n   int t = 1; n   for (int i = 0; i < t; i++) { n     exec(); n   } n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string to_string(string s) { return     + s +    ; } n string to_string(const char *s) { return to_string((string)s); } n string to_string(bool b) { return (b ?  true  :  false ); } n template <typename A, typename B> n string to_string(pair<A, B> p) { n   return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ; n } n template <typename A> n string to_string(A v) { n   bool first = true; n   string res =  { ; n   for (const auto &x : v) { n     if (!first) { n       res +=  ,  ; n     } n     first = false; n     res += to_string(x); n   } n   res +=  } ; n   return res; n } n void debug_out() { cerr << endl; } n template <typename Head, typename... Tail> n void debug_out(Head H, Tail... T) { n   cerr <<     << to_string(H); n   debug_out(T...); n } n const int md = (int)1e9 + 7; n inline void add(int &a, int b) { n   a += b; n   if (a >= md) a -= md; n } n inline void sub(int &a, int b) { n   a -= b; n   if (a < 0) a += md; n } n inline int mul(int a, int b) { n   return (int)((long long)a * b % md); n   unsigned long long x = (long long)a * b; n   unsigned xh = (unsigned)(x >> 32), xl = (unsigned)x, d, m; n   asm( divl %4;  n t  :  =a (d),  =d (m) :  d (xh),  a (xl),  r (md)); n   return m; n } n inline int power(int a, long long b) { n   int res = 1; n   while (b > 0) { n     if (b & 1) { n       res = mul(res, a); n     } n     a = mul(a, a); n     b >>= 1; n   } n   return res; n } n inline int inv(int a) { n   a %= md; n   if (a < 0) a += md; n   int b = md, u = 0, v = 1; n   while (a) { n     int t = b / a; n     b -= t * a; n     swap(a, b); n     u -= t * v; n     swap(u, v); n   } n   assert(b == 1); n   if (u < 0) u += md; n   return u; n } n template <typename T> n class graph { n  public: n   struct edge { n     int from; n     int to; n     T cost; n   }; n   vector<edge> edges; n   vector<vector<int>> g; n   int n; n   function<bool(int)> ignore; n   graph(int _n) : n(_n) { n     g.resize(n); n     ignore = nullptr; n   } n   virtual int add(int from, int to, T cost) = 0; n   virtual void set_ignore_edge_rule(const function<bool(int)> &f) { n     ignore = f; n   } n   virtual void reset_ignore_edge_rule() { ignore = nullptr; } n }; n template <typename T> n class forest : public graph<T> { n  public: n   using graph<T>::edges; n   using graph<T>::g; n   using graph<T>::n; n   forest(int _n) : graph<T>(_n) {} n   int add(int from, int to, T cost = 1) { n     assert(0 <= from && from < n && 0 <= to && to < n); n     int id = (int)edges.size(); n     assert(id < n - 1); n     g[from].push_back(id); n     g[to].push_back(id); n     edges.push_back({from, to, cost}); n     return id; n   } n }; n template <typename T> n class dfs_forest : public forest<T> { n  public: n   using forest<T>::edges; n   using forest<T>::g; n   using forest<T>::n; n   using forest<T>::ignore; n   vector<int> pv; n   vector<int> pe; n   vector<int> order; n   vector<int> pos; n   vector<int> end; n   vector<int> sz; n   vector<int> root; n   vector<int> depth; n   vector<T> dist; n   dfs_forest(int _n) : forest<T>(_n) {} n   void init() { n     pv = vector<int>(n, -1); n     pe = vector<int>(n, -1); n     order.clear(); n     pos = vector<int>(n, -1); n     end = vector<int>(n, -1); n     sz = vector<int>(n, 0); n     root = vector<int>(n, -1); n     depth = vector<int>(n, -1); n     dist = vector<T>(n); n   } n   void clear() { n     pv.clear(); n     pe.clear(); n     order.clear(); n     pos.clear(); n     end.clear(); n     sz.clear(); n     root.clear(); n     depth.clear(); n     dist.clear(); n   } n  n  private: n   void do_dfs(int v) { n     pos[v] = (int)order.size(); n     order.push_back(v); n     sz[v] = 1; n     for (int id : g[v]) { n       if (id == pe[v] || (ignore != nullptr && ignore(id))) { n         continue; n       } n       auto &e = edges[id]; n       int to = e.from ^ e.to ^ v; n       depth[to] = depth[v] + 1; n       dist[to] = dist[v] + e.cost; n       pv[to] = v; n       pe[to] = id; n       root[to] = (root[v] != -1 ? root[v] : to); n       do_dfs(to); n       sz[v] += sz[to]; n     } n     end[v] = (int)order.size() - 1; n   } n   void do_dfs_from(int v) { n     depth[v] = 0; n     dist[v] = T{}; n     root[v] = v; n     pv[v] = pe[v] = -1; n     do_dfs(v); n   } n  n  public: n   void dfs(int v, bool clear_order = true) { n     if (pv.empty()) { n       init(); n     } else { n       if (clear_order) { n         order.clear(); n       } n     } n     do_dfs_from(v); n   } n   void dfs_all() { n     init(); n     for (int v = 0; v < n; v++) { n       if (depth[v] == -1) { n         do_dfs_from(v); n       } n     } n     assert((int)order.size() == n); n   } n }; n template <typename T> n class lca_forest : public dfs_forest<T> { n  public: n   using dfs_forest<T>::edges; n   using dfs_forest<T>::g; n   using dfs_forest<T>::n; n   using dfs_forest<T>::pv; n   using dfs_forest<T>::pos; n   using dfs_forest<T>::end; n   using dfs_forest<T>::depth; n   int h; n   vector<vector<int>> pr; n   lca_forest(int _n) : dfs_forest<T>(_n) {} n   inline void build_lca() { n     assert(!pv.empty()); n     int max_depth = 0; n     for (int i = 0; i < n; i++) { n       max_depth = max(max_depth, depth[i]); n     } n     h = 1; n     while ((1 << h) <= max_depth) { n       h++; n     } n     pr.resize(n); n     for (int i = 0; i < n; i++) { n       pr[i].resize(h); n       pr[i][0] = pv[i]; n     } n     for (int j = 1; j < h; j++) { n       for (int i = 0; i < n; i++) { n         pr[i][j] = (pr[i][j - 1] == -1 ? -1 : pr[pr[i][j - 1]][j - 1]); n       } n     } n   } n   inline bool anc(int x, int y) { n     return (pos[x] <= pos[y] && end[y] <= end[x]); n   } n   inline int lca(int x, int y) { n     assert(!pr.empty()); n     if (anc(x, y)) { n       return x; n     } n     if (anc(y, x)) { n       return y; n     } n     for (int j = h - 1; j >= 0; j--) { n       if (pr[x][j] != -1 && !anc(pr[x][j], y)) { n         x = pr[x][j]; n       } n     } n     return pr[x][0]; n   } n }; n template <typename T> n class fenwick { n  public: n   vector<T> fenw; n   int n; n   fenwick(int _n) : n(_n) { fenw.resize(n); } n   void modify(int x, T v) { n     while (x < n) { n       fenw[x] += v; n       x |= (x + 1); n     } n   } n   T get(int x) { n     T v{}; n     while (x >= 0) { n       v += fenw[x]; n       x = (x & (x + 1)) - 1; n     } n     return v; n   } n }; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   const int MAX = (int)1e7 + 10; n   vector<int> prime_div(MAX); n   for (int i = 0; i < MAX; i++) { n     prime_div[i] = i; n   } n   for (int i = 2; i * i < MAX; i++) { n     if (prime_div[i] == i) { n       for (int j = i * i; j < MAX; j += i) { n         if (prime_div[j] == j) { n           prime_div[j] = i; n         } n       } n     } n   } n   vector<int> pos(MAX); n   vector<int> primes; n   for (int i = 2; i < MAX; i++) { n     if (prime_div[i] == i) { n       pos[i] = (int)primes.size(); n       primes.push_back(i); n     } n   } n   vector<vector<pair<int, int>>> at(primes.size()); n   int n; n   cin >> n; n   lca_forest<int> g(n); n   for (int i = 0; i < n - 1; i++) { n     int x, y; n     cin >> x >> y; n     x--; n     y--; n     g.add(x, y); n   } n   g.dfs(0); n   g.build_lca(); n   for (int i = 0; i < n; i++) { n     int foo; n     cin >> foo; n     while (foo > 1) { n       int d = prime_div[foo]; n       int cc = 0; n       while (foo % d == 0) { n         foo /= d; n         cc++; n       } n       at[pos[d]].emplace_back(cc, i); n     } n   } n   int tt; n   cin >> tt; n   vector<int> u(tt), v(tt), lca(tt); n   vector<int> res(tt, 1); n   for (int i = 0; i < tt; i++) { n     int foo; n     cin >> u[i] >> v[i] >> foo; n     u[i]--; n     v[i]--; n     lca[i] = g.lca(u[i], v[i]); n     while (foo > 1) { n       int d = prime_div[foo]; n       int cc = 0; n       while (foo % d == 0) { n         foo /= d; n         cc++; n       } n       for (int j = 1; j <= cc; j++) { n         at[pos[d]].emplace_back(j, ~i); n       } n     } n   } n   fenwick<int> fenw(n); n   for (int it = 0; it < (int)primes.size(); it++) { n     if (at[it].empty()) { n       continue; n     } n     sort(at[it].rbegin(), at[it].rend()); n     for (auto &p : at[it]) { n       int id = p.second; n       if (id >= 0) { n         fenw.modify(g.pos[id], 1); n         fenw.modify(g.end[id] + 1, -1); n       } else { n         id = ~id; n         int cnt = fenw.get(g.pos[u[id]]) + fenw.get(g.pos[v[id]]) - n                   fenw.get(g.pos[lca[id]]); n         if (lca[id] != 0) { n           cnt -= fenw.get(g.pos[g.pv[lca[id]]]); n         } n         res[id] = mul(res[id], power(primes[it], cnt)); n       } n     } n     for (auto &p : at[it]) { n       int id = p.second; n       if (id >= 0) { n         fenw.modify(g.pos[id], -1); n         fenw.modify(g.end[id] + 1, +1); n       } n     } n   } n   for (int i = 0; i < tt; i++) { n     cout << res[i] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 105000; n int a[maxn], ans[maxn]; n int n, p, res1, res2; n bool judge1(int k) { n   int sum = 0; n   for (int i = 1; i <= n; i++) { n     if (a[i] <= k) n       sum++; n     else { n       int tmp = a[i] - k; n       sum -= tmp; n       if (sum < 0) return 0; n       k += tmp; n       sum++; n     } n   } n   return 1; n } n bool judge2(int k) { n   int sum = 0; n   for (int i = 1; i <= n; i++) { n     if (a[i] <= k) { n       sum++; n       if (sum >= p) return 0; n     } else { n       int tmp = a[i] - k; n       sum -= tmp; n       k += tmp; n       sum++; n     } n   } n   return 1; n } n void solve() { n   scanf( %d %d , &n, &p); n   int max_v = 0; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     max_v = max(max_v, a[i]); n   } n   sort(a + 1, a + n + 1); n   int l = 1, r = max_v; n   while (l <= r) { n     int mid = l + r >> 1; n     if (judge1(mid)) n       r = mid - 1; n     else n       l = mid + 1; n   } n   res1 = l; n   r = max_v; n   while (l <= r) { n     int mid = l + r >> 1; n     if (judge2(mid)) n       l = mid + 1; n     else n       r = mid - 1; n   } n   res2 = r; n   printf( %d n , res2 - res1 + 1); n   for (int i = res1; i <= res2; i++) printf( %d  , i); n   printf(  n ); n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int b[1100000], a[1100000], pre[1100000]; n int main() { n   int n, m, k, i, j, s, cnt, len = 0, max = 0; n   long long ans = 0; n   scanf( %d%d%d , &n, &m, &k); n   for (i = 1; i <= m; ++i) { n     scanf( %d , &s); n     b[s] = 1; n   } n   b[n] = 1; n   for (i = 1; i < n; ++i) n     if (b[i]) n       pre[i] = pre[i - 1]; n     else n       pre[i] = i; n   for (i = 1; i < n; ++i) { n     if (b[i]) n       ++len; n     else n       len = 0; n     if (len > max) max = len; n   } n   for (i = 1; i <= k; ++i) scanf( %d , &a[i]); n   if (max == 0) n     max = 1; n   else n     ++max; n   for (i = max; i <= k; ++i) { n     cnt = 0; n     j = 0; n     if (b[j]) continue; n     while (j < n) { n       ++cnt; n       if (!b[j]) n         j = j + i; n       else n         j = pre[j] + i; n     } n     if (ans == 0) n       ans = (long long)cnt * a[i]; n     else if ((long long)cnt * a[i] < ans) n       ans = (long long)cnt * a[i]; n   } n   if (ans > 0) n     printf( %I64d , ans); n   else n     printf( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   std::ios::sync_with_stdio(false); n   std::cin.tie(nullptr); n   int32_t n, m, k; n   std::cin >> n >> m >> k; n   if (n % 2 == 0) { n     std::cout <<  Marsel n ; n   } else { n     bool avail = k == 1; n     for (int32_t i = 2; i * i <= m; ++i) { n       if (m % i == 0) { n         avail |= m / i >= k; n         break; n       } n     } n     if (m >= k * 2 && avail) { n       std::cout <<  Timur n ; n     } else { n       std::cout <<  Marsel n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1 << 19; n const double PI = acos(-1); n int n, x; n int a[N]; n vector<long long> f, g, h; n long long res[N]; n int rev[N]; n void calc_rev(int n, int logn) { n   for (int i = 0; i < n; ++i) { n     rev[i] = 0; n     for (int j = 0; j < logn; ++j) n       if (i >> j & 1) { n         rev[i] |= 1 << logn - j - 1; n       } n   } n } n void fft(complex<double> a[], int n, bool invert) { n   for (int i = 0; i < n; ++i) n     if (i < rev[i]) { n       swap(a[i], a[rev[i]]); n     } n   for (int len = 2; len <= n; len <<= 1) { n     double alpha = 2 * PI / len * (invert ? -1 : 1); n     complex<double> wl = complex<double>(cos(alpha), sin(alpha)); n     for (int i = 0; i < n; i += len) { n       complex<double> w = complex<double>(1); n       for (int j = 0; j < (len >> 1); ++j) { n         complex<double> u = a[i + j], v = a[i + j + (len >> 1)] * w; n         a[i + j] = u + v; n         a[i + j + (len >> 1)] = u - v; n         w *= wl; n       } n     } n   } n   if (invert) n     for (int i = 0; i < n; ++i) a[i] /= n; n } n vector<long long> mult(vector<long long> a, vector<long long> b) { n   static complex<double> fa[N], fb[N], fc[N]; n   int na = a.size(), nb = b.size(); n   int n = 1, logn = 0; n   while (n < max(na, nb)) n <<= 1, logn++; n   n <<= 1, logn++; n   calc_rev(n, logn); n   for (int i = 0; i < n; ++i) fa[i] = fb[i] = complex<double>(0); n   for (int i = 0; i < na; ++i) fa[i] = complex<double>(a[i]); n   for (int i = 0; i < nb; ++i) fb[i] = complex<double>(b[i]); n   fft(fa, n, false); n   fft(fb, n, false); n   for (int i = 0; i < n; ++i) fc[i] = fa[i] * fb[i]; n   fft(fc, n, true); n   vector<long long> res; n   for (int i = 0; i < na + nb - 1; ++i) n     res.push_back((long long)(fc[i].real() + 0.5)); n   return res; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> x; n   f.assign(n + 1, 0), g.assign(n + 1, 0); n   f[0] = g[n] = 1; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n     a[i] = a[i - 1] + (a[i] < x); n     f[a[i]]++, g[n - a[i]]++; n   } n   h = mult(f, g); n   for (int i = 0; i <= n; ++i) res[0] += f[i] * (f[i] - 1) / 2; n   for (int i = 1; i <= n; ++i) res[i] = h[i + n]; n   for (int i = 0; i <= n; ++i) cout << res[i] <<    ; n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k, cla[30], a[200 + 5], hd[2 * 200 + 5], len = 0; n char s[30]; n struct Edge { n   int v, net; n } e[2 * 160000 + 5]; n void addi(int u, int v) { n   e[len] = (Edge){v, hd[u]}; n   hd[u] = len++; n } n void add(int u, int v) { n   addi(u, v); n   addi(v <= n ? n + v : v - n, u <= n ? n + u : u - n); n } n template <class T> n void read(T &x) { n   char ch; n   bool ok; n   for (ok = 0, ch = getchar(); !isdigit(ch); ch = getchar()) n     if (ch ==  - ) ok = 1; n   for (x = 0; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar()) n     ; n   if (ok) x = -x; n } n int col[200 + 5], col_cpy[200 + 5]; n bool dfs(int u, int ty) { n   if (col_cpy[u] != -1) return col_cpy[u] == ty; n   col_cpy[u] = ty; n   for (int i = hd[ty * n + u]; ~i; i = e[i].net) { n     int v = e[i].v; n     if (!(v > n ? dfs(v - n, 1) : dfs(v, 0))) return 0; n   } n   return 1; n } n int fl = 0, mx[2]; n bool chk(int x, int ty) { n   if (fl || ty) return 1; n   for (int i = (x), en = (n); i <= en; ++i) { n     if (col_cpy[i] == -1) { n       if (mx[!cla[a[i]]] > a[i]) return 1; n       continue; n     } n     if (mx[col_cpy[i]] > a[i]) return 1; n     if (mx[col_cpy[i]] < a[i]) return 0; n   } n   return 1; n } n bool chk(int x, int ty, int tty) { n   memcpy(col_cpy, col, sizeof col); n   if (dfs(x, ty) && chk(x + 1, tty)) { n     memcpy(col, col_cpy, sizeof col_cpy); n     return 1; n   } n   return 0; n } n int as[200 + 5]; n int main() { n   memset(hd, -1, sizeof hd); n   scanf( %s , s + 1); n   k = strlen(s + 1); n   int mn = 0; n   for (int i = (1), en = (k); i <= en; ++i) { n     cla[i] = s[i] ==  C ; n     if (cla[i] != cla[1] && !mn) mn = i; n     mx[cla[i]] = max(mx[cla[i]], i); n   } n   read(n); n   read(m); n   for (int i = (1), en = (m); i <= en; ++i) { n     int x, y, xx, yy; n     char c; n     read(x); n     cin >> c; n     y = c ==  C ; n     read(xx); n     cin >> c; n     yy = c ==  C ; n     add(x + n * y, xx + n * yy); n     if (y != yy && !mx[yy]) { n       puts( -1 ); n       return 0; n     } n   } n   memset(col, -1, sizeof col); n   for (int i = (1), en = (n); i <= en; ++i) { n     char c; n     cin >> c; n     a[i] = c -  a  + 1; n   } n   for (int i = (1), en = (n); i <= en; ++i) { n     if (fl) { n       if (chk(i, cla[1], 1)) n         as[i] = 1; n       else if (chk(i, !cla[1], 1)) n         as[i] = mn; n       else { n         puts( -1 ); n         return 0; n       } n     } else { n       int tem = 0, tem1 = 0; n       for (int j = (a[i] + 1), en = (k); j <= en; ++j) { n         if (cla[j] != cla[a[i]]) { n           if (!tem) tem = j; n         } else { n           if (!tem1) tem1 = j; n         } n       } n       if (chk(i, cla[a[i]], 0)) n         as[i] = a[i]; n       else { n         if (tem > tem1) swap(tem, tem1); n         if (tem && chk(i, cla[tem], 1)) n           as[i] = tem; n         else if (tem1 && chk(i, cla[tem1], 1)) n           as[i] = tem1; n         else { n           puts( -1 ); n           return 0; n         } n       } n     } n     fl |= as[i] > a[i]; n   } n   for (int i = (1), en = (n); i <= en; ++i) putchar( a  + as[i] - 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Exam { n   int s, d, c, id; n   bool operator<(const Exam &e1) const { return d < e1.d; } n }; n const int N = 105; n int n, m, to[N]; n Exam e[N]; n int main() { n   cin >> n >> m; n   for (int i = 1; i <= m; i++) { n     cin >> e[i].s >> e[i].d >> e[i].c; n     e[i].id = i; n     to[e[i].d] = m + 1; n   } n   sort(e + 1, e + m + 1); n   for (int i = 1; i <= m; i++) { n     int cnt = 0; n     for (int j = e[i].s; j < e[i].d; j++) { n       if (to[j] == 0) { n         to[j] = e[i].id; n         if (++cnt == e[i].c) break; n       } n     } n     if (cnt < e[i].c) { n       cout << -1 << endl; n       return 0; n     } n   } n   for (int i = 1; i <= n; i++) cout << to[i] <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const long long INFF = 0x3f3f3f3f3f3f3f3fll; n const long long M = 1e9 + 7; n const long long maxn = 5007; n const double eps = 0.00000001; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n template <typename T> n inline T abs(T a) { n   return a > 0 ? a : -a; n } n template <typename T> n inline T powMM(T a, T b) { n   T ret = 1; n   for (; b; b >>= 1ll, a = a * a % M) ret = 1ll * ret * a % M; n   return ret; n } n vector<int> edge[maxn]; n vector<long long> dp1[maxn], dp2[maxn]; n long long now1[maxn], now2[maxn]; n long long a[maxn], b[maxn], m; n int num[maxn], ans; n void dfs(int x) { n   num[x] = 1; n   dp1[x].resize(maxn, INFF); n   dp2[x].resize(maxn, INFF); n   dp1[x][1] = a[x]; n   dp1[x][0] = 0; n   dp2[x][1] = a[x] - b[x]; n   dp2[x][0] = INFF; n   int i, j; n   for (int v : edge[x]) { n     dfs(v); n     for (i = 0; i <= num[x]; i++) now1[i] = dp1[x][i], now2[i] = dp2[x][i]; n     for (i = 0; i <= num[x]; i++) n       for (j = 1; j <= num[v]; j++) { n         dp1[x][i + j] = min(dp1[x][i + j], now1[i] + dp1[v][j]); n         dp2[x][i + j] = min(dp2[x][i + j], now2[i] + min(dp1[v][j], dp2[v][j])); n       } n     vector<long long>().swap(dp1[v]); n     vector<long long>().swap(dp2[v]); n     num[x] += num[v]; n   } n } n int n; n int i, j, k; n int main() { n   scanf( %d%I64d , &n, &m); n   for (i = 1; i <= n; i++) { n     scanf( %I64d%I64d , &a[i], &b[i]); n     if (i != 1) { n       int v; n       scanf( %d , &v); n       edge[v].push_back(i); n     }; n   } n   dfs(1); n   ans = 0; n   for (i = 1; i <= n; i++) n     if (dp1[1][i] <= m || dp2[1][i] <= m) ans = max(ans, i); n   printf( %d , ans); n } n


#include <bits/stdc++.h> n const double PI = acos(-1); n using namespace std; n template <class T> n ostream& operator<<(ostream& out, vector<T> v) { n   out << v.size() <<   n ; n   for (auto e : v) out << e <<   n ; n   return out; n } n struct point { n   long long x, y; n   point() {} n   point(const point& a) { x = a.x, y = a.y; } n   point(long long _x, long long _y) { n     x = _x; n     y = _y; n   } n   point operator-(point a) { return point(x - a.x, y - a.y); } n   point operator+(point a) { return point(x + a.x, y + a.y); } n }; n ostream& operator<<(ostream& out, point p) { n   return out <<  (  << p.x <<     << p.y <<  ) ; n } n long double dist(point a, point b) { n   long double X = a.x - b.x; n   long double Y = a.y - b.y; n   return sqrt(X * X + Y * Y); n } n istream& operator>>(istream& in, point& p) { return in >> p.x >> p.y; } n long double area(point a, point b, point c) { n   return a.x * b.y + b.x * c.y + c.x * a.y - a.y * b.x - b.y * c.x - c.y * a.x; n } n const long long N = 100100; n point p1, p2, p[N]; n long long n, k, use[N]; n vector<pair<long long, long long> > v[5]; n long long lg(long long a) { n   if (a % 2 == 1) a++; n   a /= 2; n   return max(1LL, a); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> k; n   for (long long i = 1; i <= n; i++) { n     cin >> p1 >> p2; n     p[i] = p1 + p2; n   } n   for (long long i = 1; i <= n; i++) { n     v[0].push_back({p[i].x, i}); n     v[1].push_back({p[i].x, i}); n   } n   for (long long i = 1; i <= n; i++) { n     v[2].push_back({p[i].y, i}); n     v[3].push_back({p[i].y, i}); n   } n   sort(v[0].begin(), v[0].end()); n   sort(v[1].begin(), v[1].end(), greater<pair<long long, long long> >()); n   sort(v[2].begin(), v[2].end()); n   sort(v[3].begin(), v[3].end(), greater<pair<long long, long long> >()); n   long long ans = 1e18 + 100; n   for (long long i = 0; i < (1 << (2 * k)); i++) { n     long long order[12], msk = i, used[12]; n     for (long long j = 1; j <= k; j++) { n       order[j] = msk % 4; n       msk /= 4; n     } n     long long d[] = {v[0][0].first, v[1][0].first, v[2][0].first, n                      v[3][0].first}; n     for (long long j = 1; j <= k; j++) { n       long long p = order[j], ind = 0; n       while (use[v[order[j]][ind].second]) ind++; n       use[v[p][ind].second] = 1; n       used[j] = v[p][ind].second; n     } n     for (int j = 0; j < 4; j++) { n       int ind = 0; n       while (use[v[j][ind].second]) ind++; n       d[j] = v[j][ind].first; n     } n     ans = min(ans, lg(d[1] - d[0]) * lg(d[3] - d[2])); n     for (long long j = 1; j <= k; j++) use[used[j]] = 0; n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n string s[51]; n int n, m; n bool check(int i, int j) { n   for (int k = 1; k <= n; ++k) n     if (s[k][j] ==  #  && s[k] != s[i]) return false; n   return true; n } n signed main() { n   ios::sync_with_stdio(false); n   cin >> n >> m; n   for (int i = 1; i <= n; ++i) cin >> s[i]; n   for (int i = 1; i <= n; ++i) n     for (int j = 0; j <= m - 1; ++j) n       if (s[i][j] ==  # ) n         if (!check(i, j)) { n           cout <<  No ; n           return 0; n         } n   cout <<  Yes ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n T gcd(T a, T b) { n   while (a > 0 && b > 0) { n     if (a > b) n       a %= b; n     else n       b %= a; n   } n   return a + b; n } n void YES_NO(bool YES_NO, bool isExit = true) { n   if (YES_NO) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n   if (isExit) { n     exit(0); n   } n } n void Yes_No(bool Yes_No, bool isExit = true) { n   if (Yes_No) n     cout <<  Yes  << endl; n   else n     cout <<  No  << endl; n   if (isExit) { n     exit(0); n   } n } n void yes_no(bool yes_no, bool isExit = true) { n   if (yes_no) n     cout <<  yes  << endl; n   else n     cout <<  no  << endl; n   if (isExit) { n     exit(0); n   } n } n int main() { n   string s, t; n   cin >> s; n   cin >> t; n   int cnt = 0; n   for (int i = 0; i < s.size(); ++i) { n     if (s[i] != t[i]) { n       ++cnt; n     } n   } n   if (cnt % 2 == 1) { n     cout <<  impossible  << endl; n     return 0; n   } n   cnt /= 2; n   string ans = s; n   for (int i = 0; i < s.size(); ++i) { n     if (s[i] != t[i] && cnt) { n       ans[i] = t[i]; n       --cnt; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n int r, g, b; n int mins; n int total; n int tour; n int cycles; n int main() { n   scanf( %d %d %d , &r, &g, &b); n   if (r >= 2) { n     r -= 2; n   } else if (r == 1) { n     r -= 1; n   } n   mins = 30; n   tour = 1; n   total = r + g + b; n   while (total > 0) { n     if (tour == 1) { n       if (g >= 2) { n         g -= 2; n       } else if (g == 1) { n         g -= 1; n       } n       tour = 2; n     } else if (tour == 2) { n       if (b >= 2) { n         b -= 2; n       } else if (b == 1) { n         b -= 1; n       } n       tour = 0; n     } else if (tour == 0) { n       if (r >= 2) { n         r -= 2; n       } else if (r == 1) { n         r -= 1; n       } n       tour = 1; n     } n     total = r + g + b; n     cycles++; n   } n   mins += cycles; n   printf( %d , mins); n } n


#include <bits/stdc++.h> n using namespace std; n int cap[1000000], flow[1000000]; n int to[1000000], _prev[1000000], last[10000], used[10000], level[10000]; n struct MaxFlow { n   int V, E; n   MaxFlow(int n) { n     int i; n     V = n; n     E = 0; n     for ((i) = 0; (i) < (int)(V); (i)++) last[i] = -1; n   } n   void add_edge(int x, int y, int f) { n     cap[E] = f; n     flow[E] = 0; n     to[E] = y; n     _prev[E] = last[x]; n     last[x] = E; n     E++; n     cap[E] = 0; n     flow[E] = 0; n     to[E] = x; n     _prev[E] = last[y]; n     last[y] = E; n     E++; n   } n   bool bfs(int s, int t) { n     int i; n     for ((i) = 0; (i) < (int)(V); (i)++) level[i] = -1; n     queue<int> q; n     q.push(s); n     level[s] = 0; n     while (!q.empty()) { n       int x = q.front(); n       q.pop(); n       for (i = last[x]; i >= 0; i = _prev[i]) n         if (level[to[i]] == -1 && cap[i] > flow[i]) { n           q.push(to[i]); n           level[to[i]] = level[x] + 1; n         } n     } n     return (level[t] != -1); n   } n   int dfs(int v, int t, int f) { n     int i; n     if (v == t) return f; n     for (i = used[v]; i >= 0; used[v] = i = _prev[i]) n       if (level[to[i]] > level[v] && cap[i] > flow[i]) { n         int tmp = dfs(to[i], t, min(f, cap[i] - flow[i])); n         if (tmp > 0) { n           flow[i] += tmp; n           flow[i ^ 1] -= tmp; n           return tmp; n         } n       } n     return 0; n   } n   int maxflow(int s, int t) { n     int i; n     while (bfs(s, t)) { n       for ((i) = 0; (i) < (int)(V); (i)++) used[i] = last[i]; n       while (dfs(s, t, (1 << 29)) != 0) n         ; n     } n     int ans = 0; n     for (i = last[s]; i >= 0; i = _prev[i]) ans += flow[i]; n     return ans; n   } n }; n int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}; n int X, Y; n string board[30]; n int dist[30][30][30][30]; n int A, B; n int cx, cy, ct; n int ax[500], ay[500], at[500]; n int bx[500], by[500], bt[500]; n queue<int> q; n void bfs(int s, int t) { n   int i, j; n   for ((i) = 0; (i) < (int)(X); (i)++) n     for ((j) = 0; (j) < (int)(Y); (j)++) dist[s][t][i][j] = (1 << 29); n   if (board[s][t] ==  # ) return; n   dist[s][t][s][t] = 0; n   q.push(s); n   q.push(t); n   while (!q.empty()) { n     int x = q.front(); n     q.pop(); n     int y = q.front(); n     q.pop(); n     for ((i) = 0; (i) < (int)(4); (i)++) { n       int x2 = x + dx[i], y2 = y + dy[i]; n       if (x2 >= 0 && x2 < X && y2 >= 0 && y2 < Y && board[x2][y2] !=  #  && n           dist[s][t][x2][y2] == (1 << 29)) { n         dist[s][t][x2][y2] = dist[s][t][x][y] + 1; n         q.push(x2); n         q.push(y2); n       } n     } n   } n } n bool check(long long T) { n   int i, j, k; n   MaxFlow mf(A + A + 2 * (X * Y) + 2); n   int V = A + A + 2 * (X * Y) + 2; n   for ((i) = 0; (i) < (int)(A); (i)++) mf.add_edge(V - 2, i, 1); n   for ((i) = 0; (i) < (int)(A); (i)++) mf.add_edge(A + i, V - 1, 1); n   for ((i) = 0; (i) < (int)(X * Y); (i)++) n     mf.add_edge(A + A + i, A + A + X * Y + i, 1); n   for ((i) = 0; (i) < (int)(A); (i)++) n     for ((j) = 0; (j) < (int)(X); (j)++) n       for ((k) = 0; (k) < (int)(Y); (k)++) { n         int d = dist[ax[i]][ay[i]][j][k]; n         if (d != (1 << 29) && (long long)d * at[i] <= T) n           mf.add_edge(i, A + A + j * Y + k, 1); n       } n   for ((i) = 0; (i) < (int)(A); (i)++) n     for ((j) = 0; (j) < (int)(X); (j)++) n       for ((k) = 0; (k) < (int)(Y); (k)++) { n         int d = dist[bx[i]][by[i]][j][k]; n         if (d != (1 << 29) && (long long)d * bt[i] <= T) n           mf.add_edge(A + A + X * Y + j * Y + k, A + i, 1); n       } n   int f = mf.maxflow(V - 2, V - 1); n   return (f == A); n } n int main(void) { n   int i, j; n   cin >> X >> Y >> A >> B; n   for ((i) = 0; (i) < (int)(X); (i)++) cin >> board[i]; n   for ((i) = 0; (i) < (int)(X); (i)++) n     for ((j) = 0; (j) < (int)(Y); (j)++) bfs(i, j); n   cin >> cx >> cy >> ct; n   for ((i) = 0; (i) < (int)(A); (i)++) cin >> ax[i] >> ay[i] >> at[i]; n   for ((i) = 0; (i) < (int)(B); (i)++) cin >> bx[i] >> by[i] >> bt[i]; n   cx--; n   cy--; n   for ((i) = 0; (i) < (int)(A); (i)++) { n     ax[i]--; n     ay[i]--; n   } n   for ((i) = 0; (i) < (int)(B); (i)++) { n     bx[i]--; n     by[i]--; n   } n   if (A < B) { n     ax[A] = cx; n     ay[A] = cy; n     at[A] = ct; n     A++; n   } else { n     bx[B] = cx; n     by[B] = cy; n     bt[B] = ct; n     B++; n   } n   if (A != B) { n     cout << -1 << endl; n     return 0; n   } n   long long low = -1, high = (1ll << 40); n   while (high - low > 1) { n     long long mid = (low + high) / 2; n     if (check(mid)) n       high = mid; n     else n       low = mid; n   } n   if (high == (1ll << 40)) high = -1; n   cout << high << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9; n const long long LINF = 1e18; n int n, m, k; n bool noted[13]; n bool connected[13][13]; n int cnt = 0; n set<long long> st; n set<set<int>> sets; n vector<int> vec[13]; n long long pw[13]; n bool visitedd[13]; n map<long long, bool> visiteddd[13][13]; n void bruteforce_string(int u, int v, int d, long long code) { n   if (d == n / 2) { n     if (!connected[u][v]) return; n     cnt++; n     st.insert(code); n     return; n   } n   for (int x : vec[u]) n     for (int y : vec[v]) { n       if (x == y) continue; n       if (visitedd[x] || visitedd[y]) continue; n       long long nx = min(x, y); n       long long ny = max(x, y); n       long long ncode = code + (ny << (4LL * nx)); n       if (!visiteddd[nx][ny][ncode]) { n         visiteddd[nx][ny][ncode] = 1; n         visitedd[x] = 1; n         visitedd[y] = 1; n         bruteforce_string(nx, ny, d + 1, ncode); n         visitedd[x] = 0; n         visitedd[y] = 0; n       } n     } n } n int cnt2 = 0; n map<set<int>, bool> visited; n void bruteforce_striling(set<int> st) { n   visited[st] = 1; n   if (st.size() == 1) return; n   for (auto it = st.begin(); it != st.end(); it++) { n     auto jt = it; n     ++jt; n     for (; jt != st.end(); jt++) { n       set<int> nt = st; n       nt.erase(*it); n       nt.erase(*jt); n       nt.insert(*it + *jt); n       if (!visited[nt]) bruteforce_striling(nt); n     } n   } n } n long long P(int n, int k) { n   long long res = 1; n   for (int i = 0; i < k; i++) res = (res * (n - i)); n   return res; n } n int main() { n   pw[0] = 1; n   for (int i = 1; i <= 12; i++) pw[i] = pw[i - 1] * 13; n   scanf( %d %d %d n , &n, &m, &k); n   for (int i = 1; i <= m; i++) { n     int u, v; n     scanf( %d %d , &u, &v); n     vec[u].push_back(v); n     vec[v].push_back(u); n     connected[u][v] = connected[v][u] = 1; n   } n   for (int i = 1; i <= n; i++) { n     for (int j = i + 1; j <= n; j++) { n       visitedd[i] = 1; n       visitedd[j] = 1; n       bruteforce_string(i, j, 1, ((1LL * j) << (4 * i))); n       visitedd[i] = 0; n       visitedd[j] = 0; n     } n   } n   for (auto it : st) { n     set<int> temp; n     for (int i = 1; i <= 12; i++) { n       int u = i; n       int v = ((it >> (4LL * i)) & 15); n       if (v) temp.insert((1 << u) + (1 << v)); n     } n     sets.insert(temp); n   } n   for (auto it : sets) { n     if (!visited[it]) bruteforce_striling(it); n   } n   long long res = 0; n   for (auto it : visited) { n     res += P(k, it.first.size()); n   } n   printf( %lld n , res); n } n


#include <bits/stdc++.h> n using namespace std; n char s[2000005], str[2000005]; n int pre[2000005]; n int find(int x) { return x == pre[x] ? x : pre[x] = find(pre[x]); } n int main() { n   int n, q, x; n   while (scanf( %d , &n) != EOF) { n     for (int i = 1; i < 2000005; i++) pre[i] = i; n     int maxx = 0; n     while (n--) { n       scanf( %s%d , str, &q); n       int len = strlen(str); n       while (q--) { n         scanf( %d , &x); n         maxx = max(maxx, x + len); n         for (int i = find(x); i < x + len; i = pre[i] = find(i + 1)) n           s[i] = str[i - x]; n       } n     } n     for (int i = 1; i < maxx; i++) { n       if (s[i] ==   0 ) s[i] =  a ; n     } n     printf( %s , s + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 500; n int n, s, deg[N], cnt; n int main() { n   scanf( %d%d , &n, &s); n   for (int i = 1; i < n; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     deg[x]++; n     deg[y]++; n   } n   for (int i = 1; i <= n; i++) n     if (deg[i] == 1) cnt++; n   if (n == 2) n     printf( %.10lf n , (double)s); n   else n     printf( %.10lf n , (double)(2 * s) / (double)cnt); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 50; n const int magic = 2500; n struct Node { n   int from, to, delta, add; n   Node(int from, int to, int delta, int add) n       : from(from), to(to), delta(delta), add(add) {} n }; n int n, a[maxn], c[maxn], q[maxn], id[maxn], b[maxn], ans[maxn], Q; n vector<Node> All; n void BuildInterval() { n   for (auto&& x : All) n     for (int i = x.from; i <= x.to; ++i) n       b[id[i]] -= x.delta, ans[id[i]] += x.add; n   for (int i = 1; i <= Q; ++i) id[i] = i; n   sort(id + 1, id + Q + 1, n        [&](const int& x, const int& y) { return b[x] < b[y]; }); n   All.clear(); n   All.push_back(Node(1, Q, 0, 0)); n } n int main(int argc, char* argv[]) { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %d%d , c + i, q + i), id[i] = i; n   sort(id + 1, id + n + 1, [&](const int& x, const int& y) { n     return q[x] > q[y] || (q[x] == q[y] && c[x] < c[y]); n   }); n   for (int i = 1; i <= n; ++i) a[i] = c[id[i]]; n   scanf( %d , &Q); n   for (int i = 1; i <= Q; ++i) scanf( %d , b + i); n   BuildInterval(); n   for (int i = 1; i <= n; ++i) { n     for (int j = 0, limit = All.size(); j < limit; ++j) { n       if (All[j].from > All[j].to) continue; n       if (b[id[All[j].from]] - All[j].delta >= a[i]) n         All[j].delta += a[i], ++All[j].add; n       else if (b[id[All[j].to]] - All[j].delta >= a[i]) { n         int l = All[j].from + 1, r = All[j].to; n         while (l < r) { n           int mid = l + r >> 1; n           if (b[id[mid]] - All[j].delta >= a[i]) n             r = mid; n           else n             l = mid + 1; n         } n         All.push_back(Node(l, All[j].to, All[j].delta + a[i], All[j].add + 1)); n         All[j].to = l - 1; n       } n     } n     if (All.size() > magic || i == n) BuildInterval(); n   } n   for (int i = 1; i <= Q; ++i) printf( %d  , ans[i]); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f, N = 3.1e5; n int n, m, dis[N], fm[N]; n vector<int> vec[N]; n void bfs() { n   memset(dis, 0x3f, sizeof(dis)); n   queue<int> q; n   q.push(1); n   dis[1] = 0; n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     for (int v : vec[u]) n       if (dis[v] == INF) dis[v] = dis[u] + 1, fm[v] = u, q.push(v); n   } n } n int x[N], y[N], fa[N], sz[N], d[N]; n bool vis[N]; n int find(int u) { return u == fa[u] ? u : fa[u] = find(fa[u]); } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> m; n   for (int i = 1; i <= m; i++) n     cin >> x[i] >> y[i], vec[x[i]].push_back(y[i]), vec[y[i]].push_back(x[i]); n   bfs(); n   stack<int> s; n   if (dis[n] <= 4) n     for (int i = n; i; i = fm[i]) s.push(i); n   else { n     bool ok = 0; n     for (int i = 1; i <= n; i++) n       if (dis[i] == 2) { n         s.push(n); n         s.push(1); n         s.push(i); n         s.push(fm[i]); n         s.push(1); n         ok = 1; n         break; n       } n     if (!ok) { n       for (int i = 1; i <= n; i++) fa[i] = i, sz[i] = 1; n       for (int i = 1; i <= m; i++) n         if (x[i] != 1 && y[i] != 1 && dis[x[i]] == 1 && dis[y[i]] == 1) { n           int u = x[i], v = y[i]; n           d[u]++, d[v]++; n           int fv = find(v), fu = find(u); n           if (fu == fv) continue; n           fa[fv] = fu, sz[fu] += sz[fv]; n         } n       for (int i = 1; i <= n; i++) n         if (dis[i] == 1 && d[i] != sz[find(i)] - 1) { n           for (int v : vec[i]) n             if (v != 1) vis[v] = 1; n           for (int v : vec[i]) n             if (v != 1) { n               bool Get = 0; n               for (int vv : vec[v]) n                 if (vv != 1 && vv != i && !vis[vv]) { n                   s.push(n); n                   s.push(i); n                   s.push(vv); n                   s.push(v); n                   s.push(i); n                   s.push(1); n                   Get = 1; n                   break; n                 } n               if (Get) break; n             } n           break; n         } n     } n   } n   cout << int(s.size() - 1) << endl; n   while (!s.empty()) cout << s.top() <<    , s.pop(); n   return 0; n } n


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


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC target( popcnt ) n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   cin >> n; n   vector<pair<char, int>> arr; n   for (int i = 0; i < 2 * n; i++) { n     char sym; n     cin >> sym; n     int tmp; n     if (sym ==  + ) { n       tmp = 1; n     } else { n       cin >> tmp; n     } n     arr.emplace_back(sym, tmp); n   } n   reverse(arr.begin(), arr.end()); n   stack<int> mys; n   string s =  YES ; n   vector<int> ans; n   for (int i = 0; i < int(arr.size()); i++) { n     char sym; n     int x; n     tie(sym, x) = arr[i]; n     if (sym ==  + ) { n       if (mys.empty()) { n         s =  NO ; n         break; n       } n       ans.push_back(mys.top()); n       mys.pop(); n     } else { n       if (!mys.empty() && mys.top() < x) { n         s =  NO ; n         break; n       } n       mys.push(x); n     } n   } n   cout << s <<   n ; n   if (s ==  YES ) { n     reverse(ans.begin(), ans.end()); n     for (auto ele : ans) { n       cout << ele <<    ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int q; n   cin >> q; n   int l[500], r[500], d[500], ans[500]; n   for (int i = 0; i < q; i++) { n     cin >> l[i] >> r[i] >> d[i]; n     int quo; n     if (d[i] < l[i]) { n       ans[i] = d[i]; n     } else { n       quo = int(r[i] / d[i]); n       ans[i] = d[i] * (quo + 1); n     } n   } n   for (int i = 0; i < q; i++) { n     cout << ans[i] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, v[100010], c[100010], l[100010], r, mx = 0; n map<long long, long long> dp, path, acp; n vector<long long> ans, vt[3 * 100010]; n void getdp(long long x) { n   long long i, ss; n   dp.clear(); n   path.clear(); n   acp.clear(); n   for (i = 0; i < vt[x].size(); i++) { n     dp[l[vt[x][i]]] = dp[l[vt[x][i]] + c[vt[x][i]]] = -1000000000000000000; n     path[l[vt[x][i]]] = path[l[vt[x][i]] + c[vt[x][i]]] = -1; n     acp[vt[x][i]] = -1; n   } n   dp[0] = 0; n   for (ss = 0; ss < vt[x].size(); ss++) { n     i = vt[x][ss]; n     if (l[i] == 0) { n       if (v[i] > dp[l[i] + c[i]] || path[l[i] + c[i]] == -1) { n         dp[l[i] + c[i]] = v[i]; n         path[l[i] + c[i]] = i; n         acp[i] = -1; n       } n     } else { n       if (path[l[i]] == -1) { n         continue; n       } n       if (dp[l[i]] + v[i] > dp[l[i] + c[i]] || path[l[i] + c[i]] == -1) { n         dp[l[i] + c[i]] = dp[l[i]] + v[i]; n         path[l[i] + c[i]] = i; n         acp[i] = path[l[i]]; n       } n     } n   } n   i = path[x]; n   if (dp[x] > mx) { n     mx = dp[x]; n     ans.clear(); n     while (i != -1) { n       ans.push_back(i); n       i = acp[i]; n     } n   } n   return; n } n int main() { n   long long i, j, mx = 0; n   scanf( %lld , &n); n   for (i = 0; i < n; i++) { n     scanf( %lld%lld%lld%lld , &v[i], &c[i], &l[i], &r); n     vt[c[i] + l[i] + r].push_back(i); n   } n   for (i = 0; i <= 300000; i++) { n     if (vt[i].empty()) { n       continue; n     } n     getdp(i); n   } n   sort(ans.begin(), ans.end()); n   printf( %lld n , (long long)ans.size()); n   for (i = 0; i < ans.size(); i++) { n     printf( %lld  , ans[i] + 1); n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 300005, M = 25; n const long long p = 998244353ll; n inline long long expo(long long a, int b = 998244351) { n   long long c = 1ll; n   while (b) { n     if (b & 1) c = c * a % p; n     b >>= 1; n     a = a * a % p; n   } n   return c; n } n long long FAC[N], IFA[N]; n inline long long comb(int a, int b) { n   return (b < 0 || b > a) ? 0ll : (FAC[a] * (IFA[b] * IFA[a - b] % p) % p); n } n vector<int> L[N], R[N]; n int I[N], C[M << 1]; n long long E[M], ss; n inline void dfs(int m, long long a, int w = 1) { n   if (m) { n     dfs(m - 1, a, w); n     if ((ss & E[m]) == E[m]) dfs(m - 1, a & (~E[m]), -w); n   } else { n     C[__builtin_popcountll(a)] += w; n   } n } n int main() { n   int n, m, i, a, b, c = 0, f = 0, c0 = 0, c1 = 0; n   long long ans = 0ll, s1 = 0ll; n   vector<int>::iterator d; n   scanf( %d%d , &n, &m); n   FAC[0] = 1ll; n   for (i = (1); i <= (n); ++i) FAC[i] = FAC[i - 1] * i % p; n   IFA[n] = expo(FAC[n]); n   for (i = (n); i >= (1); --i) IFA[i - 1] = IFA[i] * i % p; n   for (i = (1); i <= (n); ++i) { n     scanf( %d%d , &a, &b); n     L[a].push_back(i); n     R[b].push_back(i); n   } n   for (i = (1); i <= (m); ++i) { n     scanf( %d%d , &a, &b); n     if (!I[a]) I[a] = ++c; n     if (!I[b]) I[b] = ++c; n     E[i] = (1ll << I[a]) | (1ll << I[b]); n   } n   C[0] = 1; n   for (i = (1); i <= (n); ++i) { n     for (d = L[i].begin(); d != L[i].end(); ++d) { n       a = *d; n       if (I[a]) { n         ++c1; n         f = 1; n         s1 |= 1ll << I[a]; n       } n       ++c0; n     } n     if (f) { n       for (a = (0); a <= (c1); ++a) C[a] = 0; n       ss = s1; n       dfs(m, s1); n       f = 0; n     } n     for (a = (0); a <= (c1); ++a) n       ans = (ans + (C[c1 - a] + p) * comb(c0 - a, i - a)) % p; n     for (d = R[i].begin(); d != R[i].end(); ++d) { n       a = *d; n       if (I[a]) { n         --c1; n         f = 1; n         s1 ^= 1ll << I[a]; n       } n       --c0; n     } n   } n   printf( %lld , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void ga(int N, int *A) { n   for (int i(0); i < N; i++) cin >> A[i]; n } n int main(void) { n   ios_base::sync_with_stdio(false); n   string num; n   getline(cin, num); n   int ln = num.length(); n   int b = 0; n   int st = 0; n   int en = ln; n   bool dot = 0; n   for (char e : num) { n     dot = dot or (e ==  . ); n   } n   for (int i(0); i < ln; i++) { n     if (num[i] !=  0 ) { n       st = i; n       break; n     } n   } n   for (int i = ln - 1; i > 0; i--) { n     if (num[i] !=  0 ) { n       en = i + 1; n       break; n     } n   }; n   ; n   if (num[st] ==  . ) { n     b--; n     for (int i(st + 1); i < ln; i++) { n       if (num[i] !=  0 ) { n         st = i; n         break; n       } n       b--; n     } n     cout << num[st] << (en - st - 1 == 0 ?    :  . ) n          << num.substr(st + 1, en - st - 1) <<  E  << b << endl; n     return 0; n   } else { n     b--; n     for (int i(st); i < ln; i++) { n       if (num[i] ==  . ) { n         en--; n         num.erase(i, 1); n         break; n       } n       b++; n     }; n     for (int i = en - 1; i >= 0; i--) { n       if (num[i] !=  0 ) { n         ; n         en = i + 1; n         break; n       } n     } n     cout << num[st] << (en - st - 1 == 0 ?    :  . ) n          << num.substr(st + 1, en - st - 1) n          << (b == 0 ?    :  E  + to_string(b)) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int a[1000005]; n inline int Pow_Log(int x, int p) { n   int sol = 1; n   while (p) { n     if (p & 1) { n       sol = (1LL * sol * x) % 1000000009; n       --p; n     } n     p >>= 1; n     x = (1LL * x * x) % 1000000009; n   } n   return sol; n } n int main() { n   int i, j, sol = 1, x; n   cin.sync_with_stdio(0); n   cin >> n >> m; n   x = Pow_Log(2, m); n   for (i = 1; i <= n; ++i) { n     --x; n     if (x < 0) x += 1000000009; n     sol = (1LL * sol * x) % 1000000009; n   } n   cout << sol; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int n, m, a, b, c, d, k, x, y, z, ans = 0, total = 0; n long long int arr[201000] = {0}; n int main(void) { n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> arr[i]; n   sort(arr, arr + n); n   a = (n / 2); n   ans += abs(arr[a] - m); n   for (int i = a + 1; i < n; i++) { n     if (arr[i] < m) { n       ans += abs(arr[i] - m); n     } else { n       break; n     } n   } n   for (int i = a - 1; i >= 0; i--) { n     if (arr[i] > m) { n       ans += abs(arr[i] - m); n     } else { n       break; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string file[10005]; n unordered_map<string, pair<int, int> > ss; n unordered_map<string, bool> sk; n void deal(const string &in, int loc) { n   sk.clear(); n   int len = in.size(); n   string temp; n   for (int i = 1; i <= len; ++i) { n     for (int j = 0; j <= len - i; ++j) { n       temp.clear(); n       for (int k = j; k < i + j; ++k) { n         temp.push_back(in[k]); n       } n       auto &flag = sk[temp]; n       if (flag) n         continue; n       else { n         flag = true; n         auto it = ss.find(temp); n         if (it == ss.end()) { n           ss.emplace(make_pair(temp, make_pair(loc, 1))); n         } else n           ++it->second.second; n       } n     } n   } n } n string quest; n int main() { n   int n, m; n   ios::sync_with_stdio(false); n   cin >> n; n   for (int i = 0; i < n; ++i) { n     cin >> file[i]; n     deal(file[i], i); n   } n   cin >> m; n   while (m--) { n     cin >> quest; n     auto it = ss.find(quest); n     if (it != ss.end()) { n       cout << it->second.second <<     << file[it->second.first] <<   n ; n     } else { n       cout <<  0 - n ; n     } n   } n   return 0; n } n


#define DEBUG 0 n  n #include <bits/stdc++.h> n using namespace std; n  n #if DEBUG n // basic debugging macros n int __i__,__j__; n #define printLine(l) for(__i__=0;__i__<l;__i__++){cout<< - ;}cout<<endl n #define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl n #define printVar(n) cout<<#n<< :  <<n<<endl n #define printArr(a,l) cout<<#a<< :  ;for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<   ;}cout<<endl n #define print2dArr(a,r,c) cout<<#a<< : n ;for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<   ;}cout<<endl;} n #define print2dArr2(a,r,c,l) cout<<#a<< : n ;for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(   )<<a[__i__][__j__]<<   ;}cout<<endl;} n  n // advanced debugging class n // debug 1,2, A , test ; n class _Debug { n     public: n         template<typename T> n         _Debug& operator,(T val) { n             cout << val << endl; n             return *this; n         } n }; n #define debug _Debug(), n #else n #define printLine(l) n #define printLine2(l,c) n #define printVar(n) n #define printArr(a,l) n #define print2dArr(a,r,c) n #define print2dArr2(a,r,c,l) n #define debug n #endif n  n // define n #define MAX_VAL 999999999 n #define MAX_VAL_2 999999999999999999LL n #define EPS 1e-6 n #define mp make_pair n #define pb push_back n  n // typedef n typedef unsigned int UI; n typedef long long int LLI; n typedef unsigned long long int ULLI; n typedef unsigned short int US; n typedef pair<int,int> pii; n typedef pair<LLI,LLI> plli; n typedef vector<int> vi; n typedef vector<LLI> vlli; n typedef vector<pii> vpii; n typedef vector<plli> vplli; n  n // ---------- END OF TEMPLATE ---------- n #define MOD 1000000007 n  n int modPow(int b,int e) { n     int r = 1; n     while (e > 0) { n         if (e & 1) r = ((LLI) r*b) % MOD; n         e >>= 1; n         b = ((LLI) b*b) % MOD; n     } n     return r; n } n int fact[41],C[41][41],ways[40]; n int p[40],v[40],occ[41],occ2[41]; n int dp[1000000]; n int main() { n     int i; n     int n; n     scanf( %d ,&n); n     for (i = 0; i < n; i++) scanf( %d ,&p[i]),p[i]--; n  n     int j,k; n     fact[0] = 1; n     for (i = 1; i <= n; i++) fact[i] = ((LLI) i*fact[i-1]) % MOD; n     for (i = 0; i <= n; i++) { n         C[i][0] = 1; n         for (j = 1; j <= i; j++) C[i][j] = (C[i-1][j-1]+C[i-1][j]) % MOD; n     } n     for (i = 0; i < n; i++) { n         for (j = 0; j <= i; j++) { n             ways[i] += ((((LLI) C[i][j]*fact[j]) % MOD)*fact[n-j-1]) % MOD; n             ways[i] %= MOD; n         } n     } n     for (i = 0; i < n; i++) { n         if (!v[i]) { n             int u = i,c = 0; n             while (!v[u]) v[u] = 1,u = p[u],c++; n             occ[c]++; n         } n     } n     int s = 1; n     for (i = 1; i <= n; i++) s *= occ[i]+1; n     dp[0] = 1; n     for (i = 1; i < s; i++) { n         int t = i,s2 = 1,sum = 0; n         for (j = 1; j <= n; j++) { n             occ2[j] = t % (occ[j]+1),s2 *= occ2[j]+1,sum += occ2[j]*j; n             t /= occ[j]+1; n         } n         for (j = 1; j < s2; j++) { n             int t2 = j,sum2 = 0,num = 0,j2 = 0,pp = 1; n             LLI c = 1; n             for (k = 1; k <= n; k++) { n                 int occ3 = t2 % (occ2[k]+1); n                 c *= C[occ2[k]][occ3],c %= MOD,num += occ3,sum2 += occ3*k; n                 j2 += (occ2[k]-occ3)*pp; n                 t2 /= occ2[k]+1,pp *= occ[k]+1; n             } n             if (!(num & 1)) c = MOD-c; n             c *= dp[j2],c %= MOD; n             dp[i] += (c*modPow(ways[sum-sum2],sum2)) % MOD,dp[i] %= MOD; n         } n     } n     printf( %d n ,dp[s-1]); n  n     return 0; n } n  n


#include <bits/stdc++.h> n using namespace std; n long long n, a[100069]; n int main() { n   long long t, rr, i; n   bool bad; n   scanf( %lld , &t); n   for (rr = 0; rr < t; rr++) { n     scanf( %lld , &n); n     for (i = 1; i <= n * 4; i++) { n       scanf( %lld , a + i); n     } n     sort(a + 1, a + n * 4 + 1); n     bad = 0; n     for (i = 1; i <= n * 4; i += 2) { n       if (a[i] != a[i + 1]) { n         bad = 1; n         break; n       } n     } n     for (i = 3; i <= n * 2; i += 2) { n       if (a[i] * a[n * 4 + 1 - i] != a[1] * a[n * 4]) { n         bad = 1; n         break; n       } n     } n     if (bad) { n       printf( NO n ); n     } else { n       printf( YES n ); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, len, kmpA[100010], ans, kmpB[100010], mxA[100010], mxB[100010]; n char S[100010], A[100010], B[100010]; n int main() { n   scanf( %s , S + 1); n   n = strlen(S + 1); n   scanf( %d , &m); n   while (m--) { n     scanf( %s , A); n     kmpA[0] = -1; n     len = strlen(A); n     if (len == 1) continue; n     for (int i = 1, k = -1; i <= len; i++) { n       while (k != -1 && A[i - 1] != A[k]) k = kmpA[k]; n       k++; n       kmpA[i] = k; n     } n     for (int i = 0; i <= len - 1; i++) B[len - 1 - i] = A[i]; n     kmpB[0] = -1; n     for (int i = 1, k = -1; i <= len; i++) { n       while (k != -1 && B[i - 1] != B[k]) k = kmpB[k]; n       k++; n       kmpB[i] = k; n     } n     for (int i = 1, k = 0; i <= n; i++) { n       while (k != -1 && S[i] != A[k]) k = kmpA[k]; n       k++; n       mxA[i] = k; n     } n     for (int i = n, k = 0; i >= 1; i--) { n       while (k != -1 && S[i] != B[k]) k = kmpB[k]; n       k++; n       mxB[i] = k; n     } n     for (int i = 1; i <= n; i++) mxA[i] = max(mxA[i - 1], mxA[i]); n     for (int i = n; i >= 1; i--) mxB[i] = max(mxB[i + 1], mxB[i]); n     bool flag = false; n     for (int i = 1; i <= n + 1; i++) { n       if (mxA[i - 1] + mxB[i] >= len) { n         flag = true; n         break; n       } n     } n     ans += flag; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bitset<1005> tt[30]; n unordered_map<bitset<1005>, int> ff; n pair<bitset<1005>, int> ar[1000005]; n int bc[1000005]; n void print(bitset<1005> t) { n   for (int i = 0; i < 12; ++i) { n     if (t[i]) { n       putchar( 1 ); n     } else { n       putchar( 0 ); n     } n   } n   putchar(  n ); n } n int construct(int l, int r, bool isG) { n   bitset<1005> tmp; n   ar[0] = {tmp, 0}; n   int cc = 1; n   for (int i = l; i <= r; ++i) { n     int ind = i; n     if (isG) { n       ind -= l; n     } n     int tcc = cc; n     for (int j = 0; j < cc; ++j) { n       ar[tcc++] = {ar[j].first ^ tt[i], (1 << ind) + ar[j].second}; n     } n     cc = tcc; n   } n   if (!isG) { n     for (int i = 0; i < cc; ++i) { n       if (!ff.count(ar[i].first)) { n         ff[ar[i].first] = bc[ar[i].second]; n       } else { n         ff[ar[i].first] = min(ff[ar[i].first], bc[ar[i].second]); n       } n     } n   } n   return cc; n } n void solve() { n   int n, s, d; n   scanf( %d %d %d  , &n, &s, &d); n   for (int i = 0; i < s; ++i) { n     int x; n     scanf( %d  , &x); n     while (x--) { n       int t; n       scanf( %d  , &t); n       tt[i][t - 1] = 1; n     } n   } n   bc[0] = 0; n   for (int i = 1; i < 1000005; ++i) { n     bc[i] = bc[i / 2] + (i & 1); n   } n   int g = min(s - 1, 18); n   construct(0, g, 0); n   int sz = construct(g + 1, s - 1, 1); n   while (d--) { n     bitset<1005> tmp; n     int x; n     scanf( %d  , &x); n     while (x--) { n       int t; n       scanf( %d  , &t); n       tmp[t - 1] = 1; n     } n     const int inf = 1e9; n     int ret = inf; n     for (int i = 0; i < sz; ++i) { n       if (ff.count(tmp ^ ar[i].first)) { n         ret = min(ret, bc[ar[i].second] + ff[tmp ^ ar[i].first]); n       } n     } n     if (ret == inf) { n       ret = -1; n     } n     printf( %d n , ret); n   } n } n int main() { n   solve(); 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   cout.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     long long n1, n2, n3; n     cin >> n1 >> n2 >> n3; n     vector<long long> a, b, c; n     for (long long i = (0); i < (n1); i++) { n       long long m; n       cin >> m; n       a.push_back(m); n     } n     for (long long i = (0); i < (n2); i++) { n       long long m; n       cin >> m; n       b.push_back(m); n     } n     for (long long i = (0); i < (n3); i++) { n       long long m; n       cin >> m; n       c.push_back(m); n     } n     sort(a.begin(), a.end()); n     sort(b.begin(), b.end()); n     sort(c.begin(), c.end()); n     long long ans = 9e18L; n     long long fans = 9e18L; n     for (long long i = (0); i < (n1); i++) { n       long long x = a[i]; n       long long yi = lower_bound(b.begin(), b.end(), x) - b.begin(); n       long long zi = upper_bound(c.begin(), c.end(), x) - c.begin(); n       zi--; n       if (zi >= 0 && zi < n3 && yi >= 0 && yi < n2) { n         long long y = b[yi]; n         long long z = c[zi]; n         ans = (x - y) * (x - y) + (x - z) * (x - z) + (z - y) * (z - y); n         fans = min(fans, ans); n       } n     } n     for (long long i = (0); i < (n1); i++) { n       long long x = a[i]; n       long long yi = upper_bound(b.begin(), b.end(), x) - b.begin(); n       long long zi = lower_bound(c.begin(), c.end(), x) - c.begin(); n       yi--; n       if (zi >= 0 && zi < n3 && yi >= 0 && yi < n2) { n         long long y = b[yi]; n         long long z = c[zi]; n         ans = (x - y) * (x - y) + (x - z) * (x - z) + (z - y) * (z - y); n         fans = min(fans, ans); n       } n     } n     for (long long i = (0); i < (n2); i++) { n       long long x = b[i]; n       long long yi = lower_bound(a.begin(), a.end(), x) - a.begin(); n       long long zi = upper_bound(c.begin(), c.end(), x) - c.begin(); n       zi--; n       if (zi >= 0 && zi < n3 && yi >= 0 && yi < n1) { n         long long y = a[yi]; n         long long z = c[zi]; n         ans = (x - y) * (x - y) + (x - z) * (x - z) + (z - y) * (z - y); n         fans = min(fans, ans); n       } n     } n     for (long long i = (0); i < (n2); i++) { n       long long x = b[i]; n       long long yi = upper_bound(a.begin(), a.end(), x) - a.begin(); n       long long zi = lower_bound(c.begin(), c.end(), x) - c.begin(); n       yi--; n       if (zi >= 0 && zi < n3 && yi >= 0 && yi < n1) { n         long long y = a[yi]; n         long long z = c[zi]; n         ans = (x - y) * (x - y) + (x - z) * (x - z) + (z - y) * (z - y); n         fans = min(fans, ans); n       } n     } n     for (long long i = (0); i < (n3); i++) { n       long long x = c[i]; n       long long yi = upper_bound(b.begin(), b.end(), x) - b.begin(); n       long long zi = lower_bound(a.begin(), a.end(), x) - a.begin(); n       yi--; n       if (zi >= 0 && zi < n1 && yi >= 0 && yi < n2) { n         long long y = b[yi]; n         long long z = a[zi]; n         ans = (x - y) * (x - y) + (x - z) * (x - z) + (z - y) * (z - y); n         fans = min(fans, ans); n       } n     } n     for (long long i = (0); i < (n3); i++) { n       long long x = c[i]; n       long long yi = lower_bound(b.begin(), b.end(), x) - b.begin(); n       long long zi = upper_bound(a.begin(), a.end(), x) - a.begin(); n       zi--; n       if (zi >= 0 && zi < n1 && yi >= 0 && yi < n2) { n         long long y = b[yi]; n         long long z = a[zi]; n         ans = (x - y) * (x - y) + (x - z) * (x - z) + (z - y) * (z - y); n         fans = min(fans, ans); n       } n     } n     cout << fans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); n const int INF = 2e9; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n, p; n   cin >> n >> p; n   vector<int> a(n); n   for (int i = 0; i < (int)(n); i++) cin >> a[i]; n   sort((a).begin(), (a).end()); n   int l = -INF, r = INF; n   for (int i = 0; i < (int)(n); i++) { n     l = max(l, a[i] - i); n     if (p - 1 <= i) r = min(r, a[i] - i + (p - 1)); n   } n   vector<int> ans; n   for (int i = l; i < r; i++) ans.push_back(i); n   cout << ((int)(ans).size()) << endl; n   for (auto x : ans) cout << x <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int getReverted(int num) { n   bool bin[8] = {0}; n   for (int j = 0; num != 0; j++) { n     bin[j] = num % 2; n     num /= 2; n   } n   for (int j = 0; j < 8; j++) { n     num += (int)bin[j] * pow(2, 7 - j); n   } n   return num; n } n int strSize(char *str) { n   int i; n   for (i = 0; str[i] !=   0 ; i++) n     ; n   return i; n } n int main() { n   char str[101]; n   int last = 0, result, size, reverted; n   scanf(  %[^ n]s , str); n   size = strSize(str); n   for (int i = 0; str[i] !=   0 ; i++) { n     reverted = getReverted(str[i]); n     result = (last - reverted) % 256; n     if (result < 0) n       while (result < 0) result += 256; n     cout << result; n     if (i != size - 1) cout << endl; n     last = getReverted(str[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string getmin(string prev, string cur) { n   if (prev.length() < cur.length()) { n     for (int i = 0; i < cur.length(); i++) { n       if (cur[i] ==  ? ) cur[i] = (i == 0) ?  1  :  0 ; n     } n     return cur; n   } n   if (prev.length() > cur.length()) return   ; n   int fmsm = 100; n   for (int i = 0; i < cur.length(); i++) { n     if (cur[i] ==  ? ) continue; n     if (cur[i] != prev[i]) { n       fmsm = i; n       break; n     } n   } n   int nm = 0; n   for (int i = 0; i < cur.length(); i++) { n     if (i == fmsm) { n       if (cur[i] < prev[i]) nm++; n     } n     if (cur[i] ==  ? ) { n       if (i < fmsm) n         nm = nm * 10 + prev[i] -  0 ; n       else { n         nm *= 10; n       } n     } n   } n   if (fmsm == 100) nm++; n   for (int i = cur.length() - 1; i >= 0; i--) { n     if (cur[i] ==  ? ) { n       cur[i] =  0  + nm % 10; n       nm /= 10; n     } n   } n   if (nm) return   ; n   return cur; n } n int main() { n   int n; n   scanf( %d , &n); n   string cur =   ; n   vector<string> nums; n   for (int i = 0; i < n; i++) { n     char ch[32]; n     scanf(  %s , ch); n     string chs(ch); n     string x = getmin(cur, chs); n     if (x.empty()) { n       printf( NO n ); n       return 0; n     } n     nums.push_back(x); n     cur = x; n   } n   printf( YES n ); n   for (int i = 0; i < n; i++) printf( %s n , nums[i].c_str()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   int t, ang; n   cin >> t; n   while (t--) { n     cin >> ang; n     int ans = -1; n     for (int i = 3; i <= 360; ++i) { n       int k = ang * i / 180; n       if ((ang * i) % 180 == 0 && 360 % i == 0 && 1 <= k && k <= i - 2) { n         ans = i; n         break; n       } n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e3 + 1; n char a[N], b[N]; n vector<int> g[26]; n bool vis[26][26]; n vector<pair<char, char> > sol; n char go[26]; n int main() { n   scanf( %s%s , a, b); n   int n = strlen(a); n   for (int i = 0; i < n; ++i) { n     if (a[i] == b[i]) continue; n     int x = a[i] -  a ; n     int y = b[i] -  a ; n     g[x].push_back(y); n     g[y].push_back(x); n   } n   bool can = true; n   for (int i = 0; i < 26 && can; ++i) { n     sort(g[i].begin(), g[i].end()); n     g[i].resize(unique(g[i].begin(), g[i].end()) - g[i].begin()); n     can &= g[i].size() <= 1; n   } n   if (!can) { n     puts( -1 ); n     return 0; n   } n   for (int i = 0; i < 26; ++i) n     if (!g[i].empty()) { n       int x = min(i, g[i][0]), y = max(i, g[i][0]); n       if (vis[x][y]) continue; n       go[x] = y +  a ; n       go[y] = x +  a ; n       vis[x][y] = true; n       sol.push_back(make_pair(x +  a , y +  a )); n     } else n       go[i] = i +  a ; n   for (int i = 0; i < 26 && can; ++i) { n     can &= go[a[i] -  a ] == b[i]; n     can &= go[b[i] -  a ] == a[i]; n   } n   if (!can) { n     puts( -1 ); n     return 0; n   } n   printf( %d n , (int)sol.size()); n   for (int i = 0; i < (int)sol.size(); ++i) n     printf( %c %c n , sol[i].first, sol[i].second); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n, k; n   cin >> n >> k; n   long long a[n * k]; n   for (int i = 0; i < n * k; i++) { n     cin >> a[i]; n   } n   long long sum = 0; n   int jump = ((n + 1) / 2); n   if (n % 2 == 0) jump++; n   int count = 0; n   for (int i = n * k - jump; count < k; i -= jump) { n     sum += a[i]; n     count++; n   } n   cout << sum << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   string input, temp; n   bool f1, f2; n   cin >> n; n   getline(cin, input); n   for (int i = 0; i < n; i++) { n     f1 = false; n     f2 = false; n     getline(cin, input); n     if (input.length() > 4) { n       temp = input.substr(0, 5); n       if (temp ==  miao. ) f2 = true; n       temp = input.substr(input.length() - 5, 5); n       if (temp ==  lala. ) f1 = true; n     } n     if (f1 && !f2) n       cout <<  Freda s  << endl; n     else if (f2 && !f1) n       cout <<  Rainbow s  << endl; n     else n       cout <<  OMG>.< I don t know!  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int arr[n]; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   sort(arr, arr + n); n   int runsum = 0; n   int pen = 0; n   int k = 0; n   while (runsum <= 350 && ((runsum + arr[k]) <= 710) && k < n) n     runsum += arr[k++]; n   if (runsum <= 350) { n     cout << k <<   0  << endl; n   } else { n     runsum -= 350; n     pen += runsum; n     while ((runsum + arr[k]) <= 360 && k < n) { n       runsum += arr[k++]; n       pen += runsum; n     } n     cout << k <<     << pen << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int temp1[26]; n int temp2[1001][26]; n set<int> myset[1001]; n set<int> empty; n vector<int> myvec; n int main() { n   int n; n   cin >> n; n   string str; n   cin >> str; n   int m; n   cin >> m; n   string arr[m]; n   for (int i = 0; i < m; i++) { n     cin >> arr[i]; n   } n   for (int i = 0; i < n; i++) { n     if (str[i] !=  * ) { n       temp1[str[i] -  a ] = 1; n     } n   } n   for (int i = 0; i < m; i++) { n     for (int j = 0; j < n; j++) { n       if (str[j] ==  * ) { n         if (temp1[arr[i][j] -  a ] == 1) { n           myset[i] = empty; n           break; n         } else { n           myset[i].insert(arr[i][j] -  a ); n           temp2[i][arr[i][j] -  a ] = 1; n         } n       } else { n         if (str[j] != arr[i][j]) { n           myset[i] = empty; n           break; n         } n       } n     } n   } n   for (int i = 0; i < m; i++) { n     if (myset[i].empty() == false) { n       myvec.push_back(i); n     } n   } n   int ans = 0; n   int size = myvec.size(); n   for (int j = 0; j < 26; j++) { n     int cnt = 0; n     for (int i = 0; i < size; i++) { n       if (temp2[myvec[i]][j] == 1) { n         cnt++; n       } n     } n     if (cnt == size) { n       ans++; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 100; n vector<int> G[MAXN]; n map<int, int> cnt; n bool vis[MAXN]; n int sz; n int cN, c[MAXN], b[MAXN]; n int dp[MAXN]; n void dfs(int u) { n   vis[u] = true; n   sz++; n   for (int i = 0; i < G[u].size(); i++) { n     int v = G[u][i]; n     if (!vis[v]) dfs(v); n   } n } n inline int smin(int &a, int b) { return a = min(a, b); } n bool lucky(int x) { n   while (x) { n     if (x % 10 != 7 && x % 10 != 4) return false; n     x /= 10; n   } n   return true; n } n int main() { n   ios::sync_with_stdio(false); n   cout.tie(0); n   cin.tie(0); n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     int a, b; n     cin >> a >> b; n     a--; n     b--; n     G[a].push_back(b); n     G[b].push_back(a); n   } n   for (int u = 0; u < n; u++) n     if (!vis[u]) { n       sz = 0; n       dfs(u); n       cnt[sz]++; n     } n   for (map<int, int>::iterator iter = cnt.begin(); iter != cnt.end(); iter++) { n     int x = iter->first, pw = 1; n     int temp = iter->second; n     while (temp >= pw) { n       c[cN++] = x * pw, b[cN - 1] = pw, temp -= pw; n       pw *= 2; n     } n     if (temp) { n       c[cN++] = x * temp; n       b[cN - 1] = temp; n     } n   } n   fill(dp, dp + MAXN, -1u / 4); n   dp[0] = 0; n   for (int i = 0; i < cN; i++) { n     int val = c[i]; n     for (int j = MAXN - 1; j >= 0; j--) n       if (val + j < MAXN) smin(dp[j + val], dp[j] + b[i]); n   } n   int ans = -1u / 4; n   for (int i = 1; i < MAXN; i++) n     if (lucky(i)) smin(ans, dp[i]); n   cout << (ans < MAXN ? ans - 1 : -1) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int read() { n   int xx = 0, ff = 1; n   char ch = getchar(); n   while (ch >  9  || ch <  0 ) { n     if (ch ==  - ) ff = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     xx = xx * 10 + ch -  0 ; n     ch = getchar(); n   } n   return xx * ff; n } n int N, K, f[110][100010]; n struct Segment { n   int L, R; n } S[110]; n int q[100010], head, tail; n int main() { n   N = read(), K = read(); n   for (int i = 1; i <= K; i++) S[i].L = read(), S[i].R = read(); n   for (int j = 0; j <= N; j++) f[0][j] = (1 << 29); n   f[0][0] = 0; n   for (int i = 1; i <= K; i++) { n     for (int j = 0; j <= N; j++) f[i][j] = f[i - 1][j]; n     head = 1, tail = 0; n     for (int j = 0; j <= S[i].R; j++) { n       if (j <= N) { n         while (head <= tail && f[i - 1][j] <= f[i - 1][q[tail]]) tail--; n         q[++tail] = j; n       } n       while (head <= tail && q[head] <= j - (S[i].R - S[i].L + 1)) head++; n       if (head <= tail) f[i][j] = min(f[i][j], f[i - 1][q[head]] + 2); n     } n     head = 1, tail = 0; n     for (int j = S[i].R; j >= 0; j--) { n       if (S[i].R - j <= N) { n         while (head <= tail && f[i - 1][S[i].R - j] <= f[i - 1][q[tail]]) n           tail--; n         q[++tail] = S[i].R - j; n       } n       while (head <= tail && q[head] <= S[i].L - (j + 1)) head++; n       if (head <= tail) f[i][j] = min(f[i][j], f[i][q[head]] + 1); n     } n   } n   if (f[K][N] >= (1 << 29)) n     puts( Hungry ); n   else { n     puts( Full ); n     printf( %d n , f[K][N]); n   } n   return 0; n } n


#include<bits/stdc++.h> n #define pb push_back n using namespace std; n typedef long long ll; n const int maxn=1e6+100; n const int M=1000000007; n typedef array<int,41> A; n bool vis[50]; n int f[50],n,mx,F[50][50],G[50][50],p[50],nf[50],inv[50]; n int ways[50][50][50]; n map<A,int> dp[41][41][41]; n void add(int &x,int y){x+=y;if (x>=M)x-=M;} n int C(int x,int y){ n  if (y<0||y>x) return 0; n  return 1ll*f[x]*nf[y]%M*nf[x-y]%M; n } n void init(){ n  inv[1]=1; for (int i=2;i<=n;i++) inv[i]=M-1ll*(M/i)*inv[M%i]%M; n  f[0]=nf[0]=1; for (int i=1;i<=n;i++) f[i]=1ll*f[i-1]*i%M,nf[i]=1ll*nf[i-1]*inv[i]%M; n  F[0][0]=f[n-1]; n  for (int i=0;i<=n-1;i++) n  for (int j=1;j+i<=n-1;j++){ n         F[i][j]=0; n         for (int x=0;x<=i;x++) n    for (int y=0;y<=j;y++){ n     add(F[i][j],1ll*C(i,x)*C(j,y)%M*f[n-1-x-y]%M*f[x+y]%M); n     if (!y) add(G[i][j],1ll*C(i,x)*C(j,y)%M*f[n-1-x-y]%M*f[x+y]%M); n    } n  } n  for (int i=0;i<=n-1;i++) n  for (int j=0;j+i<=n-1;j++){ n   int x=1,y=1; n   for (int k=1;k<=n;k++){ n    x=1ll*x*F[i][j]%M; n    y=1ll*y*G[i][j]%M; n    ways[i][j][k]=(x-y+M)%M; n   } n  } n } n int solve(int lasttot,int tot,int block,A a){ n     if (dp[lasttot][tot][block].find(a)!=dp[lasttot][tot][block].end()){ n   return dp[lasttot][tot][block][a]; n     } n     int ret=0,sum=n; n     for (int i=1;i<=mx;i++) sum-=a[i]*i; n     if (sum==n) return dp[lasttot][tot][block][a]=nf[block]; n  A tmp=a; n     for (int i=1;i<=mx;i++) { n   if (a[i]){ n    tmp[i]--; n             add(ret,1ll*ways[sum-tot-lasttot][lasttot][i]*a[i]%M*solve(lasttot,tot+i,block+1,tmp)%M); n             if (block) add(ret,1ll*ways[sum-tot][tot][i]*a[i]%M*nf[block]%M*solve(tot,i,1,tmp)%M); n    tmp[i]++; n   } n     } n     return dp[lasttot][tot][block][a]=ret; n } n int main(){ n  scanf( %d ,&n); n  init(); n  for (int i=1;i<=n;i++) scanf( %d ,&p[i]); n  A a; n  for (int i=0;i<=40;i++) a[i]=0; n  for (int i=1;i<=n;i++) if (!vis[i]){ n   int w=0,tmp=i; n   while (!vis[tmp]){ n    w++; n    vis[tmp]=1; n    tmp=p[tmp]; n   } n   a[w]++; n   mx=max(mx,w); n  } n  printf( %d n ,solve(0,0,0,a)); n  return 0; n } n  n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   string s; n   cin >> s; n   long long l = s.length(); n   vector<char> s1; n   long long pos = -1; n   for (long long i = 0; i < l; i++) { n     if (s[i] ==  a ) n       pos = i; n     else n       s1.push_back(s[i]); n   } n   long long l2 = s1.size(); n   long long ri = l - 1 - pos; n   long long le = l2 - ri; n   if (l2 % 2 != 0 || le > ri) n     cout <<  :( ; n   else { n     long long j = l2 / 2; n     bool flag = true; n     for (long long i = 0; i < j; i++) { n       if (s1[i] != s1[i + j]) { n         flag = false; n         break; n       } n     } n     if (!flag) n       cout <<  :( ; n     else { n       for (long long i = 0; i < l - j; i++) cout << s[i]; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   long long x, y; n   int id; n   bool operator<(const node& b) const { n     if (y != b.y) n       return y < b.y; n     else n       return x < b.x; n   } n } a[210000], b[210000], c, d[210000]; n vector<node> q; n int n, num, last; n int ans[210000]; n set<node> s; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) n     cin >> a[i].x >> a[i].y, a[i].id = i, d[i] = a[i]; n   sort(a + 1, a + 1 + n); n   for (int i = n; i >= 1; i--) n     if (a[i].x > last) last = a[i].x, b[++num] = a[i]; n   reverse(b + 1, b + 1 + num); n   for (int i = 1; i <= num; i++) { n     while (q.size() > 1) { n       node c = q[q.size() - 1], d = q[q.size() - 2]; n       if ((c.y - d.y) * d.x * b[i].y * (c.x - b[i].x) < n           (b[i].y - c.y) * b[i].x * d.y * (d.x - c.x)) n         q.pop_back(); n       else n         break; n     } n     q.push_back(b[i]); n   } n   num = 0; n   for (int i = 0; i < q.size(); i++) s.insert(q[i]); n   for (int i = 1; i <= n; i++) n     if (s.count(d[i])) printf( %d  , i); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n, a, b; n     cin >> n >> a >> b; n     int N = n; n     if (abs(a - b) > 1) { n       cout << -1 <<   n ; n       continue; n     } n     if (a + b > n - 2) { n       cout << -1 <<   n ; n       continue; n     } n     bool flag = false; n     if (a < b) { n       swap(a, b); n       flag = true; n     } n     int A = a; n     int B = b; n     int sol[n]; n     int i = 1; n     while (a--) { n       sol[i] = n; n       i += 2; n       n--; n     } n     i = 2; n     int temp = 1; n     while (b--) { n       sol[i] = temp; n       i += 2; n       temp++; n     } n     sol[0] = B + 1; n     temp = B + 2; n     int index = A + B + 1; n     if (B == A) { n       while (index != N) { n         sol[index] = temp; n         temp++; n         index++; n       } n     } else { n       temp = N - A; n       while (index != N) { n         sol[index] = temp; n         temp--; n         index++; n       } n     } n     if (flag) { n       for (int i = 0; i < N; i++) { n         sol[i] = N + 1 - sol[i]; n       } n     } n     for (int i = 0; i < N; i++) { n       cout << sol[i] <<    ; n     } n     cout <<   n ; n   } n   cerr <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC n        <<  ms n ; n   return 0; n } n


#include <bits/stdc++.h> n char str[110]; n int main() { n   int len, t, _max = 0; n   scanf( %s , str); n   len = strlen(str); n   for (int i = 0; i < len; i++) n     for (int j = i + 1; j < len; j++) { n       t = 0; n       while (str[i + t] == str[j + t]) t++; n       if (t > _max) _max = t; n     } n   printf( %d , _max); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 100; n long long n, m, dp[N][N], a[N][N], b[N][N], c[N], len; n char go[N][N][N]; n char str[N << 1]; n inline long long read() { n   long long sym = 0, res = 0; n   char ch = 0; n   while (!isdigit(ch)) sym |= (ch ==  - ), ch = getchar(); n   while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar(); n   return sym ? -res : res; n } n void file() { n   freopen( read.in ,  r , stdin); n   freopen( write.out ,  w , stdout); n } n long long power(long long a, long long x) { n   long long res = 1; n   while (x) { n     if (x & 1) res *= a; n     a *= a; n     x >>= 1; n   } n   return res; n } n void write(long long now, long long x, long long y, char ch) { n   if (now == 0) { n     printf( %c , ch); n     return; n   } n   if (go[now][x][y] ==  H ) n     write(now - 1, x - 1, y,  H ); n   else n     write(now - 1, x, y - 1,  M ); n   if (now != len) printf( %c , ch); n } n signed main() { n   n = read(); n   len = n << 1; n   scanf( %s , str + 1); n   for (long long i = 1; i <= len; i++) { n     c[i] = str[i] -  0 ; n   } n   for (long long i = 1; i <= n; i++) { n     a[i][i] = a[i - 1][i - 1] + c[i] * power(10, n - i); n     go[i][i][0] =  H ; n     b[i][i] = b[i - 1][i - 1] + c[i] * power(10, n - i); n     go[i][0][i] =  M ; n   } n   for (long long i = 1; i <= len; i++) { n     for (long long j = max(i - n, 1ll); j <= min(i - 1ll, n); j++) { n       long long k = i - j, ta = c[i] * power(10, n - j), n                 tb = c[i] * power(10, n - k); n       if (a[i - 1][j - 1] + ta + b[i - 1][k] > n           b[i - 1][k - 1] + tb + a[i - 1][j]) { n         a[i][j] = a[i - 1][j - 1] + ta; n         b[i][k] = b[i - 1][k]; n         go[i][j][k] =  H ; n       } else { n         b[i][k] = b[i - 1][k - 1] + tb; n         a[i][j] = a[i - 1][j]; n         go[i][j][k] =  M ; n       } n     } n   } n   write(len, n, n,    ); n   return 0; n } n


#include<bits/stdc++.h> n #define ll long long n #define vi vector<int> n #define vl vector<ll>  n #define pb push_back n #define FASTANDFURIOUS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); n #define rep(i,a,b) for(ll i=a;i<b;i++) n #define For(i,n) for(ll i=0;i<n;i++) n #define MOD 1000000007 n #define MAX 100001 n #define pll pair <ll,ll> n #define pii pair <int,int> n #define dbg(x)    cout << #x <<  :   << x << endl; n #define fi first n #define se second n #define read(n,v) For(i,n)cin>>v[i] n #define mkp make_pair n #define YES cout<< YES n ; n #define NO cout<< NO n ; n #define No cout<< No n ; n #define Yes cout<< Yes n ; n #define INF 1e18 n using namespace std;  n   n ll ncr2(ll n, ll k ) n { n     if (k > n) return 0; n     if (k * 2 > n) k = n-k; n     if (k == 0) return 1; n   n     ll result = n; n     for(ll i = 2; i <= k; ++i ) { n         result = result * (n-i+1); n         result /= i; n     } n     return result; n } n ll pow(ll x, unsigned int y, int p){ n     ll res=1; n     x=x%p; n     if (x==0) return 0; n     while (y > 0) n     { n         if (y & 1) n             res = (res*x) % p; n         y = y>>1; n         x = (x*x) % p; n     } n     return res; n } n ll _pow(ll a, ll b){ n     if(!b) n         return 1; n     ll temp = _pow(a, b / 2); n     temp = (temp * temp); n     if(b % 2) n         return (a * temp); n     return temp; n } n ll invmod(ll a,ll m){ n     return pow(a,m-2,m); n } n ll feelthepower(ll x,ll y){ n     ll res = 1LL; n     while(y){ n         if(y&1){ n             res = (res*1LL*x)%MOD; n         } n         x = (x*1LL*x)%MOD; n         y/=2; n     } n     return res; n } n // ll ncr(ll n,ll r) n // { n //     if(n<r) n //         return 0; n //     ll ans=fac[n]; n //     ans*=invmod(fac[n-r],MOD); n //     ans%=MOD; n //     ans*=invmod(fac[r],MOD); n //     ans%=MOD; n //     return ans; n // } n bool has(int kek,int d){ n     while(kek){ n         int temp = kek%10; n         if(temp == d){ n             return true; n         } n         kek/=10; n     } n     return false; n } n signed main(){ n     FASTANDFURIOUS; n     #ifndef ONLINE_JUDGE n     freopen( input.txt ,  r , stdin); n     freopen( output.txt ,  w , stdout); n     #endif n     int tc=1; n     cin>>tc; n     For(ti,tc){ n         int n,d; n         cin>>n>>d; n         For(i,n){ n             string s; n             cin>>s; n             if(s.length()>2){ n                 cout<< YES n ; n             } n             else{ n                 int req = stoi(s); n                 int flag=0; n                 while(req>=0){ n                     if(has(req,d)){ n                         flag=1; n                         break; n                     } n                     else{ n                         req-=d; n                    } n                 } n                 if(flag){ n                     cout<< YES n ; n                 } n                 else{ n                     cout<< NO n ; n                 } n             } n         } n     } n }