#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n const int N = 1000005; n const double PI = 4 * atan(1); n const double eps = 1e-7; n long long x, y, z; n int main() { n   ios::sync_with_stdio(0); n   cin >> x >> y >> z; n   long long ans = 0; n   ans = x / z + y / z; n   long long a, b; n   a = x; n   b = y; n   long long c = (z - x % z) % z; n   long long res = 0; n   if (b >= c && ((a + c) / z + (b - c) / z) > ans) { n     ans = ((a + c) / z + (b - c) / z); n     res = c; n   } n   a = x; n   b = y; n   c = (z - y % z) % z; n   if (a >= c && ((a - c) / z + (b + c) / z) > ans) { n     ans = ((a + c) / z + (b - c) / z); n     res = c; n   } else if (a >= c && ((a - c) / z + (b + c) / z) == ans) { n     res = min(res, c); n   } n   cout << ans <<     << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n int a[N], b[N], d[N], used[N], dis[N], ANS[N], dlt[N]; n int n, m, Y0, Y1, lft, ans; n vector<int> ch[N], fa[N]; n priority_queue<pair<int, int>, vector<pair<int, int> >, n                greater<pair<int, int> > > n     pq; n int ABS(int x) { n   if (x >= 0) n     return x; n   else n     return -x; n } n int lnk(int x, int y) { n   ch[x].push_back(y); n   fa[y].push_back(x); n   return ABS(b[x] - a[y]); n } n int avi(int x) { n   int ret = 0; n   for (int i = 0; i < int(fa[x].size()); i++) { n     int to = fa[x][i]; n     if (used[to] == -1 || used[to] == dis[x]) ret++; n   } n   return ret; n } n int main() { n   scanf( %d%d%d%d , &n, &m, &Y0, &Y1); n   for (int i = 1; i <= n; i++) scanf( %d , a + i); n   for (int i = 1; i <= m; i++) scanf( %d , b + i); n   for (int i = 1; i <= m; i++) used[i] = -1; n   for (int i = 1; i <= n; i++) { n     int x = lower_bound(b + 1, b + 1 + m, a[i]) - b - 1; n     int y = x + 1; n     if (x == 0) n       dis[i] = lnk(y, i); n     else if (y == m + 1) n       dis[i] = lnk(x, i); n     else if (a[i] - b[x] < b[y] - a[i]) n       dis[i] = lnk(x, i); n     else if (a[i] - b[x] > b[y] - a[i]) n       dis[i] = lnk(y, i); n     else { n       dis[i] = lnk(x, i); n       lnk(y, i); n     } n     if (avi(i) == 1) { n       dlt[i] = 1; n       pq.push(make_pair(dis[i], i)); n     } n   } n   lft = n; n   while (!pq.empty()) { n     int D = pq.top().first, x = pq.top().second, y; n     pq.pop(); n     lft--; n     if (avi(x) == 0) continue; n     for (int i = 0; i < int(fa[x].size()); i++) { n       y = fa[x][i]; n       if (used[y] == -1 || used[y] == D) break; n     } n     used[y] = D; n     ANS[y]++; n     for (int i = 0; i < int(ch[y].size()); i++) { n       int to = ch[y][i]; n       if (dis[to] != D && !dlt[to] && avi(to) == 1) { n         dlt[to] = 1; n         pq.push(make_pair(dis[to], to)); n       } n     } n   } n   for (int i = 1; i <= m; i++) ans += ANS[i]; n   ans += lft; n   printf( %d n , n - ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n std::mt19937 rnd( n     (int)std::chrono::steady_clock::now().time_since_epoch().count()); n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n const int MOD = 1000000007; n void inc(int& a, int b) { n   if ((a += b) >= MOD) a -= MOD; n } n void dec(int& a, int b) { inc(a, MOD - b); } n int qx, qy, xdim, ydim; n int inv[6 + 1]; n int calcformula(int x, int y) { n   int ret = max(max((x + 1) / 2, (y + 1) / 2), (x + y + 2) / 3); n   if (ret % 2 != (x + y) % 2) ++ret; n   return ret; n } n int calc(int x, int y) { n   if (x == 1 && y == 0 || x == 0 && y == 1) return 3; n   if (x == 1 && y == 1) return xdim > 3 || ydim > 3 ? 4 : 0; n   if (x == 2 && y == 2) return 4; n   if (x == 3 && y == 0 && xdim == 4 || x == 0 && y == 3 && ydim == 4) return 5; n   return calcformula(x, y); n } n int divup(int num, int den) { n   if (den < 0) num = -num, den = -den; n   return num >= 0 ? (num + den - 1) / den : num / den; n } n int divdn(int num, int den) { n   if (den < 0) num = -num, den = -den; n   return num >= 0 ? num / den : (num - den + 1) / den; n } n int makesamepar(int a, int b) { n   if ((a & 1) != (b & 1)) ++a; n   return a; n } n int cnt(int lo, int hi) { return hi - lo + 1; } n int sum(int lo, int hi) { n   return (long long)(lo + hi) * (hi - lo + 1) / 2 % MOD; n } n int sumsq(int n) { n   return (long long)n * (n + 1) % MOD * (2 * n + 1) % MOD * inv[6] % MOD; n } n int sumsq(int lo, int hi) { n   int ret = 0; n   inc(ret, sumsq(hi)); n   if (lo != 0) dec(ret, sumsq(lo - 1)); n   return ret; n } n int calcsumstupid(int xlim, int ylim) { n   int ret = 0; n   for (int x = (0); x <= (xlim); ++x) n     for (int y = (0); y <= (ylim); ++y) inc(ret, calc(x, y)); n   return ret; n } n int calcsum(int xlim, int ylim) { n   int ret = 0; n   for (int dx = (0); dx < (12); ++dx) n     if (dx <= xlim) n       for (int dy = (0); dy < (6); ++dy) n         if (dy <= ylim) { n           int A = (xlim - dx) / 12, B = (ylim - dy) / 6, n               D = divup(divup(dx, 2) - divup(dx + dy, 3), 2) - 1, n               E = makesamepar(divup(dx, 2), dx + dy); n           int cur = 0; n           { n             int xlo = max(0, B - D), xhi = A, ylo = 0, yhi = B; n             if (xlo <= xhi && ylo <= yhi) { n               cur = (cur + (long long)cnt(xlo, xhi) * cnt(ylo, yhi) % MOD * E) % n                     MOD; n               cur = (cur + (long long)cnt(ylo, yhi) * sum(xlo, xhi) % MOD * 6) % n                     MOD; n             } n           } n           { n             int xlo = max(0, -D), xhi = min(A, B - D - 1); n             if (xlo <= xhi) { n               cur = (cur + (long long)cnt(xlo, xhi) * E % MOD * (D + 1)) % MOD; n               cur = (cur + (long long)sum(xlo, xhi) * E) % MOD; n               cur = (cur + (long long)sum(xlo, xhi) * 6 % MOD * (D + 1)) % MOD; n               cur = (cur + (long long)sumsq(xlo, xhi) * 6) % MOD; n             } n           } n           inc(ret, cur); n         } n   for (int dx = (0); dx < (12); ++dx) n     if (dx <= xlim) n       for (int dy = (0); dy < (6); ++dy) n         if (dy <= ylim) { n           int A = (xlim - dx) / 12, B = (ylim - dy) / 6, n               C = divup(divup(dx, 2) - divup(dx + dy, 3), 2), n               D = divup(dx + dy, 3) - divup(dy, 2), n               E = makesamepar(divup(dx + dy, 3), dx + dy); n           int cur = 0; n           { n             int xlo = max(0, divup(B - D, 4)), xhi = A, ylo = 0, yhi = B; n             if (xlo <= xhi && ylo <= yhi) { n               cur = (cur + (long long)cnt(xlo, xhi) * cnt(ylo, yhi) % MOD * E) % n                     MOD; n               cur = (cur + (long long)cnt(ylo, yhi) * sum(xlo, xhi) % MOD * 4) % n                     MOD; n               cur = (cur + (long long)cnt(xlo, xhi) * sum(ylo, yhi) % MOD * 2) % n                     MOD; n             } n           } n           { n             int xlo = max(0, divup(-D, 4)), xhi = min(A, divup(B - D, 4) - 1); n             if (xlo <= xhi) { n               cur = (cur + (long long)cnt(xlo, xhi) * E % MOD * (D + 1)) % MOD; n               cur = (cur + (long long)sum(xlo, xhi) * E % MOD * 4) % MOD; n               cur = (cur + (long long)sumsq(xlo, xhi) * 16) % MOD; n               cur = (cur + (long long)sum(xlo, xhi) * (D + 1) % MOD * 4) % MOD; n               cur = (cur + (long long)sumsq(xlo, xhi) * 16) % MOD; n               cur = (cur + (long long)sum(xlo, xhi) * (2 * D + 1) % MOD * 4) % n                     MOD; n               cur = (cur + (long long)cnt(xlo, xhi) * D % MOD * (D + 1)) % MOD; n             } n           } n           { n             int xlo = max(0, max(B - C + 1, divup(B - D, 4))), xhi = A, ylo = 0, n                 yhi = B; n             if (xlo <= xhi && ylo <= yhi) { n               cur = (cur - n                      (long long)cnt(xlo, xhi) * cnt(ylo, yhi) % MOD * E % MOD + n                      MOD) % n                     MOD; n               cur = (cur - n                      (long long)cnt(ylo, yhi) * sum(xlo, xhi) % MOD * 4 % MOD + n                      MOD) % n                     MOD; n               cur = (cur - n                      (long long)cnt(xlo, xhi) * sum(ylo, yhi) % MOD * 2 % MOD + n                      MOD) % n                     MOD; n             } n           } n           { n             int xlo = max(0, max(1 - C, divup(C - D - 1, 3))), n                 xhi = min(A, B - C); n             if (xlo <= xhi) { n               cur = (cur - (long long)cnt(xlo, xhi) * E % MOD * C % MOD + MOD) % n                     MOD; n               cur = (cur - (long long)sum(xlo, xhi) * E % MOD + MOD) % MOD; n               cur = (cur - (long long)sumsq(xlo, xhi) * 4 % MOD + MOD) % MOD; n               cur = (cur - (long long)sum(xlo, xhi) * C % MOD * 4 % MOD + MOD) % n                     MOD; n               cur = (cur - (long long)sumsq(xlo, xhi) % MOD + MOD) % MOD; n               cur = (cur - (long long)sum(xlo, xhi) * (2 * C - 1) % MOD + MOD) % n                     MOD; n               cur = (cur - (long long)cnt(xlo, xhi) * (C - 1) % MOD * C % MOD + n                      MOD) % n                     MOD; n             } n           } n           { n             int xlo = max(0, divup(-D, 4)), n                 xhi = min(A, min(divup(B - D, 4) - 1, divup(C - D - 1, 3) - 1)); n             if (xlo <= xhi) { n               cur = (cur - (long long)cnt(xlo, xhi) * E % MOD * (D + 1) % MOD + n                      MOD) % n                     MOD; n               cur = (cur - (long long)sum(xlo, xhi) * E % MOD * 4 % MOD + MOD) % n                     MOD; n               cur = (cur - (long long)sumsq(xlo, xhi) * 16 % MOD + MOD) % MOD; n               cur = (cur - (long long)sum(xlo, xhi) * (D + 1) % MOD * 4 % MOD + n                      MOD) % n                     MOD; n               cur = (cur - (long long)sumsq(xlo, xhi) * 16 % MOD + MOD) % MOD; n               cur = (cur - n                      (long long)sum(xlo, xhi) * (2 * D + 1) % MOD * 4 % MOD + n                      MOD) % n                     MOD; n               cur = (cur - (long long)cnt(xlo, xhi) * D % MOD * (D + 1) % MOD + n                      MOD) % n                     MOD; n             } n           } n           inc(ret, cur); n         } n   for (int dx = (0); dx < (6); ++dx) n     if (dx <= xlim) n       for (int dy = (0); dy < (12); ++dy) n         if (dy <= ylim) { n           int A = (xlim - dx) / 6, B = (ylim - dy) / 12, n               C = divdn(divup(dx + dy, 3) - divup(dy, 2), 2) + 1, n               E = makesamepar(divup(dy, 2), dx + dy); n           int cur = 0; n           { n             int xlo = 0, xhi = min(A, -C), ylo = 0, yhi = B; n             if (xlo <= xhi && ylo <= yhi) { n               cur = (cur + (long long)cnt(xlo, xhi) * cnt(ylo, yhi) % MOD * E) % n                     MOD; n               cur = (cur + (long long)cnt(xlo, xhi) * sum(ylo, yhi) % MOD * 6) % n                     MOD; n             } n           } n           { n             int xlo = max(0, -C + 1), xhi = min(A, B - C); n             if (xlo <= xhi) { n               cur = (cur + (long long)cnt(xlo, xhi) * E % MOD * (B - C + 1)) % n                     MOD; n               cur = (cur - (long long)sum(xlo, xhi) * E % MOD + MOD) % MOD; n               cur = (cur + (long long)cnt(xlo, xhi) * (C + B) % MOD * n                                (B - C + 1) % MOD * 3) % n                     MOD; n               cur = (cur - n                      (long long)sum(xlo, xhi) * (2 * C - 1) % MOD * 3 % MOD + n                      MOD) % n                     MOD; n               cur = (cur - (long long)sumsq(xlo, xhi) * 3 % MOD + MOD) % MOD; n             } n           } n           inc(ret, cur); n         } n   vector<pair<int, int>> special; n   special.push_back(make_pair(1, 0)); n   special.push_back(make_pair(0, 1)); n   special.push_back(make_pair(1, 1)); n   special.push_back(make_pair(3, 0)); n   special.push_back(make_pair(0, 3)); n   special.push_back(make_pair(2, 2)); n   for (int i = (0); i < (((int)(special).size())); ++i) { n     int x, y; n     tie(x, y) = special[i]; n     if (x <= xlim && y <= ylim) { n       dec(ret, calcformula(x, y)); n       inc(ret, calc(x, y)); n     } n   } n   return ret; n } n void precalc() { n   inv[1] = 1; n   for (int i = (2); i <= (6); ++i) n     inv[i] = (long long)(MOD - MOD / i) * inv[MOD % i] % MOD; n } n int solve() { n   int ret = 0; n   inc(ret, calcsum(xdim - 1, ydim - 1)); n   dec(ret, calcsum(xdim - 1, qy - 1)); n   dec(ret, calcsum(qx - 1, ydim - 1)); n   inc(ret, calcsum(qx - 1, qy - 1)); n   return ret; n } n void run() { n   scanf( %d%d%d%d , &qx, &qy, &xdim, &ydim); n   --qx, --qy; n   printf( %d n , solve()); n } n void verifycalc() { n   for (xdim = 3; xdim <= 20; ++xdim) n     for (ydim = 3; ydim <= 20; ++ydim) { n       vector<vector<int>> d(xdim, vector<int>(ydim, INT_MAX)); n       queue<pair<int, int>> q; n       d[0][0] = 0, q.push(make_pair(0, 0)); n       while (!q.empty()) { n         int x, y; n         tie(x, y) = q.front(); n         q.pop(); n         for (int dx = (-2); dx <= (+2); ++dx) n           for (int dy = (-2); dy <= (+2); ++dy) n             if (dx * dx + dy * dy == 5) { n               int nx = x + dx, ny = y + dy; n               if (nx < 0 || nx >= xdim || ny < 0 || ny >= ydim) continue; n               if (d[nx][ny] == INT_MAX) n                 d[nx][ny] = d[x][y] + 1, q.push(make_pair(nx, ny)); n             } n       } n       for (int x = (0); x < (xdim); ++x) n         for (int y = (0); y < (ydim); ++y) n           if (d[x][y] == INT_MAX) { n             assert(xdim == 3 && ydim == 3 && x == 1 && y == 1); n             d[x][y] = 0; n           } n       for (int x = (0); x < (xdim); ++x) n         for (int y = (0); y < (ydim); ++y) assert(d[x][y] == calc(x, y)); n       printf( done (%d,%d) n , xdim, ydim); n     } n } n void verifysum() { n   for (xdim = 3; xdim <= 100; ++xdim) { n     for (ydim = 3; ydim <= 100; ++ydim) n       for (int dx = (1); dx <= (min(xdim, 3)); ++dx) n         for (int dy = (1); dy <= (min(ydim, 3)); ++dy) { n           int have = calcsum(xdim - dx, ydim - dy); n           int want = calcsumstupid(xdim - dx, ydim - dy); n           assert(have == want); n         } n     printf( done xdim=%d n , xdim); n   } n } n int main() { n   precalc(); n   int ncase; n   scanf( %d , &ncase); n   for (int i = (1); i <= (ncase); ++i) run(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   char t[n + 1]; n   scanf( %s , t); n   int i = 0, k = 1; n   while (t[i] !=   0 ) { n     printf( %c , t[i]); n     i = i + k; n     k++; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const long long INFF = 0x3f3f3f3f3f3f3f3fll; n const long long M = 1e9 + 7; n const long long maxn = 1e6 + 7; n const double pi = acos(-1.0); n const double eps = 0.00000001; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n template <typename T> n inline T abs(T a) { n   return a > 0 ? a : -a; n } n template <typename T> n inline T powMM(T a, T b) { n   T ret = 1; n   for (; b; b >>= 1ll, a = (long long)a * a % M) n     if (b & 1) ret = (long long)ret * a % M; n   return ret; n } n int A[maxn]; n map<int, int> S; n vector<int> del, ini[2], have[2]; n int cnt[2], ans; n int main() { n   int n, m, i, j; n   scanf( %d%d , &n, &m); n   m = min(m, n * 2); n   for (i = 1; i <= n; i++) scanf( %d , &A[i]); n   for (i = 1; i <= n; i++) { n     if (S.count(A[i])) { n       del.push_back(i); n       ans++; n     } else { n       S[A[i]] = i, cnt[A[i] & 1]++; n       ini[A[i] & 1].push_back(i); n     } n   } n   for (i = 0; i < 2; i++) { n     sort(ini[i].begin(), ini[i].end()); n     for (j = 0; j < (int)ini[i].size() - n / 2; j++) { n       S.erase(A[ini[i][j]]); n       cnt[i]--; n       ans++; n       del.push_back(ini[i][j]); n     } n   } n   j = 0; n   for (i = 1; i <= m; i++) { n     if (!S.count(i)) { n       if (cnt[i & 1] != n / 2) { n         cnt[i & 1]++; n         A[del[j++]] = i; n       } n     } n   } n   if (cnt[0] != n / 2 || cnt[1] != n / 2) return 0 * puts( -1 ); n   printf( %d n , ans); n   for (i = 1; i <= n; i++) printf( %d  , A[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a, mn, mx, ans = 0; n   cin >> n >> a; n   mn = mx = a; n   for (int i = 1; i < n; i++) { n     cin >> a; n     if (a < mn) { n       mn = a; n       ans++; n     } n     if (a > mx) { n       mx = a; n       ans++; n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n inline int gi() { n   char tmp = getchar(); n   int ans = 0, flag = 1; n   while (!isdigit(tmp)) { n     if (tmp ==  - ) flag = -1; n     tmp = getchar(); n   } n   while (isdigit(tmp)) { n     ans = ans * 10 + tmp -  0 ; n     tmp = getchar(); n   } n   return ans * flag; n } n inline void in(int &x) { x = gi(); } n inline void in2(int &x, int &y) { in(x), in(y); } n inline void in3(int &x, int &y, int &z) { in(x), in(y), in(z); } n inline void in4(int &x, int &y, int &z, int &a) { in3(x, y, z), in(a); } n inline void smax(int &x, int y) { x = max(x, y); } n inline void smin(int &x, int y) { x = min(x, y); } n int lowbit(int x) { return x & -x; } n const int N = 1002000; n int C[N], n, maxx; n void Add(int x, int v) { n   while (x <= maxx) { n     smax(C[x], v); n     x += lowbit(x); n   } n } n int Query(int x) { n   int ans = 0; n   while (x) { n     smax(ans, C[x]); n     x -= lowbit(x); n   } n   return ans; n } n struct Nod { n   int x, y; n } Node[N]; n bool cmp(Nod a, Nod b) { n   if (a.y != b.y) return a.y < b.y; n   return a.x < b.x; n } n signed main() { n   int n = gi(); n   for (int i = (int)(1); i <= (int)(n); ++i) { n     Node[i].x = gi(); n     Node[i].y = i - Node[i].x; n     smax(maxx, Node[i].x); n   } n   sort(Node + 1, Node + n + 1, cmp); n   int ans = 0; n   for (int i = (int)(1); i <= (int)(n); ++i) { n     if (Node[i].y < 0) continue; n     int g = Query(Node[i].x - 1); n     Add(Node[i].x, g + 1); n     smax(ans, g + 1); n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   map<string, string> hh; n   map<string, string>::iterator it; n   int n; n   string a, b, c; n   cin >> n; n   while (n--) { n     cin >> a >> b; n     it = hh.find(a); n     if (it == hh.end()) n       hh[b] = a; n     else { n       c = it->second; n       hh.erase(it); n       hh[b] = c; n     } n   } n   cout << hh.size() << endl; n   for (it = hh.begin(); it != hh.end(); it++) n     cout << it->second <<     << it->first << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, c[23][23], d[23], u[23]; n int main() { n   scanf( %d%d , &n, &m); n   for (int xt, yt, i = 1; i <= m; ++i) { n     scanf( %d%d , &xt, &yt); n     if (c[xt][yt] || xt == yt) continue; n     ++d[xt], ++d[yt]; n     c[xt][yt] = c[yt][xt] = 1; n   } n   for (int j, co, p, mint, i = 1; i <= n; ++i) { n     fill(u, u + n + 1, 0); n     co = 0; n     for (j = i; !u[j]; j = p) { n       mint = n + n; n       p = j; n       u[j] = 1; n       ++co; n       for (int k = 1; k <= n; ++k) n         if (!u[k] && c[j][k] && (d[k] < mint || d[k] == mint && k < p)) n           p = k, mint = d[k]; n     } n     if (co == n) { n       puts( Yes ); n       return 0; n     } n   } n   puts( No ); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   vector<pair<int, int> > v; n   for (int i = 0; i < n; i++) { n     int a; n     cin >> a; n     v.push_back(make_pair(a, i)); n   } n   sort(v.begin(), v.end()); n   int cur = 0; n   vector<int> ans; n   for (int i = 0; i < v.size() && cur + v[i].first <= k; i++) { n     cur += v[i].first; n     ans.push_back(v[i].second); n   } n   cout << ans.size() << endl; n   for (int i = 0; i < ans.size(); i++) { n     cout << ans[i] + 1 <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n bool Check(char x) { n   if (x <=  3  && x >=  1 ) n     return true; n   else n     return false; n } n int main() { n   char s[1000]; n   cin >> s; n   char x; n   for (int i = 0; i < strlen(s); ++i) { n     for (int j = i + 1; j < strlen(s); ++j) { n       if (s[j] < s[i] && Check(s[i]) && Check(s[j])) { n         x = s[i]; n         s[i] = s[j]; n         s[j] = x; n       } n     } n   } n   for (int i = 0; i < strlen(s); i++) { n     cout << s[i]; n   } n   return 0; n } n


