#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int x = 0, f = 1; n   char c = getchar(); n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) f = -1; n   for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ; n   return x * f; n } n const long long MAXN = 500010; n const long long Mod = 1000000007LL; n struct data { n   long long x, y; n   inline void ModT() { x %= Mod, y %= Mod; } n } a[MAXN + 1], pre[MAXN + 1]; n inline data md(long long x, long long y) { n   data xxx; n   xxx.x = x, xxx.y = y; n   return xxx; n } n inline long long operator*(const data &a, const data &b) { n   return a.x * b.y - b.x * a.y; n } n inline data operator+(const data &a, const data &b) { n   return md(a.x + b.x, a.y + b.y); n } n inline data operator-(const data &a, const data &b) { n   return md(a.x - b.x, a.y - b.y); n } n long long N, tmp, Sum0[MAXN + 1], Sum1[MAXN + 1], ans; n int main() { n   N = read(); n   for (long long i = 1; i <= N; i++) { n     long long x = read(), y = read(); n     a[i] = md(x, y); n     pre[i] = pre[i - 1] + a[i], pre[i].ModT(); n   } n   for (int i = 2; i <= N; i++) { n     tmp = a[i - 1] * a[i]; n     Sum0[i] = Sum0[i - 1] + tmp; n     Sum1[i] = (Sum1[i - 1] + Sum0[i]) % Mod; n   } n   long long Now = abs(Sum0[N + 1] = Sum0[N] + a[N] * a[1]); n   long long j = 1; n   for (long long i = 3; i <= N; i++) { n     for (; j < i - 1 && abs(Sum0[i] - Sum0[j] + a[i] * a[j]) > Now / 2.0; ++j) n       ; n     ans = (ans + Sum0[i] % Mod * (i - 1 - j) - (Sum1[i - 2] - Sum1[j - 1]) + n            a[i] * (pre[i - 2] - pre[j - 1])) % n           Mod; n     ans = (ans + Sum1[j - 1] + pre[j - 1] * a[i] + n            (Sum0[N + 1] - Sum0[i]) % Mod * (j - 1)) % n           Mod; n   } n   ans = ((Now % Mod * (Mod + 1 >> 2) % Mod * N % Mod * (N - 3) % Mod + ans) % n              Mod + n          Mod) * n         2LL % Mod; n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 Rand(time(0)); n const int maxn = 5e2 + 5; n const long long maxc = 1e9 + 7; n int n, m; n vector<int> adj[maxn]; n int d[maxn][maxn]; n pair<int, int> trace[maxn][maxn]; n vector<int> resOne, resN; n void bfs() { n   queue<pair<int, int> > q; n   q.push(make_pair(1, n)); n   memset(d, (-1), sizeof(d)); n   d[1][n] = 0; n   while (!q.empty()) { n     int s = q.front().first; n     int t = q.front().second; n     q.pop(); n     for (auto u : adj[s]) { n       for (auto v : adj[t]) { n         if (d[u][v] != -1 || u == v) continue; n         trace[u][v] = make_pair(s, t); n         d[u][v] = d[s][t] + 1; n         q.push(make_pair(u, v)); n       } n     } n   } n   cout << d[n][1] <<   n ; n   if (d[n][1] == -1) return; n   int s = 1, t = n; n   while (t != 0) { n     resOne.push_back(t); n     resN.push_back(s); n     pair<int, int> cur = trace[t][s]; n     t = cur.first, s = cur.second; n   } n   reverse((resOne).begin(), (resOne).end()); n   reverse((resN).begin(), (resN).end()); n   for (auto u : resOne) cout << u <<    ; n   cout <<   n ; n   for (auto u : resN) cout << u <<    ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   while (m--) { n     int u, v; n     cin >> u >> v; n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   bfs(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200 + 5; n const int LEN = 1e6 + 10; n int n, m, q; n int a[N]; n int b[N]; n int f[N][N]; n char ch[LEN]; n int g[LEN], l; n int xt[N * N], yt[N * N]; n int dp[N][N]; n int cnt, cir[N * N][10]; n int lc[N * N]; n int c0[N][N]; n int bel[N][N]; n int nx[N][N], ny[N][N]; n int rd[N][N]; n int v[N][N], cc; n int pre[N][N]; n bool check(int x, int y) { n   if (x <= 0 || y <= 0 || x >= n + 1 || y >= m + 1) n     return false; n   else n     return true; n } n void dfs_1(int x, int y) { n   v[x][y] = cc; n   int x0 = nx[x][y], y0 = ny[x][y]; n   if (v[x0][y0] > 0) { n     if (v[x0][y0] == cc) c0[x0][y0] = ++cnt; n     return; n   } n   dfs_1(x0, y0); n } n void dfs_2(int x, int y, int k) { n   v[x][y] = k; n   bel[x][y] = k; n   cir[k][f[x][y]] = true; n   int x0 = nx[x][y], y0 = ny[x][y]; n   if (v[x0][y0] > 0) return; n   dfs_2(x0, y0, k); n } n void init() { n   cin >> n >> m >> q; n   memset(v, 0, sizeof(v)); n   for (int i = 1; i <= n; i++) { n     scanf( %s , ch); n     for (int j = 1; j <= m; j++) f[i][j] = ch[j - 1] -  0 ; n   } n   for (int i = 0; i < 10; i++) scanf( %d %d , &a[i], &b[i]); n   cnt = 0; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       nx[i][j] = i + a[f[i][j]]; n       ny[i][j] = j + b[f[i][j]]; n       if (!check(nx[i][j], ny[i][j])) { n         nx[i][j] = i; n         ny[i][j] = j; n         bel[i][j] = ++cnt; n         v[i][j] = cnt; n         cir[cnt][f[i][j]] = true; n       } n       rd[nx[i][j]][ny[i][j]]++; n     } n   cc = cnt; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       if (v[i][j] == 0) { n         cc++; n         dfs_1(i, j); n       } n   memset(v, 0, sizeof(v)); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       if (c0[i][j] > 0) { n         dfs_2(i, j, c0[i][j]); n       } n } n bool bfs() { n   int L, R, x1, y1, x2, y2; n   L = 1, R = 0; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       if (rd[i][j] == 0) { n         R++; n         xt[R] = i, yt[R] = j; n         pre[i][j] = 0; n       } else n         pre[i][j] = rd[i][j]; n   while (L <= R) { n     x1 = xt[L], y1 = yt[L]; n     x2 = nx[x1][y1], y2 = ny[x1][y1]; n     if (dp[x1][y1] >= l) return true; n     if (g[dp[x1][y1] + 1] == f[x1][y1]) dp[x1][y1]++; n     dp[x2][y2] = max(dp[x1][y1], dp[x2][y2]); n     pre[x2][y2]--; n     if (pre[x2][y2] == 0) { n       R++; n       xt[R] = x2, yt[R] = y2; n     } n     if (bel[x2][y2] != 0) { n       if (lc[bel[x2][y2]] <= dp[x2][y2]) return true; n     } n     L++; n   } n   return false; n } n void work() { n   bool sign; n   for (int i = 1; i <= q; i++) { n     scanf( %s , ch); n     l = strlen(ch); n     memset(dp, 0, sizeof(dp)); n     for (int j = 1; j <= l; j++) g[j] = ch[j - 1] -  0 ; n     sign = false; n     for (int j = 1; j <= cnt; j++) { n       lc[j] = l; n       while (cir[j][g[lc[j]]] && lc[j] != 0) lc[j]--; n       if (lc[j] == 0) { n         sign = true; n         break; n       } n     } n     if (sign) { n       cout <<  YES  << endl; n       continue; n     } n     if (bfs()) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n   } n } n int main() { n   init(); n   work(); n   return 0; n } n


#include <bits/stdc++.h> n int b[1010]; n double dp[1010][1010]; n int main() { n   int n, m, i, j, x, y; n   double ans = 0; n   scanf( %d%d , &n, &m); n   for (i = 0; i < n; i++) scanf( %d , &b[i]); n   for (i = 0; i < n; i++) { n     for (j = 0; j < n; j++) { n       if (b[i] > b[j]) n         dp[i][j] = 1; n       else n         dp[i][j] = 0; n     } n   } n   while (m--) { n     scanf( %d%d , &x, &y); n     x--; n     y--; n     dp[x][y] = dp[y][x] = 0.5; n     for (i = 0; i < n; i++) { n       if (x == i || y == i) continue; n       dp[x][i] = (dp[x][i] + dp[y][i]) * 0.5; n       dp[y][i] = dp[x][i]; n       dp[i][x] = 1 - dp[x][i]; n       dp[i][y] = dp[i][x]; n     } n   } n   for (i = 0; i < n; i++) { n     for (j = i + 1; j < n; j++) { n       ans += dp[i][j]; n     } n   } n   printf( %.10f n , ans); n   return 0; n } n


