#include <bits/stdc++.h> n using namespace std; n using ll = long long; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0), cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int b[8]; n     for (int i = 1; i <= 7; ++i) cin >> b[i]; n     int first = b[7] - b[6]; n     int last = b[7] - b[5]; n     cout << first <<     << b[7] - (first + last) <<     << last << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline void read(int &x) { n   x = 0; n   int f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   x *= f; n } n inline void judge() { n   freopen( in.txt ,  r , stdin); n   freopen( out.txt ,  w , stdout); n } n const int maxn = 100005; n int fac[maxn], facinv[maxn]; n const int mod = 1e9 + 7; n inline int powmod(int a, int b) { n   int res = 1; n   for (; b; b >>= 1) { n     if (b & 1) res = 1ll * res * a % mod; n     a = 1ll * a * a % mod; n   } n   return res; n } n inline void prprpr() { n   fac[0] = 1; n   for (int i = (1); i <= (100000); i++) fac[i] = 1ll * fac[i - 1] * i % mod; n   for (int i = (0); i <= (100000); i++) facinv[i] = powmod(fac[i], mod - 2); n } n inline int C(int n, int m) { n   return 1ll * fac[n] * facinv[m] % mod * facinv[n - m] % mod; n } n inline int Gans(int x, int n, int *a) { n   if (n < x) return 0; n   return a[n - x + 1] * 1ll * powmod(26, n) % mod; n } n inline void calc(int x, int *&a) { n   a = (int *)malloc(140005 * sizeof(int)); n   int inv = powmod(26, mod - 2); n   int v1 = powmod(inv, x), v2 = 1; n   for (int i = (x); i <= (100000); i++) { n     a[i - x + 1] = 1ll * C(i - 1, x - 1) * v2 % mod * v1 % mod; n     v1 = 1ll * v1 * inv % mod; n     v2 = 1ll * v2 * (26 - 1) % mod; n     a[i - x + 1] = (a[i - x + 1] + a[i - x]) % mod; n   } n } n char s[maxn]; n int nowlen; n map<int, int *> zball; n int main() { n   prprpr(); n   int m; n   read(m); n   scanf( %s , s + 1); n   nowlen = strlen(s + 1); n   calc(nowlen, zball[nowlen]); n   for (int i = (1); i <= (m); i++) { n     int x; n     read(x); n     if (x == 2) { n       int v; n       read(v); n       printf( %d n , Gans(nowlen, v, zball[nowlen])); n     } else { n       scanf( %s , s + 1); n       nowlen = strlen(s + 1); n       if (!zball.count(nowlen)) calc(nowlen, zball[nowlen]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string arr[11] = { ABSINTH ,  BEER ,     BRANDY ,  CHAMPAGNE ,  GIN ,  RUM , n                      SAKE ,     TEQUILA ,  VODKA ,   WHISKEY ,    WINE }; n   int n; n   cin >> n; n   int counter = 0; n   string str; n   int num_convert; n   for (int i = 0; i < n; i++) { n     str =   ; n     cin >> str; n     if (isdigit(str.at(0))) { n       num_convert = stoi(str, nullptr, 10); n       if (num_convert < 18) { n         counter++; n       } n     } else { n       for (int i = 0; i < 11; i++) { n         if (str == arr[i]) { n           counter++; n         } n       } n     } n   } n   cout << counter; n } n


#include <bits/stdc++.h> n const int LIM = 1e5 + 5; n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   cin >> n; n   vector<int> x(n), y(n); n   for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; n   if (n % 2) { n     cout <<  NO ; n     return 0; n   } else { n     int mid = n / 2; n     for (int i = 0; i < mid - 1; i++) { n       if (x[i] - x[i + 1] == x[i + mid + 1] - x[i + mid] && n           y[i] - y[i + 1] == y[i + mid + 1] - y[i + mid]) { n         continue; n       } else { n         cout <<  NO ; n         return 0; n       } n     } n     cout <<  YES ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool isp(const int x) { n   if (x <= 1) return false; n   for (int i = 2; i * i <= x; ++i) n     if (x % i == 0) return false; n   return true; n } n int pow(int x, int e, const int MOD) { n   int r = 1; n   for (; e; e >>= 1, x = (long long)x * x % MOD) n     if (e & 1) r = (long long)r * x % MOD; n   return r; n } n bool isr(int n, int p) { n   for (int i = 2, q = p - 1; i * i <= q; ++i) n     if (q % i == 0) { n       if (pow(n, i, p) == 1 || pow(n, q / i, p) == 1) return false; n     } n   return true; n } n int main() { n   int n, x; n   scanf( %d%d , &n, &x); n   if (!isp(n + 1)) return puts( -1 ), 0; n   for (--x; x > 1; --x) n     if (isr(x, n + 1)) return printf( %d n , x), 0; n   return puts( -1 ), 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long read() { n   long long x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = (x << 3) + (x << 1) + (ch ^ 48); n     ch = getchar(); n   } n   return x * f; n } n long long n, w, b, x, c[1005], cost[1005], f[1005][10005], C, a[10005], tot; n long long cmp(long long x, long long y) { return x > y; } n signed main() { n   n = read(); n   w = read(); n   b = read(); n   x = read(); n   for (long long i = 1; i <= n; i++) c[i] = read(), C += c[i]; n   for (long long i = 1; i <= n; i++) cost[i] = read(); n   memset(f, -0x3f, sizeof(f)); n   f[0][0] = w; n   for (long long i = 1; i <= n; i++) { n     if (i != 1) n       for (long long j = 0; j <= C; j++) n         f[i][j] = min(f[i - 1][j] + x, w + b * j); n     else n       for (long long j = 0; j <= C; j++) f[i][j] = f[i - 1][j]; n     tot = 0; n     for (long long k = 1; k <= c[i]; k *= 2) { n       a[++tot] = k; n       c[i] -= k; n     } n     if (c[i]) a[++tot] = c[i]; n     sort(a + 1, a + tot + 1, cmp); n     for (long long k = 1; k <= tot; k++) { n       for (long long j = C; j >= a[k]; j--) { n         if (f[i][j - a[k]] >= cost[i] * a[k]) n           f[i][j] = max(f[i][j], f[i][j - a[k]] - cost[i] * a[k]); n       } n     } n   } n   long long ans = 0; n   for (long long i = C; i >= 0; i--) { n     if (f[n][i] >= 0) { n       ans = i; n       break; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void no() { cout <<  NO  << endl; } n void yes() { cout <<  YES  << endl; } n int main() { n   int q, n, wyn; n   cin >> q; n   for (int i = 0; i < q; i++) { n     cin >> n; n     char a; n     string s; n     cin >> a; n     cin >> s; n     if (s.length() == 1 && a >= s[0]) n       no(); n     else { n       yes(); n       cout << 2 << endl; n       cout << a <<   n  << s << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 10000; n int degree[maxn + 5]; n int Cn_i(int n, int i) { n   int up = 1; n   int down = 1; n   for (int t = n; t >= n - i + 1; t--) { n     up = up * t; n   } n   for (int t = i; t >= 1; t--) { n     down = down * t; n   } n   return up / down; n } n int main() { n   int n; n   while (scanf( %d , &n) != EOF) { n     for (int i = 0; i < n; i++) degree[i] = 0; n     for (int i = 0; i < n - 1; i++) { n       int a, b; n       scanf( %d%d , &a, &b); n       degree[a]++; n       degree[b]++; n     } n     int ans = 0; n     for (int i = 0; i <= n; i++) { n       if (degree[i] >= 2) { n         ans += Cn_i(degree[i], 2); n       } n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n, m; n     cin >> n >> m; n     if (n * m % 2 == 1) n       cout << n * m / 2 + 1 << endl; n     else n       cout << n * m / 2 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int F[60][60], f[60][60], g[60][60], h[60][60], dp[60][60], fac[60], inv[60], n     mod = 1000000007; n int fpow(int a, int b) { n   int ans = 1, t = a; n   while (b) { n     if (b & 1) ans = 1ll * ans * t % mod; n     t = 1ll * t * t % mod; n     b >>= 1; n   } n   return ans; n } n int calc(int n, int m, int a, int b) { n   int ans = 0; n   int cur = 1; n   for (int i = 0; i * a <= n && i * b <= m; i++) { n     ans = (ans + 1ll * dp[n - i * a][m - i * b] * cur % mod * inv[i]) % mod; n     cur = 1ll * cur * (g[a][b] + i) % mod; n   } n   return ans; n } n int main() { n   fac[0] = inv[0] = 1; n   for (int i = 1; i <= 51; i++) { n     fac[i] = 1ll * fac[i - 1] * i % mod; n     inv[i] = fpow(fac[i], mod - 2); n   } n   int n, m; n   scanf( %d%d , &n, &m); n   f[0][1] = 1; n   dp[0][0] = 1; n   for (int i = 1; i <= n; i++) { n     for (int j = n + 1; j >= 1; j--) { n       F[i - 1][j] = (F[i - 1][j + 1] + f[i - 1][j]) % mod; n     } n     for (int j = n + 1; j >= 1; j--) { n       h[i][j] = 0; n       for (int k = 0; k < i; k++) { n         h[i][j] = (h[i][j] + 1ll * F[k][j] * F[i - k - 1][j]) % mod; n       } n       g[i][j] = (h[i][j] - h[i][j + 1] + mod) % mod; n     } n     for (int j = 1; j <= n + 1; j++) { n       for (int x = n; x >= 0; x--) { n         for (int y = n + 1; y >= 0; y--) { n           dp[x][y] = calc(x, y, i, j); n         } n       } n     } n     for (int j = 1; j <= n + 1; j++) { n       f[i][j] = dp[i][j - 1]; n     } n   } n   printf( %d n , f[n][m]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n char s[maxn]; n int size[maxn], last[200]; n bool isover[maxn]; n string ans[maxn], now; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0), cout.tie(0); n   cin >> s; n   int len = strlen(s); n   bool hasdel = false; n   now =   ; n   for (int no = len - 1; ~no; no--) { n     now = s[no] + now; n     if (now.size() > 1) { n       if (now[0] != now[1]) last[now[0]] = now[1]; n     } n     if (now.size() > 1 && !hasdel) { n       if (now[0] == now[1] && now[1] > last[now[1]]) { n         now = now.substr(2); n         hasdel = true; n       } n     } else n       hasdel = false; n     size[no] = now.size(); n     if (now.size() > 10) n       ans[no] = now.substr(0, 5) +  ...  + now.substr(now.size() - 2); n     else n       ans[no] = now; n   } n   for (int i = 0; i < len; i++) { n     cout << size[i] <<     << ans[i] <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> children[1000005]; n int r_1[1000005], r_2[1000005], timer, n, k, p[1000005], mx[1000005 << 2], n     inc[1000005 << 2]; n stack<int> seq; n vector<int> ans; n void dfs(int node) { n   timer++; n   r_1[node] = timer; n   for (int i = 0; i < children[node].size(); i++) { n     int neb = children[node][i]; n     dfs(neb); n   } n   r_2[node] = timer; n } n int rt(int r1, int r2, int q1, int q2, int ind, int typ) { n   if (q1 > q2) return 0; n   if (q1 > r2 || q2 < r1) return 0; n   if (q1 <= r1 && q2 >= r2) { n     inc[ind] += typ; n     return inc[ind] + mx[ind]; n   } else { n     inc[ind * 2] += inc[ind]; n     inc[ind * 2 + 1] += inc[ind]; n     inc[ind] = 0; n     int mid = (r1 + r2) / 2; n     int left = 0, right = 0; n     left = rt(r1, mid, q1, q2, ind * 2, typ); n     right = rt(mid + 1, r2, q1, q2, ind * 2 + 1, typ); n     mx[ind] = n         max(mx[ind * 2] + inc[ind * 2], mx[ind * 2 + 1] + inc[ind * 2 + 1]); n     return max(left, right); n   } n } n int main() { n   scanf( %d %d , &n, &k); n   for (int i = 0; i < n; i++) scanf( %d , &p[i]); n   p[n] = n + 1; n   for (int i = 0; i <= n; i++) { n     while (seq.size()) { n       int top = seq.top(); n       if (p[top] >= p[i]) break; n       children[i].push_back(top); n       seq.pop(); n     } n     seq.push(i); n   } n   dfs(n); n   for (int i = n - 1; i >= 0; i--) { n     if (i + k <= n) { n       ans.push_back(rt(1, timer, r_1[i + k - 1], r_1[i], 1, 0) + 1); n       rt(1, timer, r_1[i + k - 1] + 1, r_2[i + k - 1], 1, -1); n     } n     rt(1, timer, r_1[i] + 1, r_2[i], 1, 1); n   } n   reverse(ans.begin(), ans.end()); n   for (int i = 0; i < ans.size(); i++) { n     printf( %d  , ans[i]); n   } n   printf(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> gph[500005]; n int n, par[500005], dep[500005], msk[500005]; n int dp[500005], sz[500005]; n int mx[1 << 22]; n int l[23] = {}; n void dfs2(int x, vector<pair<int, int> > &v) { n   v.push_back(pair<int, int>(dep[x], msk[x])); n   for (auto &i : gph[x]) dfs2(i, v); n } n void dfs(int x) { n   if (gph[x].empty()) { n     mx[msk[x]] = dep[x]; n     return; n   } n   for (int i = 1; i < gph[x].size(); i++) { n     dfs(gph[x][i]); n     vector<pair<int, int> > w; n     dfs2(gph[x][i], w); n     for (auto &j : w) mx[j.second] = -1; n   } n   dfs(gph[x][0]); n   for (int i = 1; i < gph[x].size(); i++) { n     vector<pair<int, int> > w; n     dfs2(gph[x][i], w); n     for (auto &j : w) { n       for (int k = 0; k < 23; k++) { n         int val = mx[j.second ^ l[k]]; n         if (~val) dp[x] = max(dp[x], j.first + val - 2 * dep[x]); n       } n     } n     for (auto &j : w) mx[j.second] = max(mx[j.second], j.first); n   } n   for (int k = 0; k < 23; k++) { n     if (mx[msk[x] ^ l[k]] != -1) { n       dp[x] = max(dp[x], mx[msk[x] ^ l[k]] - dep[x]); n     } n   } n   mx[msk[x]] = max(mx[msk[x]], dep[x]); n } n int main() { n   scanf( %d , &n); n   char ch[6]; n   for (int i = 0; i < 22; i++) l[i] = (1 << i); n   for (int i = 2; i <= n; i++) { n     scanf( %d %s , &par[i], ch); n     gph[par[i]].push_back(i); n     dep[i] = dep[par[i]] + 1; n     msk[i] = msk[par[i]] ^ (1 << (*ch -  a )); n   } n   for (int i = n; i; i--) { n     sz[i] = 1; n     for (auto &j : gph[i]) sz[i] += sz[j]; n     sort(gph[i].begin(), gph[i].end(), n          [&](const int &a, const int &b) { return sz[a] > sz[b]; }); n   } n   memset(mx, -1, sizeof(mx)); n   dfs(1); n   for (int i = n; i; i--) { n     for (auto &j : gph[i]) dp[i] = max(dp[i], dp[j]); n   } n   for (int i = 1; i <= n; i++) printf( %d  , dp[i]); n } n


