#include <bits/stdc++.h>   using namespace std;   const int inft = 1000000009;   const int mod = 1000000007;   const int MAXN = 100006;   int f[MAXN];   const int N = MAXN, P = MAXN;   vector<int> G[N];   pair<int, int> E[MAXN], Q[MAXN];   int C[MAXN];   namespace LCAO {   vector<pair<int, int> > pyt[N];   int LCA[P];   int kolor[N], REP[N], przodek[N];   int find(int first) {     return REP[first] < 0 ? first : REP[first] = find(REP[first]);   }   void DfsTarjan(int first, int par) {     kolor[first] = 1;     REP[first] = -1;     przodek[first] = first;     for (typeof((G[first]).begin()) it = (G[first]).begin();          it != (G[first]).end(); ++it)       if (*it != par) {         DfsTarjan(*it, first);         int a = find(first), b = find(*it);         if (REP[a] < REP[b]) swap(a, b);         REP[b] += REP[a];         REP[a] = b;         przodek[b] = first;       }     for (typeof((pyt[first]).begin()) it = (pyt[first]).begin();          it != (pyt[first]).end(); ++it)       if (kolor[it->first] == 2) {         int lca = przodek[find(it->first)];         LCA[it->second] = lca;       }     kolor[first] = 2;   }   void dodaj_krawedz(int a, int b) {     G[a].push_back(b);     G[b].push_back(a);   }   int nr = 0;   void dodaj_pytanie(int a, int b) {     if (a == b)       LCA[nr] = a;     else {       pyt[a].push_back(pair<int, int>(b, nr));       pyt[b].push_back(pair<int, int>(a, nr));     }     nr++;   }   void czysc(int n = N) {     for (int i = 0; i < (n); ++i) G[i].clear(), pyt[i].clear(), kolor[i] = 0;     nr = 0;   }   }  // namespace LCAO   pair<int, pair<int, int> > rev(pair<int, pair<int, int> > a) {     return pair<int, pair<int, int> >(         a.first, pair<int, int>(a.second.second, a.second.first));   }   pair<int, pair<int, int> > merge(pair<int, pair<int, int> > t1,                                    pair<int, pair<int, int> > t2) {     ;     if (t1.first == -inft) {       if (t2.first == -inft) {         ;         return pair<int, pair<int, int> >(             -inft, pair<int, int>(t1.second.first + t2.second.first,                                   t1.second.first + t2.second.first));       } else {         ;         return pair<int, pair<int, int> >(             t2.first,             pair<int, int>(t1.second.first + t2.second.first, t2.second.second));       }     } else if (t2.first == -inft) {       ;       return pair<int, pair<int, int> >(           t1.first,           pair<int, int>(t1.second.first, t1.second.second + t2.second.second));     };     return pair<int, pair<int, int> >(         t1.first + t2.first + f[t1.second.second + t2.second.first],         pair<int, int>(t1.second.first, t2.second.second));   }   int eval(pair<int, pair<int, int> > t1) {     ;     if (t1.first == -inft) return f[t1.second.first];     return f[t1.second.first] + f[t1.second.second] + t1.first;   }   struct drzewo {     int T;     vector<pair<int, pair<int, int> > > drz;     void init(int n) {       T = 1;       while (T < n) T *= 2;       drz.resize(2 * T, pair<int, pair<int, int> >(0, pair<int, int>(0, 0)));     }     void update(int a, int b) {       assert(a == b);       a += T;       drz[a] = pair<int, pair<int, int> >(-inft, pair<int, int>(1, 1));       a /= 2;       while (a) {         drz[a] = merge(drz[2 * a], drz[2 * a + 1]);         a /= 2;       }     }     pair<int, pair<int, int> > get(int a, int b) {       pair<int, pair<int, int> > ret1 =           pair<int, pair<int, int> >(-inft, pair<int, int>(0, 0));       pair<int, pair<int, int> > ret2 =           pair<int, pair<int, int> >(-inft, pair<int, int>(0, 0));       a += T;       b += T;       while (a <= b) {         if (a % 2 == 1) {           ret1 = merge(ret1, drz[a]);           a++;         }         if (b % 2 == 0) {           ret2 = merge(drz[b], ret2);           b--;         }         a /= 2;         b /= 2;       }       return merge(ret1, ret2);     }   };   namespace HLD {   drzewo CS[N];   int nrc[N];   int ind[N];   int hop[N];   int siz[N];   int sciezek;   pair<int, pair<int, int> > get(int a, int anc) {     ;     pair<int, pair<int, int> > ret(-inft, pair<int, int>(0, 0));     while (nrc[a] != nrc[anc]) {       ret = merge(ret, rev(CS[nrc[a]].get(0, ind[a])));       a = hop[nrc[a]];     }     ret = merge(ret, rev(CS[nrc[a]].get(ind[anc] + 1, ind[a])));     ;     return ret;   }   void update(int a, int anc) {     ;     while (nrc[a] != nrc[anc]) {       CS[nrc[a]].update(0, ind[a]);       a = hop[nrc[a]];     }     CS[nrc[a]].update(ind[anc], ind[a]);   }   int rozm(int u, int pr) {     siz[u] = 1;     for (typeof((G[u]).begin()) it = (G[u]).begin(); it != (G[u]).end(); ++it)       if (*it != pr) siz[u] += rozm(*it, u);     return siz[u];   }   void ciezka(int u, int pr, int csc, int index) {     nrc[u] = csc;     ind[u] = index;     int dz = -1;     for (typeof((G[u]).begin()) it = (G[u]).begin(); it != (G[u]).end(); ++it)       if (*it != pr && (dz == -1 || siz[*it] > siz[dz])) dz = *it;     for (typeof((G[u]).begin()) it = (G[u]).begin(); it != (G[u]).end(); ++it)       if (*it == dz)         ciezka(*it, u, csc, index + 1);       else if (*it != pr) {         hop[sciezek++] = u;         ciezka(*it, u, sciezek - 1, 0);       }     if (dz == -1) {       CS[csc].init(index + 1);     }   }   void init(int root) {     rozm(root, -1);     sciezek = 1;     hop[0] = -1;     ciezka(root, -1, 0, 0);   }   }  // namespace HLD   void solve() {     int n, q;     scanf( %d%d , &n, &q);     f[0] = 0;     for (int i = 0; i < (n - 1); ++i) {       scanf( %d , &f[i + 1]);     }     vector<pair<int, int> > EV;     for (int i = 0; i < (n - 1); ++i) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       a--;       b--;       LCAO::dodaj_krawedz(a, b);       E[i] = pair<int, int>(a, b);       EV.push_back(pair<int, int>(c + 1, -(i + 1)));     }     for (int i = 0; i < (q); ++i) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       a--;       b--;       LCAO::dodaj_pytanie(a, b);       Q[i] = pair<int, int>(a, b);       EV.push_back(pair<int, int>(c, i));     }     vector<int> ANS(q);     LCAO::DfsTarjan(0, -1);     HLD::init(0);     for (int i = 0; i < (n - 1); ++i)       if (HLD::siz[E[i].first] > HLD::siz[E[i].second])         swap(E[i].first, E[i].second);     sort((EV).begin(), (EV).end());     reverse((EV).begin(), (EV).end());     for (typeof((EV).begin()) it = (EV).begin(); it != (EV).end(); ++it) {       if (it->second >= 0) {         ;         int u = LCAO::LCA[it->second], u1 = Q[it->second].first,             u2 = Q[it->second].second;         pair<int, pair<int, int> > t1 = HLD::get(u1, u), t2 = HLD::get(u2, u);         t1 = merge(t1, rev(t2));         ANS[it->second] = eval(t1);       } else {         int u = -it->second - 1;         ;         HLD::update(E[u].first, E[u].first);       }     }     for (typeof((ANS).begin()) it = (ANS).begin(); it != (ANS).end(); ++it)       printf( %d n , *it);   }   int main() {     int te = 1;     for (int ti = 0; ti < (te); ++ti) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     cin >> n >> m;     double lift[n], land[n];     for (int i = 0; i < (n); i++) cin >> lift[i] >> land[i];     double ans = 0;     for (int i = n - 1; i >= 0; i--) {       ans = (ans + m / land[(i + 1) % n]) / (1 - 1 / land[(i + 1) % n]);       if (ans < 0 || ans > 1e9) return !(cout << -1);       ans = (ans + m / lift[i]) / (1 - 1 / lift[i]);       if (ans < 0 || ans > 1e9) return !(cout << -1);     }     cout << fixed << setprecision(7) << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100100;   long long int a[N], l[N];   int main() {     int n;     long long int ans(0);     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %lld , &a[i]), a[i]++;     long long int o(a[n] + 1);     for (int i = n; i >= 1; --i) l[i] = o = max(--o, a[i]);     for (int i = 1; i <= n; ++i) l[i] = max(l[i], l[i - 1]);     for (int i = 1; i <= n; ++i) ans += (l[i] - a[i]);     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int add(int a, int b, int m = 1000000007) {     a += b;     if (a >= m) a -= m;     return a;   }   inline int mul(int a, int b, int m = 1000000007) {     return (int)(((long long)a * (long long)b) % m);   }   inline int norm(int x, int m = 1000000007) {     if (x >= m) x %= m;     if (x < 0) x += m;     return x;   }   inline int neg(int x, int m = 1000000007) {     x = -x;     return norm(x);   }   int c[501];   int dp[501][501];   int f(int i, int j) {     if (i == j) return 1;     if (i == j - 1) return 2 - (int)(c[i] == c[j]);     int &ans = dp[i][j];     if (ans != -1) return ans;     ans = 1000000007;     for (int k = i; k <= j - 1; ++k) {       ans = min(ans, f(i, k) + f(k + 1, j));     }     if (c[i] == c[j]) ans = min(ans, f(i + 1, j - 1));     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; ++i) cin >> c[i];     memset(dp, -1, sizeof(dp));     cout << f(1, n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double PI = acosl(-1.0);   const double EPS = 1e-12;   void combination(long long com[][1005]) {     com[0][0] = 1;     int sz = 1000;     for (int i = 1; i <= sz; i++) {       com[i][0] = 1;       for (int j = 1; j <= i; j++) {         com[i][j] = com[i - 1][j] + com[i - 1][j - 1];         com[i][j] = com[i][j] % 1000000007;       }     }   }   int find_par(int cn) {}   int gcd(int u, int v) {     if (v == 0) return u;     return gcd(v, u % v);   }   void insert_ind(int cs, int ci, int s, int e) {     if (s == e) {       return;     }     int mid = (s + e) / 2;     if (ci <= mid)       insert_ind(2 * cs, ci, s, mid);     else       insert_ind(2 * cs + 1, ci, mid + 1, e);   }   void update_ind(int cs, int ci, int s, int e, int val) {     if (s == e) {       return;     }     int mid = (s + e) / 2;     if (ci <= mid)       update_ind(2 * cs, ci, s, mid, val);     else       update_ind(2 * cs + 1, ci, mid + 1, e, val);   }   void update_seg(int cs, int ds, int de, int s, int e, int val) {     if (ds == s && de == e) {       return;     }     int mid = (s + e) / 2;     if (ds <= mid) update_seg(2 * cs, ds, min(mid, de), s, mid, val);     if (de > mid) update_seg(2 * cs + 1, max(mid + 1, ds), de, mid + 1, e, val);   }   void pattern_match(char pat[], const int len, int pi[]) {     pi[1] = 0;     for (int i = 2; i <= len; i++) {       int st = i - 1;       while (st >= 0 && pat[pi[st] + 1] != pat[i]) st = pi[st];       if (st == 0)         pi[i] = 0;       else         pi[i] = pi[st] + 1;     }   }   void pattern_match(char pat[], int pi[], char tar[], const int len1, int gi[]) {     if (pat[0] == tar[0]) gi[0] = 1;     for (int i = 1; i < len1; i++) {       int st = gi[i - 1];       while (pat[st] != tar[i]) {         if (st == 0) {           st = -1;           break;         }         st = pi[st - 1];       }       if (st == -1)         gi[i] = 0;       else         gi[i] = st + 1;     }   }   struct myArray {     int mat[10][10];   };   myArray matrix_mul(myArray mat1, myArray mat2, const int sz) {     int tmp[sz][sz];     memset((tmp), 0, sizeof((tmp)));     for (int r = 0; r < sz; r++)       for (int c = 0; c < sz; c++)         for (int cr = 0; cr < sz; cr++)           tmp[r][c] += mat1.mat[r][cr] * mat2.mat[c][cr];     myArray res;     for (int r = 0; r < sz; r++)       for (int c = 0; c < sz; c++) res.mat[r][c] = tmp[r][c];     return res;   }   myArray unit_matrix(const int sz) {     myArray ma;     memset((ma.mat), 0, sizeof((ma.mat)));     for (int i = 0; i < sz; i++) ma.mat[i][i] = 1;     return ma;   }   myArray matrix_expo(int p, myArray mat, const int sz) {     if (p == 0) {       return unit_matrix(sz);     }     if (p & 1) return matrix_mul(mat, matrix_expo(p - 1, mat, sz), sz);     myArray tmp = matrix_expo(p >> 1, mat, sz);     return matrix_mul(tmp, tmp, sz);   }   int X[] = {0, 0, 1, -1};   int Y[] = {1, -1, 0, 0};   string s;   unsigned long long int l, r;   int main() {     cin >> s;     int ln = s.length();     unsigned long long int pos = 0;     for (int i = 0; i < ln; i++)       if (s[i] ==  ^ ) pos = i;     for (int i = 0; i < ln; i++) {       if (i < pos) {         if (s[i] !=  = ) l = l + (s[i] -  0 ) * (pos - i);       } else {         if (s[i] !=  = ) r = r + (s[i] -  0 ) * (i - pos);       }     }     if (l > r)       cout <<  left  << endl;     else if (r > l)       cout <<  right  << endl;     else       cout <<  balance  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, i, rs, j;   vector<long long> ball;   vector<long long>::iterator pos;   int main() {     scanf( %lld , &n);     for (i = 0; i < n; i++) scanf( %lld , &j), ball.push_back(j);     sort(ball.begin(), ball.end());     rs = 0;     i = 0;     if (n % 2 == 0) {       j = ball[0] + ball[1];       pos = lower_bound(ball.begin() + 2, ball.end(), j);       ball.insert(pos, j);       rs += j;       i = 2;     }     for (; i < n - 1; i += 3) {       j = ball[i] + ball[i + 1] + ball[i + 2];       pos = lower_bound(ball.begin() + i + 3, ball.end(), j);       ball.insert(pos, j);       rs += j;       n++;     }     printf( %lld , rs);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n;   int main() {     char c;     scanf( %I64d%1c , &n, &c);     c -=  a ;     long long ans = 0;     n -= 1;     if (n % 4 <= 1) {       ans += ((n / 4) * 2 + n % 4) * 6 + n;     } else {       ans += ((n / 4) * 2 + (n % 4 - 2)) * 6 + n - 2;     }     if (c <= 2) {       ans += 4 + c;     } else {       ans += 6 - c;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:10240000 )   using namespace std;   const int MAXN = 100010;   int a[MAXN], cnt[MAXN];   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     memset(cnt, 0, sizeof(cnt));     int sta = 1, num = 0;     while (num < k) {       if (cnt[a[sta]] == 0) {         num++;       }       cnt[a[sta]]++;       sta++;       if (sta > n) {         break;       }     }     if (num < k) {       printf( -1 -1 n );     } else {       int old = 1, l = 1, r = sta - 1;       int m = r - l + 1;       for (int i = sta; i <= n; i++) {         int j = old + 1;         cnt[a[old]]--;         if (j < i) {           while (a[j] == a[old]) {             cnt[a[old]]--;             j++;             if (j == i) {               break;             }           }         }         if (cnt[a[old]] == 0) {           num--;         }         old = j;         j = i;         while (num < k) {           if (cnt[a[j]] == 0) {             num++;           }           cnt[a[j]]++;           j++;           if (j > n) {             break;           }         }         if (num < k) {           break;         }         i = j - 1;         int tmp = i - old + 1;         if (tmp < m) {           m = tmp;           l = old;           r = i;         }       }       memset(cnt, 0, sizeof(cnt));       for (int i = l; i <= r; i++) {         cnt[a[i]]++;       }       while (cnt[a[l]] > 1) {         cnt[a[l]]--;         l++;       }       printf( %d %d n , l, r);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MAXN = 3005;   const int MOD = 1000000007;   const double eps = 1e-8;   const double PI = acos(-1.0);   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long qpow(long long a, long long n, long long p = MOD) {     long long r = 1 % p;     for (a %= p; n; a = a * a % p, n >>= 1)       if (n & 1) r = r * a % p;     return r;   }   long long inv(long long x, long long p = MOD) {     return x <= 1 ? 1 : inv(p % x, p) * (p - p / x) % p;   }   struct node {     int val, id;   } a[3005];   int da[3005];   bool cmpa(node a, node b) { return a.val > b.val; }   bool cmpb(node a, node b) { return a.id < b.id; }   struct RMQ {     int f[MAXN][21], pos[MAXN][21];     int n;     void init(int a[], int sz) {       n = sz;       for (int i = 0; i < n; i++) {         f[i][0] = a[i];         pos[i][0] = i;       }       for (int j = 1; (1 << j) <= n; j++) {         for (int i = 0; i + (1 << j) - 1 < n; i++) {           if (f[i][j - 1] < f[i + (1 << (j - 1))][j - 1]) {             f[i][j] = f[i + (1 << (j - 1))][j - 1];             pos[i][j] = pos[i + (1 << (j - 1))][j - 1];           } else {             f[i][j] = f[i][j - 1];             pos[i][j] = pos[i][j - 1];           }         }       }     }     int query(int l, int r) {       int k = 0;       while ((1 << (k + 1)) <= r - l + 1) {         k++;       }       return f[l][k] >= f[r - (1 << k) + 1][k] ? pos[l][k]                                                : pos[r - (1 << k) + 1][k];     }   } myRMQ;   int ans[4];   inline void update(int i, int j, int k) { ans[1] = i, ans[2] = j, ans[3] = k; }   inline bool check(int i, int j, int k) {     if (da[i] > da[ans[1]]) {       return 1;     } else if (da[i] == da[ans[1]]) {       if (da[j] > da[ans[2]]) {         return 1;       } else if (da[j] == da[ans[2]] && da[k] > da[ans[3]]) {         return 1;       }     }     return 0;   }   int main(int argc, char* argv[]) {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i].val);       a[i].id = i;     }     sort(a + 1, a + n + 1, cmpa);     for (int i = 1; i <= n; i++) {       da[i] = a[i].val - a[i + 1].val;     }     myRMQ.init(da, n + 1);     for (int i = 1; i < n; i++) {       for (int j = i + 1; j < n; j++) {         int cnt[4];         cnt[1] = i, cnt[2] = j - i;         if (cnt[1] > 2 * cnt[2] || cnt[2] > 2 * cnt[1] ||             min(cnt[1], cnt[2]) > 2 * (n - j)) {           continue;         }         int l = j + (max(cnt[1], cnt[2]) + 1) / 2,             r = j + 2 * min(cnt[1], cnt[2]);         l = max(l, j + 1), r = min(n, r);         if (l > r) {           continue;         }         int k = myRMQ.query(l, r);         if (ans[1] == 0 || check(i, j, k)) {           update(i, j, k);         }       }     }     for (int i = 1; i <= ans[1]; i++) {       a[i].val = 1;     }     for (int i = ans[1] + 1; i <= ans[2]; i++) {       a[i].val = 2;     }     for (int i = ans[2] + 1; i <= ans[3]; i++) {       a[i].val = 3;     }     for (int i = ans[3] + 1; i <= n; i++) {       a[i].val = -1;     }     sort(a + 1, a + n + 1, cmpb);     for (int i = 1; i <= n; i++) {       printf( %d  , a[i].val);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     string s;     cin >> s;     for (long long i = 1; i <= n; i++)       if (!(n % i)) reverse(s.begin(), (s.begin() + i));     cout << s <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010, inf = 1e9;   int n, ty, l, r, x;   bitset<maxn> v[26], ans;   char s[maxn], s2[maxn], c;   inline void read(int &k) {     int f = 1;     k = 0;     char c = getchar();     while (c <  0  || c >  9 ) c ==  -  && (f = -1), c = getchar();     while (c <=  9  && c >=  0 ) k = k * 10 + c -  0 , c = getchar();     k *= f;   }   int main() {     scanf( %s , s + 1);     int len = strlen(s + 1);     for (int i = 1; i <= len; i++) v[s[i] -  a ][i] = 1;     read(n);     for (int i = 1; i <= n; i++) {       read(ty);       if (ty == 1) {         read(x);         scanf( %c , &c);         v[s[x] -  a ][x] = 0;         v[(s[x] = c) -  a ][x] = 1;       } else {         read(l);         read(r);         scanf( %s , s2);         int m = strlen(s2);         if (r - l + 1 < m) {           puts( 0 );           continue;         }         ans.set();         for (int j = 0; j < m; j++) ans &= (v[s2[j] -  a ] >> j);         printf( %d n ,                (int)(ans >> (l)).count() - (int)(ans >> (r - m + 2)).count());       }     }   }


