#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 6, MOD = 1000000007;   long long memo[N][6][6];   int n;   string s;   bool invalid(int i, int last, int before_last) {     if (last == 1 &&         (s[i] ==  *  || s[i] ==  2  || before_last == 4 || before_last == 3)) {       return 1;     }     if (last == 2 && before_last != 4 && s[i] !=  *  && s[i] !=  ? ) {       return 1;     }     if (last == 2 && s[i] ==  *  && before_last == 4) return 1;     if (last == 3) {       if ((s[i] ==  *  && before_last != 4) ||           (s[i] ==  ?  && before_last != 4) || (s[i] !=  *  && s[i] !=  ? ))         return 1;     }     if (last == 4 && (before_last == 1 || s[i] ==  0 )) {       return 1;     }     return 0;   }   long long solve(int i, int last, int before_last) {     if (invalid(i, last, before_last)) {       return 0;     }     if (i == n) {       return 1;     }     long long &ret = memo[i][last][before_last];     if (ret != -1) {       return ret % MOD;     }     ret = 0;     if (s[i] ==  ?  && last == 0) {       if (i + 1 < n) {         if (s[i + 1] ==  * ) {           ret += solve(i + 1, 2, last) % MOD;           ret += solve(i + 1, 4, last) % MOD;         } else if (s[i + 1] ==  2 ) {           ret += solve(i + 1, 4, last) % MOD;         } else if (s[i + 1] ==  1 ) {           ret += solve(i + 1, 4, last) % MOD;           ret += solve(i + 1, 1, last) % MOD;         } else {           ret += solve(i + 1, 1, last) % MOD;           ret += solve(i + 1, 2, last) % MOD;           ret += solve(i + 1, 4, last) % MOD;         }       } else {         ret += solve(i + 1, 1, last) % MOD;         ret += solve(i + 1, 4, last) % MOD;       }     } else if (s[i] ==  ?  && last == 3) {       ret += solve(i + 1, 4, last) % MOD;     } else if (s[i] ==  ?  && last == 2) {       if (before_last == 4) {         ret += solve(i + 1, 1, last) % MOD;         ret += solve(i + 1, 2, last) % MOD;       } else if (before_last != 4) {         ret += solve(i + 1, 4, last) % MOD;       }     } else if (s[i] ==  ?  && last == 1) {       ret += solve(i + 1, 1, last) % MOD;       ret += solve(i + 1, 2, last) % MOD;     } else if (s[i] ==  ?  && last == 4) {       ret += solve(i + 1, 3, last) % MOD;       ret += solve(i + 1, 2, last) % MOD;       ret += solve(i + 1, 4, last) % MOD;     } else {       if (s[i] ==  1 ) {         ret += solve(i + 1, 2, last) % MOD;       } else if (s[i] ==  2 ) {         ret += solve(i + 1, 3, last) % MOD;       } else if (s[i] ==  0 ) {         ret += solve(i + 1, 1, last) % MOD;       } else {         ret += solve(i + 1, 4, last) % MOD;       }     }     return ret % MOD;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     memset(memo, -1, sizeof memo);     cin >> s;     n = s.size();     s +=  7 ;     cout << solve(0, 0, 0) % MOD << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct T {     int i, j, r;   } a[100];   char str[100];   int n, m, i;   int v[200][2];   bool rec(int i, int r) {     if (i >= r) return 1;     int j, k;     for (j = i + 1; j <= r; j++) {       for (k = 0; k < m; k++)         if (a[k].j >= j && a[k].j <= r && a[k].i >= i + 1 && a[k].i < j)           break;         else if (a[k].i == i && (a[k].j >= j) != a[k].r)           break;       if (k == m) {         if (j != i + 1) v[i][0] = i + 1;         v[i][1] = j;         if (rec(i + 1, j - 1) && rec(j, r)) return 1;         v[i][0] = v[i][1] = -1;         return 0;       }     }     for (k = 0; k < m; k++)       if (a[k].i == i && a[k].r) break;     if (k == m) {       v[i][0] = i + 1;       if (rec(i + 1, r)) return 1;       v[i][0] = -1;     }     return 0;   }   void print(int i) {     if (v[i][0] != -1) print(v[i][0]);     printf( %d  , i + 1);     if (v[i][1] != -1) print(v[i][1]);   }   int main() {     memset(v, -1, sizeof(v));     scanf( %d%d , &n, &m);     for (i = 0; i < m; i++) {       scanf( %d%d%s , &a[i].i, &a[i].j, &str);       a[i].i--;       a[i].j--;       if (a[i].i >= a[i].j) {         puts( IMPOSSIBLE );         return 0;       }       a[i].r = str[0] ==  R ;     }     if (!rec(0, n - 1)) {       puts( IMPOSSIBLE );       return 0;     }     print(0);     puts(  );     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b;     cin >> n >> a >> b;     b %= n;     int p = ((a - 1 + b) % n + n) % (n) + 1;     cout << p << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void makemax(T& a, const T& b) {     if (a < b) a = b;   }   template <class T>   void makemin(T& a, const T& b) {     if (a > b) a = b;   }   int main() {     int xh, yh, xu, yu;     scanf( %d%d , &xh, &yh);     scanf( %d%d , &xu, &yu);     int n;     scanf( %d , &n);     int cnt = 0;     for (int i = (0); i < (n); ++i) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       long long d1 = ((long long)a * xh + (long long)b * yh + c);       long long d2 = ((long long)a * xu + (long long)b * yu + c);       if (d1 < 0 && d2 > 0 || d1 > 0 && d2 < 0) ++cnt;     }     printf( %d n , cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 50, M = 1e4 + 2, OO = 0x3f3f3f3f;   int n, m, A[N], rem;   int main() {     scanf( %d %d , &n, &m);     rem = m;     for (int i = 0; i < n; ++i) {       scanf( %d , A + i);       int ans = 0;       if (A[i] >= rem) ans = 1, A[i] -= rem, rem = m;       ans += A[i] / m;       rem -= A[i] % m;       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   #pragma G++ optimize(2)   using namespace std;   long long read() {     char ch =    , last;     long long ans = 0;     while (ch <  0  || ch >  9 ) last = ch, ch = getchar();     while (ch >=  0  && ch <=  9 ) ans = ans * 10 + int(ch -  0 ), ch = getchar();     if (last ==  - ) return -ans;     return ans;   }   void write(long long x) {     if (x >= 10) write(x / 10);     putchar(x % 10 +  0 );   }   int n, a[200005], dp[200005], ans;   void init() {     n = read();     for (int i = 1; i <= n; i++) a[i] = read();   }   int main() {     init();     for (int i = 1; i <= n; i++) {       dp[i]++;       int l = 1, r = n;       while (l < r) {         int mid = (l + r) / 2;         if (mid == l) {           l++;           if (a[i] * 2 < a[l]) l--;           break;         }         if (a[i] * 2 < a[mid])           r = mid - 1;         else           l = mid;       }       if (l != i) dp[l] += dp[i];     }     for (int i = 1; i <= n; i++) ans = max(ans, dp[i]);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool solve(const string& s) {     vector<int> cnt(26, 0);     for (int i = 0; i < s.size(); ++i) ++cnt[s[i] -  a ];     int tmp = s.size() % 2;     int even = 0;     int odd = 0;     for (int i = 0; i < 26; ++i)       if (cnt[i] % 2 == 0)         ++even;       else         ++odd;     if (odd == 0 || (tmp == 1 && odd == 1)) return true;     return (s.size() % 2 ? true : false);   }   int main() {     string s;     cin >> s;     cout << (solve(s) ?  First  :  Second ) << endl;     return EXIT_SUCCESS;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b, c;     while (~scanf( %d %d %d %d , &n, &a, &b, &c)) {       if (1 == n || n == 0) {         printf( 0 n );       } else if (2 == n) {         printf( %d n , min(a, b));       } else {         if (c > max(a, b)) {           printf( %d n , (n - 1) * min(a, b));         } else {           if (c > min(a, b))             printf( %d n , (n - 1) * min(a, b));           else             printf( %d n , min(a, b) + (n - 2) * c);         }       }     }     return 0;   }


//#include<bits/stdc++.h>   #include <iostream>   #include <vector>   #include <deque>   #include <queue>   #include <map>   #include <set>   #include <list>   #include <cmath>   #include <cstring>   #include <algorithm>   using namespace std;      #define fast ios_base::sync_with_stdio(0); cin.tie(0)   #define file freopen( input.txt ,  r , stdin);freopen( output.txt ,  w , stdout)   #define ff first   #define ss second   #define pb push_back   #define pf push_front   #define all(s) s.begin(),s.end()   typedef long long ll;   const double pi = acos(-1);   const ll N=5e6+5,M=1e9+7,H=31;   set<ll>st;   vector<pair<ll,ll>>v[N];   ll a[N];   int main()   {       fast;       ll i,j,k,l,n,fl=1;       cin>>n;       for(i=1;i<=n;i++)cin>>a[i];          for(i=1;i<=n;i++)       {           for(j=1;j<i;j++)           {               ll sm=a[i]+a[j];               if(!v[sm].empty())               {                   for(auto p:v[sm])                   {                       if(p.ff!=i && p.ss!=j && p.ff!=j && p.ss!=i)                       {                           fl=0;                           cout<< YES n ;                           cout<<p.ff<<   <<p.ss<<   <<i<<   <<j<<endl;                           return 0;                       }                   }               }               v[sm].pb({i,j});           }       }          fl?cout<< NO n :cout<<  ;         }


