#include <bits/stdc++.h>   using namespace std;   void run();   int main() {     ios::sync_with_stdio(0);     cout.precision(10);     run();   }   struct vec2 {     int x, y, sum;     vec2 *c, *rgb;     inline bool operator<(vec2 const &a) const {       return x < a.x or x == a.x and y < a.y;     }   };   int yc[1000002], n;   struct thingy {     vec2 *things;     int n, pivot;     thingy *l, *r;     thingy(vec2 *u, vec2 *v) {       pivot = u[rand() % (n = (v - u))].y;       auto a = u, b = v - 1, c = b;       while (a <= b)         if (b->y == pivot)           swap(a++[0], b[0]);         else           --b;       for (sort(u, b = a); b < c;) {         while (b < c and b->y < pivot) ++b;         while (b < c and c->y > pivot) --c;         if (b < c) swap(*b, *c);       }       while (b < v and b->y < pivot) ++b;       l = (a < b ? new thingy(a, b) : nullptr);       r = (b < v ? new thingy(b, v) : nullptr);       int sum = 0;       vec2 *last[2] = {};       things = new vec2[n];       for (int i = 0, j = 0, k = 0, t = 0; t < n; ++t) {         vec2 &from =             (i < (a - u) and (j == b - a or u[i] < l->things[j]) and                      (k == v - b or u[i] < r->things[k])                  ? u[i++]              : j < (b - a) and (k == v - b or l->things[j] < r->things[k])                  ? l->things[j++]                  : r->things[k++]);         things[t] = {from.x, from.y, sum += (from.y <= pivot), &from,                      max((from.y <= pivot ? last[1] : nullptr),                          (from.y >= pivot ? last[0] : nullptr))};         if (things[t].y != pivot) last[pivot < things[t].y] = things + t;       }     }     int query(int x, int y) const {       vec2 *a = things - 1, *b = things + n;       while (a + 1 < b) {         vec2 *m = a + (b - a) / 2;         (m->x <= x ? a : b) = m;       }       if (a < things) return 0;       thingy const *on = this;       int res = 0;       while (a and on) {         if (on->pivot <= y) res += a->sum;         if (y == on->pivot) return res;         while (a and (a->y == on->pivot or (a->y < on->pivot) != (y < on->pivot)))           a = a->rgb;         if (a) on = (y < on->pivot ? on->l : on->r), a = a->c;       }       return res;     }     ~thingy() {       delete things;       delete l;       delete r;     }   };   vec2 v[100002];   void run() {     int worth[9];     cin >> n;     for (int i = n; i--;) cin >> v[i].x >> v[i].y, yc[i] = v[i].y;     sort(yc, yc + n);     yc[n] = 1 << 30;     for (int i = 9; i--;) cin >> worth[i];     sort(worth, worth + 9);     thingy data(v, v + n);     sort(v, v + n);     v[n].x = 1 << 30;     do {       int sx[3] = {}, sy[3] = {}, si[3] = {}, sj[3] = {};       for (int i = 9; i--;) si[i / 3] += worth[i], sj[i % 3] += worth[i];       for (int i = 0; i < 2; i++) si[i + 1] += si[i], sj[i + 1] += sj[i];       for (int i = 3; i--;) si[i]--, sj[i]--;       if ((sx[0] = v[si[0]].x) == v[si[0] + 1].x) continue;       if ((sx[1] = v[si[1]].x) == v[si[1] + 1].x) continue;       if ((sy[0] = yc[sj[0]]) == yc[sj[0] + 1]) continue;       if ((sy[1] = yc[sj[1]]) == yc[sj[1] + 1]) continue;       sx[2] = sy[2] = 1 << 30;       int u = data.query(sx[0], sy[0]);       if (u - 0 != worth[0]) continue;       int v = data.query(sx[1], sy[0]);       if (v - u != worth[3]) continue;       int w = data.query(sx[2], sy[0]);       if (w - v != worth[6]) continue;       int a = data.query(sx[0], sy[1]);       if (a - 0 != worth[0] + worth[1]) continue;       int b = data.query(sx[1], sy[1]);       if (b - a != worth[3] + worth[4]) continue;       int c = data.query(sx[2], sy[1]);       if (c - b != worth[6] + worth[7]) continue;       long double ra = sx[0] + 0.5, rb = sx[1] + 0.5, rc = sy[0] + 0.5,                   rd = sy[1] + 0.5;       cout << ra <<     << rb <<   n  << rc <<     << rd << endl;       return;     } while (next_permutation(worth, worth + 9));     cout <<  -1  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int f[1001000];   int dp[22][1001000];   int get(int x, int k) {     for (int i = 21; i >= 0; i--)       if (k & (1 << i)) x = dp[i][x];     return x;   }   int dist[1001000];   int foi[1001000];   vector<int> L[1001000];   char str[1001000];   char nova[1001000];   void bfs(int x, int dc) {     queue<pair<int, int> > Q;     Q.push(pair<int, int>(x, 0));     while (Q.size()) {       pair<int, int> u = Q.front();       Q.pop();       for (vector<int>::iterator it = L[u.first].begin(); it < L[u.first].end();            it++)         if (!foi[*it]) {           foi[*it] = 1;           dist[*it] = 1 + u.second;           Q.push(pair<int, int>(*it, dist[*it]));         }     }   }   char debugs[1001000];   int main() {     int n, m;     scanf(  %s , str);     n = strlen(str);     scanf( %d , &m);     while (m--) {       int d, k;       scanf( %d%d , &k, &d);       for (int i = 0; i <= n; i++) {         L[i].clear();         dist[i] = 9999999;         foi[i] = 0;       }       int cont = 0;       for (int r = 0; r < d; r++)         for (int i = r; i < k; i += d) {           L[i + 1].push_back(cont);           f[cont] = i + 1;           ;           cont++;         }       f[k] = k;       bfs(k, 0);       for (int i = 0; i < k; i++) dp[0][i] = f[i];       dp[0][k] = k;       for (int j = 1; j < 22; j++) {         for (int i = 0; i < k; i++) {           dp[j][i] = dp[j - 1][dp[j - 1][i]];           ;         }         dp[j][k] = k;       }       for (int i = 0; i < k; i++)         ;       for (int i = 0; i < n; i++) {         int y0 = 0;         int p0 = i;         int u = get(0, i + 1) - 1;         if (i + k > n) y0 = i - n + k, p0 = n - k;         u = get(y0, p0 + 1) - 1;         ;         if (dist[y0] > p0) {           nova[i] = str[u];           continue;         }         int p = dist[y0];         nova[i] = str[p0 - p + k];         debugs[i] = str[p0 - p + k];         if (debugs[i] <  a  || debugs[i] >  z ) debugs[i] =  ? ;       }       for (int i = 0; i < n; i++) str[i] = nova[i];       printf( %s n , str);       for (int i = 0; i < n; i++)         ;       ;     }   }


#include <bits/stdc++.h>   using namespace std;   int dp[10][10][10][10], pres_path;   void dfs(int x, int y, int u, int v, int p);   void dfs_next(int x, int y, int u, int v, int p) {     int &t = dp[x][y][u][v];     if (t == 0 or t > pres_path + 1) {       t = ++pres_path;       if (p < 10) dfs(x, y, u, v, p + 1);       --pres_path;     }   }   void dfs(int x, int y, int u, int v, int p) {     dfs_next(x, y, u, (v + x) % 10, p), dfs_next(x, y, u, (v + y) % 10, p);   }   int main() {     string s;     ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr), cin >> s;     for (int x = 0; x < int(10); ++x)       for (int y = 0; y < int(10); ++y)         for (int u = 0; u < int(10); ++u) dfs(x, y, u, u, 1);     for (int x = 0; x < int(10); ++x) {       for (int y = 0; y < int(10); ++y) {         bool valid = true;         int count = 0;         for (int l, i = 0, j = 1, k = s.size(); j < k and valid; i = j++)           if ((l = dp[x][y][s[i] -  0 ][s[j] -  0 ]))             count += l - 1;           else             count = -1, valid = false;         cout << count <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000007;   char s[maxn];   int n, cnt, a[maxn];   bool check(int p, bool need_touch) {     int x = 0, maxv = 0;     bool touched = 0;     for (int i = 1, _c = cnt; i <= _c; i++) {       maxv = max(maxv, x);       x += a[i];       if (x <= p) {         x = p + 1;         touched = 1;       }     }     return (x > maxv) && (!need_touch || touched);   }   int main() {     cnt = 0;     gets(s + 1);     n = strlen(s + 1);     int x = 1;     while (x <= n) {       int y = x;       while (y < n && s[y + 1] == s[x]) ++y;       a[++cnt] = y - x + 1;       if (s[x] ==  L ) a[cnt] *= -1;       x = y + 1;     }     if (a[cnt] < 0)       for (int i = 1, _c = cnt; i <= _c; i++) a[i] *= -1;     if (check(-n - 1, 0)) {       puts( 1 );       return 0;     }     int res = 0;     int l = -n, r = -1, mid, pos = 0;     while (l <= r) {       mid = (l + r) / 2;       if (check(mid, 1)) {         pos = mid;         r = mid - 1;       } else         l = mid + 1;     }     res -= pos;     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0;     int sign = 0;     char c = getchar();     for (; !isdigit(c); c = getchar()) {       sign |= c ==  - ;     }     for (; isdigit(c); c = getchar()) {       x = x * 10 + c -  0 ;     }     return sign ? -x : x;   }   const int ms = 1 << 22;   const int lim = (1 << 22) - 1;   int arr[ms], pai[ms], comps;   bool hav[ms];   bool vis[ms];   int find(int x) {     if (x == pai[x]) return x;     return pai[x] = find(pai[x]);   }   void unite(int x, int y) {     x = find(x);     y = find(y);     if (x != y) {       --comps;       pai[x] = y;     }   }   void dfs(int u, int mask) {     if (hav[mask]) unite(u, mask);     if (vis[mask]) return;     vis[mask] = true;     if (mask == 0) return;     int last_bit = 31 - __builtin_clz(mask);     for (int i = last_bit; i >= 0; --i) {       int nmask = mask & (~(1 << i));       dfs(u, nmask);     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     iota(pai, pai + ms, 0);     int n = read(), m = read();     comps = m;     for (int i = 0; i < m; ++i) {       arr[i] = read();       hav[arr[i]] = true;     }     for (int i = 0; i < m; ++i) {       dfs(arr[i], ~arr[i] & lim);     }     cout << comps <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     if (k > (n % 2 == 0 ? n * n / 2 : (n * n + 1) / 2)) {       cout <<  NO  << endl;       return 0;     }     cout <<  YES  << endl;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (k && (i + j) % 2 == 0) {           cout <<  L ;           k--;         } else {           cout <<  S ;         }       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000000 + 10;   int tot;   vector<int> primes;   int notP[N];   vector<long long> divisors[N];   map<pair<long long, int>, int> dp;   int isP(long long x) {     for (int i = 0; (long long)primes[i] * primes[i] <= x; ++i) {       if (x % primes[i] == 0) return false;     }     return true;   }   int dfs(long long x, int cur) {     if (dp.count(make_pair(x, cur))) {       return dp[make_pair(x, cur)];     }     int &ret = dp[make_pair(x, cur)];     if (cur == tot) {       if (x == 1) {         ret++;       } else if (x > N) {         ret += isP(x - 1);       }       return ret;     }     ret += dfs(x, cur + 1);     for (int i = 0; i < divisors[cur].size(); ++i) {       if (x % divisors[cur][i] == 0) {         ret += dfs(x / divisors[cur][i], cur + 1);       }     }     return ret;   }   void solve() {     long long n;     cin >> n;     tot = 0;     for (int i = 0; i < primes.size(); ++i) {       int prime = primes[i];       int flag = false;       for (long long tmp = prime; tmp < n; tmp *= prime) {         if (n % (tmp + 1) == 0) {           if (!flag) {             flag = true;             ++tot;           }           divisors[tot - 1].push_back(tmp + 1);         }       }     }     cout << dfs(n, 0) << endl;   }   int main() {     for (int i = 2; i < N; ++i) {       if (notP[i]) continue;       primes.push_back(i);       for (long long j = (long long)i * i; j < N; j += i) {         notP[j] = true;       }     }     solve();     return 0;   }


