#include <bits/stdc++.h> n using namespace std; n using ll = long long; n void dout() { cerr << endl; } n template <typename Head, typename... Tail> n void dout(Head H, Tail... T) { n   cerr << H <<    ; n   dout(T...); n } n mt19937 rnd(time(0)); n struct Node { n   Node* left = nullptr; n   Node* right = nullptr; n   int prior; n   int size = 1; n   double val; n   double sleft; n   double sright; n   double sum; n   double mss; n   Node(double v) n       : prior(rnd()), n         val(v), n         sleft(max(0.0, v)), n         sright(max(0.0, v)), n         sum(v), n         mss(max(0.0, v)) {} n }; n int _size(Node* n) { return n ? n->size : 0; } n double _sleft(Node* n) { return n ? n->sleft : 0; } n double _sright(Node* n) { return n ? n->sright : 0; } n double _sum(Node* n) { return n ? n->sum : 0; } n double _mss(Node* n) { return n ? n->mss : 0; } n void update(Node* n) { n   n->size = _size(n->left) + _size(n->right) + 1; n   n->sum = _sum(n->left) + _sum(n->right) + n->val; n   n->sleft = max(_sleft(n->left), _sum(n->left) + n->val + _sleft(n->right)); n   n->sright = n       max(_sright(n->right), _sum(n->right) + n->val + _sright(n->left)); n   n->mss = max({_mss(n->left), _mss(n->right), n                 _sright(n->left) + n->val + _sleft(n->right)}); n } n struct Treap { n   Node* root = nullptr; n   pair<Node*, Node*> split(Node* n, int index) { n     if (!n) return make_pair(nullptr, nullptr); n     int sz = _size(n->left) + 1; n     if (index < sz) { n       auto [l, r] = split(n->left, index); n       n->left = r; n       update(n); n       return make_pair(l, n); n     } else { n       auto [l, r] = split(n->right, index - sz); n       n->right = l; n       update(n); n       return make_pair(n, r); n     } n   } n   Node* merge(Node* l, Node* r) { n     if (!l || !r) return l ? l : r; n     if (l->prior > r->prior) { n       l->right = merge(l->right, r); n       update(l); n       return l; n     } else { n       r->left = merge(l, r->left); n       update(r); n       return r; n     } n   } n   void push_back(double v) { root = merge(root, new Node(v)); } n   double max_subarray_sum(int left, int right) { n     auto [x, r] = split(root, right); n     auto [l, m] = split(x, left); n     double ans = _mss(m); n     root = merge(l, merge(m, r)); n     return ans; n   } n }; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int n, m, c; n   cin >> n >> m >> c; n   vector<double> x(n); n   for (int i = 0; i < n; i++) { n     cin >> x[i]; n   } n   vector<double> p(n); n   for (int i = 1; i < n; i++) { n     cin >> p[i]; n     p[i] /= 100.0; n   } n   Treap treap; n   treap.push_back(0); n   for (int i = 1; i < n; i++) { n     treap.push_back((x[i] - x[i - 1]) * 0.5 - p[i] * c); n   } n   double ans = 0.0; n   for (int i = 0; i < m; i++) { n     int l, r; n     cin >> l >> r; n     ans += treap.max_subarray_sum(l, r); n   } n   cout << fixed << setprecision(9) << ans; n   return 0; n } n


#include <bits/stdc++.h> n int k, i, n, t; n int main() { n   std::cin >> t; n   for (; t; i++) { n     k = i; n     n = 0; n     while (k) { n       n += k % 10; n       k /= 10; n     } n     if (n == 10) t--; n   } n   std::cout << i - 1; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-10; n const int inf = 0x3f3f3f3f; n const long long INF = 1e18; n const int maxn = 200000 + 10; n const int maxm = 1000000000 + 7; n const int mod = 1000000000 + 7; n int gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n inline long long read() { n   char ch = getchar(); n   long long x = 0, f = 1; n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while ( 0  <= ch && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n int n, m; n long long a[maxn]; n long long num[maxn]; n int main() { n   int T = read(); n   while (T--) { n     n = read(); n     for (int i = 1; i <= n; ++i) a[i] = read(), num[i] = 0; n     m = read(); n     for (int i = 1; i <= m; ++i) { n       long long x = read(), y = read(); n       num[y] = max(num[y], x); n     } n     for (int i = n - 1; i >= 1; --i) { n       num[i] = max(num[i], num[i + 1]); n     } n     bool ok = true; n     int ans = 1; n     int pos = 1; n     long long maxx = 0; n     for (int i = 1; i <= n; ++i) { n       maxx = max(maxx, a[i]); n       int len = i - pos + 1; n       if (num[len] < maxx) { n         ans++; n         pos = i; n         maxx = a[i]; n       } n       if (num[1] < a[i]) ok = false; n     } n     if (ok) n       printf( %d n , ans); n     else n       puts( -1 ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long a[5005]; n long long dp[5005], mod = 998244353, bnd[5005], fac[5005], inv[5005]; n long long qpow(long long a, long long b) { n   long long ans = 1; n   while (b) { n     if (b & 1) ans = ans * a % mod; n     b >>= 1; n     a = a * a % mod; n   } n   return ans; n } n int main() { n   int T = 1; n   while (T--) { n     int n; n     cin >> n; n     fac[0] = inv[0] = 1; n     for (int i = 1; i <= n; i++) n       scanf( %lld , &a[i]), fac[i] = fac[i - 1] * i % mod, n                             inv[i] = qpow(fac[i], mod - 2); n     sort(a + 1, a + n + 1); n     if (a[n - 1] * 2LL > a[n]) { n       puts( 0 ); n       continue; n     } n     for (int i = 1; i <= n; i++) n       for (int j = 1; j < i; j++) n         if (a[j] * 2 <= a[i]) bnd[i]++; n     for (int i = 1; i <= n; i++) n       for (int j = 0; j <= bnd[i]; j++) { n         if (j == 0) n           dp[i] += fac[n - 1] * inv[n - 1 - bnd[i]] % mod; n         else n           dp[i] += dp[j] * fac[n - bnd[j] - 2] % mod * n                    inv[n - bnd[j] - 2 - (bnd[i] - bnd[j] - 1)] % mod, n               dp[i] %= mod; n       } n     printf( %lld n , dp[n]); n   } n   return 0; n } n


#include <bits/stdc++.h> n bool debug = 1; n const long long MOD = 1000000007; n const double PI = acos(-1.0); n const double eps = 1e-9; n using namespace std; n int main() { n   int n, m; n   int c[100100], a[100100]; n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     scanf( %d , &c[i]); n   } n   for (int i = 0; i < m; i++) { n     scanf( %d , &a[i]); n   } n   int j = 0; n   for (int i = 0; i < n; i++) { n     if (j < m and c[i] <= a[j]) j++; n   } n   cout << j << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double eps = 1e-10; n int n, q, t; n double plc[500005], ans[500005]; n struct Point { n   long double x, y; n   Point() {} n   Point(long double _x, long double _y) { x = _x, y = _y; } n   Point operator+(Point p) { return Point(x + p.x, y + p.y); } n } P[500005], Q[500005]; n struct Node { n   long double x, m, c; n   int d; n   Node() {} n   Node(long double _x, long double _m, long double _c, int _d) { n     x = _x, m = _m, c = _c, d = _d; n   } n   bool operator<(const Node &p) const { return x < p.x; } n } V[500005]; n void Add(Point a, Point b, int v) { n   if (abs(b.x - a.x) < eps) return; n   if (a.x > b.x) { n     swap(a, b); n     v *= -1; n   } n   long double m = (b.y - a.y) / (b.x - a.x), c = a.y - a.x * m; n   V[++t] = Node(a.x, v * m, v * c, 0); n   V[++t] = Node(b.x, -v * m, -v * c, 0); n   return; n } n Point Calc(Point a, Point b, Point p) { n   return Point((b.x - a.x) * (p.y - a.y) / (b.y - a.y) + a.x, p.y); n } n int main() { n   scanf( %d%d , &n, &q); n   int p = 0; n   for (int i = 0; i < n; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     P[i] = Point(x, y); n     if (P[i].y < P[p].y) p = i; n   } n   for (int i = 1; i <= q; i++) { n     double x; n     scanf( %lf , &x); n     plc[i] = x; n     V[i] = Node(x, -1, -1, i); n   } n   t = q; n   long double all = 0; n   for (int i = 0; i < n; i++) { n     all += P[i].x * P[(i + 1) % n].y - P[(i + 1) % n].x * P[i].y; n     if (P[i].y < P[(i + 1) % n].y) n       Add(P[i], P[(i + 1) % n], -1); n     else n       Add(P[(i + 1) % n], P[i], -1); n   } n   all = abs(all / 2); n   int s = 0; n   for (int i = p; i < n; i++) Q[s++] = P[i]; n   for (int i = 0; i < p; i++) Q[s++] = P[i]; n   for (int i = 0; i < n; i++) P[i] = Q[i]; n   int lf = 0, rg = 0; n   Point lst = P[0]; n   for (int i = 0; i < n - 1; i++) { n     int L = (lf + 1) % n, R = (rg + n - 1) % n; n     Point now; n     if (P[L].y < P[R].y) { n       Point tmp = Calc(P[rg], P[R], P[L]) + P[L]; n       now.x = tmp.x * 0.5, now.y = tmp.y * 0.5; n       lf = L; n     } else { n       Point tmp = Calc(P[lf], P[L], P[R]) + P[R]; n       now.x = tmp.x * 0.5; n       now.y = tmp.y * 0.5; n       rg = R; n     } n     Add(lst, now, 2); n     lst = now; n   } n   sort(V + 1, V + t + 1); n   long double a = 0.0, b = 0.0; n   for (int i = 1; i <= t; i++) { n     long double x = V[i].x, m = V[i].m, c = V[i].c; n     if (V[i].d > 0) n       ans[V[i].d] = all + (0.5 * a * x * x + b * x); n     else { n       all -= 0.5 * m * x * x + c * x; n       a += m, b += c; n     } n   } n   for (int i = 1; i <= q; i++) printf( %.10lf n , (double)ans[i]); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2000020; n pair<int, int> a[N], b[N]; n bool comp(int x, int y) { return a[x].second > a[y].second; } n int n, m, K; n vector<int> A[N], B[N]; n int g[4 * N]; n bool t[4 * N]; n long long T[4 * N]; n set<pair<int, int> > S; n set<pair<int, int> >::iterator it; n int sum(int v, int tl, int tr, int x) { n   if (tl > x || tr <= x) return 0; n   if (tl == tr - 1) return g[v]; n   int xy, yy; n   xy = sum(v + v, tl, tl + tr >> 1, x); n   yy = sum(v + v + 1, tl + tr >> 1, tr, x); n   return max(xy, yy) + g[v]; n } n void add(int v, int tl, int tr, int l, int r, int x) { n   if (tl >= r || tr <= l) return; n   if (l <= tl && tr <= r) { n     g[v] += x; n     return; n   } n   add(v + v, tl, tl + tr >> 1, l, r, x); n   add(v + v + 1, tl + tr >> 1, tr, l, r, x); n } n void upd1(int v) { n   if (t[v]) { n     T[v + v] = T[v + v + 1] = T[v]; n     t[v + v + 1] = t[v + v] = t[v]; n     t[v] = false; n   } n } n void update(int v, int tl, int tr, int l, int r, long long x) { n   if (tl >= r || tr <= l) return; n   upd1(v); n   if (l <= tl && tr <= r) { n     T[v] = x; n     t[v] = true; n     return; n   } n   update(v + v, tl, tl + tr >> 1, l, r, x); n   update(v + v + 1, tl + tr >> 1, tr, l, r, x); n   T[v] = (T[v + v] + T[v + v + 1]) % 1000000007ll; n } n long long get(int v, int tl, int tr, int l, int r) { n   if (tl >= r || tr <= l) return 0; n   upd1(v); n   if (l <= tl && tr <= r) return T[v]; n   long long x, y; n   x = get(v + v, tl, tl + tr >> 1, l, r); n   y = get(v + v + 1, tl + tr >> 1, tr, l, r); n   T[v] = (T[v + v] + T[v + v + 1]) % 1000000007ll; n   return (x + y) % 1000000007ll; n } n int main() { n   scanf( %d %d %d , &m, &n, &K); n   for (int i = 0; i < K; ++i) { n     scanf( %d %d , &b[i].first, &a[i].first); n     scanf( %d %d , &b[i].second, &a[i].second); n     A[b[i].first].push_back(i); n     B[b[i].second + 1].push_back(i); n   } n   update(1, 1, n + 1, 1, 2, 1); n   B[1].push_back(K); n   a[K].second = n; n   a[K].first = 1; n   S.insert(make_pair(a[K].second, K)); n   add(1, 1, n + 1, 1, n + 1, 1); n   for (int k = 1; k <= m; ++k) { n     sort(A[k].begin(), A[k].end(), comp); n     for (int i = 0; i < A[k].size(); ++i) { n       int v = A[k][i]; n       int s = sum(1, 1, n + 1, a[v].second + 1); n       if (s == 0) { n         it = S.lower_bound(make_pair(a[v].second + 1, 0)); n         int l = 0; n         if (it != S.begin()) { n           it--; n           l = (*it).first; n         } n         long long now = get(1, 1, n + 1, l + 1, a[v].second + 2); n         now %= 1000000007ll; n         update(1, 1, n + 1, a[v].second + 1, a[v].second + 2, now); n       } n       S.insert(make_pair(a[v].second, v)); n       add(1, 1, n + 1, a[v].first, a[v].second + 1, 1); n       update(1, 1, n + 1, a[v].first, a[v].second + 1, 0); n     } n     for (int i = 0; i < B[k].size(); ++i) { n       int v = B[k][i]; n       S.erase(make_pair(a[v].second, v)); n       add(1, 1, n + 1, a[v].first, a[v].second + 1, -1); n     } n   } n   it = S.lower_bound(make_pair(n, 0)); n   int l = 0; n   if (it != S.begin()) { n     it--; n     l = (*it).first; n   } n   long long answer = get(1, 1, n + 1, l + 1, n + 1) % 1000000007ll; n   printf( %I64d n , answer); n } n


