#include <bits/stdc++.h>   using namespace std;   int n, m;   long long res1, res2, f[5][5];   string s;   int main() {     std::ios::sync_with_stdio(false);     cin >> s;     n = s.size();     for (int i = 0; i < (n); i++) {       f[s[i] -  a ][i % 2]++;       res1 += f[s[i] -  a ][1 - (i % 2)];       res2 += f[s[i] -  a ][i % 2];     }     cout << res1 <<     << res2 << endl;     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mxn = 3e5 + 5;   const long long MOD = 1e9 + 7;   const int BASE = 100000000;   const int INF = 1e9 + 8;   long long g[mxn], cnt[mxn], a[mxn];   void up_g(int x, const long long &val) {     while (x < mxn) {       g[x] += val;       x += x & (-x);     }   }   void update_g(int l, int r, const long long &val) {     up_g(l, val);     up_g(r + 1, -val);   }   long long get_g(int x) {     long long res = 0;     while (x) {       res += g[x];       x -= x & (-x);     }     return res;   }   void update_cnt(int x) {     while (x < mxn) {       cnt[x] += 1LL;       x += x & (-x);     }   }   long long get(int x) {     long long res = 0;     while (x) {       res += cnt[x];       x -= x & (-x);     }     return res;   }   long long get_cnt(int l, int r) { return (get(r) - get(l - 1)); }   signed main() {     int n;     cin >> n;     for (int i = (1); i <= (n); ++i) cin >> a[i];     long long cur = 0, sum = 0;     for (int i = (1); i <= (n); ++i) {       cur += (long long)(i - 1) * a[i] - get_g(a[i]);       cur += sum;       int x = (int)(a[i]);       while (x < mxn) {         long long k = min(x + (int)(a[i]) - 1, (int)(mxn - 5));         cur -= (long long)(x)*get_cnt(x, k);         update_g(x, k, x);         x += a[i];       }       update_cnt(a[i]);       sum += a[i];       cout << cur <<    ;     }   }


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


#include <cassert>   #include <cstdio>   #include <cstdlib>   #include <cstring>   #include <algorithm>   #include <iostream>   #include <set>   #include <map>   #include <vector>   #include <string>      #include <cmath>   #include <queue>   #include <stack>      #include <unordered_set>   #include <unordered_map>   #include <array>      using namespace std;      #define LL long long      inline int read() {       int x = 0, f = 1;       char c = getchar();       while (c <  0  || c >  9 ) {           if (c ==  - ) {               f = -1;           }           c = getchar();       }       while (c >=  0  && c <=  9 ) {           x = x * 10 + c -  0 ;           c = getchar();       }       return x * f;   }      inline void write(int x) {       static int sta[35];       int top = 0;       do {           sta[top++] = x % 10, x /= 10;       } while (x);       while (top) putchar(sta[--top] + 48);    }      inline void writeln(int x) {    if (x < 0) {     putchar( - ); x = -x;    }       static int sta[35];       int top = 0;       do {           sta[top++] = x % 10, x /= 10;       } while (x);       while (top) putchar(sta[--top] + 48);     putchar(  n );   }      inline LL readll() {       LL x = 0, f = 1;       char c = getchar();       while (c <  0  || c >  9 ) {           if (c ==  - ) {               f = -1;           }           c = getchar();       }       while (c >=  0  && c <=  9 ) {           x = x * 10 + c -  0 ;           c = getchar();       }       return x * f;   }      inline void writell(LL x) {    if (x < 0) {     putchar( - ); x = -x;    }       static LL sta[35];       int top = 0;       do {           sta[top++] = x % 10, x /= 10;       } while (x);       while (top) putchar(sta[--top] + 48);    }      inline void writellln(LL x) {    if (x < 0) {     putchar( - ); x = -x;    }       static LL sta[35];       int top = 0;       do {           sta[top++] = x % 10, x /= 10;       } while (x);       while (top) putchar(sta[--top] + 48);     putchar(  n );   }      const int hashMod = 999983;      template<class TYPENAME>   class HashNode {   public:       TYPENAME val;       int key, next;       HashNode(TYPENAME _val, int _key, int _next): val(_val), key(_key), next(_next) {}       bool isNull() {           return key == -1;       }   };      template<class TYPENAME>   class Hash {   public:       vector<HashNode<TYPENAME> > nodes;       vector<int> d;       int nodeN;       Hash() {           nodeN = 0;            d = vector<int>(hashMod, -1);       }       void push(int key, TYPENAME val) {           nodes.push_back(HashNode<TYPENAME>(val, key, d[key]));           d[key] = nodeN++;       }       HashNode<TYPENAME> find(int key, TYPENAME val) {           for (int p = d[key]; p != -1; p = nodes[p].next) {               if (nodes[p].val == val) {                   return nodes[p];               }           }           return HashNode<TYPENAME>(val, -1, -1);       }   };      int n, c, q;   vector<int> ii;   vector<LL> jj;   vector<int> p;   vector<vector<LL> > ways, wayC;      LL permContained(int l, int r, int cc) {       if (l == -1) {           return 1; // result for {-1, -1}       }       // otherwise, we can rotate (r, n)       // we have n - r - 1 to rotate, and cc - (r - l) coins       return ways[n - r - 1][cc - (r - l)];   }      // we can discretize all the queries, so we have an index for each query   // for each layer, we first save all the queries into boxes   // and take them out      bool pSmaller(const pair<int, int> &a, const pair<int, int> &b) {       return p[a.second] < p[b.second];   }   bool pGreater(const pair<int, int> &a, const pair<int, int> &b) {       return p[a.second] > p[b.second];   }      class Query {   public:       int ii, idx;       LL jj;       Query(int _idx, int _ii, LL _jj): idx(_idx), ii(_ii), jj(_jj) {}       void print() {           printf( Query(idx = %d, ii = %d, jj = %lld)  , idx, ii, jj);       }   };      bool cmpQuery(const Query &a, const Query &b) {       return a.jj < b.jj;   }   void solve() {       n = read(); c = read(); q = read();       // printf( task: n = %d. c = %d, q = %d n , n, c, q);       p = vector<int>(n);       for (int i = 0; i < n; ++i) {           p[i] = read();       }       ii = vector<int>(q);       jj = vector<LL>(q);       for (int i = 0; i < q; ++i) {           ii[i] = read() - 1; jj[i] = readll() - 1;           // cout << ii[i] <<     << jj[i] << endl;       }          // for (int i = 0; i < q; ++i) {       //     // ii[i] = read() - 1; jj[i] = readll() - 1;       //     cout << ii[i] <<     << jj[i] << endl;       // }          wayC = vector<vector<LL> >(n);       for (int i = 0; i < n; ++i) {           wayC[i] = vector<LL>(c + 1, 0);           wayC[i][0] = 1;       }          // wayC[n][c] = C(n, c)       for (int i = 0; i < n; ++i) {           for (int j = 1; j <= c; ++j) {               // consider C(i, j)               if (i < j) {                   wayC[i][j] = 0;               } else {                   wayC[i][j] = wayC[i - 1][j] + wayC[i - 1][j - 1];               }           }       }          // cout <<  finish wayC  << endl;       // for (int i = 0; i < q; ++i) {       //     // ii[i] = read() - 1; jj[i] = readll() - 1;       //     cout << ii[i] <<     << jj[i] << endl;       // }              ways = vector<vector<LL> >(n + 1);       for (int i = 0; i <= n; ++i) {           ways[i] = vector<LL>(c + 1, 1);       }       // ways[n][c] = C(n - 1, 0) + C(n - 1, 1) + ... + C(n - 1, c)       // ways[n][c] = ways[n][c - 1] + wayC[n - 1][c] (n > 0)       for (int i = 1; i <= n; ++i) {           ways[i][0] = wayC[i - 1][0];           for (int j = 1; j <= c; ++j) {               ways[i][j] = ways[i][j - 1] + wayC[i - 1][j];               // printf( ways(len = %d, c = %d) = %lld n , i, j, ways[i][j]);           }       }          // cout <<  finish ways  << endl;          // for (int i = 0; i < q; ++i) {       //     // ii[i] = read() - 1; jj[i] = readll() - 1;       //     cout << ii[i] <<     << jj[i] << endl;       // }          // now ways[len][c] = ways(n, c)          // we should build a deque for each 0 .. c, contains       // the [l, r] as the leftmost rotation(not over c)       // and sorted by the lex order. Our queries are all on layer c(we can use at most c coins)       // we sort all the jj, and scan the deque, every time we find an [l, r] so that jj is behind this       // we know that [0 .. r] has been decided for this jj query. if ii <= r, we can return the query result       // otherwise we want to decide the remaining part jj - ord([l, r]) = jj , with coins c - r + l,        // and start from r + 1       // for each c, we can decide p[l]  permutations before using [l, r] started at l  for each l in [0, n)       // so the query becomes another query (c - r + l, jj  + p[r + 1], ii) on layer c - r + l       // finally we have all queryies on layer 0, so there is only one state for queries       // queries down to here must asks something hard to decide, and here we must have jj = 1       // then we just return i-th          // first to make deques for each c  = [0 .. c]          vector<deque<pair<int, int> > > dq(c + 1);       for (int cc = 0; cc <= c; ++cc) {           // dq[cc].push_back({-1, -1}); // no change           dq[cc].push_back({n - 1, n - 1});           for (int i = n - 1; i >= 0; --i) {               vector<pair<int, int> > lft, rgt;               for (int j = i + 1; j <= i + cc && j < n; ++j) {                   // we have rotations [i, j]                   // current deque has all permutations with i-th = p[i]                   // so [i, j] is with i-th = p[j]                   // we should divide it into two parts: p[j] < p[i] && p[j] > p[i]                   // for p[j] < p[i], we insert it at front, from the order p[j] large to small                   // for p[j] > p[i], we insert it at back, from small to large                   // printf( p[j = %d] = %d, p[i = %d] = %d n , j, p[j], i, p[i]);                   if (p[j] < p[i]) {                       lft.push_back({i, j});                   } else {                       rgt.push_back({i, j});                   }               }               sort(lft.begin(), lft.end(), pGreater);               sort(rgt.begin(), rgt.end(), pSmaller);               for (int i = 0; i < lft.size(); ++i) {                   dq[cc].push_front(lft[i]);               }               for (int i = 0; i < rgt.size(); ++i) {                   dq[cc].push_back(rgt[i]);               }           }              // cout <<  c =   << cc << endl;           // for (auto pr: dq[cc]) {           //     printf( (%d, %d)  , pr.first, pr.second);           // }           // putchar(  n );       }          // cout <<  finish creating deques  << endl;          // int mc = 0;       // vector<int> queryIdx = discretize(jj, mc);       // vector<LL> ts(mc + 1, 0);       // for (int i = 0; i < q; ++i) {       //     ts[queryIdx[i]] = jj[i];       // }       // vector<vector<vector<Query> > > ids(c + 1);       // for (int i = 0; i <= c; ++i) {       //     ids[i] = vector<vector<Query> >(mc + 1);       // }       // for (int i = 0; i < q; ++i) {       //     ids[c][queryIdx[i]].push_back(Query(i, ii[i], queryIdx[i], jj[i]));       // }          vector<int> ans(q, -1);       // for (int i = 0; i < q; ++i) {       //     ans[i] = -1;       // }       // for (int i = 0; i < q; ++i) {       //     cout << ans[i] <<    ;       // }       // cout << endl;          vector<vector<Query> > que(c + 1);       for (int i = 0; i < q; ++i) {           que[c].push_back(Query(i, ii[i], jj[i]));           // que[c].back().print();       }          vector<vector<LL> > pp(c + 1);       // pp[cc][l]: the permutations before the first [l, r] started at l(l in [0, n - 1))       for (int cc = 0; cc <= c; ++cc) {           pp[cc] = vector<LL>(n, -1);           LL perms = 0;           int ll, rr;           for (pair<int, int> pr: dq[cc]) {               ll = pr.first; rr = pr.second;               if (ll == -1) {                   continue;               }               if (pp[cc][ll] == -1) {                   pp[cc][ll] = perms;                   // printf( pp[c = %d][l = %d] = %lld, from (l = %d, r = %d) n , cc, ll, pp[cc][ll], ll, rr);               }               perms += permContained(ll, rr, cc);           }           // pp[cc][n - 1] = perms - 1;           for (int i = n - 2; i >= 0; --i) {               pp[cc][i] = min(pp[cc][i], pp[cc][i + 1]);           }           for (int i = 0; i < n; ++i) {               // printf( pp[c = %d][l = %d] = %lld n , cc, i, pp[cc][i]);           }           // how to deal with -1, -1? it means no rotation at all           // and contains exactly 1 permutation p0 ... p_{n - 1}       }          // cout <<  finish calculating pp s  << endl;          for (int cc = c; cc >= 0; --cc) {           // work on layer cc           if (que[cc].size() == 0) {               continue;           }           sort(que[cc].begin(), que[cc].end(), cmpQuery);           // now we have queries saved in que[cc]           // and sorted by order of jj              // for [l, r] on layer cc, the undecided part is (r, n), len = n - r - 1           // so it contains ways[n - r - 1][cc - (r - l)]           // we go from the beginning of dq[cc], and use a pointer in que[cc] for current               // when we want to insert a new query c , jj , ii, we just do que[c ].push_back(Query(idx, ii, jj ))           // TODO: !!!!!           int qcur = 0;           LL currPerm = 0;           // cout <<  coin   << cc <<  :  ;           // for (int i = 0; i < que[cc].size(); ++i) {           //     // printf( Query(idx = %d, ii = %d, jj = %lld)  , que[cc][i].idx, que[cc][i].ii, que[cc][i].jj);           //     que[cc][i].print();           // }           // cout << endl;              // for (int i = 0; i < q; ++i) {           //     cout << ans[i] <<    ;           // }           // cout << endl;              for (pair<int, int> pr: dq[cc]) {               int ll = pr.first, rr = pr.second;               // printf( (%d, %d)  , ll, rr);               // printf( l = %d, r = %d, cc = %d, currPerm = %lld n , ll, rr, cc, currPerm);               LL newPerm = permContained(ll, rr, cc);               // printf( new perm = %lld n , newPerm);               while (qcur < que[cc].size() && que[cc][qcur].jj < currPerm + newPerm) {                   int cii = que[cc][qcur].ii;                   LL cjj = que[cc][qcur].jj;                   int cidx = que[cc][qcur].idx;                   // printf( qcur = %d: idx = %d, ii = %d, jj = %lld n , qcur, cidx, cii, cjj);                   if (ll == -1 || cii < ll) {                       // cout <<  quit1  << endl;                       ans[cidx] = p[cii];                       ++qcur; continue;                   }                   if (cii >= ll && cii <= rr) {                       // cout <<  quit2  << endl;                       ans[cidx] = p[rr - (cii - ll)];                       ++qcur; continue;                   }                   // otherwise, it is not determined                   // we should insert it into cc - (rr - ll)                   int nc = cc - (rr - ll);                   // what is the rank of the permutation in nc?                   // all [0, r] fixed, so we need to find the (que[cc][qucr].jj - currPerm)-th                    // in dq[cc], after pp[cc][r + 1]                   if (rr >= n - 1) {                       // cout <<  quit-1  << endl;                       ans[cidx] = -1;                       ++qcur; continue;                   }                   // otherwise, we should insert it to layer nc                   que[nc].push_back(Query(cidx, cii, pp[nc][rr + 1] + cjj - currPerm));                   ++qcur;                   // cout <<  quit0  << endl;               }               currPerm += newPerm;           }       }          for (int i = 0; i < q; ++i) {           writeln(ans[i]);       }   }      int main() {    // std::ios::sync_with_stdio(false);       // std::cin.tie(0);       int t = read();       for (int i = 0; i < t; ++i) {           solve();       }    return 0;   }


