#include <bits/stdc++.h> n using namespace std; n #pragma GCC optimize( Ofast ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma ) n #pragma GCC optimize( unroll-loops ) n const long long int mod = 1e9 + 7; n const long long int mod1 = 998244353; n const long long int inf = 1e18; n const long long int MX = 1e6 + 1; n const double PI = 3.141592653589793238; n template <typename T> n ostream& operator<<(ostream& out, const vector<T>& v) { n   out <<  [ ; n   for (auto i = v.begin(); i != v.end(); i++) n     out << (i != v.begin() ?  ,  :   ) << (*i); n   return (out <<  ] ); n } n template <typename T> n ostream& operator<<(ostream& out, const set<T>& s) { n   out <<  [ ; n   for (auto i = s.begin(); i != s.end(); i++) n     out << (i != s.begin() ?  ,  :   ) << (*i); n   return (out <<  ] ); n } n template <typename T> n ostream& operator<<(ostream& out, const unordered_set<T>& s) { n   out <<   n  <<  [ ; n   for (auto i = s.begin(); i != s.end(); i++) n     out << (i != s.begin() ?  ,  :   ) << (*i); n   return (out <<  ] ); n } n template <typename T1, typename T2> n ostream& operator<<(ostream& out, const pair<T1, T2>& p) { n   return (out <<  (  << p.first <<  ,  << p.second <<  ) ); n } n template <typename T1, typename T2> n ostream& operator<<(ostream& out, const map<T1, T2>& m) { n   out <<  {  <<   n ; n   for (auto x : m) out <<      << x.first <<   ->   << x.second <<   n ; n   return (out <<  } ); n } n template <typename T1, typename T2> n ostream& operator<<(ostream& out, const unordered_map<T1, T2>& m) { n   out <<  {  <<   n ; n   for (auto x : m) out <<      << x.first <<   ->   << x.second <<   n ; n   return (out <<  } ); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int t; n   cin >> t; n   cin.ignore(); n   while (t--) { n     long long int n, m; n     cin >> n >> m; n     map<long long int, long long int> mp; n     for (long long int i = 0; i < m; i++) { n       long long int x, y, z; n       cin >> x >> y >> z; n       mp[y]++; n     } n     long long int p1 = 0; n     for (long long int i = 0; i < n; i++) { n       if (mp.find(i + 1) == mp.end()) { n         p1 = i + 1; n         break; n       } n     } n     for (long long int i = 0; i < n; i++) { n       if (i + 1 == p1) { n         continue; n       } n       cout << p1 <<     << i + 1 <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n void Solve() { n   int n; n   string a, b; n   cin >> n >> a >> b; n   a =  -  + a +  - ; n   b =  -  + b +  - ; n   int val = 0; n   for (int i = 1; i <= n; i++) { n     if (a[i] != b[i]) n       val += 2; n     else if (a[i] ==  0 ) { n       val++; n       if (a[i - 1] ==  1  && b[i - 1] ==  1 ) n         val++; n       else if (a[i + 1] ==  1  && b[i + 1] ==  1 ) { n         val++; n         a[i + 1] = b[i + 1] =  - ; n       } n     } n   } n   cout << val << endl; n } n int main() { n   int t; n   cin >> t; n   while (t--) Solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   long long x = 0; n   bool f = 1; n   char s = getchar(); n   while ((s <  0  || s >  9 ) && s > 0) { n     if (s ==  - ) f ^= 1; n     s = getchar(); n   } n   while (s >=  0  && s <=  9 ) x = (x << 1) + (x << 3) + s -  0 , s = getchar(); n   return f ? x : -x; n } n int n, m, ans[500005]; n int IN, dfn[500005], low[500005], bl[500005], tot; n stack<int> st; n int d1[500005], sd[500005], d2[500005], ccg[500005]; n vector<int> G[500005], cl[500005]; n inline void dfs0(int x, int fa) { n   dfn[x] = low[x] = ++IN, st.push(x); n   for (unsigned i = 0; i < G[x].size(); i++) { n     int v = G[x][i]; n     if (v == fa) continue; n     if (!dfn[v]) n       dfs0(v, x), low[x] = min(low[x], low[v]); n     else n       low[x] = min(low[x], dfn[v]); n   } n   if (low[x] == dfn[x]) { n     tot++; n     while (!st.empty() && dfn[st.top()] >= dfn[x]) n       bl[st.top()] = tot, cl[tot].push_back(st.top()), st.pop(); n   } n } n queue<int> q; n int db[500005]; n inline void bfs1(int x) { n   for (int i = 1; i <= n; i++) db[i] = -1; n   db[x] = 0, q.push(x); n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     for (unsigned i = 0; i < G[u].size(); i++) { n       int v = G[u][i]; n       if (db[v] < 0) db[v] = db[u] + 1, q.push(v); n     } n   } n } n inline void dfs1(int x) { n   d1[x] = 1; n   for (unsigned i = 0; i < G[x].size(); i++) { n     int v = G[x][i]; n     if (db[v] == db[x] + 1) { n       if (!d1[v]) dfs1(v); n       d1[x] = max(d1[x], d1[v] + 1); n     } n   } n } n struct node { n   int x, y; n   node() {} n   node(int X, int Y) { x = X, y = Y; } n }; n int dq[500005 << 1], hd, tl; n bool vis[500005]; n inline void dfs2(int x) { n   vis[x] = 1; n   int len = cl[x].size(), cj = len >> 1; n   for (int id = 0; id < len; id++) { n     int u = cl[x][id]; n     sd[u] = ans[u] = 1; n     for (unsigned i = 0; i < G[u].size(); i++) { n       int v = G[u][i]; n       if (bl[u] != bl[v]) sd[u] = max(sd[u], d1[v] + 1); n     } n   } n   hd = tl = 0; n   for (int i = cj, lim = len << 1; i < lim; i++) { n     int u = cl[x][i % len], p; n     while (hd < tl && i - dq[hd] > cj) hd++; n     if (hd < tl) p = dq[hd], ans[u] = max(ans[u], i - p + sd[cl[x][p % len]]); n     while (hd < tl && ((p = dq[tl - 1]) || 1) && n            i - p + sd[cl[x][p % len]] < sd[u]) n       tl--; n     dq[tl++] = i; n   } n   hd = tl = 0; n   for (int i = cj, g = (len << 1) - 1; i <= g; i++) { n     int u = cl[x][(g - i) % len], p; n     while (hd < tl && i - dq[hd] > cj) hd++; n     if (hd < tl) n       p = dq[hd], ans[u] = max(ans[u], i - p + sd[cl[x][(g - p) % len]]); n     while (hd < tl && ((p = dq[tl - 1]) || 1) && n            i - p + sd[cl[x][(g - p) % len]] < sd[u]) n       tl--; n     dq[tl++] = i; n   } n   for (int id = 0; id < len; id++) { n     int u = cl[x][id]; n     hd = tl = 0; n     for (unsigned i = 0; i < G[u].size(); i++) n       if (bl[G[u][i]] != x) { n         int v = G[u][i]; n         while (hd < tl && d1[dq[tl - 1]] < d1[v]) tl--; n         dq[tl++] = v; n       } n     for (unsigned i = 0; i < G[u].size(); i++) n       if (bl[G[u][i]] != x) { n         int v = G[u][i], cg = ans[u]; n         if (hd < tl && dq[hd] == v) hd++; n         if (hd < tl) cg = max(cg, d1[dq[hd]] + 1); n         while (hd < tl && d1[dq[tl - 1]] < d1[v]) tl--; n         dq[tl++] = v; n         if (!vis[bl[v]]) ccg[v] = cg; n       } n     for (unsigned i = 0; i < G[u].size(); i++) n       if (bl[G[u][i]] != x) { n         int v = G[u][i]; n         if (!vis[bl[v]]) swap(d1[u], ccg[v]), dfs2(bl[v]), swap(d1[u], ccg[v]); n       } n   } n } n signed main() { n   n = read(), m = read(); n   for (int i = 1; i <= m; i++) { n     int u = read(), v = read(); n     G[u].push_back(v), G[v].push_back(u); n   } n   dfs0(1, 0); n   bfs1(1), dfs1(1); n   dfs2(bl[1]); n   for (int i = 1; i <= n; i++) printf( %d  , max(ans[i], sd[i]) - 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int Read() { n   char c; n   while (c = getchar(), (c !=  - ) && (c <  0  || c >  9 )) n     ; n   bool neg = (c ==  - ); n   int ret = (neg ? 0 : c - 48); n   while (c = getchar(), c >=  0  && c <=  9 ) ret = ret * 10 + c - 48; n   return neg ? -ret : ret; n } n const int MAXN = 300005; n const long double eps = 1e-10; n struct node { n   long double l, r, a, b, c, dx, da, db, dc; n   int fa, son[2]; n   long double F(long double x) { return (a * x + b) * x + c; } n } t[MAXN << 1]; n int N, Q, A, B, root, cnt; n long double ans[MAXN], apex[MAXN]; n inline int CreateNew(long double l, long double r, long double a = 0, n                      long double b = 0, long double c = 0, int c0 = 0, n                      int c1 = 0) { n   return t[++cnt].l = l, t[cnt].r = r, t[cnt].a = a, t[cnt].b = b, t[cnt].c = c, n          t[cnt].son[0] = c0, t[cnt].son[1] = c1, cnt; n } n inline void MarkX(int x, long double dx) { n   t[x].c += (t[x].a * dx - t[x].b) * dx; n   t[x].dc += (t[x].da * dx - t[x].db) * dx; n   t[x].b += -2 * t[x].a * dx, t[x].db += -2 * t[x].da * dx; n   t[x].l += dx, t[x].r += dx, t[x].dx += dx; n } n inline void MarkY(int x, long double da, long double db, long double dc) { n   t[x].a += da, t[x].b += db, t[x].c += dc; n   t[x].da += da, t[x].db += db, t[x].dc += dc; n } n inline void Pushdown(int x) { n   if (t[x].son[0]) n     MarkX(t[x].son[0], t[x].dx), MarkY(t[x].son[0], t[x].da, t[x].db, t[x].dc); n   if (t[x].son[1]) n     MarkX(t[x].son[1], t[x].dx), MarkY(t[x].son[1], t[x].da, t[x].db, t[x].dc); n   t[x].dx = t[x].da = t[x].db = t[x].dc = 0; n } n inline void Rotate(int x, int tp) { n   int y = t[x].fa; n   Pushdown(y), Pushdown(x); n   t[y].son[!tp] = t[x].son[tp]; n   t[x].fa = t[y].fa; n   if (t[x].son[tp]) t[t[x].son[tp]].fa = y; n   if (t[y].fa) n     t[t[y].fa].son[t[t[y].fa].son[1] == y] = x; n   else n     root = x; n   t[y].fa = x, t[x].son[tp] = y; n } n inline void Splay(int x) { n   for (Pushdown(x); t[x].fa;) n     if (t[x].fa == root) n       Rotate(x, t[t[x].fa].son[0] == x); n     else { n       int y = t[x].fa, z = t[y].fa; n       if (y == t[z].son[0]) n         if (x == t[y].son[0]) n           Rotate(y, 1), Rotate(x, 1); n         else n           Rotate(x, 0), Rotate(x, 1); n       else if (x == t[y].son[1]) n         Rotate(y, 0), Rotate(x, 0); n       else n         Rotate(x, 1), Rotate(x, 0); n     } n } n inline long double FindOpt(int x) { n   for (;;) { n     Pushdown(x); n     long double opt = min(-t[x].b * 0.5 / t[x].a, (long double)Q); n     if (opt < t[x].l - eps) n       if (t[x].son[0]) n         x = t[x].son[0]; n       else n         return Splay(x), t[x].l; n     else if (opt > t[x].r + eps) n       if (t[x].son[1]) n         x = t[x].son[1]; n       else n         return Splay(x), t[x].r; n     else n       return Splay(x), opt; n   } n } n int main() { n   scanf( %d%d%d%d , &N, &Q, &A, &B); n   memset(t, 0, sizeof(t)); n   root = CreateNew(1, Q); n   for (int i = 1; i <= N; i++) { n     if (i > 1) { n       if (A < B) { n         long double opt = FindOpt(root); n         apex[i] = opt; n         int l(t[root].son[0]), r(t[root].son[1]); n         if (opt - t[root].l > eps) { n           l = CreateNew(t[root].l, opt, t[root].a, t[root].b, t[root].c, n                         t[root].son[0], 0); n           if (t[root].son[0]) t[t[root].son[0]].fa = l; n           t[l].fa = root; n         } n         if (t[root].r - opt > eps) { n           r = CreateNew(opt, t[root].r, t[root].a, t[root].b, t[root].c, 0, n                         t[root].son[1]); n           if (t[root].son[1]) t[t[root].son[1]].fa = r; n           t[r].fa = root; n         } n         if (l) MarkX(l, A); n         if (r) MarkX(r, B); n         t[root].c = t[root].F(opt); n         t[root].son[0] = l, t[root].son[1] = r, t[root].l = opt + A, n         t[root].r = opt + B; n         t[root].a = t[root].b = t[root].da = t[root].db = t[root].dc = n             t[root].dx = 0; n       } else n         MarkX(root, A); n     } n     double x = Read(); n     MarkY(root, 1, -2 * x, x * x); n   } n   long double opt = FindOpt(root); n   double sum = t[root].F(opt); n   for (int i = N; i >= 1; i--) { n     ans[i] = opt; n     if (opt > apex[i] + B) n       opt -= B; n     else if (opt < apex[i] + A) n       opt -= A; n     else n       opt = apex[i]; n   } n   for (int i = 1; i <= N; i++) n     printf( %.10f%c , (double)ans[i], i < N ?     :   n ); n   printf( %.10f n , sum); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n struct rge { n   T b, e; n }; n template <class T> n rge<T> range(T i, T j) { n   return rge<T>{i, j}; n }; n template <class A, class B> n ostream &operator<<(ostream &os, pair<A, B> p) { n   return os <<  (  << p.first <<  ,   << p.second <<  ) ; n } n template <class T> n ostream &operator<<(ostream &os, rge<T> d) { n   os <<  [ ; n   for (auto it = d.b; it != d.e; it++) os << (it == d.b ?    :  ,  ) << *it; n   return os <<  ] ; n } n const int N = 1e5 + 5; n const long long inf = 1e18; n long long stones[N], frogs[N]; n int n, jump; n bool can(long long x) { n   for (int i = (1); i <= ((n)); i += (+1)) { n     frogs[i] = 0; n   } n   frogs[0] = x; n   int l = 0, r = 1; n   while (l < n) { n     while (frogs[l] > 0) { n       while (r <= n && stones[r] - frogs[r] <= 0) { n         r++; n       } n       if (l + jump < r) { n         return false; n       } n       long long add = min(frogs[l], stones[r] - frogs[r]); n       frogs[r] += add; n       frogs[l] -= add; n     } n     l++; n     r = max(l + 1, r); n   } n   return true; n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(15); n   cin >> n >> jump; n   for (int i = (1); i <= ((n - 1)); i += (+1)) { n     cin >> stones[i]; n   } n   stones[n] = inf; n   long long lo = 0, hi = inf; n   while (lo + 1 < hi) { n     long long mid = (lo + hi) / 2; n     if (can(mid)) { n       lo = mid; n     } else { n       hi = mid; n     } n   } n   while (can(lo + 1)) { n     lo++; n   } n   cout << lo <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n std::vector<int> v[100005]; n int dist[100005]; n void dfs(int s, int par) { n   if (par != -1) dist[s] = dist[par] + 1; n   for (int i = 0; i < v[s].size(); i++) { n     if (par != v[s][i]) dfs(v[s][i], s); n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long t = 1, xx, x = 0, y = 0, cc, m, k, n; n   cin >> t; n   while (t--) { n     int a, b, da, db; n     cin >> n >> a >> b >> da >> db; n     for (int i = 1; i < n; i++) { n       cin >> x >> y; n       v[x].push_back(y); n       v[y].push_back(x); n       dist[i] = 0; n     } n     dist[n] = 0; n     dfs(a, -1); n     int ab = dist[b]; n     int farest, mx = -1; n     for (int i = 1; i < n + 1; i++) { n       if (mx < dist[i]) { n         mx = dist[i]; n         farest = i; n       } n     } n     for (int i = 1; i < n + 1; i++) dist[i] = 0; n     dfs(farest, -1); n     int diameter = -1; n     for (int i = 1; i < n + 1; i++) diameter = max(diameter, dist[i]); n     if (ab <= da || 2 * da >= diameter || 2 * da >= db) n       cout <<  Alice  << endl; n     else n       cout <<  Bob  << endl; n     for (int i = 1; i < n + 1; i++) v[i].clear(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename F, typename S> n ostream &operator<<(ostream &os, const pair<F, S> &p) { n   return os <<  (  << p.first <<  ,   << p.second <<  ) ; n } n template <typename T> n ostream &operator<<(ostream &os, const vector<T> &v) { n   os <<  { ; n   for (auto it = v.begin(); it != v.end(); ++it) { n     if (it != v.begin()) os <<  ,  ; n     os << *it; n   } n   return os <<  } ; n } n template <typename T> n ostream &operator<<(ostream &os, const set<T> &v) { n   os <<  [ ; n   for (auto it = v.begin(); it != v.end(); ++it) { n     if (it != v.begin()) os <<  ,  ; n     os << *it; n   } n   return os <<  ] ; n } n template <typename T> n ostream &operator<<(ostream &os, const multiset<T> &v) { n   os <<  [ ; n   for (auto it = v.begin(); it != v.end(); ++it) { n     if (it != v.begin()) os <<  ,  ; n     os << *it; n   } n   return os <<  ] ; n } n template <typename F, typename S> n ostream &operator<<(ostream &os, const map<F, S> &v) { n   os <<  [ ; n   for (auto it = v.begin(); it != v.end(); ++it) { n     if (it != v.begin()) os <<  ,  ; n     os << it->first <<   =   << it->second; n   } n   return os <<  ] ; n } n void faltu() { cerr << endl; } n template <typename T> n void faltu(T a[], int n) { n   for (int i = 0; i < n; ++i) cerr << a[i] <<    ; n   cerr << endl; n } n template <typename T, typename... hello> n void faltu(T arg, const hello &...rest) { n   cerr << arg <<    ; n   faltu(rest...); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   int t; n   cin >> t; n   while (t--) { n     int n, s; n     cin >> n; n     s = sqrt(n); n     if (n == 1) { n       cout << 0 << endl; n       continue; n     } else { n       if (s * s == n) { n         cout << 2 * s - 2 << endl; n       } else if ((s + 1) * s >= n) { n         cout << 2 * s - 1 << endl; n       } else if ((s + 1) * (s + 1) >= n) { n         cout << 2 * s << endl; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n int n, a[maxn], b[maxn], t[maxn]; n bool check(int num, int pos) { n   t[pos] = num; n   if (pos == n) return true; n   for (int i = 0; i <= 3; i++) { n     if ((num | i) == a[pos] && (num & i) == b[pos]) return check(i, pos + 1); n   } n   return false; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i < n; i++) { n     scanf( %d , &a[i]); n   } n   for (int i = 1; i < n; i++) { n     scanf( %d , &b[i]); n   } n   for (int i = 0; i <= 3; i++) { n     if (check(i, 1)) { n       printf( YES n ); n       for (int j = 1; j <= n; j++) { n         printf( %d  , t[j]); n       } n       return 0; n     } n   } n   printf( NO ); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200000 + 10; n const int M = 5 * N; n const int OO = 1000000000; n int ans = 0; n int anum = 0; n int i; n int n; n int result; n int sum[N]; n int tree[M]; n string s; n int lowbit(int x) { return x & (-x); } n int min(int a, int b) { return a < b ? a : b; } n int ask(int x) { n   int i = x; n   int result = OO; n   while (i > 0) { n     result = min(result, tree[i]); n     i -= lowbit(i); n   } n   return result; n } n void update(int x, int y) { n   int i = x; n   while (i < M) { n     tree[i] = min(tree[i], y); n     i += lowbit(i); n   } n } n int main() { n   getline(cin, s); n   n = s.size(); n   for (i = 0; i < n; i++) n     if (s[i] >=  a  && s[i] <=  z ) s[i] = s[i] -  a  +  A ; n   for (i = 0; i < n; i++) { n     sum[i + 1] = sum[i]; n     if (s[i] ==  A  || s[i] ==  E  || s[i] ==  I  || s[i] ==  O  || s[i] ==  U ) n       sum[i + 1]--; n     else n       sum[i + 1] += 2; n   } n   for (i = 0; i <= n; i++) sum[i] += 2 * n; n   for (i = 0; i < M; i++) tree[i] = OO; n   update(sum[0], 0); n   for (i = 1; i <= n; i++) { n     result = ask(sum[i]); n     if (i - result > ans) { n       ans = i - result; n       anum = 0; n     } n     if (i - result == ans) anum++; n     update(sum[i], i); n   } n   if (ans > 0) n     cout << ans <<     << anum <<   n ; n   else n     cout <<  No solution n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n const int MAX_N = 1e5 + 50; n int w[MAX_N]; n void solve() { n   int n, m; n   cin >> n >> m; n   long long ret = ((long long)w[n] + (long long)w[m] - 1LL) * 2LL; n   cout << ret % MOD <<   n ; n } n void precal() { n   w[0] = 0; n   w[1] = 1; n   w[2] = 2; n   for (int i = (3); i < (MAX_N); ++i) { n     w[i] = w[i - 1] + w[i - 2]; n     w[i] %= MOD; n   } n } n signed main(void) { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   precal(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e6 + 2e5; n int p[MAXN + 10], rub[MAXN + 10]; n bool mark[MAXN + 10]; n bool palin(int x) { n   stringstream sst; n   sst << x; n   string s; n   sst >> s; n   for (int i = 0; i < s.length(); i++) n     if (s[i] != s[s.length() - i - 1]) return false; n   return true; n } n int main() { n   ios::sync_with_stdio(false); n   rub[1] = 1; n   cerr << palin(121) << endl; n   long double a, b; n   cin >> a >> b; n   for (int i = 2; i <= MAXN; i++) { n     if (palin(i)) { n       rub[i] = rub[i - 1] + 1; n     } else n       rub[i] = rub[i - 1]; n     if (!mark[i]) { n       p[i] = p[i - 1] + 1; n       for (int j = i + i; j <= MAXN; j += i) mark[j] = true; n     } else n       p[i] = p[i - 1]; n   } n   long double x = a / b; n   int Max = 0; n   for (int i = 1; i <= MAXN; i++) n     if ((long double)p[i] / (long double)rub[i] <= x) Max = i; n   cout << Max << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int SZ = 200005; n vector<int> graph[SZ]; n int par[SZ]; n int dst[SZ]; n int tot; n void dfs(int x, int crt) { n   par[x] = crt; n   tot++; n   for (int nxt : graph[x]) { n     if (par[nxt]) continue; n     dfs(nxt, crt); n   } n } n int main(void) { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     for (int i = 1; i <= n; i++) { n       graph[i].clear(); n       par[i] = 0; n       dst[i] = 0; n     } n     for (int i = 1; i <= n; i++) { n       int x; n       cin >> x; n       graph[i].push_back(x); n     } n     int pp = 0; n     for (int i = 1; i <= n; i++) { n       if (par[i]) continue; n       tot = 0; n       dfs(i, ++pp); n       dst[pp] = tot; n     } n     for (int i = 1; i <= n; i++) cout << dst[par[i]] <<    ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e9 + 7; n const int maxn = 1e6 + 100; n const double EPS = 1e-12; n struct point { n   double x, y; n }; n string a[11] = { zero ,  one ,    two ,    three ,  four ,  five , n                  six ,   seven ,  eight ,  nine ,   ten }; n string b[11] = {  ,      ,     twen ,   thir ,  for , n                  fif ,  six ,  seven ,  eigh ,  nine }; n string c[11] = {  ,      ,      ,       thir ,  four , n                  fif ,  six ,  seven ,  eigh ,  nine }; n int n; n int main() { n   cin >> n; n   if (n <= 10) { n     cout << a[n] << endl; n     return 0; n   } n   if (n < 20) { n     if (n == 11) n       cout <<  eleven  << endl; n     else if (n == 12) n       cout <<  twelve  << endl; n     else n       cout << c[n % 10] <<  teen  << endl; n     return 0; n   } n   if (n % 10 == 0) { n     cout << b[n / 10] <<  ty  << endl; n     return 0; n   } n   cout << b[n / 10] <<  ty-  << a[n % 10] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int64_t read() { n   bool b = 0; n   int64_t n = 0; n   char c = getchar(); n   for (; !(( 0 ) <= (c) && (c) <= ( 9 )); c = getchar()) b = (c ==  - ); n   for (; (( 0 ) <= (c) && (c) <= ( 9 )); c = getchar()) n = 10 * n + (c -  0 ); n   if (b) n = -n; n   return n; n } n const int64_t N = 1e5 + 10; n int64_t _log[2 * N], ss[2 * N][20], bl[N][20]; n vector<int64_t> adj[N]; n int64_t h[N], first[N]; n vector<int64_t> et; n int64_t V[N]; n int64_t n, q; n int64_t tin[N], tout[N], t = -1; n int64_t stlen, sth; n int64_t lp[N]; n int64_t st[2 * N]; n void calc(int64_t i, int64_t k) { n   st[i] = st[i << 1] + st[i << 1 | 1] + lp[i] * k; n } n void app(int64_t i, int64_t vv, int64_t k) { n   st[i] += vv * k; n   if (i < stlen) lp[i] += vv; n } n void build(int64_t l, int64_t r) { n   int64_t k = 2; n   for (l += stlen, r += stlen - 1; l > 1; k <<= 1) { n     l >>= 1, r >>= 1; n     for (int64_t i = r; i >= l; --i) calc(i, k); n   } n } n void push(int64_t l, int64_t r) { n   int64_t s = sth, k = 1 << (sth - 1); n   for (l += stlen, r += stlen - 1; s > 0; --s, k >>= 1) n     for (int64_t i = l >> s; i <= r >> s; ++i) n       if (lp[i] != 0) { n         app(i << 1, lp[i], k); n         app(i << 1 | 1, lp[i], k); n         lp[i] = 0; n       } n } n void add(int64_t l, int64_t r, int64_t vv) { n   push(l, l + 1), push(r - 1, r); n   int64_t l0 = l, r0 = r, k = 1; n   for (l += stlen, r += stlen; l < r; l >>= 1, r >>= 1, k <<= 1) { n     if (l & 1) app(l++, vv, k); n     if (r & 1) app(--r, vv, k); n   } n   build(l0, l0 + 1), build(r0 - 1, r0); n } n int64_t query(int64_t l, int64_t r) { n   int64_t l0 = l, r0 = r; n   push(l, l + 1), push(r - 1, r); n   int64_t res = 0; n   for (l += stlen, r += stlen; l < r; l >>= 1, r >>= 1) { n     if (l & 1) res += st[l++]; n     if (r & 1) res += st[--r]; n   } n   l = l0, r = r0; n   return res; n } n void _clog() { n   for (int64_t i = 2; i < 2 * N; ++i) _log[i] = _log[i >> 1] + 1; n } n void clca() { n   int64_t n = et.size(); n   for (int64_t i = 0; (i) < (n); ++(i)) ss[i][0] = et[i]; n   for (int64_t k = 1; (1 << k) <= n; ++k) n     for (int64_t i = 0; i + (1 << k) <= n; ++i) { n       int64_t j = i + (1 << (k - 1)); n       if (h[ss[i][k - 1]] < h[ss[j][k - 1]]) n         ss[i][k] = ss[i][k - 1]; n       else n         ss[i][k] = ss[j][k - 1]; n     } n } n int64_t lca(int64_t l, int64_t r) { n   l = first[l], r = first[r]; n   if (r < l) swap(l, r); n   int64_t k = _log[r - l + 1]; n   int64_t a = ss[l][k], b = ss[r - (1 << k) + 1][k]; n   if (h[a] < h[b]) n     return a; n   else n     return b; n } n void pdfs(int64_t v, int64_t p) { n   first[v] = int64_t((et).size()); n   tin[v] = ++t; n   et.push_back(v); n   bl[v][0] = p; n   for (int64_t i = 0; (i) < (19); ++(i)) bl[v][i + 1] = bl[bl[v][i]][i]; n   for (int64_t c : adj[v]) { n     if (c == p) continue; n     h[c] = h[v] + 1; n     pdfs(c, v); n     et.push_back(v); n   } n   tout[v] = t; n } n int64_t rlca(int64_t root, int64_t l, int64_t r) { n   return lca(l, root) ^ lca(r, root) ^ lca(l, r); n } n int64_t up(int64_t v, int64_t first) { n   for (int64_t i = 19; first && i >= 0; --i) n     if ((1 << i) <= first) v = bl[v][i], first -= (1 << i); n   return v; n } n int64_t qsub(int64_t v) { return query(tin[v], tout[v] + 1); } n void msub(int64_t v, int64_t vv) { add(tin[v], tout[v] + 1, vv); } n int main() { n   ; n   n = read(), q = read(), stlen = n; n   sth = 8 * 4 - __builtin_clz(stlen); n   ; n   for (int64_t i = 0; (i) < (n); ++(i)) V[i] = read(); n   int64_t a, b; n   for (int64_t i = 0; (i) < (n - 1); ++(i)) { n     a = read() - 1, b = read() - 1; n     adj[a].push_back(b); n     adj[b].push_back(a); n   } n   _log[1] = 0; n   _clog(); n   pdfs(0, 0); n   clca(); n   ; n   for (int64_t i = 0; (i) < (n); ++(i)) n     ; n   ; n   ; n   ; n   for (int64_t i = 0; (i) < (n); ++(i)) n     ; n   ; n   ; n   for (int64_t i = 0; (i) < (n); ++(i)) st[stlen + tin[i]] = V[i]; n   build(0, n); n   int64_t op, root = 0; n   while (q--) { n     op = read(); n     if (op == 1) { n       root = read() - 1; n     } else if (op == 2) { n       int64_t v = rlca(root, read() - 1, read() - 1); n       int64_t vv = read(); n       if (root == v) { n         msub(0, vv); n       } else if (lca(v, root) == v) { n         ; n         msub(0, vv), msub(up(root, h[root] - h[v] - 1), -vv); n       } else { n         msub(v, vv); n       } n     } else { n       int64_t v = read() - 1; n       ; n       assert(op == 3); n       if (root == v) { n         printf( %lld n , qsub(0)); n       } else if (lca(v, root) == v) { n         ; n         ; n         printf( %lld n , qsub(0) - qsub(up(root, h[root] - h[v] - 1))); n       } else { n         printf( %lld n , qsub(v)); n       } n     }; n     for (int64_t i = 0; (i) < (n); ++(i)) n       ; n     ; 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   char board[n][n]; n   bool even = true; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) cin >> board[i][j]; n   for (int i = 0; i < n; i++) { n     int c = 0; n     for (int j = 0; j < n; j++) { n       if (i - 1 >= 0 and board[i - 1][j] ==  o ) c++; n       if (i + 1 < n and board[i + 1][j] ==  o ) c++; n       if (j - 1 >= 0 and board[i][j - 1] ==  o ) c++; n       if (j + 1 < n and board[i][j + 1] ==  o ) c++; n       if (c % 2 == 1) even = false; n     } n   } n   if (even) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int MAX = 1e7 + 7; n const long long int MOD = 1000000007; n void fast() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n } n int main() { n   fast(); n   long long int TEST_CASES = 1; n   while (TEST_CASES--) { n     int n; n     cin >> n; n     vector<pair<string, int>> v(n); n     map<string, long long int> mp, now; n     for (long long int(i) = 0; (i) < n; (i)++) { n       cin >> v[i].first >> v[i].second; n       mp[v[i].first] += v[i].second; n     } n     string mxs; n     long long int mx = INT_MIN; n     for (auto i : mp) { n       if (mx < i.second) { n         mx = i.second; n         mxs = i.first; n       } n     } n     string str; n     for (int i = 0; i < n; i++) { n       now[v[i].first] += v[i].second; n       if (mp[v[i].first] == mx && now[v[i].first] >= mx) { n         str = v[i].first; n         break; n       } n     } n     cout << str <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef struct { n   int freq; n   char l; n } db; n int comp(const void *a, const void *b) { n   db *x = (db *)a; n   db *y = (db *)b; n   return x->freq - y->freq; n } n int main() { n   db aa[30]; n   db e; n   string str; n   int let[30], sz, i, cnt, k, d, j; n   while (cin >> str) { n     cin >> d; n     memset(let, 0, sizeof(let)); n     sz = str.length(); n     for (i = 0; i < sz; i++) { n       let[str[i] -  a ]++; n     } n     cnt = 0; n     k = 0; n     for (i = 0; i < 26; i++) { n       if (let[i]) { n         cnt++; n         aa[k].l = i +  a ; n         aa[k].freq = let[i]; n         k++; n       } n     } n     qsort(aa, k, sizeof(db), comp); n     sz = str.size(); n     for (i = 0; i < k; i++) { n       if (d == 0) break; n       for (j = 0; j < str.size() && d > 0; j++) { n         if (str[j] == aa[i].l) { n           str.erase(j, 1); n           j--; n           let[aa[i].l -  a ]--; n           d--; n         } n       } n     } n     cnt = 0; n     for (i = 0; i < 26; i++) { n       if (let[i]) cnt++; n     } n     cout << cnt << endl; n     cout << str << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n char c[10005]; n int main() { n   int i, j, k, n, m; n   int x0 = 0, x = 0, y0 = 0, y = 0; n   scanf( %d%s , &n, c + 1); n   for (i = 1; i <= n; i++) { n     if (!x0 && c[i] ==  R ) x0 = i; n     if (c[i] ==  R ) x = i; n     if (!y0 && c[i] ==  L ) y0 = i; n     if (c[i] ==  L ) y = i; n   } n   if (!x0) n     printf( %d %d n , y, y0 - 1); n   else if (!y0) n     printf( %d %d n , x0, x + 1); n   else n     printf( %d %d n , x0, x); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int blk_size; n struct node { n   int l, r, id; n   long long int ans = 0; n }; n bool compare(node a, node b) { n   if (a.l / blk_size != b.l / blk_size) n     return (a.l) / blk_size < (b.l) / blk_size; n   return a.r < b.r; n } n bool compare2(node a, node b) { return a.id < b.id; } n long long int freq[3000001]; n int main() { n   ios_base::sync_with_stdio(false); n   ; n   int n, m, k; n   cin >> n >> m >> k; n   std::vector<int> a(n), pxor(n + 1); n   for (int i = 0; i < n; i++) cin >> a[i]; n   pxor[0] = 0; n   for (int i = 1; i <= n; i++) pxor[i] = pxor[i - 1] ^ a[i - 1]; n   blk_size = sqrt(n + 1); n   std::vector<node> q(m); n   for (int i = 0; i < m; i++) { n     cin >> q[i].l >> q[i].r; n     q[i].id = i; n   } n   sort(q.begin(), q.end(), compare); n   int start = 0, end = 0; n   long long int ans = 0; n   freq[0] = 1; n   for (int i = 0; i < m; i++) { n     int l = q[i].l - 1, r = q[i].r; n     while (start > l) { n       start--; n       ans += freq[pxor[start] ^ k]; n       freq[pxor[start]]++; n     } n     while (start < l) { n       freq[pxor[start]]--; n       ans -= freq[pxor[start] ^ k]; n       start++; n     } n     while (end > r) { n       freq[pxor[end]]--; n       ans -= freq[pxor[end] ^ k]; n       end--; n     } n     while (end < r) { n       end++; n       ans += freq[pxor[end] ^ k]; n       freq[pxor[end]]++; n     } n     q[i].ans = ans; n   } n   sort(q.begin(), q.end(), compare2); n   for (int i = 0; i < m; i++) printf( %lld n , q[i].ans); n   return 0; n } n


