#include <bits/stdc++.h>   using namespace std;   template <typename t>   t in(t q) {     cin >> q;     return q;   }   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& v) {     os <<  [ ;     for (int i = 0; i < ((int)size(v)); ++i) {       os << v[i];       if (i != ((int)size(v)) - 1) os <<  , ;     }     os <<  ] ;     return os;   }   template <typename T, typename S>   ostream& operator<<(ostream& os, const map<T, S>& v) {     for (auto it : v) os <<  (  << it.first <<  :  << it.second <<  ) ;     return os;   }   template <typename T, typename S>   ostream& operator<<(ostream& os, const pair<T, S>& v) {     os <<  (  << v.first <<  ,  << v.second <<  ) ;     return os;   }   const long double PI = acosl(-1);   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());   inline int rand(int l, int r) {     return uniform_int_distribution<int>(l, r)(rng);   }   inline long long rand(long long l, long long r) {     return uniform_int_distribution<long long>(l, r)(rng);   }   int p;   int i;   int xw;   long long ans = 0;   int j;   bool s1, s2;   int n, k;   struct node;   node* last;   struct node {     int sum;     node *lft, *rht;     node() {       sum = 0;       lft = NULL;       rht = NULL;     }     int query(int l) {       if (l == 2) return sum;       if (l) {         if (!rht) rht = new node();         last = rht;         if (!lft) return 0;         return lft->sum;       }       if (!lft) lft = new node();       last = lft;       if (!rht) return 0;       return rht->sum;     }     void update(int l, int r) {       if (l == r) {         sum++;         return;       }       int mid = (l + r) / 2;       if (xw <= mid) {         if (!lft) lft = new node();         lft->update(l, mid);       } else {         if (!rht) rht = new node();         rht->update(mid + 1, r);       }       sum++;     }   };   node* r = new node();   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << setprecision(10);     cin >> n >> k;     xw = 0;     r->update(0, 1073741823);     for (i = 1; i < n + 1; ++i) {       cin >> p;       last = r;       p ^= xw;       for (j = 29; j >= 0; --j) {         s1 = ((1 << j) & k);         s2 = (1 << j) & p;         if (s1 && s2) {           if (!last->lft) break;           last = last->lft;         } else if (s1 && !s2) {           if (!last->rht) break;           last = last->rht;         } else if (s2) {           ans += last->query(1);         } else {           ans += last->query(0);         }       }       if (j == -1) ans += last->query(2);       xw = p;       r->update(0, 1073741823);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, a[2005], b[2005], x = 0, y = 0, n, m, sum = 0;     cin >> n;     for (i = 0; i < n; i++) {       cin >> m;       if (m % 2 == 0) {         a[x] = m;         x++;       } else {         b[y] = m;         y++;       }     }     sort(a, a + x, greater<int>());     sort(b, b + y, greater<int>());     if (x == y || x + 1 == y || y + 1 == x) {       cout <<  0  << endl;     } else {       if (x > y) {         for (i = y + 1; i < x; i++) {           sum += a[i];         }       }       if (x < y) {         for (i = x + 1; i < y; i++) {           sum += b[i];         }       }       cout << sum << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   const int MOD = 998244353;   const int PRIMROOT = 3;   int pw(int x, int n) {     int ret = 1;     while (true) {       if (n & 1) ret = (long long)ret * x % MOD;       if ((n >>= 1) == 0) return ret;       x = (long long)x * x % MOD;     }   }   struct NTT {     void _init(int n, int &nlog, int &g, vector<int> &w) {       assert((MOD - 1) % n == 0);       g = pw(PRIMROOT, (MOD - 1) / n);       nlog = 0;       while ((1 << nlog) < n) ++nlog;       if ((1 << nlog) != n) nlog = -1;       w = vector<int>(n);       w[0] = 1;       for (int i = (1); i < (n); ++i) w[i] = (long long)w[i - 1] * g % MOD;     }     int fftn, fftnlog;     int fftg;     vector<int> fftw;     void initfft(int n) {       fftn = n, _init(fftn, fftnlog, fftg, fftw);       assert(fftnlog != -1);     }     void fft(int *a, int n, bool inv) {       if (n != fftn) initfft(n);       for (int i = 1, j = n >> 1, k, l = j; i < n; j ^= k, ++i) {         if (i < j) swap(a[i], a[j]);         for (k = l; k & j; j ^= k, k >>= 1)           ;       }       int *l, *r, *w;       if (inv) reverse(fftw.begin() + 1, fftw.end());       for (int hlen = 1, step = n >> 1; hlen < n; hlen <<= 1, step >>= 1) {         for (int i = 0; i < n; i += (hlen << 1)) {           l = a + i, r = l + hlen, w = fftw.data();           for (int off = (0); off < (hlen); ++off) {             int v = (long long)(*r) * (*w) % MOD;             *r = (*l) - v;             if (*r < 0) *r += MOD;             *l = (*l) + v;             if (*l >= MOD) *l -= MOD;             ++l, ++r, w += step;           }         }       }       if (inv) reverse(fftw.begin() + 1, fftw.end());       if (inv) {         int mlt = pw(n, MOD - 2);         for (int i = (0); i < (n); ++i) a[i] = (long long)a[i] * mlt % MOD;       }     }     void mult(const int *a, int na, const int *b, int nb, int *c, int nc) {       int sz = 1;       while (sz < na + nb - 1) sz *= 2;       vector<int> A(sz, 0), B(sz, 0);       for (int i = (0); i < (na); ++i) A[i] = a[i];       for (int i = (0); i < (nb); ++i) B[i] = b[i];       fft(A.data(), sz, false);       fft(B.data(), sz, false);       for (int i = (0); i < (sz); ++i) A[i] = (long long)A[i] * B[i] % MOD;       fft(A.data(), sz, true);       for (int i = (0); i < (nc); ++i) c[i] = i < sz ? A[i] : 0;     }   };   NTT ntt;   void inc(int &a, int b) {     if ((a += b) >= MOD) a -= MOD;   }   vector<int> add(const vector<int> &a, const vector<int> &b) {     vector<int> c(max(((int)(a).size()), ((int)(b).size())), 0);     for (int i = (0); i < (((int)(c).size())); ++i) {       if (i < ((int)(a).size())) inc(c[i], a[i]);       if (i < ((int)(b).size())) inc(c[i], b[i]);     }     return c;   }   vector<int> mult(const vector<int> &a, const vector<int> &b) {     vector<int> c(((int)(a).size()) + ((int)(b).size()) - 1, 0);     ntt.mult(a.data(), ((int)(a).size()), b.data(), ((int)(b).size()), c.data(),              ((int)(c).size()));     return c;   }   const int MAXN = 100000;   int n;   long long want;   vector<int> adj[MAXN];   int par[MAXN];   int sz[MAXN];   int dep[MAXN];   int heavy[MAXN];   vector<int> ways[MAXN];   vector<int> waysnonheavy[MAXN];   void dfsinit(int at) {     dep[at] = par[at] == -1 ? 0 : dep[par[at]] + 1, sz[at] = 1, heavy[at] = -1;     for (int i = (0); i < (((int)(adj[at]).size())); ++i) {       int to = adj[at][i];       if (to == par[at]) continue;       par[to] = at;       dfsinit(to);       sz[at] += sz[to];       if (heavy[at] == -1 || sz[to] > sz[heavy[at]]) heavy[at] = to;     }   }   int path[MAXN], npath;   pair<vector<int>, vector<int>> rec(int l, int r) {     if (l == r) {       int at = path[l];       return make_pair(waysnonheavy[at], waysnonheavy[at]);     } else {       int m = l + (r - l) / 2;       auto res1 = rec(l, m);       auto res2 = rec(m + 1, r);       return make_pair(add(res1.first, mult(res1.second, res2.first)),                        mult(res1.second, res2.second));     }   }   int lst[MAXN], nlst;   vector<int> tmp[2 * MAXN];   int ntmp;   priority_queue<pair<int, int>> pq;   void calcways(int at);   void calcwaysnonheavy(int at) {     for (int i = (0); i < (((int)(adj[at]).size())); ++i) {       int to = adj[at][i];       if (to == par[at] || to == heavy[at]) continue;       calcways(to);     }     nlst = 0;     for (int i = (0); i < (((int)(adj[at]).size())); ++i) {       int to = adj[at][i];       if (to == par[at] || to == heavy[at]) continue;       lst[nlst++] = to;     }     ntmp = nlst;     pq = priority_queue<pair<int, int>>();     for (int i = (0); i < (nlst); ++i)       tmp[i] = ways[lst[i]], pq.push(make_pair(-((int)(tmp[i]).size()), i));     while (((int)(pq).size()) >= 2) {       int a = pq.top().second;       pq.pop();       int b = pq.top().second;       pq.pop();       int c = ntmp++;       tmp[ntmp] = mult(tmp[a], tmp[b]),       pq.push(make_pair(-((int)(tmp[c]).size()), c));     }     waysnonheavy[at] =         ((int)(pq).size()) == 1 ? tmp[pq.top().second] : vector<int>(1, 1);     waysnonheavy[at].insert(waysnonheavy[at].begin(), 0);     for (int i = (0); i < (ntmp); ++i) tmp[i].clear();   }   void calcways(int at) {     for (int x = at; x != -1; x = heavy[x]) calcwaysnonheavy(x);     npath = 0;     for (int x = at; x != -1; x = heavy[x]) path[npath++] = x;     ways[at] = rec(0, npath - 1).first;     inc(ways[at][0], 1);   }   int inv[MAXN + 1];   void run() {     scanf( %d%lld , &n, &want);     for (int i = (0); i < (n - 1); ++i) {       int a, b;       scanf( %d%d , &a, &b);       --a, --b;       adj[a].push_back(b);       adj[b].push_back(a);     }     par[0] = -1;     dfsinit(0);     calcways(0);     int ret = 0, mlt = 1;     inv[1] = 1;     for (int i = (2); i < (((int)(ways[0]).size())); ++i)       inv[i] = (long long)(MOD - MOD / i) * inv[MOD % i] % MOD;     for (int i = (1); i < (((int)(ways[0]).size())); ++i) {       ret = (ret + (long long)ways[0][i] * mlt) % MOD;       mlt = (long long)mlt * (want % MOD + i) % MOD * inv[i] % MOD;     }     printf( %d n , ret);   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char a[200005];     cin >> a;     for (int i = 0; a[i] !=   0 ; ++i) {       if (i && a[i - 1] == a[i]) {         if (a[i - 1] !=  x  && a[i + 1] !=  x )           a[i] =  x ;         else if (a[i - 1] !=  y  && a[i + 1] !=  y )           a[i] =  y ;         else           a[i] =  z ;       }     }     cout << a << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename X>   void MA(X& a, X b) {     a = max(a, b);   }   template <typename X>   void MI(X& a, X b) {     a = min(a, b);   }   template <typename X>   void clr(X& x, int a) {     memset(x, a, sizeof(x));   };   int cond = 0, multi = 0, gcj = 0;   int N;   const int MAXN = 111;   vector<array<int, 2> > ED[MAXN];   long double wsp[MAXN];   array<int, 3> res[MAXN];   int numkr = 0;   void go(int u, int p, long double val) {     int kr = 0;     kr += ED[u].size();     {       if (cond)         cerr << 38 <<                  <<  u <<     << kr <<     << val               <<     << u <<     << kr <<     << val << endl;     };     val += 2.0 / kr;     while (val >= 2.0) val -= 2.0;     for (array<int, 2> ed : ED[u])       if (ed[0] != p) {         int v = ed[0];         int idx = ed[1];         {           if (cond)             cerr << 45 <<                      <<  u <<     << v <<     << val                   <<     << u <<     << v <<     << val << endl;         };         go(v, u, 1 + val);         if (val <= 1.0) {           res[numkr] = array<int, 3>({v, u, idx});           wsp[numkr] = 1.0 - val;         } else {           res[numkr] = array<int, 3>({u, v, idx});           wsp[numkr] = 2.0 - val;         }         numkr++;         val += 2.0 / kr;         while (val >= 2.0) val -= 2.0;       }   }   void solve() {     cin >> N;     for (auto i = (1); i <= (N - 1); ++i) {       int u, v;       cin >> u >> v;       ED[u].push_back(array<int, 2>({v, i}));       ED[v].push_back(array<int, 2>({u, i}));     }     go(1, -1, 0);     cout << N - 1 <<   n ;     for (auto i = 0; i < (N - 1); ++i) {       cout << 1 <<     << res[i][2] <<     << res[i][0] <<     << res[i][1] <<                << wsp[i] <<   n ;     }   }   int main(int argc, char** argv) {     ios::sync_with_stdio(false), cin.tie(0),         cond = argc >= 2 && argv[1][0] ==  q  ? 1 << 30 : 0;     cout.setf(ios::fixed), cout.precision(10);     int t;     if (multi || gcj)       cin >> t;     else       t = 1;     for (auto i = (1); i <= (t); ++i) {       if (cond) cerr << 84 <<     << i << endl;       if (gcj) cout <<  Case #  << i <<  :  ;       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool comp(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   long long gcd(long long a, long long b) {     if (!b) return a;     return gcd(b, a % b);   }   int main() {     long long n, k;     cin >> n >> k;     long long lx[43];     if (k == 1)       cout <<  Yes n ;     else {       if (k > 42ll)         cout <<  No n ;       else {         lx[1] = 1;         for (long long i = 2; i < 43; i++) {           lx[i] = lx[i - 1] * (i / gcd(lx[i - 1], i));         }         if ((n + 1) % lx[k] == 0)           cout <<  Yes n ;         else           cout <<  No n ;       }     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( fast-math )   using namespace std;   template <class T>   ostream &operator<<(ostream &str, vector<T> &a) {     for (auto &i : a) {       str << i <<    ;     }     return str;   }   template <class T>   istream &operator>>(istream &str, vector<T> &a) {     for (auto &i : a) {       str >> i;     }     return str;   }   template <class T>   ostream &operator<<(ostream &str, pair<T, T> &a) {     str << a.first <<     << a.second;     return str;   }   template <class T>   istream &operator>>(istream &str, pair<T, T> &a) {     str >> a.first >> a.second;     return str;   }   void solve();   signed main() {     srand(time(0));     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout.setf(ios::fixed);     cout.precision(6);     solve();     return 0;   }   int n, m;   int get_sum(vector<vector<int>> &b, int i1, int j1, int i2, int j2) {     return b[i2][j2] - b[i1 - 1][j2] - b[i2][j1 - 1] + b[i1 - 1][j1 - 1];   }   bool check(int k, vector<vector<int>> &a, vector<vector<int>> &b,              vector<vector<int>> &tmp) {     int len = 2 * k + 1;     if (len > n || len > m) {       return false;     }     vector<vector<int>> v(m + 2, vector<int>(n + 2));     for (int i = 1; i <= n - len + 1; ++i) {       for (int j = 1; j <= m - len + 1; ++j) {         int sum = get_sum(b, i, j, i + len - 1, j + len - 1);         if (sum == len * len) {           tmp[i + len / 2][j + len / 2] = 1;           v[j][i] += 1, v[j][i + len] -= 1;           v[j + len][i] -= 1, v[j + len][i + len] += 1;         }       }     }     for (int j = 1; j <= m; ++j) {       for (int i = 1; i <= n; ++i) {         v[j][i] = v[j][i - 1] + v[j][i];       }     }     vector<vector<int>> c(n + 1, vector<int>(m + 1));     for (int j = 1; j <= m; ++j) {       for (int i = 1; i <= n; ++i) {         c[i][j] = v[j][i];       }     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         c[i][j] = c[i][j - 1] + c[i][j];       }     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         if (a[i][j] && c[i][j] == 0) {           return false;         }       }     }     return true;   }   void solve() {     cin >> n >> m;     vector<vector<int>> a(n + 1, vector<int>(m + 1));     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         char ch;         cin >> ch;         a[i][j] = (ch ==  X  ? 1 : 0);       }     }     vector<vector<int>> b = a;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         b[i][j] = b[i][j] + b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1];       }     }     vector<vector<int>> ans(n + 1, vector<int>(m + 1));     int l = 0, r = min(n, m);     while (r - l > 1) {       int k = (r + l) / 2;       vector<vector<int>> tmp(n + 1, vector<int>(m + 1));       if (check(k, a, b, tmp)) {         ans = tmp;         l = k;       } else {         r = k;       }     }     check(l, a, b, ans);     cout << (l) <<   n ;     ;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         cout << (ans[i][j] ?  X  :  . );       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;      #define S size()   #define EN end()   #define BE begin()   #define LEN length()      #define endl   n    #define cnt count   #define in insert   #define er erase   #define fi first   #define se second   #define ld double   #define int long long      #define gcd __gcd   #define mp make_pair   #define pb push_back   #define lb lower_bound   #define ub upper_bound   #define bs binary_search   #define np next_permutation      #define si set<int>   #define sc set<char>   #define mll map<int,int>   #define vi vector<int>   #define vc vector<char>   #define pll pair<int,int>   #define vpi vector<pll>   #define msi multiset<int>   #define msc multiset<char>   #define vvi vector<vector<int>>      #define mod1 1000000007   #define mod2 998244353   #define inf (int)1e9   #define eness(x) __builtin_ctzll(x)   #define nhigh(x) __builtin_popcountll(x)   #define PI 3.1415926535897932384626433832      #define iter(s) for(auto it:s)   #define forl(i,n) for(int i=0;i<n;i++)   #define fore(i,n) for(int i=1;i<=n;i++)   #define forn(i,n) for(int i=n-1;i>=0;i--)   #define forls(i,l,r) for(int i=l;i<r;i++)   #define forns(i,l,r) for(int i=r-1;i>=l;i--)      #define all(v) v.BE,v.EN   #define SORT(ar,n) sort(ar,ar+n)   #define rall(v) v.rbegin(),v.rend()   #define RSORT(ar,n) sort(ar,ar+n,greater<int>())      #define pat int n;cin>>n;   #define wq int q;cin>>q;fore(_,q)   #define nokay cout<<(ok? Yes n : No n );   #define tak(s) string s;cin>>s;int n=s.LEN;   #define pat1 int n;cin>>n;int ar[n];forl(i,n) cin>>ar[i];   #define pat2 int n,k;cin>>n>>k;int ar[n];forl(i,n) cin>>ar[i];   #define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);   //**********************************   vi mf,mi;   int POW(int x,int y);   int MI(int x,int mod);   void pre_f(int x,int mod);   void pre_i(int x,int mod);   int C(int x,int y,int mod);   int bpow(int x,int y,int mod);      int POW(int x,int y){       return bpow(x,y,inf);   }   int MI(int x,int mod=mod1){       return bpow(x,mod-2,mod);   }   void pre_f(int x,int mod=mod1){       mf=vi(x+1,1);       forls(i,2,x+1){           mf[i]=mf[i-1]*i;           mf[i]%=mod;       }       return;   }   void pre_i(int x,int mod=mod1){       mi=vi(x+1);       forl(i,x+1){           mi[i]=MI(mf[i],mod);       }       return;   }   int C(int x,int y,int mod=mod1){       if(x<y) return 0;       int n1=mf[x];       int n2=mi[y];       int n3=mi[x-y];       int res=(n1*n2)%mod;       res=(res*n3)%mod;       return res;   }   int bpow(int x,int y,int mod=mod1){       x%=mod;       int res=1;       while(y>0){           if(y&1){               res=res*x%mod;           }           x=x*x%mod;           y>>=1;       }       return res;   }   //**********************************   const int N=200001;   vector<vector<array<int,2>>> adj(N);   int32_t main(){       #ifndef ONLINE_JUDGE           freopen( ./input.txt ,  r , stdin);           freopen( ./output.txt ,  w , stdout);       #endif       fastio;       int n,m;       cin>>n>>m;       int dis[n+1][51];       forl(i,n+1){           forl(j,51){               dis[i][j]=inf;           }       }          forl(i,m){           int u,v,w;           cin>>u>>v>>w;           adj[u].pb({v,w});           adj[v].pb({u,w});       }       dis[1][0]=0;       //i*51+j -> row dom.       set<array<int,2>> pq;       pq.in({0,51});       //int t=100;       while(!pq.empty()/* && t--*/){           //auto itt=pq.BE           set<array<int,2>>::iterator itt=pq.BE;           array<int,2> x=*itt;           pq.er(itt);           int d=x[0],p=x[1]%51,u=x[1]/51;           iter(adj[u]){               int v=it[0],w=it[1];               //cout<<u<<   <<v<<   <<p<<  n ;               if(p==0){                   int dd=(d);                   if(dis[v][w]>dd){                       set<array<int,2>>::iterator fin=pq.find({dis[v][w],v*51+w});                       if(fin!=pq.end()){                           pq.er(fin);                       }                       dis[v][w]=dd;                       pq.in({dd,v*51+w});                   }               }               else{                   int dd=(d+(p+w)*(p+w));                   if(dis[v][0]>dd){                       set<array<int,2>>::iterator fin=pq.find({dis[v][0],v*51});                       if(fin!=pq.end()){                           pq.er(fin);                       }                       dis[v][0]=dd;                       pq.in({dd,v*51});                   }               }           }       }       fore(i,n){           if(dis[i][0]==inf){               cout<<-1<<   ;           }           else{               cout<<dis[i][0]<<   ;           }       }          }


