#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 9;   const long long INF = 1e12;   int n = 100000;   long long a[MAXN];   long long f[20][MAXN];   void init() {     for (int i = 1; i <= n; i++) {       a[i] = i;     }     for (int i = 1; i <= n; i++) {       for (int j = i + i; j < MAXN; j += i) {         a[j] -= a[i];       }     }   }   long long c(int l, int r) {     long long ans = 0;     int lst = 0;     for (int i = l; i <= r; i = lst + 1) {       lst = r / (r / i);       ans += a[r / i] * (lst - i + 1ll);     }     return ans;   }   void work(long long *dpf, long long *dpg, int l, int r, int L, int R) {     if (l > r) return;     int mid = (l + r) / 2;     int opt = -1;     long long cost = c(min(mid - 1, R) + 1, mid);     for (int i = min(mid - 1, R); i >= L; i--) {       long long newf = dpf[i] + cost;       if (newf < dpg[mid]) {         dpg[mid] = newf;         opt = i;       }       cost += a[mid / i];     }     if (opt == -1) opt = L;     work(dpf, dpg, l, (mid - 1), L, opt);     work(dpf, dpg, (mid + 1), r, opt, R);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     init();     for (int i = 1; i < MAXN; i++) {       a[i] += a[i - 1];     }     f[0][0] = 0;     memset(f, 0x3f, sizeof(f));     for (int i = 1; i <= n; i++) {       f[1][i] = 1ll * i * (i + 1) / 2;     }     for (int i = 1; i < 16; i++) {       work(f[i], f[i + 1], 1, n, 1, n);     }     int T;     cin >> T;     while (T--) {       int n, k;       cin >> n >> k;       if (k >= 17) {         cout << n << endl;       } else {         cout << f[k][n] << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Max = 1e3, Max_Q = 1e4;   const int fx[8] = {0, 0, 1, 1, 1, -1, -1, -1};   const int fy[8] = {1, -1, 0, 1, -1, 0, 1, -1};   int h, w, Q, cnt, s, t, Top, siz, q[Max + 5], stk[Max + 5],       Id[Max + 5][Max + 5], fa[Max * Max + 5], vis[Max * Max + 5];   char S[Max + 5][Max + 5];   map<int, int> Tag[Max * Max + 5];   struct kk {     int x, y;   } A[20];   inline int Get(int x) { return x == fa[x] ? x : fa[x] = Get(fa[x]); }   inline int GET(int x) { return x == fa[x] ? x : GET(fa[x]); }   int main() {     scanf( %d%d%d , &h, &w, &Q);     for (int i = 1; i <= h; i++) scanf( %s , S[i] + 1);     for (int i = 1; i <= h; i++)       for (int j = 1; j <= w; j++) Id[i][j] = ++cnt;     s = ++cnt, t = ++cnt;     for (int i = 1; i <= w; i++) Id[0][i] = s, Id[h + 1][i] = t;     for (int i = 1; i <= h; i++) Id[i][0] = t, Id[i][w + 1] = s;     vis[s] = vis[t] = 1;     for (int i = 1; i <= h; i++)       for (int j = 1; j <= w; j++) vis[Id[i][j]] = S[i][j] ==  # ;     for (int i = 1; i <= cnt; i++) fa[i] = i;     for (int i = 1; i <= h; i++)       for (int j = 1; j <= w; j++)         if (vis[Id[i][j]])           for (int k = 0; k < 8; k++)             if (vis[Id[i + fx[k]][j + fy[k]]])               fa[Get(Id[i][j])] = Get(Id[i + fx[k]][j + fy[k]]);     int flg = 0;     for (int i = 1; i <= h; i++)       for (int j = 1; j <= w; j++)         if ((i != 1 || j != 1) && (i != h || j != w))           for (int x = 0; x < 8; x++)             if (vis[Id[i + fx[x]][j + fy[x]]])               for (int y = x + 1; y < 8; y++)                 if (vis[Id[i + fx[y]][j + fy[y]]]) {                   int Fx = Get(Id[i + fx[x]][j + fy[x]]);                   int Fy = Get(Id[i + fx[y]][j + fy[y]]);                   int Fs = Get(s), Ft = Get(t);                   if (min(Fx, Fy) == min(Fs, Ft) && max(Fx, Fy) == max(Fs, Ft))                     flg = 1;                   Tag[Fx][Fy] = Tag[Fy][Fx] = 1;                 }     if (flg == 1) {       for (int i = 1; i <= Q; i++) puts( NO );       return 0;     }     for (int i = 1; i <= cnt; i++) fa[i] = Get(i);     for (int T = 1; T <= Q; T++) {       int K;       scanf( %d , &K);       Top = siz = flg = 0;       q[++siz] = Get(s), q[++siz] = Get(t);       for (int i = 1; i <= K; i++) {         scanf( %d%d , &A[i].x, &A[i].y);         vis[Id[A[i].x][A[i].y]] = 1;         q[++siz] = Get(Id[A[i].x][A[i].y]);         for (int j = 0; j < 8; j++)           if (vis[Id[A[i].x + fx[j]][A[i].y + fy[j]]])             q[++siz] = Get(Id[A[i].x + fx[j]][A[i].y + fy[j]]);       }       for (int i = 1; i <= K; i++)         for (int j = 0; j < 8; j++)           if (vis[Id[A[i].x + fx[j]][A[i].y + fy[j]]])             stk[++Top] = GET(Id[A[i].x + fx[j]][A[i].y + fy[j]]),             fa[stk[Top]] = GET(Id[A[i].x][A[i].y]);       for (int i = 1; i <= K; i++) {         for (int j = 0; j < 8; j++)           if (!vis[Id[A[i].x + fx[j]][A[i].y + fy[j]]]) {             int nx = A[i].x + fx[j], ny = A[i].y + fy[j];             if ((nx == 1 && ny == 1) || (nx == h && ny == w)) continue;             for (int x = 0; x < 8; x++)               if (vis[Id[nx + fx[x]][ny + fy[x]]])                 for (int y = x + 1; y < 8; y++)                   if (vis[Id[nx + fx[y]][ny + fy[y]]]) {                     int Fx = GET(Id[nx + fx[x]][ny + fy[x]]),                         Fy = GET(Id[nx + fx[y]][ny + fy[y]]);                     int Fs = GET(s), Ft = GET(t);                     if (min(Fx, Fy) == min(Fs, Ft) && max(Fx, Fy) == max(Fs, Ft))                       flg = 1;                   }           }       }       sort(q + 1, q + siz + 1);       siz = unique(q + 1, q + siz + 1) - q - 1;       for (int i = 1; i <= siz; i++)         if (GET(q[i]) == GET(s))           for (int j = 1; j <= siz; j++)             if (GET(q[j]) == GET(t) && Tag[q[i]][q[j]]) flg = 1;       flg ? puts( NO ) : puts( YES );       fflush(stdout);       for (int i = 1; i <= Top; i++) fa[stk[i]] = stk[i];       for (int i = 1; i <= K; i++) vis[Id[A[i].x][A[i].y]] = 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct elem {     int u, clen, tlen;     int nlis;     int lis[4];     elem() {       clen = -1;       nlis = 0;     }     elem(int u, int clen, int tlen) : u(u), clen(clen), tlen(tlen) { nlis = 0; }   };   void write(string s, elem e) {     cout <<  [  << s <<  , u   << e.u <<  , clen   << e.clen <<  , tlen            << e.tlen <<  , lis  ;     for (int i = 0; i < e.nlis; i++) cout << e.lis[i] <<  , ;     cout <<  ]  <<   n ;   }   void add(elem &e, int u) { e.lis[e.nlis++] = u; }   bool operator<(elem e1, elem e2) {     if (e1.clen != e2.clen) return e1.clen < e2.clen;     return e1.tlen < e2.tlen;   }   elem operator+(elem e1, elem e2) {     elem e = elem(e1.u, e1.clen + e2.clen, e1.tlen + e2.tlen);     for (int i = 0; i < e1.nlis; i++) add(e, e1.lis[i]);     for (int i = 0; i < e2.nlis; i++) add(e, e2.lis[i]);     return e;   }   void maximize(int &a, int b) { a = max(a, b); }   void maximize(elem &a, elem b) { a = max(a, b); }   const int limit = 200005;   int n;   vector<int> g[limit];   elem best1[limit];   elem best2[limit];   elem best3[limit];   elem sol;   int n1, n2, n3;   elem lis1[limit];   elem lis2[limit];   elem lis3[limit];   void compute(int u, int p) {     elem &b1 = best1[u];     elem &b2 = best2[u];     elem &b3 = best3[u];     b1 = elem(u, 0, 0);     add(b1, u);     vector<int> &ar = g[u];     for (int i = 0; i < int(ar.size()); i++) {       int v = ar[i];       if (v != p) compute(v, u);     }     n1 = n2 = n3 = 0;     for (int i = 0; i < int(ar.size()); i++) {       int v = ar[i];       if (v != p) {         lis1[n1++] = elem(v, 0, 1) + best1[v];         if (best2[v].clen != -1) lis2[n2++] = elem(v, 1, 2) + best2[v];         if (best3[v].clen != -1) lis3[n3++] = elem(v, 0, 1) + best3[v];       }     }     sort(lis1, lis1 + n1);     reverse(lis1, lis1 + n1);     sort(lis2, lis2 + n2);     reverse(lis2, lis2 + n2);     sort(lis3, lis3 + n3);     reverse(lis3, lis3 + n3);     if (n1 >= 1) {       maximize(b1, lis1[0]);     }     if (n2 >= 1) maximize(b2, lis2[0]);     if (n1 >= 2) maximize(b2, lis1[0] + lis1[1]);     if (n1 >= 3) maximize(b3, lis1[0] + lis1[1] + lis1[2]);     for (int i1 = 0; i1 < 2 and i1 < n1; i1++)       for (int i2 = 0; i2 < 2 and i2 < n2; i2++)         if (lis1[i1].u != lis2[i2].u) maximize(b3, lis2[i2] + lis1[i1]);     if (n3 >= 1) maximize(b3, lis3[0]);     if (n2 >= 2) maximize(sol, lis2[0] + lis2[1]);     if (n3 >= 1) {       elem e = lis3[0];       add(e, u);       maximize(sol, e);     }     for (int i1 = 0; i1 < 3; i1++)       for (int j1 = i1 + 1; j1 < 3 and j1 < n1; j1++)         for (int i2 = 0; i2 < 3 and i2 < n2; i2++)           if (lis1[i1].u != lis2[i2].u and lis1[j1].u != lis2[i2].u)             maximize(sol, lis1[i1] + lis1[j1] + lis2[i2]);     for (int i1 = 0; i1 < 2 and i1 < n1; i1++)       for (int i3 = 0; i3 < 2 and i3 < n3; i3++)         if (lis1[i1].u != lis3[i3].u) maximize(sol, lis3[i3] + lis1[i1]);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     compute(1, 0);     int(&lis)[4] = sol.lis;     cout << lis[0] <<     << lis[2] <<   n ;     cout << lis[1] <<     << lis[3] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, m, v;   int main() {     n = read();     m = read();     v = read();     if (m > (long long)(n - 1) * (n - 2) / 2 + 1 || m < n - 1) {       printf( -1 n );     } else {       for (int i = 1; i <= n; i++) {         if (i != v) {           printf( %d %d n , v, i);         }       }       int s = (v == 1 ? 2 : 1);       m -= (n - 1);       for (int i = 1; i <= n; i++) {         if (i != s && i != v) {           for (int j = i + 1; j <= n; j++) {             if (j != s && j != v) {               if (!m--) {                 return 0;               }               printf( %d %d n , i, j);             }           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 110;   static int N, M, P, val[MAXN], cut[MAXN];   int main() {     scanf( %d%d , &N, &M);     for (int i = 1; i <= N; i++) scanf( %d , &val[i]);     for (int i = 1, odd = 0, evn = 0; i < N; i++) {       ((val[i] & 1) ? odd : evn) += 1;       if (odd == evn) cut[P++] = abs(val[i + 1] - val[i]);     }     sort(cut, cut + P);     for (int i = 0, sum = 0; i < P; i++)       if ((sum += cut[i]) > M) return printf( %d n , i), 0;     printf( %d n , P);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int sol1, sol2, sol3, n;   string str;   int main() {     cin >> n >> str;     for (int i = 0; i < str.length(); i++) {       if (str[i] ==  A )         sol1++;       else if (str[i] ==  I )         sol2++;     }     sol3 = str.length() - sol1 - sol2;     if (sol2 == 0) {       cout << sol1 << endl;       return 0;     }     if (sol2 > 1)       cout << 0 << endl;     else       cout << 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const long long inf64 = 1e18;   const int N = 1e5 + 5;   int xmax, ymax, zmax, n, m, k;   enum TYPE { XZ, OPEN, CLOSED, UNKNOWN };   vector<pair<int, int> > add[N];   vector<pair<pair<pair<int, int>, pair<int, int> >, int> > op[N], cl[N];   vector<int> fen[4 * N];   vector<int> lin_ar[N];   vector<int> ar[4 * N];   void merge(int v) {     for (int i = 0, j = 0;          i < (int)ar[v << 1].size() || j < (int)ar[v << 1 | 1].size();) {       if (j == (int)ar[v << 1 | 1].size() ||           (i < (int)ar[v << 1].size() && ar[v << 1][i] < ar[v << 1 | 1][j])) {         if (ar[v].empty() || ar[v << 1][i] > ar[v].back()) {           ar[v].push_back(ar[v << 1][i]);         }         i++;       } else {         if (ar[v].empty() || ar[v << 1 | 1][j] > ar[v].back()) {           ar[v].push_back(ar[v << 1 | 1][j]);         }         j++;       }     }   }   void build(int v, int tl, int tr) {     if (tl == tr) {       ar[v] = lin_ar[tl];       sort(begin(ar[v]), end(ar[v]));       ar[v].resize(unique(begin(ar[v]), end(ar[v])) - ar[v].begin());     } else {       int tm = (tl + tr) >> 1;       build(v << 1, tl, tm);       build(v << 1 | 1, tm + 1, tr);       merge(v);     }     fen[v].resize(ar[v].size());   }   void change(int v, int tl, int tr, int px, int py) {     int pos = lower_bound(begin(ar[v]), end(ar[v]), py) - ar[v].begin();     for (int cur = pos; cur < (int)fen[v].size(); cur |= (cur + 1)) fen[v][cur]++;     if (tl < tr) {       int tm = (tl + tr) >> 1;       if (px <= tm) {         change(v << 1, tl, tm, px, py);       } else {         change(v << 1 | 1, tm + 1, tr, px, py);       }     }   }   int get(int v, int tl, int tr, int lx, int rx, int ly, int ry) {     if (lx <= tl && tr <= rx) {       int res = 0;       int pr = upper_bound(begin(ar[v]), end(ar[v]), ry) - ar[v].begin() - 1;       int pl = lower_bound(begin(ar[v]), end(ar[v]), ly) - ar[v].begin();       if (pl <= pr) {         for (int cur = pr; cur >= 0; cur = (cur & (cur + 1)) - 1)           res += fen[v][cur];         for (int cur = pl - 1; cur >= 0; cur = (cur & (cur + 1)) - 1)           res -= fen[v][cur];       }       return res;     } else {       int tm = (tl + tr) >> 1;       int res = 0;       if (lx <= tm) {         res += get(v << 1, tl, tm, lx, rx, ly, ry);       }       if (rx > tm) {         res += get(v << 1 | 1, tm + 1, tr, lx, rx, ly, ry);       }       return res;     }   }   TYPE res[N];   int cnt[N];   int lx, rx, ly, ry, lz, rz;   int main() {     scanf( %d %d %d , &xmax, &ymax, &zmax);     lx = ly = lz = inf;     rx = ry = rz = -inf;     scanf( %d %d %d , &n, &m, &k);     for (int i = 0; i < n; i++) {       int xi, yi, zi;       scanf( %d %d %d , &xi, &yi, &zi);       lx = min(lx, xi);       rx = max(rx, xi);       ly = min(ly, yi);       ry = max(ry, yi);       lz = min(lz, zi);       rz = max(rz, zi);     }     if (lx > rx || ly > ry || lz > rz) {       puts( INCORRECT );       return 0;     }     for (int i = 0; i < m; i++) {       int xi, yi, zi;       scanf( %d %d %d , &xi, &yi, &zi);       if (lx <= xi && xi <= rx && ly <= yi && yi <= ry && lz <= zi && zi <= rz) {         puts( INCORRECT );         return 0;       }       add[xi].push_back({yi, zi});       lin_ar[yi].push_back(zi);     }     build(1, 1, ymax);     puts( CORRECT );     for (int iter = 0; iter < k; iter++) {       int xi, yi, zi;       scanf( %d %d %d , &xi, &yi, &zi);       if (lx <= xi && xi <= rx && ly <= yi && yi <= ry && lz <= zi && zi <= rz) {         res[iter] = OPEN;         continue;       }       int LX = min(lx, xi);       int RX = max(rx, xi);       int LY = min(ly, yi);       int RY = max(ry, yi);       int LZ = min(lz, zi);       int RZ = max(rz, zi);       op[LX].push_back({{{LY, RY}, {LZ, RZ}}, iter});       cl[RX].push_back({{{LY, RY}, {LZ, RZ}}, iter});     }     for (int x = 1; x <= xmax; x++) {       for (auto hlp : op[x]) {         int lx, rx, ly, ry, id;         tie(lx, rx) = hlp.first.first;         tie(ly, ry) = hlp.first.second;         id = hlp.second;         int tmp = get(1, 1, ymax, lx, rx, ly, ry);         cnt[id] -= tmp;       }       for (pair<int, int> pt : add[x]) {         int x0, y0;         tie(x0, y0) = pt;         change(1, 1, ymax, x0, y0);       }       for (auto hlp : cl[x]) {         int lx, rx, ly, ry, id;         tie(lx, rx) = hlp.first.first;         tie(ly, ry) = hlp.first.second;         id = hlp.second;         int tmp = get(1, 1, ymax, lx, rx, ly, ry);         cnt[id] += tmp;       }     }     for (int iter = 0; iter < k; iter++) {       if (res[iter] == XZ) {         res[iter] = cnt[iter] > 0 ? CLOSED : UNKNOWN;       }       if (res[iter] == OPEN) {         puts( OPEN );       } else if (res[iter] == CLOSED) {         puts( CLOSED );       } else {         puts( UNKNOWN );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ar[6];   int main() {     long long int n, x, j, y, cnt = 0, sum = 0;     for (cin >> n, j = 0; j < n; j++) {       cin >> x >> y;       ar[x] += 1;       ar[y] += 1;     }     for (int i = 1; i <= 5; i++) {       if (ar[i] >= 3 || ar[i] <= 1) cnt++;     }     if (cnt > 0)       cout <<  WIN ;     else       cout <<  FAIL ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int matrix[5][5];     for (int i = 0; i < 5; i++) {       for (int j = 0; j < 5; j++) {         cin >> matrix[i][j];       }     }     int row = 0;     int col = 0;     for (int i = 0; i < 5; i++) {       for (int j = 0; j < 5; j++) {         if (matrix[i][j] == 1) {           row = i + 1;           col = j + 1;         }       }     }     int swaps = 0;     swaps += abs(3 - row);     swaps += abs(3 - col);     cout << swaps;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0);     int m, n;     cin >> m >> n;     vector<int> A(m), B(n);     for (int &i : A) cin >> i;     for (int &i : B) cin >> i;     vector<pair<int, pair<int, int>>> C;     for (int i = 0; i < m; ++i) {       int t;       cin >> t;       for (int j = 0; j < t; ++j) {         int a;         cin >> a;         --a;         C.emplace_back(make_pair(A[i] + B[a], make_pair(i, a)));       }     }     sort(C.rbegin(), C.rend());     long long res = 0;     vector<int> fa(n), fst(m, -1);     iota(fa.begin(), fa.end(), 0);     function<int(int)> ffa = [&](int x) {       if (fa[x] == x) return x;       return fa[x] = ffa(fa[x]);     };     auto merge = [&](int x, int y) {       x = ffa(x);       y = ffa(y);       if (x != y) {         fa[x] = y;       }     };     for (int i = 0; i < ((int)(C).size()); ++i) {       int v = C[i].first;       auto [idx, val] = C[i].second;       if (fst[idx] == -1) {         fst[idx] = val;         continue;       }       if (ffa(fst[idx]) == ffa(val)) {         res += v;       } else {         merge(fst[idx], val);       }     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:167177216 )   using namespace std;   const long long MOD = 1000000000 + 7;   int main() {     ios::sync_with_stdio(false);     string s;     cin >> s;     long long bcount = 0;     long long ans = 0;     for (int i = s.size() - 1; i >= 0; --i) {       if (s[i] ==  b ) {         bcount++;       }       if (s[i] ==  a ) {         ans += bcount;         bcount *= 2;         bcount %= MOD;         ans %= MOD;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char a[1000005];   char l[1000005];   char r[1000005];   int f[1000005];   int okl[1000005];   int okr[1000005];   int mod = 998244353;   char ss[2000005];   int heigh[2000005];   int sa[2000005];   int Rank[2000005];   int length;   int val[30];   int c[2000005];   int temp[2][2000005];   void suffix_array() {     int A = 250;     int* Rank = temp[0];     int* new_rank = temp[1];     for (int i = 0; i < A; ++i) c[i] = 0;     for (int i = 0; i < length; ++i) c[Rank[i] = ss[i]]++;     for (int i = 1; i < A; ++i) c[i] += c[i - 1];     for (int i = length - 1; i >= 0; --i) sa[--c[ss[i]]] = i;     for (int n = 1; n < length; n *= 2) {       for (int i = 0; i < A; ++i) c[i] = 0;       for (int i = 0; i < length; ++i) c[Rank[i]]++;       for (int i = 1; i < A; ++i) c[i] += c[i - 1];       int* sa2 = new_rank;       int r = 0;       for (int i = length - n; i < length; ++i) sa2[r++] = i;       for (int i = 0; i < length; ++i)         if (sa[i] >= n) sa2[r++] = sa[i] - n;       for (int i = length - 1; i >= 0; --i) sa[--c[Rank[sa2[i]]]] = sa2[i];       new_rank[sa[0]] = r = 0;       for (int i = 1; i < length; ++i) {         if (!(Rank[sa[i - 1]] == Rank[sa[i]] && sa[i - 1] + n < length &&               Rank[sa[i - 1] + n] == Rank[sa[i] + n]))           r++;         new_rank[sa[i]] = r;       }       swap(Rank, new_rank);       if (r == length - 1) break;       A = r + 1;     }   }   void lcp_array() {     for (int i = 0; i < length; ++i) Rank[sa[i]] = i;     for (int i = 0, lcp = 0, h = 0; i < length; i++)       if (Rank[i] == 0)         heigh[0] = 0;       else {         int j = sa[Rank[i] - 1];         if (lcp > 0) lcp--;         while (ss[i + lcp] == ss[j + lcp]) lcp++;         heigh[Rank[i]] = lcp;       }   }   int dp[1000005];   int okzero;   int main() {     scanf( %s , a);     scanf( %s , l);     if (l[0] ==  0  && l[1] == 0) l[0] =  1 , okzero = 1;     scanf( %s , r);     int lena = strlen(a), lenl = strlen(l), lenr = strlen(r);     for (int i = 0; a[i] != 0; i++) ss[i] = a[i];     ss[lena] =  $ ;     for (int i = 0; l[i] != 0; i++) ss[i + lena + 1] = l[i];     length = lena + lenl + 1;     ss[length] = 0;     suffix_array();     int st = 0;     for (int i = 0; i < length; i++) {       if (sa[i] == lena + 1) st = i;     }     lcp_array();     int now = 1e9;     for (int i = st + 1; i < length; i++) {       now = min(now, heigh[i]);       if (sa[i] < lena) {         if (a[sa[i] + now] < l[now]) {           okl[sa[i]] = 0;         } else {           okl[sa[i]] = 1;         }       }     }     now = 1e9;     for (int i = st - 1; i >= 0; i--) {       now = min(heigh[i + 1], now);       if (sa[i] < lena) {         if (a[sa[i] + now] < l[now]) {           okl[sa[i]] = 0;         } else {           okl[sa[i]] = 1;         }       }     }     for (int i = 0; r[i] != 0; i++) ss[i + lena + 1] = r[i];     length = lena + lenr + 1;     ss[length] = 0;     suffix_array();     st = 0;     for (int i = 0; i < length; i++) {       if (sa[i] == lena + 1) st = i;     }     lcp_array();     now = 1e9;     for (int i = st + 1; i < length; i++) {       now = min(now, heigh[i]);       if (sa[i] < lena) {         if (a[sa[i] + now] <= r[now] || r[now] == 0) {           okr[sa[i]] = 1;         } else {           okr[sa[i]] = 0;         }       }     }     now = 1e9;     for (int i = st - 1; i >= 0; i--) {       now = min(heigh[i + 1], now);       if (sa[i] < lena) {         if (a[sa[i] + now] <= r[now] || r[now] == 0) {           okr[sa[i]] = 1;         } else {           okr[sa[i]] = 0;         }       }     }     int l = 0, r = -1;     long long sum = 0;     if (lenl == 1) {       if (okl[r + 1]) {         if (a[r + 1] !=  0 ) sum += 1;         r++;       }     }     for (int i = 0; a[i] != 0; i++) {       dp[i] = sum;       if (a[i] ==  0  && okzero) {         if (i == 0)           dp[i]++;         else           dp[i] += dp[i - 1];         dp[i] %= mod;       }       while (1) {         if (i - r + 1 > lenl) {           if (a[r + 1] !=  0 ) {             if (r == -1)               sum++;             else               sum += dp[r];           }           r++;         } else if (i - r + 1 == lenl) {           if (okl[r + 1]) {             if (a[r + 1] !=  0 ) {               if (r == -1)                 sum++;               else                 sum += dp[r];             }             r++;           } else {             break;           }         } else {           break;         }       }       while (1) {         if (i - l + 2 > lenr) {           if (a[l] !=  0 ) {             if (l == 0)               sum--;             else               sum -= dp[l - 1];           }           l++;         } else if (i - l + 2 == lenr) {           if (!okr[l]) {             if (a[l] !=  0 ) {               if (l == 0)                 sum--;               else                 sum -= dp[l - 1];             }             l++;           } else {             break;           }         } else {           break;         }       }       sum = (sum % mod + mod) % mod;     }     printf( %d n , dp[lena - 1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 510;   const int mod = 1e9 + 7;   long long mi1[N], mi[N], C[N][N], dp[N][N];   int main() {     int n, m;     scanf( %d%d , &n, &m);     mi[0] = mi1[0] = 1;     for (int i = 1; i <= n; i++) {       mi[i] = mi[i - 1] * m % mod;       mi1[i] = mi1[i - 1] * (m - 1) % mod;     }     for (int i = 0; i <= n; i++) {       C[i][0] = 1;       for (int j = 1; j <= i; j++)         C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;     }     for (int j = 1; j <= n; j++) dp[1][j] = C[n][j] * mi1[n - j] % mod;     for (int i = 2; i <= n; i++) {       for (int j = 0; j <= n; j++) {         for (int k = 0; k <= j; k++) {           long long V;           V = (dp[i - 1][k] % mod * C[n - k][j - k] % mod * mi1[n - j] % mod *                mi[k] % mod) %               mod;           dp[i][j] = (dp[i][j] + V) % mod;           if (j == k)             dp[i][j] = (dp[i][j] - mi1[n] * dp[i - 1][k] % mod + mod) % mod;         }       }     }     printf( %lld n , dp[n][n]);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d;     int m, v, m1, m2, v1, v2;     cin >> a >> b >> c >> d;     m1 = 3 * a / 10;     m2 = a - (a / 250) * c;     if (m1 > m2)       m = m1;     else       m = m2;     v1 = 3 * b / 10;     v2 = b - (b / 250) * d;     if (v1 > v2)       v = v1;     else       v = v2;     if (m > v)       cout <<  Misha ;     else if (m < v)       cout <<  Vasya ;     else       cout <<  Tie ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   /** START OF DESPERATE OPTIMIZATION **/   #pragma GCC target ( avx2 )   #pragma GCC optimization ( O3 )   #pragma GCC optimization ( unroll-loops )       #include<bits/stdc++.h>   using namespace std;       using ll = long long;   using LD = long double;       const LD EPS = 1e-9, PI = acos(-1);   inline bool eq(LD a, LD b) { return fabs(a-b) < EPS; }   inline bool lt(LD a, LD b) { return a + EPS < b; }   inline bool le(LD a, LD b) { return a < b + EPS; }   inline int sign(LD x) { return eq(x, 0) ? 0 : (x < 0 ? -1 : 1); }       struct point {     LD x, y;     point(LD x = 0, LD y = 0) : x(x), y(y) {}     point operator+(const point& p) const { return point(x+p.x, y+p.y); }     point operator-(const point& p) const { return point(x-p.x, y-p.y); }     point operator*(LD s) { return point(x*s, y*s); }     point operator/(LD s) { return point(x/s, y/s); }     LD operator*(const point& p) const { return x*p.x + y*p.y; } // dot     LD operator%(const point& p) const { return x*p.y - y*p.x; } // cross     LD norm_sq() { return *this * *this; }     LD norm() { return sqrt(*this * *this); }     point rotate(LD cs, LD sn) { return point(x*cs-y*sn, x*sn+y*cs); }     point rotate(LD angle) { return rotate(cos(angle), sin(angle)); }     bool operator==(const point& p) const { return eq(x, p.x) && eq(y, p.y); }     bool operator<(const point& p) const { return eq(y, p.y) ? x < p.x : y < p.y; }   };       int ccw(point a, point b, point c) { return sign((b - a) % (c - b)); }   LD dist(point a, point b) { return (b-a).norm(); }   LD dist2(point a, point b) { return (b-a).norm_sq(); }   LD angle(point a, point o, point b) {     point oa = a-o, ob = b-o;     return acos(oa*ob/(oa.norm()*ob.norm()));   }   point bisector(point a, point b) { return a * b.norm() + b * a.norm(); }       struct line {     point a, ab; // p(t) = a + ab * t     line(point ta, point tb) {       if (tb < ta) swap(ta, tb);       a = ta; ab = tb-ta;     }     point b() { return a + ab; }     bool isLine() { return !(ab == point()); } // minor     operator bool() { return !(ab == point()); } // minor     // Line     bool onLine(point p) {       if (ab == point()) return a == p;       return eq(ab % (p-a), 0);     }     LD distLine(point p) {       if (ab == point()) return dist(a, p);       return fabs((p-a) % ab)/ab.norm();     }     point projection(point p) {       if (ab == point()) return a;       return a + ab * ((p-a) * ab / ab.norm_sq());     }     point reflection(point p) {       return projection(p) * 2.0 - p;     }     // Segment     bool onSegment(point p) {       if (ab == point()) return a == p;       point pa = a-p, pb = b()-p;       return eq(pa % pb, 0) && le(pa * pb, 0);     }     LD distSegment(point p) {       if (le((p-a) * ab, 0)) return dist(a, p);       if (le(0, (p-b()) * ab)) return dist(b(), p);       return distLine(p);     }     point closestSegment(point p) {       if (le((p-a) * ab, 0)) return a;       if (le(0, (p-b()) * ab)) return b();       return projection(p);     }     bool areParallel(line l) {       return eq(ab % l.ab, 0);     }     bool areSame(line l) {       return areParallel(l) && onLine(l.a) && l.onLine(a);     }   };       bool areIntersect(line l1, line l2, point & res) {     if (l1.areParallel(l2)) return 0;     LD ls = (l2.a  - l1.a) % l2.ab, rs = l1.ab % l2.ab;     res = l1.a + l1.ab * ls/rs;     return 1;   }       const int N = 2e5;   point p[N + 10];   int n, H;       void print(point P) {     cerr <<  (  << P.x <<  ,  << P.y <<  )  <<   n ;   }       void solve() {     cin >> n >> H;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       p[i] = point(x, y);       // cin >> p[i].x >> p[i].y;     }     LD ans = 0;     point eye = p[n - 1] + point(0, H);     vector<point> st = {eye, p[n - 1]};     for (int i = n - 2; i >= 0; i--) {       // print(eye); print(st[1]); print(p[i]);       if (ccw(eye, st[1], p[i]) <= 0) {         line l1 = line(eye, st[1]);         line l2 = line(p[i], p[i + 1]);         point cut;         if (areIntersect(l1, l2, cut)) {           if (l2.onSegment(cut)) {             ans += dist(cut, p[i]);           }         } else if (l1.areSame(l2)) {           ans += dist(p[i], p[i + 1]);         }       }       while ((int)st.size() >= 2 && ccw(st[st.size() - 2], st.back(), p[i]) <= 0) {         st.pop_back();       }       st.push_back(p[i]);       // cerr << ans <<   n ;     }         cout << ans <<   n ;   }       int main() {     ios_base::sync_with_stdio(0);     cin.tie(0); cout.tie(0);         cout << fixed << setprecision(12);         int TC = 1;     for(int i = 1; i <= TC; i++) {       solve();     }          return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimise( ofast )   #pragma GCC optimise( unroll-loops )   using namespace std;   const int N = 200000 + 10;   const long long MOD = 1000000000 + 7;   const long long INF = 1000000000000000000;   const long long LOG = 25;   int n, m, k, s1, s2, f, l[N], r[N], val[N], node[N], nodeu[N], NODE[N];   long long dis[N], dis2[N], dis3[N];   vector<pair<int, int>> G[N], Gin[N];   inline void DJ(int v) {     memset(dis, 63, sizeof dis);     dis[v] = 0;     set<pair<long long, int>> st;     st.insert({dis[v], v});     while (st.size()) {       pair<long long, int> fr = *st.begin();       st.erase(st.begin());       for (auto u : G[fr.second]) {         if (dis[u.first] > fr.first + val[u.second]) {           st.erase({dis[u.first], u.first});           dis[u.first] = fr.first + val[u.second];           st.insert({dis[u.first], u.first});         }       }     }   }   inline void DJ2(int v) {     memset(dis2, 63, sizeof dis2);     dis2[v] = 0;     set<pair<long long, int>> st;     st.insert({0, v});     while (st.size()) {       pair<long long, int> fr = *st.begin();       st.erase(st.begin());       for (auto u : G[fr.second]) {         if (dis2[u.first] > fr.first + val[u.second]) {           st.erase({dis2[u.first], u.first});           dis2[u.first] = fr.first + val[u.second];           st.insert({dis2[u.first], u.first});         }       }     }   }   bool cmp(int x, int y) { return dis[node[x]] < dis[node[y]]; }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k >> s1 >> s2 >> f;     for (int i = 1; i <= m; i++) {       int v, u, w;       cin >> v >> u >> w;       G[v].push_back({u, i});       Gin[u].push_back({v, i});       val[i] = w;     }     for (int i = m + 1; i <= m + k; i++) {       int v, u, L, R;       cin >> v >> u >> L >> R;       l[i] = L, r[i] = R;       node[i] = v;       nodeu[i] = u;       G[v].push_back({u, i});       Gin[u].push_back({v, i});       val[i] = R;     }     DJ(s1), DJ2(s2);     for (int i = m + 1; i <= m + k; i++) {       if (dis[node[i]] < dis2[node[i]] && val[i] != l[i]) {         val[i] = l[i];         DJ(s1);         DJ2(s2);         i = m;       }     }     if (dis[f] < dis2[f]) {       cout <<  WIN n ;       for (int i = m + 1; i <= m + k; i++) cout << val[i] <<    ;       return 0;     }     if (dis[f] == dis2[f]) {       cout <<  DRAW n ;       for (int i = m + 1; i <= m + k; i++) cout << val[i] <<    ;       return 0;     }     cout <<  LOSE ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2500 + 10;   int n;   pair<int, int> p[MAXN];   pair<int, int> sec[MAXN];   int sz;   int half(pair<int, int> p) {     assert(p.first || p.second);     return p.second > 0 || (p.second == 0 && p.first < 0);   }   long long dot(pair<int, int> a, pair<int, int> b) {     return 1ll * a.first * b.first + 1ll * a.second * b.second;   }   long long cross(pair<int, int> a, pair<int, int> b) {     return 1ll * a.first * b.second - 1ll * a.second * b.first;   }   int nxt(int x) { return x + 1 == sz ? 0 : x + 1; }   void solve() {     cin >> n;     for (int i = 0; i < n; i++) cin >> p[i].first >> p[i].second;     long long ans = 0;     for (int i = 0; i < n; i++) {       sz = 0;       for (int j = 0; j < n; j++)         if (i ^ j)           sec[sz++] = {p[j].first - p[i].first, p[j].second - p[i].second};       sort(sec, sec + sz, [](pair<int, int> a, pair<int, int> b) {         return make_tuple(half(a), 0, dot(a, b)) <                make_tuple(half(b), cross(a, b), dot(a, b));       });       long long temp = 0;       int cur = 0;       for (int j = 0; j < sz; j++) {         if (cur == j) cur = nxt(j);         while (cur != j && cross(sec[j], sec[cur]) > 0) cur = nxt(cur);         int ln = cur > j ? cur - j : sz - (j - cur);         temp += 1ll * (ln - 1) * (ln - 2) * (ln - 3) / 6;       }       ans += 1ll * (n - 1) * (n - 2) * (n - 3) * (n - 4) / 24 - temp;     }     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int te = 1;     for (int w = 1; w <= te; w++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n;     cin >> n;     string s;     cin >> s;     long long int temp = 0;     for (long long int i = 0; i < n - 1; i++) {       if (s[i] > s[i + 1]) {         cout <<  YES  << endl << i + 1 <<     << i + 2 << endl;         temp = 1;         break;       }     }     if (temp == 0) cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100000 + 5;   int n, S;   int a[N];   long long now[N];   bool check(int x, int& ans2) {     for (int i = 1; i <= n; i++) {       now[i] = a[i] + 1ll * i * x;     }     sort(now + 1, now + 1 + n);     long long sum = 0;     for (int i = 1; i <= x; i++) {       sum += now[i];       if (sum > S) return false;     }     ans2 = sum;     return true;   }   int main() {     scanf( %d%d , &n, &S);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     int L = 0, R = n, ans1 = 0, ans2 = 0;     while (L <= R) {       int M = L + R >> 1;       if (check(M, ans2)) {         L = M + 1;         ans1 = M;       } else         R = M - 1;     }     printf( %d %d n , ans1, ans2);     return 0;   }


