#include <bits/stdc++.h>   using namespace std;   int main(void) {     long long int n = 0ll, k = 0ll, p = 0ll, pn = 0ll, even = 0ll, odd = 0ll;     while (cin >> n) {       cin >> k >> p;       if (k == 0) {         for (long long int i = 0; i < p; i++) {           cin >> pn;           cout <<  . ;         }         cout << endl;       } else {         if (n % 2 == 0) {           if (k >= (n >> 1)) {             even = 2;             k -= (n >> 1);             odd = n + 1 - (k << 1);           } else {             odd = n + 1;             even = n + 2 - (k << 1);           }           for (int i = 0; i < p; i++) {             cin >> pn;             if (pn % 2 == 0) {               if (pn >= even) {                 cout <<  X ;               } else {                 cout <<  . ;               }             } else {               if (pn >= odd) {                 cout <<  X ;               } else {                 cout <<  . ;               }             }           }           cout << endl;         } else {           n--;           k--;           if (k >= (n >> 1)) {             even = 2;             k -= (n >> 1);             odd = n + 1 - (k << 1);           } else {             odd = n + 1;             even = n + 2 - (k << 1);           }           for (int i = 0; i < p; i++) {             cin >> pn;             if (pn == n + 1) {               cout <<  X ;             } else if (pn % 2 == 0) {               if (pn >= even) {                 cout <<  X ;               } else {                 cout <<  . ;               }             } else {               if (pn >= odd) {                 cout <<  X ;               } else {                 cout <<  . ;               }             }           }           cout << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> mp;   int fin(int rem) {     for (auto p : mp) {       if (p.first >= rem) return p.first;     }     return -1;   }   int main() {     long long ans = 0, rem = 0, p, x, y, n, RES = 1e9;     cin >> n >> x >> y;     long long a[] = {x, x, x, x, y, y};     sort(a, a + 6);     do {       mp.clear();       ans = 0;       for (int i = 0; i < 6; ++i) {         if ((x = fin(a[i])) == -1) {           ++ans;           ++mp[n - a[i]];         } else {           ++mp[x - a[i]];           if (!--mp[x]) mp.erase(x);         }       }       RES = min(RES, ans);     } while (next_permutation(a, a + 6));     cout << RES;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2000005;   template <typename T>   void read(T &x) {     x = 0;     int f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -f;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     x *= f;   }   template <typename T>   void write(T x) {     if (x < 0) x = -x, putchar( - );     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   template <typename T>   void writeln(T x) {     write(x);     puts(  );   }   int n, m1, m2, m, t;   int x1[MAXN], x2[MAXN];   int mid1[MAXN], mid2[MAXN];   int pos1[MAXN], pos2[MAXN];   int dp[3][MAXN], path[3][MAXN], pos[MAXN];   int main() {     read(n), read(m1), read(m2), read(t);     for (int i = 1; i <= m1; i++) read(x1[i]);     for (int i = 1; i <= m2; i++) read(x2[i]);     pos[++m] = 0;     int p1 = 1, p2 = 1;     while (p1 <= m1 || p2 <= m2) {       if (p1 > m1)         pos[++m] = x2[p2++] + 1;       else if (p2 > m2)         pos[++m] = x1[p1++] + 1;       else {         int Min = min(x1[p1], x2[p2]);         pos[++m] = Min + 1;         if (Min == x1[p1]) p1++;         if (Min == x2[p2]) p2++;       }     }     if (pos[m] != n + 1) pos[++m] = n + 1;     p1 = 1;     for (int i = 1; i <= m1; i++) {       while (x1[i] > pos[p1]) p1++;       if (pos[p1] > x1[i]) mid1[p1] = x1[i];       pos1[p1] += x1[i] == pos[p1];     }     p2 = 1;     for (int i = 1; i <= m2; i++) {       while (x2[i] > pos[p2]) p2++;       if (pos[p2] > x2[i]) mid2[p2] = x2[i];       pos2[p2] += x2[i] == pos[p2];     }     memset(dp, -1, sizeof(dp));     dp[1][1] = 0;     for (int i = 1; i <= m - 1; i++) {       if (dp[1][i] != -1 && pos2[i] == 0) {         int tmp = min(dp[1][i], t);         if (tmp > dp[2][i]) {           dp[2][i] = tmp;           path[2][i] = 1;         }       }       if (dp[2][i] != -1 && pos1[i] == 0) {         int tmp = min(dp[2][i], t);         if (tmp > dp[1][i]) {           dp[1][i] = tmp;           path[1][i] = 1;         }       }       if (dp[1][i] != -1) {         int tmp = dp[1][i];         if (pos1[i + 1] == 0 && mid1[i + 1] == 0) tmp += pos[i + 1] - pos[i];         if (pos1[i + 1] == 0 && mid1[i + 1] != 0) {           tmp += mid1[i + 1] - pos[i] - 1;           if (tmp < t)             tmp = -1;           else             tmp -= t;           if (tmp != -1) tmp += pos[i + 1] - mid1[i + 1] + 1;         }         if (pos1[i + 1] != 0 && mid1[i + 1] == 0) {           tmp += pos[i + 1] - pos[i] - 1;           if (tmp < t)             tmp = -1;           else             tmp -= t;           if (tmp != -1) tmp += 1;         }         if (pos1[i + 1] != 0 && mid1[i + 1] != 0) {           tmp += mid1[i + 1] - pos[i] - 1;           if (tmp < t)             tmp = -1;           else             tmp -= t;           if (tmp != -1) tmp += pos[i + 1] - mid1[i + 1];           if (tmp < t)             tmp = -1;           else             tmp -= t;           if (tmp != -1) tmp += 1;         }         dp[1][i + 1] = tmp;       }       if (dp[2][i] != -1) {         int tmp = dp[2][i];         if (pos2[i + 1] == 0 && mid2[i + 1] == 0) tmp += pos[i + 1] - pos[i];         if (pos2[i + 1] == 0 && mid2[i + 1] != 0) {           tmp += mid2[i + 1] - pos[i] - 1;           if (tmp < t)             tmp = -1;           else             tmp -= t;           if (tmp != -1) tmp += pos[i + 1] - mid2[i + 1] + 1;         }         if (pos2[i + 1] != 0 && mid2[i + 1] == 0) {           tmp += pos[i + 1] - pos[i] - 1;           if (tmp < t)             tmp = -1;           else             tmp -= t;           if (tmp != -1) tmp += 1;         }         if (pos2[i + 1] != 0 && mid2[i + 1] != 0) {           tmp += mid2[i + 1] - pos[i] - 1;           if (tmp < t)             tmp = -1;           else             tmp -= t;           if (tmp != -1) tmp += pos[i + 1] - mid2[i + 1];           if (tmp < t)             tmp = -1;           else             tmp -= t;           if (tmp != -1) tmp += 1;         }         dp[2][i + 1] = tmp;       }     }     if (dp[1][m] == -1 && dp[2][m] == -1) {       printf( No n );       return 0;     }     printf( Yes n );     int px, py;     if (dp[1][m] == -1)       py = 2, px = m;     else       py = 1, px = m;     static int shifts[MAXN], cnts = 0;     static int x[MAXN], y[MAXN], cnt = 0;     int now = 0;     while (px != 1 || py != 1) {       if (path[py][px]) {         cnt += now;         int tx = pos[px] - dp[py][px];         for (int i = 1; i <= now; i++) {           tx += t;           x[cnt - i + 1] = tx;           y[cnt - i + 1] = py;         }         py = 3 - py;         now = 0;         shifts[++cnts] = pos[px];       } else {         if (py == 1)           now += mid1[px] != 0, now += pos1[px] != 0;         else           now += mid2[px] != 0, now += pos2[px] != 0;         px = px - 1;       }     }     cnt += now;     int tx = 0;     for (int i = 1; i <= now; i++) {       tx += t;       x[cnt - i + 1] = tx;       y[cnt - i + 1] = py;     }     writeln(cnts);     reverse(shifts + 1, shifts + cnts + 1);     for (int i = 1; i <= cnts; i++) printf( %d  , shifts[i]);     printf(  n );     writeln(cnt);     reverse(x + 1, x + cnt + 1);     reverse(y + 1, y + cnt + 1);     for (int i = 1; i <= cnt; i++) printf( %d %d n , x[i], y[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int sum[100005];   int main() {     int h1, h2, a, b, k, x;     cin >> h1 >> h2 >> a >> b;     int num = h1 + a * 8;     if (num >= h2)       x = 0;     else if (a <= b)       x = -1;     else {       x = 1;       num -= b * 12;       for (int i = 1;; i++) {         num += a * 12;         if (num >= h2)           break;         else {           x++;           num -= b * 12;         }       }     }     cout << x << endl;     return 0;   }


