#include <bits/stdc++.h>   using namespace std;   const long double pi = 3.1415926535897932384626433832795l;   template <typename T>   inline auto sqr(T x) -> decltype(x * x) {     return x * x;   }   template <typename T1, typename T2>   inline bool umx(T1& a, T2 b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <typename T1, typename T2>   inline bool umn(T1& a, T2 b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   struct Input {     int n, k;     vector<vector<int> > g;     vector<int> h;     vector<int> s;     bool read() {       if (!(cin >> n)) {         return 0;       }       h.resize(n);       for (int i = int(0); i < int(n); ++i) {         cin >> h[i];       }       g.assign(n, vector<int>());       for (int i = int(0); i < int(n - 1); ++i) {         int u, v;         cin >> u >> v;         --u, --v;         g[u].push_back(v);         g[v].push_back(u);       }       cin >> k;       s.resize(k);       for (int i = int(0); i < int(k); ++i) {         cin >> s[i];       }       return 1;     }     void init(const Input& input) { *this = input; }   };   struct Data : Input {     int ans;     void write() { cout << ans <<   n ; }     virtual void solve() {}     virtual void clear() { *this = Data(); }   };   struct Solution : Data {     vector<int> sc_best;     vector<int> fs_best;     vector<int> all_vals;     vector<int> heights;     vector<int> backw_pos;     vector<int> forw_pos;     vector<int> fail_pos;     vector<int> fail_vers;     void dfs(int x, int par, int first, int second) {       if (first == -1 || h[x] <= h[first]) {         second = first;         first = x;       } else if (second == -1 || h[x] <= h[second]) {         second = x;       }       fs_best[x] = first;       sc_best[x] = second;       for (auto to : g[x]) {         if (to != par) {           dfs(to, x, first, second);         }       }     }     int mfit() {       int ans = -1;       int ln = 0;       for (int i = int(0); i < int(((int)(all_vals).size())); ++i) {         int cur = 0;         vector<int> new_h;         int rn = ln;         while (rn < n && fs_best[heights[rn]] == all_vals[i]) ++rn;         int fail_from = 0, fail_to = fail_pos[i];         int lp = forw_pos[i], rp = backw_pos[i];         bool ok = true;         for (int j = int(ln); j < int(rn); ++j) {           int a = h[all_vals[i]];           int b = 2000000000;           if (sc_best[heights[j]] != -1) {             b = h[sc_best[heights[j]]];           }           if (fail_from != fail_to) {             if (b >= fail_vers[fail_from]) {               umx(cur, fail_vers[fail_from] - a);               ++fail_from;             } else {               ok = false;             }           } else if (lp != rp) {             if (b >= s[lp]) {               umx(cur, s[lp] - a);               ++lp;             } else {               ok = false;             }           }         }         if (ok && fail_from == fail_to && lp == rp && (ans == -1 || ans > cur)) {           ans = cur;         }         ln = rn;       }       return ans;     }     void solve() {       sort((s).begin(), (s).end());       reverse((s).begin(), (s).end());       sc_best.assign(n, -1);       fs_best.assign(n, -1);       dfs(0, -1, -1, -1);       heights.resize(n);       for (int i = int(0); i < int(n); ++i) {         heights[i] = i;       }       sort((heights).begin(), (heights).end(), [&](int a, int b) {         return (h[fs_best[a]] > h[fs_best[b]] ||                 (h[fs_best[a]] == h[fs_best[b]] && fs_best[a] < fs_best[b]) ||                 (fs_best[a] == fs_best[b] &&                  (sc_best[b] != -1 &&                   (sc_best[a] == -1 || h[sc_best[a]] > h[sc_best[b]]))));       });       all_vals.clear();       for (auto x : heights) {         if (all_vals.empty() || all_vals.back() != fs_best[x]) {           all_vals.push_back(fs_best[x]);         }       }       int lp = 0, ln = 0;       int cnt = ((int)(all_vals).size());       forw_pos.assign(cnt, 0);       fail_pos.assign(cnt, 0);       for (int i = int(0); i < int(cnt - 1); ++i) {         while (ln < n && fs_best[heights[ln]] == all_vals[i]) {           int cur_h = h[all_vals[i]];           while (lp < k && cur_h < s[lp]) {             fail_vers.push_back(s[lp]);             ++lp;           }           if (lp < k) {             ++lp;           }           ++ln;         }         forw_pos[i + 1] = lp;         fail_pos[i + 1] = ((int)(fail_vers).size());       };       backw_pos.assign(cnt, k);       int rp = k - 1, rn = n - 1;       for (int i = int(cnt) - 1; i >= int(1); --i) {         while (rn >= 0 && fs_best[heights[rn]] == all_vals[i]) {           int cur_h = h[all_vals[i]];           if (rp >= 0) {             if (cur_h >= s[rp]) {               --rp;             }           }           --rn;         }         backw_pos[i - 1] = rp + 1;       }       ans = mfit();     }     void clear() { *this = Solution(); }   };   Solution sol;   int main() {     cout.setf(ios::showpoint | ios::fixed);     cout.precision(20);     ios_base::sync_with_stdio(false);     sol.read();     sol.solve();     sol.write();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long prod = 1;     int arr[10];     for (int i = 0; i < 10; i++) arr[i] = 1;     int p = 0;     while (prod < n) {       p %= 10;       prod /= arr[p];       ++arr[p];       prod *= arr[p];       p++;     }     string s =  codeforces ;     for (int i = 0; i < 10; i++) {       for (int j = 0; j < arr[i]; j++) cout << s[i];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, len, lcm, g, mod;   long long a[266666], b[266666], c[266666], d[266666], e[266666], f[266666];   long long pw[266666], tmp[266666], w[2][266666], rev[266666];   long long mul(long long a, long long b) {     return (a * b - (long long)(((long double)a * b + 0.5) / mod) * mod + mod) %            mod;   }   long long qp(long long a, long long b) {     long long c = 1;     for (; b; b >>= 1, a = mul(a, a))       if (b & 1) c = mul(c, a);     return c;   }   long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }   void init() {     for (len = 1; len <= 2 * n; len <<= 1)       ;     lcm = len / gcd(len, n) * n;     mod = lcm + 1;     while (mod < 5000000) mod += lcm;     for (;; mod += lcm) {       long long flag = 0;       for (long long i = 2; i * i <= mod; i++)         if (mod % i == 0) {           flag = 1;           break;         }       if (!flag) break;     }     for (g = 3;; g++) {       long long flag = 0;       for (long long i = 2; i * i <= mod - 1; i++)         if ((mod - 1) % i == 0) {           if (qp(g, i) == 1) {             flag = 1;             break;           }           if (qp(g, (mod - 1) / i) == 1) {             flag = 1;             break;           }         }       if (!flag) break;     }     long long dan = qp(g, (mod - 1) / n);     w[0][0] = w[1][0] = 1;     for (long long i = 1; i < n; i++) w[0][i] = mul(w[0][i - 1], dan);     for (long long i = 1; i < n; i++) w[1][i] = w[0][n - i];     for (long long i = 0; i < len; i++) {       if (i & 1)         rev[i] = (rev[i >> 1] >> 1) | (len >> 1);       else         rev[i] = rev[i >> 1] >> 1;     }   }   void fft(long long *a, long long o) {     for (long long i = 0; i < len; i++)       if (i < rev[i]) swap(a[i], a[rev[i]]);     for (long long k = 2, dan, now, t; k <= len; k <<= 1) {       dan = qp(g, (o ? (mod - 1 - (mod - 1) / k) : (mod - 1) / k));       for (long long i = 0; i < len; i += k) {         now = 1;         for (long long j = 0; j < (k >> 1); j++, now = mul(now, dan)) {           t = mul(a[i + j + (k >> 1)], now);           a[i + j + (k >> 1)] = (a[i + j] - t + mod) % mod;           a[i + j] = (a[i + j] + t) % mod;         }       }     }     if (o) {       long long inv = qp(len, mod - 2);       for (long long i = 0; i < len; i++) a[i] = mul(a[i], inv);     }   }   void init(long long o) {     for (long long i = 0; i < 2 * n; i++) pw[i] = w[o][(i * (i - 1) / 2) % n];     for (long long i = 2 * n; i < len; i++) pw[i] = 0;     reverse(pw, pw + 2 * n);     fft(pw, 0);   }   void dft(long long *a, long long o) {     for (long long i = 0; i < n; i++)       tmp[i] = mul(a[i], w[o][(n - (i * (i - 1) / 2) % n) % n]);     for (long long i = n; i < len; i++) tmp[i] = 0;     fft(tmp, 0);     for (long long i = 0; i < len; i++) tmp[i] = mul(tmp[i], pw[i]);     fft(tmp, 1);     reverse(tmp, tmp + 2 * n);     for (long long i = 0; i < n; i++)       a[i] = mul(tmp[i], w[o][(n - (i * (i - 1) / 2) % n) % n]);     if (o) {       long long inv = qp(n, mod - 2);       for (long long i = 0; i < n; i++) a[i] = mul(a[i], inv);     }   }   long long ans[5], ans_cnt;   signed main() {     scanf( %lld , &n);     init();     for (long long i = 0; i < n; i++) scanf( %lld , &b[i]);     for (long long i = 0; i < n; i++) scanf( %lld , &c[i]);     for (long long i = 0, inv = qp(mod - 2, mod - 2); i < n; i++)       d[i] = mul((c[(i + 1) % n] - c[i] + mod) % mod, inv), e[i] = b[i];     init(0);     dft(d, 0);     reverse(e + 1, e + n);     dft(e, 0);     for (long long i = 0; i < n; i++) f[i] = mul(d[i], qp(e[i], mod - 2));     init(1);     dft(f, 1);     long long x2 = 0, x1 = 0, x0 = -c[0];     for (long long i = 0, now = 0, k; i < n; i++) {       k = b[i] - now;       x2++;       x1 -= 2 * k;       x0 += k * k;       a[i] = ((f[i] < mod - f[i]) ? f[i] : f[i] - mod);       if (a[i] > 1000000) {         puts( 0 );         return 0;       }       now = now + a[i];     }     long long det = x1 * x1 - 4 * x2 * x0, sq = sqrt(det);     if (det < 0 || sq * sq != det) {       puts( 0 );       return 0;     }     if (((-x1 - sq) % (2 * x2)) == 0) ans[++ans_cnt] = (-x1 - sq) / (2 * x2);     if (((-x1 + sq) % (2 * x2)) == 0 && (!ans_cnt || sq))       ans[++ans_cnt] = (-x1 + sq) / (2 * x2);     printf( %lld n , ans_cnt);     if (!ans_cnt) return 0;     for (long long t = 1, now; t <= ans_cnt; t++) {       now = ans[t];       printf( %lld  , now);       for (long long i = 0; i < n - 1; i++) {         now = now + a[i];         printf( %lld  , now);       }       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100 + 10;   const int maxe = maxn * 2;   int fir[maxn];   struct Edge {     int v, c, nxt;     Edge(int v = 0, int c = 0, int nxt = 0) : v(v), c(c), nxt(nxt) {}   } edge[maxe];   int cnt;   bool cir[maxn];   void init() {     memset(fir, -1, sizeof(fir));     cnt = 0;   }   void add_edge(int u, int v, int c) {     edge[cnt] = Edge(v, c, fir[u]);     fir[u] = cnt++;   }   bool dfs(int from, int to, int c) {     cir[from] = true;     if (from == to) return true;     for (int e = fir[from]; e != -1; e = edge[e].nxt)       if (!cir[edge[e].v]) {         if (edge[e].c != c) continue;         if (dfs(edge[e].v, to, c)) {           return true;         }       }     return false;   }   int solve(int from, int to) {     int ans = 0;     bool vis[maxn];     memset(vis, false, sizeof(vis));     for (int e = fir[from]; e != -1; e = edge[e].nxt)       if (!vis[edge[e].c]) {         memset(cir, false, sizeof(cir));         if (dfs(from, to, edge[e].c)) {           ans++;         }         vis[edge[e].c] = true;       }     return ans;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     init();     for (int i = 0; i < m; i++) {       int u, v, c;       scanf( %d%d%d , &u, &v, &c);       add_edge(u, v, c);       add_edge(v, u, c);     }     int q;     scanf( %d , &q);     while (q--) {       int u, v;       scanf( %d%d , &u, &v);       printf( %d n , solve(u, v));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long INF = 1e17;   struct item {     long long t, d, p;   };   long long n, dp[105][2100][2], ans;   item arr[200], arrc[200];   long long solve(long long pos, long long tim) {     if (pos > n) return 0;     if (dp[pos][tim][0]) return max(dp[pos][tim][0], dp[pos][tim][1]);     long long ts = tim + arr[pos].t;     dp[pos][tim][0] = solve(pos + 1, tim);     if (ts < arr[pos].d) dp[pos][tim][1] = solve(pos + 1, ts) + arr[pos].p;     return max(dp[pos][tim][0], dp[pos][tim][1]);   }   bool comp(item l, item r) {     if (l.d == r.d) {       if (l.t == r.t) return l.p > r.p;       return l.t < r.t;     }     return l.d < r.d;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> arr[i].t >> arr[i].d >> arr[i].p;       arrc[i] = {arr[i].t, arr[i].d, arr[i].p};     }     sort(arr + 1, arr + n + 1, comp);     ans = solve(1, 0);     cout << ans << endl;     long long ansar[300], m = 0;     long long tim = 0;     for (int i = 1; i <= n && ans; i++) {       if (dp[i][tim][1] == ans) {         ansar[++m] = i;         tim += arr[i].t;         ans -= arr[i].p;       }     }     cout << m << endl;     for (int i = 1; i <= m; i++) {       long long first = ansar[i];       for (int j = 1; j <= n; j++) {         if (arr[first].t == arrc[j].t && arr[first].d == arrc[j].d &&             arr[first].p == arrc[j].p) {           cout << j <<    ;           arrc[j].t = 1000000000000;           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> ve;   const int MAX = 51;   long long C[MAX][MAX];   void build() {     for (int i = 0; i < MAX; ++i)       for (int j = 0; j < MAX; ++j)         C[i][j] = (j == 0) ? 1 : ((i == 0) ? 0 : C[i - 1][j - 1] + C[i - 1][j]);   }   double memo[MAX][MAX][MAX];   double solve(int i, int last, int mx) {     if (i == m) {       if (last != n) return 0;       return mx;     }     double &ret = memo[i][last][mx];     if (ret == ret) return ret;     ret = 0;     for (int j = 0; j <= n - last; j++) {       ret += C[n - last][j] * 1LL *              solve(i + 1, last + j, max(mx, (j / ve[i]) + (j % ve[i] != 0)));     }     return ret;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     build();     cin >> n >> m;     for (int i = 0; i < m; i++) {       int x;       cin >> x;       ve.push_back(x);     }     memset(memo, -1, sizeof memo);     cout << fixed << setprecision(20) << powl(1.0 / m, n) * solve(0, 0, 0)          << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int s[100005];   int bas[100005];   const int INF = 0x7fffffff;   bool cmp(int a, int b) { return a > b; }   int main() {     int n, m;     while (scanf( %d , &m) != EOF) {       memset(s, 0, sizeof(s));       memset(bas, 0, sizeof(bas));       int i, j;       int minbas = INF;       for (i = 0; i < m; i++) {         scanf( %d , &bas[i]);         if (minbas > bas[i]) minbas = bas[i];       }       scanf( %d , &n);       for (i = 0; i < n; i++) {         scanf( %d , &s[i]);       }       sort(s, s + n, cmp);       int sum = 0;       int tot = 0;       int pan = 0;       for (i = 0; i < n;) {         for (j = 0; j < minbas; j++) {           sum += s[i];           i++;           if (i >= n) {             pan = 1;             break;           }         }         i += 2;       }       printf( %d n , sum);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, arr[55] = {}, sm = 0, dp[55][2] = {};   long long rec(int ind, bool dt) {     if (ind == n - 1) {       if (dt)         return 0;       else         return arr[ind];     }     if (dp[ind][dt] != -1) return dp[ind][dt];     if (dt)       return dp[ind][dt] = min(rec(ind + 1, dt) + arr[ind], rec(ind + 1, !dt));     else       return dp[ind][dt] = max(rec(ind + 1, dt), rec(ind + 1, !dt) + arr[ind]);   }   int main() {     cin >> n;     for (int i = 0; i < 55; i++) {       dp[i][0] = -1;       dp[i][1] = -1;     }     for (int i = 0; i < n; i++) {       cin >> arr[i];       sm += arr[i];     }     long long ans = rec(0, 0);     cout << (sm - ans) <<     << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[251][251][51];   bool check(int n, int ans, int t) {     if (t == 0) {       if (ans == n) return 1;       return 0;     }     bool ret = 0;     if (arr[n][ans + 3][t - 1] == -1)       arr[n][ans + 3][t - 1] = check(n, ans + 3, t - 1);     ret |= arr[n][ans + 3][t - 1];     if (arr[n][ans + 4][t - 1] == -1)       arr[n][ans + 4][t - 1] = check(n, ans + 4, t - 1);     ret |= arr[n][ans + 4][t - 1];     if (arr[n][ans + 5][t - 1] == -1)       arr[n][ans + 5][t - 1] = check(n, ans + 5, t - 1);     ret |= arr[n][ans + 5][t - 1];     return ret;   }   int main() {     for (int i = 0; i < 251; i++)       for (int ii = 0; ii < 251; ii++)         for (int iii = 0; iii < 51; iii++) arr[i][ii][iii] = -1;     int n, k;     cin >> n >> k;     for (int i = 0; i <= n; i++) {       if (check(k - i * 2, 0, n - i)) {         cout << i;         return 0;       }     }     cout << 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 1000010;   struct Point {     long long x, y;     Point() {}     Point(long long x, long long y) : x(x), y(y) {}     bool operator<(const Point &rhs) const {       if (x == rhs.x) return y < rhs.y;       return x < rhs.x;     }   } p[5000];   long long fac[maxn];   long long powmod(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = res * a % mod;       a = a * a % mod;       b >>= 1;     }     return res;   }   long long C(long long n, long long m) {     if (m > n || m < 0) return 0;     long long s1 = fac[n], s2 = fac[m] * fac[n - m] % mod;     return s1 * powmod(s2, mod - 2) % mod;   }   long long dp[maxn];   int n, m, k;   int main() {     fac[0] = 1LL;     for (int i = 1; i < maxn; i++) fac[i] = fac[i - 1] * i % mod;     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= k; i++) {       scanf( %lld%lld , &p[i].x, &p[i].y);       p[i].x--, p[i].y--;     }     p[++k].x = n - 1;     p[k].y = m - 1;     sort(p + 1, p + k + 1);     for (int i = 1; i <= k; i++) {       dp[i] = C(p[i].x + p[i].y, p[i].x);       for (int j = 1; j < i; j++) {         if (p[j].y <= p[i].y) {           dp[i] += (mod - dp[j] * C(p[i].x - p[j].x + p[i].y - p[j].y,                                     p[i].x - p[j].x));           dp[i] %= mod;         }       }     }     printf( %lld n , (dp[k] + mod) % mod);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     cin >> a >> b;     long long int mx = 0;     for (long long int i = 0; i < a.size(); i++) {       long long int g = (a[i] -  0 );       mx = max(mx, g);     }     for (long long int i = 0; i < b.size(); i++) {       long long int g = (b[i] -  0 );       mx = max(mx, g);     }     mx++;     string h =   ;     long long int c = 0, s = 0;     for (long long int i = 0; i < 20; i++) {       if (a.size() < i) a =  0  + a;       if (b.size() < i) b =  0  + b;     }     for (long long int i = 18; i >= 0; i--) {       long long int q = (a[i] -  0 ), w = (b[i] -  0 );       s = (q + w + c) % mx;       char ch = ( 0  + s);       h = ch + h;       c = (q + w + c) / mx;     }     long long int k = 0;     while (h[k] ==  0 ) k++;     cout << 19 - k << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 1e6;   const long long int inf = 1e14;   const long long int mod = 1e9 + 7;   const double PI = acos(-1);   long long int powm(long long int a, long long int b) {     a = a % mod;     long long int res = 1;     while (b) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return res;   }   long long int n, a[N];   long double f(long double xn) {     set<long double> b = {0};     long double su = 0, ans = 0;     long double ma = 0, mi = 0;     for (int i = 0; i < n; i++) {       su += (long double)a[i] - xn;       ans = max({ans, abs(su - mi), abs(su - ma)});       ma = max(ma, su);       mi = min(mi, su);     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     cout << fixed << std::setprecision(10);     while (t--) {       cin >> n;       long double B = -100000;       long double A = 100000;       for (int i = 0; i < n; i++) {         cin >> a[i];         B = max(B, (long double)a[i]);         A = min(A, (long double)a[i]);       }       for (int i = 0; i < 100; i++) {         long double m1 = (A * 2 + B) / 3.0;         long double m2 = (A + 2 * B) / 3.0;         if (f(m1) > f(m2))           A = m1;         else           B = m2;       }       cout << f(A) <<   n ;     }   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const long long mod = 1e9 + 7;   long long a[200010];   int main() {     long long n, k;     cin >> n >> k;     long long i;     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     long long sum = 0;     for (i = 1; i <= n; i++) {       long long temp = min(i, n - i + 1);       temp = min(temp, n - k + 1);       temp = min(temp, k);       sum += temp * a[i];     }     double ans = double(sum) / (n - k + 1);     printf( %.10lf , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     while (cin >> n) {       int m = n % 4;       cout << (m == 0 || m == 3 ? 0 : 1) << endl << n / 2 <<    ;       for (int i = n; i >= 4; i -= 4) cout << i - 1 <<     << i - 2 <<    ;       if (m == 2)         cout <<  1   << endl;       else if (m == 3)         cout <<  3   << endl;       else         cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e3 + 5;   int n, m, k;   struct node {     int x, y, step;   };   char s[maxn][maxn];   bool vis[maxn][maxn][4];   int go[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};   int bfs(int x, int y, int tx, int ty) {     for (int i = 0; i < 4; ++i) vis[x][y][i] = 1;     queue<node> q;     node tmp, tem;     tem.x = x, tem.y = y, tem.step = 0;     q.push(tem);     int xx, yy;     while (!q.empty()) {       tmp = q.front();       q.pop();       if (tmp.x == tx && tmp.y == ty) return tmp.step;       for (int i = 0; i < 4; i++) {         tem = tmp;         tem.step++;         for (int j = 1; j <= k; j++) {           xx = tem.x + go[i][0];           yy = tem.y + go[i][1];           if (xx < 0 || xx > n) break;           if (yy < 0 || yy > m) break;           if (s[xx][yy] !=  . ) break;           if (vis[xx][yy][i]) break;           tem.x = xx;           tem.y = yy;           vis[xx][yy][i] = 1;           q.push(tem);         }       }     }     return -1;   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++) scanf( %s , s[i] + 1);     int x, xx, y, yy;     scanf( %d%d%d%d , &x, &y, &xx, &yy);     printf( %d n , bfs(x, y, xx, yy));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long A[100005];   long long D[100005];   long long qzh[100005];   long long hzh[100005];   long long ans[100005];   long long dp[100005];   int main() {     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) scanf( %lld , &A[i]);     for (int i = 1; i <= n; i++) scanf( %lld , &D[i]);     for (int i = n; i >= 1; i--) {       hzh[i] = A[i] + hzh[i + 1];       dp[i] = max(dp[i + 1], hzh[i] - D[i]);     }     long long MIN = D[1];     for (int i = 1; i <= n; i++) {       MIN = min(MIN, D[i]);       qzh[i] = qzh[i - 1] + A[i];       ans[i] = max(dp[i + 1], qzh[i] - MIN + dp[i + 1]);     }     if (k == 0) {       long long res = 0;       for (int i = 1; i <= n; i++) {         res = max(res, dp[i]);       }       cout << res << endl;     } else if (k == 1) {       long long res = 0;       for (int i = 1; i < n; i++) {         res = max(res, ans[i]);       }       MIN = min(A[n], D[n]);       for (int i = n - 1; i >= 1; i--) {         dp[i] = hzh[i] - D[i];         res = max(res, dp[i] - MIN);         MIN = min(MIN, min(A[i], D[i]));       }       cout << res << endl;     } else {       long long res = 0;       for (int i = 1; i < n; i++) {         res = max(res, qzh[n] - D[i]);       }       res = max(res, A[n] - D[n]);       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 50;   int mod = 1e9 + 7;   long long add(long long a, long long b) {     return (a % mod + b % mod + mod) % mod;   }   long long mul(long long a, long long b) { return (a % mod * (b % mod)) % mod; }   int dp[N][3];   int solve(int rem, int val) {     if (rem == 0) return val == 1;     int &ans = dp[rem][val];     if (~ans) return ans;     ans = solve(rem - 1, val);     ans = add(ans, solve(rem - 1, val * -1));     return ans;   }   int dp2[N][20];   int solve2(int remp, int rem) {     if (remp == 0) return rem == 0;     int &ans = dp2[remp][rem];     if (~ans) return ans;     ans = solve2(remp - 1, rem);     if (rem) ans = add(ans, solve2(remp, rem - 1));     return ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(dp, -1, sizeof(dp));     memset(dp2, -1, sizeof(dp2));     int t;     cin >> t;     while (t--) {       int x, y;       cin >> x >> y;       map<int, int> co;       for (int i = 2; i * i <= x; i++) {         while (x % i == 0) {           x /= i;           co[i]++;         }       }       if (x != 1) co[x]++;       long long ans = solve(y, 1);       for (auto it : co) ans = mul(ans, solve2(y, it.second));       cout << ans <<   n ;     }     return 0;   }


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