#include <bits/stdc++.h>   struct book {     int t, w;     bool operator<(const book &b) const { return w < b.w; }   } ones[102], twos[102];   int main() {     int n;     scanf( %d , &n);     int nOnes = 0;     int tWidthOnes = 0;     int nTwos = 0;     int tWidthTwos = 0;     for (int i = 0; i < n; i++) {       int t, w;       scanf( %d %d , &t, &w);       if (t == 1) {         ones[nOnes].t = t;         ones[nOnes++].w = w;         tWidthOnes += w;       } else {         twos[nTwos].t = t;         twos[nTwos++].w = w;         tWidthTwos += w;       }     }     std::sort(ones, ones + nOnes);     std::sort(twos, twos + nTwos);     int best = 1 << 30;     for (int i = 1; i <= 1 * nOnes + 2 * nTwos; i++) {       for (int j = 0; j <= i; j++) {         if (j <= nOnes && (i - j) <= nTwos) {           int botWidth = 1 * j + 2 * (i - j);           int topWidth = 0;           for (int k = 0; k < nOnes - j; k++) {             topWidth += ones[k].w;           }           for (int k = 0; k < nTwos - (i - j); k++) {             topWidth += twos[k].w;           }           if (topWidth <= botWidth) {             if (botWidth < best) best = botWidth;           }         }       }     }     printf( %d n , best);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   const int oo = 1e9 + 5;   struct seg {     seg(int a, int x, int y) : A(a), first(x), second(y) {}     int A;     int first;     int second;   };   bool operator<(const seg &M, const seg &N) { return M.A < N.A; }   set<seg> segs;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     int N, Q;     scanf( %d %d n , &N, &Q);     segs.insert(seg(0, 0, 0));     for (int i = 0; i < Q; ++i) {       int x, y;       char c;       scanf( %d %d %c n , &x, &y, &c);       set<seg>::iterator it = segs.upper_bound(seg(x, 0, 0));       --it;       if (x == it->A) {         printf( 0 n );         continue;       }       int fa = it->A;       int fy = it->second;       int fx = it->first;       if (c ==  U ) {         printf( %d n , y - it->second);         segs.insert(seg(x, x, fy));       } else {         printf( %d n , x - it->first);         segs.erase(it);         segs.insert(seg(fa, fx, y));         segs.insert(seg(x, fx, fy));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     cout.tie();     int n;     cin >> n;     int arr[5001] = {0};     int ans = 0;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       arr[x]++;     }     for (int i = 1; i <= n; i++) {       if (arr[i] >= 2) ans += arr[i] - 1;     }     for (int i = n + 1; i <= 5000; i++) ans += arr[i];     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, x, l, j, k, i;     cin >> n >> x;     long long a[x + 1];     for (i = 1; i <= x; i++) {       a[i] = 0;     }     for (i = 0; i < n; i++) {       cin >> l;       for (j = 0; j < l; j++) {         cin >> k;         a[k]++;       }     }     int t = 1;     for (i = 1; i <= x; i++) {       if (a[i] == 0) {         t = 0;       }     }     if (t == 1) {       cout <<  YES ;     } else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     string s;     cin >> s;     long long x = 1;     long long zero = 0;     set<char> q;     bool h = 0, mn = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  ? ) {         if (h)           zero++;         else {           x = x * 9;           h = 1;         }       } else if (s[i] >=  0  && s[i] <=  9 ) {         if (s[i] >  0 ) h = 1;       } else {         if (h)           q.insert(s[i]);         else {           q.insert(s[i]);           mn = 1;           h = 1;         }       }     }     for (long long t = 10; t > 10 - q.size(); t--) {       if (mn == 1 && t == 10)         x = x * 9;       else         x = x * t;     }     cout << x;     for (int i = 0; i < zero; i++) cout << 0;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fun(long long int n) {     int count = 0;     while (n) {       if (n % 10 == 7 || n % 10 == 4) count++;       n = n / 10;     }     if (count == 0) {       cout <<  NO ;       return;     }     while (count) {       int r = count % 10;       if (r != 7 && r != 4) {         cout <<  NO ;         return;       }       count = count / 10;     }     cout <<  YES ;     return;   }   int main() {     long long int n;     cin >> n;     fun(n);     return 0;   }