#include <bits/stdc++.h> n int a[300300]; n int b[300300]; n int t[300300]; n int n, q; n void update(int u, const int &val) { n   while (1 <= u && u <= n) { n     t[u] += val; n     u = u + (u & (-u)); n   } n } n int sum(int u) { n   int res = 0; n   while (1 <= u && u <= n) { n     res += t[u]; n     u = u & (u - 1); n   } n   return (res); n } n void init(void) { n   int i, v; n   scanf( %d , &n); n   for (i = 1; i <= n; i = i + 1) { n     scanf( %d , &v); n     a[i] = v; n     b[v] = i; n   } n   memset(t, 0, sizeof t); n   for (i = 2; i <= n; i = i + 1) n     if (b[i] < b[i - 1]) update(i, 1); n } n void swap(int &a, int &b) { n   int sw; n   sw = a; n   a = b; n   b = sw; n } n void answer(void) { n   int i, t, x, y, r, t1, t2; n   bool px, py, px1, py1; n   scanf( %d , &q); n   for (i = 1; i <= q; i = i + 1) { n     scanf( %d , &t); n     scanf( %d , &x); n     scanf( %d , &y); n     if (t == 2) { n       t1 = a[x]; n       t2 = a[y]; n       px = (b[t1] < b[t1 - 1]); n       py = (b[t2] < b[t2 - 1]); n       px1 = (b[t1 + 1] < b[t1]); n       py1 = (b[t2 + 1] < b[t2]); n       b[t1] = y; n       b[t2] = x; n       swap(a[x], a[y]); n       if (b[t1] < b[t1 - 1] && !px) update(t1, 1); n       if (b[t1] > b[t1 - 1] && px) update(t1, -1); n       if (b[t1 + 1] < b[t1] && !px1) update(t1 + 1, 1); n       if (b[t1 + 1] > b[t1] && px1) update(t1 + 1, -1); n       if (t2 != t1 && t2 != t1 + 1) { n         if (b[t2] < b[t2 - 1] && !py) update(t2, 1); n         if (b[t2] > b[t2 - 1] && py) update(t2, -1); n       } n       if (t2 + 1 != t1 && t2 + 1 != t1 + 1) { n         if (b[t2 + 1] < b[t2] && !py1) update(t2 + 1, 1); n         if (b[t2 + 1] > b[t2] && py1) update(t2 + 1, -1); n       } n     } else { n       r = sum(y) - sum(x); n       printf( %d n , r + 1); n     } n   } n } n int main(void) { n   init(); n   answer(); n   return 0; n } n