#include <bits/stdc++.h>   const int N = 200010;   const long long INF = 1ll << 60;   const int inf = 0x3f3f3f3f;   class SegmentTree {    public:     SegmentTree() {}     void Init(int n, int v[]) {       n_ = n;       Build(1, n, 1, v);     }     void ChangeSingle(int l, int r, int rt, int id, int x) {       if (l == r) {         min_[rt] = std::pair<int, int>(x, l);         return;       }       int m = (l + r) >> 1;       if (id <= m) {         ChangeSingle(l, m, rt << 1, id, x);       } else {         ChangeSingle(m + 1, r, rt << 1 | 1, id, x);       }       Up(rt);     }     std::pair<int, int> MinInterval(int l, int r, int rt, int L, int R) {       if (L > R) {         return std::pair<int, int>(inf, inf);       }       if (L <= l && r <= R) {         return min_[rt];       }       int m = (l + r) >> 1;       std::pair<int, int> ans(inf, inf);       if (L <= m) {         ans = std::min(ans, MinInterval(l, m, rt << 1, L, R));       }       if (R > m) {         ans = std::min(ans, MinInterval(m + 1, r, rt << 1 | 1, L, R));       }       return ans;     }       private:     void Build(int l, int r, int rt, int v[]) {       if (l == r) {         min_[rt].first = v[l];         min_[rt].second = l;         return;       }       int m = (l + r) >> 1;       Build(l, m, rt << 1, v);       Build(m + 1, r, rt << 1 | 1, v);       Up(rt);     }     void Up(int rt) { min_[rt] = std::min(min_[rt << 1], min_[rt << 1 | 1]); }     int n_;     std::pair<int, int> min_[N << 2 | 1];   } seg;   int t;   int n, m;   int a[N];   int b[N];   std::multiset<int> se[N];   int pre[N];   int v[N];   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       for (int i = 0; i < n; ++i) {         se[i].clear();         pre[i] = 0;       }       for (int i = 1; i <= n; ++i) {         scanf( %d%d , &a[i], &b[i]);         se[a[i]].insert(b[i]);       }       if (n == 1) {         printf( 0 n );         continue;       }       for (int i = 0; i < n; ++i) {         pre[i] = (i == 0 ? se[i].size() : pre[i - 1] + se[i].size());         v[i] = (se[i].size() ? (*se[i].begin()) : inf);       }       seg.Init(n - 1, v);       int id_st = n - 1;       while (id_st >= 0 && pre[id_st] > id_st) {         --id_st;       }       int num = 0;       int num_last = 0;       int num2 = 0;       long long ans = 0ll;       while (num < n) {         int inc = 0;         for (int i = num_last; i <= num; ++i) {           if (se[i].size()) {             inc += se[i].size();             se[i].clear();           }         }         num_last = num + 1;         if (inc) {           num += inc;           continue;         } else {           while (id_st >= num + 1 && pre[id_st] + num2 > id_st) {             --id_st;           }           std::pair<int, int> x = seg.MinInterval(1, n - 1, 1, id_st + 1, n - 1);           ans += x.first;           int id = x.second;           se[id].erase(se[id].begin());           if (se[id].size()) {             seg.ChangeSingle(1, n - 1, 1, id, *se[id].begin());           } else {             seg.ChangeSingle(1, n - 1, 1, id, inf);           }           ++num2;           ++num;         }       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, k;     scanf( %d %d , &n, &k);     printf( %d n , 6 * n * k - k);     for (int i = 0; i < n; ++i) {       printf( %d %d %d %d n , 6 * i * k + k, 6 * i * k + 2 * k, 6 * i * k + 3 * k,              6 * i * k + 5 * k);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long t, fact[405], inv[405], dp[405][405], ans[405], n, dp2[405];   long long p;   long long exp(long long x, long long k) {     if (k == 0) return 1;     if (k % 2 == 1) return x * exp(x, k - 1) % p;     long long y = exp(x, k / 2);     return y * y % p;   }   int main() {     cin >> t >> p;     fact[0] = 1;     for (int i = 1; i < 405; ++i) {       fact[i] = i * fact[i - 1] % p;       inv[i] = exp(i, p - 2);     }     dp[0][0] = 1;     for (int i = 0; i <= 399; ++i)       for (int k = 1; k <= 400; ++k)         for (int j = 0; j <= 400 - k; ++j)           dp[j + k][i + 1] = (dp[j + k][i + 1] + fact[k] * dp[j][i]) % p;     dp2[1] = dp2[2] = 1;     for (int i = 3; i <= 400; ++i) {       dp2[i] = fact[i];       for (int j = 1; j < i; ++j)         dp2[i] = (p + dp2[i] - dp2[j] * fact[i - j] % p) % p;     }     for (int i = 1; i <= 400; ++i) {       ans[i] = fact[i];       for (int j = 3; j < i; ++j) ans[i] = (ans[i] + p - dp[i][j] * ans[j]) % p;       for (int j = 1; j <= i - 1; ++j)         ans[i] = (ans[i] + p - 2 * dp2[j] * fact[i - j] % p) % p;       ans[2] = 2;     }     for (int i = 0; i < t; ++i) {       int x;       cin >> x;       cout << ans[x] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   struct Amulet {     char p[2][2];     void Read() { cin >> p[0][0] >> p[0][1] >> p[1][0] >> p[1][1]; }     Amulet Rotate() const {       Amulet ret(*this);       ret.p[0][0] = this->p[0][1];       ret.p[0][1] = this->p[1][1];       ret.p[1][0] = this->p[0][0];       ret.p[1][1] = this->p[1][0];       return ret;     }   };   bool Equiv(Amulet const& a1, Amulet const& a2) {     return a1.p[0][0] == a2.p[0][0] && a1.p[0][1] == a2.p[0][1] &&            a1.p[1][0] == a2.p[1][0] && a1.p[1][1] == a2.p[1][1];   }   bool operator==(Amulet const& a1, Amulet const& a2) {     Amulet tmp(a1);     for (int i = 0; i < 4; ++i) {       if (Equiv(tmp, a2)) return true;       tmp = tmp.Rotate();     }     return false;   }   int main() {     vector<Amulet> v;     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       Amulet a;       a.Read();       vector<Amulet>::iterator it = find(v.begin(), v.end(), a);       if (it == v.end()) {         v.push_back(a);       }       char dummy;       cin >> dummy >> dummy;     }     cout << v.size() << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     cout << (n / k + 1) * k;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int a;     int id;     bool operator<(const node &b) const {       if (a != b.a)         return a < b.a;       else         return id > b.id;     }   };   struct node que[305];   bool vis[305];   int main() {     int t, n, m;     scanf( %d , &t);     while (t--) {       memset(vis, 0, sizeof(vis));       scanf( %d%d , &n, &m);       for (int i = 1; i <= m; i++) {         scanf( %d , &que[i].a);         que[i].id = i;       }       sort(que + 1, que + m + 1);       long long ans = 0;       for (int i = 1; i <= m; i++) {         for (int j = 1; j < que[i].id; j++) ans += vis[j];         vis[que[i].id] = 1;       }       printf( %lld n , ans);     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     set<char> ss;     for (char c : s) ss.insert(c);     if (ss.size() < n)       cout <<  NO  << endl;     else {       cout <<  YES  << endl;       int vis[30];       memset(vis, 0, sizeof vis);       string res =   ;       for (char c : s) {         if (n == 1)           res += c;         else {           if (res.size() > 0 and !vis[c -  a ]) {             n--;             vis[c -  a ] = 1;             cout << res << endl;             res = string(1, c);           } else {             vis[c -  a ] = 1;             res += c;           }         }       }       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   long long stk[300001][3], top = 1, n, m, best = 1, nownum, K, B;   long long eval(long long x) {     return (K + stk[x][0]) * stk[x][2] + B + stk[x][1];   }   double intersect(long long x, long long y) {     return (double)(stk[x][0] - stk[y][0]) / (stk[y][1] - stk[x][1]);   }   bool comp(long long x) {     return eval(top) * (stk[top][2] - stk[top - 1][2]) >=            (eval(top - 1) - eval(top)) * (x - stk[top][2]);   }   signed main() {     scanf( %I64d%I64d , &nownum, &m);     --nownum;     for (long long i = 1, opt, k, b, s; i <= m; i++) {       scanf( %I64d , &opt);       if (opt == 1) {         scanf( %I64d , &k);         top = 1;         K = B = 0;         stk[top][0] = 0;         stk[top][1] = 0;         stk[top][2] = 0;         nownum += k;       } else if (opt == 2) {         scanf( %I64d , &k);         if (eval(top) == 0) {           nownum += k;           goto loop;         }         while (top > 1 && comp(nownum + 1)) --top;         ++top;         stk[top][0] = -K;         stk[top][1] = -B;         stk[top][2] = nownum + 1;         nownum += k;       } else {         scanf( %I64d%I64d , &b, &s);         K += s;         B += b;         while (top > 1 && eval(top - 1) <= eval(top)) --top;       }     loop:       printf( %I64d %I64d n , stk[top][2] + 1, eval(top));     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, p, x;     cin >> n >> k >> p;     int impair(k - p);     vector<int> pai, imp;     for (int i = 0; i < n; ++i) {       cin >> x;       if (x & 1)         imp.push_back(x);       else         pai.push_back(x);     }     int avpair(pai.size()), avimpair(imp.size());     avimpair -= impair;     if (avimpair < 0 || (avpair + (avimpair >> 1)) < p || (avimpair & 1)) {       cout <<  NO ;       return 0;     }     cout <<  YES n ;     vector<vector<int> > res;     res.resize(k);     int iimp(0), ipai(0);     for (int i = 0; i < impair; ++i) res[i].push_back(imp[iimp++]);     for (int i = impair; i < k; ++i)       if (ipai < pai.size())         res[i].push_back(pai[ipai++]);       else {         res[i].push_back(imp[iimp++]);         res[i].push_back(imp[iimp++]);       }     while (ipai < pai.size()) res[0].push_back(pai[ipai++]);     while (iimp < imp.size()) res[0].push_back(imp[iimp++]);     for (int i = 0; i < k; ++i) {       cout << res[i].size() <<    ;       for (int j = 0; j < res[i].size(); ++j) cout << res[i][j] <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x;     cin >> x;     cout << 25;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &x) {     x = 0;     bool f = false;     char ch = getchar();     while (!isdigit(ch)) {       f |= ch ==  - , ch = getchar();     }     while (isdigit(ch)) {       x = (x << 1) + (x << 3) + (ch ^ 48);       ch = getchar();     }     x = f ? -x : x;     return;   }   template <typename T>   inline void write(T x) {     if (x < 0) x = -x, putchar( - );     if (x > 9) write(x / 10);     putchar(x % 10 ^ 48);     return;   }   const int N = 1e3 + 5, MOD = 998244353;   int n, m, val[N], dp[N], Ans, C[N][N];   int main() {     read(n);     for (int i = 1; i <= n; i++) read(val[i]), C[i][i] = C[i][0] = 1;     for (int i = 1; i <= n; i++)       for (int j = 1; j < i; j++)         C[i][j] = (C[i - 1][j - 1] + C[i - 1][j] > +MOD                        ? C[i - 1][j - 1] + C[i - 1][j] - MOD                        : C[i - 1][j - 1] + C[i - 1][j]);     dp[n + 1] = 1;     for (int i = n; i >= 1; i--) {       if (val[i] <= 0) continue;       for (int j = val[i] + i + 1; j <= n + 1; j++)         dp[i] = (dp[i] + 1ll * dp[j] * C[j - i - 1][val[i]] % MOD > +MOD                      ? dp[i] + 1ll * dp[j] * C[j - i - 1][val[i]] % MOD - MOD                      : dp[i] + 1ll * dp[j] * C[j - i - 1][val[i]] % MOD);     }     for (int i = 1; i <= n; i++)       Ans = (Ans + dp[i] > +MOD ? Ans + dp[i] - MOD : Ans + dp[i]);     write(Ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class t>   t mag(t a) {     return a > 0 ? a : -a;   }   template <class T, class U>   T cdiv(T num, U den) {     return (num / den) + ((num % den) > 0);   }   std::ifstream term( /dev/tty );   std::string tempstring;   using ll = int_fast64_t;   using ii = pair<int, int>;   using vi = vector<int>;   using vl = vector<ll>;   using vii = vector<ii>;   const int &sij = 400010;   const ll &mod = 998244353ll;   int n;   ll add(ll a, ll b) { return (a + b) % mod; }   int esc(int tcase) {     cin >> n;     vi vec(n);     for (auto &e : vec) cin >> e;     vl dp0(201), sdp0(201), dp1(201), sdp1(201);     for (int i = 1; i <= 200; i++) {       if (vec.back() == -1 or i == vec.back()) dp0[i] = 1;     }     partial_sum(dp0.begin(), dp0.end(), sdp0.begin(), add);     partial_sum(dp1.begin(), dp1.end(), sdp1.begin(), add);     ;     auto get0 = [&](int l, int r) -> ll {       if (r < l) return 0;       return (sdp0[r] - sdp0[l - 1] + mod) % mod;     };     auto get1 = [&](int l, int r) -> ll {       if (r < l) return 0;       return (sdp1[r] - sdp1[l - 1] + mod) % mod;     };     for (auto i = n - 2; i >= 0; i--) {       vl ndp0(201), ndp1(201);       for (int x = 1; x <= 200; x++) {         if (vec[i] == -1 or x == vec[i]) {           ndp0[x] = (get0(1, x - 1) + get1(1, x - 1)) % mod;           ndp1[x] = (get1(x + 1, 200) + get1(x, x) + get0(x, x)) % mod;         }       }       partial_sum(ndp0.begin(), ndp0.end(), sdp0.begin(), add);       partial_sum(ndp1.begin(), ndp1.end(), sdp1.begin(), add);       ;       ;       ;     }     cout << get1(1, 200) <<   n ;     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tc = 1;     for (int i = 1; i <= tc; i++) esc(i);   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1 << 28;   const long long LINF = 1ll << 61;   inline long long getnum() {     register long long r = 0;     register bool ng = 0;     register char c;     c = getchar();     while (c !=  -  && (c <  0  || c >  9 )) c = getchar();     if (c ==  - ) ng = 1, c = getchar();     while (c !=     && c !=   n ) r = r * 10 + c -  0 , c = getchar();     if (ng) r = -r;     return r;   }   template <class T>   inline void putnum(T x) {     if (x < 0) putchar( - ), x = -x;     register short a[20] = {}, sz = 0;     while (x > 0) a[sz++] = x % 10, x /= 10;     if (sz == 0) putchar( 0 );     for (int i = sz - 1; i >= 0; i--) putchar( 0  + a[i]);   }   inline void putsp() { putchar(   ); }   inline void putendl() { putchar(  n ); }   inline char mygetchar() {     register char c = getchar();     while (c ==     || c ==   n ) c = getchar();     return c;   }   const int dx[] = {1, -1, 0, 0};   const int dy[] = {0, 0, 1, -1};   const int maxn = 1700;   int w, h, c[maxn][maxn], ans[12345];   bool g[maxn][maxn], ng[2][maxn][maxn], vis[maxn][maxn], p;   void color(int x, int y, int id) {     c[x][y] = id;     for (int i = 0; i < 4; i++) {       int nx = x + dx[i], ny = y + dy[i];       if (nx > 0 && nx <= w && ny > 0 && ny <= h && g[nx][ny] && c[nx][ny] == 0) {         color(nx, ny, id);       }     }   }   void dfs(int x, int y) {     vis[x][y] = 1;     for (int i = 0; i < 4; i++) {       int nx = x + dx[i], ny = y + dy[i];       if (nx > 0 && nx <= w && ny > 0 && ny <= h && g[nx][ny] && !vis[nx][ny]) {         dfs(nx, ny);       }     }   }   void getsmaller() {     p ^= 1;     for (int i = 1; i <= w; i++) {       for (int j = 1; j <= h; j++) {         ng[p][i][j] = ng[p ^ 1][i][j];         for (int k = 0; k < 4; k++) {           if (!ng[p ^ 1][i + dx[k]][j + dy[k]]) {             ng[p][i][j] = 0;           }         }       }     }   }   void getbigger() {     p ^= 1;     for (int i = 1; i <= w; i++) {       for (int j = 1; j <= h; j++) {         ng[p][i][j] = ng[p ^ 1][i][j];         for (int k = 0; k < 4; k++) {           if (ng[p ^ 1][i + dx[k]][j + dy[k]]) {             ng[p][i][j] = 1;           }         }       }     }   }   void see() {     for (int i = 1; i <= w; i++) {       for (int j = 1; j <= h; j++) {         putnum(g[i][j] & (!vis[i][j])), putsp();       }       putendl();     }     putendl();   }   int main() {     w = getnum(), h = getnum();     for (int i = 1; i <= w; i++) {       for (int j = 1; j <= h; j++) {         g[i][j] = getnum();       }     }     int id = 0;     for (int i = 1; i <= w; i++) {       for (int j = 1; j <= h; j++) {         if (g[i][j] && c[i][j] == 0) {           id++;           color(i, j, id);         }       }     }     for (int i = 1; i <= w; i++)       for (int j = 1; j <= h; j++) ng[p][i][j] = g[i][j];     getsmaller();     getsmaller();     getsmaller();     getbigger();     getbigger();     getbigger();     getbigger();     getbigger();     for (int i = 1; i <= w; i++) {       for (int j = 1; j <= h; j++) {         g[i][j] &= !ng[p][i][j];       }     }     for (int i = 1; i <= w; i++)       for (int j = 1; j <= h; j++) ng[p][i][j] = g[i][j];     getsmaller();     getbigger();     for (int i = 1; i <= w; i++)       for (int j = 1; j <= h; j++) g[i][j] = ng[p][i][j];     for (int i = 1; i <= w; i++) {       for (int j = 1; j <= h; j++) {         if (g[i][j] && !vis[i][j]) {           ans[c[i][j]]++;           dfs(i, j);         }       }     }     sort(ans + 1, ans + id + 1);     putnum(id), putsp(), putendl();     for (int i = 1; i <= id; i++) putnum(ans[i]), putsp();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class Solve {    public:     int num;     int inputNum[2005];     int inversion[2005][2];     int sequence[2005];       public:     Solve() {       num = 0;       memset(inputNum, 0, sizeof(inputNum));       memset(inversion, 0, sizeof(inversion));       memset(sequence, 0, sizeof(sequence));     }     void stat() {       for (int i = 0; i < num; ++i) {         for (int j = 0; j < i; ++j) {           if (inputNum[j] < inputNum[i]) {             ++inversion[i][0];           }         }       }       for (int i = 0; i < num; ++i) {         for (int j = i + 1; j < num; ++j) {           if (inputNum[i] > inputNum[j]) {             ++inversion[i][1];           }         }       }     }     void calculate() {       for (int i = 0; i < num; ++i) {         if (inversion[i][0] < inversion[i][1]) {           sequence[i] = -inputNum[i];         } else {           sequence[i] = inputNum[i];         }       }     }     int getResult() {       int total = 0;       for (int i = 0; i < num; ++i) {         for (int j = i + 1; j < num; ++j) {           if (sequence[i] > sequence[j]) {             ++total;           }         }       }       return total;     }     void readData() {       cin >> num;       for (int i = 0; i < num; ++i) {         cin >> inputNum[i];         if (inputNum[i] < 0) {           inputNum[i] = -1 * inputNum[i];         }       }     }     int facade() {       readData();       stat();       calculate();       return getResult();     }   };   int main() {     Solve solve;     cout << solve.facade() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, x, y;     cin >> n >> m;     y = 3 * m;     x = 2 * n;     for (int i = 6; i <= x && i <= y; i += 6) {       if (x <= y)         x += 2;       else         y += 3;     }     cout << max(x, y);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 505;   bool arr[N][N];   int dp[N][N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m, k;     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       string s;       cin >> s;       for (int j = 1; j <= m; j++) {         arr[i][j] = (int)(s[j - 1] -  0 );       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (arr[i][j] && arr[i - 1][j] && arr[i + 1][j] && arr[i][j - 1] &&             arr[i][j + 1]) {           dp[i][j] = 1;         }       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         dp[i][j] += dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];       }     }     long long int ans = 0;     for (int a = 2; a < n; a++) {       for (int b = a; b < n; b++) {         int ptr = 1;         for (int c = 2; c < m; c++) {           while (ptr < m &&                  (dp[a - 1][c - 1] - dp[b][c - 1] - dp[a - 1][ptr] + dp[b][ptr] <                   k)) {             ptr++;           }           ans += (m - ptr);         }       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   static long long mi[400005][20];   static bool mark[400005][20];   static long long psum[400005];   long long f(int x, int k) {     if (k == 0) return psum[x];     if (mark[x][k]) return mi[x][k];     mark[x][k] = 1;     return mi[x][k] = min(f(x, k - 1), f(x + (1 << (k - 1)), k - 1));   }   long long qry(int l, int r) {     int t = r - l + 1;     int lg = 31 - __builtin_clz(t);     return min(f(l, lg), f(r - (1 << lg) + 1, lg));   }   int main() {     long long n, a, b, c, d, start, len;     scanf( %lld %lld %lld %lld %lld %lld %lld , &n, &a, &b, &c, &d, &start, &len);     vector<pair<long long, long long> > v;     for (long long i = 0; i < n; i++) {       long long x, y;       scanf( %lld %lld , &x, &y);       v.push_back(make_pair(y, x));     }     if (v[0].first == 0)       psum[0] = -d;     else       psum[0] = c;     for (int i = 1; i < n; i++) {       if (v[i].first)         psum[i] = psum[i - 1] + c;       else         psum[i] = psum[i - 1] - d;     }     psum[n] = 1000000000000000000;     vector<long long> t;     t.push_back(0);     for (int i = 0; i < n; i++) {       t.push_back(v[i].second + 1);       if (v[i].second - len + 1 >= 0) t.push_back(v[i].second - len + 1);     }     sort(t.begin(), t.end());     int l = 0, r = 0;     long long at = start;     for (int i = 0; i < t.size(); i++) {       while (l < v.size() && v[l].second < t[i]) {         if (v[l].first)           at += a;         else           at -= b;         if (at < 0) {           printf( -1 n );           return 0;         }         l++;       }       while (r < v.size() && v[r].second < t[i] + len) r++;       long long low = qry(l, r - 1) - (l > 0 ? psum[l - 1] : 0) + at;       if (low >= 0) {         printf( %lld n , t[i]);         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int get() {     char ch;     while (ch = getchar(), (ch <  0  || ch >  9 ) && ch !=  - )       ;     if (ch ==  - ) {       int s = 0;       while (ch = getchar(), ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 ;       return -s;     }     int s = ch -  0 ;     while (ch = getchar(), ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 ;     return s;   }   const int mo = 1e9 + 7;   const int N = 2e6 + 5;   int cnt[N];   int val[N];   int lst[N];   int pri[N], k;   int n;   int tim[N];   bool bz[N];   int main() {     n = get();     for (int i = 1; i <= n; i++) {       int x = get();       cnt[x]++;     }     lst[1] = 1;     for (int i = 2; i <= 2e6; i++) {       if (!lst[i]) pri[++k] = lst[i] = i;       for (int j = 1; j <= k; j++) {         if (1ll * pri[j] * i > 2e6) break;         lst[i * pri[j]] = pri[j];         if (i % pri[j] == 0) break;       }     }     for (int i = 1; i <= 2e6; i++) val[i] = 1;     int C = 0;     for (int i = 2e6; i >= 2; i--) {       for (int T = 1; T <= cnt[i]; T++) {         if (val[i] < i)           bz[i] = 1, tim[i] = 1, val[i] = i;         else {           bz[i - 1] = 1;           int x = i - 1;           while (x > 1) {             int v = lst[x];             int t = 1;             while (x % v == 0) {               x /= v;               t = t * v;             }             if (t > val[v]) {               val[v] = t;               tim[v] = 1;             } else if (val[v] == t)               tim[v]++;           }         }       }     }     for (int i = 1; i <= 2e6; i++)       if (bz[i]) {         bool can = 1;         for (int x = i; x > 1;) {           int v = lst[x], t = 1;           for (; x % v == 0;) x /= v, t *= v;           if (val[v] == t && tim[v] == 1) can = 0;         }         if (can) {           C = 1;           break;         }       }     int ans = 1;     for (int i = 1; i <= 2e6; i++) ans = 1ll * ans * val[i] % mo;     ans = (ans + C) % mo;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool vis[50];   bool OK(vector<set<int> > v) {     for (int i = 0; i < (int)v.size(); i++)       if ((int)v[i].size() > 3) return 1;     return 0;   }   int Find(vector<set<int> > v, int x) {     for (int i = 0; i < (int)v.size(); i++)       if (find(v[i].begin(), v[i].end(), x) != v[i].end()) return i;     return -1;   }   int main() {     int n, q, x, y, ex, ey, c = 0;     scanf( %d %d , &n, &q);     if (n % 3) {       cout << -1;       return 0;     }     vector<set<int> > v(n / 3);     while (q--) {       scanf( %d %d , &x, &y);       vis[x] = 1, vis[y] = 1;       ex = Find(v, x), ey = Find(v, y);       if (ex != -1)         v[ex].insert(y);       else if (ey != -1)         v[ey].insert(x);       else {         if (c == n / 3) {           cout << -1;           return 0;         }         v[c].insert(x), v[c].insert(y), c++;       }     }     if (OK(v)) {       cout << -1;       return 0;     }     c = 1;     for (int i = 0; i < (int)v.size(); i++) {       for (int j = 0; j < 3 - (int)v[i].size(); j++) {         for (int k = c; k < n + 1; k++)           if (!vis[k]) {             v[i].insert(k);             c = k + 1;             j--;             break;           }       }     }     for (int i = 0; i < (int)v.size(); i++) {       for (set<int>::iterator it = v[i].begin(); it != v[i].end(); it++)         printf( %d  , *it);       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long w1, h1, w2, h2;     cin >> w1 >> h1 >> w2 >> h2;     long long ans = h1 + h2 + 2;     ans += h1 + h2 + 2 + (w1 - w2);     ans += w1 + w2;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   vector<int> cnt[N];   int res[N];   int main() {     int n;     while (cin >> n) {       for (int i = 1; i < N; i++) cnt[i].clear();       for (int i = 1; i <= n; i++) {         int v;         cin >> v;         cnt[v].push_back(i);       }       bool ok = true;       for (int i = 1; i < N; i++) {         if (i > 1 && cnt[i].size() > cnt[i - 1].size()) ok = false;         for (int j = 0; j < cnt[i].size(); j++) {           res[cnt[i][j]] = j + 1;         }       }       if (!ok) {         printf( %d n , -1);       } else {         printf( %d n , cnt[1].size());         for (int i = 1; i <= n; i++) printf( %d%c , res[i], i == n ?   n  :    );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     while (n--) {       int a, s, d;       cin >> a >> s >> d;       if (a > s) swap(a, s);       if (a > d) swap(a, d);       if (s > d) swap(s, d);       if (s == d) {         cout <<  YES  << endl;         cout << a <<     << a <<     << d << endl;       } else {         cout <<  NO  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   const int INF = 1e9;   pair<int, int> NULLPOINT = make_pair(INF, INF);   int n;   int gcd(int x, int y) {     while (y) {       int t = x;       x = y;       y = t % y;     }     return x;   }   struct Line {     int x, y, xx, yy;     pair<int, int> slope() {       pair<int, int> ret = {x - xx, y - yy};       if (ret.second < 0) {         ret.first *= -1;         ret.second *= -1;       }       int g = gcd(abs(ret.first), ret.second);       ret.first /= g, ret.second /= g;       return ret;     }     pair<int, int> intersect(const Line &l) const {       long long den =           1LL * (x - xx) * (l.y - l.yy) - 1LL * (y - yy) * (l.x - l.xx);       if (den == 0) return NULLPOINT;       long long c1 = 1LL * x * yy - 1LL * y * xx;       long long c2 = 1LL * l.x * l.yy - 1LL * l.y * l.xx;       long long ix = c1 * (l.x - l.xx) - (x - xx) * c2;       long long iy = c1 * (l.y - l.yy) - (y - yy) * c2;       if (ix % den != 0) return NULLPOINT;       if (iy % den != 0) return NULLPOINT;       ix /= den;       iy /= den;       if (ix < min(x, xx) || ix > max(x, xx) || ix < min(l.x, l.xx) ||           ix > max(l.x, l.xx))         return NULLPOINT;       if (iy < min(y, yy) || iy > max(y, yy) || iy < min(l.y, l.yy) ||           iy > max(l.y, l.yy))         return NULLPOINT;       return pair<int, int>(ix, iy);     }   };   Line lines[N];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d %d %d %d , &lines[i].x, &lines[i].y, &lines[i].xx, &lines[i].yy);     }     long long ans = 0;     for (int i = 0; i < n; ++i) {       pair<int, int> slope = lines[i].slope();       if (slope.first == 0)         ans += abs((lines[i].y - lines[i].yy) / slope.second) + 1;       else         ans += abs((lines[i].x - lines[i].xx) / slope.first) + 1;     }     set<pair<int, int>> intersects;     intersects.insert(NULLPOINT);     for (int i = 0; i < n; ++i) {       set<pair<int, int>> lineIntersects;       lineIntersects.insert(NULLPOINT);       for (int j = 0; j < n; ++j) {         pair<int, int> p = lines[i].intersect(lines[j]);         lineIntersects.insert(p);         intersects.insert(p);       }       ans -= lineIntersects.size() - 1;     }     ans += intersects.size() - 1;     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   int main() {     long long n, k;     scanf( %lld%lld , &n, &k);     if (k < 2) {       printf( %lld , n);       return 0;     }     long long s = 1;     while (s - 1 < n) s *= 2;     printf( %lld , s - 1);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cin.exceptions(cin.failbit);     int n;     cin >> n;     vector<long long> a(n);     long long s = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       s += a[i];     }     sort(a.begin(), a.end());     reverse(a.begin(), a.end());     if (s % 2 == 1) {       cout <<  NO  << endl;       return 0;     }     if (a[0] <= s / 2) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 160;   const int mod = 1e9 + 7;   int n, m, f[N][N][2][2], ans;   void inc(int& a, int b) {     if (a += b, a >= mod) a -= mod;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; ++i)       for (int j = i; j <= m; ++j) {         f[i][j][1][1] = 1;       }     for (int h = 1; h <= n; ++h) {       int tot = 0;       for (int i = 1; i <= m; ++i)         for (int j = 1; j <= m; ++j)           for (int kl = 0; kl <= 1; ++kl)             for (int kr = 0; kr <= 1; ++kr) {               inc(tot, f[i][j][kl][kr]);             }       inc(ans, (long long)tot * (n + 1 - h) % mod);       if (h == n) break;       for (int j = 1; j <= m; ++j)         for (int i = 1; i < j; ++i)           for (int kr = 0; kr <= 1; ++kr) {             inc(f[i + 1][j][0][kr], (f[i][j][0][kr] + f[i][j][1][kr]) % mod);           }       for (int i = 1; i <= m; ++i)         for (int j = m; j > i; --j)           for (int kl = 0; kl <= 1; ++kl) {             inc(f[i][j - 1][kl][0], (f[i][j][kl][0] + f[i][j][kl][1]) % mod);           }       for (int j = 2; j <= m; ++j)         for (int i = j; i > 1; --i)           for (int kr = 0; kr <= 1; ++kr) {             inc(f[i - 1][j][1][kr], f[i][j][1][kr]);           }       for (int i = 1; i <= m - 1; ++i)         for (int j = i; j < m; ++j)           for (int kl = 0; kl <= 1; ++kl) {             inc(f[i][j + 1][kl][1], f[i][j][kl][1]);           }     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1e5 + 5;   char a[MAX_N];   int main() {     int N;     cin >> N;     scanf( %s , a + 1);     int cnt = 0;     for (int i = 1; i <= N; i++) {       if (a[i] ==  S  && a[i] >= 2 && a[i - 1] ==  G ) {         cnt++;       }     }     if (a[N] ==  G ) cnt++;     int len = 0, prelen = (cnt >= 2), ans = 0;     for (int i = 1; i <= N; i++) {       if (a[i] ==  G ) {         len++;         ans = max(ans, len + prelen);       }       if (a[i] ==  S ) {         if (2 <= i && i <= N - 1 && a[i - 1] ==  G  && a[i + 1] ==  G ) {           if (cnt == 2) {             prelen = len;           } else if (cnt >= 3) {             prelen = len + 1;           }         } else {           prelen = (cnt >= 2);         }         len = 0;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double EPS = 1e-10;   const long double INF = (int)1e9 + 34;   const int N = (int)1e6 + 34;   void ret(int x) {     cout << x;     exit(0);   }   int n, k;   int a[N];   int b[N], len;   bool u[N];   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) scanf( %d , a + i);     srand(3431);     sort(a, a + n);     a[n] = 100000000;     int lst = a[0];     b[len++] = a[0];     for (int i = 1; i < n; i++)       if (a[i + 1] - lst >= k) {         b[len++] = lst = a[i];       }     int mn = a[0];     for (int i = 0; i < n; i++) mn = min(mn, a[i]);     vector<int> v;     for (int i = 0; i < 30; i++) v.push_back(a[abs((rand() << 16) ^ rand()) % n]);     for (int i = 1; i <= 1000000; i++)       for (int j = 0; !u[i] && j < (int)v.size(); j++)         if (v[j] % i > k) u[i] = true;     int l1 = -1;     int pr;     bool fail;     for (int d = mn; d >= 0; d--) {       if (u[d]) continue;       fail = false;       for (int i = 0; !fail && i < len; i++)         if (b[i] % d > k) fail = true;       if (!fail) {         pr = d;         break;       }       l1 = d;     }     for (int d = pr; d >= 0; d--) {       if (u[d]) continue;       fail = false;       for (int i = n - 1; !fail && i >= 0; i--)         if (a[i] % d > k) fail = true;       if (!fail) {         pr = d;         break;       }       l1 = d;     }     cout << pr;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     long long n, cnt1 = 0, cnt2 = 0, l, r;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> l >> r;       cnt1 += l;       cnt2 += r;     }     cout << min(cnt1, n - cnt1) + min(cnt2, n - cnt2);   }


