#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n using str = string; n using pi = pair<int, int>; n using pl = pair<ll, ll>; n using vi = vector<int>; n using vl = vector<ll>; n using vpi = vector<pair<int, int>>; n using vvi = vector<vi>; n int Bit(int mask, int b) { return (mask >> b) & 1; } n template <class T> n bool ckmin(T &a, const T &b) { n   if (b < a) { n     a = b; n     return true; n   } n   return false; n } n template <class T> n bool ckmax(T &a, const T &b) { n   if (b > a) { n     a = b; n     return true; n   } n   return false; n } n const int INFi = 2e9; n const ll INF = 2e18; n const int maxN = 605; n const int LG = 20; n struct blossom { n   int n, m; n   vector<int> mate; n   vector<vector<int>> b; n   vector<int> p, d, bl; n   vector<vector<int>> g; n   blossom(int n) : n(n) { n     m = n + n / 2; n     mate.assign(n, -1); n     b.resize(m); n     p.resize(m); n     d.resize(m); n     bl.resize(m); n     g.assign(m, vector<int>(m, -1)); n   } n   void add_edge(int u, int v) { n     g[u][v] = u; n     g[v][u] = v; n   } n   void match(int u, int v) { n     g[u][v] = g[v][u] = -1; n     mate[u] = v; n     mate[v] = u; n   } n   vector<int> trace(int x) { n     vector<int> vx; n     while (true) { n       while (bl[x] != x) x = bl[x]; n       if (!vx.empty() && vx.back() == x) break; n       vx.push_back(x); n       x = p[x]; n     } n     return vx; n   } n   void contract(int c, int x, int y, vector<int> &vx, vector<int> &vy) { n     b[c].clear(); n     int r = vx.back(); n     while (!vx.empty() && !vy.empty() && vx.back() == vy.back()) { n       r = vx.back(); n       vx.pop_back(); n       vy.pop_back(); n     } n     b[c].push_back(r); n     b[c].insert(b[c].end(), vx.rbegin(), vx.rend()); n     b[c].insert(b[c].end(), vy.begin(), vy.end()); n     for (int i = 0; i <= c; i++) { n       g[c][i] = g[i][c] = -1; n     } n     for (int z : b[c]) { n       bl[z] = c; n       for (int i = 0; i < c; i++) { n         if (g[z][i] != -1) { n           g[c][i] = z; n           g[i][c] = g[i][z]; n         } n       } n     } n   } n   vector<int> lift(vector<int> &vx) { n     vector<int> A; n     while (vx.size() >= 2) { n       int z = vx.back(); n       vx.pop_back(); n       if (z < n) { n         A.push_back(z); n         continue; n       } n       int w = vx.back(); n       int i = (A.size() % 2 == 0 n                    ? find(b[z].begin(), b[z].end(), g[z][w]) - b[z].begin() n                    : 0); n       int j = n           (A.size() % 2 == 1 n                ? find(b[z].begin(), b[z].end(), g[z][A.back()]) - b[z].begin() n                : 0); n       int k = b[z].size(); n       int dif = (A.size() % 2 == 0 ? i % 2 == 1 : j % 2 == 0) ? 1 : k - 1; n       while (i != j) { n         vx.push_back(b[z][i]); n         i = (i + dif) % k; n       } n       vx.push_back(b[z][i]); n     } n     return A; n   } n   int solve() { n     for (int ans = 0;; ans++) { n       fill(d.begin(), d.end(), 0); n       queue<int> Q; n       for (int i = 0; i < m; i++) bl[i] = i; n       for (int i = 0; i < n; i++) { n         if (mate[i] == -1) { n           Q.push(i); n           p[i] = i; n           d[i] = 1; n         } n       } n       int c = n; n       bool aug = false; n       while (!Q.empty() && !aug) { n         int x = Q.front(); n         Q.pop(); n         if (bl[x] != x) continue; n         for (int y = 0; y < c; y++) { n           if (bl[y] == y && g[x][y] != -1) { n             if (d[y] == 0) { n               p[y] = x; n               d[y] = 2; n               p[mate[y]] = y; n               d[mate[y]] = 1; n               Q.push(mate[y]); n             } else if (d[y] == 1) { n               vector<int> vx = trace(x); n               vector<int> vy = trace(y); n               if (vx.back() == vy.back()) { n                 contract(c, x, y, vx, vy); n                 Q.push(c); n                 p[c] = p[b[c][0]]; n                 d[c] = 1; n                 c++; n               } else { n                 aug = true; n                 vx.insert(vx.begin(), y); n                 vy.insert(vy.begin(), x); n                 vector<int> A = lift(vx); n                 vector<int> B = lift(vy); n                 A.insert(A.end(), B.rbegin(), B.rend()); n                 for (int i = 0; i < (int)A.size(); i += 2) { n                   match(A[i], A[i + 1]); n                   if (i + 2 < (int)A.size()) add_edge(A[i + 1], A[i + 2]); n                 } n               } n               break; n             } n           } n         } n       } n       if (!aug) return ans; n     } n   } n }; n vector<int> g1[maxN]; n bool used[maxN]; n bool was[maxN]; n int comp[maxN]; n bool ok = false; n int ee = 0; n int vv = 0; n void dfs(int v, int p) { n   ee += (int)g1[v].size(); n   vv++; n   was[v] = true; n   for (auto &u : g1[v]) { n     if (u == p) continue; n     if (was[u]) { n       ok = true; n       continue; n     } n     dfs(u, v); n   } n } n void dfs2(int v) { n   used[v] = true; n   for (auto &u : g1[v]) { n     if (used[u]) continue; n     dfs2(u); n   } n } n void dfs3(int v) { n   for (auto &u : g1[v]) { n     if (comp[u]) continue; n     comp[u] = comp[v]; n     dfs3(u); n   } n } n vector<pair<int, int>> gg[maxN]; n bool U[maxN]; n void my_assert(bool x) { n   if (!x) exit(0); n } n void find_answ(vector<int> a) { n   int n = a.size(); n   vector<array<int, 4>> kek1; n   for (int i = 0, j = 0; i < n; i = j) { n     if (a[i] != 0) { n       j++; n       continue; n     } n     while (j < n && a[j] == 0) j++; n     int len = j - i; n     if (len % 2 == 0) continue; n     my_assert(i > 0 && j < n); n     if (a[i - 1] == a[j]) { n       a[i] = a[i - 1]; n       continue; n     } n     gg[a[i - 1]].emplace_back(a[j], kek1.size()); n     gg[a[j]].emplace_back(a[i - 1], kek1.size()); n     kek1.push_back({a[i - 1], a[j], i, j - 1}); n   } n   for (int i = 1; i < n; ++i) { n     if (a[i] == a[i - 1] && a[i] != 0) { n       U[a[i]] = true; n     } n   } n   queue<int> q; n   vi h(kek1.size(), 0); n   auto make = [&](int i, int c) { n     h[i] = 1; n     auto [x, y, l, r] = kek1[i]; n     if (x == c) { n       a[l] = c; n     } else { n       my_assert(y == c); n       a[r] = c; n     } n   }; n   function<void(int)> dfss = [&](int v) { n     for (auto &[u, i] : gg[v]) { n       if (U[u] || h[i]) continue; n       U[u] = true; n       make(i, u); n       dfss(u); n     } n   }; n   for (int i = 1; i < maxN; ++i) { n     if (U[i]) { n       dfss(i); n       continue; n     } n   } n   function<void(int)> go = [&](int v) { n     for (auto &[u, i] : gg[v]) { n       if (U[u] || h[i]) continue; n       U[u] = true; n       make(i, u); n       go(u); n     } n   }; n   vi deg(maxN, 0); n   for (int i = 1; i < maxN; ++i) { n     if (U[i]) continue; n     deg[i] = gg[i].size(); n     if (gg[i].size() == 1) { n       q.push(i); n     } n   } n   while (!q.empty()) { n     int v = q.front(); n     q.pop(); n     vector<pair<int, int>> tt; n     for (auto &[u, i] : gg[v]) { n       if (U[u]) continue; n       tt.emplace_back(u, i); n     } n     my_assert(tt.size() <= 1); n     if (tt.empty()) continue; n     auto [u, i] = tt.back(); n     U[v] = true; n     make(i, v); n     deg[u]--; n     if (deg[u] == 1) { n       q.push(u); n     } n   } n   for (int i = 1; i < maxN; ++i) { n     if (deg[i] == 0 || U[i]) continue; n     go(i); n   } n   int k = 1; n   for (int i = 1; i < n; ++i) { n     if (a[i] == 0 && a[i - 1] == 0) { n       while (k < maxN && U[k]) k++; n       a[i] = a[i - 1] = k++; n       if (k < maxN) U[k] = true; n     } else if (a[i - 1] == 0) { n       a[i - 1] = 1; n     } n   } n   for (int i = 0; i < (n); ++i) cout << a[i] <<    ; n   cout <<   n ; n } n void solve() { n   int n; n   cin >> n; n   vi a(n); n   for (int i = 0; i < (n); ++i) cin >> a[i]; n   int L, R; n   int g = 0; n   { n     int k = 0; n     while (k < n && a[k] == 0) k++; n     if (k == n) { n       for (int i = 1; i < n; i += 2) { n         a[i] = a[i - 1] = (i / 2) + 1; n       } n       a[n - 1] = a[n - 2]; n       for (int i = 0; i < (n); ++i) cout << a[i] <<    ; n       return; n     } n     L = k; n     g += k / 2; n     if (k % 2) { n       used[a[k]] = true; n       a[k - 1] = a[k]; n     } n   } n   { n     int k = n - 1; n     while (k >= 0 && a[k] == 0) k--; n     R = k; n     g += (n - 1 - k) / 2; n     if ((n - 1 - k) % 2) { n       used[a[k]] = true; n       a[k + 1] = a[k]; n     } n   } n   for (int i = L + 1; i <= R; ++i) { n     if (a[i] == 0) continue; n     if (a[i] != a[i - 1]) continue; n     used[a[i]] = true; n   } n   vector<array<int, 4>> kek; n   for (int i = L, j = L; i <= R; i = j) { n     j = i + 1; n     if (a[i] != 0) continue; n     while (j <= R && a[j] == 0) j++; n     int len = j - i; n     int t1 = a[i - 1]; n     int t2 = a[j]; n     if (len % 2) { n       g += len / 2; n       g1[t1].push_back(t2); n       g1[t2].push_back(t1); n       continue; n     } n     g += (len) / 2 - 1; n     kek.push_back({t1, t2, i, j - 1}); n   } n   for (int i = 1; i < maxN; ++i) { n     if (was[i]) continue; n     ee = vv = 0; n     ok = false; n     dfs(i, -1); n     if ((vv - 1) * 2 != ee) { n       ok = true; n     } n     if (ok) { n       used[i] = true; n     } n   } n   for (int i = 1; i < maxN; ++i) { n     if (used[i]) { n       dfs2(i); n     } n   } n   int C = 0; n   int t = 0; n   for (int i = 1; i < maxN; ++i) { n     if (used[i]) continue; n     t++; n     if (comp[i]) continue; n     C++; n     t--; n     comp[i] = C; n     dfs3(i); n   } n   blossom B(C + 1); n   set<pair<int, int>> wasss; n   for (auto &[a, b, i, j] : kek) { n     if (used[a] || used[b] || comp[a] == comp[b]) { n       g++; n       continue; n     } n     pair<int, int> tmp = {comp[a], comp[b]}; n     if (tmp.first > tmp.second) swap(tmp.first, tmp.second); n     if (wasss.count(tmp)) continue; n     wasss.insert(tmp); n     B.add_edge(comp[a], comp[b]); n   } n   B.solve(); n   set<pair<int, int>> have; n   for (int i = 1; i <= C; ++i) { n     if (i < B.mate[i]) { n       have.insert({i, B.mate[i]}); n     } n   } n   auto ans = a; n   for (auto &[a, b, i, j] : kek) { n     if (used[a] || used[b] || comp[a] == comp[b]) { n       continue; n     } n     pair<int, int> cur = {comp[a], comp[b]}; n     if (cur.first > cur.second) swap(cur.first, cur.second); n     if (!have.count(cur)) { n       g++; n       continue; n     } n     have.erase(cur); n     ans[i] = ans[i - 1]; n     ans[j] = ans[j + 1]; n   } n   find_answ(ans); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int t = 1; n   for (int i = 0; i < (t); ++i) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:64000000 ) n using namespace std; n const int MAXN = -1; n const int MOD = 1; n const int INF = (int)(1e9); n int sign(long long x) { n   if (x > 0) return 1; n   if (x < 0) return -1; n   return 0; n } n vector<int> getB(vector<int> a, int n, int &s) { n   vector<int> b(a.size() + 40); n   for (int i = 0; i < (int)a.size(); i++) { n     int x = a[i]; n     int j = i; n     while (x) { n       b[j] += x % 2; n       x /= 2; n       j++; n     } n   } n   for (int j = 0; j < (int)b.size(); j++) { n     if (b[j]) { n       b[j + 1] += b[j] / 2; n       b[j] %= 2; n     } n   } n   int mx = -1; n   for (int j = 0; j < (int)b.size(); j++) n     if (b[j] != 0) mx = j; n   if (mx == -1) { n     s = 0; n     return vector<int>(a.size(), 0); n   } n   s = 1; n   if (b[mx] == -1) { n     s = -1; n     for (int i = 0; i < (int)b.size(); i++) b[i] *= -1; n   } n   for (int i = 0; i < (int)b.size(); i++) { n     b[i + 1] += b[i] / 2; n     b[i] %= 2; n     if (b[i] == -1) { n       b[i] = 1; n       b[i + 1] += -1; n     } n   } n   return b; n } n int fastsolve(vector<int> a, int n, int k) { n   for (int i = 0; i < 40; i++) a.push_back(0); n   long long cur = 0; n   int mn = INF, mx = -INF; n   int s; n   vector<int> b = getB(a, n, s); n   for (int i = 0; i < (int)b.size(); i++) { n     if (b[i] == 1) { n       mn = min(mn, i); n       mx = max(mx, i); n     } n   } n   if (mx - mn > 35) { n     return 0; n   } n   cur = 0; n   for (int i = mx; i >= mn; i--) { n     cur *= 2; n     if (i != mn) cur += b[i]; n   } n   cur *= s; n   int ans = 0; n   for (int i = mn; i >= 0; i--) { n     cur += b[i] * s; n     if (abs(cur) > 2LL * k) { n       break; n     } n     ans += i <= n && abs(cur - a[i]) <= k && (i != n || abs(cur - a[i]) != 0); n     cur *= 2; n   } n   return ans; n } n int slowsolve(vector<int> a, int n, int k) { n   for (int i = 0; i < 40; i++) a.push_back(0); n   int ans = 0; n   for (int i = 0; i <= n; i++) { n     vector<int> na = a; n     for (int j = -k; j <= k; j++) { n       na[i] = j; n       if (i == n && j == 0) continue; n       int s; n       getB(na, n, s); n       if (s == 0) { n         ans++; n         getB(na, n, s); n       } n     } n   } n   return ans; n } n int main() { n   int n, k; n   while (scanf( %d%d , &n, &k) == 2) { n     vector<int> a(n + 1); n     for (int i = 0; i <= n; i++) scanf( %d , &a[i]); n     printf( %d n , fastsolve(a, n, k)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   long long T = 0; n   int f = 0; n   char c = getchar(); n   for (; c <  0  || c >  9 ; c = getchar()) f |= c ==  - ; n   for (; c >=  0  && c <=  9 ; c = getchar()) T = T * 10 + c -  0 ; n   return f ? -T : T; n } n const double eps = 1e-7; n const int maxn = 1e5 + 233; n const double pi = acos(-1.0); n struct Vector { n   double x, y, r; n } A[maxn]; n int n, a; n double ans; n struct WZP_AK_SZB { n   double l, r; n   bool operator<(const WZP_AK_SZB &n) const { n     if (l == n.l) return r > n.r; n     return l < n.l; n   } n } B[maxn]; n int numB; n set<double> S; n set<double>::iterator it; n bool check(double x) { n   numB = 0; n   for (register int i = (1); i <= (n); ++i) { n     double dis = sqrt(((A[i].x - a) * (A[i].x - a)) + ((A[i].y) * (A[i].y))); n     if (dis > A[i].r + x || A[i].r > dis + x || x > dis + A[i].r) continue; n     double u = atan2(A[i].y, A[i].x - a); n     double t = acos((((dis) * (dis)) + ((x) * (x)) - ((A[i].r) * (A[i].r))) / n                     2.0 / dis / x); n     double l = u - t, r = u + t; n     if (l < -pi) l += 2 * pi; n     if (l > pi) l -= 2 * pi; n     if (r < -pi) r += 2 * pi; n     if (r > pi) r -= 2 * pi; n     if (l > r) swap(l, r); n     B[++numB].l = l; n     B[numB].r = r; n   } n   sort(B + 1, B + 1 + numB); n   S.clear(); n   for (register int i = (1); i <= (numB); ++i) { n     it = S.upper_bound(B[i].l); n     if (it != S.end() && *it < B[i].r) return true; n     S.insert(B[i].r); n   } n   return false; n } n int main() { n   n = read(), a = read(); n   for (register int i = (1); i <= (n); ++i) { n     A[i].x = read(), A[i].y = read(); n     A[i].r = sqrt(((A[i].x + a) * (A[i].x + a)) + ((A[i].y) * (A[i].y))); n   } n   double l = 0.0; n   double r = 2.0 * a; n   while (r - l > 1e-7) { n     double mid = (l + r) / 2; n     if (check(mid)) { n       r = mid; n     } else { n       l = mid; n     } n   } n   printf( %.10lf n , l); n } n