#include <bits/stdc++.h>   int arr1[500005];   using namespace std;   int main() {     int t;     cin >> t;     for (int i = 1; i <= t; i++) {       int a;       cin >> a;       arr1[a] = i;     }     long long int sum = 0;     for (int i = 1; i < t; i++) {       sum += abs(arr1[i] - arr1[i + 1]);     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n_Cases = 1;     for (long long case_i = 1; case_i <= n_Cases; case_i++) {       long long up, down;       cin >> up >> down;       long long n = up + down + 1;       for (long long i = 1; i <= up; i++) cout << i <<    ;       cout << n <<    ;       for (long long j = n - 1; j >= n - down; j--) cout << j <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int a[N], b[N];   int main() {     int i, j, n, m, k, t, x, y, p;     long long ax, ay, tx, ty;     while (~scanf( %d , &n)) {       for (i = 0; i < n; i++) scanf( %d , &a[i]);       scanf( %d , &m);       for (i = 0; i < m; i++) scanf( %d , &b[i]);       sort(a, a + n);       sort(b, b + m);       ax = n * 2, ay = m * 2;       for (i = 0; i < n; i++) {         tx = (n - i) * 3 + i * 2;         p = lower_bound(b, b + m, a[i]) - b;         ty = (m - p) * 3 + p * 2;         if (tx - ty > ax - ay || (tx - ty) == (ax - ay) && tx > ax)           ax = tx, ay = ty;       }       printf( %I64d:%I64d n , ax, ay);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int len;   char s[109];   int main() {     cin >> len;     cin >> s;     int interval = 0;     for (int i = 0; i < len; i += interval) {       cout << s[i];       interval++;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = s.size();     queue<int> pos;     int arr[n];     arr[0] = 0;     int lastb = -1;     for (int i = 0; i < n; i++) {       if (s[i] ==  b ) {         if (i + 3 < n) {           if (s.substr(i, 4) ==  bear ) {             pos.push(i);             lastb = i;           }         }       }       if (i > 0) {         arr[i] = arr[i - 1];       }       if (s[i] ==  r ) {         if (lastb != -1 && i - lastb <= 3) {           arr[i] = arr[i - 1] + 1;         }       }     }     int k = 0;     int ans = 0;     for (int i = 0; i < n; i++) {       if (!pos.empty() && i > pos.front()) {         k++;         pos.pop();       }       for (int j = i + 1; j < n; j++) {         if (arr[j] - k > 0) {           ans++;         }       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   long long p(long long b, long long e) {     if (e == 0) return 1;     if (e == 1) return b;     if (e & 1) {       return ((b % 998244353) * p((b * b) % 998244353, e / 2)) % 998244353;     }     return (p((b * b) % 998244353, e / 2)) % 998244353;   }   int32_t main() {     long long n, m;     cin >> n >> m;     cout << p(2, (m + n));   }