#include <bits/stdc++.h>   using namespace std;   long long int Mmax(long long int a, long long int b) {     if (a > b) return a;     return b;   }   long long int Mmin(long long int a, long long int b) {     if (a < b) return a;     return b;   }   long long int nod(long long int a, long long int b) {     while (a && b) {       if (a > b)         a %= b;       else         b %= a;     }     return Mmax(a, b);   }   long long int nok(long long int a, long long int b) {     return a * b / nod(a, b);   }   bool IsPrime(long long int x) {     if (x < 2) return false;     long long int X = sqrt(x), i;     for (i = 2; i <= X; i++)       if (x % i == 0) return false;     return true;   }   void hanoi(int n, int A, int C, int B) {     if (n == 1) {       cout << n <<     << A <<     << C << endl;     } else {       hanoi(n - 1, A, B, C);       cout << n <<     << A <<     << C << endl;       hanoi(n - 1, B, C, A);     }   }   string pr2(string a, int d) {     if (d == 0) return  0 ;     string b;     long long int sz = a.size(), i, prenos = 0;     for (i = 0; i < sz; i++) {       b[i] = a[i];     }     for (i = sz - 1; i > -1; i--) {       a[i] = ((b[i] -  0 ) * d + prenos) % 10 +  0 ;       prenos = ((b[i] -  0 ) * d + prenos) / 10;     }     if (prenos) a = char(prenos +  0 ) + a;     return a;   }   string sum(string a, string b) {     bool carry = false;     long long int i, sz1, sz2, maxsz, minsz;     string c, d;     sz1 = a.size();     sz2 = b.size();     maxsz = max(sz1, sz2);     minsz = min(sz1, sz2);     while (sz1 < maxsz) {       sz1++;       a =  0  + a;     }     while (sz2 < maxsz) {       sz2++;       b =  0  + b;     }     for (i = maxsz - 1; i > -1; i--) {       d = char((a[i] + b[i] - 96 + carry) % 10 + 48) + d;       if (a[i] + b[i] - 96 + carry > 9)         carry = true;       else         carry = false;     }     if (carry == true) d = char( 1 ) + d;     return d;   }   string pr(string a, string b) {     string res =  0 , p, p2;     int sz = a.size(), x = 0;     for (sz = a.size(); sz > 0; sz--, x++) {       int d = a[sz - 1] -  0 ;       a = a.erase(sz - 1, 1);       p2 = pr2(b, d);       p2 += p;       res = sum(res, p2);       p +=  0 ;     }     return res;   }   bool vesokosna(long long int x) {     return (x % 4 == 0 && x % 100 || x % 400 == 0);   }   long long int reverse(long long int x) {     long long int mirror = 0;     while (x) {       mirror = mirror * 10 + x % 10;       x /= 10;     }     return mirror;   }   long long int ost(string x, long long int k) {     long long int num = 0, i, sz = x.size();     for (i = 0; i < sz; i++) {       num = num * 10;       num += x[i] -  0 ;       num %= k;     }     return num;   }   bool can[128][128];   vector<string> ans;   int main() {     char last;     int k, i, j, sz2 = 1;     cin >> k;     string q;     cin >> q;     int sz = q.size();     if (sz < k) {       cout <<  NO n ;       return 0;     }     string help;     help += q[0];     ans.push_back(help);     last = q[0];     for (i = 1; i < sz; i++) {       if (sz2 == k) break;       bool can = true;       ;       for (j = 0; j < sz2; j++)         if (q[i] == ans[j][0]) can = false;       if (can) {         string help;         help += q[i];         last = q[i];         ans.push_back(help);         sz2++;       } else         ans.back() += q[i];     }     if (sz2 == k) {       cout <<  YES n ;       for (; i < sz; i++) {         ans.back() += q[i];       }       for (i = 0; i < sz2; i++) cout << ans[i] << endl;       return 0;     }     cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <ostream& out = cout, class... T>   void prints(T&&...) {}   template <ostream& out = cout, class... T>   void printe(T&&...) {}   template <ostream& out = cout, class... T>   void printw(T&&...) {}   template <ostream& out = cout, class... T>   void printew(T&&...) {}   template <ostream& out = cout, class... T>   void printb(T&&...) {}   template <ostream& out = cout, class... T>   void printd(T&&...) {}   template <ostream& out = cout, class... T>   void printde(T&&...){};   template <class T>   istream& operator>>(istream& in, vector<T>& v) {     for (auto& e : v) {       in >> e;     }     return in;   }   int main() {     int n;     cin >> n;     vector<char> s(n);     cin >> s;     int k = 0;     bool pr;     for (int i = 0; i < n; i++) {       if (s[i] ==  1 ) {         k++;         pr = true;       } else {         break;       }     }     if (k == n) {       cout <<  YES ;       return 0;     }     int l = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  0 ) {         l++;         pr = false;       } else {         break;       }     }     if (l == n) {       cout <<  YES ;       return 0;     }     int m;     m = max(l, k);     for (int i = 0; i < n; i = i + m) {       if (s[i] ==  1  && pr) {         for (int j = 0; j < m; j++) {           if (s[j + i] !=  1 ) {             cout <<  NO ;             return 0;           }         }         pr = false;         continue;       }       if (s[i] ==  0  && !pr) {         for (int j = 0; j < m; j++) {           if (s[j + i] !=  0 ) {             cout <<  NO ;             return 0;           }         }         pr = true;         continue;       }       cout <<  NO ;       return 0;     }     cout <<  YES ;   }