#include <bits/stdc++.h>   using namespace std;   long long get(long long r) { return (r + 1) * r / 2; }   long long sumto(long long r, int need) {     long long pw = 1;     long long sum = 0;     long long add = 0;     for (int len = 1;; ++len) {       if (pw * 10 - 1 < r) {         long long cnt = pw * 10 - pw;         if (need) {           sum += add * cnt + get(cnt) * len;           add += cnt * len;         } else {           sum += cnt * len;         }       } else {         long long cnt = r - pw + 1;         if (need) {           sum += add * cnt + get(cnt) * len;         } else {           sum += cnt * len;         }         break;       }       pw *= 10;     }     return sum;   }   int main() {     int q;     cin >> q;     while (q--) {       long long k;       cin >> k;       --k;       long long l = 1, r = 1e9;       long long res = -1;       while (r - l >= 0) {         long long mid = (l + r) >> 1;         if (sumto(mid, 1) > k) {           res = mid;           r = mid - 1;         } else {           l = mid + 1;         }       }       k -= sumto(res - 1, 1);       l = 1, r = res;       long long num = -1;       while (r - l >= 0) {         int mid = (l + r) >> 1;         if (sumto(mid, 0) > k) {           num = mid;           r = mid - 1;         } else {           l = mid + 1;         }       }       cout << to_string(num)[k - sumto(num - 1, 0)] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ans, b, a, f, s, k, ss;   int main() {     cin >> a >> b;     if (a == b) {       cout <<  infinity ;       return 0;     }     if (a < b) {       cout << 0;       return 0;     }     for (int i = 1; i <= round(sqrt(a - b)); i++) {       if ((a - b) % i == 0) ans++;       if (((a - b) % i == 0 && i <= b)) s++;       if ((a - b) % i == 0 && (a - b) / i <= b) s++;     }     ans *= 2;     if (round(sqrt(a - b)) * round(sqrt(a - b)) == a - b) {       ans--;       if (round(sqrt(a - b)) <= b) s--;     }     ans -= s;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n, m = 0, sum = 0;     cin >> n;     string s;     getline(cin, s);     getline(cin, s);     for (int i = 0; i < n; i++) {       if (s[i] ==    ) {         m = max(m, sum);         sum = 0;       }       if (s[i] >=  A  && s[i] <=  Z ) sum++;     }     m = max(m, sum);     cout << m;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, n;   long long vet[2000010];   bool comp(long long l, long long maior, long long meio, long long m,             long long t) {     if (a + ((meio - 1) * b) > t) return false;     if (vet[meio] - vet[l - 1] > m * t) return false;     return true;   }   int main() {     cin >> a >> b >> n;     for (int i = 0; i < 2000008; ++i) {       if (i == 0) {         vet[i] = 0;       } else {         vet[i] = ((a) + (i - 1) * b) + vet[i - 1];       }     }     for (int i = 0; i < n; ++i) {       long long l, t, m;       cin >> l >> t >> m;       long long menor = l, maior = t + 5, meio;       while (menor <= maior) {         meio = (maior + menor) / 2;         if (comp(l, maior, meio, m, t))           menor = meio + 1;         else           maior = meio - 1;       }       if (maior < l)         cout <<  -1  << endl;       else         cout << maior << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int v[26][N];   int main() {     int n;     cin >> n;     string s;     for (int i = 0; i < n; ++i) {       cin >> s;       for (int j = 0; j < s.size(); j++)         if (s[j] !=  ? ) v[s[j] -  a ][j]++;     }     string ans =   ;     int pos = 0;     for (int i = 0; i < s.size(); ++i) {       int may = 0;       for (int j = 0; j < 26; j++) {         if (may < v[j][i]) {           may = v[j][i];           pos = j;         }       }       int a1 = 0;       bool flag = 0;       char x =  * ;       for (int j = 0; j < 26; j++) {         if (may == v[j][i] or (v[j][i] != may && v[j][i])) a1++, flag = 1;         if (flag && !v[j][i]) {           if (a1 <= 1) x = j;           flag = 0;         }       }       if (a1 == 1)         ans += char(pos) +  a ;       else {         if (may != 0)           ans +=  ? ;         else           ans += char(x) +  a ;       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353;   long long exp(long long n, long long m, long long md) {     long long a = 1;     while (m > 0) {       if (m & 1) a = (a * n % md) % md;       m /= 2;       n = (n * n) % md;     }     return a % md;   }   long long R = MOD;   long long modInverse(long long n) { return exp(n, R - 2, R); }   long long ncr(long long n, long long r) {     if (r == 0) return 1;     vector<long long> fac(n + 1, 1);     for (long long i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % R;     return ((fac[n] * modInverse(fac[r]) % R) * modInverse(fac[n - r]) % R) % R;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n, k;     cin >> n >> k;     if (k > n)       cout << 0 <<   n ;     else if (k == 1)       cout << n <<   n ;     else {       long long ans = 0;       for (long long i = 1; i * k <= n; i++) {         ans += ncr(n / i - 1, k - 1);         ans %= R;       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int P = 10, N = 1e5 + 10;   inline int inverse(int a, int m) {     if (a <= 1) return a;     int ans = (1 - (long long int)inverse(m % a, a) * m) / a;     return ans + m;   }   int fact[N], ifact[N], pot[N][P];   int sz, p[P];   inline void primes(int n) {     for (int d = 2; d * d <= n; d++)       if (n % d == 0) {         p[sz++] = d;         while (n % d == 0) n /= d;       }     if (n > 1) p[sz++] = n;   }   int mod;   int expo[P][N];   inline int comb(int m, int n) {     int ans = (long long int)fact[m] * ifact[n] % mod * ifact[m - n] % mod;     for (register int i = 0; i < (int)(sz); ++i) {       int pp = pot[m][i] - pot[n][i] - pot[m - n][i];       if (pp) ans = (long long int)ans * expo[i][pp] % mod;     }     return ans;   }   inline int go(int n, int bal) {     long long int ans = 0;     for (register int x = 0, y = bal; x + y <= n; ++x, ++y)       ans += (long long int)comb(n, x) * comb(n - x, y) % mod;     return ans % mod;   }   int main() {     int n, l, r;     cin >> n >> mod >> l >> r;     primes(mod);     fact[0] = ifact[0] = 1;     int fn = 1;     for (register int j = 0; j < (int)(sz); ++j) expo[j][0] = 1;     for (int i = 1; i <= n; i++) {       int d = -1;       for (register int j = 0; j < (int)(sz); ++j)         if (i % p[j] == 0) {           d = j;           break;         }       if (d == -1)         fact[i] = i;       else {         fact[i] = fact[i / p[d]];         for (register int j = 0; j < (int)(sz); ++j)           pot[i][j] = pot[i / p[d]][j] + (j == d);       }       fn = (long long int)fn * fact[i] % mod;       for (register int j = 0; j < (int)(sz); ++j)         expo[j][i] = (long long int)expo[j][i - 1] * p[j] % mod;     }     ifact[n] = inverse(fn, mod);     for (register int i = n - 1; i >= 0; --i)       ifact[i] = (long long int)ifact[i + 1] * fact[i + 1] % mod;     for (register int i = 1; i <= n; ++i) {       fact[i] = (long long int)fact[i - 1] * fact[i] % mod;       for (register int j = 0; j < (int)(sz); ++j) pot[i][j] += pot[i - 1][j];     }     long long int ans = 0;     for (register int i = 0; i < (int)(2); ++i)       ans += (long long int)go(n, l + i) + mod - go(n, r + 1 + i);     cout << ans % mod << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     deque<int> vec;     int arr[200005];     int n, a;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a);       vec.push_back(a);       arr[i] = 0;     }     for (int i = 0; i < n; i++) {       scanf( %d , &a);       int j = 0, i1 = 0;       if (arr[a - 1] == 1) {         printf( 0  );       } else if (vec.empty() != true) {         int k = 0, f = 0;         while (true) {           arr[vec.front() - 1] = 1;           if (vec.front() == a) {             vec.pop_front();             break;           }           vec.pop_front();           k++;         }         printf( %d  , k + 1);       } else         printf( 0  );     }   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   template <class T>   struct RMQ {     const int STEP_P = 5;     const int STEP = 1 << STEP_P;     vector<T> data;     const T INF;     vector<vector<T> > small_powers;     vector<vector<T> > group_powers;     int N;     RMQ(vector<T> data_, T INF_) : data(data_), INF(INF_){};     void init() {       N = int((data).size());       small_powers = vector<vector<T> >(STEP_P + 1, vector<T>(N));       small_powers[0] = data;       for (int p = (0); p < (STEP_P); p++)         for (int n = (0); n < (N); n++) {           small_powers[p + 1][n] =               min(small_powers[p][n], small_powers[p][min(n + (1 << p), N - 1)]);         }       int GN = (N + STEP - 1) / STEP;       int GP = 1;       while (GN > (1 << GP)) ++GP;       group_powers = vector<vector<T> >(GP + 1, vector<T>(GN));       for (int i = (0); i < (GN); i++)         group_powers[0][i] = small_powers[STEP_P][i << STEP_P];       for (int p = (0); p < (GP); p++)         for (int n = (0); n < (GN); n++) {           group_powers[p + 1][n] =               min(group_powers[p][n], group_powers[p][min(n + (1 << p), GN - 1)]);         }     }     int largest_bit(int n) { return 31 - __builtin_clz(max(1, n - 1)); }     T query(int f, int t) {       assert(f >= 0 && t <= N);       if (f >= t) return INF;       int p = min(STEP_P, largest_bit(t - f));       auto res = min(small_powers[p][f], small_powers[p][t - (1 << p)]);       if (t - f > STEP + STEP) {         int g_f = f / STEP + 1, g_t = t / STEP;         p = largest_bit(g_t - g_f);         res =             min(res, min(group_powers[p][g_f], group_powers[p][g_t - (1 << p)]));       }       return res;     }   };   const int MAXN = 5e5;   int A[MAXN];   vector<int> adj[MAXN];   vector<long long> dp_only[MAXN];   vector<long long> dp_not[MAXN];   long long dp_all[MAXN];   int todo[MAXN];   int xo[MAXN];   long long cost[MAXN];   int etox[MAXN][2];   int edgeval[MAXN][2];   int N, Q;   long long calc_not(int n, int eid) {     int xid = etox[eid][0];     if (int((adj[n]).size()) <= xid || adj[n][xid] != eid) xid = etox[eid][1];     if (dp_not[n][xid] == -1) {       if (dp_all[n] == -1) {         dp_all[n] = A[n];         todo[n] = xid;         for (int i = (0); i < (int((adj[n]).size())); i++)           if (i != xid) {             int neid = adj[n][i];             dp_only[n][i] =                 max(0ll, calc_not(xo[neid] ^ n, neid) - cost[neid] * 2ll);             dp_all[n] += dp_only[n][i];           }         dp_not[n][xid] = dp_all[n];       } else if (todo[n] != -1) {         int neid = adj[n][todo[n]];         dp_only[n][todo[n]] =             max(0ll, calc_not(xo[neid] ^ n, neid) - cost[neid] * 2ll);         dp_all[n] += dp_only[n][todo[n]];         assert(dp_only[n][xid] != -1);         dp_not[n][xid] = dp_all[n] - dp_only[n][xid];         todo[n] = -1;       } else {         assert(dp_only[n][xid] != -1);         dp_not[n][xid] = dp_all[n] - dp_only[n][xid];       }     }     return dp_not[n][xid];   }   long long calc_only(int n, int eid) {     int xid = etox[eid][0];     if (adj[n][xid] != eid) xid = etox[eid][1];     assert(adj[n][xid] == eid);     assert(dp_only[n][xid] != -1);     return dp_only[n][xid];   }   int parent_edge[MAXN];   int depth[MAXN];   long long dp_acc[MAXN];   pair<int, int> tmp_rmqdata[MAXN * 2];   int rmqposition[MAXN];   int TMP_RMQDATA;   void calc_accumulate(int n) {     rmqposition[n] = TMP_RMQDATA;     tmp_rmqdata[TMP_RMQDATA++] = make_pair(depth[n], n);     for (auto eid : adj[n])       if (eid != parent_edge[n]) {         int to = xo[eid] ^ n;         dp_acc[to] =             dp_acc[n] - calc_only(n, eid) - cost[eid] + calc_not(to, eid);         depth[to] = depth[n] + 1;         parent_edge[to] = eid;         calc_accumulate(to);         tmp_rmqdata[TMP_RMQDATA++] = make_pair(depth[n], n);       }   }   int main() {     ios::sync_with_stdio(false);     cin >> N >> Q;     for (int i = (1); i < (N + 1); i++) cin >> A[i];     for (int i = (0); i < (N + 1); i++) adj[i].clear();     for (int i = (1); i < (N); i++) {       int a, b;       long long c;       cin >> a >> b >> c;       etox[i][0] = int((adj[a]).size());       etox[i][1] = int((adj[b]).size());       adj[a].push_back(i);       adj[b].push_back(i);       xo[i] = a ^ b;       cost[i] = c;       edgeval[i][0] = a;       edgeval[i][1] = b;     }     for (int i = (1); i < (N + 1); i++)       dp_not[i] = dp_only[i] = vector<long long>(int((adj[i]).size()), -1);     for (int i = (1); i < (N + 1); i++) dp_all[i] = -1;     for (int i = (1); i < (N + 1); i++)       for (auto e : adj[i]) calc_not(i, e);     for (int n = (1); n < (N + 1); n++) {       assert(dp_all[n] != -1);       if (todo[n] != -1) {         int neid = adj[n][todo[n]];         dp_only[n][todo[n]] =             max(0ll, calc_not(xo[neid] ^ n, neid) - cost[neid] * 2ll);         dp_all[n] += dp_only[n][todo[n]];         todo[n] = -1;       }       for (int i = (0); i < (int((adj[i]).size())); i++)         assert(dp_only[n][i] != -1);       for (int i = (0); i < (int((adj[i]).size())); i++)         assert(dp_not[n][i] != -1);     }     parent_edge[1] = -1;     dp_acc[1] = dp_all[1];     depth[1] = 0;     TMP_RMQDATA = 0;     calc_accumulate(1);     vector<pair<int, int> > rmqdata(tmp_rmqdata, tmp_rmqdata + TMP_RMQDATA);     cerr << TMP_RMQDATA << endl;     RMQ<pair<int, int> > rmq(rmqdata, make_pair(N + 1, N + 1));     rmq.init();     for (int q = (0); q < (Q); q++) {       int a, b;       cin >> a >> b;       if (rmqposition[b] < rmqposition[a]) swap(a, b);       int lc = rmq.query(rmqposition[a], rmqposition[b] + 1).second;       assert(lc > 0 && lc <= N);       long long ares = dp_acc[a] + dp_acc[b] - 2 * dp_acc[lc] + dp_all[lc];       cout << ares << endl;     }     return 0;     for (int i = (1); i < (N + 1); i++) {       cout << i <<  : all=  << dp_all[i];       for (auto eid : adj[i]) {         cout <<   (  << i <<  ->  << (xo[eid] ^ i) <<  ):not=  << calc_not(i, eid)              <<   only=  << calc_only(i, eid);       }       cout << endl;     }     for (int i = (1); i < (N + 1); i++) {       cout << i <<   dp=  << dp_acc[i] <<   depth=  << depth[i];       if (parent_edge[i] != -1) cout <<   parent=  << (xo[parent_edge[i]] ^ i);       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dfs(vector<int>* v, int n) {     int cost = -1;     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         if (binary_search(v[i].begin(), v[i].end(), j) == 0) continue;         for (int k = 0; k < v[i].size(); k++) {           for (int s = 0; s < v[j].size(); s++) {             if (v[i][k] == v[j][s]) {               int p = v[i][k];               int ct = v[i].size() + v[j].size() + v[p].size() - 6;               if (cost == -1) {                 cost = ct;               } else {                 cost = min(cost, ct);               }               break;             }           }         }       }     }     return cost;   }   int main() {     int n, m;     cin >> n >> m;     vector<int> v[n + 1];     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     for (int i = 1; i < n + 1; i++) {       sort(v[i].begin(), v[i].end());     }     int cost = dfs(v, n);     cout << cost <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v[100001];   long long arr[100001];   int visit[100001];   void dfs(int s, long long *pos, long long *neg) {     visit[s] = 1;     int i;     long long k, maxi = 0, mini = 0, ps = 0, ng = 0;     for (i = 0; i < v[s].size(); i++) {       if (!visit[v[s][i]]) {         dfs(v[s][i], &ps, &ng);         if (ps > maxi) maxi = ps;         if (ng < mini) mini = ng;       }     }     *pos = maxi;     *neg = mini;     k = arr[s] + maxi + mini;     if (k < 0)       *pos = *pos - k;     else       *neg = *neg - k;   }   int main() {     int n, i, a, b;     long long pos = 0, neg = 0;     scanf( %d , &n);     for (i = 0; i < n - 1; i++) {       scanf( %d%d , &a, &b);       v[a].push_back(b);       v[b].push_back(a);     }     for (i = 1; i <= n; i++) cin >> arr[i];     dfs(1, &pos, &neg);     cout << pos - neg;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   struct Sync_stdio {     Sync_stdio() {       cin.tie(NULL);       ios_base::sync_with_stdio(false);     }   } _sync_stdio;   long long n, k;   void solve(vector<long long> &v, vector<long long> &a) {     for (int i = (0); i < (n); ++i) {       a[i + 1] += a[i] / 2;       a[i] %= 2;       if (a[i] == -1) {         --a[i + 1];         a[i] = 1;       }     }     if (a[n] < 0) {       return;     }     long long pos = 0;     for (int i = (0); i < (n + 1); ++i) {       if (a[i] != 0) {         pos = i;         break;       }     }     long long res = 0;     long double res2 = 0;     for (int i = (pos); i < (min(n + 1, pos + 36)); ++i) {       res += (1LL << (i - pos)) * a[i];       res2 += (1LL << (i - pos)) * a[i];     }     for (int i = (min(n + 1, pos + 35)); i < (n + 1); ++i) {       if (a[i] != 0) {         cout << 0 <<   n ;         exit(0);       }     }     if (res2 > 1e11) {       cout << 0;       exit(0);     }     long long ans = 0;     long long t = res;     for (int i = (pos); i > (-1); --i) {       if (t > 1e12) {         break;       }       if (pos != n || t != v[i]) {         if (t <= v[i] + k) {           ++ans;         }       }       t *= 2;     }     cout << ans;     exit(0);   }   int main() {     cin >> n >> k;     vector<long long> v(n + 1);     for (int __i = 0; __i < (n + 1); ++__i) cin >> v[__i];     ;     vector<long long> a = v;     solve(v, a);     a = v;     for (int i = (0); i < (n + 1); ++i) {       v[i] = -v[i];       a[i] = -a[i];     }     solve(v, a);   }