#include <vector> n #include <array> n #include <stack> n #include <queue> n #include <list> n #include <bitset> n #include <set> n #include <map> n #include <unordered_set> n #include <unordered_map> n #include <algorithm> n #include <numeric> n #include <iostream> n #include <iomanip> n #include <string> n #include <chrono> n #include <random> n #include <cmath> n #include <cassert> n #include <climits> n #include <cstring> n #include <cstdlib> n #include <functional> n #include <sstream> n  n using namespace std; n  n const long long MOD = 998244353; n  n vector<vector<int>> matXmat(const vector<vector<int>>& A, const vector<vector<int>>& B, long long M = MOD) { n     int n = A.size(); n     assert(n != 0); n     assert(A[0].size() == B.size()); n     int l = B.size(); n     assert(l != 0); n     int m = B[0].size(); n     assert(m != 0); n  n     vector<vector<int>> res(n, vector<int>(m, 0)); n  n     long long MOD2 = M * 1LL * M; n     for (int i = 0; i < n; ++i) { n         for (int j = 0; j < l; ++j) { n             for (int k = 0; k < m; ++k) { n                 res[i][k] += A[i][j] * 1LL * B[j][k] % M; n                 if (res[i][k] >= M) { n                     res[i][k] -= M; n                 } n                 if (res[i][k] < 0) { n                     res[i][k] += M; n                 } n             } n         } n     } n     return res; n } n  n  n vector<long long> __tmpA(500, 0); n vector<vector<int>> matXmat2(const vector<vector<int>>& A, const vector<vector<int>>& B, long long M = MOD) { n     int n = A.size(); n     assert(n != 0); n     assert(A[0].size() == B.size()); n     int l = B.size(); n     assert(l != 0); n     int m = B[0].size(); n     assert(m != 0); n  n     vector<vector<int>> res(n, vector<int>(m, 0)); n  n     long long MOD2 = M * 1LL * M; n     for (int i = 0; i < n; ++i) { n         for (int k = 0; k < m; ++k) { n             __tmpA[k] = 0; n         } n         for (int j = 0; j < l; ++j) { n             for (int k = 0; k < m; ++k) { n                 __tmpA[k] += A[i][j] * 1LL * B[j][k]; n                 if (__tmpA[k] >= MOD2) { n                     __tmpA[k] -= MOD2; n                 } n             } n         } n         for (int k = 0; k < m; ++k) { n             if (__tmpA[k] >= MOD) { n                 res[i][k] = __tmpA[k] % MOD; n             } else { n                 res[i][k] = __tmpA[k]; n             } n         } n     } n     return res; n } n  n vector<int> matXvec(const vector<vector<int>>& A, const vector<int>& B, long long M = MOD) { n     int n = A.size(); n     assert(n != 0); n     int m = A[0].size(); n     assert(m == B.size()); n  n     vector<int> res(n, 0); n  n     long long MOD2 = M * 1LL * M; n     for (int i = 0; i < n; ++i) { n         long long ans = 0; n         for (int j = 0; j < m; ++j) { n             ans += A[i][j] * 1LL * B[j]; n             if (ans >= MOD2) { n                 ans -= MOD2; n             } n             if (ans < 0) { n                 ans += MOD2; n             } n         } n         ans %= M; n         if (ans < 0) { n             ans += M; n         } n         res[i] = ans; n     } n     return res; n } n  n vector<vector<int>> matPow(vector<vector<int>> A, long long n, long long M = MOD) { n     int m = A.size(); n     assert(m != 0 && A[0].size() == m); n     vector<vector<int>> res(m, vector<int>(m, 0)); n     for (int i = 0; i < m; ++i) { n         res[i][i] = 1; n     } n  n     while (n > 0) { n         if (n & 1) { n             res = matXmat2(res, A, M); n         } n         A = matXmat2(A, A, M); n         n >>= 1; n     } n     return res; n } n  n  n class Trie{ n     public: n         Trie(int n = 110000) : N(n), nodes(n), rt(-1), idx(-1) { n             rt = newNode(); n         } n  n         void reset() { n             for (int i = 0; i <= idx; ++i) { n                 nodes[i].reset(); n             } n             idx = -1; n             rt = newNode(); n         } n  n  n         int root() { return rt; } n  n         int index(char ch) { n             return ch -  a ; n         } n  n         void insert(string& s) { n             int cur = rt; n             for (auto c : s) { n                 c = index(c); n                 if (nodes[cur].nexts[c] == -1) { n                     nodes[cur].nexts[c] = newNode(); n                 } n                 cur = nodes[cur].nexts[c]; n                 nodes[cur].cnt += 1; n             } n             nodes[cur].isEnd = true; n         } n  n  n         bool query(string& s) { n             int cur = rt; n             for (auto c : s) { n                 c = index(c); n                 if (nodes[cur].nexts[c] == -1) { n                     return false; n                 } n                 cur = nodes[cur].nexts[c]; n             } n             return nodes[cur].isEnd; n         } n  n         int next(int r, char ch) { n             ch = index(ch); n             return nodes[r].nexts[ch]; n         } n  n         bool isEnd(int u) { n             return nodes[u].isEnd; n         } n  n  n     private: n         const static int A = 26; n         struct Node { n             Node() : cnt(0), isEnd(false) {  n                 fill(begin(nexts), end(nexts), -1); n             } n  n             void reset() { n                 cnt = 0; n                 isEnd = false; n                 fill(begin(nexts), end(nexts), -1); n             } n  n             int nexts[A]; n             int cnt; n             bool isEnd; n         }; n  n         int N; n         int rt; n         int idx; n         vector<Node> nodes; n  n         int newNode() { n             return ++idx; n         } n }; n  n class Solution { n public: n     long long solve(vector<string>& S, int m) { n         int n = S.size(); n  n         Trie tr(2000); n         for (auto s : S) { n             tr.insert(s); n         } n         const int N = 100; n         vector<vector<vector<pair<int,int>>>> nexts(N, vector<vector<pair<int,int>>>(N)); n          n         int rt = tr.root(); n         vector<pair<int,int>> que; n         que.emplace_back(rt, rt); n         vector<vector<bool>> ok(N, vector<bool>(N, false)); n         ok[rt][rt] = true; n         vector<vector<bool>> visited(N, vector<bool>(N, false)); n         visited[rt][rt] = true; n         for (int i = 0; i < que.size(); ++i) { n             int u = que[i].first, v = que[i].second; n  n             for (int j =  a ; j <=  z ; ++j) { n                 int nu = tr.next(u, j); n                 int nv = tr.next(v, j); n                 if (nu < 0 || nv < 0) { n                     continue; n                 } n                 if (tr.isEnd(nu) && tr.isEnd(nv)) { n                     nexts[u][v].emplace_back(rt, rt); n                 } n                 if (tr.isEnd(nu)) { n                     nexts[u][v].emplace_back(rt, nv); n                     if (!visited[rt][nv]) { n                         visited[rt][nv] = true; n                         que.emplace_back(rt, nv); n                     } n                 } n                 if (tr.isEnd(nv)) { n                     nexts[u][v].emplace_back(nu, rt); n                     if (!visited[nu][rt]) { n                         visited[nu][rt] = true; n                         que.emplace_back(nu, rt); n                     } n                 } n                 { n                     nexts[u][v].emplace_back(nu, nv); n                     if (!visited[nu][nv]) { n                         visited[nu][nv] = true; n                         que.emplace_back(nu, nv); n                     } n                 } n             } n         } n  n  n         while (true) { n             int chg = 0; n             for (auto& p : que) { n                 int u = p.first, v = p.second; n                 if (ok[u][v]) { n                     continue; n                 } n                 for (auto& p2 : nexts[u][v]) { n                     int nu = p2.first, nv = p2.second; n                     if (ok[nu][nv]) { n                         ok[u][v] = true; n                         ++chg; n                         break; n                     } n                  n                 } n             } n             if (chg == 0) { n                 break; n             } n         } n  n         map<pair<int,int>,int> indices; n         for (auto& p : que) { n             int u = p.first, v = p.second; n             if (ok[u][v]) { n                 int idx = indices.size(); n                 indices[p] = idx; n             } n         }     n         int sz = indices.size(); n         // cout <<  sz   << sz << endl; n         vector<vector<int>> mat(sz, vector<int>(sz, 0)); n         for (auto& p : que) { n             int u = p.first, v = p.second; n             if (ok[u][v]) { n                 for (auto& p2 : nexts[u][v]) { n                     int nu = p2.first, nv = p2.second; n                     if (ok[nu][nv]) { n                         // cout << indices[p] <<     << indices[p2] <<     << u <<     << v <<  endl; n                         mat[indices[p2]][indices[p]] += 1; n                     } n                 } n             } n         } n  n         auto M = matPow(mat, m); n  n         return M[0][0]; n     } n }; n  n int main(int argc, char** argv) { n     ios::sync_with_stdio(false); n     cin.tie(0); n  n     Solution sol; n  n     int n, m; n     cin >> n >> m; n  n     vector<string> S(n); n     for (int i = 0; i < n; ++i) { n         cin >> S[i]; n     } n  n     cout << sol.solve(S, m) <<   n ; n  n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const int inf = 0x3f3f3f, maxn = 5e5 + 500; n long long gcd(long long x, long long y) { n   if (y == 0) n     return x; n   else n     return gcd(y, x % y); n } n long long ksm(long long a, long long b) { n   long long r = 1; n   while (b) { n     if (b & 1) r = (r * a) % mod; n     a = a * a % mod; n     b >>= 1; n   } n   return r; n } n int n, m, f[maxn][25] = {0}; n int query(int l, int r) { n   int sum = 0; n   for (int i = 23; i >= 0; i--) { n     if (f[l][i] < r && f[l][i] != 0) { n       l = f[l][i]; n       sum += (1 << i); n     } n   } n   if (f[l][0] < r) return -1; n   return sum + 1; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> n >> m; n   int max1 = 0; n   for (int i = 1; i <= n; i++) { n     int l, r; n     cin >> l >> r; n     f[l][0] = max(f[l][0], r); n     max1 = max(r, max1); n   } n   for (int l = 0; l <= max1; l++) n     if (l != 0) f[l][0] = max(f[l][0], max(l, f[l - 1][0])); n   for (int j = 1; j <= 23; j++) n     for (int l = 0; l <= max1; l++) f[l][j] = f[f[l][j - 1]][j - 1]; n   for (int i = 1; i <= m; i++) { n     int l, r; n     cin >> l >> r; n     int ans = query(l, r); n     cout << ans << endl; n   } n } n