#include<cstdio>   #include<iomanip>   #include<iostream>   #include<cstring>   #include<string>   #include<cmath>   #include<map>   #include<algorithm>   #include<vector>   #include<set>   #include<queue>   #include<unordered_map>   #define Quick ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)   #define ll long long   #define P pair<int,int>   #define inf 0x3f3f3f3f   #define endl   n    #define PI acos(-1)   #define mem(a, b) memset(a, b, sizeof a)   using namespace std;   const int N =2007;   const int mod = 1e9 + 7;   ll a[N];   ll dp[N][N];   int main()   {       Quick;          //重新排序使其在每一位上的（max-min）总和最小          int n; cin >> n;       for (int i = 0; i < n; i++)cin >> a[i];       sort(a, a + n);       for (int i = 0; i < n; i++) {           for (int j = 0; j < n; j++) {               dp[i][j] = 1e12;//初始dp数组保留最大值。           }       }       //初始化dp数组。       dp[0][0] = a[n - 1] - a[0];       //减小这个差值，可以删掉一个最小的或者最大的       for (int i = 1; i < n; i++)       {           //只删除最大值i次           dp[i][0] = dp[i - 1][0] + a[n - i - 1] - a[0]; //删除最大值从右边删除，那么删除之后当前最大值就是a[n-i-1];           //只删除最小值i次           dp[0][i] = dp[0][i - 1] + a[n - 1] - a[i];     //删除最小值从左边删除，那么删除之后当前最小值就是a[i]。       }          //接下来开始进行状态转移取最优。       for (int i = 1; i < n; i++) {           for (int j = 1; i + j < n; j++) {               //i+j不得超过n次。               dp[i][j] = min(dp[i][j], dp[i - 1][j] + a[n - i - 1] - a[j]);//选择删除最大值               dp[i][j] = min(dp[i][j], dp[i][j - 1] + a[n - i - 1] - a[j]);//选择删除最小值           }       }       ll res = 1e12;       for (int i = 0; i < n; i++) {           res = min(res, dp[i][n - i - 1]);       }       cout << res << endl;   }