#include <bits/stdc++.h> n using namespace std; n struct child { n   long long v, p, d; n }; n child c[4123]; n bool gone[4123]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < (int)(n); i++) { n     scanf( %lld%lld%lld , &c[i].v, &c[i].d, &c[i].p); n   } n   int ans = 0; n   vector<int> all; n   for (int i = 0; i < (int)(n); i++) { n     if (gone[i]) continue; n     ans++; n     all.push_back(i + 1); n     for (int j = i + 1; j < n && c[i].v; j++) { n       if (gone[j]) continue; n       c[j].p -= c[i].v; n       c[i].v--; n     } n     long long dec = 0; n     for (int j = i + 1; j < n; j++) { n       if (gone[j]) continue; n       c[j].p -= dec; n       if (c[j].p < 0) { n         gone[j] = 1; n         dec += c[j].d; n       } n     } n   } n   printf( %d n , ans); n   for (int i = 0; i < (int)(all.size()); i++) { n     printf( %d%c , all[i], (i == all.size() - 1 ?   n  :    )); n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int n, mnPre[(100005)], mxPre[(100005)], mnSuf[(100005)], mxSuf[(100005)]; n pair<int, int> a[2][(100005)]; n long long solve(int ax) { n   sort(a[ax] + 1, a[ax] + 1 + n); n   for (int i = 1; i <= n; ++i) { n     mnPre[i] = min(mnPre[i - 1], a[ax][i].second); n     mxPre[i] = max(mxPre[i - 1], a[ax][i].second); n   } n   for (int i = n; i >= 1; --i) { n     mnSuf[i] = min(mnSuf[i + 1], a[ax][i].second); n     mxSuf[i] = max(mxSuf[i + 1], a[ax][i].second); n   } n   long long r = (1LL << 60) - 1; n   long long m = 0; n   int mn, mx; n   for (int i = 59; i >= 0; --i) { n     bool allowed = 0; n     m = r - (1LL << i); n     allowed = (1LL * (a[ax][n].first - a[ax][1].first) * n                (a[ax][n].first - a[ax][1].first)) <= m; n     for (int en = 1, st = 1; en <= n && !allowed; ++en) { n       while ((1LL * (a[ax][en].first - a[ax][st].first) * n               (a[ax][en].first - a[ax][st].first)) > m) n         ++st; n       mn = min(mnPre[st - 1], mnSuf[en + 1]); n       mx = max(mxPre[st - 1], mxSuf[en + 1]); n       allowed = (1LL * (mx - mn) * (mx - mn)) <= m && n                 max((1LL * (mn) * (mn)), (1LL * (mx) * (mx))) + n                         max((1LL * (a[ax][en].first) * (a[ax][en].first)), n                             (1LL * (a[ax][st].first) * (a[ax][st].first))) <= n                     m; n     } n     if (allowed) r -= (1LL << i); n   } n   return r; n } n int main() { n   scanf( %d , &n); n   for (int i = 1, x, y; i <= n; ++i) { n     scanf( %d%d , &x, &y); n     a[0][i] = {x, y}, a[1][i] = {y, x}; n   } n   printf( %I64d , min(solve(0), solve(1))); n } n