#include <bits/stdc++.h>   using namespace std;   const unsigned long long mod = 1000000007;   int main() {     int x, y;     unsigned long long n = 0;     cin >> x >> y;     unsigned long long t = 0;     int power = 2;     for (int p = 0; p < 2200; p++) {       if (power > y) break;       t += y + 1 - power;       power += 2;     }     for (int i = 1; i < x; i++) {       y = min(i, x - i);       n += y;     }     n *= t;     cout << n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 200020;   const long long MOD = (int)1e9 + 7;   const int INF = 1e9;   const long long LLINF = 0x3f3f3f3f3f3f3f3f;   const long double EPS = 1e-7;   void get_sub(string s, int size, set<string>& sub) {     int n = s.size();     for (int l = 0, r = size - 1; r < n; l++, r++) {       string t = s.substr(l, size);       sub.insert(t);     }   }   set<string> merge(set<string> a, set<string> b) {     set<string> res = a;     for (auto s : b) {       res.insert(s);     }     return res;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int n, m;     cin >> n;     vector<string> pre(301, string()), suf(301, string());     vector<vector<set<string>>> sub(301, vector<set<string>>(10, set<string>()));     for (int i = 1; i <= n; i++) {       string s;       cin >> s;       int sz = s.size();       pre[i] = s.substr(0, min(9, sz));       suf[i] = s.substr(max(0, sz - 9), min(9, sz));       for (int k = 1; k <= 9; k++) {         get_sub(s, k, sub[i][k]);       }     }     cin >> m;     for (int i = 1; i <= m; i++) {       int a, b;       cin >> a >> b;       string t = suf[a] + pre[b];       int sz = t.size();       string p = pre[a] + pre[b];       sz = p.size();       pre[n + i] = p.substr(0, min(9, sz));       string s = suf[a] + suf[b];       sz = s.size();       suf[n + i] = s.substr(max(0, sz - 9), min(9, sz));       for (int k = 1; k <= 9; k++) {         sub[n + i][k] = merge(sub[a][k], sub[b][k]);         get_sub(t, k, sub[n + i][k]);       }       int res = 0;       for (int k = 1; k <= 9; k++) {         if ((int)sub[n + i][k].size() == (1 << k)) res = k;       }       cout << res <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   template <class T>   void print(vector<T>& v, bool spaced = true) {     int n = v.size();     string space = (spaced ?     :   );     for (int i = 0; i < n; ++i) {       cout << v[i] << space;     }     cout <<   n ;   }   template <class T>   void printendl(vector<T>& v) {     int n = v.size();     for (int i = 0; i < n; ++i) {       cout << v[i] <<   n ;     }   }   template <class T>   T gcd(T a, T b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   template <class T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <class T>   T extended_gcd(T a, T b, T& x, T& y) {     if (b == 0) {       x = 1;       y = 0;       return a;     }     T x1, y1;     T g = extended_gcd(b, a % b, x1, y1);     x = y1;     y = x1 - (a / b) * y1;     return g;   }   template <class T>   T diophantine_eq(T a, T b, T c, T& x, T& y, T& g) {     g = extended_gcd(abs(a), abs(b), x, y);     if (c % g) return false;     x *= (c / g);     y *= (c / g);     if (a < 0) x *= -1;     if (b < 0) y *= -1;     return true;   }   template <class T>   T euler_phi(T n) {     T result = n;     for (int i = 2; i * i <= n; ++i) {       if (n % i == 0) {         while (n % i == 0) {           n /= i;         }         result -= result / i;       }     }     if (n > 1) result -= result / n;     return result;   }   vector<ll> ranged_euler_phi(ll n) {     vector<ll> phi(n + 1);     phi[0] = 0;     phi[1] = 1;     for (int i = 2; i <= n; ++i) phi[i] = i;     for (int i = 2; i <= n; ++i) {       if (phi[i] == i) {         for (int j = i; j <= n; j += i) {           phi[j] -= phi[j] / i;         }       }     }     return phi;   }   bool check(int n) {     int count = 0;     for (int i = 2; i * i <= n; ++i) {       if (n % i == 0) {         count++;         while (n % i == 0) {           n /= i;         }       }     }     if (n > 1) count++;     return count == 2;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     ll n, x;     cin >> n >> x;     ll ans = 0;     for (int i = 1; i <= n; ++i) {       if (x % i == 0 && x / i <= n) ans++;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int mod1 = 1000000007;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long int t;     t = 1;     for (long long int f = 0; f < t; f++) {       int n;       cin >> n;       string A;       cin >> A;       int i;       int x = n - 11;       int in = -1, c = 0;       int y = 0;       int r = ceil(x / 2.0);       x = x / 2;       for (i = 0; i < n; i++) {         if (in == -1 && A[i] ==  8 ) in = i + 1;         if (A[i] ==  8 ) c++;         if (c == x + 1 && y == 0) y = i + 1;       }       if (in - 1 > r) {         cout <<  NO  << endl;         continue;       }       if (c <= x) {         cout <<  NO  << endl;         continue;       } else {         y = y - x;         y--;         if (y <= r) {           cout <<  YES  << endl;           continue;         }         cout <<  NO  << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int a, long long int n, long long int m);   long long int power(long long int a, long long int n, long long int m) {     if (n == 0) return 1;     long long int x = power(a, n / 2, m);     if (n % 2 != 0)       return (((a * x) % m) * (x) % m) % m;     else       return (x * x) % m;   }   double PI = 3.14159265357;   int32_t main() {     long long int n, i, j, x, y, m, k, t, sum, count, cnt, b, c, d, j1, z, a,         temp;     ios::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     cin >> t;     while (t--) {       cin >> n;       long long int arr[n];       long long int e = 0, o = 0;       for (i = 0; i < n; i++) {         cin >> arr[i];         if (arr[i] % 2 == 0)           e++;         else           o++;       }       if (e - o != (n) % 2) {         cout <<  -1 n ;         continue;       }       cnt = 0;       for (i = 0; i < n; i++)         if (arr[i] % 2 != i % 2) cnt++;       cout << cnt / 2 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &x) {     x = 0;     char ch;     while (!isdigit(ch = getchar()))       ;     do {       x = 10 * x + ch -  0 ;     } while (isdigit(ch = getchar()));   }   const int N = 3e6 + 111;   const int INF = 1e9;   int n, q, D[N], res;   long long A[N], F[N];   bool vst[N];   template <typename T>   inline bool mini(T &x, T y) {     if (x > y)       x = y;     else       return 0;     return 1;   }   template <typename T>   inline bool maxi(T &x, T y) {     if (x < y)       x = y;     else       return 0;     return 1;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     read(n);     read(q);     for (int i = 1; i <= n; i++) {       read(A[i]);     }     for (int i = n + 1; i <= 3 * n; i++) {       A[i] = A[i - n];     }     for (int i = 1; i <= 3 * n; i++) {       F[i] = F[i - 1] + A[i];     }     while (q--) {       long long x;       read(x);       int j = 0;       for (int i = 1; i <= 3 * n; i++) {         while (F[i] - F[j] > x) j++;         D[i] = i - j;       }       int k = INF;       int p;       for (int i = 2 * n + 1; i <= 3 * n; i++) {         if (mini(k, D[i])) {           p = i;         }       }       if (k >= n) {         cout << 1 <<   n ;         continue;       }       res = INF;       for (int r = p - D[p]; r <= p; r++) {         int l = r - n + 1;         int i = r;         int cnt = 0;         while (i >= l) {           cnt++;           i -= D[i];         }         mini(res, cnt);       }       cout << res <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, e, f;     scanf( %d%d%d%d%d%d , &a, &b, &c, &d, &e, &f);     if (d == 0) {       printf( Hermione );       return 0;     }     if (c == 0) {       printf( Ron );       return 0;     }     if (b == 0) {       printf( Hermione );       return 0;     }     if (a == 0) {       printf( Ron );       return 0;     }     if (f == 0) {       printf( Hermione );       return 0;     }     if (e == 0) {       printf( Ron );       return 0;     }     if (b * d * f > a * c * e)       printf( Ron );     else       printf( Hermione );     return 0;   }