#include <bits/stdc++.h>   using namespace std;   const int nax = 505;   int n;   char grid[nax][nax];   int cc[nax][nax];   int cc_size[nax * nax];   int when_added[nax * nax];   const int dx[4] = {-1, 1, 0, 0};   const int dy[4] = {0, 0, -1, 1};   const char EMPTY =  . ;   bool inside(int x, int y) { return 0 <= min(x, y) && max(x, y) < n; }   void dfs(int x, int y, int which_cc) {     cc[x][y] = which_cc;     ++cc_size[which_cc];     for (int i = 0; i < 4; ++i) {       int x2 = x + dx[i];       int y2 = y + dy[i];       if (inside(x2, y2) && grid[x2][y2] == EMPTY && cc[x2][y2] == 0)         dfs(x2, y2, which_cc);     }   }   void add(int x, int y, int& answer, int current_time) {     if (inside(x, y) && grid[x][y] == EMPTY) {       int id = cc[x][y];       if (when_added[id] != current_time) {         when_added[id] = current_time;         answer += cc_size[id];       }     }   }   int main() {     int k;     scanf( %d%d , &n, &k);     for (int i = 0; i < n; ++i) scanf( %s , grid[i]);     int how_many_cc = 0;     for (int x = 0; x < n; ++x)       for (int y = 0; y < n; ++y)         if (grid[x][y] == EMPTY && cc[x][y] == 0) dfs(x, y, ++how_many_cc);     int cur_time = 1;     int best_answer = 0;     for (int y_low = 0; y_low + k <= n; ++y_low) {       for (int x = 0; x < k; ++x)         for (int y = y_low; y < y_low + k; ++y) --cc_size[cc[x][y]];       for (int x_low = 0; x_low + k <= n; ++x_low) {         int answer = k * k;         for (int x = x_low; x < x_low + k; ++x) {           add(x, y_low - 1, answer, cur_time);           add(x, y_low + k, answer, cur_time);         }         for (int y = y_low; y < y_low + k; ++y) {           add(x_low - 1, y, answer, cur_time);           add(x_low + k, y, answer, cur_time);         }         ++cur_time;         best_answer = max(best_answer, answer);         if (x_low + k != n) {           for (int y = y_low; y < y_low + k; ++y) {             ++cc_size[cc[x_low][y]];             --cc_size[cc[x_low + k][y]];           }         }       }       for (int x = n - k; x < n; ++x)         for (int y = y_low; y < y_low + k; ++y) ++cc_size[cc[x][y]];     }     printf( %d , best_answer);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1000000000;   const int maxn = 100010;   int a[maxn];   int max(int a, int b) { return a > b ? a : b; }   int min(int a, int b) { return a > b ? b : a; }   int main() {     int n, l, r, i, j;     string s;     while (cin >> n) {       for (i = 0; i < n; i++) cin >> a[i];       cin >> s;       l = -inf, r = inf;       for (i = 4; i < n; i++) {         if (s[i] ==  1 ) {           int maxi = -inf;           for (j = i; j >= i - 4; j--) {             maxi = max(maxi, a[j]);           }           int cnt = 0;           for (j = i; j >= i - 4; j--) {             if (s[j] ==  0 ) cnt++;           }           if (cnt == 4) {             l = max(l, maxi + 1);           }         } else if (s[i] ==  0 ) {           int mina = inf;           for (j = i; j >= i - 4; j--) {             mina = min(mina, a[j]);           }           int cnt = 0;           for (j = i; j >= i - 4; j--) {             if (s[j] ==  1 ) cnt++;           }           if (cnt == 4) {             r = min(r, mina - 1);           }         }       }       cout << l <<     << r << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long i, j, k, n, v[200010], m, a, b, x, y, h, w, l, p, ans, numitor, aux,       mini, sum, poz;   string s1, s2, second;   char c;   map<long long, long long> mip;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> x;     for (long long i = 1; i <= n; i++) {       cin >> v[i];       if (v[i] < x)         v[i] = -1;       else if (v[i] > x)         v[i] = 1;       else {         v[i] = 0;         poz = i;       }     }     mip[0] = 1;     sum = 0;     for (long long i = 1; i <= n; i++) {       sum += v[i];       if (i >= poz) {         if (mip.find(sum) != mip.end()) ans += mip[sum];         if (mip.find(sum - 1) != mip.end()) ans += mip[sum - 1];       } else {         mip[sum] += 1;         v[i] = sum;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, ex, ey, sx[N], sy[N];   char s[N];   inline bool check(int m) {     for (int i = 1; i + m - 1 <= n; i++) {       int decx = sx[n] - sx[i + m - 1] + sx[i - 1];       int decy = sy[n] - sy[i + m - 1] + sy[i - 1];       int nedx = ex - decx;       int nedy = ey - decy;       if (abs(nedx) + abs(nedy) <= m && !(m - abs(nedx) - abs(nedy) & 1))         return 1;     }     return 0;   }   int main() {     scanf( %d%s%d%d , &n, s + 1, &ex, &ey);     for (int i = 1; i <= n; i++) {       sx[i] = sx[i - 1] + (s[i] ==  L  ? -1 : (s[i] ==  R  ? 1 : 0));       sy[i] = sy[i - 1] + (s[i] ==  D  ? -1 : (s[i] ==  U  ? 1 : 0));     }     int l = 0, r = n, mid, ans = -1;     while (l <= r) {       mid = l + r >> 1;       if (check(mid)) {         ans = mid;         r = mid - 1;       } else {         l = mid + 1;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, i, j, x, y = 0, w, z = 0, e;     cin >> a >> b >> c >> d;     if (d % c != 0) {       cout << 0;       return 0;     }     w = d / c;     if (c == d) {       if (c >= a && c <= b)         cout << 1;       else         cout << 0;       return 0;     }     for (i = 1; i <= sqrt(w); i++) {       if (w % i == 0) {         x = w / i;         e = 0;         for (j = 2; j <= i; j++) {           if (i % j == 0 && x % j == 0) {             e = 1;             break;           }         }         if (e == 0) {           if (i * c >= a && i * c <= b && x * c >= a && x * c <= b) y++;         }       }     }     cout << y * 2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 5;   int tree[4 * MAXN], n, m, a[MAXN], size = 0, less1[MAXN];   vector<int> del, nums;   void initialize(int l, int r, int node) {     tree[node] = r - l + 1;     if (r == l) return;     int mid = (l + r) / 2;     initialize(l, mid, 2 * node);     initialize(mid + 1, r, 2 * node + 1);   }   int elim(int node) {     while (node >= 1) {       tree[node]--;       node /= 2;     }   }   void find(int l, int r, int sum, int node) {     if (l == r) {       nums[l] = -2;       elim(node);       return;     }     int mid = (l + r) / 2;     if (tree[2 * node] >= sum)       find(l, mid, sum, 2 * node);     else       find(mid + 1, r, sum - tree[2 * node], 2 * node + 1);   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m;     for (int i = 0; i < m; ++i) {       cin >> a[i];     }     for (int i = 0; i < MAXN; ++i) less1[i] = 0;     for (int i = 0; i < m - 1; ++i)       for (int k = a[i]; k < a[i + 1]; ++k) less1[k] = i + 1;     for (int i = a[m - 1]; i < MAXN; ++i) less1[i] = m;     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       if (x == -1) {         del.push_back(less1[size]);         size -= less1[size];       } else {         nums.push_back(x);         size++;       }     }     if (nums.size() == 0) {       cout <<  Poor stack!  << endl;       return 0;     }     initialize(0, nums.size() - 1, 1);     for (int i = 0; i < del.size(); ++i)       for (int j = del[i] - 1; j >= 0; --j) find(0, nums.size() - 1, a[j], 1);     int ct = 0;     for (int i = 0; i < nums.size(); ++i) {       if (nums[i] != -2) {         cout << nums[i];         ++ct;       }     }     if (ct == 0) cout <<  Poor stack! ;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long INFF = 0x3f3f3f3f3f3f3f3f;   const double pi = acos(-1.0);   const double eps = 1e-9;   const long long mod = 1e9 + 7;   int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch< 0  | ch>  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   void Out(int aa) {     if (aa > 9) Out(aa / 10);     putchar(aa % 10 +  0 );   }   int n, t;   int f[55], s[55], p[55];   double dp[55][5005];   bool check(double mid) {     for (int i = n; i >= 1; i--) {       for (int j = t + 1; j <= 5000; j++) dp[i + 1][j] = mid;       for (int j = 0; j <= t; j++) {         double t1 = (dp[i + 1][j + f[i]] + f[i]) * p[i] / 100;         double t2 = (dp[i + 1][j + s[i]] + s[i]) * (100 - p[i]) / 100;         dp[i][j] = min(mid, t1 + t2);       }     }     return dp[1][0] < mid;   }   int main() {     n = read(), t = read();     for (int i = 1; i <= n; i++) f[i] = read(), s[i] = read(), p[i] = read();     double l = 0, r = 1e12;     for (int i = 0; i < 100; i++) {       double mid = (l + r) / 2;       if (check(mid))         r = mid;       else         l = mid;     }     printf( %.10f n , l);     return 0;   }