#include <bits/stdc++.h>   using namespace std;   int arr[500005], brr[500005];   vector<int> vv[500005], ans;   int Now[500005];   int total[500005];   int tree[500005 * 4];   void update(int node, int b, int e, int i, int v) {     if (i < b || i > e) return;     if (b == e && b == i) {       tree[node] = v;       return;     }     int left = 2 * node, right = left + 1, mid = (b + e) / 2;     update(left, b, mid, i, v);     update(right, mid + 1, e, i, v);     tree[node] = tree[left] + tree[right];   }   int query(int node, int b, int e, int v) {     if (b == e) return b;     int left = 2 * node, right = left + 1, mid = (b + e) / 2;     int ret;     if (tree[left] >= v)       ret = query(left, b, mid, v);     else       ret = query(right, mid + 1, e, v - tree[left]);     return ret;   }   int main() {     int n, k, m, s;     scanf( %d %d %d %d , &n, &k, &m, &s);     for (int i = 1; i <= n; i++) {       scanf( %d , &arr[i]);       vv[arr[i]].push_back(i);     }     for (int i = 1; i <= s; i++) {       int x;       scanf( %d , &x);       brr[x]++;     }     if (k < s) {       cout <<  -1 ;       return 0;     }     for (int i = 1; i <= n; i++) {       if (total[arr[i]] == brr[arr[i]]) continue;       Now[arr[i]] = i;       update(1, 1, n, i, 1);       total[arr[i]]++;     }     if (tree[1] < s) {       cout <<  -1 ;       return 0;     }     bool flag = 0;     int id = 0, id2 = 0;     for (int i = 1; i <= n; i++) {       int pp = query(1, 1, n, s);       int z = 0;       z = i / k;       if (i % k == 0) z--;       int ppp = max(pp, i + k - 1);       z++;       z += ((n - ppp) / k);       if (z >= m) {         flag = 1;         id = i;         id2 = pp;         break;       }       update(1, 1, n, i, 0);       int idd = upper_bound(vv[arr[i]].begin(), vv[arr[i]].end(), Now[arr[i]]) -                 vv[arr[i]].begin();       if (idd == vv[arr[i]].size() && brr[arr[i]]) break;       if (brr[arr[i]]) {         update(1, 1, n, vv[arr[i]][idd], 1);         Now[arr[i]] = vv[arr[i]][idd];       }     }     if (flag == 0) {       printf( -1 n );     } else {       for (int i = 1; i <= 500000; i++) total[i] = 0;       for (int i = 1; i < id; i++) {         if ((id - i) % k)           ans.push_back(i);         else           break;       }       if (id2 - id + 1 > k) {         int tt = id2 - id + 1;         for (int i = id; i <= id2 && tt > k; i++) {           if (total[arr[i]] >= brr[arr[i]]) {             tt--;             ans.push_back(i);           } else             total[arr[i]]++;         }       }       printf( %d n , ans.size());       for (int i = 0; i < ans.size(); i++) printf( %d  , ans[i]);     }   }


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