#include <bits/stdc++.h> n int m, n, s; n int main() { n   scanf( %d%d , &n, &m); n   int ans = 0; n   for (int i = 0; i <= 40; i++) n     for (int j = 0; j <= 40; j++) { n       if (i * i + j == n && j * j + i == m) ans++; n     } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 300005; n int n; n long long x1, x2; n struct sss { n   long long val; n   int num; n } a[maxn]; n bool cmp(const sss &a, const sss &b) { return a.val > b.val; } n void scanff() { n   scanf( %d%I64d%I64d , &n, &x1, &x2); n   for (int i = 1; i <= n; i++) { n     scanf( %I64d , &a[i].val); n     a[i].num = i; n   } n   sort(a + 1, a + n + 1, cmp); n } n void work() { n   int now1, now2; n   bool flag = false; n   if (x1 < x2) { n     swap(x1, x2); n     flag = true; n   } n   for (now1 = 1; now1 <= n; now1++) { n     if (a[now1].val * now1 >= x1) break; n   } n   if (now1 > n) { n     printf( No n ); n     return; n   } n   for (now2 = now1 + 1; now2 <= n; now2++) { n     if (a[now2].val * (now2 - now1) >= x2) break; n   } n   if (now2 > n) { n     int head = 1, tail = now1; n     for (;;) { n       if (tail + 1 <= n) { n         if (a[tail + 1].val * (tail - head + 1) >= x1) { n           tail++; n           head++; n           if (a[head - 1].val * (head - 1) >= x2) { n             printf( Yes n ); n             if (!flag) { n               printf( %d %d n , tail - head + 1, head - 1); n               for (int i = head; i <= tail; i++) { n                 printf( %d  , a[i].num); n               } n               printf(  n ); n               for (int i = 1; i <= head - 1; i++) { n                 printf( %d  , a[i].num); n               } n               return; n             } else { n               printf( %d %d n , head - 1, tail - head + 1); n               for (int i = 1; i <= head - 1; i++) { n                 printf( %d  , a[i].num); n               } n               printf(  n ); n               for (int i = head; i <= tail; i++) { n                 printf( %d  , a[i].num); n               } n               return; n             } n           } n         } else { n           tail++; n         } n       } else n         break; n     } n     printf( No n ); n     return; n   } n   printf( Yes n ); n   if (!flag) { n     printf( %d %d n , now1, now2 - now1); n     for (int i = 1; i <= now1; i++) { n       printf( %d  , a[i].num); n     } n     printf(  n ); n     for (int i = now1 + 1; i <= now2; i++) { n       printf( %d  , a[i].num); n     } n   } else { n     printf( %d %d n , now2 - now1, now1); n     for (int i = now1 + 1; i <= now2; i++) { n       printf( %d  , a[i].num); n     } n     printf(  n ); n     for (int i = 1; i <= now1; i++) { n       printf( %d  , a[i].num); n     } n   } n } n int main() { n   scanff(); n   work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct state { n   int i, j, dp, cp; n }; n int di[] = {0, 1, 0, -1}; n int dj[] = {1, 0, -1, 0}; n state n[50][50][4][2]; n state current; n char b[50][51]; n int r, c; n int moves; n void read() { n   cin >> r >> moves; n   for (int i = 0; i < r; i++) { n     cin >> b[i]; n   } n   c = strlen(b[0]); n } n void write() { cout << b[current.i][current.j] <<   n ; } n inline bool valid(int i, int j) { n   return i > -1 && i < r && j > -1 && j < c && b[i][j] !=  0 ; n } n void preprocess(int i, int j, int dp, int cp) { n   int ni = i, nj = j; n   while (valid(ni, nj) && b[ni][nj] == b[i][j]) { n     ni += di[dp]; n     nj += dj[dp]; n   } n   ni -= di[dp]; n   nj -= dj[dp]; n   int p = (dp + (cp ? +1 : -1) + 4) % 4; n   while (valid(ni, nj) && b[ni][nj] == b[i][j]) { n     ni += di[p]; n     nj += dj[p]; n   } n   ni -= di[p]; n   nj -= dj[p]; n   ni += di[dp]; n   nj += dj[dp]; n   if (valid(ni, nj)) { n     n[i][j][dp][cp].i = ni; n     n[i][j][dp][cp].j = nj; n     n[i][j][dp][cp].dp = dp; n     n[i][j][dp][cp].cp = cp; n   } else { n     n[i][j][dp][cp].i = i; n     n[i][j][dp][cp].j = j; n     n[i][j][dp][cp].dp = !cp ? dp : (dp + 1) % 4; n     n[i][j][dp][cp].cp = !cp; n   } n } n void preprocess() { n   for (int i = 0; i < r; i++) { n     for (int j = 0; j < c; j++) { n       for (int dp = 0; dp < 4; dp++) { n         for (int cp = 0; cp < 2; cp++) { n           preprocess(i, j, dp, cp); n         } n       } n     } n   } n } n void move() { n   for (int i = 0; i < moves; i++) { n     current = n[current.i][current.j][current.dp][current.cp]; n   } n } n int main() { n   current.i = current.j = current.dp = current.cp = 0; n   read(); n   preprocess(); n   move(); n   write(); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize  Ofast,omit-frame-pointer,inline  n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n, m; n   cin >> n >> m; n   int mx = -INT_MAX; n   multiset<int> vs; n   for (int i = 0; i < n; i++) { n     int x; n     cin >> x; n     mx = max(mx, x); n     vs.insert(x); n   } n   mx += m; n   while (m--) { n     int p = *vs.begin(); n     vs.insert(p + 1); n     vs.erase(vs.begin()); n   } n   cout << (*vs.rbegin()) <<     << mx << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100005; n int main() { n   int n, m, t; n   cin >> n >> m >> t; n   int total = (n - 2) * (n - 1) / 2 + 1; n   if (total >= m && m >= n - 1) { n     m = m - n + 1; n     int cant = 0; n     if (t != 1) n       cant = 1; n     else n       cant = n; n     printf( %d %d n , t, cant); n     for (int i = 1; i < n; i++) { n       if (i != cant && i + 1 != cant) printf( %d %d n , i, i + 1); n     } n     for (int i = 1; i <= n && m; i++) { n       if (t - i == 1 || i - t == 1 || t == i || i == cant) continue; n       printf( %d %d n , i, t); n       m--; n     } n     for (int i = 1; i <= n && m; i++) { n       if (i == t || i == cant) continue; n       for (int j = i + 2; j <= n && m; j++) { n         if (j == t || j == cant) continue; n         printf( %d %d n , i, j); n         m--; n       } n     } n   } else n     puts( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e6; n const long long MOD = 1e9 + 7; n const long long N = 1e6 + 7; n const long long N_N = 1e3; n const int INF = 1e9 + 228; n const long double eps = 1e-12; n long long n, a[N], ans, l, ans1; n int main() { n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n   } n   for (int i = 2; i <= n; ++i) { n     if (a[i - 1] > a[i]) { n       ans++; n       ans1 = i; n     } n   } n   if (ans > 1) { n     cout << -1; n   } n   if (ans == 0) { n     cout << 0; n   } n   if (ans == 1) { n     if (a[1] >= a[ans1] && a[1] >= a[n]) { n       cout << n - ans1 + 1; n     } else n       cout << -1; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T1, class T2> n ostream &operator<<(ostream &os, const pair<T1, T2> &p) { n   os <<  {  << p.first <<  ,  << p.second <<  } ; n   return os; n } n const int N = 2e6 + 5; n const int oo = 1e9 + 7; n int lp[N + 1]; n vector<int> pr; n void sieve() { n   for (int i = 2; i <= N; ++i) { n     if (lp[i] == 0) { n       lp[i] = i; n       pr.push_back(i); n     } n     for (int j = 0; j < (int)pr.size() && pr[j] <= lp[i] && i * pr[j] <= N; ++j) n       lp[i * pr[j]] = pr[j]; n   } n } n int n; n int a[N]; n bool isp[N]; n int cnt(int x) { return upper_bound(a, a + n, x) - lower_bound(a, a + n, x); } n int chk() { n   for (int i = upper_bound(a, a + n, 1) - a; i < n; i++) { n     if (isp[a[i] + 1]) return a[i]; n   } n   return 0; n } n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   sieve(); n   for (int i : pr) isp[i] = 1; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   int y = chk(); n   int x = cnt(1) + (y > 0); n   if (x >= 2) { n     cout << x <<   n ; n     if (y) { n       cout << y <<    ; n       x--; n     } n     for (int i = 1; i <= x; i++) cout <<  1  ; n     cout <<   n ; n   } else { n     for (int i = 0; i < n; i++) { n       for (int j = i + 1; j < n; j++) { n         if (isp[a[i] + a[j]]) { n           cout <<  2 n ; n           cout << a[i] <<     << a[j] << endl; n           return 0; n         } n       } n     } n     cout <<  1 n ; n     cout << a[0] <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n; n const int maxn = 16; n char tp[maxn]; n int r[maxn], b[maxn]; n int dp[1 << maxn][2][16 * 16 * 1]; n int inf = (int)(1e9); n int go(int msk, int R, int B, int x, int y) { n   x = min(x, n * n); n   y = min(y, n * n); n   if (msk == (1 << n) - 1) return 0; n   int &res = dp[msk][y == 0][max(x, y)]; n   if (res != -1) return res; n   res = inf; n   for (int i = 0; i < n; i++) { n     if (msk & (1 << i)) continue; n     int costr = max(0, r[i] - R); n     int costb = max(0, b[i] - B); n     int needr = max(0, costr - x); n     int needb = max(0, costb - y); n     int t = max(needr, needb); n     res = min(res, t + go(msk | (1 << i), R + (tp[i] ==  R ), n                           B + (tp[i] ==  B ), x + t - costr, y + t - costb)); n   } n   return res; n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> tp[i] >> r[i] >> b[i]; n   } n   int needr = 0, needb = 0; n   for (int i = 0; i < n; i++) { n     needr += max(0, r[i] - n); n     needb += max(0, b[i] - n); n     r[i] = min(r[i], n); n     b[i] = min(b[i], n); n   } n   int t = max(needr, needb); n   memset(dp, -1, sizeof(dp)); n   cout << n + t + go(0, 0, 0, t - needr, t - needb) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int solve(int i, int a, int b, int c) { n   if (i == 0) return a + b + c; n   if (i == 1) return max((a + b) * c, a + b * c); n   if (i == 2) return max(a * (b + c), a * b + c); n   return a * b * c; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int a, b, c; n   cin >> a >> b >> c; n   int ans = 0; n   for (int i = 0; i < 4; ++i) { n     ans = max(ans, solve(i, a, b, c)); n     ans = max(ans, solve(i, c, b, a)); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int k; n string s; n vector<string> ans; n bool all[26]; n int main() { n   ios_base::sync_with_stdio(0); n   cin >> k >> s; n   string build =   ; n   for (int i = 0; i < s.size(); ++i) n     if (!all[s[i] -  a ]) { n       if (!build.empty()) ans.push_back(build); n       build = s[i]; n       all[s[i] -  a ] = 1; n     } else n       build += s[i]; n   ans.push_back(build); n   if (ans.size() < k) n     cout <<  NO ; n   else { n     cout <<  YES  n          <<   n ; n     while (ans.size() > k) { n       int last = ans.size() - 1; n       string s1 = ans[last], s2 = ans[last - 1]; n       ans.pop_back(); n       ans.pop_back(); n       ans.push_back(s2 + s1); n     } n     for (int i = 0; i < ans.size(); ++i) cout << ans[i] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n static const int mxn = 21; n long long n, res; n int m; n struct Node { n   long long a; n   int b; n   bool operator<(const Node& c) const { return b > c.b; } n } nodes[mxn]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n >> m; n   for (int i = 1; i <= m; ++i) { n     cin >> nodes[i].a >> nodes[i].b; n   } n   sort(nodes + 1, nodes + 1 + m); n   for (int i = 1; i <= m; ++i) { n     if (n >= nodes[i].a) { n       res += nodes[i].a * nodes[i].b; n       n -= nodes[i].a; n     } else { n       res += n * nodes[i].b; n       break; n     } n   } n   cout << res <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n static const int INF = 500000000; n template <class T> n void debug(T a, T b) { n   for (; a != b; ++a) cerr << *a <<    ; n   cerr << endl; n } n int n; n vector<pair<int, int> > g[3005]; n pair<int, int> es[3005]; n int dfs(int v, int p) { n   int res = 0; n   for (int i = 0; i < g[v].size(); ++i) { n     pair<int, int>& e = g[v][i]; n     if (e.first == p) continue; n     res += e.second + dfs(e.first, v); n   } n   return res; n } n int move(int v, int p, int val) { n   int res = val; n   for (int i = 0; i < g[v].size(); ++i) { n     pair<int, int>& e = g[v][i]; n     if (e.first == p) continue; n     res = min(res, move(e.first, v, val + 1 - e.second * 2)); n   } n   return res; n } n int main() { n   cin >> n; n   for (int i = 0; i < n - 1; ++i) { n     int a, b; n     cin >> a >> b; n     --a; n     --b; n     g[a].push_back(make_pair(b, 0)); n     g[b].push_back(make_pair(a, 1)); n     es[i] = make_pair(a, b); n   } n   int ans = INF; n   if (n <= 2) ans = 0; n   for (int i = 0; i < n - 1; ++i) { n     int A, B; n     A = es[i].first; n     B = es[i].second; n     int sum1 = dfs(A, B), sum2 = dfs(B, A); n     ans = min(ans, move(A, B, sum1) + move(B, A, sum2)); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[500005], b[500005], dp[500005], t; n vector<long long> c; n void poisk_del(long long z) { n   for (int del = 2; del * del <= z; del++) { n     if (z % del == 0) c.push_back(del); n     while (z % del == 0) { n       z /= del; n     } n   } n   if (z != 1) c.push_back(z); n } n void add(int s) { n   for (long long mask = 1; mask < (1 << s); mask++) { n     long long proz = 1; n     int kol = 0; n     for (int j = 0; j < s; j++) { n       if ((mask & (1 << j)) > 0) { n         proz *= c[j]; n         kol++; n       } n     } n     if (kol % 2 == 1) { n       t += dp[proz]; n       dp[proz]++; n     } else { n       t -= dp[proz]; n       dp[proz]++; n     } n   } n } n void delet(int s) { n   for (long long mask = 1; mask < (1 << s); mask++) { n     long long proz = 1; n     int kol = 0; n     for (int j = 0; j < s; j++) { n       if ((mask & (1 << j)) > 0) { n         proz *= c[j]; n         kol++; n       } n     } n     if (kol % 2 == 1) { n       dp[proz]--; n       t -= dp[proz]; n     } else { n       dp[proz]--; n       t += dp[proz]; n     } n   } n } n int main() { n   long long n, q; n   cin >> n >> q; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   n = 0; n   for (int i = 0; i < q; i++) { n     int x; n     cin >> x; n     x--; n     c.clear(); n     if (b[x] == 0) { n       n++; n       b[x] = 1; n       poisk_del(a[x]); n       int s = c.size(); n       long long ans = (n * (n + 1) / 2) - n; n       add(s); n       cout << ans - t << endl; n     } else { n       n--; n       b[x] = 0; n       poisk_del(a[x]); n       int s = c.size(); n       long long ans = (n * (n + 1) / 2) - n; n       delet(s); n       cout << ans - t << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int arr[1000000]; n map<pair<int, int>, int> mp; n int cnt[1000000]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   long long n; n   cin >> n; n   long long ans = 0; n   for (int i = 0; i < n; i++) { n     cin >> arr[i + 1]; n     ans += arr[i + 1]; n   } n   int q; n   cin >> q; n   for (int i = 0; i < q; i++) { n     int s, t, u; n     cin >> s >> t >> u; n     if (mp[make_pair(s, t)]) { n       cnt[mp[make_pair(s, t)]]--; n       if (cnt[mp[make_pair(s, t)]] < arr[mp[make_pair(s, t)]]) { n         ans++; n       } n     } n     cnt[u]++; n     mp[make_pair(s, t)] = u; n     if (cnt[u] <= arr[u]) ans--; n     cout << max(ans, n) << endl; n   } n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:167772160 ) n using namespace std; n int n, i, j, a, b, x[100001], y[100001], v, k, uns[100001], p, q, w[6]; n int findd(int l, int r, int xx) { n   int t; n   t = (l + r) / 2; n   if (l == r) { n     if (x[l] == xx) n       return l; n     else n       return -1; n   } else { n     if (x[t] >= xx) n       return findd(l, t, xx); n     else n       return findd(t + 1, r, xx); n   } n } n int main() { n   cin >> n; n   cin >> a >> b; n   if (a > b) { n     p = 1; n     q = 2; n   } else { n     p = 2; n     q = 1; n   } n   for (i = 0; i < n; i++) { n     cin >> x[i]; n     y[i] = x[i]; n   } n   sort(x, x + n); n   if (a == b) { n     for (i = 1; i <= a; i++) cout << 1 <<    ; n     for (i = 1; i <= b; i++) cout << 2 <<    ; n     cout << endl; n     return 0; n   } n   memset(w, 0, sizeof(w)); n   for (i = 0; i < n; i++) uns[i] = q; n   k = 0; n   v = max(a, b); n   for (i = 0; i < v; i++) w[x[i]]++; n   if (p == 1) { n     for (i = 0; i < n; i++) { n       if (w[y[i]]) { n         uns[i] = p; n         k++; n         w[y[i]]--; n       } n     } n   } else { n     for (i = n - 1; i >= 0; i--) { n       if (w[y[i]]) { n         uns[i] = p; n         k++; n         w[y[i]]--; n       } n     } n   } n   for (i = 0; i < n; i++) cout << uns[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int D[1 << 20], cnt[20][20]; n bool chk[1 << 20]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ((void)0); n   ((void)0); n   ((void)0); n   int N, M; n   queue<int> Q; n   string s; n   cin >> N >> M >> s; n   for (int i = 1; i < N; i++) n     if (s[i - 1] != s[i]) { n       cnt[s[i - 1] -  a ][s[i] -  a ]++; n       cnt[s[i] -  a ][s[i - 1] -  a ]++; n     } n   memset(D, 0x7f, sizeof(D)); n   chk[0] = true; n   D[0] = 0; n   Q.push(0); n   while (!Q.empty()) { n     int b = Q.front(), bc = __builtin_popcount(b) + 1; n     Q.pop(); n     for (int i = 0; i < M; i++) n       if (~b & (1 << i)) { n         int diff = 0; n         for (int j = 0; j < M; j++) { n           if (b & (1 << j)) n             diff += bc * cnt[i][j]; n           else n             diff -= bc * cnt[i][j]; n         } n         D[b | (1 << i)] = min(D[b | (1 << i)], D[b] + diff); n         if (!chk[b | (1 << i)]) { n           chk[b | (1 << i)] = true; n           Q.push(b | (1 << i)); n         } n       } n   } n   cout << D[(1 << M) - 1] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool compare(string &s1, string &s2) { return s1.size() < s2.size(); } n void solve() { n   int n; n   cin >> n; n   vector<string> s(n); n   for (int i = 0; i < n; i++) cin >> s[i]; n   sort(s.begin(), s.end(), compare); n   for (int i = 0; i < n - 1; i++) n     if (s[i + 1].find(s[i]) == -1) { n       cout <<  NO n ; n       return; n     } n   cout <<  YES n ; n   for (int i = 0; i < n; i++) cout << s[i] << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n #include <iostream> n using namespace std; n  n #define db cout <<  debugging... n ; n #define db1(x) cout << #x <<   =   << x <<   n  n #define db2(x, y) cout << #x <<   =   << x <<  ,   << #y <<   =   <<y <<   n  n #define db3(x, y, z) cout << #x <<   =   << x <<  ,   << #y <<   =   << y <<  ,   << #z <<   =   << z <<   n  n #define dbvec(a) cout << #a <<  :  ; for (auto x: a) cout << x <<    ; cout <<   n  n  n #define int long long n #define pb push_back n #define all(x) x.begin(), x.end() n #define endl   n  n #define fileio freopen( input.txt ,  r , stdin); freopen( output.txt ,  w , stdout) n #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) n const int MOD = 1000000007; n  n int32_t main() { n     fastio; n     // fileio; n  n     int t; n     cin >> t; n  n     while (t--) { n  n         int n; n         cin >> n; n  n         bool b = true; n  n         for (int i = 0; i < n; ++i) { n             int x; n             cin >> x; n  n             // db3(t, n, x); n  n             int sqrtt = sqrt(x); n             sqrtt *= sqrtt; n  n             if (sqrtt != x) { n                 b = false; n             } n         } n  n         if (b) { n             cout <<  NO n ; n         } else { n             cout <<  YES n ; n         } n  n     } n  n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int n; n int dx[] = {0, 0, -1, 1}; n int dy[] = {1, -1, 0, 0}; n char s[100002]; n void Print(long long x) { n   printf( %lld n , x); n   exit(0); n } n bool ok(long long x1, long long y1, long long x2, long long y2, long long day) { n   return (abs(x2 - x1) + abs(y2 - y1) <= day); n } n long long bs(long long addX, long long addY, int n, long long x1, long long y1, n              long long x2, long long y2) { n   long long i = 0, p = 1LL << 31; n   while (p) { n     if (i + p && n         !ok(x1 + addX * (i + p), y1 + addY * (i + p), x2, y2, (i + p) * n)) n       i += p; n     p >>= 1; n   } n   return i; n } n int main() { n   long long x1, y1, x2, y2; n   int n; n   scanf( %lld%lld%lld%lld%d n%s , &x1, &y1, &x2, &y2, &n, &s); n   long long addX = 0, addY = 0; n   for (int i = 0; i < n; ++i) { n     int d; n     if (s[i] ==  U ) n       d = 0; n     else if (s[i] ==  D ) n       d = 1; n     else if (s[i] ==  L ) n       d = 2; n     else if (s[i] ==  R ) n       d = 3; n     addX += dx[d]; n     addY += dy[d]; n     if (abs(x2 - x1 - addX) + abs(y2 - y1 - addY) <= (i + 1)) Print(i + 1); n   } n   long long cnt = bs(addX, addY, n, x1, y1, x2, y2); n   if (cnt > 1) --cnt; n   x1 += cnt * addX; n   y1 += cnt * addY; n   long long day = cnt * n; n   for (int t = 0; t < 20; ++t) { n     for (int i = 0; i < n; ++i) { n       int d; n       ++day; n       if (s[i] ==  U ) n         d = 0; n       else if (s[i] ==  D ) n         d = 1; n       else if (s[i] ==  L ) n         d = 2; n       else if (s[i] ==  R ) n         d = 3; n       x1 += dx[d]; n       y1 += dy[d]; n       if (abs(x2 - x1) + abs(y2 - y1) <= day) Print(day); n     } n   } n   printf( -1 n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int recur_depth = 0; n const long long sz = 14, isz = 2e6 + 10, mod = 1e9 + 7; n long long p[sz], win[sz][sz], scc[(1 << sz)], n; n long long fastPow(long long x, long long n, long long MOD) { n   long long ret = 1; n   while (n) { n     if (n & 1) ret = (ret * x) % MOD; n     x = (x * x) % MOD; n     n >>= 1; n   } n   return ret % MOD; n } n inline long long inv(long long x) { return fastPow(x, mod - 2, mod); } n long long prob(long long from, long long to) { n   long long ret = 1; n   for (long long i = 0; i < n; ++i) { n     for (long long j = 0; j < n; ++j) { n       if ((from >> i & 1) && (to >> j & 1)) ret = (ret * win[i][j]) % mod; n     } n   } n   return ret; n } n int main() { n   std::ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   cin >> n; n   for (long long i = 0; i < n; ++i) cin >> p[i]; n   for (long long i = 0; i < n; ++i) n     for (long long j = 0; j < n; ++j) n       win[i][j] = (p[i] * inv(p[i] + p[j])) % mod; n   long long ans = 0, lim = (1 << n) - 1; n   for (int mask = 0; mask <= lim; mask++) { n     scc[mask] = 1; n     for (int i = mask; i > 0; i = (i - 1) & mask) { n       if (i == mask) continue; n       scc[mask] -= (scc[i] * prob(i, mask ^ i)) % mod; n       if (scc[mask] < 0) scc[mask] += mod; n     } n     long long win_prob = (scc[mask] * __builtin_popcount(mask)) % mod; n     win_prob = (win_prob * prob(mask, lim ^ mask)) % mod; n     ans += win_prob; n     if (ans >= mod) ans -= mod; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <algorithm> n #include <array> n #include <bitset> n #include <cctype> n #include <chrono> n #include <cmath> n #include <ctime> n #include <deque> n #include <fstream> n #include <functional> n #include <iomanip> n #include <iostream> n #include <iso646.h> n #include <iterator> n #include <list> n #include <map> n #include <memory> n #include <numeric> n /*                           mnciitbhu                        */ n // n //  |    /| |    |    --  |  |  -------  |⎻⎻   |   |  |    | n //  |   / | |    |   /    |  |     |     |   |  |   |  |    | n //  |   /  | |    |  (     |  |     |     |--<   |---|  |    | n //  |      | |    |       |  |     |     |   |  |   |     / n //  |      | |     |    --  |  |     |     |__/   |   |    -- n // n #include <queue> n #include <ratio> n #include <regex> n #include <set> n #include <sstream> n #include <stack> n #include <string> n #include <type_traits> n #include <unordered_map> n #include <unordered_set> n #include <utility> n #include <valarray> n #include <vector> n using namespace std; n using namespace std::chrono; n using ll = long long; n using ull = unsigned long long; n using ld = long double; n #if not defined(ONLINE_JUDGE) && not defined(_MSVC_LANG) && defined(DEBUG_) n #include  myconfig.hpp  n #else n #define LOL(x) ; n #define LOLX(...) ; n #endif n #if not defined(DEBUG_) n #endif n  n int main()  n { n  ios::sync_with_stdio(false); n  cin.tie(0); n  n  string s; n  cin >> s; n  if(s.length() == 1) n  { n   cout << s; n   return 0; n  } n  for(int i = 0; i < s.size() - 1; ++i) n  { n   if(i < s.size() - 2 and s[i] == s[i + 1] and s[i] == s[i + 2]) n   { n    if(s[i] ==  z ) n     s[i + 1] =  a ; n    else n     s[i + 1] =  z ; n   } n   else if(s[i] == s[i + 1]) n   { n    if(i != 0)  n    { n     if(s[i - 1] !=  d  and s[i + 1] !=  d ) n      s[i] =  d ; n     else if(s[i - 1] !=  e  and s[i + 1] !=  e ) n      s[i] =  e ; n     else n      s[i] =  f ; n    } n    else n    { n     if(s[i + 1] ==  d ) n      s[i] =  e ; n     else n      s[i] =  d ; n    } n   } n  } n  cout << s; n  n  return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<pair<int, int>> v; n   for (int i = 0; i < n; i++) { n     int l, r; n     cin >> r >> l; n     v.push_back(make_pair(l, r)); n   } n   sort(v.begin(), v.end()); n   reverse(v.begin(), v.end()); n   int len = v.size(); n   long long k = 1, sum = 0, i = 0; n   while (k--) { n     sum += v[i].second; n     k += v[i].first; n     i++; n     if (i == len) break; n   } n   cout << sum << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:16000000 ) n using namespace std; n long long mod = 998244353; n long double inf = 1e9; n long double eps = 1e-8; n long double pi = acos(-1); n ifstream in( input.txt ); n ofstream out( output.txt ); n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, k; n   cin >> n >> k; n   string s; n   cin >> s; n   if (k == 0) { n     cout << s; n   } else { n     if (s.size() == 1) { n       cout << 0; n       return 0; n     } n     if (s[0] !=  1 ) { n       s[0] =  1 ; n       k--; n     } n     for (int i = 1; i < n; i++) { n       if (k == 0) break; n       if (s[i] !=  0 ) { n         s[i] =  0 ; n         k--; n       } n     } n     cout << s; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 101010; n int a[N]; n int b[N]; n int c[N]; n int n; n long long ans; n void init() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %1d , a + i); n     c[i] = a[i]; n   } n   for (int i = 1; i <= n; i++) { n     scanf( %1d , b + i); n   } n   for (int i = 1; i < n; i++) { n     int delta = c[i] - b[i]; n     c[i] -= delta; n     c[i + 1] -= delta; n     ans += abs(delta); n   } n } n void check(int now, int add) { n   if (ans == 0) return; n   if (0 <= a[now + 1] + add && a[now + 1] + add <= 9) { n     printf( %d %d n , now, add); n     a[now] += add; n     a[now + 1] += add; n     ans--; n     return; n   } n   check(now + 1, -add); n   if (ans == 0) return; n   printf( %d %d n , now, add); n   a[now] += add; n   a[now + 1] += add; n   ans--; n } n void work() { n   printf( %lld n , ans); n   if (ans > 100000) ans = 100000; n   for (int i = 1; i < n && ans > 0; i++) n     while (a[i] != b[i] && ans) check(i, (b[i] > a[i]) ? 1 : -1); n } n int main() { n   init(); n   if (c[n] == b[n]) n     work(); n   else n     printf( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 300010; n class cmp { n  public: n   bool operator()(const pair<long long int, long long int> &a, n                   const pair<long long int, long long int> &b) { n     if (a.first == b.first) return a.second > b.second; n     return a.first < b.first; n   } n }; n long long int a[N], b[N], fact[N]; n long long int mod = 998244353; n void cal() { n   fact[1] = 1; n   for (long long int i = 2; i < N; i++) { n     fact[i] = ((fact[i - 1] % mod) * (i % mod)) % mod; n   } n } n bool sort1(const pair<long long int, long long int> &x, n            const pair<long long int, long long int> &y) { n   if (x.first == y.first) return x.second < y.second; n   return x.first < y.first; n } n void solve() { n   long long int n; n   cin >> n; n   cal(); n   memset(a, 0, sizeof(a)); n   memset(b, 0, sizeof(b)); n   long long int i, x, y, f = 0; n   vector<pair<long long int, long long int>> v; n   for (i = 0; i < n; i++) { n     cin >> x >> y; n     a[x]++; n     b[y]++; n     v.push_back({x, y}); n     if (a[x] == n || b[y] == n) f = 1; n   } n   if (f) { n     cout <<  0  << endl; n     return; n   } n   long long int ans = fact[n]; n   long long int ans1 = 1; n   for (i = 1; i < N; i++) { n     if (a[i]) { n       long long int cnt = fact[a[i]]; n       ans1 = ((ans1 % mod) * (cnt % mod)) % mod; n     } n   } n   ans = (ans - ans1 + mod) % mod; n   long long int ans2 = 1; n   for (i = 1; i < N; i++) { n     if (b[i]) { n       long long int cnt = fact[b[i]]; n       ans2 = ((ans2 % mod) * (cnt % mod)) % mod; n     } n   } n   ans = (ans - ans2 + mod) % mod; n   sort(v.begin(), v.end(), sort1); n   long long int k = 0; n   for (i = 0; i < n - 1; i++) { n     if (v[i].second > v[i + 1].second) { n       k = 1; n       break; n     } n   } n   if (k == 0) { n     ans1 = 1; n     for (i = 0; i < n;) { n       long long int j = i; n       long long int cnt = 0; n       while (j < n && v[i].first == v[j].first && v[i].second == v[j].second) { n         j++; n         cnt++; n       } n       i = j; n       cnt = fact[cnt]; n       ans1 = ((ans1 % mod) * (cnt % mod)) % mod; n     } n     ans = (ans + ans1) % mod; n   } n   cout << ans << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   int t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100009], c[100009], b[100009], d[100009]; n long long ksm(long long a, long long n, long long d) { n   long long ans; n   ans = 1; n   while (n > 0) { n     if (n % 2 == 1) ans = (ans * a) % d; n     a = a * a % d; n     n = n / 2; n   } n   return ans % d; n } n long long ksm2(long long a, long long n) { n   long long ans; n   ans = 1; n   while (n > 0) { n     if (n % 2 == 1) { n       if (a > 1e5) return 0; n       ans = ans * a; n     } n     if (ans > 1e5) return 0; n     if (a > 1e5) return 0; n     a = a * a; n     n = n / 2; n   } n   return ans; n } n int main() { n   int n, k; n   cin >> n >> k; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     c[i] = 1; n     b[i] = 1; n     int gg = a[i]; n     for (int j = 2; j <= sqrt(gg); j++) n       if (a[i] % j == 0) { n         int g = 0; n         while (a[i] % j == 0) { n           g++; n           a[i] /= j; n         } n         g = g % k; n         b[i] *= ksm(j, g, 1e18 + 9); n         c[i] *= ksm2(j, (k - g) % k); n       } n     if (a[i] != 1) { n       b[i] *= a[i]; n       c[i] *= ksm2(a[i], k - 1); n     } n     d[b[i]]++; n   } n   long long ans = 0; n   for (int i = 1; i <= n; i++) { n     if (c[i] != 0) { n       ans += d[c[i]]; n       if (c[i] == b[i]) ans--; n     } n   } n   ans /= 2; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000010; n long long s1[N], s2[N]; n int p, q, n, b[N], d[N]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %I64d , &s1[i]), s1[i] += s1[i - 1]; n   for (int i = 1; i <= n; i++) scanf( %I64d , &s2[i]), s2[i] += s2[i - 1]; n   for (int i = 0; i <= n; i++) { n     while (s1[i] > s2[p] && p <= n) p++; n     if (s1[i] <= s2[p] && b[s2[p] - s1[i]]) { n       q = b[s2[p] - s1[i]] - 1; n       printf( %d n , i - q); n       for (int j = q + 1; j <= i; j++) printf( %d  , j); n       q = d[s2[p] - s1[i]]; n       putchar(  n ); n       printf( %d n , p - q); n       for (int j = q + 1; j <= p; j++) printf( %d  , j); n       return 0; n     } else n       b[s2[p] - s1[i]] = i + 1, d[s2[p] - s1[i]] = p; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 10; n const int len = 700, MAX = 1e7 + 10; n int n, m, k, a[maxn]; n int f[MAX], g[MAX]; n long long ans[maxn]; n struct query { n   int l, r, id; n } q[maxn]; n bool operator<(const query &a, const query &b) { n   if ((a.l - 1) / len != (b.l - 1) / len) return a.l < b.l; n   return a.r < b.r; n } n void enter() { n   cin >> n >> m >> k; n   for (int i = 1; i <= n; ++i) cin >> a[i]; n   for (int i = 1; i <= m; ++i) { n     cin >> q[i].l >> q[i].r; n     q[i].id = i; n   } n   sort(q + 1, q + m + 1); n } n int lim(int i) { return ((i - 1) / len + 1) * len; } n void solve() { n   long long ret = 0; n   int rgt = 0, it, cur = 0; n   g[0] = 1; n   for (int i = 1; i <= m; ++i) { n     if (rgt < lim(q[i].l)) { n       rgt = lim(q[i].l); n       it = rgt + 1; n       memset(f, 0, sizeof(f)); n       f[0] = 1; n       cur = 0; n       ret = 0; n     } n     if (q[i].r <= rgt) { n       long long tmp = 0; n       for (int j = q[i].l, v = 0; j <= q[i].r; ++j) { n         v ^= a[j]; n         tmp += g[v ^ k]; n         ++g[v]; n       } n       ans[q[i].id] = tmp; n       for (int j = q[i].l, v = 0; j <= q[i].r; ++j) { n         v ^= a[j]; n         --g[v]; n       } n       continue; n     } n     while (it <= q[i].r) { n       cur ^= a[it++]; n       ret += f[cur ^ k]; n       ++f[cur]; n     } n     long long save = ret; n     --f[0]; n     for (int j = rgt, v = 0; j >= q[i].l; --j) { n       v ^= a[j]; n       ret += f[v ^ k]; n       ret += g[v ^ k]; n       ++g[v]; n     } n     ++f[0]; n     ans[q[i].id] = ret; n     for (int j = rgt, v = 0; j >= q[i].l; --j) { n       v ^= a[j]; n       --g[v]; n     } n     ret = save; n   } n } n int main() { n   ios_base ::sync_with_stdio(0); n   enter(); n   solve(); n   for (int i = 1; i <= m; ++i) printf( %I64d n , ans[i]); n } n


