#include <bits/stdc++.h> n using namespace std; n const int Max = 510; n int arr[Max][Max]; n int ps[Max][Max]; n bool check(int i, int j); n int calcPs(int minX, int minY, int maxX, int maxY); n int main() { n   int n, m, k; n   cin >> n >> m >> k; n   for (int i = 0; i < n; i++) { n     string s; n     cin >> s; n     for (int j = 0; j < m; j++) { n       if (s[j] ==  0 ) n         arr[i][j] = 0; n       else n         arr[i][j] = 1; n     } n   } n   for (int i = 1; i < n; i++) { n     for (int j = 1; j < m; j++) { n       ps[i][j] = ps[i - 1][j] + ps[i][j - 1] - ps[i - 1][j - 1] + check(i, j); n     } n   } n   long long result = 0; n   for (int i = 1; i < n - 1; i++) { n     for (int j = i; j < n - 1; j++) { n       int l = 1; n       int r = 1; n       while (r < m - 1 && l < m - 1) { n         int calcedPs = calcPs(i, l, j, r); n         if (calcedPs >= k) { n           result += m - r - 1; n           l++; n         } else n           r++; n       } n     } n   } n   cout << result; n } n bool check(int i, int j) { n   return arr[i][j] == 1 && arr[i][j + 1] == 1 && arr[i + 1][j] == 1 && n          arr[i][j - 1] == 1 && arr[i - 1][j] == 1; n } n int calcPs(int minX, int minY, int maxX, int maxY) { n   minX--; n   minY--; n   return ps[maxX][maxY] - ps[minX][maxY] - ps[maxX][minY] + ps[minX][minY]; n } n


#include <bits/stdc++.h> n using namespace std; n char s[1000005]; n int main() { n   int n, k; n   while (scanf( %d%d , &n, &k) != EOF) { n     if (k > n || (n > 1 && k == 1)) { n       printf( -1 n ); n       break; n     } else { n       if ((n - k) % 2) { n         for (int i = 1; i <= n - k + 1; i++) { n           s[i] =  a ; n           s[i + 1] =  b ; n           i++; n         } n         s[n - k + 2] =  a ; n         int c = 99; n         for (int i = n - k + 3; i <= n; i++) { n           s[i] = c; n           c++; n         } n       } else { n         for (int i = 1; i <= n - k; i++) { n           s[i] =  a ; n           s[i + 1] =  b ; n           i++; n         } n         int c = 97; n         for (int i = n - k + 1; i <= n; i++) { n           s[i] = c; n           c++; n         } n       } n     } n     for (int i = 1; i <= n; i++) printf( %c , s[i]); n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n string toStr(const T &x) { n   stringstream s; n   s << x; n   return s.str(); n } n template <class T> n int toInt(const T &x) { n   stringstream s; n   s << x; n   int r; n   s >> r; n   return r; n } n const double pi = acos(-1); n const double Pi2 = acos(0); n struct point { n   double x, y; n   point() {} n   point(double X, double Y) : x(X), y(Y) {} n   point sub(point a) { return point(x - a.x, y - a.y); } n   point add(point a) { return point(x + a.x, y + a.y); } n   double cross(point a) { return x * a.y - y * a.x; } n   point multbyscalar(double ua) { return point(ua * x, ua * y); } n }; n int lucky(string cad) { n   for (int i = 0; i < cad.size(); ++i) n     if (cad[i] !=  4  and cad[i] !=  7 ) return 0; n   return 1; n } n int main() { n   int n, x, y; n   cin >> n >> x >> y; n   int pin = 1; n   n >>= 1; n   if ((x == n or x == n + 1) and (y == n or y == n + 1)) pin = 0; n   if (pin) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   char ch = getchar(); n   int nega = 1; n   while (!isdigit(ch)) { n     if (ch ==  - ) nega = -1; n     ch = getchar(); n   } n   int ans = 0; n   while (isdigit(ch)) { n     ans = ans * 10 + ch - 48; n     ch = getchar(); n   } n   if (nega == -1) return -ans; n   return ans; n } n int add(int x, int y) { return x + y >= 998244353 ? x + y - 998244353 : x + y; } n int sub(int x, int y) { return x - y < 0 ? x - y + 998244353 : x - y; } n int mul(int x, int y) { return 1LL * x * y % 998244353; } n int B = 707; n int n, m, a[500005], b[500005], fa[500005]; n int c[500005], d[500005]; n struct Query { n   int opt, l, r, x, ans; n }; n Query q[500005]; n int find(int u) { return u == fa[u] ? u : fa[u] = find(fa[u]); } n void merge(int x, int y) { n   if (c[y]) n     fa[c[x]] = c[y]; n   else { n     b[c[x]] = y; n     c[y] = c[x]; n   } n   d[y] += d[x]; n   c[x] = d[x] = 0; n } n signed main() { n   cin >> n >> m; n   for (int i = 1; i <= n; i++) a[i] = read(); n   for (int i = 1; i <= m; i++) { n     q[i].opt = read(), q[i].l = read(), q[i].r = read(), q[i].x = read(); n   } n   for (int L = 1, R = B; L <= n; L += B, R += B) { n     if (R > n) R = n; n     if (L > n) break; n     int maxn = 0, tag = 0; n     for (int k = 1; k <= 500000; k++) { n       if (c[k]) c[k] = 0; n       if (d[k]) d[k] = 0; n     } n     for (int k = L; k <= R; k++) { n       if (a[k] > maxn) maxn = a[k]; n       int x = a[k]; n       if (c[x]) n         fa[k] = c[x]; n       else { n         c[x] = fa[k] = k; n         b[k] = x; n       } n       d[x]++; n     } n     for (int j = 1; j <= m; j++) { n       int opt = q[j].opt, l = q[j].l, r = q[j].r, x = q[j].x; n       if (r < L || l > R) continue; n       if (opt == 1) { n         if (l <= L && R <= r) { n           if (x * 2 <= maxn - tag) { n             for (int k = tag + 1; k <= tag + x; k++) { n               if (c[k]) merge(k, k + x); n             } n             tag += x; n           } else { n             for (int k = maxn; k > tag + x; k--) { n               if (c[k]) merge(k, k - x); n             } n             maxn = min(maxn, tag + x); n           } n         } else { n           for (int k = L; k <= R; k++) { n             a[k] = b[find(k)]; n             c[a[k]] = d[a[k]] = 0; n             a[k] -= tag; n           } n           memset(b + L, 0, (R - L + 1) * 4); n           tag = 0; n           l = max(l, L), r = min(r, R); n           for (int k = l; k <= r; k++) n             if (a[k] > x) a[k] -= x; n           maxn = 0; n           for (int k = L; k <= R; k++) { n             if (a[k] > maxn) maxn = a[k]; n             int x = a[k]; n             if (c[x]) n               fa[k] = c[x]; n             else { n               c[x] = fa[k] = k; n               b[k] = x; n             } n             d[x]++; n           } n         } n       } n       if (opt == 2) { n         if (l <= L && R <= r) { n           if (x + tag <= 500000) q[j].ans += d[x + tag]; n         } else { n           l = max(l, L), r = min(r, R); n           for (int k = l; k <= r; k++) { n             if (b[find(k)] == tag + x) q[j].ans++; n           } n         } n       } n     } n   } n   for (int i = 1; i <= m; i++) { n     if (q[i].opt == 2) printf( %d n , q[i].ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t, i, n, x, j; n   cin >> t; n   while (t--) { n     cin >> n; n     vector<int> a, b; n     for (i = 0; i < n; i++) { n       cin >> x; n       a.push_back(x); n     } n     for (i = 0; i < n; i++) { n       cin >> x; n       b.push_back(x); n     } n     sort(a.begin(), a.end()); n     sort(b.begin(), b.end()); n     for (i = 0; i < n; i++) { n       cout << a[i] <<    ; n     } n     cout <<   n ; n     for (i = 0; i < n; i++) { n       cout << b[i] <<    ; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n struct XD { n   double x, y, z; n   void input() { scanf( %lf%lf%lf , &x, &y, &z); } n   XD operator+(const XD& b) const { n     XD a; n     a.x = x + b.x; n     a.y = y + b.y; n     a.z = z + b.z; n     return a; n   } n }; n XD a, v; n double r; n inline double MIN(double a, double b) { return a < b ? a : b; } n inline double solve(XD a, XD b, XD v, double r) { n   double c1, c2, c3; n   c1 = v.x * v.x + v.y * v.y + v.z * v.z; n   c2 = v.x * (a.x - b.x) * 2 + v.y * (a.y - b.y) * 2 + v.z * (a.z - b.z) * 2; n   c3 = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + n        (a.z - b.z) * (a.z - b.z) - r * r; n   if (c2 * c2 - 4 * c1 * c3 < 0) return 1e100; n   double s1 = (-c2 - sqrt(c2 * c2 - 4 * c1 * c3)) / (2 * c1); n   if (s1 < 0) n     return 1e100; n   else n     return s1; n } n int main() { n   a.input(); n   v.input(); n   scanf( %lf , &r); n   int n, i; n   scanf( %d , &n); n   double mint = 1e100; n   for (i = 0; i < n; i++) { n     XD cen; n     cen.input(); n     double ri; n     scanf( %lf , &ri); n     mint = MIN(mint, solve(a, cen, v, r + ri)); n     int q; n     scanf( %d , &q); n     while (q--) { n       XD dif; n       dif.input(); n       mint = MIN(mint, solve(a, cen + dif, v, r)); n     } n   } n   if (mint > 1e99) n     puts( -1 ); n   else n     printf( %.10lf n , mint); n } n


#include <bits/stdc++.h> n bool compare(int a, int b) { return a < b; } n void swapped(char s1, char s2) { n   char temp = s1; n   s1 = s2; n   s2 = temp; n } n long long int modd(long long int n, long long int k) { n   return (k + (n % k)) % k; n } n bool i(long long first) { return first && (!(first & (first - 1))); } n bool p(long long n) { n   long long i, flag = 1; n   for (i = 2; i <= sqrt(n); i++) { n     if (n % i == 0) { n       flag = 0; n       break; n     } n   } n   if (flag == 1) { n     return true; n   } else { n     return false; n   } n   return 0; n } n using namespace std; n void solve() { n   long long n; n   cin >> n; n   if (n == 1) { n     cout <<  FastestFinger  <<   n ; n     return; n   } n   if (n == 2) { n     cout <<  Ashishgup  <<   n ; n     return; n   } n   if (i(n)) { n     cout <<  FastestFinger  <<   n ; n     return; n   } n   if (n & 1) { n     cout <<  Ashishgup  <<   n ; n     return; n   } n   n /= 2; n   if (p(n)) { n     cout <<  FastestFinger  <<   n ; n     return; n   } else { n     cout <<  Ashishgup  <<   n ; n     return; n   } n } n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int 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 int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n, m, mn, mx; n   cin >> n >> m >> mn >> mx; n   set<int> temp; n   for (int i = 0; i < m; ++i) { n     int x; n     cin >> x; n     temp.insert(x); n   } n   if (*temp.begin() < mn or *temp.rbegin() > mx) { n     cout <<  Incorrect  << endl; n     return 0; n   } n   int off = 0; n   if (*temp.begin() != mn) off++; n   if (*temp.rbegin() != mx) off++; n   if (n - m >= off) { n     cout <<  Correct  << endl; n   } else { n     cout <<  Incorrect  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int x, s, t; n int main(void) { n   cin >> t >> s >> x; n   int a = (x - t) / s; n   if (t == x) { n     cout <<  YES  << endl; n   } else if (a <= 0) { n     cout <<  NO  << endl; n   } else if (t + a * s == x || t + a * s + 1 == x) { n     cout <<  YES  << endl; n   } else { n     cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 5; n const int oo = 0x3f3f3f3f; n inline long long read() { n   char ch = getchar(); n   int x = 0, f = 1; n   while (ch >  9  || ch <  0 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n long long N, M, a[MAXN], b[MAXN], leftt, rightt, mid, ans, cnt, st, nd; n bool vis[MAXN]; n namespace solution { n void init() { n   N = read(); n   M = read(); n   for (int i = 1; i <= N; i++) a[i] = read(); n   for (int i = 1; i <= M; i++) b[i] = read(); n   sort(a + 1, a + N + 1); n   sort(b + 1, b + M + 1); n } n bool check(long long length) { n   int t = 1; n   for (int i = 1; i <= M; i++) { n     st = b[i] - length; n     nd = b[i] + length; n     while (t <= N && a[t] >= st && a[t] <= nd) t++; n   } n   return t > N; n } n void slove() { n   leftt = 0; n   rightt = 2000000000; n   while (leftt + 1 < rightt) { n     mid = (leftt + rightt) >> 1; n     if (check(mid)) n       rightt = mid; n     else n       leftt = mid; n   } n   if (check(leftt)) n     ans = leftt; n   else n     ans = rightt; n } n void output() { cout << ans << endl; } n }  // namespace solution n int main() { n   using namespace solution; n   init(); n   slove(); n   output(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD(1000000007); n const int INF((1 << 30) - 1); n const int MAXN(30); n string a[MAXN]; n int type[200] = {0}; n int main() { n   int n, m, x; n   scanf( %d%d%d , &n, &m, &x); n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i =  A ; i <=  Z ; i++) type[i] = INF; n   for (int i =  a ; i <=  z ; i++) type[i] = INF; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       if (a[i][j] !=  S ) n         type[a[i][j]] = 1; n       else { n         for (int k = 0; k < n; k++) n           for (int l = 0; l < m; l++) n             if (a[k][l] !=  S ) n               type[a[k][l] -  a  +  A ] = n                   min(type[a[k][l] -  a  +  A ], n                       (i - k) * (i - k) + (j - l) * (j - l)); n       } n     } n   int q; n   scanf( %d , &q); n   int ans = 0; n   while (q--) { n     char c; n     scanf(  %c , &c); n     if (type[c] == INF) { n       printf( -1 ); n       return 0; n     } else if (c >=  A  && c <=  Z  && type[c] > x * x) n       ans++; n   } n   printf( %d , ans); n } n