#include<bits/stdc++.h>    using namespace std;   void solve()   {    long long int n,s=0,sum=0,k;    cin>>n;    long long int arr[n+1];    for(int i=1;i<=n;i++)    {    cin>>arr[i];    if(i%2==1)    sum=sum+arr[i];    else    s=s+arr[i];}    if(sum>=s)    {     for(int i=1;i<=n;i++)        {         if(i%2==1)         cout<<arr[i]<<   ;         else         cout<< 1 <<   ;     }    }     else    {     for(int i=1;i<=n;i++)        {         if(i%2==0)         cout<<arr[i]<<   ;         else         cout<< 1 <<   ;     }    }     cout<<endl;   }   int main() {    int t=1;    cin >> t;    while(t--) {     solve();    }   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   struct point {     double x, y;     point() {}     point(double _x, double _y) {       x = _x;       y = _y;     }     point operator+(const point &t) { return point(x + t.x, y + t.y); }     point operator-(const point &t) { return point(x - t.x, y - t.y); }     double dist(const point &t) {       return ((x - t.x) * (x - t.x) + (y - t.y) * (y - t.y));     }   };   struct line {     double a, b, c;     line() {}     line(double _a, double _b, double _c) {       a = _a;       b = _b;       c = _c;     }     void build(const point &p, const point &q) {       a = p.y - q.y;       b = q.x - p.x;       c = -(p.x * (p.y - q.y) + p.y * (q.x - p.x));     }   };   int n, lt, rt;   point p[2000];   double mx = 1e+15, mn = -(1e+15);   bool intersect(const line &a, point &res) {     if (fabs(a.a) <= eps) return false;     res.y = p[0].y;     res.x = (-a.c - (a.b * res.y)) / a.a;     return true;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %lf%lf , &p[i].x, &p[i].y);     p[n] = p[0];     lt = int(min(p[0].x, p[1].x));     rt = int(max(p[0].x, p[1].x));     p[n + 1] = p[1];     for (int i = 1; i < n; i++) {       line l;       l.build(p[i], p[i + 1]);       point res, tt = p[i + 1] - p[i];       if (intersect(l, res)) {         if (tt.y < eps)           mx = min(mx, res.x);         else           mn = max(mn, res.x);       } else if ((p[1].x - p[0].x) * tt.x > eps) {         printf( 0 n );         return 0;       }     }     int x = ceil(mn - eps), y = floor(mx + eps);     printf( %d n , max(0, min(y, rt) - max(x, lt) + 1));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long min(long long a, long long b) { return (a < b) ? a : b; }   int main() {     long long n, m, b_max_1 = 0, b_max_2 = 0, g_min = 1e9;     long long sum_b = 0, sum_g = 0;     cin >> n >> m;     long long b[n], g[m];     for (int i = 0; i < n; ++i) {       cin >> b[i];       sum_b += b[i];       if (b[i] > b_max_1) {         b_max_2 = b_max_1;         b_max_1 = b[i];       } else if (b[i] > b_max_2) {         b_max_2 = b[i];       }     }     sum_b = sum_b * m;     for (int i = 0; i < m; ++i) {       cin >> g[i];       sum_g += g[i];       g_min = min(g_min, g[i]);     }     if (b_max_1 > g_min) {       cout << -1 <<   n ;       return 0;     }     if (g_min > b_max_1)       sum_b = sum_b + sum_g - (m - 1) * b_max_1 - b_max_2;     else       sum_b = sum_b - m * b_max_1 + sum_g;     cout << sum_b <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[200010];   struct seg {     int val, idx;   } tree1[600010], tree2[600010];   void build(int node, int s, int e) {     if (s > e) return;     if (s == e) {       tree1[node].val = a[s];       tree1[node].idx = s;       tree2[node].val = a[s];       tree2[node].idx = s;       return;     }     int mid = (s + e) / 2;     build(2 * node, s, mid);     build(2 * node + 1, mid + 1, e);     if (tree1[2 * node].val > tree1[2 * node + 1].val)       tree1[node].idx = tree1[2 * node + 1].idx;     else       tree1[node].idx = tree1[2 * node].idx;     if (tree2[2 * node].val > tree2[2 * node + 1].val)       tree2[node].idx = tree2[2 * node].idx;     else       tree2[node].idx = tree2[2 * node + 1].idx;     tree1[node].val = min(tree1[2 * node].val, tree1[2 * node + 1].val);     tree2[node].val = max(tree2[2 * node].val, tree2[2 * node + 1].val);   }   seg query1(int node, int s, int end, int l, int r) {     if (s > end || s > r || end < l) {       seg temp;       temp.val = 1000000000;       temp.idx = -1;       return temp;     }     if (s >= l && end <= r) return tree1[node];     seg res1 = query1(2 * node, s, (s + end) / 2, l, r);     seg res2 = query1(2 * node + 1, (s + end) / 2 + 1, end, l, r);     seg res;     if (res1.val < res2.val) {       res.val = res1.val;       res.idx = res1.idx;     } else {       res.val = res2.val;       res.idx = res2.idx;     }     return res;   }   seg query2(int node, int s, int end, int l, int r) {     if (s > end || s > r || end < l) {       seg temp;       temp.val = -1000000000;       temp.idx = -1;       return temp;     }     if (s >= l && end <= r) return tree2[node];     seg res1 = query2(2 * node, s, (s + end) / 2, l, r);     seg res2 = query2(2 * node + 1, (s + end) / 2 + 1, end, l, r);     seg res;     if (res1.val > res2.val) {       res.val = res1.val;       res.idx = res1.idx;     } else {       res.val = res2.val;       res.idx = res2.idx;     }     return res;   }   int main() {     int n;     cin >> n;     int q;     cin >> q;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     build(1, 0, n - 1);     while (q--) {       int l, r, x;       scanf( %d %d %d , &l, &r, &x);       l--;       r--;       seg mx = query1(1, 0, n - 1, l, r);       seg mi = query2(1, 0, n - 1, l, r);       if (mx.val == x && mi.val == x) {         printf( -1 n );       } else if (mx.val == x) {         printf( %d n , mi.idx + 1);       } else         printf( %d n , mx.idx + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18 + 10;   const int inf = 1e9 + 10;   const int N = 1e6 + 10;   vector<int> t[N * 4];   void build(int v, int tl, int tr, vector<int> &a) {     if (tl == tr) {       t[v].push_back(a[tl]);     } else {       int tm = (tl + tr) / 2;       build(v * 2, tl, tm, a);       build(v * 2 + 1, tm + 1, tr, a);       t[v] = t[v * 2];       for (auto i : t[v * 2 + 1]) {         t[v].push_back(i);       }       sort(t[v].begin(), t[v].end());     }   }   int get(int v, int tl, int tr, int l, int r, int x) {     if (l > r) {       return 0;     }     if (tl == l && tr == r) {       int ind = lower_bound(t[v].begin(), t[v].end(), x) - t[v].begin();       if (ind != t[v].size() && t[v][ind] == x) {         return 1;       } else {         return 0;       }     }     int tm = (tl + tr) / 2;     int ql = get(v * 2, tl, tm, l, min(r, tm), x);     int qr = get(v * 2 + 1, tm + 1, r, max(l, tm + 1), r, x);     return (ql + qr);   }   int main() {     cin.tie(0);     ios::sync_with_stdio(0);     int n, k;     cin >> n >> k;     vector<int> a(k), last(n + 1, k);     for (int i = 0; i < k; i++) {       cin >> a[i];       if (last[a[i]] == k) {         last[a[i]] = i;       }     }     build(1, 0, k - 1, a);     int ans = 0;     for (int i = 1; i <= n; i++) {       if (last[i] == k) {         ans++;       }       if (i > 1 && get(1, 0, k - 1, last[i], k - 1, i - 1) == 0) {         ans++;       }       if (i < n && get(1, 0, k - 1, last[i], k - 1, i + 1) == 0) {         ans++;       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool As;   char c;   int n, m, k;   inline void read(int& a) {     a = 0;     do c = getchar();     while (c <  0  || c >  9 );     while (c <=  9  && c >=  0 ) a = (a << 3) + (a << 1) + c -  0 , c = getchar();   }   int Min[1211];   double A[11][11];   bool Has[11][11];   const double eps = 1e-7;   int Matrix(int n) {     int o = 1;     double res = 1;     if (n < 0) return 0;     for (int i = 0; i < n; i++) {       int j = -1;       for (int t = i; t < n; t++)         if (((A[t][i]) > 0 ? (A[t][i]) : -(A[t][i])) > eps) {           j = t;           break;         }       if (j ^ i) o ^= 1;       if (j == -1) return 0;       for (int t = 0; t < n; t++) swap(A[j][t], A[i][t]);       for (int j = i + 1; j < n; j++)         if (((A[j][i]) > 0 ? (A[j][i]) : -(A[j][i])) > eps) {           double U = A[j][i] / A[i][i];           for (int k = 0; k < n; k++) A[j][k] -= U * A[i][k];         }       res *= A[i][i];     }     if (o)       return res + 0.1;     else       return -res + 0.1;   }   int Build(int S) {     vector<int> Q;     Q.clear();     memset(A, 0, sizeof(A));     while (S) Q.push_back(Min[S]), S ^= 1 << Min[S];     for (int i = 0; i < Q.size(); i++)       for (int j = 0; j < i; j++)         if (Has[Q[i]][Q[j]]) A[i][j]--, A[j][i]--, A[j][j]++, A[i][i]++;     return Q.size() - 1;   }   int Cnt[2002];   int Pow(int a, int x) {     int res = 1;     for (x; x; x >>= 1, a = a * a)       if (x & 1) res = res * a;     return res;   }   int F[2002];   int G[2002];   int main() {     Min[0] = -1;     for (int i = 1; i < 1024; i++)       Cnt[i] = (i & 1) ? Cnt[i >> 1] + 1 : Cnt[i >> 1],       Min[i] = (i & 1) ? 0 : (Min[i >> 1] + 1);     read(n), read(m), read(k);     while (m--) {       int a, b;       read(a), read(b);       a--, b--;       Has[b][a] = Has[a][b] = true;     }     int t = 1 << n;     t--;     for (int i = 1; i <= t; i++) {       int W = 1;       for (int j = 0; j < n; j++)         if ((1 << j) & i) {           int f = 0;           for (int k = 0; k < n; k++)             if (!(i & (1 << k)))               if (Has[j][k]) f++;           W *= f;         }       int df;       G[i] = F[i] = W * (df = Matrix(Build(t ^ i)));     }     int Ans = 0;     for (int i = t; ~i; i--) {       if (Cnt[i] == k) Ans += G[i];       int j = (i - 1) & i;       while (j) {         G[j] += (Cnt[j ^ i] & 1 ? -1 : 1) * F[i];         j = i & (j - 1);       }     }     cout << Ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, ans;   float x, dis, t;   struct ponto {     float ini, fim;     bool operator<(const ponto &lhs) const { return lhs.ini > ini; }   } p[1010];   int main() {     scanf( %d%f , &n, &t);     ans = 2;     for (int i = 0; i < n; i++) {       scanf( %f%f , &x, &dis);       dis /= 2.0;       p[i].ini = x - dis;       p[i].fim = x + dis;     }     sort(p, p + n);     for (int i = 1; i < n; i++) {       if (p[i - 1].fim + t < p[i].ini)         ans += 2;       else if (p[i - 1].fim + t == p[i].ini)         ans++;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   long long int inverse(long long int i) {     if (i == 1) return 1;     return (MOD - ((MOD / i) * inverse(MOD % i)) % MOD + MOD) % MOD;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     string s;     cin >> s;     long long x = 0, y = 0, ans = 0, len = 0, last;     for (int i = 0; i < n; i++) {       cin >> s;       if (s[i] ==  U )         y++;       else if (s[i] ==  D )         y--;       else if (s[i] ==  R )         x++;       else         x--;       len++;       if (len > (abs(x) + abs(y))) {         x = 0;         y = 0;         len = 0;         ans++;         i--;         last = i;       }     }     if (last != (n - 1)) ans++;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   using lint = long long;   bool has(int s, int x) {     int i = s / 50 % 475;     for (int ii = (0); ii < int(25); ++ii) {       i = (i * 96 + 42) % 475;       if (i + 26 == x) {         return true;       }     }     return false;   }   void solve(istream& cin, ostream& cout) {     int p, x, y;     cin >> p >> x >> y;     for (int i = 0; x - i * 50 >= y; i++) {       if (has(x - i * 50, p)) {         cout << 0;         return;       }     }     for (int i = 1;; i++) {       if (has(x + i * 100, p) || has(x + i * 100 - 50, p)) {         cout << i;         return;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     solve(cin, cout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct vec {     int to;     int fro;   };   int fa[200010], son[200010][26], mx[200010];   int rt, lst, tot;   int n, m;   char s[200010];   vec mp[200010];   int tai[200010], cnt;   int P[200010];   int ans[200010];   vector<int> qs[200010];   int av[200010];   int len[200010];   int Rt[200010], Son[4000010][2];   int TOT;   inline void be(int x, int y) {     mp[++cnt].to = y;     mp[cnt].fro = tai[x];     tai[x] = cnt;   }   int merge(int x, int y) {     if (!x || !y) {       return x + y;     }     Son[x][0] = merge(Son[x][0], Son[y][0]);     Son[x][1] = merge(Son[x][1], Son[y][1]);     return x;   }   void change(int &x, int y, int z, int p) {     if (!x) {       x = ++TOT;     }     if (y == z) {       return;     }     int mid = y + z >> 1;     if (p <= mid) {       change(Son[x][0], y, mid, p);     } else {       change(Son[x][1], mid + 1, z, p);     }   }   void ins(int x) {     int np = ++tot, p = lst;     mx[np] = mx[p] + 1;     while (p && !son[p][x]) {       son[p][x] = np;       p = fa[p];     }     if (!p) {       fa[np] = rt;     } else {       int q = son[p][x];       if (mx[q] == mx[p] + 1) {         fa[np] = q;       } else {         int nq = ++tot;         mx[nq] = mx[p] + 1;         memcpy(son[nq], son[q], sizeof(son[q]));         fa[nq] = fa[q];         fa[np] = fa[q] = nq;         while (p && son[p][x] == q) {           son[p][x] = nq;           p = fa[p];         }       }     }     lst = np;   }   int L;   int t[200010];   void DFS(int x, int y, int z) {     if (y == z) {       t[++L] = y;       return;     }     int mid = y + z >> 1;     if (Son[x][0]) {       DFS(Son[x][0], y, mid);     }     if (Son[x][1]) {       DFS(Son[x][1], mid + 1, z);     }   }   void dfs(int x) {     int i, y;     for (i = tai[x]; i; i = mp[i].fro) {       y = mp[i].to;       dfs(y);     }     for (i = tai[x]; i; i = mp[i].fro) {       y = mp[i].to;       Rt[x] = merge(Rt[x], Rt[y]);     }     L = 0;     if (qs[x].size()) {       L = 0;       DFS(Rt[x], 1, n);       for (i = 0; i < qs[x].size(); i++) {         int wzh = 1;         int ti = qs[x][i];         int tav = av[qs[x][i]];         if (L < tav) {           ans[ti] = -1;         } else {           ans[ti] = 1000000000;           for (int j = tav; j <= L; j++) {             ans[ti] = min(ans[ti], t[j] - t[j - tav + 1] + len[ti]);           }         }       }     }   }   int main() {     int i, x;     lst = rt = tot = 1;     scanf( %s , s + 1);     n = strlen(s + 1);     int p = rt;     for (i = 1; i <= n; i++) {       ins(s[i] -  a );       p = son[p][s[i] -  a ];       P[i] = p;       change(Rt[p], 1, n, i);     }     for (i = 2; i <= tot; i++) {       be(fa[i], i);     }     scanf( %d , &m);     for (i = 1; i <= m; i++) {       scanf( %d%s , &av[i], s + 1);       int p = rt;       for (int j = 1; s[j]; j++) {         p = son[p][s[j] -  a ];       }       len[i] = strlen(s + 1);       if (!p) {         ans[i] = -1;       } else {         qs[p].push_back(i);       }     }     dfs(1);     for (i = 1; i <= m; i++) {       printf( %d n , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool iguales(vector<string>& x, vector<string>& y) {     for (int i = (int)0; i < (int)x.size(); i++) {       if (x[i] ==  T  || y[i] ==  T ) continue;       if (!(x[i] == y[i])) return false;     }     return true;   }   int main() {     map<string, vector<vector<string> > > mapa;     map<string, string> peso;     int n, m, k;     scanf( %d n , &n);     string linea, nom, alfa, beta;     while (n--) {       getline(cin, linea);       for (int i = (int)0; i < (int)linea.size(); i++)         if (linea[i] ==  (  || linea[i] ==  )  || linea[i] ==  , ) linea[i] =    ;       vector<string> x;       stringstream flujo(linea);       while (flujo >> linea) x.push_back(linea);       nom = x[1];       x.erase(x.begin());       x.erase(x.begin());       mapa[nom].push_back(x);     }     cin >> m;     while (m--) {       cin >> alfa >> beta;       peso[beta] = alfa;     }     scanf( %d n , &k);     while (k--) {       getline(cin, linea);       for (int i = (int)0; i < (int)linea.size(); i++)         if (linea[i] ==  (  || linea[i] ==  )  || linea[i] ==  , ) linea[i] =    ;       vector<string> x;       stringstream flujo(linea);       int cc = 0;       while (flujo >> linea) {         if (cc == 0) {           nom = linea;           cc = 1;         } else           x.push_back(peso[linea]);       }       map<string, vector<vector<string> > >::iterator iter;       iter = mapa.find(nom);       if (iter != mapa.end()) {         vector<vector<string> > r = iter->second;         int tot = 0;         for (int i = (int)0; i < (int)r.size(); i++) {           vector<string> second = r[i];           if (x.size() == second.size()) {             if (iguales(x, second)) tot++;           }         }         cout << tot << endl;       } else         cout << 0 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   int n, k;   int a[200];   int main() {     ios::sync_with_stdio(false);     cin >> n >> k;     int e = 0, s = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] == 1)         e++;       else         s++;     }     int ee = e, ss = s;     int ans = -1;     for (int b = 1; b <= k; b++) {       ee = e;       ss = s;       for (int i = 0; b + i * k <= n; i++) {         int c = b + i * k;         if (a[c] == 1)           ee--;         else           ss--;       }       ans = max(ans, abs(ee - ss));     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, c;     cin >> n >> k >> c;     int p = ((n * k * c) / 100);     int k1 = p / k;     int k2 = p % k;     for (int i = 0; i < n; i++) {       if (i != 0) cout <<    ;       if (i < k1)         cout << k;       else if (i == k1)         cout << k2;       else         cout << 0;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   int a[100005], b[100005];   bool compare(int c, int d) { return a[c - 1] < a[d - 1]; }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       b[i] = i + 1;     }     sort(b, b + n, compare);     cout << (n + 1) / 2 << endl;     for (int i = 0; i < n; i += 2) cout << b[i] <<    ;     cout << endl << n / 2 << endl;     for (int i = 1; i < n; i += 2) cout << b[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxN = 2e5 + 10;   const long long maxB = 500;   const long long INF = 4557430888798830399;   const int INF_I = 2139062143;   const long long maxA = 1e6 + 10;   const long long MOD = 1e9 + 7;   const long long mINF = -4557430888798830400;   const int mINF_I = -2139062144;   template <typename T>   T binaryExpo(T n, T p) {     if (p == 0) {       return 1LL;     }     if (p & 1) {       return n * binaryExpo(n, p - 1);     }     T ret = binaryExpo(n, p / 2);     return ret * ret;   }   template <typename T>   T bigMod(T n, T p, T m) {     if (p == 0) {       return 1LL % m;     }     if (p & 1) {       return (n % m * bigMod(n, p - 1, m)) % m;     }     T ret = bigMod(n, p / 2, m) % m;     return (ret * ret) % m;   }   template <typename T>   T modInv(T n, T m) {     return bigMod(n, m - 2, m);   }   bool FILE_PRINT = 0;   int marked[+2];   vector<long long> prime;   void sieve(long long n);   bool is_prime(long long num);   int arr[maxN + 10], ans[maxN + 10], idx[maxN + 10];   long long cum[maxN + 10];   pair<int, int> query[maxN + 10];   vector<int> divisors[maxN + 10];   long long spd[maxA + 10];   long long mp[maxN + 10];   void calc_spd(long long n) {     memset(spd, -1, sizeof spd);     for (long long i = 2; i <= n; i++) {       if (spd[i] == -1) {         prime.push_back(i);         mp[prime.size() - 1] = ((i - 1) * modInv(i, MOD)) % MOD;         for (long long j = i; j <= n; j += i) {           if (spd[j] == -1) spd[j] = prime.size() - 1;         }       }     }   }   inline bool compare(long long x, long long y) {     return make_pair(query[x].first / maxB, query[x].second) <            make_pair(query[y].first / maxB, query[y].second);   }   signed cnt[maxN + 10];   void solve(long long n, long long q) {     long long a, b = -1, l, r, ans = 1;     for (long long curr_block = -1, i = 0; i < q; i++) {       tie(l, r) = query[idx[i]];       if (l / maxB != curr_block) {         curr_block = l / maxB;         ans = 1;         memset(cnt, 0, sizeof cnt);         b = (curr_block + 1) * maxB - 1;       }       while (b + 1 <= r) {         b++;         for (auto p : divisors[b]) {           if (cnt[p] == 0) ans = (ans * mp[p]) % MOD;           cnt[p]++;         }       }       long long temp = ans;       for (a = l; a <= min(r, (curr_block + 1) * maxB - 1); a++) {         for (auto p : divisors[a]) {           if (cnt[p] == 0) ans = (ans * mp[p]) % MOD;           cnt[p]++;         }       }       if (ans < 0) ans += MOD;       ::ans[idx[i]] = (::ans[idx[i]] * ans) % MOD;       for (a = l; a <= min(r, (curr_block + 1) * maxB - 1); a++) {         for (auto p : divisors[a]) {           cnt[p]--;         }       }       ans = temp;     }   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout.precision(15);     cout << fixed;     calc_spd(maxA + 5);     long long number_of_test_cases = 1, test_case;     for (test_case = 1; test_case <= number_of_test_cases; test_case++) {       long long i, j, k, l, r, m, n, query_type, q;       long long a, b, c, x, y, z;       cin >> n;       for (i = (0); i < (n); ++i) {         cin >> arr[i];         x = arr[i];         while (x > 1) {           long long p = spd[x];           while (x % prime[p] == 0) {             x /= prime[p];           }           divisors[i].push_back(p);         }       }       cum[0] = arr[0];       for (i = (1); i <= (n - 1); ++i) {         cum[i] = (cum[i - 1] * arr[i]) % MOD;       }       cin >> q;       for (i = (0); i < (q); ++i) {         cin >> l >> r;         l--;         r--;         query[i] = make_pair(l, r);         ans[i] = cum[r];         if (l > 0) ans[i] = (ans[i] * modInv((long long)cum[l - 1], MOD)) % MOD;       }       for (i = (0); i < (q); ++i) idx[i] = i;       sort(idx, idx + q, compare);       solve(n, q);       for (i = (0); i < (q); ++i) cout << ans[i] <<   n ;     }     return 0;   }   bool is_prime(long long num) {     return (num > 1 &&             (num == 2 || ((((num)&1LL) ? (1) : (0)) &&                           !(marked[(num) >> 6] & (1L << (((num) % 64) >> 1))))));   }   void sieve(long long n) {     long long i, j;     (marked[(1) >> 6] |= (1L << (((1) % 64) >> 1)));     for (i = 3; i * i <= n; i += 2) {       if (!(marked[(i) >> 6] & (1L << (((i) % 64) >> 1)))) {         for (j = i * i; j <= n; j += i + i)           (marked[(j) >> 6] |= (1L << (((j) % 64) >> 1)));       }     }     prime.clear();     prime.push_back(2);     for (i = 3; i <= n; i += 2) {       if (is_prime(i)) prime.push_back(i);     }   }


