#include <bits/stdc++.h> n using namespace std; n const int MAXN = 200005; n struct Node { n   int pos, id; n   Node(int p = 0, int i = 0) : pos(p), id(i) {} n   bool operator<(const Node& rhs) const { return pos < rhs.pos; } n } a[MAXN], b[MAXN]; n int m, n; n long long c[3 * MAXN]; n int ans[MAXN]; n void add(int x, int y, int k) { c[x + n] += k, c[y + n] -= k; } n int main() { n   scanf( %d%d , &m, &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i].pos); n     a[i].pos--, a[i].id = i + 1; n   } n   for (int i = 0; i < n; i++) { n     scanf( %d , &b[i].pos); n     b[i].pos--, b[i].id = i + 1; n   } n   sort(a, a + n); n   sort(b, b + n); n   for (int i = 0; i < n; i++) { n     int j = lower_bound(b, b + n, a[i]) - b - i; n     int p = a[i].pos + (m + 1) / 2; n     if (p < m) { n       int k = lower_bound(b, b + n, Node(p)) - b - i; n       add(j, k, -a[i].pos); n       add(k, n - i, a[i].pos + m); n       add(n - i, j + n, a[i].pos); n     } else { n       int k = lower_bound(b, b + n, Node(p - m)) - b - i; n       add(j, n - i, -a[i].pos); n       add(n - i, k + n, m - a[i].pos); n       add(k + n, j + n, a[i].pos); n     } n   } n   for (int i = 0; i < n; i++) { n     int j = i - (upper_bound(a, a + n, b[i]) - a - 1); n     int p = b[i].pos - (m + 1) / 2; n     if (p >= 0) { n       int k = i - (upper_bound(a, a + n, Node(p)) - a - 1); n       add(j, k, b[i].pos); n       add(k, j + n, -b[i].pos); n     } else { n       int k = i - (upper_bound(a, a + n, Node(p + m)) - a - 1); n       add(j, k + n, b[i].pos); n       add(k + n, j + n, -b[i].pos); n     } n   } n   for (int i = 1; i < 3 * n; i++) c[i] += c[i - 1]; n   for (int i = 0; i < n; i++) c[i] += c[i + n] + c[i + 2 * n]; n   int p = min_element(c, c + n) - c; n   printf( %lld n , c[p]); n   for (int i = 0; i < n; i++) ans[a[i].id] = b[(i + p) % n].id; n   for (int i = 1; i <= n; i++) printf( %d  , ans[i]); n   putchar(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Maxn = 1e5 + 1, Mod = 1e9 + 7; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long n, k; n   cin >> n >> k; n   std::vector<int> v(n); n   for (auto &x : v) cin >> x; n   multiset<int> s; n   int pos = -1; n   long long count = 0; n   for (int i = 0; i < n; i++) { n     if (v[i] < 0) { n       count++; n       if (pos != -1) { n         s.insert(i - pos - 1); n       } n       pos = i; n     } n   } n   int fx; n   if (pos != -1) fx = n - 1 - pos; n   if (count > k) { n     cout <<  -1 n ; n     return 0; n   } n   long long ans = 0; n   int flag = 0; n   for (int i = 0; i < n; i++) { n     if (!flag) { n       if (v[i] >= 0) n         continue; n       else { n         ans++; n         flag = flag ^ 1; n       } n     } else { n       if (v[i] < 0) n         continue; n       else { n         ans++; n         flag = flag ^ 1; n       } n     } n   } n   k -= count; n   int fl = 0; n   for (auto x : s) { n     if (x == 0) continue; n     if (k < x) { n       fl = 1; n       if (fx != 0 && x > fx && fx <= k) { n         k -= fx; n         ans -= 1; n       } n       break; n     } n     ans -= 2; n     k -= x; n   } n   if (!fl && fx != 0 && fx <= k) ans -= 1; n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n const unsigned int Mod1 = 1000000009, Mod2 = 1000000007; n const unsigned int Bas1 = 12232, Bas2 = 14124; n struct mybit { n   unsigned long long b[16]; n   mybit() { memset(b, 0, sizeof b); } n   void clear() { memset(b, 0, sizeof b); } n   void flip(int z) { b[z >> 6] ^= 1llu << (z & 63); } n   unsigned int cnt() { n     unsigned int ret = 0; n     for (unsigned int j = 0u; j < 16u; ++j) ret += __builtin_popcount(b[j]); n     return ret; n   } n   unsigned long long calc() { n     unsigned int z1 = 0, z2 = 0; n     for (unsigned int j = 0u; j < 16u; ++j) n       z1 = (z1 + b[j] % Mod1 * Bas1) % Mod1, n       z2 = (z2 + b[j] % Mod2 * Bas2) % Mod2; n     return (unsigned long long)z1 << 32 | z2; n   } n   void operator^=(const mybit &p2) { n     for (unsigned int j = 0u; j < 16u; ++j) b[j] ^= p2.b[j]; n   } n }; n int N, S, Z, Q; n mybit bits[31], now; n std::unordered_map<unsigned long long, int> mp; n void DFS1(int st, int k) { n   if (st > S) { n     unsigned long long z = now.calc(); n     if (mp.find(z) != mp.end()) n       mp[z] = std::min(mp[z], k); n     else n       mp[z] = k; n     return; n   } n   DFS1(st + 1, k); n   now ^= bits[st]; n   DFS1(st + 1, k + 1); n   now ^= bits[st]; n } n int Ans; n void DFS2(int st, int k) { n   if (st > Z) { n     unsigned long long z = now.calc(); n     if (mp.find(z) != mp.end()) Ans = std::min(Ans, k + mp[z]); n     return; n   } n   DFS2(st + 1, k); n   now ^= bits[st]; n   DFS2(st + 1, k + 1); n   now ^= bits[st]; n } n int main() { n   scanf( %d%d%d , &N, &S, &Q), Z = S / 3; n   for (int i = 1; i <= S; ++i) { n     unsigned int c, x; n     scanf( %u , &c); n     while (c--) { n       scanf( %u , &x); n       bits[i].flip(x - 1); n     } n   } n   now.clear(); n   DFS1(Z + 1, 0); n   while (Q--) { n     now.clear(); n     unsigned int c, x; n     scanf( %u , &c); n     while (c--) { n       scanf( %u , &x); n       now.flip(x - 1); n     } n     Ans = S + 1; n     DFS2(1, 0); n     printf( %d n , Ans == S + 1 ? -1 : Ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007LL; n const long long mod2 = 998244353LL; n int n; n int a[100005], b[100005]; n int main() { n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &a[i]); n   } n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &b[i]); n   } n   sort(a + 1, a + n + 1); n   sort(b + 1, b + n + 1); n   long long det = 0; n   int i = n, j = n; n   bool cur = false; n   while (i >= 1 || j >= 1) { n     if (!cur) { n       if (i < 1) { n         j--; n       } else { n         if (j < 1) { n           det += a[i]; n           i--; n         } else { n           if (a[i] >= b[j]) { n             det += a[i]; n             i--; n           } else { n             j--; n           } n         } n       } n     } else { n       if (j < 1) { n         i--; n       } else { n         if (i < 1) { n           det -= b[j]; n           j--; n         } else { n           if (b[j] >= a[i]) { n             det -= b[j]; n             j--; n           } else { n             i--; n           } n         } n       } n     } n     cur = !cur; n   } n   cout << det << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, j, n, m, k, dist, min_count, num; n   vector<int> len_jumps, mosqs, mosq_count, result; n   cin >> n >> m >> k; n   len_jumps.resize(m); n   mosqs.resize(k); n   mosq_count.resize(m); n   for (i = 0; i < m; i++) { n     cin >> len_jumps[i]; n     mosq_count[i] = 0; n   } n   for (i = 0; i < k; i++) { n     cin >> mosqs[i]; n   } n   for (i = 0; i < m; i++) { n     for (j = 0; j < k; j++) { n       if (mosqs[j] % len_jumps[i] == 0) { n         mosq_count[i]++; n       } n     } n   } n   min_count = n; n   for (i = 0; i < m; i++) { n     if (mosq_count[i] < min_count) { n       min_count = mosq_count[i]; n     } n   } n   num = 0; n   for (i = 0; i < m; i++) { n     if (mosq_count[i] == min_count) { n       num++; n       result.push_back(i + 1); n     } n   } n   cout << num << endl; n   for (i = 0; i < result.size() - 1; i++) { n     cout << result[i] <<    ; n   } n   cout << result[result.size() - 1] << endl; n   return 0; n } n


#include <bits/stdc++.h> n const int mod = 1051131, inv2 = (mod + 1) / 2, phi = 700752; n using namespace std; n int n, T, s; n long long w; n int a[33554440]; n void qmo(int &x) { x += (x >> 31) & mod; } n int ksm(int a, int k) { n   int res = 1; n   for (; k; k >>= 1, a = 1ll * a * a % mod) n     if (k & 1) res = 1ll * res * a % mod; n   return res; n } n void calc(int m, int p, int q) { n   if (!m) return a[0] = 1ll * a[0] * ksm(p + q, T) % mod, void(); n   for (int i = 0; i < m; i++) { n     int x = a[i], y = a[i + m]; n     qmo(a[i] = x + y - mod), qmo(a[i + m] = x - y); n   } n   calc(m >> 1, (p << 1) % mod, (q + 1ll * (m - 1) * p) % mod); n   int w = ksm(q - 1ll * (m - 1) * p % mod + mod, T); n   for (int i = 0; i < m; i++) { n     int x = a[i], y = 1ll * a[i + m] * w % mod; n     a[i] = 1ll * (x + y) * inv2 % mod, n     a[i + m] = 1ll * (x - y + mod) * inv2 % mod; n   } n } n int main() { n   scanf( %d%lld%d , &n, &w, &s); n   if (w > phi) n     T = w % phi + phi; n   else n     T = w; n   for (int i = 0; i < s; i++) scanf( %d , &a[i]); n   for (int i = s; i < (1 << n); i++) a[i] = (a[i - s] * 101 + 10007) % mod; n   calc((1 << n) / 2, 1, 0); n   int res = 0; n   for (int i = 0; i < (1 << n); i++) res ^= a[i]; n   printf( %d n , res); n } n


