#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   int par[N], ran[N];   struct DSU {     DSU() {       for (int i = 1; i < N; ++i) par[i] = i, ran[i] = 1;     }     int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }     bool unite(int a, int b) {       a = find(a), b = find(b);       if (a == b) return false;       ran[a] += ran[a] == ran[b];       if (ran[a] < ran[b]) swap(a, b);       par[b] = a;       return true;     }   };   int a[N];   int n, q;   vector<int> primes;   int spf[N];   void sieve() {     for (int i = 2; i < N; ++i) {       if (spf[i] == 0) spf[i] = i, primes.push_back(i);       int sz = primes.size();       for (int j = 0; j < sz && i * primes[j] < N && primes[j] <= spf[i]; ++j) {         spf[i * primes[j]] = primes[j];       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     sieve();     cin >> n >> q;     DSU ds;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     for (int i = 1; i <= n; ++i) {       int x = a[i];       while (x > 1) {         ds.unite(spf[a[i]], spf[x]);         x /= spf[x];       }     }     set<pair<int, int>> pary;     for (int i = 1; i <= n; ++i) {       int x = a[i];       vector<int> v;       while (x > 1) {         v.push_back(spf[x]);         x /= spf[x];       }       x = a[i] + 1;       while (x > 1) {         v.push_back(spf[x]);         x /= spf[x];       }       v.resize(unique(v.begin(), v.end()) - v.begin());       for (auto &j : v) {         j = ds.find(j);       }       for (auto j : v) {         for (auto k : v) {           if (j < k) pary.insert({j, k});         }       }     }     while (q--) {       int x, y;       cin >> x >> y;       x = spf[a[x]], y = spf[a[y]];       if (ds.find(x) == ds.find(y))         cout << 0 << endl;       else {         x = ds.find(x);         y = ds.find(y);         if (x > y) swap(x, y);         if (pary.count({x, y}))           cout << 1 << endl;         else           cout << 2 << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T extgcd(T a, T b, T& x, T& y) {     for (T u = y = 1, v = x = 0; a;) {       T q = b / a;       swap(x -= q * u, u);       swap(y -= q * v, v);       swap(b -= q * a, a);     }     return b;   }   template <class T>   T mod_inv(T a, T m) {     T x, y;     extgcd(a, m, x, y);     return (m + x % m) % m;   }   long long mod_pow(long long a, long long n, long long mod) {     long long ret = 1;     long long p = a % mod;     while (n) {       if (n & 1) ret = ret * p % mod;       p = p * p % mod;       n >>= 1;     }     return ret;   }   template <long long mod, long long primitive_root>   class NTT {    public:     long long get_mod() const { return mod; }     void _ntt(vector<long long>& a, long long sign) {       const long long n = ((long long)(a).size());       const long long g = primitive_root;       long long h = (long long)mod_pow(g, (mod - 1) / n, mod);       if (sign == -1) h = (long long)mod_inv(h, mod);       long long i = 0;       for (long long j = 1; j < n - 1; ++j) {         for (long long k = n >> 1; k > (i ^= k); k >>= 1)           ;         if (j < i) swap(a[i], a[j]);       }       for (long long m = 1; m < n; m *= 2) {         const long long m2 = 2 * m;         const long long base = mod_pow(h, n / m2, mod);         long long w = 1;         for (long long x = 0; x < (m); x++) {           for (long long s = x; s < n; s += m2) {             long long u = a[s];             long long d = a[s + m] * w % mod;             a[s] = u + d;             if (a[s] >= mod) a[s] -= mod;             a[s + m] = u - d;             if (a[s + m] < 0) a[s + m] += mod;           }           w = w * base % mod;         }       }       for (auto& x : a)         if (x < 0) x += mod;     }     void ntt(vector<long long>& input) { _ntt(input, 1); }     void intt(vector<long long>& input) {       _ntt(input, -1);       const long long n_inv = mod_inv(((long long)(input).size()), mod);       for (auto& x : input) x = x * n_inv % mod;     }     vector<long long> convolution(const vector<long long>& a,                                   const vector<long long>& b) {       long long ntt_size = 1;       while (ntt_size < ((long long)(a).size()) + ((long long)(b).size()))         ntt_size *= 2;       vector<long long> _a = a, _b = b;       _a.resize(ntt_size);       _b.resize(ntt_size);       ntt(_a);       ntt(_b);       for (long long i = 0; i < (ntt_size); i++) {         (_a[i] *= _b[i]) %= mod;       }       intt(_a);       return _a;     }     vector<long long> powup(const vector<long long>& a, long long exponent) {       long long ntt_size = 1;       while (ntt_size < (((long long)(a).size()) * exponent)) ntt_size *= 2;       vector<long long> _a = a;       _a.resize(ntt_size);       ntt(_a);       for (long long i = 0; i < (ntt_size); i++) {         _a[i] = mod_pow(_a[i], exponent, mod);       }       intt(_a);       return _a;     }   };   vector<long long> mul(vector<long long> a, vector<long long> b, long long mod) {     for (auto& x : a) x %= mod;     for (auto& x : b) x %= mod;     NTT<167772161, 3> ntt1;     NTT<469762049, 3> ntt2;     NTT<1224736769, 3> ntt3;     auto x = ntt1.convolution(a, b);     auto y = ntt2.convolution(a, b);     auto z = ntt3.convolution(a, b);     const long long m1 = ntt1.get_mod(), m2 = ntt2.get_mod(), m3 = ntt3.get_mod();     const long long m1_inv_m2 = mod_inv<long long>(m1, m2);     const long long m12_inv_m3 = mod_inv<long long>(m1 * m2, m3);     const long long m12_mod = m1 * m2 % mod;     vector<long long> ret(((long long)(x).size()));     for (long long i = 0; i < (((long long)(x).size())); i++) {       long long v1 = (y[i] - x[i]) * m1_inv_m2 % m2;       if (v1 < 0) v1 += m2;       long long v2 = (z[i] - (x[i] + m1 * v1) % m3) * m12_inv_m3 % m3;       if (v2 < 0) v2 += m3;       long long constants3 = (x[i] + m1 * v1 + m12_mod * v2) % mod;       if (constants3 < 0) constants3 += mod;       ret[i] = constants3;     }     return ret;   }   vector<long long> exppoly(vector<long long> base, long long e, long long mod) {     vector<long long> ans = {1};     while (e > 0) {       if (e % 2 == 1) {         ans = mul(ans, base, mod);         e--;       } else {         base = mul(base, base, mod);         e /= 2;       }     }     return ans;   }   const long long MOD = 1000000007LL;   int main() {     ios_base::sync_with_stdio(false);     long long a, b, k, t;     cin >> a >> b >> k >> t;     vector<long long> v;     for (long long x = 0; x < 2 * k + 1; x++) v.push_back(1);     vector<long long> got = exppoly(v, t, MOD);     long long len = got.size();     vector<long long> suf = got;     for (long long x = len - 2; x >= 0; x--) suf[x] = (suf[x] + suf[x + 1]) % MOD;     long long ans = 0;     for (long long x = 0; x < len; x++) {       long long me = b + x;       long long youneed = max(0LL, me + 1 - a);       if (youneed >= len) continue;       ans += (got[x] * suf[youneed]);       ans %= MOD;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   bool dp[505][505];   int c[505];   int N, K, a[505], b[505];   long long s1, s2;   int main() {     ios::sync_with_stdio(false);     cin >> N >> K;     for (int i = 1; i <= N; ++i) cin >> a[i] >> b[i], s1 += a[i], s2 += b[i];     dp[0][0] = 1;     for (int i = 0; i < N; ++i) {       for (int j = 0; j < K; ++j) c[j] = 0, dp[i + 1][j] = dp[i][j];       if (a[i + 1] + b[i + 1] >= K)         for (int j = 0; j < K; ++j) {           if (!dp[i][j]) continue;           int l, r;           l = max(1, K - b[i + 1]);           r = min(K - 1, a[i + 1]);           if (l <= r) {             int St, Ed;             St = j + l;             Ed = j + r;             St %= K;             Ed %= K;             c[St]++;             if (Ed >= St) {               c[Ed + 1]--;             } else {               c[0]++;               c[Ed + 1]--;             }           }         }       for (int j = 0; j < K; ++j) {         if (j) c[j] += c[j - 1];         dp[i + 1][j] |= c[j];       }     }     long long res = 0;     for (int j = 0; j < K; ++j) {       if (!dp[N][j]) continue;       long long l1, l2;       l1 = s1, l2 = s2;       l1 -= j;       l2 -= (K - j) % K;       long long cur = bool(j) + (l1 / K) + (l2 / K);       res = max(res, cur);     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char ch;     int n, cnt = 0;     long long x, a;     scanf( %d%I64d , &n, &x);     for (int i = 0; i < n; i++) {       while (isspace(ch = getchar()))         ;       scanf( %I64d , &a);       if (ch ==  + )         x += a;       else {         if (x < a)           cnt++;         else           x -= a;       }     }     cout << x <<     << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int cnt[N];   int n, k;   int cut[N];   vector<pair<int, int> > arr;   struct Sub {     bool operator()(pair<int, pair<int, int> > a, pair<int, pair<int, int> > b) {       if (a.first != b.first)         return a.first < b.first;       else         return (cnt[a.second.second] / (a.second.first + 1)) <                (cnt[b.second.second] / (b.second.first + 1));     }   };   bool ForSort(pair<int, int> a, pair<int, int> b) { return a.first > b.first; }   int main() {     scanf( %d%d , &n, &k);     int tx;     for (int i = 1; i <= n; i++) scanf( %d , &tx), cnt[tx]++;     for (int i = 1; i <= 200000; i++)       if (cnt[i] > 0) arr.push_back({cnt[i], i});     sort(arr.begin(), arr.end(), ForSort);     priority_queue<pair<int, pair<int, int> >,                    vector<pair<int, pair<int, int> > >, Sub>         pq;     int len = 1, ex = arr[0].first;     cut[arr[0].second] = 1;     cout << arr[0].second <<    ;     pq.push(pair<int, pair<int, int> >(arr[0].first,                                        pair<int, int>(1, arr[0].second)));     int i = 1;     pair<int, pair<int, int> > u =         pair<int, pair<int, int> >(2, pair<int, int>(10, 1));     pair<int, pair<int, int> > v =         pair<int, pair<int, int> >(2, pair<int, int>(4, 2));     while (len < k) {       pair<int, pair<int, int> > u = pq.top();       if (i >= arr.size()) {         if (cut[u.second.second] + 1 <= cnt[u.second.second]) {           len++;           cut[u.second.second] = u.second.first + 1;           pq.pop();           cout << u.second.second <<    ;           pq.push(pair<int, pair<int, int> >(               cnt[u.second.second] / (u.second.first + 1),               pair<int, int>(u.second.first + 1, u.second.second)));         } else           pq.pop();       } else {         if (u.second.first + 1 <= cnt[u.second.second] &&             cnt[u.second.second] / (u.second.first + 1) > arr[i].first) {           cut[u.second.second] = u.second.first + 1;           cout << u.second.second <<    ;           len++;           pq.pop();           pq.push(pair<int, pair<int, int> >(               cnt[u.second.second] / (u.second.first + 1),               pair<int, int>(u.second.first + 1, u.second.second)));         } else {           ex = min(ex, arr[i].first);           cut[arr[i].second] = 1;           cout << arr[i].second <<    ;           len++;           pq.push(pair<int, pair<int, int> >(arr[i].first,                                              pair<int, int>(1, arr[i].second)));           i++;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300010;   long long n, a[N], t;   map<long long, bool> vis;   int solve() {     scanf( %lld , &t);     while (t--) {       scanf( %lld , &n);       vis.clear();       bool imp = 0;       for (int i = 1; i <= n; i++) {         scanf( %lld , &a[i]);         long long nw = (i + a[i]) % n;         if (nw < 0) nw += n;         if (vis[nw]) {           imp = 1;         }         vis[nw] = 1;       }       if (imp)         printf( NO n );       else         printf( YES n );     }     return 0;   }   int main() { return solve(); }