#include <bits/stdc++.h>   using namespace std;   const long long int INF = 1e9 + 7;   long long int gcd(long long int a, long long int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long int lcm(long long int a, long long int b) {     return (a / gcd(a, b)) * b;   }   long long int sq(long long int x) { return x * x; }   void solve() {     long long int n, x1, x2, y1, y2;     cin >> n >> x1 >> y1 >> x2 >> y2;     long long int ans = 8e18;     vector<pair<long long int, long long int>> v(n);     for (long long int i = 0; i < n; i++) {       long long int x, y;       cin >> x >> y;       v[i].first = sq(x - x1) + sq(y - y1);       v[i].second = sq(x - x2) + sq(y - y2);     }     v.push_back({0, 0});     for (auto i : v) {       long long int r1 = i.first;       long long int r2 = 0;       for (auto j : v) {         if (j.first > r1) {           r2 = max(r2, j.second);         }       }       ans = min(ans, r1 + r2);     }     cout << ans;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int x1, x2, a, b;   int main() {     while (cin >> x1 >> x2 >> a >> b) {       bool ch = false;       if (x1 > x2) {         swap(x1, x2);         swap(a, b);         a = -a;         b = -b;         ch = true;       }       int dif = abs(x1 - x2);       if (a <= 0) {         if (dif <= b)           cout <<  FIRST  << endl << (ch ? x1 : x2) << endl;         else           cout <<  DRAW  << endl;       } else {         int rem = dif % (a + b);         if (rem == 0)           cout <<  SECOND  << endl;         else if (rem >= a && rem <= b)           cout <<  FIRST  << endl << (ch ? x2 - rem : x1 + rem) << endl;         else           cout <<  DRAW  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     map<int, int> pmax, maxp;     vector<int> g[n + 2];     for (int i = 0; i < n; i++) {       int a, b;       cin >> a >> b;       g[a].push_back(b);       if (pmax.find(a) == pmax.end())         pmax[a] = b;       else         pmax[a] = max(pmax[a], b);     }     for (auto i = pmax.begin(); i != pmax.end(); i++) {       maxp[i->second] = i->first;     }     int q;     cin >> q;     while (q--) {       int k;       cin >> k;       vector<pair<int, int> > maxpaux;       for (int i = 0; i < k; i++) {         int l;         cin >> l;         if (pmax.find(l) == pmax.end()) continue;         maxpaux.push_back(pair<int, int>(pmax[l], l));         maxp.erase(pmax[l]);       }       if (maxp.empty()) {         cout << 0 <<     << 0 <<   n ;       } else if (maxp.size() == 1) {         cout << maxp.begin()->second <<     << g[maxp.begin()->second][0] <<   n ;       } else {         auto en = maxp.end();         en--;         int personmax = en->second;         cout << personmax <<    ;         en--;         int secondperson = en->second;         int pos = upper_bound(g[personmax].begin(), g[personmax].end(),                               pmax[secondperson]) -                   g[personmax].begin();         int answer = g[personmax][pos];         cout << answer <<   n ;       }       for (int i = 0; i < maxpaux.size(); i++) {         maxp[maxpaux[i].first] = maxpaux[i].second;       }     }     return 0;   }