#include <bits/stdc++.h>   using namespace std;      int n, m;      vector<int> a1, a2;   vector<int> b1, b2;      int subsolve(vector<int>& box, vector<int>& spec) {       int N = (int) box.size();       int M = (int) spec.size();          vector<int> good (M+5, 0);       int cumulate = 0;       for (int i=M-1; i>=0; i--) {           int& sp = spec[i];           if (binary_search(box.begin(), box.end(), sp)) cumulate++;           good[i] = cumulate;       }                 int ans=good[0];       for (int i=0; i<M; i++) {           int boxcnt = (int)(upper_bound(box.begin(), box.end(), spec[i]) - box.begin());           // _ * _ _ _ * _ _ *           //   # # # # # # # #           // [spec[i] - boxcnt + 1, spec[i] + 1)           int left_spec = (int)(lower_bound(spec.begin(), spec.end(), spec[i] - boxcnt + 1) - spec.begin());           ans = max(ans, (i-left_spec+1) + good[i+1]);       }       return ans;   }      void solve() {       a1.clear(); a2.clear(); b1.clear(); b2.clear();       cin >> n >> m;       for (int i=0; i<n; i++) {           int tmp; scanf( %d , &tmp);           if (tmp > 0) a1.push_back(tmp);           else a2.push_back(-tmp);       }       for (int i=0; i<m; i++) {           int tmp; scanf( %d , &tmp);           if (tmp > 0) b1.push_back(tmp);           else b2.push_back(-tmp);       }       sort(a1.begin(), a1.end());       sort(a2.begin(), a2.end());       sort(b1.begin(), b1.end());       sort(b2.begin(), b2.end());          printf( %d n , subsolve(a1, b1) + subsolve(a2, b2));   }      int main() {       int t; cin >> t;       while (t--)           solve();   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n;     cin >> n;     long long int a[n + 1][n + 1];     long long int s = 0;     for (int i = 1; i < n + 1; i++)       for (int j = 1; j < n + 1; j++) {         cin >> a[i][j];         if (i == j) s += a[i][j];       }     s %= 2;     long long int q;     cin >> q;     while (q--) {       long long int x;       cin >> x;       if (x == 1 || x == 2) {         long long int t;         cin >> t;         s ^= 1;       } else         cout << s;     }     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int t;     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   bool fine(int v) {     int z = 0, s = 0;     while ((v & 1) == 0) {       z++;       v >>= 1;     }     while ((v & 1) == 1) {       s++;       v >>= 1;     }     return v == 0 && z == s - 1;   }   int main() {     int n;     scanf( %d , &n);     for (int i = n; i >= 1; i--) {       if (n % i == 0 && fine(i)) {         printf( %d , i);         return 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool umin(T &x, T y) {     return y < x ? x = y, 1 : 0;   }   template <class T>   bool umax(T &x, T y) {     return y > x ? x = y, 1 : 0;   }   const int N = 505;   int n, m, g[N][N][2];   bitset<N> dp[100][2][N], ok, tmp;   signed main() {     cin >> n >> m;     for (int i = 1, u, v, w; i <= m; ++i) {       cin >> u >> v >> w;       dp[0][w][u][v] = 1;     }     for (int i = 1; i <= 60; ++i) {       for (int u = 1; u <= n; ++u) {         for (int k = 1; k <= n; ++k) {           if (dp[i - 1][0][u][k]) dp[i][0][u] |= dp[i - 1][1][k];           if (dp[i - 1][1][u][k]) dp[i][1][u] |= dp[i - 1][0][k];         }       }     }     for (int i = 1; i <= n; ++i)       if (dp[60][0][i].count()) {         puts( -1 );         return 0;       }     long long ans = 0;     ok[1] = 1;     int cur = 0;     for (int i = 59; i >= 0; --i) {       tmp = 0;       for (int u = 1; u <= n; ++u)         if (ok[u]) tmp |= dp[i][cur][u];       if (tmp.count()) {         for (int u = 1; u <= n; ++u) ok[u] = tmp[u];         ans |= (1ll << i);         if (ans > 1e18) {           ans = -1;           break;         }         cur ^= 1;       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   /*   #include <ext/pb_ds/assoc_container.hpp>    #include <ext/pb_ds/tree_policy.hpp>    using namespace __gnu_pbds;    #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>    */   typedef long long ll;   typedef long double ld;   typedef unsigned long long ull;   #define rep(i,a,b) for(ll i=a;i<=b;++i)   #define rrep(i,a,b) for(ll i=a;i>=b;--i)   #define FOR(i,n)  for(ll i=0;i<n;i++)   #define pb push_back   #define mp make_pair   #define PI 3.14159265358979323846   #define fi first   #define se second   #define all(x)  x.begin(),x.end()   #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);      const ll INF = 1e18+10;   const ll mod = 1e9+7;   const ll MAXN = 2e5+10;      ll poww(ll a, ll b) {           if(b<0) return 0LL;       ll ans = 1;       while (b) {           if (b & 1)ans = ans * a;           a = a * a;           b >>= 1;       }          return ans;   }   ll binpow(ll a, ll b)   {       if (b < 0) return 0LL;       if (a <= 0)return 0LL;       a %= mod;              ll ans = 1LL;       while (b) {           if (b & 1)ans = ans * a % mod;           a = a * a % mod;           b >>= 1;       }       return ans;   }   ll modinv(ll n) {       return binpow(n, mod - 2);   }      void solve() {         ll n; cin>>n;       vector<ll> x;       ll a[n]; FOR(i,n) { cin>>a[i]; x.pb(a[i]); }       sort(all(x));       vector<ll> s(n,0); s[0] = x[0];       ll j = 0;       vector<ll> inv(n,1);       for(ll i=1; i<n; i++) {            if(x[i]>s[i-1]) {               for(ll k=i-1; k>=j; k--) {                   inv[k] = 0;               }               j = i;           }           s[i] = s[i-1] + x[i];       }       map<ll,ll> mt;       FOR(i,n) {           if(inv[i]==1) mt[x[i]] = 1;       }       vector<ll> ans;       FOR(i,n) {           if(mt[a[i]]==1) ans.pb(i+1);       }       cout<<ans.size()<<  n ;       FOR(i,ans.size()) cout<<ans[i]<<   ;       cout<<  n ;   }         int main() {       IOS;        #ifndef ONLINE_JUDGE       freopen( input.txt ,  r , stdin);           freopen( output.txt ,  w , stdout);       #endif              ll no_of_test_cases; cin>>no_of_test_cases;        //ll no_of_test_cases = 1;       //cout<<fixed<<setprecision(10);              for(ll i=1; i<=no_of_test_cases; i++) {           solve();       }        return 0;    }