#include <bits/stdc++.h>   int main() {     int c, input[100010];     int i = -1, j, k;     while ((c = getchar()) !=   n ) {       if (i < 0 || input[i] != c)         input[++i] = c;       else         i--;     }     if (i < 0)       printf( Yes n );     else       printf( No n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int SIZE = 1 << 10;   int pointer = SIZE;   char buffer[SIZE];   char Advance() {     if (pointer == SIZE) {       fread(buffer, 1, SIZE, stdin);       pointer = 0;     }     return buffer[pointer++];   }   int Read() {     int answer = 0;     char ch = Advance();     while (!isdigit(ch)) ch = Advance();     while (isdigit(ch)) {       answer = answer * 10 + ch -  0 ;       ch = Advance();     }     return answer;   }   const int MAXN = 5000;   const long long MOD = 1000000007;   void Add(int &x, int y) {     x += y;     if (x >= MOD) x -= MOD;   }   void Subtract(int &x, int y) {     x -= y;     if (x < 0) x += MOD;   }   int factorial[1 + MAXN], inverse[1 + MAXN];   int RaiseToPower(int base, int power) {     int answer = 1;     while (power) {       if (power % 2) answer = (1LL * answer * base) % MOD;       base = (1LL * base * base) % MOD;       power /= 2;     }     return answer;   }   int Combinations2(int n) {     if (n % 2 == 0)       return (1LL * (n / 2) * (n - 1)) % MOD;     else       return (1LL * n * ((n - 1) / 2)) % MOD;   }   int children[1 + MAXN], depth[1 + MAXN];   int answer[1 + 2 * MAXN], chains[1 + 2 * MAXN];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i < n; i++) scanf( %d , &children[i]);     depth[1] = 1;     for (int i = 2; i <= n; i++)       depth[i] = (1LL * depth[i - 1] * children[i - 1]) % MOD;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         chains[i + j] = (1LL * depth[i] * depth[j] + chains[i + j]) % MOD;     int multiplier = 1;     for (int i = 1; i < n; i++) {       int divide = RaiseToPower(children[i], MOD - 2);       for (int j = i + 1; j <= n; j++) {         int add = (1LL * multiplier * depth[j]) % MOD;         Add(answer[j - i], add);         Subtract(chains[j - i + 2], (2LL * depth[j] * depth[i]) % MOD);         depth[j] = (1LL * depth[j] * divide) % MOD;       }       divide = (1LL * divide * divide) % MOD;       for (int j = 2; j <= 2 * (n - i); j++) {         chains[j] = (1LL * chains[j + 2] * divide) % MOD;         int add = (1LL * chains[j] * Combinations2(children[i])) % MOD;         add = (1LL * add * multiplier) % MOD;         Add(answer[j], add);       }       multiplier = (1LL * multiplier * children[i]) % MOD;     }     for (int i = 1; i <= 2 * n - 2; i++) printf( %d  , answer[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[200010], b[200010];   int nxt[200010];   void make_next() {     int i = 0, j = -1;     nxt[0] = -1;     while (i < m) {       if (j == -1 || b[i] == b[j]) {         i++;         j++;         if (b[i] == b[j])           nxt[i] = nxt[j];         else           nxt[i] = j;       } else         j = nxt[j];     }   }   int kmp() {     int i = 0, j = 0;     int cnt = 0;     while (i < n) {       if (a[i] == b[j]) {         i++;         j++;         if (j == m) {           cnt++;         }       } else {         j = nxt[j];         if (j == -1) {           i++;           j = 0;         }       }     }     return cnt;   }   int main() {     int i, j;     while (cin >> n >> m) {       for (i = 0; i < n; i++) cin >> a[i];       for (i = 0; i < m; i++) cin >> b[i];       if (n < m) {         cout <<  0 n ;         continue;       } else if (m == 1) {         cout << n << endl;         continue;       }       for (i = 0; i < n - 1; i++) a[i] = a[i + 1] - a[i];       for (i = 0; i < m - 1; i++) b[i] = b[i + 1] - b[i];       m--;       n--;       make_next();       cout << kmp() << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int SIZE = 1e5 + 5;   long long n, m, s;   vector<pair<long long, long long> > bug;   vector<pair<long long, long long> > stud;   vector<long long> pass;   long long allot[SIZE];   struct cmp {     bool operator()(pair<long long, long long> const& lhs,                     pair<long long, long long> const& rhs) {       return lhs.first < rhs.first;     }   };   long long ok(long long val) {     long long i = 0;     long long j = 0;     long long temp = s;     priority_queue<pair<long long, long long>,                    vector<pair<long long, long long> >,                    greater<pair<long long, long long> > >         pq;     while (i < bug.size()) {       while (stud[j].first >= bug[i].first && j < stud.size()) {         pq.push(make_pair(pass[stud[j].second], stud[j].second));         j++;       }       if (pq.size() == 0) return 0;       pair<long long, long long> cheap = pq.top();       pq.pop();       if (temp < cheap.first) return 0;       temp -= cheap.first;       long long days = 0;       while (i < bug.size() && days < val) {         allot[bug[i].second] = cheap.second;         i++;         days++;       }     }     return 1;   }   long long lowerbound(long long l, long long h) {     long long mid = (l + h) / 2;     if (l == h) return mid;     if (ok(mid)) {       return lowerbound(l, mid);     } else       return lowerbound(mid + 1, h);   }   int main() {     cin.sync_with_stdio(0);     cin >> n >> m >> s;     for (int i = 0; i <= m - 1; i++) {       long long a;       cin >> a;       bug.push_back(make_pair(a, i));     }     sort(bug.begin(), bug.end());     reverse(bug.begin(), bug.end());     for (int i = 0; i <= n - 1; i++) {       long long a;       cin >> a;       stud.push_back(make_pair(a, i));     }     sort(stud.begin(), stud.end());     reverse(stud.begin(), stud.end());     for (int i = 0; i <= n - 1; i++) {       long long a;       cin >> a;       pass.push_back(a);     }     long long l = 0;     long long h = bug.size();     long long temp = lowerbound(l, h);     if (ok(temp)) {       cout <<  YES n ;       for (int i = 0; i <= m - 1; i++) cout << allot[i] + 1 <<    ;     } else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mat[100001], mat2[100001];   long long k, suma, a, b, s, c;   int n;   map<int, int> mapa;   long long ct;   int main() {     cin >> n >> k;     for (int i = 0; i < n; ++i) {       cin >> mat[i];       mapa[mat[i]]++;     }     sort(mat, mat + n);     suma = 1;     c = 1;     for (int i = 0; i < n; i++) {       if (i == 0) {       } else if (mat[i] == mat[i - 1]) {         suma += n;         continue;       }       ct = mapa[mat[i]];       if (suma + ct * n > k) {         a = mat[i];         s = k - suma;         b = mat[(int)(s / ct)];         break;       }       suma += n;     }     cout << a <<     << b << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxm = 1e5 + 5;   vector<int> g[maxm];   int n, q;   int sz[maxm];   int d[maxm];   int f[maxm][25];   const int maxd = 20;   void dfs(int x, int fa) {     sz[x] = 1;     for (int j = 1; j <= maxd; j++) {       f[x][j] = f[f[x][j - 1]][j - 1];     }     for (int v : g[x]) {       if (v == fa) continue;       d[v] = d[x] + 1;       f[v][0] = x;       dfs(v, x);       sz[x] += sz[v];     }   }   int lca(int a, int b) {     if (d[a] < d[b]) swap(a, b);     for (int i = maxd; i >= 0; i--) {       if (d[f[a][i]] >= d[b]) {         a = f[a][i];       }     }     if (a == b) return a;     for (int i = maxd; i >= 0; i--) {       if (f[a][i] != f[b][i]) {         a = f[a][i];         b = f[b][i];       }     }     return f[a][0];   }   signed main() {     ios::sync_with_stdio(0);     cin >> n;     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       g[a].push_back(b);       g[b].push_back(a);     }     d[1] = 1;     f[1][0] = 1;     dfs(1, 1);     cin >> q;     while (q--) {       int a, b;       cin >> a >> b;       if (a == b) {         cout << n << endl;         continue;       }       int lc = lca(a, b);       int dab = d[a] + d[b] - 2 * d[lc];       if (dab % 2) {         cout << 0 << endl;         continue;       }       if (d[a] < d[b]) swap(a, b);       int dist = dab / 2;       for (int i = maxd; i >= 0; i--) {         if (dist - (1 << i) > 0) {           a = f[a][i];           b = f[b][i];           dist -= (1 << i);         }       }       if (d[a] == d[b]) {         cout << n - sz[a] - sz[b] << endl;         continue;       }       cout << sz[f[a][0]] - sz[a] << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   const double PI = acos(-1);   template <class A, class B>   std::ostream& operator<<(std::ostream& st, const std::pair<A, B> p) {     st <<  (  << p.first <<  ,   << p.second <<  ) ;     return st;   }   using namespace std;   const int MAX = 100 * 1000 + 10;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   std::vector<int> cand_base{26,  29,  31,  37,  41,  43,  47,  53, 59,                              61,  67,  71,  73,  79,  83,  89,  97, 101,                              103, 107, 109, 113, 127, 131, 137, 139};   std::vector<int> cand_mod{1000001273, 1000001279, 1000001311, 1000001329,                             1000001333};   int base[2], mod[2], base_power[2][MAX];   int n;   std::vector<int> adj[MAX];   int siz[MAX];   int add(int a, int b, int m) {     a += b;     if (a >= m) a -= m;     if (a < 0) a += m;     if (a >= m || a < 0) a = (a % m + m) % m;     return a;   }   int mul(int a, int b, int m) { return (a * (long long)b) % m; }   void init_hashing() {     srand(0);     shuffle(cand_base.begin(), cand_base.end(), rng);     shuffle(cand_mod.begin(), cand_mod.end(), rng);     for (int i = 0; i < (2); i++) base[i] = cand_base[i] + n;     for (int i = 0; i < (2); i++) mod[i] = cand_mod[i];     for (int i = 0; i < (2); i++) base_power[i][0] = 1;     for (int i = 0; i < 2; i++)       for (int j = 0; j < MAX - 1; j++)         base_power[i][j + 1] = mul(base_power[i][j], base[i], mod[i]);   }   struct DS {     map<std::pair<int, int>, int> cnt;     void add(std::pair<int, int> x, int v) {       cnt[x] += v;       if (cnt[x] == 0)         cnt.erase(x);       else         assert(cnt[x] > 0);     }   };   std::pair<int, int> f[MAX];   vector<pair<std::pair<int, int>, int>> children[MAX];   DS ds;   std::pair<int, int> merge(std::pair<int, int> L, std::pair<int, int> R,                             int len) {     std::pair<int, int> h;     h.first = add(mul(L.first, base_power[0][len], mod[0]), R.first, mod[0]);     h.second = add(mul(L.second, base_power[1][len], mod[1]), R.second, mod[1]);     return h;   }   std::pair<int, int> dfs(int u, int p) {     auto& C = children[u];     for (int v : adj[u])       if (v != p) {         auto tmp = dfs(v, u);         C.emplace_back(tmp, v);         siz[u] += siz[v];       }     sort(C.begin(), C.end());     f[u] = std::pair<int, int>(0, 0);     siz[u] = 1;     for (auto [h, v] : C) {       f[u] = merge(f[u], h, siz[v]);       siz[u] += siz[v];     }     f[u] = merge(f[u], std::pair<int, int>(siz[u], siz[u]), 1);     ds.add(f[u], 1);     return f[u];   }   std::pair<int, int> ans;   void dfs(int u, int p, std::pair<int, int> fp) {     std::pair<int, int> old = f[u];     ds.add(old, -1);     ans = max(ans, std::pair<int, int>(ds.cnt.size(), -u));     auto& C = children[u];     if (p) {       C.emplace_back(fp, p);       sort(C.begin(), C.end());     }     int m = ((int)C.size());     std::vector<int> sizes(m);     std::vector<std::pair<int, int>> suff(m);     for (int i = 0; i < (m); i++) {       int v = C[i].second;       sizes[i] = (v == p) ? (n - siz[u]) : siz[v];     }     for (int i = m - 1, tot = 0; i > 0; i--) {       std::pair<int, int> h = C[i].first;       suff[i - 1] = merge(h, suff[i], tot);       tot += sizes[i];     }     std::pair<int, int> H(0, 0);     int tot = 0;     for (int i = 0; i < (m); i++) {       auto [h, v] = C[i];       int s = sizes[i];       std::pair<int, int> tmp = merge(H, suff[i], n - 1 - s - tot);       tmp = merge(tmp, std::pair<int, int>(n - s, n - s), 1);       ds.add(tmp, 1);       if (v != p) dfs(v, u, tmp);       ds.add(tmp, -1);       H = merge(H, h, s);       tot += s;     }     ds.add(old, 1);   }   int main() {     scanf( %d , &n);     for (int e = 0; e < (n - 1); e++) {       int a, b;       scanf( %d %d , &a, &b);       adj[a].push_back(b);       adj[b].push_back(a);     }     init_hashing();     dfs(1, 0);     ans = std::pair<int, int>(-1, 0);     dfs(1, 0, std::pair<int, int>(0, 0));     cout << -ans.second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   #pragma GCC optimize( no-stack-protector )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native )   #pragma GCC optimize( fast-math )   const long long N = 1e6 + 5;   const long double EPS = 1e-12;   const long long INF = 2e18 + 5;   const long long MOD = 1e9 + 7;   const long double PI = 3.14159265358979323;   vector<set<long long> > g;   vector<pair<long long, long long> > a;   vector<long long> ans, u;   void dfs(long long v) {     u[v] = 1;     for (auto &i : g[v])       if (!u[i]) dfs(i);     ans.push_back(v);   }   void topsort(long long n) {     ans.clear();     for (long long i = 0; i < n; i++) {       if (!u[i]) dfs(i);     }     reverse(ans.begin(), ans.end());   }   bool bin(long long n, long long m) {     for (long long i = 0; i < n; i++) {       g[i].clear();       u[i] = 0;     }     for (long long i = 0; i < m; i++) {       g[a[i].first].insert(a[i].second);     }     topsort(n);     for (long long i = 0; i + 1 < ans.size(); i++) {       if (g[ans[i]].find(ans[i + 1]) == g[ans[i]].end()) return 0;     }     return 1;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long ttt = 1;     for (; ttt; --ttt) {       long long n, m;       cin >> n >> m;       a.resize(m);       g.resize(n);       u.resize(n);       for (long long i = 0; i < m; i++) {         cin >> a[i].first >> a[i].second;         a[i].first--;         a[i].second--;       }       if (!bin(n, m)) {         return cout <<  -1 n , 0;       }       long long l = 1, r = m;       while (r - l > 1) {         long long mid = (l + r) / 2;         if (mid <= m && bin(n, mid))           r = mid;         else           l = mid;       }       if (bin(n, l))         cout << l <<   n ;       else         cout << r <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, *a, *b, times, i, day;     while (cin >> n >> m) {       a = new int[m];       b = new int[m];       times = 1;       for (i = 0; i < m; i++) cin >> a[i] >> b[i];       for (i = 0; i < m - 1; i++) {         if (b[i] != a[i + 1] - 1) break;       }       if (i + 1 == m && b[i] == n)         cout <<  OK  << endl;       else {         if (a[0] != 1) {           day = 1;           times--;         } else if (b[i] == a[i + 1]) {           day = b[i];           while (b[i] == a[i + 1] && b[i] == day) {             times++;             i++;           }         } else {           day = b[i] + 1;           times--;         }         cout << day <<     << times << endl;       }       delete[] a;       delete[] b;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     char m[11], digit[10] = { 0 }, digitcount(0);     scanf( %d%s , &n, &m);     while (n != 0) {       digit[digitcount++] =  0  + n % 10;       n /= 10;     }     sort(digit, digit + digitcount);     if (digit[0] ==  0 ) {       for (int i = 1; i < digitcount; ++i) {         if (digit[i] !=  0 ) {           digit[0] = digit[i];           digit[i] =  0 ;           break;         }       }     }     if (strcmp(m, digit) == 0)       cout <<  OK  << endl;     else       cout <<  WRONG_ANSWER  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 1000 + 10;   int n, flag, a[maxN], i, j, m;   int main() {     cin >> n;     for (i = 2; i <= n; i++) {       for (j = 2; j * j <= i; j++) {         if (i != j && i % j == 0) flag = 1;       }       j = i;       while (flag == 0 && j <= n) {         a[m++] = j;         j *= i;       }       flag = 0;     }     cout << m << endl;     for (int k = 0; k < m; k++) cout << a[k] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (a < 0) a = -a;     if (b < 0) b = -b;     return b == 0 ? a : gcd(b, a % b);   }   template <typename T>   void read(T &res) {     bool flag = false;     char ch;     while (!isdigit(ch = getchar())) (ch ==  - ) && (flag = true);     for (res = ch - 48; isdigit(ch = getchar());          res = (res << 1) + (res << 3) + ch - 48)       ;     flag && (res = -res);   }   long long lcm(long long a, long long b) { return a * b / gcd(a, b); }   long long qp(long long a, long long b, long long mod) {     long long ans = 1;     if (b == 0) {       return ans % mod;     }     while (b) {       if (b % 2 == 1) {         b--;         ans = ans * a % mod;       }       a = a * a % mod;       b = b / 2;     }     return ans % mod;   }   long long qpn(long long a, long long b, long long p) {     long long ans = 1;     a %= p;     while (b) {       if (b & 1) {         ans = (ans * a) % p;         --b;       }       a = (a * a) % p;       b >>= 1;     }     return ans % p;   }   set<long long> s;   signed main() {     long long t;     read(t);     while (t--) {       long long n;       read(n);       long long po = 0;       s.insert(po);       for (long long i = 1; i * i <= n; i++) {         s.insert(n / i);         s.insert(n / (n / i));       }       printf( %d n , s.size());       for (auto x : s) {         printf( %lld  , x);       }       s.clear();       printf(  n );     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   const long long N = 2e5 + 10;   const long long mod = 1e9 + 7;   struct Trie {     Trie *child[2];     long long cnt;   };   Trie *createNode() {     Trie *node = (Trie *)malloc(sizeof(Trie));     memset(node->child, NULL, sizeof node->child);     node->cnt = 0;     return node;   }   void insert(Trie *root, long long x) {     for (long long i = 30; i >= 0; --i) {       long long val = (1LL << i);       long long bit = 0;       if (val & x) bit = 1;       if (!root->child[bit]) root->child[bit] = createNode();       root = root->child[bit];       root->cnt++;     }   }   void erase(Trie *root, long long x) {     for (long long i = 30; i >= 0; --i) {       long long val = (1LL << i);       long long bit = 0;       if (val & x) bit = 1;       if (!root->child[bit]) root->child[bit] = createNode();       root = root->child[bit];       root->cnt--;     }   }   long long query(Trie *root, long long x) {     long long ans = 0;     for (long long i = 30; i >= 0; --i) {       long long val = (1 << i);       long long bit = 0;       if (val & x) bit = 1;       if (root->child[bit] && root->child[bit]->cnt > 0) {         root = root->child[bit];       } else {         assert(root->child[bit ^ 1] && root->child[bit ^ 1]->cnt > 0);         ans += val;         root = root->child[bit ^ 1];       }     }     return ans;   }   void solve() {     long long n;     cin >> n;     long long a[n], b[n];     for (long long i = 0; i < n; ++i) cin >> a[i];     for (long long i = 0; i < n; ++i) cin >> b[i];     Trie *root = createNode();     for (long long i = 0; i < n; ++i) {       insert(root, b[i]);     }     vector<long long> ans;     for (long long i = 0; i < n; ++i) {       long long x = query(root, a[i]);       ans.push_back(x);       erase(root, a[i] ^ x);     }     for (long long i = 0; i < n; ++i) cout << ans[i] <<    ;     cout <<   n ;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     ;     long long t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline int read(T &a) {     a = 0;     char c = getchar(), f = 1;     while (c >  9  || c <  0 ) {       if (c ==  - ) f = (~f) + 1;       if (c == -1) return -1;       c = getchar();     }     while (c <=  9  && c >=  0 )       a = (a << 1) + (a << 3) + (c ^ 48), c = getchar();     a *= f;     return 1;   }   template <typename T>   inline int write(T a) {     if (a < 0) putchar( - ), a = (~a) + 1;     if (a / 10) return write(a / 10) & putchar(a % 10 | 48);     return putchar(a | 48);   }   template <typename T>   inline int write(T a, char c) {     return write(a) + putchar(c);   }   int n, m;   int w[200001];   int x[200001], y[200001];   int need[200001];   bool used[200001];   vector<int> v[200001];   bool ok[200001];   queue<int> q;   int ans[200001], cnt;   int main() {     read(n), read(m);     for (int i = 1; i <= n; i++) read(w[i]);     for (int i = 1; i <= m; i++) {       read(x[i]), read(y[i]), need[x[i]]++, need[y[i]]++;       v[x[i]].push_back(i);       v[y[i]].push_back(i);     }     for (int i = 1; i <= n; i++)       if (need[i] <= w[i]) {         used[i] = 1;         for (auto j : v[i])           if (!ok[j]) {             ok[j] = 1;             q.push(j);           }       }     while (!q.empty()) {       int t = q.front();       q.pop();       ans[++cnt] = t;       need[x[t]]--, need[y[t]]--;       int i = y[t];       if (need[i] <= w[i] && !used[i]) {         used[i] = 1;         for (auto j : v[i])           if (!ok[j]) {             ok[j] = 1;             q.push(j);           }       }       i = x[t];       if (need[i] <= w[i] && !used[i]) {         used[i] = 1;         for (auto j : v[i])           if (!ok[j]) {             ok[j] = 1;             q.push(j);           }       }     }     if (cnt != m) return puts( DEAD ) & 0;     puts( ALIVE );     for (int i = cnt; i >= 1; i--) write(ans[i],    );     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   int n, Cnt = 0, Num = 0;   int l[200000 + 10], r[200000 + 10];   map<int, int> mp;   int Di[200000 + 10];   vector<int> f[200000 + 10], No[200000 + 10];   int cur[200000 + 10];   bool b[200000 + 10];   int Ans[200000 + 10];   int Check() {     int Now = -1, ODD = 0;     for (int i = 1; i <= Cnt; i++)       if (f[i].size() % 2 == 1) {         ODD++;         Now = i;       }     if (ODD == 2) return Now;     if (ODD == 0) return 1;     return -1;   }   void Euler(int x) {     for (int i = cur[x]; i < f[x].size(); i = cur[x]) {       cur[x] = i + 1;       if (b[No[x][i]]) continue;       b[No[x][i]] = true;       Euler(f[x][i]);     }     Ans[++Ans[0]] = x;   }   int main() {     scanf( %d , &n);     n--;     for (int i = 1; i <= n; i++) scanf( %d , &l[i]);     for (int i = 1; i <= n; i++) scanf( %d , &r[i]);     int x, y;     for (int i = 1; i <= n; i++) {       if (l[i] > r[i]) return printf( -1 ), 0;       if (!mp.count(l[i]))         x = mp[l[i]] = ++Cnt, Di[Cnt] = l[i];       else         x = mp[l[i]];       if (!mp.count(r[i]))         y = mp[r[i]] = ++Cnt, Di[Cnt] = r[i];       else         y = mp[r[i]];       Num++;       f[x].push_back(y);       No[x].push_back(Num);       f[y].push_back(x);       No[y].push_back(Num);     }     int Begin = Check();     if (Begin == -1) return printf( -1 ), 0;     Euler(Begin);     if (Ans[0] != n + 1) return printf( -1 ), 0;     for (int i = n + 1; i; i--) printf( %d  , Di[Ans[i]]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, a[100005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     cout.tie();     cin >> n >> k;     if (k < n / 2 || (n == 1 && k)) {       cout << -1;       return 0;     }     if (n == 1 && k == 0) {       cout << 1;       return 0;     }     k = k - (n - 2) / 2;     cout << k <<     << k * 2 <<    ;     k = k * 2 + 1;     for (int i = 0; i <= n - 3; i++) cout << k + i <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void qmax(long long &x, int y) {     if (x < y) x = y;   }   void qmin(long long &x, long long y) {     if (x > y) x = y;   }   inline long long read() {     char s;     long long k = 0, base = 1;     while ((s = getchar()) !=  -  && s != EOF && !(isdigit(s)))       ;     if (s == EOF) exit(0);     if (s ==  - ) base = -1, s = getchar();     while (isdigit(s)) {       k = k * 10 + (s ^  0 );       s = getchar();     }     return k * base;   }   inline void write(int x) {     static char cnt, num[15];     cnt = 0;     if (!x) {       printf( 0 );       return;     }     for (; x; x /= 10) num[++cnt] = x % 10;     for (; cnt; putchar(num[cnt--] + 48))       ;   }   const int maxn = 1e5 + 100;   int n, m, k, s, X, Y;   int a[maxn];   int po[maxn], ne[maxn * 2], to[maxn * 2], id;   void add(int x, int y) {     id++;     to[id] = y;     ne[id] = po[x];     po[x] = id;   }   int dis[maxn], vis[maxn];   queue<int> q;   int c[maxn][101];   void spfa(int x) {     memset(vis, 0, sizeof(vis));     memset(dis, 0x3f3f3f3f, sizeof(dis));     int inf = dis[0];     while (!q.empty()) q.pop();     for (int i = 1; i <= n; i++)       if (a[i] == x) {         dis[i] = 0;         vis[i] = 1;         q.push(i);       }     while (!q.empty()) {       int u = q.front(), v;       q.pop();       vis[u] = 0;       for (int i = po[u]; i; i = ne[i]) {         v = to[i];         if (dis[v] > dis[u] + 1) {           dis[v] = dis[u] + 1;           if (!vis[v]) {             vis[v] = 1;             q.push(v);           }         }       }     }     for (int i = 1; i <= n; i++) c[i][x] = dis[i];   }   int main() {     n = read();     m = read();     k = read();     s = read();     for (int i = 1; i <= n; i++) a[i] = read();     for (int i = 1; i <= m; i++) {       X = read();       Y = read();       add(X, Y);       add(Y, X);     }     for (int i = 1; i <= k; i++) spfa(i);     for (int i = 1; i <= n; i++) {       long long sum = 0;       sort(c[i] + 1, c[i] + k + 1);       for (int j = 1; j <= s; j++) sum += c[i][j];       printf( %lld  , sum);     }   }