#include <bits/stdc++.h> n const long long MOD = 1000000007; n int N, K; n long long a[5002], FUL[5001]; n long long inv[5001]; n long long O; n long long POWER(long long a, long long b) { n   long long r = 1; n   for (; b; b >>= 1) { n     if (b & 1) r = r * a % MOD; n     a = a * a % MOD; n   } n   return r; n } n int main() { n   scanf( %d%d , &N, &K); n   if (N == 1) { n     printf( %lld n , K % MOD); n     return 0; n   } n   FUL[0] = 1; n   for (int i = 1; i <= N; i++) { n     scanf( %lld , a + i); n     FUL[i] = 0; n     for (int j = i; j; j--) FUL[j] = (FUL[j] * a[i] - FUL[j - 1] + MOD) % MOD; n     FUL[0] = FUL[0] * a[i] % MOD; n   } n   inv[1] = 1; n   for (int i = 2; i <= N; i++) inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD; n   for (int i = 1; i <= N; i++) { n     static long long pol[5000]; n     pol[N - 1] = (MOD - FUL[N]) % MOD; n     for (int j = N - 2; ~j; j--) n       pol[j] = (pol[j + 1] * a[i] - FUL[j + 1] + MOD) % MOD; n     long long TPW = 1; n     for (int a = 0; a < N && a < K; a++) { n       TPW = TPW * inv[N] % MOD * (K - a) % MOD; n       O = (O + pol[a] % MOD * inv[a + 1] % MOD * TPW) % MOD; n     } n   } n   printf( %lld n , O); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ld = long double; n template <class T> n inline T gcd(T a, T b) { n   return !a ? b : gcd(b % a, a); n } n template <class T> n inline T lcm(T a, T b) { n   return (a * b) / gcd(a, b); n } n mt19937 rnd(time(0)); n const int INF = 1e9; n const long long LLINF = 1e15; n void solve() { n   int n, m; n   cin >> n >> m; n   string a, b; n   cin >> a >> b; n   int ans = 0; n   vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0)); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       dp[i][j] = max(0, max(dp[i - 1][j], dp[i][j - 1]) - 1); n       if (a[i - 1] == b[j - 1]) { n         dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 2); n       } n       ans = max(ans, dp[i][j]); n     } n   } n   cout << ans <<   n ; n   return; n } n signed main() { n   ios_base ::sync_with_stdio(0); n   cin.tie(0), cout.tie(0); n   int t = 1; n   while (t-- > 0) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int mod = 1e9 + 7; n void __print(int x) { cerr << x; } n void __print(long x) { cerr << x; } n void __print(long long x) { cerr << x; } n void __print(unsigned x) { cerr << x; } n void __print(unsigned long x) { cerr << x; } n void __print(unsigned long long x) { cerr << x; } n void __print(float x) { cerr << x; } n void __print(double x) { cerr << x; } n void __print(long double x) { cerr << x; } n void __print(char x) { cerr <<      << x <<     ; } n void __print(const char *x) { cerr <<     << x <<    ; } n void __print(const string &x) { cerr <<     << x <<    ; } n void __print(bool x) { cerr << (x ?  true  :  false ); } n template <typename T, typename V> n void __print(const pair<T, V> &x) { n   cerr <<  { ; n   __print(x.first); n   cerr <<  , ; n   __print(x.second); n   cerr <<  } ; n } n template <typename T> n void __print(const T &x) { n   int f = 0; n   cerr <<  { ; n   for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i); n   cerr <<  } ; n } n void _print() { cerr <<  ] n ; } n template <typename T, typename... V> n void _print(T t, V... v) { n   __print(t); n   if (sizeof...(v)) cerr <<  ,  ; n   _print(v...); n } n void solve() { n   long long int l, r; n   cin >> l >> r; n   long long int mposs = (r - 1) >> 1; n   if (r - mposs >= l) n     cout << mposs <<   n ; n   else n     cout << r % l <<   n ; n } n signed main() { n   int 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 long long int ans, sum, pro; n string s, str; n long long int solve(int st, int end, string z) { n   long long int sum2 = 0, pro2 = 1; n   for (int i = st; i <= end; i++) { n     if (z[i] ==  + ) { n       sum2 += pro2; n       pro2 = 1; n     } else if (i % 2 == 0) n       pro2 *= s[i] -  0 ; n   } n   return sum2 + pro2; n } n int main() { n   cin >> s; n   str =  1* ; n   str += s; n   str +=  *1 ; n   s = str; n   for (int i = 1; i < s.size(); i += 2) { n     if (s[i] ==  + ) continue; n     for (int j = i + 2; j < s.size(); j += 2) { n       if (s[j] ==  * ) { n         sum = 0, pro = 1; n         for (int k = 0; k < s.size(); k++) { n           if (k == i) n             pro *= solve(i + 1, j - 1, s); n           else if (k >= i && k <= j) n             continue; n           else if (s[k] ==  + ) { n             sum += pro; n             pro = 1; n           } else if (k % 2 == 0) n             pro *= s[k] -  0 ; n         } n         sum += pro; n         ans = max(ans, sum); n       } n     } n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n bool bad[105]; n string A[105]; n bool check(string a, string b) { n   if ((int)a.size() != (int)b.size()) return false; n   for (int i = 0; i < (int)a.size(); i++) n     if (tolower(a[i]) != tolower(b[i])) return false; n   return true; n } n int main() { n   int n, i, j, k; n   char c, c2; n   string s; n   cin >> n; n   for (i = 0; i < n; i++) cin >> A[i]; n   cin >> s >> c; n   for (i = 0; i < n; i++) { n     for (j = 0; j < (int)s.size(); j++) n       if (check(s.substr(j, (int)A[i].size()), A[i])) n         for (k = j; k < j + (int)A[i].size(); k++) bad[k] = true; n   } n   for (i = 0; i < (int)s.size(); i++) n     if (bad[i]) { n       if (isupper(s[i])) n         c2 = toupper(c); n       else n         c2 = tolower(c); n       if (s[i] == c2) { n         if (isupper(s[i])) { n           for (c2 =  A ; c2 <=  Z ; c2++) n             if (c2 != s[i]) { n               s[i] = c2; n               break; n             } n         } else { n           for (c2 =  a ; c2 <=  z ; c2++) n             if (c2 != s[i]) { n               s[i] = c2; n               break; n             } n         } n       } else n         s[i] = c2; n     } n   cout << s; n   return 0; n } n