#include <bits/stdc++.h> n using i64 = long long; n std::vector<std::vector<int>> read_tree1(int v) { n   std::vector<std::vector<int>> graph(v); n   while (v-- > 1) { n     int x, y; n     std::cin >> x >> y; n     graph[x - 1].push_back(y - 1); n     graph[y - 1].push_back(x - 1); n   } n   return graph; n } n template <class T> n std::pair<T, T> ext_euclid(T a, T b) { n   if (b == 0) { n     return {a > 0 ? +1 : -1, 0}; n   } else { n     auto res = ext_euclid(b, a % b); n     return {res.second, res.first - a / b * res.second}; n   } n } n template <class T> n T mod_inv(T num, T mod) { n   num = (num % mod + mod) % mod; n   T res = ext_euclid(num, mod).first; n   return res < 0 ? res + mod : res; n } n int main() { n   std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0); n   const i64 MOD = 998244353; n   int n; n   std::cin >> n; n   auto tree = read_tree1(n); n   std::function<std::tuple<i64, i64, i64>(int, int)> dfs = n       [&](int cur, int prv) -> std::tuple<i64, i64, i64> { n     std::vector<std::tuple<i64, i64, i64>> nxts; n     for (int nxt : tree[cur]) n       if (nxt != prv) { n         nxts.push_back(dfs(nxt, cur)); n       } n     i64 prod = 1; n     for (const auto& [f, g, h] : nxts) { n       prod = prod * (f + h) % MOD; n     } n     i64 F = 1, G = 1, H = 0; n     for (const auto& [f, g, h] : nxts) { n       F = F * f % MOD; n       G = G * (f + h) % MOD; n       H = (H + g * mod_inv(f + h, MOD)) % MOD; n     } n     H = H * prod % MOD; n     F = (F + H) % MOD; n     return {F, G, H}; n   }; n   std::cout << std::get<0>(dfs(0, -1)) <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const int MAXN = 2e5 + 5; n int n, k, d, ansL = 1, ansR = 1, top1, top2, flag, pos; n int a[MAXN], st1[MAXN], st2[MAXN]; n map<int, int> lst; n namespace SegmentTree { n struct Tree { n   int l, r; n   int w, tag; n } tree[MAXN << 2]; n void update(int k) { tree[k].w = min(tree[k << 1].w, tree[k << 1 | 1].w); } n void apply(int k, int val) { n   tree[k].w += val; n   tree[k].tag += val; n } n void down(int k) { n   if (tree[k].tag != 0) { n     apply(k << 1, tree[k].tag); n     apply(k << 1 | 1, tree[k].tag); n     tree[k].tag = 0; n   } n } n void Build(int k, int l, int r) { n   tree[k].l = l; n   tree[k].r = r; n   if (l == r) { n     tree[k].w = l; n     return; n   } n   int mid = (l + r) >> 1; n   Build(k << 1, l, mid); n   Build(k << 1 | 1, mid + 1, r); n   update(k); n } n void Modify(int k, int l, int r, int val) { n   if (tree[k].l >= l && tree[k].r <= r) { n     apply(k, val); n     return; n   } n   down(k); n   int mid = (tree[k].l + tree[k].r) >> 1; n   if (l <= mid) Modify(k << 1, l, r, val); n   if (r > mid) Modify(k << 1 | 1, l, r, val); n   update(k); n } n void Delete(int k, int x) { n   if (tree[k].l == tree[k].r) { n     tree[k].w = 0; n     return; n   } n   down(k); n   int mid = (tree[k].l + tree[k].r) >> 1; n   if (x <= mid) n     Delete(k << 1, x); n   else n     Delete(k << 1 | 1, x); n   update(k); n } n int Find(int k, int x) { n   if (tree[k].l == tree[k].r) return tree[k].l; n   down(k); n   if (tree[k << 1].w <= x) n     return Find(k << 1, x); n   else n     return Find(k << 1 | 1, x); n } n void Query(int k, int l, int r, int x) { n   if (tree[k].l >= l && tree[k].r <= r) { n     if (tree[k].w <= x) { n       flag = 1; n       pos = Find(k, x); n     } n     return; n   } n   down(k); n   int mid = (tree[k].l + tree[k].r) >> 1; n   if (l <= mid && !flag) Query(k << 1, l, r, x); n   if (r > mid && !flag) Query(k << 1 | 1, l, r, x); n } n }  // namespace SegmentTree n int main() { n   scanf( %d%d%d , &n, &k, &d); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     a[i] += INF; n   } n   if (d == 0) { n     for (int i = 1; i <= n; i++) { n       int l = i; n       while (a[i] == a[i + 1] && i < n) i += 1; n       if (i - l + 1 > ansR - ansL + 1) { n         ansL = l; n         ansR = i; n       } n     } n     printf( %d %d n , ansL, ansR); n     return 0; n   } n   SegmentTree::Build(1, 1, n); n   int L = 1; n   for (int R = 1; R <= n; R++) { n     int tmp = L; n     if (a[R] % d == a[R - 1] % d) n       L = max(lst[a[R]] + 1, L); n     else n       L = R; n     lst[a[R]] = R; n     while (tmp < L) { n       SegmentTree::Delete(1, tmp); n       tmp += 1; n     } n     while (top1 && st1[top1] >= L && a[st1[top1]] >= a[R]) { n       SegmentTree::Modify(1, max(L, st1[top1 - 1] + 1), st1[top1], n                           a[st1[top1]] / d); n       top1 -= 1; n     } n     SegmentTree::Modify(1, max(L, st1[top1] + 1), R, -a[R] / d); n     st1[++top1] = R; n     while (top2 && st2[top2] >= L && a[st2[top2]] <= a[R]) { n       SegmentTree::Modify(1, max(L, st2[top2 - 1] + 1), st2[top2], n                           -a[st2[top2]] / d); n       top2 -= 1; n     } n     SegmentTree::Modify(1, max(L, st2[top2] + 1), R, a[R] / d); n     st2[++top2] = R; n     flag = 0; n     pos = 0; n     SegmentTree::Query(1, L, R, k + R); n     if (R - pos + 1 > ansR - ansL + 1) { n       ansL = pos; n       ansR = R; n     } n   } n   printf( %d %d n , ansL, ansR); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void printArray(vector<T> arr) { n   for (T a : arr) cout << a <<    ; n   cout <<   n ; n } n void printVerdict(bool verdict) { cout << (verdict ?  YES  :  NO ) <<   n ; } n vector<long long> findPrime(long long n) { n   vector<long long> ret; n   for (int i = 2; i * i <= n && ret.empty(); i++) { n     if (n % i == 0) ret.push_back(i); n   } n   if (ret.empty()) return {}; n   for (int i = 2; i * i <= n / ret.front(); i++) { n     if ((n / ret.front()) % i == 0 && i != ret.front()) { n       ret.push_back(i); n       break; n     } n   } n   ret.push_back((n / ret.front()) / ret.back()); n   if (ret.back() == ret[0] || ret.back() == ret[1]) return {}; n   return ret; n } n int main() { n   std::ios_base::sync_with_stdio(false); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     bool verdict = true; n     vector<long long> ret = findPrime(n); n     if (ret.empty()) verdict = false; n     printVerdict(verdict); n     if (verdict) printArray(ret); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5; n const long long M = 1e9 + 9; n int n, x, y; n pair<int, int> pos[N]; n map<pair<int, int>, int> mp; n set<int> q; n long long ans; n int children(int x, int y) { n   int ret = 0; n   for (int dx = -1; dx <= 1; dx++) { n     map<pair<int, int>, int>::iterator c = mp.find(make_pair(x + dx, y - 1)); n     if (c != mp.end()) ret++; n   } n   return ret; n } n void update(int x, int y) { n   map<pair<int, int>, int>::iterator p = mp.find(make_pair(x, y)); n   if (p == mp.end()) return; n   for (int dx = -1; dx <= 1; dx++) { n     map<pair<int, int>, int>::iterator c = mp.find(make_pair(x + dx, y + 1)); n     if (c != mp.end() && children(x + dx, y + 1) == 1) { n       q.erase(p->second); n       return; n     } n   } n   q.insert(p->second); n } n void insert(int x, int y, int z) { n   pos[z].first = x; n   pos[z].second = y; n   mp[make_pair(x, y)] = z; n } n void remove(int x, int y) { n   mp.erase(make_pair(x, y)); n   for (int dx = -1; dx <= 1; dx++) { n     update(x + dx, y + 1); n     update(x + dx, y - 1); n   } n   for (int dx = -2; dx <= 2; dx++) { n     update(x + dx, y); n   } n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> x >> y; n     insert(x, y, i); n   } n   for (int i = 0; i < n; i++) { n     update(pos[i].first, pos[i].second); n   } n   for (int act = 0; !q.empty(); act++) { n     set<int>::iterator it; n     if ((act & 1) == 0) { n       it = --q.end(); n     } else { n       it = q.begin(); n     } n     ans = ans * n + (*it); n     ans %= M; n     remove(pos[*it].first, pos[*it].second); n     q.erase(it); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long UNDEF = -1; n const long long INF = 1e18; n template <typename T> n inline bool chkmax(T &aa, T bb) { n   return aa < bb ? aa = bb, true : false; n } n template <typename T> n inline bool chkmin(T &aa, T bb) { n   return aa > bb ? aa = bb, true : false; n } n long long cross(const pair<long long, long long> &a, n                 const pair<long long, long long> &b, n                 const pair<long long, long long> &c) { n   return (b.first - a.first) * (c.second - a.second) - n          (b.second - a.second) * (c.first - a.first); n } n vector<pair<long long, long long> > convexHullAllowStraightEdges( n     vector<pair<long long, long long> > points) { n   if (points.size() <= 1) return points; n   sort(points.begin(), points.end()); n   vector<pair<long long, long long> > h; n   for (auto p : points) { n     while (h.size() >= 2 && cross(h.end()[-2], h.back(), p) > 0) h.pop_back(); n     h.push_back(p); n   } n   reverse(points.begin(), points.end()); n   int upper = h.size(); n   for (auto p : points) { n     while (h.size() > upper && cross(h.end()[-2], h.back(), p) > 0) n       h.pop_back(); n     h.push_back(p); n   } n   h.resize(h.size() - 1 - (h[0] == h[1])); n   return h; n } n static char stdinBuffer[1024]; n static char *stdinDataEnd = stdinBuffer + sizeof(stdinBuffer); n static const char *stdinPos = stdinDataEnd; n void readAhead(size_t amount) { n   size_t remaining = stdinDataEnd - stdinPos; n   if (remaining < amount) { n     memmove(stdinBuffer, stdinPos, remaining); n     size_t sz = fread(stdinBuffer + remaining, 1, n                       sizeof(stdinBuffer) - remaining, stdin); n     stdinPos = stdinBuffer; n     stdinDataEnd = stdinBuffer + remaining + sz; n     if (stdinDataEnd != stdinBuffer + sizeof(stdinBuffer)) *stdinDataEnd = 0; n   } n } n long long readInt() { n   readAhead(16); n   long long x = 0; n   bool neg = false; n   while (*stdinPos ==     || *stdinPos ==   n ) ++stdinPos; n   if (*stdinPos ==  - ) { n     ++stdinPos; n     neg = true; n   } n   while (*stdinPos >=  0  && *stdinPos <=  9 ) { n     x *= 10; n     x += *stdinPos -  0 ; n     ++stdinPos; n   } n   return neg ? -x : x; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   long long n = readInt(), m = readInt(); n   long long ox = readInt(), oy = readInt(); n   set<pair<long long, long long> > vmin, vmax; n   for (long long i = 0; i < n; i++) { n     long long x = readInt(), y = readInt(); n     vmax.insert(make_pair(x, y)); n   } n   long long xhi = 0, yhi = 0; n   for (long long i = 0; i < m; i++) { n     long long x = readInt(), y = readInt(); n     vmin.insert(make_pair(x, y)); n     chkmax(xhi, x); n     chkmax(yhi, y); n   } n   set<pair<long long, long long> > toch; n   for (auto &w : vmin) toch.insert(w); n   for (auto &w : vmax) toch.insert(w); n   toch.insert(make_pair(0, 0)); n   toch.insert(make_pair(xhi, 0)); n   toch.insert(make_pair(0, yhi)); n   vector<pair<long long, long long> > vtoch; n   for (auto &w : toch) vtoch.push_back(w); n   vector<pair<long long, long long> > ch = convexHullAllowStraightEdges(vtoch); n   for (auto &w : ch) { n     if (vmax.find(w) != vmax.end()) { n       printf( Max n ); n       return 0; n     } n   } n   printf( Min n ); n } n


