#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1100000;   int p[MAXN], f[MAXN], g[MAXN];   int main() {     int n;     scanf( %d , &n);     f[1] = 1, g[1] = 0;     for (int i = 2; i <= n + 1; i++) {       scanf( %d , &p[i]);       f[i] = 1, g[i] = 0;       for (int v = i; v != 1; v = p[v]) {         int tmp = f[p[v]];         if (f[v] > g[p[v]])           f[p[v]] = g[p[v]] = f[v];         else           f[p[v]] = max(f[p[v]], f[v] + 1);         if (f[p[v]] == tmp) break;       }       printf( %d  , g[1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, x;     cin >> n >> x;     string s;     cin >> s;     for (int j = 0; j < x; j++) {       for (int i = 0; i < n - 1; i++) {         if (s[i] ==  B  && s[i + 1] ==  G ) {           s[i] =  G ;           s[i + 1] =  B ;           i++;         }       }     }     cout << s <<   n ;     return 0;   }


#include<bits/stdc++.h>   using namespace std;   typedef long long ll;   typedef unsigned long long ull;   #define pii pair<int,int>   #define fi first   #define se second   #define mp make_pair   #define poly vector<ll>   #define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)   #define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)   #define pb push_back   inline ll read(){    ll x=0; char ch=getchar(); bool d=1;    for(;!isdigit(ch);ch=getchar()) if(ch== - ) d=0;    for(;isdigit(ch);ch=getchar()) x=x*10+ch- 0 ;    return d?x:-x;   }   inline ull rnd(){    return ((ull)rand()<<30^rand())<<4|rand()%4;   }   const int N=1e5+5;   map<pii,bool> used;   map<int,int> id;   set<int> S;   poly v[N<<1],rv;   bool ans[N];   int q[N];   int main(){    int n=read(),m=read(),cnt=1;    used[mp(0,0)]=1; id[0]=1; rv.pb(0); v[1].pb(0);    For(i,1,n){     int x=read(),y=read();     if(!id[x]) id[x]=++cnt,rv.pb(x);     used[mp(x,y)]=1; v[id[x]].pb(y);    }    For(i,1,m){     int x=read(),y=read(); q[i]=y;     if(used[mp(x,y)]) continue;     if(!id[x]) id[x]=++cnt,rv.pb(x);     v[id[x]].pb(-i);    }    sort(rv.begin(),rv.end());    int pre=-1,ssw=0;    for(auto o:rv){     for(int i=pre+1;i<o;){      while(S.find(ssw)!=S.end()) ssw++;      auto ksg=S.upper_bound(ssw);      if(ksg==S.end()){       ssw+=o-i; break;      }      int t=min(*ksg-ssw,(int)o-i);      ssw+=t; i+=t;     }     int pos=id[o],mn=0x3f3f3f3f;     sort(v[pos].begin(),v[pos].end());     for(auto x:v[pos]) if(x>=0){      mn=x; break;     }     while(S.find(ssw)!=S.end()) ssw++;     if(ssw<mn) S.insert(ssw); mn=min(mn,ssw);     for(auto x:v[pos]){      if(x>=0) S.insert(x);      else ans[-x]=(q[-x]!=mn);     }     pre=o;    }    For(i,1,m) puts(ans[i]? WIN : LOSE );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int x = 0, y = 0;     for (int i = 0; i < s.size(); i++) {       x = x % 4;       y = y % 4;       if (s[i] ==  0 ) {         cout << 3 <<     << y + 1 << endl;         y++;       } else {         cout << 1 <<     << x + 1 << endl;         x += 2;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     srand(time(NULL));     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       unordered_map<string, int> codes;       vector<string> v(n);       for (int i = 0; i < n; i++) {         string x;         cin >> x;         v[i] = x;         codes[x]++;       }       int ans = 0;       vector<string> anss;       for (int i = 0; i < n; i++) {         if (codes[v[i]] > 1) {           ans++;           string x = v[i];           while (codes[x] >= 1) {             x = v[i];             int pos = rand() % 4;             char digit = (char)( 0  + (rand() % 10));             x[pos] = digit;           }           codes[x] = 1;           codes[v[i]]--;           anss.push_back(x);         } else           anss.push_back(v[i]);       }       cout << ans <<   n ;       for (auto a : anss) cout << a <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double x, y, R, r, eps = 0.000001;   int a, b;   int main() {     scanf( %lf , &r);     for (a = 1; a < 11; a++)       for (b = 1; b < 11; b++) {         x = (double)a / 2;         y = (double)b;         R = sqrt(x * x + y * y);         if (abs((double)a / 2 * (double)b / R - r) < eps) {           printf( %d %d n , a, b);           return 0;         }       }   }