#include <bits/stdc++.h> n using std ::vector; n template <typename T> n T max(T x, T y) { n   return (x > y) ? x : y; n } n template <typename T> n T min(T x, T y) { n   return (x < y) ? x : y; n } n template <typename T> n bool chkmax(T &x, T y) { n   return (x >= y) ? 0 : (x = y, 1); n } n template <typename T> n bool chkmin(T &x, T y) { n   return (x <= y) ? 0 : (x = y, 1); n } n template <typename T> n T read(T &in) { n   in = 0; n   char ch; n   T f = 1; n   while (!isdigit(ch = getchar())) n     if (ch ==  - ) f = -1; n   while (isdigit(ch)) in = in * 10 + ch -  0 , ch = getchar(); n   return in *= f; n } n static const int max1 = 100000 + 11; n static const int BIT = 16; n bool vis[max1]; n vector<int> fac[max1]; n struct Node { n   Node *ch[2]; n   int v; n   Node() { ch[0] = ch[1] = NULL, v = 100001; } n }; n struct Trie { n   Node *root; n   Trie() { root = new Node; } n   void Insert(int x) { n     Node *o = root; n     chkmin(o->v, x); n     for (int i = (BIT), ir = (0); i >= (ir); --i) { n       int c = x >> i & 1; n       if (!o->ch[c]) o->ch[c] = new Node; n       o = o->ch[c]; n       chkmin(o->v, x); n     } n   } n } T[max1]; n void Init(int n = 100000) { n   for (int i = 1; i <= n; ++i) n     for (int j = i; j <= n; j += i) fac[j].push_back(i); n } n void Modify(int x) { n   if (vis[x]) return; n   vis[x] = 1; n   for (vector<int>::iterator i = fac[x].begin(); i != fac[x].end(); ++i) n     T[*i].Insert(x); n } n int Query(int x, int k, int s) { n   if (x % k) return -1; n   s -= x; n   int c = 0; n   Node *o = T[k].root; n   if (o->v > s) return -1; n   for (int i = (BIT), ir = (0); i >= (ir); --i) { n     int w = x >> i & 1; n     if (s < (1 << i) || o->ch[1] && o->ch[1]->v > s) n       o = o->ch[0]; n     else if (!o->ch[0]) n       o = o->ch[1], c += 1 << i; n     else if (!o->ch[1]) n       o = o->ch[0]; n     else if (w) n       o = o->ch[0]; n     else n       o = o->ch[1], c += 1 << i; n   } n   return c; n } n int main() { n   int q; n   read(q); n   Init(); n   while (q--) { n     int o, x, k, s; n     read(o), read(x); n     if (o == 1) { n       Modify(x); n     } else { n       read(k), read(s); n       printf( %d n , Query(x, k, s)); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int ans, n, a[10005], cnt, f, i, j, vis[10005]; n int main() { n   scanf( %d , &n); n   for (i = 0; i < n; i++) { n     scanf( %d , &a[i]); n   } n   ans = 0; n   f = 0; n   cnt = 0; n   memset(vis, 0, sizeof vis); n   for (i = 0; i < n; i++) { n     if (!f) { n       for (j = 0; j < n; j++) { n         if (cnt >= a[j] && !vis[j]) { n           vis[j] = 1; n           cnt++; n         } n       } n     } else { n       for (j = n - 1; j >= 0; j--) { n         if (cnt >= a[j] && !vis[j]) { n           vis[j] = 1; n           cnt++; n         } n       } n     } n     if (cnt == n) { n       break; n     } else { n       ans++; n     } n     f = 1 - f; n   } n   printf( %d , 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 a[n], ans = 0, maxi = 0; n   for (int i = 0; i < 7; i++) { n     cin >> a[i]; n     maxi += a[i]; n   } n   int t; n   if (maxi >= n) n     t = 1; n   else if (n % maxi == 0) { n     t = n / maxi; n   } else { n     t = n / maxi + 1; n   } n   while (t--) { n     for (int i = 0; i < 7; i++) { n       n -= a[i]; n       if (n <= 0) { n         ans = i + 1; n         break; n       } n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:100000000 ) n using namespace std; n int b[500][100005], c[500]; n int main() { n   srand(time(0)); n   int n, m, i, j, k; n   scanf( %d %d , &n, &m); n   map<int, vector<int> > a; n   for (i = 0; i < n; i++) { n     scanf( %d , &k); n     if (k <= n) a[k].push_back(i + 1); n   } n   vector<int> v; n   map<int, vector<int> >::iterator it; n   for (it = a.begin(); it != a.end(); it++) n     if (it->first > it->second.size()) v.push_back(it->first); n   for (i = 0; i < v.size(); i++) a.erase(v[i]); n   k = 0; n   for (it = a.begin(); it != a.end(); it++) { n     c[k] = it->first; n     for (i = 0; i < it->second.size(); i++) b[k][it->second[i]] = 1; n     for (i = 1; i <= n; i++) b[k][i] += b[k][i - 1]; n     k++; n   } n   while (m--) { n     scanf( %d %d , &i, &j); n     int cnt = 0; n     for (n = 0; n < k; n++) n       if (c[n] == b[n][j] - b[n][i - 1]) cnt++; n     printf( %d n , cnt); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T gcd(T a, T b) { n   return b ? gcd(b, a % b) : a; n } n int num[26]; n int main() { n   int T; n   scanf( %d , &T); n   while (T--) { n     int n; n     string s, t; n     cin >> n >> s >> t; n     int rev = 0, flg = 0; n     memset(num, 0, sizeof(num)); n     for (int i = 0; i < n; i++) { n       for (int j = s[i] -  a  + 1; j < 26; j++) { n         rev += num[j]; n       } n       num[s[i] -  a ]++; n     } n     for (int i = 0; i < 26; i++) { n       if (num[i] >= 2) flg = 1; n     } n     memset(num, 0, sizeof(num)); n     for (int i = 0; i < n; i++) { n       for (int j = t[i] -  a  + 1; j < 26; j++) { n         rev += num[j]; n       } n       num[t[i] -  a ]++; n     } n     for (int i = 0; i < 26; i++) { n       if (num[i] >= 2) flg = 1; n     } n     sort(s.begin(), s.end()); n     sort(t.begin(), t.end()); n     if (s != t || (rev % 2 != 0 && !flg)) n       puts( NO ); n     else n       puts( YES ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long dr[] = {-1, 1, 0, 0, -1, 1, -1, 1}; n long long dc[] = {0, 0, -1, 1, -1, -1, 1, 1}; n int main() { n   long long T; n   cin >> T; n   while (T--) { n     string a, b; n     cin >> a >> b; n     if (a < b) { n       cout << a <<   n ; n       continue; n     } n     bool f = 0; n     long long sz = min(a.size(), b.size()); n     long long loop = 0; n     for (long long i = 0; i < sz; i++) { n       if (a[i] < b[i]) { n         f = 1; n         break; n       } else { n         long long indx = -1; n         char mn = b[i]; n         for (long long j = i + 1; j < a.size(); j++) { n           if (a[j] <= mn) { n             mn = a[j]; n             indx = j; n           } n         } n         if (indx == -1 and a[i] > b[i]) { n           break; n         } else if (indx == -1 and a[i] == b[i]) { n           continue; n         } n         if (a[i] == a[indx]) continue; n         swap(a[i], a[indx]); n         loop++; n         if (a < b) { n           f = 1; n         } n         break; n       } n     } n     if (f == 1) { n       cout << a <<   n ; n     } else { n       cout <<  ---  n            <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long LAKLSNCJKQ() { n   char c = getchar(); n   if (32281 > 23346) { n     long long SJQTNVYTHY; n     SJQTNVYTHY = 890; n     long long VLABDWDNOG; n     double QHJMZGOBOX; n     bool SJAZLHXFNS; n   } n   long long x = 0; n   double IBTBRLYCXT; n   IBTBRLYCXT = 22204; n   if (IBTBRLYCXT) { n     if (28191 > 11727) { n       if (31516 > 10166) { n         short OIYWZWGUMU; n         OIYWZWGUMU = 32597; n         bool KBORLDDWJN; n         KBORLDDWJN = 28507; n         if (15624 > 14783) { n           double XPAYQSVEQU; n           bool KTQMTWTZFW; n         } n         bool ATVFEDBUXZ; n         ATVFEDBUXZ = 5419; n         if (ATVFEDBUXZ) { n           short YGYZAWOKXY; n         } n       } n       double BQWXBOXCPY; n       BQWXBOXCPY = 6361; n     } n     long long VAOVGFEAUK; n     long long FEIASNIVBT; n     FEIASNIVBT = 18457; n   } n   bool f = 0; n   if (22244 > 7895) { n     short MVPVMWUJOD; n     MVPVMWUJOD = 28548; n     if (MVPVMWUJOD) { n       if (13366 > 13803) { n         bool XDCCNBURPK; n         XDCCNBURPK = 13989; n         long long UPCCKTPSFJ; n         UPCCKTPSFJ = 5412; n       } n     } n   } n   for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45); n   if (331 > 31276) { n     double XUKCKKWRRB; n     XUKCKKWRRB = 2944; n     if (XUKCKKWRRB) { n       short KHPLISVQGN; n       KHPLISVQGN = 21673; n       if (10023 > 7274) { n         if (3328 > 5414) { n           bool JYTIEGOKKQ; n         } n         bool XBXALUHDZX; n         XBXALUHDZX = 9228; n         if (XBXALUHDZX) { n           long long HEXFFVFFRE; n         } n         short FLWZRFLJBM; n         FLWZRFLJBM = 6345; n         if (FLWZRFLJBM) { n           double YOOXQTHBXQ; n           long long SWBPNZOBPM; n           short MIMUYITJME; n           long long LVFSTHJESV; n         } n       } n     } n     if (7446 > 10128) { n       double MQGRWENFXI; n       MQGRWENFXI = 16177; n       if (31692 > 5532) { n         bool VEXACEEMMA; n         VEXACEEMMA = 5606; n         if (11065 > 16359) { n           double EOSLBZHSUN; n         } n         if (9892 > 13627) { n           short GMZDPSFDZG; n           long long JFHPKLADKT; n           bool FYESZAROVH; n         } n       } n       long long LXVYMIPDCK; n     } n     short XYCYVTPGLD; n     XYCYVTPGLD = 25583; n   } n   for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); n   if (23117 > 2644) { n     double LTCKFKKIVJ; n     if (17820 > 22924) { n       double VKBSTTDPFF; n       VKBSTTDPFF = 26648; n       if (VKBSTTDPFF) { n         if (16774 > 5619) { n           long long AZVUQUXROT; n           double GISFTHWSVA; n           long long YWTCSRLTNK; n           short EYBHYCANBM; n         } n         bool MSQJZZIUHR; n         MSQJZZIUHR = 14372; n         double BTTXSQBCBR; n         BTTXSQBCBR = 28650; n       } n       if (17173 > 31740) { n         if (10763 > 16891) { n           short RDTWNHMTID; n         } n         double OUHOEPPBMO; n         bool KXNZUQYVPS; n       } n       if (17326 > 28582) { n         bool WWXKPIIHCE; n         WWXKPIIHCE = 30063; n       } n     } n   } n   if (f) x = -x; n   return x; n   if (17432 > 28544) { n     if (828 > 28220) { n       long long FNDIWALLAX; n       FNDIWALLAX = 31062; n       if (FNDIWALLAX) { n         long long TYAMBDKTLO; n         TYAMBDKTLO = 22072; n         if (23808 > 27160) { n           long long DTDGOVKVWS; n           double NZZOJGQYGA; n           long long UMAYDUQNKS; n         } n       } n       long long EKBLPPACGT; n       EKBLPPACGT = 26135; n       if (EKBLPPACGT) { n         long long OWRLBFHLLO; n         OWRLBFHLLO = 9211; n         if (OWRLBFHLLO) { n           double SXDKTWOMBI; n         } n         bool GKCDYTVHSG; n         if (5365 > 24741) { n           double IIIWGIIJSZ; n           long long FDJQMWIQZF; n         } n       } n       bool UKNSMRJBST; n       UKNSMRJBST = 11817; n       if (UKNSMRJBST) { n         double KSQRSYJYHA; n         if (10789 > 3838) { n           double QUJBIILQGR; n           double RJBINMMZGZ; n           long long IJFIBQPBAT; n         } n         short XVZPFSLVNQ; n       } n     } n     if (27853 > 9859) { n       if (7496 > 18297) { n         if (9508 > 1820) { n           long long BRRIBTPAGH; n           double IZYQBJHUQZ; n         } n       } n     } n     if (13069 > 13617) { n       if (28990 > 9166) { n         bool IPTBNMVVTS; n         IPTBNMVVTS = 20463; n       } n       short BRZLWCLFWL; n       BRZLWCLFWL = 29016; n     } n   } n } n using namespace std; n const long long Mask = (1ll << 30) - 1, inf = 1e18; n long long n; n char s[600005]; n long long PKCNKSQOWC[600005][20], NOQEFVKSSX[600005]; n long long PASLQWKEND1, PASLQWKEND2, a26, a30, PASLQWKEND; n map<long long, long long> ZLMQOGHJFF; n long long OZXICPQWDF[600005], ODIUVNKJQW[600005]; n inline long long ask(long long l, long long r) { n   if (l > r) swap(l, r); n   long long k = NOQEFVKSSX[r - l + 1]; n   long long RJYRZIFLXF; n   RJYRZIFLXF = 4416; n   return min(PKCNKSQOWC[r][k], PKCNKSQOWC[l + (1 << k) - 1][k]); n   if (11184 > 12519) { n     short BJCZAVIHQU; n     BJCZAVIHQU = 21585; n     double JTPTTPPEIW; n     if (7270 > 10837) { n       bool YXCIVCJQUR; n       YXCIVCJQUR = 18023; n       if (YXCIVCJQUR) { n         short HMEDVWYZAD; n         double BIZBSPXTPI; n         BIZBSPXTPI = 19761; n       } n       bool EPFHBLNBQV; n       EPFHBLNBQV = 16855; n       if (EPFHBLNBQV) { n         if (8920 > 87) { n           long long GUTVDVDAUP; n           long long TQQSGXKQKB; n           long long CWYOQFLQWS; n         } n       } n     } n     bool MFGSZBWZXL; n   } n } n void print(long long x, long long y) { n   if (!y) { n     printf( %lld n , x); n     return; n     short PQCMYOUFVD; n     PQCMYOUFVD = 21379; n     if (PQCMYOUFVD) { n       short KYVFDSGZVL; n       KYVFDSGZVL = 28299; n       if (KYVFDSGZVL) { n         if (14693 > 25213) { n           short FEZICBMRZI; n           long long VDNSTGUSLU; n           long long IHWUUSLHLQ; n         } n         short VRRFLEUIWY; n         VRRFLEUIWY = 16770; n         if (VRRFLEUIWY) { n           bool HKMSYIJLMH; n           short FTMBCPPWWL; n           long long HBVFUJHJXC; n         } n         long long AWEWSLADGZ; n         AWEWSLADGZ = 32404; n         if (AWEWSLADGZ) { n           long long TUOIXVWQLK; n           bool VNAAHTOMCM; n           double RYYBVYDOFI; n         } n       } n       double PUKHNXGHLR; n       PUKHNXGHLR = 11134; n     } n   } n   printf( %lld , y); n   bool BFZFAJAHJP; n   BFZFAJAHJP = 27702; n   if (BFZFAJAHJP) { n     long long GRJKVDSUPK; n     GRJKVDSUPK = 31083; n     if (GRJKVDSUPK) { n       if (7344 > 21031) { n         if (13430 > 6930) { n           long long YZTEKYCEXH; n           double RMGXTHTCXE; n           short WOFOSURDYX; n         } n         double KYVQLKWMKV; n       } n       long long CJSSCLMZUU; n       CJSSCLMZUU = 24416; n       if (1470 > 27735) { n         long long MMUICAJFAP; n         if (5792 > 14230) { n           double DPSXHZDHOT; n           long long NPKNGIBVQT; n           double UVEGIPSWFF; n           short SRFYCDCVFU; n           short CJRMQOIKBI; n         } n       } n     } n     if (11216 > 22837) { n       long long MNKZBFRGFJ; n       short ICSTNOPDLO; n       ICSTNOPDLO = 6349; n       if (ICSTNOPDLO) { n         if (27645 > 14013) { n           long long FOLNJLTMDX; n           long long RQGHCPFZMY; n           long long CBANSDKKKB; n           long long RDOHCWWIPX; n         } n         if (10160 > 24441) { n           double VSVQHUFVMW; n         } n       } n       long long XPTKNPPOHX; n       XPTKNPPOHX = 18014; n       if (3933 > 31689) { n         long long FNXJPICBKA; n       } n     } n     double BAGZRPCXQH; n     BAGZRPCXQH = 11896; n   } n   long long now = inf / 10; n   long long QLXZPYBXTJ; n   QLXZPYBXTJ = 17162; n   while (now > x && now >= 10) putchar( 0 ), now /= 10; n   if (2226 > 31142) { n     long long EDWJMGBWHJ; n     EDWJMGBWHJ = 32093; n     if (EDWJMGBWHJ) { n       if (7027 > 23752) { n         if (15643 > 24958) { n           bool UNBRLRBRKZ; n           short CYZELXDDHX; n           bool MIKZQCQKLS; n           bool CVPGIILVHA; n         } n       } n       long long QYISVVTYAS; n       QYISVVTYAS = 30577; n     } n     long long XAHLGLMGRD; n     XAHLGLMGRD = 11996; n     if (XAHLGLMGRD) { n       long long ETKECDJAMX; n       ETKECDJAMX = 6319; n       if (28138 > 7202) { n         if (24397 > 24360) { n           bool VNTZVBCFYC; n         } n         double FNIAMKXDKC; n         FNIAMKXDKC = 2707; n         if (FNIAMKXDKC) { n           long long BTPDBRLEIW; n           short NCOLRHIITE; n           double HQFYCCBACD; n           bool GMZIUJWMFA; n           long long EDXJKJUBFW; n         } n       } n       if (8285 > 10375) { n         long long OCOYCBMFLM; n         OCOYCBMFLM = 21978; n         if (27175 > 15533) { n           short UZEPJAZTDP; n           double GNJDGVOAMW; n           double FCHIHZFDER; n           short OGUZXULEOL; n         } n         if (14265 > 20236) { n           long long KABFUJALMS; n           short ZGBWNAUAER; n         } n       } n     } n   } n   printf( %lld n , x); n   if (6512 > 31058) { n     if (20281 > 1432) { n       if (13622 > 17665) { n         if (29270 > 7054) { n           long long FFGDTLRVDD; n           long long FVQIHPGNGA; n           short GPQZERIEVA; n         } n         short BJGSVDUUAU; n         bool KVAOEUMIRF; n       } n       bool DHTVYEZTDC; n       if (8247 > 8501) { n         if (24741 > 12098) { n           bool IYROVUUNZX; n           long long WQROVRNZFF; n           bool JCDKQKUXWP; n           long long XBGJSYBGKU; n         } n         long long ZTZOASWUJT; n         ZTZOASWUJT = 7936; n         if (ZTZOASWUJT) { n           short BGLTBDDZXJ; n         } n         if (27819 > 5085) { n           long long NYCVYZFPER; n           long long FAGJEBIZYM; n         } n       } n     } n     long long CWQAYAGVVA; n     if (7808 > 24851) { n       long long LVDDJUADIK; n       LVDDJUADIK = 27710; n     } n   } n } n signed main() { n   n = LAKLSNCJKQ(), NOQEFVKSSX[0] = -1; n   bool OJBUOKHNZP; n   OJBUOKHNZP = 9527; n   if (OJBUOKHNZP) { n     long long THDITISJUK; n     THDITISJUK = 32453; n     if (THDITISJUK) { n       bool AEKBKKXSQJ; n       AEKBKKXSQJ = 4561; n       if (AEKBKKXSQJ) { n         double OTNTQJYURH; n         OTNTQJYURH = 8786; n       } n       if (32521 > 3021) { n         bool LIPPFKNCSW; n         if (4668 > 21251) { n           bool GEEJRXLMRQ; n           long long EQOMAXBWSR; n           long long YFWKKNUBNX; n         } n       } n       long long OCTWNVRHIS; n     } n     double IDABZUKKIV; n   } n   for (long long i = (1); i <= (n); ++i) NOQEFVKSSX[i] = NOQEFVKSSX[i >> 1] + 1; n   if (7728 > 10480) { n     long long TJWNMUJCBD; n     TJWNMUJCBD = 899; n     if (TJWNMUJCBD) { n       double OCLIDBOVHI; n       short FEHVYHHCKQ; n       FEHVYHHCKQ = 21844; n       double TIKOQFHVPD; n       TIKOQFHVPD = 27273; n       long long WIHBCOGVWF; n     } n     bool SLJQQOMDJC; n     SLJQQOMDJC = 27775; n     short ZJSCRHEQMD; n   } n   OZXICPQWDF[0] = -1; n   double CHVRMSFDIT; n   CHVRMSFDIT = 28336; n   for (long long i = (1); i <= (n); ++i) { n     scanf( %s , s + i); n     if (5013 > 30592) { n       double YYLFBDEYIA; n       YYLFBDEYIA = 17517; n       bool TNAWJTYVJW; n       TNAWJTYVJW = 32675; n       long long KZZTAJUUMW; n     } n     s[i] = ((s[i] -  a  + a26) % 26) +  a ; n     bool AVCQWAUQGM; n     AVCQWAUQGM = 17877; n     if (AVCQWAUQGM) { n       short KNDWIIAUDN; n       KNDWIIAUDN = 11578; n       if (KNDWIIAUDN) { n         bool XZGWKECTXO; n         long long ROMCPCZVRW; n       } n       if (3031 > 28497) { n         if (5615 > 28550) { n           long long KMYCQLCMRK; n           long long NUJUQEZAGM; n           bool AQHLXZSMJF; n           long long GPHHMIDCDN; n           short MGXFDNMKLV; n         } n         double QWLZXBLCUV; n         QWLZXBLCUV = 11743; n         if (QWLZXBLCUV) { n           double CEMFHTAJKE; n         } n         long long MLDXLMCEZM; n       } n       bool LREWUAAYZU; n       short OVACEMKBUI; n     } n     long long w = LAKLSNCJKQ(); n     short RZYSLIYYLY; n     RZYSLIYYLY = 9499; n     w ^= (a30 & Mask); n     short HBIHGJNXAH; n     PKCNKSQOWC[i][0] = w; n     short TWUENILLHZ; n     for (long long j = (1); j <= (19); ++j) n       if (i >= (1 << j)) n         PKCNKSQOWC[i][j] = n             min(PKCNKSQOWC[i - (1 << (j - 1))][j - 1], PKCNKSQOWC[i][j - 1]); n     long long j = OZXICPQWDF[i - 1]; n     if (6425 > 25228) { n       long long OVKNAHKQGH; n       OVKNAHKQGH = 4501; n       if (OVKNAHKQGH) { n         if (31760 > 16539) { n           short RLTXWGZHYR; n           short GEOBYOKLES; n         } n         long long XHZSTOCISZ; n         XHZSTOCISZ = 22954; n         if (29408 > 21905) { n           bool JHYTHTGDKJ; n         } n         short RAXAIPWLJW; n         RAXAIPWLJW = 6467; n         if (RAXAIPWLJW) { n           long long ZGOYUWAYZD; n         } n       } n       long long EIPPCNMEQF; n       EIPPCNMEQF = 3644; n       short ZYDUAOZJRA; n       ZYDUAOZJRA = 632; n       if (ZYDUAOZJRA) { n         short PZAFKAOQXY; n         double SAAAUIOWLM; n         SAAAUIOWLM = 22279; n         if (SAAAUIOWLM) { n           short UFYBMKZBDF; n           short JYGBVNQHDC; n         } n         bool EFYYBKVPFD; n         EFYYBKVPFD = 10307; n         if (EFYYBKVPFD) { n           bool RQCXPYVCCR; n           bool CMCMTSPIFA; n         } n         if (30868 > 25897) { n           long long EWIHEWTHXS; n           double RDUMYFGMYW; n         } n       } n     } n     while (j >= 0 && s[j + 1] != s[i]) j = OZXICPQWDF[j]; n     bool RTAMEHWMGO; n     RTAMEHWMGO = 1477; n     OZXICPQWDF[i] = j + 1; n     if (19881 > 32092) { n       long long RIUVFDXUGO; n       if (13388 > 21570) { n         if (21487 > 7615) { n           short PSWIBTGZKN; n         } n         short XPOHUCUACK; n         XPOHUCUACK = 32156; n         if (XPOHUCUACK) { n           long long KZDFMDYGLZ; n           long long YRIRTLEODA; n         } n         bool BUKJIWBLIS; n         BUKJIWBLIS = 27616; n         if (BUKJIWBLIS) { n           short UIHOWHWHZP; n         } n         short ASQZFIRDXA; n         ASQZFIRDXA = 3309; n       } n     } n     if (s[i] == s[OZXICPQWDF[i - 1] + 1]) n       ODIUVNKJQW[i - 1] = ODIUVNKJQW[OZXICPQWDF[i - 1]]; n     else n       ODIUVNKJQW[i - 1] = OZXICPQWDF[i - 1]; n     if (27391 > 3744) { n       long long RSCAKDIEHL; n       RSCAKDIEHL = 11196; n       if (RSCAKDIEHL) { n         if (28157 > 27255) { n           double IWGDFKWLXD; n           bool VOMUPWPIND; n         } n         if (4100 > 11906) { n           bool QIXZLSKWDV; n           bool PLLNOGQRTF; n         } n         if (32712 > 11866) { n           short CZXRVBXXPU; n           short LASWUSAAMX; n           short JXQLYTDOKM; n         } n       } n       long long JGORDMHITJ; n       JGORDMHITJ = 16257; n     } n     j = i - 1; n     long long ZGLUSKXMSY; n     ZGLUSKXMSY = 21361; n     while (j >= 1) { n       if (s[j + 1] == s[i]) n         j = ODIUVNKJQW[j]; n       else { n         long long t = ask(i - j, i - 1); n         long long ZXXEWLUNJN; n         PASLQWKEND -= t, ZLMQOGHJFF[t]--, j = OZXICPQWDF[j]; n         if (26848 > 4959) { n           double ZIUPHCQHXF; n           long long ENGJOSZHOX; n         } n       } n     } n     long long add = (s[i] == s[1]); n     double BJDVQKKZOO; n     BJDVQKKZOO = 11772; n     while (ZLMQOGHJFF.size() && ((--ZLMQOGHJFF.end())->first) > w) { n       auto it = --ZLMQOGHJFF.end(); n       if (20559 > 3094) { n         long long VEQQVLIMKJ; n         VEQQVLIMKJ = 9639; n         if (15413 > 18844) { n           short DBCPWNWZKU; n           long long CBRMFIYLBH; n         } n         if (10465 > 8950) { n           long long QAVPKTSOLN; n           bool PIIKHCBCWK; n         } n         double NVGIGZTZQY; n         NVGIGZTZQY = 28060; n         if (NVGIGZTZQY) { n           double VGVNCHNPGM; n           short YRZQUOSJUM; n         } n         bool CPHJORRGJS; n       } n       add += it->second, PASLQWKEND -= it->second * it->first; n       if (11171 > 21467) { n         long long KRHUPMUQCT; n         KRHUPMUQCT = 4789; n         if (31245 > 5281) { n           long long CADVVAFLGJ; n         } n       } n       ZLMQOGHJFF.erase(it); n       long long YGIXFXONAK; n       YGIXFXONAK = 8967; n     } n     PASLQWKEND += add * w, ZLMQOGHJFF[w] += add; n     if (30861 > 32345) { n       long long MJHZOWCGQF; n       bool FJCOTOGVFN; n       FJCOTOGVFN = 13155; n       if (28712 > 12867) { n         if (27262 > 15580) { n           long long XRHQKNJWFK; n           bool WMWMAFDFVN; n           long long TSZBACQOUC; n         } n         if (8570 > 21638) { n           bool XLZICHFHVW; n         } n         short QGZZGTPGNW; n         QGZZGTPGNW = 32135; n         if (QGZZGTPGNW) { n           long long UJNORZHGWS; n           long long YTIXUOYAEX; n           bool YCXWDEQSDG; n         } n         long long MCPDAQXWVP; n       } n     } n     a26 = (a26 + PASLQWKEND) % 26, a30 = (a30 + PASLQWKEND) & Mask; n     long long KEDZHCKFIZ; n     KEDZHCKFIZ = 2329; n     if (KEDZHCKFIZ) { n       long long ZYURMHVIGM; n     } n     PASLQWKEND1 += PASLQWKEND; n     if (28120 > 8670) { n       bool THTEVDTHEQ; n     } n     if (PASLQWKEND1 >= inf) PASLQWKEND2++, PASLQWKEND1 -= inf; n     print(PASLQWKEND1, PASLQWKEND2); n     if (20512 > 5823) { n       if (4608 > 16596) { n         double YWDFXFBSAN; n         YWDFXFBSAN = 8542; n         if (YWDFXFBSAN) { n           short YKRCRINEMM; n           long long GRKAGLHJPR; n           long long YBGWHEWZXM; n           short SLGRSYCQMB; n         } n         if (17831 > 8044) { n           long long WSSQXKMEWI; n         } n       } n       bool WPHZJRTOXT; n       WPHZJRTOXT = 23409; n       long long ZVKRUTMJKO; n       ZVKRUTMJKO = 1981; n     } n   } n   return 0; n   long long ZUSFQYEYXO; n   ZUSFQYEYXO = 20994; n   if (ZUSFQYEYXO) { n     bool RTWAUOYVNL; n     long long SVOEZZDQBR; n     SVOEZZDQBR = 25293; n     double DHZACPREKX; n     DHZACPREKX = 25408; n   } n } n