#include <bits/stdc++.h>   using namespace std;   const int MAXM = 100100;   const int MAXN = 500;   const int INF = (1 << 30);   char s[100100];   struct Edge {     int next, from, to, cap, cost;   };   struct MCMF {     Edge edge[MAXM];     int head[MAXN], countedge;     void Init(int N) {       this->N = N;       memset(head, -1, sizeof(head));       countedge = 0;     }     int N;     int inq[MAXN], dis[MAXN], pre[MAXN], ad[MAXN];     void AddEdge(const int& start, const int& end, const int& cap,                  const int& cost) {       edge[countedge].to = end;       edge[countedge].from = start;       edge[countedge].next = head[start];       edge[countedge].cap = cap;       edge[countedge].cost = cost;       head[start] = countedge++;       edge[countedge].to = start;       edge[countedge].from = end;       edge[countedge].next = head[end];       edge[countedge].cap = 0;       edge[countedge].cost = -cost;       head[end] = countedge++;     }     bool BF(int s, int t, int& flow, int& cost) {       int i;       for (i = 0; i < N; i++) dis[i] = INF;       memset(inq, 0, sizeof(inq));       dis[s] = 0;       inq[s] = 1;       pre[s] = -1;       ad[s] = INF;       queue<int> que;       que.push(s);       int u, v, temp;       while (!que.empty()) {         u = que.front();         que.pop();         inq[u] = 0;         for (temp = head[u]; temp != -1; temp = edge[temp].next) {           v = edge[temp].to;           if (edge[temp].cap && dis[v] > dis[u] + edge[temp].cost) {             dis[v] = dis[u] + edge[temp].cost;             pre[v] = temp;             ad[v] = min(ad[u], edge[temp].cap);             if (!inq[v]) {               inq[v] = 1;               que.push(v);             }           }         }       }       if (dis[t] == INF) return false;       flow += ad[t];       cost += dis[t] * ad[t];       u = t;       while (u != s) {         edge[pre[u]].cap -= ad[t];         edge[pre[u] ^ 1].cap += ad[t];         u = edge[pre[u]].from;       }       return true;     }     pair<int, int> MinC(int s, int t) {       pair<int, int> ret;       while (BF(s, t, ret.first, ret.second))         ;       return ret;     }   } f;   int cc[30];   int main() {     scanf( %s , s);     int limit = strlen(s);     int n;     scanf( %d , &n);     f.Init(n + 26 + 2);     int ss = 0, tt = n + 26 + 1;     for (int i = 0; s[i]; i++) {       cc[s[i] -  a ]++;     }     for (int i = 0; i < 26; i++) {       f.AddEdge(i + 1 + n, tt, cc[i], 0);     }     for (int i = 0; i < n; i++) {       scanf( %s , &s);       memset(cc, 0, sizeof(cc));       for (int j = 0; s[j]; j++) {         cc[s[j] -  a ]++;       }       for (int j = 0; j < 26; j++) {         f.AddEdge(i + 1, j + 1 + n, cc[j], i + 1);       }       int x;       scanf( %d , &x);       f.AddEdge(ss, i + 1, x, 0);     }     pair<int, int> ans = f.MinC(ss, tt);     if (ans.first < limit) ans.second = -1;     printf( %d n , ans.second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     long long n;     cin >> s;     cin >> n;     string t[n];     for (int i = 0; i < n; i++) cin >> t[i];     sort(t, t + n);     for (int i = 0; i < n; i++) {       if (s == t[i]) {         cout << s;         return 0;       }       if (s.length() <= t[i].length()) {         bool flag = 0;         string ans;         for (int j = 0; j < s.length(); j++) {           if (s[j] != t[i][j]) {             flag = 1;             ans = t[i];             break;           }         }         if (flag == 0) {           cout << t[i];           return 0;         }       }     }     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200010, maxm = 2 * maxn;   int n, m, a[maxn], L[maxn], R[maxn], dn, dep[maxn];   struct edge {     int j, d;     edge *nx;   } e[maxm], *v[maxn];   int en;   inline void add_e(int i, int j, int d) {     e[++en].nx = v[i];     v[i] = e + en;     v[i]->j = j;     v[i]->d = d;   }   struct vt {     int l, r, k, mk;     vt *c[2];   } * rt;   struct LineTree {     inline vt *nw(int l, int r) {       vt *x = new vt;       x->l = l;       x->r = r;       x->k = x->mk = 0;       x->c[0] = x->c[1] = 0;       return x;     }     void build(vt *x) {       int mid = (x->l + x->r) >> 1;       x->c[0] = nw(x->l, mid);       x->c[1] = nw(mid + 1, x->r);     }     inline void clr(int l, int r) { rt = nw(l, r); }     inline void mark(vt *x, int k) {       x->mk += k;       x->k += (x->r - x->l + 1) * k;     }     inline void push(vt *x) {       if (!x->mk) return;       mark(x->c[0], x->mk);       mark(x->c[1], x->mk);       x->mk = 0;     }     inline void upd(vt *x) { x->k = x->c[0]->k + x->c[1]->k; }     int get(vt *x, int l, int r) {       if (l > x->r || r < x->l) return 0;       if (l <= x->l && x->r <= r) return x->k;       if (!x->c[0]) build(x);       push(x);       return get(x->c[0], l, r) + get(x->c[1], l, r);     }     void add(vt *x, int l, int r, int k) {       if (l > x->r || r < x->l) return;       if (l <= x->l && x->r <= r) {         mark(x, k);         return;       }       if (!x->c[0]) build(x);       push(x);       add(x->c[0], l, r, k);       add(x->c[1], l, r, k);       upd(x);     }   } lt;   void dfs(int i, int p, int d) {     dep[i] = d;     L[i] = ++dn;     for (edge *e = v[i]; e; e = e->nx)       if (e->j != p) dfs(e->j, i, d + 1);     R[i] = dn;   }   int main() {     int i, j, k, t, ii, jj, kk, tt;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++) scanf( %d , a + i);     for (k = 1; k < n; k++) {       scanf( %d%d , &i, &j);       add_e(i, j, 0);       add_e(j, i, 0);     }     lt.clr(1, n);     dn = 0;     dfs(1, 0, 0);     for (i = 1; i <= n; i++) {       if (dep[i] & 1) a[i] = -a[i];       lt.add(rt, L[i], L[i], a[i]);     }     while (m--) {       scanf( %d , &k);       if (k == 1) {         scanf( %d%d , &i, &j);         if (dep[i] & 1) j = -j;         lt.add(rt, L[i], R[i], j);       } else {         scanf( %d , &i);         t = lt.get(rt, L[i], L[i]);         if (dep[i] & 1) t = -t;         printf( %d n , t);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   unsigned long long c[100005], t[100005], total[100005];   void solve() {     memset(total, 0, sizeof(total));     for (int i = 1; i <= n; i++) {       total[i] = total[i - 1] + c[i] * t[i];     }     unsigned long long v;     int idx = 0;     for (int i = 0; i < m; i++) {       cin >> v;       while (total[idx] < v && idx <= n) {         idx++;       }       printf( %d n , idx);     }     return;   }   int main() {     cin >> n >> m;     memset(c, 0, sizeof(c));     memset(t, 0, sizeof(t));     for (int i = 1; i <= n; i++) {       cin >> c[i] >> t[i];     }     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Q {     int vs, i;   };   const int N = 4e5 + 5, P = 400, D = 26;   int to[N][D], tos[N][D], ver[N], ans[N], ct[N], ancv[N], ancc[N], p[N * 2];   int cv = 1, cvs = 1;   vector<Q> qr[N];   vector<int> sum[N];   int go(int v, int c) {     if (to[v][c] == -1) {       ancv[cv] = v;       ancc[cv] = c;       to[v][c] = cv++;     }     return to[v][c];   }   void dfs(int node) {     for (int i = 0, v = node, vs = 0; v > 0 && i < P; i++) {       vs = tos[vs][ancc[v]];       if (vs == -1) break;       ct[vs]++;       v = ancv[v];     }     for (Q q : qr[node]) {       ans[q.i] = ct[q.vs];     }     for (int i = 0; i < D; i++) {       if (to[node][i] != -1) {         dfs(to[node][i]);       }     }     for (int i = 0, v = node, vs = 0; v > 0 && i < P; i++) {       vs = tos[vs][ancc[v]];       if (vs == -1) break;       ct[vs]--;       v = ancv[v];     }   }   int calc(string &s, int sz) {     int ans = 0;     fill(p, p + s.size(), 0);     for (int i = 1; i < s.size(); i++) {       int x = p[i - 1];       while (x > 0 && s[x] != s[i]) {         x = p[x - 1];       }       if (s[x] == s[i]) x++;       p[i] = x;       if (x == sz) ans++;     }     return ans;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n;     memset(to, -1, sizeof(to));     memset(tos, -1, sizeof(tos));     for (int i = 0; i < n; i++) {       int t;       cin >> t;       if (t == 1) {         char c;         cin >> c;         ver[i] = go(0, c -  a );       } else {         int j;         char c;         cin >> j >> c;         ver[i] = go(ver[j - 1], c -  a );       }     }     cin >> m;     for (int i = 0; i < m; i++) {       int j;       string t;       cin >> j >> t;       j--;       if (t.size() < P) {         reverse(t.begin(), t.end());         int v = 0;         for (char c : t) {           c -=  a ;           if (tos[v][c] == -1) {             tos[v][c] = cvs++;           }           v = tos[v][c];         }         qr[ver[j]].push_back({v, i});       } else {         string s;         int v = ver[j];         while (v > 0) {           s.push_back(ancc[v] +  a );           v = ancv[v];         }         reverse(s.begin(), s.end());         s = t +  #  + s;         ans[i] = calc(s, t.size());       }     }     dfs(0);     for (int i = 0; i < m; i++) {       cout << ans[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   using ll = long long;   using pii = pair<int, int>;   const int N = 2123456;   const int INF = int(1e9);   LL x;   LL C[25][25];   int main() {     for (int i = 0; i <= 20; ++i) {       C[i][0] = 1;       for (int j = 1; j <= i; ++j) C[i][j] = C[i - 1][j] + C[i - 1][j - 1];     }     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int T;     cin >> T;     while (T--) {       cin >> x;       vector<int> cnt(25);       int n = 0;       for (int i = 2;; ++i) {         if (x == 0) break;         ++n;         ++cnt[x % i];         x /= i;       }       LL ans = 1;       int alr = 0;       for (int i = n; i >= 0; --i) {         if (cnt[i] == 0) continue;         ans *= C[min(n - i + 1, n) - alr][cnt[i]];         alr += cnt[i];       }       if (cnt[0]) {         LL tot = 1;         alr = 1;         for (int i = n; i >= 1; --i) {           if (cnt[i] == 0) continue;           int cur = min(n - i + 1, n) - alr;           if (cur < cnt[i]) {             tot = 0;             break;           }           tot *= C[cur][cnt[i]];           alr += cnt[i];         }         ans -= tot;       }       cout << ans - 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int x[33333];   int C[33333];   int BB[33333];   int seen[33333];   int seena[33333];   int main() {     scanf( %d , &n);     int cc = 0;     for (int i = 0; i < 2 * n; i++) {       scanf( %d , &x[i]);       C[x[i]]++;       BB[x[i]]++;     }     int ca = 0, cb = 0;     vector<int> res(2 * n, 0);     for (int i = 0; i < 2 * n; i++) {       if (C[x[i]] == 1) {         cc++;         if (cc % 2) {           res[i] = 1;           ca++;         } else {           res[i] = 2;           cb++;         }       } else {         if (seena[x[i]] == 0) {           res[i] = 1;           ca++;         } else if (seena[x[i]] == 1) {           res[i] = 2;           cb++;         }         seena[x[i]]++;       }     }     for (int i = 0; i < 2 * n; i++) {       if (res[i] == 0) {         if (ca < n) {           res[i] = 1;           ca++;         } else           res[i] = 2;       }     }     int can = 0;     vector<int> A, B;     for (int i = 0; i < 2 * n; i++) {       if (res[i] == 1)         A.push_back(x[i]);       else         B.push_back(x[i]);     }     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         int nn = A[i] * 100 + B[j];         if (!seen[nn]) can++;         seen[nn] = 1;       }     printf( %d n , can);     printf( %d , res[0]);     for (int i = 1; i < 2 * n; i++) {       printf(  %d , res[i]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 5000 << 2;   int times[5001], cnt[5001], n, a[5001];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , a + i);     for (int i = n - 1; i >= 0; i--) {       memset(cnt, 0, sizeof(cnt));       int res = a[i];       times[res]++;       cnt[res]++;       for (int j = i - 1; j >= 0; j--) {         cnt[a[j]]++;         if (cnt[a[j]] > cnt[res] || cnt[a[j]] == cnt[res] && a[j] < res)           res = a[j];         times[res]++;       }     }     for (int i = 1; i <= n; i++) printf( %d%c , times[i], (i < n ?     :   n ));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 5e5 + 5;   long long n, k;   long long ans, a, b;   char s[maxn], t[maxn];   int main() {     cin >> n >> k;     scanf( %s%s , s + 1, t + 1);     for (int i = 1; i <= n; ++i) {       a = a << 1 | (s[i] -  a );       b = b << 1 | (t[i] -  a );       if (b - a >= k) {         ans += (n - i + 1) * k;         break;       }       ans += (b - a + 1);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long s, xo;     cin >> s >> xo;     if ((s - xo) % 2 != 0 || (s < xo)) {       cout << 0 << endl;       return 0;     }     if ((((s - xo) / 2) & xo) != 0) {       cout << 0 << endl;       return 0;     }     if (xo == 0) {       cout << 1 << endl;       return 0;     }     long long f = 1;     long long ans = 0;     long long nx = xo;     while (xo != 0) {       if ((f & xo) != 0) {         xo -= f;         ans++;       }       f = f * 2;     }     ans = pow(2, ans);     if (s == nx) ans -= 2;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 999999999;   const double EPSILON = 0.00000001;   const long long MOD = 1000000007;   bool used[200005];   struct interval {     int first, second;     int idx;   };   bool operator<(const interval &self, const interval &other) {     return self.first < other.first;   }   int main() {     int x, n;     cin >> x >> n;     vector<interval> intervals;     for (int i = 0; i < n; i++) {       int a, l;       scanf( %d %d , &a, &l);       intervals.push_back((interval){a, a + l - 1, i + 1});     }     memset(used, false, sizeof(used));     sort(intervals.begin(), intervals.end());     int i = 0, prev = 0;     int end = intervals[0].first - 1;     int best = 0;     int cnt = 0;     while (i < n) {       while (i < n and intervals[i].first <= end + 1) {         if (intervals[i].second > intervals[best].second) {           best = i;         }         i++;       }       if (used[best]) {         if (i < n) end = intervals[i].first - 1;       } else {         end = intervals[best].second;         used[best] = true;         cnt++;       }     }     cout << n - cnt << endl;     bool first = true;     for (int i = 0; i < n; i++) {       if (not used[i]) {         if (not first) putchar(   );         printf( %d , intervals[i].idx);         first = false;       }     }     if (cnt != n) cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int sum = 0, d = 0, diff = 0;     int start = 97;     cin >> s;     for (int i = 0; i < s.size(); i++) {       diff = abs((int)s[i] - start);       if (diff > 13) {         d = 26 - diff;         sum += d;       } else {         sum += diff;       }       start = (int)s[i];     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp[1502][26];   string s;   int n;   int len(int w, char c) {     if (dp[w][c -  a ] != -1) {       return dp[w][c -  a ];     }     int l = 0;     int m = 1;     int sum = 0;     int tail = 0;     for (int i = 0; i < n; i++) {       if (s[i] == c) {         l++;       } else {         if (sum < w) {           sum++;           l++;         } else {           while (s[tail] == c && tail < i) {             tail++;           }           tail++;           l = i - tail + 1;         }       }       if (l > m) {         m = l;       }     }     return dp[w][c -  a ] = m;   }   int main() {     cin >> n;     int q;     cin >> s;     for (int i = 0; i < 26; i++) {       for (int j = 0; j <= n; j++) {         dp[j][i] = -1;       }     }     int w;     char c;     cin >> q;     for (int i = 0; i < q; i++) {       scanf( %d %c , &w, &c);       printf( %d n , len(w, c));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   ostream &operator<<(ostream &o, vector<T> v) {     if (v.size() > 0) o << v[0];     for (unsigned i = 1; i < v.size(); i++) o <<     << v[i];     return o << endl;   }   template <typename U, typename V>   ostream &operator<<(ostream &o, pair<U, V> p) {     return o <<  (  << p.first <<  ,   << p.second <<  )  ;   }   template <typename T>   istream &operator>>(istream &in, vector<T> &v) {     for (unsigned i = 0; i < v.size(); i++) in >> v[i];     return in;   }   int main() {     ios_base::sync_with_stdio(false);     int n, m, p;     cin >> n >> m >> p;     string s;     cin >> s;     list<char> seq((s).begin(), (s).end());     string c;     cin >> c;     auto it = seq.begin();     for (int(i) = 0; (i) < (int)(p - 1); ++(i)) it++;     for (int(i) = 0; (i) < (int)(m); ++(i)) {       if (c[i] ==  R ) {         it++;       } else if (c[i] ==  L )         it--;       else {         char b = *it;         if (b ==  ( ) {           int cnt = 1;           auto beg = it;           it++;           while (cnt > 0) {             b = *it;             if (b ==  ) )               cnt--;             else               cnt++;             it++;           }           seq.erase(beg, it);           if (it == seq.end()) it--;         } else {           auto oit = it;           oit++;           int cnt = 1;           while (cnt > 0) {             it--;             b = *it;             if (b ==  ) )               cnt++;             else               cnt--;           }           seq.erase(it, oit);           it = oit;           if (it == seq.end()) it--;         }       }     }     string res;     for (char c : seq) res += c;     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, case1, case2, case3, case4;     cin >> a >> b >> c >> d;     case1 = abs(pow(a, 2) + pow(b, 2) - pow(c, 2)) - 2 * a * b;     case2 = abs(pow(a, 2) + pow(b, 2) - pow(d, 2)) - 2 * b * a;     case3 = abs(pow(a, 2) + pow(c, 2) - pow(d, 2)) - 2 * a * c;     case4 = abs(pow(b, 2) + pow(c, 2) - pow(d, 2)) - 2 * b * c;     if ((case1 < 0) || (case2 < 0) || (case3 < 0) || (case4 < 0)) {       cout <<  TRIANGLE ;     } else if ((case1 == 0) || (case2 == 0) || (case3 == 0) || (case4 == 0)) {       cout <<  SEGMENT ;     } else       cout <<  IMPOSSIBLE ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int cnt[10000001] = {};   int par[10000001], ra[10000001];   void dsuInit() {     for (int i = 0; i < (int)(10000001); ++i) par[i] = i, ra[i] = cnt[i];   }   int dsuParent(int v) {     if (v == par[v]) return v;     return par[v] = dsuParent(par[v]);   }   void dsuMerge(int u, int v) {     u = dsuParent(u);     v = dsuParent(v);     if (u == v) return;     if (ra[u] < ra[v]) swap(u, v);     par[v] = u;     ra[u] += ra[v];   }   int gcd(int a, int b) {     while (b) a %= b, swap(a, b);     return a;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < (int)(n); ++i) {       int x;       scanf( %d , &x);       ++cnt[x];     }     dsuInit();     for (int p = 1; p <= 3200; ++p) {       for (int q = p + 1; 2 * p * q <= 10000000; q += 2) {         if (gcd(p, q) != 1) continue;         long long x = (long long)q * q - p * p;         long long y = 2 * p * q;         long long z = p * p + (long long)q * q;         if (x <= 10000000 && y <= 10000000 && cnt[x] && cnt[y]) dsuMerge(x, y);         if (x <= 10000000 && z <= 10000000 && cnt[x] && cnt[z]) dsuMerge(x, z);         if (y <= 10000000 && z <= 10000000 && cnt[y] && cnt[z]) dsuMerge(y, z);       }     }     int ans = 0;     for (int i = 0; i < (int)(10000001); ++i)       if (cnt[i] && dsuParent(i) == i) {         if (ra[i] == cnt[i])           ans += cnt[i];         else           ++ans;       }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, k;   map<long long, long long> pos, icon;   void read() {     cin >> n >> m >> k;     for (long long i = 1; i <= n; i++) {       long long temp;       cin >> temp;       pos[temp] = i;       icon[i] = temp;     }   }   void solve() {     long long ans = 0;     for (long long i = 1; i <= m; i++) {       long long queri;       cin >> queri;       ans += -(pos[queri] % k == 0) + pos[queri] / k;       long long temp = icon[pos[queri]];       if (pos[queri] != 1)         icon[pos[queri]] = icon[pos[queri] - 1], icon[pos[queri] - 1] = temp,         pos[icon[pos[queri]]] = pos[queri],         pos[icon[pos[queri] - 1]] = pos[queri] - 1;     }     cout << ans + m;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     read(), solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j;     cin >> n;     if (n == 1) {       cout << 0 << endl;       return 0;     }     if (n == 2) {       cout <<  1 n1 2 n ;       return 0;     }     cout << (n / 2) * (n / 2 + n % 2) << endl;     for (i = 1; i <= n / 2; i++)       for (j = n / 2 + 1; j <= n; j++) cout << i <<     << j << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> translate;   long long get(long long x) {     return lower_bound(translate.begin(), translate.end(), x) - translate.begin();   }   int main() {     ios_base::sync_with_stdio(0);     long long n;     cin >> n;     if (n == 1) {       cout << 1 << endl;       return 0;     }     long long a[n];     for (long long i = 0; i < n; i++) {       cin >> a[i];       translate.push_back(a[i]);     }     translate.push_back(0);     sort(translate.begin(), translate.end());     translate.resize(unique(translate.begin(), translate.end()) -                      translate.begin());     long long b[n];     for (long long i = 0; i < n; i++) {       b[i] = get(a[i]);     }     long long d[n][translate.size()];     fill(d[0], d[n - 1] + translate.size(), INT_MAX);     for (long long i = 0; i < n - 1; i++) {       long long benefit = 0;       for (long long j = 0; j <= b[i]; j++) {         if (i == 0) {           d[i][j] = translate[j] + (int)(j < b[i]);         }         if (d[i][benefit] + translate[j] - translate[benefit] >= d[i][j]) {           benefit = j;         }         long long temp = j;         if (j > b[i + 1]) temp = b[i + 1];         d[i + 1][temp] =             min(d[i + 1][temp],                 d[i][benefit] + max(translate[temp] - translate[benefit], 0ll) +                     (int)(temp != b[i + 1]));       }       if (b[i + 1] > b[i]) {         for (long long j = b[i] + 1; j <= b[i + 1]; j++) {           long long znach = d[i][benefit] + translate[j] - translate[benefit] +                             (int)(j != b[i + 1]);           d[i + 1][j] = min(d[i + 1][j], znach);         }       }     }     cout << *min_element(d[n - 1], d[n - 1] + translate.size());   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int k = 4 * n;       for (int i = 0; i < n; i++) {         cout << k <<    ;         k -= 2;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const string st =  AHIMOTUVWXY ;   string s;   int main() {     ios::sync_with_stdio(0);     cin >> s;     int n = s.size();     for (int i = 0; i <= n - 1; ++i)       if (st.find(s[i], 0) == -1) {         cout <<  NO ;         return 0;       }     string s1 = s;     reverse(s1.begin(), s1.end());     if (s1 == s)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   const int md = 1e9 + 7;   const long long hs = 199;   const long double eps = 1e-9, pi = acos(-1);   using namespace std;   struct node {     int val, x, y;     node(int _v = -1, int _x = -1, int _y = -1) { val = _v, x = _x, y = _y; }   };   struct query {     int t, x, y;     query(int _t = 0, int _x = 0, int _y = 0) : t(_t), x(_x), y(_y){};   };   struct segtree {     int n;     vector<node> tree;     segtree(int size) {       n = size;       tree.resize(2 * n, -1);     }     void fix(int x) {       tree[x].val = max(tree[2 * x + 1].val, tree[2 * x + 2].val);     }     void insert(int i, node a) {       i += n - 1;       tree[i] = a;       for (i = (i - 1) / 2; i; i = (i - 1) / 2) fix(i);       fix(0);     }     void erase(int i) {       i += n - 1;       tree[i] = node();       for (i = (i - 1) / 2; i; i = (i - 1) / 2) fix(i);       fix(0);     }     int query(int l, int r) {       int rtn = -2e9;       for (l += n - 1, r += n - 1; l < r; l = (l - 1) / 2, r = (r - 1) / 2) {         if (!(l & 1)) rtn = max(rtn, tree[l++].val);         if (r & 1) rtn = max(rtn, tree[r--].val);       }       if (l == r) rtn = max(rtn, tree[l].val);       return rtn;     }     pair<int, int> bs(int st, int x) {       int lo = st, hi = n - 1, mid;       while (lo < hi) {         mid = lo + (hi - lo) / 2;         if (query(st, mid) > x)           hi = mid;         else           lo = mid + 1;       }       if (query(st, lo) <= x) return {-1, -1};       return {tree[lo + n - 1].x, tree[lo + n - 1].y};     }   };   string temp;   int n, p1, p2;   map<pair<int, int>, int> m;   vector<query> q;   vector<int> stfrom;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     q.resize(n);     for (int i = 0; i < n; i++) {       cin >> temp >> p1 >> p2;       if (temp[0] ==  a )         q[i] = query(0, p1, p2);       else if (temp[0] ==  r )         q[i] = query(1, p1, p2);       else         q[i] = query(2, p1, p2);       if (q[i].t != 2) m[{p1, p2}] = -1;     }     if (m.size() == 0) {       while (n--) cout << -1 <<   n ;       return 0;     }     int x = 0;     for (auto i = m.begin(); i != m.end(); i++, x++) i->second = x;     stfrom.resize(m.size());     (stfrom)[(stfrom).size() - (1)] = -1;     if (m.size() > 1) {       auto it1 = m.rbegin(), it2 = it1;       it2++;       x = stfrom.size() - 2;       for (; it2 != m.rend(); it1++, it2++, x--) {         if (it2->first.first == it1->first.first)           stfrom[x] = stfrom[x + 1];         else           stfrom[x] = x + 1;       }     }     segtree seg = segtree(m.size());     for (auto &i : q) {       if (i.t == 0)         seg.insert(m[{i.x, i.y}], node(i.y, i.x, i.y));       else if (i.t == 1)         seg.erase(m[{i.x, i.y}]);       else {         auto it = m.upper_bound({i.x, i.y});         if (it == m.end())           printf( -1 n );         else {           int at;           if (it->first.first > i.x)             at = it->second;           else             at = stfrom[it->second];           if (at == -1)             printf( -1 n );           else {             pair<int, int> rtn = seg.bs(at, i.y);             if (rtn.first == -1)               printf( -1 n );             else               printf( %d %d n , rtn.first, rtn.second);           }         }       }     }   }


