#include <bits/stdc++.h> n using namespace std; n int g[65]{0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4,  4,  5,  5,  5,  5, 5, 5, n           6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,  7,  8,  8,  8,  8, 8, 8, n           8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10}; n const int MAXN = 1000007; n int s[MAXN]; n map<pair<int, long long>, int> dp; n int grundy(pair<int, long long> s) { n   if (dp.find(s) != dp.end()) return dp[s]; n   long long mask = s.second; n   int &res = dp[s]; n   set<int> S; n   for (int i = 1; i <= 60; i++) { n     if (!(mask & (1ll << i)) && s.first >= i) { n       S.insert(grundy(make_pair(s.first - i, (mask | (1ll << i))))); n     } n   } n   while (S.count(res) > 0) res++; n   return res; n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &s[i]); n   } n   if (n == 1) n     printf( NO n ); n   else { n     int XOR = 0; n     for (int i = 0; i < n; i++) { n       XOR ^= grundy(make_pair(s[i], 0)); n     } n     if (XOR == 0) n       printf( YES n ); n     else n       printf( NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void cline() { cout <<   n ; } n template <typename T, typename... V> n void cline(T t, V... v) { n   cout << t; n   if (sizeof...(v)) cout <<    ; n   cline(v...); n } n void cspc() { cout <<    ; } n template <typename T, typename... V> n void cspc(T t, V... v) { n   cout << t; n   if (sizeof...(v)) cout <<    ; n   cspc(v...); n } n int n; n int a[105]; n int dp[104][52][52][2]; n int calc(int indx, int even, int odd, int pre) { n   if (indx == n) return 0; n   if (dp[indx][even][odd][pre] != -1) return dp[indx][even][odd][pre]; n   if (indx == 0) { n     if (a[indx] == 0) { n       if (even == 0) { n         return dp[indx][even][odd][pre] = calc(indx + 1, even, odd - 1, 1); n       } else if (odd == 0) { n         return dp[indx][even][odd][pre] = calc(indx + 1, even - 1, odd, 0); n       } else { n         return dp[indx][even][odd][pre] = min(calc(indx + 1, even, odd - 1, 1), n                                               calc(indx + 1, even - 1, odd, 0)); n       } n     } else { n       return dp[indx][even][odd][pre] = calc(indx + 1, even, odd, a[indx] % 2); n     } n   } else { n     if (a[indx] == 0) { n       if (even == 0) { n         if (pre % 2 == 0) { n           return dp[indx][even][odd][pre] = n                      calc(indx + 1, even, odd - 1, 1) + 1; n         } else { n           return dp[indx][even][odd][pre] = calc(indx + 1, even, odd - 1, 1); n         } n       } else if (odd == 0) { n         if (pre % 2 == 1) { n           return dp[indx][even][odd][pre] = n                      calc(indx + 1, even - 1, odd, 0) + 1; n         } else { n           return dp[indx][even][odd][pre] = calc(indx + 1, even - 1, odd, 0); n         } n       } else { n         if (pre % 2 != 0) { n           return dp[indx][even][odd][pre] = n                      min(calc(indx + 1, even, odd - 1, 1), n                          calc(indx + 1, even - 1, odd, 0) + 1); n         } else { n           return dp[indx][even][odd][pre] = n                      min(calc(indx + 1, even, odd - 1, 1) + 1, n                          calc(indx + 1, even - 1, odd, 0)); n         } n       } n     } else { n       if (a[indx] % 2 != pre % 2) { n         return dp[indx][even][odd][pre] = n                    calc(indx + 1, even, odd, a[indx] % 2) + 1; n       } else { n         return dp[indx][even][odd][pre] = n                    calc(indx + 1, even, odd, a[indx] % 2); n       } n     } n   } n } n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   int even = n / 2, odd = (n + 1) / 2; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i] % 2 == 0) n       even--; n     else n       odd--; n     if (a[i] == 0) even++; n   } n   for (int in1 = 0; in1 < 104; in1++) { n     for (int in2 = 0; in2 < 52; in2++) { n       for (int in3 = 0; in3 < 52; in3++) { n         dp[in1][in2][in3][0] = -1; n         dp[in1][in2][in3][1] = -1; n       } n     } n   } n   cspc(calc(0, even, odd, 0)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e3 + 3; n int n, m, dp[N], vis[2][N]; n vector<int> adj[2][N]; n vector<pair<int, int>> e; n void dfs(int u, int dir) { n   vis[dir][u] = 1; n   for (int v : adj[dir][u]) n     if (!vis[dir][v]) dfs(v, dir); n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> n >> m; n   for (int i = 0, u, v; i < m; i++) { n     cin >> u >> v; n     adj[0][u].push_back(v); n     adj[1][v].push_back(u); n     e.push_back({u, v}); n   } n   dfs(1, 0), dfs(n, 1); n   for (int i = 0; i < n - 1; i++) n     for (auto [u, v] : e) n       if (vis[0][u] & vis[1][v]) { n         dp[u] = min(dp[u], dp[v] + 2); n         dp[v] = min(dp[v], dp[u] - 1); n       } n   for (auto [u, v] : e) n     if (vis[0][u] & vis[1][v] & (dp[u] > dp[v] + 2 || dp[v] > dp[u] - 1)) n       return cout <<  No  << endl, 0; n   cout <<  Yes  << endl; n   for (auto [u, v] : e) n     cout << (vis[0][u] & vis[1][v] ? dp[u] - dp[v] : 1) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxn = 1e6 + 10; n long long a[maxn], b[maxn], ans[maxn]; n int32_t main() { n   long long n; n   cin >> n; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n     b[i] = a[i]; n   } n   sort(b, b + n); n   if (b[0] == b[n - 1]) { n     if (b[0] == 0) { n       cout <<  YES  <<   n ; n       for (long long i = 0; i < n; i++) cout <<  1  ; n     } else n       cout <<  NO ; n     exit(0); n   } n   long long pos = -1, mx = b[n - 1]; n   for (long long i = 0; i < n; i++) { n     if (a[i] == mx && a[(i - 1 + n) % n] != mx) pos = i; n   } n   ans[pos] = a[pos]; n   bool bad = 1; n   for (long long i = (pos - 1 + n) % n; i != pos; i = (i - 1 + n) % n) { n     if (a[i] == 0 && bad) n       ans[i] = ans[(i + 1) % n] * 2LL, bad = 0; n     else n       ans[i] = ans[(i + 1) % n] + a[i]; n   } n   cout <<  YES  <<   n ; n   for (long long i = 0; i < n; i++) cout << ans[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 105; n long long l, r, dp[N]; n long long gao(long long n) { n   long long m = n, ans = 0; n   int bit[N], len = 0; n   while (n) { n     bit[++len] = n % 2; n     n /= 2; n   } n   for (int i = 2; i < len; i++) { n     memset(dp, 0, sizeof(dp)); n     dp[1] = 1; n     for (int j = 2; j < i; j++) { n       if (i % j) continue; n       dp[j] += 1LL << (j - 1); n     } n     for (int j = 1; j <= i; j++) { n       for (int k = 2; k * j < i; k++) n         if (i % (k * j) == 0) dp[j * k] -= dp[j]; n     } n     for (int j = 1; j <= i; j++) ans += dp[j]; n   } n   for (int i = len; i <= len; i++) { n     memset(dp, 0, sizeof(dp)); n     for (int j = 1; j < i; j++) { n       if (i % j) continue; n       for (int k = len; k > len - j; k--) { n         if (k != len && bit[k] == 1) { n           dp[j] += 1LL << (k - (len - j) - 1); n         } n       } n       long long sum = 0; n       for (int k = len; k > len - j; k--) { n         if (bit[k] == 0) continue; n         for (int r = k; r > 0; r -= j) { n           sum += 1LL << (r - 1); n         } n       } n       if (sum <= m) dp[j]++; n     } n     for (int j = 1; j <= i; j++) { n       for (int k = 2; k * j < i; k++) n         if (i % (k * j) == 0) dp[j * k] -= dp[j]; n     } n     for (int j = 1; j <= i; j++) ans += dp[j]; n   } n   return ans; n } n int main() { n   while (cin >> l >> r) { n     cout << gao(r) - gao(l - 1) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n int setBit(int N, int pos) { return N = N | (1 << pos); } n int resetBit(int N, int pos) { return N = N & ~(1 << pos); } n bool checkBit(int N, int pos) { return (bool)(N & (1 << pos)); } n using namespace std; n const int maxn = 100000; n int n, m, cost[maxn + 5], okayRoad[maxn + 5], par[maxn + 5]; n vector<int> graph[maxn + 5], flag[maxn + 5]; n map<pair<int, int>, int> mapp, out; n map<pair<int, int>, int>::iterator it; n void bfs() { n   queue<int> q; n   int i, u, v; n   memset(cost, 63, sizeof(cost)); n   ; n   cost[1] = 0; n   par[1] = 1; n   q.push(1); n   while (!q.empty()) { n     u = q.front(); n     q.pop(); n     int siz = (int)graph[u].size(); n     for (i = 0; i < siz; i++) { n       v = graph[u][i]; n       if (cost[u] + 1 < cost[v]) { n         cost[v] = cost[u] + 1; n         okayRoad[v] = okayRoad[u] + flag[u][i]; n         par[v] = u; n         q.push(v); n       } else if (cost[u] + 1 == cost[v] && n                  okayRoad[u] + flag[u][i] > okayRoad[v]) { n         okayRoad[v] = okayRoad[u] + flag[u][i]; n         par[v] = u; n         q.push(v); n       } n     } n   } n } n void giveOutput() { n   int u, v = n; n   vector<int> path; n   path.push_back(n); n   while (v != par[v]) { n     v = par[v]; n     path.push_back(v); n   } n   int i, j, siz = (int)path.size(); n   for (i = 1; i < siz; i++) { n     u = path[i - 1]; n     v = path[i]; n     if (u > v) swap(u, v); n     if (mapp[pair<int, int>(u, v)] == 0) out[pair<int, int>(u, v)] = 1; n     mapp[pair<int, int>(u, v)] = -1; n   } n   for (__typeof((mapp).begin()) it = (mapp).begin(); it != (mapp).end(); it++) { n     if (it->second == 1) out[it->first] = 0; n   } n   printf( %d n , (int)out.size()); n   for (__typeof((out).begin()) it = (out).begin(); it != (out).end(); it++) { n     cout << it->first.first <<     << it->first.second <<     << it->second n          <<   n ; n   } n } n int main() { n   int i, u, v, w; n   scanf( %d %d , &n, &m); n   for (i = 0; i < m; i++) { n     scanf( %d %d %d , &u, &v, &w); n     if (u > v) swap(u, v); n     graph[u].push_back(v); n     graph[v].push_back(u); n     flag[u].push_back(w); n     flag[v].push_back(w); n     mapp[pair<int, int>(u, v)] = w; n   } n   bfs(); n   giveOutput(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[301][301], h, w, dp[301][301]; n int used[601][601]; n int dx[] = {0, 1, -1, 0, 0, 1, -1, 1, -1}; n int dy[] = {0, 0, 0, 1, -1, 1, 1, -1, -1}; n int read() { n   int x; n   scanf( %d , &x); n   return x; n } n bool check(int x, int y) { n   if (x >= 1 && x <= h && y >= 1 && y <= w && !used[x][y]) n     return true; n   else n     return false; n } n void dfs(int x, int y, int component) { n   used[x][y] = component; n   for (int i = 1; i <= 8; i++) { n     int kx = dx[i] + x, ky = dy[i] + y; n     if (check(kx, ky) && a[x][y] == a[kx][ky]) { n       dfs(kx, ky, component); n     } n   } n } n void init() { n   for (int i = 0; i <= 600; i++) { n     for (int j = 0; j <= 600; j++) { n       used[i][j] = 0; n     } n   } n } n int main() { n   int q; n   q = read(); n   while (q--) { n     h = read(), w = read(); n     init(); n     for (int i = 1; i <= h; i++) { n       for (int j = 1; j <= w; j++) { n         a[i][j] = read(); n       } n     } n     int cntfirst = 0, cntsecond = 0; n     for (int i = 1; i <= h; i++) { n       for (int j = 1; j <= w; j++) { n         if (!used[i][j]) dfs(i, j, cntfirst + 1), cntfirst++; n       } n     } n     for (int i = h / 2 + 1; i <= h; i++) { n       for (int j = 1; j <= w; j++) { n         dp[i - h / 2][j] = a[i][j]; n       } n     } n     for (int i = 1; i <= h / 2; i++) { n       for (int j = 1; j <= w; j++) { n         dp[i + h / 2][j] = a[i][j]; n       } n     } n     for (int i = 1; i <= h; i++) { n       for (int j = 1; j <= w; j++) { n         a[i][j] = dp[i][j]; n       } n     } n     init(); n     for (int i = 1; i <= h; i++) { n       for (int j = 1; j <= w; j++) { n         if (!used[i][j]) dfs(i, j, cntsecond + 1), cntsecond++; n       } n     } n     if (cntfirst <= cntsecond) { n       printf( NO n ); n     } else { n       printf( YES n ); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 22e4; n char s[N * 2]; n int l[N * 2], r[N * 2]; n int main() { n   ios::sync_with_stdio(0); n   int n, k; n   cin >> n >> k >> s; n   for (int i = 0; i < n; i++) s[i + n] = s[i]; n   for (int i = 0, lx = -2e9; i < n * 2; i++) { n     if (s[i] == s[i + 1]) lx = i + 1; n     l[i + 1] = lx; n   } n   for (int i = n * 2 - 1, rx = 2e9; i > 0; i--) { n     if (s[i] == s[i - 1]) rx = i - 1; n     r[i - 1] = rx; n   } n   for (int i = 0; i < n; i++) { n     if (i + n - l[i + n] < r[i] - i) { n       if (i + n - l[i + n] <= k) n         cout << s[l[i + n]]; n       else if (k & 1) n         cout << (s[i] ==  W  ?  B  :  W ); n       else n         cout << s[i]; n     } else { n       if (r[i] - i <= k) n         cout << s[r[i]]; n       else if (k & 1) n         cout << (s[i] ==  W  ?  B  :  W ); n       else n         cout << s[i]; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = 2.0 * acos(0.0); n const double E = exp(1); n template <class T1> n void deb(T1 e) { n   cout << e << endl; n } n template <class T1, class T2> n void deb(T1 e1, T2 e2) { n   cout << e1 <<     << e2 << endl; n } n template <class T1, class T2, class T3> n void deb(T1 e1, T2 e2, T3 e3) { n   cout << e1 <<     << e2 <<     << e3 << endl; n } n template <class T1, class T2, class T3, class T4> n void deb(T1 e1, T2 e2, T3 e3, T4 e4) { n   cout << e1 <<     << e2 <<     << e3 <<     << e4 << endl; n } n template <class T1, class T2, class T3, class T4, class T5> n void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) { n   cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 << endl; n } n template <class T1, class T2, class T3, class T4, class T5, class T6> n void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) { n   cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 <<     << e6 n        << endl; n } n template <typename T> n inline T sqr(T n) { n   return n * n; n } n inline double hypot(double x, double y) { return sqrt(sqr(x) + sqr(y)); } n template <typename T> n inline T pmod(T n, T m) { n   return ((n % m) + m) % m; n } n template <typename T> n T power(T n, int p) { n   return (p == 0) ? (T)(1) : (sqr(power(n, p >> 1)) * ((p & 1) * (n - 1) + 1)); n } n template <typename T> n T bigmod(T n, int p, T m) { n   return (p == 0) n              ? (T)(1) n              : ((sqr(bigmod(n, p >> 1, m)) % m) * ((p & 1) * (n - 1) % m + 1)) % n                    m; n } n bool dp[21][(1 << 6)][11][11][11][11][11]; n int row[6], col[23]; n int r, c; n vector<int> save[10]; n int calc(int mask) { n   int cnt = 0; n   int prv = 0; n   for (int i = 0; i < r; i++) { n     if (!prv && (mask & (1 << i))) { n       cnt++; n     } n     prv = mask & (1 << i); n   } n   return cnt; n } n char grid[6][21]; n int tmp[10]; n bool complet = 0; n void rec(int now, int prv_maks, int r1, int r2, int r3, int r4, int r5) { n   if (r1 < 0 || r2 < 0 || r3 < 0 || r4 < 0 || r5 < 0) return; n   if (complet) return; n   if (dp[now][prv_maks][r1][r2][r3][r4][r5]) return; n   dp[now][prv_maks][r1][r2][r3][r4][r5] = 1; n   if (now == c) { n     if (r1 + r2 + r3 + r4 + r5 == 0) { n       for (int i = 0; i < r; ++i) { n         for (int j = 0; j < c; ++j) printf( %c , grid[i][j]); n         printf(  n ); n       } n       complet = 1; n     } n     return; n   } n   int mask = 0; n   for (int i = 0; i < (int)save[col[now]].size(); i++) { n     mask = save[col[now]][i]; n     tmp[0] = r1; n     tmp[1] = r2; n     tmp[2] = r3; n     tmp[3] = r4; n     tmp[4] = r5; n     for (int j = 0; j < r; j++) { n       if (!(prv_maks & (1 << j)) && (mask & (1 << j))) { n         tmp[j]--; n       } n     } n     for (int j = 0; j < r; j++) { n       grid[j][now] = (mask & (1 << j)) ?  *  :  . ; n     } n     rec(now + 1, mask, tmp[0], tmp[1], tmp[2], tmp[3], tmp[4]); n     if (complet) return; n   } n } n int main() { n   scanf( %d %d , &r, &c); n   for (int i = 0; i < r; ++i) scanf( %d , &row[i]); n   for (int i = 0; i < c; ++i) { n     scanf( %d , &col[i]); n   }; n   int lim = 1 << r; n   for (int i = 0; i < (1 << r); i++) { n     save[calc(i)].push_back(i); n   } n   rec(0, 0, row[0], row[1], row[2], row[3], row[4]); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int p, d; n   cin >> p >> d; n   long long int temp = 1; n   long long int po[19]; n   for (int i = 0; i <= 18; ++i) { n     po[i] = temp; n     temp *= 10; n   } n   int i = 1; n   temp = p; n   while (1) { n     long long int t = temp % po[i]; n     t /= po[i - 1]; n     long long int x = temp; n     x -= (t * po[i - 1]); n     x += (9 * po[i - 1]); n     if (p - x >= 0 && p - x <= d) { n       i++; n       temp = x; n       continue; n     } n     if ((p - x + po[i]) <= d && x - po[i] >= 0) { n       x -= po[i]; n       temp = x; n       i++; n     } else n       break; n   } n   cout << temp; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[5005], dp[5005], b[5005]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   dp[0] = 0; n   for (int i = 1; i <= n; i++) { n     int p = i, s = a[i]; n     while (p > 0 && s < b[p - 1]) { n       s += a[p - 1]; n       p--; n     } n     dp[i] = dp[p - 1] + i - p; n     b[i] = s; n   } n   printf( %d n , dp[n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n const int maxn = 1e5 + 5; n vector<int> a[maxn]; n int res[maxn]; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) { n     int q, w; n     scanf( %d%d , &q, &w); n     a[q].push_back(w); n   } n   int ms = 0; n   for (int i = 1; i <= m; i++) { n     int sump = a[i].size(); n     sort(a[i].begin(), a[i].end()); n     ms = max(sump, ms); n     int sum = 0; n     for (int j = sump - 1; j >= 0; j--) { n       sum += a[i][j]; n       if (sum >= 0) n         res[sump - j] += sum; n       else n         break; n     } n   } n   int max1 = 0; n   for (int i = 1; i <= ms; i++) max1 = max(res[i], max1); n   printf( %d n , max1); n } n