#include <iostream>   #include <vector>   #include <algorithm>      using namespace std;      #define int long long      void solve() {       int n;       vector<long long> vect;       cin >> n;       for (int i = 0; i < n; i++) {           long long x;           cin >> x;           vect.push_back(x);       }       sort(vect.begin(), vect.end());       long long res = 0;       long long now = 0;       for (int i = n - 2; i >= 0; i--) {           res -= now - (n - i - 2) * vect[i];           now += vect[i + 1];       }       cout << res <<   n ;   }      signed main()   {       ios_base::sync_with_stdio(false);       cin.tie(nullptr);       int t;       cin >> t;       for (int i = 0; i < t; i++)           solve();       return 0;   }


// Problem : B. Tree Array   // Contest : Codeforces - Codeforces Round #728 (Div. 1)   // URL : https://codeforces.com/contest/1540/problem/B   // Memory Limit : 256 MB   // Time Limit : 2000 ms   // Powered by CP Editor (https://github.com/cpeditor/cpeditor)      #include <bits/stdc++.h>      using namespace std;      int N;   long long pas[205][205];   const long long MOD = 1e9+7;   long long cache[205][205];   vector<int> graph[205];   int par[205];   bool vis[205];      long long add(long long a, long long b){    return (a + b) % MOD;   }      long long mult(long long a, long long b){    return a * b % MOD;   }      long long qikpow(long long b, long long e){    if(!e){     return 1;    }    long long ret = qikpow(b, e / 2);    ret = mult(ret, ret);    if(e & 1){     ret = mult(ret, b);    }    return ret;   }      long long sub(long long a, long long b){    return ((a - b) % MOD + MOD ) % MOD;   }      long long divd(long long a, long long b){    return mult(a, qikpow(b, MOD - 2));   }      void dfs1(int n){    for(int e : graph[n]){     if(e != par[n]){      par[e] = n;      dfs1(e);     }    }   }      int dfs2(int n, int p){    int sz = 1;    for(int e : graph[n]){     if(!vis[e] && p != e){      sz += dfs2(e, n);     }    }    return sz;   }      int main(){    ios::sync_with_stdio(0);    cin.tie(0);    cout.tie(0);    cin >> N;    for(int i = 0; i <= N; i++){     pas[i][0] = 1;     for(int j = 1; j <= i; j++){      pas[i][j] = add(pas[i-1][j], pas[i-1][j-1]);     }    }     for(int i = 1; i < N; i++){     int a, b;     cin >> a >> b;     graph[a].emplace_back(b);     graph[b].emplace_back(a);    }    long long ans = 0;    for(int n = 1; n <= N; n++){     fill(par, par+1+N, 0);     dfs1(n);     vis[n] = 1;     for(int k = n+1; k <= N; k++){      int cur = k, len = 0;      while(cur != n){       vis[cur] = 1;       len++;       cur = par[cur];      }      cur = k;      for(int t = len; t; t--){       int s = dfs2(cur, 0);       //cout << s <<   n ;       long long tot = divd(s, N);       if(t == len){        ans = add(ans, tot);       }       else{        /*        long long p = 1;//qikpow(divd(1, 2), len);             cout << p <<     << pas[len - 1][len - t] <<   n ;        p = mult(p, divd(pas[len - 1][len - t], pas[len][len-t]));        cout << n <<     << k <<     << cur <<   n ;        cout << p <<     << tot <<   n ;        ans = add(ans, mult(p, tot));        */        //cout << n <<     << k <<     << cur <<   n ;        //cout << tot <<   n ;        if(!cache[len][t]){         for(int c = 0; c < t; c++){          cache[len][t] = add(cache[len][t], mult(pas[c+len-t-1][len-t-1], qikpow(divd(1, 2), c+len-t)));          //cout << mult(mult(pas[c+len-t-1][len-t-1], qikpow(divd(1, 2), c+len-t)), tot) <<   n ;         }          }        ans = add(mult(tot, cache[len][t]), ans);               }       cur = par[cur];      }      cur = k;      while(cur != n){       vis[cur] = 0;       cur = par[cur];      }     }     vis[n] = 0;    }    cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int a = 0;     char c = getchar();     bool f = 0;     while (!isdigit(c)) {       f = c ==  - ;       c = getchar();     }     while (isdigit(c)) {       a = a * 10 + c - 48;       c = getchar();     }     return f ? -a : a;   }   const int _ = 1e5 + 11;   vector<int> nxt[_][2];   int N, C[_], ans;   long long num;   void addEd(int a, int b, int c) { nxt[a][c].push_back(b); }   int deg[_], dst[_], seq[_], cseq;   unsigned long long arr[_][50];   void build(int fir) {     memset(deg, 0, sizeof(deg));     cseq = 0;     for (int i = 1; i <= N + 8; ++i) {       for (auto t : nxt[i][0]) deg[t] += dst[t] == dst[i];       for (auto t : nxt[i][1]) deg[t] += dst[t] == dst[i] + 1;     }     queue<int> q;     q.push(fir);     while (!q.empty()) {       int t = q.front();       q.pop();       seq[++cseq] = t;       for (int l = 0; l < 2; ++l)         for (auto p : nxt[t][l])           if (dst[p] == dst[t] + l && !--deg[p]) q.push(p);     }   }   void solve(int size, vector<int> node, int fir, int mx) {     memset(arr, 0, sizeof(arr));     for (int i = 0; i < node.size(); ++i)       arr[node[i]][i >> 6] |= 1ull << (i & 63);     for (int i = 1; i <= cseq; ++i) {       int t = seq[i];       for (int l = 0; l < 2; ++l)         for (auto p : nxt[t][l])           if (dst[p] == dst[t] + l)             for (int r = 0; r < 50; ++r) arr[p][r] |= arr[t][r];     }     long long cnt = 0;     int val = node.size();     for (int i = 1; i <= N && val == node.size(); ++i)       if (dst[i] == mx) {         int num = 0;         for (int j = 0; j < 50; ++j) {           num += __builtin_popcountll(arr[i][j]);         }         val = min(val, num);       }     if (val == node.size()) --mx;     for (int i = 1; i <= N; ++i)       if (dst[i] > mx)         cnt += node.size();       else if (dst[i] == mx) {         int num = 0;         for (int j = 0; j < 50; ++j) {           num += __builtin_popcountll(arr[i][j]);         }         cnt += node.size() - num;       }     if (ans < mx) {       ans = mx;       num = 0;     }     if (ans == mx) num += cnt;   }   int main() {     ios::sync_with_stdio(0);     cin >> N;     for (int i = 1; i <= N; ++i) {       char c;       cin >> c;       C[i] = c -  a  + 1;       addEd(i, N + C[i], 0);       addEd(N + C[i], i, 1);     }     for (int i = 2; i <= N; ++i) {       addEd(i - 1, i, 1);       addEd(i, i - 1, 1);     }     for (int i = 1; i <= 8; ++i) {       memset(dst, 0x3f, sizeof(dst));       dst[N + i] = 0;       deque<int> q;       q.push_back(N + i);       int mx = 0;       while (!q.empty()) {         int t = q.front();         q.pop_front();         if (t <= N) mx = max(mx, dst[t]);         for (auto r : nxt[t][0])           if (dst[r] > dst[t]) {             dst[r] = dst[t];             q.push_front(r);           }         for (auto r : nxt[t][1])           if (dst[r] > dst[t] + 1) {             dst[r] = dst[t] + 1;             q.push_back(r);           }       }       vector<int> node;       build(N + i);       for (int j = 1; j <= N; ++j)         if (C[j] == i) {           node.push_back(j);           if (node.size() == 64 * 50) {             solve(64 * 50, node, N + i, mx);             node.clear();           }         }       if (node.size()) solve(node.size(), node, N + i, mx);     }     cout << ans <<     << num / 2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int64_t ans, n, k, m, r[100005];   char s[100005], t[100005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int64_t tt;     cin >> tt;     while (tt--) {       cin >> n;       cin >> s;       cin >> t;       vector<int> ans;       m = n - 1;       int i = 0, j = n - 1;       while (i < j) {         r[m--] = i;         i++;         r[m--] = j;         j--;       }       if (i == j) r[m] = i;       m = 0;       for (int i = n - 1; i >= 0; i--) {         if ((s[r[i]] -  0  + m) % 2 == t[i] -  0 ) ans.push_back(1);         ans.push_back(i + 1);         m++;       }       cout << (int)ans.size() <<    ;       for (auto i : ans) cout << i <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> a;   int k, t, n, mx;   string s;   int main() {     cin >> n >> k;     cin >> s;     for (int i = 0; i < s.size(); i++)       if (s[i] ==  . ) a.push_back(i);     for (int i = 0; i < a.size() - 1; i++) mx = max(mx, a[i + 1] - a[i]);     if (mx > k)       cout <<  NO ;     else       cout <<  YES ;   }