#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   const long long INF = 0x3f3f3f3f3f3f3f3f;   const long long llinf = (1LL << 62);   const int inf = (1 << 30);   const long long nmax = 3e5 + 50;   const int mod = 1e9 + 7;   const int lim = 1e6;   using namespace std;   int n, m, a[nmax], b[nmax], st[4 * lim + 50], i, t, x, lzy[4 * lim + 50], q;   void push(int nod, int l, int r) {     if (l > r) return;     if (!lzy[nod]) return;     st[nod] += lzy[nod];     if (l != r) {       lzy[nod * 2] += lzy[nod];       lzy[nod * 2 + 1] += lzy[nod];     }     lzy[nod] = 0;   }   void upd(int nod, int l, int r, int tl, int tr, int v) {     push(nod, l, r);     if (tl <= l && r <= tr) {       lzy[nod] += v;       push(nod, l, r);       return;     }     int mid = (l + r) / 2;     if (tl <= mid) upd(nod * 2, l, mid, tl, tr, v);     if (mid < tr) upd(nod * 2 + 1, mid + 1, r, tl, tr, v);     push(nod * 2, l, mid);     push(nod * 2 + 1, mid + 1, r);     st[nod] = max(st[nod * 2], st[nod * 2 + 1]);   }   int qry(int nod, int l, int r) {     push(nod, l, r);     if (l == r) return l;     int mid = (l + r) / 2;     push(2 * nod, l, mid);     push(2 * nod + 1, mid + 1, r);     if (st[2 * nod + 1] > 0) return qry(2 * nod + 1, mid + 1, r);     return qry(2 * nod, l, mid);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cerr.tie(0);     cout.tie(0);     cin >> n >> m;     for (i = 1; i <= n; i++) {       cin >> a[i];       upd(1, 1, lim, 1, a[i], 1);     }     for (i = 1; i <= m; i++) {       cin >> b[i];       upd(1, 1, lim, 1, b[i], -1);     }     cin >> q;     while (q--) {       cin >> t >> i >> x;       if (t == 1) {         upd(1, 1, lim, 1, a[i], -1);         a[i] = x;         upd(1, 1, lim, 1, a[i], 1);       } else {         upd(1, 1, lim, 1, b[i], 1);         b[i] = x;         upd(1, 1, lim, 1, b[i], -1);       }       if (st[1] <= 0)         cout << -1 <<   n ;       else         cout << qry(1, 1, lim) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s, s1, s2;   bool fn() {     int i, j, k, flag = 0;     int len = s.size();     int len1 = s1.size();     int len2 = s2.size();     for (i = 0; i < len; i++) {       for (j = i, k = 0; k < len1; j++, k++) {         if (s[j] != s1[k] || j >= len) break;       }       if (k == len1) {         flag++;         break;       }     }     for (i = j; i < len; i++) {       for (j = i, k = 0; k < len2; j++, k++) {         if (s[j] != s2[k] || i >= len) break;       }       if (k == len2) {         flag++;         break;       }     }     if (flag == 2)       return true;     else       return false;   }   int main() {     cin >> s >> s1 >> s2;     bool Forward = false;     if (fn() == true) Forward = true;     reverse(s.begin(), s.end());     bool Backward = false;     if (fn() == true) Backward = true;     if (Forward && Backward)       cout <<  both  << endl;     else if (Forward)       cout <<  forward  << endl;     else if (Backward)       cout <<  backward  << endl;     else       cout <<  fantasy  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005, MOD = 1e9 + 7;   long long fact[N], inv[N];   long long qpow(long long a, int b) {     long long ans = 1;     do {       if (b & 1) ans = ans * a % MOD;       a = a * a % MOD;     } while (b /= 2);     return ans;   }   int main() {     int n;     cin >> n;     fact[0] = 1;     for (int i = 1; i <= n * 2; i++) fact[i] = fact[i - 1] * i % MOD;     inv[n * 2] = qpow(fact[n * 2], MOD - 2);     for (int i = n * 2 - 1; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % MOD;     long long ans = 0;     for (int i = 0; i < n; i++)       ans += fact[n - 1 + i] * inv[n - 1] % MOD * inv[i] % MOD;     cout << (ans * 2 - n) % MOD << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   // #define int  long long int   #define mod 1000000007   #define pb push_back   #define mp make_pair   #define bs binary_search   #define lb lower_bound   #define ub upper_bound   #define gcd __gcd   #define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);   #define min3(a,b,c) min(a,min(b,c))   #define max3(a,b,c) max(a,max(b,c))   #define all(i) i.begin(),i.end()   #define rep(i,a,b) for(int i=a;i<b;i++)   #define set_bit __builtin_popcount //gives number of set_bits   #define ff first   #define ss second   #define cases(t) int t;cin>>t; rep(casn,1,t+1)   #define el cout<<  n ;   #define deci(n) int n; scanf( %lld ,&n);   #define decs(n) string n; cin>>n;   #define sz(v) v.size()   #define repit(m) for(auto it=m.begin();it!=m.end();it++)   #define debx cout<< -> ;   #define deb(x) cout<<#x<<   <<x<<endl;   #define cYES cout<< YES n ;   #define cNO cout<< NO n ;   #define ins insert   #define imax 800000000000000000   #define imin -1000000000000000000   //  cerr <<   nTime :   << (double)clock() / (double)CLOCKS_PER_SEC <<  s n ;   //  IIITA   //SUNEET KUMAR -->  ਸੁਨੀਤ   // scanning numbers extremely fast/////////      void fs(int &number)   {       bool negative = false;       register int c;       number = 0;       c = getchar();       if (c== - )       {           negative = true;           c = getchar();       }       for (; (c>47 && c<58); c=getchar())           number = number *10 + c - 48;       if (negative)           number *= -1;   }   // ========================================   int power(int a,int x)   {       a%=mod;       int res=1;       while(x>0)       {           if(x&1)           res=res*a%mod;           a=a*a%mod;           x>>=1;       }       return res;   }      int max(int a,int b)   {       if(a>b)       {           return a;       }       else       {           return b;       }   }      int min(int a,int b)   {       if(a>b)       {           return b;       }       else       {           return a;       }   }   int madd(int a,int b)   {       int ans;       ans=(a%mod+b%mod)%mod;       return ans;   }   int mmult(int a,int b)   {       int ans=1;       ans=((a%mod)*(b%mod))%mod;       return ans%mod;   }   int modinverse(int a)   {       return power(a,mod-2);   }   // int fact[500004];   // void Factorial()   // {   //     fact[0]=1;   //     for(int i=1;i<=500001;i++)   //     {   //         fact[i]=mmult(fact[i-1],i);   //     }   // }   // int ncr(int n,int r)   // {   //     if(r>n)   //     {   //         return 0;   //     }   //     if(n==r||r==0)   //     {   //         return 1;   //     }   //     if(n==0)   //     {   //         return 0;   //     }   //     mmult(fact[n],modinverse(mmult(fact[r],fact[n-r])));   // }   void solve()   {       int n;cin>>n;       int a[n+10][n+10];       string s;       for(int i=1;i<=n;i++)       {              string s;cin>>s;           for(int j=0;j<s.length();j++)           {               a[i][j+1]=s[j]- 0 ;           }       }       // map<int,int>m;       int m[12],mxr[12],mxc[12],mir[12],mic[12];       memset(m,0,sizeof(m));       memset(mxr,0,sizeof(mxr));memset(mxc,0,sizeof(mxc));       // memset(mic,0,sizeof(mic));       // memset(mir,0,sizeof(mir));       for(int i=0;i<=10;i++)       {           mic[i]=100000;           mir[i]=1000000;       }       for(int i=1;i<=n;i++)       {           for(int j=1;j<=n;j++)           {               int x=a[i][j];               mir[x]=min(mir[x],i);               mic[x]=min(mic[x],j);               mxr[x]=max(mxr[x],i);               mxc[x]=max(mxc[x],j);           }       }       for(int i=1;i<=n;i++)       {           for(int j=1;j<=n;j++)           {               int x=a[i][j];               m[x]=max(m[x],max(mxr[x]-i,i-mir[x])*(max(n-j,j-1)));               m[x]=max(m[x],max(mxc[x]-j,j-mic[x])*(max(n-i,i-1)));           }       }       // debx;       for(int i=0;i<10;i++)       {           cout<<m[i]<<   ;       }       el   }   signed main()   {       // fastio;       cases(t)       {           // cout<< Case # <<i<< :  ;           solve();           // cerr <<   nTime :   << (double)clock() / (double)CLOCKS_PER_SEC <<  s n ;       }   }