#include <bits/stdc++.h> n using namespace std; n long long s(long long x) { n   long long sum = 0; n   while (x) { n     sum += x % 10; n     x /= 10; n   } n   return sum; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long T; n   T = 1; n   while (T--) { n     long long n, i, x, ans = -1; n     cin >> n; n     x = sqrt(n); n     for (i = 1; i <= 90; i++) { n       long long l, r; n       l = 1; n       r = x; n       while (l <= r) { n         long long m = l + (r - l) / 2; n         long long z = m * m + m * i; n         if (z == n && s(m) == i) n           ans = m, r = m - 1; n         else if (z < n) n           l = m + 1; n         else n           r = m - 1; n       } n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n const int N = 4000; n const int INF = 1e9; n struct edge { n   int to, c, f, back; n   edge(int to, int c, int f, int back) : to(to), c(c), f(f), back(back) {} n }; n vector<edge> g[N]; n vector<int> d(N), ptr(N); n int n, h, m; n int s, t; n void add_edge(int v, int u, int c) { n   g[v].push_back({u, c, 0, (int)g[u].size()}); n   g[u].push_back({v, 0, 0, (int)g[v].size() - 1}); n } n bool bfs() { n   fill(d.begin(), d.end(), INF); n   d[s] = 0; n   queue<int> q; n   q.push(s); n   while ((int)q.size()) { n     int v = q.front(); n     q.pop(); n     for (auto i : g[v]) { n       if (i.c > i.f && d[i.to] == INF) { n         d[i.to] = d[v] + 1; n         q.push(i.to); n       } n     } n   } n   return d[t] != INF; n } n int dfs(int v, int cur_flow = INF) { n   if (v == t || cur_flow == 0) return cur_flow; n   for (int i = ptr[v]; i < (int)g[v].size(); i++) { n     int u = g[v][i].to; n     if (d[v] + 1 == d[u]) { n       int push = dfs(u, min(cur_flow, g[v][i].c - g[v][i].f)); n       if (push) { n         g[v][i].f += push; n         g[u][g[v][i].back].f -= push; n         return push; n       } n     } n     ptr[v]++; n   } n   return 0; n } n int maxFlow() { n   int ret = 0; n   while (bfs()) { n     int cur = dfs(s); n     fill(ptr.begin(), ptr.end(), 0); n     while (cur) { n       ret += cur; n       cur = dfs(s); n     } n   } n   return ret; n } n int get_hash(int x, int y) { return x * 52 + y; } n signed main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> n >> h >> m; n   s = 0, t = N - 1; n   for (int i = 0; i < n; i++) { n     add_edge(s, get_hash(i, 0), INF); n     for (int j = 0; j <= h; j++) { n       add_edge(get_hash(i, j), get_hash(i, j + 1), h * h - j * j); n       add_edge(get_hash(i, j + 1), get_hash(i, j), INF); n     } n     add_edge(get_hash(i, h), t, 0); n   } n   int st = 50 * 55 + 10; n   assert(st + m < N); n   for (int i = 0; i < m; i++) { n     int l, r, x, c; n     cin >> l >> r >> x >> c; n     if (x == h) continue; n     l--; n     r--; n     for (int j = l; j <= r; j++) { n       add_edge(get_hash(j, x + 1), st + i, INF); n     } n     add_edge(st + i, t, c); n   } n   cout << n * h * h - maxFlow() <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n string A[18][18], s; n int n, m, U[101], us, J[3][3]; n bool B[1001]; n int r1, c1, r2, c2, size; n int tonum(char ch) { n   if (ch ==  C ) return 1; n   if (ch ==  D ) return 2; n   if (ch ==  H ) return 3; n   if (ch ==  S ) return 4; n   if (ch ==  T ) return 8; n   if (ch ==  J ) return 9; n   if (ch ==  Q ) return 10; n   if (ch ==  K ) return 11; n   if (ch ==  A ) return 12; n   return (int)ch - 50; n } n inline bool inside(int a, int b, int c) { n   if (b > c) swap(b, c); n   return (b <= a && a <= c); n } n inline bool ff(int r, int c) { n   bool B[13]; n   for (int i = 0; i <= 12; i++) B[i] = false; n   for (int i = r; i <= r + 2; i++) n     for (int j = c; j <= c + 2; j++) { n       if (B[tonum(A[i][j][0])]) return false; n       B[tonum(A[i][j][0])] = true; n     } n   return true; n } n inline bool check() { n   for (int i = 1; i <= size; i++) n     for (int j = i + 1; j <= size; j++) { n       r1 = (i % m) ? i / m + 1 : i / m; n       c1 = (i % m) ? (i % m) : m; n       r2 = (j % m) ? j / m + 1 : j / m; n       c2 = (j % m) ? (j % m) : m; n       if (!(inside(r2, r1, r1 + 2) && inside(c2, c1, c1 + 2)) && n           !(inside(r2, r1, r1 + 2) && inside(c2 + 2, c1, c1 + 2)) && n           inside(r1 + 2, 1, n) && inside(r2 + 2, 1, n) && n           inside(c1 + 2, 1, m) && inside(c2 + 2, 1, m)) { n         if (ff(r1, c1) && ff(r2, c2)) return true; n       } n     } n   return false; n } n char torank(int k) { n   int r = (k % 4) ? k / 4 + 1 : k / 4; n   if (r <= 8) return (char)(r + 49); n   if (r == 9) return  T ; n   if (r == 10) return  J ; n   if (r == 11) return  Q ; n   if (r == 12) return  K ; n   if (r == 13) return  A ; n } n char tosuit(int k) { n   int r = k % 4; n   if (r == 0) return  S ; n   if (r == 1) return  C ; n   if (r == 2) return  D ; n   if (r == 3) return  H ; n } n inline bool replacee(int j, int k) { n   if (J[j][1] == 0) return false; n   A[J[j][1]][J[j][2]][0] = torank(k); n   A[J[j][1]][J[j][2]][1] = tosuit(k); n   return true; n } n string print(int k) { n   char A[3]; n   A[0] = torank(k); n   A[1] = tosuit(k); n   A[2] =   0 ; n   string str(A); n   return str; n } n void printt() { n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) cout << A[i][j][0] << A[i][j][1] <<    ; n     cout << endl; n   } n   cout << endl; n } n int main() { n   bool rep1, rep2; n   cin >> n >> m; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       cin >> s; n       A[i][j].assign(s); n       if (s[0] ==  J ) { n         if (s[1] ==  1 ) { n           J[1][1] = i; n           J[1][2] = j; n         } else if (s[1] ==  2 ) { n           J[2][1] = i; n           J[2][2] = j; n         } n       } n       B[tonum(s[0]) * 4 + tonum(s[1])] = true; n     } n   size = n * m; n   for (int i = 1; i <= 52; i++) n     if (!B[i]) U[us++] = i; n   for (int i = 0; i < us; i++) n     for (int j = 0; j < us; j++) n       if (i != j) { n         rep1 = replacee(1, U[i]); n         rep2 = replacee(2, U[j]); n         if (check()) { n           cout <<  Solution exists.  << endl; n           if (!rep1 && !rep2) n             cout <<  There are no jokers.  << endl; n           else if (rep1 && rep2) n             cout <<  Replace J1 with   << print(U[i]) <<   and J2 with   n                  << print(U[j]) <<  .  << endl; n           else if (rep1) n             cout <<  Replace J1 with   << print(U[i]) <<  .  << endl; n           else if (rep2) n             cout <<  Replace J2 with   << print(U[j]) <<  .  << endl; n           cout <<  Put the first square to (  << r1 <<  ,   << c1 <<  ).  n                << endl; n           cout <<  Put the second square to (  << r2 <<  ,   << c2 <<  ).  n                << endl; n           return 0; n         } n       } n   cout <<  No solution.  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, n; n   int x; n   cin >> t; n   while (t--) { n     cin >> n; n     map<int, int> m; n     for (int i = 0; i < n; i++) { n       cin >> x; n       m[x] = 1; n     } n     cout << m.size() << endl; n   } n } n


