#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     while (cin >> n) {       string s;       cin >> s;       string res =   ;       for (int i = 0; i < n; i++) {         if (s[i] <=  1 )           continue;         else {           if (s[i] ==  4 )             res +=  3 , res +=  2 , res +=  2 ;           else {             if (s[i] ==  6 )               res +=  5 , res +=  3 ;             else {               if (s[i] ==  8 )                 res +=  7 , res +=  2 , res +=  2 , res +=  2 ;               else {                 if (s[i] ==  9 )                   res +=  3 , res +=  3 , res +=  2 , res +=  7 ;                 else                   res += s[i];               }             }           }         }       }       sort(res.begin(), res.end());       reverse(res.begin(), res.end());       cout << res << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int i, j, n, ans = 0, k1, k2;       cin >> n;       long long int arr[n];       vector<vector<long long int> > vec(26);       for (i = 0; i < n; i++) {         cin >> arr[i];         vec[arr[i] - 1].push_back(i);       }       long long int dp1[n][26], dp2[n][26];       for (i = 0; i < n; i++)         for (j = 0; j < 26; j++) {           dp1[i][j] = 0;           dp2[i][j] = 0;         }       dp1[0][arr[0] - 1]++;       for (i = 1; i < n; i++) {         for (j = 0; j < 26; j++)           if (arr[i] == j + 1)             dp1[i][j] += dp1[i - 1][j] + 1;           else             dp1[i][j] += dp1[i - 1][j];       }       dp2[n - 1][arr[n - 1] - 1]++;       for (i = n - 2; i >= 0; i--) {         for (j = 0; j < 26; j++)           if (arr[i] == j + 1)             dp2[i][j] += dp2[i + 1][j] + 1;           else             dp2[i][j] += dp2[i + 1][j];       }       for (i = 0; i < 26; i++) {         long long int dd = vec[i].size();         ans = max(ans, dd);       }       for (i = 0; i < 26; i++) {         for (k1 = 0; k1 < vec[i].size(); k1++) {           for (k2 = k1; k2 < vec[i].size(); k2++) {             long long int d1 = vec[i][k1], d2 = vec[i][k2];             for (j = 0; j < 26; j++)               if (i != j)                 ans = max(ans, k2 - k1 + 1 + 2 * min(dp1[d1][j], dp2[d2][j]));           }         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 500005;   long long a[MAX], pre[MAX], suf[MAX], t;   int main() {     int ans = -1, pos = 0, n;     scanf( %d , &n);     for (register int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       pre[i] = pre[i - 1] | a[i];     }     for (register int i = n; i >= 1; i--) suf[i] = suf[i + 1] | a[i];     for (register int i = 1; i <= n; i++) {       t = pre[i - 1] | suf[i + 1];       if ((a[i] | t) - t > ans) {         ans = (a[i] | t) - t;         pos = i;       }     }     printf( %lld  , a[pos]);     for (register int i = 1; i <= n; i++)       if (i != pos) printf( %lld  , a[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   priority_queue<pair<int, string> > all[10010];   int main() {     int n, m;     cin >> n >> m;     string name;     int reg, sc;     for (int i = 0; i < n; i++) {       cin >> name >> reg >> sc;       all[reg].push(make_pair(sc, name));     }     for (int i = 1; i <= m; i++) {       int tt[4];       int tool = 0;       pair<int, string> p[4];       while (all[i].size()) {         p[tool] = all[i].top();         all[i].pop();         tt[tool++] = p[tool].first;         if (tool == 3) break;       }       if (tool == 2) {         cout << p[0].second <<     << p[1].second << endl;       } else {         if (p[0].first == p[2].first || p[1].first == p[2].first) {           cout <<  ?  << endl;         } else {           cout << p[0].second <<     << p[1].second << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n = 1009;   int LG2(int N) {     int ans = 0;     while (N) {       N >>= 1;       ans++;     }     return ans - 1;   }   int main() {     cin.tie(0);     cin.sync_with_stdio(0);     int n;     cin >> n;     map<string, int> M;     int o = 1;     vector<long long> v(n);     vector<string> vv(n);     int ans = 0;     for (int i = 0; i < (n); i++) {       string s;       cin >> s;       ans += s.length();       vv[i] = s;       if (M[s]) {         v[i] = M[s];       } else {         M[s] = o;         v[i] = o;         o++;       }     }     ans += n - 1;     int L = ans;     for (int f = 0; f < n; f++) {       int len = 0;       vector<long long> p;       for (int l = f; l < n; l++) {         len += vv[l].length();         if (l > f) len++;         p.push_back(v[l]);         int pL = l - f + 1;         int cntP = 0;         for (int i = l + 1; i < n; i++) {           int o = i + pL - 1;           if (o > n) continue;           int c = 0;           bool b = 1;           for (int j = i; j <= o; j++) {             if (v[j] == p[c]) {             } else {               b = 0;               break;             }             c++;           }           if (b) {             cntP++;             i = o;           }         }         if (!cntP) continue;         int rB = (len - pL) * (cntP + 1);         ans = min(ans, L - rB);       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define INF 1000000009      int get(int i){       cout <<  ?   << i+1 << endl;       cout.flush();       int a; cin >> a;       int b;       if(i == 0) b = INF;       else{           cout <<  ?   << i << endl;           cout.flush();           cin >> b;       }       return b-a;   }      int main(){       // freopen( input.txt ,  r , stdin);       // freopen( output.txt ,  w , stdout);       ios_base::sync_with_stdio(false);       cin.tie(0);       int n; cin >> n;       if(n == 1){           cout <<  !   << 1 << endl;           cout.flush();           return 0;       }       if(get(1) < 0){           cout <<  !   << 1 << endl;           cout.flush();           return 0;       }       if(get(n-1) > 0){           cout <<  !   << n << endl;           cout.flush();           return 0;       }       int lo = 0, hi = n-1;       while(lo < hi){           int mid = lo+(hi-lo)/2;           if(get(mid) > 0) lo = mid+1;           else hi = mid;       }       cout <<  !   << lo << endl;       cout.flush();   }


#include <bits/stdc++.h>   using namespace std;   int N, M;   int timew, cnt;   stack<int> si;   int low[2000005], dep[2000005], siz[2000005], dfn[2000005], nex[2000005],       las[2000005], Arrive[2000005], st[2000005], cnt1;   bool isin[2000005];   void jt(int xx, int yy) {     cnt++;     nex[cnt] = las[xx];     las[xx] = cnt;     Arrive[cnt] = yy;   }   void tarjan(int noww) {     timew++;     low[noww] = dfn[noww] = timew;     si.push(noww);     isin[noww] = true;     for (int i = las[noww]; i; i = nex[i]) {       if (!dfn[Arrive[i]]) {         tarjan(Arrive[i]);         low[noww] = min(low[noww], low[Arrive[i]]);       } else if (isin[Arrive[i]])         low[noww] = min(low[noww], dfn[Arrive[i]]);     }     if (low[noww] == dfn[noww]) {       cnt1++;       int k = -1;       while (k != noww) {         k = si.top();         si.pop();         isin[k] = false;         st[k] = cnt1;         siz[cnt1]++;       }     }   }   void Clear() {     cnt = 0;     cnt1 = 0;     timew = 0;     for (int i = 1; i <= N; i++)       las[i] = dep[i] = st[i] = siz[i] = dfn[i] = low[i] = dep[i] = 0;   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       scanf( %d%d , &N, &M);       Clear();       for (int i = 1; i <= M; i++) {         int u, v;         scanf( %d%d , &u, &v);         if (u != v) jt(u, v);       }       for (int i = 1; i <= N; i++)         if (!dfn[i]) tarjan(i);       if (siz[st[1]] == N) {         puts( No );         continue;       }       for (int i = 1; i <= N; i++)         for (int j = las[i]; j; j = nex[j])           if (st[i] != st[Arrive[j]]) dep[st[i]]++;       bool flag = false;       for (int i = 1; i <= cnt1; i++) {         if (!dep[i] && siz[i]) {           flag = true;           puts( Yes );           vector<int> ans[2];           for (int j = 1; j <= N; j++) ans[st[j] == i].push_back(j);           printf( %d %d n , ans[1].size(), ans[0].size());           for (auto &i : ans[1]) printf( %d  , i);           cout <<   n ;           for (auto &i : ans[0]) printf( %d  , i);           cout <<   n ;           break;         }       }       if (!flag) puts( No );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   const int inf = 1e9 + 100;   int a[N + 100], b[N + 100];   vector<pair<int, int> > mon[N + 100];   int tree[N * 4 + 100], lazy[N * 4 + 100];   void build(int v, int tl, int tr) {     if (tl == tr) {       tree[v] = -b[tl + 1];       return;     }     int tm = (tl + tr) / 2;     build(v * 2, tl, tm);     build(v * 2 + 1, tm + 1, tr);     tree[v] = max(tree[v * 2], tree[v * 2 + 1]);   }   void push(int v) {     tree[v * 2] += lazy[v];     tree[v * 2 + 1] += lazy[v];     lazy[v * 2] += lazy[v];     lazy[v * 2 + 1] += lazy[v];     lazy[v] = 0;   }   void update(int v, int tl, int tr, int l, int r, int addend) {     if (l > r) {       return;     }     if (tl == l && tr == r) {       tree[v] += addend;       lazy[v] += addend;       return;     }     push(v);     int tm = (tl + tr) / 2;     update(v * 2, tl, tm, l, min(r, tm), addend);     update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, addend);     tree[v] = max(tree[v * 2], tree[v * 2 + 1]);   }   int query(int v, int tl, int tr, int l, int r) {     if (l > r) {       return -inf;     }     if (tl == l && tr == r) {       return tree[v];     }     push(v);     int tm = (tl + tr) / 2;     return max(query(v * 2, tl, tm, l, min(r, tm)),                query(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));   }   int main() {     for (int i = 1; i <= N + 1; i++) {       a[i] = b[i] = inf;     }     int n, m, p;     scanf( %d%d%d , &n, &m, &p);     for (int i = 1; i <= n; i++) {       int cur, cost;       scanf( %d%d , &cur, &cost);       a[cur] = min(cost, a[cur]);     }     int mx = 0;     for (int i = 1; i <= m; i++) {       int cur, cost;       scanf( %d%d , &cur, &cost);       b[cur] = min(cost, b[cur]);       mx = max(mx, cur);     }     for (int i = 1; i <= p; i++) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       mon[x].push_back(make_pair(y, z));     }     for (int i = 1; i <= N; i++) {       sort(mon[i].begin(), mon[i].end());     }     for (int i = N; i > 0; i--) {       a[i] = min(a[i], a[i + 1]);       b[i] = min(b[i], b[i + 1]);     }     build(1, 1, N);     int ans = -a[1] - b[1];     int total = 0;     for (int i = 1; i <= N; i++) {       if (a[i + 1] == inf) {         break;       }       for (auto it : mon[i]) {         update(1, 1, N, it.first, N, it.second);         ans = max(ans, query(1, 1, N, 1, mx - 1) - a[i + 1]);       }     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   char s[500][500];   int di[4] = {-1, 1, 0, 0};   int dj[4] = {0, 0, -1, 1};   typedef int int2d[500][500];   int2d p[26];   int2d d;   struct Pos {     int r, c;     Pos(int r = 0, int c = 0) : r(r), c(c) {}     void init(int r, int c) {       this->r = r;       this->c = c;     }     bool operator<(const Pos& p) const {       int d1 = d[r][c], d2 = d[p.r][p.c];       return d1 < d2 || d1 == d2 && (r < p.r || r == p.r && c < p.c);     }   } wh[27];   int n, m;   bool isDigit(char c) { return c >=  0  && c <=  9 ; }   set<Pos> heap;   void calc(int i, int j, int2d& par) {     memset(d, 127, sizeof(d));     d[i][j] = 0;     heap.insert(Pos(i, j));     while (!heap.empty()) {       Pos p = *heap.begin();       heap.erase(heap.begin());       char ch = s[p.r][p.c];       if (!isDigit(ch) && ch != s[i][j]) {         continue;       }       int cost = (isDigit(ch) ? ch -  0  : 1) + d[p.r][p.c];       for (int dir = 0; dir < 4; dir++) {         int r = p.r + di[dir], c = p.c + dj[dir];         if (r >= 0 && c >= 0 && r < n && c < m && s[r][c] !=  # ) {           if (d[r][c] > cost) {             heap.erase(Pos(r, c));             d[r][c] = cost;             heap.insert(Pos(r, c));             par[r][c] = dir;           }         }       }     }   }   char sm[10000];   int main() {     int k;     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       scanf( %s , s[i]);     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (s[i][j] >=  a  && s[i][j] <=  z ) {           wh[s[i][j] -  a ].init(i, j);           calc(i, j, p[s[i][j] -  a ]);         }       }     }     int r, c;     int r2, c2;     scanf( %d %d %s %d %d , &r, &c, sm, &r2, &c2);     r--, c--;     r2--, c2--;     calc(r2, c2, p[26]);     int len = strlen(sm);     for (int i = 0; i < len && k;) {       char ch = s[r][c];       if (ch == sm[i]) {         i++;         continue;       }       int cost = (isDigit(ch) ? ch -  0  : 1);       int dir = p[sm[i] -  a ][r][c];       if (cost > k) {         k = 0;         break;       }       k -= cost;       r -= di[dir];       c -= dj[dir];     }     while (k > 0 && (r != r2 || c != c2)) {       char ch = s[r][c];       int cost = (isDigit(ch) ? ch -  0  : 1);       if (cost > k) {         k = cost;         exit(1);         break;       }       k -= cost;       int dir = p[26][r][c];       r -= di[dir];       c -= dj[dir];     }     printf( %d %d n , r + 1, c + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T abs(T x) {     return x > 0 ? x : -x;   }   const int tt = 75;   int n;   int m;   int x[100];   int y[100];   int z[100];   vector<int> v;   vector<int> w[300];   int res[301][301][2];   int was[301][301][2];   map<int, int> num;   int f[300];   int calc() {     vector<pair<int, int> > v;     for (int i = 0; i < n; i++)       if (z[i]) {         v.push_back(make_pair(x[i], 1));         v.push_back(make_pair(x[i] + y[i], -1));       } else {         v.push_back(make_pair(x[i] - y[i], 1));         v.push_back(make_pair(x[i], -1));       }     sort((v).begin(), (v).end());     int cur = 0, bal = 0;     for (int i = 0; i + 1 < 2 * n; i++) {       bal += v[i].second;       if (bal) cur += v[i + 1].first - v[i].first;     }     return cur;   }   int go(int i, int j, int t) {     if (j < i) {       t = 0;       j = i;     }     if (i == ((int)(v).size())) return 0;     if (was[i][j][t]) return res[i][j][t];     was[i][j][t] = 1;     int cur = go(i + 1, j, t);     if ((!t || i < j) && f[i] > j)       cur = max(cur, go((t ? j : i) + 1, f[i], 0) + (v[f[i]] - v[j]));     for (int k = 0; k < ((int)(w[i]).size()); k++)       if (w[i][k] > j)         cur = max(cur, go((t ? j : i) + 1, w[i][k], 1) + (v[w[i][k]] - v[j]));     return res[i][j][t] = cur;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d%d , &x[i], &y[i]);       v.push_back(x[i] - y[i]);       v.push_back(x[i]);       v.push_back(x[i] + y[i]);     }     sort((v).begin(), (v).end());     v.resize(unique((v).begin(), (v).end()) - v.begin());     for (int i = 0; i < ((int)(v).size()); i++) num[v[i]] = i;     for (int i = 0; i < n; i++) {       int a = num[x[i] - y[i]];       int b = num[x[i]];       int c = num[x[i] + y[i]];       f[b] = c;       w[a].push_back(b);     }     printf( %d n , go(0, 0, 0));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main()   {        ios_base :: sync_with_stdio(false); cin.tie(NULL);        int t ; cin >> t ; while(t--)        {            int a , b ; cin >> a >> b ;      a-=b ;      while(b--) cout <<  a  ;      string d =  cba  ;      for(int i = 0 ; i < a ; i++)      {          cout << d[i % 3] ;      }      cout << endl ;        }      }