#include <bits/stdc++.h>   int gcd(int x, int y) {     int r1 = x, q, r2 = y, r;     while (r2 > 0) {       q = r1 / r2;       r = r1 - q * r2;       r1 = r2;       r2 = r;     }     return r1;   }   using namespace std;   int main(int argc, char const *argv[]) {     int n, m, x, cnt;     char c;     cin >> n >> m;     char arr[n];     int arr1[n];     map<int, pair<int, int> > arr2;     cnt = 0;     cin >> arr;     arr1[0] = -1;     for (int i = 1; i < n; i++) {       arr1[i] = -1;       if (arr[i] ==  .  && arr[i - 1] ==  . ) {         arr2[cnt] = make_pair(i, i - 1);         arr1[i] = cnt;         cnt++;       }     }     for (int i = 0; i < m; i++) {       cin >> x >> c;       x--;       if (arr[x] ==  .  && c ==  .  || arr[x] !=  .  && c !=  . )         ;       else if (arr[x] !=  .  && c ==  . ) {         if (x != 0 && arr[x - 1] ==  . ) {           arr2[cnt] = make_pair(x, x - 1);           arr1[x] = cnt;           cnt++;         }         if (x != n - 1 && arr[x + 1] ==  . ) {           arr2[cnt] = make_pair(x + 1, x);           arr1[x + 1] = cnt;           cnt++;         }       } else {         if (x == n - 1) {           if (arr1[x] == -1)             ;           else {             arr2.erase(arr2.find(arr1[x]));             arr1[x] = -1;           }         } else {           if (arr1[x] != -1 && arr1[x + 1] != -1) {             arr2.erase(arr2.find(arr1[x + 1]));             arr1[x + 1] = -1;             arr2.erase(arr2.find(arr1[x]));             arr1[x] = -1;           } else if (arr1[x] != -1) {             arr2.erase(arr2.find(arr1[x]));             arr1[x] = -1;           } else if (arr1[x + 1] != -1) {             arr2.erase(arr2.find(arr1[x + 1]));             arr1[x + 1] = -1;           } else {           }         }       }       arr[x] = c;       printf( %d , arr2.size());       printf(  n );       ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     const int N = 26;     int mas[26];     for (int i = 0; i < N; ++i) mas[i] = 0;     int rez = 0;     for (int i = 0; i < n * 2 - 2; ++i) {       char a;       cin >> a;       if (isupper(a)) {         if (mas[tolower(a) -  a ] > 0)           mas[tolower(a) -  a ]--;         else           rez++;       } else         mas[a -  a ]++;     }     cout << rez << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[505];   pair<int, int> query(set<int> s) {     cout <<  ?  ;     for (auto e : s) {       cout << e <<    ;     }     cout << endl;     pair<int, int> res;     cin >> res.first >> res.second;     a[res.first] = res.second;     return res;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, k;     cin >> n >> k;     set<int> s;     for (int i = 1; i <= k; i++) {       s.insert(i);     }     int mn = 1e9 + 1;     for (int i = k + 1; i <= n; i++) {       pair<int, int> u = query(s);       mn = min(mn, u.second);       s.erase(u.first);       s.insert(i);     }     pair<int, int> u = query(s);     mn = min(mn, u.second);     s.erase(u.first);     int ans = 1;     set<int> t;     int sm = 1e9 + 1, bg = 0;     for (int i = 1; i <= n; i++) {       if (a[i] != 0) {         t.insert(i);         sm = min(sm, a[i]);         bg = max(bg, a[i]);       }       if (t.size() == 2) break;     }     set<int> ss;     for (auto e : s) ss.insert(e);     for (auto e : t) ss.insert(e);     for (auto e : s) {       ss.erase(e);       auto u = query(ss);       if (u.second == bg) ans++;       ss.insert(e);     }     cout <<  !   << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int main() {     string s;     cin >> s;     string a =   ;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  a  || s[i] ==  b ) a += s[i];     }     int ans = 1, cnt = 0;     for (int i = 0; i < a.size(); i++) {       if (a[i] ==  b ) {         ans = (ans * 1ll * (cnt + 1)) % MOD;         cnt = 0;       } else {         cnt++;       }     }     ans = (ans * 1ll * (cnt + 1)) % MOD;     printf( %d n , ans - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long ans = 0;   int r = -1;   int n, g[40][21], p[40][21];   char ch;   void update(unsigned long long &a, int &b, int &c, unsigned long long d,               int e) {     if (b == 0 || a < d) {       a = d;       c = e;       b = 1;     }   }   unsigned long long f[40][21], bas[21], a[1010];   int main() {     bas[1] = 1;     for (int i = 2; i <= 19; i++) bas[i] = bas[i - 1] * 10LL;     scanf( %d , &n);     for (int i = 1; i <= n + n; i++) {       scanf(  %c , &ch);       a[i] = ch -  0 ;     }     g[0][0] = 1;     f[0][0] = 0;     for (int i = 1; i <= n + n; i++)       for (int j = 0; j <= n; j++)         if (g[i - 1][j]) {           int d1 = j, d2 = i - 1 - j;           d1 = n - d1, d2 = n - d2;           if (d2 > 0)             update(f[i][j], g[i][j], p[i][j], f[i - 1][j] + bas[d2] * a[i], j);           if (j != n)             update(f[i][j + 1], g[i][j + 1], p[i][j + 1],                    f[i - 1][j] + bas[d1] * a[i], j);         }     int sx = n + n, sy = n;     string a =   ;     while (sx != 0) {       int ty = p[sx][sy];       sx--;       if (ty == sy)         a +=  M ;       else         a +=  H ;       sy = ty;     }     reverse(a.begin(), a.end());     cout << a << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n < 3)       cout << -1;     else       for (int i = n; i > 0; --i) {         cout << i <<    ;       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct pony {     long long s, m, r, t;   } ponys[100005];   bool cmp(pony &x, pony &y) { return x.t < y.t; }   struct node {     long long l, r, latest;     long long *sm, *sr, *t;   } nodes[100005 << 4];   void build(long long ord, long long l, long long r) {     nodes[ord].latest = 0;     nodes[ord].l = l, nodes[ord].r = r;     if (l == r) {       nodes[ord].sm = &ponys[l].m;       nodes[ord].sr = &ponys[l].r;       nodes[ord].t = &ponys[l].t;       return;     }     int m = (l + r) >> 1;     build(ord << 1, l, m);     build(ord << 1 | 1, m + 1, r);     pony *tmp = new pony[r - l + 1];     for (int i = 0; i < r - l + 1; i++) tmp[i] = ponys[l + i];     sort(tmp, tmp + r - l + 1, cmp);     nodes[ord].sm = new long long[r - l + 2];     nodes[ord].sr = new long long[r - l + 2];     nodes[ord].t = new long long[r - l + 2];     nodes[ord].sm[0] = nodes[ord].sr[0] = nodes[ord].t[0] = 0;     for (int i = 1; i < r - l + 2; i++) {       nodes[ord].sm[i] = tmp[i - 1].m + nodes[ord].sm[i - 1];       nodes[ord].sr[i] = tmp[i - 1].r + nodes[ord].sr[i - 1];       nodes[ord].t[i] = tmp[i - 1].t;     }     delete[] tmp;   }   long long mana_obserbed(long long ord, long long t, long long l, long long r) {     long long res = 0;     if (nodes[ord].latest > 0)       nodes[ord << 1].latest = nodes[ord << 1 | 1].latest = nodes[ord].latest;     if (nodes[ord].l == l && nodes[ord].r == r) {       if (nodes[ord].latest > 0) {         if (l == r)           res = min(ponys[l].m, ponys[l].r * (t - nodes[ord].latest));         else {           int len = nodes[ord].r - nodes[ord].l + 2;           int tmp = upper_bound(nodes[ord].t + 1, nodes[ord].t + len,                                 t - nodes[ord].latest) -                     nodes[ord].t;           res = nodes[ord].sm[tmp - 1] +                 (nodes[ord].sr[len - 1] - nodes[ord].sr[tmp - 1]) *                     (t - nodes[ord].latest);         }         nodes[ord].latest = t;         return res;       } else if (nodes[ord].latest == 0 && l == r) {         res = min(ponys[l].m, ponys[l].s + ponys[l].r * t);         nodes[ord].latest = t;         return res;       }     }     int m = (nodes[ord].l + nodes[ord].r) >> 1;     if (r <= m)       res += mana_obserbed(ord << 1, t, l, r);     else if (m < l)       res += mana_obserbed(ord << 1 | 1, t, l, r);     else       res += mana_obserbed(ord << 1, t, l, m) +              mana_obserbed(ord << 1 | 1, t, m + 1, r);     nodes[ord].latest = nodes[ord << 1].latest == nodes[ord << 1 | 1].latest                             ? nodes[ord << 1].latest                             : -1;     return res;   }   int main() {     long long n, m, t, l, r;     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> ponys[i].s >> ponys[i].m >> ponys[i].r;       if (ponys[i].r)         ponys[i].t = (ponys[i].m + ponys[i].r - 1) / ponys[i].r;       else         ponys[i].t = 0x7fffffffffffffff;     }     build(1, 1, n);     cin >> m;     for (long long i = 1; i <= m; i++) {       cin >> t >> l >> r;       cout << mana_obserbed(1, t, l, r) << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using std::bitset;   using namespace std;   struct point {     long long x, y;     bool operator<(const point &I) const {       return x < I.x || (x == I.x && y < I.y);     }   } a[101000];   long long n;   long long hmi[101000], tmi[101000], hma[101000], tma[101000];   long long judge(double r) {     long long i, j, tem;     long long mmi, mma;     j = 1;     for (i = 1; i <= n; i++) {       while (j <= n && a[j].x - a[i].x <= 2 * r) j++;       mmi = min(hmi[i - 1], tmi[j]);       mma = max(hma[i - 1], tma[j]);       if (mma - mmi <= 2 * r) return 1;     }     return 0;   }   int main() {     long long i, j, tem;     long long tx, ty;     while (scanf( %I64d , &n) != EOF) {       for (i = 1; i <= n; i++) {         scanf( %I64d%I64d , &tx, &ty);         a[i].x = tx - ty;         a[i].y = tx + ty;       }       sort(a + 1, a + 1 + n);       hmi[0] = 0x3f3f3f3f3f3f3f3fll;       hma[0] = -0x3f3f3f3f3f3f3f3fll;       for (i = 1; i <= n; i++) {         hmi[i] = min(hmi[i - 1], a[i].y);         hma[i] = max(hma[i - 1], a[i].y);       }       tmi[n + 1] = 0x3f3f3f3f3f3f3f3fll;       tma[n + 1] = -0x3f3f3f3f3f3f3f3fll;       for (i = n; i > 0; i--) {         tmi[i] = min(tmi[i + 1], a[i].y);         tma[i] = max(tma[i + 1], a[i].y);       }       double low, high, mid, ans = 0;       low = 0;       high = 1e20;       while (high - low > 1e-6) {         mid = (low + high) / 2;         if (judge(mid))           high = mid;         else           low = mid;       }       printf( %.6lf n , (low + high) / 2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = 3.1415926535897932384626433832795;   const int inf = 1e9;   const long long inf2 = 1e18;   const int mod = 1e9 + 7;   void boost() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   inline long long exp(long long x, long long n, long long m = mod) {     long long r = 1;     while (n) {       if (n & 1) r = r * x % m;       x = x * x % m, n >>= 1;     }     return r;   }   void solve() {     int n, k;     cin >> n >> k;     vector<int> ncr(n + 1, 0);     vector<int> arr(n + 1);     for (int i = 1; i < n + 1; ++i) cin >> arr[i];     ncr[0] = 1;     for (int i = 1; i < n + 1; ++i) {       ncr[i] = (ncr[i - 1] * 1LL * (k + i - 1)) % mod;       ncr[i] = (ncr[i] * exp(i, mod - 2)) % mod;     }     vector<int> ans(n + 1, 0);     for (int i = 1; i < n + 1; ++i) {       for (int j = i; j < n + 1; ++j) {         ans[j] = (ans[j] * 1LL + 1LL * arr[i] * ncr[j - i]) % mod;       }     }     for (int i = 1; i < n + 1; ++i) cout << ans[i] <<    ;     return;   }   int main() {     boost();     int tc = 1;     while (tc--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a1[3], a2[3], i;     cin >> a1[0] >> a1[1] >> a1[2];     cin >> a2[0] >> a2[1] >> a2[2];     for (i = 0; i < 3; i++) {       if (a1[i] == a2[i]) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int n, k, cal;   string solve() {     for (int i = 0; i < s.size(); i++) {       int m4x = min(s[i] + k, (int) z );       int m1n = max(s[i] - k, (int) a );       if (s[i] - m1n >= m4x - s[i]) {         k -= s[i] - m1n;         s[i] = m1n;       } else {         k -= m4x - s[i];         s[i] = m4x;       }     }     if (k == 0) return s;     return  -1 ;   }   int main() {     cin >> n >> k >> s;     cout << solve();   }


