#include <bits/stdc++.h> n const double EPS = 1e-8; n using namespace std; n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n template <typename A, size_t N, typename T> n void Fill(A (&array)[N], const T &val) { n   std::fill((T *)array, (T *)(array + N), val); n } n class Graph { n  public: n   int vn; n   int sumcost = 0; n   vector<vector<pair<int, int>>> g; n   Graph(int n) { n     vn = n; n     g.resize(n); n   } n   virtual void con(int a, int b, int w) = 0; n   int getWeight(int f, int t) { n     auto itr = lower_bound((g[f]).begin(), (g[f]).end(), make_pair(t, INT_MIN)); n     if (itr != g[f].end()) return itr->second; n     return INT_MIN; n   } n   int Costsum() { return sumcost; } n   void scan(int edcount, bool oindexed, bool w) { n     for (int i = (0); (edcount) > i; i++) { n       int a, b, c = 1; n       scanf( %d %d , &a, &b); n       if (w) scanf( %d , &c); n       con(a - oindexed, b - oindexed, c); n     } n   } n }; n class BiDGraph : public Graph { n  public: n   BiDGraph(int n) : Graph(n) {} n   void con(int a, int b, int w = 1) { n     g[a].push_back({b, w}); n     g[b].push_back({a, w}); n     sumcost++; n   } n }; n struct RSQ { n   int n; n   vector<int> dat; n   RSQ() {} n   RSQ(int n_) { n     n = 1; n     while (n < n_) n *= 2; n     dat.resize(2 * n - 1, 0); n   } n   void add(int k, int a) { n     k += n - 1; n     dat[k] += a; n     while (k > 0) { n       k = (k - 1) / 2; n       dat[k] = dat[2 * k + 1] + dat[2 * k + 2]; n     } n   } n   int query(int a, int b) { return query(a, b, 0, 0, n); } n   int query(int a, int b, int k, int l, int r) { n     if (r <= a || b <= l) return 0; n     if (a <= l && r <= b) return dat[k]; n     int vl = query(a, b, 2 * k + 1, l, (l + r) / 2); n     int vr = query(a, b, 2 * k + 2, (l + r) / 2, r); n     return vl + vr; n   } n }; n class Heavy_Light_Decomposition { n  public: n   BiDGraph g, compg; n   vector<int> sz, depth, chain, par; n   int bn = 0; n   vector<int> bvn, inbn; n   vector<vector<int>> bv; n   Heavy_Light_Decomposition(BiDGraph graph, vector<int> root) n       : g(graph), n         compg(graph.vn), n         sz(graph.vn, 1), n         depth(graph.vn), n         chain(graph.vn), n         par(graph.vn), n         bvn(graph.vn, -1), n         inbn(graph.vn) { n     for (auto itr : root) getsz(itr, itr); n     bv.push_back(vector<int>()); n     for (auto itr : root) { n       if (bv[bv.size() - 1].size()) bv.push_back(vector<int>()), bn++; n       HLD(itr, -1, itr, bn); n     } n   } n   int getsz(int cur, int p) { n     par[cur] = p; n     for (auto itr : g.g[cur]) n       if (p != itr.first) n         depth[itr.first] = depth[cur] + 1, sz[cur] += getsz(itr.first, cur); n     return sz[cur]; n   } n   void HLD(int cur, int p, int head, int num) { n     chain[cur] = head, bvn[cur] = num; n     inbn[cur] = bv[num].size(), bv[num].push_back(cur); n     pair<int, int> Maxc = {-1, -1}; n     for (auto itr : g.g[cur]) n       if (itr.first != p) Maxc = max(Maxc, {sz[itr.first], itr.first}); n     for (auto itr : g.g[cur]) n       if (itr.first != p) { n         int nb = num; n         if (itr.first != Maxc.second) { n           bv.push_back(vector<int>()); n           nb = ++bn; n         } n         HLD(itr.first, cur, itr.first == Maxc.second ? head : itr.first, nb); n       } n   } n   int lca(int a, int b) { n     if (chain[a] == chain[b]) return depth[a] < depth[b] ? a : b; n     if (depth[chain[a]] > depth[chain[b]]) return lca(par[chain[a]], b); n     return lca(a, par[chain[b]]); n   } n   void for_each_edge(int a, int b, function<void(int, int)> func) { n     if (chain[a] == chain[b]) n       return func(inbn[a] < inbn[b] ? a : b, inbn[a] < inbn[b] ? b : a); n     if (depth[chain[a]] < depth[chain[b]]) swap(a, b); n     for_each_edge(a, chain[a], func), for_each_edge(par[chain[a]], b, func); n   } n }; n struct UnionFind { n   vector<int> data; n   UnionFind(int size) : data(size, -1) {} n   bool unionSet(int x, int y) { n     x = root(x); n     y = root(y); n     if (x != y) { n       if (data[y] < data[x]) swap(x, y); n       data[x] += data[y]; n       data[y] = x; n     } n     return x != y; n   } n   bool findSet(int x, int y) { return root(x) == root(y); } n   int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } n   bool isroot(int x) { return data[x] < 0; } n   int size(int x) { return -data[root(x)]; } n }; n int main() { n   int n; n   cin >> n; n   BiDGraph g(n); n   vector<int> t(n); n   vector<int> root; n   UnionFind uf(n); n   for (int i = (0); (n) > i; i++) { n     int p; n     scanf( %d %d , &p, &t[i]); n     if (p == -1) root.push_back(i); n     if (p > 0) uf.unionSet(i, p - 1), g.con(i, p - 1); n   } n   Heavy_Light_Decomposition hld(g, root); n   vector<RSQ> seg; n   for (int i = (0); (hld.bv.size()) > i; i++) { n     seg.push_back(RSQ(hld.bv[i].size())); n     for (int j = (0); (hld.bv[i].size()) > j; j++) n       seg[i].add(j, t[hld.bv[i][j]]); n   } n   int q; n   cin >> q; n   for (int i = (0); (q) > i; i++) { n     int mode, p, c; n     scanf( %d %d %d , &mode, &p, &c); n     c--, p--; n     if (c == p || !uf.findSet(p, c)) { n       printf( NO n ); n       continue; n     } n     int lca = hld.lca(p, c); n     if (mode == 1) { n       bool f = 0; n       if (lca == p) { n         int sum = 0; n         hld.for_each_edge(p, c, [&](int u, int v) { n           sum += seg[hld.bvn[u]].query(hld.inbn[u], hld.inbn[v] + 1); n           if (u == lca) { n             sum -= t[lca]; n           } else if (v == lca) { n             sum -= t[lca]; n           } n         }); n         if (sum == 0) f = 1; n       } n       printf(f ?  YES n  :  NO n ); n     } else { n       if (lca == c) { n         printf( NO n ); n         continue; n       } n       int sum = 0, sum2 = 0; n       hld.for_each_edge(p, lca, [&](int u, int v) { n         sum += seg[hld.bvn[u]].query(hld.inbn[u], hld.inbn[v] + 1); n         if (u == lca) { n           sum -= t[lca]; n         } else if (v == lca) { n           sum -= t[lca]; n         } n       }); n       hld.for_each_edge(c, lca, [&](int u, int v) { n         sum2 += seg[hld.bvn[u]].query(hld.inbn[u], hld.inbn[v] + 1); n         if (u == lca) { n           sum2 -= t[lca]; n         } else if (v == lca) { n           sum2 -= t[lca]; n         } n       }); n       if (sum == 0 && sum2 == (hld.depth[c] - hld.depth[lca])) n         printf( YES n ); n       else n         printf( NO n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n ostream& operator<<(ostream& os, vector<T> V) { n   for (auto v : V) os << v <<    ; n   return cout <<   ; n } n template <class T> n ostream& operator<<(ostream& os, set<T> S) { n   for (auto s : S) os << s <<    ; n   return cout <<   ; n } n template <class L, class R> n ostream& operator<<(ostream& os, pair<L, R> P) { n   return os << P.first <<     << P.second; n } n const long long mod = 1; n long long inv(long long i) { n   if (i == 1) return 1; n   return (mod - ((mod / i) * inv(mod % i)) % mod) % mod; n } n long long gcd(long long a, long long b) { n   if (a == 0) return b; n   return gcd(b, b % a); n } n int main() { n   int r, h; n   cin >> r >> h; n   int ans = 2 * (h / r); n   if ((double)(h - (ans / 2) * r) / (double)r >= sqrt(3) / 2) { n     ans += 3; n   } else if (2 * (h - (ans / 2) * r) >= r) { n     ans += 2; n   } else n     ans++; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int t; n double pi = acos(-1.0); n double d, h, v, e; n int main() { n   scanf( %lf%lf%lf%lf , &d, &h, &v, &e); n   double r = d / 2; n   if (pi * r * r * e > v) n     cout <<  NO  << endl; n   else { n     double s = (pi * r * r * h) / (v - pi * r * r * e); n     cout <<  YES  << endl; n     printf( %.12f n , s); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int ans[5001][5001]; n int main() { n   memset((ans), 0, sizeof(ans)); n   int n, m, l, r; n   char s[5001]; n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     l = r = 0; n     scanf( %s , s); n     for (int j = 0; j < m; j++) { n       if (s[j] ==  0 ) { n         l = j + 1; n       } else n         ans[l][j]++; n     } n   } n   int maxi = -1, x, y; n   for (int i = 2; i < m; i++) { n     for (int j = 1; j <= i; j++) { n       ans[j][i] += ans[j - 1][i]; n     } n   } n   for (int i = 0; i <= m; i++) n     for (int j = i; j < m; j++) maxi = max((j - i + 1) * ans[i][j], maxi); n   cout << maxi << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, fre[11], fre1[11]; n string tot, no, cm =   , cm1 =   ; n bool belongs(int x) { n   int tmp = x, len = 0, i; n   int tmf[11] = {}; n   while (tmp > 0) { n     tmf[(tmp % 10)]++; n     tmp /= 10; n     len++; n   } n   if (n - len == x) { n     for (i = 0; i < 10; i++) { n       if (fre1[i] < tmf[i]) return false; n     } n     return true; n   } n   return false; n } n int main() { n   int i, j; n   cin >> tot; n   cin >> no; n   if (tot ==  01  || tot ==  10 ) { n     cout <<  0 n ; n     return 0; n   } n   n = tot.length(); n   m = no.length(); n   for (i = 0; i < n; i++) { n     fre[tot[i] - 48]++; n     fre1[tot[i] - 48]++; n   } n   for (i = 0; i < m; i++) { n     fre1[no[i] - 48]--; n   } n   for (i = 1; i <= n; i++) { n     if (belongs(i)) { n       int tmp = i; n       while (tmp > 0) { n         fre1[(tmp % 10)]--; n         tmp /= 10; n       } n       break; n     } n   } n   int tm; n   for (i = 0; i < 10; i++) { n     tm = fre1[i]; n     while (tm > 0) { n       cm1 += (i + 48); n       tm--; n     } n   } n   for (i = 1; i < 10; i++) { n     if (fre1[i] > 0) { n       cm += (i + 48); n       fre1[i]--; n       break; n     } n   } n   for (i = 0; i < 10; i++) { n     tm = fre1[i]; n     while (tm > 0) { n       cm += (i + 48); n       tm--; n     } n   } n   if (no[0] ==  0 ) { n     i = 1; n     n = cm.size(); n     while (i < n && cm[i] < no[0]) { n       i++; n     } n     string ans1 =   , ans2 =   ; n     for (j = 0; j < min(i, n); j++) ans1 += cm[j]; n     ans1 += no; n     for (j = i; j < n; j++) ans1 += cm[j]; n     i = 1; n     while (i < n && cm[i] <= no[0]) { n       i++; n     } n     for (j = 0; j < min(i, n); j++) ans2 += cm[j]; n     ans2 += no; n     for (j = i; j < n; j++) ans2 += cm[j]; n     string ans; n     if (ans1[0] !=  0 ) { n       ans = ans1; n     } else if (ans2[0] !=  0 ) { n       ans = ans2; n     } n     if (ans1[0] !=  0 ) { n       ans = min(ans, ans1); n     } n     if (ans2[0] !=  0 ) { n       ans = min(ans, ans2); n     } n     cout << ans << endl; n   } else { n     string ans3 = no + cm1; n     i = 1; n     n = cm.size(); n     while (i < n && cm[i] < no[0]) { n       i++; n     } n     string ans1 =   , ans2 =   ; n     for (j = 0; j < min(i, n); j++) ans1 += cm[j]; n     ans1 += no; n     for (j = i; j < n; j++) ans1 += cm[j]; n     i = 1; n     while (i < n && cm[i] <= no[0]) { n       i++; n     } n     for (j = 0; j < min(i, n); j++) ans2 += cm[j]; n     ans2 += no; n     for (j = i; j < n; j++) ans2 += cm[j]; n     string ans; n     if (ans1[0] !=  0 ) { n       ans = ans1; n     } else if (ans2[0] !=  0 ) { n       ans = ans2; n     } else if (ans3[0] !=  0 ) { n       ans = ans3; n     } n     if (ans1[0] !=  0 ) { n       ans = min(ans, ans1); n     } n     if (ans2[0] !=  0 ) { n       ans = min(ans, ans2); n     } n     if (ans3[0] !=  0 ) { n       ans = min(ans, ans3); n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef long long ll; n typedef long l; n typedef pair<int, int> pint; n typedef vector<pint> vpint; n typedef vector<int> vint; n typedef vector<vint> vvint; n int n, m, x[123457], cum[1234567]; n int ans; n map<int, int> mp; n int main() { n   cin >> n; n   for (int i = 0; i < n; ++i) { n     cin >> x[i]; n     cum[i] = x[i]; n   } n   sort(cum, cum + n); n   for (int i = 0; i < n; ++i) { n     if (x[i] != cum[i]) ans++; n   } n   if (ans < 3) n     cout <<  YES ; n   else n     cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n struct ma { n   int x, vt; n } a[105]; n bool cmp(ma p, ma y) { return p.x < y.x; } n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i].x; n     a[i].vt = i; n   } n   sort(a + 1, a + n + 1, cmp); n   for (int i = 1; i <= n / 2; i++) n     cout << a[i].vt <<     << a[n - i + 1].vt << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t; n   cin >> t; n   long long arr[t], sum = 0; n   for (int i = 0; i < t; ++i) { n     cin >> arr[i]; n     sum += arr[i]; n   } n   if (sum != 0) { n     cout <<  YES  << endl; n     cout << 1 << endl; n     cout << 1 <<     << t << endl; n     return 0; n   } n   if (t == 1) { n     if (arr[0] != 0) { n       cout <<  YES  << endl; n       cout << 1 << endl; n       cout << 1 << endl; n     } else n       cout <<  NO  << endl; n   } else { n     for (int i = 0; i < t; i++) { n       sum += arr[i]; n       if (sum != 0) { n         cout <<  YES  << endl; n         cout << 2 << endl; n         cout << 1 <<     << i + 1 << endl; n         cout << i + 2 <<     << t << endl; n         return 0; n       } n     } n     cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long global = 0; n void test_case(long long); n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t; n   int yes = 1; n   if (yes) n     cin >> t; n   else n     t = 1; n   for (long long T = 0; T < t; T++) { n     test_case(T); n   } n   return 0; n } n void test_case(long long T) { n   long long n, m; n   cin >> n >> m; n   vector<string> vec(n); n   for (long long(i) = 0; (i) < n; (i)++) { n     cin >> vec[i]; n   } n   vector<long long> x = {0, 1, 0, -1}, y = {1, 0, -1, 0}; n   long long g = 0; n   for (long long(i) = 0; (i) < n; (i)++) { n     for (long long(j) = 0; (j) < m; (j)++) { n       if (vec[i][j] ==  G ) g++; n       if (vec[i][j] ==  B ) { n         for (long long k = 0; k < 4; k++) { n           long long idx = i + x[k]; n           long long jdx = j + y[k]; n           if (idx >= 0 && idx < n && jdx >= 0 && jdx < m) { n             if (vec[idx][jdx] ==  G ) { n               cout <<  no  << endl; n               return; n             } else if (vec[idx][jdx] ==  . ) { n               vec[idx][jdx] =  # ; n             } n           } n         } n       } n     } n   } n   queue<pair<long long, long long>> q; n   q.push(pair<long long, long long>(n - 1, m - 1)); n   map<pair<long long, long long>, long long> v; n   v[pair<long long, long long>(n - 1, m - 1)]++; n   long long vg = 0; n   while (!q.empty()) { n     auto f = q.front(); n     q.pop(); n     if (vec[f.first][f.second] ==  G ) n       vg++; n     else if (vec[f.first][f.second] ==  # ) n       break; n     for (long long k = 0; k < 4; k++) { n       long long idx = f.first + x[k]; n       long long jdx = f.second + y[k]; n       if (idx >= 0 && idx < n && jdx >= 0 && jdx < m) { n         if (vec[idx][jdx] ==  #  || vec[idx][jdx] ==  B ) continue; n         if (!v[pair<long long, long long>(idx, jdx)]) { n           v[pair<long long, long long>(idx, jdx)]++; n           q.push(pair<long long, long long>(idx, jdx)); n         } n       } n     } n   } n   if (vg == g) n     cout <<  yes  << endl; n   else n     cout <<  no  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1004; n int cnk[N][N] = {0}; n int mod = 1000000007; n void init_cnk() { n   for (int i = 0; i < N; ++i) { n     cnk[i][0] = 1; n     cnk[i][i] = 1; n   } n   for (int i = 1; i < N; ++i) { n     for (int j = 1; j < N; ++j) { n       cnk[i][j] = (cnk[i - 1][j - 1] + cnk[i - 1][j]) % mod; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cout.precision(10); n   cout << fixed; n   int k; n   cin >> k; n   vector<int> c(k, 0); n   for (int i = 0; i < k; ++i) cin >> c[i]; n   init_cnk(); n   int n = c.size(); n   vector<int> res(n, 0); n   res[0] = 1; n   int acc = c[0]; n   for (int i = 1; i < n; ++i) { n     int cur = c[i]; n     for (int j = 0; j < cur; ++j) { n       res[i] += (1LL * cnk[acc - 1 + j][j] * res[i - 1]) % (1LL * mod); n       res[i] %= mod; n     } n     acc += cur; n   } n   cout << res[n - 1] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = 300 * 1000 + 7; n const long long MOD = 1000 * 1000 * 1000 + 7; n const long long INF = 1000000000000000 + 7; n const double PI = 2 * acos(0.0); n long long a, b, c; n int main(void) { n   cin >> a >> b >> c; n   if (a > b || a > c) n     cout <<  No  << endl; n   else n     cout <<  Yes  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int arr[15]; n   for (int i = 1; i <= 14; i++) cin >> arr[i]; n   long long int brr[15]; n   long long int ans = -1; n   for (int i = 1; i <= 14; i++) { n     if (arr[i] == 0) continue; n     for (int j = 1; j <= 14; j++) brr[j] = arr[j]; n     long long int st = brr[i]; n     brr[i] = 0; n     for (int j = 1; j <= 14; j++) brr[j] += st / 14; n     st = st % 14; n     int k = i + 1; n     if (k > 14) k = 1; n     while (st > 0) { n       brr[k] += 1; n       k = k + 1; n       if (k > 14) k = 1; n       st--; n     } n     long long int temp = 0; n     for (int j = 1; j <= 14; j++) n       if (brr[j] % 2 == 0) temp += brr[j]; n     ans = (ans > temp) ? ans : temp; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k; n void search(int cur) { n   int tot, c[10]; n   int ok; n   if (cur == n) n     tot++; n   else n     for (int i = 0; i < n; i++) { n       ok = 1; n       c[cur] = i; n     } n   for (int j = 0; j < cur; j++) { n     if (c[cur] == c[j] || cur - c[cur] == j - c[j] || n         cur + c[cur] == j + c[j]) { n       ok = 0; n       break; n     } n   } n   if (ok) search(cur + 1); n } n const long long MAXN = 55; n long long num[MAXN]; n void xswl() { n   scanf( %lld%lld , &n, &k); n   for (long long i = 1; i <= n; ++i) { n     scanf( %lld , &num[i]); n   } n   num[0] = 1; n   sort(num + 1, num + 1 + n); n   long long res = 999999999999999; n   for (long long i = 2e5; i >= 0; --i) { n     long long cnt = 0; n     long long nowr = 0; n     int t = lower_bound(num + 1, num + 1 + n, i) - num; n     for (int j = t; j <= n; ++j) { n       long long now = 0; n       long long u = num[j]; n       while (u > i) { n         ++now; n         u >>= 1; n       } n       if (u == i) { n         ++cnt; n         nowr += now; n       } n       if (cnt == k) break; n     } n     if (cnt == k) { n       if (res > nowr) { n         res = nowr; n       } n     } n   } n   printf( %lld , res); n } n int main() { xswl(); } n