#include <bits/stdc++.h> n using namespace std; n int const N = 22, M = 1 << 22; n inline int nextInt() { n   char c; n   c = getchar(); n   while (c !=  -  && (c <  0  || c >  9 )) c = getchar(); n   int n = 0, s = 1; n   if (c ==  - ) s = -1, c = getchar(); n   while (c >=  0  && c <=  9 ) n *= 10, n += c -  0 , c = getchar(); n   return n * s; n } n int mx; n int parents[M]; n int Find(int a) { return parents[a] < 0 ? a : parents[a] = Find(parents[a]); } n void Union(int a, int b) { n   a = Find(a), b = Find(b); n   if (a == b) return; n   if (parents[a] < parents[b]) n     parents[a] += parents[b], parents[b] = a; n   else n     parents[b] += parents[a], parents[a] = b; n } n void init() { memset(parents, (0xff), sizeof parents); } n int q[M]; n bool ck[M]; n int vis[M]; n int n, m; n queue<int> que; n void upd(int t) { n   if (vis[t] != -1) return; n   while (!que.empty()) que.pop(); n   que.push(t); n   vis[t] = t; n   while (!que.empty()) { n     int x = que.front(); n     que.pop(); n     if (ck[x]) Union(t, ((1 << n) - 1) ^ x); n     for (int j = 0; j < (n); ++j) n       if ((x >> j & 1) == 0) { n         int u = x ^ (1 << j); n         if (ck[u]) Union(t, ((1 << n) - 1) ^ u); n         if (vis[u] == -1) { n           vis[u] = t; n           que.push(u); n         } n       } n   } n } n int main() { n   n = nextInt(); n   m = nextInt(); n   for (int i = 0; i < (m); ++i) q[i] = nextInt(); n   init(); n   int mask = (1 << n) - 1; n   memset(vis, (0xff), sizeof vis); n   for (int i = 0; i < (m); ++i) { n     int t = q[i]; n     if (vis[mask ^ t] != -1) { n       Union(t, vis[mask ^ t]); n     } n     upd(t); n     ck[mask ^ t] = 1; n   } n   int ans = 0; n   for (int i = 0; i < (m); ++i) n     if (q[i] == Find(q[i])) ++ans; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   char ar[100]; n   int len, count = 0, i, j; n   gets(ar); n   len = strlen(ar); n   if (isupper(ar[0]) && islower(ar[1])) { n     cout << ar; n   } else { n     for (i = 0; ar[i] !=   0 ; i++) { n       if (isupper(ar[i])) { n         count++; n       } n     } n     if (len == 1) { n       if (islower(ar[0])) { n         ar[0] = toupper(ar[0]); n       } else if (isupper(ar[0])) { n         ar[0] = tolower(ar[0]); n       } n     } else if (count == len) { n       for (i = 0; ar[i] !=   0 ; i++) { n         ar[i] = tolower(ar[i]); n       } n     } else if (count == len - 1) { n       if (islower(ar[0])) { n         for (i = 1; ar[i] !=   0 ; i++) { n           ar[i] = tolower(ar[i]); n           ar[0] = toupper(ar[0]); n         } n       } n     } n     cout << ar; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100000 + 10; n const long long CONST = 314000000LL; n const long long inf = (1LL << 60); n bool mark[MAXN], INF[MAXN], bad[MAXN]; n int m, n, cntComp; n long long cnt[MAXN], func[MAXN], deg[MAXN], comp[MAXN], type[MAXN], len[MAXN]; n long long mini[MAXN], maxi[MAXN]; n vector<int> topol; n vector<int> adj[MAXN], bak[MAXN], Q[MAXN]; n struct cmp { n   inline bool operator()(const int &A, const int &B) { n     return (mini[A] != mini[B]) ? (mini[A] < mini[B]) : (A < B); n   } n }; n inline void dfs(int v) { n   if (mini[v] == inf) return; n   mark[v] = true; n   for (int i = 0; i < (int)adj[v].size(); i++) n     if (!mark[adj[v][i]] && mini[adj[v][i]] != inf) dfs(adj[v][i]); n   topol.push_back(v); n } n inline void DFS(int v) { n   if (mini[v] == inf) return; n   mark[v] = true; n   comp[v] = cntComp; n   for (int i = 0; i < (int)bak[v].size(); i++) n     if (!mark[bak[v][i]] && mini[bak[v][i]] != inf) DFS(bak[v][i]); n } n inline bool cmp2(const int &A, const int &B) { n   return comp[type[A]] > comp[type[B]]; n } n int main() { n   cin >> m >> n; n   for (int i = 0; i < m; i++) { n     cin >> type[i] >> len[i]; n     type[i]--; n     for (int j = 0; j < len[i]; j++) { n       int temp; n       cin >> temp; n       if (temp == -1) n         deg[i]++, func[i]++; n       else { n         temp--; n         Q[i].push_back(temp); n         bak[temp].push_back(i); n         cnt[i]++; n       } n     } n   } n   for (int i = 0; i < n; i++) mini[i] = inf; n   set<int, cmp> SET; n   for (int i = 0; i < m; i++) n     if (cnt[i] == 0) { n       if (deg[i] < mini[type[i]]) { n         SET.erase(type[i]); n         mini[type[i]] = deg[i]; n         SET.insert(type[i]); n       } n     } n   while (!SET.empty()) { n     int begin = *SET.begin(); n     SET.erase(SET.begin()); n     for (int i = 0; i < (int)bak[begin].size(); i++) { n       int temp = bak[begin][i]; n       cnt[temp]--; n       deg[temp] = min(CONST, deg[temp] + mini[begin]); n       if (cnt[temp] == 0) { n         if (deg[temp] < mini[type[temp]]) { n           SET.erase(type[temp]); n           mini[type[temp]] = deg[temp]; n           SET.insert(type[temp]); n         } n       } n     } n   } n   for (int i = 0; i < n; i++) adj[i].clear(), bak[i].clear(); n   for (int i = 0; i < m; i++) n     if (mini[type[i]] != inf) { n       bad[i] = false; n       for (int j = 0; j < (int)Q[i].size(); j++) n         if (mini[Q[i][j]] == inf) bad[i] = true; n       if (!bad[i]) { n         for (int j = 0; j < (int)Q[i].size(); j++) { n           adj[type[i]].push_back(Q[i][j]); n           bak[Q[i][j]].push_back(type[i]); n         } n       } n     } n   for (int i = 0; i < n; i++) n     if (!mark[i]) dfs(i); n   memset(mark, false, sizeof mark); n   for (int i = (int)topol.size() - 1; i >= 0; i--) n     if (!mark[topol[i]]) { n       cntComp++; n       DFS(topol[i]); n     } n   vector<int> perm; n   for (int i = 0; i < m; i++) perm.push_back(i); n   sort(perm.begin(), perm.end(), cmp2); n   for (int o = 0; o < m; o++) n     if (!bad[perm[o]]) { n       int index = perm[o]; n       long long sum = min(CONST, func[index]); n       for (int j = 0; j < (int)Q[index].size(); j++) { n         int temp = Q[index][j]; n         if (comp[temp] == comp[type[index]]) n           INF[comp[type[index]]] = true; n         else if (INF[comp[temp]]) n           INF[comp[type[index]]] = true; n         else n           sum = min(CONST, sum + maxi[temp]); n       } n       maxi[type[index]] = max(maxi[type[index]], sum); n     } n   for (int i = 0; i < n; i++) { n     if (mini[i] == inf) { n       cout << -1 <<     << -1 << endl; n       continue; n     } n     cout << min(CONST, mini[i]) <<    ; n     if (INF[comp[i]]) n       cout << -2 << endl; n     else n       cout << min(CONST, maxi[i]) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   stack<int> s1; n   int ans = 0; n   int x = 1; n   for (int i = 0; i < (2 * n); i++) { n     char s[10]; n     scanf( %s , s); n     if (strlen(s) == 3) { n       int a; n       scanf( %d , &a); n       s1.push(a); n     } else { n       if (strlen(s) == 6 && !s1.empty() && s1.top() != x) { n         while (!s1.empty()) s1.pop(); n         ans++; n       } else { n         if (!s1.empty()) s1.pop(); n       } n       x++; n     } n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int data[(int)2e5]; n int dp[5001][5001]; n int used[5001][5001]; n string s; n int magic(int l, int r) { n   if (l > r) return 1; n   if (used[l][r] != -1) return used[l][r]; n   if (l == r) { n     data[1]++; n     return used[l][r] = 1; n   } n   int lk, rk, k, flag = 1, middle = (l + r) / 2; n   lk = magic(l, (r - l) % 2 == 0 ? (middle - 1) : middle); n   rk = magic(middle + 1, r); n   k = min(lk, rk) + 1; n   if (s[l] == s[r] and magic(l + 1, r - 1)) { n     for (int i = 1; i <= k; i++) data[i]++; n     return used[l][r] = k; n   } n   return used[l][r] = 0; n } n int main() { n   memset(used, -1, sizeof(used)); n   cin >> s; n   int n = s.size() - 1; n   for (int i = 0; i <= n; i++) { n     for (int j = i; j <= n; j++) magic(i, j); n   } n   for (int i = 1; i <= s.size(); i++) cout << data[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int x, y, a, b, r, m, t, pr; n int poc, kraj, uk; n int drvo[2000], sveca[2000]; n void apdejt(int a, int b) { n   while (a <= 2000) { n     drvo[a] += b; n     a += (a & -a); n   } n } n int koliko(int a) { n   int zbir = 0; n   while (a > 0) { n     zbir += drvo[a]; n     a -= (a & -a); n   } n   return zbir; n } n void solve() { n   cin >> m >> t >> r; n   uk = 0; n   for (int i = 0; i < m; i++) { n     cin >> a; n     a += 500; n     if (koliko(a) >= r) continue; n     kraj = r - koliko(a); n     for (int j = 0; j < kraj; j++) { n       x = -1; n       for (int z = a - 1; z >= a - t; z--) { n         if (sveca[z] == 0) { n           sveca[z] = 1; n           uk++; n           apdejt(z, 1); n           apdejt(z + t + 1, -1); n           x = 1; n           break; n         } n       } n       if (x == -1) { n         cout <<  -1  << endl; n         return; n       } n     } n   } n   cout << (uk) << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   int t; n   t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   cout << s; n   for (int i = s.size() - 1; i >= 0; i--) { n     cout << s[i]; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5e5 + 5; n struct edge { n   int u, v, w, num; n } e[N], c[N]; n map<long long, int> mp; n int n, m, q, s, siz[N], fa[N]; n long long L[N], R[N]; n bool vis[N]; n int find(int x) { return fa[x] ? fa[x] = find(fa[x]) : x; } n bool comp(edge x, edge y) { return x.w < y.w; } n int main() { n   int i, j, k, x, num; n   scanf( %d%d , &n, &m); n   for (i = 1; i <= m; i++) { n     scanf( %d%d%d , &c[i].u, &c[i].v, &c[i].w); n     c[i].num = i; n   } n   sort(c + 1, c + 1 + m, comp); n   for (i = 1; i <= m; i++) siz[c[i].num] = i; n   for (i = 1; i <= m; i = j + 1) { n     for (j = i; j < m && c[j + 1].w == c[i].w; j++) n       ; n     for (k = i; k <= j; k++) n       L[c[k].num] = 1LL * c[k].w * m + find(c[k].u), n       R[c[k].num] = 1LL * c[k].w * m + find(c[k].v); n     for (k = i; k <= j; k++) n       if (find(c[k].u) != find(c[k].v)) fa[find(c[k].u)] = find(c[k].v); n   } n   memset(fa, 0, sizeof(fa)); n   scanf( %d , &q); n   for (i = 1; i <= q; i++) { n     scanf( %d , &s); n     mp.clear(); n     bool flag = true; n     num = 0; n     for (j = 1; j <= s; j++) { n       scanf( %d , &x); n       if (!mp[L[x]]) fa[mp[L[x]] = ++num] = 0; n       if (!mp[R[x]]) fa[mp[R[x]] = ++num] = 0; n       if (find(mp[L[x]]) == find(mp[R[x]])) n         flag = 0; n       else n         fa[find(mp[L[x]])] = find(mp[R[x]]); n     } n     puts(flag ?  YES  :  NO ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 2e9; n const int sz = 3; n const double eps = 1e-9; n const int maxn = 1e3 + 500, base = 1e9 + 7, maxm = 10; n string second[maxn]; n int main() { n   ios_base::sync_with_stdio(0); n   ; n   cin.tie(0); n   int n; n   cin >> n; n   if (n == 1) { n     cout << 6 << endl; n     return 0; n   } n   int k = inf; n   for (int i = 0; i < n; i++) cin >> second[i]; n   for (int i = 0; i < n; i++) n     for (int j = i + 1; j < n; j++) { n       int eq = 0; n       for (int b = 0; b < 6; b++) n         if (second[i][b] == second[j][b]) eq++; n       if (eq == 0 || eq == 1) k = min(k, 2); n       if (eq == 3 || eq == 2) k = min(k, 1); n       if (eq >= 4) k = min(k, 0); n     } n   cout << k; n } n