#include <bits/stdc++.h>   using namespace std;   string s;   int pos[1000];   int n, a, b;   int main() {     cin >> n;     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  x )         a++;       else         b++;     }     cout << abs(n / 2 - a) << endl;     int t = abs(n / 2 - a);     if (a > b) {       for (int i = 0; i < s.size(); i++)         if (s[i] ==  x  && t) {           s[i] =  X ;           t--;         }     } else if (a < b) {       for (int i = 0; i < s.size(); i++)         if (s[i] ==  X  && t) {           s[i] =  x ;           t--;         }     }     cout << s << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   void checkDefine();   long long int a, b, c, d;   int main() {     cin >> a >> b >> c >> d;     long long int t1 = max(3 * a / 10, a - (a * c) / 250);     long long int t2 = max(3 * b / 10, b - (b * d) / 250);     if (t1 > t2) {       cout <<  Misha ;     } else if (t1 < t2) {       cout <<  Vasya ;     } else {       cout <<  Tie ;     }     return 0;   }   void checkDefine() {     long long int n, a[200005];     map<long long int, long long int> m;     cin >> n;     for (int i = (0), _b = (n - 1); i <= _b; i++) {       cin >> a[i];       m[a[i]]++;     }     string s;     cin >> s;     {       cout <<  s             <<   =  ;       cout << (s) << endl;     };     {       cout <<  a             <<   =  ;       for (int _ = 0, _a = (n); _ < _a; _++) cout << a[_] <<    ;       cout << endl;     };     {       cout <<   ------------              <<   =  ;       cout << ( ------------ ) << endl;     };     for (__typeof(m.begin()) it = m.begin(); it != m.end(); ++it) {       cout << it->first <<     << it->second << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, cnt[200005], x, y, ans;   vector<long long> v[200005];   void dfs(long long pos, long long pre) {     long long len = v[pos].size();     for (long long i = 0; i < len; i++) {       long long xx = v[pos][i];       if (xx != pre) {         dfs(xx, pos);         cnt[pos] += cnt[xx];         ans += min(cnt[xx], 2 * k - cnt[xx]);       }     }   }   int main() {     scanf( %lld%lld , &n, &k);     for (long long i = 0; i < 2 * k; i++) {       scanf( %lld , &x);       cnt[x] = 1;     }     for (long long i = 0; i < n - 1; i++) {       scanf( %lld%lld , &x, &y);       v[x].push_back(y);       v[y].push_back(x);     }     dfs(1, 0);     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   bool cmp(pair<long long, int> l, pair<long long, int> r) {     return l.first < r.first;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n, A, cf, cm, money;     cin >> n >> A >> cf >> cm >> money;     vector<pair<long long, int> > v(n + 1);     for (int i = 1; i <= n; i++) {       cin >> v[i].first;       v[i].second = i;     }     sort(v.begin(), v.end());     vector<long long> pf(n + 1, 0);     long long c = 0;     for (int i = 1; i <= n; i++) pf[i] = v[i].first + pf[i - 1];     vector<long long> ps(n + 2, 0);     for (int i = n; i >= 1; i--) ps[i] = ps[i + 1] + v[i].first;     long long ans = 0;     long long no = 0;     long long mn = 0;     for (long long i = 0; i <= n; i++) {       long long m = money;       m = m - max((long long)0, (A * i - ps[n - i + 1]));       if (m < 0) continue;       long long pnts = cf * i;       int lo = 0;       int hi = A;       while (lo < hi) {         long long mid = (lo + hi + 1) >> (long long)1;         vector<pair<long long, int> >::iterator it = lower_bound(             v.begin(), v.begin() + (n - i + 1), make_pair(mid, 0), cmp);         if (it == v.begin()) {           lo = mid;           continue;         } else           it--;         long long reqd = ((long long)(it - v.begin())) * mid - pf[it - v.begin()];         if (reqd <= m)           lo = mid;         else           hi = mid - 1;       }       pnts += lo * cm;       if (ans < pnts) {         ans = pnts;         no = i;         mn = lo;       }       ans = max(ans, pnts);     }     cout << ans <<   n ;     ;     vector<long long> re(n + 1, 0);     for (int i = n; i > n - no; i--) re[(int)v[i].second] = A;     for (int i = 1; i <= n - no; i++) re[v[i].second] = max(v[i].first, mn);     for (int i = 1; i <= n; i++) cout << re[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   int nextInt() {     int x;     scanf( %d , &x);     return x;   }   double nextDouble() {     double x;     scanf( %lf , &x);     return x;   }   long long nextLong() {     long long x;     scanf( %I64d , &x);     return x;   }   char nextChar() {     char x;     scanf( %c , &x);     return x;   }   void newLine() { printf(  n ); }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   long long powM(long long a, long long b, long long MOD) {     long long x = 1, y = a;     while (b > 0) {       if (b % 2 == 1) {         x = (x * y);         if (x > MOD) x %= MOD;       }       y = (y * y);       if (y > MOD) y %= MOD;       b /= 2;     }     return x;   }   long long ModExp(long long n, long long k, long long MOD) {     long long ans = 1;     while (k > 0) {       if (k & 1) ans = (ans * n) % MOD;       n = (n * n) % MOD;       k /= 2;     }     return ans;   }   long long Exp(long long n, long long k) {     long long ans = 1;     while (k > 0) {       if (k & 1) ans = (ans * n);       n = (n * n);       k /= 2;     }     return ans;   }   int countSetBits(long long n) {     int ans = 0;     while (n != 0) {       n -= (n & -n);       ++ans;     }     return ans;   }   const int N = 100100;   const int M = 12;   const int INF = 1e6;   const double EPS = 1e-6;   const long double PI = 2 * acos(0);   using namespace std;   const int LOG = 18;   long long mod = 1000000009;   int par[N];   int getPar(int x) { return x == par[x] ? x : par[x] = getPar(par[x]); };   bool same(int x, int y) { return getPar(x) == getPar(y); }   void merge(int x, int y) {     int xx = getPar(x);     int yy = getPar(y);     if (xx != yy) par[xx] = yy;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) par[i] = i;     long long ans = 1;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       x--, y--;       if (same(x, y)) {         ans = (ans * 2ll) % mod;       } else {         merge(x, y);       }       cout << (ans + mod - 1) % mod << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     set<int> co[2];     set<pair<int, int> > delta[2];     int w, h, n;     scanf( %d%d%d , &w, &h, &n);     co[0].insert(0);     co[0].insert(w);     delta[0].insert(make_pair(w, 0));     co[1].insert(0);     co[1].insert(h);     delta[1].insert(make_pair(h, 0));     for (int i = (0), _end_ = (n); i < _end_; ++i) {       static char s[2];       static int first;       scanf( %s%d , s, &first);       int ty = s[0] ==  H ;       co[ty].insert(first);       auto it = co[ty].lower_bound(first);       auto tmp = it;       --tmp;       ++it;       delta[ty].erase(make_pair(*it - *tmp, *tmp));       delta[ty].insert(make_pair(first - *tmp, *tmp));       delta[ty].insert(make_pair(*it - first, first));       printf( %I64d n ,              (long long)delta[0].rbegin()->first * delta[1].rbegin()->first);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void func() {     string s;     cin >> s;     long long n = s.length();     long long i = 1, len = 0, pre[n];     pre[0] = 0;     while (i < n) {       if (s[i] == s[len]) {         len++;         pre[i++] = len;       } else {         if (len == 0) {           pre[i++] = 0;         } else {           len = pre[len - 1];         }       }     }     if (pre[n - 1] == 0) {       cout <<  Just a legend             <<   n ;       return;     }     for (long long i = 0; i < n - 1; ++i) {       if (pre[i] == pre[n - 1]) {         cout << s.substr(0, pre[n - 1]) <<   n ;         return;       }     }     if (pre[pre[n - 1] - 1] == 0) {       cout <<  Just a legend             <<   n ;       return;     }     cout << s.substr(0, pre[pre[n - 1] - 1]) <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       func();     }   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   struct item {     long long t, d, p, idx;   };   item sh[200005];   bool cmp(item x, item y) { return x.d < y.d; }   long long n;   long long dp[105][2005];   long long sol(long long i, long long cur) {     if (i == n) return 0;     if (~dp[i][cur]) return dp[i][cur];     if (sh[i].t + cur >= sh[i].d) return dp[i][cur] = sol(i + 1, cur);     return dp[i][cur] = max(sh[i].p + sol(i + 1, cur + sh[i].t), sol(i + 1, cur));   }   vector<long long> ans;   void print(long long i, long long cur) {     if (i == n) return;     if (sh[i].t + cur >= sh[i].d) {       print(i + 1, cur);     } else if (sh[i].p + sol(i + 1, cur + sh[i].t) > sol(i + 1, cur)) {       ans.push_back(sh[i].idx);       print(i + 1, cur + sh[i].t);     } else       print(i + 1, cur);   }   void solve() {     long long i, j, k, l, r, m, a, b, c, d, x, y, z, t;     cin >> n;     memset(dp, -1, sizeof dp);     for (i = 0; i < n; i++) {       cin >> sh[i].t >> sh[i].d >> sh[i].p;       sh[i].idx = i + 1;     }     sort(sh, sh + n, cmp);     cout << sol(0, 0) << endl;     print(0, 0);     cout << ans.size() << endl;     for (auto &cv : ans) {       cout << cv <<    ;     }     cout << endl;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long INF = 4e18;   const long long MAX = 1e5;   const long long MV = 1e18;   const long double PI = 3.14159265358979323846;   long long MA = -INF, MI = INF;   long long PO(long long x, long long y) {     if (y == 0) return 1;     long long ans = PO(x, y / 2);     ans *= ans, ans %= MOD;     if (y % 2 == 1) ans *= x, ans %= MOD;     return ans % MOD;   }   void RE(long long x) {     x %= MOD;     if (x < 0) x += MOD;   }   long long fib[100], dp1[100], dp2[100], siz = 2;   void cal() {     fib[1] = 1, fib[2] = 2;     while (true) {       long long temp = fib[siz - 1] + fib[siz];       if (temp > MV)         break;       else         fib[++siz] = temp;     }   }   int32_t main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0),         cout << fixed << setprecision(10);     cal();     long long t;     cin >> t;     deque<long long> rep;     while (t--) {       long long n;       cin >> n;       for (long long i = siz; i >= 1; i--) {         if (n >= fib[i]) rep.push_back(i), n -= fib[i];       }       reverse(rep.begin(), rep.end());       rep.push_front(0);       long long len = rep.size();       dp1[0] = 1;       dp2[0] = 0;       for (long long i = 1; i < len; i++) {         dp1[i] = dp1[i - 1] + dp2[i - 1];         dp2[i] = (dp1[i - 1] * ((rep[i] - rep[i - 1] - 1) / 2)) +                  (dp2[i - 1] * ((rep[i] - rep[i - 1]) / 2));       }       cout << dp1[len - 1] + dp2[len - 1] <<   n ;       rep.clear();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   static long long mod = 998244353;   long long pow(long long x, long long y) {     x = x % mod;     int res = 1;     while (y > 0) {       if (y & 1) {         res = (res * x) % mod;       }       y = y >> 1;       x = (x * x) % mod;     }     return res;   }   long long modInverse(long long n, long long mod) { return pow(n, mod - 2); }   long long nCrmodFermat(long long n, long long r) {     if (r == 0) return 1;     long long fact[n + 1];     fact[0] = 1;     for (long long i = 1; i <= n; i++) {       fact[i] = ((fact[i - 1] % mod) * (i % mod)) % mod;     }     return (fact[n] * modInverse(fact[r], mod) % mod *             modInverse(fact[n - r], mod) % mod) %            mod;   }   int main() {     long long n;     cin >> n;     vector<long long> v(2 * n);     long long sum = 0;     for (int i = 0; i < 2 * n; i++) {       cin >> v[i];     }     sort(v.begin(), v.end());     int i = 0;     int j = (2 * n) - 1;     while (i < n && j >= n) {       sum = (sum + abs(v[i] - v[j])) % mod;       i++;       j--;     }     cout << ((sum % mod) * (nCrmodFermat((2 * n), n) % mod)) % mod << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[100010];   vector<pair<long long, long long> > people;   long long Free[100010];   int main() {     long long ts, tf, t;     cin >> ts >> tf >> t;     int n;     scanf( %d , &n);     if (n == 0) {       cout << ts << endl;       return 0;     }     for (int i = 1; i <= n; i++) {       scanf( %I64d , &a[i]);     }     people.push_back(make_pair(0, 0));     long long cnt = 1;     for (int i = 1; i < n; i++) {       if (a[i] != a[i + 1]) {         people.push_back(make_pair(a[i], cnt));         cnt = 1;       } else         cnt++;     }     people.push_back(make_pair(a[n], cnt));     long long ans, wait;     ans = a[1] - 1;     wait = ts - (a[1] - 1);     if (wait < 0) {       wait = 0;       ans = ts;     }     long long time = max(people[1].first, ts);     for (int i = 1; i + 1 < people.size(); i++) {       if (time + t > tf) break;       time = time + people[i].second * t;       if (time + t > tf) break;       long long come_time = people[i + 1].first - 1;       long long new_wait = time - come_time;       if (new_wait < 0) {         new_wait = 0;         come_time = time;       }       if (new_wait < wait) {         wait = new_wait;         ans = come_time;       }       time = max(time, people[i + 1].first);     }     time = time + people.back().second * t;     if (time + t <= tf) {       ans = time;       wait = 0;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long int co = 0, i, n, y, m, j, k, t, x = 0;     cin >> n;     int a[n + 1];     for (i = 1; i <= n; i++) cin >> a[i];     co = 0;     int c = 1;     j = 0;     vector<int> v;     map<int, int> mp;     for (i = 1; i <= n; i++) {       mp[a[i]]++;       co += a[i];       j++;       if (a[i] < 0) {         if (mp[-1 * a[i]] != 1) {           co = -1;           break;         }       }       if (mp[a[i]] > 1) {         c = 0;         break;       }       if (co == 0) {         v.push_back(j);         mp.clear();         j = 0;         co = 0;       }     }     if (!co) {       if (c) {         cout << v.size() <<   n ;         for (int i = 0; i < v.size(); i++) {           cout << v[i] <<    ;         }       } else         cout << -1 <<   n ;     } else       cout << -1 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, tot;   long long ans, sum;   char s[100010], t[100010];   void print(int x, int opt) {     tot++;     printf( %d %d n , x, opt);     if (tot == 100000) exit(0);   }   bool check(int i, int opt) {     if (i == n) return 0;     if (opt == -1) {       if (s[i + 1] >  0 ) return s[i]--, s[i + 1]--, print(i, -1), 1;       if (check(i + 1, 1)) return s[i]--, s[i + 1]--, print(i, -1), 1;       return 0;     }     if (opt == 1) {       if (s[i + 1] <  9 ) return s[i]++, s[i + 1]++, print(i, 1), 1;       if (check(i + 1, -1)) return s[i]++, s[i + 1]++, print(i, 1), 1;       return 0;     }   }   int main() {     scanf( %d%s%s , &n, s + 1, t + 1);     for (int i = 1; i < n; i++) {       int S = sum + s[i] -  a , T = t[i] -  a ;       ans += abs(S - T), sum = T - S;     }     if (sum + s[n] -  a  != t[n] -  a ) return puts( -1 ), 0;     printf( %lld n , ans);     for (int i = 1; i < n; i++) {       while (s[i] > t[i])         if (!check(i, -1)) return puts( -1 ), 0;       while (s[i] < t[i])         if (!check(i, 1)) return puts( -1 ), 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[100005];   int c[100005], N, full;   int LG;   void read() {     scanf( %d n , &N);     for (int line = 1; line <= N; ++line) {       scanf( %s , s + 1);       s[0] =  # ;       int len = strlen(s) - 1;       LG = len;       for (int i = 1; i <= len; ++i) {         if (s[i] ==  ? ) continue;         if (c[i] == 0) {           c[i] = s[i] -  a  + 1;           continue;         }         if (c[i] == s[i] -  a  + 1)           continue;         else {           if (c[i] != -1) {             c[i] = -1;             full++;           }           if (full == len) return;         }       }     }   }   int main() {     read();     for (int i = 1; i <= LG; ++i)       if (c[i] == -1)         printf( ? );       else if (c[i] == 0)         printf( x );       else         printf( %c , c[i] +  a  - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (int)2e9;   const double EPS = 1e-6;   const double PI = 3.1415926535;   const int MOD = 1000003;   int last[100000];   int main() {     int a, b, m, now, i = 2;     cin >> a >> b >> m >> now;     last[now] = 1;     while (1) {       now = (a * now + b) % m;       if (last[now]) {         cout << i - last[now];         return 0;       } else         last[now] = i++;     }   }