#include <bits/stdc++.h>   using namespace std;   void file() {}   void fast() {     std::ios_base::sync_with_stdio(0);     cin.tie(NULL);   }   const int N = 510 + 20;   const double PI = acos(-1.0);   bool cmp(complex<double> a, complex<double> b) {     if (a.real() == b.real()) return a.imag() < b.imag();     return a.real() < b.real();   }   bool cmp_doub(double a, double b) {     if (fabs(a - b) <= 1e-9) {       return 1;     }     return 0;   }   bool is_correct(complex<double> p1, complex<double> p2, complex<double> p3,                   complex<double> p4) {     vector<double> dists;     double dist1 = (hypot((p1 - p2).imag(), (p1 - p2).real()));     double dist2 = (hypot((p2 - p4).imag(), (p2 - p4).real()));     double dist3 = (hypot((p3 - p4).imag(), (p3 - p4).real()));     double dist4 = (hypot((p3 - p1).imag(), (p3 - p1).real()));     double dist5 = (hypot((p2 - p3).imag(), (p2 - p3).real()));     double dist6 = (hypot((p1 - p4).imag(), (p1 - p4).real()));     dists.push_back(dist1);     dists.push_back(dist2);     dists.push_back(dist3);     dists.push_back(dist4);     dists.push_back(dist5);     dists.push_back(dist6);     sort(((dists).begin()), ((dists).end()));     if (dists[0] > 0 && cmp_doub(dists[0], dists[1]) &&         cmp_doub(dists[1], dists[2]) && cmp_doub(dists[2], dists[3]) &&         cmp_doub(dists[3], dists[2])) {       if (cmp_doub(dists[4], dists[5]) && !cmp_doub(dists[5], dists[0])) {         return 1;       }     }     return 0;   }   complex<double> rotate(complex<double> a, complex<double> b, int c) {     for (int i = 0; i < c; i++) {       a = (((((a) - (b))) * exp(complex<double>(0, PI / 2.0))) + b);     }     return a;   }   int main() {     file();     fast();     int n;     cin >> n;     for (int i = 0; i < n; i++) {       vector<pair<complex<double>, complex<double>>> points;       for (int j = 0; j < 4; j++) {         int x, y, z, m;         cin >> x >> y >> z >> m;         points.push_back({complex<double>(x, y), complex<double>(z, m)});       }       int ans = 1e9;       for (int j1 = 0; j1 < 4; j1++) {         for (int j2 = 0; j2 < 4; j2++) {           for (int j3 = 0; j3 < 4; j3++) {             for (int j4 = 0; j4 < 4; j4++) {               vector<complex<double>> points1(4);               points1[0] = rotate(points[0].first, points[0].second, j1);               points1[1] = rotate(points[1].first, points[1].second, j2);               points1[2] = rotate(points[2].first, points[2].second, j3);               points1[3] = rotate(points[3].first, points[3].second, j4);               if (is_correct(points1[0], points1[1], points1[2], points1[3])) {                 ans = min(ans, j1 + j2 + j3 + j4);               }             }           }         }       }       if (ans == 1e9) ans = -1;       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[300001];   const long long mod = 1000000007;   int main(int argc, const char* argv[]) {     string S;     cin >> S;     int n = (int)S.size();     string A(n,  2 );     int scr = 0;     for (int i = 0; i < n; ++i) {       char a = S[(i + n - 1) % n];       char b = S[i];       char c = S[(i + 1) % n];       if (a == b && b == c)         A[i] =  0 ;       else if (a == b && b != c) {         ++scr;         A[i] =  1 ;         A[(i + 1) % n] =  0 ;       } else if (a != b && b == c)         A[i] =  0 ;     }     int fst = 0;     while (fst < n && !(A[fst] !=  2  && A[(fst + 1) % n] ==  2 )) ++fst;     if (fst == n) {       if (A[0] ==  2 )         cout << n / 2 << endl;       else         cout << scr << endl;       return 0;     }     int j = 0;     for (int i = 0; i < n; ++i) {       char a = A[(i + fst) % n];       char b = A[(i + fst + 1) % n];       if (a ==  2  && b !=  2 ) {         scr += (i - j + 1) / 2;       }       if (a !=  2  && b ==  2 ) j = i;     }     cout << scr << endl;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int main() {     int n, a, b, k;     scanf( %d%d%d%d , &n, &a, &b, &k);     int tot = 0;     cin >> s;     int prev = -1;     for (int i = 0; i < n; i++)       if (s[i] ==  1 ) {         tot += (i - prev - 1) / b;         prev = i;       }     tot += (n - prev - 1) / b;     int ans = tot - a + 1;     printf( %d n , ans);     int cnt = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  1 ) {         cnt = 0;       } else {         cnt++;       }       if (cnt == b && ans) {         ans--;         printf( %d  , i + 1);         cnt = 0;       }     }     printf(  n );     return 0;   }


#include<bits/stdc++.h>   using namespace std;   typedef long long ll;   typedef unsigned long long ull;   const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   const int inf = 0x3f3f3f3f;   const ll linf = 0x3f3f3f3f3f3f3f3f;   const ll mod = 1e9 + 7;   //const ll mod = 998244353;       ll ksm(ll x,ll k) {    ll ret=1;    while(k) {     if(k&1) ret=ret*x%mod;     x=x*x%mod,k>>=1;    }    return ret;   }       ll prime[10000005],pcnt,phi[10000005];   bool mark[10000005];   inline void pre(ll n) {    mark[1]=1;    for(ll i=2;i<=n;i++) {     if(!mark[i]) prime[++pcnt]=i/*,phi[i]=i-1*/;     for(ll j=1;j<=pcnt;j++) {      ll k=i*prime[j];      if(k>n) break;      mark[k]=1;      if(i%prime[j]==0) {   //    phi[k]=phi[i]*prime[j];       break;      }   //   else phi[k]=phi[i]*(prime[j]-1);     }    }   }      struct data {    int u,v,val;    data(int _u=0,int _v=0,int _val=0):u(_u),v(_v),val(_val) {}    bool operator < (const data &x) const {     if(val==x.val) return u<x.u;     return val<x.val;    }   }a[505*505];   int fa[505*505],c[505*505];   vector <int> u,v;      int getfa(int x) {    return x==fa[x] ? x:fa[x]=getfa(fa[x]);   }      int main() {    ios::sync_with_stdio(false);    cin.tie(nullptr);    int T=1;   // cin>>T;    while(T--) {     int n; cin>>n;     for(int i=1;i<=n*n;i++) fa[i]=i;     int cnt=0;     for(int i=1;i<=n;i++) {      for(int j=1;j<=n;j++) {       int x; cin>>x;       if(i==j) c[i]=x;       if(i>=j) continue;       a[++cnt]=data(i,j,x);      }     }     sort(a+1,a+cnt+1);     int k=n;     for(int i=1;i<=cnt;i++) {      int fu=getfa(a[i].u),fv=getfa(a[i].v);      if(fu==fv) continue;      if(fu>n && c[fu]==a[i].val) {       fa[fv]=fu,u.push_back(fv),v.push_back(fu);       continue;      }      if(fv>n && c[fv]==a[i].val) {       fa[fu]=fv,u.push_back(fu),v.push_back(fv);       continue;      }      k++;      fa[fu]=fa[fv]=k;      c[k]=a[i].val;      u.push_back(fu),v.push_back(k);      u.push_back(fv),v.push_back(k);     }     cout<<k<<  n ;     for(int i=1;i<=k;i++) cout<<c[i]<<   ;     cout<<  n ;     cout<<k<<  n ;     for(int i=0;i<u.size();i++) cout<<u[i]<<   <<v[i]<<  n ;    }   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b);   bool prime(int n);   long long sumdigit(long long n);   bool ispowerof2(int n);   long long onesinbinary(long long n);   long long power(long long a, long long b);   bool cmp(pair<int, int> x, pair<int, int> y) { return x.second < y.second; }   bool cmp(int x, int y) { return x > y; }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long t;     cin >> t;     while (t--) {       int n;       cin >> n;       char arr[2][n];       for (int i = 0; i < 2; i++) {         for (int j = 0; j < n; j++) {           cin >> arr[i][j];         }       }       int ans = 0;       vector<int> v;       for (int i = 0; i < n; i++) {         if (arr[0][i] ==  0  && arr[1][i] ==  0 )           ans++;         else if (arr[0][i] ==  0  || arr[1][i] ==  0 )           ans += 2;         else {           v.push_back(i);         }       }       int x = v.size();       for (int i = 0; i < x; i++) {         if (v[i] < n - 1 && v[i] > 0) {           if (arr[0][v[i] - 1] ==  0  && arr[1][v[i] - 1] ==  0 ) {             ans++;           } else if (arr[0][v[i] + 1] ==  0  && arr[1][v[i] + 1] ==  0 ) {             ans++;             arr[0][v[i] + 1] =  1 , arr[1][v[i] + 1] =  1 ;           }         } else if (v[i] == n - 1) {           if (arr[0][v[i] - 1] ==  0  && arr[1][v[i] - 1] ==  0 ) {             ans++;           }         } else if (v[i] == 0) {           if (arr[0][v[i] + 1] ==  0  && arr[1][v[i] + 1] ==  0 ) {             ans++;             arr[0][v[i] + 1] =  1 , arr[1][v[i] + 1] =  1 ;           }         }       }       cout << ans << endl;     }     return 0;   }   long long onesinbinary(long long n) {     long long cnt = 0;     while (n) {       n = n & (n - 1);       cnt++;     }     return cnt;   }   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   bool prime(int n) {     for (int i = 2; i * i <= n; i++)       if (n % i == 0) return false;     return true;   }   long long sumdigit(long long n) {     int c = 0;     while (n > 0) {       c += n % 10;       n /= 10;     }     return c;   }   bool ispowerof2(int n) {     if (n == 0) return false;     return (!(n & ((n) & (n - 1))));   }   long long power(long long a, long long b) {     if (b == 0) return 1;     long long res = 1;     while (b) {       if (b % 2 == 1) res = (res * a) % 1000000007;       a = (a * a) % 1000000007;       b /= 2;     }     return res;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int p, c = 0;     cin >> p;     long long int x = p;     long long int n = std::numeric_limits<int>::digits - 1;     std::string s;     s.reserve(n + 1);     do s.push_back(((x >> n) & 1) +  0 );     while (--n > -1);     for (auto x : s)       if (x ==  1 ) c++;     cout << c;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Str {     int l;     char *s;   } str[50010 << 2];   int tot;   char s[3100000];   int k;   int n, l[50010], r[50010];   char ans[3100000];   int cut(int pos) {     for (int i = 0; i < tot; i++)       if (pos == 0) {         tot++;         for (int k = tot - 1; k > i; k--) str[k] = str[k - 1];         return i;       } else if (str[i].l <= pos)         pos -= str[i].l;       else {         tot += 2;         for (int k = tot - 1; k > i + 1; k--) str[k] = str[k - 2];         str[i + 2].l = str[i].l - pos;         str[i + 2].s = str[i].s + pos;         str[i].l = pos;         return i + 1;       }     return tot++;   }   void getans(int h, int t) {     int l = 0;     for (int i = 0; t >= 0 && i < tot; i++)       if (str[i].l <= h) {         h -= str[i].l;         t -= str[i].l;       } else {         for (int k = max(0, h); k < str[i].l && k <= t; k++)           ans[l++] = str[i].s[k];         int tmp = min(str[i].l, t);         h -= tmp;         t -= tmp;       }   }   void deal(int d, int len) {     if (d < 0) {       Str tmp;       tmp.l = len;       tmp.s = s + 1;       str[tot++] = tmp;       return;     }     if (r[d] >= len) {       deal(d - 1, len);       return;     }     int c = r[d] - l[d] + 1;     if (r[d] + c >= len) {       deal(d - 1, r[d]);       Str tmp;       tmp.l = len - r[d];       tmp.s = new char[len - r[d]];       int c_2 = c / 2;       int D = (tmp.l >= c_2) ? c : (tmp.l * 2);       getans(l[d], l[d] + D - 1);       for (int i = 0; i < tmp.l; i++)         if (i < c_2)           tmp.s[i] = ans[i * 2 + 1];         else           tmp.s[i] = ans[(i - c_2) << 1];       str[tot++] = tmp;     } else {       deal(d - 1, len - c);       int pos = cut(r[d] + 1);       Str tmp;       tmp.l = c;       tmp.s = new char[c];       int c_2 = c / 2;       getans(l[d], r[d]);       for (int i = 0; i < c; i++)         if (i < c_2)           tmp.s[i] = ans[i * 2 + 1];         else           tmp.s[i] = ans[(i - c_2) << 1];       str[pos] = tmp;     }   }   int main() {     scanf( %s , s + 1);     scanf( %d , &k);     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d%d , &l[i], &r[i]);     tot = 1;     str[0].l = 1;     str[0].s = new char[1];     str[0].s[0] =    ;     deal(n - 1, k);     getans(0, k);     ans[k + 1] = 0;     printf( %s n , ans + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     while (cin >> n) {       long long i = 5, cnt = 1, x, ans = 0, y, z = 5, m;       if (n < 5 || n == 5) {         if (n == 1)           cout <<  Sheldon  << endl;         else if (n == 2)           cout <<  Leonard  << endl;         else if (n == 3)           cout <<  Penny  << endl;         else if (n == 4)           cout <<  Rajesh  << endl;         else if (n == 5)           cout <<  Howard  << endl;         continue;       }       while (i < n || i == n) {         x = i;         if (i == n) {           x = 0;           break;         } else {           z += z;           i += z;         }         cnt = cnt * 2;       }       if (x == 0)         cout <<  Howard  << endl;       else {         y = n - x;         if (y < 1) y *= -1;         ans = y / cnt;         ans++;         if (y % cnt == 0) ans--;         if (ans == 1)           cout <<  Sheldon  << endl;         else if (ans == 2)           cout <<  Leonard  << endl;         else if (ans == 3)           cout <<  Penny  << endl;         else if (ans == 4)           cout <<  Rajesh  << endl;         else if (ans == 5)           cout <<  Howard  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300010;   int ans[N], vis[N];   vector<int> G[N], s[N], tmp;   void dfs(int u, int fa) {     int sz = s[u].size();     for (int i = 1; i <= sz; i++) vis[i] = 0;     for (int j : s[u]) {       if (ans[j] && ans[j] <= sz) vis[ans[j]] = 1;     }     for (int j = 1; j <= sz; j++) {       if (!vis[j]) tmp.push_back(j);     }     int cur = 0;     for (int j : s[u]) {       if (!ans[j]) ans[j] = tmp[cur++];     }     tmp.clear();     for (int v : G[u]) {       if (v == fa) continue;       dfs(v, u);     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       int cnt;       scanf( %d , &cnt);       for (int j = 1; j <= cnt; j++) {         int x;         scanf( %d , &x);         s[i].push_back(x);       }     }     for (int i = 1; i <= n - 1; i++) {       int u, v;       scanf( %d%d , &u, &v);       G[u].push_back(v);       G[v].push_back(u);     }     dfs(1, 0);     int mx = 0;     for (int i = 1; i <= m; i++) {       if (!ans[i]) ans[i] = 1;       mx = max(mx, ans[i]);     }     printf( %d n , mx);     for (int i = 1; i <= m; i++) printf( %d  , ans[i]);     printf(  n );     return 0;   }