/** n   *  Author: N.Nafi1211 || <nomaannafi99@gmail.com> #~# n **/  n  n #include <bits/stdc++.h> n using namespace std; n  n clock_t startTime; n double getCurrentTime(){ n  return (double) (clock() - startTime) / CLOCKS_PER_SEC; n } n  n #define PB push_back n  n typedef long long ll; n typedef vector<char> vc; n typedef vector<int> vi; n typedef vector<long long> vll; n typedef vector<double> vd; n  n void solve() n { n  string a, b; n  cin >> a >> b; n  int n = a.length(), m = b.length(); n  n  int res = 0; n  n  for(int len=1; len<=min(n, m); ++len) { n   for(int i=0; i+len<=n; ++i) { n    for(int j=0; j+len<=m; ++j) { n     if(a.substr(i, len) == b.substr(j, len)) { n      res = max(res, len); n     } n    } n   } n  } n  int ans = n-res + m-res; n  cout << ans <<   n ; n  return; n  n } n  n int main() n { n  ios_base::sync_with_stdio(0); n  cin.tie(0); n  //startTime = clock(); n  n  int t; n  n  cin >> t; n  n  while(t--) n   solve(); n  n  //printf( %.3lf n , getCurrentTime()); n  return 0; n } 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   int test; n   cin >> test; n   while (test--) { n     int n; n     cin >> n; n     for (int i = 0; i < n; i++) { n       cout << 8 <<    ; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<pair<int, int> > > adj; n vector<int> in; n vector<int> out; n vector<pair<int, int> > visit; n pair<int, int> cal(int son) { n   if (visit[son].first > 0) return visit[son]; n   if (visit[son].first == -2) return {-1, -1}; n   visit[son] = {-2, 0}; n   pair<int, int> temp, ans = {0, 0}; n   for (int i = 0; i < adj[son].size(); ++i) { n     temp = cal(adj[son][i].first); n     if (temp.first == -1) return temp; n     if (temp.first > ans.first) { n       ans.first = temp.first; n       ans.second = max(temp.second, adj[son][i].second); n     } n   } n   ++ans.first; n   visit[son] = ans; n   return visit[son]; n } n int main() { n   int n, m; n   cin >> n >> m; n   adj.resize(n + 1); n   out.resize(n + 1); n   in.resize(n + 1); n   visit.resize(n + 1, {-1, 0}); n   int num1, num2; n   for (int i = 0; i < m; ++i) { n     cin >> num1 >> num2; n     out[num1]++; n     in[num2]++; n     adj[num1].push_back({num2, i}); n   } n   int node = 0, cnt = 0; n   for (int i = 1; i <= n; ++i) { n     if (in[i] == 0) { n       node = i; n       ++cnt; n     } n   } n   if (cnt != 1) { n     cout << -1 << endl; n     return 0; n   } n   pair<int, int> temp = cal(node); n   if (temp.second == -1 || temp.first != n) n     cout << -1 << endl; n   else n     cout << temp.second + 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxn = 2e5 + 5; n pair<long long, long long> a[maxn]; n long long n; n long long cnt[maxn][2]; n void solve() { n   cin >> n; n   for (long long i = 1; i <= n; i++) n     cnt[i][0] = cnt[i][1] = 0, cin >> a[i].first >> a[i].second; n   long long ans = n * (n - 1) * (n - 2) / 6; n   for (long long i = 1; i <= n; i++) { n     cnt[a[i].first][0]++; n     cnt[a[i].second][1]++; n   } n   for (long long i = 1; i <= n; i++) { n     ans -= (cnt[a[i].first][0] - 1) * (cnt[a[i].second][1] - 1); n   } n   cout << ans <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t; n   cin >> t; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std; n const long long int mod = 1e9 + 7; n const long long int MAX = LLONG_MAX; n const long long int MIN = LLONG_MIN; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long int n, k; n   cin >> n >> k; n   long long int a[n]; n   for (long long int i = 0; i < n; i++) cin >> a[i]; n   map<long long int, long long int> mp; n   long long int c = 0; n   deque<long long int> d; n   for (long long int i = 0; i < n; i++) { n     if (c < k) { n       if (mp[a[i]] == 0) { n         d.push_front(a[i]); n         mp[a[i]]++; n         c++; n       } else { n       } n     } else { n       long long int x = d.back(); n       if (mp[a[i]] != 0) { n       } else { n         mp[x] = mp[x] - 1; n         d.pop_back(); n         d.push_front(a[i]); n         mp[a[i]]++; n       } n     } n   } n   cout << d.size() <<   n ; n   for (auto i = d.begin(); i != d.end(); i++) { n     cout << *i <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, a[100005]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   long i; n   for (i = 0; i <= n - 1; i++) cin >> a[i]; n   sort(a, a + n); n   long long pc = 1, qc = 1, rc = 1; n   long long b[3]; n   long long p = a[0], q = a[1], r = a[2]; n   if (p == q && q == r) { n     long long c = 3; n     for (i = 3; i <= n - 1; i++) n       if (a[i] == p) c++; n     cout << c * (c - 1) * (c - 2) / 6; n   } else if (p == q) { n     long long pc = 2, rc = 1; n     for (i = 3; i <= n - 1; i++) n       if (a[i] == p) n         pc++; n       else if (a[i] == r) n         rc++; n     cout << pc * (pc - 1) * rc / 2; n   } else if (q == r) { n     long long pc = 1, rc = 2; n     for (i = 3; i <= n - 1; i++) n       if (a[i] == p) n         pc++; n       else if (a[i] == r) n         rc++; n     cout << rc * (rc - 1) * pc / 2; n   } else { n     long long rc = 1; n     for (i = 3; i <= n - 1; i++) n       if (a[i] == r) rc++; n     cout << rc; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /stack:200000000 ) n #pragma GCC optimize( Ofast ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n using namespace std; n signed main() { n   long long int t; n   cin >> t; n   vector<long long int> nums = {6, 10, 14, 15}; n   long long int minS = nums[0] + nums[1] + nums[2]; n   long long int maxS = nums[0] + nums[1] + nums[3]; n   while (t--) { n     long long int n; n     cin >> n; n     if (n <= minS) n       cout <<  NO n ; n     else { n       long long int d = n - minS; n       if (d == nums[0] || d == nums[1] || d == nums[2]) { n         if (n <= maxS) n           cout <<  NO n ; n         else n           cout <<  YES n  n                << 6 <<     << 10 <<     << 15 <<     << n - maxS <<   n ; n       } else n         cout <<  YES n  << 6 <<     << 10 <<     << 14 <<     << d <<   n ; n     } n   } n   return 0; n } n