#include <bits/stdc++.h> n using namespace std; n bool G[30][30]; n int main() { n   int T; n   scanf( %d , &T); n   while (T--) { n     int n, p; n     scanf( %d%d , &n, &p); n     memset(G, 0, sizeof(G)); n     for (int i = 0; i < n; ++i) n       G[i][(i + 1) % n] = G[(i + 1) % n][i] = G[i][(i + 2) % n] = n           G[(i + 2) % n][i] = 1; n     for (int step = 3; p; ++step) { n       for (int i = 0; p && i < n; ++i) { n         G[i][(i + step) % n] = G[(i + step) % n][i] = 1; n         --p; n       } n     } n     for (int i = 0; i < n; ++i) n       for (int j = i + 1; j < n; ++j) n         if (G[i][j]) printf( %d %d n , i + 1, j + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7, lg = 20, N = 1e5 + 5; n int ans[N]; n bool vis[N]; n vector<pair<int, int> > g[N]; n struct node { n   node *ch[11]; n   node *sp[lg]; n   int val, lvl, last; n   node() { n     memset(ch, 0, sizeof ch); n     memset(sp, 0, sizeof sp); n     val = lvl = last = 0; n   } n }; n struct cmp { n   bool operator()(const pair<node *, int> a, const pair<node *, int> b) const { n     if (b.first->lvl != a.first->lvl) return a.first->lvl < b.first->lvl; n     node *u = (node *)b.first; n     node *v = (node *)a.first; n     for (int i = lg - 1; i >= 0; i--) { n       if (u->sp[i] != v->sp[i]) { n         u = u->sp[i]; n         v = v->sp[i]; n       } n     } n     if (v->last != u->last) return v->last < u->last; n     return a.second < b.second; n   } n }; n vector<int> digits[N]; n void build() { n   for (int i = 1; i < N; i++) { n     int j = i; n     while (j) digits[i].push_back(j % 10), j /= 10; n     reverse(digits[i].begin(), digits[i].end()); n   } n } n void build(node *a) { n   for (int i = 1; i < lg; i++) { n     a->sp[i] = a->sp[i - 1]->sp[i - 1]; n   } n } n void dij() { n   node *root = new node(); n   root->sp[0] = root; n   build(root); n   set<pair<node *, int>, cmp> st; n   st.insert({root, 1}); n   while (st.size()) { n     node *cur = (*st.begin()).first; n     int temp = (*st.begin()).second; n     st.erase(st.begin()); n     if (vis[temp] == 0) { n       vis[temp] = 1; n       ans[temp] = cur->val; n     } else n       continue; n     for (int i = 0; i < g[temp].size(); i++) { n       int v = g[temp][i].first; n       int cost = g[temp][i].second; n       node *temp = cur; n       for (auto dig : digits[cost]) { n         if (!temp->ch[dig]) { n           temp->ch[dig] = new node(); n           temp->ch[dig]->lvl = temp->lvl + 1; n           temp->ch[dig]->val = ((temp->val * 1ll * 10) % mod + dig) % mod; n           temp->ch[dig]->sp[0] = temp; n           temp->ch[dig]->last = dig; n           build(temp->ch[dig]); n         } n         temp = temp->ch[dig]; n       } n       st.insert({temp, v}); n     } n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   build(); n   int n, m; n   cin >> n >> m; n   for (int i = 1; i <= m; i++) { n     int u, v; n     cin >> u >> v; n     g[u].push_back({v, i}); n     g[v].push_back({u, i}); n   } n   dij(); n   for (int i = 2; i <= n; i++) cout << ans[i] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma comment(linker,  /stack:200000000 ) n using namespace std; n const int mnx = 3e5 + 9; n const int mod = 1e9 + 7; n const long long inf = 1e15 + 4; n long long binpow(long long a, int n) { n   long long res = 1; n   while (n) { n     if (n & 1) res = (res * a) % mod; n     a = (a * a) % mod; n     n >>= 1; n   } n   return res % mod; n } n long long fact[mnx], rev[mnx]; n void pre() { n   fact[0] = rev[0] = 1; n   for (int i = 1; i <= 1e5; i++) { n     fact[i] = fact[i - 1] * i % mod; n     rev[i] = binpow(fact[i], mod - 2) % mod; n   } n } n long long cnk(int n, int k) { n   if (n < k) return 0; n   return (fact[n] * rev[k] % mod) * rev[n - k] % mod; n } n long long n, m, k; n void solve() { n   cin >> n >> m >> k; n   pre(); n   cout << cnk(m - 1, k * 2) * cnk(n - 1, k * 2) % mod <<   n ; n } n int main() { n   int tt = 1; n   while (tt--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int read() { n   int x = 0, f = 1; n   char c = getchar(); n   while (c <  0  or c >  9 ) { n     if (c ==  - ) f = -f; n     c = getchar(); n   } n   while (c >=  0  and c <=  9 ) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   return x * f; n } n struct EDGE { n   int to, Next; n } edge[400100]; n struct DOTS { n   long long cnt, num[2], all, sum, dpth; n   vector<int> sons; n } dot[200100]; n int n; n int h[200100], cnt; n long long ans; n bool vis[200100]; n void add(int from, int to) { n   edge[++cnt].to = to; n   edge[cnt].Next = h[from]; n   h[from] = cnt; n } n void dfs(int t) { n   vis[t] = 1; n   dot[t].num[0]++; n   for (int i = h[t]; i; i = edge[i].Next) { n     int v = edge[i].to; n     if (!vis[v]) { n       dot[t].cnt++; n       dot[t].sons.push_back(v); n       dot[v].dpth = dot[t].dpth + 1; n       dfs(v); n       ans += dot[t].num[0] * dot[v].num[1] * 2 * dot[t].sum; n       ans %= 1000000007; n       ans -= dot[t].num[1] * dot[v].num[0] * 2 * dot[t].sum; n       ans %= 1000000007; n       dot[t].num[0] += dot[v].num[1]; n       dot[t].num[1] += dot[v].num[0]; n     } n   } n   ans += dot[t].sum; n } n void dp(int t) { n   for (int i = 0; i < dot[t].cnt; ++i) { n     int v = dot[t].sons[i]; n     ans += dot[v].num[0] * (dot[1].num[dot[v].dpth & 1] - dot[v].num[0]) * 2 * n            dot[v].sum; n     ans %= 1000000007; n     ans -= dot[v].num[1] * (dot[1].num[(dot[v].dpth ^ 1) & 1] - dot[v].num[1]) * n            2 * dot[v].sum; n     ans %= 1000000007; n     dp(v); n   } n } n int main() { n   n = read(); n   for (int i = 1; i <= n; ++i) dot[i].sum = read(); n   for (int i = 1; i < n; ++i) { n     int u = read(); n     int v = read(); n     add(u, v); n     add(v, u); n   } n   dfs(1); n   dp(1); n   ans %= 1000000007; n   ans += 1000000007; n   ans %= 1000000007; n   printf( %lld , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n, m, count = 0; n   cin >> n >> m; n   char x; n   vector<int> r, c; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> x; n       if (x ==  S ) { n         r.push_back(i); n         c.push_back(j); n       } n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if ((find(r.begin(), r.end(), i) != r.end()) && n           (std::find(c.begin(), c.end(), j) != c.end())) { n         continue; n       } else { n         count++; n       } n     } n   } n   cout << count; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a[11] = {0}, i, maxx, c; n   cin >> n; n   for (i = 1; i <= n; i++) { n     cin >> a[i]; n     if (i == 1) n       maxx = a[1]; n     else n       maxx = max(a[i], maxx); n   } n   printf( %d , maxx ^ a[n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, ans, temp; n set<int> st; n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   ; n   cin >> n >> m; n   ans = n + m; n   temp = 2; n   while (n) { n     n -= (temp % 6 != 0); n     st.insert(temp); n     temp += 2; n   } n   temp = 3; n   while (m) { n     m -= (temp % 6 != 0); n     st.insert(temp); n     temp += 3; n   } n   for (auto i : st) { n     ans--; n     if (!ans) return cout << i <<   n , 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int p = 1000 * 1000 * 1000 + 7; n int main() { n   int n, m; n   vector<long long> fact(1000001); n   fact[0] = 1; n   for (int i = 1; i < 1000001; i++) fact[i] = (i * fact[i - 1]) % p; n   cin >> n >> m; n   vector<pair<int, int>> v(m); n   for (int i = 0; i < n; i++) { n     int k; n     cin >> k; n     for (int j = 0; j < k; j++) { n       int l; n       cin >> l; n       l--; n       v[l].first *= p; n       v[l].first += i + 1; n       v[l].second *= 2348621; n       v[l].second += i + 1; n     } n   } n   map<pair<int, int>, int> f; n   for (int i = 0; i < m; i++) f[v[i]]++; n   long long ans = 1; n   for (map<pair<int, int>, int>::iterator a = f.begin(); a != f.end(); a++) n     ans = (fact[(*a).second] * ans) % p; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n string arr[10] = { 0 ,  0 ,  2 ,  3 ,  322 ,  5 ,  53 ,  7 ,  7222 ,  7332 }; n int main() { n   int x; n   cin >> x; n   char a[x]; n   string s; n   for (int i = 0; i < x; i++) { n     cin >> a[i]; n     if (a[i] !=  0  && a[i] !=  1 ) s += arr[a[i] -  0 ]; n   } n   sort(s.rbegin(), s.rend()); n   cout << s; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<long long, pair<long long, long long> > > edges; n vector<long long> wt(100005); n long long sz[100005], parent[100005]; n long long ans = 0; n long long n, m; n void make_set() { n   for (long long i = 1; i <= n; i++) { n     sz[i] = 1; n     parent[i] = i; n   } n } n long long findParent(long long x) { n   if (x == parent[x]) return x; n   return findParent(parent[x]); n } n void merge_sets(long long x, long long y, long long w) { n   x = findParent(x); n   y = findParent(y); n   if (x == y) return; n   ans += w * sz[x] * sz[y]; n   if (sz[x] > sz[y]) { n     parent[y] = x; n     sz[x] += sz[y]; n   } else { n     parent[x] = y; n     sz[y] += sz[x]; n   } n } n int main() { n   cin >> n >> m; n   for (long long i = 1; i <= n; i++) cin >> wt[i]; n   for (long long i = 1; i <= m; i++) { n     long long x, y; n     cin >> x >> y; n     edges.push_back(make_pair(min(wt[x], wt[y]), make_pair(x, y))); n   } n   sort(edges.begin(), edges.end()); n   reverse(edges.begin(), edges.end()); n   make_set(); n   for (long long i = 0; i < m; i++) { n     merge_sets(edges[i].second.first, edges[i].second.second, edges[i].first); n   } n   double anss = (double)ans; n   anss /= (double)n; n   anss /= (double)(n - 1); n   anss *= 2.00; n   cout << fixed << setprecision(10) << anss << endl; n   return 0; n } n