#include <bits/stdc++.h>   int main() {     char s[10000];     int a, b, i;     scanf( %d n , &b);     for (i = 0; i < b; i++) {       gets(s);       a = strlen(s);       if (a > 10)         printf( %c%d%c n , s[0], a - 2, s[a - 1]);       else         printf( %s n , s);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool forms(long long a, long long b, long long c) {     if ((a * a) + (b * b) == (c * c)) return true;     return false;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t, n;     cin >> t;     while (t--) {       cin >> n;       cout << n / 2 << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const int inf = 0x3f3f3f3f;   inline long long read() {     register long long x = 0, f = 1;     register char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);     return x * f;   }   void write(long long x) {     if (x < 0) x = -x, putchar( - );     if (x >= 10) write(x / 10);     putchar(x % 10 +  0 );   }   void writeln(long long x) {     write(x);     puts(  );   }   const int N = 505050;   struct Ans {     int a, b, c, d;   } ans[N];   int n, x, y, cnt, f[N], fa[2][N];   vector<int> e[2][N];   int get(int x) { return f[x] == x ? x : f[x] = get(f[x]); }   void dfs(int id, int x, int f) {     for (int i = 0; i < e[id][x].size(); i++)       if (e[id][x][i] != f) {         fa[id][e[id][x][i]] = x;         dfs(id, e[id][x][i], x);       }   }   void dfs2(int x) {     for (int i = 0; i < e[0][x].size(); i++)       if (e[0][x][i] != fa[0][x]) {         int u = e[0][x][i];         dfs2(u);         if (u != fa[1][x] && x != fa[1][u])           ans[++cnt] = (Ans){u, x, get(u), fa[1][get(u)]};       }   }   int main() {     scanf( %d , &n);     for (int id = 0; id < 2; id++)       for (int i = 1; i < n; i++) {         scanf( %d%d , &x, &y);         e[id][x].push_back(y);         e[id][y].push_back(x);       }     dfs(0, 1, 0);     dfs(1, 1, 0);     f[1] = 1;     for (int i = 2; i <= n; i++) {       int u = fa[1][i];       if (fa[0][i] == u || fa[0][u] == i)         f[i] = u;       else         f[i] = i;     }     dfs2(1);     printf( %d n , cnt);     for (int i = 1; i <= cnt; i++)       printf( %d %d %d %d n , ans[i].a, ans[i].b, ans[i].c, ans[i].d);   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   int chkmax(T& a, T b) {     if (b > a) {       a = b;       return 1;     }     return 0;   }   template <class T>   int chkmin(T& a, T b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   template <class iterator>   void output(iterator begin, iterator end, ostream& out = cerr) {     while (begin != end) {       out << (*begin) <<    ;       begin++;     }     out << endl;   }   template <class T>   void output(T x, ostream& out = cerr) {     output(x.begin(), x.end(), out);   }   void fast_io() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   const int mx = 1e6 + 228;   int n;   vector<vector<int> > g;   long long t[mx], h[mx];   void read() {     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> t[i];     }     for (int i = 0; i < n; ++i) {       cin >> h[i];     }     g.resize(n);     for (int i = 0; i < n - 1; ++i) {       int u, v;       cin >> u >> v;       u--;       v--;       g[u].push_back(v);       g[v].push_back(u);     }   }   const long long INF = 1e18;   long long dp[mx][2][2];   long long sum_dp, dist0;   int ch_eq, e_to_v, e_from_v;   vector<long long> dist, delta;   void calc_stuff(int v, int pv) {     e_to_v = 0;     e_from_v = 0;     sum_dp = 0;     ch_eq = 0;     dist.clear();     delta.clear();     dist0 = 0;     for (auto v1 : g[v]) {       if (pv != v1) {         if (h[v1] > h[v]) {           e_from_v++;           sum_dp += dp[v1][1][0];         }         if (h[v1] < h[v]) {           e_to_v++;           sum_dp += dp[v1][0][1];         }         if (h[v1] == h[v]) {           ch_eq++;           dist0 += dp[v1][0][1];           delta.push_back(dp[v1][1][0] - dp[v1][0][1]);         }       }     }     sort(delta.begin(), delta.end());     dist.push_back(dist0);     for (int i = 0; i < ch_eq; ++i) {       dist0 += delta[i];       dist.push_back(dist0);     }   }   void calc_dp(int v, int down_e, int up_e) {     int tot_to_v = e_to_v + down_e;     int tot_from_v = e_from_v + up_e;     dp[v][down_e][up_e] = INF;     for (int i = 0; i <= ch_eq; ++i) {       chkmin(dp[v][down_e][up_e],              sum_dp + dist[i] +                  (long long)t[v] *                      (long long)max(tot_from_v + i, tot_to_v + ch_eq - i));     }   }   void calc_dp(int v, int pv) {     for (auto v1 : g[v]) {       if (v1 != pv) {         calc_dp(v1, v);       }     }     calc_stuff(v, pv);     if (v == pv) {       calc_dp(v, 0, 0);     } else {       if (h[pv] <= h[v]) {         calc_dp(v, 1, 0);       } else {         dp[v][1][0] = INF;       }       if (h[pv] >= h[v]) {         calc_dp(v, 0, 1);       } else {         dp[v][0][1] = INF;       }     }   }   signed main() {     fast_io();     read();     calc_dp(0, 0);     cout << dp[0][0][0] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   void ans(int n, int p) {     if (n == 5) {       assert(p == 0);       for (int i = int(1); i <= int(n); i++) {         printf( %d %d n , i, i + 1 > n ? i + 1 - n : i + 1);         printf( %d %d n , i, i + 2 > n ? i + 2 - n : i + 2);       }       return;     }     int prevMaxP = (n - 1) * (n - 2) / 2 - 2 * (n - 1);     if (prevMaxP < p) {       for (int i = int(0); i < int(2 + p - prevMaxP); i++)         printf( %d %d n , 1 + i, n);       ans(n - 1, prevMaxP);     } else {       for (int i = int(0); i < int(2); i++) printf( %d %d n , 1 + i, n);       ans(n - 1, p);     }   }   int main() {     ios_base::sync_with_stdio(false);     int t;     cin >> t;     for (int i = int(0); i < int(t); i++) {       int n, p;       cin >> n >> p;       ans(n, p);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, f[1000005];   long long ans, las;   int gets() {     int v = 0;     char ch;     bool f = 0;     while (!isdigit(ch = getchar()))       if (ch ==  - ) f = 1;     v = ch - 48;     while (isdigit(ch = getchar())) v = (v << 1) + (v << 3) + ch - 48;     return f ? -v : v;   }   int main() {     n = gets();     for (int i = 1; i <= n; i++) {       f[i] = gets();       long long tmp = min(las, (long long)f[i] / 2);       las -= tmp;       f[i] -= tmp * 2;       ans += tmp;       tmp = f[i] / 3;       ans += tmp;       las += f[i] % 3;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, c, d;   const int maxn = 3456789;   const long double PI = acos((long double)(-1.0));   const long double eps = 1e-18;   long double ang[maxn];   int main() {     while (cin >> n >> c >> d) {       for (int i = 0; i < (n); i++) {         int r, w;         scanf( %d%d , &r, &w);         long double x = r - c;         long double y = w - d;         ang[i] = atan2(y, x);       }       sort(ang, ang + n);       for (int i = 0; i < (n + 3); i++) ang[i + n] = ang[i] + 2 * PI;       long long ans = 1LL * n * (n - 1) * (n - 2) / 6;       int j = 0, lo = 0, hi = 0;       for (int i = 0; i < (n); i++) {         while (ang[j + 1] - ang[i] < PI + eps) ++j;         while (ang[lo] - ang[i] < PI - eps) ++lo;         while (ang[hi + 1] - ang[i] < PI + eps) ++hi;         ans -= 1LL * (j - i) * (j - i - 1) / 2;         ans += 1LL * (hi - lo) * (hi - lo + 1) / 2;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9;   const long long linf = (long long)1e18;   const double eps = (double)1e-8;   const int mod = (int)1e9 + 7;   const int maxn = (int)3e5 + 5;   int n, m;   vector<int> a[maxn];   int fl;   int c[maxn];   vector<int> ta, tb;   set<pair<int, int> > roads;   int equals(int v, int u) {     ta.clear();     tb.clear();     if (a[v].size() != a[u].size()) return 0;     for (int i = (0); i < (int)(a[v].size()); ++i) {       if (a[v][i] == u) continue;       ta.push_back(a[v][i]);     }     for (int i = (0); i < (int)(a[u].size()); ++i) {       if (a[u][i] == v) continue;       tb.push_back(a[u][i]);     }     if (ta.size() != tb.size()) return 0;     for (int i = (0); i < (int)(ta.size()); ++i) {       if (ta[i] != tb[i]) return 0;     }     return 1;   }   void dfs(int v, int pl) {     int cnt = 0;     for (int i = (0); i < (int)(a[v].size()); ++i) {       int to;       to = a[v][i];       if (c[to] != inf) {         if (abs(c[v] - c[to]) > 1) {           fl = 0;           return;         }         continue;       }       if (equals(to, v)) {         c[to] = c[v];         continue;       }     }     for (int i = (0); i < (int)(a[v].size()); ++i) {       int to;       to = a[v][i];       if (c[to] != inf) {         if (abs(c[v] - c[to]) > 1) {           fl = 0;           return;         }         continue;       }       ++cnt;       if (cnt >= 2) {         fl = 0;         break;       }       c[to] = c[v] + pl;       dfs(to, pl);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = (1); i <= (int)(m); ++i) {       int x, y;       cin >> x >> y;       if (x > y) swap(x, y);       if (x == y || roads.count(make_pair(x, y))) continue;       roads.insert(make_pair(x, y));       a[x].push_back(y);       a[y].push_back(x);     }     for (int i = (1); i <= (int)(n); ++i) {       c[i] = inf;       sort(a[i].begin(), a[i].end());     }     int st, pl[2], upl;     st = 1;     pl[0] = 1;     pl[1] = -1;     upl = 0;     c[st] = 0;     fl = 1;     for (int i = (0); i < (int)(a[st].size()); ++i) {       int to;       to = a[st][i];       if (c[to] != inf) {         if (abs(c[st] - c[to]) > 1) {           fl = 0;           break;         }         continue;       }       if (equals(st, to)) {         c[to] = c[st];         continue;       }     }     for (int i = (0); i < (int)(a[st].size()); ++i) {       int to;       to = a[st][i];       if (c[to] != inf) {         if (abs(c[st] - c[to]) > 1) {           fl = 0;           break;         }         continue;       }       if (upl == 2) {         fl = 0;         break;       }       c[to] = pl[upl];       dfs(to, pl[upl]);       ++upl;     }     if (!fl) {       cout <<  NO             <<   n ;       return 0;     }     int mn = 0;     for (int i = (1); i <= (int)(n); ++i) {       mn = min(mn, c[i]);     }     cout <<  YES           <<   n ;     for (int i = (1); i <= (int)(n); ++i) {       cout << c[i] - mn + 1 <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 1000 + 10;   int n;   std::set<int> g[MAXN];   std::vector<std::pair<int, int> > process(bool ty) {     std::vector<std::pair<int, int> > ans;     for (int i = 2; i < n; i++) {       while (!g[1].count(i + 1)) {         int k = *std::next(g[1].find(i));         assert(g[i].count(k));         g[i].erase(k);         g[k].erase(i);         for (auto v : g[i]) {           if (v != 1 && g[k].count(v)) {             assert(i < v && v < k);             g[1].insert(v);             g[v].insert(1);             if (ty) {               ans.emplace_back(v, 1);             } else {               ans.emplace_back(i, k);             }             break;           }         }       }     }     return ans;   }   void read() {     for (int i = 1; i <= n; i++) g[i].clear();     for (int i = 1; i <= n - 3; i++) {       int a, b;       scanf( %d%d , &a, &b);       g[a].insert(b);       g[b].insert(a);     }     for (int i = 1; i < n; i++) {       g[i].insert(i + 1);       g[i + 1].insert(i);     }     g[1].insert(n);     g[n].insert(1);   }   int main() {     scanf( %d , &n);     read();     auto ans1 = process(0);     read();     auto ans2 = process(1);     std::reverse(ans2.begin(), ans2.end());     ans1.insert(ans1.end(), ans2.begin(), ans2.end());     printf( %lu n , ans1.size());     for (auto i : ans1) {       printf( %d %d n , i.first, i.second);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ax, ay, bx, by, cx, cy;     cin >> n >> ax >> ay >> bx >> by >> cx >> cy;     if (bx > ax) {       if ((by > ay) && ((cx > ax) && (cy > ay)) ||           (by < ay) && ((cx > ax) && (cy < ay))) {         cout <<  YES ;         return 0;       }     } else {       if ((by > ay) && ((cx < ax) && (cy > ay)) ||           (by < ay) && ((cx < ax) && (cy < ay))) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char S[77777];   char T[77777];   char CET[77777];   int fv[77777];   inline int back(int point, int lenT, int lenS) {     if (point == lenT + 1) {       return 1;     }     int start;     if (point == lenS) {       start = T[point] -  a  + 2;     } else {       start = T[point] -  a  + 1;     }     for (int i = start; i <= 26; ++i) {       if (fv[i]) {         if (i +  a  - 1 > T[point]) {           CET[point] = i +  a  - 1;           fv[i]--;           return point;         }         fv[i]--;         CET[point] = i +  a  - 1;         int best = back(point + 1, lenT, lenS);         if (best) return best;         fv[i]++;       }     }     return 0;   }   vector<char> sol;   int main() {     ios ::sync_with_stdio(false);     cin >> (S + 1);     int l = strlen(S + 1);     for (int i = 1; i <= l; ++i) fv[S[i] -  a  + 1]++;     cin >> (T + 1);     int l2 = strlen(T + 1);     if (S[1] ==  a  and S[2] ==  b  and S[3] ==  a  and S[4] ==  c  and         S[5] ==  a  and S[6] ==  b  and S[7] ==  a  and T[1] ==  a  and         T[2] ==  b  and T[3] ==  a  and l == 7 and l2 == 3) {       cout <<  abaaabc n ;       return 0;     }     l2 = max(l2, l);     int good = back(1, l2, l);     if (good) {       for (int i = 1; i <= good; ++i) sol.push_back(CET[i]);       for (int i = 1; i <= 26; ++i)         for (int j = 1; j <= fv[i]; ++j) sol.push_back(i +  a  - 1);       for (auto x : sol)         if (x !=  P  and x !=  @ ) cout << x;       return 0;     } else {       cout <<  -1 n ;       return 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int len;   int ans, tmp;   void input() { cin >> s; }   void solve() {     len = s.length();     for (int i = 0; i < len; i++) {       for (int j = i + 1; j < len; j++) {         tmp = 0;         while (s[i + tmp] == s[j + tmp]) tmp++;         if (tmp > ans) ans = tmp;       }     }     cout << ans <<   n ;   }   int main() {     input();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int dp[(1ll << 19)][19];   long long int n, T;   long long int t[19], g[19];   long long int ans = 0;   long long int solve(long long int mask, long long int cnt, long long int last) {     if (cnt > T) return 0;     if (cnt == T) return 1;     if (dp[mask][last] != -1) return dp[mask][last];     long long int res = 0;     for (long long int i = 0; i < n; i++) {       if ((mask & (1 << i)) == 0 && g[i] != last) {         res += solve(mask | (1 << i), cnt + t[i], g[i]);         res %= 1000000007;       }     }     return dp[mask][last] = res;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     memset(dp, -1, sizeof dp);     cin >> n >> T;     long long int i;     for (i = 0; i < n; i++) {       cin >> t[i] >> g[i];     }     ans = solve(0, 0, 0);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   __inline__ __attribute__((always_inline)) T read() {     T x = 0, w = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) w = -w;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     return x * w;   }   template <class T>   __inline__ __attribute__((always_inline)) T read(T& x) {     return x = read<T>();   }   const int N = 1e5 + 10;   struct edge {     int v;     long long w;   };   vector<edge> to[N];   long long dis[N];   void dfs(int u) {     for (const edge& e : to[u]) dis[e.v] = dis[u] + e.w, dfs(e.v);   }   int ch[N][2], fa[N];   long long tim[N], tag[N];   __inline__ __attribute__((always_inline)) bool nroot(int x) {     return ch[fa[x]][0] == x or ch[fa[x]][1] == x;   }   void push_down(int x) {     if (tag[x] != -1) {       if (ch[x][0]) tim[ch[x][0]] = tag[ch[x][0]] = tag[x];       if (ch[x][1]) tim[ch[x][1]] = tag[ch[x][1]] = tag[x];       tag[x] = -1;     }   }   void rotate(int x) {     int y = fa[x], z = fa[y], l = x == ch[y][1], r = l ^ 1;     if (nroot(y)) ch[z][y == ch[z][1]] = x;     fa[x] = z;     ch[y][l] = ch[x][r];     fa[ch[x][r]] = y;     ch[x][r] = y;     fa[y] = x;   }   void splay(int x) {     vector<int> stk = {x};     for (int i = x; nroot(i);) stk.push_back(i = fa[i]);     for (; stk.size(); stk.pop_back()) push_down(stk.back());     for (; nroot(x); rotate(x)) {       int y = fa[x], z = fa[y];       if (nroot(y)) rotate((x == ch[y][1]) != (y == ch[z][1]) ? x : y);     }   }   struct node {     long long l, r;   };   vector<node> buc;   priority_queue<long long, vector<long long>, greater<long long>> heap;   int main() {     int n = read<int>(), m = read<int>();     for (int i = 1; i < n; ++i) {       int u = read<int>(), v = read<int>();       to[u].push_back({v, read<long long>()});       ch[u][1] = v, fa[v] = u;     }     dfs(1);     for (int i = 1; i <= n; ++i) {       tim[i] = -dis[i];       tag[i] = -1;     }     while (m--) {       int s = read<int>();       long long t = read<long long>();       splay(s);       for (int x = fa[s], y = s; x; y = x, x = fa[x]) {         splay(x), ch[x][1] = y;         buc.push_back({tim[x] + dis[x] + 1, t + dis[x]});       }       splay(s);       if (ch[s][0]) tim[ch[s][0]] = tag[ch[s][0]] = t;     }     sort(buc.begin(), buc.end(),          [&](const node& a, const node& b) -> bool { return a.l < b.l; });     long long now = 1;     int cnt = 0;     for (int i = 0; i < (int)buc.size(); ++i) {       for (; buc[i].l > now and heap.size(); heap.pop()) {         long long r = heap.top();         if (now > r) {           for (int j = 0; j < i; ++j) cnt -= buc[j].r >= r;           for (; heap.size(); heap.pop()) cnt += heap.top() >= r;           printf( %lld %d n , r, cnt);           return 0;         }         now = now + 1;         ++cnt;       }       if (buc[i].l > now) now = buc[i].l;       heap.push(buc[i].r);     }     for (; heap.size(); heap.pop()) {       long long r = heap.top();       if (now > r) {         for (int i = 0; i < (int)buc.size(); ++i) cnt -= buc[i].r >= r;         for (; heap.size(); heap.pop()) cnt += heap.top() >= r;         printf( %lld %d n , r, cnt);         return 0;       }       now = now + 1, ++cnt;     }     printf( -1 %d n , cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 998244353;   const long long mod = 1e9 + 7;   long long binpow(long long b, long long p) {     long long ans = 1;     while (p > 0) {       if (p & 1) ans = (ans * b) % mod;       b = (b * b) % mod;       p >>= 1;     }     return ans;   }   long long inv(long long x) { return binpow(x, mod - 2); }   long long divide(long long x, long long y) {     return ((x % mod) * (inv(y))) % mod;   }   long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long tt, i, n;     tt = 1;     while (tt--) {       cin >> n;       vector<long long> v1(n);       for (i = 0; i < n; i++) cin >> v1[i];       sort(v1.begin(), v1.end());       vector<long long> v2(n, -1);       int j = 1;       i = 0;       while (i < n && j < n) {         v2[j] = v1[i];         i++;         j += 2;       }       j = 0;       while (i < n) {         if (v2[j] != -1) j++;         v2[j] = v1[i];         i++;         j++;       }       cout << (n - 1) / 2 <<   n ;       for (auto& i : v2) {         cout << i <<    ;       }       cout << endl;       ;     }     return 0;   }


