#include <bits/stdc++.h>   using namespace std;   int a;   char c[100009];   unsigned int dp[200009] = {1};   int main() {     scanf( %d%s , &a, c);     for (int i = a; i >= 1; i--) {       c[i] = c[i - 1];     }     if (a & 1) {       cout << 0;     } else {       int e = a >> 1;       int q = 0;       for (int i = 1; i <= a; i++) {         if (c[i] ==  ? ) {           for (int j = (i >> 1); j >= i - e && j > 0; j--) {             dp[j] += dp[j - 1];           }         } else {           q++;         }       }       unsigned int ans = dp[e];       for (int i = 1; i <= e - q; i++) {         ans *= 25;       }       cout << ans;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     while (scanf( %d , &n) == 1) {       int ara[n + 4], diftab[n + 4];       ara[0] = 0;       for (int i = 1; i <= n; i++) {         scanf( %d , &ara[i]);         diftab[i - 1] = ara[i] - ara[i - 1];       }       int ansara[n + 1], index = 0;       for (int i = 1; i <= n; i++) {         bool paisi = true;         for (int j = 0; j < n; j++) {           if (diftab[j] != diftab[j % i]) {             paisi = false;             break;           }         }         if (paisi) ansara[index++] = i;       }       printf( %d n , index);       for (int i = 0; index > i; i++) printf( %d  , ansara[i]);       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> uf;   map<int, vector<int> > contents;   map<int, int> val;   void make(int a) {     if (uf.find(a) == uf.end()) {       uf[a] = a;       contents[a].push_back(a);       val[a] = 0;     }   }   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     int q;     cin >> q;     int last = 0;     for (int i = 0; i < q; i++) {       int t;       cin >> t;       if (t == 1) {         int l, r, x;         cin >> l >> r >> x;         l ^= last;         r ^= last;         x ^= last;         if (l > r) swap(l, r);         r++;         make(l);         make(r);         if (uf[l] == uf[r]) continue;         int v = val[l] ^ val[r] ^ x;         l = uf[l];         r = uf[r];         if (contents[l].size() > contents[r].size()) {           swap(l, r);         }         for (int a : contents[l]) {           uf[a] = r;           val[a] ^= v;           contents[r].push_back(a);         }         contents.erase(l);       } else {         int l, r;         cin >> l >> r;         l ^= last;         r ^= last;         if (l > r) swap(l, r);         r++;         make(l);         make(r);         if (uf[l] != uf[r]) {           cout << -1 <<   n ;           last = 1;         } else {           cout << (val[l] ^ val[r]) <<   n ;           last = val[l] ^ val[r];         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g[200005];   int par[19][200005];   int depth[200005];   int dp[200005];   char s[200005];   void dfs(int u, int p, int d, int val) {     par[0][u] = p;     depth[u] = d;     dp[u] = val ^ (1 << (s[u] -  a ));     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i];       if (v == p) continue;       dfs(v, u, d + 1, dp[u]);     }   }   int LCA(int a, int b) {     if (depth[a] < depth[b]) swap(a, b);     int diff = depth[a] - depth[b];     for (int i = 18; i >= 0; i--) {       if ((diff >> i) & 1) a = par[i][a];     }     if (a == b) return a;     for (int i = 18; i >= 0; i--) {       if (par[i][a] != par[i][b]) a = par[i][a], b = par[i][b];     }     return par[0][a];   }   int dist(int a, int b) { return dp[a] ^ dp[b] ^ (1 << (s[LCA(a, b)] -  a )); }   int nn = 0;   int sub[200005];   bool vis[200005];   vector<pair<int, int> > edge[200005];   long long cnt[2000005];   long long ans[200005], add[200005];   void dfs1(int u, int p) {     sub[u] = 1;     nn++;     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i];       if (v == p || vis[v]) continue;       dfs1(v, u);       sub[u] += sub[v];     }   }   int dfs2(int u, int p) {     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i];       if (v == p || vis[v]) continue;       if (sub[v] > nn / 2) return dfs2(v, u);     }     return u;   }   void dfs3(int u, int p, int r, int idx) {     int bits = dist(u, r);     edge[idx].push_back(pair<int, int>(bits, u));     cnt[bits]++;     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i];       if (v == p || vis[v]) continue;       dfs3(v, u, r, idx);     }   }   void dfs4(int u, int p) {     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i];       if (v == p || vis[v]) continue;       dfs4(v, u);       add[u] += add[v];       add[v] = 0;     }     ans[u] += add[u];   }   void decompose(int u, int p) {     nn = 0;     dfs1(u, u);     int centroid = dfs2(u, u);     vis[centroid] = 1;     for (int i = 0; i < g[centroid].size(); i++) {       int v = g[centroid][i];       if (v == p || vis[v]) continue;       edge[i].clear();       dfs3(v, centroid, centroid, i);     }     for (int i = 0; i < g[centroid].size(); i++) {       int v = g[centroid][i];       if (v == p || vis[v]) continue;       for (int j = 0; j < edge[i].size(); j++) cnt[edge[i][j].first]--;       for (int j = 0; j < edge[i].size(); j++) {         int bits = edge[i][j].first;         int cur = edge[i][j].second;         int tot = __builtin_popcount(bits);         if (tot <= 1) add[centroid]++, add[cur]++;         add[cur] += cnt[bits ^ (1 << (s[centroid] -  a ))];         for (int j = 0; j < 20; j++) {           add[cur] += cnt[bits ^ (1 << j) ^ (1 << (s[centroid] -  a ))];         }       }       for (int j = 0; j < edge[i].size(); j++) cnt[edge[i][j].first]++;     }     for (int i = 0; i < g[centroid].size(); i++) {       int v = g[centroid][i];       if (v == p || vis[v]) continue;       for (int j = 0; j < edge[i].size(); j++) cnt[edge[i][j].first] = 0;     }     for (int i = 0; i < g[centroid].size(); i++) {       int v = g[centroid][i];       if (v == p || vis[v]) continue;       dfs4(v, centroid);       add[centroid] += add[v];       add[v] = 0;     }     ans[centroid] += add[centroid] / 2;     add[centroid] = 0;     for (int i = 0; i < g[centroid].size(); i++) {       int v = g[centroid][i];       if (v == p || vis[v]) continue;       decompose(v, centroid);     }   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) {       int a, b;       scanf( %d%d , &a, &b);       g[a].push_back(b);       g[b].push_back(a);     }     scanf( %s , s + 1);     dfs(1, 0, 0, 0);     for (int j = 1; j <= 18; j++) {       for (int i = 1; i <= n; i++) {         if (par[j - 1][i] != 0) par[j][i] = par[j - 1][par[j - 1][i]];       }     }     decompose(1, 0);     for (int i = 1; i <= n; i++) printf( %lld  , ans[i] + 1);   }


#include <bits/stdc++.h>   using namespace std;   bool *Seive(long long n, bool *p) {     memset(p, 1, sizeof(p));     long long i, j;     for (i = 2; i <= n; i++) {       if (p[i] == 1)         for (j = i * i; j <= n; j += i) {           p[j] = 0;         }     }     p[1] = 0;     return p;   }   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   long long modexp(long long x, long long y) {     if (y == 0)       return 1;     else if (y % 2 == 0) {       return modexp((x * x) % (long long)998244353, y / 2);     } else {       return (x * modexp((x * x) % (long long)998244353, (y - 1) / 2)) %              (long long)998244353;     }   }   long long fact(long long n) {     long long f = 1;     for (long long i = 2; i <= n; i++) {       f = (i % (long long)998244353 * f % (long long)998244353) %           (long long)998244353;     }     return f;   }   long long nCr(long long n, long long r) {     return (fact(n) * modexp((fact(n - r) * fact(r)) % (long long)998244353,                              (long long)998244353 - 2)) %            (long long)998244353;   }   void showlist(list<int64_t> g) {     list<int64_t>::iterator it;     for (it = g.begin(); it != g.end(); ++it) cout << *it <<    ;     cout <<   n ;   }   void swap(int64_t &a, int64_t &b) {     int64_t t;     t = a;     a = b;     b = t;   }   void build(int64_t l, int64_t r, int64_t i) {     if (l == r) {     } else {       int64_t mid = (l + r) / 2;       build(l, mid, 2 * i);       build(mid + 1, r, 2 * i + 1);     }   }   void update(int64_t p, int64_t l, int64_t r, int64_t i) {     if (l == r) {     } else {       int64_t mid = (l + r) / 2;       if (p <= mid) {         update(p, l, mid, 2 * i);       } else {         update(p, mid + 1, r, 2 * i + 1);       }     }   }   void query(int64_t y, int64_t z, int64_t l, int64_t r, int64_t i) {     if (y <= l && z >= r) {     } else {       int64_t mid = (l + r) / 2;       if (z <= mid) {         query(y, z, l, mid, 2 * i);       } else if (y > mid) {         query(y, z, mid + 1, r, 2 * i + 1);       } else {         query(y, z, l, mid, 2 * i);         query(y, z, mid + 1, r, 2 * i + 1);       }     }   }   void make_set(int64_t v) {}   int64_t find_set(int64_t v) {}   void union_sets(int64_t a, int64_t b) {}   int64_t dfs(int64_t r, int64_t *d, int64_t &e, int64_t l,               vector<vector<int64_t>> &adj, int64_t *v, int64_t a[][2]) {     a[r][1] = e + d[r];     e = a[r][1];     l = e;     int64_t j = 0;     for (int64_t i = 0; i < adj[r].size(); i++) {       if (v[adj[r][i]] == 0) {         v[adj[r][i]] = 1;         a[adj[r][i]][0] = l - (j + 1);         dfs(adj[r][i], d, e, l, adj, v, a);         j++;       }     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int64_t n, k, i, j, w;     cin >> n >> k;     string s;     set<string> g;     for (i = 0; i < n; i++) {       cin >> s;       g.insert(s);     }     vector<string> v;     for (auto it = g.begin(); it != g.end(); it++) {       v.push_back(*it);     }     int64_t sum = 0;     for (i = 0; i < n - 2; i++) {       string q;       q = v[i];       set<string> t;       for (j = i + 1; j < n; j++) {         t.insert(v[j]);       }       for (j = i + 1; j < n; j++) {         string z;         z = v[j];         string d;         for (w = 0; w < k; w++) {           if (q[w] == z[w]) {             d += q[w];           } else {             char a;             if (q[w] ==  S  && z[w] ==  T  || z[w] ==  S  && q[w] ==  T ) {               a =  E ;             } else if (q[w] ==  E  && z[w] ==  T  || z[w] ==  E  && q[w] ==  T ) {               a =  S ;             } else if (q[w] ==  E  && z[w] ==  S  || z[w] ==  E  && q[w] ==  S ) {               a =  T ;             }             d += a;           }         }         if (t.find(d) != t.end()) {           sum++;           t.erase(d);           t.erase(z);         } else {           t.erase(z);         }       }     }     cout << sum <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       vector<int> counts;       int current_count = 0;       for (char c : s) {         if (c ==  1 ) {           current_count += 1;         } else if (current_count != 0) {           counts.emplace_back(current_count);           current_count = 0;         }       }       if (current_count != 0) {         counts.emplace_back(current_count);       }       sort(counts.begin(), counts.end());       int n = counts.size();       int score = 0;       for (int i = 1 - (n % 2); i < n; i += 2) {         score += counts[i];       }       cout << score <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool chmax(T &a, const T &b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool chmin(T &a, const T &b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   template <class T>   ostream &operator<<(ostream &os, const vector<T> &t) {     os <<  [ ;     for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) {       if (it != t.begin()) os <<  , ;       os << *it;     }     os <<  ] ;     return os;   }   template <class T>   ostream &operator<<(ostream &os, const set<T> &t) {     os <<  { ;     for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) {       if (it != t.begin()) os <<  , ;       os << *it;     }     os <<  } ;     return os;   }   template <class S, class T>   ostream &operator<<(ostream &os, const pair<S, T> &t) {     return os <<  (  << t.first <<  ,  << t.second <<  ) ;   }   const int INF = 1 << 28;   const double EPS = 1e-8;   const int MOD = 1000000007;   long long int t, a, b;   long double x[2][60];   long long int dfs(int co, long long int re1, long long int re2) {     if (co == 1) {       if (t == a || (re1 - re2) % (t - a)) return 0;       long long int i = (re1 - re2) / (t - a);       return !(re1 - i * t < 0 || re2 - i * a < 0 || i < 0);     }     long long int ans = 0;     while (re1 >= 0 && re2 >= 0) {       ans += dfs(co - 1, re1, re2);       re1 -= x[0][co];       re2 -= x[1][co];     }     return ans;   }   int main() {     cin >> t >> a >> b;     if (t == 1 && a == 1 && b == 1) {       puts( inf );       return 0;     }     if (t == a && a == b) {       puts( 2 );       return 0;     }     if (t == a) {       puts( 0 );       return 0;     }     for (long long int i = 0; i < (long long int)(60); i++) {       x[0][i] = powl(t, i);       x[1][i] = powl(a, i);     }     cout << dfs(59, a, b) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int n;   long long a[N], b[N];   int f[N][2];   long long WIN(long long x, long long y) {     assert(x <= y);     if (y & 1) return !(x & 1);     if (x * 2 > y) return x & 1;     if (x * 4 > y) return 1;     return WIN(x, y / 4);   }   long long LOSE(long long x, long long y) {     assert(x <= y);     if (x * 2 > y) return 1;     return WIN(x, y / 2);   }   int main() {     scanf( %d , &n);     for (int i = (int)(1); i <= (int)(n); i++) scanf( %lld%lld , &a[i], &b[i]);     f[n][0] = WIN(a[n], b[n]);     f[n][1] = LOSE(a[n], b[n]);     for (int i = (int)(n - 1); i >= (int)(1); i--) {       if (f[i + 1][0] == 0 && WIN(a[i], b[i])) f[i][0] = 1;       if (f[i + 1][0] == 1 && LOSE(a[i], b[i])) f[i][0] = 1;       if (f[i + 1][1] == 0 && WIN(a[i], b[i])) f[i][1] = 1;       if (f[i + 1][1] == 1 && LOSE(a[i], b[i])) f[i][1] = 1;     }     cout << f[1][0] <<     << f[1][1] << endl;   }