#include <bits/stdc++.h>   using namespace std;   int n, m, l, r, a[100100], L[100100], R[100100];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 1; i <= n; ++i)       if (a[i] > a[i - 1])         L[i] = i;       else         L[i] = L[i - 1];     for (int i = n; i >= 1; --i)       if (a[i] > a[i + 1])         R[i] = i;       else         R[i] = R[i + 1];     while (m--) {       scanf( %d%d , &l, &r);       if (R[l] >= L[r])         puts( Yes );       else         puts( No );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int ret = 0;     char c = getchar();     while (c >  9  || c <  0 ) c = getchar();     while (c >=  0  && c <=  9 )       ret = (ret << 3) + (ret << 1) + (c ^ 48), c = getchar();     return ret;   }   const int maxn = 55;   const int maxk = 6;   const int maxm = 2500;   const int inf = 1e9;   int n, k;   int dlim[maxk];   struct edge {     int from, to, val;   } e1[15], e2[maxm];   int cnt1, cnt2;   int ans;   int d[maxk];   bool ini[maxm], x[maxm], y[maxm];   int dis[maxm], pre[maxm];   struct dsu {     int fa[maxn];     void prework() {       for (int i = 1; i <= n; i++) fa[i] = i;     }     int get(int x) { return x == fa[x] ? x : fa[x] = get(fa[x]); }     void merge(int x, int y) { fa[get(x)] = get(y); }     bool check(int x, int y) { return get(x) == get(y); }   } S;   queue<int> q;   bool inq[maxm];   int ret = 0;   bool deb = 0;   struct graph {     int head[maxm], ver[maxm * maxm], nxt[maxm * maxm], val[maxm * maxm], tot;     void add(int x, int y, int z) {       ver[++tot] = y;       val[tot] = z;       nxt[tot] = head[x];       head[x] = tot;     }     void clear() {       tot = 0;       for (int i = 1; i <= cnt2 + 2; i++) head[i] = 0;     }     int dis[maxm], pre[maxm], len[maxm];     bool inq[maxm];     void spfa() {       for (int i = 1; i <= cnt2 + 2; i++)         dis[i] = 0x3f3f3f3f, inq[i] = 0, pre[i] = 0;       dis[cnt2 + 1] = 0;       q.push(cnt2 + 1);       inq[cnt2 + 1] = 1;       while (!q.empty()) {         int now = q.front();         q.pop();         inq[now] = 0;         for (int i = head[now]; i; i = nxt[i])           if (dis[ver[i]] > dis[now] + val[i] ||               (dis[ver[i]] == dis[now] + val[i] && len[ver[i]] > len[now] + 1)) {             dis[ver[i]] = dis[now] + val[i];             len[ver[i]] = len[now] + 1;             pre[ver[i]] = now;             if (!inq[ver[i]]) q.push(ver[i]);             inq[ver[i]] = 1;           }       }     }     void update() {       int now = cnt2 + 2;       while (now) {         ini[now] ^= 1;         if (ini[now])           ret -= e2[now].val;         else           ret += e2[now].val;         now = pre[now];       }     }   } o;   bool calc(int chose) {     for (int i = 1; i <= k; i++) d[i] = 0;     S.prework();     for (int i = 1; i <= cnt1; i++)       if ((chose >> (i - 1)) & 1) {         d[e1[i].from]++, d[e1[i].to]++;         S.merge(e1[i].from, e1[i].to);       }     for (int i = 1; i <= cnt2; i++)       if (ini[i]) {         if (e2[i].from <= k) d[e2[i].from]++;         S.merge(e2[i].from, e2[i].to);       }     int s = cnt2 + 1, t = cnt2 + 2;     o.clear();     for (int i = 1; i <= cnt2; i++) {       if (ini[i])         x[i] = y[i] = 0;       else {         x[i] = (!S.check(e2[i].from, e2[i].to));         y[i] = (e2[i].from > k || d[e2[i].from] + 1 <= dlim[e2[i].from]);         if (x[i]) o.add(s, i, e2[i].val);         if (y[i]) o.add(i, t, 0);       }     }     for (int i = 1; i <= cnt2; i++) {       if (!ini[i]) continue;       S.prework();       for (int j = 1; j <= cnt2; j++)         if (ini[j] && j != i) S.merge(e2[j].from, e2[j].to);       for (int i = 1; i <= cnt1; i++)         if ((chose >> (i - 1)) & 1) S.merge(e1[i].from, e1[i].to);       for (int j = 1; j <= cnt2; j++) {         if (ini[j]) continue;         if (!S.check(e2[j].from, e2[j].to)) o.add(i, j, e2[j].val);         if (e2[j].from > k ||             d[e2[j].from] - (e2[j].from == e2[i].from) < dlim[e2[j].from])           o.add(j, i, -e2[i].val);       }     }     o.spfa();     if (o.dis[t] == 0x3f3f3f3f) return false;     o.update();     return true;   }   void solve(int chose) {     for (int i = 1; i <= k; i++) d[i] = 0;     S.prework();     ret = 0;     for (int i = 1; i <= cnt1; i++)       if ((chose >> (i - 1)) & 1) {         d[e1[i].from]++;         d[e1[i].to]++;         ret += e1[i].val;         if (d[e1[i].from] > dlim[e1[i].from]) return;         if (d[e1[i].to] > dlim[e1[i].to]) return;         if (S.check(e1[i].from, e1[i].to)) return;         S.merge(e1[i].from, e1[i].to);       }     for (int i = 1; i <= cnt2; i++) ini[i] = 0;     int cnt = 0;     if (ret > ans) return;     while (calc(chose))       if (ret > ans) return;     ret = 0;     bool flag = 1;     S.prework();     for (int i = 1; i <= cnt1; i++)       if ((chose >> (i - 1)) & 1) S.merge(e1[i].from, e1[i].to), ret += e1[i].val;     for (int i = 1; i <= cnt2; i++)       if (ini[i]) S.merge(e2[i].from, e2[i].to), ret += e2[i].val;     for (int i = 1; i <= n; i++)       if (!S.check(1, i)) return;     ans = min(ret, ans);   }   int main() {     n = read();     k = read();     for (int i = 1; i <= k; i++) dlim[i] = read();     for (int i = 1; i <= n - 1; i++)       for (int j = 1; j <= n - i; j++)         if (i <= k && i + j <= k) {           cnt1++;           e1[cnt1].from = i;           e1[cnt1].to = i + j;           e1[cnt1].val = read();         } else {           cnt2++;           e2[cnt2].from = i;           e2[cnt2].to = i + j;           e2[cnt2].val = read();         }     ans = inf;     for (int i = 0; i < (1 << cnt1); i++) solve(i);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string a, b;   int ans = 0;   vector<int> A, B;   string cp(string s, int n) {     string ans = s;     for (int i = 1; i < n; i++) ans += s;     return ans;   }   int main() {     cin >> a >> b;     for (int i = 1; i <= a.size(); i++)       if (a.size() % i == 0 && cp(a.substr(0, i), a.size() / i) == a)         A.push_back(i);     for (int i = 1; i <= b.size(); i++)       if (b.size() % i == 0 && cp(b.substr(0, i), b.size() / i) == b)         B.push_back(i);     for (int i = 0; i < A.size(); i++)       for (int j = 0; j < B.size(); j++)         if (A[i] == B[j] && a.substr(0, A[i]) == b.substr(0, B[j])) ans++;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   static const int MAXN = 5004;   static const int ALPHA = 26;   static const int MODULUS = 1e9 + 7;   int n;   char s[MAXN];   int binom[MAXN][MAXN];   int f[MAXN][ALPHA] = {{0}}, f_rowsum[MAXN] = {0};   void preprocess_binomials() {     binom[0][0] = 1;     for (int i = 1; i < MAXN; ++i) {       binom[i][0] = 1;       for (int j = 1; j <= i; ++j)         binom[i][j] = (binom[i - 1][j - 1] + binom[i - 1][j]) % MODULUS;     }   }   int main() {     preprocess_binomials();     scanf( %d , &n);     getchar();     for (int i = 0; i < n; ++i) s[i] = getchar() -  a ;     f_rowsum[0] = 1;     for (int i = 0; i < n; ++i) {       for (int len = i + 1; len >= 1; --len) {         int increment =             ((f_rowsum[len - 1] - f[len - 1][s[i]] - f[len][s[i]]) % MODULUS +              MODULUS) %             MODULUS;         (f[len][s[i]] += increment) %= MODULUS;         (f_rowsum[len] += increment) %= MODULUS;       }     }     int ans = 0;     for (int i = 1; i <= n; ++i)       for (int j = 0; j < ALPHA; ++j)         ans =             ((long long)ans + (long long)f[i][j] * binom[n - 1][i - 1]) % MODULUS;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   std::vector<long long> prime;   unsigned long long int power(unsigned long long int x, unsigned long long int y,                                unsigned long long int mod) {     unsigned long long int res = 1;     while (y) {       if (y & 1) res = res * x % mod;       x = x * x % mod;       y >>= 1;     }     return res;   }   bool miller(unsigned long long int x, unsigned long long int d) {     unsigned long long int a = rand() % (x - 1) + 2;     unsigned long long int ad = power(a, d, x);     if (ad == 1 || ad == x - 1) {       return true;     }     while (d != x - 1) {       ad = ad * ad % x;       if (ad == 1) {         return false;       }       if (ad == x - 1) {         return true;       }       d *= 2;     }     return false;   }   bool primer(unsigned long long int x) {     if (x == 2 || x == 3 || x == 5 || x == 7) return true;     if (x % 2 == 0 || x == 1) return false;     unsigned long long int d = x - 1;     while (d % 2 == 0) d = d / 2;     for (int i = 0; i < 7; ++i) {       if (!miller(x, d)) {         return false;       }     }     return true;   }   bool isp(long long n) {     if (n == 1) {       return false;     }     for (int i = 2; i <= sqrt(n); i++) {       if (!n % 2) {         return false;       }     }     return true;   }   int nearestprime(unsigned long long int x) {     unsigned long long int i;     for (i = x; !primer(i); i--)       ;     return i;   }   set<pair<int, int> > st;   int main() {     ios::sync_with_stdio(false);     int n, k, c, p;     int tsize[1000 + 45];     pair<int, pair<int, int> > price[1000 + 45];     bool occ[1000 + 45];     for (int i = 0; i <= 1000; i++) {       occ[i] = false;     }     vector<pair<int, int> > ans;     pair<int, int> table[1000 + 45];     cin >> n;     for (int i = 0; i < n; i++) {       cin >> c >> p;       price[i].first = p;       price[i].second.first = INT_MAX - c;       price[i].second.second = i;     }     cin >> k;     for (int i = 0; i < k; i++) {       cin >> table[i].first;       table[i].second = i;     }     pair<int, int> *it;     sort(price, price + n);     sort(table, table + k);     table[k].first = INT_MAX;     table[k].second = INT_MAX;     long long sum = 0;     int cnt = 0;     for (int i = n - 1; i >= 0; i--) {       it = lower_bound(table, table + k,                        make_pair(INT_MAX - price[i].second.first, -1));       if (it->first == INT_MAX) {         continue;       } else {         bool flag = true;         while (occ[it->second] == true) {           it++;           if (it->first == INT_MAX) {             flag = false;             break;           }         }         if (flag == true) {           occ[it->second] = true;           sum += price[i].first;           cnt++;           ans.push_back(make_pair(price[i].second.second, it->second));         }       }     }     cout << cnt <<     << sum <<   n ;     sort(ans.begin(), ans.end());     for (int i = 0; i < ans.size(); i++) {       cout << ans[i].first + 1 <<     << ans[i].second + 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T qmin(const T &x, const T &y) {     return x < y ? x : y;   }   template <typename T>   inline T qmax(const T &x, const T &y) {     return x > y ? x : y;   }   template <typename T>   inline void getmin(T &x, const T &y) {     if (y < x) x = y;   }   template <typename T>   inline void getmax(T &x, const T &y) {     if (y > x) x = y;   }   inline void fileio(string s) {     freopen((s +  .in ).c_str(),  r , stdin);     freopen((s +  .out ).c_str(),  w , stdout);   }   const int inf = (int)1e9 + 7;   const long long linf = (long long)1e17 + 7;   const int N = 1e5 + 7, Node = N << 2;   int to[Node][10];   long long val[Node][10];   int n, q, a[N];   inline void merge(int u) {     for (int i = 0; i < (10); ++i) val[u][i] = 0;     for (int i = 0; i < (10); ++i) {       val[u][to[((u) << 1)][i]] += val[((u) << 1)][i];       val[u][to[((u) << 1 ^ 1)][i]] += val[((u) << 1 ^ 1)][i];     }   }   inline void psd(int u) {     for (int i = 0; i < (10); ++i) {       to[((u) << 1)][i] = to[u][to[((u) << 1)][i]];       to[((u) << 1 ^ 1)][i] = to[u][to[((u) << 1 ^ 1)][i]];     }     for (int i = 0; i < (10); ++i) to[u][i] = i;   }   inline void init(int u, int l, int r) {     for (int i = 0; i < (10); ++i) to[u][i] = i;     if (l == r) {       for (int v = a[l], w = 1; v; v /= 10, w *= 10) val[u][v % 10] += w;     } else {       int mid = l + r >> 1;       init(((u) << 1), l, mid);       init(((u) << 1 ^ 1), mid + 1, r);       merge(u);     }   }   inline void change(int u, int l, int r, int l1, int r1, int x, int y) {     if (l1 <= l && r <= r1) {       for (int i = 0; i < (10); ++i)         if (to[u][i] == x) to[u][i] = y;     } else {       psd(u);       int mid = l + r >> 1;       if (l1 <= mid) change(((u) << 1), l, mid, l1, r1, x, y);       if (r1 > mid) change(((u) << 1 ^ 1), mid + 1, r, l1, r1, x, y);       merge(u);     }   }   inline long long getans(int u, int l, int r, int l1, int r1) {     long long ans = 0;     if (l1 <= l && r <= r1) {       for (int i = 0; i < (10); ++i) ans += to[u][i] * val[u][i];     } else {       psd(u);       int mid = l + r >> 1;       if (l1 <= mid) ans += getans(((u) << 1), l, mid, l1, r1);       if (r1 > mid) ans += getans(((u) << 1 ^ 1), mid + 1, r, l1, r1);       merge(u);     }     return ans;   }   int main() {     scanf( %d%d , &n, &q);     for (int i = (1); i <= (n); ++i) scanf( %d , a + i);     init(1, 1, n);     while (q--) {       int type, l, r, x, y;       scanf( %d%d%d , &type, &l, &r);       if (type == 1) {         scanf( %d%d , &x, &y);         change(1, 1, n, l, r, x, y);       } else {         printf( %lld n , getans(1, 1, n, l, r));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<vector<int>> moves(2, vector<int>());     for (int i = 0; i < 2; ++i) {       int k;       cin >> k;       for (int j = 0; j < k; ++j) {         int m;         cin >> m;         moves[i].push_back(m);       }     }     queue<std::pair<int, int>> q;     q.push({0, 0});     q.push({0, 1});     vector<vector<int>> res(n, vector<int>(2, -1));     res[0][0] = 0;     res[0][1] = 0;     vector<vector<int>> counter(n, vector<int>(2, 0));     while (!q.empty()) {       std::pair<int, int> v = q.front();       q.pop();       int pos = v.first;       int player = v.second;       if (res[pos][player] == 0) {         for (const auto& m : moves[1 ^ player]) {           int k = pos - m;           if (k < 0) {             k += n;           }           if (res[k][1 ^ player] == -1) {             res[k][1 ^ player] = 1;             q.push({k, 1 ^ player});           }         }       } else {         for (const auto& m : moves[1 ^ player]) {           int k = pos - m;           if (k < 0) {             k += n;           }           if (res[k][1 ^ player] == -1) {             ++counter[k][1 ^ player];             if (counter[k][1 ^ player] == (int)moves[1 ^ player].size()) {               res[k][1 ^ player] = 0;               q.push({k, 1 ^ player});             }           }         }       }     }     for (int i = 0; i < 2; ++i) {       for (int j = 1; j < n; ++j) {         if (res[j][i] == 0) {           cout <<  Lose  ;         } else if (res[j][i] == 1) {           cout <<  Win  ;         } else {           cout <<  Loop  ;         }       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   int a[maxn], b[maxn];   int p[maxn];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     memset(p, 0, sizeof(p));     for (int i = 1; i <= n; i++) {       scanf( %d , &b[i]);       p[b[i]] = i;     }     if (p[1]) {       for (int i = 1; p[i] == p[1] + i - 1; i++) {         if (p[i] == n) {           int k = i + 1;           for (; k <= n && p[k] <= k - i - 1; k++)             ;           if (k > n) {             printf( %d n , n - i);             return 0;           }         }       }     }     int ans = 0;     for (int i = 1; i <= n; i++) {       ans = max(ans, p[i] - i + 1 + n);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 2e9;   struct point {     int x, y, id;     point operator-(const point &a) const {       point res;       res.x = x - a.x;       res.y = y - a.y;       return res;     }     int operator*(const point &a) const { return x * a.y - y * a.x; }   } p[100010], o;   int dis(point x, point y) {     return (x.x - y.x) * (x.x - y.x) + (x.y - y.y) * (x.y - y.y);   }   int qua(point x) {     if (x.x > 0 && x.y >= 0) {       return 1;     }     if (x.x <= 0 && x.y > 0) {       return 2;     }     if (x.x < 0 && x.y <= 0) {       return 3;     }     if (x.x >= 0 && x.y < 0) {       return 4;     }   }   bool cmp(point x, point y) {     if (fabs(atan2(x.y, x.x) - atan2(y.y, y.x)) > 0.1) {       return atan2(x.y, x.x) < atan2(y.y, y.x);     }     int tmp = (x - o) * (y - o);     if (tmp == 0) {       return dis(x, o) < dis(y, o);     } else {       return tmp > 0;     }   }   point Div(point x, point y) {     point res;     res.x = x.x * y.x + x.y * y.y;     res.y = x.y * y.x - x.x * y.y;     return res;   }   int n, ans, ansa = 1, ansb = -inf;   bool upd(int a, int b) {     if (1LL * a * ansb < 1LL * ansa * b) {       ansa = a;       ansb = b;       return true;     } else {       return false;     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d%d , &p[i].x, &p[i].y);       p[i].id = i + 1;     }     sort(p, p + n, cmp);     p[n] = p[0];     for (int i = 0; i < n; i++) {       point x = Div(p[i], p[i + 1]);       if (x.y < 0) {         x.y = -x.y;       }       if (upd(x.y, x.x)) {         ans = i;       }     }     printf( %d %d n , p[ans].id, p[ans + 1].id);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:512000000 )   using namespace std;   void solve(bool);   void precalc();   clock_t start;   int main() {     start = clock();     int t = 1;     cout.sync_with_stdio(0);     cin.tie(0);     precalc();     cout.precision(10);     cout << fixed;     int testNum = 1;     while (t--) {       solve(true);     }     cout.flush();     return 0;   }   template <typename T>   T binpow(T q, T w, T mod) {     if (!w) return 1 % mod;     if (w & 1) return q * 1LL * binpow(q, w - 1, mod) % mod;     return binpow(q * 1LL * q % mod, w / 2, mod);   }   template <typename T>   T gcd(T q, T w) {     while (w) {       q %= w;       swap(q, w);     }     return q;   }   template <typename T>   T lcm(T q, T w) {     return q / gcd(q, w) * w;   }   template <typename T>   void make_unique(vector<T>& a) {     sort(a.begin(), a.end());     a.erase(unique(a.begin(), a.end()), a.end());   }   template <typename T>   void relax_min(T& cur, T val) {     cur = min(cur, val);   }   template <typename T>   void relax_max(T& cur, T val) {     cur = max(cur, val);   }   void precalc() {}   const long long C = 100500;   long long mod;   long long phi;   long long rem[C];   long long rev_rem[C];   vector<long long> primes, degs;   long long n;   long long get_deg(long long n, long long p) {     long long res = 0;     while (n) {       res += n / p;       n /= p;     }     return res;   }   long long getC(long long n, long long k) {     if (n < k) {       return 0;     }     long long res = rem[n] * rev_rem[k] % mod * rev_rem[n - k] % mod;     for (long long i = 0; i < primes.size(); ++i) {       long long deg = get_deg(n, primes[i]) - get_deg(k, primes[i]) -                       get_deg(n - k, primes[i]);       res = res * binpow(primes[i], deg, mod) % mod;     }     return res;   }   long long get_res(long long l) {     long long res = 0;     for (long long par = 0; par < 2; ++par) {       for (long long cur = 0; 2 * cur + par <= n; ++cur) {         long long m = 2 * cur + par;         long long cur_l = l;         if ((cur_l + par) % 2) {           ++cur_l;         }         long long now_c = (m + cur_l) / 2;         res += getC(n, m) * getC(m, now_c);         res %= mod;       }     }     return res;   }   void solve(bool read) {     long long l, r;     cin >> n >> mod >> l >> r;     rem[0] = 1;     long long M = mod;     phi = mod;     for (long long p = 2; p * p <= M; ++p) {       if (M % p == 0) {         phi = phi * (p - 1) / p;         primes.push_back(p);         degs.push_back(0);         while (M % p == 0) {           M /= p;           ++degs.back();         }       }     }     if (M > 1) {       phi = phi * (M - 1) / M;       primes.push_back(M);       degs.push_back(1);     }     for (long long i = 1; i < C; ++i) {       long long cur = i;       for (long long p : primes) {         while (cur % p == 0) {           cur /= p;         }       }       rem[i] = rem[i - 1] * cur % mod;     }     for (long long i = 0; i < C; ++i) {       rev_rem[i] = binpow(rem[i], phi - 1, mod);     }     long long res = get_res(l) - get_res(r + 1);     res %= mod;     if (res < 0) {       res += mod;     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1200 + 10;   char s[maxn];   int a[maxn];   int main() {     while (~scanf( %s , s)) {       memset(a, 0, sizeof(a));       int len = strlen(s);       int cnt = 0;       int m;       scanf( %d , &m);       if (len % m == 0) {         int cur = len / m;         int sign = 1;         for (int i = 0; i < len; i += cur) {           for (int j = i, k = i + cur - 1; j < k; j++, k--) {             if (s[j] != s[k]) {               sign = 0;               break;             }           }           if (sign == 0) break;         }         if (sign) cnt = 1;       }       if (cnt)         printf( YES n );       else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, m;   string a, s;   int main() {     cin >> a >> s;     m = s.size();     sort(s.begin(), s.end());     for (m--; i < a.size(); i++) {       if (a[i] < s[m]) a[i] = s[m--];     }     cout << a;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string one, o, two;     vector<int> a(2, 0);     cin >> n;     cin >> one;     a[0] += 1;     while (n-- > 1) {       cin >> o;       if (o == one)         a[0] += 1;       else {         a[1] += 1;         two = o;       }     }     if (a[0] > a[1])       cout << one;     else       cout << two;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx )   const long double eps = 1e-12;   const long double Pi = acos(-1);   const long long md = 1e9 + 7;   using namespace std;   long long n, m, p[10100], f[10100], x, y;   pair<long long, long long> d[10100];   bool used[10100];   bool cmp(pair<long long, long long> a, pair<long long, long long> b) {     if (f[b.second] && f[a.second]) {       return a.first > b.first;     }     if (!f[b.second] && !f[a.second]) {       return a.first > b.first;     }     return f[a.second];   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> m;     for (long long i = 1; i <= 2 * n; i++) {       cin >> p[i];       d[i].first = p[i];       d[i].second = i;     }     for (long long i = 0; i < m; i++) {       cin >> x >> y;       f[x] = y;       f[y] = x;       d[x].first = p[x] - p[y];       d[y].first = p[y] - p[x];     }     sort(d + 1, d + 2 * n + 1, cmp);     long long t;     cin >> t;     long long cnt = 2 * n;     long long it = 1;     while (cnt) {       if (t == 2) {         cnt--;         cin >> x;         used[x] = true;         if (f[x]) {           cout << f[x] <<   n ;           used[f[x]] = true;           cnt--;           cout << flush;           ;         } else {           t = 3 - t;         }       } else {         for (; it <= 2 * n; it++) {           if (used[d[it].second]) continue;           cout << d[it].second <<   n ;           used[d[it].second] = true;           cout << flush;           ;           if (f[d[it].second]) {             cin >> x;             used[x] = true;             cnt--;             t = 3 - t;           }           break;         }         cnt--;         t = 3 - t;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 50, M1 = 998244353, M2 = 1e9 + 7;   struct ModInt {     int x1, x2;     ModInt(int a = 0, int b = 0) : x1(a), x2(b) {}   };   ModInt operator+(ModInt a, ModInt b) {     return ModInt((a.x1 + b.x1) % M1, (a.x2 + b.x2) % M2);   }   ModInt operator-(ModInt a, ModInt b) {     return ModInt((a.x1 - b.x1 + M1) % M1, (a.x2 - b.x2 + M2) % M2);   }   ModInt operator*(ModInt a, ModInt b) {     return ModInt(1ll * a.x1 * b.x1 % M1, 1ll * a.x2 * b.x2 % M2);   }   bool operator==(ModInt a, ModInt b) { return a.x1 == b.x1 && a.x2 == b.x2; }   int n, m, sz[N], B[2];   char s[N];   ModInt h[2][N], pw[N];   ModInt f(int l, int r) {     return h[l & 1][sz[r]] - h[l & 1][sz[l - 1]] * pw[sz[r] - sz[l - 1]];   }   int main(int argc, char *argv[]) {     scanf( %d%s , &n, s + 1);     pw[0] = ModInt(1, 1), B[0] = 213, B[1] = 233;     for (int i = 1; i <= (n); ++i) {       pw[i] = pw[i - 1] * ModInt(10007, 10007);       if (s[i] ==  0 ) {         ++m;         h[0][m] = h[0][m - 1] * pw[1] + ModInt(B[i & 1], B[i & 1]);         h[1][m] = h[1][m - 1] * pw[1] + ModInt(B[(i & 1) ^ 1], B[(i & 1) ^ 1]);       }       sz[i] = m;     }     int q;     scanf( %d , &q);     while (q--) {       int l1, l2, len;       scanf( %d%d%d , &l1, &l2, &len);       puts(f(l1, l1 + len - 1) == f(l2, l2 + len - 1) ?  Yes  :  No );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, k;     cin >> n >> k;     k--;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     int res = 0;     if (a[k] != 0) {       res++;       a[k] = 0;     }     for (int i = 0; i < n; i++) {       if (i == k) continue;       if (a[i] == 0) a[i] = n;     }     sort(a.begin(), a.end());     int gap = 0;     int ind = 0;     int prev = 0;     int te = n;     for (int i = 0; i < n; i++) {       while (ind < n && a[ind] <= i) {         ind++;         if (ind == n || a[ind] > i) break;         gap += max(0, a[ind] - a[ind - 1] - 1);       }       ind--;       int wrong = n - ind - 1;       te = min(te, max(wrong, gap));     }     if (n > 1) res += te;     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T checkmin(T &a, T b) {     return (a < b) ? a : a = b;   }   template <class T>   inline T checkmax(T &a, T b) {     return (a > b) ? a : a = b;   }   template <class T>   T GCD(T a, T b) {     if (a < 0) return GCD(-a, b);     if (b < 0) return GCD(a, -b);     return (a == 0) ? b : GCD(b % a, a);   }   template <class T>   T LCM(T a, T b) {     if (a < 0) return LCM(-a, b);     if (b < 0) return LCM(a, -b);     return (a == 0 || b == 0) ? 0 : a / GCD(a, b) * b;   }   template <class T>   inline T sqr(T X) {     return X * X;   }   namespace Poor {   const int MaxiN = 2005;   const int MaxiM = 2005;   const int MaxiS = 2005;   int N, M;   int Id[MaxiM];   pair<int, int> Opt[MaxiS][MaxiS];   string Base[MaxiN];   string St;   vector<int> List[MaxiN][26];   void Run() {     cin >> N;     for (int i = 0; i < N; ++i) cin >> Base[i];     cin >> M;     for (int i = 0; i < M; ++i) {       cin >> Id[i];       --Id[i];     }     cin >> St;     for (int i = 0; i < N; ++i)       for (int j = 0; j < (int)Base[i].size(); ++j)         List[i][Base[i][j] -  a ].push_back(j);     int Len = St.size();     for (int i = 0; i < Len + 1; ++i)       for (int j = 0; j < Len + 1; ++j) Opt[i][j] = make_pair(M, 0);     Opt[0][0] = make_pair(0, 0);     for (int i = 1; i <= Len; ++i) {       int t = St[i - 1] -  a ;       Opt[i][0] = make_pair(0, 0);       for (int j = 1; j <= i; ++j) {         Opt[i][j] = Opt[i - 1][j];         pair<int, int> Tmp = Opt[i - 1][j - 1];         while (Tmp < Opt[i][j]) {           vector<int>::iterator it =               lower_bound(List[Id[Tmp.first]][t].begin(),                           List[Id[Tmp.first]][t].end(), Tmp.second);           if (it != List[Id[Tmp.first]][t].end()) {             Tmp.second = *it + 1;             break;           }           ++Tmp.first;           Tmp.second = 0;         }         checkmin(Opt[i][j], Tmp);       }     }     for (int j = Len; j >= 0; --j)       if (Opt[Len][j] < make_pair(M, 0)) {         cout << j << endl;         break;       }   }   }  // namespace Poor   int main() {     ios::sync_with_stdio(false);     Poor::Run();     return 0;   }


