#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using ull = unsigned long long;   const double PI = acos(-1.0);   const int EPS = (1e-10);   const int N = 1e5 * 2 + 10;   const int inf = 1e9 * 2 + 10;   const ll INF = 1e18 * 2 + 10;   const int MOD = 1e9 + 7;   int nxt() {     int x;     cin >> x;     return x;   }   int fcmp(double a, double b) {     return (fabs(a - b) < EPS ? 0 : a > b ? 1 : -1);   }   int n;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n;     int mx = 0, p = 0;     for (int i = (1); i <= (n); ++i) {       int k, a;       cin >> k >> a;       mx = max(mx, k);       ll s = 1;       int m = 0;       while (s < a) {         s *= 4;         m++;       }       p = max(p, k + m);     }     if (mx == p) p++;     cout << p;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1001;   int i, j, n, ans;   int a[N], f[N][300], d[20], sum[N][10];   void init() {     d[1] = 1;     for (i = 2; i <= 9; i++) d[i] = d[i - 1] * 2;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     for (i = 1; i <= n; i++) {       for (j = 1; j <= 8; j++) sum[i][j] = sum[i - 1][j];       sum[i][a[i]]++;     }   }   void mark(int st, int k, int len, int v, int s) {     for (i = st; i <= n; i++) {       int t = sum[i][k] - sum[st][k];       if (t > len) return;       if (t == len)         if (f[i][s] == -1 || f[i][s] < v) f[i][s] = v;     }   }   int cal(int len) {     int ans = -1;     memset(f, 255, sizeof(f));     f[0][0] = 0;     int i, j, k;     for (i = 0; i <= n; i++)       for (j = 0; j <= d[9] - 1; j++)         if (f[i][j] != -1) {           if (j == d[9] - 1 && f[i][j] > ans) ans = f[i][j];           for (k = 1; k <= 8; k++)             if ((d[k] & j) == 0) {               mark(i, k, len, f[i][j] + len, d[k] + j);               mark(i, k, len + 1, f[i][j] + len + 1, d[k] + j);             }         }     return ans;   }   void work() {     int l = 0, r = n, mid, ans = 0, t;     while (l <= r) {       mid = (l + r) / 2;       t = cal(mid);       if (t != -1)         l = mid + 1, ans = t;       else         r = mid - 1;     }     printf( %d n , ans);   }   int main() {     init();     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   int a[MAXN], op[MAXN], op1[MAXN], op2[MAXN];   int n, m;   vector<long long> sum[MAXN * 4];   set<int> col[MAXN];   vector<int> e[MAXN * 4];   void get(int o, int l, int r, int x, int y) {     if (x <= l && r <= y) {       e[o].push_back(x);       return;     }     int mid = (l + r) / 2, lch = o * 2, rch = lch + 1;     if (mid >= x) get(lch, l, mid, x, y);     if (mid < y) get(rch, mid + 1, r, x, y);   }   void build(int o, int l, int r) {     if (e[o].size()) {       sort(e[o].begin(), e[o].end());       int sz = unique(e[o].begin(), e[o].end()) - e[o].begin();       for (int i = 0; i <= sz; i++) sum[o].push_back(0);     }     if (l == r) return;     int mid = (l + r) / 2, lch = o * 2, rch = lch + 1;     build(lch, l, mid);     build(rch, mid + 1, r);   }   void add(int o, int x, int v) {     while (x) {       sum[o][x] += v;       x -= (x & -x);     }   }   long long getsum(int o, int x) {     long long res = 0;     while (x < sum[o].size()) {       res += sum[o][x];       x += (x & -x);     }     return res;   }   void update(int o, int l, int r, int x, int p, int v) {     if (sum[o].size()) {       int pos = upper_bound(e[o].begin(), e[o].begin() + sum[o].size() - 1, p) -                 e[o].begin();       if (pos != 0) add(o, pos, v);     }     if (l == r) return;     int mid = (l + r) / 2, lch = o * 2, rch = lch + 1;     if (mid >= x)       update(lch, l, mid, x, p, v);     else       update(rch, mid + 1, r, x, p, v);   }   long long res;   void query(int o, int l, int r, int x, int y) {     if (x <= l && r <= y) {       res += getsum(           o, lower_bound(e[o].begin(), e[o].begin() + sum[o].size() - 1, x) -                  e[o].begin() + 1);       return;     }     int mid = (l + r) / 2, lch = o * 2, rch = lch + 1;     if (mid >= x) query(lch, l, mid, x, y);     if (mid < y) query(rch, mid + 1, r, x, y);   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       col[a[i]].insert(i);     }     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &op[i], &op1[i], &op2[i]);       if (op[i] == 2) get(1, 1, n, op1[i], op2[i]);     }     build(1, 1, n);     for (int i = 1; i <= n; i++) {       auto pos = col[a[i]].lower_bound(i);       if (pos == col[a[i]].begin()) continue;       pos--;       update(1, 1, n, i, *pos, i - *pos);     }     for (int i = 1; i <= m; i++) {       if (op[i] == 1) {         int x = op1[i], v = op2[i];         if (a[x] == v) continue;         auto pos = col[a[x]].lower_bound(x);         int flag = 0;         if (pos != col[a[x]].begin()) {           pos--;           flag++;           update(1, 1, n, x, *pos, *pos - x);         }         pos = col[a[x]].lower_bound(x);         pos++;         if (pos != col[a[x]].end()) {           flag++;           update(1, 1, n, *pos, x, x - *pos);         }         if (flag == 2) {           pos = col[a[x]].lower_bound(x);           auto ppos = pos;           ppos--;           pos++;           update(1, 1, n, *pos, *ppos, *pos - *ppos);         }         col[a[x]].erase(x);         a[x] = v;         col[v].insert(x);         pos = col[v].lower_bound(x);         flag = 0;         if (pos != col[v].begin()) {           pos--;           flag++;           update(1, 1, n, x, *pos, x - *pos);         }         pos = col[v].lower_bound(x);         pos++;         if (pos != col[a[x]].end()) {           flag++;           update(1, 1, n, *pos, x, *pos - x);         }         if (flag == 2) {           pos = col[v].lower_bound(x);           auto ppos = pos;           ppos--;           pos++;           update(1, 1, n, *pos, *ppos, *ppos - *pos);         }       } else {         res = 0;         query(1, 1, n, op1[i], op2[i]);         printf( %I64d n , res);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e3 + 5;   vector<int> adj[N];   int n, m, eu[N], ev[N], ew[N], a[N], b[N], g[N];   bool dfs1(int u, int t, int w, int p = -1) {     if (u == t) {       return 1;     }     for (int e : adj[u]) {       int v = eu[e] ^ ev[e] ^ u;       if (v == p) {         continue;       }       if (dfs1(v, t, w, u)) {         ew[e] = max(ew[e], w);         return 1;       }     }     return 0;   }   int dfs2(int u, int t, int p = -1) {     if (u == t) {       return 1e9;     }     for (int e : adj[u]) {       int v = eu[e] ^ ev[e] ^ u;       if (v == p) {         continue;       }       int a = dfs2(v, t, u);       if (~a) {         return min(a, ew[e]);       }     }     return -1;   }   int main() {     cin >> n;     for (int i = 1; i < n; i++) {       cin >> eu[i] >> ev[i], eu[i]--, ev[i]--;       adj[eu[i]].push_back(i);       adj[ev[i]].push_back(i);     }     fill(ew + 1, ew + n, 1);     cin >> m;     for (int i = 0; i < m; i++) {       cin >> a[i] >> b[i] >> g[i], --a[i], --b[i];       dfs1(a[i], b[i], g[i]);     }     for (int i = 0; i < m; i++) {       if (dfs2(a[i], b[i]) ^ g[i]) {         cout <<  -1 ;         exit(0);       }     }     for (int i = 1; i < n; i++) {       cout << ew[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000 * 1000 * 1000 + 7;   long long mod(long long n) {     n %= MOD;     if (n < 0)       return n + MOD;     else       return n;   }   long long fp(long long a, long long p) {     long long ans = 1, c = a;     for (long long i = 0; (1ll << i) <= p; ++i) {       if ((p >> i) & 1) ans = mod(ans * c);       c = mod(c * c);     }     return ans;   }   long long dv(long long a, long long b) { return mod(a * fp(b, MOD - 2)); }   const long long N = 2e6 + 7;   long long first[N];   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     first[0] = 1;     for (long long i = 1; i < N; ++i) first[i] = mod(first[i - 1] * i);     long long n;     cin >> n;     ++n;     long long a = mod(2 * first[2 * n - 1]);     long long b = mod(first[n] * first[n - 1]);     long long ans = mod(dv(a, b) - 1);     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int Imx = 2147483647;   const long long Lbig = 2e18;   const int mod = 1e9 + 7;   struct fastio {     char s[100000];     int it, len;     fastio() { it = len = 0; }     inline char get() {       if (it < len) return s[it++];       it = 0;       len = fread(s, 1, 100000, stdin);       if (len == 0)         return EOF;       else         return s[it++];     }     bool notend() {       char c = get();       while (c ==     || c ==   n ) c = get();       if (it > 0) it--;       return c != EOF;     }   } _buff;   inline long long getnum() {     long long r = 0;     bool ng = 0;     char c;     c = _buff.get();     while (c !=  -  && (c <  0  || c >  9 )) c = _buff.get();     if (c ==  - ) ng = 1, c = _buff.get();     while (c >=  0  && c <=  9 ) r = r * 10 + c -  0 , c = _buff.get();     return ng ? -r : r;   }   template <class T>   inline void putnum(T x) {     if (x < 0) putchar( - ), x = -x;     register short a[20] = {}, sz = 0;     while (x) a[sz++] = x % 10, x /= 10;     if (sz == 0) putchar( 0 );     for (int i = sz - 1; i >= 0; i--) putchar( 0  + a[i]);   }   inline char getreal() {     char c = _buff.get();     while (c <= 32) c = _buff.get();     return c;   }   long long qpow(long long x, long long k) {     return k == 0 ? 1                   : 1ll * qpow(1ll * x * x % mod, k >> 1) * (k & 1 ? x : 1) % mod;   }   int n;   vector<int> vy;   int getidy(int y) { return upper_bound(vy.begin(), vy.end(), y) - vy.begin(); }   bool ANS[100111];   struct node {     set<int> st, tst;     int mn, mx;     int cmxu, hmxu;     void add(int x) {       st.insert(x);       tst.insert(x);       mx = *st.rbegin();     }     void del(int x) {       st.erase(x);       tst.erase(x);       assert(st.size() > 0);       mx = *st.rbegin();     }     node() {       add(0);       cmxu = hmxu = mn = 0;     }     void query(int x) {       while (tst.size() > 0 && *tst.rbegin() >= x)         ANS[*tst.rbegin()] = 1, tst.erase(--tst.end());     }   } a[800111];   void updateu(int p) { a[p].cmxu = max(a[p >> 1].cmxu, a[p].mx); }   void update(int p, bool isl) {     a[p].mn = max(a[p].mx, (isl ? 0 : min(a[p << 1].mn, a[p << 1 | 1].mn)));   }   void deltag(int p, bool isl) {     a[p].query(max(a[p].mn, max(a[p].hmxu, a[p].mx)));     if (!isl) {       int cmxu = max(a[p].hmxu, a[p].mx);       a[p << 1].hmxu = min(a[p << 1].hmxu, cmxu),              a[p << 1 | 1].hmxu = min(a[p << 1 | 1].hmxu, cmxu);     }     a[p].hmxu = a[p >> 1].cmxu;   }   void modify(int x, int y, int op, int v, int l, int r, int p = 1) {     deltag(p, l == r);     updateu(p);     if (x <= l && r <= y) {       if (op == 1)         a[p].add(v);       else         a[p].del(v);       updateu(p);       update(p, l == r);       if (l < r) {         a[p << 1].hmxu = min(a[p << 1].hmxu, a[p].cmxu);         a[p << 1 | 1].hmxu = min(a[p << 1 | 1].hmxu, a[p].cmxu);       }       a[p].query(max(a[p].mn, a[p].cmxu));       return;     }     int m = l + r >> 1;     if (x <= m) modify(x, y, op, v, l, m, p << 1);     if (m < y) modify(x, y, op, v, m + 1, r, p << 1 | 1);     update(p, l == r);     a[p].query(max(a[p].mn, a[p].cmxu));   }   void pushdownall(int l, int r, int p) {     deltag(p, l == r);     updateu(p);     a[p].query(max(a[p].mn, a[p].cmxu));     if (l == r) return;     int m = l + r >> 1;     pushdownall(l, m, p << 1);     pushdownall(m + 1, r, p << 1 | 1);   }   struct query {     int op, x, yl, yr, id;     bool operator<(const query &t) const {       return make_pair(make_pair(x, op), op == 1 ? -id : id) <              make_pair(make_pair(t.x, t.op), t.op == 1 ? -t.id : t.id);     }   };   vector<query> qr;   int main() {     n = getnum();     for (int i = 1; i <= n; i++) {       int xl, yl, xr, yr;       xl = getnum(), yl = getnum();       xr = getnum(), yr = getnum();       yr--;       vy.push_back(yl);       vy.push_back(yr + 1);       query tmp;       tmp.yl = yl;       tmp.yr = yr;       tmp.id = i;       tmp.x = xl;       tmp.op = 1;       qr.push_back(tmp);       tmp.x = xr;       tmp.op = 2;       qr.push_back(tmp);     }     sort(vy.begin(), vy.end());     vy.erase(unique(vy.begin(), vy.end()), vy.end());     sort(qr.begin(), qr.end());     int sz = vy.size();     for (int i = 0; i < qr.size(); i++) {       int yl = getidy(qr[i].yl);       int yr = getidy(qr[i].yr);       modify(yl, yr, qr[i].op, qr[i].id, 1, sz);     }     int ans = 0;     for (int i = 0; i <= n; i++) ans += ANS[i];     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long arr[n][n];     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < n; j++) cin >> arr[i][j];     }     long long ans[n];     ans[2] = sqrt(arr[1][2] * arr[2][0] / arr[1][0]);     ans[1] = arr[1][2] / ans[2];     ans[0] = arr[1][0] / ans[1];     for (long long i = 3; i < n; i++) {       ans[i] = arr[i][0] / ans[0];     }     for (long long i = 0; i < n; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, p, q, l, b = 0, i, d, m, n, k, sum = 0, t = 1, x = 0, z = 0,                               y = 0;     vector<long long int> v;     cin >> a;     for (int i = 0; i < a; i++) {       cin >> x;       if (x > 0) {         sum = sum + (x - 1);       } else if (x == 0) {         y++;       } else {         p = -x - 1;         sum = sum + p;         z++;       }     }     sum = sum + y;     if (z % 2 == 1 && y == 0) {       sum = sum + 2;     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10, oo = 1e9 + 10, MOD = 1e9 + 7;   void solve() {     long long a, b;     cin >> a >> b;     if (a > b) {       long long ans = 0;       while (b != a) {         b *= 2;         ans++;         if (b > a) {           cout <<  -1 n ;           return;         }       }       int q = 0, q1 = 0;       if (ans >= 3) {         long long k = ans / 3;         k += ans % 3;         q = ans % 3;         ans = k;         q1 = 1;       }       if (q >= 2 && q1) {         ans -= q / 2;       }       if (!q1) {         ans = (ans + 1) / 2;       }       cout << ans <<   n ;     } else {       if (a == b) {         cout <<  0 n ;         return;       }       long long ans = 0;       while (a != b) {         a *= 2;         ans++;         if (a > b) {           cout <<  -1 n ;           return;         }       }       int q = 0, q1 = 0;       if (ans >= 3) {         long long k = ans / 3;         k += ans % 3;         q = ans % 3;         ans = k;         q1 = 1;       }       if (q >= 2 && q1) {         ans -= q / 2;       }       if (!q1) {         ans = (ans + 1) / 2;       }       cout << ans <<   n ;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t = 1;     cin >> t;     while (t--) {       solve();     }   }


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


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1000000007;   const int maxn = 300010;   int vis[maxn], cnt[maxn];   long long sum[maxn];   int mod(int x, int u) {     int ret = 0;     for (int i = 2; i <= u; ++i)       if (vis[i]) {         ret += x % i;       }     return ret;   }   long long cal(int x) {     long long ret = 0, xx = x;     for (int i = 1;; ++i) {       int d = x / (i + 1), u = x / i;       if (u <= 500) {         return ret + mod(x, u);       }       ret += xx * (cnt[u] - cnt[d]) - (sum[u] - sum[d]) * i;     }     return ret;   }   int main() {     static int a[maxn];     static long long p[maxn];     int n, N = 300000;     cin >> n;     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);     }     for (int i = 0; i < n; i += 400) {       int j = min(n, i + 400);       for (int k = i; k < j; ++k) {         long long ak = a[k];         p[k] = cal(a[k]) + ak * (cnt[N] - cnt[a[k]]);         for (int kk = 0; kk < N; kk += a[k]) {           int rig = min(kk + a[k] - 1, N);           p[k] += (sum[rig] - sum[kk]) - (long long)kk * (cnt[rig] - cnt[kk]);         }         for (int kk = i; kk < k; ++kk) {           p[k] += a[kk] % a[k] + a[k] % a[kk];         }       }       for (int k = i; k < j; ++k) {         vis[a[k]] = 1;       }       for (int k = 1; k <= N; ++k) {         cnt[k] = vis[k] + cnt[k - 1];         sum[k] = vis[k] * k + sum[k - 1];       }     }     long long pp = 0;     for (int i = 0; i < n; ++i) {       pp += p[i];       printf( %lld  , pp);     }     puts(  );     return 0;   }