#include <bits/stdc++.h> n using namespace std; n int maxn = 1000000000; n int main(int argc, char const *argv[]) { n   int t; n   cin >> t; n   while (t--) { n     int a, b; n     cin >> a >> b; n     if (a > b) a = a + b, b = a - b, a = a - b; n     int side = max(2 * a, b); n     cout << side * side << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   cin.tie(0); n   cout.tie(0); n   ios_base::sync_with_stdio(0); n   int q; n   cin >> q; n   while (q--) { n     int a, b, n, S; n     cin >> a >> b >> n >> S; n     int x = min(a, S / n); n     cout << (S - x * n <= b ?  YES  :  NO ) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int c[400000], t[400000], n, m, x[400000]; n int main() { n   scanf( %d%d , &n, &m); n   int s = 0; n   for (int i = 0; i < n; ++i) { n     scanf( %d%d , &c[i], &t[i]); n     s += c[i] * t[i]; n     x[i] = s; n   } n   while (m--) { n     int a; n     scanf( %d , &a); n     printf( %d n , lower_bound(x, x + n, a) - x + 1); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = (long long)1000000000000; n const double eps = (double)1e-8; n const int mod = (int)1000000007; n const int maxn = (int)1e6 + 5; n int n, res, cnt, z[maxn]; n pair<pair<int, int>, pair<int, int> > a[maxn]; n vector<int> t[maxn]; n vector<pair<int, int> > vc[maxn]; n map<int, int> m; n int sum(int z, int r) { n   res = 0; n   for (; r >= 0; r = (r & (r + 1)) - 1) res += t[z][r]; n   return res; n } n void upd(int z, int i, int delta) { n   for (; i < (int)t[z].size(); i = (i | (i + 1))) t[z][i] += delta; n   return; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> n; n   cnt = 0; n   for (int i = (1); i <= (n); i++) { n     cin >> a[i].second.first >> a[i].first.first >> a[i].first.second; n     a[i].second.second = i; n     if (!m.count(a[i].first.second)) m[a[i].first.second] = ++cnt; n     vc[m[a[i].first.second]].push_back(make_pair(a[i].first.first, i)); n   } n   for (int i = (1); i <= (cnt); i++) { n     sort(vc[i].begin(), vc[i].end()); n     for (int j = (0); j < (vc[i].size()); j++) { n       z[vc[i][j].second] = j; n       t[i].push_back(0); n     } n   } n   for (int i = (1); i <= (n); i++) { n     if (a[i].second.first == 1) { n       upd(m[a[i].first.second], z[i], 1); n     } else if (a[i].second.first == 2) { n       upd(m[a[i].first.second], z[i], -1); n     } else { n       cout << sum(m[a[i].first.second], z[i]) <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n const int Mod = 1001943197; n const int Base = 34300; n const int MN = 100005, MQ = 100005, S = 500, MS = S + 5; n char s[MN], t[MN]; n int N, lt, Lim, per[MN]; n int pBase[MN]; n int Hs[MN], Ht[MN]; n inline int Hmerge(int h1, int h2, int l2) { n   return (int)(((long long)h1 * pBase[l2] + h2) % Mod); n } n inline int gHash(int *H, int lb, int rb) { n   return (int)(((long long)H[lb - 1] * (Mod - pBase[rb - lb + 1]) + H[rb]) % n                Mod); n } n inline bool smallerThan(int pos1, int pos2) { n   if (pos1 == pos2) return false; n   bool rev = false; n   if (pos1 > pos2) std::swap(pos1, pos2), rev = true; n   int lb = 0, rb = lt + (pos2 - pos1), ans = -1; n   while (lb <= rb) { n     int mid = (lb + rb) / 2; n     int hs1 = mid <= lt ? gHash(Ht, 1, mid) n                         : Hmerge(Ht[lt], gHash(Hs, pos1 + 1, pos1 + (mid - lt)), n                                  mid - lt); n     int hs2 = mid <= pos2 - pos1 ? gHash(Hs, pos1 + 1, pos1 + mid) n                                  : Hmerge(gHash(Hs, pos1 + 1, pos2), n                                           gHash(Ht, 1, mid - (pos2 - pos1)), n                                           mid - (pos2 - pos1)); n     if (hs1 == hs2) n       ans = mid, lb = mid + 1; n     else n       rb = mid - 1; n   } n   if (ans == lt + (pos2 - pos1)) return rev ? pos2 < pos1 : pos1 < pos2; n   char ch1 = ans < lt ? t[ans + 1] : s[pos1 + ans - lt + 1]; n   char ch2 = ans < pos2 - pos1 ? s[pos1 + ans + 1] : t[ans - (pos2 - pos1) + 1]; n   if (rev) std::swap(ch1, ch2); n   return ch1 < ch2; n } n int iper[MN], id[MN]; n int ST[17][MN]; n inline int gMin(int x, int y) { return iper[x] < iper[y] ? x : y; } n inline int RMQ(int l, int r) { n   int j = 31 - __builtin_clz(r - l + 1); n   return gMin(ST[j][l + (1 << j) - 1], ST[j][r]); n } n int Q, ql[MQ], qr[MQ], qk[MQ], qx[MQ], qy[MQ], Ans[MQ]; n std::vector<int> V[MS]; n int main() { n   scanf( %s%s%d , s + 1, t + 1, &Q); n   N = (int)(strlen(s + 1)), lt = (int)(strlen(t + 1)); n   for (int i = 1; i <= N; ++i) n     Hs[i] = (int)(((long long)Hs[i - 1] * Base + (s[i] -  a  + 1)) % Mod); n   for (int i = 1; i <= lt; ++i) n     Ht[i] = (int)(((long long)Ht[i - 1] * Base + (t[i] -  a  + 1)) % Mod); n   Lim = std::max(N, lt), pBase[0] = 1; n   for (int i = 1; i <= Lim; ++i) n     pBase[i] = (int)((long long)pBase[i - 1] * Base % Mod); n   for (int i = 1; i <= N + 1; ++i) per[i] = i - 1; n   std::sort(per + 1, per + N + 2, smallerThan); n   for (int i = 1; i <= N + 1; ++i) iper[per[i]] = i; n   for (int i = 0; i <= N; ++i) ST[0][i] = i; n   for (int j = 0; 2 << j <= N + 1; ++j) n     for (int i = (2 << j) - 1; i <= N; ++i) n       ST[j + 1][i] = gMin(ST[j][i - (1 << j)], ST[j][i]); n   for (int i = 1; i <= Q; ++i) { n     scanf( %d%d%d%d%d , &ql[i], &qr[i], &qk[i], &qx[i], &qy[i]); n     if (qk[i] > S) { n       int lim = N / qk[i], ans = -1; n       for (int j = 0; j <= lim; ++j) { n         int l = j * qk[i] + qx[i]; n         int r = j * qk[i] + qy[i]; n         l = std::max(l, ql[i]); n         r = std::min(r, qr[i]); n         if (l <= r) { n           int res = RMQ(l, r); n           if (ans == -1) n             ans = res; n           else n             ans = gMin(ans, res); n         } n       } n       Ans[i] = ans; n     } else n       V[qk[i]].push_back(i); n   } n   for (int k = 1; k <= S; ++k) { n     int tot = 0, mxlen = N / k + 1; n     for (int j = 0; j < k; ++j) n       for (int i = j; i <= N; i += k) ST[0][++tot] = i, id[i] = tot; n     for (int j = 0; 2 << j <= mxlen; ++j) n       for (int i = 2 << j; i <= tot; ++i) n         ST[j + 1][i] = gMin(ST[j][i - (1 << j)], ST[j][i]); n     for (int i : V[k]) { n       int ans = -1; n       for (int j = qx[i]; j <= qy[i]; ++j) { n         int l = id[j] + (ql[i] - j + k - 1) / k; n         int r = id[j] + (qr[i] - j + k) / k - 1; n         if (l <= r) { n           int res = RMQ(l, r); n           if (ans == -1) n             ans = res; n           else n             ans = gMin(ans, res); n         } n       } n       Ans[i] = ans; n     } n   } n   for (int i = 1; i <= Q; ++i) printf( %d%c , Ans[i],    n [i == Q]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[100004]; n long long k, mod = 1000000007; n long long qpow(long long n, long long m) { n   long long ans = 1; n   for (; m; m >>= 1) { n     if (m & 1) ans = ans * n % mod; n     n = n * n % mod; n   } n   return ans; n } n int main() { n   scanf( %s %lld , s, &k); n   int l = strlen(s); n   long long p = 0, q = 0; n   for (int i = 0; i < l; i++) n     if (s[i] ==  0  || s[i] ==  5 ) p = (p + qpow(2, i)) % mod; n   q = (qpow(2, k * l) - 1) * qpow(qpow(2, l) - 1, mod - 2) % mod; n   printf( %lld n , p * q % mod); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<int> v(6); n   for (int i = 0; i < 6; ++i) cin >> v[i]; n   int n; n   cin >> n; n   vector<pair<int, int>> a; n   int num; n   for (int i = 0; i < n; ++i) { n     cin >> num; n     for (int j = 0; j < 6; ++j) { n       a.push_back({num - v[j], i}); n     } n   } n   sort(a.begin(), a.end()); n   int ans = 1e9 + 7; n   map<int, int> mp; n   int t = 0; n   int l = 0; n   for (int i = 0; i < a.size(); ++i) { n     int k = a[i].second; n     if (mp[k] == 0) { n       t++; n     } n     mp[k]++; n     while (mp[a[l].second] > 1) { n       mp[a[l].second]--; n       l++; n     } n     if (t == n) { n       ans = min(ans, a[i].first - a[l].first); n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   char c; n   unsigned int mask; n   int u; n   vector<unsigned int> ip; n   set<unsigned int> net; n   cin >> n >> k; n   scanf( %c , &c); n   unsigned int x, x1; n   for (int i = 0; i < n; i++) { n     c = 0; n     x = 0; n     x1 = 0; n     while (c !=   n ) { n       scanf( %c , &c); n       if ((c !=  . ) && (c !=   n )) { n         x *= 10; n         x += (c -  0 ); n       } else { n         x1 = x1 << 8; n         x1 += x; n         x = 0; n       } n     } n     ip.push_back(x1); n   } n   for (int len = 1; len < 32; len++) { n     mask = 1; n     for (int y = 1; y < len; y++) { n       mask = mask << 1; n       mask++; n     } n     mask = mask << (32 - len); n     unsigned int v = 0; n     for (int i = 0; i < n; i++) { n       v = ip[i]; n       v &= mask; n       net.insert(v); n     } n     u = net.size(); n     if (u == k) { n       unsigned int xx[4]; n       xx[3] = mask % 256; n       mask /= 256; n       xx[2] = mask % 256; n       mask /= 256; n       xx[1] = mask % 256; n       mask /= 256; n       xx[0] = mask; n       cout << xx[0] <<  .  << xx[1] <<  .  << xx[2] <<  .  << xx[3] << endl; n       return 0; n     } n     if (u > k) { n       cout <<  -1  << endl; n       return 0; n     } n     net.clear(); n   } n   cout <<  -1  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n int t; n long long sufa[100010]; n long long a[100010]; n pair<long long, long long> ab[100010]; n long long n, m; n int main() { n   cin >> t; n   while (t--) { n     scanf( %lld %lld , &n, &m); n     for (long long i = 0; i < m; i++) { n       scanf( %lld %lld , &ab[i].first, &ab[i].second); n     } n     sort(ab, ab + m); n     sufa[m] = 0; n     sufa[m - 1] = a[m - 1] = ab[m - 1].first; n     for (int i = m - 1 - 1; i >= 0; i--) { n       a[i] = ab[i].first; n       sufa[i] = sufa[i + 1] + a[i]; n     } n     long long ans = 0; n     if (n <= m) { n       ans = sufa[m - n]; n     } n     for (long long i = 0; i < m; i++) { n       long long idx = lower_bound(a, a + m, ab[i].second) - a; n       idx = max(idx, m - n); n       long long costn = m - idx; n       long long costa = 0; n       if (idx > i && costn < n) { n         costa = ab[i].first; n         costn += 1; n       } n       ans = max(ans, sufa[idx] + costa + (n - costn) * ab[i].second); n     } n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n long long mpow(long long a, long long n, long long mod) { n   long long ret = 1; n   long long b = a; n   while (n) { n     if (n & 1) ret = (ret * b) % mod; n     b = (b * b) % mod; n     n >>= 1; n   } n   return (long long)ret; n } n using namespace std; n int a[100000 + 5]; n map<int, int> ind; n long long cnt[1500]; n long long dp[1400][1400]; n long long fact[100000 + 5]; n long long inv[100000 + 5]; n void computefact() { n   fact[0] = 1; n   inv[0] = 1; n   long long i, j; n   for (j = 1; j < 100000 + 5; j++) { n     fact[j] = (fact[j - 1] * j) % 1000000007; n     inv[j] = mpow(fact[j], 1000000007 - 2, 1000000007); n   } n } n long long ncr(long long n, long long r) { n   long long den = (inv[r] * inv[n - r]) % 1000000007; n   long long num = (fact[n] * den) % 1000000007; n   return num; n } n bool chk(int x) { n   while (x != 0) { n     int p = x % 10; n     if (!(p == 4 || p == 7)) { n       return 0; n     } n     x /= 10; n   } n   return 1; n } n int main() { n   int i, j; n   vector<int> luck; n   long long n, len; n   cin >> n >> len; n   long long unl = 0; n   int c = 1; n   computefact(); n   for (j = 0; j < n; j++) { n     cin >> a[j]; n     if (chk(a[j])) { n       if (!ind[a[j]]) { n         luck.push_back(a[j]); n         ind[a[j]] = c; n         cnt[c]++; n         c++; n       } else { n         cnt[ind[a[j]]]++; n       } n     } else n       unl++; n   } n   dp[0][0] = 1; n   int sz = luck.size(); n   for (i = 1; i <= sz; i++) { n     for (j = 0; j <= sz; j++) { n       dp[i][j] = (dp[i - 1][j] + (dp[i - 1][j - 1] * cnt[i]) % 1000000007) % n                  1000000007; n     } n   } n   long long ans = 0; n   for (long long k = 0; k <= min(len, unl); k++) { n     long long q = len - k; n     if (q > sz) continue; n     ans = (ans + (ncr(unl, k) * dp[sz][q]) % 1000000007) % 1000000007; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,unroll-loops ) n using namespace std; n mt19937 rng((int)std::chrono::steady_clock::now().time_since_epoch().count()); n const int N = 1e5 + 3; n int ok[N], tsz[N], dep[N]; n vector<int> adj[N], g[N]; n multiset<int> mset[N]; n int vis[N]; n bool flag; n void dfs2(int u) { n   vis[u] = 1; n   for (auto v : adj[u]) { n     if (vis[v] == 2) flag = false; n     if (!vis[v]) dfs2(v); n   } n   vis[u] = 2; n } n void dfs(int u, int keep) { n   vis[u] = 1; n   int bigchild = -1, high = -1; n   for (auto v : adj[u]) { n     if (!vis[v] and tsz[v] > high) { n       high = tsz[v]; n       bigchild = v; n     } n   } n   multiset<int> backEdge; n   for (auto v : adj[u]) { n     if (!vis[v] and v != bigchild) n       dfs(v, 0); n     else if (vis[v] == 1) n       backEdge.insert(v); n   } n   if (bigchild != -1) { n     dfs(bigchild, 1); n     swap(mset[u], mset[bigchild]); n   } n   for (auto x : backEdge) mset[u].insert(x); n   for (auto v : adj[u]) { n     if (v != bigchild) { n       for (auto x : mset[v]) { n         mset[u].insert(x); n       } n     } n   } n   mset[u].erase(u); n   if (int(mset[u].size()) == 1) { n     g[*mset[u].begin()].push_back(u); n   } n   vis[u] = 2; n } n bool interesting(int u) { n   flag = true; n   dfs2(u); n   return flag; n } n void dfs4(int u) { n   vis[u] = 1; n   ok[u] = 1; n   for (int v : g[u]) { n     if (!vis[v]) dfs4(v); n   } n   vis[u] = 2; n } n int dfs3(int u, int d = 0) { n   vis[u] = 1; n   dep[u] = d; n   for (auto v : adj[u]) { n     if (!vis[v]) tsz[u] += dfs3(v, d + 1); n   } n   vis[u] = 2; n   return tsz[u] + 1; n } n void solve() { n   int n, m; n   cin >> n >> m; n   for (int i = 1; i <= n; ++i) n     adj[i].clear(), tsz[i] = 0, mset[i].clear(), ok[i] = 0, g[i].clear(); n   for (int i = 0; i < m; ++i) { n     int a, b; n     cin >> a >> b; n     adj[a].push_back(b); n   } n   int root = -1; n   for (int t = 0; t < 100; ++t) { n     int u = rng() % n + 1; n     if (interesting(u)) { n       root = u; n     } n     for (int i = 1; i <= n; ++i) vis[i] = 0; n     if (root != -1) break; n   } n   if (root == -1) { n     cout << -1 << endl; n     return; n   } n   dfs3(root); n   for (int i = 1; i <= n; ++i) vis[i] = 0; n   dfs(root, 0); n   for (int i = 1; i <= n; ++i) vis[i] = 0; n   dfs4(root); n   vector<int> ans; n   for (int i = 1; i <= n; ++i) n     if (ok[i]) ans.push_back(i); n   if (5 * int(ans.size()) < n) n     cout << -1 << endl; n   else { n     for (auto x : ans) cout << x <<    ; n     cout << endl; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int vp, vd, t, f, c; n   cin >> vp >> vd >> t >> f >> c; n   int vs = vd - vp; n   if (vp > vd) { n     cout << 0; n     return 0; n   } n   if (vp == vd) { n     cout << 0; n     return 0; n   } n   double d = vp * t; n   d += d / (1.0 * vs) * vp; n   cerr << d << endl; n   if (int(d) >= c) { n     cout << 0; n     return 0; n   } n   int ans = 1; n   while ((int)d < c) { n     d += (d / vd + f) * vp; n     d += (d / vs) * vp; n     if (d - c > -1e-12) { n       cout << ans; n       return 0; n     } n     ans++; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k, k1, k2, m; n int main() { n   cin >> n >> k; n   m = n; n   while (m % 2 == 0) { n     k1++; n     m /= 2; n   } n   while (m % 5 == 0) { n     k2++; n     m /= 5; n   } n   for (int i = 1; i <= max(0ll, k - k1); ++i) { n     n *= 2; n   } n   for (int i = 1; i <= max(0ll, k - k2); ++i) { n     n *= 5; n   } n   cout << n; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, aa[300005], bb[300005], v[1000005], q; n int x[4000005], y[4000005], dx; n void build(int l, int r, int i) { n   if (l + 1 == r) { n     y[i] = v[l]; n     return; n   } n   int mi = (l + r) / 2; n   build(l, mi, i * 2); n   build(mi, r, i * 2 + 1); n   y[i] = max(y[i * 2], y[i * 2 + 1]); n } n void add(int a, int b, int l, int r, int i) { n   if (a == l && b == r) { n     x[i] += dx; n     y[i] += dx; n     return; n   } n   int mi = (l + r) / 2; n   if (a < mi) add(a, min(mi, b), l, mi, i * 2); n   if (mi < b) add(max(a, mi), b, mi, r, i * 2 + 1); n   y[i] = max(y[i * 2], y[i * 2 + 1]) + x[i]; n } n int find(int l, int r, int i, int vv) { n   if (l + 1 == r) return l; n   vv -= x[i]; n   int mi = (l + r) / 2; n   if (y[i * 2 + 1] > vv) return find(mi, r, i * 2 + 1, vv); n   return find(l, mi, i * 2, vv); n } n int main() { n   scanf( %d%d , &n, &m); n   v[0] = n + 1; n   for (int i = 1; i <= n; i++) { n     scanf( %d , aa + i); n     v[aa[i]]++; n   } n   for (int i = 1; i <= m; i++) { n     scanf( %d , bb + i); n     v[bb[i]]--; n   } n   for (int i = 1000000; i >= 0; i--) v[i] += v[i + 1]; n   build(0, 1000001, 1); n   scanf( %d , &q); n   while (q--) { n     int ta, tb, tc; n     scanf( %d%d%d , &ta, &tb, &tc); n     if (ta == 1) { n       if (aa[tb] < tc) { n         dx = 1; n         add(aa[tb] + 1, tc + 1, 0, 1000001, 1); n       } else if (aa[tb] > tc) { n         dx = -1; n         add(tc + 1, aa[tb] + 1, 0, 1000001, 1); n       } n       aa[tb] = tc; n     } else { n       if (bb[tb] < tc) { n         dx = -1; n         add(bb[tb] + 1, tc + 1, 0, 1000001, 1); n       } else if (bb[tb] > tc) { n         dx = 1; n         add(tc + 1, bb[tb] + 1, 0, 1000001, 1); n       } n       bb[tb] = tc; n     } n     ta = find(0, 1000001, 1, 0); n     if (ta == 0) ta = -1; n     printf( %d n , ta); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i, maxi, mini; n   cin >> n; n   int z[n], o = 0; n   for (i = 0; i < n; i++) { n     cin >> z[i]; n     if (i == 0) { n       maxi = z[i]; n       mini = z[i]; n     } n     if (i > 0) { n       if (z[i] > maxi) { n         o++; n         maxi = z[i]; n       } n       if (z[i] < mini) { n         o++; n         mini = z[i]; n       } n     } n   } n   cout << o; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1000000007; n const int INF = 1e9; n const long long LINF = 1LL * INF * INF; n const int MAXN = 100007; n const double EPS = 1e-7; n int A[MAXN]; n int main() { n   ios_base::sync_with_stdio(0); n   int n, m; n   cin >> n >> m; n   if (n == 1 && m == 1) { n     cout <<  YES n1 ; n     return 0; n   } n   if (n == 1 && m <= 3 || m == 1 && n <= 3 || n == 2 && m <= 3 || n       m == 2 && n <= 3) { n     cout <<  NO ; n     return 0; n   } n   if (n == 1 && m == 4) { n     cout <<  YES n2 4 1 3 ; n     return 0; n   } n   if (n == 4 && m == 1) { n     cout <<  YES n2 n4 n1 n3 ; n     return 0; n   } n   if (n == 2 && m == 4) { n     cout <<  YES n ; n     cout <<  5 4 7 2  << endl; n     cout <<  3 6 1 8 ; n     return 0; n   } n   if (n == 4 && m == 2) { n     cout <<  YES n ; n     cout <<  6 1 n ; n     cout <<  3 8 n ; n     cout <<  2 5 n ; n     cout <<  7 4 n ; n     return 0; n   } n   if (n == 3 && m == 3) { n     cout <<  YES n ; n     cout <<  2 9 4 n ; n     cout <<  7 5 3 n ; n     cout <<  6 1 8 n ; n     return 0; n   } n   if (n == 3 && m == 4) { n     cout <<  YES n ; n     cout <<  6 8 11 2 n ; n     cout <<  9 3 1 10 n ; n     cout <<  4 12 7 5 n ; n     return 0; n   } n   if (n == 4 && m == 3) { n     cout <<  YES n ; n     cout <<  10 3 9 n ; n     cout <<  5 1 7 n ; n     cout <<  12 6 11 n ; n     cout <<  4 8 2 n ; n     return 0; n   } n   if (n == 4 && m == 4) { n     cout <<  YES n ; n     cout <<  2 11 14 9 n ; n     cout <<  16 6 8 1 n ; n     cout <<  13 3 10 4 n ; n     cout <<  7 5 12 15 n ; n     return 0; n   } n   if (n >= 5) { n     cout <<  YES n ; n     for (int i = (0); i < (2); ++i) { n       for (int f = i * m + 1; f <= n * m; f += 2 * m) { n         for (int j = (1); j < (m + 1); ++j) { n           int cur = f + j - 1; n           if ((j + 1) & 1) cur += m; n           if (cur > n * m) cur -= n * m; n           cout << cur <<    ; n         } n         cout << endl; n       } n     } n     return 0; n   } n   if (m >= 5) { n     cout <<  YES n ; n     for (int i = (1); i < (n + 1); ++i) { n       int cur = 1; n       for (int j = (1); j < (m + 1); ++j) { n         int c = cur; n         cur += 2; n         if (cur > m) cur = 2; n         if ((i + 1) & 1) ++c; n         if (c > m) c -= m; n         cout << (i - 1) * m + c <<    ; n       } n       cout << endl; n     } n     return 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 2e5 + 5; n int n, k, a; n int vis_time[MAX], vis_cnt[MAX], ans; n struct data { n   int size, op; n   bool operator<(data b) const { n     if (size == b.size) n       return op > b.op; n     else n       return size < b.size; n   } n }; n priority_queue<data> line; n int main() { n   scanf( %d%d , &n, &k); n   for (register int i = 1; i <= n; ++i) { n     scanf( %d , &a); n     line.push((data){a, 0}); n   } n   ans = 0x3f3f3f3f; n   while (!line.empty()) { n     data tmp = line.top(); n     line.pop(); n     int size = tmp.size, op = tmp.op; n     vis_time[size]++; n     vis_cnt[size] += op; n     if (vis_time[size] == k) { n       ans = min(ans, vis_cnt[size]); n     } n     if (!size) n       continue; n     else n       line.push((data){size / 2, op + 1}); n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long dp[100000 + 25]; n struct node { n   int iz, der; n   long long tiempo; n   node() {} n   node(long long t, int i, int d) { n     tiempo = t; n     iz = i; n     der = d; n   } n }; n struct otro { n   int proct, pos; n   long long tiemp; n   otro() {} n   otro(int ps, long long time, int timprt) { n     pos = ps; n     tiemp = time; n     proct = timprt; n   } n   bool operator<(const otro& algo) const { return algo.tiemp < tiemp; } n }; n vector<node> v; n int n, m, ini, fin; n int valoreleg; n char eleg; n char ch[500000]; n map<long long, int> mp; n void f() { n   long long tiemp = 1; n   int c = 0; n   int pos = ini; n   while (true) { n     if (v[mp[tiemp]].iz <= pos && v[mp[tiemp]].der >= pos) { n       ch[c++] =  X ; n       tiemp++; n       continue; n     } n     pos += valoreleg; n     ch[c] = eleg; n     if (v[mp[tiemp]].iz <= pos && v[mp[tiemp]].der >= pos) { n       pos -= valoreleg; n       ch[c] =  X ; n     } n     c++; n     tiemp++; n     if (pos == fin) { n       for (int a = 0; a < c; a++) cout << ch[a]; n       cout << endl; n       return; n     } n   } n } n int main() { n   cin >> n >> m >> ini >> fin; n   int li, ri; n   long long tim; n   v.push_back(node(0, 0, 0)); n   for (int a = 0; a < m; a++) { n     cin >> tim >> li >> ri; n     mp[tim] = a + 1; n     v.push_back(node(tim, li, ri)); n   } n   if (ini < fin) { n     valoreleg = 1; n     eleg =  R ; n   } else { n     valoreleg = -1; n     eleg =  L ; n   } n   f(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int q; n   cin >> q; n   while (q--) { n     int a, b, n, s; n     cin >> a >> b >> n >> s; n     if (s - n * min(a, s / n) <= b) n       cout <<  YES n ; n     else n       cout <<  NO n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, cnt, ans; n int a[410][410], c[160010]; n int now, f[2][410][410]; n void Init() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) scanf( %d , &a[i][j]); n } n inline void insert(int x) { n   if (c[x]) ++cnt; n   ++c[x]; n } n inline void erase(int x) { n   --c[x]; n   if (c[x]) --cnt; n } n void Work() { n   int p; n   for (int i = 1; i <= n; ++i) { n     p = 1; n     for (int j = 1; j <= m; ++j) { n       insert(a[i][j]); n       while (cnt) { n         f[0][i][p] = j - 1; n         erase(a[i][p]); n         ++p; n       } n     } n     while (p <= m) { n       f[0][i][p] = m; n       erase(a[i][p]); n       ++p; n     } n     for (int j = 1; j <= m; ++j) ans = max(ans, f[0][i][j] - j + 1); n   } n } n void Solve() { n   int p; n   for (int s = 2; s <= n; ++s) { n     now ^= 1; n     for (int i = 1; i <= n - s + 1; ++i) { n       int j = i + s - 1; n       for (int k = 1; k <= m; ++k) n         f[now][i][k] = min(f[now ^ 1][i][k], f[now ^ 1][i + 1][k]); n       p = 1; n       for (int k = 1; k <= m; ++k) { n         insert(a[i][k]); n         insert(a[j][k]); n         while (cnt) { n           f[now][i][p] = min(f[now][i][p], k - 1); n           erase(a[i][p]); n           erase(a[j][p]); n           ++p; n         } n       } n       while (p <= m) { n         f[now][i][p] = min(f[now][i][p], m); n         erase(a[i][p]); n         erase(a[j][p]); n         ++p; n       } n       for (int k = 1; k <= m; ++k) ans = max(ans, s * (f[now][i][k] - k + 1)); n     } n   } n   printf( %d n , ans); n } n int main() { n   Init(); n   Work(); n   Solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 61; n int a[N], n; n long long dp[N][2][2], k; n long long Dfs(int pos, int x, int y) { n   if (pos < n - pos + 1) return 1; n   if (dp[pos][x][y] != -1) return dp[pos][x][y]; n   long long ans = 0; n   for (int i = 0; i < 2; i++) n     if (a[pos] == -1 || a[pos] == i) n       for (int j = 0; j < 2; j++) n         if (a[n - pos + 1] == -1 || a[n - pos + 1] == j) { n           if (x && (i > j) || y && (i > !j) || pos == n - pos + 1 && (i != j)) n             continue; n           ans += Dfs(pos - 1, x && (i == j), y && (i != j)); n         } n   return dp[pos][x][y] = ans; n } n int main() { n   scanf( %d%lld , &n, &k); n   k++; n   memset(dp, -1, sizeof(dp)); n   memset(a, -1, sizeof(a)); n   a[n] = 0; n   if (Dfs(n, 1, 1) < k) n     puts( -1 ); n   else { n     for (int i = n - 1; i > 0; i--) { n       a[i] = 0; n       memset(dp, -1, sizeof(dp)); n       long long num = Dfs(n, 1, 1); n       if (k > num) k -= num, a[i] = 1; n     } n     for (int i = n; i >= 1; i--) printf( %d , a[i]); n     puts(  ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i, j; n   string s1, s2; n   cin >> n >> s1 >> s2; n   if (s2 ==  week ) { n     if (n == 5 || n == 6) { n       cout <<  53  << endl; n     } else { n       cout <<  52  << endl; n     } n   } else { n     if (n <= 29) { n       cout <<  12  << endl; n     } else if (n == 30) { n       cout <<  11  << endl; n     } else if (n == 31) { n       cout <<  7  << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200002; n long long sum, ans, nd, T; n priority_queue<long long> q; n int n, k, b, c, t[N], i, j; n int main() { n   scanf( %d%d%d%d , &n, &k, &b, &c), ans = 1e18; n   b = min(b, c * 5); n   for (i = 1; i <= n; i++) scanf( %d , &t[i]); n   sort(t + 1, t + n + 1); n   for (i = 0; i < 5; i++) { n     T = 2e9 + i; n     while (!q.empty()) q.pop(); n     sum = 0; n     for (j = 1; j <= n; j++) { n       nd = (T - t[j]) / 5 * b + (T - t[j]) % 5 * c; n       sum += nd; n       q.push(nd); n       if (q.size() > k) sum -= q.top(), q.pop(); n       if (q.size() == k) ans = min(ans, sum - (T - t[j]) / 5 * b * k); n     } n   } n   printf( %lld , ans); n } n


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