#include<cstdio> n const int N=100005; n int n,a[100005]; n inline int ask2(int x){ n     if(a[x]) return a[x]; n     printf( ? %d n ,x); n     fflush(stdout); n     scanf( %d ,a+x); n     return a[x]; n } n inline int ask(int x){ n     if(ask2(x)>ask2(x+1)) return 1; n     else  return 0; n } n int main(){ n     scanf( %d ,&n); n     a[0]=a[n+1]=1e9; n     int l=1,r=n; n     int mid=(l+r)/2; n     while(r-l>20){ n         mid=(l+r)/2; n         if(ask(mid)) l=mid+1; n         else r=mid; n     } n     for(int i=l-1;i<=r+1;i++) n         ask2(i); n     for(int i=l;i<=r;i++){ n         if(a[i]<a[i+1]&&a[i]<a[i-1]){ n             printf( ! %d n ,i); n             return 0; n         } n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n const int N = 1e3, MOD = (1e9) + 7; n int n, m, k, A[N + 9][N + 9], row[N + 9], col[N + 9], x, y; n char c; n void init() { n   for (int i = 0; i < N + 5; ++i) row[i] = col[i] = i; n } n int main() { n   scanf( %d%d%d , &n, &m, &k); n   init(); n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) scanf( %d , &A[i][j]); n   } n   for (int i = 0; i < k; ++i) { n     cin.ignore(); n     scanf( %c %d %d , &c, &x, &y); n     switch (c) { n       case  c : n         swap(col[x], col[y]); n         break; n       case  r : n         swap(row[x], row[y]); n         break; n       case  g : n         printf( %d n , A[row[x]][col[y]]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void my_dbg() { cout << endl; } n template <typename Arg, typename... Args> n void my_dbg(Arg A, Args... B) { n   cout <<     << A; n   my_dbg(B...); n } n using ll = long long; n using vi = vector<int>; n using vl = vector<ll>; n using pii = pair<int, int>; n const int inf = INT_MAX; n const int ninf = INT_MIN; n const int mod = 1e9 + 7; n const int maxN = 2e5 + 2; n void solve() { n   int n, m; n   scanf( %d , &n); n   scanf( %d , &m); n   vector<pii> a(m); n   for (int i = (int)(0); i < (int)(m); i++) { n     scanf( %d , &a[i].first); n     scanf( %d , &a[i].second); n   } n   sort(a.begin(), a.end(), [&](pii a, pii b) { return a.second < b.second; }); n   ll sum = 0, ans = 0; n   multiset<int> ms; n   for (int i = (int)(0); i < (int)(m); i++) { n     while ((int)ms.size() and n            (*ms.begin() < a[i].second or (int) ms.size() >= n)) { n       sum -= *ms.begin(); n       ms.erase(ms.begin()); n     } n     sum += a[i].first; n     ll cur = sum; n     ll rem = n - (int)ms.size() - 1; n     cur += rem * a[i].second; n     ans = max(ans, cur); n     ms.insert(a[i].first); n   } n   printf( %lld n , ans); n } n int main() { n   int t = 1; n   scanf( %d , &t); n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   string s; n   cin >> s; n   long long int a = 0, b = 0, c = 0; n   for (int i = 0; i < s.length(); i++) { n     if (i > 0 && s[i - 1] ==  v  && s[i] ==  v ) { n       a++; n       c += b; n     } else if (s[i] ==  o ) { n       b += a; n     } n   } n   cout << c; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, x, nr; n bool kgood(int N, int K) { n   int i, ap[10] = {0}; n   while (N) { n     ++ap[N % 10]; n     N /= 10; n   } n   for (i = 0; i <= K; ++i) n     if (!ap[i]) return false; n   return true; n } n int main() { n   int i; n   scanf( %d%d , &n, &k); n   for (i = 0; i < n; ++i) { n     scanf( %d , &x); n     if (kgood(x, k)) ++nr; n   } n   printf( %d n , nr); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long add(long long a, long long b) { n   a += b; n   if (a >= 1000000007) { n     a -= 1000000007; n   } n   return a; n } n long long sub(long long a, long long b) { n   a -= b; n   if (a < 0) { n     a += 1000000007; n   } n   return a; n } n long long mul(long long a, long long b) { return (a * b) % 1000000007; } n void add_self(long long& a, long long b) { a = add(a, b); } n void sub_self(long long& a, long long b) { a = sub(a, b); } n void mul_self(long long& a, long long b) { a = mul(a, b); } n const long long MAXN = 200010; n long long get(long long val, long long tot) { n   long long ans = 0; n   long long L = val, R = val + 1 - (val % 2); n   while (R <= tot) { n     ans += R - L + 1; n     L = 2 * L; n     R = 2 * R + 1; n   } n   ans += max(0LL, tot - L + 1); n   return ans; n } n int main() { n   long long x, k; n   cin >> x >> k; n   long long lo = 0, hi = 1e18, ans = 0; n   while (lo <= hi) { n     long long mid = (lo + hi) / 2; n     if (get(2 * mid + 1, x) >= k) { n       ans = 2 * mid + 1; n       lo = mid + 1; n     } else { n       hi = mid - 1; n     } n   } n   lo = 0; n   hi = 1e18; n   while (lo <= hi) { n     long long mid = (lo + hi) / 2; n     if (get(2 * mid, x) >= k) { n       ans = max(ans, 2 * mid); n       lo = mid + 1; n     } else { n       hi = mid - 1; n     } n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int flag = 0; n   if (s.length() < 7) { n     cout <<  NO n ; n     return 0; n   } n   for (int i = 0; i <= s.length() - 7; i++) { n     flag = 0; n     for (int j = i; j < i + 7; j++) { n       if (s[i] == s[j]) n         continue; n       else { n         flag = 1; n         break; n       } n     } n     if (flag == 0) { n       cout <<  YES n ; n       return 0; n     } n   } n   cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long d[61]; n int ans; n int n, a[200005]; n void insert() { n   for (int i = 1; i <= n; i++) { n     long long x = a[i]; n     for (int j = 60; j >= 0; j--) n       if (x & (1LL << j)) { n         if (d[j] == 0) { n           d[j] = x; n           ans++; n           break; n         } else n           x ^= d[j]; n       } n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]), a[i] ^= a[i - 1]; n   if (a[n] == 0) { n     printf( -1 n ); n     return 0; n   } n   insert(); n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const long long MX = 100; n long long A[MX][MX]; n long long acum[MX][MX]; n long long n, m; n long long getAns(long long a, long long b) { n   long long ans = n * m; n   for (long long i = 0; i < n; i++) { n     for (long long j = 0; j < m; j++) { n       if (i + a - 1 < n && j + b - 1 < m) { n         long long cur = 0; n         for (long long l = i; l <= i + a - 1; l++) { n           cur += acum[l][j + b] - acum[l][j]; n         } n         ans = min(ans, cur); n       } n     } n   } n   return ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> n >> m; n   for (long long i = 0; i < n; i++) { n     for (long long j = 0; j < m; j++) { n       cin >> A[i][j]; n     } n   } n   for (long long i = 0; i < n; i++) { n     for (long long j = 0; j < m; j++) { n       acum[i][j + 1] = acum[i][j] + A[i][j]; n     } n   } n   long long a, b; n   cin >> a >> b; n   long long ans = min(getAns(a, b), getAns(b, a)); n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n int const nmax = 100; n int v[1 + nmax]; n map<int, int> dp; n int mex(vector<int> v) { n   sort(v.begin(), v.end()); n   v.erase(unique(v.begin(), v.end()), v.end()); n   for (int i = 0; i < v.size(); i++) n     if (v[i] != i) return i; n   return v.size(); n } n int computedp(int mask) { n   map<int, int>::iterator it = dp.find(mask); n   if (it != dp.end()) return it->second; n   vector<int> v; n   for (int i = 1; (1 << i) <= mask; i++) { n     int newmask = ((mask & ((1 << i) - 1)) | (mask >> i)); n     v.push_back(computedp(newmask)); n   } n   dp[mask] = mex(v); n   return dp[mask]; n } n map<int, int> frec; n void decompose(int number) { n   for (int i = 2; i * i <= number; i++) { n     if (number % i == 0) { n       int p = 0; n       while (number % i == 0) { n         number /= i; n         p++; n       } n       frec[i] |= (1 << p); n     } n   } n   if (1 < number) frec[number] |= 2; n } n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> v[i]; n   for (int i = 1; i <= n; i++) decompose(v[i]); n   int result = 0; n   for (map<int, int>::iterator it = frec.begin(); it != frec.end(); it++) { n     result ^= computedp(it->second | 1); n   } n   if (result == 0) n     cout <<  Arpa ; n   else n     cout <<  Mojtaba ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void fast() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n } n long long cmp(pair<int, int> a, pair<int, int> b) { n   return a.second < b.second; n } n int main() { n   int n, m; n   cin >> n >> m; n   char a[n + 1][m + 1]; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       cin >> a[i][j]; n     } n   } n   long long ans = 0; n   long long x[n + 1][m + 1]; n   long long y[n + 1][m + 1]; n   for (int i = 0; i <= n; i++) { n     for (int j = 0; j <= m; j++) { n       x[i][j] = 0; n       y[i][j] = 0; n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       if (a[i][j] ==  0 ) { n         x[i][j] = x[i][j - 1] + 1; n         y[i][j] = y[i - 1][j] + 1; n         long long ymin = y[i][j]; n         long long xmin = x[i][j]; n         for (int k = j - x[i][j] + 1; k <= j; k++) { n           ymin = min(ymin, y[i][k]); n         } n         for (int k = i - y[i][j] + 1; k <= i; k++) { n           xmin = min(xmin, x[k][j]); n         } n         long long p1 = ymin + x[i][j]; n         long long p2 = xmin + y[i][j]; n         long long p = (max(p1, p2)) * 2; n         ans = max(p, ans); n       } n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 10101; n const int BIT = 30; n int N; n int arr[MAXN], brr[MAXN]; n int real_arr[MAXN]; n bool isb[MAXN], risb[MAXN]; n vector<pair<int, int> > vans; n void action(int a, int b) { n   arr[b] ^= arr[a]; n   vans.push_back(make_pair(b + 1, a + 1)); n } n void aswap(int a, int b) { n   if (a == b) return; n   action(a, b); n   action(b, a); n   action(a, b); n } n void fail() { n   cout << -1 << endl; n   exit(0); n } n void calc() { n   int basis[BIT]; n   memset((basis), -1, sizeof(basis)); n   memset((isb), 0, sizeof(isb)); n   for (int i = 0; i < BIT; i++) { n     for (int j = 0; j < N; j++) { n       if (isb[j]) continue; n       if (arr[j] & (1 << i)) { n         basis[i] = j; n         isb[j] = true; n         break; n       } n     } n     if (basis[i] == -1) continue; n     for (int j = 0; j < N; j++) { n       if (j == basis[i]) continue; n       if (arr[j] & (1 << i)) { n         action(basis[i], j); n       } n     } n   } n   bool bused[BIT]; n   int rbasis[BIT]; n   memset((bused), 0, sizeof(bused)); n   memset((risb), 0, sizeof(risb)); n   for (int i = 0; i < N; i++) { n     int x = brr[i]; n     for (int j = 0; j < BIT; j++) { n       if (basis[j] == -1) continue; n       if (x & (1 << j)) { n         x ^= arr[basis[j]]; n         if (!bused[j]) { n           bused[j] = true; n           if (!risb[i]) { n             rbasis[j] = i; n             risb[i] = true; n           } n         } n       } n     } n     if (x) fail(); n   } n   for (int i = 0; i < N; i++) { n     if (arr[i]) continue; n     int x = brr[i]; n     for (int j = 0; j < BIT; j++) { n       if (basis[j] == -1) continue; n       if (x & (1 << j)) { n         x ^= arr[basis[j]]; n         action(basis[j], i); n       } n     } n   } n   if (0) { n     cout <<  B  ; n     for (int i = 0; i < BIT; i++) cout << basis[i] <<    ; n     cout << endl; n     cout <<  -A  ; n     for (int i = 0; i < N; i++) cout << arr[i] <<    ; n     cout << endl; n   } n   int mat[BIT], mat2[BIT]; n   bool oked[BIT]; n   memset((mat), 0, sizeof(mat)); n   memset((mat2), 0, sizeof(mat2)); n   memset((oked), 0, sizeof(oked)); n   memset((rbasis), -1, sizeof(rbasis)); n   memset((bused), 0, sizeof(bused)); n   for (int i = 0; i < BIT; i++) { n     if (basis[i] == -1) continue; n     mat2[i] = 1 << i; n     rbasis[i] = i; n     int x = brr[basis[i]]; n     for (int j = 0; j < BIT; j++) { n       if (basis[j] == -1) continue; n       if (x & (1 << j)) { n         x ^= arr[basis[j]]; n         mat[i] ^= 1 << j; n       } n     } n   } n   if (0) n     for (int i = 0; i < BIT; i++) { n       if (basis[i] == -1) continue; n       for (int j = 0; j < BIT; j++) { n         if (basis[j] == -1) continue; n         cout << !!(mat[i] & (1 << j)) <<    ; n       } n       cout << endl; n     } n   for (int i = 0; i < BIT; i++) { n     if (basis[i] == -1) continue; n     int pv = -1; n     for (int j = 0; j < BIT; j++) { n       if (basis[j] == -1) continue; n       if (bused[j]) continue; n       if (mat[j] & 1 << i) { n         pv = j; n         bused[j] = true; n         break; n       } n     } n     if (pv == -1) continue; n     swap(bused[i], bused[pv]); n     swap(mat[i], mat[pv]); n     swap(mat2[i], mat2[pv]); n     for (int j = 0; j < BIT; j++) { n       if (basis[j] == -1) continue; n       if (j == i) continue; n       if (mat[j] & 1 << i) { n         mat[j] ^= mat[i]; n         mat2[j] ^= mat2[i]; n       } n     } n   } n   for (int i = 0; i < BIT; i++) { n     if (basis[i] == -1) continue; n     if (!(mat[i] & 1 << i)) { n       for (int j = 0; j < BIT; j++) { n         if (basis[j] == -1) continue; n         if (j == i) continue; n         if (mat[j] & 1 << i) action(basis[i], basis[j]); n       } n       action(basis[i], basis[i]); n     } n   } n   for (int i = 0; i < BIT; i++) { n     if (basis[i] == -1) continue; n     int pv = -1; n     for (int j = i; j < BIT; j++) { n       if (basis[j] == -1) continue; n       if (mat2[j] & 1 << i) { n         pv = j; n         break; n       } n     } n     swap(mat2[i], mat2[pv]); n     aswap(basis[i], basis[pv]); n     for (int j = 0; j < BIT; j++) { n       if (basis[j] == -1) continue; n       if (j == i) continue; n       if (mat2[j] & 1 << i) { n         mat2[j] ^= mat2[i]; n         action(basis[i], basis[j]); n       } n     } n   } n   if (0) n     for (int i = 0; i < BIT; i++) { n       if (basis[i] == -1) continue; n       for (int j = 0; j < BIT; j++) { n         if (basis[j] == -1) continue; n         cout << !!(mat[i] & (1 << j)) <<    ; n       } n       cout << endl; n     } n   return; n   for (int i = 0; i < BIT; i++) { n     if (basis[i] == -1) continue; n     int pv = -1; n     int ii = rbasis[i]; n     for (int j = 0; j < BIT; j++) { n       if (basis[j] == -1) continue; n       if (oked[j]) continue; n       if (mat[j] & (1 << i)) { n         pv = j; n         break; n       } n     } n     if (pv == -1) { n       continue; n     } n     if (0) cout <<  II   << ii <<   PV   << pv << endl; n     oked[pv] = true; n     swap(mat2[ii], mat2[pv]); n     int lb = -1; n     for (int j = 0; j < BIT; j++) n       if (basis[j] != -1 && rbasis[j] == pv) lb = j; n     swap(rbasis[i], rbasis[lb]); n     if (0) cout <<  SWAP RB   << i <<     << lb << endl; n     aswap(basis[ii], basis[pv]); n     vector<pair<int, int> > vb; n     int b = basis[pv]; n     int orig_arr = arr[b]; n     for (int j = 0; j < BIT; j++) { n       if (basis[j] == -1) continue; n       if (j == i) continue; n       if (1) { n         int rj = rbasis[j]; n         if ((mat2[pv] ^ mat[pv]) & (1 << j)) { n           mat2[pv] ^= mat2[rj]; n           arr[basis[pv]] ^= arr[basis[rj]]; n           vb.push_back(make_pair(basis[pv] + 1, basis[rj] + 1)); n         } n       } n     } n     if (!(mat2[pv] & (1 << i))) { n       mat2[pv] ^= 1 << i; n       arr[b] ^= orig_arr; n       vans.push_back(make_pair(b + 1, b + 1)); n     } n     for (__typeof(vb.begin()) it = vb.begin(); it != vb.end(); it++) n       vans.push_back(*it); n   } n   vector<pair<int, int> > vi; n   for (int q = 0; q < BIT; q++) { n     int i = rbasis[q]; n     if (i == -1 || basis[i] == -1) continue; n     if (oked[i]) continue; n     vi.push_back(make_pair(basis[q] + 1, basis[q] + 1)); n     for (int j = 0; j < BIT; j++) { n       if (basis[j] == -1) continue; n       if (j == q) continue; n       if ((mat2[i] ^ mat[i]) & (1 << j)) { n         mat2[i] ^= 1 << j; n         vi.push_back(make_pair(basis[q] + 1, basis[j] + 1)); n         cout <<  VIPB   << q <<     << j << endl; n         cout <<  NOW   << rbasis[q] << endl; n       } n     } n   } n   if (0) n     for (int i = 0; i < BIT; i++) { n       if (basis[i] == -1) continue; n       for (int j = 0; j < BIT; j++) { n         if (basis[j] == -1) continue; n         cout << !!(mat2[i] & (1 << j)) <<    ; n       } n       cout << endl; n     } n   if (0) { n     cout <<  A  ; n     for (int i = 0; i < N; i++) cout << arr[i] <<    ; n     cout << endl; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin >> N; n   for (int i = 0; i < N; i++) cin >> arr[i]; n   for (int i = 0; i < N; i++) cin >> brr[i]; n   for (int i = 0; i < N; i++) real_arr[i] = arr[i]; n   calc(); n   for (__typeof(vans.begin()) it = vans.begin(); it != vans.end(); it++) { n     real_arr[it->first - 1] ^= real_arr[it->second - 1]; n   } n   if (0) { n     cout <<  R  ; n     for (int i = 0; i < N; i++) cout << real_arr[i] <<    ; n     cout << endl; n   } n   int A = vans.size(); n   cout << A <<   n ; n   for (__typeof(vans.begin()) it = vans.begin(); it != vans.end(); it++) { n     cout << it->first <<     << it->second <<   n ; n   } n   cout << flush; n   for (int i = 0; i < N; i++) assert(real_arr[i] == brr[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, m, a, b, s1, s2; n   cin >> n >> m >> a >> b; n   if (n % m == 0) n     cout <<  0  << endl; n   else { n     s1 = (n - ((n / m) * m)) * b; n     s2 = (((n / m) + 1) * m - n) * a; n     if (s1 > s2) n       printf( %I64d , s2); n     else n       printf( %I64d , s1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, k; n   cin >> n >> k; n   long long cnt = 0.5 * n / (k + 1); n   cout << cnt <<     << cnt * k <<     << n - cnt - cnt * k << endl; n } n


#include <bits/stdc++.h> n using namespace std; n void solution() { n   int n, m; n   cin >> n >> m; n   int rows[n][m]; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> rows[i][j]; n     } n   } n   int cols[m][n]; n   for (int i = 0; i < m; i++) { n     for (int j = 0; j < n; j++) { n       cin >> cols[i][j]; n     } n   } n   int el = cols[0][0]; n   for (int i = 0; i < n; i++) { n     if (find(rows[i], rows[i] + m, el) != rows[i] + m) { n       int l = find(rows[i], rows[i] + m, el) - rows[i]; n       int arrangement[n]; n       for (int j = 0; j < n; j++) { n         for (int k = 0; k < n; k++) { n           if (cols[0][j] == rows[k][l]) { n             arrangement[j] = k; n             break; n           } n         } n       } n       for (int i = 0; i < n; i++) { n         for (int j = 0; j < m; j++) { n           cout << rows[arrangement[i]][j] <<    ; n         } n         cout << endl; n       } n       return; n     } n   } n   return; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int count, counter = 0; n   cin >> count; n   while (counter++ < count) { n     solution(); n   } n   return 0; n } n


