#include <bits/stdc++.h> n using namespace std; n bool dbg = 0; n clock_t start_time = clock(); n void bad(string mes =  Impossible ) { n   cout << mes; n   exit(0); n } n void bad(int mes) { n   cout << mes; n   exit(0); n } n template <typename T> n string bin(T x, int st = 2) { n   string ans =   ; n   while (x > 0) { n     ans += char( 0  + x % st); n     x /= st; n   } n   reverse(ans.begin(), ans.end()); n   return ans.empty() ?  0  : ans; n } n template <typename T> n void amax(T& x, T y) { n   x = max(x, y); n } n template <typename T> n void amin(T& x, T y) { n   x = min(x, y); n } n template <typename T> n T input() { n   T ans = 0, m = 1; n   char c =    ; n   while (!((c >=  0  && c <=  9 ) || c ==  - )) { n     c = getchar(); n   } n   if (c ==  - ) m = -1, c = getchar(); n   while (c >=  0  && c <=  9 ) { n     ans = ans * 10 + (c -  0 ), c = getchar(); n   } n   return ans * m; n } n template <typename T> n void read(T& a) { n   a = input<T>(); n } n template <typename T> n void read(T& a, T& b) { n   read(a), read(b); n } n template <typename T> n void read(T& a, T& b, T& c) { n   read(a, b), read(c); n } n template <typename T> n void read(T& a, T& b, T& c, T& d) { n   read(a, b), read(c, d); n } n const int inf = 1e9 + 20; n const short short_inf = 3e4 + 20; n const long double eps = 1e-15; n const int maxn = (int)1e5 + 12, base = 1e9 + 7; n const long long llinf = 2e18 + 5; n template <typename T> n T binpow(T n, T second) { n   if (second <= 0) return 1LL; n   if (second % 2 == 0) { n     T b = binpow(n, second / 2); n     return (1LL * b * b) % base; n   } else { n     return (1LL * binpow(n, second - 1) * n) % base; n   } n } n vector<int> g[maxn], gr[maxn]; n bool used[maxn]; n int u[maxn]; n vector<int> cmp, order; n void dfs1(int v) { n   used[v] = 1; n   for (int to : g[v]) n     if (!used[to]) dfs1(to); n   order.push_back(v); n } n void dfs2(int v) { n   used[v] = 1; n   cmp.push_back(v); n   for (int to : gr[v]) n     if (!used[to]) dfs2(to); n } n int comp[maxn], sz[maxn]; n int main() { n   int n, m, h; n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   read(n, m, h); n   for (int i = 0; i < n; i++) { n     read(u[i]); n   } n   for (int i = 0; i < m; i++) { n     int a, b; n     read(a, b); n     a--, b--; n     if (u[a] + 1 == u[b] || (u[a] == h - 1 && u[b] == 0)) { n       g[a].push_back(b); n       gr[b].push_back(a); n     } n     swap(a, b); n     if (u[a] + 1 == u[b] || (u[a] == h - 1 && u[b] == 0)) { n       g[a].push_back(b); n       gr[b].push_back(a); n     } n   } n   memset(used, 0, sizeof(used)); n   for (int i = 0; i < n; i++) n     if (!used[i]) dfs1(i); n   memset(used, 0, sizeof(used)); n   for (int i = n - 1; i >= 0; i--) { n     int v = order[i]; n     if (!used[v]) { n       cmp.clear(); n       dfs2(v); n       for (int j : cmp) { n         comp[j] = v; n         sz[v]++; n       } n     } n   } n   for (int i = 0; i < n; i++) { n     for (int to : g[i]) n       if (comp[to] != comp[i]) { n         sz[comp[i]] = 0; n       } n   } n   int res = inf, ans; n   for (int i = 0; i < n; i++) { n     if (sz[i] > 0 && sz[i] < res) { n       res = sz[i]; n       ans = i; n     } n   } n   cout << res <<   n ; n   for (int i = 0; i < n; i++) n     if (comp[i] == ans) cout << i + 1 <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MX = 100010; n int t[MX]; n int main() { n   int n; n   cin >> n; n   for (int i = (1); i <= (n); ++i) { n     scanf( %d , &t[i]); n   } n   for (int i = (1); i <= (n); ++i) { n     printf( %d  , t[i] + t[i + 1]); n   } n } n


#include <bits/stdc++.h> n template <typename T> n bool ckmax(T& a, const T& b) { n   return b > a ? a = b, 1 : 0; n } n template <typename T> n bool ckmin(T& a, const T& b) { n   return b < a ? a = b, 1 : 0; n } n const int MV = 1e5 + 10; n const int MM = 1e5 + 10; n const int MG = 450; n const int INF = 0x3f3f3f3f; n struct DSU { n   int p[MM], t[MM]; n   char r[MM]; n   void init(int M) { n     memset(p, -1, M * sizeof *p); n     memset(r, 0, M * sizeof *r); n     std::iota(t, t + M, 0); n   } n   int find(int v) { return ~p[v] ? p[v] = find(p[v]) : v; } n   bool merge(int a, int b) { n     a = find(a), b = find(b); n     if (a == b) return 0; n     t[a] = t[b]; n     if (r[a] < r[b]) std::swap(a, b); n     r[a] += r[a] == r[b]; n     p[a] = b; n   } n } dsu; n int M, v[MM], maxv[MM], dp[MM][2], ub[MV]; n bool ok[MM]; n int solve() { n   scanf( %d , &M); n   for (int i = 0; i < M; ++i) { n     scanf( %d , v + i); n     assert(v[i] > 0); n   } n   for (int i = 0, j = 0; i < MV; ++i) { n     while (j < M && v[j] == i) ++j; n     ub[i] = j; n   } n   memset(maxv, 0x3f, sizeof maxv); n   std::fill(ok, ok + M, 1); n   int f = 0; n   bool c = 0; n   for (int i = 0; f == i; ++i, c ^= 1) { n     dsu.init(M + 1); n     for (int j = M - 1; j >= 0; --j) { n       if (ok[j] &= (maxv[j] > 0)) ckmax(f, i + 1); n       dp[j][c] = v[j] * 2 - maxv[j]; n       ckmax(dp[j][c], 0); n       ckmin(dp[j][c], v[j] - 1); n       if (i) { n         ckmax(dp[j][c], dp[j][!c]); n         int x = ub[dp[j][!c]], y = ub[dp[j][c]]; n         for (int g = dsu.find(x), t; (t = dsu.t[g]) < y;) { n           maxv[t] = v[j]; n           dsu.merge(g, t + 1); n           g = dsu.find(g); n         } n       } n     } n     memset(maxv, 0, sizeof maxv); n   } n   return f; n } n int main() { n   int N, f = 0; n   scanf( %d , &N); n   for (int i = 0; i < N; ++i) f ^= solve(); n   if (f) n     printf( YES n ); n   else n     printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mx = 2e5 + 10; n long long int x[mx], y[mx]; n int ord[mx]; n int hs[mx], h = 0; n vector<int> g[mx]; n int ans[mx]; n int cross(int a, int o, int b) { n   long long int l = (x[o] - x[a]) * (y[o] - y[b]) * y[a] * x[b]; n   long long int r = (y[o] - y[a]) * (x[o] - x[b]) * x[a] * y[b]; n   if (l == r) return 0; n   if (l < r) return -1; n   return 1; n } n bool cmp1(int i, int j) { n   if (x[i] != x[j]) return x[i] < x[j]; n   if (y[i] != y[j]) return y[i] < y[j]; n   return i < j; n } n bool cmp(int i, int j) { n   int c = cross(i, ord[0], j); n   if (c == 0) { n     if (x[j] != x[i]) return x[j] < x[i]; n     return i < j; n   } n   return c > 0; n } n inline bool ccw(int a, int o, int b) { return (-cross(a, o, b)) >= 0; } n int main() { n   int n, xi, yi; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d %d , &xi, &yi); n     x[i] = xi, y[i] = yi, ord[i] = i; n   } n   sort(ord, ord + n, cmp1); n   int c = 0; n   int il = 0, id = 0; n   for (int i = 0; i < n;) { n     int ii = ord[i]; n     int xi = x[ii], yi = y[ii]; n     while (i < n && x[ord[i]] == xi && y[ord[i]] == yi) { n       g[ii].push_back(ord[i]); n       i++; n     } n     int j = ord[il]; n     if (xi > x[j] || (xi == x[j] && yi > y[j])) il = c; n     j = ord[id]; n     if (yi > y[j] || (yi == y[j] && xi > x[j])) id = c; n     ord[c++] = ii; n   } n   int dwn = ord[id]; n   swap(ord[0], ord[il]); n   sort(ord + 1, ord + c, cmp); n   for (int i = 0; i < c; i++) { n     while (h >= 2 && !ccw(hs[h - 2], hs[h - 1], ord[i])) h--; n     hs[h++] = ord[i]; n     if (ord[i] == dwn) break; n   } n   c = 0; n   for (int i = 0; i < h; i++) { n     int u = hs[i]; n     for (int j = 0; j < int(g[u].size()); j++) { n       ans[c++] = 1 + g[u][j]; n     } n   } n   sort(ans, ans + c); n   printf( %d , ans[0]); n   for (int i = 1; i < c; i++) printf(  %d , ans[i]); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int mod = 1e9 + 7; n   string S; n   cin >> S; n   bool flag = false; n   long ans = 0; n   long plus = 0; n   for (int i = 0; i < S.size(); i++) { n     if (S[i] ==  a ) { n       if (flag) { n         ans = (2 * ans + 1) % mod; n       } else { n         ans = ans + 1 + plus; n         ans = ans % mod; n       } n       flag = false; n     } else if (S[i] ==  b ) { n       plus = ans; n       flag = true; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int temp; n   int a[6] = {0}; n   int i = 0; n   while (n > 0) { n     a[i] = n % 2; n     n = n / 2; n     i++; n   } n   temp = a[0]; n   a[0] = a[4]; n   a[4] = temp; n   temp = a[2]; n   a[2] = a[3]; n   a[3] = temp; n   int count = 1; n   int sum = 0; n   for (int i = 0; i < 6; i++) { n     sum = sum + a[i] * count; n     count = count * 2; n   } n   cout << sum; n } n