#include <bits/stdc++.h> n int dp[51 * 10001]; n int main(void) { n   int n, d, a, sum, i, j; n   while (scanf( %d%d , &n, &d) != EOF) { n     sum = 0; n     memset(dp, 0, sizeof(dp)); n     dp[0] = 1; n     for (i = 0; i < n; i++) { n       scanf( %d , &a); n       sum += a; n       for (j = sum; j >= a; j--) { n         if (dp[j - a] == 1) dp[j] = 1; n       } n     } n     int k = 0; n     int ans = 0; n     while (true) { n       i = k + d; n       while (dp[i] == 0 && i > k) i--; n       if (k == i) break; n       k = i; n       ans++; n     } n     printf( %d %d n , k, ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 150000; n struct node { n   long long l, r, sm, mx; n } tr[4 * maxn]; n inline node comb(node ll, node rr) { n   node ret; n   ret.l = max(ll.l, ll.sm + rr.l); n   ret.r = max(rr.r, rr.sm + ll.r); n   ret.sm = ll.sm + rr.sm; n   ret.mx = max(max(ll.mx, rr.mx), ll.r + rr.l); n   return ret; n } n inline void pushup(int o) { tr[o] = comb(tr[o * 2], tr[o * 2 + 1]); } n long long a[maxn]; n void build(int o, int l, int r) { n   if (l == r) { n     tr[o].l = tr[o].r = tr[o].sm = tr[o].mx = a[l]; n     return; n   } n   build(o * 2, l, (l + r) / 2); n   build(o * 2 + 1, (l + r) / 2 + 1, r); n   pushup(o); n } n node query(int o, int l, int r, int ql, int qr) { n   if (ql <= l && qr >= r) return tr[o]; n   if (qr <= (l + r) / 2) return query(o * 2, l, (l + r) / 2, ql, qr); n   if (ql > (l + r) / 2) return query(o * 2 + 1, (l + r) / 2 + 1, r, ql, qr); n   node ll = query(o * 2, l, (l + r) / 2, ql, qr), n        rr = query(o * 2 + 1, (l + r) / 2 + 1, r, ql, qr); n   return comb(ll, rr); n } n long long b[maxn]; n int main() { n   long long n, q, c; n   scanf( %lld%lld%lld , &n, &q, &c); n   long long x; n   scanf( %lld , &x); n   n--; n   for (int i = 1; i <= n; i++) scanf( %lld , b + i); n   for (int i = 1; i <= n; i++) { n     scanf( %lld , &x); n     a[i] = (b[i] - b[i - 1]) * 50 - c * x; n   } n   build(1, 1, n); n   long long ans = 0; n   while (q--) { n     long long l, r; n     scanf( %lld%lld , &l, &r); n     r--; n     node tmp = query(1, 1, n, l, r); n     ans += max(tmp.mx, 0LL); n   } n   cout << fixed << setprecision(9) << 0.01 * ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n long long chess[5][2004][2004]; n int main() { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   int N, r1, r2, c1, c2; n   cin >> N; n   for (int i = 1; i < N + 1; i += 1) n     for (int j = 1; j < N + 1; j += 1) n       cin >> chess[0][i][j], n           chess[1][i][j] = chess[0][i][j] + chess[1][i - 1][j - 1], n           chess[2][i][j] = chess[0][i][j] + chess[2][i - 1][j + 1]; n   for (int i = N; i >= 1; i -= 1) n     for (int j = N; j >= 1; j -= 1) n       chess[3][i][j] = chess[0][i][j] + chess[3][i + 1][j + 1], n       chess[4][i][j] = chess[0][i][j] + chess[4][i + 1][j - 1]; n   long long ec = -1, oc = -1, t; n   for (int i = 1; i < N + 1; i += 1) n     for (int j = 1; j < N + 1; j += 1) { n       t = chess[0][i][j] + chess[1][i - 1][j - 1] + chess[2][i - 1][j + 1] + n           chess[3][i + 1][j + 1] + chess[4][i + 1][j - 1]; n       if (i + j & 1 && oc < t) n         r1 = i, c1 = j, oc = t; n       else if ((i + j & 1) == 0 && ec < t) n         r2 = i, c2 = j, ec = t; n     } n   cout << oc + ec <<   n  << r1 <<     << c1 <<     << r2 <<     << c2 <<   n ; n } n


#include <bits/stdc++.h> n   n //#define int long long n   n #define pii pair<short, int> n   n #define x1 x1228 n #define y1 y1228 n   n #define left left228 n #define right right228 n   n #define data data228 n   n #define pb push_back n #define eb emplace_back n   n #define mp make_pair                                                                 n                                                                                n #define ff first                                                                   n #define ss second    n   n #define all(x) x.begin(), x.end() n #define debug(x) cout << #x <<  :   << x << endl;  n #define TIME (ld)clock()/CLOCKS_PER_SEC n   n using namespace std; n /** Fast input-output */ n  n template <class T = int> inline T readInt(); n inline double readDouble(); n inline int readUInt(); n inline int readChar(); // first non-blank character n inline void readWord( char *s ); n inline bool readLine( char *s ); // do not save   n  n inline bool isEof(); n inline int getChar(); n inline int peekChar(); n inline bool seekEof(); n inline void skipBlanks(); n  n template <class T> inline void writeInt( T x, char end = 0, int len = -1 ); n inline void writeChar( int x ); n inline void writeWord( const char *s ); n inline void writeDouble( double x, int len = 0 ); n inline void flush(); n  n static struct buffer_flusher_t { n     ~buffer_flusher_t() { n         flush(); n     } n } buffer_flusher; n  n /** Read */         n  n static const int buf_size = 4096; n  n static unsigned char buf[buf_size]; n static int buf_len = 0, buf_pos = 0; n  n inline bool isEof() { n     if (buf_pos == buf_len) { n         buf_pos = 0, buf_len = fread(buf, 1, buf_size, stdin); n         if (buf_pos == buf_len) n             return 1; n     } n     return 0; n } n  n  n inline int getChar() { n     return isEof() ? -1 : buf[buf_pos++]; n } n  n inline int peekChar() { n     return isEof() ? -1 : buf[buf_pos]; n } n  n inline bool seekEof() { n     int c; n     while ((c = peekChar()) != -1 && c <= 32) n         buf_pos++; n     return c == -1; n } n  n inline void skipBlanks() { n     while (!isEof() && buf[buf_pos] <= 32U) n         buf_pos++; n } n  n inline int readChar() { n     int c = getChar(); n     while (c != -1 && c <= 32) n         c = getChar(); n     return c; n } n  n inline int readUInt() { n     int c = readChar(), x = 0; n     while ( 0  <= c && c <=  9 ) n         x = x * 10 + c -  0 , c = getChar(); n     return x; n } n  n template <class T> n inline T readInt() { n     int s = 1, c = readChar(); n     T x = 0; n     if (c ==  - ) n         s = -1, c = getChar(); n     else if (c ==  + ) n         c = getChar(); n     while ( 0  <= c && c <=  9 ) n         x = x * 10 + c -  0 , c = getChar(); n     return s == 1 ? x : -x; n } n  n inline double readDouble() { n     int s = 1, c = readChar(); n     double x = 0; n     if (c ==  - ) n         s = -1, c = getChar(); n     while ( 0  <= c && c <=  9 ) n         x = x * 10 + c -  0 , c = getChar(); n     if (c ==  . ) { n         c = getChar(); n         double coef = 1; n         while ( 0  <= c && c <=  9 ) n             x += (c -  0 ) * (coef *= 1e-1), c = getChar(); n     } n     return s == 1 ? x : -x; n } n  n inline void readWord( char *s ) { n     int c = readChar(); n     while (c > 32) n         *s++ = c, c = getChar(); n     *s = 0; n } n  n inline bool readLine( char *s ) { n     int c = getChar(); n     while (c !=   n  && c != -1) n         *s++ = c, c = getChar(); n     *s = 0; n     return c != -1; n } n  n /** Write */ n  n static int write_buf_pos = 0; n static char write_buf[buf_size]; n  n inline void writeChar( int x ) { n     if (write_buf_pos == buf_size) n         fwrite(write_buf, 1, buf_size, stdout), write_buf_pos = 0; n     write_buf[write_buf_pos++] = x; n } n  n inline void flush() { n     if (write_buf_pos) n         fwrite(write_buf, 1, write_buf_pos, stdout), write_buf_pos = 0; n } n  n template <class T> n inline void writeInt( T x, char end, int output_len ) { n     if (x < 0) n         writeChar( - ), x = -x; n  n     char s[24]; n     int n = 0; n     while (x || !n) n         s[n++] =  0  + x % 10, x /= 10; n     while (n < output_len) n         s[n++] =  0 ; n     while (n--) n         writeChar(s[n]); n     if (end) n         writeChar(end); n } n  n inline void writeWord( const char *s ) { n     while (*s) n         writeChar(*s++); n } n  n inline void writeDouble( double x, int output_len ) { n     if (x < 0) n         writeChar( - ), x = -x; n     int t = (int)x; n     writeInt(t), x -= t; n     writeChar( . ); n     for (int i = output_len - 1; i > 0; i--) { n         x *= 10; n         t = std::min(9, (int)x); n         writeChar( 0  + t), x -= t; n     } n     x *= 10; n     t = std::min(9, (int)(x + 0.5)); n     writeChar( 0  + t); n } n typedef long long ll;  n typedef long double ld;  n                                                                                n const int maxn = 1500 + 7, mod = 1e9 + 7, MAXN = 2e6 + 7; n const double eps = 1e-9;                                         n const ll INF = 1e18, inf = 1e15; n mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());                        n int n, q;  n int cl[maxn][maxn];  n vector<pii> ladder1[2][maxn], ladder2[2][maxn];  n   n vector<pii> merge(vector<pii> p1, vector<pii> p2) { n     vector<pii> res; n     res.reserve((int)p1.size() + (int)p2.size());  n     int pt1 = 0;  n     int pt2 = 0;  n     while (pt1 < (int)p1.size() && pt2 < (int)p2.size()) { n         if (p1[pt1].ff <= p2[pt2].ff) { n             res.pb(p1[pt1++]);  n         } else { n             res.pb(p2[pt2++]);  n         } n     } n     while (pt1 < (int)p1.size()) { n         res.pb(p1[pt1++]);  n     }  n     while (pt2 < (int)p2.size()) { n         res.pb(p2[pt2++]);  n     } n     return res;  n } n   n int used[maxn * maxn];  n   n void compress(vector<pii> &res) { n     for (auto x : res) { n         used[x.ss] = 0;  n     } n     vector<pii> nw;  n     for (auto x : res) { n         if (!used[x.ss]) { n             nw.pb(x);  n             used[x.ss] = 1;  n         } n     } n     while ((int)nw.size() > q + 1) { n         nw.pop_back();  n     } n     res = nw;  n } n   n void add(int i, int j, vector<pii> &cur, vector<int> &point) { n     short sz = min(i + 1, n - j);  n     if ((int)cur.size() <= q) { n         point[0]++;  n         point[sz]--;  n     } else { n         point[0]++;  n         point[min(sz, cur.back().ff)]--;  n     } n } n   n void solve() { n     n = readInt(); n     q = readInt();  n     for (int i = 0; i < n; ++i) { n         for (int j = 0; j < n; ++j) { n             cl[i][j] = readInt();  n         } n     } n     vector<int> point(n + 1);  n     int pt = 0;  n     for (int i = 0; i < n; ++i) { n         pt ^= 1;  n         for (int j = n - 1; j >= 0; --j) {                         n             vector<pii> res = ladder1[pt][j + 1];  n             if (i) { n                 res = merge(res, ladder1[pt ^ 1][j + 1]);                          n             } n             for (auto &x : res) { n                 x.ff++;              n             } n             res = merge(res, {{0, cl[i][j]}});  n             compress(res);  n             ladder1[pt][j] = res;  n   n   n             res.clear();  n             if (i) { n                 res = merge(ladder2[pt ^ 1][j], ladder2[pt ^ 1][j + 1]);  n                 for (auto &x : res) { n                     x.ff++;              n                 } n             } n             res = merge(res, {{0, cl[i][j]}});  n             compress(res);  n             ladder2[pt][j] = res;  n   n             res = merge(res, ladder1[pt][j]);  n             compress(res); n             add(i, j, res, point);   n         } n         for (int j = 0; j < n; ++j) { n             ladder1[pt ^ 1][j].clear();  n             ladder2[pt ^ 1][j].clear();  n         }                  n     } n //    cout << TIME;  n //    return;  n     int res = 0; n     for (int i = 0; i < n; ++i) { n         res += point[i];  n         cout << res <<   n ;  n     }      n }                                 n                   n signed main() {           n #ifdef LOCAL n     freopen( TASK.in ,  r , stdin); n     freopen( TASK.out ,  w , stdout); n #endif // LOCAL                                                                              n     ios_base::sync_with_stdio(false); n     cin.tie(0); n     cout.precision(20);  n     cout << fixed;  n     int t = 1;  n     for (int i = 0; i < t; ++i) {               n         solve(); n     } n     return 0; n }   n