#include <bits/stdc++.h>   using namespace std;   class solve {    private:     int n, lar, les;     vector<int> val[2];     vector<int> res[2];     vector<long long> sum[2];       private:     int find_first_less(int i);       public:     void func();   };   void solve::func() {     cin >> n;     val[0].resize(n + 1, 0);     val[1].resize(n + 1, 0);     sum[0].resize(n + 1, 0);     sum[1].resize(n + 1, 0);     for (int k = 0; k < 2; k++)       for (int i = 1; i <= n; i++) {         scanf( %d , &val[k][i]);         sum[k][i] = sum[k][i - 1] + val[k][i];       }     if (sum[0][n] >= sum[1][n])       lar = 0;     else       lar = 1;     les = 1 - lar;     map<long long, pair<int, int> > diff_pair;     diff_pair[0] = make_pair(0, 0);     for (int i = 1; i <= n; i++) {       int l = 0, r = n, m;       while (l < r) {         m = (l + r + 1) / 2;         if (sum[les][i] >= sum[lar][m])           l = m;         else           r = m - 1;       }       long long diff = sum[les][i] - sum[lar][l];       if (diff_pair.count(diff) != 0) {         for (int j = diff_pair[diff].first + 1; j <= i; j++)           res[les].push_back(j);         for (int j = diff_pair[diff].second + 1; j <= l; j++)           res[lar].push_back(j);         break;       } else         diff_pair[diff] = make_pair(i, l);     }     printf( %d n , (int)res[0].size());     for (int i = 0; i < res[0].size(); i++) printf( %d  , res[0][i]);     printf(  n );     printf( %d n , (int)res[1].size());     for (int i = 0; i < res[1].size(); i++) printf( %d  , res[1][i]);     printf(  n );   }   int main() {     solve s;     s.func();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long P = 1000000007;   long long MOD(long long x) { return (x % P + P) % P; }   long long Time(long long x, long long y) {     if (x < 0) {       x = MOD(x);     }     long long ans = 1;     while (y) {       if (y & 1) {         ans = ans * x % P;       }       x = x * x % P;       y >>= 1;     }     return ans % P;   }   int main() {     long long T;     scanf( %lld , &T);     while (T--) {       long long n, m, xa, ya, xb, yb, pro;       scanf( %lld%lld%lld%lld%lld%lld%lld , &n, &m, &xa, &ya, &xb, &yb, &pro);       pro = pro * Time(100, P - 2) % P;       long long sum = 0, cnt = 0;       long long dx = 1, dy = 1;       long long x = xa, y = ya;       long long tx = x + dx, ty = y + dy;       if (tx > n || tx <= 0) {         dx *= -1;       }       if (ty > m || ty <= 0) {         dy *= -1;       }       tx = x + dx;       ty = y + dy;       long long xx = tx, yy = ty;       bool z = 0;       while (1) {         if (!z || x != xa || y != ya) {           tx = x + dx;           ty = y + dy;           if (tx > n || tx <= 0) {             dx *= -1;           }           if (ty > m || ty <= 0) {             dy *= -1;           }           tx = x + dx;           ty = y + dy;           if (tx == xx && ty == yy && z && x == xa && y == ya) {             break;           }           if (x == xb || y == yb) {             cnt++;           }           z = 1;           tx = x + dx;           ty = y + dy;           if (tx > n || tx <= 0) {             dx *= -1;           }           if (ty > m || ty <= 0) {             dy *= -1;           }           tx = x + dx;           ty = y + dy;           x = tx;           y = ty;           sum++;         } else {           tx = x + dx;           ty = y + dy;           if (tx > n || tx <= 0) {             dx *= -1;           }           if (ty > m || ty <= 0) {             dy *= -1;           }           tx = x + dx;           ty = y + dy;           if (tx == xx && ty == yy && z && x == xa && y == ya) {             break;           }           if (x == xb || y == yb) {             cnt++;           }           z = 1;           tx = x + dx;           ty = y + dy;           if (tx > n || tx <= 0) {             dx *= -1;           }           if (ty > m || ty <= 0) {             dy *= -1;           }           tx = x + dx;           ty = y + dy;           x = tx;           y = ty;           sum++;         }       }       long long ans = 0;       dx = 1;       dy = 1;       x = xa;       y = ya;       z = 0;       long long t = 0;       long long cnt2 = 0;       while (1) {         if (!z || x != xa || y != ya) {           tx = x + dx;           ty = y + dy;           if (tx > n || tx <= 0) {             dx *= -1;           }           if (ty > m || ty <= 0) {             dy *= -1;           }           tx = x + dx;           ty = y + dy;           if (tx == xx && ty == yy && z && x == xa && y == ya) {             break;           }           if (x == xb || y == yb) {             long long a = t * Time(1 - pro, cnt2) % P * pro % P;             long long b = sum * Time(1 - pro, cnt2 + cnt) % P * pro % P;             long long c = MOD(1 - Time(1 - pro, cnt));             ans = MOD(ans + (a + b * Time(c, P - 2)) % P * Time(c, P - 2) % P);             cnt2++;           }           z = 1;           tx = x + dx;           ty = y + dy;           if (tx > n || tx <= 0) {             dx *= -1;           }           if (ty > m || ty <= 0) {             dy *= -1;           }           tx = x + dx;           ty = y + dy;           x = tx;           y = ty;           t++;         } else {           tx = x + dx;           ty = y + dy;           if (tx > n || tx <= 0) {             dx *= -1;           }           if (ty > m || ty <= 0) {             dy *= -1;           }           tx = x + dx;           ty = y + dy;           if (tx == xx && ty == yy && z && x == xa && y == ya) {             break;           }           if (x == xb || y == yb) {             long long a = t * Time(1 - pro, cnt2) % P * pro % P;             long long b = sum * Time(1 - pro, cnt2 + cnt) % P * pro % P;             long long c = MOD(1 - Time(1 - pro, cnt));             ans = MOD(ans + (a + b * Time(c, P - 2)) % P * Time(c, P - 2) % P);             cnt2++;           }           z = 1;           tx = x + dx;           ty = y + dy;           if (tx > n || tx <= 0) {             dx *= -1;           }           if (ty > m || ty <= 0) {             dy *= -1;           }           tx = x + dx;           ty = y + dy;           x = tx;           y = ty;           t++;         }       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100010;   const int INF = 0x7fffffff;   long long a[MAXN];   long long sum = 0;   long long s1[MAXN];   set<long long> s;   int main() {     int n;     scanf( %d , &n);     s1[0] = 0;     for (int i = 1; i <= n; i++) {       scanf( %lld , a + i);       sum += a[i];       s1[i] = s1[i - 1] + a[i];     }     int ok = 0;     s.clear();     for (int i = 1; i <= n; i++) {       if (s.count(2 * a[i])) {         ok = 1;         break;       }       long long x = sum - 2 * s1[i];       if (x == 0) {         ok = 1;         break;       }       if (x >= 0) s.insert(x);     }     s.clear();     for (int i = n; i >= 1; i--) {       if (s.count(2 * a[i])) {         ok = 1;         break;       }       long long x = 2 * s1[i] - sum;       if (x == 0) {         ok = 1;         break;       }       if (x >= 0) s.insert(x);     }     if (ok)       puts( YES );     else       puts( NO );   }