#include <bits/stdc++.h> n using namespace std; n bool isprime(long long n) { n   if (n <= 1) return false; n   if (n <= 3) return true; n   if (n % 2 == 0 || n % 3 == 0) return false; n   for (long long i = 5; i * i <= n; i = i + 6) { n     if (n % i == 0 || n % (i + 2) == 0) return false; n   } n   return true; n } n bool sec(const pair<long long, long long> &a, n          const pair<long long, long long> &b) { n   return a.second > b.second; n } n long long po(long long x, long long y, long long p) { n   long long res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   srand(time(NULL)); n   long long n; n   cin >> n; n   long long a[n], b[n], i, an = 0, m = 998244353; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n     a[i] = a[i] * (i + 1) * (n - i); n   } n   for (i = 0; i < n; i++) cin >> b[i]; n   sort(b, b + n); n   sort(a, a + n); n   for (i = 0; i < n; i++) { n     an += ((a[n - 1 - i] % m) * b[i]) % m; n     an = an % m; n   } n   cout << an; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = 2e5 + 5; n const long long MOD = 1e9 + 7; n const long long INF = 1e18; n mt19937 rnd(time(0)); n signed main() { n   long long q; n   cin >> q; n   while (q--) { n     long long d, mod; n     cin >> d >> mod; n     long long c = 1; n     long long lg = 0; n     while ((1ll << lg) <= d) { n       c = (c * (min(d, (1ll << (lg + 1)) - 1) - (1ll << lg) + 2ll)) % mod; n       lg++; n     } n     c--; n     if (c < 0) { n       c += mod; n     } n     cout << c <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int read() { n   char ch = getchar(); n   int h = 0, t = 1; n   while ((ch >  9  || ch <  0 ) && ch !=  - ) ch = getchar(); n   if (ch ==  - ) t = -1, ch = getchar(); n   while (ch >=  0  && ch <=  9 ) h = h * 10 + ch -  0 , ch = getchar(); n   return h * t; n } n const int N = 2001000; n struct edge { n   int next, to; n } a[N]; n int n, m, Ans, du[N], head[N], cnt = 1; n int dep[N], vis[N], fa[N], ed[N], ve[N]; n void link(int x, int y) { n   a[++cnt] = (edge){head[x], y}; n   head[x] = cnt; n } n void dfs(int x) { n   for (int i = head[x]; i; i = a[i].next) { n     int R = a[i].to; n     if (R == fa[x]) continue; n     if (!dep[R]) n       dep[R] = dep[x] + 1, fa[R] = x, ed[R] = i, dfs(R); n     else if (dep[R] < dep[x]) { n       vis[R] = ve[i] = ve[i ^ 1] = 1; n       for (int p = x; p != R; p = fa[p]) n         vis[p] = 1, ve[ed[p]] = ve[ed[p] ^ 1] = 1; n     } n   } n } n void calctree(int x, int rt) { n   if (!vis[x]) vis[x] = 2; n   int s = 0; n   for (int i = head[x]; i; i = a[i].next) n     if (!ve[i]) ve[i] = ve[i ^ 1] = 1, calctree(a[i].to, rt), s++; n   Ans += (s >> 1) + (x == rt && s & 1); n } n void calccircle(int x) { n   vis[x] = 3; n   for (int i = head[x]; i; i = a[i].next) { n     int R = a[i].to; n     if (R == fa[x]) continue; n     if (vis[R] == 1) n       dep[R] = dep[x] + 1, fa[R] = x, calccircle(R); n     else if (vis[R] == 3 && dep[R] < dep[x]) { n       int s = (du[R] > 2); n       for (int p = x; p != R; p = fa[p]) s += (du[p] > 2); n       Ans += (s < 2); n     } n   } n } n int main() { n   n = read(); n   m = read(); n   for (int i = 1; i <= m; i++) { n     int x = read(), y = read(); n     link(x, y); n     link(y, x); n     du[x]++; n     du[y]++; n   } n   for (int i = 1; i <= n; i++) n     if (!dep[i]) dep[i] = 1, dfs(i); n   for (int i = 1; i <= n; i++) n     if (vis[i]) calctree(i, i); n   for (int i = 1; i <= n; i++) n     if (!vis[i]) calctree(i, i); n   for (int i = 1; i <= n; i++) n     if (vis[i] == 1) dep[i] = 1, fa[i] = 0, calccircle(i); n   printf( %d %d n , Ans, m); n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int main() { n   cin >> n >> m; n   cout << min(n, m) + 1 << endl; n   for (int i = 0; i < min(n, m) + 1; i++) { n     cout << i <<     << min(n, m) - i << 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   long long int a[100]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   int m = a[0]; n   for (int i = 1; i < n; i++) { n     if (a[i] > m) { n       m = a[i]; n     } n   } n   int o = 0; n   for (int i = 0; i < n; i++) { n     o = o + (m - a[i]); n   } n   cout << o; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 500005, maxd = 20; n int jump[maxd][maxn], range[maxd][maxn]; n int a[maxn], L[maxn], lmin[maxd][maxn]; n int n; n int getminL(int a, int b) { return L[a] < L[b] ? a : b; } n int getmin(int a, int b) { n   int k = b - a + 1 ? 31 - __builtin_clz(b - a + 1) : 0; n   return getminL(lmin[k][a], lmin[k][b - (1 << k) + 1]); n } n int main() { n   int i, x, d, ld; n   scanf( %d , &n); n   for (ld = 0; (1 << ld) <= n; ++ld) n     ; n   for (i = 1; i <= n; ++i) scanf( %d , a + i), a[i + n] = a[i]; n   for (i = 1; i <= n + n; ++i) L[i] = max(i - a[i], 0), lmin[0][i] = i; n   for (d = 1; d < ld; ++d) n     for (i = 1; i <= n + n - (1 << d) + 1; ++i) n       lmin[d][i] = getminL(lmin[d - 1][i], lmin[d - 1][i + (1 << (d - 1))]); n   for (i = 1; i <= n + n; ++i) { n     jump[0][i] = getmin(L[i], i); n     range[0][i] = L[i]; n     for (d = 1; range[d - 1][i]; ++d) n       jump[d][i] = jump[d - 1][jump[d - 1][i]], n       range[d][i] = range[d - 1][jump[d - 1][i]]; n   } n   long long ans = 0; n   for (i = n; i < n + n; ++i) n     for (d = ld - 1, x = i, ++ans; d >= 0; --d) n       if (range[d][x] > i - n + 1) ans += 1 << d, x = jump[d][x]; n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int OO = 1e9; n const long long INF = 1e18; n const int irand(int lo, int hi) { n   return ((double)rand() / (RAND_MAX + 1.0)) * (hi - lo + 1) + lo; n } n const long long lrand(long long lo, long long hi) { n   return ((double)rand() / (RAND_MAX + 1.0)) * (hi - lo + 1) + lo; n } n template <typename T> n T getnum() { n   int sign = 1; n   T ret = 0; n   char c; n   do { n     c = getchar(); n   } while (c ==     || c ==   n ); n   if (c ==  - ) n     sign = -1; n   else n     ret = c -  0 ; n   while (1) { n     c = getchar(); n     if (c <  0  || c >  9 ) break; n     ret = 10 * ret + c -  0 ; n   } n   return sign * ret; n } n inline void ini(int& x) { x = getnum<int>(); } n inline void scani(int& x) { scanf( %d , &x); } n int n, m; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   if (n * m > 2 && (n == 1 || m == 1)) { n     cout << 1 << endl; n     cout << n <<     << m <<   1 1  << endl; n     if (n == 1) { n       for (int j = 1; j <= m; j += 1) cout << 1 <<     << j << endl; n     } else { n       for (int i = 1; i <= n; i += 1) cout << i <<     << 1 << endl; n     } n     cout <<  1 1  << endl; n   } else if ((n * m) & 1) { n     cout << 1 << endl; n     cout << n <<     << m <<   1 1  << endl; n     for (int i = 1; i <= n; i += 1) { n       if (i & 1) { n         for (int j = 1; j <= m; j += 1) { n           cout << i <<     << j << endl; n         } n       } else { n         for (int j = m; j >= 1; j -= 1) { n           cout << i <<     << j << endl; n         } n       } n     } n     cout <<  1 1  << endl; n   } else { n     cout << 0 << endl; n     cout <<  1 1  << endl; n     if (m & 1) { n       for (int i = 1; i <= n; i += 1) { n         if (i & 1) { n           for (int j = 2; j <= m; j += 1) cout << i <<     << j << endl; n         } else { n           for (int j = m; j >= 2; j -= 1) cout << i <<     << j << endl; n         } n       } n       for (int i = n; i >= 1; i -= 1) cout << i <<     << 1 << endl; n     } else { n       for (int j = 1; j <= m; j += 1) { n         if (j & 1) { n           for (int i = 2; i <= n; i += 1) cout << i <<     << j << endl; n         } else { n           for (int i = n; i >= 2; i -= 1) cout << i <<     << j << endl; n         } n       } n       for (int j = m; j >= 1; j -= 1) cout << 1 <<     << j << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e9; n const long long Inf = 1e18; n const int N = 2e5 + 10; n const int mod = 0; n long long gi() { n   long long x = 0, o = 1; n   char ch = getchar(); n   while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar(); n   if (ch ==  - ) o = -1, ch = getchar(); n   while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar(); n   return x * o; n } n template <typename T> n bool chkmax(T &a, T b) { n   return a < b ? a = b, 1 : 0; n }; n template <typename T> n bool chkmin(T &a, T b) { n   return a > b ? a = b, 1 : 0; n }; n int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; } n int sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; } n void inc(int &a, int b) { a = (a + b >= mod ? a + b - mod : a + b); } n void dec(int &a, int b) { a = (a - b < 0 ? a - b + mod : a - b); } n int n, x[N], sum[N]; n long long a[N], t, b[N]; n int main() { n   cin >> n >> t; n   for (int i = 1; i <= n; i++) a[i] = gi(); n   for (int i = 1; i <= n; i++) x[i] = gi(); n   for (int i = 1; i <= n; i++) { n     if (x[i] < i) return puts( No ), 0; n     sum[i]++; n     sum[x[i]]--; n   } n   for (int i = 1; i <= n; i++) { n     sum[i] += sum[i - 1]; n     b[i] = a[i] + t; n     if (sum[i]) b[i] = a[i + 1] + t; n     chkmax(b[i], b[i - 1] + 1); n   } n   for (int i = 1; i <= n; i++) n     if (x[i] != n && b[x[i]] >= a[x[i] + 1] + t) return puts( No ), 0; n   puts( Yes ); n   for (int i = 1; i <= n; i++) printf( %lld  , b[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int sum, n, m, i, j, ans, a[1000001], v[1000001], cnt[1000001]; n int main() { n   scanf( %d%d , &n, &m); n   for (i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (i = 1; i <= n; i++) n     for (j = i + 1; j <= n; j++) cnt[abs(a[i] - a[j])]++; n   for (i = 1; i <= 1e6; i++) { n     sum = 0; n     for (j = i; j <= 1e6; j += i) sum += cnt[j]; n     if (sum > (m + 1) * m / 2) continue; n     for (j = 1; j <= n; j++) { n       if (v[a[j] % i] == i) ans++; n       v[a[j] % i] = i; n     } n     if (ans <= m) { n       printf( %d , i); n       return 0; n     } n     ans = 0; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long int N = 1e6, mod = 1e9 + 7, inf = 1e10; n long long int a[N], dp[N]; n int main() { n   long long int n, mn = 0, mx = -1, ans_1 = 0, ans_2 = 0, cnt, clk, clr; n   cin >> n; n   for (long long int i = 1; i * i * i <= n; i++) { n     if (n % i == 0) { n       for (long long int j = 1; j * j <= (n / i); j++) { n         long long int k = n / (i * j); n         if (i * j * k == n) { n           cnt = (i + 1) * (j + 2) * (k + 2); n           if (mn == 0) mn = cnt; n           mn = min(mn, cnt); n           mx = max(mx, cnt); n           clk = (i + 2) * (j + 1) * (k + 2); n           mn = min(mn, clk); n           mx = max(mx, clk); n           clr = (i + 2) * (j + 2) * (k + 1); n           mn = min(mn, clr); n           mx = max(mx, clr); n         } n       } n     } n   } n   ans_1 = mn - n; n   ans_2 = mx - n; n   cout << ans_1 <<    ; n   return cout << (ans_2), 0; n } n


#include <bits/stdc++.h> n int arr[150]; n int temp[150]; n int main() { n   int n, m; n   std::cin >> n >> m; n   for (int i = 0; i < n; ++i) { n     int a, b; n     std::cin >> a >> b; n     for (int j = a; j <= b; ++j) arr[j]++; n   } n   int cnt = 0; n   for (int i = 1; i <= m; ++i) { n     if (!arr[i]) temp[cnt++] = i; n   } n   std::cout << cnt << std::endl; n   for (int i = 0; i < cnt; ++i) { n     if (!i) n       std::cout << temp[i]; n     else n       std::cout <<     << temp[i]; n   } n   if (cnt) std::cout << std::endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 6000; n int dp[N][N], len[N], dep[N], sz[N], n, k, val[N]; n char S[N * 300]; n char *s[N]; n struct Edge { n   int L, len; n   int to; n   Edge(int L = 0, int len = 0, int to = 0) : L(L), len(len), to(to) {} n } d[N][26]; n inline int idx(int c) { return c -  a ; } n void dfs(int x) { n   sz[x] = val[x]; n   for (int i = 0; i <= sz[x]; i++) dp[x][i] = dep[x] * i * (i - 1) / 2; n   for (int i = 0; i < 26; i++) n     if (d[x][i].to) { n       int u = d[x][i].to; n       dep[u] = dep[x] + d[x][i].len; n       dfs(u); n       sz[x] += sz[u]; n       for (int i = sz[x]; i >= 0; i--) { n         int xx = 0; n         for (int j = 0; j <= sz[u] && j <= i; j++) n           xx = max(xx, dp[x][i - j] + dp[u][j] + j * (i - j) * dep[x]); n         dp[x][i] = xx; n       } n     } n } n int xb; n int main() { n   scanf( %d%d , &n, &k); n   s[0] = S; n   xb = 1; n   for (int i = 1; i <= n; i++) { n     s[i] = s[i - 1] + len[i - 1]; n     scanf( %s , s[i]); n     len[i] = strlen(s[i]); n     int q = 1; n     for (int j = 0; j < len[i];) { n       int c = idx(s[i][j]); n       if (d[q][c].to) { n         for (int k = 0; k < d[q][c].len && j + k <= len[i]; k++) n           if (s[i][j + k] != S[d[q][c].L + k]) { n             int p = d[q][c].to; n             d[q][c].to = ++xb; n             int nq = xb; n             if (j + k < len[i]) d[nq][idx(s[i][j + k])].to = ++xb; n             d[nq][idx(S[d[q][c].L + k])].to = p; n             if (j + k < len[i]) { n               d[nq][idx(s[i][j + k])].L = (&s[i][j + k]) - S; n               d[nq][idx(s[i][j + k])].len = len[i] - j - k; n             } n             d[nq][idx(S[d[q][c].L + k])].L = d[q][c].L + k; n             d[nq][idx(S[d[q][c].L + k])].len = d[q][c].len - k; n             d[q][c].len = k; n             break; n           } n       } else { n         d[q][c].L = (&s[i][j]) - S; n         d[q][c].len = len[i] - j; n         d[q][c].to = ++xb; n       } n       j += d[q][c].len; n       q = d[q][c].to; n     } n     val[q]++; n   } n   dfs(1); n   printf( %d n , dp[1][k]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long i, j = 0, k = 0, l = 0, m = 0, n, t = 0, sum = 0, r = 0, q = 0, p = 0, n              z = 0; n int a[2000005]; n vector<int> v; n int main() { n   ios_base::sync_with_stdio(false); n   string s, f, g; n   cin >> m >> f >> g; n   n = g.size(); n   if (g[n - 1] ==  k ) n     t = 0; n   else n     t = 1; n   if (t == 1) { n     if (m < 30) n       cout <<  12 ; n     else if (m == 31) n       cout <<  7 ; n     else n       cout <<  11 ; n   } else { n     if (m == 5 || m == 6) n       cout <<  53 ; n     else n       cout <<  52 ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b, n; n short ans = 0; n int main() { n   cin >> a >> b; n   while (b > 0) { n     if (b == 1) { n       ans = 0; n       break; n     } n     if (b % a != 0) { n       ans = 1; n       break; n     } n     ++n; n     b = b / a; n   } n   if (ans == 0) { n     cout <<  YES  << endl; n     cout << n - 1; n   } else n     cout <<  NO  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int Nmax = 2e5 + 17; n inline int sqr(int x) { return x * x; } n int main(void) { n   int a[6]; n   for (int i = 0; i < 6; i++) cin >> a[i]; n   cout << sqr(a[0] + a[1] + a[2]) - sqr(a[0]) - sqr(a[2]) - sqr(a[4]); n } n