#include <bits/stdc++.h> n using namespace std; n const int OO = 1e9; n const double EPS = 1e-9; n template <class T> n void _db(const char* dbStr, T e) { n   cout << dbStr <<   =   << e << endl; n } n template <class T, class... L> n void _db(const char* dbStr, T e, L... r) { n   while (*dbStr !=  , ) cout << *dbStr++; n   cout <<   =   << e <<  , ; n   _db(dbStr + 1, r...); n } n template <class S, class T> n ostream& operator<<(ostream& o, const map<S, T>& v) { n   o <<  [ ; n   int i = 0; n   for (const pair<S, T>& pr : v) n     o << (!i++ ?    :  ,  ) <<  {  << pr.first <<   :   << pr.second <<  } ; n   return o <<  ] ; n } n template <template <class, class...> class S, class T, class... L> n ostream& operator<<(ostream& o, const S<T, L...>& v) { n   o <<  [ ; n   int i = 0; n   for (const auto& e : v) o << (!i++ ?    :  ,  ) << e; n   return o <<  ] ; n } n template <class S, class T> n ostream& operator<<(ostream& o, const pair<S, T>& pr) { n   return o <<  (  << pr.first <<  ,   << pr.second <<  ) ; n } n ostream& operator<<(ostream& o, const string& s) { n   for (const char& c : s) o << c; n   return o; n } n template <class T> n using V = vector<T>; n template <class T> n using VV = V<V<T>>; n template <class T> n using VVV = VV<V<T>>; n using ll = long long; n using pii = pair<int, int>; n using vi = V<int>; n using vii = V<pii>; n using vvi = VV<int>; n using mii = map<int, int>; n using umii = unordered_map<int, int>; n using si = set<int>; n using usi = unordered_set<int>; n vii monoStFunc(vi a) { n   int n = int(a.size()); n   vii b(n); n   stack<pii> st; n   st.push(make_pair(INT_MAX, -1)); n   for (int i = 0; i < n; ++i) { n     while (st.top().first < a[i]) st.pop(); n     b[i].first = st.top().second; n     st.push(make_pair(a[i], i)); n   } n   while (!st.empty()) st.pop(); n   st.push(make_pair(INT_MAX, n)); n   for (int i = n - 1; i >= 0; --i) { n     while (st.top().first <= a[i]) st.pop(); n     b[i].second = st.top().second; n     st.push(make_pair(a[i], i)); n   } n   return b; n } n int n, q; n vi a, d; n int main() { n   ios::sync_with_stdio(false); n   cout.precision(10); n   cin.tie(0); n   cin >> n >> q; n   a.assign(n, 0); n   for (int i = 0; i < n; ++i) cin >> a[i]; n   d.assign(n - 1, 0); n   for (int i = 0; i < n - 1; ++i) d[i] = abs(a[i + 1] - a[i]); n   true; n   for (int qq = 0; qq < q; ++qq) { n     int l, r; n     cin >> l >> r; n     --l, --r; n     vi v; n     for (int i = l; i < r; ++i) v.push_back(d[i]); n     vii LR = monoStFunc(v); n     ll ans = 0; n     for (int i = 0; i < int(v.size()); ++i) n       ans += v[i] * 1LL * ((i - LR[i].first) * 1LL * (LR[i].second - i)); n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int gi() { n   char cc = getchar(); n   int cn = 0, flus = 1; n   while (cc <  0  || cc >  9 ) { n     if (cc ==  - ) flus = -flus; n     cc = getchar(); n   } n   while (cc >=  0  && cc <=  9 ) cn = cn * 10 + cc -  0 , cc = getchar(); n   return cn * flus; n } n const int N = 3e5 + 5; n int n, q, a[N], g[20], f[N][20]; n signed main() { n   n = gi(), q = gi(); n   for (register int i = (1); i <= (n); ++i) a[i] = gi(); n   for (register int i = (0); i <= (19); ++i) g[i] = n + 1; n   memset(f, 63, sizeof(f)); n   for (register int i = n; i >= 1; --i) { n     for (register int j = (0); j <= (19); ++j) n       if ((1 << j) & a[i]) f[i][j] = i; n     for (register int j = (0); j <= (19); ++j) n       if ((1 << j) & a[i]) n         for (register int k = (0); k <= (19); ++k) n           f[i][k] = min(f[i][k], f[g[j]][k]); n     for (register int j = (0); j <= (19); ++j) n       if ((1 << j) & a[i]) g[j] = i; n   } n   while (q--) { n     int x = gi(), y = gi(); n     int flag = 0; n     for (register int j = (0); j <= (19); ++j) n       if ((1 << j) & a[y]) flag |= (f[x][j] <= y); n     (flag) ? puts( Shi ) : puts( Fou ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 2147483647; n const long long LLINF = 9223372036854775807; n int main() { n   int n; n   cin >> n; n   long long mod = 1000000009; n   if (n == 2) cout << 10, exit(0); n   long long b = 5, g = 1, r = 6; n   long long fb = 2, fg = 2, t = 4; n   for (int i = 0; i < n / 2 - 2; ++i) { n     b = r + 3 * g * (t + 1); n     g = (g * (1 + t)) % mod; n     r = (b + g) % mod; n     fb = (t + fg * 2) % mod; n     fg = (fg * 2) % mod; n     t = (fg + fb) % mod; n   } n   long long ans = ((r * r + 1) * 2) % mod; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = int(500 * 1000 + 7); n long long n, k; n vector<pair<long long, long long> > adj[N]; n long long dp[N][2]; n void dfs(int v, int p = -1) { n   vector<long long> x; n   long long curr = 0; n   for (auto it : adj[v]) { n     long long to = it.first; n     long long w = it.second; n     if (to == p) continue; n     dfs(to, v); n     curr += dp[to][0]; n     x.push_back(dp[to][1] + w - dp[to][0]); n   } n   sort(x.begin(), x.end(), greater<long long>()); n   for (long long i = 0; i < min((long long)x.size(), k); i++) { n     if (x[i] > 0) curr += x[i]; n   } n   dp[v][0] = dp[v][1] = curr; n   if (k <= (long long)x.size() && x[k - 1] > 0) dp[v][1] -= x[k - 1]; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long q; n   cin >> q; n   while (q--) { n     cin >> n >> k; n     for (long long i = 0; i < n; i++) adj[i].clear(); n     for (long long i = 0; i < n - 1; i++) { n       long long u, v, w; n       cin >> u >> v >> w; n       u--; n       v--; n       adj[u].push_back({v, w}); n       adj[v].push_back({u, w}); n     } n     dfs(0, -1); n     cout << dp[0][0] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1010; n struct Point { n   double x, y; n   Point(double _ = 0, double __ = 0) { x = _, y = __; } n   bool operator<(const Point &_) const { n     if (fabs(x - _.x) > 1e-10) return x < _.x; n     return y < _.y; n   } n } po[N], rec[N * 2], stk[N * 2]; n struct Line { n   Point a, b; n } L; n struct Mem { n   Point a; n   int type; n   bool operator<(const Mem &_) const { n     if (fabs(a.x - _.a.x) > 1e-10) return a.x < _.a.x; n     if (fabs(a.y - _.a.y) > 1e-10) return a.y < _.a.y; n     return type < _.type; n   } n } pp[N * 2]; n int n, m; n inline double xmul(Point a, Point b, Point c) { n   return (a.x - b.x) * (a.y - c.y) - (a.y - b.y) * (a.x - c.x); n } n inline bool across(Point &a, Point &b, Point &c, Point &d) { n   double p1 = xmul(a, b, c), p2 = xmul(a, b, d); n   if (fabs(p1) < 1e-10 || fabs(p2) < 1e-10) return 1; n   if (p1 * p2 < 1e-10) return 1; n   return 0; n } n inline bool oneline(Point &a, Point &b, Point &c, Point &d) { n   double p1 = xmul(a, b, c), p2 = xmul(a, b, d); n   if (fabs(p1) < 1e-10 && fabs(p2) < 1e-10) return 1; n   return 0; n } n inline Point intersection(Line &u, Line &v) { n   Point ret = u.a; n   double t = n       ((u.a.x - v.a.x) * (v.a.y - v.b.y) - (u.a.y - v.a.y) * (v.a.x - v.b.x)) / n       ((u.a.x - u.b.x) * (v.a.y - v.b.y) - (u.a.y - u.b.y) * (v.a.x - v.b.x)); n   ret.x += (u.b.x - u.a.x) * t; n   ret.y += (u.b.y - u.a.y) * t; n   return ret; n } n inline double dis(Point &a, Point &b) { n   return sqrt(((a.x - b.x) * (a.x - b.x)) + ((a.y - b.y) * (a.y - b.y))); n } n inline bool onseg(Point &a, Point &b, Point &c) { n   if (fabs(xmul(a, b, c)) < 1e-10) return 1; n   return 0; n } n inline double getans() { n   Point a, b; n   int tot = 0, cnt = 0, top = 0; n   double ans = 0; n   for (int i = 1; i <= n; i++) { n     if (oneline(L.a, L.b, po[i], po[i + 1])) { n       cnt++; n       pp[cnt].a = po[i]; n       pp[cnt].type = 1; n       cnt++; n       pp[cnt].a = po[i + 1]; n       pp[cnt].type = -1; n       if (pp[cnt].a < pp[cnt - 1].a) swap(pp[cnt].a, pp[cnt - 1].a); n       continue; n     } n     int k1 = onseg(L.a, L.b, po[i]) || xmul(L.a, L.b, po[i]) < 0; n     int k2 = onseg(L.a, L.b, po[i + 1]) || xmul(L.a, L.b, po[i + 1]) < 0; n     if (k1 + k2 != 1) continue; n     if (onseg(L.a, L.b, po[i])) { n       rec[++tot] = po[i]; n       continue; n     } n     if (onseg(L.a, L.b, po[i + 1])) { n       rec[++tot] = po[i + 1]; n       continue; n     } n     if (across(L.a, L.b, po[i], po[i + 1])) { n       Line tmp; n       tmp.a = po[i], tmp.b = po[i + 1]; n       rec[++tot] = intersection(L, tmp); n     } n   } n   sort(rec + 1, rec + tot + 1); n   for (int i = 1; i < tot; i += 2) { n     cnt++; n     pp[cnt].a = rec[i]; n     pp[cnt].type = 1; n     cnt++; n     pp[cnt].a = rec[i + 1]; n     pp[cnt].type = -1; n   } n   sort(pp + 1, pp + cnt + 1); n   for (int i = 1; i <= cnt; i++) { n     if (pp[i].type == 1) n       stk[++top] = pp[i].a; n     else { n       if (top == 1) ans += dis(stk[top], pp[i].a); n       top--; n     } n   } n   return ans; n } n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %lf%lf , &po[i].x, &po[i].y); n   po[n + 1] = po[1]; n   for (int i = 1; i <= m; i++) { n     scanf( %lf%lf%lf%lf , &L.a.x, &L.a.y, &L.b.x, &L.b.y); n     printf( %.8lf n , getans()); n   } n   return 0; n } n


#include <bits/stdc++.h> n bool vis[100000 + 3]; n int pr[20000]; n int h; n int a[300]; n int n; n int endp[200000], next[200000], cap[200000]; n int gra[300], cur[300], dist[300], prev[300]; n int cnt[300]; n int ecnt; n char buf[10000], *bend; n char out[10000], *oend; n void add_edge(int u, int v, int c) { n   endp[++ecnt] = v; n   cap[ecnt] = c; n   next[ecnt] = gra[u]; n   gra[u] = ecnt; n   endp[++ecnt] = u; n   cap[ecnt] = 0; n   next[ecnt] = gra[v]; n   gra[v] = ecnt; n } n int isap(int vcnt, int S_, int T_) { n   memmove(cur, gra, sizeof(gra)); n   memset(cnt, 0, sizeof(cnt)); n   memset(dist, 0, sizeof(dist)); n   prev[S_] = S_; n   int ret = 0, top; n   int u = S_; n   while (dist[S_] < vcnt) { n     int i = cur[u]; n     for (; ~i; i = next[i]) { n       int v = endp[i]; n       if (cap[i] && dist[u] == dist[v] + 1) { n         prev[v] = cur[u] = i; n         u = v; n         break; n       } n     } n     if (!~i) { n       cur[u] = gra[u]; n       top = vcnt; n       for (int i = gra[u]; ~i; i = next[i]) { n         int v = endp[i]; n         if (cap[i] && dist[v] < top) { n           top = dist[v]; n         } n       } n       ++cnt[top + 1]; n       if (!--cnt[dist[u]]) { n         goto STOP; n       } n       dist[u] = top + 1; n       if (u != S_) { n         u = endp[prev[u] ^ 1]; n       } n     } n     if (u == T_) { n       int arg = 1 << 29; n       while (u != S_) { n         if (cap[prev[u]] < arg) { n           arg = cap[prev[u]]; n         } n         u = endp[prev[u] ^ 1]; n       } n       ret += arg; n       while (u != T_) { n         cap[cur[u]] -= arg; n         cap[cur[u] ^ 1] += arg; n         u = endp[cur[u]]; n       } n       u = S_; n     } n   } n STOP: n   return ret; n } n int find(int u, int p) { n   vis[u] = true; n   sprintf(bend,   %d , u + 1); n   bend += strlen(bend); n   *bend = 0; n   for (int i = gra[u]; ~i; i = next[i]) { n     int v = endp[i]; n     if (v == p || vis[v]) { n       continue; n     } n     if ((!!cap[i]) ^ (a[u] & 1)) { n       return find(v, u) + 1; n     } n   } n   return 1; n } n bool is_pr(int val) { n   int l = 0, r = h - 1; n   while (r - l > 1) { n     int mid = (l + r) >> 1; n     if (pr[mid] < val) { n       l = mid; n     } else { n       r = mid; n     } n   } n   return pr[r] == val; n } n int main() { n   for (int i = 2; i < 100000; ++i) { n     if (!vis[i]) { n       pr[h++] = i; n     } n     for (int j = 0; j < h; ++j) { n       if (100000 / pr[j] < i) { n         break; n       } n       vis[pr[j] * i] = true; n       if (!(i % pr[j])) { n         break; n       } n     } n   } n   while (scanf( %d , &n) != EOF) { n     for (int i = 0; i < n; ++i) { n       scanf( %d , a + i); n     } n     memset(gra, 255, sizeof(gra)); n     ecnt = -1; n     for (int i = 0; i < n; ++i) { n       if (a[i] & 1) { n         add_edge(n, i, 2); n         for (int j = 0; j < n; ++j) { n           if (!(a[j] & 1) && is_pr(a[i] + a[j])) { n             add_edge(i, j, 1); n           } n         } n       } else { n         add_edge(i, n + 1, 2); n       } n     } n     int flow = isap(n + 2, n, n + 1); n     if (flow != n) { n       puts( Impossible ); n     } else { n       oend = out; n       memset(vis, 0, sizeof(vis)); n       int cnt = 0; n       for (int i = 0; i < n; ++i) { n         if (!vis[i]) { n           bend = buf; n           sprintf(oend,  %d%s n , find(i, -1), buf); n           oend += strlen(oend); n           ++cnt; n         } n       } n       *(++oend) = 0; n       printf( %d n%s , cnt, out); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n const int MAX_N = (int)1e5 + 123; n const double eps = 1e-6; n const int inf = (int)1e9 + 123; n using namespace std; n int n, k; n int mini = inf; n string second; n int sum[MAX_N]; n int main() { n   cin >> n >> k >> second; n   for (int i = 0; i < int((second).size()); i++) n     sum[i] = (i > 0 ? sum[i - 1] : 0) + (second[i] ==  0 ); n   vector<int> q; n   for (int i = 0; i < int((second).size()); i++) n     if (second[i] ==  0 ) q.push_back(i); n   for (int i = 0; i < int((second).size()); i++) { n     if (sum[int((second).size()) - 1] - (i > 0 ? sum[i - 1] : 0) < k + 1) break; n     int l = i, r = int((second).size()) - 1, mid = -1, ans = -1; n     while (l <= r) { n       mid = (l + r) / 2; n       if (sum[mid] - (i > 0 ? sum[i - 1] : 0) >= k + 1) { n         ans = mid; n         r = mid - 1; n       } else n         l = mid + 1; n     } n     assert(ans != -1); n     int now = ans - i; n     if ((ans - i + 1) % 2 == 1) { n       int mid = (ans + i) / 2; n       auto it = lower_bound(q.begin(), q.end(), mid); n       if (it != q.end()) now = min(now, max(*it - i, ans - *it)); n       if (it != q.begin()) { n         it--; n         now = min(now, max(*it - i, ans - *it)); n       } n     } else { n       int mid = (ans + i) / 2 + 1; n       auto it = lower_bound(q.begin(), q.end(), mid); n       if (it != q.end()) now = min(now, max(*it - i, ans - *it)); n       mid--; n       it = lower_bound(q.begin(), q.end(), mid); n       if (it != q.end()) now = min(now, max(*it - i, ans - *it)); n       if (it != q.begin()) { n         it--; n         now = min(now, max(*it - i, ans - *it)); n       } n     } n     mini = min(mini, now); n   } n   cout << mini; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int t; n   cin >> t; n   while (t--) { n     long long int n, m, sum = 0; n     cin >> n >> m; n     long long int a[5] = {0}; n     if (n == 1) n       cout <<  0  << endl; n     else if (n == 2) n       cout << m << endl; n     else n       cout << (2 * m) << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200005; n int n; n vector<int> adj[N]; n vector<pair<int, int> > r; n int color[N]; n bool vis[N]; n void solve(int x) { n   vis[x] = true; n   for (auto w : adj[x]) { n     if (!vis[w]) { n       color[w] = (color[x]) ^ 1; n       solve(w); n     } n   } n } n int32_t main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     x--, y--; n     adj[x].push_back(y); n     adj[y].push_back(x); n     int k = 2 * i; n     int kk = 2 * i + 1; n     k %= 2 * n; n     kk %= 2 * n; n     adj[k].push_back(kk); n     adj[kk].push_back(k); n     r.push_back(pair<int, int>(x, y)); n   } n   for (int i = 0; i < 2 * n; i++) { n     if (!vis[i]) { n       solve(i); n     } n   } n   for (auto w : r) { n     cout << color[w.first] + 1 <<     << color[w.second] + 1 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long mod; n long long lgput(long long a, long long b) { n   if (b == 0) return 1; n   if (b == 1) return a % mod; n   long long c = lgput(a, b / 2); n   c = c * c % mod; n   if (b & 1) c = c * a % mod; n   return c; n } n map<long long, int> hh; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n, k; n   cin >> n >> mod >> k; n   int i, j, z; n   for (i = 0; i < n; i++) { n     cin >> z; n     hh[(lgput(z, 4) - 1LL * k * z % mod + mod) % mod]++; n   } n   long long ans = 0; n   for (pair<int, int> cur : hh) ans += 1LL * cur.second * (cur.second - 1) / 2; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( avx,avx2,fma ) n #pragma GCC optimization( unroll-loops ) n const int N = 1e5 + 5; n const long double pi = 3.141592653; n const long long MOD = 1e9 + 7; n const long long mod = 998244353; n const long long INF = 9223372036854775807LL; n using namespace std; n int dx[9] = {1, -1, 0, 0, 1, 1, -1, -1, 0}; n int dy[9] = {0, 0, 1, -1, 1, -1, 1, -1, 0}; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int T = 1; n   while (T--) { n     string s; n     long long i, j, ans = 1, n; n     cin >> s; n     n = (long long)s.size(); n     bool ok = true; n     for (i = 0; i < n; i++) { n       if (s[i] ==  w  || s[i] ==  m ) ok = false; n     } n     if (!ok) n       ans = 0; n     else { n       long long dp[N]; n       dp[0] = 0; n       dp[1] = 1; n       dp[2] = 2; n       for (i = 3; i < N; i++) dp[i] = (dp[i - 1] + dp[i - 2]) % MOD; n       for (i = 0; i < n; i++) { n         if (s[i] ==  u  || s[i] ==  n ) { n           j = i; n           while (j < n && s[j] == s[i]) j++; n           ans = (ans * dp[j - i]) % MOD; n           i = j - 1; n         } n       } n     } n     cout << ans; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 200005; n map<int, int> Map; n struct Node { n   int au, sub; n } node[MAX]; n int n, temp, m; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &temp); n     Map[temp]++; n   } n   int m; n   scanf( %d , &m); n   for (int i = 1; i <= m; i++) { n     scanf( %d , &node[i].au); n   } n   int Max1, Max2; n   Max1 = Max2 = 0; n   int id = 1; n   for (int i = 1; i <= m; i++) { n     scanf( %d , &node[i].sub); n     if (Map[node[i].au] > Max1 || n         (Map[node[i].au] == Max1 && Map[node[i].sub] > Max2)) { n       Max1 = Map[node[i].au]; n       Max2 = Map[node[i].sub]; n       id = i; n     } n   } n   cout << id << endl; n   return 0; n } n