/*-- ILSH  --*/   #include  bits/stdc++.h    using namespace std;   typedef long long ll;   typedef double ld;   #define pb push_back    #define pop pop_back   #define mp make_pair   #define vii vector < ll >   #define dt cout<< HERE n ;   #define pii pair < ll , ll >   #define vpi vector < pii >   #define fi first   #define se second    #define sz(x) ((ll)x.size())   #define len(x) ((ll)x.length())   void up(vii &v){ for ( ll i=0;i<sz(v);i++) cout<<v[i]<<   ; cout<<  n ;}   const ll inf=1e18+1e17;   const ll mod =1e9+7;   using cd= complex < double > ;      //const ll mod = 998244353;   ll modInverse(ll a,ll m){ll m0=m;ll y=0,x=1;if(m == 1)return 0;while(a> 1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}     ll powm(ll a,ll b){a=a%mod;ll res=1;while(b){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return (res%mod);}   const ll N = 5e3 +5;   bool check(int fx, int fy, int pos, string &s, int x, int y){    int n=len( s);    for ( int i=pos;i<n;i++){     int nx=x, ny=y;     if ( s[i]== R )      nx=x+1;     if ( s[i]== L )      nx=x-1;     if ( s[i]== U )      ny=y+1;     if ( s[i]== D )      ny=y-1;     if ( nx==fx&&ny==fy)      continue;     else{      x=nx;      y=ny;     }    }    if ( x==0&&y==0)     return true;    return false;   }   void solve(){    map< pii , bool > m;       string s;    cin>> s;    int n=len( s);    int x_pos=0,y_pos=0;    for ( int i=0;i<n;i++){     int nx=x_pos, ny=y_pos;     if ( s[i]== R )      nx=x_pos+1;     if ( s[i]== L )      nx=x_pos-1;     if ( s[i]== U )      ny=y_pos+1;     if ( s[i]== D )      ny=y_pos-1;     if ( m[{nx,ny}]==0){      m[{nx, ny}]=1;      if ( check( nx , ny,i,s, x_pos,y_pos)){       cout<<nx<<   <<ny<<  n ;       return;      }     }     x_pos=nx;     y_pos=ny;    }    cout<< 0 0 n ;         }         int main(){    ios_base::sync_with_stdio(false);    cin.tie( NULL);    cout.tie(NULL);    #ifndef ONLINE_JUDGE     freopen ( INPUT.txt  ,  r  , stdin);     freopen ( OUTPUT.txt ,  w  , stdout);    #endif    ll t=1;       cin>>t;    for ( ll i=1;i<=t;i++){     //cout<< Case  <<i<< :  ;        solve();       }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2222;   const long long INF = 1e9 + 19;   const int ALF = 26;   int n;   string s[N];   vector<vector<int>> nextS[N];   int m;   int id[N];   string t;   pair<int, int> dp[N][N];   vector<vector<int>> nextT;   pair<int, int> nextG[N][ALF];   void read() {     cin >> n;     for (int i = 0; i < n; i++) cin >> s[i];     scanf( %d , &m);     for (int i = 0; i < m; i++) {       scanf( %d , &id[i]);       id[i]--;     }     cin >> t;   }   void calcNext(string ss, vector<vector<int>> &a) {     int nn = ss.size();     a.resize(nn + 1, vector<int>(ALF, INF));     for (int i = nn - 1; i >= 0; i--) {       for (int j = 0; j < ALF; j++) a[i][j] = a[i + 1][j];       a[i][ss[i] -  a ] = i;     }   }   void upd(pair<int, int> &A, pair<int, int> B) { A = min(A, B); }   int solve() {     memset(dp, 63, sizeof(dp));     dp[0][0] = make_pair(0, 0);     for (int i = 0; i < n; i++) nextS[i].clear();     nextT.clear();     calcNext(t, nextT);     for (int i = 0; i < n; i++) {       calcNext(s[i], nextS[i]);     }     memset(nextG, 63, sizeof(nextG));     for (int i = m - 1; i >= 0; i--) {       for (int j = 0; j < ALF; j++) nextG[i][j] = nextG[i + 1][j];       for (int j = 0; j < ALF; j++)         if (nextS[id[i]][0][j] != INF)           nextG[i][j] = make_pair(i, nextS[id[i]][0][j]);     }     for (int i = 0; i < (int)t.size(); i++) {       for (int j = 0; j <= i; j++) {         if (dp[i][j].first < INF) {           int x = dp[i][j].first;           int y = dp[i][j].second;           for (int ch = 0; ch < ALF; ch++) {             if (nextT[i][ch] < INF) {               pair<int, int> p2;               if (nextS[id[x]][y][ch] < INF) {                 p2 = make_pair(x, nextS[id[x]][y][ch]);               } else {                 p2 = nextG[x + 1][ch];               }               if (p2.first < INF) {                 p2.second++;                 upd(dp[nextT[i][ch] + 1][j + 1], p2);               }             }           }         }       }     }     int answer = 0;     for (int pos = 0; pos <= (int)t.size(); pos++)       for (int i = 0; i <= (int)t.size(); i++)         if (dp[pos][i].first < INF) answer = max(i, answer);     return answer;   }   int dp2[N][N];   void upd(int &A, int B) { A = max(A, B); }   int stupid() {     string tmp;     for (int i = 0; i < m; i++) tmp += s[id[i]];     n = 1;     s[0] = tmp;     m = 1;     id[0] = 0;     dp2[0][0] = 0;     for (int i = 0; i <= (int)s[0].size(); i++)       for (int j = 0; j <= (int)t.size(); j++) {         if (i == 0 && j == 0) continue;         dp2[i][j] = -INF;         if (i > 0) upd(dp2[i][j], dp2[i - 1][j]);         if (j > 0) upd(dp2[i][j], dp2[i][j - 1]);         if (i > 0 && j > 0 && s[0][i - 1] == t[j - 1])           upd(dp2[i][j], dp2[i - 1][j - 1] + 1);       }     return dp2[s[0].size()][t.size()];   }   void printAns(int xx) { printf( %d n , xx); }   void genTest() {     int T = 6;     n = rand() % T + 1;     for (int i = 0; i < n; i++) {       int len = rand() % T + 1;       s[i] =   ;       for (int j = 0; j < len; j++) s[i] +=  a  + rand() % T;     }     m = rand() % T + 1;     for (int i = 0; i < m; i++) id[i] = rand() % n;     int len = rand() % T + 1;     t =   ;     for (int i = 0; i < len; i++) t +=  a  + rand() % T;   }   void printTest() {     cout << n << endl;     for (int i = 0; i < n; i++) cout << s[i] << endl;     cout << m << endl;     for (int i = 0; i < m; i++) cout << id[i] + 1 <<    ;     cout << endl;     cout << t << endl;   }   void stress() {     for (int tt = 0;; tt++) {       cerr <<  tt             <<   =   << tt << endl;       genTest();       auto r1 = solve();       auto r2 = stupid();       cerr <<  (             <<  r1             <<  ,              <<  r2             <<  ) = (  << r1 <<  ,   << r2 <<  ) n ;       ;       assert(r1 == r2);     }   }   int main() {     if (1) {       read();       printAns(solve());     } else {       stress();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int Maxn3 = 1e3 + 10;   const long long int Maxn4 = 1e4 + 10;   const long long int Maxn5 = 1e5 + 10;   const long long int Maxn6 = 1e6 + 10;   const long long int Maxn7 = 1e7 + 10;   const long long int Maxn8 = 1e8 + 10;   const long long int Maxn9 = 1e9 + 10;   const long long int Maxn18 = 1e18 + 10;   const long long int Mod1 = 1e7 + 7;   const long long int Mod2 = 1e9 + 7;   const long long int LLMax = LLONG_MAX;   const long long int LLMin = LLONG_MIN;   const long long int INTMax = INT_MAX;   const long long int INTMin = INT_MIN;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     long long int a, b, n;     cin >> a >> b >> n;     bool mark[n + 1];     for (long long int i = 0; i <= n; i++) mark[i] = 0;     for (long long int i = a; i <= n; i += a) mark[i] = 1;     long long int res = 0;     for (long long int i = b; i <= n; i += b)       if (mark[i]) res++;     return cout << res, 0;   }