#include <bits/stdc++.h> n using namespace std; n long long int a[300009]; n vector<pair<pair<long long int, long long int>, n             pair<long long int, long long int>>> n     v; n long long int ans = 1; n vector<int> vec; n bool check(int idx, long long int mid) { n   long long int dist, i, j, x, fuel = mid, cnt = v[idx].second.second, n                                kitna_chlegi; n   for (i = v[idx].first.first; i < v[idx].first.second; i++) { n     x = a[i + 1] - a[i]; n     kitna_chlegi = fuel / v[idx].second.first; n     if (kitna_chlegi < x) { n       if (cnt == 0 || mid / v[idx].second.first < x) { n         return 0; n       } n       fuel = mid; n       cnt--; n     } n     fuel -= x * v[idx].second.first; n   } n   return 1; n } n void update(int idx) { n   if (check(idx, ans)) { n     return; n   } n   long long int l = ans, r = 1000000000000000000, temp = r; n   bool f; n   while (l <= r) { n     long long int mid = (l + r) >> 1; n     f = check(idx, mid); n     if (f) { n       temp = min(temp, mid); n       r = mid - 1; n     } else { n       l = mid + 1; n     } n   } n   ans = max(ans, temp); n } n int main() { n   long long int i, j, k, x, y, t, n, m, p; n   scanf( %lld%lld , &n, &m); n   for (i = 1; i <= n; i++) { n     scanf( %lld , &a[i]); n   } n   for (i = 0; i < m; i++) { n     scanf( %lld%lld , &x, &y); n     scanf( %lld%lld , &j, &k); n     v.push_back(make_pair(make_pair(x, y), make_pair(j, k))); n     vec.push_back(i); n   } n   random_shuffle(vec.begin(), vec.end()); n   for (i = 0; i < m; i++) { n     update(vec[i]); n   } n   cout << ans << endl; n   ; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n int node[(ll)(1e5 + 7)], in[(ll)(1e5 + 7)], out[(ll)(1e5 + 7)], n     ti = 1, hie[(ll)(1e5 + 7)]; n int dp[(ll)(1e5 + 7)][17]; n vector<int> gr[(ll)(1e5 + 7)], hi[(ll)(1e5 + 7)]; n void dfs(int node, int h) { n   hi[h].push_back(ti); n   hie[node] = h; n   in[node] = ti++; n   for (int x : gr[node]) { n     dfs(x, h + 1); n   } n   out[node] = ti++; n } n int main() { n   ios_base ::sync_with_stdio(false); n   cin.tie(nullptr); n   int n; n   cin >> n; n   vector<int> ve; n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j < 17; j++) { n       dp[i][j] = -1; n     } n   } n   for (int i = 1; i <= n; i++) { n     int val; n     cin >> val; n     if (val) { n       dp[i][0] = val; n       gr[val].push_back(i); n     } else { n       ve.push_back(i); n     } n   } n   for (int x : ve) { n     dfs(x, 1); n   } n   for (int j = 1; j < 17; j++) { n     for (int i = 1; i <= n; i++) { n       if (dp[i][j - 1] != -1) { n         dp[i][j] = dp[dp[i][j - 1]][j - 1]; n       } n     } n   } n   int q; n   cin >> q; n   for (int i = 0; i < q; i++) { n     int x, p; n     cin >> x >> p; n     for (int j = 0; (1 << j) <= p; j++) { n       if ((1 << j) & p) { n         x = dp[x][j]; n       } n     } n     if (x == -1) { n       cout <<  0  ; n       continue; n     } n     int hh = hie[x] + p; n     int xx = (upper_bound(hi[hh].begin(), hi[hh].end(), out[x]) - n               lower_bound(hi[hh].begin(), hi[hh].end(), in[x])); n     cout << max(0, xx - 1) <<    ; n   } n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int x[110000]; n char str[110000]; n long long tail[110000], a[110000], b[110000], c[110000], sum[110000], n     cm1[110000], cm2[110000]; n int n, m; n const long long MOD = 1000000007L; n long long mod_reset(long long x) { return (x % MOD + MOD) % MOD; } n void extgcd(long long a, long long b, long long &x, long long &y) { n   if (b == 0) { n     x = 1L; n     y = 0L; n     return; n   } n   long long div = a / b; n   extgcd(b, a % b, y, x); n   y = mod_reset(y - div * x % MOD); n } n long long get_antimul(long long a) { n   long long x, y; n   extgcd(a, MOD, x, y); n   return x; n } n void conduct() { n   long long ans; n   scanf( %s , str); n   for (int i = 0; i < n; ++i) x[i + 1] = str[i] -  0 ; n   if (m == 0) { n     ans = 0L; n     for (int i = 1; i <= n; ++i) ans = (ans * 10 + x[i]) % MOD; n     cout << ans << endl; n     return; n   } n   cm1[n - m] = cm2[n - m] = 1; n   for (int i = n - m; i; --i) { n     long long ref = get_antimul(n - i - m + 1); n     cm1[i - 1] = (cm1[i] * (n - i)) % MOD * ref % MOD; n     cm2[i - 1] = (cm2[i] * (n - i - 1)) % MOD * ref % MOD; n   } n   tail[0] = 0L; n   for (int i = 1; i <= n; ++i) tail[i] = tail[i - 1] + x[n - i + 1]; n   a[0] = b[0] = sum[0] = ans = 0L; n   c[0] = 1L; n   for (int i = 1; i <= n - m; ++i) { n     a[i] = (a[i - 1] * 10 + x[i]) % MOD; n     c[i] = c[i - 1] * 10 % MOD; n     b[i] = (b[i - 1] + c[i - 1] * x[n - i + 1]) % MOD; n     sum[i] = (mod_reset(sum[i - 1] - b[i - 1]) * 10 + tail[n - i + 1]) % MOD; n     ans = (ans + mod_reset(sum[i] - a[i] - b[i]) * cm2[i] + n            (a[i] + b[i]) * cm1[i]) % n           MOD; n   } n   cout << ans << endl; n } n int main() { n   while (scanf( %d%d , &n, &m) != EOF) conduct(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n const double PI = 3.141592653589793238463; n const int MAXN = 100005; n long long n, s; n long long temp = 0; n long long arr[MAXN]; n bool ok(long long mid) { n   long long tArray[n]; n   for (long long i = 0; i < n; i++) { n     tArray[i] = (arr[i] + ((i + 1) * mid)); n   } n   sort(tArray, tArray + n); n   temp = 0; n   long long t = mid; n   for (int i = 0; i < t; i++) { n     if (temp + tArray[i] <= s) { n       temp += tArray[i]; n     } else { n       return 0; n     } n   } n   return 1; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> s; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   long long l = 0, r = n; n   long long ans = 0; n   long long mn = 0; n   while (l <= r) { n     long long mid = l + (r - l) / 2; n     if (ok(mid)) { n       ans = mid; n       mn = temp; n       l = mid + 1; n     } else { n       r = mid - 1; n     } n   } n   cout << ans <<     << mn <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e3 + 5; n const int INF = 0x3f3f3f3f; n const int MOD = 1e3; n int ans[MAXN]; n char s[MAXN]; n void solve() { n   int n; n   cin >> n; n   int k, num; n   int s12, s13, s23; n   cout <<  ?   << 1 <<     << 2 << endl; n   scanf( %d , &s12); n   cout <<  ?   << 1 <<     << 3 << endl; n   scanf( %d , &s13); n   cout <<  ?   << 2 <<     << 3 << endl; n   scanf( %d , &s23); n   ans[1] = s13 - s23; n   ans[2] = s12 - ans[1]; n   ans[3] = s13 - ans[1] - ans[2]; n   for (int i = 4; i <= n; i++) { n     cout <<  ?   << i - 1 <<     << i << endl; n     scanf( %d , &ans[i]); n     ans[i] = ans[i] - ans[i - 1]; n   } n   cout <<  !   << ans[1] << flush; n   for (int i = 2; i <= n; i++) { n     cout <<     << ans[i] << flush; n   } n   cout << endl; n   return; n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int r, g, b; n   cin >> r >> g >> b; n   int a[3] = {r, g, b}; n   int i = 0; n   while (a[0] > 0 || a[1] > 0 || a[2] > 0) { n     if (a[i % 3] > 0) a[i % 3] -= 2; n     i++; n   } n   cout << 30 + i - 1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 1e5 + 1; n int MOD = 1e9 + 7; n const int INF = 1e9; n const long long LINF = 1e18; n void solve() { n   int n; n   cin >> n; n   string s; n   cin >> s; n   vector<int> a; n   int ans = 0; n   bool ok = true; n   bool all_s = true; n   vector<int> pref(n); n   for (int i = 0; i < n; ++i) { n     if (i == 0) { n       if (s[i] ==  G ) n         pref[i] = 1; n       else n         pref[i] = 0; n     } else { n       if (s[i] ==  G ) n         pref[i] = 1 + pref[i - 1]; n       else n         pref[i] = pref[i - 1]; n     } n   } n   for (int i = 0; i < n; ++i) { n     if (s[i] ==  S ) { n       ok = false; n       int l = 0, r = 0; n       bool k1 = false, k2 = false; n       int j = i - 1; n       while (j >= 0 && s[j] ==  G ) { n         l++; n         j--; n       } n       if (j > 0) { n         if (pref[j - 1]) k1 = true; n       } n       j = i + 1; n       while (j < n && s[j] ==  G ) { n         r++; n         j++; n       } n       if (j < n - 1 && pref[n - 1] - pref[j] > 0) k2 = true; n       if (k1 || k2) n         ans = max(ans, r + l + 1); n       else n         ans = max(ans, r + l); n     } else n       all_s = false; n   } n   if (ok) ans = n; n   if (all_s) ans = 0; n   cout << ans << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n map<char, int> mp; n map<char, int> mp1; n map<char, int> mp2; n long long frq[100002] = {}; n bool lol = true; n int main() { n   bool u = false; n   long long x, y, p; n   scanf( %lld%lld , &x, &y); n   long long num = y, sum = 0; n   if (x == 1 && y == 10) { n     printf( -1 n ); n     return 0; n   } n   if (y < 10) { n     for (int i = 1; i <= x; i++) { n       cout << num; n     } n   } else { n     for (int i = 1; i <= x; i++) { n       if (i == x) { n         cout << num % 10; n       } else n         cout << num / 10; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string a, b; n   int n; n   cin >> n >> a >> b; n   int T[n], pom[n]; n   for (int i = 0; i < n; ++i) T[i] = -1; n   for (int i = 0; i < n; ++i) { n     bool ud = false; n     for (int j = 0; j < n; ++j) { n       if (T[j] == -1 && a[j] == b[i]) { n         ud = true; n         T[j] = i; n         break; n       } n     } n     if (!ud) { n       cout << -1 << endl; n       return 0; n     } n   } n   queue<int> ans; n   int t = (T[n - 1] == 0 ? n - 1 : n); n   while (t > 0) { n     int np = -1; n     for (int i = 0; i < n; ++i) n       if (T[i] == n - t) { n         np = i; n         break; n       } n     ans.push(n - np - 1); n     ans.push(1); n     ans.push(n); n     int id = 0; n     for (int i = np - 1; i >= 0; --i) { n       pom[id++] = T[i]; n     } n     for (int i = np + 1; i < t; ++i) { n       pom[i - 1] = T[i]; n     } n     t--; n     for (int i = 0; i < t; ++i) T[i] = pom[i]; n     for (int i = t; i < n; ++i) { n       T[i] = i - t; n     } n   } n   cout << ans.size() << endl; n   while (!ans.empty()) { n     cout << ans.front() <<    ; n     ans.pop(); n   } n   cout << endl; n } n