#include <bits/stdc++.h> n long long get2(long long, long long); n long long get1(long long n, long long x) { n   if (x & 1) n     return (x + 1) / 2; n   else if (n & 1) n     return get2(n / 2, x / 2) + (n + 1) / 2; n   else n     return get1(n / 2, x / 2) + n / 2; n } n long long get2(long long n, long long x) { return get1(n, x == 1 ? n : x - 1); } n int main() { n   long long n; n   int q; n   std::cin >> n >> q; n   while (q--) { n     long long x; n     std::cin >> x; n     std::cout << get1(n, x) << std::endl; n   } n   return 0; n } n


/* n { n ###################### n #       Author       # n #        Gary        # n #        2021        # n ###################### n */ n #include<bits/stdc++.h> n #define rb(a,b,c) for(int a=b;a<=c;++a) n #define rl(a,b,c) for(int a=b;a>=c;--a) n #define LL long long n #define IT iterator n #define PB push_back n #define II(a,b) make_pair(a,b) n #define FIR first n #define SEC second n #define FREO freopen( check.out , w ,stdout) n #define rep(a,b) for(int a=0;a<b;++a) n #define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) n #define random(a) rng()%a n #define ALL(a) a.begin(),a.end() n #define POB pop_back n #define ff fflush(stdout) n #define fastio ios::sync_with_stdio(false) n #define check_min(a,b) a=min(a,b) n #define check_max(a,b) a=max(a,b) n using namespace std; n //inline int read(){ n //    int x=0; n //    char ch=getchar(); n //    while(ch< 0 ||ch> 9 ){ n //        ch=getchar(); n //    } n //    while(ch>= 0 &&ch<= 9 ){ n //        x=(x<<1)+(x<<3)+(ch^48); n //        ch=getchar(); n //    } n //    return x; n //} n const int INF=0x3f3f3f3f; n typedef pair<int,int> mp; n /*} n */ n const int MAXN=1e5+233; n vector<int> gra[MAXN]; n vector<int> tree[MAXN]; n int n,m; n int vis[MAXN]; n int num[MAXN]; n bool leaf[MAXN]; n int g[MAXN],f[MAXN][2],h[MAXN]; n void dfs(int now,int pre){ n  for(auto it:gra[now]){ n   if(it!=pre){ n    if(vis[it]){ n     if(vis[it]<vis[now]){ n      num[it]--; n      num[now]++; n     } n    } n    else{ n     vis[it]=vis[now]+1; n     dfs(it,now); n    } n   } n  } n } n void gao(int now,int pre){ n  vis[now]=1; n  for(auto it:gra[now]) if(it!=pre){ n   if(!vis[it]){ n    gao(it,now); n    num[now]+=num[it]; n //   cout<<now<<   <<it<<   <<num[now]<<endl; n   } n  } n  if(!num[now]&&pre){ n   tree[pre].PB(now); n   tree[now].PB(pre); n  } n } n vector<mp> rest; n bool cmp(int A,int B){ n  return f[A][1]-f[A][0]<f[B][1]-f[B][0]; n } n void calc(int now,int pre){ n  vis[now]=1; n  vector<int> sons; n  f[now][0]=0; n  bool all_leaf=true; n  for(auto it:gra[now]) if(it!=pre) calc(it,now),sons.PB(it),f[now][0]+=f[it][1],all_leaf&=leaf[it]; n  if((sons.size()&1)&&all_leaf) f[now][0]=INF; n  else n  f[now][0]+=(sons.size()+1)>>1; n  int sum=0; n  for(auto it:sons) sum+=f[it][0]; n  sort(ALL(sons),cmp); n  f[now][1]=INF; n  if(sons.size()==0){ n   f[now][1]=0; n   g[now]=now; n   h[now]=0; n   leaf[now]=true; n  } n  rb(i,1,sons.size()){ n   sum+=f[sons[i-1]][1]-f[sons[i-1]][0]; n   if(i>=sons.size()-1); n   else continue; n //  cout<< # <<now<<   <<sum<<   <<f[sons[i-1]][1]<<   <<f[sons[i-1]][0]<<endl; n   if(i&1){ n    if(sum+i/2<f[now][1]){ n     f[now][1]=sum+i/2; n     g[now]=g[sons[0]]; n     h[now]=i; n    } n   } n   else{ n    if(leaf[sons[0]]) continue; n    if(sum+i/2<f[now][1]){ n     g[now]=g[sons[1]]; n     f[now][1]=sum+i/2;  n     h[now]=i; n    } n   } n  } n // cout<<now<< : <<f[now][0]<<   <<f[now][1]<<endl; n } n void gao(int now,int ty,int pre){ n  vector<int> sons; n  for(auto it:gra[now]) if(it!=pre) sons.PB(it); n  if(ty==0){ n   int notleaf=-1; n   rep(i,sons.size()){ n    int now=i,nex=i+1;  n    if((sons.size()&1)&&notleaf==-1&&!leaf[sons[now]]){ n     notleaf=sons[now]; n     now++; n     nex++; n    } n    if((sons.size()&1)&&notleaf==-1&&!leaf[sons[nex]]){ n     notleaf=sons[nex]; n     nex++; n    } n    if(nex>=sons.size()) break; n    rest.PB(II(g[sons[now]],g[sons[nex]])); n    i=nex; n   } n   if(notleaf!=-1){ n    rest.PB(II(g[notleaf],now)); n   } n   for(auto it:sons) gao(it,1,now);return; n  } n  if(sons.empty()) return; n  sort(ALL(sons),cmp); n  if((h[now])&1){ n   rb(i,1,h[now]-1){ n    rest.PB(II(g[sons[i]],g[sons[i+1]])); n    ++i; n   } n  } n  else{ n   rb(i,2,h[now]-1){ n    rest.PB(II(g[sons[i]],g[sons[i+1]])); n    ++i; n   } n   rest.PB(II(g[sons[0]],now)); n  } n  rb(i,1,h[now]) gao(sons[i-1],1,now); n  rb(i,h[now]+1,sons.size()) gao(sons[i-1],0,now); n } n void solve(){ n  rest.clear(); n  rb(i,1,n) gra[i].clear(),leaf[i]=false; n  rb(i,1,n) tree[i].clear(); n  rb(i,1,n) vis[i]=0; n  rb(i,1,n) num[i]=0; n  rb(i,1,m){ n   int si; n   scanf( %d ,&si); n   int pre=-1; n   rb(j,1,si){ n    int ai; n    scanf( %d ,&ai); n    if(pre!=-1) gra[pre].PB(ai),gra[ai].PB(pre); n    pre=ai; n   } n  } n  vis[1]=1; n  dfs(1,0); n  rb(i,1,n) vis[i]=0; n  gao(1,0); n  rb(i,1,n) vis[i]=0; n  rb(i,1,n) gra[i]=tree[i]; n  rb(i,1,n) if(!vis[i]){ n   calc(i,0); n   int ret=f[i][0],z=0; n   int sum=0; n   for(auto it:gra[i]){ n    sum+=f[it][1]; n   } n   for(auto it:gra[i]){ n    if(sum-f[it][1]+f[it][0]+gra[i].size()/2<ret){ n     ret=sum-f[it][1]+f[it][0]+gra[i].size()/2; n     z=it; n    } n   } n   if(z==0) n   gao(i,0,0);  n   else{ n    gao(z,0,i); n    for(auto it:gra[i]) if(it!=z) gao(it,1,i); n    int pre=-1; n    for(auto it:gra[i]){ n     if(it!=z){ n      if(pre!=-1) rest.PB(II(g[pre],g[it])),pre=-1; n      else{ n       pre=it; n      } n     } n    } n    if(pre!=-1) rest.PB(II(g[pre],i)); n   } n  } n  printf( %d n ,int(rest.size())); n  for(auto it:rest){ n   printf( %d %d n ,it.FIR,it.SEC);  n  } n } n int main(){ n  while(true){ n   scanf( %d%d ,&n,&m); n   if(!n&&!m){ n    break; n   } n   solve();  n  } n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 5; n string s[N]; n int n, k, fa[N], len[N], ch[N][26], root = 1, last = 1, tot = 1, times[N]; n void insert(int x) { n   int now = ++tot, pre = last; n   last = now, len[now] = len[pre] + 1; n   for (; pre && !ch[pre][x]; pre = fa[pre]) ch[pre][x] = now; n   if (!pre) n     fa[now] = root; n   else { n     int q = ch[pre][x]; n     if (len[q] == len[pre] + 1) n       fa[now] = q; n     else { n       int nows = ++tot; n       len[nows] = len[pre] + 1; n       memcpy(ch[nows], ch[q], sizeof(ch[q])); n       fa[nows] = fa[q], fa[q] = fa[now] = nows; n       for (; pre && ch[pre][x] == q; pre = fa[pre]) ch[pre][x] = nows; n     } n   } n } n long long vis[N], sum[N]; n void getcnt() { n   for (int i = 1; i <= n; i++) { n     int now = root; n     for (int j = 0; j < s[i].length(); j++) { n       now = ch[now][s[i][j] -  a ]; n       int t = now; n       while (t && vis[t] != i) vis[t] = i, times[t]++, t = fa[t]; n     } n   } n } n void dfs(int x) { n   if (x == root || vis[x]) return; n   vis[x] = 1; n   dfs(fa[x]); n   sum[x] += sum[fa[x]]; n } n int main() { n   ios::sync_with_stdio(0); n   cin >> n >> k; n   for (int i = 1; i <= n; i++) cin >> s[i]; n   for (int i = 1; i <= n; i++) { n     last = 1; n     for (int j = 0; j < s[i].length(); j++) insert(s[i][j] -  a ); n   } n   getcnt(); n   for (int i = 1; i <= tot; i++) n     sum[i] = (times[i] >= k) * (len[i] - len[fa[i]]); n   memset(vis, 0, sizeof(vis)); n   for (int i = 1; i <= tot; i++) dfs(i); n   for (int i = 1; i <= n; i++) { n     long long ans = 0, now = root; n     for (int j = 0; j < s[i].length(); j++) n       now = ch[now][s[i][j] -  a ], ans += sum[now]; n     printf( %lld  , ans); n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n const int N = 100010; n const int MX = 123456; n const int mod = (int)1e9 + 7; n const int base = 1023456789; n const unsigned long long BS1 = 10000019ULL; n const int INF = (1 << 29); n template <class T> n inline void fastScan(T &x) { n   register char c = getchar(); n   int neg = 0; n   x = 0; n   for (; (c < 48 || c > 57) && (c !=  - ); c = getchar()) n     ; n   if (c ==  - ) { n     neg = 1; n     c = getchar(); n   } n   for (; c > 47 && c < 58; c = getchar()) { n     x = (x << 1) + (x << 3) + c - 48; n   } n   if (neg) x = -x; n } n int n, m, q; n int W[15]; n int kunt[(1 << 12) + 10]; n char str[15]; n long long dp[(1 << 12) + 5][105]; n bool Check(int nn, int pos) { return (bool)(nn & (1 << pos)); } n int P(int a, int b) { n   int x = 0; n   for (int i = 0; i < n; i++) { n     if (Check(a, i) == Check(b, i)) { n       x += W[i]; n     } n   } n   return x; n } n int main() { n   fastScan(n); n   fastScan(m); n   fastScan(q); n   for (int i = 0; i < n; i++) { n     fastScan(W[i]); n   } n   for (int i = 0; i < m; i++) { n     scanf( %s , str); n     int x = 0; n     for (int j = 0; str[j]; j++) { n       if (str[j] ==  1 ) { n         x += (1 << j); n       } n     } n     kunt[x]++; n   } n   for (int i = 0; i <= (1 << 12); i++) { n     int x = 0; n     for (int j = 0; j <= (1 << 12); j++) { n       if (kunt[j] >= 0) { n         x = P(i, j); n         if (x <= 100) dp[i][x] += kunt[j]; n       } n     } n   } n   for (int i = 0; i <= (1 << 12); i++) { n     for (int k = 1; k <= 101; k++) dp[i][k] += dp[i][k - 1]; n   } n   for (int i = 0; i < q; i++) { n     int x = 0, k = 0; n     scanf( %s %d , str, &k); n     for (int j = 0; j < n; j++) { n       if (str[j] ==  1 ) x += (1 << j); n     } n     printf( %d n , dp[x][k]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1000000007, ans = 1, n, ert, dp[1000002]; n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n, ert = n; n   dp[0] = 1, dp[1] = 1; n   for (int i = 2; i <= n; i++) { n     dp[i] = ((i - 1) * dp[i - 2] + dp[i - 1]) % mod; n   } n   for (int i = 1; i <= n; i++) { n     int x; n     cin >> x; n     if (x == 2) ans *= ert, ans %= mod, ert--; n   } n   cout << ans * dp[ert] % mod <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n #define arr(i,n) for(ll i=0;i<n;i++) n #define ARR(i,n) for(ll i=n-1;i>=0;i--) n #define f(i,a,b)  for(ll i=a;i<b;i++) n #define F(i,a,b)  for(ll i=b-1;i>=a;i--) n #define float double n #define PI 3.14159265358979323846 n #define pb push_back n #define mp make_pair n #define vi vector<ll> n #define ceil(a) (ll) ceil(a) n #define floor(a) (ll) floor(a) n #define pow(a,b) (ll) pow(a,b) n #define fixed(x) cout<<fixed<<setprecision(6)<<x; n #define vpii vector< pair<ll,ll> > n #define debug(x) cout<<(#x)<<  is  <<(x)<<endl n #define dbg(x,y)  cout<<#x<< =  <<x<<   and   <<#y<< = <<y<<endl n #define gcd(a,b) __gcd(a,b) n #define lcm(a,b) (a*(b/gcd(a,b))) n #define all(v) v.begin(),v.end() n #define array(a,n) arr(i,n) cout<<a[i]<<   ; n #define array2D(a,n,m) arr(i,n) {arr(j,m) cout<<a[i][j]<<   ; cout<<endl;} n #define IOS  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) n typedef long long ll; n using namespace std; n const ll  mod = 1000000000 + 7; n void solve() n { n     //code start here n     ll n; n     cin>>n; n     n=2*n; n     ll a[n]; n     arr(i,n) cin>>a[i]; n     sort(a,a+n); n     ll start=0,end=n-1; n     arr(i,n) n     { n         if(i%2==0) {cout<<a[start]; start++;} n         else {cout<<a[end]; end--; } n         cout<<   ; n     } n     cout<<endl; n } n int main() n { n     IOS; n     int t; cin>>t; n     while(t--)  solve(); n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int t; n   cin >> t; n   while (t--) { n     long long int n, i, j, x, y, a[100005], v[100005]; n     map<long long int, long long int> ma; n     cin >> n; n     for (i = 1; i <= n; i++) { n       cin >> a[i]; n       ma[a[i]] = i; n       v[i] = 0; n     } n     long long int fl = 0, p = -1; n     for (i = 1; i <= n; i++) { n       if (!v[ma[i]]) { n         for (j = ma[i]; j <= n; j++) { n           if (v[j] == 1 || j == n + 1) { n             break; n           } n           if (a[j] != j - ma[i] + i) { n             fl = 1; n             break; n           } n           v[j] = 1; n         } n       } n     } n     if (fl) { n       cout <<  No n ; n     } else { n       cout <<  Yes n ; n     } n   } n   return 0; n } n