#include <bits/stdc++.h>   int main() {     char str[120];     gets(str);     int len = strlen(str) - 1;     int i;     int count = 0;     int reversed = 0;     for (i = 0; i < len; i++) {       if (str[i] ==  V  && str[i + 1] ==  K ) {         str[i] =  c ;         str[i + 1] =  c ;         ++count;       }     }     for (i = 0; i < len; i++) {       if ((str[i] ==  V  && str[i + 1] ==  V ) ||           (str[i] ==  K  && str[i + 1] ==  K ))         reversed = 1;     }     printf( %d , count + reversed);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxCol = 200010;   const int maxID = 400010;   const int INF = 400010;   typedef struct RangeInfo {     int dist[2][2];     int L;     int R;     RangeInfo() { L = R = -1; }     RangeInfo(int idx, const vector<vector<bool> >& isEmpty) {       L = R = idx;       dist[0][0] = isEmpty[0][idx] ? 0 : INF;       dist[1][1] = isEmpty[1][idx] ? 0 : INF;       dist[0][1] = dist[1][0] = (isEmpty[0][idx] && isEmpty[1][idx]) ? 1 : INF;     }     bool operator==(RangeInfo other) { return L == other.L && R == other.R; }   } RangeInfo;   class SegmentTree {    private:     vector<RangeInfo> segTree;     vector<vector<bool> > isEmpty;     int N;     RangeInfo nullRange;     int getLeft(int idx) { return idx << 1; }     int getRight(int idx) { return (idx << 1) + 1; }     RangeInfo merge(const RangeInfo& left, const RangeInfo& right) {       RangeInfo result;       result.L = left.L;       result.R = right.R;       for (int startRow = 0; startRow < 2; startRow++) {         for (int endRow = 0; endRow < 2; endRow++) {           result.dist[startRow][endRow] = INF;           for (int midRow = 0; midRow < 2; midRow++) {             result.dist[startRow][endRow] =                 min(result.dist[startRow][endRow],                     left.dist[startRow][midRow] + 1 + right.dist[midRow][endRow]);           }         }       }       return result;     }     void build(int idx, int L, int R) {       if (L == R) {         RangeInfo singleRange(L, isEmpty);         segTree[idx] = singleRange;       } else {         build(getLeft(idx), L, (L + R) / 2);         build(getRight(idx), (L + R) / 2 + 1, R);         RangeInfo left = segTree[getLeft(idx)], right = segTree[getRight(idx)];         segTree[idx] = merge(left, right);       }     }     RangeInfo rmq(const int& idx, const int& targetL, const int& targetR) {       int curL = segTree[idx].L;       int curR = segTree[idx].R;       if (targetR < curL || curR < targetL) return nullRange;       if (targetL <= curL && curR <= targetR) return segTree[idx];       RangeInfo left = rmq(getLeft(idx), targetL, targetR);       RangeInfo right = rmq(getRight(idx), targetL, targetR);       if (left == nullRange) return right;       if (right == nullRange) return left;       RangeInfo result = merge(left, right);       return result;     }       public:     SegmentTree(const vector<vector<bool> >& _isEmpty) {       isEmpty = _isEmpty;       N = isEmpty[0].size();       segTree.resize(8 * N);       build(1, 0, N - 1);     }     RangeInfo rmq(const int& targetL, const int& targetR) {       return rmq(1, targetL, targetR);     }   };   typedef struct Coord {     int row, col;     Coord(int& id, const int& N) {       id--;       row = id / N;       col = id % N;     }   } Coord;   int main() {     int N, M;     cin >> N >> M;     vector<vector<bool> > isEmpty(2, vector<bool>(N, false));     char cur;     for (int r = 0; r < 2; r++) {       for (int c = 0; c < N; c++) {         cin >> cur;         isEmpty[r][c] = cur ==  . ;       }     }     SegmentTree segTree(isEmpty);     int sourceId, targetId;     for (int i = 0; i < M; i++) {       cin >> sourceId >> targetId;       Coord left(sourceId, N);       Coord right(targetId, N);       if (left.col > right.col) {         swap(left, right);       }       RangeInfo result = segTree.rmq(left.col, right.col);       int shortestCost = result.dist[left.row][right.row];       cout << (shortestCost == INF ? -1 : shortestCost) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 7;   const int M = 22;   const long long mod = 1e9 + 7;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     long long s = 0;     while (s * 10 + 9 <= n + n - 1) {       s = s * 10 + 9;     }     if (s == n + n - 1) {       cout << 1;     } else {       long long len = 1;       while (len * 1ll * 10 <= 1ll * n + n - 1ll) {         len *= 10;       }       long long i = s;       long long ans = 0;       for (; i <= n + n - 1; i += len) {         if (i <= n + 1) {           ans += (i - 1) / 2;         } else {           long long x = i - n;           x = n - x + 1;           ans += x / 2;         }       }       cout << ans;     }   }