#include <bits/stdc++.h> n template <class T> n std::vector<T> ReadVector(size_t size) { n   std::vector<T> vector(size); n   for (auto& element : vector) { n     std::cin >> element; n   } n   return vector; n } n int64_t divisor(int64_t x) { n   for (int64_t d = 2; d * d <= x; ++d) { n     while (x % d == 0) { n       x /= d; n       return d; n     } n   } n   return x; n } n void YES(bool yes) { n   if (yes) { n     std::cout <<  YES n ; n   } else { n     std::cout <<  NO n ; n   } n } n class Solver { n  public: n   Solver() {} n   void solve() { n     int t; n     std::cin >> t; n     while (t--) { n       one(); n     } n   } n   int lo(int& a, int& d) { n     if (a + d == 0) return 0; n     int losers = 0; n     if (d > a) { n       int m = std::max(0, a); n       losers += m; n       d -= m; n       a -= m; n     } else if (d < a) { n       int m = std::max(0, d - 1); n       losers += m; n       a -= m; n       d -= m; n     } else { n       losers += d - 1; n       d = 1; n       a = 1; n     } n     return losers; n   } n   int wi(int& a, int& d) { n     int winners = 0; n     if (d > a) { n       int m = a; n       winners += m; n       d -= m; n       a = 0; n     } else if (d < a) { n       int m = d; n       winners += m; n       a -= m; n       d = 0; n     } else { n       winners += d; n       d = 0; n       a = 0; n     } n     return winners; n   } n   void one() { n     int n, x, y; n     std::cin >> n >> x >> y; n     if (x > y) std::swap(x, y); n     int a = x - 1; n     int b = n - x; n     int c = y - 1; n     int d = n - y; n     int losers = 0; n     losers += lo(a, d); n     losers += lo(c, b); n     losers += std::min(b, d); n     a = x - 1; n     b = n - x; n     c = y - 1; n     d = n - y; n     int winners = 1; n     winners += wi(a, d); n     winners += wi(c, b); n     winners += std::min(a, c); n     std::cout << n - losers <<     << winners << std::endl; n   } n }; n int main() { n   Solver solver; n   solver.solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool debug = 0; n int n, m, k; n int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; n string direc =  RDLU ; n long long ln, lk, lm; n void etp(bool f = 0) { n   puts(f ?  YES  :  NO ); n   exit(0); n } n void addmod(int &x, int y, int mod = 1000000007) { n   assert(y >= 0); n   x += y; n   if (x >= mod) x -= mod; n   assert(x >= 0 && x < mod); n } n void et() { n   puts( -1 ); n   exit(0); n } n long long fastPow(long long x, long long y, int mod = 1000000007) { n   long long ans = 1; n   while (y > 0) { n     if (y & 1) ans = (x * ans) % mod; n     x = x * x % mod; n     y >>= 1; n   } n   return ans; n } n char s[525][525], qy[525]; n int a[525][525 + 300], q; n void pp(int x, int y) { n   for (int(i) = 1; (i) <= (int)(x); (i)++) { n     for (int(j) = 1; (j) <= (int)(y); (j)++) printf( %d  , a[i][j]); n     puts(  ); n   } n } n void Gaw() { n   int SZ = n + q; n   int fr = 0; n   for (int(i) = 1; (i) <= (int)(m); (i)++) { n     int j = -1, r = i; n     while (r <= n) { n       for (int k = i; k <= m; k++) { n         if (abs(a[k][r]) != 0) { n           j = k; n           break; n         } n       } n       if (j == -1) n         r++; n       else { n         for (int k = i; k <= m; k++) swap(a[k][i], a[k][r]); n         break; n       } n     } n     if (n < r) break; n     if (j == -1) { n       continue; n     } n     fr++; n     if (i != j) n       for (int k = i; k <= SZ; k++) swap(a[i][k], a[j][k]); n     for (int k = i + 1; k <= m; k++) n       if (k != i && a[k][i] != 0) { n         for (int p = SZ; p >= i; p--) { n           a[k][p] = a[i][p] * (5 - a[k][i]) % 5 + a[k][p] * a[i][i] % 5; n           a[k][p] %= 5; n         } n       } n   } n   int ans = fastPow(5, n - fr); n   for (int(i) = 1; (i) <= (int)(q); (i)++) { n     int ta = ans; n     for (int(j) = 1; (j) <= (int)(m); (j)++) n       if (a[j][n + i] != 0) { n         bool ok = 0; n         for (int(x) = 1; (x) <= (int)(n); (x)++) n           if (a[j][x] != 0) { n             ok = 1; n             break; n           } n         if (ok) continue; n         ta = 0; n         break; n       } n     printf( %d n , ta); n   } n } n void fmain(int tid) { n   scanf( %d%d , &n, &m); n   for (int(i) = 1; (i) <= (int)(n); (i)++) scanf( %s , s[i] + 1); n   for (int(j) = 1; (j) <= (int)(m); (j)++) { n     for (int(i) = 1; (i) <= (int)(n); (i)++) { n       a[j][i] = s[i][j] -  a ; n     } n   } n   scanf( %d , &q); n   for (int(i) = 1; (i) <= (int)(q); (i)++) { n     scanf( %s , qy + 1); n     for (int(j) = 1; (j) <= (int)(m); (j)++) { n       a[j][n + i] = qy[j] -  a ; n     } n   } n   Gaw(); n } n int main() { n   int t = 1; n   for (int(i) = 1; (i) <= (int)(t); (i)++) { n     fmain(i); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char a[130000]; n struct gg { n   int x, y, z; n } b[130000]; n int cmp(gg p, gg q) { return p.z < q.z; } n void solve() { n   int n, m; n   cin >> n >> m; n   cin >> a; n   int l = 0; n   int p = 0, q = 0, o = 0; n   for (int i = 0; i < n; i++) n     if (a[i] ==  W ) { n       p = i; n       o = i; n       break; n     } n   for (int i = 0; i < n; i++) { n     if (a[i] ==  W ) { n       q = i; n       b[l].x = p; n       b[l].z = q - p - 1; n       b[l++].y = q; n       p = q; n     } n   } n   sort(b, b + l, cmp); n   for (int i = 0; i < l && m > 0; i++) { n     int gg = b[i].x, hh = b[i].y; n     for (int j = gg + 1; j < hh && m > 0; j++) n       if (a[j] ==  L ) { n         a[j] =  W ; n         m--; n       } n   } n   for (int i = o; i >= 0 && m > 0; i--) n     if (a[i] ==  L ) { n       a[i] =  W ; n       m--; n     } n   for (int i = q; i < n && m > 0; i++) n     if (a[i] ==  L ) { n       a[i] =  W ; n       m--; n     } n   int s = 0; n   for (int i = 0; i < n; i++) n     if (a[i] ==  W ) { n       if (i == 0 || a[i - 1] !=  W ) n         s++; n       else n         s += 2; n     } n   printf( %d n , s); n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n struct point { n   int x, l; n } pp[1000000 * 2]; n int qq[1000000 * 2], sk; n int pcompare(const void *a, const void *b) { n   struct point *pa = (struct point *)a; n   struct point *pb = (struct point *)b; n   return pa->x != pb->x ? pa->x - pb->x : pb->l - pa->l; n } n void sort(struct point *pp, int n) { n   int i; n   srand(time(NULL)); n   for (i = n - 1; i >= 0; i--) { n     struct point tmp; n     int j = rand() % (i + 1); n     tmp = pp[i], pp[i] = pp[j], pp[j] = tmp; n   } n   qsort(pp, n, sizeof *pp, pcompare); n } n void sweep(struct point *pp, int n, int k) { n   int d, i; n   d = 0; n   for (i = 0; i <= n; i++) n     if (pp[i].l) { n       d++; n       if (d == k) qq[sk++] = pp[i].x; n     } else { n       d--; n       if (d == k - 1) qq[sk++] = pp[i].x; n     } n   printf( %d n , sk / 2); n   for (i = 0; i < sk; i++) printf( %d%c , qq[i], i % 2 == 0 ?     :   n ); n } n int main() { n   int n, k, i; n   scanf( %d%d , &n, &k); n   for (i = 0; i < n; i++) { n     int l, r; n     scanf( %d%d , &l, &r); n     pp[i * 2].x = l, pp[i * 2].l = 1; n     pp[i * 2 + 1].x = r, pp[i * 2 + 1].l = 0; n   } n   sort(pp, n * 2); n   sk = 0; n   sweep(pp, n * 2, k); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n long long f[110][110]; n long long n, k; n char s[110]; n long long ch2i[225]; n long long ich2i[110][225]; n int main() { n   cin >> n >> k; n   scanf( %s , s); n   for (int i =  a ; i <  z  + 1; i++) { n     ch2i[i] = -1; n   } n   for (int i = n - 1; i >= 0; i--) { n     for (int ch =  a ; ch <  z  + 1; ch++) { n       ich2i[i][ch] = ch2i[ch]; n     } n     ch2i[s[i]] = i; n   } n   f[0][0] = 1; n   for (int i = 0; i < n; i++) { n     f[i][1] = 1; n   } n   for (int len = 2; len < n + 1; len++) { n     for (int i = 0; i < n - len + 1; i++) { n       for (int j = i + 1; j < n - len + 2; j++) { n         if (ich2i[i][s[j]] != j) continue; n         f[i][len] += f[j][len - 1]; n       } n     } n   } n   long long cnt = 0; n   long long ans = 0; n   for (int len = n + 1 - 1; len >= 0; len--) { n     for (int i = 0; i < n - len + 1; i++) { n       if (i != ch2i[s[i]]) continue; n       cnt += f[i][len]; n       ans += (n - len) * f[i][len]; n       if (cnt >= k) { n         ans -= (cnt - k) * (n - len); n         cout << ans << endl; n         return 0; n       } n     } n   } n   cout << -1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b, sol; n int main() { n   sol = 1; n   scanf( %lld%lld , &a, &b); n   sol *= ((1LL) << __builtin_popcountll(b)); n   if (((a - b) & 1) || (((a - b) >> 1) & b)) { n     puts( 0 ); n     return 0; n   } n   if (a == b) sol -= 2; n   if (!(a & 1) && !b) { n     puts( 1 ); n     return 0; n   } n   cout << sol; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 110, MAXK = 22, mod = 1000000007; n struct edge { n   int adj, next; n } e[MAXN << 1]; n int n, k, f[MAXN][MAXK << 1]; n int tot, head[MAXN], temp[MAXK << 1]; n inline void AddEdge(int u, int v) { n   tot++; n   e[tot].adj = v, e[tot].next = head[u]; n   head[u] = tot; n } n inline void Init() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i < n; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     AddEdge(u, v), AddEdge(v, u); n   } n } n void DFS(int u, int fa) { n   f[u][0] = f[u][k + 1] = 1; n   for (int i = head[u]; i; i = e[i].next) { n     int &v = e[i].adj; n     if (v == fa) continue; n     DFS(v, u); n     memset(temp, 0, sizeof(temp)); n     for (int i = 0; i <= 2 * k; i++) n       for (int j = 0; j <= 2 * k; j++) { n         if (i + j + 1 <= 2 * k + 1) n           temp[min(i, j + 1)] = n               (temp[min(i, j + 1)] + (long long)f[u][i] * f[v][j]) % mod; n         else n           temp[max(i, j + 1)] = n               (temp[max(i, j + 1)] + (long long)f[u][i] * f[v][j]) % mod; n       } n     memcpy(f[u], temp, sizeof(temp)); n   } n } n int main() { n   Init(); n   DFS(1, 0); n   int ans = 0; n   for (int i = 0; i <= k; i++) ans = (ans + f[1][i]) % mod; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = int(500 * 1000 + 7); n int n, k; n vector<pair<int, int> > adj[N]; n long long dp[N][2]; n void dfs(int v, int p = -1) { n   vector<long long> x; n   long long curr = 0; n   for (auto it : adj[v]) { n     int to = it.first; n     int w = it.second; n     if (to == p) continue; n     dfs(to, v); n     curr += dp[to][0]; n     x.push_back(dp[to][1] + w - dp[to][0]); n   } n   sort(x.begin(), x.end(), greater<long long>()); n   for (int i = 0; i < min((int)x.size(), k); i++) { n     if (x[i] > 0) curr += x[i]; n   } n   dp[v][0] = dp[v][1] = curr; n   if (k <= (int)x.size() && x[k - 1] > 0) dp[v][1] -= x[k - 1]; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int q; n   cin >> q; n   while (q--) { n     cin >> n >> k; n     for (int i = 0; i < n; i++) adj[i].clear(); n     for (int i = 0; i < n - 1; i++) { n       int u, v, w; n       cin >> u >> v >> w; n       u--; n       v--; n       adj[u].push_back({v, w}); n       adj[v].push_back({u, w}); n     } n     dfs(0, -1); n     cout << dp[0][0] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int oo = 0x3f3f3f3f; n const long long ooo = 9223372036854775807ll; n const int _cnt = 1000 * 1000 + 7; n const int _p = 1000 * 1000 * 1000 + 7; n const int N = 200005; n const double PI = acos(-1.0); n const double eps = 1e-9; n int o(int x) { return x % _p; } n int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } n int lcm(int a, int b) { return a / gcd(a, b) * b; } n void file_put() { n   freopen( filename.in ,  r , stdin); n   freopen( filename.out ,  w , stdout); n } n long long Pow(long long x, long long k) { n   long long ans = 1; n   for (; k; k >>= 1, x = x * x % _p) n     if (k & 1) (ans *= x) %= _p; n   return ans; n } n long long calc(int x, int k, int m) { n   return (Pow(10, k) * Pow(100 - 9 * x, m) % _p - Pow(91 - 9 * x, m)) % _p * x % n          _p * Pow(9, _p - 2) % _p; n } n char st[N]; n int n, cnt[10], s = 0; n long long ans = 0; n int main() { n   scanf( %s , st + 1); n   n = strlen(st + 1); n   for (int i = (1); i <= (n); ++i) { n     for (int j = (0); j <= (st[i] -  0  - 1 + (i == n)); ++j) { n       cnt[j]++, s = 0; n       for (int k = (0); k <= (9); ++k) { n         s += cnt[k]; n         (ans += Pow(10, i - s) * calc(k, cnt[k], n - i) % _p) %= _p; n       } n       cnt[j]--; n     } n     cnt[st[i] -  0 ]++; n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, c; n   long long t, a; n   scanf( %d%lld%d , &n, &t, &c); n   int ans = 0, tmp = 0; n   for (int i = 0; i < n; i++) { n     scanf( %lld , &a); n     if (a > t) { n       tmp = 0; n     } else { n       tmp++; n       if (tmp >= c) { n         ans++; n       } n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, j, k, p, q, mx = 0, sm = -1, smc = 0, cnt = 0, n; n   scanf( %d , &n); n   int arr[n + 5]; n   int a[100050]; n   memset(a, 0, sizeof(a)); n   for (i = 0; i < n; i++) { n     scanf( %d , &p); n     a[p]++; n     arr[i] = p; n   } n   sort(arr, arr + n); n   for (i = n - 1; i >= 0; i--) { n     if (a[arr[i]] % 2) { n       return !printf( Conan n ); n     } n   } n   printf( Agasa n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mas[200100], k, s = 0, d; n long long n, p = 1, del = 0, a, b, c; n unsigned long long inf = n     (unsigned long long)1000000000 * 1000000000 * (long long)10; n int main() { n   cin >> n >> k; n   for (int i = 1; i <= n; i++) scanf( %I64d , &mas[i]); n   for (int i = 1; i <= n; i++, p++) { n     a = (p - 1); n     b = (n - del - p); n     c = mas[i]; n     if (a * b > (s - k) / c) { n       printf( %d n , i); n       p--; n       del++; n     } else { n       if (s < inf) s += (p - 1) * mas[i]; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t, n, a[1000], k; n int main() n { n     cin >> t; n     while(t--) n     { n         cin >> n >> k; n         if(k <= (n - 1)/2) n         { n             int spt = 0, spt1 = k + 1; n             for(int i = 1; i <= 2*k + 1; i++) n             { n                 if(i%2 == 1) n                     a[i] = ++spt; n                 else a[i] = ++spt1; n             } n             for(int i = 2*k + 2; i <= n; ++i) n                 a[i] = ++spt1; n             for(int i = 1; i <= n; ++i) n                 cout << a[i] <<    ; n             cout <<   n ; n         } n         else cout << -1 <<   n ; n     } n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   char ch; n   int val; n   int idx; n   node(char ch =  a , int val = -1, int idx = 0) : ch(ch), val(val), idx(idx) {} n }; n void swap(node& a, node& b) { n   node temp(a.ch, a.val, a.idx); n   a = b; n   b = temp; n } n void disp(vector<node>& arr) { n   for (auto e : arr) cout << e.ch <<   t ; n   cout <<   n ; n   for (auto e : arr) cout << e.val <<   t ; n   cout <<   n ; n   for (auto e : arr) cout << e.idx <<   t ; n   cout <<   n ; n } n int main() { n   { n     ios_base::sync_with_stdio(false); n     cin.tie(NULL); n   }; n   long long n; n   cin >> n; n   string str; n   cin >> str; n   vector<long long> res(n, -1); n   vector<node> arr(n); n   for (int i = 0; i < n; i++) { n     arr[i].ch = str[i]; n     arr[i].idx = i; n   } n   for (int i = 0; i < n; i++) { n     bool isZero = 0, isOne = 0; n     char smallestChar = arr[i].ch; n     int idx = i; n     for (int j = i; j < n; j++) { n       if (int(smallestChar) > int(arr[j].ch)) { n         smallestChar = arr[j].ch; n         idx = j; n       } n     } n     for (int j = i; j < idx; j++) { n       if (arr[j].val == 0) n         isZero = 1; n       else if (arr[j].val == 1) n         isOne = 1; n     } n     if (isZero and isOne) { n       cout <<  NO n ; n       return 0; n     } else if (isZero) { n       if (arr[idx].val == 0) { n         cout <<  NO n ; n         return 0; n       } else { n         arr[idx].val = 1; n         for (int j = i; j < idx; j++) arr[j].val = 0; n         for (int j = idx; j > i; j--) swap(arr[j], arr[j - 1]); n       } n     } else if (isOne) { n       if (arr[idx].val == 1) { n         cout <<  NO n ; n         return 0; n       } else { n         arr[idx].val = 0; n         for (int j = i; j < idx; j++) arr[j].val = 1; n         for (int j = idx; j > i; j--) swap(arr[j], arr[j - 1]); n       } n     } else { n       if (arr[idx].val == 1) { n         for (int j = i; j < idx; j++) arr[j].val = 0; n         for (int j = idx; j > i; j--) swap(arr[j], arr[j - 1]); n       } else if (arr[idx].val == 0) { n         for (int j = i; j < idx; j++) arr[j].val = 1; n         for (int j = idx; j > i; j--) swap(arr[j], arr[j - 1]); n       } else { n         arr[idx].val = 1; n         for (int j = i; j < idx; j++) arr[j].val = 0; n         for (int j = idx; j > i; j--) swap(arr[j], arr[j - 1]); n       } n     } n   } n   cout <<  YES n ; n   for (auto e : arr) res[e.idx] = e.val; n   for (auto e : res) cout << e; n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   int n, m; n   cin >> n >> m; n   int t[m], l[m], r[m]; n   int a[n + 1]; n   fill_n(a, n + 1, -1); n   a[0] = 1e5; n   for (int i = 0; i < m; i++) { n     cin >> t[i] >> l[i] >> r[i]; n     if (t[i] == 1) { n       for (int j = l[i] + 1; j <= r[i]; j++) { n         a[j] = 1; n       } n     } n   } n   for (int i = 0; i < m; i++) { n     if (t[i] == 0) { n       bool ok = false; n       for (int j = l[i] + 1; j <= r[i]; j++) { n         ok |= (a[j] == -1); n       } n       if (ok == false) { n         cout <<  NO n ; n         return 0; n       } n     } n   } n   cout <<  YES n ; n   for (int i = 1; i <= n; i++) { n     a[i] += a[i - 1]; n     cout << a[i] <<    ; n   } n   cout <<   n ; n } n