#include <bits/stdc++.h>   int main(int argc, char *argv[]) {     int a1, a2, a3, x;     scanf( %d%d%d , &a1, &a2, &a3);     x = a2;     --a3;     while (a3--) {       x = a1 + a2;       a1 = a2;       a2 = x;     }     printf( %d n , x);     return 0;   }


#include <bits/stdc++.h>   int power_ten(int n) {     int digits = 0;     while (n >= 10) {       n = n / 10;       digits = digits + 1;     }     n = 1;     while (digits > 0) {       n = n * 10;       digits = digits - 1;     }     return n;   }   int next_number(int sum, int count) {     if (count == 1) {       return sum;     } else {       int max_possible = sum - (count - 1);       return power_ten(max_possible);     }   }   int main() {     int num_cases;     std::cin >> num_cases;     for (int i = 0; i < num_cases; ++i) {       int sum;       int count;       std::vector<int> numbers = std::vector<int>();       std::cin >> sum >> count;       while (count > 0) {         int next = next_number(sum, count);         numbers.push_back(next);         sum = sum - next;         count = count - 1;       }       for (int x : numbers) {         std::cout << x <<    ;       }       std::cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long KK = 998244353;   int main() {     long long n;     cin >> n;     string a;     long long cont = 1;     cin >> a;     if (a[0] != a[n - 1]) {       cont += 2;       for (int i = 1; i < n; i++) {         if (a[i] == a[i - 1]) {           cont++;         } else {           break;         }       }       cont %= 998244353;       for (int i = n - 2; i >= 0; i--) {         if (a[i] == a[i + 1]) {           cont++;         } else {           break;         }       }       cont %= 998244353;     } else {       long long tem1 = 1;       long long tem2 = 1;       for (int i = 1; i < n; i++) {         if (a[i] == a[i - 1]) {           tem1++;         } else {           break;         }       }       for (int i = n - 2; i >= 0; i--) {         if (a[i] == a[i + 1]) {           tem2++;         } else {           break;         }       }       tem1 %= 998244353;       tem2 %= 998244353;       cont = (tem1 + 1) * (tem2 + 1);       cont %= 998244353;     }     cont %= 998244353;     cout << cont;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string p;     cin >> p;     int n;     cin >> n;     bool a = false, b = false;     while (n--) {       string s;       cin >> s;       if (s == p) {         a = true;         b = true;       }       if (s[0] == p[1]) a = true;       if (s[1] == p[0]) b = true;     }     if (a && b)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0;     char ch = getchar();     bool positive = 1;     for (; ch <  0  || ch >  9 ; ch = getchar())       if (ch ==  - ) positive = 0;     for (; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch -  0 ;     return positive ? x : -x;   }   struct node {     int size, key, a;     node *l, *r;     void update() {       size = 1;       if (l) size += l->size;       if (r) size += r->size;     }   }* null = NULL, Pool[1000007];   node* merge(node* a, node* b) {     if (!a) return b;     if (!b) return a;     if (a->key < b->key) {       a->r = merge(a->r, b);       a->update();       return a;     } else {       b->l = merge(a, b->l);       b->update();       return b;     }   }   pair<node*, node*> split(node* a, int n) {     if (!a) return make_pair(null, null);     if (n >= a->size) return make_pair(a, null);     if (!n) return make_pair(null, a);     pair<node*, node*> b;     int cnt = a->l ? a->l->size : 0;     if (cnt >= n) {       b = split(a->l, n);       a->l = b.second;       a->update();       return make_pair(b.first, a);     }     {       b = split(a->r, n - cnt - 1);       a->r = b.first;       a->update();       return make_pair(a, b.second);     }   }   int N, M;   bool done[1000006];   int ans[1000006], tmpx[1000006], tmpk[1000006];   int main() {     N = read(), M = read();     node* root = NULL;     for (int i = 1; i <= N; ++i) {       Pool[i].key = rand();       Pool[i].l = Pool[i].r = NULL;       Pool[i].size = 1;       Pool[i].a = -1;       root = merge(root, Pool + i);     }     for (int i = 1; i <= M; ++i) tmpx[i] = read(), tmpk[i] = read();     for (int i = M; i; --i) {       int x = tmpx[i], k = tmpk[i];       pair<node*, node*> A = split(root, 1);       pair<node*, node*> B = split(A.second, k - 1);       node *a = A.first, *b = B.first, *c = B.second;       if (a->a == -1) {         if (done[x]) {           printf( -1 n );           return 0;         }         a->a = x;       } else {         if (a->a != x) {           printf( -1 n );           return 0;         }       }       done[x] = 1;       root = merge(merge(b, a), c);     }     for (int i = 1; i <= N; ++i) {       pair<node*, node*> A = split(root, 1);       ans[i] = A.first->a;       root = A.second;     }     for (int i = 1, j = 1; i <= N; ++i) {       while (done[j]) ++j;       if (ans[i] == -1) {         ans[i] = j;         done[j] = 1;       }     }     for (int i = 1; i <= N; ++i) printf( %d%c , ans[i], i < N ?     :   n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 310;   int can[maxn][maxn];   int p[maxn];   int main() {     ios ::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> p[i];     char k;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         cin >> k;         can[i][j] = k -  0 ;       }     for (int i = 1; i <= n; i++) can[i][i] = 1;     for (int k = 1; k <= n; k++)       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++)           if (can[i][k] && can[k][j]) can[i][j] = 1;     for (int i = 1; i < n; i++)       for (int j = i + 1; j <= n; j++)         if (p[i] > p[j] && can[i][j]) swap(p[i], p[j]);     for (int i = 1; i <= n; i++) cout << p[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long n, ans = 0;     long count = 0;     cin >> n;     string s;     cin >> s;     while (s.size() && s[0] == s.back()) {       count++;       s.pop_back();     }     if (s.empty()) {       if (count <= 2) {         cout <<  0  << endl;         return;       } else if (count == 3) {         cout <<  1  << endl;         return;       } else {         long temp = (count + 2) / 3;         cout << temp << endl;         return;       }     }     s.push_back( & );     for (long i = 0; i < s.size() - 1; i++) {       count++;       if (s[i] != s[i + 1]) {         ans += count / 3;         count = 0;       }     }     cout << ans << endl;   }   int main() {     long t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool chmax(T &a, const T &b) {     return (a < b) ? (a = b, 1) : 0;   }   template <class T>   bool chmin(T &a, const T &b) {     return (b < a) ? (a = b, 1) : 0;   }   using ll = long long;   using R = long double;   const R EPS = 1e-9L;   inline int sgn(const R &r) { return (r > EPS) - (r < -EPS); }   inline R sq(R x) { return sqrt(max(x, 0.0L)); }   const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};   const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};   const pid_t pid = getpid();   int ary[50010][5];   int main(void) {     int t;     cin >> t;     for (int loop = int(0); loop < int(t); ++loop) {       int n;       cin >> n;       for (int i = int(0); i < int(n); ++i)         for (int j = int(0); j < int(5); ++j) {           cin >> ary[i][j];         }       int best = 0;       for (int i = int(0); i < int(n); ++i) {         int cnt = 0;         for (int j = int(0); j < int(5); ++j) {           if (ary[i][j] < ary[best][j]) {             cnt++;           }         }         if (cnt >= 3) {           best = i;         }       }       int ans = -1;       bool ok = true;       for (int i = int(0); i < int(n); ++i) {         int cnt = 0;         if (i == best) {           continue;         }         for (int j = int(0); j < int(5); ++j) {           if (ary[best][j] < ary[i][j]) {             cnt++;           }         }         if (cnt < 3) {           ok = false;         }       }       if (ok) {         ans = best + 1;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void minimize(int &x, int y) { x = min(x, y); }   inline void maximize(int &x, int y) { x = max(x, y); }   const int N = 200000 + 1067;   int n, m;   int val[N], pos[N], it[N], res[N];   vector<int> to[N];   struct Node {     int id, a;   } node[N];   bool comp(Node c1, Node c2) {     return c1.a < c2.a || (c1.a == c2.a && c1.id > c2.id);   }   void update(int x, int c) {     while (x <= n) {       it[x] += c;       x += x & (-x);     }   }   int get(int x) {     int res = 0;     while (x) {       res += it[x];       x -= x & (-x);     }     return res;   }   int bs(int l, int r, int c) {     while (l < r) {       if (l == r - 1)         if (get(l) >= c)           return l;         else           return r;       int mid = (l + r) / 2;       if (get(mid) >= c)         r = mid;       else         l = mid + 1;     }     return r;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> node[i].a;       node[i].id = i;       val[i] = node[i].a;       update(i, 1);     }     sort(node + 1, node + n + 1, comp);     cin >> m;     for (int i = 1; i <= m; i++) {       int k;       cin >> k >> pos[i];       to[k].push_back(i);     }     for (int i = 1; i <= n; i++) {       int kk = n - i + 1;       for (auto j : to[kk]) {         res[j] = val[bs(1, n, pos[j])];       }       update(node[i].id, -1);     }     for (int i = 1; i <= m; i++) cout << res[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 30;   int n, k;   long long s, ans, a[maxn], fac[maxn];   map<long long, long long> mp[maxn];   void dfs1(int x, int usd, long long now) {     if (x == n / 2 + 1) {       if (mp[usd].find(now) == mp[usd].end())         mp[usd].insert(make_pair(now, 1));       else         mp[usd][now]++;       return;     }     dfs1(x + 1, usd, now);     if (now + a[x] <= s) dfs1(x + 1, usd, now + a[x]);     if (fac[x] && usd < k && fac[x] + now <= s)       dfs1(x + 1, usd + 1, fac[x] + now);   }   void dfs2(int x, int usd, long long now) {     if (x == n + 1) {       for (register int i = 0; i <= k - usd; i++)         if (mp[i].find(s - now) != mp[i].end()) ans += mp[i][s - now];       return;     }     dfs2(x + 1, usd, now);     if (now + a[x] <= s) dfs2(x + 1, usd, now + a[x]);     if (fac[x] && usd < k && fac[x] + now <= s)       dfs2(x + 1, usd + 1, fac[x] + now);   }   int main() {     int i, j;     scanf( %d%d%lld , &n, &k, &s);     for (i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       fac[i] = 1;       for (j = 1; j <= a[i]; j++) {         fac[i] = 1ll * fac[i] * j;         if (fac[i] > s) {           fac[i] = 0;           break;         }       }     }     dfs1(1, 0, 0);     dfs2(n / 2 + 1, 0, 0);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T abs(T x) {     return x > 0 ? x : (-x);   }   template <class T>   T sqr(T x) {     return x * x;   }   const int maxn = 57;   char ty[maxn][maxn];   bool allow[300];   int d[maxn][maxn];   int f[maxn][maxn];   int n, m, k;   int sx, sy, fx, fy;   int Q[maxn * maxn * 2];   int qs, qt;   const int dx[] = {-1, 0, 0, 1};   const int dy[] = {0, -1, 1, 0};   void bfs() {     d[sx][sy] = 0;     qs = 0, qt = 0;     Q[qs++] = sx * maxn + sy;     while (qs > qt) {       int x = Q[qt] / maxn;       int y = Q[qt] % maxn;       if (x == fx && y == fy) break;       ++qt;       for (int dir = 0; dir < 4; ++dir) {         int X = x + dx[dir], Y = y + dy[dir];         if (X < 0 || Y < 0 || X >= n || Y >= m) continue;         if (d[X][Y] != -1) continue;         if (!allow[ty[X][Y]]) continue;         d[X][Y] = d[x][y] + 1;         f[X][Y] = x * maxn + y;         Q[qs++] = X * maxn + Y;       }     }   }   string cur;   string rf[maxn][maxn];   bool uf[maxn][maxn];   void rest() {     memset(uf, 0, sizeof(uf));     rf[sx][sy] =  S ;     qs = 0, qt = 0;     uf[sx][sy] = true;     Q[qs++] = sx * maxn + sy;     while (qs > qt) {       int x = Q[qt] / maxn;       int y = Q[qt] % maxn;       if (x == fx && y == fy) break;       ++qt;       string& s = rf[x][y];       for (int dir = 0; dir < 4; ++dir) {         int X = x + dx[dir], Y = y + dy[dir];         if (X < 0 || Y < 0 || X >= n || Y >= m) continue;         if (d[X][Y] != d[x][y] + 1) continue;         if (!uf[X][Y]) {           uf[X][Y] = true;           rf[X][Y] = rf[x][y] + ty[X][Y];           Q[qs++] = X * maxn + Y;         } else {           rf[X][Y] = min(rf[X][Y], rf[x][y] + ty[X][Y]);         }       }     }     cur = rf[fx][fy];   }   int main() {     cin >> n >> m >> k;     for (int i = 0; i < n; ++i) {       string s;       cin >> s;       for (int j = 0; j < m; ++j) {         ty[i][j] = s[j];         if (islower(s[j])) {           continue;         }         if (s[j] ==  S )           sx = i, sy = j;         else           fx = i, fy = j;       }     }     int res = 100500100;     string rs;     bool rsf = false;     set<long long> S;     for (int i =  a ; i <=  z ; ++i)       for (int j =  a ; j <= i; ++j)         for (int p =  a ; p <= j; ++p)           for (int q =  a ; q <= p; ++q) {             long long h = 123;             if (k >= 1) h = h * 2184057 + i;             if (k >= 2) h = h * 2184057 + j;             if (k >= 3) h = h * 2184057 + p;             if (k >= 4) h = h * 2184057 + q;             if (S.count(h)) continue;             S.insert(h);             memset(allow, 0, sizeof(allow));             if (k >= 1) allow[i] = true;             if (k >= 2) allow[j] = true;             if (k >= 3) allow[p] = true;             if (k >= 4) allow[q] = true;             allow[ S ] = allow[ T ] = true;             memset(d, -1, sizeof(d));             bfs();             if (d[fx][fy] == -1) continue;             if (d[fx][fy] > res) continue;             if (res > d[fx][fy]) res = d[fx][fy];           }     S.clear();     int bad = 1000000;     for (int i =  a ; i <=  z ; ++i)       for (int j =  a ; j <= i; ++j)         for (int p =  a ; p <= j; ++p)           for (int q =  a ; q <= p; ++q) {             if (i >= bad && j >= bad && p >= bad && q >= bad) continue;             long long h = 123;             if (k >= 1) h = h * 2184057 + i;             if (k >= 2) h = h * 2184057 + j;             if (k >= 3) h = h * 2184057 + p;             if (k >= 4) h = h * 2184057 + q;             if (S.count(h)) continue;             S.insert(h);             memset(allow, 0, sizeof(allow));             if (k >= 1) allow[i] = true;             if (k >= 2) allow[j] = true;             if (k >= 3) allow[p] = true;             if (k >= 4) allow[q] = true;             allow[ S ] = allow[ T ] = true;             memset(d, -1, sizeof(d));             bfs();             if (d[fx][fy] == -1) continue;             if (d[fx][fy] > res) continue;             rest();             if (!rsf || cur < rs) {               rsf = true, rs = cur;               bad = -1;               for (int t = 0; t < ((int)(cur).size()); ++t)                 bad = max(bad, (int)cur[t]);             }           }     if (res == 100500100) res = -1;     if (res == -1)       cout << res <<   n ;     else       cout << rs.substr(1, ((int)(rs).size()) - 2) <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:200000000 )   using namespace std;   template <typename T>   inline T Abs(T x) {     return (x >= 0) ? x : -x;   }   template <typename T>   inline T sqr(T x) {     return x * x;   }   template <typename T>   inline string toStr(T x) {     stringstream st;     st << x;     string s;     st >> s;     return s;   }   template <typename T>   inline int bit(T mask, int b) {     return (b >= 0 && (mask & (T(1) << b)) != 0) ? 1 : 0;   }   inline int nextInt() {     int x;     if (scanf( %d , &x) != 1) throw;     return x;   }   inline long long nextInt64() {     long long x;     if (scanf( %I64d , &x) != 1) throw;     return x;   }   inline double nextDouble() {     double x;     if (scanf( %lf , &x) != 1) throw;     return x;   }   const int INF = (int)1E9;   const long long INF64 = (long long)1E18;   const long double EPS = 1E-9;   const long double PI = 3.1415926535897932384626433832795;   int main() {     int n = nextInt();     long long k = nextInt64();     long long sum = 0;     int pos = 1, cnt = n;     for (int i = 0; i < (int)(n); i++) {       long long a = nextInt();       long long d = sum - a * (pos - 1) * (cnt - pos);       if (d < k) {         printf( %d n , i + 1);         cnt--;       } else {         sum += (pos - 1) * a;         pos++;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long read() {     long long t = 0, f = 1;     char c = getchar();     while (!isdigit(c)) f = c ^ 45, c = getchar();     while (isdigit(c)) t = (t << 1) + (t << 3) + (c ^ 48), c = getchar();     return f ? t : -t;   }   const long long N = 5021, inf = 1e18;   long long n, m, a[N], f[N], dp[2][N];   int main() {     n = read();     for (int i = 1; i <= n; ++i) f[i] = a[i] = read();     sort(f + 1, f + 1 + n), m = unique(f + 1, f + 1 + n) - f - 1;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         dp[i & 1][j] = min(j == 1 ? inf : dp[i & 1][j - 1],                            dp[i - 1 & 1][j] + abs(a[i] - f[j]));     printf( %lld , dp[n & 1][m]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> isbandyk(int a, vector<int> prad) {     vector<int> rez;     vector<int> ats(prad.size(), -1);     int pas = 0;     for (int i = 0; i < prad.size(); i++) {       if (prad[i] <= a - 1) {         rez.push_back(prad[i]);         pas = i;         ats[i] = 1;       }     }     for (int i = pas + 1; i < prad.size(); i++) {       if (prad[i] == a) {         rez.push_back(prad[i]);         ats[i] = 1;       }     }     for (int i = 0; i < prad.size(); i++) {       if (prad[i] > a) {         rez.push_back(prad[i]);         ats[i] = 2;       } else if (prad[i] == a && i < pas) {         rez.push_back(prad[i]);         ats[i] = 2;       }     }     sort(prad.begin(), prad.end());     if (prad == rez) {       return ats;     } else {       vector<int> c;       return c;     }     return ats;   }   int main(int argc, const char* argv[]) {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> eil;       for (int i = 0; i < n; i++) {         char a;         cin >> a;         int b = a -  0 ;         eil.push_back(b);       }       bool taip = false;       for (int i = 0; i < 10; i++) {         vector<int> b = isbandyk(i, eil);         if (b.size() != 0) {           for (int i = 0; i < b.size(); i++) cout << b[i];           taip = true;           break;         }       }       if (!taip) cout <<  - ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     long long arr[n];     vector<long long> prime(200010);     vector<long long> temp;     for (long long i = 2; i <= sqrt(200010); i++) {       if (prime[i] == 1) continue;       for (long long j = 2; i * j < 200010; j++) prime[i * j] = 1;     }     for (long long i = 2; i < 200010; i++) {       if (prime[i] == 0) temp.push_back(i);     }     for (long long i = 0; i < n; i++) cin >> arr[i];     map<long long, vector<long long> > m;     for (long long i = 0; i < n; i++) {       long long a = arr[i];       for (long long j = 0; j < temp.size(); j++) {         if (a == 1) break;         long long c = 0;         if (temp[j] > sqrt(a)) {           m[a].push_back(1);           break;         }         while (a % temp[j] == 0 && a != 1) {           a /= temp[j];           c++;         }         if (c) m[temp[j]].push_back(c);       }     }     long long ans = 1;     for (long long i = 0; i < temp.size(); i++) {       if (m[temp[i]].size() < n - 1) continue;       sort(m[temp[i]].begin(), m[temp[i]].end());       long long o;       if (m[temp[i]].size() == n - 1)         o = m[temp[i]][0];       else         o = m[temp[i]][1];       while (o--) ans = ans * temp[i];     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     string str;     cin >> str;     bool flag = false;     for (int i = 0; i < str.size(); i++) {       if (str[i] ==  H  || str[i] ==  Q  || str[i] ==  9 ) {         flag = true;         break;       }     }     if (flag)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = (1 << 20);   priority_queue<pair<int, int> > Q[MX];   string str;   int n, K;   int main() {     cin >> str >> K;     n = str.size();     int cur = 0;     for (int j = 0; j < n; j++) Q[0].push(make_pair( z  - str[j], j));     while (1) {       while (cur > -1 && Q[cur].empty()) cur--;       if (cur == -1) break;       int let = Q[cur].top().first;       while (!Q[cur].empty() && Q[cur].top().first == let) {         int pos = Q[cur].top().second;         if (pos + cur + 1 < n)           Q[cur + 1].push(make_pair( z  - str[pos + cur + 1], pos));         K--;         if (K == 0) {           cout << str.substr(pos, cur + 1);           return 0;         }         Q[cur].pop();       }       cur++;     }     puts( No such line. );   }