#include <bits/stdc++.h>   int main() {     int n, a, sum;     scanf( %d , &n);     int k = 0;     int arr[100];     for (int i = n - 9 * (log10(n) + 1 + 1); i <= n; i++) {       sum = a = i;       while (a != 0) {         sum += a % 10;         a /= 10;       }       if (sum == n) {         arr[k++] = i;       }     }     printf( %d n , k);     for (int i = 0; i < k; i++) {       printf( %d n , arr[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = ((int)5e2) + 5;   vector<string> str;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       str.push_back(s);     }     vector<string> comb = { 12 ,  23 ,  34 ,  31 ,  14 ,  24 };     for (int i = 0; i < 2; i++) {       for (int c = 0; c < 6; c++) {         string first[2];         first[0] = comb[c];         first[1] = comb[c];         reverse(first[1].begin(), first[1].end());         set<char> t = { 1 ,  2 ,  3 ,  4 };         t.erase(comb[c][0]);         t.erase(comb[c][1]);         string sec[2];         sec[0] += (*t.begin());         t.erase(t.begin());         sec[0] += (*t.begin());         sec[1] = sec[0];         reverse(sec[1].begin(), sec[1].end());         vector<string> board;         for (int row = 0; row < n; row++) {           string r;           string* pattern = first;           if (row & 1) pattern = sec;           bool ok = true;           for (int ver = 0; ver < 2; ver++) {             ok = true;             for (int col = 0; col < m; col++) {               r += pattern[ver][col & 1];               if (str[row][col] !=  0  && r[col] != str[row][col]) {                 ok = false;                 break;               }             }             if (ok)               break;             else               r =   ;           }           if (ok) board.push_back(r);         }         if (board.size() == n) {           if (i == 0)             for (int j = 0; j < n; j++) cout << board[j] << endl;           else {             for (int col = 0; col < m; col++) {               string temp;               for (int row = 0; row < n; row++) {                 temp.push_back(board[row][col]);               }               cout << temp << endl;             }           }           return 0;         }       }       vector<string> arr;       for (int col = 0; col < m; col++) {         string temp;         for (int row = 0; row < n; row++) {           temp.push_back(str[row][col]);         }         arr.push_back(temp);       }       str = arr;       swap(n, m);     }     cout <<  0 ;     return 0;   }


#include <bits/stdc++.h>   using namespace ::std;   const long double PI = acos(-1);   const long long MOD = 1000000000 + 7;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long add(long long a, long long b, long long m = MOD) {     if (a >= m) a %= m;     if (b >= m) b %= m;     if (a < 0) a += m;     if (b < 0) b += m;     long long res = a + b;     if (res >= m or res <= -m) res %= m;     if (res < 0) res += m;     return res;   }   long long mul(long long a, long long b, long long m = MOD) {     if (a >= m) a %= m;     if (b >= m) b %= m;     if (a < 0) a += m;     if (b < 0) b += m;     long long res = a * b;     if (res >= m or res <= -m) res %= m;     if (res < 0) res += m;     return res;   }   long long pow_mod(long long a, long long b, long long m = MOD) {     long long res = 1LL;     a = a % m;     while (b) {       if (b & 1) res = mul(res, a, m);       b >>= 1;       a = mul(a, a, m);     }     return res;   }   long long fastexp(long long a, long long b) {     long long res = 1LL;     while (b) {       if (b & 1) res = res * a;       b >>= 1;       a *= a;     }     return res;   }   int gcdExtendido(int a, int b, int *x, int *y) {     if (a == 0) {       *x = 0;       *y = 1;       return b;     }     int x1, y1;     int gcd = gcdExtendido(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     return gcd;   }   int modInverso(int a, int m) {     int x, y;     int g = gcdExtendido(a, m, &x, &y);     if (g != 1)       return -1;     else       return (x % m + m) % m;   }   const int N = 300000 + 5;   const int L = 30;   const int SUML = 300000 * 30 + 5;   const int E = 2;   int n;   int a[N];   int nodes = 1;   int frec[SUML];   int trie[SUML][E];   void insert(int x) {     int pos = 0;     for (int i = L - 1; i >= 0; i--) {       int nxt = (x >> i) & 1;       if (trie[pos][nxt] == 0) {         trie[pos][nxt] = nodes++;       }       pos = trie[pos][nxt];       frec[pos] += 1;     }   }   void erase(int val) {     int pos = 0;     for (int i = L - 1; i >= 0; i--) {       int nxt = (val >> i) & 1;       pos = trie[pos][nxt];       frec[pos] -= 1;     }   }   int getMin(int x) {     int ans = 0;     int pos = 0;     for (int i = L - 1; i >= 0; i--) {       int have = (x >> i) & 1;       int nxt = have;       if (frec[trie[pos][nxt]] == 0) nxt ^= 1;       ans |= (nxt ^ have) << i;       pos = trie[pos][nxt];     }     return ans;   }   int main() {     scanf( %d , &(n));     for (int i = 1; i <= n; i++) scanf( %d , &(a[i]));     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &(x));       insert(x);     }     for (int i = 1; i <= n; i++) {       int cur = getMin(a[i]);       erase(cur ^ a[i]);       printf( %d%c , cur,    n [i == n]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void file() {}   const int N = 1e5 + 5, MAX = 3e7, MOD = 1e9 + 7;   int a[N];   int n, k;   long long dp[N][12];   long long seg[4 * N][12];   void update(int indx, int l, int r, int pos, int who, long long val) {     if (l == r) {       seg[indx][who] = val;       return;     }     if (pos <= (l + r) / 2)       update(indx * 2, l, (l + r) / 2, pos, who, val);     else       update(indx * 2 + 1, (l + r) / 2 + 1, r, pos, who, val);     seg[indx][who] = seg[indx * 2][who] + seg[indx * 2 + 1][who];   }   long long get(int indx, int l, int r, int i, int j, int who) {     if (l > j || r < i) return 0;     if (l >= i && r <= j) return seg[indx][who];     return get(indx * 2, l, (l + r) / 2, i, j, who) +            get(indx * 2 + 1, (l + r) / 2 + 1, r, i, j, who);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     file();     scanf( %d %d , &n, &k);     k++;     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = n - 1; i >= 0; i--) {       for (int j = 2; j <= k; j++) {         dp[i][j] = get(1, 1, N - 1, a[i] + 1, N - 1, j - 1);         if (j == k) dp[i][j] += dp[i + 1][j];         update(1, 1, N - 1, a[i], j, dp[i][j]);       }       update(1, 1, N - 1, a[i], 1, 1);       dp[i][1] = dp[i + 1][1] + 1;     }     printf( %lld n , dp[0][k]);   }


#include <bits/stdc++.h>   using namespace std;   const long long LLmn = LLONG_MIN;   const long long LLmx = LLONG_MAX;   const long long MOD = 1e6 + 3;   const long long N = 1e9 + 7;   const long double PI = 3.14159265358979323846;   long long gcd(long long a, long long b) {     if (a == 0) {       return b;     }     return gcd(b % a, a);   }   long long lcm(long long a, long long b) { return a * b / gcd(a, b); }   pair<int, int> w[9] = {make_pair(-1, 0), make_pair(0, -1),  make_pair(1, 0),                          make_pair(0, 1),  make_pair(-1, -1), make_pair(0, 1),                          make_pair(1, -1), make_pair(1, 1)};   void solve() {     long long n;     cin >> n;     long long a[n];     for (long long i = 0; i < n; i++) cin >> a[i];     if (n & 1) {       if (a[0] + a[1] != 0)         cout << -a[2] <<     << -a[2] <<     << a[0] + a[1] <<    ;       else if (a[0] + a[2] != 0)         cout << -a[1] <<     << a[0] + a[2] <<     << -a[1] <<    ;       else         cout << a[1] + a[2] <<     << -a[0] <<     << -a[0] <<    ;       for (long long i = 3; i < n; i += 2) {         if (i + 1 < n) cout << a[i + 1] <<     << -a[i] <<    ;       }       cout <<   n ;       ;     } else {       for (long long i = 0; i < n; i += 2) {         if (i + 1 < n) cout << a[i + 1] <<     << -a[i] <<    ;       }       cout <<   n ;       ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     ;     long long t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 2e5 + 5;   const long long P = (479 << 21) + 1;   const long long G = 3;   long long wn[21];   inline long long fpw(long long x, long long y, long long m) {     long long rtn = 1;     for (x = (x >= m ? x % m : x); y; y >>= 1) {       if (y & 1) rtn = rtn * x % m;       x = x * x % m;     }     return rtn;   }   inline void Getwn() {     for (int i = 0; i < 21; i++) wn[i] = fpw(G, (P - 1) >> i, P);   }   inline vector<long long> ntt(vector<long long> rtn, int Rev = 1) {     int ntt_n = rtn.size();     for (int i = 0, j = 0; i < ntt_n; i++) {       if (i > j) swap(rtn[i], rtn[j]);       for (int k = (ntt_n >> 1); (j ^= k) < k; k >>= 1)         ;     }     for (int i = 2, m = 1; i <= ntt_n; i <<= 1, m++) {       long long w = 1, u, t;       int mh = i >> 1;       for (int j = 0; j < mh; j++) {         for (int k = j; k < ntt_n; k += i) {           u = rtn[k], t = w * rtn[k + mh] % P;           rtn[k] = (u + t) % P;           rtn[k + mh] = (u - t + P) % P;         }         w = w * wn[m] % P;       }     }     if (!~Rev) {       for (int i = 1; i < ntt_n / 2; i++) swap(rtn[i], rtn[ntt_n - i]);       long long Revn = fpw(ntt_n, P - 2, P);       for (int i = 0; i < ntt_n; i++) rtn[i] = rtn[i] * Revn % P;     }     return rtn;   }   int n, m, k;   int N = 1;   char s[MAX_N], t[MAX_N];   vector<long long> a, b;   int ans[MAX_N];   int tot;   inline void conv(char now) {     Getwn();     a = b = vector<long long>(N);     for (int i = 0, j = 0; i < n && j < n; i++) {       while ((s[j] && s[j] != now) || i - j > k) j++;       if (s[j] == now && abs(i - j) <= k) a[i] = 1;     }     for (int i = 0; i < m; i++)       if (t[i] == now) b[i] = 1;     a = ntt(a);     b = ntt(b);     for (int i = 0; i < N; i++) a[i] = a[i] * b[i] % P;     a = ntt(a, -1);     for (int i = m - 1; i < n + m - 1; i++) ans[i - m + 1] += a[i];   }   int main() {     scanf( %d%d%d , &n, &m, &k);     while (N < n + m - 1) N <<= 1;     scanf( %s , s);     scanf( %s , t);     for (int i = 0; i < m / 2; i++) swap(t[i], t[m - i - 1]);     conv( A );     conv( T );     conv( G );     conv( C );     for (int i = 0; i < n; i++)       if (ans[i] == m) tot++;     printf( %d n , tot);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mark[2000010 * 2];   int tree[2000010 * 4];   bool emerged[2000010 * 2];   void insert(int l, int r, int i, int ind, int num) {     tree[ind] += num;     if (l == r) return;     int mid = (l + r) / 2;     if (i <= mid) insert(l, mid, i, ind * 2, num);     if (i > mid) insert(mid + 1, r, i, ind * 2 + 1, num);   }   int find(int l, int r, int y, int ind) {     if (l == r) return l;     int mid = (l + r) / 2;     if (tree[ind * 2] >= y) {       return find(l, mid, y, ind * 2);     } else {       return find(mid + 1, r, y - tree[ind * 2], ind * 2 + 1);     }   }   int main() {     memset(tree, 0, sizeof(tree));     memset(emerged, 0, sizeof(emerged));     memset(mark, 0, sizeof(mark));     int n, m;     scanf( %d%d , &n, &m);     for (int i = n + 1; i <= 2 * n; ++i) insert(1, 2 * n, i, 1, 1);     int x, y;     for (int i = 0; i < m; i++) {       scanf( %d%d , &x, &y);       int place = find(1, 2 * n, y, 1);       if (((mark[place] > 0) || emerged[x]) && (mark[place] != x)) {         cout << -1 << endl;         return 0;       }       insert(1, 2 * n, place, 1, -1);       insert(1, 2 * n, n - i, 1, 1);       mark[n - i] = mark[place] = x;       emerged[x] = true;     }     int j = 1;     for (int i = n + 1; i <= 2 * n; i++) {       int tmp;       if (mark[i] > 0)         tmp = mark[i];       else {         while (emerged[j]) j++;         tmp = j;         j++;       }       printf( %d  , tmp);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x = 0, y, n, sol = 0, energy = 0;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> y;       energy += x - y;       if (energy < 0) {         sol = sol - energy;         energy = 0;       }       x = y;     }     cout << sol;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(time(0));   uniform_int_distribution<int> uid(-1e9, 1e9);   long double f[51];   vector<vector<vector<long double>>> dp;   pair<long double, long double> solve(vector<int> v, int l, int r) {     dp.assign(v.size() + 1, vector<vector<long double>>(                                 r + 1, vector<long double>(v.size() + 1, 0)));     dp[0][0][0] = 1;     for (int i = 0; i < v.size(); ++i)       for (int j = 0; j <= r; ++j)         for (int k = 0; k < v.size(); ++k) {           dp[i + 1][j][k] += dp[i][j][k];           if (v[i] + j <= r) dp[i + 1][j + v[i]][k + 1] += dp[i][j][k];         }     long double res = 0, x = 0;     for (int i = l; i <= r; ++i)       for (int j = 0; j <= v.size(); ++j)         if (dp[v.size()][i][j]) {           long double x2 = dp[v.size()][i][j] * f[j] * f[v.size() - j];           if (x2) res = ((res * x) + (x2 * j)) / (x + x2), x += x2;         }     return {res, x};   }   vector<int> v;   signed main() {     int n, p, s = 0;     cin >> n;     v.resize(n);     for (auto& i : v) cin >> i, s += i;     cin >> p;     if (s <= p) {       cout << n;       exit(0);     }     f[0] = 1;     for (int i = 1; i <= 50; i++) f[i] = f[i - 1] * i;     long double res = 0, x = 0;     for (int i = 0; i < n; i++) {       vector<int> w;       for (int j = 0; j < n; j++)         if (j - i) w.push_back(v[j]);       auto p2 = solve(w, max(0, p - v[i] + 1), p);       if (p2.second)         res = ((res * x) + (p2.first * p2.second)) / (x + p2.second),         x += p2.second;     }     cout << fixed << setprecision(20) << res;   }