// Problem: A. Dungeon   // Contest: Codeforces - Educational Codeforces Round 100 (Rated for Div. 2)   // URL: https://codeforces.com/problemset/problem/1463/A   // Memory Limit: 256 MB   // Time Limit: 2000 ms   //    // Powered by CP Editor (https://cpeditor.org)      #include<bits/stdc++.h>   using namespace std;   #pragma GCC optimize( O2 )   #define M 1000000007   #define ll long long int   #define pb push_back      #define pf push_front   #define all(x) x.begin(), x.end()   #define pob pop_back   #define pof pop_front   #define debug1(x) cout<<#x<<   <<x<<endl;   #define debug2(x,y) cout<<#x<<   <<x<<     <<#y<<   <<y<<endl;   #define debug3(x,y,z) cout<<#x<<   <<x<<     <<#y<<   <<y<<     <<#z<<   <<z<<endl;   #define present(c,x) ((c).find(x) != (c).end())   #define null NULL   #define mp make_pair   #define sz(x) (ll)x.size()   #define fi first   #define se second   #define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);   #define inf 1e18   //#define endl   n    //unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();   //shuffle (foo.begin(), foo.end(), std::default_random_engine(seed));   #define ordered_set tree<ll, null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>   typedef pair<int, int>  pii;   #define pi (3.14159265358979323846264338327950288)   template<typename T>   void printv(const T& t) {       std::copy(t.cbegin(), t.cend(), std::ostream_iterator<typename T::value_type>(std::cout,  ,  ));       cout<<endl;   }   ll modpower(ll a,ll b,ll c)   {    ll res=1;    while(b)    {     if(b&1LL)      res=(res*a)%c;     a=(a*a)%c;     b>>=1;    }    return res;   }   //-------------------------------Template--Above-----------------------------------------------   void solve(){    vector<ll>v(3);    for(ll i=0;i<3;i++)    cin>>v[i];    sort(all(v));    ll sum=v[0]+v[1]+v[2];    if(sum%9!=0){     cout<< NO <<endl;     return;    }    if(v[0]<sum/9){     cout<< NO <<endl;     return;    }    cout<< YES <<endl;       return;   }   int main()   {       boost       ll t;      // t=1;       cin>>t;       while(t--){           solve();       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   char ar[] =  1689 , s[1000010];   int val[10], ct[10];   int main() {     do {       val[atoi(ar) % 7] = atoi(ar);     } while (next_permutation(ar, ar + 4));     scanf( %s , s);     int len = strlen(s);     for (int i = 0; i < len; ++i) ct[s[i] -  0 ]++;     for (int i = 0; i < 4; ++i) ct[ar[i] -  0 ]--;     int rem = 0, div = 0;     for (int i = 1; i < 10; ++i) {       while (ct[i]--) {         printf( %d , i);         div = rem * 10 + i;         rem = div % 7;       }     }     rem *= 10000;     for (int i = 0; i < 7; ++i)       if (!((val[i] + rem) % 7)) {         printf( %d , val[i]);         while (ct[0]--) printf( 0 );         printf(  n );         return 0;       }     return 0;   }