#include <bits/stdc++.h>   using namespace std;   long long n, m, rr[10][10];   long long func(long long), dp[(1 << 21)];   map<long long, pair<long long, long long> > mr;   long long check(long long i, long long j) {     return (abs(mr[i].first - mr[j].first) + abs(mr[i].second - mr[j].second)) ==            3;   }   int main() {     scanf( %lld %lld , &n, &m);     if (n > m) swap(n, m);     if (n * m <= 21) {       long long x = 0;       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) {           mr[x++] = make_pair(i, j);         }       memset(dp, -1, sizeof(dp));       cout << func(0);     } else {       long long ans = 0;       if (n == 1) {         ans += m - m % 6;         m = m % 6;         ans += (m >= 3 ? 2 * (m - 3) : 0);       } else         ans = n * m - (n * m) % 2;       cout << ans <<   n ;     }   }   long long func(long long mask) {     if (dp[mask] != -1) return dp[mask];     long long ans = 0;     for (int i = 0; i < n * m; i++) {       for (int j = i + 1; j < n * m; j++) {         if ((mask & (1 << i)) == 0 && (mask & (1 << j)) == 0 && check(i, j)) {           ans = max(ans, 2 + func(mask | (1 << i) | (1 << j)));         }       }     }     return dp[mask] = ans;   }