#include <bits/stdc++.h>   using namespace std;   template <class Flow = long long, class Cost = long long>   struct MinCostFlow {     const Flow INF_FLOW = 1000111000;     const Cost INF_COST = 1000111000111000LL;     long long n, t, S, T;     Flow totalFlow;     Cost totalCost;     vector<long long> last, visited;     vector<Cost> dis;     struct Edge {       long long to;       Flow cap;       Cost cost;       long long ackjalscjaowjico;       Edge(long long to, Flow cap, Cost cost, long long ackjalscjaowjico)           : to(to), cap(cap), cost(cost), ackjalscjaowjico(ackjalscjaowjico) {}     };     vector<Edge> edges;     MinCostFlow(long long n)         : n(n),           t(0),           totalFlow(0),           totalCost(0),           last(n, -1),           visited(n, 0),           dis(n, 0) {       edges.clear();     }     long long addEdge(long long from, long long to, Flow cap, Cost cost) {       edges.push_back(Edge(to, cap, cost, last[from]));       last[from] = t++;       edges.push_back(Edge(from, 0, -cost, last[to]));       last[to] = t++;       return t - 2;     }     pair<Flow, Cost> minCostFlow(long long _S, long long _T) {       S = _S;       T = _T;       SPFA();       while (1) {         while (1) {           for (long long i = 0, _i = (n); i < _i; ++i) visited[i] = 0;           if (!findFlow(S, INF_FLOW)) break;         }         if (!modifyLabel()) break;       }       return make_pair(totalFlow, totalCost);     }       private:     void SPFA() {       for (long long i = 0, _i = (n); i < _i; ++i) dis[i] = INF_COST;       priority_queue<pair<Cost, long long> > Q;       Q.push(make_pair(dis[S] = 0, S));       while (!Q.empty()) {         long long x = Q.top().second;         Cost d = -Q.top().first;         Q.pop();         if (dis[x] != d) continue;         for (long long it = last[x]; it >= 0; it = edges[it].ackjalscjaowjico)           if (edges[it].cap > 0 && dis[edges[it].to] > d + edges[it].cost)             Q.push(make_pair(-(dis[edges[it].to] = d + edges[it].cost),                              edges[it].to));       }       Cost disT = dis[T];       for (long long i = 0, _i = (n); i < _i; ++i) dis[i] = disT - dis[i];     }     Flow findFlow(long long x, Flow flow) {       if (x == T) {         totalCost += dis[S] * flow;         totalFlow += flow;         return flow;       }       visited[x] = 1;       Flow now = flow;       for (long long it = last[x]; it >= 0; it = edges[it].ackjalscjaowjico)         if (edges[it].cap && !visited[edges[it].to] &&             dis[edges[it].to] + edges[it].cost == dis[x]) {           Flow tmp = findFlow(edges[it].to, min(now, edges[it].cap));           edges[it].cap -= tmp;           edges[it ^ 1].cap += tmp;           now -= tmp;           if (!now) break;         }       return flow - now;     }     bool modifyLabel() {       Cost d = INF_COST;       for (long long i = 0, _i = (n); i < _i; ++i)         if (visited[i])           for (long long it = last[i]; it >= 0; it = edges[it].ackjalscjaowjico)             if (edges[it].cap && !visited[edges[it].to])               d = min(d, dis[edges[it].to] + edges[it].cost - dis[i]);       if (d == INF_COST) return false;       for (long long i = 0, _i = (n); i < _i; ++i)         if (visited[i]) dis[i] += d;       return true;     }   };   signed main() {     long long n;     cin >> n;     string s;     cin >> s;     s =     + s;     MinCostFlow<long long, long long> mcmf(n + 2);     long long m;     cin >> m;     while (m--) {       string t;       long long cost;       cin >> t >> cost;       for (long long i = 1; i + t.size() <= s.size(); i++) {         if (s.substr(i, t.size()) == t) mcmf.addEdge(i, i + t.size(), 1, -cost);       }     }     long long x;     cin >> x;     for (long long i = 0; i <= n; i++) {       mcmf.addEdge(i, i + 1, x, 0);     }     auto ans = mcmf.minCostFlow(0, n + 1);     cout << -ans.second;   }