#include<bits/stdc++.h> n  n using namespace std; n  n #define task  sol  n #define lb lower_bound n #define ub upper_bound n #define fi first n #define se second n #define pb push_back n #define mp make_pair n #define zs(v) ((int)(v).size()) n #define BIT(x, i) (((x) >> (i)) & 1) n #define CNTBIT __builtin_popcountll n #define ALL(v) (v).begin(),(v).end() n #define endl   n  n  n typedef long double ld; n typedef long long ll; n typedef pair<int, int> pii; n  n const ll base=331; n const int dx[8]={0,-1,0,1,1,-1,-1,1}; n const int dy[8]={-1,0,1,0,-1,-1,1,1}; n  n int c[55][55]; n int mod; n ll dp[55][55*55]; n ll fact[55]; n int f[4005]; n int n; n  n  n void gogo() n { n     cin>>n>>mod; n  n     dp[0][0]=1; n     for (int i=1;i<=n;++i) n     { n         for (int num=0;num<=n*n;++num) n         { n             for (int k=1;k<=i;++k) n                 if (num+i-k<=n*n) (dp[i][num+i-k]+=dp[i-1][num])%=mod; n         } n     } n  n     for (int i=0;i<=n;++i) n     { n         c[i][0]=1; n         for (int j=1;j<=i;++j) n             c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod; n     } n     fact[0]=1; n     for (int i=1;i<=n;++i) fact[i]=fact[i-1]*i%mod; n  n  n     int ans=0; n     for (int i=0;i<n;++i) n     { n         ll val=c[n][i]*fact[i]%mod; n         int len=n-i-1; n         int m=len*(len-1)/2; n  n         for (int i=0;i<=m;++i) f[i]=0; n         for (int inv1=0;inv1<=m;++inv1) n         { n             for (int inv2=0;inv2<=inv1;++inv2) n             { n                 (f[inv1-inv2]+=dp[len][inv1]*dp[len][inv2]%mod)%=mod; n             } n         } n         for (int i=1;i<=m;++i) (f[i]+=f[i-1])%=mod; n         int value=0; n         for (int x=1;x<=len+1;++x) n         { n             for (int y=x+1;y<=len+1;++y) n             { n                 assert(y-x>=0); n                 if (m>y-x) n                     (value+=(f[m]-f[y-x]+mod)%mod)%=mod; n             } n         } n //        cout<<value<<endl; n         ans=(ans+val*value%mod)%mod; n     } n     cout<<ans; n } n int main() n { n     ios_base::sync_with_stdio(0); cin.tie(0); n     if (fopen(task .inp ,  r )) n     { n         freopen(task .inp ,  r , stdin); n         freopen(task .out ,  w , stdout); n     } n     gogo(); n } n  n  n  n  n  n  n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, m, k, x = 0; n   cin >> n >> m >> k; n   if (n + m - 2 < k) { n     cout << -1; n     return 0; n   } n   if (m > n) swap(m, n); n   if (k < m) x = n * (m / (k + 1)); n   if (k < n) x = max(x, m * (n / (k + 1))); n   if (k >= n) x = m / (k - n + 2); n   cout << x; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std; n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   cerr << name <<   :   << arg1 <<   n ; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cerr.write(names, comma - names) <<   :   << arg1 <<   |  ; n   __f(comma + 1, args...); n } n long long int gcd(long long int a, long long int b) { n   if (a < b) n     return gcd(b, a); n   else if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n long long int isPrime(long long int n) { n   long long int p = (long long int)sqrt(n); n   for (int i = (2); i <= (p); i += (1)) n     if (n % i == 0) return 0; n   return 1; n } n long long int pow(long long int b, long long int e) { n   if (e == 0) n     return 1; n   else if (e % 2 == 0) { n     long long int a = pow(b, e / 2); n     return a * a; n   } else { n     long long int a = pow(b, e / 2); n     return b * a * a; n   } n } n long long int powm(long long int x, long long int y, n                    long long int m = 1000000007) { n   x = x % m; n   long long int res = 1; n   while (y) { n     if (y & 1) res = res * x; n     res %= m; n     y = y >> 1; n     x = x * x; n     x %= m; n   } n   return res; n } n long long int modInverse(long long int a, long long int m) { n   return powm(a, m - 2, m); n } n void solve() { n   long long int n; n   cin >> n; n   vector<long long int> arr(n); n   for (int i = (0); i <= (n - 1); i += (1)) cin >> arr[i]; n   if (n == 1) { n     cout <<  1 1  <<   n  n          << (-arr[0]) <<   n  n          <<  1 1  n          <<   n0  <<   n  n          <<  1 1 n  n          <<  0  <<   n ; n     return; n   } n   vector<vector<long long int>> ans; n   ans.push_back({1, 1, -arr[0]}); n   arr[0] = 0; n   vector<long long int> temp; n   temp.push_back(2); n   temp.push_back(n); n   for (int i = (1); i <= (n - 1); i += (1)) { n     long long int x = arr[i] % n; n     arr[i] += x * (n - 1); n     temp.push_back(x * (n - 1)); n   } n   ans.push_back(temp); n   temp.clear(); n   temp.push_back(1); n   temp.push_back(n); n   for (int i = (0); i <= (n - 1); i += (1)) { n     temp.push_back(-arr[i]); n   } n   ans.push_back(temp); n   for (int i = (0); i <= (2); i += (1)) { n     cout << ans[i][0] <<     << ans[i][1] <<   n ; n     for (int j = (2); j <= ((int)ans[i].size() - 1); j += (1)) n       cout << ans[i][j] <<    ; n     cout <<   n ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   int T = 1; n   while (T--) { n     solve(); n   } n   return 0; n } n