#include <bits/stdc++.h> n using namespace std; n long long int M = 1000000007; n long long int min(long long int a, long long int b, long long int c, n                   long long int d) { n   long long int arr[4] = {a, b, c, d}; n   sort(arr, arr + 4); n   return arr[0]; n } n long long int max(long long int a, long long int b, long long int c, n                   long long int d) { n   long long int arr[4] = {a, b, c, d}; n   sort(arr, arr + 4); n   return arr[3]; n } n long long int gcd(long long int a, long long int b) { n   if (b < a) { n     int temp = a; n     a = b; n     b = temp; n   } n   if (a == 0) { n     return b; n   } n   return gcd(b % a, a); n } n long long int lcm(long long int a, long long int b) { n   return (a * b / gcd(a, b)); n } n vector<long long int> getprimes() { n   vector<long long int> pl(101, 1); n   for (int i = 2; i <= 100; i++) { n     if (pl[i] == 1) { n       for (int j = 2 * i; j <= 100; j += i) { n         pl[j] = 0; n       } n     } n   } n   return pl; n } n double distsqrd(double x1, double y1, double x2, double y2) { n   return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1); n } n long long int fact(long long int first) { n   long long int ans = 1; n   if (first == 0) { n     return 1; n   } n   while (first > 0) { n     ans = (ans * first) % 1000000007; n     first--; n   } n   return ans % 1000000007; n } n long long int power(long long int a, long long int b) { n   long long int ans = 1; n   while (b > 0) { n     if (b % 2 == 1) { n       ans *= a; n       ans = ans; n     } n     b /= 2; n     a *= a; n     a = a; n   } n   return ans; n } n vector<int> getbinary(int first) { n   vector<int> bin(10, 0); n   int iter = 0; n   while (first > 0) { n     if (first % 2 == 1) { n       bin[iter] = 1; n     } else { n       bin[iter] = 0; n     } n     iter++; n     first /= 2; n   } n   return bin; n } n int getnum(vector<int> bin) { n   int t = 1; n   int n = bin.size(); n   int ret = 0; n   for (int i = 0; i < n; i++) { n     ret += t * bin[i]; n     t *= 2; n   } n   return ret; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   cin >> n; n   map<pair<int, int>, int> m1; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       int temp; n       cin >> temp; n       m1[make_pair(i, temp)] = j; n     } n   } n   int b[n + 1]; n   map<int, int> m2; n   for (int i = 1; i <= n; i++) { n     cin >> b[i]; n     m2[b[i]] = i; n   } n   int ans[n + 1][n + 1]; n   set<int> s; n   for (int i = 1; i <= n; i++) { n     s.insert(i); n     int no1 = -1, no2 = -1, min1 = n + 1, min2 = n + 1; n     for (auto e : s) { n       if (m2[e] < min1) { n         min2 = min1; n         min1 = m2[e]; n         no2 = no1; n         no1 = e; n       } else if (m2[e] < min2) { n         min2 = m2[e]; n         no2 = e; n       } n     } n     if (no2 == -1) { n       no2 = no1; n     } n     for (int j = 1; j <= n; j++) { n       if (j == no1 && j == no2) { n         ans[i][j] = -1; n       } else if (j != no1) { n         ans[i][j] = no1; n       } else if (j == no1 && j != no2) { n         ans[i][j] = no2; n       } n     } n   } n   for (int j = 1; j <= n; j++) { n     int min = 1e9, out; n     for (int i = 1; i <= n; i++) { n       if (ans[i][j] != -1) { n         if (m1[make_pair(j, ans[i][j])] < min) { n           min = m1[make_pair(j, ans[i][j])]; n           out = i; n         } n       } n     } n     cout << out <<    ; n   } n   cout << endl; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n int solver(string s) { n   if (s.length() == 1) { n     if (s ==  0 ) return 1; n     if (s ==  _ ) n       return 1; n     else n       return 0; n   } n   if (s[0] ==  0 ) { n     return 0; n   } n   if (s.back() ==  _ ) { n     int ans = 0; n     for (char c =  0 ; c <=  9 ; c++) { n       s[s.length() - 1] = c; n       ans += solver(s); n     } n     return ans; n   } n   int _ = 0; n   for (char c : s) { n     _ += (c ==  _ ); n   } n   if (s.back() >=  0  && s.back() <=  9  && s[s.length() - 2] >=  0  && n       s[s.length() - 2] <=  9 ) { n     if (s.back() !=  0  && s.back() !=  5 ) { n       return 0; n     } n     if (s.back() ==  0 ) { n       if (s[s.length() - 2] !=  5  && s[s.length() - 2] !=  0 ) { n         return 0; n       } n     } n     if (s.back() ==  5 ) { n       if (s[s.length() - 2] !=  2  && s[s.length() - 2] !=  7 ) { n         return 0; n       } n     } n     return pow(10, _); n   } n   if (s.back() >=  0  && s.back() <=  9  && s[s.length() - 2] ==  _ ) { n     if (s.back() ==  0  || s.back() ==  5 ) n       return 2 * pow(10, _ - 1); n     else n       return 0; n   } n } n vector<string> generate(string orig) { n   vector<string> v; n   string dum = orig; n   int x = 0; n   for (char c : orig) x += (c ==  X ); n   if (!x) { n     return {orig}; n   } n   for (char i =  0 ; i <=  9 ; i++) { n     for (int j = 0; j < dum.length(); j++) { n       if (dum[j] ==  X ) { n         dum[j] = i; n       } n     } n     v.push_back(dum); n     dum = orig; n   } n   return v; n } n int main() { n   string orig; n   cin >> orig; n   if (orig.length() == 1) { n     if (orig ==  X ) n       cout << 1; n     else n       cout << solver(orig); n     return 0; n   } n   vector<string> v = generate(orig); n   int ans = 0; n   for (string s : v) { n     if (s[0] ==  0 ) { n       ans += 0; n     } else if (s[0] ==  _ ) { n       for (char j =  1 ; j <=  9 ; j++) { n         s[0] = j; n         ans += solver(s); n       } n     } else { n       ans += solver(s); n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 500010; n int ans[N], arr[N], MAX[N]; n long long power_mod(long long x, long long y) { n   x %= 1000000007; n   long long res = 1; n   while (y) { n     if (y & 1) { n       res = (res * x) % 1000000007; n     } n     y /= 2; n     x = (x * x) % 1000000007; n   } n   return res; n } n void solve() { n   int n; n   cin >> n; n   vector<pair<int, int>> v(N); n   for (int i = 1; i <= n; i++) { n     cin >> v[i].first >> v[i].second; n     ans[i] = MAX[i] = 1; n   } n   sort(v.begin() + 1, v.begin() + n + 1); n   arr[n + 1] = v[n].second + 1; n   for (int i = 1; i <= n; i++) { n     arr[i] = v[i].first; n   } n   int ma = 0; n   for (int i = n; i >= 1; i--) { n     int up = upper_bound(arr + 1, arr + 2 + n, v[i].second) - arr; n     int p = ans[i]; n     ans[i] = max(ans[i], ans[i + 1]); n     ans[i] = max(ans[i], p + ans[up]); n   } n   int res = *max_element(ans, ans + n + 1); n   cout << res <<   n ; n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   int tc = 1; n   while (tc--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, p[11111], c[11111]; n vector<pair<int, int> > ve; n int main() { n   int a; n   cin >> n; n   for (int i = 2; i <= n; i++) { n     cin >> a; n     c[i] = a; n   } n   int s = 1; n   cin >> p[1]; n   for (int i = 2; i <= n; i++) { n     cin >> p[i]; n     if (p[i] != p[c[i]]) { n       s++; n     } n   } n   cout << s; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   set<long long> s; n   for (long long a = 1; a <= 2 * 1e9; a *= 2) { n     for (long long b = 1; b <= 2 * 1e9; b *= 3) { n       s.insert(a * b); n     } n   } n   int l, r, ans = 0; n   cin >> l >> r; n   for (set<long long>::iterator it = s.begin(); it != s.end(); ++it) n     ans += *it <= r && *it >= l; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const bool debug = 0; n int main() { n   if (!debug) { n     cin.tie(0); n     cin.sync_with_stdio(0); n     cout.tie(0); n     cout.sync_with_stdio(0); n   } n   int n, m; n   cin >> n >> m; n   vector<vector<int>> d(m, vector<int>(n)); n   for (int i = 0; i < m; i++) n     for (int j = 0; j < n; j++) cin >> d[i][j]; n   vector<int> out(m); n   for (int i = 0; i < m; i++) out[i] = i; n   for (int v = 0; v < n - 1; v++) { n     vector<pair<int, int>> k(m); n     int r = 0; n     for (int i = 0; i < m; i++) { n       k[i] = {d[i][n - 1] - d[i][v], i}; n       r += k[i].first; n     } n     sort(k.begin(), k.end()); n     reverse(k.begin(), k.end()); n     if (debug) n       for (int i = 0; i < m; i++) n         cout << k[i].first <<  :  << k[i].second <<    ; n     if (debug) cout <<   n  << r <<   n ; n     int i = 0; n     for (; i < m; i++) { n       if (r > 0) n         r -= k[i].first; n       else n         break; n     } n     if (r <= 0 && out.size() > i) { n       out.resize(i); n       for (int j = 0; j < i; j++) out[j] = k[j].second; n     } n   } n   cout << out.size() <<   n ; n   for (int i = 0; i < out.size(); i++) cout << out[i] + 1 <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace IO { n inline char gc() { n   static char buf[1000000], *p1 = buf, *p2 = buf; n   return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) n              ? EOF n              : *p1++; n } n template <typename T> n inline void read(T &x) { n   x = (T)0; n   T f = 1; n   char ssd = gc(); n   while (ssd <  0  || ssd >  9 ) f = ssd ==  -  ? -1 : 1, ssd = gc(); n   while (ssd >=  0  && ssd <=  9 ) n     x = (x << 3) + (x << 1) + (ssd -  0 ), ssd = gc(); n   x = x * f; n } n char OUT[1000000], *S = OUT, *T = OUT + 1000000; n char Num[1000000]; n int toP; n inline void out() { n   fwrite(OUT, sizeof(char), S - OUT, stdout); n   S = OUT; n } n inline void pc(char ssd) { n   *S++ = ssd; n   if (S == T) out(); n } n template <typename T> n inline void write(T x) { n   if (x == 0) pc( 0 ); n   if (x < 0) x = -x, pc( - ); n   toP = 0; n   while (x) Num[++toP] = x % 10 +  0 , x /= 10; n   while (toP) pc(Num[toP--]); n } n };  // namespace IO n const int maxn = 4e5 + 10; n namespace SGT { n int sum[maxn << 5]; n int ls[maxn << 5], rs[maxn << 5], Node; n inline void pushup(int NODE) { sum[NODE] = sum[ls[NODE]] + sum[rs[NODE]]; } n void change(int &NODE, int l, int r, int id) { n   if (!NODE) NODE = ++Node; n   if (l == r) { n     sum[NODE] += 1; n     return; n   } n   int mid = (l + r) >> 1; n   if (mid >= id) n     change(ls[NODE], l, mid, id); n   else n     change(rs[NODE], mid + 1, r, id); n   pushup(NODE); n } n int query(int NODE, int l, int r, int L, int R) { n   if (L > R) return 0; n   if (!NODE || (L <= l && r <= R)) return sum[NODE]; n   int re = 0; n   int mid = (l + r) >> 1; n   if (mid >= L) re += query(ls[NODE], l, mid, L, R); n   if (mid < R) re += query(rs[NODE], mid + 1, r, L, R); n   return re; n } n int merge(int root1, int root2, int l, int r) { n   if (!root1 || !root2) return root1 + root2; n   int New = ++Node; n   if (l == r) { n     sum[New] = sum[root1] + sum[root2]; n     return New; n   } else { n     int mid = (l + r) >> 1; n     ls[New] = merge(ls[root1], ls[root2], l, mid); n     rs[New] = merge(rs[root1], rs[root2], mid + 1, r); n     pushup(New); n     return New; n   } n } n }  // namespace SGT n namespace Tham { n int root[maxn]; n int len[maxn], fa[maxn], son[maxn][26], end = 1, tnt = 1; n inline int insert(int C, int last) { n   end = ++tnt; n   len[end] = len[last] + 1; n   while (last && son[last][C] == 0) son[last][C] = end, last = fa[last]; n   if (!last) { n     fa[end] = 1; n     return end; n   } n   register int c = son[last][C]; n   if (len[last] + 1 == len[c]) { n     fa[end] = c; n     return end; n   } n   len[++tnt] = len[last] + 1; n   for (register int i = 0; i < 26; i += 1) son[tnt][i] = son[c][i]; n   fa[tnt] = fa[c], fa[c] = tnt; n   fa[end] = tnt; n   while (son[last][C] == c) son[last][C] = tnt, last = fa[last]; n   return end; n } n }  // namespace Tham n int Len; n char ssd[maxn], S[maxn]; n int head[maxn], to[maxn], nxt[maxn], tot; n inline void add(int x, int y) { n   nxt[++tot] = head[x]; n   head[x] = tot; n   to[tot] = y; n } n void dfs(int now) { n   for (register int i = head[now]; i; i = nxt[i]) { n     dfs(to[i]); n     Tham::root[now] = SGT::merge(Tham::root[now], Tham::root[to[i]], 1, Len); n   } n } n int pos[maxn], id[maxn]; n int main() { n   scanf( %s , S + 1); n   Len = strlen(S + 1); n   id[0] = pos[0] = 1; n   for (register int i = 1; i <= Len; i += 1) n     pos[i] = Tham::insert(S[i] -  a , pos[i - 1]), n     SGT::change(Tham::root[pos[i]], 1, Len, i); n   for (register int i = 2; i <= Tham::tnt; i += 1) add(Tham::fa[i], i); n   dfs(1); n   int T; n   scanf( %d , &T); n   while (T--) { n     int l, r; n     scanf( %d %d %s , &l, &r, ssd + 1); n     int LL = strlen(ssd + 1), match = 0; n     for (register int i = 1; i <= LL; i += 1) { n       if (Tham::son[id[i - 1]][ssd[i] -  a ]) n         id[i] = Tham::son[id[i - 1]][ssd[i] -  a ], match += 1; n       else n         break; n     } n     bool ccf = false; n     for (register int i = match; i >= 0; i -= 1) { n       for (register int color = (i < LL ? ssd[i + 1] -  a  + 1 : 0); color < 26; n            color += 1) n         if (Tham::son[id[i]][color]) { n           int nxt = Tham::son[id[i]][color]; n           if (SGT::query(Tham::root[nxt], 1, Len, l + i, r)) { n             for (register int j = 1; j <= i; j += 1) printf( %c , ssd[j]); n             printf( %c n , char(color + 97)); n             ccf = true; n             break; n           } n         } n       if (ccf) break; n     } n     if (!ccf) puts( -1 ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long int t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     unordered_map<int, long long> mmap; n     while (n % 3 == 0) { n       mmap[3]++; n       n /= 3; n     } n     while (n % 2 == 0) { n       mmap[2]++; n       n /= 2; n     } n     if ((n > 1) || (mmap[2] > mmap[3])) n       cout << -1 << endl; n     else { n       long long count = mmap[3]; n       count += (mmap[3] - mmap[2]); n       cout << count << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 58; n vector<int> adj[maxn], V; n bitset<maxn> mark; n void dfs(int v) { n   mark[v] = 1; n   V.push_back(v); n   for (auto u : adj[v]) { n     if (!mark[u]) { n       dfs(u); n       V.push_back(v); n     } n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n, m, k; n   cin >> n >> m >> k; n   for (int i = 0; i < m; i++) { n     int v, u; n     cin >> v >> u; n     v--; n     u--; n     adj[v].push_back(u); n     adj[u].push_back(v); n   } n   dfs(0); n   int ptr = 0; n   while (k) { n     cout << (V.size() - ptr) / k <<    ; n     for (int i = 0; i < (V.size() - ptr) / k; i++) { n       cout << V[ptr + i] + 1 <<    ; n     } n     ptr += (V.size() - ptr) / k; n     cout <<   n ; n     k--; n   } n } n