#include <bits/stdc++.h>   using namespace std;   long long int fast_exp(long long int a, long long int b) {     if (a == 0) return 0;     if (b == 0) return 1;     if (b == 1) return a;     if (b % 2 == 0) {       return fast_exp(((a % 1000000007) * (a % 1000000007)) % 1000000007, b / 2) %              1000000007;     }     return ((a % 1000000007) *             fast_exp(((a % 1000000007) * (a % 1000000007)) % 1000000007,                      (b - 1) / 2)) %            1000000007;   }   long long int comb(long long int n, long long int k) {     long long int ans = 1, j = 1;     k = max(k, n - k);     for (long long int i = n; i > k; --i) {       ans *= i;       if (j <= (n - k)) {         ans = ans / j;         j++;       }     }     if (j <= (n - k)) {       ans = ans / j;       j++;     }     return ans;   }   struct node {     long long int x, y;   };   long long int ax, bx, ay, by, binx, biny;   node ar[100005];   double disA[100005], disB[100005], disBin[100005];   double dist(long long int x1, long long int y1, long long int x2,               long long int y2) {     double ans = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));     return ans;   }   int main() {     cin >> ax >> ay >> bx >> by >> binx >> biny;     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> ar[i].x >> ar[i].y;       disBin[i] = dist(binx, biny, ar[i].x, ar[i].y);       disA[i] = -disBin[i] + dist(ax, ay, ar[i].x, ar[i].y);       disB[i] = -disBin[i] + dist(bx, by, ar[i].x, ar[i].y);     }     int optimalA1 = 1, optimalA2, optimalB1 = 1, optimalB2;     double T = 0.0;     for (int i = 1; i <= n; i++) {       T += 2.0 * disBin[i];       if (disA[i] < disA[optimalA1]) {         optimalA1 = i;       }       if (disB[i] < disB[optimalB1]) {         optimalB1 = i;       }     }     optimalA2 = (optimalA1 + 1) % n;     optimalB2 = (optimalB1 + 1) % n;     for (int i = 1; i <= n; i++) {       if (disA[i] < disA[optimalA2] && i != optimalA1) {         optimalA2 = i;       }       if (disB[i] < disB[optimalB2] && i != optimalB1) {         optimalB2 = i;       }     }     if (binx == ax && biny == ay || binx == bx && biny == by) {       cout << fixed << setprecision(10) << T;       return 0;     }     if (optimalB1 == optimalA1) {       T = min(           T + disA[optimalA1],           min(T + disB[optimalB1], min(T + disA[optimalA1] + disB[optimalB2],                                        T + disA[optimalA2] + disB[optimalB1])));     } else {       T = min(T + disA[optimalA1],               min(T + disB[optimalB1], T + disA[optimalA1] + disB[optimalB1]));     }     cout << fixed << setprecision(10) << T;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long A[10][10] = {};   void rec(long long x, long long y, long long n) {     if ((n % 2) == 0) {       A[x][y] = n + 1;     }     if (n == 0)       return;     else {       long long arrx[] = {-2, 2};       long long arry[] = {-1, 1};       for (auto i : arrx) {         for (auto j : arry) {           long long newx = x + i, newy = y + j;           if (newx >= 0 && newx < 10 && newy >= 0 && newy < 10) {             {               cerr <<  >                      <<  newx                     <<  :   << newx <<   ,                      <<  newy                     <<  :   << newy << endl;             };             if (A[newx][newy] < n) rec(newx, newy, n - 1);           }         }       }       for (auto j : arrx) {         for (auto i : arry) {           long long newx = x + i, newy = y + j;           if (newx >= 0 && newx < 10 && newy >= 0 && newy < 10) {             {               cerr <<  >                      <<  newx                     <<  :   << newx <<   ,                      <<  newy                     <<  :   << newy << endl;             };             if (A[newx][newy] < n) rec(newx, newy, n - 1);           }         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       double n, h;       cin >> n >> h;       double f = h / sqrt(n);       cout << setprecision(9);       for (long long i = 0; i < n - 1; i++) {         cout << f * sqrt(i + 1) <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long K = 1;   int main() {     vector<int> ma, v;     int n, b, i, ans, x;     cin >> n >> b;     ans = b;     v.resize(n);     for (i = 0; i < n; i++) cin >> v[i];     ma.resize(n);     ma[n - 1] = v[n - 1];     for (i = n - 2; i >= 0; i--) ma[i] = max(v[i], ma[i + 1]);     for (i = 0; i < n - 1; i++) {       x = b % v[i] + b / v[i] * ma[i + 1];       if (x > ans) ans = x;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > v;   int n, m, vis[100005], in[100005], d[100005];   vector<int> e[100005];   int dfs(int i) {     vis[i] = 1;     int ans = 0;     for (auto first : e[i]) {       if (vis[first]) {         ans = max(ans, d[first]);         continue;       }       ans = max(ans, dfs(first));     }     d[i] = ans + 1;     return ans + 1;   }   bool check(int first) {     int j;     for (int i = 0; i < n; i++) {       e[i].clear();       vis[i] = 0;       in[i] = 0;       d[i] = 0;     }     for (int i = 0; i < first; i++) {       e[v[i].first].push_back(v[i].second);       in[v[i].second]++;     }     int f;     for (int i = 0; i < n; i++)       if (in[i] == 0) {         j = i;         f = dfs(i);         break;       }     return f == n;   }   void solve() {     int first, second;     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> first >> second;       first--;       second--;       v.push_back({first, second});     }     int l = 1, r = m, mid;     while (l < r) {       mid = l + (r - l) / 2;       if (check(mid))         r = mid;       else         l = mid + 1;     }     if (check(l))       cout << l <<   n ;     else       cout << -1;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool is_opening(char c) {     switch (c) {       case  ( :       case  [ :       case  { :       case  < :         return true;         break;       case  ) :       case  ] :       case  } :       case  > :         return false;         break;     }   }   bool is_match_bracket(char c1, char c2) {     if (c1 ==  (  && c2 ==  ) ) {       return true;     } else if (c1 ==  [  && c2 ==  ] ) {       return true;     } else if (c1 ==  {  && c2 ==  } ) {       return true;     } else if (c1 ==  <  && c2 ==  > ) {       return true;     }     return false;   }   int main(void) {     string str;     cin >> str;     size_t len = str.length();     int ans = 0;     stack<char> s;     bool imp = false;     for (int i = 0; i < len; ++i) {       bool is_cur_opening = is_opening(str.at(i));       if (!is_cur_opening) {         if (!s.empty() && is_opening(s.top())) {           if (!is_match_bracket(s.top(), str.at(i))) {             ++ans;           }           s.pop();         } else {           imp = true;           break;         }       } else {         s.push(str.at(i));       }     }     if (imp || !s.empty()) {       cout <<  Impossible  << endl;     } else {       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int num[5];   char board[5][10][55];   int p[] = {1, 2, 3, 0};   int main() {     for (int i = 0; i < 4; i++) cin >> num[i], num[i]--;     int cnt, ii, k;     for (int i = 0; i < 4; i++) {       for (int j = 0; j < 8; j++)         for (k = 0; k < 50; k++) board[i][j][k] = i +  A ;       for (int j = 0; j < 8 && num[p[i]]; j += 2)         for (k = 0; k < 50 && num[p[i]]; k += 2)           board[i][j][k] = p[i] +  A , num[p[i]]--;     }     cout << 32 <<     << 50 << endl;     for (int i = 0; i < 4; i++)       for (int j = 0; j < 8; j++, cout << endl)         for (int k = 0; k < 50; k++) cout << board[i][j][k];     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void read(T &x) {     x = 0;     char c = getchar();     bool f = 0;     for (; !isdigit(c); c = getchar()) f ^= c ==  - ;     for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);     x = f ? -x : x;   }   inline void readChar(char &c) {     for (c = getchar(); c <  A  || c >  E ; c = getchar())       ;   }   template <class T>   inline void write(T x) {     if (x < 0) {       putchar( - );       x = -x;     }     T y = 1;     int len = 1;     for (; y <= x / 10; y *= 10) ++len;     for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);   }   const int MAXN = 1e3;   int n, m, ans, a[MAXN + 5];   char s[MAXN + 5][MAXN + 5];   int main() {     read(n), read(m);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) readChar(s[i][j]);     for (int i = 1; i <= m; ++i) read(a[i]);     for (int i = 1; i <= m; ++i) {       int maxn = 0, tot[5] = {0};       for (int j = 1; j <= n; ++j) {         ++tot[(int)s[j][i] -  A ];         maxn = max(maxn, tot[(int)s[j][i] -  A ]);       }       ans += maxn * a[i];     }     write(ans);     putchar(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 2e18;   const double PI = acos(-1.0);   const double E = exp(1);   const double EPS = 1e-8;   const long long mod = 1e4 + 7;   const int maxn = 3e5 + 5;   void pre() {     freopen( in.txt ,  r , stdin);     freopen( out.txt ,  w , stdout);   }   struct node {     long long l, r;     bool operator<(const node &q) const { return l > q.l; }   } arr[maxn];   priority_queue<long long, vector<long long>, greater<long long> > que;   int num;   long long k1, k2;   int www;   int main(void) {     cin >> num;     scanf( %I64d%I64d , &arr[0].l, &arr[0].r);     k1 = arr[0].l, k2 = arr[0].r;     for (int i = (1); i < (num); i++) {       scanf( %I64d%I64d , &arr[i].l, &arr[i].r);     }     sort(arr, arr + num);     int rk = 0;     int nxt = 0;     for (int i = 0; i < (num); i++) {       if (arr[i].l == k1 && arr[i].r == k2) {         www = i;         if (rk == 0) rk = i + 1;         break;       } else if (arr[i].l == k1) {         if (rk == 0) rk = i + 1;       }       que.push(arr[i].r - arr[i].l + 1);     }     nxt = rk;     int pos = rk;     while (!que.empty()) {       long long cur = que.top();       if (cur <= k1)         k1 -= cur;       else         break;       que.pop();       pos--;       for (int i = (nxt); i < (num); i++) {         if (i == www) continue;         if (k1 < arr[i].l) {           que.push(arr[i].r - arr[i].l + 1);           pos++;           nxt++;         } else {           break;         }       }       rk = min(rk, pos);     }     cout << rk << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<pair<int, int> > S;   set<pair<int, int> >::iterator itr;   int n, l, r, ans;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     while (n--) {       cin >> l >> r;       itr = S.lower_bound(make_pair(l, 0));       ++ans;       vector<set<pair<int, int> >::iterator> v;       while ((itr->second) <= r && itr != S.end()) {         r = max((itr->first), r);         v.push_back(itr);         l = min(l, (itr->second));         ++itr;         --ans;       }       for (int i = 0; i < v.size(); i++) S.erase(v[i]);       S.insert(make_pair(r, l));       cout << ans <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long int dp[20][1 << 20];   long long int len[1 << 21] = {0};   std::vector<int> v[1000000];   int n;   int r[21][21];   long long int solve(int last, int mask, int pa) {     long long int sol = 0;     if (r[last][pa] == 1 && len[mask] >= 3) {       sol += 1;     }     if (dp[last][mask]) {       return dp[last][mask];     }     for (int i = 0; i < v[last].size(); i++) {       if ((mask & (1 << v[last][i])) == 0 && v[last][i] > pa) {         sol += solve(v[last][i], mask | (1 << v[last][i]), pa);       }     }     return dp[last][mask] = sol;   }   int main() {     int x, y, m;     cin >> n >> m;     while (m--) {       cin >> x >> y;       x--;       y--;       v[x].push_back(y);       v[y].push_back(x);       r[x][y] = 1;       r[y][x] = 1;     }     for (int i = 1; i <= (1 << (n)); i++) {       x = 0;       for (int j = 0; j < n; j++) {         if ((i >> j) & 1) x++;       }       len[i] = x;     }     long long int sol = 0;     for (int i = 0; i < n; i++) {       sol += solve(i, 0 | (1 << i), i);     }     cout << fixed;     cout << setprecision(0) << sol / 2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100 * 1000 + 7, MAX_LOG = 20;   int n, m;   vector<int> adj[MAXN];   bool isPassed[MAXN];   int par[MAXN][MAX_LOG], cycleCnt[MAXN], h[MAXN];   void pre(int root) {     isPassed[root] = true;     for (auto nei : adj[root]) {       if (!isPassed[nei]) {         par[nei][0] = root;         h[nei] = h[root] + 1;         pre(nei);         cycleCnt[root] = cycleCnt[root] + cycleCnt[nei];       } else if (par[root][0] != nei and h[nei] < h[root]) {         cycleCnt[nei]--;         cycleCnt[root]++;       }     }     return;   }   int nanCyCnt[MAXN][MAX_LOG];   void dfs(int root, int lstRt) {     par[root][0] = lstRt;     if (lstRt != -1 and cycleCnt[root] == 0) nanCyCnt[root][0] = 1;     for (int i = 1; i < MAX_LOG and h[root] >= (1 << i) and                     par[par[root][i - 1]][i - 1] != -1;          ++i) {       par[root][i] = par[par[root][i - 1]][i - 1];       nanCyCnt[root][i] =           nanCyCnt[root][i - 1] + nanCyCnt[par[root][i - 1]][i - 1];     }     isPassed[root] = true;     for (auto nei : adj[root]) {       if (!isPassed[nei]) {         h[nei] = h[root] + 1;         dfs(nei, root);       }     }     return;   }   int lca(int v, int u) {     int nancy = 0;     if (h[v] > h[u]) swap(v, u);     for (int i = 0; h[v] ^ h[u]; ++i) {       if ((h[u] - h[v]) & (1 << i)) {         nancy += nanCyCnt[u][i];         u = par[u][i];       }     }     if (v == u) return nancy;     for (int i = MAX_LOG - 1; i >= 0; --i) {       if (par[v][i] != par[u][i]) {         nancy += (nanCyCnt[v][i] + nanCyCnt[u][i]);         v = par[v][i], u = par[u][i];       }     }     return nancy + nanCyCnt[v][0] + nanCyCnt[u][0];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     memset(par, -1, sizeof par);     cin >> n >> m;     for (int i = 0; i < m; ++i) {       int v, u;       cin >> v >> u, v--, u--;       adj[v].push_back(u);       adj[u].push_back(v);     }     memset(isPassed, 0, sizeof isPassed);     pre(0);     memset(isPassed, 0, sizeof isPassed);     memset(h, 0, sizeof h);     dfs(0, -1);     int mercsNum;     cin >> mercsNum;     while (mercsNum--) {       int sh, wa;       cin >> wa >> sh, wa--, sh--;       cout << lca(wa, sh) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int m;     int count[200005][2];     cin >> m;     while (m--) {       int n, a, b;       long long T;       cin >> n >> T >> a >> b;       vector<pair<int, int> > problems(n + 1);       for (int i = 1; i <= n; i++) {         cin >> problems[i].second;       }       for (int i = 1; i <= n; i++) {         cin >> problems[i].first;       }       sort(problems.begin(), problems.end());       count[0][0] = 0;       count[0][1] = 0;       for (int i = 1; i <= n; i++) {         count[i][problems[i].second] = count[i - 1][problems[i].second] + 1;         count[i][problems[i].second ^ 1] = count[i - 1][problems[i].second ^ 1];       }       long long curr = 0;       int res = 0;       for (int i = 1; i <= n; i++) {         long long spare = problems[i].first - 1 - curr;         curr += problems[i].second ? b : a;         if (spare < 0) continue;         int res1 = i - 1;         if (spare)           for (int type = 0; type <= 1; type++) {             long long currCount = count[n][type] - count[i - 1][type];             int solvable = min(spare / (type ? b : a), currCount);             res1 += solvable;             spare -= solvable * (type ? b : a);           }         res = max(res, res1);       }       if (T >= curr)         cout << n << endl;       else         cout << res << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<long long int> v;     for (int i = 1; i <= n; i++) {       long long int a;       cin >> a;       v.push_back(a);     }     sort(v.begin(), v.end());     long long int total = 0;     int cnt = 0;     for (int i = 0; i < v.size(); i++) {       total += v[i];       if (total - v[i] <= v[i])         ++cnt;       else         total -= v[i];     }     cout << cnt << endl;   }