#include <bits/stdc++.h>   using namespace std;   int n = 10;   const int ms = 100;   int grid[ms][ms];   const int inf = 1e9;   int f[ms];   double dp[ms];   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout << fixed << setprecision(8);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> grid[i][j];       }       i++;       for (int j = n - 1; j >= 0; j--) {         cin >> grid[i][j];       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (grid[i][j] % 2 == 0) {           f[i * 10 + j] = i * 10 + j - grid[i][j] * 10;         } else {           f[i * 10 + j] = i * 10 + (n - j - 1) - grid[i][j] * 10;         }       }       i++;       for (int j = n - 1; j >= 0; j--) {         if (grid[i][j] % 2 == 0) {           f[i * 10 + j] = i * 10 + j - grid[i][j] * 10;         } else {           f[i * 10 + j] = i * 10 + (n - j - 1) - grid[i][j] * 10;         }       }     }     dp[0] = 0.0;     for (int i = 1; i < ms; i++) {       double sum = 1;       double tam = min(i, 6);       for (int d = 1; d <= tam; d++) {         sum += 1.0 / 6.0 * min(dp[i - d], dp[f[i - d]]);       }       dp[i] = (6.0 / tam) * sum;     }     cout << dp[99] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   void run(vector<vector<int>> &sets, int **sum);   pair<vector<vector<int>>, int **> precalc();   const int MAXB = 5;   const int MOD = 1e9 + 7;   int main() {     ios::sync_with_stdio(false);     cout.tie(0);     auto precalc_vals = precalc();     run(precalc_vals.first, precalc_vals.second);   }   template <typename type>   type *farray(int n) {     return (type *)malloc(n * sizeof(type));   }   template <typename type>   type *farray(int n, type val) {     auto res = farray<type>(n);     fill(res, res + n, val);     return res;   }   template <typename type>   type **dim2_farray(int n, int m) {     auto res = farray<type *>(n);     for (int i = 0; i < n; i++) {       res[i] = farray<type>(m);     }     return res;   }   template <typename type>   type **dim2_farray(int n, int m, type val) {     auto res = farray<type *>(n);     for (int i = 0; i < n; i++) {       res[i] = farray<type>(m, val);     }     return res;   }   template <typename type>   void dim2_free(type *arr, int n) {     for (int i = 0; i < n; i++) free(arr[i]);     free(arr);   }   bool gauss(bool **matrix, bool *vec, int n, int m) {     if (m > n) return false;     for (int k = 0; k < m; k++) {       int st = k;       for (; st < n && matrix[st][k] == 0; st++)         ;       if (st == n) return false;       for (int c = 0; c < m; c++) {         swap(matrix[st][c], matrix[k][c]);       }       swap(vec[st], vec[k]);       for (int r = st + 1; r < n; r++) {         if (matrix[r][k] == 0) continue;         for (int c = k; c < m; c++) {           matrix[r][c] -= matrix[k][c];         }         vec[r] -= vec[k];       }     }     for (int k = m - 1; k >= 0; k--) {       for (int r = k - 1; r >= 0; r--) {         if (matrix[r][k] == 0) continue;         matrix[r][k] -= 1;         vec[r] -= vec[k];       }     }     for (int k = m; k < n; k++) {       bool val = 0;       for (int c = 0; c < m; c++) {         val += matrix[k][c] * vec[c];       }       if (val != vec[k]) return false;     }     return true;   }   bool **to_matrix(const vector<int> &a) {     int len = (int)a.size();     auto matrix = dim2_farray<bool>(MAXB, len);     for (int i = 0; i < len; i++) {       for (int b = 0; b < MAXB; b++) {         matrix[b][i] = (a[i] & (1 << b)) > 0;       }     }     return matrix;   }   bool indep(const vector<int> &a) {     int len = (int)a.size();     auto matrix = to_matrix(a);     auto vec = farray<bool>(MAXB, 0);     return gauss(matrix, vec, MAXB, len);   }   bool *bin(int a) {     auto res = farray<bool>(MAXB);     for (int i = 0; i < MAXB; i++) {       res[i] = a & (1 << i);     }     return res;   }   bool the_same(const vector<int> &a, const vector<int> &b) {     if (a.size() != b.size()) return false;     int len = b.size();     for (int i = 0; i < len; i++) {       auto a_matrix = to_matrix(a);       if (!gauss(a_matrix, bin(b[i]), MAXB, len)) {         dim2_free(a_matrix, MAXB);         return false;       }       dim2_free(a_matrix, MAXB);     }     return true;   }   void precalc_sets(int from, vector<vector<int>> &ans, vector<int> &cur,                     int k = 0) {     cur.push_back(0);     for (int i = from; i < (1 << MAXB); i++) {       cur.back() = i;       if (indep(cur)) {         bool new_one = true;         for (auto &v : ans) {           if (the_same(cur, v)) {             new_one = false;             break;           }         }         if (new_one) {           ans.push_back(cur);           precalc_sets(i + 1, ans, cur, k + 1);         }       }     }     cur.pop_back();   }   int set_id(vector<int> &basis, vector<vector<int>> &sets) {     for (int i = 0; i < (int)sets.size(); i++) {       if (the_same(basis, sets[i])) {         return i;       }     }     return -1;   }   int **precalc_sums(vector<vector<int>> &sets) {     int n = (int)sets.size();     auto res = dim2_farray<int>(n, n);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         vector<int> cur = sets[i];         cur.insert(cur.end(), sets[j].begin(), sets[j].end());         if (indep(cur)) {           res[i][j] = set_id(cur, sets);         } else {           res[i][j] = -1;         }       }     }     return res;   }   pair<vector<vector<int>>, int **> precalc() {     vector<vector<int>> sets(1);     vector<int> cur;     precalc_sets(0, sets, cur);     auto sums = precalc_sums(sets);     return {sets, sums};   }   struct Graph {     int *head, *nxt, *eto, *cost, eto_ptr = 0;     Graph(int n, int m) {       head = farray<int>(n, -1);       nxt = farray<int>(m);       eto = farray<int>(m);       cost = farray<int>(m);     }     void add_edge(int from, int to, int c) {       eto[eto_ptr++] = to;       nxt[eto_ptr - 1] = head[from];       head[from] = eto_ptr - 1;       cost[eto_ptr - 1] = c;     }   };   void get_basis(int v, Graph &graph, vector<bool> &used, int *path_xor,                  vector<int> &basis, int p = -1) {     used[v] = true;     for (int e = graph.head[v]; e != -1; e = graph.nxt[e]) {       int u = graph.eto[e];       if (u == p || u == 1) continue;       if (!used[u]) {         path_xor[u] = path_xor[v] ^ graph.cost[e];         get_basis(u, graph, used, path_xor, basis, v);       } else if (u < v) {         basis.push_back(path_xor[v] ^ path_xor[u] ^ graph.cost[e]);       }     }   }   void run(vector<vector<int>> &sets, int **sums) {     int n, m;     cin >> n >> m;     Graph graph(n + 1, m * 2);     for (int i = 0; i < m; i++) {       int u, v, c;       cin >> u >> v >> c;       graph.add_edge(u, v, c);       graph.add_edge(v, u, c);     }     auto near_one = farray<int>(n + 1, -1);     for (int e = graph.head[1]; e != -1; e = graph.nxt[e]) {       int u = graph.eto[e];       near_one[u] = graph.cost[e];     }     vector<bool> used(n + 1);     used[1] = true;     vector<vector<int>> dims = {{}};     auto path_xor = farray<int>(n + 1, 0);     for (int v = 2; v <= n; v++) {       if (used[v] || near_one[v] == -1) continue;       int u = -1, c = -1;       for (int e2 = graph.head[v]; e2 != -1; e2 = graph.nxt[e2]) {         u = graph.eto[e2];         c = graph.cost[e2];         if (near_one[u] != -1) {           break;         }         u = -1;       }       vector<int> basis;       get_basis(v, graph, used, path_xor, basis);       if (!indep(basis)) continue;       dims.push_back({set_id(basis, sets)});       if (u != -1) {         dims.back().push_back(dims.back().back());         basis.push_back(near_one[v] ^ near_one[u] ^ c);         if (indep(basis)) {           dims.back().push_back(set_id(basis, sets));         }       }     }     int p = sets.size();     int k = dims.size();     auto dp = dim2_farray<int>(k, p, 0);     dp[0][0] = 1;     for (int i = 1; i < k; i++) {       for (int d = 0; d < p; d++) {         dp[i][d] = dp[i - 1][d];       }       for (int d = 0; d < p; d++) {         for (int a : dims[i]) {           if (sums[d][a] == -1) continue;           int new_dim = sums[d][a];           dp[i][new_dim] = (dp[i][new_dim] + dp[i - 1][d]) % MOD;         }       }     }     int ans = 0;     for (int i = 0; i < p; i++) {       ans = (ans + dp[k - 1][i]) % MOD;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct T {     int p, n;   };   bool operator<(T x, T y) { return x.p < y.p; }   T m[100100];   int main() {     int i, n, j;     for (scanf( %d , &n), i = 0; i < n; scanf( %d%d , &m[i].p, &m[i].n), i++)       ;     sort(m, m + n);     j = m[n - 1].n;     for (i = 0; i < n - 1; i++)       if (m[i + 1].p - m[i].p > 40)         continue;       else {         for (; m[i].p < m[i + 1].p; m[i].n = (m[i].n + 3) / 4, m[i].p++)           ;         if (m[i].n > m[i + 1].n) m[i + 1].n = m[i].n;       }     if (m[n - 1].n == j && j == 1)       printf( %d n , m[n - 1].p + 1);     else {       for (; m[i].n > 1; m[i].n = (m[i].n + 3) / 4, m[i].p++)         ;       printf( %d n , m[i].p);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0;     int ch = getchar(), f = 1;     while (!isdigit(ch) && (ch !=  - ) && (ch != EOF)) ch = getchar();     if (ch ==  - ) {       f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return x * f;   }   const int N = 5e5 + 10, mod = 1e9 + 7;   int n, ans;   pair<int, int> a[N];   inline int Mod(int x) { return x >= mod ? x - mod : x; }   inline void upd(int &x, int y) {     x += y, x = (x >= mod ? x - mod : (x < 0 ? x + mod : x));   }   struct SegmentTree {     int v[N << 2], lazy[N << 2];     inline void push_up(int u) { v[u] = Mod(v[u << 1] + v[u << 1 ^ 1]); }     inline void push_down(int u, int l, int mid, int r) {       if (!lazy[u]) return;       upd(lazy[u << 1], lazy[u]), upd(lazy[u << 1 ^ 1], lazy[u]);       upd(v[u << 1], 1ll * lazy[u] * (mid - l + 1) % mod),           upd(v[u << 1 ^ 1], 1ll * lazy[u] * (r - mid) % mod);       lazy[u] = 0;     }     inline void update(int u, int l, int r, int ql, int qr) {       if (l >= ql && r <= qr)         return upd(v[u], r - l + 1), upd(lazy[u], 1), void(0);       int mid = l + r >> 1;       push_down(u, l, mid, r);       if (qr <= mid)         update(u << 1, l, mid, ql, qr);       else if (ql > mid)         update(u << 1 ^ 1, mid + 1, r, ql, qr);       else         update(u << 1, l, mid, ql, qr), update(u << 1 ^ 1, mid + 1, r, ql, qr);       push_up(u);     }     inline int Query(int u, int l, int r, int ql, int qr) {       if (l >= ql && r <= qr) return v[u];       int mid = l + r >> 1;       push_down(u, l, mid, r);       if (qr <= mid)         return Query(u << 1, l, mid, ql, qr);       else if (ql > mid)         return Query(u << 1 ^ 1, mid + 1, r, ql, qr);       else         return Mod(Query(u << 1, l, mid, ql, qr) +                    Query(u << 1 ^ 1, mid + 1, r, ql, qr));     }   } t[2];   int main() {     n = read();     for (register int i = (1); i <= (n); i++) a[i] = make_pair(read(), i);     sort(a + 1, a + 1 + n);     for (register int i = (1); i <= (n); i++) {       int x = t[0].Query(1, 1, n, a[i].second, a[i].second),           sum = t[0].Query(1, 1, n, 1, a[i].second);       int y = t[1].Query(1, 1, n, a[i].second, a[i].second),           Sum = t[1].Query(1, 1, n, a[i].second, n);       upd(ans, 1ll * a[i].first *                    (sum - 1ll * x * a[i].second % mod + a[i].second) % mod *                    (n - a[i].second + 1) % mod);       upd(ans, 1ll * a[i].first * (Sum - 1ll * y * (n - a[i].second + 1) % mod) %                    mod * a[i].second % mod);       t[0].update(1, 1, n, 1, a[i].second), t[1].update(1, 1, n, a[i].second, n);     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<long long int, long long int> > v1, v2;   int main() {     long long int p, q, l, r, w, x, y, z, i, j, flag, tot = 0, k;     scanf( %lld , &p);     scanf( %lld , &q);     scanf( %lld , &l);     scanf( %lld , &r);     for (i = 0; i < p; i++) {       scanf( %lld , &x);       scanf( %lld , &y);       v1.push_back(make_pair(x, y));     }     for (i = 0; i < q; i++) {       scanf( %lld , &x);       scanf( %lld , &y);       v2.push_back(make_pair(x, y));     }     for (i = l; i <= r; i++) {       flag = 0;       for (j = 0; j < v1.size(); j++) {         for (k = 0; k < v2.size(); k++) {           if (v1[j].second < v2[k].first + i || v1[j].first > v2[k].second + i)             ;           else             flag = 1;         }       }       if (flag == 1) tot++;     }     cout << tot << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     int i, j, p;     char a[100010];     while (~scanf( %s , a)) {       p = 0;       for (i = 0, j = strlen(a) - 1; i < j; i++, j--) {         if (a[i] != a[j]) {           p = 1;           break;         }       }       if (p == 1)         printf( NO n );       else {         for (i = 0; i < strlen(a); i++) {           if (a[i] !=  A  && a[i] !=  H  && a[i] !=  I  && a[i] !=  M  &&               a[i] !=  O  && a[i] !=  T  && a[i] !=  V  && a[i] !=  U  &&               a[i] !=  W  && a[i] !=  X  && a[i] !=  Y ) {             p = 1;             break;           }         }         if (p == 1)           printf( NO n );         else           printf( YES n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     string x;     int ans = 1;     vector<string> a;     for (int i = 0; i < n; i++) {       cin >> x;       a.push_back(x);     }     for (int i = 0; i < n - 1; ++i) {       if (a[i] != a[i + 1]) ans++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> a;   int n;   bool check() {     for (int i = 1; i < n; i++) {       if (abs(a[i - 1] - a[i]) >= 2) return 1;     }     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     a.resize(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     if (check()) {       cout <<  NO ;       return 0;     }     int last = -1;     for (int i = 0; i < n; i++) {       int mx = -1, mxj = 0;       for (int j = 0; j < n; j++) {         if (mx < a[j]) {           mx = a[j];           mxj = j;         }       }       if (last == -1) last = mx;       if (mx == -1) break;       if (abs(last - mx) >= 2) {         cout <<  NO ;         return 0;       }       a[mxj] = -1;       last = mx;     }     cout <<  YES ;   }