#include <bits/stdc++.h>   using namespace std;   int n, d[100005], g[100005];   bool vis[100005];   char str[100005];   void get() {     bool sign = 1;     int cur = 1;     while (cur >= 1 && cur <= n) {       if (vis[cur]) {         sign = 0;         break;       }       vis[cur] = 1;       cur += g[cur] * d[cur];     }     if (!sign)       cout <<  INFINITE  << endl;     else       cout <<  FINITE  << endl;   }   int main() {     cin >> n >> str + 1;     for (int i = 1; i <= n; i++) cin >> d[i];     for (int i = 1; i <= n; i++) g[i] = str[i] ==  >  ? 1 : -1;     get();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   vector<char> s;   int main() {     cin >> n >> k;     if (k > n) {       cout << -1;       cin >> n;       return 0;     }     if (k == 1 && n > 1) {       cout << -1;       cin >> n;       return 0;     }     for (int i = 0; i < n; i++) {       if (i % 2 == 0) {         s.push_back( a );       } else {         s.push_back( b );       }     }     int x = 98 + k - 2;     for (int i = n - 1; i >= n - k + 2; i--) {       s[i] = (char)x;       x--;     }     for (int i = 0; i < n; i++) {       cout << s[i];     }     cin >> n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x7fffffff;   inline int reint() {     int d;     scanf( %d , &d);     return d;   }   inline long relong() {     long l;     scanf( %ld , &l);     return l;   }   inline char rechar() {     scanf(   );     return getchar();   }   inline double redouble() {     double d;     scanf( %lf , &d);     return d;   }   inline string restring() {     string s;     cin >> s;     return s;   }   int mask(int a) {     char str[10];     sprintf(str,  %d , a);     char ans[10];     int j = 0;     for (int i = (0); i < (strlen(str)); i++) {       if (str[i] ==  4  || str[i] ==  7 ) {         ans[j++] = str[i];       }     }     int res = 0;     for (int i = (0); i < (j); i++) {       res += ans[i] -  0 ;       if (i != j - 1) {         res *= 10;       }     }     return res;   }   int c, b;   int main(void) {     cin >> c >> b;     c++;     while (mask(c) != b) {       c++;     }     cout << c << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define int long long   void solve()   {       int n;       cin >> n;       int a[n];              for(int i = 0; i < n; i++) cin >> a[i];       cout<<(n/2)*6<<endl;       for(int i = 1; i <= n; i+=2){           int j = i + 1;           cout<<1<<   <<i<<   <<j<<endl;           cout<<2<<   <<i<<   <<j<<endl;           cout<<2<<   <<i<<   <<j<<endl;           cout<<1<<   <<i<<   <<j<<endl;           cout<<2<<   <<i<<   <<j<<endl;           cout<<2<<   <<i<<   <<j<<endl;       }   }      int32_t main()   {       ios_base::sync_with_stdio(false);       cin.tie(0);       cout.tie(0);       int t;       cin>> t;       while(t--)solve();       return 0;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   const int N = 2.5e5;   vector<int> adj[N];   int dep[N], par[N];   bool leaf[N];   bool dfs(int u, int p = -1, int d = 1) {     if (dep[u] > 0) return false;     dep[u] = d;     par[u] = p;     leaf[u] = true;     for (int v : adj[u]) {       if (dfs(v, u, d + 1)) leaf[u] = false;     }     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       u--, v--;       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(0);     int r = 0;     for (int u = 0; u < n; u++) {       if (dep[u] > dep[r]) r = u;     }     dfs(r);     const int plen = ((n + k - 1) / k);     int leaves = 0;     for (int u = 0; u < n; u++) {       if (dep[u] >= plen) {         cout <<  PATH n  << dep[u] <<   n ;         while (u != -1) {           cout << (u + 1) <<    ;           u = par[u];         }         cout <<   n ;         return 0;       }       if (leaf[u]) leaves++;     }     assert(leaves >= k);     cout <<  CYCLES n ;     int values[3];     vector<int> cy;     cy.reserve(N);     for (int u = 0; u < n && k > 0; u++) {       if (!leaf[u]) continue;       int top = -1;       int id = 0;       for (int v : adj[u]) {         if (v == par[u]) continue;         if ((dep[u] - dep[v]) >= 3 && (dep[u] - dep[v] + 1) % 3 != 0) {           top = v;           break;         }         values[id++] = v;         if (id == 2) break;       }       if (top >= 0) {         for (int v = u; v != top; v = par[v]) {           cy.push_back(v);         }         cy.push_back(top);       } else {         cy.push_back(u);         if (dep[values[0]] < dep[values[1]]) swap(values[0], values[1]);         for (int v = values[0]; v != values[1]; v = par[v]) {           cy.push_back(v);         }         cy.push_back(values[1]);       }       cout << cy.size() <<   n ;       for (int u : cy) cout << (u + 1) <<    ;       cout <<   n ;       cy.clear();       k--;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[1000010], a[1000010], b[1000010];   char perm[300];   char used[300];   char savedPerm[300];   char savedUsed[300];   int k;   bool fit(char from, char to) {     if (perm[from] != 0) {       if (perm[from] != to) return false;     } else {       if (used[to] != 0) return false;       used[to] = 1;       perm[from] = to;     }     return true;   }   void fillUnused() {     char i, j =  a ;     for (i =  a ; i <  a  + k; i++) {       if (perm[i] == 0) {         while (used[j] == 1) j++;         perm[i] = j;         j++;       }     }   }   void solve() {     scanf( %d%s%s%s , &k, s, a, b);     memset(perm, 0, sizeof(perm));     memset(used, 0, sizeof(used));     int n = strlen(s);     int state = 0;     int conflict = -1;     for (int i = 0; i < n; i++) {       switch (state) {         case 0:           if (a[i] == b[i]) {             if (!fit(s[i], a[i])) {               printf( NO n );               return;             }           } else {             for (char ch = a[i] + 1; ch < b[i]; ch++) {               if (fit(s[i], ch)) {                 state = -1;                 break;               }             }             if (state != -1) {               memcpy(savedPerm, perm, sizeof(perm));               memcpy(savedUsed, used, sizeof(used));               if (conflict == -1) {                 if (fit(s[i], a[i])) {                   conflict = i;                   state = 1;                 } else if (fit(s[i], b[i]))                   state = 2;                 else {                   printf( NO n );                   return;                 }               } else if (fit(s[i], b[i]))                 state = 2;               else {                 printf( NO n );                 return;               }             }           }           break;         case 1:           for (char ch = a[i] + 1; ch <  a  + k; ch++) {             if (fit(s[i], ch)) {               state = -1;               break;             }           }           if (state != -1) {             if (!fit(s[i], a[i])) {               state = 0;               i = conflict - 1;               memcpy(perm, savedPerm, sizeof(perm));               memcpy(used, savedUsed, sizeof(used));               break;             }           }           break;         case 2:           for (char ch =  a ; ch < b[i]; ch++) {             if (fit(s[i], ch)) {               state = -1;               break;             }           }           if (state != -1) {             if (!fit(s[i], b[i])) {               printf( NO n );               return;             }           }           break;       }       if (state == -1) break;     }     fillUnused();     printf( YES n );     for (int i =  a ; i <  a  + k; i++) printf( %c , perm[i]);     printf(  n );   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int B = 20;   const int N = 1e5 + 7;   int n, m, a[N];   struct ND {     int l0, r0;     ND() {}     ND(int l0, int r0) : l0(l0), r0(r0) {}     void init(int p, int v) {       l0 = v == 0 ? p : n + 1;       r0 = v == 0 ? p : 0;     }     void merge(const ND &a, const ND &b) {       l0 = min(a.l0, b.l0);       r0 = max(a.r0, b.r0);     }   };   struct Tree {     static const int N = ::N << 2;     ND nd[N];     void chg(int o, int l, int r, int qx, int qv) {       if (l == r) {         nd[o].init(qx, qv);         return;       }       int mid = l + r >> 1;       if (qx <= mid)         chg(o << 1, l, mid, qx, qv);       else         chg(o << 1 | 1, mid + 1, r, qx, qv);       nd[o].merge(nd[o << 1], nd[o << 1 | 1]);     }     ND qry(int o, int l, int r, int ql, int qr) {       if (ql <= l && qr >= r) return nd[o];       int mid = l + r >> 1;       ND qryl(n + 1, 0);       if (ql <= mid) qryl = qry(o << 1, l, mid, ql, qr);       ND qryr(n + 1, 0);       if (qr > mid) qryr = qry(o << 1 | 1, mid + 1, r, ql, qr);       ND ret;       ret.merge(qryl, qryr);       return ret;     }   } tree[B];   long long dc(int len) { return 1ll * (len + 1) * len / 2; }   long long getv(int p, int vv) {     long long ret = 0;     for (int b = (0); b < (B); ++b) {       int v = vv >> b & 1;       int lenl = p - 1 - (p > 1 ? tree[b].qry(1, 1, n, 1, p - 1).r0 : 0);       int lenr = (p < n ? tree[b].qry(1, 1, n, p + 1, n).l0 : n + 1) - p - 1;       long long tmp = v == 0 ? dc(lenl) + dc(lenr) : dc(lenl + lenr + 1);       ret += tmp * (1 << b);     }     return ret;   }   void solve() {     for (int i = (1); i < (n + 1); ++i) scanf( %d , &a[i]);     for (int i = (1); i < (n + 1); ++i)       for (int b = (0); b < (B); ++b) tree[b].chg(1, 1, n, i, a[i] >> b & 1);     long long ans = 0;     for (int b = (0); b < (B); ++b) {       int tmp = 0;       for (int i = (1); i < (n + 2); ++i)         if (a[i] >> b & 1)           tmp++;         else {           ans += dc(tmp) * (1 << b);           tmp = 0;         }     }     while (m--) {       int p, v;       scanf( %d%d , &p, &v);       ans += -getv(p, a[p]) + getv(p, v);       a[p] = v;       for (int b = (0); b < (B); ++b) tree[b].chg(1, 1, n, p, a[p] >> b & 1);       printf( %lld n , ans);     }   }   int main() {     while (~scanf( %d%d , &n, &m)) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[200010];   int main() {     int n;     long long sum = 0, MAX = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %I64d , a + i);       sum += a[i];       MAX = max(a[i], MAX);     }     long long ans;     if (sum % (n - 1) == 0)       ans = sum / (n - 1);     else       ans = sum / (n - 1) + 1;     ans = max(MAX, ans);     printf( %I64d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   long long n, d, b;   int nl[100100], nr[100100];   int find(int *next, int x) {     if (next[x] == x) return x;     return next[x] = find(next, next[x]);   }   long long bit[100100];   inline int lowbit(int x) { return x & -x; }   void add(int x, long long y) {     while (x <= n) {       bit[x] += y;       x += lowbit(x);     }   }   long long sum(int x) {     long long res = 0;     while (x > 0) {       res += bit[x];       x -= lowbit(x);     }     return res;   }   long long get(int x) { return sum(x) - sum(x - 1); }   int make(int x, int t) {     int nx = 0;     int l = max(1ll, x - t * d), r = min(n, x + t * d);     if (sum(r) - sum(l - 1) < b) return 1;     if (x == t) {       for (int i = l; i <= r; i = find(nl, i)) {         int gi = get(i);         nx += gi;         if (nx < b) {           add(i, -get(i));           nl[i] = i + 1;           nr[i] = i - 1;         } else {           add(i, nx - gi - b);           break;         }       }     } else {       for (int i = r; i >= l; i = find(nr, i)) {         int gi = get(i);         nx += gi;         if (nx < b) {           add(i, -get(i));           nl[i] = i + 1;           nr[i] = i - 1;         } else {           add(i, nx - gi - b);           break;         }       }     }     return 0;   }   int main() {     scanf( %d%d%d , &n, &d, &b);     memset(nl, 0, sizeof(nl));     memset(nr, 0, sizeof(nr));     for (int i = 1; i <= n; i++) {       int a;       scanf( %d , &a);       add(i, a);       if (a != 0) {         nl[i] = i;         nr[i] = i;       } else {         nl[i] = i + 1;         nr[i] = i - 1;       }     }     int x1 = 0, x2 = 0, l = 1, r = n;     while (l <= r) {       if (l == r)         x1 += make(l, l);       else if (x1 > x2) {         x1 += make(l, l);         x2 += make(r, l);       } else {         x2 += make(r, l);         x1 += make(l, l);       }       l++;       r--;     }     printf( %d n , max(x1, x2));     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int cmp(char a, char b) { return a > b; }   int main() {     char s[300050];     char str[300050];     char ans[300050];     scanf( %s%s , s, str);     int len = strlen(s);     sort(s, s + len);     sort(str, str + len, cmp);     if (len == 1) {       printf( %s n , s);       return 0;     }     int l, r, L, R;     l = L = 0;     r = (len + 1) / 2 - 1;     if (len & 1) {       R = len / 2 - 1;     } else       R = r;     int sum = 0;     int i = 0;     int j = len - 1;     while (i <= j) {       if ((sum & 1) == 0) {         if (s[l] < str[L]) {           ans[i++] = s[l++];         } else {           ans[j--] = s[r--];         }         sum++;       } else {         if (s[l] >= str[L]) {           ans[j--] = str[R--];         } else {           ans[i++] = str[L++];         }         sum++;       }     }     ans[len] =   0 ;     printf( %s n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int l[50000];   int p[50000];   pair<pair<double, int>, int> prod[50000];   int main() {     std::ios_base::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> l[i] >> p[i];       if (p[i] == 100)         prod[i].first.first = -1000000000;       else         prod[i].first.first = -l[i] * p[i] * 1.0 / (100 - p[i]);       prod[i].first.second = p[i];       prod[i].second = i;     }     sort(prod, prod + n);     double F = l[prod[0].second] * p[prod[0].second] / 100.0;     double E = l[prod[0].second];     for (int i = 1; i < n; i++) {       E = E + l[prod[i].second] + (1 - p[prod[i].second] / 100.0) * F;       F += p[prod[i].second] / 100.0 * l[prod[i].second];     }     cout << setprecision(25) << E << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool sip;   char A[100005], B[100005];   int C[35], D[35], tam1, tam2, res = 0, puede = 0, quedan;   int main() {     scanf( %s%s , A, B);     for (tam1 = 0; A[tam1] !=   0 ; tam1++)       ;     for (tam2 = 0; B[tam2] !=   0 ; tam2++)       ;     if (tam2 > tam1) {       printf( 0 n );       return 0;     }     for (int i = 0; i < tam2; i++) {       ++D[B[i] -  a ];     }     for (int i = 0; i < tam2; i++) {       if (A[i] !=  ? ) {         ++C[A[i] -  a ];       } else {         ++puede;       }     }     for (int i = 0; i <= tam1 - tam2; i++) {       quedan = puede;       sip = true;       for (int e = 0; e < 26; e++) {         if (C[e] > D[e] or D[e] - C[e] > quedan) {           sip = false;           break;         } else {           quedan -= (D[e] - C[e]);         }       }       if (sip) {         ++res;       }       if (i == tam1 - tam2) {         continue;       }       if (A[i] ==  ? ) {         --puede;       } else {         --C[A[i] -  a ];       }       if (A[i + tam2] ==  ? ) {         ++puede;       } else {         ++C[A[i + tam2] -  a ];       }     }     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int a, b;       cin >> a >> b;       if (b < a) swap(a, b);       if (b - a > 10) {         cout << fixed << (int)ceil((double)(b - a) / 10) <<   n ;       } else if (a != b)         cout <<  1 n ;       else         cout <<  0 n ;     }   }