#include<bits/stdc++.h>   using namespace std;   bool ok[100005];   typedef long long int ll;   int gcd(int a ,int b)   {       if(b==0)       return a;       else if(a==0)       return a;       else           return gcd(b,a%b);   }   int main()   {       int n;       cin>>n;       ll prod=1;       for(int i=1;i<n;i++)       {           if(gcd(n,i)==1)           {               ok[i]=1;               prod=(prod*i)%n;           }       }       if(prod!=1)       ok[prod]=0;          cout<<count(ok+1,ok+n,1)<<endl;       for(int i=1;i<n;i++)       {           if(ok[i])           cout<<i<<   ;       }       return 0;      }


#include <bits/stdc++.h>   using namespace std;   int inf = 1000000000, mxx, mxy, mnx = inf, mny = inf, n, m, i, j, r = 0,       x[2000001], y[2000001];   char a[3001][3001], c[3001][3001];   bool ok(int mxx, int mxy, int mnx, int mny) {     for (int i = 0; i < r; i++)       if (x[i] < mnx || x[i] > mxx || y[i] < mny || y[i] > mxy ||           (x[i] != mxx && x[i] != mnx && y[i] != mxy && y[i] != mny))         return false;     return (mxx - mnx == mxy - mny && mxx < n && mxy < m && mnx >= 0 && mny >= 0);   }   void go(int mxx, int mxy, int mnx, int mny) {     int i, j;     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) {         if (i >= mnx && i <= mxx && j >= mny && j <= mxy &&             ((i == mxx || i == mnx) || (j == mxy || j == mny)) && a[i][j] !=  w )           c[i][j] =  + ;         else           c[i][j] = a[i][j];       }   }   int main() {     cin >> n >> m;     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) {         cin >> a[i][j];         if (a[i][j] ==  w ) {           x[r] = i;           y[r] = j;           r++;         }       }     for (i = 0; i < r; i++) {       if (x[i] > mxx) mxx = x[i];       if (y[i] > mxy) mxy = y[i];       if (x[i] < mnx) mnx = x[i];       if (y[i] < mny) mny = y[i];     }     for (i = 0; i <= m; i++) {       if (ok(mxx, i + (mxx - mnx), mnx, i)) {         go(mxx, i + (mxx - mnx), mnx, i);         for (i = 0; i < n; i++)           for (j = 0; j < m; j++) {             cout << c[i][j];             if (j == m - 1) cout << endl;           }         return 0;       }     }     for (i = 0; i <= n; i++) {       if (ok(i + (mxy - mny), mxy, i, mny)) {         go(i + (mxy - mny), mxy, i, mny);         for (i = 0; i < n; i++)           for (j = 0; j < m; j++) {             cout << c[i][j];             if (j == m - 1) cout << endl;           }         return 0;       }     }     cout <<  -1 ;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 11, MAXL = 100000 + 10;   struct State {     int len, fa, num[MAXN], tr[26];     State() : len(0), fa(0) {       memset(num, 0, sizeof(num));       memset(tr, 0, sizeof(tr));     }     State(int len, int fa, int numr, int ref) : len(len), fa(fa) {       memset(num, 0, sizeof(num));       memset(tr, 0, sizeof(tr));       num[ref] = numr;     }   } SAM[MAXL * 2];   int n, tot = 1, c[MAXN][2];   string str[MAXN];   void Construct_SAM(const string &str, int ref) {     int ns = str.size();     for (int cp = 1, pre = 1, i = 0, id = str[i] -  a ; i < ns;          id = str[++i] -  a , pre = cp) {       if (SAM[cp].tr[id] && SAM[SAM[cp].tr[id]].len == SAM[cp].len + 1) {         cp = SAM[cp].tr[id];         ++SAM[cp].num[ref];         continue;       }       cp = ++tot;       SAM[cp] = State(SAM[pre].len + 1, 0, 1, ref);       for (; pre && !SAM[pre].tr[id]; SAM[pre].tr[id] = cp, pre = SAM[pre].fa)         ;       if (pre != 0)         if (SAM[pre].len + 1 == SAM[SAM[pre].tr[id]].len)           SAM[cp].fa = SAM[pre].tr[id];         else {           int tp = SAM[pre].tr[id];           SAM[++tot] = State(SAM[pre].len + 1, SAM[tp].fa, 0, 0);           memcpy(SAM[tot].tr, SAM[tp].tr, sizeof(SAM[tp].tr));           SAM[cp].fa = SAM[tp].fa = tot;           for (; pre && SAM[pre].tr[id] == tp;                SAM[pre].tr[id] = tot, pre = SAM[pre].fa)             ;         }       else         SAM[cp].fa = 1;     }   }   void init() {     cin >> str[0];     c[0][0] = 1, c[0][1] = MAXL;     Construct_SAM(str[0], 0);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> str[i] >> c[i][0] >> c[i][1];       Construct_SAM(str[i], i);     }   }   vector<int> l[MAXL];   void Calc(int id) {     for (int i = MAXL - 1; i >= 0; --i)       for (int j = 0; j < (int)l[i].size(); ++j)         SAM[SAM[l[i][j]].fa].num[id] += SAM[l[i][j]].num[id];   }   bool Check(int x) {     for (int i = 0; i <= n; ++i)       if (!(SAM[x].num[i] >= c[i][0] && SAM[x].num[i] <= c[i][1])) return false;     return true;   }   void solve() {     for (int i = 1; i <= tot; ++i) l[SAM[i].len].push_back(i);     for (int i = 0; i <= n; ++i) Calc(i);     long long CC = 0;     for (int i = 2; i <= tot; ++i)       if (Check(i)) CC += SAM[i].len - SAM[SAM[i].fa].len;     cout << CC << endl;   }   int main() {     init();     solve();     fclose(stdin);     fclose(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<long long int> st;   set<long long int>::iterator it;   long long int cnt[200010];   int main() {     long long int n, a, b, x, y, z, p, m, d, mn, mx, t, i;     scanf( %lld , &t);     while (t--) {       scanf( %lld , &n);       p = 0;       for (i = 1; i <= n; i++) {         scanf( %lld , &a);         st.insert(a);         cnt[a]++;         p = max(p, cnt[a]);       }       x = st.size();       if (x == 1) {         if (p >= 2) {           cout << 1 << endl;         } else           cout << 0 << endl;       } else {         x = x - 1;         if (p <= x)           cout << p << endl;         else {           d = p - x;           if (d > 1)             cout << x + 1 << endl;           else             cout << x << endl;         }       }       for (i = 1; i <= n; i++) cnt[i] = 0;       st.clear();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool prime[1500000 + 10];   bool a[1500000 + 10];   int func(int N, int x) {     int i, ans = 0;     if (x == 2) return 0;     if (a[1]) return 1;     if (x >= 1500000) return -1;     for (i = 2; i <= x - 1; i++)       if (prime[i])         if (a[i])           ans++;         else           return -1;     return ans;   }   int main(void) {     int i, j, N, x, tmp;     for (i = 2; i < 1500000; i++) prime[i] = true;     for (i = 2; i * i < 1500000; i++)       if (prime[i])         for (j = i * i; j < 1500000; j += i) prime[j] = false;     scanf( %d%d , &N, &x);     for ((i) = 0; (i) < (int)(N); (i)++) {       scanf( %d , &tmp);       if (tmp < 1500000) a[tmp] = true;     }     int ans = func(N, x);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void task();   int main() {     srand(time(0));     ios_base::sync_with_stdio(0);     task();     return 0;   }   vector<int> prefix_function(string s) {     int n = s.length();     vector<int> p(n, 0);     for (int i = 1; i < n; ++i) {       int j = p[i - 1];       while (j > 0 && s[i] != s[j]) j = p[j - 1];       if (s[i] == s[j]) p[i] = j + 1;     }     return p;   }   string s[3];   void task() {     cin >> s[0] >> s[1] >> s[2];     sort(s, s + 3);     int ans = 1e9 + 10;     do {       string ss = s[0];       {         vector<int> p = prefix_function(s[1] +  !  + s[0]);         int mx = 0;         for (int i = s[1].length(); i < ((int)((p).size())); ++i)           mx = max(mx, p[i]);         if (p.back() != ((int)((s[1]).size())) && mx != ((int)((s[1]).size())))           ss += s[1].substr(p.back(), ((int)((s[1]).size())) - p.back());       }       {         vector<int> p = prefix_function(s[2] +  !  + ss);         int mx = 0;         for (int i = s[2].length(); i < ((int)((p).size())); ++i)           mx = max(mx, p[i]);         if (p.back() != ((int)((s[2]).size())) && mx != ((int)((s[2]).size())))           ss += s[2].substr(p.back(), ((int)((s[2]).size())) - p.back());         ans = min(ans, ((int)((ss).size())));       }     } while (next_permutation(s, s + 3));     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int MOD = 1e9 + 7;   const int maxn = 3e5 + 10;   const int maxv = 1e3 + 10;   const double eps = 1e-9;   std::vector<int> G[maxn];   int ans[maxn];   void inv(int i) { ans[i] ^= 1; }   bool bad(int u) {     int cnt = 0;     for (int i = 0; i < G[u].size(); i++) {       cnt += ans[u] == ans[G[u][i]];     }     return cnt >= 2;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d%d , &u, &v);       if (u > v) swap(u, v);       G[v].push_back(u);       G[u].push_back(v);     }     stack<int> s;     for (int i = 1; i <= n; i++) {       if (bad(i)) s.push(i);     }     while (s.size()) {       int u = s.top();       s.pop();       if (bad(u)) inv(u);       for (int i = 0; i < G[u].size(); i++) {         int v = G[u][i];         if (bad(G[u][i])) s.push(v);       }     }     for (int i = 1; i <= n; i++) {       printf( %d , ans[i]);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   char s[105];   string S;   multiset<string> st;   vector<string> v;   inline bool cmp(string a, string b) { return a.length() < b.length(); }   int cnt[26];   char ans[105];   int f[105][26];   int main() {     scanf( %d , &n);     if (n <= 3) {       if (n == 1) {         printf( ? 1 1 n ), fflush(stdout);         scanf( %s , s);         printf( ! %s n , s);         return 0;       }       printf( ? 2 %d n , n), fflush(stdout);       for (int i = 1; i <= n * (n - 1) / 2; i++) {         scanf( %s , s);         S = s;         sort(S.begin(), S.end());         st.insert(S);       }       printf( ? 1 %d n , n), fflush(stdout);       for (int i = 1; i <= n * (n + 1) / 2; i++) {         scanf( %s , s);         S = s;         sort(S.begin(), S.end());         if (st.find(S) == st.end())           v.push_back(S);         else           st.erase(st.find(S));       }       sort(v.begin(), v.end(), cmp);       printf( !  );       for (int i = 0; i < n; i++) {         if (i == 0) {           printf( %c , v[i][0]);           continue;         }         for (int j = 0; j < i + 1; j++) cnt[v[i][j] -  a ]++;         for (int j = 0; j < i; j++) cnt[v[i - 1][j] -  a ]--;         for (int j = 0; j < 26; j++) {           if (cnt[j]) {             cnt[j] = 0, printf( %c , j +  a );             break;           }         }       }       puts(  );       return 0;     }     int m = (n + 1) / 2;     printf( ? 2 %d n , m), fflush(stdout);     for (int i = 1; i <= m * (m - 1) / 2; i++) {       scanf( %s , s);       S = s;       sort(S.begin(), S.end());       st.insert(S);     }     printf( ? 1 %d n , m), fflush(stdout);     for (int i = 1; i <= m * (m + 1) / 2; i++) {       scanf( %s , s);       S = s;       sort(S.begin(), S.end());       if (st.find(S) == st.end())         v.push_back(S);       else         st.erase(st.find(S));     }     sort(v.begin(), v.end(), cmp);     for (int i = 0; i < m; i++) {       if (i == 0) {         ans[i + 1] = v[i][0];         continue;       }       for (int j = 0; j < i + 1; j++) cnt[v[i][j] -  a ]++;       for (int j = 0; j < i; j++) cnt[v[i - 1][j] -  a ]--;       for (int j = 0; j < 26; j++) {         if (cnt[j]) {           cnt[j] = 0, ans[i + 1] = j +  a ;           break;         }       }     }     printf( ? 1 %d n , n), fflush(stdout);     for (int i = 1; i <= n * (n + 1) / 2; i++) {       scanf( %s , s);       int len = strlen(s);       for (int j = 0; j < len; j++) {         f[len][s[j] -  a ]++;       }     }     for (int i = m; i; i--) {       for (int j = 0; j < 26; j++) {         int x = f[i][j] - f[i - 1][j];         for (int k = i; k < n + 1 - i; k++) x -= ans[k] == j +  a ;         if (x) {           ans[n + 1 - i] = j +  a ;           break;         }       }     }     printf( !  );     for (int i = 1; i <= n; i++) printf( %c , ans[i]);     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   long long a, b;   vector<long long> A, B, C;   int main() {     scanf( %lld %lld , &a, &b);     for (long long i = 1; i <= sqrt(a); i++)       if (a % i == 0) A.push_back(i);     for (long long i = 1; i <= sqrt(b); i++)       if (b % i == 0) B.push_back(i);     for (long long i = 1; i <= sqrt(a + b); i++)       if ((a + b) % i == 0) C.push_back(i);     long long ans;     for (long long i : C) {       for (long long j : A) {         if (j <= i && a / j <= (a + b) / i) ans = 2 * i + (2 * (a + b) / i);       }       for (long long j : B) {         if (j <= i && b / j <= (a + b) / i) ans = 2 * i + (2 * (a + b) / i);       }     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   vector<int> a, b, e;   char s[5];   long long ans;   int c;   int main() {     int n, f;     scanf( %d , &n);     while (n--) {       scanf( %s %d , &s, &f);       if (s[0] ==  0  && s[1] ==  1 )         a.push_back(f);       else if (s[0] ==  1  && s[1] ==  0 )         b.push_back(f);       else if (s[0] ==  0  && s[1] ==  0 )         e.push_back(f);       else {         c++;         ans += f;       }     }     int temp = c + 2 * min((int)a.size(), (int)b.size());     c += min((int)a.size(), (int)b.size());     if (!a.empty()) sort(a.rbegin(), a.rend());     if (!b.empty()) sort(b.rbegin(), b.rend());     for (int i = 0; i < min((int)a.size(), (int)b.size()); ++i) {       ans += a[i];       ans += b[i];     }     if (a.size() > b.size()) {       for (int i = min(a.size(), b.size()); i < a.size(); ++i) e.push_back(a[i]);     } else if (b.size() > a.size()) {       for (int i = min(a.size(), b.size()); i < b.size(); ++i) e.push_back(b[i]);     }     if (!e.empty()) sort(e.rbegin(), e.rend());     for (int i = 0; i < e.size(); ++i) {       if (((temp + 2) / 2) <= c) {         ans += e[i];         temp++;       }     }     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   ifstream fin( Sisend.txt );   int n, c;   bool b[100005];   vector<int> v, v1;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cerr.tie(0);     cin >> n;     for (int(i) = (0); ((i)) < ((n)); ((i))++) {       cin >> c;       v.emplace_back(c);     }     sort(v.rbegin(), v.rend());     int l = 1, r = v.size() / 2 + 1;     int vas = 0;     v1.emplace_back(v[0]);     while (r < v.size()) {       while (r < v.size() and v[r] == v[l]) r++;       v1.emplace_back(v[r]), v1.emplace_back(v[l]);       b[r] = 1;       vas++;       l++;       r++;     }     while (l < v.size()) {       if (!b[l]) {         v1.emplace_back(v[l]);       }       l++;     }     cout << vas << endl;     for (int i : v1) cout << i <<    ;   }