#include <bits/stdc++.h>   const long long mod = 2147483647LL;   long long read() {     long long r = 0;     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) {       r = 10LL * r + (long long)c -  0 ;       c = getchar();     }     return r;   }   long long fast(long long a, long long b) {     long long r = 1LL;     while (b) {       if (b & 1) r = (r * a) % mod;       b >>= 1;       a = (a * a) % mod;     }     return r;   }   std::string str;   int a, b, c, T;   signed main() {     T = read();     while (T--) {       std::cin >> str;       a = 0;       b = 0;       c = 0;       for (int i = 0; i < str.size(); ++i) {         if (str[i] ==  A ) ++a;         if (str[i] ==  B ) ++b;         if (str[i] ==  C ) ++c;       }       if (b == a + c)         puts( YES );       else         puts( NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 500010;   const int INF = 0x3f3f3f3f;   const int iinf = 1 << 30;   const long long linf = 2e18;   const int MOD = 1000000007;   const double eps = 1e-7;   void print(int x) {     cout << x << endl;     exit(0);   }   void PRINT(string x) {     cout << x << endl;     exit(0);   }   void douout(double x) { printf( %lf n , x + 0.0000000001); }   int num[N], bit[N];   int n;   struct node {     int x, y, z;   } a[N];   bool cmp(node a, node b) { return a.y > b.y; }   void lsh() {     sort(num + 1, num + n + 1);     int t = unique(num + 1, num + n + 1) - (num + 1);     for (int i = (1); i <= (n); i++)       a[i].x = t - (lower_bound(num + 1, num + 1 + t, a[i].x) - (num + 1));   }   void add(int x, int y) {     for (; x < N; x += (x & -x)) bit[x] = max(bit[x], y);   }   int ask(int x) {     int ans = 0;     for (; x; x -= (x & -x)) ans = max(ans, bit[x]);     return ans;   }   signed main() {     scanf( %d , &n);     for (int i = (1); i <= (n); i++) scanf( %d , &a[i].x), num[i] = a[i].x;     for (int i = (1); i <= (n); i++) scanf( %d , &a[i].y);     for (int i = (1); i <= (n); i++) scanf( %d , &a[i].z);     lsh();     sort(a + 1, a + n + 1, cmp);     int ans = 0;     for (int i = 1, j; i <= n; i = j) {       for (j = i; j <= n && a[j].y == a[i].y; j++) {         int z = ask(a[j].x - 1);         if (z > a[j].z) ans++;       }       for (; i < j; i++) add(a[i].x, a[i].z);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 500;   int n, ret, cnt;   char a[maxn][maxn];   int arr[maxn][maxn];   pair<int, int> par[maxn][maxn];   multiset<pair<int, int> > s;   pair<int, int> root(pair<int, int> c) {     if (par[c.first][c.second].first < 0) return c;     return par[c.first][c.second] = root(par[c.first][c.second]);   }   void merge(pair<int, int> A, pair<int, int> B) {     if ((A = root(A)) == (B = root(B))) return;     if (par[A.first][A.second].first < par[B.first][B.second].first) swap(A, B);     par[B.first][B.second].first += par[A.first][A.second].first;     par[A.first][A.second] = B;   }   void add(pair<int, int> A) {     A = root(A);     if (arr[A.first][A.second] == 0) ret += -par[A.first][A.second].first;     arr[A.first][A.second]++;   }   void Add(pair<int, int> A) {     int i = A.first, j = A.second;     if (a[i][j] ==  X ) ret++;     if (a[i][j] !=  X ) add({i, j});     if (i - 1 >= 0 && a[i - 1][j] !=  X ) add({i - 1, j});     if (i + 1 < n && a[i + 1][j] !=  X ) add({i + 1, j});     if (j - 1 >= 0 && a[i][j - 1] !=  X ) add({i, j - 1});     if (j + 1 < n && a[i][j + 1] !=  X ) add({i, j + 1});   }   void rem(pair<int, int> A) {     A = root(A);     arr[A.first][A.second]--;     if (arr[A.first][A.second] == 0) ret -= -par[A.first][A.second].first;   }   void Rem(pair<int, int> A) {     int i = A.first, j = A.second;     if (a[i][j] ==  X ) ret--;     if (a[i][j] !=  X ) rem({i, j});     if (i - 1 >= 0 && a[i - 1][j] !=  X ) rem({i - 1, j});     if (i + 1 < n && a[i + 1][j] !=  X ) rem({i + 1, j});     if (j - 1 >= 0 && a[i][j - 1] !=  X ) rem({i, j - 1});     if (j + 1 < n && a[i][j + 1] !=  X ) rem({i, j + 1});   }   int main() {     ios_base::sync_with_stdio(false);     int K;     cin >> n >> K;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) cin >> a[i][j];     for (int i = 0; i < maxn; i++)       for (int j = 0; j < maxn; j++) par[i][j] = {-1, -1};     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (a[i][j] ==  . ) {           if (i + 1 < n && a[i + 1][j] ==  . ) merge({i, j}, {i + 1, j});           if (j + 1 < n && a[i][j + 1] ==  . ) merge({i, j}, {i, j + 1});         }     int ans = 0;     for (int i = K - 1; i < n; i++) {       memset(arr, 0, sizeof arr);       ret = 0;       for (int j = i - K + 1; j <= i; j++)         for (int k = 0; k < K; k++) {           Add({j, k});         }       ans = max(ans, ret);       for (int j = K; j < n; j++) {         for (int k = i - K + 1; k <= i; k++) Add({k, j});         for (int k = i - K + 1; k <= i; k++) Rem({k, j - K});         ans = max(ans, ret);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int T;     cin >> T;     while (T--) {       int n, k;       cin >> n >> k;       vector<int> a(n);       for (int i = 0; i < n; ++i) {         cin >> a[i];       }       if (n == 1) {         if (a[0] == k) {           cout <<  yes n ;         } else {           cout <<  no n ;         }         continue;       }       bool flag = false;       bool k_flag = false;       for (int i = 0; i < n; ++i) {         if (a[i] == k) {           k_flag = true;           break;         }       }       if (!k_flag) {         cout <<  no n ;         continue;       }       for (int i = 0; i < n; ++i) {         if (a[i] != k) {           continue;         }         if (i - 1 >= 0 && a[i - 1] >= k || i + 1 < n && a[i + 1] >= k) {           flag = true;           break;         }         if (i - 2 >= 0 && a[i - 2] >= k || i + 2 < n && a[i + 2] >= k) {           flag = true;           break;         }         if (flag) {           break;         }       }       for (int i = 0; i < n - 1; ++i) {         if (a[i] >= k && a[i + 1] >= k) {           flag = true;         }       }       for (int i = 0; i < n - 2; ++i) {         if (a[i] >= k && a[i + 2] >= k) {           flag = true;         }       }       if (flag) {         cout <<  yes n ;       } else {         cout <<  no n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, m;   int a[128], id = 1;   int main() {     cin >> t >> m;     for (int i = 0; i < t; ++i) {       string q;       cin >> q;       switch (q[0]) {         case  a : {           int k;           bool ok = false;           cin >> k;           for (int i = 0; i + k <= m; ++i) {             int j = 0;             for (j = 0; j < k && a[i + j] == 0; ++j)               ;             if (j == k) {               ok = true;               for (int j = 0; j < k; ++j) a[i + j] = id;               break;             }           }           if (ok)             cout << id++ << endl;           else             puts( NULL );           break;         }         case  e : {           bool ok = false;           int x;           cin >> x;           if (x > 0) {             for (int i = 0; i < m; ++i)               if (a[i] == x) ok = true, a[i] = 0;           }           if (!ok) puts( ILLEGAL_ERASE_ARGUMENT );           break;         }         case  d :           for (int i = remove(a, a + m, 0) - a; i < m; ++i) a[i] = 0;           break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void OUT_TST(string s, istream_iterator<string> it) { cerr << s; }   template <typename T, typename... Args>   void OUT_TST(string s, istream_iterator<string> it, T a, Args... args) {     cerr << *it <<  =  << a <<    ;     OUT_TST(s, ++it, args...);   }   template <class T>   void rd(T &ret) {     ret = 0;     bool ok = 0, u = 0;     for (;;) {       int c = getchar();       if (c >=  0  && c <=  9 )         ret = (ret << 3) + (ret << 1) + c -  0 , ok = 1;       else if (c ==  - )         u = 1;       else if (ok) {         if (u) ret *= -1;         return;       }     }   }   long long powmod(long long p, long long n, long long mod) {     long long ret = 1;     for (; n; n >>= 1) {       if (n & 1) ret = ret * p % mod;       p = p * p % mod;     }     return ret;   }   template <class T>   bool chmin(T &a, const T &b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool chmax(T &a, const T &b) {     return b > a ? a = b, 1 : 0;   }   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   bool ok(vector<pair<int, int> > &bn, vector<int> &pos, bool tmp) {     vector<pair<int, int> > an(4);     for (int i = (0); i < (4); i++) an[i] = bn[pos[i]];     if (tmp == 1) {       if (an[0].first != an[2].first) return 0;       if (an[0].second >= an[2].second) return 0;       if (an[1].second != an[3].second) return 0;       if (an[1].first <= an[3].first) return 0;       return 1;     }     return 1;     if (an[0].first != an[3].first) return 0;     if (an[0].second >= an[3].second) return 0;     if (an[1].second >= an[2].second) return 0;     return 1;   }   vector<pair<int, int> > gao(vector<pair<int, int> > an, bool tmp) {     vector<int> pos;     for (int i = (0); i < (4); i++) pos.push_back(i);     bool fg = 0;     if (ok(an, pos, tmp)) fg = 1;     while (!fg && next_permutation((pos).begin(), (pos).end())) {       if (ok(an, pos, tmp)) {         assert(fg == 0);         fg = 1;       }     }     vector<pair<int, int> > cn(4);     for (int i = (0); i < (4); i++) cn[i] = an[pos[i]];     return cn;   }   vector<pair<int, int> > an, bn;   int xlow, ylow, xup, yup;   bool ins(int first, int second) {     if (first >= xlow && first <= xup && second >= ylow && second <= yup)       return 1;     return 0;   }   int main() {     pair<int, int> t;     for (int i = (0); i < (4); i++) {       scanf( %d%d , &t.first, &t.second);       an.push_back(t);     }     for (int i = (0); i < (4); i++) {       scanf( %d%d , &t.first, &t.second);       bn.push_back(t);     }     an = gao(an, 0);     bn = gao(bn, 1);     xlow = INT_MAX, ylow = INT_MAX, xup = -INT_MAX, yup = -INT_MAX;     for (int i = (0); i < (4); i++) {       chmin(xlow, an[i].first);       chmax(xup, an[i].first);       chmin(ylow, an[i].second);       chmax(yup, an[i].second);     }     for (int i = (0); i < (4); i++) {       string _s =  an[i].x, an[i].y ;       replace(_s.begin(), _s.end(),  , ,    );       stringstream _ss(_s);       istream_iterator<string> _it(_ss);       OUT_TST(  , _it, an[i].first, an[i].second);     };     puts(  );     for (int i = (0); i < (4); i++) {       string _s =  bn[i].x, bn[i].y ;       replace(_s.begin(), _s.end(),  , ,    );       stringstream _ss(_s);       istream_iterator<string> _it(_ss);       OUT_TST(  , _it, bn[i].first, bn[i].second);     };     puts(  );     int l = bn[1].second, r = bn[1].second;     for (int i = (bn[3].first); i < (bn[1].first + 1); i++) {       for (int j = (l); j < (r + 1); j++)         if (ins(i, j)) {           puts( YES );           return 0;         }       if (i < bn[0].first)         --l, ++r;       else         ++l, --r;     }     puts( NO );     return 0;   }