#include<iostream> n #include<string> n using namespace std; n int  main() n { n  int t; n  cin>>t; n  for(int i=0;i<t;i++) n  { n   int n; n   string r,b; n   cin>>n; n   cin>>r>>b; n   int counter1=0,counter2=0; n   for(int i=0;i<n;i++) n   { n    if(r[i]>b[i]) n     counter1++; n    else if(r[i]<b[i]) n     counter2++; n   } n   if(counter1>counter2) n    cout<< RED <<endl; n   else if(counter1==counter2) n    cout<< EQUAL <<endl; n   else  n    cout<< BLUE <<endl; n  } n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n int n; n char s[105][105]; n char t[105]; n bool judge1() { n   int i = 0; n   for (; i < n; i++) t[i] =  E ; n   t[i] =   0 ; n   for (int i = 0; i < n; i++) n     if (strcmp(t, s[i]) == 0) return 1; n   return 0; n } n bool judge2() { n   for (int i = 0; i < n; i++) { n     int F = 1; n     for (int j = 0; j < n; j++) n       if (s[j][i] !=  E ) { n         F = 0; n         break; n       } n     if (F) return 1; n   } n   return 0; n } n int main() { n   while (~scanf( %d , &n)) { n     for (int i = 0; i < n; i++) scanf( %s , s[i]); n     if (judge1() && judge2()) { n       cout << -1 << endl; n       continue; n     } n     if (judge1()) { n       for (int i = 0; i < n; i++) { n         for (int j = 0; j < n; j++) n           if (s[j][i] ==  . ) { n             cout << j + 1 <<     << i + 1 << endl; n             break; n           } n       } n     } else n       for (int i = 0; i < n; i++) { n         int l = strlen(s[i]); n         for (int j = 0; j < l; j++) n           if (s[i][j] ==  . ) { n             cout << i + 1 <<     << j + 1 << endl; n             break; n           } n       } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   float n; n   cin >> n; n   int p = 1; n   float count = 0; n   while (n != 0) { n     count = count + 1.0 / n; n     n--; n   } n   cout << count; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i, n1, output = 0; n   cin >> n; n   if (n % 2 == 0) n     cout << n / 2 - 1; n   else n     cout << n / 2; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma GCC optimize( Ofast ) n #pragma GCC target( avx,avx2,fma ) n #pragma GCC optimization( unroll-loops ) n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n void __print(int x) { cout << x; } n void __print(long x) { cout << x; } n void __print(long long x) { cout << x; } n void __print(unsigned x) { cout << x; } n void __print(unsigned long x) { cout << x; } n void __print(unsigned long long x) { cout << x; } n void __print(float x) { cout << x; } n void __print(double x) { cout << x; } n void __print(long double x) { cout << x; } n void __print(char x) { cout <<      << x <<     ; } n void __print(const char *x) { cout <<     << x <<    ; } n void __print(const string &x) { cout <<     << x <<    ; } n void __print(bool x) { cout << (x ?  true  :  false ); } n template <typename T, typename V> n void __print(const pair<T, V> &x) { n   cout <<  { ; n   __print(x.first); n   cout <<  , ; n   __print(x.second); n   cout <<  } ; n } n template <typename T> n void __print(const T &x) { n   int first = 0; n   cout <<  { ; n   for (auto &i : x) cout << (first++ ?  ,  :   ), __print(i); n   cout <<  } ; n } n void _print() { cout <<  ] n ; } n template <typename T, typename... V> n void _print(T t, V... v) { n   __print(t); n   if (sizeof...(v)) cout <<  ,  ; n   _print(v...); n } n template <class T> n void remdup(vector<T> &v) { n   sort((v).begin(), (v).end()); n   v.erase(unique((v).begin(), (v).end()), end(v)); n } n template <typename T> n struct cmp { n   bool operator()(const T &p1, const T &p2) {} n }; n const long long N = 2e5 + 100; n const long long mod = 1e9 + 7; n const long long X = 2e5 + 100; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   ; n   string s; n   cin >> s; n   long long ans = 0, wait = 0, m = 0; n   for (auto &it : s) { n     if (it ==  M ) { n       m++; n       if (wait) wait--; n     } else { n       if (m) { n         ans = max(ans, m + wait); n         wait++; n       } n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int MOD = 1e9 + 7; n long long int t; n string s; n long long int n; n long long int dp[100][2501]; n long long int adp[100][2501]; n long long int l, r, sm; n void solve() { n   cin >> s; n   n = s.length() - 1; n   sm = 0; n   for (auto it : s) sm += it -  a ; n   l = adp[n][sm] - 1; n   if (l < 0) l += MOD; n   cout << l << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   for (int i = 0; i < 26; i++) adp[0][i] = dp[0][i] = 1; n   for (int i = 1; i <= 2500; i++) { n     dp[0][i] += dp[0][i - 1]; n     dp[0][i] %= MOD; n   } n   for (int i = 1; i < 100; i++) { n     for (int j = 0; j <= 2500; j++) { n       l = r = 0; n       if (j - 26 >= 0) l = dp[i - 1][j - 26]; n       r = dp[i - 1][j]; n       dp[i][j] = r - l; n       if (dp[i][j] < 0) dp[i][j] += MOD; n       dp[i][j] %= MOD; n       adp[i][j] = dp[i][j]; n       if (j != 0) { n         dp[i][j] += dp[i][j - 1]; n         dp[i][j] %= MOD; n       } n     } n   } n   t = 1; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   for (int tc = 1; tc <= t; tc++) { n     int n; n     cin >> n; n     pair<pair<int, int>, int> arr[2 * n - 1]; n     for (int i = 0; i < 2 * n - 1; i++) { n       cin >> arr[i].first.first >> arr[i].first.second; n       arr[i].second = i; n     } n     sort(arr, arr + 2 * n - 1); n     long long odd = 0, even = 0; n     for (int i = 0; i < 2 * n - 1; i++) { n       if (i & 1) n         even += arr[i].first.second; n       else n         odd += arr[i].first.second; n     } n     if (odd >= even) { n       cout <<  YES n ; n       int ans[n]; n       for (int i = 0; i < 2 * n - 1; i += 2) ans[i / 2] = arr[i].second + 1; n       sort(ans, ans + n); n       for (int i = 0; i < n - 1; i++) cout << ans[i] <<    ; n       cout << ans[n - 1] <<   n ; n     } else { n       cout <<  YES n ; n       int ans[n]; n       for (int i = 1; i < 2 * n - 1; i += 2) ans[i / 2] = arr[i].second + 1; n       ans[n - 1] = arr[2 * n - 2].second + 1; n       sort(ans, ans + n); n       for (int i = 0; i < n - 1; i++) cout << ans[i] <<    ; n       cout << ans[n - 1] <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n pair<int, pair<int, int> > tup[100000 * 2 + 10]; n multiset<int> st; n int L[100000 * 2 + 10], R[100000 * 2 + 10], sl[100000 * 2 + 10], n     sr[100000 * 2 + 10]; n int main() { n   int m, n, r, l, t; n   scanf( %d%d , &m, &n); n   int flag = 0; n   for (int i = 1; i <= n; i++) { n     scanf( %d%d%d , &l, &r, &t); n     tup[i] = make_pair(l, make_pair(t, 0)); n     tup[i + n] = make_pair(r, make_pair(t, 1)); n   } n   n *= 2; n   sort(tup + 1, tup + n + 1); n   int lasty = -1, o = 0; n   for (int i = 1; i <= n; i++) { n     int cury = tup[i].first; n     if (lasty != -1 && cury != lasty && st.size()) { n       if (st.empty()) { n         printf( empty n ); n         return 0; n       } n       int curt = *st.begin(); n       L[++o] = curt - lasty; n       R[o] = curt - cury; n     } n     lasty = cury; n     if (tup[i].second.second) n       st.erase(st.lower_bound(tup[i].second.first)); n     else n       st.insert(tup[i].second.first); n   } n   if (flag) { n     printf( o:%d n , o); n     return 0; n   } n   sort(L + 1, L + o + 1); n   sort(R + 1, R + o + 1); n   for (int i = 1; i <= o; i++) n     sl[i] = sl[i - 1] + L[i], sr[i] = sr[i - 1] + R[i]; n   while (m--) { n     scanf( %d , &t); n     l = lower_bound(L + 1, L + o + 1, t) - L - 1; n     r = lower_bound(R + 1, R + o + 1, t) - R - 1; n     printf( %d n , (int)((r - l) * (long long)t - sr[r] + sl[l])); 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 n; n     cin >> n; n     string s[n]; n     map<string, int> m; n     set<string> k; n     int count = 0; n     for (int i = 0; i < n; i++) { n       cin >> s[i]; n       k.insert(s[i]); n     } n     for (int i = 0; i < n; i++) { n       if (m[s[i]] >= 1) { n         count++; n         int j = 0; n         while (k.find(s[i]) != k.end()) { n           s[i][3] = j +  0 ; n           j++; n         } n       } n       m[s[i]]++; n       k.insert(s[i]); n     } n     cout << count << endl; n     for (int i = 0; i < n; i++) cout << s[i] << endl; n   } 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), cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int a, b, c, d; n     cin >> a >> b >> c >> d; n     cout << max(a + b, c + d) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:268435456 ) n using namespace std; n long long _gcd(long long a, long long b) { n   if (b == 0) return a; n   _gcd(b, a % b); n } n int main() { n   int n, m, k, a[20500][10], res[20500] = {0}, b[20500][10] = {0}; n   cin >> n >> m >> k; n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < m; ++j) cin >> a[i][j]; n   for (int i = 0; i < k; ++i) { n     int l, r; n     cin >> l >> r; n     l--; n     r--; n     b[0][r]++; n     b[l][r]--; n     b[l + 1][r]++; n     b[n][r]--; n   } n   for (int i = 0; i < m; ++i) { n     for (int j = 1; j < n; ++j) b[j][i] += b[j - 1][i]; n   } n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) n       if (a[i][j] == 1) res[i] += b[i][j]; n   } n   for (int i = 0; i < n; ++i) cout << res[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n const long double eps = 1e-9; n const int inf = 1e+9; n const double pi = acos(-1.0); n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n long long xabs(long long a) { return a > 0 ? a : -a; } n map<int, vector<string>> s; n int sm[9][2] = {{0, 1},  {0, -1}, {1, 0},   {-1, 0}, {1, 1}, n                 {1, -1}, {-1, 1}, {-1, -1}, {0, 0}}; n void dfs(int x, int y, int t) { n   if (t == 9) { n     cout <<  WIN ; n     exit(0); n   } n   if (s[t][x][y] ==  S ) return; n   for (int i = 0; i < 9; i++) { n     int xx = x + sm[i][0]; n     int yy = y + sm[i][1]; n     if (xx >= 0 && xx < 8 && yy >= 0 && yy < 8 && s[t][xx][yy] !=  S ) n       dfs(xx, yy, t + 1); n   } n } n int main() { n   for (int i = 0; i < 8; i++) { n     string t; n     cin >> t; n     s[0].push_back(t); n   } n   for (int i = 1; i <= 8; i++) { n     string r =  ........ ; n     s[i].push_back(r); n     for (int k = 0; k < 7; k++) { n       s[i].push_back(s[i - 1][k]); n     } n   } n   dfs(7, 0, 0); n   cout <<  LOSE ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T, class U> n void maximize(T &x, U y) { n   if (x < y) x = y; n } n template <class T, class U> n void minimize(T &x, U y) { n   if (x > y) x = y; n } n template <class T> n T Abs(T x) { n   return (x < (T)0 ? -x : x); n } n namespace task { n const int N = 2e5 + 5; n const int maxVal = 5e5; n vector<int> prime; n vector<vector<int> > p; n int e[maxVal + 5]; n int cnt[maxVal + 5]; n bool inshelf[N]; n int a[N]; n int n, q; n void solve() { n   cin >> n >> q; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n   } n   iota(e, e + 1 + maxVal, 0); n   for (int i = 2; i <= maxVal; ++i) { n     if (e[i] == i) { n       prime.emplace_back(i); n     } n     for (int j = 0; j < (int)((prime).size()) and i * prime[j] <= maxVal; ++j) { n       e[i * prime[j]] = prime[j]; n       if (i % prime[j] == 0) { n         break; n       } n     } n   } n   p.resize(n + 2, vector<int>()); n   for (int i = 1; i <= n; ++i) { n     int tmp = a[i]; n     for (int k = e[tmp]; k > 1 and tmp > 1; k = e[tmp]) { n       while (tmp % k == 0) { n         tmp /= k; n       } n       p[i].emplace_back(k); n     } n   } n   int cur = 0; n   long long ans = 0; n   while (q--) { n     int x; n     cin >> x; n     long long subs = 0; n     int k = (inshelf[x] ? -1 : 1); n     for (int mask = 1; mask < ((1LL) << ((int)((p[x]).size()))); ++mask) { n       int mul = 1; n       for (int i = 0; i < (int)((p[x]).size()); ++i) { n         if ((((mask) >> (i)) & 1)) { n           mul *= p[x][i]; n         } n       } n       subs += 1LL * ((__builtin_popcount(mask) & 1) ? 1 : -1) * 1LL * cnt[mul]; n     } n     if (!inshelf[x]) { n       ans += cur - subs; n       inshelf[x] = true; n       ++cur; n     } else { n       ans -= cur - (a[x] == 1 ? 1 : subs); n       inshelf[x] = false; n       --cur; n     } n     cout << ans <<   n ; n     for (int mask = 1; mask < ((1LL) << ((int)((p[x]).size()))); ++mask) { n       int mul = 1; n       for (int i = 0; i < (int)((p[x]).size()); ++i) { n         if ((((mask) >> (i)) & 1)) { n           mul *= p[x][i]; n         } n       } n       cnt[mul] += k; n     } n   } n } n }  // namespace task n int main(void) { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   task::solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n const int mod = 1e9 + 7; n const int maxn = 55; n int st[maxn]; n struct E { n   int u, v, w, cost; n   int nxt; n } edge[500009]; n int gtot = 0, head[maxn * 100]; n void addedge(int u, int v, int w, int cost) { n   edge[gtot].v = v; n   edge[gtot].w = w; n   edge[gtot].cost = cost; n   edge[gtot].nxt = head[u]; n   head[u] = gtot++; n   edge[gtot].v = u; n   edge[gtot].w = 0; n   edge[gtot].cost = -cost; n   edge[gtot].nxt = head[v]; n   head[v] = gtot++; n } n int dis[maxn * 100], path[500009], vis[maxn * 100], pre[maxn * 100]; n bool spfa(int s, int t) { n   memset(pre, -1, sizeof(pre)); n   memset(dis, inf, sizeof(dis)); n   memset(vis, 0, sizeof(vis)); n   queue<int> que; n   que.push(s); n   vis[s] = 1; n   dis[s] = 0; n   while (!que.empty()) { n     int u = que.front(); n     que.pop(); n     vis[u] = 0; n     for (int i = head[u]; ~i; i = edge[i].nxt) { n       int v = edge[i].v, val = edge[i].w, cost = edge[i].cost; n       if (val > 0 && dis[v] > dis[u] + cost) { n         dis[v] = dis[u] + cost; n         pre[v] = u; n         path[v] = i; n         if (vis[v] == 0) { n           vis[v] = 1; n           que.push(v); n         } n       } n     } n   } n   return pre[t] != -1; n } n int mcmf(int s, int t) { n   int flow = 0, cost = 0; n   while (spfa(s, t)) { n     int f = inf; n     for (int i = t; i != s; i = pre[i]) { n       f = min(f, edge[path[i]].w); n     } n     flow += f; n     cost += f * dis[t]; n     for (int i = t; i != s; i = pre[i]) { n       edge[path[i]].w -= f; n       edge[path[i] ^ 1].w += f; n     } n   } n   return cost; n } n int main() { n   memset(head, -1, sizeof(head)); n   gtot = 0; n   int n, m, k, c, d; n   scanf( %d%d%d%d%d , &n, &m, &k, &c, &d); n   for (int i = 1; i <= k; i++) { n     int x; n     scanf( %d , &x); n     st[x]++; n   } n   int s = 0, t = 100 * n + 1; n   for (int i = 1; i <= n; i++) { n     for (int j = 2; j <= 100; j++) { n       addedge((i - 1) * 100 + j - 1, (i - 1) * 100 + j, inf, c); n     } n   } n   for (int i = 2; i <= n; i++) { n     if (st[i]) addedge(s, (i - 1) * 100 + 1, st[i], 0); n   } n   for (int i = 1; i <= 100; i++) addedge(i, t, inf, 0); n   for (int i = 1; i <= m; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     for (int j = 2; j <= 100; j++) { n       for (int k = 1; k <= 20; k++) { n         addedge((u - 1) * 100 + j - 1, (v - 1) * 100 + j, 1, n                 (k * k - (k - 1) * (k - 1)) * d + c); n         addedge((v - 1) * 100 + j - 1, (u - 1) * 100 + j, 1, n                 (k * k - (k - 1) * (k - 1)) * d + c); n       } n     } n   } n   printf( %d n , mcmf(s, t)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int read(); n int n; n int a[200005], b[200005], c[200005], bk[200005]; n int hd[200005], nx[400005], to[400005], cnt; n void add(int f, int t) { nx[++cnt] = hd[f], hd[f] = cnt, to[cnt] = t; } n int fa[200005], dep[200005]; n void dfs1(int u) { n   for (int i = hd[u], v; i; i = nx[i]) n     if ((v = to[i]) != fa[u]) dep[v] = dep[fa[v] = u] + 1, dfs1(v); n } n bool check1() { n   for (int i = 1; i <= n; ++i) c[i] = b[i]; n   int u = a[1]; n   while (fa[u]) swap(c[u], c[fa[u]]), u = fa[u]; n   for (int i = 1; i <= n; ++i) n     if (c[i] != i) return 0; n   return 1; n } n vector<int> st[2]; n int idcnt; n void fail() { puts( -1 ), exit(0); } n void get(int u, int id) { n   if (id >= 2 || (id == 1 && fa[st[0][0]] != fa[u])) fail(); n   st[id].push_back(u); n   while (1) { n     int v = 0; n     for (int i = hd[u]; i; i = nx[i]) n       if (to[i] != fa[u] && c[to[i]] != to[i]) v ? fail() : (v = to[i], void()); n     if (!v) break; n     st[id].push_back(u = v); n   } n } n void dfs2(int u) { n   for (int i = hd[u], v; i; i = nx[i]) n     if ((v = to[i]) != fa[u]) (c[v] != v) ? get(v, idcnt++) : dfs2(v); n } n int p[200005], q[200005], len; n int M(int x) { return x >= len ? x - len : x; } n int getdis(int u, int v) { n   int rt = 0; n   while (u != v) (dep[u] < dep[v]) ? swap(u, v) : void(), ++rt, u = fa[u]; n   return rt; n } n void work() { n   for (int i = 1; i <= n; ++i) q[i] = -1; n   for (int i = 0; i < st[0].size(); ++i) n     p[len] = c[st[0][i]], q[st[0][i]] = len, ++len; n   int ru = st[0].back(), rv = fa[st[0].front()], rw = rv; n   if (st[1].size()) { n     rv = st[1].back(); n     for (int i = st[1].size() - 1; i >= 0; --i) n       p[len] = c[st[1][i]], q[st[1][i]] = len, ++len; n   } n   if ((ru = bk[ru]) > (rv = bk[rv])) swap(ru, rv); n   long long dis = q[p[0]]; n   for (int i = 1; i < len; ++i) n     if (M(q[p[i]] - i + len) != dis) fail(); n   for (int i = 1; i <= n; ++i) n     if (c[i] != i && q[i] == -1) fail(); n   int t = a[1]; n   while (q[t] == -1 && t != 1) t = fa[t]; n   if (t == 1) { n     dis = min(dis, len - dis) * (len + 1); n     printf( %d %d %lld n , ru, rv, dis + getdis(a[1], rw) + dep[rw]); n     return; n   } n   dis = q[t] >= st[0].size() n             ? min((dis - 1) * (len + 1) + (q[t] + 1), n                   1ll * M(len - dis) * (len + 1) + (len - q[t])) n             : min(dis * (len + 1) + (q[t] + 1), n                   (len - dis - 1) * (len + 1) + (len - q[t])); n   printf( %d %d %lld n , ru, rv, dis + dep[rw] + getdis(a[1], t)); n } n int main() { n   n = read(); n   for (int i = 1; i <= n; ++i) bk[a[i] = read() + 1] = i; n   for (int i = 1; i <= n; ++i) b[a[i]] = read() + 1; n   for (int i = 1, u, v; i < n; ++i) n     u = a[read()], v = a[read()], add(u, v), add(v, u); n   for (int i = 1; i <= n; ++i) a[b[i]] = i; n   dfs1(1); n   if (check1()) return printf( 0 %d n , dep[a[1]]), 0; n   dfs2(1), work(); n   return 0; n } n const int _SIZE = 1 << 22; n char ibuf[_SIZE], *iS = ibuf, *iT = ibuf; n int read() { n   int x = 0, f = 1; n   char c = (iS == iT ? iT = ((iS = ibuf) + fread(ibuf, 1, _SIZE, stdin)), n             (iS == iT ? EOF : *iS++) : *iS++); n   while (!isdigit(c)) n     f = (c ==  - ) ? -1 : f, n     c = (iS == iT ? iT = ((iS = ibuf) + fread(ibuf, 1, _SIZE, stdin)), n          (iS == iT ? EOF : *iS++) : *iS++); n   while (isdigit(c)) n     x = x * 10 + c -  0 , n     c = (iS == iT ? iT = ((iS = ibuf) + fread(ibuf, 1, _SIZE, stdin)), n          (iS == iT ? EOF : *iS++) : *iS++); n   return x * f; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, t = 1, c1, c2; n vector<vector<long long>> adj; n vector<vector<long long>> g; n vector<bool> visited; n void DFS(long long v) { n   visited[v] = true; n   g[t].push_back(v); n   for (auto i : adj[v]) n     if (!visited[i]) DFS(i); n } n long long number_of_components() { n   for (long long v = 1; v <= n; v++) n     if (!visited[v]) { n       DFS(v); n       if (g[t].size() > 3) { n         cout <<  -1 ; n         return -1; n       } n       if (g[t].size() == 1) c1++; n       if (g[t].size() == 2) c2++; n       t++; n     } n } n void solve() { n   long long m, x, y, j = 0, h = 1; n   cin >> n >> m; n   adj.resize(n + 1); n   g.resize(n + 1); n   visited.assign(n + 1, false); n   for (long long i = 1; i <= m; i++) { n     cin >> x >> y; n     adj[x].push_back(y); n     adj[y].push_back(x); n   } n   long long z = number_of_components(); n   if (z == -1) return; n   if (c2 > c1) { n     cout <<  -1 ; n     return; n   } n   if ((c1 - c2) % 3 != 0) { n     cout << -1; n     return; n   } n   for (long long i = 1; i <= t; i++) { n     if (g[i].size() == 3) { n       for (auto v : g[i]) cout << v <<    ; n       cout <<   n ; n     } n     if (g[i].size() == 2) { n       for (auto v : g[i]) cout << v <<    ; n       for (j = h; j <= t; j++) n         if (g[j].size() == 1) { n           cout << g[j][0]; n           break; n         } n       h = j + 1; n       cout <<   n ; n     } n   } n   for (long long i = j + 1; i <= t; i++) { n     if (g[i].size() == 1) cout << g[i][0] <<    ; n     if ((j - i) % 3 == 0) cout <<   n ; n   } n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   solve(); n   cerr <<  time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, d, h; n int main() { n   cin >> n >> d >> h; n   if (d - h > h) { n     cout <<  -1  << endl; n     return 0; n   } n   if (h == 1 && d == 1 && n > 2) { n     cout <<  -1  << endl; n     return 0; n   } n   for (int i = 2; i <= h + 1; i++) { n     cout << i - 1 <<     << i << endl; n   } n   int j = 1; n   for (int i = h + 2; i <= d + 1; i++) { n     if (i > h + 2) j = i - 1; n     cout << j <<     << i << endl; n   } n   for (int i = d + 2; i <= n; i++) { n     cout << h <<     << i << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, k; n char s[200005]; n vector<long long> cnt[3][202]; n vector<pair<long long, long long> > res; n int main() { n   long long i, j; n   scanf( %lld , &n); n   scanf( %s , &s); n   for (i = 0; i <= n - 1; i++) { n     cnt[1][s[i]].push_back(i + 1); n   } n   scanf( %s , &s); n   for (i = 0; i <= n - 1; i++) { n     cnt[2][s[i]].push_back(i + 1); n   } n   for (i =  a ; i <=  z ; i++) { n     while (cnt[1][i].size() && cnt[2][i].size()) { n       res.push_back(make_pair(cnt[1][i].back(), cnt[2][i].back())); n       cnt[1][i].pop_back(), cnt[2][i].pop_back(); n     } n   } n   for (i =  a ; i <=  z ; i++) { n     while (cnt[2][i].size() && cnt[1][ ? ].size()) { n       res.push_back(make_pair(cnt[1][ ? ].back(), cnt[2][i].back())); n       cnt[1][ ? ].pop_back(), cnt[2][i].pop_back(); n     } n   } n   for (i =  a ; i <=  z ; i++) { n     while (cnt[1][i].size() && cnt[2][ ? ].size()) { n       res.push_back(make_pair(cnt[1][i].back(), cnt[2][ ? ].back())); n       cnt[2][ ? ].pop_back(), cnt[1][i].pop_back(); n     } n   } n   while (cnt[1][ ? ].size() && cnt[2][ ? ].size()) { n     res.push_back(make_pair(cnt[1][ ? ].back(), cnt[2][ ? ].back())); n     cnt[2][ ? ].pop_back(), cnt[1][ ? ].pop_back(); n   } n   long long d = res.size(); n   printf( %lld n , d); n   for (i = 0; i <= d - 1; i++) { n     printf( %lld %lld n , res[i].first, res[i].second); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2010; n char mp[N][N]; n int n, m, cnt1, cnt2, in[N][N]; n int xx[6] = {0, 0, 1, 0, -1}; n int yy[6] = {0, 1, 0, -1, 0}; n queue<pair<long long, long long> > q; n int main() { n   int n, m; n   while (cin >> n >> m) { n     memset(in, 0, sizeof in); n     for (int i = 1; i <= n; i++) { n       scanf( %s , mp[i] + 1); n     } n     cnt1 = cnt2 = 0; n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= m; j++) n         if (mp[i][j] ==  . ) { n           cnt1++; n           for (int k = 1; k <= 4; k++) n             if (mp[i + xx[k]][j + yy[k]] ==  . ) in[i][j]++; n           if (in[i][j] == 1) { n             q.push(pair<long long, long long>(i, j)); n           } n         } n     } n     while (!q.empty()) { n       pair<long long, long long> u = q.front(); n       q.pop(); n       int x = u.first, y = u.second, tx, ty, i; n       for (i = 1; i <= 4; i++) { n         tx = x + xx[i]; n         ty = y + yy[i]; n         if (mp[tx][ty] ==  . ) { n           cnt2 += 2; n           if (i == 1) mp[x][y] =  < , mp[tx][ty] =  > ; n           if (i == 2) mp[x][y] =  ^ , mp[tx][ty] =  v ; n           if (i == 3) mp[x][y] =  > , mp[tx][ty] =  < ; n           if (i == 4) mp[x][y] =  v , mp[tx][ty] =  ^ ; n           break; n         } n       } n       if (i == 5) continue; n       x = tx, y = ty; n       for (int i = 1; i <= 4; i++) { n         tx = x + xx[i]; n         ty = y + yy[i]; n         if (mp[tx][ty] ==  . ) { n           in[tx][ty]--; n           if (in[tx][ty] == 1) { n             q.push(pair<long long, long long>(tx, ty)); n           } n         } n       } n     } n     if (cnt1 < cnt2) { n       cout << cnt1 <<     << cnt2 << endl; n       for (int i = 1; i <= n; i++) { n         printf( %s n , mp[i] + 1); n       } n       break; n     } n     if (cnt1 != cnt2) { n       printf( Not unique n ); n       continue; n     } n     for (int i = 1; i <= n; i++) { n       printf( %s n , mp[i] + 1); n     } n   } n } n


