#include <bits/stdc++.h> n using namespace std; n const int MAN = 110; n const int MAM = 60; n int dp[MAN][MAM][2]; n int INF = -100000000; n int main() { n   string str; n   int m; n   while (cin >> str >> m) { n     int len = str.size(); n     memset(dp, 0, sizeof(dp)); n     for (int i = 0; i <= len; ++i) { n       for (int j = 0; j <= m; ++j) { n         dp[i][j][0] = INF; n         dp[i][j][1] = INF; n       } n     } n     dp[0][0][0] = 0; n     dp[0][0][1] = 0; n     for (int i = 1; i <= len; ++i) { n       for (int j = 0; j <= m; ++j) { n         if (str[i - 1] ==  F ) { n           dp[i][j][0] = max(dp[i - 1][j][0] != INF ? dp[i - 1][j][0] + 1 : INF, n                             j > 0 ? dp[i - 1][j - 1][1] : INF); n           dp[i][j][1] = max(dp[i - 1][j][1] != INF ? dp[i - 1][j][1] - 1 : INF, n                             j > 0 ? dp[i - 1][j - 1][0] : INF); n         } else { n           dp[i][j][0] = n               max(dp[i - 1][j][1], (j > 0 && dp[i - 1][j - 1][0] != INF) n                                        ? dp[i - 1][j - 1][0] + 1 n                                        : INF); n           dp[i][j][1] = n               max(dp[i - 1][j][0], (j > 0 && dp[i - 1][j - 1][1] != INF) n                                        ? dp[i - 1][j - 1][1] - 1 n                                        : INF); n         } n       } n     } n     int ans = INF; n     for (int i = m; i >= 0; i -= 2) { n       ans = max(ans, max(dp[len][i][0], dp[len][i][1])); n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double EPS = 1e-6; n const int INF = (int)(INT_MAX - 100); n const long long mod = (int)(1e+9 + 7); n const int N = (int)(1e5); n int main() { n   int n, s; n   cin >> n >> s; n   char d; n   int p, k; n   map<int, int, greater<int> > C; n   map<int, int> V; n   for (int i = 0; i < n; i++) { n     cin >> d >> p >> k; n     if (d ==  B ) n       C[p] += k; n     else n       V[p] += k; n   } n   k = 0; n   vector<pair<int, int> > ans; n   for (pair<int, int> x : V) { n     if (k == s) break; n     k++; n     ans.push_back({x.first, x.second}); n   } n   reverse(ans.begin(), ans.end()); n   for (pair<int, int> x : ans) n     cout <<  S   << x.first <<     << x.second <<   n ; n   k = 0; n   for (pair<int, int> x : C) { n     if (k == s) break; n     k++; n     cout <<  B   << x.first <<     << x.second <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<string> V; n   for (int i = 0; i < 4; ++i) { n     string s; n     cin >> s; n     V.push_back(s); n   } n   bool pos = false; n   for (int r = 0; r < 3; ++r) { n     for (int c = 0; c < 3; ++c) { n       int dots = 0, nums = 0; n       dots += (V[r][c] ==  . ); n       nums += (V[r][c] !=  . ); n       dots += (V[r][c + 1] ==  . ); n       nums += (V[r][c + 1] !=  . ); n       dots += (V[r + 1][c] ==  . ); n       nums += (V[r + 1][c] !=  . ); n       dots += (V[r + 1][c + 1] ==  . ); n       nums += (V[r + 1][c + 1] !=  . ); n       if (dots >= 3 || nums >= 3) pos = true; n     } n   } n   cout << (pos ?  YES  :  NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n pair<int, int> a[1010]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     scanf( %d%d , &a[i].second, &a[i].first); n     if (a[i].first < a[i].second) swap(a[i].first, a[i].second); n   } n   sort(a, a + n); n   vector<int> ans; n   int last = INT_MIN; n   for (int i = 0; i < n; ++i) n     if (a[i].second > last) { n       ans.push_back(a[i].first); n       last = a[i].first; n     } n   printf( %d n , (int)ans.size()); n   for (int c : ans) printf( %d  , c); n   printf(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n long long cd, w, a, b, kq = 0, mod = 1e9 + 7, fact[1000001], sf[1000001], n                        p[1000001]; n void inp() { cin >> cd >> w >> a >> b; } n long long bigmod(long long hat, long long base) { n   if (hat == 0) return 1; n   long long k = bigmod(hat / 2, base); n   if (hat % 2 == 1) return k * k % mod * base % mod; n   return k * k % mod; n } n void create() { n   p[0] = fact[0] = sf[0] = 1; n   for (long long i = 1; i <= 1000000; i++) { n     fact[i] = fact[i - 1] * i % mod; n     sf[i] = bigmod(mod - 2, fact[i]); n     p[i] = p[i - 1] * w % mod; n   } n } n long long C(long long k, long long n) { n   if (k > n) return 0; n   return fact[n] * sf[k] % mod * sf[n - k] % mod; n } n long long A(long long k, long long n) { n   if (k > n) return 0; n   return C(k, n) * fact[k] % mod; n } n long long cayley(long long k, long long n) { n   if (n == k) return 1; n   return k * bigmod(n - k - 1, n) % mod; n } n long long get(long long node) { n   return A(node, cd - 2) * cayley(node + 2, cd) % mod * p[cd - node - 2] % mod * n          C(node, w - 1) % mod; n } n void do_it() { n   create(); n   for (long long i = 0; i <= cd - 2; i++) kq += get(i), kq %= mod; n   cout << kq; n } n int main() { n   inp(); n   do_it(); n } n


