#include <bits/stdc++.h> n using namespace std; n signed long long n, m, answer; n signed long long calc(signed long long n, signed long long m) { n   signed long long answer; n   if (m - n >= 1) { n     answer = n; n   } else { n     answer = n         m + (signed long long)ceil((sqrt(1.0L + 8.0L * (n - m)) - 1.0L) / 2.0L); n   } n   return answer; n } n int main() { n   cin >> n >> m; n   cout << calc(n, m); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, vis[4001], children, ans[4001]; n long long v[4001], abcdefghijklmnopqrstuvwxyz[4001], d[4001]; n int main() { n   while (~scanf( %d , &n)) { n     memset(vis, 0, sizeof(vis)); n     children = 0; n     for (register int i = 1; i <= n; i++) { n       scanf( %lld%lld%lld , &v[i], &d[i], &abcdefghijklmnopqrstuvwxyz[i]); n     } n     for (register int i = 1; i <= n; i++) { n       if (vis[i]) { n         continue; n       } n       ans[children++] = i; n       register long long temp1 = v[i], temp2 = 0; n       for (register int j = i + 1; j <= n; j++) n         if (!vis[j]) { n           abcdefghijklmnopqrstuvwxyz[j] -= temp1; n           temp1--; n           if (temp1 < 0) { n             break; n           } n         } n       for (register int j = i + 1; j <= n; j++) { n         if (!vis[j]) { n           abcdefghijklmnopqrstuvwxyz[j] -= temp2; n         } n         if (abcdefghijklmnopqrstuvwxyz[j] < 0 && !vis[j]) { n           temp2 += d[j]; n           vis[j] = 1; n         } n       } n     } n     printf( %d n , children); n     for (register int i = 0; i < children; i++) { n       printf( %d%c , ans[i], i == children - 1 ?   n  :    ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n using pii = pair<int, int>; n using pll = pair<ll, ll>; n using vi = vector<int>; n const ll INF = 100000000000ll; n const int N = 200005; n const int prime = 31; n const ll mod = 1000000007; n const ld eps = 1e-5; n mt19937_64 strong_random( n     chrono::system_clock::now().time_since_epoch().count()); n ll n; n void input() { scanf( %lld , &n); } n void solve() { n   vector<ll> divisors; n   ll nval = n; n   ll dv = 2; n   while (dv * dv <= n) { n     if (n % dv == 0) { n       int cc = 0; n       divisors.push_back(1); n       while (n % dv == 0) { n         n /= dv; n         divisors.back() *= dv; n       } n     } else { n       dv++; n     } n   } n   if (n != 1) { n     divisors.push_back(n); n   } n   int bitcnt = (int)(divisors).size(); n   pll ans = {nval, 1}; n   for (int i = 0; i < (1 << bitcnt); i++) { n     ll a = 1, b = 1; n     for (int j = 0; j < bitcnt; j++) { n       if ((1 << j) & i) { n         a *= divisors[j]; n       } else { n         b *= divisors[j]; n       } n     } n     if (a < b) swap(a, b); n     ans = min(ans, {a, b}); n   } n   cout << ans.second <<     << ans.first << endl; n } n void precalc() {} n int main() { n   precalc(); n   int testcases = 1; n   for (int testId = 1; testId <= testcases; testId++) { n     input(); n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   cerr << name <<   :   << arg1 << std::endl; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cerr.write(names, comma - names) <<   :   << arg1 <<   |  ; n   __f(comma + 1, args...); n } n vector<int> f, g; n void fdo(int k) { n   if (k == 0) return; n   vector<int> temp = f; n   f.clear(); n   f.push_back(0); n   for (auto it : temp) f.push_back(it); n   bool flag = true; n   int ch = 0; n   for (int i = 0; i < g.size(); i++) { n     if (abs(f[i] + g[i]) > 1) flag = false; n   } n   for (int i = 0; i < g.size(); i++) { n     if (flag) { n       f[i] = f[i] + g[i]; n     } else { n       f[i] = f[i] - g[i]; n     } n   } n   g = temp; n   for (int i = 0; i < f.size(); i++) { n     assert(abs(f[i]) < 2); n   } n   assert(f[f.size() - 1] == 1); n   assert(g[g.size() - 1] == 1); n   fdo(k - 1); n } n int main() { n   int n; n   scanf( %d , &n); n   f.push_back(0); n   f.push_back(1); n   if (n != 1) n     g.push_back(-1); n   else n     g.push_back(1); n   fdo(n - 1); n   cout << f.size() - 1 << endl; n   for (auto it : f) cout << it <<    ; n   cout << endl; n   cout << g.size() - 1 << endl; n   for (auto it : g) cout << it <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a, b; n int ans = 0; n bool ok = true; n int gcd(int a, int b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n void solve(int a) { n   while (a % 2 == 0) { n     a /= 2; n     ans++; n   } n   while (a % 3 == 0) { n     a /= 3; n     ans++; n   } n   while (a % 5 == 0) { n     a /= 5; n     ans++; n   } n   if (a != 1) ok = false; n } n int main() { n   scanf( %d%d , &a, &b); n   int x = gcd(a, b); n   a = a / x; n   b = b / x; n   solve(a); n   solve(b); n   if (ok) n     printf( %d n , ans); n   else n     puts( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> g; n int n; n int a = 0; n int b = 0; n int ans = 0; n bool used[200][200]; n void dfs(int a, int b) { n   used[a][b] = 1; n   for (int i = max(0, n - a); i <= min(n, b); i++) { n     if (!used[a + i - (n - i)][b - i + (n - i)]) { n       dfs(a + i - n + i, b - i - i + n); n     } n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < 2 * n - 1; i++) { n     int x; n     scanf( %d , &x); n     if (x <= 0) n       b++; n     else n       a++; n     g.push_back(abs(x)); n   } n   sort(g.begin(), g.end()); n   for (int i = 0; i < 200; i++) { n     for (int j = 0; j < 200; j++) { n       used[i][j] = 0; n     } n   } n   dfs(a, b); n   for (int i = 0; i <= 2 * n - 1; i++) { n     if (used[2 * n - 1 - i][i]) { n       for (int j = 0; j < i; j++) { n         ans -= g[j]; n       } n       for (int j = i; j < g.size(); j++) { n         ans += g[j]; n       } n       printf( %d , ans); n       return 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ull = unsigned long long; n using pii = pair<int, int>; n using pll = pair<ll, ll>; n template <class T> n inline bool Min(T &a, T b) { n   return a > b ? (a = b, true) : false; n } n template <class T> n inline bool Max(T &a, T b) { n   return a < b ? (a = b, true) : false; n } n inline int ni() { n   int a; n   scanf( %d , &a); n   return a; n } n inline ll nl() { n   ll a; n   scanf( %lld , &a); n   return a; n } n inline double nd() { n   double a; n   scanf( %lf , &a); n   return a; n } n inline void pi(int a) { printf( %d  , a); } n inline void pl(ll a) { printf( %lld  , a); } n inline void pd(double a) { printf( %.12lf  , a); } n void solve() { n   int n = ni(); n   vector<int> xs(n); n   for (int i = 0; i < (int)(n); ++i) xs[i] = ni(); n   vector<int> cnt(n + 1); n   vector<int> ans(n + 1); n   for (int i = 0; i < n; i++) { n     fill((cnt).begin(), (cnt).end(), 0); n     int maxCnt = -1, maxNum = n; n     for (int j = i; j < n; j++) { n       cnt[xs[j]]++; n       if (maxCnt <= cnt[xs[j]]) { n         if (maxCnt < cnt[xs[j]] or (maxCnt == cnt[xs[j]] and xs[j] < maxNum)) n           maxNum = xs[j]; n         maxCnt = cnt[xs[j]]; n       } n       ans[maxNum]++; n     } n   } n   for (int i = 1; i <= n; i++) pi(ans[i]); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   srand((int)clock()); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 200; n const int oo = 1000000007; n int n, k, m, a[10], lik[10], head[10], adj[10]; n long long res; n bool fre[10], ok; n void make(int u, int v) { n   m++; n   adj[m] = v; n   lik[m] = head[u]; n   head[u] = m; n } n void dfs(int u) { n   fre[u] = false; n   int i = head[u]; n   while (i != 0) { n     int v = adj[i]; n     if (fre[v]) dfs(v); n     i = lik[i]; n   } n } n bool check() { n   m = 0; n   memset(lik, 0, sizeof(lik)); n   memset(head, 0, sizeof(head)); n   memset(fre, 1, sizeof(fre)); n   for (long long i = 1; i <= k; i++) make(a[i], i); n   dfs(1); n   for (long long i = 1; i <= k; i++) n     if (fre[i]) return false; n   return true; n } n void att(int i) { n   if (i > k) { n     if (!ok) return; n     if (check()) res++; n     return; n   } n   for (long long x = 1; x <= k; x++) n     if ((x != i) || (i == 1)) { n       bool z = ok; n       if (x == 1) ok = true; n       a[i] = x; n       att(i + 1); n       ok = z; n     }; n } n int main() { n   cin >> n >> k; n   long long sum = 1; n   for (long long i = 1; i <= n - k; i++) sum = (sum * (n - k)) % oo; n   att(1); n   cout << (res * sum) % oo; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int r = 0, c = 0; n   string str; n   cin >> str; n   if (str.length() > 2) { n     for (int i = 0; i < str.length() - 2; i++) { n       if (str[i] ==  Q ) { n         for (int j = i + 1; j < str.length() - 1; j++) { n           if (str[j] ==  A ) r++; n           if (r > 0) { n             for (int k = j + 1; k < str.length(); k++) { n               if (str[k] ==  Q ) { n                 c++; n               } n               r = 0; n             } n           } n         } n       } n     } n   } n   printf( %d , c); n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n static constexpr ll oo = numeric_limits<ll>::max() / 2; n struct Node { n   ll sm, mx; n   Node() : sm{0}, mx{-oo} {} n   Node(ll sm_, ll mx_) : sm{sm_}, mx{mx_} {} n }; n struct LazySegmentTree { n   vector<Node> tree; n   vector<ll> mark; n   int n; n   LazySegmentTree(vector<ll> a) : n(a.size()) { n     tree.resize(4 * n); n     mark.resize(4 * n, oo); n     build(1, 0, n - 1, a); n   } n   Node merge(Node lhs, Node rhs) { n     Node node; n     node.sm = lhs.sm + rhs.sm; n     node.mx = max(lhs.mx, rhs.mx); n     return node; n   } n   void build(int v, int tl, int tr, const vector<ll>& a) { n     if (tl == tr) { n       tree[v] = {a[tl], a[tl]}; n       return; n     } n     int tm = (tl + tr) / 2; n     build(2 * v, tl, tm, a); n     build(2 * v + 1, tm + 1, tr, a); n     tree[v] = merge(tree[2 * v], tree[2 * v + 1]); n   } n   void push(int v, int l, int r) { n     if (mark[v] == oo) { n       return; n     } n     int m = (l + r) / 2; n     mark[2 * v] = mark[v]; n     tree[2 * v].mx = mark[v]; n     tree[2 * v].sm = (m - l + 1) * mark[v]; n     mark[2 * v + 1] = mark[v]; n     tree[2 * v + 1].mx = mark[v]; n     tree[2 * v + 1].sm = (r - m) * mark[v]; n     mark[v] = oo; n   } n   Node query(int l, int r) { return query(1, 0, n - 1, l, r); } n   Node query(int v, int tl, int tr, int l, int r) { n     if (l > r) return Node(); n     if (tl == l && tr == r) { n       return tree[v]; n     } n     push(v, tl, tr); n     int tm = (tl + tr) / 2; n     Node sl = query(2 * v, tl, tm, l, min(tm, r)); n     Node sr = query(2 * v + 1, tm + 1, tr, max(l, tm + 1), r); n     return merge(sl, sr); n   } n   void assign(int lo, int hi, ll x) { return update(1, 0, n - 1, lo, hi, x); } n   void update(int v, int tl, int tr, int l, int r, ll x) { n     if (l > r) return; n     if (tl == l && tr == r) { n       mark[v] = x; n       tree[v].mx = x; n       tree[v].sm = (r - l + 1) * x; n       return; n     } n     push(v, tl, tr); n     int tm = (tl + tr) / 2; n     update(2 * v, tl, tm, l, min(tm, r), x); n     update(2 * v + 1, tm + 1, tr, max(l, tm + 1), r, x); n     tree[v] = merge(tree[2 * v], tree[2 * v + 1]); n   } n }; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(nullptr); n   cout.tie(nullptr); n   int n; n   cin >> n; n   vector<ll> a(n); n   for (int i = 0; i < n; ++i) cin >> a[i]; n   vector<ll> b(n - 1); n   for (int i = 0; i < n - 1; ++i) cin >> b[i]; n   vector<ll> t(n, 0); n   for (int i = 1; i < n; ++i) { n     t[i] = t[i - 1] + b[i - 1]; n   } n   vector<ll> s(n); n   s[0] = t[0]; n   for (int i = 1; i < n; ++i) s[i] = s[i - 1] + t[i]; n   auto sum = [&](const int lo, const int hi) -> ll { n     if (lo > hi) return 0; n     ll ret = s[hi]; n     if (lo > 0) { n       ret -= s[lo - 1]; n     } n     return ret; n   }; n   vector<ll> c(n); n   for (int i = 0; i < n; ++i) c[i] = a[i] - t[i]; n   LazySegmentTree tree(move(c)); n   int q; n   cin >> q; n   while (q-- > 0) { n     char op; n     cin >> op; n     if (op ==  + ) { n       int pos, x; n       cin >> pos >> x; n       if (x == 0) continue; n       --pos; n       auto node = tree.query(pos, pos); n       ll d = node.mx + x; n       int lo = pos, hi = n; n       while (hi - lo > 1) { n         int m = lo + (hi - lo) / 2; n         node = tree.query(lo, m); n         if (node.mx >= d) { n           hi = m; n         } else { n           lo = m; n         } n       } n       tree.assign(pos, lo, d); n     } else { n       int lo, hi; n       cin >> lo >> hi; n       --lo; n       --hi; n       auto node = tree.query(lo, hi); n       cout << node.sm + sum(lo, hi) << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   long long ca; n   cin >> ca; n   while (ca--) { n     long long n, i, j, k, l, r, m; n     cin >> l >> r >> m; n     for (i = l; i <= r; i++) { n       long long x1, x2; n       x1 = m / i; n       if (m % i != 0) n         x2 = m / i + 1; n       else n         x2 = m / i; n       long long y1 = m - (x1 * i); n       long long y2 = (x2 * i) - m; n       long long lim = r - l; n       if (y1 <= lim && x1 > 0) { n         cout << i <<     << l + y1 <<     << l << endl; n         break; n       } n       if (y2 <= lim && x2 > 0) { n         cout << i <<     << l <<     << l + y2 << endl; n         break; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool debug = false; n int n, m, k; n int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; n bool ck(int k) { n   double ss = (double)k * m, cnt = 1; n   double C = 1, A = k, B = 1; n   for (long long lp = 1; cnt < n && ss > 0 && A >= 0; lp++) { n     C = C * A / B; n     A--; n     B++; n     double y = min(C, ss / lp); n     cnt += y; n     ss -= y * lp; n   } n   return cnt >= n; n } n int main() { n   int t; n   scanf( %d , &t); n   while (t--) { n     scanf( %d%d , &n, &m); n     int l = 0, r = n; n     while (l + 1 < r) { n       int mid = (l + r) / 2; n       if (ck(mid)) n         r = mid; n       else n         l = mid + 1; n     } n     if (ck(l)) n       printf( %d n , l); n     else n       printf( %d n , r); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, sz[1005], lab[1005], cur = 1, cur2, f = 1; n vector<int> v[1005]; n int getsz(int node, int p) { n   sz[node] = 1; n   for (int u : v[node]) { n     if (u != p) sz[node] += getsz(u, node); n   } n   return sz[node]; n } n int find(int node, int p) { n   for (int u : v[node]) { n     if (u != p && sz[u] > n / 2) return find(u, node); n   } n   return node; n } n void assign(int node, int p) { n   if (f) n     lab[node] = cur++; n   else n     lab[node] = (++cur2) * cur; n   printf( %d %d %d n , node, p, lab[node] - lab[p]); n   for (int u : v[node]) { n     if (u != p) assign(u, node); n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i < n; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     v[a].push_back(b); n     v[b].push_back(a); n   } n   getsz(1, 0); n   int c = find(1, 0); n   getsz(c, 0); n   vector<pair<int, int> > ch; n   for (int u : v[c]) ch.push_back({sz[u], u}); n   sort(ch.begin(), ch.end()); n   reverse(ch.begin(), ch.end()); n   for (auto p : ch) { n     assign(p.second, c); n     if (f && n <= 3 * cur && 3 * cur <= 2 * n) f = 0; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e18; n struct CHT { n   vector<long long> m, c; n   bool decSlope, askMin; n   CHT(bool slopeType, bool queryType) { n     decSlope = slopeType; n     askMin = queryType; n   } n   bool throwLine(long long l1, long long l2, long long l3) { n     if (decSlope) { n       if (askMin) n         return (double)(c[l2] - c[l1]) * (m[l1] - m[l3]) >= n                (double)(c[l3] - c[l1]) * (m[l1] - m[l2]); n       else n         return (c[l2] - c[l1]) * (m[l1] - m[l3]) <= n                (c[l3] - c[l1]) * (m[l1] - m[l2]); n     } else { n       if (!askMin) n         return (c[l2] - c[l1]) * (m[l1] - m[l3]) >= n                (c[l3] - c[l1]) * (m[l1] - m[l2]); n       else n         return (c[l2] - c[l1]) * (m[l1] - m[l3]) <= n                (c[l3] - c[l1]) * (m[l1] - m[l2]); n     } n   } n   void add(long long M, long long C) { n     m.push_back(M); n     c.push_back(C); n     while (((long long)m.size()) >= 3 && n            throwLine(((long long)m.size()) - 3, ((long long)m.size()) - 2, n                      ((long long)m.size()) - 1)) { n       m.erase(m.end() - 2); n       c.erase(c.end() - 2); n     } n   } n   long long f(long long i, long long x) { return m[i] * x + c[i]; } n   long long query(long long x) { n     long long l = 0, r = ((long long)m.size()) - 1, ret; n     if (askMin) n       ret = inf; n     else n       ret = -inf; n     while (l <= r) { n       long long m1 = l + (r - l) / 3; n       long long m2 = r - (r - l) / 3; n       if (f(m1, x) == f(m2, x)) { n         ret = f(m1, x); n         r = m2 - 1; n         l = m1 + 1; n       } else if (f(m1, x) < f(m2, x)) { n         if (askMin) { n           ret = f(m1, x); n           r = m2 - 1; n         } else { n           ret = f(m2, x); n           l = m1 + 1; n         } n       } else { n         if (askMin) { n           ret = f(m2, x); n           l = m1 + 1; n         } else { n           ret = f(m1, x); n           r = m2 - 1; n         } n       } n     } n     return ret; n   } n }; n const long long lim = 2e5 + 10; n long long a[lim]; n long long s[lim]; n long long p[lim]; n int main() { n   CHT machine(true, false); n   long long n; n   scanf( %lld , &n); n   for (long long i = 1; i <= n; i++) { n     scanf( %lld , &a[i]); n     p[i] = p[i - 1] + a[i]; n     s[i] = s[i - 1] + i * a[i]; n   } n   long long ans = s[n], ans2 = s[n]; n   for (long long i = n; i; i--) { n     machine.add(i, -p[i]); n     long long tmp = machine.query(a[i]) + p[i] - i * a[i] + s[n]; n     ans = max(ans, tmp); n   } n   CHT machine2(false, false); n   for (long long i = 1; i <= n; i++) { n     machine2.add(i, -p[i - 1]); n     long long tmp = machine2.query(a[i]) + p[i - 1] - i * a[i] + s[n]; n     ans2 = max(ans2, tmp); n   } n   cout << max(ans, ans2) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1000000000; n const long long mod = 998244353; n inline long long add(long long v1, long long v2) { n   v1 += v2; n   if (v1 >= mod) v1 -= mod; n   if (v1 < 0) v1 += mod; n   return v1; n } n inline long long mul(long long v1, long long v2) { return v1 * v2 % mod; } n inline long long mypow(long long v, long long t) { n   long long res = 1; n   while (t) { n     if (t & 1) res = res * v % mod; n     v = v * v % mod; n     t >>= 1; n   } n   return res; n } n inline void bye() { n   puts(  ); n   exit(0); n } n const int N = 303030; n int a[N]; n long long cnt[N]; n long long dp[8][N]; n long long fac[N], ifac[N]; n long long C(int v1, int v2) { n   if (v1 < v2) return 0; n   return mul(fac[v1], mul(ifac[v2], ifac[v1 - v2])); n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , a + i); n     cnt[a[i]]++; n   } n   fac[0] = 1; n   for (int i = 1; i < N; i++) { n     fac[i] = fac[i - 1] * i % mod; n   } n   ifac[N - 1] = mypow(fac[N - 1], mod - 2); n   for (int i = N - 2; i >= 0; i--) { n     ifac[i] = ifac[i + 1] * (i + 1) % mod; n   } n   for (int i = 1; i < N; i++) { n     for (int j = i * 2; j < N; j += i) { n       cnt[i] += cnt[j]; n     } n   } n   for (int i = 1; i < 8; i++) { n     for (int j = N - 1; j >= 1; j--) { n       dp[i][j] = C(cnt[j], i); n       for (int k = j * 2; k < N; k += j) { n         dp[i][j] = add(dp[i][j], -dp[i][k]); n       } n     } n     if (dp[i][1]) { n       printf( %d n , i); n       return 0; n     } n   } n   puts( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[200000], t[200000]; n int equi(int a, int b, int c, int d) { n   bool x = 1; n   for (int i = 0; i <= b - a; i++) { n     x &= (s[i + a] == t[i + c]); n   } n   if (x) return 1; n   if (b <= a) return 0; n   int n = b - a + 1; n   if (n % 2 == 1) return 0; n   if (equi(a, a + n / 2 - 1, c, c + n / 2 - 1)) { n     if (equi(a + n / 2, b, c + n / 2, d)) return 1; n   } n   if (equi(a, a + n / 2 - 1, c + n / 2, d)) { n     if (equi(a + n / 2, b, c, c + n / 2 - 1)) return 1; n   } n   return 0; n } n int main() { n   int n = 0; n   scanf( %s , s); n   scanf( %s , t); n   while (s[n++] !=   0 ) n     ; n   n--; n   if (equi(0, n - 1, 0, n - 1)) n     printf( YES ); n   else n     printf( NO ); n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> all; n vector<int> zu; n vector<int> de; n int main() { n   string x; n   cin >> x; n   int y = x.size() / 2; n   cout << x; n   for (size_t i = 0; i < y; i++) { n     swap(x[i], x[x.size() - i - 1]); n   } n   cout << x << endl; n   return 0; n } n