#include<bits/stdc++.h>      #define ll long long   #define MAX 1000006   #define gcd(a, b)           __gcd(a, b)   #define lcm(a, b)           ((a)*((b)/gcd(a,b)))   using namespace std;         //******************* my code starts here **********************************      int main()   {   int t;      cin>>t;   getchar();      while(t--)   {        //ll i,x1,n,k,m;                  vector<ll>v;            vector<int>v1;            vector<pair<int,int>>pir;               string s,s1;            ll a,b,coun=0,new_coun=0,ans=0;            cin>>a>>b;               if(a<b)            {                cout<< 1 <<endl;                continue;            }              ll sqr=sqrt(a),minn=INT_MAX;               for(int i=0;i<=sqr;i++)            {                if(i==0 and b==1)                {                    continue;                }                   int check=b+i;                 coun =i;                int temp=a;                   while(temp != 0)                {                    temp/=check;                    coun++;                }                   minn=min(minn,coun);            }               cout<<minn<<endl;                              }                     return 0;      }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 50;   inline int rd(register int x = 0, register char ch = getchar(),                 register int f = 0) {     for (; ch <  0  || ch >  9 ; ch = getchar()) f = ch ==  - ;     for (; ch >=  0  && ch <=  9 ; ch = getchar())       x = (x << 1) + (x << 3) + ch - 48;     return f ? -x : x;   }   int n, m, cnt;   int a[N], pre[N], A[N], fr[N];   long long val[N], bit[N];   set<int> Set[N];   struct node {     int t, x, y, val, op;   } q[N * 4], p[N * 4];   bool cmp(node a, node b) { return a.t < b.t; }   void add(int p, int v) {     p += 5;     for (; p <= n + 5; p += p & -p) bit[p] += v;   }   long long ask(int p, long long a = 0) {     p += 5;     if (p <= 0) return 0;     for (; p; p -= p & -p) a += bit[p];     return a;   }   void cdq(int l, int r) {     if (l >= r) return;     int mid = (l + r) >> 1, pl = l, pr = mid + 1, pp = l;     cdq(l, mid), cdq(mid + 1, r);     while (pl <= mid && pr <= r) {       if (q[pl].x <= q[pr].x)         p[pp] = q[pl++], fr[pp++] = 1;       else         p[pp++] = q[pr++];     }     while (pl <= mid) p[pp] = q[pl++], fr[pp++] = 1;     while (pr <= r) p[pp++] = q[pr++];     for (int pos = l; pos <= r; ++pos) {       if (fr[pos] && !p[pos].op)         add(p[pos].y, p[pos].val);       else if (!fr[pos] && p[pos].op)         val[p[pos].op] += ask(n) - ask(p[pos].y - 1);     }     for (int pos = l; pos <= r; ++pos) {       q[pos] = p[pos];       if (fr[pos] && !p[pos].op) add(p[pos].y, -p[pos].val);       fr[pos] = 0;     }   }   int main() {     n = rd(), m = rd();     for (int i = 1; i <= n; ++i) {       a[i] = rd();       if (Set[a[i]].size()) pre[i] = *--Set[a[i]].end();       Set[a[i]].insert(i);       q[++cnt] = (node){0, i, pre[i], i - pre[i], 0};     }     for (int r = 1; r <= m; ++r) {       A[r] = rd();       int b = rd(), c = rd();       if (A[r] == 1) {         q[++cnt] = (node){r, b, pre[b], pre[b] - b, 0};         if (next(Set[a[b]].find(b)) != Set[a[b]].end()) {           int pos = *next(Set[a[b]].find(b));           q[++cnt] = (node){r, pos, pre[pos], pre[pos] - pos, 0};           pre[pos] = pre[b];           q[++cnt] = (node){r, pos, pre[pos], pos - pre[pos], 0};         }         Set[a[b]].erase(b);         a[b] = c;         pre[b] = 0;         Set[a[b]].insert(b);         if (Set[a[b]].find(b) != Set[a[b]].begin())           pre[b] = *prev(Set[a[b]].find(b));         q[++cnt] = (node){r, b, pre[b], b - pre[b], 0};         if (next(Set[a[b]].find(b)) != Set[a[b]].end()) {           int pos = *next(Set[a[b]].find(b));           q[++cnt] = (node){r, pos, pre[pos], pre[pos] - pos, 0};           pre[pos] = b;           q[++cnt] = (node){r, pos, pre[pos], pos - pre[pos], 0};         }       } else         q[++cnt] = (node){r, c, b, 0, r};     }     cdq(1, cnt);     for (int i = 1; i <= m; ++i)       if (A[i] == 2) printf( %lld n , val[i]);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, k;     cin >> n >> k;     int answer = 1;     while (k % 2 == 0) {       k /= 2;       answer++;     }     cout << answer;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct STree {     vector<int> st;     int n;     STree(int n) : st(4 * n + 5, 0), n(n) {}     void upd(int k, int s, int e, int p, int v) {       if (s + 1 == e) {         st[k] = v;         return;       }       int m = (s + e) / 2;       if (p < m)         upd(2 * k, s, m, p, v);       else         upd(2 * k + 1, m, e, p, v);       st[k] = (st[2 * k] | st[2 * k + 1]);     }     int query(int k, int s, int e, int pos, int v) {       if (e - 1 < pos) return -1;       if (s >= pos) {         if (!(st[k] & v)) return -1;         if (s + 1 == e) return s;       }       int m = (s + e) / 2;       int ans = query(2 * k, s, m, pos, v);       if (ans == -1) ans = query(2 * k + 1, m, e, pos, v);       return ans;     }     void upd(int p, int v) { upd(1, 0, n, p, v); }     int query(int a, int b) { return query(1, 0, n, a, b); }   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       string s;       int n, k;       cin >> n >> k >> s;       vector<int> a(n);       int ne = n / 2 - k;       for (int i = 0, ThxDem = 2 * (k - 1); i < ThxDem; ++i) a[i] = i % 2;       for (int i = 2 * (k - 1), ThxDem = n; i < ThxDem; ++i)         a[i] = i - 2 * (k - 1) > ne;       STree st(n);       for (int i = 0, ThxDem = n; i < ThxDem; ++i) st.upd(i, 1 << (s[i] ==  ) ));       cout << n <<   n ;       for (int i = 0, ThxDem = n; i < ThxDem; ++i) {         int wh = st.query(i, 1 << a[i]);         swap(s[i], s[wh]);         st.upd(i, 1 << (s[i] ==  ) ));         st.upd(wh, 1 << (s[wh] ==  ) ));         cout << i + 1 <<     << wh + 1 <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> v[3001];   long long visited[3001][3001];   long long poss[3001];   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, m, k;     cin >> n >> m >> k;     pair<long long, long long> parent[n + 1][n + 1];     for (long long i = 0; i < m; i++) {       long long a, b;       cin >> a >> b;       v[a].push_back(b);       v[b].push_back(a);     }     set<tuple<long long, long long, long long>> s;     for (long long i = 0; i < k; i++) {       long long a, b, c;       cin >> a >> b >> c;       s.insert({a, b, c});     }     queue<pair<long long, long long>> q;     q.push({1, 1});     visited[1][1] = 1;     parent[1][1] = {-1, -1};     poss[1] = 1;     pair<long long, long long> last = {-1, -1};     while (!q.empty()) {       pair<long long, long long> node = q.front();       if (node.second == n) {         last = {node};         break;       }       q.pop();       for (auto c : v[node.second]) {         if (visited[node.second][c] == 0 &&             !s.count({node.first, node.second, c})) {           parent[node.second][c] = node;           visited[node.second][c] = visited[node.first][node.second] + 1;           poss[c] = 1;           q.push({node.second, c});         }       }     }     if (poss[n]) {       vector<long long> ans;       pair<long long, long long> start = last;       while ((parent[start.first][start.second]) != parent[1][1]) {         ans.push_back(start.second);         start = parent[start.first][start.second];       }       ans.push_back(start.second);       reverse(ans.begin(), ans.end());       cout << ans.size() - 1 <<   n ;       for (auto c : ans) cout << c <<    ;     } else       cout << -1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e5 + 6;   const long long MOD = 1e9 + 7;   int a[56];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, cnt = 0, mn = 50;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       mn = min(mn, a[i]);     }     for (int i = 0; i < n; i++)       if (a[i] == mn) cnt++;     if (cnt <= n / 2)       cout <<  Alice ;     else       cout <<  Bob ;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   struct sch {     long long int s, e, t;   };   bool sortinrev(const struct sch &a, const struct sch &b) { return (a.s < b.s); }   vector<long long int> graph[200010];   vector<long long int> graphr[200010];   long long int vis[200010], visf[200010], visr[200010];   char ans[200010];   int flag;   void cycle(long long int cur) {     if (!flag) return;     vis[cur] = 1;     for (long long int i = 0; i < graph[cur].size(); i++) {       long long int u = graph[cur][i];       if (vis[u] == 1) {         flag = 0;         return;       } else if (vis[u] == 2) {         continue;       } else {         cycle(u);       }     }     vis[cur] = 2;     return;   }   void dfs_front(long long int cur, long long int s) {     visf[cur] = 1;     for (long long int i = 0; i < graph[cur].size(); i++) {       long long int u = graph[cur][i];       if (visf[u] == 1) {         continue;       }       if (ans[u] ==  z ) ans[u] =  E ;       dfs_front(u, s);     }   }   void dfs_back(long long int cur, long long int s) {     visr[cur] = 1;     for (long long int i = 0; i < graphr[cur].size(); i++) {       long long int u = graphr[cur][i];       if (visr[u] == 1) {         continue;       }       if (ans[u] ==  z ) ans[u] =  E ;       dfs_back(u, s);     }   }   int main() {     long long int n, m;     cin >> n >> m;     flag = 1;     for (long long int i = 0; i < n; i++) ans[i] =  z ;     for (long long int i = 0; i < m; i++) {       long long int u, v;       cin >> u >> v;       graph[u - 1].push_back(v - 1);       graphr[v - 1].push_back(u - 1);     }     for (long long int i = 0; i < n; i++) {       if (!vis[i]) cycle(i);     }     if (flag == 0) {       cout << -1 << endl;       return 0;     }     memset(visf, 0, sizeof(visf));     memset(visr, 0, sizeof(visr));     for (long long int i = 0; i < n; i++) {       if (ans[i] ==  z ) {         ans[i] =  A ;         dfs_front(i, i);         dfs_back(i, i);       } else if (ans[i] ==  E ) {         if (visf[i] == 0) dfs_front(i, i);         if (visr[i] == 0) dfs_back(i, i);       }     }     long long int cnt = 0;     for (long long int i = 0; i < n; i++) {       if (ans[i] ==  A ) cnt++;     }     cout << cnt << endl;     for (long long int i = 0; i < n; i++) {       cout << ans[i];     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <typename U, typename V>   inline void smax(U &a, const V &b) {     if (a < b) a = b;   }   const long long INF = 0x3f3f3f3f3f3f3f3fLL;   const double pi = acosl(-1.), eps = 1e-9;   const int NN = 1010;   int hd[NN];   int nx[NN << 1];   int to[NN << 1];   int E;   void add(int u, int v) {     nx[E] = hd[u];     to[E] = v;     hd[u] = E++;     nx[E] = hd[v];     to[E] = u;     hd[v] = E++;   }   int flag[NN];   int father[NN];   int id[NN];   int crr_dp, crr_id;   pair<int, int> p[NN];   void dfs(int u, int dp = 0, int key = 1) {     flag[u] = key;     if (crr_dp < dp) {       crr_id = u;       crr_dp = dp;     }     for (int e = hd[u]; ~e; e = nx[e]) {       int v = to[e];       if (flag[v] == key) continue;       father[v] = u;       dfs(v, dp + 1, key);     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     memset(hd, -1, sizeof(hd));     for (int i = 0, u, v; i < m; i++) {       scanf( %d%d , &u, &v);       add(u, v);     }     m = 0;     for (int i = 1, u, v; i <= n; i++) {       if (!flag[i]) {         crr_dp = -1;         dfs(i);         crr_dp = -1;         dfs(u = crr_id, 0, 2);         v = crr_id;         for (int j = 0; j < crr_dp / 2; j++) {           v = father[v];         }         p[m++] = pair<int, int>(crr_dp, v);       }     }     sort(p, p + m,          [](pair<int, int> a, pair<int, int> b) { return a.first > b.first; });     int dia = p[0].first;     if (m > 1) smax(dia, (p[0].first + 1 >> 1) + 1 + (p[1].first + 1 >> 1));     if (m > 2) smax(dia, (p[1].first + 1 >> 1) + 2 + (p[2].first + 1 >> 1));     printf( %d n , dia);     for (int i = 1; i < m; i++) {       printf( %d %d n , p[0].second, p[i].second);     }     return 0;   }