#include <bits/stdc++.h> n int comp(const void *a, const void *b) { return *(int *)a - *(int *)b; } n int min(int a, int b) { return a < b ? a : b; } n int max(int a, int b) { return a > b ? a : b; } n int rev(int n) { n   int r = 0; n   for (int i = 0; i < 8; i++) r = r | (((n >> i) & 1) << (7 - i)); n   return r; n } n char c; n int n; n int main() { n   int p = 0, t; n   while (1) { n     scanf( %c , &c); n     if (c < 32 || c > 126) break; n     t = (256 + rev(p) - rev(c)) % 256; n     p = c; n     printf( %d n , t); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double EPS = 1e-9; n const long long int mod = 1e9 + 7; n long long int pow(long long int x, long long int y) { n   long long int sum = 1; n   for (long long int i = 0; i < y; ++i) { n     sum *= x; n     sum %= mod; n   } n   return sum; n } n int main(void) { n   long long int k, p; n   cin >> p >> k; n   if (k == 0) { n     cout << pow(p, p - 1) << endl; n     return 0; n   } n   if (k == 1) { n     cout << pow(p, p) << endl; n     return 0; n   } n   int o = 1; n   long long int prod = k; n   while (prod != 1) { n     prod *= k; n     prod %= p; n     o++; n   } n   assert((p - 1) % o == 0); n   cout << pow(p, (p - 1) / o) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   long long sum1 = 0, sum2 = 0; n   vector<long long> one, two; n   int last = 0; n   for (int i = 0; i < n; i++) { n     int temp; n     scanf( %d , &temp); n     if (temp < 0) { n       two.push_back(abs(temp)); n       sum2 += abs(temp); n       last = 2; n     } else { n       one.push_back(temp); n       sum1 += temp; n       last = 1; n     } n   } n   if (sum1 != sum2) { n     if (sum1 > sum2) n       puts( first ); n     else n       puts( second ); n     return 0; n   } n   for (int i = 0; i < min(one.size(), two.size()); i++) { n     if (one[i] != two[i]) { n       if (one[i] < two[i]) n         puts( second ); n       else if (one[i] > two[i]) n         puts( first ); n       return 0; n     } n   } n   if (one.size() != two.size()) { n     if (one.size() > two.size()) n       puts( first ); n     else n       puts( second ); n     return 0; n   } n   if (last == 1) n     puts( first ); n   else n     puts( second ); n } n


#include <bits/stdc++.h> n using namespace std; n const int MXN = 300300; n int n, a[MXN], match[MXN], cnt[MXN]; n map<int, int> prevMatch[MXN]; n int main() { n   int T; n   scanf( %d , &T); n   for (int t = 1; t <= T; ++t) { n     scanf( %d , &n); n     for (int i = 1; i <= n; ++i) { n       scanf( %d , &a[i]); n       match[i] = cnt[i] = 0; n       prevMatch[i].clear(); n     } n     for (int i = 2; i <= n; ++i) { n       if (a[i] == a[i - 1]) { n         match[i] = i - 1; n       } else { n         match[i] = max(0, prevMatch[i - 1][a[i]]); n       } n       if (match[i] > 1) { n         swap(prevMatch[i], prevMatch[match[i] - 1]); n         prevMatch[i][a[match[i] - 1]] = match[i] - 1; n       } n     } n     long long res = 0; n     for (int i = 2; i <= n; ++i) { n       if (match[i] == 0) continue; n       cnt[i] = cnt[match[i] - 1] + 1; n       res += cnt[i]; n     } n     cout << res <<   n ; n   } n   fclose(stdin); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 998244353; n long long power(long long x, long long y) { n   long long z = 1; n   while (y > 0) { n     if (y % 2) z = z * x; n     x = x * x; n     y /= 2; n   } n   return z; n } n long long gcd(long long a, long long b) { n   if (a < b) return gcd(b, a); n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long min(long long a, long long b) { n   if (a < b) return a; n   return b; n } n long long max(long long a, long long b) { n   if (a > b) return a; n   return b; n } n void solve() { n   string s; n   cin >> s; n   vector<long long> v; n   long long n = s.size(), cnt = 0; n   for (long long i = 0; i < n; i++) { n     if (s[i] ==  1 ) v.push_back(i); n   } n   if (v.empty()) { n     cout << 0 << endl; n     return; n   } n   for (long long i = v[0]; i < v[v.size() - 1]; i++) { n     if (s[i] ==  0 ) cnt++; n   } n   cout << cnt << endl; n } n int main() { n   long long t; n   cin >> t; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n inline int lb(int a) { return a & (-a); } n long long a[100100], bit[7][15][100100]; n int n, m, t; n inline void adj(int z, int zm, int pos, long long val) { n   for (int i = pos; i <= n; i += lb(i)) bit[z][zm][i] += val; n } n inline long long qry(int z, int zm, int pos) { n   if (pos <= 0) return 0; n   long long rt = 0; n   for (int i = pos; i > 0; i -= lb(i)) rt += bit[z][zm][i]; n   return rt; n } n inline long long sum(int z, int zm, int l, int r) { n   int z2 = z * 2 - 2; n   int lb = l + zm - 1, rb = r; n   if (lb > r) return 0; n   while (rb % z2 != lb % z2) rb--; n   lb -= z2; n   if (rb < l) return 0; n   return qry(z, rb % z2, rb) - qry(z, lb % z2, lb); n } n inline int s(int z, int i) { n   int mod = i % (2 * z - 2); n   if (mod == 0) n     return 2; n   else if (mod <= z) n     return mod; n   else n     return 2 * z - mod; n } n inline void update(int p, int v) { n   for (int z = 2; z <= 6; z++) { n     int z2 = z * 2 - 2; n     adj(z, p % z2, p, v - a[p]); n   } n   a[p] = v; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     int in; n     scanf( %d , &in); n     update(i, in); n   } n   scanf( %d , &m); n   while (m-- > 0) { n     scanf( %d , &t); n     if (t == 1) { n       int p, v; n       scanf( %d%d , &p, &v); n       update(p, v); n     } else { n       int l, r, z; n       scanf( %d%d%d , &l, &r, &z); n       long long ans = 0; n       int z2 = z * 2 - 2; n       for (int i = 1; i <= z2; i++) { n         ans += s(z, i) * sum(z, i, l, r); n       } n       printf( %I64d n , ans); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n const long long MAX = 1e6 + 5; n bool cmp(const pair<long long, long long> &a, n          const pair<long long, long long> &b) { n   if (a.first < b.first) n     return true; n   else if (a.first == b.first) { n     if (b.second > a.second) return true; n     return false; n   } n   return false; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long tc = 1, i, j; n   while (tc--) { n     long long n; n     cin >> n; n     long long a, b, c, d, e, f; n     cin >> a >> b >> c; n     cin >> d >> e >> f; n     long long mi, ma; n     mi = max(0LL, max(c - f - e, max(b - d - e, a - d - f))); n     ma = min(a, e) + min(b, f) + min(c, d); n     cout << mi <<     << ma <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n int n, fa[200005][2], sz[200005][2]; n long long ans; n int find(int x, int c) { n   return fa[x][c] == x ? x : (fa[x][c] = find(fa[x][c], c)); n } n void merge(int x, int y, int c) { n   x = find(x, c), y = find(y, c); n   if (x == y) return; n   fa[y][c] = fa[x][c], sz[x][c] += sz[y][c]; n } n int main() { n   scanf( %d , &n); n   for (register int i = 1; i <= n; ++i) n     fa[i][0] = fa[i][1] = i, sz[i][0] = sz[i][1] = 1; n   for (register int i = 1, u, v, w; i < n; ++i) n     scanf( %d%d%d , &u, &v, &w), merge(u, v, w); n   for (register int i = 1; i <= n; ++i) n     ans += 1ll * sz[find(i, 0)][0] * sz[find(i, 1)][1] - 1; n   printf( %lld , ans); n } n