#include <bits/stdc++.h> n const int N = 123456; n int arr[N], i, j; n using namespace std; n int main() { n   long long n, k, a, b, ans1 = 0, ans2 = 0, ans = 0; n   scanf( %lld %lld , &n, &k); n   scanf( %lld %lld , &a, &b); n   ans1 = (n - 1) * a; n   if (k == 1) return cout << ans1 << endl, 0; n   while (n != 0 && n != 1) { n     if (n % k == 0) { n       if (b < a * (n - n / k)) n         ans += b; n       else n         ans += a * (n - n / k); n       n = n / k; n     } else { n       ans += ((n % k) * a); n       n = n - (n % k); n     } n   } n   if (n == 0) ans -= a; n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100010; n const int maxk = 17; n struct TNode { n   int L, R; n   int lc, rc; n   int sum; n   bool sw; n   TNode(int L = 0, int R = 0) : L(L), R(R), lc(-1), rc(-1), sum(0), sw(false) {} n }; n TNode t[3 * maxn]; n int tc = 0; n int build(int L, int R) { n   int node = tc++; n   t[node] = TNode(L, R); n   if (R - L > 1) { n     int M = (L + R) / 2; n     t[node].lc = build(L, M); n     t[node].rc = build(M, R); n   } n   return node; n } n void relax(int node) { n   if (t[node].sw) { n     t[node].sw = false; n     t[node].sum = t[node].R - t[node].L - t[node].sum; n     if (t[node].R - t[node].L > 1) { n       t[t[node].lc].sw ^= true; n       t[t[node].rc].sw ^= true; n     } n   } n } n void combine(int node) { t[node].sum = t[t[node].lc].sum + t[t[node].rc].sum; } n int getsum(int node, int L, int R) { n   relax(node); n   if (R <= t[node].L || t[node].R <= L) { n     return 0; n   } n   if (L <= t[node].L && t[node].R <= R) { n     return t[node].sum; n   } n   return getsum(t[node].lc, L, R) + getsum(t[node].rc, L, R); n } n void swapseg(int node, int L, int R) { n   relax(node); n   if (R <= t[node].L || t[node].R <= L) { n     return; n   } n   if (L <= t[node].L && t[node].R <= R) { n     t[node].sw = true; n     relax(node); n     return; n   } n   swapseg(t[node].lc, L, R); n   swapseg(t[node].rc, L, R); n   combine(node); n } n int N, M; n vector<int> e[maxn]; n int par[maxn], d[maxn], w[maxn]; n int root[maxn], len[maxn], sky[maxn], tr[maxn]; n int up[maxk + 1][maxn]; n int A, B; n bool enabled; n void dfs_build(int v, int p) { n   par[v] = p; n   d[v] = (p == -1 ? 0 : d[p] + 1); n   w[v] = 1; n   root[v] = v; n   len[v] = 1; n   for (int i = 0; i < (int)(e[v].size()); ++i) { n     int u = e[v][i]; n     if (u == p) { n       continue; n     } n     if (d[u] == -1) { n       dfs_build(u, v); n       w[v] += w[u]; n     } else { n       A = u; n       B = v; n     } n   } n   for (int i = 0; i < (int)(e[v].size()); ++i) { n     int u = e[v][i]; n     if (u == p) { n       continue; n     } n     if (d[u] == d[v] + 1 && 2 * w[u] >= w[v]) { n       root[v] = root[u]; n       ++len[root[v]]; n     } n   } n } n void build_up() { n   for (int i = 0; i < (int)(N); ++i) { n     up[0][i] = par[i]; n   } n   for (int j = 0; j < (int)(maxk); ++j) { n     for (int i = 0; i < (int)(N); ++i) { n       up[j + 1][i] = (up[j][i] == -1 ? -1 : up[j][up[j][i]]); n     } n   } n } n int get_up(int v, int d) { n   for (int j = maxk; j >= 0; --j) { n     if ((1 << j) <= d) { n       d -= 1 << j; n       v = up[j][v]; n     } n   } n   return v; n } n int lca(int v, int u) { n   if (d[v] < d[u]) { n     swap(v, u); n   } n   v = get_up(v, d[v] - d[u]); n   if (v == u) { n     return v; n   } n   for (int j = maxk; j >= 0; --j) { n     if (up[j][v] != up[j][u]) { n       v = up[j][v]; n       u = up[j][u]; n     } n   } n   return par[v]; n } n int dist(int v, int u) { n   int w = lca(u, v); n   return d[u] + d[v] - 2 * d[w]; n } n int total; n void swap_up(int v, int x) { n   int r = root[v]; n   int p = d[r] - d[v]; n   total += getsum(tr[r], 0, len[r]); n   if (p + x <= len[r]) { n     swapseg(tr[r], p, p + x); n   } else { n     swapseg(tr[r], p, len[r]); n     swap_up(sky[r], x - (len[r] - p)); n   } n   total -= getsum(tr[r], 0, len[r]); n } n void swap_path(int x, int y) { n   int w = lca(x, y); n   swap_up(x, d[x] - d[w]); n   swap_up(y, d[y] - d[w]); n } n int sum_up(int v, int x) { n   int r = root[v]; n   int p = d[r] - d[v]; n   if (p + x <= len[r]) { n     return getsum(tr[r], p, p + x); n   } else { n     return getsum(tr[r], p, len[r]) + sum_up(sky[r], x - (len[r] - p)); n   } n } n int onpath(int x, int y, int z) { n   int w = lca(x, y), l = dist(x, y); n   if (z <= d[x] - d[w]) { n     return get_up(x, z); n   } else { n     return get_up(y, l - z); n   } n } n int fork(int x) { n   int d1 = dist(x, A), d2 = dist(x, B), d3 = dist(A, B); n   return onpath(x, A, (d1 + d2 - d3) / 2); n } n int bonus() { n   if (!enabled) { n     return 0; n   } n   int w = lca(A, B); n   if (sum_up(A, d[A] - d[w]) + sum_up(B, d[B] - d[w]) == dist(A, B)) { n     return 0; n   } else { n     return 1; n   } n } n int main() { n   scanf( %d%d , &N, &M); n   for (int i = 0; i < (int)(N); ++i) { n     int x, y; n     scanf( %d%d , &x, &y); n     --x; n     --y; n     e[x].push_back(y); n     e[y].push_back(x); n   } n   for (int i = 0; i < (int)(N); ++i) { n     d[i] = -1; n   } n   dfs_build(0, -1); n   build_up(); n   for (int i = 0; i < (int)(N); ++i) { n     if (root[i] == i) { n       tr[i] = build(0, len[i]); n       sky[i] = get_up(i, len[i]); n     } n   } n   if (d[A] > d[B]) { n     swap(A, B); n   } n   total = N; n   enabled = false; n   for (int i = 0; i < (int)(M); ++i) { n     int x, y; n     scanf( %d%d , &x, &y); n     --x; n     --y; n     int p = fork(x), q = fork(y); n     if (p == q) { n       swap_path(x, y); n     } else { n       swap_path(x, p); n       swap_path(y, q); n       int lup = d[q] < d[p] ? d[p] - d[q] : d[p] - d[A] + 1 + d[B] - d[q]; n       int ldown = d[q] > d[p] ? d[q] - d[p] : d[B] - d[p] + 1 + d[q] - d[A]; n       if (lup == ldown) { n         int vup = p == A ? B : par[p]; n         int vdown = p == B ? A : get_up(B, d[B] - d[p] - 1); n         if (vup < vdown) { n           --lup; n         } else { n           --ldown; n         } n       } n       if (lup < ldown) { n         if (d[q] < d[p]) { n           swap_path(p, q); n         } else { n           swap_path(p, A); n           enabled ^= true; n           swap_path(B, q); n         } n       } else { n         if (d[q] > d[p]) { n           swap_path(p, q); n         } else { n           swap_path(p, B); n           enabled ^= true; n           swap_path(q, A); n         } n       } n     } n     cout << total - bonus() <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int A[200005]; n int lazy[600005], ma[600005], mi[600005]; n long long sum[600005]; n void push_up(int cur) { n   sum[cur] = sum[cur * 2] + sum[cur * 2 + 1]; n   ma[cur] = max(ma[cur * 2], ma[cur * 2 + 1]); n   mi[cur] = min(mi[cur * 2], mi[cur * 2 + 1]); n } n void push_down(int cur, int l, int r) { n   if (lazy[cur] == 0) return; n   int mid = (l + r) / 2; n   sum[cur * 2] = (lazy[cur] * 1ll * (mid - l + 1)); n   ma[cur * 2] = mi[cur * 2] = lazy[cur]; n   lazy[cur * 2] = lazy[cur]; n   sum[cur * 2 + 1] = (lazy[cur] * 1ll * (r - mid)); n   ma[cur * 2 + 1] = mi[cur * 2 + 1] = lazy[cur]; n   lazy[cur * 2 + 1] = lazy[cur]; n   lazy[cur] = 0; n } n int __ma; n void build(int cur, int l, int r) { n   lazy[cur] = 0; n   __ma = max(__ma, cur); n   if (l == r) { n     sum[cur] = mi[cur] = ma[cur] = A[r]; n     return; n   } n   int mid = (l + r) / 2; n   build(cur * 2, l, mid); n   build(cur * 2 + 1, mid + 1, r); n   push_up(cur); n } n void modify_toMax(int cur, int l, int r, int cl, int cr, int Ma) { n   if (mi[cur] >= Ma) return; n   if (l >= cl && r <= cr) { n     if (ma[cur] <= Ma) { n       ma[cur] = mi[cur] = Ma; n       sum[cur] = Ma * 1ll * (r - l + 1); n       lazy[cur] = Ma; n       return; n     } n   } n   push_down(cur, l, r); n   int mid = (l + r) / 2; n   if (cl <= mid) modify_toMax(cur * 2, l, mid, cl, cr, Ma); n   if (cr > mid) modify_toMax(cur * 2 + 1, mid + 1, r, cl, cr, Ma); n   push_up(cur); n } n long long query_sum(int cur, int l, int r, int cl, int cr) { n   if (l >= cl && r <= cr) return sum[cur]; n   push_down(cur, l, r); n   int mid = (l + r) / 2; n   long long ans = 0; n   if (cl <= mid) ans += query_sum(cur * 2, l, mid, cl, cr); n   if (cr > mid) ans += query_sum(cur * 2 + 1, mid + 1, r, cl, cr); n   return ans; n } n int query_firSmallInd(int cur, int l, int r, int cl, int cr, int Ma) { n   if (mi[cur] > Ma) return -1; n   if (l == r) { n     if (ma[cur] <= Ma) return r; n     return -1; n   } n   push_down(cur, l, r); n   int mid = (l + r) / 2; n   if (cl <= mid) { n     int ind = query_firSmallInd(cur * 2, l, mid, cl, cr, Ma); n     if (ind != -1) return ind; n   } n   if (cr > mid) return query_firSmallInd(cur * 2 + 1, mid + 1, r, cl, cr, Ma); n   return -1; n } n int query_maxPresum(int cur, int l, int r, long long Ma) { n   if (l == r) { n     if (ma[cur] <= Ma) return r + 1; n     return r; n   } n   push_down(cur, l, r); n   int mid = (l + r) / 2; n   if (sum[cur * 2] <= Ma) n     return query_maxPresum(cur * 2 + 1, mid + 1, r, Ma - sum[cur * 2]); n   return query_maxPresum(cur * 2, l, mid, Ma); n } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i += 1) scanf( %d , &A[i]); n   build(1, 1, n); n   int a, b, c; n   for (int i = 1; i <= m; i += 1) { n     scanf( %d%d%d , &a, &b, &c); n     if (a == 1) { n       modify_toMax(1, 1, n, 1, b, c); n     } else { n       int lef, rig, cur_ind = b, ans = 0; n       while (cur_ind <= n) { n         lef = query_firSmallInd(1, 1, n, cur_ind, n, c); n         if (lef == -1) break; n         long long pre = 0; n         if (lef > 1) pre = query_sum(1, 1, n, 1, lef - 1); n         rig = query_maxPresum(1, 1, n, pre + c); n         --rig; n         c -= query_sum(1, 1, n, lef, rig); n         ans += (rig - lef + 1); n         cur_ind = rig + 2; n       } n       printf( %d n , ans); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int read() { n   int x = 0, f = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while ( 0  <= c && c <=  9 ) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   return x * f; n } n int n, m, cnt, maxx, tab[300], f[1005][105][105]; n char s[15]; n struct Trie { n   int bj, len, fail, ch[4]; n } tree[105]; n void Insert() { n   int len = strlen(s + 1), now = 1; n   maxx = max(maxx, len); n   for (int i = 1; i <= len; ++i) { n     int v = tab[s[i]]; n     int &o = tree[now].ch[v]; n     if (!o) o = ++cnt; n     now = o; n   } n   tree[now].bj = 1; n   tree[now].len = len; n } n void Build() { n   queue<int> q; n   for (int i = 0; i <= 3; ++i) tree[0].ch[i] = 1; n   q.push(1); n   while (!q.empty()) { n     int x = q.front(), fail = tree[x].fail; n     q.pop(); n     tree[x].bj |= tree[fail].bj; n     tree[x].len = max(tree[x].len, tree[fail].len); n     for (int i = 0; i <= 3; ++i) { n       int &y = tree[x].ch[i]; n       if (!y) n         y = tree[fail].ch[i]; n       else n         tree[y].fail = tree[fail].ch[i], q.push(y); n     } n   } n } n inline int Mod(int x) { return x >= 1000000009 ? x - 1000000009 : x; } n int main() { n   tab[ A ] = 0; n   tab[ C ] = 1; n   tab[ G ] = 2; n   tab[ T ] = 3; n   n = read(); n   m = read(); n   cnt = 1; n   for (int i = 1; i <= m; ++i) scanf( %s , s + 1), Insert(); n   Build(); n   f[0][0][1] = 1; n   for (int i = 0; i < n; ++i) n     for (int j = 0; j <= maxx; ++j) n       for (int k = 1; k <= cnt; ++k) n         if (f[i][j][k]) n           for (int p = 0; p <= 3; ++p) { n             int y = tree[k].ch[p]; n             if (j + 1 <= tree[y].len) n               f[i + 1][0][y] = Mod(f[i + 1][0][y] + f[i][j][k]); n             else n               f[i + 1][j + 1][y] = Mod(f[i + 1][j + 1][y] + f[i][j][k]); n           } n   int ans = 0; n   for (int k = 1; k <= cnt; ++k) ans = Mod(ans + f[n][0][k]); n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n inline void in(int &MAGNUS) { scanf( %d , &MAGNUS); } n inline void out(int MAGNUS) { printf( %d n , MAGNUS); } n inline void in(int &MAGNUS, int &CLAR) { scanf( %d%d , &MAGNUS, &CLAR); } n inline void out(int MAGNUS, int CLAR) { printf( %d %d n , MAGNUS, CLAR); } n inline void inl(long long &LIV) { scanf( %lld , &LIV); } n inline void inl(long long &LIV, long long &MART) { n   scanf( %lld%lld , &LIV, &MART); n } n inline void outl(long long LIV) { printf( %lld n , LIV); } n inline void outl(long long LIV, long long MART) { n   printf( %lld %lld n , LIV, MART); n } n using namespace std; n int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1}; n int dy[] = {0, -1, 0, 1, 1, -1, -1, 1}; n int R, C, x[405][405], sum[8][405][405]; n bool inside(int r, int c) { return 1 <= r && r <= R && 1 <= c && c <= C; } n int rsum(int dir, int r1, int c1, int r2, int c2) { n   return abs(sum[dir][r2][c2] - sum[dir][r1 - dx[dir]][c1 - dy[dir]]); n } n int main() { n   in(R, C); n   for (int i = 1; i <= R; i++) { n     for (int j = 1; j <= C; j++) { n       char ch; n       cin >> ch; n       x[i][j] = ch -  0 ; n     } n   } n   for (int dir = 0; dir <= 7; dir++) { n     for (int i = 1; i <= R; i++) { n       for (int j = 1; j <= C; j++) { n         if (inside(i - dx[dir], j - dy[dir])) continue; n         int r = i, c = j; n         while (inside(r, c)) { n           if (r == i && c == j) n             sum[dir][r][c] = x[i][j]; n           else n             sum[dir][r][c] = x[r][c] + sum[dir][r - dx[dir]][c - dy[dir]]; n           r += dx[dir]; n           c += dy[dir]; n         } n       } n     } n   } n   long long ans = 0; n   for (int i = 1; i <= R; i++) { n     for (int j = 1; j <= C; j++) { n       for (int dir = 0; dir <= 3; dir++) { n         for (int k = 1; k <= min(R, C); k++) { n           int r1 = i + dx[dir] * k, c1 = j + dy[dir] * k; n           int r2 = i + dx[(dir + 1) % 4] * k, c2 = j + dy[(dir + 1) % 4] * k; n           if (!inside(r1, c1) || !inside(r2, c2)) continue; n           int s1 = rsum(dir, i, j, r1, c1), n               s2 = rsum((dir + 1) % 4, i, j, r2, c2), n               s3 = rsum(dir + 4, r2, c2, r1, c1); n           ans += (s1 == 0 && s2 == 0 && s3 == 0); n         } n         for (int k = 1; k <= min(R, C); k++) { n           int r1 = i + dx[dir] * k, c1 = j + dy[dir] * k; n           int r2 = i + dx[(dir + 1) % 4] * k, c2 = j + dy[(dir + 1) % 4] * k; n           int r3 = i + dx[(dir + 2) % 4] * k, c3 = j + dy[(dir + 2) % 4] * k; n           if (!inside(r1, c1) || !inside(r2, c2) || !inside(r3, c3)) continue; n           int s1 = rsum(dir, i, j, r1, c1), s2 = rsum(dir + 4, r2, c2, r1, c1); n           int s3 = rsum((dir + 2) % 4, i, j, r3, c3), n               s4 = rsum((dir + 1) % 4 + 4, r3, c3, r2, c2); n           ans += (s1 == 0 && s2 == 0 && s3 == 0 && s4 == 0); n         } n       } n     } n   } n   outl(ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = (int)1e7 + 7; n const int Mx = (int)1e7; n int n, m; n int A[N], B[N]; n int lp[N]; n map<int, vector<int> > a, b; n void precalc() { n   for (int i = 2; i <= Mx; i++) { n     if (!lp[i]) { n       lp[i] = i; n       if (i * 1ll * i <= Mx) { n         for (int j = i * i; j <= Mx; j += i) { n           if (!lp[j]) lp[j] = i; n         } n       } n     } n   } n } n int main() { n   precalc(); n   scanf( %d%d , &n, &m); n   for (int i = 1, x; i <= n; i++) { n     scanf( %d , &A[i]); n     x = A[i]; n     while (x > 1) { n       int p = lp[x]; n       a[p].push_back(i); n       x /= p; n     } n   } n   for (int i = 1, x; i <= m; i++) { n     scanf( %d , &B[i]); n     x = B[i]; n     while (x > 1) { n       int p = lp[x]; n       b[p].push_back(i); n       x /= p; n     } n   } n   for (int i = 2; i < N; i++) { n     if (lp[i] == i) { n       int len = min(a[i].size(), b[i].size()); n       while (len) { n         len--; n         A[a[i].back()] /= i; n         B[b[i].back()] /= i; n         a[i].pop_back(); n         b[i].pop_back(); n       } n     } n   } n   printf( %d %d n , n, m); n   for (int i = 1; i <= n; i++) { n     printf( %d  , A[i]); n   } n   printf(  n ); n   for (int i = 1; i <= m; i++) { n     printf( %d  , B[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n int f[100001]; n int a[100001]; n using namespace std; n int main() { n   bool isAm = false; n   long long int n, m, x; n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     cin >> x; n     if (f[x] == 0) n       f[x] = i + 1; n     else n       f[x] = -1; n   } n   for (int i = 0; i < m; i++) { n     cin >> x; n     if (f[x] == 0) { n       cout <<  Impossible ; n       return 0; n     } else if (f[x] != -1) { n       a[i] = f[x]; n     } else n       isAm = true; n   } n   if (isAm) { n     cout <<  Ambiguity ; n     return 0; n   } n   cout <<  Possible n ; n   for (int i = 0; i < m; i++) cout << a[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC target( avx2 ) n #pragma GCC optimization( O3 ) n #pragma GCC optimization( unroll-loops ) n #pragma GCC optimize( Ofast ) n #pragma GCC target( avx,avx2,fma ) n using namespace std; n long long binpow(long long base, long long exp, int mod) { n   long long res = 1; n   while (exp > 0) { n     if (exp % 2 == 1) res = (res * base) % mod; n     exp = exp >> 1; n     base = (base * base) % mod; n   } n   return res; n } n long long mod(long long x) { n   return ((x % 1000000007LL + 1000000007LL) % 1000000007LL); n } n long long add(long long a, long long b) { return mod(mod(a) + mod(b)); } n long long mul(long long a, long long b) { return mod(mod(a) * mod(b)); } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long int m; n   cin >> m; n   vector<long long int> v1; n   for (long long int i = 0; i < m; i++) { n     long long int x; n     cin >> x; n     v1.push_back(x); n   }; n   sort(v1.begin(), v1.end()); n   long long int n; n   cin >> n; n   vector<long long int> v2; n   for (long long int i = 0; i < n; i++) { n     long long int x; n     cin >> x; n     v2.push_back(x); n   }; n   sort(v2.begin(), v2.end()); n   long long int sum = 0; n   for (int i = 0; i < n; i++) sum += v2[i]; n   if (n < v1[0] + 2) { n     cout << sum <<   n ; n   } else { n     long long int sum2 = 0; n     for (long long int i = n - 1; i >= 0; i -= v1[0] + 2) { n       for (long long int j = i; j >= max(i - v1[0] + 1, 0LL); j--) n         sum2 += v2[j]; n     } n     cout << sum2 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1 << 29; n struct abc { n   int left, right, capacity, cost; n } edge[12345]; n int n, k, x, e = 0, cost[50], p[50]; n void addEdge(int a, int b, int c, int d) { n   edge[e].left = a; n   edge[e].right = b; n   edge[e].capacity = c; n   edge[e].cost = d; n   e++; n   edge[e].left = b; n   edge[e].right = a; n   edge[e].capacity = 0; n   edge[e].cost = -d; n   e++; n } n bool getPath(int s, int t) { n   for (int i = 0; i < n; i++) cost[i] = INF; n   cost[s] = 0; n   bool upd = true; n   for (int it = 1; upd && it < n; it++) n     for (int i = upd = 0; i < e; i++) n       if (edge[i].capacity > 0 && cost[edge[i].left] < INF && n           cost[edge[i].right] > cost[edge[i].left] + edge[i].cost) { n         cost[edge[i].right] = cost[edge[i].left] + edge[i].cost; n         p[edge[i].right] = i; n         upd = true; n       } n   return cost[t] < INF; n } n int minCostMaxFlow(int s, int t) { n   int MaxFlow = 0, MinCost = 0, flow; n   while (getPath(s, t)) { n     MinCost += cost[t]; n     if (MinCost > k) return MaxFlow; n     flow = INF; n     for (int c = t; c != s; c = edge[p[c]].left) { n       flow = min(flow, edge[p[c]].capacity); n       if (edge[p[c]].cost != 0) flow = 1; n     } n     for (int c = t; c != s; c = edge[p[c]].left) { n       edge[p[c]].capacity -= flow; n       edge[p[c] ^ 1].capacity += flow; n     } n     MaxFlow += flow; n   } n   return MaxFlow; n } n int main() { n   cin >> n >> k; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) { n       cin >> x; n       if (x) { n         addEdge(i, j, x, 0); n         addEdge(i, j, INF, 1); n       } n     } n   cout << minCostMaxFlow(0, n - 1); n } n