#include <bits/stdc++.h>   using namespace std;   long long i, j, x, y, curr, T, t, K, N, coun[51], fact[21], rev[51];   vector<int> ans, v;   set<int> cand;   set<int>::iterator it;   void precomp() {     fact[0] = 1;     for (i = 1; i < 21; i++) {       fact[i] = fact[i - 1] * i;     }     coun[0] = coun[1] = 1;     for (i = 2; i < 23; i++) {       coun[i] = fact[i - 2] + coun[i - 1];       for (j = 2; j < i; j++) {         coun[i] += (fact[j - 2] * coun[i - j]);       }     }     for (i = 23; i < 51; i++) coun[i] = coun[22];   }   void fillv(long long n, long long k) {     v.clear();     if (n < 3) {       for (i = n; i > 0; i--) v.push_back(i);       return;     }     cand.clear();     for (i = 1; i < n; i++) {       cand.insert((int)i);       rev[i] = 0;     }     v.push_back(n);     rev[n] = 1;     for (i = 1; i < (n - 1); i++) {       for (j = i + 1; rev[j] > 0; j = rev[j])         ;       x = cand.size();       for (it = cand.begin(), y = 0; y < (k / fact[x - 2]); y++, ++it) {         if (j == (*it)) ++it;       }       if (j == (*it)) ++it;       v.push_back(*it);       rev[*it] = v.size();       cand.erase(it);       k = k % fact[x - 2];     }     v.push_back(*cand.begin());   }   void fill(long long n, long long k) {     int i;     if (n == 0) return;     if (coun[n - 1] > k) {       ans.push_back(ans.size() + 1);       fill(n - 1, k);       return;     }     k -= coun[n - 1];     for (i = 2; i < n; i++) {       j = fact[i - 2] * coun[n - i];       if (j <= k) {         k -= j;         continue;       }       break;     }     fillv(i, k / coun[n - i]);     k = k % (coun[n - i]);     n -= i;     int x = ans.size();     for (j = 0; j < i; j++) {       ans.push_back(x + v[j]);     }     fill(n, k);   }   int main() {     precomp();     cin >> T;     for (t = 0; t < T; t++) {       cin >> N >> K;       if (K > coun[N]) {         cout <<  -1 n ;         continue;       }       ans.clear();       fill(N, K - 1);       for (i = 0; i < N; i++) {         cout << ans[i] <<    ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     deque<int> dq;     int n;     cin >> n;     int f = 0, a = 0, b = 0;     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       dq.push_back(x);     }     while (!dq.empty()) {       int ans = max(dq.front(), dq.back());       if (f == 0) {         a += ans;         f = 1;         if (ans == dq.front())           dq.pop_front();         else           dq.pop_back();       } else {         b += ans;         f = 0;         if (ans == dq.front())           dq.pop_front();         else           dq.pop_back();       }     }     cout << a <<     << b;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100001;   int q, n;   int d[MAXN], p[MAXN];   int main() {     cin >> q;     int small = 1 << 30;     for (int i = 0; i < q; ++i) {       cin >> d[i];       small = ((small) > (d[i]) ? (d[i]) : (small));     }     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> p[i];     }     sort(p, p + n, greater<int>());     int cost = 0;     for (int i = 0; i < n; i++) {       if (i % (small + 2) < small) {         cost += p[i];       }     }     cout << cost << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     long long ans = 0;     for (int i = (0); i < (n); ++i) {       long long t, T, x, cost;       cin >> t >> T >> x >> cost;       if (t >= T) {         ans += cost + m * x;         continue;       }       long long aux1 = cost;       if (m > (T - t)) aux1 += m * x;       long long aux2 = (long long)ceil((double)(m - (T - t)) / (T - t)) + 1;       aux2 *= cost;       ans += min(aux1, aux2);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   void file() {}   void fast() {     std::ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);   }   int main() {     int x;     cin >> x;     int a[1003][3];     int ans = 0;     for (int i = 0; i < (int)x; i++)       for (int t = 0; t < (int)3; t++) {         cin >> a[i][t];         if (t) a[i][t] += a[i][t - 1];         if (t == 2) ans += a[i][t] >= 2;       }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> mp;   int a[300000];   int n, k;   int b[300000];   int cnt = 0;   int cmp(int a, int b) { return mp[a] > mp[b]; }   bool check(int mid) {     int sum = 0;     for (int i = 1; i <= cnt; i++) {       sum += mp[b[i]] / mid;     }     return sum >= k;   }   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + 1 + n);     for (int i = 1; i <= n; i++) {       if (!mp[a[i]]) b[++cnt] = a[i];       mp[a[i]]++;     }     int l = 1;     int r = 250000;     int ans;     while (l <= r) {       int mid = l + r >> 1;       if (check(mid))         ans = mid, l = mid + 1;       else         r = mid - 1;     }     int nd = k;     int now = 1;     sort(b + 1, b + 1 + cnt);     while (nd) {       while (nd && mp[b[now]] >= ans)         cout << b[now] <<    , mp[b[now]] -= ans, nd--;       now++;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int x, y, a, b;       cin >> x >> y >> a >> b;       if ((y - x) % (a + b) == 0) {         cout << (y - x) / (a + b) <<   n ;       } else {         cout << -1 <<   n ;       }     }   }


#include <bits/stdc++.h>   long long a[100000], b[100000];   using namespace std;   bool isnp(long long n, long long k, long long t) {     long long magic = 0;     for (long long i = 0; i < t; i++) {       if (a[i] * n > b[i]) magic += a[i] * n - b[i];       if (magic > k) return false;     }     return true;   }   int32_t main() {     long long n, k;     cin >> n >> k;     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     for (long long i = 0; i < n; i++) {       cin >> b[i];     }     long long l = 0, r = 2000000001;     while (r - l != 1) {       if (isnp((r + l) / 2, k, n))         l = (r + l) / 2;       else         r = (r + l) / 2;     }     cout << l;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5, K = 505, INF = K * (1e4 + 5);   int n, m, k;   int c[N], a[N], visit[N];   int w[K][K];   vector<pair<int, int>> edges[N];   vector<int> colors;   void dfs(int s) {     visit[s] = 1;     colors.push_back(a[s]);     for (auto x : edges[s]) {       int nxt = x.first;       int w = x.second;       if (visit[nxt] || w) continue;       dfs(nxt);     }   }   vector<vector<int>> ffloyd(int M) {     vector<vector<int>> dist(M, vector<int>(M, INF));     for (int i = 0; i < M; i++)       for (int j = 0; j < M; j++) dist[i][j] = w[i][j];     for (int k = 0; k < M; k++) {       for (int i = 0; i < M; i++) {         for (int j = 0; j < M; j++) {           if (dist[i][k] < INF && dist[k][j] < INF)             dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);         }       }     }     return dist;   }   void solve() {     cin >> n >> m >> k;     for (int i = 0; i < k; i++) cin >> c[i];     int col = 0;     for (int i = 0, id = 0; i < k; i++) {       for (int j = 0; j < c[i]; j++) a[id++] = col;       col++;     }     for (int i = 0; i < k; i++)       for (int j = 0; j < k; j++)         if (i != j) w[i][j] = INF;     while (m--) {       int u, v, x;       cin >> u >> v >> x;       u--;       v--;       edges[u].push_back({v, x});       edges[v].push_back({u, x});       u = a[u], v = a[v];       if (u == v) continue;       w[u][v] = min(w[u][v], x);       w[v][u] = min(w[v][u], x);     }     int fail = 0;     for (int i = 0; i < n; i++) {       if (!visit[i]) {         dfs(i);         sort(colors.begin(), colors.end());         int count = 1;         for (int i = 1; i < colors.size(); i++) {           if (colors[i] == colors[i - 1]) {             count++;             continue;           }           if (c[colors[i - 1]] != count) {             fail = 1;             break;           }           count = 1;         }         if (c[colors.back()] != count) {           fail = 1;           break;         }         colors.clear();       }     }     if (fail) {       cout <<  No n ;       return;     }     cout <<  Yes n ;     vector<vector<int>> dist = ffloyd(k);     for (int i = 0; i < k; i++) {       for (int j = 0; j < k; j++) {         if (dist[i][j] == INF) dist[i][j] = -1;         cout << dist[i][j] <<    ;       }       cout <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   char a[222][222];   struct Dinic {     struct edge {       int to, flow, cap;     };     const static int N = 202 * 202;     vector<edge> e;     vector<int> g[N + 7];     int dp[N + 7];     int ptr[N + 7];     void clear() {       for (int i = 0; i < N + 7; i++) g[i].clear();       e.clear();     }     void addEdge(int a, int b, int cap = 1) {       g[a].push_back(e.size());       e.push_back({b, 0, cap});       g[b].push_back(e.size());       e.push_back({a, 0, 0});     }     int minFlow, start, finish;     bool bfs() {       for (int i = 0; i < N; i++) dp[i] = -1;       dp[start] = 0;       vector<int> st;       int uk = 0;       st.push_back(start);       while (uk < st.size()) {         int v = st[uk++];         for (int to : g[v]) {           auto ed = e[to];           if (ed.cap - ed.flow >= minFlow && dp[ed.to] == -1) {             dp[ed.to] = dp[v] + 1;             st.push_back(ed.to);           }         }       }       return dp[finish] != -1;     }     int dfs(int v, int flow) {       if (v == finish) return flow;       for (; ptr[v] < g[v].size(); ptr[v]++) {         int to = g[v][ptr[v]];         edge ed = e[to];         if (ed.cap - ed.flow >= minFlow && dp[ed.to] == dp[v] + 1) {           int add = dfs(ed.to, min(flow, ed.cap - ed.flow));           if (add) {             e[to].flow += add;             e[to ^ 1].flow -= add;             return add;           }         }       }       return 0;     }     int dinic(int start, int finish) {       Dinic::start = start;       Dinic::finish = finish;       int flow = 0;       for (minFlow = 1; minFlow; minFlow >>= 1) {         while (bfs()) {           for (int i = 0; i < N; i++) ptr[i] = 0;           while (int now = dfs(start, (int)2e9 + 7)) flow += now;         }       }       return flow;     }   } dinic;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) cin >> a[i][j];     int s = n * m;     int t = n * m + 1;     auto get_node = [](int first, int second) { return first * m + second; };     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j)         if (a[i][j] ==  # ) {           if (i > 0 && a[i - 1][j] ==  # )             dinic.addEdge(get_node(i, j), get_node(i - 1, j));           if (j + 1 < m && a[i][j + 1] ==  # )             dinic.addEdge(get_node(i, j), get_node(i, j + 1));           if (j == 0 || a[i][j - 1] ==  . ) dinic.addEdge(s, get_node(i, j));           if (i == 0 || a[i - 1][j] ==  . ) dinic.addEdge(get_node(i, j), t);         }     }     cout << dinic.dinic(s, t);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     std::ios::sync_with_stdio(false);     cin >> n >> m;     int x, y;     for (int i = 0; i < m; i++) cin >> x >> y;     for (int i = 0; i < n; i++)       if (i % 2 == 0)         cout << 0;       else         cout << 1;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   struct abc {     long long int y, x;   };   bool compare(abc a1, abc a2) {     if (a1.x == a2.x) return a1.y < a2.y;     return a1.x < a2.x;   }   long long int countDivisors(long long int n) {     long long int cnt = 0;     for (long long int i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         if (n / i == i)           cnt++;         else           cnt = cnt + 2;       }     }     return cnt;   }   const long long int mod = 1e9 + 7;   long long int n, m, x, y, l, r, ans, k, q, w, h;   string second, p;   map<long long int, long long int> mp;   void solve() {     cin >> n >> k;     long long int a[n], sum = 0;     vector<long long int> v;     for (long long int i = 0; i < n; i++) {       cin >> a[i];       ans += a[i] / 10;       long long int x = a[i] % 10;       if (x % 10 != 0)         x = 10 - x;       else         x = 0;       if (x) v.push_back(x);       a[i] += x;       sum += (100 - a[i]);     }     sort(v.begin(), v.end());     for (long long int i = 0; i < v.size(); i++) {       if (k >= v[i])         ans++, k -= v[i];       else {         k = 0;         break;       }     }     ans += min(sum, k) / 10;     cout << ans;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n;     cin >> n;     int flag = 0;     int m;     cin >> m;     long long a[m];     for (int i = 0; i < m; i++) {       cin >> a[i];     }     sort(a, a + m);     for (int i = 1; i < m - 1; i++) {       if ((a[i] - a[i - 1] == 1) && (a[i + 1] - a[i] == 1)) {         flag = 1;         break;       }     }     if (flag == 1 || a[m - 1] == n || a[0] == 1)       cout <<  NO             <<   n ;     else       cout <<  YES             <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int INF = 1e18;   const int N = 3e5 + 7;   const int MOD = 1e9 + 7;   constexpr int mul(int a, int b) { return 1LL * a * b % MOD; }   template <typename... T>   constexpr int mul(int a, int b, T... t) {     return mul(mul(a, b), t...);   }   inline int read() {     char ch = getchar();     int x = 0, f = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while ( 0  <= ch && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   inline long long int readl() {     char ch = getchar();     long long int x = 0, f = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while ( 0  <= ch && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   long long int a[N], b[N];   long long int dp[N][3];   int main() {     int T = read();     while (T--) {       int n = read();       for (int i = 1; i <= n; i++) {         a[i] = readl();         b[i] = readl();       }       for (int i = 1; i <= n; i++) {         for (int j = 0; j < 3; j++) {           dp[i][j] = INF;         }       }       dp[1][0] = 0;       dp[1][1] = b[1];       dp[1][2] = b[1] * 2;       for (int i = 2; i <= n; i++) {         for (int j = 0; j < 3; j++) {           for (int k = 0; k < 3; k++) {             if (a[i] + j == a[i - 1] + k) {               continue;             }             dp[i][j] = min(dp[i][j], dp[i - 1][k] + b[i] * j);           }         }       }       cout << min(dp[n][0], min(dp[n][1], dp[n][2])) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, *a, s, t, d1 = 0, d2 = 0;     cin >> n;     a = new int[n];     for (int i = 0; i < n; i++) cin >> a[i];     cin >> s >> t;     if (s < t) {       int tmp = t;       t = s;       s = tmp;     }     for (int i = t - 1; i < s - 1; i++) d1 += a[i];     for (int i = s - 1; i < n; i++) d2 += a[i];     for (int i = 0; i < t - 1; i++) d2 += a[i];     if (d1 > d2)       cout << d2;     else       cout << d1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> prefix_function(const string &s) {     int n = (int)s.size();     vector<int> p(n);     p[0] = 0;     for (int i = 1; i < n; i++) {       p[i] = p[i - 1];       while (p[i] > 0 && s[p[i]] != s[i]) p[i] = p[p[i] - 1];       if (s[p[i]] == s[i]) p[i]++;     }     return p;   }   vector<int> Z_function(string s) {     int n = (int)s.size();     vector<int> Z(n);     int l = 0, r = 0;     for (int i = 1; i < n; i++) {       if (i <= r) Z[i] = min(Z[i - l], r - i + 1);       while (i + Z[i] < n && s[i + Z[i]] == s[Z[i]]) Z[i]++;       if (i + Z[i] >= r) {         l = i;         r = i + Z[i] - 1;       }     }     return Z;   }   int main() {     string a;     getline(cin, a);     string b;     getline(cin, b);     int n = (int)a.size();     if (n != (int)b.size()) {       cout <<  -1 -1  << endl;       return 0;     }     vector<int> Z = Z_function(b + char(10) + a);     reverse(a.begin(), a.end());     vector<int> pi = prefix_function(a + char(10) + b);     reverse(a.begin(), a.end());     int i = 0;     int x = -1;     int y = -1;     while (i < n - 1) {       if (a[i] != b[n - i - 1]) break;       if (i + Z[n + 1 + i + 1] + pi[2 * n - i - 1] + 1 >= n) {         x = i;         y = n - pi[2 * n - i - 1];       };       i++;     }     cout << x <<     << y << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int A = 1000001;   int x, p, k;   bool b[A];   vector<int> v[A];   int calc(int x) {     int ret = 0;     int n = v[p].size();     for (int i = 1; i < (1 << n); i++) {       int pro = 1;       for (int j = 0; j < n; j++) {         if ((1 << j) & i) pro *= v[p][j];       }       ret += x / pro * (__builtin_popcount(i) % 2 ? 1 : -1);     }     return x - ret;   }   int main() {     for (int i = 2; i < A; i++) b[i] = 1;     for (int i = 2; i < A; i++) {       if (b[i] == 0) continue;       v[i].push_back(i);       for (int j = i + i; j < A; j += i) {         v[j].push_back(i);         b[j] = 0;       }     }     int T;     scanf( %d , &T);     while (T--) {       scanf( %d %d %d , &x, &p, &k);       int c = calc(x);       int l = 1, r = 1e9;       while (l <= r) {         int mid = (l + r) / 2;         if (calc(mid) - c >= k)           r = mid - 1;         else           l = mid + 1;       }       printf( %d n , r + 1);     }   }