#include <bits/stdc++.h> n using namespace std; n double dot(complex<double> a, complex<double> b) { n   return (conj(a) * b).real(); n } n double cross(complex<double> a, complex<double> b) { n   return (conj(a) * b).imag(); n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long double x, y, minangle = 600; n   int n, s, e; n   cin >> n; n   vector<pair<long double, int>> v; n   for (int i = 1; i <= n; i++) { n     cin >> x >> y; n     v.push_back({atan2(x, y) * 180.0 / 3.14159265359, i}); n     while (v.back().first < 0) v.back().first += 360.0; n     while (v.back().first > 360.0) v.back().first -= 360.0; n   } n   sort(v.begin(), v.end()); n   for (int i = 0; i < v.size(); i++) { n     if (min(abs(v[i].first - v[(i + 1) % n].first), n             360.0 - abs(v[i].first - v[(i + 1) % n].first)) - n             minangle <= n         -1e-20) { n       minangle = min(abs(v[i].first - v[(i + 1) % n].first), n                      360.0 - abs(v[i].first - v[(i + 1) % n].first)); n       s = v[i].second; n       e = v[(i + 1) % n].second; n     } n   } n   cout << s <<     << e; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const signed long long Infinity = 1000000001; n const long double Epsilon = 1e-9; n template <typename T, typename U> n ostream& operator<<(ostream& os, const pair<T, U>& p) { n   return os <<  (  << p.first <<  ,  << p.second <<  ) ; n } n template <typename T> n ostream& operator<<(ostream& os, const vector<T>& V) { n   os <<  [ ; n   for (__typeof(V.begin()) i = V.begin(); i != V.end(); ++i) n     os << *i << (i - V.begin() + 1 == ((int)V.size()) ?    :  , ); n   os <<  ] n ; n   return os; n } n template <typename T> n ostream& operator<<(ostream& os, const set<T>& S) { n   os <<  ( ; n   for (__typeof(S.begin()) i = S.begin(); i != S.end(); ++i) n     os << *i << (*i == *S.rbegin() ?    :  , ); n   os <<  ) n ; n   return os; n } n template <typename T, typename U> n ostream& operator<<(ostream& os, const map<T, U>& M) { n   os <<  { ; n   for (__typeof(M.begin()) i = M.begin(); i != M.end(); ++i) n     os << *i << (i->first == M.rbegin()->first ?    :  , ); n   os <<  } n ; n   return os; n } n int N, K; n void read_data() { scanf( %d %d , &N, &K); } n void solve() { n   if (N == K) { n     printf( -1 n ); n   } else { n     for (int(i) = (1); (i) <= (N - K - 1); (i)++) printf( %d  , i + 1); n     printf( 1  ); n     for (int(i) = (N - K + 1); (i) <= (N); (i)++) printf( %d  , i); n   } n } n int main() { n   read_data(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N; n char S[500050]; n int Aint[4 * 500050]; n int pa, pb, pv; n long long A[500050]; n void update(int k, int st, int dr) { n   if (pa <= st && dr <= pb) { n     Aint[k] += pv; n     return; n   } n   int m = (st + dr) / 2; n   if (pa <= m) { n     update(2 * k, st, m); n   } n   if (pb > m) { n     update(2 * k + 1, m + 1, dr); n   } n } n void goUpdates(int p) { n   int a = p + 1; n   int b = N - p; n   if (a > b) { n     swap(a, b); n   } n   pa = 1; n   pb = a; n   pv = 1; n   update(1, 1, N); n   if (b + 1 <= N) { n     pa = b + 1; n     pb = N; n     pv = -1; n     update(1, 1, N); n   } n } n void go(int k, int st, int dr, long long sum) { n   sum += Aint[k]; n   if (st == dr) { n     A[st] = sum; n     return; n   } n   int m = (st + dr) / 2; n   go(2 * k, st, m, sum); n   go(2 * k + 1, m + 1, dr, sum); n } n int main() { n   cin.sync_with_stdio(false); n   fgets(S, sizeof(S), stdin); n   N = 0; n   for (int i = 0; S[i] !=   n  && S[i] !=   0 ; i++, N++) n     ; n   for (int i = 0; i < N; i++) { n     if (S[i] ==  I  || S[i] ==  E  || S[i] ==  A  || S[i] ==  O  || n         S[i] ==  U  || S[i] ==  Y ) { n       goUpdates(i); n     } n   } n   go(1, 1, N, 0); n   double ans = 0.0; n   for (int i = 1; i <= N; i++) { n     A[i] += A[i - 1]; n     ans += (double)A[i] / i; n   } n   cout << fixed << setprecision(10) << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 300009; n map<short, int> f[maxn]; n int a[maxn], n, K, p, q, d; n int sum[maxn], i, j, k; n int main() { n   scanf( %d%d , &n, &K); n   d = n / K; n   for (i = 1; i <= n; i++) scanf( %d , &a[i]); n   sort(a + 1, a + n + 1); n   for (i = 2; i <= n; i++) sum[i] = sum[i - 1] + a[i] - a[i - 1]; n   f[0][0] = 0; n   for (i = 1; i <= n; i++) { n     for (k = 0; k <= 1; k++) { n       if (i >= d) n         for (map<short, int>::iterator j = f[i - d].begin(); n              j != f[i - d].end(); j++) n           if (j->first + k <= n % K) { n             if (!f[i].count(j->first + k)) n               f[i][j->first + k] = j->second + sum[i] - sum[i - d + 1]; n             else n               f[i][j->first + k] = n                   min(f[i][j->first + k], j->second + sum[i] - sum[i - d + 1]); n           } n       d++; n     } n     if (i >= d) f[i - d].clear(); n     d -= 2; n   } n   printf( %d , f[n][n % K]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long abs(long long, long long); n double dis(long long x1, long long y1, long long x2, long long y2) { n   double d = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); n   d = sqrt(d * 1.0); n   return d; n } n void solve() { n   long long w, h; n   cin >> w >> h; n   long long u1, d1, u2, d2; n   cin >> u1 >> d1 >> u2 >> d2; n   long long a = w; n   for (long long i = h; i > 0; i--) { n     a += i; n     if (i == d1) { n       a -= u1; n       if (a < 0) a = 0; n     } n     if (i == d2) { n       a -= u2; n       if (a < 0) a = 0; n     } n   } n   cout << a; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long TESTS = 1; n   while (TESTS--) { n     solve(); n   } n   return 0; n } n long long abs(long long a, long long b) { n   if (a > b) n     return a - b; n   else n     return b - a; 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   long long n, x, t, m, y, z, k; n   cin >> t; n   while (t--) { n     cin >> n >> m; n     vector<vector<long long> > a(n, vector<long long>(m)); n     string s; n     for (int i = 0; i < n; i++) { n       cin >> s; n       for (int j = 0; j < m; j++) { n         a[i][j] = s[j] -  0 ; n       } n     } n     vector<vector<long long> > ans; n     auto f = [&](int i, int j) { a[i][j] ^= 1; }; n     for (int i = 0; i < n - 2; i++) { n       for (int j = 0; j < m - 1; j++) { n         if (a[i][j]) { n           ans.push_back({i, j, i + 1, j, i, j + 1}); n           f(i, j); n           f(i + 1, j); n           f(i, j + 1); n         } n       } n       if (a[i][m - 1]) { n         ans.push_back({i, m - 1, i + 1, m - 1, i + 1, m - 2}); n         f(i, m - 1); n         f(i + 1, m - 1); n         f(i + 1, m - 2); n       } n     } n     for (int j = 0; j < m - 2; j++) { n       if (a[n - 2][j] && a[n - 1][j]) { n         ans.push_back({n - 2, j, n - 1, j, n - 2, j + 1}); n         f(n - 2, j); n         f(n - 1, j); n         f(n - 2, j + 1); n       } else if (a[n - 2][j]) { n         ans.push_back({n - 2, j, n - 1, j + 1, n - 2, j + 1}); n         f(n - 2, j); n         f(n - 1, j + 1); n         f(n - 2, j + 1); n       } else if (a[n - 1][j]) { n         ans.push_back({n - 1, j, n - 1, j + 1, n - 2, j + 1}); n         f(n - 1, j); n         f(n - 1, j + 1); n         f(n - 2, j + 1); n       } n     } n     for (int k = 0; k < 4; k++) { n       vector<long long> move; n       auto choose = [&](pair<long long, long long> o) { n         move.push_back(o.first); n         move.push_back(o.second); n         a[o.first][o.second] ^= 1; n       }; n       vector<pair<long long, long long> > b, g; n       for (int i = n - 2; i < n; i++) { n         for (int j = m - 2; j < m; j++) { n           if (a[i][j]) n             b.push_back({i, j}); n           else n             g.push_back({i, j}); n         } n       } n       if (b.size() == 0) break; n       if (b.size() == 4) { n         choose(b[0]); n         choose(b[1]); n         choose(b[2]); n       } else if (b.size() == 1) { n         choose(b[0]); n         choose(g[0]); n         choose(g[1]); n       } else if (b.size() == 2) { n         choose(b[0]); n         choose(g[0]); n         choose(g[1]); n       } else if (b.size() == 3) { n         choose(b[0]); n         choose(b[1]); n         choose(b[2]); n       } n       ans.push_back(move); n     } n     cout << ans.size() <<   n ; n     for (auto &it : ans) { n       for (int j : it) { n         cout << j + 1 <<    ; n       } n       cout <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   long long n, d, m, l, i, le, ri, step; n   while (~scanf( %I64d%I64d%I64d%I64d , &n, &d, &m, &l)) { n     for (i = 0; i < n; i++) { n       le = i * m + l; n       ri = (i + 1) * m; n       step = (le + d) / d; n       if (step * d < ri) break; n     } n     printf( %I64d n , step * d); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, x[1000009], y[1000009], id[1000009]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d %d , x + i, y + i), id[i] = i; n   sort(id + 1, id + 1 + n, [](int a, int b) { n     if (x[a] / 1000 != x[b] / 1000) return x[a] / 1000 < x[b] / 1000; n     if (x[a] / 1000 % 2) return y[a] > y[b]; n     return y[a] < y[b]; n   }); n   for (int i = 1; i <= n; i++) printf( %d  , id[i]); n } n


#include <bits/stdc++.h> n using namespace std; n int q, n; n long long k; n long long len[100004]; n string s1 =  What are you doing while sending  , n        s2 =  ? Are you busy? Will you send  , s3 =  ? , n        f0 = n             What are you doing at the end of the world? Are you busy? Will you   n             save us? ; n int ge; n void pre() { n   s1 +=    ; n   s2 =     + s2 +    ; n   s3 =     + s3; n   len[0] = 75; n   for (int i = 1; i <= 100000; i++) { n     len[i] = len[i - 1] * 2 + 33 + 30 + 1 + 1 + 2 + 1; n     if (len[i] > 1000000000000000000LL) { n       ge = i; n       return; n     } n   } n } n int dfs(int x) { n   if (x <= ge && k > len[x]) return printf( . ); n   if (!x) return printf( %c , f0[k - 1]); n   if (k <= 34) return printf( %c , s1[k - 1]), 0; n   k -= 34; n   if (x > ge || k <= len[x - 1]) return dfs(x - 1); n   k -= len[x - 1]; n   if (k <= 32) return printf( %c , s2[k - 1]), 0; n   k -= 32; n   if (k <= len[x - 1]) return dfs(x - 1); n   k -= len[x - 1]; n   return printf( %c , s3[k - 1]); n } n int main() { n   scanf( %d , &q); n   pre(); n   while (q--) { n     scanf( %d%I64d , &n, &k); n     dfs(n); n   } n   return 0; n } n


#include <bits/stdc++.h> n using uint64 = unsigned long long; n const int N = 100, seed = 65537; n char s[N]; n std::unordered_map<uint64, int> words; n std::unordered_set<uint64> mark; n int dfs(int d, uint64 hs) { n   if (s[d] == 0) { n     if (mark.count(hs)) return 0; n     mark.insert(hs); n     auto it = words.find(hs); n     if (it == words.end()) n       return 0; n     else n       return it->second; n   } n   int ret = 0; n   if (s[d] ==  ? ) { n     ret += dfs(d + 1, hs); n     for (char c =  a ; c <=  e ; ++c) { n       ret += dfs(d + 1, hs * seed + c); n     } n   } else { n     ret += dfs(d + 1, hs * seed + s[d]); n   } n   return ret; n } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; ++i) { n     scanf( %s , s); n     uint64 hs = 0; n     for (int j = 0; s[j]; ++j) { n       hs = hs * seed + s[j]; n     } n     words[hs] += 1; n   } n   for (int i = 0; i < m; ++i) { n     scanf( %s , s); n     mark.clear(); n     printf( %d n , dfs(0, 0)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dq[4040]; n int st = 0; n int dr = 0; n int m[3030][3030]; n int mn[3030][3030]; n int N, M, K, L, X, Y, Z; n long long ret = 0; n void make() { n   for (int i = 1; i <= N; ++i) { n     int ind = 0; n     st = dr = 0; n     for (int j = 1; j <= M; ++j) { n       while (dr - st > 0 && m[i][dq[dr - 1]] > m[i][j]) { n         --dr; n       } n       dq[dr++] = j; n       while (dq[st] <= j - L) { n         ++st; n       } n       if (j - L >= 0) { n         mn[i][j - L + 1] = m[i][dq[st]]; n       } n     } n   } n   for (int j = 1; j <= M - L + 1; ++j) { n     st = dr = 0; n     for (int i = 1; i <= N; ++i) { n       while (dr - st > 0 && mn[dq[dr - 1]][j] > mn[i][j]) --dr; n       dq[dr++] = i; n       while (dq[st] <= i - K) ++st; n       if (i - K >= 0) { n         ret += mn[dq[st]][j]; n       } n     } n   } n } n int G[3030 * 3030]; n int main() { n   cin.sync_with_stdio(false); n   cin >> N >> M >> K >> L; n   cin >> G[0] >> X >> Y >> Z; n   for (int i = 1; i <= N * M + 100; ++i) { n     G[i] = (1LL * G[i - 1] * X + Y) % Z; n   } n   for (int i = 1; i <= N; ++i) { n     for (int j = 1; j <= M; ++j) { n       m[i][j] = G[(i - 1) * M + j - 1]; n     } n   } n   make(); n   cout << ret << endl; n } n