#include <bits/stdc++.h>   int N, M, K, MOD;   int dp[200][200][200];   int C[200][200];   int fac[200];   __attribute__((optimize( -O3 ))) __attribute__((optimize( -O3 ))) __inline       __attribute__((__gnu_inline__, __always_inline__, __artificial__)) int       calc(int n, int m, int k) {     if (n == 0) {       if (k == 0) return dp[n][m][k] = 1 % MOD;       return dp[n][m][k] = 0;     }     if (n == 1) {       if (m == 1 && k == 1) return dp[n][m][k] = 1 % MOD;       if (m > 1 && k == 0) return dp[n][m][k] = 1 % MOD;       return dp[n][m][k] = 0;     }     if (m == 1) {       if (k == 1) {         return dp[n][m][k] = fac[n];       }       return dp[n][m][k] = 0;     }     if (m > n) {       if (k == 0) {         return dp[n][m][k] = fac[n];       }       return dp[n][m][k] = 0;     }     int ans = 0;     for (int ln = 0; ln + 1 <= n; ++ln) {       if (m - 1 > ln) {         int lk = 0;         int rn = n - ln - 1, rk = k - lk;         ans += 1ll * dp[ln][m - 1][lk] * dp[rn][m - 1][rk] % MOD * C[n - 1][ln] %                MOD;         if (ans >= MOD) ans -= MOD;         continue;       }       if (m - 1 > n - ln - 1 && k <= ln) {         int lk = k;         int rn = n - ln - 1, rk = k - lk;         ans += 1ll * dp[ln][m - 1][lk] * dp[rn][m - 1][rk] % MOD * C[n - 1][ln] %                MOD;         if (ans >= MOD) ans -= MOD;         continue;       }       for (int lk = std::max(0, k - (n - ln - 1)); lk <= std::min(ln, k); ++lk) {         int rn = n - ln - 1, rk = k - lk;         ans += 1ll * dp[ln][m - 1][lk] * dp[rn][m - 1][rk] % MOD * C[n - 1][ln] %                MOD;         if (ans >= MOD) ans -= MOD;       }     }     return dp[n][m][k] = ans;   }   __attribute__((optimize( -O3 ))) int main() {     scanf( %d%d%d%d , &N, &M, &K, &MOD);     for (int i = 1; i <= N; ++i) {       C[i][0] = C[i][i] = 1 % MOD;       for (int j = 1; j <= i - 1; ++j)         C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;     }     fac[0] = 1;     for (int i = 1; i <= N; ++i) fac[i] = 1ll * fac[i - 1] * i % MOD;     for (int i = 0; i <= N; ++i)       for (int j = 0; j <= std::min(N, M); ++j)         for (int k = 0; k <= std::min(i, K); ++k) {           calc(i, j, k);         }     printf( %d n , dp[N][M][K]);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, a, b;     cin >> n >> a >> b;     long long int m = 0;     for (long long int i = 1; i < n; i++) {       long long int q = i;       long long int w = n - i;       long long int ca = a / q, cb = b / w;       if (min(ca, cb) > m) m = min(ca, cb);     }     cout << m;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int L, v, l, r, d;       cin >> L >> v >> l >> r;       if (r == l && r % v == 0)         d = 1;       else         d = r / v - (l - 1) / v;       cout << L / v - d <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   ostream& operator<<(ostream& os, const vector<T>& v) {     for (auto i = begin(v); i != end(v); i++)       os << *i << (i == end(v) - 1 ?    :    );     return os;   }   template <class T>   istream& operator>>(istream& is, vector<T>& v) {     for (auto i = begin(v); i != end(v); i++) is >> *i;     return is;   }   vector<vector<int>> g;   vector<int> visited;   vector<int> bad_parents;   bool total_stop = false;   int full_bt_depth(int i) {     visited[i] = true;     vector<int> sizes;     for (int u : g[i]) {       if (visited[u]) continue;       sizes.push_back(full_bt_depth(u));     }     if (sizes.size() == 0) return 1;     if (sizes.size() == 1) {       if (sizes[0] != 1) total_stop = true;       bad_parents.push_back(i);       return -1;     }     if (sizes.size() == 2) {       if (sizes[0] == sizes[1] && sizes[0] != -1) {         return sizes[0] + 1;       }       if (sizes[0] == -1 && sizes[1] == -1) total_stop = true;       return -1;     }     if (sizes.size() == 3) {       sort((sizes).begin(), (sizes).end());       if (sizes[0] == sizes[1] && (sizes[1] + 1) == sizes[2]) {         bad_parents.push_back(i);         return -1;       }     }     total_stop = true;     return -1;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     if (n == 2) {       cout <<  2 n 1 2 ;       return 0;     }     int n_vtx = (1 << n) - 1;     g.resize(n_vtx);     visited.resize(n_vtx);     int first_a = -1, first_b = -1;     for (int i = 0; i < (n_vtx - 2); i++) {       int a, b;       cin >> a >> b;       if (first_a == -1) first_a = a;       if (first_b == -1) first_b = b;       a--, b--;       g[a].push_back(b);       g[b].push_back(a);     }     queue<int> leaves;     for (int i = 0; i < n_vtx; i++) {       if (g[i].size() == 1) {         leaves.push(i);         visited[i] = true;       }     }     vector<int> last_row;     while (leaves.size() > 0) {       int sz = leaves.size();       last_row.clear();       while (sz-- > 0) {         int q = leaves.front();         leaves.pop();         last_row.push_back(q);         for (int u : g[q]) {           visited[u]++;           if (visited[u] + 1 == g[u].size()) {             leaves.push(u);           }         }       }     }     for (int x : last_row) {       visited.assign(visited.size(), 0);       full_bt_depth(x);     }     if (total_stop || bad_parents.size() == 0) {       cout << 0;       return 0;     } else {       sort((bad_parents).begin(), (bad_parents).end());       cout << bad_parents.size() <<   n ;       for (int u : bad_parents) cout << u + 1 <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const int N = 100010;   int n, k, m;   int a[N];   int main() {     ios_base::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     int cnt = 0;     while (k > 0) {       cnt += 1;       k -= cnt;     }     cout << a[k + cnt];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int vis[200005];   pair<int, int> seg[200005];   vector<pair<int, pair<int, int> > > v;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long m, n, i, j, t, x, y, w, k, l, r;     cin >> n >> k;     for (i = 0; i < n; i++) {       cin >> l >> r;       v.push_back({l, {i, 1}});       v.push_back({r + 1, {i, -1}});       seg[i].first = l;       seg[i].second = r + 1;     }     sort(v.begin(), v.end());     vector<int> ans;     priority_queue<pair<int, int> > pq;     int count = 0;     for (i = 0; i < v.size();) {       x = v[i].first;       while (i < v.size() && x == v[i].first) {         if (vis[v[i].second.first]) {           i++;           continue;         }         if (v[i].second.second == 1) {           pq.push({seg[v[i].second.first].second, v[i].second.first});         }         count += v[i].second.second;         i++;       }       if (count > k) {         int rem = count - k;         count = k;         while (true) {           if (vis[pq.top().second] == 1) {             pq.pop();             continue;           }           rem--;           ans.push_back(pq.top().second);           vis[pq.top().second] = 1;           pq.pop();           if (rem == 0) break;         }       }     }     cout << ans.size() <<   n ;     sort(ans.begin(), ans.end());     for (auto x : ans) {       cout << x + 1 <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long niz[1000000];   long long kum[1000000];   int main() {     ios_base::sync_with_stdio(false);     cout.precision(10);     cout << fixed;     int n, s, f;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> niz[i];     }     cin >> s >> f;     long long s1, f1;     for (int i = 1; i <= n; i++) {       s1 = s - i + 1;       if (s1 <= 0) s1 += n;       f1 = f - i + 1;       ;       if (f1 <= 0) f1 += n;       if (s1 > f1) {         kum[1] += niz[i];         kum[f1] -= niz[i];         kum[s1] += niz[i];       } else {         kum[s1] += niz[i];         kum[f1] -= niz[i];       }     }     kum[0] = 0;     long long maxi = 0;     for (int i = 1; i <= n; i++) {       kum[i] = kum[i] + kum[i - 1];       maxi = max(maxi, kum[i]);     }     for (int i = 1; i <= n; i++) {       if (kum[i] == maxi) {         cout << i;         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 5;   const long long int inf64 = 1e18 + 5;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, i;     pair<long long int, long long int> fr;     cin >> n;     vector<pair<long long int, long long int> > v;     cin >> fr.first >> fr.second;     for (i = 0; i < n - 1; i++) {       long long int a, b;       cin >> a >> b;       v.push_back({a, b});     }     sort(v.begin(), v.end(), greater<pair<long long int, long long int> >());     int ans = 0;     for (i = 0; i < n - 1; i++) {       if (v[i].first <= fr.first) break;       ++ans;     }     priority_queue<long long int, vector<long long int>, greater<long long int> >         pq;     for (int i = 0, j = 0; i < v.size(); i = j) {       while (j < v.size() && v[j].first > fr.first) {         pq.push(v[j].second - v[j].first + 1);         ++j;       }       if (pq.empty()) break;       ans = min(ans, (int)pq.size());       long long int p = pq.top();       if (p > fr.first) break;       pq.pop();       fr.first -= p;     }     ans = min(ans, (int)pq.size());     while (!pq.empty() && fr.first >= pq.top()) {       fr.first -= pq.top();       pq.pop();       ans = min(ans, (int)pq.size());     }     cout << ans + 1;   }