#include <bits/stdc++.h>   const int maxn = 400010, maxq = 400010;   int n, cnt[maxn], tmp[maxn], lg[maxn];   int min(int a, int b) { return a < b ? a : b; }   int max(int a, int b) { return a > b ? a : b; }   struct SA {     char S[maxn];     int nxt[maxn], mn[maxn], sa[maxn], r[2][maxn], *rk, ht[20][maxn];     void make() {       for (int i = 0; i < 128; i++) cnt[i] = 0, tmp[i] = 1 << 30;       mn[n] = 1 << 30;       for (int i = n; i--;)         nxt[i] = tmp[S[i]], tmp[S[i]] = i, mn[i] = min(nxt[i], mn[i + 1]);       for (int i = 0; i < n; i++) cnt[S[i]]++;       for (int i = 1; i < 128; i++) cnt[i] += cnt[i - 1];       for (int i = n; i--;) sa[--cnt[S[i]]] = i;       int tot = 0;       rk = *r;       for (int i = 0; i < n; i++)         rk[sa[i]] = i && S[sa[i - 1]] == S[sa[i]] ? tot - 1 : tot++;       for (int k = 1, *t = r[1]; tot < n; k *= 2) {         for (int i = 0; i < k; i++) tmp[i] = i + n - k;         for (int i = 0, j = k; i < n; i++)           if (sa[i] >= k) tmp[j++] = sa[i] - k;         for (int i = 0; i < tot; i++) cnt[i] = 0;         for (int i = 0; i < n; i++) cnt[rk[i]]++;         for (int i = 1; i < tot; i++) cnt[i] += cnt[i - 1];         for (int i = n; i--;) sa[--cnt[rk[tmp[i]]]] = tmp[i];         rk[n] = -1;         for (int i = tot = 0; i < n; i++)           t[sa[i]] = i && rk[sa[i - 1]] == rk[sa[i]] &&                              rk[sa[i - 1] + k] == rk[sa[i] + k]                          ? tot - 1                          : tot++;         std::swap(rk, t);       }       for (int i = 0, h = 0; i < n; ht[0][rk[i++]] = h)         for (h ? --h : 0; rk[i] + 1 < n && S[i + h] == S[sa[rk[i] + 1] + h]; h++)           ;       for (int k = 1; k <= lg[n]; k++)         for (int i = 0; i + (1 << k) <= n; i++)           ht[k][i] = min(ht[k - 1][i], ht[k - 1][i + (1 << k - 1)]);     }     int lcp(int i, int j) {       if (i == n || j == n) return 0;       int k;       if ((i = rk[i]) > (j = rk[j]))         return k = lg[i - j], min(ht[k][j], ht[k][i - (1 << k)]);       return k = lg[j - i], min(ht[k][i], ht[k][j - (1 << k)]);     }   } S0, S1;   int R[maxq], ans[maxq];   std::vector<int> pf[maxn], qs[maxn];   int ul[maxn], ur[maxn], dl[maxn], dr[maxn], ml[maxn], pl[maxn], pr[maxn],       list[maxn];   int find(int* u, int i) { return u[i] == i ? i : u[i] = find(u, u[i]); }   void upd(int* u, int* d, int l, int r, int x) {     while ((l = find(u, l)) < r) d ? d[l] = x : 0, u[l] = find(u, l + 1);   }   int calc(int l, int r, int br) {     int len = r - l;     for (int i = pf[len].size(); i--;) {       int p = len / pf[len][i];       if (S0.lcp(l, l + p) >= len - p) return 1;     }     if (dl[l] && l + dl[l] * 2 <= r) return 2;     if (dr[r] && r - dr[r] * 2 >= l) return 2;     if (r > br && ul[r] > r) return 2;     for (int i = 1; l + i < r && l + i <= br; i++)       if (S0.lcp(l, r - i) >= i) return 2;     if (S0.nxt[l] < r || S1.nxt[n - r] < n - l || ml[l] <= r) return 3;     if (S0.mn[l] < r) return 4;     return -1;   }   int main() {     scanf( %d%s , &n, S0.S);     for (int i = n, j = 0; i--; j++) S1.S[j] = S0.S[i];     for (int i = 2; i <= n; i++) {       lg[i] = lg[i / 2] + 1;       if (!pf[i].size())         for (int j = i; j <= n; j += i) pf[j].push_back(i);     }     S0.make();     S1.make();     for (int i = 0; i <= n + 1; i++) ul[i] = ur[i] = i;     for (int l = 1; l <= n / 2; l++) {       int la = -1;       for (int i = 0; i + l <= n; i += l)         if (i > la) {           int pl = i - S1.lcp(n - i - l, n - i), pr = i + S0.lcp(i, i + l);           if (pr - pl >= l) {             upd(ul, dl, pl, pr - l + 1, l);             upd(ur, dr, pl + l * 2, pr + l + 1, l);           }           la = pr;         }     }     ml[n] = 1 << 30;     for (int i = n; i--;) {       ml[i] = ml[i + 1];       if (dl[i]) ml[i] = min(ml[i], i + dl[i] * 2);     }     int q;     scanf( %d , &q);     for (int i = 0, l; i < q; i++) {       scanf( %d%d , &l, R + i);       qs[l - 1].push_back(i);     }     int b = 0;     while (b * b < n * 4) b++;     for (int bl = 0, br = b; bl < n; bl = br, br += b) {       if (br > n) br = n;       for (int i = 0; i <= br; i++) cnt[i] = 0;       for (int i = br + 1; i <= n; i++) {         ul[i] = i;         pl[i] = br - S1.lcp(n - i, n - br);         cnt[pl[i]]++;       }       for (int i = 0; i < br; i++) cnt[i + 1] += cnt[i];       int tot = cnt[br];       for (int i = n; i > br; i--) tmp[--cnt[pl[i]]] = i;       for (int l = bl, i = 0; l < n && l < br; l++) {         for (; i < tot && pl[tmp[i]] <= l; i++)           upd(ul, 0, tmp[i], tmp[i] + S0.lcp(br, tmp[i]) + 1, 0);         for (int id = qs[l].size(); id--;) {           int x = qs[l][id];           ans[x] = calc(l, R[x], br);         }       }     }     for (int i = 0; i < q; i++) printf( %d n , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   string ls[] = {  ,      one ,  two ,    three ,  four ,                   five ,  six ,  seven ,  eight ,  nine };   string fr[] = {  ,        ,       twenty ,   thirty ,  forty ,                   fifty ,  sixty ,  seventy ,  eighty ,  ninety };   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     int first = n / 10, second = n % 10;     switch (n) {       case 0:         cout <<  zero  << endl;         break;       case 10:         cout <<  ten  << endl;         break;       case 11:         cout <<  eleven  << endl;         break;       case 12:         cout <<  twelve  << endl;         break;       case 13:         cout <<  thirteen  << endl;         break;       case 14:         cout <<  fourteen  << endl;         break;       case 15:         cout <<  fifteen  << endl;         break;       case 16:         cout <<  sixteen  << endl;         break;       case 17:         cout <<  seventeen  << endl;         break;       case 18:         cout <<  eighteen  << endl;         break;       case 19:         cout <<  nineteen  << endl;         break;       default: {         if (!first)           cout << ls[second] << endl;         else if (!second)           cout << fr[first] << endl;         else           cout << fr[first] <<  -  << ls[second] << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       double n, m, k;       cin >> n >> m >> k;       if (m == 0)         cout << 0 << endl;       else if (n / k >= m) {         cout << (int)m << endl;       } else {         double zz = (m - (n / k));         int tt;         tt = ceil(zz / (k - 1));         cout <<    << (int)(n / k) - tt << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int r, h, sum, n;     float k, l;     cin >> r >> h;     n = h / r;     h -= n * r;     l = r / 2.0;     k = sqrt(3) / 2 * r;     if (h < l) sum = n * 2 + 1;     if (h >= l && h < k) sum = n * 2 + 2;     if (h >= k) sum = n * 2 + 3;     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   namespace IO {   const unsigned int Buffsize = 1 << 15, Output = 1 << 23;   static char Ch_[Buffsize], *S_ = Ch_, *T_ = Ch_;   static char Out[Output], *nowps = Out;   inline void flush() {     fwrite(Out, 1, nowps - Out, stdout);     nowps = Out;   }   template <typename T>   inline T Read() {     T _ = 0;     static char __;     T ___ = 1;     for (__ = ((S_ == T_) && (T_ = (S_ = Ch_) + fread(Ch_, 1, Buffsize, stdin),                              S_ == T_)                    ? 0                    : *S_++);          !isdigit(__);          __ = ((S_ == T_) && (T_ = (S_ = Ch_) + fread(Ch_, 1, Buffsize, stdin),                              S_ == T_)                    ? 0                    : *S_++))       if (__ ==  - ) ___ = -1;     for (; isdigit(__);          __ = ((S_ == T_) && (T_ = (S_ = Ch_) + fread(Ch_, 1, Buffsize, stdin),                              S_ == T_)                    ? 0                    : *S_++))       _ = (_ << 3) + (_ << 1) + (__ ^ 48);     return _ *= ___;   }   template <typename T>   inline void write(T _, char __ =   n ) {     if (!_) *nowps++ =  0 ;     if (_ < 0) *nowps++ =  - , _ = -_;     static unsigned int sta[111], tp;     for (tp = 0; _; _ /= 10) sta[++tp] = _ % 10;     for (; tp; *nowps++ = sta[tp--] ^ 48)       ;     (*nowps++) = __;   }   template <class T>   inline bool chkmax(T &_, T __) {     return _ < __ ? _ = __, 1 : 0;   }   template <class T>   inline bool chkmin(T &_, T __) {     return _ > __ ? _ = __, 1 : 0;   }   }  // namespace IO   using namespace std;   using namespace IO;   const int N = 2e5 + 10, Mod = 1e9 + 7;   int n;   int fa[N], sz[N], flag[N], ans;   int find(int first) {     return first == fa[first] ? first : fa[first] = find(fa[first]);   }   void merge(int first, int second) {     int fx = find(first), fy = find(second);     if (fx != fy) {       fa[fx] = fy;       sz[fy] += sz[fx];       flag[fy] |= flag[fx];     } else       flag[fy] = 1;   }   int main() {     n = Read<int>();     for (int i = 1; i <= 2 * n; ++i) fa[i] = i, sz[i] = 1, flag[i] = 0;     for (register int i = (1), i_end_ = (n); i <= i_end_; ++i) {       int u = Read<int>(), v = Read<int>();       if (u != v)         merge(u, v);       else         flag[u] = 2;     }     ans = 1;     for (register int i = (1), i_end_ = (2 * n); i <= i_end_; ++i)       if (find(i) == i) {         if (flag[i] == 0)           ans = (1ll * ans * sz[i]) % Mod;         else if (flag[i] == 1)           ans = (ans * 2ll) % Mod;       }     printf( %d n , ans);     return flush(), 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     vector<int> v(n);     vector<pair<int, int>> vv(n);     for (int i = 0; i < n; i++) {       scanf( %d , &v[i]);     }     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     for (int i = 0; i < n; i++) {       scanf( %d , &vv[i].first);       vv[i].second = i;     }     sort(vv.begin(), vv.end());     vector<int> ans(n);     for (int i = 0; i < n; i++) {       ans[vv[i].second] = v[i];     }     for (int i = 0; i < ans.size(); i++) cout << ans[i] <<    ;     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   ostream& operator<<(ostream& os, vector<int>& x) {     for (int i = 0; i < x.size(); i++) os << x[i] <<    ;     return os;   }   ostream& operator<<(ostream& os, pair<int, int> x) {     cout << x.first <<     << x.second <<    ;     return os;   }   ostream& operator<<(ostream& os, vector<pair<int, int> >& x) {     for (int i = 0; i < x.size(); i++) os << x[i] <<   n ;     return os;   }   vector<pair<int, int> > changed;   bool mark[500005];   struct dsu {     int par[500005];     dsu() {       for (int i = 1; i <= 500005 - 5; i++) par[i] = i;     }     int find(int x, bool cache = false) {       if (cache) {         if (!mark[x]) {           mark[x] = true;           changed.push_back(make_pair(x, par[x]));         }       }       if (par[x] == x) return x;       return par[x] = find(par[x]);     }     bool uni(int x, int y, bool cache = false) {       x = find(x, cache);       y = find(y, cache);       if (x != y) {         if (cache) {           if (!mark[x]) {             mark[x] = true;             changed.push_back(make_pair(x, par[x]));           }         }         par[x] = y;         return true;       }       return false;     }   } d;   struct data {     int u, v, c;     data(int _u, int _v, int _c) : u(_u), v(_v), c(_c){};   };   bool byPrice(data x, data y) { return x.c < y.c; }   int n, m, q;   vector<data> edge;   vector<data> oredge;   vector<vector<vector<int> > > query(500005);   vector<vector<pair<int, int> > > withW(500005);   vector<vector<int> > tmp(500005);   bool ans[500005];   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int u, v, c;       cin >> u >> v >> c;       edge.push_back(data(u, v, c));       withW[c].push_back(make_pair(u, v));     }     cin >> q;     for (int i = 1; i <= q; i++) {       int num;       cin >> num;       vector<int> zz;       while (num--) {         int t;         cin >> t;         t--;         zz.push_back(t);         tmp[edge[t].c].push_back(t);       }       for (int j = 0; j < zz.size(); j++) {         int c = edge[zz[j]].c;         if (tmp[c].empty()) continue;         tmp[c].push_back(i);         query[c].push_back(tmp[c]);         tmp[c].clear();       }     }     memset(ans, 1, sizeof(ans));     for (int w = 1; w <= 500000; w++) {       for (int i = 0; i < query[w].size(); i++) {         for (int j = 0; j < query[w][i].size() - 1; j++) {           int num = query[w][i][j];           assert(edge[num].c == w);           int u = edge[num].u;           int v = edge[num].v;           d.find(u);           d.find(v);         }       }       for (int i = 0; i < query[w].size(); i++) {         int which = query[w][i].back();         bool ok = true;         for (int j = 0; j < query[w][i].size() - 1; j++) {           int num = query[w][i][j];           int u = edge[num].u;           int v = edge[num].v;           if (!d.uni(u, v, 1)) {             ok = false;             break;           }         }         if (!ok) {           ans[which] = false;         }         for (int j = 0; j < changed.size(); j++) {           d.par[changed[j].first] = changed[j].second;           mark[changed[j].first] = false;         }         changed.clear();       }       for (int i = 0; i < withW[w].size(); i++) {         int u = withW[w][i].first;         int v = withW[w][i].second;         d.uni(u, v);       }     }     for (int i = 1; i <= q; i++) {       if (ans[i] == 1)         cout <<  YES  <<   n ;       else         cout <<  NO  <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s;     cin >> n >> s;     int a1[n], a2[n];     for (int i = 0; i < n; i++) a1[i] = s[i] -  0 ;     for (int i = n; i < 2 * n; i++) a2[i - n] = s[i] -  0 ;     for (int i = 0; i < n; i++) {       int s1(i), s2(i);       for (int j = i + 1; j < n; j++) {         if (a1[j] < a1[s1]) s1 = j;         if (a2[j] < a2[s2]) s2 = j;       }       swap(a1[i], a1[s1]);       swap(a2[i], a2[s2]);     }     int l(0), m(0);     for (int i = 0; i < n; i++)       if (a1[i] < a2[i])         l += 1;       else if (a1[i] > a2[i])         m += 1;       else if (a1[i] == a2[i]) {         cout <<  NO  << endl;         return 0;       }     if ((l == n) || (m == n))       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = int(1e9);   long long n, m;   pair<long long, long long> p = make_pair(0, 0);   long long b[222222];   long long c[222222];   long long ans;   map<long long, long long> mp;   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       mp[x]++;     }     cin >> m;     for (int i = 1; i <= m; i++) cin >> b[i];     for (int i = 1; i <= m; i++) cin >> c[i];     for (int i = 1; i <= m; i++)       if (p <= make_pair(mp[b[i]], mp[c[i]]))         ans = i, p = make_pair(mp[b[i]], mp[c[i]]);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<long long> heros(n);     for (auto& x : heros) cin >> x;     sort(heros.begin(), heros.end());     long long sum = accumulate(heros.begin(), heros.end(), 0ll);     int m;     cin >> m;     while (m--) {       long long atk, dfns;       cin >> atk >> dfns;       int id = lower_bound(heros.begin(), heros.end(), atk) - heros.begin();       long long ans = 2e18 + 5;       if (id > 0) {         ans = min(ans,                   atk - heros[id - 1] + max(0ll, dfns - (sum - heros[id - 1])));       }       if (id < n) {         ans = min(ans, max(0ll, dfns - (sum - heros[id])));       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 3;   int last[22][22];   int a[maxn], dp[20][maxn];   int main() {     ios_base::sync_with_stdio(false);     int n, q;     cin >> n >> q;     for (int i = 1; i <= n; i++) cin >> a[i];     int l = 19;     memset(last, 63, sizeof last);     memset(dp, 63, sizeof dp);     for (int i = n; i >= 1; i--) {       for (int fb = 0; fb < l; fb++)         for (int sb = 0; sb < l; sb++)           if (a[i] & (1 << fb) and a[i] & (1 << sb)) last[fb][sb] = i;       for (int fb = 0; fb < l; fb++)         for (int sb = 0; sb < l; sb++)           if (a[i] & (1 << sb)) dp[fb][i] = min(dp[fb][i], last[fb][sb]);       for (int fb = 0; fb < l; fb++)         for (int sb = 0; sb < l; sb++)           if (dp[sb][i] <= n) dp[fb][i] = min(dp[fb][i], dp[fb][dp[sb][i]]);     }     while (q--) {       int x, y;       cin >> x >> y;       bool ret = 0;       for (int i = 0; i < l; i++)         if (a[y] & (1 << i) and dp[i][x] <= y) ret |= 1;       if (ret == 1)         cout <<  Shi n ;       else         cout <<  Fou n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int a[100005];   int b[100005];   bool ok(long long x) {     long long s = k;     for (int i = 0; i < n; i++) {       if (x * a[i] >= b[i]) {         s -= (x * a[i] - b[i]);       }       if (s < 0) {         return false;       }     }     return true;   }   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int j = 0; j < n; j++) {       cin >> b[j];     }     if (n == 1) {       cout << (b[0] + k) / a[0] << endl;     } else {       int sum = 0;       long long l = 0, r = 0xffffffff;       long long mid;       while (l <= r) {         mid = (l + r) >> 1;         if (ok(mid)) {           l = mid + 1;           sum = mid;         } else {           r = mid - 1;         }       }       cout << sum << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     vector<string> a(n);     map<string, int> M;     for (int i = 0; i < n; ++i) {       cin >> a[i];       M[a[i]] = i;     }     vector<vector<int> > Inv(1 << n, vector<int>(n, 0));     for (int mask = 1; mask < (1 << n); ++mask)       for (int j = 0; j < n; ++j)         if ((mask & (1 << j)) == 0)           for (int l = 0; l < n; ++l)             if ((mask & (1 << l)) > 0 && M[a[j]] < M[a[l]]) ++Inv[mask][j];     int m;     cin >> m;     int p = -1, nr;     for (int i = 0; i < m; ++i) {       int k;       cin >> k;       vector<string> b(k);       for (int j = 0; j < k; ++j) cin >> b[j];       vector<vector<int> > nast(k, vector<int>(n, INF));       if (M.find(b[k - 1]) != M.end()) nast[k - 1][M[b[k - 1]]] = k - 1;       for (int j = k - 2; j >= 0; --j) {         for (int l = 0; l < n; ++l) nast[j][l] = nast[j + 1][l];         if (M.find(b[j]) != M.end()) nast[j][M[b[j]]] = j;       }       vector<vector<int> > dp((1 << n), vector<int>(n * (n - 1) / 2 + 1, INF));       for (int j = 0; j < n; ++j)         if (nast[0][j] != INF) dp[1 << j][0] = nast[0][j];       for (int mask = 1; mask < (1 << n); ++mask) {         for (int inv = 0; inv <= n * (n - 1) / 2; ++inv) {           if (dp[mask][inv] == INF) continue;           for (int j = 0; j < n; ++j) {             if ((mask & (1 << j)) == 0) {               int noweInv = inv + Inv[mask][j];               if (dp[mask][inv] + 1 < k && nast[dp[mask][inv] + 1][j] != INF)                 dp[mask | (1 << j)][noweInv] =                     min(dp[mask | (1 << j)][noweInv], nast[dp[mask][inv] + 1][j]);             }           }         }       }       for (int j = 0; j <= n * (n - 1) / 2; ++j) {         if (dp[(1 << n) - 1][j] != INF && n * (n - 1) / 2 - j + 1 > p) {           p = n * (n - 1) / 2 - j + 1;           nr = i;         }       }     }     if (p == -1)       cout <<  Brand new problem! ;     else {       cout << nr + 1 << endl;       cout <<  [: ;       for (int i = 0; i < p; ++i) cout <<  | ;       cout <<  :] ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 14;   const int Q = 101;   int n, m, q;   long long dp[N][1 << N];   bool edge[N][N];   int a[Q], b[Q], c[Q];   int lowbit(int x) { return x & (-x); }   int in(int i, int S) { return ((S >> i) & 1); }   bool check(int u, int k) {     for (int i = 0; i < n; i++)       if (i != u) {         for (int j = 0; j < n; j++)           if (j != u)             if (edge[i][j] && (in(i, k) ^ in(j, k))) return false;       }     return true;   }   long long DP(int u, int S) {     if (dp[u][S] != -1) return dp[u][S];     dp[u][S] = 0;     int status = S - (1 << u);     int t;     for (t = 0; t < n; t++)       if (in(t, status)) break;     for (int k = status; k; k = (k - 1) & status)       if (in(t, k)) {         if (!check(u, k)) continue;         int v, cnt = 0;         for (int i = 0; i < n; i++) {           if (edge[u][i] && in(i, k)) {             cnt++;             v = i;           }         }         if (cnt >= 2) continue;         bool flag = true;         for (int i = 1; i <= q; i++) {           if (c[i] == u && in(a[i], k) && in(b[i], k)) {             flag = false;             break;           }           if (in(c[i], k) && (!in(a[i], k) || !in(b[i], k))) {             flag = false;             break;           }         }         if (!flag) continue;         if (cnt == 1) {           dp[u][S] += DP(v, k) * DP(u, S - k);         } else {           for (v = 0; v < n; v++)             if (in(v, k)) dp[u][S] += DP(v, k) * DP(u, S - k);         }       }     return dp[u][S];   }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       x--, y--;       edge[x][y] = edge[y][x] = true;     }     for (int i = 1; i <= q; i++) {       scanf( %d%d%d , &a[i], &b[i], &c[i]);       a[i]--;       b[i]--;       c[i]--;     }     memset(dp, -1, sizeof(dp));     for (int i = 0; i < n; i++) dp[i][1 << i] = 1;     printf( %lld , DP(0, (1 << n) - 1));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t = 1;   void solve() {     long long n, i, k, s = 0, b;     cin >> n >> k;     long long a[n];     for (i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     b = a[0];     for (i = 1; i < n; i++) {       long long c = (k - a[i]) / b;       if (c > 0) s += c;     }     cout << s <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 20;   const int inf = 0x3f3f3f3f;   const int modd = 1e9 + 7;   inline int read() {     int x = 0, f = 1;     char c = getchar();     while (c !=  -  && (c <  0  || c >  9 )) c = getchar();     if (c ==  - ) f = -1, c = getchar();     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return f * x;   }   template <class T>   inline void sc(T &x) {     char c;     x = 0;     while ((c = getchar()) <  0 )       ;     while (c >=  0  && c <=  9 ) x = x * 10 + (c - 48), c = getchar();   }   inline long long gcd(long long a, long long b) {     return b == 0 ? a : gcd(b, a % b);   }   inline long long exgcd(long long a, long long b, long long &x, long long &y) {     long long d;     (b == 0 ? (x = 1, y = 0, d = a)             : (d = exgcd(b, a % b, y, x), y -= a / b * x));     return d;   }   inline long long qpow(long long a, long long n) {     long long sum = 1;     while (n) {       if (n & 1) sum = sum * a % modd;       a = a * a % modd;       n >>= 1;     }     return sum;   }   inline long long qmul(long long a, long long n) {     long long sum = 0;     while (n) {       if (n & 1) sum = (sum + a) % modd;       a = (a + a) % modd;       n >>= 1;     }     return sum;   }   inline long long inv(long long a) { return qpow(a, modd - 2); }   int a[maxn];   int main() {     int n, m;     scanf( %d%d , &n, &m);     if (m && n < 3) return printf( -1 n ), 0;     int i = 1;     for (; i <= n;) {       if (m >= (i - 1) / 2) {         a[i] = i, m -= (i - 1) / 2;         i++;         continue;       }       if (m > 0) a[i] = 2 * (i - m) - 1, m = 0, i++;       if (!m) break;     }     for (int j = n; j >= i; j--) a[j] = (int)9e8 - (n - j) * (a[i - 1] + 1);     if (!m) {       for (int i = 1; i <= n; i++) printf( %d%c , a[i],    n [i == n]);       return 0;     }     printf( -1 n );   }