#include <bits/stdc++.h> n using namespace std; n typedef int64_t g; n g n,p[269420],v=1e9+7,T,r,i,k,s; n map<g,g> l; n int main(){ n cin>>T; n while(T--){ n cin>>n; n l.clear(); n for(i=0,s=0,p[0]=1,l[0]=1;++i<=n;){ n cin>>k; n p[i]=(p[i-1]*2+v-p[l[s]-1])%v; n l[s]=i; n s+=k; n }cout<<p[n]<<endl; n } n }


#include <bits/stdc++.h> n using namespace std; n int n, m, p, dp[2][110][110][110], ans; n const int mod = 1e9 + 7; n int main() { n   scanf( %d%d%d , &n, &m, &p); n   for (int i = 1; i <= n; i++) dp[0][i][i][1] = 1; n   for (int i = 0; i < m - 1; i++) { n     memset(dp[!(i & 1)], 0, sizeof(dp[!(i & 1)])); n     for (int j = 1; j <= n; j++) n       for (int k = 1; k <= j; k++) n         for (int s = 1; s <= p; s++) n           if (dp[i & 1][j][k][s]) { n             int ns = s; n             for (int k2 = k; k2 <= n - j; k2++) { n               if (k2 > k) ns *= (k2 - 1), ns /= (k2 - k); n               if (ns > p) break; n               (dp[!(i & 1)][j + k2][k2 - k][ns] += dp[i & 1][j][k][s]) %= mod; n             } n           } n     for (int j = 1; j <= n; j++) n       for (int s = 1; s <= p; s++) n         (ans += 1ll * (m - i - 1) * dp[!(i & 1)][j][0][s] % mod) %= mod; n   } n   return printf( %d , ans), 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f, MOD = 1e9 + 7; n const int n_ = 1e5 + 1000; n const long double PI = acos(-1.0); n long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); } n long long power(long long a, long long n) { n   long long p = 1; n   while (n > 0) { n     if (n % 2) { n       p = p * a; n     } n     n >>= 1; n     a *= a; n   } n   return p; n } n long long power(long long a, long long n, long long mod) { n   long long p = 1; n   while (n > 0) { n     if (n % 2) { n       p = p * a; n       p %= mod; n     } n     n >>= 1; n     a *= a; n     a %= mod; n   } n   return p % mod; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n, h; n   cin >> n >> h; n   int res = 0; n   for (int(i) = 0; (i) < (n); (i)++) { n     int a; n     cin >> a; n     if (a > h) n       res += 2; n     else n       res++; n   } n   cout << res << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   double d, h, v, e; n   cin >> d >> h >> v >> e; n   d /= 2; n   double vol = d * d * acos(-1) * h; n   double incre = e * d * d * acos(-1); n   if (incre >= v) { n     cout <<  NO ; n     return 0; n   } n   double ans = vol / (v - incre); n   if (ans > 1e4) { n     cout <<  NO ; n     return 0; n   } n   cout <<  YES n ; n   cout << setprecision(15) << ans; n } n


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