#include <bits/stdc++.h>   using namespace std;   void print(int x) { cerr << x; }   void print(long x) { cerr << x; }   void print(long long x) { cerr << x; }   void print(unsigned x) { cerr << x; }   void print(unsigned long x) { cerr << x; }   void print(unsigned long long x) { cerr << x; }   void print(float x) { cerr << x; }   void print(double x) { cerr << x; }   void print(long double x) { cerr << x; }   void print(char x) { cerr <<      << x <<     ; }   void print(const char *x) { cerr <<     << x <<    ; }   void print(const string &x) { cerr <<     << x <<    ; }   void print(bool x) { cerr << (x ?  true  :  false ); }   const long long int MOD = 1e9 + 7;   const long long int INF = 1e18;   const long long int maxn = 1e6 + 4;   void answer() {     long long int a;     cin >> a;     vector<long long int> v;     long long int sum = 0;     for (long long int i = 0; i < a; ++i) {       long long int temp;       cin >> temp;       v.push_back(temp);       sum += temp;     }     long long int k = sum / a;     long long int ans = 0;     if (a == 1) {       cout << 0;     } else {       for (long long int i = 0; i < a - 1; ++i) {         if (v[i] < k) {           long long int real = k - v[i];           ans += real;           v[i + 1] -= real;           v[i] = k;         } else {           long long int real = v[i] - k;           ans += real;           v[i + 1] += real;           v[i] = k;         }       }       cout << ans;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t-- > 0) {       answer();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char str1[10], str2[10], str3[10];     int flag1, flag2, flag3;     flag1 = 0;     flag2 = 0;     flag3 = 0;     cin >> str1 >> str2 >> str3;     if (strcmp(str1, str2) == 0) {       flag1 = 1;     } else if (strcmp(str2, str3) == 0) {       flag2 = 1;     } else if (strcmp(str3, str1) == 0) {       flag3 = 1;     }     if ((flag1 | flag2 | flag3) == 0) {       cout <<  ?  << endl;       return 0;     }     if ((flag1 & flag2 & flag3) == 1) {       cout <<  ?  << endl;       return 0;     }     if (flag1 == 1) {       if (strcmp(str3,  rock ) == 0) {         if (strcmp(str2,  scissors ) == 0) {           cout <<  S  << endl;           return 0;         }       }       if (strcmp(str3,  scissors ) == 0) {         if (strcmp(str2,  paper ) == 0) {           cout <<  S  << endl;           return 0;         }       }       if (strcmp(str3,  paper ) == 0) {         if (strcmp(str2,  rock ) == 0) {           cout <<  S  << endl;           return 0;         }       }     }     if (flag2 == 1) {       if (strcmp(str1,  rock ) == 0) {         if (strcmp(str2,  scissors ) == 0) {           cout <<  F  << endl;           return 0;         }       }       if (strcmp(str1,  scissors ) == 0) {         if (strcmp(str2,  paper ) == 0) {           cout <<  F  << endl;           return 0;         }       }       if (strcmp(str1,  paper ) == 0) {         if (strcmp(str2,  rock ) == 0) {           cout <<  F  << endl;           return 0;         }       }     }     if (flag3 == 1) {       if (strcmp(str2,  rock ) == 0) {         if (strcmp(str3,  scissors ) == 0) {           cout <<  M  << endl;           return 0;         }       }       if (strcmp(str2,  scissors ) == 0) {         if (strcmp(str3,  paper ) == 0) {           cout <<  M  << endl;           return 0;         }       }       if (strcmp(str2,  paper ) == 0) {         if (strcmp(str3,  rock ) == 0) {           cout <<  M  << endl;           return 0;         }       }     }     cout <<  ?  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a[3010], x, y, c[100], d[100], n, l, r, time, count = 0, p, q, i, j;     scanf( %d%d%d%d , &p, &q, &l, &r);     memset(a, 0, sizeof(a));     while (p--) {       scanf( %d%d , &x, &y);       for (i = x; i <= y; i++) a[i]++;     }     for (i = 0; i < q; i++) {       scanf( %d%d , &c[i], &d[i]);     }     for (time = l; time <= r; time++) {       for (i = 0; i < q; i++) {         int flag = 0;         for (j = c[i] + time; j <= d[i] + time; j++) {           if (a[j] > 0) {             count++;             flag++;             break;           }         }         if (flag > 0) {           break;         }       }     }     printf( %d n , count);     return 0;   }


#include <bits/stdc++.h>   std::priority_queue<std::pair<long long, int> > que;   long long dis[2005];   int w[2005][2005];   int main() {     int n, mn = 1e9;     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) {       for (int j = 1; j < n - i; j++) {         int x;         scanf( %d , &x);         w[i][i + j] = w[i + j][i] = x;         mn = std::min(mn, x);       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i != j) w[i][j] -= mn;       }     }     for (int i = 0; i < n; i++) {       dis[i] = 1e18;       for (int j = 0; j < n; j++) {         if (i != j) dis[i] = std::min(dis[i], (long long)w[i][j] << 1);       }       que.push(std::make_pair(-dis[i], i));     }     while (!que.empty()) {       long long d = -que.top().first;       int u = que.top().second;       que.pop();       if (dis[u] != d) continue;       for (int v = 0; v < n; v++) {         if (u != v && d + w[u][v] < dis[v]) {           dis[v] = d + w[u][v];           que.push(std::make_pair(-dis[v], v));         }       }     }     for (int i = 0; i < n; i++)       printf( %lld n , (long long)(n - 1) * mn + dis[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve();   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     solve();     return 0;   }   long long ar[3];   void solve() {     long long x, y, ans = 0;     cin >> x >> y;     ar[0] = ar[1] = ar[2] = y;     while (ar[0] < x || ar[1] < x || ar[2] < x) {       sort(ar, ar + 3);       ar[0] = ar[1] + ar[2] - 1;       ans++;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   typedef class Point {    public:     double x, y;     Point(double x = 0.0, double y = 0.0) : x(x), y(y) {}   } Point, Vector;   Point operator-(Point a, Point b) { return Point(a.x - b.x, a.y - b.y); }   double cross(Vector u, Vector v) { return u.x * v.y - u.y * v.x; }   int n;   Point *ps;   inline void init() {     scanf( %d , &n);     ps = new Point[(n + 1)];     for (int i = 1; i <= n; i++) scanf( %lf%lf , &ps[i].x, &ps[i].y);   }   int cnt = 0;   long long res = 0;   pair<double, int> *ar;   bool *vis;   int getNext(int p) {     if (p == cnt) return 1;     return p + 1;   }   inline void solve() {     vis = new bool[(n + 1)];     ar = new pair<double, int>[(n + 1)];     for (int i = 1; i <= n; i++) {       cnt = 0;       for (int j = 1; j <= n; j++)         if (j ^ i) {           Vector dif = ps[j] - ps[i];           ar[++cnt] = make_pair(atan2(dif.y, dif.x), j);         }       sort(ar + 1, ar + cnt + 1);       int p = 1, cntl = 0;       memset(vis, false, sizeof(bool) * (n + 1));       for (int j = 1; j < n; j++) {         Vector dif = ps[ar[j].second] - ps[i];         for (int np = getNext(p);              np != j && cross(dif, ps[ar[np].second] - ps[i]) > 0;              p = np, np = getNext(np))           cntl += !vis[np], vis[np] = true;         res = res + cntl * 1ll * (cntl - 1) / 2 * (n - cntl - 2) * 1ll *                         (n - cntl - 3) / 2;         int np = ar[getNext(j)].second, nj = getNext(j);         if (cross(dif, ps[np] - ps[i]) > 0)           cntl--, vis[nj] = false;         else {           if (p == j) p = getNext(j);         }       }     }     cout << (res >> 1) << endl;   }   int main() {     init();     solve();     return 0;   }