#include <bits/stdc++.h> n long long int segMax[1000010] = {0}, segSum[1000010] = {0}; n long long int a[200010]; n void constructMax(int low, int high, int pos) { n   if (low > high) return; n   if (low == high) { n     segMax[pos] = a[low]; n     return; n   } n   int mid = low + (high - low) / 2; n   constructMax(low, mid, pos * 2 + 1); n   constructMax(mid + 1, high, pos * 2 + 2); n   segMax[pos] = std::max(segMax[pos * 2 + 1], segMax[pos * 2 + 2]); n } n void updateMax(int low, int high, int node, long long int val, int pos) { n   if (low == high && low == node) { n     segMax[pos] = val; n     return; n   } n   if (high < node || low > node) return; n   int mid = low + (high - low) / 2; n   updateMax(low, mid, node, val, pos * 2 + 1); n   updateMax(mid + 1, high, node, val, pos * 2 + 2); n   segMax[pos] = std::max(segMax[pos * 2 + 1], segMax[pos * 2 + 2]); n } n void constructSum(int low, int high, int pos) { n   if (low > high) return; n   if (low == high) { n     segSum[pos] = a[low]; n     return; n   } n   int mid = low + (high - low) / 2; n   constructSum(low, mid, pos * 2 + 1); n   constructSum(mid + 1, high, pos * 2 + 2); n   segSum[pos] = segSum[pos * 2 + 1] + segSum[pos * 2 + 2]; n } n void updateSum(int low, int high, int node, long long int val, int pos) { n   if (low == high && low == node) { n     a[low] = val; n     segSum[pos] = val; n     return; n   } n   if (low > node || high < node) return; n   int mid = low + (high - low) / 2; n   updateSum(low, mid, node, val, pos * 2 + 1); n   updateSum(mid + 1, high, node, val, pos * 2 + 2); n   segSum[pos] = segSum[pos * 2 + 1] + segSum[pos * 2 + 2]; n } n int findMax(int low, int high, int sumToFind, int pos) { n   if (low == high && segMax[pos] >= sumToFind) { n     return low; n   } else if (low == high) { n     return -1; n   } n   int mid = low + (high - low) / 2; n   if (segMax[pos * 2 + 1] >= sumToFind) { n     return findMax(low, mid, sumToFind, pos * 2 + 1); n   } else if (segMax[pos * 2 + 2] >= sumToFind) { n     return findMax(mid + 1, high, sumToFind, pos * 2 + 2); n   } else { n     return -1; n   } n } n long long int findSum(int qlow, int qhigh, int low, int high, int pos) { n   if (high < qlow || low > qhigh) return 0; n   if (qlow > qhigh) n     return 0; n   else if (qlow <= low && high <= qhigh) { n     return segSum[pos]; n   } n   int mid = low + (high - low) / 2; n   return findSum(qlow, qhigh, low, mid, pos * 2 + 1) + n          findSum(qlow, qhigh, mid + 1, high, pos * 2 + 2); n } n int main() { n   std::ios_base::sync_with_stdio(0); n   std::cin.tie(0); n   int n, q; n   std::cin >> n >> q; n   for (int i = 0; i < n; ++i) { n     std::cin >> a[i]; n   } n   constructMax(1, n - 1, 0); n   constructSum(1, n - 1, 0); n   while (q--) { n     int node; n     long long int val; n     std::cin >> node >> val; n     --node; n     if (node != 0) { n       updateMax(1, n - 1, node, val, 0); n       updateSum(1, n - 1, node, val, 0); n     } else { n       a[node] = val; n     } n     if (a[0] == 0) { n       std::cout <<  1 n ; n       continue; n     } n     long long int curSum = a[0]; n     bool flag = false; n     while (curSum <= 1e9) { n       int node = findMax(1, n - 1, curSum, 0); n       long long int nowSum; n       if (node == -1) n         break; n       else { n         nowSum = findSum(1, node - 1, 1, n - 1, 0); n         nowSum += a[0]; n       } n       if (nowSum == a[node]) { n         std::cout << node + 1 <<   n ; n         flag = true; n         break; n       } else { n         curSum = nowSum + a[node]; n       } n     } n     if (!flag) { n       std::cout <<  -1 n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   for (int z = 0; z < t; z++) { n     int n, x, y; n     cin >> n; n     vector<vector<int>> v; n     for (int i = 0; i < n; i++) { n       cin >> x >> y; n       vector<int> t(2); n       t[0] = x, t[1] = y; n       v.push_back(t); n     } n     sort(v.begin(), v.end()); n     bool e = false; n     for (int i = 0; i < n - 1; i++) n       if (v[i + 1][1] < v[i][1]) { n         e = true; n         break; n       } n     if (e) n       cout <<  NO  << endl; n     else { n       cout <<  YES  << endl; n       string s; n       for (int i = 0; i < v[0][0]; i++) s +=  R ; n       for (int i = 0; i < v[0][1]; i++) s +=  U ; n       for (int i = 0; i < n - 1; i++) { n         for (int j = v[i][0]; j < v[i + 1][0]; j++) s +=  R ; n         for (int j = v[i][1]; j < v[i + 1][1]; j++) s +=  U ; n       } n       cout << s << endl; 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 a[n]; n   for (int i = 0; i < n; ++i) cin >> a[i]; n   string col[] = { Power ,  Space ,  Time ,  Soul ,  Reality ,  Mind }; n   string stone[] = { purple ,  blue ,  green ,  orange ,  red ,  yellow }; n   cout << 6 - n <<   n ; n   for (int i = 0; i < 6; ++i) { n     int flag = 0; n     for (int j = 0; j < n; ++j) { n       if (stone[i] == a[j]) { n         flag = 1; n         break; n       } n     } n     if (!flag) { n       cout << col[i] <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e5 + 10, M = 1e9, eps = 1e-7, MOD = 1e9 + 7; n long long tab[N]; n int main() { n   long long n, l; n   cin >> n >> l; n   n--; n   for (long long i = 1; i <= n; i++) cin >> tab[i]; n   long long pocz = 0; n   long long pot = 1 << 30; n   while (pot > 0) { n     long long moze = pot + pocz; n     if (moze > M) { n       pot /= 2; n       continue; n     } n     long long pom = 0; n     bool czujka = true; n     for (long long i = 1; i <= l; i++) pom += tab[i]; n     if (pom < moze) czujka = false; n     for (long long i = l + 1; i <= n; i++) { n       pom += tab[i]; n       pom -= tab[i - l]; n       if (pom < moze) czujka = false; n     } n     if (czujka) pocz = moze; n     pot /= 2; n   } n   cout << pocz; n } n