#include <iostream> n #include <cstdio> n #include <algorithm> n #include <bits/stdc++.h> n #define ALL(x) (x).begin(), (x).end() n #define sz(a) int(a.size()) n #define rep(i,x,n) for(int i=x;i<n;i++) n #define repd(i,x,n) for(int i=x;i<=n;i++) n #define pii pair<int,int> n #define pll pair<long long ,long long> n #define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) n #define MS0(X) memset((X), 0, sizeof((X))) n #define MSC0(X) memset((X),   0 , sizeof((X))) n #define pb push_back n #define mp make_pair n #define fi first n #define se second n #define eps 1e-6 n #define chu(x)  if(DEBUG_Switch) cout<< [ <<#x<<   <<(x)<< ] <<endl n #define du3(a,b,c) scanf( %d %d %d ,&(a),&(b),&(c)) n #define du2(a,b) scanf( %d %d ,&(a),&(b)) n #define du1(a) scanf( %d ,&(a)); n using namespace std; n typedef long long ll; n ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} n ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} n ll powmod(ll a, ll b, ll MOD) { if (a == 0ll) {return 0ll;} a %= MOD; ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;} n ll poww(ll a, ll b) { if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a ;} a = a * a ; b >>= 1;} return ans;} n void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf( %d , V[i] ); if (i != Len - 1) {printf(   );} else {printf(  n );}}} n void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf( %lld , V[i] ); if (i != Len - 1) {printf(   );} else {printf(  n );}}} n inline long long readll() {long long tmp = 0, fh = 1; char c = getchar(); while (c <  0  || c >  9 ) {if (c ==  - ) { fh = -1; } c = getchar();} while (c >=  0  && c <=  9 ) { tmp = tmp * 10 + c - 48, c = getchar(); } return tmp * fh;} n inline int readint() {int tmp = 0, fh = 1; char c = getchar(); while (c <  0  || c >  9 ) {if (c ==  - ) { fh = -1; } c = getchar();} while (c >=  0  && c <=  9 ) { tmp = tmp * 10 + c - 48, c = getchar(); } return tmp * fh;} n void pvarr_int(int *arr, int n, int strat = 1) {if (strat == 0) {n--;} repd(i, strat, n) {printf( %d%c , arr[i], i == n ?   n  :    );}} n void pvarr_LL(ll *arr, int n, int strat = 1) {if (strat == 0) {n--;} repd(i, strat, n) {printf( %lld%c , arr[i], i == n ?   n  :    );}} n const int maxn = 1000010; n const int inf = 0x3f3f3f3f; n /*** TEMPLATE CODE * * STARTS HERE ***/ n #define DEBUG_Switch 0 n pll a[5]; n int b[5]; n int main() n { n #if DEBUG_Switch n     freopen( D:  code  input.txt ,  r , stdin); n #endif n     //freopen( D:  code  output.txt , w ,stdout); n     int t; n     t = readint(); n     while (t--) { n         repd(i, 1, 4) { n             a[i].fi = readint(); n             a[i].se = readint(); n             b[i] = i; n         } n         ll ans = 1e18; n         do { n             ll x1 = min(a[b[1]].fi, a[b[3]].fi), x2 = max(a[b[1]].fi, a[b[3]].fi), x3 = min(a[b[2]].fi, a[b[4]].fi), x4 = max(a[b[2]].fi, a[b[4]].fi); n             ll y1 = min(a[b[1]].se, a[b[2]].se), y2 = max(a[b[1]].se, a[b[2]].se), y3 = min(a[b[3]].se, a[b[4]].se), y4 = max(a[b[3]].se, a[b[4]].se); n             ll x_l, x_r, y_l, y_r; n             ll cost_x, cost_y; n             if (x4 < x1) { n                 x_l = x_r = 0; n                 cost_x = x2 - x3 + x1 - x4; n             } else { n                 x_l = max(x3 - x2, 0ll); n                 x_r = x4 - x1; n                 cost_x = x2 - x1 + x4 - x3; n             } n  n             if (y4 < y1) { n                 y_l = y_r = 0; n                 cost_y = y2 - y3 + y1 - y4; n             } else { n                 y_l = max(y3 - y2, 0ll); n                 y_r = y4 - y1; n                 cost_y = y2 - y1 + y4 - y3; n             } n  n             ll temp = cost_x + cost_y; n             if (y_l > x_r) { n                 temp += 2ll * (y_l - x_r); n             } else if (x_l > y_r) { n                 temp += 2ll * (x_l - y_r); n             } n             ans = min(ans, temp); n         } while (next_permutation(b + 1, b + 1 + 4)); n         printf( %lld n , ans ); n     } n  n     return 0; n } n  n  n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int T, l, r; n   cin >> T; n   for (int i = 1; i <= T; i++) { n     cin >> l >> r; n     cout << l <<     << 2 * l << endl; n   } 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 n, k; n   cin >> n >> k; n   string s; n   cin >> s; n   int l = -1; n   for (int i = 0; i < n - 1 && k > 0; i++) { n     if (s[i] ==  4  && s[i + 1] ==  7 ) { n       if (i % 2 == 1) { n         if (i - 1 >= 0 && s[i - 1] ==  4 ) { n           l = i; n           break; n         } n       } n       --k; n       if (i % 2 == 0) n         s[i + 1] =  4 ; n       else n         s[i] =  7 ; n     } n   } n   if (l != -1) { n     if (k % 2 == 1) s[l] =  7 ; n   } n   cout << s; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   std::ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   while (t--) { n     long long n, i, j = 0, x; n     cin >> n; n     string s =   ; n     stack<long long> q; n     deque<long long> d; n     for (i = 0; i < (n); i++) { n       cin >> x; n       d.push_back(x); n     } n     q.push(0); n     while (!d.empty()) { n       if (d.front() >= q.top() && n           (d.front() < d.back() || d.back() < q.top())) { n         q.push(d.front()); n         s +=  L ; n         d.pop_front(); n       } else if (d.back() >= q.top() && n                  (d.front() >= d.back() || d.front() < q.top())) { n         q.push(d.back()); n         s +=  R ; n         d.pop_back(); n       } else n         break; n     } n     cout << q.size() - 1 <<   n ; n     cout << s; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD(1000000007); n const int Max_W(1000050); n inline int Mult(const int &a, const int &b) { return (a * 1LL) * b % MOD; } n constexpr int Add(int a, int b) { return a + b >= MOD ? a + b - MOD : a + b; } n constexpr int Sub(int a, int b) { return a - b < 0 ? a - b + MOD : a - b; } n void exgcd(const int &a, const int &b, int &x, int &y) { n   if (b == 0) n     x = 1, y = 0; n   else n     exgcd(b, a % b, y, x), y -= x * (a / b); n } n inline int inverse(const int &a) { n   int invx, invy; n   exgcd(a, MOD, invx, invy); n   return (invx % MOD + MOD) % MOD; n } n int power(int a, int n) { n   int Ret(1); n   while (n) { n     if (n & 1) Ret = Mult(Ret, a); n     a = Mult(a, a), n >>= 1; n   } n   return Ret; n } n int W, A[Max_W], Fac[Max_W], Inv[Max_W]; n inline int P(const int &n, const int &m) { n   return (0 <= m && m <= n) ? Mult(Fac[n], Inv[n - m]) : 0; n } n int work(const int &N) { n   int Ans(0); n   if (W == 1) n     Ans = N; n   else n     Ans = Mult(Sub(power(W, N + 1), W), inverse(Sub(W, 1))); n   for (int len = N + 1; len - N <= W; ++len) n     if (len - N < N + 1) n       Ans = n           Add(Ans, Mult(Mult(A[len - N], A[len - N]), power(W, N - (len - N)))); n     else n       Ans = Add(Ans, Mult(A[len - N], P(W - ((len - N) - (N + 1) + 1), N))); n   return Ans; n } n int main() { n   int N; n   scanf( %d%d , &W, &N); n   A[0] = 1; n   for (int i = 1; i <= W; ++i) A[i] = Mult(A[i - 1], W - i + 1); n   Fac[0] = 1; n   for (int i = 1; i <= W; ++i) Fac[i] = Mult(Fac[i - 1], i); n   Inv[W] = inverse(Fac[W]); n   for (int i = W - 1; i >= 0; --i) Inv[i] = Mult(Inv[i + 1], i + 1); n   printf( %d , Sub(work(N), work(N - 1))); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n void solve() { n   int n, k; n   cin >> n >> k; n   string s; n   cin >> s; n   set<char> st; n   for (auto i : s) st.insert(i); n   if (k > n) { n     string p = s; n     char ch = *st.begin(); n     for (int i = 0; i < k - n; i++) { n       p += ch; n     } n     cout << p; n   } else { n     int p = k; n     k--; n     char ch = *st.rbegin(); n     if (s[k] == ch) { n       for (; k >= 0; k--) { n         if (s[k] != ch) break; n       } n       for (int i = 0; i < k; i++) cout << s[i]; n       cout << *(st.upper_bound(s[k])); n       ch = *st.begin(); n       for (int i = 0; i < p - k - 1; i++) cout << ch; n     } else { n       for (int i = 0; i < k; i++) cout << s[i]; n       cout << *(st.upper_bound(s[k])); n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b, c; n int n; n long long X1, Y1, X2, Y2; n long long sign(long long a) { n   if (a > 0) return 1; n   if (a < 0) return -1; n   return 0; n } n int main() { n   cin >> X1 >> Y1 >> X2 >> Y2; n   cin >> n; n   int ans = 0; n   for (int i = 0; i < n; ++i) { n     cin >> a >> b >> c; n     if (sign(a * X1 + b * Y1 + c) != sign(a * X2 + b * Y2 + c)) ans++; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     vector<long long> v(n); n     set<long long> s; n     for (long long x = 0; x < n; x++) { n       cin >> v[x]; n     } n     long long index = -1; n     if (v[n - 1] > v[n - 2]) { n       for (long long x = n - 1; x >= 1; x--) { n         if (v[x] < v[x - 1]) { n           index = x; n           break; n         } n       } n       cout << (index == -1 ? 0 : index) <<   n ; n     } else { n       long long count = 0; n       long long index = -1; n       for (long long x = n - 1; x > 0; x--) { n         if (v[x] < v[x - 1] && count == 1) { n           index = x; n           break; n         } n         if (v[x] > v[x - 1]) { n           count = 1; n         } n       } n       cout << (index == -1 ? 0 : index) <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const int maxn = 110000; n int n, m, h; n int head[maxn], num; n struct road { n   int to, next; n } edge[maxn * 2]; n void add(int u, int v) { n   edge[num].to = v; n   edge[num].next = head[u]; n   head[u] = num++; n } n int dfn[maxn], low[maxn], block[maxn]; n int id, cnt, vis[maxn], numxx[maxn]; n int out[maxn]; n stack<int> q; n void dfs(int u, int fa) { n   dfn[u] = low[u] = ++id; n   q.push(u); n   vis[u] = 1; n   for (int i = head[u]; i != -1; i = edge[i].next) { n     int v = edge[i].to; n     if (!dfn[v]) { n       dfs(v, u); n       low[u] = min(low[v], low[u]); n     } else if (vis[v]) n       low[u] = min(low[u], dfn[v]); n   } n   if (dfn[u] == low[u]) { n     cnt++; n     int v; n     do { n       v = q.top(); n       vis[v] = 0; n       q.pop(); n       block[v] = cnt; n       numxx[cnt]++; n     } while (v != u); n   } n } n int tim[maxn]; n void init() { n   id = num = cnt = 0; n   memset(dfn, 0, sizeof(dfn)); n   memset(low, 0, sizeof(low)); n   memset(edge, 0, sizeof(edge)); n   memset(numxx, 0, sizeof(numxx)); n   memset(block, 0, sizeof(block)); n   memset(vis, 0, sizeof(vis)); n   while (!q.empty()) q.pop(); n   memset(head, -1, sizeof(head)); n   memset(out, 0, sizeof(out)); n } n int main() { n   while (scanf( %d%d%d , &n, &m, &h) != EOF) { n     init(); n     for (int i = 1; i <= n; i++) { n       scanf( %d , &tim[i]); n     } n     for (int i = 1; i <= m; i++) { n       int a, b; n       scanf( %d%d , &a, &b); n       if ((tim[a] + 1) % h == tim[b]) add(a, b); n       if ((tim[b] + 1) % h == tim[a]) add(b, a); n     } n     for (int i = 1; i <= n; i++) { n       if (!dfn[i]) dfs(i, -1); n     } n     for (int i = 1; i <= n; i++) { n       for (int j = head[i]; j != -1; j = edge[j].next) { n         int v = edge[j].to; n         if (block[v] != block[i]) { n           out[block[i]]++; n         } n       } n     } n     int ans = INF; n     int flag = 0; n     for (int i = 1; i <= cnt; i++) { n       if (out[i] == 0) { n         if (ans > numxx[i]) { n           ans = numxx[i]; n           flag = i; n         } n       } n     } n     cout << ans << endl; n     for (int i = 1; i <= n; i++) { n       int putt = 0; n       if (block[i] == flag) { n         ans--; n         putt = 1; n       } n       if (ans != 0 && putt == 1) n         cout << i <<    ; n       else if (ans == 0 && putt == 1) n         cout << i << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long int N = 200001; n const long long int M = 21; n struct point { n   long long int x, y, cur; n   bool operator==(const point b) { n     if (this->x == b.x && this->y == b.y) return 1; n     return 0; n   } n   bool operator!=(const point b) { return !(*this == b); } n   friend bool operator<(const point a, const point b) { n     if (a.x != b.x) return a.x < b.x; n     return a.y < b.y; n   } n }; n void debug(stringstream &s) {} n template <typename T, typename... Args> n void debug(stringstream &s, T a, Args... args) { n   string word; n   s >> word; n   cout << word <<   =   << a << endl; n   debug(s, args...); n } n bool overflow; n long long int fast_exp(long long int x, long long int n) { n   if (n == 0) return 1; n   long long int ans; n   if (n % 2 == 0) { n     ans = fast_exp(x, n / 2); n     if (ans > ans * ans % 998244353) overflow = 1; n     ans = ans * ans % 998244353; n   } else { n     ans = fast_exp(x, n - 1); n     if (ans > ans * x % 998244353) overflow = 1; n     ans = ans * x % 998244353; n   } n   return ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int _ = 1; n   while (_--) { n     long long int n, m = 0, x = 0, y = 0, ans = 0, k; n     string s, sol; n     cin >> s; n     n = s.size(); n     set<long long int, greater<long long int>> c[26]; n     s =  0  + s; n     for (int i = 1; i <= n; i++) c[s[i] -  a ].insert(i); n     long long int dp[n + 1][51]; n     memset(dp, -1, sizeof(dp)); n     for (int i = 0; i <= n; i++) dp[i][0] = n + 1; n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j < 51; j++) { n         dp[i][j] = dp[i - 1][j]; n         x = dp[i - 1][j - 1]; n         auto it = c[s[i] -  a ].upper_bound(x); n         if (it != c[s[i] -  a ].end() && *it >= i) { n           dp[i][j] = max(dp[i][j], *it); n         } n       } n     } n     x = -1; n     for (int i = 50; i > 0; i--) { n       bool flag = 0; n       m = 0; n       for (int j = 1; j <= n; j++) { n         if (dp[j][i] != -1) { n           if (dp[j][i] - j >= m) { n             x = j; n             y = i; n             m = dp[j][i] - j; n           } n           flag = 1; n         } n       } n       if (flag) break; n     } n     for (int i = x; i > 0; i--) { n       if (dp[i - 1][y] != dp[i][y]) { n         if (dp[i][y] > i) n           sol = s[i] + sol + s[i]; n         else n           sol = s[i]; n         y--; n       } n     } n     cout << sol <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int oo = 0x3f3f3f3f; n const double eps = 1e-9; n vector<int> p, vg; n set<pair<int, int> > done; n bool cando(int i, int j) { n   return done.find(make_pair(min(i, j), max(i, j))) == done.end(); n } n int moves = 0; n void doswap(int i, int j) { n   ++moves; n   assert(i != j); n   assert(min(i, j) >= 0 && max(i, j) < int((vg).size())); n   assert(cando(i, j)); n   printf( %d %d n , min(i, j) + 1, max(i, j) + 1); n   swap(p[i], p[j]); n   swap(vg[i], vg[j]); n   done.insert(make_pair(min(i, j), max(i, j))); n } n void brute_force(vector<int> pp) { n   int N = int((pp).size()); n   vector<pair<int, int> > op; n   vector<int> aim = pp; n   sort((aim).begin(), (aim).end()); n   for (int i = (0); i < (N); i++) n     for (int j = (0); j < (i); j++) n       if (cando(i, j)) op.push_back(make_pair(i, j)); n   sort((op).begin(), (op).end()); n   do { n     vector<int> tmp = pp; n     for (auto it : op) { n       swap(tmp[it.first], tmp[it.second]); n     } n     if (tmp == aim) { n       for (auto it : op) doswap(it.first, it.second); n       return; n     } n   } while (next_permutation((op).begin(), (op).end())); n   cerr <<  EPIC FAIL n ; n } n int main() { n   ios::sync_with_stdio(false); n   int N; n   cin >> N; n   if (N == 1) { n     cout <<  YES n ; n     return 0; n   } n   if ((N * (N - 1)) % 4 != 0) { n     cout <<  NO n ; n     return 0; n   } n   printf( YES n ); n   p = vector<int>(N); n   for (int i = (0); i < (N); i++) p[i] = i; n   vg = p; n   while (true) { n     vector<int> ids; n     for (int i = (0); i < (N); i++) n       if (p[i] != -1) ids.push_back(i); n     int S = int((ids).size()); n     if (S <= 1) break; n     assert(ids[S - 1] == S - 1); n     if (S <= 5) { n       vector<int> tmp(S); n       for (int i = (0); i < (S); i++) tmp[i] = p[i]; n       brute_force(tmp); n       break; n     } n     vector<int> x(S - 1); n     for (int i = (0); i < (S - 1); i++) x[i] = i; n     random_shuffle((x).begin(), (x).end()); n     if (p[S - 1] == S - 1) { n       bool ok = false; n       while (!ok) { n         int z1 = max((rand() % (S - 1)), rand() % (S - 1)); n         int z2 = max((rand() % (S - 1)), rand() % (S - 1)); n         if (z1 == z2) continue; n         if (!cando(z1, S - 1) || !cando(z2, S - 1)) continue; n         if (!cando(z1, z2)) continue; n         ok = true; n         doswap(z2, S - 1); n         doswap(z2, z1); n         for (auto i : x) { n           if (i != z1 && i != z2 && cando(i, S - 1)) { n             doswap(i, S - 1); n           } n         } n         doswap(z1, S - 1); n       } n     } else { n       int id_largest = -1; n       for (int i = (0); i < (S); i++) n         if (p[i] == S - 1) id_largest = i; n       assert(id_largest != -1); n       if (cando(id_largest, S - 1)) { n         for (auto i : x) { n           if (i != id_largest && cando(i, S - 1)) { n             doswap(i, S - 1); n           } n         } n         doswap(id_largest, S - 1); n       } else { n         int z = S - 2; n         while (!cando(z, S - 1) || !cando(id_largest, z)) --z; n         assert(z >= 0); n         assert(z != id_largest); n         doswap(id_largest, z); n         for (auto i : x) { n           if (i != z && cando(i, S - 1)) { n             doswap(i, S - 1); n           } n         } n         doswap(z, S - 1); n       } n     } n     assert(p[S - 1] == S - 1); n     p[S - 1] = -1; n   } n   assert(moves == (N * (N - 1)) / 2); n   for (int i = (0); i < (N); i++) assert(vg[i] == i); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9; n const int Mod = 1e9 + 7; n const int Mod2 = 49157; n const int p = 10; n inline long long Read() { n   long long Ans = 0; n   char Ch = getchar(), Las =    ; n   while (!isdigit(Ch)) { n     Las = Ch; n     Ch = getchar(); n   } n   while (isdigit(Ch)) { n     Ans = (Ans << 3) + (Ans << 1) + Ch -  0 ; n     Ch = getchar(); n   } n   if (Las ==  - ) Ans = -Ans; n   return Ans; n } n inline void Write(long long x) { n   if (x < 0) { n     x = -x; n     putchar( - ); n   } n   if (x >= 10) Write(x / 10); n   putchar(x % 10 +  0 ); n } n unsigned long long Hash[1000010], Hash2[1000010], idx[1000010], Pow[1000010], n     Pow2[1000010]; n unsigned long long a, b, c; n unsigned long long a2, b2, c2; n int Left_a, Right_a, Left_b, Right_b, Left_c, Right_c, Len; n bool Flag; n string s; n inline void Get_Hash() { n   Pow[0] = 1; n   Pow2[0] = 1; n   for (int i = 1; i <= 1000010 / 2; i++) { n     Pow[i] = Pow[i - 1] * p % Mod; n     Pow2[i] = Pow2[i - 1] * p % Mod2; n   } n   idx[0] = s[0] -  0 ; n   Hash[0] = idx[0]; n   Hash2[0] = idx[0]; n   for (int i = 1; i < Len; i++) { n     idx[i] = s[i] -  0 ; n     Hash[i] = (Hash[i - 1] * p + idx[i]) % Mod; n     Hash2[i] = (Hash2[i - 1] * p + idx[i]) % Mod2; n   } n } n inline unsigned long long Cmp_Hash(int Left, int Right) { n   if (Left == 0) return Hash[Right]; n   return (Hash[Right] + Mod - (Hash[Left - 1] * Pow[Right - Left + 1]) % Mod) % n          Mod; n } n inline unsigned long long Cmp_Hash2(int Left, int Right) { n   if (Left == 0) return Hash2[Right]; n   return (Hash2[Right] + Mod2 - n           (Hash2[Left - 1] * Pow2[Right - Left + 1]) % Mod2) % n          Mod2; n } n int main() { n   cin >> s; n   Len = s.size(); n   Get_Hash(); n   int j; n   for (int i = 1; i <= Len / 2; i++) { n     if (i > 1 and idx[0] == 0) break; n     a = Cmp_Hash(0, i - 1); n     a2 = Cmp_Hash2(0, i - 1); n     if (i < Len / 3 + 1) { n       j = (Len - i) / 2; n       if (!(idx[i] == 0 and j > 1) and !(Len - i - j > 1 and idx[i + j] == 0)) { n         b = Cmp_Hash(i, i + j - 1); n         b2 = Cmp_Hash2(i, i + j - 1); n         c = Cmp_Hash(i + j, Len - 1); n         c2 = Cmp_Hash2(i + j, Len - 1); n         if ((a + b) % Mod == c % Mod and (a2 + b2) % Mod2 == c2 % Mod2) { n           Flag = 1, Left_a = 0, Right_a = i - 1, Left_b = i; n           Right_b = i + j - 1, Left_c = i + j, Right_c = Len - 1; n           break; n         } n       } n       j = (Len - i - 1) / 2; n       if (!(idx[i] == 0 and j > 1) and !(Len - i - j > 1 and idx[i + j] == 0)) { n         b = Cmp_Hash(i, i + j - 1); n         b2 = Cmp_Hash2(i, i + j - 1); n         c = Cmp_Hash(i + j, Len - 1); n         c2 = Cmp_Hash2(i + j, Len - 1); n         if ((a + b) % Mod == c % Mod and (a2 + b2) % Mod2 == c2 % Mod2) { n           Flag = 1, Left_a = 0, Right_a = i - 1, Left_b = i; n           Right_b = i + j - 1, Left_c = i + j, Right_c = Len - 1; n           break; n         } n       } n     } n     if (i > (Len - 1) / 3 - 1) { n       j = Len - 2 * i; n       if (!(idx[i] == 0 and j > 1) and !(Len - i - j > 1 and idx[i + j] == 0)) { n         b = Cmp_Hash(i, i + j - 1); n         b2 = Cmp_Hash2(i, i + j - 1); n         c = Cmp_Hash(i + j, Len - 1); n         c2 = Cmp_Hash2(i + j, Len - 1); n         if ((a + b) % Mod == c % Mod and (a2 + b2) % Mod2 == c2 % Mod2) { n           Flag = 1, Left_a = 0, Right_a = i - 1, Left_b = i; n           Right_b = i + j - 1, Left_c = i + j, Right_c = Len - 1; n           break; n         } n       } n       j = Len - 2 * i - 1; n       if (!(idx[i] == 0 and j > 1) and !(Len - i - j > 1 and idx[i + j] == 0)) { n         b = Cmp_Hash(i, i + j - 1); n         b2 = Cmp_Hash2(i, i + j - 1); n         c = Cmp_Hash(i + j, Len - 1); n         c2 = Cmp_Hash2(i + j, Len - 1); n         if ((a + b) % Mod == c % Mod and (a2 + b2) % Mod2 == c2 % Mod2) { n           Flag = 1, Left_a = 0, Right_a = i - 1, Left_b = i; n           Right_b = i + j - 1, Left_c = i + j, Right_c = Len - 1; n           break; n         } n       } n     } n     if (Flag == 1) break; n   } n   if (Flag == 1) { n     for (int i = Left_a; i <= Right_a; i++) Write(idx[i]); n     putchar( + ); n     for (int i = Left_b; i <= Right_b; i++) Write(idx[i]); n     putchar( = ); n     for (int i = Left_c; i <= Right_c; i++) Write(idx[i]); n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1); n const double EPS = 1e-7; n const int inf = 1e8; n int main() { n   int n, sum = 0; n   cin >> n; n   vector<int> in(n); n   for (int i = 0; i < n; i++) cin >> in[i]; n   for (int i = 0; i < n; i++) sum += in[i]; n   vector<int> used(n); n   for (int i = 0; i < n; i++) n     if (!used[i]) { n       for (int j = i + 1; j < n; j++) n         if (!used[j] && in[i] + in[j] == sum * 2 / n) { n           used[i] = used[j] = true; n           cout << i + 1 <<     << j + 1 << endl; n           break; n         } n     } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, p, q, r, e, ans; n vector<long long> fst, lst, mid, Ans; n int main() { n   cin >> n >> p >> q >> r; n   for (int i = 0; i < n; i++) { n     cin >> e; n     fst.push_back(p * e); n     mid.push_back(q * e); n     lst.push_back(r * e); n   } n   long long mxe; n   mxe = fst[0]; n   for (int i = 1; i < n; i++) { n     mxe = max(mxe, fst[i]); n     fst[i] = mxe; n   } n   mxe = lst[n - 1]; n   for (int i = n - 2; i >= 0; i--) { n     mxe = max(mxe, lst[i]); n     lst[i] = mxe; n   } n   for (int i = 0; i < n; i++) { n     ans = fst[i] + mid[i] + lst[i]; n     Ans.push_back(ans); n   } n   cout << *max_element(Ans.begin(), Ans.end()); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   int a[m][n]; n   for (int i = 0; i < m; i++) n     for (int j = 0; j < n; j++) cin >> a[i][j]; n   int ans[n]; n   memset(ans, 0, sizeof(ans)); n   int k = 0; n   int x = 0, y = 0; n   int ma = INT_MIN; n   for (int i = 0; i < m; i++) { n     for (int j = 0; j < n; j++) { n       if (a[i][j] > ma) { n         x = j; n         ma = a[i][j]; n       } n     } n     ans[x]++; n     ma = INT_MIN; n   } n   ma = INT_MIN; n   for (int i = 0; i < n; i++) { n     if (ans[i] > ma) { n       x = i; n       ma = ans[i]; n     } n   } n   cout << x + 1 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n map<string, set<string> > ma; n set<string> hostname; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   int n; n   cin >> n; n   while (n--) { n     string s; n     cin >> s; n     int i = s.find( / , 7); n     if (i != -1) { n       string path = s.substr(i, s.size()); n       string name = s.substr(0, i); n       ma[name].insert(path); n       hostname.insert(name); n     } else { n       ma[s].insert( lorem ); n       hostname.insert(s); n     } n   } n   map<set<string>, vector<string> > ans; n   for (string s : hostname) { n     ans[ma[s]].emplace_back(s); n   } n   for (auto it = begin(ans); it != end(ans);) { n     if ((it->second).size() == 1) { n       ans.erase(it->first); n       it = begin(ans); n     } else n       ++it; n   } n   cout << ans.size() <<   n ; n   for (auto [key, val] : ans) { n     for (string s : val) { n       cout << s <<    ; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n template <typename T> n T min(T x, T y) { n   return x < y ? x : y; n } n template <typename T> n T max(T x, T y) { n   return x > y ? x : y; n } n template <typename T> n T abs(T x) { n   return x > 0 ? x : -x; n } n template <typename T> n T gcd(T x, T y) { n   return x ? gcd(y % x, x) : y; n } n int main() { n   int t, d, l, r, p; n   scanf( %d , &t); n   while (t--) { n     scanf( %d %d %d %d , &d, &p, &l, &r); n     printf( %d n , d / p - r / p + (l - 1) / p); n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <typename num_t> n inline void addmod(num_t& a, const long long& b, const int& m) { n   a = (a + b) % m; n   if (a < 0) a += m; n } n template <typename num_t> n inline void update_max(num_t& a, const num_t& b) { n   a = max(a, b); n } n template <typename num_t> n inline void update_min(num_t& a, const num_t& b) { n   a = min(a, b); n } n template <typename num_t> n num_t gcd(num_t lhs, num_t rhs) { n   return !lhs ? rhs : gcd(rhs % lhs, lhs); n } n template <typename num_t> n num_t pw(num_t n, num_t k, num_t mod) { n   num_t res = 1; n   for (; k > 0; k >>= 1) { n     if (k & 1) res = 1ll * res * n % mod; n     n = 1ll * n * n % mod; n   } n   return res; n } n const int inf = 1e9 + 7; n const int mod = inf; n const int MAX_N = 200000 + 7; n const long long ll_inf = 9ll * inf * inf; n int n, k; n array<int, 5> arr[MAX_N]; n int pre_calc[32][MAX_N]; n int calc(array<int, 5>& arr, int mask) { n   int sum = 0; n   for (int i = (0), _b = (k); i < _b; ++i) n     if (mask & (1 << i)) n       sum += arr[i]; n     else n       sum -= arr[i]; n   return sum; n } n void update(int i, array<int, 5>& temp) { n   arr[i] = temp; n   for (int mask = (0), _b = (1 << k); mask < _b; ++mask) { n     pre_calc[mask][i] = calc(temp, mask); n   } n } n template <typename num_t> n class SegmentTree { n  public: n   void init(int l, int r) { n     tree.resize((r - l + 1) << 1); n     node_index = 0; n     build_tree(tree[node_index++], l, r); n   } n   void update(int left_index, int right_index) { n     update_(tree[0], left_index, right_index); n   } n   num_t get(int left_index, int right_index) { n     if (right_index < left_index) return 0; n     return get(tree[0], left_index, right_index).best_value; n   } n  n  private: n   struct node { n     static const num_t nil = 0; n     node *left_child, *right_child; n     int left_index, right_index; n     array<int, 32> min_value; n     array<int, 32> max_value; n     int best_value = 0; n     bool inited = false; n     void push_down() { n       for (int i = (0), _b = (1 << k); i < _b; ++i) { n         min_value[i] = max_value[i] = left_index; n       } n       best_value = 0; n       inited = true; n     } n     inline int dist(array<int, 5>& lhs, array<int, 5>& rhs) { n       int sum = 0; n       for (int i = (0), _b = (k); i < _b; ++i) sum += abs(lhs[i] - rhs[i]); n       return sum; n     } n     void merge_node() { n       node &lhs = *left_child, &rhs = *right_child; n       merge_node(lhs, rhs); n     } n     void merge_node(node& lhs, node& rhs) { n       best_value = max(lhs.best_value, rhs.best_value); n       inited = true; n       if (lhs.inited && rhs.inited) { n         for (int i = (0), _b = (1 << k); i < _b; ++i) { n           update_max(best_value, n                      dist(arr[lhs.max_value[i]], arr[rhs.min_value[i]])); n           update_max(best_value, n                      dist(arr[rhs.max_value[i]], arr[lhs.min_value[i]])); n           if (pre_calc[i][lhs.max_value[i]] <= pre_calc[i][rhs.max_value[i]]) n             max_value[i] = rhs.max_value[i]; n           else n             max_value[i] = lhs.max_value[i]; n           if (pre_calc[i][lhs.min_value[i]] <= pre_calc[i][rhs.min_value[i]]) n             min_value[i] = lhs.min_value[i]; n           else n             min_value[i] = rhs.min_value[i]; n         } n       } else if (lhs.inited) { n         min_value = lhs.min_value; n         max_value = lhs.max_value; n       } else { n         min_value = rhs.min_value; n         max_value = rhs.max_value; n       } n     } n     void lazy_update() {} n     inline void init(int left, int right, node* left_child_, n                      node* right_child_) { n       left_index = left; n       right_index = right; n       left_child = left_child_; n       right_child = right_child_; n     } n     int size() const { return right_index - left_index + 1; } n   }; n   vector<node> tree; n   int node_index = 0; n   void build_tree(node& root, int left, int right) { n     if (left == right) { n       root.init(left, right, nullptr, nullptr); n       root.push_down(); n       return; n     } n     int mid = (left + right) >> 1, lhs = node_index++, rhs = node_index++; n     build_tree(tree[lhs], left, mid); n     build_tree(tree[rhs], mid + 1, right); n     root.init(left, right, &tree[lhs], &tree[rhs]); n     root.merge_node(); n   } n   void update_(node& root, int u, int v) { n     if (u > root.right_index || v < root.left_index) return; n     if (u <= root.left_index && root.right_index <= v) { n       root.push_down(); n     } else { n       root.lazy_update(); n       update_(*root.left_child, u, v); n       update_(*root.right_child, u, v); n       root.merge_node(); n     } n   } n   node get(node& root, int u, int v) { n     if (u <= root.left_index && root.right_index <= v) return root; n     if (u > root.right_index || v < root.left_index) return node(); n     root.lazy_update(); n     auto lhs = get(*root.left_child, u, v); n     auto rhs = get(*root.right_child, u, v); n     node ans; n     ans.merge_node(lhs, rhs); n     return ans; n   } n }; n SegmentTree<int> segment_tree; n void solve() { n   cin >> n >> k; n   for (int i = (0), _b = (n); i < _b; ++i) { n     array<int, 5> cur; n     for (int j = (0), _b = (k); j < _b; ++j) cin >> cur[j]; n     update(i, cur); n   } n   segment_tree.init(0, n - 1); n   int q; n   cin >> q; n   while (q-- > 0) { n     int op; n     cin >> op; n     if (op == 1) { n       int u; n       cin >> u; n       --u; n       array<int, 5> cur; n       for (int j = (0), _b = (k); j < _b; ++j) cin >> cur[j]; n       update(u, cur); n       segment_tree.update(u, u); n     } else { n       int u, v; n       cin >> u >> v; n       cout << segment_tree.get(u - 1, v - 1) <<   n ; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   const bool multiple_test = false; n   int test = 1; n   if (multiple_test) cin >> test; n   for (int i = 0; i < test; ++i) { n     solve(); n   } n } n