#include <bits/stdc++.h>      using namespace std;   #define N 200020   int cnt, last[N], n, ans;   struct edge {       int to, next;   } e[N << 1];      inline void add(int u, int v) {       e[++cnt] = {v, last[u]}, last[u] = cnt;       e[++cnt] = {u, last[v]}, last[v] = cnt;   }      int dfs(int x, int fa) {       vector<pair<int, int> > q;       q.clear();       for (int i = last[x]; i; i = e[i].next) {           int y = e[i].to;           if (y == fa)continue;           q.push_back({dfs(y, x), y});       }       if (!q.size())return 0;       sort(q.begin(), q.end());       for (int i = 1; i < q.size(); ++i) {           ans = max(q[i - (x == 1)].first + 2, ans);       }       return q[(q.size() - 1) * (x == 1)].first + 1;   }      inline void solve() {       scanf( %d , &n);       for (int i = 1; i <= n; ++i)last[i] = 0;       cnt = 0;       for (int i = 1; i < n; ++i) {           int u, v;           scanf( %d%d , &u, &v);           add(u, v);       }       ans = 0;       ans = max(ans, dfs(1, 0));       printf( %d n , ans);   }      int main() {       int T = 1;       scanf( %d , &T);       for (int i = 1; i <= T; ++i)solve();   }


#include <bits/stdc++.h>   using namespace std;   int hag(int p, int t) {     int d;     d = max(3 * p / 10, p - ((p / 250) * t));     return d;   }   int main() {     int a, b, c, d;     cin >> a >> b >> c >> d;     if (hag(a, c) > hag(b, d)) cout <<  Misha ;     if (hag(a, c) == hag(b, d)) cout <<  Tie ;     if (hag(a, c) < hag(b, d)) cout <<  Vasya ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k, f, t, sum = -999999999, m, x, i;     cin >> n >> k;     for (i = 0; i < n; i++) {       cin >> f >> t;       if (k < t) {         m = f - (t - k);       } else {         m = f;       }       x = max(sum, m);       sum = x;     }     cout << x << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   unordered_map<string, int> ma;   int T, n, tot;   int a[1000010], b[1000010];   long long dp[1000010][2], ans;   struct node {     int per, to;   } e[1000010];   int head[1000010];   long long sum;   void addedge(int from, int to) {     e[++tot].to = to;     e[tot].per = head[from];     head[from] = tot;   }   void dfs(int u, int fa) {     dp[u][b[u]]++;     for (int i = head[u]; i > 0; i = e[i].per) {       int v = e[i].to;       if (v == fa) continue;       dfs(v, u);       sum += dp[v][0] * dp[u][1] + dp[v][1] * dp[u][0];       if (b[u] > 0) {         dp[u][0] += dp[v][1];         dp[u][1] += dp[v][0];       } else {         dp[u][0] += dp[v][0];         dp[u][1] += dp[v][1];       }     }     sum += b[u];   }   int main() {     T = 1;     while (T--) {       memset(head, -1, sizeof(head));       scanf( %d , &n);       for (int i = 1; i <= n; ++i) {         scanf( %d , &a[i]);       }       for (int i = 1; i < n; ++i) {         int u, v;         scanf( %d%d , &u, &v);         addedge(u, v);         addedge(v, u);       }       for (int i = 0; i <= 20; ++i) {         sum = 0;         for (int j = 1; j <= n; ++j) {           b[j] = (a[j] & (1 << i)) > 0;           dp[j][0] = dp[j][1] = 0;         }         dfs(1, -1);         ans += sum << i;       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   bitset<N> b;   int p[N];   int cnt[N];   bool was[N];   int main() {     int n, k;     scanf( %d %d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , p + i);       p[i]--;       was[i] = false;     }     for (int i = 1; i <= n; i++) {       cnt[i] = 0;     }     int c1 = 0, c2 = 0;     for (int i = 0; i < n; i++) {       if (was[i]) {         continue;       }       int x = i;       int len = 0;       while (!was[x]) {         was[x] = true;         x = p[x];         len++;       }       c1 += len % 2;       c2 += len / 2;       cnt[len]++;     }     b.set(n);     for (int i = 1; i <= n; i++) {       if (cnt[i] == 0) {         continue;       }       for (int j = 0; (1 << j) <= cnt[i]; j++) {         int x = i * (1 << j);         b |= (b >> x);         cnt[i] -= (1 << j);       }       b |= (b >> (i * cnt[i]));     }     int ans_min = k;     if (!b.test(n - k)) {       ans_min++;     }     int ans_max = 0;     ans_max += 2 * min(k, c2);     k -= min(k, c2);     ans_max += min(k, c1);     printf( %d %d n , ans_min, ans_max);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string c;     cin >> c;     string ans = regex_replace(c, regex( (/)+ ),  / );     if (ans[ans.size() - 1] ==  /  and ans.size() > 1) {       ans[ans.size() - 1] =    ;     }     cout << ans << endl;     ;   }


