#include <bits/stdc++.h> n #define MAXN   100001   n int spf[MAXN];  n using namespace std;    n #define mod             1000000007 n #define int             long long //32bit as well as 64bit n #define vi              vector<int> // a[n] s[n]  v(n)  pop_back    n #define vvi             vector<vector<int>>  // vvi(n)  vec[i]=vi(col); n #define maxx(arr)       *max_element(arr.begin(),arr.end())  n #define minn(arr)       *min_element(arr.begin(),arr.end()) n #define maxa(arr)       *max_element(arr,arr+arr.size()) n #define mina(arr)       *min_element(arr,arr+arr.size()) n #define sortt(sv)       sort(sv.begin(),sv.end()) //str & v   rbegin,rend n #define pb              push_back  // s0d and v s.pb(s[i]) n #define forr(i,z,n)     for(int i=z;i<n;i++)   // n= name.size() n #define forn(i,n,x)     for(int i=n-1;i>=x;i--)    //for(i+=3) loop last line i+=2; n #define aa(i,st)        for(auto i=st.begin();i!=st.end();i++)  //arr not/*i(vec,set,0Dstring)/mp(i->first) n #define an(i,st)        for(auto i=st.rbegin();i!=st.rend();i++)    n #define gcd(a,b)        __gcd(a,b) //0,x=x n #define lcm(a,b)        ((a)*(b)/gcd(a,b)) // 0,x =0   n #define con(arr,s);     /*string to array*/int arr[s.size()]={0};for(int i=0;i<s.size();i++){arr[i]=arr[i]*10+(s[i]-48);} n  n int    binpower                                                                                (int base, unsigned int e, int m) {int result = 1;base %= m;while (e) {if (e & 1)result = result * base % m;base = base * base % m;e >>= 1;}return result;} n bool   check_composite                                                                                (int n, int a, int d, int s) {int x = binpower(a, d, n);if (x == 1 || x == n - 1)return false;for (int r = 1; r < s; r++) {x = x * x % n;if (x == n - 1)return false;}return true;}; n bool   prime(int n)    /* 1 is not prime*/                                                                                { if (n < 2)return false;int r = 0;int d = n - 1;while ((d & 1) == 0) {d >>= 1;r++;}for (int a : {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37}) {if (n == a)return true;if (check_composite(n, a, d, r))return false;}return true;} n int    fact (int n)    /*fa(3)=3*2  fa(0)=1    npr=fa(n)/ fac(n-r)      ncr=fa(n)/(fa(n-r)*fa(r))          for aba 3p2=aa ab ba ba aa ab(6)  and 3c2(3) =  ab aa ba (because input is in int)  */      { int res=1; for(int i=2;i<=n;i++) res=res*i; return res;}  n void   helperfactor()                                                                                {spf[1] = 1;for (int i=2; i<MAXN; i++)spf[i] = i;for (int i=4; i<MAXN; i+=2)spf[i] = 2;for (int i=3; i*i<MAXN; i++){if (spf[i] == i){for (int j=i*i; j<MAXN; j+=i)if (spf[j]==j)spf[j] = i;}}}  n void   lcmfactor       (vi &ret,int x)                         /*       12= 2 2 3         */                                          { helperfactor();while (x != 1) { ret.push_back(spf[x]); x = x / spf[x];}}  n void   primefactor  (vi &arr,int n)                            /*       12= 2 3           */                                                                 {bool prime[n + 1];memset(prime, true, sizeof(prime));for (int p = 2; p * p <= n; p++){if (prime[p] == true){for (int i = p * p; i <= n; i += p)prime[i] = false;}}for (int p = 2; p <= n; p++)if (prime[p])arr.pb(p);} n void   allfactor    (vi &arr,int n)     /*sort to get lexiographically  12= 1 12 2 6 3 4  */                                                 {for (int i=1; i<=sqrt(n); i++){if (n%i == 0){if (n/i == i)arr.pb(i);else{arr.pb(i); arr.pb(n/i);}}}} n  n // void   longfactor(vi &arr,int n)                                                                           {while (n%2 == 0){arr.pb(2);n = n/2;}for (int i = 3; i <= sqrt(n); i = i+2){while (n%i == 0){arr.pb(i);n = n/i; }}if (n > 2) arr.pb(n); }  n // void   helperlongprime(int limit, vi &prime,vi &arr)                                                        {vector<bool> mark(limit + 1, true);for (int p=2; p*p<limit; p++){if (mark[p] == true){for (int i=p*p; i<limit; i+=p)mark[i] = false;}}for (int p=2; p<limit; p++){if (mark[p] == true){prime.push_back(p);arr.pb(p);}}} n // void   longprimefactor(vi &arr,int n)                                                                       {int limit = floor(sqrt(n))+1;vector<int> prime;prime.reserve(limit);helperlongprime(limit, prime,arr);int low = limit;int high = 2*limit;while (low < n){if (high >= n)high = n;bool mark[limit+1];memset(mark, true, sizeof(mark));for (int i = 0; i < prime.size(); i++){int loLim = floor(low/prime[i]) * prime[i];if (loLim < low)loLim += prime[i];for (int j=loLim; j<high; j+=prime[i])mark[j-low] = false;}for (int i = low; i<high; i++)if (mark[i - low] == true)arr.pb(i);low = low + limit;high = high + limit;}} n  n //use v.size/s=   instead making bool/checkpoints/else if/else   n // v(n) imp for cin not for pb n  n  n  n  n //JAI SARGURU DEV  JAI SATGURU DEV   DONT WASTE TIME n //Dasrath manjhi 22 years  gate 10years  sonu bahiya appu bhaiya kunal akshay alok bhanu me 1 year january 22 n //Become financial independent as fast as u can to enjoy life -> STUDENT LIFE,STUDY ONLY n //Dont waste time in finding reason to relax n  n //  JUST STUDY,NO RELAX,NO REASON   for 1YEAR  n  n void solve(){  n  n int n; n cin>>n; n  n vi v(n); n forr(i,0,n){ n     cin>>v[i]; n } n int maxy=v[n-1]; n vi ans(n); n forn(i,n,0){ n    ans[i]=v[i]; n    if(i+ans[i]<n){ n      ans[i]+=ans[i+ans[i]]; n    } n    if(ans[i]>maxy){ n     maxy=ans[i]; n    } n } n  n cout<<maxy<<  n ; n  n  n  n  n  n  n  n  n  n  n  n } n  n  n  n  n  n  n  n  n  n int32_t main(){ n      n     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); n     #ifndef ONLINE_JUDGE n         freopen( input.txt , r ,stdin); n         freopen( output.txt , w ,stdout); n     #endif n  n     int t;cin>>t;while(t--) n         solve(); n      n      n     return 0; n } n  n /*pow(base,power)       sqrt(n)     ceil(cbrt(n))/ceil(n)    n long double n = -7.11;       cbrt(n);         gives till .5 point  /long long double not exist n int h= (s[0]- 0 )*10  + s[1]- 0 ;  n s.erase(remove(s.begin(),s.end(),  a  ),s.end());        string search in      n multimap =mp.insert((pair <int, int> ( fir, sec )));  can have sorted same key and definitely same value   n */ n