#include <bits/stdc++.h> n const int P = (1 << 30) - 1; n int a, b, c, p[2005], vis[2005]; n std::unordered_map<long long, int> mmp[2005]; n void sieve(int n) { n   vis[0] = vis[1] = 1; n   for (int i = 2; i <= n; ++i) { n     if (!vis[i]) p[++*p] = i; n     for (int j = 1; j <= *p && i * p[j] <= n; ++j) { n       vis[i * p[j]] = 1; n       if (i % p[j] == 0) break; n     } n   } n } n int dp(int kk1, int kk2, int kk3, int pid) { n   if (pid == 0) return 1; n   long long ha = 1ll * kk1 * (a + 1) * (a + 1) + 1ll * kk2 * (a + 1) + kk3; n   if (mmp[pid].count(ha)) return mmp[pid][ha]; n   int ans = 0; n   int k1 = 1, k2 = 1, k3 = 1, k4 = 0; n   while (k1 <= kk1) { n     k2 = 1; n     int k5 = 0; n     while (k2 <= kk2) { n       k3 = 1; n       int k6 = 0; n       while (k3 <= kk3) { n         (ans += n          1ll * dp(kk1 / k1, kk2 / k2, kk3 / k3, pid - 1) * (k4 + k5 + k6 + 1) & n          P) &= P; n         k3 *= p[pid], ++k6; n       } n       k2 *= p[pid], ++k5; n     } n     k1 *= p[pid], ++k4; n   } n   return mmp[pid][ha] = ans; n } n int main() { n   scanf( %d%d%d , &a, &b, &c); n   if (a < b) a ^= b ^= a ^= b; n   if (a < c) a ^= c ^= a ^= c; n   sieve(a); n   printf( %d n , dp(a, b, c, *p)); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast , 3,  inline ) n using namespace std; n string s, t; n int n; n void pairr() { n   if (cin >> t) { n     s += t; n     if (t ==  pair ) s +=  < , pairr(), s +=  , , pairr(), s +=  > ; n   } else { n     cout <<  Error occurred ; n     exit(0); n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   pairr(); n   if (cin >> t) { n     cout <<  Error occurred ; n     return 0; n   } n   cout << s; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s; n int m, ch[1002]; n int gt(int bal, int prv, int st) { n   if (st == m) return ch[st] = 11; n   if (bal <= 0) { n     for (int i = 1; i <= 10; i++) { n       if (i != prv && s[i] ==  1  && bal + i > 0) { n         int t = gt(bal + i, i, st + 1); n         if (t) return ch[st] = i; n       } n     } n     return 0; n   } n   for (int i = 1; i <= 10; i++) { n     if (i != prv && s[i] ==  1  && bal - i < 0) { n       int t = gt(bal - i, i, st + 1); n       if (t) return ch[st] = i; n     } n   } n   return 0; n } n int main() { n   memset(ch, -1, sizeof(ch)); n   cin >> s >> m; n   s =     + s; n   int to = gt(0, 0, 0); n   if (ch[0] == -1) n     cout <<  NO ; n   else { n     int k = 0; n     cout <<  YES n ; n     while (k < m) { n       cout << ch[k] <<    ; n       k++; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[10000], m, x, v[10000], sol[10000]; n void g(int n) { n   for (int i = 2; i <= 1000; i++) { n     for (int q = i; q <= 1000; q++) { n       if (q % i != 0 && i * q <= 1000) v[i * q] = 1; n     } n   } n } n int main() { n   int k = 0; n   cin >> n; n   g(n); n   for (int i = 2; i <= n; i++) { n     if (v[i] == 0) { n       sol[k] = i; n       k++; n     } n   } n   cout << k << endl; n   for (int i = 0; i < k; i++) { n     cout << sol[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n, k; n     cin >> n >> k; n     char arr[] = { a ,  b ,  c ,  d ,  e ,  f ,  g ,  h ,  i , n                    j ,  k ,  l ,  m ,  n ,  o ,  p ,  q ,  r , n                    s ,  t ,  u ,  v ,  w ,  x ,  y ,  z }; n     int i = 0; n     while (n--) { n       cout << arr[i]; n       i++; n       if (i == k) { n         i = 0; n       } n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long s[200005], e[200005]; n long long win(long long s, long long e) { n   if (e & 1) { n     if (s & 1) return 0; n     return 1; n   } n   if (s > e / 2) { n     if (s & 1) return 1; n     return 0; n   } n   if (s > e / 4) return 1; n   return win(s, e >> 2); n } n long long lose(long long s, long long e) { n   if (s > e / 2) return 1; n   return win(s, e >> 1); n } n int main() { n   long long i, n, j, k, t, m, w, l, cur = 0; n   scanf( %lld , &t); n   for (i = 1; i <= t; i++) scanf( %lld%lld , &s[i], &e[i]); n   for (i = 1; i <= t; i++) { n     w = win(s[i], e[i]); n     l = lose(s[i], e[i]); n     w ^= cur; n     l ^= cur; n     if (w == l) break; n     if (w) n       cur = 1; n     else n       cur = 0; n   } n   printf( %lld %lld n , w, l); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   std::ios::sync_with_stdio(0); n   long long n, m; n   cin >> n >> m; n   vector<long long> a, b; n   vector<long long> sum1, sum2; n   long long prev = 0; n   for (int i = 0; i < n; i++) { n     long long x; n     cin >> x; n     prev += x; n     a.push_back(x); n     sum1.push_back(prev); n   } n   prev = 0; n   for (int i = 0; i < m; i++) { n     long long x; n     cin >> x; n     prev += x; n     b.push_back(x); n     sum2.push_back(prev); n   } n   long long z; n   cin >> z; n   vector<long long> dp1, dp2; n   for (int l = 1; l <= n; l++) { n     long long mini = sum1[l - 1]; n     for (int i = l; i < sum1.size(); i++) { n       mini = min(sum1[i] - sum1[i - l], mini); n     } n     dp1.push_back(mini); n   } n   for (int l = 1; l <= m; l++) { n     long long mini = sum2[l - 1]; n     for (int i = l; i < sum2.size(); i++) { n       mini = min(sum2[i] - sum2[i - l], mini); n     } n     dp2.push_back(mini); n   } n   long long prod = 0; n   for (long long i = 0; i < dp1.size(); i++) { n     for (long long j = 0; j < dp2.size(); j++) { n       if (dp1[i] * dp2[j] <= z) { n         prod = max((i + 1) * (j + 1), prod); n       } n     } n   } n   cout << prod; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = (int)(1e2 + 5); n int n, m, k; n int grid[N][N]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n >> m >> k; n   for (int(i) = (1); (i) <= (n); (i)++) n     for (int(j) = (1); (j) <= (m); (j)++) cin >> grid[i][j]; n   int score = 0, updates = 0; n   for (int(j) = (1); (j) <= (m); (j)++) { n     int col_score = 0; n     int col_update = 0; n     int update = 0; n     for (int(i) = (1); (i) <= (n); (i)++) { n       if (i - 1 >= 1) update += grid[i - 1][j]; n       if (grid[i][j] == 1) { n         int temp_score = 0; n         for (int q = i; q < i + k && q <= n; q++) temp_score += grid[q][j]; n         if (temp_score > col_score) { n           col_score = temp_score; n           col_update = update; n         } n       } n     } n     score += col_score; n     updates += col_update; n   } n   cout << score <<     << updates; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n template <class c> n struct rge { n   c b, e; n }; n template <class c> n rge<c> range(c i, c j) { n   return rge<c>{i, j}; n } n template <class c> n auto dud(c* x) -> decltype(cerr << *x, 0); n template <class c> n char dud(...); n struct debug { n   template <class c> n   debug& operator<<(const c&) { n     return *this; n   } n }; n const long long MOD = 1e9 + 7; n const long long N = 1e6 + 10; n const long long INF = 1e18 + 10; n bool isPrime(long long x) { n   if (x <= 1) return false; n   for (long long i = 2; i * i <= x; i++) { n     if (x % i == 0) return false; n   } n   return true; n } n vector<bool> prime(N, true); n vector<long long> primes; n void seive() { n   prime[0] = prime[1] = false; n   for (long long i = 2; i * i <= N; i++) { n     if (prime[i]) { n       for (long long j = i + i; j < N; j += i) prime[j] = false; n     } n   } n   for (long long i = 0; i < N; i++) { n     if (prime[i]) { n       primes.emplace_back(i); n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   seive(); n   long long n; n   cin >> n; n   if (isPrime(n)) { n     cout << 1 << endl; n     cout << n << endl; n     return 0; n   } n   long long cur = n; n   while (cur--) { n     if (isPrime(cur)) { n       debug() <<   [  n               <<  cur  n                   :   n               << (cur) <<  ]  ; n       if (cur + 2 == n) { n         cout << 2 << endl; n         cout << 2 <<     << cur << endl; n         return 0; n       } n       int target = n - cur; n       debug() <<   [  n               <<  target  n                   :   n               << (target) <<  ]  ; n       int L = 0, R = (int)primes.size() - 1; n       while (L <= R) { n         if (primes[L] + primes[R] == target) { n           cout << 3 << endl; n           cout << primes[L] <<     << primes[R] <<     << cur << endl; n           return 0; n         } else if (primes[L] + primes[R] > target) n           R--; n         else { n           debug() <<   [  n                   <<  L  n                       :   n                   << (L) n                   <<  ]   n                        [  n                   <<  R  n                       :   n                   << (R) <<  ]  ; n           debug() <<   [  n                   <<  primes[L]  n                       :   n                   << (primes[L]) n                   <<  ]   n                        [  n                   <<  primes[R]  n                       :   n                   << (primes[R]) <<  ]  ; n           L++; n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   long long n; n   cin >> n; n   char s; n   long long cnt = 0; n   while (cin >> s) { n     cnt += s ==  8 ; n   } n   long long ans = 0; n   for (long long i = 0; i <= cnt; ++i) { n     if (min(i, (n - i) / 10) > ans) ans = min(i, (n - i) / 10); n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = (int)1e9; n const int EPS = 1e-8; n const int MOD = 1000000007; n const long double PI = 3.14159265359; n const int dx4[4] = {0, 1, 0, -1}; n const int dy4[4] = {-1, 0, 1, 0}; n const int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0}; n const int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1}; n inline bool grid_inside(int x, int y, int n, int m) { n   return x >= 1 && x <= n && y >= 1 && y <= m; n } n bool inrange(int a, int b, int a1, int b1) { n   if (a >= a1 && a <= b1) return true; n   if (b >= a1 && b <= b1) return true; n   if (a1 >= a && a1 <= b) return true; n   if (b1 >= a && b1 <= b) return true; n   return false; n } n template <typename T> n T lcm(T a, T b) { n   return (a * b) / __gcd(a, b); n } n template <typename ForwardIterator, typename T> n T first_val(ForwardIterator first, ForwardIterator last, T value) { n   auto it = std::lower_bound(first, last, value); n   return (it != last) ? (it - first) : -1; n } n template <typename ForwardIterator, typename T> n T last_val(ForwardIterator first, ForwardIterator last, T value) { n   auto it = std::upper_bound(first, last, value); n   return ((it != last) ? ((it - first) - 1) : -1); n } n template <typename T> n T Dis(T x1, T y1, T x2, T y2) { n   return sqrt(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2))); n } n template <typename T> n T Angle(T x1, T y1, T x2, T y2) { n   return atan((double)(y1 - y2) / (double)(x1 - x2)); n } n int Set(int N, int pos) { return N = N | (1 << pos); } n int Reset(int N, int pos) { return N = N & ~(1 << pos); } n bool Check(int N, int pos) { return (bool)(N & (1 << pos)); } n template <class T, class X> n inline T togglebit(T a, X i) { n   T t = 1; n   return (a ^ (t << i)); n } n bool compare(const pair<int, int> &i, const pair<int, int> &j) { n   return i.first < j.first; n } n int doubleCompare(double x, double y) { n   if (fabs(x - y) <= EPS) return 0; n   if (x < y) return -1; n   return 1; n } n int LSOne(long long int n) { return log2(n & -n) + 1; } n int rangeClear(int n, int i, int j) { n   int ones = ~0; n   int a = ones << (j + 1); n   int b = (i << 2) - 1; n   int mask = a | b; n   int ans = n & mask; n   return ans; n } n int countSetBits(int n) { n   int count = 0; n   while (n > 0) { n     count += (n & 1); n     n = n >> 1; n   } n   return count; n } n int getPosBit(int n, int k) { return (n & (1 << k)) != 0 ? 1 : 0; } n void setPosBit(int &n, int k) { n = n | (1 << k); } n long long int fast_power(long long int a, long long int x) { n   if (x == 0) n     return 1; n   else if (x == 1) n     return a; n   else { n     long long int R = fast_power(a, x >> 1); n     if (!(x & 1)) n       return R * R; n     else n       return R * a * R; n   } n } n long long int fast_power_unlocked(long long int a, long long int n, n                                   long long int mod) { n   long long int res = 1; n   while (n > 0) { n     if (n & 1) { n       res = (res * a) % mod; n     } n     a = (a * a) % mod; n     n = n >> 1; n   } n   return res; n } n long long int modInverse(long long int A, long long int M) { n   return fast_power_unlocked(A, M - 2, M); n } n bool checkPrime(long long int n) { n   int cnt = 0; n   for (long long int i = 2; i * i <= n; i++) { n     if (n % i == 0) { n       if (n / i == i) n         cnt++; n       else n         cnt += 2; n     } n   } n   if (cnt == 2) n     return true; n   else n     return false; n } n const int MAX_N = 1001; n void solve() { n   int n, x, m; n   cin >> n >> x >> m; n   pair<int, int> v; n   v = make_pair(x, x); n   int k = 1; n   while (m--) { n     int a, b; n     cin >> a >> b; n     if (inrange(a, b, v.first, v.second)) { n       if (a < v.first) v.first = a; n       if (b > v.second) v.second = b; n     } n   } n   cout << v.second - v.first + 1; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   ; n   for (auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); n        blockTime.second; n        fprintf(stderr,  %s: %ld ms n ,  Time Taken , n                chrono::duration_cast<chrono::milliseconds>( n                    chrono::high_resolution_clock::now() - blockTime.first) n                    .count()), n             fflush(stderr), blockTime.second = false) { n     int t; n     cin >> t; n     for (int i = 0; i < t; ++i) { n       solve(); n       cout <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0), cout.tie(0); n   long long n, m, l; n   cin >> n >> m >> l; n   vector<long long> a(n); n   vector<pair<long long, long long>> lr(n); n   long long ans = 0, old = -1000; n   long long flag = 0; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i] > l) { n       if (flag == 0) ans++; n       flag = 1; n     } n     if (a[i] <= l && flag == 1) { n       flag = 0; n     } n   } n   while (m--) { n     long long tp; n     cin >> tp; n     if (tp == 0) { n       cout << ans << endl; n     } else { n       long long p, d; n       cin >> p >> d; n       if (n > 1) { n         if (a[p - 1] <= l && a[p - 1] + d > l) { n           if (p - 1 > 0 && p - 1 < n - 1) { n             if (a[p - 2] > l && a[p] > l) n               ans--; n             else if (a[p - 2] <= l && a[p] > l) n               ans += 0; n             else if (a[p - 2] > l && a[p] <= l) n               ans += 0; n             else n               ans++; n           } else if (p - 1 == 0) { n             if (a[p] > l) n               ans += 0; n             else if (a[p] <= l) n               ans++; n           } else { n             if (a[p - 2] > l) n               ans += 0; n             else if (a[p - 2] <= l) n               ans++; n           } n         } n       } else { n         if (a[p - 1] <= l && a[p - 1] + d > l) ans++; n       } n       a[p - 1] += d; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:200000000 ) n using namespace std; n char a[105][105]; n int n, m; n bool u[105][105]; n int main() { n   memset(u, false, sizeof(u)); n   scanf( %d %d n , &n, &m); n   for (int i = 0; i < n; i++, scanf(  n )) n     for (int j = 0; j < m; j++) scanf( %c , &a[i][j]); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       for (int ix = 0; ix < m; ix++) n         if (ix != j && a[i][ix] == a[i][j]) u[i][ix] = u[i][j] = true; n       for (int ix = 0; ix < n; ix++) n         if (ix != i && a[ix][j] == a[i][j]) u[ix][j] = u[i][j] = true; n     } n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       if (!u[i][j]) putchar(a[i][j]); n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int v[1005][1005]; n long long c[1005][1005], sum[1005][1005], t[1005][1005]; n int main() { n   int n = 0, m = 0, a = 0, b = 0; n   scanf( %d%d%d%d , &n, &m, &a, &b); n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) { n       scanf( %d , &v[i][j]); n       sum[i][j] = sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1] + n                   (long long)v[i][j]; n     } n   } n   vector<pair<long long, pair<int, int>>> res; n   set<pair<long long, pair<int, int>>> cost; n   for (int i = 1; i <= n; ++i) { n     deque<long long> q; n     for (int j = m; j >= 1; --j) { n       while (!q.empty() && v[i][q.back()] > v[i][j]) { n         q.pop_back(); n       } n       q.push_back(j); n       while (q.front() >= j + b) { n         q.pop_front(); n       } n       t[i][j] = v[i][q.front()]; n     } n   } n   for (int i = 1; i <= m; ++i) { n     deque<long long> q; n     for (int j = n; j >= 1; --j) { n       while (!q.empty() && t[q.back()][i] > t[j][i]) { n         q.pop_back(); n       } n       q.push_back(j); n       while (q.front() >= j + a) { n         q.pop_front(); n       } n       c[j][i] = t[q.front()][i]; n     } n   } n   for (int i = 1; i + a - 1 <= n; ++i) { n     for (int j = 1; j + b - 1 <= m; ++j) { n       long long tmp = sum[i + a - 1][j + b - 1] - sum[i + a - 1][j - 1] - n                       sum[i - 1][j + b - 1] + sum[i - 1][j - 1] - n                       (long long)a * b * c[i][j]; n       cost.insert(make_pair(tmp, make_pair(i, j))); n     } n   } n   auto it = cost.begin(); n   while (it != cost.end()) { n     while (it != cost.end() && c[it->second.first][it->second.second] == -1) { n       ++it; n     } n     if (it == cost.end()) { n       break; n     } n     res.push_back(*it); n     int row = it->second.first, col = it->second.second; n     int rMin = max(row - a + 1, 0), cMin = max(col - b + 1, 0), n         rMax = min(row + a - 1, n - (a - 1)), n         cMax = min(col + b - 1, m - (b - 1)); n     for (int i = rMin; i <= rMax; ++i) { n       for (int j = cMin; j <= cMax; ++j) { n         c[i][j] = -1; n       } n     } n   } n   printf( %d n , res.size()); n   for (int i = 0; i < res.size(); ++i) { n     printf( %d %d %I64d n , res[i].second.first, res[i].second.second, n            res[i].first); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string a, p, s; n bool suff[2002][2002]; n bool pref[2002][2002]; n long long int hash1[2002][2002]; n long long int hash2[2002][2002]; n set<pair<int, int> > ans; n int main() { n   cin >> a >> p >> s; n   long long int mod1 = 1000000007; n   long long int mod2 = 1000003; n   for (int i = 0; i < a.size(); i++) { n     pref[i][p.size() - 1] = (a[i] == p[p.size() - 1]); n     suff[i][s.size() - 1] = (a[i] == s[s.size() - 1]); n   } n   for (int i = p.size() - 2; i >= 0; i--) n     for (int j = 0; j < a.size() - 1; j++) n       pref[j][i] = pref[j + 1][i + 1] && (a[j] == p[i]); n   for (int i = s.size() - 2; i >= 0; i--) n     for (int j = 0; j < a.size() - 1; j++) n       suff[j][i] = suff[j + 1][i + 1] && (a[j] == s[i]); n   int l = max(p.size(), s.size()); n   for (int i = 0; i < a.size(); i++) { n     hash1[i][i] = a[i] -  a ; n     hash2[i][i] = 0; n     for (int j = i + 1; j < a.size(); j++) { n       hash1[i][j] = (hash1[i][j - 1] * 26 + a[j] -  a ) % mod1; n       hash2[i][j] = j - i; n     } n   } n   for (int i = 0; i < a.size(); i++) n     for (int j = i + l - 1; j < a.size(); j++) n       if (pref[i][0] && suff[j - s.size() + 1][0]) n         ans.insert(make_pair(hash1[i][j], hash2[i][j])); n   cout << ans.size() << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char str[100003]; n struct Node { n   int val; n   int val2; n   Node* pt[26]; n } node[100003]; n int cnt; n int mex(Node* node) { n   if (node->val != -1) return node->val; n   int f[30] = {}; n   for (int i = 0; i < 26; ++i) n     if (node->pt[i]) f[mex(node->pt[i])] = 1; n   for (int i = 0; i < 30; ++i) n     if (f[i] == 0) return node->val = i; n } n int mex2(Node* node) { n   if (node->val2 != -1) return node->val2; n   int f[30] = {}; n   int flag = 0; n   for (int i = 0; i < 26; ++i) n     if (node->pt[i]) { n       f[mex2(node->pt[i])] = 1; n       flag = 1; n     } n   if (!flag) return node->val2 = 1; n   for (int i = 0; i < 30; ++i) n     if (f[i] == 0) return node->val2 = i; n } n int main() { n   cnt = 27; n   int N, K; n   cin >> N >> K; n   for (int i = 0; i < 100003; ++i) node[i].val = node[i].val2 = -1; n   for (int i = 0; i < N; ++i) { n     cin >> str; n     Node* now = node; n     now->pt[str[0] -  a ] = node + str[0] -  a  + 1; n     for (int j = 0; str[j]; ++j) n       if (now->pt[str[j] -  a ]) n         now = now->pt[str[j] -  a ]; n       else n         now = now->pt[str[j] -  a ] = node + cnt++; n   } n   if (mex(node) == 0) n     cout <<  Second  << endl; n   else if (K % 2 == 1 || mex2(node)) n     cout <<  First  << endl; n   else n     cout <<  Second  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct pairvar { n   int a; n   int b; n   int c; n   int max; n }; n bool isPrime(long long x) { n   if (x == 1) { n     return false; n   } n   long long a = (long long)x; n   for (int i = 2; i <= (long long)sqrt((double)a); i++) { n     if (a % i == 0) { n       return false; n     } n   } n   return true; n } n int gcd(int a, int b) { n   if (b == 0) { n     return a; n   } n   return gcd(b, a % b); n } n long long factorial(long long x) { n   long long sum = 1; n   for (long long i = 1; i <= x; i++) { n     sum *= i; n   } n   return sum; n } n string tostr(int x) { n   string s =   ; n   while (x != 0) { n     s += (x % 10) +  0 ; n     x /= 10; n   } n   string t =   ; n   for (int i = s.length() - 1; i >= 0; i--) { n     t += s[i]; n   } n   return t; n } n bool cmp(const pairvar &a, const pairvar &b) { n   if (a.a == b.a) return a.b < b.b; n   return a.a < b.a; n } n int calc(int a, int b) { return (a * b) / gcd(a, b); } n int main() { n   string s; n   cin >> s; n   int ans = 1; n   int k = s.size() - 1; n   int j = 1; n   for (int i = s.size() - 1; i >= 0; i--) { n     if (s[i] ==  0 ) { n       k--; n       j++; n     } else { n       if (k > j) { n         ans++; n         k--; n         j = 1; n       } else if (k == j) { n         if (s[0] >= s[i]) { n           j = 1; n           k--; n           ans++; n         } else { n           j++; n           k--; n         } n       } n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long n, sum = 0; n   cin >> n; n   vector<long long> arr(n + 1); n   for (long long i = 1; i <= n; i++) cin >> arr[i], sum += arr[i]; n   map<pair<long long, long long>, long long> ma; n   long long m, a, b, c; n   cin >> m; n   while (m--) { n     cin >> a >> b >> c; n     if (!ma.count({a, b})) { n       if (c > 0) { n         arr[c]--; n         if (arr[c] >= 0) sum--; n       } n     } else { n       long long temp = ma[{a, b}]; n       arr[temp]++; n       if (arr[temp] > 0) sum++; n       if (c > 0) { n         arr[c]--; n         if (arr[c] >= 0) sum--; n       } else { n         ma.erase(ma.find({a, b})); n       } n     } n     if (c != 0) ma[{a, b}] = c; n     cout << sum << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n inline int read() { n   register int x = 0; n   register char f = 1, ch = getchar(); n   for (; !isdigit(ch); ch = getchar()) n     if (ch ==  - ) f = !f; n   for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^  0 ); n   return f ? x : -x; n } n int n, d[250005], X, vis[250005]; n long long sum; n std ::vector<std ::pair<int, int> > E[250005]; n std ::pair<int, int> D[250005]; n void addedge(int u, int v, int w) { n   E[u].push_back(std ::make_pair(v, w)), ++d[u]; n } n bool cmp(std ::pair<int, int> x, std ::pair<int, int> y) { n   return d[x.first] > d[y.first]; n } n struct Normal_Heap { n   std ::vector<long long> a; n   void push(long long x) { n     a.push_back(x), std ::push_heap(a.begin(), a.end()); n   } n   long long top() { return a[0]; } n   void pop() { std ::pop_heap(a.begin(), a.end()), a.pop_back(); } n   long long popn() { n     long long x; n     return std ::pop_heap(a.begin(), a.end()), x = a[a.size() - 1], n                                                a.pop_back(), x; n   } n   int size() { return a.size(); } n }; n struct Erase_Heap { n   Normal_Heap a, b; n   int sz; n   long long sum; n   void push(long long x) { a.push(x), ++sz, sum += x; } n   void erase(long long x) { b.push(x), --sz, sum -= x; } n   void pre() { n     while (a.size() && b.size() && a.top() == b.top()) a.pop(), b.pop(); n   } n   long long top() { return pre(), a.top(); } n   void pop() { pre(), --sz, sum -= a.top(), a.pop(); } n   int size() { return sz; } n } H[250005]; n void die(int u) { n   for (auto to : E[u]) { n     register int v = to.first, w = to.second; n     if (d[v] <= X) break; n     H[v].push(w); n   } n } n long long dp[250005][2]; n std ::vector<long long> tmp, del; n void dfs(int u, int fa = 0) { n   vis[u] = X; n   int num = d[u] - X; n   long long res = 0; n   for (; H[u].size() > num; H[u].pop()) n     ; n   for (auto to : E[u]) { n     register int v = to.first, w = to.second; n     if (v == fa) continue; n     if (d[v] <= X) break; n     dfs(v, u); n   } n   tmp.clear(), del.clear(); n   for (auto to : E[u]) { n     register int v = to.first, w = to.second; n     if (v == fa) continue; n     if (d[v] <= X) break; n     long long x = dp[v][1] + w - dp[v][0]; n     if (x <= 0) { n       --num, res += dp[v][1] + w; n       continue; n     } n     res += dp[v][0], H[u].push(x), del.push_back(x); n   } n   for (; H[u].size() && H[u].size() > num; H[u].pop()) n     tmp.push_back(H[u].top()); n   dp[u][0] = res + H[u].sum; n   for (; H[u].size() && H[u].size() > num - 1; H[u].pop()) n     tmp.push_back(H[u].top()); n   dp[u][1] = res + H[u].sum; n   for (auto i : tmp) H[u].push(i); n   for (auto i : del) H[u].erase(i); n } n int main() { n   n = read(); n   for (register int i = 1, u, v, w; i < n; ++i) n     u = read(), v = read(), w = read(), addedge(u, v, w), addedge(v, u, w), n     sum += w; n   printf( %lld , sum); n   for (register int i = 1; i <= n; ++i) n     D[i] = std ::make_pair(d[i], i), std ::sort(E[i].begin(), E[i].end(), cmp); n   std ::sort(D + 1, D + 1 + n); n   register int i = 1; n   for (X = 1; X < n; ++X) { n     while (i <= n && D[i].first == X) die(D[i].second), ++i; n     long long ans = 0; n     for (register int j = i; j <= n; ++j) { n       register int v = D[j].second; n       if (vis[v] == X) continue; n       dfs(v), ans += dp[v][0]; n     } n     printf(  %lld , ans); n   } n   putchar(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n const bool testing = false; n pair<long long, long long> d[100000]; n int nf[100000], nb[100000]; n pair<long long, long long> getmid(int a, int b) { n   long long y = d[b].second - d[a].second; n   long long x = d[b].first - d[a].first; n   pair<long long, long long> res = n       make_pair(-y + x * x + 2 * x * d[a].first, 2 * x); n   return res; n } n void program() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     long long t1, t2; n     cin >> t1 >> t2; n     d[i] = make_pair(t1, t2); n   } n   std::sort(d, d + n); n   int start = 0; n   while (start + 1 < n && d[start + 1].first == d[start].first) start++; n   { n     nb[start] = -1; n     int prev = start; n     while (prev < n) { n       int t = prev + 1; n       while (t + 1 < n && d[t + 1].first == d[t].first) t++; n       if (t < n) nb[t] = prev; n       nf[prev] = t; n       prev = t; n     } n   } n   { n     int t1 = start; n     while (true) { n       int t2 = nf[t1]; n       if (t2 == n) break; n       int t3 = nf[t2]; n       if (t3 == n) break; n       pair<long long, long long> A1 = getmid(t1, t2); n       pair<long long, long long> A2 = getmid(t1, t3); n       if (A2.first * A1.second <= A1.first * A2.second) { n         nf[t1] = t3; n         nb[t3] = t1; n         if (nb[t1] != -1) t1 = nb[t1]; n       } else n         t1 = nf[t1]; n     } n   } n   long long res = 0; n   { n     int t = start; n     while (nf[t] != n) { n       res++; n       t = nf[t]; n     } n   } n   cout << res; n } n int main() { n   if (!testing) { n     program(); n     return 0; n   } n   FILE* fin = NULL; n   fin = fopen( in.txt ,  w+ ); n   fprintf(fin,   n3 n-1 0 n0 2 n1 0 n ); n   fclose(fin); n   freopen( in.txt ,  r , stdin); n   printf( test case(1) => expected :  n ); n   printf( 2 ); n   printf( test case(1) => found    :  n ); n   program(); n   fin = fopen( in.txt ,  w+ ); n   fprintf(fin,   n5 n1 0 n1 -1 n0 -1 n-1 0 n-1 -1 n ); n   fclose(fin); n   freopen( in.txt ,  r , stdin); n   printf( test case(2) => expected :  n ); n   printf( 1 ); n   printf( test case(2) => found    :  n ); n   program(); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n template <class T> n T abs(T x) { n   if (x < 0) return -x; n   return x; n } n template <class T> n T sqr(T a) { n   return a * a; n } n const double pi = acos(-1.0); n const double eps = 1e-8; n int a[100010]; n int a1[100010]; n int a2[100010]; n int b; n int ar[100010]; n int flag[100010]; n int main() { n   int i, n, m, k; n   while (2 == scanf( %d%d , &n, &m)) { n     int cnt = 0; n     for (i = 1; i <= n + m; i++) { n       if (i <= n) n         scanf( %d , &a1[i]); n       else n         scanf( %d , &a2[i - n]); n     } n     k = 0; n     for (i = 1; i <= n + m; i++) { n       scanf( %d , &b); n       if (b == 1) { n         cnt++; n         if (i <= n) n           ar[cnt] = a1[i]; n         else n           ar[cnt] = a2[i - n]; n       } else { n         ++k; n         if (i <= n) n           a[k] = a1[i]; n         else n           a[k] = a2[i - n]; n       } n     } n     k = 1; n     for (i = 1; i <= n; i++) { n       if (k + 1 <= cnt) { n         if (abs(a[i] - ar[k]) <= abs(a[i] - ar[k + 1])) n           flag[k]++; n         else { n           k++; n           i--; n         } n       } else n         flag[k]++; n     } n     for (i = 1; i <= cnt; i++) printf( %d  , flag[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n ifstream in; n ofstream out; n const long long kk = 1000; n const long long MOD = 10e9 + 7; n long long a, b, x, y; n long long GCD(long long n, unsigned long long m) { n   while (n != 0 && m != 0) { n     if (n > m) { n       n %= m; n     } else { n       m %= n; n     } n   } n   return (n + m); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin >> a >> b >> x >> y; n   long long x1, y1; n   long long k = GCD(x, y); n   x /= k; n   y /= k; n   cout << min(a / x, b / y); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 200000 + 5; n int n, ex, ey; n char s[MAXN]; n struct node { n   int x, y; n   node() {} n   node(int _x, int _y) : x(_x), y(_y) {} n } p[MAXN]; n bool OK(int t) { n   for (int i = 0; i + t <= n; i++) { n     int px = p[i].x - p[0].x + p[n].x - p[i + t].x; n     int py = p[i].y - p[0].y + p[n].y - p[i + t].y; n     int tx = ex - px; n     int ty = ey - py; n     if (abs(tx) + abs(ty) <= t) { n       return true; n     } n   } n   return false; n } n int main() { n   while (~scanf( %d , &n)) { n     scanf( %s , s + 1); n     scanf( %d%d , &ex, &ey); n     if ((n - abs(ex) - abs(ey)) < 0) { n       printf( -1 n ); n       continue; n     } n     if ((n - abs(ex) - abs(ey)) & 1) { n       printf( -1 n ); n       continue; n     } n     p[0] = node(0, 0); n     for (int i = 1; i <= n; i++) { n       if (s[i] ==  U ) { n         p[i] = node(p[i - 1].x, p[i - 1].y + 1); n       } else if (s[i] ==  D ) { n         p[i] = node(p[i - 1].x, p[i - 1].y - 1); n       } else if (s[i] ==  L ) { n         p[i] = node(p[i - 1].x - 1, p[i - 1].y); n       } else if (s[i] ==  R ) { n         p[i] = node(p[i - 1].x + 1, p[i - 1].y); n       } n     } n     int l = 0, r = n; n     while (l <= r) { n       int mid = (l + r) >> 1; n       if (OK(mid)) { n         r = mid - 1; n       } else { n         l = mid + 1; n       } n     } n     printf( %d n , r + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   int mod = 1e9 + 7; n   cin >> s; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] ==  w  || s[i] ==  m ) { n       cout << 0; n       return 0; n     } n   } n   int a, b = 1, c = 0; n   for (int i = 0; i < s.length(); i++) { n     if (s[i] == s[i - 1] && (s[i] ==  n  || s[i] ==  u )) { n       a = (b + c) % mod; n     } else n       a = b; n     c = b; n     b = a; n   } n   cout << a; n } n