#include <bits/stdc++.h> n const int MAX = 1e3 + 11; n using namespace std; n char A[MAX]; n int W[33]; n int main() { n   scanf( %s , (A)); n   int(K); n   scanf( %d , &K); n   for (int i = 0; i < (26); ++i) scanf( %d , &(W[i])); n   int mx = 0, N = int(strlen(A)); n   int v = *max_element(W, W + 26); n   for (int i = 0; i < (K + 1); ++i) { n     int s = 0, pos = i; n     for (int j = 0; j < (N); ++j) { n       s += W[A[j] -  a ] * (j + 1 + i); n     } n     for (int k = 0; k < (pos); ++k) { n       s += (k + 1) * v; n     } n     for (int k = (pos + N); k < (K + N); ++k) { n       s += (k + 1) * v; n     } n     mx = max(mx, s); n   } n   printf( %d , mx); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int i, j, n; n int a[1005]; n string s; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(NULL); n   cin >> n; n   n--; n   cin >> s; n   for (i = 0; i <= n; i++) a[i] = 1; n   for (i = 0; i < n; i++) { n     if (s[i] ==  = ) a[i + 1] = a[i]; n     if (s[i] ==  R ) a[i + 1] = a[i] + 1; n     if (s[i] ==  L ) { n       for (j = i; j >= 0; j--) { n         if ((s[j] ==  L  && a[j] > a[j + 1]) || n             (s[j] ==  R  && a[j] < a[j + 1]) || n             (s[j] ==  =  && a[j] == a[j + 1])) n           break; n         if ((s[j] ==  L )) a[j] = a[j + 1] + 1; n         if ((s[j] ==  = )) a[j] = a[j + 1]; n       } n     } n   } n   for (i = 0; i <= n; i++) cout << a[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n template <class T> n void R(T &x) { n   cin >> x; n } n void R(int &x) { scanf( %d , &x); } n void R(long long &x) { scanf( %lld , &x); } n void R(double &x) { scanf( %lf , &x); } n void R(char &x) { scanf(  %c , &x); } n void R(char *x) { scanf( %s , x); } n long long _pow(long long a, long long b) { n   long long res = 1ll; n   while (b) { n     if (b & 1) res = res * a % 1000000007; n     a = a * a % 1000000007; n     b >>= 1; n   } n   return res; n } n int main() { n   int n, k; n   char t[10005], s[10005]; n   while (~scanf( %d , &(n))) { n     R(k); n     R(t); n     int len = strlen(t); n     int i, j, flag = 0; n     for (i = 1; i < len; i++) { n       for (j = i; j < len; j++) { n         if (t[j] != t[j - i]) break; n       } n       if (j == len) break; n     } n     j = len; n     for (int o = 1; o < k; o++) { n       for (int x = len - i; x < len; x++) t[j++] = t[x]; n     } n     t[j] =   0 ; n     puts(t); n   } n   return 0; n } n


#include<set> n #include<map> n #include<stack> n #include<cmath> n #include<queue> n #include<cstdio> n #include<vector> n #include<climits> n #include<cstdlib> n #include<cstring> n #include<iostream> n #include<algorithm> n #define LL long long n using namespace std; n LL read(){ n  bool f=0;LL x=0;char c=getchar(); n  while(c< 0 || 9 <c){if(c== - )f=1;c=getchar();} n  while( 0 <=c&&c<= 9 ) x=(x<<3)+(x<<1)+(c^48),c=getchar(); n  return !f?x:-x; n } n typedef pair<long double,long double> pii; n #define mp make_pair n #define fi first n #define se second n #define lch (u<<1) n #define rch (u<<1|1) n const long double eps=1e-10; n const int MAXN=200000; n const int INF=0x3f3f3f3f; n LL a[MAXN+5]; n vector<pair<int,LL> > Tu[5*MAXN+5]; n bool K(pii p,pii a,pii b){if(p.fi==a.fi) return 1;return (p.se-a.se)/(p.fi-a.fi)>=(p.se-b.se)/(p.fi-b.fi);} n void Build(int u,int L,int R){ n  if(L==R){ n   Tu[u].push_back(mp(L,a[L])); n   return ; n  } n  int Mid=(L+R)>>1; n  Build(lch,L,Mid),Build(rch,Mid+1,R); n  Tu[u]=Tu[lch]; n  int lst=Tu[u].size()-1; n  for(int i=0;i<Tu[rch].size();i++){ n   while(lst&&K(Tu[u][lst-1],Tu[u][lst],Tu[rch][i])) Tu[u].pop_back(),lst--; n   Tu[u].push_back(Tu[rch][i]),lst++; n  } n  return ; n } n pair<long double,int> P[MAXN+5]; n int Query(int u,int L,int R,int qL,int qR,int pos){ n  if(qL<=L&&R<=qR){ n   int siz=Tu[u].size(); n   int le=0,ri=siz; n   while(le+1<ri){ n    int mid=(le+ri)>>1; n    if(K(mp(pos,a[pos]),Tu[u][mid-1],Tu[u][mid])) le=mid; n    else ri=mid; n   } n   return Tu[u][le].first; n  } n  int Mid=(L+R)>>1,ret=-1; n  if(qL<=Mid) n   ret=Query(lch,L,Mid,qL,qR,pos); n  if(Mid+1<=qR){ n   int tmp=Query(rch,Mid+1,R,qL,qR,pos); n   if(ret==-1||K(mp(pos,a[pos]),mp(ret,a[ret]),mp(tmp,a[tmp]))) n    ret=tmp; n  } n  return ret; n } n int n,m; n void Get(int L,int R,int ad){ n  if(L>=R) return ; n  int p=Query(1,0,n,L,R,L); n  P[p]=mp(1.0*(a[p]-a[L])/(p-L)-eps,R-L-1+ad); n  //printf( %f %d %d %d n ,(double)P[p].first,p,L,R-L-1+ad); n  Get(L,p-1,1),Get(p,R,ad); n  return ; n } n int ans[MAXN+5]; n long double k[MAXN+5]; n int main(){ n  n=read(),m=read(); n  for(int i=1;i<=n;i++) n   a[i]=a[i-1]+read(); n  Build(1,0,n); n  Get(0,n,0); n  sort(P+1,P+n+1); n  for(int i=n;i>=1;i--) n   ans[i]=max(P[i].second,ans[i+1]); n  for(int i=1;i<=m;i++){ n   k[i]=read(); n   int t=upper_bound(P+1,P+n+1,mp(k[i],0))-P; n   printf( %d ,ans[t]),putchar(i==m?  n :   ); n  } n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n int n, ans, Max, an, x; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &x); n     if (Max < x) { n       Max = x; n       ans = 0; n       an = 0; n     } n     if (x == Max) n       an++; n     else n       an = 0; n     ans = max(ans, an); n   } n   printf( %d , ans); n } n