#include <bits/stdc++.h>   using namespace std;   void sprint(string s) {     for (int i = 0; i < (int)s.size(); ++i) printf( %c , s[i]);     printf(  n );   }   long long f(long long n, long long r) {     long long ans = 1;     for (long long i = 0; i < r; ++i) {       ans = (ans * (n - i)) / (i + 1);     }     return ans;   }   int main() {     long long n;     cin >> n;     long long ans = f(n + 4, 5) * f(n + 2, 3);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 2;   const int INF = 1e9 + 1;   const double EPS = 1e-9;   int n, m;   int a[MAXN];   int r[MAXN], t[MAXN];   int b[MAXN];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cin >> n >> m;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     int it = 0;     for (int i = 0; i < m; ++i) {       int ct, crt;       cin >> ct >> crt;       while (it > 0 && crt >= r[it - 1]) --it;       t[it] = ct;       r[it++] = crt;     }     r[it] = 0;     int bl = 0, br = r[0];     for (int i = 0; i < br; ++i) {       b[i] = a[i];     }     sort(b, b + br);     for (int i = 1; i < it + 1; ++i) {       for (int j = r[i - 1]; j > r[i]; --j) {         if (t[i - 1] == 1) {           a[j - 1] = b[--br];         } else           a[j - 1] = b[bl++];       }     }     for (int i = 0; i < n; ++i) {       cout << a[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   int a[1005];   int main() {     int x, i, j;     while (scanf( %d%*c , &x) != EOF) a[x] = 1;     bool flag = false;     for (i = j = 1; i < 1001; i = ++j)       if (a[i]) {         for (j = i; a[j]; ++j)           ;         --j;         if (!flag)           flag = true;         else           printf( , );         if (i == j)           printf( %d , i);         else           printf( %d-%d , i, j);       }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   const long long logN = 20;   const long long M = 1000000007;   const long long INF = 1e12;   const long long N = 505;   const long long K = 250505;   long long dp[K];   void solve() {     long long n, k;     cin >> n >> k;     long long A[n], B[n];     for (long long i = 0; i < n; i++) cin >> A[i] >> B[i];     long long r = 0, g = 0;     for (long long i = 0; i < n; i++) r += A[i], g += B[i];     dp[0] = 1;     for (long long i = 0; i < n; i++) {       long long r0 = A[i];       long long g0 = B[i];       if ((r0 + g0) < k) continue;       long long downr = max(k - g0, 0LL);       long long upr = min(r0, k);       long long mx = K;       for (long long i = K - 1; i >= 0; i--) {         if (dp[i] != 0) {           for (long long j = i + downr + 1; j < i + upr + 1; j++) {             if (j >= mx) break;             dp[j] = dp[i] + 1;           }           dp[i + downr] = dp[i] + 1;           mx = i + downr;         }       }     }     long long ans = 0;     for (long long i = 0; i < K; i++) {       if (dp[i] != 0) {         long long cnt = dp[i] - 1;         long long r0 = i;         long long g0 = cnt * k - r0;         cnt += (r - r0) / k + (g - g0) / k;         ans = max(ans, cnt);       }     }     cout << ans <<   n ;     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long no;     no = 1;     while (no--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, vector<long long> > mp;   long long a[200005];   long long t[200005];   set<long long> s;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     for (long long i = 0; i < n; i++) cin >> a[i], s.insert(a[i]);     for (long long i = 0; i < n; i++) {       cin >> t[i];       mp[a[i]].push_back(t[i]);     }     for (auto i : s) sort(mp[i].begin(), mp[i].end());     long long ans = 0;     multiset<long long> temp;     long long sum = 0;     while (s.size()) {       long long v = *s.begin();       s.erase(s.begin());       for (auto i : mp[v]) temp.insert(i), sum += i;       auto p = s.lower_bound(v);       long long nex = 1e18;       if (p != s.end()) nex = *p;       long long d = nex - v;       long long siz = min(d, (long long)temp.size());       long long c = 0;       while (siz--) {         auto po = prev(temp.end());         ans += (*po) * c;         c++;         sum -= (*po);         temp.erase(po);       }       ans += sum * c;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 1e6 + 7;   int N, a[maxN], f[(1LL << 22) + 7];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> N;     memset(f, -1, sizeof f);     for (int i = 1; i <= N; i++) {       cin >> a[i];       f[a[i]] = a[i];     }     for (int i = 0; i <= 22; i++)       for (int mask = 0; mask < (1LL << 22); mask++)         if (mask & (1LL << i)) f[mask] = max(f[mask], f[mask ^ (1LL << i)]);     for (int i = 1; i <= N; i++) {       cout << f[(1LL << 22) - 1 - a[i]] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long rd() {     char c;     while (c = getchar(), c <  0  || c >  9 )       ;     long long X = c - 48;     while (c = getchar(), c >=  0  && c <=  9 ) X = X * 10 + c - 48;     return X;   }   template <class T>   inline void print(T x) {     if (x < 0) {       putchar( - );       return print(-x);     }     if (x < 10) {       putchar( 0  + x);       return;     }     print(x / 10);     putchar(x % 10 +  0 );   }   string s;   void solve(int n, vector<int> &a) {     if (n == 1) {       s =  B ;       return;     }     vector<int> idx(n + 1);     s = string(n,  B );     for (__typeof(0) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));          i += 1 - (((0) > (n)) << 1))       idx[a[i]] = i;     for (__typeof(n + 1) i = (n + 1) - ((n + 1) > (1));          i != (1) - ((n + 1) > (1)); i += 1 - (((n + 1) > (1)) << 1)) {       for (int j = idx[i] - i; j >= 0; j -= i) {         if (a[j] > i and s[j] ==  B ) {           s[idx[i]] =  A ;           break;         }       }       for (int j = idx[i] + i; j < n; j += i) {         if (a[j] > i and s[j] ==  B ) {           s[idx[i]] =  A ;           break;         }       }     }   }   int32_t main() {     int n;     cin >> n;     vector<int> a(n);     for (int &i : a) cin >> i;     solve(n, a);     cout << s <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   const long long INF = (long long)1e14 + 5;   long long N, cur = 1, last = 0, ans[MAXN];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> N;     for (int i = 1; i <= N; i += 2) {       long long x;       cin >> x;       while (cur * cur <= INF) {         long long l = last + 1, r = cur - 1, found = -1;         while (l <= r) {           long long m = (l + r) >> 1;           if (cur * cur - m * m == x) {             found = m;             break;           } else if (cur * cur - m * m > x)             l = m + 1;           else             r = m - 1;         }         if (found != -1) {           ans[i] = found * found - last * last;           ans[i + 1] = x;           last = cur;           cur++;           break;         }         cur++;       }       if (cur * cur > INF) {         cout <<  No n ;         return 0;       }     }     cout <<  Yes n ;     for (int i = 1; i <= N; i++) {       cout << ans[i] << (i + 1 <= N ?     :   n );     }   }


#include <bits/stdc++.h>   using namespace std;   typedef int nod[100010];   typedef int edg[200010];   int n, m;   int e = 1;   nod h;   edg link, v, u;   nod vis;   nod fz;   int ju;   void creat(int x, int y) {     link[++e] = h[x];     h[x] = e;     v[e] = y;     link[++e] = h[y];     h[y] = e;     v[e] = x;   }   int dfs(int x) {     if (vis[x])       return 0;     else       vis[x] = 1;     for (int i = h[x]; i; i = link[i])       if (!u[i]) {         u[i] = u[i ^ 1] = 1;         if ((ju = dfs(v[i])))           printf( %d %d %d n , x, v[i], ju);         else if (!fz[x])           fz[x] = v[i];         else           printf( %d %d %d n , fz[x], x, v[i]), fz[x] = 0;       }     return fz[x];   }   int main() {     scanf( %d%d , &n, &m);     if (m & 1) {       printf( No solution n );       return 0;     }     for (int i = 1, x, y; i <= m; ++i) scanf( %d%d , &x, &y), creat(x, y);     dfs(1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int K = 5;   void NO() {     puts( unfair );     exit(0);   }   int main() {     int n, b, q;     scanf( %d%d%d , &n, &b, &q);     vector<pair<int, int>> w;     w.push_back(make_pair(b, n));     while (q--) {       int a, b;       scanf( %d%d , &a, &b);       w.push_back(make_pair(a, b));     }     sort(w.begin(), w.end());     for (int mask = 0; mask < (1 << K); ++mask) {       int at_least = 0, at_most = 0;       int prev_upto = 0, prev_quan = 0;       for (pair<int, int> query : w) {         int now_upto = query.first, now_quan = query.second;         int places_matching = 0;         int places_other = 0;         for (int i = prev_upto + 1; i <= now_upto; ++i) {           if (mask & (1 << (i % K)))             ++places_matching;           else             ++places_other;         }         if (now_quan < prev_quan) NO();         int quan = now_quan - prev_quan;         int places_total = now_upto - prev_upto;         assert(places_total == places_matching + places_other);         if (quan > places_total) NO();         at_least += max(0, quan - places_other);         at_most += min(quan, places_matching);         prev_upto = now_upto;         prev_quan = now_quan;       }       int must_be = n / K * __builtin_popcount(mask);       if (!(at_least <= must_be && must_be <= at_most)) NO();     }     puts( fair );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char W[1000 + 10];   int N[1000 + 10];   int main() {     int n, m;     scanf( %d%d%s , &n, &m, W);     for (int i = 0; i < n; ++i) (N[i] = W[i] -  a );     bool fixed = false;     for (int i = n - 1; i >= 0; --i) {       while (true) {         N[i]++;         if (N[i] == m) break;         if (i - 1 >= 0 && N[i] == N[i - 1]) continue;         if (i - 2 >= 0 && N[i] == N[i - 2]) continue;         fixed = true;         for (int j = i + 1; j < n; ++j) {           N[j] = -1;           while (true) {             N[j]++;             if (j - 1 >= 0 && N[j] == N[j - 1]) continue;             if (j - 2 >= 0 && N[j] == N[j - 2]) continue;             break;           }         }         break;       }       if (fixed) break;     }     if (!fixed)       printf( NO n );     else {       for (int i = 0; i < n; ++i) printf( %c ,  a  + N[i]);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimization( unroll-loops )   using namespace std;   const long long large = 1e11, remi2 = 998244353;   const long long remi = 1e9 + 7, inf = LLONG_MAX;   const long double Pi = acos(-1);   long long PowI(long long a, long long b, long long m) {     long long ans = 1 % m;     while (b > 0) {       if (b % 2) ans = (((ans % m) * (a % m)) % m);       a = (((a % m) * (a % m)) % m);       b = (long long)(b / ((long long)2));     }     return ans;   }   void Foxtrot() {     long long n, k;     cin >> n >> k;     vector<long long> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     sort(v.begin(), v.end());     long long sum = 0;     for (int i = 0; i < (n - (2 * k)); i++) {       sum += v[i];     }     for (long long i = n - 2 * k; i < (n - k); i++) {       sum += (v[i] / v[i + k]);     }     cout << sum <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long T = 1;     cin >> T;     for (int i = 1; i < T + 1; i++) {       Foxtrot();     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(3)   using namespace std;   bool Finish_read;   template <class T>   inline void read(T &x) {     Finish_read = 0;     x = 0;     int f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       if (ch == EOF) return;       ch = getchar();     }     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     x *= f;     Finish_read = 1;   }   template <class T>   inline void print(T x) {     if (x / 10 != 0) print(x / 10);     putchar(x % 10 +  0 );   }   template <class T>   inline void writeln(T x) {     if (x < 0) putchar( - );     x = abs(x);     print(x);     putchar(  n );   }   template <class T>   inline void write(T x) {     if (x < 0) putchar( - );     x = abs(x);     print(x);   }   const int maxn = 100005, maxlog = 20;   int mx[maxlog][maxn], n, c, v[100005];   long long f[maxn], sum[maxn];   inline int get(int l, int r) {     int k = log2(r - l + 1);     return min(mx[k][l], mx[k][r - (1 << k) + 1]);   }   int main() {     read(n);     read(c);     for (int i = 1; i <= n; i++) {       read(v[i]);       mx[0][i] = v[i];       sum[i] = sum[i - 1] + v[i];     }     for (int j = 1; (1 << j) <= n; j++)       for (int i = 1; i + (1 << j) - 1 <= n; i++)         mx[j][i] = min(mx[j - 1][i], mx[j - 1][i + (1 << (j - 1))]);     for (int i = 1; i < c; i++) f[i] = f[i - 1] + v[i];     for (int i = c; i <= n; i++)       f[i] = min(f[i - 1] + v[i],                  f[i - c] + sum[i] - sum[i - c] - get(i - c + 1, i));     printf( %lld n , f[n]);   }