#include <bits/stdc++.h> n using namespace std; n pair<long long, long long> p1[1005]; n pair<long long, long long> p2[1005]; n vector<long long> v; n int main() { n   long long i, j, n, x, y, a, b; n   cin >> n; n   for (i = 0; i < n; i++) cin >> p1[i].first >> p1[i].second; n   for (i = 0; i < n; i++) cin >> p2[i].first >> p2[i].second; n   sort(p1, p1 + n); n   sort(p2, p2 + n); n   cout << p1[0].first + p2[n - 1].first <<     n        << p1[0].second + p2[n - 1].second; n } n


#include <bits/stdc++.h> n using namespace std; n long long inf = 2147483647; n const long long ll = 9223372036854775807, ninf = 1000000000; n const double eps = 1e-6; n const long long nll = 1000000000000000000; n vector<int> node[200005]; n vector<int> num; n int deg[200005] = {}; n void dfs(int x) { n   for (int i = 0; i < node[x].size(); i++) { n     dfs(node[x][i]); n   } n   num.push_back(x); n } n int A[200005] = {}; n int main() { n   int a; n   while (cin >> a) { n     int r = 1; n     for (int i = 1; i <= a; i++) { n       cin >> A[i]; n       deg[A[i]]++; n       if (A[i]) { n         deg[i]++; n         node[A[i]].push_back(i); n       } else { n         r = i; n       } n     } n     if (a % 2 == 0) { n       cout <<  NO  <<   n ; n       continue; n     } n     dfs(r); n     vector<int> ans1, ans2; n     cout <<  YES  <<   n ; n     for (int i = 0; i < num.size(); i++) { n       int now = num[i]; n       if (deg[now] % 2 == 0) { n         ans2.push_back(now); n         deg[A[now]]--; n       } else { n         ans1.push_back(now); n       } n     } n     for (int i = 0; i < ans2.size(); i++) { n       cout << ans2[i] <<   n ; n     } n     reverse(ans1.begin(), ans1.end()); n     for (int i = 0; i < ans1.size(); i++) { n       cout << ans1[i] <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1005; n int fa[2][maxn << 1]; n int cost[2][maxn][maxn]; n int dd[2][maxn]; n int n; n int sz[2]; n int dp[maxn]; n void init(int t) { n   cin >> sz[t]; n   for (int i = (2); i <= (sz[t]); ++i) cin >> fa[t][i]; n   for (int i = (1); i <= (n); ++i) cin >> dd[t][i]; n } n void cal(int t) { n   for (int l = (1); l <= (n); ++l) { n     vector<int> sons(sz[t] + 1, 0); n     for (int i = (1); i <= (sz[t]); ++i) sons[fa[t][i]]++; n     for (int r = (l); r <= (n); ++r) { n       int now = dd[t][r]; n       int val = 0; n       while (now != 1 && sons[now] == 0) n         val++, sons[fa[t][now]]--, now = fa[t][now]; n       cost[t][l][r] = cost[t][l][r - 1] + val; n     } n   } n } n void solve() { n   for (int i = (1); i <= (n); ++i) { n     int& ans = dp[i]; n     for (int j = (0); j < (i); ++j) n       ans = max(ans, dp[j] + max(cost[1][j + 1][i], cost[0][j + 1][i])); n   } n } n int main(void) { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   for (int i = (0); i < (2); ++i) init(i); n   for (int i = (0); i < (2); ++i) cal(i); n   solve(); n   cout << dp[n] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline T SQR(T x) { n   return x * x; n } n template <class T> n inline string TOSTR(const T &x) { n   stringstream ss; n   ss << x; n   return ss.str(); n } n template <class T> n void UPDATE_MIN(T &x, T y) { n   if (y < x) { n     x = y; n   } n } n template <class T> n void UPDATE_MAX(T &x, T y) { n   if (x < y) { n     x = y; n   } n } n int gcd(int a, int b) { return a ? gcd(b % a, a) : b; } n long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; } n long long powmod(long long a, long long p, long long m) { n   long long r = 1; n   while (p) { n     if (p & 1) r = r * a % m; n     p >>= 1; n     a = a * a % m; n   } n   return r; n } n const int MOD = 1000 * 1000 * 1000 + 7; n const double PI = 3.1415926535897932384626433832795l; n long long n, m, k; n long long p10[10000]; n long long p9_10[10000]; n long long counts_a[100] = {}; n long long counts_b[100] = {}; n long long *counts, *counts2; n int main() { n   cin >> n >> k >> m; n   long long a10 = 1, a9_10 = 1; n   for (int(i) = 0; (i) < (int)(n); (i)++) { n     p10[i] = a10; n     p9_10[i] = a9_10; n     a10 = (a10 * 10LL) % k; n     a9_10 = (a9_10 * ((i == 0) ? 9LL : 10LL)) % m; n   } n   counts = counts_a; n   counts2 = counts_b; n   counts[0] = 1; n   long long res = 0; n   for (int(i) = 0; (i) < (int)(n); (i)++) { n     for (int(j) = 0; (j) < (int)(k); (j)++) counts2[j] = 0; n     for (int(r) = 0; (r) < (int)(k); (r)++) { n       int mind = ((i == n) ? 1 : 0); n       for (int(d) = mind; (d) < (int)(10); (d)++) { n         long long r2 = (d * p10[i] + r) % k; n         counts2[r2] = (counts2[r2] + counts[r]) % m; n       } n     } n     res += (counts2[0] - 1) * p9_10[n - i - 1]; n     res %= m; n     while (res < 0) res += m; n     counts2[0] = 1; n     { n       __typeof(counts) tmp = counts; n       counts = counts2; n       counts2 = tmp; n     }; n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<char, long long int> cou; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   long long int n; n   cin >> n; n   while (n--) { n     string s; n     cin >> s; n     cou[s[0]]++; n   } n   long long int ans = 0; n   for (map<char, long long int>::iterator it = cou.begin(); it != cou.end(); n        it++) { n     long long int req = it->second; n     long long int f = (req + 1) / 2; n     long long int s = req / 2; n     ans = ans + (f * (f - 1)) / 2 + (s * (s - 1)) / 2; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int mark[1 << 22]; n int is[1 << 22]; n int a[1 << 22]; n int n, m; n int tot; n void dfs(int x) { n   if (mark[x]) return; n   mark[x] = 1; n   if (is[x]) dfs(tot ^ x); n   for (int j = 0; j < n; j++) { n     if (x >> j & 1) { n       dfs(x ^ (1 << j)); n     } n   } n } n signed main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; i++) { n     scanf( %d , &a[i]); n     is[a[i]] = 1; n   } n   tot = (1 << n) - 1; n   int ans = 0; n   for (int i = 1; i <= m; i++) { n     if (mark[a[i]]) continue; n     mark[a[i]] = 1; n     ans++; n     dfs(tot ^ a[i]); n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 5e5 + 7; n const long long INF = 1e17 + 7; n long long h[N], t[N], f[N][2], pos[N], w[N]; n long long n, num = 0; n struct edge { n   long long v, next; n } e[N * 2]; n struct pir { n   long long a, b; n } p[N]; n bool cmp(pir x, pir y) { return (x.b - x.a) < (y.b - y.a); } n void add(long long x, long long y) { n   e[num] = (edge){y, pos[x]}; n   pos[x] = num++; n } n void dfs(long long x, long long fa) { n   long long cnt = 0, s1 = 0, s0 = 0, hh = 0, ss = 0; n   for (long long i = pos[x]; ~i; i = e[i].next) { n     if (e[i].v == fa) continue; n     hh = 1; n     dfs(e[i].v, x); n     if (h[e[i].v] > h[x]) s1++, ss += f[e[i].v][1]; n     if (h[e[i].v] < h[x]) s0++, ss += f[e[i].v][0]; n   } n   if (!hh) { n     f[x][0] = f[x][1] = t[x]; n     return; n   } n   w[0] = 0; n   for (long long i = pos[x]; ~i; i = e[i].next) { n     if (e[i].v != fa && h[e[i].v] == h[x]) { n       w[0] += f[e[i].v][0]; n       p[++cnt] = (pir){f[e[i].v][0], f[e[i].v][1]}; n     } n   } n   sort(p + 1, p + cnt + 1, cmp); n   for (long long i = 1; i <= cnt; i++) w[i] = w[i - 1] + p[i].b - p[i].a; n   f[x][0] = f[x][1] = INF; n   for (long long i = 0; i <= cnt + 1 - 1; i++) { n     f[x][0] = n         min(f[x][0], w[i] + max(cnt - i + s0, i + s1 + (x != 1)) * t[x] + ss); n     f[x][1] = n         min(f[x][1], w[i] + max(cnt - i + s0 + (x != 1), i + s1) * t[x] + ss); n   } n } n int main() { n   scanf( %I64d , &n); n   memset(pos, -1, sizeof(pos)); n   for (long long i = 1; i <= n; i++) scanf( %I64d , &t[i]); n   for (long long i = 1; i <= n; i++) scanf( %I64d , &h[i]); n   for (long long i = 1; i <= n - 1; i++) { n     long long x, y; n     scanf( %I64d%I64d , &x, &y); n     add(x, y); n     add(y, x); n   } n   dfs(1, 0); n   printf( %I64d n , f[1][0]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i = 0; n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   vector<int> ans; n   int n; n   int m; n   cin >> n >> m; n   int a[110]; n   int b[20]; n   memset(a, 0, sizeof a); n   memset(b, 0, sizeof b); n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (int i = 0; i < m; i++) { n     int t; n     cin >> t; n     b[t] = 1; n   } n   for (int i = 0; i < n; i++) { n     if (b[a[i]] == 1) ans.push_back(a[i]); n   } n   for (int i = 0; i < ans.size(); i++) { n     cout << ans[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string t(int a) { n   int i, tmp = 1; n   for (i = 1; i <= a; i *= 3) { n   } n   string s; n   for (; i >= 1; i /= 3) { n     if (a / i == 2) n       s +=  2 , a %= i; n     else if (a / i == 1) n       s +=  1 , a %= i; n     else n       s +=  0 ; n   } n   return s; n } n int main() { n   int i, a, b = 0, c; n   cin >> a >> c; n   string s1, s2, s3; n   s1 = t(a), s2 = t(c); n   int t = max(((int)s1.size()), ((int)s2.size())); n   for (i = 0; i < t; i++) { n     if (((int)s1.size()) - t + i >= 0) n       a = s1[((int)s1.size()) - t + i] -  0 ; n     else n       a = 0; n     if (((int)s2.size()) - t + i >= 0) n       c = s2[((int)s2.size()) - t + i] -  0 ; n     else n       c = 0; n     s3 += ((c - a + 3) % 3 +  0 ); n   } n   reverse(s3.begin(), s3.end()); n   for (i = 0; i < ((int)s3.size()); i++) { n     t = 1; n     for (int j = 0; j < i; j++) t *= 3; n     b += (s3[i] -  0 ) * t; n   } n   cout << b << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, vet[202020], cap[202020]; n set<long long> s; n int main() { n   scanf( %lld , &n); n   for (long long i = 1; i <= n; i++) scanf( %lld , &cap[i]), s.insert(i); n   scanf( %lld , &m); n   long long op, x, p, k; n   while (m--) { n     scanf( %lld , &op); n     if (op == 1) { n       scanf( %lld %lld , &p, &x); n       for (auto it = s.lower_bound(p); it != s.end() && x; it = s.erase(it)) { n         long long id = *it; n         if (cap[id] - vet[id] > x) { n           vet[id] += x; n           break; n         } n         x -= cap[id] - vet[id]; n         vet[id] = cap[id]; n       } n     } else { n       scanf( %lld , &k); n       printf( %lld n , vet[k]); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 15, maxx = 10; n long long a[maxn], b[maxn], c[maxn]; n void Init() { n   for (int i = 1; i <= maxx; i++) { n     long long x = i, l = 1, r = 0; n     while (x--) l *= 10, r = r * 10 + 9; n     l /= 10; n     a[i] = (r - l + 1) * i; n     b[i] = b[i - 1] + a[i]; n     c[i] = c[i - 1] + (b[i - 1] + i + b[i]) * (r - l + 1) / 2; n   } n } n int main() { n   ios::sync_with_stdio(0); n   Init(); n   long long t, n, pos; n   cin >> t; n   while (t--) { n     cin >> n; n     pos = lower_bound(c + 1, c + maxx + 1, n) - c; n     n = n - c[pos - 1]; n     long long l = 1, r = 0, x = pos, t = b[pos - 1]; n     while (x--) l *= 10, r = 10 * r + 9; n     l /= 10; n     long long L = l; n     while (l <= r) { n       long long mid = (l + r) >> 1; n       long long cnt = mid - L + 1; n       if ((2 * t + pos + cnt * pos) * cnt / 2 >= n) n         r = mid - 1; n       else n         l = mid + 1; n     } n     long long cnt = l - L; n     n -= (2 * t + pos + cnt * pos) * cnt / 2; n     pos = lower_bound(b + 1, b + maxx + 1, n) - b; n     n -= b[pos - 1]; n     int ans = 1; n     for (int i = 1; i < pos; i++) ans *= 10; n     t = (n - 1) / pos; n     n -= t * pos; n     ans += t; n     n = pos - n; n     while (n--) ans /= 10; n     cout << ans % 10 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool flag; n int n, a[1010], vis[2010], T; n pair<int, int> ans[5]; n void read(int &x) { n   char ch = getchar(); n   int mark = 1; n   for (; ch !=  -  && (ch <  0  || ch >  9 ); ch = getchar()) n     ; n   if (ch ==  - ) mark = -1, ch = getchar(); n   for (x = 0; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch - 48; n   x *= mark; n } n bool check(int step) { n   for (int i = 1; i <= n; i++) n     if (a[i] != i) return 0; n   return 1; n } n void rev(int *a, int l, int r) { n   for (int i = 0; i <= (r - l - 1) / 2; i++) swap(a[i + l], a[r - i]); n } n int expect() { n   int ans = 1; n   for (int i = 2; i <= n; i++) n     if (abs(a[i] - a[i - 1]) != 1) ans++; n   return ans; n } n void dfs(int step) { n   if (check(step - 1)) { n     printf( %d n , step - 1); n     for (int i = step - 1; i; i--) n       printf( %d %d n , ans[i].first, ans[i].second); n     flag = 1; n     return; n   } n   if (step > 3) return; n   int c[1010]; n   for (int i = 1; i <= n; i++) { n     for (int j = i + 1; j <= n; j++) n       if (abs(a[i - 1] - a[j]) == 1 || abs(a[i] - a[j + 1]) == 1) { n         for (int k = i; k <= j; k++) c[k] = a[k]; n         rev(a, i, j); n         if (expect() <= (3 - step) * 2 + 1) { n           ans[step] = make_pair(i, j); n           dfs(step + 1); n           if (flag) return; n         } n         for (int k = i; k <= j; k++) a[k] = c[k]; n       } n   } n } n int main() { n   read(n); n   for (int i = 1; i <= n; i++) read(a[i]); n   a[n + 1] = n + 1; n   dfs(1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool test(long long k, long long x, long long n, long long m, long long p1, n           long long l1, long long r1, long long p2, long long l2, n           long long r2) { n   if (p1 * 2 + l1 + r1 > n) return false; n   if (p2 * 2 + l2 + r2 > m) return false; n   for (long long i = 0; i < k - 2; i++) { n     long long p3 = p1 + p2 + (r1 * l2); n     long long l3 = l1; n     long long r3 = r2; n     l1 = l2; n     r1 = r2; n     p1 = p2; n     l2 = l3; n     r2 = r3; n     p2 = p3; n     if (p2 > x) return false; n   } n   return p2 == x; n } n string build(long long n, long long p, long long l, long long r) { n   string s(n,  X ); n   if (l) s[0] =  C ; n   if (r) s[n - 1] =  A ; n   for (long long i = 0; i < p; i++) { n     s[l + i * 2] =  A ; n     s[l + i * 2 + 1] =  C ; n   } n   return s; n } n signed main() { n   ios::sync_with_stdio(false); n   long long k, x, n, m; n   cin >> k >> x >> n >> m; n   for (long long p1 = 0; p1 <= n / 2; p1++) { n     for (long long l1 = 0; l1 <= 1; l1++) { n       for (long long r1 = 0; r1 <= 1; r1++) { n         for (long long p2 = 0; p2 <= m / 2; p2++) { n           for (long long l2 = 0; l2 <= 1; l2++) { n             for (long long r2 = 0; r2 <= 1; r2++) { n               if (test(k, x, n, m, p1, l1, r1, p2, l2, r2)) { n                 string s1 = build(n, p1, l1, r1); n                 string s2 = build(m, p2, l2, r2); n                 cout << s1 <<   n  << s2 <<   n ; n                 return 0; n               } n             } n           } n         } n       } n     } n   } n   cout <<  Happy new year! n ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize 2 n using namespace std; n const int N = 2e4 + 9; n struct stree { n   int l, r, lazy, sum; n } t[N << 2]; n int dp[20005]; n inline void pushdown(int now) { n   int lazy = t[now].lazy; n   if (!lazy) return; n   if (t[now].l != t[now].r) n     t[now * 2].lazy += lazy, t[now * 2 + 1].lazy += lazy; n   t[now].sum += lazy; n   t[now].lazy = 0; n } n inline void build(int now, int l, int r) { n   t[now].l = l, t[now].r = r, t[now].lazy = 0; n   if (l == r) { n     t[now].sum = dp[l]; n     return; n   } n   int mid = (l + r) / 2; n   build(now * 2, l, mid), build(now * 2 + 1, mid + 1, r); n   t[now].sum = max(t[now * 2].sum, t[now * 2 + 1].sum); n } n inline void change(int now, int l, int r, int d) { n   if (l > r) return; n   pushdown(now); n   if (t[now].l == l && t[now].r == r) { n     t[now].lazy += d; n     return; n   } n   pushdown(now); n   if (t[now * 2].r >= r) n     change(now * 2, l, r, d); n   else if (t[now * 2 + 1].l <= l) n     change(now * 2 + 1, l, r, d); n   else n     change(now * 2, l, t[now * 2].r, d), n         change(now * 2 + 1, t[now * 2 + 1].l, r, d); n   pushdown(now); n   if (t[now].l != t[now].r) n     pushdown(now * 2), pushdown(now * 2 + 1), n         t[now].sum = max(t[now * 2].sum, t[now * 2 + 1].sum); n } n inline int query(int now, int l, int r) { n   pushdown(now); n   if (l > r) return 0; n   if (t[now].l == l && t[now].r == r) return t[now].sum; n   if (t[now * 2].r >= r) n     return query(now * 2, l, r); n   else if (t[now * 2 + 1].l <= l) n     return query(now * 2 + 1, l, r); n   else n     return max(query(now * 2, l, t[now * 2].r), n                query(now * 2 + 1, t[now * 2 + 1].l, r)); n } n int qzh[55][20005], a[55][20005], cf[20005]; n int main() { n   int n, m, k; n   cin >> n >> m >> k; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       cin >> a[i][j]; n       qzh[i][j] = qzh[i][j - 1] + a[i][j]; n     } n   } n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     if (i != 1) { n       for (int j = 1; j <= k; j++) dp[j] -= qzh[i][k] - qzh[i][j - 1]; n     } n     build(1, 1, m); n     memset(dp, 0, sizeof dp); n     for (int j = 1; j <= m - k + 1; j++) { n       dp[j] = query(1, 1, m) - qzh[i][j - 1] - qzh[i + 1][j - 1] + n               qzh[i][j + k - 1] + qzh[i + 1][j + k - 1]; n       if (i != 1) n         change(1, max(1, j - k + 1), min(m, j), a[i][j]), n             change(1, max(1, j + 1), min(m, j + k), -a[i][j + k]); n       ans = max(ans, dp[j]); n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const double eps = 1e-6; n template <class T> n T gcd(T a, T b) { n   if (!b) return a; n   return gcd(b, a % b); n } n const int maxn = 1e6 + 10; n int n, m; n int phi[maxn]; n int a[maxn]; n int get(int x) { n   int res = x; n   for (long long i = 2; i * i <= x; i++) { n     if (x % i == 0) { n       res = res / i * (i - 1); n       while (x % i == 0) x /= i; n     } n   } n   if (x > 1) res = res / x * (x - 1); n   return res; n } n int qpow(int b, int n, int mod) { n   int res = 1; n   while (n) { n     if (n & 1) res = 1LL * res * b >= mod ? 1LL * res * b % mod + mod : res * b; n     b = 1LL * b * b >= mod ? 1LL * b * b % mod + mod : b * b; n     n >>= 1; n   } n   return res; n } n int solve(int l, int r, int k) { n   if (phi[k] == 1) return 1; n   if (l == r) { n     if (a[l] < phi[k]) n       return a[l]; n     else n       return a[l] % phi[k] + phi[k]; n   } else n     return qpow(a[l], solve(l + 1, r, k + 1), phi[k]); n } n int main() { n   scanf( %d , &n); n   scanf( %d , &phi[0]); n   while (phi[m] != 1) { n     phi[m + 1] = get(phi[m]); n     m++; n   } n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n   } n   int q; n   scanf( %d , &q); n   for (int i = 0; i < q; i++) { n     int l, r; n     scanf( %d , &l); n     scanf( %d , &r); n     int ans = solve(l, r, 0) % phi[0]; n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long M = 1000000007; n long long bigMod(long long n, long long power, long long mod = M) { n   if (power == 0) return 1; n   if (power == 1) n     return n % mod; n   else if (power % 2 == 0) { n     long long v = bigMod(n, power / 2, mod); n     return ((v % mod) * (v % mod)) % mod; n   } else { n     long long v = bigMod(n, power - 1, mod) % mod; n     return ((v % mod) * (n % mod)) % mod; n   } n } n int main() { n   long long n; n   scanf( %lld , &n); n   long long number = bigMod(2, n); n   cout << ((number * (number + 1)) / 2) % M << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3005; n int n, a[N]; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     scanf( %d , a + i); n   } n   int ans = 0; n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < i; ++j) { n       if (a[j] > a[i]) { n         ++ans; n       } n     } n   } n   printf( %.12f n , (double)(ans / 2 * 4 + ans % 2)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, K; n int pover[64000]; n int ipover[64000]; n int dt[503][503]; n int lsum[2][503][503]; n const int mod = 1000000007; n int main() { n   scanf( %d%d , &n, &K); n   int maxval = 0; n   pover[0] = 1; n   for (int i = 1; i < 64000; i++) { n     pover[i] = (pover[i - 1] * (long long)2) % mod; n   } n   ipover[0] = 1; n   for (int i = 1; i < 64000; i++) { n     ipover[i] = (ipover[i - 1] * (long long)500000004) % mod; n   } n   for (int j = 0; j <= 0; j++) { n     dt[0][j] = 1; n   } n   for (int k = 0; k <= n; k++) { n     long long ksum = 0; n     for (int j = 0; j < k; j++) { n       long long mul = pover[(k - j) * (n - k + 1)]; n       ksum = (ksum + dt[0][j] * mul) % mod; n       lsum[1][j][k] = ksum; n     } n   } n   for (int i = 1; i <= K; i++) { n     int ci = i % 2; n     for (int j = 1; j <= n; j++) { n       for (int k = 1; k <= j; k++) { n         long long baseCnt = lsum[ci][k - 1][j]; n         long long tot = baseCnt * ipover[j - k + 1] % mod; n         dt[i][j] = (dt[i][j] + tot) % mod; n       } n     } n     int ni = 1 - i % 2; n     memset(lsum[ni], 0, sizeof(lsum[0])); n     for (int k = 0; k <= n; k++) { n       long long ksum = 0; n       for (int j = 0; j < k; j++) { n         long long mul = pover[(k - j) * (n - k + 1)]; n         ksum = (ksum + dt[i][j] * mul) % mod; n         lsum[ni][j][k] = ksum; n       } n     } n   } n   long long ans = 0; n   for (int i = 0; i <= n; i++) { n     ans += dt[K][i]; n     ans %= mod; n   } n   ans %= mod; n   printf( %d n , (int)ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int d[1005], s[1005], sufmax[1005], mxpos[1005], pred[1005]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n, k; n   cin >> n >> k; n   ++n; n   for (int i = 1; i < n; ++i) cin >> d[i]; n   for (int i = 1; i < n; ++i) cin >> s[i]; n   for (int i = n - 1; i >= 1; --i) { n     if (s[i] > sufmax[i + 1]) { n       mxpos[i] = i; n       sufmax[i] = s[i]; n     } else { n       mxpos[i] = mxpos[i + 1]; n       sufmax[i] = sufmax[i + 1]; n     } n   } n   for (int i = 1; i < n; ++i) pred[i] = pred[i - 1] + d[i]; n   int tott = 0, oil = s[1]; n   for (int i = 1; i < n;) { n     int j = i; n     do { n       oil -= d[j]; n       ++j; n       while (oil < 0) tott += k, oil += s[i]; n       oil += s[j]; n     } while (s[j] < s[i] && j < n); n     i = j; n   } n   cout << tott + pred[n - 1] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5e5 + 10, B = 1e6 + 3; n int n, m, p1[N][2], p2[N][2], x, y; n long long ans = 1; n int main() { n   scanf( %d%d n , &n, &m); n   char a[n + 3][m + 3]; n   for (int i = 0; i < n; ++i) gets(a[i]); n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) n       if (a[i][j] !=  . ) { n         x = (a[i][j] <  2 ) || (a[i][j] >  3 ); n         y = i % 2; n         p1[j][x ^ y] = 1; n         x = a[i][j] <  3 ; n         y = j % 2; n         p2[i][x ^ y] = 1; n       } n   } n   for (int i = 0; i < m; ++i) ans = (ans * (2 - p1[i][0] - p1[i][1])) % B; n   for (int i = 0; i < n; ++i) ans = (ans * (2 - p2[i][0] - p2[i][1])) % B; n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma GCC optimize( O3 ) n #pragma GCC target( avx,avx2,sse,sse2,sse3,sse4,popcnt,fma ) n #pragma GCC optimize( unroll-loops ) n const long long int MAXN = 2e5 + 5; n const long long int mod = 1000000007; n const long long int N = 200005; n void solve() { n   map<pair<int, int>, vector<int>> mpX, mpY; n   int n, m, k; n   cin >> n >> m >> k; n   vector<int> xec(n), yec(m); n   map<int, int> haveX, haveY; n   for (int i = 0; i < n; i++) { n     cin >> xec[i], haveX[xec[i]] += 1; n   } n   for (int i = 0; i < m; i++) { n     cin >> yec[i], haveY[yec[i]] += 1; n   } n   for (int i = 0; i < k; i++) { n     int x, y; n     cin >> x >> y; n     if (haveX[x] && haveY[y]) continue; n     if (haveX[x]) { n       int idx = lower_bound(yec.begin(), yec.end(), y) - yec.begin(); n       mpX[{yec[idx - 1], yec[idx]}].push_back(x); n     } n     if (haveY[y]) { n       int idx = lower_bound(xec.begin(), xec.end(), x) - xec.begin(); n       mpY[{xec[idx - 1], xec[idx]}].push_back(y); n     } n   } n   long long int ans = 0; n   for (auto [a, b] : mpX) { n     sort(b.begin(), b.end()); n     map<int, int> mpTemp; n     int total = b.size(); n     for (auto x : b) { n       mpTemp[x] += 1; n     } n     for (auto [c, d] : mpTemp) { n       ans += (long long int)d * (long long int)(total - d); n     } n   } n   for (auto [a, b] : mpY) { n     sort(b.begin(), b.end()); n     map<int, int> mpTemp; n     int total = b.size(); n     for (auto y : b) { n       mpTemp[y] += 1; n     } n     for (auto [c, d] : mpTemp) { n       ans += (long long int)d * (long long int)(total - d); n     } n   } n   cout << ans / 2ll <<   n ; n   return; n } n int main() { n   ios_base ::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int 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   while (t--) { n     int n, c0, c1, h; n     cin >> n >> c0 >> c1 >> h; n     string s; n     cin >> s; n     int o = 0, z = 0; n     for (int i = 0; i < n; i++) { n       if (s[i] ==  1 ) n         o++; n       else n         z++; n     } n     int ans = 0; n     if (c0 < c1) { n       if (c0 + h <= c1) n         ans = z * c0 + o * (c0 + h); n       else n         ans = z * c0 + o * c1; n     } else { n       if (c1 + h <= c0) n         ans = c1 * o + z * (c1 + h); n       else n         ans = c1 * o + c0 * z; n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( O3 ) n #pragma GCC optimize( O2 ) n #pragma GCC optimize( inline ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n const int INF = 1e9 + 7; n int n; n vector<int> G[55]; n double dp[55][55][55][55]; n int vis[55][55]; n double tmp[55][55]; n long long C[55][55]; n double cpro[55][55][55][55]; n void merge_dp(int asz, double a[][55], int bsz, double b[][55], n               double ret[][55]) { n   for (int i = 0; i <= asz + bsz; i++) n     for (int j = 0; j <= asz + bsz; j++) ret[i][j] = 0; n   for (int ia = 0; ia <= asz; ia++) n     for (int ja = 0; ja <= asz; ja++) n       for (int ib = 0; ib <= bsz; ib++) n         for (int jb = 0; jb <= bsz; jb++) { n           if (ia == 0 && ib == 0) { n             ret[ia + ib][0] = a[ia][0] * b[ib][0]; n             continue; n           } n           for (int jt = ja + jb; jt <= asz + bsz; jt++) n             ret[ia + ib][jt] += n                 a[ia][ja] * b[ib][jb] * n                 (cpro[jt][ja][asz][bsz] + cpro[jt][jb][bsz][asz]) / n                 C[asz + bsz][asz]; n         } n } n int dfs(int v, int par) { n   if (vis[v][par]) return vis[v][par]; n   int tsz = 0; n   dp[v][par][0][0] = 1.0; n   for (int i = 0; i < (int)(G[v].size()); i++) { n     int u = G[v][i]; n     if (u == par) continue; n     int csz = dfs(u, v); n     merge_dp(tsz, dp[v][par], csz, dp[u][v], tmp); n     tsz += csz; n     for (int j = 0; j <= tsz; j++) n       for (int k = 0; k <= tsz; k++) dp[v][par][j][k] = tmp[j][k]; n   } n   if (par > 0) { n     for (int i = 0; i <= tsz; i++) n       for (int j = 0; j <= tsz; j++) { n         tmp[i][j] = dp[v][par][i][j]; n         dp[v][par][i][j] *= 1 - 1.0 * j / (tsz + 1); n       } n     for (int i = 0; i <= tsz; i++) n       for (int j = 0; j <= tsz; j++) n         for (int k = j; k <= tsz; k++) n           dp[v][par][i + 1][k + 1] += tmp[i][j] * (1.0 / (tsz + 1)); n     tsz++; n   } n   return vis[v][par] = tsz; n } n double aa[55]; n double gen_ans(int v) { n   dfs(v, 0); n   memset(aa, 0, sizeof(aa)); n   for (int i = 0; i <= n; i++) n     for (int j = 0; j <= n; j++) aa[i] += dp[v][0][i][j]; n   for (int i = n; i >= 0; i--) n     for (int j = n; j > i; j--) aa[i] -= C[j][i] * aa[j]; n   double ret = 0.0, t = 1.0; n   for (int i = 0; i <= n; i++) { n     ret = ret + aa[i] * t; n     t *= 0.5; n   } n   return ret; n } n void init_C() { n   C[0][0] = 1; n   for (int i = 1; i <= (int)(n); i++) { n     C[i][0] = 1; n     for (int j = 1; j <= (int)(n); j++) C[i][j] = C[i - 1][j] + C[i - 1][j - 1]; n   } n   for (int a = 0; a <= n; a++) n     for (int b = 0; a + b <= n; b++) n       for (int ja = 0; ja <= a; ja++) n         for (int jt = ja; jt <= a + b; jt++) n           if (ja > 0) n             cpro[jt][ja][a][b] = C[jt - 1][ja - 1] * C[a + b - jt][a - ja]; n           else n             cpro[jt][ja][a][b] = 0; n } n int main() { n   scanf( %d , &n); n   init_C(); n   for (int i = 0; i < (int)(n - 1); i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     G[u].push_back(v); n     G[v].push_back(u); n   } n   for (int i = 1; i <= (int)(n); i++) printf( %.8lf n , gen_ans(i)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 500010; n int m, k, n, s, a[maxn], b[maxn], c[maxn], maxx, tong[maxn], ansl, ansr, n     vis[maxn]; n bool check(int l, int r) { n   memcpy(c, tong, sizeof(c)); n   for (int i = l; i <= r; i++) c[a[i]]--; n   for (int i = 1; i <= maxx; i++) n     if (c[i] > 0) { n       return false; n     } n   return true; n } n void gen(int l, int r) { n   int temp = l - (min(n - 1, (l - 1) / k) * k + 1); n   temp += max(0, r - l + 1 - k); n   if (temp <= m - n * k) { n     printf( %d n , temp); n     int num = 0; n     for (int i = min(n - 1, (l - 1) / k) * k + 1; i < l; i++) { n       printf( %d  , i); n       num++; n     } n     int num2 = 0; n     memset(c, 0, sizeof(c)); n     for (int i = l; i <= r; i++) n       if (c[a[i]] + 1 <= tong[a[i]]) { n         vis[i] = 1; n         c[a[i]]++; n         num2++; n       } n     num2 = r - l + 1 - num2; n     num += num2; n     for (int i = l; i <= r; i++) n       if (!vis[i] && num > temp) { n         num--; n         vis[i] = 1; n       } n     for (int i = l; i <= r; i++) n       if (!vis[i]) printf( %d  , i); n     exit(0); n   } n } n void solve(int x) { n   memset(c, 0, sizeof(c)); n   int cur = m; n   for (int i = x; i <= m; i++) c[a[i]]++; n   for (int i = x - 1; i >= 1; i--) { n     c[a[i]]++; n     while (cur > i) { n       if (c[a[cur]] - 1 >= tong[a[cur]] && n           c[a[cur - 1]] + 1 >= tong[a[cur - 1]]) { n         c[a[cur]]--; n         cur--; n       } else n         break; n     } n     gen(i, cur); n   } n } n int main() { n   scanf( %d%d%d%d , &m, &k, &n, &s); n   for (int i = 1; i <= m; i++) scanf( %d , &a[i]); n   for (int i = 1; i <= s; i++) { n     scanf( %d , &b[i]); n     maxx = max(maxx, b[i]); n     tong[b[i]]++; n   } n   int l = 1, r = m, res = 0; n   while (l <= r) { n     int mid = (l + r) >> 1; n     if (check(mid, m)) { n       res = mid; n       l = mid + 1; n     } else n       r = mid - 1; n   } n   if (res) { n     gen(res, m); n     solve(res); n     puts( -1 ); n   } else n     puts( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2005; n bool can = 1; n char arr[N][N]; n int n, m, vis[N][N], dp[N][N]; n bool valid(pair<int, int> a) { n   return min(a.first, a.second) > -1 && a.first < n && a.second < m && n          arr[a.first][a.second] !=  # ; n } n pair<int, int> get_next(pair<int, int> a) { n   if (arr[a.first][a.second] ==  < ) return {a.first, a.second - 1}; n   if (arr[a.first][a.second] ==  > ) return {a.first, a.second + 1}; n   if (arr[a.first][a.second] ==  ^ ) return {a.first - 1, a.second}; n   return {a.first + 1, a.second}; n } n void dfs(pair<int, int> u) { n   vis[u.first][u.second] = 1; n   pair<int, int> c = get_next(u); n   if (valid(c)) { n     if (vis[c.first][c.second] == 0) n       dfs(c); n     else if (vis[c.first][c.second] == 1) { n       can = 0; n       return; n     } n   } n   vis[u.first][u.second] = 2; n } n bool go(pair<int, int> u) { n   vis[u.first][u.second] = 1; n   pair<int, int> c = get_next(u); n   bool ret = 1; n   if (valid(c)) { n     if (vis[c.first][c.second] == 0) n       ret &= go(c); n     else n       ret = 0; n   } n   return ret; n } n int solve(pair<int, int> u) { n   if (!valid(u)) return 0; n   if (~dp[u.first][u.second]) return dp[u.first][u.second]; n   pair<int, int> c = get_next(u); n   return dp[u.first][u.second] = solve(c) + 1; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   memset(dp, -1, sizeof(dp)); n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < m; ++j) cin >> arr[i][j]; n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < m; ++j) n       if (!vis[i][j] && valid({i, j})) dfs({i, j}); n   if (can) { n     vector<pair<int, pair<int, int>>> v; n     for (int i = 0; i < n; ++i) n       for (int j = 0; j < m; ++j) v.push_back({solve({i, j}), {i, j}}); n     sort(v.rbegin(), v.rend()); n     if (v.size() == 1 || v[0].first == 0) n       cout << v[0].first; n     else { n       int ans1 = v[0].first, ans2 = v[0].first - 1; n       memset(vis, 0, sizeof(vis)); n       go(v[0].second); n       for (int i = 1; i < v.size(); ++i) { n         if (v[i].first < v[i - 1].first) break; n         if (go(v[i].second)) { n           ans2 = ans1; n           break; n         } n       } n       cout << ans1 + ans2; n     } n   } else n     cout << -1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1.01e9; n const double eps = 1e-9; n const int N = 1e5 + 10; n int t[N]; n int mem[N]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; (i) < (n); ++i) scanf( %d , &t[i]); n   int s = 0; n   for (int i = 0; (i) < (n); ++i) { n     int v = s + 20; n     if (i) { n       int l = lower_bound(t, t + i, t[i] - 90 + 1) - t; n       v = min(v, mem[l] + 50); n     } n     if (i) { n       int l = lower_bound(t, t + i, t[i] - 1440 + 1) - t; n       v = min(v, mem[l] + 120); n     } n     mem[i + 1] = v; n     printf( %d n , v - s); n     s = v; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x, y; n   scanf( %d %d , &x, &y); n   long long ans = 0; n   for (int val = 1; val <= x; ++val) { n     ans += (int)floor((y - (5 - (val % 5))) / 5.0) + 1; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double PI = 3.14159265359; n const long long MOD = (long long)1e9 + 7; n const long long MAXN = (long long)1e5 + 10; n const long long INF = (long long)9223372036854775; n const long double EPS = (long double)1e-8; n long long par[MAXN], sz[MAXN], ln[MAXN], pw[MAXN]; n pair<pair<long long, long long>, long long> a[MAXN]; n long long get_par(long long node) { n   if (node == par[node]) return node; n   par[node] = get_par(par[node]); n   return par[node]; n } n void merge(long long a, long long b) { n   long long x = get_par(a); n   long long y = get_par(b); n   if (x == y) return; n   ln[y] += ln[x]; n   sz[y] += sz[x]; n   par[x] = y; n } n bool CMPx(pair<pair<long long, long long>, long long> a, n           pair<pair<long long, long long>, long long> b) { n   return a.first.first < b.first.first; n } n bool CMPy(pair<pair<long long, long long>, long long> a, n           pair<pair<long long, long long>, long long> b) { n   return a.first.second < b.first.second; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   for (int i = 0; i < MAXN; i++) par[i] = i; n   pw[0] = 1; n   for (int i = 1; i < MAXN; i++) pw[i] = (pw[i - 1] * 2ll) % MOD; n   fill(sz, sz + MAXN, 1); n   long long n; n   scanf( %lld , &n); n   for (int i = 0; i < n; i++) { n     scanf( %lld%lld , &a[i].first.first, &a[i].first.second); n     a[i].second = i; n   } n   sort(a, a + n, CMPx); n   ln[get_par(a[0].second)]++; n   for (int i = 1; i < n; i++) { n     if (a[i].first.first == a[i - 1].first.first) { n       merge(a[i].second, a[i - 1].second); n     } else { n       ln[get_par(a[i].second)]++; n     } n   } n   sort(a, a + n, CMPy); n   ln[get_par(a[0].second)]++; n   for (int i = 1; i < n; i++) { n     if (a[i].first.second == a[i - 1].first.second) { n       merge(a[i].second, a[i - 1].second); n     } else { n       ln[get_par(a[i].second)]++; n     } n   } n   long long ans = 1; n   for (int i = 0; i < n; i++) { n     if (par[i] == i) { n       if (ln[i] <= sz[i]) { n         ans *= pw[ln[i]]; n       } else { n         ans *= (pw[ln[i]] - 1); n       } n       ans %= MOD; n     } n   } n   printf( %lld , ans); n   return 0; n } n