///****In the name of ALLAH, most Gracious, most Compassionate****//   #include<bits/stdc++.h>      #define Input                   freopen( in.txt , r ,stdin)   #define Output                  freopen( out.txt , w ,stdout)   #define ll                      long long int   #define ull                     unsigned long long int   #define pii                     pair<int,int>   #define pll                     pair<ll,ll>   #define sc                      scanf   #define scin(x)                 sc( %d ,&(x))   #define scin2(x,y)              sc( %d %d ,&(x),&(y))   #define scln(x)                 sc( %lld ,&(x))   #define scln2(x,y)              sc( %lld %lld ,&(x),&(y))   #define pf                      printf   #define all(a)                  (a.begin()),(a.end())   #define UNIQUE(X)               (X).erase(unique(all(X)),(X).end())   #define SORT_UNIQUE(c)          (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))   #define ms(a,b)                 memset(a,b,sizeof(a))   #define pb(a)                   push_back(a)   #define mp                      make_pair   #define db                      double   #define EPS                     10E-10   #define ff                      first   #define ss                      second   #define sqr(x)                  (x)*(x)   #define vi                      vector<int>   #define vl                      vector<ll>   #define vii                     vector<vector<int> >   #define vll                     vector<vector<ll> >   #define DBG                     pf( HI n )   #define MOD                     1000000007   #define CIN                     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)   #define RUN_CASE(t,T)           for(__typeof(t) t=1;t<=T;t++)   #define CASE(t)                 printf( Case %d:  ,t)   #define CASEl(t)                printf( Case %d: n ,t)   #define intlimit                2147483690   #define longlimit               9223372036854775800   #define infinity                (1<<28)   #define gcd(a,b)                __gcd(a,b)   #define lcm(a,b)                (a)*(b)/gcd(a,b)   #define mxx                     123456789   #define PI                      2*acos(0.0)   #define rep(i,a,b)              for(__typeof(i) i=a;i<=b;i++)   #define rev(i,a,b)              for(__typeof(i) i=a;i>=b;i--)   #define coutv(v)                for(auto it:v)cout<<it<<   ;cout<<  n ;   #define cinv(v)                 for(auto &it:v)cin>>it;   #define srt(v)                  sort(v.begin(),v.end());   #define rsrt(v)                 sort(v.rbegin(),v.rend());   #define rvs(v)                  reverse(v.begin(),v.end());      using namespace std;   /**     toint, tostring, BigMod, Power , sieve, Primefactorize ,frequency in n!     **/   //ll toint(string s){ll n=0,k=1;for(int i=s.size()-1; i>=0; i--){n += ((s[i]- 0 )*k);k*=10;}return n;}   //string tostring(ll x){string s=  ;while(x){s += (x%10)+ 0 ;x/=10;}reverse(s.begin(),s.end());return s;}   //ll BigMod(ll a,ll b){if(b == 0)return 1%MOD;else if(b%2 == 0){ll temp=BigMod(a,b/2);return ((temp%MOD)*(temp%MOD))%MOD;}else{return ((a%MOD)*BigMod(a,b-1)%MOD)%MOD;}}   //ll Power(ll a,ll n){ll ret=1;for(ll i=1 ; i<=n ; i++)ret = ((ret%MOD)*(a%MOD))%MOD;return ret;}   //bool isPrime(ll n){for(ll i=2 ; i*i<=n ; i++){if(n%i == 0)return 0;}return 1;}   //vector<ll>Prime;   //bool mark[10000003];   //void sieve(ll n){ll i,j;mark[1]=1;for(i=4; i<=n; i+=2)mark[i]=1;Prime.push_back(2);for(i=3; i<=n; i+=2){if(!mark[i]){Prime.push_back(i);if(i*i<=n){for(j=i*i; j<=n; j+=(i*2))mark[j]=1;}}}}   //map<ll,ll>Factor;   //void Primefactorize(ll n){for(ll i=0; i<Prime.size() && Prime[i]*Prime[i]<=n; i++){if(n%Prime[i] == 0){while(n%Prime[i] == 0){Factor[Prime[i]]++;n/=Prime[i];}}}if(n>1){Factor[n]++;}}   //ll frequency(ll n,ll factor)/** Frequency of a factor in n! **/{ll cnt=0;while(n){cnt += (n/factor);n /= factor;}return cnt;}   /**     Order Set       **/   //#include <ext/pb_ds/assoc_container.hpp>   //using namespace __gnu_pbds;   //template<typename T> using orderset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;   //orderset<int> s ; //orderset<int>::iterator it ;   //orderset<int> X; //X.insert(1); //X.insert(2); //X.insert(4); //X.insert(8); //X.insert(16);   //cout<<*X.find_by_order(0)<<endl; // 2 //cout<<*X.find_by_order(2)<<endl; // 4 //cout<<*X.find_by_order(4)<<endl; // 16 //cout<<(end(X)==X.find_by_order(6))<<endl; // true   //cout<<X.order_of_key(-5)<<endl;  // 0 //cout<<X.order_of_key(1)<<endl;   // 0 //cout<<X.order_of_key(3)<<endl;   // 2 //cout<<X.order_of_key(4)<<endl;   // 2 //cout<<X.order_of_key(400)<<endl; // 5      struct custom_hash {    ///For unordered map or set       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);       }   };      /** Debugging Tool **/   #define error(args...) { string _s = #args; replace(_s.begin(), _s.end(),  , ,    ); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }   void err(istream_iterator<string> it) {}   template<typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args)   {       cerr << *it <<   =   << a << endl;       err(++it, args...);   }   ///      inline int add(int a, int b) {a += b; return a >= MOD ? a - MOD : a;}   inline int sub(int a, int b) {a -= b; return a < 0 ? a + MOD : a;}   inline int mul(int a, int b) {return (ll) a * b % MOD;}   int Set(int N, int pos) {return  N = N | (1<<pos);}   int Reset(int N, int pos) {return  N = N & ~(1<<pos);}   bool Cheek(int N, int pos) {return  (bool)(N & (1<<pos));}      //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   //int my_rand(int l,int r)   //{   //    return uniform_int_distribution<int>(l , r) (rng);   //}      //string small =  abcdefghijklmnopqrstuvwxyz ;   //string capital =  ABCDEFGHIJKLMNOPQRSTUVWXYZ ;      ///------------------Graph Moves-------------------   ///const int fx[] = {+1,-1,+0,+0};   ///const int fy[] = {+0,+0,+1,-1};   ///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King s move   ///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///King s move   ///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///Knight s move   ///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///Knight s move      ll s[5009],added[5009];      void Solve(int t)   {       ll i,j,k,n,ans=0;       scln(n);       for(i=1 ; i<=n ; i++)           scln(s[i]);          for(i=1 ; i<=n ; i++){           if(s[i] - added[i] <= 1){               for(j=i+2 ; j<=min(n , i+s[i]) ; j++)                   added[j]++;               if(added[i] >= s[i]){                   ll xtra = added[i] - (s[i] - 1);                   added[i+1] += xtra;               }               continue;           }              ll temp = (s[i] - 1) - added[i];           added[i] += temp;           ans += temp;      //        error(i , temp);           for(j=i+2 ; j<=min(n , i+s[i]) ; j++){               added[j]++;           }              if(added[i] >= s[i]){               ll xtra = added[i] - (s[i] - 1);               added[i+1] += xtra;           }       }       pf( %lld n ,ans);          for(i=1 ; i<=n+2 ; i++)           s[i] = added[i] = 0;   }      int main()   {       int t,T;       T = 1;       cin>>T;       RUN_CASE(t,T)       {           Solve(t);       }       return 0;   }      /** Stuff u should look for       * Avoid overflow       * Corner(Small) case       * Don t get stuck on one approach       * Don t forget to clean used memory in each case   **/