#include <bits/stdc++.h> n const int N = 1e3 + 10; n using namespace std; n int a[N], b[N], c[N]; n char str1[N], str2[N], str3[N]; n int main() { n   int tc; n   cin >> tc; n   while (tc--) { n     long long n, k, sum{0}, suma{0}, sumb{0}; n     cin >> n >> k; n     for (int i = 0; i < n; ++i) { n       cin >> a[i]; n       suma += a[i]; n     } n     for (int i = 0; i < n; ++i) { n       cin >> b[i]; n       sumb += b[i]; n     } n     if (k > 0) { n       for (int i = 0; i < n; ++i) { n         for (int j = i; j < n - 1; ++j) { n           if (a[i] >= a[j + 1]) swap(a[i], a[j + 1]); n           if (b[i] <= b[j + 1]) swap(b[i], b[j + 1]); n         } n       } n       for (int i = 0; i < k; ++i) { n         if (a[i] < b[i]) swap(a[i], b[i]); n       } n       for (int i = 0; i < n; ++i) { n         sum += a[i]; n       } n       cout << sum <<   n ; n     } else n       cout << suma <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a[3], b[3]; n int main() { n   int n, m; n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> n >> m; n   for (int i = 1; i <= n; ++i) { n     int c; n     cin >> c; n     a[c % 2]++; n   } n   for (int j = 1; j <= m; ++j) { n     int c; n     cin >> c; n     b[c % 2]++; n   } n   cout << min(a[1], b[0]) + min(b[1], a[0]) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n1, n2, k1, k2; n   cin >> n1 >> n2 >> k1 >> k2; n   if (n1 > n2) { n     cout <<  First  << endl; n     return 0; n   } n   if (n2 > n1) { n     cout <<  Second  << endl; n     return 0; n   } n   if (k1 < k2) { n     cout <<  Second  << endl; n     return 0; n   } n   if (k2 < k1) { n     cout <<  Second  << endl; n     return 0; n   } n   if (n1 == n2 && k1 == k2) { n     cout <<  Second  << endl; n     return 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100005, maxl = 200005, maxsg = 60; n int n, f, SG, cnt, maxx; n int p[maxl], c[maxl], sg[maxl], A[maxn], B[maxn]; n bitset<maxl> ok, have[maxsg]; n void sieve(int n) { n   c[1] = 1; n   for (int i = 2; i <= n; i++) { n     if (c[i] == 0) p[++cnt] = i, ok[i] = 1; n     for (int j = 1; j <= cnt; j++) { n       if (i * p[j] > n) break; n       c[i * p[j]] = 1; n       if (c[i] == 0) ok[i * p[j]] = 1; n       if (i % p[j] == 0) break; n     } n   } n } n int main() { n   scanf( %d%d , &n, &f); n   for (int i = 1; i <= n; i++) { n     int x, y, z; n     scanf( %d%d%d , &x, &y, &z); n     A[i] = y - x - 1, B[i] = z - y - 1; n     maxx = max(maxx, max(A[i], B[i])); n   } n   sieve(maxx), ok[f] = 0, have[0] = ok; n   for (int i = 1; i <= maxx; i++) { n     while (have[sg[i]][i]) sg[i]++; n     have[sg[i]] |= (ok << i); n   } n   for (int i = 1; i <= n; i++) SG ^= sg[A[i]] ^ sg[B[i]]; n   if (SG == 0) n     puts( Bob nAlice ); n   else n     puts( Alice nBob ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void logf(istream_iterator<string> it) {} n template <typename T, typename... Args> n void logf(istream_iterator<string> it, T a, Args... args) { n   cout << *it <<  =  << a <<    ; n   logf(++it, args...); n } n const double PI = acos(-1); n void solve() { n   string s; n   cin >> s; n   ; n   reverse(s.begin(), s.end()); n   int ans = 0; n   int car = 0; n   function<void(int)> inc = [&](int idx) { n     if (idx == s.size()) n       s +=  1 ; n     else { n       if (s[idx] ==  1 ) { n         s[idx] =  0 ; n         inc(idx + 1); n       } else n         s[idx] =  1 ; n     } n   }; n   for (size_t i = 0; i + 1 < s.size(); i++) { n     if (s[i] ==  1 ) { n       inc(i); n       ans++; n     } n     if (i + 1 < s.size()) ans++; n   } n   cout << ans << endl; n } n int main() { n   cin.tie(nullptr); n   std::ios::sync_with_stdio(false); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int n, q; n int m; n int lastans; n int a[1000][700]; n int b[100100]; n int sz[1000]; n short int cnt[1000][100100]; n void remake() { n   int pos = 0; n   for (int i = 0; i <= m; i++) { n     sz[i] = 0; n     for (int j = 0; j < 700; a[i][j] = 0, j++) { n       if (a[i][j] == -1 || a[i][j] == 0) continue; n       cnt[i][a[i][j]]--; n       b[pos] = a[i][j]; n       pos++; n     } n   } n   for (int i = 0; i < n; i++) { n     a[i / 333][i % 333] = b[i]; n     cnt[i / 333][b[i]]++; n     sz[i / 333]++; n   } n } n int find(int it, int pos) { n   int i = 0; n   pos--; n   while (pos || a[it][i] == -1) { n     if (a[it][i] == -1) pos++; n     pos--; n     i++; n   } n   int res = a[it][i]; n   a[it][i] = -1; n   return res; n } n void update(int it, int pos, int k) { n   pos--; n   int t = sz[it] - pos; n   int i = 0; n   while (pos || a[it][i] == -1) { n     if (a[it][i] == -1) pos++; n     pos--; n     i++; n   } n   int buf = a[it][i]; n   a[it][i] = k; n   while (t) { n     i++; n     if (buf != -1) t--; n     swap(a[it][i], buf); n   } n } n int solve(int r, int k) { n   int res = 0; n   int pos = 0; n   int it = 0; n   while (it <= m && sz[it] <= r) { n     r -= sz[it]; n     res += cnt[it][k]; n     it++; n   } n   int i = 0; n   while (pos < r) { n     if (a[it][i] == -1 || a[it][i] == 0) { n       i++; n       continue; n     } n     res += (a[it][i] == k); n     i++; n     pos++; n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i / 333][i % 333]; n     cnt[i / 333][a[i / 333][i % 333]]++; n     sz[i / 333]++; n   } n   m = (n - 1) / 333 + 1; n   cin >> q; n   while (q--) { n     int type, l, r, k; n     cin >> type >> l >> r; n     l = (l + lastans - 1) % n + 1; n     r = (r + lastans - 1) % n + 1; n     if (l > r) swap(l, r); n     if (type == 1) { n       int it = 0; n       int pos = 0; n       while (pos < l) { n         pos += sz[it]; n         it++; n       } n       if (pos >= l) { n         it--; n         pos -= sz[it]; n       } n       int p1 = pos; n       int w = it; n       it = 0; n       pos = 0; n       while (pos < r) { n         pos += sz[it]; n         it++; n       } n       if (pos >= r) { n         it--; n         pos -= sz[it]; n       } n       k = find(it, r - pos); n       cnt[w][k]++; n       cnt[it][k]--; n       sz[w]++; n       sz[it]--; n       update(w, l - p1, k); n       if (sz[w] > 2 * 333) remake(); n     } else { n       cin >> k; n       k = (k + lastans - 1) % n + 1; n       lastans = solve(r, k) - solve(l - 1, k); n       printf( %d n , lastans); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n const double eps = 1e-11; n const int INFINITE = 0x3f3f3f3f; n template <class T> n inline void checkmin(T &a, T b) { n   if (b < a) a = b; n } n template <class T> n inline void checkmax(T &a, T b) { n   if (b > a) a = b; n } n template <class T> n inline T sqr(T x) { n   return x * x; n } n template <class T> n inline T lowbit(T n) { n   return (n ^ (n - 1)) & n; n } n template <class T> n inline int countbit(T n) { n   return (n == 0) ? 0 : (1 + countbit(n & (n - 1))); n } n typedef vector<int> VI; n typedef vector<VI> VII; n typedef vector<string> VS; n int dx[4] = {1, 0, 0, -1}; n int dy[4] = {0, 1, -1, 0}; n bool isright(int x1, int y1, int x2, int y2, int x3, int y3) { n   int l12 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); n   int l23 = (x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3); n   int l31 = (x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1); n   if (l12 == 0 || l23 == 0 || l31 == 0) return false; n   return (l12 + l23 == l31 || l12 + l31 == l23 || l23 + l31 == l12); n } n int main() { n   ios::sync_with_stdio(false); n   int p[3][2]; n   cin >> p[0][0] >> p[0][1] >> p[1][0] >> p[1][1] >> p[2][0] >> p[2][1]; n   if (isright(p[0][0], p[0][1], p[1][0], p[1][1], p[2][0], p[2][1])) { n     cout <<  RIGHT n ; n     return 0; n   } n   for (int n = (int)(0); n < (int)(3); n++) n     for (int i = (int)(0); i < (int)(4); i++) { n       p[n][0] += dx[i], p[n][1] += dy[i]; n       if (isright(p[0][0], p[0][1], p[1][0], p[1][1], p[2][0], p[2][1])) { n         cout <<  ALMOST n ; n         return 0; n       } n       p[n][0] -= dx[i], p[n][1] -= dy[i]; n     } n   cout <<  NEITHER n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const ll mod = 998244353; n int n, m, t[1 << 19]; n struct segTree { n   struct { n     ll kk, bk, kb, bb; n   } a[1 << 20]; n   void upd(int p, int l, int r) { n     int mid = l + r >> 1, v = t[mid] == 1 ? 9 - t[mid + 1] : 0; n     a[p].kk = a[p * 2].kb * a[p * 2 + 1].bk % mod; n     if (l < mid && mid + 1 < r) n       (a[p].kk += a[p * 2].kk * a[p * 2 + 1].kk % mod * v) %= mod; n     a[p].bk = a[p * 2].bb * a[p * 2 + 1].bk % mod; n     if (mid + 1 < r) n       (a[p].bk += a[p * 2].bk * a[p * 2 + 1].kk % mod * v) %= mod; n     a[p].kb = a[p * 2].kb * a[p * 2 + 1].bb % mod; n     if (l < mid) (a[p].kb += a[p * 2].kk * a[p * 2 + 1].kb % mod * v) %= mod; n     a[p].bb = a[p * 2].bb * a[p * 2 + 1].bb % mod; n     (a[p].bb += a[p * 2].bk * a[p * 2 + 1].kb % mod * v) %= mod; n   } n   void build(int p = 1, int l = 1, int r = n) { n     if (l == r) { n       a[p] = {1, 1, 1, t[l] + 1}; n       return; n     } n     int mid = l + r >> 1; n     build(p * 2, l, mid); n     build(p * 2 + 1, mid + 1, r); n     upd(p, l, r); n   } n   void ins(int x, int p = 1, int l = 1, int r = n) { n     if (l == r) { n       a[p] = {1, 1, 1, t[l] + 1}; n       return; n     } n     int mid = l + r >> 1; n     if (x <= mid) n       ins(x, p * 2, l, mid); n     else n       ins(x, p * 2 + 1, mid + 1, r); n     upd(p, l, r); n   } n } tr; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) { n     char c; n     scanf(  %c , &c); n     t[i] = c -  0 ; n   } n   tr.build(); n   while (m--) { n     int p, v; n     scanf( %d%d , &p, &v); n     t[p] = v; n     tr.ins(p); n     printf( %lld n , tr.a[1].bb); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int a[1111]; n int b[1111]; n int c[1111]; n int vis[1111]; n int pos[5]; n int cntp; n int main() { n   scanf( %d , &n); n   bool flag = 0; n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &a[i]); n     vis[a[i]]++; n   } n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &b[i]); n     if (a[i] != b[i]) { n       pos[++cntp] = i; n     } n   } n   int dvis; n   for (int i = 1; i <= n; ++i) n     if (!vis[i]) { n       dvis = i; n       break; n     } n   if (cntp == 1) { n     a[pos[1]] = dvis; n   } else { n     if (b[pos[1]] == dvis && vis[a[pos[1]]] > 1) n       a[pos[1]] = dvis; n     else n       a[pos[2]] = dvis; n   } n   for (int i = 1; i <= n; ++i) printf( %d  , a[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e9 + 7; n struct hhh { n   long long x; n   long long y; n   long long v; n } c[1000001]; n bool operator<(hhh a, hhh b) { n   return (a.v != b.v ? a.v > b.v : (a.x != b.x ? a.x > b.x : a.y > b.y)); n } n vector<hhh> v; n long long n, m, a, b, h[1001][1001], g[1001][1001], mi[1001][1001], n     minf[1001][1001], k; n bool f[1001][1001]; n long long pre[3][1001][1001]; 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 << 1) + (x << 3) + (ch ^ 48); n     ch = getchar(); n   } n   return x * f; n } n bool check(hhh t) { n   if (f[t.x][t.y]) { n     return 0; n   } n   for (long long i = max(t.x - a + 1, (long long)1); i <= t.x + a - 1; i++) { n     for (long long j = max(t.y - b + 1, (long long)1); j <= t.y + b - 1; j++) { n       f[i][j] = 1; n     } n   } n   return 1; n } n int main() { n   n = read(); n   m = read(); n   a = read(); n   b = read(); n   for (long long i = 1; i <= (n); i++) { n     for (long long j = 1; j <= (m); j++) { n       h[i][j] = read(); n     } n   } n   for (long long i = 1; i <= (n); i++) { n     for (long long j = 1; j <= (m); j++) { n       pre[1][i][j] = pre[1][i][j - 1] + h[i][j]; n       pre[2][i][j] = pre[2][i - 1][j] + h[i][j]; n     } n   } n   for (long long i = 1; i <= (a); i++) { n     g[1][1] += pre[1][i][b]; n   } n   for (long long i = 2; i <= m - b + 1; i++) { n     g[1][i] = g[1][i - 1] + pre[2][a][i + b - 1] - pre[2][a][i - 1]; n   } n   for (long long i = 2; i <= n - a + 1; i++) { n     for (long long j = 1; j <= (m - b + 1); j++) { n       g[i][j] = g[i - 1][j] + pre[1][i + a - 1][j + b - 1] - n                 pre[1][i + a - 1][j - 1] - pre[1][i - 1][j + b - 1] + n                 pre[1][i - 1][j - 1]; n     } n   } n   for (long long i = 1; i <= (n); i++) { n     long long s = 1; n     long long t = 0; n     long long que[1001]; n     que[0] = INF; n     for (long long j = 1; j <= (m); j++) { n       while (s <= t && h[i][que[t]] >= h[i][j]) { n         t--; n       } n       que[++t] = j; n       if (j - b >= 0) { n         mi[i][j - b + 1] = h[i][que[s]]; n       } n       if (que[s] == j - b + 1) { n         s++; n       } n     } n   } n   for (long long j = 1; j <= (m - b + 1); j++) { n     long long s = 1; n     long long t = 0; n     long long que[1001]; n     que[0] = INF; n     for (long long i = 1; i <= (n); i++) { n       while (s <= t && mi[que[t]][j] >= mi[i][j]) { n         t--; n       } n       que[++t] = i; n       if (i - a >= 0) { n         minf[i - a + 1][j] = mi[que[s]][j]; n       } n       if (que[s] == i - a + 1) { n         s++; n       } n     } n   } n   for (long long i = 1; i <= (n - a + 1); i++) { n     for (long long j = 1; j <= (m - b + 1); j++) { n       g[i][j] -= a * b * minf[i][j]; n       hhh t; n       t.x = i; n       t.y = j; n       t.v = g[i][j]; n       v.push_back(t); n     } n   } n   make_heap(v.begin(), v.end()); n   while (!v.empty()) { n     hhh t = v.front(); n     pop_heap(v.begin(), v.end()); n     v.pop_back(); n     if (check(t)) { n       c[++k] = t; n     } n   } n   cout << k << endl; n   for (long long i = 1; i <= (k); i++) { n     printf( %I64d %I64d %I64d n , c[i].x, c[i].y, c[i].v); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n struct Aho { n   enum { ALPHA = 30 }; n   struct Node { n     int p = -1, link = -1, superLink = -1; n     int next[ALPHA], go[ALPHA]; n     bool leaf = false; n     vector<int> leaves; n     char ch; n     Node(int p = -1, char c =  $ ) : p(p), ch(c) { n       fill(begin(next), end(next), -1); n       fill(begin(go), end(go), -1); n     } n   }; n   vector<Node> nodes; n   void insert(string &s, int id) { n     int v = 0; n     for (char ch : s) { n       int c = ch -  a ; n       if (nodes[v].next[c] == -1) { n         Node aux = Node(v, ch); n         nodes[v].next[c] = (int)nodes.size(); n         nodes.push_back(aux); n       } n       v = nodes[v].next[c]; n     } n     nodes[v].leaf = true; n     nodes[v].leaves.push_back(id); n   } n   int go(int v, char ch) { n     int c = ch -  a ; n     if (nodes[v].go[c] == -1) { n       if (nodes[v].next[c] != -1) { n         nodes[v].go[c] = nodes[v].next[c]; n       } else { n         if (v == 0) n           nodes[v].go[c] = 0; n         else n           nodes[v].go[c] = go(nodes[v].link, ch); n       } n     } n     return nodes[v].go[c]; n   } n   Aho(vector<string> &vs) { n     Node root = Node(); n     nodes.push_back(root); n     int id = 0; n     for (auto s : vs) insert(s, id++); n     queue<int> fila; n     nodes[0].link = 0; n     for (int &v : nodes[0].next) { n       if (v != -1) { n         fila.push(v); n         nodes[v].link = 0; n       } else n         v = 0; n     } n     while (!fila.empty()) { n       int v = fila.front(); n       fila.pop(); n       for (int u : nodes[v].next) { n         if (u != -1) { n           int c = nodes[u].ch -  a ; n           int fail = nodes[v].link; n           while (nodes[fail].next[c] == -1) { n             fail = nodes[fail].link; n           } n           fail = nodes[fail].next[c]; n           for (int id : nodes[fail].leaves) { n             nodes[u].leaves.push_back(id); n           } n           nodes[u].link = fail; n           fila.push(u); n         } n       } n     } n   } n   int find(int idx, int p) { n     if (idx != p and (nodes[idx].leaf or idx == 0)) return idx; n     if (nodes[idx].superLink == -1) { n       nodes[idx].superLink = find(nodes[idx].link, p); n     } n     return nodes[idx].superLink; n   } n   vector<vector<int> > findAll(string s, int n) { n     vector<vector<int> > res(n + 5); n     int idx = 0; n     for (int i = 0; i < (int)s.size(); i++) { n       char ch = s[i]; n       idx = go(idx, ch); n       for (int id : nodes[idx].leaves) res[i].push_back(id); n     } n     return res; n   } n }; n string s; n string ss[100005]; n int n; n int k[100005]; n int32_t main() { n   cin.tie(NULL); n   cout.tie(NULL); n   ios_base::sync_with_stdio(0); n   cin >> s >> n; n   vector<string> vs; n   for (int i = 0; i < n; i++) { n     cin >> k[i] >> ss[i]; n     vs.push_back(ss[i]); n   } n   Aho ac = Aho(vs); n   auto res = ac.findAll(s, (int)s.size()); n   vector<vector<int> > pos(n + 5); n   for (int i = 0; i < (int)res.size(); i++) { n     for (int idx : res[i]) { n       pos[idx].push_back(i); n     } n   } n   for (int i = 0; i < n; i++) { n     int res = 0x3f3f3f3f; n     if ((int)pos[i].size() < k[i]) { n       cout << -1 <<   n ; n       continue; n     } n     for (int j = 0; j + k[i] <= (int)pos[i].size(); j++) { n       res = min(res, pos[i][k[i] + j - 1] - pos[i][j] + (int)ss[i].size()); n     } n     cout << res <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s, s1; n   int m; n   cin >> s; n   cin >> m; n   int l, r, k, i, j, d, ind; n   while (m--) { n     cin >> l >> r >> k; n     --l; n     --r; n     d = r - l + 1; n     s1 = s.substr(l, d); n     for (i = l; i <= r; ++i) { n       ind = (i - l + k) % d + l; n       s[ind] = s1[i - l]; n     } n   } n   cout << s; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxn = 100005; n const long long p = 1e9 + 7; n long long a[maxn], n, x, sum; n long long st[maxn], top; n vector<long long> v; n inline long long read() { n   long long x = 0, f = 1; n   char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n inline long long qpow(long long x, long long y) { n   long long res = 1; n   while (y) { n     if (y & 1) res = (res * x % p) % p; n     x = (x % p * x % p) % p; n     y >>= 1; n   } n   return res % p; n } n signed main() { n   n = read(); n   x = read(); n   for (long long i = 1; i <= n; i++) a[i] = read(), sum += a[i]; n   for (long long i = 1; i <= n; i++) st[++top] = sum - a[i]; n   sort(st + 1, st + n + 1); n   reverse(st + 1, st + n + 1); n   while (1) { n     long long res = st[top], cnt = 0; n     while (top > 0 && res == st[top]) cnt++, top--; n     if (cnt % x) { n       printf( %d , qpow(x, min(sum, res))); n       return 0; n     } else { n       cnt /= x; n       for (long long i = 1; i <= cnt; i++) st[++top] = res + 1; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct NODE { n   char name[102]; n   int to; n }; n struct TRIE { n   vector<NODE> fold, file; n }; n TRIE trie[5][10010]; n int cnt[5]; n int ans_file, ans_fold; n int track(int index, int tar, int &layer) { n   int i, j, count = 0; n   if (trie[index][tar].fold.size() < 1) { n     return trie[index][tar].file.size(); n   } else { n     for (i = 0, j = trie[index][tar].fold.size(); i < j; ++i) { n       count += track(index, trie[index][tar].fold[i].to, layer); n     } n     layer += trie[index][tar].fold.size(); n     return (count + trie[index][tar].file.size()); n   } n } n int main() { n   int i, j, index, now; n   char in[102], *p; n   NODE tmp; n   memset(trie, 0, sizeof(trie)); n   memset(cnt, 0, sizeof(cnt)); n   while (scanf( %s , in) != EOF) { n     p = strtok(in,  :  ); n     if (p[0] ==  C ) n       index = 0; n     else if (p[0] ==  D ) n       index = 1; n     else if (p[0] ==  E ) n       index = 2; n     else if (p[0] ==  F ) n       index = 3; n     else if (p[0] ==  G ) n       index = 4; n     now = 0; n     p = strtok(NULL,    ); n     while (p != NULL) { n       for (i = 0, j = strlen(p); i < j; ++i) n         if (p[i] ==  . ) break; n       if (i == j) { n         for (i = 0, j = trie[index][now].fold.size(); i < j; ++i) n           if (!strcmp(trie[index][now].fold[i].name, p)) break; n         if (i == j) { n           strcpy(tmp.name, p); n           tmp.to = ++cnt[index]; n           trie[index][now].fold.push_back(tmp); n           now = cnt[index]; n         } else { n           now = trie[index][now].fold[i].to; n         } n       } else { n         strcpy(tmp.name, p); n         trie[index][now].file.push_back(tmp); n       } n       p = strtok(NULL,    ); n     } n   } n   for (i = 0, ans_file = 0, ans_fold = 0; i < 5; ++i) { n     for (j = 0, now = trie[i][0].fold.size(); j < now; ++j) { n       index = 0; n       ans_file = max(ans_file, track(i, trie[i][0].fold[j].to, index)); n       ans_fold = max(ans_fold, index); n     } n   } n   printf( %d %d n , ans_fold, ans_file); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int T[2 * 10010]; n vector<int> G[6010]; n vector<int> S[6010]; n int P[6010]; n int C[6010]; n map<int, int> M; n bool V[6010]; n int mx; n int n = 6010; n void modify(int p, int value) { n   for (T[p += n] = value; p > 1; p >>= 1) T[p >> 1] = max(T[p], T[p ^ 1]); n } n int query(int l, int r) { n   int res = 0; n   for (l += n, r += n; l < r; l >>= 1, r >>= 1) { n     if (l & 1) res = max(res, T[l++]); n     if (r & 1) res = max(res, T[--r]); n   } n   return res; n } n void dfs(int u) { n   V[u] = true; n   int val = 1 + query(0, P[u]); n   S[P[u]].push_back(val); n   modify(P[u], val); n   mx = max(mx, val); n   for (int i = 0; i < G[u].size(); i++) { n     int v = G[u][i]; n     if (!V[v]) { n       dfs(v); n     } n   } n   S[P[u]].pop_back(); n   if (!S[P[u]].empty()) { n     modify(P[u], S[P[u]].back()); n   } else { n     modify(P[u], 0); n   } n } n int main() { n   ios::sync_with_stdio(false); n   int N; n   cin >> N; n   for (int i = 1; i <= N; i++) { n     cin >> P[i]; n     C[i] = P[i]; n   } n   for (int i = 0; i < N - 1; i++) { n     int u, v; n     cin >> u >> v; n     G[u].push_back(v); n     G[v].push_back(u); n   } n   sort(C + 1, C + N + 1); n   int count = 1; n   M[C[1]] = 1; n   for (int i = 2; i <= N; i++) { n     if (C[i] != C[i - 1]) { n       count++; n       M[C[i]] = count; n     } n   } n   for (int i = 1; i <= N; i++) { n     P[i] = M[P[i]]; n   } n   for (int i = 1; i <= N; i++) { n     dfs(i); n     memset(V, false, sizeof V); n   } n   cout << mx <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int cnt[200001], n, par; n vector<int> adj[200001]; n vector<pair<int, int> > v; n void count(int h, int p) { n   cnt[h]++; n   for (auto it : adj[h]) n     if (it ^ p) { n       count(it, h); n       cnt[h] += cnt[it]; n     } n } n int ct(int h, int p) { n   for (auto it : adj[h]) n     if (it ^ p) { n       if (cnt[it] > n / 2) return ct(it, h); n     } n   par = p; n   return h; n } n vector<pair<int, pair<int, int> > > res; n void dfs(int h, int p) { n   for (auto it : adj[h]) n     if (it ^ p) { n       dfs(it, h); n     } n   v.push_back({h, p}); n } n void f(int h, int p) { n   v.clear(); n   dfs(h, p); n   v.pop_back(); n   int t = h; n   for (auto it : v) { n     res.push_back({p, {t, it.first}}); n     res.push_back({it.first, {it.second, h}}); n     t = it.first; n   } n   res.push_back({p, {t, h}}); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i < n; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     adj[x].push_back(y); n     adj[y].push_back(x); n   } n   count(1, 0); n   int cen = ct(1, 0), cen2 = 0; n   for (auto it : adj[cen]) n     if (par != it && 2 * cnt[it] == n) cen2 = it; n   for (auto it : adj[cen]) n     if (it != cen2) f(it, cen); n   for (auto it : adj[cen2]) n     if (it != cen) f(it, cen2); n   printf( %d n , res.size()); n   for (auto it : res) n     printf( %d %d %d n , it.first, it.second.first, it.second.second); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool f[10]; n char s[100005]; n int main() { n   int n, i, j; n   scanf( %d , &n); n   scanf( %s , s); n   for (i = 0; i < n; i++) { n     if (s[i] ==  L ) { n       for (j = 0; j < 10; j++) n         if (!f[j]) break; n       f[j] = 1; n     } else if (s[i] ==  R ) { n       for (j = 9; j >= 0; j--) n         if (!f[j]) break; n       f[j] = 1; n     } else { n       f[s[i] -  0 ] = 0; n     } n   } n   for (i = 0; i < 10; i++) printf( %d , f[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> pr; n bool isp[1001]; n void p() { n   memset(isp, true, sizeof isp); n   isp[0] = isp[1] = false; n   for (int i = 2; i < 1001; ++i) { n     if (!isp[i]) continue; n     pr.push_back(i); n     for (int j = 2 * i; j < 1001; j += i) isp[j] = false; n   } n } n int main() { n   p(); n   string s; n   cin >> s; n   int n = s.length(); n   bool ans = 0; n   set<int> st; n   for (int i = 0; i < pr.size(); ++i) { n     if (pr[i] > n / 2) break; n     for (int j = 1; pr[i] * j <= n; ++j) st.insert(pr[i] * j); n   } n   int cnt[26], mx = 0, ch = -1; n   memset(cnt, 0, sizeof cnt); n   for (int i = 0; i < n; ++i) { n     cnt[s[i] -  a ]++; n     if (mx < cnt[s[i] -  a ]) { n       mx = cnt[s[i] -  a ]; n       ch = s[i]; n     } n   } n   if (mx >= st.size()) { n     cout <<  YES  << endl; n     string ans = s; n     for (int i = 0; i < n; ++i) ans[i] =    ; n     for (set<int>::iterator it = st.begin(); it != st.end(); ++it) n       ans[*it - 1] = ch; n     cnt[ch -  a ] -= st.size(); n     int idx = 0; n     for (int i = 0; i < 26; ++i) n       for (int j = 0; j < cnt[i]; ++j) { n         while (ans[idx] !=    ) ++idx; n         ans[idx] = i +  a ; n       } n     cout << ans << endl; n   } else n     cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t[6000020][2], tt; n void ins(long long x) { n   int p = 0; n   for (int i = 40; i--;) { n     if (!t[p][x >> i & 1]) t[p][x >> i & 1] = ++tt; n     p = t[p][x >> i & 1]; n   } n } n long long qy(long long x) { n   long long z = 0; n   int p = 0; n   for (int i = 40; i--;) { n     if (t[p][~x >> i & 1]) n       z += 1LL << i, p = t[p][~x >> i & 1]; n     else n       p = t[p][x >> i & 1]; n   } n   return z; n } n int n; n long long a[100020]; n long long ans; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %I64d , a + i); n   long long w = 0; n   ins(w); n   for (int i = 0; i < n; i++) ins(w ^= a[i]); n   for (int i = 0; i < n; i++) ans = max(ans, qy(w ^= a[i])); n   printf( %I64d , ans); n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n using namespace std; n const int MAXN = 5e2 + 10; n int n, m; n long long adj[MAXN][MAXN]; n long long adj_[MAXN][MAXN]; n int ans[MAXN][MAXN]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   memset(adj, 63, sizeof(adj)); n   memset(adj_, 63, sizeof(adj_)); n   for (int i = 0; i < m; i++) { n     int u, v, l; n     cin >> u >> v >> l; n     adj[u][v] = adj[v][u] = l; n     adj_[u][v] = adj_[v][u] = l; n   } n   for (int i = 1; i <= n; i++) adj[i][i] = 0; n   for (int k = 1; k <= n; k++) n     for (int i = 1; i <= n; i++) n       for (int j = 1; j <= n; j++) n         adj[i][j] = min(adj[i][j], adj[i][k] + adj[j][k]); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) n       for (int k = 1; k <= n; k++) n         if (adj_[k][j] < 1e9 && (adj[i][k] + adj_[k][j]) == adj[i][j]) n           ans[i][j]++; n   for (int i = 1; i < n; i++) n     for (int j = i + 1; j <= n; j++) { n       int answer = 0; n       for (int k = 1; k <= n; k++) n         if ((adj[i][k] + adj[k][j]) == adj[i][j]) answer += ans[i][k]; n       cout << answer <<    ; n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int ask(int i, int j) { n   cout <<  ?   << i <<     << j << endl; n   fflush(stdout); n   int val; n   cin >> val; n   return val; n } n int main() { n   int n; n   cin >> n; n   int a[n + 1]; n   int index = 1, i, x, y; n   for (int i = 2; i <= n; i++) { n     x = ask(index, i); n     y = ask(i, index); n     if (x > y) { n       a[index] = x; n       index = i; n     } else if (y > x) { n       a[i] = y; n     } n   } n   a[index] = n; n   cout <<  !  ; n   for (i = 1; i <= n; i++) cout << a[i] <<    ; n   cout <<   n ; n   fflush(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n long long n, m, s, t; n long long pos[maxn], T[maxn]; n long long cal(long long x) { n   if (s < m) n     s += t; n   else n     s -= t; n   t--; n   return (s % n + n) % n; n } n int main() { n   cin >> n >> m >> s >> t; n   s--; n   while (t % n) s = cal(s); n   long long temp = t / n; n   long long tick = 0; n   while (temp--) { n     if (pos[s]) { n       temp %= tick - T[s]; n       s = pos[s]; n     } else { n       T[s] = tick; n       long long tmp = s; n       t = n; n       for (int i = 1; i <= n; i++) s = cal(s); n       pos[tmp] = s; n       tick++; n     } n   } n   cout << s + 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     for (long long i = 1; i <= n; i++) { n       cout << 1 <<    ; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n bool done[1010]; n int l[1010], r[1010], ans[1010]; n int main() { n   int n, i, j, k; n   scanf( %d , &n); n   int rem = n; n   for (i = 0; i < n; i++) { n     scanf( %d , &l[i]); n     done[i] = 0; n   } n   for (i = 0; i < n; i++) scanf( %d , &r[i]); n   int maxx = n; n   while (1) { n     set<int> S; n     bool over = 1; n     for (i = 0; i < n; i++) { n       if (done[i] == 0) { n         over = 0; n         if (l[i] == 0 and r[i] == 0) { n           S.insert(i); n         } n       } n     } n     if (over) break; n     int sz = S.size(); n     if (sz == 0) { n       cout <<  NO  << endl; n       return 0; n     } n     set<int>::iterator it; n     for (it = S.begin(); it != S.end(); it++) { n       int idx = *it; n       ans[idx] = maxx; n       for (j = idx - 1; j >= 0; j--) { n         if (done[j] == 0 and S.find(j) == S.end()) { n           if (r[j] == 0) { n             cout <<  NO  << endl; n             return 0; n           } n           r[j]--; n         } n       } n       for (j = idx + 1; j < n; j++) { n         if (done[j] == 0 and S.find(j) == S.end()) { n           if (l[j] == 0) { n             cout <<  NO  << endl; n             return 0; n           } n           l[j]--; n         } n       } n     } n     for (it = S.begin(); it != S.end(); it++) { n       done[*it] = 1; n     } n     maxx--; n   } n   cout <<  YES  << endl; n   for (i = 0; i < n; i++) cout << ans[i] <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int ans; n bool one, two, three; n vector<int> v; n int main() { n   scanf( %d , &n); n   while (one == false || two == false || three == false) { n     for (int i = 1; i <= n; i++) { n       if (!one) { n         if (i % 2 == 0) { n           ans++; n           v.push_back(i); n         } n         if ((n % 2 == 0 && i == n) || (n % 2 != 0 && i == n - 1)) { n           one = true; n           break; n         } n       } else if (!two) { n         if (i % 2 != 0) { n           ans++; n           v.push_back(i); n         } n         if ((n % 2 != 0 && i == n) || (n % 2 == 0 && i == n - 1)) { n           two = true; n           break; n         } n       } else if (!three) { n         if (i % 2 == 0) { n           ans++; n           v.push_back(i); n         } n         if ((n % 2 == 0 && i == n) || (n % 2 != 0 && i == n - 1)) { n           three = true; n           goto A; n         } n       } n     } n   } n A: n   printf( %d n , ans); n   for (int i = 0; i < v.size(); i++) { n     printf( %d  , v[i]); n   } n } n