#include <bits/stdc++.h>   using namespace std;   int w;   long long n, k;   pair<long long, long long> o = {0, 0};   pair<long long, long long> csop(long long kezd, long long kim) {     long long sum = 0, kov = kezd + k;     if (kezd <= kim && kim <= kov) {       kov++;     }     sum = (kov - kezd) * (kov - kezd - 1) / 2;     if (log(k) + log(kezd) < 42.0) {       sum += kezd * (kov - kezd);     } else {       sum = 2e18;     }     if (kezd <= kim && kim < kov) {       sum -= kim;     }     return {sum, kov};   }   pair<long long, long long> calc(long long ert) {     if (ert <= k * (k + 1) / 2) {       return {1, k * (k + 1) / 2};     }     long long kis = ert / k - k / 2;     auto s = calc(kis);     long long fi = s.first, se = s.second;     long long s2 = kis, kor = 0, ert2 = 0;     s2 -= (fi - 1) * (k + 1), kor += fi - 1, ert2 = (fi - 1) * (k + 1);     long long ss = (s2 + k - 2) / k;     kor += ss, ert2 += ss * k;     ert2++, kor++;     if (ert2 >= se) {       ert2++;     }     auto cs = csop(ert2, se);     if (cs.first < ert) {       ert2 = cs.second, kor++;       cs = csop(ert2, se);     }     return {kor, cs.first};   }   int main() {     ios_base::sync_with_stdio(false);     cin >> w;     while (w--) {       cin >> n >> k;       if (n <= k) {         cout << n <<   n ;         continue;       }       if (k == 2 && n <= 5) {         cout << n <<   n ;         continue;       }       auto s = calc(n);       if (s.second == n) {         cout << s.first * (k + 1) <<   n ;       } else {         long long fi = s.first, ans = fi * (k + 1);         n -= fi * (k + 1) - 1;         ans += (k + 1) * (n / k) + n % k;         if (n % k == 0) {           ans--;         }         cout << ans <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cl[5000010], cr[5000010], ld[5000010], sl = 1;   bool yz[5000010];   void pushd(int x) {     if (cl[x] == 0) {       cl[x] = ++sl;       yz[cl[x]] = 1;     }     if (cr[x] == 0) {       cr[x] = ++sl;       yz[cr[x]] = 1;     }     yz[x] = 0;     if (ld[x] == 0) return;     ld[cl[x]] = ld[cr[x]] = ld[x];     ld[x] = 0;   }   vector<int> cf[50010], ve[5000010];   void addqj(int i, long long l, long long r, long long L, long long R, int x) {     if (R <= l || r <= L) return;     if (L <= l && r <= R) {       ld[i] = x;       cf[x].push_back(i);       return;     }     long long m = (l + r) >> 1;     pushd(i);     addqj(cl[i], l, m, L, R, x);     addqj(cr[i], m, r, L, R, x);   }   void link(int x, int y) {     if (yz[x] && yz[y]) {       if (ld[x] < ld[y])         ve[x].push_back(y);       else         ve[y].push_back(x);       return;     }     link(yz[x] ? x : cl[x], yz[y] ? y : cl[y]);     link(yz[x] ? x : cr[x], yz[y] ? y : cr[y]);   }   int find(int i, long long l, long long r, long long x) {     if (yz[i]) return i;     long long m = (l + r) >> 1;     return x < m ? find(cl[i], l, m, x) : find(cr[i], m, r, x);   }   int lx[50010], fa[5000010], ans[50010];   long long A[50010], B[50010];   int getv(int x) { return x == fa[x] ? x : fa[x] = getv(fa[x]); }   void merge(int x, int y) {     x = getv(x);     y = getv(y);     if (x != y) fa[x] = y;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     ld[1] = m + 1;     yz[1] = 1;     for (int i = 1; i <= m; i++) {       char zf[10];       scanf( %s%lld%lld , zf, &A[i], &B[i]);       lx[i] = zf[0] ==  b  ? 0 : 1;       if (lx[i] == 0) addqj(1, 0, (1ll << n), A[i], B[i] + 1, i);     }     for (int i = 1; i <= sl; i++) {       fa[i] = i;       if (!yz[i]) link(cl[i], cr[i]);     }     for (int i = 1; i <= sl; i++) {       if (ld[i] != m + 1) continue;       for (int j = 0; j < ve[i].size(); j++) merge(i, ve[i][j]);     }     for (int i = m; i >= 1; i--) {       if (lx[i])         ans[i] = (getv(find(1, 0, (1ll << n), A[i])) ==                   getv(find(1, 0, (1ll << n), B[i])));       else {         for (int x = 0; x < cf[i].size(); x++) {           int u = cf[i][x];           for (int y = 0; y < ve[u].size(); y++) merge(u, ve[u][y]);         }       }     }     for (int i = 1; i <= m; i++) {       if (lx[i]) printf( %d n , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 15;   long long Get_Num(int num[], int b, int n) {     long long number = 0;     long long in = 1;     for (int i = n - 1; i >= 0; i--) {       number += num[i] * in;       in = in * b;     }     return number;   }   int main() {     int x[N], y[N];     int b;     int n;     long long X, Y;     cin >> n >> b;     for (int i = 0; i < n; i++) {       cin >> x[i];     }     X = Get_Num(x, b, n);     cin >> n >> b;     for (int i = 0; i < n; i++) {       cin >> y[i];     }     Y = Get_Num(y, b, n);     if (X == Y) {       printf( = n );     } else if (X > Y) {       printf( > n );     } else {       printf( < n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long n, m;       cin >> n >> m;       long sum = 0;       if (n == 1 || n == 2) {         if (n == 1)           cout << 0 << endl;         else           cout << m << endl;       } else {         cout << 2 * m << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   long long n, m;   int k;   int mpow(int a, long long b) {     int c = 1;     for (; b; b >>= 1, a = 1ll * a * a % mod)       if (b & 1) c = 1ll * c * a % mod;     return c;   }   int main() {     scanf( %lld%lld%d , &n, &m, &k);     if ((n + m) & 1)       if (k == -1) {         printf( 0 n );         return 0;       }     int tmp = mpow(2, n - 1);     printf( %d n , mpow(tmp, m - 1));   }


#include <bits/stdc++.h>   using namespace std;   int tt(char p) {     int s;     if (p ==  > )       s = 8;     else if (p ==  < )       s = 9;     else if (p ==  + )       s = 10;     else if (p ==  - )       s = 11;     else if (p ==  . )       s = 12;     else if (p ==  , )       s = 13;     else if (p ==  [ )       s = 14;     else       s = 15;     return s;   }   int main() {     string x;     int t = 0;     int q = x.length() - 1;     cin >> x;     for (int i = 0; i < x.length(); ++i) {       t = (t * 16 + tt(x[i])) % 1000003;     }     cout << t;     return 0;   }


#include <bits/stdc++.h>   template <typename T>   inline T MIN(T a, T b) {     return a < b ? a : b;   }   template <typename T>   inline T MAX(T a, T b) {     return a > b ? a : b;   }   using namespace std;   void reop() { freopen( input.txt ,  r , stdin); }   int a[100001] = {0};   int ans = 0, curans = 0;   bool test(int div, int n, int start) {     int prev = start;     for (int i = 2; i < n; ++i) {       if (a[i] == prev + div)         prev = a[i];       else if (a[i] + 1 == prev + div) {         prev = a[i] + 1;         curans++;       } else if (a[i] - 1 == prev + div) {         prev = a[i] - 1;         curans++;       } else         return false;     }     ans = MIN(ans, curans);     return true;   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     if (n == 1 || n == 2) {       cout << 0;       return 0;     }     ans = 1000000007;     for (int i = -1; i <= 1; ++i) {       for (int j = -1; j <= 1; ++j) {         curans = 0;         int div = a[1] + j - (a[0] + i);         if (j) curans++;         if (i) curans++;         test(div, n, a[1] + j);       }     }     cout << (ans == 1000000007 ? -1 : ans);     return 0;   }