#include <bits/stdc++.h> n using namespace std; n int co; n bool query(int x, int y) { n   assert(++co <= 60); n   printf( 1 %d %d n , x, y); n   fflush(stdout); n   char st[5]; n   scanf( %s , st); n   return st[0] ==  N ; n } n int main() { n   int fst, scnd, n, k; n   scanf( %d %d , &n, &k); n   int l = 1, r = n; n   while (l < r) { n     int m = (l + r) / 2; n     if (query(m, m + 1)) n       l = m + 1; n     else n       r = m; n   } n   fst = l; n   l = 1, r = fst - 1; n   while (l < r) { n     int m = (l + r) / 2; n     if (query(m, m + 1)) n       l = m + 1; n     else n       r = m; n   } n   if (l == r && !query(l, l + 1)) { n     printf( 2 %d %d n , fst, l); n     fflush(stdout); n     return 0; n   } n   l = fst + 1, r = n; n   while (l < r) { n     int m = (l + r) / 2; n     if (query(m, m + 1)) n       l = m + 1; n     else n       r = m; n   } n   printf( 2 %d %d n , fst, l); n   fflush(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int dim = 52; n char a[dim][dim]; n int s[dim][dim]; n int dp[dim][dim][dim][dim]; n void compute(int i1, int j1, int i2, int j2) { n   if (dp[i1][j1][i2][j2] != 0x3f3f3f3f) return; n   int ans = max(i2 - i1 + 1, j2 - j1 + 1); n   if (s[i2][j2] - s[i1 - 1][j2] - s[i2][j1 - 1] + s[i1 - 1][j1 - 1] == 0) { n     dp[i1][j1][i2][j2] = 0; n     return; n   } n   if (s[i2][j2] - s[i1 - 1][j2] - s[i2][j1 - 1] + s[i1 - 1][j1 - 1] == n       (i2 - i1 + 1) * (j2 - j1 + 1)) { n     dp[i1][j1][i2][j2] = ans; n     return; n   } n   for (int i = i1; i < i2; ++i) { n     compute(i1, j1, i, j2); n     compute(i + 1, j1, i2, j2); n     ans = min(ans, dp[i1][j1][i][j2] + dp[i + 1][j1][i2][j2]); n   } n   for (int j = j1; j < j2; ++j) { n     compute(i1, j1, i2, j); n     compute(i1, j + 1, i2, j2); n     ans = min(ans, dp[i1][j1][i2][j] + dp[i1][j + 1][i2][j2]); n   } n   dp[i1][j1][i2][j2] = ans; n } n void solve() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i] + 1; n     for (int j = 1; j <= n; ++j) n       s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + (a[i][j] ==  # ); n   } n   memset(dp, 0x3f, sizeof dp); n   compute(1, 1, n, n); n   cout << dp[1][1][n][n]; n } n int main() { n   cin.tie(0); n   ios_base::sync_with_stdio(false); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   vector<int> arrNums; n   int iTemp, nNeed, nNum, i; n   long long iSum = 0; n   cin >> nNum >> nNeed; n   while (nNum--) { n     cin >> iTemp; n     arrNums.push_back(iTemp); n   } n   sort(arrNums.begin(), arrNums.end()); n   for (i = 0; i < nNeed; ++i) { n     iSum += arrNums[i]; n   } n   cout << iSum; n endapp: n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 7; n const int INF = 1e9 + 7; n int xx[8] = {1, 1, 1, 0, -1, -1, -1, 0}, yy[8] = {1, 0, -1, -1, -1, 0, 1, 1}; n int n, m, hd = 0, ti = 0; n vector<int> a[N], p[N], dis[N]; n char s[N]; n int Qux[N * 5], Quy[N * 5]; n void bfs() { n   while (hd != ti) { n     int tx = Qux[++hd], ty = Quy[hd]; n     for (int j = 0; j <= 8 - 1; j++) { n       if (tx + xx[j] < 0 || tx + xx[j] > n + 1) continue; n       if (ty + yy[j] < 0 || ty + yy[j] > m + 1) continue; n       if (dis[tx + xx[j]][ty + yy[j]] > dis[tx][ty] + 1) { n         dis[tx + xx[j]][ty + yy[j]] = dis[tx][ty] + 1; n         Qux[++ti] = tx + xx[j]; n         Quy[ti] = ty + yy[j]; n       } n     } n   } n } n bool check(int x) { n   for (int i = 0; i <= n + 1 - 1; i++) n     for (int j = 0; j <= m + 1 - 1; j++) p[i][j] = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       if (dis[i][j] >= x) { n         if (i - x + 1 <= 0) return 0; n         if (i + x - 1 > n) return 0; n         if (j - x + 1 <= 0) return 0; n         if (j + x - 1 > m) return 0; n         p[i - x + 1][j - x + 1]++; n         p[i - x + 1][j + x]--; n         p[i + x][j - x + 1]--; n         p[i + x][j + x]++; n       } n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       p[i][j] = p[i][j] + p[i - 1][j] + p[i][j - 1] - p[i - 1][j - 1]; n       if (!p[i][j] && a[i][j]) return 0; n     } n   } n   return 1; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; i++) { n     Qux[++ti] = 0; n     Quy[ti] = i; n     Qux[++ti] = n + 1; n     Quy[ti] = i; n   } n   for (int i = 0; i <= n + 2 - 1; i++) n     for (int j = 0; j <= m + 2 - 1; j++) dis[i].push_back(0); n   for (int i = 0; i <= n + 2 - 1; i++) n     for (int j = 0; j <= m + 2 - 1; j++) p[i].push_back(0); n   for (int i = 1; i <= n; i++) { n     scanf( %s , s + 1); n     a[i].push_back(0); n     Qux[++ti] = i; n     Quy[ti] = 0; n     Qux[++ti] = i; n     Quy[ti] = m + 1; n     for (int j = 1; j <= m; j++) { n       if (s[j] ==  X ) { n         a[i].push_back(1); n         dis[i][j] = INF; n       } else { n         a[i].push_back(0); n         Qux[++ti] = i; n         Quy[ti] = j; n       } n     } n   } n   bfs(); n   int l = 1, r = (min(n, m) + 1) / 2; n   while (l < r - 1) { n     int mid = (l + r) >> 1; n     if (check(mid)) n       l = mid; n     else n       r = mid; n   } n   int ans; n   if (check(r)) n     ans = r; n   else n     ans = l; n   check(ans); n   printf( %d n , ans - 1); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) n       if (dis[i][j] >= ans) n         putchar( X ); n       else n         putchar( . ); n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, Bef[201000]; n long long w[201000]; n map<pair<int, int>, int> Map[201000]; n struct Tree { n   int K[262144 + 262144], T[262144 + 262144]; n   void init() { n     for (int i = 0; i < 262144 + 262144; i++) K[i] = -1; n   } n   void Put2(int nd, int x) { K[nd] = T[nd] = x; } n   void UDT(int nd) { T[nd] = (T[nd * 2] | T[nd * 2 + 1]); } n   void Spread(int nd) { n     if (K[nd] != -1) { n       Put2(nd * 2, K[nd]); n       Put2(nd * 2 + 1, K[nd]); n     } n     K[nd] = -1; n   } n   void Put(int nd, int b, int e, int s, int l, int x) { n     if (s > l) return; n     if (s <= b && e <= l) { n       Put2(nd, x); n       return; n     } n     Spread(nd); n     int m = (b + e) >> 1; n     if (s <= m) Put(nd * 2, b, m, s, l, x); n     if (l > m) Put(nd * 2 + 1, m + 1, e, s, l, x); n     UDT(nd); n   } n   int Left(int nd, int b, int e, int s, int l) { n     if (!T[nd]) return l + 1; n     if (s > l) return l + 1; n     if (b == e) return b; n     Spread(nd); n     int m = (b + e) >> 1; n     if (s <= m) { n       int x = Left(nd * 2, b, m, s, l); n       if (x <= l) return x; n     } n     if (l > m) { n       return Left(nd * 2 + 1, m + 1, e, s, l); n     } n     return l + 1; n   } n } IT; n struct Range { n   int b, e; n }; n vector<Range> Save; n long long Sum1(int b, int e) { n   return 1ll * ((n - b + 1) + (n - e + 1)) * (e - b + 1) / 2; n } n void Calc(int b, long long x, int e, long long y) { n   int i; n   for (i = 0; i <= e - b - 1; i++) { n     long long t2 = Sum1(b + 1, b + i) + x; n     long long t1 = Sum1(e - i, e - 1) + x; n     long long tp = n - e + 1; n     if (t1 + tp <= y && y <= t2 + tp) { n       Map[e][{e, e}] = b; n       Save.push_back({e, e}); n     } n     long long bbb = n + 1 + t1 - y + 1; n     long long eee = n + 1 + t2 - y + 1; n     bbb = max(bbb, (long long)e + 1); n     eee = min(eee, (long long)n + 1); n     if (bbb <= eee) { n       int b1 = bbb, e1 = eee; n       Map[e][{b1, e1}] = b; n       Save.push_back({b1, e1}); n     } n   } n } n void Do(int b, int e) { n   Save.clear(); n   if (IT.Left(1, 0, n + 1, b, b) == b) { n     Calc(b, w[b], e, w[e]); n   } n   int pp = IT.Left(1, 0, n + 1, b + 1, e - 1); n   if (b + 1 <= pp && pp <= e - 1) { n     Calc(pp, w[b] - 1, e, w[e]); n   } n   if (IT.Left(1, 0, n + 1, e, e) == e && w[e] != w[b] - 1) { n     IT.Put(1, 0, n + 1, e, e, 0); n   } n   if (w[b] != w[e]) { n     IT.Put(1, 0, n + 1, e + 1, n + 1, 0); n   } n   IT.Put(1, 0, n + 1, 0, e - 1, 0); n   for (auto &t : Save) { n     IT.Put(1, 0, n + 1, t.b, t.e, 1); n   } n } n int Res[201000]; n void Print2(long long b, long long e, int c, long long s) { n   if (c == 0) return; n   long long t2 = Sum1(b + 1, b + c - 1); n   long long t1 = Sum1(e - c + 2, e); n   if (t1 <= s - (n - b + 1) && s - (n - b + 1) <= t2) { n     Res[b] = 1; n     Print2(b + 1, e, c - 1, s - (n - b + 1)); n   } else { n     Print2(b + 1, e, c, s); n   } n } n void Print(int ty, long long s1, int x, int y, long long s2) { n   Res[ty] = Res[y] = 1; n   long long ss = s2 - (n - y + 1) - s1; n   int i; n   for (i = 0; i <= x - ty - 1; i++) { n     long long t2 = Sum1(ty + 1, ty + i); n     long long t1 = Sum1(x - i, x - 1); n     if (t1 <= ss && ss <= t2) { n       Print2(ty + 1, x - 1, i, ss); n       return; n     } n   } n } n int RR[101000]; n long long Res2[101000]; n int main() { n   int i, DEB = 0; n   scanf( %d , &n); n   mt19937 rng((unsigned)time(NULL)); n   if (DEB) { n     long long ss = 0; n     for (i = 1; i <= n + 1; i++) { n       RR[i] = !!(rng() % 5); n       if (i == n + 1) RR[i] = 1; n       if (RR[i]) { n         ss += (n - i + 1); n         Res2[i] = ss; n       } n     } n     for (i = 1; i <= n; i++) printf( %d , RR[i]); n     puts(  ); n     long long z = Res2[n + 1]; n     for (i = n; i >= 1; i--) { n       if (Res2[i]) n         z = Res2[i]; n       else n         Res2[i] = z + 1; n     } n   } n   int ck = 0; n   for (i = 1; i <= n; i++) { n     if (!DEB) { n       scanf( %lld , &w[i]); n     } n     if (DEB) { n       if (rng() % 3 == 0) { n         w[i] = Res2[i]; n       } n       printf( %lld  , w[i]); n     } n     if (w[i] != 0 && w[i] != 1) ck = 1; n   } n   if (!ck) { n     for (i = 1; i <= n; i++) printf( 0 ); n     puts(  ); n     return 0; n   } n   IT.Put(1, 0, n + 1, 0, 0, 1); n   int prv = 0; n   for (i = 1; i <= n; i++) { n     if (!w[i]) continue; n     Do(prv, i); n     Bef[i] = prv; n     prv = i; n   } n   int x = prv, y = IT.Left(1, 0, n + 1, 0, n + 1); n   while (x) { n     for (auto &t : Map[x]) { n       pair<int, int> tp = t.first; n       if (tp.first <= y && y <= tp.second) { n         int ty = t.second; n         long long s1 = w[Bef[x]], s2 = w[x]; n         if (ty != Bef[x]) { n           s1--; n         } n         if (y != x) { n           s2--; n         } n         Print(ty, s1, x, y, s2); n         y = ty; n         break; n       } n     } n     x = Bef[x]; n   } n   for (i = 1; i <= n; i++) printf( %d , Res[i]); n   puts(  ); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 10010, M = 15010, inf = 1e9; n struct st1 { n   int to, next, c; n } e[M << 1]; n struct st2 { n   int to, next, f, op; n } F[1000001]; n int n, m, x, y, z, cnt, cnt2, ans, i, col, cyc, S, T, fi[N], c[N], l[N], n     op[M << 1], d[N + M], f2[N + M], dep[N + M], num[N + M]; n bool vis[N], u[M << 1]; n void addl(int x, int y, int z) { n   e[++cnt].to = y, e[cnt].next = fi[x], e[cnt].c = z, fi[x] = cnt; n } n void addf(int x, int y, int f) { n   F[++cnt2].to = y, F[cnt2].next = f2[x], F[cnt2].f = f, F[cnt2].op = cnt2 + 1, n   f2[x] = cnt2; n   F[++cnt2].to = x, F[cnt2].next = f2[y], F[cnt2].f = 0, F[cnt2].op = cnt2 - 1, n   f2[y] = cnt2; n } n void dfs(int x, int fa, int d) { n   vis[x] = 1; n   for (int i = fi[x]; i; i = e[i].next) n     if (!u[i] && e[i].to != fa) { n       int y = e[i].to; n       if (vis[y]) { n         cyc++, u[i] = u[op[i]] = 1; n         addf(S, cyc, dep[x] - dep[y]); n         for (int j = dep[y] + 1; j <= dep[x]; j++) n           u[l[j]] = u[op[l[j]]] = 1, addf(cyc, c[j] + 1, 1); n         addf(cyc, e[i].c + 1, 1); n       } else { n         c[dep[y] = d + 1] = e[i].c, l[d + 1] = i, dfs(y, x, d + 1); n         if (!u[i]) addf(S, ++cyc, 1), addf(cyc, e[i].c + 1, 1); n       } n     } n } n int sap(int x, int del) { n   if (x == T) return del; n   int sum = 0, md = cyc + 1; n   for (int i = f2[x]; i; i = F[i].next) n     if (F[i].f) { n       if (d[F[i].to] == d[x] - 1) { n         int save = sap(F[i].to, min(F[i].f, del - sum)); n         sum += save, F[i].f -= save, F[F[i].op].f += save; n         if (d[S] >= cyc + 1 || sum == del) return sum; n       } n       md = min(md, d[F[i].to]); n     } n   if (!sum) { n     if (!(--num[d[x]])) n       d[S] = cyc + 1; n     else n       num[d[x] = md + 1]++; n   } n   return sum; n } n int main() { n   scanf( %d%d n , &n, &m); n   for (i = 1; i <= m; i++) { n     scanf( %d%d%d n , &x, &y, &z); n     addl(x, y, z), addl(y, x, z); n     col = max(col, z); n   } n   for (i = 1; i <= cnt; i += 2) op[op[i] = i + 1] = i; n   S = 0, T = 1, cyc = 1 + col; n   for (i = 1; i <= col; i++) addf(i + 1, T, 1); n   dfs(1, 0, 0); n   num[0] = cyc + 1; n   for (; d[S] <= cyc;) ans += sap(S, inf); n   printf( %d , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int N, M, M2, B; n const int MAXN = 100015; n const int MAXM = 20; n const int MAXM2 = (1 << 20); n char S[MAXN]; n int bitc[MAXM2]; n int bitl[MAXM2]; n int dp[MAXM2]; n int cnt[MAXM][MAXM]; n int mcnt[MAXM2][MAXM]; n int last; n int main() { n   cin >> N >> M >> S; n   M2 = (1 << M); n   B = M2 - 1; n   for (int i = 0; i < M; ++i) n     for (int j = 0; j < M; ++j) cnt[i][j] = 0; n   bitc[0] = 0; n   bitl[0] = 0; n   dp[0] = 0; n   for (int j = 0; j < M; ++j) mcnt[0][j] = 0; n   for (int i = 1; i < M2; ++i) { n     int b = i & (i - 1); n     bitc[i] = bitc[b] + 1; n     for (int j = 0; j < M; ++j) n       if ((1 << j) & i) { n         bitl[i] = j; n         break; n       } n     for (int j = 0; j < M; ++j) mcnt[i][j] = 0; n     dp[i] = 1e9; n   } n   for (int i = 0; i < N - 1; ++i) { n     if (S[i] == S[i + 1]) continue; n     ++cnt[S[i] -  a ][S[i + 1] -  a ]; n     ++cnt[S[i + 1] -  a ][S[i] -  a ]; n   } n   for (int i = 1; i < M2; ++i) n     for (int j = 0; j < M; ++j) n       mcnt[i][j] = mcnt[i & (i - 1)][j] + cnt[bitl[i]][j]; n   for (int i = 0; i < M2; ++i) n     for (int j = 0; j < M; ++j) { n       if (((1 << j) & i) == 0) n         dp[i | (1 << j)] = min(dp[i | (1 << j)], n                                dp[i] + bitc[i] * (mcnt[i][j] - mcnt[B ^ i][j])); n     } n   cout << dp[B] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n int a[10005]; n int num[10005]; n int main() { n   int n; n   scanf( %d , &n); n   int mm = 0; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     num[a[i]]++; n     mm = max(mm, a[i]); n   } n   int nn = 0; n   for (int i = 1; i <= mm; i++) { n     if (mm % i == 0) num[i]--; n   } n   for (int i = 10000; i >= 1; i--) { n     if (num[i] > 0) { n       nn = i; n       break; n     } n   } n   printf( %d %d n , mm, nn); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace fastIO { n bool IOerror = 0; n inline char nc() { n   static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000; n   if (p1 == pend) { n     p1 = buf; n     pend = buf + fread(buf, 1, 100000, stdin); n     if (pend == p1) { n       IOerror = 1; n       return -1; n     } n   } n   return *p1++; n } n inline bool blank(char ch) { n   return ch ==     || ch ==   n  || ch ==   r  || ch ==   t ; n } n inline void read(long long &x) { n   char ch; n   long long f = 1; n   while (blank(ch = nc())) n     ; n   while (ch ==  - ) f = -f, ch = nc(); n   if (IOerror) return; n   for (x = ch -  0 ; (ch = nc()) >=  0  && ch <=  9 ; x = x * 10 + ch -  0 ) n     ; n   x *= f; n } n inline void read(int &x) { n   char ch; n   int f = 1; n   while (blank(ch = nc())) n     ; n   while (ch ==  - ) f = -f, ch = nc(); n   if (IOerror) return; n   for (x = ch -  0 ; (ch = nc()) >=  0  && ch <=  9 ; x = x * 10 + ch -  0 ) n     ; n   x *= f; n } n inline void read(char *s) { n   char ch; n   while (blank(ch = nc())) n     ; n   if (IOerror) return; n   int i = 0; n   for (; !blank(ch); s[i++] = ch, ch = nc()) n     ; n   s[i] =   0 ; n } n };  // namespace fastIO n using namespace fastIO; n inline long long read() { n   long long x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n int n; n int p[300010]; n int c[500010]; n int ans[300010]; n class Treap { n  public: n   struct treap_point { n     int l, r, x, rep, son, rnd; n   } t[500010]; n   int treesz, root; n   inline void update(int k) { n     t[k].son = t[t[k].l].son + t[t[k].r].son + t[k].rep; n   } n   inline void right_rotate(int &k) { n     int tt = t[k].l; n     t[k].l = t[tt].r; n     t[tt].r = k; n     update(k); n     update(tt); n     k = tt; n   } n   inline void left_rotate(int &k) { n     int tt = t[k].r; n     t[k].r = t[tt].l; n     t[tt].l = k; n     update(k); n     update(tt); n     k = tt; n   } n   inline void insert_to_tree(int &k, int x) { n     if (!k) { n       k = ++treesz; n       t[k].x = x; n       t[k].rnd = rand(); n       t[k].son = t[k].rep = 1; n       t[k].l = t[k].r = 0; n       return; n     } n     t[k].son++; n     if (x == t[k].x) { n       t[k].rep++; n       return; n     } n     if (x < t[k].x) { n       insert_to_tree(t[k].l, x); n       if (t[t[k].l].rnd < t[k].rnd) right_rotate(k); n     } n     if (x > t[k].x) { n       insert_to_tree(t[k].r, x); n       if (t[t[k].r].rnd < t[k].rnd) left_rotate(k); n     } n   } n   inline bool delete_from_tree(int &k, int x) { n     if (!k) return 0; n     if (x == t[k].x) { n       if (t[k].rep > 1) { n         t[k].rep--; n         t[k].son--; n         return 1; n       } n       if (!t[k].l || !t[k].r) { n         k = t[k].l + t[k].r; n         return 1; n       } n       if (t[t[k].l].rnd < t[t[k].r].rnd) { n         right_rotate(k); n         return delete_from_tree(k, x); n       } n       left_rotate(k); n       return delete_from_tree(k, x); n     } n     int res; n     if (x < t[k].x) { n       res = delete_from_tree(t[k].l, x); n       if (res) t[k].son--; n       return res; n     } n     res = delete_from_tree(t[k].r, x); n     if (res) t[k].son--; n     return res; n   } n   inline int get_succ_in_tree(int k, int x) { n     if (!k) return -1; n     int sv; n     if (x < t[k].x) { n       sv = get_succ_in_tree(t[k].l, x); n       return sv == -1 ? t[k].x : sv; n     } n     return get_succ_in_tree(t[k].r, x); n   } n   inline int get_pred_in_tree(int k, int x) { n     if (!k) return -1; n     int sv; n     if (x > t[k].x) { n       sv = get_pred_in_tree(t[k].r, x); n       return sv == -1 ? t[k].x : sv; n     } n     return get_pred_in_tree(t[k].l, x); n   } n   inline int ask_kth_in_tree(int k, int x) { n     if (!k) return -1; n     if (x <= t[t[k].l].son) return ask_kth_in_tree(t[k].l, x); n     if (x > t[t[k].l].son + t[k].rep) n       return ask_kth_in_tree(t[k].r, x - t[t[k].l].son - t[k].rep); n     return t[k].x; n   } n   inline int ask_rank_in_tree(int k, int x) { n     if (!k) return -1; n     if (x == t[k].x) return t[t[k].l].son + 1; n     if (x < t[k].x) return ask_rank_in_tree(t[k].l, x); n     return t[t[k].l].son + t[k].rep + ask_rank_in_tree(t[k].r, x); n   } n   inline void init() { treesz = root = 0; } n   inline void insert(int x) { insert_to_tree(root, x); } n   inline int del(int x) { return delete_from_tree(root, x); } n   inline int succ(int x) { return get_succ_in_tree(root, x); } n   inline int pred(int x) { return get_pred_in_tree(root, x); } n   inline int ask_kth(int x) { return ask_kth_in_tree(root, x); } n   inline int ask_rank(int x) { return ask_rank_in_tree(root, x); } n } T; n int main() { n   srand(time(0)); n   n = read(); n   for (int i = 1; i <= n; i++) T.insert(i); n   ans[1] = 1; n   for (int i = 1; i <= n; i++) { n     p[i] = read(); n     T.del(p[i]); n     ans[i + 1] = max(0, (T.ask_kth(n - i) - n + i)) + 1; n   } n   for (int i = 1; i <= n + 1; i++) printf( %d  , ans[i]); n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int m, k; n   scanf( %d %d , &m, &k); n   vector<int> a(k, 0); n   vector<int> t(m - 1), r(m - 1, 0); n   vector<int> last(k, 0); n   for (int i = 0; i < k; ++i) { n     scanf( %d , &a[i]); n   } n   int free_num = 0; n   for (int i = 0; i + 1 < m; ++i) { n     scanf( %d %d , &t[i], &r[i]); n     if (t[i] > 0) { n       last[t[i] - 1] = i; n     } n   } n   int first_upset_id = -1; n   int before_upset_num = 0; n   for (int i = 0; i + 1 < m; ++i) { n     if (r[i] == 1) { n       first_upset_id = i; n       break; n     } else if (t[i] == 0) { n       ++before_upset_num; n     } n   } n   for (int i = 0; i + 1 < m; ++i) { n     if (t[i] == 0) { n       ++free_num; n     } else { n       --a[t[i] - 1]; n     } n   } n   if (first_upset_id >= 0) { n     int min_id = -1; n     for (int i = 0; i < k; ++i) { n       if ((last[i] < first_upset_id) && n           ((min_id == -1) || (a[min_id] > a[i]))) { n         min_id = i; n       } n     } n     free_num -= a[min_id]; n   } n   for (int i = 0; i < k; ++i) { n     if ((a[i] <= free_num) || n         ((last[i] < first_upset_id) && (a[i] <= before_upset_num))) { n       printf( Y ); n     } else { n       printf( N ); n     } n   } n   printf(  n ); n } n int main() { n   int t; n   scanf( %d , &t); n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct om_nom { n   int t; n   int h; n   int m; n } a[2005]; n int n, x; n bool eaten[2005]; n bool have_candy(int type) { n   int flag = false; n   for (int i = 0; i < n; ++i) n     if (a[i].t == (bool)type && !eaten[i]) { n       flag = true; n       break; n     } n   return flag; n } n int solve(int cur, int H) { n   int cnt = 0; n   for (int i = 0; i < n; ++i) { n     eaten[i] = false; n   } n   while (have_candy(cur)) { n     int mm = -1, it = -1; n     for (int i = 0; i < n; ++i) n       if (a[i].t == cur && a[i].m > mm && a[i].h <= H && !eaten[i]) { n         it = i; n         mm = a[i].m; n       } n     if (it != -1) { n       H += a[it].m; n       cur ^= 1; n       eaten[it] = true; n     } else n       break; n     cnt++; n   } n   return cnt; n } n int main() { n   cin >> n >> x; n   for (int i = 0; i < n; ++i) { n     cin >> a[i].t >> a[i].h >> a[i].m; n   } n   cout << max(solve(0, x), solve(1, x)) << endl; n   return 0; n } n