#include <bits/stdc++.h> n using namespace std; n static const int INF = 500000000; n template <class T> n void debug(T a, T b) { n   for (; a != b; ++a) cerr << *a <<    ; n   cerr << endl; n } n string s[2005]; n int n, K; n int lcp[2005]; n int prof[2005][2005]; n struct uf { n   int par[2005]; n   vector<int> dp[2005]; n   void init(int n) { n     for (int i = 0; i < n; ++i) { n       dp[i].resize(2); n     } n     memset(par, -1, sizeof(par)); n   } n   int root(int a) { n     if (par[a] == -1) return a; n     return par[a] = root(par[a]); n   } n   void unite(int a, int b, int lb) { n     a = root(a); n     b = root(b); n     vector<int> tmp(dp[a].size() + dp[b].size() - 1); n     for (int i = 0; i < dp[a].size(); ++i) n       for (int j = 0; j < dp[b].size(); ++j) n         tmp[i + j] = max(tmp[i + j], dp[a][i] + dp[b][j] + lb * i * j); n     par[a] = b; n     dp[b] = tmp; n     dp[a].clear(); n   } n }; n uf u; n int used[2005]; n int main() { n   scanf( %d%d , &n, &K); n   for (int i = 0; i < n; ++i) cin >> s[i]; n   sort(s, s + n); n   u.init(n); n   for (int i = 0; i < n - 1; ++i) { n     int& t = lcp[i]; n     for (t = 0; n          t < s[i].size() && t < s[i + 1].size() && s[i][t] == s[i + 1][t]; ++t) n       ; n   } n   for (int i = 0; i < n - 1; ++i) { n     int tallest = -1, ind; n     for (int j = 0; j < n - 1; ++j) n       if (used[j] == 0 && tallest < lcp[j]) { n         tallest = lcp[j]; n         ind = j; n       } n     used[ind] = 1; n     u.unite(ind, ind + 1, tallest); n   } n   printf( %d n , u.dp[u.root(0)][K]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   int arr[n + 10]; n   for (int i = 1; i <= n; i++) scanf( %d , &arr[i]); n   int start, end; n   start = 1; n   int pos_1 = -1, pos_2 = -1; n   int cnt = 0; n   int t = 0; n   for (int i = 1; i <= n;) { n     pos_1 = -1; n     pos_2 = -1; n     start = i; n     for (int j = start; j <= n; j++) { n       if (arr[j] != -1) { n         pos_1 = j; n         break; n       } n     } n     if (pos_1 != -1) { n       for (int j = pos_1 + 1; j <= n; j++) n         if (arr[j] != -1) { n           pos_2 = j; n           break; n         } n       if (pos_2 == -1) { n         cnt++; n         break; n       } n       t++; n       if (arr[pos_1] == arr[pos_2]) { n         start = pos_2 + 1; n         for (int j = pos_2 + 1; j <= n; j++) n           if (arr[j] == -1 || arr[j] == arr[pos_1]) n             start = j + 1; n           else { n             start = j; n             break; n           } n         cnt++; n       } else { n         long long val = (arr[pos_2] - arr[pos_1]); n         int d = pos_2 - pos_1; n         if (val % d == 0) { n           int yes = val / d; n           val = arr[pos_1]; n           yes *= (-1); n           for (int j = pos_1 - 1; j >= start; j--) { n             val += yes; n             if (val <= 0) { n               cnt++; n               start = pos_2; n               goto End; n             } n             if (arr[j] != -1 && arr[j] != val) { n               cnt++; n               start = pos_2; n               goto End; n             } n           } n           val = arr[pos_2]; n           yes *= (-1); n           start = -1; n           for (int j = pos_2 + 1; j <= n; j++) { n             val += yes; n             if (val <= 0) { n               start = j; n               break; n             } n             if (arr[j] != -1 && arr[j] != val) { n               start = j; n               break; n             } n           } n           if (start == -1) start = n + 1; n           cnt++; n         } else { n           cnt += 1; n           start = pos_2; n         } n       } n     } else { n       cnt++; n       break; n     } n   End:; n     i = start; n   } n   cout << cnt << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct bign { n   int len, s[109]; n   bign() { n     memset(s, 0, sizeof(s)); n     len = 1; n   } n   bign(int num) { *this = num; } n   bign(const char *num) { *this = num; } n   bign operator=(const int num) { n     char s[109]; n     sprintf(s,  %d , num); n     *this = s; n     return *this; n   } n   bign operator=(const char *num) { n     for (int i = 0; num[i] ==  0 ; num++) n       ; n     len = strlen(num); n     for (int i = 0; i < len; i++) s[i] = num[len - i - 1] -  0 ; n     return *this; n   } n   bign operator+(const bign &b) const { n     bign c; n     c.len = 0; n     for (int i = 0, g = 0; g || i < max(len, b.len); i++) { n       int x = g; n       if (i < len) x += s[i]; n       if (i < b.len) x += b.s[i]; n       c.s[c.len++] = x % 10; n       g = x / 10; n     } n     return c; n   } n   bign operator+=(const bign &b) { n     *this = *this + b; n     return *this; n   } n   void clean() { n     while (len > 1 && !s[len - 1]) len--; n   } n   bign operator*(const bign &b) { n     bign c; n     c.len = len + b.len; n     for (int i = 0; i < len; i++) { n       for (int j = 0; j < b.len; j++) { n         c.s[i + j] += s[i] * b.s[j]; n       } n     } n     for (int i = 0; i < c.len; i++) { n       c.s[i + 1] += c.s[i] / 10; n       c.s[i] %= 10; n     } n     c.clean(); n     return c; n   } n   bign operator*=(const bign &b) { n     *this = *this * b; n     return *this; n   } n   bign operator-(const bign &b) { n     bign c; n     c.len = 0; n     for (int i = 0, g = 0; i < len; i++) { n       int x = s[i] - g; n       if (i < b.len) x -= b.s[i]; n       if (x >= 0) n         g = 0; n       else { n         g = 1; n         x += 10; n       } n       c.s[c.len++] = x; n     } n     c.clean(); n     return c; n   } n   bign operator-=(const bign &b) { n     *this = *this - b; n     return *this; n   } n   bign operator/(const bign &b) { n     bign c, f = 0; n     for (int i = len - 1; i >= 0; i--) { n       f = f * 10; n       f.s[0] = s[i]; n       while (f >= b) { n         f -= b; n         c.s[i]++; n       } n     } n     c.len = len; n     c.clean(); n     return c; n   } n   bign operator/=(const bign &b) { n     *this = *this / b; n     return *this; n   } n   bign operator%(const bign &b) { n     bign r = *this / b; n     r = *this - r * b; n     return r; n   } n   bign operator%=(const bign &b) { n     *this = *this % b; n     return *this; n   } n   bool operator<(const bign &b) { n     if (len != b.len) return len < b.len; n     for (int i = len - 1; i >= 0; i--) { n       if (s[i] != b.s[i]) return s[i] < b.s[i]; n     } n     return false; n   } n   bool operator>(const bign &b) { n     if (len != b.len) return len > b.len; n     for (int i = len - 1; i >= 0; i--) { n       if (s[i] != b.s[i]) return s[i] > b.s[i]; n     } n     return false; n   } n   bool operator==(const bign &b) { return !(*this > b) && !(*this < b); } n   bool operator!=(const bign &b) { return !(*this == b); } n   bool operator<=(const bign &b) { return *this < b || *this == b; } n   bool operator>=(const bign &b) { return *this > b || *this == b; } n   string str() const { n     string res =   ; n     for (int i = 0; i < len; i++) res = char(s[i] +  0 ) + res; n     return res; n   } n }; n map<int, bool> mp; n const int MAX = 5e4 + 5; n int n, m, Tot, tot; n int a[MAX], b[MAX], pm[MAX], pim[MAX]; n bool use[MAX]; n void dfs(int n, int I = 0, int tot = 0, int qwq = 0) { n   if (qwq == n - 1) { n     printf( YES n ); n     printf( %d n , tot); n     for (int i = 0; i < tot; ++i) printf( %d %d n , a[i], b[i]); n     exit(0); n   } n   if (mp[qwq]) return; n   mp[qwq] = 1; n   for (int i = I + 1; i <= Tot; ++i) { n     if (i == Tot) { n       int qaq = min((int)((long long)(n - 1 - qwq) * pm[i] / n), pm[i] - 1); n       if (qwq + n / pm[i] * qaq != n - 1) n         continue; n       else n         a[tot] = qaq, b[tot] = pm[i], dfs(n, i, tot + 1, qwq + n / pm[i] * qaq); n     } else { n       for (int j = min((int)((long long)(n - 1 - qwq) * (long long)pm[i] / n                              (long long)n), n                        pm[i] - 1); n            j >= 1; --j) n         if (qwq + n / pm[i] * j <= n - 1) n           a[tot] = j, b[tot] = pm[i], dfs(n, i, tot + 1, qwq + n / pm[i] * j); n         else n           break; n     } n   } n } n bool look(int x) { n   if (x == 1) return 0; n   if (x == 2) return 1; n   for (int i = 2; i <= sqrt(x); ++i) n     if (x % i == 0) return 0; n   return 1; n } n void ss(int *pm) { n   use[1] = 1; n   for (int i = 2; i <= m; ++i) { n     if (!use[i]) pm[++tot] = i; n     for (int j = 1; j <= tot && pm[j] * i <= m; ++j) { n       use[i * pm[j]] = 1; n       if (i % pm[j] == 0) break; n     } n   } n } n bool work(int x) { n   int a = n; n   while (a % x == 0) a /= x; n   return a == 1; n } n int main() { n   scanf( %d , &n), m = sqrt(n); n   if (n % 2 == 0 && (n / 2) % 2 == 1 && n != 2) { n     cout <<  YES  << endl <<  2  << endl <<  1 2  << endl; n     cout << (n / 2 - 1) / 2 <<     << n / 2 << endl; n     return 0; n   } n   if (look(n)) return printf( NO ), 0; n   ss(pim); n   for (int i = 1; i <= tot; ++i) n     if (work(pim[i])) return printf( NO ), 0; n   for (int i = 2; i <= m; ++i) n     if (n % i == 0) { n       pm[++Tot] = i; n       if (i != n / i) pm[++Tot] = n / i; n     } n   if (Tot + 2 < 4) return printf( NO ), 0; n   sort(pm + 1, pm + 1 + Tot), dfs(n); n   return printf( NO ), 0; n } n istream &operator>>(istream &in, bign &x) { n   string s; n   in >> s; n   x = s.c_str(); n   return in; n } n ostream &operator<<(ostream &out, const bign &x) { n   out << x.str(); n   return out; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n const long long N = 5e5; n long long id[N], a[N], pos[N]; n int main() { n   ios_base::sync_with_stdio(false); n   long long n, t, m, l, k, ans, i, j, res = 0, fl; n   t = 1; n   long long x; n   while (t--) { n     long long o; n     cin >> n >> m >> k; n     for (i = 0; i < n; i++) { n       cin >> a[i]; n       pos[a[i]] = i; n     } n     long long ct = 1; n     j = 0; n     for (o = 0;; o += k) { n       for (i = o; i < o + k; ++i) id[a[i]] = ct; n       ct++; n       if (i > n) break; n     } n     for (i = 0; i < m; i++) { n       cin >> x; n       res += id[x]; n       if (pos[x] > 0) { n         long long p = pos[x]; n         long long val = a[p - 1]; n         swap(id[x], id[val]); n         swap(a[p], a[p - 1]); n         pos[x] = p - 1; n         pos[val] = p; n       } n     } n     cout << res <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n long long gcd(long long a, long long b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n signed main() { n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     long long maxai = 0; n     multiset<long long> a; n     for (long long i = 0; i < n; i++) { n       long long ai; n       cin >> ai; n       a.insert(ai); n       if (ai > maxai) maxai = ai; n     } n     while (maxai != 1 && a.size()) { n       long long br = 0; n       for (long long i = 1; i <= maxai / 2; i++) { n         if (maxai % i != 0) continue; n         for (long long k = 1; k < 1010; k++) { n           if (k * maxai / i > 1010) break; n           long long count = a.count(k * maxai / i); n           if (count) { n             br = 1; n             for (long long j = 0; j < count; j++) cout << k * maxai / i <<    ; n             a.erase(k * maxai / i); n             maxai = gcd(maxai, k * maxai / i); n             break; n           } n         } n         if (br) break; n       } n       if (!br) break; n     } n     for (multiset<long long>::iterator i = a.begin(); i != a.end(); i++) n       cout << *i <<    ; n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long Gcd(long long a, long long b) { n   if (a % b == 0) return b; n   return Gcd(b, a % b); n } n long long Max(long long a, long long b) { n   if (a > b) return a; n   return b; n } n long long Min(long long a, long long b) { n   if (a < b) return a; n   return b; n } n long long gcdExtended(long long a, long long b, long long *x, long long *y) { n   if (a == 0) { n     *x = 0, *y = 1; n     return b; n   } n   long long x1, y1; n   long long gcd = gcdExtended(b % a, a, &x1, &y1); n   *x = y1 - (b / a) * x1; n   *y = x1; n   return gcd; n } 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 long long modInverse(long long a, long long m) { n   long long x, y; n   long long g = gcdExtended(a, m, &x, &y); n   if (g != 1) n     return -1; n   else { n     long long res = (x % m + m) % m; n     return res; n   } n } n vector<int> primeFactors(int n) { n   vector<int> v; n   while (n % 2 == 0) { n     v.push_back(2); n     n = n / 2; n   } n   for (int i = 3; i <= sqrt(n); i = i + 2) { n     while (n % i == 0) { n       v.push_back(i); n       n = n / i; n     } n   } n   if (n > 2) v.push_back(n); n   return v; n } n long long C[2001][2000]; n void binomialCoeff(long long n, long long k) { n   long long i, j; n   for (i = 0; i <= n; i++) { n     for (j = 0; j <= k; j++) { n       if (j == 0 || j == i) n         C[i][j] = 1; n       else n         C[i][j] = (C[i - 1][j - 1] % 1000000007 + C[i - 1][j] % 1000000007) % n                   1000000007; n     } n   } n } n long long spf[100010]; n void sieve() { n   spf[1] = 1; n   for (int i = 2; i < 100010; i++) spf[i] = i; n   for (int i = 4; i < 100010; i += 2) spf[i] = 2; n   for (int i = 3; i * i < 100010; i++) { n     if (spf[i] == i) { n       for (int j = i * i; j < 100010; j += i) n         if (spf[j] == j) spf[j] = i; n     } n   } n } n long long binarySearch(long long arr[], long long l, long long r, long long x) { n   if (r >= l) { n     long long mid = l + (r - l) / 2; n     if (arr[mid] == x) return mid; n     if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x); n     return binarySearch(arr, mid + 1, r, x); n   } n   return -1; n } n const long long N = 100000; n long long n; n long long tree[2 * N]; n void build(long long arr[]) { n   for (long long i = 0; i < n; i++) { n     tree[n + i] = arr[i]; n   } n   for (long long i = n - 1; i > 0; --i) { n     tree[i] = tree[i << 1] + tree[i << 1 | 1]; n   } n } n void updateTreeNode(long long p, long long value) { n   tree[p + n] = value; n   p = p + n; n   for (long long i = p; i > 1; i >>= 1) { n     tree[i >> 1] = tree[i] + tree[i ^ 1]; n   } n } n long long query(long long l, long long r) { n   long long res = 0; n   for (l += n, r += n; l < r; l >>= 1, r >>= 1) { n     if (l & 1) { n       res += tree[l++]; n     } n     if (r & 1) { n       res += tree[--r]; n     } n   } n   return res; n } n void dfs(std::vector<long long> v[], long long s, bool visited[]) { n   visited[s] = true; n   for (long long i = 0; i < v[s].size(); ++i) { n     if (!visited[v[s][i]]) { n       dfs(v, v[s][i], visited); n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   string x69; n   cin >> x69; n   long long n = x69.length(); n   char s[n + 1]; n   for (int i = 0, _n = (n); i < _n; i++) { n     s[i + 1] = x69[i]; n   } n   long long ev = 0; n   long long od = 0; n   long long ao = 0; n   long long ae = 0; n   long long bo = 0; n   long long be = 0; n   for (int i = (1), _b = (n); i <= _b; i++) { n     if (s[i] ==  a ) { n       if (i % 2) { n         od += ao + 1; n         ev += ae; n       } else { n         od += ae + 1; n         ev += ao; n       } n       if (i % 2) n         ao++; n       else n         ae++; n     } n     if (s[i] ==  b ) { n       if (i % 2) { n         od += bo + 1; n         ev += be; n       } else { n         od += be + 1; n         ev += bo; n       } n       if (i % 2) n         bo++; n       else n         be++; n     } n   } n   cout << ev <<     << od << endl; n   return 0; n } n