#include<bits/stdc++.h>   #define int long long   #define pii pair<int,int>   #define F first   #define S second   #define pi acos(-1.0)   #define pb push_back   #define sf(x) scanf( %lld ,&x)   #define pf(x) printf( %lld ,&x)   using namespace std;   const int mod=1e9+7;   int a1[2000],ar[2000],ff[2000] ;   map<int,int>mp,mk ;   int bigmod(int a , int b)   {       if(b==0) return 1 ;       int x = bigmod(a,b/2) ;       x=((x%mod)*(x%mod))%mod ;       if(b%2) x=((x%mod)*(a%mod))%mod ;       return x ;   }   int ncr(int a , int b)   {       int p=(ff[a-b]*ff[b])%mod ;       p=(ff[a]*bigmod(p,mod-2)) ; p%=mod ;       return p ;   }   int32_t main()   {       ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;       ff[0]=1 ; ff[1]=1 ;       for(int i = 2 ; i <= 1000 ; i++) ff[i]=(ff[i-1]*i)%mod ;       int t ; cin>>t ;       while(t--)       {           int n,k,mx=0 ; cin>>n>>k ; mp.clear() ; mk.clear() ;           set<int>st ;           for(int i = 1 ; i <= n ; i++){cin>>ar[i] ; mp[ar[i]]++ ; a1[i]=ar[i] ; }           sort(a1+1,a1+n+1) ; reverse(a1+1,a1+n+1) ;          // for(int i = 1 ; i <= n ; i++) cout<<a1[i]<<    ; cout<<endl ;           for(int i = 1 ; i <= k ; i++) {mx+=a1[i] ; st.insert(a1[i]) ; mk[a1[i]]++ ;}           int ans=1 ;           for(int x : st)           {               int p=mp[x],q=mk[x] ;             //  cout<<x<<   <<p<<   <<q<<endl ;               ans*=ncr(p,q); ans%=mod ;           }           cout<<ans<<endl ;       }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 2, M = 1e9 + 7;   int tt = 1, n, k;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> tt;     while (tt--) {       cin >> n;       if (n == 1) {         cout <<  a n ;         continue;       }       string second =   , ans =   ;       for (int i = 0; i < n / 2 - 1; i++) second +=  a ;       ans +=  a  + second +  b  + second;       if (n & 1) ans +=  c ;       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 7;   const long long inf = 1e17 + 7;   pair<long long, long long> a[maxn];   pair<long long, long long> A[maxn];   pair<pair<long long, long long>, pair<long long, long long> > S[maxn];   int pos;   inline long long elf(pair<long long, long long> z, long long x) {     return z.first * x + z.second;   }   inline long long earl(pair<long long, long long> z, long long v) {     long long a = z.first, b = z.second;     long long x = (v - b) / a;     if (a * x >= v - b) return x;     return x + 1;   }   inline long double intx(pair<long long, long long> l1,                           pair<long long, long long> l2) {     long long a1 = l1.first, a2 = l2.first, b1 = l1.second, b2 = l2.second;     return (long double)(b2 - b1) / (long double)(a1 - a2);   }   void ins(long long a, long long b) {     while (pos >= 2 && intx(S[pos].first, S[pos - 1].first) >=                            intx(make_pair(a, b), S[pos].first))       pos--;     S[pos].second.second = ceil(intx(S[pos].first, make_pair(a, b))) - 1;     pos++;     S[pos] =         make_pair(make_pair(a, b),                   make_pair(ceil(intx(S[pos - 1].first, make_pair(a, b))), inf));   }   int main() {     int n;     long long s;     scanf( %d %lld , &n, &s);     for (int i = 1; i <= n; i++) {       scanf( %lld %lld , &a[i].first, &a[i].second);     }     sort(a + 1, a + n + 1);     a[0].first = -1;     long long cur = -1;     long long best = inf;     int idx = 0;     for (int i = n; i >= 0; i--) {       if (a[i].first != cur) {         if (cur > 0) {           idx++;           A[idx] = make_pair(cur, best);         }         cur = a[i].first;         best = inf;       }       best = min(best, a[i].second);     }     n = idx;     for (int i = 1; i <= n; i++) a[i] = A[i];     best = inf;     idx = 0;     for (int i = 1; i <= n; i++) {       if (a[i].second >= best) continue;       idx++;       A[idx] = a[i];       best = min(best, a[i].second);     }     n = idx;     reverse(A + 1, A + n + 1);     long long ans = inf;     pos = 1;     S[pos] = make_pair(make_pair(A[1].first, 0), make_pair(0, inf));     int fp = 1;     for (int i = 2; i <= n; i++) {       while (fp < pos && elf(S[fp].first, S[fp].second.second) < A[i].second)         fp++;       long long cx = earl(S[fp].first, A[i].second);       long long fcx = elf(S[fp].first, cx);       ins(A[i].first, fcx - A[i].second - A[i].first * cx);       fp = min(fp, pos);     }     for (int i = 1; i <= pos; i++) {       ans = min(ans, earl(S[i].first, s));     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 3;   const long long int M = 1000000007;   void solve() {     string s;     cin >> s;     int n = s.length();     for (int i = 0; i < n - 1; ++i) {       s +=  0 ;     }     long long int ans = 0;     for (int i = 0; i < 2 * (n - 1) + 1; ++i) {       ans += ans + s[i] -  0 ;       ans %= M;     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     solve(), cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct like {     int id;     int change = 0;   };   int main() {     int n, s, max = 0, idmax = 0, count = 0, k = 0;     cin >> n;     like *A = new like[n];     for (int i = 0; i < n; i++) {       cin >> s;       k = 1;       for (int j = 0; j < count; j++) {         if (A[j].id == s) {           A[j].change++;           k = 0;           if (A[j].change > max) {             max = A[j].change;             idmax = A[j].id;           }         }       }       if (k == 1) {         A[count].id = s;         A[count].change++;         if (A[count].change > max) {           max = A[count].change;           idmax = A[count].id;         }         count++;       }     }     cout << idmax << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int H[100000][5], V[100000][5];   long long dp[32];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 1; i < m; ++i)       for (int j = 0; j < n; ++j) cin >> H[i][j];     for (int i = 0; i < m; ++i)       for (int j = 0; j < n; ++j) cin >> V[i][j];     for (int i = 1; i < (1 << n); ++i) dp[i] = 1e18;     const int sz = 1 << n;     for (int i = 1; i < m; ++i) {       for (int j = 0; j < sz; ++j) {         for (int k = 0; k < n; ++k) {           if (!(j & (1 << k))) {             auto &t = dp[j | (1 << k)];             const auto &nt = dp[j] + H[i][k];             if (nt < t) t = nt;           }         }         for (int k = 0; k < n; ++k) {           if ((((j >> k)) ^ ((j >> ((k + 1) % n)))) & 1) dp[j] += V[i][k];         }       }     }     cout << dp[sz - 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int arr[100000], arr1[100000], arr2[100000];   int main() {     int n, flag = 0;     cin >> n;     multiset<long long int> m;     multiset<long long int>::iterator it;     for (int i = 0; i < n; i++) {       cin >> arr[i];       m.insert(arr[i]);       if (i == 0)         arr1[i] = arr[i];       else         arr1[i] = arr1[i - 1] + arr[i];     }     for (int i = n - 1; i >= 0; i--) {       if (i == n - 1)         arr2[n - 1 - i] = arr[i];       else         arr2[n - 1 - i] = arr2[n - 2 - i] + arr[i];     }     if (arr1[n - 1] % 2 != 0)       cout <<  NO ;     else {       long long int sum = arr1[n - 1] / 2;       it = m.find(arr[0]);       m.erase(it);       if (arr1[0] == sum || arr2[0] == sum) flag = 1;       if (!flag) {         for (int i = 1; i < n - 1; i++) {           if (m.find(sum - arr1[i - 1]) != m.end()) {             flag = 1;             break;           }           if (!flag) {             int low = i + 1, high = n - 1;             while (low < high) {               int mid = low + (high - low + 1) / 2;               if (arr1[mid] - arr1[i] + arr1[i - 1] > sum)                 high = mid - 1;               else                 low = mid;             }             if (arr1[low] - arr1[i] + arr1[i - 1] == sum) {               flag = 1;               break;             }           }           it = m.find(arr[i]);           m.erase(it);         }       }       m.clear();       if (!flag) {         for (int i = 0; i < n; i++) m.insert(arr[i]);         it = m.find(arr[n - 1]);         m.erase(it);         for (int i = 1; i < n - 1; i++) {           if (m.find(sum - arr2[i - 1]) != m.end()) {             flag = 1;             break;           }           int low = i + 1, high = n - 1;           while (low < high) {             int mid = low + (high - low + 1) / 2;             if (arr2[mid] - arr2[i] + arr2[i - 1] > sum)               high = mid - 1;             else               low = mid;           }           if (arr2[low] - arr2[i] + arr2[i - 1] == sum) {             flag = 1;             cout << i << endl;             break;           }           it = m.find(arr[n - 1 - i]);           m.erase(it);         }       }       if (flag)         cout <<  YES ;       else         cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll MOD = 1e9 + 7;   void dfs(int node, vector<vector<pair<int, int>>>& adj, vector<bool>& vu,            ll& cnt) {     for (auto& p : adj[node]) {       if (!vu[p.first] and p.second == 0) {         vu[p.first] = true;         ++cnt;         dfs(p.first, adj, vu, cnt);       }     }   }   ll getPow(ll a, ll p) {     ll ret = 1, cp = a;     while (p) {       if (p & 1) ret = (ret * cp) % MOD;       p >>= 1;       cp = (cp * cp) % MOD;     }     return ret;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, k, a, b, c;     cin >> n >> k;     vector<vector<pair<int, int>>> adj(n + 1);     for (int i = 1; i < n; ++i) {       cin >> a >> b >> c;       adj[a].emplace_back(b, c);       adj[b].emplace_back(a, c);     }     vector<bool> vu(n + 1);     ll ans = getPow(n, k);     for (int i = 1; i <= n; ++i) {       if (!vu[i]) {         ll tmp = 1;         vu[i] = true;         dfs(i, adj, vu, tmp);         ans = (ans - getPow(tmp, k)) % MOD;       }     }     cout << (ans + MOD) % MOD;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, v[5000];   char a[5000][5050];   bool dfs(int x, int from) {     v[x] = 1;     for (int y = 0; y < n; y++)       if (a[x][y] ==  1 ) {         if (!v[y]) {           if (dfs(y, x)) return true;         } else {           if (a[y][from] ==  1 ) {             printf( %d %d %d n , y + 1, from + 1, x + 1);             return true;           }         }       }     return false;   }   int main() {     scanf( %d , &n);     gets(a[0]);     for (int i = 0; i < n; i++) gets(a[i]);     for (int i = 0; i < n; i++)       if (!v[i])         if (dfs(i, -1)) return 0;     puts( -1 );   }


#include <bits/stdc++.h>   const double EPS = 0.0000000001;   const long long mod1 = 998244353;   const long long mod2 = 1000000007;   const long long mod3 = 1000000009;   const long long mod4 = 998244353;   const long long inf = 10000000000000000;   using namespace std;   signed main() {     cin.tie(0);     cout.tie(0);     std::ios_base::sync_with_stdio(0);     long long n, a;     cin >> n >> a;     long long matrix[a][n];     for (long long i = 0; i < a; i++) {       for (long long z = 0; z < n; z++) {         char c;         cin >> c;         matrix[i][z] = (c -  0 );       }     }     bool used[a];     for (long long i = 0; i < a; i++) {       bool p = 0;       for (long long z = 0; z < n; z++) {         if (!matrix[i][z]) p = 1;       }       used[i] = p;     }     long long c = 0;     long long x = 1;     long long maxi = -1;     for (long long i = 0; i < a; i++) {       if (used[i]) {         c++;         continue;       }       maxi = max(maxi, c);       c = 0;     }     maxi = max(maxi, c);     cout << maxi;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> x[1024], y[1024];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       for (int i = 0; i < n; i++) {         cin >> x[i].first >> x[i].second;         y[i].first = x[i].first;         y[i].second = x[i].second;       }       sort(x, x + n, [](const pair<int, int>& a, const pair<int, int>& b) {         return a.first < b.first || (a.first == b.first && a.second < b.second);       });       sort(y, y + n, [](const pair<int, int>& a, const pair<int, int>& b) {         return a.second < b.second || (a.second == b.second && a.first < b.first);       });       string ans =   ;       int r = 0, c = 0;       for (int i = 0; i < n; i++) {         if (x[i] != y[i]) {           cout <<  NO  << endl;           ans =   ;           break;         } else {           ans += string(x[i].first - r,  R );           ans += string(x[i].second - c,  U );           r = x[i].first;           c = x[i].second;         }       }       if (!ans.empty()) {         cout <<  YES  << endl << ans << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[123456];   int main() {     scanf( %s , s);     stack<pair<int, int> > st;     int best = 0, rr = -1;     int sqb = 0;     for (int i = 0; s[i]; ++i) {       if (s[i] ==  (  || s[i] ==  [ ) {         st.push(make_pair(i, sqb));         sqb = 0;       } else if (s[i] ==  ) ) {         if (st.size() > 0 && s[st.top().first] ==  ( ) {           sqb += st.top().second;           if (best < sqb) {             best = sqb;             rr = i;           }           st.pop();         } else {           stack<pair<int, int> >().swap(st);           sqb = 0;         }       } else if (s[i] ==  ] ) {         if (st.size() > 0 && s[st.top().first] ==  [ ) {           sqb += st.top().second + 1;           if (best < sqb) {             best = sqb;             rr = i;           }           st.pop();         } else {           stack<pair<int, int> >().swap(st);           sqb = 0;         }       }     }     s[rr + 1] = 0;     int ll = rr;     stack<int> out;     for (int i = rr; i >= 0; --i) {       if (s[i] ==  )  || s[i] ==  ] ) {         out.push(i);       } else if (s[i] ==  ( ) {         if (out.size() > 0 && s[out.top()] ==  ) ) {           ll = i;           out.pop();         } else           break;       } else if (s[i] ==  [ ) {         if (out.size() > 0 && s[out.top()] ==  ] ) {           ll = i;           out.pop();         } else           break;       }     }     while (out.size() > 0) {       ll = out.top() + 1;       out.pop();     }     printf( %d n , best);     puts(s + ll);     return 0;   }