#include <bits/stdc++.h> n int main() { n   unsigned short n; n   unsigned short ac1; n   unsigned short i; n   unsigned short w; n   unsigned short ac2; n   unsigned short gw; n   if (scanf( %hu , &n) != 1) return -1; n   if (n < 1 || n > 100) return -1; n   ac1 = 0; n   for (i = 0; i < n; i++) { n     if (scanf( %hu , &w) != 1) return -1; n     if (w != 100 && w != 200) return -1; n     if (w == 100) ac1++; n   } n   ac2 = n - ac1; n   gw = 50 * (ac1 + 2 * ac2); n   if (!(gw % 200) || (!(gw % 100) && ac1)) n     printf( YES n ); n   else n     printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n const int maxN = 1005; n long long x[maxN], y[maxN]; n long long det(int i, int j, int k) { n   return (x[j] - x[i]) * (y[k] - y[i]) - (x[k] - x[i]) * (y[j] - y[i]); n } n long long askArea(int i, int j, int k) { n   cout << 1 <<     << i <<     << j <<     << k << endl; n   long long resp; n   cin >> resp; n   return resp; n } n int askVec(int i, int j, int k) { n   cout << 2 <<     << i <<     << j <<     << k << endl; n   int res; n   cin >> res; n   return res; n } n int n; n int main() { n   cin >> n; n   int who = n; n   vector<int> up, down; n   for (int i = 2; i < n; i++) { n     if (askVec(1, i, who) < 0) { n       up.emplace_back(i); n     } else { n       down.emplace_back(i); n     } n   } n   vector<pair<long long, int> > get_vals; n   for (int v : up) { n     get_vals.emplace_back(askArea(1, v, who), v); n   } n   sort(get_vals.begin(), get_vals.end()); n   reverse(get_vals.begin(), get_vals.end()); n   deque<int> ans_up; n   if (!get_vals.empty()) ans_up.push_back(get_vals[0].second); n   for (int i = 1; i < get_vals.size(); i++) { n     int p = get_vals[i].second; n     if (askVec(1, p, ans_up.front()) < 0) n       ans_up.push_front(p); n     else n       ans_up.push_back(p); n   } n   vector<int> perm; n   for (int v : ans_up) perm.push_back(v); n   perm.push_back(who); n   get_vals.clear(); n   deque<int> ans_down; n   for (int v : down) { n     get_vals.emplace_back(askArea(1, v, who), v); n   } n   sort(get_vals.begin(), get_vals.end()); n   reverse(get_vals.begin(), get_vals.end()); n   if (!get_vals.empty()) ans_down.push_back(get_vals[0].second); n   for (int i = 1; i < get_vals.size(); i++) { n     int p = get_vals[i].second; n     if (askVec(1, p, ans_down.front()) < 0) n       ans_down.push_front(p); n     else n       ans_down.push_back(p); n   } n   for (int v : ans_down) perm.push_back(v); n   reverse(perm.begin(), perm.end()); n   cout << 0 <<    ; n   cout << 1 <<    ; n   for (int v : perm) cout << v <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class c> n struct rge { n   c b, e; n }; n template <class c> n rge<c> range(c i, c j) { n   return rge<c>{i, j}; n } n template <class c> n auto dud(c* x) -> decltype(cerr << *x, 0); n template <class c> n char dud(...); n struct debug { n   template <class c> n   debug& operator<<(const c&) { n     return *this; n   } n }; n const long long xx = 2e7; n const long long MOD = 1e9 + 7; n const long long inf = 1e18; n long long isprime(long long n) { n   if (n == 2) return 1; n   if (n % 2 == 0) return 0; n   for (long long i = 3; i * i <= n; i += 2) { n     if (n % i == 0) return 0; n   } n   return 1; n } n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long n; n   cin >> n; n   if (isprime(n)) { n     cout << 1 <<   n ; n   } else if (n % 2 == 0 || isprime(n - 2)) { n     cout << 2 <<   n ; n   } else n     cout << 3 <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n constexpr int maxn = 2e5 + 10, N = 260, M = 5e6 + 10; n constexpr int MAX_INF = 0x3f3f3f3f; n int mp[maxn]; n int main() { n   int T; n   cin >> T; n   while (T--) { n     int n, m; n     scanf( %d%d , &n, &m); n     int root = 0; n     memset(mp, 0, sizeof(mp)); n     while (m--) { n       int a, b, c; n       scanf( %d%d%d , &a, &b, &c); n       mp[b] = 1; n     } n     for (int i = 1; i <= n; i++) { n       if (!mp[i]) { n         root = i; n         break; n       } n     } n     for (int i = 1; i <= n; i++) { n       if (i == root) continue; n       printf( %d %d n , i, root); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, hp = 0, row[100], col[100]; n char cake[101][101]; n int main() { n   for (int i = 0; i < 100; ++i) { n     row[i] = 0, col[i] = 0; n   } n   cin >> n; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       cin >> cake[i][j]; n       if (cake[i][j] ==  C ) { n         ++row[j]; n         ++col[i]; n       } n     } n   } n   for (int i = 0; i < n; i++) { n     hp += (row[i] * (row[i] - 1)) / 2; n     hp += (col[i] * (col[i] - 1)) / 2; n   } n   cout << hp; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[100001], b[100001]; n void solve(int first) { n   vector<int> ans(1, first); n   for (int i = 1; i < n; i++) { n     int pre = ans.back(); n     for (int j = 0; j <= 3; j++) { n       if ((pre & j) == b[i] && (pre | j) == a[i]) { n         ans.push_back(j); n         break; n       } n     } n   } n   if (ans.size() != n) return; n   cout <<  YES n ; n   for (int x : ans) cout << x <<    ; n   exit(0); n } n int main() { n   cin >> n; n   for (int i = 1; i < n; i++) cin >> a[i]; n   for (int i = 1; i < n; i++) cin >> b[i]; n   for (int i = 0; i <= 3; i++) solve(i); n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int a[111]; n int b[111]; n int main() { n   cin >> n >> m; n   int s = 0; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     s ^= a[i]; n   } n   int tmp = 0; n   for (int i = 0; i < m; i++) { n     cin >> b[i]; n     tmp ^= b[i]; n   } n   if (tmp != s) { n     cout <<  NO ; n     return 0; n   } n   cout <<  YES  << endl; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (i == 0 && j == 0) { n         cout << (tmp ^ a[0] ^ b[0]) <<    ; n       } else if (i == 0) { n         cout << b[j] <<    ; n       } else if (j == 0) { n         cout << a[i] <<    ; n       } else { n         cout << 0 <<    ; n       } n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, temp; n   cin >> n; n   string s; n   cin >> s; n   temp = n; n   for (int i = n - 2; i >= 0; i--) { n     if (s.substr(i, 2) ==  10  || s.substr(i, 2) ==  01 ) { n       temp -= 2; n       s.erase(i, 2); n       i++; n     } n   } n   cout << temp; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   map<int, bool> a; n   for (int i = 0, j; i < n; i++) { n     cin >> j; n     a[j] = 1; n   } n   int k = 0; n   vector<int> l; n   for (int i = 1; m - i >= 0; i++) n     if (!a[i]) { n       l.push_back(i); n       m -= i; n     } n   cout << l.size() << endl; n   for (int i = 0; i < l.size(); i++) cout << l[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5; n int n, m, q, t = 1; n int lson[N * 2], rson[N * 2], vm[2][N * 2], ovl[N * 2]; n set<pair<int, int> > sm[2][N * 2]; n map<int, int> op[N * 2]; n void build(int pos, int x, int y) { n   vm[1][pos] = m + 1; n   if (x == y) return; n   int mid = (x + y) >> 1; n   lson[pos] = ++t; n   rson[pos] = ++t; n   build(lson[pos], x, mid); n   build(rson[pos], mid + 1, y); n } n inline int MAX(int knd, int pos) { n   if (sm[knd][pos].empty()) return 0; n   set<pair<int, int> >::iterator it = sm[knd][pos].end(); n   it--; n   return it->first; n } n inline int MIN(int knd, int pos) { n   if (sm[knd][pos].empty()) return m + 1; n   return sm[knd][pos].begin()->first; n } n void update(int pos) { n   vm[0][pos] = MAX(0, pos); n   if (lson[pos]) vm[0][pos] = max(vm[0][pos], vm[0][lson[pos]]); n   if (rson[pos]) vm[0][pos] = max(vm[0][pos], vm[0][rson[pos]]); n   vm[1][pos] = MIN(1, pos); n   if (lson[pos]) vm[1][pos] = min(vm[1][pos], vm[1][lson[pos]]); n   if (rson[pos]) vm[1][pos] = min(vm[1][pos], vm[1][rson[pos]]); n   ovl[pos] = (MIN(1, pos) <= vm[0][pos]) | (MAX(0, pos) >= vm[1][pos]); n   ovl[pos] |= ovl[lson[pos]] | ovl[rson[pos]]; n } n void modify(int knd, int pos, int l, int r, int x, int y, pair<int, int> v) { n   if (l >= x && r <= y) { n     if (knd == 0) { n       if (sm[knd][pos].find(v) != sm[knd][pos].end()) n         sm[knd][pos].erase(v); n       else n         sm[knd][pos].insert(v); n     } else { n       if (sm[knd][pos].find(v) != sm[knd][pos].end()) n         sm[knd][pos].erase(v); n       else n         sm[knd][pos].insert(v); n     } n     update(pos); n     return; n   } n   if (l > y || r < x) return; n   int mid = (l + r) >> 1; n   modify(knd, lson[pos], l, mid, x, y, v); n   modify(knd, rson[pos], mid + 1, r, x, y, v); n   update(pos); n } n int main() { n   scanf( %d%d%d , &n, &m, &q); n   build(1, 1, n); n   for (int i = 1; i <= q; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     if (op[x][y] == 0) { n       op[x][y] = i; n       if (x % 2 == 0) n         modify(0, 1, 1, n, 1, x / 2, make_pair(y / 2, i)); n       else n         modify(1, 1, 1, n, (x + 1) / 2, n, make_pair((y + 1) / 2, i)); n     } else { n       if (x % 2 == 0) n         modify(0, 1, 1, n, 1, x / 2, make_pair(y / 2, op[x][y])); n       else n         modify(1, 1, 1, n, (x + 1) / 2, n, make_pair((y + 1) / 2, op[x][y])); n       op[x][y] = 0; n     } n     if (ovl[1]) n       puts( NO ); n     else n       puts( YES ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int x1, y1, x2, y2; n   cin >> x1 >> y1 >> x2 >> y2; n   if (x1 == x2 && y1 == y2) { n     cout <<  10 ; n     return; n   } n   if (x1 == x2) { n     cout << 2 * (abs(y2 - y1) + 1) + 4; n     return; n   } n   if (y1 == y2) { n     cout << 2 * (abs(x2 - x1) + 1) + 4; n     return; n   } n   cout << 2 * (abs(x2 - x1) + abs(y2 - y1) + 2); n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n template <class T> n bool ckmin(T& a, const T& b) { n   return a > b ? a = b, 1 : 0; n } n template <class T> n bool ckmax(T& a, const T& b) { n   return a < b ? a = b, 1 : 0; n } n const int N = 1 << 7, M = 1 << 14; n int a[M], b[M], c[M]; n bool val[N], vis[N]; n vector<int> g[N]; n int n, m; n bool dfs(int u, bool x) { n   val[u] = x; n   vis[u] = true; n   for (int e : g[u]) { n     int v = a[e] ^ b[e] ^ u; n     bool new_x = c[e] ^ 1 ^ x; n     if (!vis[v]) { n       if (!dfs(v, new_x)) return false; n     } else if (new_x != val[v]) n       return false; n   } n   return true; n } n bool solve(bool init) { n   fill(vis, vis + n, false); n   fill(val, val + n, false); n   for (auto u = (0); u < (n); ++u) n     if (!vis[u] && !dfs(u, init)) return false; n   return true; n } n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cin >> n >> m; n   for (auto e = (0); e < (m); ++e) { n     cin >> a[e] >> b[e] >> c[e], --a[e], --b[e]; n     g[a[e]].push_back(e); n     g[b[e]].push_back(e); n   } n   if (solve(0) || solve(1)) { n     int cnt = 0; n     for (auto u = (0); u < (n); ++u) cnt += val[u]; n     cout << cnt <<   n ; n     for (auto e = (0); e < (m); ++e) assert(c[e] ^ val[a[e]] ^ val[b[e]]); n     for (auto u = (0); u < (n); ++u) n       if (val[u]) cout << u + 1 <<    ; n   } else n     cout <<  Impossible ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200005; n const int M = 400005; n inline int read() { n   int 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 f * x; n } n int n, m, q, num; n int hd[N], nxt[M], to[M], tot; n inline void add(int x, int y) { n   to[++tot] = y; n   nxt[tot] = hd[x]; n   hd[x] = tot; n } n int dfn[N], low[N], dfn_cnt; n int st[N], tp; n bool vis[N]; n vector<int> G[N]; n void tarjan(int x) { n   vis[x] = 1; n   st[++tp] = x; n   dfn[x] = low[x] = ++dfn_cnt; n   for (int i = hd[x]; i; i = nxt[i]) { n     int y = to[i]; n     if (!dfn[y]) { n       tarjan(y); n       low[x] = min(low[x], low[y]); n       if (low[y] == dfn[x]) { n         ++num; n         while (st[tp + 1] != y) { n           G[num].push_back(st[tp]); n           G[st[tp]].push_back(num); n           vis[st[tp--]] = 0; n         } n         G[num].push_back(x); n         G[x].push_back(num); n       } n     } else if (vis[y]) n       low[x] = min(low[x], dfn[y]); n   } n } n multiset<int> s[N]; n int siz[N], fa[N], dep[N], son[N]; n void dfs_son(int x, int f) { n   fa[x] = f; n   siz[x] = 1; n   dep[x] = dep[f] + 1; n   for (int i = 0; i < G[x].size(); i++) { n     int y = G[x][i]; n     if (y == f) continue; n     dfs_son(y, x); n     siz[x] += siz[y]; n     if (siz[y] > siz[son[x]]) son[x] = y; n   } n } n int rev[N], top[N]; n void dfs_chain(int x, int tp) { n   top[x] = tp; n   dfn[x] = ++dfn_cnt; n   rev[dfn_cnt] = x; n   if (son[x]) dfs_chain(son[x], tp); n   for (int i = 0; i < G[x].size(); i++) { n     int y = G[x][i]; n     if (y == fa[x] || y == son[x]) continue; n     dfs_chain(y, y); n   } n } n int val[N << 2]; n int w[N]; n void build(int l, int r, int p) { n   if (l == r) { n     val[p] = w[rev[l]]; n     return; n   } n   build(l, ((l + r) >> 1), (p << 1)); n   build(((l + r) >> 1) + 1, r, (p << 1 | 1)); n   val[p] = min(val[(p << 1)], val[(p << 1 | 1)]); n } n void modify(int l, int r, int t, int v, int p) { n   if (l == r) { n     val[p] = v; n     return; n   } n   if (t <= ((l + r) >> 1)) n     modify(l, ((l + r) >> 1), t, v, (p << 1)); n   else n     modify(((l + r) >> 1) + 1, r, t, v, (p << 1 | 1)); n   val[p] = min(val[(p << 1)], val[(p << 1 | 1)]); n } n int query(int l, int r, int L, int R, int p) { n   if (L <= l && r <= R) return val[p]; n   int ans = 0x3f3f3f3f; n   if (L <= ((l + r) >> 1)) n     ans = min(ans, query(l, ((l + r) >> 1), L, R, (p << 1))); n   if (R > ((l + r) >> 1)) n     ans = min(ans, query(((l + r) >> 1) + 1, r, L, R, (p << 1 | 1))); n   return ans; n } n int get_min(int x, int y) { n   int ans = 0x3f3f3f3f; n   while (top[x] != top[y]) { n     if (dep[top[x]] < dep[top[y]]) swap(x, y); n     ans = min(ans, query(1, num, dfn[top[x]], dfn[x], 1)); n     x = fa[top[x]]; n   } n   if (dfn[x] > dfn[y]) swap(x, y); n   ans = min(ans, query(1, num, dfn[x], dfn[y], 1)); n   if (x > n) ans = min(ans, w[fa[x]]); n   return ans; n } n int main() { n   n = read(); n   m = read(); n   q = read(); n   for (int i = 1; i <= n; i++) w[i] = read(); n   num = n; n   for (int i = 1, x, y; i <= m; i++) { n     x = read(); n     y = read(); n     add(x, y), add(y, x); n   } n   tarjan(1); n   dfn_cnt = 0; n   dfs_son(1, 0); n   dfs_chain(1, 1); n   for (int i = 1; i <= n; i++) n     if (fa[i]) s[fa[i]].insert(w[i]); n   for (int i = n + 1; i <= num; i++) w[i] = *s[i].begin(); n   memset(val, 0x3f, sizeof(val)); n   build(1, num, 1); n   char op; n   int x, y; n   while (q--) { n     cin >> op; n     x = read(); n     y = read(); n     if (op ==  C ) { n       modify(1, num, dfn[x], y, 1); n       if (fa[x]) { n         s[fa[x]].erase(s[fa[x]].lower_bound(w[x])); n         s[fa[x]].insert(y); n         if (w[fa[x]] != *s[fa[x]].begin()) { n           w[fa[x]] = *s[fa[x]].begin(); n           modify(1, num, dfn[fa[x]], w[fa[x]], 1); n         } n       } n       w[x] = y; n     } else n       printf( %d n , get_min(x, y)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename TT> n ostream& operator<<(ostream& s, pair<T, TT> t) { n   return s <<  (  << t.first <<  ,  << t.second <<  ) ; n } n template <typename T> n ostream& operator<<(ostream& s, vector<T> t) { n   for (int(i) = 0; (i) < (sz(t)); ++(i)) s << t[i] <<    ; n   return s; n } n int r, n; n long long MOD = 1000003; n long long qp(long long a, long long b) { n   long long x = 1; n   while (b) { n     if (b & 1) x = x * a % MOD; n     a = a * a % MOD; n     b >>= 1; n   } n   return x; n } n int main() { n   cin >> r >> n; n   long long ans = 0, cur = 1; n   for (int a = n, b = 1; b <= r; a++, b++) { n     cur = cur * a % MOD * qp(b, MOD - 2) % MOD; n     ans = (ans + cur) % MOD; n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string name, a; n   vector<pair<int, string> > s; n   vector<pair<int, string> > v(n); n   for (int i = 0; i < (int)n; i++) cin >> v[i].second >> v[i].first; n   sort(v.begin(), v.end()); n   int h = 1e9; n   for (int i = 0; i < (int)n; i++) { n     if (v[i].first > (int)s.size()) { n       cout << -1 << endl; n       return 0; n     } n     if (i && v[i - 1].first != v[i].first) h--; n     s.insert(s.begin() + v[i].first, make_pair(h, v[i].second)); n   } n   for (int i = 0; i < (int)s.size(); i++) n     cout << s[i].second <<     << s[i].first << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     long long int n, k; n     cin >> n >> k; n     long long int ans = 0; n     if (n < k) { n       cout << n << endl; n       continue; n     } n     while (n != 0) { n       if (n % k == 0) { n         n = n / k; n         ans++; n       } else { n         long long x = n % k; n         n -= x; n         ans += x; n       } n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 111; n const double INF = 1e200; n double dp[N][10 * N]; n struct problem { n   int a, p; n   bool operator<(const problem &o) const { return a > o.a; } n } p[N]; n int n; n double C, T; n double solve(double x) { n   x /= 0.9; n   auto t = (sqrt(C * x) - 1) / C; n   t = max(t, 0.0); n   return x / (1 + C * t) + t; n } n int main() { n   int tc; n   cin >> tc; n   while (tc--) { n     cin >> n >> C >> T; n     for (int i = 0; i < n; i++) cin >> p[i].a >> p[i].p; n     sort(p, p + n); n     fill(dp[0], dp[N], INF); n     dp[0][0] = 0; n     int sum = 0; n     for (int i = n - 1; i >= 0; i--) { n       for (int k = n - 1 - i; k >= 0; k--) { n         for (int s = sum; s >= 0; s--) n           if (dp[k][s] < INF) { n             dp[k + 1][s + p[i].p] = n                 min(dp[k + 1][s + p[i].p], dp[k][s] / 0.9 + p[i].a); n           } n       } n       sum += p[i].p; n     } n     int ans = 0; n     for (int s = sum; s > 0; s--) { n       for (int k = 0; k <= n; k++) { n         if (dp[k][s] < INF) { n           auto cost = k * 10 + solve(dp[k][s]); n           if (cost <= T) { n             ans = max(ans, s); n           } n         } n       } n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a[101], ans = 0; n   cin >> n; n   bool flag = false; n   for (int i = 1; i <= n; i += 1) { n     cin >> a[i]; n     if (a[i] == 100) flag = true; n     ans += a[i]; n   } n   if (ans % 200 == 100) n     cout <<  NO  << endl; n   else { n     if (ans % 400 == 0) n       cout <<  YES  << endl; n     else if (flag) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 10 * 100 * 1000 + 10; n vector<int> vec[N]; n int bit[N]; n int n, c; n void addbit(int i, int p) { n   for (i++; i <= c; i += (i & -i)) bit[i] += p; n } n int get(int i) { n   int x = 0; n   for (i++; i > 0; i -= (i & -i)) x += bit[i]; n   return x; n } n void add(int l, int r) { n   addbit(l, 1); n   addbit(r, -1); n } n int main() { n   cin >> n >> c; n   for (int i = 0; i < n; i++) { n     int t; n     cin >> t; n     for (int j = 0; j < t; j++) { n       int a; n       cin >> a; n       vec[i].push_back(a - 1); n     } n   } n   for (int i = 0; i < n - 1; i++) { n     int j = 0, k = 0; n     while (j < (int)vec[i].size() && k < (int)vec[i + 1].size() && n            vec[i][j] == vec[i + 1][k]) n       j++, k++; n     if (j == (int)vec[i].size()) n       add(0, c); n     else if (k == (int)vec[i + 1].size()) { n       cout <<  -1 n ; n       return 0; n     } else { n       int a = vec[i][j], b = vec[i + 1][k]; n       int li = (c - a) % c, ri = (c - b) % c; n       if (li < ri) n         add(li, ri); n       else n         add(li, c), add(0, ri); n     } n   } n   for (int i = 0; i < c; i++) n     if (get(i) >= n - 1) { n       cout << i << endl; n       return 0; n     } n   cout << -1 << endl; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int n; n string s, ret; n bool dfs(int idx, int four, int seven, bool flag) { n   if (idx == n) return true; n   if (flag) { n     for (int i = 0; i < four; i++) ret[idx + i] =  4 ; n     for (int i = four; i < four + seven; i++) ret[idx + i] =  7 ; n     return true; n   } n   if (four > 0 && s[idx] <=  4  && n       dfs(idx + 1, four - 1, seven, s[idx] <  4 )) { n     ret[idx] =  4 ; n     return true; n   } n   if (seven > 0 && s[idx] <=  7  && n       dfs(idx + 1, four, seven - 1, s[idx] <  7 )) { n     ret[idx] =  7 ; n     return true; n   } n   return false; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> s; n   n = s.length(); n   ret.resize(n); n   if (n % 2 == 1 || !dfs(0, n / 2, n / 2, false)) { n     int half = (n + 2) / 2; n     for (int i = 0; i < half; i++) cout <<  4 ; n     for (int i = 0; i < half; i++) cout <<  7 ; n     cout <<   n ; n   } else n     cout << ret <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline void Routine() { n   srand(time(NULL)); n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n } n template <class T, class U> n istream &operator>>(istream &in, pair<T, U> &p) { n   in >> p.fi >> p.se; n   return in; n } n template <class T, class U> n ostream &operator<<(ostream &out, const pair<T, U> &p) { n   out << p.first <<     << p.second; n   return out; n } n template <class T> n istream &operator>>(istream &in, vector<T> &v) { n   for (auto &i : v) { n     in >> i; n   } n   return in; n } n template <class T> n ostream &operator<<(ostream &out, const vector<T> &v) { n   for (auto &i : v) { n     out << i <<   n ; n   } n   return out; n } n const long long mod = 1e9 + 7; n int main() { n   Routine(); n   long long q, l1, l2, r1, r2, i; n   cin >> q; n   for (i = 0; i < q; i++) { n     cin >> l1 >> r1 >> l2 >> r2; n     if (l1 != r2) { n       cout << l1 <<     << r2 <<   n ; n     } else { n       cout << r1 <<     << l2 <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int mod = 1e9 + 7; n using namespace std::chrono; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int n; n   cin >> n; n   string s; n   cin >> s; n   long long int a[26]; n   for (int i = 0; i < 26; i++) cin >> a[i]; n   long long int maxx = -1, len = 0, minn; n   vector<long long int> dp(n + 1, 0), dp2(n + 1, 1e12); n   for (int i = 0; i < n; i++) { n     minn = 1e12; n     for (int j = i; j >= 0; j--) { n       len = i - j + 1; n       minn = min(minn, a[s[j] -  a ]); n       if (minn < len) break; n       long long int x = j - 1 >= 0 ? dp[j - 1] : 1; n       dp[i] = (dp[i] + x) % mod; n       maxx = max(maxx, len); n       x = j - 1 >= 0 ? dp2[j - 1] : 0; n       dp2[i] = min(dp2[i], x + 1); n     } n   } n   cout << dp[n - 1] % mod << endl << maxx << endl << dp2[n - 1]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<string> s; n vector<pair<int, int> > v; n int gf = 0; n int x[9] = {-1, -1, -1, 0, 1, 1, 1, 0, 0}; n int y[9] = {-1, 0, 1, 1, 1, 0, -1, -1, 0}; n void dfs(int a, int b, int le) { n   if (gf) return; n   if (le == 8 || (a == 0 && b == 7)) { n     gf = 1; n     return; n   } n   int a1, b1, i, j, k, x1, y1, flag, x2, y2; n   for (i = 0; i < 9; i++) { n     flag = 0; n     a1 = a + x[i], b1 = b + y[i]; n     if (a1 >= 0 && a1 < 8 && b1 >= 0 && b1 < 8) { n       for (k = 0; k < v.size(); k++) { n         x1 = v[k].first + (le + 1); n         y1 = v[k].second; n         x2 = v[k].first + (le); n         y2 = v[k].second; n         if ((a1 == x1 && b1 == y1) || (a1 == x2 && b1 == y2)) flag = 1; n       } n       if (flag == 0) dfs(a1, b1, le + 1); n     } n   } n } n int main() { n   string st; n   int i; n   for (i = 0; i < 8; i++) { n     cin >> st; n     s.push_back(st); n   } n   int j; n   for (i = 0; i < 8; i++) { n     for (j = 0; j < 8; j++) { n       if (s[i][j] ==  S ) v.push_back(make_pair(i, j)); n     } n   } n   dfs(7, 0, 0); n   if (gf) n     cout <<  WIN  n          <<   n ; n   else n     cout <<  LOSE  n          <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Wall { n   int l, r, t; n   void init(int _l, int _r, int _t) { l = _l, r = _r, t = _t; } n   void input() { scanf( %d%d%d , &l, &r, &t); } n   static bool by_l(const Wall &a, const Wall &b) { return a.l < b.l; } n   bool operator<(const Wall &a) const { return t > a.t; } n } w[500010], wc[500010]; n struct Table { n   int a[500010 * 2], top; n   Table() { top = 0; } n   void insert(int x) { a[top++] = x; } n   void sort() { n     std::sort(a, a + top); n     top = unique(a, a + top) - a; n   } n   int search(int x) { return lower_bound(a, a + top, x) - a; } n } table; n struct Tri { n   int x, p; n   void init(int _x, int _p) { x = _x, p = _p; } n   bool operator<(const Tri &a) const { return x < a.x; } n } tri[500010]; n int q[500010]; n int main() { n   int n, m; n   cin >> m >> n; n   for (int i = 0; i < n; ++i) { n     w[i].input(); n   } n   for (int i = 0; i < m; ++i) { n     scanf( %d , q + i); n   } n   sort(w, w + n, Wall::by_l); n   for (int i = 0; i < n; ++i) { n     table.insert(w[i].l), table.insert(w[i].r); n   } n   table.sort(); n   priority_queue<Wall> que; n   int nc = 0; n   for (int i = 0, j = 0; i < table.top - 1; ++i) { n     while (j < n && w[j].l <= table.a[i]) { n       que.push(w[j++]); n     } n     while (!que.empty()) { n       Wall wall = que.top(); n       if (wall.r > table.a[i]) { n         wc[nc++].init(table.a[i], table.a[i + 1], wall.t); n         break; n       } n       que.pop(); n     } n   } n   int ntri = 0; n   for (int i = 0; i < nc; ++i) { n     tri[ntri++].init(wc[i].t - wc[i].r, 1); n     tri[ntri++].init(wc[i].t - wc[i].l, -1); n   } n   sort(tri, tri + ntri); n   int sgm = 0, cnt = 0; n   for (int i = 0, j = 0; i < m; ++i) { n     while (j < ntri && tri[j].x <= q[i]) { n       cnt += tri[j].p; n       sgm += tri[j].x * tri[j].p; n       ++j; n     } n     printf( %d n , q[i] * cnt - sgm); n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n; n   scanf( %d , &n); n   int a[200001]; n   int i; n   for (i = 0; i < n; i++) { n     scanf( %d , &a[i]); n   } n   long long buy = a[n - 1]; n   int pre = a[n - 1]; n   for (i = n - 2; i >= 0; i--) { n     if (a[i] >= pre - 1) { n       if (pre - 1 == 0) n         break; n       else n         buy += pre - 1; n       pre--; n     } else { n       buy += a[i]; n       pre = a[i]; n     } n   } n   printf( %lld n , buy); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   set<string> s; n   s.insert( don t even ); n   s.insert( worse ); n   s.insert( terrible ); n   s.insert( no way ); n   s.insert( go die in a hole ); n   s.insert( are you serious ); n   int c = 0; n   while (true) { n     cout << c++ << endl; n     string t; n     getline(cin, t); n     if (t !=  no ) { n       if (s.count(t) == 0) { n         cout <<  normal  << endl; n         return 0; n       } else { n         cout <<  grumpy  << endl; n         return 0; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int a[n]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   int max = a[0]; n   int pos = 0; n   for (int i = 0; i < n; i++) { n     if (max < a[i]) { n       max = a[i]; n       pos = i; n     } n   } n   bool k = true; n   for (int i = pos; i > 0; i--) { n     if (a[i - 1] >= a[i]) { n       k = false; n     } n   } n   for (int i = pos; i < n - 1; i++) { n     if (a[i] <= a[i + 1]) { n       k = false; n     } n   } n   if (k == true) n     printf( YES n ); n   else n     printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<int>> sum; n vector<vector<bool>> used; n int n, m; n int g = 0; n int k = 0; n vector<pair<int, int>> p = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; n void dfs(int first, int second, const int &r1, const int &r2, const int &l1, n          const int &l2) { n   if (first <= r1 || first > r2 || second <= l1 || second > l2 || n       used[first][second]) n     return; n   used[first][second] = true; n   k++; n   for (int i = 0; i < 4; i++) n     dfs(first + p[i].first, second + p[i].second, r1, r2, l1, l2); n } n bool f(int r) { n   r = r * 2 + 1; n   k = 0; n   for (int i = 0; i <= n; i++) n     for (int j = 0; j <= m; j++) used[i][j] = false; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       if (i >= r && j >= r && n           sum[i][j] - sum[i - r][j] - sum[i][j - r] + sum[i - r][j - r] == n               r * r) { n         dfs(i, j, i - r, i, j - r, j); n       } n   if (k == g) n     return true; n   else n     return false; n } n int main() { n   cin >> n >> m; n   sum.resize(n + 1, vector<int>(m + 1, 0)); n   used.resize(n + 1, vector<bool>(m + 1, 0)); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       char c; n       cin >> c; n       sum[i + 1][j + 1] = sum[i][j + 1] + sum[i + 1][j] - sum[i][j]; n       if (c ==  X ) sum[i + 1][j + 1]++; n     } n   g = sum.back().back(); n   int l = 0, r = min(n / 2 + 2, m / 2 + 2); n   while (l + 1 < r) { n     int c = (l + r) / 2; n     if (f(c)) n       l = c; n     else n       r = c; n   } n   cout << l <<   n ; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       if (i >= l + 1 && j >= l + 1 && i + l <= n && j + l <= m && n           sum[i + l][j + l] - sum[i - l - 1][j + l] - sum[i + l][j - l - 1] + n                   sum[i - l - 1][j - l - 1] == n               (2 * l + 1) * (2 * l + 1)) n         cout <<  X ; n       else n         cout <<  . ; n     } n     cout <<   n ; n   } n   cin >> n; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   for (int i = 0; i < t; i++) { n     int n; n     cin >> n; n     int sum = 0, odd = 0, even = 0; n     for (int i = 0; i < n; i++) { n       int x; n       cin >> x; n       if (x % 2 == 0) { n         even++; n       } else { n         odd++; n       } n       sum += x; n     } n     if (sum % 2 == 1) { n       cout <<  YES n ; n     } else { n       if (odd < n && odd > 0) { n         cout <<  YES n ; n       } else { n         cout <<  NO n ; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = (int)1E9; n const long long LINF = (long long)1E18; n int INP, AM; n char BUF[(1 << 10) + 1], *inp = BUF; n template <typename T> n T gcd(T a, T b) { n   return (b == 0) ? abs(a) : gcd(b, a % b); n } n template <typename T> n inline T lcm(T a, T b) { n   return a / gcd(a, b) * b; n } n template <typename T> n inline T sqr(T x) { n   return x * x; n } n const char DEBUG_PARAM[] =  __LOCAL_TESTING ; n const char IN[] =  input.txt ; n const char OUT[] =  output.txt ; n int ntest = 0, test; n inline void init(); n inline void run(); n inline void stop() { ntest = test - 1; } n int main(int argc, char* argv[]) { n   if (argc > 1 && strcmp(argv[1], DEBUG_PARAM) == 0) { n     freopen(IN,  r , stdin); n   } n   init(); n   if (ntest == 0) { n     puts( ntest = ? ); n     return 0; n   } n   for (test = 1; test <= ntest; test++) { n     run(); n   } n   return 0; n } n const int dx[] = {-1, 0, 0, 1}; n const int dy[] = {0, -1, 1, 0}; n const long double EPS = 1E-9; n const long long MODULO = 1000000007LL; n inline void init() { ntest = 1; } n double s; n void run() { n   cin >> s; n   double a, b, c; n   cin >> a >> b >> c; n   if (a == 0 && b == 0 && c == 0) { n     cout <<  0 0 0 ; n     return; n   } n   double sum = a + b + c; n   printf( %.20lf %.20lf %.20lf , a / sum * s, b / sum * s, c / sum * s); n } n