#include <bits/stdc++.h> n const double EPS = 1e-24; n const long long int MOD = 1000000007ll; n const double PI = 3.14159265359; n int INF = 2147483645; n long long int INFINF = 9223372036854775807; n template <class T> n T Max2(T a, T b) { n   return a < b ? b : a; n } n template <class T> n T Min2(T a, T b) { n   return a < b ? a : b; n } n template <class T> n T Max3(T a, T b, T c) { n   return Max2(Max2(a, b), c); n } n template <class T> n T Min3(T a, T b, T c) { n   return Min2(Min2(a, b), c); n } n template <class T> n T Max4(T a, T b, T c, T d) { n   return Max2(Max2(a, b), Max2(c, d)); n } n template <class T> n T Min4(T a, T b, T c, T d) { n   return Min2(Min2(a, b), Max2(c, d)); n } n using namespace std; n int n; n int a[110]; n int main() { n   std::ios::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   reverse(a, a + n); n   int sum = 0, cur = 0; n   for (int i = 0; i < n; i++) sum += a[i]; n   int cnt = 0; n   while (cur <= sum / 2) cur += a[cnt++]; n   cout << cnt; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n, m, a, b; n     cin >> n >> m >> a >> b; n     a--; n     b--; n     vector<vector<int> > graph(n); n     for (int i = 0; i < m; i++) { n       int u, v; n       cin >> u >> v; n       u--; n       v--; n       graph[u].push_back(v); n       graph[v].push_back(u); n     } n     int x = 0; n     vector<bool> vis(n); n     function<void(int)> dfs = [&](int u) { n       vis[u] = true; n       for (int v : graph[u]) { n         if (vis[v] || v == x) continue; n         dfs(v); n       } n     }; n     x = b; n     dfs(a); n     int cnta = count(vis.begin(), vis.end(), false) - 1; n     fill(vis.begin(), vis.end(), false); n     x = a; n     dfs(b); n     int cntb = count(vis.begin(), vis.end(), false) - 1; n     cout << (long long)cnta * cntb <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5; n const int M = 0x3f3f3f3f; n long long n, m, k, q, h; n int ld[N], rd[N]; n vector<long long> p; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0), cout.tie(0); n   cin >> n >> m >> k >> q; n   vector<vector<long long> > vec(n + 1); n   memset(ld, 0x3f, sizeof(ld)); n   memset(rd, 0x3f, sizeof(rd)); n   while (k--) { n     int x, y; n     cin >> x >> y; n     vec[x].push_back(y); n   } n   int f = !vec[1].empty(); n   vector<vector<long long> > tp = move(vec); n   for (int i = 1; i <= n; ++i) n     if (!tp[i].empty()) { n       h = i; n       sort(tp[i].begin(), tp[i].end()); n       vec.push_back(tp[i]); n     } n   long long l = (vec[0].back() << 1) - vec[0][0] - 1, r = vec[0].back() - 1, n             lp = vec[0][0], rp = vec[0].back(); n   while (q--) { n     int pos; n     cin >> pos; n     p.push_back(pos); n   } n   sort(p.begin(), p.end()); n   for (int i = 1; i <= m; ++i) { n     auto tmp = lower_bound(p.begin(), p.end(), i); n     if (tmp != p.end()) n       rd[i] = *tmp - i; n     else n       rd[i] = M; n     tmp = upper_bound(p.begin(), p.end(), i); n     if (tmp != p.begin()) n       ld[i] = i - *(tmp - 1); n     else n       ld[i] = M; n   } n   q = vec.size(); n   if (!f) l = r = rd[1], lp = rp = rd[1] + 1; n   for (int i = f; i < q; ++i) { n     vector<pair<long long, long long> > pos; n     if (ld[lp] ^ M) pos.push_back(make_pair(lp - ld[lp], l + ld[lp])); n     if (rd[lp] ^ M) pos.push_back(make_pair(lp + rd[lp], l + rd[lp])); n     if (ld[rp] ^ M) pos.push_back(make_pair(rp - ld[rp], r + ld[rp])); n     if (rd[rp] ^ M) pos.push_back(make_pair(rp + rd[rp], r + rd[rp])); n     l = r = 1e18, lp = vec[i][0], rp = vec[i].back(); n     for (auto j : pos) { n       if (j.first >= rp) n         l = min(l, j.second + j.first - lp); n       else n         l = min(l, j.second + rp - j.first + rp - lp); n       if (j.first <= lp) n         r = min(r, j.second + rp - j.first); n       else n         r = min(r, j.second + j.first - lp + rp - lp); n     } n   } n   cout << min(l, r) + h - 1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   string a; n   cin >> a; n   char vowels[5] = { a ,  e ,  i ,  o ,  u }; n   for (int i = 0; i < a.size() - 1; ++i) { n     bool flag = false; n     for (int k = 0; k < 5; ++k) { n       if (a[i] == vowels[k]) { n         flag = true; n         break; n       } n     } n     if (a[i] ==  n ) flag = true; n     if (flag) { n       continue; n     } n     for (int k = 0; k < 5; ++k) { n       if (a[i + 1] == vowels[k]) { n         flag = true; n         break; n       } n     } n     if (flag == false) { n       cout <<  NO  << endl; n       return 0; n     } n   } n   int n = a.size(); n   bool flag = false; n   for (int k = 0; k < 5; ++k) { n     if (a[n - 1] == vowels[k]) { n       flag = true; n       break; n     } n   } n   if (a[n - 1] ==  n ) flag = true; n   if (flag == true) n     cout <<  YES  << endl; n   else n     cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 5; n const long long Inf = 0x3f3f3f3f3f3f3f3f; n int n, x, y, z, cnt, tot, head[maxn], vis[maxn]; n long long res, r[maxn], l[maxn], l0[maxn], r0[maxn], sum[maxn], ans1, n     ans2 = Inf, f[maxn], cir[maxn]; n struct Edge { n   int to, next, w; n } e[maxn << 1]; n void add(int u, int v, int w) { n   e[++cnt].to = v; n   e[cnt].w = w; n   e[cnt].next = head[u]; n   head[u] = cnt; n } n int fnd(int u, int fa = -1) { n   if (vis[u]) return u; n   vis[u] = -1; n   for (int i = head[u]; i; i = e[i].next) { n     int v = e[i].to; n     if (v != fa) { n       res = fnd(v, u); n       if (res) n         return cir[++tot] = u, sum[tot] = e[i].w, vis[u] = 1, n                res == u ? 0 : res; n     } n   } n   return 0; n } n void dfs(int u, int fa = -1) { n   for (int i = head[u]; i; i = e[i].next) { n     int v = e[i].to; n     if (vis[v] != 1 && v != fa) { n       dfs(v, u); n       ans1 = max(ans1, f[u] + f[v] + e[i].w); n       f[u] = max(f[u], f[v] + e[i].w); n     } n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d%d%d , &x, &y, &z); n     add(x, y, z); n     add(y, x, z); n   } n   fnd(1); n   sum[0] = 0; n   for (int i = 1; i <= tot; i++) { n     dfs(cir[i]); n     sum[i] += sum[i - 1]; n   } n   res = l[0] = l0[0] = -Inf; n   for (int i = 1; i <= tot; i++) { n     l0[i] = max(l0[i - 1], f[cir[i]] + sum[i] + res); n     l[i] = max(l[i - 1], f[cir[i]] + sum[i]); n     res = max(res, f[cir[i]] - sum[i]); n   } n   res = r[tot + 1], r0[tot + 1] = -Inf; n   for (int i = tot; i >= 1; i--) { n     r0[i] = max(r0[i + 1], f[cir[i]] - sum[i] + res); n     r[i] = max(r[i + 1], f[cir[i]] + sum[tot] - sum[i]); n     res = max(res, f[cir[i]] + sum[i]); n   } n   for (int i = 1; i <= tot; i++) { n     ans2 = min(ans2, max(l[i - 1] + r[i], max(l0[i - 1], r0[i]))); n   } n   printf( %lld n , max(ans1, ans2)); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(2) n using namespace std; n bool Finish_read; n template <class T> n inline void read(T &x) { n   Finish_read = 0; n   x = 0; n   int f = 1; n   char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = -1; n     if (ch == EOF) return; n     ch = getchar(); n   } n   while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar(); n   x *= f; n   Finish_read = 1; n } n template <class T> n inline void print(T x) { n   if (x / 10 != 0) print(x / 10); n   putchar(x % 10 +  0 ); n } n template <class T> n inline void writeln(T x) { n   if (x < 0) putchar( - ); n   x = abs(x); n   print(x); n   putchar(  n ); n } n template <class T> n inline void write(T x) { n   if (x < 0) putchar( - ); n   x = abs(x); n   print(x); n   putchar(   ); n } n int main() { n   int n; n   scanf( %d , &n); n   int t = sqrt(n); n   if (n % t) { n     for (int i = n / t * t + 1; i <= n; i++) printf( %d  , i); n   } n   for (int i = n / t; i >= 1; i--) n     for (int j = (i - 1) * t + 1; j <= i * t; j++) printf( %d  , j); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, m, a; n   cin >> n >> m >> a; n   cout << (n / a + (n % a != 0)) * (m / a + (m % a != 0)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 200100; n int n, b; n queue<pair<int, int> > q; n long long ans[MAXN]; n int main() { n   scanf( %d%d , &n, &b); n   long long available = 0; n   memset(ans, 0xff, sizeof ans); n   for (int i = 0, t, d; i < n; ++i) { n     scanf( %d%d , &t, &d); n     while (!q.empty() && available <= t) { n       ans[q.front().first] = available += q.front().second; n       q.pop(); n     } n     available = max(available, (long long)t); n     if ((int)q.size() < b) { n       q.push(make_pair(i, d)); n     } n   } n   while (!q.empty()) { n     ans[q.front().first] = available += q.front().second; n     q.pop(); n   } n   for (int i = 0; i < n; ++i) { n     printf( %lld%c , ans[i],    n [i + 1 == n]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x[3], l; n   scanf( %d%d%d%d , x, x + 1, x + 2, &l); n   long long ans = 1LL * (l + 3) * (l + 2) * (l + 1) / 6; n   for (int i = 0; i < 3; i++) n     for (int lx = 0; lx <= l; lx++) { n       int xx = min(l - lx, x[i] + lx - x[(i + 1) % 3] - x[(i + 2) % 3]); n       if (xx >= 0) ans -= 1LL * (2 + xx) * (1 + xx) / 2; n     } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[100003], i; n int main() { n   cin >> n; n   for (i = 1; i <= n; i++) cin >> a[i]; n   long long p = clock(); n   while (clock() - p < 1400) n     ; n   sort(a + 1, a + 1 + n); n   for (i = 1; i <= n; i++) cout << a[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 3010; n int a[MAXN], b[MAXN], c[MAXN]; n int d[MAXN][2]; n int main() { n   int n; n   while (~scanf( %d , &n)) { n     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); n     for (int i = 1; i <= n; ++i) scanf( %d , &b[i]); n     for (int i = 1; i <= n; ++i) scanf( %d , &c[i]); n     d[1][0] = b[1]; n     d[1][1] = a[1]; n     for (int i = 2; i <= n; ++i) { n       d[i][0] = max(d[i - 1][0] + b[i], d[i - 1][1] + c[i]); n       d[i][1] = max(d[i - 1][0] + a[i], d[i - 1][1] + b[i]); n     } n     printf( %d n , d[n][1]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, l, a[110], s, x, len; n int main() { n   cin >> n >> l; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     if (a[i] > s) s = a[i]; n   } n   for (int i = l; i <= s; i++) { n     for (int j = 1; j <= n; j++) x += a[j] / i; n     if (len < i * x) len = i * x; n     x = 0; n   } n   cout << len << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <int MOD_> n struct modnum { n   static constexpr int MOD = MOD_; n   static_assert(MOD_ > 0,  MOD must be positive ); n  n  private: n   using ll = long long; n   int v; n   static int minv(int a, int m) { n     a %= m; n     assert(a); n     return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a); n   } n  n  public: n   modnum() : v(0) {} n   modnum(ll v_) : v(int(v_ % MOD)) { n     if (v < 0) v += MOD; n   } n   explicit operator int() const { return v; } n   friend std::ostream& operator<<(std::ostream& out, const modnum& n) { n     return out << int(n); n   } n   friend std::istream& operator>>(std::istream& in, modnum& n) { n     ll v_; n     in >> v_; n     n = modnum(v_); n     return in; n   } n   friend bool operator==(const modnum& a, const modnum& b) { n     return a.v == b.v; n   } n   friend bool operator!=(const modnum& a, const modnum& b) { n     return a.v != b.v; n   } n   modnum inv() const { n     modnum res; n     res.v = minv(v, MOD); n     return res; n   } n   friend modnum inv(const modnum& m) { return m.inv(); } n   modnum neg() const { n     modnum res; n     res.v = v ? MOD - v : 0; n     return res; n   } n   friend modnum neg(const modnum& m) { return m.neg(); } n   modnum operator-() const { return neg(); } n   modnum operator+() const { return modnum(*this); } n   modnum& operator++() { n     v++; n     if (v == MOD) v = 0; n     return *this; n   } n   modnum& operator--() { n     if (v == 0) v = MOD; n     v--; n     return *this; n   } n   modnum& operator+=(const modnum& o) { n     v += o.v; n     if (v >= MOD) v -= MOD; n     return *this; n   } n   modnum& operator-=(const modnum& o) { n     v -= o.v; n     if (v < 0) v += MOD; n     return *this; n   } n   modnum& operator*=(const modnum& o) { n     v = int(ll(v) * ll(o.v) % MOD); n     return *this; n   } n   modnum& operator/=(const modnum& o) { return *this *= o.inv(); } n   friend modnum operator++(modnum& a, int) { n     modnum r = a; n     ++a; n     return r; n   } n   friend modnum operator--(modnum& a, int) { n     modnum r = a; n     --a; n     return r; n   } n   friend modnum operator+(const modnum& a, const modnum& b) { n     return modnum(a) += b; n   } n   friend modnum operator-(const modnum& a, const modnum& b) { n     return modnum(a) -= b; n   } n   friend modnum operator*(const modnum& a, const modnum& b) { n     return modnum(a) *= b; n   } n   friend modnum operator/(const modnum& a, const modnum& b) { n     return modnum(a) /= b; n   } n }; n template <typename T> n T pow(T a, long long b) { n   assert(b >= 0); n   T r = 1; n   while (b) { n     if (b & 1) r *= a; n     b >>= 1; n     a *= a; n   } n   return r; n } n template <int M> n string to_string(modnum<M> x) { n   return to_string(int(x)); n } n using num = modnum<998244353>; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int m, n, k; n   cin >> m >> n >> k; n   vector<num> p2(max(m, n) + 1); n   for (int i = 0; i <= max(m, n); i++) p2[i] = i ? p2[i - 1] * 2 : 1; n   map<pair<int, int>, int> cells; n   vector<int> rowTypeCnt(4), colTypeCnt(4); n   rowTypeCnt[0] = m; n   colTypeCnt[0] = n; n   vector<vector<int>> rowCnt(m, vector<int>(2)); n   vector<vector<int>> colCnt(n, vector<int>(2)); n   auto getRowType = [&](int x) { n     int res = 0; n     for (int i = 0; i < 2; i++) n       if (rowCnt[x][i]) res |= 1 << i; n     return res; n   }; n   auto getColType = [&](int x) { n     int res = 0; n     for (int i = 0; i < 2; i++) n       if (colCnt[x][i]) res |= 1 << i; n     return res; n   }; n   auto remove = [&](int x, int y) { n     if (!cells.count({x, y})) return; n     rowTypeCnt[getRowType(x)]--; n     colTypeCnt[getColType(y)]--; n     int v = cells[{x, y}]; n     cells.erase({x, y}); n     rowCnt[x][(x + y + v) & 1]--; n     colCnt[y][(x + y + v) & 1]--; n     rowTypeCnt[getRowType(x)]++; n     colTypeCnt[getColType(y)]++; n   }; n   auto add = [&](int x, int y, int v) { n     rowTypeCnt[getRowType(x)]--; n     colTypeCnt[getColType(y)]--; n     rowCnt[x][(x + y + v) & 1]++; n     colCnt[y][(x + y + v) & 1]++; n     cells[{x, y}] = v; n     rowTypeCnt[getRowType(x)]++; n     colTypeCnt[getColType(y)]++; n   }; n   while (k--) { n     int x, y, op; n     cin >> x >> y >> op; n     remove(--x, --y); n     if (op >= 0) add(x, y, op); n     if (rowTypeCnt[3] && colTypeCnt[3]) n       cout << 0 <<   n ; n     else if (rowTypeCnt[3]) n       cout << p2[colTypeCnt[0]] <<   n ; n     else if (colTypeCnt[3]) n       cout << p2[rowTypeCnt[0]] <<   n ; n     else if (rowTypeCnt[0] == m) n       cout << p2[m] + p2[n] - 2 <<   n ; n     else n       cout << p2[rowTypeCnt[0]] + p2[colTypeCnt[0]] - n                   (rowTypeCnt[1] == 0 || rowTypeCnt[2] == 0) n            <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a, b; n int x; n int main() { n   scanf( %d%d%d , &a, &b, &x); n   if (a >= b) n     for (int i = 0; i <= x - 2; i++) { n       printf( %d , i & 1); n       a -= !(i & 1); n       b -= (i & 1); n     } n   else { n     for (int i = 1; i <= x - 1; i++) { n       printf( %d , i & 1); n       a -= !(i & 1); n       b -= (i & 1); n     } n     x++; n   } n   if (x & 1) { n     for (int i = 0; i < a; i++) printf( 0 ); n     for (int i = 0; i < b; i++) printf( 1 ); n   } else { n     for (int i = 0; i < b; i++) printf( 1 ); n     for (int i = 0; i < a; i++) printf( 0 ); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   long long n, m, p; n   cin >> n >> m >> p; n   long long a; n   long long b; n   long long u = 0, v = 0; n   for (long long i = 1; i <= n; i++) { n     cin >> a; n     if (u == 0 && a % p != 0) { n       u = i; n     } n   } n   for (long long i = 1; i <= m; i++) { n     cin >> b; n     if (v == 0 && b % p != 0) { n       v = i; n     } n   } n   cout << u + v - 2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   int n, k; n   cin >> n >> k; n   vector<int> *dist = new vector<int>[n]; n   int len = 0; n   for (int i = 0; i < n; i++) { n     int d; n     cin >> d; n     dist[d].push_back(i); n     len = max(len, d); n   } n   if (dist[0].size() != 1) { n     cout << -1; n     return 0; n   } n   for (int i = 1; i <= len; i++) { n     if (dist[i].empty() || n         dist[i].size() > (long long)dist[i - 1].size() * (k - (i != 1))) { n       cout << -1; n       return 0; n     } n   } n   cout << n - 1 << endl; n   for (int i = 1; i <= len; i++) { n     int counter = 0; n     int index = 0; n     for (int child : dist[i]) { n       if (counter == k - (i != 1)) { n         counter = 0; n         index++; n       } n       cout << dist[i - 1][index] + 1 <<     << child + 1 << endl; n       counter++; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, n; n   cin >> a >> b >> n; n   bool aa = 0, bb = 1; n   if (a < b) swap(a, b), swap(aa, bb); n   for (int i = 0; i < a - (n + 1) / 2 - (n % 2 == 0); i++) cout << aa; n   for (int i = 0; i < (n + 1) / 2; i++) cout << aa << bb; n   for (int i = 0; i < b - (n + 1) / 2; i++) cout << bb; n   if (n % 2 == 0) cout << aa; n } n