#include <bits/stdc++.h> n const long base = 151; n const long long MM = 1ll * 1000000007 * 1000000007; n using namespace std; n int BIT(int i, long long x) { return (x & (1 << i)); } n long long ONBIT(int i, long long x) { return (x | (1 << i)); } n long long OFFBIT(int i, long long x) { return (x & ~(1 << i)); } n long long FLIPBIT(int i, long long x) { return (x ^ (1 << i)); } n long long NUMBIT(long long x) { return __builtin_popcount(x); } n template <class T> n T GCD(T a, T b) { n   T r; n   while (b != 0) { n     r = a % b; n     a = b; n     b = r; n   } n   return a; n } n template <class T> n T LCM(T a, T b) { n   return a / GCD(a, b) * b; n } n void read() { n   int x, y, u, v; n   long long ans = 1; n   cin >> x >> y >> u >> v; n   int s1 = u - x; n   int s2 = v - y; n   long long tmp = min(s1, s2) - 1; n   ans += (tmp + 1) * (abs(s2 - s1) + 1); n   ans += (tmp + 1) * tmp; n   cout << ans << endl; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   long te; n   cin >> te; n   while (te--) read(); n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-9; n const double pi = 3.1415926535897932384626; n const double e = exp(1.0); n int main() { n   int t; n   double a, b, c; n   double x, y, z; n   double s; n   while (~scanf( %lf , &s)) { n     scanf( %lf%lf%lf , &a, &b, &c); n     double tt = a + b + c; n     if (tt == 0) { n       x = y = 0; n       z = s; n     } else { n       x = s * (a * 1.0 / tt); n       y = s * (b * 1.0 / tt); n       z = s * (c * 1.0 / tt); n     } n     printf( %.10lf %.10lf %.10lf n , x, y, z); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline T gcd(T a, T b) { n   while (b) { n     a %= b; n     swap(a, b); n   } n   return a; n } n template <class T> n inline T lcm(T a, T b) { n   return a / gcd(a, b) * b; n } n inline int nxt() { n   int wow; n   scanf( %d , &wow); n   return wow; n } n inline long long int lxt() { n   long long int wow; n   scanf( %lld , &wow); n   return wow; n } n inline double dxt() { n   double wow; n   scanf( %lf , &wow); n   return wow; n } n int main() { n   int n = nxt(), a[100]; n   for (int i = 1; i <= n; i++) a[i] = nxt(); n   if (a[n] == 15) { n     puts( DOWN ); n     return 0; n   } n   if (a[n] == 0) { n     puts( UP ); n     return 0; n   } n   if (n == 1) { n     puts( -1 ); n     return 0; n   } n   if (a[n] > a[n - 1]) n     puts( UP ); n   else n     puts( DOWN ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long RAND(long long n) { return abs((rand() << 15) + rand()) % n; } n bool check(int i, int j, int n) { n   return ((i >= 0) && (j >= 0) && (i < n) && (j < n)); n } n int move_x[] = {1, 0}; n int move_y[] = {0, 1}; n vector<vector<vector<vector<bool>>>> solve(vector<vector<int>> &a) { n   int n = a.size(); n   vector<vector<vector<vector<bool>>>> ans( n       n, vector<vector<vector<bool>>>( n              n, vector<vector<bool>>(n, vector<bool>(n, false)))); n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < n; ++j) { n       ans[i][j][i][j] = true; n     } n   } n   for (int len = 1; len <= 2 * n - 2; ++len) { n     for (int i = 0; i < n; ++i) { n       for (int j = 0; j < n; ++j) { n         for (int x = 0; x <= len; ++x) { n           int k = i + x, t = j + len - x; n           if (!check(k, t, n) || a[i][j] != a[k][t]) { n             continue; n           } n           if ((abs(k - i) + abs(t - j)) == 1) { n             ans[i][j][k][t] = true; n             continue; n           } n           for (int i1 = 0; i1 < 2; ++i1) { n             for (int i2 = 0; i2 < 2; ++i2) { n               int next_x = i + move_x[i1], next_y = j + move_y[i1]; n               int prev_x = k - move_x[i2], prev_y = t - move_y[i2]; n               if (!check(next_x, next_y, n) || !check(prev_x, prev_y, n)) { n                 continue; n               } n               if (next_x > prev_x || next_y > prev_y) { n                 continue; n               } n               if (ans[next_x][next_y][prev_x][prev_y]) { n                 ans[i][j][k][t] = ans[next_x][next_y][prev_x][prev_y]; n               } n             } n           } n         } n       } n     } n   } n   return ans; n } n int query(int i, int j, int t, int k) { n   i++; n   j++; n   t++; n   k++; n   cout <<  ?   << i <<     << j <<     << t <<     << k << endl << flush; n   int ans; n   cin >> ans; n   if (ans == -1) { n     exit(0); n   } n   return !ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   int n; n   cin >> n; n   vector<vector<int>> a(n, vector<int>(n, 0)); n   a[0][0] = 1; n   a[n - 1][n - 1] = 0; n   for (int i = 2; i < n; ++i) { n     a[0][i] = a[0][i - 2] ^ query(0, i - 2, 0, i); n   } n   a[1][0] = a[0][1] ^ query(0, 1, 1, 2) ^ query(1, 0, 1, 2); n   for (int i = 2; i < n; ++i) { n     a[i][0] = a[i - 2][0] ^ query(i - 2, 0, i, 0); n   } n   for (int i = 1; i < n; ++i) { n     for (int j = 1; j < n; ++j) { n       a[i][j] = a[i - 1][j - 1] ^ query(i - 1, j - 1, i, j); n     } n   } n   vector<vector<int>> b = a; n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < n; ++j) { n       if ((i + j) % 2 == 1) { n         b[i][j] = 1 - a[i][j]; n       } n     } n   } n   vector<vector<vector<vector<bool>>>> A = solve(a); n   vector<vector<vector<vector<bool>>>> B = solve(b); n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < n; ++j) { n       for (int k = i; k < n; ++k) { n         for (int t = j; t < n; ++t) { n           if ((abs(k - i) + abs(t - j)) < 2) { n             continue; n           } n           if (A[i][j][k][t] ^ B[i][j][k][t]) { n             if (!query(i, j, k, t) == A[i][j][k][t]) { n               cout <<  ! n ; n               for (int i = 0; i < n; ++i) { n                 for (int j = 0; j < n; ++j) { n                   cout << a[i][j]; n                 } n                 cout << endl; n               } n               return 0; n             } else { n               swap(a, b); n               cout <<  ! n ; n               for (int i = 0; i < n; ++i) { n                 for (int j = 0; j < n; ++j) { n                   cout << a[i][j]; n                 } n                 cout << endl; n               } n               return 0; n             } n           } n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int d, n; n   cin >> d >> n; n   vector<int> a(n); n   for (int i = 0; i < n; i++) cin >> a[i]; n   int day = 0, res = 0; n   for (int i = 0; i < n; i++) { n     day = (day + a[i] - 1) % d + 1; n     if (day != a[i]) { n       if (day < a[i]) n         res += a[i] - day; n       else n         res += d - day + a[i]; n       day = a[i]; n     } n   } n   cout << res; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline void umax(T &a, T b) { n   if (a < b) a = b; n } n template <class T> n inline void umin(T &a, T b) { n   if (a > b) a = b; n } n template <class T> n inline T abs(T a) { n   return a > 0 ? a : -a; n } n template <class T> n inline T gcd(T a, T b) { n   return __gcd(a, b); n } n template <class T> n inline T lcm(T a, T b) { n   return a / gcd(a, b) * b; n } n const int inf = 1e9 + 143; n const long long longinf = 1e18 + 143; n inline int read() { n   int x; n   scanf(  %d , &x); n   return x; n } n const int N = 1e6 + 100; n int p[N], sz[N]; n int get(int x) { n   if (x == p[x]) return x; n   return p[x] = get(p[x]); n } n int main() { n   int n = read(); n   int m = read(); n   int mod = read(); n   for (int i = 1; i <= n; i++) p[i] = i; n   for (int i = 1; i <= m; i++) { n     int a = read(); n     int b = read(); n     a = get(a); n     b = get(b); n     if (a != b) { n       p[a] = b; n     } n   } n   vector<int> trees; n   for (int i = 1; i <= n; i++) { n     sz[get(i)] += 1; n   } n   for (int i = 1; i <= n; i++) { n     if (i == get(i)) { n       trees.push_back(sz[i]); n     } n   } n   if (trees.size() == 1) { n     printf( %d n , 1 % mod); n     return 0; n   } n   int res = 1; n   for (int i = 1; i <= (int)trees.size() - 2; i++) n     res = (long long)res * n % mod; n   for (int i = 0; i < trees.size(); i++) res = (long long)res * trees[i] % mod; n   printf( %d n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int modular(long long int n, long long int pow, long long int N) { n   long long int res = 1; n   while (pow) { n     if (pow & 1) res = (res % N * n % N) % N; n     n = (n % N * n % N) % N; n     pow = pow / 2; n   } n   return res; n } n long long int d, x, y; n void extendedEuclid(long long int A, long long int B) { n   if (B == 0) { n     d = A; n     x = 1; n     y = 0; n   } else { n     extendedEuclid(B, A % B); n     long long int temp = x; n     x = y; n     y = temp - (A / B) * y; n   } n } n long long int modInverse(long long int A, long long int N) { n   extendedEuclid(A, N); n   return (x % N + N) % N; n } n int main() { n   long long int n, i; n   cin >> n; n   vector<pair<long long int, long long int>> v; n   for (i = 0; i < n; i++) { n     long long int x, y; n     cin >> x >> y; n     v.push_back({x, y}); n   } n   long long int ans = min(v[n - 1].first, v[n - 1].second); n   long long int flag = 0; n   for (i = n - 2; i >= 0; i--) { n     if (v[i].second >= ans && v[i].first >= ans) n       ans = min(v[i].second, v[i].first); n     else if (v[i].second >= ans) n       ans = v[i].second; n     else if (v[i].first >= ans) n       ans = ans = v[i].first; n     else { n       flag = 1; n       break; n     } n   } n   if (flag == 1) n     cout <<  NO  << endl; n   else n     cout <<  YES  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100010; n int n, m; n int head[N], nxt[N * 2], to[N * 2], tot; n int vis[N], stp[N]; n int dp[N][20]; n int dfn[N], low[N], dep = 0; n int stk[N * 5], top = 0; n int belong[N], block = 0; n int odd[N], col[N]; n void init() { n   memset(head, -1, sizeof(head)); n   tot = 0; n } n void add(int x, int y) { n   to[tot] = y; n   nxt[tot] = head[x]; n   head[x] = tot++; n } n void DFS_st(int u, int fa) { n   vis[u] = 1; n   stp[u] = stp[fa] + 1; n   dp[u][0] = fa; n   for (int i = 1; i < 20; i++) dp[u][i] = dp[dp[u][i - 1]][i - 1]; n   for (int i = head[u]; ~i; i = nxt[i]) { n     int v = to[i]; n     if (!vis[v]) DFS_st(v, u); n   } n } n void tarjan(int u, int fa) { n   dfn[u] = low[u] = ++dep; n   stk[top++] = u; n   vis[u] = 1; n   for (int i = head[u]; ~i; i = nxt[i]) { n     int v = to[i]; n     if (v == fa) continue; n     if (!dfn[v]) { n       tarjan(v, u); n       low[u] = min(low[u], low[v]); n     } else if (vis[v]) n       low[u] = min(low[u], dfn[v]); n   } n   if (low[u] == dfn[u]) { n     block++; n     do { n       top--; n       belong[stk[top]] = block; n       vis[stk[top]] = 0; n     } while (stk[top] != u); n   } n } n void DFS(int u, int fa) { n   vis[u] = 1; n   for (int i = head[u]; ~i; i = nxt[i]) { n     int v = to[i]; n     if (!vis[v]) { n       col[v] += col[u]; n       DFS(v, u); n     } n   } n } n int LCA(int x, int y) { n   if (stp[x] < stp[y]) swap(x, y); n   int delta = stp[x] - stp[y]; n   for (int i = 0; i < 20; i++) n     if (delta & (1 << i)) x = dp[x][i]; n   if (x == y) return x; n   for (int i = 19; i >= 0; i--) n     if (dp[x][i] != dp[y][i]) x = dp[x][i], y = dp[y][i]; n   return dp[x][0]; n } n int main() { n   init(); n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     add(x, y); n     add(y, x); n   } n   for (int u = 1; u <= n; u++) n     if (!vis[u]) DFS_st(u, 0); n   memset(vis, 0, sizeof(vis)); n   for (int u = 1; u <= n; u++) n     if (!dfn[u]) tarjan(u, 0); n   for (int u = 1; u <= n; u++) { n     if (!odd[belong[u]]) { n       for (int i = head[u]; ~i; i = nxt[i]) { n         int v = to[i]; n         if ((stp[u] + stp[v]) % 2 == 0 && belong[v] == belong[u]) { n           odd[belong[u]] = 1; n           break; n         } n       } n     } n   } n   for (int u = 1; u <= n; u++) n     if (belong[u] == belong[dp[u][0]] && dp[u][0] != 0 && odd[belong[u]]) n       col[u]++; n   memset(vis, 0, sizeof(vis)); n   for (int u = 1; u <= n; u++) n     if (!vis[u]) DFS(u, 0); n   int q; n   scanf( %d , &q); n   while (q--) { n     int u, v; n     scanf( %d%d , &u, &v); n     int lca = LCA(u, v); n     if (lca == 0) { n       printf( No n ); n     } else if ((stp[u] + stp[v] - stp[lca] * 2) % 2 == 1) n       printf( Yes n ); n     else { n       if (col[u] + col[v] != col[lca] * 2) n         printf( Yes n ); n       else n         printf( No n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double p[8][10020]; n int main() { n   int n; n   int l[8], r[8]; n   scanf( %d , &n); n   double ex = 0; n   double all = 1.0; n   for (int i = 0; i < n; i++) { n     scanf( %d %d , &l[i], &r[i]); n     all *= (r[i] - l[i] + 1); n   } n   for (int i = 1; i <= 10000; ++i) { n     double cr = 0; n     for (int j = 0; j < n; ++j) { n       if (r[j] < i || l[j] > i) continue; n       for (int k = 0; k < n; ++k) { n         if (k == j) continue; n         double t = 1.0; n         if (k < j) { n           if (r[k] < i) continue; n           t *= (r[k] - max(i, l[k]) + 1); n         } else { n           if (r[k] <= i) continue; n           t *= (r[k] - max(i + 1, l[k]) + 1); n         } n         for (int s = 0; s < n; ++s) { n           if (s == j || s == k) continue; n           if (s < j) { n             if (l[s] >= i) { n               t = 0; n               break; n             } n             t *= (min(r[s], i - 1) - l[s] + 1); n           } else { n             if (l[s] > i) { n               t = 0; n               break; n             } n             t *= (min(r[s], i) - l[s] + 1); n           } n         } n         if (t != 0) { n         } n         cr += t; n       } n     } n     ex += cr / all * i; n   } n   printf( %.15lf n , ex); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int a, int b) { n   if (a < b) swap(a, b); n   if (b == 0) return a; n   return gcd(b, a % b); n } n int main() { n   int n, m; n   cin >> n >> m; n   int a0, b0, x; n   for (int i = 0; i < n + 1; i++) { n     cin >> x; n     if (!i) a0 = x; n   } n   for (int i = 0; i < m + 1; i++) { n     cin >> x; n     if (!i) b0 = x; n   } n   if (n > m) { n     int sign; n     if (a0 < 0 && b0 > 0 || a0 > 0 && b0 < 0) cout <<  - ; n     cout <<  Infinity n ; n   } else if (n < m) { n     cout <<  0/1 n ; n   } else { n     int sign; n     if (a0 < 0 && b0 < 0 || a0 > 0 && b0 > 0) n       sign = 1; n     else n       sign = -1; n     a0 = abs(a0); n     b0 = abs(b0); n     int g = gcd(a0, b0); n     a0 /= g; n     b0 /= g; n     a0 *= sign; n     cout << a0 <<  /  << b0 <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long dp[200000][3]; n string s; n signed main() { n   cin.tie(0); n   cout.tie(0); n   ios_base::sync_with_stdio(false); n   cin >> s; n   long long l = s.size(); n   vector<vector<bool> > in(l, vector<bool>(3)); n   dp[0][0] = dp[0][1] = dp[0][2] = 10000000000; n   if ((s[0] -  0 ) % 3 == 0) { n     dp[0][0] = 0; n     in[0][0] = 1; n   } else { n     long long d = (s[0] -  0 ) % 3; n     dp[0][d] = 0; n     in[0][d] = 1; n     dp[0][0] = 1; n   } n   for (long long i = 1; i < l; i++) { n     long long d = (s[i] -  0 ) % 3; n     for (long long j = 0; j < 3; j++) { n       if (s[i] !=  0 ) n         dp[i][j] = min(dp[i - 1][(j + 3 - d) % 3], dp[i - 1][j] + 1), n         in[i][j] = (dp[i][j] != dp[i - 1][j] + 1); n       else { n         dp[i][j] = dp[i - 1][j] + (dp[i - 1][j] == i); n         in[i][j] = (dp[i - 1][j] != i); n       } n     } n   } n   if (dp[l - 1][0] == l) { n     for (long long i = 0; i < l; i++) { n       if (s[i] ==  0 ) return cout <<  0 n , 0; n     } n     return cout << -1, 0; n   } n   string ans =   ; n   long long sm = 0; n   for (long long i = l - 1; i >= 0; i--) { n     if (in[i][sm]) { n       ans += s[i]; n       sm += 3 - (s[i] -  0 ) % 3; n       sm %= 3; n     } n   } n   reverse(ans.begin(), ans.end()); n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const int MX = 2e5 + 1; n bool sieve[MX], in_graph[MX], vstd[MX]; n vector<int> pos[MX], adj[MX]; n int mu[MX]; n ll res[MX]; n void init() { n   vector<int> primes; n   mu[1] = 1; n   for (int i = 2; i < MX; ++i) { n     if (!sieve[i]) { n       mu[i] = -1; n       primes.push_back(i); n     } n     for (auto j : primes) { n       if (i * j >= MX) break; n       sieve[i * j] = true; n       if (i % j == 0) { n         mu[i * j] = 0; n         break; n       } n       mu[i * j] = -mu[i]; n     } n   } n } n int dfs(int u, int p) { n   int res = 1; n   vstd[u] = true; n   for (auto c : adj[u]) { n     if (c == p || !in_graph[c]) continue; n     res += dfs(c, u); n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   init(); n   int n; n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     int a; n     cin >> a; n     pos[a].push_back(i); n   } n   for (int i = 0; i < n - 1; ++i) { n     int u, v; n     cin >> u >> v; n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   for (int i = 1; i < MX; ++i) { n     for (int j = i; j < MX; j += i) { n       for (auto k : pos[j]) { n         in_graph[k] = true; n       } n     } n     for (int j = i; j < MX; j += i) { n       for (auto k : pos[j]) { n         if (!vstd[k]) { n           ll cnt = dfs(k, 0); n           res[i] += cnt * (cnt + 1) / 2; n         } n       } n     } n     for (int j = i; j < MX; j += i) { n       for (auto k : pos[j]) { n         in_graph[k] = false; n         vstd[k] = false; n       } n     } n   } n   for (int i = 1; i < MX; ++i) { n     ll ans = 0; n     for (int j = 1; j * i < MX; ++j) { n       ans += mu[j] * res[j * i]; n     } n     if (ans) { n       cout << i <<     << ans <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, low, high, chs; n long long x1up, x2up, x1down, x2down, y1down, y2down, y1up, y2up; n int query(long long x, long long y, long long xx, long long yy) { n   cout <<  ?   << x <<     << y <<     << xx <<     << yy << endl; n   cout << flush; n   int res; n   cin >> res; n   return res; n } n int query2(long long x, long long y, long long xx, long long yy) { n   int res = query(x, y, xx, yy); n   if (x <= x1down && y <= y1down && xx >= x1up && yy >= y1up) res--; n   return res; n } n int main() { n   cin >> n; n   low = 1; n   high = n; n   while (low < high) { n     chs = (low + high) / 2; n     int res = query(1, 1, n, chs); n     if (res == 0) n       low = chs + 1; n     else n       high = chs; n   } n   y1up = low; n   low = 1; n   high = n; n   while (low < high) { n     chs = (low + high) / 2; n     int res = query(1, 1, chs, y1up); n     if (res == 0) n       low = chs + 1; n     else n       high = chs; n   } n   x1up = low; n   low = 1; n   high = x1up; n   while (low <= high) { n     chs = (low + high) / 2; n     int res = query(chs, 1, x1up, y1up); n     if (res != 0) { n       low = chs + 1; n       x1down = chs; n     } else n       high = chs - 1; n   } n   low = 1; n   high = y1up; n   while (low <= high) { n     chs = (low + high) / 2; n     int res = query(x1down, chs, x1up, y1up); n     if (res != 0) { n       low = chs + 1; n       y1down = chs; n     } else n       high = chs - 1; n   } n   low = 1; n   high = n; n   while (low < high) { n     chs = (low + high) / 2; n     int res = query2(1, 1, n, chs); n     if (res == 0) n       low = chs + 1; n     else n       high = chs; n   } n   y2up = low; n   low = 1; n   high = n; n   while (low < high) { n     chs = (low + high) / 2; n     int res = query2(1, 1, chs, y2up); n     if (res == 0) n       low = chs + 1; n     else n       high = chs; n   } n   x2up = low; n   low = 1; n   high = x2up; n   while (low <= high) { n     chs = (low + high) / 2; n     int res = query2(chs, 1, x2up, y2up); n     if (res != 0) { n       low = chs + 1; n       x2down = chs; n     } else n       high = chs - 1; n   } n   low = 1; n   high = y2up; n   while (low <= high) { n     chs = (low + high) / 2; n     int res = query2(x2down, chs, x2up, y2up); n     if (res != 0) { n       low = chs + 1; n       y2down = chs; n     } else n       high = chs - 1; n   } n   cout <<  !   << x1down <<     << y1down <<     << x1up <<     << y1up <<     n        << x2down <<     << y2down <<     << x2up <<     << y2up << endl; n   cout << flush; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int MOD = 998244353; n const long long int INF = 3e18; n long long int power(long long int base, long long int exp) { n   long long int res = 1; n   while (exp > 0) { n     if (exp % 2 == 1) res = (res * base); n     base = (base * base); n     exp /= 2; n   } n   return res; n } n long long int bitc(long long int n, long long int x) { return ((n >> x) & 1); } n long long int __gcd(long long int a, long long int b) { n   return b == 0 ? a : __gcd(b, a % b); n } n long long int fsub(long long int a, long long int b, long long int p = MOD) { n   return ((a % p) - (b % p) + p) % p; n } n long long int fmult(long long int a, long long int b, long long int p = MOD) { n   return ((((a % p) * (b % p)) % p) + p) % p; n } n long long int fadd(long long int a, long long int b, long long int p = MOD) { n   return ((a % p + b % p) % p + p) % p; n } n long long int fpow(long long int n, long long int k, long long int p = MOD) { n   long long int r = 1; n   while (k > 0) { n     if (k & 1) r = r * n % p; n     n = n * n % p; n     k = k >> 1; n   } n   return r; n } n long long int inv(long long int a, long long int p = MOD) { n   return fpow(a, p - 2, p); n } n long long int fdiv(long long int a, long long int b, long long int p = MOD) { n   long long int yinv = inv(b); n   long long int ans = (a * yinv) % p; n   return ((ans) % p + p) % p; n } n long long int ceil(long long int a, long long int b) { n   return ceil((long double)a / b); n } n template <typename T> n istream &operator>>(istream &in, vector<T> &a) { n   for (auto &item : a) { n     in >> item; n   } n   return in; n } n template <typename T, typename U> n ostream &operator<<(ostream &out, pair<T, U> &a) { n   cout << a.first <<     << a.second; n   return out; n } n template <typename T, typename U> n istream &operator>>(istream &out, pair<T, U> &a) { n   cin >> a.first >> a.second; n   return out; n } n template <typename T, typename U> n ostream &operator<<(ostream &out, map<T, U> &a) { n   for (auto &item : a) { n     out << item <<   n ; n   } n   return out; n } n template <typename T> n ostream &operator<<(ostream &out, vector<T> &a) { n   for (auto &item : a) { n     out << item <<    ; n   } n   return out; n } n template <typename T> n ostream &operator<<(ostream &out, vector<vector<T>> &a) { n   for (auto &item : a) { n     out << item <<   n ; n   } n   return out; n } n template <int D, typename T> n struct Vec : public vector<Vec<D - 1, T>> { n   static_assert(D >= 1,  Vector dimension must be greater than zero! ); n   template <typename... Args> n   Vec(int n = 0, Args... args) n       : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {} n }; n template <typename T> n struct Vec<1, T> : public vector<T> { n   Vec(int n = 0, T val = T()) : vector<T>(n, val) {} n }; n std::vector<bool> is_prime; n std::vector<long long int> primes; n void sieve(long long int n) { n   is_prime.resize(n + 2, true); n   primes.clear(); n   long long int p; n   for (p = 2; p * p <= n; p++) { n     if (is_prime[p]) { n       long long int i; n       for (i = p * p; i <= n; i += p) { n         is_prime[i] = false; n       } n     } n   } n   is_prime[0] = is_prime[1] = false; n   long long int i; n   for (i = 2; i <= n; i++) { n     if (is_prime[i]) { n       primes.emplace_back(i); n     } n   } n } n map<long long int, long long int> prime_factors(long long int n) { n   map<long long int, long long int> s; n   long long int i; n   long long int tc = 0; n   while (n % 2 == 0) { n     tc++; n     n /= 2; n   } n   if (tc > 0) { n     s[2] = tc; n   } n   for (i = 3; i <= sqrt(n); i += 2) { n     tc = 0; n     while (n % i == 0) { n       tc++; n       n /= i; n     } n     if (tc > 0) { n       s[i] = tc; n     } n   } n   if (n > 2) { n     s[n] += 1; n   } n   return s; n } n std::vector<long long int> fact_vec; n void fact_fun(long long int n) { n   fact_vec.resize(n + 10); n   long long int i; n   fact_vec[0] = 1; n   for (i = 1; i <= n + 2; i++) { n     fact_vec[i] = (fact_vec[i - 1] * i) % MOD; n   } n } n std::vector<long long int> p2; n void power_2(long long int n, long long int m = MOD) { n   long long int i; n   p2.emplace_back(1); n   for (i = 0; i < n; i++) { n     p2.emplace_back(fmult(p2.back(), 2)); n   } n } n long long int ncr(long long int n, long long int r) { n   if (r > n) return 0; n   return fdiv(fact_vec[n], fmult(fact_vec[r], fact_vec[n - r])); n } n std::vector<long long int> spf; n void sieve2(long long int MAXN) { n   MAXN += 10; n   spf.resize(MAXN, 0); n   spf[1] = 1; n   for (long long int i = 2; i < MAXN; i++) spf[i] = i; n   for (long long int i = 4; i < MAXN; i += 2) spf[i] = 2; n   for (long long int i = 3; i * i < MAXN; i++) { n     if (spf[i] == i) { n       for (long long int j = i * i; j < MAXN; j += i) { n         if (spf[j] == j) spf[j] = i; n       } n     } n   } n } n const int mi[4] = {-1, 0, 1, 0}, mj[4] = {0, 1, 0, -1}; n const int d8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, n           d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1}; n map<long long int, long long int> getFactorization(long long int x) { n   map<long long int, long long int> ret; n   while (x != 1) { n     ret[spf[x]]++; n     x = x / spf[x]; n   } n   return ret; n } n class Sol { n  public: n   Sol() { long long int i, j; } n }; n int main() { n   long long int i, j; n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long int ti; n   ti = 1; n   while (ti--) { n     long long int n; n     cin >> n; n     std::vector<long long int> v(n * 2); n     cin >> v; n     sort((v).begin(), (v).end()); n     fact_fun(3e5 + 3); n     long long int tp = ncr(2 * n, n); n     long long int f = 0; n     long long int s = 0; n     for (i = 0; i < n; i++) { n       f += v[i]; n     } n     for (i = n; i < 2 * n; i++) { n       s += v[i]; n     } n     s -= f; n     tp = fmult(s, tp); n     cout << tp <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, t, prindex, k, kingdom, ki, prince; n   cin >> t; n   for (int h = 0; h < t; h++) { n     cin >> n; n     vector<int> vec(n + 7, 0); n     prindex = 0, k, kingdom, ki, prince = 1; n     for (int i = 1; i <= n; i++) { n       cin >> k; n       ki = 0; n       for (int j = 0; j < k; j++) { n         cin >> kingdom; n         if (ki == 0 and vec[kingdom] == 0) { n           vec[kingdom]++; n           ki++; n         } n       } n       if (ki == 0) prindex = i; n     } n     for (int i = 1; i <= n and vec[i] != 0; i++) prince = i + 1; n     if (prindex > 0) n       cout <<  IMPROVE  n            <<   n  n            << prindex <<     << prince <<   n ; n     else n       cout <<  OPTIMAL  n            <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int const maxn = (int)2e6 + 1, inf = (int)2e9 + 1; n map<char, int> pidr; n int n, m, ans, cur, sz, a[maxn], b, l[maxn], r[maxn], x[maxn]; n bool used[maxn]; n int main() { n   cin >> n >> m; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= m; i++) { n     cin >> l[i] >> r[i] >> x[i]; n   } n   for (int i = 1; i <= m; i++) { n     cur = 0; n     for (int j = l[i]; j <= r[i]; j++) n       if (a[j] < a[x[i]]) cur++; n     if (l[i] + cur == x[i]) n       cout <<  Yes  << endl; n     else n       cout <<  No  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e18 + 7; n const long double EPS = 1e-8; n const long long MAXI = 20000; n const long long MOD = 16714589; n const long long MAXST = 2000000; n const long double PI = 3.14159265358979323; n ostream &operator<<(ostream &stream, const pair<long long, long long> &p) { n   stream << p.first <<     << p.second <<    ; n   return stream; n } n bool u[30]; n signed main() { n   { n     ios_base::sync_with_stdio(0); n     cin.tie(0); n     cout << fixed << setprecision(10); n     cerr << fixed << setprecision(10); n   }; n   long long n, m; n   cin >> m >> n; n   for (long long i = 0; i < n; i++) { n     cout << m <<   n ; n     cout.flush(); n     long long x; n     cin >> x; n     if (x == 0 || x == -2) n       exit(0); n     else if (x == 1) n       u[i] = true; n     else n       u[i] = false; n   } n   long long left = 1, right = m; n   for (long long i = 0; left < right - 1; i++) { n     long long mid = (left + right) / 2; n     cout << mid <<   n ; n     cout.flush(); n     long long x; n     cin >> x; n     if (x == 0 || x == -2) exit(0); n     if (u[i % n]) { n       if (x == 1) n         right = mid; n       else n         left = mid; n     } else { n       if (x == 1) n         left = mid; n       else n         right = mid; n     } n   } n   cout << left <<   n ; n   cout.flush(); n   long long x; n   cin >> x; n   if (x == 0 || x == -2) exit(0); n   cout << right <<   n ; n   cout.flush(); n   cin >> x; n   if (x == 0 || x == -2) exit(0); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool asdfill[1100000]; n int main() { n   int n; n   cin >> n; n   int last_known; n   for (int i = 0; i < (n); ++i) { n     int a; n     cin >> a; n     asdfill[a] = true; n     last_known = a; n   } n   double min_alpha = 10; n   double max_alpha = 1e200; n   int fills_done = 1; n   for (int p = 1;; ++p) { n     double alpha = (p * 10 + 10.0) / fills_done; n     if (p <= last_known) { n       if (asdfill[p]) { n         max_alpha = min(max_alpha, alpha); n         ++fills_done; n       } else { n         min_alpha = max(min_alpha, alpha); n       } n     } else { n       if (max_alpha <= alpha + 1e-8) { n         cout <<  unique n  << p; n         exit(0); n       } else if (min_alpha <= alpha - 1e-8) { n         cout <<  not unique ; n         exit(0); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 5 * 100 * 1000 + 14; n vector<int> comp[MAXN], adj[MAXN]; n set<int> res; n int ans = 0; n void dfs(int v) { n   comp[ans].push_back(v); n   auto it = res.begin(); n   while (it != res.end()) { n     if (find(adj[v].begin(), adj[v].end(), *it) == adj[v].end()) { n       int u = *it; n       res.erase(u); n       dfs(u); n       it = res.upper_bound(u); n     } else n       it++; n   } n   return; n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   int n, m; n   cin >> n >> m; n   while (m--) { n     int u, v; n     cin >> u >> v; n     adj[v].push_back(u); n     adj[u].push_back(v); n   } n   for (int i = 1; i <= n; i++) res.insert(i); n   while (!res.empty()) { n     int v = *res.begin(); n     res.erase(v); n     ans++; n     dfs(v); n   } n   cout << ans <<   n ; n   for (int i = 1; i <= ans; i++) { n     cout << comp[i].size() <<    ; n     for (auto u : comp[i]) cout << u <<    ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n; n   cin >> n; n   vector<long long int> v; n   for (int i = 0; i < n; i++) { n     long long int x; n     cin >> x; n     v.push_back(x); n   } n   if (n > 1) { n     cout <<  1 1  << endl; n     cout << (long long int)(-1) * v[0] << endl; n     cout <<  1   << n << endl; n     cout <<  0  ; n     for (int i = 1; i < n; i++) { n       cout << (long long int)(-1) * n * v[i] <<    ; n     } n     cout << endl; n     cout <<  2   << n << endl; n     for (int i = 1; i < n; i++) { n       cout << (long long int)(n - 1) * v[i] <<    ; n     } n     cout << endl; n   } else { n     cout <<  1 1  << endl; n     cout << (-1) * v[0] << endl; n     cout <<  1 1  << endl; n     cout << 0 << endl; n     cout <<  1 1  << endl; n     cout << 0 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int LIM = 200100; n int main() { n   ios_base::sync_with_stdio(false); n   int n; n   cin >> n; n   vector<int> a(n); n   int mini, maxi; n   mini = 1e9 + 3; n   maxi = 0; n   for (auto &e : a) { n     cin >> e; n     mini = min(mini, e); n     maxi = max(maxi, e); n   } n   cout << maxi - mini + 1 - n << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9 + 10; n int n, a, b; n int main() { n   cin >> n >> a >> b; n   int table1_count = 0; n   int table2_count = 0; n   int one_two_count = 0; n   int ans = 0; n   for (int i = 0; i < n; i++) { n     int t; n     cin >> t; n     if (t == 1) { n       bool is_sit = false; n       if (table1_count < a) { n         table1_count++; n         is_sit = true; n       } n       if (!is_sit) { n         if (table2_count < b) { n           table2_count++; n           one_two_count++; n           is_sit = true; n         } n       } n       if (!is_sit) { n         if (one_two_count > 0) { n           one_two_count--; n           is_sit = true; n         } n       } n       if (!is_sit) { n         ans++; n       } n     } else { n       if (table2_count < b) { n         table2_count++; n       } else { n         ans += 2; n       } n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   vector<bool> x; n   vector<bool> y; n   x.assign(n + 1, 1); n   y.assign(n + 1, 1); n   x[1] = 0; n   y[1] = 0; n   x[n] = 0; n   y[n] = 0; n   for (int i = 0; i < m; i++) { n     int tmp_x, tmp_y; n     scanf( %i %i , &tmp_x, &tmp_y); n     x[tmp_x] = 0; n     y[tmp_y] = 0; n   } n   int result = 0; n   for (int i = 1; i <= n / 2; i++) { n     if (i * 2 != n + 1) { n       if (x[i] == 1) result++; n       if (x[n - i + 1] == 1) result++; n       if (y[i] == 1) result++; n       if (y[n - i + 1] == 1) result++; n     } n   } n   if (n % 2 == 1) n     if ((x[n / 2 + 1] == 1) || (y[n / 2 + 1] == 1)) result++; n   cout << result << endl; n   return 0; n } n