#include <bits/stdc++.h> n using namespace std; n int Month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; n int A[1000 + 1]; n int B[126]; n void omae_wa_mou_shindeiru() { n   int n, k; n   cin >> n >> k; n   string s; n   cin >> s; n   for (int i = 0; i < n; ++i) { n     int c = 1; n     while (s[i] == s[i + 1] && i < n) { n       ++c; n       ++i; n     } n     B[s[i]] += c / k; n   } n   int ans = 0; n   for (int i =  a ; i <=  z ; ++i) { n     ans = max(ans, B[i]); n   } n   cout << ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   ; n   int t = 1; n   while (t--) { n     omae_wa_mou_shindeiru(); n     if (t) cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long i; n   while (cin >> i) { n     if (i % 2) n       cout << 1 << endl; n     else n       cout << 2 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n const int maxN = 1e5 + 10; n int n, m, s, f; n int t[maxN], l[maxN], r[maxN]; n bool inside(int l, int m, int r) { return l <= m && m <= r; } n void slv() { n   int d = f > s ? 1 : -1; n   m++; n   t[m] = inf, l[m] = inf, r[m] = -inf; n   int tm = 1; n   int p = 1; n   while (true) { n     if (s == f) break; n     if (tm != t[p]) n       s += d, printf( %c , d > 0 ?  R  :  L ); n     else { n       if (inside(l[p], s, r[p]) || inside(l[p], s + d, r[p])) n         printf( X ); n       else n         printf( %c , d > 0 ?  R  :  L ), s += d; n       p++; n     } n     tm++; n   } n } n int main() { n   while (~scanf( %d%d%d%d , &n, &m, &s, &f)) { n     for (int i = 1; i <= m; i++) scanf( %d%d%d , &t[i], &l[i], &r[i]); n     slv(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n string s[55]; n vector<int> getRow(int x) { n   vector<int> R; n   for (int i = 1; i <= m; i++) n     if (s[x][i] ==  # ) R.push_back(i); n   return R; n } n vector<int> getCol(int x) { n   vector<int> C; n   for (int i = 1; i <= n; i++) n     if (s[i][x] ==  # ) C.push_back(i); n   return C; n } n int Viz[55]; n int main() { n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     string t; n     cin >> t; n     s[i] =  .  + t +  . ; n   } n   int nope = 0; n   for (int i = 1; i <= n && !nope; i++) { n     if (!Viz[i]) { n       vector<int> V, R; n       int ok = 0; n       for (int j = 1; j <= m; j++) { n         if (s[i][j] ==  # ) { n           R.push_back(j); n           if (!ok) n             V = getCol(j), ok = 1; n           else { n             vector<int> U = getCol(j); n             if (U != V) nope = 1; n           } n         } n       } n       for (int j : V) { n         Viz[j] = 1; n         vector<int> Row = getRow(j); n         if (R != Row) { n           nope = 1; n         } n       } n     } n   } n   if (nope) n     cout <<  No ; n   else n     cout <<  Yes ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n int const nmax = 200000; n struct Person { n   int cost; n   int number; n   bool operator<(Person const &a) const { return number < a.number; } n }; n Person v[1 + nmax]; n void solve() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> v[i].number >> v[i].cost; n   sort(v + 1, v + n + 1); n   ll result = 0; n   int votes = 0; n   priority_queue<int, vector<int>, greater<int>> pq; n   for (int i = n; 1 <= i; i--) { n     pq.push(v[i].cost); n     if (v[i].number <= i - 1 + votes) n       continue; n     else { n       result += pq.top(); n       votes++; n       pq.pop(); n     } n   } n   cout << result <<   n ; n } n int main() { n   int t; n   cin >> t; n   for (int testcase = 1; testcase <= t; testcase++) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int times[50] = {0}; n int graph[50][50] = {0}; n void findMissing(int n, int &temp1, int &temp2) { n   bool condition = false; n   for (int i = 0; i < n; i++) { n     if (times[i] != (n - 1)) { n       if (condition) n         temp2 = i; n       else { n         temp1 = i; n         condition = true; n       } n     } n   } n } n void swap(int &n1, int &n2) { n   n1 += n2; n   n2 = n1 - n2; n   n1 -= n2; n } n void findOrder(int n, int &temp1, int &temp2) { n   for (int i = 0; i < n; i++) { n     bool condition = false; n     if (i == temp1 || i == temp2) n       continue; n     else { n       if (graph[temp1][i] == 1 && graph[i][temp2] == 1) n         return; n       else if (graph[i][temp1] == 1 && graph[temp2][i] == 1) { n         swap(temp1, temp2); n         return; n       } n     } n   } n } n int main() { n   int n, temp1, temp2; n   cin >> n; n   for (int i = 0; i < (((n * (n - 1)) / 2) - 1); i++) { n     cin >> temp1 >> temp2; n     times[temp1 - 1]++; n     times[temp2 - 1]++; n     graph[temp1 - 1][temp2 - 1] = 1; n   } n   findMissing(n, temp1, temp2); n   findOrder(n, temp1, temp2); n   cout << temp1 + 1 <<     << temp2 + 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int mp[500][500]; n int rSum[500][500], cSum[500][500]; n int dSumF[500][500], dSumB[500][500]; n int blacks(int r1, int c1, int r2, int c2) { n   int ans = 1; n   if (r1 == r2 && c1 == c2) { n     ans = 1; n   } else if (r1 == r2) { n     if (c2 > c1) { n       ans = rSum[r1][c2] - rSum[r1][c1 - 1]; n     } else { n       ans = rSum[r1][c1] - rSum[r1][c2 - 1]; n     } n   } else if (c1 == c2) { n     if (r2 > r1) { n       ans = cSum[r2][c1] - cSum[r1 - 1][c1]; n     } else { n       ans = cSum[r1][c1] - cSum[r2 - 1][c1]; n     } n   } else if (abs(r1 - r2) == abs(c1 - c2)) { n     if (r1 < r2) { n       if (c1 < c2) { n         ans = dSumB[r2][c2] - dSumB[r1 - 1][c1 - 1]; n       } else { n         ans = dSumF[r2][c2] - dSumF[r1 - 1][c1 + 1]; n       } n     } else { n       if (c2 < c1) { n         ans = dSumB[r1][c1] - dSumB[r2 - 1][c2 - 1]; n       } else { n         ans = dSumF[r1][c1] - dSumF[r2 - 1][c2 + 1]; n       } n     } n   } else n     ans = 1; n   return ans; n } n int valid(int r1, int c1, int r2, int c2, int r3, int c3) { n   return !(blacks(r1, c1, r2, c2) || blacks(r1, c1, r3, c3) || n            blacks(r2, c2, r3, c3)); n } n int main() { n   scanf( %d %d n , &n, &m); n   int i, j, k; n   char c; n   for (i = 1; i <= n; i++) { n     for (j = 1; j <= m; j++) { n       scanf( %c , &c); n       mp[i][j] = c -  0 ; n     } n     scanf(  n ); n   } n   for (i = 0; i <= n + 1; i++) { n     for (j = 0; j <= m + 1; j++) { n       rSum[i][j] = 0; n       cSum[i][j] = 0; n       dSumB[i][j] = 0; n       dSumF[i][j] = 0; n     } n   } n   for (i = 1; i <= n; i++) { n     for (j = 1; j <= m; j++) { n       rSum[i][j] = rSum[i][j - 1] + mp[i][j]; n       cSum[i][j] = cSum[i - 1][j] + mp[i][j]; n       dSumF[i][j] = dSumF[i - 1][j + 1] + mp[i][j]; n       dSumB[i][j] = dSumB[i - 1][j - 1] + mp[i][j]; n     } n   } n   int ans = 0; n   for (i = 1; i <= n; i++) { n     for (j = 1; j <= m; j++) { n       for (k = 1; j + k <= m && i - k > 0; k++) { n         ans += valid(i, j, i, j + k, i - k, j); n       } n       for (k = 1; j - k > 0 && i - k > 0; k++) { n         ans += valid(i, j, i, j - k, i - k, j); n       } n       for (k = 1; j + k <= m && i + k <= n; k++) { n         ans += valid(i, j, i, j + k, i + k, j); n       } n       for (k = 1; j - k > 0 && i + k <= n; k++) { n         ans += valid(i, j, i, j - k, i + k, j); n       } n       k = 1; n       while (i - k > 0 && j + k <= m && j - k > 0) { n         ans += valid(i, j, i - k, j + k, i - k, j - k); n         k++; n       } n       k = 1; n       while (i + k <= n && j + k <= m && j - k > 0) { n         ans += valid(i, j, i + k, j + k, i + k, j - k); n         k++; n       } n       k = 1; n       while (j - k > 0 && i + k <= n && i - k > 0) { n         ans += valid(i, j, i + k, j - k, i - k, j - k); n         k++; n       } n       k = 1; n       while (j + k <= m && i + k <= n && i - k > 0) { n         ans += valid(i, j, i + k, j + k, i - k, j + k); n         k++; n       } n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const string FILENAME =  input ; n vector<pair<int, int> > best; n vector<int> a; n int main() { n   int n, m; n   cin >> n >> m; n   vector<int> has(2 * n, 0); n   vector<int> pr(2 * n, -1); n   vector<pair<int, int> > next(2 * n, {0, 0}); n   for (int i = 0; i < 2 * n; i++) { n     int t; n     cin >> t; n     a.push_back(t); n     next[i] = {-a[i], i}; n   } n   sort((next).begin(), (next).end()); n   for (int i = 0; i < m; i++) { n     int x, y; n     cin >> x >> y; n     x--; n     y--; n     pr[x] = y; n     pr[y] = x; n     if (a[x] > a[y]) { n       swap(x, y); n     } n     best.push_back({y, x}); n   } n   int ans; n   int cnt = 0; n   int t; n   cin >> t; n   if (t == 1) { n     for (int i = 0; i < m; i++) { n       cout << best[i].first + 1 << endl; n       cin >> ans; n       if (ans == -1) return 0; n       has[best[i].first] = 1; n       has[ans - 1] = 1; n     } n     for (int i = 0; i < 2 * n; i++) { n       if (has[next[i].second] == 0) { n         cout << next[i].second + 1 << endl; n         cin >> ans; n         if (ans == -1) return 0; n         has[ans - 1] = 1; n         has[next[i].second] = 1; n       } n     } n     return 0; n   } n   cin >> ans; n   ans--; n   has[ans] = 1; n   cnt++; n   while (pr[ans] != -1) { n     cout << pr[ans] + 1 << endl; n     cnt++; n     if (cnt == 2 * n) return 0; n     has[pr[ans]] = 1; n     cin >> ans; n     cnt++; n     if (ans == -1) return 0; n     ans--; n     has[ans] = 1; n   } n   for (int i = 0; i < m; i++) { n     if (has[best[i].first] == 0) { n       has[best[i].first] = 1; n       cout << best[i].first + 1 << endl; n       cnt++; n       if (cnt == 2 * n) return 0; n       cin >> ans; n       cnt++; n       if (ans == -1) return 0; n       ans--; n       has[ans] = 1; n     } n   } n   for (int i = 0; i < 2 * n; i++) { n     if (has[next[i].second] == 0) { n       cout << next[i].second + 1 << endl; n       cnt++; n       if (cnt == 2 * n) return 0; n       cin >> ans; n       cnt++; n       if (ans == -1) return 0; n       ans--; n       has[ans] = 1; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, k, i, j; n   bool flag, flag1, final_flag; n   string p, q; n   cin >> t; n   for (i = 0; i < t; i++) { n     map<char, int> m; n     final_flag = false; n     cin >> p >> q; n     for (j = 0; j < p.size(); j++) { n       if (m.find(p[j]) == m.end()) n         m[p[j]] = 1; n       else n         m[p[j]] += 1; n     } n     for (j = 0; j < q.size(); j++) { n       map<char, int> m1; n       flag1 = true; n       flag = true; n       if (m.find(q[j]) != m.end()) { n         k = j; n         for (k = j; k < p.size() + j; k++) { n           if (m.find(q[k]) == m.end()) { n             flag = false; n             break; n           } else { n             if (m1.find(q[k]) == m1.end()) n               m1[q[k]] = 1; n             else n               m1[q[k]] += 1; n           } n         } n         if (flag) { n           map<char, int>::iterator it; n           for (it = m.begin(); it != m.end(); it++) { n             if (m1.find(it->first) == m1.end()) { n               flag1 = false; n               break; n             } n             if (m1[it->first] != m[it->first]) { n               flag1 = false; n               break; n             } n           } n           if (flag1) final_flag = true; n         } n       } n       if (final_flag) break; n     } n     if (final_flag) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n const long long oo = 1e18; n const long long mod = 1e9 + 7; n const int INF = 1 << 30; n vector<pair<pair<int, long long>, int>> adj[N]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   ios_base::sync_with_stdio(0); n   int n, m, k; n   cin >> n >> m >> k; n   map<pair<int, int>, long long> edges; n   for (int i = 0; i < m; i++) { n     int u, v; n     long long w; n     cin >> u >> v >> w; n     edges[{u, v}] = w; n     adj[u].push_back({{v, w}, 0}); n     adj[v].push_back({{u, w}, 0}); n   } n   int ans = 0; n   for (int i = 0; i < k; i++) { n     int s; n     long long y; n     cin >> s >> y; n     adj[1].push_back({{s, y}, 1}); n   } n   priority_queue<pair<pair<int, long long>, int>, n                  vector<pair<pair<int, long long>, int>>, n                  greater<pair<pair<int, long long>, int>>> n       q; n   long long dis[N]; n   bool anagetHenaBeTrain[N]; n   for (int i = 0; i < N; i++) dis[i] = INF; n   memset(anagetHenaBeTrain, false, sizeof(anagetHenaBeTrain)); n   dis[1] = 0; n   q.push({{dis[1], 1}, 0}); n   while (q.size()) { n     auto top = q.top(); n     q.pop(); n     long long cost = top.first.first; n     int node = top.first.second; n     int type = top.second; n     if (cost > dis[node]) continue; n     for (auto v : adj[node]) { n       if (v.first.second + cost < dis[v.first.first]) { n         dis[v.first.first] = v.first.second + cost; n         anagetHenaBeTrain[v.first.first] = v.second; n         q.push({{dis[v.first.first], v.first.first}, v.second}); n       } else if (v.first.second + cost == dis[v.first.first]) { n         if (anagetHenaBeTrain[v.first.first] == 1 && v.second == 0) { n           anagetHenaBeTrain[v.first.first] = 0; n         } n       } n     } n   } n   for (int i = 1; i <= n; i++) n     if (anagetHenaBeTrain[i] == 1) ans++; n   cout << k - ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double EPS = 1E-9; n const int INF = (int)1E9; n const long long INF64 = (long long)1E18; n const long double PI = 2 * acos(.0); n int n, k; n string number; n int repla2[11]; n string construct(int ind) { n   string resp =   ; n   bool used[10005]; n   memset(used, false, sizeof(used)); n   for (int i = 0; i < (int)((number).size()); i++) { n     bool cent2 = 1; n     if (repla2[abs((number[i] -  0 ) - ind)] > 0 && ind <= (number[i] -  0 )) { n       repla2[abs((number[i] -  0 ) - ind)]--; n       char a =  0  + ind; n       used[i] = true; n       resp += a; n       cent2 = 0; n     } n     if (cent2) resp += number[i]; n   } n   for (int i = n - 1; i >= 0; i--) { n     bool cent2 = 1; n     if (!used[i] && repla2[abs((number[i] -  0 ) - ind)] > 0 && n         ind >= (number[i] -  0 )) { n       repla2[abs((number[i] -  0 ) - ind)]--; n       char a =  0  + ind; n       resp[i] = a; n       cent2 = 0; n     } n   } n   return resp; n } n int main() { n   cin >> n >> k >> number; n   string winner; n   int mini = INF; n   int ind = -1; n   int conts[11]; n   fill(conts, conts + 11, 0); n   for (int i = 0; i < (int)((number).size()); i++) { n     conts[number[i] -  0 ]++; n   } n   bool cent = 0; n   string resp2; n   for (int i = 0; i < (int)(10); i++) { n     int kk = k - conts[i]; n     if (kk <= 0) { n       cent = 1; n       cout << 0 << endl; n       cout << number << endl; n       break; n     } n     int temp = 0; n     fill(repla2, repla2 + 11, 0); n     for (int j = 1; j < (int)(10); j++) { n       int cont1 = i - j; n       int cont2 = i + j; n       if (cont2 < 10) { n         if (kk <= conts[cont2]) { n           temp += (kk * j); n           repla2[j] += kk; n           if (temp < mini) { n             ind = i; n             mini = temp; n             resp2 = construct(i); n           } else if (temp == mini) { n             string temp = construct(i); n             if (temp < resp2) resp2 = temp; n           } n           break; n         } else { n           temp += (conts[cont2] * j); n           kk -= conts[cont2]; n           repla2[j] += conts[cont2]; n         } n       } n       if (cont1 >= 0) { n         if (kk <= conts[cont1]) { n           temp += (kk * j); n           repla2[j] += kk; n           if (temp < mini) { n             mini = temp; n             resp2 = construct(i); n           } else if (temp == mini) { n             string temp = construct(i); n             if (temp < resp2) resp2 = temp; n           } n           break; n         } else { n           temp += (conts[cont1] * j); n           kk -= conts[cont1]; n           repla2[j] += conts[cont1]; n         } n       } n     } n   } n   bool used[10005]; n   memset(used, false, sizeof(used)); n   if (!cent) { n     cout << mini << endl; n     cout << resp2; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int MOD = 998244353; n int n, c, a[3005], cnt[3005], pw[3005], ipw1[3005], ans[3005]; n inline int mval(int x) { return x >= MOD ? x - MOD : x; } n inline void inc(int &x, int a) { (x += a) >= MOD && (x -= MOD); } n inline void dec(int &x, int a) { x = mval(MOD + x - a); } n inline int qpow(int x, int p) { n   int ret = 1; n   while (p) { n     if (p & 1) ret = 1ll * ret * x % MOD; n     p >>= 1, x = 1ll * x * x % MOD; n   } n   return ret; n } n namespace sub1 { n int f[3005][1 << 10], g[3005]; n inline void solve(void) { n   int u = (1 << c) - 1; n   g[0] = 1; n   ans[0] = pw[n] - 1; n   for (int t = 1; t * c <= n + 1; ++t) { n     for (int i = 1; i <= n; ++i) std::fill(f[i], f[i] + (1 << c), 0); n     for (int i = 1; i <= n; ++i) { n       inc(f[i][0], g[i - 1]); n       inc(f[i][1 << a[i]], g[i - 1]); n       for (int s = 0; s < u; ++s) n         inc(f[i][s], f[i - 1][s]), inc(f[i][s | (1 << a[i])], f[i - 1][s]); n     } n     for (int i = 0; i <= n; ++i) g[i] = f[i][u ^ (1 << a[i])]; n     for (int i = 0; i <= n; ++i) inc(ans[t], 1ll * g[i] * pw[n - i] % MOD); n   } n   for (int i = 0; i <= n; ++i) dec(ans[i], ans[i + 1]); n } n }  // namespace sub1 n namespace sub2 { n long long *f, *g, dp[2][3005], tr[3005][3005]; n inline void solve(void) { n   for (int i = 1; i <= n; ++i) { n     std::fill(cnt, cnt + c + 1, 0); n     int cur = 1, cc = 0; n     tr[i][i] = (c == 1); n     for (int j = i - 1; j; --j) { n       if (a[j] != a[i]) { n         cur = 1ll * ipw1[cnt[a[j]]] * cur % MOD; n         if (!cnt[a[j]]) ++cc; n         ++cnt[a[j]]; n         cur = 1ll * (pw[cnt[a[j]]] - 1) * cur % MOD; n       } n       tr[j][i] = (cc == c - 1 ? cur : 0); n     } n   } n   f = dp[0], g = dp[1]; n   f[0] = 1; n   ans[0] = pw[n] - 1; n   for (int t = 1; t * c <= n; ++t) { n     std::swap(f, g); n     std::fill(f, f + n + 1, 0); n     for (int j = 1; j <= n; ++j) n       if (g[j - 1]) n         for (int i = j; i <= n; ++i) f[i] += g[j - 1] * tr[j][i] % MOD; n     for (int i = 1; i <= n; ++i) f[i] %= MOD; n     for (int i = 0; i <= n; ++i) inc(ans[t], f[i] * pw[n - i] % MOD); n   } n   for (int i = 0; i <= n; ++i) dec(ans[i], ans[i + 1]); n } n }  // namespace sub2 n int main() { n   scanf( %d%d , &n, &c); n   pw[0] = 1; n   ipw1[0] = 1; n   for (int i = 1; i <= n; ++i) n     pw[i] = 2ll * pw[i - 1] % MOD, ipw1[i] = qpow(pw[i] - 1, MOD - 2); n   for (int i = 1; i <= n; ++i) scanf( %d , a + i), --a[i]; n   if (c <= 10) n     sub1::solve(); n   else n     sub2::solve(); n   for (int i = 0; i <= n; ++i) printf( %d  , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long power(long long x, long long y, long long p) { n   long long res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n const int N = 1e5 + 7; n const int xinc[] = {0, 0, 1, -1}; n const int yinc[] = {1, -1, 0, 0}; n const long double PI = acos(-1.0); n const double EPS = 1e-9; n string s; n long long a, n, sum[4007], ans; n map<long long, long long> m; n void solve() { n   cin >> a >> s; n   n = s.size(); n   for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + s[i - 1] -  0 ; n   long long t = 0; n   for (int i = 1; i <= n; i++) n     for (int j = i; j <= n; j++) { n       long long psum = sum[j] - sum[i - 1]; n       m[psum]++; n       t++; n     } n   for (auto i : m) { n     long long psum = i.first; n     if (psum != 0 && a != 0 && a % psum == 0) { n       long long cur = m[a / psum] * i.second; n       ans += cur; n     } n     if (a == 0) { n       if (psum == 0) n         ans += m[psum] * t; n       else n         ans += m[psum] * m[0]; n     } n   } n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t; n   t = 1; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int num[100008]; n int cnt1[100008]; n int cnt2[100008]; n int cnt; n struct node { n   int s, t; n } ans[100008]; n bool cmp(node a, node b) { n   if (a.s == b.s) return a.t < b.t; n   return a.s < b.s; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &num[i]); n     if (num[i] == 1) { n       cnt1[i] = cnt1[i - 1] + 1; n       cnt2[i] = cnt2[i - 1]; n     } else if (num[i] == 2) { n       cnt1[i] = cnt1[i - 1]; n       cnt2[i] = cnt2[i - 1] + 1; n     } n   } n   int acnt = 0; n   int bcnt = 0; n   int pre; n   int atmp; n   int btmp; n   for (int i = 1; i <= n; i++) { n     pre = 1; n     acnt = 0; n     bcnt = 0; n     while (true) { n       atmp = lower_bound(cnt1 + pre, cnt1 + 1 + n, i + cnt1[pre - 1]) - cnt1; n       btmp = lower_bound(cnt2 + pre, cnt2 + 1 + n, i + cnt2[pre - 1]) - cnt2; n       if (atmp < btmp) { n         acnt++; n         pre = atmp + 1; n         if (atmp == n) { n           if (num[n] != 2 && acnt > bcnt) { n             cnt++; n             ans[cnt].s = acnt; n             ans[cnt].t = i; n           } n           break; n         } n       } else if (atmp > btmp) { n         bcnt++; n         pre = btmp + 1; n         if (btmp == n) { n           if (num[n] != 1 && acnt < bcnt) { n             cnt++; n             ans[cnt].s = bcnt; n             ans[cnt].t = i; n           } n           break; n         } n       } else { n         break; n       } n     } n   } n   sort(ans + 1, ans + 1 + cnt, cmp); n   printf( %d n , cnt); n   for (int i = 1; i <= cnt; i++) { n     printf( %d %d n , ans[i].s, ans[i].t); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n; n   cin >> n; n   string s; n   cin >> s; n   bool ans = false; n   for (int i = 1; i <= n; ++i) n     for (int start = 0; start < n; ++start) { n       int jump = 0; n       int cur = start; n       while (cur < n && s[cur] ==  * ) { n         jump += 1; n         cur += i; n       } n       if (jump >= 5) ans = true; n     } n   if (ans) n     cout <<  yes  << endl; n   else n     cout <<  no  << endl; n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rnd(time(0)); n const double eps = 1e-10; n const long long inf = 0x3f3f3f3f3f3f3f3fLL; n const long long N = 2e5 + 5; n const long long MOD = 1e9 + 7; n long long pw(long long b, long long p) { n   long long res = 1; n   while (p > 0) { n     if (p & 1) res = res * b % MOD; n     b = b * b % MOD; n     p >>= 1; n   } n   return res; n } n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long n; n   cin >> n; n   vector<long long> h(n); n   long long sum = 0; n   for (long long i = 0; i < n; i++) { n     cin >> h[i]; n     sum += h[i]; n   } n   sum -= (n * (n - 1)) / 2; n   long long rem = sum % n; n   long long cnt = sum / n; n   for (long long i = 0; i < n; i++) { n     cout << i + cnt + (rem >= i + 1) <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100005; n long long n, m, a, d; n long long t[N]; n int main() { n   cin >> n >> m >> a >> d; n   for (int j = 1; j <= m; j++) { n     scanf( %lld , &t[j]); n   } n   t[m + 1] = 8e18; n   long long i = 1, ans = 0, last = -1; n   for (int j = 1; j <= m + 1; j++) { n     if (i > n) { n       if (j <= m && last < t[j]) { n         ans++; n         last = t[j] + d; n       } n       continue; n     } n     if (t[j] > last) { n       if (t[j] <= i * a) { n         ans++; n         last = t[j] + d; n         i = last / a + 1; n         continue; n       } n       long long u = d / a + 1; n       long long togo = min(n, t[j] / a); n       long long dis = ((togo - i) / u); n       ans += dis + 1; n       i += dis * u; n       last = i * a + d; n       if (j <= m && last < t[j]) { n         ans++; n         last = t[j] + d; n       } n       i = last / a + 1; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const double esp = 1e-8; n const int msz = 10000; n const int mod = 1e9 + 7; n struct Tr { n   char s[26]; n   int len, l; n }; n Tr s[111]; n bool vis[26]; n int main() { n   char str[1111]; n   int n, ans; n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     scanf( %s , str); n     s[i].len = strlen(str); n     s[i].l = 0; n     memset(vis, 0, sizeof(vis)); n     for (int j = 0; j < s[i].len; ++j) { n       if (!vis[str[j] -  a ]) { n         vis[str[j] -  a ] = 1; n         s[i].s[s[i].l++] = str[j]; n       } n     } n   } n   int mx = 0; n   for (int i =  a ; i <=  z ; ++i) { n     for (int j = i; j <=  z ; ++j) { n       ans = 0; n       for (int k = 0; k < n; ++k) { n         if (s[k].l == 1 && (s[k].s[0] == i || s[k].s[0] == j)) n           ans += s[k].len; n         else if (s[k].l == 2 && ((s[k].s[0] == i && s[k].s[1] == j) || n                                  (s[k].s[1] == i && s[k].s[0] == j))) n           ans += s[k].len; n       } n       mx = max(mx, ans); n     } n   } n   printf( %d n , mx); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e1 + 5; n int a[N][N], pos[N][N], last[N * N]; n double ev[N * N], reg[N * N]; n int main() { n   for (int i = 0; i < 10; i++) { n     for (int j = 0; j < 10; j++) { n       scanf( %d , &a[i][j]); n       if (i % 2 == 0) { n         pos[i][j] = 10 * i + j; n       } else { n         pos[i][j] = 10 * i + 9 - j; n       } n       last[pos[i][j]] = pos[i - a[i][j]][j]; n     } n   } n   ev[0] = 0; n   for (int i = 1; i < 100; i++) { n     double sum = 0; n     int cnt = 0; n     for (int j = i - 1; j >= max(i - 6, 0); j--) { n       sum += ev[j]; n       cnt++; n     } n     ev[i] = 1 + (1.0 * sum / 6); n     ev[i] *= 6.0 / cnt; n     reg[i] = ev[i]; n     ev[i] = min(ev[i], reg[last[i]]); n   } n   printf( %.7f n , ev[99]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int n, m, cnt = 0, k, cntt = 0, cnts = 0; n long long int v[100001]; n bool vis[100001], ans[100001]; n long long int cnte[100001]; n int main() { n   cin >> n >> m; n   memset(vis, false, sizeof(vis)); n   memset(cnte, 0, sizeof(cnte)); n   for (int i = 1; i <= m; i++) { n     cin >> v[i]; n     cnte[v[i]]++; n     if (vis[v[i]] == false) { n       vis[v[i]] = true; n       cnt++; n     } n     if (cnt == n) { n       ans[i] = 1; n       for (int j = 1; j <= n; j++) { n         if (cnte[j] > 1) { n           cnte[j]--; n         } else { n           cnt--; n           cnte[j]--; n           vis[j] = false; n         } n       } n     } else { n       ans[i] = 0; n     } n   } n   for (int i = 1; i <= m; i++) { n     cout << ans[i]; n   } n } n