#include <bits/stdc++.h> n using namespace std; n bool endline = false; n template <class T> n istream& operator>>(istream& inp, vector<T>& v) { n   for (auto& it : v) inp >> it; n   return inp; n } n template <class T> n ostream& operator<<(ostream& out, vector<T>& v) { n   for (auto& it : v) out << it << (endline ?   n  :    ); n   return out; n } n template <class T, class U> n istream& operator>>(istream& inp, pair<T, U>& v) { n   inp >> v.first >> v.second; n   return inp; n } n template <class T, class U> n ostream& operator<<(ostream& out, pair<T, U>& v) { n   out << v.first <<     << v.second; n   return out; n } n void debug() { cout << endl; } n template <typename H, typename... T> n void debug(H a, T... b) { n   cout << a <<    ; n   debug(b...); n } n void FAST_IO(string filein =   , string fileout =   ) { n   if (fopen(filein.c_str(),  r )) { n     freopen(filein.c_str(),  r , stdin); n     freopen(fileout.c_str(),  w , stdout); n   } n   cin.tie(0), cout.tie(0)->sync_with_stdio(0); n } n void Hollwo_Pelw(); n signed main() { n   FAST_IO( .inp ,  .out ); n   int testcases = 1; n   for (int test = 1; test <= testcases; test++) { n     Hollwo_Pelw(); n   } n   return 0; n } n const int allmod[3] = {(int)1e9 + 7, 998244353, (int)1e9 + 9}; n const int mod = allmod[1]; n const int MAXN = 1e6 + 6; n const int inf = 2e9; n const long long linf = 1e18; n long long n; n void dofirst() { n   cout <<  First  << endl; n   for (long long i = 1; i <= n; i++) cout << i <<    ; n   for (long long i = 1; i <= n; i++) cout << i <<    ; n   cout << endl; n } n vector<long long> pr[MAXN], adj[MAXN]; n void addedge(long long u, long long v) { n   adj[u].push_back(v), adj[v].push_back(u); n } n long long vis[MAXN]; n void dfs(long long u, long long c) { n   vis[u] = c; n   for (auto v : adj[u]) n     if (!vis[v]) dfs(v, 3 - c); n } n void check(long long v) { n   long long sum = 0; n   for (long long i = 1; i <= 2 * n; i++) n     if (vis[i] == v) sum += i; n   if (sum % (2 * n) == 0) { n     for (long long i = 1; i <= 2 * n; i++) n       if (vis[i] == v) cout << i <<    ; n     cout << endl; n   } n } n void dosecond() { n   cout <<  Second  << endl; n   for (long long i = 1, p; i <= 2 * n; i++) cin >> p, pr[p].push_back(i); n   for (long long i = 1; i <= n; i++) n     addedge(pr[i][0], pr[i][1]), addedge(i, i + n); n   for (long long i = 1; i <= 2 * n; i++) n     if (!vis[i]) dfs(i, 1); n   check(1); n   check(2); n } n void getverdict() { n   long long x; n   cin >> x; n   if (!x) exit(0); n } n void Hollwo_Pelw() { n   cin >> n; n   if (n % 2 == 0) { n     dofirst(); n   } else { n     dosecond(); n   } n   getverdict(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k, i = 1; n   cin >> n >> k; n   if (k == 1) n     cout << n; n   else { n     vector<int> ans; n     while (ans.size() < k) { n       i = 2; n       while (n % i != 0 && i <= n + 1) i++; n       if (i >= n + 1) { n         cout << -1; n         return 0; n       } n       n /= i; n       ans.push_back(i); n     } n     for (i = 0; i < ans.size() - 1; i++) cout << ans[i] <<    ; n     cout << n * ans[ans.size() - 1]; n   } n } n