/* n   n     ----@sagittarius_k2----- n     Created by Ritesh Ranjan n     -> n   n */ n   n #define fio                            n    ios_base::sync_with_stdio(false);   n    cin.tie(NULL);                      n    cout.tie(NULL); n   n #include <bits/stdc++.h> n #include <iostream> n #include <set> n #include <algorithm> n #include <iterator> n   n   n using namespace std; n   n #define int long long int n   n #define M 1000000007 n   n using namespace std; n   n signed main() n { n     int t; n     cin>>t; n     while(t--) n     { n         int n; n         cin>>n; n         int a[n+1], b[n+1]; n         for(int i=1; i<=n; i++) n         { n             cin>>a[i]; n             b[i]=a[i]; n         } n         sort(a+1, a+n+1); n  n         int ans=-1, min_no=-1; n         for(int i=1; i<=n; i++) n         { n             int c=0; n             while(i<n && a[i]==a[i+1]) n             { n                 i++; n                 c++; n             } n             if(c==0) n             { n                 min_no=a[i]; n                 break; n             } n         } n         for(int i=1; i<=n; i++) n         { n             if(b[i]==min_no) n             { n                 ans=i; n                 break; n             } n         } n         cout<<ans<<  n ; n     } n }


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline T abs(T t) { n   return t < 0 ? -t : t; n } n const long long modn = 1000000007; n inline long long mod(long long x) { return x % modn; } n const int MAXN = 100010, INF = 0x3f3f3f3f; n int n, m, deg, s[MAXN], p[MAXN]; n int main() { n   scanf( %d , &n); n   for (int a = 0; a < n; a++) { n     scanf( %d , &s[a]); n     p[s[a]] = a; n   } n   int ult = -1, cnt = 0, res = 0; n   for (int a = 1; a <= n; a++) { n     if (p[a] > ult) { n       cnt++; n       ult = p[a]; n       res = max(cnt, res); n     } else { n       cnt = 1; n       ult = p[a]; n     } n   } n   printf( %d n , n - res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> g[4111]; n int f[4111], v[4111][4111]; n int main() { n   int n, m; n   cin >> n >> m; n   while (m--) { n     int a, b; n     cin >> a >> b; n     if (a > b) swap(a, b); n     g[a].push_back(b); n     f[a]++; n     f[b]++; n     v[a][b] = v[b][a] = 1; n   } n   int ans = -1; n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j < g[i].size(); j++) { n       for (int k = j + 1; k < g[i].size(); k++) { n         int a = g[i][j], b = g[i][k]; n         int w = f[a] + f[b] + f[i] - 6; n         if (v[a][b]) { n           if (ans == -1) n             ans = w; n           else n             ans = min(ans, w); n         } n       } n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n void smain(); n int main() { n   ios::sync_with_stdio(false); n   smain(); n   return 0; n } n const int maxn = 300000 + 10; n int num[maxn]; n int num1[maxn], num2[maxn]; n int tot = 1; n int min1[maxn], min2[maxn]; n int la1[maxn], la2[maxn]; n int flo(int a, int b) { n   int ans = a / b; n   if (a % b != 0) ans++; n   return ans; n } n const int INF = 2e9; n int a1[maxn], a2[maxn]; n int flag[maxn]; n bool cal(int n, int *Min, int *La, int *This, int *a1, int *a2) { n   bool flagg = false; n   int A1, A2; n   for (int i = (2); i <= (n); ++i) { n     if (Min[i - 1] == INF || This[i] == INF) continue; n     if (Min[i - 1] + This[i] <= i) { n       flagg = true; n       A1 = La[i - 1]; n       A2 = i; n       break; n     } n   } n   if (!flagg) return false; n   a1[0] = Min[A1]; n   a2[0] = This[A2]; n   int i = 1, j = 1; n   for (j = 1; j < a1[0]; ++i) { n     a1[j] = flag[i]; n     ++j; n   } n   a1[j] = flag[A1]; n   for (j = 1; j < a2[0]; ++i) { n     if (i == A1) continue; n     a2[j] = flag[i]; n     ++j; n   } n   a2[j] = flag[A2]; n   return true; n } n struct Node { n   int o, flag; n } node[maxn]; n bool cmp(Node a, Node b) { return a.o > b.o; } n void smain() { n   int n, x1, x2; n   cin >> n >> x1 >> x2; n   for (int i = (1); i <= (n); ++i) cin >> num[i]; n   for (int i = (1); i <= (n); ++i) node[i].o = num[i], node[i].flag = i; n   sort(node + 1, node + n + 1, cmp); n   for (int i = (1); i <= (n); ++i) num[i] = node[i].o, flag[i] = node[i].flag; n   int tmp; n   for (int i = (1); i <= (n); ++i) { n     tmp = flo(x1, num[i]); n     if (tmp > i) tmp = INF; n     min1[i] = num1[i] = tmp; n     tmp = flo(x2, num[i]); n     if (tmp > i) tmp = INF; n     min2[i] = num2[i] = tmp; n     la1[i] = la2[i] = i; n   } n   for (int i = (2); i <= (n); ++i) { n     if (min1[i - 1] <= min1[i]) { n       min1[i] = min1[i - 1]; n       la1[i] = la1[i - 1]; n     } n     if (min2[i - 1] <= min2[i]) { n       min2[i] = min2[i - 1]; n       la2[i] = la2[i - 1]; n     } n   } n   int ans1 = -1, ans2 = -1; n   if (cal(n, min1, la1, num2, a1, a2)) { n   } else if (cal(n, min2, la2, num1, a2, a1)) { n   } else { n     cout <<  No  << endl; n     return; n   } n   cout <<  Yes  << endl; n   cout << a1[0] <<     << a2[0] << endl; n   for (int i = 1; a1[i] != 0; ++i) cout << a1[i] <<    ; n   cout << endl; n   for (int i = 1; a2[i] != 0; ++i) cout << a2[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}; n int dy[] = {1, 0, -1, 0, 1, -1, 1, -1}; n void fast() { n   std::ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n } n string t; n bool solve(int m) { return t.substr(0, m) == t.substr(t.size() - m); } n int main() { n   fast(); n   ; n   int n, k; n   cin >> n >> k; n   cin >> t; n   int idx = 1; n   int mx = 0; n   while (idx <= t.size() / 2) { n     if (solve(idx)) { n       mx = max(mx, idx); n     } n     idx++; n   } n   string s = t.substr(mx); n   string a = t; n   for (int i = 0; i < k - 1; i++) a += s; n   mx = 0; n   while (k) { n     for (idx = 0; k; idx++) { n       if (a.substr(idx, t.size()) == t) { n         k--; n         mx = idx + t.size(); n         if (k == 0) break; n       } n     } n   } n   cout << a.substr(0, mx) <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int query(int x) { n   printf( ? %d n , x); n   int res; n   fflush(stdout); n   scanf( %d , &res); n   return res; n } n int main() { n   int n; n   scanf( %d , &n); n   int m = n / 2; n   if (m % 2 == 1) { n     printf( ! -1 n ); n     exit(0); n   } n   int d = query(1) - query(m + 1); n   if (d == 0) { n     printf( ! 1 n ); n     exit(0); n   } n   int l = 2, r = m; n   while (l <= r) { n     int mid = (l + r) / 2; n     int t = query(mid) - query(mid + m); n     if (!t) { n       printf( ! %d n , mid); n       exit(0); n     } n     if ((t < 0 && d < 0) || (t > 0 && d > 0)) n       l = mid + 1; n     else n       r = mid - 1; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 7; n void solve() { n   long long int n; n   cin >> n; n   vector<long long int> a(n), b; n   for (auto i = 0; i < (n); i++) { n     cin >> a[i]; n   }; n   int cnt = 0, pos1 = 0, pos2 = 0; n   for (auto i = 0; i < (n); i++) n     if (a[i] != i + 1) { n       b.push_back((i)); n       cnt++; n     } n   bool flag = true; n   long long int x = b.size(); n   for (auto i = 0; i < (x - 1); i++) { n     if (b[i + 1] - b[i] != 1) flag = false; n   } n   if (cnt == 0) n     cout << 0; n   else if (flag) n     cout << 1; n   else if (cnt == 2) { n     cout << 2; n   } else if (cnt == n) n     cout << 1; n   else if (cnt > 2) n     cout << 2; n } n void template1() { n   long long int t; n   cin >> t; n   while (t--) { n     solve(); n     cout <<   n ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   template1(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int sdf[30] = {4,   22,  27,  58,  85,  94,  121, 166, 202, 265, n                274, 319, 346, 355, 378, 382, 391, 438, 454, 483, n                517, 526, 535, 562, 576, 588, 627, 634, 636, 645}; n long long int a[71720], b, c, d, n, m, i, j, k, sum, sumend; n bool cmp(int a, int b) { return a > b; } n int gcd(int a, int b) { n   if (!b) return a; n   return gcd(b, a % b); n } n int gqt(int n) { n   if (!n || n) return 0; n   if (n == 2) return 1; n   for (int i = 3; i <= sqrt(n); i++) n     if (n % i == 0) return 0; n   return 1; n } n int main() { n   cin >> n; n   for (i = 1; i <= n; i++) cin >> a[i]; n   sum = a[n]; n   sort(a + 1, a + n + 1); n   sumend = a[n]; n   cout << (sumend ^ sum) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 998244353; n const int BASE = 27; n const int N = 200000 + 2; n const int LOGN = 20; n const long long oo = 1e18; n const double EPS = 1e-9; n int n, q, a[N], mn[N], mx[N], freq[N], dsu[N], bst[N], sum[N]; n int find(int i) { return dsu[i] == i ? i : dsu[i] = find(dsu[i]); } n struct seg { n   int l, r, val; n   seg(int _l, int _r, int _val) { l = _l, r = _r, val = _val; } n   bool operator<(const seg& sg) const { return l < sg.l; } n }; n vector<seg> cln; n vector<seg> sg; n int main() { n   memset(mn, -1, sizeof mn); n   cin >> n >> q; n   for (int i = 1; i <= 200000; ++i) dsu[i] = i; n   for (int i = 0; i < n; ++i) { n     scanf( %d , &a[i]); n     freq[a[i]]++; n     if (mn[a[i]] == -1) { n       mn[a[i]] = mx[a[i]] = i; n     } n     mx[a[i]] = max(mx[a[i]], i); n     mn[a[i]] = min(mn[a[i]], i); n   } n   for (int i = 1; i <= 200000; ++i) { n     if (mn[i] == -1) continue; n     sg.push_back(seg(mn[i], mx[i], i)); n   } n   sort(sg.begin(), sg.end()); n   for (int i = 0; i < sg.size(); ++i) { n     if (cln.size() && cln.back().r >= sg[i].l) { n       dsu[find(cln.back().val)] = find(sg[i].val); n       cln.back().r = max(cln.back().r, sg[i].r); n       continue; n     } n     cln.push_back(sg[i]); n   } n   for (int i = 1; i <= 200000; ++i) { n     if (mn[i] == -1) continue; n     bst[find(i)] = max(bst[find(i)], freq[i]); n     sum[find(i)] += freq[i]; n   } n   int ans = 0; n   for (int i = 1; i <= 200000; ++i) { n     if (find(i) == i) { n       ans += sum[i] - bst[i]; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct query { n   int t = 0, row = 0, col = 0; n   long long x = 0; n }; n int n, m; n vector<vector<long long>> mat; n void rotate_row(int row) { n   long long temp = mat[row][m]; n   for (int i = m; i > 1; i--) { n     mat[row][i] = mat[row][i - 1]; n   } n   mat[row][1] = temp; n } n void rotate_col(int col) { n   long long temp = mat[n][col]; n   for (int i = n; i > 1; i--) { n     mat[i][col] = mat[i - 1][col]; n   } n   mat[1][col] = temp; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int T = 1; n   while (T--) { n     long long q; n     cin >> n >> m >> q; n     for (int i = 0; i <= n; i++) { n       vector<long long> temp(m + 1, 0); n       mat.push_back(temp); n     } n     stack<query> s; n     while (q--) { n       int t, row, col; n       long long x; n       query temp; n       cin >> t; n       if (t == 1) { n         cin >> row; n         temp.t = t; n         temp.row = row; n       } n       if (t == 2) { n         cin >> col; n         temp.t = t; n         temp.col = col; n       } n       if (t == 3) { n         cin >> row >> col >> x; n         temp.row = row; n         temp.col = col; n         temp.x = x; n         temp.t = t; n       } n       s.push(temp); n     } n     while (!s.empty()) { n       int t = s.top().t; n       int row = s.top().row; n       int col = s.top().col; n       long long x = s.top().x; n       if (t == 1) { n         rotate_row(row); n       } n       if (t == 2) { n         rotate_col(col); n       } n       if (t == 3) { n         mat[row][col] = x; n       } n       s.pop(); n     } n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= m; j++) { n         cout << mat[i][j] <<    ; n       } n       cout << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   while (~scanf( %d , &n)) { n     int t = sqrt(n * 1.0); n     for (int i = t; i >= 1; i--) { n       if (n % i == 0) { n         cout << i <<     << n / i << endl; n         break; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i; n   int a, b; n   int draw = 0, awin = 0, bwin = 0; n   cin >> a >> b; n   for (i = 1; i < 7; i++) { n     if (abs(i - a) == abs(i - b)) n       draw++; n     else if (abs(i - a) > abs(i - b)) n       bwin++; n     else n       awin++; n   } n   cout << awin <<     << draw <<     << bwin << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC target( sse4 ) n using namespace std; n template <class T> n bool ckmin(T& a, const T& b) { n   return b < a ? a = b, 1 : 0; n } n template <class T> n bool ckmax(T& a, const T& b) { n   return a < b ? a = b, 1 : 0; n } n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n const long double pii = 3.14159265359; n const int MOD = 1000000007; n const char nl =   n ; n const int MX = 200001; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   string str; n   cin >> str; n   vector<int> v(6); n   for (int x = 0; x < (6); x++) v[x] = str[x] -  0 ; n   vector<int> val(6); n   int mn = INT_MAX; n   for (int z = 0; z < (10); z++) { n     if (z == v[0]) n       val[0] = 1; n     else n       val[0] = 0; n     for (int b = 0; b < (10); b++) { n       if (b == v[1]) n         val[1] = 1; n       else n         val[1] = 0; n       for (int c = 0; c < (10); c++) { n         if (c == v[2]) n           val[2] = 1; n         else n           val[2] = 0; n         for (int d = 0; d < (10); d++) { n           if (d == v[3]) n             val[3] = 1; n           else n             val[3] = 0; n           for (int e = 0; e < (10); e++) { n             if (e == v[4]) n               val[4] = 1; n             else n               val[4] = 0; n             for (int first = 0; first < (10); first++) { n               if (first == v[5]) n                 val[5] = 1; n               else n                 val[5] = 0; n               if (z + b + c == d + e + first) n                 ckmin(mn, 6 - (val[0] + val[1] + val[2] + val[3] + val[4] + n                                val[5])); n             } n           } n         } n       } n     } n   } n   cout << mn << nl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n using pii = pair<int, int>; n const int N = 2e5 + 5, M = 998244353, INF = 0x3f3f3f3f; n void Main(); n void print() { cout <<   n ; } n template <typename T, typename... U> n void print(const T& x, const U&... y) { n   ((sizeof...(y) == 0) ? (cout << x) : (cout << x <<    )); n   print(y...); n } n template <typename T> n void print(const T& a, int l, int r, char c) { n   for (int i = l; i <= r; ++i) { n     cout << a[i]; n     if (i == r) n       cout <<   n ; n     else n       cout << c; n   } n } n void input() {} n template <typename T, typename... U> n void input(T& x, U&... y) { n   cin >> x; n   input(y...); n } n template <typename T> n void input(T& a, int l, int r, bool f) { n   for (int i = l; i <= r; ++i) cin >> a[i]; n } n template <typename T> n void Max(T& a, T b) { n   a < b ? a = b : 1; n } n template <typename T> n void Min(T& a, T b) { n   a > b ? a = b : 1; n } n template <typename T> n void Add(T& a, T b) { n   a += b, a > M ? a -= M : 1; n } n template <typename T> n void Mul(T& a, T b) { n   a = a * b % M; n } n int main(int argc, char** argv) { n   ios::sync_with_stdio(0), cin.tie(0); n   Main(); n } n struct Dinic { n   int tot, S, T; n   struct edge { n     int v, w, rev; n   }; n   vector<edge> G[N]; n   void add(int u, int v, int w) { n     G[u].push_back({v, w, (int)G[v].size()}); n     G[v].push_back({u, 0, (int)G[u].size() - 1}); n   } n   void init(int tot_) { n     tot = tot_; n     for (int i = 0; i <= tot_; i++) G[i].clear(); n   } n   int dis[N], cur[N], num[N], pv[N], pe[N]; n   void bfs() { n     for (int i = 0; i <= tot; i++) dis[i] = INF; n     dis[T] = 0; n     queue<int> q; n     q.push(T); n     while (!q.empty()) { n       int u = q.front(); n       q.pop(); n       for (edge& e : G[u]) n         if (G[e.v][e.rev].w && dis[e.v] == INF) n           dis[e.v] = dis[u] + 1, q.push(e.v); n     } n   } n   int augment() { n     int u = T, ans = INF; n     while (u != S) { n       ans = min(ans, G[pv[u]][pe[u]].w); n       u = pv[u]; n     } n     u = T; n     while (u != S) { n       G[pv[u]][pe[u]].w -= ans; n       G[u][G[pv[u]][pe[u]].rev].w += ans; n       u = pv[u]; n     } n     return ans; n   } n   int maxflow(int S_, int T_) { n     S = S_, T = T_; n     bfs(); n     for (int i = 1; i <= tot; i++) num[i] = 0, cur[i] = 0; n     for (int i = 1; i <= tot; i++) n       if (dis[i] != INF) num[dis[i]]++; n     int ans = 0, u = S; n     while (dis[S] < tot) { n       if (u == T) { n         ans += augment(); n         u = S; n       } n       bool adv = 0; n       for (int& i = cur[u]; i < G[u].size(); i++) { n         int v = G[u][i].v, w = G[u][i].w; n         if (w <= 0 || dis[u] != dis[v] + 1) continue; n         cur[u] = i; n         adv = 1, pv[v] = u, pe[v] = i, u = v; n         break; n       } n       if (!adv) { n         if (dis[u] != INF && --num[dis[u]] == 0) break; n         dis[u] = tot - 1; n         for (const edge& e : G[u]) n           if (e.w > 0) dis[u] = min(dis[u], dis[e.v]); n         num[++dis[u]]++; n         cur[u] = 0; n         if (u != S) u = pv[u]; n       } n     } n     return ans; n   } n } D; n int tot, n, m, id[N << 2], L, R, now; n void build(int o, int l, int r) { n   if (l == r) { n     id[o] = ++tot; n     D.add(id[o], n + l, 1); n     return; n   } n   id[o] = ++tot; n   int mid = (l + r) / 2; n   build((o << 1), l, mid), build(((o << 1) | 1), mid + 1, r); n   D.add(id[o], id[(o << 1)], INF), D.add(id[o], id[((o << 1) | 1)], INF); n } n void update(int o, int l, int r) { n   if (l > R || r < L) return; n   if (L <= l && r <= R) { n     D.add(now, id[o], 1); n     return; n   } n   int mid = (l + r) / 2; n   update((o << 1), l, mid), update(((o << 1) | 1), mid + 1, r); n } n void dfs(int u, int fa, int& ans) { n   if (u <= n) { n     ans = u; n     return; n   } n   for (int i = (int)D.G[u].size() - 1; i >= 0; --i) { n     Dinic::edge& e = D.G[u][i]; n     if (e.v && e.w > 0) { n       dfs(e.v, u, ans); n       --e.w; n       return; n     } n   } n } n int A[N], B[N], C[N], ans[N], num[N]; n void Main() { n   input(n, m); n   tot = n + m; n   build(1, 1, m); n   D.tot = tot + 2; n   const int S = tot + 1, T = tot + 2; n   for (int i = 1, op, k, x; i <= n; ++i) { n     input(op); n     if (op == 0) { n       D.add(S, i, 1); n       input(k); n       while (k--) { n         input(x); n         D.add(i, x + n, 1); n       } n     } else if (op == 1) { n       D.add(S, i, 1); n       input(L, R); n       now = i; n       update(1, 1, m); n     } else { n       D.add(S, i, 2); n       input(A[i], B[i], C[i]); n       D.add(i, A[i] + n, 1); n       D.add(i, B[i] + n, 1); n       D.add(i, C[i] + n, 1); n     } n   } n   for (int i = 1; i <= m; ++i) D.add(i + n, T, 1); n   print(D.maxflow(S, T)); n   for (Dinic::edge e : D.G[T]) n     if (e.w) dfs(e.v, T, ans[e.v - n]); n   for (int i = 1; i <= m; ++i) ++num[ans[i]]; n   for (int i = 1; i <= n; ++i) n     if (A[i] && num[i] == 1) { n       if (ans[A[i]] != i) n         ans[A[i]] = i; n       else n         ans[B[i]] = i; n     } n   for (int i = 1; i <= m; ++i) n     if (ans[i]) print(ans[i], i); n } n


#include <bits/stdc++.h> n using namespace std; n int i; n double x, y, n, a, b, rsa, rsb = 1; n long long cmmdc(long long a, long long b) { n   while (a && b) (a > b ? a %= b : b %= a); n   return a + b; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin >> x >> y >> n; n   for (b = 1; b <= n; ++b) { n     a = max(0LL, (long long)(x * b / y) - 5); n     for (i = 0; i < 10; ++i, ++a) { n       double gmb = fabs(x * b - y * a) / (y * b); n       double fnc = fabs(x * rsb - y * rsa) / (y * rsb); n       if (gmb < fnc) n         rsb = b, rsa = a; n       else if (gmb == fnc && a / cmmdc(a, b) < rsa / cmmdc(rsa, rsb)) n         rsa = a, rsb = b; n     } n   } n   long long ggg = cmmdc(rsa, rsb); n   cout << (long long)(rsa) / ggg <<  /  << (long long)(rsb) / ggg <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, R, C, g[110][110]; n vector<int> A, B; n int main() { n   scanf( %d %d %d , &N, &R, &C); n   for (int i = 1; i <= (N); i++) { n     if (i & 1) n       A.push_back(i); n     else n       B.push_back(i); n   } n   for (int r = 1; r <= (R); r++) n     for (int c = 1; c <= (C); c++) { n       if ((r + c) % 2 == 0 && A.size()) g[r][c] = A.back(), A.pop_back(); n       if ((r + c) % 2 == 1 && B.size()) g[r][c] = B.back(), B.pop_back(); n     } n   if (A.size() || B.size()) n     puts( -1 ); n   else { n     for (int r = 1; r <= (R); r++) { n       for (int c = 1; c <= (C); c++) printf( %d  , g[r][c]); n       puts(  ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k; n int s[100005]; n int mask[25]; n struct Reg { n   int l, r; n } reg[23][100]; n bool test(int p) { n   if (p == n) return true; n   set<int> q[2]; n   set<int>::iterator pp; n   int now = 1, nxt = 1; n   q[0].insert(mask[p] - 1); n   for (int i = p; i < n; i++) { n     nxt = now; n     now = now ^ 1; n     for (pp = q[now].begin(); pp != q[now].end(); pp++) { n       int mask_n = *pp; n       bool ok = false; n       for (int j = 1; j <= reg[i][0].l; j++) { n         if ((mask[reg[i][j].l] & mask_n) && (mask[reg[i][j].r] & mask_n)) { n           ok = true; n           break; n         } n       } n       if (ok) { n         for (int j = 0; j < i; j++) { n           if (mask_n & mask[j]) { n             q[nxt].insert((mask_n - mask[j]) | mask[i]); n           } n         } n       } n     } n     q[now].clear(); n   } n   return (!q[now ^ 1].empty()); n } n int main() { n   mask[0] = 1; n   for (int i = 1; i < 25; i++) mask[i] = (mask[i - 1] << 1); n   cin >> n; n   for (int i = 0; i < (n); i++) cin >> s[i]; n   bool ok = true; n   for (int i = 1; i < n; i++) { n     ok = false; n     for (int j = 0; j < i; j++) { n       for (int k = 0; k <= j; k++) { n         if (s[j] + s[k] == s[i]) { n           ok = true; n           reg[i][0].l++; n           reg[i][reg[i][0].l].l = j; n           reg[i][reg[i][0].l].r = k; n         } n       } n     } n     if (ok == false) break; n   } n   if (!ok) { n     cout << -1 << endl; n     return 0; n   } n   int l = 1, r = n; n   int ret = -1; n   while (l <= r) { n     int mid = (l + r) / 2; n     if (test(mid)) { n       r = mid - 1; n       ret = mid; n     } else { n       l = mid + 1; n     } n   } n   cout << ret << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int a, b, s; n   cin >> a >> b >> s; n   if (s < abs(a) + abs(b)) n     cout <<  NO  << endl; n   else if (s == abs(a) + abs(b)) n     cout <<  YES  << endl; n   else { n     s -= abs(a); n     s -= abs(b); n     if (s % 2 == 0) 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 int main(int argc, char** argv) { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   unordered_map<int, int> idx; n   int N, x; n   cin >> N; n   while (N--) { n     cin >> x; n     if (x) idx[x] = 1; n   } n   cout << idx.size() << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n static inline void canhazfast() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n } n template <typename T> n T gcd(T a, T b) { n   return b == 0 ? a : gcd(b, a % b); n } n template <typename T> n T extgcd(T a, T b, T &x, T &y) { n   T x0 = 1, y0 = 0, x1 = 0, y1 = 1; n   while (b) { n     T q = a / b; n     a %= b; n     swap(a, b); n     x0 -= q * x1; n     swap(x0, x1); n     y0 -= q * y1; n     swap(y0, y1); n   } n   x = x0; n   y = y0; n   return a; n } n int main() { n   canhazfast(); n   static int a[100016]; n   static char b[100016]; n   int n; n   int l = -1000000000, r = 1000000000; n   cin >> n; n   for (int i = 0; i < n; ++i) cin >> a[i]; n   cin >> b; n   for (int i = 4; i < n; ++i) { n     if (b[i] != b[i - 1]) { n       if (b[i] ==  0 ) n         for (int j = 0; j <= 4; ++j) r = min(r, a[i - j] - 1); n       else n         for (int j = 0; j <= 4; ++j) l = max(l, a[i - j] + 1); n     } n   } n   cout << l <<     << r <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 300000; n const long long INF = 1e18; n const int sqrtConst = 550; n const int alphabet = 26; n const long long mod = 998244353; n void solve() { n   string s; n   cin >> s; n   bool has1 = false; n   for (int i = 1; i < s.size(); i++) { n     if (s[i] ==  1 ) { n       has1 = true; n       break; n     } n   } n   int cnt = (s.size() + 1) / 2; n   if (!has1 && (s.size() % 2)) cnt--; n   cout << cnt; n } n int main() { n   cin.tie(0); n   cout.tie(0); n   ios_base::sync_with_stdio(false); n   cout << setprecision(6) << fixed; n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int Q, N, M, K, L; n bool board[10001][3]; n long long dp[10001][8]; n int bitCheck[4][2][2] = { n     {{-2, 0}, {-1, 0}}, {{1, 0}, {2, 0}}, {{0, 1}, {0, 2}}, {{0, -1}, {0, -2}}}; n void getNextStates(int n, int m, int thisState, int nextState, n                    vector<int>& res) { n   if (m == 3) { n     res.push_back(nextState); n     return; n   } n   if (board[n][m] || (thisState & (1 << m))) { n     getNextStates(n, m + 1, thisState, nextState, res); n     return; n   } n   if (n < N - 1) { n     if (!board[n + 1][m]) n       getNextStates(n, m + 1, thisState, nextState | (1 << m), res); n   } n   if (m < 2) { n     if (!board[n][m + 1] && !(thisState & (1 << (m + 1)))) n       getNextStates(n, m + 2, thisState, nextState, res); n   } n } n long long solve(int n, int state) { n   if (n == N) { n     return 1LL; n   } n   long long& ret = dp[n][state]; n   if (~ret) return ret; n   ret = 0; n   vector<int> next; n   getNextStates(n, 0, state, 0, next); n   for (int i = 0; i < next.size(); i++) { n     ret += solve(n + 1, next[i]); n     ret %= 1000000007LL; n   } n   return ret; n } n int x, y; n long long ret; n void solve2(int n, int cnt) { n   if (n == 4) { n     if (!cnt) return; n     memset(dp, -1, sizeof dp); n     long long t = solve(0, 0); n     if (cnt % 2) n       ret += t; n     else n       ret -= t; n     ret = (ret + 1000000007LL) % 1000000007LL; n     return; n   } n   solve2(n + 1, cnt); n   bool flag = true; n   for (int j = 0; j < 2; j++) { n     int nx = x + bitCheck[n][j][0]; n     int ny = y + bitCheck[n][j][1]; n     if (nx < 0 || ny < 0 || nx >= N || ny >= 3 || board[nx][ny]) flag = false; n   } n   if (!flag) return; n   for (int j = 0; j < 2; j++) { n     int nx = x + bitCheck[n][j][0]; n     int ny = y + bitCheck[n][j][1]; n     board[nx][ny] = 1; n   } n   solve2(n + 1, cnt + 1); n   for (int j = 0; j < 2; j++) { n     int nx = x + bitCheck[n][j][0]; n     int ny = y + bitCheck[n][j][1]; n     board[nx][ny] = 0; n   } n } n int main() { n   cin >> N; n   board[N][0] = board[N][1] = board[N][2] = 1; n   for (int i = 0; i < 3; i++) { n     string s; n     cin >> s; n     for (int j = 0; j < N; j++) { n       board[j][i] = s[j] ==  .  ? false : true; n       if (s[j] ==  O ) { n         y = i; n         x = j; n       } n     } n   } n   solve2(0, 0); n   cout << ret; n   cin >> N; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n int n, m, mex = N, ans[N]; n pair<int, int> a[N]; n int main() { n   cin >> n >> m; n   for (int i = 1; i <= m; ++i) { n     int l, r; n     cin >> l >> r; n     a[i] = {l, r}; n     mex = min(mex, r - l + 1); n   } n   int cur = 0; n   cout << mex <<   n ; n   for (int i = 1; i <= n; ++i) { n     if (cur == mex) cur = 0; n     cout << cur++ <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, j, n, m, l, r, q, nr; n   string s; n   string t; n   cin >> n >> m >> q; n   cin >> s >> t; n   int cnt[1001] = {0}; n   for (int i = 0; i <= n - m; i++) { n     if (s.substr(i, m) == t) { n       cnt[i] = 1; n     } n   } n   l = 0; n   r = 0; n   for (i = 1; i <= q; i++) { n     cin >> l >> r; n     nr = 0; n     for (j = l - 1; j <= r - m; j++) { n       if (cnt[j]) nr++; n     } n     cout << nr <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool compare(string &s1, string &s2) { return s1.size() < s2.size(); } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   vector<string> s; n   string str; n   int n, i, j, flag = 0; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> str; n     s.push_back(str); n   } n   sort(s.begin(), s.end(), compare); n   for (i = 0; i < n - 1; i++) { n     j = 0; n     while (j < s[i + 1].length()) { n       int l = s[i].length(); n       flag = 0; n       if (s[i] == s[i + 1].substr(j, l)) { n         flag = 1; n         break; n       } n       j++; n     } n     if (flag != 1) { n       cout <<  NO n ; n       break; n     } n   } n   if (flag == 1 || n == 1) { n     cout <<  YES n ; n     for (i = 0; i < n; i++) { n       cout << s[i] <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a, b, t, c, j, k, T, i, A[1028], B[1028], C[1028]; n int main() { n   cin >> a >> b; n   while (a > 0) { n     a--; n     t++; n     if (t == b) { n       t = 0; n       a++; n     } n     j++; n   } n   cout << j; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(3) n using namespace std; n const long long INF = 2e18; n const int maxn = 1e6 + 6; n const int mod = 1e9 + 6; n const double eps = 1e-15; n inline bool read(long long &num) { n   char in; n   bool IsN = false; n   in = getchar(); n   if (in == EOF) return false; n   while (in !=  -  && (in <  0  || in >  9 )) in = getchar(); n   if (in ==  - ) { n     IsN = true; n     num = 0; n   } else n     num = in -  0 ; n   while (in = getchar(), in >=  0  && in <=  9 ) { n     num *= 10, num += in -  0 ; n   } n   if (IsN) num = -num; n   return true; n } n long long n, m, p; n long long num[maxn]; n vector<long long> v; n int vis[maxn]; n int getid(long long x) { n   return lower_bound(v.begin(), v.end(), x) - v.begin() + 1; n } n long long dp[maxn][2]; n long long pre[maxn], first[maxn], sc[maxn]; n int main() { n   int T; n   scanf( %d , &T); n   while (T--) { n     read(n); n     v.clear(); n     for (int i = 1; i <= n; i++) { n       vis[i] = 0; n       dp[i][0] = dp[i][1] = 0; n       pre[i] = 0; n       first[i] = 0; n       sc[i] = -(1e9 + 7); n     } n     for (int i = 1; i <= n; i++) { n       read(num[i]); n       v.push_back(num[i]); n     } n     long long maxl = 0; n     sort(v.begin(), v.end()); n     v.erase((unique(v.begin(), v.end())), v.end()); n     for (int i = 1; i <= n; i++) vis[getid(num[i])]++; n     for (int i = 1; i <= n; i++) { n       int id = getid(num[i]); n       pre[id]++; n       dp[id][0] = dp[id][0] + 1; n       if (pre[id] == 1) first[id] = max(dp[id - 1][0], dp[id - 1][1]); n       if (pre[id] == vis[id]) dp[id][1] = first[id] + vis[id]; n       sc[id] = n           max(sc[id], max(dp[id - 1][0] - pre[id], dp[id - 1][1] - pre[id])); n       maxl = max(maxl, sc[id] + pre[id] + 1); n       maxl = max(maxl, max(dp[id][0], dp[id][1])); n     } n     printf( %lld n , n - maxl); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const unsigned long long Mode = 1e9 + 7; n void Modulo(unsigned long long &x) { x = ((x % Mode + Mode) % Mode); } n unsigned long long Pow(unsigned long long x, unsigned long long y) { n   unsigned long long res = 1; n   for (unsigned long long i = 0; (1ULL << i) <= y; i++, x *= x, Modulo(x)) n     if (y & (1ULL << i)) res *= x, Modulo(res); n   return res; n } n int main() { n   unsigned long long n, ans = 1, D = 1; n   cin >> n; n   D = n; n   for (unsigned long long i = 2ULL * n - 1; i > 0; i--) ans *= i, Modulo(ans); n   for (unsigned long long i = 1; i <= n - 1; i++) D *= i * i, Modulo(D); n   ans *= Pow(D, Mode - 2); n   ans *= 2ULL; n   Modulo(ans); n   ans -= n; n   Modulo(ans); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 5; n int vals[N], found[N]; n struct node { n   node *left, *right; n   int val, size, priority; n   node(int v) { n     val = v, size = 1, priority = rand(), left = NULL, right = NULL; n   } n }; n int sz(node* t) { return (t) ? t->size : 0; } n void upd_sz(node*& t) { n   if (t) t->size = sz(t->left) + 1 + sz(t->right); n } n void split(node* t, node*& l, node*& r, int k) { n   if (!t) n     l = r = NULL; n   else if (sz(t->left) + 1 <= k) n     split(t->right, t->right, r, k - sz(t->left) - 1), l = t; n   else n     split(t->left, l, t->left, k), r = t; n   upd_sz(t); n } n void merge(node*& t, node* l, node* r) { n   if (!l || !r) n     t = l ? l : r; n   else if (l->priority >= r->priority) n     merge(l->right, l->right, r), t = l; n   else n     merge(r->left, l, r->left), t = r; n   upd_sz(t); n } n int main() { n   srand(time(NULL)); n   int n, m, x, y; n   scanf( %d %d , &n, &m); n   node* t = NULL; n   for (int i = 1; i <= n; i++) { n     merge(t, t, new node(i)); n   } n   node* a; n   node* b; n   while (m--) { n     scanf( %d %d , &x, &y); n     split(t, a, t, y); n     split(a, a, b, y - 1); n     if (vals[b->val] == x) { n     } else if (vals[b->val] == 0 && found[x] == 0) n       vals[b->val] = x; n     else { n       printf( -1 n ); n       return 0; n     } n     found[x] = 1; n     merge(a, b, a); n     merge(t, a, t); n   } n   int f = 1; n   for (int i = 1; i <= n; i++) { n     if (vals[i] == 0) { n       while (found[f] != 0) { n         f++; n       } n       vals[i] = f++; n     } n   } n   for (int i = 1; i <= n; i++) { n     printf( %d  , vals[i]); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6; n int n, t[1000001]; n struct data { n   int num, loc, vis; n } b[1000001]; n int a[1000001]; n int lowbit(int x) { return x & (-x); } n int Query(int x) { n   int sum = 0; n   while (x > 0) { n     sum = max(sum, t[x]); n     x -= lowbit(x); n   } n   return sum; n } n void Add(int x, int va) { n   while (x <= N) { n     t[x] = max(t[x], va); n     x += lowbit(x); n   } n } n bool cmp(data p, data q) { return p.num < q.num; } n bool cmp2(data p, data q) { return p.vis < q.vis; } n int work() { n   memset(t, 0, sizeof(t)); n   for (int i = 1; i <= n; i++) { n     b[i].num = a[i]; n     b[i].vis = i; n   } n   sort(b + 1, b + n + 1, cmp); n   for (int i = 1; i <= n; i++) b[i].loc = n + 1 - i; n   sort(b + 1, b + n + 1, cmp2); n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     int nowans = Query(b[i].loc); n     Add(b[i].loc, i); n     if (nowans == 0) continue; n     ans = max(ans, b[i].num ^ b[nowans].num); n   } n   return ans; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   int ans = work(); n   for (int i = 1; i <= n / 2; i++) swap(a[i], a[n + 1 - i]); n   ans = max(ans, work()); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n string s; n int main() { n   cin.tie(0); n   std::ios::sync_with_stdio(false); n   cin >> n >> k; n   cin >> s; n   if (k == 2) { n     string s1 =   , s2 =   ; n     for (int i = 0; i < s.size(); i++) n       if (i & 1) n         s1 +=  A , s2 +=  B ; n       else n         s1 +=  B , s2 +=  A ; n     int x = 0, y = 0; n     for (int i = 0; i < s.size(); i++) n       x += (s[i] == s1[i] ? 1 : 0), y += (s[i] == s2[i] ? 1 : 0); n     if (x > y) n       cout << s.size() - x << endl << s1 << endl; n     else n       cout << s.size() - y << endl << s2 << endl; n     return 0; n   } n   string h; n   int z = 1; n   map<int, char> mop; n   map<char, int> mops; n   for (char c =  A ; c <=  Z ; c++) { n     mop[z] = c, mops[c] = z, z++; n     if (z > k) break; n   } n   string t = s; n   int ans = 0; n   for (int i = 0; i < s.size() - 1; i++) { n     if (s[i] == s[i + 1]) { n       h = s[i], h += s[i + 1]; n       int f = i + 1; n       for (int j = i + 2; j < s.size(); j++) { n         if (s[j] != s[i]) break; n         f++; n         h += s[j]; n       } n       char prev = s[i - 1], next = h[1]; n       if (h.size() % 2 == 0) n         for (int j = 0; j < h.size(); j += 2) { n           for (__typeof((mops).begin()) it = (mops).begin(); it != (mops).end(); n                it++) n             if (it->first != prev && it->first != next) { n               h[j] = it->first; n               prev = h[j + 1], next = h[j + 3]; n               ans++; n               break; n             } n         } n       else { n         prev = h[0], next = h[2]; n         for (int j = 1; j < h.size(); j += 2) { n           for (__typeof((mops).begin()) it = (mops).begin(); it != (mops).end(); n                it++) n             if (it->first != prev && it->first != next) { n               h[j] = it->first; n               prev = h[j + 1]; n               next = h[j + 3]; n               ans++; n               break; n             } n         } n       } n       int n = 0; n       for (int j = i; j < f; j++) s[j] = h[n++]; n       i = f - 1; n     } n   } n   cout << ans << endl; n   cout << s << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int conversion(string p) { n   int o; n   o = atoi(p.c_str()); n   return o; n } n string toString(int h) { n   stringstream ss; n   ss << h; n   return ss.str(); n } n long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); } n long long lcm(long long a, long long b) { return (a * (b / gcd(a, b))); } n long long toi(string p) { n   long long x; n   istringstream in(p); n   in >> x; n   return x; n } n long long square(long long n) { return n * n; } n long long fastexp(long base, long power) { n   if (power == 0) n     return 1; n   else if (power % 2 == 0) n     return square(fastexp(base, power / 2)); n   else n     return base * (fastexp(base, power - 1)); n } n bool is_prime(int n) { n   for (int i = 2; i * i <= n; i++) n     if (n % i == 0) return 0; n   return 1; n } n int logba(int a, int b) { return log(a) / log(b); } n long long sum(long long x) { return ((x) * (x - 1)) / 2; } n int main() { n   long long n, x, y, res = 0; n   cin >> n; n   map<long long, long long> M, N; n   map<pair<long long, long long>, long long> R; n   set<pair<long long, long long> > S; n   for (int i = 0; i < n; i++) { n     cin >> x >> y; n     M[x]++; n     N[y]++; n     S.insert(make_pair(x, y)); n     R[make_pair(x, y)]++; n   } n   if (S.size() == 1) { n     cout << ((n) * (n - 1)) / 2 << endl; n     return 0; n   } n   for (map<long long, long long>::iterator it = M.begin(); it != M.end(); n        it++) { n     res += sum(it->second); n   } n   for (map<long long, long long>::iterator it = N.begin(); it != N.end(); n        it++) { n     res += sum(it->second); n   } n   for (map<pair<long long, long long>, long long>::iterator it = R.begin(); n        it != R.end(); it++) { n     res -= sum(it->second); n   } n   cout << res << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int bignumlen = 2200; n const int Blen = 8; n const long long base = 100000000; n struct bignum { n   int len; n   long long data[bignumlen]; n   long long &operator[](int x) { return (data[x]); } n   const long long &operator[](int x) const { return (data[x]); } n   bignum() { n     memset(data, 0, sizeof(data)); n     len = 0; n   } n   void clear() { n     for (int i = len; i >= 1; --i) data[i] = 0; n     len = 0; n   } n   int check(const bignum &a, const bignum &b) { n     if (a.len > b.len) return (0); n     if (b.len > a.len) return (1); n     for (int i = a.len; i >= 1; --i) { n       if (a.data[i] < b.data[i]) return (1); n       if (b.data[i] < a.data[i]) return (0); n     } n     return 2; n   } n   bool operator<(const bignum &b) { return (check(*this, b) == 1); } n   bool operator>(const bignum &b) { return (check(*this, b) == 0); } n   bool operator<=(const bignum &b) { return (check(*this, b) >= 1); } n   bool operator>=(const bignum &b) { return (check(*this, b) % 2 == 0); } n   bool operator!=(const bignum &b) { return (check(*this, b) != 2); } n   bool operator==(const bignum &b) { return (check(*this, b) == 2); } n   bignum operator=(const bignum &x) { n     for (int i = x.len + 1; i <= len; ++i) data[i] = 0; n     for (int i = 1; i <= x.len; ++i) data[i] = x.data[i]; n     len = x.len; n     return *this; n   } n   bignum operator=(long long x) { n     for (int i = len; i >= 0; --i) data[i] = 0; n     len = 0; n     while (x) { n       data[++len] = x % base; n       x /= base; n     } n     return *this; n   } n   bignum(long long x) { n     memset(data, 0, sizeof(data)); n     len = 0; n     (*this) = x; n   } n   bignum operator*(const bignum &b) { n     int i, j; n     bignum tmp; n     for (i = 1; i <= len; ++i) n       if (data[i] != 0) n         for (j = 1; j <= b.len; ++j) n           if (b.data[j] != 0) { n             tmp.data[i + j - 1] += data[i] * b.data[j]; n             tmp.data[i + j] += tmp.data[i + j - 1] / base; n             tmp.data[i + j - 1] %= base; n           } n     tmp.len = len + b.len - 1; n     while (tmp.data[tmp.len + 1]) tmp.len++; n     return tmp; n   } n   bignum operator*(long long x) { n     int i; n     bignum tmp; n     for (i = 1; i <= len; ++i) tmp[i] = data[i] * x; n     tmp.len = len; n     for (i = 1; i <= len; ++i) { n       tmp[i + 1] += tmp[i] / base, tmp[i] %= base; n       if (tmp[i + 1] && i + 1 > tmp.len) tmp.len++; n     } n     return tmp; n   } n   bignum operator/(long long x) { n     int i; n     bignum tmp; n     long long y = 0; n     for (i = len; i >= 1; --i) { n       y = y * base + data[i]; n       tmp[i] = y / x; n       y %= x; n     } n     tmp.len = len; n     while (tmp[tmp.len] == 0 && tmp.len > 1) tmp.len--; n     return tmp; n   } n   bignum operator/(const bignum &b) { n     if (b.len <= 1 && b[1] == 0) { n       printf( error! 被0除! ); n       for (;;) n         ; n     } n     int i, l1 = (len - 1) * Blen, l2 = (b.len - 1) * Blen; n     long long x = data[len], y = b[b.len]; n     while (x) x /= 10, l1++; n     while (y) y /= 10, l2++; n     bignum tmp, chu, B; n     chu = *this; n     B = b; n     for (i = 1; i * Blen <= l1 - l2; ++i) B *= base; n     for (i = 1; i <= (l1 - l2) % Blen; ++i) B *= 10; n     for (i = l1 - l2; i >= 0; --i) { n       x = 0; n       while (chu >= B) chu -= B, x++; n       tmp[i / Blen + 1] = tmp[i / Blen + 1] * 10 + x; n       B /= 10; n     } n     tmp.len = (l1 - l2) / Blen + 1; n     while (tmp.len >= 1 && !tmp[tmp.len]) tmp.len--; n     return tmp; n   } n   bignum operator+(const bignum &b) { n     bignum tmp; n     int i, l = max(len, b.len); n     for (i = 1; i <= l; ++i) tmp[i] = data[i] + b[i]; n     for (i = 1; i <= l; ++i) tmp[i + 1] += tmp[i] / base, tmp[i] %= base; n     tmp.len = l; n     if (tmp[tmp.len + 1]) tmp.len++; n     return tmp; n   } n   bignum operator+(long long x) { n     bignum tmp; n     tmp = *this; n     tmp[1] += x; n     for (int i = 1; i <= len && tmp[i] >= base; ++i) n       tmp[i + 1] += tmp[i] / base, tmp[i] %= base; n     while (tmp[tmp.len + 1]) tmp.len++; n     return tmp; n   } n   bignum operator-(const bignum &b) { n     int i; n     bignum tmp; n     for (i = 1; i <= len; ++i) tmp.data[i] = data[i] - b.data[i]; n     for (i = 1; i <= len; ++i) { n       if (tmp[i] < 0) tmp.data[i] += base, tmp.data[i + 1]--; n     } n     tmp.len = len; n     while (tmp[tmp.len] == 0 && tmp.len > 1) tmp.len--; n     return tmp; n   } n   bignum operator-(long long x) { n     bignum tmp; n     tmp = *this; n     tmp[1] -= x; n     for (int i = 1; i <= len && tmp[i] < 0; ++i) { n       tmp[i + 1] += (tmp[i] + 1) / base - 1; n       tmp[i] = (tmp[i] + 1) % base + base - 1; n     } n     while (!tmp[tmp.len] && tmp.len > 1) tmp.len--; n     return tmp; n   } n   long long operator%(long long x) { n     int i; n     long long y = 0; n     for (i = len; i >= 1; --i) y = (y * base + data[i]) % x; n     return y; n   } n   bignum operator%(const bignum &b) { n     if (b.len <= 1 && b[1] == 0) { n       printf( error! 被0 mod! ); n       for (;;) n         ; n     } n     int i, l1 = (len - 1) * Blen, l2 = (b.len - 1) * Blen; n     long long x = data[len], y = b[b.len]; n     while (x) x /= 10, l1++; n     while (y) y /= 10, l2++; n     bignum chu, B; n     chu = *this; n     B = b; n     for (i = 1; i * Blen <= l1 - l2; ++i) B *= base; n     for (i = 1; i <= (l1 - l2) % Blen; ++i) B *= 10; n     for (i = l1 - l2; i >= 0; --i) { n       while (chu >= B) chu -= B; n       B /= 10; n     } n     return chu; n   } n   bignum operator+=(const bignum &b) { return *this = (*this + b); } n   bignum operator*=(const bignum &b) { return *this = (*this * b); } n   bignum operator-=(const bignum &b) { return *this = (*this - b); } n   bignum operator/=(const bignum &b) { return *this = (*this / b); } n   bignum operator%=(const bignum &b) { return *this = (*this % b); } n   bignum operator*=(long long x) { return (*this = (*this * x)); } n   bignum operator+=(long long x) { return (*this = (*this + x)); } n   bignum operator-=(long long x) { return (*this = (*this - x)); } n   bignum operator/=(long long x) { return (*this = (*this / x)); } n   void read() { n     char c[bignumlen * Blen + 10]; n     scanf( %s , c + 1); n     int l = strlen(c + 1); n     (*this).clear(); n     long long x; n     for (int i = 1; i <= (l - 1) / Blen + 1; ++i) { n       x = 0; n       for (int j = l - Blen * i + 1; j <= l - Blen * i + Blen; ++j) n         if (j >= 1) x = x * 10 + c[j] - 48; n       data[++len] = x; n     } n   } n   void write() { n     printf( %I64d , data[len]); n     for (int i = len - 1; i >= 1; --i) printf( %0*I64d , Blen, data[i]); n   } n } p, q, pp, qq; n bignum gcd(const bignum &A, const bignum &B) { n   bignum a = A, b = B, res = 1; n   while (!(a[1] & 1) && !(b[1] & 1)) a /= 2, b /= 2, res *= 2; n   for (;;) { n     if (a.len == 1 && a[1] == 0) return b * res; n     if (b.len == 1 && b[1] == 0) return a * res; n     while (!(a[1] & 1)) a /= 2; n     while (!(b[1] & 1)) b /= 2; n     if (a > b) n       a -= b; n     else n       b -= a; n   } n } n void YF(bignum &A, bignum &B) { n   bignum tmp = gcd(A, B); n   A /= tmp; n   B /= tmp; n } n int n, i, x, num; n int main() { n   scanf( %d , &n); n   while (n % 2 == 0) { n     n /= 2; n     num++; n   } n   if (n == 1) { n     printf( %d/%d n , num, 1); n     return 0; n   } n   p = 0; n   q = 1; n   pp = 1; n   qq = 1; n   for (i = n + 1;;) { n     if (i > n) { n       if (q % (i - n) == 0) n         q /= i - n; n       else n         p *= i - n; n       if (qq % (i - n) == 0) n         qq /= i - n; n       else n         pp *= i - n; n       if (p % i == 0) n         p /= i; n       else n         q *= i; n       if (pp % i == 0) n         pp /= i; n       else n         qq *= i; n     } else n       p += q; n     if (i == 1) break; n     if (i % 2 == 0) n       i /= 2; n     else n       i += n; n   } n   YF(p, q); n   p = p * qq; n   q = q * (qq - pp); n   p += q * num; n   bignum tmp = gcd(p, q); n   (p / tmp).write(); n   printf( / ); n   (q / tmp).write(); n } n


#include <bits/stdc++.h> n using namespace std; n long long v2[34]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t; n   cin >> t; n   for (int i = 0; i <= 33; ++i) { n     if (i == 0) { n       v2[i] = 1; n     } else { n       v2[i] = 2 * v2[i - 1]; n     } n   } n   while (t--) { n     int n; n     cin >> n; n     vector<long long> v(n); n     for (int i = 0; i < n; ++i) { n       cin >> v[i]; n     } n     int ans = 0; n     for (int i = 1; i < n; ++i) { n       if (v[i] < v[i - 1]) { n         long long aux = 0; n         int k = 0; n         long long dif = v[i - 1] - v[i]; n         for (int j = 0; j < 34; ++j) { n           aux += v2[j]; n           if (aux >= dif) { n             ans = max(ans, j + 1); n             k = j; n             break; n           } n         } n         v[i] += dif; n       } n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int N = 1000005; n using namespace std; n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n long long lcm(long long a, long long b) { return a * b / gcd(a, b); } n int a[N]; n int main() { n   long long n; n   cin >> n; n   long long d, d1, ans; n   for (long long i = 0; i < n; i++) cin >> a[i]; n   d1 = gcd(a[0], a[1]); n   ans = a[0] / d1 * a[1]; n   for (long long i = 2; i < n; i++) { n     ans = gcd(ans, a[i]); n     long long gg = gcd(d1, ans); n     ans = d1 / gg * ans; n     d1 = gg; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   long long x = 0, f = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     x = (x << 3) + (x << 1) + (c ^ 48); n     c = getchar(); n   } n   return f == 1 ? x : -x; n } n inline void print(long long x) { n   if (x < 0) putchar( - ), x = ~x + 1; n   if (x >= 10) print(x / 10); n   putchar((x % 10) | 48); n } n long long n; n struct node { n   long long x, y; n } a[2510], v[5010]; n long long xiangxian(node x) { n   if (x.x >= 0) { n     if (x.y >= 0) n       return 1; n     else n       return 4; n   } else { n     if (x.y >= 0) n       return 2; n     else n       return 3; n   } n } n long long cross(node x, node y) { return x.x * y.y - y.x * x.y; } n bool cmp(node x, node y) { n   long long x1 = xiangxian(x); n   long long x2 = xiangxian(y); n   if (x1 != x2) n     return x1 < x2; n   else n     return cross(x, y) > 0; n } n long long ans; n long long C(long long x, long long y) { n   if (x < 0) return 0; n   long long res = 1; n   for (long long i = 1; i <= y; ++i) res *= (x - i + 1); n   for (long long i = 1; i <= y; ++i) res /= i; n   return res; n } n signed main() { n   n = read(); n   for (long long i = 1; i <= n; ++i) a[i].x = read(), a[i].y = read(); n   for (long long i = 1; i <= n; ++i) { n     long long cnt = 0; n     for (long long j = 1; j <= n; ++j) { n       if (j == i) continue; n       v[++cnt].x = a[j].x - a[i].x; n       v[cnt].y = a[j].y - a[i].y; n     } n     sort(v + 1, v + cnt + 1, cmp); n     for (long long j = 1; j <= cnt; ++j) v[j + cnt] = v[j]; n     long long lst = 1; n     for (long long j = cnt + 1; j <= 2 * cnt; ++j) { n       while (lst + cnt < j || cross(v[j], v[lst + 1]) >= 0) { n         ++lst; n         if (lst + 1 == j) break; n       } n       ans += C(j - lst - 1, 3); n     } n   } n   print(5 * C(n, 5) - ans); n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b, c, m, n; n int main() { n   cin >> a; n   cout << a / 2520; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n, m, k; n     cin >> n >> m >> k; n     vector<int> a(n); n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n     } n     vector<int> what(m); n     for (int x = 0; x < m; x++) { n       int y = m - 1 - x; n       what[x] = max(a[x], a[n - 1 - y]); n     } n     k = min(k, m - 1); n     int ans = 0; n     for (int fix = 0; fix <= k; fix++) { n       int fiy = k - fix; n       int mn = (int)2e9; n       for (int i = fix; i <= m - 1 - fiy; i++) { n         mn = min(mn, what[i]); n       } n       ans = max(ans, mn); n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:60777216 ) n using namespace std; n int err; n vector<char> best; n vector<char> curr; n int n, r; n int it; n void go(int pos, int f1, int f2, int errors) { n   if (err <= errors) return; n   if (pos == -1) { n     err = errors; n     best = curr; n   } else { n     if (f1 == f2) { n       curr[pos] =  T ; n       go(-1, 0, 0, errors + (pos + 1 < n && curr[pos + 1] == curr[pos])); n     } else if (f1 > f2) { n       curr[pos] =  T ; n       go(pos - 1, f1 - f2, f2, n          errors + (pos + 1 < n && curr[pos + 1] == curr[pos])); n     } else { n       curr[pos] =  B ; n       go(pos - 1, f1, f2 - f1, n          errors + (pos + 1 < n && curr[pos + 1] == curr[pos])); n     } n   } n } n int gcd(int a, int b) { n   while (a && b) n     if (a > b) n       a %= b; n     else n       b %= a; n   return a + b; n } n int ngcd(int a, int b) { n   int res = 0; n   while (a && b) n     if (a > b) n       res += a / b, a %= b; n     else n       res += b / a, b %= a; n   return res; n } n int main() { n   cin >> n >> r; n   vector<int> nm; n   for (int other = 1; other <= r; other++) { n     int g = gcd(other, r); n     if (g == 1) { n       int t = ngcd(other, r); n       if (t == n) { n         nm.push_back(other); n       } n     } n   } n   if (nm.size() == 0) n     puts( IMPOSSIBLE ); n   else { n     err = n + 1; n     curr.resize(n); n     for (int i = (0); i < (nm.size()); i++) { n       go(n - 1, r, nm[i], 0); n       go(n - 1, nm[i], r, 0); n     } n     cout << err << endl; n     for (int i = (0); i < (best.size()); i++) printf( %c , best[i]); n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rnnnd(chrono::steady_clock::now().time_since_epoch().count()); n inline int read() { n   int x = 0, f = 1, c = getchar(); n   while (!isdigit(c)) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (isdigit(c)) { n     x = (x << 1) + (x << 3) + (c ^ 48); n     c = getchar(); n   } n   return f == 1 ? x : -x; n } n const int N = 1e5 + 4; n int n, m, c[N], vis[N], dep[N], up1[N], up2[N]; n vector<int> e[N], ans; n void upd(int x, int v) { n   if (!v || dep[v] >= dep[x]) return; n   if (!up1[x] || dep[v] < dep[up1[x]]) { n     up2[x] = up1[x]; n     up1[x] = v; n   } else if (!up2[x] || dep[v] < dep[up2[x]]) n     up2[x] = v; n } n bool dfs_1(int x) { n   vis[x] = 2; n   for (auto v : e[x]) { n     if (!vis[v]) { n       dep[v] = dep[x] + 1; n       if (dfs_1(v)) return 1; n       upd(x, up1[v]); n       upd(x, up2[v]); n     } else if (vis[v] == 1) n       return 1; n     else n       upd(x, v); n   } n   vis[x] = 1; n   return 0; n } n void dfs_3(int x) { n   vis[x] = 3; n   if (!up1[x] || (!up2[x] && up1[up1[x]])) { n     up1[x] = 1; n     ans.push_back(x); n   } else n     up1[x] = 0; n   for (auto v : e[x]) n     if (vis[v] != 3) dfs_3(v); n } n inline void solve() { n   for (int i = 1; i <= n; i++) e[i].clear(); n   n = read(); n   m = read(); n   for (int i = 1, u, v; i <= m; i++) { n     u = read(); n     v = read(); n     e[u].push_back(v); n   } n   for (int i = 1; i <= n; i++) c[i] = i; n   shuffle(c + 1, c + n + 1, rnnnd); n   for (int i = 1; i <= min(n, 100); i++) { n     memset(vis, 0, sizeof(int) * (n + 1)); n     memset(up1, 0, sizeof(int) * (n + 1)); n     memset(up2, 0, sizeof(int) * (n + 1)); n     memset(dep, 0, sizeof(int) * (n + 1)); n     if (dfs_1(c[i])) continue; n     dfs_3(c[i]); n     if (ans.size() * 5 >= n) { n       sort(ans.begin(), ans.end()); n       for (auto v : ans) cout << v <<    ; n       puts(  ); n     } else n       puts( -1 ); n     ans.clear(); n     return; n   } n   puts( -1 ); n } n int main() { n   for (int T = read(); T--;) solve(); n   return (0 - 0); n } n


#include <bits/stdc++.h> n using namespace std; n int b[105]; n int main() { n   int n, t, m, k; n   cin >> t; n   while (t--) { n     cin >> n >> m >> k; n     for (int i = 0; i < n; i++) cin >> b[i]; n     for (int i = 0; i < n - 1; i++) { n       if (b[i] + k < b[i + 1]) n         m -= (b[i + 1] - b[i] - k); n       else n         m += min(b[i] - b[i + 1] + k, b[i]); n       if (m < 0) { n         puts( NO ); n         goto end; n       } n     } n     puts( YES ); n   end: n     continue; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 500; n const pair<double, double> inf = make_pair(-1, -1); n pair<double, double> T[N << 2]; n double f[N]; n int n, m; n inline int read() { n   int n = 0; n   char c; n   for (c = getchar(); c <  0  || c >  9 ; c = getchar()) n     ; n   for (; c >=  0  && c <=  9 ; c = getchar()) n = n * 10 + c -  0 ; n   return n; n } n pair<double, double> merg(pair<double, double> t1, pair<double, double> t2) { n   double l1 = t1.first, r1 = t1.second, l2 = t2.first, r2 = t2.second; n   return make_pair(l1 * l2 / (1 + (l2 - 1) * r1), n                    r2 + l2 * (1 - r2) * r1 / (1 - (1 - l2) * r1)); n } n void up(int x) { T[x] = merg(T[x << 1], T[x << 1 | 1]); } n void build(int x, int l, int r) { n   if (l == r) { n     T[x] = make_pair(f[l], f[l]); n     return; n   } n   int mi = (l + r) >> 1; n   build(x << 1, l, mi); n   build(x << 1 | 1, mi + 1, r); n   up(x); n } n void modify(int x, int l, int r, int pos) { n   if (l == r) { n     T[x] = make_pair(f[l], f[l]); n     return; n   } n   int mi = (l + r) >> 1; n   if (pos <= mi) n     modify(x << 1, l, mi, pos); n   else n     modify(x << 1 | 1, mi + 1, r, pos); n   up(x); n } n pair<double, double> qry(int x, int l, int r, int L, int R) { n   if (L <= l && r <= R) return T[x]; n   int mi = (l + r) >> 1; n   pair<double, double> t1 = inf, t2 = inf; n   if (L <= mi) t1 = qry(x << 1, l, mi, L, R); n   if (mi < R) t2 = qry(x << 1 | 1, mi + 1, r, L, R); n   return t1 == inf ? t2 : (t2 == inf ? t1 : merg(t1, t2)); n } n int main() { n   n = read(), m = read(); n   for (int i = 1; i <= n; i++) { n     int x = read(), y = read(); n     f[i] = x * 1.0 / y; n   } n   build(1, 1, n); n   while (m--) { n     int kd, x, y, z; n     kd = read(), x = read(), y = read(); n     if (kd == 2) { n       pair<double, double> ans = qry(1, 1, n, x, y); n       printf( %.10lf n , ans.first); n     } else { n       z = read(); n       f[x] = y * 1.0 / z; n       modify(1, 1, n, x); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool endline = false; n template <class T> n istream& operator>>(istream& inp, vector<T>& v) { n   for (auto& it : v) inp >> it; n   return inp; n } n template <class T> n ostream& operator<<(ostream& out, vector<T>& v) { n   for (auto& it : v) out << it << (endline ?   n  :    ); n   return out; n } n template <class T, class U> n istream& operator>>(istream& inp, pair<T, U>& v) { n   inp >> v.first >> v.second; n   return inp; n } n template <class T, class U> n ostream& operator<<(ostream& out, pair<T, U>& v) { n   out << v.first <<     << v.second; n   return out; n } n const int mod1 = 998244353, mod = 1e9 + 7; n const int MAXN = 1e6 + 6, MAXM = 5e5 + 5; n const int inf = 2e9; n const long long linf = 1e18; n long long n, m, a[5050]; n void Solve() { n   cin >> n >> m; n   long long tmp = 0, i; n   for (i = 1; i <= n; i++) { n     if (tmp + (i - 1) / 2 < m) { n       a[i] = i; n       tmp += (i - 1) / 2; n     } else { n       long long gap = m - tmp; n       if (gap == 0) { n         a[i] = i; n       } else { n         a[i] = a[i - 1] + a[i - 2 * gap]; n       } n       tmp += gap; n       i++; n       break; n     } n   } n   if (tmp < m) { n     cout << -1; n     return; n   } n   for (; i <= n; i++) { n     a[i] = 1e8 + i * i; n   } n   for (i = 1; i <= n; i++) { n     cout << a[i] <<    ; n   } n } n signed main() { n   if (fopen(   n              .inp , n              r )) { n     freopen( n            n          .inp , n          r , stdin); n     freopen( n            n          .out , n          w , stdout); n   }; n   std::ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long TC = 1; n   while (TC--) Solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   priority_queue<pair<int, int> > pq1, pq2; n   int n, w; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> w, pq1.push({-w, i}); n   n <<= 1; n   for (int i = 0; i < n; i++) { n     char ch; n     cin >> ch; n     pair<int, int> cur; n     int ret; n     if (ch ==  0 ) n       cur = pq1.top(), ret = cur.second, pq2.push({-cur.first, cur.second}), n       pq1.pop(); n     else n       ret = pq2.top().second, pq2.pop(); n     cout << ret + 1 <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double eps = 1e-9; n const int inf = (1 << 30) - 1; n const long long inf64 = ((long long)1 << 62) - 1; n const long double pi = acos(-1); n template <class T> n T sqr(T x) { n   return x * x; n } n template <class T> n T abs(T x) { n   return x < 0 ? -x : x; n } n int main() { n   ios_base::sync_with_stdio(0); n   int n, t, k, d; n   cin >> n >> t >> k >> d; n   cout << ((d / t + 1) * k >= n ?  NO  :  YES ) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n long long val[100000], dp[100000][2]; n vector<int> g[100000]; n void dfs(int v, int p) { n   long long c1 = 0, c2 = 0; n   for (int i = 0; i < (g[v].size()); i++) { n     int next = g[v][i]; n     if (next != p) { n       dfs(next, v); n       c1 = max(c1, dp[next][0]); n       c2 = max(c2, dp[next][1]); n     } n   } n   long long d = c1 - c2; n   if (val[v] + d > 0) n     c2 += val[v] + d; n   else n     c1 += -(val[v] + d); n   dp[v][0] = c1, dp[v][1] = c2; n } n int main() { n   std::ios::sync_with_stdio(false); n   cin >> n; n   for (int i = 0; i < n - 1; i++) { n     int a, b; n     cin >> a >> b; n     g[a - 1].push_back(b - 1); n     g[b - 1].push_back(a - 1); n   } n   for (int i = 0; i < n; i++) cin >> val[i]; n   dfs(0, -1); n   cout << dp[0][0] + dp[0][1]; n } n


#include <bits/stdc++.h> n const int inf = 0x3f3f3f3f; n using namespace std; n int yh() { n   int ret = 0; n   bool f = 0; n   char c = getchar(); n   while (!isdigit(c)) { n     if (c == EOF) return -1; n     if (c ==  - ) f = 1; n     c = getchar(); n   } n   while (isdigit(c)) ret = (ret << 3) + (ret << 1) + (c ^ 48), c = getchar(); n   return f ? -ret : ret; n } n template <typename T> n void yh(T& ret) { n   ret = 0; n   bool f = 0; n   char c = getchar(); n   while (!isdigit(c)) { n     if (c == EOF) return ret = -1, void(); n     if (c ==  - ) f = 1; n     c = getchar(); n   } n   while (isdigit(c)) ret = (ret << 3) + (ret << 1) + (c ^ 48), c = getchar(); n   ret = f ? -ret : ret; n } n char s[200005]; n int main() { n   for (register int _ = (yh()); _ >= (1); _--) { n     int n = yh(); n     queue<int> q; n     scanf( %s , s + 1); n     int bloc = 0; n     for (register int i = (1); i <= (n); i++) { n       if (s[i] == s[i - 1]) { n         q.push(bloc); n       } else n         bloc++; n     } n     int opts = 0, dlt = 0; n     for (register int i = (1); i <= (n); i++) { n       if (q.empty()) break; n       q.pop(); n       opts++; n       dlt++; n       while (!q.empty() && q.front() == i) { n         q.pop(); n         dlt++; n       } n       dlt++; n     } n     opts += (n - dlt + 1) / 2; n     cout << opts <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int last1[510][5010], last2[510][5100], pre[510][5100]; n int main() { n   int s, d; n   cin >> s >> d; n   memset(last1, -1, sizeof(last1)); n   memset(last2, -1, sizeof(last2)); n   memset(pre, -1, sizeof(pre)); n   queue<pair<int, int> > q; n   q.push(make_pair(0, 0)); n   while (!q.empty()) { n     pair<int, int> cur = q.front(); n     q.pop(); n     for (int i = 0; i < 10; i++) { n       if (i == 0 && cur.first == 0 && cur.second == 0) continue; n       int nx1 = (cur.first * 10 + i) % s, nx2 = cur.second + i; n       if (nx2 > d) continue; n       if (pre[nx1][nx2] != -1) continue; n       last1[nx1][nx2] = cur.first, last2[nx1][nx2] = cur.second; n       pre[nx1][nx2] = i; n       q.push(make_pair(nx1, nx2)); n     } n   } n   if (pre[0][d] == -1) { n     cout << -1; n     return 0; n   } n   vector<int> ans; n   int nx1 = 0, nx2 = d; n   while (1) { n     if (pre[nx1][nx2] == -1) break; n     ans.push_back(pre[nx1][nx2]); n     int tmp1 = last1[nx1][nx2]; n     int tmp2 = last2[nx1][nx2]; n     nx1 = tmp1, nx2 = tmp2; n   } n   for (int i = ans.size() - 1; i >= 0; i--) { n     cout << ans[i]; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, Q; n vector<vector<int> > ad; n vector<int> val, par; n void fun(int c, int p) { n   par[c] = p; n   int i; n   for (i = 0; i < ad[c].size(); i++) { n     if (ad[c][i] != p) fun(ad[c][i], c); n   } n } n int gcd(int a, int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n int query(int c, int v) { n   if (c == -1) return c; n   if (gcd(val[c], v) > 1) return c + 1; n   return query(par[c], v); n } n int main() { n   int i, j, k; n   cin >> N >> Q; n   ad.resize(N); n   val.resize(N); n   par.resize(N); n   for (i = 0; i < N; i++) cin >> val[i]; n   for (i = 1; i < N; i++) { n     cin >> j >> k; n     ad[j - 1].push_back(k - 1); n     ad[k - 1].push_back(j - 1); n   } n   fun(0, -1); n   while (Q) { n     Q--; n     cin >> k; n     if (k == 2) { n       cin >> j >> k; n       val[j - 1] = k; n     } else { n       cin >> j; n       cout << query(par[j - 1], val[j - 1]) << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m(0), a(0), b(0), c(0), x; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> x; n     if (i % 3 == 0) n       a += x; n     else if (i % 3 == 1) n       b += x; n     else n       c += x; n   } n   m = max(max(a, b), c); n   if (m == a) n     cout <<  chest ; n   else if (m == b) n     cout <<  biceps ; n   else n     cout <<  back ; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     long long months, monthlen, weeklen; n     cin >> months >> monthlen >> weeklen; n     long long n2 = monthlen - 1; n     long long n1 = weeklen / gcd(n2, weeklen); n     long long lim = min(months, monthlen); n     long long ini = lim - n1; n     long long sum = 0; n     long long len = (ini + n1 - 1) / n1; n     sum = ini * len - n1 * ((len - 1) * (len - 1) + (len - 1)) / 2; n     cout << sum << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long M = 1e9 + 7; n const long long INF = 1e9; n inline long long pwr(long long base, long long n, long long m) { n   long long ans = 1; n   while (n > 0) { n     if (n % 2 == 1) ans = (ans * base) % m; n     base = (base * base) % m; n     n /= 2; n   } n   return ans; n } n const int N = 1e6 + 10; n int a[N], n, dp[1 << 22]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     dp[a[i]] = a[i]; n   } n   for (int i = 0; i < 22; i++) { n     for (int mask = 0; mask < 1 << 22; mask++) { n       if ((mask & (1 << i))) dp[mask] = max(dp[mask], dp[mask ^ (1 << i)]); n     } n   } n   for (int i = 0; i < n; i++) { n     int temp = a[i]; n     a[i] = (((1 << 22) - 1) ^ a[i]); n     if (!dp[a[i]]) dp[a[i]] = -1; n     cout << dp[a[i]] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c, d; n   cin >> a >> b >> c >> d; n   if (a <= b) n     cout <<  Second ; n   else n     cout <<  First ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n void file() { n   freopen( alost.in ,  r , stdin); n   freopen( output.txt ,  w , stdout); n } n bool ar[10000005]; n void sieve() { n   ar[0] = ar[1] = 1; n   for (long long i = 2; i * i <= (int)1e7; i++) n     if (!ar[i]) n       for (long long j = i * i; j <= (int)1e7; j += i) ar[j] = 1; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL), cout.tie(NULL); n   ; n   sieve(); n   int n; n   cin >> n; n   for (int i = 2; i <= (int)1e7 && n; i++) n     if (!ar[i]) cout << i <<    , n--; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n const int N = 1e6 + 5; n inline int readint() { n   char c = getchar(); n   int ans = 0; n   while (c <  0  || c >  9 ) { n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     ans = ans * 10 + c -  0 , c = getchar(); n   } n   return ans; n } n vector<int> tree[N]; n bool check[N]; n int father[N][21]; n int deep[N]; n void dfs(int x, int level) { n   for (int i = 0; father[father[x][i]][i]; i++) { n     father[x][i + 1] = father[father[x][i]][i]; n   } n   deep[x] = level; n   for (int i = 0; i < tree[x].size(); i++) { n     int to = tree[x][i]; n     if (to == father[x][0]) { n       continue; n     } n     father[to][0] = x; n     dfs(to, level + 1); n   } n } n int main() { n   int n, k; n   n = readint(), k = readint(); n   int u, v; n   for (int i = 1; i < n; i++) { n     u = readint(), v = readint(); n     tree[u].push_back(v); n     tree[v].push_back(u); n   } n   k = n - k; n   k--, check[n] = 1; n   dfs(n, 1); n   for (int i = n - 1; i >= 1 && k; i--) { n     int aim = -1; n     int now = i; n     if (check[i]) { n       continue; n     } n     for (int j = 20; j >= 0; j--) { n       if (father[now][j] == 0 || check[father[now][j]]) { n         continue; n       } n       now = father[now][j]; n     } n     if (deep[i] - deep[now] + 1 <= k) { n       now = i; n       while (now != 0 && !check[now]) { n         check[now] = 1; n         k--; n         now = father[now][0]; n       } n     } n   } n   for (int i = 1; i <= n - 1; i++) { n     if (!check[i]) { n       cout << i <<    ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n const int32_t mod = 1e9 + 7; n using namespace std; n unordered_map<long long, long long> mp; n void fun(vector<long long>& v, long long idx, long long sum) { n   if (idx == (long long)v.size()) { n     mp[sum]++; n     return; n   } n   fun(v, idx + 1, sum); n   fun(v, idx + 1, sum - v[idx]); n   fun(v, idx + 1, sum + v[idx]); n } n void solve(long long test) { n   long long n; n   cin >> n; n   mp.clear(); n   vector<long long> v(n); n   for (long long i = 0; i < n; i++) { n     cin >> v[i]; n   } n   fun(v, 0, 0); n   if (mp[0] > 1) n     cout <<  YES  n          <<   n ; n   else n     cout <<  NO  n          <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t = 1; n   cin >> t; n   long long i = 1; n   while (i <= t) { n     solve(i); n     i++; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   list<int> L; n   int N, M; n   cin >> N >> M; n   set<pair<int, int> > S; n   for (int i = 0; i < M; ++i) { n     int u, v; n     cin >> u >> v; n     S.insert(pair<int, int>(u, v)); n   } n   L.push_back(1); n   for (int i = 2; i <= N; ++i) { n     list<int>::iterator it = L.begin(); n     while (it != L.end() && S.count(pair<int, int>(i, *it))) it++; n     L.insert(it, i); n   } n   for (list<int>::iterator it = L.begin(); it != L.end(); ++it) { n     cout << *it <<    ; n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, j, ans = 0, n, k, a[100000]; n   scanf( %d%d , &n, &k); n   for (i = 0; i < n; ++i) { n     scanf( %d , &a[i]); n   } n   for (i = 0; i < k && a[i] < 0; ++i) a[i] *= -1; n   if (i < k) { n     sort(a, a + n); n     k -= i; n     if (k & 1) { n       a[0] *= -1; n     } n   } n   for (j = 0; j < n; ++j) { n     ans += a[j]; n   } n   printf(  n%d , ans); n   return 0; n } n


#include <bits/stdc++.h> n  n using namespace std; n  n typedef long long ll; n  n const ll DIM = 1e6 + 7; n const ll INF = 1e16 + 7; n const ll MODULO = 1e9 + 7; n  n ll n,m,nt,k,q; n  n ll val,val1,last,res,c0,c1,c2; n  n int main() n { n     ios_base::sync_with_stdio(); n     cin.tie(); n     cout.tie(); n  n     cin>>nt; n     for(int t=1; t<=nt; t++) n     { n  n         cin>>n; n  n         res=0; n         c0=0; n         c1=0; n         c2=0; n  n         for(int i=1; i<=n; i++) n         { n             cin>>val; n  n             if(val%3==0)c0++; n             else if(val%3==1)c1++; n             else c2++; n         } n  n         for(int i=1; i<=2; i++) n         { n  n             if(c0>n/3) n             { n                 val=c0-n/3; n                 res+=val; n                 c1+=val; n                 c0-=val; n             } n  n             if(c1>n/3) n             { n                 val=c1-n/3; n                 res+=val; n                 c2+=val; n                 c1-=val; n             } n  n             if(c2>n/3) n             { n                 val=c2-n/3; n                 res+=val; n                 c0+=val; n                 c2-=val; n             } n         } n  n         cout<<res<<endl; n     } n  n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double PI = acos(-1.0l); n const long long MOD = 1e9 + 7; n bool debug = 1; n const int N = 3e3 + 10; n int seg[2 * N]; n int n, m; n void build() { n   for (int i = n - 1; i > 0; i--) seg[i] = seg[i << 1] + seg[i << 1 | 1]; n } n int qry(int l, int r) { n   int ans = 0; n   for (l += n, r += n; l < r; l >>= 1, r >>= 1) { n     if (l & 1) ans += seg[l++]; n     if (r & 1) ans += seg[--r]; n   } n   return ans; n } n void up(int pos, int x) { n   for (seg[pos += n] = x; pos > 1; pos >>= 1) { n     seg[pos >> 1] = seg[pos] + seg[pos ^ 1]; n   } n } n char mat[N][N]; n int dpesq[N][N], dpdir[N][N], dpdia[N][N]; n bool ok(int i, int j) { return i >= 0 and i < n and j >= 0 and j < m; } n vector<int> ev[N]; n int main() { n   cin >> n >> m; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) scanf(  %c , mat[i] + j); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       int ant = 0; n       if (j) ant = dpesq[i][j - 1]; n       if (mat[i][j] ==  z ) dpesq[i][j] = ant + 1; n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = m - 1; j >= 0; j--) { n       int ant = 0; n       if (j < m - 1) ant = dpdir[i][j + 1]; n       if (mat[i][j] ==  z ) dpdir[i][j] = ant + 1; n     } n   } n   for (int i = n - 1; i >= 0; i--) { n     for (int j = 0; j < m; j++) { n       int ant = 0; n       if (ok(i + 1, j - 1)) ant = dpdia[i + 1][j - 1]; n       if (mat[i][j] ==  z ) dpdia[i][j] = ant + 1; n     } n   } n   long long ans = 0; n   for (int inic = 0; inic < n; inic++) { n     int i = inic, j = 0; n     memset(seg, 0, sizeof(seg)); n     for (int jj = 0; jj < m; jj++) ev[jj].clear(); n     while (ok(i, j)) { n       for (auto it : ev[j]) { n         up(it, 0); n       } n       if (mat[i][j] ==  z ) { n         up(j, 1); n         ev[j + dpdir[i][j]].push_back(j); n         int mind = min(dpesq[i][j], dpdia[i][j]); n         ans += qry(j - mind + 1, j + 1); n       } n       i--, j++; n     } n   } n   for (int inicj = 1; inicj <= m - 1; inicj++) { n     int i = n - 1, j = inicj; n     memset(seg, 0, sizeof(seg)); n     for (int jj = 0; jj < m; jj++) ev[jj].clear(); n     while (ok(i, j)) { n       for (auto it : ev[j]) { n         up(it, 0); n       } n       if (mat[i][j] ==  z ) { n         up(j, 1); n         ev[j + dpdir[i][j]].push_back(j); n         int mind = min(dpesq[i][j], dpdia[i][j]); n         ans += qry(j - mind + 1, j + 1); n       } n       i--, j++; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n #define pb push_back n  n int i,j,n,m,e; n vector<int>v,s; n  n int main() n { n #ifndef ONLINE_JUDGE n  freopen( input.txt , r ,stdin); n  freopen( output.txt , w ,stdout); n #endif n  n  int t; n  cin>>t; n  while(t--) n  { n   int k,sum=0; n   cin>>n>>k; n   int a[n+5]; n  n   for(i=0;i<n;i++) n   { n    cin>>a[i]; n   } n   sort(a,a+n); n    n   for(i=0;i<n;i++) n   { n    sum+=a[i]; n    if(sum==k)v.pb(a[i]); n    else s.pb(a[i]); n   } n   if(v.size()==0) n   { n    cout<< YES <<endl; n          for(auto it : s)cout<<it<<   ; n          cout<<endl; n   } n      else n      { n       for(auto it:v)s.pb(it); n         n       sum=0; n       string ans= YES ; n  n       for(auto it:s) n       { n        sum+=it; n        if(sum==k) n        { n         ans= NO ;break; n        } n       } n       if(ans== NO )cout<<ans<<endl; n       else n       { n        cout<<ans<<endl; n              for(auto it : s)cout<<it<<   ;cout<<endl; n       } n      }  n      v.clear(); n      s.clear();    n  } n } n


#include <bits/stdc++.h> n using namespace std; n int l, r, p, prim[100], cnt, a[4000000], n, f[4000000], ans; n bool ok[4000000]; n void DFS(int x, long long now) { n   if (x > cnt) return; n   while (now <= r) { n     DFS(x + 1, now); n     now = now * prim[x]; n     if (now <= r) a[++n] = now; n   } n } n int main() { n   scanf( %d%d%d , &l, &r, &p); n   for (int i = 2; i <= p; ++i) { n     bool OK = true; n     for (int j = 2; j * j <= i; ++j) n       if (i % j == 0) { n         OK = false; n         break; n       } n     if (OK) prim[++cnt] = i; n   } n   a[++n] = 1; n   DFS(1, 1); n   sort(a + 1, a + n + 1); n   for (int i = 2; i <= n; ++i) f[i] = p + 1; n   for (int q = 1; q <= p; ++q) { n     int now = 1; n     for (int i = 1; i <= n; ++i) { n       long long tmp = a[i] * q; n       while (now <= n && a[now] < tmp) ++now; n       if (now > n) break; n       if (a[now] == tmp && f[now] > f[i] + 1) { n         f[now] = f[i] + 1; n         if (f[now] + q <= p) ok[now] = 1; n       } n     } n   } n   for (int i = 1; i <= n; ++i) n     if (a[i] >= l && ok[i]) ++ans; n   printf( %d n , ans); n   return 0; n } n