#include <bits/stdc++.h>   using namespace std;   struct Expr {     char a[1010], b[1010];     int v;     int op;   };   Expr exps[5010];   char ansMin[1010], ansMax[1010];   char buf[10010];   map<string, int> varIndex;   int calc(int a, int b, int op) {     if (op == 1)       return a & b;     else if (op == 2)       return a | b;     else if (op == 3)       return a ^ b;   }   int work(int bit, int n, int v) {     int ans = 0;     for (int i = 0; i < n; i++) {       if (exps[i].op) {         int a, b;         if (isdigit(exps[i].a[0]))           a = exps[i].a[bit] -  0 ;         else if (exps[i].a[0] ==  ? )           a = v;         else {           string _var;           _var.assign(exps[i].a);           a = varIndex[_var];           a = exps[a].v;         }         if (isdigit(exps[i].b[0]))           b = exps[i].b[bit] -  0 ;         else if (exps[i].b[0] ==  ? )           b = v;         else {           string _var;           _var.assign(exps[i].b);           b = varIndex[_var];           b = exps[b].v;         }         exps[i].v = calc(a, b, exps[i].op);         ans += exps[i].v;       } else {         exps[i].v = exps[i].a[bit] -  0 ;         ans += exps[i].v;       }     }     return ans;   }   int main() {     int n, m;     char op[16], var[16];     scanf( %d%d , &n, &m);     getchar();     for (int i = 0; i < n; i++) {       gets(buf);       if (sscanf(buf,  %s := %s %s %s , var, exps[i].a, op, exps[i].b) == 4) {         if (op[0] ==  A )           exps[i].op = 1;         else if (op[0] ==  O )           exps[i].op = 2;         else if (op[0] ==  X )           exps[i].op = 3;       } else {         sscanf(buf,  %s := %s , var, exps[i].a);         exps[i].op = 0;       }       string _var;       _var.assign(var);       varIndex[var] = i;     }     for (int i = 0; i < m; i++) {       int a = work(i, n, 0);       int b = work(i, n, 1);       if (a > b)         ansMin[i] =  1 , ansMax[i] =  0 ;       else if (a < b)         ansMin[i] =  0 , ansMax[i] =  1 ;       else         ansMin[i] =  0 , ansMax[i] =  0 ;     }     puts(ansMin);     puts(ansMax);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     map<int, vector<int>> mappu;     cin >> n >> m;     for (long long i = (0); i < (m); i++) {       int a, b;       cin >> a >> b;       mappu[a].push_back(b);       mappu[b].push_back(a);     }     for (long long i = (1); i < (n + 1); i++) {       mappu[i].push_back(i);       sort(mappu[i].begin(), mappu[i].end());     }     for (long long i = (1); i < (n + 1); i++) {       for (long long j = (0); j < (mappu[i].size()); j++) {         if (mappu[i] != mappu[mappu[i][j]]) {           cout <<  NO ;           return 0;         }       }     }     cout <<  YES ;   }