#include <bits/stdc++.h>   using namespace std;   int n, arr[101], color, maxi, mini = 101;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> color;     for (int i = 0; i < n; i++) {       cin >> arr[i];       mini = min(mini, arr[i]);       maxi = max(maxi, arr[i]);     }     if (maxi - mini > color) {       cout <<  NO n ;       return 0;     }     cout <<  YES n ;     for (int i = 0; i < n; i++) {       int j = 1;       while (arr[i]--) {         cout << j <<    ;         if (j == color) j = 0;         j++;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string S;   struct State {     char p[2][13];   };   int dx[5] = {1, 0, -1, 0, 1}, dy[8] = {0, 1, 0, -1, 1};   bool OK = false;   int solve(State &E, int r1, int r2, int depth) {     if (OK == true) return 1;     if (depth == 27) {       for (int i = 0; i < 26; i++) {         cout << E.p[i / 13][i % 13];         if (i % 13 == 12) cout << endl;       }       OK = true;       return 1;     }     for (int i = 0; i < 5; i++) {       int cx = r1 + dx[i], cy = r2 + dy[i];       if (cx < 0 || cx >= 2 || cy < 0 || cy >= 13) continue;       if (E.p[cx][cy] !=  $  && E.p[cx][cy] != S[depth]) continue;       char F = E.p[cx][cy];       E.p[cx][cy] = S[depth];       solve(E, cx, cy, depth + 1);       E.p[cx][cy] = F;     }     return 0;   }   int main() {     cin >> S;     for (int i = 0; i < 2; i++) {       for (int j = 0; j < 13; j++) {         State Y;         for (int k = 0; k < 26; k++) Y.p[k / 13][k % 13] =  $ ;         Y.p[i][j] = S[0];         solve(Y, i, j, 1);       }     }     if (OK == false) cout <<  Impossible  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 2000000000;   static inline int Rint() {     struct X {       int dig[256];       X() {         for (int i =  0 ; i <=  9 ; ++i) dig[i] = 1;         dig[ - ] = 1;       }     };     static X fuck;     int s = 1, v = 0, c;     for (; !fuck.dig[c = getchar()];)       ;     if (c ==  - )       s = 0;     else if (fuck.dig[c])       v = c ^ 48;     for (; fuck.dig[c = getchar()]; v = v * 10 + (c ^ 48))       ;     return s ? v : -v;   }   template <typename T>   static inline void cmax(T& a, const T& b) {     if (b > a) a = b;   }   template <typename T>   static inline void cmin(T& a, const T& b) {     if (b < a) a = b;   }   const int maxn = 100005;   int data[505][505];   long long sum[505][505];   long long ps[505][505];   long long best_sum[505][505];   long long best_cnt[505][505];   static inline long long sq(long long x) { return x * x; }   static inline int check_intersection(int x1, int y1, int x2, int y2, int r) {     const int r2 = r * r;     const int F = sq(2 * (r + 1));     const int d = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);     if (d <= F) {       const int sx = x1 + x2;       const int sy = y1 + y2;       int ux[2], uy[2];       int tx = sx >> 1, ty = sy >> 1;       for (int a = -2; a <= 3; ++a)         for (int b = -2; b <= 3; ++b) {           int t0 = sq(a + tx - x1) + sq(b + ty - y1);           if (t0 > r2) continue;           int t1 = sq(a + tx - x2) + sq(b + ty - y2);           if (t1 > r2) continue;           return 1;         }     }     return 0;   }   int main() {     const int n = Rint(), m = Rint(), r = Rint();     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) data[i][j] = Rint();     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) ps[i][j] = data[i][j] + ps[i][j - 1];     const int r2 = r * r;     for (int i = r + 1; i <= n - r; ++i)       for (int j = r + 1; j <= m - r; ++j) {         long long s = 0;         int l = j;         for (int ii = i - r; ii <= i; ++ii) {           while (sq(ii - i) + sq(l - j) <= r2) --l;           const int r = 2 * j - l;           s += ps[ii][r - 1] - ps[ii][l];           int other = 2 * i - ii;           if (other != ii) s += ps[other][r - 1] - ps[other][l];         }         sum[i][j] = s;       }     for (int i = 1; i <= n; ++i) {       long long bv = 0;       int bc = 0;       for (int j = m; j >= 1; --j) {         if (sum[i][j] > bv)           bv = sum[i][j], bc = 1;         else if (sum[i][j] == bv)           ++bc;         best_sum[i][j] = bv;         best_cnt[i][j] = bv ? bc : 0;       }     }     const int limit = (r + 15) * (r + 15);     const int most = (r + 1) * 2;     long long best = 0;     long long cnt = 0;     for (int j = r + 1; j <= m - r; ++j)       for (int i = r + 1; i <= n - r; ++i) {         const long long s1 = sum[i][j];         for (int ii = r + 1; ii < i - 2 * r; ++ii) {           if (best_sum[ii][j + 1] == 0) continue;           long long t = s1 + best_sum[ii][j + 1];           if (t > best)             best = t, cnt = best_cnt[ii][j + 1];           else if (t == best)             cnt += best_cnt[ii][j + 1];         }         for (int ii = i + 2 * r + 1; ii <= n - r; ++ii) {           if (best_sum[ii][j] == 0) continue;           long long t = s1 + best_sum[ii][j];           if (t > best)             best = t, cnt = best_cnt[ii][j];           else if (t == best)             cnt += best_cnt[ii][j];         }         const int starti = max(i - 2 * r, r + 1);         const int endi = min(i + 2 * r, n - r);         for (int ii = starti, lastj = j + 1; ii <= i; ++ii) {           while (lastj <= m - r && check_intersection(i, j, ii, lastj, r))             ++lastj;           if (lastj > m - r) break;           const int s = s1 + best_sum[ii][lastj];           if (s > best)             best = s, cnt = best_cnt[ii][lastj];           else if (s == best)             cnt += best_cnt[ii][lastj];         }         for (int ii = endi, lastj = j; ii > i; --ii) {           while (lastj <= m - r && check_intersection(i, j, ii, lastj, r))             ++lastj;           if (lastj > m - r) break;           const int s = s1 + best_sum[ii][lastj];           if (s > best)             best = s, cnt = best_cnt[ii][lastj];           else if (s == best)             cnt += best_cnt[ii][lastj];         }       }     printf( %I64d %I64d n , best, cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void in(int &x) {     register int c = getchar();     x = 0;     for (; (c < 48 || c > 57); c = getchar())       ;     for (; c > 47 && c < 58; c = getchar()) {       x = (x << 1) + (x << 3) + c - 48;     }   }   long long mod;   bool prime(int n) {     int i;     if (n % 2 == 0 && n > 2) return false;     for (i = 3; i * i <= n; i += 2)       if (n % i == 0) return false;     return true;   }   long long powmod(long long base, long long exp) {     long long res = 1;     while (exp) {       if (exp & 1) res = (res * base) % mod;       base = (base * base) % mod;       exp >>= 1;     }     return res;   }   int main() {     int n, i, x;     in(n);     if (n == 1) {       puts( YES n1 );       return 0;     }     if (n == 4) {       puts( YES n1 n3 n2 n4 );       return 0;     }     if (!prime(n)) {       puts( NO );       return 0;     }     mod = n;     puts( YES n1 );     for (i = 2; i < n; i++) printf( %lld n , i * powmod(i - 1, n - 2) % n);     printf( %d n , n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = (int)1e9;   const int mod = (int)1e9 + 7;   const double PI = acos(-1.0);   const int MAX = 400009;   int n;   char s[MAX], ans[MAX];   int occ[250];   int main(int argc, char* argv[]) {     scanf( %d , &n);     scanf( %s , s);     for (int i = 0; i < n; i++) occ[s[i]]++;     int odd = 0;     vector<char> a;     for (int i = 0; i < 130; i++) {       odd += (occ[i] & 1);       if (occ[i] & 1) {         a.push_back(i);         --occ[i];       }     }     for (int i = 0; i < 130; i++)       while (occ[i]--) a.push_back(i);     reverse((a).begin(), (a).end());     for (int i = 0; i < n; i++) ans[i] =  * ;     for (int d = 1; d <= n; d++)       if (n % d == 0 && d >= odd && (!odd || ((n / d) % 2 == 1))) {         int nbr = d, len = n / d;         for (int i = 0; i < nbr && odd; i++) {           ans[len * i + len / 2] = a.back();           a.pop_back();         }         cout << nbr << endl;         for (int i = 0; i < nbr; i++)           for (int j = 0; j < len / 2; j++) {             ans[len * i + j] = a.back();             a.pop_back();             ans[len * i + len - 1 - j] = a.back();             a.pop_back();           }         for (int i = 0; i < nbr; i++) {           if (i) cout <<    ;           for (int j = 0; j < len; j++) cout << ans[i * len + j];         }         cout << endl;         return 0;       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, p, i, t, ans, a[101];   char s[101];   int main() {     scanf( %I64d%I64d , &n, &p);     for (i = 1; i <= n; i++) {       scanf( %s n , &s);       if (strlen(s) > 4) a[i] = 1;     }     for (i = n; i; i--) {       ans += t * p;       if (a[i]) ans += p / 2;       t = t * 2 + a[i];     }     printf( %I64d , ans);   }