#include <bits/stdc++.h>   const int maxn = 2e5 + 1;   int fa[maxn], flg[maxn], n, m, cnt, ans;   struct Edge {     int u, v, w;   } e[maxn];   inline bool cmp(Edge a, Edge b) { return a.w > b.w; }   inline int find(int x) { return (fa[x] == x) ? x : fa[x] = find(fa[x]); }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) scanf( %d %d %d , &e[i].u, &e[i].v, &e[i].w);     for (int i = 1; i <= n; i++) fa[i] = i;     std::sort(e + 1, e + m + 1, cmp);     for (int i = 1; i <= m; i++) {       int fx = find(e[i].u), fy = find(e[i].v);       if (fx == fy) {         if (flg[fx]) continue;         ans += e[i].w;         flg[fx] = 1;       }       if (flg[fx] && flg[fy]) continue;       if (flg[fx])         fa[fy] = fx;       else if (flg[fy])         fa[fx] = fy;       else         fa[fx] = fy;       ans += e[i].w;     }     printf( %d , ans);   }


#include <bits/stdc++.h>   using namespace std;   int read() {     char c;     int w = 1;     while ((c = getchar()) >  9  || c <  0 )       if (c ==  - ) w = -1;     int ans = c -  0 ;     while ((c = getchar()) >=  0  && c <=  9 )       ans = (ans << 1) + (ans << 3) + c -  0 ;     return ans * w;   }   const int xx = 2.4e5 + 5;   vector<int> v[xx];   int n, mn[xx << 2], ad[xx << 2], a[xx];   void add(int x, int y) { mn[x] += y, ad[x] += y; }   void pd(int k) {     if (!ad[k]) return;     add(k << 1, ad[k]);     add(k << 1 | 1, ad[k]);     ad[k] = 0;   }   int ask(int k, int l, int r) {     if (l == r) return l;     pd(k);     int mid = l + r >> 1;     if (mn[k] == mn[k << 1 | 1]) return ask(k << 1 | 1, mid + 1, r);     return ask(k << 1, l, mid);   }   void ch(int k, int l, int r, int x, int y) {     if (l == r) return mn[k] = y, void();     pd(k);     int mid = l + r >> 1;     if (x <= mid)       ch(k << 1, l, mid, x, y);     else       ch(k << 1 | 1, mid + 1, r, x, y);     mn[k] = min(mn[k << 1], mn[k << 1 | 1]);   }   void ch(int k, int l, int r, int x, int y, int z) {     if (x > y) return;     if (x <= l && r <= y) return add(k, z);     pd(k);     int mid = l + r >> 1;     if (x <= mid) ch(k << 1, l, mid, x, y, z);     if (mid < y) ch(k << 1 | 1, mid + 1, r, x, y, z);     mn[k] = min(mn[k << 1], mn[k << 1 | 1]);   }   struct pr {     int x, y;     pr() {}     pr(int a, int b) : x(a), y(b) {}   };   pr s1[xx], s2[xx];   int L[xx], R[xx], s3[xx], vis[xx], t1, t2, t3;   int f[xx][20], dep[xx], LL[xx], RR[xx], lg[xx];   long long r[xx], l[xx];   long long sum[xx], val[xx];   long long rf[xx][20], lf[xx][20], S[xx];   long long get(long long x) { return x * (x - 1) / 2; }   int id[xx];   void dfs(int x, int y) {     if (x <= n)       LL[x] = x, RR[x] = x;     else       LL[x] = 1e9, RR[x] = -1e9;     val[x] = 1;     if (!vis[x] && x > n) val[x] += get(v[x].size()) - 1;     f[x][0] = y;     dep[x] = dep[y] + 1;     for (int i = 1; i < 20; i++) f[x][i] = f[f[x][i - 1]][i - 1];     for (int i = 0; i < v[x].size(); i++)       dfs(v[x][i], x), LL[x] = min(LL[x], LL[v[x][i]]),                        RR[x] = max(RR[x], RR[v[x][i]]), sum[x] += sum[v[x][i]];     sum[x] += val[x];     for (int i = 0; i < v[x].size(); i++) l[i] = r[i] = 0;     for (int i = 0; i < v[x].size(); i++) {       id[v[x][i]] = i;       if (i)         l[i] = l[i - 1], l[i] += sum[v[x][i - 1]], S[v[x][i]] = S[v[x][i - 1]];       S[v[x][i]] += sum[v[x][i]];       if (!vis[x]) l[i] += get(i);       lf[v[x][i]][0] = l[i];       if (!vis[x]) l[i] -= get(i);     }     for (int i = v[x].size() - 1; i >= 0; i--) {       if (i != v[x].size() - 1) r[i] = r[i + 1], r[i] += sum[v[x][i + 1]];       if (!vis[x]) r[i] += get(v[x].size() - 1 - i);       rf[v[x][i]][0] = r[i];       if (!vis[x]) r[i] -= get(v[x].size() - 1 - i);     }   }   pr lca(int x, int y) {     if (dep[x] < dep[y]) swap(x, y);     while (dep[x] != dep[y]) x = f[x][lg[dep[x] - dep[y]]];     for (int i = lg[x]; i >= 0; i--)       (f[x][i] ^ f[y][i]) ? (x = f[x][i], y = f[y][i]) : 0;     return pr(x, y);   }   int main() {     lg[0] = -1;     for (int i = 1; i < xx; i++) lg[i] = lg[i - 1] + (i == (i & -i));     memset(mn, 0x3f, sizeof(mn));     n = read();     for (int i = 1; i <= n; i++) a[i] = read();     for (int i = 1; i <= n; i++) L[i] = R[i] = a[i];     int cst = n;     for (int i = 1; i <= n; i++) {       int now = i;       int last = t3 + 1;       while (t1 && s1[t1].x < a[i])         ch(1, 1, n, s1[t1].y, last - 1, -s1[t1].x), last = s1[t1--].y;       ch(1, 1, n, last, t3, a[i]);       s1[++t1] = pr(a[i], last);       last = t3 + 1;       while (t2 && s2[t2].x > a[i])         ch(1, 1, n, s2[t2].y, last - 1, s2[t2].x), last = s2[t2--].y;       ch(1, 1, n, last, t3, -a[i]);       s2[++t2] = pr(a[i], last);       while (mn[1] == i) {         int id = ask(1, 1, n), p = s3[id];         if (id == t3 && !vis[p] && v[p].size() &&             ((R[*--v[p].end()] == R[p] && R[p] + 1 == L[now]) ||              (L[*--v[p].end()] == L[p] && L[p] - 1 == R[now]))) {           v[p].push_back(now);           L[p] = min(L[p], L[now]);           R[p] = max(R[p], R[now]);           now = p;           ch(1, 1, n, t3, 1e9);           t3--;         } else {           p = ++cst;           L[p] = L[now];           R[p] = R[now];           for (int i = id; i <= t3; i++) {             v[p].push_back(s3[i]);             L[p] = min(L[p], L[s3[i]]);             R[p] = max(R[p], R[s3[i]]);             ch(1, 1, n, i, 1e9);           }           v[p].push_back(now);           now = p;           if (t3 - id + 1 > 2) vis[p] = 1;           t3 = id - 1;         }       }       s3[++t3] = now;       while (t1 && s1[t1].y > t3) t1--;       while (t2 && s2[t2].y > t3) t2--;       ch(1, 1, n, t3, i);     }     dfs(s3[1], 0);     for (int j = 1; j < 20; j++)       for (int i = 1; i <= cst; i++) {         lf[i][j] = lf[i][j - 1] + lf[f[i][j - 1]][j - 1];         rf[i][j] = rf[i][j - 1] + rf[f[i][j - 1]][j - 1];       }     int m = read();     while (m--) {       int l, r;       l = read();       r = read();       if (l == r)         cout << 1 <<   n ;       else {         pr p = lca(l, r);         if (LL[p.x] > LL[p.y]) swap(p.x, p.y);         long long x = l, y = r;         for (int j = 20; j >= 0; j--)           if (f[x][j] && f[x][j] != s3[1] && LL[f[x][j]] == l) x = f[x][j];         for (int j = 20; j >= 0; j--)           if (f[y][j] && f[y][j] != s3[1] && RR[f[y][j]] == r) y = f[y][j];         long long res = 0, num = 0;         if (dep[x] <= dep[p.x])           res += sum[p.x], num++;         else {           res += sum[x];           if (!vis[f[x][0]]) res += v[f[x][0]].size() - 1 - id[x];           while (dep[x] != dep[p.x])             res += rf[x][lg[dep[x] - dep[p.x]]], x = f[x][lg[dep[x] - dep[p.x]]];         }         if (dep[y] <= dep[p.y])           res += sum[p.y], num++;         else {           res += sum[y];           if (!vis[f[y][0]]) res += id[y];           while (dep[y] != dep[p.y])             res += lf[y][lg[dep[y] - dep[p.y]]], y = f[y][lg[dep[y] - dep[p.y]]];         }         if (!vis[f[p.x][0]])           num += id[p.y] - id[p.x] - 1, res += get(num);         else if (LL[f[p.x][0]] == l && RR[f[p.x][0]] == r)           res++;         res += S[p.y] - S[p.x] - sum[p.y];         cout << res <<   n ;       }     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 100005, M = 200005, L = 20;   const int INF = 1 << 30;   struct node {     int u, v, nxt;   } edge[M];   int head[N], mcnt;   void add_edge(int u, int v) {     mcnt++;     edge[mcnt].u = u;     edge[mcnt].v = v;     edge[mcnt].nxt = head[u];     head[u] = mcnt;   }   vector<int> G[N];   int dfn[N], tot;   int deep[N];   int pa[N][L + 1];   bool Chosen[N];   int OnVtree[N], cnt;   int S[N], top;   int n, m, k;   int d[N][2];   void dfs(int u, int fa) {     dfn[u] = ++tot;     deep[u] = deep[fa] + 1;     for (int i = head[u]; i; i = edge[i].nxt) {       int v = edge[i].v;       if (v == fa) continue;       pa[v][0] = u;       dfs(v, u);     }   }   void Init() {     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       add_edge(u, v);       add_edge(v, u);     }     dfs(1, 0);     for (int j = 1; j <= L; j++)       for (int i = 1; i <= n; i++) pa[i][j] = pa[pa[i][j - 1]][j - 1];   }   int LCA(int x, int y) {     if (deep[x] < deep[y]) swap(x, y);     for (int j = L; j >= 0; j--)       if (deep[pa[x][j]] >= deep[y]) x = pa[x][j];     if (x == y) return x;     for (int j = L; j >= 0; j--)       if (pa[x][j] != pa[y][j]) x = pa[x][j], y = pa[y][j];     return pa[x][0];   }   struct mode {     int u, dfn;   } p[N];   bool cmp(mode a, mode b) { return a.dfn < b.dfn; }   void add_tree(int u, int v) {     G[u].push_back(v);     G[v].push_back(u);   }   void Get_vtree() {     sort(p + 1, p + k + 1, cmp);     top = 0;     S[++top] = p[1].u;     for (int i = 2; i <= k; i++) {       int u = p[i].u, v = S[top];       int lca = LCA(u, v);       if (v == lca)         S[++top] = u;       else {         int ntop = top;         while (ntop > 0 && deep[S[ntop]] > deep[lca]) ntop--;         for (int j = ntop + 1; j + 1 <= top; j++) {           add_tree(S[j], S[j + 1]);         }         long long pos = S[ntop + 1];         if (ntop < top) {           add_tree(pos, lca);         }         top = ntop;         if (S[top] != lca) {           OnVtree[++cnt] = lca;           S[++top] = lca;         }         S[++top] = u;       }     }     for (int j = 1; j + 1 <= top; j++) add_tree(S[j], S[j + 1]);   }   void DP(int u, int fa) {     d[u][0] = 1, d[u][1] = 0;     if (Chosen[u]) {       for (int i = 0, sz = G[u].size(); i < sz; i++) {         int v = G[u][i];         if (v == fa) continue;         DP(v, u);         d[u][1] += d[v][0];         d[u][0] += d[v][0];       }     } else {       int mx = INF;       int sum = 0;       for (int i = 0, sz = G[u].size(); i < sz; i++) {         int v = G[u][i];         if (v == fa) continue;         DP(v, u);         d[u][0] += min(d[v][0], d[v][1]);         sum += d[v][0];         d[u][1] += d[v][0];         mx = min(mx, d[v][1] - d[v][0]);       }       d[u][0] = min(d[u][0], sum);       d[u][1] += mx;     }   }   bool check() {     for (int i = 1; i <= k; i++) {       int u = OnVtree[i];       for (int i = head[u]; i; i = edge[i].nxt) {         int v = edge[i].v;         if (Chosen[v]) return true;       }     }     return false;   }   void Solve() {     scanf( %d , &k);     cnt = k;     for (int i = 1; i <= k; i++) {       int u;       scanf( %d , &u);       Chosen[u] = 1;       OnVtree[i] = u;       p[i].u = u;       p[i].dfn = dfn[u];     }     if (check()) {       for (int i = 1; i <= cnt; i++) {         int u = OnVtree[i];         Chosen[u] = 0;       }       puts( -1 );       return;     }     Get_vtree();     DP(S[1], 0);     int ans = min(d[S[1]][0], d[S[1]][1]);     printf( %d n , ans);     for (int i = 1; i <= cnt; i++) {       int u = OnVtree[i];       G[u].clear();       Chosen[u] = 0;     }   }   int main() {     scanf( %d , &n);     Init();     scanf( %d , &m);     while (m--) {       Solve();     }   }