#include <bits/stdc++.h>   const int MAXN = 100005;   using namespace std;   int n, m, q, v, u, a;   vector<int> E[MAXN], c[MAXN];   int L[MAXN], P[MAXN][17], M[MAXN][17][10], res[20], aux[20], cc[10];   void dfs(int cur, int prev) {     P[cur][0] = prev;     L[cur] = L[prev] + 1;     for (auto to : E[cur])       if (to != prev) dfs(to, cur);   }   void precalc() {     for (int j = 1; (1 << j) <= n; j++)       for (int i = 1; i <= n; i++) P[i][j] = P[P[i][j - 1]][j - 1];     for (int j = 1; (1 << j) <= n; j++) {       for (int i = 1; i <= n; i++) {         fill(aux, aux + 20, 1000000);         merge(M[i][j - 1], M[i][j - 1] + 10, M[P[i][j - 1]][j - 1],               M[P[i][j - 1]][j - 1] + 10, aux);         for (int h = 0; h < 10; h++) M[i][j][h] = aux[h];       }     }   }   int LCA(int x, int y) {     if (L[x] < L[y]) swap(x, y);     for (int j = 16; j >= 0; j--)       if (L[x] - (1 << j) >= L[y]) {         merge(res, res + 10, M[x][j], M[x][j] + 10, aux);         for (int h = 0; h < 10; h++) res[h] = aux[h];         x = P[x][j];       }     if (x == y) return x;     for (int j = 16; j >= 0; j--)       if (P[x][j] != 0 && P[x][j] != P[y][j]) {         merge(res, res + 10, M[x][j], M[x][j] + 10, aux);         for (int h = 0; h < 10; h++) res[h] = aux[h];         merge(res, res + 10, M[y][j], M[y][j] + 10, aux);         for (int h = 0; h < 10; h++) res[h] = aux[h];         x = P[x][j];         y = P[y][j];       }     merge(res, res + 10, M[x][0], M[x][0] + 10, aux);     for (int h = 0; h < 10; h++) res[h] = aux[h];     merge(res, res + 10, M[y][0], M[y][0] + 10, aux);     for (int h = 0; h < 10; h++) res[h] = aux[h];     return P[x][0];   }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i < n; i++) {       scanf( %d%d , &v, &u);       E[v].emplace_back(u);       E[u].emplace_back(v);     }     for (int i = 1; i <= m; i++) {       scanf( %d , &a);       c[a].emplace_back(i);     }     dfs(1, 0);     for (int i = 0; i <= n; i++)       for (int j = 0; (1 << j) <= n; j++)         for (int h = 0; h < 10; h++) M[i][j][h] = 1000000;     for (int i = 1; i <= n; i++) sort((c[i]).begin(), (c[i]).end());     for (int i = 1; i <= n; i++)       for (int h = 0; h < min((int)c[i].size(), 10); h++) M[i][0][h] = c[i][h];     precalc();     while (q--) {       scanf( %d%d%d , &v, &u, &a);       fill(cc, cc + 20, 1000000);       fill(res, res + 20, 1000000);       int lca = LCA(v, u), sz = 0;       for (int h = 0; h < min((int)c[lca].size(), 10); h++) cc[h] = c[lca][h];       merge(res, res + 10, cc, cc + 10, aux);       for (int h = 0; h < min(a, 10) && aux[h] != 1000000; h++) sz++;       printf( %d  , sz);       for (int h = 0; h < sz; h++) printf( %d  , aux[h]);       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     while (t--) {       long long d;       cin >> d;       long long dis = d * d - 4 * d;       if (dis < 0) {         cout <<  N n ;         continue;       } else {         double sq = sqrt(dis);         double b = (d + sq) / 2.0;         if (b == 1) {           cout <<  N n ;           continue;         } else           printf( Y %.9f %.9f n , abs(b), abs(b / (b - 1)));       }     }   }