#include <bits/stdc++.h>   using namespace std;   long long n, p;   int get(int x) {     int sum = 0;     while (x) {       if (x & 1) sum++;       x >>= 1;     }     return sum;   }   int main() {     scanf( %lld%lld , &n, &p);     int sum = 0;     while (n - sum * p > 0) {       int s = get(n - sum * p);       if (sum >= s && sum <= n - sum * p) {         printf( %d n , sum);         return 0;       }       sum++;     }     puts( -1 );   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n;     cin >> n;     vector<long long> a(n), b(n), idxs(n + 1), ans(n, n);     multiset<long long> s1, s2;     for (long long i = 0; i < n; i++) {       cin >> a[i];       idxs[a[i]] = i;     }     for (long long i = 0; i < n; i++) {       cin >> b[i];       if (idxs[b[i]] < i) {         s1.insert(i - idxs[b[i]]);       } else {         s2.insert(idxs[b[i]] - i);       }     }     for (long long i = 0; i < n; i++) {       while (s1.size() && *s1.begin() == i) {         s2.insert(-i);         s1.erase(s1.find(i));       }       if (s1.size()) {         ans[i] = min(ans[i], *s1.begin() - i);       }       if (s2.size()) {         ans[i] = min(ans[i], i + *s2.begin());       }       assert(s2.count(idxs[b[i]] - i));       s2.erase(s2.find(idxs[b[i]] - i));       s1.insert(n - idxs[b[i]] + i);     }     for (long long i = 0; i < n; i++) cout << ans[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long dp[300005];   int main() {     long long n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++)       for (int j = i + i; j <= n; j += i) dp[j]++;     long long sum = 0, m = 0;     for (int i = 1; i <= n; i++) {       sum += dp[i];       if (sum >= k) {         m = i;         break;       }     }     vector<pair<long long, long long> > vec;     for (int i = m / 2 + 1; i <= m; i++) vec.emplace_back(dp[i], i);     sort(vec.rbegin(), vec.rend());     set<int> st;     for (int i = 1; i <= m; i++) st.insert(i);     k = sum - k;     for (int i = 0; i < vec.size() and k > 0; i++) {       if (vec[i].first <= k) {         k -= vec[i].first;         st.erase(vec[i].second);       }     }     if (k != 0)       cout <<  No  << endl;     else {       cout <<  Yes  << endl;       cout << st.size() << endl;       for (int val : st) cout << val <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   priority_queue<pair<long long, pair<long long, long long>>> pq;   long long divide(long long x, long long y) {     if (x < y) return 1e16;     long long t = x / y, rm = x % y;     t += rm / y;     rm %= y;     return rm * (t + 1) * (t + 1) + (y - rm) * t * t;   }   void solve() {     cin >> n >> k;     long long ans = 0;     k -= n;     while (n--) {       long long x;       cin >> x;       ans += x * x;       pq.push({x * x - divide(x, 2), {x, 2}});     }     while (k--) {       auto x = pq.top();       pq.pop();       ans -= x.first;       pq.push({divide(x.second.first, x.second.second) -                    divide(x.second.first, x.second.second + 1),                {x.second.first, x.second.second + 1}});     }     cout << ans <<   n ;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     solve();   }


#include<bits/stdc++.h>   using namespace std;   #define ll long long   #define ull unsigned long long   #define inf INT_MAX   #define minf INT_MIN   #define infl LLONG_MAX   #define minfl LLONG_MIN   #define mod 1000000007         /*----------------------Debugger-----------------------------------*/      #ifndef ONLINE_JUDGE   #define show(x) cerr<< #x << :  ; _print(x); cerr <<endl;   #else   #define show(x)   #endif      template<class T> void _print(T x){ cerr<<x<<endl; }   template<class T> void _print(vector<T> x){cerr<< [ ; for(auto i: x) cerr<<i<< ,  ; cerr<< ] n ;}   template<class T> void _print(set<T> x){ cerr<< {  ; for(auto i: x) cerr<<i<< ,  ; cerr<< } n ;}         /*-------------------------------------------------------------------------------------------------*/      ll exp(int a,int b,int p){ll res=1; a=a%p;     while(b){ if(b & 1) res=(res*a)%p; a=((ll)a*a)%p; b=b>>1; } return res; }      ll mmiPrime(int a, int p){ return exp(a,p-2,p); }      pair<int,int> extendedGCD(int a, int b){ if(b==0){ pair<int,int> ans; ans.first=1; ans.second=0; return ans; }    pair<int,int> temp=extendedGCD(b,a%b); pair<int,int> ans;    ans.first=temp.second; ans.second=temp.first - (a/b)*temp.second; return ans; }      int mmi(int a, int m){ pair<int,int> tmp=extendedGCD(a,m); return tmp.first; }      int ncr(int n,int r, int p, int fact[]){ return ((fact[n] * mmiPrime(fact[r],p) % p) * mmiPrime(fact[n-r],p))%p; }      /*-------------------------------------------------------------------------------------------------*/         void solve(){    int n,k;    cin>>n>>k;    int a[k];    int t[k];       for(int i=0;i<k;i++)     cin>>a[i];          for(int i=0;i<k;i++)     cin>>t[i];       vector<ll> ac(n+1,INT_MAX);       for(int i=0;i<k;i++){     ac[a[i]]=t[i];    }          ll L[n+1],R[n+1];       ll p=INT_MAX;    for(int i=1;i<=n;i++){     p=min(p+1,ac[i]);     L[i]=p;    }       p=INT_MAX;    for(int i=n;i>0;i--){     p=min(p+1,ac[i]);     R[i]=p;    }       for(int i=1;i<=n;i++)     cout<<min(L[i],R[i])<<   ;    cout<<  n ;      }      int main(){    ios_base::sync_with_stdio(false); cin.tie(NULL);       #ifndef ONLINE_JUDGE     freopen( input.txt , r ,stdin);     freopen( output.txt , w ,stdout);     freopen( error.txt , w ,stderr);    #endif       clock_t time = clock();       int t;    cin>>t;    while(t--){     solve();    }       time = clock() - time;        #ifndef ONLINE_JUDGE     cout<< time:  <<time*1000/CLOCKS_PER_SEC<<  miliseconds n ;    #endif       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long int power(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   int main() {     int n;     cin >> n;     long long int n1 = 0, n0 = 0, x1 = 0, x0 = 0;     string a, b;     cin >> a >> b;     for (int i = 0; i < n; i++) {       if (a[i] ==  0  && b[i] ==  1 ) n0++;       if (a[i] ==  1  && b[i] ==  1 ) n1++;       if (a[i] ==  1  && b[i] ==  0 ) x1++;       if (a[i] ==  0  && b[i] ==  0 ) x0++;     }     long long int ans = 0;     for (int i = 0; i < n; i++) {       if (b[i] ==  0 ) {         if (a[i] ==  1 )           ans += n0;         else           ans += n1;       }     }     ans += x1 * x0;     cout << ans;     return 0;   }


/***************************************************************    File name: CF1517F.cpp    Author: ljfcnyali    Create time: 2021年04月27日 星期二 10时19分32秒   ***************************************************************/   #include<bits/stdc++.h>      using namespace std;      #define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i )    #define mem(a) memset ( (a), 0, sizeof ( a ) )    #define str(a) strlen ( a )    #define pii pair<int, int>   #define int long long   typedef long long LL;      const int maxn = 1010;   const int Mod = 998244353;      int n, Begin[maxn], Next[maxn], To[maxn], e, ans[maxn], ret, f[maxn][maxn][2], g[maxn][2], Max[maxn];      inline void add(int u, int v) { To[++ e] = v; Next[e] = Begin[u]; Begin[u] = e; }       inline int power(int a, int b) { int r = 1; while ( b ) { if ( b & 1 ) r = r * a % Mod; a = a * a % Mod; b >>= 1; } return r; }      inline void DFS(int u, int fa, int x)   {    f[u][0][0] = f[u][x][1] = 1; Max[u] = 0;    for ( int i = Begin[u]; i; i = Next[i] )     {     int v = To[i]; if ( v == fa ) continue ;      DFS(v, u, x);      REP(k, 0, Max[u]) REP(j, 0, Max[v])     {      g[max(k, j + 1)][0] = (g[max(k, j + 1)][0] + f[u][k][0] * f[v][j][0]) % Mod;      if ( j < x - k ) g[x - k][1] = (g[x - k][1] + f[u][x - k][1] * f[v][j][0]) % Mod;      else g[j + 1][0] = (g[j + 1][0] + f[u][x - k][1] * f[v][j][0]) % Mod;     }        REP(k, 0, Max[u]) REP(j, x - Max[v], x)     {      if ( k <= j - 1 ) g[j - 1][1] = (g[j - 1][1] + f[u][k][0] * f[v][j][1]) % Mod;      else g[k][0] = (g[k][0] + f[u][k][0] * f[v][j][1]) % Mod;      g[max(x - k, j - 1)][1] = (g[max(x - k, j - 1)][1] + f[u][x - k][1] * f[v][j][1]) % Mod;     }     REP(k, 0, x) REP(o, 0, 1) { f[u][k][o] = g[k][o]; g[k][o] = 0; }      Max[u] = max(Max[u], Max[v] + 1);    }   }      inline int Solve(int x)   {    mem(f); DFS(1, 0, x);    int sum = 0; REP(i, 0, x) sum = (sum + f[1][i][1]) % Mod; return sum;   }      signed main()   {   #ifndef ONLINE_JUDGE       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);   #endif    scanf( %lld , &n);    REP(i, 1, n - 1) { int u, v; scanf( %lld%lld , &u, &v); add(u, v); add(v, u); }    REP(i, 0, n) ans[i] = Solve(i);      REP(i, 1, n) ret = (ret + (ans[i] - ans[i - 1]) * (i - 1)) % Mod;    ret = (ret + n - 1) * power((Mod + 1) / 2, n) % Mod;    printf( %lld n , (ret + Mod) % Mod);       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     cout.tie();     int n, q, i;     cin >> n;     int arr[106] = {};     for (i = 1; i <= n; i++) {       cin >> arr[i];     }     cin >> q;     int x, y;     while (q--) {       cin >> x >> y;       arr[x - 1] += (y - 1);       arr[x + 1] += (arr[x] - y);       arr[x] = 0;     }     for (i = 1; i <= n; i++) {       cout << arr[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct bus {     double t, v;     double cost, time;   };   bus bus[100000];   int main() {     int n, a, d;     scanf( %d%d%d , &n, &a, &d);     double fastest = 0.0;     double x, y;     for (int i = 0; i < n; i++) {       scanf( %lf%lf , &bus[i].t, &bus[i].v);       x = (d - bus[i].v * bus[i].v / (2.0 * a)) / bus[i].v;       y = bus[i].t + (bus[i].v / a) + x;       if (x < 0) {         y = bus[i].t + sqrt(2.0 * d / (double)a);       }       if (fastest <= y) fastest = y;       printf( %.10f n , fastest);     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100050;   vector<int> E[N];   queue<int> q[2];   int c, in[N], col[N], sol;   int main() {     int n, m, u, v, i;     scanf( %i %i , &n, &m);     for (i = 0; i < n; i++) scanf( %i , &col[i]);     while (m--) {       scanf( %i %i , &u, &v);       E[v].push_back(u);       in[u]++;     }     for (i = 0; i < n; i++)       if (!in[i]) q[col[i]].push(i);     while (!q[0].empty() || !q[1].empty()) {       if (q[c].empty()) {         if (!c) sol++;         c ^= 1;       }       u = q[c].front();       q[c].pop();       for (i = 0; i < E[u].size(); i++) {         v = E[u][i];         in[v]--;         if (!in[v]) q[col[v]].push(v);       }     }     printf( %i n , sol);     return 0;   }


#include <bits/stdc++.h>   const int mod = 1e9 + 7;   using namespace std;   bool sortcol(const vector<int>& v1, const vector<int>& v2) {     return v1[1] < v2[1];   }   void fastio() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   bool compare(const pair<long long int, long long int>& a,                const pair<long long int, long long int>& b) {     if (a.first > b.first) return true;     if (a.first == b.first) return a.second < b.second;     return false;   }   long long int power(long long int x, long long int y) {     long long int res = 1;     x = x % mod;     while (y > 0) {       if (y & 1) res = (res * x) % mod;       y = y >> 1;       x = (x * x) % mod;     }     return res;   }   vector<int> vin(int n) {     vector<int> v;     for (int i = 0; i < n; i++) {       int t;       cin >> t;       v.push_back(t);     }     return v;   }   vector<int> ch;   void solve() {     long long int n, k;     cin >> n >> k;     long long int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     long long int l = a[0] - k, r = a[0] + k;     for (int i = 0; i < n; i++) {       long long int x = a[i] - k;       long long int y = a[i] + k;       l = max(l, x);       r = min(r, y);     }     if (l > r) {       cout << -1 <<   n ;     } else       cout << r <<   n ;   }   int main() {     int tc;     cin >> tc;     while (tc--) solve();   }