#include <bits/stdc++.h> n const double pi = acos(-1); n const int MOD = 1e9 + 7; n const int INF = 1e9 + 7; n const int MAXN = 1e6 + 5; n const double eps = 1e-9; n using namespace std; n int main() { n   for (int i = 0; i < 9; i++) printf( %d ? ?<>%d n , i, i + 1); n   printf( 9 ? ?>> ? ?0 n ? ?<>1 n ); n   for (int i = 0; i <= 9; i++) printf(  ?%d>>%d ? n , i, i); n   printf(  ?>> ? ? n>> ? n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long w, m, k; n long long comp; n long long getpre(long long a) { n   long long tmp = 1, ct = 0; n   while (a >= tmp) tmp *= 10, ++ct; n   tmp /= 10; n   long long t = 1; n   long long ans = 0; n   for (long long i = 1; i < ct; ++i) ans += i * 9 * t, t *= 10; n   ans += (a - tmp + 1) * ct; n   return ans; n } n bool judge(long long len) { n   long long tl = m - 1; n   long long tr = m + len - 1; n   if (getpre(tr) - getpre(tl) <= comp) return true; n   return false; n } n int main() { n   cin >> w >> m >> k; n   long long l = 0, r = w / k + 1, ans = 0; n   comp = r - 1; n   while (l <= r) { n     long long mid = (l + r) >> 1; n     if (judge(mid)) n       l = mid + 1, ans = mid; n     else n       r = mid - 1; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   int t; n   cin >> t; n   while (t--) { n     long long n, k; n     cin >> n >> k; n     long long a[n]; n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n     } n     if (k % 2 == 0) n       k = 2; n     else n       k = 1; n     while (k--) { n       long long m = -10000000000; n       for (int i = 0; i < n; i++) { n         m = max(m, a[i]); n       } n       for (int i = 0; i < n; i++) { n         a[i] = m - a[i]; n       } n     } n     for (int i = 0; i < n; i++) cout << a[i] <<    ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long f[500005]; n int main() { n   string s; n   cin >> s; n   for (int i = 1; i <= s.size(); i++) n     f[i] = (s[i - 1] ==  I  || s[i - 1] ==  O  || s[i - 1] ==  E  || n             s[i - 1] ==  A  || s[i - 1] ==  U  || s[i - 1] ==  Y ); n   for (int i = 1; i <= s.size(); i++) f[i] = f[i - 1] + f[i]; n   long long cur = 0; n   long double ans = 0; n   for (int i = 1; i <= s.size(); i++) n     cur += (f[s.size() - i + 1] - f[i - 1]), n         ans += (long double)cur / (long double)i; n   printf( %.10Lf , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   long long t; n   cin >> n >> t; n   vector<long long> a, b; n   for (long long i = 0; i < n; i++) { n     long long x; n     cin >> x; n     x += t; n     a.push_back(x); n   } n   vector<int> breaks; n   bool poss = true; n   long long cur = 0; n   for (long long i = 1; i <= n; i++) { n     long long x; n     cin >> x; n     b.push_back(x); n     if (x < i) poss = false; n     if (x < cur) poss = false; n     if (x != cur && i != (cur + 1)) poss = false; n     if (x != cur) { n       breaks.push_back(1); n     } else { n       breaks.push_back(0); n     } n     cur = x; n   } n   for (int i = 1; i < n; i++) { n     if (breaks[i] && !breaks[i - 1] && a[i - 1] + 1 == a[i]) poss = false; n   } n   if (!poss) { n     cout <<  No  << endl; n     return 0; n   } n   cout <<  Yes  << endl; n   for (int i = 0; i < n; i++) { n     if (b[i] == n) { n       cout << a[n - 1] + i + 1 <<    ; n     } else { n       cout << a[b[i]] - (b[i] - i) <<    ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int n; n   cin >> n; n   long long int a[n + 1]; n   for (long long int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   long long int f = 0; n   for (long long int i = 1; i <= n; i++) { n     for (long long int j = 1; j <= n; j++) { n       if (j != i) { n         for (long long int k = 1; k <= n; k++) { n           if (k != j) { n             if (a[i] == a[j] + a[k]) { n               f = 1; n               cout << i <<     << j <<     << k << endl; n               break; n             } n           } n         } n         if (f) { n           break; n         } n       } n     } n     if (f) { n       break; n     } n   } n   if (f == 0) { n     cout << -1; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, j = 0; n   cin >> n; n   vector<int> ai(n); n   if (n == 4) { n     cout << 4 <<   n ; n     cout << 3 <<     << 1 <<     << 4 <<     << 2 <<   n ; n     return 0; n   } n   for (int i = 1; i <= n; i += 2) { n     ai[j] = i; n     j++; n   } n   for (int k = 2; k <= n; k += 2) { n     if (abs(ai[j - 1] - k) != 1) { n       ai[j] = k; n       j++; n     } n   } n   cout << j <<   n ; n   for (int i = 0; i < j; i++) cout << ai[i] <<    ; n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, k; n   cin >> n >> m >> k; n   if (m >= n && k >= n) { n     cout <<  Yes  << endl; n   } else n     cout <<  No  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, v[105], frec[105]; n vector<int> ans; n int main() { n   cin >> n >> k; n   for (int i = 1; i <= n; i++) cin >> v[i]; n   for (int i = 1; i <= n; i++) n     if (!frec[v[i]]) { n       frec[v[i]] = 1; n       ans.push_back(i); n       if (ans.size() == k) break; n     } n   if (ans.size() == k) { n     cout <<  YES  <<   n ; n     for (int i = 0; i < ans.size(); i++) cout << ans[i] <<    ; n     cout <<   n ; n   } else n     cout <<  NO  <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int lg = 22; n const long long int N = 2e5 + 5; n const long long int INF = 1e18; n const long long int mod = 1e9 + 7; n const double PI = 3.14159265358979323846; n template <typename T> n T power(T x, T y, long long int m) { n   T ans = 1; n   while (y > 0) { n     if (y & 1LL) ans = (ans * x) % m; n     y >>= 1LL; n     x = (x * x) % m; n   } n   return ans % m; n } n inline long long int mul(long long int a, long long int b, long long int p) { n   return (a * 1ll * b) % p; n } n inline long long int sub(long long int a, long long int b, long long int p) { n   long long int c = a - b; n   if (c < 0) c += p; n   return c; n } n inline long long int add(long long int a, long long int b, long long int p) { n   long long int c = a + b; n   if (c > p) c -= p; n   return c; n } n long long int mark[N]; n long long int n, q, a[N], minidx[N], maxidx[N]; n int main() { n   long long int ans = 0; n   cin >> n >> q; n   for (long long int i = 1; i <= n; i++) { n     cin >> a[i]; n     if (minidx[a[i]] == 0) { n       minidx[a[i]] = i; n     } n     maxidx[a[i]] = i; n   } n   for (long long int i = 1; i <= n; i++) { n     long long int maxcnt = 0, cnt = 0; n     long long int maxi = maxidx[a[i]]; n     if (mark[i]) { n       continue; n     } n     map<long long int, long long int> xfreq; n     for (long long int j = i; j <= maxi; j++) { n       cnt++; n       mark[j] = 1; n       xfreq[a[j]]++; n       maxcnt = max(maxcnt, xfreq[a[j]]); n       maxi = max(maxi, maxidx[a[j]]); n     } n     ans += (cnt - maxcnt); n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n vector<set<int> > A; n set<int>::iterator it; n int main() { n   int n, m, a; n   cin >> n; n   A.resize(n); n   int D[101]; n   for (int i = 1; i <= 100; ++i) D[i] = 0; n   for (int i = 0; i < n; ++i) { n     cin >> m; n     for (int j = 0; j < m; ++j) { n       cin >> a; n       ++D[a]; n       A[i].insert(a); n     } n   } n   for (int i = 0; i < n; ++i) { n     bool yes = 1; n     for (int j = 0; j < n; ++j) { n       if (i != j) { n         bool y = 0; n         for (it = A[j].begin(); it != A[j].end(); ++it) n           if (A[i].count(*it) == 0) y = 1; n         if (y == 0) yes = 0; n       } n     } n     if (yes) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n   } n } n


#include <bits/stdc++.h> n int main() { n   int n, a[1010], temp, lamak, maxin, max, i, j; n   long int count; n   while (scanf( %d , &n) != EOF) { n     count = 0; n     for (i = 0; i < n; i++) { n       scanf( %d , &a[i]); n     } n   again: n     max = 0; n     for (i = 0; i < n; i++) { n       if (a[i] >= max) { n         max = a[i]; n         maxin = i; n       } n     } n     if (max > a[0]) { n       a[maxin] = a[maxin] - 1; n       a[0] = a[0] + 1; n       count = count + 1; n       goto again; n     } n     if (max == a[0] && maxin != 0) { n       a[maxin] = a[maxin] - 1; n       a[0] = a[0] + 1; n       count = count + 1; n       printf( %ld n , count); n     } else { n       printf( %ld n , count); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   char s[1007][1007]; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       cin >> s[i][j]; n     } n   } n   if (n < 3) { n     cout <<  0 ; n   } else { n     int res = 0; n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= n; j++) { n         if (s[i][j] ==  X  && s[i - 1][j + 1] ==  X  && n             s[i + 1][j - 1] ==  X  && s[i - 1][j - 1] ==  X  && n             s[i + 1][j + 1] ==  X ) { n           res++; n         } n       } n     } n     cout << res; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma warning(disable : 4996) n #pragma comment(linker,  /STACK:336777216 ) n using namespace std; n int IT_MAX = 1 << 17; n const long long MOD = 1000000009; n const int INF = 0x3f3f3f3f; n const long long LL_INF = 0x3f3f3f3f3f3f3f3f; n const double PI = acos(-1); n const double ERR = 1e-8; n vector<pair<long long, long long> > Vu; n int main() { n   int N, K, M, i, j; n   scanf( %d %d %d , &N, &K, &M); n   for (i = 1; i <= N; i++) { n     int t; n     scanf( %d , &t); n     if (!Vu.empty() && Vu.back().first == t) { n       Vu.back().second++; n       if (Vu.back().second == K) Vu.pop_back(); n     } else n       Vu.emplace_back(t, 1); n   } n   long long s = 0; n   for (auto it : Vu) s += it.second; n   if (M == 1 || s == 0) return !printf( %lld n , s); n   s *= M; n   int st = 0, en = (int)Vu.size() - 1; n   while (st < en) { n     if (Vu[st].first != Vu[en].first) return !printf( %lld n , s); n     if (Vu[st].second + Vu[en].second == K) { n       s -= (long long)(M - 1) * K; n       st++, en--; n       continue; n     } n     if (Vu[st].second + Vu[en].second > K) s -= (long long)(M - 1) * K; n     return !printf( %lld n , s); n   } n   long long x = Vu[st].second * M; n   if (x % K == 0) { n     return !printf( 0 n ); n   } else { n     return !printf( %lld n , s - (x / K) * K); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MXN = 1e5 + 1; n const int MAXN = 1e3 + 1; n const long long INF = 1e16; n const int MOD = 65000; n const int MAX = 1e2; n const double EPS = 1e-9; n long long n; n long long a, b, c, d, e, first, g, h; n int main() { n   ios_base::sync_with_stdio(0); n   string second; n   cin >> second; n   for (int i = 0; i < second.size(); ++i) { n     if (second[i] ==  B ) ++a; n     if (second[i] ==  u ) ++b; n     if (second[i] ==  l ) ++c; n     if (second[i] ==  b ) ++d; n     if (second[i] ==  a ) ++e; n     if (second[i] ==  s ) ++first; n     if (second[i] ==  u ) ++g; n     if (second[i] ==  r ) ++h; n   } n   g = g / 2; n   e = e / 2; n   cout << min(a, min(b, min(c, min(d, min(e, min(first, min(g, h))))))); n   return 0; n } n


#include <iostream> n #include <vector> n #include <algorithm> n using namespace std; n  n int main() { n  int testCase; n   cin >> testCase; n  while (testCase--) { n   vector<int> balls; n   int ball; n   cin >> ball; n   while (ball--) { n    int num; n    cin >> num; n    balls.push_back(num); n   } n   int maxNum = 1; n   int lastNum = balls[0]; n   int count = 1; n   for (int i = 1;i < balls.size();i++) { n    if (balls[i] != lastNum) { n     lastNum = balls[i]; n     maxNum = max(count, maxNum); n     count = 1; n    } n    else { n     count++; n    } n   } n   maxNum = max(count, maxNum); n   cout << maxNum << endl; n  } n  return 0; n }