#include <bits/stdc++.h>   using namespace std;   const long long OO = 1e18;   vector<int> prs = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};   long long solve(long long num, int in, int lst) {     if (in == prs.size() || lst == 0) return num == 1 ? 1 : -1;     long long res = -1;     long long cur = 1;     long long cp = num;     for (int i = 0; i <= lst; i++) {       if (num < (i + 1) || cur > OO || (i && cur > OO / prs[in])) break;       if (i) cur *= prs[in];       if (num % (i + 1) != 0) continue;       long long can = solve(num / (i + 1), in + 1, i);       if ((res == -1 && can != -1) || (can != -1 && can < (res + cur - 1) / cur))         res = cur * can;     }     return res;   }   int main() {     long long n;     cin >> n;     cout << solve(n, 0, 100);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10, Q = 1e5 + 10;   int n, q;   struct edg {     int x, y, t;     bool operator==(edg a) { return x == a.x && y == a.y; }   } e[Q];   bool cmp(edg a, edg b) {     return a.x < b.x || (a.x == b.x && a.y < b.y) ||            (a.x == b.x && a.y == b.y && a.t < b.t);   }   class stk {    private:     int tp;     struct elm {       int x, y, rnk;     } e[Q << 2];       public:     void push(int x, int y, int rnk) {       e[++tp] = (elm){x, y, rnk};       return;     }     elm top() { return e[tp]; }     int size() { return tp; }     void pop() {       if (tp) tp--;       return;     }   } s;   class ufs {    private:     struct elm {       int fth, rnk;     } d[N << 1];       public:     void init() {       for (int i = 1; i <= (n << 1); i++) d[i].fth = i, d[i].rnk = 0;       return;     }     inline int find(int x) {       while (x != d[x].fth) x = d[x].fth;       return x;     }     bool check(int x, int y) { return find(x) == find(y); }     void unite(int x, int y) {       x = find(x), y = find(y);       if (x == y) return;       if (d[x].rnk < d[y].rnk) swap(x, y);       s.push(x, y, d[x].rnk == d[y].rnk);       d[y].fth = x;       d[x].rnk += d[x].rnk == d[y].rnk;       return;     }     void divide() {       int x = s.top().x, y = s.top().y;       d[y].fth = y;       d[x].rnk -= s.top().rnk;       s.pop();       return;     }   } u;   class sgt {    private:     struct elm {       int x, y;     };     vector<elm> v[Q << 2];       public:     void insert(int i, int l, int r, int lq, int rq, int x, int y) {       if (l > rq || r < lq) return;       if (l >= lq && r <= rq) {         v[i].push_back((elm){x, y});         return;       }       int mid = l + r >> 1;       insert(i << 1, l, mid, lq, rq, x, y);       insert(i << 1 | 1, mid + 1, r, lq, rq, x, y);       return;     }     void query(int i, int l, int r) {       int sz = s.size();       bool flag = true;       for (int j = 0; j < v[i].size() && flag; j++) {         int x = v[i][j].x, y = v[i][j].y;         if (u.check(x, y))           flag = false;         else           u.unite(x, y + n), u.unite(x + n, y);       }       if (flag) {         if (l == r)           puts( YES );         else {           int mid = l + r >> 1;           query(i << 1, l, mid);           query(i << 1 | 1, mid + 1, r);         }       } else         for (int i = l; i <= r; i++) puts( NO );       while (s.size() > sz) u.divide();       return;     }   } t;   inline int rd() {     int f = 1, x = 0;     char c = getchar();     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) f = -1;     for (; c >=  0  && c <=  9 ; c = getchar()) x = (x << 3) + (x << 1) + c -  0 ;     return f * x;   }   int main() {     n = rd(), q = rd();     u.init();     for (int i = 1; i <= q; i++) e[i].x = rd(), e[i].y = rd(), e[i].t = i;     sort(e + 1, e + 1 + q, cmp);     for (int i = 1; i <= q; i++) {       if (e[i] == e[i + 1])         t.insert(1, 1, q, e[i].t, e[i + 1].t - 1, e[i].x, e[i].y), i++;       else         t.insert(1, 1, q, e[i].t, q, e[i].x, e[i].y);     }     t.query(1, 1, q);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   const long long mo = 1e9 + 7;   const long long inf = 1e9;   const long long Inf = 1e18;   long long w[N], a[N];   int x[N], y[N];   int main() {     int n, m, k;     scanf( %d%d%d , &n, &k, &m);     for (int i = (1); i <= (n); ++i) scanf( %lld , &w[i]);     sort(w + 1, w + n + 1);     for (int i = (1); i <= (m); ++i) w[i] += w[i - 1], a[i] = w[i];     for (int i = (1); i <= (k); ++i) scanf( %d%d , &x[i], &y[i]);     for (int i = (1); i <= (m); ++i)       for (int j = (1); j <= (k); ++j)         if (x[j] <= i) a[i] = min(a[i - x[j]] + w[i] - w[i - x[j] + y[j]], a[i]);     printf( %lld n , a[m]);   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll LINF = 1001002003004005006ll;   int dx[] = {1, 0, -1, 0};   int dy[] = {0, 1, 0, -1};   ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }   template <class T>   bool chmax(T &a, const T &b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool chmin(T &a, const T &b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   void solve() {     ll n, m;     cin >> n >> m;     vector<tuple<ll, ll, ll>> v(n);     for (int i = 0; i < n; i++) {       ll t, l, h;       cin >> t >> l >> h;       v[i] = make_tuple(t, l, h);     }     sort(v.begin(), v.end());     ll L = m, H = m, T = 0;     for (int i = 0; i < n; i++) {       ll now = get<0>(v[i]), l = get<1>(v[i]), h = get<2>(v[i]);       L = L - (now - T);       H = H + (now - T);       if (h < L or H < l) {         cout <<  NO  << endl;         return;       }       chmax(L, l);       chmin(H, h);       T = now;     }     cout <<  YES  << endl;     return;   }   signed main() {     cin.tie(0);     ios::sync_with_stdio(0);     int q;     cin >> q;     while (q--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int solve(int x) {     int sum = 0;     while (x >= 5) {       sum += x / 5;       x /= 5;     }     return sum;   }   int main() {     int m;     cin >> m;     int k = 0;     vector<long long> vec;     for (int i = 1; i <= 1000000; i++) {       long long sum = solve(i);       if (sum == m) {         k++;         vec.push_back(i);       } else if (sum > m)         break;     }     cout << k << endl;     for (int i = 0; i < k; i++) cout << vec[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:64000000 )   using namespace std;   const int INF = (int)1E9;   const long long INF64 = (long long)1E18;   const long double EPS = 1E-8;   const long double PI = 3.1415926535897932384626433832795;   const int MAXN = 5200;   const int MAXF = 1001000;   long long d1[MAXN], d[MAXN], D[MAXN][MAXN], p;   long long f[MAXF], a[MAXF];   vector<long long> l;   int n, m;   long long get(int n, int c) {     if (n == 0 && c == 0) return 1;     if (n == 0 || c == 0) return 0;     long long &ans = D[n][c];     if (ans != -1) return ans;     ans = (get(n - 1, c - 1) + get(n - 1, c) * (c - 1)) % p;     return ans;   }   int main() {     cin >> n >> m >> p;     f[0] = a[0] = 1;     for (int i = 1; i < MAXF; i++) {       f[i] = (f[i - 1] * i) % p;       a[i] = (a[i - 1] * (m - i + 1)) % p;     }     int prev = -1;     long long sum = 0;     memset(D, 255, sizeof D);     for (int step = 0; step < (int)(n); step++) {       int l;       scanf( %d , &l);       for (int i = 1; i <= l; i++)         if (prev == -1) {           long long cur = get(l, i) % p;           cur = (cur * a[i]) % p;           d1[i] = cur;         } else {           long long cur = get(l, i) % p;           cur = (cur * a[i]) % p;           cur = (cur * sum) % p;           long long ppp = 0;           if (i <= prev) {             ppp = get(l, i) % p;             ppp = (ppp * f[i]) % p;             ppp = (ppp * d[i]) % p;           }           d1[i] = (cur - ppp + p) % p;         }       sum = 0;       for (int i = 0; i < (int)(l + 1); i++) {         sum = (sum + d1[i]) % p;         d[i] = d1[i];       }       prev = l;     }     long long ans = 0;     for (int i = 0; i < (int)(prev + 1); i++) ans = (ans + d[i]) % p;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e5 + 10;   const int M = 20;   vector<int> soln[M][M];   int compute(vector<int> sha) {     vector<int> sz(sha.size(), 1);     vector<int> out[sha.size()];     for (int i = sha.size() - 1; i > 0; i--) {       sz[sha[i]] += sz[i];       out[sha[i]].push_back(i);     }     int l1, l2;     int bb = 0;     for (int i = 0; i < sha.size(); i++) {       if (out[i].size() == 2) {         l1 = sz[out[i][0]];         l2 = sz[out[i][1]];         if (l1 > l2) swap(l1, l2);         if (l1 * 2 <= l2) {           bb++;         }       }     }     return bb;   }   void brute(int cid, vector<int> pp) {     if (cid == pp.size()) {       int bal = compute(pp);       soln[pp.size()][bal] = pp;       return;     }     brute(cid + 1, pp);     if (pp.size() + 2 < M) {       pp.push_back(cid);       pp.push_back(cid);       brute(cid + 1, pp);     }   }   bool ish(int n) {     if ((n & (n + 1)) == 0) {       return true;     }     return false;   }   int res[N];   bool valid(int n, int s1, int s2) {     if (s1 > s2) swap(s1, s2);     if (ish(s1) && ish(s2)) return false;     int cn = !ish(s1) + !ish(s2) + (s1 * 2 <= s2);     if (cn > 1) return false;     return true;   }   int cnt = 1;   void bins(int n, int c) {     int root = cnt;     res[cnt] = c;     cnt++;     if (n == 1) {       return;     }     bins(n / 2, root);     bins(n / 2, root);   }   void solve1(int n, int c) {     int root = cnt;     cnt++;     res[root] = c;     int k = 1;     while ((k * 2 - 1) < n) {       k *= 2;     }     int sz1 = (k - 1);     int sz2 = (n - 1 - sz1);     if (!valid(n, sz1, sz2)) {       k /= 2;       sz1 = k - 1;       sz2 = (n - 1 - sz1);     }     if (ish(sz1))       bins(sz1, root);     else       solve1(sz1, root);     if (ish(sz2))       bins(sz2, root);     else       solve1(sz2, root);   }   void extend(vector<int> pp, int c) {     res[cnt] = c;     for (int i = 1; i < pp.size(); i++) {       res[cnt + i] = pp[i] + cnt;     }     cnt += pp.size();   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout.tie(0);     ;     int n, k;     cin >> n >> k;     if (n % 2 == 0) {       cout <<  NO n ;       return 0;     }     if (k > max((n - 3) / 2, 0)) {       cout <<  NO n ;       return 0;     }     brute(0, {-1});     int par = 0;     while (n > M && k > 1) {       if (k == 2) {         if (!ish(n - 2)) {           n -= 2;           res[cnt + 1] = cnt;           res[cnt + 2] = cnt;           par = cnt;           cnt += 2;         } else {           n -= 4;           res[cnt + 1] = cnt;           res[cnt + 2] = cnt + 1;           res[cnt + 3] = cnt + 1;           res[cnt + 4] = cnt;           par = cnt;           cnt += 4;         }       } else {         n -= 2;         res[cnt + 1] = cnt;         res[cnt + 2] = cnt;         par = cnt;         cnt += 2;       }       k--;     }     if (k == 0) {       if (!ish(n)) {         cout <<  NO n ;         return 0;       }       bins(n, par);     } else if (k == 1) {       if (ish(n)) {         cout <<  NO n ;         return 0;       }       solve1(n, par);     } else {       if (soln[n][k].empty()) {         cout <<  NO n ;         return 0;       }       extend(soln[n][k], par);     }     cout <<  YES n ;     for (int i = 1; i < cnt; i++) {       cout << res[i] <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string op;     int x = 0;     for (int k = 0; k < n; k++) {       cin >> op;       if (op ==  ++X  || op ==  X++ ) {         x++;       } else if (op ==  --X  || op ==  X-- ) {         x--;       }     }     cout << x << endl;   }


#include <bits/stdc++.h>   using namespace std;   bool isprime(long long k) {     for (long long i = 2; i <= sqrt(k); i++)       if (k % i == 0) return false;     return true;   }   long long bm(long long a, long long b, long long mod) {     if (b == 0) return 1;     long long t = bm(a, b / 2, mod);     t = t * t % mod;     return (b % 2 == 1 ? t * a % mod : t);   }   long long inv(long long a, long long mod) { return bm(a, mod - 2, mod); }   void gay(long long TC) { cout <<  Case #  << TC <<  :  ; }   void solve(long long TC) {     string s;     cin >> s;     long long n = s.length();     if (n % 2) {       cout <<  NO n ;       return;     }     if (s.substr(0, n / 2) != s.substr(n / 2, n / 2)) {       cout <<  NO n ;     } else       cout <<  YES n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     for (long long i = 1; i <= t; i++) solve(i);     return 0;   }


#include <bits/stdc++.h>   int aa[100005];   int main(void) {     int n;     while (~scanf( %d , &n)) {       for (int i = 0; i < n; i++) {         scanf( %d , &aa[i]);       }       for (int i = 0; i < n - 1; i++) {         printf( %d  , aa[i] + aa[i + 1]);       }       printf( %d n , aa[n - 1]);     }   }


#include <bits/stdc++.h>   using namespace std;   static const int maxn = 3e5 + 5;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int n;     cin >> n;     multiset<int> ms;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       ms.insert(x);     }     int ans = 0;     while (ms.empty() == false) {       int mini = *ms.begin();       ++ans;       vector<int> del;       for (int x : ms) {         if (x % mini == 0) del.push_back(x);       }       for (int x : del) ms.erase(ms.find(x));     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   int vis[200005];   int comp_size;   int cycle_length;   void dfs(int cur, int prev, int t, vector<vector<int>> &edges) {     vis[cur] = t;     comp_size++;     for (int e : edges[cur]) {       if (vis[e] == -1) {         dfs(e, cur, t + 1, edges);       } else if (e != prev) {         if (cycle_length == 0) cycle_length = t - vis[e] + 1;       }     }   }   long long mod_exp(int a, int b) {     if (b == 0) {       return 1;     } else if (b == 1) {       return a;     }     long long c;     if (b % 2 == 0) {       c = mod_exp(a, b / 2);       c = c * c % MOD;     } else {       c = mod_exp(a, (b - 1) / 2);       c = c * c * a % MOD;     }     return c;   }   int main() {     int n;     memset(vis, -1, sizeof vis);     cin >> n;     vector<vector<int>> edges(n);     for (int i = 0; i < n; i++) {       int a;       cin >> a;       a--;       edges[i].push_back(a);       edges[a].push_back(i);     }     long long ans = 1;     for (int i = 0; i < n; i++) {       if (vis[i] == -1) {         comp_size = 0;         cycle_length = 0;         dfs(i, -1, 1, edges);         cycle_length = cycle_length == 0 ? 2 : cycle_length;         ans = (ans * mod_exp(2, comp_size - cycle_length) % MOD) *               (mod_exp(2, cycle_length) - 2) % MOD;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long pw[16], t[20], na[30], ma[30], ta[30], per[30];   vector<long long> rem;   void calc_pw() {     long long i;     pw[0] = 1;     for (i = 1; i <= 11; i++) pw[i] = 7 * pw[i - 1];   }   long long conv(long long num) {     long long ret = 0, temp;     temp = num;     while (temp > 0) {       t[ret++] = temp % 7;       temp /= 7;     }     return ret;   }   int main() {     long long i, j, n, m, temp, mx_n, mx_m, cur, ans = 0, idx, k, x, t1 = 0,                                                  t2 = 0;     cin >> n >> m;     calc_pw();     for (i = 0; i < 7; i++) rem.push_back(i);     mx_n = max(1LL, conv(n - 1));     mx_m = max(1LL, conv(m - 1));     for (k = 0; k < (1 << rem.size()); k++) {       temp = 0;       for (x = 0; x < rem.size(); x++)         if (k & (1 << x)) temp++;       if (temp == mx_m + mx_n && temp > 0) {         idx = 0;         for (j = 0; j < rem.size(); j++)           if (k & (1 << j)) per[idx++] = rem[j];         do {           idx = 0;           t1 = 0;           t2 = 0;           for (j = mx_m - 1; j >= 0; j--) t1 += pw[j] * per[j];           for (j = mx_m; j < mx_m + mx_n; j++) t2 += pw[idx++] * per[j];           if (t1 < m && t2 < n && (t1 != 0 || t2 != 0)) ans++;         } while (next_permutation(per, per + mx_m + mx_n));       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       long long x1, y1, x2, y2;       cin >> x1 >> y1 >> x2 >> y2;       if (x1 == x2) {         cout << abs(y1 - y2) << endl;       } else if (y1 == y2) {         cout << abs(x1 - x2) << endl;       } else         cout << abs(x1 - x2) + abs(y1 - y2) + 2 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n, s;       cin >> n >> s;       long long cnt = 0, x = n;       while (x) {         cnt += x % 10;         x /= 10;       }       long long ans = 0, now = 1;       while (1) {         if (cnt <= s) {           cout << ans << endl;           break;         }         long long p = n % 10;         if (!p) p = 10;         ans += (10 - p) * now;         n += 10 - p;         n /= 10;         x = n;         cnt = 0;         while (x) {           cnt += x % 10;           x /= 10;         }         now *= 10;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, count = 0;     cin >> n;     for (int i = 0; i < n; i++) {       int x;       scanf( %1d , &x);       if (x) {         count++;         continue;       }       break;     }     cout << min(count + 1, n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, x, y;   int work() {     int ans = 0;     int b = x % m;     if (b == 0) b = m;     int a = x / m + (b != m);     int d = y % m;     if (d == 0) d = m;     int c = y / m + (d != m);     if (a == c) return 1;     if (b == 1 && (d == m || y == n)) return 1;     if (x == 1) {       if (c == 1) return 1;       if (d == m) return 1;       if (y == n) return 1;       return 2;     }     if (a + 1 == c) return 2;     if (d + 1 == b) return 2;     if (b == 1) return 2;     if (d == m) return 2;     if (y == n) return 2;     return 3;   }   int main() {     while (cin >> n >> m >> x >> y) printf( %d , work());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100000 + 10;   map<long long, long long> mp;   int main() {     long long n, k, p, x, ans = 0;     scanf( %lld%lld%lld , &n, &p, &k);     for (long long i = 0; i < n; ++i) {       scanf( %lld , &x);       mp[((x * x % p * x % p * x % p - x * k % p) % p + p) % p]++;     }     for (auto e : mp) {       x = e.second;       ans += x * (x - 1) / 2;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 30;   int main() {     int n, m;     scanf( %d%d , &n, &m);     int maxc = 0;     for (int i = 0; i < n; i++) {       int minc = INF;       for (int j = 0; j < m; j++) {         int cij;         scanf( %d , &cij);         if (minc > cij) minc = cij;       }       if (maxc < minc) maxc = minc;     }     printf( %d n , maxc);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long gcd(long long a, long long b) {     a = ((a) < 0 ? -(a) : (a));     b = ((b) < 0 ? -(b) : (b));     while (b) {       a = a % b;       swap(a, b);     }     return a;   }   const long long inf = 2147383647;   const long long mod = 1000000007;   const double pi = 2 * acos(0.0);   const double eps = 1e-9;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int main() {     int t;     cin >> t;     int x, y, z, a, b, c, ans;     for (int kas = 1; kas <= t; kas++) {       scanf( %d , &x);       scanf( %d , &y);       scanf( %d , &z);       a = min(x, y);       b = max(x, y);       c = b - a;       if (z <= a) {         ans = (x + y + z) / 3;         ans = min(ans, a);       } else         ans = a;       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  9  || s[i] ==  H  || s[i] ==  Q ) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;   }