#include <bits/stdc++.h> n const long long MaxN = 1e5 + 50; n template <class t> n inline void read(t &s) { n   s = 0; n   register long long f = 1; n   register char c = getchar(); n   while (!isdigit(c)) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar(); n   s *= f; n   return; n } n template <class t, class... A> n inline void read(t &x, A &...a) { n   read(x); n   read(a...); n } n template <class t> n inline void write(t x) { n   if (x < 0) putchar( - ), x = -x; n   long long buf[21], top = 0; n   while (x) buf[++top] = x % 10, x /= 10; n   if (!top) buf[++top] = 0; n   while (top) putchar(buf[top--] ^  0 ); n   return; n } n inline void setIn(std::string s) { n   freopen(s.c_str(),  r , stdin); n   return; n } n inline void setOut(std::string s) { n   freopen(s.c_str(),  w , stdout); n   return; n } n inline void setIO(std::string s =   ) { n   setIn(s +  .in ); n   setOut(s +  .out ); n   return; n } n template <class t> n inline bool ckmin(t &x, t y) { n   if (x > y) { n     x = y; n     return 1; n   } n   return 0; n } n template <class t> n inline bool ckmax(t &x, t y) { n   if (x < y) { n     x = y; n     return 1; n   } n   return 0; n } n inline long long lowbit(long long x) { return x & (-x); } n std::vector<long long> E[MaxN]; n long long f[MaxN], g[MaxN], up[MaxN][21], dep[MaxN], s[MaxN][21], to[MaxN], n     a[MaxN], n, L, S; n inline void dfs(long long u, long long fa) { n   up[u][0] = fa, dep[u] = dep[fa] + 1; n   for (auto v : E[u]) n     if (v != fa) s[v][0] = a[u], dfs(v, u); n } n inline void dfs2(long long u, long long fa) { n   f[u] = -1; n   for (auto v : E[u]) n     if (v != fa) dfs2(v, u), ckmax(f[u], f[v] - 1), g[u] += g[v]; n   if (!~f[u]) f[u] = to[u], ++g[u]; n } n signed main(void) { n   read(n, L, S); n   if (!L) return std::puts( -1 ), 0; n   for (long long i = 1; i <= n; ++i) { n     read(a[i]); n     if (a[i] > S) return std::puts( -1 ), 0; n   } n   register long long v; n   for (long long i = 2; i <= n; ++i) n     read(v), E[i].push_back(v), E[v].push_back(i); n   dfs(1, 0); n   for (long long k = 1; k < 21; ++k) n     for (long long i = 1; i <= n; ++i) n       up[i][k] = up[up[i][k - 1]][k - 1], n       s[i][k] = s[i][k - 1] + s[up[i][k - 1]][k - 1]; n   for (long long i = 1; i <= n; ++i) { n     register long long pos = i, nl = 0, ns = a[i]; n     for (long long k = 20; ~k; --k) n       if (up[pos][k] && nl + (1 << k) < L && ns + s[pos][k] <= S) n         nl += (1 << k), ns += s[pos][k], pos = up[pos][k]; n     to[i] = nl; n   } n   dfs2(1, 0); n   write(g[1]), std::puts(  ); n   return 0; n } n