#include <bits/stdc++.h> n inline int read() { n   int f = 1, x = 0; n   char ch = getchar(); n   while (!(ch >=  0  && ch <=  9 )) { n     if (ch ==  - ) f *= -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return f * x; n } n int dx[8] = {1, 1, -1, -1, 2, 2, -2, -2}; n int dy[8] = {2, -2, 2, -2, 1, -1, 1, -1}; n struct Point { n   int x, y, c, fa; n   friend bool operator==(Point a, Point b) { n     return (a.x == b.x && a.y == b.y); n   } n } w[2], b[2], list[4][1000 * 1000 + 1]; n int otherx, othery; n void printlist(int k, Point a) { n   if (a.fa == -1) return; n   if (a.fa != 1) printlist(k, list[k][a.fa]); n   printf( %d %d n , a.x, a.y); n } n int n, m, head, tail, v[4][1000 + 1][1000 + 1]; n void closer(int k, Point st, Point ed) { n   Point a, b; n   head = tail = 1; n   memset(v[k], 0, sizeof(v[k])); n   v[k][st.x][st.y] = head; n   list[k][head] = st, list[k][head].c = 0, list[k][head].fa = -1; n   if (st == ed) return; n   while (head <= tail) { n     a = list[k][head]; n     for (int i = 0; i < 8; i++) { n       b = a, b.x += dx[i], b.y += dy[i], b.c++; n       if (b.x < 1 || b.y < 1 || b.x > n || b.y > m || v[k][b.x][b.y] != 0) n         continue; n       tail++; n       v[k][b.x][b.y] = tail; n       b.fa = head; n       list[k][tail] = b; n       if (b == ed) return; n     } n     head++; n   } n } n void printlast(int k) { n   if (k == 0) { n     printf( %d %d n , b[0].x - 1, b[0].y + 2); n     printf( %d %d n , b[0].x - 3, b[0].y + 1); n     printf( %d %d n , b[0].x - 1, b[0].y); n   } else { n     printf( %d %d n , w[0].x + 1, w[0].y + 2); n     printf( %d %d n , w[0].x + 3, w[0].y + 1); n     printf( %d %d n , w[0].x + 1, w[0].y); n   } n } n bool choose; n int main() { n   n = read(), m = read(), w[1].x = read(), w[1].y = read(), b[1].x = read(), n   b[1].y = read(); n   w[0].x = n / 2, w[0].y = m / 2, b[0].x = n / 2 + 1, b[0].y = m / 2; n   closer(0, w[1], w[0]), closer(1, b[1], b[0]); n   closer(2, w[1], b[0]); n   closer(3, b[1], w[0]); n   if ((w[1].x + w[1].y) % 2 != (b[1].x + b[1].y) % 2) { n     if (list[0][v[0][w[0].x][w[0].y]].c <= list[1][v[1][b[0].x][b[0].y]].c) n       printf( WHITE n ), printlist(0, list[0][v[0][w[0].x][w[0].y]]); n     else if (list[2][v[2][b[0].x][b[0].y]].c >= n              list[1][v[1][b[0].x][b[0].y]].c + 2) n       printf( BLACK n ), printlist(1, list[1][v[1][b[0].x][b[0].y]]); n     else n       printf( WHITE n ), printlist(2, list[2][v[2][b[0].x][b[0].y]]), n           printlast(0); n   } else { n     if (list[1][v[1][b[0].x][b[0].y]].c < list[0][v[0][w[0].x][w[0].y]].c) n       printf( BLACK n ), printlist(1, list[1][v[1][b[0].x][b[0].y]]); n     else if (list[3][v[3][w[0].x][w[0].y]].c > list[0][v[0][w[0].x][w[0].y]].c) n       printf( WHITE n ), printlist(0, list[0][v[0][w[0].x][w[0].y]]); n     else n       printf( BLACK n ), printlist(3, list[3][v[3][w[0].x][w[0].y]]), n           printlast(1); n   } n   fflush(stdout); n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /stack:200000000 ) n #pragma GCC optimize( Ofast ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4 ) n using namespace std; n const int inf = (int)2e9 + 99999, mod = (int)1e9 + 7; n const long long linf = (long long)2e18 + 99999; n int kob(int x, int y) { return ((long long)x * y) % mod; } n int aza(int x, int y) { n   x -= y; n   if (x < 0) return x + mod; n   return x; n } n int kos(int x, int y) { n   x += y; n   if (x >= mod) return x - mod; n   return x; n } n const int maxn = (int)1e5 + 777, maxn2 = (int)1e6 + 55; n int main() { n   int a1, a2, a3, a4; n   cin >> a1 >> a2 >> a3 >> a4; n   int a11 = a1, a22 = a2, a33 = a3, a44 = a4; n   a1 -= a3; n   a2 -= a3; n   bool bad = false; n   if (a3 <= a4) bad = 1, --a1; n   if (a3 < a4) --a2; n   if (abs(a3 - a4) >= 2 || a1 < 0 || a2 < 0) { n     if (a33 == a44 && a11 < a22) { n       a11 -= a33; n       a22 -= a33; n       a22--; n       if (a11 < 0 || a22 < 0) { n         cout << -1; n         exit(0); n       } n       for (int i = 1; i <= a33; ++i) cout <<  74 ; n       for (int i = 1; i <= a11; ++i) cout << 4; n       cout << 7; n       for (int i = 1; i <= a22; ++i) cout << 7; n       exit(0); n     } n     cout <<  -1 , exit(0); n   } n   if (a3 < a4) cout <<  7 ; n   for (int i = 1; i <= a1; ++i) cout <<  4 ; n   for (int i = 1; i <= a3; ++i) cout <<  47 ; n   for (int i = 1; i <= a2; ++i) cout <<  7 ; n   if (bad) cout <<  4 ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 10; n const int SQRTN = 320; n const int LOGN = 20; n const double PI = acos(-1); n int n, val; n map<int, int> dp; n int dp2[N]; n int range[N]; n bool en[N]; n int grundy(long long n) { n   if (n < 1e6) return dp2[n]; n   if (dp.find(n) != dp.end()) return dp[n]; n   int& mex = dp[n]; n   int st = 0; n   double e = sqrt(n); n   double s = sqrt(e); n   int i = ceil(s), _ = floor(e); n   while (i < n && i <= _) { n     i = range[i]; n     st = st | (1 << grundy(i)); n     i++; n   } n   while (st & (1 << mex)) mex++; n   return mex; n } n int calc(int n) { n   int& mex = dp2[n]; n   int st = 0; n   double e = sqrt(n); n   double s = sqrt(e); n   for (int i = ceil(s), _ = floor(e); i < n && i <= _; i++) { n     st = st | (1 << dp2[i]); n   } n   while (st & (1 << mex)) mex++; n   return mex; n } n int main() { n   for (int i = 0; i < 1000000; i++) { n     calc(i); n   } n   range[999999] = 999999; n   en[999999] = 1; n   for (int i = 999998; i > -1; i--) { n     if (dp2[i] != dp2[i + 1]) n       range[i] = i, en[i] = 1; n     else n       range[i] = range[i + 1]; n   } n   cin >> n; n   long long a; n   for (int i = 0; i < n; i++) { n     scanf( %lld , &a); n     val = val ^ grundy(a); n   } n   cout << (val ?  Furlo  :  Rublo ) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long cross2(long long x1, long long y1, long long x2, long long y2) { n   return x1 * y2 - x2 * y1; n } n long long cross(long long i, long long j, long long k, const long long* xx, n                 const long long* yy) { n   return cross2(xx[j] - xx[i], yy[j] - yy[i], xx[k] - xx[i], yy[k] - yy[i]); n } n int main() { n   int n; n   cin >> n; n   auto* xx = new long long[n]; n   auto* yy = new long long[n]; n   for (int i = 0; i < n; i++) { n     cin >> xx[i]; n     cin >> yy[i]; n   } n   bool flip = xx[0] < xx[1]; n   long long x = xx[1], y = yy[1]; n   for (int i = 0; i < n; i++) { n     xx[i] -= x; n     yy[i] -= y; n     if (flip) { n       xx[i] = -xx[i]; n       yy[i] = -yy[i]; n     } n   } n   long long left = 0, right = xx[0]; n   for (int i = 2; i + 1 < n; i++) { n     long long cright = cross(i, i + 1, 0, xx, yy); n     long long cleft = cross(i, i + 1, 1, xx, yy); n     if (cright > 0 && cleft > 0) { n       cout << 0; n       return 0; n     } n     long long x0 = xx[i], y0 = yy[i], x1 = xx[i + 1], y1 = yy[i + 1]; n     if (cright > 0 || cleft > 0) { n       long long p = x0 * (y1 - y0) - y0 * (x1 - x0); n       long long q = y1 - y0; n       if (q < 0) { n         p = -p; n         q = -q; n       } n       if (cright > 0) n         right = min(right, (p / q)); n       else n         left = max(left, ((p + q - 1) / q)); n     } n   } n   cout << (left <= right ? right - left + 1 : 0) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000010; n bitset<N> b; n int p[N]; n int cnt[N]; n bool was[N]; n int main() { n   int n, k; n   scanf( %d %d , &n, &k); n   for (int i = 0; i < n; i++) { n     scanf( %d , p + i); n     p[i]--; n     was[i] = false; n   } n   for (int i = 1; i <= n; i++) { n     cnt[i] = 0; n   } n   int c1 = 0, c2 = 0; n   for (int i = 0; i < n; i++) { n     if (was[i]) { n       continue; n     } n     int x = i; n     int len = 0; n     while (!was[x]) { n       was[x] = true; n       x = p[x]; n       len++; n     } n     c1 += len % 2; n     c2 += len / 2; n     cnt[len]++; n   } n   b.set(0); n   for (int i = 1; i <= n; i++) { n     if (cnt[i] == 0) { n       continue; n     } n     int j = 1; n     while (cnt[i] > 0) { n       j = min(j, cnt[i]); n       int u = i * j; n       b |= (b << u); n       cnt[i] -= j; n       j *= 2; n     } n   } n   int ans_min = k; n   if (!b.test(k)) { n     ans_min++; n   } n   int ans_max = 0; n   ans_max += 2 * min(k, c2); n   k -= min(k, c2); n   ans_max += min(k, c1); n   printf( %d %d n , ans_min, ans_max); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[100001], first, space, op = 1, last; n int main() { n   long long k, n, page; n   cin >> k >> n >> page; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   if (n == 0) { n     cout << 0; n     return 0; n   } n   first = (a[1] - space) / page; n   if ((a[1] - space) % page) first++; n   for (int i = 1; i <= n; i++) { n     long long pg_now = (a[i] - space) / page; n     if ((a[i] - space) % page) pg_now++; n     if (pg_now == first) n       last++; n     else { n       space = last; n       first = (a[i] - space) / page; n       if ((a[i] - space) % page) first++; n       last++; n       op++; n     } n   } n   cout << op; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int md = 1000000007; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int tt{}, T{}; n   tt = 1; n   while (tt--) { n     int n{}, m{}, ans{}, k{}, a{}, b{}, c{}, f{}; n     cin >> n; n     if (n == 1) { n       cout <<  1 n ; n       return 0; n     } n     if (n == 2) { n       cout <<  2 1 n ; n       return 0; n     } n     a = sqrt(n); n     b = n - a * a; n     for (int j = 0; j < b; ++j) { n       for (int i = n + 1 - j * (a + 1) - a - 1; i < n + 1 - j * (a + 1); ++i) { n         if (i > 0) cout << i <<    ; n       } n     } n     if (b > 0) n = n - (b) * (a + 1); n     for (int i = 0; i < a - b; ++i) { n       for (int j = n + 1 - i * a - a; j < n + 1 - i * a; ++j) { n         if (j > 0) cout << j <<    ; n       } n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n int n; n char a[1000005], b[1000005], dic[130]; n int main() { n   dic[ W ] =  E ; n   dic[ E ] =  W ; n   dic[ N ] =  S ; n   dic[ S ] =  N ; n   scanf( %d%s%s , &n, a, b); n   unsigned int ha = 0, hb = 0, rol = 1, mul = 233; n   for (int i = n - 2; i >= 0; i--) { n     if ((ha = a[i] * rol + ha) == (hb = dic[b[i]] + hb * mul)) { n       puts( NO ); n       return 0; n     } n     rol *= mul; n   } n   puts( YES ); n } n