#include <bits/stdc++.h> n int next[1 + (1000 * (1000 - 1)) * 2], hh[1 + (1000 * (1000 - 1)) * 2], l_; n int link(int l, int h) { n   next[l_] = l; n   hh[l_] = h; n   return l_++; n } n int ij[(1000 * (1000 - 1))], ww[(1000 * (1000 - 1))], ao[1000]; n long long ww_[1000][1000]; n int pq[1 + 1000], iq[1000], cnt; n long long *dd; n int less(int u, int v) { return dd[u] < dd[v]; } n int i2(int i) { n   return (i *= 2) > cnt ? 0 : i < cnt && less(pq[i + 1], pq[i]) ? i + 1 : i; n } n void pq_up(int u) { n   int i, j, v; n   for (i = iq[u]; (j = i / 2) && less(u, v = pq[j]); i = j) pq[iq[v] = i] = v; n   pq[iq[u] = i] = u; n } n void pq_dn(int u) { n   int i, j, v; n   for (i = iq[u]; (j = i2(i)) && less(v = pq[j], u); i = j) pq[iq[v] = i] = v; n   pq[iq[u] = i] = u; n } n void pq_add_last(int u) { iq[u] = ++cnt; } n int pq_remove_first() { n   int u = pq[1], v = pq[cnt--]; n   iq[v] = 1; n   pq_dn(v); n   return u; n } n void dijkstra(int s, int n) { n   int h, i, j, l, w; n   memset(dd, 0x3f, n * sizeof *dd), dd[s] = 0; n   pq_add_last(s), pq_up(s); n   while (cnt) { n     i = pq_remove_first(); n     for (l = ao[i]; l; l = next[l]) { n       h = hh[l]; n       j = i ^ ij[h]; n       w = ww[h]; n       if (dd[j] > dd[i] + w) { n         if (dd[j] == 0x3f3f3f3f3f3f3f3fLL) pq_add_last(j); n         dd[j] = dd[i] + w; n         pq_up(j); n       } n     } n   } n } n int main() { n   int n, m, s, t, h, i, j, w, d, c; n   scanf( %d%d%d%d , &n, &m, &s, &t), s--, t--; n   l_ = 1; n   for (h = 0; h < m; h++) { n     scanf( %d%d%d , &i, &j, &w), i--, j--; n     ij[h] = i ^ j; n     ww[h] = w; n     ao[i] = link(ao[i], h); n     ao[j] = link(ao[j], h); n   } n   for (i = 0; i < n; i++) { n     dd = ww_[i]; n     dijkstra(i, n); n   } n   l_ = 1; n   m = 0; n   for (i = 0; i < n; i++) { n     scanf( %d%d , &d, &c); n     dd = ww_[i]; n     ao[i] = 0; n     for (j = 0; j < n; j++) n       if (j != i && dd[j] <= d) { n         ij[m] = i ^ j; n         ww[m] = c; n         ao[i] = link(ao[i], m++); n       } n   } n   dijkstra(s, n); n   printf( %lld n , dd[t] == 0x3f3f3f3f3f3f3f3fLL ? -1 : dd[t]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Point { n   int x, y, nr; n   bool t; n }; n const int N = 2e4 + 7; n int n, m; n int ans[N]; n Point tab[N]; n bool cmp(Point a, Point b) { n   if (a.x == b.x) return a.y < b.y; n   return a.x < b.x; n } n int xr, yr; n void change(Point &a) { n   xr = a.x; n   yr = a.y; n } n bool cmp2(Point a, Point b) { n   return (a.x - xr) * (b.y - yr) < (b.x - xr) * (a.y - yr); n } n void wczytaj(int a) { n   scanf( %d %d , &tab[a].x, &tab[a].y); n   tab[a].nr = a; n   if (a > n) { n     tab[a].t = true; n     tab[a].nr -= n; n   } n } n void connect(int x, int y) { n   if (tab[x].t) n     ans[tab[y].nr] = tab[x].nr; n   else n     ans[tab[x].nr] = tab[y].nr; n } n void solve(int from, int to) { n   if (from > to) return; n   assert((to - from) % 2 == 1); n   if (from + 1 == to) { n     connect(from, to); n     return; n   } n   int id = min_element(tab + from, tab + to + 1, cmp) - tab; n   swap(tab[id], tab[from]); n   change(tab[from]); n   sort(tab + from + 1, tab + to + 1, cmp2); n   int pref = 0, mid = 0; n   for (int i = from + 1; i <= to; ++i) { n     if (tab[i].t != tab[from].t && pref == 0) { n       mid = i; n       break; n     } n     pref += tab[i].t ? 1 : -1; n   } n   assert(mid != 0); n   connect(from, mid); n   solve(from + 1, mid - 1); n   solve(mid + 1, to); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) wczytaj(i); n   for (int i = 1; i <= n; ++i) wczytaj(n + i); n   solve(1, 2 * n); n   for (int i = 1; i <= n; ++i) printf( %d n , ans[i]); n   return 0; n } n