#include <bits/stdc++.h>   using namespace std;   const int MXN = 1000100;   const long long inf = 1e15;   const int mod = 1000000007;   char s[MXN];   int was[2 * MXN];   int main() {     scanf( %s , s);     int n = strlen(s);     if (s[n - 1] ==  L ) {       for (int i = 0; i < (n); i++) {         if (s[i] ==  R )           s[i] =  L ;         else           s[i] =  R ;       }     }     for (int i = 0; i < (n); i++) {       if (s[i] ==  R )         s[i] = 1;       else         s[i] = -1;     }     int cur = 0;     int mn = 0, mx = 0, cmx = 0, tmx = 0;     for (int i = 0; i < (n); i++) {       was[cur + n] = 1;       cur += s[i];       tmx = max(tmx, cur);       if (cur < mn) {         mn = cur;         mx = -1e9;         cmx = 0;       }       if (cur > mx) {         mx = cur;         cmx = 1;       } else if (cur == mx) {         cmx++;       }     }     if (!was[cur + n]) {       printf( 1 n );       return 0;     }     if (cur == mx && cmx == 1) {       if (cur - mn > tmx) {         printf( %d n , cur - mn - tmx);         return 0;       }     }     printf( 0 );   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000 * 1000 * 1000 + 7;   const int INF = 1000 * 1000 * 1000;   const long long LINF = (long long)INF * INF;   struct Query {     int l, r, ind, k;   };   int n, m;   int c[100100];   vector<int> adj[100100];   int cnt[100100], bnd[100100];   int ans[100100];   vector<int> st;   int sttime[100100];   int fntime[100100];   Query qr[100100];   void dfs(int v, int par) {     st.push_back(v);     sttime[v] = st.size() - 1;     for (int u : adj[v]) {       if (u == par) {         continue;       }       dfs(u, v);     }     fntime[v] = st.size() - 1;   }   bool mos_cmp(Query &a, Query &b) {     if (a.l / 400 == b.l / 400) {       return (a.l / 400 % 2 ? a.r > b.r : a.r < b.r);     }     return a.l / 400 < b.l / 400;   }   void mos_add(int i) {     cnt[c[i]]++;     bnd[cnt[c[i]]]++;   }   void mos_rem(int i) {     bnd[cnt[c[i]]]--;     cnt[c[i]]--;   }   int main(void) {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> m;     for (int i = (1); i < (n + 1); i++) {       cin >> c[i];     }     for (int i = (0); i < (n - 1); i++) {       int ai, bi;       cin >> ai >> bi;       adj[ai].push_back(bi);       adj[bi].push_back(ai);     }     dfs(1, -1);     for (int i = (0); i < (m); i++) {       int vi, ki;       cin >> vi >> ki;       qr[i].l = sttime[vi];       qr[i].r = fntime[vi];       qr[i].k = ki;       qr[i].ind = i;     }     sort(qr, qr + m, mos_cmp);     int l = 0, r = -1;     for (int i = (0); i < (m); i++) {       while (l > qr[i].l) {         l--;         mos_add(st[l]);       }       while (r < qr[i].r) {         r++;         mos_add(st[r]);       }       while (l < qr[i].l) {         mos_rem(st[l]);         l++;       }       while (r > qr[i].r) {         mos_rem(st[r]);         r--;       }       ans[qr[i].ind] = bnd[qr[i].k];     }     for (int i = (0); i < (m); i++) {       cout << ans[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long st = 1, mod = 998244353;     int n;     cin >> n;     vector<long long> ans(n + 1);     ans[n] = 10;     ans[n - 1] = 20;     for (int i = n - 2; i >= 1; i--) {       ans[i] = ans[i + 1] + 9;     }     for (int i = n - 1; i >= 1; i--) {       ans[i] = ((ans[i] * 9) % mod * st) % mod;       st = (10 * st) % mod;     }     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;     cout << endl;   }   int main() {     ios_base::sync_with_stdio(false);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long s = 0, w = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 , ch = getchar();     return s * w;   }   const long long p = 998244353;   long long qp(long long x, long long y) {     long long res = 1;     for (long long t = x; y; y >>= 1, t = t * t % p)       if (y & 1) res = res * t % p;     return res;   }   struct node {     long long u, v, w;   } a[1000003];   vector<node> v[1000003];   long long f[1000003], g[1000003];   long long c[1000003];   signed main() {     long long n = read(), m = read(), k = read() + 1;     for (long long i = 1; i <= m; ++i) {       long long X = read();       a[i].u = read();       a[i].v = read();       a[i].w = read();       v[X].push_back(a[i]);     }     long long ans = 1e18;     memset(f, -1, sizeof(f)), memset(g, -1, sizeof(g));     memset(c, -1, sizeof(c));     long long S = 0, C = 0;     for (long long i = 1; i <= 1000000; ++i) {       for (node j : v[i])         if (j.v == 0) {           if (c[j.u] == -1) {             S += j.w, ++C, c[j.u] = j.w;           } else if (c[j.u] > j.w) {             S -= c[j.u] - j.w, c[j.u] = j.w;           }         }       if (C == n) f[i] = S;     }     S = 0, C = 0;     memset(c, -1, sizeof(c));     for (long long i = 1000000; i >= 1; --i) {       for (node j : v[i])         if (j.u == 0) {           if (c[j.v] == -1) {             S += j.w, ++C, c[j.v] = j.w;           } else if (c[j.v] > j.w) {             S -= c[j.v] - j.w, c[j.v] = j.w;           }         }       if (C == n) g[i] = S;     }     for (long long i = 1; i + k <= 1000000; ++i)       if (f[i] > -1 && g[i + k] > -1) {         ans = min(ans, f[i] + g[i + k]);       }     if (ans > 1e17)       puts( -1 );     else       printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void sc() {}   template <typename T, typename... Args>   void sc(T& a, Args&... args) {     cin >> a, sc(args...);   }   template <typename T>   void pr(T a) {     cout << a;   }   template <typename T, typename... Args>   void pr(T a, Args... args) {     cout << a <<    , pr(args...);   }   template <typename T>   void prl(T a) {     cout << a <<   n ;   }   template <typename T, typename... Args>   void prl(T a, Args... args) {     cout << a <<    , prl(args...);   }   template <typename T>   int sz(const T& a) {     return (int)a.size();   }   int dp[81][200003];   struct comp {     bool operator()(const pair<int, int>& lhs, const pair<int, int>& rhs) const {       return lhs.first + lhs.second <= rhs.first + rhs.second;     }   };   int main() {     cin.tie(NULL);     ios_base::sync_with_stdio(false);     int n, m;     sc(n, m);     pair<int, int> aten[n + 1];     aten[0] = {0, 0};     for (__typeof(2 * (m + 1)) i = (1) - ((1) > (2 * (m + 1)));          i != (2 * (m + 1)) - ((1) > (2 * (m + 1)));          i += 1 - 2 * ((1) > (2 * (m + 1))))       dp[0][i] = m + 1;     for (__typeof(n + 1) i = (1) - ((1) > (n + 1));          i != (n + 1) - ((1) > (n + 1)); i += 1 - 2 * ((1) > (n + 1))) {       sc(aten[i].first, aten[i].second);     }     sort(aten + 1, aten + n + 1, comp());     for (__typeof(n + 1) i = (1) - ((1) > (n + 1));          i != (n + 1) - ((1) > (n + 1)); i += 1 - 2 * ((1) > (n + 1))) {       dp[i][2 * (m + 1)] = m + 1;       for (__typeof(1) j = (2 * (m + 1)) - ((2 * (m + 1)) > (1));            j != (1) - ((2 * (m + 1)) > (1)); j += 1 - 2 * ((2 * (m + 1)) > (1))) {         int addneeded = 0;         if (j >= aten[i].first) {           addneeded = max(0, j - aten[i].first - aten[i].second);         } else           addneeded = max(0, aten[i].first - aten[i].second - j);         dp[i][j] = min(             dp[i][j + 1],             min(dp[i - 1][j],                 addneeded + (aten[i].first - aten[i].second - addneeded - 1 >= 0                                  ? dp[i - 1][aten[i].first - aten[i].second -                                              addneeded - 1]                                  : 0)));       }     }     prl(dp[n][m]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y, z = 0, k, t = 0, e, g;     vector<int> zero;     vector<int> po;     vector<int> ne;     cin >> x;     g = x;     while (x--) {       cin >> y;       if (y < 0) {         ne.push_back(y);         k *= y;       }       if (y > 0) {         po.push_back(y);       }       if (y == 0) {         zero.push_back(y);       }       if (y < 0 || y == 0) t++;     }     if (t == g) {       for (int i = 0; i < 2; i++) {         e = ne.back();         po.push_back(e);         ne.pop_back();       }     }     k = ne.size();     if (k % 2 == 0) {       e = ne.back();       zero.push_back(e);       ne.pop_back();     }     cout << ne.size() <<    ;     for (int i = 0; i < ne.size(); i++) cout << ne[i] <<    ;     cout << endl;     cout << po.size() <<    ;     for (int i = 0; i < po.size(); i++) cout << po[i] <<    ;     cout << endl;     cout << zero.size() <<    ;     for (int i = 0; i < zero.size(); i++) cout << zero[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 1e9 + 9;   const long long inf = 1e18 + 18;   const int max6 = 1e6 + 6;   const int modx = 1e9 + 123;   const int mody = 997;   const int base = 137;   int a[max6], dd[max6], cnt[max6];   int main() {     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       for (int i = 0; i <= 2 * k; ++i) dd[i] = cnt[i] = 0;       for (int i = 1; i <= n; ++i) cin >> a[i];       int m = n / 2;       for (int i = 1; i <= m; ++i) {         int gmax = max(a[i], a[n - i + 1]) + k;         int gmin = min(a[i], a[n - i + 1]) + 1;         dd[gmin]++;         dd[gmax + 1]--;         cnt[a[i] + a[n - i + 1]]++;       }       int res = oo;       dd[1] += dd[0];       for (int i = 2; i <= 2 * k; ++i) {         dd[i] += dd[i - 1];         res = min(res, n - dd[i] - cnt[i]);       }       cout << res <<   n ;     }   }