#include <bits/stdc++.h> n #define int long long n  n #pragma GCC target ( avx2 ) n #pragma GCC optimization ( O3 ) n #pragma GCC optimization ( unroll-loops ) n  n /*#include <ext/pb_ds/assoc_container.hpp> n #include <ext/pb_ds/tree_policy.hpp> n using namespace __gnu_pbds; n #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>*/ n  n using namespace std; n  n  n signed main() { n     //ios_base::sync_with_stdio(0); n     //cin.tie(0); n     //cout.tie(0); n     int n; n     cin >> n; n     int a[n]; n     for (int i = 0; i < n; ++i) cin >> a[i]; n     vector <pair <int, pair <int, int> > > goga; n     for (int i = 0; i < n; ++i) { n         for (int j = i + 1; j < n; ++j) { n             if (a[i] > a[j]) goga.push_back({a[i] - a[j], {i, j}}); n             else goga.push_back({a[j] - a[i], {j, i}}); n         } n     } n     sort(goga.begin(), goga.end()); n     reverse(goga.begin(), goga.end()); n     for (int i = 0; i < goga.size(); ++i) { n         if (goga[i].first >= 0 && i < goga.size()) { n         int first = goga[i].second.first, second = goga[i].second.second; n         cout <<  ?   << first + 1 <<     << second + 1 << endl; n         string lol; n         cin >> lol; n         if (lol ==  Yes ) { n             cout <<  !   << first + 1 <<     << second + 1 << endl; n             return 0; n         } n         } n     } n     cout <<  !   << 0 <<     << 0 << endl; n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1004; n int a[N]; n int main() { n   int n; n   scanf( %d , &n); n   vector<pair<int, int> > vec; n   int i; n   for (i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     vec.push_back(make_pair(a[i], i)); n   } n   sort(vec.begin(), vec.end()); n   reverse(vec.begin(), vec.end()); n   int ans = 0; n   for (i = 0; i < vec.size(); i++) { n     ans = ans + (i)*vec[i].first + 1; n   } n   printf( %d n , ans); n   for (i = 0; i < vec.size(); i++) printf( %d  , vec[i].second); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, ms, type[5005], dp[5005]; n int main() { n   scanf( %d %d , &n, &ms); n   for (int i = 1; i <= n; i++) { n     double x; n     scanf( %d %lf , type + i, &x); n   } n   for (int i = 1; i <= n; i++) { n     int j = type[i]; n     for (int k = j; k >= 1; k--) { n       dp[j] = max(dp[j], 1 + dp[k]); n     } n   } n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     ans = max(ans, dp[i]); n   } n   printf( %d n , n - ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   char s[105]; n   cin >> s; n   vector<int> a; n   string ans =   ; n   int j, ct = 0; n   for (int i = 0; i <= n - 1;) { n     if (s[i] ==  o  && s[i + 1] ==  g  && s[i + 2] ==  o  && i <= n - 3) { n       ct = 0; n       for (j = i + 3; j < n - 1;) { n         if (s[j] ==  g  && s[j + 1] ==  o ) { n           ct = 1; n           j = j + 2; n           i = j; n         } else { n           i = j; n           break; n         } n       } n       i = j; n       if (ct == 1) { n         ans +=  *** ; n       } else { n         ans +=  *** ; n       } n     } else { n       ans += s[i]; n       i++; n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int const N = 1e5 + 13; n int n, m; n set<int> e[N]; n set<pair<int, int> > q; n int p[N]; n int tin[N], cnt, w[N], ans; n int gcd(int a, int b) { return (!a ? b : gcd(b % a, a)); } n void init() { n   for (int i = 0; i < N; ++i) p[i] = i; n } n int find(int u) { n   if (p[u] == u) return u; n   return p[u] = find(p[u]); n } n void uni(int a, int b) { n   a = find(a); n   b = find(b); n   if (a == b) return; n   if (e[a].size() < e[b].size()) swap(a, b); n   for (int to : e[b]) e[a].insert(find(to)); n   p[b] = a; n   e[b].clear(); n } n void print(int ans) { n   printf( %d n , ans); n   exit(0); n } n pair<int, int> getMax() { n   auto it = q.end(); n   --it; n   pair<int, int> res = (*it); n   return res; n } n void merge(int id) { n   if (id != find(id)) return; n   vector<int> ver; n   for (int v : e[id]) ver.push_back(find(v)); n   e[id].clear(); n   for (int i = 0; i < ver.size(); ++i) { n     int pi = find(ver[i]); n     q.erase(make_pair(e[pi].size(), pi)); n   } n   for (int i = 1; i < ver.size(); ++i) uni(ver[i], ver[i - 1]); n   int lv = find(ver[0]); n   id = find(id); n   e[id].insert(lv); n   q.insert(make_pair(e[lv].size(), lv)); n   q.insert(make_pair(e[id].size(), id)); n   if (e[id].find(id) != e[id].end()) print(1); n } n void compress() { n   for (int i = 0; i < n; ++i) { n     q.insert(make_pair(e[i].size(), find(i))); n   } n   while (true) { n     pair<int, int> cur = getMax(); n     if (cur.first < 2) return; n     q.erase(cur); n     merge(cur.second); n   } n } n void dfs(int u) { n   w[u] = 1; n   tin[u] = cnt; n   ++cnt; n   for (int to : e[u]) { n     int vt = find(to); n     if (!w[vt]) n       dfs(vt); n     else if (w[vt] == 1) { n       ans = gcd(ans, tin[u] - tin[vt] + 1); n     } n   } n   w[u] = 2; n   --cnt; n } n void solve() { n   init(); n   scanf( %d %d , &n, &m); n   for (int i = 0; i < m; ++i) { n     int u, v; n     scanf( %d %d , &u, &v); n     --u; n     --v; n     if (u == v) print(1); n     e[u].insert(find(v)); n   } n   compress(); n   for (int i = 0; i < n; ++i) n     if (!w[find(i)]) dfs(find(i)); n   if (ans == 0) ans = n; n   printf( %d n , ans); n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int sum(int a[], int size) { n   int sum = 0; n   for (int i = 0; i < size; i++) { n     sum = sum + a[i]; n   } n   return sum; n } n int main() { n   int n; n   cin >> n; n   int a1[n], a2[n - 1], a3[n - 3]; n   for (int i = 0; i < n; i++) { n     cin >> a1[i]; n   } n   for (int i = 0; i < n - 1; i++) { n     cin >> a2[i]; n   } n   for (int i = 0; i < n - 2; i++) { n     cin >> a3[i]; n   } n   cout << sum(a1, n) - sum(a2, n - 1) << endl n        << sum(a2, n - 1) - sum(a3, n - 2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dir[8][2] = {{1, 0}, {-1, 0}, {0, 1},  {0, -1}, n                  {1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; n int main() { n   int n, k, p, x, y; n   int cntY = 0, a[1100] = {0}, sum = 0; n   scanf( %d %d %d %d %d , &n, &k, &p, &x, &y); n   for (int i = 1; i <= k; i++) { n     scanf( %d , &a[i]); n     sum += a[i]; n     if (a[i] >= y) cntY++; n   } n   int Mid = (n + 1) / 2; n   if (cntY >= Mid) { n     sum += (n - k); n     if (sum > x) n       printf( -1 n ); n     else { n       for (int i = 1; i <= (n - k); i++) printf( 1%c , i == n - k ?   n  :    ); n     } n   } else { n     sum += y * (Mid - cntY) + n - k - Mid + cntY; n     if (sum > x || k - cntY >= Mid) n       printf( -1 n ); n     else { n       for (int i = 1; i <= (Mid - cntY); i++) n         printf( %d%c , y, i == n - k ?   n  :    ); n       for (int i = 1; i <= n - k - Mid + cntY; i++) n         printf( 1%c , i == n - k - Mid + cntY ?   n  :    ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n const double PI = acos(-1); n const double EPS = 1e-6; n const long long MOD = 998244353; n const long long N = 30 + 10; n template <typename T> n inline T Abs(T x) { n   return x < 0 ? x * -1 : x; n } n template <typename T> n inline T Max(T x, T y, T z) { n   return std::max(std::max(x, y), z); n } n template <typename T> n inline T Min(T x, T y, T z) { n   return std::min(std::min(x, y), z); n } n template <typename T> n inline void Ckmax(T &x, T y) { n   x = std::max(x, y); n } n template <typename T> n inline void Ckmin(T &x, T y) { n   x = std::min(x, y); n } n template <typename T> n inline T Sqr(T x) { n   return x * x; n } n template <typename T> n inline T Pow(T x, T y) { n   T r = 1; n   while (y > 0) { n     if (y % 2 > 0) (r *= x) %= MOD; n     (x *= x) %= MOD; n     y /= 2; n   } n   return r % MOD; n } n template <typename T> n T Pow(T x, T y, T z) { n   T r = 1; n   while (y > 0) { n     if (y % 2 > 0) (r *= x) %= z; n     (x *= x) %= z; n     y /= 2; n   } n   return r % z; n } n template <typename T> n inline T gcd(T x, T y) { n   return y > 0 ? gcd(y, x % y) : x; n } n template <typename T> n inline T lcm(T x, T y) { n   return x / gcd(x, y) * y; n } n inline void cinspu(void) { n   std::ios::sync_with_stdio(0); n   std::cin.tie(0); n } n inline long long fac(long long x) { n   long long r = 1; n   for (; x > 1; --x) (r *= x) %= MOD; n   return r; n } n int a[N], b[N], ans[N], tim; n int print(char z, int x, int y) { n   ++tim; n   printf( %c %d %d n , z, x, y); n   fflush(stdout); n   if (z ==  ? ) { n     int r; n     scanf( %d , &r); n     return r; n   } n   return -2; n } n int main() { n   const char q =  ? ; n   for (int i = 29, x = 0, y = 0; i >= 0; --i) { n     int n = (1 << i), r; n     if (ans[i]) n       r = ans[i] - 3; n     else n       r = print(q, x, y); n     if (r > 0) { n       int p = print(q, x + n, y + n); n       if (p > 0) { n         int t = print(q, x + n, y); n         if (t > 0) { n           a[i] = b[i] = 0; n           ans[i - 1] = 3 + r; n         } else { n           a[i] = b[i] = 1; n           ans[i - 1] = 3 + p; n           x += n; n           y += n; n         } n       } else { n         a[i] = 1; n         b[i] = 0; n         x += n; n       } n     } else if (r < 0) { n       int p = print(q, x + n, y + n); n       if (p < 0) { n         int t = print(q, x + n, y); n         if (t > 0) { n           a[i] = b[i] = 0; n           ans[i - 1] = 3 + r; n         } else { n           a[i] = b[i] = 1; n           ans[i - 1] = 3 + p; n           x += n; n           y += n; n         } n       } else { n         a[i] = 0; n         b[i] = 1; n         y += n; n       } n     } else { n       r = print(q, x + n, y); n       if (r > 0) { n         a[i] = b[i] = 0; n       } else { n         a[i] = b[i] = 1; n         x += n; n         y += n; n       } n     } n   } n   int x = 0; n   for (int i = 0; i < 30; ++i) x += a[i] * (1 << i); n   int y = 0; n   for (int i = 0; i < 30; ++i) y += b[i] * (1 << i); n   print( ! , x, y); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   double a, b, c; n   cin >> a >> b >> c; n   cout << (int)ceil(c * (a - b) / b); n } n


#include <bits/stdc++.h> n inline int read() { n   int x = 0, w = 1; n   char ch = 0; n   while (ch <  0  || ch >  9 ) { n     ch = getchar(); n     if (ch ==  - ) w = -1; n   } n   while (ch <=  9  && ch >=  0 ) { n     x = (x << 1) + (x << 3) + ch -  0 ; n     ch = getchar(); n   } n   return x * w; n } n using namespace std; n const int N = 5005; n const int M = 2e6 + 5; n const int Mod = 1e9 + 7; n char str[M]; n int n, k1, k2, tot, tim, ans; n int s[N], bg[N], vis[N]; n int dfn[N], low[N], b[N]; n int mn[N], mx[N], cnt[N]; n int fac[M], inv[M]; n inline void ad(int &x, int y) { n   x += y; n   if (x >= Mod) x -= Mod; n   if (x < 0) x += Mod; n } n inline int Pow(int x, int y) { n   int res = 1; n   while (y) { n     if (y & 1) res = 1ll * res * x % Mod; n     x = 1ll * x * x % Mod; n     y >>= 1; n   } n   return res; n } n inline void math_init(int nn) { n   fac[0] = 1; n   for (int i = 1; i <= nn; ++i) fac[i] = 1ll * fac[i - 1] * i % Mod; n   inv[nn] = Pow(fac[nn], Mod - 2); n   for (int i = nn; i; --i) inv[i - 1] = 1ll * inv[i] * i % Mod; n } n inline int C(int x, int y) { n   if (x < y || x < 0 || y < 0) return 0; n   return 1ll * (1ll * fac[x] * inv[y] % Mod) * inv[x - y] % Mod; n } n vector<int> G[N], g[N], f[N]; n stack<int> sta; n int gcd(int x, int y) { n   if (!y) return x; n   return gcd(y, x % y); n } n inline void input() { n   n = read(), k1 = read(), k2 = read(); n   for (int i = 1; i <= n; ++i) { n     scanf( %s , str + 1); n     for (int j = 1; j <= n; ++j) n       if (str[j] ==  1 ) G[i].push_back(j); n   } n   for (int i = 1; i <= n; ++i) { n     s[i] = read(); n     scanf( %s , str + 1); n     for (int j = 1; j <= s[i]; ++j) { n       g[i].push_back(str[j] -  0 ); n       mn[i] += str[j] -  0 ; n     } n   } n } n void tarjan(int x) { n   dfn[x] = low[x] = ++tim; n   sta.push(x), vis[x] = 1; n   for (int i = 0, sz = G[x].size(); i < sz; ++i) { n     int y = G[x][i]; n     if (!dfn[y]) { n       tarjan(y); n       low[x] = min(low[x], low[y]); n     } else if (vis[y]) n       low[x] = min(low[x], dfn[y]); n   } n   if (low[x] == dfn[x]) { n     int now = 0; n     ++tot; n     do { n       now = sta.top(), sta.pop(), vis[now] = 0; n       b[now] = tot, bg[tot] = gcd(bg[tot], s[now]); n     } while (now != x); n   } n } n namespace sub1 { n inline void build() { n   for (int i = 1; i <= n; ++i) n     if (!dfn[i]) tarjan(i); n   for (int i = 1; i <= tot; ++i) f[i].resize(bg[i] + 1); n   for (int i = 1; i <= n; ++i) n     for (int j = 0; j < s[i]; ++j) f[b[i]][j % bg[b[i]]] |= g[i][j]; n } n inline void solve() { n   build(); n   for (int i = tot; i > 1; --i) { n     int now = gcd(bg[i], bg[i - 1]); n     for (int j = 0; j < bg[i]; ++j) { n       f[i - 1][j % now] |= f[i][j]; n       cnt[i] += f[i][j]; n     } n   } n   for (int i = 0; i < bg[1]; ++i) cnt[1] += f[1][i]; n   for (int i = 1; i <= n; ++i) mx[i] = 1ll * cnt[b[i]] * s[i] / bg[b[i]]; n } n }  // namespace sub1 n namespace sub2 { n inline void solve() { n   for (int i = 1; i <= n; ++i) { n     int cnt1 = 0, cnt2 = 0; n     for (int j = 1; j <= n; ++j) { n       if (i == j) continue; n       if (mn[j] > mx[i]) n         ++cnt1; n       else if (mx[j] > mx[i] || (mx[j] == mx[i] && j < i)) n         ++cnt2; n     } n     if (cnt1 > k1 - 1) continue; n     for (int j = min(k2, min(k1 - 1 - cnt1, cnt2)); j + cnt1 + 1 >= k2; --j) n       ad(ans, 1ll * C(cnt2, j) * C(cnt1, k2 - j - 1) % Mod); n   } n   printf( %d n , ans); n } n }  // namespace sub2 n int main() { n   math_init(M - 5), input(); n   sub1::solve(), sub2::solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   if (m == 3 && n > 4) { n     cout <<  -1  << endl; n     return 0; n   } n   int cnt = 0, ans = 0; n   for (int i = 0; i < m; i++) printf( %d %d n , i, ans += (cnt++)); n   if (m < n) cout << m + 100000 <<     << ans << endl; n   for (int i = m + 1; i < n; i++) printf( %d %d n , i + 100000, ans -= (--cnt)); n   return 0; n } n