#include <bits/stdc++.h>   int Pos(int a) {     if (a < 0) {       return 0;     }     return a;   }   int main() {     int n = 0, p1 = 0, t1 = 0, p2 = 0, t2 = 0, p3 = 0;     int energy = 0;     std::vector<int> timeDatal;     std::vector<int> timeDatar;     std::cin >> n >> p1 >> p2 >> p3 >> t1 >> t2;     for (int i = 0; i < n; i++) {       int input;       std::cin >> input;       timeDatal.push_back(input);       std::cin >> input;       timeDatar.push_back(input);       energy += p1 * (timeDatar[i] - timeDatal[i]);       if (i != 0) {         int delta = timeDatal[i] - timeDatar[i - 1];         if (delta - t1 >= 0) {           energy += t1 * p1;         } else if (delta >= 0) {           energy += delta * p1;         }         delta -= t1;         if (delta - t2 >= 0) {           energy += t2 * p2;         } else if (delta >= 0) {           energy += delta * p2;         }         delta -= t2;         if (delta > 0) {           energy += p3 * delta;         }       }     }     std::cout << energy;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010, mod = 998244353;   inline int read() {     int x = 0, f = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) f |= ch ==  - , ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return f ? -x : x;   }   int n, fa[maxn], dep[maxn], last = 1, chg, ans[maxn], al, seq[maxn], sl;   set<int> s[maxn];   int main() {     n = read();     for (int i = (2); i <= (n); i++) {       dep[i] = dep[fa[i] = read() + 1] + 1;       s[fa[i]].insert(i);       if (dep[i] > dep[last]) last = i;     }     chg = last;     while (chg != 1) {       while (chg != 1 && s[fa[chg]].size() == 1) chg = fa[chg];       if (chg != 1) {         int was = fa[chg];         set<int>::iterator hhh = s[was].find(chg);         for (set<int>::iterator it = s[was].begin(); it != s[was].end(); it++) {           int f = *it;           if (f == chg) continue;           s[f].insert(chg);           fa[chg] = f;           ans[++al] = chg - 1;           s[was].erase(hhh);           break;         }       }     }     for (int i = last; i; i = fa[i]) seq[++sl] = i - 1;     for (int i = (n); i >= (1); i--) printf( %d  , seq[i]);     printf(  n%d n , al);     for (int i = (al); i >= (1); i--) printf( %d  , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   void solve() {     int n, k;     cin >> n >> k;     vector<int> a(n * k);     for (auto &it : a) cin >> it;     reverse(a.begin(), a.end());     long long ans = 0;     int mid = n / 2, cnt = 0;     for (int i = mid; i < (int)a.size() && cnt++ != k; i += mid + 1) {       ans += a[i];     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 101111, maxm = 5011, inf = 2147000000;   struct orz {     int d, num;   } a[maxn];   int n, v, ans;   bool cmp(orz x, orz y) { return (x.d < y.d); }   int main() {     scanf( %d%d , &n, &v);     int i, j, x, y;     for (i = 1; i <= n; i++) scanf( %d%d , &a[i].d, &a[i].num);     sort(a + 1, a + n + 1, cmp);     x = 1;     for (i = 2; i <= n; i++)       if (a[i].d == a[x].d)         a[x].num += a[i].num;       else         a[++x] = a[i];     n = x;     a[0].d = -10;     int res;     int now = 1;     a[n + 1].d = -1;     for (i = 1; i <= 3100; i++) {       while (a[now].d < i - 1 && now < n) now++;       res = v;       if (a[now].d == i - 1 || a[now].d == i) {         if (a[now].num <= res) {           res -= a[now].num;           a[now].num = 0;         } else {           a[now].num -= res;           res = 0;         }       }       if (a[now].d == i - 1 && res) {         now++;         if (a[now].d == i) {           if (a[now].num <= res) {             res -= a[now].num;             a[now].num = 0;           } else {             a[now].num -= res;             res = 0;           }         }       }       ans += v - res;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MXN = 1e2 * 2;   const int TMXN = 1048576;   const long long INF = 1e9 + 7;   const long long INFL = 1e18;   struct query {     int l, r, id;   };   int n;   int a[TMXN];   long long ans[TMXN];   long long res;   int cnt[TMXN];   int m, k;   query q[TMXN];   bool cmp(query a, query b) {     if (a.l / 447 != b.l / 447) return (a.l / 447 < b.l / 447);     return a.r < b.r;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i <= m; i++) {       scanf( %d%d , &q[i].l, &q[i].r);       q[i].l;       q[i].id = i;     }     int L = 0, R = -1;     sort(q + 1, q + m + 1, cmp);     for (int i = 1; i <= m; i++) {       while (q[i].r > R) {         R++;         res += (((cnt[a[R]] + 1) * (cnt[a[R]] + 1) * a[R])) -                ((cnt[a[R]] * cnt[a[R]]) * a[R]);         cnt[a[R]]++;       }       while (q[i].l < L) {         L--;         res += (((cnt[a[L]] + 1) * (cnt[a[L]] + 1) * a[L])) -                ((cnt[a[L]] * cnt[a[L]]) * a[L]);         cnt[a[L]]++;       }       while (q[i].r < R) {         res -= ((cnt[a[R]] * cnt[a[R]]) * a[R]) -                (((cnt[a[R]] - 1) * (cnt[a[R]] - 1) * a[R]));         cnt[a[R]]--;         R--;       }       while (q[i].l > L) {         res -= ((cnt[a[L]] * cnt[a[L]]) * a[L]) -                (((cnt[a[L]] - 1) * (cnt[a[L]] - 1) * a[L]));         cnt[a[L]]--;         L++;       }       ans[q[i].id] = res;     }     for (int i = 1; i <= m; i++) printf( %I64d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   int main(void) {     int a, s, d;     long long x, y;     scanf( %d%d%d , &a, &s, &d);     x = a / d;     y = s / d;     if (x * d < a) x++;     if (y * d < s) y++;     printf( %lld , x * y);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, a, b, c, res = LONG_LONG_MAX;   int main() {     cin >> n >> a >> b >> c;     if (n % 4 == 0) return puts( 0 );     if (n % 4 == 1) {       res = min(res, a * 3);       res = min(res, a + b);       res = min(res, c);     } else if (n % 4 == 2) {       res = min(res, a * 2);       res = min(res, b);       res = min(res, c * 2);     } else {       res = min(res, a);       res = min(res, b + c);       res = min(res, c * 3);     }     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   vector<int> v[N];   vector<pair<int, int> > ans;   int deg[N], maxT;   void dfs(int x, int T, int u) {     ans.push_back({x, T});     int beginT = T;     for (auto it : v[x])       if (it != u) {         if (T == maxT) {           T = maxT - deg[x];           ans.push_back({x, T});         }         dfs(it, T + 1, x);         ans.push_back({x, ++T});       }     if (T >= beginT) ans.push_back({x, beginT - 1});   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);       deg[x]++;       deg[y]++;     }     for (int i = 1; i <= n; i++) maxT = max(maxT, deg[i]);     dfs(1, 0, 0);     ans.pop_back();     cout << ans.size() <<   n ;     for (auto it : ans) cout << it.first <<     << it.second <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   using lint = long long;   const lint linf = 1e18 + 7;   const lint inf = 1e9 + 7;   const int MOD = 1000000007;   void press(vector<long long>& x) {     map<int, int> memo;     int n = x.size();     for (int i = 0; i < n; ++i) {       memo[x[i]] += 1;     }     int cur = 1;     for (auto& val : memo) {       val.second = cur;       ++cur;     }     for (int i = 0; i < n; ++i) {       x[i] = memo[x[i]];     }   }   void solve() {     int n;     cin >> n;     vector<lint> a(n, 0);     for (int i = 0; i < n; ++i) cin >> a[i];     auto b = a;     press(b);     vector<vector<int>> dp(n + 5, vector<int>(3, 0));     vector<int> cnt(n + 5, 0);     for (int i = 0; i < n; ++i) cnt[b[i]] += 1;     int res = n - 1;     for (int i = 0; i < n; ++i) {       if (dp[b[i]][0] == 0) {         dp[b[i]][0] = max(dp[b[i] - 1][1], dp[b[i] - 1][2]) + 1;       }       if (dp[b[i]][1] + 1 < cnt[b[i]]) {         ++dp[b[i]][1];       } else {         dp[b[i]][2] = dp[b[i]][0] + dp[b[i]][1];         dp[b[i]][1] += 1;       }       int hoge = dp[b[i]][1] + cnt[b[i] + 1] - dp[b[i] + 1][1];       res = min(res, n - hoge);       hoge = cnt[b[i]] - dp[b[i]][1] + dp[b[i] - 1][2] + 1;       res = min(res, n - hoge);     }     for (int i = 1; i <= n; ++i) {       for (int j = 0; j < 3; ++j) {         res = min(res, n - dp[i][j]);       }     }     cout << res <<   n ;   }   signed main() {     cin.tie(0);     ios::sync_with_stdio(false);     int t;     cin >> t;     for (int i = 0; i < t; ++i) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 9;   struct edge {     int to, nxt;   } e[N * 2];   int hd[N], tot;   void add(int u, int v) {     e[++tot] = (edge){v, hd[u]};     hd[u] = tot;   }   int n, sz[N], msz[N];   void pre(int u, int fa) {     for (int i = hd[u], v; i; i = e[i].nxt)       if ((v = e[i].to) != fa) {         pre(v, u);         sz[u] += sz[v];         if (sz[v] > sz[msz[u]]) msz[u] = v;       }     sz[u]++;   }   int f[N][2], mx[N];   void dfs1(int u, int fa) {     for (int i = hd[u], v; i; i = e[i].nxt)       if ((v = e[i].to) != fa) {         dfs1(v, u);         int tmp = (sz[v] > n / 2 ? f[v][0] : sz[v]);         if (tmp > f[u][0])           f[u][1] = f[u][0], f[u][0] = tmp, mx[u] = v;         else if (tmp > f[u][1])           f[u][1] = tmp;       }   }   int g[N];   void dfs2(int u, int fa) {     for (int i = hd[u], v; i; i = e[i].nxt)       if ((v = e[i].to) != fa) {         int tmp = (n - sz[v] > n / 2 ? g[u] : n - sz[v]);         g[v] = max(g[v], tmp);         if (v == mx[u])           g[v] = max(g[v], f[u][1]);         else           g[v] = max(g[v], f[u][0]);         dfs2(v, u);       }   }   int main() {     scanf( %d , &n);     for (int i = 1, u, v; i < n; i++) scanf( %d%d , &u, &v), add(u, v), add(v, u);     pre(1, 0), dfs1(1, 0), dfs2(1, 0);     for (int i = 1; i <= n; i++) {       bool centroid = 1;       if (sz[msz[i]] > n / 2)         centroid = (sz[msz[i]] - f[i][0] <= n / 2);       else if (n - sz[i] > n / 2)         centroid = (n - sz[i] - g[i] <= n / 2);       cout << centroid <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   template <typename T>   inline T range(T l, T r) {     return uniform_int_distribution<T>(l, r)(rng);   }   inline void setin(string s) { freopen(s.c_str(),  r , stdin); }   inline void setout(string s) { freopen(s.c_str(),  w , stdout); }   template <typename T>   void Min(T &a, T b) {     a = min(a, b);   }   template <typename T>   void Max(T &a, T b) {     a = max(a, b);   }   const int mod = 998244353;   const int inf = 0x3f3f3f3f;   const int N = 1e6 + 15;   int n;   vector<int> g[N];   int cnt[N], cl[N];   void dfs(int v, int p = -1) {     cnt[cl[v]]++;     for (int to : g[v]) {       if (to != p) {         cl[to] = cl[v] ^ 1;         dfs(to, v);       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     cin >> n;     for (int i = 1; i < n; ++i) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     dfs(1);     cout << min(cnt[0], cnt[1]) - 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long max(long long a, long long b) {     if (a > b)       return a;     else       return b;   }   long long min(long long a, long long b) {     if (a < b)       return a;     else       return b;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   int n, m, len1 = 1, len2 = 1, ans;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int a = 7; a < n; a *= 7) len1 += 1;     for (int b = 7; b < m; b *= 7) len2 += 1;     if (len1 + len2 <= 7) {       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) {           vector<int> used(7, 0);           for (int a = i, k = 0; k < len1; a /= 7, k++) used[a % 7] += 1;           for (int b = j, k = 0; k < len2; b /= 7, k++) used[b % 7] += 1;           if (*max_element(used.begin(), used.end()) <= 1) ans++;         }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char n[1000 + 2];   char m[1000 + 2];   int color_n[30];   int color_m[30];   int main() {     while (scanf( %s , n) != EOF) {       scanf( %s , m);       memset(color_n, 0, sizeof(color_n));       memset(color_m, 0, sizeof(color_m));       for (int i = 0; i < strlen(n); i++) color_n[n[i] -  a ]++;       for (int j = 0; j < strlen(m); j++) color_m[m[j] -  a ]++;       int ans = 0;       int flag = 1;       for (int i = 0; i < 30; i++) {         ans += min(color_n[i], color_m[i]);         if (color_m[i] && color_n[i] == 0) flag = 0;       }       if (ans == 0 || flag == 0)         printf( -1 n );       else         printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int N, X, sum = 0;     std::cin >> N >> X;     for (int i = 0; i < N; i++) {       int tmp;       std::cin >> tmp;       sum += tmp;     }     if (sum + N - 1 == X)       std::cout <<  YES n ;     else       std::cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200000 + 10;   inline long long rd() {     long long x = 0, w = 1;     char ch = 0;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 3) + (x << 1) + (ch ^ 48);       ch = getchar();     }     return x * w;   }   int to[N], nt[N], hd[N], tot = 1;   inline void add(int x, int y) {     ++tot, to[tot] = y, nt[tot] = hd[x], hd[x] = tot;   }   int n, m, k, a[N], len[N], ans;   int st[N], tt = -1;   inline void dfs(int x) {     ++tt, st[tt] = st[tt - 1] + len[x];     ans = max(ans, st[tt] - st[max(0, tt - m)]);     if (tt < m)       for (int i = hd[x]; i; i = nt[i]) dfs(to[i]);     --tt;   }   int main() {     n = rd(), m = rd(), k = rd();     for (int i = 1; i <= n; i++) a[i] = rd();     for (int i = 1, su = a[1], j = 1; i <= n; i++) {       while (j < n && su + a[j + 1] <= k) su += a[++j];       len[i] = j - i + 1, add(j + 1, i), su -= a[i];     }     dfs(n + 1);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[1010];   int sum = 0;   int cnt = 0;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       sum += a[i];     }     for (int i = 0; i < n; i++) {       if ((sum % 2) == (a[i] % 2)) {         cnt++;       }     }     printf( %d n , cnt);   }