#include <bits/stdc++.h>   // #include <ext/pb_ds/assoc_container.hpp>   // #include <ext/pb_ds/tree_policy.hpp>   using namespace std;   // using namespace __gnu_pbds;   #define lli long long int   #define llu unsigned long long int   #define pb push_back   #define rt return 0   #define endln   n    #define all(x) x.begin(), x.end()   #define sz(x) (lli)(x.size())   const lli MOD = 1e9 + 7;   const double PI = 2 * acos(0.0);   // cout << fixed << setprecision(0) << pi <<endl;   // typedef tree<int, null_type, less<int>, rb_tree_tag,   //              tree_order_statistics_node_update>   //     new_data_set;   // for multiset   // typedef tree<int, null_type, less_equal<int>, rb_tree_tag,   //              tree_order_statistics_node_update>   //     new_data_set;   // order_of_key(val): returns the number of values less than val   // find_by_order(k): returns an iterator to the kth largest element (0-based)      void solve() {       lli n, a;       cin >> n >> a;       cout << n - 1 <<     << a << endl;   }      int main(void) {       ios::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);       lli t;       cin >> t;       while (t--)           solve();       rt;   }


#include <bits/stdc++.h>   using namespace std;   long long make(long long n) {     if (n % 4 == 3) return 0;     if (n % 4 == 0) return n;     if (n % 4 == 1) return 1;     if (n % 4 == 2) return (n ^ 1);   }   int main() {     long long n;     cin >> n;     long long i, nim = 0;     for (i = 0; i < n; i++) {       long long a, b;       cin >> a >> b;       nim ^= (make(a - 1) ^ make(a + b - 1));     }     if (nim != 0)       cout <<  tolik ;     else       cout <<  bolik ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int p = 0; p < t; ++p) {       int n;       cin >> n;       int d[2][n];       for (int i = 0; i <= 1; ++i) {         for (int j = 0; j < n; ++j) cin >> d[i][j];       }       if (n == 1)         cout << 0 << endl;       else {         int suff[n], pref[n];         suff[0] = 0;         pref[0] = 0;         for (int i = 1; i < n; ++i) {           suff[i] = d[0][n - i] + suff[i - 1];           pref[i] = d[1][i - 1] + pref[i - 1];         }         int res = 2e9;         for (int i = 0; i < n; ++i) {           res = min(res, max(suff[n - 1 - i], pref[i]));         }         cout << res << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long p = 1e9 + 7;   struct aaa {     long long x, y;   } a[200010];   long long n, ans = 1, sz[500010], fa[500010], v[500010], fac[500010],                aa[500010], bb[500010], cnt0, cnt1;   map<long long, long long> mp0, mp1;   long long find(long long x) {     if (x == fa[x]) return x;     return fa[x] = find(fa[x]);   }   int main() {     long long i, x, y;     scanf( %lld , &n);     fac[0] = 1;     for (i = 1; i <= n * 2; i++) fac[i] = fac[i - 1] * 2 % p;     for (i = 1; i <= n; i++) {       scanf( %lld%lld , &a[i].x, &a[i].y);       aa[i] = a[i].x;       bb[i] = a[i].y;     }     sort(aa + 1, aa + n + 1);     sort(bb + 1, bb + n + 1);     for (i = 1; i <= n; i++) {       if (i == 1 || aa[i] != aa[i - 1]) mp0[aa[i]] = ++cnt0;     }     for (i = 1; i <= n; i++) {       if (i == 1 || bb[i] != bb[i - 1]) mp1[bb[i]] = ++cnt1;     }     for (i = 1; i <= cnt0 + cnt1; i++) fa[i] = i, sz[i] = 1;     for (i = 1; i <= n; i++) {       x = find(mp0[a[i].x]);       y = find(cnt0 + mp1[a[i].y]);       if (x != y) {         fa[x] = y;         v[y] |= v[x];         sz[y] += sz[x];       } else         v[x] = 1;     }     for (i = 1; i <= cnt0 + cnt1; i++)       if (fa[i] == i) {         if (v[i])           ans = ans * fac[sz[i]] % p;         else           ans = ans * (fac[sz[i]] - 1 + p) % p;       }     printf( %lld , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, s;     cin >> a >> b >> s;     if (a < 0) a *= (-1);     if (b < 0) b *= (-1);     (s >= (a + b) && (s - a - b) % 2 == 0) ? cout <<  YES  : cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, x;     cin >> n >> x;     long long ans = 0;     for (long long i = 1; i <= n; i++) {       if (i * n >= x) {         if (x % i == 0) ans += 1;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   int t, n, per[200001], where[200001];   int groupcnt;   int main() {     scanf( %d , &t);     for (int test = 0; test < t; test++) {       scanf( %d , &n);       groupcnt = 0;       for (int i = 1; i <= n; i++) {         scanf( %d , &per[i]);         where[per[i]] = i;       }       for (int i = 1; i <= n; i++) {         groupcnt++;         int location = where[i];         if (location > 1 && per[location - 1] < i) groupcnt--;         if (location < n && per[location + 1] < i) groupcnt--;         if (groupcnt == 1)           printf( 1 );         else           printf( 0 );       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100005], b[100005];   int main() {     int n, m, k;     map<int, int> f1;     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < m; i++) {       cin >> b[i];     }     bool f = false;     sort(a, a + n);     sort(b, b + m);     reverse(a, a + n);     reverse(b, b + m);     if (n <= m) {       for (int i = 0; i < n; i++) {         if (a[i] > b[i]) {           f = true;           break;         }       }     } else {       f = true;     }     if (f) {       cout <<  YES ;     } else {       cout <<  NO ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> v;     int n, a, b;     while (scanf( %d , &n) != EOF) {       v.assign(n, 0);       for (int i = 0; i < n; i++) {         scanf( %d , &v[i]);       }       sort(v.begin(), v.end());       a = 1;       b = n - 1;       while (a < n && v[a] == v[0]) a++;       while (b >= 0 && v[b] == v[n - 1]) b--;       if (a > b)         printf( 0 n );       else         printf( %d n , b - a + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using str = string;   using srt = short;   const int INF = (int)1e9 + 4;   const int MOD = (int)1e9 + 7;   const int N = 1005;   const ll inf = (ll)4e18;   const ll mod = 998244353;   bool us[N][N];   set<pair<int, int>> ans;   vector<pair<int, int>> arr(3);   vector<pair<int, int>> dirs = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};   int dist(pair<int, int> a, pair<int, int> b) {     return abs(a.first - b.first) + abs(a.second - b.second);   }   void vToV(int st, int en) {     int x1 = arr[st].first, y1 = arr[st].second, x2 = arr[en].first,         y2 = arr[en].second;     ans.insert({x1, y1});     while (x1 != x2 || y1 != y2) {       us[x1][y1] = 1;       if (x1 < x2 && us[x1 + 1][y1]) {         ans.insert({++x1, y1});       } else if (y1 < y2 && us[x1][y1 + 1]) {         ans.insert({x1, ++y1});       } else if (y1 > y2 && us[x1][y1 - 1]) {         ans.insert({x1, --y1});       } else {         int dst = INF;         pair<int, int> dir;         for (auto it : dirs) {           int now = dist({x1 + it.first, y1 + it.second}, {x2, y2});           if (now < dst) {             dir = it;             dst = now;           }         }         x1 += dir.first;         y1 += dir.second;         ans.insert({x1, y1});       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     for (auto &it : arr) {       cin >> it.first >> it.second;       ans.insert(it);       us[it.first][it.second] = 1;     }     sort(begin(arr), end(arr));     arr.emplace_back(arr.back());     vToV(0, 1);     vToV(1, 2);     cout << ans.size() << endl;     for (auto &it : ans) cout << it.first <<     << it.second << endl;   }


#include <bits/stdc++.h>   using namespace std;   int row[300000];   int verts[300000];   int main() {     long long int v, p = 0, h, input, answer = 0, tanswer = 1000000000;     cin >> v >> h;     row[0] = 0;     verts[0] = 0;     for (int i = 1; i <= v; i++) {       cin >> verts[i];     }     verts[v + 1] = 1000000000;     v++;     for (int j = 1; j <= h; j++) {       int first;       cin >> first;       if (first == 1) {         p++;         cin >> row[p] >> first;       } else {         cin >> first >> first;       }     }     sort(row, row + p + 1);     sort(verts, verts + v);     int rows = p;     int cr = 1;     for (int c = 1; c <= v; c++) {       for (int r = cr; r <= rows; r++) {         if (row[r] < verts[c]) {           if (r == rows) {             answer = rows - r + c - 1;             cr = r + 1;             break;           }           continue;         } else {           answer = rows - r + c;           cr = r;           break;         }       }       if (answer < tanswer) tanswer = answer;     }     cout << tanswer;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     string s;     map<string, int> m;     for (__typeof((n)) i = (0); i < (n); i++) {       cin >> s;       if (m[s])         cout <<  YES  << endl;       else         cout <<  NO  << endl;       m[s]++;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long powr(long long exp) {     if (exp == 1) return 2;     if (exp % 2 == 0) {       long long ret = (powr(exp / 2)) % 1000000007;       ret = (ret * ret) % 1000000007;       return ret;     }     long long ret = powr(exp / 2) % 1000000007;     ret = (ret * ret * 2) % 1000000007;     return ret;   }   int main() {     string s;     cin >> s;     long long mul = 1;     string s1 =   ;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  a  || s[i] ==  b ) s1 += s[i];     }     s1 +=  b ;     long long st = 1;     for (int i = 0; i < s1.size(); i++) {       if (s1[i] ==  b ) {         mul = ((mul) * (st % 1000000007)) % 1000000007;         st = 1;       } else if (s1[i] ==  a ) {         st++;       }     }     mul = (mul - 1);     if (mul < 0) mul += 1000000007;     cout << mul;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 101;   const int BITS = 60;   struct node {     int son[2];     bool all;     bool have;   } f[N * 200 * 4];   int na, nb;   int tot;   vector<pair<int, int> > d[BITS + 1];   void ins(long long l, int bits, int s, long long ll, long long rr) {     if (l + (1ll << bits) - 1 < ll || rr < l) return;     if (f[s].all) return;     if (l >= ll && l + (1ll << bits) - 1 <= rr) {       f[s].all = 1;       f[s].have = 1;       return;     }     f[s].have = 1;     if (!f[s].son[0]) f[s].son[0] = ++tot;     if (!f[s].son[1]) f[s].son[1] = ++tot;     ins(l, bits - 1, f[s].son[0], ll, rr);     ins(l + (1ll << (bits - 1)), bits - 1, f[s].son[1], ll, rr);     f[s].all = (f[f[s].son[0]].all && f[f[s].son[1]].all);   }   const int mod = 998244353;   int add(int x, int y) {     x += y;     return x >= mod ? x - mod : x;   }   int sub(int x, int y) {     x -= y;     return x < 0 ? x + mod : x;   }   int mul(int x, int y) { return 1ll * x * y % mod; }   int calc(int x, int y) {     int z = 1;     while (y) {       if (y & 1) z = mul(z, x);       x = mul(x, x), y >>= 1;     }     return z;   }   int ni2 = calc(2, mod - 2);   int calc(long long x) { return mul(mul((x - 1) % mod, x % mod), ni2); }   int work(int prefix, int bits) {     if (!d[bits].size()) return 0;     for (auto u : d[bits]) {       if (f[u.first].all || f[u.second].all) {         return add(mul(prefix, (1ll << bits) % mod), calc(1ll << bits));       }     }     int v = 0;     for (int x = 0; x < 2; x++) {       d[bits - 1].clear();       for (int i = 0; i < 2; i++)         for (auto u : d[bits])           if (f[f[u.first].son[i]].have && f[f[u.second].son[i ^ x]].have)             d[bits - 1].push_back({f[u.first].son[i], f[u.second].son[i ^ x]});       v = add(work(add(prefix, (((long long)x) << (bits - 1)) % mod), bits - 1),               v);     }     return v;   }   int main() {     tot = 3;     scanf( %d , &na);     while (na--) {       long long l, r;       scanf( %lld %lld , &l, &r);       ins(0, BITS, 1, l, r);     }     scanf( %d , &nb);     while (nb--) {       long long l, r;       scanf( %lld %lld , &l, &r);       ins(0, BITS, 2, l, r);     }     d[BITS].push_back({1, 2});     printf( %d n , work(0, BITS));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isv(char x) {     if (x ==  a  || x ==  e  || x ==  i  || x ==  o  || x ==  u ) return true;     return false;   }   int main() {     ios::sync_with_stdio(0);     long long c, a, b, act;     cin >> c;     cin >> a >> b;     act = max(a, b);     --c;     while (c--) {       cin >> a >> b;       if (a <= act && b <= act)         act = max(a, b);       else if (a <= act)         act = a;       else if (b <= act)         act = b;       else {         cout <<  NO  <<   n ;         return 0;       }     }     cout <<  YES  <<   n ;     return 0;   }