#include <bits/stdc++.h>   using namespace std;   const int INF = 2e9;   const long long BIG_INF = 1e18;   const long long MOD = 1e9 + 7;   const int maxn = 1e5 + 5;   vector<int> g[maxn];   int p[maxn], max_height, deep_v;   void dfs(int v, int height) {     if (height > max_height) {       max_height = height;       deep_v = v;     }     for (int j = 0; j < (int)g[v].size(); j++) {       int to = g[v][j];       dfs(to, height + 1);     }   }   void out(int v) {     if (v) out(p[v]);     ;     cout << v <<    ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int u;       cin >> u;       p[i] = u;       g[u].push_back(i);     }     dfs(0, 0);     vector<int> ans;     int v = deep_v;     while (1) {       while (v && (int)g[p[v]].size() == 1) v = p[v];       if (!v) break;       int par = p[v];       g[par].erase(find(g[par].begin(), g[par].end(), v));       int to = g[par][0];       ans.push_back(v);       g[to].push_back(v);       p[v] = to;     }     out(deep_v);     cout <<   n ;     reverse(ans.begin(), ans.end());     cout << (int)ans.size() <<   n ;     for (int i = 0; i < (int)ans.size(); i++) cout << ans[i] <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n;   long long a[1006];   long long fac[1000006];   long long power(long long a, long long i) {     if (i == 0) return 1 % 1000000007;     long long t = power(a, i / 2);     long long ans = t * t % 1000000007;     if (i % 2 == 1) ans = ans * a % 1000000007;     return ans;   }   long long work(long long m, long long i) {     return ((fac[m] % 1000000007) *             (power(fac[i] * fac[m - i] % 1000000007, 1000000007 - 2) %              1000000007)) %            1000000007;   }   int main() {     fac[0] = 1;     for (int i = 1; i < 1000006; i++) fac[i] = (fac[i - 1] * i) % 1000000007;     long long ans = 1;     long long sum = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       sum += a[i];     }     for (int i = n; i >= 1; i--) {       ans = ans * work(sum - 1, a[i] - 1) % 1000000007;       sum -= a[i];     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n, k;     cin >> n >> k;     long long int a[n], s = 0;     vector<pair<long long int, long long int> > v;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] <= k) {         v.push_back({a[i], i + 1});         s += a[i];       }     }     if (s < (k + 1) / 2) {       cout << -1 << endl;       return;     }     s = 0;     sort(v.begin(), v.end());     vector<long long int> ans;     for (int i = v.size() - 1; i >= 0; i--) {       if (s + v[i].first >= (k + 1) / 2 and s + v[i].first <= k) {         s += v[i].first;         ans.push_back(v[i].second);         break;       } else if (s + v[i].first < (k + 1) / 2) {         ans.push_back(v[i].second);         s += v[i].first;       }     }     if (ans.size() == 0) {       cout << -1 << endl;     }     sort(ans.begin(), ans.end());     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) {       cout << ans[i] <<    ;     }     cout << endl;   }   int main() {     int t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const long long INF = 1e12;   const int MOD = 1e9 + 7;   const unsigned long long BIT_FLAG_0 = (1 << 0);   const unsigned long long BIT_FLAG_1 = (1 << 1);   const unsigned long long BIT_FLAG_2 = (1 << 2);   const unsigned long long BIT_FLAG_3 = (1 << 3);   const unsigned long long BIT_FLAG_4 = (1 << 4);   const unsigned long long BIT_FLAG_5 = (1 << 5);   const unsigned long long BIT_FLAG_6 = (1 << 6);   const unsigned long long BIT_FLAG_7 = (1 << 7);   const long long dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};   const long long Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},                   Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};   void print() { cout <<   n ; }   template <class Head, class... Tail>   void print(Head &&head, Tail &&...tail) {     cout << head;     if (sizeof...(tail) != 0) cout <<    ;     print(forward<Tail>(tail)...);   }   template <class T>   void print(vector<T> &vec) {     for (auto &a : vec) {       cout << a;       if (&a != &vec.back()) cout <<    ;     }     cout <<   n ;   }   template <class T>   void print(set<T> &set) {     for (auto &a : set) {       cout << a <<    ;     }     cout <<   n ;   }   template <class T>   void print(vector<vector<T>> &df) {     for (auto &vec : df) {       print(vec);     }   }   long long power(long long a, long long n) {     long long res = 1;     while (n > 0) {       if (n & 1) res = res * a;       a *= a;       n >>= 1;     }     return res;   }   long long comb(long long n, long long k) {     vector<vector<long long>> v(n + 1, vector<long long>(n + 1, 0));     for (long long i = 0; i < (long long)((v).size()); i++) {       v[i][0] = 1;       v[i][i] = 1;     }     for (long long k = 1; k < (long long)((v).size()); k++) {       for (long long j = 1; j < k; j++) {         v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);       }     }     return v[n][k];   }   void add(long long &a, long long b) {     a += b;     if (a >= MOD) a -= MOD;   }   template <class T>   inline bool chmin(T &a, T b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <class T>   inline bool chmax(T &a, T b) {     if (a < b) {       a = b;       return true;     }     return false;   }   __attribute__((constructor)) void faster_io() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);   }   long long n, k;   map<long long, long long> got;   pair<bool, multiset<long long>> isOK(long long idx) {     multiset<long long> ans;     multiset<long long> trueans;     long long cnt = 0;     for (const auto &[key, value] : got) {       long long types = value / idx;       cnt += types;       for (long long ti = 0; ti < (long long)(types); ti++) {         ans.insert(key);       }     }     if (cnt >= k) {       long long now = 0;       for (auto i : ans) {         trueans.insert(i);         now++;         if (now == k) {           break;         }       }       return make_pair(true, trueans);     } else {       return make_pair(false, trueans);     }   }   multiset<long long> bin_search() {     multiset<long long> finalans;     long long ng = n + 1;     long long ok = 0;     while (abs(ok - ng) > 1) {       long long mid = (ok + ng) / 2;       long long bl = isOK(mid).first;       auto nums = isOK(mid).second;       if (bl) {         ok = mid;         finalans = nums;       } else         ng = mid;     }     return finalans;   }   signed main() {     cin >> n >> k;     vector<long long> A(n);     for (long long ni = 0; ni < (long long)(n); ni++) {       long long v;       cin >> v;       A[ni] = v;       got[v]++;     }     auto ret = bin_search();     for (auto i : ret) {       cout << i <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e6 + 5;   int main() {     ios_base::sync_with_stdio(0);     long long q;     cin >> q;     while (q--) {       long long n;       cin >> n;       long long cnt = 0;       long long flag = 1;       while (n != 1) {         if (n % 2 == 0) {           n = n / 2;           cnt++;         } else if (n % 3 == 0) {           n = (2 * n) / 3;           cnt++;         } else if (n % 5 == 0) {           n = (4 * n) / 5;           cnt++;         } else {           cout <<  -1  << endl;           flag = 0;           break;         }       }       if (flag) cout << cnt << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x;     while (cin >> x) {       map<char, int> p1;       string str, strr;       ;       bool l = 0;       int sum;       cin >> str;       for (int i = 0; i < str.size(); i++) {         p1[str[i]]++;       }       for (int i = 0; i < str.size(); i++) {         if (p1[str[i]] % x != 0) {           l = 1;           break;         }       }       if (l == 0) {         for (char i =  a ; i <=  z ; i++) {           sum = 0;           if (p1[i] > 0) {             sum = p1[i] / x;           }           while (sum--) {             strr += i;           }         }         while (x--) {           cout << strr;         }       } else         cout << -1;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200200;   const int mod = 1e9 + 7;   int n, a, b;   vector<int> q;   int main() {     cin >> n >> a >> b;     q.push_back(a);     q.push_back(a);     q.push_back(a);     q.push_back(a);     q.push_back(b);     q.push_back(b);     sort(q.begin(), q.end());     int res = 1e9;     do {       int ans = 1, cur = n;       for (int i = 0; i < q.size(); ++i)         if (cur - q[i] >= 0)           cur -= q[i];         else           ans++, cur = n - q[i];       res = min(res, ans);     } while (next_permutation(q.begin(), q.end()));     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using lli = long long int;   lli mod = 1000000007.0;   int main(void) {     long long t;     cin >> t;     lli x;     lli n;     while (t--) {       cin >> n;       x = 1;       for (lli i = 2 * n; i >= 3; i--) {         x *= i;         x = x % mod;       }       cout << x << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x[210], y[210], ans, dp[210][210];   long long S[210][210];   bool in[210][210][210];   int gogo(int x) {     if (x % n == 0) return n;     return x % n;   }   long long cp(int a, int b, int c) {     return 1LL * (x[a] - x[c]) * (y[b] - y[c]) -            1LL * (y[a] - y[c]) * (x[b] - x[c]);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d%d , &x[i], &y[i]);     for (int i = 1; i <= n; i++)       for (int j = i; j <= n; j++) {         for (int p = i + 1; p < j; p++) S[i][j] += cp(p, p + 1, i);       }     for (int i = 1; i <= n; i++)       for (int j = 1; j < i; j++) {         for (int p = gogo(i + 1); p != j; p = gogo(p + 1))           S[i][j] += cp(gogo(p), gogo(p + 1), i);       }     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++)         for (int p = j + 1; p <= n; p++)           if (abs(cp(j, p, i)) + abs(S[i][j]) + abs(S[j][p]) + abs(S[p][i]) ==                   abs(S[1][n]) &&               cp(j, p, i)) {             in[i][j][p] = true;           }     for (int i = 1; i <= n; i++) dp[i][i + 1] = 1;     for (int i = n; i; i--)       for (int j = i + 1; j <= n; j++)         for (int p = i + 1; p < j; p++)           if (in[i][p][j])             dp[i][j] = (dp[i][j] + 1LL * dp[i][p] * dp[p][j]) % 1000000007;     ans = dp[1][n];     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int round_up(int i) {     while (i & (i - 1)) {       i = ((i - 1) | i) + 1;     }     return i;   }   class seg_t {    public:     vector<int> seg, ar;     int n;     seg_t(vector<int>& a) {       n = a.size();       ar = a;       int si = round_up(n);       seg.resize(si * 2);       build(0, 0, n - 1);     }     void build(int i, int l, int r) {       if (l == r) {         seg[i] = ar[l];         return;       }       int mid = (l + r) / 2;       build(i * 2 + 1, l, mid);       build(i * 2 + 2, mid + 1, r);       seg[i] = min(seg[i * 2 + 1], seg[i * 2 + 2]);     }     int q(int i, int l, int r, int lind, int rind, int val) {       if (r < lind || r > rind) {         return -1;       }       if (l == r) {         if (seg[i] >= val) return -1;         return l;       }       if (lind <= l && r <= rind) {         if (seg[i] >= val) return -1;       }       int mid = (l + r) / 2;       int t = q(i * 2 + 1, l, mid, lind, rind, val);       if (t >= 0) return t;       return q(i * 2 + 2, mid + 1, r, lind, rind, val);     }     int qq(int i, int l, int r, int lind, int rind) {       if (r < lind || r > rind) {         return 1000000000;       }       if (lind <= l && r <= rind) {         return seg[i];       }       int mid = (l + r) / 2;       return min(qq(i * 2 + 1, l, mid, lind, rind),                  qq(i * 2 + 2, mid + 1, r, lind, rind));     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<int> a(2 * n);     for (int i = 0; i < n; i++) {       cin >> a[i];       a[i + n] = a[i];     }     seg_t t(a);     vector<int> b(2 * n);     for (int i = 0; i < n; i++) {       int tmp = t.q(0, 0, 2 * n - 1, i, n * 2 - 1, (a[i] + 1) / 2);       if (tmp == -1)         b[i] = 1000000000;       else         b[i] = tmp;       b[i + n] = b[i] + n;     }     seg_t tt(b);     for (int i = 0; i < n; i++) {       int tmp = tt.qq(0, 0, 2 * n - 1, i, n * 2 - 1);       if (tmp >= 1000000000)         cout << -1 <<    ;       else         cout << tmp - i <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using pii = pair<int, int>;   int const N = 1e5 + 20, MAX = 7000 + 20;   int n, q;   bitset<MAX> bt[N];   int a[MAX];   vector<int> dv[MAX];   bitset<MAX> save[MAX];   void pre() {     a[1] = 1;     for (int i = 1; i < MAX; i++) {       for (int j = 2 * i; j < MAX; j += i) a[j] ^= a[i], dv[j].push_back(i);       dv[i].push_back(i);     }     for (int i = 1; i < MAX; i++) {       for (int j = 1; i * j < MAX; j++) {         if (a[j]) save[i][i * j] = 1;       }     }   }   int main() {     pre();     scanf( %d %d  , &n, &q);     while (q--) {       int tp, x, y, z, v;       scanf( %d  , &tp);       if (tp == 1) {         scanf( %d %d  , &x, &v);         x--;         bt[x].reset();         for (int u : dv[v]) bt[x][u] = 1;       } else if (tp == 2) {         scanf( %d %d %d  , &x, &y, &z);         x--, y--, z--;         bt[x] = (bt[y] ^ bt[z]);       } else if (tp == 3) {         scanf( %d %d %d  , &x, &y, &z);         x--, y--, z--;         bt[x] = (bt[y] & bt[z]);       } else if (tp == 4) {         scanf( %d %d  , &x, &v);         x--;         bitset<MAX> tmp = (bt[x] & save[v]);         putchar( 0  + (tmp.count() & 1));       }     }     putchar(  n );   }