#include <bits/stdc++.h>   using namespace std;   bool f(int n, int h, int c, int t) {     return (2 * n + 1ll) * abs(1ll * n * (h + c - 2 * t) + t - c) <=            (2 * n - 1ll) * (1ll * n * (h + c - 2 * t) + h - t);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     long long t = 1;     cin >> t;     while (t--) {       int h, c, t;       cin >> h >> c >> t;       if (2 * t <= h + c)         cout <<  2               <<   n ;       else {         int a = h - t;         int b = 2 * t - c - h;         int k = 2 * (a / b) + 1;         long long val1 =             abs(k / 2 * 1ll * c + (k + 1) / 2 * 1ll * h - t * 1ll * k);         long long val2 = abs((k + 2) / 2 * 1ll * c + (k + 3) / 2 * 1ll * h -                              t * 1ll * (k + 2));         if (val1 * (k + 2) <= val2 * k)           cout << k <<   n ;         else           cout << k + 2 <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   #define sim template < class c   #define ris return * this   #define dor > debug & operator <<   #define eni(x) sim > typename      enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {   sim > struct rge { c b, e; };   sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }   sim > auto dud(c* x) -> decltype(cerr << *x, 0);   sim > char dud(...);   struct debug {   #ifndef ONLINE_JUDGE   ~debug() { cerr << endl; }   eni(!=) cerr << boolalpha << i; ris; }   eni(==) ris << range(begin(i), end(i)); }   sim, class b dor(pair < b, c > d) {     ris <<  (  << d.first <<  ,   << d.second <<  ) ;   }   sim dor(rge<c> d) {     *this <<  [ ;     for (auto it = d.b; it != d.e; ++it)       *this <<  ,   + 2 * (it == d.b) << *it;     ris <<  ] ;   }   #else   sim dor(const c&) { ris; }   #endif   };   #define imie(...)   [  << #__VA_ARGS__  :   << (__VA_ARGS__) <<  ]        #define ll long long      const ll mod = 998244353;      long long power(long long x, ll y, ll p)   {       long long res = 1; // Initialize result           x = x % p; // Update x if it is more than or       // equal to p           while (y > 0)       {                   // If y is odd, multiply x with result           if (y & 1)               res = (res * x) % p;               // y must be even now           y = y >> 1; // y = y/2           x = (x * x) % p;       }       return res;   }       // Returns n^(-1) mod p   long long modInverse(long long n, int p)   {       return power(n, p - 2, p);   }       // Returns nCr % p using Fermat s little   // theorem.   long long nCrModPFermat(long long n,int r, int p)   {       // If n<r, then nCr should return 0       if (n < r)           return 0;       // Base case       if (r == 0)           return 1;           // Fill factorial array so that we       // can find all factorial of r, n       // and n-r       long long fac[n + 1];       fac[0] = 1;       for (int i = 1; i <= n; i++)           fac[i] = (fac[i - 1] * i) % p;           return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;   }      void test_case() {       ll n;       cin >> n;       string s;       cin >> s;       ll cnt = 0, cnt2 = 0, tmp = 0;       for(ll i = 0; i < n; ++i) {           if(s[i] ==  0 ) {               cnt2 = cnt2 + (tmp) / 2;               tmp = 0;               cnt++;           } else {               tmp++;           }       }       cnt2 = cnt2 + (tmp) / 2;       cout << nCrModPFermat(cnt + cnt2, cnt, mod) << endl;   }       int main()   {       ll T;        cin >> T;       for(ll i = 1; i <= T; ++i) {           test_case();       }       return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   int rd() {     int k = 0;     char c = getchar();     while (c >  9  || c <  0 ) c = getchar();     while (c >=  0  && c <=  9 ) k = k * 10 + c -  0 , c = getchar();     return k;   }   const int N = 300000, M = 600001;   int T, x, y, f[M], sx[M], sy[M];   long long ans;   vector<pair<int, int> > v[M << 1];   map<pair<int, int>, int> mp;   pair<int, int> p;   int F(int x) {     while (x != f[x]) x = f[x];     return x;   }   void Add(int x, int l, int r, int s, int t, pair<int, int> p) {     if (s <= l && r <= t) {       v[x].push_back(p);       return;     }     if (s <= ((l + r) >> 1)) Add((x << 1), l, ((l + r) >> 1), s, t, p);     if (((l + r) >> 1) < t) Add((x << 1 | 1), ((l + r) >> 1) + 1, r, s, t, p);   }   void Solve(int x, int l, int r) {     long long pre = ans;     stack<int> S;     for (int i = 0; i < v[x].size(); ++i) {       int a = F(v[x][i].first), b = F(v[x][i].second + N);       if (a == b) continue;       if (sx[a] + sy[a] > sx[b] + sy[b]) {         int t = a;         a = b, b = t;       }       ans -= (long long)sx[a] * sy[a] + (long long)sx[b] * sy[b],           f[a] = b, sx[b] += sx[a], sy[b] += sy[a];       ans += (long long)sx[b] * sy[b], S.push(a);     }     if (l == r)       printf( %lld  , ans);     else       Solve((x << 1), l, ((l + r) >> 1)),           Solve((x << 1 | 1), ((l + r) >> 1) + 1, r);     while (!S.empty()) {       int t = S.top(), z = f[t];       S.pop(), f[t] = t, sx[z] -= sx[t], sy[z] -= sy[t];     }     ans = pre;   }   int main() {     T = rd();     for (int i = 1; i <= T; ++i) {       x = rd(), y = rd(), p = make_pair(x, y);       if (mp.count(p))         Add(1, 1, T, mp[p], i - 1, p), mp.erase(p);       else         mp[p] = i;     }     for (auto t : mp) Add(1, 1, T, t.second, T, t.first);     for (int i = 1; i <= N; ++i) sx[f[i] = i] = 1;     for (int i = N + 1; i < M; ++i) sy[f[i] = i] = 1;     Solve(1, 1, T);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> adj[100007][2];   long long ecnt[100007][2] = {0};   long long ss[100007] = {0};   long long sum = 0;   long long n, m, q;   int main() {     cin >> n >> m;     for (long long i = 0; i < m; i++) {       long long a, b;       cin >> a >> b;       --a;       --b;       if (a > b) swap(a, b);       adj[a][0].push_back(b);       adj[b][1].push_back(a);       ecnt[a][0]++;       ecnt[b][1]++;     }     for (long long i = 0; i < n; i++) {       ss[i] = ecnt[i][0] * ecnt[i][1];       sum += ss[i];     }     cin >> q;     cout << sum << endl;     while (q--) {       long long v;       cin >> v;       --v;       sum -= ss[v];       ss[v] = 0;       ecnt[v][1] += ecnt[v][0];       ecnt[v][0] = 0;       for (auto i : adj[v][0]) {         sum -= ecnt[i][0] * ecnt[i][1];         ecnt[i][1]--;         ecnt[i][0]++;         sum += ecnt[i][0] * ecnt[i][1];         ss[i] = ecnt[i][0] * ecnt[i][1];         adj[i][0].push_back(v);       }       adj[v][0].clear();       cout << sum << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int maxdp[27];   int dp[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     string str;     cin >> n >> str;     for (int i = 0; i < n; ++i) {       for (int c = 26; c > str[i] -  a ; --c)         maxdp[str[i] -  a ] = max(maxdp[c] + 1, maxdp[str[i] -  a ]);       dp[i] = maxdp[str[i] -  a ];     }     cout << *max_element(dp, dp + n) << endl;     for (int i = 0; i < n; ++i) {       cout << dp[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int SIZE = 1e2 + 5;   int main() {     int n, m, c;     string s[SIZE], extract, f;     c = 0, f =  acef ;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> s[i];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         extract.push_back(s[i][j]);         extract.push_back(s[i + 1][j]);         extract.push_back(s[i][j + 1]);         extract.push_back(s[i + 1][j + 1]);         sort(extract.begin(), extract.end());         if (extract == f) c++;         extract.clear();       }     }     cout << c << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 7;   pair<int, pair<int, int> > A[maxn];   map<int, int> X;   map<int, int> Y;   int Hx[maxn], Hy[maxn];   int ans[maxn];   int fa[maxn];   int fi(int u) {     if (fa[u] == u) return u;     return fa[u] = fi(fa[u]);   }   void un(int u, int v) {     int p1 = fi(u), p2 = fi(v);     if (p1 != p2) fa[p1] = p2;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n * m; i++) {       fa[i] = i;       scanf( %d , &A[i].first);       A[i].second.first = i / m;       A[i].second.second = i % m;     }     int j = -1;     sort(A, A + n * m);     for (int i = 0; i < n * m; i++) {       if (i != n * m - 1 && A[i].first == A[i + 1].first) continue;       for (int k = j + 1; k <= i; k++) {         int p = A[k].second.first * m + A[k].second.second;         int x = A[k].second.first, y = A[k].second.second;         Hx[x] = p;         Hy[y] = p;       }       for (int k = j + 1; k <= i; k++) {         int p = A[k].second.first * m + A[k].second.second;         int x = A[k].second.first, y = A[k].second.second;         un(Hx[x], p);         un(Hy[y], p);       }       for (int k = j + 1; k <= i; k++) {         int p = A[k].second.first * m + A[k].second.second;         int x = A[k].second.first, y = A[k].second.second;         int pa = fi(p);         ans[pa] = max(ans[pa], max(X[x], Y[y]) + 1);       }       for (int k = j + 1; k <= i; k++) {         int p = A[k].second.first * m + A[k].second.second;         int x = A[k].second.first, y = A[k].second.second;         X[x] = max(X[x], ans[fi(p)]);         Y[y] = max(Y[y], ans[fi(p)]);       }       j = i;     }     for (int i = 0; i < n * m; i++) {       printf( %d  , ans[fi(i)]);       if (i % m == m - 1) printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> adj[100005], stx, sty;   long long mx = 0ll, ans[100005];   int sz[100005], par[100005];   pair<int, int> centroid = {0, 0};   bool cmp(int u, int v) { return sz[u] < sz[v]; }   void dfs(int nw, int bf) {     par[nw] = bf;     sz[nw] = 1;     for (int nx : adj[nw])       if (nx != bf) {         dfs(nx, nw);         sz[nw] += sz[nx];       }     sort(adj[nw].begin(), adj[nw].end(), cmp);     mx += 2 * min(sz[nw], n - sz[nw]);     centroid = max(centroid, {min(sz[nw], n - sz[nw]), nw});   }   void get_subtree(int nw, int bf, vector<int> &v) {     v.push_back(nw);     for (int nx : adj[nw])       if (nx != bf) get_subtree(nx, nw, v);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int u, v, i = 1; i < n; i++) {       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(1, 0);     int x = centroid.second, y = par[x];     if (sz[x] * 2 > n) swap(x, y);     get_subtree(x, y, stx);     get_subtree(y, x, sty);     for (int i = 0; i < stx.size(); i++) {       ans[stx[i]] = sty[i];       ans[sty[sty.size() - stx.size() + i]] = stx[i];     }     for (int i = 0; i < sty.size() - stx.size(); i++)       ans[sty[i]] = sty[stx.size() + i];     cout << mx << endl;     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int a, b;   bool temp = false;   int main() {     cin >> a;     for (b = 1; b <= 500; b++)       if ((b * (b + 1)) / 2 == a) {         temp = true;         break;       }     if (temp)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e5 + 9, lg = 20;   int n, q, timer = 1;   vector<int> adj[inf], level[inf];   int depth[inf], in[inf], out[inf], parent[inf][lg];   void dfs(int u, int par) {     in[u] = timer++;     level[depth[u]].push_back(in[u]);     for (auto v : adj[u])       if (v != par) parent[v][0] = u, depth[v] = depth[u] + 1, dfs(v, u);     out[u] = timer++;   }   int KthParent(int u, int k) {     for (int j = lg - 1; j >= 0; j--)       if (k & (1ll << j)) u = parent[u][j];     return u;   }   int CntLevelInSubtree(int u, int h) {     return upper_bound(level[h].begin(), level[h].end(), out[u]) -            lower_bound(level[h].begin(), level[h].end(), in[u]);   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       int tmp;       cin >> tmp;       if (tmp) adj[tmp].push_back(i), adj[i].push_back(tmp);     }     for (int i = 1; i <= n; i++)       if (!in[i]) dfs(i, 0);     for (int j = 1; j < lg; j++)       for (int i = 1; i <= n; i++) parent[i][j] = parent[parent[i][j - 1]][j - 1];     cin >> q;     while (q--) {       int v, p;       cin >> v >> p;       if (depth[v] < p) {         cout << 0 <<    ;         continue;       }       int u = KthParent(v, p);       cout << CntLevelInSubtree(u, depth[v]) - 1 <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 1000000 + 5;   int f[maxn], inv[maxn], finv[maxn];   void init() {     inv[1] = 1;     for (int i = 2; i < maxn; i++)       inv[i] = (mod - mod / i) * 1ll * inv[mod % i] % mod;     f[0] = finv[0] = 1;     for (int i = 1; i < maxn; i++) {       f[i] = f[i - 1] * 1ll * i % mod;       finv[i] = finv[i - 1] * 1ll * inv[i] % mod;     }   }   int C(int n, int m) {     if (m < 0 || m > n) return 0;     return f[n] * 1ll * finv[n - m] % mod * finv[m] % mod;   }   long long qpow(long long x, long long n) {     long long r = 1;     while (n > 0) {       if (n & 1) r = r * x % mod;       n >>= 1;       x = x * x % mod;     }     return r;   }   long long T(long long n, long long k) {     if (k == n) return 1;     return k * qpow(n, n - k - 1) % mod;   }   int n, m, a, b;   int main() {     init();     cin >> n >> m >> a >> b;     long long ans = 0;     for (int i = 1; i < n; i++) {       long long tot = 1ll * C(m - 1, i - 1) * C(n - 2, i - 1) % mod * f[i - 1] %                       mod * qpow(m, n - i - 1) % mod * T(n, i + 1) % mod;       ans += tot;       if (ans >= mod) ans -= mod;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int func1(long long int i) {     long long int m = i;     return i * (i + 1) * (2 * i + 1) / 6 - (m + m + 2) * i * (i + 1) / 2 +            (m + m + 1 + m * m) * i;   }   long long int func2(long long int x, long long int i) {     return x * (i + i * i - i * (i + 1) / 2);   }   int main() {     long long int inp, tem, ans = 0, tem2;     cin >> inp;     vector<pair<long long int, long long int> > v;     bool flag = 0;     for (int i = 0; i < 100000000; i++)       if (ans > 0) ans += 1;     ans = 0;     for (long long int i = 1; func1(i) <= inp; i++) {       tem = inp - func1(i);       if (!tem) {         flag = 1;         v.push_back(make_pair(i, i));       } else {         tem2 = func2(1, i);         if (tem % tem2 == 0) v.push_back(make_pair(i, i + tem / tem2));       }     }     if (!flag)       cout << 2 * v.size();     else       cout << 2 * v.size() - 1;     cout <<   n ;     for (int i = 0; i < v.size(); i++)       cout << v[i].first <<     << v[i].second <<   n ;     int i = v.size() - 1;     if (flag) i--;     for (; i >= 0; i--) cout << v[i].second <<     << v[i].first <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void chkMax(T &x, T y) {     if (y > x) x = y;   }   template <typename T>   void chkMin(T &x, T y) {     if (y < x) x = y;   }   template <typename T>   void inline read(T &x) {     int f = 1;     x = 0;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f = -1;       s = getchar();     }     while (s <=  9  && s >=  0 ) x = x * 10 + (s ^ 48), s = getchar();     x *= f;   }   const int N = 2005;   int n, f[10][10][10][10][10], g[10][10][10][10][10];   int ans = 2e9;   int main() {     read(n);     memset(f, 0x3f, sizeof f);     f[1][0][0][0][0] = 0;     for (int i = 1; i <= n; i++) {       int x, y;       read(x), read(y);       memcpy(g, f, sizeof f);       memset(f, 0x3f, sizeof f);       for (int p = 1; p <= 9; p++) {         for (int a = 0; a <= 9; a++) {           for (int b = 0; b <= 9; b++) {             for (int c = 0; c <= 9; c++) {               for (int d = 0; d <= 9; d++) {                 if (a == 0) {                   chkMin(f[x][y][b][c][d], g[p][a][b][c][d] + abs(p - x));                 }                 if (b == 0) {                   chkMin(f[x][a][y][c][d], g[p][a][b][c][d] + abs(p - x));                 }                 if (c == 0) {                   chkMin(f[x][a][b][y][d], g[p][a][b][c][d] + abs(p - x));                 }                 if (d == 0) {                   chkMin(f[x][a][b][c][y], g[p][a][b][c][d] + abs(p - x));                 }               }             }           }         }       }       for (int a = 9; ~a; a--) {         for (int b = 9; ~b; b--) {           for (int c = 9; ~c; c--) {             for (int d = 9; ~d; d--) {               for (int p = 1; p <= 9; p++) {                 if (a) chkMin(f[a][0][b][c][d], f[p][a][b][c][d] + abs(p - a));                 if (b) chkMin(f[b][a][0][c][d], f[p][a][b][c][d] + abs(p - b));                 if (c) chkMin(f[c][a][b][0][d], f[p][a][b][c][d] + abs(p - c));                 if (d) chkMin(f[d][a][b][c][0], f[p][a][b][c][d] + abs(p - d));               }             }           }         }       }     }     for (int i = 1; i <= 9; i++) chkMin(ans, f[i][0][0][0][0]);     printf( %d n , ans + 2 * n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     int k = 0, l = 0, n;     cin >> a >> b;     n = a.size();     for (int i = 0; i < n; i++) {       if (a[i] ==  4  && b[i] ==  7 ) {         k++;       } else if (a[i] ==  7  && b[i] ==  4 ) {         l++;       }     }     int p = max(k, l);     cout << p << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   template <class T>   T gcd(T a, T b) {     return ((b == 0) ? a : gcd(b, a % b));   }   void solve() {     int n, k;     long long x;     cin >> n >> k >> x;     string s;     cin >> s;     x--;     int cnt = 0;     vector<int> nm;     for (int i = n - 1; i >= 0; i--) {       if (s[i] ==  * )         cnt++;       else {         if (cnt) nm.push_back(cnt);         cnt = 0;       }     }     if (cnt) nm.push_back(cnt);     int uwu = 0;     vector<int> d;     while (x > 0) {       int cr = (nm[uwu++] * k) + 1;       d.push_back(x % cr);       x /= cr;     }     int ind = 0, lst = -1;     string ans =   ;     for (int i = n - 1; i >= 0; i--) {       if (s[i] ==  a )         ans +=  a , lst = 1;       else {         if (!lst) continue;         if (ind == (int)(d.size())) continue;         for (int j = 0; j < (int)(d[ind]); j++) ans +=  b ;         ind++;         lst = 0;       }     }     reverse(ans.begin(), ans.end());     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int tt;     cin >> tt;     while (tt--) {       long long n, s, t;       cin >> n >> s >> t;       cout << max(n - s + 1, n - t + 1) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace runzhe2000 {   const int INF = 1 << 29;   int ft[100005], gt[100005], f[100005][10], g[100005][10], timer = 1, c[10],                                                             sta[100005], top;   char s[100005];   bool insta[100005];   struct node {     int l, r, v;   } no[100005];   void del(int x) {     no[no[x].l].r = no[x].r;     no[no[x].r].l = no[x].l;   }   void main() {     int n, q;     scanf( %d%d%s , &n, &q, s + 1);     for (int i = 1, v; i <= n; i++) {       if (s[i] >=  0  && s[i] <=  9 )         v = s[i] -  0 ;       else         v = s[i] ==  <  ? 11 : 10;       no[i] = (node){i - 1, i + 1, v};     }     memset(ft, 63, sizeof(ft));     memset(gt, 63, sizeof(gt));     ++timer;     ++n;     no[n] = (node){n - 1, n + 1, 10};     for (int l = 1; l <= n; l++)       if (ft[l] > INF) {         for (int cur = l, next, pos = 10; l <= cur && cur <= n;              cur = next, ++timer) {           if (timer < ft[cur]) {             ft[cur] = timer;             for (int i = 0; i < 10; i++) f[cur][i] = c[i];           }           if (no[cur].v < 10) {             c[no[cur].v--]++;             if (no[cur].v < 0) del(cur);           } else {             pos = no[cur].v;           }           next = pos == 11 ? no[cur].l : no[cur].r;           if (no[cur].v > 9 && no[next].v > 9) del(cur);           if (!insta[cur]) sta[++top] = cur, insta[cur] = 1;           if (pos == 11) {             for (; no[cur].l < sta[top] && sta[top] <= cur && top; --top) {               gt[sta[top]] = ++timer;               for (int i = 0; i < 10; i++) g[sta[top]][i] = c[i];             }           }         }       }     for (; q--;) {       int l, r;       scanf( %d%d , &l, &r);       if (ft[r + 1] < gt[l]) {         for (int i = 0; i < 10; i++)           printf( %d%c , f[r + 1][i] - f[l][i], i == 9 ?   n  :    );       } else {         for (int i = 0; i < 10; i++)           printf( %d%c , g[l][i] - f[l][i], i == 9 ?   n  :    );       }     }   }   }  // namespace runzhe2000   int main() { runzhe2000::main(); }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int r = 0, b = 0, y = 0, g = 0;     int len = s.size();     for (int i = 0; i < len; i++) {       if (s[i] ==  B )         b = i % 4;       else if (s[i] ==  G )         g = i % 4;       else if (s[i] ==  R )         r = i % 4;       else if (s[i] ==  Y )         y = i % 4;     }     int w = 0, x = 0, yy = 0, z = 0, pos;     for (int i = 0; i < len; i++) {       if (s[i] ==  ! ) {         pos = i % 4;         if (pos == r)           w++;         else if (pos == b)           x++;         else if (pos == y)           yy++;         else if (pos == g)           z++;       }     }     cout << w <<     << x <<     << yy <<     << z << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     unsigned short x;     std::cin >> x;     (x > 1) ? std::cout << x <<     << x : std::cout << -1;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, a[300005], b[300005];   int main() {     cin >> n >> k;     k--;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i < n; i++) b[i] = a[i + 1] - a[i];     long long res = a[n] - a[1];     sort(b + 1, b + n);     for (int i = n - 1; i >= n - k; i--) res -= b[i];     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int T = 31;   const int mod = 1000000007;   const long long oo = 1LL << 60;   long long N;   int K;   long long B[T][T];   long long power[70];   long long dp[70][T][T];   bool bio[70];   long long rot[T][T][T];   long long mult(long long a, long long b) {     if (a == 0) return 0;     if (b >= oo / a + 1) return oo;     return a * b;   }   void mult(long long A[T][T], long long B[T][T]) {     static long long C[T][T];     for (int i = (0); i < (T); ++i)       for (int j = (0); j < (T); ++j) C[i][j] = 0;     for (int i = (0); i < (T); ++i)       for (int j = (0); j < (T); ++j)         for (int k = (0); k < (T); ++k)           C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % mod;     for (int i = (0); i < (T); ++i)       for (int j = (0); j < (T); ++j) A[i][j] = C[i][j];   }   void rec(long long prefix, int n, long long A[T][T]) {     long long lo = mult(prefix, power[n]);     long long hi = lo + power[n] - 1;     if (lo >= N) return;     long long z = prefix % K;     mult(A, rot[z]);     if (n == 0) {       mult(A, B);     } else {       bool memo = hi < N;       auto AA = memo ? dp[n] : A;       if (!bio[n] && memo)         for (int i = (0); i < (T); ++i) AA[i][i] = 1;       if (!bio[n] || !memo)         for (int i = (0); i < (K); ++i) rec(prefix * K + i, n - 1, AA);       if (memo) bio[n] = true, mult(A, AA);     }     mult(A, rot[(K - z) % K]);   }   int main() {     scanf( %lld%d , &N, &K);     for (int i = (0); i < (K); ++i) B[i][i] = 1;     for (int i = (1); i < (K); ++i) B[i][0] = 1;     B[K][0] = 1;     B[K][K] = 1;     for (int x = (0); x < (K); ++x)       for (int i = (0); i < (K); ++i) rot[x][i][(i + x) % K] = 1;     for (int x = (0); x < (K); ++x)       for (int i = (K); i < (T); ++i) rot[x][i][i] = 1;     static long long A[T][T];     A[0][K] = 1;     power[0] = 1;     for (int i = (1); i < (70); ++i) power[i] = mult(power[i - 1], K);     rec(0, 69, A);     long long ans = 1;     for (int i = (0); i < (K); ++i) ans = (ans + A[0][i]) % mod;     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     int n, p, q;     cin >> n;     vector<pair<int, int>> v1;     int x1, x2;     for (size_t i = 0; i < n; i++) {       cin >> x1 >> x2;       v1.push_back(make_pair(x1, x2));     }     bool s = true;     sort(v1.begin(), v1.end());     for (size_t i = 0; i < n; i++) {       if (v1[i].second > v1[i + 1].second && i + 1 < n) {         s = false;         break;       }     }     if (s == true) {       cout <<  Poor Alex ;     } else {       cout <<  Happy Alex ;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     printf( %d , n % 2);   }