//SAGAR SINGH n // #pragma GCC optimize( Ofast ) n // #pragma GCC target( avx,avx2,fma ) n // #pragma GCC optimization( unroll-loops ) n #include<bits/stdc++.h> n using namespace std; n #define fastio ios_base::sync_with_stdio;cin.tie(NULL);cout.tie(0); n #define ll long long  n #define ld long double  n #define rep(i,a,b) for(ll i=a;i<b;i++) //rep(i,0,n)  n #define repr(i,a,b) for(ll i=a;i>=b;i--)//repr(i,n-1,0) n #define repit(it,a) for(auto it=(a).begin();it!=(a).end();it++)//repr(i,n,0) n #define vll vector<long long> n #define vpl vector<pair<ll,ll> > n #define sll set<long long> n #define msll multiset<long long> n #define mll map<ll,ll> n #define mmll multimap<ll,ll> n #define all(x) x.begin(),x.end() n #define rall(x) x.rbegin(),x.rend() n #define get(x) getline(cin,x) n #define in(v) for(auto &x:v) cin>>x; n #define out(v) for(auto x:v) {cout<<x<<   ;} cout<<  n ; n #define str string n #define pb  push_back n #define ins insert n #define lb lower_bound n #define ub upper_bound n #define ff first n #define ss second n /*--- bit-stuff ----*/ n #define setbits(a) ( __builtin_popcountll(a)) n #define right(a) (__builtin_ctzll(a)) n #define left(a) (__builtin_clzll(a)) n #define parity(a) (__builtin_parityll(a)) n  n #define TRACE n #ifdef TRACE n #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) n     template <typename Arg1> n     void __f(const char* name, Arg1&& arg1){ n         cout << name <<   :   << arg1 << endl; n         //use cerr if u want to display at the bottom n     } n     template <typename Arg1, typename... Args> n     void __f(const char* names, Arg1&& arg1, Args&&... args){ n         const char* comma = strchr(names + 1,  , ); cout.write(names, comma - names) <<   :   << arg1<<  |  ;__f(comma+1, args...); n     } n #else n #define trace(...) n #endif n  n  n const ll mod = 1e9+7; n const ll N = 1e5+1; n const ll INF = 1e18; n const ll NINF = -1e18; n  n  n void solve(){ n  n ll n;cin>>n; n vll v(n);in(v); n  n str s; n rep(i,0,n) s.pb( 0 ); n  n ll cur=0; n ll i=n-1; n  n while(i>=0){ n  cur=max({cur,v[i],(ll)0}); n   if(cur>0) s[i]= 1 ; n   else s[i]= 0 ; n   i--; n   cur--; n } n  n out(s); n  n  n  n  n  n  n } n  n int main(){ n   ios_base::sync_with_stdio; n   cin.tie(NULL);cout.tie(0); n   ll t=1; n   cin>>t; n   while(t--)  n     solve(); n  n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n long long N, K; n int M; n vector<long long> special; n int sol = 0; n int main() { n   scanf( %lld %d %lld , &N, &M, &K); n   for (int i = 0; i < M; i++) { n     long long v; n     scanf( %lld , &v); n     special.push_back(v); n   } n   int curr = 0, add = 0; n   while (curr < M) { n     sol++; n     long long v = special[curr]; n     v--; n     v -= (long long)add; n     long long page = v / K; n     long long en = K + K * page; n     long long toAdd = 0; n     while (curr < M && special[curr] - add <= en) { n       curr++; n       toAdd++; n     } n     add += toAdd; n   } n   printf( %d n , sol); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename t> n t in(t q) { n   cin >> q; n   return q; n } n template <typename T> n ostream& operator<<(ostream& os, const vector<T>& v) { n   os <<  [ ; n   for (int i = 0; i < ((int)size(v)); ++i) { n     os << v[i]; n     if (i != ((int)size(v)) - 1) os <<  , ; n   } n   os <<  ] ; n   return os; n } n template <typename T, typename S> n ostream& operator<<(ostream& os, const map<T, S>& v) { n   for (auto it : v) os <<  (  << it.first <<  :  << it.second <<  ) ; n   return os; n } n template <typename T, typename S> n ostream& operator<<(ostream& os, const pair<T, S>& v) { n   os <<  (  << v.first <<  ,  << v.second <<  ) ; n   return os; n } n const long double PI = acosl(-1); n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count()); n inline int rand(int l, int r) { n   return uniform_int_distribution<int>(l, r)(rng); n } n inline long long rand(long long l, long long r) { n   return uniform_int_distribution<long long>(l, r)(rng); n } n int p; n int i; n int xw; n long long ans = 0; n int j; n bool s1, s2; n int n, k; n struct node; n node* last; n struct node { n   int sum; n   node *lft, *rht; n   node() { n     sum = 0; n     lft = NULL; n     rht = NULL; n   } n   int query(int l) { n     if (l == 2) return sum; n     if (l) { n       if (!rht) rht = new node(); n       last = rht; n       if (!lft) return 0; n       return lft->sum; n     } n     if (!lft) lft = new node(); n     last = lft; n     if (!rht) return 0; n     return rht->sum; n   } n   void update(int l, int r) { n     if (l == r) { n       sum++; n       return; n     } n     int mid = (l + r) / 2; n     if (xw <= mid) { n       if (!lft) lft = new node(); n       lft->update(l, mid); n     } else { n       if (!rht) rht = new node(); n       rht->update(mid + 1, r); n     } n     sum++; n   } n }; n node* r = new node(); n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cout << setprecision(10); n   cin >> n >> k; n   xw = 0; n   r->update(0, 1073741823); n   for (i = 1; i < n + 1; ++i) { n     cin >> p; n     last = r; n     p ^= xw; n     for (j = 29; j >= 0; --j) { n       s1 = ((1 << j) & k); n       s2 = (1 << j) & p; n       if (s1 && s2) { n         if (!last->lft) break; n         last = last->lft; n       } else if (s1 && !s2) { n         if (!last->rht) break; n         last = last->rht; n       } else if (s2) { n         ans += last->query(1); n       } else { n         ans += last->query(0); n       } n     } n     if (j == -1) ans += last->query(2); n     xw = p; n     r->update(0, 1073741823); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, a[2005], b[2005], x = 0, y = 0, n, m, sum = 0; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> m; n     if (m % 2 == 0) { n       a[x] = m; n       x++; n     } else { n       b[y] = m; n       y++; n     } n   } n   sort(a, a + x, greater<int>()); n   sort(b, b + y, greater<int>()); n   if (x == y || x + 1 == y || y + 1 == x) { n     cout <<  0  << endl; n   } else { n     if (x > y) { n       for (i = y + 1; i < x; i++) { n         sum += a[i]; n       } n     } n     if (x < y) { n       for (i = x + 1; i < y; i++) { n         sum += b[i]; n       } n     } n     cout << sum << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n const int MOD = 998244353; n const int PRIMROOT = 3; n int pw(int x, int n) { n   int ret = 1; n   while (true) { n     if (n & 1) ret = (long long)ret * x % MOD; n     if ((n >>= 1) == 0) return ret; n     x = (long long)x * x % MOD; n   } n } n struct NTT { n   void _init(int n, int &nlog, int &g, vector<int> &w) { n     assert((MOD - 1) % n == 0); n     g = pw(PRIMROOT, (MOD - 1) / n); n     nlog = 0; n     while ((1 << nlog) < n) ++nlog; n     if ((1 << nlog) != n) nlog = -1; n     w = vector<int>(n); n     w[0] = 1; n     for (int i = (1); i < (n); ++i) w[i] = (long long)w[i - 1] * g % MOD; n   } n   int fftn, fftnlog; n   int fftg; n   vector<int> fftw; n   void initfft(int n) { n     fftn = n, _init(fftn, fftnlog, fftg, fftw); n     assert(fftnlog != -1); n   } n   void fft(int *a, int n, bool inv) { n     if (n != fftn) initfft(n); n     for (int i = 1, j = n >> 1, k, l = j; i < n; j ^= k, ++i) { n       if (i < j) swap(a[i], a[j]); n       for (k = l; k & j; j ^= k, k >>= 1) n         ; n     } n     int *l, *r, *w; n     if (inv) reverse(fftw.begin() + 1, fftw.end()); n     for (int hlen = 1, step = n >> 1; hlen < n; hlen <<= 1, step >>= 1) { n       for (int i = 0; i < n; i += (hlen << 1)) { n         l = a + i, r = l + hlen, w = fftw.data(); n         for (int off = (0); off < (hlen); ++off) { n           int v = (long long)(*r) * (*w) % MOD; n           *r = (*l) - v; n           if (*r < 0) *r += MOD; n           *l = (*l) + v; n           if (*l >= MOD) *l -= MOD; n           ++l, ++r, w += step; n         } n       } n     } n     if (inv) reverse(fftw.begin() + 1, fftw.end()); n     if (inv) { n       int mlt = pw(n, MOD - 2); n       for (int i = (0); i < (n); ++i) a[i] = (long long)a[i] * mlt % MOD; n     } n   } n   void mult(const int *a, int na, const int *b, int nb, int *c, int nc) { n     int sz = 1; n     while (sz < na + nb - 1) sz *= 2; n     vector<int> A(sz, 0), B(sz, 0); n     for (int i = (0); i < (na); ++i) A[i] = a[i]; n     for (int i = (0); i < (nb); ++i) B[i] = b[i]; n     fft(A.data(), sz, false); n     fft(B.data(), sz, false); n     for (int i = (0); i < (sz); ++i) A[i] = (long long)A[i] * B[i] % MOD; n     fft(A.data(), sz, true); n     for (int i = (0); i < (nc); ++i) c[i] = i < sz ? A[i] : 0; n   } n }; n NTT ntt; n void inc(int &a, int b) { n   if ((a += b) >= MOD) a -= MOD; n } n vector<int> add(const vector<int> &a, const vector<int> &b) { n   vector<int> c(max(((int)(a).size()), ((int)(b).size())), 0); n   for (int i = (0); i < (((int)(c).size())); ++i) { n     if (i < ((int)(a).size())) inc(c[i], a[i]); n     if (i < ((int)(b).size())) inc(c[i], b[i]); n   } n   return c; n } n vector<int> mult(const vector<int> &a, const vector<int> &b) { n   vector<int> c(((int)(a).size()) + ((int)(b).size()) - 1, 0); n   ntt.mult(a.data(), ((int)(a).size()), b.data(), ((int)(b).size()), c.data(), n            ((int)(c).size())); n   return c; n } n const int MAXN = 100000; n int n; n long long want; n vector<int> adj[MAXN]; n int par[MAXN]; n int sz[MAXN]; n int dep[MAXN]; n int heavy[MAXN]; n vector<int> ways[MAXN]; n vector<int> waysnonheavy[MAXN]; n void dfsinit(int at) { n   dep[at] = par[at] == -1 ? 0 : dep[par[at]] + 1, sz[at] = 1, heavy[at] = -1; n   for (int i = (0); i < (((int)(adj[at]).size())); ++i) { n     int to = adj[at][i]; n     if (to == par[at]) continue; n     par[to] = at; n     dfsinit(to); n     sz[at] += sz[to]; n     if (heavy[at] == -1 || sz[to] > sz[heavy[at]]) heavy[at] = to; n   } n } n int path[MAXN], npath; n pair<vector<int>, vector<int>> rec(int l, int r) { n   if (l == r) { n     int at = path[l]; n     return make_pair(waysnonheavy[at], waysnonheavy[at]); n   } else { n     int m = l + (r - l) / 2; n     auto res1 = rec(l, m); n     auto res2 = rec(m + 1, r); n     return make_pair(add(res1.first, mult(res1.second, res2.first)), n                      mult(res1.second, res2.second)); n   } n } n int lst[MAXN], nlst; n vector<int> tmp[2 * MAXN]; n int ntmp; n priority_queue<pair<int, int>> pq; n void calcways(int at); n void calcwaysnonheavy(int at) { n   for (int i = (0); i < (((int)(adj[at]).size())); ++i) { n     int to = adj[at][i]; n     if (to == par[at] || to == heavy[at]) continue; n     calcways(to); n   } n   nlst = 0; n   for (int i = (0); i < (((int)(adj[at]).size())); ++i) { n     int to = adj[at][i]; n     if (to == par[at] || to == heavy[at]) continue; n     lst[nlst++] = to; n   } n   ntmp = nlst; n   pq = priority_queue<pair<int, int>>(); n   for (int i = (0); i < (nlst); ++i) n     tmp[i] = ways[lst[i]], pq.push(make_pair(-((int)(tmp[i]).size()), i)); n   while (((int)(pq).size()) >= 2) { n     int a = pq.top().second; n     pq.pop(); n     int b = pq.top().second; n     pq.pop(); n     int c = ntmp++; n     tmp[ntmp] = mult(tmp[a], tmp[b]), n     pq.push(make_pair(-((int)(tmp[c]).size()), c)); n   } n   waysnonheavy[at] = n       ((int)(pq).size()) == 1 ? tmp[pq.top().second] : vector<int>(1, 1); n   waysnonheavy[at].insert(waysnonheavy[at].begin(), 0); n   for (int i = (0); i < (ntmp); ++i) tmp[i].clear(); n } n void calcways(int at) { n   for (int x = at; x != -1; x = heavy[x]) calcwaysnonheavy(x); n   npath = 0; n   for (int x = at; x != -1; x = heavy[x]) path[npath++] = x; n   ways[at] = rec(0, npath - 1).first; n   inc(ways[at][0], 1); n } n int inv[MAXN + 1]; n void run() { n   scanf( %d%lld , &n, &want); n   for (int i = (0); i < (n - 1); ++i) { n     int a, b; n     scanf( %d%d , &a, &b); n     --a, --b; n     adj[a].push_back(b); n     adj[b].push_back(a); n   } n   par[0] = -1; n   dfsinit(0); n   calcways(0); n   int ret = 0, mlt = 1; n   inv[1] = 1; n   for (int i = (2); i < (((int)(ways[0]).size())); ++i) n     inv[i] = (long long)(MOD - MOD / i) * inv[MOD % i] % MOD; n   for (int i = (1); i < (((int)(ways[0]).size())); ++i) { n     ret = (ret + (long long)ways[0][i] * mlt) % MOD; n     mlt = (long long)mlt * (want % MOD + i) % MOD * inv[i] % MOD; n   } n   printf( %d n , ret); n } n int main() { n   run(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   char a[200005]; n   cin >> a; n   for (int i = 0; a[i] !=   0 ; ++i) { n     if (i && a[i - 1] == a[i]) { n       if (a[i - 1] !=  x  && a[i + 1] !=  x ) n         a[i] =  x ; n       else if (a[i - 1] !=  y  && a[i + 1] !=  y ) n         a[i] =  y ; n       else n         a[i] =  z ; n     } n   } n   cout << a << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename X> n void MA(X& a, X b) { n   a = max(a, b); n } n template <typename X> n void MI(X& a, X b) { n   a = min(a, b); n } n template <typename X> n void clr(X& x, int a) { n   memset(x, a, sizeof(x)); n }; n int cond = 0, multi = 0, gcj = 0; n int N; n const int MAXN = 111; n vector<array<int, 2> > ED[MAXN]; n long double wsp[MAXN]; n array<int, 3> res[MAXN]; n int numkr = 0; n void go(int u, int p, long double val) { n   int kr = 0; n   kr += ED[u].size(); n   { n     if (cond) n       cerr << 38 <<     n            <<  u <<     << kr <<     << val  n            <<     << u <<     << kr <<     << val << endl; n   }; n   val += 2.0 / kr; n   while (val >= 2.0) val -= 2.0; n   for (array<int, 2> ed : ED[u]) n     if (ed[0] != p) { n       int v = ed[0]; n       int idx = ed[1]; n       { n         if (cond) n           cerr << 45 <<     n                <<  u <<     << v <<     << val  n                <<     << u <<     << v <<     << val << endl; n       }; n       go(v, u, 1 + val); n       if (val <= 1.0) { n         res[numkr] = array<int, 3>({v, u, idx}); n         wsp[numkr] = 1.0 - val; n       } else { n         res[numkr] = array<int, 3>({u, v, idx}); n         wsp[numkr] = 2.0 - val; n       } n       numkr++; n       val += 2.0 / kr; n       while (val >= 2.0) val -= 2.0; n     } n } n void solve() { n   cin >> N; n   for (auto i = (1); i <= (N - 1); ++i) { n     int u, v; n     cin >> u >> v; n     ED[u].push_back(array<int, 2>({v, i})); n     ED[v].push_back(array<int, 2>({u, i})); n   } n   go(1, -1, 0); n   cout << N - 1 <<   n ; n   for (auto i = 0; i < (N - 1); ++i) { n     cout << 1 <<     << res[i][2] <<     << res[i][0] <<     << res[i][1] <<     n          << wsp[i] <<   n ; n   } n } n int main(int argc, char** argv) { n   ios::sync_with_stdio(false), cin.tie(0), n       cond = argc >= 2 && argv[1][0] ==  q  ? 1 << 30 : 0; n   cout.setf(ios::fixed), cout.precision(10); n   int t; n   if (multi || gcj) n     cin >> t; n   else n     t = 1; n   for (auto i = (1); i <= (t); ++i) { n     if (cond) cerr << 84 <<     << i << endl; n     if (gcj) cout <<  Case #  << i <<  :  ; n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool comp(const pair<int, int> &a, const pair<int, int> &b) { n   return (a.second < b.second); n } n long long gcd(long long a, long long b) { n   if (!b) return a; n   return gcd(b, a % b); n } n int main() { n   long long n, k; n   cin >> n >> k; n   long long lx[43]; n   if (k == 1) n     cout <<  Yes n ; n   else { n     if (k > 42ll) n       cout <<  No n ; n     else { n       lx[1] = 1; n       for (long long i = 2; i < 43; i++) { n         lx[i] = lx[i - 1] * (i / gcd(lx[i - 1], i)); n       } n       if ((n + 1) % lx[k] == 0) n         cout <<  Yes n ; n       else n         cout <<  No n ; n     } n   } n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,no-stack-protector ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC optimize( fast-math ) n using namespace std; n template <class T> n ostream &operator<<(ostream &str, vector<T> &a) { n   for (auto &i : a) { n     str << i <<    ; n   } n   return str; n } n template <class T> n istream &operator>>(istream &str, vector<T> &a) { n   for (auto &i : a) { n     str >> i; n   } n   return str; n } n template <class T> n ostream &operator<<(ostream &str, pair<T, T> &a) { n   str << a.first <<     << a.second; n   return str; n } n template <class T> n istream &operator>>(istream &str, pair<T, T> &a) { n   str >> a.first >> a.second; n   return str; n } n void solve(); n signed main() { n   srand(time(0)); n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cout.setf(ios::fixed); n   cout.precision(6); n   solve(); n   return 0; n } n int n, m; n int get_sum(vector<vector<int>> &b, int i1, int j1, int i2, int j2) { n   return b[i2][j2] - b[i1 - 1][j2] - b[i2][j1 - 1] + b[i1 - 1][j1 - 1]; n } n bool check(int k, vector<vector<int>> &a, vector<vector<int>> &b, n            vector<vector<int>> &tmp) { n   int len = 2 * k + 1; n   if (len > n || len > m) { n     return false; n   } n   vector<vector<int>> v(m + 2, vector<int>(n + 2)); n   for (int i = 1; i <= n - len + 1; ++i) { n     for (int j = 1; j <= m - len + 1; ++j) { n       int sum = get_sum(b, i, j, i + len - 1, j + len - 1); n       if (sum == len * len) { n         tmp[i + len / 2][j + len / 2] = 1; n         v[j][i] += 1, v[j][i + len] -= 1; n         v[j + len][i] -= 1, v[j + len][i + len] += 1; n       } n     } n   } n   for (int j = 1; j <= m; ++j) { n     for (int i = 1; i <= n; ++i) { n       v[j][i] = v[j][i - 1] + v[j][i]; n     } n   } n   vector<vector<int>> c(n + 1, vector<int>(m + 1)); n   for (int j = 1; j <= m; ++j) { n     for (int i = 1; i <= n; ++i) { n       c[i][j] = v[j][i]; n     } n   } n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) { n       c[i][j] = c[i][j - 1] + c[i][j]; n     } n   } n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) { n       if (a[i][j] && c[i][j] == 0) { n         return false; n       } n     } n   } n   return true; n } n void solve() { n   cin >> n >> m; n   vector<vector<int>> a(n + 1, vector<int>(m + 1)); n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) { n       char ch; n       cin >> ch; n       a[i][j] = (ch ==  X  ? 1 : 0); n     } n   } n   vector<vector<int>> b = a; n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) { n       b[i][j] = b[i][j] + b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1]; n     } n   } n   vector<vector<int>> ans(n + 1, vector<int>(m + 1)); n   int l = 0, r = min(n, m); n   while (r - l > 1) { n     int k = (r + l) / 2; n     vector<vector<int>> tmp(n + 1, vector<int>(m + 1)); n     if (check(k, a, b, tmp)) { n       ans = tmp; n       l = k; n     } else { n       r = k; n     } n   } n   check(l, a, b, ans); n   cout << (l) <<   n ; n   ; n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) { n       cout << (ans[i][j] ?  X  :  . ); n     } n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n  n #define S size() n #define EN end() n #define BE begin() n #define LEN length() n  n #define endl   n  n #define cnt count n #define in insert n #define er erase n #define fi first n #define se second n #define ld double n #define int long long n  n #define gcd __gcd n #define mp make_pair n #define pb push_back n #define lb lower_bound n #define ub upper_bound n #define bs binary_search n #define np next_permutation n  n #define si set<int> n #define sc set<char> n #define mll map<int,int> n #define vi vector<int> n #define vc vector<char> n #define pll pair<int,int> n #define vpi vector<pll> n #define msi multiset<int> n #define msc multiset<char> n #define vvi vector<vector<int>> n  n #define mod1 1000000007 n #define mod2 998244353 n #define inf (int)1e9 n #define eness(x) __builtin_ctzll(x) n #define nhigh(x) __builtin_popcountll(x) n #define PI 3.1415926535897932384626433832 n  n #define iter(s) for(auto it:s) n #define forl(i,n) for(int i=0;i<n;i++) n #define fore(i,n) for(int i=1;i<=n;i++) n #define forn(i,n) for(int i=n-1;i>=0;i--) n #define forls(i,l,r) for(int i=l;i<r;i++) n #define forns(i,l,r) for(int i=r-1;i>=l;i--) n  n #define all(v) v.BE,v.EN n #define SORT(ar,n) sort(ar,ar+n) n #define rall(v) v.rbegin(),v.rend() n #define RSORT(ar,n) sort(ar,ar+n,greater<int>()) n  n #define pat int n;cin>>n; n #define wq int q;cin>>q;fore(_,q) n #define nokay cout<<(ok? Yes n : No n ); n #define tak(s) string s;cin>>s;int n=s.LEN; n #define pat1 int n;cin>>n;int ar[n];forl(i,n) cin>>ar[i]; n #define pat2 int n,k;cin>>n>>k;int ar[n];forl(i,n) cin>>ar[i]; n #define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); n //********************************** n vi mf,mi; n int POW(int x,int y); n int MI(int x,int mod); n void pre_f(int x,int mod); n void pre_i(int x,int mod); n int C(int x,int y,int mod); n int bpow(int x,int y,int mod); n  n int POW(int x,int y){ n     return bpow(x,y,inf); n } n int MI(int x,int mod=mod1){ n     return bpow(x,mod-2,mod); n } n void pre_f(int x,int mod=mod1){ n     mf=vi(x+1,1); n     forls(i,2,x+1){ n         mf[i]=mf[i-1]*i; n         mf[i]%=mod; n     } n     return; n } n void pre_i(int x,int mod=mod1){ n     mi=vi(x+1); n     forl(i,x+1){ n         mi[i]=MI(mf[i],mod); n     } n     return; n } n int C(int x,int y,int mod=mod1){ n     if(x<y) return 0; n     int n1=mf[x]; n     int n2=mi[y]; n     int n3=mi[x-y]; n     int res=(n1*n2)%mod; n     res=(res*n3)%mod; n     return res; n } n int bpow(int x,int y,int mod=mod1){ n     x%=mod; n     int res=1; n     while(y>0){ n         if(y&1){ n             res=res*x%mod; n         } n         x=x*x%mod; n         y>>=1; n     } n     return res; n } n //********************************** n const int N=200001; n vector<vector<array<int,2>>> adj(N); n int32_t main(){ n     #ifndef ONLINE_JUDGE n         freopen( ./input.txt ,  r , stdin); n         freopen( ./output.txt ,  w , stdout); n     #endif n     fastio; n     int n,m; n     cin>>n>>m; n     int dis[n+1][51]; n     forl(i,n+1){ n         forl(j,51){ n             dis[i][j]=inf; n         } n     } n  n     forl(i,m){ n         int u,v,w; n         cin>>u>>v>>w; n         adj[u].pb({v,w}); n         adj[v].pb({u,w}); n     } n     dis[1][0]=0; n     //i*51+j -> row dom. n     set<array<int,2>> pq; n     pq.in({0,51}); n     //int t=100; n     while(!pq.empty()/* && t--*/){ n         //auto itt=pq.BE n         set<array<int,2>>::iterator itt=pq.BE; n         array<int,2> x=*itt; n         pq.er(itt); n         int d=x[0],p=x[1]%51,u=x[1]/51; n         iter(adj[u]){ n             int v=it[0],w=it[1]; n             //cout<<u<<   <<v<<   <<p<<  n ; n             if(p==0){ n                 int dd=(d); n                 if(dis[v][w]>dd){ n                     set<array<int,2>>::iterator fin=pq.find({dis[v][w],v*51+w}); n                     if(fin!=pq.end()){ n                         pq.er(fin); n                     } n                     dis[v][w]=dd; n                     pq.in({dd,v*51+w}); n                 } n             } n             else{ n                 int dd=(d+(p+w)*(p+w)); n                 if(dis[v][0]>dd){ n                     set<array<int,2>>::iterator fin=pq.find({dis[v][0],v*51}); n                     if(fin!=pq.end()){ n                         pq.er(fin); n                     } n                     dis[v][0]=dd; n                     pq.in({dd,v*51}); n                 } n             } n         } n     } n     fore(i,n){ n         if(dis[i][0]==inf){ n             cout<<-1<<   ; n         } n         else{ n             cout<<dis[i][0]<<   ; n         } n     } n      n }