#include <bits/stdc++.h> n #include <iomanip>      // std::setprecision n  n #define ll long long n const long modulo=1000000007; n  n using namespace std; n  n  n  n int ctoi(char c) {return c- 0 ;} n  n  n  n int compare(pair <int,pair<int,int>> one, pair <int,pair<int,int>> two){ n  if(one.first<two.first) return 1; n  return 0; n } n  n ll power(ll a, ll b){ n ll res=1; n while(b!=0){ n  n if(b%2==1){ n  res*=a; n  //res%=modulo; n } n a*=a; n //a%=modulo; n b/=2; n } n return res; n } n  n int dp[501][501][21]={0}; n int n,m,k; n int dn[501][501]; n int rightt[501][501]; n  n int explore(int q,int i,int j){ n  n if(q==0){ return 0; n } n  n if(dp[i][j][q]!=0){ n  //cout<< 1 ; n  return dp[i][j][q]; n } n  int ans = dp[i][j][k]; n ans=INT_MAX; n  n  if(j<m-1) ans=min(ans,explore(q-2,i,j+1) + 2*dn[i][j]); n  if(j>0)ans=min(ans,explore(q-2,i,j-1) +2*dn[i][j-1]); n  if(i<n-1)ans=min(ans,explore(q-2,i+1,j) +2*rightt[i][j]); n  if(i>0)ans=min(ans,explore(q-2,i-1,j) +2*rightt[i-1][j]); n  n  n  //ans=min(min(explore(d,r,n-2,i,j-1,dn,right) +2*dn[i][y0], explore(d,r,n-2,i,j+1,dn,right) +2*dn[i][y]),min(explore(d,r,n-2,i-1,j,dn,right)+2*right[x0][j], explore(d,r,n-2,i+1,j,dn,right)+2*right[x][j])); n  dp[i][j][q]=ans; n  return ans; n  n  n  n } n  n  n void solve() n { n  n cin>>n>>m>>k; n  n  n  n if(k%2!=0){ n  n for(int i=0;i<n;i++){ n  for(int j=0;j<m;j++){ n    n   cout<< -1 <<   ; n  } n  cout<<endl; n } n return; n } n  n for(int i=0;i<n;i++){ n  for(int j=0;j<m-1;j++){ n   cin>>dn[i][j]; n  } n  n } n  n for(int i=0;i<n-1;i++){ n  for(int j=0;j<m;j++){ n   cin>>rightt[i][j]; n  } n  n } n  n int ans[501][501]; n  n for(int i=0;i<n;i++){ n  for(int j=0;j<m;j++){ n   ans[i][j]=explore(k,i,j); n   cout<<ans[i][j]<<   ; n  } n  cout<<endl; n } n  n  n  n } n  n  n  n  n  n  n  n int main() { n  n   #ifndef ONLINE_JUDGE n      freopen( input.txt ,  r , stdin); n      freopen( output.txt ,  w , stdout); n   #endif n  ios_base::sync_with_stdio(false);  n     cin.tie(NULL);    n  n  n ll t=1;//cin>>t; n while(t--){ n  n solve(); n  n } n  n  n return 0; n } n  n  n  n //rememberhere