#include <bits/stdc++.h>   template <int MOD_>   struct modnum {     static constexpr int MOD = MOD_;     static_assert(MOD_ > 0,  MOD must be positive );       private:     using ll = long long;     int v;     static int minv(int a, int m) {       a %= m;       assert(a);       return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);     }       public:     modnum() : v(0) {}     modnum(ll v_) : v(int(v_ % MOD)) {       if (v < 0) v += MOD;     }     explicit operator int() const { return v; }     friend std::ostream& operator<<(std::ostream& out, const modnum& n) {       return out << int(n);     }     friend std::istream& operator>>(std::istream& in, modnum& n) {       ll v_;       in >> v_;       n = modnum(v_);       return in;     }     friend bool operator==(const modnum& a, const modnum& b) {       return a.v == b.v;     }     friend bool operator!=(const modnum& a, const modnum& b) {       return a.v != b.v;     }     modnum inv() const {       modnum res;       res.v = minv(v, MOD);       return res;     }     friend modnum inv(const modnum& m) { return m.inv(); }     modnum neg() const {       modnum res;       res.v = v ? MOD - v : 0;       return res;     }     friend modnum neg(const modnum& m) { return m.neg(); }     modnum operator-() const { return neg(); }     modnum operator+() const { return modnum(*this); }     modnum& operator++() {       v++;       if (v == MOD) v = 0;       return *this;     }     modnum& operator--() {       if (v == 0) v = MOD;       v--;       return *this;     }     modnum& operator+=(const modnum& o) {       v += o.v;       if (v >= MOD) v -= MOD;       return *this;     }     modnum& operator-=(const modnum& o) {       v -= o.v;       if (v < 0) v += MOD;       return *this;     }     modnum& operator*=(const modnum& o) {       v = int(ll(v) * ll(o.v) % MOD);       return *this;     }     modnum& operator/=(const modnum& o) { return *this *= o.inv(); }     friend modnum operator++(modnum& a, int) {       modnum r = a;       ++a;       return r;     }     friend modnum operator--(modnum& a, int) {       modnum r = a;       --a;       return r;     }     friend modnum operator+(const modnum& a, const modnum& b) {       return modnum(a) += b;     }     friend modnum operator-(const modnum& a, const modnum& b) {       return modnum(a) -= b;     }     friend modnum operator*(const modnum& a, const modnum& b) {       return modnum(a) *= b;     }     friend modnum operator/(const modnum& a, const modnum& b) {       return modnum(a) /= b;     }   };   int main() {     using namespace std;     ios_base::sync_with_stdio(false), cin.tie(nullptr);     using num = modnum<int(1e9) + 7>;     int Q;     cin >> Q;     string A;     cin >> A;     vector<num> dp(int(A.size()) + 1, num(1));     Q--;     while (Q--) {       string B;       cin >> B;       vector<num> ndp(int(B.size()) + 1, num(0));       int Asize = int(A.size());       int Bsize = int(B.size());       int L = max(Asize + 1, Bsize + 1);       A.resize(L + 1,  $ );       B.resize(L + 1,  % );       dp.resize(L + 1, num(0));       ndp.resize(L, num(0));       vector<array<array<num, 2>, 2>> pref_dp(L);       pref_dp[0][0][0]++;       for (int i = 0; i < L; i++) {         for (int z : {0, 1}) {           pref_dp[i][1][z] += dp[i] * pref_dp[i][0][z];         }         if (i + 1 == L) break;         for (int z : {0, 1}) {           pref_dp[i + 1][z][1] += pref_dp[i][z][1];           if (A[i + z] == B[i]) {             pref_dp[i + 1][z][0] += pref_dp[i][z][0];           } else if (A[i + z] < B[i]) {             pref_dp[i + 1][z][1] += pref_dp[i][z][0];           }         }       }       bool suff_less = true;       num ways_suff = num(0);       num ways_suff_less = num(0);       for (int i = L - 1; i >= 0; i--) {         ways_suff += dp[i + 1];         if (suff_less) {           ways_suff_less += dp[i + 1];         }         if (A[i] < B[i + 1]) {           ways_suff_less = ways_suff;         } else if (A[i] > B[i + 1]) {           ways_suff_less = 0;         }         if (A[i + 1] != B[i + 1]) {           suff_less = A[i + 1] < B[i + 1];         }         ndp[i] += ways_suff_less * pref_dp[i][0][0];         ndp[i] += suff_less * pref_dp[i][1][0];         ndp[i] += ways_suff * pref_dp[i][0][1];         ndp[i] += pref_dp[i][1][1];       }       A.resize(Asize);       B.resize(Bsize);       dp.resize(Asize + 1);       ndp.resize(Bsize + 1);       A = std::move(B);       dp = std::move(ndp);     }     num ans = accumulate(dp.begin(), dp.end(), num(0));     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, 0, 1, -1};   int dy[] = {-1, 1, 0, 0};   template <class T>   T power(T N, T P) {     return (P == 0) ? 1 : N * power(N, P - 1);   }   template <class T>   T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   struct debugger {     template <typename T>     debugger& operator,(const T& v) {       cerr << v <<    ;       return *this;     }   } dbg;   void make_unique(vector<int>& a) {     sort(a.begin(), a.end());     a.erase(unique(a.begin(), a.end()), a.end());   }   int on(int n, int pos) { return n = n | (1 << pos); }   void off(int& n, int pos) { n = n & ~(1 << pos); }   bool check(int n, int pos) { return (bool)(n & (1 << pos)); }   const int N = 1e5 + 10;   const int M = 64;   int id, cnt[M * N], a[N * M][5];   int new_node() {     for (int i = 0; i < 3; i++) {       a[id][i] = -1;     }     cnt[id] = 0;     return id++;   }   vector<int> bit(70);   void make(long long int x) {     bit.clear();     int i = 0;     while (x) {       bit.push_back(x % 2);       x /= 2LL;       i++;     }     while (i < M - 1) {       bit.push_back(0LL);       i++;     }     reverse(bit.begin(), bit.end());   }   void add(long long int x) {     make(x);     int cur = 0, typ;     for (int i = 0; i < M; i++) {       typ = bit[i];       if (a[cur][typ] == -1) {         a[cur][typ] = new_node();       }       cur = a[cur][typ];       ++cnt[cur];     }   }   void del(long long int x) {     make(x);     int cur = 0, typ;     for (int i = 0; i < M; i++) {       typ = bit[i];       cur = a[cur][typ];       --cnt[cur];     }   }   long long int query(long long int x) {     make(x);     int cur = 0, typ;     long long int ans = 0LL;     for (int i = 0; i < M; i++) {       typ = bit[i];       if (cnt[a[cur][!typ]] > 0) {         ans += (1LL << (M - i - 2));         cur = a[cur][!typ];       } else {         if (a[cur][typ] == -1) return ans;         cur = a[cur][typ];       }     }     return ans;   }   long long int arr[N];   int main() {     int n;     while (scanf( %d , &n) != EOF) {       id = 0;       new_node();       for (__typeof(n) i = 1; i <= n; i++) {         scanf( %lld , &arr[i]);       }       long long int xr = 0LL;       for (int i = n; i >= 1; i--) {         xr ^= arr[i];         add(xr);       }       long long int mx = 0LL;       long long int nw = 0LL;       mx = max(mx, query(nw));       for (int i = 1; i <= n; i++) {         nw ^= arr[i];         mx = max(mx, query(nw));         del(xr);         xr ^= arr[i];       }       printf( %lld n , mx);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t > 0) {       t--;       string s, x;       cin >> s;       x.push_back(s[0]);       for (int i = 1; i < s.size(); i++) {         if (i % 2 != 0) x.push_back(s[i]);       }       cout << x << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n, m, a;     cin >> n >> m;     int l = 1, mx = 0;     for (int i = 0; i < n; i++) {       cin >> a;       if ((a + m - 1) / m >= mx) {         mx = (a + m - 1) / m;         l = i + 1;       }     }     cout << l << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long const M = 2000 + 10, M2 = 1e7 + 10, mod = 1e9 + 7, inf = 1e9 + 10,                   sq = 450;   long long a[M][M], ro[M], col[M], all[M];   int32_t main() {     long long n, ans = 0;     cin >> n;     for (long long i = 1; i <= n; i++) {       string x;       cin >> x;       for (long long j = 0; j < x.size(); j++) {         a[i][j + 1] = x[j] -  0 ;       }     }     for (long long i = 1; i <= n; i++) {       for (long long j = n; j > i; j--) {         long long good = col[j] xor ro[i];         long long need = good xor a[i][j];         ro[i] = ro[i] xor need;         all[i] = all[i] xor need;         col[j] = col[j] xor need;         all[j] = all[j] xor need;         ans += need;       }     }     for (long long i = 1; i <= n; i++) col[i] = 0, ro[i] = 0;     for (long long i = n; i >= 1; i--) {       for (long long j = 1; j < i; j++) {         long long good = col[j] xor ro[i];         long long need = good xor a[i][j];         ro[i] = ro[i] xor need;         all[i] = all[i] = all[i] xor need;         col[j] = col[j] xor need;         all[j] = all[j] xor need;         ans += need;       }     }     for (long long i = 1; i <= n; i++) {       ans += all[i] xor a[i][i];     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     long long a[n], b[m];     for (long long i = 0; i < n; ++i) {       cin >> a[i];     }     for (long long i = 0; i < m; ++i) {       cin >> b[i];     }     long long ans = INF;     for (long long i = 0; i < n; ++i) {       long long res = -INF;       for (long long j = 0; j < n; ++j) {         if (i != j) {           for (long long k = 0; k < m; ++k) {             res = max(res, a[j] * b[k]);           }         }       }       ans = min(ans, res);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int n, x[maxn], y[maxn];   int solve(set<pair<int, int> >& a, set<pair<int, int> >& b) {     set<pair<int, int> >::iterator itl = a.begin(), itd = b.begin(), it1;     set<pair<int, int> >::reverse_iterator itr = a.rbegin(), itu = b.rbegin(),                                            it2;     set<pair<int, int> > f, s;     bool chk = false;     for (int i = 0; i < a.size() - 1; ++i) {       if (next(itl)->first > itl->first + 1) {         chk = true;         for (it1 = a.begin(); it1 != next(itl); ++it1) {           f.insert({x[it1->second], it1->second});         }       } else if (next(itd)->first > itd->first + 1) {         chk = true;         for (it1 = b.begin(); it1 != next(itd); ++it1) {           f.insert({x[it1->second], it1->second});         }       } else if (next(itr)->first + 1 < itr->first) {         chk = true;         for (it2 = a.rbegin(); it2 != next(itr); ++it2) {           f.insert({x[it2->second], it2->second});         }       } else if (next(itu)->first + 1 < itu->first) {         chk = true;         for (it2 = b.rbegin(); it2 != next(itu); it2++) {           f.insert({x[it2->second], it2->second});         }       }       if (chk) {         for (auto u : f) {           s.insert({y[u.second], u.second});           b.erase({y[u.second], u.second});           a.erase(u);         }         return solve(a, b) + solve(f, s);       }       itl++;       itr++;       itd++;       itu++;     }     return 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     set<pair<int, int> > xs, ys;     for (int i = 0; i < n; ++i) {       cin >> x[i] >> y[i];       xs.insert({x[i], i});       ys.insert({y[i], i});     }     cout << solve(xs, ys);     return 0;   }


#include <bits/stdc++.h>   int main() {     int t = 1, i, j, n;     long long int p, q, temp, arr[90];     for (j = 0; j < t; j++) {       scanf( %lld %lld , &p, &q);       scanf( %d , &n);       for (i = 0; i < n; i++) scanf( %lld , &arr[i]);       for (i = 0; i < n; i++) {         if (p / q < arr[i]) {           printf( NO n );           break;         }         p = p - (q * arr[i]);         if (p == 0 && i != n - 1) {           printf( NO n );           break;         }         if (i != n - 1) {           temp = p;           p = q;           q = temp;         }       }       if (p == 0 && i == n)         printf( YES n );       else if (i == n)         printf( NO n );     }     return 0;   }