#include <bits/stdc++.h>   using namespace std;   vector<int> t;   int n, x, i, j, h, sol, temp;   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (i = 0; i < n; i++) {       cin >> x;       t.push_back(x);     }     cin >> h;     sort(t.begin(), t.end());     sol = 0;     for (i = 0; i < n; i++) {       temp = 1;       for (j = i + 1; j < n; j++) {         if (t[j] - t[i] <= h) temp++;       }       sol = max(sol, temp);     }     cout << sol << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 305;   int n, m;   class Point {    public:     long long x, y;     Point() : x(0), y(0) {}     Point(long long _x, long long _y) : x(_x), y(_y) {}     void read() { scanf( %lld%lld , &x, &y); }     Point operator+(const Point &o) const { return Point(x + o.x, y + o.y); }     Point operator-(const Point &o) const { return Point(x - o.x, y - o.y); }     long long operator*(const Point &o) const { return x * o.y - y * o.x; }     bool operator<(const Point &o) const {       int c = (y == 0 && x > 0) || (y > 0);       int oc = (o.y == 0 && o.x > 0) || (o.y > 0);       if (c != oc) return c > oc;       return (*this) * o > 0;     }   } p[maxn];   class Edge {    public:     Point w;     int u, v;     Edge() {}     Edge(Point _w, int _u, int _v) : w(_w), u(_u), v(_v) {}     bool operator<(const Edge &o) const { return w < o.w; }   } e[maxn * maxn];   long long dp[maxn][maxn][6];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) p[i].read();     for (int i = 0; i < n; i++)       for (int j = i + 1; j < n; j++) {         e[m++] = Edge(p[j] - p[i], i, j);         e[m++] = Edge(p[i] - p[j], j, i);       }     sort(e, e + m);     for (int i = 0; i < n; i++) dp[i][i][0] = 1;     for (int i = 0; i < m; i++)       for (int j = 0; j < n; j++)         for (int k = 0; k < 5; k++) dp[j][e[i].v][k + 1] += dp[j][e[i].u][k];     long long ans = 0;     for (int i = 0; i < n; i++) ans += dp[i][i][5];     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, x;     cin >> n >> x;     string second;     cin >> second;     long long ans = 0;     long long sm = 0;     for (long long i = 0; i < n; i++) {       if (second[i] ==  0 )         sm++;       else         sm--;     }     long long c = 0;     for (long long i = 0; i < n; i++) {       if (sm == 0 && c == x) {         cout << -1 << endl;         return;       }       if ((x - c) % sm == 0 && (x - c) / sm >= 0 && sm != 0) ans++;       if (second[i] ==  0 )         c++;       else         c--;     }     cout << ans << endl;   }   int main() {     long long t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   struct sort_pred {     bool operator()(const std::pair<int, int> &left,                     const std::pair<int, int> &right) {       return right.first > left.first;     }   };   int n, m, k, t;   int r = 0;   vector<bool> visited;   vector<vector<int>> v;   vector<int> distanc;   queue<int> q;   map<pair<int, int>, int> mp;   vector<bool> chosen;   void bfs(int first) {     visited[first] = true;     q.push(first);     while (!q.empty()) {       int s = q.front();       q.pop();       for (auto u : v[s]) {         if (distanc[s] - mp[make_pair(s, u)] >= 0 &&             distanc[s] - mp[make_pair(s, u)] > distanc[u]) {           if (!visited[u]) r++;           visited[u] = true;           distanc[u] = distanc[s] - mp[make_pair(s, u)];           if (chosen[u]) distanc[u] = t;           q.push(u);         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     map<int, int> mp;     vector<int> b(n);     for (int i = 0; i < n; i++) {       int first;       cin >> first;       mp[first] = i + 1;     }     for (int i = 0; i < n; i++) {       int first;       cin >> first;       cout << mp[first] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int inf = 1e9 + 5;   long long powmod(long long a, long long b) {     long long ret = 1;     while (b) {       if (b & 1) ret = (ret * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return ret;   }   const int maxn = 3e5 + 5;   long long a[maxn];   int n, m;   int q[maxn];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     long long tot = 0;     for (int i = 0; i <= n - 1; i++) {       cin >> a[i];       tot += a[i];     }     sort(a, a + n);     cin >> m;     for (int i = 0; i <= m - 1; i++) {       cin >> q[i];       cout << tot - a[n - q[i]] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1002000, CAN = 34;   int n, m, p, vis[MAXN], pr[MAXN], pcnt;   char w1[MAXN], w2[MAXN];   vector<int> can[300];   int muln(int x, int y) { return 1LL * x * y % p; }   int mo(int x) {     while (x >= p) x -= p;     while (x < 0) x += p;     return x;   }   int qpow(int x, int y) {     int ret = 1;     for (; y; y >>= 1, x = muln(x, x))       if (y & 1) ret = muln(ret, x);     return ret;   }   struct poly {     int deg;     vector<int> a;     poly(int x = 0) : deg(x) { a.resize(x + 1, 0); }     int& operator[](int idx) { return a[idx]; }     void print(string s) {       cerr <<  Poly   << s <<  :  ;       for (auto g : a) printf( %d  , g);       cerr << endl;     }     int at(int x) {       x = mo(x);       int ret = 0;       for (int i = deg; i >= 0; --i) ret = mo(muln(ret, x) + mo(a[i]));       return ret;     }     void norm() {       for (auto& g : a) g = mo(g);     }   } I;   void sieve() {     for (int i = 2; i <= 1000000; ++i) {       if (!vis[i]) {         pr[++pcnt] = i;       }       for (int j = 1; j <= pcnt && i * pr[j] <= 1000000; ++j) {         vis[i * pr[j]] = true;         if (i % pr[j] == 0) break;       }     }     for (int k = 1, i = pr[k]; k <= pcnt; i = pr[++k]) {       if (i > m)         for (int j = 1; j <= CAN; ++j)           if ((i - 1) % pr[j] == 0) can[j].push_back(i);     }   }   void sol(int opt) {     int d = pr[opt];     poly a(d - 1);     for (int i = 0; i < n; ++i) a[i % d] += I[i];     for (auto pri : can[opt]) {       p = pri;       int rr = 2;       while (qpow(rr, (p - 1) / d) == 1) rr++;       rr = qpow(rr, (p - 1) / d);       for (int Cnt = 1; Cnt < d; ++Cnt) {         int r = qpow(rr, Cnt);         if (r < 2 || r > p - 2) continue;         int val = a.at(r);         if (val == 0) {           printf( %d %d n , p, r);           exit(0);         }       }     }   }   int main() {     scanf( %d%d%s%s , &n, &m, w1, w2);     sieve();     I = poly(n - 1);     for (int i = 0; i < n; ++i) I[i] = w1[i] - w2[i];     for (int i = 1; i <= CAN; ++i) sol(i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[100007], ans[100007], vis[100007];   int count(int x) {     int cnt = 0, now = 0;     memset(vis, 255, sizeof(vis));     for (int i = 1; i <= n; i++) {       if (vis[a[i]] == now) continue;       vis[a[i]] = now;       if (++cnt > x) {         cnt = 1;         vis[a[i]] = ++now;       }     }     return now + 1;   }   void work(int l, int r) {     if (l > r) return;     int cnt1 = count(l), cnt2 = count(r);     if (cnt1 == cnt2) {       for (int i = l; i <= r; i++) ans[i] = cnt1;       return;     }     ans[l] = cnt1;     ans[r] = cnt2;     int mid = (l + r) >> 1;     work(l + 1, mid);     work(mid + 1, r - 1);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     work(1, n);     for (int i = 1; i <= n; i++) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     long long a[n];     for (long long i = 0; i < n; i++) cin >> a[i];     vector<long long> good, bad;     for (long long i = 0; i < n; i++) {       long long val = sqrt(a[i]);       if (val * val == a[i])         good.push_back(a[i]);       else         bad.push_back(a[i]);     }     long long sz1 = good.size(), sz2 = bad.size();     if (sz1 == sz2) {       cout << 0 <<   n ;     } else if (sz1 > sz2) {       long long nz = 0;       for (auto it : good) {         if (it) nz++;       }       long long req = (sz1 - sz2) / 2;       if (nz >= req)         cout << req <<   n ;       else         cout << nz + (req - nz) * 2 <<   n ;     } else {       vector<long long> ans;       long long req = (sz2 - sz1) / 2;       for (auto it : bad) {         long long val = sqrt(it);         long long down = it - val * val, up = (val + 1) * (val + 1) - it;         ans.push_back(min(down, up));       }       sort(ans.begin(), ans.end());       long long fans = 0;       for (long long i = 0; i < req; i++) {         fans += ans[i];       }       cout << fans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = (1 << 22) + 5;   int n, m;   bool is[MAX], seen[MAX];   int conj(int x) {     int r = 0;     for (int i = 0; i < n; ++i)       if (!(x & (1 << i))) r += (1 << i);     return r;   }   void dfs(int st, bool p = 0) {     if (seen[st]) return;     seen[st] = 1;     if (is[st]) dfs(conj(st), 1);     if (p) {       for (int i = 0; i < n; ++i)         if (st & (1 << i)) {           dfs(st - (1 << i), 1);         }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cin >> n >> m;     vector<int> st((1 << n) + 1, 0);     vector<bool> lz((1 << n) + 1, 0);     for (int i = 0; i < m; ++i) {       int x;       cin >> x;       is[x] = 1;     }     int cnt = 0;     for (int i = 0; i < (1 << n); ++i) {       if (!seen[i] && is[i]) {         dfs(i);         ++cnt;       }     }     cout << cnt <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     long long int n, x;     cin >> n;     vector<vector<long long int> > a(n);     for (long long int i = 0; i < n; i++) {       cin >> x;       for (long long int j = 0; j < x; j++) {         long long int tp;         cin >> tp;         a[i].push_back(tp);       }     }     long long int a1 = 0, b = 0;     vector<long long int> q;     for (long long int i = 0; i < n; i++) {       long long int f = a[i].size();       if (f % 2 != 0) {         for (long long int j = 0; j < (f - 1) / 2; j++) {           a1 += a[i][j];         }         for (long long int j = (f - 1) / 2 + 1; j < f; j++) {           b += a[i][j];         }         q.push_back(a[i][(f - 1) / 2]);       } else {         for (long long int j = 0; j < f / 2; j++) {           a1 += a[i][j];         }         for (long long int j = f / 2; j < f; j++) {           b += a[i][j];         }       }     }     sort(q.begin(), q.end(), greater<long long int>());     for (long long int k = 0; k < q.size(); k++) {       if (k % 2 == 0)         a1 += q[k];       else         b += q[k];     }     cout << a1 <<     << b;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 3 * (int)1e5 + 100;   int b[maxN];   int t[4 * maxN];   int a[maxN];   void build(int v, int tl, int tr) {     if (tl == tr) {       t[v] = a[tl];       return;     }     int tm = (tl + tr) / 2;     build(v + v, tl, tm);     build(v + v + 1, tm + 1, tr);     t[v] = min(t[v + v], t[v + v + 1]);   }   void upd(int v, int tl, int tr, int pos, int val) {     if (tl == tr) {       t[v] = val;       return;     }     int tm = (tl + tr) / 2;     if (pos <= tm)       upd(v + v, tl, tm, pos, val);     else       upd(v + v + 1, tm + 1, tr, pos, val);     t[v] = min(t[v + v], t[v + v + 1]);   }   const int INF = (int)1e9 + 100;   int get(int v, int tl, int tr, int l, int r) {     if (l > r) return INF;     if (tl == l && tr == r) {       return t[v];     }     int tm = (tl + tr) / 2;     return min(get(v + v, tl, tm, l, min(r, tm)),                get(v + v + 1, tm + 1, tr, max(l, tm + 1), r));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       set<pair<int, int> > s;       for (int i = 1; i <= n; i++) {         cin >> a[i];         s.insert(make_pair(a[i], i));       }       bool ok = true;       build(1, 1, n);       for (int i = 1; i <= n; i++) {         cin >> b[i];         if (!ok) continue;         auto it = s.lower_bound(make_pair(b[i], -1));         if (it == s.end() || ((it->first) != b[i])) {           ok = false;           continue;         }         int ind = (it->second);         s.erase(it);         if (b[i] != get(1, 1, n, 1, ind)) {           ok = false;         }         upd(1, 1, n, ind, INF);       }       if (ok)         cout <<  YES  <<   n ;       else         cout <<  NO  <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[11];   int main() {     int i, n, m, x;     while (scanf( %d , &a[0]) > 0) {       int c[33] = {0};       c[a[0]]++;       for ((i) = 0; (i) < (5); (i)++) {         scanf( %d , &a[i + 1]);         c[a[i + 1]]++;       }       bool f = 0;       int mx = 0;       for ((i) = 0; (i) < (11); (i)++) {         mx = max(mx, c[i]);         c[i] = c[i] % 4;         if (c[i] == 2) f = 1;       }       if (mx < 4)         printf( Alien n );       else if (f)         printf( Elephant n );       else         printf( Bear n );     }     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 2000 + 10;   const int INF = std::numeric_limits<int>::max();   const double EPS = 1e-6;   const int dx[] = {1, 0, -1, 0};   const int dy[] = {0, 1, 0, -1};   int a[MAXN][MAXN];   std::deque<std::pair<std::pair<int, int>, int>> q;   using std::cin;   using std::cout;   using std::endl;   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(0);     std::cout.tie(0);     int n, m;     cin >> n >> m;     int r, c;     cin >> r >> c;     int x, y;     cin >> x >> y;     for (int i = 0; i <= n + 1; ++i) {       for (int j = 0; j <= m + 1; ++j) {         a[i][j] = -1;       }     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         char c;         cin >> c;         if (c ==  . ) a[i][j] = INF;       }     }     q.push_back({{r, c}, 0});     a[r][c] = 0;     while (!q.empty()) {       int cur_x = q.front().first.first, cur_y = q.front().first.second,           cur_step = q.front().second;       q.pop_front();       for (int i = 0; i < 4; ++i) {         if (a[cur_x + dx[i]][cur_y + dy[i]] > cur_step + (dy[i] == -1)) {           a[cur_x + dx[i]][cur_y + dy[i]] = cur_step + (dy[i] == -1);           if (dy[i] == -1)             q.push_back({{cur_x + dx[i], cur_y + dy[i]}, cur_step + 1});           else             q.push_front({{cur_x + dx[i], cur_y + dy[i]}, cur_step});         }       }     }     int ans = 0;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         if (a[i][j] != -1) {           if (a[i][j] <= x && a[i][j] + j - c <= y) {             ++ans;           }         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,unroll-loops,no-stack-protector,fast-math,inline )   #pragma GCC target(         sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native )   using namespace std;   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  { ;     string sep;     for (const auto &x : v) os << sep << x, sep =  ,  ;     return os <<  } ;   }   template <typename A, typename B>   ostream &operator<<(ostream &os, const pair<A, B> &p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   void dbg_out() { cerr << endl; }   template <typename Head, typename... Tail>   void dbg_out(Head H, Tail... T) {     cerr <<     << H;     dbg_out(T...);   }   template <const int &MOD>   struct _m_int {     int val;     _m_int(int64_t v = 0) {       if (v < 0) v = v % MOD + MOD;       if (v >= MOD) v %= MOD;       val = v;     }     static int inv_mod(int a, int m = MOD) {       int g = m, r = a, x = 0, y = 1;       while (r != 0) {         int q = g / r;         g %= r;         swap(g, r);         x -= q * y;         swap(x, y);       }       return x < 0 ? x + m : x;     }     explicit operator int() const { return val; }     explicit operator int64_t() const { return val; }     _m_int &operator+=(const _m_int &other) {       val -= MOD - other.val;       if (val < 0) val += MOD;       return *this;     }     _m_int &operator-=(const _m_int &other) {       val -= other.val;       if (val < 0) val += MOD;       return *this;     }     static unsigned fast_mod(uint64_t x, unsigned m = MOD) {       return x % m;       unsigned x_high = x >> 32, x_low = (unsigned)x;       unsigned quot, rem;       asm( divl %4 n  :  =a (quot),  =d (rem) :  d (x_high),  a (x_low),  r (m));       return rem;     }     _m_int &operator*=(const _m_int &other) {       val = fast_mod((uint64_t)val * other.val);       return *this;     }     _m_int &operator/=(const _m_int &other) { return *this *= other.inv(); }     friend _m_int operator+(const _m_int &a, const _m_int &b) {       return _m_int(a) += b;     }     friend _m_int operator-(const _m_int &a, const _m_int &b) {       return _m_int(a) -= b;     }     friend _m_int operator*(const _m_int &a, const _m_int &b) {       return _m_int(a) *= b;     }     friend _m_int operator/(const _m_int &a, const _m_int &b) {       return _m_int(a) /= b;     }     _m_int &operator++() {       val = val == MOD - 1 ? 0 : val + 1;       return *this;     }     _m_int &operator--() {       val = val == 0 ? MOD - 1 : val - 1;       return *this;     }     _m_int operator++(int) {       _m_int before = *this;       ++*this;       return before;     }     _m_int operator--(int) {       _m_int before = *this;       --*this;       return before;     }     _m_int operator-() const { return val == 0 ? 0 : MOD - val; }     bool operator==(const _m_int &other) const { return val == other.val; }     bool operator!=(const _m_int &other) const { return val != other.val; }     _m_int inv() const { return inv_mod(val); }     _m_int pow(int64_t p) const {       if (p < 0) return inv().pow(-p);       _m_int a = *this, result = 1;       while (p > 0) {         if (p & 1) result *= a;         a *= a;         p >>= 1;       }       return result;     }     friend ostream &operator<<(ostream &os, const _m_int &m) {       return os << m.val;     }   };   extern const int MOD = 998244353;   using mod_int = _m_int<MOD>;   const int BITS = 53;   template <typename T>   struct xor_basis {     T basis[BITS];     int n = 0;     T min_value(T start) const {       if (n == BITS) return 0;       for (int i = 0; i < n; i++) start = min(start, start ^ basis[i]);       return start;     }     T max_value(T start = 0) const {       if (n == BITS) return ((T)1 << BITS) - 1;       for (int i = 0; i < n; i++) start = max(start, start ^ basis[i]);       return start;     }     bool add(T x) {       x = min_value(x);       if (x == 0) return false;       basis[n++] = x;       for (int k = n - 1; k > 0 && basis[k] > basis[k - 1]; k--)         swap(basis[k], basis[k - 1]);       return true;     }     void merge(const xor_basis<T> &other) {       for (int i = 0; i < other.n && n < BITS; i++) add(other.basis[i]);     }     void merge(const xor_basis<T> &a, const xor_basis<T> &b) {       if (a.n > b.n) {         *this = a;         merge(b);       } else {         *this = b;         merge(a);       }     }   };   int N, M, B;   vector<int64_t> basis;   vector<int64_t> answers;   void generate_all() {     vector<int64_t> change(B + 1, 0);     int64_t prefix = 0;     for (int i = 0; i < B; i++) {       prefix ^= basis[i];       change[i] = prefix;     }     change[B] = prefix;     int64_t value = 0;     for (unsigned mask = 0; mask < 1U << B; mask++) {       answers[__builtin_popcountll(value)]++;       value ^= change[__builtin_ctz(mask + 1)];     }   }   void dp_on_repeats() {     ;     for (int i = 0; i < B; i++)       for (int j = i + 1; j < B; j++)         basis[i] = min(basis[i], basis[i] ^ basis[j]);     ;     vector<int> repeats;     for (int bit = 0; bit < M; bit++) {       int count = 0;       for (int i = 0; i < B; i++)         if (basis[i] >> bit & 1) count++;       if (count > 1) repeats.push_back(bit);     }     int R = repeats.size();     vector<pair<int, int>> options(B);     int count_sum = 0;     for (int i = 0; i < B; i++) {       int64_t value = basis[i];       int count = __builtin_popcountll(value);       int repeat_mask = 0;       for (int r = 0; r < R; r++)         if (value >> repeats[r] & 1) {           count--;           repeat_mask |= 1 << r;         }       options[i] = {count, repeat_mask};       count_sum += count;     };     sort(options.begin(), options.end());     if (R <= 20) {       vector<vector<int64_t>> dp(count_sum + 1, vector<int64_t>(1 << R, 0));       dp[0][0] = 1;       int max_count = 0;       for (pair<int, int> &option : options) {         int opt_count = option.first;         int opt_mask = option.second;         for (int count = max_count; count >= 0; count--)           for (int mask = 0; mask < 1 << R; mask++)             dp[count + opt_count][mask ^ opt_mask] += dp[count][mask];         max_count += opt_count;       }       for (int count = 0; count <= count_sum; count++)         for (int mask = 0; mask < 1 << R; mask++)           if (dp[count][mask] > 0)             answers[count + __builtin_popcount(mask)] += dp[count][mask];     } else {       vector<vector<unsigned>> dp(count_sum - 1, vector<unsigned>(1 << R, 0));       int max_count = 0;       for (pair<int, int> &option : options) {         int opt_count = option.first;         int opt_mask = option.second;         for (int count = min(max_count - 1, count_sum - 1 - opt_count - 1);              count >= 0; count--)           for (int mask = 0; mask < 1 << R; mask++)             dp[count + opt_count][mask ^ opt_mask] += dp[count][mask];         dp[opt_count - 1][opt_mask]++;         max_count += opt_count;       }       for (int count = 0; count < count_sum - 1; count++)         for (int mask = 0; mask < 1 << R; mask++)           if (dp[count][mask] > 0)             answers[count + 1 + __builtin_popcount(mask)] += dp[count][mask];       int everything = 0;       for (int i = 0; i < B; i++) everything ^= options[i].second;       answers[count_sum + __builtin_popcount(everything)]++;       answers[0]++;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cin >> N >> M;     xor_basis<int64_t> basis_obj;     for (int i = 0; i < N; i++) {       int64_t a;       cin >> a;       basis_obj.add(a);     }     B = basis_obj.n;     basis.resize(B);     for (int i = 0; i < B; i++) basis[i] = basis_obj.basis[i];     answers.assign(M + 1, 0);     if (B <= 0.57 * M)       generate_all();     else       dp_on_repeats();     for (int i = 0; i <= M; i++) {       mod_int answer = answers[i];       answer *= mod_int(2).pow(N - B);       cout << answer << (i < M ?     :   n );     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int g[405][405];   vector<int> v[405];   double ans;   double gai[405];   double pos[405];   double suan(int yi, int juli) {     memset(gai, 0, sizeof(gai));     for (int i = 1; i <= n; i++) {       if (g[i][yi] == juli) {         for (int j = 0; j < (int)v[i].size(); j++) {           gai[v[i][j]] += 1.0 / n / (int)v[i].size();         }       }     }     vector<int> r;     r.clear();     for (int i = 1; i <= n; i++)       if (gai[i]) r.push_back(i);     double ret = 0;     for (int i = 1; i <= n; i++) {       double tmp = 0;       for (int j = 0; j < (int)r.size(); j++) {         pos[g[i][r[j]]] = max(pos[g[i][r[j]]], gai[r[j]]);       }       for (int j = 0; j < (int)r.size(); j++) {         tmp += pos[g[i][r[j]]];         pos[g[i][r[j]]] = 0;       }       ret = max(ret, tmp);     }     return ret;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++)         if (i != j) g[i][j] = 199912310;     }     for (int i = 1; i <= m; i++) {       int x, y, z;       scanf( %d%d , &x, &y);       g[x][y] = 1;       g[y][x] = 1;       v[x].push_back(y);       v[y].push_back(x);     }     for (int k = 1; k <= n; k++) {       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++)           g[i][j] = g[j][i] = min(g[i][j], g[i][k] + g[k][j]);       }     }     for (int i = 1; i <= n; i++) {       double now = 0;       for (int dist = 0; dist < n; dist++) {         int cnt = 0;         for (int j = 1; j <= n; j++) {           if (g[i][j] == dist) cnt++;         }         if (!cnt) continue;         double p = 1.0 / n;         double q = suan(i, dist);         now += max(p, q);       }       ans = max(ans, now);     }     printf( %.8lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool voltea;   int A[100005], B[100005], I[100005], D[100005], R[100005], ctos, hay, x, y, mid,       en;   int Z[100005], grande;   void lis() {     B[1] = A[1];     if (voltea)       D[ctos] = 1;     else       I[1] = 1;     hay = 1;     for (int i = 2; i <= ctos; i++) {       if (A[i] > B[hay]) {         ++hay;         B[hay] = A[i];         en = hay;       } else {         x = 1;         y = hay;         while (x < y) {           mid = (x + y) / 2;           if (B[mid] < A[i]) {             x = mid + 1;           } else {             y = mid;           }         }         B[x] = A[i];         en = x;       }       if (voltea) {         D[ctos - i + 1] = en;       } else {         I[i] = en;       }     }   }   int main() {     scanf( %d , &ctos);     for (int i = 1; i <= ctos; i++) {       scanf( %d , &A[i]);     }     lis();     voltea = true;     x = 1;     y = ctos;     while (x < y) {       swap(A[x], A[y]);       A[x] *= -1;       A[y] *= -1;       ++x;       --y;     }     if (x == y) {       A[x] *= -1;     }     lis();     grande = 1;     for (int i = 1; i <= ctos; i++) {       if (I[i] + D[i] - 1 > grande) {         grande = I[i] + D[i] - 1;       }     }     for (int i = 1; i <= ctos; i++) {       if (I[i] + D[i] - 1 == grande) {         Z[I[i]]++;       } else {         R[i] = 1;       }     }     for (int i = 1; i <= ctos; i++) {       if (R[i] == 0) {         R[i] = 2;         if (Z[I[i]] == 1) {           R[i] = 3;         }       }       printf( %d , R[i]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, b, c;     cin >> a >> b >> c;     if (a >= c || b >= c) {       cout <<  0 ;     } else if (a <= 0 && b <= 0) {       cout <<  -1 ;     } else {       long long int count = 0;       while (a < c && b < c) {         if (a > b) {           swap(a, b);         } else if (a < 0) {           count += (abs(a) / b + (abs(a) % b != 0));           if (abs(a) % b) {             long long int r = abs(a) % b;             a = (b - r);           } else {             a = 0;           }         } else {           long long int p = b;           b += a;           a = p;           count++;         }       }       cout << count;     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};   const int dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},                            {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};   int par[200010], r[200010], lar[200010];   void init() {     for (int i = 0; i < 200010; i++) {       par[i] = i;       r[i] = 0;       lar[i] = 1;     }   }   int find(int x) {     if (par[x] == x) return x;     return par[x] = find(par[x]);   }   bool same(int x, int y) { return find(x) == find(y); }   void unit(int x, int y) {     if (same(x, y)) return;     x = find(x);     y = find(y);     if (r[x] < r[y]) {       par[x] = y;       lar[y] += lar[x];     } else {       par[y] = x;       lar[x] += lar[y];       if (r[x] == r[y]) {         r[x]++;       }     }   }   int main() {     static int n;     static int a[200010];     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     init();     bool used[200010];     for (int i = 0; i < 200010; i++) {       used[i] = false;     }     vector<pair<int, int> > vec;     for (int i = 1; i <= n; i++) {       vec.push_back(pair<int, int>(a[i], i));     }     sort(vec.begin(), vec.end());     reverse(vec.begin(), vec.end());     int ans[200010];     int k = 1;     for (int i = 0; i < vec.size(); i++) {       pair<int, int> p = vec[i];       used[p.second] = true;       if (used[p.second - 1]) {         unit(p.second, p.second - 1);       }       if (used[p.second + 1]) {         unit(p.second, p.second + 1);       }       for (; k <= lar[find(p.second)]; k++) {         ans[k] = p.first;       }     }     for (int i = 1; i <= n; i++) {       printf( %d  , ans[i]);     }     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100 + 7;   int n;   map<pair<int, int>, int> id;   vector<int> g[N];   long double rep(long double x) {     if (x >= 2) {       x -= 2;     }     return x;   }   void dfs(int a, int p = 0, long double t = 0) {     int deg = (int)g[a].size();     long double jump = 2 / (long double)deg;     for (auto &b : g[a]) {       if (b == p) continue;       t = rep(t + jump);       cout << 1 <<     << id[{a, b}] <<    ;       if (t <= 1) {         cout << b <<     << a <<     << fixed << setprecision(6) << 1 - t <<   n ;       } else {         cout << a <<     << b <<     << fixed << setprecision(6) << 1 - rep(t + 1)              <<   n ;       }       dfs(b, a, rep(t + 1));     }   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i < n; i++) {       int x, y;       cin >> x >> y;       id[{x, y}] = i;       id[{y, x}] = i;       g[x].push_back(y);       g[y].push_back(x);     }     int root = 1;     cout << n - 1 <<   n ;     dfs(root);   }


