#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   using pl = pair<long long, long long>;   using vll = vector<long long>;   using mll = map<long long, long long>;   using vpl = vector<pl>;   long long mod = 1000000007;   long long modu(long long a, long long b) {     long long c = a % b;     return (c < 0) ? c + b : c;   }   long long ipow(long long a, long long b) {     long long ans = 1;     while (b--) {       ans = ans * a;     }     return ans;   }   long long getmx(long long i, long long j, long long i1, long long j1,                   long long i2, long long j2) {     long long ans = 0;     ans += abs(i - i1) + abs(j - j1);     ans += abs(i1 - i2) + abs(j1 - j2);     ans += abs(i - i2) + abs(j - j2);     return ans;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   bool isleap(long long n) {     if (n % 400 == 0) return true;     if (n % 4 == 0 && n % 100 != 0) return true;     return false;   }   void solve() {     long long n, dif = 0;     cin >> n;     for (long long i = n + 1;; i++) {       if (isleap(i)) {         dif += 2;       } else {         dif++;       }       if (dif % 7 == 0 && (isleap(i) == isleap(n))) {         cout << i <<   n ;         return;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     while (t--) {       solve();     }   }


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


#include <bits/stdc++.h>   using namespace std;   void scanint(long long int &x);   map<long long int, long long int> vv;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     multiset<long long int> ms;     long long int n;     scanint(n);     long long int a[n];     long long int curr = 1;     long long int i = 0;     for (i = 0; i < n; i++) {       scanint(a[i]);       if (!vv[a[i]] && a[i] >= 1 && a[i] <= n)         vv[a[i]]++;       else         ms.insert(a[i]);     }     long long int ans = 0;     multiset<long long int>::iterator itr;     for (itr = ms.begin(); itr != ms.end(); itr++) {       while (vv[curr]) curr++;       ans += abs(*itr - curr);       vv[curr]++;     }     cout << ans << endl;     return 0;   }   void scanint(long long int &x) {     register int c = getchar();     x = 0;     int neg = 0;     for (; ((c < 48 || c > 57) && c !=  - ); c = getchar())       ;     if (c ==  - ) {       neg = 1;       c = getchar();     }     for (; c > 47 && c < 58; c = getchar()) {       x = (x << 1) + (x << 3) + c - 48;     }     if (neg) x = -x;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, mid, ans = 0;     int all[100001];     all[0] = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a;       all[i] = all[i - 1] + a;     }     if (all[n] % 2 == 1) {       cout << 0;       return 0;     }     mid = all[n] / 2;     for (int i = 1; i < n; i++) {       if (all[i] == all[n] - all[i]) ans++;     }     cout << ans;   }


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


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   inline int add(int x, int y) {     x += y;     if (x >= mod) x -= mod;     return x;   }   inline int mul(int x, int y) { return ((long long)x) * y % mod; }   const int N = 1e6 + 5;   int fac[N + 5], ifac[N + 5], p[N + 5];   int Pow(int a, int b) {     int x = 1;     for (; b > 0; b >>= 1) {       if (b & 1) x = mul(x, a);       a = mul(a, a);     }     return x;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int n, m;     cin >> n >> m;     fac[0] = ifac[0] = p[0] = 1;     for (int i = 1; i < N; ++i) {       fac[i] = mul(fac[i - 1], i);       ifac[i] = Pow(fac[i], mod - 2);       p[i] = mul(p[i - 1], m);     }     auto comb = [&](int x, int y) {       return mul(mul(fac[x], ifac[x - y]), ifac[y]);     };     auto f = [&](int x, int y) {       if (x == y) return 1;       return mul(y, Pow(x, x - y - 1));     };     int ans = 0;     for (int k = 1; k < n; ++k)       if (m >= k) {         int g = mul(mul(comb(m - 1, m - k), comb(n - 2, k - 1)),                     mul(mul(fac[k - 1], p[n - k - 1]), f(n, k + 1)));         ans = add(ans, g);       }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[27];   int main() {     long long n;     string s;     cin >> n;     cin >> s;     long long c = 0, i, d;     for (i = 0; i < (2 * n) - 2; i++) {       if (s[i] >=  a  && s[i] <=  z ) {         d = s[i] -  a ;         a[d]++;       } else {         d = s[i] -  A ;         if (a[d] > 0) {           a[d]--;         } else {           c++;         }       }     }     cout << c << endl;   }


// Problem: A. Dense Array   // Contest: Codeforces - Codeforces Round #702 (Div. 3)   // URL: https://codeforces.com/contest/1490/problem/A   // Memory Limit: 256 MB   // Time Limit: 2000 ms   // Powered by CP Editor (https://github.com/cpeditor/cpeditor)      #include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   #define ll          long long   #define pb          push_back   #define eb    emplace_back   #define mp    make_pair   #define pii         pair<ll,ll>   #define vi          vector<int>   #define vii         vector<pii>   #define mi          map<ll,ll>   #define mii         map<pii,ll>   #define all(a)      (a).begin(),(a).end()   #define fi          first   #define si          second   #define sz(x)       (ll)x.size()   #define endl          n    #define checkbit(n, b) ((n >> b) & 1)   #define mod        1000000007   #define inf        1000000000000000000   #define puts(n)  cout<<n;   #define um           unordered_map<ll,ll>   #define rep(i,a,b)  for(int i=a;i<b;i++)   #define setbits(x) __builtin_popcount(x)   #define mset(m,v) memset(m,v,sizeof(m))   #define int ll    #define deb(x) cout << #x <<  =  << x << endl   #define deb2(x, y) cout << #x <<  =  << x <<  ,  << #y <<  =  << y << endl   using namespace std;   int power(int base, int exp);        //=======================        // USED UNORDERED_MAP????????    // INT_MAX and LONG_MAX range???    //gcd(x,y)=gcd(x-y,y)    //gcd(x,y,z...)=gcd(x,y-x,z-x,...)   void solve() {    int n;    cin>>n;    vi arr(n,0);    rep(i,0,n)    {     cin>>arr[i];    }    int cnt=0;    rep(i,0,n-1)    {     int x=max(arr[i],arr[i+1]);     int y=min(arr[i],arr[i+1]);     while(y*2<x)     {      x=(x+1)/2;      cnt++;     }    }    cout<<cnt<<endl;   }       int32_t main() {       ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);       srand(chrono::high_resolution_clock::now().time_since_epoch().count());          int t = 1;       cin >> t;       while(t--) {         solve();       }           return 0;   }       int power(int base, int exp) {     base %= mod;     int result = 1;     while (exp > 0) {       if (exp & 1) result = ((ll)result * base) % mod;       base = ((ll)base * base) % mod;       exp >>= 1;     }     return result;   }


#include <bits/stdc++.h>   using namespace std;   string s;   struct SUM {     int n;     bool pp;   } b;   vector<SUM> a;   bool cmp(SUM u, SUM v) { return u.n < v.n; }   int main() {     std::ios::sync_with_stdio(false);     int i, j, k, m;     cin >> m >> s;     s = s[0] ==  -  ? s :  +  + s;     for (i = 0; i < s.size();) {       j = i + 1;       if (s[i + 1] <  0  || s[i + 1] >  9 )         k = 1;       else {         for (k = 0; s[j] >=  0  && s[j] <=  9 ; ++j) k = k * 10 + s[j] -  0 ;         ++j;       }       if (s[i] ==  - ) k = -k;       b.n = k;       b.pp = s[j] !=  a ;       a.push_back(b);       i = j + 3;     }     sort(a.begin(), a.end(), cmp);     for (k = 0, i = 0; i < a.size(); ++i) {       if (a[i].pp)         k += a[i].n * ++m;       else         k += a[i].n * m++;     }     cout << k << endl;     return 0;   }


#include <iostream>   #include <bits/stdc++.h>   using namespace std;      int main()   {       int t; cin >> t;       while (t--){           //int n; cin >> n;           string s; cin >> s;           string res =   ;           for (int i=0;i<s.size();i++){               if (i%2==0){                   if (s[i]== a ){                       res +=  b ;                   } else {                       res +=  a ;                   }               } else {                   if (s[i]== z ){                       res +=  y ;                   } else {                       res +=  z ;                   }               }                 }           cout << res << endl;                   }   }


#include <bits/stdc++.h>   using namespace std;   const long long LIM = 1e5;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout.precision(10);     cout << fixed;     long long n, r;     cin >> n >> r;     vector<long long> L(n);     vector<long long> T(n);     for (long long i = 0; i < n; i++) cin >> L[i];     for (long long i = 0; i < n; i++) cin >> T[i];     long long cnt = 0;     vector<long long> ans;     long long curTime = 0;     long long timePotion = 0;     for (long long i = 0; i < n; i++) {       long long l = L[i];       long long t = T[i];       if (timePotion < l) {         t -= timePotion;         l -= timePotion;         curTime += timePotion;         if (t < 0) {           cout << -1 <<   n ;           return 0;         }         if (2 * l > t) {           long long szz = ans.size();           long long timeNeedPotion = 2 * l - t;           if (t - timeNeedPotion < 0) {             cout << -1 <<   n ;             return 0;           }           long long cntMoments = (timeNeedPotion / r) + (timeNeedPotion % r != 0);           curTime = curTime + t - timeNeedPotion;           cnt += cntMoments;           for (long long i = 0; i < cntMoments; i++) {             if (ans.size() < LIM) {               ans.push_back(curTime + i * r);             } else {               break;             }           }           curTime += timeNeedPotion;           timePotion = r - (timeNeedPotion % r);           if (timePotion == r) timePotion -= r;         } else {           curTime += l * 2;           timePotion = 0;         }       } else {         if (l > t) {           cout << -1 <<   n ;           return 0;         } else {           timePotion -= l;           curTime += l;         }       }     }     cout << cnt <<   n ;     if (cnt <= LIM) {       for (long long xx : ans) cout << xx <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long Length, X, Y;   long long Dp[10000001];   int main(void) {     register long long i;     cin >> Length >> X >> Y;     Dp[1] = X;     for (i = 2; i <= Length; i++) {       Dp[i] = Dp[i - 1] + X;       if (i & 1) {         Dp[i] = min(Dp[i], Dp[(i >> 1) + 1] + X + Y);       } else {         Dp[i] = min(Dp[i], Dp[i >> 1] + Y);       }     }     cout << Dp[Length] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int i1, i2, a1, a2;     cout <<  ?  ;     for (int i = 1; i <= k; ++i) cout << i <<    ;     cout <<   n ;     cout.flush();     cin >> i1 >> a1;     cout <<  ?  ;     for (int i = 1; i <= k + 1; ++i) {       if (i == i1) ++i;       cout << i <<    ;     }     cout <<   n ;     cout.flush();     cin >> i2 >> a2;     if (a1 < a2) {       swap(i1, i2);       swap(a1, a2);     }     int count = 0, c1 = 0, c2;     for (int ch = 1; ch <= k + 10; ++ch) {       if (ch == i1 || ch == i2) ++ch;       if (ch == i1 || ch == i2) ++ch;       ++c1;       if (c1 > k - 1) break;       cout <<  ?  ;       c2 = 0;       for (int i = 1; i <= k + 10; ++i) {         ++c2;         if (c2 > k) break;         if (i == i2) ++i;         if (i == ch)           cout << i2 <<    ;         else           cout << i <<    ;       }       cout <<   n ;       cout.flush();       int ich, ach;       cin >> ich >> ach;       if (ich == i1) ++count;     }     cout <<  !   << count + 1;     cout.flush();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[110];   map<int, bool> mp[3];   bool Check(int x) {     if (x < 10) {       if (mp[0][x] || mp[1][x] || mp[2][x]) return true;     } else if (x < 100) {       int a = x / 10, b = x % 10;       if (mp[0][a] && mp[1][b]) return true;       if (mp[0][a] && mp[2][b]) return true;       if ((mp[1][a] && mp[2][b]) || (mp[1][a] && mp[0][b])) return true;       if ((mp[2][a] && mp[0][b]) || (mp[2][a] && mp[1][b])) return true;     }     return false;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       for (int x, j = 0; j < 6; ++j) {         scanf( %d , &x);         mp[i][x] = true;       }     }     int i;     for (i = 1; i < 1000; ++i) {       if (!Check(i)) break;     }     printf( %d n , i - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int a, b;     int s[4010];     cin >> n;     memset(s, 0, sizeof(s));     for (int i = 0; i < n; i++) {       cin >> a >> b;       s[a + b]++;       s[a - b + 3000]++;     }     long long sum = 0;     for (int i = 0; i <= 4000; i++) {       if (s[i] > 1) sum += (s[i] * (s[i] - 1) / 2);     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long x, y, z;     cin >> x >> y >> z;     long long xx = x, yy = y;     long long g1 = x % z, p1;     if ((y + g1) / z > y / z) {       y += g1;       if (g1 - (y) % z > 0) g1 -= (y) % z;     } else       g1 = 0;     p1 = (x / z) + (y / z);     long long g2 = yy % z, p2;     if ((xx + g2) / z > xx / z) {       xx += g2;       if (g2 - (xx) % z > 0) g2 -= (xx) % z;     } else       g2 = 0;     p2 = (xx / z) + (yy / z);     if (p1 > p2)       cout << p1 <<     << g1;     else if (p2 > p1)       cout << p2 <<     << g2;     else {       cout << p1 <<    ;       if (g1 < g2)         cout << g1;       else         cout << g2;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long M = 1e6 + 5;   const long long mod = 1e9 + 7;   void solve() {     long long n;     cin >> n;     long long a = n / 10;     long long b = n % 10;     long long ans = a + (b == 9);     cout << ans;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long T = 1;     cin >> T;     while (T-- > 0) {       solve();       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename TP>   inline bool rd(TP& r) {     r = 0;     char tmp = getchar();     while (tmp <  0  || tmp >  9 ) {       if (tmp == EOF) return 0;       tmp = getchar();     }     while ( 0  <= tmp && tmp <=  9 ) {       r = (r << 3) + (r << 1) + tmp -  0 ;       tmp = getchar();     }     return 1;   }   long long a[110], b[110], n;   long long dt[110 * 110];   bool vis[1000100];   long long ab(long long num) {     if (num >= 0) return num;     return -num;   }   int main() {     int t;     rd(t);     int tot;     int nb;     while (t--) {       rd(n);       for (int i = 1; i <= n; i++) rd(a[i]);       tot = 0;       for (int i = 1; i <= n; i++)         for (int j = 1; j < i; j++) dt[++tot] = ab(a[i] - a[j]);       sort(dt + 1, dt + tot + 1);       tot = unique(dt + 1, dt + tot + 1) - (dt + 1);       memset(vis, 0, sizeof(vis));       nb = 0;       for (int i = 1; i <= 1000000 && nb != n; i++)         if (!vis[i]) {           b[++nb] = i;           for (int j = 1; j <= tot && i + dt[j] < 1000100; j++)             vis[i + dt[j]] = 1;         }       if (nb != n)         printf( NO n );       else {         printf( YES n );         for (int i = 1; i <= n; i++) printf( %I64d  , b[i]);         printf(  n );       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   #pragma comment(linker,  /STACK:336777216 )   using namespace std;   int IT_MAX = 1 << 17;   const long long MOD = 1000000007;   const int INF = 0x1f3f3f3f;   const long long LL_INF = 1034567890123456789ll;   const double PI = acos(-1);   const double ERR = 1E-11;   multiset<int> Sx;   int in[100050];   int main() {     int N, K, i, j;     scanf( %d %d , &N, &K);     for (i = 1; i <= N; i++) scanf( %d , &in[i]);     int ans = -1;     vector<int> Va;     for (i = 1, j = 1; i <= N; i++) {       while (j <= N) {         if (Sx.empty()) {           Sx.insert(in[j++]);           continue;         }         auto it1 = Sx.begin();         auto it2 = Sx.end();         it2--;         if (abs(in[j] - *it1) > K || abs(in[j] - *it2) > K) break;         Sx.insert(in[j++]);       }       if (ans < j - i) {         ans = j - i;         Va.clear();       }       if (ans == j - i) Va.push_back(i);       Sx.erase(Sx.lower_bound(in[i]));     }     printf( %d %d n , ans, (int)Va.size());     for (auto it : Va) printf( %d %d n , it, it + ans - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct info {     int l, r, need, onemore, take;   };   vector<string> solve(vector<int> a, int n) {     vector<string> ans(n + 1, string(n,  0 ));     vector<info> state = {{0, n, (n + 1) / 2, ((n + 1) & 1), 0}};     int pos = 0;     for (auto i : a) {       for (auto &j : state)         while (j.need && i) {           --i;           --j.need;           ++j.take;         }       for (auto &j : state)         if (j.onemore && i) {           --i;           --j.onemore;           ++j.take;         }       int j = 0;       while (i > 0) {         if (state[j].take != state[j].r - state[j].l + 1) {           --i;           ++state[j].take;         }         j = (j + 1) % state.size();       }       vector<info> nstate;       for (auto &k : state) {         for (int p = k.l; p < k.l + k.take; ++p) ans[p][pos] =  1 ;         if (k.take) nstate.push_back({k.l, k.l + k.take - 1, 0, 0, 0});         if (k.take < k.r - k.l + 1)           nstate.push_back({k.l + k.take, k.r, 0, 0, 0});       }       state = nstate;       for (auto &k : state) {         k.need = (k.r - k.l + 1) / 2;         k.onemore = (k.r - k.l + 1) & 1;         k.take = 0;       }       ++pos;     }     sort(ans.begin(), ans.end());     reverse(ans.begin(), ans.end());     while (!ans.empty() && ans.back() == string(n,  0 )) ans.pop_back();     return ans;   }   void validate(vector<int> a, int n, vector<string> ans) {     for (auto &j : ans)       for (int i = 0; i < n; ++i)         if (j[i] ==  1 ) --a[i];     assert(count(a.begin(), a.end(), 0) == n);     for (int i = 1; i < ans.size(); ++i) assert(ans[i - 1] != ans[i]);   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int n;     cin >> n;     vector<int> a(n);     for (auto &i : a) cin >> i;     auto ans = solve(a, n);     validate(a, n, ans);     cout << ans.size() <<   n ;     for (auto i : ans) cout << i <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt[ T  + 1];   string p =  AGTC ;   int main() {     int n;     cin >> n;     string s;     cin >> s;     for (int i = 0, __l = s.size(); i < __l; ++i) cnt[s[i]]++;     int maxi = 0;     for (int i = 0, __l = p.size(); i < __l; ++i) maxi = max(maxi, cnt[p[i]]);     int x = 0;     for (int i = 0, __l = p.size(); i < __l; ++i) x += cnt[p[i]] == maxi;     long long ans = 1;     for (int i = 0, __l = n; i < __l; ++i) (ans *= x) %= 1000000007;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double ESP = 1E-8;   long double cal(long double x, long double y, long double z) {     return log(x) * pow(y, z);   }   long double ca(long double x, long double y, long double z) {     return y * z * log(x);   }   int main() {     const char* result[12] = { x^y^z ,  x^z^y ,  (x^y)^z ,  (x^z)^y ,                                y^x^z ,  y^z^x ,  (y^x)^z ,  (y^z)^x ,                                z^x^y ,  z^y^x ,  (z^x)^y ,  (z^y)^x };     long double a[20];     long double x, y, z;     cin >> x >> y >> z;     a[0] = cal(x, y, z);     a[1] = cal(x, z, y);     a[2] = ca(x, y, z);     a[3] = ca(x, z, y);     a[4] = cal(y, x, z);     a[5] = cal(y, z, x);     a[6] = ca(y, x, z);     a[7] = ca(y, z, x);     a[8] = cal(z, x, y);     a[9] = cal(z, y, x);     a[10] = ca(z, x, y);     a[11] = ca(z, y, x);     long double maxn = a[0];     int res = 0;     for (int i = 1; i < 12; ++i) {       if (maxn < a[i] - ESP) {         maxn = a[i];         res = i;       }     }     printf( %s , result[res]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll MOD = (int)1e9 + 7;   ll modAdd(ll a, ll b) {     if (a + b >= MOD)       return a + b - MOD;     else       return a + b;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     vector<int> sweetness(n);     for (int& v : sweetness) cin >> v;     vector<vector<pair<int, int>>> offs(n);     for (int i = 0; i < m; ++i) {       int s, h;       cin >> s >> h;       int a = 0;       for (int need = h; a < n; ++a) {         if (sweetness[a] == s) --need;         if (need == 0) break;       }       int b = n - 1;       for (int need = h; b >= 0; --b) {         if (sweetness[b] == s) --need;         if (need == 0) break;       }       offs[s - 1].push_back({a, b});     }     vector<pair<int, ll>> res;     for (int a = -1; a < n; ++a) {       int cou = 0;       ll v0 = (a != -1);       ll v1 = (a == -1);       for (auto& vec : offs) {         ll dp[2][2][2];         for (int i = 0; i < 2; ++i) {           for (int j = 0; j < 2; ++j) {             for (int t = 0; t < 2; ++t) {               dp[i][j][t] = 0;             }           }         }         dp[0][0][0] = v0;         dp[0][0][1] = v1;         for (auto pr : vec) {           int le = (pr.first <= a) + (pr.first == a);           int ri = (pr.second >= a + 1);           for (int i = 1; i >= 0; --i) {             for (int j = 1; j >= 0; --j) {               for (int t = 1; t >= 0; --t) {                 if (le && i) {                   if (le == 2 && t == 1) {                     dp[i][j][t] =                         modAdd(dp[i][j][t], modAdd(dp[0][j][0], dp[0][j][1]));                   } else if (le == 1) {                     dp[i][j][t] = modAdd(dp[i][j][t], dp[0][j][t]);                   }                 }                 if (ri && j) {                   dp[i][j][t] = modAdd(dp[i][j][t], dp[i][0][t]);                 }               }             }           }         }         if (dp[1][1][0] || dp[1][1][1]) {           cou += 2;           v0 = dp[1][1][0];           v1 = dp[1][1][1];         } else if (dp[1][0][0] || dp[1][0][1] || dp[0][1][0] || dp[0][1][1]) {           ++cou;           v0 = modAdd(dp[1][0][0], dp[0][1][0]);           v1 = modAdd(dp[1][0][1], dp[0][1][1]);         }       }       res.push_back({cou, v1});     }     sort(res.begin(), res.end());     ll ans = 0;     int mc = res.back().first;     while (!res.empty() && res.back().first == mc) {       ans = modAdd(ans, res.back().second);       res.pop_back();     }     cout << mc <<     << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 21;   long long int tot[N];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int n;     cin >> n;     long long int i, j, a[n], b, c, ans = 0;     for (i = 0; i < n; i++) {       cin >> a[i];       for (j = 0; j < N; j++) {         if (a[i] & (1LL << j)) {           tot[j]++;         }       }     }     for (i = 0; i < n; i++) {       long long int cur = 0;       for (j = 0; j < N; j++) {         if (tot[j]) {           cur += (1LL << j);           tot[j]--;         }       }       ans += (cur * cur);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool test_cases_exist = false;   void solve() {     long long int i, j, n, m, k, x, y, ans;     cin >> n;     vector<long long int> v(n);     for (auto &z : v) cin >> z;     long long int bit = 23;     long long int oneall = (1 << 23) - 1;     vector<long long int> dp((1 << 23), -1);     for (auto z : v) dp[z] = z;     for (i = 0; i < (1 << bit); i++) {       for (j = 0; j < bit; j++) {         if (dp[i] != -1) break;         if (i >> j & 1) dp[i] = dp[i ^ 1 << j];       }     }     for (auto z : v) cout << dp[oneall ^ z] <<    ;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t = 1;     if (test_cases_exist) cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     cin >> n >> m;     long long a = 1;     long long b = 1;     long long c = 1000000007;     for (int i = 0; i < n; i++) {       b = b * (2 * m - 1);       b = b + a;       b = b % c;       a = a * m;       a = a % c;     }     cout << b;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dfn[2100], low[2100], tim, dis[2100], n, i, x, y, M, be[2100], m, j, ans,       du[2100];   vector<int> E[2100], e[2100], q;   void tarjan(int x, int ff) {     dfn[x] = low[x] = ++tim;     q.push_back(x);     for (int i = 0; i < e[x].size(); ++i)       if (e[x][i] != ff) {         if (!dfn[e[x][i]]) {           tarjan(e[x][i], x);           low[x] = min(low[x], low[e[x][i]]);         } else           low[x] = min(low[x], dfn[e[x][i]]);       }     if (low[x] == dfn[x]) {       ++M;       for (;;) {         int t = q.back();         q.pop_back();         be[t] = M;         if (t == x) break;       }     }   }   void dfs(int p, int ff, int dis) {     dfn[p] = 1;     if (dis > y) y = dis, x = p;     for (int i = 0; i < E[p].size(); ++i)       if (E[p][i] != ff) dfs(E[p][i], p, dis + 1);   }   int main() {     scanf( %d%d , &n, &m);     for (i = 1; i <= m; ++i) {       scanf( %d%d , &x, &y);       e[x].push_back(y);       e[y].push_back(x);     }     for (i = 1; i <= n; ++i)       if (!dfn[i]) tarjan(i, 0);     for (i = 1; i <= n; ++i)       for (j = 0; j < e[i].size(); ++j)         if (be[i] != be[e[i][j]]) E[be[i]].push_back(be[e[i][j]]), du[be[i]]++;     memset(dfn, 0, sizeof(dfn));     for (i = 1; i <= M; ++i) {       if (!dfn[i]) {         y = 0;         dfs(i, 0, 1);         y = 0;         dfs(x, 0, 1);         if (y == 1)           ans--;         else           ans += y - 2 - 1;       }       if (du[i] <= 1) ans++;     }     printf( %d n , n - ans - 1);   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   const int INF = 1e9;   struct dot {     int l, r;   };   typedef int node;   const int neutro = 0;   struct RMQ {     int sz;     node t[4 * MAXN];     node &operator[](int p) { return t[sz + p]; }     void init(int n) {       sz = 1 << (32 - __builtin_clz(n));       for (int i = (0); i < (int)(2 * sz); i++) t[i] = neutro;     }     void updall() {       for (int i = sz - 1; i >= 0; i--) {         t[i] = (t[2 * i] ^ t[2 * i + 1]);       }     }     node get(int i, int j) { return get(i, j, 1, 0, sz); }     node get(int i, int j, int n, int a, int b) {       if (j <= a || i >= b) return neutro;       if (i <= a && b <= j) return t[n];       int c = (a + b) / 2;       return (get(i, j, 2 * n, a, c) ^ get(i, j, 2 * n + 1, c, b));     }     void set(int p, node val) {       for (p += sz; p > 0 && t[p] != val;) {         t[p] = val;         p /= 2;         val = (t[p * 2] ^ t[p * 2 + 1]);       }     }   } rmq;   int n, grundy[MAXN], ans[MAXN];   vector<dot> events[MAXN];   int main() {     rmq.init(MAXN);     rmq.updall();     for (int i = (1); i < (int)(MAXN); i++) {       int s = i;       for (int j = i; s < MAXN; j++, s += j) {         if (j == i) continue;         events[s].push_back({i, j});       }     }     grundy[1] = grundy[2] = 0;     rmq.set(1, 0);     rmq.set(2, 0);     for (int i = (3); i < (int)(MAXN); i++) {       ans[i] = INF;       long long bm = 0;       for (auto ev : events[i]) {         long long v = rmq.get(ev.l, ev.r + 1);         if (v < 0) {           printf( %d %d %d : %d %d n , i, ev.l, ev.r, grundy[ev.l], grundy[ev.r]);           exit(-1);         }         bm |= (1ll << v);         if (v == 0) {           if (ev.r - ev.l + 1 < ans[i]) {             ans[i] = ev.r - ev.l + 1;           }         }       }       for (long long j = 0; j < 60; j++) {         if ((bm & (1ll << j)) == 0) {           grundy[i] = j;           break;         }       }       rmq.set(i, grundy[i]);     }     while (scanf( %d , &n) == 1) {       printf( %d n , grundy[n] == 0 ? -1 : ans[n]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int n, v[N], id[N], now[N], p[N];   bool is_lucky(int x) {     while (x) {       if (x % 10 != 7 && x % 10 != 4) return false;       x /= 10;     }     return true;   }   void change(int pos1, int pos2) {     swap(now[p[pos1]], now[p[pos2]]);     swap(p[pos1], p[pos2]);   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , v + i), p[i] = id[i] = now[i] = i;     if (is_sorted(v, v + n)) return printf( 0 n ), 0;     sort(id, id + n, [](int a, int b) { return v[a] < v[b]; });     int c = -1;     for (int i = 0; i < n; i++)       if (is_lucky(v[i])) {         c = i;         break;       }     if (c == -1) return printf( -1 n ), 0;     vector<pair<int, int>> ans;     for (int i = 0; i < n; i++) {       if (is_lucky(v[i])) {         c = i;         break;       }     }     for (int i = 0; i < n; i++)       if (p[i] != id[i]) {         if (now[c] != i) {           ans.emplace_back(now[c], i);           change(now[c], i);         }         if (now[c] != now[id[i]]) {           ans.emplace_back(now[c], now[id[i]]);           change(now[c], now[id[i]]);         }       }     printf( %d n , (int)ans.size());     for (auto x : ans) printf( %d %d n , x.first + 1, x.second + 1);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int a, b;       cin >> a >> b;       if (a == b) {         cout << 0 <<   n ;         continue;       }       if (a - b > 5) {         int answ = 0;         int cant = (a - b) / 5;         answ = answ + cant;         a = a - cant * 5;         if (a - b == 1 or a - b == 2)           answ = answ + 1;         else {           if (a != b) answ = answ + 2;         }         cout << answ <<   n ;         continue;       }       if (b - a > 5) {         int answ = 0;         int cant = (b - a) / 5;         a = a + cant * 5;         answ = answ + cant;         if (b - a == 1 or b - a == 2)           answ = answ + 1;         else {           if (a != b) answ = answ + 2;         }         cout << answ <<   n ;         continue;       }       if (abs(a - b) == 1 or abs(a - b) == 2 or abs(a - b) == 5)         cout << 1 <<   n ;       else         cout << 2 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     char a[n + 2][m + 2];     int flag = 0;     for (long long int i = 0; i <= n + 1; i++) {       for (long long int j = 0; j <= m + 1; j++) {         a[i][j] =  . ;       }     }     for (long long int i = 1; i <= n; i++)       for (long long int j = 1; j <= m; j++) cin >> a[i][j];     for (long long int i = 1; i <= n; i++) {       for (long long int j = 1; j <= m; j++) {         if (a[i][j] ==  S ) {           if (a[i - 1][j] ==  W  || a[i + 1][j] ==  W  || a[i][j - 1] ==  W  ||               a[i][j + 1] ==  W ) {             flag = 1;             break;           }         }         if (a[i][j] ==  W ) {           if (a[i - 1][j] ==  .  || a[i - 1][j] ==  D ) a[i - 1][j] =  D ;           if (a[i + 1][j] ==  .  || a[i + 1][j] ==  D ) a[i + 1][j] =  D ;           if (a[i][j - 1] ==  .  || a[i][j - 1] ==  D ) a[i][j - 1] =  D ;           if (a[i][j + 1] ==  .  || a[i][j + 1] ==  D ) a[i][j + 1] =  D ;         }       }       if (flag == 1) break;     }     if (flag == 1)       cout <<  No             <<   n ;     else {       cout <<  Yes             <<   n ;       for (long long int i = 1; i <= n; i++) {         for (long long int j = 1; j <= m; j++) {           cout << a[i][j];         }         cout <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 6;   const int maxlog = 20;   const long long inf = 1e18;   const int mod = 1e9 + 7;   const long long base = 307;   map<long long, int> cnt1, cnt2;   set<int> st;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int need = (n + 1) / 2;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       cnt1[x]++;       if (y != x) cnt2[y]++;       st.insert(x);       st.insert(y);     }     int ans = mod;     for (set<int>::iterator it = st.begin(); it != st.end(); it++) {       int x = *it;       int kol = cnt1[x] + cnt2[x];       if (kol < need) continue;       int new_need = need - cnt1[x];       ans = min(ans, new_need);     }     if (ans == mod)       cout << -1;     else       cout << max(0, ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n, i, c = 0;     cin >> n;     long long int a[n];     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     for (i = 0; i < n; i++) {       if (a[i] == a[i + 1]) {         c++;         i++;       }     }     cout << c / 2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool prime(int x) {     if (x == 1)       return false;     else if (x == 2)       return true;     for (int i = 2; i * i <= x; i++) {       if (x % i == 0) return false;     }     return true;   }   void fun2(int t) {     if (t == 1) {       cout <<  * ;       return;     }     cout <<  * ;     return fun2(t - 1);   }   void fun(int s) {     map<int, int> asd;     map<int, int>::iterator ir;     ir = asd.begin();     ir->first;     if (s) {       cout << s % 10 << endl;       fun(s / 10);     }   }   long long numb(long long i) {     if (i == 2 || i == 1)       return 1;     else {       long long n = i, z = 0;       while (n > 1) {         if (i % n == 0) {           z++;         }         n--;       }       return z;     }   }   int main() {     std::ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int r1, r2, c1, c2, d1, d2;     cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;     vector<vector<int>> v(2, vector<int>(2));     v[0][0] = (r1 - c2 + d1) / 2;     v[0][1] = r1 - v[0][0];     v[1][0] = c1 - v[0][0];     v[1][1] = d1 - v[0][0];     bool b = true;     for (int i = 0; i < 2; i++) {       for (int j = 0; j < 2; j++) {         for (int h = 0; h < 2; h++) {           for (int g = 0; g < 2; g++) {             if (i == h && j == g) continue;             if (v[i][j] == v[h][g]) {               b = false;             }           }         }       }     }     for (int i = 0; i < 2; i++) {       for (int j = 0; j < 2; j++) {         if (v[i][j] == 0 || v[i][j] > 9) b = false;       }     }     if (r1 != v[0][0] + v[0][1] || r2 != v[1][0] + v[1][1] ||         c1 != v[0][0] + v[1][0] || c2 != v[0][1] + v[1][1] ||         d1 != v[0][0] + v[1][1] || d2 != v[0][1] + v[1][0])       b = false;     if (b) {       for (int i = 0; i < 2; i++) {         for (int j = 0; j < 2; j++) {           cout << v[i][j] <<    ;         }         cout << endl;       }     } else {       cout << -1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<string> s(3e5 + 1);   vector<pair<int, int>> p;   int n;   vector<pair<int, int>> q;   int Kr(int kb, int kn) {     int ans = 0;     for (int i = 0; i < n; i++) {       int r1 = q[i].first - kb;       int r2 = q[i].second - kn;       int r;       if (r1 * r2 >= 0)         r = max(abs(r1), abs(r2));       else         r = abs(r1) + abs(r2);       ans = max(ans, r);     }     return ans;   }   pair<int, int> F(int kb) {     int Fl = 0, Fr = 5e5;     if (!kb) Fl++;     while (Fr - Fl > 2) {       int m1 = Fl + (Fr - Fl) / 3;       int m2 = Fr - (Fr - Fl) / 3;       if (Kr(kb, m1) >= Kr(kb, m2))         Fl = m1;       else         Fr = m2;     }     return min(make_pair(Kr(kb, Fl), Fl), min(make_pair(Kr(kb, Fl + 1), Fl + 1),                                               make_pair(Kr(kb, Fl + 2), Fl + 2)));   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s[i];     }     q.resize(n);     for (int i = 0; i < n; i++) {       int kb = 0;       for (int j = 0; j < s[i].size(); j++) {         if (s[i][j] ==  B ) ++kb;       }       q[i] = {kb, s[i].size() - kb};     }     int l = 0, r = 5e5;     while (r - l > 2) {       int m1 = l + (r - l) / 3;       int m2 = r - (r - l) / 3;       if (F(m1) >= F(m2))         l = m1;       else         r = m2;     }     auto l0 = F(l);     auto l1 = F(l + 1);     auto l2 = F(l + 2);     if (l0 <= l1 && l0 <= l2) {       cout << l0.first <<   n ;       for (int i = 0; i < l; i++) {         cout <<  B ;       }       for (int i = 0; i < l0.second; i++) {         cout <<  N ;       }     } else if (l1 <= l0 && l1 <= l2) {       cout << l1.first <<   n ;       for (int i = 0; i < l + 1; i++) {         cout <<  B ;       }       for (int i = 0; i < l1.second; i++) {         cout <<  N ;       }     } else {       cout << l2.first <<   n ;       for (int i = 0; i < l + 2; i++) {         cout <<  B ;       }       for (int i = 0; i < l2.second; i++) {         cout <<  N ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char** argv) {     long long n;     cin >> n;     long long sum = n * (n + 1) / 2;     if (sum % 2 == 1)       cout << 1;     else       cout << 0;   }


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


#include <bits/stdc++.h>   using namespace std;   using namespace std::chrono;   template <class e, class t, int N>   std::basic_istream<e, t>& operator>>(std::basic_istream<e, t>& in,                                        const e (&literal)[N]) {     std::array<e, N - 1> buffer;     in >> buffer[0];     if (N > 2) in.read(&buffer[1], N - 2);     if (strncmp(&buffer[0], literal, N - 1))       in.setstate(in.rdstate() | std::ios::badbit);     return in;   }   template <class e, class t>   std::basic_istream<e, t>& operator>>(std::basic_istream<e, t>& in,                                        const e& literal) {     e buffer;     in >> buffer;     if (buffer != literal) in.setstate(in.rdstate() | std::ios::badbit);     return in;   }   template <class e, class t, int N>   std::basic_istream<e, t>& operator>>(std::basic_istream<e, t>& in,                                        e (&carray)[N]) {     return std::operator>>(in, carray);   }   template <class t1, class t2>   istream& operator>>(istream& in, pair<t1, t2>& p) {     in >> p.first >> p.second;     return in;   }   template <class t>   istream& operator>>(istream& in, vector<t>& v) {     for (int i = 0; i < v.size(); i++) {       in >> v[i];     }     return in;   }   template <class t>   ostream& operator<<(ostream& out, vector<t>& a) {     for (auto x : a) {       out << x <<    ;     }     return out;   }   template <class t1, class t2>   ostream& operator<<(ostream& out, map<t1, t2>& a) {     for (auto x : a) {       out << x <<    ;     }     return out;   }   template <class t>   ostream& operator<<(ostream& out, set<t>& a) {     for (auto x : a) {       out << x <<    ;     }     return out;   }   template <class t1, class t2>   ostream& operator<<(ostream& out, const pair<t1, t2>& a) {     out << a.first <<     << a.second;     return out;   }   template <class t1, class t2>   pair<t1, t2> operator+(const pair<t2, t1>& a, const pair<t1, t2>& b) {     return {a.first + b.first, a.second + b.second};   }   template <class t1, class t2>   pair<t1, t2> operator-(const pair<t2, t1>& a, const pair<t1, t2>& b) {     return {a.first - b.first, a.second - b.second};   }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }   long long fpow(long long b, long long e, long long m = (long long)(1e9 + 7)) {     long long r = 1;     while (e) {       if (e & 1) r = (r * b) % m;       e >>= 1;       b = (b * b) % m;     }     return r;   }   long long n, m;   vector<long long> a;   long long c[100][100];   long double dp[100][100][100];   void init() {     for (long long i = 0; i < (long long)60; i++)       for (long long j = 0; j < (long long)60; j++)         for (long long k = 0; k < (long long)70; k++) dp[i][j][k] = -2;     for (long long i = 0; i < (long long)51; i++) {       for (long long j = 0; j < (long long)51; j++) {         if (j == 0)           c[i][j] = 1;         else if (i == 0)           c[i][j] = 0;         else           c[i][j] = c[i - 1][j - 1] + c[i - 1][j];       }     }   }   long double solve(long long i, long long k, long long mx) {     if (i == m) return (!k ? mx : 0);     long double& r = dp[i][k][mx];     if (r > -1) return r;     long double p = 1;     r = 0;     for (long long j = 0; j < (long long)k + 1; j++) {       long long len = (j + a[i] - 1) / a[i];       r += (c[k][j] * p * solve(i + 1, k - j, max(mx, len)));       p /= m;     }     return r;   }   int32_t main(int32_t argc, char const* argv[]) {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> m;     a.resize(m);     cin >> a;     init();     cout << setprecision(15) << solve(0, n, 0) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool field[100][100][100];   int n, m, k;   bool check(int x, int y, int z) {     return (x >= 0 && x < n && y >= 0 && y < m && z >= 0 && z < k &&             field[x][y][z]);   }   int main() {     cin.sync_with_stdio(false);     cout.sync_with_stdio(false);     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         for (int x = 0; x < k; x++) {           char v;           cin >> v;           field[i][j][x] = (v ==  1 );         }       }     }     int answer = 0;     for (int x = 0; x < n; x++) {       for (int y = 0; y < m; y++) {         for (int z = 0; z < k; z++) {           if (check(x, y, z)) {             if ((check(x - 1, y, z) && check(x + 1, y, z)) ||                 (check(x, y - 1, z) && check(x, y + 1, z)) ||                 (check(x, y, z - 1) && check(x, y, z + 1))) {               answer++;               continue;             }             if (check(x - 1, y, z) &&                 ((check(x, y + 1, z) && !check(x - 1, y + 1, z)) ||                  (check(x, y, z + 1) && !check(x - 1, y, z + 1)))) {               answer++;               continue;             }             if (check(x, y - 1, z) &&                 ((check(x + 1, y, z) && !check(x + 1, y - 1, z)) ||                  (check(x, y, z + 1) && !check(x, y - 1, z + 1)))) {               answer++;               continue;             }             if (check(x, y, z - 1) &&                 ((check(x, y + 1, z) && !check(x, y + 1, z - 1)) ||                  (check(x + 1, y, z) && !check(x + 1, y, z - 1)))) {               answer++;               continue;             }           }         }       }     }     cout << answer <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   char g[N][N];   int l[N][N], r[N][N], up[N][N], dn[N][N];   int jx[N][N], jy[N][N];   struct Node {     int x, y, len;   };   vector<Node> p;   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %s , g[i] + 1);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (g[i][j] ==  * ) {           l[i][j] = l[i][j - 1] + 1;           up[i][j] = up[i - 1][j] + 1;         }     for (int i = n; i >= 1; i--)       for (int j = m; j >= 1; j--)         if (g[i][j] ==  * ) {           r[i][j] = r[i][j + 1] + 1;           dn[i][j] = dn[i + 1][j] + 1;         }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (g[i][j] ==  * ) {           int len = min(min(l[i][j], r[i][j]), min(up[i][j], dn[i][j]));           if (len > 1) {             Node temp;             temp = (Node){i, j, len - 1};             p.push_back(temp);             jx[i - len + 1][j]++, jx[i + len][j]--;             jy[i][j - len + 1]++, jy[i][j + len]--;           }         }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         jx[i][j] += jx[i - 1][j], jy[i][j] += jy[i][j - 1];     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (g[i][j] ==  *  && !jx[i][j] && !jy[i][j]) {           printf( -1 n );           return 0;         }     printf( %d n , (int)p.size());     for (int i = 0; i < p.size(); i++)       printf( %d %d %d n , p[i].x, p[i].y, p[i].len);     return 0;   }


#include<bits/stdc++.h>   using namespace std;   #define M 105      int frq[M];      int main()   {       int t;       scanf( %d , &t);          while(t--)       {           int n, x;           scanf( %d %d , &n, &x);              memset(frq, 0, sizeof(frq));           for(int i = 1; i <= n; i++)           {               int p;               scanf( %d , &p);                  frq[p]++;           }              vector<int> ans;                         for(int i = 1; i <= 100; i++)           {               while (frq[i] > 1)               {                   ans.push_back(i);                   frq[i]--;               }           }              for(int i = 1; i <= 100; i++)           {               if(frq[i])               {                   ans.push_back(i);                   frq[i]--;               }           }              int ald = 0;           for(int i = 0; i < n; i++)           {               ald += ans[i];               if(ald == x)               {                   swap(ans[i], ans[n-1]);                   break;               }           }              ald = 0;           bool flag = true;           for(int d: ans)           {               ald += d;               if(ald == x)               {                   flag = false;                   break;               }           }              if(!flag) printf( NO n );           else           {               printf( YES n );               for(int d: ans) printf( %d  , d);               printf(  n );           }       }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, x, k = 0;     cin >> n;     vector<int> a;     for (i = 0; i < n; i++) {       cin >> x;       a.push_back(x);     }     sort(a.begin(), a.end());     for (i = 0; i < n; i++) {       if (a[i] % 2 != 0) k++;     }     int y = min(k, n - k);     cout << y <<   n ;     return 0;   }


#include <cstdio>   #include <iostream>   #include <cstring>   #include <algorithm>   #include <vector>   using namespace std;   # define rep(i,a,b) for(int i=(a); i<=(b); ++i)   # define drep(i,a,b) for(int i=(a); i>=(b); --i)   typedef long long int_;   inline int readint(){    int a = 0; char c = getchar(), f = 1;    for(; c< 0 ||c> 9 ; c=getchar())     if(c ==  - ) f = -f;    for(;  0 <=c&&c<= 9 ; c=getchar())     a = (a<<3)+(a<<1)+(c^48);    return a*f;   }   inline void getMin(int &a,const int &b){    if(a > b) a = b;   }      const int Mod = 998244353;   inline void add(int &x,const int &y){    (x += y) >= Mod ? x -= Mod : 0;   }   inline void mul(int &x,const int &y){    x = int_(x)*y%Mod;   }   int inv[4] = {0,1,(Mod+1)/2,(Mod+1)/3};   inline int C(const int &n,const int &m){    int res = 1;    rep(i,1,m) mul(res,inv[i]);    rep(i,0,m-1) mul(res,n-i);    return res;   }      const int MaxN = 1000005;   const int infty = (1<<30)-1;   int dp[MaxN][4]; // prefix sum      int main(){    int n = readint(), x;    dp[0][0] = 1; // only one node    rep(i,1,n) rep(j,0,3){     rep(k,x=0,2) // at most 2      add(x,dp[i-1][k]);     dp[i][j] = C(j+x-1,j);    }    drep(i,n,1) rep(j,0,3) // get origin value     add(dp[i][j],Mod-dp[i-1][j]);    int ans = 0;    rep(i,1,n) rep(j,2,3) rep(k,0,3-j)     add(ans,1ll*dp[i][j]*dp[n-i][k]%Mod);    rep(j,0,3) add(ans,dp[n][j]);    printf( %d n ,ans);    return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     return x * f;   }   const long long MAXN = 100010;   const long long INF = 2147483600;   long long N;   long long a[MAXN + 1];   int f[63][MAXN + 1];   int p[MAXN + 1], id[MAXN + 1], nwp[MAXN + 1];   int t[2];   long long sta[2][MAXN + 1];   int cnt[2];   inline void Sort(long long x) {     t[0] = t[1] = 0;     for (long long i = 1; i <= N; i++) {       long long d = (a[p[i]] >> x) & 1;       sta[d][++t[d]] = p[i];     }     for (long long i = 1; i <= t[1]; i++) p[i] = sta[1][i];     for (long long i = 1; i <= t[0]; i++) p[i + t[1]] = sta[0][i];     return;   }   int main() {     N = read();     for (long long i = 1; i <= N; i++) {       a[i] = read();     }     memset(f, 127, sizeof(f));     for (long long i = 1; i <= N; i++) p[i] = i;     Sort(0);     f[0][0] = t[0];     f[0][t[1]] = min(f[0][t[1]], t[1]);     for (long long i = 1; i <= 62; i++) {       for (long long j = 1; j <= N; j++) id[j] = p[j];       Sort(i);       cnt[0] = cnt[1] = 0;       for (long long j = 1; j <= N; j++) nwp[p[j]] = j;       int mx1 = 0, mx0 = 0;       for (long long j = 0; j <= N; j++) {         if (j) {           long long x = (a[id[j]] >> i) & 1;           ++cnt[x];           if (x) mx1 = max(mx1, nwp[id[j]]);           mx0 = max(mx0, nwp[id[j]]);         }         if (f[i - 1][j] <= i * N) {           f[i][mx1] = min(f[i][mx1], f[i - 1][j] + cnt[1] + t[0] - cnt[0]);           f[i][max(t[1], mx0)] =               min(f[i][max(t[1], mx0)], f[i - 1][j] + cnt[0] + t[1] - cnt[1]);         }       }     }     printf( %d n , f[62][0]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x, q;   vector<int> adj[205];   bool visited[205];   void dfs(int n) {     visited[n] = 1;     for (int i = 0; i < adj[n].size(); i++) {       if (!visited[adj[n][i]]) {         visited[adj[n][i]] = 1;         dfs(adj[n][i]);       }     }   }   int main() {     int n, m;     cin >> n >> m;     bool flag = 0;     for (int i = m + 1; i <= n + m; i++) {       cin >> q;       while (q--) {         cin >> x;         if (x) {           flag = 1;         }         adj[i].push_back(x);         adj[x].push_back(i);       }     }     if (!flag) {       cout << n << endl;       return 0;     }     int ans = -1;     for (int i = m + 1; i <= n + m; i++) {       if (!visited[i]) {         dfs(i);         ans++;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   string ar[] = { zero ,     one ,      two ,        three ,     four ,                   five ,     six ,      seven ,      eight ,     nine ,                   ten ,      eleven ,   twelve ,     thirteen ,  fourteen ,                   fifteen ,  sixteen ,  seventeen ,  eighteen };   string br[] = {  ,       ten ,    twenty ,   thirty ,  forty ,                   fifty ,  sixty ,  seventy ,  eighty ,  ninety };   int main() {     int q = 1;     while (q--) {       int n;       cin >> n;       if (n <= 18) {         cout << ar[n];         continue;       }       if (n < 20) {         cout << ar[n % 10] <<  teen ;         continue;       }       int f = n / 10;       if (n % 10 == 0) {         cout << br[f];         continue;       }       cout << br[f] <<  -  << ar[n % 10];     }   }


#include <bits/stdc++.h>   using ll = long long int;   using namespace std;   struct custom_hash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   bool printSub(int a[], int sum) {     if (sum == 0) return true;     if (sum < 0) return false;     for (int i = 0; i < 3; ++i) {       int rem = sum - a[i];       if (printSub(a, rem)) {         cout << a[i] <<    ;         return true;       }     }   }   void solve() {     int n, ans = 0;     cin >> n;     int a[n];     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 30; i > 0; --i) {       int sum = 0;       for (int j = 0; j < n; ++j) {         if (a[j] > i) {           sum = 0;         } else           sum = max(a[j], sum + a[j]);         ans = max(ans, sum - i);       }     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, s;     cin >> n >> s;     int a[s];     memset(a, 0, sizeof a);     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       a[x - 1] = max(a[x - 1], y);     }     int t = 0;     for (int i = 0; i < s; i++) {       t += max(a[s - i - 1] - t, 0);       t++;     }     cout << t << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char grid[105][105];   int dix[] = {-1, 1, 0, 0}, diy[] = {0, 0, -1, 1}, par[105][105], col[105][105],       n, m;   char ddd[] =  UDLR ;   vector<int> vec;   void dfs(int xx, int yy) {     int i, p, q;     col[xx][yy] = 1;     for (i = 0; i < 4; i++) {       p = xx + dix[i];       q = yy + diy[i];       if (p >= 0 && p < n && q >= 0 && q < m && grid[p][q] !=  *  && !col[p][q]) {         par[p][q] = i;         dfs(p, q);       }     }     return;   }   int main() {     int i, j, k, p, q, x, y;     scanf( %d %d , &n, &m);     for (i = 0; i < n; i++) scanf( %s , grid[i]);     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         if (grid[i][j] ==  F ) p = i, q = j;       }     }     dfs(0, 0);     while (p || q) {       vec.push_back(par[p][q]);       y = par[p][q];       p -= dix[y], q -= diy[y];     }     reverse(vec.begin(), vec.end());     for (i = 0; i < vec.size(); i++) {       printf( %c n , ddd[vec[i]]);       fflush(stdout);       scanf( %d %d , &x, &y);       x--, y--;       if (p == x && q == y) {         swap(ddd[vec[i]], ddd[vec[i] - 1]);         i--;       }       p = x, q = y;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int q;     cin >> q;     for (int k = 0; k < q; ++k) {       string s, t;       cin >> s >> t;       vector<bool> a(26), b(26);       for (int i = 0; i < s.size(); ++i) {         a[s[i] -  a ] = true;         b[t[i] -  a ] = true;       }       bool flag = false;       for (int i = 0; i < 26; ++i) {         if (a[i] && b[i]) {           flag = true;           break;         }       }       if (flag)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct T {     T *l, *r;     long long d, sum, mx;     bool pushed;     void recalc(long long len, long long d) {       this->d = d;       sum = len * d;       mx = max(0ll, sum);     }     T(long long len, long long d) {       l = r = 0;       this->d = d;       sum = len * d;       mx = max(0ll, sum);       pushed = 0;     }     void push(int l, int r) {       if (!pushed) return;       int m = (l + r) / 2;       this->l->recalc(m + 1 - l, d);       this->r->recalc(r + 1 - m, d);       this->l->pushed = 1;       this->r->pushed = 1;       pushed = 0;     }     void upd(int l, int r, int tl, int tr, long long x) {       if (r < tl || tr < r) return;       if (tl <= l && r <= tr) {         d = x;         sum = (r - l + 1) * d;         mx = max(0ll, sum);         pushed = 1;       }       int m = (l + r) / 2;       if (!this->l) this->l = new T(m - l + 1, d);       if (!this->r) this->r = new T(r - m + 1, d);       push(l, r);       this->l->upd(l, m, tl, tr, x);       this->r->upd(m + 1, r, tl, tr, x);       sum = this->l->sum + this->r->sum;       mx = max(this->l->mx, this->l->sum + this->r->mx);     }   };   int main() {     long long n;     cin >> n;     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) {         while (n % i == 0) n /= i;         return cout << (n == 1 ? i : 1), 0;       }     }     cout << n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 5, M = N * 3;   int n, i, j, l, r, scnt, s1;   bool bb[M];   int w1[M], bbel[M];   unsigned long long w2[M];   struct seg {     int l, r, c, bel;     bool operator<(const seg& rhs) const { return r < rhs.r; }   };   set<seg> S;   vector<int> ve[N], in[N], out[N];   void del(seg s) {     S.erase(s);     out[i].push_back(s.c);   }   void ins(seg s) {     s.c = ++scnt;     w1[scnt] = s.r - s.l + 1;     w2[scnt] = 1ll * w1[scnt] * s.bel;     bbel[scnt] = s.bel;     S.insert(s);     in[i].push_back(s.c);     ve[s.bel].push_back(s.c);   }   unsigned long long s2, s3, s4, k;   void rmv(int x) {     if (bb[x]) bb[x] = 0, s1 -= w1[x], s2 -= w2[x];   }   void calc(int lm) {     s1 = s2 = s3 = s4 = 0;     memset(bb + 1, 0, scnt);     for (i = 1, j = 0; i <= n; ++i) {       for (int x : out[i]) rmv(x);       for (int x : in[i])         if (bbel[x] >= j) bb[x] = 1, s1 += w1[x], s2 += w2[x];       for (; s1 > lm || !j; ++j)         for (int x : ve[j]) rmv(x);       s3 += s2 - 1ll * s1 * (j - 1);       s4 += i - j + 1;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     S.insert((seg){1, 1 << 30, 0, 0});     for (i = 1; i <= n; ++i) {       cin >> l >> r;       --r;       auto it = S.lower_bound((seg){0, l, 0, 0});       if (it->l < l) ins((seg){it->l, l - 1, 0, it->bel});       if (it->r >= r) {         seg tmp = *it;         del(*it);         if (r < tmp.r) tmp.l = r + 1, ins(tmp);       } else {         for (; it != S.end() && it->r <= r;) del(*it++);         if (it != S.end() && it->l <= r) {           seg tmp = *it;           del(*it);           tmp.l = r + 1;           ins(tmp);         }       }       ins((seg){l, r, 0, i});     }     calc(1 << 30);     unsigned long long ts3 = s3;     k = s4 - k;     int le = 0, ri = 1e9, mid;     for (; le < ri;) {       mid = le + ri >> 1;       calc(mid);       if (s4 >= k)         ri = mid;       else         le = mid + 1;     }     calc(le);     cout << ts3 - (s3 - 1ll * (s4 - k) * le) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int w, h;   char g[100][100], d[100][100];   bool use[100][100];   int dx[] = {-1, 0, 1, 0};   int dy[] = {0, -1, 0, 1};   bool is_valid(int y, int x) { return 0 <= y && y < h && 0 <= x && x < w; }   bool check() {     for (int i = 0; i < h; i++) {       for (int j = 0; j < w; j++) {         if (g[i][j] ==  B  && !use[i][j]) return true;       }     }     return false;   }   void dfs(int y, int x, int dir, bool can) {     if (!is_valid(y, x)) return;     if (g[y][x] ==  W ) return;     use[y][x] = true;     if (!can)       dfs(y + dy[dir], x + dx[dir], dir, can);     else {       dfs(y + dy[dir], x + dx[dir], dir, can);       for (int i = 0; i < 4; i++) {         if (i == dir) continue;         dfs(y + dy[i], x + dx[i], i, false);       }     }     return;   }   int main() {     cin >> h >> w;     for (int i = 0; i < h; i++) {       for (int j = 0; j < w; j++) {         cin >> g[i][j];         d[i][j] = g[i][j];       }     }     for (int i = 0; i < h; i++) {       for (int j = 0; j < w; j++) {         memset(use, 0, sizeof(use));         if (g[i][j] ==  W ) continue;         for (int k = 0; k < 4; k++) {           dfs(i, j, k, true);         }         if (check()) {           cout <<  NO  << endl;           return 0;         }       }     }     cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   const double PI = acos(-1.0);   using namespace std;   const double EPS = 1e-9;   const int N = 5e5 + 9;   int n, mem[3009][2 * 3009], nxt[3009];   pair<int, int> a[3009];   bool com(pair<int, int> a, pair<int, int> b) {     if (a.first < b.first)       return 1;     else if (a.first == b.first) {       if (a.second > b.second)         return 1;       else         return 0;     } else       return 0;   }   int dp(int l, int mx) {     if (l > n || a[l].first > mx) return 0;     int& ret = mem[l][mx];     if (~ret) return ret;     ret = dp(l + 1, mx);     if (a[l].second <= mx)       ret = max(ret, 1 + dp(l + 1, a[l].second) + dp(nxt[l], mx));     return ret;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       cin >> n;       map<int, int> mp;       for (int i = 1; i <= n; i++) {         cin >> a[i].first >> a[i].second;         mp[a[i].first];         mp[a[i].second];       }       int id = 0;       for (auto& p : mp) p.second = ++id;       for (int i = 1; i <= n; i++) {         a[i].first = mp[a[i].first];         a[i].second = mp[a[i].second];       }       sort(a + 1, a + 1 + n, com);       for (int i = 1; i <= n; i++) {         nxt[i] = n + 1;         for (int j = i + 1; j <= n; j++) {           if (a[j].first > a[i].second) {             nxt[i] = j;             break;           }         }       }       for (int i = 0; i <= n + 2; i++)         for (int j = 0; j <= n * 2 + 9; j++) mem[i][j] = -1;       cout << dp(1, n * 2 + 2) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dis[10001][1001];   int pos[10001];   int g, r, n, m;   void bfs() {     deque<pair<int, pair<int, int> > > fila;     fila.push_front({0, {0, 0}});     while (!fila.empty()) {       int v = fila.front().first;       int s = fila.front().second.first;       int t = fila.front().second.second;       fila.pop_front();       if (dis[v][s] != -1) continue;       dis[v][s] = t;       if (v) {         if (s < g and s + (pos[v] - pos[v - 1]) <= g and             dis[v - 1][s + (pos[v] - pos[v - 1])] == -1) {           fila.push_front({v - 1, {s + (pos[v] - pos[v - 1]), t}});         }       }       if (v < m - 1) {         if (s < g and s + (pos[v + 1] - pos[v]) <= g and             dis[v + 1][s + (pos[v + 1] - pos[v])] == -1) {           fila.push_front({v + 1, {s + (pos[v + 1] - pos[v]), t}});         }       }       if (s == g and dis[v][0] == -1) {         fila.push_back({v, {0, t + 1}});       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     memset(dis, -1, sizeof(dis));     cin >> n >> m;     int l[m];     for (int i = 0; i < m; i++) cin >> l[i];     sort(l, l + m);     for (int i = 0; i < m; i++) pos[i] = l[i];     cin >> g >> r;     bfs();     int res = -1;     for (int i = 0; i < m - 1; i++) {       if (dis[i][0] == -1) continue;       if ((pos[m - 1] - pos[i]) > g) continue;       int atual = dis[i][0] * (g + r) + (pos[m - 1] - pos[i]);       if (res == -1)         res = atual;       else         res = min(res, atual);     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 8e4 + 10;   const long long mod = 998244353, modg = 3, modi = 332748118;   int a[maxn], b[maxn];   int pow_mod(int a, int b) {     int ans = 1;     while (b) {       if (b & 1) ans = (long long)ans * a % mod;       a = (long long)a * a % mod, b >>= 1;     }     return ans;   }   int add(int a, int b) {     a += b;     if (a > mod) return a - mod;     return a;   }   int sub(int a, int b) {     a -= b;     if (a < 0) return a + mod;     return a;   }   class nubmer {    public:     int rev[maxn], len, pw;     long long wt[2][maxn];     void init_0() {       int len = 1;       while (len <= maxn / 2) len <<= 1;       for (int mid = 1; mid < len; mid <<= 1) {         long long wn1 = pow_mod(modg, (mod - 1) / (mid << 1));         long long wn2 = pow_mod(modi, (mod - 1) / (mid << 1));         wt[0][mid] = wt[1][mid] = 1;         long long wt1 = wn1, wt2 = wn2;         for (int j = 1; j <= mid; ++j) {           wt[0][mid + j] = wt1;           wt1 = wt1 * wn1 % mod;           wt[1][mid + j] = wt2;           wt2 = wt2 * wn2 % mod;         }       }     }     void init(int n) {       len = 1;       pw = 0;       while (len <= n) len <<= 1, pw++;       for (int i = 0; i <= len - 1; ++i)         rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (pw - 1));     }     void transform(int *a, int flag) {       int f = flag == 1 ? 0 : 1;       for (int i = 0; i <= len - 1; ++i)         if (i < rev[i]) swap(a[i], a[rev[i]]);       for (int mid = 1; mid < len; mid <<= 1) {         for (int r = mid << 1, j = 0; j < len; j += r) {           long long *p = wt[f] + mid;           int *p1 = a + j, *p2 = a + j + mid;           for (int k = 0; k < mid; ++k, ++p, ++p1, ++p2) {             int x = *p1, y = (*p) * (*p2) % mod;             *p1 = add(x, y), *p2 = sub(x, y);           }         }       }       if (flag == -1) {         long long inv = pow_mod(len, mod - 2);         for (int i = 0; i <= len; i++) {           a[i] = a[i] * inv % mod;           if (a[i] < 0) a[i] += mod;         }       }     }   } ntt;   int n, k;   int s1[maxn], s2[maxn];   vector<int> solve(int l, int r) {     if (l == r) {       return vector<int>{1, s2[l]};     }     int mid = (l + r) >> 1;     vector<int> x = solve(l, mid), y = solve(mid + 1, r);     ntt.init(x.size() + y.size());     for (int i = 0; i <= ntt.len + 5; i++) a[i] = 0, b[i] = 0;     for (int i = 0; i < x.size(); i++) a[i] = x[i];     for (int i = 0; i < y.size(); i++) b[i] = y[i];     ntt.transform(a, 1);     ntt.transform(b, 1);     for (int i = 0; i < ntt.len; i++) a[i] = (long long)a[i] * b[i] % mod;     ntt.transform(a, -1);     int len = x.size() + y.size();     int mi = min(ntt.len, min(k + 1, len));     vector<int> ans(mi);     for (int i = 0; i < mi; i++) {       ans[i] = a[i];     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ntt.init_0();     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> s1[i];     }     int T;     cin >> T;     vector<int> tmp;     while (T--) {       int flag;       cin >> flag;       if (flag == 1) {         int q, i, d;         cin >> q >> i >> d;         for (int j = 1; j <= n; j++) s2[j] = sub(q, s1[j]);         s2[i] = sub(q, d);         tmp = solve(1, n);         cout << tmp[k] <<   n ;       } else {         int q, l, r, d;         cin >> q >> l >> r >> d;         for (int j = 1; j <= n; j++) {           if (j >= l && j <= r)             s2[j] = sub(sub(q, s1[j]), d);           else             s2[j] = sub(q, s1[j]);         }         tmp = solve(1, n);         cout << tmp[k] <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   inline void in(int &x) { scanf( %d , &x); }   inline void in(int &x, int &y) { scanf( %d %d , &x, &y); }   inline void in(int &x, int &y, int &z) { scanf( %d %d , &x, &y, &z); }   inline void out(int x) { printf( %d  , x); }   inline void outln(int x) { printf( %d n , x); }   inline void outln(int x, int y) { printf( %d %d n , x, y); }   inline int _abs(int x) { return x > 0 ? x : -x; }   const int SIZE = (int)1e7 + 10;   int n, m;   int a[SIZE], b[SIZE], minp[SIZE];   int pa[SIZE], pb[SIZE];   void precalc() {     for (int i = 2; i * i < SIZE; ++i) {       if (!minp[i]) {         for (int j = i * i; j < SIZE; j += i) {           if (!minp[j]) minp[j] = i;         }       }     }     for (int i = 2; i < SIZE; ++i)       if (!minp[i]) minp[i] = i;   }   void factor(int *mas, int val) {     for (; val != 1; val /= minp[val]) {       ++mas[minp[val]];     }   }   void output(int *a, int *pa, int size) {     for (int i = 0; i < (int)(size); i++) {       int val = a[i], res = 1;       for (; val != 1; val /= minp[val]) {         if (pa[minp[val]])           --pa[minp[val]];         else           res *= minp[val];       }       out(res);     }   }   int main() {     precalc();     in(n, m);     for (int i = 0; i < (int)(n); i++) {       in(a[i]);       factor(pa, a[i]);     }     for (int i = 0; i < (int)(m); i++) {       in(b[i]);       factor(pb, b[i]);     }     for (int i = 2; i < SIZE; ++i) {       pa[i] = pb[i] = min(pa[i], pb[i]);     }     outln(n, m);     output(a, pa, n);     printf(  n );     output(b, pb, m);     return 0;   }


#include <bits/stdc++.h>   const int N = 1000005;   std::vector<int> e[N];   int a[N], n, m, x, y, r[N], c[N], id[N], cnt, cnt2, s[N], vis[N];   void dfs(int x) {     if (vis[x]) return;     vis[x] = 1;     for (auto u : e[x]) {       dfs(u);       a[x] |= a[u];     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &x, &y);       e[x].push_back(y);       r[y]++;       c[x]++;     }     for (int i = 1; i <= n; i++)       if (!c[i]) a[i] = 1 << cnt, id[i] = cnt++;     for (int i = 1; i <= n; i++)       if (!r[i]) {         dfs(i);         s[cnt2++] = a[i];       }     for (int i = 1; i < (1 << cnt) - 1; i++) {       int t = 0, S = 0, t2 = 0;       for (int j = 0; j < cnt; j++)         if (i & (1 << j)) t++, S |= s[j];       for (int j = 0; j < cnt; j++)         if (S & (1 << j)) t2++;       if (t2 <= t) {         puts( NO );         return 0;       }     }     puts( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long A, B, n;     cin >> A >> B >> n;     long long i, j;     if (A == 0) {       if (B == 0) {         cout << 0;       } else         cout <<  No solution ;       return 0;     }     if (B % A) {       cout <<  No solution ;       return 0;     }     long long rez = B / A;     if (rez == 1) {       cout << 1;       return 0;     }     if (B == 0) {       cout << 0;       return 0;     }     for (long long i = -1002; i <= 1002; i++) {       long long cur = i;       for (j = 2; j <= n; j++) {         cur *= i;         if (abs(cur) > 1000000000) break;       }       if (cur == rez) {         cout << i;         return 0;       }     }     cout <<  No solution ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void geth(int in, int& out) {     cout << in << endl;     cin >> out;     if (out != 1 && out != -1) {       exit(0);     }   }   int main() {     ios_base::sync_with_stdio(false);     int n, mx;     cin >> mx >> n;     std::vector<int> pp(n);     for (auto&& x : pp) {       geth(1, x);     }     int l = 2;     int r = mx;     int tr = 0;     while (l < r) {       int mid = (l + r) / 2, res;       geth(mid, res);       res *= pp[tr];       if (res > 0) {         l = mid + 1;       } else if (res < 0) {         r = mid - 1;       }       tr = (tr + 1) % n;     }     geth(l, r);   }


#include <bits/stdc++.h>   using namespace std;   map<string, int> sz = {       { S , 0}, { M , 1}, { L , 2}, { XL , 3}, { XXL , 4},   };   string st[5] = { S ,  M ,  L ,  XL ,  XXL };   int a[5];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cerr.tie(nullptr);     for (int i = 0; i < 5; i++) cin >> a[i];     int n;     cin >> n;     while (n--) {       string s;       cin >> s;       int x = sz[s];       int bi = -1, bv = 123123123;       for (int i = 0; i < 5; i++) {         if (!a[i]) continue;         int v = 2 * abs(i - x) + (i < x);         if (v < bv) {           bv = v;           bi = i;         }       }       a[bi]--;       cout << st[bi] <<   n ;     }   }


#include<bits/stdc++.h>   using namespace std;      const int N = 3e5 + 9;   const long long inf = 2e18;      int a[N], c[N], n, m;   long long s1[N], s2[N];      long long f(int mid) {     for (int i = mid; i <= n; i++) {       if (a[i] < i - mid + 1) return 0;     }     return 1;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t; cin >> t;     while (t--) {       cin >> n >> m;       for (int i = 1; i <= n; i++) {         cin >> a[i];       }       for (int i = 1; i <= m; i++) {         cin >> c[i];         s2[i] = s2[i - 1] + c[i];       }       sort(a + 1, a + n + 1);       for (int i = 1; i <= n; i++) {         s1[i] = s1[i - 1] + c[a[i]];       }       int l = 1, r = n; int z = n + 1;       while (l <= r) {         int mid = l + r >> 1;         if (f(mid)) {           z = mid; r = mid - 1;         }         else {           l = mid + 1;         }       }       long long ans = inf;       for (int i = z; i <= n + 1; i++) {         ans = min(ans, s1[i - 1] + s2[n - i + 1]);       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     while (n--) {       unsigned long long a, b, c;       cin >> a >> b >> c;       unsigned long long d;       d = (a * a + (b + c) * (b + c));       d = sqrt(d) - 1;       cout << d <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     ;     unsigned long long x, y;     cin >> x >> y;     if (x < y) {       return cout << -1, 0;     }     if ((x - y) & 1) {       return cout << -1, 0;     }     long long z = (x - y) / 2;     if (y & z) {       cout << -1;       return 0;     }     long long a = z;     long long b = x - z;     if (a > b) swap(a, b);     cout << a <<     << b <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int N, type[100005];   int Tm, in[100005], out[100005];   int par[100005][20];   bool comp[100005][20][2];   vector<int> G[100005];   void dfs(int nd) {     in[nd] = ++Tm;     for (int i = 0; i < G[nd].size(); i++) {       int ch = G[nd][i];       if (ch == par[nd][0]) continue;       comp[ch][0][type[ch]] = 1;       dfs(ch);     }     out[nd] = ++Tm;   }   int LCA(int u, int v) {     if ((in[u] <= in[v] && out[u] >= out[v])) return u;     for (int i = 20 - 1; i >= 0; i--)       if (!(in[par[u][i]] <= in[v] && out[par[u][i]] >= out[v])) u = par[u][i];     return par[u][0];   }   bool get(int u, int lca, int fl) {     if ((in[u] <= in[lca] && out[u] >= out[lca])) return false;     bool x = true;     for (int i = 20 - 1; i >= 0; i--)       if (!(in[par[u][i]] <= in[lca] && out[par[u][i]] >= out[lca])) {         x = x && comp[u][i][fl];         u = par[u][i];       }     x = x && comp[u][0][fl];     return x;   }   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) {       scanf( %d , &par[i][0]);       scanf( %d , &type[i]);       if (par[i][0] != -1) G[par[i][0]].push_back(i);     }     for (int i = 1; i <= N; i++)       if (par[i][0] == -1) {         par[i][0] = i;         dfs(i);       }     for (int i = 1; i < 20; i++)       for (int j = 1; j <= N; j++) {         par[j][i] = par[par[j][i - 1]][i - 1];         for (int fl = 0; fl < 2; fl++)           comp[j][i][fl] = comp[j][i - 1][fl] && comp[par[j][i - 1]][i - 1][fl];       }     int Q;     scanf( %d , &Q);     for (int i = 0; i < Q; i++) {       int tp, u, v;       scanf( %d , &tp);       scanf( %d , &u);       scanf( %d , &v);       int lca = LCA(u, v);       if (v == lca) {         puts( NO );       } else {         if (tp == 1) {           if (u == lca && get(v, lca, 0))             puts( YES );           else             puts( NO );         } else {           if (u == lca && get(v, lca, 1))             puts( YES );           else if (u != lca && get(u, lca, 0) && get(v, lca, 1))             puts( YES );           else             puts( NO );         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> Left;   vector<int> Right;   map<pair<int, int>, int> excep;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie();     cin >> n;     for (int i = 0; i < n; i++) {       int l, r;       cin >> l >> r;       Left.push_back(l);       Right.push_back(r);       excep[{l, r}] = 1;     }     sort(Left.begin(), Left.end(), greater<int>());     sort(Right.begin(), Right.end());     if (excep[{Left[0], Right[0]}] == 1)       cout << max(0, Right[1] - Left[1]);     else       cout << max(0, max(Right[0] - Left[1], Right[1] - Left[0]));   }


#include <bits/stdc++.h>   using namespace std;   long long int n, k;   vector<long long int> od, ev;   long long int dps[200005], dpd[200005];   void buildDp() {     dps[0] = 0LL;     dps[1] = k - 1;     dpd[0] = 1LL;     dpd[1] = k - 2;     for (int i = 2; i < 200005; i++) {       dps[i] = ((dps[i - 2] * (k - 1)) % 998244353LL +                 ((dps[i - 1] * (k - 2)) % 998244353LL)) %                998244353LL;       dpd[i] = ((dpd[i - 2] * (k - 1)) % 998244353LL +                 ((dpd[i - 1] * (k - 2)) % 998244353LL)) %                998244353LL;     }   }   vector<pair<long long int, int>> p;   long long int solve(vector<long long int> v) {     p.clear();     long long int ans = 1LL;     int vz = (int)v.size();     if (vz == 0) return 1LL;     for (int i = 0; i < vz; i++)       if (v[i] != -1) p.push_back(make_pair(v[i], i));     int pz = (int)p.size();     if (pz > 0) {       long long int nf = p[0].second;       long long int nb = vz - 1 - p[pz - 1].second;       for (int i = 0; i < nf; i++) ans = (ans * (k - 1)) % 998244353LL;       for (int i = 0; i < nb; i++) ans = (ans * (k - 1)) % 998244353LL;       if (pz >= 2) {         for (int i = 0; i < pz - 1; i++) {           int gap = p[i + 1].second - p[i].second - 1;           if (p[i].first == p[i + 1].first)             ans = (ans * dps[gap]) % 998244353LL;           else             ans = (ans * dpd[gap]) % 998244353LL;         }       }     } else {       ans = k;       for (int i = 0; i < vz - 1; i++) ans = (ans * (k - 1)) % 998244353LL;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(0);     ;     cin >> n >> k;     for (int i = 0; i < n; i++) {       long long int temp;       cin >> temp;       if (i & 1LL)         od.push_back(temp);       else         ev.push_back(temp);     }     buildDp();     cout << (solve(ev) * solve(od)) % 998244353LL;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC diagnostic ignored  -Wmissing-declarations    inline int safe_mul(const int x, const int y)       __attribute__((warn_unused_result));   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     vector<int> a(n);     for (int& x : a) cin >> x;     int const inf = 200001;     vector<vector<int>> te(inf + 2);     for (int i = 0; i < m; ++i) {       int d, t;       cin >> d >> t;       te[d].push_back(t - 1);     }     int l = 0;     int r = inf;     while (r - l > 1) {       int mid = (l + r) >> 1;       auto tmpa = a;       int val = mid;       int sum = 0;       for (int i = mid; i >= 1; --i) {         for (int x : te[i]) {           int cur = min(val, i);           int need = min(tmpa[x], cur);           cur -= need;           val = min(val, cur);           tmpa[x] -= need;           sum += need;         }       }       if (accumulate(begin(tmpa), end(tmpa), 0LL) * 2 <= mid - sum)         r = mid;       else         l = mid;     }     if (r == inf) {       int mid = inf - 1;       auto tmpa = a;       int val = mid;       int64_t sum = 0;       for (int i = mid; i >= 1; --i) {         for (int x : te[i]) {           int cur = min(val, i);           int need = min(tmpa[x], cur);           cur -= need;           val = min(val, cur);           tmpa[x] -= need;           sum += need;         }       }       sum += accumulate(begin(tmpa), end(tmpa), 0LL) * 2;       cout << sum << endl;     } else {       cout << r << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2 * 200000;   const int MAXM = 199999 * 2 * 2 + 200000 * 2;   int n, m, a, b;   string s[2];   int dsu[MAXN];   int to[MAXM], head[MAXN], nxt[MAXM], E;   int p[MAXN][19];   int d[MAXN];   int tin[MAXN], tout[MAXN], timer;   inline int root(int x) { return ~dsu[x] ? dsu[x] = root(dsu[x]) : x; }   inline void merge(int a, int b) { dsu[root(a)] = root(b); }   inline void addEdge(int a, int b) {     to[E] = b;     nxt[E] = head[a];     head[a] = E++;     to[E] = a;     nxt[E] = head[b];     head[b] = E++;     merge(a, b);   }   void dfs(int v, int par, int dist = 0) {     tin[v] = ++timer;     p[v][0] = par;     d[v] = dist;     for (int i = 1; i < 19; ++i) p[v][i] = p[p[v][i - 1]][i - 1];     for (int i = head[v]; ~i; i = nxt[i]) {       if (to[i] != par) {         dfs(to[i], v, dist + 1);       }     }     tout[v] = ++timer;   }   bool ancestor(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; }   int lca(int a, int b) {     if (ancestor(a, b)) return a;     if (ancestor(b, a)) return b;     for (int i = 18; i > -1; --i)       if (!ancestor(p[a][i], b)) a = p[a][i];     return p[a][0];   }   int Distance(int a, int b) {     int c = lca(a, b);     return d[a] + d[b] - 2 * d[c];   }   int dist(int a, int b) {     if (root(a) != root(b)) return -1;     int d1, d2;     d1 = Distance(a, b);     if (b < n)       d2 = Distance(a, b + n);     else       d2 = Distance(a, b - n);     return min(d1, d2 + 1);   }   int main() {     ios_base::sync_with_stdio(false);     memset(dsu, 0xff, sizeof dsu);     memset(head, 0xff, sizeof head);     cin >> n >> m;     cin >> s[0] >> s[1];     for (int i = 0; i < n; ++i) {       if (s[0][i] ==  . ) {         if (s[1][i] ==  .  &&             (i + 1 == n || max(s[0][i + 1], s[1][i + 1]) ==  X ))           addEdge(i, n + i);         if (i + 1 != n && s[0][i + 1] ==  . ) addEdge(i, i + 1);       }       if (s[1][i] ==  .  && i + 1 != n && s[1][i + 1] ==  . )         addEdge(n + i, n + i + 1);     }     for (int i = 0; i < 2 * n; ++i)       if (root(i) == i) dfs(i, i);     while (m-- > 0) {       cin >> a >> b;       --a, --b;       if (a % n > b % n) swap(a, b);       cout << dist(a, b) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void Read(T &x) {     char c = getchar();     bool f = false;     for (x = 0; !isdigit(c); c = getchar()) {       if (c ==  - ) {         f = true;       }     }     for (; isdigit(c); c = getchar()) {       x = x * 10 + c -  0 ;     }     if (f) {       x = -x;     }   }   template <typename T>   inline bool CheckMax(T &a, const T &b) {     return a < b ? a = b, true : false;   }   template <typename T>   inline bool CheckMin(T &a, const T &b) {     return a > b ? a = b, true : false;   }   const int N = 205;   unsigned int ans, mod, c[N][N], f[N][N], s[N][N];   int n, m;   int main() {     Read(n), Read(m), Read(mod);     for (int i = 0; i <= n; ++i) {       c[i][0] = 1;       for (int j = 1; j <= i; ++j) {         c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;       }     }     f[1][0] = 1;     for (int i = 0; i <= m; ++i) {       s[1][i] = 1;     }     for (int i = 2; i <= n; ++i) {       for (int j = 1; j < i; ++j) {         for (int k = 0; k < m; ++k) {           f[i][k + 1] = (1LL * s[j][m - 1] * c[i - 2][j - 1] % mod * f[i - j][k] +                          f[i][k + 1]) %                         mod;         }       }       for (int j = 1; j <= m; ++j) {         s[i][j] = (s[i][j - 1] + f[i][j]) % mod;       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j <= m; ++j) {         for (int k = 0; j + k <= m; ++k) {           if (k != 1) {             ans = (1LL * f[i + 1][j] * f[n - i][k] + ans) % mod;           }         }       }     }     ans = 2LL * n * (n - 1) * ans % mod;     printf( %u n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const xn = 1e4 + 105, xm = 105;   int n, m, cnt, hd[xn], ct, to[xn], nxt[xn], w[xn], s1, s2, f;   long long dis[2][xn], inf = 1e17;   bool vis[xn];   struct E {     int u, v, bh, l, r, w;   } ed[xm];   struct N {     long long d;     int id;     N(long long d = 0, int i = 0) : d(d), id(i) {}     bool operator<(const N &y) const { return d > y.d; }   };   priority_queue<N> q;   int rd() {     int ret = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = 0;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) ret = ret * 10 + ch -  0 , ch = getchar();     return f ? ret : -ret;   }   void add(int x, int y, int z) {     to[++ct] = y;     nxt[ct] = hd[x];     hd[x] = ct;     w[ct] = z;   }   void dij(int t) {     for (int i = 1; i <= n; i++) dis[t][i] = inf;     for (int i = 1; i <= n; i++) vis[i] = 0;     int st = (t ? s2 : s1);     dis[t][st] = 0;     q.push(N(0, st));     while (q.size()) {       int x = q.top().id;       q.pop();       if (vis[x]) continue;       vis[x] = 1;       for (int i = hd[x], u; i; i = nxt[i])         if (dis[t][u = to[i]] > dis[t][x] + w[i]) {           dis[t][u] = dis[t][x] + w[i];           q.push(N(dis[t][u], u));         }     }   }   int main() {     n = rd();     m = rd();     cnt = rd();     s1 = rd();     s2 = rd();     f = rd();     for (int i = 1, x, y, z; i <= m; i++)       x = rd(), y = rd(), z = rd(), add(x, y, z);     for (int i = 1; i <= cnt; i++)       ed[i].u = rd(), ed[i].v = rd(), ed[i].l = rd(), ed[i].r = rd(),       ed[i].bh = ct + 1, ed[i].w = 1, add(ed[i].u, ed[i].v, ed[i].r);     dij(0);     dij(1);     while (dis[0][f] >= dis[1][f]) {       int i;       for (i = 1; i <= cnt; i++)         if (dis[0][ed[i].u] <= dis[1][ed[i].u] && ed[i].w) break;       if (i > cnt) {         if (dis[0][f] > dis[1][f])           puts( LOSE );         else {           puts( DRAW );           for (int j = 1; j <= cnt; j++)             printf( %d  , ed[j].w ? ed[j].r : ed[j].l);           puts(  );         }         return 0;       }       ed[i].w = 0;       w[ed[i].bh] = ed[i].l;       dij(0);       dij(1);     }     puts( WIN );     for (int j = 1; j <= cnt; j++) printf( %d  , ed[j].w ? ed[j].r : ed[j].l);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct edg {     int cost, id, parity;     bool operator<(edg other) const { return cost > other.cost; }   };   vector<int> g[1000011 >> 1][2];   int from[1000011], to[1000011], l[1000011], r[1000011];   int N, M;   bool cmp(int &a, int &b) { return l[a] > l[b]; }   int main() {     int i;     priority_queue<edg, vector<edg>, less<edg>> q;     scanf( %d%d , &N, &M);     if (N == 1) {       printf( 0 n );       return 0;     }     for (i = 1; i <= M; ++i) {       scanf( %d%d%d%d , &from[i * 2], &to[i * 2], &l[i * 2], &r[i * 2]);       r[i * 2]--;       from[i * 2 + 1] = to[i * 2];       to[i * 2 + 1] = from[i * 2];       l[i * 2 + 1] = l[i * 2];       r[i * 2 + 1] = r[i * 2];       g[from[i * 2]][0].push_back(i * 2);       g[from[i * 2]][1].push_back(i * 2);       g[to[i * 2]][0].push_back(i * 2 + 1);       g[to[i * 2]][1].push_back(i * 2 + 1);     }     for (i = 1; i <= N; ++i) {       sort(g[i][0].begin(), g[i][0].end(), cmp);       sort(g[i][1].begin(), g[i][1].end(), cmp);     }     while (!g[1][0].empty() && l[g[1][0].back()] == 0) {       edg e = {0, g[1][0].back(), 0};       q.push(e);       g[1][0].pop_back();     }     while (!q.empty()) {       edg curr = q.top();       q.pop();       if (to[curr.id] == N) {         printf( %d n , curr.cost + 1);         return 0;       }       int mxright = r[curr.id] - ((r[curr.id] % 2) != curr.parity);       while (!g[to[curr.id]][curr.parity ^ 1].empty() &&              l[g[to[curr.id]][curr.parity ^ 1].back()] <= mxright + 1) {         int nxtid = g[to[curr.id]][curr.parity ^ 1].back();         int ncost = l[nxtid];         ncost += (ncost % 2 == curr.parity);         ncost = max(ncost, curr.cost + 1);         if (ncost <= r[nxtid]) {           q.push(edg{ncost, nxtid, curr.parity ^ 1});         }         g[to[curr.id]][curr.parity ^ 1].pop_back();       }     }     printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, a, b, t;     string str;     cin >> n >> a >> b >> t >> str;     str += str;     long long len = 1, l = n, r, remain = t - 1 - (str[n] ==  w ) * b, ans = 1;     if (remain < 0) {       cout <<  0 n ;       return 0;     }     while (len < n) {       long long require = 2 * a + 1 + (str[l - 1] ==  w ) * b;       if (remain < require) {         break;       } else {         l--;         len++;         remain -= require;       }     }     for (r = n + 1; r < str.size(); r++) {       remain -= a + 1 + (str[r] ==  w ) * b;       while (r - l + 1 > n || (l < n && remain < 0)) {         remain += 2 * a + 1 + (str[l] ==  w ) * b;         l++;       }       if (l >= n && remain < 0) break;       ans = max(ans, r - l + 1);     }     len = 1, l = r = n, remain = t - 1 - (str[n] ==  w ) * b;     while (len < n) {       long long require = 2 * a + 1 + (str[r + 1] ==  w ) * b;       if (remain < require) {         break;       } else {         r++;         len++;         remain -= require;       }     }     for (l = n - 1; l > 0; l--) {       remain -= a + 1 + (str[l] ==  w ) * b;       while (r - l + 1 > n || (r > n && remain < 0)) {         remain += 2 * a + 1 + (str[r] ==  w ) * b;         r--;       }       if (r <= n && remain < 0) break;       ans = max(ans, r - l + 1);     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   const int INF = (int)1e9;   const long long LINF = (long long)1e18;   const long double PI = 2 * acos((long double)0);   long long gcd(long long a, long long b) {     long long r;     while (b) {       r = a % b;       a = b;       b = r;     }     return a;   }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   long long fpow(long long n, long long k, int p = MOD) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   template <class T>   void setmin(T& a, T val) {     if (a > val) a = val;   }   template <class T>   void setmax(T& a, T val) {     if (a < val) a = val;   }   void addmod(int& a, int val, int p = MOD) {     if ((a = (a + val)) >= p) a -= p;   }   void submod(int& a, int val, int p = MOD) {     if ((a = (a - val)) < 0) a += p;   }   int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }   int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }   const int maxn = 200010;   long long n, d, m;   long long x[maxn];   long long p[maxn];   long long st[4 * maxn];   void build(int node, int L, int R) {     if (L == R) {       st[node] = p[L];       return;     }     build(node << 1, L, (L + R) >> 1);     build((node << 1) + 1, ((L + R) >> 1) + 1, R);     st[node] = min(st[node << 1], st[(node << 1) + 1]);   }   long long query(int node, int l, int r, int L, int R) {     if (l > R || r < L) return LINF;     if (l <= L && r >= R) return st[node];     return min(query(node << 1, l, r, L, (L + R) >> 1),                query((node << 1) + 1, l, r, ((L + R) >> 1) + 1, R));   }   void solve() {     cin >> d >> n >> m;     vector<pair<int, int> > v;     for (int i = (1); i < (m + 1); i++) {       cin >> x[i] >> p[i];       v.push_back(make_pair(x[i], p[i]));     }     sort((v).begin(), (v).end());     for (int i = (1); i < (m + 1); i++) {       x[i] = v[i - 1].first;       p[i] = v[i - 1].second;     }     x[m + 1] = d;     build(1, 0, m + 1);     int cur = 0;     long long ans = 0, r = 0;     while (cur < m + 1) {       if (x[cur] + n < x[cur + 1]) {         cout << -1;         return;       }       int lo = cur + 1, hi = upper_bound(x, x + m + 2, x[cur] + n) - x - 1;       while (lo < hi) {         int mid = (lo + hi) >> 1;         if (query(1, cur + 1, mid, 0, m + 1) > p[cur])           lo = mid + 1;         else           hi = mid;       }       if (query(1, cur + 1, lo, 0, m + 1) <= p[cur]) {         ans += p[cur] * max(0LL, x[lo] - x[cur] - r);         r = max(0LL, x[cur] + r - x[lo]);         cur = lo;       } else {         ans += (n - r) * p[cur];         r = x[cur] + n - x[cur + 1];         cur++;       }     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a == 0) return b;     if (b == 0) return a;     if (a == b) return a;     if (a > b) return gcd(a - b, b);     return gcd(a, b - a);   }   int main() {     long long int n, m;     cin >> n >> m;     long long int a[n + 1], b[m + 1];     for (long long int i = 0; i < n + 1; i++) {       cin >> a[i];     }     for (long long int i = 0; i < m + 1; i++) {       cin >> b[i];     }     if (m > n)       cout <<  0/1 ;     else if (n > m) {       int sign = 1;       if ((a[0] < 0 && b[0] > 0) || (a[0] > 0 && b[0] < 0)) sign = 0;       if (sign == 0)         cout <<  -Infinity ;       else         cout <<  Infinity ;     } else {       int sign = 1;       if ((a[0] < 0 && b[0] > 0) || (a[0] > 0 && b[0] < 0)) sign = 0;       int g = gcd(a[0], b[0]);       a[0] /= g;       b[0] /= g;       if (sign == 1) {         if (a[0] < 0) a[0] = -a[0];         if (b[0] < 0) b[0] = -b[0];         cout << a[0] <<  /  << b[0];       } else {         if (a[0] < 0) a[0] = -a[0];         if (b[0] < 0) b[0] = -b[0];         cout <<  -  << a[0] <<  /  << b[0];       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct heap {     int v, x;   } h[1000010];   int n, m, a[500010];   int tmp, sz, ans, tot;   int v[500010], cnt;   int nxt[500010], pre[500010], pos[500010];   inline int read() {     char ch = getchar();     int f = 1, x = 0;     while (!(ch >=  0  && ch <=  9 )) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + (ch -  0 );       ch = getchar();     }     return x * f;   }   void pushup(int x) {     while (h[x].v < h[x >> 1].v) {       pos[h[x >> 1].x] = x;       swap(h[x], h[x >> 1]);       x = x >> 1;     }     pos[h[x].x] = x;   }   void push(int v, int x) {     sz++;     h[sz].v = v;     h[sz].x = x;     pos[x] = sz;     pushup(sz);   }   void pushdown(int x) {     int to;     while ((x << 1) <= sz) {       to = (x << 1);       if (to < sz && h[to].v > h[to + 1].v) to++;       if (h[x].v > h[to].v) {         pos[h[to].x] = x;         swap(h[to], h[x]);         x = to;       } else         break;     }     pos[h[x].x] = x;   }   void del(int x) {     h[x].v = 0x7fffffff;     pushdown(x);   }   void init() {     m = read();     n = read();     for (int i = 1; i <= n; i++) a[i] = read();     sort(a + 1, a + n + 1);     for (int i = 2; i <= n; i++) {       push(a[i] - a[i - 1], i);       pre[i] = i - 1;       nxt[i] = i + 1;     }     pre[2] = nxt[n] = -1;   }   void solve() {     int a, b;     heap k;     for (int i = 1; i <= m; i++) {       k = h[1];       if (pre[k.x] == -1) {         ans += k.v;         del(1);         del(pos[nxt[k.x]]);         pre[nxt[nxt[k.x]]] = -1;       } else if (nxt[k.x] == -1) {         ans += k.v;         del(1);         del(pos[pre[k.x]]);         nxt[pre[pre[k.x]]] = -1;       } else {         ans += k.v;         a = nxt[k.x];         b = pre[k.x];         pre[k.x] = pre[b];         nxt[pre[b]] = k.x;         nxt[k.x] = nxt[a];         pre[nxt[a]] = k.x;         h[1].v = h[pos[a]].v + h[pos[b]].v - h[1].v;         pushdown(1);         del(pos[a]);         del(pos[b]);       }     }     printf( %d n , ans);   }   int main() {     init();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7, N = 2e5 + 5;   int par[N], over[N];   int getpar(int u) {     if (par[par[u]] == par[u]) return par[u];     return par[u] = getpar(par[u]);   }   bool unite(int a, int b) {     a = getpar(a);     b = getpar(b);     if (a == b) {       if (over[a]) return false;       over[a] += 1;       return true;     } else {       if (over[a] && over[b]) {         return false;       }       par[a] = b;       over[b] += over[a];       return true;     }     assert(false);   }   struct Edge {     int a, b, c;     bool operator<(const Edge &t) const { return c > t.c; }   };   int main() {     iota(par, par + N, 0);     int n, m;     cin >> n >> m;     vector<Edge> edges(m);     for (int i = 0; i < m; ++i)       scanf( %d %d %d , &edges[i].a, &edges[i].b, &edges[i].c);     sort(edges.begin(), edges.end());     int ans = 0;     for (auto cur : edges)       if (unite(cur.a, cur.b)) ans += cur.c;     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   class Solution {     int max_free;     vector<bool> visited;     vector<int> parent;     vector<set<int>> children;     void dfs(int i) {       visited[i] = true;       for (int j : children[i]) {         if (!visited[j]) {           if (i != 0) cout << i <<     << j << endl;           dfs(j);         }       }     }       public:     void solve() {       int n;       cin >> n;       vector<int> a(n);       for (int i = 1; i < n; ++i) scanf( %d , &a[i]);       children = vector<set<int>>(n + 1);       parent = vector<int>(n + 1, -1);       children[0].insert(n);       parent[n] = 0;       max_free = n;       for (int i = 1; i < n; ++i) {         if (parent[a[i]] == -1) {           if (!children[a[i]].empty()) {             max_free--;             while (!children[max_free].empty()) max_free--;           }           if (parent[max_free] != -1) {             int p = parent[max_free];             children[p].erase(max_free);             children[p].insert(a[i]);           }         } else {           max_free--;           while (!children[max_free].empty()) max_free--;         }         children[a[i]].insert(max_free);         parent[max_free] = a[i];       }       cout << a[1] << endl;       visited = vector<bool>(n + 1);       dfs(0);     }   };   int main() {     Solution solution = Solution();     solution.solve();   }