#include <bits/stdc++.h>   using namespace std;   long long qpow(long long a, long long b) {     long long ans = 1;     while (b) {       if (b % 2) ans = ans * a;       a = a * a;       b = b / 2;     }     return ans;   }   vector<int> pos;   stack<long long> num;   stack<char> ch;   long long cal(string s) {     while (!num.empty()) num.pop();     while (!ch.empty()) ch.pop();     for (int i = 0; i < s.length(); i++) {       char c = s[i];       if (c >=  0  && c <=  9 )         num.push(c -  0 );       else if (c ==  ( ) {         ch.push(c);       } else if (c ==  ) ) {         while (ch.top() !=  ( ) {           char x = ch.top();           ch.pop();           long long a = num.top();           num.pop();           long long b = num.top();           num.pop();           if (x ==  * )             num.push(a * b);           else             num.push(a + b);         }         ch.pop();       } else {         if (c ==  + ) {           while (!ch.empty() && ch.top() ==  * ) {             char x = ch.top();             ch.pop();             long long a = num.top();             num.pop();             long long b = num.top();             num.pop();             if (x ==  * )               num.push(a * b);             else               num.push(a + b);           }           ch.push(c);         } else           ch.push(c);       }     }     while (!ch.empty()) {       char x = ch.top();       ch.pop();       long long a = num.top();       num.pop();       long long b = num.top();       num.pop();       if (x ==  * )         num.push(a * b);       else         num.push(a + b);     }     return num.top();   }   int main() {     ios::sync_with_stdio(false);     string str;     while (cin >> str) {       int n = str.size();       pos.clear();       pos.push_back(-1);       for (int i = 1; i < n; i += 2) {         if (str[i] ==  * ) {           pos.push_back(i);         }       }       pos.push_back(n);       int len = pos.size();       long long ans = 0;       for (int i = 0; i < len - 1; i++) {         for (int j = i + 1; j < len; j++) {           string s = str;           s.insert(pos[i] + 1, 1,  ( );           s.insert(pos[j] + 1, 1,  ) );           ans = max(ans, cal(s));         }       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e4 + 7;   bitset<N> a[60];   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     int n, m;     cin >> m >> n;     for (int i = 0, t; i < m; i++) {       cin >> t;       for (int j = 0, x; j < t; j++) cin >> x, a[i].set(x);       for (int j = 0; j < i; j++) {         if ((a[i] & (~a[j])) == a[i]) return cout <<  impossible  << endl, 0;       }     }     cout <<  possible n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> build(int n) {     map<int, bool> s;     for (int i = 2; i * i <= n; i++) {       if (s[i] == false) {         for (int j = 2 * i; j <= n; j = j + i) s[j] = true;       }     }     vector<int> t;     for (int i = 2; i <= n; i++) {       if (s[i] == false) t.push_back(i);     }     return t;   }   int main() {     int n;     cin >> n;     vector<int> a = build(n);     int b[n - 1];     int s = 1;     for (int i = 0; i < a.size(); i++) {       for (int j = a[i]; j <= n; j = j + a[i]) b[j - 2] = s;       s++;     }     for (int i = 0; i < n - 1; i++) cout << b[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long sum, i, j;     cin >> sum;     vector<long> length(3);     for (i = 0; i < 3; i++) cin >> length[i];     vector<vector<long> > dp(2, vector<long>(sum + 1, INT_MIN));     dp[3 % 2][0] = 0;     for (i = 2; i >= 0; i--) {       for (j = 0; j <= sum; j++) {         dp[i % 2][j] = dp[(i + 1) % 2][j];         if (j - length[i] >= 0 && dp[i % 2][j - length[i]] != INT_MIN)           dp[i % 2][j] = max(dp[i % 2][j], 1 + dp[i % 2][j - length[i]]);       }     }     cout << dp[0][sum];   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long add(long long x, long long y) {     x += y;     if (x >= mod) x -= mod;     return x;   }   long long mul(long long x, long long y) { return (x * y) % mod; }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     long long x, s;     cin >> s >> x;     long long ret = 0;     if (s == x) ret = -2;     long long ans = 1;     for (int i = 0; i <= 40; i++) {       if (x & (1LL << (i))) {         ans *= 2;         if (s < (1LL << (i))) {           cout << 0 << endl;           exit(0);         };         s -= (1LL << (i));       }     }     for (int i = 0; i <= 40; i++) {       if (!(x & (1LL << (i)))) {         if (s & (1LL << (i + 1))) {           s -= (1LL << (i + 1));         }       }     }     if (s != 0) {       cout << 0 << endl;       exit(0);     };     cout << ans + ret << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   uint64_t rnd_data = 0xDEADBEEFDULL;   inline void my_srand(int seed) { rnd_data = ((uint64_t)seed << 16) | 0x330E; }   inline int my_rand() {     rnd_data = rnd_data * 0x5DEECE66DULL + 0xB;     return (rnd_data >> 17) & 0x7FFFFFFF;   }   template <typename T>   void my_random_shuffle(T b, T e) {     for (int i = (1); i <= (int)((int)(e - b) - 1); i++) {       swap(b[i], b[my_rand() % (i + 1)]);     }   }   template <class _T>   inline _T sqr(const _T &x) {     return x * x;   }   template <typename type_t, typename less_t = std::less<type_t>>   inline bool uin(type_t &a, const type_t &b, const less_t &ls = less_t()) {     return ls(b, a) ? a = b, true : false;   }   template <typename type_t, typename less_t = std::less<type_t>>   inline bool uax(type_t &a, const type_t &b, const less_t &ls = less_t()) {     return ls(a, b) ? a = b, true : false;   }   const long double PI = 3.1415926535897932384626433832795L;   const long double EPS = 1e-9;   const int MAXN = 202400;   const size_t LIM = 300;   int n;   long double p[MAXN];   vector<int> a[MAXN];   vector<int> al[MAXN];   vector<int> ah[MAXN];   long double s[MAXN];   long double sh[MAXN];   bool hv[MAXN];   void precalc() {     for (int i = 0; i < (int)(n); i++) {       s[i] = 0.0;       for (int vn : al[i]) {         s[i] += p[vn];       }     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i < (int)(n); i++) {       double x;       scanf( %lf , &x);       p[i] = x;     }     for (int i = 0; i < (int)(n - 1); i++) {       int x, y;       scanf( %d%d , &x, &y);       a[x].push_back(y);       a[y].push_back(x);     }     for (int i = 0; i < (int)(n); i++) {       hv[i] = a[i].size() > LIM;       sh[i] = 0.0;     }     for (int i = 0; i < (int)(n); i++) {       for (int vn : a[i]) {         if (hv[vn]) {           ah[i].push_back(vn);         } else {           al[i].push_back(vn);         }       }     }     precalc();     for (int i = 0; i < (int)(n); i++) {       if (hv[i]) {         for (auto vn : a[i]) {           sh[i] += 1.0 - p[vn];         }       }     }     int m;     scanf( %d , &m);     long double spall = 0.0;     for (int i = 0; i < (int)(n); i++) {       spall += p[i];     }     long double sumprev = 0.0;     for (int j = 0; j < (int)(n); j++) {       sumprev += a[j].size() * p[j];       sumprev += (1.0 - p[j]) * s[j];       sumprev += p[j] * sh[j];     }     for (int i = 0; i < (int)(m); i++) {       int x;       double y;       scanf( %d%lf , &x, &y);       spall -= p[x];       sumprev -= a[x].size() * p[x] + (1.0 - p[x]) * s[x] + p[x] * sh[x];       if (!hv[x]) {         for (int vn : a[x]) {           sumprev -= (1.0 - p[vn]) * s[vn];           s[vn] -= p[x];         }       }       for (auto vn : ah[x]) {         sumprev -= p[vn] * sh[vn];         sh[vn] -= 1.0 - p[x];       }       p[x] = y;       for (auto vn : ah[x]) {         sh[vn] += 1.0 - p[x];         sumprev += p[vn] * sh[vn];       }       if (!hv[x]) {         for (int vn : a[x]) {           s[vn] += p[x];           sumprev += (1.0 - p[vn]) * s[vn];         }       }       spall += p[x];       sumprev += a[x].size() * p[x] + (1.0 - p[x]) * s[x] + p[x] * sh[x];       long double ans = 2.0 + sumprev;       ans -= spall * 2.0;       ans /= 2.0;       printf( %0.9f n , (double)ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x, ans = 0;   vector<int> a, b;   bool cmp(const int &a, const int &b) { return a > b; }   int main(int argc, char *argv[]) {     scanf( %d%d , &n, &x);     a.resize(n);     b.resize(n);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);     }     for (int i = 0; i < n; ++i) {       scanf( %d , &b[i]);     }     sort(a.begin(), a.end(), cmp);     sort(b.begin(), b.end(), cmp);     for (int i = 0, j = n - 1; i < n && j >= 0; ++i) {       for (; j >= 0 && a[i] + b[j] < x; --j)         ;       if (j >= 0) {         ++ans;       }       --j;     }     printf( 1 %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 30;   int n, m, T;   string s[N], t[N];   int main() {     ios::sync_with_stdio(false), cin.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> s[i];     for (int i = 0; i < m; i++) cin >> t[i];     cin >> T;     while (T--) {       int x;       cin >> x;       x--;       cout << s[x % n] << t[x % m] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   struct Hungary {     vector<int> g[1005];     int from[1005], mx[1005], ans;     bool use[1005];     int n, sume;     int nume[1005];     bool match(int x, int exp) {       for (int i = int(0); i < int(g[x].size()); ++i) {         if (g[x][i] == exp) continue;         if (!use[g[x][i]]) {           use[g[x][i]] = true;           if (from[g[x][i]] == -1 || match(from[g[x][i]], exp)) {             from[g[x][i]] = x;             mx[x] = g[x][i];             return true;           }         }       }       return false;     }     void matching(int exp) {       ans = 0;       memset(from, -1, sizeof(from));       memset(mx, 0, sizeof(mx));       for (int i = int(1); i < int(n + 1); ++i) {         if (i == exp) continue;         memset(use, 0, sizeof(use));         if (match(i, exp)) ans++;       }     }     void init(int nn) {       n = nn;       for (int i = int(1); i < int(n + 1); ++i) g[i].clear();       sume = 0;       memset(nume, 0, sizeof(nume));     }     void AddEdge(int u, int v) {       g[u].push_back(v);       sume++;       nume[u]++;       if (u != v) nume[v]++;     }   } H;   bool mp[1005][1005];   int main() {     int n, m;     while (scanf( %d%d , &n, &m) == 2) {       memset(mp, 0, sizeof(mp));       H.init(n);       for (int i = int(0); i < int(m); ++i) {         int u, v;         scanf( %d%d , &u, &v);         mp[u][v] = true;         H.AddEdge(u, v);       }       int ans = n * n * n;       for (int i = int(1); i < int(n + 1); ++i) {         int pans = 0;         if (!mp[i][i]) pans++;         for (int j = int(1); j < int(n + 1); ++j) {           if (j == i) continue;           if (!mp[i][j]) pans++;           if (!mp[j][i]) pans++;         }         H.matching(i);         pans += (H.sume - H.nume[i] - H.ans);         pans += (n - 1 - H.ans);         ans = min(ans, pans);       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   const int N = 1e6 + 10;   int main() {     int n;     cin >> n;     map<int, int> mc;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       mc[x] = i;     }     pair<int, int> ans = {INF, INF};     for (auto &p : mc) {       pair<int, int> pp = p;       swap(pp.first, pp.second);       ans = min(ans, pp);     }     cout << ans.second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long const INF = 1e18;   long long s[300100], a[300100];   int n, k;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     s[n + 1] = 0;     for (int i = n; i >= 1; i--) s[i] = s[i + 1] + a[i];     s[0] = s[1];     sort(s + 2, s + n + 1);     long long res = 0;     for (int i = n; i >= n - k + 2; i--) res = res + s[i];     res += s[1];     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double tux, pur, foo, bar, baz, quz = 1;   int main() {     cin >> tux;     for (int i = 1; i <= tux; i++) {       cin >> pur;       foo += pur;       bar++;       if (foo * quz > baz * bar) {         baz = foo;         quz = bar;       }     }     printf( %.6lf , baz / quz);     return 0;   }