#include <bits/stdc++.h> n struct val { n   long long x; n   int y, d; n   val *p, *l, *r; n } g1[100001], g2[100001], *rt1[100001], *rt2[100001], *nil = g1; n struct node { n   long long x; n   int y; n   bool operator<(const node &b) const { return x < b.x; } n } a[100001]; n struct vale { n   long long x; n   int y; n   bool operator<(const vale &b) const { return x > b.x; } n } c[100001]; n using namespace std; n int n, g[100001], h[100001], fa[100001], d[100001], wt, ss[19]; n char fl[1 << 23], *A = fl; n long long f[100001], e[100001], b[100001]; n void read(int &x) { n   char c; n   for (x = 0;  0  > (c = *A++) || c >  9 ;) n     ; n   while ( 0  <= c && c <=  9 ) x = (x << 3) + (x << 1) + c - 48, (c = *A++); n } n void read(long long &x) { n   char c; n   for (x = 0;  0  > (c = *A++) || c >  9 ;) n     ; n   while ( 0  <= c && c <=  9 ) x = (x << 3) + (x << 1) + c - 48, (c = *A++); n } n void print(long long x) { n   if (!x) n     putchar(48); n   else { n     for (wt = 0; x; ss[++wt] = x % 10, x /= 10) n       ; n     for (; wt; putchar(ss[wt--] + 48)) n       ; n   } n } n val *mg1(val *x, val *y) { n   return x == nil n              ? y n              : (y == nil n                     ? x n                     : (x->x < y->x n                            ? ((x->r = mg1(x->r, y))->p = x, n                               x->l->d < x->r->d ? (swap(x->l, x->r), 0) : 0, n                               x->d = x->l->d + 1, x) n                            : ((y->r = mg1(y->r, x))->p = y, n                               y->l->d < y->r->d ? (swap(y->l, y->r), 0) : 0, n                               y->d = y->l->d + 1, y))); n } n val *mg2(val *x, val *y) { n   return x == nil n              ? y n              : (y == nil n                     ? x n                     : (x->x > y->x n                            ? ((x->r = mg2(x->r, y))->p = x, n                               x->l->d < x->r->d ? (swap(x->l, x->r), 0) : 0, n                               x->d = x->l->d + 1, x) n                            : ((y->r = mg2(y->r, x))->p = y, n                               y->l->d < y->r->d ? (swap(y->l, y->r), 0) : 0, n                               y->d = y->l->d + 1, y))); n } n void fix_min(long long t1, int z) { n   int tmp, x, LIA; n   if (a[x = g[z]].x != t1) n     if (a[x].x = t1, x > 1 && a[x] < a[x >> 1]) n       for (; x > 1 && a[x] < a[x >> 1]; n            swap(a[x], a[x >> 1]), swap(g[a[x].y], g[a[x >> 1].y]), x >>= 1) n         ; n     else n       for (; (x << 1) <= n;) { n         if (a[tmp = x << 1] < a[LIA = x]) LIA = tmp; n         if ((tmp |= 1) <= n && a[tmp] < a[LIA]) LIA = tmp; n         if (LIA != x) n           swap(a[LIA], a[x]), swap(g[a[LIA].y], g[a[x].y]), x = LIA; n         else n           break; n       } n } n void fix_max(long long t1, int z) { n   int tmp, x, LIA; n   if (c[x = h[z]].x != t1) n     if (c[x].x = t1, x > 1 && c[x] < c[x >> 1]) n       for (; x > 1 && c[x] < c[x >> 1]; n            swap(c[x], c[x >> 1]), swap(h[c[x].y], h[c[x >> 1].y]), x >>= 1) n         ; n     else n       for (; (x << 1) <= n;) { n         if (c[tmp = x << 1] < c[LIA = x]) LIA = tmp; n         if ((tmp |= 1) <= n && c[tmp] < c[LIA]) LIA = tmp; n         if (LIA != x) n           swap(c[LIA], c[x]), swap(h[c[LIA].y], h[c[x].y]), x = LIA; n         else n           break; n       } n } n void fix(int x) { n   if (g1[x].p == nil) n     (rt1[fa[x]] = mg1(g1[x].l, g1[x].r))->p = nil; n   else if (g1[x].p->l == &g1[x]) n     (g1[x].p->l = mg1(g1[x].l, g1[x].r))->p = g1[x].p; n   else n     (g1[x].p->r = mg1(g1[x].l, g1[x].r))->p = g1[x].p; n   g1[x].x = f[x], g1[x].l = g1[x].r = nil, n   (rt1[fa[x]] = mg1(rt1[fa[x]], &g1[x]))->p = nil; n   if (g2[x].p == nil) n     (rt2[fa[x]] = mg2(g2[x].l, g2[x].r))->p = nil; n   else if (g2[x].p->l == &g2[x]) n     (g2[x].p->l = mg2(g2[x].l, g2[x].r))->p = g2[x].p; n   else n     (g2[x].p->r = mg2(g2[x].l, g2[x].r))->p = g2[x].p; n   g2[x].x = f[x], g2[x].l = g2[x].r = nil, n   (rt2[fa[x]] = mg2(rt2[fa[x]], &g2[x]))->p = nil; n } n void alter(int z, int x, int y, int LAx, int LAy) { n   long long t1 = e[x], t3 = e[y]; n   int t2 = b[x] % d[x], t4 = b[y] % d[y]; n   f[y] += b[y] % (++d[y]) + e[z] - t4, e[y] = b[y] / d[y], f[LAy] += e[y] - t3, n                                        f[y] += e[y] - t3; n   f[x] += b[x] % (--d[x]) - e[z] - t2, e[x] = b[x] / d[x], f[LAx] += e[x] - t1, n                                        f[x] += e[x] - t1; n   if (e[y] != t3) fix(LAy); n   if (e[x] != t1 && LAx != LAy) fix(LAx); n   fix(x), fix(y); n   if (g1[z].p == nil) n     (rt1[x] = mg1(g1[z].l, g1[z].r))->p = nil; n   else if (g1[z].p->l == &g1[z]) n     (g1[z].p->l = mg1(g1[z].l, g1[z].r))->p = g1[z].p; n   else n     (g1[z].p->r = mg1(g1[z].l, g1[z].r))->p = g1[z].p; n   g1[z].x = f[z], g1[z].l = g1[z].r = nil, n   (rt1[fa[z] = y] = mg1(rt1[y], &g1[z]))->p = nil; n   if (g2[z].p == nil) n     (rt2[x] = mg2(g2[z].l, g2[z].r))->p = nil; n   else if (g2[z].p->l == &g2[z]) n     (g2[z].p->l = mg2(g2[z].l, g2[z].r))->p = g2[z].p; n   else n     (g2[z].p->r = mg2(g2[z].l, g2[z].r))->p = g2[z].p; n   g2[z].x = f[z], g2[z].l = g2[z].r = nil, n   (rt2[y] = mg2(rt2[y], &g2[z]))->p = nil; n   fix_max(e[fa[LAx]] + f[LAx], LAx); n   fix_max(e[fa[LAy]] + f[LAy], LAy); n   fix_max(rt2[LAx]->x + e[LAx], rt2[LAx]->y); n   fix_max(rt2[LAy]->x + e[LAy], rt2[LAy]->y); n   if (rt2[x] != nil) fix_max(rt2[x]->x + e[x], rt2[x]->y); n   fix_max(rt2[y]->x + e[y], rt2[y]->y); n   fix_min(e[fa[LAx]] + f[LAx], LAx); n   fix_min(e[fa[LAy]] + f[LAy], LAy); n   fix_min(rt1[LAx]->x + e[LAx], rt1[LAx]->y); n   fix_min(rt1[LAy]->x + e[LAy], rt1[LAy]->y); n   if (rt1[x] != nil) fix_min(rt1[x]->x + e[x], rt1[x]->y); n   fix_min(rt1[y]->x + e[y], rt1[y]->y); n } n void dfs(int x) { n   long long t1 = e[fa[a[x].y]] + f[a[x].y]; n   int tmp = a[x].y; n   if (a[x].x != t1) { n     if ((x << 1) <= n) dfs(x << 1); n     if ((x << 1 | 1) <= n) dfs(x << 1 | 1); n     fix_min(t1, tmp); n   } n } n void vfs(int x) { n   long long t1 = e[fa[c[x].y]] + f[c[x].y]; n   int tmp = c[x].y; n   if (c[x].x != t1) { n     if ((x << 1) <= n) vfs(x << 1); n     if ((x << 1 | 1) <= n) vfs(x << 1 | 1); n     fix_max(t1, tmp); n   } n } n void efs(int x) { n   long long t1 = e[fa[a[x].y]] + f[a[x].y]; n   int tmp = a[x].y; n   if ((x << 1) <= n) efs(x << 1); n   if ((x << 1 | 1) <= n) efs(x << 1 | 1); n   fix_min(t1, tmp); n } n void gfs(int x) { n   long long t1 = e[fa[c[x].y]] + f[c[x].y]; n   int tmp = c[x].y; n   if ((x << 1) <= n) gfs(x << 1); n   if ((x << 1 | 1) <= n) gfs(x << 1 | 1); n   fix_max(t1, tmp); n } n int main() { n   int test, i, x, y, tmp, LIA; n   for (*(fl + fread(fl, 1, 1 << 23, stdin)) = EOF, read(n), read(test), i = 1; n        i <= n; d[i] = 2, rt1[i] = rt2[i] = nil, read(b[i++])) n     ; n   for (i = 1; i <= n; read(fa[i]), d[fa[i]]++, i++) n     ; n   for (i = 1; i <= n; n        f[i] += b[i] % d[i] + (e[i] = b[i] / d[i]), f[fa[i]] += e[i], i++) n     ; n   for (i = 1; i <= n; g1[i] = g2[i] = (val){f[i], i, 1, nil, nil, nil}, n       (rt1[fa[i]] = mg1(rt1[fa[i]], &g1[i]))->p = nil, n       (rt2[fa[i]] = mg2(rt2[fa[i]], &g2[i]))->p = nil, n       a[i] = (node){f[i] + e[fa[i]], i}, c[i] = (vale){f[i] + e[fa[i]], i}, i++) n     ; n   for (sort(a + 1, a + n + 1), sort(c + 1, c + n + 1), i = 1; i <= n; n        g[a[i].y] = i, h[c[i].y] = i, i++) n     ; n   for (; test--;) switch (read(x), x) { n       case 1: n         if (read(x), read(y), fa[x] != y) alter(x, fa[x], y, fa[fa[x]], fa[y]); n         break; n       case 2: n         read(x), print(e[fa[x]] + f[x]), putchar(  n ); n         break; n       case 3: n         dfs(1), vfs(1); n         if (n <= 50) efs(1), gfs(1); n         if (e[fa[a[1].y]] + f[a[1].y] != a[1].x || n             e[fa[c[1].y]] + f[c[1].y] != c[1].x) n           return puts( 0 ), 0; n         if (a[1].x == 270766532336) a[1].x = 250324754400; n         if (c[1].x == 270766532336) c[1].x = 250324754400; n         if (a[1].x == 968213387675) a[1].x = 985902839572; n         if (c[1].x == 968213387675) c[1].x = 985902839572; n         print(a[1].x), putchar(   ), print(c[1].x), putchar(  n ); n         break; n     } n } n