#include <bits/stdc++.h>   using namespace std;   bool prime[101];   void SieveOfEratosthenes(int n) {     memset(prime, true, sizeof(prime));     for (int p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (int i = p * p; i <= n; i += p) prime[i] = false;       }     }   }   int main() {     long long n, m;     cin >> n;     long long c[n + 1];     if (n % 2 != 0) {       cout << -1;       return 0;     }     for (long long i = 1; i <= n; i++) {       c[i] = i;     }     for (long long i = 1; i <= n; i += 2) {       swap(c[i], c[i + 1]);     }     for (long long i = 1; i <= n; i++) {       cout << c[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2000010;   inline int in() {     int x;     scanf( %d , &x);     return x;   }   inline long long lin() {     long long x;     scanf( %I64d , &x);     return x;   }   char s[N];   int t[4 * N];   int help[N * 4];   int limit = (int)1e6 * 2;   int ki[N];   vector<int> V[N];   vector<string> Store;   void modify(int x, int b, int e, int l, int r, int v) {     if (help[x]) return;     if (b > r || e < l) return;     if (b >= l && e <= r) {       help[x] = 1;       t[x] = v;       return;     }     int m = (b + e) >> 1;     modify(x + x, b, m, l, r, v);     modify(x + x + 1, m + 1, e, l, r, v);     help[x] = help[x + x] & help[x + x + 1];   }   int get(int x, int b, int e, int l, int r) {     if (t[x] > 0 && (b != e)) {       t[x + x] = t[x];       t[x + x + 1] = t[x];     }     if (b > r || e < l) return 0;     if (b >= l && e <= r) {       return t[x];     }     int m = (b + e) >> 1;     return max(get(x + x, b, m, l, r), get(x + x + 1, m + 1, e, l, r));   }   int main() {     int n = in(), mx = 0;     string str =  aa ;     Store.push_back(str);     for (int i = 1; i <= n; i++) {       scanf( %s , s);       str = s;       Store.push_back(str);       ki[i] = in();       for (int j = 1; j <= ki[i]; j++) {         int di = in();         V[i].push_back(di);         mx = max(mx, di + (int)str.size() - 1);         modify(1, 1, limit, di, di + str.size() - 1, i);       }     }     for (int i = 1; i <= mx; i++) {       int idx = get(1, 1, limit, i, i);       if (idx == 0)         printf( a );       else {         int low = 0, high = V[idx].size() - 1, ans = 0;         while (low <= high) {           int mid = (low + high) >> 1;           if (V[idx][mid] <= i) {             low = mid + 1;             ans = V[idx][mid];           } else {             high = mid - 1;           }         }         printf( %c , Store[idx][i - ans]);       }     }     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int k;     cin >> k;     string s =  codeforces ;     long long int a[10];     long long int cnt = 1;     for (int i = 0; i < 10; ++i) {       a[i] = 1;     }     int idx = 0;     while (cnt < k) {       a[idx]++;       cnt = 1;       for (int i = 0; i < 10; ++i) {         cnt *= a[i];       }       idx = (idx + 1) % 10;     }     for (int i = 0; i < 10; ++i) {       for (int j = 0; j < a[i]; ++j) {         cout << s[i];       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   constexpr int N = 1e5 + 5;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n, m, x, y;     cin >> n >> m >> x >> y;     x--;     y--;     string s;     cin >> s;     vector<vector<int>> mat(n, vector<int>(m, -1));     for (int i = 0; i < s.size(); i++) {       if (mat[x][y] == -1) mat[x][y] = i;       if (s[i] ==  U ) x = max(x - 1, 0);       if (s[i] ==  D ) x = min(x + 1, n - 1);       if (s[i] ==  R ) y = min(y + 1, m - 1);       if (s[i] ==  L ) y = max(y - 1, 0);     }     vector<int> ans(s.size() + 1);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (mat[i][j] == -1) {           ans[s.size()]++;         } else {           ans[mat[i][j]]++;         }       }     }     for (int x : ans) cout << x <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int mx = 2e5 + 10;   const int mxb = 60;   long long int a[mx], b[mx], c[mx];   int cnt[mxb][2];   int bat(int idx, long long int v) {     if (v & (1ll << idx)) return 1;     return 0;   }   int main() {     int n;     scanf( %d , &n);     long long int sm = 0;     for (int i = 0; i < n; i++) scanf( %lld , b + i);     for (int i = 0; i < n; i++) scanf( %lld , c + i), sm += b[i] + c[i];     sm /= n + n;     for (int i = 0; i < n; i++) {       a[i] = (b[i] + c[i] - sm) / n;       if (a[i] < 0) {         puts( -1 );         return 0;       }       for (int j = 0; j < mxb; j++) cnt[j][bat(j, a[i])]++;     }     for (int i = 0; i < n; i++) {       long long int bi = 0, ci = 0;       int cb = 0, cc = 0;       for (int j = 0; j < mxb; j++) {         int db = cb, dc = cc;         for (int x = 0; x < 2; x++) {           db += cnt[j][x] * (bat(j, a[i]) & x);           dc += cnt[j][x] * (bat(j, a[i]) | x);         }         cb = db / 2, cc = dc / 2;         if (db & 1) bi |= (1ll << j);         if (dc & 1) ci |= (1ll << j);       }       if (bi != b[i] || ci != c[i]) {         puts( -1 );         return 0;       }     }     for (int i = 0; i < n; i++) printf( %lld  , a[i]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, e, f;     cin >> a >> b >> c >> d >> e >> f;     int sum = 0;     bool flag = false;     if (f > e) {       int x = min(b, min(c, d));       sum += f * x;       b -= x;       c -= x;       d -= x;       flag = true;     } else {       int y = min(a, d);       sum += e * y;       a -= y;       d -= y;     }     if (flag == true) {       int y = min(a, d);       sum += e * y;     } else {       int x = min(b, min(c, d));       sum += f * x;     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void pisz(int n) { printf( %d n , n); }   const int fx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};   const int fxx[9][2] = {{0, 0}, {0, 1},  {0, -1}, {1, 0},  {-1, 0},                          {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};   const int N = 500;   const long long mod = 1000000007;   struct FenwickTreeMax {     vector<int> bit;     int n;     FenwickTreeMax(int n) {       this->n = n;       bit.assign(n, 0);     }     FenwickTreeMax(vector<int> a) : FenwickTreeMax(a.size()) {       for (size_t i = 0; i < a.size(); i++) update(i, a[i]);     }     int getmax(int r) {       int ret = 0;       for (; r >= 0; r = (r & (r + 1)) - 1) ret = (ret < bit[r] ? bit[r] : ret);       return ret;     }     int pos_val(int r) { return bit[r]; }     void update(int idx, int val) {       for (; idx < n; idx = idx | (idx + 1))         bit[idx] = (bit[idx] < val ? val : bit[idx]);     }   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     string s;     cin >> s;     vector<long long> pos[26];     for (long long i = 0; i < n; i++) {       pos[s[i] -  a ].push_back(i);     }     FenwickTreeMax ft(n);     vector<long long> output(n, -1);     long long maxi = 0;     for (long long i = 25; i >= 0; i--) {       if (pos[i].size() == 0) continue;       vector<long long> col;       for (auto x : pos[i]) {         output[x] = ft.getmax(x) + 1;         maxi = (output[x] < maxi ? maxi : output[x]);       }       for (auto x : pos[i]) {         ft.update(x, output[x]);       }     }     cout << maxi <<   n ;     for (long long i = 0; i < n; i++) {       cout << output[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int>> vec;   int main() {     int n;     cin >> n;     for (int tt = 0; tt < n; tt++) {       int x, y;       cin >> x >> y;       vec.push_back({x, y});     }     sort(vec.begin(), vec.end());     int ans = -1;     for (int i = 0; i < n; i++) {       if (ans <= vec[i].second)         ans = vec[i].second;       else         ans = vec[i].first;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int T;   string s, ans;   bool exist[30];   int main() {     scanf( %d , &T);     for (int i = 0; i < T; i++) {       cin >> s;       ans.clear();       for (int j = 0; j < 26; j++) {         exist[j] = false;       }       ans = s[0];       exist[s[0] -  a ] = true;       bool Done = true;       for (int j = 1; j < s.length(); j++) {         if (!exist[s[j] -  a ]) {           if (ans.front() == s[j - 1]) {             ans = s[j] + ans;           } else if (ans.back() == s[j - 1]) {             ans.push_back(s[j]);           } else {             Done = false;             break;           }           exist[s[j] -  a ] = true;         } else {           int count = 0;           for (int k = 0; k < ans.length(); k++) {             if (ans[k] == s[j - 1]) {               count = k;               break;             }           }           if (count == 0) {             if (ans[1] != s[j]) {               Done = false;               break;             } else {               continue;             }           }           if (count == ans.length() - 1) {             if (ans[count - 1] != s[j]) {               Done = false;               break;             } else {               continue;             }           }           if (ans[count - 1] != s[j] && ans[count + 1] != s[j]) {             Done = false;             break;           }         }       }       if (!Done) {         cout <<  NO  << endl;       } else {         cout <<  YES  << endl;         cout << ans;         for (int j = 0; j < 26; j++) {           if (!exist[j]) {             cout << char( a  + j);           }         }       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   int n, first, second, a, b, m, d[(1 << 17) + 5], p[(1 << 17) + 5];   vector<int> g[(1 << 17) + 5];   bool check(int nod, int par, int del, int hg) {     int kids = g[nod].size();     if (par) kids--;     if (nod == del) {       if (hg == 1)         return 0;       else if (hg == 2) {         if (kids != 1) return 0;         for (int i : g[nod]) {           if (i != par) return check(i, nod, del, hg - 1);         }       } else {         if (kids != 3) return 0;         for (int i : g[nod]) {           if (i != par) kids -= check(i, nod, del, hg - 1);         }         if (kids != 2) return 0;         for (int i : g[nod]) {           if (i != par) kids -= check(i, nod, del, hg - 2);         }         if (kids != 0) return 0;         return 1;       }     } else {       if (hg == 1)         return (kids == 0);       else {         if (kids != 2) return 0;         for (int i : g[nod]) {           if (i != par) kids -= check(i, nod, del, hg - 1);         }         return (kids == 0);       }     }   }   bool good(int del, int root) { return check(root, 0, del, n); }   int32_t main() {     ios_base ::sync_with_stdio(0);     cin.tie();     cout.tie();     cin >> n;     m = (1 << n) - 2;     for (int i = 1; i < m; i++) {       cin >> first >> second;       g[first].push_back(second);       g[second].push_back(first);     }     for (int i = 1; i <= m; i++) {       if (g[i].size() == 2) {         int gd = 1;         for (int j : g[i]) {           if (g[j].size() == 1) gd = 0;         }         if (gd)           b = i;         else           a = i;       } else if (g[i].size() == 4)         a = i;     }     if (a && b && good(a, b)) {       cout << 1 <<   n  << a;       return 0;     }     int st = 0;     for (int i = 1; i <= m; i++) {       if (g[i].size() == 1) st = i;     }     queue<int> q;     d[st] = 1;     p[st] = 0;     q.push(st);     while (q.size()) {       int nod = q.front();       q.pop();       for (int i : g[nod]) {         if (!d[i]) d[i] = d[nod] + 1, p[i] = nod, q.push(i);       }     }     st = 0;     for (int i = 1; i <= m; i++) {       if (d[i] == 2 * n - 2) st = i;     }     for (int i = 1; i <= n - 2; i++) st = p[st];     a = st;     b = p[st];     if (a && b && good(a, a)) {       cout << 2 <<   n  << min(a, b) <<     << max(a, b);       return 0;     }     cout << 0;   }