#include <bits/stdc++.h>   using namespace std;   int n;   int k;   vector<pair<long double, long double> > vp;   const long double PI = 2 * acos(0.0);   bool check(long double r) {     vector<pair<long double, int> > events;     for (int i = 0; i < n; ++i) {       long double ang = atan2(vp[i].second, vp[i].first);       long double d =           sqrt(vp[i].first * vp[i].first + vp[i].second * vp[i].second);       if (d > 2 * r) continue;       long double alph = (PI - acos(1 - (d * d) / (2 * (r * r)))) / 2;       long double ang_in = ang - alph;       long double ang_out = ang + alph;       if (ang_in < 0) {         ang_in += 2 * PI;         ang_out += 2 * PI;       }       events.emplace_back(ang_in, 1);       events.emplace_back(ang_out, -1);       events.emplace_back(ang_in + 2 * PI, 1);       events.emplace_back(ang_out + 2 * PI, -1);     }     sort(events.begin(), events.end());     int ck = 0;     for (int i = 0; i < (int)events.size(); ++i) {       ck += events[i].second;       if (ck >= k) return true;     }     return false;   }   int main() {     cout.setf(ios::fixed);     cout << setprecision(10);     cin >> n;     cin >> k;     for (int i = 0; i < n; ++i) {       int first, second;       cin >> first >> second;       vp.emplace_back(first, second);     }     long double l = 0;     long double r = 2e5;     while (r - l > 1e-6) {       long double mid = (l + r) / 2;       if (check(mid)) {         r = mid;       } else {         l = mid;       }     }     cout << l << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long check(long long x) {     long long i = 0, ans = 0;     while (x > 0) {       if ((x & (1)) == 1) {         ans = max(ans, i);       }       x = x >> 1;       i++;     }     return ans;   }   void solve() {     long long n;     cin >> n;     long long a[n + 1];     map<long long, long long> mp;     for (long long i = 0; i < n; i++) {       cin >> a[i];       mp[check(a[i])]++;     }     long long ans = 0;     for (auto x : mp) {       if (x.second > 1) ans += ((x.second) * (x.second - 1)) / 2;     }     cout << ans << endl;     return;   }   int main() {     int t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int cnt = 0;   vector<int> ans;   vector<vector<int> > adj;   void dfs(int u, int col) {     if (ans[u] != -1) return;     ans[u] = col;     for (int i = 0; i < adj[u].size(); ++i) dfs(adj[u][i], col);   }   char conv(int first) {     if (first == 0) return  b ;     if (first == 1) return  a ;     if (first == 2) return  c ;   }   int main() {     cout.setf(ios::fixed);     cout.precision(7);     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     adj = vector<vector<int> >(n);     vector<int> deg(n, 0);     for (int asdf = 0; asdf < m; ++asdf) {       int first, second;       cin >> first >> second;       --first;       --second;       adj[first].push_back(second);       adj[second].push_back(first);       ++deg[first];       ++deg[second];     }     ans = vector<int>(n, -1);     int qt = 0;     for (int i = 0; i < n; ++i)       if (deg[i] == n - 1) {         ans[i] = 0;         ++qt;       }     for (int i = 0; i < n; ++i)       if (ans[i] == -1) {         ++cnt;         dfs(i, cnt);       }     bool ok = true;     if (cnt >= 3) ok = false;     int n1 = 0, m1 = 0, n2 = 0, m2 = 0;     for (int i = 0; i < n; ++i) {       if (ans[i] == 1) {         ++n1;         m1 += deg[i] - qt;       } else if (ans[i] == 2) {         ++n2;         m2 += deg[i] - qt;       }     }     if (n1 * (n1 - 1) != m1) ok = false;     if (n2 * (n2 - 1) != m2) ok = false;     if (not ok)       cout <<  No n ;     else {       cout <<  Yes n ;       for (int i = 0; i < n; ++i) cout << conv(ans[i]);       cout <<   n ;     }   }