#include <bits/stdc++.h> n using namespace std; n using T = int; n struct Edge { n   int from, to; n   T cost, flow, cap; n   Edge(int _from = 0, int _to = 0, T _cost = 0, T _cap = 0) n       : from(_from), to(_to), cost(_cost), flow(0), cap(_cap) {} n }; n const int N = 7010; n const int INF = 0x3f3f3f3f; n int n; n vector<Edge> edges; n vector<int> g[N]; n int par[N]; n int dist[N]; n int pi[N]; n void addEdge(int from, int to, T cost, T cap) { n   g[from].push_back(edges.size()); n   edges.emplace_back(from, to, cost, cap); n   g[to].push_back(edges.size()); n   edges.emplace_back(to, from, -cost, 0); n } n bool dijkstra(int s, int t) { n   for (int i = 0; i <= t; ++i) { n     dist[i] = INF; n     par[i] = -1; n   } n   priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> pq; n   dist[s] = 0; n   pq.push({0, s}); n   while (!pq.empty()) { n     auto on = pq.top(); n     pq.pop(); n     int chosen = on.second; n     int d = on.first; n     if (d > dist[chosen]) continue; n     for (int edge_id : g[chosen]) { n       int to = edges[edge_id].to; n       int cost = edges[edge_id].cost; n       T flowing = edges[edge_id].flow; n       T cap = edges[edge_id].cap; n       if (cap <= flowing) continue; n       if (dist[to] > dist[chosen] + pi[chosen] - pi[to] + cost) { n         dist[to] = dist[chosen] + pi[chosen] - pi[to] + cost; n         par[to] = edge_id; n         pq.push({dist[to], to}); n       } n     } n   } n   return dist[t] != INF; n } n int mcmf(int s, int t) { n   memset(pi, 0, sizeof pi); n   int cost = 0, max_flow = 0; n   while (dijkstra(s, t)) { n     for (int i = 0; i <= t; ++i) { n       pi[i] += dist[i]; n     } n     int cur = t, flow = (1 << 30); n     for (int cur = t; par[cur] != -1; cur = edges[par[cur]].from) { n       flow = min(flow, edges[par[cur]].cap - edges[par[cur]].flow); n     } n     for (int cur = t; par[cur] != -1; cur = edges[par[cur]].from) { n       cost += edges[par[cur]].cost * flow; n       edges[par[cur]].flow += flow; n       edges[par[cur] ^ 1].flow -= flow; n     } n     max_flow += flow; n   } n   return cost; n } n int main() { n   scanf( %d , &n); n   vector<int> a(n); n   addEdge(0, 1, 0, 4); n   for (int i = 0; i < n; ++i) { n     scanf( %d , &a[i]); n   } n   for (int i = 0; i < n; ++i) { n     addEdge(1, i + 2, 0, 1); n     addEdge(i + 2, n + i + 2, -1, 1); n     addEdge(n + i + 2, 2 * n + 2, 0, 1); n     for (int j = i + 1; j < n; ++j) { n       if (abs(a[i] - a[j]) == 1 or a[i] % 7 == a[j] % 7) { n         addEdge(n + i + 2, j + 2, 0, 1); n       } n     } n   } n   printf( %d n , -1 * mcmf(0, 2 * n + 2)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = 200100; n const long long INF = 2000000100; n const long long MOD = 998244353; n long long N, S[MAXN], P[MAXN]; n long long B[MAXN]; n void update(int ind, long long v) { n   for (int i = ind; i <= N; i += (i & -i)) { n     B[i] += v; n   } n } n long long query(int ind) { n   if (ind == 0) return 0; n   long long s = 0; n   for (int i = ind; i > 0; i -= (i & -i)) { n     s += B[i]; n   } n   return s; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin >> N; n   for (int i = 0; i < N; i++) cin >> S[i]; n   for (int i = 1; i <= N; i++) update(i, i); n   for (int i = N - 1; i >= 0; i--) { n     long long a = 1, b = N, c; n     long long ans = -39; n     while (a <= b) { n       c = (a + b) / 2; n       if (query(c - 1) > S[i]) { n         b = c - 1; n       } else { n         ans = c; n         a = c + 1; n       } n     } n     P[i] = ans; n     update(ans, -ans); n   } n   for (int i = 0; i < N; i++) cout << P[i] << (i == N - 1 ?   n  :    ); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long a, b; n   cin >> b >> a; n   a--; n   b -= a; n   if (b >= 0 && b % 2 == 0 && a > 0) { n     cout <<  Yes  << endl; n   } else if (b == 0 && a == 0) n     cout <<  Yes  << endl; n   else n     cout <<  No  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = 3.141592653589793238463; n int a[100009], p[200009]; n int main() { n   cin.tie(0); n   cin.sync_with_stdio(0); n   int h; n   cin >> h; n   for (int i = (0); i <= (h); i++) cin >> a[i]; n   bool perfect = true; n   for (int i = 0; i < (h); i++) n     if (a[i] > 1 && a[i + 1] > 1) perfect = false; n   if (perfect) { n     cout <<  perfect  <<   n ; n     return 0; n   } n   cout <<  ambiguous  <<   n ; n   int idx = 1; n   p[0] = 0; n   for (int i = (0); i <= (h); i++) { n     p[i + 1] = idx; n     for (int j = (0); j < (a[i]); j++) cout << p[i] <<    ; n     idx += a[i]; n   } n   cout <<   n ; n   idx = 1; n   p[0] = 0; n   for (int i = (0); i <= (h); i++) { n     p[i + 1] = idx; n     if (i > 0 && a[i] > 1 && a[i - 1] > 1) { n       cout << p[i] <<    ; n       for (int j = (0); j < (a[i] - 1); j++) cout << p[i] + 1 <<    ; n     } else n       for (int j = (0); j < (a[i]); j++) cout << p[i] <<    ; n     idx += a[i]; n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 2; n const int M = 1e9 + 7; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   vector<int> v(n); n   for (int i = 0; i < n; i++) cin >> v[i]; n   vector<int> pre(n, 1); n   for (int i = 1; i < n; i++) { n     if (v[i] <= v[i - 1] * 2) pre[i] = pre[i - 1] + 1; n   } n   cout << *max_element(pre.begin(), pre.end()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   float a, b, c, d; n   float mpts; n   float vpts; n   cin >> a >> b >> c >> d; n   mpts = max((3 * a) / 10, a - ((a / 250) * c)); n   vpts = max((3 * b) / 10, b - ((b / 250) * d)); n   if (mpts == vpts) { n     cout <<  Tie n ; n     return 0; n   } n   mpts > vpts ? cout <<  Misha n  : cout <<  Vasya n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e3 + 10; n const int oo = 1e9; n vector<int> g[N], gt[N]; n vector<pair<int, int> > b[N], bt[N]; n int cost[N][N]; n void bfs(int u, int n, vector<int> adj[], vector<pair<int, int> > &b, bool q) { n   queue<int> Q; n   vector<int> d(n + 1, oo); n   d[u] = 0; n   Q.push(u); n   while (!Q.empty()) { n     int cur = Q.front(); n     Q.pop(); n     for (auto v : adj[cur]) { n       int dist = d[cur] + 1; n       if (dist >= d[v]) continue; n       d[v] = dist; n       Q.push(v); n       if (q) cost[u][v] = dist; n     } n   } n   for (int i = 1; i <= n; i++) b.push_back({d[i], i}); n   sort(b.begin(), b.end()); n   while (!b.empty() && b.back().first >= oo) b.pop_back(); n   reverse(b.begin(), b.end()); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n, m; n   cin >> n >> m; n   for (int i = 0; i <= n; i++) { n     for (int j = 0; j <= n; j++) cost[i][j] = oo; n     cost[i][i] = 0; n   } n   for (int i = 0; i < m; i++) { n     int u, v; n     cin >> u >> v; n     g[u].push_back(v); n     gt[v].push_back(u); n   } n   for (int i = 1; i <= n; i++) { n     bfs(i, n, g, b[i], 1); n     bfs(i, n, gt, bt[i], 0); n   } n   vector<int> ans; n   int best = -1; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       if (i == j) continue; n       for (int k = 0; k < min(3, (int)bt[i].size()); k++) { n         for (int l = 0; l < min(3, (int)b[j].size()); l++) { n           int u = bt[i][k].second, du = bt[i][k].first; n           int v = b[j][l].second, dv = b[j][l].first; n           int cur_ans = du + cost[i][j] + dv; n           if (cur_ans >= oo || cur_ans <= best) continue; n           set<int> S = {u, i, j, v}; n           if (S.size() < 4) continue; n           best = cur_ans; n           ans = {u, i, j, v}; n         } n       } n     } n   } n   for (auto x : ans) cout << x <<    ; n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool isprime(long long n) { n   if (n < 2) return false; n   if (n == 2) return true; n   if (n % 2 == 0) return false; n   for (int i = 3; i * i <= n; i = i + 2) { n     if (n % i == 0) return false; n   } n   return true; n } n int main() { n   int n; n   cin >> n; n   int a[n]; n   for (int i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   int temp = -1, cnt = 0; n   for (int i = 0; i < n; i++) { n     if (temp != a[i] && a[i] != 0) { n       cnt++; n       temp = a[i]; n     } n   } n   cout << cnt; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c, d, e, f; n   cin >> a >> b >> c >> d >> e >> f; n   cout << (b * d * f > a * c * e || c == 0 && d > 0 || a == 0 && b > 0 && d > 0 n                ?  Ron  n                :  Hermione ) n        <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int m, n, z, n1, m1; n   int a[10000], b[10000]; n   int g, j, k, p = 0; n   int count = 0; n   cin >> n >> m >> z; n   n1 = n; n   m1 = m; n   if (z <= 10000 && z > 0 && n >= 1 && m >= 1) { n     while (n <= z || m <= z) { n       a[j] = n; n       n = n + n1; n       j++; n       b[g] = m; n       m = m + m1; n       g++; n     } n     for (k = 0; k < j; k++) { n       for (p = 0; p < g; p++) { n         if (a[k] == b[p]) { n           count++; n         } n       } n     } n     cout << count; n     return 0; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   int n; n   cin >> n; n   int a[n]; n   int ans = 0, sum = 0; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     ans += a[i]; n   } n   sum = ans; n   sort(a, a + n); n   for (int j = n - 1; j >= 1; j--) { n     for (int x = 2; x < a[j]; x++) { n       if (a[j] % x != 0) continue; n       ans = min(ans, sum - a[j] - a[0] + a[j] / x + a[0] * x); n     } n   } n   cout << ans << endl; n   cerr <<  Time :   << (double)clock() / (double)CLOCKS_PER_SEC <<  s  n        <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n int len; n int big; n int Dgt[30]; n int N; n int ans; n void tochar(int); n int main() { n   while (scanf( %d , &N) != EOF) { n     memset(Dgt, 0, sizeof(Dgt)); n     ans = 0; n     while (N) { n       big = -1; n       tochar(N); n       for (int i = 0; i < len; i++) { n         if (Dgt[i] > big) big = Dgt[i]; n       } n       N -= big; n       ans++; n     } n     printf( %d n , ans); n   } n } n void tochar(int n) { n   len = 0; n   while (n) { n     Dgt[len] = n % 10; n     n /= 10; n     len++; n   } n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n; n   cin >> n; n   long long a[3], b[3]; n   cin >> a[0] >> a[1] >> a[2]; n   cin >> b[0] >> b[1] >> b[2]; n   cout << max(0ll, a[0] - b[0] - b[2]) + max(0ll, a[1] - b[1] - b[0]) + n               max(0ll, a[2] - b[2] - b[1]) n        <<    ; n   cout << min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0]) << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   int t; n   t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool equal(string s) { n   int n = 0; n   for (int i = 0; i < s.length(); i++) { n     if (s[i] ==  a ) n++; n   } n   if (n * 2 != s.length()) return false; n   return true; n } n string s, s1, sex; n int n, d, k; n int main() { n   cin >> k; n   cin >> s; n   n = s.length(); n   sex = s; n   for (int i = 2; i <= n; i = i + 2) { n     for (int j = 0; j <= n - i; j++) { n       s1 = s.substr(j, i); n       if (equal(s1)) { n         while (s.find(s1) != -1) { n           s.erase(s.find(s1), 1); n           d++; n         } n       } n     } n   } n   cout <<  25 ; n } n