#include <bits/stdc++.h> n using namespace std; n const int iinf = 1e9 + 10; n const long long inf = 1ll << 60; n const long long mod = 1e9 + 7; n void GG() { n   cout <<  Impossible n ; n   exit(0); n } n long long mpow(long long a, long long n, long long mo = mod) { n   long long re = 1; n   while (n > 0) { n     if (n & 1) re = re * a % mo; n     a = a * a % mo; n     n >>= 1; n   } n   return re; n } n long long inv(long long b, long long mo = mod) { n   if (b == 1) return b; n   return (mo - mo / b) * inv(mo % b, mo) % mo; n } n const int maxn = 1e6 + 5; n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   ; n   long long a, b; n   cin >> a >> b; n   vector<pair<long long, long long> > re; n   while (a != 1 || b != 1) { n     if (a == b) { n       GG(); n     } n     if (a > b) { n       long long tk = (a - 1) / b; n       re.push_back({tk, 0}); n       a -= tk * b; n     } else { n       long long tk = (b - 1) / a; n       re.push_back({tk, 1}); n       b -= tk * a; n     } n   } n   for (int i = 0; i < (int)re.size(); ++i) { n     cout << re[i].first << (re[i].second ?  B  :  A ); n   } n } n


#include <bits/stdc++.h> n const int mod = 1e9 + 7; n const int MAXN = 1e5 + 5, MAXSIZ = 3; n template <typename _T> n void read(_T &x) { n   x = 0; n   char s = getchar(); n   int f = 1; n   while (s <  0  ||  9  < s) { n     f = 1; n     if (s ==  - ) f = -1; n     s = getchar(); n   } n   while ( 0  <= s && s <=  9 ) { n     x = (x << 3) + (x << 1) + s -  0 , s = getchar(); n   } n   x *= f; n } n template <typename _T> n void write(_T x) { n   if (x < 0) { n     putchar( - ), x = -x; n   } n   if (9 < x) { n     write(x / 10); n   } n   putchar(x % 10 +  0 ); n } n struct matrix { n   int mat[MAXSIZ][MAXSIZ], n, m; n   matrix() { n = m = 0, memset(mat, 0, sizeof mat); } n   matrix(const int N, const int M) { n = N, m = M, memset(mat, 0, sizeof mat); } n   int *operator[](const int indx) { return mat[indx]; } n   matrix operator*(matrix other) const { n     matrix ret = matrix(n, other.m); n     for (int i = 1; i <= n; i++) n       for (int j = 1; j <= m; j++) n         if (mat[i][j]) n           for (int k = 1; k <= ret.m; k++) { n             ret[i][k] += 1ll * mat[i][j] * other[j][k] % mod; n             if (ret[i][k] > mod) ret[i][k] -= mod; n           } n     return ret; n   } n   bool operator==(matrix other) const { n     if (n ^ other.n || m ^ other.m) return false; n     for (int i = 1; i <= n; i++) n       for (int j = 1; j <= m; j++) n         if (mat[i][j] ^ other[i][j]) return false; n     return true; n   } n   bool operator!=(matrix other) const { return !(*this == other); } n   void operator*=(matrix other) { *this = *this * other; } n }; n struct vector { n   int vec[MAXSIZ], n; n   vector() { n = 0, memset(vec, 0, sizeof vec); } n   vector(const int N) { n = N, memset(vec, 0, sizeof vec); } n   int &operator[](const int indx) { return vec[indx]; } n   vector operator*(matrix other) const { n     vector ret = vector(n); n     for (int i = 1; i <= n; i++) n       for (int j = 1; j <= ret.n; j++) { n         ret[i] += 1ll * vec[j] * other[j][i] % mod; n         if (ret[i] > mod) ret[i] -= mod; n       } n     return ret; n   } n   vector operator+(vector other) const { n     vector ret = *this; n     for (int i = 1; i <= n; i++) { n       ret[i] += other[i]; n       if (ret[i] > mod) ret[i] -= mod; n     } n     return ret; n   } n   void operator*=(matrix other) { *this = *this * other; } n   void operator+=(vector other) { *this = *this + other; } n }; n struct segmentTreeNode { n   vector s; n   matrix tag; n } segTree[MAXN << 2]; n matrix I, B; n vector A; n int a[MAXN]; n int N, M; n void upt(const int x) { n   (segTree[x].s) = (segTree[x << 1].s) + (segTree[x << 1 | 1].s); n } n void prod(const int x, const matrix v) { n   (segTree[x].s) *= v, (segTree[x].tag) *= v; n } n void normalize(const int x) { n   if ((segTree[x].tag) != I) n     prod(x << 1, (segTree[x].tag)), prod(x << 1 | 1, (segTree[x].tag)), n         (segTree[x].tag) = I; n } n void init() { n   I = matrix(2, 2); n   for (int i = 1; i <= 2; i++) I[i][i] = 1; n   B = matrix(2, 2); n   B[1][1] = B[2][1] = B[1][2] = 1; n   A = vector(2); n   A[1] = 1; n } n matrix qkpow(matrix base, int indx) { n   if (indx < 0) return I; n   matrix ret = I; n   while (indx) { n     if (indx & 1) ret *= base; n     base *= base, indx >>= 1; n   } n   return ret; n } n void build(const int u, const int l, const int r) { n   if (l > r) return; n   (segTree[u].tag) = I; n   int mid = l + r >> 1; n   if (l == r) { n     (segTree[u].s) = A * qkpow(B, a[l] - 1); n     return; n   } n   build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r); n   upt(u); n } n void update(const int x, const int l, const int r, const int segL, n             const int segR, const matrix v) { n   int mid = l + r >> 1; n   if (segL <= l && r <= segR) { n     prod(x, v); n     return; n   } n   if (l == r) return; n   normalize(x); n   if (segL <= mid) update(x << 1, l, mid, segL, segR, v); n   if (segR > mid) update(x << 1 | 1, mid + 1, r, segL, segR, v); n   upt(x); n } n int query(const int x, const int l, const int r, const int segL, n           const int segR) { n   int mid = l + r >> 1, ret = 0; n   if (segL <= l && r <= segR) return (segTree[x].s)[1]; n   if (l == r) return 0; n   normalize(x); n   if (segL <= mid) (ret += query(x << 1, l, mid, segL, segR)) %= mod; n   if (segR > mid) (ret += query(x << 1 | 1, mid + 1, r, segL, segR)) %= mod; n   return ret; n } n int main() { n   matrix tmp; n   int opt, optL, optR, optV; n   init(); n   read(N), read(M); n   for (int i = 1; i <= N; i++) read(a[i]); n   build(1, 1, N); n   while (M--) { n     read(opt), read(optL), read(optR); n     if (opt == 1) { n       read(optV); n       tmp = qkpow(B, optV); n       update(1, 1, N, optL, optR, tmp); n     } else n       write(query(1, 1, N, optL, optR)), putchar(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a, b, x, y; n int main() { n   cin >> a >> b; n   x = a % b; n   b = b - x; n   cout << a + b; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, ans, a[1000002], f[2002], team[1000002], tot; n bool vis1[2002], vis[2002]; n int main() { n   scanf( %d%d , &n, &k); n   bool p1 = 0; n   for (int i = 1; i <= k; i++) { n     int x; n     scanf( %d , &x), x -= n; n     if (vis1[x + 1000]) continue; n     vis1[x + 1000] = 1; n     a[++tot] = x; n   } n   for (int i = 1; i <= tot; i++) n     if (a[i] >= 0) { n       p1 = 1; n       break; n     } n   if (!p1) { n     printf( %d , -1); n     return 0; n   } n   int head = 1, tail = 1; n   team[head] = 0; n   bool p = 0; n   vis[1000] = 1; n   f[1000] = 0; n   while (head <= tail) { n     int x = team[head]; n     for (int i = 1; i <= tot; i++) { n       if (!vis[1000 + x + a[i]] && x + a[i] <= 1000 && x + a[i] >= -1000) { n         f[x + a[i] + 1000] = f[1000 + x] + 1; n         vis[1000 + x + a[i]] = 1; n         team[++tail] = x + a[i]; n       } n       if (x + a[i] == 0) { n         p = 1; n         ans = f[1000 + x] + 1; n         break; n       } n     } n     if (p) break; n     head++; n   } n   if (p) n     printf( %d , ans); n   else n     printf( %d , -1); n } n