#include <bits/stdc++.h> n using namespace std; n void OJ() {} n void solve() { n   long long n; n   cin >> n; n   long long digit = 1000000, a = -1, b = -1; n   for (long long i = 0; i < 1e6; ++i) { n     if (n >= 4 * i) n       if ((n - 4 * i) % 7 == 0) { n         if ((n - 4 * i) / 7 + i <= digit) n           digit = (n - 4 * i) / 7 + i, a = i, b = (n - 4 * i) / 7; n       } n   } n   if (a == -1) { n     cout << -1; n     return; n   } n   for (long long i = 0; i < a; ++i) cout << 4; n   for (long long i = 0; i < b; ++i) cout << 7; n } n signed main() { n   OJ(); n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int p[12]; n int main() { n   long long n; n   cin >> n; n   if (n < 5) { n     cout << (n * (n - 1) / 2) << endl; n     return 0; n   } n   long long p = 5; n   for (int i = 1;; ++i) { n     if (p > n) { n       p /= 10; n       long long tot = p * 2; n       --i; n       ++n; n       if (n % tot <= p) { n         long long a = n % tot; n         long long b = p - a; n         long long x = n / tot; n         long long ans = (a * x * (x + 1)) + (b * x * x); n         ans -= x; n         cout << ans << endl; n       } else { n         long long a = n % tot - p; n         long long b = p - a; n         long long x = n / tot; n         long long ans = (a * (x + 1) * (x + 1)) + b * x * (x + 1); n         ans -= x; n         cout << ans << endl; n       } n       return 0; n     } n     p *= 10; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void rd(T &k) { n   char c = getchar(); n   int f = 1; n   k = 0; n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f *= -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     k = k * 10 + c -  0 ; n     c = getchar(); n   } n   k *= f; n } n const int N = 2200; n int n, m, k, s, t; n char c[5005]; n int f[N][1 << 12], sum[N]; n int g[1 << 12]; n int main() { n   cin >> c + 1; n   n = strlen(c + 1); n   for (k = 0, s = 1; s <= n; ++k, s <<= 1) n     ; n   --k; n   m = n + 1 - (1 << k); n   f[0][0] = 1; n   for (register int i = 1; i <= m; ++i) { n     char mx =  z ; n     memset(g, 0, sizeof(g)); n     for (register int j = 0; j < (1 << k); ++j) { n       if (f[i - 1][j]) g[j] = 1; n       for (register int p = 0; p < k; ++p) n         if ((j & (1 << p)) && g[j ^ (1 << p)]) g[j] = 1; n       if (g[j]) mx = min(mx, c[i + j]); n     } n     cout << mx; n     for (register int j = 0; j < (1 << k); ++j) n       if (g[j] && c[j + i] == mx) f[i][j] = 1; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long int INF = 1e18; n int32_t main() { n   long long int n; n   cin >> n; n   if (n % 2 != 0) { n     cout << 0 <<   n ; n     return 0; n     ; n   } n   long long int k = pow(2, n / 2); n   cout << k <<   n ; n   return 0; n   ; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n using ll = long long; n using db = long double; n using ii = pair<int, int>; n const int N = 5e5 + 5, LG = 19, MOD = 1e9 + 7; n const int SQ = 225; n const long double EPS = 1e-7; n string s; n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int _; n   cin >> _; n   while (_--) { n     int n; n     cin >> n; n     int cnt[2] = {}; n     vector<int> v; n     for (int i = 0; i < n; i++) { n       string s; n       cin >> s; n       v.push_back(s.size() / 2); n       for (auto c : s) cnt[c -  0 ]++; n     } n     cnt[0] /= 2; n     cnt[1] /= 2; n     sort(v.begin(), v.end()); n     int sum = cnt[0] + cnt[1]; n     int ans = 0; n     for (auto x : v) n       if (x <= sum) { n         sum -= x; n         ans++; n       } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long power(long long x, long long y, long long mod = 2e18) { n   long long ans = 1; n   x %= mod; n   while (y) { n     if (y & 1) ans = (x * ans) % mod; n     x = (x * x) % mod; n     y >>= 1; n   } n   return ans; n } n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long t; n   cin >> t; n   cout << setprecision(20); n   while (t--) { n     long long n, k; n     cin >> n >> k; n     if (n >= 32) { n       cout <<  YES   << n - 1 << endl; n       continue; n     } n     long long total = (pow(4, n) - 1) / 3; n     if (k > total) { n       cout <<  NO  << endl; n       continue; n     } n     long long left; n     bool f = 0; n     for (long long i = n; i >= 1; i--) { n       left = power(2, i + 1) - (i + 2); n       long long curr = (2 * (i) + 1) * (power(4, n - i) / 3); n       if (total - curr >= k && k >= left) { n         cout <<  YES   << n - i << endl; n         f = 1; n         break; n       } n     } n     if (!f) cout <<  NO n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[51][51]; n long long combinatorics(long long n, long long k) { n   double res = 1; n   for (long long i = 1; i <= k; ++i) res = res * (n - k + i) / i; n   return (long long)(res + 0.01); n } n int main() { n   long long n, m, i, j, numOneRow[51] = {0}, numZeroRow[51] = {0}, n                         numOneColumn[51] = {0}, numZeroColumn[51] = {0}, x, y; n   long long c; n   cin >> n >> m; n   c = m * n; n   for (i = 0; i < n; i++) { n     for (j = 0; j < m; j++) { n       cin >> a[i][j]; n       if (a[i][j] == 0) { n         numZeroRow[i]++, numZeroColumn[j]++; n       } else { n         numOneRow[i]++, numOneColumn[j]++; n       } n     } n   } n   for (i = 0; i < n; i++) { n     j = 2; n     x = numOneRow[i], y = numZeroRow[i]; n     while (x >= j) { n       c += combinatorics(x, j); n       j++; n     } n     j = 2; n     while (y >= j) { n       c += combinatorics(y, j); n       j++; n     } n   } n   for (j = 0; j < m; j++) { n     i = 2; n     x = numOneColumn[j], y = numZeroColumn[j]; n     while (x >= i) { n       c += combinatorics(x, i); n       i++; n     } n     i = 2; n     while (y >= i) { n       c += combinatorics(y, i); n       i++; n     } n   } n   cout << c << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long max(long long a, long long b) { n   if (a > b) { n     return a; n   } else { n     return b; n   } n } n long long min(long long a, long long b) { n   if (a < b) { n     return a; n   } else { n     return b; n   } n } n struct P { n   double x, y; n   P() {} n   P(double x, double y) : x(x), y(y) {} n   P operator+(const P &a) const { return P(x + a.x, y + a.y); } n   P operator-(const P &a) const { return P(x - a.x, y - a.y); } n   double operator^(const P &a) const { return x * a.x + y * a.y; } n   void in() { scanf( %lf%lf , &x, &y); } n   void out() { printf( REQUIRED %.7f %.7f n , x, y); } n   double dist(P a, P b) { n     return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); n   } n   double sqdist(P a, P b) { n     return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); n   } n }; n int n, m; n int a[300001], b[300001]; n int nxt[1000001], dir[1000001], cost[1000001], rev[1000001]; n int h; n int visit[300001], c[300001]; n int edge[300001]; n int l[300001], r[300001]; n int lb[300001], ty[1000001]; n void insert(int u, int v) { n   nxt[++h] = nxt[u]; n   nxt[u] = h; n   dir[h] = v; n   nxt[++h] = nxt[v]; n   nxt[v] = h; n   dir[h] = u; n } n void insert2(int u, int v, int id) { n   nxt[++h] = nxt[u]; n   nxt[u] = h; n   dir[h] = v; n   rev[h] = h + 1; n   ty[h] = id; n   edge[id] = h; n   nxt[++h] = nxt[v]; n   nxt[v] = h; n   dir[h] = u; n   rev[h] = h - 1; n   ty[h] = -1; n } n void DFS2(int p, int color) { n   c[p] = color; n   visit[p] = 1; n   for (int i = nxt[p]; i > 0; i = nxt[i]) n     if (visit[dir[i]] == 0) { n       DFS2(dir[i], 1 - color); n     } n } n int s, t; n int lvl[300001]; n int q[300001]; n bool BFS() { n   for (int i = (1); i <= (2 * n); i++) lvl[i] = -1; n   lvl[s] = 0; n   int top = 0, tail = 0; n   q[top++] = s; n   while (top > tail) { n     int u = q[tail++]; n     for (int po = nxt[u]; po > 0; po = nxt[po]) { n       if (lvl[dir[po]] == -1 && cost[po] > 0) { n         lvl[dir[po]] = lvl[u] + 1; n         q[top++] = dir[po]; n       } n     } n   } n   return (lvl[t] != -1); n } n int DFS(int u, int flow) { n   if (u == t) return flow; n   int w = flow; n   for (int po = nxt[u]; po > 0; po = nxt[po]) { n     if (lvl[dir[po]] == lvl[u] + 1 && cost[po]) { n       int x = DFS(dir[po], min(w, cost[po])); n       w -= x; n       cost[po] -= x; n       cost[rev[po]] += x; n     } n   } n   if (w == flow) lvl[u] = -3; n   return flow - w; n } n int MaxFlow() { n   int ans = 0; n   int p; n   while (BFS()) { n     while (p = DFS(s, 99999), p) { n       ans += p; n     } n   } n   return ans; n } n set<int> S; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = (1); i <= (n); i++) nxt[i] = -1; n   h = n; n   for (int i = (1); i <= (n); i++) scanf( %d , &a[i]); n   for (int i = (1); i <= (m); i++) { n     scanf( %d%d , &l[i], &r[i]); n     insert(l[i], r[i]); n   } n   for (int i = (1); i <= (n); i++) visit[i] = 0; n   for (int i = (1); i <= (n); i++) n     if (visit[i] == 0) DFS2(i, 1); n   for (int i = (0); i <= (n + 1); i++) nxt[i] = -1; n   h = n + 1; n   for (int i = (1); i <= (n); i++) { n     if (c[i] == 1) n       insert2(i, n + 1, i); n     else n       insert2(0, i, i); n   } n   for (int i = (1); i <= (m); i++) { n     if (c[l[i]] == 1) n       insert2(r[i], l[i], 0); n     else n       insert2(l[i], r[i], 0); n   } n   for (int i = (1); i <= (n); i++) { n     int base = a[i]; n     for (int j = (2); j <= (sqrt(base)); j++) { n       if (base % j == 0) { n         S.insert(j); n         while (base % j == 0) base /= j; n       } n     } n     if (base != 1) S.insert(base); n   } n   int ans = 0; n   s = 0; n   t = n + 1; n   for (set<int>::iterator it = S.begin(); it != S.end(); ++it) { n     int w = *it; n     for (int i = (1); i <= (h); i++) cost[i] = 0; n     for (int i = (1); i <= (h); i++) n       if (ty[i] == 0) cost[i] = 999; n     for (int i = (1); i <= (n); i++) { n       b[i] = 0; n       int base = a[i]; n       while (base % w == 0) { n         base /= w; n         b[i]++; n       } n       cost[edge[i]] = b[i]; n     } n     ans += MaxFlow(); n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e6 + 10; n typedef struct Item { n   long long v; n   int id; n   Item(long long a, int b) { n     v = a; n     id = b; n   } n   bool operator<(const Item &rhs) const { return v < rhs.v; } n } Item; n typedef struct Node { n   vector<int> p; n   vector<Item> pp; n   long long sum, r; n   int id; n   bool operator<(const Node &rhs) const { n     return pp.back().v < rhs.pp.back().v; n   } n } Node; n int n, m; n Node nd[MAXN]; n int bs(int i, int u, int v, long long x) { n   if (u > v) return -1; n   int mid = u + (v - u) / 2; n   if (nd[i].pp[mid].v == x) n     return mid; n   else if (nd[i].pp[mid].v > x) n     return bs(i, u, mid - 1, x); n   return bs(i, mid + 1, v, x); n } n int main(void) { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout << setprecision(10) << fixed; n   cin >> n; n   for (int i = 0; i < n; i++) { n     int k; n     cin >> k; n     nd[i].sum = 0; n     nd[i].id = i + 1; n     for (int j = 0; j < k; j++) { n       long long v; n       cin >> v; n       nd[i].sum += v; n       nd[i].p.push_back(v); n     } n     for (int j = 0; j < k; j++) n       nd[i].pp.push_back(Item(nd[i].sum - nd[i].p[j], j + 1)); n     sort(nd[i].pp.begin(), nd[i].pp.end()); n     nd[i].r = nd[i].pp.back().v; n   } n   sort(nd, nd + n); n   bool found = false; n   for (int i = 1; i < n; i++) { n     for (int j = i - 1; j >= 0; j--) { n       if (nd[j].r < nd[i].pp[0].v) break; n       for (int k = 0; k < nd[j].pp.size(); k++) { n         int pos = bs(i, 0, nd[i].pp.size() - 1, nd[j].pp[k].v); n         if (pos > -1) { n           found = true; n           cout <<  YES  << endl; n           cout << nd[i].id <<     << nd[i].pp[pos].id << endl; n           cout << nd[j].id <<     << nd[j].pp[k].id << endl; n           break; n         } n       } n       if (found) break; n     } n     if (found) break; n   } n   if (!found) cout <<  NO  << endl; n   cerr <<  execute time :   << (double)clock() / CLOCKS_PER_SEC << endl; n   return 0; n } n