#include <bits/stdc++.h> n char s[100005], stack[100005], ss; n int main() { n   long long n, k, now, i, i2, l, plus = 0, kid, pos; n   scanf( %lld %lld , &n, &k); n   for (i = 1; i <= k; i++) { n     scanf( %lld , &now); n     plus = 0; n     ss = 0; n     kid = n; n     while (kid / 2 + plus + 1 != now) { n       if (kid / 2 + plus + 1 < now) { n         stack[++ss] =  R ; n         plus += kid / 2 + 1; n         kid /= 2; n       } else { n         stack[++ss] =  L ; n         kid /= 2; n       } n     } n     now = kid; n     scanf( %s , s); n     l = strlen(s); n     for (i2 = 0; i2 < l; i2++) { n       if (s[i2] ==  R ) { n         if (now == 1) continue; n         plus += now / 2 + 1; n         now /= 2; n         stack[++ss] =  R ; n       } else if (s[i2] ==  L ) { n         if (now == 1) continue; n         now /= 2; n         stack[++ss] =  L ; n       } else { n         if (now == n) continue; n         if (stack[ss] ==  R ) plus -= now + 1; n         now = now * 2 + 1; n         ss--; n       } n     } n     printf( %lld n , plus + now / 2 + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e6 + 10; n const int MAXM = 4e6 + 10; n const long long MOD = 1e9 + 7; n const long long INF = 0x3f3f3f3f; n const unsigned long long BASE = 233; n const int base = 5; n mt19937_64 mt(time(0)); n char rubbish[110]; n bool GETDATA; n inline long long read() { n   long long x = 0, f = 1; n   char ch; n   do { n     ch = getchar(); n     if (ch ==  - ) f = -1; n   } while (ch <  0  || ch >  9 ); n   do { n     x = x * 10 + ch - 48; n     ch = getchar(); n   } while (ch >=  0  && ch <=  9 ); n   return x * f; n } n inline void write(long long x, char con =   n ) { n   if (x < 0) putchar( - ), x = -x; n   if (x > 9) write(x / 10, 0); n   putchar(x % 10 +  0 ); n   if (con) { n     printf( %c , con); n   } n } n long long N, M, K, Q; n long long a[MAXN]; n char s[MAXN][110]; n int sz[MAXN]; n vector<int> es[30]; n vector<pair<int, int> > tot; n vector<int> topsort; n bool occ[30]; n bool vis[30]; n int ord[30]; n void dfs(int u) { n   vis[u] = true; n   for (auto v : es[u]) { n     if (!vis[v]) { n       dfs(v); n     } n   } n   topsort.push_back(u); n } n void init() { n   for (int i = 0; i < 30; i++) { n     es[i].clear(); n     occ[i] = false; n     vis[i] = false; n   } n   tot.clear(); n   topsort.clear(); n } n void solve() { n   long long ans = 0; n   int now; n   int id; n   N = read(); n   M = read(); n   init(); n   for (int i = 0; i < N; i++) { n     now = read(); n     for (int j = 0; j < M; j++) { n       id = now * N + j; n       scanf( %s , s[id]); n       for (sz[id] = 0; s[id][sz[id]] !=   0 ; sz[id]++) { n         occ[s[id][sz[id]] -  a ] = true; n       } n     } n   } n   for (int i = 1, j; i < N * M; i++) { n     now = min(sz[i - 1], sz[i]); n     for (j = 0; j < now; j++) { n       if (s[i - 1][j] != s[i][j]) { n         break; n       } n     } n     if (j < now) { n       es[s[i][j] -  a ].push_back(s[i - 1][j] -  a ); n       tot.push_back(pair<int, int>{s[i][j] -  a , s[i - 1][j] -  a }); n     } else if (sz[i - 1] > sz[i]) { n       printf( IMPOSSIBLE n ); n       return; n     } n   } n   for (int i = 0; i < 26; i++) { n     if (occ[i] && !vis[i]) { n       dfs(i); n     } n   } n   for (int i = 0; i < topsort.size(); i++) { n     ord[topsort[i]] = i; n   } n   for (auto x : tot) { n     if (ord[x.first] < ord[x.second]) { n       printf( IMPOSSIBLE n ); n       return; n     } n   } n   for (auto ch : topsort) { n     printf( %c , ch +  a ); n   } n   printf(  n ); n } n int main() { n   int T; n   T = 1; n   for (int t = 1; t <= T; t++) { n     GETDATA = false; n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int ts, kk = 1; n template <class T> n inline T _sq(T a) { n   return a * a; n } n template <class T, class X> n inline T _pow(T a, X y) { n   T z = 1; n   for (int i = 1; i <= y; i++) { n     z *= a; n   } n   return z; n } n template <class T> n inline T _gcd(T a, T b) { n   a = _abs(a); n   b = _abs(b); n   if (!b) return a; n   return _gcd(b, a % b); n } n template <class T> n inline T _lcm(T a, T b) { n   a = _abs(a); n   b = _abs(b); n   return (a / _gcd(a, b)) * b; n } n template <class T> n inline T _extended(T a, T b, T &x, T &y) { n   a = _abs(a); n   b = _abs(b); n   T g, x1, y1; n   if (!b) { n     x = 1; n     y = 0; n     g = a; n     return g; n   } n   g = _extended(b, a % b, x1, y1); n   x = y1; n   y = x1 - (a / b) * y1; n   return g; n } n template <class T, class X> n inline bool getbit(T a, X i) { n   T t = 1; n   return ((a & (t << i)) > 0); n } n template <class T, class X> n inline T setbit(T a, X i) { n   T t = 1; n   return (a | (t << i)); n } n template <class T, class X> n inline T resetbit(T a, X i) { n   T t = 1; n   return (a & (~(t << i))); n } n template <class T, class X> n inline T togglebit(T a, X i) { n   T t = 1; n   return (a ^ (t << i)); n } n template <class T, class X, class Y> n inline T _bigmod(T n, X m, Y mod) { n   unsigned long long ret = 1, a = n % mod; n   while (m) { n     if (m & 1) ret = (ret * a) % mod; n     m >>= 1; n     a = (a * a) % mod; n   } n   ret %= mod; n   return (T)ret; n } n template <class T, class Y> n inline T _modinv(T n, Y mod) { n   return _bigmod(n, mod - 2, mod); n } n int main() { n   int n, cnt = 0; n   ; n   double x, tot = 0.0, ans, add; n   cin >> n; n   for (int i = 1; i <= n + n; i++) { n     cin >> x; n     add = (x - (int)x); n     tot += add; n     if (add == 0.0) cnt++; n   } n   tot -= n; n   while (cnt-- > 0 && tot < -.5) tot += 1.0; n   tot = fabs(tot); n   cout << setprecision(3) << fixed << tot << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n const int maxn = 1007; n long long dp[maxn][maxn][4]; n char s[maxn]; n int T, k; n long long dfs(int pos, int dis, int ok, int limit) { n   if (pos == -1) { n     return ok; n   } n   if (!limit && dp[pos][dis][ok] != -1) return dp[pos][dis][ok]; n   int up = limit ? s[pos] -  0  : 9; n   long long res = 0; n   for (int i = 0; i <= up; i++) { n     if (i != 4 && i != 7) n       res = (res + dfs(pos - 1, max(0, dis - 1), ok, limit && (i == up))) % MOD; n     else n       res = (res + dfs(pos - 1, k, ok || dis, limit && (i == up))) % MOD; n   } n   if (!limit) dp[pos][dis][ok] = res; n   return res; n } n int check(int len) { n   int pre = -1; n   for (int i = 0; i < len; i++) { n     if (s[i] ==  4  || s[i] ==  7 ) { n       if (pre != -1 && i - pre <= k) return 1; n       pre = i; n     } n   } n   return 0; n } n int main() { n   memset(dp, -1, sizeof(dp)); n   scanf( %d%d , &T, &k); n   while (T--) { n     scanf( %s , s); n     int len = strlen(s); n     for (int i = 0; i < len / 2; i++) swap(s[i], s[len - 1 - i]); n     long long ans = (dfs(len - 1, 0, 0, true) - check(len) + MOD) % MOD; n     scanf( %s , s); n     len = strlen(s); n     for (int i = 0; i < len / 2; i++) swap(s[i], s[len - 1 - i]); n     ans = (dfs(len - 1, 0, 0, true) - ans + MOD) % MOD; n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n clock_t time_p = clock(); n void timer() { n   time_p = clock() - time_p; n   cerr <<  Execution Time:   << (double)(time_p) / CLOCKS_PER_SEC <<   n ; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n, k, r = 2, g = 5, b = 8, cnt = 0, tot = 0; n   cin >> n >> k; n   r *= n; n   g *= n; n   b *= n; n   if (r % k) n     cnt += (r / k + 1); n   else n     cnt += r / k; n   if (g % k) n     cnt += (g / k + 1); n   else n     cnt += g / k; n   if (b % k) n     cnt += (b / k + 1); n   else n     cnt += b / k; n   cout << cnt; n   timer(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e3 + 6.66; n const int MAXM = 2e3 + 6.66; n const long long MOD = 1e9 + 7; n long long dp[MAXN][MAXM]; n long long dp1[MAXN][MAXM]; n long long par[MAXN][MAXM]; n long long par2[MAXN][MAXM]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n, m; n   cin >> n >> m; n   for (int sz = 0; sz < m - 1; sz++) dp[0][sz] = 1; n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j < m - 1; j++) { n       if (i == 1) { n         dp[i][j] = 1; n         dp1[i][j] = 1; n         par[i][j] = j + 1; n         par2[i][j] = par2[i][j - 1] + j + 1; n         continue; n       } n       dp1[i][j] = (1 + ((2 + j) * par[i - 1][j - 1]) % MOD * 1LL - n                    par2[i - 1][j - 1] * 1LL + MOD) % n                   MOD; n       dp[i][j] = n           (1 + ((2 + j) * par[i - 1][j]) % MOD - par2[i - 1][j] + MOD) % MOD; n       par[i][j] = (par[i][j - 1] + dp[i][j]) % MOD; n       par2[i][j] = (par2[i][j - 1] + (1LL * (j + 1LL) * dp[i][j]) % MOD) % MOD; n     } n   } n   long long ans = 0LL; n   for (int t = 0; t < n; t++) n     for (int sz = 0; sz < m - 1; sz++) { n       ans = (ans + n              (((m - sz - 1LL) * 1LL * dp[t + 1][sz]) % MOD * dp1[n - t][sz]) % n                  MOD) % n             MOD; n     } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long i, n, m, a[1000001], t1, t2, sum; n int main() { n   cin >> n >> m; n   for (i = 0; i < m; i++) { n     scanf( %I64d %I64d , &t1, &t2); n     a[t1]++; n     a[t2]++; n   } n   for (i = 1; i <= n; i++) sum += a[i] * (n - 1LL - a[i]); n   sum /= 2LL; n   cout << n * (n - 1LL) * (n - 2LL) / 6LL - sum << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000; n set<pair<long long, long long> > q; n long long prod(pair<long long, long long> a, pair<long long, long long> b) { n   return a.first * b.second - a.second * b.first; n } n bool check(pair<long long, long long> a, pair<long long, long long> b, n            pair<long long, long long> c) { n   return (prod({b.first - a.first, b.second - a.second}, n                {c.first - a.first, c.second - a.second}) > 0); n } n const long double eps = 1e-12; n void addPoint(long long x, long long y) { n   while (q.size()) { n     auto it = q.lower_bound({x, 0}); n     if (it != q.end() && it->first == x) { n       if (it->second > y) n         q.erase(it); n       else n         return; n     } else n       break; n   } n   auto it1 = q.lower_bound({x, 0}); n   if (it1 != q.end()) { n     if (it1->second <= y) return; n     auto it2 = q.lower_bound({x, 0}); n     it2--; n     if (!check(*it2, {x, y}, *it1)) return; n   } n   while (q.size() > 1) { n     auto it1 = q.lower_bound({x, 0}); n     if (it1 == q.end()) break; n     auto it2 = q.upper_bound(*it1); n     if (it2 == q.end()) break; n     if (!check({x, y}, *it1, *it2)) n       q.erase(it1); n     else n       break; n   } n   while (q.size()) { n     auto it1 = q.lower_bound({x, 0}); n     if (it1 == q.begin()) break; n     it1--; n     if (it1 == q.begin()) break; n     auto it2 = q.lower_bound({x, 0}); n     it2--; n     it2--; n     if (!check(*it2, *it1, {x, y})) n       q.erase(it1); n     else n       break; n   } n   q.insert({x, y}); n } n long long maxx = 0, yy = 0; n long double f(long double x) { n   if ((long double)q.rbegin()->first + eps < x) return 1e14; n   pair<int, int> it1 = *q.lower_bound({(long long)(x - eps), 0}); n   if (abs(it1.first - x) < eps) return it1.second; n   auto kek = q.lower_bound({(long long)(x - eps), 0}); n   kek--; n   pair<int, int> it2 = *kek; n   long double X = it1.first, Y = it1.second, XX = it2.first, YY = it2.second; n   long double a = YY - Y, b = X - XX, c = -a * X - b * Y; n   return (-a * x - c) / b; n } n int main() { n   ios::sync_with_stdio(0); n   int qq; n   long long m; n   cin >> qq >> m; n   int j = 0; n   q.insert({0, 0}); n   int k = 0; n   for (int i = 1; i <= qq; i++) { n     int k, a, b; n     cin >> k >> a >> b; n     if (k == 1) { n       long long x = (a + j) % MOD + 1; n       long long y = (b + j) % MOD + 1; n       if (x > maxx) { n         maxx = x; n         yy = y; n       } else if (x == maxx) n         yy = min(yy, y); n       addPoint(x, y); n     } else { n       k++; n       long long t = (a + j) % MOD + 1; n       long long h = (b + j) % MOD + 1; n       long long x = (h + t - 1) / t; n       auto it1 = q.lower_bound({x, 0}); n       bool ok = 0; n       if (it1 != q.end()) { n         auto it2 = prev(it1); n         long long a = it1->second - it2->second, b = it2->first - it1->first, n                   c = -it1->first * a - it1->second * b; n         if (b < 0) a *= -1, b *= -1, c *= -1; n         if (-a * h - c * t <= m * b) ok = true; n       } n       if (ok) { n         j = i; n         cout <<  YES n ; n       } else n         cout <<  NO n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 200005; n int N, M, K; n int A[MAXN]; n int B[MAXN]; n set<int> adj[MAXN]; n int deg[MAXN]; n set<pair<int, int> > st; n bool inGraph[MAXN]; n int ans[MAXN]; n void update(int x) { n   if (!inGraph[x]) return; n   set<pair<int, int> >::iterator it = st.find(make_pair(deg[x], x)); n   st.erase(it); n   deg[x]--; n   st.insert(make_pair(deg[x], x)); n } n void fix() { n   while (!st.empty() && st.begin()->first < K) { n     int cur = st.begin()->second; n     st.erase(st.begin()); n     inGraph[cur] = false; n     for (auto nxt : adj[cur]) { n       adj[nxt].erase(cur); n       update(nxt); n     } n     adj[cur].clear(); n   } n } n int main() { n   scanf( %d %d %d , &N, &M, &K); n   for (int i = 0; i < M; i++) { n     scanf( %d %d , &A[i], &B[i]); n     deg[A[i]]++; n     deg[B[i]]++; n     adj[A[i]].insert(B[i]); n     adj[B[i]].insert(A[i]); n   } n   for (int i = 1; i <= N; i++) { n     st.insert(make_pair(deg[i], i)); n     inGraph[i] = true; n   } n   for (int i = M - 1; i >= 0; i--) { n     fix(); n     ans[i] = st.size(); n     adj[A[i]].erase(B[i]); n     adj[B[i]].erase(A[i]); n     if (inGraph[B[i]]) update(A[i]); n     if (inGraph[A[i]]) update(B[i]); n   } n   for (int i = 0; i < M; i++) printf( %d n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC target( avx2 ) n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long k; n   cin >> k; n   long long pref = 0; n   vector<long long> poww10(17); n   poww10[0] = 1; n   for (int i = 1; i < 17; i++) { n     poww10[i] = poww10[i - 1] * 10; n   } n   for (int len = 1; len <= 15; len++) { n     if (pref + len * (poww10[len] - poww10[len - 1]) >= k) { n       k -= pref; n       long long l = 0, r = poww10[len] - poww10[len - 1]; n       while (l + 1 < r) { n         long long mid = (l + r) / 2; n         if (len * mid < k) { n           l = mid; n         } else { n           r = mid; n         } n       } n       k -= len * l; n       cout << to_string(poww10[len - 1] + l)[k - 1] <<   n ; n       return 0; n     } n     pref += len * (poww10[len] - poww10[len - 1]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int l, r, x, y; n vector<int> primes; n int cnt(int idx, int a, int b) { n   if (idx == primes.size()) return a >= l && a <= r && b >= l && b <= r; n   return cnt(idx + 1, a * primes[idx], b) + cnt(idx + 1, a, b * primes[idx]); n } n int main() { n   cin >> l >> r >> x >> y; n   if (y % x) return puts( 0 ); n   y /= x; n   for (int i = 2; i * i <= y; i++) { n     int v = 1; n     while (y % i == 0) y /= i, v *= i; n     if (v > 1) primes.push_back(v); n   } n   if (y > 1) primes.push_back(y); n   cout << cnt(0, x, x); n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); n const ld pi = acos(0) * 2; n template <typename T> n inline void read(T &x) { n   char c; n   bool nega = 0; n   while ((!isdigit(c = getchar())) && (c !=  - )) n     ; n   if (c ==  - ) { n     nega = 1; n     c = getchar(); n   } n   x = c - 48; n   while (isdigit(c = getchar())) x = x * 10 + c - 48; n   if (nega) x = -x; n } n template <typename T> n inline void writep(T x) { n   if (x > 9) writep(x / 10); n   putchar(x % 10 + 48); n } n template <typename T> n inline void write(T x) { n   if (x < 0) { n     putchar( - ); n     x = -x; n   } n   writep(x); n } n template <typename T> n inline void writeln(T x) { n   write(x); n   putchar(  n ); n } n int n, m; n int r[500001]; n int root(int u) { n   if (r[u] < 0) return u; n   return r[u] = root(r[u]); n } n bool unite(int u, int v) { n   u = root(u); n   v = root(v); n   if (u == v) return 0; n   if (r[u] > r[v]) swap(u, v); n   r[u] += r[v]; n   r[v] = u; n   return 1; n } n int main() { n   read(n); n   read(m); n   for (int i = (1); i <= (n); i++) r[i] = -1; n   for (int i = (1); i <= (m); i++) { n     int k; n     read(k); n     int v = -1; n     int u; n     for (int i = (1); i <= (k); i++) { n       read(u); n       if (v != -1) n         unite(u, v); n       else n         v = u; n     } n   } n   for (int i = (1); i <= (n); i++) { n     write(-r[root(i)]); n     putchar(   n [i == n]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct graph { n   int n; n   vector<vector<int>> adj; n   graph(int n) : n(n), adj(n) {} n   void add_edge(int u, int v) { adj[u].push_back(v); } n   vector<int> &operator[](int u) { return adj[u]; } n }; n vector<vector<int>> scc_gabow(graph &adj) { n   int n = adj.n; n   vector<vector<int>> scc; n   vector<int> S, B, I(n); n   function<void(int)> dfs = [&](int u) { n     B.push_back(I[u] = S.size()); n     S.push_back(u); n     for (int v : adj[u]) n       if (!I[v]) n         dfs(v); n       else n         while (I[v] < B.back()) B.pop_back(); n     if (I[u] == B.back()) { n       scc.push_back({}); n       for (B.pop_back(); I[u] < S.size(); S.pop_back()) { n         scc.back().push_back(S.back()); n         I[S.back()] = n + scc.size(); n       } n     } n   }; n   for (int u = 0; u < n; ++u) n     if (!I[u]) dfs(u); n   return scc; n } n const long long mod = 1000000007; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   vector<long long> a(n); n   for (int i = 0; i < n; ++i) cin >> a[i]; n   graph adj(n); n   int m; n   cin >> m; n   for (int i = 0; i < m; ++i) { n     int u, v; n     cin >> u >> v; n     adj.add_edge(--u, --v); n   } n   auto scc = scc_gabow(adj); n   long long mn = 0, ways = 1; n   for (auto &comp : scc) { n     long long best = a[comp[0]], total = 0; n     for (int u : comp) n       if (a[u] == best) n         ++total; n       else if (a[u] < best) n         best = a[u], total = 1; n     mn += best; n     ways = ways * total % mod; n   } n   cout << mn <<     << ways <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5005; n short dp[N][N]; n int ans[N]; n int main() { n   string s; n   cin >> s; n   int n; n   n = s.size(); n   for (int len = 1; len <= n; len++) { n     for (int l = 0; l < n - len + 1; l++) { n       int r = l + len; n       if (len == 1) { n         dp[l][r] = 1; n         continue; n       } else if (len == 2) { n         dp[l][r] = (s[l] == s[r - 1] ? 2 : 0); n         continue; n       } n       if (s[l] != s[r - 1] || !dp[l + 1][r - 1]) { n         continue; n       } n       dp[l][r] = 1; n       int m = (l + r) >> 1; n       if (len & 1) { n         if (dp[l][m] && dp[m + 1][r]) { n           dp[l][r] = dp[l][m] + 1; n         } n       } else { n         if (dp[l][m] && dp[m][r]) { n           dp[l][r] = dp[l][m] + 1; n         } n       } n     } n   } n   for (int len = 1; len <= n; len++) { n     for (int l = 0; l < n - len + 1; l++) { n       ans[dp[l][l + len]]++; n     } n   } n   for (int i = n - 1; i >= 1; i--) { n     ans[i] += ans[i + 1]; n   } n   for (int i = 1; i <= n; i++) { n     cout << ans[i] <<    ; n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long fastpower(long a, long b, long long n = 1000000007) { n   long res = 1; n   while (b > 0) { n     if ((b & 1) != 0) { n       res = (res % n * a % n) % n; n     } n     a = (a % n * a % n) % n; n     b = b >> 1; n   } n   return res; n } n bool isPrime(long long n) { n   if (n <= 3) return n > 1; n   if (n % 2 == 0 || n % 3 == 0) return false; n   for (long long i = 5; i * i <= n; i += 6) n     if (n % i == 0 || n % (i + 2) == 0) return false; n   return true; n } n long long gcd(long long a, long long b) { n   long long c = a % b; n   while (c != 0) { n     a = b; n     b = c; n     c = a % b; n   } n   return b; n } n int32_t main() { n   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); n   long long t = 1; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     long long count = 1, i = 0; n     while (count <= n) { n       i++; n       count = i * i; n       if (count == n) { n         i--; n         break; n       } else if (count > n) { n         i--; n         break; n       } n     } n     count = i * i; n     long long x = 1, y = i + 1; n     for (long long j = count + 1; j <= (i + 1) * (i + 1); j++) { n       if (j == n) { n         cout << x <<     << y <<   n ; n         break; n       } else { n         if (x >= i + 1) y--; n         if (x < i + 1) x++; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool compare(pair<pair<long long int, long long int>, long long int> p1, n              pair<pair<long long int, long long int>, long long int> p2) { n   return p1.first.first < p2.first.first; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int i, te, j, x, n, m, k, t, y, a, b, r; n   te = 1; n   while (te--) { n     string s; n     cin >> s; n     n = s.length(); n     long long int a[n], c[n], ans = 0, cnt = 0, co = 0; n     for (i = 0; i < n; i++) { n       if (s[i] ==  o ) co++; n       c[i] = co; n     } n     for (i = n - 1; i >= 0; i--) { n       if (s[i] ==  o ) { n         ans += cnt; n       } n       if (s[i] ==  v  && s[i - 1] ==  v  && i >= 1) { n         cnt++; n       } n       a[i] = ans; n     } n     cnt = 0; n     for (i = 0; i <= n - 1; i++) { n       if (s[i] ==  v  && s[i + 1] ==  v ) { n         cnt += a[i]; n       } n     } n     cout << cnt <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   int q; n   cin >> q; n   while (q--) { n     int n; n     cin >> n; n     long long l = 0, r = n + 1; n     while (r - l > 1) { n       long long k = (l + r) >> 1; n       if ((long long)(n - k) * (n - k - 1) >= 2LL * k) n         l = k; n       else n         r = k; n     } n     long long ans = 2 * l; n     for (int i = l + 1; n          i < n && (long long)i + (long long)(n - i) * (n - i - 1) / 2 > ans; n          i++) n       ans = (long long)i + (long long)(n - i) * (n - i - 1) / 2; n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int countBits(long long mask) { n   int res = 0; n   while (mask) mask &= (mask - 1), ++res; n   return res; n } n string toString(long long n) { n   stringstream ss; n   ss << n; n   return ss.str(); n } n long long toNumber(string s) { n   stringstream ss; n   long long n; n   ss << s; n   ss >> n; n   return n; n } n int n, p[1001], dp[1001]; n int main() { n   while (cin >> n) { n     for (int i = (int)(1), _m = (int)(n + 1); i < _m; ++i) cin >> p[i]; n     for (int i = (int)(1), _m = (int)(n + 1); i < _m; ++i) { n       dp[i] = 1; n       if (i != p[i]) n         for (int j = (int)(p[i]), _m = (int)(i); j < _m; ++j) n           dp[i] = (dp[i] + dp[j] + 1) % 1000000007; n     } n     int res = 0; n     for (int i = (int)(1), _m = (int)(n + 1); i < _m; ++i) n       res = (res + dp[i] + 1) % 1000000007; n     cout << res << endl; n   } n } n