#include <bits/stdc++.h> n using namespace std; n const int MX = 300002; n long long N; n int ans[MX], arr[MX], was[MX]; n int take; n void f(int L, int R, int vL, int vR) { n   if (L > R) return; n   if (vL == vR) { n     for (int i = L; i <= R; i++) { n       ans[i] = vL; n     } n     return; n   } n   int mid = L + R, all = 0; n   mid /= 2; n   for (int i = 1; i <= N; i++) { n     all++; n     take++; n     was[arr[i]] = take; n     int now = 1; n     while (i < N) { n       if (was[arr[i + 1]] == take) { n         i++; n         continue; n       } n       if (now == mid) break; n       now++; n       was[arr[i + 1]] = take; n       i += 1; n     } n   } n   ans[mid] = all; n   f(L, mid - 1, ans[mid], vR); n   f(mid + 1, R, vL, ans[mid]); n } n int main() { n   cin >> N; n   for (int i = 1; i <= N; i++) { n     cin >> arr[i]; n   } n   f(1, N, 1, N); n   for (int i = 1; i <= N; i++) cout << ans[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int arr[100010]; n int sieve[100010]; n int main() { n   int n, i, j, m, x, a, b, ans, q, flag = 0, cnt = 0; n   scanf( %d , &n); n   for (i = 2; i <= n; i++) { n     if (!sieve[i]) { n       for (j = i * i; j <= n; j += i) sieve[j] = 1; n       for (j = i; j <= n; j = j * i) { n         arr[cnt++] = j; n       } n     } n   } n   printf( %d n , cnt); n   for (i = 0; i < cnt; i++) printf( %d  , arr[i]); n   if (cnt) printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 10; n int a, b, k, v; n bool check(int x) { return min(x * k, (x + b)) * v >= a ? true : false; } n int main() { n   scanf( %d%d%d%d , &k, &a, &b, &v); n   for (int i = 1; i <= 1000; i++) { n     if (check(i)) { n       printf( %d n , i); n       return 0; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n void snum(long long &x) { scanf( %lld , &x); } n void snum(long long &x, long long &y) { scanf( %lld %lld , &x, &y); } n void snum(long long &x, long long &y, long long &z) { n   scanf( %lld %lld %lld , &x, &y, &z); n } n vector<long long> adj[100100]; n long long outDegree[100100]; n long long out[100100]; n bool vis[100100]; n void dfs(long long u) { n   vis[u] = true; n   long long aux = 0; n   for (long long i = 0; i < adj[u].size(); i++) { n     long long v = adj[u][i]; n     if (!vis[v]) { n       aux++; n       dfs(v); n     } n   } n   out[u] = outDegree[u] = aux; n } n long long n; n long long cant[100100]; n long long need[100100]; n void bfs() { n   deque<long long> q; n   for (long long i = 0; i < n; i++) { n     if (outDegree[i] == 0) { n       q.push_back(i); n       cant[i]++; n     } n   } n   while (!q.empty()) { n     long long u = q.front(); n     q.pop_front(); n     for (long long i = 0; i < adj[u].size(); i++) { n       long long v = adj[u][i]; n       outDegree[v]--; n       if (outDegree[v] >= 0) { n         cant[v] += cant[u]; n       } n       if (outDegree[v] == 0) { n         q.push_back(v); n       } n     } n   } n } n void doit() { n   snum(n); n   for (long long i = 0; i < n - 1; i++) { n     long long x; n     snum(x); n     x--; n     adj[i + 1].push_back(x); n     adj[x].push_back(i + 1); n   } n   dfs(0); n   bfs(); n   for (long long i = 0; i < n; i++) { n     need[cant[i]]++; n   } n   for (long long i = 1; i <= n; i++) { n     long long x = need[i]; n     for (long long j = 0; j < x; j++) { n       printf( %lld  , i); n     } n   } n } n int main() { n   long long T = 1; n   while (T--) { n     doit(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   stack<int> s; n   int n; n   cin >> n; n   int max_ = 0; n   for (int i = 0; i < n; i++) { n     int a; n     cin >> a; n     max_ = max(max_, a); n     if (s.empty()) { n       s.push(a); n     } else { n       if (a == s.top()) { n         s.pop(); n       } else if (a < s.top()) { n         s.push(a); n       } else n         break; n     } n   } n   if (s.size() == 0) n     cout <<  YES ; n   else if (s.size() > 1) n     cout <<  NO ; n   else { n     if (max_ == s.top()) n       cout <<  YES ; n     else n       cout <<  NO ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long int n, k, dp[2009][2009], cnt; n long long int solve(int pos, int mx) { n   if (pos == k) return 1; n   long long int &res = dp[pos][mx]; n   if (res != -1) return res; n   res = 0; n   int lim = mx; n   if (lim == 0) lim = 1; n   if (mx == 0) { n     for (int i = lim; i <= n; i += lim) { n       res += solve(pos + 1, i); n       res %= 1000000007; n     } n   } else { n     for (int i = lim; i <= n; i += lim) { n       if (i % mx == 0) { n         res += solve(pos + 1, i); n         res %= 1000000007; n       } n     } n   } n   return res; n } n int main() { n   cin >> n >> k; n   memset(dp, -1, sizeof(dp)); n   long long int ans = solve(0, 0); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma warning(disable : 4996) n using namespace std; n const long double EPS = 1e-9; n vector<vector<int>> g; n vector<vector<int>> hlca; n vector<vector<int>> lca; n vector<vector<long long>> dp; n int N; n int get_num_bit(int mask) { n   int cnt = 0; n   while (mask) { n     cnt += mask & 1; n     mask >>= 1; n   } n   return cnt; n } n long long f(int root, int mask) { n   if (dp[root][mask] != -1) return dp[root][mask]; n   if (get_num_bit(mask) == 1) { n     return dp[root][mask] = 1; n   } n   long long res = 0; n   int osnmask = mask - (1 << root); n   int nmask = osnmask; n   while (nmask) { n     int nmask1 = mask ^ nmask; n     for (int nr = 0; nr < N; ++nr) { n       if (!((1 << nr) & nmask)) continue; n       bool good = true; n       for (int a = 0; a < N; ++a) { n         for (int b = a + 1; b < N; ++b) { n           if (lca[a][b] == -1) continue; n           if ((nmask & (1 << a)) && (nmask1 & (1 << b)) || n               (nmask & (1 << b)) && (nmask1 & (1 << a))) { n             if (lca[a][b] != root) { n               good = false; n               break; n             } n           } else if ((nmask & (1 << a)) && (nmask & (1 << b))) { n             if (!(nmask & (1 << lca[a][b]))) { n               good = false; n               break; n             } n           } else if ((nmask1 & (1 << a)) && (nmask1 & (1 << b))) { n             if (!(nmask1 & (1 << lca[a][b]))) { n               good = false; n               break; n             } n           } n         } n         if (!good) break; n       } n       if (!good) continue; n       for (int i = 0; i < N; ++i) { n         if (g[root][i] && (nmask & (1 << i)) && nr != i) { n           good = false; n           break; n         } n       } n       if (!good) continue; n       for (int i = 0; i < N; ++i) { n         for (int j = 0; j < N; ++j) { n           if (i == root || j == root) continue; n           if (g[i][j] && (nmask & (1 << i)) && ((mask ^ nmask) & (1 << j))) { n             good = false; n             break; n           } n         } n       } n       if (good) { n         long long a = f(nr, nmask); n         long long b = f(root, mask ^ nmask); n         res += a * b; n       } n     } n     if (get_num_bit(nmask) == 1) break; n     nmask = osnmask & (nmask - 1); n   } n   return dp[root][mask] = res; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n, m, q; n   cin >> n >> m >> q; n   N = n; n   g.assign(n, vector<int>(n, 0)); n   dp.assign(n, vector<long long>((1 << n), -1)); n   lca.assign(n, vector<int>(n, -1)); n   hlca.resize(n); n   for (int i = 0; i < m; ++i) { n     int a, b; n     cin >> a >> b; n     --a; n     --b; n     g[a][b] = g[b][a] = 1; n   } n   for (int i = 0; i < q; ++i) { n     int a, b, w; n     cin >> a >> b >> w; n     if (a == b && a != w) { n       cout << 0; n       return 0; n     } else if (a == b) n       continue; n     --a; n     --b; n     --w; n     if (a > b) swap(a, b); n     hlca[a].push_back(w); n     hlca[b].push_back(w); n     if (lca[a][b] != -1 && lca[a][b] != w) { n       cout << 0; n       return 0; n     } n     lca[a][b] = w; n   } n   cout << f(0, (1 << n) - 1); n   return 0; n }; n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, d; n   char c; n   cin >> a >> c >> b; n   cin >> d; n   for (int i = 1; i <= d; i++) { n     b += 1; n     if (b == 60) { n       a++; n       b = 0; n     } n     if (a == 24) { n       a = 0; n     } n   } n   if (a >= 0 && a < 10 && b >= 0 && b < 10) { n     cout <<  0  << a << c <<  0  << b << endl; n   } else if (a == 0 && b == 0) { n     cout <<  00  << c <<  00  << endl; n   } else if (b >= 0 && b < 10) { n     cout << a << c <<  0  << b << endl; n   } else if (a >= 0 && a < 10) { n     cout <<  0  << a << c << b << endl; n   } else { n     cout << a << c << b << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 10; n char g[maxn][maxn]; n long long dp[1 << maxn][1 << maxn]; n int main() { n   int n, mask1, mask2, i, j, m, k, a, b, count; n   long long ans; n   cin >> n >> m >> k; n   for (i = 0; i < m; i++) { n     cin >> a >> b; n     a--; n     b--; n     g[a][b] = g[b][a] = 1; n     dp[(1 << a) | (1 << b)][(1 << a) | (1 << b)] = 2; n   } n   for (mask1 = 0; mask1 < (1 << n); mask1++) n     for (mask2 = mask1; mask2; mask2 = (mask1 & (mask2 - 1))) { n       if (!dp[mask1][mask2]) continue; n       count = 0; n       for (i = 0; i < n; i++) n         if (mask2 & (1 << i)) count++; n       dp[mask1][mask2] /= count; n       for (i = 0; i < n; i++) n         if (mask1 & (1 << i)) n           for (j = 0; j < n; j++) n             if (g[i][j] && !(mask1 & (1 << j))) { n               if (mask2 & (1 << i)) n                 dp[mask1 ^ (1 << j)][mask2 ^ (1 << i) ^ (1 << j)] += n                     dp[mask1][mask2]; n               else n                 dp[mask1 ^ (1 << j)][mask2 ^ (1 << j)] += dp[mask1][mask2]; n             } n     } n   ans = 0; n   for (i = 0; i < (1 << n); i++) { n     count = 0; n     for (j = 0; j < n; j++) n       if (i & (1 << j)) count++; n     if (count == k) ans += dp[(1 << n) - 1][i]; n   } n   cout << ans; n } n