#include <bits/stdc++.h>   using namespace std;   istream& in = cin;   int n;   int a[1000010];   void input() {     in >> n;     for (int i = 1; i <= n; ++i) in >> a[i];   }   long long mod = (long long)1e9 + 7;   long long fac[1000010], inv[1000010];   long long quick_mod(long long a, long long p) {     long long ret = 1;     a %= mod;     while (p) {       if (p & 1) ret = ret * a % mod;       a = a * a % mod;       p /= 2;     }     return ret;   }   long long C(int n, int m) { return fac[n] * inv[m] % mod * inv[n - m] % mod; }   long long cale(int k) {     long long large = fac[k];     long long less = 1;     less = fac[n] * inv[k + 1] % mod;     return large * less % mod;   }   int main() {     fac[0] = 1;     for (int i = 1; i < 1000010; ++i) fac[i] = fac[i - 1] * i % mod;     inv[1000009] = quick_mod(fac[1000009], mod - 2);     for (int i = 1000008; i >= 0; --i) inv[i] = inv[i + 1] * (i + 1) % mod;     int TEST_CASE = 1;     while (TEST_CASE-- > 0) {       input();       sort(a + 1, a + n + 1);       long long ans = 0;       a[0] = -1;       int pos = 1, K = n;       while (pos <= n) {         int val = a[pos];         int num = 0;         while (a[pos] == val) {           pos++;           num++;         }         if (val != a[n]) ans = (ans + cale(K - 1) * num % mod * val % mod) % mod;         K -= num;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   int mod = 1000000007;   using namespace std;   bool isp(long long x) {     for (long long i = 2; i * i <= x; ++i)       if (x % i == 0) return false;     return true;   }   void pog() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;   }   bool sortinrev(const pair<long long, long long> &a,                  const pair<long long, long long> &b) {     return (a.first > b.first);   }   bool prime_check(long long n) {     bool flag = 1;     for (long long i = 2; i <= sqrt(n); i++) {       if (n % i == 0) {         flag = 0;         break;       }     }     return flag;   }   long long power(long long x, unsigned long long y, long long p) {     long long res = 1;     x = x % p;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   int32_t main() {     pog();     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long arr[n];       for (long long i = 0; i < n; i++) {         cin >> arr[i];       };       long long sum = arr[0] + arr[1];       long long flag = 0;       for (long long i = 2; i < n; i++)         if (sum <= arr[i]) {           flag = i + 1;           break;         }       if (flag)         cout << 1 <<     << 2 <<     << flag <<   n ;       else         cout << -1 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int t1, t2;   int s1[100010], s2[100010];   pair<int, int> c1[100010], c2[100010];   bool cmp(pair<int, int> a, pair<int, int> b) { return a.first > b.first; }   int main() {     int n, v;     cin >> n >> v;     for (int i = 0; i < n; i++) {       int t, p;       cin >> t >> p;       if (t == 1) {         c1[t1++] = make_pair(p, i + 1);       } else         c2[t2++] = make_pair(p, i + 1);     }     sort(c1, c1 + t1, cmp);     sort(c2, c2 + t2, cmp);     s1[0] = s2[0] = 0;     for (int i = 0; i < t1; i++) {       s1[i + 1] = s1[i] + c1[i].first;     }     for (int i = 0; i < t2; i++) {       s2[i + 1] = s2[i] + c2[i].first;     }     int ans = -1;     int tmp = -1;     for (int i = 0; i <= t2; i++) {       if (i * 2 <= v && s1[min(v - i * 2, t1)] + s2[i] > ans) {         ans = s1[min(v - i * 2, t1)] + s2[i];         tmp = i;       }     }     cout << ans << endl;     for (int i = 0; i < min(v - tmp * 2, t1); i++) cout << c1[i].second << endl;     for (int i = 0; i < tmp; i++) cout << c2[i].second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 3) + (x << 1) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   const long long N = 107, MOD = 1e9 + 7;   long long n, K, c;   bool s[N];   struct Mat {     long long val[N][N];     long long Max_n, Max_m;     Mat() {       memset(val, 0, sizeof(val));       Max_n = Max_m = 0;     }     Mat operator*(const Mat el) const {       Mat c;       for (long long i = 0; i <= Max_n; ++i)         for (long long j = 0; j <= el.Max_m; ++j)           for (long long k = 0; k <= Max_m; ++k)             c.val[i][j] =                 (c.val[i][j] + ((val[i][k] * el.val[k][j]) % MOD)) % MOD;       c.Max_n = Max_n, c.Max_m = el.Max_m;       return c;     }     inline void I(long long n) {       Max_n = Max_m = n;       for (long long i = 0; i <= n; ++i) val[i][i] = 1;     }   };   inline long long power(long long x, long long y) {     long long res = 1, base = x;     while (y) {       if (y & 1) res = (res * base) % MOD;       base = (base * base) % MOD;       y >>= 1;     }     return res;   }   signed main() {     n = read(), K = read();     for (long long i = 1; i <= n; ++i) s[i] = read(), c += (s[i] == 0);     Mat A, F;     long long t = 0;     for (long long i = 1; i <= c; ++i)       if (s[i] == 0) ++t;     F.val[0][t] = 1;     F.Max_n = 1, F.Max_m = c;     for (long long i = 0; i <= c; ++i) {       if (i != 0) A.val[i - 1][i] = (c - i + 1) * (c - i + 1);       A.val[i][i] = (c * (c - 1) / 2) + ((n - c) * (n - c - 1) / 2) +                     (i * (c - i)) + (c - i) * (n - c - c + i);       if (i != c) A.val[i + 1][i] = (i + 1) * (n - c - c + i + 1);     }     A.Max_n = A.Max_m = c;     long long y = K;     Mat res;     res.I(c);     while (y) {       if (y & 1) res = res * A;       A = A * A;       y >>= 1;     }     F = F * res;     long long ans = F.val[0][c], sum = 0;     for (long long i = 0; i <= c; ++i) sum = (sum + F.val[0][i]) % MOD;     ans = (ans * power(sum, MOD - 2)) % MOD;     printf( %lld n , ans);     return 0;   }