#include <bits/stdc++.h>   using namespace std;   int n, leaf;   vector<int> vt[100005];   int ara[100005], chk[100005], level[100005], child[100005];   map<int, int> mp;   void bfs() {     int i, j, k;     queue<int> qu;     qu.push(0);     chk[0] = 1;     level[0] = 0;     while (!qu.empty()) {       k = qu.front();       qu.pop();       for (i = 0; i < vt[k].size(); ++i) {         j = vt[k][i];         if (!chk[j]) {           qu.push(j);           level[j] = level[k] + 1;           chk[j] = 1;         }       }     }   }   int main() {     long long i, j, k;     long long xr, ans;     scanf( %d , &n);     for (i = 0; i < n; ++i) scanf( %d , &ara[i]);     for (i = 1; i < n; ++i) {       scanf( %d , &k);       k--;       child[k] = 1;       vt[i].push_back(k);       vt[k].push_back(i);     }     bfs();     for (i = 0; i < n; ++i)       if (!child[i]) leaf = i;     for (i = 0, xr = 0, k = n; i < n; ++i) {       if (level[leaf] % 2 == level[i] % 2) xr ^= ara[i], k--, mp[ara[i]]++;       ;     }     ans = 0;     if (xr == 0) {       ans += (k * (k - 1)) / 2;       k = n - k;       ans += (k * (k - 1)) / 2;       for (i = 0; i < n; ++i) {         if (level[leaf] % 2 != level[i] % 2) ans += mp[ara[i]];       }     } else {       for (i = 0; i < n; ++i) {         if (level[leaf] % 2 == level[i] % 2) continue;         k = xr ^ ara[i];         ans += mp[k];       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int testnum;   const int maxn = 100005;   int par[maxn];   int size[maxn];   int find(int u) {     if (par[u] == u) return u;     return par[u] = find(par[u]);   }   bool unify(int u, int v) {     int cu = find(u), cv = find(v);     if (cu == cv) return true;     if (size[cu] > size[cv]) {       par[cv] = cu;       size[cu] += size[cv];     } else {       par[cu] = cv;       size[cv] += size[cu];     }     return false;   }   int n, m;   void preprocess() {     for (int i = 0; i < maxn; i++) {       par[i] = i;       size[i] = 1;     }   }   long long mod = 1000000009;   void solve() {     int a, b;     long long ans = 1;     for (int i = 0; i < m; i++) {       scanf( %d , &a);       scanf( %d , &b);       bool z = unify(a, b);       if (z) {         ans = (ans + ans) % mod;       }       cout << (ans - 1) << endl;     }   }   bool input() {     scanf( %d , &n);     scanf( %d , &m);     return true;   }   int main() {     preprocess();     int T = 1;     for (testnum = 1; testnum <= T; testnum++) {       if (!input()) break;       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     scanf(  %d , &n);     if (n <= 2) {       puts( No );       return 0;     }     puts( Yes );     if (n & 1) {       printf( 2 1 %d n , n);       printf( %d  , n - 2);       for (int i = 2; i < n; i++) printf( %d  , i);       puts(  );     } else {       printf( %d n , n / 2);       for (int i = 1; i <= n; i++)         if (i & 1) printf( %d  , i);       puts(  );       printf( %d n , n / 2);       for (int i = 1; i <= n; i++)         if (!(i & 1)) printf( %d  , i);       puts(  );     }   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   const long long N = 100000;   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  { ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  } ;   }   template <typename first, typename second>   ostream &operator<<(ostream &os, const pair<first, second> &p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T>   ostream &operator<<(ostream &os, const set<T> &v) {     os <<  [ ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  ] ;   }   template <typename T>   ostream &operator<<(ostream &os, const multiset<T> &v) {     os <<  [ ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  ] ;   }   template <typename first, typename second>   ostream &operator<<(ostream &os, const map<first, second> &v) {     os <<  [ ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << it->first <<   =   << it->second;     }     return os <<  ] ;   }   pair<long long, long long> get(multiset<long long> &m) {     auto it = m.end();     it--;     return {*m.begin(), *it};   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long n;     cin >> n;     long long p;     cin >> p;     long long q;     cin >> q;     long long r;     cin >> r;     vector<long long> a(n);     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     vector<long long> temp;     temp.push_back(p);     temp.push_back(q);     temp.push_back(r);     multiset<long long> m(a.begin(), a.end()), pref;     ;     long long res = LLONG_MIN;     for (long long i = 0; i < n; i++) {       pref.insert(a[i]);       pair<long long, long long> left = get(pref);       pair<long long, long long> ryt = get(m);       long long mid = a[i];       long long cur = mid * temp[1];       if (temp[0] > 0) {         cur += (temp[0] * left.second);       } else {         cur += (temp[0] * left.first);       }       if (temp[2] > 0) {         cur += (temp[2] * ryt.second);       } else {         cur += (temp[2] * ryt.first);       }       res = max(res, cur);       m.erase(m.find(a[i]));     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int ab, bc, ca, abc;     int temp[4];     for (int i = 0; i < 4; i++) {       cin >> temp[i];     }     sort(temp, temp + 4);     ab = temp[0];     bc = temp[1];     ca = temp[2];     abc = temp[3];     int a, b, c;     a = abc - bc;     b = ab - a;     c = ca - a;     cout << a <<     << b <<     << c << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <class T1>   void deb(T1 e) {     cout << e << endl;   }   template <class T1, class T2>   void deb(T1 e1, T2 e2) {     cout << e1 <<     << e2 << endl;   }   template <class T1, class T2, class T3>   void deb(T1 e1, T2 e2, T3 e3) {     cout << e1 <<     << e2 <<     << e3 << endl;   }   template <class T1, class T2, class T3, class T4>   void deb(T1 e1, T2 e2, T3 e3, T4 e4) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 << endl;   }   template <class T1, class T2, class T3, class T4, class T5>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 << endl;   }   template <class T1, class T2, class T3, class T4, class T5, class T6>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 <<     << e6          << endl;   }   string st;   long long cum1[500010], cum2[500010], cum3[500010], cumhelp3[500010];   bool okay(char ch) {     return ch ==  A  || ch ==  E  || ch ==  I  || ch ==  O  || ch ==  U  ||            ch ==  Y ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     int mini, i, j, n, baki1, baki2;     cin >> st;     for (i = 0; i < st.size(); i++) {       if (!okay(st[i])) continue;       baki1 = i;       baki2 = st.size() - i - 1;       mini = min(baki1, baki2);       mini++;       cum1[1]++;       cum1[mini + 1]--;       if (baki1 > baki2) swap(baki1, baki2);       if (baki2 > baki1) {         cum2[baki1 + 2] += mini;         cum2[baki2 + 2] -= mini;       }       mini--;       cumhelp3[st.size() - mini + 2]--;       cum3[st.size() - mini + 1] += mini;     }     double ans = 0;     for (i = 1; i <= st.size(); i++) {       cum1[i] += cum1[i - 1];       cum2[i] += cum2[i - 1];       cumhelp3[i] += cumhelp3[i - 1];       cum3[i] += cum3[i - 1] + cumhelp3[i];     }     for (i = 1; i <= st.size(); i++) {       cum1[i] *= (long long)i;       ans += (double)(cum1[i] + cum2[i] + cum3[i]) / (double)i;     }     cout << fixed << setprecision(12) << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b, T, ans = 0;     cin >> n >> a >> b >> T;     vector<int> d(n, 1);     for (int& p : d) {       char c;       cin >> c;       if (c ==  w ) p += b;     }     vector<int> rtime(n), ltime(n);     rtime[0] = d[0], ltime[0] = d[0];     for (int i = 1; i < n; i++) {       rtime[i] = d[i] + a + rtime[i - 1];       ltime[i] = d[n - i] + a + ltime[i - 1];     }     if (d[0] <= T) ans = 1;     for (int i = 1; i < n; i++) {       int time = T - rtime[i];       if (time >= 0) ans = max(ans, 1 + i);       time -= i * a;       if (time > 0) {         time += d[0];         int num_left =             lower_bound(ltime.begin(), ltime.end(), time) - ltime.begin();         if (ltime[num_left] > time && num_left > 0) num_left--;         ans = max(ans, 1 + i + num_left);       }     }     for (int i = 1; i < n; i++) {       int time = T - ltime[i];       if (time >= 0) ans = max(ans, 1 + i);       time -= i * a;       if (time > 0) {         time += d[0];         int num_right =             lower_bound(rtime.begin(), rtime.end(), time) - rtime.begin();         if (rtime[num_right] > time && num_right > 0) num_right--;         ans = max(ans, 1 + i + num_right);       }     }     cout << min(n, ans) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int n, l;     cin >> n >> l;     int arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     sort(arr, arr + n);     double maxy = INT_MIN * 1.0;     for (int i = 0; i < n - 1; i++) {       if (arr[i + 1] - arr[i] > maxy) maxy = arr[i + 1] - arr[i];     }     maxy *= 1.0;     if (arr[0] == 0 or arr[n - 1] == l) {       if (arr[0] == 0 and arr[n - 1] == l) {         cout << fixed << setprecision(10) << maxy / 2;       } else if (arr[0] == 0) {         cout << fixed << setprecision(10) << max(maxy / 2, (l - arr[n - 1]) * 1.0)              <<   n ;       } else {         cout << fixed << setprecision(10) << max(maxy / 2, (arr[0]) * 1.0)              <<   n ;       }     } else {       cout << fixed << setprecision(10)            << max(maxy / 2, max(l - arr[n - 1], arr[0]) * 1.0) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long max(long long a, long long b) {     if (a > b)       return a;     else       return b;   }   long long min(long long a, long long b) {     if (a < b)       return a;     else       return b;   }   long long power(long long B, long long P) {     if (P == 0) return 1;     long long X = power(B, P / 2);     if (P % 2 == 0)       return X * X;     else       return B * X * X;   }   long long fx4[] = {1, -1, 0, 0};   long long fy4[] = {0, 0, 1, -1};   int main() {     long long T, N, M, X, Y, W, K, Q, R, P;     cin >> N >> M;     long long e1 = 0, o1 = 0, e2 = 0, o2 = 0;     for (int i = 1; i <= N; i++) {       cin >> X;       if (X % 2)         o1++;       else         e1++;     }     for (int i = 1; i <= M; i++) {       cin >> X;       if (X % 2)         o2++;       else         e2++;     }     cout << (min(e1, o2) + min(o1, e2)) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x6fffffff;   const int MINF = 0x80000000;   const long long mod = 1000000007;   const int cons = 100001;   const double pi = 3.141592653589793;   vector<int> pos;   bool isOk(int x, int t) {     double res = 0;     for (int i = 1; i < pos.size(); i++) {       int diff = pos[i] - pos[i - 1];       int l = -1;       int r = x + 1;       while (l + 1 < r) {         int mid = l + r >> 1;         int y = x - mid;         double avail = (double)y / 2 + mid;         if (avail >= (double)diff)           r = mid;         else           l = mid;       }       if (r == x + 1) return false;       diff -= r;       res += (double)r * 2;       res += min((double)diff, ((double)x - r) / 2);     }     return res <= (double)t;   }   int main() {     int n, k, s, t;     cin >> n >> k >> s >> t;     map<int, int> M;     for (int i = 0; i < n; i++) {       int c, v;       scanf( %d%d , &c, &v);       M[c] = max(M[c], v);     }     int cur = 0;     vector<pair<int, int> > dat;     for (auto it : M) {       if (cur < it.second) {         cur = it.second;         dat.push_back(it);       }     }     pos.resize(k);     for (int i = 0; i < k; i++) {       scanf( %d , &pos[i]);     }     pos.push_back(0);     pos.push_back(s);     sort(pos.begin(), pos.end());     int L = -1;     int R = dat.size();     while (L + 1 < R) {       int mid = L + R >> 1;       if (isOk(dat[mid].second, t))         R = mid;       else         L = mid;     }     if (R == dat.size())       puts( -1 );     else       printf( %d n , dat[R].first);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:1024000000,1024000000 )   template <typename T>   T Max(T a, T b) {     return a > b ? a : b;   }   template <typename T>   T Min(T a, T b) {     return a < b ? a : b;   }   template <typename T>   T Abs(T A) {     return A > 0 ? A : -1 * A;   }   template <typename T>   void Swap(T &a, T &b) {     T tmp = a;     a = b;     b = tmp;   }   const long long LINF = 0x3FFFFFFFFFFFFFFLL;   const int INF = 0X3FFFFFFF;   const int MAXN = 1e5 + 5;   long long sum[MAXN << 2][5];   int cnt[MAXN << 2];   char opt[MAXN][5];   int a[MAXN], c[MAXN];   inline void PushUp(int rt) {     for (int i = 0; i < 5; i++)       sum[rt][i] =           sum[rt << 1][i] + sum[rt << 1 | 1][((i - cnt[rt << 1]) % 5 + 5) % 5];   }   void Build(int l, int r, int rt) {     cnt[rt] = 0;     fill(sum[rt], sum[rt] + 5, 0);     if (l == r) return;     int m = (l + r) >> 1;     Build(l, m, rt << 1);     Build(m + 1, r, rt << 1 | 1);   }   void update(int pos, int val, int col, int l, int r, int rt) {     if (col)       cnt[rt]++;     else       cnt[rt]--;     if (l == r) {       sum[rt][0] = (long long)col * val;       return;     }     int m = (l + r) >> 1;     if (pos <= m)       update(pos, val, col, l, m, rt << 1);     else       update(pos, val, col, m + 1, r, rt << 1 | 1);     PushUp(rt);   }   int main() {     int n;     while (~scanf( %d , &n)) {       int id = 0;       for (int i = 1; i <= n; i++) {         scanf( %s , opt[i]);         if (opt[i][0] !=  s ) {           scanf( %d , c + i);           a[id++] = c[i];         }       }       sort(a, a + id);       int num = unique(a, a + id) - a;       if (num)         Build(1, num, 1);       else         sum[1][2] = 0;       for (int i = 1; i <= n; i++) {         int pos = lower_bound(a, a + num, c[i]) - a + 1;         if (opt[i][0] ==  a )           update(pos, c[i], 1, 1, num, 1);         else if (opt[i][0] ==  d ) {           if (cnt[1]) update(pos, c[i], 0, 1, num, 1);         } else {           if (cnt[1] == 0) sum[1][2] = 0;           printf( %I64d n , sum[1][2]);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 2e5 + 5;   const long long base = 9999991;   int n, m;   char s1[maxN], s2[maxN];   vector<int> res;   long long p[maxN], h1[30], h2[30];   int mark[30];   int check() {     for (int i = 0; i <= 25; ++i)       if (h1[i]) {         mark[i] = -1;         for (int j = 0; j <= 25; ++j)           if (h1[i] == h2[j]) mark[i] = j;         if (mark[i] == -1) return 0;       } else         mark[i] = -2;     for (int i = 0; i <= 25; ++i)       if (h1[i] && mark[mark[i]] != i && mark[mark[i]] != -2) return 0;     return 1;   }   int main() {     scanf( %d %d n%s n%s , &n, &m, s1 + 1, s2 + 1);     p[0] = 1;     for (int i = 1; i <= n; ++i) p[i] = p[i - 1] * 2 % base;     for (int i = 1; i <= m; ++i)       for (int j = 0; j <= 25; ++j) {         if (s1[i] -  a  == j)           h1[j] = (h1[j] * 2 + 1) % base;         else           h1[j] = h1[j] * 2 % base;         if (s2[i] -  a  == j)           h2[j] = (h2[j] * 2 + 1) % base;         else           h2[j] = h2[j] * 2 % base;       }     if (check()) res.push_back(1);     for (int i = m + 1; i <= n; ++i) {       for (int j = 0; j <= 25; ++j) {         if (s1[i - m] -  a  == j) h1[j] = (h1[j] - p[m - 1] + base) % base;         ;         if (s1[i] -  a  == j)           h1[j] = (h1[j] * 2 + 1) % base;         else           h1[j] = h1[j] * 2 % base;       }       if (check()) res.push_back(i - m + 1);     }     printf( %d n , (int)res.size());     for (int i = 0; i < (int)res.size(); ++i) printf( %d  , res[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, c;     cin >> a >> b >> c;     long long sum = 2 * c;     sum += 2 * min(a, b);     if (a > b || b > a) sum++;     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int ans = INT_MAX;     char W[100001];     scanf( %100000s , W);     string s = W, t =  Bulbasaur ;     map<char, int> I, M;     for (char ch : t) ++I[ch];     for (char ch : s) ++M[ch];     for (auto p : I) {       ans = min(ans, M[p.first] / p.second);     }     printf( %d , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5;   const int lg = 22;   int spt[2 * N + 100][lg], par[N + 100][lg], H[N + 100], E[2 * N + 100],       L[2 * N + 100];   int dept[2 * N + 100], vis[N + 100], mx[N + 100][lg], P[N + 100],       rg[2 * N + 100], idx = 1;   vector<pair<int, int> > g[N + 100];   vector<pair<long, pair<int, int> > > edge1, edge2;   int find(int i) {     if (P[i] == i) return i;     return P[i] = find(P[i]);   }   bool sameset(int i, int j) { return (find(i) == find(j)); }   void dfs(int v, int dep, int p) {     dept[v] = dep;     H[v] = idx;     L[idx] = dep;     E[idx++] = v;     for (auto it : g[v]) {       if (it.first != p) {         mx[it.first][0] = it.second;         par[it.first][0] = v;         dfs(it.first, dep + 1, v);         E[idx] = v;         L[idx++] = dep;       }     }   }   int getmin(int i, int j) {     int l = min(i, j), r = max(i, j);     int lr = rg[r - l + 1];     if (L[spt[l][lr]] <= L[spt[r - (1 << lr) + 1][lr]])       return spt[l][lr];     else       return spt[r - (1 << lr) + 1][lr];   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w);       edge1.push_back(make_pair(w, make_pair(u, v)));       edge2.push_back(make_pair(w, make_pair(u, v)));     }     sort(edge1.begin(), edge1.end());     for (int i = 1; i <= n; i++) P[i] = i;     for (int i = 0; (1 << i) <= 2 * N; i++) {       rg[1 << i] = i;     }     for (int i = 1; i <= 2 * N; i++) {       if (!rg[i]) rg[i] = rg[i - 1];     }     long long ans = 0;     for (auto it : edge1) {       int t1 = it.first;       int u = it.second.first, v = it.second.second;       if (!sameset(u, v)) {         ans += t1;         g[u].push_back(make_pair(v, t1));         g[v].push_back(make_pair(u, t1));         u = find(u);         v = find(v);         P[v] = u;       }     }     memset(dept, -1, sizeof dept);     dfs(1, 0, 0);     for (int j = 1; j < lg; j++) {       for (int i = 1; i <= n; i++) {         par[i][j] = par[par[i][j - 1]][j - 1];         mx[i][j] = max(mx[i][j - 1], mx[par[i][j - 1]][j - 1]);       }     }     for (int i = 1; i < 2 * n; i++) {       spt[i][0] = i;     }     for (int j = 1; j < lg; j++) {       for (int i = 1; i + (1 << j) - 1 < 2 * n; i++) {         if (L[spt[i][j - 1]] <= L[spt[i + (1 << (j - 1))][j - 1]])           spt[i][j] = spt[i][j - 1];         else           spt[i][j] = spt[i + (1 << (j - 1))][j - 1];       }     }     for (auto it : edge2) {       int u = it.second.first, v = it.second.second;       int lcs = E[getmin(H[u], H[v])];       int minus = 0;       int cur = u;       for (int i = lg - 1; i >= 0; i--) {         if (dept[par[cur][i]] >= dept[lcs]) {           minus = max(minus, mx[cur][i]);           cur = par[cur][i];         }       }       cur = v;       for (int i = lg - 1; i >= 0; i--) {         if (dept[par[cur][i]] >= dept[lcs]) {           minus = max(minus, mx[cur][i]);           cur = par[cur][i];         }       }       printf( %lld n , ans + it.first - minus);     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000 + 10;   int n;   int data[maxn];   int f[25][maxn];   bool mark[(1 << 25)], tt;   int res = 0, p;   int tmp;   int tm, tp;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> data[i];     memset(mark, 0, sizeof(mark));     for (int k = 0; k <= 20; k++) {       p = -1;       for (int i = n; i >= 1; i--) {         if ((data[i] & (1 << k)) == 0) {           if (p == -1) {             p = i;           }           f[k][i] = p;         } else           p = -1;       }     }     for (int i = 1; i <= n; i++) {       tmp = data[i];       if (!mark[tmp]) {         mark[tmp] = 1;         res++;       }       p = i;       while (p <= n) {         tm = n + 1;         for (int k = 0; k <= 20; k++)           if ((tmp & (1 << k)) == 0 && f[k][i] < tm && f[k][i] > 0) {             tp = k;             tm = f[k][i];           }         if (tm >= n) break;         for (int k = 0; k <= 20; k++)           if (f[k][i] == tm) tmp += (1 << k);         if (!mark[tmp]) {           mark[tmp] = 1;           res++;         }         p = tm + 1;       }     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<string, int> person;   vector<pair<int, string> > points;   int cnt;   bool compare(pair<int, string> a, pair<int, string> b) {     if (a.first == b.first) return a.second < b.second;     return a.first > b.first;   }   void update(string name, int p = 0) {     if (!person[name]) {       person[name] = ++cnt;       points.push_back(make_pair(p, name));     } else       points[person[name] - 1].first += p;   }   int main() {     string me;     int n;     cin >> me >> n;     for (int i = 0; i < n; i++) {       string X, Y, type, temp;       cin >> X >> type;       int point;       if (type ==  posted ) {         cin >> temp >> Y >> temp;         point = 15;       } else if (type ==  commented ) {         cin >> temp >> Y >> temp;         point = 10;       } else {         cin >> Y >> temp;         point = 5;       }       Y = Y.substr(0, Y.length() - 2);       if (X == me)         update(Y, point);       else if (Y == me)         update(X, point);       else         update(X), update(Y);     }     sort(points.begin(), points.end(), compare);     for (int i = 0; i < cnt; i++) cout << points[i].second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int maxn = 2e6 + 5;   char s[maxn], t[maxn];   int m;   struct Suffixam {     struct state {       int len, link;       map<char, int> next;     };     int id[maxn << 1], size[maxn << 1], cnt[maxn << 1];     state st[maxn << 1];     int last, sz;     int vis[maxn << 1];     void sam_init() {       memset(vis, -1, sizeof(vis));       sz = 0;       st[0].len = 0;       st[0].link = -1;       st[0].next.clear();       sz++;       last = 0;     }     void sam_extend(char c) {       int cur = sz++;       st[cur].len = st[last].len + 1;       st[cur].next.clear();       size[cur] = 1;       int p = last;       while (~p && !st[p].next.count(c)) {         st[p].next[c] = cur;         p = st[p].link;       }       if (p == -1) {         st[cur].link = 0;       } else {         int q = st[p].next[c];         if (st[p].len + 1 == st[q].len) {           st[cur].link = q;         } else {           int clone = sz++;           st[clone].len = st[p].len + 1;           st[clone].next = st[q].next;           st[clone].link = st[q].link;           while (~p && st[p].next[c] == q) {             st[p].next[c] = clone;             p = st[p].link;           }           st[q].link = st[cur].link = clone;         }       }       last = cur;     }     void get() {       for (int i = 1; i < sz; ++i) {         ++cnt[st[i].len];       }       for (int i = 1; i < sz; ++i) {         cnt[i] += cnt[i - 1];       }       for (int i = 1; i < sz; ++i) {         id[cnt[st[i].len]--] = i;       }       for (int i = sz; i >= 1; --i) {         size[st[id[i]].link] += size[id[i]];       }     }     void solve(const char *ss, int x) {       ll ans = 0;       int len = 0, now = 0;       for (int i = 0; ss[i]; ++i) {         if (st[now].next.count(ss[i]) != 0) {           now = st[now].next[ss[i]];           len++;           while (~now && st[st[now].link].len >= m) {             now = st[now].link;             len = st[now].len;           }           if (vis[now] != x && len >= m) {             ans += size[now];             vis[now] = x;           }         } else {           while (~now && !st[now].next.count(ss[i])) {             now = st[now].link;           }           if (now != -1) {             len = st[now].len + 1;             now = st[now].next[ss[i]];           } else {             len = 0;             now = 0;           }           while (~now && st[st[now].link].len >= m) {             now = st[now].link;             len = st[now].len;           }           if (vis[now] != x && len >= m) {             ans += size[now];             vis[now] = x;           }         }       }       printf( %lld n , ans);     }   } sam;   int main() {     scanf( %s , s + 1);     int n = strlen(s + 1);     sam.sam_init();     for (int i = 1; i <= n; ++i) {       sam.sam_extend(s[i]);     }     sam.get();     int q;     scanf( %d , &q);     while (q--) {       scanf( %s , t + 1);       m = strlen(t + 1);       for (int i = 1; i <= m; ++i) {         t[i + m] = t[i];       }       t[2 * m + 1] = 0;       sam.solve(t + 1, q);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mN = 30;   int a[mN];   int n;   void output(int x) {     string s;     string mid;     for (int i = 1; i <= n; i++) {       if (a[i] / x % 2) mid += char(i +  a  - 1);       for (int j = 1; j <= a[i] / x / 2; j++) s += char(i +  a  - 1);     }     s += mid;     for (int i = n; i >= 1; i--) {       for (int j = 1; j <= a[i] / x / 2; j++) s += char(i +  a  - 1);     }     for (int i = 1; i <= x; i++) {       cout << s;       reverse(s.begin(), s.end());     }   }   int gcd(int x, int y) {     if (x % y == 0) return y;     return gcd(y, x % y);   }   int main() {     cin >> n;     int odd = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] % 2) odd++;     }     int maxl = a[1];     for (int i = 2; i <= n; i++) maxl = gcd(maxl, a[i]);     if (odd > 1) {       cout << 0 << endl;       output(1);     } else if (maxl > 1) {       if (odd <= 1) {         cout << maxl << endl;         output(maxl);       }     } else {       cout << maxl << endl;       output(maxl);     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 130 * 1000 + 5;   const int mod = 1000 * 1000 * 1000 + 7;   short dp[21][32][maxN];   int mas[maxN];   int ss[6][maxN];   int a[20], b[20];   vector<int> v[6];   int c[20], d[20];   int n, m;   char ans[20][20];   int p;   void solve(int lev, int mask, int state) {     if (lev == 0) return;     int tmp = state;     for (int z = 0; z < n; z++) {       c[z] = tmp % p;       tmp /= p;     }     int smask = dp[lev][mask][state];     for (int j = 0; j < n; j++) {       d[j] = c[j];       if ((mask >> j & 1) != (smask >> j & 1)) {         if (mask >> j & 1) d[j]--;       }     }     int sstate = 0;     for (int j = n - 1; j >= 0; j--) sstate *= p, sstate += d[j];     solve(lev - 1, smask, sstate);     for (int i = 0; i < n; i++) ans[i][lev - 1] = ((mask >> i & 1) ?  *  :  . );   }   int tof[32][32], tofm[32][32];   int main() {     ios::sync_with_stdio(0);     cin.tie();     memset(dp, -1, sizeof dp);     cin >> n >> m;     for (int mask = 0; mask < (1 << n); mask++) {       int bef = 0, st = 0;       for (int i = 0; i < n; i++)         if (mask >> i & 1) {           if (bef == 0) st++;           bef = 1;         } else           bef = 0;       v[st].push_back(mask);     }     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) cin >> b[i];     p = *max_element(a, a + n);     p++;     int stat = 0;     for (int i = n - 1; i >= 0; i--) stat *= p, stat += a[i];     for (int state = 0; state < stat + 1; state++) {       int tmp = state;       for (int z = 0; z < n; z++) {         ss[z][state] = tmp % p;         if (ss[z][state] == 0) mas[state] |= (1 << z);         tmp /= p;       }     }     for (int mask = 0; mask < (1 << n); mask++)       for (int smask = 0; smask < (1 << n); smask++) {         int pp = 0;         for (int j = 0; j < n; j++) {           d[j] = 0;           if ((mask >> j & 1) != (smask >> j & 1)) {             if (mask >> j & 1) d[j]--, tofm[mask][smask] |= (1 << j);           }         }         int sstate = 0;         for (int j = n - 1; j >= 0; j--) sstate *= p, sstate += d[j];         tof[mask][smask] = sstate;       }     for (int i = 1; i < m + 1; i++) {       int ind = b[i - 1];       for (int state = 0; state < stat + 1; state++) {         for (auto mask : v[ind]) {           for (auto smask : v[(i == 1 ? 0 : b[i - 2])]) {             if (tofm[mask][smask] & mas[state]) continue;             int sstate = state + tof[mask][smask];             if (dp[i - 1][smask][sstate] != -1 ||                 (i == 1 && sstate == 0 && smask == 0)) {               dp[i][mask][state] = smask;               break;             }           }         }       }     }     int answer = -1;     for (int i = 0; i < (1 << n); i++) {       if (dp[m][i][stat] > -1) {         answer = i;         break;       }     }     solve(m, answer, stat);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) cout << ans[i][j];       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   long long min(long long x, long long y) {     if (x > y)       return y;     else       return x;   }   int main() {     long long n, m;     long long k;     scanf( %I64d %I64d %I64d , &n, &m, &k);     long long l = 1, r = n * m, mid, sum;     while (l <= r) {       mid = (l + r) >> 1;       sum = 0;       for (int i = 1; i <= n; i++) sum += min(m, (mid - 1) / i);       if (sum < k)         l = mid + 1;       else         r = mid - 1;     }     printf( %I64d , l - 1);     scanf(   );   }