#include <bits/stdc++.h>   const double eps = 1e-8;   const double pi = acos(-1.0);   const int INF = 0x7f7f7f7f;   const double inf = 1e50;   template <class T>   inline T minx(T a, T b) {     return (a == -1 || b < a) ? b : a;   }   template <class T>   inline T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <class T>   inline T lcm(T a, T b) {     return a * (b / gcd(a, b));   }   template <class T>   inline T getbit(T n) {     return n ? (1 + getbit(n & (n - 1))) : 0;   }   template <class T>   inline T lowbit(T n) {     return n & (-n);   }   using namespace std;   pair<double, double> parse(double x, double y) { return make_pair(x, y); }   int main() {     int i, j, k;     pair<double, double> A, B, C;     double x, y;     double dx, dy, tx, ty;     while (cin >> x >> y) {       A = parse(x, y);       cin >> x >> y;       B = parse(x, y);       cin >> x >> y;       C = parse(x, y);       dx = B.first - A.first;       dy = B.second - A.second;       tx = C.first - B.first;       ty = C.second - B.second;       double res = dx * ty - dy * tx;       if (res == 0)         puts( TOWARDS );       else if (res > 0)         puts( LEFT );       else         puts( RIGHT );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000009;   const int maxn = 1000010;   long long p[maxn], q[maxn];   int main() {     int i, n;     long long nAns = 0;     cin >> n;     n /= 2;     p[1] = 2;     q[1] = 1;     for (i = 2; i <= n; i++) {       p[i] = p[i - 1] * 2 % mod;       q[i] = q[i - 1] * (p[i] - 3) % mod;       nAns = (nAns + q[i] * 4) % mod;     }     cout << (2 * nAns * nAns % mod + nAns * 8 % mod + 10) % mod << endl;     return 0;   }