#include <bits/stdc++.h> n const long long INF = 1e18; n void swap(long long &a, long long &b) { n   long long temp; n   temp = a; n   a = b; n   b = temp; n } n using namespace std; n void solve() { n   long long n, k, ans; n   cin >> n >> k; n   ans = n; n   for (long long i = 1; i <= sqrt(n); i++) { n     if (n % i == 0) { n       if (n / i <= k) ans = min(ans, i); n       if (i <= k) ans = min(ans, n / i); n     } n   } n   cout << ans; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     solve(); n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x; n   cin >> n >> x; n   int pos = 1; n   long long ans = 0; n   for (int i = 0; i < n; i++) { n     int l, r; n     cin >> l >> r; n     ans += 1LL * (l - pos) % x + (r - l + 1); n     pos = r + 1; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int strike[10010]; n bool isIn(long long x, long long y, long long cx, long long cr) { n   return (x - cx) * (x - cx) + y * y <= cr * cr; n } n int main() { n   int n, m; n   cin >> n; n   vector<pair<pair<long long, long long>, int> > mish(n + 2); n   for (int i = 1; i <= n; i++) n     cin >> mish[i].first.first >> mish[i].first.second, mish[i].second = i; n   n += 1; n   mish[0].first.first = -100000; n   mish[0].first.second = 0; n   mish[n].first.first = 100000; n   mish[n].first.second = 0; n   sort(mish.begin(), mish.end()); n   for (int i = 1; i <= n; i++) strike[i] = -1; n   cin >> m; n   for (int i = 1; i <= m; i++) { n     int x, y; n     cin >> x >> y; n     int l = 0, r = n; n     while (l < r) { n       int s = (l + r) / 2 + 1; n       if (x < mish[s].first.first) n         r = s - 1; n       else n         l = s; n     } n     if (strike[mish[l].second] == -1 && n         isIn(x, y, mish[l].first.first, mish[l].first.second)) n       strike[mish[l].second] = i; n     if (strike[mish[l + 1].second] == -1 && n         isIn(x, y, mish[l + 1].first.first, mish[l + 1].first.second)) n       strike[mish[l + 1].second] = i; n   } n   int c = 0; n   for (int i = 1; i < n; i++) n     if (strike[i] != -1) c++; n   cout << c << endl; n   for (int i = 1; i < n; i++) cout << strike[i] <<    ; n exit: n   return (0); n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 2000000000; n const int N = 300005; n int p[N], sum[N], dp[N]; n vector<int> g[N]; n bool cmp(int q, int w) { return (sum[q] > sum[w]); } n void dfs(int v, int pr = 0) { n   p[v] = pr; n   sum[v] = 1; n   if (pr && g[v].size() == 1) { n     dp[v] = v; n     return; n   } n   vector<int> a; n   for (int i = 0; i < g[v].size(); i++) { n     int to = g[v][i]; n     if (to == pr) continue; n     dfs(to, v); n     a.push_back(to); n     sum[v] += sum[to]; n   } n   sort((a).begin(), (a).end(), cmp); n   int n = a.size(); n   int first = dp[a[0]]; n   while (sum[v] - sum[first] > sum[v] / 2) { n     first = p[first]; n   } n   dp[v] = first; n } n int main() { n   cin.tie(0); n   ios_base::sync_with_stdio(0); n   int n, m; n   cin >> n >> m; n   for (int i = 2; i <= n; i++) { n     int first; n     cin >> first; n     g[i].push_back(first); n     g[first].push_back(i); n   } n   dfs(1); n   for (int i = 1; i <= m; i++) { n     int first; n     cin >> first; n     cout << dp[first] <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long mn = (long long)(1e9); n long long n, ans, k, a[311111], near[2111111], x; n bool mark[2111111]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> k; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     mark[a[i]] = 1; n     mn = min(mn, a[i]); n   } n   for (int i = 1; i <= 2000000; i++) { n     near[i] = x; n     if (mark[i]) x = i; n   } n   for (int i = mn; i >= 1; i--) { n     long long mx = -(long long)(1e9); n     for (int j = 0; j <= 1000000; j += i) { n       if (near[j + i] >= j) mx = max(mx, near[j + i] - j); n     } n     if (mx != -(long long)(1e9) && mx <= k) { n       cout << i; n       return 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e18; n const long long mod = 1e9 + 7; n unsigned long long power(long long x, unsigned long long y, long long p) { n   long long res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n bool isPrime(long long n) { n   if (n <= 1) return false; n   if (n <= 3) return true; n   if (n % 2 == 0 || n % 3 == 0) return false; n   for (long long i = 5; i * i <= n; i = i + 6) n     if (n % i == 0 || n % (i + 2) == 0) return false; n   return true; n } n const long long maxn = 3000 * 3000; n long long g[maxn]; n deque<pair<long long, long long>> d; n long long mat[3001][3001]; n long long mn[3001][3001]; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long n, m, a, b, x, y, z; n   cin >> n >> m >> a >> b; n   cin >> g[0] >> x >> y >> z; n   for (long long i = 1; i < n * m + 1; i++) { n     g[i] = (g[i - 1] * x + y) % z; n   } n   for (long long i = 1; i < n + 1; i++) { n     for (long long j = 1; j < m + 1; j++) { n       mat[i][j] = g[(i - 1) * m + j - 1]; n     } n   } n   for (long long i = 1; i < n + 1; i++) { n     d.clear(); n     for (long long j = 1; j < m + 1; j++) { n       while (d.size() && d.back().first > mat[i][j]) { n         d.pop_back(); n       } n       d.push_back({mat[i][j], j}); n       if (j >= b) { n         mn[i][j] = d.front().first; n         if (j - d.front().second >= b - 1) { n           d.pop_front(); n         } n       } n     } n   } n   d.clear(); n   for (long long j = b; j < m + 1; j++) { n     d.clear(); n     for (long long i = 1; i < n + 1; i++) { n       while (d.size() && d.back().first > mn[i][j]) { n         d.pop_back(); n       } n       d.push_back({mn[i][j], i}); n       if (i >= a) { n         mat[i][j] = d.front().first; n         if (i - d.front().second >= a - 1) { n           d.pop_front(); n         } n       } n     } n   } n   long long ans = 0; n   for (long long i = a; i < n + 1; i++) { n     for (long long j = b; j < m + 1; j++) { n       ans += mat[i][j]; n     } n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n int main() { n   std::ios_base::sync_with_stdio(0); n   std::cout.tie(0); n   std::cin.tie(0); n   int n; n   std::cin >> n; n   int a[n]; n   for (int i = 0; i < n; ++i) std::cin >> a[i]; n   std::sort(a, a + n); n   for (int i = n - 1; i >= 0; --i) { n     int t = sqrt(a[i]); n     if (t * t != a[i]) { n       std::cout << a[i] <<   n ; n       return 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int x, y, z, inf = 1e9, f[210][210], n, m, Max[210]; n pair<pair<int, int>, int> p[40010]; n pair<int, int> q[210]; n void read(int &x) { n   char ch = getchar(); n   int mark = 1; n   for (; ch !=  -  && (ch <  0  || ch >  9 ); ch = getchar()) n     ; n   if (ch ==  - ) mark = -1, ch = getchar(); n   for (x = 0; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch - 48; n   x *= mark; n } n int main() { n   read(n); n   read(m); n   for (int i = 1; i <= n; i++) n     for (int j = i + 1; j <= n; j++) f[i][j] = f[j][i] = inf; n   for (int i = 1; i <= m; i++) { n     read(x); n     read(y); n     read(z); n     f[x][y] = f[y][x] = z; n     p[i] = make_pair(make_pair(x, y), z); n   } n   for (int k = 1; k <= n; k++) n     for (int i = 1; i <= n; i++) n       if (i != k) n         for (int j = 1; j <= n; j++) n           if (j != i && j != k) f[i][j] = min(f[i][j], f[i][k] + f[k][j]); n   double Min = 1e9; n   for (int i = 1; i <= n; i++) { n     double Max = 0; n     for (int j = 1; j <= n; j++) Max = max(Max, (double)f[i][j]); n     Min = min(Min, Max); n   } n   for (int i = 1; i <= m; i++) { n     int x = p[i].first.first, y = p[i].first.second; n     for (int j = 1; j <= n; j++) q[j] = make_pair(f[x][j], f[y][j]); n     sort(q + 1, q + n + 1); n     Max[n + 1] = 0; n     for (int j = n; j; j--) Max[j] = max(Max[j + 1], q[j].second); n     for (int j = 1; j <= n; j++) { n       int l = q[j].first, r = Max[j + 1]; n       if (l > r) swap(l, r); n       if (l + p[i].second >= r) Min = min(Min, (l + p[i].second + r) / 2.0); n     } n   } n   printf( %.1lf n , Min); 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   int n; n   cin >> n; n   vector<int> a(n); n   for (int i = 0; i < n; ++i) cin >> a[i]; n   multiset<int> s; n   for (int v : a) s.insert(v); n   int ans = 0; n   for (int i = 0; i < n; ++i) { n     auto it = s.upper_bound(a[i]); n     if (it != s.end()) { n       ++ans; n       s.erase(it); n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[100010]; n int main() { n   long long n, k; n   cin >> n >> k; n   for (int i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   long long x = a[0], ans = 0; n   for (int i = 1; i < n; i++) { n     if ((a[i] - x) % k != 0) { n       cout << -1 << endl; n       return 0; n     } n     ans += (a[i] - x) / k; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve(); n int main() { n   ios::sync_with_stdio(0); n   solve(); n   return 0; n } n int a[1000001]; n void solve() { n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; ++i) { n     int v; n     cin >> v; n     a[v]++; n   } n   for (int i = 0; i < m; ++i) { n     int v; n     cin >> v; n     a[v]--; n   } n   int ans = 0; n   int j = 0; n   for (int i = 1; i <= 1000000; ++i) { n     if (a[i] > 0) { n       j = max(j, i); n       bool f = 0; n       while (j <= 1000000 && !f) { n         if (a[j] < 0) { n           a[j]++; n           f = 1; n         } else n           j++; n       } n       ans += !f; n     } n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n char s[100000]; n int col[100000], dp[21][1 << 20]; n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   for (int i = 0; i < n; i++) { n     scanf(  %s , s); n     for (int j = 0; j < m; j++) col[j] |= (s[j] -  0 ) << i; n   } n   for (int i = 0; i < m; i++) dp[0][col[i]]++; n   for (int k = 1; k <= n; k++) n     for (int mask = 0; mask < (1 << n); mask++) { n       int sum = k > 1 ? (k - 2 - n) * dp[k - 2][mask] : 0; n       for (int p = 0; p < n; p++) sum += dp[k - 1][mask ^ (1 << p)]; n       dp[k][mask] = sum / k; n     } n   int ans = n * m; n   for (int mask = 0; mask < (1 << n); mask++) { n     int cnt = 0; n     for (int k = 0; k <= n; k++) cnt += min(k, n - k) * dp[k][mask]; n     ans = min(ans, cnt); n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e11; n const int M = 1e5 + 5; n vector<pair<long long, int> > adj[M]; n vector<int> ans; n long long d[M], vis[M], pre[M]; n int n, m; n void Dijkstra() { n   for (int i = 1; i <= n; ++i) d[i] = INF; n   d[1] = 0; n   priority_queue<pair<long long, int> > q; n   q.push(make_pair(d[1], 1)); n   while (!q.empty()) { n     int u = q.top().second; n     q.pop(); n     if (vis[u]) continue; n     vis[u] = 1; n     for (int i = 0; i < adj[u].size(); ++i) { n       int v = adj[u][i].second; n       long long dist = adj[u][i].first + d[u]; n       if (d[v] > dist) { n         d[v] = dist; n         pre[v] = u; n         q.push(make_pair(-d[v], v)); n       } n     } n   } n } n int main() { n   int u, v, w; n   cin >> n >> m; n   while (m--) { n     cin >> u >> v >> w; n     adj[u].push_back(make_pair(w, v)); n     adj[v].push_back(make_pair(w, u)); n   } n   Dijkstra(); n   if (d[n] == INF) n     cout <<  -1  << endl; n   else { n     for (int i = n; pre[i]; i = pre[i]) ans.push_back(pre[i]); n     for (int i = ans.size() - 1; i >= 0; --i) cout << ans[i] <<    ; n     cout << n <<    ; n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, x; n   cin >> n; n   vector<long long> a; n   for (int i = 0; i < n; i++) { n     cin >> x; n     a.push_back(x); n   } n   for (int i = 0; i < n - 1; i++) { n     cout << a[i] + a[i + 1] <<    ; n   } n   cout << a[n - 1] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void read(T &x) { n   x = 0; n   char c = getchar(); n   int f = 0; n   for (; !isdigit(c); c = getchar()) f |= c ==  - ; n   for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^  0 ); n   if (f) x = -x; n } n template <typename T> n void write(T x, char ed =   n ) { n   static short st[30]; n   short tp = 0; n   if (x < 0) putchar( - ), x = -x; n   do st[++tp] = x % 10, x /= 10; n   while (x); n   while (tp) putchar(st[tp--] |  0 ); n   putchar(ed); n } n const int N = 505000; n struct node { n   long long d; n   int id; n   bool operator<(const node &i) const { return id < i.id; } n   node(long long D = 0, int I = 0) : d(D), id(I) {} n }; n vector<vector<node> > vec; n vector<node> ety; n int ne[N << 1], to[N << 1], h[N], f[N], rt, tot, n; n inline void add(int x, int y) { ne[++tot] = h[x], to[h[x] = tot] = y; } n int dep[N], L[N], R[N], cnt; n int son[N], mxd[N], rev[N]; n long long ans[N]; n void dfs1(int x, int fa) { n   mxd[x] = dep[x] = dep[fa] + 1, L[x] = ++cnt, rev[cnt] = x; n   if (dep[x] >= vec.size()) vec.push_back(ety); n   vec[dep[x]].push_back(node(0, L[x])); n   for (int i = h[x]; i; i = ne[i]) { n     int y = to[i]; n     dfs1(to[i], x); n     if (mxd[y] >= mxd[x]) son[x] = y, mxd[x] = mxd[y]; n   } n   R[x] = cnt; n } n inline bool inc(int x, int l, int r) { return R[x] >= r && L[x] <= l; } n long long tab[N], t[N]; n void dfs2(int x) { n   int ct = 0, nw = dep[x]; n   long long res = 0; n   t[dep[x]]++; n   auto pl = lower_bound(vec[dep[x]].begin(), vec[dep[x]].end(), node(0, L[x])), n        pr = pl; n   ++pr; n   while ( jzpakioi , true) { n     res += 1ll * (ct += t[nw]) * (pr - pl) + tab[nw]; n     tab[nw] = t[nw] = 0, pl->d += res; n     if (pr != vec[nw].end()) pr->d -= res; n     if (++nw > mxd[x]) break; n     pl = lower_bound(vec[nw].begin(), vec[nw].end(), node(0, L[x])); n     pr = upper_bound(vec[nw].begin(), vec[nw].end(), node(0, R[x])); n     if (inc(son[x], pl->id, (pr - 1)->id)) { n       t[nw] += ct, tab[nw] += res; n       break; n     } n   } n   if (son[x]) dfs2(son[x]); n   for (int i = h[x]; i; i = ne[i]) n     if (to[i] != son[x]) dfs2(to[i]); n } n int main() { n   read(n), vec.push_back(ety); n   for (int i = 1; i <= n; i++) read(f[i]), f[i] ? add(f[i], i), 0 : rt = i; n   dfs1(rt, 0), dfs2(rt); n   for (int i = 1; i <= mxd[rt]; i++) { n     long long res = 0; n     for (auto t : vec[i]) res += t.d, ans[rev[t.id]] += res; n   } n   for (int i = 1; i <= n; i++) write(ans[i] - dep[i],    ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n int dx[8] = {1, -1, 0, 0, -1, -1, 1, 1}; n int dy[8] = {0, 0, -1, 1, -1, 1, -1, 1}; n vector<int> adj[300010], val(300010, 1), vis(300010, 0), dis1(300010, 0), n     dis2(300010, 0); n int myrandom(int i) { return std::rand() % i; } n int dp[5010]; n int n; n set<pair<int, int>> st; n int maxi = 0; n int poss[5010][5010]; n void dfs(int a) { n   vis[a] = 1; n   int cnt = 0; n   vector<int> v; n   for (auto i : adj[a]) { n     if (vis[i] == 0) { n       dfs(i); n       if (dp[i] > 0) { n         v.push_back(dp[i]); n       } n       cnt = cnt + dp[i]; n     } n   } n   int cnt1 = n - cnt - 1; n   if (cnt1 > 0) { n     v.push_back(cnt1); n   } n   int n = (int)v.size(); n   int sum = accumulate((v).begin(), (v).end(), 0); n   int res[sum + 1]; n   memset(res, 0, sizeof(res)); n   res[0] = 1; n   for (int i = 0; i < n; i++) { n     for (int j = sum; j >= 0; j--) { n       if (j - v[i] >= 0) { n         res[j] = res[j] | res[j - v[i]]; n       } n     } n   } n   maxi = max(maxi, sum); n   for (int i = 1; i < sum; i++) { n     poss[i][sum - i] = poss[i][sum - i] | res[i]; n   } n   dp[a] = 1 + cnt; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n; n   for (int i = 0; i < n - 1; i++) { n     int a, b; n     cin >> a >> b; n     adj[a].push_back(b); n     adj[b].push_back(a); n   } n   memset(poss, 0, sizeof(poss)); n   dfs(1); n   vector<pair<int, int>> ans; n   for (int i = 1; i <= 5000; i++) { n     for (int j = 1; j <= 5000; j++) { n       if (i + j == maxi && poss[i][j] == 1) { n         ans.push_back({i, j}); n       } n     } n   } n   cout << (int)ans.size() <<   n ; n   for (auto i : ans) { n     cout << i.first <<     << i.second <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct st { n   int t, p, g; n   char s[30]; n } a[100]; n int x[3]; n int y[6]; n int main() { n   int n, m, i, j, k; n   scanf( %d , &n); n   for (i = 0; i < n; i++) { n     scanf( %d%s , &m, a[i].s); n     for (j = 0; j < m; j++) { n       scanf( %d-%d-%d , &x[0], &x[1], &x[2]); n       for (k = 0; k < 3; k++) { n         y[k * 2] = x[k] / 10; n         y[k * 2 + 1] = x[k] % 10; n       } n       for (k = 0; k < 5; k++) n         if (y[k] != y[k + 1]) break; n       if (k == 5) { n         a[i].t++; n         continue; n       } n       for (k = 0; k < 5; k++) n         if (y[k] <= y[k + 1]) break; n       if (k == 5) n         a[i].p++; n       else n         a[i].g++; n     } n   } n   vector<int> ans; n   int ma = a[0].t; n   ans.push_back(0); n   for (i = 1; i < n; i++) { n     if (a[i].t > ma) { n       ans.clear(); n       ans.push_back(i); n       ma = a[i].t; n     } else if (a[i].t == ma) { n       ans.push_back(i); n     } n   } n   printf( If you want to call a taxi, you should call:  ); n   printf( %s , a[ans[0]].s); n   for (i = 1; i < ans.size(); i++) printf( , %s , a[ans[i]].s); n   printf( . n ); n   ans.clear(); n   ma = a[0].p; n   ans.push_back(0); n   for (i = 1; i < n; i++) { n     if (a[i].p > ma) { n       ans.clear(); n       ans.push_back(i); n       ma = a[i].p; n     } else if (a[i].p == ma) { n       ans.push_back(i); n     } n   } n   printf( If you want to order a pizza, you should call:  ); n   printf( %s , a[ans[0]].s); n   for (i = 1; i < ans.size(); i++) printf( , %s , a[ans[i]].s); n   printf( . n ); n   ans.clear(); n   ma = a[0].g; n   ans.push_back(0); n   for (i = 1; i < n; i++) { n     if (a[i].g > ma) { n       ans.clear(); n       ans.push_back(i); n       ma = a[i].g; n     } else if (a[i].g == ma) { n       ans.push_back(i); n     } n   } n   printf( n        If you want to go to a cafe with a wonderful girl, you should call:  ); n   printf( %s , a[ans[0]].s); n   for (i = 1; i < ans.size(); i++) printf( , %s , a[ans[i]].s); n   printf( . n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   long long n, x, sum(0), cnt(0), prev(INT_MAX); n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> x; n     if (i && x == prev) n       cnt++; n     else n       cnt = 1; n     prev = x; n     sum += cnt; n   } n   cout << sum; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<pair<int, int>, bool> mp; n bool check(int x, int y, int z) { n   if (y < x) swap(x, y); n   if (z < y) swap(z, y); n   if (y < x) swap(x, y); n   if (x + y > z && z > y && mp.count({x, y}) == 0) { n     mp[{x, y}] = 1; n     return 1; n   } else n     return 0; n } n int main() { n   int n; n   cin >> n; n   long long ans = 0; n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= n; ++j) { n       if ((i ^ j) <= n && check(i, j, (i ^ j))) ans++; n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   int n; n   while (t--) { n     int n; n     string s; n     cin >> n; n     cin >> s; n     int flag = 1, start = 0, end = n - 1; n     while (start <= end) { n       char ssp = s[start] + 1; n       char sep = s[end] + 1; n       char sem = s[end] - 1; n       char ssm = s[start] - 1; n       if ((ssp == sep) || (ssp == sem) || (ssm == sep) || (ssm == sem)) n         flag = 1; n       else { n         flag = 0; n         break; n       } n       start++; n       end--; n     } n     if (flag == 0) n       cout <<  NO  << endl; n     else n       cout <<  YES  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int arr[111]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = (0); i < (n); ++i) scanf( %d , &arr[i]); n   sort(arr, arr + n); n   int t = 10; n   int ans = 0; n   int qts = 0; n   for (int i = (0); i < (n); ++i) { n     t += arr[i]; n     if (t > 720) break; n     qts++; n     if (t > 360) ans += (t - 360); n   } n   printf( %d %d n , qts, ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int h, m, ti; n   scanf( %d:%d , &h, &m); n   scanf( %d , &ti); n   int realh = ti / 60, realmin = ti % 60; n   while (realh--) { n     if (h == 23) n       h = 0; n     else n       h++; n   } n   while (realmin--) { n     if (m == 59) { n       m = 0; n       if (h == 23) n         h = 0; n       else n         h++; n     } else n       m++; n   } n   if (h < 10) printf( 0 ); n   printf( %d: , h); n   if (m < 10) printf( 0 ); n   printf( %d , m); n   return 0; n } n