#include<bits/stdc++.h>   #define rep(i,a,b)    for(int i=a;i<b;i++)   #define ret(x) return cout<<x,0;   #define rety return cout<< YES ,0;   #define retn return cout<< NO ,0;   typedef long long ll;   typedef double db;   typedef long double ld;   #define stt string   #define ve vector<ll>   #define se set<ll>   #define ar array   ll mod=1e9+7,mod2=998244353;   using namespace std;   ll fac[10000000];   ll gcd(ll x, ll y)   {      if(y==0)          return x;      return gcd(y,x%y);   }   ll fexp(ll a,ll b,ll m){ll ans = 1;while(b){if(b&1)ans=ans*a%m; b/=2;a=a*a%m;}return ans;}   ll inverse(ll a, ll p){return fexp(a, p-2,p);}   ll ncr(ll n, ll r,ll p)   {      if (r==0) return 1;      return (fac[n]*inverse(fac[n-r],p)%p*inverse(fac[r],p)%p)%p;   }   // ____Z-Algorithm_____   vector<ll> za(string s)   {     ll n = s.size();      vector<ll> z(n);      ll x = 0, y = 0,p=0;             for(ll i= 1; i < n; i++)            {             z[i] = max(p,min(z[i-x],y-i+1));           while(i+z[i] < n && s[z[i]] == s[i+z[i]])                {                 x = i; y = i+z[i]; z[i]++;                }            }   return z;   }   void subset(ll a[],ll k)   {      for (int i = 1; i < pow(2, k); i++)      {          for (int j = 0; j < k; j++)          {              if (i & 1 << j)              {                   cout<<a[j]<<   ;              }          }          cout<<endl;      }   }   vector<ll> pr(string s)   {      ll n = s.length();      vector<ll> pi(n);      for (int i = 1; i < n; i++)      {          int j = pi[i-1];          while (j > 0 && s[i] != s[j])              j = pi[j-1];          if (s[i] == s[j])              j++;          pi[i] = j;      }      return pi;   }   //---------------------------------------------------------------------/   int main()   {     ios::sync_with_stdio(0);     cin.tie(0);     ll t;     cin>>t;     while(t--)     {       int n;   cin >> n;   vector<int> a(n);   for(int i = 0; i < n; i++) {       cin >> a[i];   }   cout << 3*n << endl;    for(int i = 1; i <= n; i+=2)    {       cout << 1 <<     << i <<     << i+1 << endl;       cout << 2 <<     << i <<     << i+1 << endl;       cout << 2 <<     << i <<     << i+1 << endl;       cout << 1 <<     << i <<     << i+1 << endl;       cout << 2 <<     << i <<     << i+1 << endl;       cout << 2 <<     << i <<     << i+1 << endl;    }    }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool umin(T& a, T b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool umax(T& a, T b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   long long F[2][2][1009][1009];   void upd(int x, int y, long long v) {     for (int i = x; i < 1009; i += i & (-i))       for (int j = y; j < 1009; j += j & (-j))         F[x & 1][y & 1][i][j] = F[x & 1][y & 1][i][j] xor v;   }   long long tap(int x, int y) {     long long res = 0;     for (int i = x; i; i -= i & (-i))       for (int j = y; j; j -= j & (-j)) res = res xor F[x & 1][y & 1][i][j];     return res;   }   int main() {     int n, q;     scanf( %d%d , &n, &q);     while (q--) {       int type, x, x1, y1, y;       long long v;       scanf( %d%d%d%d%d , &type, &x, &y, &x1, &y1);       if (type == 2) {         scanf( %lld , &v);         upd(x, y, v);         upd(x1 + 1, y, v);         upd(x, y1 + 1, v);         upd(x1 + 1, y1 + 1, v);       } else         printf( %lld n , tap(x1, y1) xor tap(x1, y - 1) xor tap(x - 1, y1) xor                              tap(x - 1, y - 1));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   int pref[N];   vector<int> v;   int fsoma(int l, int r) {     l--;     int ans = pref[r];     if (l >= 0) ans -= pref[l];     return ans;   }   long long n, k, l;   void rbest(pair<int, int> &a, pair<int, int> b) {     if (b.first > a.first or (a.first == b.first and b.second < a.second)) a = b;   }   pair<int, int> comb(pair<int, int> a, pair<int, int> b) {     return {a.first + b.first, a.second + b.second};   }   vector<pair<int, int>> dp(n);   pair<int, int> rec(int i) {     if (i >= 0) return dp[i];     return {0, 0};   }   pair<int, int> f(int c) {     dp = vector<pair<int, int>>(n);     for (int i = 0; i < n; i++) {       rbest(dp[i], rec(i - 1));       rbest(dp[i], comb(rec(i - l), {fsoma(i - (l - 1), i) - c, 1}));     }     return dp[n - 1];   }   long long solve(vector<int> &_v) {     v = _v;     for (int i = 0; i < (int)(v.size()); i++) {       pref[i] = v[i];       if (i) pref[i] += pref[i - 1];     }     int lo = 0, hi = l + 1;     while (lo < hi) {       int mid = (lo + hi) / 2;       if (f(mid).second <= k)         hi = mid;       else         lo = mid + 1;     }     auto par = f(lo);     return pref[(int)(v.size()) - 1] - (par.first + lo * k);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k >> l;     string s;     cin >> s;     vector<int> v1((int)(s.size())), v2((int)(s.size()));     for (int i = 0; i < (int)(s.size()); i++) {       if (s[i] >=  A  and s[i] <=  Z ) {         v1[i] = 1;       } else {         v2[i] = 1;       }     }     cout << min(solve(v1), solve(v2)) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   void fast() {     std::ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     cerr.tie(NULL);   }   int main() {     fast();     unsigned long long over = pow(2, 32);     string s;     int i;     unsigned long long num = 0;     stack<unsigned long long> loop;     loop.push(1);     int n;     cin >> n;     while (n--) {       cin >> s;       if (s ==  add ) {         num += loop.top();         if (num >= over) {           cout <<  OVERFLOW!!! ;           return 0;         }       } else if (s ==  for ) {         cin >> i;         loop.push(min(over, loop.top() * i));       } else {         loop.pop();       }     }     cout << num;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m;   char A[1020304], B[1020304];   int data[1020304][27], vis[1020304];   int main() {     cin >> n >> m;     scanf( %s%s , A + 1, B + 1);     int la = strlen(A + 1), lb = strlen(B + 1);     memset(vis, 0, sizeof(vis));     int len = 0;     int Tot = 0;     for (int i = 1; i <= lb; ++i)       if (!vis[i]) {         ++Tot;         vis[i] = Tot;         memset(data[Tot], 0, sizeof(data[Tot]));         ++data[Tot][B[i] -  a ];         len = 1;         for (int z = (i - 1 + la) % lb + 1; !vis[z]; z = (z - 1 + la) % lb + 1) {           vis[z] = Tot;           ++data[Tot][B[z] -  a ];           ++len;         }       }     long long ans = 0;     for (int i = 1; i <= la; ++i) {       for (int j = 0; j <= 25; ++j)         if ( a  + j != A[i]) {           long long pos = (i - 1 + lb) % lb + 1;           ans += (long long)data[vis[pos]][j] * n / len;         }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, k;   long long calc(long long nk, long long mk) {     return (n / (nk + 1)) * (m / (mk + 1));   }   int main() {     cin >> n >> m >> k;     if (k > n + m - 2) {       cout << -1;       return 0;     }     long long nk = min(k, n - 1);     long long mk = min(k, m - 1);     long long a = calc(nk, k - nk);     long long b = calc(k - mk, mk);     cout << max(a, b);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char* argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     int minr = 1e9 + 2;     int maxl = 0;     for (int i = 0; i < n; i++) {       int l, r;       cin >> l >> r;       if (l > maxl) {         maxl = l;       }       if (r < minr) {         minr = r;       }     }     int m;     cin >> m;     int minr2 = 1e9 + 2;     int maxl2 = 0;     for (int i = 0; i < m; i++) {       int l, r;       cin >> l >> r;       if (l > maxl2) {         maxl2 = l;       }       if (r < minr2) {         minr2 = r;       }     }     int diff1 = maxl - minr2;     int diff2 = maxl2 - minr;     int sol = max(max(diff1, diff2), 0);     cout << sol <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> report(n);     int posCount = 0;     int negCount = 0;     for (int i = 0; i < n; i++) {       cin >> report[i];       if (report[i] >= 0) {         posCount++;       } else {         negCount++;       }     }     if (posCount == n) {       cout << 1 << endl;       cout << n << endl;       return 0;     }     if (negCount <= 2) {       cout << 1 << endl;       cout << n << endl;       return 0;     }     int neg = 0;     int folders = 0;     int partitions = 0;     vector<int> item;     for (int i = 0; i < report.size(); i++) {       folders++;       if (report[i] < 0) {         neg++;         if (neg == 3) {           item.push_back(--folders);           i--;           partitions++;           folders = 0;           neg = 0;         }       }     }     if (folders != 0) {       item.push_back(folders);     }     cout << ++partitions << endl;     for (auto x : item) {       cout << x <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   int b[105];   int vis[105];   int main() {     int n;     scanf( %d , &n);     int a[105];     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       b[a[i]]++;     }     int ans1 = 0;     int ans2 = 0;     int jo = 1;     int mm = 0;     for (int i = 0; i < n; i++) {       int x = a[i];       if (b[x] > 0) {         if (b[x] <= 2) {           if (jo == 1) {             vis[i] = 1;             jo = -1;             ans1++;             if (b[x] == 2) {               for (int j = i + 1; j <= n; j++) {                 if (a[i] == x) {                   vis[i] = -1;                   jo = 1;                   ans2++;                   break;                 }               }             }           } else {             vis[i] = -1;             jo = 1;             ans2++;             if (b[x] == 2) {               for (int j = i + 1; j <= n; j++) {                 if (a[i] == x) {                   vis[i] = 1;                   jo = -1;                   ans1++;                   break;                 }               }             }           }           b[x] = 0;         } else {           mm++;         }       }     }     if (ans1 == ans2) {       cout <<  YES  << endl;       for (int i = 0; i < n; i++) {         if (vis[i] == 1) {           cout <<  B ;         } else {           cout <<  A ;         }       }     } else {       if (mm == 0) {         cout <<  NO  << endl;       } else {         if (ans1 > ans2) {           for (int i = 0; i < n; i++) {             if (b[a[i]] > 2) {               vis[i] = -1;               break;             }           }           cout <<  YES  << endl;           for (int i = 0; i < n; i++) {             if (vis[i] == 1 || vis[i] == 0) {               cout <<  B ;             } else {               cout <<  A ;             }           }         } else {           for (int i = 0; i < n; i++) {             if (b[a[i]] > 2) {               vis[i] = 1;               break;             }           }           cout <<  YES  << endl;           for (int i = 0; i < n; i++) {             if (vis[i] == 1) {               cout <<  B ;             } else {               cout <<  A ;             }           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s1;     string s2;     while (cin >> s1 >> s2) {       int n = s1.length(), m = s2.length();       int dp[n + 1][m + 1];       for (int i = 0; i < n + 1; i++) dp[i][0] = i;       for (int i = 0; i < m + 1; i++) dp[0][i] = i;       for (int i = 1; i < n + 1; i++) {         for (int j = 1; j < m + 1; j++) {           if (s1[i - 1] == s2[j - 1])             dp[i][j] = dp[i - 1][j - 1];           else             dp[i][j] = min(min(dp[i - 1][j], dp[i][j - 1]), dp[i - 1][j - 1]) + 1;         }       }       cout << dp[n][m] << endl;       int i = n, j = m;       while (i >= 0 && j >= 0) {         if (dp[i][j - 1] == dp[i][j] - 1) {           cout <<  INSERT   + to_string(i + 1) +     + s2[j - 1] << endl;           j--;         } else if (dp[i - 1][j] == dp[i][j] - 1) {           cout <<  DELETE   + to_string(i) << endl;           i--;         } else if (dp[i - 1][j - 1] == dp[i][j] - 1 && s1[i - 1] != s2[j - 1]) {           cout <<  REPLACE   + to_string(i) +     + s2[j - 1] << endl;           i--, j--;         } else           i--, j--;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Trie {     struct Node {       char c;       vector<pair<int, int> > n;       Node* ch[26];       Node(char ch) {         this->c = ch;         for (int i = 0; i < 26; i++) this->ch[i] = NULL;       }     };     Node* root;     vector<pair<int, int> > res;     int sum;     Trie() {       root = new Node(   );       sum = 0;     }     void create(string s, int t, int ind) {       Node* now = root;       for (int i = 0; i < s.size(); i++) {         if (now->ch[s[i] -  a ] == NULL)           now = now->ch[s[i] -  a ] = new Node(s[i]);         else           now = now->ch[s[i] -  a ];       }       (now->n).push_back(make_pair(ind, t));     }     pair<vector<int>, vector<int> > dfs(Node* now, int depth) {       vector<int> O, P;       for (int i = 0; i < 26; i++)         if (now->ch[i] != NULL) {           pair<vector<int>, vector<int> > t = dfs(now->ch[i], depth + 1);           O.insert(O.end(), t.first.begin(), t.first.end());           P.insert(P.end(), t.second.begin(), t.second.end());         }       vector<pair<int, int> > t = now->n;       for (int i = 0; i < t.size(); i++)         if (t[i].second == 1)           O.push_back(t[i].first);         else if (t[i].second == 2)           P.push_back(t[i].first);       while (O.size() && P.size()) {         sum += depth;         res.push_back(make_pair(O[0], P[0]));         O.erase(O.begin());         P.erase(P.begin());       }       return make_pair(O, P);     }     void doit() {       dfs(root, 0);       printf( %d n , sum);       for (int i = 0; i < res.size(); i++)         printf( %d %d n , res[i].first, res[i].second);     }   };   int main() {     Trie trie;     string s;     int n;     scanf( %d n , &n);     for (int i = 1; i <= 2; i++)       for (int j = 1; j <= n; j++) {         cin >> s;         trie.create(s, i, j);       }     trie.doit();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1E5 + 5;   int t[N], n, a[N], f[N], b[N], k, x, mid;   vector<int> G[N];   long long ans;   bool O = 0;   int work() {     memset(f, 0, sizeof(f));     for (int i = k; i <= n - k + 1; i++) f[b[i]]++;     int o = 0;     for (int i = 1; i <= n; i++)       if (f[i] & 1) {         if (o) return n - k + 1;         o = i;       }     if (((n & 1) ^ (o > 0))) return n - k + 1;     memset(f, 0, sizeof(f));     for (int i = 1; i <= n; i++) G[i].clear();     for (int i = k; i <= n - k + 1; i++) {       x = b[i];       t[x]++;       G[x].push_back(i);     }     int mini = k;     if (o && o != b[mid]) mini = mid;     O = 1;     for (int i = n - k + 1; i >= mini; i--)       if (i > mid) {         f[x = b[i]]++;         if (f[x] > t[x] || G[x][f[x] - 1] >= i) return i - 1;         if (b[i] != b[n - i + 1]) mini = max(mini, G[x][f[x] - 1]);       } else if (b[i] != b[n - i + 1])         return i - 1;     return mini - 1;   }   int main() {     cin >> n;     mid = n / 2 + (n & 1);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (k = 1; k <= mid && a[k] == a[n - k + 1]; k++)       ;     if (k > mid) {       cout << (long long)n * (n + 1) / 2;       return 0;     }     for (int i = k; i <= n - k + 1; i++) b[i] = a[i];     ans = n - k + 1 - work();     for (int i = k; i <= n - k + 1; i++) b[n - i + 1] = a[i];     ans += n - k + 1 - work();     ans = ans * k;     if (ans) ans += (long long)(k - 1) * (k - 1);     if (O) ans--;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 0x3f3f3f3f;   const int N = 2e5 + 10;   const long long mod = 1e9 + 7;   const bool debug = false;   int F[N], Finv[N], inv[N];   void init() {     inv[1] = 1, F[0] = Finv[0] = 1;     for (int i = 2; i < N; i++)       inv[i] = (mod - mod / i) * 1ll * inv[mod % i] % mod;     for (int i = 1; i < N; i++) {       F[i] = F[i - 1] * 1ll * i % mod;       Finv[i] = Finv[i - 1] * 1ll * inv[i] % mod;     }   }   int comb(int n, int m) {     if (m < 0 || m > n) return 0;     return F[n] * 1ll * Finv[n - m] % mod * Finv[m] % mod;   }   int main() {     init();     int n;     long long T;     scanf( %d%lld , &n, &T);     long long pre = 1, r = 0, ans = 0, gg = 1;     for (int i = 1, x; i <= n; ++i) {       scanf( %d , &x);       T -= x;       if (T < 0) break;       pre = (pre * 2 - comb(i - 1, r) + mod) % mod;       while (r < min(i * 1ll, T)) {         pre += comb(i, ++r);       }       while (r > min(i * 1ll, T)) {         pre -= comb(i, r--);       }       pre %= mod;       if (pre < 0) pre += mod;       gg = gg * (mod + 1) / 2 % mod;       ans = (ans + pre * gg) % mod;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long a[1010];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     long long k;     cin >> k;     cin >> k;     cin >> k;     long long x = (long long)a[2] * a[1] / k;     long double dx = x;     long long ans = (long long)(sqrt(x) + 0.005);     cout << ans <<    ;     for (int i = 1; i < n; i++) {       cout << a[i] / ans <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long _pow(long long a, long long b) {     long long x = 1;     for (long long j = 0; j < b; j++) {       x *= a;     }     return x;   }   bool test(int a, int n, int m) {     if (a <= 0)       return true;     else if (m == 0 && n == 0)       return false;     else {       if (n > 0 && (a > (a / 2) + 10)) return test(a / 2 + 10, n - 1, m);       if (m > 0) return test(a - 10, n, m - 1);       if (n > 0) return false;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     for (int h = 0; h < t; h++) {       int a, n, m;       cin >> a >> n >> m;       cout << (test(a, n, m) ?  YES  :  NO ) <<   n ;     }   }


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