#include <bits/stdc++.h> n const int maxn = int(1e5) + 7, mod = int(1e9) + 7; n bool not_prime[maxn]; n std::map<int, int> cnt[maxn]; n std::vector<int> factor[maxn]; n long long qpow(long long p, long long q) { n   long long ret = 1; n   while (q) { n     if (q & 1) ret = ret * p % mod; n     p = p * p % mod; n     q >>= 1; n   } n   return ret; n } n void init() { n   for (int i = 2; i < maxn; i++) { n     for (int j = 2; i * j < maxn; j++) factor[i * j].push_back(i); n     if (!not_prime[i]) { n       for (int j = 1; i * j < maxn; j++) { n         int num = i * j; n         not_prime[num] = true; n         cnt[num][i] = j; n       } n     } n   } n } n int f[maxn], m; n int calc(int x, int y) { n   int ret = m / y, a = x / y, b = m / y; n   std::vector<int> buf; n   for (auto &it : cnt[a]) { n     buf.push_back(it.first); n   } n   int len = int(buf.size()); n   for (int i = 1; i < 1 << len; i++) { n     int tmp = 1; n     for (int j = 0; j < len; j++) { n       if ((i >> j) & 1) { n         tmp = -tmp * buf[j]; n       } n     } n     ret += b / tmp; n   } n   return ret; n } n int main() { n   init(); n   std::cin >> m; n   int inv_m = int(qpow(m, mod - 2)), ans = 1; n   for (int i = 2; i <= m; i++) { n     f[i] = 1; n     for (auto &k : factor[i]) { n       f[i] = int((f[i] + 1ll * calc(i, k) * f[k] % mod * inv_m % mod) % mod); n     } n     f[i] = n         int(1ll * f[i] * n             qpow((1 - 1ll * (m / i) * inv_m % mod + mod) % mod, mod - 2) % mod); n     ans = int((ans + 1ll * f[i] * inv_m % mod) % mod); n   } n   std::cout << ans << std::endl; n   return 0; n } n


#include <bits/stdc++.h> n int gcd(int a, int b) { n   int r; n   while (b != 0) { n     r = a % b; n     a = b; n     b = r; n   } n   return a; n } n int main() { n   int n, m; n   int deg1, deg2; n   scanf( %d %d , &n, &m); n   for (int i = 0, a; i <= n; i++) { n     scanf( %d , &a); n     if (i == 0) deg1 = a; n   } n   for (int i = 0, a; i <= m; i++) { n     scanf( %d , &a); n     if (i == 0) deg2 = a; n   } n   if (n > m) { n     if (deg1 > 0 && deg2 > 0 || (deg1 < 0 && deg2 < 0)) n       printf( Infinity ); n     else n       printf( -Infinity ); n   } else if (m > n) n     printf( 0/1 ); n   else { n     while (gcd(deg1, deg2) != 1) { n       int r = gcd(deg1, deg2); n       deg1 /= r; n       deg2 /= r; n     } n     if (deg1 < 0 && deg2 < 0 || (deg1 > 0 && deg2 > 0)) n       printf( %d/%d , deg1, deg2); n     else n       printf( -%d/%d , abs(deg1), abs(deg2)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 5; n struct node { n   int vl, mnvl; n   node *l, *r; n   node() { n     mnvl = MAXN; n     vl = -1; n     l = r = NULL; n   } n }; n vector<node*> dv(MAXN); n vector<bool> inarr(MAXN, false); n vector<vector<int>> diverse(MAXN); n deque<int> dbl(int a) { n   deque<int> d; n   while (a != 0) d.push_front(a % 2), a /= 2; n   while (d.size() != 18) d.push_front(0); n   return d; n } n void ins(node* d, deque<int> a, int n) { n   while (!a.empty()) { n     d->mnvl = min(d->mnvl, n); n     int b = a.front(); n     a.pop_front(); n     if (b == 0) { n       if (d->l == NULL) d->l = new node(); n       d = d->l; n     } else { n       if (d->r == NULL) d->r = new node(); n       d = d->r; n     } n   } n   d->vl = n; n   d->mnvl = min(d->mnvl, n); n } n int fnd(node* d, deque<int> xd, int s, int x) { n   while (!xd.empty()) { n     int xx = xd.front(); n     xd.pop_front(); n     if (xx == 0) n       if (d->r != NULL && d->r->mnvl + x <= s) n         d = d->r; n       else if (d->l != NULL && d->l->mnvl + x <= s) n         d = d->l; n       else n         return -1; n     else if (d->l != NULL && d->l->mnvl + x <= s) n       d = d->l; n     else if (d->r != NULL && d->r->mnvl + x <= s) n       d = d->r; n     else n       return -1; n   } n   return d->vl; n } n int main() { n   for (int i = 1; i < MAXN; i++) n     for (int j = i; j < MAXN; j += i) diverse[j].push_back(i); n   for (int i = 1; i < dv.size(); i++) dv[i] = new node(); n   int n, q, a, x, k, s; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> q; n     if (q == 1) { n       cin >> a; n       if (!inarr[a]) { n         inarr[a] = true; n         deque<int> d = dbl(a); n         for (int i = 0; i < diverse[a].size(); i++) n           ins(dv[diverse[a][i]], d, a); n       } n     } else { n       cin >> x >> k >> s; n       if (x % k != 0 || s - x <= 0) n         cout << -1 << endl; n       else n         cout << fnd(dv[k], dbl(x), s, x) << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long fast_pow(long long a, long long p) { n   long long res = 1; n   while (p) { n     if (p % 2 == 0) { n       a = a * 1LL * a % 1000000007; n       p /= 2; n     } else { n       res = res * 1LL * a % 1000000007; n       p--; n     } n   } n   return res; n } n long long fact(long long n) { n   long long res = 1; n   for (long long i = 1; i <= n; i++) { n     res = res * 1LL * i % 1000000007; n   } n   return res; n } n long long C(long long n, long long k) { n   return fact(n) * 1LL * fast_pow(fact(k), 1000000007 - 2) % 1000000007 * 1LL * n          fast_pow(fact(n - k), 1000000007 - 2) % 1000000007; n } n vector<long long> sieveOfEratosthenes(long long n) { n   vector<long long> primes; n   vector<bool> prime(n + 1, true); n   for (long long p = 2; p * p <= n; p++) { n     if (prime[p] == true) { n       for (long long i = p * p; i <= n; i += p) prime[i] = false; n     } n   } n   for (long long p = 2; p <= n; p++) n     if (prime[p]) primes.push_back(p); n   return primes; n } n bool isPrime(long long n) { n   if (n <= 1) return false; n   if (n <= 3) return true; n   if (n % 2 == 0 || n % 3 == 0) return false; n   for (long long i = 5; i * i <= n; i = i + 6) n     if (n % i == 0 || n % (i + 2) == 0) return false; n   return true; n } n bool isPerfectSquare(long double x) { n   if (x >= 0) { n     long long sr = sqrt(x); n     return (sr * sr == x); n   } n   return false; n } n long long sum(long long n) { n   long long res = 0; n   while (n > 0) { n     res += n % 10; n     n = n / 10; n   } n   return res; n } n vector<long long> adj[10001]; n vector<long long> vis(10001); n vector<long long> col(10001); n void dfs(long long v) { n   vis[v] = 1; n   for (auto ch : adj[v]) { n     if (vis[ch] == 0) { n       dfs(ch); n     } n   } n } n bool bptdfs(long long v, long long c) { n   vis[v] = 1; n   col[v] = c; n   for (auto ch : adj[v]) { n     if (vis[ch] == 0) { n       if (bptdfs(ch, c ^ 1) == false) { n         return false; n       } n     } else { n       if (col[v] == col[ch]) { n         return false; n       } n     } n   } n   return true; n } n int32_t main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); n   long long t = 1; n   while (t--) { n     long long n, M; n     cin >> n >> M; n     vector<long long> t(n); n     for (long long i = (0); i <= (n - 1); i++) { n       cin >> t[i]; n     } n     vector<long long> ans(n, 0); n     for (long long i = (1); i <= (n - 1); i++) { n       long long c = 0, sum = 0; n       priority_queue<long long> q; n       for (long long j = (0); j <= (i); j++) { n         sum += t[j]; n         if (j != i) { n           q.push(t[j]); n         } n       } n       if (sum > M) { n         while (sum > M) { n           long long x = q.top(); n           q.pop(); n           sum -= x; n           c++; n         } n       } n       ans[i] = c; n     } n     for (auto x : ans) { n       cout << x <<    ; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n class UFDS { n  public: n   vector<int> p, rank; n   int count = 0; n   UFDS(int n) { n     p.resize(n); n     rank.resize(n); n     for (int i = 0; i < n; i++) p[i] = i; n     count = n; n   } n   int getParent(int i) { return (p[i] == i) ? i : (p[i] = getParent(p[i])); } n   void join(int i, int j) { n     int a = getParent(i), b = getParent(j); n     if (a == b) return; n     count -= 1; n     if (rank[a] > rank[b]) { n       p[b] = a; n     } else { n       p[a] = b; n       if (rank[a] == rank[b]) rank[b] += 1; n     } n   } n }; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n, m; n   cin >> n >> m; n   set<int> ls, rss; n   vector<int> rs; n   vector<vector<int> > edges(m, vector<int>(4)); n   for (int i = 0; i < m; i++) { n     cin >> edges[i][2] >> edges[i][3] >> edges[i][0] >> edges[i][1]; n     ls.insert(edges[i][0]); n     if (!rss.count(edges[i][1])) { n       rss.insert(edges[i][1]); n       rs.push_back(edges[i][1]); n     } n     edges[i][2] -= 1; n     edges[i][3] -= 1; n   } n   sort(rs.begin(), rs.end()); n   sort(edges.begin(), edges.end()); n   int out = 0, prev = 0; n   for (auto l : ls) { n     int lo = prev, hi = rss.size(), ans = -1; n     while (lo < hi) { n       int idx = (lo + hi) / 2; n       int mid = rs[idx]; n       UFDS ufds(n); n       for (auto e : edges) { n         if (e[0] > l) break; n         if (e[1] >= mid) ufds.join(e[2], e[3]); n       } n       if (ufds.getParent(0) == ufds.getParent(n - 1)) { n         lo = idx + 1; n         ans = mid; n         prev = idx; n       } else { n         hi = idx; n       } n     } n     if (ans != -1) out = max(out, ans - l + 1); n   } n   if (out) n     cout << out; n   else n     cout <<  Nice work, Dima! ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n const long double PI = 3.141592653589793238462643383279502884197; n priority_queue<int, vector<int>, greater<int> > pq; n vector<int> v; n int al[256]; n char s[200001], t[200001]; n int visit[200001]; n int n, m; n int main() { n   scanf( %s %s , s, t); n   n = strlen(s); n   m = strlen(t); n   memset(al, -1, sizeof(al)); n   int l = 0; n   for (int i = 0; i < n; i++) { n     if (l < m && s[i] == t[l]) { n       al[s[i]] = l; n       l++; n     } n     if (al[s[i]] == -1) return !printf( No ); n     visit[i] = al[s[i]]; n   } n   if (l != m) return !printf( No ); n   l = m - 1; n   memset(al, -1, sizeof(al)); n   for (int i = n - 1; i >= 0; i--) { n     if (l >= 0 && s[i] == t[l]) { n       al[s[i]] = l; n       l--; n     } n     if (al[s[i]] == -1) return !printf( No ); n     if (visit[i] < al[s[i]]) return !printf( No ); n   } n   if (l != -1) return !printf( No ); n   printf( Yes ); n } n


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


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100005; n int pos[maxn]; n int n, x, y; n int main() { n   int i, j; n   while (scanf( %d , &n) != EOF) { n     memset(pos, -1, sizeof(pos)); n     for (i = 1; i <= n; i++) { n       scanf( %d%d , &x, &y); n       int ans = 0; n       for (j = 1; j * j <= x; j++) { n         if (x % j == 0) { n           if (y == 0) { n             ans++; n             pos[j] = i; n             if (x / j != j) ans++; n             pos[x / j] = i; n             continue; n           } n           if (pos[j] < i - y) ans++; n           pos[j] = i; n           if (x / j != j && pos[x / j] < i - y) ans++; n           pos[x / j] = i; n         } n       } n       printf( %d n , ans); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n const int MAX = 5000001; n unsigned int arr[MAX], P[MAX]; n void sieve() { n   unsigned int i, j, t, k; n   arr[0] = arr[1] = 0; n   for (i = 2; i < MAX; i++) arr[i] = i; n   for (i = 4; i < MAX; i += 2) arr[i] = 2; n   for (i = 3; i * i <= MAX; i += 2) n     if (arr[i] == i) n       for (j = i * i; j < MAX; j += 2 * i) n         if (arr[j] == j) arr[j] = i; n   for (i = 2; i < 5000001; i++) P[i] = P[i / arr[i]] + 1; n   for (i = 2; i < 5000001; i++) P[i] += P[i - 1]; n } n int main(void) { n   sieve(); n   unsigned int tc, i, a, b; n   scanf( %u , &tc); n   for (i = 1; i <= tc; i++) { n     scanf( %u %u , &a, &b); n     printf( %u n , P[a] - P[b]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int64_t solve(int m, int n) { n   if (m > n) swap(m, n); n   if (m == 1) { n     if (n <= 3) return 0; n     if (n % 6 == 2 || n % 6 == 4) return n - 2; n     if (n % 6 == 1 || n % 6 == 5) return n - 1; n     if (n % 6 == 3) return n - 3; n     return n; n   } n   if (m == 2) { n     if (n <= 2) return 0; n     if (n == 3) return 4; n     if (n == 4) return 8; n     if (n == 7) return 12; n     return n * 2; n   } n   int64_t res = 1LL * m * n; n   if (res % 2 == 1) res -= 1; n   return res; n } n int main() { n   int n, m; n   cin >> n >> m; n   cout << solve(n, m) << endl; n   return 0; n } n