#include <bits/stdc++.h>   const int maxn = 1e5 + 7;   int main(int argc, char *argv[]) {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     int n, k;     std::set<std::pair<int, int> > t[maxn], s;     std::cin >> n >> k;     int u, v, w;     int ans = 0;     for (int i = 0; i < n - 1; i++) {       std::cin >> u >> v >> w;       t[u].insert(std::make_pair(v, w));       t[v].insert(std::make_pair(u, w));     }     for (int i = 1; i <= n; i++) {       if (t[i].size() == 1) {         s.insert(std::make_pair((*t[i].begin()).second, i));       }     }     while (n > k || s.size() > 2) {       auto i = *s.begin();       s.erase(i);       int cur = i.second;       ans = i.first;       n--;       int nxt = (*t[cur].begin()).first;       t[nxt].erase(t[nxt].lower_bound(std::make_pair(cur, 0)));       if (t[nxt].size() == 1) {         s.insert(std::make_pair((*t[nxt].begin()).second + ans, nxt));       }     }     std::cout << ans << std::endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e3 + 5;   const int MOD = 1e9 + 7;   int N, M, A, B;   int G[MAXN * MAXN], X, Y, Z;   int H[MAXN][MAXN];   int P[MAXN][MAXN];   int T[MAXN][MAXN];   long long ans;   deque<pair<int, int> > qu;   void reset() { qu.clear(); }   void push(int v, int p) {     while (qu.size() && qu.back().first >= v) {       qu.pop_back();     }     qu.push_back({v, p});   }   int pop(int p) {     while (qu.size() && qu.front().second < p) {       qu.pop_front();     }     assert(qu.size());     return qu.front().first;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> N >> M >> A >> B;     cin >> G[0] >> X >> Y >> Z;     for (int i = 1; i < N * M; i++) {       G[i] = (1LL * G[i - 1] * X + Y) % Z;     }     for (int i = 0; i < N; i++) {       for (int j = 0; j < M; j++) {         H[i][j] = G[i * M + j];       }     }     for (int i = 0; i < N; i++) {       reset();       for (int j = 0; j < B; j++) push(H[i][j], j);       P[i][B - 1] = pop(0);       for (int j = B; j < M; j++) {         push(H[i][j], j);         P[i][j] = pop(j - B + 1);       }     }     for (int j = B - 1; j < M; j++) {       reset();       for (int i = 0; i < A; i++) push(P[i][j], i);       ans += pop(0);       for (int i = A; i < N; i++) {         push(P[i][j], i);         ans += pop(i - A + 1);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int withoutzero(int x);   int main() {     int a, b, c, d, e, f;     cin >> a >> b;     d = withoutzero(a);     e = withoutzero(b);     c = a + b;     f = withoutzero(c);     if ((d + e) == f) {       cout <<  YES ;     } else {       cout <<  NO ;     }   }   int withoutzero(int x) {     int arr[10], i = 0, t = 0, k = 0;     while (x > 0) {       arr[i] = x % 10;       x = x / 10;       i++;     }     for (int j = 0; j < i; j++) {       if (arr[j] != 0) {         t += arr[j] * pow(10, k);         k++;       }     }     return t;   }