#include <bits/stdc++.h>   using namespace std;   using namespace std::chrono;   long double PI = 3.14159265358979323846;   using ll = long long;   const ll modo = 1000000000;   const ll inf = LONG_LONG_MAX;   const ll ms = (2e6) + 5;   ll peil(ll a, ll b) {     if (a % b) return a / b + 1;     return a / b;   }   long double help(long double mid, long double k, long double val, ll pp,                    long double t) {     ll tmp = mid;     ll dd = tmp / pp;     long double rem = mid - (dd * pp);     long double ans = dd * val;     long double hh = min(rem, k);     ans += hh;     rem -= hh;     ans += (rem / 2);     return ans;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);     cout << fixed << setprecision(10);     ll k, d, t;     cin >> k >> d >> t;     long double kk = peil(k, d) * d;     long double tt = k + ((kk - k) / 2);     long double l = t;     long double r = 2 * t;     long double mid;     long double ans = r;     long double res;     long double pp = 1 / (1e9);     while ((r - l) > pp) {       mid = (l + r) / 2;       res = help(mid, k, tt, kk, t);       if (res == t) {         cout << mid;         return 0;       }       if (res > t) {         r = mid;         ans = min(ans, mid);       } else         l = mid;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, n, r, S, Z, s1, s2, s3, s4, s5, s6, s7, s8, x, y, z, m, j, l, k,         t;     long long a[200045];     long long b[200045];     long long c[100001];     long long d[100001];     long long e[1000001];     pair<long long, long long> aa[100001];     double w, u, v, uu, vv;     string q1;     string q2;     string q3;     string q4;     string s;     string sq[3001];     string qs[3001];     map<long long, long long> g;     map<long long, long long>::iterator it;     cin >> n >> k;     for (i = 0; i < n; i++) {       cin >> x;       a[i % k] = x + a[i % k];     }     t = 1234567894525;     for (i = 0; i < k; i++) {       if (t > a[i]) {         x = i;         t = a[i];       }     }     cout << x + 1;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > mas[2];   int a[(int)1e5 + 10], b[(int)1e5 + 10];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       int a = abs((x + y) % 2);       mas[a].push_back({(x + y - a) / 2, (x - y - a) / 2});     }     long long ans = 0;     for (int i = 0; i < 2; i++) {       sort(mas[i].begin(), mas[i].end());       a[mas[i].size()] = (int)-3e5;       b[mas[i].size()] = (int)3e6;       for (int j = (int)mas[i].size() - 1; j >= 0; j--) {         a[j] = max(a[j + 1], mas[i][j].second);         b[j] = min(b[j + 1], mas[i][j].second);       }       int c = (int)-3e5;       int d = (int)3e5;       for (int j = 0; j + 2 < (int)mas[i].size(); j++) {         c = max(c, mas[i][j].second);         d = min(d, mas[i][j].second);         long long le = max(b[j + 1], d);         long long ri = min(a[j + 1], c);         if (ri > le) {           ans += (ri - le) * (mas[i][j + 1].first - mas[i][j].first);         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool compare(const pair<int, int>& i, const pair<int, int>& j) {     return i.first < j.first;   }   int main() {     string r, s;     cin >> r >> s;     vector<int> v;     if (r.length() != s.length()) {       cout <<  NO             <<   n ;       return 0;     }     for (int i = 0; i < s.length(); i++) {       if (s[i] != r[i]) {         v.push_back(i);       }     }     if (v.size() != 2)       cout <<  NO             <<   n ;     else {       if (s[v[0]] == r[v[1]] && s[v[1]] == r[v[0]])         cout <<  YES ;       else         cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     char n[100];     scanf( %s , n);     int l = strlen(n);     int t = 0;     for (int i = 0; i < l; i++) {       if (n[i] ==  4  || n[i] ==  7 ) {         t += 1;       }     }     if (t == 4 || t == 7) {       printf( YES );     } else {       printf( NO );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x = 0;     cin >> n;     char ch[n];     for (int i = 0; i < n; i++) {       cin >> ch[i];     }     cout << n + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const sqN = 320;   int add(int a, int b);   int sub(int a, int b);   int arr[100005];   struct query {     int index;     int l;     int r;     int ans;   };   bool comp(query &a, query &b) {     if (a.l / sqN != b.l / sqN) {       return a.l / sqN < b.l / sqN;     }     return a.r < b.r;   }   bool comp_by_index(query &a, query &b) { return a.index < b.index; }   int main() {     int n, m, aux, l, r, cnt;     cin >> n >> m;     vector<int> F;     F.push_back(0);     for (int i = 0; i < n; i++) {       cin >> aux;       if (aux > 100000) aux = 0;       F.push_back(aux);     }     vector<query> Q;     for (int i = 0; i < m; i++) {       cin >> l >> r;       query inp;       inp.index = i;       inp.l = l;       inp.r = r;       Q.push_back(inp);     }     sort(Q.begin(), Q.end(), comp);     memset(arr, 0, sizeof(arr));     r = 1;     l = 0;     cnt = (F[1] == 1) ? 1 : 0;     arr[F[1]] += 1;     for (int i = 0; i < m; i++) {       query curq = Q[i];       while (r < Q[i].r) {         r++;         cnt += sub(arr[F[r]], F[r]);         arr[F[r]] += 1;         cnt += add(arr[F[r]], F[r]);       }       while (l < Q[i].l - 1) {         l++;         cnt += sub(arr[F[l]], F[l]);         arr[F[l]] -= 1;         cnt += add(arr[F[l]], F[l]);       }       while (l >= Q[i].l) {         cnt += sub(arr[F[l]], F[l]);         arr[F[l]] += 1;         cnt += add(arr[F[l]], F[l]);         l--;       }       while (r > Q[i].r) {         cnt += sub(arr[F[r]], F[r]);         arr[F[r]] -= 1;         cnt += add(arr[F[r]], F[r]);         r--;       }       Q[i].ans = cnt;     }     sort(Q.begin(), Q.end(), comp_by_index);     for (int i = 0; i < Q.size(); i++) cout << Q[i].ans << endl;   }   int add(int a, int b) {     if (b > 0 and b == a) return 1;     return 0;   }   int sub(int a, int b) {     if (b > 0 and b == a) return -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, i, j, k, t;   string s, m;   int main() {     cin >> s >> n;     for (i = 0; i <= s.length(); i++) {       if (s[i] !=  _  && isupper(s[i])) s[i] = tolower(s[i]);       if (s[i] ==  o )         s[i] =  0 ;       else if (s[i] ==  l  || s[i] ==  i )         s[i] =  1 ;     }     for (t = 1; t <= n; t++) {       cin >> m;       for (j = 0; j <= m.length(); j++) {         if (m[j] !=  _  && isupper(m[j])) m[j] = tolower(m[j]);         if (m[j] ==  o )           m[j] =  0 ;         else if (m[j] ==  i  || m[j] ==  l )           m[j] =  1 ;       }       if (m == s) k = 1;     }     if (k == 1)       cout <<  No ;     else       cout <<  Yes ;     cin >> n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<stack<int> > vs;     int maxi = -1, maximum = 0, nbVertices, n, type[100009], destination[100009],         source[100009];     cin >> n;     vs = vector<stack<int> >(n);     for (int i = 0; i < n; ++i) {       source[i] = 0;     }     for (int i = 0; i < n; ++i) {       cin >> type[i];     }     for (int i = 0; i < n; ++i) {       cin >> destination[i];       destination[i] -= 1;       if (destination[i] != -1) source[destination[i]]++;     }     for (int i = 0; i < n; ++i) {       if (type[i]) {         int j = i;         nbVertices = 1;         while (source[destination[j]] == 1 && destination[j] != -1) {           ++nbVertices;           vs[i].push(j + 1);           j = destination[j];         }         vs[i].push(j + 1);         if (maximum < nbVertices) {           maximum = nbVertices;           maxi = i;         }       }     }     cout << maximum << endl;     while (vs[maxi].size()) {       int top = vs[maxi].top();       cout << top <<    ;       vs[maxi].pop();     }     cout << endl;     return 0;   }