#include <bits/stdc++.h> n using namespace std; n int a[105][2]; n int main() { n   int n, sum = 0, b = 0; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i][0]); n     sum += a[i][0]; n   } n   n /= 2; n   sum = sum / n; n   for (int j = 1; j <= n; j++) { n     for (int i = 1; i <= 2 * n; i++) { n       if (a[i][1] == 0) { n         if (b == 0) { n           printf( %d  , i); n           b = a[i][0]; n           a[i][1] = 1; n         } else { n           if (b + a[i][0] == sum) { n             printf( %d n , i); n             b = 0; n             a[i][1] = 1; n             break; n           } n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long SG[1110000] = {0, 1, 2, 1, 4, 3, 2, 1, 5,  6, 2, 1, 8,  7,  5,  9, n                          8, 7, 3, 4, 7, 4, 2, 1, 10, 9, 3, 6, 11, 12, 14, 13}; n long long n, Ans, vis[1110000]; n set<long long> Hehe; n int main() { n   scanf( %I64d , &n); n   long long Orz = (long long)(floor)(sqrt(1.0 * n)); n   for (long long i = 2; i * i <= n; ++i) { n     long long c = 0; n     if (vis[i]) continue; n     for (long long j = i; j <= n; j *= i, c++) { n       if (j > Orz) n         Hehe.insert(j); n       else n         vis[j] = 1; n     } n     Ans ^= SG[c]; n   } n   long long tmp = n - Orz - Hehe.size(); n   if (!(tmp & 1)) Ans ^= 1; n   if (Ans) n     printf( Vasya ); n   else n     printf( Petya ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, cnt; n bool vis[1000005]; n vector<int> G[1000005]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     G[u].push_back(v); n   } n   for (int u = 1; u <= n; u++) { n     if (vis[u]) continue; n     for (int i = 0; i < G[u].size(); i++) { n       int v = G[u][i]; n       if (v > u) vis[v] = true; n     } n   } n   for (int u = n; u > 0; u--) { n     if (vis[u]) continue; n     for (int i = 0; i < G[u].size(); i++) vis[G[u][i]] = true; n   } n   for (int i = 1; i <= n; i++) n     if (!vis[i]) cnt++; n   printf( %d n , cnt); n   for (int i = 1; i <= n; i++) n     if (!vis[i]) printf( %d  , i); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2013; n char p[1 << 20], s[205]; n int k, n, m; n int main() { n   gets(p); n   gets(s); n   cin >> k; n   n = strlen(p); n   m = strlen(s); n   string minLex; n   for (int i = 1; i <= k + 1; ++i) minLex +=  1 ; n   int rboud = min(m, k), cntIn = n / k, R = n % k; n   for (int d = 1; d <= rboud && cntIn * d <= m; ++d) { n     string cans; n     for (int i = 1; i <= k; ++i) cans +=  0 ; n     { n       int r = d - 1, i = min(n - 1, k - 1); n       for (; i >= 0 && r >= 0; --i) { n         int l1 = m / d + (r < m % d); n         int l2 = cntIn + (i < R); n         if (l1 != l2) continue; n         bool diff = false; n         for (int e = 0; e < l1 && !diff; ++e) n           diff = s[r + e * d] != p[i + e * k]; n         if (diff) continue; n         cans[i] =  1 ; n         --r; n       } n       if (r == -1) minLex = min(minLex, cans); n     } n   } n   if (minLex.size() > k) n     cout << 0; n   else n     cout << minLex; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int x, y, z; n } a[10]; n int flag; n long long v[5]; n long long dist(int i, int j) { n   long long x = a[i].x - a[j].x; n   long long y = a[i].y - a[j].y; n   long long z = a[i].z - a[j].z; n   return x * x + y * y + z * z; n } n int ok() { n   int cnt = 0; n   for (int i = 1; i < 8; i++) n     for (int j = 0; j < i; j++) { n       long long w = dist(i, j); n       if (!cnt) n         v[++cnt] = w; n       else { n         int k = 1; n         while (k <= cnt && v[k] != w) k++; n         if (k > cnt && cnt == 3) return 0; n         if (k > cnt) v[++cnt] = w; n       } n     } n   if (cnt == 3) return 1; n   return 0; n } n void dfs(int p) { n   if (flag) return; n   if (p == 8) { n     if (ok()) flag = 1; n     return; n   } n   node tmp = a[p]; n   dfs(p + 1); n   if (!flag) { n     a[p].y = tmp.z; n     a[p].z = tmp.y; n     dfs(p + 1); n   } n   if (!flag) { n     a[p].x = tmp.y; n     a[p].y = tmp.x; n     a[p].z = tmp.z; n     dfs(p + 1); n   } n   if (!flag) { n     a[p].x = tmp.y; n     a[p].y = tmp.z; n     a[p].z = tmp.x; n     dfs(p + 1); n   } n   if (!flag) { n     a[p].x = tmp.z; n     a[p].y = tmp.x; n     a[p].z = tmp.y; n     dfs(p + 1); n   } n   if (!flag) { n     a[p].x = tmp.z; n     a[p].y = tmp.y; n     a[p].z = tmp.x; n     dfs(p + 1); n   } n } n int main() { n   for (int i = 0; i < 8; i++) cin >> a[i].x >> a[i].y >> a[i].z; n   dfs(0); n   if (!flag) n     puts( NO ); n   else { n     puts( YES ); n     for (int i = 0; i < 8; i++) printf( %d %d %d n , a[i].x, a[i].y, a[i].z); n   } n } n