#include <bits/stdc++.h> n using namespace std; n long long get(long long r) { return (r + 1) * r / 2; } n long long sumto(long long r, int need) { n   long long pw = 1; n   long long sum = 0; n   long long add = 0; n   for (int len = 1;; ++len) { n     if (pw * 10 - 1 < r) { n       long long cnt = pw * 10 - pw; n       if (need) { n         sum += add * cnt + get(cnt) * len; n         add += cnt * len; n       } else { n         sum += cnt * len; n       } n     } else { n       long long cnt = r - pw + 1; n       if (need) { n         sum += add * cnt + get(cnt) * len; n       } else { n         sum += cnt * len; n       } n       break; n     } n     pw *= 10; n   } n   return sum; n } n int main() { n   int q; n   cin >> q; n   while (q--) { n     long long k; n     cin >> k; n     --k; n     long long l = 1, r = 1e9; n     long long res = -1; n     while (r - l >= 0) { n       long long mid = (l + r) >> 1; n       if (sumto(mid, 1) > k) { n         res = mid; n         r = mid - 1; n       } else { n         l = mid + 1; n       } n     } n     k -= sumto(res - 1, 1); n     l = 1, r = res; n     long long num = -1; n     while (r - l >= 0) { n       int mid = (l + r) >> 1; n       if (sumto(mid, 0) > k) { n         num = mid; n         r = mid - 1; n       } else { n         l = mid + 1; n       } n     } n     cout << to_string(num)[k - sumto(num - 1, 0)] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int ans, b, a, f, s, k, ss; n int main() { n   cin >> a >> b; n   if (a == b) { n     cout <<  infinity ; n     return 0; n   } n   if (a < b) { n     cout << 0; n     return 0; n   } n   for (int i = 1; i <= round(sqrt(a - b)); i++) { n     if ((a - b) % i == 0) ans++; n     if (((a - b) % i == 0 && i <= b)) s++; n     if ((a - b) % i == 0 && (a - b) / i <= b) s++; n   } n   ans *= 2; n   if (round(sqrt(a - b)) * round(sqrt(a - b)) == a - b) { n     ans--; n     if (round(sqrt(a - b)) <= b) s--; n   } n   ans -= s; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   int n, m = 0, sum = 0; n   cin >> n; n   string s; n   getline(cin, s); n   getline(cin, s); n   for (int i = 0; i < n; i++) { n     if (s[i] ==    ) { n       m = max(m, sum); n       sum = 0; n     } n     if (s[i] >=  A  && s[i] <=  Z ) sum++; n   } n   m = max(m, sum); n   cout << m; n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b, n; n long long vet[2000010]; n bool comp(long long l, long long maior, long long meio, long long m, n           long long t) { n   if (a + ((meio - 1) * b) > t) return false; n   if (vet[meio] - vet[l - 1] > m * t) return false; n   return true; n } n int main() { n   cin >> a >> b >> n; n   for (int i = 0; i < 2000008; ++i) { n     if (i == 0) { n       vet[i] = 0; n     } else { n       vet[i] = ((a) + (i - 1) * b) + vet[i - 1]; n     } n   } n   for (int i = 0; i < n; ++i) { n     long long l, t, m; n     cin >> l >> t >> m; n     long long menor = l, maior = t + 5, meio; n     while (menor <= maior) { n       meio = (maior + menor) / 2; n       if (comp(l, maior, meio, m, t)) n         menor = meio + 1; n       else n         maior = meio - 1; n     } n     if (maior < l) n       cout <<  -1  << endl; n     else n       cout << maior << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n int v[26][N]; n int main() { n   int n; n   cin >> n; n   string s; n   for (int i = 0; i < n; ++i) { n     cin >> s; n     for (int j = 0; j < s.size(); j++) n       if (s[j] !=  ? ) v[s[j] -  a ][j]++; n   } n   string ans =   ; n   int pos = 0; n   for (int i = 0; i < s.size(); ++i) { n     int may = 0; n     for (int j = 0; j < 26; j++) { n       if (may < v[j][i]) { n         may = v[j][i]; n         pos = j; n       } n     } n     int a1 = 0; n     bool flag = 0; n     char x =  * ; n     for (int j = 0; j < 26; j++) { n       if (may == v[j][i] or (v[j][i] != may && v[j][i])) a1++, flag = 1; n       if (flag && !v[j][i]) { n         if (a1 <= 1) x = j; n         flag = 0; n       } n     } n     if (a1 == 1) n       ans += char(pos) +  a ; n     else { n       if (may != 0) n         ans +=  ? ; n       else n         ans += char(x) +  a ; n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 998244353; n long long exp(long long n, long long m, long long md) { n   long long a = 1; n   while (m > 0) { n     if (m & 1) a = (a * n % md) % md; n     m /= 2; n     n = (n * n) % md; n   } n   return a % md; n } n long long R = MOD; n long long modInverse(long long n) { return exp(n, R - 2, R); } n long long ncr(long long n, long long r) { n   if (r == 0) return 1; n   vector<long long> fac(n + 1, 1); n   for (long long i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % R; n   return ((fac[n] * modInverse(fac[r]) % R) * modInverse(fac[n - r]) % R) % R; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long n, k; n   cin >> n >> k; n   if (k > n) n     cout << 0 <<   n ; n   else if (k == 1) n     cout << n <<   n ; n   else { n     long long ans = 0; n     for (long long i = 1; i * k <= n; i++) { n       ans += ncr(n / i - 1, k - 1); n       ans %= R; n     } n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int P = 10, N = 1e5 + 10; n inline int inverse(int a, int m) { n   if (a <= 1) return a; n   int ans = (1 - (long long int)inverse(m % a, a) * m) / a; n   return ans + m; n } n int fact[N], ifact[N], pot[N][P]; n int sz, p[P]; n inline void primes(int n) { n   for (int d = 2; d * d <= n; d++) n     if (n % d == 0) { n       p[sz++] = d; n       while (n % d == 0) n /= d; n     } n   if (n > 1) p[sz++] = n; n } n int mod; n int expo[P][N]; n inline int comb(int m, int n) { n   int ans = (long long int)fact[m] * ifact[n] % mod * ifact[m - n] % mod; n   for (register int i = 0; i < (int)(sz); ++i) { n     int pp = pot[m][i] - pot[n][i] - pot[m - n][i]; n     if (pp) ans = (long long int)ans * expo[i][pp] % mod; n   } n   return ans; n } n inline int go(int n, int bal) { n   long long int ans = 0; n   for (register int x = 0, y = bal; x + y <= n; ++x, ++y) n     ans += (long long int)comb(n, x) * comb(n - x, y) % mod; n   return ans % mod; n } n int main() { n   int n, l, r; n   cin >> n >> mod >> l >> r; n   primes(mod); n   fact[0] = ifact[0] = 1; n   int fn = 1; n   for (register int j = 0; j < (int)(sz); ++j) expo[j][0] = 1; n   for (int i = 1; i <= n; i++) { n     int d = -1; n     for (register int j = 0; j < (int)(sz); ++j) n       if (i % p[j] == 0) { n         d = j; n         break; n       } n     if (d == -1) n       fact[i] = i; n     else { n       fact[i] = fact[i / p[d]]; n       for (register int j = 0; j < (int)(sz); ++j) n         pot[i][j] = pot[i / p[d]][j] + (j == d); n     } n     fn = (long long int)fn * fact[i] % mod; n     for (register int j = 0; j < (int)(sz); ++j) n       expo[j][i] = (long long int)expo[j][i - 1] * p[j] % mod; n   } n   ifact[n] = inverse(fn, mod); n   for (register int i = n - 1; i >= 0; --i) n     ifact[i] = (long long int)ifact[i + 1] * fact[i + 1] % mod; n   for (register int i = 1; i <= n; ++i) { n     fact[i] = (long long int)fact[i - 1] * fact[i] % mod; n     for (register int j = 0; j < (int)(sz); ++j) pot[i][j] += pot[i - 1][j]; n   } n   long long int ans = 0; n   for (register int i = 0; i < (int)(2); ++i) n     ans += (long long int)go(n, l + i) + mod - go(n, r + 1 + i); n   cout << ans % mod << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   deque<int> vec; n   int arr[200005]; n   int n, a; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &a); n     vec.push_back(a); n     arr[i] = 0; n   } n   for (int i = 0; i < n; i++) { n     scanf( %d , &a); n     int j = 0, i1 = 0; n     if (arr[a - 1] == 1) { n       printf( 0  ); n     } else if (vec.empty() != true) { n       int k = 0, f = 0; n       while (true) { n         arr[vec.front() - 1] = 1; n         if (vec.front() == a) { n           vec.pop_front(); n           break; n         } n         vec.pop_front(); n         k++; n       } n       printf( %d  , k + 1); n     } else n       printf( 0  ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-9; n template <class T> n struct RMQ { n   const int STEP_P = 5; n   const int STEP = 1 << STEP_P; n   vector<T> data; n   const T INF; n   vector<vector<T> > small_powers; n   vector<vector<T> > group_powers; n   int N; n   RMQ(vector<T> data_, T INF_) : data(data_), INF(INF_){}; n   void init() { n     N = int((data).size()); n     small_powers = vector<vector<T> >(STEP_P + 1, vector<T>(N)); n     small_powers[0] = data; n     for (int p = (0); p < (STEP_P); p++) n       for (int n = (0); n < (N); n++) { n         small_powers[p + 1][n] = n             min(small_powers[p][n], small_powers[p][min(n + (1 << p), N - 1)]); n       } n     int GN = (N + STEP - 1) / STEP; n     int GP = 1; n     while (GN > (1 << GP)) ++GP; n     group_powers = vector<vector<T> >(GP + 1, vector<T>(GN)); n     for (int i = (0); i < (GN); i++) n       group_powers[0][i] = small_powers[STEP_P][i << STEP_P]; n     for (int p = (0); p < (GP); p++) n       for (int n = (0); n < (GN); n++) { n         group_powers[p + 1][n] = n             min(group_powers[p][n], group_powers[p][min(n + (1 << p), GN - 1)]); n       } n   } n   int largest_bit(int n) { return 31 - __builtin_clz(max(1, n - 1)); } n   T query(int f, int t) { n     assert(f >= 0 && t <= N); n     if (f >= t) return INF; n     int p = min(STEP_P, largest_bit(t - f)); n     auto res = min(small_powers[p][f], small_powers[p][t - (1 << p)]); n     if (t - f > STEP + STEP) { n       int g_f = f / STEP + 1, g_t = t / STEP; n       p = largest_bit(g_t - g_f); n       res = n           min(res, min(group_powers[p][g_f], group_powers[p][g_t - (1 << p)])); n     } n     return res; n   } n }; n const int MAXN = 5e5; n int A[MAXN]; n vector<int> adj[MAXN]; n vector<long long> dp_only[MAXN]; n vector<long long> dp_not[MAXN]; n long long dp_all[MAXN]; n int todo[MAXN]; n int xo[MAXN]; n long long cost[MAXN]; n int etox[MAXN][2]; n int edgeval[MAXN][2]; n int N, Q; n long long calc_not(int n, int eid) { n   int xid = etox[eid][0]; n   if (int((adj[n]).size()) <= xid || adj[n][xid] != eid) xid = etox[eid][1]; n   if (dp_not[n][xid] == -1) { n     if (dp_all[n] == -1) { n       dp_all[n] = A[n]; n       todo[n] = xid; n       for (int i = (0); i < (int((adj[n]).size())); i++) n         if (i != xid) { n           int neid = adj[n][i]; n           dp_only[n][i] = n               max(0ll, calc_not(xo[neid] ^ n, neid) - cost[neid] * 2ll); n           dp_all[n] += dp_only[n][i]; n         } n       dp_not[n][xid] = dp_all[n]; n     } else if (todo[n] != -1) { n       int neid = adj[n][todo[n]]; n       dp_only[n][todo[n]] = n           max(0ll, calc_not(xo[neid] ^ n, neid) - cost[neid] * 2ll); n       dp_all[n] += dp_only[n][todo[n]]; n       assert(dp_only[n][xid] != -1); n       dp_not[n][xid] = dp_all[n] - dp_only[n][xid]; n       todo[n] = -1; n     } else { n       assert(dp_only[n][xid] != -1); n       dp_not[n][xid] = dp_all[n] - dp_only[n][xid]; n     } n   } n   return dp_not[n][xid]; n } n long long calc_only(int n, int eid) { n   int xid = etox[eid][0]; n   if (adj[n][xid] != eid) xid = etox[eid][1]; n   assert(adj[n][xid] == eid); n   assert(dp_only[n][xid] != -1); n   return dp_only[n][xid]; n } n int parent_edge[MAXN]; n int depth[MAXN]; n long long dp_acc[MAXN]; n pair<int, int> tmp_rmqdata[MAXN * 2]; n int rmqposition[MAXN]; n int TMP_RMQDATA; n void calc_accumulate(int n) { n   rmqposition[n] = TMP_RMQDATA; n   tmp_rmqdata[TMP_RMQDATA++] = make_pair(depth[n], n); n   for (auto eid : adj[n]) n     if (eid != parent_edge[n]) { n       int to = xo[eid] ^ n; n       dp_acc[to] = n           dp_acc[n] - calc_only(n, eid) - cost[eid] + calc_not(to, eid); n       depth[to] = depth[n] + 1; n       parent_edge[to] = eid; n       calc_accumulate(to); n       tmp_rmqdata[TMP_RMQDATA++] = make_pair(depth[n], n); n     } n } n int main() { n   ios::sync_with_stdio(false); n   cin >> N >> Q; n   for (int i = (1); i < (N + 1); i++) cin >> A[i]; n   for (int i = (0); i < (N + 1); i++) adj[i].clear(); n   for (int i = (1); i < (N); i++) { n     int a, b; n     long long c; n     cin >> a >> b >> c; n     etox[i][0] = int((adj[a]).size()); n     etox[i][1] = int((adj[b]).size()); n     adj[a].push_back(i); n     adj[b].push_back(i); n     xo[i] = a ^ b; n     cost[i] = c; n     edgeval[i][0] = a; n     edgeval[i][1] = b; n   } n   for (int i = (1); i < (N + 1); i++) n     dp_not[i] = dp_only[i] = vector<long long>(int((adj[i]).size()), -1); n   for (int i = (1); i < (N + 1); i++) dp_all[i] = -1; n   for (int i = (1); i < (N + 1); i++) n     for (auto e : adj[i]) calc_not(i, e); n   for (int n = (1); n < (N + 1); n++) { n     assert(dp_all[n] != -1); n     if (todo[n] != -1) { n       int neid = adj[n][todo[n]]; n       dp_only[n][todo[n]] = n           max(0ll, calc_not(xo[neid] ^ n, neid) - cost[neid] * 2ll); n       dp_all[n] += dp_only[n][todo[n]]; n       todo[n] = -1; n     } n     for (int i = (0); i < (int((adj[i]).size())); i++) n       assert(dp_only[n][i] != -1); n     for (int i = (0); i < (int((adj[i]).size())); i++) n       assert(dp_not[n][i] != -1); n   } n   parent_edge[1] = -1; n   dp_acc[1] = dp_all[1]; n   depth[1] = 0; n   TMP_RMQDATA = 0; n   calc_accumulate(1); n   vector<pair<int, int> > rmqdata(tmp_rmqdata, tmp_rmqdata + TMP_RMQDATA); n   cerr << TMP_RMQDATA << endl; n   RMQ<pair<int, int> > rmq(rmqdata, make_pair(N + 1, N + 1)); n   rmq.init(); n   for (int q = (0); q < (Q); q++) { n     int a, b; n     cin >> a >> b; n     if (rmqposition[b] < rmqposition[a]) swap(a, b); n     int lc = rmq.query(rmqposition[a], rmqposition[b] + 1).second; n     assert(lc > 0 && lc <= N); n     long long ares = dp_acc[a] + dp_acc[b] - 2 * dp_acc[lc] + dp_all[lc]; n     cout << ares << endl; n   } n   return 0; n   for (int i = (1); i < (N + 1); i++) { n     cout << i <<  : all=  << dp_all[i]; n     for (auto eid : adj[i]) { n       cout <<   (  << i <<  ->  << (xo[eid] ^ i) <<  ):not=  << calc_not(i, eid) n            <<   only=  << calc_only(i, eid); n     } n     cout << endl; n   } n   for (int i = (1); i < (N + 1); i++) { n     cout << i <<   dp=  << dp_acc[i] <<   depth=  << depth[i]; n     if (parent_edge[i] != -1) cout <<   parent=  << (xo[parent_edge[i]] ^ i); n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dfs(vector<int>* v, int n) { n   int cost = -1; n   for (int i = 1; i <= n; i++) { n     for (int j = i + 1; j <= n; j++) { n       if (binary_search(v[i].begin(), v[i].end(), j) == 0) continue; n       for (int k = 0; k < v[i].size(); k++) { n         for (int s = 0; s < v[j].size(); s++) { n           if (v[i][k] == v[j][s]) { n             int p = v[i][k]; n             int ct = v[i].size() + v[j].size() + v[p].size() - 6; n             if (cost == -1) { n               cost = ct; n             } else { n               cost = min(cost, ct); n             } n             break; n           } n         } n       } n     } n   } n   return cost; n } n int main() { n   int n, m; n   cin >> n >> m; n   vector<int> v[n + 1]; n   for (int i = 0; i < m; i++) { n     int x, y; n     cin >> x >> y; n     v[x].push_back(y); n     v[y].push_back(x); n   } n   for (int i = 1; i < n + 1; i++) { n     sort(v[i].begin(), v[i].end()); n   } n   int cost = dfs(v, n); n   cout << cost <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> v[100001]; n long long arr[100001]; n int visit[100001]; n void dfs(int s, long long *pos, long long *neg) { n   visit[s] = 1; n   int i; n   long long k, maxi = 0, mini = 0, ps = 0, ng = 0; n   for (i = 0; i < v[s].size(); i++) { n     if (!visit[v[s][i]]) { n       dfs(v[s][i], &ps, &ng); n       if (ps > maxi) maxi = ps; n       if (ng < mini) mini = ng; n     } n   } n   *pos = maxi; n   *neg = mini; n   k = arr[s] + maxi + mini; n   if (k < 0) n     *pos = *pos - k; n   else n     *neg = *neg - k; n } n int main() { n   int n, i, a, b; n   long long pos = 0, neg = 0; n   scanf( %d , &n); n   for (i = 0; i < n - 1; i++) { n     scanf( %d%d , &a, &b); n     v[a].push_back(b); n     v[b].push_back(a); n   } n   for (i = 1; i <= n; i++) cin >> arr[i]; n   dfs(1, &pos, &neg); n   cout << pos - neg; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n struct Sync_stdio { n   Sync_stdio() { n     cin.tie(NULL); n     ios_base::sync_with_stdio(false); n   } n } _sync_stdio; n long long n, k; n void solve(vector<long long> &v, vector<long long> &a) { n   for (int i = (0); i < (n); ++i) { n     a[i + 1] += a[i] / 2; n     a[i] %= 2; n     if (a[i] == -1) { n       --a[i + 1]; n       a[i] = 1; n     } n   } n   if (a[n] < 0) { n     return; n   } n   long long pos = 0; n   for (int i = (0); i < (n + 1); ++i) { n     if (a[i] != 0) { n       pos = i; n       break; n     } n   } n   long long res = 0; n   long double res2 = 0; n   for (int i = (pos); i < (min(n + 1, pos + 36)); ++i) { n     res += (1LL << (i - pos)) * a[i]; n     res2 += (1LL << (i - pos)) * a[i]; n   } n   for (int i = (min(n + 1, pos + 35)); i < (n + 1); ++i) { n     if (a[i] != 0) { n       cout << 0 <<   n ; n       exit(0); n     } n   } n   if (res2 > 1e11) { n     cout << 0; n     exit(0); n   } n   long long ans = 0; n   long long t = res; n   for (int i = (pos); i > (-1); --i) { n     if (t > 1e12) { n       break; n     } n     if (pos != n || t != v[i]) { n       if (t <= v[i] + k) { n         ++ans; n       } n     } n     t *= 2; n   } n   cout << ans; n   exit(0); n } n int main() { n   cin >> n >> k; n   vector<long long> v(n + 1); n   for (int __i = 0; __i < (n + 1); ++__i) cin >> v[__i]; n   ; n   vector<long long> a = v; n   solve(v, a); n   a = v; n   for (int i = (0); i < (n + 1); ++i) { n     v[i] = -v[i]; n     a[i] = -a[i]; n   } n   solve(v, a); n } n