#include <bits/stdc++.h>   typedef std::function<long long(long long)> fun;   class Map {     int n, w, r;     std::vector<int> A, B;     std::function<int(long long)> lower, upper;     std::vector<long long> who;     std::vector<int> val;     void find_array(std::vector<int> &a, const std::vector<long long> &S, fun f,                     fun g) {       a.resize(1 << r);       std::vector<std::list<long long> > set(1 << r);       std::vector<int> m(1 << (r + 1));       std::vector<int> ind;       for (long long x : S) {         if (set[f(x)].empty()) ind.push_back(f(x));         set[f(x)].push_back(x);       }       std::sort(ind.begin(), ind.end(),                 [&](int x, int y) { return set[x].size() > set[y].size(); });       for (int i : ind) {         a[i] = 0;         for (int j = 0; j < r; ++j) {           int ex0 = 0, ex1 = 0;           for (long long y : set[i])             ex0 += m[(1 << (j + 1)) + ((y & ((1 << (j + 1)) - 1)) ^ a[i])],                 ex1 += m[(1 << (j + 1)) +                          ((y & ((1 << (j + 1)) - 1)) ^ (a[i] | (1 << j)))];           if (ex1 < ex0) a[i] |= (1 << j);         }         for (long long y : set[i]) {           int v = (g(y) ^ a[i]);           for (int j = 0; j < r; ++j)             m[(1 << (r - j)) + v]++, v = v & ((1 << (r - 1 - j)) - 1);         }       }     }       public:     Map() {}     Map(const std::vector<long long> &S, int word) { init(S, word); }     int operator()(long long x) { return lower(x) ^ B[upper(x) ^ A[lower(x)]]; }     int size() { return (1 << r); }     bool have(long long x) { return who[(*this)(x)] == x; }     int &operator[](long long i) { return val[(*this)(i)]; }     void init(const std::vector<long long> &S, int word) {       n = (int)S.size();       w = word;       r = std::max(w / 2, (int)std::log2(n) + 3) + 1;       assert(*std::min_element(S.begin(), S.end()) >= 0);       assert(*std::max_element(S.begin(), S.end()) < (1ll << word));       lower = [&](long long x) { return x & ((1 << r) - 1); };       upper = [&](long long x) { return x >> (w - r); };       find_array(A, S, lower, upper);       auto f2 = [&](long long x) { return upper(x) ^ A[lower(x)]; };       auto &g2 = lower;       find_array(B, S, f2, g2);       who.resize(1 << r, -1);       for (long long x : S) who[(*this)(x)] = x;       val.resize(1 << r);     }   };   void make_unique(std::vector<long long> &A) {     std::sort(A.begin(), A.end());     A.resize(std::unique(A.begin(), A.end()) - A.begin());   }   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(0);     int n, k;     std::cin >> n >> k;     std::vector<int> A(n);     long long pref = 0;     std::vector<long long> values;     values.push_back(pref);     for (int i = 0; i < n; ++i) {       std::cin >> A[i];       pref += A[i];       values.push_back(pref);     }     make_unique(values);     long long min = *std::min_element(values.begin(), values.end());     std::vector<long long> lower, upper;     for (long long x : values)       lower.push_back((x - min) & ((1 << 24) - 1)),           upper.push_back((x - min) >> 24);     make_unique(lower);     make_unique(upper);     Map ml(lower, 24);     Map mu(upper, 24);     std::vector<long long> vals;     auto kto = [&](long long x) {       if (!ml.have((x - min) & ((1 << 24) - 1)) || !mu.have((x - min) >> 24))         return -1ll;       return ml((x - min) & ((1 << 24) - 1)) +              1ll * ml.size() * mu((x - min) >> 24);     };     for (long long x : values) vals.push_back(kto(x));     make_unique(vals);     Map map(vals, 40);     long long ans = 0;     pref = 0;     map[kto(pref)]++;     for (int i = 0; i < n; ++i) {       pref += A[i];       long long pow = 1;       while (std::abs(pow) < 1000000000ll * 100000ll + 5ll) {         long long want = (pref - pow);         if (want >= min && want <= min + (1ll << 48)) {           if (kto(want) != -1 && map.have(kto(want))) {             ans += map[kto(want)];           }         }         pow *= k;         if (pow == 1) break;       }       map[kto(pref)]++;     }     std::cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, q, num, tot, tp, cnt, ans, w[200100], head[200100], dfn[200100],       c[200100], low[200100], sta[200100];   int dfc, sz[200100], d[200100], f[200100], son[200100], top[200100],       tree[200100], mn[200100 * 4];   vector<int> v[200100];   multiset<int> s[200100];   struct point {     int fr, to, nxt;   } a[200100 * 2];   void add(int x, int y) {     a[++tot].fr = x;     a[tot].to = y;     a[tot].nxt = head[x];     head[x] = tot;   }   void tarjan(int x) {     dfn[x] = low[x] = ++num;     sta[++tp] = x;     for (int i = 0; i < v[x].size(); i++) {       int y = v[x][i];       if (!dfn[y]) {         tarjan(y);         low[x] = min(low[x], low[y]);         if (low[y] == dfn[x]) {           ++cnt;           int now;           do {             now = sta[tp--];             add(cnt, now);             add(now, cnt);           } while (now != y);           add(cnt, x);           add(x, cnt);         }       } else         low[x] = min(low[x], dfn[y]);     }   }   void dfs1(int x, int fa) {     f[x] = fa;     d[x] = d[fa] + 1;     sz[x] = 1;     for (int i = head[x]; i; i = a[i].nxt) {       int y = a[i].to;       if (y == fa) continue;       dfs1(y, x);       sz[x] += sz[y];       if (sz[y] > sz[son[x]]) son[x] = y;     }   }   void dfs2(int x, int lst) {     top[x] = lst;     dfn[x] = ++dfc;     tree[dfc] = x;     if (son[x]) dfs2(son[x], lst);     for (int i = head[x]; i; i = a[i].nxt)       if (!top[a[i].to]) dfs2(a[i].to, a[i].to);   }   void build(int x, int l, int r) {     if (l == r) return mn[x] = w[tree[l]], void();     int mid = (l + r) >> 1;     build(x << 1, l, mid);     build(x << 1 | 1, mid + 1, r);     mn[x] = min(mn[x << 1], mn[x << 1 | 1]);   }   void modify(int x, int l, int r, int p, int y) {     if (l == r) return mn[x] = y, void();     int mid = (l + r) >> 1;     if (p <= mid)       modify(x << 1, l, mid, p, y);     else       modify(x << 1 | 1, mid + 1, r, p, y);     mn[x] = min(mn[x << 1], mn[x << 1 | 1]);   }   int query(int x, int l, int r, int L, int R) {     if (l >= L && r <= R) return mn[x];     int mid = (l + r) >> 1, ret = 1e9;     if (L <= mid) ret = min(ret, query(x << 1, l, mid, L, R));     if (R > mid) ret = min(ret, query(x << 1 | 1, mid + 1, r, L, R));     return ret;   }   int query(int x, int y, int ret = 1e9) {     while (top[x] != top[y]) {       if (d[top[x]] < d[top[y]]) swap(x, y);       ret = min(ret, query(1, 1, cnt, dfn[top[x]], dfn[x]));       x = f[top[x]];     }     if (d[x] < d[y]) swap(x, y);     ret = min(ret, query(1, 1, cnt, dfn[y], dfn[x]));     if (y > n) ret = min(ret, w[f[y]]);     return ret;   }   int main() {     scanf( %d%d%d , &n, &m, &q);     cnt = n;     for (int i = 1; i <= n; i++) scanf( %d , &w[i]);     for (int i = 1, x, y; i <= m; i++)       scanf( %d%d , &x, &y), v[x].push_back(y), v[y].push_back(x);     tarjan(1);     dfs1(1, 0);     dfs2(1, 1);     memset(mn, 0x3f, sizeof(mn));     for (int i = 1; i <= n; i++) s[f[i]].insert(w[i]);     for (int i = n + 1; i <= cnt; i++) w[i] = (*s[i].begin());     build(1, 1, cnt);     for (int i = 1; i <= q; i++) {       char ch[4];       int a, b;       scanf( %s%d%d , ch + 1, &a, &b);       if (ch[1] ==  C ) {         if (f[a]) {           multiset<int>::iterator pos = s[f[a]].find(w[a]);           s[f[a]].erase(pos);           s[f[a]].insert(b);           w[f[a]] = (*s[f[a]].begin());           modify(1, 1, cnt, dfn[f[a]], (*s[f[a]].begin()));         }         w[a] = b;         modify(1, 1, cnt, dfn[a], w[a]);       } else         printf( %d n , query(a, b));     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100001;   vector<int> v, w;   char s[1000001];   int main() {     scanf( %s , &s);     int len = strlen(s);     for (int i = (0); i < (len); i++) {       if (s[i] ==  @ ) v.push_back(i);       if (s[i] ==  . ) w.push_back(i);     }     int t = 0, tmp = 0;     long long ans = 0;     while (t < v.size() && tmp < w.size()) {       long long first = 0, mid = 1, last = 0;       if (t == v.size()) break;       while (v[t] > w[tmp] && tmp < w.size()) tmp++;       if (tmp == w.size()) break;       if (v[t] + 1 == w[tmp]) mid = 0;       for (int i = v[t] + 1; i < w[tmp]; i++) {         if ((s[i] >  9  || s[i] <  0 ) && (s[i] >  z  || s[i] <  a )) {           mid = 0;           break;         }       }       if (!mid) {         t++;         continue;       }       if (v[t] > 0)         for (int i = v[t] - 1; i >= 0; i--) {           if ((s[i] >=  a  && s[i] <=  z ) || (s[i] >=  0  && s[i] <=  9 ) ||               s[i] ==  _ ) {             if (s[i] >=  a  && s[i] <=  z ) first++;           } else             break;         }       if (w[tmp] + 1 < len)         for (int i = w[tmp] + 1; i < len; i++) {           if (s[i] >=  a  && s[i] <=  z )             last++;           else             break;         }       ans += first * last;       t++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, c;   int ans[1001];   int zero;   inline void send(int x, int p) {     if (ans[x] == 0) --zero;     ans[x] = p;     printf( %d n , x);     fflush(stdout);   }   int main() {     scanf( %d %d %d , &n, &m, &c);     int mid = (c + 1) / 2;     zero = n;     for (int round = 1; zero && round <= m; ++round) {       int p;       scanf( %d , &p);       if (p <= mid) {         int i;         for (i = 1; i < n; ++i)           if (ans[i] == 0 || ans[i] > p) {             break;           }         send(i, p);       } else {         int i;         for (i = n; i > 1; --i)           if (ans[i] == 0 || ans[i] < p) {             break;           }         send(i, p);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int INF = 1000000000;   const int MOD = 1073741824;   const int M = INF;   const double RRR = 180.0 / PI;   vector<vector<int> > g;   vector<bool> used;   void dfs(int v) {     used[v] = 1;     for (vector<int>::iterator it = g[v].begin(); it != g[v].end(); ++it) {       if (!used[*it]) {         dfs(*it);       }     }   }   int main() {     int x, y;     cin >> x >> y;     int d1 = 1, d2 = 0;     int e = 1;     int f = 0;     int a = 0, b = 0;     int r = 0;     int ans = 0;     if (a == x && b == y) {       cout << 0;       return 0;     }     while (1) {       a += d1;       b += d2;       r++;       if (a == x && b == y) {         cout << ans;         return 0;       }       if (r == e) {         ans++;         if (f == 0) {           f = 1;           d1 = 0;           d2 = 1;           r = 0;         } else {           if (f == 1) {             f = 2;             e++;             r = 0;             d1 = -1;             d2 = 0;           } else {             if (f == 2) {               f = 3;               r = 0;               d1 = 0;               d2 = -1;             } else {               f = 0;               e++;               r = 0;               d1 = 1;               d2 = 0;             }           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mcd(long long a, long long b) {     if (b > a) swap(a, b);     if (b == 0)       return a;     else       return mcd(b, a % b);   }   long long i, j, n, m, q, a, l, r, b;   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     cin >> q;     while (q--) {       cin >> n;       if (n == 1)         cout << 3;       else if (n == 2)         cout << 2;       else if (n & 1)         cout << 1;       else         cout << 0;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long modulo = 998244353;   const long long p = modulo;   vector<int> edges[300005];   int father[300005];   long long rCount[300005];   long long oCount[300005];   long long eCount[300005];   pair<int, int> gcd(long long a, long long b) {     if (b == 0ll) return {1ll, 0ll};     pair<int, int> q = gcd(b, a % b);     return {q.second, q.first - q.second * (a / b)};   }   long long inv(long long a) {     long long aa = gcd(a, p).first;     aa %= p;     if (aa < 0) aa += p;     return aa;   }   void trace(int index) {     for (int j = 0; j < edges[index].size(); ++j) {       int v = edges[index][j];       if (v == father[index]) {         edges[index].erase(edges[index].begin() + j);         --j;         continue;       }       father[v] = index;       trace(v);     }   }   void dfs(int index) {     if (edges[index].empty()) {       rCount[index] = 1;       oCount[index] = 1;       eCount[index] = 0;       return;     }     long long totalR = 1;     long long total = 1;     for (int j = 0; j < edges[index].size(); ++j) {       int v = edges[index][j];       dfs(v);       totalR *= rCount[v];       totalR %= modulo;       total *= rCount[v] + eCount[v];       total %= modulo;     }     rCount[index] = totalR;     oCount[index] = 1;     eCount[index] = 0;     for (int j = 0; j < edges[index].size(); ++j) {       int v = edges[index][j];       long long temp = oCount[v] * total;       temp %= modulo;       temp *= inv(rCount[v] + eCount[v]);       temp %= modulo;       rCount[index] += temp;       rCount[index] %= modulo;       oCount[index] *= (rCount[v] + eCount[v]);       oCount[index] %= modulo;       eCount[index] += temp;       eCount[index] %= modulo;     }   }   int main() {     int n;     cin >> n;     if (n == 1) {       cout << 1 << endl;       return 0;     }     int u, v;     for (int i = 0; i < n - 1; ++i) {       scanf( %i%i , &u, &v);       --u;       --v;       edges[u].push_back(v);       edges[v].push_back(u);     }     for (int i = 0; i < n; ++i) {       father[i] = -1;       rCount[i] = 0;       oCount[i] = 0;       eCount[i] = 0;     }     father[0] = -1;     trace(0);     dfs(0);     long long result = rCount[0];     while (result < 0) {       result += modulo;     }     result %= modulo;     cout << result << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = (int)1e2, maxM = (int)1e2, intMax = INT_MAX, maxValue = 44721;   const long long llmax = LLONG_MAX, INF = (long long)1e9 + 1, mod = 998244353;   long long nod(long long a, long long b) {     while (a != 0 && b != 0) {       if (a < b)         b %= a;       else         a %= b;     }     return a + b;   }   int nod(int a, int b) {     while (a != 0 && b != 0) {       if (a < b)         b %= a;       else         a %= b;     }     return a + b;   }   long long nok(long long a, long long b) { return a * b / nod(a, b); }   int nok(int a, int b) { return a * b / nod(a, b); }   long long modPlus(long long a, long long b) {     a %= mod;     b %= mod;     return a + b;   }   long long modPlus(int a, int b) {     a %= mod;     b %= mod;     return (a + b) % mod;   }   long long binPow(long long a, long long b) {     long long res = 1;     while (b) {       if (b % 2 == 1) {         res *= a;         res %= mod;       }       a = a * a;       a %= mod;       b >>= 1;     }     return res;   }   int n, s, a, b, emaxx = -1;   int main() {     scanf( %d%d , &n, &s);     s *= 100;     for (int i = 0; i < n; i++) {       scanf( %d%d , &a, &b);       b += a * 100;       if (s >= b) emaxx = max((100 - (b % 100)) % 100, emaxx);     }     printf( %d n , emaxx);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int a, b, c;       cin >> a >> b >> c;       int diff = INT_MAX;       int a1, b1, c1;       for (int i = 1; i <= 10000; i++) {         for (int j = i; j <= 20000; j += i) {           for (int k = j; k <= 50000; k += j) {             int dif = abs(a - i) + abs(b - j) + abs(c - k);             if (dif < diff) {               diff = dif;               a1 = i;               b1 = j;               c1 = k;             }           }         }       }       cout << diff << endl << a1 <<     << b1 <<     << c1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, k, q;   int it[35][800005];   struct point {     int a[10];     point(){};     int &operator[](int x) { return a[x]; }   };   point p[200005];   int sign(point &p, int bit) {     int ans = 0;     for (int i = 0; i < k; i++) {       if (bit & 1 == 1) {         ans += p[i];       } else {         ans -= p[i];       }       bit >>= 1;     }     return ans;   }   void build(int id, int l, int r) {     if (l == r - 1) {       for (int i = 0; i < (1 << k); i++) {         it[i][id] = sign(p[l], i);       }       return;     }     int mid = (l + r) / 2;     build(id * 2, l, mid);     build(id * 2 + 1, mid, r);     for (int i = 0; i < (1 << k); i++) {       it[i][id] = min(it[i][id * 2], it[i][id * 2 + 1]);     }   }   void update(int id, int l, int r, int pos, point &val) {     if (l == r - 1) {       for (int i = 0; i < (1 << k); i++) {         it[i][id] = sign(val, i);       }       return;     }     int mid = (l + r) / 2;     if (pos < mid) {       update(id * 2, l, mid, pos, val);     } else {       update(id * 2 + 1, mid, r, pos, val);     }     for (int i = 0; i < (1 << k); i++) {       it[i][id] = min(it[i][id * 2], it[i][id * 2 + 1]);     }   }   int chosen[35];   void get(int id, int l, int r, int a, int b) {     if (a >= b) return;     if (l == a && r == b) {       for (int i = 0; i < (1 << k); i++) {         chosen[i] = min(chosen[i], it[i][id]);       }       return;     }     int mid = (l + r) / 2;     get(id * 2, l, mid, a, min(mid, b));     get(id * 2 + 1, mid, r, max(mid, a), b);   }   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) {       for (int j = 0; j < k; j++) {         cin >> p[i][j];       }     }     build(1, 0, n);     cin >> q;     while (q--) {       int t;       cin >> t;       if (t == 1) {         int x;         cin >> x;         x--;         point cnt;         for (int i = 0; i < k; i++) {           cin >> cnt[i];         }         update(1, 0, n, x, cnt);       }       if (t == 2) {         int l, r;         cin >> l >> r;         l--;         for (int i = 0; i < (1 << k); i++) {           chosen[i] = 1e9;         }         get(1, 0, n, l, r);         int res = 0;         for (int i = 0; i < (1 << k); i++) {           res = max(res, abs(chosen[(1 << k) - i - 1] + chosen[i]));         }         cout << res << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 10;   struct Node {     int a, b, d;   } p[MAXN];   int n, k;   bool cmp(Node aa, Node bb) { return aa.d < bb.d; }   bool cmp2(Node aa, Node bb) { return aa.d > bb.d; }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &p[i].a);     for (int i = 1; i <= n; i++) {       scanf( %d , &p[i].b);       p[i].d = p[i].a - p[i].b;     }     long long ans = 0;     sort(p + 1, p + 1 + n, cmp);     if (p[1].d >= 0) {       for (int i = 1; i <= k; i++) ans += (long long)p[i].a;       for (int i = k + 1; i <= n; i++) ans += (long long)p[i].b;     } else if (p[n].d <= 0) {       sort(p + 1, p + 1 + n, cmp2);       for (int i = 1; i <= n; i++) {         ans += (long long)p[i].a;       }     } else {       if (p[k].d <= 0) {         for (int i = 1; i <= n; i++) {           if (p[i].d <= 0)             ans += (long long)p[i].a;           else             ans += (long long)p[i].b;         }       } else {         int tmp = 0;         for (int i = 1; i <= n; i++) {           if (p[i].d <= 0) {             ans += (long long)p[i].a;           } else {             tmp = i;             break;           }         }         sort(p + tmp, p + 1 + k, cmp2);         for (int i = tmp; i <= k; i++) {           ans += (long long)p[i].a;         }         for (int i = k + 1; i <= n; i++) {           ans += (long long)p[i].b;         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     vector<long long> dp;     dp.push_back(0);     dp.push_back(1);     while (dp.back() <= n - 1) {       dp.push_back(dp[dp.size() - 1] + dp[dp.size() - 2] + 1);     }     cout << dp.size() - 2 << endl;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast ,  unroll-loops )   using namespace std;   const int inf = numeric_limits<int>::max() / 2;   const long double eps = 1e-9;   const long double pi = acos(-1);   inline void solve(), read();   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     read();     solve();     return 0;   }   pair<int, int> operator+(pair<int, int> p1, pair<int, int> p2) {     return {p1.first + p2.first, p1.second + p2.second};   }   int q;   map<pair<int, int>, int> l, s;   map<int, set<pair<int, int>>> qs;   int n = 0;   int gcd(int a, int b) {     while (b != 0) {       a %= b;       swap(a, b);     }     return a;   }   pair<int, int> getp(pair<int, int> p) {     int g = gcd(p.first, p.second);     return {p.first / g, p.second / g};   }   void add(pair<int, int> p) {     ++n;     pair<int, int> t = getp(p);     ++l[t];     int d = p.first * p.first + p.second * p.second;     for (pair<int, int> q : qs[d]) {       pair<int, int> u = getp(p + q);       ++s[u];     }     qs[d].insert(p);   }   void del(pair<int, int> p) {     --n;     pair<int, int> t = getp(p);     --l[t];     int d = p.first * p.first + p.second * p.second;     qs[d].erase(p);     for (pair<int, int> q : qs[d]) {       pair<int, int> u = getp(p + q);       --s[u];     }   }   int get(pair<int, int> p) {     pair<int, int> t = getp(p);     return n - l[t] - 2 * s[t];   }   inline void solve() {     for (int i = 0; i < q; i++) {       int t;       pair<int, int> p;       cin >> t >> p.first >> p.second;       if (t == 1) {         add(p);       } else if (t == 2) {         del(p);       } else if (t == 3) {         int ans = get(p);         cout << ans <<   n ;       }     }   }   inline void read() { cin >> q; }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   vector<pair<int, int>> adj[N], fish[N];   int n, m, now, depth[N];   struct node_t {     int x, d, v;     node_t(int x, int d, int v, int t = 0) : x(x - d * t), d(d), v(v) {}     bool operator<(const node_t &b) const {       int p = x + now * d, q = b.x + now * b.d;       return p == q ? d < b.d : p < q;     }   };   struct collision_t {     node_t x, y;     int when;     collision_t(node_t x, node_t y) : x(x), y(y) { when = y.x - x.x >> 1; }     bool operator<(const collision_t &b) const {       if (when != b.when) {         return when < b.when;       } else {         return make_tuple(x.x, x.v, y.x, y.v) <                make_tuple(b.x.x, b.x.v, b.y.x, b.y.v);       }     }   };   struct info_t {     set<collision_t> collisions;     set<node_t> nodes;     void insert_collision(node_t x, node_t y) {       if (x.d > 0 && y.d < 0) {         collisions.insert(collision_t(x, y));       }     }     void erase_collision(node_t x, node_t y) {       if (x.d > 0 && y.d < 0) {         collisions.erase(collision_t(x, y));       }     }     void insert(node_t x) {       if (!x.v) {         return;       }       if (nodes.find(x) != nodes.end()) {         x.v += nodes.find(x)->v;         erase(*nodes.find(x));       }       auto it = nodes.insert(x).first, next = it;       ++next;       if (it != nodes.begin()) {         auto prev = it;         --prev;         if (next != nodes.end()) {           erase_collision(*prev, *next);         }         insert_collision(*prev, x);       }       if (next != nodes.end()) {         insert_collision(x, *next);       }     }     void erase(node_t x) {       auto it = nodes.find(x), next = it;       ++next;       if (next != nodes.end()) {         erase_collision(x, *next);       }       if (it != nodes.begin()) {         auto prev = it;         --prev;         erase_collision(*prev, x);         if (next != nodes.end()) {           insert_collision(*prev, *next);         }       }       nodes.erase(it);     }     int reset(int x, int y) {       node_t l(x + 1, -1, y, now), r(x - 1, 1, y, now);       return max(0, y - max(nodes.find(l) == nodes.end() ? 0 : nodes.find(l)->v,                             nodes.find(r) == nodes.end() ? 0 : nodes.find(r)->v));     }     node_t cancel(node_t x, node_t y) {       if (x.v > y.v) {         return node_t(x.x, x.d, x.v - y.v);       } else {         return node_t(y.x, y.d, y.v - x.v);       }     }     void collide(collision_t x) {       erase(x.x);       erase(x.y);       insert(cancel(x.x, x.y));     }     void maintain(int x) {       while (!collisions.empty() && collisions.begin()->when <= x) {         collide(*collisions.begin());       }     }     void merge(info_t &b) {       if (nodes.size() < b.nodes.size()) {         swap(nodes, b.nodes);         swap(collisions, b.collisions);       }       for (auto x : b.nodes) {         insert(x);       }     }     int query() {       int answer = 0;       for (auto x : nodes) {         if (x.d > 0) {           answer += x.v;         }       }       return answer;     }   } info[N];   void dfs(int x, int parent) {     for (auto e : adj[x]) {       int y = e.first, w = e.second;       if (y != parent) {         depth[y] = depth[x] + w;         dfs(y, x);       }     }   }   void solve(int x, int parent) {     for (auto e : adj[x]) {       int y = e.first, w = e.second;       if (y != parent) {         solve(y, x);         now = -depth[y];         info[y].maintain(-(depth[x] + 1));         now = -(depth[x] + 1);         info[x].merge(info[y]);       }     }     now = -(depth[x] + 1);     for (auto &e : fish[x]) {       e.second = info[x].reset(e.first, e.second);     }     info[x].maintain(-depth[x]);     now = -depth[x];     for (auto e : fish[x]) {       info[x].insert(node_t(e.first, -1, e.second, now));       info[x].insert(node_t(e.first, 1, e.second, now));     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; ++i) {       int x, y, w;       scanf( %d %d %d , &x, &y, &w);       --x;       --y;       w <<= 1;       adj[x].emplace_back(y, w);       adj[y].emplace_back(x, w);     }     scanf( %d , &m);     for (int i = 1; i <= m; ++i) {       int day, value, where;       scanf( %d %d %d , &day, &value, &where);       day <<= 1;       --where;       fish[where].emplace_back(day, value);     }     dfs(0, -1);     solve(0, -1);     info[0].maintain(INT_MAX);     printf( %d n , info[0].query());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j, k;     double maxm, sum, r;     cin >> n;     double A[n];     for (i = 0; i < n; i++) cin >> A[i];     sort(A, A + n);     maxm = A[n - 1];     for (i = n - 1; i >= 0; i--) {       sum = 0;       for (j = n - 1; j >= i; j--) {         r = A[j];         for (k = n - 1; k >= i; k--) {           if (k != j) r = r * (double(1.0) - A[k]);         }         sum += r;       }       if (sum > maxm) maxm = sum;     }     cout << setprecision(10) << maxm << endl;   }