#include <bits/stdc++.h>   using namespace std;   char str[5009];   int main() {     int a = 0, b = 0, c = 0, i;     scanf( %s , str);     int n = strlen(str);     for (i = 0; str[i] ==  a ; i++) a++;     for (; str[i] ==  b ; i++) b++;     for (; str[i] ==  c ; i++) c++;     if (a && b && n == a + b + c && (a == c || c == b)) {       printf( YES n );     } else {       printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, temp;     cin >> n;     temp = n;     vector<pair<long long, int> > v;     for (int i = 2; i <= sqrt(n); i++) {       int count = 0;       while (temp % i == 0) {         temp /= i;         count++;       }       if (count != 0) v.push_back(make_pair(i, count));     }     long long num = 0, flag = 0;     if (temp != 1) v.push_back(make_pair(temp, 1));     if ((v.size() == 2 and v[0].second == 1 and v[1].second == 1) or         (v.size() == 1 and v[0].second == 2))       cout <<  2  << endl;     else {       cout <<  1 n ;       for (int i = 0; i < v.size(); i++) {         if (v[i].second > 2) {           num = v[i].first * v[i].first;           flag = 1;           break;         }       }       if (flag == 0 and v.size() >= 2) num = v[0].first * v[1].first;       cout << num << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int k = 0;       int i = 1;       while (k < n) {         if (i % 3 == 0 || to_string(i).back() ==  3 ) {         } else           ++k;         ++i;       }       cout << --i << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[100000];   int n;   priority_queue<pair<int, int>, vector<pair<int, int> >,                  greater<pair<int, int> > >       q;   int rankHash[100000];   int indHash[100000];   vector<pair<int, int> > ans;   int main(void) {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , arr + i);     bool isSorted = true;     int lucky = -1;     for (int i = 0; i < n - 1; i++) {       if (arr[i + 1] < arr[i]) {         isSorted = false;         break;       }     }     if (isSorted) {       printf( 0 n );       return 0;     }     for (int i = 0; i < n; i++) {       int tar = arr[i];       bool isLucky = true;       while (tar) {         if (tar % 10 != 4 && tar % 10 != 7) {           isLucky = false;           break;         }         tar /= 10;       }       if (isLucky) {         lucky = i;         break;       }     }     if (lucky == -1) {       printf( -1 n );       return 0;     }     for (int i = 0; i < n; i++) q.push(make_pair(arr[i], i));     for (int i = 0; i < n; i++) {       rankHash[i] = q.top().second;       q.pop();     }     for (int i = 0; i < n; i++) indHash[rankHash[i]] = i;     for (int i = 0; i < n; i++) {       if (i != lucky) {         ans.push_back(make_pair(i + 1, lucky + 1));         rankHash[indHash[i]] = lucky;         rankHash[indHash[lucky]] = i;         swap(indHash[i], indHash[lucky]);         lucky = i;       }       if (lucky != rankHash[i]) {         ans.push_back(make_pair(lucky + 1, rankHash[i] + 1));         int r1 = i;         int r2 = indHash[lucky];         int i1 = rankHash[r1];         int i2 = rankHash[r2];         rankHash[r2] = i1;         rankHash[r1] = lucky;         swap(indHash[i1], indHash[i2]);         lucky = i1;       }     }     printf( %d n , (int)ans.size());     for (int i = 0; i < ans.size(); i++)       printf( %d %d n , ans[i].first, ans[i].second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     string str;     cin >> n >> str;     int a = 0;     int d = 0;     for (int i = 0; i < n; i++) {       if (str[i] ==  A ) {         a++;       } else {         d++;       }     }     if (a > d) {       cout <<  Anton  << endl;     } else if (a < d) {       cout <<  Danik  << endl;     } else {       cout <<  Friendship  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> cnt;   int n;   int m;   int dp[500][100005];   vector<int> num;   map<int, int> can;   int ind = 0;   int dpnum[500];   map<int, int> mpind;   map<int, int> mpvis;   int main() {     scanf( %d%d , &n, &m);     int x;     for (int i = 0; i < n; i++) {       scanf( %d , &x);       num.push_back(x);       if (can[x] == 0) {         if (cnt[x] < x) {           cnt[x]++;         }         if (cnt[x] == x) {           can[x] = 1;         }       }     }     for (int i = 0; i < n; i++) {       if (!can[num[i]]) continue;       if (mpind[num[i]] != 0) continue;       if (mpind[num[i]] == 0) {         ind++;         mpind[num[i]] = ind;         dpnum[ind] = num[i];       }       int tind = mpind[num[i]];       for (int j = 0; j < n; j++) {         if (j == 0) {           if (num[j] == num[i])             dp[tind][j + 1] = 1;           else             dp[tind][j + 1] = 0;         } else {           if (num[j] == num[i])             dp[tind][j + 1] = dp[tind][j] + 1;           else             dp[tind][j + 1] = dp[tind][j];         }       }     }     int l, r;     for (int i = 0; i < m; i++) {       scanf( %d%d , &l, &r);       int ans = 0;       for (int i = 1; i <= ind; i++) {         if (dp[i][r] - dp[i][l - 1] == dpnum[i]) {           ans++;         }       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   bool local = false;   using namespace std;   template <class T>   string toString(T x) {     ostringstream sout;     sout << x;     return sout.str();   }   template <class T>   void print(T v) {     cout << ((int)(v).size()) <<   n ;     for (auto x : v) cout << x <<    ;     cout <<   n ;   };   template <class T>   void print1(T v) {     cout << ((int)(v).size()) <<   n ;     for (auto x : v) cout << x + 1 <<    ;     cout <<   n ;   };   template <class T1, class T2>   ostream &operator<<(ostream &o, pair<T1, T2> x) {     return o << x.first <<     << x.second;   }   template <class T1, class T2>   istream &operator>>(istream &o, pair<T1, T2> &x) {     return o >> x.first >> x.second;   }   template <class T1, class T2>   pair<T1, T2> operator+(pair<T1, T2> a, pair<T1, T2> b) {     a.first += b.first;     a.second += b.second;     return a;   }   template <class T1, class T2>   pair<T1, T2> operator-(pair<T1, T2> a, pair<T1, T2> b) {     a.first -= b.first;     a.second -= b.second;     return a;   }   template <class T1, class T2>   void operator+=(pair<T1, T2> &a, pair<T1, T2> b) {     a.first += b.first;     a.second += b.second;   }   template <class T1, class T2>   void operator-=(pair<T1, T2> &a, pair<T1, T2> b) {     a.first -= b.first;     a.second -= b.second;   }   int nint() {     int x;     cin >> x;     return x;   }   double getTime() { return clock() / (double)CLOCKS_PER_SEC; };   mt19937 rnd(0);   int rand(int n) { return rnd() % n; }   int rand(int l, int r) { return rnd() % (r - l + 1) + l; }   const int mod = 1000000000 + 7;   void initIO() {     if (local) {       freopen( input.txt ,  r , stdin);       srand((int)time(0));       rnd.seed((int)time(0));     } else {     }     {       ios::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);     };   }   void solve();   int main() {     initIO();     int tc = 1;     for (int tt = 0; tt < (tc); tt++) {       solve();     }     if (local)       cout <<   n             <<  time =   << getTime() <<   n ;   }   long long n;   long long get(long long l, long long r) { return r - l + 1; }   const int D = 50000;   int a, b;   int check(int a1, int b1) {     if (a1 < 0 || b1 < 0) return 0;     int d = a1 + b1;     int r = n % d;     int k = n / d;     long long a2 = a1 * k;     long long b2 = b1 * k;     long long ra = a - a2;     long long rb = b - b2;     if (ra < 0 || rb < 0 || ra > a1 || rb > b1 || ra + rb > r) return 0;     return 1;   }   int getansD(int d) {     int k = n / d;     int la = a / (k + 1);     int ra = a / k;     for (int a = la; a <= ra; a++) {       int b = d - a;       if (check(a, b)) return 1;     }     return 0;   }   int get(int a, int k) {     int l = 0, r = a / k;     int ans = 0;     while (l <= r) {       int c = (l + r) / 2;       if (a / k - c >= c * (long long)k + a % k) {         ans = c;         l = c + 1;       } else         r = c - 1;     }     return ans;   }   int getansK(int k) {     int da = a / k;     int db = b / k;     if (a % k > da || b % k > db) return 0;     int ca = get(a, k);     int cb = get(b, k);     int rd = da + db;     long long l = 1, r = rd;     long long ans = rd + 1;     while (l <= r) {       long long d = (l + r) / 2;       long long res = (long long)n - d * k;       if (n / d < k || res >= d || d < (da - ca) + (db - cb)) {         l = d + 1;       } else {         ans = d;         r = d - 1;       }     }     return max(0ll, rd - ans + 1);   }   void solve() {     cin >> a >> b;     if (a > b) swap(a, b);     n = a + b;     if (a == 1) {       long long l = n / 2 + 1;       long long r = n;       cout << get(l, r) <<   n ;       return;     }     long long ans = 0;     for (int d = 1; d <= n; d++) {       int k = n / d;       if (k <= D) break;       ans += getansD(d);     }     for (int k = 1; k <= D; k++) ans += getansK(k);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     long long x, y;     point(long long _x, long long _y) {       x = _x;       y = _y;     }     point() {}   };   struct cmp {     bool operator()(point a, point b) { return (a.x < b.x); }   };   struct vec {     long long x, y;     vec(long long _x, long long _y) {       x = _x;       y = _y;     }     vec() {}   };   set<point, cmp> daftar;   int q, jenis, last = 0;   long long totalmana, a, b;   bool ans;   long double gradien(point p1, point p2) {     return (long double)(p1.y - p2.y) / (p1.x - p2.x);   }   long double manacost(long double indeks) {     set<point, cmp>::iterator it1, it2;     it1 = daftar.lower_bound(point((long long)indeks, 0));     it2 = daftar.upper_bound(point((long long)indeks, 0));     if (it1 == it2) it1--;     if (it2 == daftar.end()) return 1000000000001LL;     return (long double)it1->y +            gradien(*it1, *it2) * ((long double)indeks - it1->x);   }   vec toVec(point awal, point akhir) {     return vec(akhir.x - awal.x, akhir.y - awal.y);   }   long double cross(vec v1, vec v2) {     return (long double)v1.x * (long double)v2.y -            (long double)v1.y * (long double)v2.x;   }   long double cross(point p1, point p2, point p3) {     return cross(toVec(p1, p2), toVec(p1, p3));   }   int keatas(int pembilang, int penyebut) {     int ret = pembilang / penyebut;     if ((pembilang % penyebut) != 0) ret++;     return ret;   }   void seimbangkan(point baru) {     auto it = daftar.find(baru);     while (prev(it) != daftar.begin()) {       auto it2 = prev(it);       auto it3 = prev(it2);       if (cross(*it3, *it2, *it) > 1e-9) break;       daftar.erase(it2);     }     while (next(it) != daftar.end()) {       auto it2 = next(it);       auto it3 = next(it2);       if (cross(*it, *it2, *it3) > 1e-9) break;       daftar.erase(it2);     }   }   int main() {     daftar.insert(point(0, 0));     scanf( %d%lld , &q, &totalmana);     for (int query = 1; query <= q; query++) {       scanf( %d%lld%lld , &jenis, &a, &b);       a = (a + last) % 1000000 + 1;       b = (b + last) % 1000000 + 1;       if (jenis == 1) {         if (manacost(a) > (long double)b + 1e-9) {           daftar.insert(point(a, b));           seimbangkan(point(a, b));         }       } else {         swap(a, b);         auto it = daftar.lower_bound(point((a + b - 1) / b, 0));         ans = false;         if (it != daftar.end()) {           if (it->y * b <= totalmana)             ans = true;           else {             auto it2 = prev(it);             if ((cross(toVec(point(it2->x * b, it2->y * b), point(a, totalmana)),                        toVec(point(it2->x * b, it2->y * b),                              point(it->x * b, it->y * b)))) < 1e-9)               ans = true;           }         }         if (ans)           printf( YES n ), last = query;         else           printf( NO n );       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int maxn = 125;   const int maxm = 305;   const int mod = 20090717;   vector<int> v;   int main() {     long long x;     scanf( %lld , &x);     while (x > 0) v.push_back(x % 2), x /= 2;     while (v.size() < 6) v.push_back(0);     long long ans = 0;     reverse(v.begin(), v.end());     ans = ans * 2 + v[0];     ans = ans * 2 + v[5];     ans = ans * 2 + v[3];     ans = ans * 2 + v[2];     ans = ans * 2 + v[4];     ans = ans * 2 + v[1];     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   void Solve();   int main() { Solve(); }   using namespace std;   const int INF = 1e9;   const int N = 20;   const double e = 1E-10;   int hm, am, dm;   int check(int ay, int dy) {     int m = max(0, ay - dm), y = max(0, am - dy);     if (!m) return -1;     return (hm / m + (hm % m != 0)) * y + 1;   }   void Solve() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int hy, ay, dy, h, a, d, mn = 1e9;     cin >> hy >> ay >> dy >> hm >> am >> dm >> h >> a >> d;     for (int i = 0; i <= 200; i++) {       for (int j = 0; j <= 200; j++) {         int hp = check(ay + i, dy + j);         if (hp == -1) continue;         mn = min(mn, max(0, hp - hy) * h + i * a + j * d);       }     }     cout << mn;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k;     cin >> n >> k;     n /= k;     if (n % 2)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   int a[15][110], b[15][110], c[15][110];   char buf[15];   int calc(int p, int q) {     static pair<int, int> d[110];     int cnt = k, res = 0;     for (int i = 1; i <= m; i++)       d[i].first = b[q][i] - a[p][i], d[i].second = c[p][i];     sort(d + 1, d + m + 1, greater<pair<int, int> >());     for (int i = 1; i <= m && d[i].first > 0; i++) {       if (cnt <= d[i].second) {         res += d[i].first * cnt;         break;       }       res += d[i].first * d[i].second;       cnt -= d[i].second;     }     return res;   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++) {       scanf( %s , buf);       for (int j = 1; j <= m; j++) scanf( %d%d%d , &a[i][j], &b[i][j], &c[i][j]);     }     int ans = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (i != j) ans = max(ans, calc(i, j));     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   #define ll long long int   using namespace std;      int main() {         ll t;    cin>>t;    while(t--)    {       ll x,y;       cin>>x>>y;       if(x==y)       {           cout<<x+y<<  n ;       }       else       {           cout<<2*max(x,y)-1<<  n ;       }    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int x = 1;     map<int, int> m;     int y = 1;     m[x] = 1;     while (y < 1001) {       m[y] = 1;       int temp = y + x;       x = y;       y = temp;     }     m[y] = 1;     for (int i = 1; i <= n; i++) {       if (m[i] == 1) {         cout <<  O ;       } else         cout <<  o ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000100;   const int INF = 1e9 + 10;   int c, n;   int a[maxn], b[maxn];   int cnt[maxn];   bool check(int anow, int &now) {     int bnow = b[now] - anow;     if (bnow <= 0) {       if (now <= n && anow + 1 > a[now]) now++;       return 0;     }     int tmp = bnow;     for (int i = now - 1; i >= 1; i--) {       tmp -= min(tmp / a[i], cnt[i]) * a[i];       if (tmp == 0) {         if (now <= n && anow + 1 > a[now]) now++;         return 0;       }     }     return 1;   }   int main() {     while (cin >> c >> n) {       for (int i = 1; i <= n; i++) scanf( %d , &a[i]);       sort(a + 1, a + n + 1);       memset(cnt, 0, sizeof(cnt));       int m = 1;       cnt[1] = 1;       for (int i = 2; i <= n; i++) {         if (a[i] != a[i - 1])           a[++m] = a[i], cnt[m] = 1;         else           cnt[m]++;       }       n = m;       int tmp = c;       b[n + 1] = tmp;       for (int i = n; i >= 1; i--) {         tmp -= min(tmp / a[i], cnt[i]) * a[i];         b[i] = tmp;       }       if (tmp) {         puts( 0 );         continue;       }       int res = 0;       int now = 1;       for (int i = 1; i <= c; i++) {         if (check(i, now)) {           res = i;           break;         }       }       if (res)         printf( %d n , res);       else         puts( Greed is good );     }     return 0;   }