#include <bits/stdc++.h> n using namespace std; n class solve { n  private: n   int n, lar, les; n   vector<int> val[2]; n   vector<int> res[2]; n   vector<long long> sum[2]; n  n  private: n   int find_first_less(int i); n  n  public: n   void func(); n }; n void solve::func() { n   cin >> n; n   val[0].resize(n + 1, 0); n   val[1].resize(n + 1, 0); n   sum[0].resize(n + 1, 0); n   sum[1].resize(n + 1, 0); n   for (int k = 0; k < 2; k++) n     for (int i = 1; i <= n; i++) { n       scanf( %d , &val[k][i]); n       sum[k][i] = sum[k][i - 1] + val[k][i]; n     } n   if (sum[0][n] >= sum[1][n]) n     lar = 0; n   else n     lar = 1; n   les = 1 - lar; n   map<long long, pair<int, int> > diff_pair; n   diff_pair[0] = make_pair(0, 0); n   for (int i = 1; i <= n; i++) { n     int l = 0, r = n, m; n     while (l < r) { n       m = (l + r + 1) / 2; n       if (sum[les][i] >= sum[lar][m]) n         l = m; n       else n         r = m - 1; n     } n     long long diff = sum[les][i] - sum[lar][l]; n     if (diff_pair.count(diff) != 0) { n       for (int j = diff_pair[diff].first + 1; j <= i; j++) n         res[les].push_back(j); n       for (int j = diff_pair[diff].second + 1; j <= l; j++) n         res[lar].push_back(j); n       break; n     } else n       diff_pair[diff] = make_pair(i, l); n   } n   printf( %d n , (int)res[0].size()); n   for (int i = 0; i < res[0].size(); i++) printf( %d  , res[0][i]); n   printf(  n ); n   printf( %d n , (int)res[1].size()); n   for (int i = 0; i < res[1].size(); i++) printf( %d  , res[1][i]); n   printf(  n ); n } n int main() { n   solve s; n   s.func(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long P = 1000000007; n long long MOD(long long x) { return (x % P + P) % P; } n long long Time(long long x, long long y) { n   if (x < 0) { n     x = MOD(x); n   } n   long long ans = 1; n   while (y) { n     if (y & 1) { n       ans = ans * x % P; n     } n     x = x * x % P; n     y >>= 1; n   } n   return ans % P; n } n int main() { n   long long T; n   scanf( %lld , &T); n   while (T--) { n     long long n, m, xa, ya, xb, yb, pro; n     scanf( %lld%lld%lld%lld%lld%lld%lld , &n, &m, &xa, &ya, &xb, &yb, &pro); n     pro = pro * Time(100, P - 2) % P; n     long long sum = 0, cnt = 0; n     long long dx = 1, dy = 1; n     long long x = xa, y = ya; n     long long tx = x + dx, ty = y + dy; n     if (tx > n || tx <= 0) { n       dx *= -1; n     } n     if (ty > m || ty <= 0) { n       dy *= -1; n     } n     tx = x + dx; n     ty = y + dy; n     long long xx = tx, yy = ty; n     bool z = 0; n     while (1) { n       if (!z || x != xa || y != ya) { n         tx = x + dx; n         ty = y + dy; n         if (tx > n || tx <= 0) { n           dx *= -1; n         } n         if (ty > m || ty <= 0) { n           dy *= -1; n         } n         tx = x + dx; n         ty = y + dy; n         if (tx == xx && ty == yy && z && x == xa && y == ya) { n           break; n         } n         if (x == xb || y == yb) { n           cnt++; n         } n         z = 1; n         tx = x + dx; n         ty = y + dy; n         if (tx > n || tx <= 0) { n           dx *= -1; n         } n         if (ty > m || ty <= 0) { n           dy *= -1; n         } n         tx = x + dx; n         ty = y + dy; n         x = tx; n         y = ty; n         sum++; n       } else { n         tx = x + dx; n         ty = y + dy; n         if (tx > n || tx <= 0) { n           dx *= -1; n         } n         if (ty > m || ty <= 0) { n           dy *= -1; n         } n         tx = x + dx; n         ty = y + dy; n         if (tx == xx && ty == yy && z && x == xa && y == ya) { n           break; n         } n         if (x == xb || y == yb) { n           cnt++; n         } n         z = 1; n         tx = x + dx; n         ty = y + dy; n         if (tx > n || tx <= 0) { n           dx *= -1; n         } n         if (ty > m || ty <= 0) { n           dy *= -1; n         } n         tx = x + dx; n         ty = y + dy; n         x = tx; n         y = ty; n         sum++; n       } n     } n     long long ans = 0; n     dx = 1; n     dy = 1; n     x = xa; n     y = ya; n     z = 0; n     long long t = 0; n     long long cnt2 = 0; n     while (1) { n       if (!z || x != xa || y != ya) { n         tx = x + dx; n         ty = y + dy; n         if (tx > n || tx <= 0) { n           dx *= -1; n         } n         if (ty > m || ty <= 0) { n           dy *= -1; n         } n         tx = x + dx; n         ty = y + dy; n         if (tx == xx && ty == yy && z && x == xa && y == ya) { n           break; n         } n         if (x == xb || y == yb) { n           long long a = t * Time(1 - pro, cnt2) % P * pro % P; n           long long b = sum * Time(1 - pro, cnt2 + cnt) % P * pro % P; n           long long c = MOD(1 - Time(1 - pro, cnt)); n           ans = MOD(ans + (a + b * Time(c, P - 2)) % P * Time(c, P - 2) % P); n           cnt2++; n         } n         z = 1; n         tx = x + dx; n         ty = y + dy; n         if (tx > n || tx <= 0) { n           dx *= -1; n         } n         if (ty > m || ty <= 0) { n           dy *= -1; n         } n         tx = x + dx; n         ty = y + dy; n         x = tx; n         y = ty; n         t++; n       } else { n         tx = x + dx; n         ty = y + dy; n         if (tx > n || tx <= 0) { n           dx *= -1; n         } n         if (ty > m || ty <= 0) { n           dy *= -1; n         } n         tx = x + dx; n         ty = y + dy; n         if (tx == xx && ty == yy && z && x == xa && y == ya) { n           break; n         } n         if (x == xb || y == yb) { n           long long a = t * Time(1 - pro, cnt2) % P * pro % P; n           long long b = sum * Time(1 - pro, cnt2 + cnt) % P * pro % P; n           long long c = MOD(1 - Time(1 - pro, cnt)); n           ans = MOD(ans + (a + b * Time(c, P - 2)) % P * Time(c, P - 2) % P); n           cnt2++; n         } n         z = 1; n         tx = x + dx; n         ty = y + dy; n         if (tx > n || tx <= 0) { n           dx *= -1; n         } n         if (ty > m || ty <= 0) { n           dy *= -1; n         } n         tx = x + dx; n         ty = y + dy; n         x = tx; n         y = ty; n         t++; n       } n     } n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100010; n const int INF = 0x7fffffff; n long long a[MAXN]; n long long sum = 0; n long long s1[MAXN]; n set<long long> s; n int main() { n   int n; n   scanf( %d , &n); n   s1[0] = 0; n   for (int i = 1; i <= n; i++) { n     scanf( %lld , a + i); n     sum += a[i]; n     s1[i] = s1[i - 1] + a[i]; n   } n   int ok = 0; n   s.clear(); n   for (int i = 1; i <= n; i++) { n     if (s.count(2 * a[i])) { n       ok = 1; n       break; n     } n     long long x = sum - 2 * s1[i]; n     if (x == 0) { n       ok = 1; n       break; n     } n     if (x >= 0) s.insert(x); n   } n   s.clear(); n   for (int i = n; i >= 1; i--) { n     if (s.count(2 * a[i])) { n       ok = 1; n       break; n     } n     long long x = 2 * s1[i] - sum; n     if (x == 0) { n       ok = 1; n       break; n     } n     if (x >= 0) s.insert(x); n   } n   if (ok) n     puts( YES ); n   else n     puts( NO ); n } n