#include <bits/stdc++.h> n using namespace std; n long long mulMod(long long a, long long b, long long m = 1000000007) { n   long long x = 0, y = a % m; n   while (b > 0) { n     if (b % 2 == 1) x = (x + y) % m; n     y = (y * 2) % m; n     b /= 2; n   } n   return x % m; n } n long long expMod(long long b, long long e, long long m = 1000000007) { n   if (!e) return 1; n   long long q = expMod(b, e / 2, m); n   q = mulMod(q, q, m); n   return e % 2 ? mulMod(b, q, m) : q; n } n long long invFact[20], fact[20]; n long long inverso(long long x) { return expMod(x, 1000000007 - 2); } n void pre() { n   fact[0] = 1; n   for (int i = (1); i < (20 - 2); i++) fact[i] = (fact[i - 1] * i) % 1000000007; n   invFact[20 - 3] = inverso(fact[20 - 3]); n   for (int i = 20 - 3 - 1; i >= 0; i--) n     invFact[i] = (invFact[i + 1] * (i + 1)) % 1000000007; n   return; n } n long long comb(long long nn, long long k) { n   if (k < 0 || nn < k) return 0; n   return (fact[nn] * invFact[k] % 1000000007) * invFact[nn - k] % 1000000007; n } n int n; n long long win[15][15]; n long long get(int mask1, int mask2) { n   long long ret = 1; n   for (int i = (0); i < (n); i++) { n     if ((mask1 >> i) & 1) { n       for (int j = (0); j < (n); j++) { n         if ((mask2 >> j) & 1) { n           ret = ((ret * win[i][j] % 1000000007) + 1000000007) % 1000000007; n           assert(ret >= 0); n         } n       } n     } n   } n   return ret; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> n; n   vector<long long> a(n); n   for (int i = (0); i < (n); i++) cin >> a[i]; n   for (int i = (0); i < (n); i++) n     for (int j = (0); j < (n); j++) n       win[i][j] = (((a[i] * inverso(a[i] + a[j])) % 1000000007) + 1000000007) % n                   1000000007; n   vector<long long> proba(1 << n, 1); n   long long rta = 0; n   for (int mask = 1; mask < (1 << n); mask++) { n     for (int submask = mask & (mask - 1); submask; n          submask = (submask - 1) & mask) { n       proba[mask] -= proba[submask] * get(submask, mask ^ submask); n       proba[mask] = ((proba[mask] % 1000000007) + 1000000007) % 1000000007; n       assert(proba[mask] >= 0); n     } n     rta += ((__builtin_popcount(mask) * proba[mask]) % 1000000007 * n             get(mask, ((1 << n) - 1) ^ mask)) % n            1000000007; n     rta = ((rta % 1000000007) + 1000000007) % 1000000007; n   } n   cout << rta <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Maxn = int(1e5); n inline int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n struct Node { n   int to, nxt, w; n } Edge[Maxn * 2 + 5]; n int tot, Head[Maxn + 5]; n inline void Addedge(int x, int y, int z) { n   Edge[++tot] = (Node){y, Head[x], z}; n   Head[x] = tot; n } n long long ans; n int n, l, w, rt, sum; n int siz[Maxn + 5], maxs[Maxn + 5], vis[Maxn + 5]; n int dis1[Maxn + 5], dis2[Maxn + 5], cur, allcur; n struct Point { n   int a, b, c; n } tmp[Maxn + 5], all[Maxn + 5]; n inline int cmp1(Point x, Point y) { return x.a < y.a; } n inline int cmp2(Point x, Point y) { return x.a > y.a; } n int t[Maxn + 5], top; n inline void Add(int x, int y) { n   while (x <= l) t[x] += y, x += (x & -x); n } n inline int Query(int x) { n   int res = 0; n   while (x > 0) res += t[x], x -= (x & -x); n   return res; n } n inline void dfs1(int x, int f) { n   siz[x] = 1, maxs[x] = 0; n   for (register int i = Head[x]; i; i = Edge[i].nxt) { n     int y = Edge[i].to; n     if (y == f || vis[y]) continue; n     dfs1(y, x); n     siz[x] += siz[y]; n     maxs[x] = max(maxs[x], siz[y]); n   } n   maxs[x] = max(maxs[x], sum - siz[x]); n   rt = maxs[x] < maxs[rt] ? x : rt; n } n inline void dfs2(int x, int f, int grand) { n   tmp[++cur] = (Point){dis1[x], dis2[x], grand}; n   for (register int i = Head[x]; i; i = Edge[i].nxt) { n     int y = Edge[i].to; n     if (y == f || vis[y]) continue; n     dis1[y] = dis1[x] + Edge[i].w; n     dis2[y] = dis2[x] + 1; n     dfs2(y, x, grand); n   } n } n inline void Count(int x) { n   int it = 1; n   allcur = 0; n   for (register int i = Head[x]; i; i = Edge[i].nxt) { n     int y = Edge[i].to; n     if (vis[y]) continue; n     dis1[y] = Edge[i].w, dis2[y] = 1; n     cur = 0, dfs2(y, x, y); n     for (register int j = 1; j <= cur; ++j) n       if (tmp[j].a <= w) all[++allcur] = tmp[j]; n   } n   sort(all + 1, all + allcur + 1, cmp1); n   for (register int i = Head[x]; i; i = Edge[i].nxt) { n     int y = Edge[i].to; n     if (vis[y]) continue; n     dis1[y] = Edge[i].w, dis2[y] = 1; n     it = 1, cur = 0, dfs2(y, x, y); n     sort(tmp + 1, tmp + cur + 1, cmp2); n     for (register int j = 1; j <= cur; ++j) { n       while (it <= allcur && tmp[j].a + all[it].a <= w) { n         if (all[it].c < y) Add(all[it].b, 1); n         it++; n       } n       if (tmp[j].a <= w && tmp[j].b <= l) ans++; n       if (tmp[j].b < l) ans += Query(l - tmp[j].b); n     } n     for (register int j = 1; j < it; ++j) n       if (all[j].c < y) Add(all[j].b, -1); n   } n } n inline void Divide(int x) { n   vis[x] = 1; n   Count(x); n   for (register int i = Head[x]; i; i = Edge[i].nxt) { n     int y = Edge[i].to; n     if (vis[y]) continue; n     rt = 0, maxs[0] = sum = siz[y]; n     dfs1(y, 0), dfs1(rt, 0); n     Divide(rt); n   } n } n int main() { n   n = read(), l = read(), w = read(); n   for (register int i = 1; i < n; ++i) { n     int a = read(), b = read(); n     Addedge(i + 1, a, b), Addedge(a, i + 1, b); n   } n   maxs[0] = sum = n; n   dfs1(1, 0), dfs1(rt, 0); n   Divide(rt); n   printf( %I64d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void splitstr(const string &s, vector<T> &out) { n   istringstream in(s); n   out.clear(); n   copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out)); n } n template <class T> n T read_value(string s) { n   T result; n   istringstream sin(s); n   sin >> result; n   return result; n } n string read_line() { n   string ret_val; n   getline(std::cin, ret_val); n   return ret_val; n } n template <class T> n void init_array(T *arr, int size, T value) { n   for (int i = 0; i < size; i++) arr[i] = value; n } n template <class T> n inline T gcd(T a, T b) { n   return (!a) ? b : gcd(b % a, a); n } n template <class T> n inline T mod(T a, T p) { n   a %= p; n   return (a < 0) ? a + p : a; n } n template <class T> n inline int num_bits(T n) { n   return (!n) ? 0 : 1 + numbits(n & (n - 1)); n } n template <class T> n inline T inverse(T a, T m) { n   a = mod<T>(a, m); n   return (a == 1) ? 1 : mod((1 - m * inverse(m % a, a)) / a, m); n } n template <class T> n inline bool is_prime(T a) { n   T lim = (T)sqrt((double)a); n   for (T i = 2; i <= T(lim + 1E-9); i++) n     if (a % i == 0) return false; n   return true; n } n template <class T> n inline T power(T a, T p, T mod) { n   if (!p) return 1; n   T temp = power(a, p >> 1, mod); n   temp = (temp * temp) % mod; n   if (p & 1) temp = (temp * a) % mod; n   return temp; n } n void get_primes(int start, int end, vector<int> &vi) { n   int *p = new int[end + 1]; n   init_array<int>(p, end + 1, 0); n   p[1] = 1; n   for (int i = 2; i <= end; i++) { n     if (!p[i]) { n       if (i >= start) vi.push_back(i); n       for (int j = 2 * i; j <= end; j += i) p[j] = 1; n     } n   } n   delete[] p; n } n bool dfs(int current, int final, int total, int *visited, int **edges, n          bool flow) { n   if (current == final) return true; n   if (visited[current]) return false; n   visited[current] = true; n   for (int i = 0; i < total; i++) n     if (edges[current][i] && dfs(i, final, total, visited, edges, flow)) { n       if (flow) { n         edges[current][i]--; n         edges[i][current]++; n       } n       return true; n     } n   return false; n } n int flow(int in, int out, int total, int **edges) { n   int result = 0; n   int *visited = new int[total]; n   while (init_array<int>(visited, total, 0), n          dfs(in, out, total, visited, edges, true)) n     result++; n   delete[] visited; n   return result; n } n void create_set(int x, int *P, int *rank) { n   P[x] = x; n   rank[x] = 0; n } n int find_set(int x, int *P) { n   if (x != P[x]) P[x] = find_set(P[x], P); n   return P[x]; n } n bool merge_sets(int x, int y, int *P, int *rank) { n   int Px = find_set(x, P); n   int Py = find_set(y, P); n   if (Px == Py) return false; n   if (rank[Px] > rank[Py]) n     P[Py] = Px; n   else n     P[Px] = Py; n   if (rank[Px] == rank[Py]) rank[Py]++; n   return true; n } n template <typename T> n int read_cum_freq(int index, T *tree) { n   int sum = 0; n   while (index) { n     sum += tree[index]; n     index -= (index & -index); n   } n   return sum; n } n template <typename T> n void upd_freq(int index, int mxIndex, int value, T *tree) { n   while (index <= mxIndex) { n     tree[index] += value; n     index += (index & -index); n   } n } n template <typename T> n int read_freq(int index, T *tree) { n   return read_cum_freq(index, tree) - read_cum_freq(index - 1, tree); n } n void build_failure_function(const string &str, int *temp_arr) { n   temp_arr[0] = temp_arr[1] = 0; n   for (int i = 2; i <= ((int)(str).size()); i++) { n     temp_arr[i] = -1; n     for (int ind = temp_arr[i - 1]; temp_arr[i] == -1; ind = temp_arr[ind]) { n       if (str[ind] == str[i - 1]) { n         temp_arr[i] = ind + 1; n       } else if (ind == 0) { n         temp_arr[i] = 0; n       } n     } n   } n } n void KMP(const string &text, const string &pattern, int *res) { n   int *temp_arr = new int[((int)(pattern).size()) + 1]; n   build_failure_function(pattern, temp_arr); n   int i = 0; n   int ind = 0; n   while (i < ((int)(text).size())) { n     if (text[i] == pattern[ind]) { n       res[i] = ++ind; n       if (res[i] == ((int)(pattern).size())) { n         ind = temp_arr[ind]; n       } n       i++; n     } else if (ind == 0) { n       res[i++] = 0; n     } else { n       ind = temp_arr[ind]; n     } n   } n   delete[] temp_arr; n } n void setup(int value, string name) { n   string name_in = name +  .in ; n   string name_out = name +  .out ; n   freopen(name_in.c_str(),  r , stdin); n   if (value) { n     freopen(name_out.c_str(),  w , stdout); n   } n } n int main() { n   int n, m; n   std::cin >> n >> m; n   vector<string> vs(n); n   for (int i = 0; i < n; i++) std::cin >> vs[i]; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       bool flag = true; n       for (int k = 0; k < m; k++) n         if (k != j && vs[i][j] == vs[i][k]) flag = false; n       for (int k = 0; k < n; k++) n         if (k != i && vs[i][j] == vs[k][j]) flag = false; n       if (flag) std::cout << vs[i][j]; n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char first[100001], second[100001], zero[100001]; n int number1[10], number2[10]; n int just_zero() { n   char *p1 = first, *p2 = second; n   while (number1[0]--) *p1++ = *p2++ =  0 ; n   return p1 - first; n } n int summary_ten(int count) { n   int min_rez = -1; n   int t = 0; n   for (int i = 1; i < 6; i++) { n     if (number1[i] && number2[10 - i]) { n       int now_rez = min(number1[i], number2[9 - i]) + n                     min(number2[10 - i], number1[i - 1]) - n                     min(number1[i] - 1, number2[9 - i]) - n                     min(number2[10 - i] - 1, number1[i - 1]); n       if (now_rez < min_rez || min_rez == -1) { n         t = i; n         min_rez = now_rez; n       } n     } n   } n   if (t) { n     number1[t]--; n     number2[10 - t]--; n     first[count] = t +  0 ; n     second[count] = (10 - t) +  0 ; n     return count + 1; n   } n   return count; n } n int summary_nine(int count) { n   char *p1 = &first[count], *p2 = &second[count]; n   for (int i = 0; i < 10; i++) { n     int t1 = number1[9 - i]; n     int t2 = number2[i]; n     while (t1 * t2) { n       *p1++ = (9 - i) +  0 ; n       *p2++ = i +  0 ; n       t1--; n       t2--; n       number1[9 - i]--; n       number2[i]--; n     } n   } n   return p1 - first; n } n int what_else(int count) { n   char *zero_p = zero; n   while (number1[0] * number2[0]) { n     *zero_p++ =  0 ; n     number1[0]--; n     number2[0]--; n   } n   char *p1 = &first[count], *p2 = &second[count]; n   for (int i = 0; i < 10; i++) { n     while (number1[i]) { n       *p1++ = i +  0 ; n       number1[i]--; n     } n     while (number2[i]) { n       *p2++ = i +  0 ; n       number2[i]--; n     } n   } n   return p1 - first; n } n void print_screen(int count) { n   char *p1 = first + count, *p2 = second + count; n   while (true) { n     printf( %c , *p1); n     if (p1 == first) break; n     *p1--; n   } n   printf( %s n , zero); n   while (true) { n     printf( %c , *p2); n     if (p2 == second) break; n     *p2--; n   } n   printf( %s , zero); n   return; n } n void maximum_sum() { n   int count1 = summary_ten(0); n   int count2 = count1; n   if (count1) count2 = summary_nine(count1); n   int count3 = what_else(count2); n   print_screen(count3 - 1); n   return; n } n int main() { n   char str[100001]; n   scanf( %s , &str); n   char *p = &str[0]; n   while (*p) { n     number2[*p -  0 ]++; n     number1[(*p++) -  0 ]++; n   } n   maximum_sum(); n   scanf( %s , &str); n   return 0; n } n