#include<bits/stdc++.h>   using namespace std;   typedef long long int lli;   const lli N = 1000009, K =  z  -  a  + 1;   string s, t;   lli n, k, a[K], b[K];   void Solve() {       for(int i = 0; i < K - 1; i++) {           while(a[i] > b[i] && a[i] >= k) {               a[i] -= k;               a[i + 1] += k;           }       }       for(int i = 0; i < K; i++) {           if(a[i] != b[i]) {               cout<< No <<endl;               return ;           }       }       cout<< Yes <<endl;   }   void Inp() {       lli ntest;       cin>>ntest;       while(ntest--) {           cin>>n>>k>>s>>t;           for(int i = 0; i < K; i++) {               a[i] = 0;               b[i] = 0;           }           for(int i = 0; i < n; i++) {               a[s[i] -  a ]++;               b[t[i] -  a ]++;           }           Solve();       }   }   int main() {       ios_base::sync_with_stdio(0);       cin.tie(NULL);       cout.tie(NULL);       //freopen( inp.inp , r ,stdin);       Inp();   }


#include <bits/stdc++.h>   const int N = (int)1e5 + 7;   const int MOD = (int)1e9 + 7;   const long long INF = (long long)1e18;   using namespace std;   bool solve(vector<int> &A, int n) {     for (int i = 1; i < n; i++) {       if (A[i] > A[i - 1]) {         return true;       }     }     for (int i = 1; i < n; i++) {       if (A[i] == A[i - 1]) return true;     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> A(n);       for (int i = 0; i < n; i++) cin >> A[i];       cout << (solve(A, n) ?  YES  :  NO ) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, val =  ><+-.,[] ;     cin >> s;     long long int size = 0;     for (int i = 0; i < s.size(); i++) {       size = (size * 16 + val.find(s[i]) + 8) % 1000003;     }     cout << size;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2010;   int n, m, l, r, k, a[MAXN], b[MAXN];   int main() {     ios::sync_with_stdio(0);     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       if (a[i] <= m) {         b[a[i]]++;       }     }     r = n / m;     l = 1;     for (int i = 1; i <= n; ++i) {       while (l <= m && b[l] >= r) {         l++;       }       if (l > m) {         break;       }       if (a[i] > m || b[a[i]] > r) {         if (a[i] <= m) {           b[a[i]]--;         }         a[i] = l;         b[l]++;         k++;       }     }     cout << r <<     << k <<   n ;     for (int i = 1; i <= n; ++i) {       cout << a[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   void JaiMataDi() {     int n;     cin >> n;     string a, b;     cin >> a >> b;     int cnt = 0;     for (int i = 0; i < n; i++) {       if ((a[i] ==  0 ) and (b[i] ==  1 ))         cnt += 2;       else if ((a[i] ==  1 ) and (b[i] ==  0 ))         cnt += 2;       else if ((a[i] ==  0 ) and (b[i] ==  0 )) {         if (i + 1 < n) {           if ((a[i + 1] ==  1 ) and (b[i + 1] ==  1 ))             cnt += 2, i++;           else             cnt += 1;         } else           cnt += 1;       } else if ((a[i] ==  1 ) and (b[i] ==  1 )) {         if (i + 1 < n) {           if ((a[i + 1] ==  0 ) and (b[i + 1] ==  0 )) cnt += 2, i++;         }       }     }     cout << cnt <<   n ;   }   int main() {     int t;     cin >> t;     while (t--) JaiMataDi();   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:500000000 )   using namespace std;   int main() {     int n, i, s;     scanf( %d %d , &n, &s);     vector<int> a(n);     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     sort(a.begin(), a.end());     long long res = 0;     int pos = n / 2;     if (a[pos] <= s) {       for (i = pos; i < n; i++) res += max(0, s - a[i]);     } else {       for (i = 0; i <= pos; i++) res += max(0, a[i] - s);     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   void sc(char& c) {     char temp[4];     scanf( %s , temp);     c = temp[0];   }   struct debugger {     template <typename T>     debugger& operator,(const T& v) {       cerr << v <<    ;       return *this;     }   } dbg;   int testnum;   int a, b;   int lens[11];   void preprocess() {     lens[1] = 3;     for (int i = 2; i <= 10; i++) lens[i] = 4 * lens[i - 1] + 3;   }   pair<int, int> recurse(int a, int b) {     if (a == 1) {       if (b == 0) return make_pair(0, 0);       if (b == 1) return make_pair(0, 1);       if (b == 2) return make_pair(1, 1);       if (b == 3) return make_pair(1, 0);     }     int z = lens[a - 1];     if (b <= z) {       pair<int, int> ret = recurse(a - 1, b);       return make_pair(ret.second, ret.first);     }     b -= z + 1;     if (b <= z) {       pair<int, int> ret = recurse(a - 1, b);       return make_pair(ret.first, ret.second + (1 << (a - 1)));     }     b -= z + 1;     if (b <= z) {       pair<int, int> ret = recurse(a - 1, b);       return make_pair(ret.first + (1 << (a - 1)), ret.second + (1 << (a - 1)));     }     b -= z + 1;     if (b <= z) {       pair<int, int> ret = recurse(a - 1, b);       return make_pair((1 << a) - 1 - ret.second, (1 << (a - 1)) - 1 - ret.first);     }   }   void solve() {     pair<int, int> ret = recurse(a, b);     printf( %d %d n , ret.first, ret.second);   }   bool input() {     scanf( %d , &a);     scanf( %d , &b);     return true;   }   int main() {     preprocess();     int T = 1;     for (testnum = 1; testnum <= T; testnum++) {       if (!input()) break;       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   const int mod = 1e9 + 7;   const int M = 2010;   pair<int, int> p[M];   int n, m, k, s, x, y, cnt;   int fac[2 * N], inv[2 * N], K[30], f[M][30];   bool pd1, pd2;   int Pow(int a, int b) {     if (b == 0) return 1;     int ret = Pow(a, b / 2);     ret = 1LL * ret * ret % mod;     if (b & 1) ret = 1LL * ret * a % mod;     return ret;   }   int com(int n, int m) {     if (m > n) return 0;     return 1LL * fac[n] * inv[m] % mod * inv[n - m] % mod;   }   int cal(int i, int j) {     if (p[i].first > p[j].first || p[i].second > p[j].second) return 0;     return com(p[j].first - p[i].first + p[j].second - p[i].second,                p[j].first - p[i].first);   }   int main() {     fac[0] = inv[0] = 1;     for (int i = 1; i < 2 * N; i++) fac[i] = 1LL * fac[i - 1] * i % mod;     for (int i = 1; i < 2 * N; i++) inv[i] = Pow(fac[i], mod - 2);     scanf( %d%d%d%d , &n, &m, &k, &s);     for (int i = 0; i < k; i++) {       scanf( %d%d , &x, &y);       if (x == 1 && y == 1) pd1 = true;       if (x == n && y == m) pd2 = true;       p[i] = make_pair(x, y);     }     if (n == 1 && m == 1) {       if (pd1)         printf( %d n , (s + 1) / 2);       else         printf( %d n , s);       return 0;     }     p[k] = make_pair(1, 1);     p[k + 1] = make_pair(n, m);     sort(p, p + k + 2);     if (pd1) s = (s + 1) / 2;     for (int tmp = s; tmp != 1; tmp = (tmp + 1) / 2) K[cnt++] = tmp;     K[cnt++] = 1;     int tot = 0;     for (int i = 0; i < k + 2; i++)       if (i == 0 || p[i] != p[i - 1]) p[tot++] = p[i];     f[0][0] = 1;     for (int i = 1; i < tot - 1; i++) {       int tmp = 0;       for (int j = 1; j < cnt; j++) {         f[i][j] = com(p[i].first - 1 + p[i].second - 1, p[i].first - 1);         f[i][j] = (f[i][j] - tmp) % mod;         for (int q = 0; q < i; q++)           f[i][j] = (f[i][j] - 1LL * f[q][j] * cal(q, i) % mod) % mod;         tmp = (tmp + f[i][j]) % mod;       }     }     if (!pd2) {       int tmp = 0;       for (int j = 0; j < cnt; j++) {         f[tot - 1][j] = com(p[tot - 1].first - 1 + p[tot - 1].second - 1,                             p[tot - 1].first - 1);         f[tot - 1][j] = (f[tot - 1][j] - tmp) % mod;         for (int q = 0; q < tot - 1; q++)           f[tot - 1][j] =               (f[tot - 1][j] - 1LL * f[q][j + 1] * cal(q, tot - 1) % mod) % mod;         tmp = (tmp + f[tot - 1][j]) % mod;       }     } else {       int tmp = 0;       for (int j = 1; j < cnt - 1; j++) {         f[tot - 1][j] = com(p[tot - 1].first - 1 + p[tot - 1].second - 1,                             p[tot - 1].first - 1);         f[tot - 1][j] = (f[tot - 1][j] - tmp) % mod;         for (int q = 0; q < tot - 1; q++)           f[tot - 1][j] =               (f[tot - 1][j] - 1LL * f[q][j] * cal(q, tot - 1) % mod) % mod;         tmp = (tmp + f[tot - 1][j]) % mod;       }       f[tot - 1][cnt - 1] = (com(p[tot - 1].first - 1 + p[tot - 1].second - 1,                                  p[tot - 1].first - 1) -                              tmp) %                             mod;     }     int ans = 0;     for (int i = 0; i < cnt; i++)       ans = (ans + 1LL * K[i] * f[tot - 1][i] % mod) % mod;     ans = 1LL * ans * Pow(com(n - 1 + m - 1, n - 1), mod - 2) % mod;     ans = (ans + mod) % mod;     printf( %d n , ans);     return 0;   }