#include <bits/stdc++.h>   const int MAXN = int(2e5);   int n, k, cnt, A, tot[2 * MAXN + 5];   bool flag;   long long ans;   int read(int &x) {     char c = getchar();     int a = 0, b = 1;     while ( 0  > c || c >  9 ) b = c ==  -  ? -1 : b, c = getchar();     while ( 0  <= c && c <=  9 ) a = a * 10 + c -  0 , c = getchar();     return x = a * b;   }   int main() {     read(n);     read(k);     tot[MAXN]++;     for (int i = 0; i < n; i++) {       read(A);       if (A == k) flag = true;       if (A > k) cnt++;       if (A < k) cnt--;       if (!flag)         tot[cnt + MAXN]++;       else         ans += tot[cnt + MAXN] + tot[cnt + MAXN - 1];     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   int n, m, k;   const int maxn = 1100000;   int has[maxn];   pair<int, int> buy[maxn];   int tmp[maxn * 2];   bool test(int mid) {     for (int i = 1; i <= n; i++) tmp[i] = has[i];     for (int i = 1; i <= mid; i++) {       tmp[i + n] = buy[i].first;     }     sort(tmp + 1, tmp + 1 + n + mid);     int dd = 0;     int cnt = 0;     bool du = true;     for (int i = 1; i <= n + mid; i++) {       if (dd > tmp[i]) {         du = false;         break;       }       cnt++;       if (cnt == k) {         dd++;         cnt = 0;       }     }     return du;   }   void solve() {     int dd = 0;     int cnt = 0;     bool du = true;     for (int i = 1; i <= n; i++) {       if (dd > has[i]) {         du = false;         break;       }       cnt++;       if (cnt == k) {         dd++;         cnt = 0;       }     }     if (du == false) {       cout << -1 << endl;       return;     }     int l = 0;     int r = m;     int ans = 0;     while (l <= r) {       int mid = (l + r) / 2;       if (test(mid)) {         ans = max(ans, mid);         l = mid + 1;       } else         r = mid - 1;     }     cout << ans << endl;     for (int i = 1; i <= ans; i++) {       if (i == 1)         printf( %d , buy[i].second);       else         printf(  %d , buy[i].second);     }     cout << endl;   }   int main() {     while (cin >> n >> m >> k) {       for (int i = 1; i <= n; i++) scanf( %d , &has[i]);       for (int i = 1; i <= m; i++) {         int x;         scanf( %d , &x);         buy[i].first = x;         buy[i].second = i;       }       sort(has + 1, has + n + 1);       sort(buy + 1, buy + m + 1);       reverse(buy + 1, buy + m + 1);       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, i, a, b, j, pos = 0, neg = 0, flag = 0, temp;     string st, st2, st3;     vector<long long int> v2, v;     long long int ar[100001] = {0};     cin >> a >> b;     if (a == 1) {       cout << b;       return 0;     } else if (b == 1) {       cout << a;       return 0;     }     while (a > 0 && b > 0) {       if (a == b) {         a = 0;         b = 0;         flag++;       } else if (a < b) {         flag += b / a;         b = b % a;       } else if (b < a) {         flag += a / b;         a = a % b;       }     }     cout << flag;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ne(long long a) {     long long k = pow(a, 0.5);     if (k * k == a) {       return 0;     }     return min(a - (k * k), (k + 1) * (k + 1) - a);   }   int main() {     long long n;     cin >> n;     vector<pair<long long, long long> > a(n, make_pair(0, 0));     for (long long i = 0; i < n; i++) {       cin >> a[i].second;       a[i].first = ne(a[i].second);     }     sort(a.begin(), a.end());     if (a[n / 2].first == 0) {       long long c = 0;       long long u = n / 2;       long long count = 0;       while (u < n && a[u].first == 0) {         c++;         u++;       }       u = c;       for (long long i = 0; i < n; i++) {         if (a[i].first == 0 && a[i].second != 0) {           u--;           count++;         }         if (u == 0) {           break;         }       }       while (u--) {         count += 2;       }       cout << count << endl;     } else {       long long count = 0;       for (long long i = 0; i < n / 2; i++) {         count = count + a[i].first;       }       cout << count << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int nax = 1e6 + 10;   vector<int> tree(4 * nax);   long long i, j, x, y, k, val;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long r, g, b;       cin >> r >> g >> b;       vector<long long> v;       v.push_back(r), v.push_back(g), v.push_back(b);       sort(v.begin(), v.end());       if (v[2] >= v[1] + v[0])         cout << v[1] + v[0] << endl;       else         cout << (v[0] + v[1] + v[2]) / 2 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, c, d;   long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }   int main() {     scanf( %lld %lld %lld %lld , &a, &b, &c, &d);     long long ans = gcd(c, d);     long long ans1 = c / ans;     long long ans2 = d / ans;     ans = min(a / ans1, b / ans2);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (int)1e9;   const int mod = (int)1e9 + 7;   const int MAXN = (int)3e5 + 5;   vector<int> primes[1000005];   int x, p, k;   vector<pair<int, int> > v(1 << 7);   int calc(int a) {     int cnt = 1;     int num = 0;     int tmp = a;     a = 0;     for (int i = 1; i < (1 << primes[p].size()); i++) {       if (cnt * 2 == i) {         cnt *= 2;         num++;       }       v[i] = {v[i - cnt].first * primes[p][num], v[i - cnt].second + 1};       if (v[i].second % 2) {         a += tmp / v[i].first;       } else {         a -= tmp / v[i].first;       }     }     return tmp - a;   }   void solve() {     cin >> x >> p >> k;     k += calc(x);     int l = x + 1, r = 6e6 + 5e5 + 3e4 + 4e3 + 0e2 + 4e1;     while (l < r) {       int m = (l + r) / 2;       if (calc(m) >= k) {         r = m;       } else {         l = m + 1;       }     }     cout << l <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     for (int i = 2; i < 1000005; i++) {       if (!primes[i].size()) {         for (int j = i; j < 1000005; j += i) {           primes[j].push_back(i);         }       }     }     v[0] = {1, 0};     int t = 1;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   long long powmod(long long base, long long exp) {     base %= ((int)1e9 + 7);     long long result = 1;     while (exp > 0) {       if (exp & 1) result = (result * base) % ((int)1e9 + 7);       base = (base * base) % ((int)1e9 + 7);       exp >>= 1;     }     return result % ((int)1e9 + 7);   }   long long inv(long long x) {     return powmod(x, ((int)1e9 + 7) - 2) % ((int)1e9 + 7);   }   long long sum_to(long long x) {     if (x < 0) return 0;     return (((x * (x + 1)) % ((int)1e9 + 7)) * inv(2)) % ((int)1e9 + 7);   }   long long sq(long long x) { return (x * x) % ((int)1e9 + 7); }   long long sumodd(long long o) {     long long x = o / 2;     x %= ((int)1e9 + 7);     return sq(x + 1) % ((int)1e9 + 7);   }   long long sumeven(long long e) {     e /= 2;     e %= ((int)1e9 + 7);     return (2 * sum_to(e)) % ((int)1e9 + 7);   }   long long f(long long x) {     if (x == 0) return 0;     if (x == 1) return 1;     if (x == 2) return 3;     long long k = 0;     for (;; k++)       if ((1LL << k) - 1 > x) break;     k--;     long long e = 2, o = 1;     long long adde = 4, addo = 2;     for (int i = int(0); i < int(k / 2 - 1); i++) {       e += adde;       o += addo;       adde *= 4;       addo *= 4;     }     long long d = x - ((1LL << k) - 1);     if (k & 1) o = (o + addo);     if (k & 1) {       o = (o + 2 * ((1LL << (k - 1)) - 1));       e = (e + 2 * ((1LL << (k - 2)) - 1));       e = (e + 2 * d);     } else {       o = (o + 2 * ((1LL << (k - 2)) - 1));       e = (e + 2 * ((1LL << (k - 1)) - 1));       o = (o + 2 * d);     }     return ((sumodd(o) + sumeven(e)) % ((int)1e9 + 7) + ((int)1e9 + 7)) %            ((int)1e9 + 7);   }   int main() {     ios::sync_with_stdio(false);     long long l, r;     cin >> l >> r;     cout << (f(r) - f(l - 1) + ((int)1e9 + 7)) % ((int)1e9 + 7) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int d, m, n, b[210000];   int top, s[210000];   struct node {     int x, p;     bool operator<(const node &a) const { return x < a.x; }   } a[210000];   char Getchar() {     static char now[1 << 20], *S, *T;     if (T == S) {       T = (S = now) + fread(now, 1, 1 << 20, stdin);       if (T == S) return EOF;     }     return *S++;   }   int read() {     int x = 0, f = 1;     char ch = Getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = Getchar();     }     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch -  0 , ch = Getchar();     return x * f;   }   int main() {     d = read();     m = read();     n = read();     for (int i = 0; i < n; i++) {       a[i].x = read();       a[i].p = read();     }     sort(a, a + n);     a[n].x = d;     a[n].p = 0;     top = 1;     s[top] = n;     for (int i = n - 1; i >= 0; i--) {       while (a[s[top]].p >= a[i].p) top--;       b[i] = s[top];       s[++top] = i;     }     int res = m - a[0].x;     long long ans = 0;     for (int i = 0; i < n && res >= 0; i++) {       if (a[b[i]].x - a[i].x > res) {         int d = min(a[b[i]].x - a[i].x, m) - res;         res += d;         ans += 1ll * d * a[i].p;       }       res -= a[i + 1].x - a[i].x;     }     if (res < 0)       puts( -1 );     else       printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5, M = 1e4, MOD = 1e9 + 7, INF = 0x3f3f3f3f;   const double eps = 1e-8, pi = acos(-1.0);   int n, m;   vector<int> son[N + 10];   int col[N + 10];   int in[N + 10], out[N + 10], bel[N + 10];   int tot;   int k[N + 10];   struct query {     int l, r, id;   } node[N + 10];   int unit;   int cnt[N + 10];   int k_ti[N + 10];   int ans[N + 10];   bool cmp(query a, query b) {     if (a.l / unit != b.l / unit)       return a.l / unit < b.l / unit;     else       return a.r < b.r;   }   void work() {     memset(cnt, 0, sizeof cnt);     memset(k_ti, 0, sizeof k_ti);     int l = 1, r = 0;     for (int i = 0; i < m; i++) {       while (r < node[i].r) {         r++;         cnt[col[bel[r]]]++;         k_ti[cnt[col[bel[r]]]]++;       }       while (r > node[i].r) {         k_ti[cnt[col[bel[r]]]]--;         cnt[col[bel[r]]]--;         r--;       }       while (l < node[i].l) {         k_ti[cnt[col[bel[l]]]]--;         cnt[col[bel[l]]]--;         l++;       }       while (l > node[i].l) {         l--;         cnt[col[bel[l]]]++;         k_ti[cnt[col[bel[l]]]]++;       }       ans[node[i].id] = k_ti[k[node[i].id]];     }   }   void dfs(int u, int fa) {     in[u] = ++tot;     bel[tot] = u;     for (int i = 0; i < son[u].size(); i++) {       int v = son[u][i];       if (v == fa) continue;       dfs(v, u);     }     out[u] = tot;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &col[i]);     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d%d , &u, &v);       son[u].push_back(v);       son[v].push_back(u);     }     tot = 0;     dfs(1, -1);     unit = (int)sqrt(n);     for (int i = 0; i < m; i++) {       int v;       scanf( %d%d , &v, &k[i]);       node[i].id = i;       node[i].l = in[v];       node[i].r = out[v];     }     sort(node, node + m, cmp);     work();     for (int i = 0; i < m; i++) printf( %d n , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n;     cin >> m >> n;     vector<int> sg(n, +1);     for (int i = 1, x; i <= n; ++i) {       cout << i <<   n ;       fflush(stdout);       cin >> x;       if (x < 0) sg[i - 1] = -1;       if (x == 0) return 0;     }     int l = n + 1, r = m, pt = 0, x;     while (l < r) {       int md = (l + r) >> 1;       cout << md <<   n ;       fflush(stdout);       cin >> x;       x *= sg[pt];       pt = (pt + 1) % n;       if (x == 0) return 0;       if (x < 0)         r = md;       else         l = md + 1;     }     cout << l <<   n ;     fflush(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 5, mod = 1e9 + 7;   long long pwr(long long b, long long p) {     long long res = 1;     while (p) {       if (p % 2) res = res * b % mod;       b = b * b % mod;       p /= 2;     }     return res;   }   long long k, n;   string colors[] = { white ,  yellow ,  green ,  blue ,  red ,  orange };   map<string, int> ids;   int cant[10][10];   map<long long, int> node_color;   map<long long, set<long long>> adj;   map<long long, long long> mem[10];   long long dfs(long long p, long long c) {     if (node_color.count(p) && node_color[p] != c) return 0;     if (adj.count(p) == 0) return 1;     if (mem[c].count(p)) return mem[c][p];     long long ret = 1;     for (long long ch : adj[p]) {       long long cur = 0;       for (int i = 1; i <= 6; ++i) {         if (cant[c][i]) continue;         cur += dfs(ch, i);         cur %= mod;       }       ret *= cur;       ret %= mod;     }     return mem[c][p] = ret;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     for (int i = 0; i < 6; ++i) {       ids[colors[i]] = i + 1, cant[i + 1][i + 1] = 1;       if (i % 2 == 0) cant[i + 1][i + 2] = cant[i + 2][i + 1] = 1;     }     cin >> k >> n;     set<long long> used;     while (n--) {       long long node;       string c;       cin >> node >> c;       int id = ids[c];       node_color[node] = id;       used.insert(node);       while (node != 1) {         long long parent = node / 2;         used.insert(parent);         adj[parent].insert(node);         node = parent;       }     }     long long color_ways = 0;     for (int i = 1; i <= 6; ++i) {       color_ways += dfs(1, i);       color_ways %= mod;     }     long long rem = ((1ll) << (1ll * k)) - 1 - used.size();     cout << color_ways * pwr(4, rem) % mod << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char c1, c2;     int t, n1, n2, ans1, ans2;     string s =  ^>v< ;     cin >> c1 >> c2 >> t;     n1 = s.find(c1);     n2 = s.find(c2);     t = t % 4;     ans1 = (n1 + t) % 4;     ans2 = (n1 - t);     if (ans2 < 0) ans2 += 4;     if (ans1 == n2 && ans2 == n2)       puts( undefined );     else if (ans1 == n2)       puts( cw );     else       puts( ccw );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void upd(long long& x) { x = -x - 1; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<long long> a(n);     for (int j = 0; j < n; j++) {       cin >> a[j];       if (a[j] >= 0) upd(a[j]);     }     if (n & 1) {       int jd = 0;       for (int j = 0; j < n; j++) {         if (a[jd] > a[j]) jd = j;       }       upd(a[jd]);     }     for (int j = 0; j < n; j++) cout << a[j] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   const double pi = acos(-1.0);   const int N = 100010;   int n;   long long x, y, a[N];   void solve() {     for (int i = 0; i < (int)(n); ++i) a[i] = 1;     a[0] = y - n + 1;     for (int i = 0; i < (int)(n); ++i) x -= ((a[i]) * (a[i]));     if (y < n || x > 0)       puts( -1 );     else {       for (int i = 0; i < (int)(n); ++i)         printf(              %I64d                n ,             a[i]);     }   }   int main() {     while (         ~scanf( %d                  %I64d                  %I64d ,                &n, &x, &y)) {       solve();     }     return 0;   }