#include <bits/stdc++.h> n using std::cin; n using std::cout; n using std::ios; n using std::sort; n const int MAX = 1e3 + 2; n int a[MAX]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL), cout.tie(NULL); n   int n = 0; n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   sort(a + 1, a + n + 1); n   cout << a[(n + 1) / 2] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, K; n int hardcode[11] = {0, 1, 0, 1, 2, 0, 2, 0, 1, 0, 1}; n int get_sprague_1(int val) { n   int tmp = val; n   while (tmp % 4 == 0) { n     tmp /= 4; n   } n   if (val <= 10) { n     return hardcode[val]; n   } else if (tmp == 6 || (val % 4 == 0 && tmp % 2 == 1 && tmp != 3)) { n     return 2; n   } else { n     return (val + 1) % 2; n   } n } n int get_sprague_2(int val) { n   if (val == 1) { n     return 1; n   } else if (val == 2) { n     return 2; n   } else { n     return (val + 1) % 2; n   } n } n int main() { n   cin.tie(0); n   cin.sync_with_stdio(0); n   cin >> N >> K; n   int xorv = 0; n   if (K % 2 == 1) { n     for (int a = 1; a <= N; a++) { n       int x; n       cin >> x; n       xorv ^= get_sprague_1(x); n     } n   } else { n     for (int a = 1; a <= N; a++) { n       int x; n       cin >> x; n       xorv ^= get_sprague_2(x); n     } n   } n   if (xorv == 0) { n     cout <<  Nicky ; n   } else { n     cout <<  Kevin ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n namespace zzc { n inline int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) { n     x = x * 10 + ch - 48; n     ch = getchar(); n   } n   return x * f; n } n const int maxn = 2e5 + 5; n int ans = 0x3f3f3f3f; n char s[3][maxn]; n int nxt[3][maxn], len[3], overlap[3][3]; n void init(int id) { n   for (int i = 2, j = 0; i <= len[id]; i++) { n     while (j && s[id][i] != s[id][j + 1]) j = nxt[id][j]; n     if (s[id][i] == s[id][j + 1]) j++; n     nxt[id][i] = j; n   } n } n int kmp(int x, int y) { n   int j = 0; n   for (int i = 1; i <= len[x]; i++) { n     while (j && s[x][i] != s[y][j + 1]) j = nxt[y][j]; n     if (s[x][i] == s[y][j + 1]) j++; n     if (j == len[y]) return len[y]; n   } n   return j; n } n int calc(int x, int y, int z) { n   if (overlap[x][y] == len[y] && overlap[y][z] == len[z]) n     return len[x]; n   else if (overlap[x][y] == len[y]) n     return len[x] + len[z] - overlap[x][z]; n   else if (overlap[y][z] == len[z]) n     return len[x] + len[y] - overlap[x][y]; n   else n     return len[x] + len[y] + len[z] - overlap[x][y] - overlap[y][z]; n } n void work() { n   for (int i = 0; i <= 2; i++) n     scanf( %s , s[i] + 1), len[i] = strlen(s[i] + 1), init(i); n   for (int i = 0; i <= 2; i++) n     for (int j = 0; j <= 2; j++) n       if (i != j) overlap[i][j] = kmp(i, j); n   ans = min(ans, calc(0, 1, 2)); n   ans = min(ans, calc(0, 2, 1)); n   ans = min(ans, calc(1, 0, 2)); n   ans = min(ans, calc(1, 2, 0)); n   ans = min(ans, calc(2, 0, 1)); n   ans = min(ans, calc(2, 1, 0)); n   printf( %d n , ans); n } n }  // namespace zzc n int main() { n   zzc::work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double dist(double x1, double y1, double x2, double y2) { n   return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); n } n bool have(long long x1, long long y1, long long x2, long long y2, long long x, n           long long y) { n   long long A = y1 - y2; n   long long B = x2 - x1; n   long long C = (x1 * y2 - x2 * y1); n   if (A * x + B * y + C != 0LL) return false; n   long long a = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); n   long long b = (x1 - x) * (x1 - x) + (y1 - y) * (y1 - y); n   long long c = (x2 - x) * (x2 - x) + (y2 - y) * (y2 - y); n   if (b > a || c > a) return false; n   if (b > c) swap(b, c); n   return (16LL * b >= c); n } n bool solve() { n   long long x1[4], y1[4], x2[4], y2[4]; n   for (int i = 1; i <= 3; i++) { n     int a, b, c, d; n     scanf( %d%d%d%d , &a, &b, &c, &d); n     x1[i] = a, y1[i] = b, x2[i] = c, y2[i] = d; n   } n   int p = -1, q = -1, l = -1; n   for (int i = 1; i <= 3; i++) n     for (int j = i + 1; j <= 3; j++) { n       if (x1[i] == x1[j] && y1[i] == y1[j]) p = i, q = j; n       if (x1[i] == x2[j] && y1[i] == y2[j]) p = i, q = j; n       if (x2[i] == x1[j] && y2[i] == y1[j]) p = i, q = j; n       if (x2[i] == x2[j] && y2[i] == y2[j]) p = i, q = j; n     } n   if (p == -1 || q == -1) return false; n   l = 1; n   if (p == 1 && q == 2) l = 3; n   if (p == 1 && q == 3) l = 2; n   if (x1[p] == x2[q] && y1[p] == y2[q]) n     swap(x1[q], x2[q]), swap(y1[q], y2[q]); n   else if (x2[p] == x1[q] && y2[p] == y1[q]) n     swap(x1[p], x2[p]), swap(y1[p], y2[p]); n   else if (x2[p] == x2[q] && y2[p] == y2[q]) n     swap(x1[q], x2[q]), swap(y1[q], y2[q]), swap(x1[p], x2[p]), n         swap(y1[p], y2[p]); n   double a = dist(x1[p], y1[p], x2[p], y2[p]); n   double b = dist(x1[q], y1[q], x2[q], y2[q]); n   double c = dist(x2[p], y2[p], x2[q], y2[q]); n   double cs = (a * a + b * b - c * c) / 2.0 / a / b; n   if (cs >= 0 && cs < 1) { n     if (have(x1[p], y1[p], x2[p], y2[p], x1[l], y1[l]) && n         have(x1[q], y1[q], x2[q], y2[q], x2[l], y2[l])) n       return true; n     if (have(x1[p], y1[p], x2[p], y2[p], x2[l], y2[l]) && n         have(x1[q], y1[q], x2[q], y2[q], x1[l], y1[l])) n       return true; n   } n   return false; n } n int main() { n   int t; n   scanf( %d , &t); n   for (int i = 0; i < t; i++) { n     int gd = solve(); n     if (gd) n       printf( YES n ); n     else n       printf( NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string s; n   cin >> s; n   int ct = 0, i, j; n   map<char, int> mp1; n   int len = s.length(); n   int bc, rc, gc; n   gc = rc = bc = 0; n   for (i = 0; i < len; i++) { n     if (s[i] ==  R ) rc++; n     if (s[i] ==  G ) gc++; n     if (s[i] ==  B ) bc++; n   } n   if (gc > 0 && bc > 0 && rc > 0) n     printf( BGR n ); n   else if (gc == 0) { n     if (rc == 0) n       printf( B ); n     else if (bc == 0) n       printf( R ); n     else if (rc == 1 && bc == 1) n       printf( G ); n     else if (rc > 1 && bc == 1) n       printf( BG ); n     else if (bc > 1 && rc == 1) n       printf( GR ); n     else n       printf( BGR ); n   } else if (bc == 0) { n     if (gc == 0) n       printf( R ); n     else if (rc == 0) n       printf( G ); n     else if (gc == 1 && rc == 1) n       printf( B ); n     else if (rc > 1 && gc == 1) n       printf( BG ); n     else if (gc > 1 && rc == 1) n       printf( BR ); n     else n       printf( BGR ); n   } else if (rc == 0) { n     if (gc == 0) n       printf( B ); n     else if (bc == 0) n       printf( G ); n     else if (gc == 1 && bc == 1) n       printf( R ); n     else if (bc > 1 && gc == 1) n       printf( GR ); n     else if (gc > 1 && bc == 1) n       printf( BR ); n     else n       printf( BGR ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100005, M = 1000000007; n int n, i, a, b, n1, n2; n struct str { n   int a, b, t; n } s1[300005], s2[300005]; n bool cmp1(str a, str b) { return a.a > b.a; } n bool cmp2(str a, str b) { return a.a < b.a; } n int main() { n   scanf( %d , &n); n   for (i = 1; i <= n; i++) { n     scanf( %d %d , &a, &b); n     if (a < b) n       s1[++n1] = (str){a, b, i}; n     else n       s2[++n2] = (str){a, b, i}; n   } n   if (n1 > n2) { n     sort(s1 + 1, s1 + 1 + n1, cmp1); n     printf( %d n , n1); n     for (i = 1; i <= n1; i++) printf( %d  , s1[i].t); n   } else { n     sort(s2 + 1, s2 + 1 + n2, cmp2); n     printf( %d n , n2); n     for (i = 1; i <= n2; i++) printf( %d  , s2[i].t); n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> v; n void solve(int n) { n   int m = 1; n   while (n > 0) { n     if (n & 1) v.push_back(m); n     n >>= 1; n     m++; n   } n   reverse(v.begin(), v.end()); n } n int main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); n   int n; n   cin >> n; n   solve(n); n   for (auto it : v) { n     cout << it <<    ; n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const int MAXN = 100; n struct mtx { n   int d[MAXN][MAXN]; n   int r, c; n }; n mtx operator*(const mtx l, const mtx r) { n   mtx res; n   res.r = l.r; n   res.c = r.c; n   assert(l.c == r.r); n   for (int i = 0; i < res.r; i++) n     for (int j = 0; j < res.c; j++) { n       int sm = 0; n       for (int k = 0; k < l.c; k++) { n         sm += 1ll * l.d[i][k] * r.d[k][j] % mod; n         sm %= mod; n       } n       res.d[i][j] = sm; n     } n   return res; n } n void idmtx(mtx &m) { n   assert(m.r == m.c); n   for (int i = 0; i < m.r; i++) { n     for (int j = 0; j < m.c; j++) { n       m.d[i][j] = i == j; n     } n   } n } n mtx mtxpow(const mtx m, long long p) { n   mtx r; n   r.r = r.c = m.r; n   idmtx(r); n   mtx c = m; n   for (; p; p >>= 1) { n     if (p & 1) r = r * c; n     c = c * c; n   } n   return r; n } n void printmtx(const mtx m) { n   cout <<  MTX ----   << endl; n   for (int i = 0; i < m.r; i++) { n     for (int j = 0; j < m.c; j++) { n       cout << m.d[i][j] <<    ; n     } n     cout << endl; n   } n } n int main() { n   long long n; n   int m; n   cin >> n >> m; n   mtx rm; n   rm.r = rm.c = m; n   for (int i = 0; i < m; i++) { n     for (int j = 0; j < m; j++) { n       rm.d[i][j] = 0; n       if (i == j) rm.d[i][j] += 1; n       if (j == 0) { n         rm.d[i][j] += i == m - 1 ? 1 : 0; n       } else { n         rm.d[i][j] += rm.d[i][j - 1]; n       } n       rm.d[i][j] %= mod; n     } n   } n   long long off = (n - 1) % m, k = (n - 1) / m; n   mtx res = mtxpow(rm, k + 1); n   cout << res.d[m - 1][off] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n; n   long double s; n   cin >> n >> s; n   vector<long long> cnt(n); n   for (long long i = 0; i < n - 1; ++i) { n     long long u, v; n     cin >> u >> v; n     --u; n     --v; n     ++cnt[u]; n     ++cnt[v]; n   } n   long long ans = 0; n   for (long long i = 0; i < n; ++i) ans += (cnt[i] == 1); n   cout << setprecision(20) << 2.0 * s / ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   char n[10005]; n   scanf( %[^ n] , n); n   int len = strlen(n); n   char temp[len + 1]; n   int j = 0; n   for (int i = 0; i < len; i++) { n     if (n[i] >=  a  && n[i] <=  z ) { n       temp[j] = n[i]; n       j++; n     } else if (n[i] ==    ) { n       if (n[i - 1] ==    ) { n         continue; n       } else if (n[i + 1] ==     && n[i - 1] ==    ) { n         continue; n       } else { n         temp[j] = n[i]; n         j++; n       } n     } else if (n[i] ==  ,  || n[i] ==  ?  || n[i] ==  .  || n[i] ==  ! ) { n       if (n[i - 1] ==    ) { n         j--; n         temp[j] = n[i]; n         j++; n       } else { n         temp[j] = n[i]; n         j++; n       } n       if (n[i + 1] !=    ) { n         temp[j] =    ; n         j++; n       } n     } n   } n   temp[j] =   0 ; n   printf( %s n , temp); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void print(vector<int> s) { n   for (int i = 0; i < s.size(); i++) cout << s[i] <<    ; n   cout << endl; n } n const int INF = 1e9 + 7; n char next(char v) { n   if (v ==  R ) return  L ; n   if (v ==  L ) return  R ; n   if (v ==  U ) return  D ; n   if (v ==  D ) return  U ; n } n int now(char v) { n   if (v ==  R ) return 1; n   if (v ==  L ) return 3; n   if (v ==  U ) return 0; n   if (v ==  D ) return 2; n } n int main() { n   int n; n   cin >> n; n   string s; n   cin >> s; n   vector<int> dp(n, INF); n   dp[0] = 1; n   vector<int> last(4, -1); n   last[now(s[0])] = 0; n   for (int i = 1; i < n; i++) { n     int a = last[now(next(s[i]))]; n     int b = last[(now(s[i]) + 1) % 4]; n     int c = last[(now(s[i]) + 3) % 4]; n     int d = min(b, c); n     last[now(s[i])] = i; n     if (a == -1 && d == -1) { n       dp[i] = 1; n       continue; n     } n     if (a == -1) { n       dp[i] = min(dp[i], dp[d] + 1); n       continue; n     } n     if (d == -1) { n       dp[i] = min(dp[i], dp[a] + 1); n       continue; n     } n     dp[i] = min(dp[i], dp[max(a, d)] + 1); n   } n   cout << dp[n - 1] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a, b, n; n const int MOD = 1e9 + 7; n long long fac[1111111]; n bool ok(int x) { n   while (x) { n     if (x % 10 == a || x % 10 == b) { n       x /= 10; n     } else n       return 0; n   } n   return 1; n } n void init() { n   fac[0] = fac[1] = 1; n   for (int i = 2; i <= 1000000; i++) { n     fac[i] = (fac[i - 1] * i) % MOD; n   } n } n void gcd(long long a, long long b, long long& d, long long& x, long long& y) { n   if (!b) { n     d = a; n     x = 1; n     y = 0; n   } else { n     gcd(b, a % b, d, y, x); n     y -= x * (a / b); n   } n } n long long inv(long long a, long long n) { n   long long d, x, y; n   gcd(a, n, d, x, y); n   return d == 1 ? (x + n) % n : -1; n } n long long C(int n, int m) { n   return fac[n] * inv(fac[m] * fac[n - m] % MOD, MOD) % MOD; n } n int main() { n   init(); n   long long ans; n   int len; n   while (scanf( %d%d%d , &a, &b, &n) != EOF) { n     ans = 0; n     for (len = 0; len <= n; len++) { n       if (ok(a * len + b * (n - len))) ans = (ans + C(n, len)) % MOD; n     } n     printf( %I64d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 3e5 + 10; n bool vis[10005][10005], rev[10005]; n struct E { n   int nxt, to; n } e[MAXN]; n int tot, head[MAXN]; n inline void add(int x, int y) { n   e[++tot] = (E){head[x], y}; n   head[x] = tot; n } n int opt[MAXN], X[MAXN], Y[MAXN], s[MAXN], m, n, q; n long long ans[MAXN]; n void dfs(int x, int sum) { n   int tmp = 0, i = x; n   if (opt[i] == 1) { n     if (vis[X[i]][Y[i]] == rev[X[i]]) n       tmp = 1, ++sum, ++s[X[i]], vis[X[i]][Y[i]] = !rev[X[i]]; n   } n   if (opt[i] == 2) { n     if (vis[X[i]][Y[i]] != rev[X[i]]) n       tmp = 1, --sum, --s[X[i]], vis[X[i]][Y[i]] = rev[X[i]]; n   } n   if (opt[i] == 3) { n     sum += m - s[X[i]] - s[X[i]]; n     rev[X[i]] ^= 1; n     s[X[i]] = m - s[X[i]]; n   } n   ans[i] = sum; n   for (int i = head[x]; i; i = e[i].nxt) dfs(e[i].to, sum); n   if (opt[x] == 1 && tmp) --sum, --s[X[i]], vis[X[i]][Y[i]] = rev[X[i]]; n   if (opt[x] == 2 && tmp) ++sum, ++s[X[i]], vis[X[i]][Y[i]] = !rev[X[i]]; n   if (opt[x] == 3) n     sum -= m - s[X[i]] - s[X[i]], rev[X[i]] ^= 1, s[X[i]] = m - s[X[i]]; n } n int main() { n   scanf( %d%d%d , &n, &m, &q); n   for (int i = 1; i <= q; ++i) { n     scanf( %d%d , &opt[i], &X[i]); n     if (opt[i] < 3) scanf( %d , &Y[i]); n     if (opt[i] == 4) n       add(X[i], i); n     else n       add(i - 1, i); n   } n   dfs(0, 0); n   for (int i = 1; i <= q; ++i) printf( %lld n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     vector<int> v(n); n     for (int i = 0; i < n; i++) cin >> v[i]; n     int u = 1e9; n     for (int a = 0; a <= 2; a++) { n       for (int b = 0; b <= 2; b++) { n         bool g = true; n         int r = 0; n         for (int i = 0; i < n; i++) { n           bool f = false; n           int m = 1e9; n           for (int x = 0; x <= a; x++) { n             for (int y = 0; y <= b; y++) { n               int s = v[i] - x - 2 * y; n               if (s >= 0 && s % 3 == 0) { n                 f = true; n                 m = min(m, s / 3); n               } n             } n           } n           if (f) n             r = max(r, a + b + m); n           else n             g = false; n         } n         if (g) u = min(u, r); n       } n     } n     cout << u <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n const int INF = 1e9 + 5; n const long long INF64 = 1e18; n template <typename T> n string to_string(const vector<T>& v) { n   string ret =  < ; n   for (auto it : v) { n     ret += to_string(it) +  ,  ; n   } n   ret.pop_back(); n   ret.pop_back(); n   ret +=  > ; n   return ret; n } n void debug_print() { cerr << endl; } n template <typename T, typename... U> n void debug_print(T t, U... u) { n   cerr <<     << to_string(t); n   debug_print(u...); n } n const int N = 1e5 + 5; n void normalize(string& s, int m) { n   reverse(s.begin(), s.end()); n   while (s.size() < m) s.push_back( 0 ); n   reverse(s.begin(), s.end()); n } n string a, b; n int solve() { n   if (a.size() == 1) { n     return a[0] == b[0] ? 0 : a[0] > b[0] ? 1 : -1; n   } n   for (int i = 0; i < a.size() - 2; i++) { n     if (a[i] == b[i]) continue; n     int mx = min(a[i], b[i]); n     a[i] -= mx; n     b[i] -= mx; n     if (a[i] >= 2) return 1; n     if (b[i] >= 2) return -1; n     if (a[i] > 0) { n       a[i + 1]++; n       a[i + 2]++; n     } n     if (b[i] > 0) { n       b[i + 1]++; n       b[i + 2]++; n     } n   } n   if (a[a.size() - 2] != b[a.size() - 2]) { n     return a[a.size() - 2] == b[a.size() - 2]  ? 0 n            : a[a.size() - 2] > b[a.size() - 2] ? 1 n                                                : -1; n   } n   if (a.back() != b.back()) { n     return a.back() == b.back() ? 0 : a.back() > b.back() ? 1 : -1; n   } n   return 0; n } n int main() { n   cin >> a >> b; n   if (a.size() > b.size()) n     normalize(b, a.size()); n   else n     normalize(a, b.size()); n   int ans = solve(); n   if (ans == 0) n     cout <<  =  << endl; n   else if (ans == 1) n     cout <<  >  << endl; n   else n     cout <<  <  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   vector<pair<int, int> > v(n); n   multiset<int> l, r; n   for (int i = 0; i < n; i++) { n     scanf( %d%d , &v[i].first, &v[i].second); n     l.insert(v[i].first); n     r.insert(v[i].second); n   } n   int ans = 0; n   for (int i = 0; i < n; i++) { n     l.erase(l.find(v[i].first)); n     r.erase(r.find(v[i].second)); n     ans = max(ans, *r.begin() - *--l.end()); n     l.insert(v[i].first); n     r.insert(v[i].second); n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int r[305]; n int main() { n   int p, n; n   cin >> p >> n; n   int a[n + 5]; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   int sum = 0, c = 0, f = -1; n   for (int i = 1; i <= n; i++) { n     c = a[i] % p; n     if (r[c] == 0) { n       f = -1; n       r[c]++; n     } else { n       f = i; n       break; n     } n   } n   cout << f << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = (int)1e6 + 123; n const long long INF = (long long)1e18 + 123; n const int inf = (int)1e9 + 123; n const int MOD = (int)1e9 + 7; n void megaRandom() { n   unsigned int FOR; n   asm( rdtsc  :  =A (FOR)); n   srand(FOR); n } n int n; n vector<int> g[N]; n long double res; n void dfs(int x, int pr = 0, int h = 1) { n   if (h > 0) res += (1.0 / h); n   for (auto to : g[x]) { n     if (to == pr) continue; n     dfs(to, x, h + 1); n   } n } n int main() { n   megaRandom(); n   cin >> n; n   for (int i = 1, x, y; i < n; i++) { n     cin >> x >> y; n     g[x].push_back(y), g[y].push_back(x); n   } n   dfs(1); n   cout << fixed << setprecision(6) << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 998244353; n const int N = 2010; n int f[N][N], g[N], dp[N]; n int p[N], ip[N]; n int power(int x, int y) { n   int ret = 1; n   for (; y; y >>= 1, x = 1ll * x * x % mod) { n     if (y & 1) ret = 1ll * ret * x % mod; n   } n   return ret; n } n int main() { n   int i, j; n   int x, y, n; n   scanf( %d , &n); n   scanf( %d%d , &x, &y); n   x = 1ll * x * power(y, mod - 2) % mod; n   p[0] = 1; n   for (i = 1; i <= n; i++) p[i] = 1ll * p[i - 1] * x % mod; n   ip[0] = 1; n   for (i = 1; i <= n; i++) ip[i] = 1ll * ip[i - 1] * (1 - x + mod) % mod; n   f[0][0] = 1; n   for (i = 1; i <= n; i++) n     for (j = 0; j <= i; j++) n       f[i][j] = (1ll * f[i - 1][j] * p[j] + n                  (j == 0 ? 0 : 1ll * f[i - 1][j - 1] * ip[i - j])) % n                 mod; n   g[1] = 1; n   for (i = 2; i <= n; i++) { n     g[i] = 1; n     for (j = 1; j <= i - 1; j++) g[i] = (g[i] - 1ll * g[j] * f[i][j]) % mod; n     g[i] = (g[i] + mod) % mod; n   } n   dp[1] = 0; n   for (i = 2; i <= n; i++) { n     dp[i] = i * (i - 1) / 2; n     dp[i] = 1ll * dp[i] * g[i] % mod; n     for (j = 1; j <= i - 1; j++) n       dp[i] = (dp[i] + 1ll * g[j] * f[i][j] % mod * n                            (dp[j] + j * (j - 1) / 2 + dp[i - j])) % n               mod; n     dp[i] = 1ll * dp[i] * power(1 - g[i] + mod, mod - 2) % mod; n   } n   dp[n] = (dp[n] + mod) % mod; n   dp[n] = (dp[n] + n * (n - 1) / 2) % mod; n   printf( %d n , dp[n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 200000; n const int MOD = int(1E9) + 7; n int pow_mod(int b, int p) { n   int ret = 1; n   while (p) { n     if (p & 1) ret = 1LL * ret * b % MOD; n     b = 1LL * b * b % MOD; n     p >>= 1; n   } n   return ret; n } n int P[MAXN + 5], S[MAXN + 5]; n int l[MAXN + 5], r[MAXN + 5], n; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &l[i]); n   for (int i = 1; i <= n; i++) scanf( %d , &r[i]); n   for (int i = 1; i < n; i++) { n     int len = max(0, min(r[i], r[i + 1]) - max(l[i], l[i + 1]) + 1); n     int tmp = 1LL * pow_mod(r[i] - l[i] + 1, MOD - 2) * n               pow_mod(r[i + 1] - l[i + 1] + 1, MOD - 2) % MOD; n     P[i] = (1 + MOD - 1LL * tmp * len % MOD) % MOD; n   } n   for (int i = 1; i < n; i++) S[i] = (P[i] + S[i - 1]) % MOD; n   int ans = (3LL * S[n - 1] % MOD + 1) % MOD; n   for (int i = 1; i + 2 < n; i++) n     ans = (ans + 2LL * (S[n - 1] + MOD - S[i + 1]) % MOD * P[i] % MOD) % MOD; n   for (int i = 1; i + 1 < n; i++) { n     int len = max(0, min(r[i], min(r[i + 1], r[i + 2])) - n                          max(l[i], max(l[i + 1], l[i + 2])) + 1); n     int tmp = 1LL * pow_mod(r[i] - l[i] + 1, MOD - 2) % MOD * n               pow_mod(r[i + 1] - l[i + 1] + 1, MOD - 2) % MOD * n               pow_mod(r[i + 2] - l[i + 2] + 1, MOD - 2) % MOD; n     int del = 1; n     del = ((del + P[i]) % MOD + MOD - 1) % MOD; n     del = ((del + P[i + 1]) % MOD + MOD - 1) % MOD; n     del = (del + 1LL * tmp * len % MOD) % MOD; n     ans = (ans + 2LL * del % MOD) % MOD; n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2005; n int n, m, x[N], y[N], xx[N], yy[N], num[N][N], vis[N * N], cur, pre[N * N]; n vector<int> v[N * N]; n using pii = pair<int, int>; n vector<pair<int, pii>> process(vector<pair<int, pii>> q) { n   sort(q.begin(), q.end()); n   vector<pair<int, pii>> ret; n   for (int i = 0; i < int(q.size()); i++) { n     int l = q[i].second.first, r = q[i].second.second, j = i + 1; n     while (j < int(q.size()) && q[i].first == q[j].first) { n       if (q[j].second.first > r) { n         ret.push_back({q[i].first, {l, r}}); n         l = q[j].second.first; n         r = q[j].second.second; n       } else n         r = max(r, q[j].second.second); n       ++j; n     } n     ret.push_back({q[i].first, {l, r}}); n     i = j - 1; n   } n   return ret; n } n bool in(int a, pii y) { return a >= y.first && a <= y.second; } n bool check(int mid) { n   mid *= 2; n   vector<pair<int, pii>> a, b; n   for (int i = 1; i <= n; i++) b.push_back({x[i], {y[i] - mid, y[i] + mid}}); n   for (int i = 1; i <= m; i++) a.push_back({yy[i], {xx[i] - mid, xx[i] + mid}}); n   a = process(a); n   b = process(b); n   for (int i = 0; i < int(a.size()); i++) n     for (int j = 0; j < int(b.size()); j++) num[i][j] = -1; n   int idx = 0; n   for (int i = 0; i < n * m; i++) v[i].clear(); n   for (int i = 0; i < int(a.size()); i++) { n     int lst = -1; n     for (int j = 0; j < int(b.size()); j++) n       if (in(a[i].first, b[j].second) && in(b[j].first, a[i].second)) { n         num[i][j] = idx++; n         if (lst != -1) v[lst].push_back(idx - 1), v[idx - 1].push_back(lst); n         lst = idx - 1; n       } n   } n   for (int i = 0; i < int(b.size()); i++) { n     int lst = -1; n     for (int j = 0; j < int(a.size()); j++) n       if (in(a[j].first, b[i].second) && in(b[i].first, a[j].second)) { n         if (lst != -1) v[lst].push_back(num[j][i]), v[num[j][i]].push_back(lst); n         lst = num[j][i]; n       } n   } n   ++cur; n   for (int i = 0; i < idx; i++) n     if (vis[i] != cur) { n       queue<int> q; n       q.push(i); n       pre[i] = -1; n       vis[i] = cur; n       while (!q.empty()) { n         int nd = q.front(); n         q.pop(); n         for (auto &i : v[nd]) { n           if (vis[i] != cur) n             q.push(i), vis[i] = cur, pre[i] = nd; n           else if (pre[nd] != i) n             return 1; n         } n       } n     } n   return 0; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n >> m; n   int t1, t2; n   for (int i = 1; i <= n; i++) cin >> t1 >> t2, x[i] = t1 + t2, y[i] = t1 - t2; n   for (int i = 1; i <= m; i++) n     cin >> t1 >> t2, xx[i] = t1 + t2, yy[i] = t1 - t2; n   int l = 1, r = 1000000000, ans = -1; n   while (l <= r) { n     int mid = (l + r) >> 1; n     if (check(mid)) n       ans = mid, r = mid - 1; n     else n       l = mid + 1; n   } n   if (ans == -1) n     cout <<  Poor Sereja!  << endl; n   else n     cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace placeholders; n template <class T> n void mini(T &l, T r) { n   l = min(l, r); n } n template <class T> n void maxi(T &l, T r) { n   l = max(l, r); n } n template <class TH> n void _dbg(const char *sdbg, TH h) { n   cerr << sdbg <<  =  << h <<   n ; n } n template <class TH, class... TA> n void _dbg(const char *sdbg, TH h, TA... a) { n   while (*sdbg !=  , ) cerr << *sdbg++; n   cerr <<  =  << h <<  , ; n   _dbg(sdbg + 1, a...); n } n template <class T> n ostream &operator<<(ostream &os, vector<T> V) { n   os <<  [ ; n   for (auto vv : V) os << vv <<  , ; n   return os <<  ] ; n } n template <class L, class R> n ostream &operator<<(ostream &os, pair<L, R> P) { n   return os <<  (  << P.first <<  ,  << P.second <<  ) ; n } n const int N = 2E2 + 10; n int a[N][N]; n void output(int n) { n   printf( %d n , n); n   for (int i = 0; i <= n; ++i) printf( %d%c , a[n][i],   n  [i < n]); n } n int main() { n   int n; n   scanf( %d , &n); n   a[0][0] = 1; n   a[1][0] = 0, a[1][1] = 1; n   for (int i = 2; i <= n; ++i) { n     for (int j = 0; j < n; ++j) a[i][j + 1] = a[i - 1][j]; n     for (int j = 0; j < n - 1; ++j) a[i][j] = a[i][j] + a[i - 2][j] & 1; n   } n   output(n); n   output(n - 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct temp { n   unordered_map<long long, int> mp; n }; n int main() { n   ios_base::sync_with_stdio(false); n   long long sum = 0, ans = 0; n   vector<int> val(26); n   string str; n   temp mpc[26]; n   for (int i = 0; i < 26; i++) cin >> val[i]; n   cin >> str; n   for (int i = 0; i < str.size(); i++) { n     int ch = str[i] -  a ; n     if (mpc[ch].mp[sum] != 0) ans += mpc[ch].mp[sum]; n     sum += val[ch]; n     mpc[ch].mp[sum]++; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string tos(int a) { n   ostringstream os(  ); n   os << a; n   return os.str(); n } n const int MAXN = 1000000; n bool isp[MAXN + 100]; n int main() { n   ios_base::sync_with_stdio(0); n   for (int i = 0; i <= MAXN; ++i) isp[i] = 1; n   isp[0] = isp[1] = 1; n   for (int i = 2; i <= MAXN; ++i) n     if (isp[i]) n       for (int j = i + i; j <= MAXN; j += i) isp[j] = 0; n   int n; n   while (cin >> n) { n     int x, y; n     for (int i = 2; i < MAXN; ++i) { n       x = i, y = n - x; n       if (!isp[x] && !isp[y]) break; n     } n     cout << x <<     << y <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   int n; n   cin >> n; n   vector<int> a(n + 1); n   vector<int> primes = {2,  3,  5,  7,  11, 13, 17, 19, 23, 29, n                         31, 37, 41, 43, 47, 53, 59, 61, 67}; n   const int MAX = 70; n   vector<int> cnt(MAX + 1); n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n     ++cnt[a[i]]; n   } n   const int NS = 1 << primes.size(); n   vector<vector<int>> nw(MAX + 1, vector<int>(NS)); n   nw[0][0] = 1; n   for (int i = 1; i <= MAX; ++i) { n     int t = i; n     int mask = 0; n     for (int j = 0; j < primes.size(); ++j) { n       mask <<= 1; n       while (t % primes[j] == 0) { n         mask ^= 1; n         t /= primes[j]; n       } n     } n     long long E = 1; n     for (int j = 1; j < cnt[i]; ++j) { n       E = E * 2 % MOD; n     } n     long long O = 0; n     if (cnt[i]) O = E; n     for (int j = 0; j < NS; ++j) { n       nw[i][j] = nw[i - 1][j] * E % MOD; n       int pv = j ^ mask; n       nw[i][j] = (nw[i][j] + nw[i - 1][pv] * O) % MOD; n     } n   } n   long long ans = nw[MAX][0] - 1; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   int x, y; n   while (cin >> x >> y) { n     while (true) { n       bool ok = false; n       if (x >= 2 && y >= 2) { n         x -= 2; n         y -= 2; n         ok = true; n       } else if (x >= 1 && y >= 12) { n         x--; n         y -= 12; n         ok = true; n       } else if (y >= 22) { n         y -= 22; n         ok = true; n       } n       if (!ok) { n         cout <<  Hanako  << endl; n         break; n       } n       ok = false; n       if (y >= 22) { n         y -= 22; n         ok = true; n       } else if (x >= 1 && y >= 12) { n         x--; n         y -= 12; n         ok = true; n       } else if (x >= 2 && y >= 2) { n         x -= 2; n         y -= 2; n         ok = true; n       } n       if (!ok) { n         cout <<  Ciel  << endl; n         break; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline void next_int(T &x) { n   x = 0; n   char c; n   bool neg = false; n   while (!isdigit(c = getchar())) n     if (c ==  - ) neg = true; n   do x = x * 10 + c - 48; n   while (isdigit(c = getchar())); n   if (neg) x = -x; n } n template <typename T> n inline void write_int(T x, char last = 0) { n   if (x < 0) putchar( - ), x = abs(x); n   char tmp[20]; n   int cnt = 0; n   while (x >= 10) tmp[cnt++] = x % 10 + 48, x /= 10; n   tmp[cnt] = x + 48; n   for (int i = (cnt); i >= (0); --i) putchar(tmp[i]); n   if (last) putchar(last); n } n struct Line { n   long long a, b; n   Line(long long _a, long long _b) : a(_a), b(_b) {} n }; n const int N = (int)2e5 + 5; n vector<Line> hull; n int n; n long long a[N], sum[N], sum2[N]; n bool bad(Line l1, Line l2, Line l3) { n   return (l1.b - l3.b) * (l2.a - l1.a) <= (l3.a - l1.a) * (l1.b - l2.b); n } n void add(Line x) { n   while (((int)hull.size()) >= 2 && n          bad(hull[((int)hull.size()) - 2], hull[((int)hull.size()) - 1], x)) n     hull.pop_back(); n   hull.push_back(x); n } n long long getval(int pos, long long x) { n   if (pos >= ((int)hull.size())) return (long long)1e18 + 7; n   return hull[pos].a * x + hull[pos].b; n } n long long read(long long x) { n   int lo = 0, hi = ((int)hull.size()) - 1, mid; n   while (lo != hi) { n     mid = (lo + hi) >> 1; n     if (getval(mid, x) <= getval(mid + 1, x)) n       hi = mid; n     else n       lo = mid + 1; n   } n   return getval(lo, x); n } n int main() { n   next_int(n); n   for (int i = (1); i <= (n); ++i) { n     next_int(a[i]); n     sum[i] = sum[i - 1] + a[i]; n     sum2[i] = sum2[i - 1] + (long long)i * a[i]; n   } n   add(Line(0, 0)); n   long long res = 0; n   for (int i = (1); i <= (n); ++i) { n     res = max(res, -read(-sum[i]) + sum2[i]); n     add(Line(-i, sum2[i] - (long long)i * sum[i])); n   } n   write_int(res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n T load() { n   T r; n   cin >> r; n   return r; n } n template <typename T> n vector<T> loadMany(int n) { n   vector<T> rs(n); n   generate(rs.begin(), rs.end(), &load<T>); n   return rs; n } n struct StrInt { n   StrInt(const string& ref) : ref(ref) {} n   int operator[](int i) const { return ref[i] -  a ; } n   int size() const { return (int)ref.size(); } n   const string& ref; n }; n struct Trans { n   explicit Trans(int k) : k(k), tab(k, -1), rev(k, -1) {} n   Trans() : tab() {} n   void add(int from, int to) { n     tab[from] = to; n     rev[to] = from; n   } n   int get(int i) { return tab[i]; } n   bool loose(int i) { return tab[i] == -1; } n   bool free(int j) { return rev[j] == -1; } n   bool anyRangeFree(int j1, int j2) { n     for (auto j = j1; j <= j2; ++j) n       if (free(j)) return true; n     return false; n   } n   int findRangeFree(int j1, int j2) { n     for (auto j = j1; j <= j2; ++j) n       if (free(j)) return j; n     return -1; n   } n   bool defined() { return not tab.empty(); } n   void fillWithAny() { n     auto j = 0; n     for (auto i = 0; i < k; ++i) n       if (loose(i)) { n         while (not free(j)) ++j; n         add(i, j); n       } n   } n   void print() { n     for (auto i = 0; i < k; ++i) cout << (char)( a  + tab[i]); n   } n   int k; n   vector<int> tab; n   vector<int> rev; n }; n Trans solveA(int i, int k, StrInt s, StrInt a, Trans&& trans) { n   auto n = (int)s.size(); n   if (trans.loose(s[i]) and trans.free(a[i])) n     trans.add(s[i], a[i]); n   else if (trans.loose(s[i])) n     return {}; n   ++i; n   for (; i < n; ++i) n     if (trans.loose(s[i]) and trans.anyRangeFree(a[i] + 1, k - 1)) n       return trans.add(s[i], trans.findRangeFree(a[i] + 1, k - 1)), move(trans); n     else if (trans.loose(s[i]) and trans.free(a[i])) n       trans.add(s[i], a[i]); n     else if (trans.loose(s[i])) n       return {}; n     else if (trans.get(s[i]) > a[i]) n       return move(trans); n     else if (trans.get(s[i]) < a[i]) n       return {}; n   return move(trans); n } n Trans solveB(int i, int, StrInt s, StrInt b, Trans&& trans) { n   auto n = (int)s.size(); n   if (trans.loose(s[i]) and trans.free(b[i])) n     trans.add(s[i], b[i]); n   else if (trans.loose(s[i])) n     return {}; n   ++i; n   for (; i < n; ++i) n     if (trans.loose(s[i]) and trans.anyRangeFree(0, b[i] - 1)) n       return trans.add(s[i], trans.findRangeFree(0, b[i] - 1)), move(trans); n     else if (trans.loose(s[i]) and trans.free(b[i])) n       trans.add(s[i], b[i]); n     else if (trans.loose(s[i])) n       return {}; n     else if (trans.get(s[i]) < b[i]) n       return move(trans); n     else if (trans.get(s[i]) > b[i]) n       return {}; n   return move(trans); n } n Trans solve(int k, StrInt s, StrInt a, StrInt b) { n   auto n = s.size(); n   auto trans = Trans(k); n   auto i = 0; n   for (; i < n; ++i) n     if (a[i] != b[i] and trans.loose(s[i])) n       break; n     else if (a[i] != b[i] and n              (a[i] < trans.get(s[i]) and trans.get(s[i]) < b[i])) n       return trans; n     else if (a[i] != b[i] and a[i] == trans.get(s[i])) n       return solveA(i, k, s, a, move(trans)); n     else if (a[i] != b[i] and b[i] == trans.get(s[i])) n       return solveB(i, k, s, b, move(trans)); n     else if (trans.loose(s[i]) and trans.free(a[i])) n       trans.add(s[i], a[i]); n     else if (trans.loose(s[i])) n       return {}; n     else if (not(a[i] <= trans.get(s[i]) and trans.get(s[i]) <= b[i])) n       return {}; n   if (i == n) return trans; n   if (trans.anyRangeFree(a[i] + 1, b[i] - 1)) n     return trans.add(s[i], trans.findRangeFree(a[i] + 1, b[i] - 1)), n            move(trans); n   auto ans1 = solveA(i, k, s, a, Trans(trans)); n   if (ans1.defined()) return ans1; n   auto ans2 = solveB(i, k, s, b, move(trans)); n   return ans2; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   auto t = load<int>(); n   while (t-- > 0) { n     auto k = load<int>(); n     auto s = load<string>(); n     auto a = load<string>(); n     auto b = load<string>(); n     auto ans = solve(k, s, a, b); n     if (ans.defined()) { n       ans.fillWithAny(); n       cout <<  YES n ; n       ans.print(); n       cout <<   n ; n     } else n       cout <<  NO n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, n; n   string s; n   cin >> s; n   vector<int> freq(27, 0); n   for (i = 0; i < s.length(); ++i) { n     if (s[i] ==  B ) n       freq[26]++; n     else if (s[i] >=  a  && s[i] <=  z ) n       freq[s[i] -  a ]++; n   } n   cout << (min(freq[26], n                min(freq[ u  -  a ], n                    min(freq[ l  -  a ], n                        min(freq[1], n                            min(freq[ s  -  a ], n                                min(freq[0] >> 1, min(freq[ u  -  a ] >> 1, n                                                      freq[ r  -  a ])))))))) n        << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[4], b[4]; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) scanf( %d , &a[i]); n   sort(a, a + n); n   if (!n) n     puts( YES n1 n1 n3 n3 ); n   else if (n == 1) n     printf( YES n%d n%d n%d n , a[0] << 1, a[0] << 1, a[0] + (a[0] << 1)); n   else if (n == 2) { n     if (a[0] * 3 == a[1]) n       printf( YES n%d n%d n , a[0] << 1, a[0] << 1); n     else if (a[1] < a[0] * 3) n       printf( YES n%d n%d n , a[0] * 3, a[0] * 4 - a[1]); n     else n       puts( NO ); n   } else if (n == 4) { n     if (a[0] + a[3] == a[1] + a[2] && (a[3] - a[0]) << 1 == a[1] + a[2]) n       puts( YES ); n     else n       puts( NO ); n   } else { n     int i; n     for (i = 1; i <= 1000000; ++i) { n       for (int j = 0; j < 3; ++j) b[j] = a[j]; n       b[3] = i; n       sort(b, b + 4); n       if (b[0] + b[3] == b[1] + b[2] && (b[3] - b[0]) << 1 == b[1] + b[2]) n         break; n     } n     if (i <= 1000000) n       printf( YES n%d n , i); n     else n       puts( NO ); n   } n   return 0; n } n