#include <bits/stdc++.h>   using namespace std;   int a[105];   struct Fenwick_Tree {     int sz, c[305];     void init(int n) {       sz = n;       for (int i = 1; i <= n; i++) c[i] = 0;     }     int lowbit(int x) { return x & (-x); }     void update(int p, int v) {       for (int i = p; i <= sz; i += lowbit(i)) c[i] = max(c[i], v);     }     int query(int p) {       int res = 0;       for (int i = p; i > 0; i -= lowbit(i)) res = max(res, c[i]);       return res;     }   } BIT;   int b[200005], cnt[305];   int pre[305], suf[305];   int main() {     int n, T;     scanf( %d%d , &n, &T);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     if (T <= 2000) {       for (int i = 0; i < T; i++)         for (int j = 1; j <= n; j++) b[i * n + j] = a[j];       int ans = 0;       BIT.init(300);       for (int i = 1; i <= n * T; i++) {         int len = BIT.query(b[i]) + 1;         BIT.update(b[i], len);         ans = max(ans, len);       }       printf( %d n , ans);     } else {       for (int i = 1; i <= n; i++) cnt[a[i]]++;       for (int i = 0; i < 2000; i++)         for (int j = 1; j <= n; j++) b[i * n + j] = a[j];       BIT.init(300);       for (int i = 1; i <= 1000 * n; i++) {         pre[b[i]] = BIT.query(b[i]) + 1;         BIT.update(b[i], pre[b[i]]);       }       BIT.init(300);       for (int i = 2000 * n; i > 1000 * n; i--) {         suf[b[i]] = BIT.query(301 - b[i]) + 1;         BIT.update(301 - b[i], suf[b[i]]);       }       int ans = 0;       for (int i = 1; i <= 300; i++)         ans = max(ans, pre[i] + suf[i] + cnt[i] * (T - 2000));       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1000011;   const long long INF = (1 << 29) + 123;   const long long MOD = 1000000007;   const long double PI = 4 * atan((long double)1);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, w;     cin >> n >> w;     int l[n];     int x;     long long ans[w], pf[w + 1];     for (int i = 0; i < w + 1; i++) ans[i] = pf[i] = 0;     for (int i = 0; i < n; i++) {       cin >> l[i];       deque<pair<long long, int>> store;       int window = w - l[i] + 1;       int best = -INF;       for (int j = 0; j < w; j++) {         if (j < l[i]) {           cin >> x;           while (!store.empty() && x >= store.back().first) store.pop_back();           store.push_back(make_pair(x, j));           best = max(best, x);         } else if (j == l[i] && j < window) {           j = window;           if (best >= 0) {             pf[l[i]] += best;             pf[window] -= best;           } else {             if (window - 1 < w - window + 1) {               pf[window - 1] += best;               pf[w - window + 1] -= best;             }           }         }         if (j == w) break;         while (store.front().second <= j - window) store.pop_front();         if (store.front().first > 0 || (j >= window - 1 && j <= w - window)) {           ans[j] += 1LL * store.front().first;         }       }     }     long long total = 0;     for (int i = 0; i < w; i++) {       total += pf[i];       cout << ans[i] + total <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse4 )   using namespace std;   constexpr long long mod = 1000000007;   const long long INF = mod * mod;   const double eps = 1e-12;   const double pi = acosl(-1.0);   long long mod_pow(long long x, long long n, long long m = mod) {     long long res = 1;     while (n) {       if (n & 1) res = res * x % m;       x = x * x % m;       n >>= 1;     }     return res;   }   struct modint {     long long n;     modint() : n(0) { ; }     modint(long long m) : n(m) {       if (n >= mod)         n %= mod;       else if (n < 0)         n = (n % mod + mod) % mod;     }     operator int() { return n; }   };   bool operator==(modint a, modint b) { return a.n == b.n; }   modint operator+=(modint& a, modint b) {     a.n += b.n;     if (a.n >= mod) a.n -= mod;     return a;   }   modint operator-=(modint& a, modint b) {     a.n -= b.n;     if (a.n < 0) a.n += mod;     return a;   }   modint operator*=(modint& a, modint b) {     a.n = ((long long)a.n * b.n) % mod;     return a;   }   modint operator+(modint a, modint b) { return a += b; }   modint operator-(modint a, modint b) { return a -= b; }   modint operator*(modint a, modint b) { return a *= b; }   modint operator^(modint a, long long n) {     if (n == 0) return modint(1);     modint res = (a * a) ^ (n / 2);     if (n % 2) res = res * a;     return res;   }   long long inv(long long a, long long p) {     return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);   }   modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }   const int max_n = 1 << 10;   modint fact[max_n], factinv[max_n];   void init_f() {     fact[0] = modint(1);     for (int i = 0; i < max_n - 1; i++) {       fact[i + 1] = fact[i] * modint(i + 1);     }     factinv[max_n - 1] = modint(1) / fact[max_n - 1];     for (int i = max_n - 2; i >= 0; i--) {       factinv[i] = factinv[i + 1] * modint(i + 1);     }   }   modint comb(int a, int b) {     if (a < 0 || b < 0 || a < b) return 0;     return fact[a] * factinv[b] * factinv[a - b];   }   long long gcd(long long a, long long b) {     if (a < b) swap(a, b);     while (b) {       long long r = a % b;       a = b;       b = r;     }     return a;   }   void solve() {     long long a, b;     cin >> a >> b;     modint ans = 0;     for (long long i = 1; i < b; i++) {       long long num = a;       ans += num * i;       modint cr = num * (num + 1) / 2;       cr *= i;       ans += cr * (modint)b;     }     cout << ans <<   n ;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, t, n, m, f[100010], ans, trl;   struct node {     int next, ar, flow, b;   } k[100010 * 20];   int first[100010], dis[100010], len;   int X[100010], y[100010], v[100010], e[100010];   int t1[100010], t2[100010], tl1, tl2, ANS;   void add(int a, int b, int t) {     len++;     k[len].ar = b;     k[len].next = first[a];     first[a] = len;     k[len].flow = t;   }   int head, tail, d[100010];   bool bfs() {     head = 0, tail = 1;     d[0] = a;     for (register int i = 1; i <= n; i++) dis[i] = 0;     dis[a] = 1;     while (head < tail) {       t = d[head];       head++;       for (register int i = first[t]; i; i = k[i].next) {         if (dis[k[i].ar] == 0 && k[i].flow > 0) {           dis[k[i].ar] = dis[t] + 1;           if (k[i].ar == b) return true;           d[tail] = k[i].ar;           tail++;         }       }     }     return false;   }   int dfs(int xx, int flow) {     if (xx == b) return flow;     if (flow == 0) return 0;     if (dis[xx] >= dis[b]) return 0;     int h, s = 0;     for (register int i = first[xx]; i > 1; i = k[i].next) {       if (flow == 0) {         dis[xx] = 0;         break;       }       if (dis[k[i].ar] == dis[xx] + 1 && k[i].flow > 0) {         h = dfs(k[i].ar, min(flow, k[i].flow));         s += h;         flow -= h;         k[i].flow -= h;         k[i ^ 1].flow += h;         if (h == 0) dis[k[i].ar] = 0;       }     }     return s;   }   void dinic() {     for (register int i = 1; i <= n; i++) first[i] = 0;     len = 1, ans = 0;     for (register int i = 1; i <= m; i++)       add(X[i], y[i], f[i]), add(y[i], X[i], f[i]);     while (bfs()) ans += dfs(a, 0x7ffffff);   }   struct gGomory_Hu_Tree {     node tr[100010 * 2], trt[2][100010];     int trl, first[100010];     void adtr(int a, int b, int t) {       trl++;       tr[trl].ar = b;       tr[trl].b = a;       tr[trl].flow = t;       tr[trl].next = first[a];       first[a] = trl;       ANS += t;     }     void dfs(int x, int y, int &w) {       for (int i = first[x]; i; i = tr[i].next) {         if (tr[i].flow >= 0 && tr[i].ar != y) {           if (tr[i].flow < tr[w].flow) w = i;           dfs(tr[i].ar, x, w);         }       }     }     void work(int x) {       int t = 1;       dfs(x, 0, t);       if (t == 1) {         printf( %d  , x);         return;       }       tr[t].flow = tr[t ^ 1].flow = -1;       work(tr[t].ar);       work(tr[t].b);     }   } ght;   void build(int l, int r) {     if (l >= r) return;     a = v[l];     b = v[l + 1];     dinic();     ght.adtr(b, a, ans);     ght.adtr(a, b, ans);     int tl1 = 0, tl2 = 0;     for (register int i = l; i <= r; i++) {       if (dis[v[i]])         tl1++, t1[tl1] = v[i], dis[v[i]] = 0;       else         tl2++, t2[tl2] = v[i];     }     for (register int i = 1; i <= tl1; i++) v[i + l - 1] = t1[i];     for (register int i = 1; i <= tl2; i++) v[l + tl1 + i - 1] = t2[i];     build(l, tl1 + l - 1);     build(l + tl1, r);   }   int main() {     int T;     len = 1;     scanf( %d%d , &n, &m);     for (register int i = 1; i <= m; i++) {       scanf( %d%d%d , &a, &b, &t);       X[i] = a, y[i] = b, f[i] = t;     }     ght.trl = 1;     ght.tr[1].flow = 0x3f3f3f3f;     for (register int i = 1; i <= n; i++) v[i] = i;     build(1, n);     printf( %d n , ANS / 2);     ght.work(1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[10005], cnt[305], dp[10005], inf = 1e8;   int main() {     int n, t;     scanf( %d %d , &n, &t);     int max_num = 0, len = n * min(n / 2, t);     if (len <= 0) len = n;     for (int i = 1; i <= n; ++i) {       scanf( %d , a + i);       max_num = max(max_num, ++cnt[a[i]]);     }     for (int i = n + 1; i <= len; ++i) {       a[i] = a[i - n];     }     int ans = 0;     for (int i = 1; i <= len; ++i) {       dp[i] = 1;       for (int j = i - 1; j >= max(i - n, 1); --j) {         if (a[i] >= a[j]) {           dp[i] = max(dp[i], dp[j] + 1);         }       }       ans = max(ans, dp[i]);     }     if (n / 2 == 0) n++;     if (t <= (n / 2)) {       printf( %d n , ans);     } else {       printf( %d n , ans + max_num * (t - (n / 2)));     }     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 1e5 * 5;   const int INF = 1e9 + 7;   const int N = 5000;   using namespace std;   int n, m, h[N], c[N], cnt;   char a[N][N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) {         cin >> a[i][j];         if (a[i][j] ==  * ) ++h[i], ++c[j], ++cnt;       }     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         if (h[i] + c[j] - (a[i][j] ==  * ) >= cnt) {           cout <<  YES  <<   n ;           cout << i <<     << j;           return 0;         }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N_MAX = 1e9, MAX = 4000001, MOD = 1000000007;   int t, n, k, ans[200001];   vector<int> cnt[200001];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> t;     while (t--) {       cin >> n >> k;       int sum = 0;       fill(ans, ans + n + 1, 0);       for (int i = 0; i < n + 1; i++) cnt[i].clear();       for (int i = 0; i < n; i++) {         int a;         cin >> a;         if (cnt[a].size() < k) cnt[a].push_back(i);       }       int curr = 1, aa = 0;       for (int i = 1; i <= n; i++) {         aa += cnt[i].size();       }       aa -= aa % k;       for (int i = 1; i <= n; i++) {         int s = min(k, (int)cnt[i].size());         for (int j = 0; j < s; j++) {           ans[cnt[i][j]] = curr;           curr = curr % k + 1;           aa--;           if (aa == 0) break;         }         if (aa == 0) break;       }       for (int i = 0; i < n; i++) {         cout << ans[i] <<    ;       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       string aba;       cin >> aba;       int ab = 0;       int ba = 0;       if (aba[0] != aba[aba.size() - 1]) {         aba[0] = aba[aba.size() - 1];         for (int i = 0; i < aba.size() - 1; i++) {           if (aba[i] ==  a  && aba[i + 1] ==  b ) {             ab += 1;           } else if (aba[i] ==  b  && aba[i + 1] ==  a ) {             ba += 1;           }         }         if (ab == ba) {           for (char c : aba) {             cout << c;           }         } else {           aba[aba.size() - 1] = aba[0];           for (char c : aba) {             cout << c;           }         }       } else {         for (char c : aba) {           cout << c;         }       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long double INF = 1e9;   vector<tuple<int, int, int> > v;   map<pair<long long, tuple<int, int, int> >, long double> mp;   vector<int> e[31][4];   long double pb[] = {1.0 / 6, 1.0 / 6, 1.0 / 3, 1.0 / 3};   int get_pos(vector<tuple<int, int, int> > v, tuple<int, int, int> p) {     return int(lower_bound(v.begin(), v.end(), p) - v.begin());   }   tuple<int, int, int> good_tp(int a, int b, int c) {     if (a > c) swap(a, c);     return tuple<int, int, int>(a, b, c);   }   long long to_num(int a[]) {     int b[8];     for (int i = 0; i < 8; i++) b[i] = a[i];     sort(b, b + 8);     long long r = 0;     for (int i = 0; i < 8; i++) {       r *= 22;       r += b[i];     }     return r;   }   long double ask(pair<long long, tuple<int, int, int> > x) {     if (mp.find(x) != mp.end())       return mp[x];     else {       long long p = x.first;       int a = get<0>(x.second);       int b = get<1>(x.second);       int c = get<2>(x.second);       int id = get_pos(v, x.second);       int A = a, B = b, C = c;       if (A && B && C) A = B = C = 0;       int num[8];       for (int i = 7; i >= 0; i--) num[i] = p % 22, p /= 22;       long double unchanged = pb[0];       bool OK = false;       long double sum = 1;       for (int i = 1; i <= 3; i++) {         bool flag = false;         long double mn = INF;         for (int j = 0; j < 8; j++) {           int t = num[j];           for (int x : e[t][i]) {             flag = true;             OK = true;             num[j] = x;             if (A != a) num[0] = id;             long long next_num = to_num(num);             if (A != a) num[0] = 0;             tuple<int, int, int> next_tp;             if (!A) {               next_tp = good_tp(i, B, C);               mn = min(mn, ask(pair<long long, tuple<int, int, int> >(next_num,                                                                       next_tp)));             }             if (!B) {               next_tp = good_tp(A, i, C);               mn = min(mn, ask(pair<long long, tuple<int, int, int> >(next_num,                                                                       next_tp)));             }             if (!C) {               next_tp = good_tp(A, B, i);               mn = min(mn, ask(pair<long long, tuple<int, int, int> >(next_num,                                                                       next_tp)));             }             num[j] = t;           }         }         if (!flag)           unchanged += pb[i];         else {           sum += pb[i] * mn;         }       }       if (!OK)         return mp[x] = 0;       else {         return mp[x] = sum / (1 - unchanged);         puts( oao );       }     }   }   int char_to_int(char c) {     if (c ==  R )       return 1;     else if (c ==  G )       return 2;     else       return 3;   }   int main() {     for (int i = 0; i <= 3; i++) {       v.emplace_back(0, 0, i);       if (i) e[i][i].push_back(0);     }     int m = 4;     for (int i = 1; i <= 3; i++)       for (int j = 1; j <= 3; j++)         for (int k = i; k <= 3; k++) {           v.emplace_back(i, j, k);           e[m][j].push_back(0);           e[m][i].push_back(k);           if (i != k) e[m][k].push_back(i);           m++;         }     int n;     scanf( %d , &n);     string second;     int num[8] = {};     for (int ni = 0; ni < n - 1; ni++) {       cin >> second;       int a = char_to_int(second[0]);       int b = char_to_int(second[1]);       int c = char_to_int(second[2]);       tuple<int, int, int> t = good_tp(a, b, c);       num[ni] = get_pos(v, t);     }     cin >> second;     int a = char_to_int(second[0]);     int b = char_to_int(second[1]);     int c = char_to_int(second[2]);     tuple<int, int, int> next_tp = good_tp(a, b, c);     printf( %.9f n , (double)ask(pair<long long, tuple<int, int, int> >(                          to_num(num), next_tp)));   }