#include <bits/stdc++.h>   using namespace std;   bool vis[8][8];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     char t;     int y, x;     cin >> t >> y;     --y;     x = t -  a ;     for (int i = 0; i < 8; i++) {       vis[i][y] = true;       vis[x][i] = true;     }     auto mark = [&](int x, int y) {       vis[x][y] = true;       for (int i = -2; i <= 2; i++) {         for (int j = -2; j <= 2; j++) {           if (i * i + j * j != 5) continue;           int dx = x + i, dy = y + j;           if (dx >= 0 && dx < 8 && dy >= 0 && dy < 8) vis[dx][dy] = true;         }       }     };     mark(x, y);     cin >> t >> y;     t;     --y;     mark(t -  a , y);     int cnt = 0;     for (int i = 0; i < 8; i++) {       for (int j = 0; j < 8; j++) cnt += vis[i][j];     }     cout << 64 - cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = (long long)1e16;   const int N = 900300;   const int K = 40;   int n;   long long a[N];   long long sum[N];   long long dp[N][2];   int par[N][2][3];   int intPoint[N];   int m;   vector<int> ans;   long long getCost(int L, int R, int f1, int f2) {     int len = R - L;     if (len == 1) {       if (a[L] == 0) return 0;       if (f1 == 0 || f2 == 0) return -1;       return a[L];     }     if (len == 2) {       if (a[L] == a[L + 1]) return 0;       if (a[L] < a[L + 1]) {         if (f2 == 0) return -1;         return abs(a[L + 1] - a[L]);       } else {         if (f1 == 0) return -1;         return abs(a[L + 1] - a[L]);       }     }     if (f1 == 0 && a[L] > a[L + 1]) return -1;     if (f2 == 0 && a[R - 1] > a[R - 2]) return -1;     long long cost = abs(sum[R] - sum[L]);     if (len == 3) {       if (a[L] + a[L + 2] <= a[L + 1]) return cost;       if (f1 == 1 && f2 == 1) return cost;       if (f1 == 0 && f2 == 0) return -1;       return cost;     }     return cost;   }   void restoreAns(int L, int R, int f1, int f2) {     int len = R - L;     if (len == 1) {       return;     }     if (len == 2) {       if (a[L] == 0 || a[L + 1] == 0) return;       ans.push_back(L);       return;     }     if (f1 == 0 && a[L] != 0 && a[L + 1] != 0) {       long long x = min(a[L], a[L + 1]);       ans.push_back(L);       a[L] -= x;       a[L + 1] -= x;     }     if (f2 == 0 && a[R - 1] != 0 && a[R - 2] != 0) {       long long x = min(a[R - 1], a[R - 2]);       ans.push_back(R - 2);       a[R - 2] -= x;       a[R - 1] -= x;     }     for (int i = L; i < R - 1; i++) {       if (a[i] != 0 && a[i + 1] != 0) {         long long x = min(a[i], a[i + 1]);         ans.push_back(i);         a[i] -= x;         a[i + 1] -= x;       }     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %lld , &a[i]);       sum[i + 1] = sum[i];       if (i % 2 == 0)         sum[i + 1] += a[i];       else         sum[i + 1] -= a[i];     }     for (int i = 0; i <= n; i++) {       if (i < 5 || i > n - 5) {         intPoint[m++] = i;         continue;       }       if (a[i - 1] <= a[i - 2] || a[i] <= a[i + 1]) intPoint[m++] = i;     }     for (int i = 0; i <= m; i++) dp[i][0] = dp[i][1] = -INF;     dp[0][0] = 0;     dp[0][1] = 0;     for (int i = 0; i < m; i++)       for (int f1 = 0; f1 < 2; f1++) {         if (dp[i][f1] < 0) continue;         for (int j = i + 1; j < min(m, i + K); j++) {           for (int f2 = 0; f2 < 2 - f1; f2++)             for (int f3 = 0; f3 < 2; f3++) {               long long cost = getCost(intPoint[i], intPoint[j], f2, f3);               if (cost == -1) continue;               if (dp[i][f1] + cost > dp[j][f3]) {                 dp[j][f3] = dp[i][f1] + cost;                 par[j][f3][0] = i;                 par[j][f3][1] = f1;                 par[j][f3][2] = f2;               }             }         }       }     int x = m - 1;     int f = 0;     if (dp[x][1] > dp[x][0]) f = 1;     while (x > 0) {       restoreAns(intPoint[par[x][f][0]], intPoint[x], par[x][f][2], f);       int nx = par[x][f][0];       f = par[x][f][1];       x = nx;     }     printf( %d n , (int)ans.size());     for (int y : ans) printf( %d n , 1 + y);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int p[111], s[111], v[111];   int main() {     int n, m, k, i, Nr = 0, c;     cin >> n >> m >> k;     for (i = 1; i <= n; ++i) cin >> p[i];     for (i = 1; i <= n; ++i) {       cin >> s[i];       if (p[i] > v[s[i]]) v[s[i]] = p[i];     }     for (i = 1; i <= k; ++i) {       cin >> c;       if (p[c] < v[s[c]]) Nr++;     }     cout << Nr <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, u, cnt = 1, ch[4000005][4], dp[4000005][4], dpp[60][4][4];   long long rev[2][4], nw = 0, ans = 0;   char s[100005];   const long long inf = 2e18;   void dfs(int p) {     for (int i = 0; i < 4; i++) dp[p][i] = inf;     for (int i = 0; i < 4; i++) {       if (!ch[p][i])         dp[p][i] = 0;       else {         dfs(ch[p][i]);         for (int j = 0; j < 4; j++) dp[p][j] = min(dp[p][j], dp[ch[p][i]][j] + 1);       }     }   }   int main() {     scanf( %lld%s , &n, s + 1);     m = strlen(s + 1);     for (int i = 1; i <= m; i++) {       int lim = min(m, 1ll * i + 39);       u = 1;       for (int j = i; j <= lim; j++) {         int le = s[j] -  A ;         if (!ch[u][le]) ch[u][le] = ++cnt;         u = ch[u][le];       }     }     dfs(1);     for (int i = 0; i < 4; i++)       for (int j = 0; j < 4; j++) dpp[0][i][j] = dp[ch[1][i]][j] + 1;     for (int i = 1; i < 60; i++) {       for (int j = 0; j < 4; j++) {         for (int k = 0; k < 4; k++) {           dpp[i][j][k] = inf;           for (int u = 0; u < 4; u++)             dpp[i][j][k] = min(dpp[i][j][k], dpp[i - 1][j][u] + dpp[i - 1][u][k]);         }       }     }     ans = 0;     for (int i = 59; i >= 0; i--) {       for (int j = 0; j < 4; j++) rev[!nw][j] = inf;       for (int j = 0; j < 4; j++)         for (int k = 0; k < 4; k++)           rev[!nw][k] = min(rev[!nw][k], rev[nw][j] + dpp[i][j][k]);       long long sum = inf;       for (int j = 0; j < 4; j++) sum = min(sum, rev[!nw][j]);       if (sum < n) {         ans += (1ll << i);         for (int j = 0; j < 4; j++)           if (rev[!nw][j] >= n) rev[!nw][j] = inf;       } else         for (int j = 0; j < 4; j++) rev[!nw][j] = rev[nw][j];       nw = !nw;     }     printf( %lld n , ans + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> ans, a;     int n, temp;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &temp);       a.push_back(temp);     }     for (int i = 0; i < a.size(); i++) {       if (a[i] == 1) {         ans.push_back(1);       } else {         ans[ans.size() - 1]++;       }     }     printf( %d n%d , (int)ans.size(), ans[0]);     for (int i = 1; i < ans.size(); i++) {       printf(  %d , ans[i]);     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     string gen =  ACTG ;     int sum = 10000;     vector<bool> used_big(n, false);     vector<bool> used_gen(4, false);     for (int i = 0; i <= n - 4; i++) {       int tmp_sum = 0;       for (int j = 0; j < 4; j++) {         int dif = abs(s[i + j] - gen[j]);         if (26 - dif < dif) dif = 26 - dif;         tmp_sum += dif;       }       if (tmp_sum < sum) sum = tmp_sum;     }     cout << sum;   }