#include <iostream> n #include <vector> n #include <set>  n #include <algorithm> n #include<map> n #include <math.h> n using namespace std; n void solve(){ n    int n,x,t; n    cin>>n>>x>>t; n    cout<<(long long)max(0,n-t/x)*(t/x) + (long long)min(n,t/x)*min(n-1,t/x-1)/2<<endl; n      n } n  n int main() n { n #ifndef ONLINE_JUDGE n     freopen( input.txt ,  r , stdin); n     freopen( output.txt ,  w , stdout); n #endif n     ios_base::sync_with_stdio(false); n     cin.tie(NULL); n  n     int testCase; n     cin>>testCase; n     while (testCase--) n     { n         solve(); n     } n      n }


#include <bits/stdc++.h> n using namespace std; n long long max(long long a, long long b) { n   if (a > b) n     return a; n   else n     return b; n } n long long min(long long a, long long b) { n   if (a < b) n     return a; n   else n     return b; n } n long long power(long long B, long long P) { n   if (P == 0) return 1; n   long long X = power(B, P / 2); n   if (P % 2 == 0) n     return X * X; n   else n     return B * X * X; n } n long long fx4[] = {1, -1, 0, 0}; n long long fy4[] = {0, 0, 1, -1}; n long long D[300005], C[300005]; n int main() { n   long long T, N, M, X, Y, W, K, Q, R, P; n   cin >> N; n   for (int i = 1; i < N; i++) { n     cin >> X >> Y; n     D[X]++; n     D[Y]++; n   } n   for (int i = 1; i <= N; i++) { n     if (D[i] == 2) { n       cout <<  NO  << endl; n       return 0; n     } n   } n   cout <<  YES  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n void solve() { n   long long int n, k; n   long long int right = (long long int)2e9; n   long long int left = 0; n   cin >> n >> k; n   long long int a[n], b[n]; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < n; i++) cin >> b[i]; n   while (right - left > 0) { n     long long int mid = (right + left + 1) / 2; n     long long int cnt = 0; n     for (int i = 0; i < n; i++) { n       cnt += max(0LL, mid * a[i] - b[i]); n       if (cnt > k) break; n     } n     if (cnt <= k) n       left = mid; n     else n       right = mid - 1; n   } n   cout << left; n } n int main() { n   solve(); n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct dat { n   int x, rev, f, cap, cost; n   dat(int x = 0, int rev = 0, int f = 0, int cap = 0, int cost = 0) n       : x(x), rev(rev), f(f), cap(cap), cost(cost) {} n }; n vector<dat> v[5100]; n void add(int s, int t, int ca, int co) { n   int n = v[s].size(); n   int m = v[t].size(); n   v[s].push_back(dat(t, m, 0, ca, co)); n   v[t].push_back(dat(s, n, 0, 0, -co)); n } n priority_queue<pair<int, int> > q; n pair<int, int> pa[5100]; n int pot[5100], vis[5100], A[5100 * 10], dist[5100], col[5100][5100], a[5100], n     b[5100], deg[5100], deg1[5100], fl[5100]; n int mx = 0; n int doit(int de) { n   int mxx = 0; n   for (int i = 0; i <= de; i++) pot[i] = 1e9; n   pot[0] = 0; n   int qt = 0; n   A[qt++] = 0; n   int nodes = de + 1; n   for (int i = 0; i <= de; i++) vis[i] = 0; n   for (int qh = 0; (qh - qt) % nodes != 0; qh++) { n     int u = A[qh % nodes]; n     vis[u] = false; n     for (int i = 0; i < (int)v[u].size(); i++) { n       dat e = v[u][i]; n       if (e.cap == e.f) continue; n       int vv = e.x; n       int ndist = pot[u] + e.cost; n       if (pot[vv] > ndist) { n         pot[vv] = ndist; n         if (!vis[vv]) { n           vis[vv] = true; n           A[qt++ % nodes] = vv; n         } n       } n     } n   } n   while (1) { n     for (int i = 0; i <= de; i++) fl[de] = 0; n     for (int i = 0; i <= de; i++) dist[i] = 1e9; n     dist[0] = 0; n     while (!q.empty()) q.pop(); n     q.push(pair<int, int>(0, 0)); n     fl[0] = 1e9; n     while (!q.empty()) { n       pair<int, int> aa = q.top(); n       q.pop(); n       int x = aa.second; n       if (-aa.first != dist[x]) continue; n       for (int i = 0; i < v[x].size(); i++) { n         dat bb = v[x][i]; n         if (bb.f == bb.cap) continue; n         int y = bb.x; n         int xx = dist[x] + bb.cost + pot[x] - pot[y]; n         if (dist[y] > xx) { n           dist[y] = xx; n           q.push(pair<int, int>(-dist[y], y)); n           pa[y] = pair<int, int>(x, i); n           fl[y] = min(fl[x], bb.cap - bb.f); n         } n       } n     } n     if (!fl[de]) break; n     mxx += fl[de]; n     for (int i = 0; i <= de; i++) pot[i] += dist[i]; n     int x = de; n     while (1) { n       pair<int, int> aa = pa[x]; n       int y = aa.first; n       int id = aa.second; n       v[y][id].f += fl[de]; n       v[x][v[y][id].rev].f -= fl[de]; n       if (!y) break; n       x = y; n     } n   } n   return mxx; n } n int main() { n   int n, m, K, T; n   scanf( %d%d%d%d , &n, &m, &K, &T); n   for (int i = 1; i <= K; i++) { n     scanf( %d%d , &a[i], &b[i]); n     deg[a[i]]++; n     deg1[b[i]]++; n   } n   int ans = 0; n   for (int i = 1; i <= n; i++) ans += (deg[i] % T) > 0; n   for (int i = 1; i <= m; i++) ans += (deg1[i] % T) > 0; n   printf( %d n , ans); n   int so = 0; n   int de = m + n + 1; n   mx = 0; n   for (int i = T; i; i--) { n     for (int j = 0; j <= de; j++) v[j].clear(); n     for (int j = 1; j <= K; j++) n       if (!col[a[j]][b[j]]) { n         add(a[j], b[j] + n, 1, 0); n       } n     int kt = 0; n     for (int j = 1; j <= n; j++) { n       add(so, j, deg[j] / i, 0); n       kt += deg[j] / i; n       if (deg[j] % i) add(so, j, 1, 1); n     } n     int kt1 = 0; n     for (int j = 1; j <= m; j++) { n       add(j + n, de, deg1[j] / i, 0); n       if (deg1[j] % i) add(j + n, de, 1, 1); n     } n     int mm = doit(de); n     mx += mm; n     for (int j = 1; j <= n; j++) { n       for (int k = 0; k < v[j].size(); k++) { n         dat aa = v[j][k]; n         if (aa.x == so) continue; n         if (aa.f == 1) { n           int y = aa.x; n           if (y > n && y <= n + m) { n             col[j][y - n] = i; n             deg[j]--, deg1[y - n]--; n           } n         } n       } n     } n   } n   for (int i = 1; i <= K; i++) printf( %d  , col[a[i]][b[i]]); n   puts(  ); n } n


#include <bits/stdc++.h> n using namespace std; n int n; n vector<int> g[100010]; n int vis[100010]; n struct node { n   int num; n   long long inc; n   long long dec; n   int val; n } nodes[100010]; n void dfs(node &u) { n   vis[u.num] = 1; n   for (int v : g[u.num]) { n     if (!vis[v]) { n       dfs(nodes[v]); n       u.inc = max(u.inc, nodes[v].inc); n       u.dec = max(u.dec, nodes[v].dec); n     } n   } n   if (u.val + u.inc - u.dec < 0) { n     u.inc += abs(u.val + u.inc - u.dec); n   } else { n     u.dec += abs(u.val + u.inc - u.dec); n   } n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     nodes[i].num = i; n     nodes[i].inc = nodes[i].dec = 0; n   } n   for (int i = 1; i < n; ++i) { n     int u, v; n     cin >> u >> v; n     g[u].push_back(v); n     g[v].push_back(u); n   } n   for (int i = 1; i <= n; ++i) { n     int v; n     cin >> v; n     nodes[i].val = v; n   } n   dfs(nodes[1]); n   cout << nodes[1].inc + nodes[1].dec; n   return 0; n } n