#include <bits/stdc++.h>   using namespace std;   long long f[100000 + 1], a[100000 + 1], n, d, b;   int main() {     scanf( %lld%lld%lld , &n, &d, &b);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     f[0] = 0;     for (int i = 1; i <= n; i++) f[i] += f[i - 1] + a[i];     long long a1 = 0, a2 = 0;     for (long long i = 1; i <= n / 2; i++) {       if (f[min(n, i + i * d)] >= (a1 + 1) * b) ++a1;       if (f[n] - f[max((long long)1, n - i - i * d)] >= (a2 + 1) * b) ++a2;     }     printf( %lld , n / 2 - min(a1, a2));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long N = 500005;   long long MAX = 9223372036854775807;   long long MOD = 1000000007;   long double PI = 4 * atan(1);   long long int t, a, b, res;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> t;     while (t--) {       cin >> a >> b;       res = 0;       a = abs(a - b);       res += a / 5;       a = a % 5;       res += a / 2 + a % 2;       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     long long int T;     cin >> T;     while (T--) {       long long int n;       cin >> n;       long long int a[n];       for (long long int i = 0; i < n; i++) cin >> a[i];       if (a[n - 1] > a[0])         cout <<  YES               <<   n ;       else         cout <<  NO               <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, siz[200005], l[200005], r[200005], a[200005], p[200005], an = 0,                                                                   b[200005];   bool vis[200005];   vector<int> vt[200005], vec;   set<int> st;   set<int>::iterator it;   int root(int node) {     while (p[node] != node) {       p[node] = p[p[node]];       node = p[node];     }     return node;   }   int merging(int n1, int n2) {     int p1 = root(n1), p2 = root(n2);     if (p1 == 0) return p2;     if (p2 == 200005 - 1) return p1;     if (p1 == p2) return p1;     if (siz[p1] > siz[p2]) {       siz[p1] += siz[p2];       p[p2] = p[p1];       l[p1] = min(l[p1], l[p2]);       r[p1] = max(r[p1], r[p2]);       return p1;     } else {       siz[p2] += siz[p1];       p[p1] = p[p2];       l[p2] = min(l[p2], l[p1]);       r[p2] = max(r[p1], r[p2]);       return p2;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     scanf( %d , &n);     int lef = 1, cur = 1, ri;     st.insert(0);     st.insert(200005 - 1);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       if (i != 1 && a[i] != a[i - 1]) {         l[cur] = lef, r[cur] = i - 1;         siz[cur] = r[cur] - l[cur] + 1;         vt[siz[cur]].push_back(l[cur]);         p[cur] = cur;         cur++;         lef = i;       }       st.insert(i);       b[i] = cur;     }     l[cur] = lef, r[cur] = n, siz[cur] = n - lef + 1;     vt[siz[cur]].push_back(l[cur]);     p[cur] = cur;     for (int i = 200005 - 1; i >= 1; i--) {       sort(vt[i].begin(), vt[i].end());       for (int j = 0, par, tmp, tpp, lol, now; j < vt[i].size(); j++) {         now = vt[i][j];         if (vis[now]) continue;         par = root(b[now]);         it = st.lower_bound(l[par]);         it--;         tmp = *it;         it = st.lower_bound(r[par]);         it++;         tpp = *it;         if (a[tmp] == a[tpp] && a[tmp]) {           lol = merging(b[tmp], b[tpp]);           if (siz[lol] >= i) {             vt[i][j] = l[lol];             j--;           } else             vt[siz[lol]].push_back(l[lol]);         }         for (it = st.lower_bound(l[par]); *it <= r[par]; it++) vec.push_back(*it);         for (int k = 0; k < vec.size(); k++) {           st.erase(vec[k]), vis[vec[k]] = true;         }         vec.clear();         an++;       }     }     printf( %d n , an);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     int maxi = 0;     int ind = 0;     string ret =   ;     for (int i = 0; i < n; i++) {       string temp;       int d = 10 - (s[i] - 48);       int j = i;       int ctr = 0;       while (ctr < n) {         ctr++;         temp += ((s[j] - 48 + d) % 10) + 48;         j = (j + 1) % s.length();       }       if (ret ==   )         ret = temp;       else if (temp < ret)         ret = temp;     }     cout << ret;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     long long n;     cin >> n;     vector<vector<long long> > p(2, vector<long long>(n)),         suf(2, vector<long long>(n + 1)), ebalVLevo(2, vector<long long>(n + 1)),         ebalVPravo(2, vector<long long>(n + 1));     for (long long i = 0; i < 2; i++) {       for (long long j = 0; j < n; j++) {         cin >> p[i][j];       }     }     for (long long i = 0; i < 2; i++) {       suf[i][n - 1] = p[i][n - 1];       for (long long j = n - 2; j >= 0; j--) {         suf[i][j] = suf[i][j + 1] + p[i][j];       }     }     for (long long i = 0; i < 2; i++) {       ebalVPravo[i][0] = (n)*p[i][0];       for (long long j = 1; j < n; j++) {         ebalVPravo[i][j] = ebalVPravo[i][j - 1] + p[i][j] * (n + j);       }     }     for (long long i = 0; i < 2; i++) {       ebalVLevo[i][n - 1] = p[i][n - 1];       for (long long j = n - 2; j >= 0; j--) {         ebalVLevo[i][j] = ebalVLevo[i][j + 1] + p[i][j] * (n - j);       }     }     long long sum = 0;     long long ans = 0;     long long i = 0, j = 0;     bool lastI = false;     for (long long t = 0; t < 2 * n; t++) {       sum += t * p[i][j];       long long tmp = sum;       long long tmpR =           ebalVPravo[i][n - 1] - ebalVPravo[i][j] - (n - t + j) * suf[i][j + 1];       long long tmpL = 0;       long long tmpLL = 0;       if (t == 0) {         tmpL = ebalVLevo[1][j] + (t + (n - j) - 1) * suf[1][j];       } else if (i == 0) {         tmpL = ebalVLevo[1][j + 1] + (t + (n - j) - 1) * suf[1][j + 1];       } else if (i == 1) {         tmpL = ebalVLevo[0][j + 1] + (t + (n - j) - 1) * suf[0][j + 1];       }       ans = max(ans, tmp + tmpL + tmpR);       if (!lastI) {         if (!i) {           i++;         } else {           i--;         }         lastI = true;       } else {         j++;         lastI = false;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long dp[300005];   vector<long long> g[300005];   long long ans = 1;   long long subs[300005];   long long f[300005][2];   void dfs(long long s, long long p) {     dp[s] = 0;     long long mx1 = 0;     long long mx2 = 0;     long long cnt = 0;     for (auto it : g[s]) {       if (it != p) {         dfs(it, s);         if (mx1 < dp[it]) {           mx2 = mx1;           mx1 = dp[it];         } else if (mx2 < dp[it])           mx2 = dp[it];         cnt++;       }     }     f[s][0] = mx1;     f[s][1] = mx2;     subs[s] = cnt;     dp[s] += mx1 + cnt;   }   void ans_dfs(long long s, long long p) {     for (auto it : g[s]) {       if (it != p) ans_dfs(it, s);     }     if (s == p) {       ans = max(ans, 1 + dp[s] + f[s][1]);       return;     }     long long y = f[p][0];     if (y == dp[s]) y = f[p][1];     long long z = max(y, f[s][1]);     ans = max(ans, 1 + dp[s] + z + 1);   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       for (long long i = 1; i <= n; i++) {         dp[i] = 0;         g[i].clear();       }       for (long long i = 0; i < n - 1; i++) {         long long a, b;         cin >> a >> b;         g[a].push_back(b);         g[b].push_back(a);       }       ans = 1;       dfs(1, 1);       ans_dfs(1, 1);       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 18;   long long dp[(1 << N)][105];   string n;   int qwq;   int m, pw[20];   bool used[10];   void init() {     pw[0] = 1;     for (int i = 1; i <= n.size(); i++) pw[i] = pw[i - 1] * 10 % m;   }   int main() {     cin >> n >> m;     dp[0][0] = 1;     init();     for (int i = 1; i < (1 << n.size()); i++) {       int sz = n.size() - __builtin_popcount(i);       for (int k = 0; k < m; k++) {         for (int j = 0; j < 10; j++) used[j] = false;         for (int j = 0; j < n.size(); j++)           if (((i >> j) & 1) && !used[n[j] -  0 ])             if (sz != (int)n.size() - 1 || n[j] !=  0 )               dp[i][k] +=                   dp[i - (1 << j)][(m + k - (n[j] -  0 ) * pw[sz] % m) % m],                   used[n[j] -  0 ] = true;       }     }     cout << dp[(1 << n.size()) - 1][0] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXM = 500 + 5;   const int MAXN = 500 + 5;   const int MAXQ = 300 + 5;   const int MAXK = 800 + 5;   const int P = 5;   const int MOD = 1e9 + 7;   int n, m, q, a[MAXN][MAXK];   int inv[P], ans = 1;   char buf[MAXM];   int main() {     for (int i = 0; i < P; i++) inv[i] = i * i * i % P;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %s , buf + 1);       for (int j = 1; j <= m; j++) a[j][i] = buf[j] -  a ;     }     scanf( %d , &q);     for (int i = 1; i <= q; i++) {       scanf( %s , buf + 1);       for (int j = 1; j <= m; j++) a[j][i + n] = buf[j] -  a ;     }     int cur = 1, r = 0;     for (int i = 1; i <= m && cur <= n; i++) {       while (cur <= n) {         int t = i;         for (int j = i + 1; j <= m; j++)           if (a[j][cur]) t = j;         for (int j = 1; j <= n + q; j++) swap(a[i][j], a[t][j]);         if (a[i][cur]) break;         cur++;       }       if (cur == n + 1) break;       for (int j = cur + 1; j <= n + q; j++)         a[i][j] = a[i][j] * inv[a[i][cur]] % P;       a[i][cur] = 1;       for (int j = i + 1; j <= m; j++) {         for (int k = cur + 1; k <= n + q; k++) {           a[j][k] -= a[j][cur] * a[i][k] % P;           if (a[j][k] < 0) a[j][k] += P;         }         a[j][cur] = 0;       }       r++;     }     for (int i = 1; i <= n - r; i++) ans = ans * 5ll % MOD;     for (int i = 1; i <= q; i++) {       int x = ans;       for (int j = 1; j <= m; j++) {         bool flg = 1;         for (int k = 1; k <= n; k++) flg &= (a[j][k] == 0);         flg &= (a[j][n + i] > 0);         if (flg) x = 0;       }       printf( %d n , x);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> st[100000], edge[200000], topo;   vector<pair<int, int> > ps;   int incnt[200000], tol;   priority_queue<int> que;   bool visit[200000];   int main(void) {     int n, m, in;     while (scanf( %d %d , &n, &m) == 2) {       for (int i = 0; i < m; ++i) st[i].clear();       for (int i = 0; i < n; ++i)         for (int j = 0; j < m; ++j) {           scanf( %d , &in);           st[j].push_back(in);         }       memset(incnt, 0, sizeof(incnt));       tol = m;       for (int i = 0; i < 200000; ++i) edge[i].clear();       for (int i = 0; i < n; ++i) {         ps.clear();         for (int j = 0; j < m; ++j)           if (st[j][i] >= 0) ps.push_back(make_pair(st[j][i], j));         sort(ps.begin(), ps.end());         for (int a = 0, b, k = ps.size(), pre = -1; a < k; a = b) {           for (b = a; (b < k) && (ps[b].first == ps[a].first); ++b) {             int now = ps[b].second;             if (pre >= 0) {               edge[pre].push_back(now);               ++incnt[now];             }             edge[now].push_back(tol);             ++incnt[tol];           }           pre = tol++;         }       }       topo.clear();       for (int i = 0; i < tol; ++i)         if (!incnt[i]) que.push(-i);       while (!que.empty()) {         int now = -que.top();         que.pop();         if (now < m) topo.push_back(now + 1);         for (int i = 0, j = edge[now].size(); i < j; ++i) {           --incnt[edge[now][i]];           if (!incnt[edge[now][i]]) que.push(-edge[now][i]);         }       }       if (topo.size() != m)         puts( -1 );       else {         printf( %d , topo[0]);         for (int i = 1, j = topo.size(); i < j; ++i) printf(  %d , topo[i]);         putchar(  n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<string, int> mp;   map<int, string> mp_back;   vector<int> way[5005 * 2];   int n, j, i, ans[5005 * 2] = {};   int main() {     cin >> n;     int w = 0;     for (i = 1; i <= n; i++) {       int v1, v2;       string s1, s2;       cin >> s1 >> s2;       if (!mp[s1])         ++w, mp[s1] = w, v1 = w, mp_back[w] = s1;       else         v1 = mp[s1];       if (!mp[s2])         ++w, mp[s2] = w, v2 = w, mp_back[w] = s2;       else         v2 = mp[s2];       way[v1].push_back(v2);       way[v2].push_back(v1);     }     for (i = 1; i <= w; i++) {       int friends[5005 * 2] = {}, friends2[5005 * 2] = {};       for (j = 0; j < way[i].size(); j++) friends[way[i][j]] = 1;       int maxf = 0;       for (j = 1; j <= w; j++)         if (!friends[j] && j != i) {           int size = 0;           for (int h = 0; h < way[j].size(); h++)             if (friends[way[j][h]]) ++size;           maxf = max(maxf, size);           friends2[j] = size;         }       for (j = 1; j <= w; j++)         if (friends2[j] == maxf && !friends[j] && j != i) ans[i]++;     }     cout << w << endl;     for (i = 1; i <= w; i++) cout << mp_back[i] <<     << ans[i] << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( avx2 )   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   void solve() {     int n;     cin >> n;     vector<int> ans;     for (int i = 1; i <= 1000; i += 2) {       ans.push_back(i);       ans.push_back(i);     }     if (ans.size() < n) {       for (int i = 0; i < ans.size(); i++) {         cout << ans[i] <<    ;       }       n -= ans.size();       for (int i = 0; i < n; i++) {         cout << ans[i] <<    ;       }       cout << endl;       return;     }     for (int i = int(0); i < int(n); i++) {       cout << ans[i] <<    ;     }     cout << endl;   }   signed main() {     int t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, i, j, sum, p[3][3];     stack<int> s;     queue<int> q1, q2;     for (i = 0; i < 3; i++)       for (j = 0; j < 3; j++) p[i][j] = (j + 3 - i) % 3;     while (s.size()) s.pop();     while (q1.size()) q1.pop();     while (q2.size()) q2.pop();     scanf( %d%d , &a, &b);     while (a) {       q1.push(a % 3);       a /= 3;     }     while (b) {       q2.push(b % 3);       b /= 3;     }     if (q1.size() > q2.size())       for (i = q2.size(); i < q1.size(); i++) q2.push(0);     else {       if (q2.size() > q1.size())         for (i = q1.size(); i < q2.size(); i++) q1.push(0);     }     while (q1.size()) {       a = q1.front();       q1.pop();       b = q2.front();       q2.pop();       s.push(p[a][b]);     }     sum = 0;     while (s.size()) {       c = s.top();       s.pop();       sum = sum * 3 + c;     }     printf( %d n , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-7;   const int MOD = 1e9 + 7;   const long long INFLL = 0x3f3f3f3f3f3f3f3f;   const int INF = 0x3f3f3f3f;   const int MAXN = 4e5 + 5;   char s[MAXN];   int vis[200], t[200];   int check(int n, int l) {     int need = (l / 2) * n, cnt = 0;     for (int i = 0; i < 200; i++) cnt += vis[i] / 2;     if (cnt >= need) return 1;     return 0;   }   void solve(int n, int l) {     vector<char> v1, v2;     printf( %d n , n);     for (int i = 0; i < 200; i++) {       while (vis[i] >= 2) v1.push_back((char)i), vis[i] -= 2;       if (vis[i]) v2.push_back((char)i);     }     for (int i = 0; i < n; i++) {       int p = 0;       while (p < l / 2) {         s[p] = s[l - 1 - p] = v1[v1.size() - 1];         v1.pop_back();         p++;       }       if (l & 1) {         if (v2.empty())           s[p] = v1[v1.size() - 1], v2.push_back(v1[v1.size() - 1]),           v1.pop_back();         else           s[p] = v2[v2.size() - 1], v2.pop_back();       }       s[l] = 0;       printf( %s  , s);     }   }   int main() {     int n;     cin >> n;     scanf( %s , s + 1);     for (int i = 1; i <= n; i++) vis[s[i]]++;     int maxn = INF;     for (int i = 1; i * i <= n; i++) {       if (n % i == 0) {         if (check(i, n / i)) maxn = min(i, maxn);         if (check(n / i, i)) maxn = min(n / i, maxn);       }     }     solve(maxn, n / maxn);   }