#include <bits/stdc++.h> n using namespace std; n long long ar[1005][1005], br[1005][1005], fr[555]; n string s[555]; n string s1, s2; n int main() { n   long long i, j, k, m, n, r, c; n   while (cin >> r >> c) { n     getchar(); n     s[0] =   ; n     for (i = 1; i <= r; i++) { n       getline(cin, s[i]); n     } n     n = r; n     if (n & 1) { n       cout << n << endl; n       continue; n     } n     while (n > 0) { n       i = 1; n       j = n; n       while (s[i] == s[j]) { n         i++, j--; n         if (i > j) break; n       } n       if (i > j) n         n /= 2; n       else { n         cout << n << endl; n         return 0; n       } n       if (n & 1) { n         cout << n << endl; n         return 0; n       } n     } n     cout << 1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int cnt[27][200010]; n int main() { n   string s; n   int q, i, j, l, r, c; n   cin >> s >> q; n   memset(cnt, 0, sizeof(cnt)); n   for (i = 0; i < s.length(); i++) { n     c = s[i] -  a ; n     cnt[c][i + 1]++; n     for (j = 0; j < 26; j++) cnt[j][i + 1] += cnt[j][i]; n   } n   for (; q > 0; q--) { n     scanf( %d%d , &l, &r); n     if (l == r) n       cout <<  Yes  << endl; n     else { n       if (s[l - 1] != s[r - 1]) n         cout <<  Yes  << endl; n       else { n         int sum = 0; n         for (i = 0; i < 26; i++) { n           if (cnt[i][r] - cnt[i][l - 1] >= 1) sum++; n           if (sum == 3) break; n         } n         if (sum == 3) n           cout <<  Yes  << endl; n         else n           cout <<  No  << endl; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   bool palindrom = true; n   for (int i = 0; i < ceil(s.length() / 2.0); i++) { n     if (s[i] != s[s.length() - 1 - i]) palindrom = false; n   } n   if (!palindrom) { n     cout << s.length() <<   n ; n     return 0; n   } n   char elso = s[0]; n   bool mind_ugyanaz = true; n   for (auto c : s) { n     if (c != elso) mind_ugyanaz = false; n   } n   if (mind_ugyanaz) n     cout <<  0 n ; n   else n     cout << s.length() - 1 <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, dfn[100010], siz[100010], tim, idfn[100010], a[100010], Q; n vector<int> v[100010]; n inline int add(int a, int b) { n   if ((a += b) >= m) a -= m; n   return a; n } n void dfs(int np, int fath) { n   dfn[np] = ++tim; n   idfn[tim] = np; n   siz[np] = 1; n   for (auto &x : v[np]) { n     if (x == fath) continue; n     dfs(x, np); n     siz[np] += siz[x]; n   } n } n bitset<1000> bas, prm; n inline void shift(bitset<1000> &bt, int v) { n   if (!v) return; n   bt = ((bt << v) | (bt >> (m - v))) & bas; n } n class sgt { n  public: n   bitset<1000> dat[400010]; n   int lzy[400010]; n   void pushnow(int p, int v) { n     lzy[p] = add(lzy[p], v); n     shift(dat[p], v); n   } n   void pushdown(int p) { n     if (lzy[p]) { n       pushnow((p << 1), lzy[p]); n       pushnow(((p << 1) | 1), lzy[p]); n       lzy[p] = 0; n     } n   } n   void pushup(int p) { dat[p] = dat[(p << 1)] | dat[((p << 1) | 1)]; } n   void build(int p, int l, int r) { n     for (int i = l; i <= r; i++) dat[p].set(a[idfn[i]]); n     if (l == r) return; n     int mid = (l + r) >> 1; n     build((p << 1), l, mid); n     build(((p << 1) | 1), mid + 1, r); n   } n   void modify(int p, int l, int r, int ml, int mr, int v) { n     if (ml <= l && r <= mr) { n       pushnow(p, v); n       return; n     } n     pushdown(p); n     int mid = (l + r) >> 1; n     if (ml <= mid) modify((p << 1), l, mid, ml, mr, v); n     if (mr > mid) modify(((p << 1) | 1), mid + 1, r, ml, mr, v); n     pushup(p); n   } n   void query(int p, int l, int r, int ql, int qr, bitset<1000> &q) { n     if (ql <= l && r <= qr) { n       q |= dat[p]; n       return; n     } n     pushdown(p); n     int mid = (l + r) >> 1; n     if (ql <= mid) query((p << 1), l, mid, ql, qr, q); n     if (qr > mid) query(((p << 1) | 1), mid + 1, r, ql, qr, q); n     return; n   } n } T; n vector<int> prime; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < m; i++) bas.set(i); n   for (int i = 2; i < m; i++) prm.set(i); n   for (int i = 2; i < m; i++) { n     if (prm[i]) prime.push_back(i); n     for (int j = 0; j < prime.size() && i * prime[j] < m; j++) { n       prm[i * prime[j]] = 0; n       if ((i % prime[j]) == 0) break; n     } n   } n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]), a[i] %= m; n   for (int i = 1, ti, tj; i < n; i++) { n     scanf( %d%d , &ti, &tj); n     v[ti].push_back(tj); n     v[tj].push_back(ti); n   } n   dfs(1, 0); n   T.build(1, 1, n); n   scanf( %d , &Q); n   bitset<1000> ans; n   while (Q--) { n     int opt, x, y; n     scanf( %d%d , &opt, &x); n     if (opt == 1) { n       scanf( %d , &y); n       y %= m; n       T.modify(1, 1, n, dfn[x], dfn[x] + siz[x] - 1, y); n     } else { n       ans.reset(); n       T.query(1, 1, n, dfn[x], dfn[x] + siz[x] - 1, ans); n       printf( %d n , (ans & prm).count()); n     } n   } n   return 0; n } n