#include <bits/stdc++.h>   int main(int argc, char **argv) {     long count = 0;     std::cin >> count;     long sum = 0;     long tmp;     long size;     do {       sum += (tmp = count);       size = (count / 2) + 1;       int offset = (count % 2) ? 2 : 1;       int start = (count % 2) ? 3 : 2;       for (long i = start; i < size; i += offset) {         if (!(count % i)) {           tmp = i;           break;         }       }       count /= tmp;     } while (count != 1);     std::cout << sum + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, men = 0, pluss = 0, nol = 0;   long long a, ans = 0;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a;       if (a < 0) {         ans += (-1 - a);         men++;       } else if (a > 0) {         ans += (a - 1);         pluss++;       } else {         nol++;       }     }     if (nol > 0) {       cout << ans + nol << endl;     } else {       if (men % 2 == 0) {         cout << ans << endl;       } else {         cout << ans + 2 << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, c, d, e, f;     cin >> a >> b >> c >> d >> e >> f;     if (d == 0)       cout <<  Hermione  << endl;     else if (c == 0)       cout <<  Ron  << endl;     else if (b == 0)       cout <<  Hermione  << endl;     else if (a == 0)       cout <<  Ron  << endl;     else if (f == 0)       cout <<  Hermione  << endl;     else if (e == 0)       cout <<  Ron  << endl;     else       cout << (b * d * f > a * c * e ?  Ron  :  Hermione ) << endl;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ul = unsigned long long;   using ld = long double;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ll n;     cin >> n;     vector<ll> a(n);     vector<pair<ll, ll>> b;     for (int i = 0; i < (n); i++) {       cin >> a[i];       a[i] -= i;       while (1) {         if (b.size() > 1 &&             (b[b.size() - 2].first - b.back().first) * b.back().second +                     b[b.size() - 2].first <=                 a[i]) {           b[b.size() - 2].second += b.back().second;           a[i] -= (b[b.size() - 2].first - b.back().first) * b.back().second;           b.pop_back();         } else if (!b.empty() && b.back().first <= a[i]) {           ll d = (a[i] - b.back().first) / (b.back().second + 1);           b.back().first += d;           a[i] -= d * b.back().second;           ll q = a[i] - b.back().first;           if (q > 0) {             pair<ll, ll> pp{b.back().first, b.back().second - q + 1};             b.back().first++;             b.back().second = q;             if (b.size() > 1 && b[b.size() - 2].first == b.back().first) {               b[b.size() - 2].second += b.back().second;               b.pop_back();             }             b.push_back(pp);           } else             b.back().second++;           break;         } else {           b.push_back({a[i], 1});           break;         }       }     }     ll cx = 0;     for (auto &pp : b)       for (int i = 0; i < (pp.second); i++) cout << cx++ + pp.first <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e3 + 5;   string s, p;   int nxt[MAX];   vector<int> cost;   int memo[MAX][MAX];   int roll(int idx, int val) {     if (idx >= (int)cost.size()) {       return 0;     }     int &ans = memo[idx][val];     if (~ans) {       return ans;     }     ans = roll(idx + 1, val);     if (val >= (int)cost[idx]) {       ans = max(ans, roll(nxt[idx], val - cost[idx]) + 1);     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> s >> p;     vector<pair<int, int> > ranges;     for (int i = int(0); i < int(s.size()); i++) {       int idx = 0;       int match = -1;       if (s[i] == p[0]) {         for (int j = int(i); j < int(s.size()); j++) {           if (p[idx] == s[j]) {             idx++;           }           if (idx == (int)p.size()) {             match = j;             break;           }         }       }       if (match != -1) {         ranges.emplace_back(i, match);       }     }     for (int i = int(0); i < int(ranges.size()); i++) {       auto it = lower_bound(ranges.begin(), ranges.end(),                             make_pair(ranges[i].second + 1, 0));       nxt[i] = it - ranges.begin();       cost.push_back(           max(0, ranges[i].second - ranges[i].first - (int)p.size() + 1));     }     memset(memo, -1, sizeof memo);     for (int i = int(0); i < int(s.size() + 1); i++) {       cout << min(roll(0, i), ((int)s.size() - i) / (int)p.size()) <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 9;   vector<int> g[N];   int a[N], cnt[N], b[N << 1], c[N << 1];   int *vis = b + N, *val = c + N;   set<int> S, now;   int main() {     int n;     scanf( %d , &n);     for (int i = (1); i < (n + 1); ++i)       scanf( %d , &a[i]), cnt[a[i]]++, g[a[i]].push_back(i);     int maxn = 0, p = 0;     for (int i = (1); i < (n + 1); ++i) {       if (maxn < cnt[i]) {         maxn = cnt[i];         p = i;       }     }     if (maxn == n) {       puts( 0 );       return 0;     }     int ans = 0;     for (auto v : g[p]) S.insert(v);     vector<int> temp;     int key = 0;     for (int i = (1); i < (n + 1); ++i) {       if (p == i) continue;       now.clear();       temp.clear();       for (auto v : g[i]) {         auto it = S.lower_bound(v);         if (it != S.end()) {           now.insert(*it);           S.erase(it);         }         it = S.lower_bound(v);         if (it != S.end()) {           now.insert(*it);           S.erase(it);         }         it = S.lower_bound(v);         if (it != S.begin()) {           --it;           now.insert(*it);           S.erase(it);         }         it = S.lower_bound(v);         if (it != S.begin()) {           --it;           now.insert(*it);           S.erase(it);         }       }       for (auto v : now) temp.push_back(v);       for (auto v : g[i]) now.insert(v);       int pos = -1, sum = 0;       for (auto v : now) {         if (v > pos) ++key;         if (vis[sum] != key) {           vis[sum] = key;           val[sum] = v;         }         if (a[v] == p) ++sum;         if (a[v] == i) --sum;         auto it = S.lower_bound(v);         if (it == S.end())           pos = n + 1;         else           pos = *it;         if (vis[sum] == key) {           int l, r;           int vv = val[sum];           auto it = now.lower_bound(vv);           if (it == now.begin())             l = 0;           else             l = *prev(it);           it = now.lower_bound(v);           ++it;           if (it == now.end())             r = n + 1;           else             r = *it;           ans = max(r - l - 1, ans);         }       }       for (auto v : temp) S.insert(v);     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = int(5e3);   const int MOD = int(1e9 + 7);   const int oo = INT_MAX;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, d, h;     while (cin >> n >> d >> h) {       if (2 * h < d) {         cout << -1 <<   n ;         continue;       }       vector<pair<int, int> > edges;       for (int i = 2; i <= h + 1; i++) {         if (i > n) continue;         edges.push_back({i - 1, i});       }       for (int i = h + 2; i <= d + 1; i++) {         if (i > n) continue;         if (i == h + 2)           edges.push_back({1, i});         else           edges.push_back({i - 1, i});       }       int id = d + 2, node = -1;       if (h < d)         node = 1;       else if (h == d && h != 1)         node = 2;       if (node != -1) {         while (id <= n) {           edges.push_back({node, id});           id++;         }       }       if (int(edges.size()) == n - 1)         for (auto& e : edges) cout << e.first <<     << e.second <<   n ;       else         cout << -1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int n = 0, f = 1;     char c;     for (c = getchar(); c !=  -  && (c <  0  || c >  9 ); c = getchar())       ;     if (c ==  - ) c = getchar(), f = -1;     for (; c >=  0  && c <=  9 ; c = getchar()) n = n * 10 + c - 48;     return n * f;   }   struct ar {     int x, y, id, d;   } now;   bool operator<(ar a, ar b) { return a.x == b.x ? a.y < b.y : a.x < b.x; }   int i, a, b, d[3005];   vector<ar> p, an;   bool cmp(ar a, ar b) { return a.x * b.y > a.y * b.x; }   void solve(vector<ar> p) {     int i, j, k, D, n = p.size() - 1;     if (!n) return;     for (i = 1; i <= n; i++)       if (p[i] < p[0]) swap(p[i], p[0]);     for (i = 1; i <= n; i++) p[i].x -= p[0].x, p[i].y -= p[0].y;     sort(p.begin() + 1, p.end(), cmp);     for (i = 1; i <= n; i++) p[i].x += p[0].x, p[i].y += p[0].y;     if (p[0].d < 0) {       for (i = 1; i <= n; i++) {         j = i, D = 0;         for (;; i++) {           D += p[i].d;           if (D >= 0) break;         }         p[i].d--, an.push_back((ar){p[i].id, p[0].id});         p[i].d -= D;         solve(vector<ar>(p.begin() + j, p.begin() + i + 1));         p[j = i].d = D - 1;         for (; D;) D += p[++i].d;         solve(vector<ar>(p.begin() + j, p.begin() + i + 1));       }       return;     }     for (i = 1; p[0].d >= 0;) {       for (j = i, D = 1; D; i++) D += p[i].d;       p[0].d--, an.push_back((ar){p[0].id, p[i - 1].id});       solve(vector<ar>(p.begin() + j, p.begin() + i));     }     solve(vector<ar>(p.begin() + i - 1, p.end()));   }   void work() {     a = read(), b = read();     for (i = 1; i <= b; i++) d[i] = read();     p.clear(), an.clear();     for (i = 1; i <= a + b; i++) {       now.x = read(), now.y = read();       if (i <= a)         now.id = i, now.d = -1;       else         now.d = d[now.id = i - a] - 1;       p.push_back(now);     }     solve(p);     puts( YES );     for (i = 0; i <= a + b - 2; i++) printf( %d %d n , an[i].x, an[i].y);   }   int main() {     for (int t = read(); t--;) work();   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   void query() {     int n, m;     cin >> n >> m;     vector<string> t(n);     for (auto& i : t) cin >> i;     vector<vector<int>> col(n, vector<int>(m, 0));     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         col[i][j] = (i > 0 ? col[i - 1][j] : 0) + t[i][j] -  0 ;     int res = inf;     queue<pair<int, int>> q;     for (int a = 5; a <= n; a++) {       for (int i = 0; i <= n - a; i++) {         while (!q.empty()) q.pop();         pair<int, int> X(inf, 0);         int add = 0;         for (int j = 0; j < m; j++) {           while (q.size() >= 3) {             if (q.front().first - q.front().second < X.first - X.second)               X = q.front();             q.pop();           }           int A = col[i + a - 2][j] - col[i][j];           if (j - 3 >= 0) res = min(res, X.first - X.second + add + a - 2 - A);           if (j > 0)             add += A + 2 - (int)(t[i][j] -  0 ) - (int)(t[i + a - 1][j] -  0 );           q.push({a - 2 - A, add});         }       }     }     cout << res <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int q = 1;     cin >> q;     while (q--) query();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void add(long long &a, long long b) {     a += b;     if (a >= (233333333 * 4 + 23333333 * 2 + 2333333 * 8 + 233333 * 5 +               23333 * 7 + 2333 + 233 * 4 + 23 * 3 + 2 + 2 + 2 + 3 + 3 + 3)) {       a -= (233333333 * 4 + 23333333 * 2 + 2333333 * 8 + 233333 * 5 + 23333 * 7 +             2333 + 233 * 4 + 23 * 3 + 2 + 2 + 2 + 3 + 3 + 3);     }   }   struct BitchIsThere {     int N;     pair<long long, long long> dt[500005];     void upd(pair<long long, long long> &a, pair<long long, long long> b) {       if (a.first > b.first) {         a = b;       } else if (a.first == b.first) {         add(a.second, b.second);       }     }     void init(int nn) {       N = nn;       for (int i = 1; i <= nn; i++) {         dt[i] = make_pair(             (233333333 * 4 + 23333333 * 2 + 2333333 * 8 + 233333 * 5 + 23333 * 7 +              2333 + 233 * 4 + 23 * 3 + 2 + 2 + 2 + 3 + 3 + 3),             0);       }     }     void insert(int x, pair<long long, long long> num) {       while (x <= N) {         upd(dt[x], num);         x += x & -x;       }     }     pair<long long, long long> qsum(int x) {       pair<long long, long long> ans =           make_pair((233333333 * 4 + 23333333 * 2 + 2333333 * 8 + 233333 * 5 +                      23333 * 7 + 2333 + 233 * 4 + 23 * 3 + 2 + 2 + 2 + 3 + 3 + 3),                     0);       while (x) {         upd(ans, dt[x]);         x -= x & -x;       }       return ans;     }   } bit;   int n;   vector<pair<long long, long long> > pills;   int main() {     scanf( %d , &n);     vector<int> ds;     ds.push_back(-1);     ds.push_back(0);     for (int i = 0; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       pills.push_back(make_pair(y, x));       ds.push_back(x);       ds.push_back(y);     }     sort(ds.begin(), ds.end());     ds.resize(unique(ds.begin(), ds.end()) - ds.begin());     sort(pills.begin(), pills.end());     bit.init(ds.size());     bit.insert(1, make_pair(0, 1));     pair<long long, long long> ans =         make_pair((233333333 * 4 + 23333333 * 2 + 2333333 * 8 + 233333 * 5 +                    23333 * 7 + 2333 + 233 * 4 + 23 * 3 + 2 + 2 + 2 + 3 + 3 + 3),                   0);     for (pair<long long, long long> p : pills) {       int x = lower_bound(ds.begin(), ds.end(), p.first) - ds.begin();       int y = lower_bound(ds.begin(), ds.end(), p.second) - ds.begin();       pair<long long, long long> res = bit.qsum(x);       if (p.second > pills.back().first) {         bit.upd(ans, make_pair(res.first + p.first, res.second));       } else {         bit.insert(y, make_pair(p.first + res.first - p.second, res.second));       }     }     printf( %lld n , ans.second);     return 0;   }