#include <bits/stdc++.h> n int edge[110][110]; n int main() { n   memset(edge, 0, sizeof(edge)); n   int n, u, v, w; n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     scanf( %d , &w); n     edge[i % n][(i + 1) % n] = edge[(i + 1) % n][i % n] = w; n   } n   scanf( %d%d , &u, &v); n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < n; ++j) { n       if (i == j) n         edge[i][j] = 0; n       else if (edge[i][j] == 0) n         edge[i][j] = 1000000; n     } n   for (int k = 0; k < n; ++k) n     for (int i = 0; i < n; ++i) n       for (int j = 0; j < n; ++j) { n         if (i == k || j == k) continue; n         if (edge[i][j] > edge[i][k] + edge[k][j]) n           edge[i][j] = edge[i][k] + edge[k][j]; n       } n   printf( %d n , edge[u - 1][v - 1]); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int t; n   scanf( %d , &t); n   while (t--) { n     int m, n; n     scanf( %d %d , &n, &m); n     char s[n][m]; n     for (int i = 0; i < n; i++) { n       scanf( %s , s[i]); n     } n     int ans = 0; n     for (int i = 0; i < n; i++) n       if (s[i][m - 1] ==  R ) ans++; n     for (int i = 0; i < m; i++) n       if (s[n - 1][i] ==  D ) ans++; n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mx = 105; n const long long mx1 = 1000001; n const long long mod = 1000000007; n vector<vector<long long> > edges; n void adds(long long &a, long long b) { n   a += b; n   if (a >= mod) a -= mod; n } n long long mul(long long a, long long b) { return (long long)a * b % mod; } n void max_self(long long &a, long long b) { a = max(a, b); } n int main() { n   int n, i, res = 0, inc1 = -1, lp = 0, rp = 0; n   cin >> n; n   string s; n   cin >> s; n   for (i = 0; i < s.size(); i++) { n     if (s[i] ==  ( ) { n       lp++; n     } else { n       rp++; n     } n     if (rp > lp && inc1 == -1) { n       inc1 = i; n     } else if (lp == rp && inc1 != -1) { n       res += i - inc1 + 1; n       inc1 = -1; n     } n   } n   if (lp != rp) n     cout <<  -1 n ; n   else { n     cout << res <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s, s1; n   vector<string> vc; n   cin >> s; n   for (int i = 0; i < s.size(); i++) { n     s1 = s[i]; n     vc.push_back(s1); n     for (int j = i + 1; j < s.size(); j++) { n       s1 = s[i]; n       s1 += s[j]; n       vc.push_back(s1); n       for (int l = j + 1; l < s.size(); l++) { n         s1 = s[i]; n         s1 += s[j]; n         s1 += s[l]; n         vc.push_back(s1); n         for (int k = l + 1; k < s.size(); k++) { n           s1 = s[i]; n           s1 += s[j]; n           s1 += s[l]; n           s1 += s[k]; n           vc.push_back(s1); n           for (int a = k + 1; a < s.size(); a++) { n             s1 = s[i]; n             s1 += s[j]; n             s1 += s[l]; n             s1 += s[k]; n             s1 += s[a]; n             vc.push_back(s1); n             for (int b = a + 1; b < s.size(); b++) { n               s1 = s[i]; n               s1 += s[j]; n               s1 += s[l]; n               s1 += s[k]; n               s1 += s[a]; n               s1 += s[b]; n               vc.push_back(s1); n               for (int c = b + 1; c < s.size(); c++) { n                 s1 = s[i]; n                 s1 += s[j]; n                 s1 += s[l]; n                 s1 += s[k]; n                 s1 += s[a]; n                 s1 += s[b]; n                 s1 += s[c]; n                 vc.push_back(s1); n                 for (int d = c + 1; d < s.size(); d++) { n                   s1 = s[i]; n                   s1 += s[j]; n                   s1 += s[l]; n                   s1 += s[k]; n                   s1 += s[a]; n                   s1 += s[b]; n                   s1 += s[c]; n                   s1 += s[d]; n                   vc.push_back(s1); n                   for (int e = d + 1; e < s.size(); e++) { n                     s1 = s[i]; n                     s1 += s[j]; n                     s1 += s[l]; n                     s1 += s[k]; n                     s1 += s[a]; n                     s1 += s[b]; n                     s1 += s[c]; n                     s1 += s[d]; n                     s1 += s[e]; n                     vc.push_back(s1); n                     for (int f = e + 1; f < s.size(); f++) { n                       s1 = s[i]; n                       s1 += s[j]; n                       s1 += s[l]; n                       s1 += s[k]; n                       s1 += s[a]; n                       s1 += s[b]; n                       s1 += s[c]; n                       s1 += s[d]; n                       s1 += s[e]; n                       s1 += s[f]; n                       vc.push_back(s1); n                     } n                   } n                 } n               } n             } n           } n         } n       } n     } n   } n   long long i; n   s1 = s[0]; n   string ans = s1; n   for (i = 0; i < vc.size(); i++) { n     string p = vc[i]; n     reverse(p.begin(), p.end()); n     if (vc[i] == p) { n       ans = max(ans, p); n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n double f(double z, double first) { n   int k = 0; n   double w; n   while (first > 2 * z) { n     w = z; n     while (2 * w < first) w *= 2, k += 2; n     first -= w; n   } n   if (first <= z) n     return first; n   else n     return 2 * z - first; n } n int main() { n   int b, c; n   double a, lo, hi, mid, w; n   int k; n   while (scanf( %d %d , &c, &b) == 2) { n     a = c; n     if (c < b) { n       printf( -1 n ); n     } else if (c == b) { n       printf( %d n , b); n     } else { n       k = ((int)(floor(a / b + 1e-9) + 1e-9 - 1)) / 2; n       hi = a / (2 * k + 1); n       lo = a / (2 * k + 2); n       k = 60; n       while (k--) { n         mid = (lo + hi) / 2.0; n         w = f(mid, a); n         if (w <= b) n           lo = mid; n         else n           hi = mid; n       } n       printf( %.10lf n , mid); n     } n   } n   return 0; n } n