#include <bits/stdc++.h>   using namespace std;   void precalc(){};   const int N = 3010;   int n, m;   vector<vector<int>> g;   vector<vector<int>> dist;   pair<int, int> pre[N][3], post[N][3];   void bfs(int x) {     queue<int> q;     q.push(x);     while (q.size()) {       int head = q.front();       q.pop();       for (auto c : g[head]) {         if (dist[x][c] > n) {           dist[x][c] = dist[x][head] + 1;           q.push(c);         }       }     }   }   inline bool distinct(int a, int b, int c, int d) {     vector<int> z = {a, b, c, d};     sort(z.begin(), z.end());     return z[0] != z[1] && z[1] != z[2] && z[2] != z[3];   }   void solve(int ncase) {     cin >> n >> m;     g.assign(n + 1, vector<int>());     dist.assign(n + 1, vector<int>(n + 1, n + 1));     for (int i = 1; i <= n; i++) {       dist[i][i] = 0;     }     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       g[x].push_back(y);     }     for (int i = 1; i <= n; i++) {       bfs(i);     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (dist[j][i] <= n) {           pair<int, int> tmppre = pair<int, int>(dist[j][i], j);           if (tmppre > pre[i][2]) {             pre[i][2] = tmppre;             if (pre[i][2] > pre[i][1]) {               swap(pre[i][2], pre[i][1]);               if (pre[i][1] > pre[i][0]) {                 swap(pre[i][1], pre[i][0]);               }             }           }         }         if (dist[i][j] <= n) {           pair<int, int> tmppost = pair<int, int>(dist[i][j], j);           if (tmppost > post[i][2]) {             post[i][2] = tmppost;             if (post[i][2] > post[i][1]) {               swap(post[i][2], post[i][1]);               if (post[i][1] > post[i][0]) {                 swap(post[i][1], post[i][0]);               }             }           }         }       }     }     int ans = -1;     vector<int> ret(4);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i == j || dist[i][j] > n) continue;         for (int a = 0; a < 3; a++) {           if (pre[i][a].second == 0) continue;           for (int b = 0; b < 3; b++) {             if (post[j][b].second == 0) continue;             int tmp = pre[i][a].first + dist[i][j] + post[j][b].first;             if (tmp > ans &&                 distinct(pre[i][a].second, i, j, post[j][b].second)) {               ans = tmp;               ret = {pre[i][a].second, i, j, post[j][b].second};             }           }         }       }     }     cout << ret[0] <<     << ret[1] <<     << ret[2] <<     << ret[3] << endl;   }   int main() {     int T = 1;     int ncase = 0;     while (T--) {       solve(++ncase);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t, c = 1;     cin >> n >> t;     int mn = INT_MAX;     for (int i = 1; i <= n; i++) {       int s, d;       cin >> s >> d;       while (s < t) {         s += d;       }       if (s < mn) {         mn = s;         c = i;       }     }     cout << c << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cerr.tie(0);     string a;     cin >> a;     vector<int> res[2];     for (char e : a) {       vector<int> ne[2];       if (e ==  a ) {         ne[0] = res[1];         ne[0].push_back(1);         ne[1] = res[1];         ne[1].push_back(0);       } else {         ne[0] = res[0];         ne[0].push_back(0);         ne[1] = res[0];         ne[1].push_back(1);       }       res[0] = ne[0];       res[1] = ne[1];     }     for (int e : res[0]) {       cout << e <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int v, m, d, f;   int main() {     int n, a, b, c;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a >> b >> c;       if (a == 1) {         v += b;         m += c;       } else {         d += b;         f += c;       }     }     if (v >= m)       cout <<  LIVE  <<   n ;     else       cout <<  DEAD  <<   n ;     if (d >= f)       cout <<  LIVE  <<   n ;     else       cout <<  DEAD  <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, 0, 1, -1, -1, -1, 1, 1};   int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};   template <class T>   inline T biton(T n, T pos) {     return n | ((T)1 << pos);   }   template <class T>   inline T bitoff(T n, T pos) {     return n & ~((T)1 << pos);   }   template <class T>   inline T ison(T n, T pos) {     return (bool)(n & ((T)1 << pos));   }   template <class T>   inline T gcd(T a, T b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   template <typename T>   string NumberToString(T Number) {     ostringstream second;     second << Number;     return second.str();   }   inline int nxt() {     int aaa;     scanf( %d , &aaa);     return aaa;   }   inline long long int lxt() {     long long int aaa;     scanf( %lld , &aaa);     return aaa;   }   inline double dxt() {     double aaa;     scanf( %lf , &aaa);     return aaa;   }   template <class T>   inline T bigmod(T p, T e, T m) {     T ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % m;       p = (p * p) % m;     }     return (T)ret;   }   int ar[200010];   vector<int> v;   map<int, int> mp;   int main() {     int c = 0;     int i = 1;     while (1) {       if (c > 100000) break;       c += i;       v.push_back(c);       mp[c] = i;       i++;     }     int n = nxt();     if (n == 0) {       cout <<  a  << endl;       return 0;     }     vector<int> ans;     while (n) {       for (int i = v.size() - 1; i >= 0; i--) {         if (v[i] <= n) {           ans.push_back(v[i]);           n -= v[i];         }       }     }     int t = 0;     for (int i = 0; i < ans.size(); i++) {       int x = ans[i];       int lagbe = mp[x];       for (int j = 0; j <= lagbe; j++) {         printf( %c , t +  a );       }       t++;     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 0x3f3f3f3f;   const long long MOD = 1e9 + 7;   const long double EPS = 1e-9;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string grid[3][3][3];     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) {         for (int k = 0; k < 3; k++) {           cin >> grid[i][k][j];         }       }     }     int a, b;     cin >> a >> b;     int gi = (a - 1) % 3;     int gj = (b - 1) % 3;     bool shit = true;     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) {         if (grid[gi][gj][i][j] ==  . ) shit = false;       }     }     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) {         for (int k = 0; k < 3; k++) {           if (shit || i == gi && k == gj) {             for (int l = 0; l < 3; l++) {               if (grid[i][k][j][l] ==  . )                 cout <<  ! ;               else                 cout << grid[i][k][j][l];             }             cout <<    ;           } else {             cout << grid[i][k][j] <<    ;           }         }         cout <<   n ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a, b, arr[100009];   int main() {     cin >> n >> a >> b;     for (int i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     cout << max(arr[n - a] - arr[n - a - 1], 0);   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);     long long n, m;     cin >> n >> m;     map<long long, set<long long>> adj;     for (long long i = 0; i < m; i++) {       long long a, b;       cin >> a >> b;       adj[a].insert(b);       adj[b].insert(a);     }     long long mx = INT_MIN, v = 0;     map<long long, long long> deg;     for (auto i : adj) {       deg[i.first] = i.second.size();       if (mx < i.second.size()) {         mx = i.second.size();         v = i.first;       }     }     deg[v] = 0;     for (auto i : adj[v]) {       deg[i]--;     }     long long f = 0;     for (long long i = 1; i <= n; i++) {       if (deg[i] > 0) {         f = 1;         break;       }     }     if (!f) {       cout <<  YES n ;       return 0;     }     mx = INT_MIN, v = 0;     for (long long i = 1; i <= n; i++) {       if (mx < deg[i]) {         mx = deg[i];         v = i;       }     }     deg[v] = 0;     for (auto i : adj[v]) {       deg[i]--;     }     f = 0;     for (long long i = 1; i <= n; i++) {       if (deg[i] > 0) {         f = 1;         break;       }     }     if (!f) {       cout <<  YES n ;       return 0;     }     cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1);   inline double cross(double x1, double y1010101010101, double x2, double y2) {     return x1 * x2 + y1010101010101 * y2;   }   inline double len(double x, double y) { return sqrt(x * x + y * y); }   inline double angle(double x1, double y1010101010101, double x2, double y2) {     if (x1 == 0 && y1010101010101 == 0) return pi;     if (x2 == 0 && y2 == 0) return pi;     return acos(cross(x1, y1010101010101, x2, y2) / len(x1, y1010101010101) /                 len(x2, y2));   }   int n, x[100005], y[100005], cur = 0;   struct data {     double tx, ty;     int fx, fy;     int cx, cy;     data operator~() {       data ans = *this;       ans.tx = -ans.tx;       ans.ty = -ans.ty;       ans.cx = -ans.cx;       ans.cy = -ans.cy;       return ans;     }   } d[100005 << 5];   inline data add(int x, int y, int cx, int cy) {     data ans;     ans.tx = d[x].tx * cx + d[y].tx * cy;     ans.ty = d[x].ty * cx + d[y].ty * cy;     ans.cx = cx;     ans.cy = cy;     ans.fx = x;     ans.fy = y;     return ans;   }   int neg[100005 << 5];   inline void dump(int x) {     if (x <= n) return;     neg[d[x].fx] = neg[x] * d[x].cx;     neg[d[x].fy] = neg[x] * d[x].cy;     dump(d[x].fx);     dump(d[x].fy);   }   inline void dfs(int x, int y, int z, int w) {     if (z == n + 1) {       d[++cur] = ~d[x];       d[++cur] = ~d[y];       vector<int> t;       t.push_back(x);       t.push_back(y);       t.push_back(cur - 1);       t.push_back(cur);       for (int i = 0; i < 4; i += 2)         for (int j = 1; j < 4; j += 2) {           int u = t[i], v = t[j];           if (len(d[u].tx + d[v].tx, d[u].ty + d[v].ty) <= 1500000.0) {             if (i == 2)               neg[x] = -1;             else               neg[x] = 1;             if (j == 3)               neg[y] = -1;             else               neg[y] = 1;             dump(x);             dump(y);             return;           }         }     }     d[++cur] = ~d[x];     d[++cur] = ~d[y];     d[++cur] = ~d[z];     vector<int> t;     t.push_back(x);     t.push_back(y);     t.push_back(z);     t.push_back(cur - 2);     t.push_back(cur - 1);     t.push_back(cur);     for (int i = 0; i < 6; i++)       for (int j = 0; j < i; j++) {         if ((i % 3) == (j % 3)) continue;         int a = t[i], b = t[j];         if (angle(d[a].tx, d[a].ty, d[b].tx, d[b].ty) >= 2.0 * pi / 3) {           d[++cur] = add(a, b, 1, 1);           int nxt = 3 - (i % 3) - (j % 3);           if (nxt == 0) dfs(cur, x, w, w + 1);           if (nxt == 1) dfs(cur, y, w, w + 1);           if (nxt == 2) dfs(cur, z, w, w + 1);           return;         }       }   }   int main() {     scanf( %d , &n);     if (n == 1) return puts( 1 ), 0;     for (int i = 1; i <= n; i++) scanf( %d%d , &x[i], &y[i]);     for (int i = 1; i <= n; i++) {       d[i].tx = x[i];       d[i].ty = y[i];       d[i].fx = i;       d[i].fy = 0;       d[i].cx = 1;       d[i].cy = 0;     }     cur = n;     dfs(1, 2, 3, 4);     for (int i = 1; i <= n; i++) printf( %d  , neg[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   const int mod = 1e9 + 7;   const long long inf = 1e17;   char a[maxn], b[maxn], s[maxn];   int v[200];   int main() {     int q;     scanf( %s%s , a, b);     int n = strlen(a);     for (int i = 0; i < n; ++i) v[a[i]] = 1;     n = strlen(b);     scanf( %d , &q);     while (q--) {       scanf( %s , s);       int len = strlen(s);       int o = len - n + 1;       if (o < 0) {         puts( NO );         continue;       }       int i = 0, j = 0, k;       while (i < n) {         if (b[i] == s[j]) {           i++;           j++;         } else if (b[i] ==  ?  && v[s[j]]) {           i++;           j++;         } else if (b[i] ==  * ) {           for (k = 0; k < o && j < len; ++k, ++j)             if (v[s[j]]) break;           if (k < o) break;           i++;         } else {           break;         }       }       if (i < n || j < len)         puts( NO );       else         puts( YES );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct hehe {     unsigned long long l, r;     mutable bool z;     inline bool operator<(hehe y) const { return l < y.l; }   };   set<hehe> s;   inline set<hehe>::iterator split(unsigned long long pos) {     hehe qaq;     qaq.l = pos;     qaq.r = 0;     qaq.z = 0;     set<hehe>::iterator itp = s.lower_bound(qaq);     if (itp->l == pos && itp != s.end()) return itp;     itp--;     unsigned long long l = itp->l, r = itp->r;     bool val = itp->z;     s.erase(itp);     qaq.l = l;     qaq.r = pos - 1;     qaq.z = val;     s.insert(qaq);     qaq.l = pos;     qaq.r = r;     qaq.z = val;     set<hehe>::iterator ret = s.insert(qaq).first;     return ret;   }   inline unsigned long long read() {     unsigned long long s = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) ch = getchar();     while (ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 , ch = getchar();     return s;   }   inline void rev(unsigned long long l, unsigned long long r) {     set<hehe>::iterator itr, itl;     itr = split(r + 1);     itl = split(l);     for (set<hehe>::iterator it = itl; it != itr; ++it) it->z ^= 1;   }   inline void fz(unsigned long long l, unsigned long long r,                  unsigned long long val) {     set<hehe>::iterator itl, itr;     itr = split(r + 1);     itl = split(l);     s.erase(itl, itr);     hehe qwq;     qwq.l = l;     qwq.r = r;     qwq.z = val;     s.insert(qwq);   }   inline unsigned long long que() {     for (set<hehe>::iterator it = s.begin(); it != s.end(); ++it) {       if (it->z == 0) return it->l;     }     return 1000000000000000001llu;   }   signed main() {     unsigned long long n;     n = read();     hehe qwq;     qwq.l = 1;     qwq.r = 1000000000000000000llu;     qwq.z = 0;     s.insert(qwq);     while (n--) {       unsigned long long opt, l, r;       opt = read();       l = read();       r = read();       if (opt == 1)         fz(l, r, 1);       else if (opt == 2)         fz(l, r, 0);       else if (opt == 3)         rev(l, r);       printf( %lld n , que());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   multiset<int> st;   multiset<int>::iterator it;   int arr[200000];   int main() {     int n, i, a, b, c, ans = 0, temp[3];     scanf( %d , &n);     scanf( %d , &temp[0]);     scanf( %d , &temp[1]);     scanf( %d , &temp[2]);     sort(temp, temp + 3);     a = temp[0];     b = temp[1];     c = temp[2];     for (i = 0; i < n; i++) {       scanf( %d , &arr[i]);       st.insert(-arr[i]);     }     for (i = 0; i < n; i++)       if (arr[i] > a + b + c) {         printf( -1 n );         return 0;       }     while (!st.empty()) {       it = st.lower_bound(-1 * (a + b + c));       if (it == st.end() or -1 * (*it) <= (b + c)) break;       st.erase(it);       ans++;     }     while (!st.empty()) {       it = st.lower_bound(-1 * (b + c));       if (it == st.end() or -1 * (*it) <= (a + c)) break;       st.erase(it);       it = st.lower_bound(-1 * (a));       if (it != st.end()) st.erase(it);       ans++;     }     while (!st.empty()) {       it = st.lower_bound(-1 * (a + c));       if (it == st.end() or -1 * (*it) <= (max(a + b, c))) break;       st.erase(it);       it = st.lower_bound(-1 * (b));       if (it != st.end()) st.erase(it);       ans++;     }     if ((a + b) > c) {       while (!st.empty()) {         it = st.lower_bound(-1 * (a + b));         if (it == st.end() or -1 * (*it) <= c) break;         st.erase(it);         it = st.lower_bound(-1 * (c));         if (it != st.end()) st.erase(it);         ans++;       }     }     while (!st.empty()) {       it = st.lower_bound(-1 * (c));       if (it == st.end()) break;       st.erase(it);       it = st.lower_bound(-1 * (b));       if (it != st.end()) {         st.erase(it);         it = st.lower_bound(-1 * (a));         if (it != st.end()) st.erase(it);       } else {         it = st.lower_bound(-1 * (a + b));         if (it != st.end()) st.erase(it);       }       ans++;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m, k;     cin >> n >> m >> k;     int best = 1e9;     for (int i = 0; i < k; i++) {       int x, y;       cin >> x >> y;       best = min(best, x - 1);       best = min(best, n - x);       best = min(best, y - 1);       best = min(best, m - y);     }     if (best > 4)       cout <<  NO n ;     else       cout <<  YES n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> ans1;     vector<char> ans2;     int n1, n2;     cin >> n1;     vector<int> a1(n1);     for (int i = 0; i < n1; i++) {       cin >> a1[i];     }     cin >> n2;     vector<int> a2(n2);     for (int i = 0; i < n2; i++) {       cin >> a2[i];     }     int now1 = 0, now2 = 0;     for (int i = 0; i < n2; i++) {       int s = 0;       while (now2 < n1 && s < a2[i]) {         s += a1[now2];         now2++;       }       if (now2 > n1 || s != a2[i] || now1 == now2) {         cout <<  NO ;         return 0;       }       int temp = now1;       for (int j = now1; j < now2; j++) {         if (a1[temp] <= a1[j] && (j - 1 >= now1 && a1[j - 1] < a1[j] ||                                   j + 1 < now2 && a1[j + 1] < a1[j])) {           temp = j;         }       }       if (temp == now1 && temp + 1 < now2 && a1[temp + 1] == a1[temp]) {         cout <<  NO ;         return 0;       }       if (temp - 1 >= now1 && a1[temp] > a1[temp - 1]) {         int him = a1[temp];         int j = temp - 1;         while (j >= now1 && him > a1[j]) {           him += a1[j];           ans1.push_back(i + j - now1 + 2);           ans2.push_back( L );           j--;         }         j = temp + 1;         while (j < now2 && him > a1[j]) {           him += a1[j];           ans1.push_back(i + 1);           ans2.push_back( R );           j++;         }       } else {         if (temp + 1 < now2 && a1[temp] > a1[temp + 1]) {           int him = a1[temp];           int j = temp + 1;           while (j < now2 && him > a1[j]) {             him += a1[j];             ans1.push_back(i + temp - now1 + 1);             ans2.push_back( R );             j++;           }           j = temp - 1;           while (j >= now1 && him > a1[j]) {             him += a1[j];             ans1.push_back(i + j - now1 + 2);             ans2.push_back( L );             j--;           }         }       }       now1 = now2;       now2 = now1;     }     if (now2 != a1.size()) {       cout <<  NO ;       return 0;     }     cout <<  YES  << endl;     for (int i = 0; i < ans1.size(); i++) {       cout << ans1[i] <<     << ans2[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long t, n;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> t;     while (t--) {       cin >> n;       long long k = 0, l = 0;       for (int i = 0; i < (n); i++) {         long long a;         cin >> a;         if (a % 2 != i % 2)           if (a % 2)             k++;           else             l++;       }       if (k != l)         cout <<  -1 n ;       else         cout << k <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   int tot;   struct node {     node *ch[26], *fail;     int len, id;     node* init(int tlen) {       memset(ch, 0, sizeof(ch));       fail = NULL;       len = tlen;       return this;     }   } * root, spT[N];   vector<int> g[N];   void addin(char* c) {     node* tmp = root;     while (*c !=   0 ) {       int t = *c -  a ;       if (tmp->ch[t] == NULL) tmp->ch[t] = spT[++tot].init(tmp->len + 1);       tmp = tmp->ch[t];       c++;     }   }   queue<node*> q;   int en, st;   void getfail() {     q.push(root);     while (!q.empty()) {       node* tmp = q.front();       q.pop();       for (int t = 0; t < 26; t++)         if (tmp->ch[t] != NULL) {           if (tmp == root)             tmp->ch[t]->fail = root;           else {             node* p = tmp->fail;             while (p != root && p->ch[t] == NULL) p = p->fail;             if (p->ch[t] != NULL)               tmp->ch[t]->fail = p->ch[t];             else               tmp->ch[t]->fail = root;           }           q.push(tmp->ch[t]);         }     }   }   char S[N];   int f[N][2];   int dfs(int x) {     f[x][0] = 0;     f[x][1] = 1;     for (auto p : g[x]) {       dfs(p);       f[x][1] += f[p][0];       f[x][0] += max(f[p][0], f[p][1]);     }     return max(f[x][0], f[x][1]);   }   bool v[N];   int main() {     int T, n;     for (int i = (1); i <= (N - 1); i++) spT[i].id = i;     cin >> T;     while (T--) {       root = spT[tot = 1].init(0);       cin >> n;       for (int i = (1); i <= (n); i++) {         scanf( %s , S);         addin(S);       }       getfail();       for (int i = (1); i <= (tot); i++) g[i].clear(), v[i] = 0;       for (int i = (1); i <= (tot); i++) {         node* tmp = &spT[i];         if (tmp->fail && tmp->fail != root && tmp->fail->len + 1 == tmp->len) {           g[tmp->fail->id].push_back(tmp->id);           v[tmp->id] = 1;         }       }       int ans = 0;       for (int i = (2); i <= (tot); i++)         if (!v[i]) ans += dfs(i);       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     string cad;     cin >> cad;     map<char, int> M;     for (int i = 0; i < cad.size(); i++) M[cad[i]]++;     int xx = M[ x ];     int yy = M[ y ];     int ans = max(xx, yy) - min(xx, yy);     if (max(xx, yy) == M[ x ])       cout << string(ans,  x ) << endl;     else       cout << string(ans,  y ) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200 * 1000 + 85;   int n, m;   int a[N];   vector<int> vec[N];   pair<pair<int, int>, int> b[N];   int mapp[N];   int ans[N];   int seg[N << 2];   inline void add(int, int, int = 1, int = 0, int = N);   inline int get(int, int = 1, int = 0, int = N);   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a[i];       mapp[a[i]] = i;     }     for (int i = 1; i <= n; i++) {       int j = 1;       while (j * i <= n) {         if (mapp[j * i] >= mapp[i]) vec[mapp[j * i]].push_back(mapp[i]);         if (mapp[i] > mapp[j * i]) vec[mapp[i]].push_back(mapp[j * i]);         j++;       }     }     for (int i = 0; i < m; i++) {       cin >> b[i].first.second >> b[i].first.first;       b[i].first.second--;       b[i].first.first--;       b[i].second = i;     }     sort(b, b + m);     int k = 0;     for (int t = 0; t < m; t++) {       while (k <= b[t].first.first) {         for (int i = 0; i < vec[k].size(); i++) add(0, vec[k][i] + 1);         k++;       }       ans[b[t].second] = get(b[t].first.second);     }     for (int i = 0; i < m; i++) cout << ans[i] <<   n ;   }   inline void add(int st, int en, int id, int l, int r) {     if (en <= l or r <= st) return;     if (st <= l and r <= en) {       seg[id]++;       return;     }     int mid = (l + r) >> 1, lc = id << 1, rc = lc | 1;     add(st, en, lc, l, mid);     add(st, en, rc, mid, r);   }   inline int get(int idx, int id, int l, int r) {     if (idx < l or r <= idx) return 0;     if (l + 1 == r) return seg[id];     int mid = (l + r) >> 1, lc = id << 1, rc = lc | 1;     return get(idx, lc, l, mid) + get(idx, rc, mid, r) + seg[id];   }


#include <bits/stdc++.h>   using namespace std;   int n, m, cnt;   vector<int> e[105];   bool f[105];   void dfs(int x) {     f[x] = 1, ++cnt;     for (int i = 0; i < e[x].size(); ++i)       if (!f[e[x][i]]) dfs(e[x][i]);   }   void work() {     int i, x, y;     scanf( %d%d , &n, &m);     if (n != m) {       puts( NO );       return;     }     for (i = 1; i <= m; ++i) {       scanf( %d%d , &x, &y);       e[x].push_back(y);       e[y].push_back(x);     }     dfs(1);     if (cnt == n)       puts( FHTAGN! );     else       puts( NO );   }   int main() {     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   const int N = 2e2 + 10;   int main() {     int n, m;     cin >> n >> m;     int l = 1, r = INF;     int ans = 0;     while (l <= r) {       int mid = (r + l) / 2;       int z = mid / 6;       int x = mid / 2 - z;       int y = mid / 3 - z;       if (z >= max(0, n - x) + max(0, m - y))         ans = mid, r = mid - 1;       else         l = mid + 1;     }     cout << ans << endl;     return 0;   }