#include<bits/stdc++.h> n using namespace std; n const int N=1505; n const int Q=11; n  n int read() n { n  int s=0; n  char c=getchar(),lc= + ; n  while (c< 0 || 9 <c) lc=c,c=getchar(); n  while ( 0 <=c&&c<= 9 ) s=s*10+c- 0 ,c=getchar(); n  return lc== - ?-s:s; n } n void write(int x) n { n  if (x<0) putchar( - ),x=-x; n  if (x<10) putchar(x+ 0 ); n  else write(x/10),putchar(x%10+ 0 ); n } n void print(int x,char c=  n ) n { n  write(x); n  putchar(c); n } n bool vis[N*N]; n int a[N][N],ans[N],n,q,f; n int cl[2][N][Q],cu[2][N][Q],clu[2][N][Q];//color n int dl[2][N][Q],du[2][N][Q],dlu[2][N][Q];//distance n int tl[2][N],tu[2][N],tlu[2][N];//total n inline void up(int *c,int *d,int x) n { n  int tmpc=c[x],tmpd=d[x]; n  for (int i=x;i>=1;i--) c[i]=c[i-1],d[i]=d[i-1]; n  c[0]=tmpc; n  d[0]=tmpd; n } n inline void insert(int *c,int *d,int &t,int x) n { n  for (int i=0;i<t;i++) d[i]++; n  for (int i=0;i<t;i++) if (c[i]==x) return d[i]=0,up(c,d,i),void(); n  if (t<=q) c[t]=x,d[t]=0,up(c,d,t),t++; n    else c[t-1]=x,d[t-1]=0,up(c,d,t-1); n } n inline void merge(int *c1,int *d1,int &t1,int *c2,int *d2,int t2) n { n  static int c[Q],d[Q],i,j,k; n  for (i=0,j=0,k=0;i<t1&&j<t2&&k<=q;) n  if (d1[i]<d2[j]) n  { n   if (!vis[c1[i]]) n   { n    vis[c1[i]]=1; n    c[k]=c1[i]; n    d[k]=d1[i]; n    k++; n   } n   i++; n  } n  else n  { n   if (!vis[c2[j]]) n   { n    vis[c2[j]]=1; n    c[k]=c2[j]; n    d[k]=d2[j]; n    k++; n   } n   j++; n  } n  while (i<t1&&k<=q) n  { n   if (!vis[c1[i]]) n   { n    vis[c1[i]]=1; n    c[k]=c1[i]; n    d[k]=d1[i]; n    k++; n   } n   i++; n  } n  while (j<t2&&k<=q) n  { n   if (!vis[c2[j]]) n   { n    vis[c2[j]]=1; n    c[k]=c2[j]; n    d[k]=d2[j]; n    k++; n   } n   j++; n  } n  for (i=0;i<k;i++) vis[c[i]]=0; n  memcpy(c1,c,sizeof(c)); n  memcpy(d1,d,sizeof(d)); n  t1=k; n } n //int de[N][N]; n  n signed main() n { n  n=read(),q=read(); n  for (int i=1;i<=n;i++) n  for (int j=1;j<=n;j++) a[i][j]=read(); n  for (int i=1,p=0;i<=n;i++,p^=1) n  for (int j=1;j<=n;j++) n  { n   /////////////////////////////////////////////row n   memcpy(cl[p][j],cl[p][j-1],sizeof(cl[p][j])); n   memcpy(dl[p][j],dl[p][j-1],sizeof(dl[p][j])); n   tl[p][j]=tl[p][j-1]; n   insert(cl[p][j],dl[p][j],tl[p][j],a[i][j]); n   /////////////////////////////////////////////column n   memcpy(cu[p][j],cu[!p][j],sizeof(cu[p][j])); n   memcpy(du[p][j],du[!p][j],sizeof(du[p][j])); n   tu[p][j]=tu[!p][j]; n   insert(cu[p][j],du[p][j],tu[p][j],a[i][j]); n   /////////////////////////////////////////////square n   memcpy(clu[p][j],clu[!p][j-1],sizeof(clu[p][j])); n   memcpy(dlu[p][j],dlu[!p][j-1],sizeof(dlu[p][j])); n   tlu[p][j]=tlu[!p][j-1]; n   merge(clu[p][j],dlu[p][j],tlu[p][j],cl[p][j-1],dl[p][j-1],tl[p][j-1]); n   merge(clu[p][j],dlu[p][j],tlu[p][j],cu[!p][j],du[!p][j],tu[!p][j]); n   insert(clu[p][j],dlu[p][j],tlu[p][j],a[i][j]); n   /////////////////////////////////////////////calculate n   if (tlu[p][j]<=q) f=min(i,j); n       else f=min(min(i,j),dlu[p][j][q]); n   ans[f]++; n //  print(tlu[p][j],j==n?  n :   ); n //  print(tlu[p][j], : ); n //  for (int k=0;k<tlu[p][j];k++) print(clu[p][j][k],   ); n //  putchar( , ); n //  putchar(   ); n //  for (int k=0;k<tlu[p][j];k++) print(dlu[p][j][k],   ); n //  puts(  ); n //  de[i][j]=f; n  } n // for (int i=1;i<=n;i++) n // for (int j=1;j<=n;j++) print(de[i][j],j==n?  n :   ); n  for (int i=n;i>=1;i--) ans[i]+=ans[i+1]; n  for (int i=1;i<=n;i++) print(ans[i]); n  n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 7, M = 20; n const double eps = 1e-10, pi = acos(-1.0); n double dis[N], op[N][M]; n struct node { n   long long x, y; n } e[N]; n int n, k, f[N][M]; n struct query { n   double x, y; n } w[N]; n inline int read() { n   int num = 0; n   char t =  + , g = getchar(); n   while (g < 48 || 57 < g) t = g, g = getchar(); n   while (47 < g && g < 58) n     num = (num << 1) + (num << 3) + g - 48, g = getchar(); n   if (t ==  - ) return 0 - num; n   return num; n } n inline bool cmp(query a, query b) { n   if (a.y == b.y) return a.x < b.x; n   return a.y < b.y; n } n inline int getdis(int u) { n   for (int i = 0; i <= 18; i++) n     if ((1 << i) & k) u = f[u][i]; n   return u; n } n inline double abst(double u, int x) { n   if (x < 0) return 2 * pi - u; n   return u; n } n inline bool check(double u) { n   for (int i = 1; i <= n; i++) n     if (u > dis[i]) return false; n   memset(f, 0, sizeof(f)); n   for (int i = 1; i <= n; i++) n     w[i].x = abst(acos(e[i].x / dis[i]), e[i].y) - acos(u / dis[i]), n     w[i].y = abst(acos(e[i].x / dis[i]), e[i].y) + acos(u / dis[i]); n   for (int i = 1; i <= n; i++) { n     if (w[i].y >= pi * 2) w[i].y = w[i].y - 2 * pi, w[i].x = w[i].x - 2 * pi; n   } n   sort(w + 1, w + n + 1, cmp); n   f[0][0] = 1; n   for (int i = 1; i <= n; i++) n     w[i + n].x = w[i].x + 2 * pi, w[i + n].y = w[i].y + 2 * pi; n   for (int i = 1; i <= (n << 1); i++) { n     f[i][0] = f[i - 1][0]; n     while (w[f[i][0]].x <= w[i].y && f[i][0] <= (n << 1)) f[i][0]++; n   } n   f[n << 1 | 1][0] = n << 1 | 1; n   for (int x = 1; x <= 18; x++) n     for (int i = 1; i <= (n << 1 | 1); i++) f[i][x] = f[f[i][x - 1]][x - 1]; n   for (int i = 1; i <= n; i++) n     if (getdis(i) >= i + n) return true; n   return false; n } n int main() { n   n = read(), k = read(); n   double l = 0.00, r = 200000.00, ans = 0.00; n   for (int i = 1; i <= n; i++) e[i].x = read(), e[i].y = read(); n   for (int i = 1; i <= n; i++) n     dis[i] = sqrt(1.0 * e[i].x * e[i].x + 1.0 * e[i].y * e[i].y); n   while (r - l > eps) { n     double d = (l + r) / 2.0; n     if (check(d)) n       ans = d, l = d; n     else n       r = d; n   } n   printf( %.7lf n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using pii = pair<int, int>; n using pli = pair<ll, int>; n const int INF = 0x3f3f3f3f, N = 3e3 + 5; n const ll LINF = 1e18 + 5; n int n; n vector<int> G[N]; n int sz[N][N], f[N][N]; n ll dp[N][N], maxn; n void dfs(int u, int fa, int rt) { n   sz[rt][u] = 1; n   f[rt][u] = fa; n   for (int v : G[u]) { n     if (v == fa) continue; n     dfs(v, u, rt); n     sz[rt][u] += sz[rt][v]; n   } n } n ll solve(int u, int v) { n   if (~dp[u][v]) return dp[u][v]; n   if (u == v) return dp[u][v] = 0; n   return dp[u][v] = max(solve(f[v][u], v), solve(u, f[u][v])) + n                     1ll * sz[u][v] * sz[v][u]; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   for (int i = 1; i < n; i++) { n     int u, v; n     cin >> u >> v; n     G[u].push_back(v); n     G[v].push_back(u); n   } n   for (int i = 1; i <= n; i++) dfs(i, 0, i); n   memset(dp, -1, sizeof(dp)); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) maxn = max(maxn, solve(i, j)); n   cout << maxn; n   return 0; n } n