#include <bits/stdc++.h> n using namespace std; n int n = 10; n const int ms = 100; n int grid[ms][ms]; n const int inf = 1e9; n int f[ms]; n double dp[ms]; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout << fixed << setprecision(8); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       cin >> grid[i][j]; n     } n     i++; n     for (int j = n - 1; j >= 0; j--) { n       cin >> grid[i][j]; n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if (grid[i][j] % 2 == 0) { n         f[i * 10 + j] = i * 10 + j - grid[i][j] * 10; n       } else { n         f[i * 10 + j] = i * 10 + (n - j - 1) - grid[i][j] * 10; n       } n     } n     i++; n     for (int j = n - 1; j >= 0; j--) { n       if (grid[i][j] % 2 == 0) { n         f[i * 10 + j] = i * 10 + j - grid[i][j] * 10; n       } else { n         f[i * 10 + j] = i * 10 + (n - j - 1) - grid[i][j] * 10; n       } n     } n   } n   dp[0] = 0.0; n   for (int i = 1; i < ms; i++) { n     double sum = 1; n     double tam = min(i, 6); n     for (int d = 1; d <= tam; d++) { n       sum += 1.0 / 6.0 * min(dp[i - d], dp[f[i - d]]); n     } n     dp[i] = (6.0 / tam) * sum; n   } n   cout << dp[99] <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, m; n   cin >> n >> m; n   long long int x[n][m], y[n][m], a[n][m], b[n], c[m], i, j, ans = 0, ans1 = 0, n                                                              d[n], e[m]; n   for (i = 0; i < n; i++) { n     long long int min = 99999999999; n     for (j = 0; j < m; j++) { n       cin >> x[i][j]; n       a[i][j] = x[i][j]; n       y[i][j] = x[i][j]; n     } n   } n   for (i = 0; i < n; i++) { n     long long int min = 99999999999; n     for (j = 0; j < m; j++) { n       if (min > a[i][j]) min = a[i][j]; n     } n     b[i] = min; n     if (b[i] != 0) ans += b[i]; n   } n   for (i = 0; i < n; i++) { n     for (j = 0; j < m; j++) { n       a[i][j] -= b[i]; n     } n   } n   for (i = 0; i < m; i++) { n     long long int min = 99999999999; n     for (j = 0; j < n; j++) { n       if (min > a[j][i]) min = a[j][i]; n     } n     c[i] = min; n     if (c[i] != 0) ans += c[i]; n   } n   for (i = 0; i < m; i++) { n     for (j = 0; j < n; j++) { n       a[j][i] -= c[i]; n     } n   } n   long long int count = 0; n   for (i = 0; i < n; i++) { n     for (j = 0; j < m; j++) { n       if (a[i][j] == 0) count++; n     } n   } n   for (i = 0; i < m; i++) { n     long long int min = 99999999999; n     for (j = 0; j < n; j++) { n       if (min > y[j][i]) min = y[j][i]; n     } n     e[i] = min; n     if (e[i] != 0) ans1 += e[i]; n   } n   for (i = 0; i < m; i++) { n     for (j = 0; j < n; j++) { n       y[j][i] -= e[i]; n     } n   } n   for (i = 0; i < n; i++) { n     long long int min = 99999999999; n     for (j = 0; j < m; j++) { n       if (min > y[i][j]) min = y[i][j]; n     } n     d[i] = min; n     if (d[i] != 0) ans1 += d[i]; n   } n   for (i = 0; i < n; i++) { n     for (j = 0; j < m; j++) { n       y[i][j] -= d[i]; n     } n   } n   long long int count1 = 0; n   for (i = 0; i < n; i++) { n     for (j = 0; j < m; j++) { n       if (y[i][j] == 0) count1++; n     } n   } n   if (ans < ans1) { n     if (count == n * m) { n       cout << ans << endl; n       for (i = 0; i < n; i++) { n         if (b[i] != 0) { n           while (b[i]--) cout <<  row   << i + 1 << endl; n         } n       } n       for (i = 0; i < m; i++) { n         if (c[i] != 0) { n           while (c[i]--) cout <<  col   << i + 1 << endl; n         } n       } n     } else { n       cout << -1 << endl; n     } n   } else { n     if (count1 == n * m) { n       cout << ans1 << endl; n       for (i = 0; i < n; i++) { n         if (d[i] != 0) { n           while (d[i]--) cout <<  row   << i + 1 << endl; n         } n       } n       for (i = 0; i < m; i++) { n         if (e[i] != 0) { n           while (e[i]--) cout <<  col   << i + 1 << endl; n         } n       } n     } else { n       cout << -1 << endl; n     } n   } n   return 0; n } n