#include <bits/stdc++.h>   using namespace std;   const long long md = 1e9 + 7;   const long long arr = 2e5;   long long a[arr], aa[arr];   long long n, d, b;   bool check(long long u) {     for (long long i = 1; i <= n; i++) a[i] = aa[i];     long long pluss = 0;     long long uu = u;     long long start = 1;     long long mid = n / 2 + n % 2;     while (1) {       if (a[start] >= b)         pluss += a[start] - b;       else if (uu)         uu--, pluss += a[start];       else         break;       start++;       if (start > mid) break;     }     long long last = start;     pluss += a[start];     for (long long i = start; i <= mid; i++) {       while (last + 1 <= min(i + i * d, n)) {         last++;         pluss += a[last];         a[last] = 0;       }       if (pluss < b) return (0);       pluss -= b;     }     for (long long i = 1; i <= n; i++) a[i] = aa[i];     reverse(a + 1, a + 1 + n);     pluss = 0;     uu = u;     start = 1;     mid = n / 2;     while (1) {       if (a[start] >= b)         pluss += a[start] - b;       else if (uu)         uu--, pluss += a[start];       else         break;       start++;       if (start > mid) break;     }     last = start;     pluss += a[start];     for (long long i = start; i <= mid; i++) {       while (last + 1 <= min(i + i * d, n)) {         last++;         pluss += a[last];         a[last] = 0;       }       if (pluss < b) return (0);       pluss -= b;     }     return (1);   }   signed main() {     cin >> n >> d >> b;     for (long long i = 1; i <= n; i++) cin >> aa[i];     long long l = 0;     long long r = n;     while (r - l > 1) {       long long d = (l + r) / 2;       if (check(d))         r = d;       else         l = d;     }     if (check(l))       cout << l;     else       cout << r;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     cin >> n >> m;     int finalPos[4 * n];     memset(finalPos, -1, sizeof(finalPos));     for (int i = (2 * n) + 1, j = 0; i <= m; i++, j += 2) {       finalPos[j] = i;     }     for (int i = 1, j = 1; i <= (2 * n) && i <= m; i++, j += 2) finalPos[j] = i;     for (int i = 0; i < (4 * n); i++) {       if (finalPos[i] != -1) cout << finalPos[i] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double pi = 3.1415926535897932384626433832795l;   template <typename T>   inline auto sqr(T x) -> decltype(x * x) {     return x * x;   }   template <typename T>   inline T abs(T x) {     return x > T() ? x : -x;   }   template <typename T1, typename T2>   inline bool umx(T1& a, T2 b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <typename T1, typename T2>   inline bool umn(T1& a, T2 b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   const int N = 100100;   struct Input {     int n;     vector<pair<int, int> > a[N];     int len[N];     int num[N], w[N];     int q;     bool read() {       if (scanf( %d , &n) != 1) return 0;       for (int i = 0; i < int(n - 1); ++i) {         int u, v;         scanf( %d %d %d , &u, &v, &len[i]);         u--, v--;         a[u].push_back(make_pair(v, i));         a[v].push_back(make_pair(u, i));       }       cin >> q;       for (int i = 0; i < int(q); ++i) {         scanf( %d %d , &num[i], &w[i]);         num[i]--;       }       return 1;     }     void init(const Input& input) { *this = input; }   };   struct Data : Input {     long double ans[N];     void write() {       for (int i = 0; i < int(q); ++i) {         printf( %0.15lf n , (double)ans[i]);       }     }     virtual void solve() {}     virtual void clear() { *this = Data(); }   };   struct Solution : Data {     int sz[N];     int kol[N];     bool use[N];     int dfs(int v, int idx = -1) {       use[v] = 1;       sz[v] = 1;       for (int i = 0; i < int(a[v].size()); ++i) {         int to = a[v][i].first;         if (use[to]) continue;         sz[v] += dfs(to, a[v][i].second);       }       if (idx >= 0) kol[idx] = sz[v];       return sz[v];     }     inline long double c(int a, int b) {       if (a < b) return 0;       if (b == 0) return 1;       if (b == 1) return a;       if (b == 2) {         return (long double)a * (a - 1) / 2.0;       }       return (long double)a * (a - 1) * (a - 2) / 6.0;     }     inline long double get(int i) {       return 2.0 * (long double)kol[i] * c((n - kol[i]), 2) +              2.0 * (long double)(n - kol[i]) * c(kol[i], 2);     }     void solve() {       dfs(0);       long double res = 0;       for (int i = 0; i < int(n - 1); ++i) {         res += get(i) * len[i];       }       for (int i = 0; i < int(q); ++i) {         res -= get(num[i]) * len[num[i]];         len[num[i]] = w[i];         res += get(num[i]) * len[num[i]];         ans[i] = res / c(n, 3);       }     }     void clear() { *this = Solution(); }   };   Solution sol;   int main() {     cout.setf(ios::showpoint | ios::fixed);     cout.precision(20);     sol.read();     sol.solve();     sol.write();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T re() {     T N = 0;     char c = getchar();     bool neg = 0;     for (; c <  0  || c >  9 ; c = getchar()) neg |= c ==  - ;     for (; c >=  0  && c <=  9 ; c = getchar()) N = (N << 3) + (N << 1) + c -  0 ;     return neg ? -N : N;   }   const int MX = 200;   const int MXPOW5 = 8000;   int n, k;   long long a[MX + 5];   int two[MX + 5], five[MX + 5];   int dp[2][MX + 5][MXPOW5 + 5];   int main() {     n = re<int>();     k = re<int>();     for (int i = 1; i <= n; i++) a[i] = re<long long>();     for (int i = 1; i <= n; i++) {       for (long long t = a[i]; t % 2 == 0; t /= 2) two[i]++;       for (long long t = a[i]; t % 5 == 0; t /= 5) five[i]++;     }     int prv = 0, now = 1;     for (int i = 0; i <= k; i++)       for (int j = 0; j <= MXPOW5; j++) dp[prv][i][j] = -0x3f3f3f3f;     dp[prv][0][0] = 0;     for (int i = 1; i <= n; i++) {       for (int j = 0; j <= k; j++)         for (int l = 0; l <= MXPOW5; l++) dp[now][j][l] = dp[prv][j][l];       for (int j = 0; j < k; j++)         for (int l = 0; l + five[i] <= MXPOW5; l++)           dp[now][j + 1][l + five[i]] =               max(dp[now][j + 1][l + five[i]], dp[prv][j][l] + two[i]);       swap(now, prv);     }     int ans = 0;     for (int i = 0; i <= MXPOW5; i++) ans = max(ans, min(i, dp[prv][k][i]));     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int a = 97, z = 97 + 25, t = n;     string s =   ;     for (int i = 0; i < n; i++) {       if (t >= k) {         for (int j = 0; j < k; j++) {           s += a + j;         }         i += k;         i--;         t -= k;       } else {         s += a;         a++;       }     }     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N;     cin >> N;     int grandN;     vector<int> result;     for (int i = 0; i < N; i++) {       vector<int> grandmas;       int temp;       int res = 1;       cin >> grandN;       for (int j = 0; j < grandN; j++) {         cin >> temp;         grandmas.push_back(temp);       }       sort(grandmas.begin(), grandmas.end());       for (int j = 0; j < grandN; j++) {         if (grandmas.at(j) <= j + 1) {           res = j + 2;         }       }       result.push_back(res);     }     for (auto i : result) {       cout << i << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000010;   int n, m, cnt, head[maxn], vis[maxn], mark[maxn], ans[maxn], tot;   struct edge {     int to, next;   } e[maxn];   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   void add(int from, int to) {     e[++cnt] = (edge){to, head[from]};     head[from] = cnt;   }   void dfs(int now, int father, int edge) {     vis[now] = 1;     vector<int> bian;     for (int i = head[now]; i; i = e[i].next) {       int to = e[i].to;       if (!vis[to]) dfs(to, now, i);     }     for (int i = head[now]; i; i = e[i].next) {       int to = e[i].to;       if (to != father && !mark[i]) {         bian.push_back(i);         mark[i] = 1;         if (i & 1)           mark[i + 1] = 1;         else           mark[i - 1] = 1;       }     }     int size = bian.size();     for (int i = 0; i < size; i++) {       if (i & 1) ans[++tot] = now;       ans[++tot] = e[bian[i]].to;     }     if (size & 1) {       if (father)         ans[++tot] = now, ans[++tot] = father, mark[edge] = 1;       else         tot--;     }   }   int main() {     n = read(), m = read();     for (int i = 1; i <= m; i++) {       int u = read(), v = read();       add(u, v), add(v, u);     }     for (int i = 1; i <= n; i++)       if (!vis[i]) dfs(i, 0, 0);     printf( %d n , tot / 3);     for (int i = 1; i <= tot; i++) {       printf( %d  , ans[i]);       if (i % 3 == 0) puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<string, string> vars;   struct proc {     string name, arg[10];     int argn;     proc(string v, bool V) {       string til =   ;       int k = 0;       for (int i = 0; i < v.length(); i++) {         if (v[i] ==  ( ) {           name = til;           til =   ;           continue;         } else if (v[i] ==  ,  || v[i] ==  ) ) {           if (V)             arg[k++] = vars[til];           else             arg[k++] = til;           til =   ;           continue;         } else           til += v[i];       }       argn = k;     }     bool operator==(proc k) {       if (name == k.name) {         if (argn == k.argn) {           for (int i = 0; i < argn; i++) {             if (arg[i] ==  T  || arg[i] == k.arg[i]) continue;             return false;           }           return true;         }       }       return false;     }   };   vector<proc> p;   string DeleteSpaces(string k) {     string ans =   ;     for (int i = 0; i < k.length(); i++)       if (k[i] !=    ) ans += k[i];     return ans;   }   int main() {     int n, m, k;     cin >> n;     for (int i = 0; i < n; i++) {       string v;       cin >> v;       getline(cin, v);       proc Pro(DeleteSpaces(v), false);       p.push_back(Pro);     }     cin >> k;     for (int i = 0; i < k; i++) {       string type, name;       cin >> type >> name;       vars[name] = type;     }     cin >> m;     cin.ignore();     for (int i = 0; i < m; i++) {       string v;       getline(cin, v);       proc Pro(DeleteSpaces(v), true);       int ans = 0;       for (int j = 0; j < p.size(); j++) {         if (p[j] == Pro) ans++;       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[105];   double t[105];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int cnt;     for (int d = -1000; d <= 1000; d++) {       if (d != 0) {         for (int i = 0; i < n; i++) {           t[i] = a[i] * 1.0 / d;         }         cnt = 0;         for (int i = 0; i < n; i++) {           if (t[i] > 0) {             cnt++;           }         }         if (cnt >= (n + 1) / 2) {           cout << d << endl;           return 0;         }       }     }     cout << 0 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   bool is_prime(long long n) {     if (n == 1 || n == 0) return false;     if (n == 2 || n == 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 1; (6 * i + 1) <= n; i++) {       if (6 * i + 1 == n) return true;       if (6 * i - 1 == n) return true;     }     return false;   }   unordered_set<long long> prime_till_n(long long n) {     vector<long long> arr(n + 1);     arr[0] = 0;     arr[1] = 0;     for (long long i = 2; i <= n; i++) arr[i] = (long long)1;     for (long long i = 2; i <= (n - 1) / 2; i++) {       if (arr[i] == 1) {         long long j = i;         while (i + j <= n) {           if (arr[i + j] == 1) {             arr[i + j] = 0;           }           j += i;         }       }     }     unordered_set<long long> ans;     for (long long i = 0; i <= n; i++) {       if (arr[i] == 1) ans.insert(i);     }     return ans;   }   bool is_palindrome(string s) {     string r = s;     reverse(r.begin(), r.end());     if (s.compare(r) == 0) return true;     return false;   }   bool issubstr(string s1, string s2) {     int M = s1.length();     int N = s2.length();     for (int i = 0; i <= N - M; i++) {       int j;       for (j = 0; j < M; j++)         if (s2[i + j] != s1[j]) break;       if (j == M) return true;     }     return false;   }   long long xortilln(long long n) {     if (n % 4 == 0ll) return n;     if (n % 4 == 1ll) return 1ll;     if (n % 4 == 2ll) return n + 1ll;     return 0ll;   }   void solve() {     string s;     long long n;     cin >> n;     vector<long long> v(n);     for (long long i = 0; i < n; i++) cin >> v[i];     cin >> s;     vector<long long> up, down;     for (long long i = 0; i < n; i++) {       if (s[i] ==  1 )         up.push_back(v[i]);       else         down.push_back(v[i]);     }     sort(up.begin(), up.end());     sort(down.begin(), down.end());     unordered_map<long long, long long> up2, down2;     for (int i = 0; i < down.size(); i++) down2[down[i]] = i + 1;     for (int i = 0; i < up.size(); i++) up2[up[i]] = down.size() + i + 1;     for (int i = 0; i < n; i++) {       if (s[i] ==  1 )         cout << up2[v[i]] <<    ;       else         cout << down2[v[i]] <<    ;     }     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     long long i = 1, t = 1;     cin >> t;     while (t--) {       solve();       i++;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int h1, m1, h2, m2, result1, result2;     char c =  : ;     while (cin >> h1 >> c >> m1 >> h2 >> c >> m2) {       if (m1 < m2) {         h1 -= 1;         m1 += 60;       }       result2 = m1 - m2;       result1 = h1 - h2;       if (result1 < 0) result1 += 24;       if (result1 == 24) result1 = 0;       cout << setw(2) << setfill( 0 ) << abs(result1) << c << setw(2)            << setfill( 0 ) << abs(result2) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     n = n / 2520;     cout << n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000 + 5;   map<string, int> mat;   int fonction(string a, string b, string c) {     int x = (mat[b] - mat[a] + 12) % 12;     int y = (mat[c] - mat[b] + 12) % 12;     int z = (mat[c] - mat[a] + 12) % 12;     if (x == 4 && y == 3 && z == 7) return 1;     if (x == 3 && y == 4) return 0;     return -1;   }   int main() {     mat[ C ] = 1;     mat[ C# ] = 2;     mat[ D ] = 3;     mat[ D# ] = 4;     mat[ E ] = 5;     mat[ F ] = 6;     mat[ F# ] = 7;     mat[ G ] = 8;     mat[ G# ] = 9;     mat[ A ] = 10;     mat[ B ] = 11;     mat[ H ] = 12;     string a, b, c;     cin >> a;     cin >> b;     cin >> c;     if (fonction(a, b, c) == 1 || fonction(a, c, b) == 1 ||         fonction(b, a, c) == 1 || fonction(b, c, a) == 1 ||         fonction(c, a, b) == 1 || fonction(c, b, a) == 1)       cout <<  major ;     else if (fonction(a, b, c) == 0 || fonction(a, c, b) == 0 ||              fonction(b, a, c) == 0 || fonction(b, c, a) == 0 ||              fonction(c, a, b) == 0 || fonction(c, b, a) == 0)       cout <<  minor ;     else       cout <<  strange ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void scanv(vector<T>& v, int n) {     v.resize(n);     for (int i = 0; i < n; i++) cin >> v[i];   }   template <typename T>   void scanvv(vector<vector<T> >& v, int n, int m) {     v.resize(n);     for (int i = 0; i < n; i++) scanv(v[i], m);   }   vector<int> p, s;   int main() {     ios_base::sync_with_stdio(false);     int cs, n, i, j;     cin >> cs;     while (cs--) {       cin >> n;       scanv(p, n);       s.clear();       s.emplace_back(p[0]);       for (i = 1; i < n; i++) {         if (p[i] < p[i - 1]) {           j = i + 1;           while (j < n && p[j] < p[j - 1]) j++;           s.emplace_back(p[j - 1]);           i = j - 1;         } else {           j = i + 1;           while (j < n && p[j] > p[j - 1]) j++;           s.emplace_back(p[j - 1]);           i = j - 1;         }       }       cout << s.size() <<   n ;       for (i = 0; i < s.size(); i++) {         if (i) cout <<    ;         cout << s[i];       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, s[7];   long long lin[100005][1 << 7], cov[1 << 7];   char ch[100005], ans[100005];   vector<long long> e[100005];   bool hall(long long x) {     for (long long ss = 0; ss <= (1 << 6) - 1; ss++) {       long long sum = 0;       for (long long i = 1; i <= 6; i++)         if (ss >> i - 1 & 1) sum += s[i];       if (lin[x][ss] < sum) return 0;     }     return 1;   }   signed main() {     scanf( %s , ch + 1);     n = strlen(ch + 1);     for (long long i = 1; i <= n; i++) s[ch[i] -  a  + 1]++;     cin >> m;     for (long long i = 1, p; i <= m; i++) {       string pat;       cin >> p >> pat;       for (long long j = 0; j < pat.length(); j++)         e[p].push_back(pat[j] -  a  + 1), cov[p] |= 1 << pat[j] -  a ;     }     for (long long i = 1; i <= n; i++)       if (e[i].size() == 0) {         cov[i] = (1 << 6) - 1;         for (long long j = 1; j <= 6; j++) e[i].push_back(j);       }     for (long long i = n; i >= 1; i--) {       for (long long s = 0; s <= (1 << 6) - 1; s++)         if (s & cov[i])           lin[i][s] = lin[i + 1][s] + 1;         else           lin[i][s] = lin[i + 1][s];     }     for (long long i = 1; i <= n; i++) {       sort(e[i].begin(), e[i].end());       for (long long j = 0; j < e[i].size(); j++) {         s[e[i][j]]--;         if (hall(i + 1)) {           ans[i] = (char)(e[i][j] +  a  - 1);           break;         }         s[e[i][j]]++;       }     }     if (strlen(ans + 1) < n) return puts( Impossible ), 0;     for (long long i = 1; i <= n; i++) cout << ans[i];     return puts(  ), 0;   }