#include <bits/stdc++.h>   using namespace std;   int n, T;   vector<int> intp;   vector<int> t;   vector<double> p;   vector<vector<long double> > dp;   vector<vector<long double> > pows;   long double ans;   void addAns(const vector<long double>& prob, int index) {     for (int j = 1; j <= T; j++) {       if (index == n - 1) {         ans += prob[j] * n;         continue;       }       if (j + t[index + 1] > T) {         ans += prob[j] * (index + 1) * pows[100 - intp[index + 1]][T - j];       }     }   }   int main() {     cin >> n >> T;     intp = vector<int>(n);     p = vector<double>(n);     t = vector<int>(n);     for (int i = 0; i < (int)(n); i++) {       cin >> intp[i] >> t[i];       p[i] = intp[i] / 100.0;     }     pows = vector<vector<long double> >(101, vector<long double>(T + 1));     for (int i = 0; i <= 100; i++) {       pows[i][0] = 1;       for (int j = 1; j <= T; j++) {         pows[i][j] = pows[i][j - 1] * i / 100.0;         if (pows[i][j] < 1e-100) pows[i][j] = 0;       }     }     dp = vector<vector<long double> >(2, vector<long double>(T + 1));     long double curp = 1;     for (int j = 1; j < t[0]; j++) {       dp[0][j] = curp * p[0];       curp *= (1 - p[0]);     }     dp[0][t[0]] = curp;     addAns(dp[0], 0);     for (int i = 1; i < n; i++) {       int ci = i & 1;       int pi = ci ^ 1;       long double sum = 0;       for (int j = 1; j <= T; j++) {         sum = sum * (1 - p[i]) + dp[pi][j - 1];         if (j >= t[i]) {           sum -= dp[pi][j - t[i]] * pows[100 - intp[i]][t[i] - 1];         }         dp[ci][j] = sum * p[i];         if (j >= t[i]) {           dp[ci][j] += dp[pi][j - t[i]] * pows[100 - intp[i]][t[i] - 1];         }       }       addAns(dp[ci], i);     }     cout.precision(16);     cout << fixed << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   ostream &operator<<(ostream &out, string str) {     for (char c : str) out << c;     return out;   }   template <class L, class R>   ostream &operator<<(ostream &out, pair<L, R> p) {     return out <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <class T>   auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {     out <<  { ;     for (auto it = a.begin(); it != a.end(); it = next(it))       out << (it != a.begin() ?  ,   :   ) << *it;     return out <<  } ;   }   void dump() { cerr <<   n ; }   template <class T, class... Ts>   void dump(T a, Ts... x) {     cerr << a <<  ,  ;     dump(x...);   }   template <class T>   int size(T &&a) {     return a.size();   }   using LL = long long;   using PII = pair<int, int>;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     auto ask = [&](int len) {       cout <<  ? 1   << len << endl;       int k = len * (len + 1) / 2;       vector<vector<string>> ret(len + 1);       for (int i = 0; i < k; i++) {         string str;         cin >> str;         ret[size(str)].emplace_back(str);       }       return ret;     };     if (n <= 2) {       auto x = ask(1);       if (n == 1) cout <<  !   << x[1][0];       if (n == 2) {         auto y = ask(2);         cout <<  !   << x[1][0] << (y[1][0] == x[1][0] ? y[1][1] : y[1][0]);       }       cout << endl;       return 0;     }     const int A = 26;     auto count = [&](vector<string> vec) {       vector<int> ret(A);       for (auto &str : vec)         for (char c : str) ret[c -  a ]++;       return ret;     };     auto process = [&](int len, vector<vector<string>> all) {       vector<vector<int>> ret(len + 1);       auto ref = count(all[1]);       auto used = ref;       for (int i = 1; i <= (len - 1) / 2; i++) {         auto a = count(all[i + 1]);         auto b = ref;         for (int &x : b) x *= (i + 1);         for (int j = 1; j <= i - 1; j++) {           for (int &x : ret[j]) a[x] += 1 + i - j;         }         for (int j = 0; j < A; j++)           for (int k = 0; k < b[j] - a[j]; k++) {             ret[i].emplace_back(j);             used[j]--;           }       }       for (int j = 0; j < A; j++)         for (int k = 0; k < used[j]; k++) ret[(len + 1) / 2].emplace_back(j);       return ret;     };     int l = (n + 1) / 2;     auto h1 = ask(l);     auto h2 = ask(l - 1);     auto e1 = process(l, h1);     auto e2 = process(l - 1, h2);     false;     false;     vector<int> ans(n + 1);     auto c1 = count(h1[1]);     auto c2 = count(h2[1]);     for (int j = 0; j < A; j++)       if (c1[j] != c2[j]) ans[l] = j;     false;     auto find = [&](vector<int> a, int b) { return (a[0] == b ? a[1] : a[0]); };     for (int i = 1; i <= l / 2; i++) {       ans[i] = find(e1[i], ans[l + 1 - i]);       if (size(e2[i]) == 2) ans[l - i] = find(e2[i], ans[i]);     }     false;     auto h = ask(n);     auto e = process(n, h);     false;     for (int i = 1; i <= n / 2; i++) {       ans[n + 1 - i] = find(e[i], ans[i]);       false;     }     cout <<  !  ;     for (int i = 1; i <= n; i++) cout << char(ans[i] +  a );     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   char getc() {     char c = getchar();     while ((c <  A  || c >  Z ) && (c <  a  || c >  z ) && (c <  0  || c >  9 ))       c = getchar();     return c;   }   long long gcd(long long n, long long m) { return m == 0 ? n : gcd(m, n % m); }   long long read() {     long long x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 )       x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     return x * f;   }   int n, m;   long long a[300010], b[300010];   signed main() {     n = read(), m = read();     for (int i = 1; i <= n; i++) a[i] = read();     for (int i = 1; i <= m; i++) b[i] = read();     sort(a + 1, a + n + 1);     long long u = 0;     for (int i = 2; i <= n; i++) u = gcd(u, a[i] - a[i - 1]);     for (int i = 1; i <= m; i++)       if (u % b[i] == 0) {         cout <<  YES  << endl;         cout << a[1] <<     << i;         return 0;       }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   int main() {     long long a, b, k = 0;     bool flag = true;     std::stack<long long> st;     std::cin >> a >> b;     st.push(b);     while (b > a && flag) {       if (b % 10 == 1) {         b = b / 10;         st.push(b);         k++;       } else if (b % 2 == 0) {         b = b / 2;         st.push(b);         k++;       } else {         flag = false;       }     }     if (!flag || b != a) {       std::cout <<  NO ;     } else {       std::cout <<  YES  << std::endl << k + 1 << std::endl;       while (!st.empty()) {         std::cout << st.top() <<    ;         st.pop();       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int fin[100005];   int main() {     int n;     while (cin >> n) {       int l, r;       int flag = 1;       int temp;       for (int i = 0; i < n; i++) {         cin >> l >> r;         if (i == 0)           fin[0] = l > r ? l : r;         else {           temp = l > r ? l : r;           if (temp <= fin[i - 1])             fin[i] = temp;           else             fin[i] = l < r ? l : r;           if (fin[i] > fin[i - 1]) flag = 0;         }       }       if (!flag) cout <<  NO  << endl;       if (flag) cout <<  YES  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3005;   int n, m, k, p[N];   bool vis[N];   inline void mk(int v) {     for (int i = v; !vis[i]; i = p[i]) vis[i] = 1;   }   int main() {     while (~scanf( %d , &n)) {       for (int i = 0; i < n; ++i) scanf( %d , &p[i]), --p[i];       scanf( %d , &m);       m = n - m;       for (int i = 0; i < n; ++i)         if (!vis[i]) k++, mk(i);       for (int i = 0; i < n; ++i) vis[i] = false;       printf( %d n , (int)abs(k - m));       if (k > m) {         mk(0);         for (int i = 1; i < n && k > m; ++i) {           if (!vis[i]) {             printf( %d %d  , 1, i + 1);             k--;             mk(i);           }         }       } else if (k < m) {         for (int i = 0; i < n && k < m; ++i) {           vector<int> pos(n, -1);           int cur = 0;           for (int j = p[i]; j != i; j = p[j]) pos[j] = ++cur;           pos[i] = cur;           cur = 0;           for (int j = i + 1; j < n && k < m; ++j)             if (pos[j] > cur) {               printf( %d %d  , i + 1, j + 1);               k++;               cur = pos[j];               swap(p[i], p[j]);             }         }       }       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct crew {     string name;     string pos;   };   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<crew> a(n);     for (int i = 0; i < n; i++) cin >> a[i].name >> a[i].pos;     for (int i = 0; i < n; i++) {       if (a[i].pos ==  rat ) cout << a[i].name <<   n ;     }     for (int i = 0; i < n; i++) {       if (a[i].pos ==  child  || a[i].pos ==  woman ) cout << a[i].name <<   n ;     }     for (int i = 0; i < n; i++) {       if (a[i].pos ==  man ) cout << a[i].name <<   n ;     }     for (int i = 0; i < n; i++) {       if (a[i].pos ==  captain ) cout << a[i].name <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int m, n, t, k;   long long a[10];   long long x[10];   int cnt;   bool ok(int n) {     for (int i = 2; i <= n; i++)       if (a[i] == i) return 0;     for (int i = 2; i <= n; i++) {       int t = a[i];       int cnt = 0;       while (t != 1) {         cnt++;         t = a[t];         if (cnt > n) return 0;       }     }     return 1;   }   void fun(int n, int cur) {     if (cur == n + 1) {       if (ok(n)) cnt++;       return;     }     for (int i = 1; i <= n; ++i) {       a[cur] = i;       fun(n, cur + 1);     }   }   int main() {     for (int i = 1; i <= 8; i++) {       cnt = 0;       fun(i, 2);       x[i] = cnt;     }     scanf( %d%d , &n, &k);     long long s = n - k;     long long ans = (x[k] * k) % 1000000007;     for (int i = 0; i < s; ++i) ans = (ans * s) % 1000000007;     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char s[5000], a[5000];     char b[] =  bear ;     int count = 0, j = 0;     scanf( %s , &s);     int i = 0;     int n = strlen(s);     printf( %s , a);     for (i = 0; i < n; i++) {       for (j = i; j < n; j++) {         if (s[j] ==  b  && s[j + 1] ==  e  && s[j + 2] ==  a  &&             s[j + 3] ==  r ) {           count = count + n - j - 3;           count = count + j - i;           count = count + (n - j - 4) * (j - i);           i = j + 1;         }       }     }     printf( %d , count);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   using ull = unsigned long long int;   bool odd(ll num) { return ((num & 1) == 1); }   bool even(ll num) { return ((num & 1) == 0); }   ll sum(ll n) { return ((n * (n + 1)) / 2); }   ll ceil(ll a, ll b) { return ((a + (b - 1)) / b); }   void InputOutput() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   ll calculation(vector<ll> &v, ll k) {     ll dis, cnt, len, index;     dis = cnt = 0;     len = (ll)v.size();     len -= k;     index = len - 1;     for (ll i = len - 1; i >= 0; i--) {       cnt++;       if (cnt == k) {         dis += (v[index] * 2);         cnt = 0;         index = i - 1;       }     }     if (cnt) dis += (v[index] * 2);     return dis;   }   void solve() {     ll n, k;     cin >> n >> k;     vector<ll> pos, neg;     ll temp, dis;     for (ll i = 0; i < n; i++) {       cin >> temp;       if (temp < 0)         neg.push_back(abs(temp));       else if (temp > 0)         pos.push_back(temp);     }     if (pos.empty() and neg.empty()) {       cout << 0 <<   n ;       return;     }     sort(pos.begin(), pos.end());     sort(neg.begin(), neg.end());     dis = 0;     dis += calculation(pos, k);     dis += calculation(neg, k);     if (pos.empty())       dis += neg.back();     else if (neg.empty())       dis += pos.back();     else {       if (pos.back() < neg.back()) {         dis += (pos.back() * 2);         dis += neg.back();       } else {         dis += (neg.back() * 2);         dis += pos.back();       }     }     cout << dis <<   n ;   }   int main() {     InputOutput();     int t = 1;     cin >> t;     for (int test_case = 1; test_case <= t; test_case++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, m, i, j, b = 0;     scanf( %d %d , &n, &m);     int pass[n];     int finger[m];     int print[m];     for (i = 0; i < n; i++) {       scanf( %d , &pass[i]);     }     for (i = 0; i < m; i++) {       scanf( %d , &finger[i]);     }     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         if (pass[i] == finger[j]) {           print[b] = pass[i];           b++;         }       }     }     for (i = 0; i < b; i++) {       printf( %d  , print[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void in(int &r) {     static char c;     r = 0;     while (c = getchar(), !isdigit(c))       ;     do r = (r << 1) + (r << 3) + (c ^ 48);     while (c = getchar(), isdigit(c));   }   const int mn = 100005;   int head[mn], ne[mn << 1], to[mn << 1], cnt1;   int fa[mn];   int n, m;   namespace part5 {   struct segment_tree {     bool mark[mn << 2];     int maxv[mn << 2], sum[mn << 2];     void up(int o) {       sum[o] = sum[o << 1] + sum[o << 1 | 1];       maxv[o] = max(maxv[o << 1] + sum[o << 1 | 1], maxv[o << 1 | 1]);     }     int L[mn << 2], R[mn << 2];     void build(int o, int l, int r) {       L[o] = l, R[o] = r;       if (l == r) {         sum[o] = -1;         maxv[o] = -1;         return;       }       int mid = l + r >> 1;       build(o << 1, l, mid);       build(o << 1 | 1, mid + 1, r);       up(o);     }     int y_1, y_2;     void down(int o) {       if (mark[o]) {         mark[o << 1] = 1;         sum[o << 1] = -(R[o << 1] - L[o << 1] + 1);         maxv[o << 1] = -1;         mark[o << 1 | 1] = 1;         sum[o << 1 | 1] = -(R[o << 1 | 1] - L[o << 1 | 1] + 1);         maxv[o << 1 | 1] = -1;         mark[o] = 0;       }     }     void mk(int o, int l, int r) {       if (y_1 <= l && r <= y_2) {         maxv[o] = -1, mark[o] = 1, sum[o] = -(r - l + 1);         return;       }       down(o);       int mid = l + r >> 1;       if (y_1 <= mid) mk(o << 1, l, mid);       if (y_2 > mid) mk(o << 1 | 1, mid + 1, r);       up(o);     }     void mk(int l, int r) {       y_1 = l, y_2 = r;       mk(1, 1, n);     }     int ad_v;     void add(int o, int l, int r) {       if (l == r) {         sum[o] += ad_v;         maxv[o] += ad_v;         return;       }       down(o);       int mid = l + r >> 1;       if (y_1 <= mid)         add(o << 1, l, mid);       else         add(o << 1 | 1, mid + 1, r);       up(o);     }     void add(int x, int v) {       y_1 = x, ad_v = v;       add(1, 1, n);     }     int S, Mx;     void ask(int o, int l, int r) {       if (y_1 <= l && r <= y_2) {         Mx = max(Mx, maxv[o] + S);         S += sum[o];         return;       }       down(o);       int mid = l + r >> 1;       if (y_2 > mid) ask(o << 1 | 1, mid + 1, r);       if (y_1 <= mid) ask(o << 1, l, mid);     }     pair<int, int> ask(int l, int r) {       y_1 = l, y_2 = r;       S = 0, Mx = -1;       ask(1, 1, n);       return make_pair(S, Mx);     }   } an;   int sz[mn], son[mn], fa[mn], H[mn], high;   void dfs(int x, int f) {     H[x] = ++high, sz[x] = 1, fa[x] = f;     for (int q(head[x]); q; q = ne[q])       if (to[q] != f) {         dfs(to[q], x);         sz[x] += sz[to[q]];         if (sz[to[q]] > sz[son[x]]) son[x] = to[q];       }     --high;   }   int dfn_l[mn], dfn_r[mn], ind, top[mn];   void redfs(int x, int f, int tp) {     dfn_l[x] = ++ind, top[x] = tp;     if (son[x]) redfs(son[x], x, tp);     for (int q(head[x]); q; q = ne[q])       if (to[q] != f && to[q] != son[x]) redfs(to[q], x, to[q]);     dfn_r[x] = ind;   }   pair<int, int> get(int x) {     int S = 0, Mx = -1;     while (x) {       pair<int, int> now = an.ask(dfn_l[top[x]], dfn_l[x]);       Mx = max(Mx, now.second + S);       S += now.first;       x = fa[top[x]];     }     return make_pair(S, Mx);   }   void solve() {     dfs(1, 0);     redfs(1, 0, 1);     an.build(1, 1, n);     int ty, x;     while (m--) {       in(ty), in(x);       if (ty == 1)         an.add(dfn_l[x], 1);       else if (ty == 2) {         an.mk(dfn_l[x], dfn_r[x]);         pair<int, int> now = get(x);         if (now.second != -1) an.add(dfn_l[x], -(1 + now.second));         now = get(x);       } else {         pair<int, int> now = get(x);         if (now.second != -1)           puts( black );         else           puts( white );       }     }   }   }  // namespace part5   int main() {     in(n), in(m);     int a;     for (int q = 2, q_end_ = n; q <= q_end_; ++q)       in(a), to[++cnt1] = a, ne[cnt1] = head[q], head[q] = cnt1, to[++cnt1] = q,              ne[cnt1] = head[a], head[a] = cnt1;     part5::solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     scanf( %d%d , &n, &k);     int z = k - 1;     while (n % z) z--;     int y = n / z;     printf( %d n , y * k + z);   }


#include <bits/stdc++.h>   using namespace std;   unordered_map<string, vector<string> > m;   set<string> q;   string SS(char C) {     string p =   ;     p += C;     return p;   }   void dfs(string s, long n) {     if (n == 0) {       q.insert(s);       return;     }     for (auto i : m[SS(s[0])]) dfs(i + s.substr(1, s.size() - 1), n - 1);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long n, t;     cin >> n >> t;     string s, p;     for (long i = long(0); i < long(t); i++) {       cin >> s >> p;       m[p].push_back(s);     }     for (auto i : m[ a ]) dfs(i, n - 2);     cout << q.size();   }