#include <bits/stdc++.h> n const long long mod = 998244853; n long long C[5050][5050], n, m, g[5050], ans; n signed main() { n   scanf( %lld%lld , &n, &m); n   for (long long i = 0; i <= n + m; i++) { n     C[i][0] = 1; n     for (long long j = 1; j <= i; j++) n       C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod; n   } n   for (long long i = 0; i <= n; i++) n     if (i <= n - m) n       g[i] = C[n + m][n]; n     else n       g[i] = C[n + m][m + i]; n   for (long long i = 0; i <= n; i++) n     (ans += i * ((g[i] - g[i + 1] + mod) % mod) % mod) %= mod; n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 2147383647; n const double pi = 2 * acos(0.0); n const double eps = 1e-9; n struct debugger { n   template <typename T> n   debugger& operator,(const T& v) { n     cerr << v <<    ; n     return *this; n   } n } dbg; n inline long long gcd(long long a, long long b) { n   a = ((a) < 0 ? -(a) : (a)); n   b = ((b) < 0 ? -(b) : (b)); n   while (b) { n     a = a % b; n     swap(a, b); n   } n   return a; n } n int ext_gcd(int a, int b, int& x, int& y) { n   if (a == 0) { n     x = 0; n     y = 1; n     return b; n   } n   int x1, y1; n   int d = ext_gcd(b % a, a, x1, y1); n   x = y1 - (b / a) * x1; n   y = x1; n   return d; n } n inline long long modInv(int a, int m) { n   int x, y; n   ext_gcd(a, m, x, y); n   if (x < 0) x += m; n   return x; n } n inline long long power(long long a, long long p) { n   long long res = 1, x = a; n   while (p) { n     if (p & 1) res = (res * x); n     x = (x * x); n     p >>= 1; n   } n   return res; n } n inline long long bigmod(long long a, long long p, long long m) { n   long long res = 1, x = a % m; n   while (p) { n     if (p & 1) res = (res * x) % m; n     x = (x * x) % m; n     p >>= 1; n   } n   return res; n } n char buf[60][30]; n long long mask[1 << 20]; n int m; n double q; n double memo[1 << 20]; n int done[1 << 20]; n double dp(int mk) { n   int pop = 0; n   if (mask[mk]) pop = __builtin_popcountll(mask[mk]); n   int pop2 = __builtin_popcountll(mk); n   if (pop <= 1) return 0; n   if (done[mk]) return memo[mk]; n   double p = 1.0 / (m - pop2); n   double res = 0; n   for (int i = (0); i <= (m - 1); ++i) { n     if (mk & (1 << i)) continue; n     res += p * dp(mk | (1 << i)); n     long long x = mask[mk | (1 << i)]; n     x = x ^ mask[mk]; n     x = __builtin_popcountll(x); n     res += p * x * q * (pop2 + 1); n   } n   done[mk] = 1; n   return memo[mk] = res; n } n int main() { n   int n; n   scanf( %d , &n); n   q = 1.0 / n; n   for (int i = (0); i <= (n - 1); ++i) { n     scanf( %s , &buf[i][0]); n   } n   m = strlen(&buf[0][0]); n   for (int i = (0); i <= (n - 1); ++i) { n     for (int j = (i + 1); j <= (n - 1); ++j) { n       int tmask = 0; n       for (int k = (0); k <= (m - 1); ++k) { n         if (buf[i][k] == buf[j][k]) tmask |= (1LL << k); n       } n       mask[tmask] |= (1LL << i); n       mask[tmask] |= (1LL << j); n     } n   } n   int limit = 1 << m; n   for (int i = (limit - 1); i >= (0); --i) { n     for (int k = (0); k <= (m - 1); ++k) { n       if (i & (1 << k)) { n         mask[i ^ (1 << k)] |= mask[i]; n       } n     } n   } n   double res = dp(0); n   printf( %.10lf n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using vint = vector<int>; n using pint = pair<int, int>; n using vpint = vector<pint>; n template <typename A, typename B> n inline void chmin(A& a, B b) { n   if (a > b) a = b; n } n template <typename A, typename B> n inline void chmax(A& a, B b) { n   if (a < b) a = b; n } n template <class A, class B> n ostream& operator<<(ostream& ost, const pair<A, B>& p) { n   ost <<  {  << p.first <<  ,  << p.second <<  } ; n   return ost; n } n template <class T> n ostream& operator<<(ostream& ost, const vector<T>& v) { n   ost <<  { ; n   for (int i = 0; i < v.size(); i++) { n     if (i) ost <<  , ; n     ost << v[i]; n   } n   ost <<  } ; n   return ost; n } n inline int topbit(unsigned long long x) { n   return x ? 63 - __builtin_clzll(x) : -1; n } n inline int popcount(unsigned long long x) { return __builtin_popcountll(x); } n inline int parity(unsigned long long x) { return __builtin_parity(x); } n const int INF = 1001001001; n const int X = 30000; n int N, D; n int cnt[33333]; n const int B = 300; n int dp[X + 1][B]; n map<int, int> dp2[X + 1]; n signed main() { n   cin >> N >> D; n   for (int i = 0; i < (N); i++) { n     int p; n     cin >> p; n     cnt[p]++; n   } n   fill_n(*dp, (X + 1) * B, -INF); n   if (D >= B) { n     dp2[D][D] = 0; n   } else { n     dp[D][D] = 0; n   } n   int ans = 0; n   for (int i = D; i <= X; i++) { n     for (int j = 1; j < B; j++) { n       if (dp[i][j] == -INF) continue; n       dp[i][j] += cnt[i]; n       chmax(ans, dp[i][j]); n       for (int k = -1; k <= 1; k++) { n         int d = j + k; n         if (d <= 0 || i + d > X) continue; n         if (d < B) n           chmax(dp[i + d][d], dp[i][j]); n         else n           chmax(dp2[i + d][d], dp[i][j]); n       } n     } n     for (auto& p : dp2[i]) { n       p.second += cnt[i]; n       int j = p.first; n       chmax(ans, p.second); n       for (int k = -1; k <= 1; k++) { n         int d = j + k; n         if (d <= 0 || i + d > X) continue; n         if (d < B) n           chmax(dp[i + d][d], p.second); n         else n           chmax(dp2[i + d][d], p.second); n       } n     } n   } n   cout << ans << endl; n   return 0; n } n