#include <bits/stdc++.h> n int main() { n   int i, j, k, l; n   long long n, m, sum; n   while (scanf( %lld%lld , &n, &m) != EOF) { n     sum = 0; n     for (int i = 1; i <= n; i++) { n       if (m % i == 0 && m / i <= n) { n         ++sum; n       } n     } n     printf( %d n , sum); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<string, int> hsh; n int check(string str, int l, int r) { n   int pos = 0, cur = 0; n   for (int i = r; i >= l; i--) { n     if (str[i] ==  ( ) n       cur++; n     else if (str[i] ==  ) ) n       cur--; n     else if (cur == 0 && pos == 0 && (str[i] ==  *  || str[i] ==  / )) n       pos = i; n     else if (cur == 0 && (str[i] ==  +  || str[i] ==  - )) { n       int lft = check(str, l, i - 1), rgt = check(str, i + 1, r); n       if (lft == 2 || rgt == 2) return 2; n       if (str[i] ==  + ) n         return 3; n       else if (str[i] ==  - ) { n         if (rgt == 3) n           return 2; n         else n           return 3; n       } n     } n   } n   if (pos) { n     int lft = check(str, l, pos - 1), rgt = check(str, pos + 1, r); n     if (lft == 2 || rgt == 2) return 2; n     if (str[pos] ==  * ) { n       if (lft == 3 || rgt == 3) n         return 2; n       else n         return 4; n     } else if (str[pos] ==  / ) { n       if (lft == 3 || rgt == 3 || rgt == 4) n         return 2; n       else n         return 4; n     } n   } else if (str[l] ==  (  && str[r] ==  ) ) { n     if (check(str, l + 1, r - 1) == 2) n       return 2; n     else n       return 1; n   } else { n     string res =   ; n     for (int i = l; i <= r; i++) res += str[i]; n     if (hsh[res]) n       return hsh[res]; n     else n       return 1; n   } n } n int main() { n   int n; n   string s, exp, ques; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> s; n     if (s ==  # ) cin >> s; n     cin >> s; n     getline(cin, exp); n     ques =   ; n     for (int j = 0; j < exp.length(); j++) n       if (exp[j] !=    ) ques += exp[j]; n     hsh[s] = check(ques, 0, ques.length() - 1); n   } n   getline(cin, exp); n   ques =   ; n   for (int i = 0; i < exp.length(); i++) n     if (exp[i] !=    ) ques += exp[i]; n   if (check(ques, 0, ques.length() - 1) == 2) n     cout <<  Suspicious  << endl; n   else n     cout <<  OK  << endl; n   return 0; n } n


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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