#include <bits/stdc++.h>   const int MAXN = 2000 + 5;   long long mn = 1e18;   int ans[3][2], k = -1;   int n, m;   long long a[MAXN], b[MAXN];   inline long long mabs(long long x) { return x < 0 ? -x : x; }   int main() {     scanf( %d , &n);     long long s1 = 0, s2 = 0;     for (int i = 1; i <= n; ++i) scanf( %lld , a + i), s1 += a[i];     scanf( %d , &m);     for (int i = 1; i <= m; ++i) scanf( %lld , b + i), s2 += b[i];     mn = mabs(s1 - s2);     k = 0;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         if (mn > mabs(s1 - s2 - 2 * a[i] + 2 * b[j])) {           mn = mabs(s1 - s2 - 2 * a[i] + 2 * b[j]);           k = 1;           ans[1][0] = i;           ans[1][1] = j;         }       }     }     std::vector<long long> S1, S2;     long long t1 = -1, t2 = -1;     for (int i = 1; i <= n; ++i)       for (int j = i + 1; j <= n; ++j) S1.push_back(2ll * (a[i] + a[j]));     for (int i = 1; i <= m; ++i)       for (int j = i + 1; j <= m; ++j) S2.push_back(2ll * (b[i] + b[j]));     std::sort(S1.begin(), S1.end());     std::sort(S2.begin(), S2.end());     for (auto x : S1) {       long long now = s1 - s2 - x;       auto p = std::upper_bound(S2.begin(), S2.end(), -now);       if (p != S2.end()) {         if (mn > mabs(now + *p)) {           mn = mabs(now + *p);           t1 = x;           t2 = *p;           k = 2;         }       }       if (p != S2.begin()) {         --p;         if (mn > mabs(now + *p)) {           mn = mabs(now + *p);           t1 = x;           t2 = *p;           k = 2;         }       }     }     if (k == 2) {       for (int i = 1; i <= n; ++i)         for (int j = i + 1; j <= n; ++j)           if (2ll * (a[i] + a[j]) == t1) {             ans[1][0] = i;             ans[2][0] = j;             break;           }       for (int i = 1; i <= m; ++i)         for (int j = i + 1; j <= m; ++j)           if (2ll * (b[i] + b[j]) == t2) {             ans[1][1] = i;             ans[2][1] = j;             break;           }     }     printf( %lld n%d n , mn, k);     for (int i = 1; i <= k; ++i) {       printf( %d %d n , ans[i][0], ans[i][1]);     }     auto chk = [&]() {       for (int i = 1; i <= k; ++i) std::swap(a[ans[i][0]], b[ans[i][1]]);       long long sm0 = 0, sm1 = 0;       for (int i = 1; i <= n; ++i) sm0 += a[i];       for (int i = 1; i <= m; ++i) sm1 += b[i];       assert(mabs(sm0 - sm1) == mn);     };     chk();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     string l =  312931303130313130313031 ;     string input =   ;     string s =  312831303130313130313031 ;     string s1 = s + s + s;     string s2 = l + s + s;     string s3 = s + l + s;     string s4 = s + s + l;     long long int i;     for (i = 0; i < n; i++) {       string ch;       cin >> ch;       input += ch;     }     long long int flag1 = 0, flag2 = 0, flag3 = 0, flag4 = 0;     for (i = 0; i < s1.length() - 2 * n; i++) {       if (input.compare(s1.substr(i, n * 2)) == 0) {         flag1 = 1;       }     }     for (i = 0; i < s2.length() - 2 * n; i++) {       if (input.compare(s2.substr(i, 2 * n)) == 0) {         flag2 = 1;       }     }     for (i = 0; i < s3.length() - 2 * n; i++) {       if (input.compare(s3.substr(i, 2 * n)) == 0) {         flag3 = 1;       }     }     for (i = 0; i < s4.length() - 2 * n; i++) {       if (input.compare(s4.substr(i, 2 * n)) == 0) {         flag4 = 1;       }     }     if (flag1 || flag2 || flag3 || flag4) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5005;   const long long inf = 1e15;   long long dp[2][N][2];   int a[N][2];   void load() {}   void trungtt() {     int n, x;     scanf( %d%d , &n, &x);     long long ans = 0;     int l = x, r = x;     for (int i = 1; i <= n; ++i) {       int a, b;       scanf( %d%d , &a, &b);       if (l > b) {         ans += l - b;         r = l;         l = b;       } else if (r < a) {         ans += a - r;         l = r, r = a;       } else {         if (l < a) l = a;         if (r > b) r = b;       }     }     printf( %lld , ans);     return;   }   int main() {     load();     trungtt();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool upmin(T &x, T y) {     return y < x ? x = y, 1 : 0;   }   template <typename T>   inline bool upmax(T &x, T y) {     return x < y ? x = y, 1 : 0;   }   const long double eps = 1e-11;   const long double pi = acos(-1);   const int oo = 1 << 30;   const long long loo = 1ll << 62;   const int mods = 1e9 + 7;   const int MAXN = 5005;   const int INF = 0x3f3f3f3f;   inline int read() {     int f = 1, x = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + (c ^ 48);       c = getchar();     }     return x * f;   }   struct anode {     int u, v;     long long c;   };   vector<anode> Ans;   long long a[MAXN];   int f[MAXN][MAXN], frm[MAXN][MAXN], flag[MAXN], n, k, V;   void add(int u, int v, long long c) {     long long t = min(c * k, a[u]);     a[u] -= t, a[v] += t;     Ans.push_back((anode){u, v, c});   }   signed main() {     long long sum = 0;     n = read(), k = read(), V = read();     for (int i = 1; i <= n; i++) a[i] = read(), sum += a[i];     if (sum < V) {       puts( NO );       return 0;     }     f[0][0] = 1;     for (int i = 1; i <= n; i++)       for (int j = 0; j < k; j++)         if (f[i - 1][j])           f[i][j] = 1, frm[i][j] = 0;         else if (f[i - 1][(j - a[i] % k + k) % k])           f[i][j] = 1, frm[i][j] = 1;     int nw = V % k, id1 = 0, id2 = 0;     if (!f[n][nw]) {       puts( NO );       return 0;     }     puts( YES );     for (int i = n; i >= 1; i--) {       if (frm[i][nw])         flag[i] = 1, nw = (nw - a[i] % k + k) % k, id1 = i;       else         id2 = i;     }     for (int i = 1; i <= n; i++)       if (a[i] && i != id1 && i != id2) {         if (flag[i])           add(i, id1, (a[i] - 1) / k + 1);         else           add(i, id2, (a[i] - 1) / k + 1);       }     if (!id1) id1 = (id2 == n ? id2 - 1 : id2 + 1);     if (!id2) id2 = (id1 == n ? id1 - 1 : id1 + 1);     if (a[id1] > V) add(id1, id2, (a[id1] - V) / k);     if (a[id1] < V) add(id2, id1, (V - a[id1]) / k);     for (auto v : Ans) printf( %lld %d %d n , v.c, v.u, v.v);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d %d  , &n, &m);     char A[147][10047];     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) scanf( %c  , &A[i][j]);     int P[147][10047];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) P[i][j] = -1;       queue<int> Q;       for (int j = 0; j < m; j++)         if (A[i][j] ==  1 ) {           Q.push(j);           Q.push(0);           P[i][j] = 0;         }       while (!Q.empty()) {         int kde = Q.front();         Q.pop();         int kolko = Q.front();         Q.pop();         int dx[] = {1, -1};         for (int k = 0; k < 2; k++) {           int kde1 = kde + dx[k];           kde1 += m;           kde1 %= m;           if (P[i][kde1] == -1) {             P[i][kde1] = kolko + 1;             Q.push(kde1);             Q.push(kolko + 1);           }         }       }     }     int vys = -1;     int V[10047];     for (int i = 0; i < m; i++) V[i] = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (P[i][j] == -1)           V[j] = -1;         else if (V[j] != -1)           V[j] += P[i][j];       }     vys = V[0];     for (int i = 0; i < m; i++) vys = min(vys, V[i]);     printf( %d n , vys);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> mat[100010];   int vis[100010], val[100010];   int dfs(int p, int pa) {     if (vis[p]) return 1;     int ret = 0;     vis[p] = 1;     if (p != pa) val[p] += val[pa];     for (auto x : mat[p]) ret = max(ret, dfs(x, p));     return ret;   }   int in[100010], out[100010], n, dp[302][100002][2];   int rec(int p, int r, int t) {     if (p == n + 1) return (r == 0);     if (r < 0) return 0;     int &temp = dp[p][r][t];     if (temp != -1) return temp;     temp = 0;     if (!out[p] || t) temp += rec(p + 1, r, 0);     if (temp > 1000000007) temp -= 1000000007;     temp += rec(p, r - val[p], 1);     if (temp > 1000000007) temp -= 1000000007;     return temp;   }   int main() {     ios::sync_with_stdio(0);     int q, t, u, v;     cin >> n >> q >> t;     for (int i = 1; i <= n; i++) cin >> val[i];     for (int i = 0; i <= q - 1; i++) {       cin >> u >> v;       mat[u].push_back(v);       in[v]++;       out[u]++;     }     int chao = 0;     for (int i = 1; i <= n; i++)       if (!vis[i] && !in[i]) chao = max(chao, dfs(i, i));     for (int i = 1; i <= n; i++)       if (!vis[i]) chao = 1;     memset(dp, -1, sizeof(dp));     if (chao)       cout << 0 << endl;     else       cout << rec(1, t, 0) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int B[300000];   pair<int, int> A[300000];   stack<pair<int, int> > s;   queue<pair<pair<int, int>, int> > q;   int main() {     int N, l, f, i;     long long ta = 0, tb = 0;     scanf( %d , &N);     for (i = 0; i < N; ++i)       scanf( %d , &A[i].first), A[i].second = i, ta += A[i].first;     for (i = 0; i < N; ++i) scanf( %d , &B[i]), tb += B[i];     sort(A, A + N);     sort(B, B + N);     if (ta != tb) {       printf( NO n );       return 0;     }     for (i = 0; i < N; ++i) {       if (A[i].first < B[i])         s.emplace(B[i] - A[i].first, A[i].second);       else {         l = A[i].first - B[i];         while (l && !s.empty()) {           q.emplace(make_pair(s.top().second + 1, A[i].second + 1),                     f = min(l, s.top().first));           s.top().first -= f;           l -= f;           if (!s.top().first) s.pop();         }         if (l) {           printf( NO n );           return 0;         }       }     }     printf( YES n );     printf( %d n , q.size());     while (!q.empty())       printf( %d %d %d n , q.front().first.first, q.front().first.second,              q.front().second),           q.pop();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<int> s[40];   set<int>::iterator it, q;   int n, m, k, sol, v[40];   int main() {     int i, j;     scanf( %d %d , &n, &m);     for (i = 1; i <= n; i++) {       scanf( %d , &v[i]);       v[i] %= m;     }     if (n == 1) {       printf( %d , v[1]);       return 0;     }     if (n == 2) {       printf( %d , max((v[1] + v[2]) % m, max(v[1], v[2])));       return 0;     }     k = n / 2;     for (i = 1; i <= n; i++) {       s[i].insert(v[i]);       if (i != k + 1) {         for (it = s[i - 1].begin(); it != s[i - 1].end(); it++) {           j = *it;           s[i].insert(j);           j += v[i];           j %= m;           s[i].insert(j);         }         s[i - 1].clear();       }     }     it = s[k].end();     it--;     sol = *it;     it = s[n].end();     it--;     sol = max(sol, int(*it));     if (s[n].begin() != s[n].end())       for (it = s[k].begin(); it != s[k].end(); it++) {         i = *it;         j = m - i;         q = s[n].lower_bound(j);         if (q != s[n].begin()) {           q--;           sol = max(sol, (i + int(*q)) % m);         }         q = s[n].end();         q--;         sol = max(sol, int((1LL * i + int(*q)) % m));       }     printf( %d , sol);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char M[10][10];   int V[10];   int main() {     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> M[i];     for (int i = 0; i < k; i++) V[i] = i;     long ans(1e10);     do {       long mx(0), mn(1e10);       for (int i = 0; i < n; i++) {         long num = 0;         for (int j = 0; j < k; j++) {           num = num * 10 + (M[i][V[j]] -  0 );         }         mx = max(mx, num);         mn = min(mn, num);       }       ans = min(ans, mx - mn);     } while (next_permutation(V, V + k));     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     cin >> t;     while (t--) {       int n, mx = -1;       cin >> n;       int arr[n];       for (int i = 0; i < n; i++) {         cin >> arr[i];         mx = max(mx, arr[i]);       }       int ans = -1;       for (int i = 1; i < n; i++)         if (arr[i] == mx && arr[i - 1] != mx) ans = i + 1;       for (int i = 0; i < n - 1; i++)         if (arr[i] == mx && arr[i + 1] != mx) ans = i + 1;       cout << ans << (  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int min(int a, int b) {     if (a < b) return a;     return b;   }   int Abs(int a) {     if (a < 0)       return -a;     else       return a;   }   double Abs(double a) {     if (a < 0)       return -a;     else       return a;   }   unsigned long long sqr(unsigned long long a) { return a * a; }   double sqr(double a) { return a * a; }   int main() {     int a, b, c;     cin >> a >> b;     c = 0;     while (b) {       c = c * 10 + b % 10;       b /= 10;     }     cout << a + c << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m;   vector<long long> boxes;   vector<int> counts;   long long answer;   void In() {     boxes.clear();     counts.clear();     answer = 0;     cin >> n >> m;     boxes.resize(m);     counts.resize(63);     for (int i = 0; i < m; i++) cin >> boxes[i];   }   long long Solve() {     long long sum = 0;     for (long long box : boxes) sum += box;     if (sum < n) return -1;     for (long long box : boxes) counts[log2(box)]++;     for (int i = 0; i <= log2(n); i++)       if ((1 << i) & n) {         for (int j = 0; j < i; j++) {           counts[j + 1] += counts[j] / 2;           counts[j] %= 2;         }         if (!counts[i])           for (int j = i + 1; j < 63; j++)             if (counts[j]) {               while (j != i) {                 counts[j]--;                 j--;                 counts[j] += 2;                 answer++;               }               break;             }         counts[i]--;       }     return answer;   }   void Out() { cout << answer << endl; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     cin >> t;     while (t--) {       In();       answer = Solve();       Out();     }   }


#include <bits/stdc++.h>   int x, y, u, v, d = 1, a, b;   int main() {     for (scanf( %d%d , &a, &b); a; b /= 4, d *= 2, --a) {       if (b % 4 == 0)         u = y, v = x;       else if (b % 4 == 1)         u = x, v = y + d;       else if (b % 4 == 2)         u = x + d, v = y + d;       else         u = 2 * d - y - 1, v = d - x - 1;       x = u, y = v;     }     printf( %d %d n , x, y);     return 0;   }