#include <bits/stdc++.h>   using namespace std;   int n, a[100001];   vector<vector<pair<int, int>>> o[6], ans;   void relax(vector<int>& m) {     o[m.size()].push_back({});     for (size_t i = 0; i < m.size(); i++)       o[m.size()].back().push_back({m[i], m[(i + 1) % m.size()]});     m.resize(1);   }   void gao(int x, int y) {     if (!y) ans.insert(ans.end(), o[x].begin(), o[x].end());     while (o[x].size() > (x == y) && o[y].size()) {       ans.push_back(o[x].back());       o[x].pop_back();       ans.back().insert(ans.back().end(), o[y].back().begin(), o[y].back().end());       o[y].pop_back();     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = 1; i <= n; i++)       if (a[i] != i) {         vector<int> u = {i}, m = {i};         while (a[u.back()] != i) u.push_back(a[u.back()]);         for (size_t c = 1; c < u.size(); c++) {           if (m.size() == 5) relax(m);           m.push_back(a[u[c]] = u[c]);         }         relax(m);       }     gao(5, 0);     gao(4, 0);     gao(2, 3);     while (o[3].size() >= 2) {       auto u = o[3].back();       o[3].pop_back();       o[2].push_back({{u[0].first, u[1].first}, {u[1].first, u[0].first}});       o[2].push_back({{u[1].first, u[2].first}, {u[2].first, u[1].first}});       gao(2, 3);     }     gao(2, 2);     gao(3, 0);     gao(2, 0);     printf( %d n , ans.size());     for (auto& c : ans) {       printf( %d n , c.size());       for (auto x : c) printf( %d  , x.first);       puts(  );       for (auto x : c) printf( %d  , x.second);       puts(  );     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m, tot, a[100010], ans[100010];   vector<pair<int, int> > q[100010];   set<int> s;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1, l, x; i <= m; i++) {       scanf( %d%d , &l, &x);       q[l].emplace_back(i, x);     }     s.insert(0);     tot = 1;     for (int i = 1; i <= n; i++) {       if (s.count(a[i]))         tot = 1ll * tot * 2 % 1000000007;       else {         vector<int> v;         for (int u : s) v.push_back(u ^ a[i]);         for (int u : v) s.insert(u);       }       for (auto &p : q[i]) ans[p.first] = s.count(p.second) ? tot : 0;     }     for (int i = 1; i <= m; i++) printf( %d n , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     std::cerr << name <<   :   << arg1 << endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     std::cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   long long int solve() {     long long int n;     cin >> n;     std::vector<long long int> v;     long long int seg = 0;     long long int count = 0;     for (long long int i = 0; i < n; i++) {       long long int a;       cin >> a;       v.push_back(a);       if (a != i + 1) {         count++;       } else {         if (count) {           seg++;           count = 0;         }       }     }     if (count) {       seg++;     }     if (seg == 0) {       cout << 0 <<   n ;     } else if (seg == 1) {       cout << 1 <<   n ;     } else {       cout << 2 <<   n ;     }     return 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int T = 1;     cin >> T;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, sav, mn = 1e9;   struct point {     long long x, y, uz;   } p[2005];   string s;   int det(point A, point B, point C) {     if (A.x * B.y + A.y * C.x + B.x * C.y - A.x * C.y - A.y * B.x - B.y * C.x < 0)       return -1;     return 1;   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> p[i].x >> p[i].y;       if (p[i].y < mn) {         mn = p[i].y;         sav = i;       }     }     cin >> s;     p[sav].uz = 1;     cout << sav <<    ;     for (int i = 0; i < s.size(); i++) {       int crt = 1, j, sgn;       while (p[crt].uz) crt++;       j = crt + 1;       if (s[i] ==  R )         sgn = 1;       else         sgn = -1;       while (j <= n) {         while (j <= n && p[j].uz) j++;         if (j > n) break;         if (det(p[sav], p[crt], p[j]) == sgn) crt = j;         j++;       }       sav = crt;       p[crt].uz = 1;       cout << sav <<    ;     }     for (int i = 1; i <= n; i++)       if (!p[i].uz) cout << i <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a;     vector<string> ss;     bool possible = false;     for (int i = 0; i < n; ++i) {       string s;       cin >> s;       if (!possible) {         if (s.substr(0, 2) ==  OO ) {           possible = true;           s[0] =  + ;           s[1] =  + ;         } else if (s.substr(3, 2) ==  OO ) {           possible = true;           s[3] =  + ;           s[4] =  + ;         }       }       ss.push_back(s);     }     if (possible) {       cout <<  YES n ;       for (int j = 0; j < n; ++j) {         cout << ss[j] <<   n ;       }     } else {       cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int maxd(long long int n) {     long long int temp = 10 * n, mm = 0;     while (temp /= 10) mm = max(mm, temp % 10);     return mm;   }   int main() {     long long int n, ans = 0;     cin >> n;     while (n) {       n -= maxd(n);       ans++;     }     cout << ans;     return 0;   }