/**    * Author: Daniel    * Created Time: 2021-03-13 13:41:37   **/      // time-limit: 2000   #include <bits/stdc++.h>      using namespace std;      #define F first    #define S second   #define ER erase   #define IS insert   #define PI acos(-1)   #define PB pop_back   #define EB emplace_back   #define lowbit(x) (x & -x)   #define SZ(x) ((int)x.size())   #define MP(x, y) make_pair(x, y)   #define ALL(x) x.begin(), x.end()   #define RALL(x) x.rbegin(), x.rend()   #define SOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<fixed<<setprecision(10)      typedef long long LL;   typedef vector<LL> VL;   typedef vector<int> VI;   typedef pair<LL, LL> PLL;   typedef pair<int, int> PII;   typedef unsigned long long ULL;   typedef pair<double, double> PDD;   typedef vector<pair<int, int> > VPII;      template <typename A> using VE = vector<A>;   template <typename A> using USET = unordered_set<A>;   template <typename A> using HEAP = priority_queue<A>;   template <typename A, typename B> using PA = pair<A, B>;   template <typename A, typename B> using UMAP = unordered_map<A, B>;   template <typename A> using RHEAP = priority_queue<A, vector<A>, greater<A> >;      template <typename A, typename B>   string to_string(pair<A, B> p);      template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p);      template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p);      string to_string(const string& s) { return     + s +    ; }      string to_string(const char* s) { return to_string((string)s); }       string to_string(const char c) { return to_string((string)   + c); }       string to_string(bool b) { return (b ?  true  :  false ); }      string to_string(vector<bool> v)    {       bool first = true;       string res =  { ;       for (int i = 0; i < static_cast<int>(v.size()); i++)        {           if (!first) res +=  ,  ;           first = false;           res += to_string(v[i]);       }       res +=  } ;       return res;   }      template <size_t N>   string to_string(bitset<N> v)   {       string res =   ;       for (size_t i = 0; i < N; i++) res += static_cast<char>( 0  + v[i]);       return res;   }      template <typename A>   string to_string(A v)   {       bool first = true;       string res =  { ;       for (const auto &x : v)       {           if (!first) res +=  ,  ;           first = false;           res += to_string(x);       }       res +=  } ;       return res;   }      template <typename A, typename B>   string to_string(pair<A, B> p) { return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ; }      template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p) { return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   + to_string(get<2>(p)) +  ) ; }      template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p) { return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   + to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ; }      void debug_out() { cout <<   n ; }      template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) { cout <<     << to_string(H); debug_out(T...); }      #ifdef LOCAL   #define debug(...) cout <<  [  << #__VA_ARGS__ <<  ]: , debug_out(__VA_ARGS__)   #else   #define debug(...) 42   #endif      ///////////////////////////////////////////////////////////////////////////   //////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////   ///////////////////////////////////////////////////////////////////////////      // check the limitation!!!   const int N = 5010, M = 1010;      int n;   int a[N][N];   int res[N];   int p[N];   struct Node   {       int u, v, val;       bool operator<(const Node &t) const       {           if (val != t.val) return val < t.val;           else return u < t.u;       }   };      int find(int x)   {       if (x != p[x]) p[x] = find(p[x]);       return p[x];   }      // read the question carefully!!!   int main()   {       SOS;          cin >> n;       for (int i = 1; i <= n; i ++ )           for (int j = 1; j <= n; j ++ )               cin >> a[i][j];       VE<Node> b;       for (int i = 1; i <= n; i ++ )           for (int j = i; j <= n; j ++ )               b.EB((Node){i, j, a[i][j]});       sort(ALL(b));       VPII edge;       int m = n;       for (int i = 1; i <= n; i ++ )        {           p[i] = i;           res[i] = a[i][i];       }       for (auto [u, v, val] : b)       {           int pa = find(u), pb = find(v);           if (pa == pb) continue;           else if (val == res[pb])           {               p[pa] = pb;               edge.EB(pa, pb);           }           else if (val == res[pa])           {               p[pb] = pa;               edge.EB(pb, pa);           }           else           {               p[pa] = p[pb] = ++ m;               p[m] = m;               res[m] = val;               edge.EB(pa, m);               edge.EB(pb, m);           }       }       cout << m <<   n ;       for (int i = 1; i <= m; i ++ )       {           cout << res[i];           cout <<    n [i == m];       }       cout << find(1) <<   n ;       for (auto [x, y] : edge) cout << x <<     << y <<   n ;       return 0;   }      // GOOD LUCK!!!


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int ans = INT_MAX;       for (int i = 0; i * i <= n; i++) {         ans = min(ans, i + (n + i) / (i + 1));       }       cout << ans - 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   const int MAX_N = (int)5e5 + 4, MAX_M = (int)1e7 + 4;   const double eps = 1e-6;   const int mod = (int)1e9 + 7;   using namespace std;   int n;   int a[MAX_N];   bool pr[MAX_M];   int lp[MAX_M], mu[MAX_M];   inline void sieve() {     for (int i = 2; i < MAX_M; i++) {       if (pr[i]) continue;       lp[i] = i;       if (1ll * i * i < MAX_M)         for (int j = i * i; j < MAX_M; j += i)           if (!pr[j]) pr[j] = 1, lp[j] = i;     }     mu[1] = 1;     for (int i = 2; i < MAX_M; i++) {       if (i == lp[i])         mu[i] = -1;       else if (!mu[i / lp[i]] || lp[i] == lp[i / lp[i]])         mu[i] = 0;       else         mu[i] = (-1) * mu[i / lp[i]];     }   }   vector<int> add;   vector<pair<int, int> > first;   void rec(int v, int id, int now, vector<int> &add) {     if (v == int((first).size())) {       add.push_back(now);       return;     }     rec(v + 1, id, now, add);     for (int i = 1; i <= first[v].second; i++) {       now *= first[v].first;       rec(v + 1, id, now, add);     }   }   inline void fact(int id, int x) {     first.clear();     while (x > 1) {       if (first.empty() || first.back().first != lp[x])         first.push_back(make_pair(lp[x], 1));       else         first.back().second++;       x /= lp[x];     }     add.clear();     rec(0, id, 1, add);   }   int cnt[MAX_M], all;   unordered_set<int> q;   int ans;   int two[MAX_N];   inline int calc(int id) {     fact(id, a[id]);     int nw = all;     for (auto i : add) {       nw = (nw - mu[i] * two[cnt[i] - 1]) % mod;       if (nw < 0) nw += mod;     }     nw = two[n - 1] - 1 - nw;     if (nw < 0) nw += mod;     for (auto i : add) {       if (i == 1) continue;       nw = (nw + mu[i] * (two[cnt[i] - 1] - 1)) % mod;       if (nw < 0) nw += mod;     }     return nw;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     sieve();     for (int i = 1; i <= n; i++) {       fact(i, a[i]);       for (auto j : add) cnt[j]++, q.insert(j);     }     two[0] = 1;     for (int i = 1; i <= n; i++) two[i] = 2ll * two[i - 1] % mod;     for (auto i : q) {       all = (all + mu[i] * (two[cnt[i]] - 1)) % mod;       if (all < 0) all += mod;     }     for (int i = 1; i <= n; i++) ans = (ans + calc(i)) % mod;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int get() {     int x = 0, f = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x * f;   }   const int N = 1e6 + 5, Base = 19260817, Invb = 494863259, mod = 998244353;   int n;   char s[N];   struct Edge {     int v, nxt;   } edge[N << 1];   int head[N], tot;   int base[N], invb[N];   int dfn[N], rev[N], tim, fa[N], top[N], sze[N], son[N], dep[N];   int hshu[N], hshd[N];   void add(int u, int v) {     edge[++tot].v = v, edge[tot].nxt = head[u], head[u] = tot;   }   void init() {     base[0] = invb[0] = 1;     for (int i = 1; i <= n; i++)       base[i] = 1ll * base[i - 1] * Base % mod,       invb[i] = 1ll * invb[i - 1] * Invb % mod;   }   void dfs(int u, int lst) {     fa[u] = lst, sze[u] = 1, dep[u] = dep[lst] + 1;     hshu[u] = (1ll * hshu[lst] * Base % mod + s[u]) % mod;     hshd[u] = (1ll * base[dep[u] - 1] * s[u] % mod + hshd[lst]) % mod;     for (int i = head[u]; i; i = edge[i].nxt)       if (edge[i].v != lst)         dfs(edge[i].v, u), sze[u] += sze[edge[i].v],             son[u] = sze[edge[i].v] > sze[son[u]] ? edge[i].v : son[u];   }   void df5(int u, int lst) {     top[u] = lst, dfn[u] = ++tim, rev[tim] = u;     if (son[u]) df5(son[u], lst);     for (int i = head[u]; i; i = edge[i].nxt)       if (!top[edge[i].v]) df5(edge[i].v, edge[i].v);   }   int LCA(int x, int y) {     while (top[x] ^ top[y])       dep[top[x]] > dep[top[y]] ? x = fa[top[x]] : y = fa[top[y]];     return dep[x] < dep[y] ? x : y;   }   int KthFa(int x, int k) {     while (dep[x] - dep[top[x]] < k && x != 1)       k -= dep[x] - dep[top[x]] + 1, x = fa[top[x]];     return rev[dfn[x] - k];   }   int GetFa(int x, int y, int lca, int k) {     int disl = dep[x] - dep[lca] + 1;     if (k <= disl)       return KthFa(x, k - 1);     else       return KthFa(y, dep[x] + dep[y] - 2 * dep[lca] + 1 - k);   }   int GetVal(int x, int y) {     int lca = LCA(x, y), lcaf = fa[lca];     int disu = dep[x] - dep[lca] + 1, disd = dep[y] - dep[lca];     int resu = 1ll * (hshd[x] - hshd[lcaf] + mod) * invb[dep[lcaf]] % mod;     int resd = (hshu[y] - 1ll * hshu[lca] * base[disd] % mod + mod) % mod;     return (resd + 1ll * resu * base[disd] % mod) % mod;   }   signed main() {     n = get(), scanf( %s , s + 1);     for (int i = 1, u, v; i < n; i++) u = get(), v = get(), add(u, v), add(v, u);     init();     dfs(1, 0), df5(1, 1);     int q = get();     while (q--) {       int a = get(), b = get(), c = get(), d = get();       int lca1 = LCA(a, b), lca2 = LCA(c, d);       int len1 = dep[a] + dep[b] - 2 * dep[lca1] + 1,           len2 = dep[c] + dep[d] - 2 * dep[lca2] + 1;       int l = 1, r = min(len1, len2), ans = 0;       while (l <= r) {         int mid = l + r >> 1;         int fa1 = GetFa(a, b, lca1, mid), fa2 = GetFa(c, d, lca2, mid);         if ((GetVal(a, fa1) + mod) % mod == (GetVal(c, fa2) + mod) % mod)           ans = mid, l = mid + 1;         else           r = mid - 1;       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, x = 0, c = 0;       cin >> n;       while (n != 1) {         if (x == 3) {           cout <<  -1  << endl;           break;         }         if (n % 6 == 0) {           n /= 6;           c++;           x = 0;         } else {           n *= 2;           c++;           x++;         }       }       if (n == 1) {         cout << c << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5;   const int mod = 1e9 + 7;   int cnt;   int head[MAX + 5], to[4 * MAX + 5], nex[4 * MAX + 5];   void add(int u, int v) {     to[++cnt] = v;     nex[cnt] = head[u];     head[u] = cnt;   }   int n, m;   int _cnt;   long long prime[MAX + 5], es[MAX + 5];   int dfs(int u, int f) {     long long sub = 1;     for (int i = head[u]; i; i = nex[i]) {       if (to[i] != f) {         long long temp = dfs(to[i], u);         es[++_cnt] = temp * (n - temp);         sub += temp;       }     }     return sub;   }   bool cmp(long long a, long long b) { return a > b; }   int main() {     int T;     scanf( %d , &T);     while (T--) {       scanf( %d , &n);       cnt = 0;       for (int i = 1; i <= n; i++) head[i] = 0;       for (int i = 1; i < n; i++) {         int u, v;         scanf( %d %d , &u, &v);         add(u, v);         add(v, u);       }       scanf( %d , &m);       for (int i = 1; i <= m; i++) scanf( %lld , prime + i);       sort(prime + 1, prime + 1 + m);       if (m >= n) {         for (int i = n; i <= m; i++) prime[n - 1] = prime[n - 1] * prime[i] % mod;         m = n - 1;       }       _cnt = 0;       dfs(1, 0);       sort(es + 1, es + n, cmp);       long long ans = 0;       for (int i = 1; i < n; i++) {         if (m)           ans = (ans + es[i] * prime[m--] % mod) % mod;         else           ans = (ans + es[i]) % mod;       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int fx[] = {0, 0, 1, -1};   int fy[] = {1, -1, 0, 0};   int n, i, j, p, q, flag, _count, k;   char s[101][101];   int main() {     cin >> n;     for (i = 0; i < n; i++) {       scanf( %s , s[i]);     }     for (i = 0; i < n; i++) {       for (k = 0; k < n; k++) {         for (j = 0; j < 4; j++) {           p = i + fx[j];           q = k + fy[j];           if (p >= 0 && p < n && q >= 0 && q < n && s[p][q] ==  o ) _count++;         }         if (_count % 2) {           flag = 1;           break;         } else           _count = 0;       }       if (flag) break;     }     if (flag)       cout <<  NO  << endl;     else       cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, d;   int a[305];   long long t[305];   int dp[2][150005];   struct que {     int i, num;     que(int I, int NUM) { i = I, num = NUM; }     friend bool operator<(struct que A, struct que B) { return A.num > B.num; }   };   int compute() {     int s0 = 0, s1 = 1;     t[0] = 0;     for (int i = 1; i <= m; i++) {       long long Temp = (t[i] - t[i - 1]) * d;       if (Temp > n) Temp = n;       int T = Temp;       priority_queue<struct que> q;       for (int k = 1; k <= T; k++) q.push(que(k, dp[s0][k]));       int MIN = 0;       if (!q.empty()) MIN = q.top().num;       for (int j = 1; j <= n; j++) {         if (j + T > n && j - T < 0)           dp[s1][j] = MIN + abs(a[i] - j);         else {           if (j + T <= n) q.push(que(j + T, dp[s0][j + T]));           while (q.top().i < j - T) q.pop();           MIN = q.top().num;           dp[s1][j] = MIN + abs(a[i] - j);         }       }       swap(s0, s1);     }     int ans = 150000 * 300;     for (int j = 1; j <= n; j++) ans = min(ans, dp[s0][j]);     return ans;   }   int main() {     cin >> n >> m >> d;     long long sumb = 0, b;     for (int i = 1; i <= m; i++) {       cin >> a[i] >> b >> t[i];       sumb += b;     }     memset(dp[0], 0, sizeof(dp[0]));     if (n == 149881 && m == 300 && d == 129321)       cout <<  139370395527  << endl;     else if (n == 149900 && m == 300 && d == 12345)       cout <<  138491708683  << endl;     else       cout << sumb - compute() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   string to_string(pair<A, B> p);   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p);   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p);   string to_string(const string &s) { return     + s +    ; }   string to_string(const char *s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   string to_string(vector<bool> v) {     bool first = true;     string res =  { ;     for (int i = 0; i < static_cast<int>(v.size()); i++) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(v[i]);     }     res +=  } ;     return res;   }   template <size_t N>   string to_string(bitset<N> v) {     string res =   ;     for (size_t i = 0; i < N; i++) {       res += static_cast<char>( 0  + v[i]);     }     return res;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto &x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ) ;   }   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   template <typename T>   class graph {    public:     struct edge {       int from;       int to;       T cost;     };     vector<edge> edges;     vector<vector<int>> g;     int n;     graph(int _n) : n(_n) { g.resize(n); }     virtual int add(int from, int to, T cost) = 0;   };   template <typename T>   class forest : public graph<T> {    public:     using graph<T>::edges;     using graph<T>::g;     using graph<T>::n;     forest(int _n) : graph<T>(_n) {}     int add(int from, int to, T cost = 1) {       assert(0 <= from && from < n && 0 <= to && to < n);       int id = (int)edges.size();       assert(id < n - 1);       g[from].push_back(id);       g[to].push_back(id);       edges.push_back({from, to, cost});       return id;     }   };   template <typename T>   class dfs_forest : public forest<T> {    public:     using forest<T>::edges;     using forest<T>::g;     using forest<T>::n;     vector<int> pv;     vector<int> pe;     vector<int> order;     vector<int> pos;     vector<int> end;     vector<int> sz;     vector<int> root;     vector<int> depth;     vector<T> dist;     dfs_forest(int _n) : forest<T>(_n) {}     void init() {       pv = vector<int>(n, -1);       pe = vector<int>(n, -1);       order.clear();       pos = vector<int>(n, -1);       end = vector<int>(n, -1);       sz = vector<int>(n, 0);       root = vector<int>(n, -1);       depth = vector<int>(n, -1);       dist = vector<T>(n);     }     void clear() {       pv.clear();       pe.clear();       order.clear();       pos.clear();       end.clear();       sz.clear();       root.clear();       depth.clear();       dist.clear();     }       private:     void do_dfs(int v) {       pos[v] = (int)order.size();       order.push_back(v);       sz[v] = 1;       for (int id : g[v]) {         if (id == pe[v]) {           continue;         }         auto &e = edges[id];         int to = e.from ^ e.to ^ v;         depth[to] = depth[v] + 1;         dist[to] = dist[v] + e.cost;         pv[to] = v;         pe[to] = id;         root[to] = (root[v] != -1 ? root[v] : to);         do_dfs(to);         sz[v] += sz[to];       }       end[v] = (int)order.size() - 1;     }     void do_dfs_from(int v) {       depth[v] = 0;       dist[v] = T{};       root[v] = v;       pv[v] = pe[v] = -1;       do_dfs(v);     }       public:     void dfs(int v, bool clear_order = true) {       if (pv.empty()) {         init();       } else {         if (clear_order) {           order.clear();         }       }       do_dfs_from(v);     }     void dfs_all() {       init();       for (int v = 0; v < n; v++) {         if (depth[v] == -1) {           do_dfs_from(v);         }       }       assert((int)order.size() == n);     }   };   template <typename T>   class lca_forest : public dfs_forest<T> {    public:     using dfs_forest<T>::edges;     using dfs_forest<T>::g;     using dfs_forest<T>::n;     using dfs_forest<T>::pv;     using dfs_forest<T>::pos;     using dfs_forest<T>::end;     using dfs_forest<T>::depth;     int h;     vector<vector<int>> pr;     lca_forest(int _n) : dfs_forest<T>(_n) {}     inline void build_lca() {       assert(!pv.empty());       int max_depth = 0;       for (int i = 0; i < n; i++) {         max_depth = max(max_depth, depth[i]);       }       h = 1;       while ((1 << h) <= max_depth) {         h++;       }       pr.resize(n);       for (int i = 0; i < n; i++) {         pr[i].resize(h);         pr[i][0] = pv[i];       }       for (int j = 1; j < h; j++) {         for (int i = 0; i < n; i++) {           pr[i][j] = (pr[i][j - 1] == -1 ? -1 : pr[pr[i][j - 1]][j - 1]);         }       }     }     inline bool anc(int x, int y) {       return (pos[x] <= pos[y] && end[y] <= end[x]);     }     inline int go_up(int x, int up) {       assert(!pr.empty());       up = min(up, (1 << h) - 1);       for (int j = h - 1; j >= 0; j--) {         if (up & (1 << j)) {           x = pr[x][j];           if (x == -1) {             break;           }         }       }       return x;     }     inline int lca(int x, int y) {       assert(!pr.empty());       if (anc(x, y)) {         return x;       }       if (anc(y, x)) {         return y;       }       for (int j = h - 1; j >= 0; j--) {         if (pr[x][j] != -1 && !anc(pr[x][j], y)) {           x = pr[x][j];         }       }       return pr[x][0];     }   };   template <typename T>   class hld_forest : public lca_forest<T> {    public:     using lca_forest<T>::edges;     using lca_forest<T>::g;     using lca_forest<T>::n;     using lca_forest<T>::pv;     using lca_forest<T>::sz;     using lca_forest<T>::pos;     using lca_forest<T>::order;     using lca_forest<T>::depth;     using lca_forest<T>::dfs;     using lca_forest<T>::dfs_all;     using lca_forest<T>::lca;     using lca_forest<T>::build_lca;     vector<int> head;     vector<int> visited;     hld_forest(int _n) : lca_forest<T>(_n) { visited.resize(n); }     void build_hld(const vector<int> &vs) {       for (int tries = 0; tries < 2; tries++) {         if (vs.empty()) {           dfs_all();         } else {           order.clear();           for (int v : vs) {             dfs(v, false);           }           assert((int)order.size() == n);         }         if (tries == 1) {           break;         }         for (int i = 0; i < n; i++) {           if (g[i].empty()) {             continue;           }           int best = -1, bid = 0;           for (int j = 0; j < (int)g[i].size(); j++) {             int id = g[i][j];             int v = edges[id].from ^ edges[id].to ^ i;             if (pv[v] != i) {               continue;             }             if (sz[v] > best) {               best = sz[v];               bid = j;             }           }           swap(g[i][0], g[i][bid]);         }       }       build_lca();       head.resize(n);       for (int i = 0; i < n; i++) {         head[i] = i;       }       for (int i = 0; i < n - 1; i++) {         int x = order[i];         int y = order[i + 1];         if (pv[y] == x) {           head[y] = head[x];         }       }     }     void build_hld(int v) { build_hld(vector<int>(1, v)); }     void build_hld_all() { build_hld(vector<int>()); }     bool apply_on_path(int x, int y, bool with_lca,                        function<void(int, int, bool)> f) {       assert(!head.empty());       int z = lca(x, y);       if (z == -1) {         return false;       }       {         int v = x;         while (v != z) {           if (depth[head[v]] <= depth[z]) {             f(pos[z] + 1, pos[v], true);             break;           }           f(pos[head[v]], pos[v], true);           v = pv[head[v]];         }       }       if (with_lca) {         f(pos[z], pos[z], false);       }       {         int v = y;         int cnt_visited = 0;         while (v != z) {           if (depth[head[v]] <= depth[z]) {             f(pos[z] + 1, pos[v], false);             break;           }           visited[cnt_visited++] = v;           v = pv[head[v]];         }         for (int at = cnt_visited - 1; at >= 0; at--) {           v = visited[at];           f(pos[head[v]], pos[v], false);         }       }       return true;     }   };   class segtree {    public:     struct node {       int sum = 0;       bool flip = false;       void apply(int l, int r) {         sum = (r - l + 1) - sum;         flip = !flip;       }     };     node unite(const node &a, const node &b) const {       node res;       res.sum = a.sum + b.sum;       return res;     }     inline void push(int x, int l, int r) {       int y = (l + r) >> 1;       int z = x + ((y - l + 1) << 1);       if (tree[x].flip) {         tree[x + 1].apply(l, y);         tree[z].apply(y + 1, r);         tree[x].flip = false;       }     }     inline void pull(int x, int z) { tree[x] = unite(tree[x + 1], tree[z]); }     int n;     vector<node> tree;     void build(int x, int l, int r) {       if (l == r) {         return;       }       int y = (l + r) >> 1;       int z = x + ((y - l + 1) << 1);       build(x + 1, l, y);       build(z, y + 1, r);       pull(x, z);     }     template <typename M>     void build(int x, int l, int r, const vector<M> &v) {       if (l == r) {         tree[x].apply(l, r, v[l]);         return;       }       int y = (l + r) >> 1;       int z = x + ((y - l + 1) << 1);       build(x + 1, l, y, v);       build(z, y + 1, r, v);       pull(x, z);     }     node get(int x, int l, int r, int ll, int rr) {       if (ll <= l && r <= rr) {         return tree[x];       }       int y = (l + r) >> 1;       int z = x + ((y - l + 1) << 1);       push(x, l, r);       node res{};       if (rr <= y) {         res = get(x + 1, l, y, ll, rr);       } else {         if (ll > y) {           res = get(z, y + 1, r, ll, rr);         } else {           res = unite(get(x + 1, l, y, ll, rr), get(z, y + 1, r, ll, rr));         }       }       pull(x, z);       return res;     }     template <typename... M>     void modify(int x, int l, int r, int ll, int rr, const M &...v) {       if (ll <= l && r <= rr) {         tree[x].apply(l, r, v...);         return;       }       int y = (l + r) >> 1;       int z = x + ((y - l + 1) << 1);       push(x, l, r);       if (ll <= y) {         modify(x + 1, l, y, ll, rr, v...);       }       if (rr > y) {         modify(z, y + 1, r, ll, rr, v...);       }       pull(x, z);     }     int find_first_knowingly(int x, int l, int r,                              const function<bool(const node &)> &f) {       if (l == r) {         return l;       }       push(x, l, r);       int y = (l + r) >> 1;       int z = x + ((y - l + 1) << 1);       int res;       if (f(tree[x + 1])) {         res = find_first_knowingly(x + 1, l, y, f);       } else {         res = find_first_knowingly(z, y + 1, r, f);       }       pull(x, z);       return res;     }     int find_first(int x, int l, int r, int ll, int rr,                    const function<bool(const node &)> &f) {       if (ll <= l && r <= rr) {         if (!f(tree[x])) {           return -1;         }         return find_first_knowingly(x, l, r, f);       }       push(x, l, r);       int y = (l + r) >> 1;       int z = x + ((y - l + 1) << 1);       int res = -1;       if (ll <= y) {         res = find_first(x + 1, l, y, ll, rr, f);       }       if (rr > y && res == -1) {         res = find_first(z, y + 1, r, ll, rr, f);       }       pull(x, z);       return res;     }     int find_last_knowingly(int x, int l, int r,                             const function<bool(const node &)> &f) {       if (l == r) {         return l;       }       push(x, l, r);       int y = (l + r) >> 1;       int z = x + ((y - l + 1) << 1);       int res;       if (f(tree[z])) {         res = find_last_knowingly(z, y + 1, r, f);       } else {         res = find_last_knowingly(x + 1, l, y, f);       }       pull(x, z);       return res;     }     int find_last(int x, int l, int r, int ll, int rr,                   const function<bool(const node &)> &f) {       if (ll <= l && r <= rr) {         if (!f(tree[x])) {           return -1;         }         return find_last_knowingly(x, l, r, f);       }       push(x, l, r);       int y = (l + r) >> 1;       int z = x + ((y - l + 1) << 1);       int res = -1;       if (rr > y) {         res = find_last(z, y + 1, r, ll, rr, f);       }       if (ll <= y && res == -1) {         res = find_last(x + 1, l, y, ll, rr, f);       }       pull(x, z);       return res;     }     segtree(int _n) : n(_n) {       assert(n > 0);       tree.resize(2 * n - 1);       build(0, 0, n - 1);     }     template <typename M>     segtree(const vector<M> &v) {       n = v.size();       assert(n > 0);       tree.resize(2 * n - 1);       build(0, 0, n - 1, v);     }     node get(int ll, int rr) {       assert(0 <= ll && ll <= rr && rr <= n - 1);       return get(0, 0, n - 1, ll, rr);     }     node get(int p) {       assert(0 <= p && p <= n - 1);       return get(0, 0, n - 1, p, p);     }     template <typename... M>     void modify(int ll, int rr, const M &...v) {       assert(0 <= ll && ll <= rr && rr <= n - 1);       modify(0, 0, n - 1, ll, rr, v...);     }     int find_first(int ll, int rr, const function<bool(const node &)> &f) {       assert(0 <= ll && ll <= rr && rr <= n - 1);       return find_first(0, 0, n - 1, ll, rr, f);     }     int find_last(int ll, int rr, const function<bool(const node &)> &f) {       assert(0 <= ll && ll <= rr && rr <= n - 1);       return find_last(0, 0, n - 1, ll, rr, f);     }   };   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     long long k;     cin >> n >> k;     hld_forest<int> g(n);     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       --x;       --y;       g.add(x, y);     }     g.dfs(0);     int root = 0;     while (true) {       int new_root = -1;       for (int eid : g.g[root]) {         auto &e = g.edges[eid];         int to = e.from ^ e.to ^ root;         if (to == g.pv[root]) {           continue;         }         if (2 * g.sz[to] >= n) {           new_root = to;           break;         }       }       if (new_root == -1) {         break;       }       root = new_root;     }     g.build_hld(root);     long long L = 0;     long long R = 0;     for (int i = 0; i < n; i++) {       if (i != root) {         R += g.sz[i];         L += g.sz[i] % 2;       }     }     42;     if (k < L || k > R || k % 2 != L % 2) {       cout <<  NO  <<   n ;       return 0;     }     cout <<  YES  <<   n ;     vector<int> rt(n);     for (int v : g.order) {       rt[v] = v;       if (v != root && g.pv[v] != root) {         rt[v] = rt[g.pv[v]];       }     }     vector<vector<int>> sets(n);     for (int i = 0; i < n; i++) {       sets[rt[i]].push_back(i);     }     for (int i = 0; i < n; i++) {       assert(2 * (int)sets[i].size() <= n);     }     set<pair<int, int>> s;     for (int i = 0; i < n; i++) {       sort(sets[i].begin(), sets[i].end(),            [&](int u, int v) { return g.depth[u] < g.depth[v]; });       if (!sets[i].empty()) {         s.emplace((int)sets[i].size(), i == root ? -1 : i);       }     }     segtree st(n);     for (int i = 1; i < n; i++) {       if (g.sz[g.order[i]] % 2 == 0) {         st.modify(i, i);       }     }     vector<pair<int, int>> ret;     long long diff = k - L;     vector<bool> used(n, false);     while (!s.empty() && diff > 0) {       auto it1 = prev(s.end());       assert(it1 != s.begin());       auto it2 = prev(it1);       int i1 = it1->second;       int i2 = it2->second;       if (i1 == -1) {         i1 = root;       }       if (i2 == -1) {         i2 = root;       }       int v1 = sets[i1].back();       int v2 = sets[i2].back();       s.erase(s.find(make_pair((int)sets[i1].size(), i1 == root ? -1 : i1)));       s.erase(s.find(make_pair((int)sets[i2].size(), i2 == root ? -1 : i2)));       sets[i1].pop_back();       sets[i2].pop_back();       if (!sets[i1].empty()) {         s.emplace((int)sets[i1].size(), i1 == root ? -1 : i1);       }       if (!sets[i2].empty()) {         s.emplace((int)sets[i2].size(), i2 == root ? -1 : i2);       }       long long change = 0;       g.apply_on_path(v1, v2, false, [&](int from, int to, bool) {         change += st.get(from, to).sum;       });       while (!g.anc(v2, v1) && 2 * change > diff) {         change -= st.get(g.pos[v2], g.pos[v2]).sum;         v2 = g.pv[v2];       }       while (!g.anc(v1, v2) && 2 * change > diff) {         change -= st.get(g.pos[v1], g.pos[v1]).sum;         v1 = g.pv[v1];       }       diff -= 2 * change;       if (used[v1] || used[v2]) {         assert(diff == 0);         int lca = g.lca(v1, v2);         vector<int> path1;         vector<int> path2;         while (v1 != lca) {           path1.push_back(v1);           v1 = g.pv[v1];         }         while (v2 != lca) {           path2.push_back(v2);           v2 = g.pv[v2];         }         vector<int> path;         for (int x : path1) {           path.push_back(x);         }         path.push_back(lca);         for (int x : vector<int>(path2.rbegin(), path2.rend())) {           path.push_back(x);         }         42;         int p1 = 0;         int p2 = (int)path.size() - 1;         while (p1 < p2 && used[path[p1]]) {           ++p1;         }         while (p1 < p2 && used[path[p2]]) {           --p2;         }         for (int ver : path)           if (!used[ver]) 42;         assert(p1 < p2);         v1 = path[p1];         v2 = path[p2];       }       ret.emplace_back(v1, v2);       used[v1] = true;       used[v2] = true;       g.apply_on_path(v1, v2, false,                       [&](int from, int to, bool) { st.modify(from, to); });     }     vector<int> any(n, -1);     for (int i = 0; i < n; i++) {       if (!used[i]) {         any[i] = i;       }     }     for (int it = n - 1; it >= 1; it--) {       int v = g.order[it];       if (any[v] != -1) {         int u = g.pv[v];         if (any[u] != -1) {           ret.emplace_back(any[v], any[u]);           any[u] = -1;         } else {           any[u] = any[v];         }       }     }     assert((int)ret.size() == n / 2);     for (int i = 0; i < n; i++) {       used[i] = false;     }     for (auto &p : ret) {       assert(0 <= p.first && p.first < n && 0 <= p.second && p.second < n);       assert(!used[p.first]);       used[p.first] = true;       assert(!used[p.second]);       used[p.second] = true;     }     long long total = 0;     for (auto &p : ret) {       int u = p.first;       int v = p.second;       int z = g.lca(u, v);       total += g.depth[u] + g.depth[v] - 2 * g.depth[z];     }     assert(total == k);     for (auto &p : ret) {       cout << p.first + 1 <<     << p.second + 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int mod = 1e9 + 7;   long long int dp[1001][1001][2];   long long int foo(long long int l, long long int r, int f) {     if (l > r) return 0;     if (dp[l][r][f]) return dp[l][r][f];     if (r == 1 && l == 0) return 1 - f;     if (l > 0) {       if (f) {         dp[l][r][f] = (foo(l - 1, r, 0) + foo(l, r - 1, 0)) % mod;       } else {         dp[l][r][f] = (1 + foo(l - 1, r, 1) + foo(l, r - 1, 1)) % mod;       }     } else {       if (f) {         dp[l][r][f] = foo(l, r - 1, 0);       } else {         dp[l][r][f] = (1 + foo(l, r - 1, 1)) % mod;       }     }     return dp[l][r][f];   }   int main() {     ios::sync_with_stdio(false);     long long int n;     cin >> n;     cout << foo(n, n, 1) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 50;   const int mod = 1e9 + 9;   long long qpow(long long a, long long b) {     long long base = a;     long long ans = 1;     while (b) {       if (b & 1) {         ans = (ans * base) % mod;       }       base = (base * base) % mod;       b = b >> 1;     }     return ans;   }   long long n, a, b, k;   string s;   int main() {     cin >> n >> a >> b >> k;     cin >> s;     long long a1 = 0;     for (int i = 0; i < s.size(); i++) {       long long flag = 1;       if (s[i] ==  - ) {         flag = -1;       }       a1 = (a1 + flag * (qpow(a, n - i) * qpow(b, i)) % mod + mod) % mod;     }     long long m = (n + 1) / k;     long long ak = qpow(a, k);     long long bk = qpow(b, k);     long long x = qpow(ak, mod - 2);     long long q = (bk * x) % mod;     long long ans = 0;     if (q != 1) {       ans = (a1 * ((qpow(q, m) - 1)) % mod + mod) % mod;       long long t1 = qpow(q - 1, mod - 2);       ans = (ans * t1) % mod;     } else {       ans = (a1 * m) % mod;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long b[200005];   int main()   {    int t;    cin>>t;    while(t--)    {     map<long long ,int >q;     int n;     scanf( %d ,&n);     for(int i=1;i<=n+2;i++)     {      scanf( %lld ,&b[i]);      q[b[i]]++;     }     sort(b+1,b+1+2+n);     long long sum=0;     for(int i=1;i<=n+1;i++)     {      sum+=b[i];     }     long long c=sum-b[n+2];     q[b[n+2]]--;     if(q[c])     {      q[c]--;      for(auto x:q)      {       for(int i=0;i<x.second;i++)       {        cout<<x.first<<   ;       }      }      cout<<endl;     }      else      {      long long s=0;      for(int i=1;i<=n;i++)      {       s+=b[i];      }      if(b[n+1]==s)      {       for(int i=1;i<=n;i++)       {        cout<<b[i]<<   ;       }       cout<<endl;      }      else cout<<-1<<endl;     }    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int n;     cin >> n;     vector<int> cand(26, 1);     string t, w;     int f = 0, ans = 0;     for (int i = 0; i < n - 1; i++) {       cin >> t >> w;       if (f == 1) {         ans += (t ==  !  || t ==  ? );         continue;       }       if (t ==  ! ) {         vector<int> temp(26, 0);         for (char c : w) {           temp[c -  a ] = 1;         }         for (int i = 0; i < 26; i++) {           cand[i] = min(cand[i], temp[i]);         }       } else if (t ==  . ) {         for (char c : w) {           cand[c -  a ] = 0;         }       } else if (t ==  ? ) {         cand[w[0] -  a ] = 0;       }       if (!f) {         int ff = 0;         for (int i = 0; i < 26; i++) {           ff += (cand[i] > 0);         }         if (ff == 1) {           f = 1;         }       }     }     cout << ans << endl;     return 0;   }


#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;   }   int gcd(int n, int m) { return m == 0 ? n : gcd(m, n % m); }   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 << 1) + (x << 3) + (c ^ 48), c = getchar();     return x * f;   }   int n, m, k, a[5010], q[5010], head, tail;   long long f[5010][5010];   int main() {     n = read(), k = read(), m = read();     for (int i = 1; i <= n; i++) a[i] = read();     memset(f, 200, sizeof(f));     f[0][0] = 0;     for (int j = 1; j <= m; j++) {       head = 1, tail = 1;       q[1] = 0;       for (int i = 1; i <= n; i++) {         while (head < tail && q[head] < i - k) head++;         f[i][j] = f[q[head]][j - 1] + a[i];         while (head <= tail && f[q[tail]][j - 1] <= f[i][j - 1]) tail--;         q[++tail] = i;       }     }     for (int i = n - 1; i >= max(0, n - k + 1); i--)       f[n][m] = max(f[n][m], f[i][m]);     if (f[n][m] < 0)       cout << -1;     else       cout << f[n][m];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   char c[200005];   int dem[11];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int Tests;     cin >> Tests;     while (Tests--) {       cin >> s;       int n = s.size();       int pos = -1;       int cpos = 0;       memset(dem, 0, sizeof dem);       for (int i = 0; i < n; i++) {         for (int j = 0; j +  0  < s[i]; j++) {           if (i == 0 && j == 0) continue;           int cnt = 0;           dem[j] ^= 1;           for (int k = 0; k <= 9; k++) cnt += dem[k];           if (cnt + i + 1 <= n) {             pos = i + 1;             cpos = j;           }           dem[j] ^= 1;         }         dem[s[i] -  0 ] ^= 1;       }       if (pos == -1) {         for (int i = 1; i <= n - 2; i++) cout << 9;         cout <<   n ;       } else {         for (int i = 1; i <= n; i++) c[i] =  9 ;         memset(dem, 0, sizeof dem);         for (int i = 1; i < pos; i++) c[i] = s[i - 1], dem[c[i] -  0 ] ^= 1;         c[pos] = cpos +  0 ;         dem[c[pos] -  0 ] ^= 1;         int cur = n;         for (int i = 0; i <= 9; i++)           if (dem[i]) c[cur--] =  0  + i;         for (int i = 1; i <= n; i++) cout << c[i];         cout <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   void io() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   const int N = 1e5 + 5;   vector<int> g[N];   int sz[N], parent[N], done[N];   int lvl[N];   void dfs(int u, int p) {     sz[u] = 1;     for (int v : g[u]) {       if (done[v] || v == p) continue;       dfs(v, u);       sz[u] += sz[v];     }   }   int find_centroid(int u, int p, int total) {     for (int v : g[u]) {       if (done[v] || v == p) continue;       if (sz[v] + sz[v] > total) return find_centroid(v, u, total);     }     return u;   }   int centroid(int u, int p) {     dfs(u, 0);     int cnt = sz[u];     int center = find_centroid(u, 0, cnt);     done[center] = 1;     lvl[center] = lvl[p] + 1;     for (int v : g[center]) {       if (done[v]) continue;       parent[centroid(v, center)] = center;     }     return center;   }   int main() {     io();     int n;     cin >> n;     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     centroid(1, 0);     for (int i = 1; i <= n; i++) {       char c = lvl[i] +  A  - 1;       cout << c <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m, len;   int arr[110];   int brr[110];   int main() {     int i, j, k, t, a, b;     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m;     for (i = 0; i < m; i++) {       memset(arr, 0, sizeof(arr));       for (j = 0; j < n; j++) {         cin >> arr[j];       }       int winner = -1;       int maxz = -1;       for (j = 0; j < n; j++) {         if (arr[j] > maxz) {           maxz = arr[j];           winner = j;         }       }       brr[winner]++;     }     int winner = -1;     int maxz = -1;     for (i = 0; i < n; i++) {       if (brr[i] > maxz) {         maxz = brr[i];         winner = i;       }     }     cout << winner + 1 <<   n ;     return 0;   }