#include <bits/stdc++.h> n int a, b, c, d, h; n int main() { n   scanf( %d %d %d %d , &a, &b, &c, &d); n   h = a + 8 * c; n   if (h >= b) { n     printf( 0 ); n     return 0; n   } n   if (c <= d) { n     printf( -1 ); n     return 0; n   } n   printf( %d , n          (b - h) / (12 * (c - d)) + (((b - h) % (12 * (c - d)) == 0) ? 0 : 1)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using vi = vector<int>; n void solve() { n   int n; n   cin >> n; n   vector<int> v(n); n   for (int i = 0; i < n; i++) { n     cin >> v[i]; n   } n   if (count(v.begin(), v.end(), 1) == 1) { n     cout << 0 << endl; n     return; n   } n   int s, e; n   for (s = 0; s < n; s++) { n     if (v[s] == 1) { n       break; n     } n   } n   for (e = n - 1; e >= 0; e--) { n     if (v[e] == 1) { n       break; n     } n   } n   int ans = 0; n   for (int i = s; i <= e; i++) { n     if (v[i] == 0) { n       ans++; n     } n   } n   cout << ans << endl; n   return; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int cnt[1 << 14]; n signed main() { n   ios_base ::sync_with_stdio(false); n   cin.tie(0); n   int n, k, maxn = 0; n   cin >> n >> k; n   for (int i = 0; i < n; ++i) { n     int a; n     cin >> a; n     maxn = max(maxn, a); n     ++cnt[a]; n   } n   long long ans = 0; n   if (k == 0) { n     for (int i = 0; i <= maxn; ++i) ans += cnt[i] * (cnt[i] - 1LL) / 2; n     cout << ans <<   n ; n     return 0; n   } n   int l = 32 - __builtin_clz(max(1, maxn)); n   for (int i = 0; i < (1 << l); ++i) { n     if (__builtin_popcount(i) != l - k) continue; n     for (int j = 0; j <= maxn; ++j) n       ans += 1LL * cnt[j] * cnt[(j & i) | (~j & ~i & ((1 << l) - 1))]; n   } n   cout << ans / 2 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   char s[1000]; n   gets(s); n   int a[1000] = {0}; n   for (int i = 0; i < strlen(s); i++) { n     if (s[i] <=  z  && s[i] >=  a ) a[s[i]]++; n   } n   int m = 0; n   for (int i = 0; i < 1000; i++) n     if (a[i]) m++; n   cout << m; n } n