#include<bits/stdc++.h> n //#include<ext/pb_ds/assoc_container.hpp> n //#include<ext/pb_ds/tree_policy.hpp> n //#include <ext/pb_ds/trie_policy.hpp> n //using namespace __gnu_pbds; n using namespace std; n #define ll     long long int n #define ld    long double n #define mod             1000000007 n #define inf             1e18 n #define endl     n  n #define pb     push_back n #define vi              vector<ll> n #define vs    vector<string> n #define pii             pair<ll,ll> n #define ump    unordered_map n #define mp     make_pair n #define pq_max          priority_queue<ll> n #define pq_min          priority_queue<ll,vi,greater<ll> > n #define all(n)    n.begin(),n.end() n #define ff     first n #define ss     second n #define mid(l,r)        (l+(r-l)/2) n #define bitc(n)   __builtin_popcount(n) n #define loop(i,a,b)  for(int i=(a);i<=(b);i++) n #define looprev(i,a,b)  for(int i=(a);i>=(b);i--) n #define iter(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) n #define log(args...)  { string _s = #args; replace(_s.begin(), _s.end(),  , ,    ); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); } n #define logarr(arr,a,b) for(int z=(a);z<=(b);z++) cout<<(arr[z])<<   ;cout<<endl;  n template <typename T> T gcd(T a, T b){if(a%b) return gcd(b,a%b);return b;} n template <typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));} n vs tokenizer(string str,char ch) {std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;} n void err(istream_iterator<string> it) {} n template<typename T, typename... Args> n void err(istream_iterator<string> it, T a, Args... args) { n     cout << *it <<   =   << a << endl; n     err(++it, args...); n } n //typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; n //typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pbtrie; n void file_i_o() n { n     ios_base::sync_with_stdio(0);  n     cin.tie(0);  n     cout.tie(0); n     #ifndef ONLINE_JUDGE n         freopen( input.txt ,  r , stdin); n         freopen( output.txt ,  w , stdout); n     #endif n } n int main(int argc, char const *argv[]) { n     clock_t begin = clock(); n     file_i_o(); n     // Write your code here.... n     int t; n     cin>>t; n     while(t--){ n         int n; n         cin>>n; n         set<char> ts; n         string s; n         cin>>s; n         int fl=0; n         ts.insert(s[0]); n         for(int i=1;i<n;i++){ n             if(s[i]==s[i-1]){ n                 continue; n             }else{ n                 if(ts.find(s[i])==ts.end()){ n                     ts.insert(s[i]); n                 }else{ n                     cout<< NO n ; n                     fl=1; n                     break; n                 } n             } n         } n         if(fl!=1){ n             cout<< YES n ; n         } n     }                    n     #ifndef ONLINE_JUDGE          n       clock_t end = clock(); n       cout<<  n nExecuted In:  <<double(end - begin) / CLOCKS_PER_SEC*1000<<  ms ; n     #endif  n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n template <class T> n bool ckmin(T& a, const T& b) { n   return b < a ? a = b, 1 : 0; n } n template <class T> n bool ckmax(T& a, const T& b) { n   return a < b ? a = b, 1 : 0; n } n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n const long double pii = 3.14159265359; n const int MOD = 1000000007; n const char nl =   n ; n const int MX = 200001; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int T; n   cin >> T; n   while (T-- != 0) { n     int N; n     cin >> N; n     vector<int> v(2); n     for (int x = 0; x < (N); x++) { n       int nb; n       cin >> nb; n       v[nb]++; n     } n     if (v[0] >= v[1]) { n       cout << v[0] << nl; n       for (int x = 0; x < (v[0]); x++) cout << 0 <<    ; n     } else { n       cout << v[1] - v[1] % 2 << nl; n       for (int x = 0; x < (v[1] - v[1] % 2); x++) { n         cout << 1 <<    ; n       } n     } n     cout << nl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k; n char s[2010][1010]; n int a[1010][1010]; n int main() { n   scanf( %d%d%d n , &n, &m, &k); n   if (k == 1) { n     int cnt = 0; n     int tot = 0; n     for (int i = 0; i < 2 * n - 1; ++i) { n       gets(s[0]); n       for (int j = 0; j < m - ((i + 1) & 1); ++j, ++tot) n         if (s[0][j] ==  E ) cnt++; n     } n     if (cnt * 4 >= tot * 3) { n       puts( YES ); n       for (int i = 0; i < n; ++i) { n         for (int j = 0; j < m; ++j) { n           if (j != 0) printf(   ); n           printf( 1 ); n         } n         printf(  n ); n       } n     } else n       puts( NO ); n     return 0; n   } n   puts( YES ); n   for (int i = 0; i < 2 * n - 1; ++i) gets(s[i]); n   if (n < m) { n     for (int i = 0; i < n; ++i) { n       int ii = 2 * i; n       a[i][0] = 0; n       for (int j = 1; j < m; ++j) n         if (s[ii][j - 1] ==  E ) n           a[i][j] = a[i][j - 1]; n         else n           a[i][j] = 1 - a[i][j - 1]; n     } n     for (int i = 1; i < n; ++i) { n       int cnt = 0; n       for (int j = 0; j < m; ++j) n         if (s[2 * i - 1][j] ==  E ) n           cnt += a[i][j] == a[i - 1][j]; n         else n           cnt += a[i][j] != a[i - 1][j]; n       if (cnt < m - cnt) n         for (int j = 0; j < m; ++j) a[i][j] = 1 - a[i][j]; n     } n   } else { n     for (int i = 0; i < m; ++i) { n       a[0][i] = 0; n       for (int j = 1; j < n; ++j) n         if (s[2 * j - 1][i] ==  E ) n           a[j][i] = a[j - 1][i]; n         else n           a[j][i] = 1 - a[j - 1][i]; n     } n     for (int i = 1; i < m; ++i) { n       int cnt = 0; n       for (int j = 0; j < n; ++j) n         if (s[2 * j][i - 1] ==  E ) n           cnt += a[j][i] == a[j][i - 1]; n         else n           cnt += a[j][i] != a[j][i - 1]; n       if (cnt < n - cnt) n         for (int j = 0; j < n; ++j) a[j][i] = 1 - a[j][i]; n     } n   } n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) { n       if (j != 0) printf(   ); n       printf( %d , a[i][j] + 1); n     } n     printf(  n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct Point { n   double x, y, z; n }; n double len[10000]; n double sum[10000]; n int n; n Point point[10001], potter; n double vp, vs; n double getDist(Point &a, Point &b) { n   double x = a.x - b.x; n   double y = a.y - b.y; n   double z = a.z - b.z; n   return sqrt(x * x + y * y + z * z); n } n double getGapConst(Point &tar, Point &vec) { n   if (!(abs(vec.x - 0.0) < 1e-10)) return tar.x / vec.x; n   if (!(abs(vec.y - 0.0) < 1e-10)) return tar.y / vec.y; n   return tar.z / vec.z; n } n int main(void) { n   scanf( %d , &n); n   for (int i = 0; i <= n; i++) n     scanf( %lf %lf %lf , &point[i].x, &point[i].y, &point[i].z); n   scanf( %lf %lf , &vp, &vs); n   scanf( %lf %lf %lf , &potter.x, &potter.y, &potter.z); n   if ((abs(point[0].x - potter.x) < 1e-10) && n       (abs(point[0].y - potter.y) < 1e-10) && n       (abs(point[0].z - potter.z) < 1e-10)) { n     printf( YES n ); n     printf( 0 n ); n     printf( %lf %lf %lf n , potter.x, potter.y, potter.z); n     return 0; n   } n   for (int i = 0; i < n; i++) { n     len[i] = getDist(point[i], point[i + 1]); n     if (i == 0) n       sum[i] = 0; n     else n       sum[i] = sum[i - 1] + len[i - 1]; n   } n   bool isFound = false; n   for (int i = 0; i < n; i++) { n     Point vec; n     vec.x = point[i + 1].x - point[i].x; n     vec.y = point[i + 1].y - point[i].y; n     vec.z = point[i + 1].z - point[i].z; n     double startRatio = sum[i] / len[i]; n     Point start; n     start.x = point[i].x - startRatio * vec.x; n     start.y = point[i].y - startRatio * vec.y; n     start.z = point[i].z - startRatio * vec.z; n     Point unit; n     unit.x = vec.x / len[i]; n     unit.y = vec.y / len[i]; n     unit.z = vec.z / len[i]; n     double s = 0, e = 1, mid; n     for (int q = 0; q < 40; q++) { n       mid = (s + e) / 2; n       Point tar; n       tar.x = point[i].x + vec.x * mid; n       tar.y = point[i].y + vec.y * mid; n       tar.z = point[i].z + vec.z * mid; n       double dist = getDist(tar, potter); n       double reqTime = dist / vp; n       Point snitch; n       snitch.x = start.x + unit.x * vs * reqTime; n       snitch.y = start.y + unit.y * vs * reqTime; n       snitch.z = start.z + unit.z * vs * reqTime; n       Point gap; n       gap.x = snitch.x - point[i].x; n       gap.y = snitch.y - point[i].y; n       gap.z = snitch.z - point[i].z; n       double gapConst = getGapConst(gap, vec); n       if ((abs(mid - gapConst) < 1e-10)) { n         isFound = true; n         printf( YES n ); n         printf( %.10lf n , reqTime); n         printf( %.10lf %.10lf %.10lf n , tar.x, tar.y, tar.z); n         break; n       } else if (mid > gapConst) n         e = mid; n       else n         s = mid; n     } n     if (isFound) break; n   } n   if (!isFound) printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   unsigned long long ans = 0; n   for (int i = 0; i < s.size(); i++) { n     int x = s[i] -  0 ; n     if (x % 4 == 0) ans++; n     if (i > 0) { n       x += 10 * (s[i - 1] -  0 ); n       if (x % 4 == 0) ans += i; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   int n, k; n   cin >> n >> k; n   string s, s1; n   cin >> s; n   if (k == 0) { n     cout << s; n   } else if (n == 1) { n     cout << 0 <<   n ; n   } else { n     if (s[0] !=  1 ) { n       k--; n     } n     s1.push_back( 1 ); n     int i = 1; n     while (k && i < n) { n       if (s[i] !=  0 ) k--; n       s1.push_back( 0 ); n       i++; n     } n     for (; i < n; i++) { n       s1.push_back(s[i]); n     } n     cout << s1 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #define ll long long n #define f(i,n) for(int i=0;i<n;i++) n #define endl (  n ) n #define pb push_back n #define mp make_pair n #define pl pair<ll, ll> n #define vl vector<ll> n #define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL); n  n #define M 1000000007 n  const int N=2e5+2; n  ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);} n ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;} n ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);} n vector<ll> sieve(int n) {int*arr = new int[n + 1](); vector<ll> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;} n ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} n ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} n ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} n ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;}  //only for prime m n  n int fact[N]; n  n         void precalc(){ n             fact[0]=1; n             for(int i=1;i<N;i++){ n                 fact[i]=mod_mul(fact[i-1],i,M); n             } n         } n  long long mod(long long x){ n             return ((x%M + M)%M); n         } n         ll inv(ll x){ n             return expo(x,M-2,M); n         } n  n         ll divide(ll a, ll b){ n             return mod_mul(a,inv(b),M); n         } n  n         ll nCr(ll n, ll r){ n             return divide(fact[n],mod_mul(fact[r],fact[n-r],M)); n         } n  n   n int main() n { n     fastIO n   ll t; n   cin>>t; n   while(t--){ n  ll n; cin >> n; n         ll arr[n], sum = 0; n         for(auto &i : arr) cin >> i, sum += i; n   n         ll cnt = sum - (sum / n * n); n         cout << cnt * (n - cnt) << endl; n          n  n   } n  n  n  n  n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9 + 7; n const int MOD = 1e9 + 7; n const int MAXN = 1e6 + 3; n const double EPS = (1e-7); n int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; } n long long gcd(long long a, long long b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n long long power(long long x, long long y) { n   long long res = 1; n   while (y > 0) { n     if (y & 1) res = res * x; n     y = y >> 1; n     x = x * x; n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n, m, v; n   cin >> n >> m >> v; n   int maxcon = ((n - 1) * (n - 2)) / 2 + 1; n   if (m > maxcon or m < n - 1) { n     cout << -1 << endl; n   } else { n     for (int i = 1; i <= n; i++) { n       if (i != v) { n         cout << i <<     << v <<    n ; n         m--; n       } n     } n     int pr = 1; n     if (pr == v) { n       pr++; n     } n     for (int i = 1; i <= n and m; i++) { n       if (i != v and i != pr) { n         for (int j = i + 1; j <= n and m; j++) { n           if (j != v and j != pr) { n             cout << i <<     << j << endl; n             m--; n           } n         } n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxN = 3e5; n int n; n int a[maxN]; n int diff[maxN]; n int ans[maxN]; n vector<int> pos[maxN]; n int main() { n   int t; n   while (scanf( %d , &t) != EOF) n     for (int tt = 1; tt <= t; tt++) { n       scanf( %d , &n); n       for (int i = 0; i < n; i++) pos[i].clear(); n       for (int i = 0; i < n; i++) { n         scanf( %d , &a[i]); n         a[i]--; n         pos[a[i]].push_back(i); n       } n       for (int i = 0; i < n; i++) diff[i] = -1; n       for (int i = 0; i < n; i++) n         if (!pos[i].empty()) { n           diff[i] = max(*pos[i].begin(), n - 1 - *pos[i].rbegin()); n           for (int j = 0; j < pos[i].size() - 1; j++) n             diff[i] = max(diff[i], pos[i][j + 1] - pos[i][j] - 1); n         } n       for (int i = 0; i < n; i++) ans[i] = -1; n       for (int i = n - 1; i >= 0; i--) n         if (diff[i] != -1) ans[diff[i]] = i + 1; n       for (int i = 0; i < n; i++) n         if (ans[i] != -1) { n           int j = i; n           while (j + 1 < n && (ans[j + 1] >= ans[i] || ans[j + 1] == -1)) n             ans[++j] = ans[i]; n           i = j; n         } n       for (int i = 0; i < n; i++) n         printf( %d%c , ans[i], i < n - 1 ?     :   n ); n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   int arr[2000]; n   memset(arr, 0, sizeof(arr)); n   string s; n   cin >> s; n   for (int i = 0; i < n; i++) arr[s[i]]++; n   int m = 10000000; n   for (int i = 65; i < 65 + k; i++) m = min(arr[i], m); n   cout << m * k; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e1 + 5; n map<int, int> mp; n long long n, arr[MAXN], brr[MAXN], crr[MAXN]; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n     brr[i] = arr[i]; n   } n   sort(arr, arr + n); n   for (int i = 0; i < n; i++) { n     crr[i] = arr[(i + 1) % n]; n   } n   for (int i = 0; i < n; i++) { n     mp[arr[i]] = crr[i]; n   } n   for (int i = 0; i < n; i++) { n     cout << mp[brr[i]] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int N = 1e5 + 1, B = 128; n int i, j, n, m, r, a[N], f[N][B]; n int main() { n   for (scanf( %d , &n); ++i <= n; scanf( %d , a + i)) n     ; n   for (j = 1; j < B; ++j) n     for (i = n; i; --i) f[i][j] = i + j + a[i] > n ? 1 : f[i + j + a[i]][j] + 1; n   for (scanf( %d , &m); m--;) { n     scanf( %d%d , &i, &j); n     if (j < B) n       printf( %d n , f[i][j]); n     else { n       for (r = 0; i <= n; i += j + a[i]) ++r; n       printf( %d n , r); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> a(n); n   for (auto &ai : a) cin >> ai; n   vector<pair<int, int>> v; n   vector<bool> b(n); n   for (int i = 0; i < n; i++) { n     if (a[i] == 0) { n       sort(begin(v), end(v)); n       for (int k = 0; k < 3; k++) n         if (!v.empty()) { n           b[v.back().second] = true, v.pop_back(); n         } n       v.clear(); n     } else { n       v.emplace_back(a[i], i); n     } n   } n   int cnt = 0; n   for (int i = 0; i < n; i++) { n     if (a[i] == 0) { n       cout << cnt; n       if (1 <= cnt) cout <<   popStack ; n       if (2 <= cnt) cout <<   popQueue ; n       if (3 <= cnt) cout <<   popFront ; n       cout << endl; n       cnt = 0; n     } else { n       if (b[i]) { n         cnt++; n         if (cnt == 1) cout <<  pushStack  << endl; n         if (cnt == 2) cout <<  pushQueue  << endl; n         if (cnt == 3) cout <<  pushFront  << endl; n       } else { n         cout <<  pushBack  << endl; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, kezd[200002], veg[200002], pos[200002], inv[200002], x, csa, csb; n vector<pair<pair<int, int>, int> > sz; n vector<int> v; n priority_queue<pair<int, int> > q; n void p() { n   for (int i = 1; i <= n; i++) inv[pos[i]] = i; n   for (int i = 1; i <= n; i++) cout << inv[i] <<    ; n   cout <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     int a, b; n     cin >> a >> b, kezd[i] = a, veg[i] = b; n     sz.push_back({{a, b}, i}); n   } n   sort(sz.begin(), sz.end()); n   for (int i = 1; i <= n; i++) { n     while (x < n && sz[x].first.first == i) n       q.push({-sz[x].first.second, sz[x].second}), x++; n     pos[i] = q.top().second, q.pop(); n   } n   for (int i = 1; i <= n; i++) { n     while (v.size() > 0 && veg[pos[v.back()]] < i) { n       v.pop_back(); n     } n     int a = kezd[pos[i]], b = veg[pos[i]]; n     if (v.size() > 0 && a <= v.back()) { n       csa = i, csb = v.back(); n     } n     while (v.size() > 0 && b >= veg[pos[v.back()]]) v.pop_back(); n     v.push_back(i); n   } n   if (!csa) { n     cout <<  YES  n          <<   n ; n     p(); n   } else { n     cout <<  NO  n          <<   n ; n     p(); n     swap(pos[csa], pos[csb]); n     p(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   bool ok = 0; n   int res = 0; n   char c; n   while (((c = getchar()) <  0  || c >  9 ) && c !=  - ) n     ; n   if (c ==  - ) n     ok = 1; n   else n     res = c - 48; n   while ((c = getchar()) >=  0  && c <=  9 ) n     res = (res << 3) + (res << 1) + (c - 48); n   return ok ? ~res + 1 : res; n } n const int N = 4e5, M = 4e5; n int h[N], net[M], go[M], val[M], dep[N], ecnt = 1, cap[M]; n void add(int u, int v, int w) { n   go[++ecnt] = v; n   cap[ecnt] = w; n   net[ecnt] = h[u]; n   h[u] = ecnt; n   swap(u, v); n   go[++ecnt] = v; n   cap[ecnt] = 0; n   net[ecnt] = h[u]; n   h[u] = ecnt; n } n int s, t, n, m; n int bfs() { n   memset(dep, 0, sizeof(dep)); n   queue<int> q; n   q.push(s); n   dep[s] = 1; n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     for (int e = h[u]; e; e = net[e]) { n       int v = go[e]; n       if (!dep[v] && cap[e]) { n         dep[v] = dep[u] + 1; n         q.push(v); n       } n     } n   } n   return dep[t]; n } n int dfs(int u, int flow) { n   if (u == t) return flow; n   int res = 0, tot = 0; n   for (int e = h[u]; e; e = net[e]) { n     int v = go[e]; n     if (dep[v] == dep[u] + 1 && cap[e]) { n       res = dfs(v, min(flow, cap[e])); n       tot += res; n       cap[e] -= res; n       cap[e ^ 1] += res; n       flow -= res; n     } n   } n   if (tot == 0) dep[u] = 0; n   return tot; n } n int a[100000], v[100000]; n int g; n int main() { n   int cntg = 0; n   int sum = 0; n   int sum1 = 0; n   s = N - 2; n   t = N - 1; n   n = read(); n   m = read(); n   g = read(); n   for (int i = 1; i <= n; i++) a[i] = read(); n   for (int i = 1; i <= n; i++) { n     v[i] = read(); n     if (a[i] == 0) n       sum -= v[i], add(s, i, v[i]), sum1 += v[i]; n     else n       add(i, t, v[i]); n   } n   for (int i = 1, w, k, u, op; i <= m; i++) { n     op = read(); n     w = read(); n     k = read(); n     while (k--) { n       u = read(); n       if (op) n         add(u, i + n, 1e9); n       else n         add(i + n, u, 1e9); n     } n     int newop = read(); n     if (op == 0 && newop == 1) sum -= g; n     if (op == 0) n       add(s, i + n, w + (newop ? g : 0)), sum1 += w + (newop ? g : 0); n     else n       add(i + n, t, w + (newop ? g : 0)); n     if (op == 1) sum += w; n   } n   int ans = 0; n   int res = 0; n   while (bfs()) { n     ans += dfs(s, 1e9); n   } n   printf( %d n , sum + sum1 - ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n auto SEED = chrono::steady_clock::now().time_since_epoch().count(); n mt19937 rng(SEED); n int main() { n   int n, k; n   cin >> n >> k; n   int dist[n][n]; n   for (int i = (0); i < (n); i++) { n     for (int j = (0); j < (n); j++) { n       cin >> dist[i][j]; n     } n   } n   int t = 0; n   int color[n]; n   long long int ans = 1ll << 60; n   while (t < 5000) { n     for (int i = (0); i < (n); i++) { n       int tt = uniform_int_distribution<int>(1, n)(rng); n       color[i] = tt & 1; n     } n     long long int dp[n][k]; n     for (int j = (0); j < (k + 1); j++) { n       for (int i = (0); i < (n); i++) { n         if (j) { n           dp[i][j] = 1ll << 60; n           for (int l = (0); l < (n); l++) { n             if (color[i] + color[l] == 1) { n               dp[i][j] = min(dp[i][j], dp[l][j - 1] + dist[l][i]); n             } n           } n         } else { n           if (i) n             dp[i][j] = 1ll << 60; n           else n             dp[i][j] = 0; n         } n       } n     } n     ans = min(ans, dp[0][k]); n     t++; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> q1; n vector<long long> q2; n long long n, x, y, a, b, k; n long long l = 1, r = n; n long long ans = 0; n long long mid; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n bool cmp(long long a, long long b) { return a > b; } n int main() { n   int T; n   scanf( %d , &T); n   while (T--) { n     q1.clear(); n     scanf( %lld , &n); n     for (int i = 1; i <= n; i++) { n       long long t; n       scanf( %lld , &t); n       q1.push_back(t); n     } n     scanf( %lld %lld %lld %lld %lld , &x, &a, &y, &b, &k); n     long long gc = gcd(a, b); n     long long lcm = a * b / gc; n     sort(q1.begin(), q1.end(), cmp); n     l = 1, r = n; n     ans = 0; n     while (l <= r) { n       q2.clear(); n       mid = (l + r) / 2; n       for (int j = 1; j <= mid; j++) { n         if (j % lcm == 0) { n           q2.push_back(x + y); n         } else if (j % a == 0) { n           q2.push_back(x); n         } else if (j % b == 0) { n           q2.push_back(y); n         } n       } n       long long res = 0; n       sort(q2.begin(), q2.end(), cmp); n       for (int i = 0; i < q2.size(); i++) { n         res += q1[i] * q2[i]; n       } n       if (res >= k * 100) { n         r = mid - 1; n         ans = mid; n       } else { n         l = mid + 1; n       } n     } n     if (!ans) n       printf( -1 n ); n     else n       printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string tmp; n   map<string, vector<vector<string> > > m; n   for (int i = 0; i < n; i++) { n     cin >> tmp; n     getline(cin, tmp); n     bool f = false; n     string name; n     vector<string> v; n     for (int j = 0; j < tmp.length(); j++) { n       string s; n       while (j < tmp.length() && n              ((tmp[j] >=  a  && tmp[j] <=  z ) || n               (tmp[j] >=  0  && tmp[j] <=  9 ) || tmp[j] ==  T )) n         s += tmp[j++]; n       if (!s.empty()) { n         if (f) n           v.push_back(s); n         else { n           name = s; n           f = true; n         } n       } n     } n     m[name].push_back(v); n   } n   int V; n   cin >> V; n   map<string, string> v; n   for (int i = 0; i < V; i++) { n     string type, name; n     cin >> type >> name; n     v[name] = type; n   } n   int k; n   scanf( %i n , &k); n   for (int i = 0; i < k; i++) { n     getline(cin, tmp); n     string name; n     int j = 0; n     while (tmp[j] !=  ( ) { n       if (tmp[j] !=    ) name += tmp[j]; n       j++; n     } n     vector<string> a; n     while (j < tmp.length()) { n       string s; n       while (j < tmp.length() && n              ((tmp[j] >=  a  && tmp[j] <=  z ) || n               (tmp[j] >=  0  && tmp[j] <=  9 ) || tmp[j] ==  T )) n         s += tmp[j++]; n       if (!s.empty()) { n         a.push_back(v[s]); n       } n       j++; n     } n     int ans = 0; n     for (int k = 0; k < m[name].size(); k++) { n       bool eq = true; n       if (a.size() != m[name][k].size()) continue; n       for (int j = 0; j < a.size(); j++) n         if (a[j] != m[name][k][j] && m[name][k][j] !=  T ) { n           eq = false; n           break; n         } n       if (eq) ans++; n     } n     cout << ans << endl; n   } 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 x1, x2, y1, y2; n     cin >> x1 >> y1 >> x2 >> y2; n     if (x1 == x2 || y1 == y2) n       cout << abs(x1 - x2) + abs(y1 - y2) << endl; n     else n       cout << abs(x1 - x2) + abs(y1 - y2) + 2 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline void read(int &x) { n   char c = getchar(); n   x = 0; n   while (!isdigit(c) && !isalpha(c)) c = getchar(); n   if (isalpha(c)) return void(x = c -  a ); n   while (isdigit(c)) x = x * 10 + c -  0 , c = getchar(); n } n const int N = 5e5 + 5, SZ = 22; n int n, vv, ww; n int e, head[N], to[N << 1], val[N << 1], nxt[N << 1]; n inline void add(int u, int v, int w) { n   to[++e] = v; n   val[e] = w; n   nxt[e] = head[u]; n   head[u] = e; n } n inline void add_edge(int u, int v, int w) { n   add(u, v, w); n   add(v, u, w); n } n int sz[N], son[N], f[1 << 22 | 5], dep[N], Son, Max, ans[N], cur[N], s[N]; n inline void dfs1(int u, int fa) { n   sz[u] = 1; n   for (int i = head[u]; i; i = nxt[i]) n     if (to[i] != fa) { n       int v = to[i], w = val[i]; n       s[v] = s[u] ^ (1 << w); n       dep[v] = dep[u] + 1; n       dfs1(v, u); n       sz[u] += sz[v]; n       if (sz[v] > sz[son[u]]) son[u] = v; n     } n } n inline void calc(int u, int fa) { n   if (f[s[u]]) Max = max(Max, f[s[u]] + dep[u]); n   for (int i = 1; i <= (1 << 21); i <<= 1) n     if (f[i ^ s[u]]) Max = max(Max, f[i ^ s[u]] + dep[u]); n   for (int i = head[u]; i; i = nxt[i]) n     if (to[i] != fa) calc(to[i], u); n } n inline void update(int u, int fa) { n   f[s[u]] = max(f[s[u]], dep[u]); n   for (int i = head[u]; i; i = nxt[i]) n     if (to[i] != fa) update(to[i], u); n } n inline void get_Max(int u, int fa) { n   for (int i = head[u]; i; i = nxt[i]) n     if (to[i] != fa && to[i] != Son) { n       calc(to[i], u); n       update(to[i], u); n     } n } n inline void clear(int u, int fa) { n   f[s[u]] = 0; n   for (int i = head[u]; i; i = nxt[i]) n     if (to[i] != fa) clear(to[i], u); n } n inline void dfs2(int u, int fa, bool keep) { n   for (int i = head[u]; i; i = nxt[i]) n     if (to[i] != fa && to[i] != son[u]) dfs2(to[i], u, false); n   if (son[u]) dfs2(son[u], u, true); n   Son = son[u]; n   f[s[u]] = max(f[s[u]], dep[u]); n   get_Max(u, fa); n   ans[u] = max(f[s[u]] - dep[u], Max - 2 * dep[u]); n   for (int i = 1; i <= (1 << 21); i <<= 1) n     ans[u] = max(ans[u], f[i ^ s[u]] - dep[u]); n   for (int i = head[u]; i; i = nxt[i]) n     if (to[i] != fa) ans[u] = max(ans[u], ans[to[i]]); n   Son = Max = 0; n   if (!keep) clear(u, fa); n } n int main() { n   read(n); n   for (int uu = 2; uu <= n; uu++) { n     read(vv); n     read(ww); n     add_edge(uu, vv, ww); n   } n   dfs1(1, 0); n   dfs2(1, 0, 0); n   for (int i = 1; i <= n; i++) printf( %d  , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k, t, i, j, ii, a; n   while (scanf( %d%d%d , &n, &k, &t) != EOF) { n     for (i = 1; i <= n; i++) { n       if ((i * k + 1) * 100 > t * n * k) break; n     } n     for (j = 0; j <= k; j++) { n       a = (i - 1) * k + j; n       if (n * k * t >= 100 * a && (a + 1) * 100 > t * n * k) { n         for (ii = 1; ii <= i - 1; ii++) printf( %d  , k); n         printf( %d , j); n         for (ii = i + 1; ii <= n; ii++) printf(  %d , 0); n         printf(  n ); n         break; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long fat[200005]; n void gerafat() { n   fat[0] = 1; n   for (long long i = 1; i < 200005; i++) { n     fat[i] = (fat[i - 1] * i) % 1000000007; n   } n } n long long modInv(long long a) { n   long long v = 1; n   long long e = 1000000007 - 2; n   while (e) { n     if (e % 2) { n       v *= a; n       v %= 1000000007; n     } n     e /= 2; n     a *= a; n     a %= 1000000007; n   } n   return v; n } n long long comb(int a, int b) { n   if (a < b) return 0; n   long long res = n       ((fat[a] * modInv(fat[b])) % 1000000007 * modInv(fat[a - b])) % n       1000000007; n   return res; n } n int main() { n   long long n, k; n   cin >> n >> k; n   gerafat(); n   vector<long long> num(0); n   set<long long> sete; n   vector<pair<long long, long long> > v(n, {0, 0}); n   for (long long i = 0; i < n; i++) { n     long long a, b; n     cin >> a >> b; n     v[i] = {a, b}; n     if (!sete.count(a)) { n       num.push_back(a); n       sete.insert(a); n     } n     if (!sete.count(b)) { n       num.push_back(b); n       sete.insert(b); n     } n     if (!sete.count(b + 1)) { n       num.push_back(b + 1); n       sete.insert(b + 1); n     } n   } n   sort(num.begin(), num.end()); n   long long tam = num.size(); n   map<long long, long long> mapa; n   for (long long i = 0; i < tam; i++) mapa[num[i]] = i; n   vector<long long> pref(tam, 0); n   for (int i = 0; i < n; i++) { n     pref[mapa[v[i].first]]++; n     pref[mapa[v[i].second + 1]]--; n   } n   for (int i = 1; i < tam; i++) pref[i] += pref[i - 1]; n   long long res = comb(pref[0], k) % 1000000007; n   for (long long i = 1; i < tam; i++) { n     res = (res + comb(pref[i], k)) % 1000000007; n     res = (res + ((long long)(num[i] - num[i - 1] - 1) * n                   comb(min(pref[i], pref[i - 1]), k)) % n                      1000000007) % n           1000000007; n   } n   cout << res << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, r; n   long long a; n   map<int, long long> d; n   int ans[300010]; n   int k = 0; n   ans[0] = 1; n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     scanf( %I64d , &a); n     if (d[a] > r) { n       ans[++k] = i; n       r = i; n     } else n       d[a] = i; n   } n   if (k) { n     printf( %i n%i , k, ans[0]); n     for (int i = 1; i < k; ++i) printf(  %i n%i , ans[i], ans[i] + 1); n     printf(  %i , n); n   } else n     cout << -1; n   return 0; n } n