#include <bits/stdc++.h> n using i64 = long long; n template <typename _Tp> n inline void chkMax(_Tp &x, const _Tp &y) { n   (x < y) and (x = y); n } n namespace IOManager { n constexpr int FILESZ = 131072; n char buf[FILESZ]; n const char *ibuf = buf, *tbuf = buf; n struct IOManager { n   inline char gc() { n     return (ibuf == tbuf) and n                    (tbuf = (ibuf = buf) + fread(buf, 1, FILESZ, stdin), n                     ibuf == tbuf) n                ? EOF n                : *ibuf++; n   } n   template <typename _Tp> n   inline operator _Tp() { n     _Tp s = 0u; n     char c = gc(); n     for (; c < 48; c = gc()) n       ; n     for (; c > 47; c = gc()) s = (_Tp)(s * 10u + c - 48u); n     return s; n   } n }; n }  // namespace IOManager n IOManager::IOManager io; n int main() { n   static std::map<i64, i64> f; n   const int n = io; n   for (int i = 1; i <= n; ++i) { n     const i64 a = io; n     if (i == 1) f[a - 1] = 0; n     for (auto it = f.rbegin(); it not_eq f.rend() and it->first >= a; ++it) { n       const i64 v = it->first; n       chkMax(f[v % a], it->second + (v - v % a) * (i - 1ll)); n       chkMax(f[a - 1], it->second + ((v - a + 1ll) / a * a) * (i - 1ll)); n     } n     f.erase(f.lower_bound(a), f.end()); n   } n   i64 ans = 0; n   for (const auto it : f) chkMax(ans, it.second + it.first * n); n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[200005]; n long long k1[200005]; n long long k2[200005]; n string ss =  first ; n string sp =  second ; n int main() { n   int n; n   cin >> n; n   int r1 = 0; n   int r2 = 0; n   long long s1 = 0; n   long long s2 = 0; n   int l1 = 0; n   int l2 = 0; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i] > 0) { n       { k1[l1++] = a[i]; } n       s1 += a[i]; n       r1 = 1; n     } else { n       { k2[l2++] = -a[i]; } n       s2 += -a[i]; n       r1 = 0; n     } n   } n   if (s1 > s2) { n     cout << ss << endl; n     return 0; n   } n   if (s1 < s2) { n     cout << sp << endl; n     return 0; n   } n   if (s1 == s2) { n     for (int i = 0; i < min(l1, l2); i++) { n       if (k1[i] > k2[i]) { n         cout << ss << endl; n         return 0; n       } n       if (k2[i] > k1[i]) { n         cout << sp << endl; n         return 0; n       } n     } n     if (!r1) { n       cout << sp << endl; n       return 0; n     } else { n       cout << ss << endl; n       return 0; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int input() { n   int res = 0, m = 1; n   char c =    ; n   while (c <  0  && c !=  - ) c = getchar(); n   if (c ==  - ) m = -1, c = getchar(); n   while (c >=  0 ) res = res * 10 + (c -  0 ), c = getchar(); n   return res * m; n } n const int N = 501; n int n, k, lft[N], l_siz, fl[N], rht[N], r_siz, fr[N]; n void shift() { n   while (r_siz) lft[l_siz] = rht[--r_siz], ++l_siz; n   if (l_siz) fl[0] = lft[0]; n   for (int i = 1; i < l_siz; ++i) fl[i] = max(fl[i - 1], lft[i]); n } n void push(int x) { n   int prev = (r_siz ? fr[r_siz - 1] : 0); n   rht[r_siz] = x, fr[r_siz] = max(prev, x), ++r_siz; n } n void pop() { n   if (!l_siz) shift(); n   --l_siz; n } n int get() { n   int res = 0; n   if (l_siz) res = fl[l_siz - 1]; n   if (r_siz) res = max(res, fr[r_siz - 1]); n   return res; n } n int a[N][N], mx[N][N], ans = 2e9; n int main() { n   int n = input(), m = input(), k = input(); n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < m; ++j) a[i][j] = 2e9; n   for (int q = input(); q; --q) { n     int i = input() - 1, j = input() - 1, t = input(); n     a[i][j] = t; n   } n   for (int j = 0; j < m; ++j) { n     for (int i = 0; i < k; ++i) push(a[i][j]); n     mx[0][j] = get(); n     for (int i = 0; i < n - k; ++i) { n       pop(), push(a[i + k][j]); n       mx[i + 1][j] = get(); n     } n     while (l_siz + r_siz) pop(); n   } n   for (int i = 0; i <= n - k; ++i) { n     for (int j = 0; j < k; ++j) push(mx[i][j]); n     ans = min(ans, get()); n     for (int j = 0; j < m - k; ++j) { n       pop(), push(mx[i][j + k]); n       ans = min(ans, get()); n     } n     while (l_siz + r_siz) pop(); n   } n   cout << (ans == 2e9 ? -1 : ans); n } n


#include <bits/stdc++.h> n int main() { n   int t, a, b, c, d, k, i, pen, pencil; n   scanf( %d , &t); n   for (i = 0; i < t; i++) { n     scanf( %d %d %d %d %d , &a, &b, &c, &d, &k); n     if (a % c != 0) { n       pen = (a / c) + 1; n     } n     if (a % c == 0) { n       pen = (a / c); n     } n     if (b % d != 0) { n       pencil = (b / d) + 1; n     } n     if (b % d == 0) { n       pencil = (b / d); n     } n     if (pen + pencil <= k) { n       printf( %d %d n , pen, pencil); n     } else { n       printf( -1 n ); n     } n   } n   return 0; n } n