#include <bits/stdc++.h> n using namespace std; n struct Lem { n   int m, v, id; n   bool operator<(Lem b) const { return m < b.m || (m == b.m && v < b.v); } n }; n int n, k, h; n Lem a[(100000 + 10)]; n bool can(long double t) { n   int j = k; n   for (int i(n - 1), _l(0); i >= _l; --i) { n     if (j > 0 && (long double)j * h / a[i].v - t <= -1e-7) j--; n   } n   return j == 0; n } n void putAns(long double t) { n   int ans[(100000 + 10)]; n   int j = k; n   for (int i(n - 1), _l(0); i >= _l; --i) { n     if (j > 0 && (long double)j * h / a[i].v - t <= -1e-7) ans[--j] = a[i].id; n   } n   for (int i(0), _n(k - 1); i < _n; ++i) printf( %d  , ans[i]); n   printf( %d n , (ans[k - 1])); n } n int main() { n   scanf( %d , &(n)), scanf( %d , &(k)), scanf( %d , &(h)); n   for (int i(0), _n(n); i < _n; ++i) scanf( %d , &(a[i].m)), a[i].id = i + 1; n   for (int i(0), _n(n); i < _n; ++i) scanf( %d , &(a[i].v)); n   sort(a, a + n); n   long double l = 0, r = 1e10; n   int cnt = 100; n   while (cnt--) { n     long double mid = (l + r) / 2.0; n     if (can(mid)) n       r = mid; n     else n       l = mid; n   } n   putAns(r); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[200000]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   int n; n   cin >> n; n   long long prev = 0; n   long long last = 1e18; n   for (int i = 0; i < n / 2; ++i) { n     long long x; n     cin >> x; n     prev = max(prev, x - last); n     last = x - prev; n     a[i] = prev; n     a[n - i - 1] = last; n   } n   for (int i = 0; i < n; ++i) { n     cout << a[i] <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e3 + 5; n char a[N][N]; n void fileIO() {} n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   fileIO(); n   int h, w; n   int tot = 0; n   cin >> h >> w; n   for (int i = 0; i < h; i++) n     for (int j = 0; j < w; j++) { n       cin >> a[i][j]; n       if (a[i][j] ==  * ) tot++; n     } n   int now = 0; n   int curi, curj; n   for (int i = 1; i < h - 1; i++) { n     for (int j = 1; j < w - 1; j++) { n       now = 0; n       if (a[i][j] ==  *  and a[i + 1][j] ==  *  and a[i - 1][j] ==  *  and n           a[i][j + 1] ==  *  and a[i][j - 1] ==  * ) { n         curi = i, curj = j; n         while (a[curi + 1][j] ==  * ) { n           now++; n           curi++; n         } n         curi = i, curj = j; n         while (a[curi - 1][j] ==  * ) { n           now++; n           curi--; n         } n         curi = i, curj = j; n         while (a[i][curj + 1] ==  * ) { n           now++; n           curj++; n         } n         curi = i, curj = j; n         while (a[i][curj - 1] ==  * ) { n           now++; n           curj--; n         } n         if (now + 1 == tot) { n           cout <<  YES ; n           exit(0); n         } n       } n     } n   } n   cout <<  NO ; n   return 0; n } n