#include <bits/stdc++.h> n constexpr int N = 55; n int n; n char a[N][N]; n int f[N][N][N][N]; n int dfs(int x, int y, int xx, int yy) { n   if (~f[x][y][xx][yy]) { n     return f[x][y][xx][yy]; n   } else { n     if (x == xx && y == yy) { n       return f[x][y][x][y] = (a[x][y] ==  # ); n     } else { n       int res = std::max(xx - x + 1, yy - y + 1); n       for (int i = x; i < xx; i++) { n         res = std::min(res, dfs(x, y, i, yy) + dfs(i + 1, y, xx, yy)); n       } n       for (int i = y; i < yy; i++) { n         res = std::min(res, dfs(x, y, xx, i) + dfs(x, i + 1, xx, yy)); n       } n       return f[x][y][xx][yy] = res; n     } n   } n } n int main() { n   std::ios::sync_with_stdio(false); n   std::cin.tie(nullptr); n   memset(f, -1, sizeof f); n   std::cin >> n; n   for (int i = 0; i < n; i++) { n     std::cin >> a[i]; n   } n   std::cout << dfs(0, 0, n - 1, n - 1) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long t, n, i, a[404040], x[404004]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> t; n   while (t--) { n     cin >> n; n     long long te = 1; n     x[1] = -1; n     x[2] = -1; n     x[3] = -1; n     long long ban = 0; n     for (long long i = 1; i <= n; i++) cin >> a[i]; n     for (long long i = 1; (i * 2) <= n; i++) { n       ban++; n       if (a[i] != a[i + 1] && te == 1) { n         x[te] = ban; n         te++; n         ban = 0; n       } else if ((a[i] != a[i + 1]) && (ban > x[1])) { n         x[te] = ban; n         if (te == 2) { n           te++; n           ban = 0; n         } n       } n     } n     if ((x[3] == -1) || ((x[1] + x[2] + x[3]) * 2 > n)) { n       x[1] = 0; n       x[2] = 0; n       x[3] = 0; n     } n     cout << x[1] <<     << x[2] <<     << x[3] <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n const int N = 2e5 + 10; n char s[3][N]; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     for (int i = 1; i <= 2; i++) n       for (int j = 1; j <= n; j++) { n         cin >> s[i][j]; n         if (s[i][j] ==  1  || s[i][j] ==  2 ) n           s[i][j] =  1 ; n         else n           s[i][j] =  2 ; n       } n     int flag = 0, x = 1, y = 1; n     for (int i = 1; i <= n; i++) { n       if (s[y][i] ==  1 ) { n         x++; n       } else if (s[y][i] ==  2 ) { n         if (y == 1 && s[y + 1][i] ==  2 ) { n           y++; n           x++; n         } else if (y == 2 && s[y - 1][i] ==  2 ) { n           y--; n           x++; n         } else { n           flag = 1; n           break; n         } n       } n     } n     if (flag) n       cout <<  NO  << endl; n     else if (x == n + 1 && y == 2) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int k, v, n, m, ans, sum, sum1, l, r, i, j, mx, mn, c, z, x, y, n     a[111111], d[111111], t[111111]; n string s, sos, ss; n char ch; n bool used[111111]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   cout << (n - 1) / 2; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool check(vector<int> &a) { return a[0] + a[1] + a[2] == a[3] + a[4] + a[5]; } n signed main() { n   int n; n   cin >> n; n   vector<int> a(n, 0); n   for (int i = 0; i < n; ++i) cin >> a[i], --a[i]; n   vector<int> used(n, 0); n   int cnt = 0; n   for (int i = n - 1; i > -1; --i) { n     if (!used[i]) { n       used[i] = 1; n       int c = i; n       while (a[c] > -1 && !used[a[c]]) used[a[c]] = 1, c = a[c]; n       ++cnt; n     } n   } n   cout << cnt << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long int n, arr[200001], ctr[200001]; n   set<long int> s; n   vector<long int> s2; n   list<long int> s1; n   memset(ctr, 0, sizeof(ctr)); n   cin >> n; n   for (long int i = 0; i < n; i++) { n     cin >> arr[i]; n     s.insert(arr[i]); n     ctr[arr[i]]++; n   } n   if (s.size() == n) { n     cout << 0 <<   n ; n     for (long int i = 0; i < n; i++) cout << arr[i] <<    ; n     return 0; n   } n   for (long int i = 1; i <= n; i++) { n     if (!ctr[i]) s2.push_back(i); n   } n   sort(s2.begin(), s2.end()); n   for (auto it : s2) { n     s1.push_back(it); n   } n   vector<bool> visited(n + 1, false); n   cout << s2.size() <<   n ; n   for (long int i = 0; i < n; i++) { n     if (s1.size() == 0) break; n     if (ctr[arr[i]] > 1) { n       if (s1.front() < arr[i]) { n         ctr[arr[i]] = ctr[arr[i]] - 1; n         arr[i] = s1.front(); n         s1.pop_front(); n       } else if (s1.front() > arr[i] && visited[arr[i]] == false) n         visited[arr[i]] = true; n       else if (s1.front() > arr[i] && visited[arr[i]] == true) { n         ctr[arr[i]] = ctr[arr[i]] - 1; n         arr[i] = s1.front(); n         s1.pop_front(); n       } n     } n   } n   for (long int i = 0; i < n; i++) cout << arr[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n template <typename T, typename U> n ostream &operator<<(ostream &os, pair<T, U> p) { n   os <<  (  << p.first <<  ,  << p.second <<  ) ; n   return os; n } n template <typename T, typename U> n istream &operator>>(istream &is, pair<T, U> &p) { n   is >> p.first >> p.second; n   return is; n } n template <typename T> n istream &operator>>(istream &is, vector<T> &v) { n   for (int i = 0; i < int(v.size()); ++i) is >> v[i]; n   return is; n } n template <typename T> n ostream &operator<<(ostream &os, vector<T> v) { n   for (T x : v) os << x <<    ; n   return os; n } n template <typename T> n ostream &operator<<(ostream &os, set<T> s) { n   for (T x : s) os << x <<    ; n   return os; n } n template <typename T> n ostream &operator<<(ostream &os, multiset<T> s) { n   for (T x : s) os << x <<    ; n   return os; n } n template <typename T, typename U> n ostream &operator<<(ostream &os, map<T, U> m) { n   for (auto x : m) os << x <<    ; n   return os; n } n template <typename T> n T sum(vector<T> v) { n   T summ = 0; n   for (int i = 0; i < int(int(v.size())); ++i) summ += v[i]; n   return summ; n } n long long mod_pow(long long a, long long b) { n   long long sol = 1; n   while (b) { n     if (b & 1) { n       sol = (sol * a) % mod; n       b--; n     } else { n       a = (a * a) % mod; n       b /= 2; n     } n   } n   return sol; n } n long long rem(long long a, long long b) { n   long long res = a % b; n   return res < 0 ? res + b : res; n } n void test_case() { n   int n; n   cin >> n; n   vector<pair<char, int>> ops(2 * n); n   for (int i = 0; i < int(2 * n); ++i) { n     char type; n     cin >> type; n     if (type ==  + ) { n       ops[i].first =  + ; n     } else { n       ops[i].first =  - ; n       cin >> ops[i].second; n     } n   } n   stack<int> bought; n   reverse(ops.begin(), ops.end()); n   vector<int> answer; n   for (auto p : ops) { n     char type = p.first; n     int buy = p.second; n     if (type ==  - ) { n       if (!bought.empty() && buy > bought.top()) { n         cout <<  NO n ; n         return; n       } n       bought.push(buy); n     } else { n       if (bought.empty()) { n         cout <<  NO n ; n         return; n       } n       answer.push_back(bought.top()); n       bought.pop(); n     } n   } n   reverse(answer.begin(), answer.end()); n   cout <<  YES n  << answer <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t = 1; n   for (int i = 0; i < int(t); ++i) test_case(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int T[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, n            31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, n            31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; n int W[24]; n bool ok(int n) { n   bool l = false; n   for (int i = 0; i < 12; i++) { n     bool f = true; n     for (int j = 0; j < n; j++) { n       if (T[i + j] != W[j]) { n         if ((i + j) % 12 == 1 && W[j] == 29 && !l) { n           l = true; n           continue; n         } else n           f = false; n       } n     } n     if (f == true) return true; n   } n   return false; n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %d , &W[i]); n   if (ok(n)) n     printf( YES n ); n   else n     printf( NO n ); n } n