#include <bits/stdc++.h>   void fre() {     freopen( c://test//input.in ,  r , stdin);     freopen( c://test//output.out ,  w , stdout);   }   template <class T>   inline void gmax(T &a, T b) {     if (b > a) a = b;   }   template <class T>   inline void gmin(T &a, T b) {     if (b < a) a = b;   }   using namespace std;   const int N = 1e5 + 10, M = 0, Z = 1e9 + 7, maxint = 2147483647,             ms31 = 522133279, ms63 = 1061109567, ms127 = 2139062143;   const double eps = 1e-8, PI = acos(-1.0);   int n, m;   int x, y;   int ind[N], s[N], num, top;   vector<int> a[N], b[N];   bool e[N];   void dfs(int x) {     e[x] = 1;     num++;     if (ind[x] == 0) s[++top] = x;     for (int i = a[x].size() - 1; i >= 0; i--) {       int y = a[x][i];       if (!e[y]) dfs(y);     }   }   int main() {     while (~scanf( %d%d , &n, &m)) {       memset(ind, 0, sizeof(ind));       for (int i = 1; i <= n; i++) a[i].clear(), b[i].clear();       for (int i = 1; i <= m; i++) {         scanf( %d%d , &x, &y);         ind[y]++;         a[x].push_back(y);         a[y].push_back(x);         b[x].push_back(y);       }       int ans = 0;       memset(e, 0, sizeof(e));       for (int i = 1; i <= n; i++)         if (!e[i]) {           num = top = 0;           dfs(i);           int sum = top;           while (top) {             int x = s[top--];             for (int j = b[x].size() - 1; j >= 0; j--) {               int y = b[x][j];               ind[y]--;               if (ind[y] == 0) {                 s[++top] = y;                 sum++;               }             }           }           if (sum == num)             ans += (num - 1);           else             ans += num;         }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int a, b, c;       cin >> a >> b >> c;       if (a > b) swap(a, b);       int mx = (b - a) * 2;       if (a > mx || b > mx || c > mx)         cout <<  -1 n ;       else {         if (c > mx / 2)           cout << c - mx / 2 <<   n ;         else           cout << c + mx / 2 <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[50100];   long long m, ans;   struct node {     int s, cnt[30];     node *ch[2];     node();   } * tp, *nul, *root[50100];   int getint() {     char ch;     while (!isdigit(ch = getchar()))       ;     int x = ch -  0 ;     for (; isdigit(ch = getchar()); x = x * 10 + ch -  0 )       ;     return x;   }   node::node() { ch[0] = tp, tp = this; }   node *newnode(node *x) {     if (!tp) new node[50000];     node *t = tp;     tp = t->ch[0], *t = *x;     return t;   }   void insert(node *&x, node *y, int w) {     node *ret = newnode(y);     ++(x = ret)->s;     for (int i = 29; i >= 0; --i) {       for (int j = 0; j <= i; ++j) x->cnt[j] += (w >> j) & 1;       int t = (w >> i) & 1;       x->ch[t] = newnode(y = y->ch[t]), ++(x = x->ch[t])->s;     }     x = ret;   }   int main() {     scanf( %d%I64d , &n, &m);     nul = new node, tp = 0;     memset(nul, 0, sizeof(node));     root[1] = nul->ch[0] = nul->ch[1] = nul;     for (int i = 1; i <= n; ++i) insert(root[i + 1], root[i], a[i] = getint());     for (int i = 29; i >= 0; --i) {       long long sum = 0;       for (int j = 2; j <= n; ++j) sum += root[j]->ch[1 ^ ((a[j] >> i) & 1)]->s;       if (sum < m) {         m -= sum, ans += (1LL << i) * sum;         for (int j = 2; j <= n; ++j) {           node *x = root[j]->ch[1 ^ ((a[j] >> i) & 1)];           for (int k = 0; k <= i - 1; ++k)             ans +=                 (1LL << k) * (((a[j] >> k) & 1) ? x->s - x->cnt[k] : x->cnt[k]);           root[j] = root[j]->ch[(a[j] >> i) & 1];         }       } else {         ans += (1LL << i) * m;         for (int j = 2; j <= n; ++j) root[j] = root[j]->ch[1 ^ ((a[j] >> i) & 1)];       }     }     printf( %d n , ans % 1000000007);     return 0;   }