#include <iostream> n #include <vector> n #include <algorithm> n #include <string> n #include <map> n #include <cstdio> n #include <utility>  n #include <queue> n #include <math.h> n #include <set> n #include <bitset> n #include <cmath> n #include <bitset> n #include <stack> n #include <cstring> n #include <deque> n using namespace std; n typedef long long ll; n typedef pair<int, int> pii; n  n int main() { n     ios_base::sync_with_stdio(0); n     cin.tie(NULL); n     int t; cin >> t; n     while(t--) { n         int n, m; cin >> n >> m; n         vector<ll> k(n + 1); n         vector<ll> c(m + 1); n         for(int i = 1; i <= n; i++) cin >> k[i]; n         for(int i = 1; i <= m; i++) cin >> c[i]; n         int idx = 1; n         sort(k.begin(), k.end()); n         ll ans = 0; n         for(int i = n; i >= 1; i--) { n             if(idx > k[i] || c[k[i]] < c[idx]) ans += c[k[i]]; n             else { n                 ans += c[idx]; n                 idx++; n             } n         } n         cout << ans <<   n ; n     } n }


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n long long mod = 1e9 + 7; n vector<long long> g[27]; n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   string s1, s2; n   cin >> s1 >> s2; n   long long n1 = s1.size(), n2 = s2.size(), i, j; n   for (i = 0; i < n1; ++i) g[s1[i] -  a ].push_back(i); n   long long cnt = 1, prev = -1, it, sz; n   for (i = 0; i < n2; ++i) { n     j = s2[i] -  a ; n     sz = g[j].size(); n     if (sz == 0) return cout << -1, 0; n     it = upper_bound(g[j].begin(), g[j].end(), prev) - g[j].begin(); n     if (it == sz) it = 0, ++cnt; n     prev = g[j][it]; n   } n   cout << cnt <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dir[4][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}}; n int n, m, k; n bool isValid(int i, int j) { return i >= 0 && j >= 0 && i < n && j < m; } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m >> k; n   int freex = -1, freey = -1, remains = 0; n   char grid[n][m]; n   bool visited[n][m]; n   memset(visited, false, sizeof visited); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       cin >> grid[i][j]; n       if (grid[i][j] ==  . ) { n         remains++; n         freex = i; n         freey = j; n       } n     } n   if (k == 0) { n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < n; j++) { n         cout << grid[i][j]; n       } n       cout <<   n ; n     } n     return 0; n   } n   queue<pair<int, int>> q; n   q.push({freex, freey}); n   int count = 0; n   while (!q.empty()) { n     auto tmp = q.front(); n     q.pop(); n     int x = tmp.first; n     int y = tmp.second; n     if (visited[x][y]) continue; n     visited[x][y] = true; n     count++; n     if (count == remains - k) break; n     for (int i = 0; i < 4; i++) { n       int nx = x + dir[i][0]; n       int ny = y + dir[i][1]; n       if (isValid(nx, ny) && grid[nx][ny] ==  .  && !visited[nx][ny]) n         q.push({nx, ny}); n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (!visited[i][j] && grid[i][j] ==  . ) n         cout <<  X ; n       else if (grid[i][j] ==  # ) n         cout <<  # ; n       else n         cout <<  . ; n     } n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int ar[30]; n int br[30]; n unordered_map<long, long> nm; n int main() { n   std::ios::sync_with_stdio(false); n   ; n   int n; n   std::cin >> n; n   for (int i = 0; i < n; i++) { n     std::cin >> ar[i]; n     br[i] = ar[i]; n     nm[ar[i]] = i; n   } n   sort(ar, ar + n); n   for (int i = 0; i < n - 1; i++) { n     br[nm[ar[i]]] = ar[i + 1]; n   } n   br[nm[ar[n - 1]]] = ar[0]; n   for (int i = 0; i < n; i++) { n     std::cout << br[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}; n int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; n long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); } n long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; } n long long power(long long a, long long b, long long ret = 1LL) { n   while (b--) ret = (ret * a); n   return ret; n } n char a[105]; n int main() { n   long long n, k; n   cin >> n >> k; n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     int cnt = 0; n     long long x; n     cin >> x; n     while (x > 0) { n       if (x % 10 == 7 || x % 10 == 4) { n         cnt++; n       } n       x /= 10; n     } n     if (cnt <= k) ans++; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC optimize( -ffloat-store ) n #pragma GCC optimize( -fno-defer-pop ) n long long int power(long long int a, long long int b, long long int m) { n   if (b == 0) return 1; n   if (b == 1) return a % m; n   long long int t = power(a, b / 2, m) % m; n   t = (t * t) % m; n   if (b & 1) t = ((t % m) * (a % m)) % m; n   return t; n } n long long int modInverse(long long int a, long long int m) { n   return power(a, m - 2, m); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int q; n   cin >> q; n   while (q--) { n     long long int i, j, k, l, n; n     cin >> n >> k; n     long long int ar[n + 1]; n     for (i = 1; i <= n; i++) { n       cin >> ar[i]; n     } n     vector<long long int> an; n     long long int s = 0; n     for (i = 1; i <= n; i++) { n       s += ar[i]; n       if (s % 2) { n         an.push_back(i); n         s = 0; n       } else if (i == n) { n         if (an.size() > 0) { n           an.pop_back(); n           an.push_back(i); n         } n       } n     } n     if (an.size() < k) { n       cout <<  NO  n            <<   n ; n     } else { n       long long int v = (an.size() - k); n       if (v % 2 == 0) { n         cout <<  YES  n              <<   n ; n         i = v; n         while (i < an.size()) { n           cout << an[i] <<    ; n           i++; n         } n         cout <<   n ; n       } else { n         cout <<  NO  n              <<   n ; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 250 + 7; n int a[MAXN][MAXN], ans[MAXN][MAXN]; n bool rmax[MAXN * MAXN], cmax[MAXN * MAXN], vis[MAXN * MAXN]; n bool canr[MAXN], canc[MAXN]; n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       scanf( %d , &a[i][j]); n     } n   for (int i = 1; i <= n; i++) { n     int MAX = 0; n     for (int j = 1; j <= m; j++) MAX = max(MAX, a[i][j]); n     rmax[MAX] = 1; n   } n   for (int j = 1; j <= m; j++) { n     int MAX = 0; n     for (int i = 1; i <= n; i++) MAX = max(MAX, a[i][j]); n     cmax[MAX] = 1; n   } n   int x = 0, y = 0; n   queue<pair<int, int> > pos; n   for (int num = n * m; num >= 1; num--) { n     x += rmax[num]; n     y += cmax[num]; n     if (rmax[num] || cmax[num]) { n       ans[x][y] = num; n     } else { n       pair<int, int> p = pos.front(); n       pos.pop(); n       ans[p.first][p.second] = num; n     } n     if (rmax[num]) { n       canr[x] = 1; n       for (int j = y - 1; j >= 1; j--) n         if (canc[j]) pos.push({x, j}); n       for (int j = y + 1; j <= m; j++) n         if (canc[j]) pos.push({x, j}); n     } n     if (cmax[num]) { n       canc[y] = 1; n       for (int i = x - 1; i >= 1; i--) n         if (canr[i]) pos.push({i, y}); n       for (int i = x + 1; i <= n; i++) n         if (canr[i]) pos.push({i, y}); n     } n   } n   for (int i = 1; i <= n; i++, puts(  )) n     for (int j = 1; j <= m; j++) printf( %d  , ans[i][j]); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   long long i, j, k, n, t, x, l, r, m; n   cin >> t; n   while (t--) { n     cin >> n; n     k = n / 2; n     long long sum = 0, y, cnt = 1; n     x = 3; n     y = 1; n     while (k--) { n       sum += ((x * 2 * cnt) + (y * 2 * cnt)); n       x += 2; n       y += 2; n       cnt++; n     } n     cout << sum <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n ll MOD = 1000000007; n ll mod = 998244353; n int inf = 1000001000; n ll INF = 1e18 + 5; n int main() { n   std::cin.tie(nullptr); n   std::ios::sync_with_stdio(false); n   int t; n   cin >> t; n   for (int(_) = 0; (_) < (t); (_)++) { n     int n; n     cin >> n; n     if (n == 1) n       cout <<  FastestFinger  << endl; n     else if (n == 2) n       cout <<  Ashishgup  << endl; n     else { n       if (n % 2) n         cout <<  Ashishgup  << endl; n       else { n         int cnt = 0; n         while (n % 2 == 0) { n           n /= 2; n           cnt++; n         } n         if (n == 1) { n           cout <<  FastestFinger  << endl; n         } else { n           if (cnt > 1) n             cout <<  Ashishgup  << endl; n           else { n             int q = 0; n             for (ll i = 3; i * i <= n; i += 2) { n               if (n % i == 0) { n                 cout <<  Ashishgup  << endl; n                 q++; n                 break; n               } n             } n             if (q == 0) cout <<  FastestFinger  << endl; n           } n         } n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = (int)1e9 + 7; n const int FFTMOD = 119 << 23 | 1; n const int INF = (int)1e9 + 23111992; n const long long LINF = (long long)1e18 + 23111992; n const long double PI = acos((long double)-1); n const long double EPS = 1e-9; n inline long long gcd(long long a, long long b) { n   long long r; n   while (b) { n     r = a % b; n     a = b; n     b = r; n   } n   return a; n } n inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n inline long long fpow(long long n, long long k, int p = MOD) { n   long long r = 1; n   for (; k; k >>= 1) { n     if (k & 1) r = r * n % p; n     n = n * n % p; n   } n   return r; n } n template <class T> n inline int chkmin(T& a, const T& val) { n   return val < a ? a = val, 1 : 0; n } n template <class T> n inline int chkmax(T& a, const T& val) { n   return a < val ? a = val, 1 : 0; n } n inline unsigned long long isqrt(unsigned long long k) { n   unsigned long long r = sqrt(k) + 1; n   while (r * r > k) r--; n   return r; n } n inline long long icbrt(long long k) { n   long long r = cbrt(k) + 1; n   while (r * r * r > k) r--; n   return r; n } n inline void addmod(int& a, int val, int p = MOD) { n   if ((a = (a + val)) >= p) a -= p; n } n inline void submod(int& a, int val, int p = MOD) { n   if ((a = (a - val)) < 0) a += p; n } n inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; } n inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); } n inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; } n inline int sign(long double x, long double y) { return sign(x - y); } n mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count()); n inline int myrand() { return abs((int)mt()); } n const int maxn = 2e6 + 5; n int fac[maxn]; n int ifac[maxn]; n int binom(int a, int b) { n   if (a > b) return 0; n   return mult(fac[b], mult(ifac[a], ifac[b - a])); n } n void chemthan() { n   fac[0] = 1; n   for (int i = (1); i < (maxn); ++i) fac[i] = mult(fac[i - 1], i); n   for (int i = (0); i < (maxn); ++i) ifac[i] = inv(fac[i]); n   int n, m, a, b; n   cin >> n >> m >> a >> b; n   int res = 0; n   for (int k = (1); k < (n); ++k) { n     int coef = binom(k - 1, m - 1); n     int d = n - 1 - k; n     int coef2 = !d ? 1 : mult(n - d, fpow(n, d - 1)); n     coef = mult(coef, fac[k - 1]); n     addmod(res, mult(coef, mult(binom(k - 1, n - 2), n                                 mult(coef2, fpow(m, n - k - 1))))); n   } n   cout << res <<   n ; n } n int main(int argc, char* argv[]) { n   ios_base::sync_with_stdio(0), cin.tie(0); n   if (argc > 1) { n     assert(freopen(argv[1],  r , stdin)); n   } n   if (argc > 2) { n     assert(freopen(argv[2],  wb , stdout)); n   } n   chemthan(); n   cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ; n   return 0; n } n