#include <bits/stdc++.h>   #define jh(x, y) (x ^= y ^= x ^= y)   #define loc(x, y) ((x - 1) * m + y)   #define lowbit(x) (x & -x)   typedef long long ll;   const int N = 5e5 + 5, INF = 0x3f3f3f3f, mod = 1e9 + 7;   const double PI = acos(-1), EPS = 1e-7;   using namespace std;   namespace fast_IO {    ll read() {     ll x = 0;     char c;     bool flag = false;     while ((c = getchar()) ==     || c ==   n  || c ==   r );     if (c ==  - )flag = true; else x = c ^ 48;     while ((c = getchar()) !=     && c !=   n  && c !=   r  && ~c)      x = (x << 1) + (x << 3) + (c ^ 48);     if (flag)return -x;     return x;    }    void write(ll x) {     if (x < 0)putchar( - ), x = -x;     if (x >= 10)write(x / 10);     putchar(x % 10 ^ 48);    }   }   char s[4];   bool tag[N];   int a[N], b[N], pre[N];   ll dp[N];   void print(int l, int r, int st, int m) {    if (l >= st) {     print(pre[l], l, st, m);     putchar( + );    }    printf( %d , b[l + 1]);    for (int i = l + 2; i <= r; ++i)     printf( *%d , b[i]);   }   void solve(int n) {    //既有*又有+    int m = n, st = 1;    while (m && b[m] == 1)--m;    while (st <= n && b[st] == 1)++st;    for (int i = 1; i < st; ++i) {     printf( 1 );     if (i != n)putchar( + );    }    if(st > n)return;    int sum = 1;    for (int i = st; i <= m; ++i)sum = min((m - st + 1) * 2, sum * b[i]);    if (sum == (m - st + 1) * 2) {     printf( %d , b[st]);     for (int i = st + 1; i <= m; ++i)      printf( *%d , b[i]);    }    else {     for (int i = st; i <= m; ++i)dp[i] = -1e17;     dp[st] = b[st]; pre[st] = st - 1;     dp[st - 1] = 0;     for (int i = st; i < m; ++i) {      if (b[i + 1] == 1)dp[i + 1] = dp[i] + 1, pre[i + 1] = i;      else {       ll mul = 1;       for (int j = i + 1; j >= st; --j) {        mul *= b[j];        if (dp[i + 1] < dp[j - 1] + mul) {         dp[i + 1] = dp[j - 1] + mul;         pre[i + 1] = j - 1;        }       }      }     }     print(pre[m], m, st, m);    }    for (int i = m + 1; i <= n; ++i)     printf( +1 );   }      int main() {    int n = fast_IO::read();    for (int i = 1; i <= n; ++i)a[i] = fast_IO::read();    scanf( %s , s);    for (int i = 0; s[i]; ++i)tag[s[i]] = true;    if (!s[1]) {     printf( %d , a[1]);     for (int i = 2; i <= n; ++i)      printf( %c%d , s[0], a[i]);    }    else if (!tag[ * ]) {     if (tag[ + ]) {      printf( %d , a[1]);      for (int i = 2; i <= n; ++i)       printf( +%d , a[i]);     }    }    else {     if (!tag[ + ]) {      printf( %d , a[1]);      for (int i = 2; i <= n; ++i) {       if (a[i] == 0) {        printf( -0 );        continue;       }       printf( *%d , a[i]);      }     }     else {      int now = 0;      for (int i = 1; i <= n; ++i) {       if (a[i] == 0) {        if (now)solve(now);        now = 0;        if (i != 1 && a[i - 1])putchar( + );        printf( 0 );        if (i != n)putchar( + );       }       else b[++now] = a[i];      }      if (now)solve(now);     }    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   const int K = 65;   const int inf = 1000 * 1000 * 1000;   const int mod = 1000 * 1000 * 1000 + 7;   int n, a[N], q;   int t[4 * N][K];   void build(int v, int s, int e) {     if (s == e) {       for (int i = 0; i < 60; i++) {         if (i % a[s] == 0)           t[v][i] = 2;         else           t[v][i] = 1;       }       return;     }     int m = (s + e) / 2;     build(2 * v, s, m);     build(2 * v + 1, m + 1, e);     for (int i = 0; i < 60; i++) {       int x = (i + t[2 * v][i]) % 60;       t[v][i] = t[2 * v][i] + t[2 * v + 1][x];     }   }   void update(int v, int s, int e, int pos) {     if (s == e) {       for (int i = 0; i < 60; i++) {         if (i % a[s] == 0)           t[v][i] = 2;         else           t[v][i] = 1;       }       return;     }     int m = (s + e) / 2;     if (pos <= m)       update(2 * v, s, m, pos);     else       update(2 * v + 1, m + 1, e, pos);     for (int i = 0; i < 60; i++) {       int x = (i + t[2 * v][i]) % 60;       t[v][i] = t[2 * v][i] + t[2 * v + 1][x];     }   }   int get(int v, int s, int e, int l, int r, int st) {     if (l > r) return -1;     if (s == l && e == r) return t[v][st];     int m = (s + e) / 2;     int answ = 0;     int T = get(2 * v, s, m, l, min(r, m), st);     if (T == -1)       T = st;     else {       answ += T;       T += st;     }     int P = get(2 * v + 1, m + 1, e, max(m + 1, l), r, T % 60);     if (P != -1) answ += P;     return answ;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     a[n + 1] = 1;     build(1, 1, n + 1);     scanf( %d , &q);     while (q--) {       char x;       int aa, b;       cin >> x;       scanf( %d%d , &aa, &b);       if (x ==  A ) {         int T = get(1, 1, n + 1, aa, b - 1, 0);         printf( %d n , T);       } else {         a[aa] = b;         update(1, 1, n + 1, aa);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long a[100002];   long b[100002];   long s[100002];   long l[100002];   vector<int> br0, br1;   map<int, vector<int> > fre, an;   const int MAXN = 100001;   int comp = 0;   vector<int> g[MAXN], h[MAXN];   bool used[MAXN];   int timer, tin[MAXN], fup[MAXN], col[MAXN];   int n, ans = 0;   void IS_BRIDGE(int i, int j) {     br0.push_back(i);     br1.push_back(j);   }   void dfs(int v, int p = -1) {     used[v] = true;     tin[v] = fup[v] = timer++;     for (size_t i = 0; i < g[v].size(); ++i) {       int to = g[v][i];       if (to == p) continue;       if (used[to])         fup[v] = min(fup[v], tin[to]);       else {         dfs(to, v);         fup[v] = min(fup[v], fup[to]);         if (fup[to] > tin[v]) IS_BRIDGE(v, to);       }     }   }   void find_bridges() {     timer = 0;     for (int i = 0; i < n; ++i) used[i] = false;     for (int i = 0; i < n; ++i)       if (!used[i]) dfs(i);   }   void dfs_h(int i) {     used[i] = 1;     col[i] = comp;     for (int j = 0; j < fre[i].size(); j++)       if (!used[fre[i][j]]) dfs_h(fre[i][j]);   }   void dfs_k(int i, int dl, int z) {     used[i] = 1;     for (int j = 0; j < an[i].size(); j++)       if (an[i][j] == z) {         ans += dl + 1;       } else if (!used[an[i][j]])         dfs_k(an[i][j], dl + 1, z);   }   int main() {     int m, k, c;     cin >> n >> m;     for (int i = 1; i <= m; i++) {       cin >> a[i] >> b[i];       g[a[i]].push_back(b[i]);       g[b[i]].push_back(a[i]);     }     cin >> k;     for (int i = 1; i <= k; i++) cin >> s[i] >> l[i];     find_bridges();     for (int i = 1; i <= n; i++)       for (int j = 0; j < g[i].size(); j++) {         bool OK = 0;         for (int k = 0; k < br0.size(); k++) {           if (((br0[k] == i) && (br1[k] == g[i][j])) ||               ((br1[k] == i) && (br0[k] == g[i][j])))             OK = 1;         }         if (!OK) {           fre[i].push_back(g[i][j]);           fre[g[i][j]].push_back(i);         }       }     for (int i = 1; i <= n; i++) used[i] = 0;     for (int i = 1; i <= n; i++)       if (!used[i]) {         comp++;         dfs_h(i);       }     for (int k = 0; k < br0.size(); k++) {       an[col[br0[k]]].push_back(col[br1[k]]);       an[col[br1[k]]].push_back(col[br0[k]]);     }     for (int i = 1; i <= k; i++) {       if (col[s[i]] == col[l[i]])         cout << 0 << endl;       else {         for (int j = 1; j <= n; j++) used[j] = 0;         ans = 0;         dfs_k(col[s[i]], 0, col[l[i]]);         cout << ans << endl;       }     }   }


#include <bits/stdc++.h>   int main(int argc, const char* argv[]) {     int n, x;     std::cin >> n >> x;     std::vector<int> v(n);     for (int i = 0; i < n; i++) std::cin >> v[i];     std::sort(v.begin(), v.end());     for (int i = 0; i < n; i++) {       if (v[i] > x) {         std::cout << x - i << std::endl;         return 0;       } else if (v[i] == x) {         std::cout << x - i + 1 << std::endl;         return 0;       }     }     std::cout << x - v.size() << std::endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   const long long inf = (long long)1e9;   double PI = 3.14159265;   double eps = 1e-9;   long long t = 0;   long long pow(long long a, long long b) {     if (b == 0) return 1;     if (b % 2 == 1) {       return (pow(a, b - 1) * a);     }     if (b % 2 == 0) {       long long c = pow(a, b / 2);       return (c * c);     }   }   vector<pair<long long, long long>> reb;   long long dp[1 << 17];   long long krask[1 << 17];   vector<vector<long long>> g;   vector<long long> dep;   vector<vector<long long>> p;   vector<vector<long long>> dep2;   vector<long long> u;   vector<long long> tin, tout;   void dfs(long long v, long long k) {     tin[v] = t++;     p[v][0] = k;     for (long long i = 1; i < 20; i++) {       p[v][i] = p[p[v][i - 1]][i - 1];     }     for (long long i = 0; i < g[v].size(); i++) {       long long to = g[v][i];       if (dep[to] == -1) {         dep[to] = dep[v] + 1;         dep2[dep[to]].push_back(t);         dfs(to, v);       }     }     tout[v] = t;   }   long long parent(long long v, long long h) {     for (long long i = 0; i < 20; i++) {       if ((h & (1 << i))) {         v = p[v][i];       }     }     return v;   }   long long lca(long long a, long long b) {     if (dep[a] < dep[b]) swap(a, b);     a = parent(a, dep[a] - dep[b]);     if (a == b) return a;     for (long long i = 19; i >= 0; i--) {       if (p[a][i] != p[b][i]) {         a = p[a][i];         b = p[b][i];       }     }     return parent(a, 1);   }   struct stree {     vector<long long> t;     int n;     stree(vector<long long> a) {       n = 1;       while (n < a.size()) {         n *= 2;       }       t.resize(n + n);       for (int i = n; i < n + a.size(); i++) {         t[i] = a[i - n];       }       for (int i = n - 1; i > 0; i--) {         t[i] = t[i + i] + t[i + i + 1];       }     }     long long sum(long long l, long long r) {       long long sum = 0;       for (l += n, r += n; l <= r; l /= 2, r /= 2) {         if (l % 2 == 1) {           sum += t[l++];         }         if (r % 2 == 0) {           sum += t[r--];         }       }       return sum;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, q;     cin >> n >> q;     vector<long long> a;     a.resize(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     stree d(a);     vector<long long> k;     k.resize(q);     long long gl = 0;     int pred = 0;     for (int i = 0; i < q; i++) {       cin >> k[i];       long long r = a.size(), l = gl - 1;       while (r - l > 1) {         long long mid = (l + r) / 2;         long long sum = d.sum(gl, mid);         if (sum > k[i] + pred)           r = mid;         else {           l = mid;         }       }       if (r == a.size()) {         gl = 0;         pred = 0;       } else {         if (k[i] + pred < d.sum(gl, r - 1)) {           pred = k[i] + pred;         } else {           pred = k[i] + pred - d.sum(gl, r - 1);           gl = r;         }       }       cout << a.size() - gl << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a1, b1, a2, b2, a3, b3;     cin >> a1 >> b1 >> a2 >> b2 >> a3 >> b3;     int l1 = min(a1, b1);     int l2 = min(a2, b2);     int l3 = min(a3, b3);     int L1 = max(a1, b1);     int L2 = max(a2, b2);     int L3 = max(a3, b3);     if (l2 + l3 <= l1 && max(L2, L3) <= L1)       cout <<  YES             <<   n ;     else if (l2 + l3 <= L1 && max(L2, L3) <= l1)       cout <<  YES             <<   n ;     else if (L2 + L3 <= l1 && max(l2, l3) <= L1)       cout <<  YES             <<   n ;     else if (L2 + L3 <= L1 && max(l2, l3) <= l1)       cout <<  YES             <<   n ;     else if (L2 + l3 <= L1 && max(l2, L3) <= l1)       cout <<  YES             <<   n ;     else if (l2 + L3 <= L1 && max(L2, l3) <= l1)       cout <<  YES             <<   n ;     else       cout <<  NO             <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 100;   const long long M = 21;   const long long mod = 1e9 + 7;   const long long MOD = 998244353;   const long long P = 1336;   const long double eps = 0.000000001;   const long long inf = 1e16 + 7;   mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());   vector<pair<long long, long long> > g[N], ng[N];   long long sz[N], pr[N], tin[N], tout[N];   long long tim = 0;   pair<long long, long long> w[N][M];   long long r[N];   long long get(long long v) {     if (pr[v] == v) return v;     return pr[v] = get(pr[v]);   }   void unite(long long a, long long b) {     a = get(a);     b = get(b);     if (a == b) return;     if (sz[a] < sz[b]) swap(a, b);     sz[a] += sz[b];     pr[b] = a;   }   void DFS(long long v, long long pr, long long zn) {     w[v][0].first = pr;     w[v][0].second = zn;     for (long long i = 1; i < M; i++) {       w[v][i].first = w[w[v][i - 1].first][i - 1].first;       w[v][i].second =           max(w[v][i - 1].second, w[w[v][i - 1].first][i - 1].second);     }     tim++;     tin[v] = tim;     for (auto to : ng[v]) {       if (to.first == pr) continue;       DFS(to.first, v, to.second);     }     tim++;     tout[v] = tim;   }   bool upper(long long a, long long b) {     return ((tin[a] <= tin[b]) && (tout[a] >= tout[b]));   }   long long LCA(long long a, long long b) {     if (upper(b, a)) swap(a, b);     long long mx = 0;     for (long long i = M - 1; i >= 0; i--) {       if (!upper(w[b][i].first, a)) {         mx = max(mx, w[b][i].second);         b = w[b][i].first;       }     }     mx = max(mx, w[b][0].second);     b = w[b][0].first;     for (long long i = M - 1; i >= 0; i--) {       if (!upper(w[a][i].first, b)) {         mx = max(mx, w[a][i].second);         a = w[a][i].first;       }     }     if (a != b) mx = max(mx, w[a][0].second);     return mx;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     srand(time(0));     long long n, m, k, T;     cin >> n >> m >> k >> T;     for (long long i = 0; i < m; i++) {       long long x, y, z;       cin >> x >> y >> z;       x--;       y--;       g[x].push_back({y, z});       g[y].push_back({x, z});     }     for (long long i = 0; i < n; i++) {       r[i] = inf;     }     priority_queue<pair<long long, long long> > q;     for (long long i = 0; i < k; i++) {       q.push({0, i});     }     while (!q.empty()) {       long long v = q.top().second;       long long ra = q.top().first;       ra = -ra;       q.pop();       if (ra > r[v]) continue;       r[v] = ra;       for (auto to : g[v]) {         if (r[to.first] > r[v] + to.second) {           r[to.first] = r[v] + to.second;           q.push({-r[to.first], to.first});         }       }     }     vector<pair<long long, pair<long long, long long> > > e;     for (long long i = 0; i < n; i++) {       for (auto to : g[i]) {         e.push_back({r[i] + r[to.first] + to.second, {i, to.first}});       }     }     for (long long i = 0; i < n; i++) {       pr[i] = i;       sz[i] = 1;     }     sort(e.begin(), e.end());     for (auto to : e) {       if (get(to.second.first) != get(to.second.second)) {         unite(to.second.first, to.second.second);         ng[to.second.first].push_back({to.second.second, to.first});         ng[to.second.second].push_back({to.second.first, to.first});       }     }     DFS(0, 0, 0);     while (T--) {       long long a, b;       cin >> a >> b;       a--;       b--;       cout << LCA(a, b) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   const int INF = (((1 << 30) - 1) << 1) + 1;   const int nINF = 1 << 31;   string s;   int main() {     ios::sync_with_stdio(false);     cin >> s;     int n = s.size();     int open, close, q, ans = 0;     for (int i = 0; i < (n); i++) {       open = 0, close = 0, q = 0;       for (int j = (i); j <= (n - 1); j++) {         if (s[j] ==  ( )           ++open;         else if (s[j] ==  ) )           ++close;         else {           ++close;           ++q;         }         if (close > open) {           if (q) {             --q;             ++open;             --close;           } else             break;         }         if ((i - j + 1) % 2 == 0 && open == close) {           ++ans;         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long n, k;     string x;     cin >> n >> k >> x;     string ans =   ;     int o = -1;     for (int i = 1; i < x.size(); i++) {       if (x.substr(i, x.size() - i) == x.substr(0, x.size() - i)) {         o = i;         break;       }     }     if (o == -1) {       for (int i = 0; i < k; i++) {         cout << x;       }     } else {       for (int i = 0; i < k; i++) {         cout << x.substr(0, o);       }       cout << x.substr(o, x.size() - o);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using lli = long long;   using lld = long double;   using ulli = unsigned long long int;   using pll = pair<lli, lli>;   using ttt = pair<lli, pll>;   using vttt = vector<ttt>;   using vll = vector<pll>;   using vl = vector<lli>;   using vi = vector<int>;   using vvi = vector<vector<int>>;   using cd = complex<lld>;   const double PI = acos(-1);   vvi adj, dist;   pll get(vi vect) {     cout <<  ?   << ((lli)(vect).size());     for (auto& x : vect) cout <<     << x;     cout <<   n ;     cout.flush();     pll ans;     cin >> ans.first >> ans.second;     return ans;   }   void dfs(int v, int p, int dis) {     dist[dis].push_back(v);     for (auto& x : adj[v])       if (x != p) {         dfs(x, v, dis + 1);       }   }   pll check(int val) {     if (dist[val].empty()) return {1000000007, 1000000007};     return get(dist[val]);   }   int tejas_919(int kkkk) {     lli n, m, k, q, u, v, temp = 0, ans = 0;     cin >> n;     adj = vvi(n + 2);     dist = vvi(n + 2);     for (int i = 1; i < n; i++) {       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     int root, pdist;     {       vi vect;       for (int i = 1; i < n + 1; i++) vect.push_back(i);       tie(root, pdist) = get(vect);     }     dfs(root, root, 0);     int l = (pdist + 1) / 2, r = pdist, cdis;     root = -1;     while (l <= r) {       int mid = (l + r) / 2;       tie(temp, cdis) = check(mid);       if (cdis == pdist) {         l = mid + 1;         root = temp;       } else         r = mid - 1;     }     if (root < 0) root = get(dist[l - 1]).first;     dist = vvi(n + 2);     dfs(root, root, 0);     ans = get(dist[pdist]).first;     cout <<  !   << root <<     << ans <<   n ;     cout.flush();     string s;     cin >> s;     return 0;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout << fixed << setprecision(10);     int t = 1;     cin >> t;     for (int i = 0; i < t; i++) {       tejas_919(i + 1);     }     {};   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   const int N = 325;   int n, s[N], sum[26][N], vc;   bitset<N> b[N];   char ans[N];   void addv(int s, int e) {     int flag = 0;     for (int i = s - 1, j = e - 1; i <= j; i++, j--) {       if (!flag) {         b[vc].reset();         flag = 1;       } else         b[vc] = b[vc - 1];       for (int k = i; k <= j; k++) b[vc].flip(k);       vc++;     }   }   int ref() {     int c = 0;     for (int i = 0; i < n; i++) {       for (int j = c + 1; j < vc; j++)         if (b[j][i]) {           swap(b[j], b[c]);           break;         }       if (!b[c][i]) continue;       for (int j = c + 1; j < vc; j++)         if (b[j][i]) b[j] ^= b[c];       c++;     }     if (c == n) {       for (int i = n - 1; i >= 0; i--) {         for (int j = 0; j < i; j++)           if (b[j][i]) b[j] ^= b[i];       }     }     return c;   }   void ask(int s, int e) {     printf( ? %d %d n , s, e);     fflush(stdout);     int cnt = (e - s + 1) * (e - s + 2) / 2;     char buf[N];     while (cnt--) {       scanf( %s , buf);       int k = strlen(buf);       if (k > (e - s + 2) / 2) continue;       for (int i = 0; i < k; i++) {         sum[buf[i] -  a ][vc + k - 1] ^= 1;       }     }     vc += (e - s + 2) / 2;   }   int main() {     cin >> n;     int aa, bb, cc;     int ra, rb, rc;     srand(time(0));     while (true) {       aa = rand() % n + 1;       bb = rand() % n + 1;       cc = rand() % n + 1;       if (aa * (aa + 1) / 2 + bb * (bb + 1) / 2 + cc * (cc + 1) / 2 >           ceil(0.777 * (n + 1) * (n + 1)) - 1)         continue;       ra = 1;       rb = rand() % (n - bb + 1) + 1;       rc = n - cc + 1;       vc = 0;       addv(ra, ra + aa - 1);       addv(rb, rb + bb - 1);       addv(rc, rc + cc - 1);       int ttt = ref();       if (ttt == n) break;     }     vc = 0;     ask(ra, ra + aa - 1);     ask(rb, rb + bb - 1);     ask(rc, rc + cc - 1);     for (int i = 0; i < 26; i++) {       vc = 0;       addv(ra, ra + aa - 1);       addv(rb, rb + bb - 1);       addv(rc, rc + cc - 1);       for (int j = 0; j < vc; j++) b[j][n] = sum[i][j];       ref();       for (int j = 0; j < n; j++)         if (b[j][n]) ans[j] = i +  a ;     }     printf( ! %s n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   using vec = vector<T>;   template <typename Iter>   ostream &_IterOutput_(ostream &o, Iter b, Iter e, const string ss =   ,                         const string se =   ) {     o << ss;     for (auto it = b; it != e; it++) o << (it == b ?    :  ,  ) << *it;     return o << se;   }   template <typename T1, typename T2>   ostream &operator<<(ostream &o, const pair<T1, T2> &pair) {     return o <<  (  << pair.first <<  ,   << pair.second <<  ) ;   }   template <typename T>   ostream &operator<<(ostream &o, const vector<T> &vec) {     return _IterOutput_(o, begin(vec), end(vec),  [ ,  ] );   }   template <typename T>   ostream &operator<<(ostream &o, const set<T> &st) {     return _IterOutput_(o, begin(st), end(st),  { ,  } );   }   template <typename T, size_t N>   ostream &operator<<(ostream &o, const array<T, N> &arr) {     return _IterOutput_(o, begin(arr), end(arr),  | ,  | );   }   template <typename T1, typename T2>   ostream &operator<<(ostream &o, const map<T1, T2> &mp) {     o <<  { ;     for (auto it = mp.begin(); it != mp.end(); it++) {       o << (it == mp.begin() ?    :  ,  ) << it->first <<  :  << it->second;     }     o <<  } ;     return o;   }   using A3 = array<long long, 3>;   inline long long get(long long x, long long i) {     return (x & (63LL << (i * 6))) >> (i * 6);   }   inline long long se(long long x, long long i, long long w) {     long long sh = (i * 6);     (x &= ~(63LL << sh)) ^= w << sh;     return x;   }   inline long long del(long long x, long long i) {     long long sh = i * 6;     long long rm = x & ((1LL << sh) - 1);     ((x >>= sh + 6) <<= sh) |= rm;     return x;   }   A3 dec(long long x) { return {x & 3, (x >> 2) & 3, (x >> 4) & 3}; }   inline long long enc(A3 a) {     if (a[2] > a[0]) swap(a[2], a[0]);     return a[0] + (a[1] << 2) + (a[2] << 4);   }   unordered_map<long long, double> mem;   const double INF = 1e9;   long long norm(long long x) {     static long long Z[30];     long long i = 1, p;     for (; p = get(x, i); i++) {       Z[i] = p;     }     sort(Z + 1, Z + i);     for (long long j = 1; j < i; j++) {       x = se(x, j, Z[j]);     }     return x;   }   long long zz = 0;   double dp(long long st) {     if (mem.count(st)) return mem[st];     double ex[4] = {0, INF, INF, INF};     for (long long i = 1, p; p = get(st, i); i++) {       auto a = dec(p);       if (!a[1] or (!a[0] and !a[2])) continue;       for (long long j = 0; j < 3; j++) {         if (!a[j]) continue;         if (a[2] == 0 and j == 1) continue;         long long cl = a[j];         auto b = a;         b[j] = 0;         long long nx;         if (!b[1] or (!b[0] and !b[2])) {           nx = del(st, i);         } else {           nx = se(st, i, enc(b));         }         long long top = get(nx, 0);         auto c = dec(top);         if (c[0] and c[1] and c[2]) {           top <<= 6;           nx <<= 6;           c = dec(top);         }         for (long long k = 0; k < 3; k++)           if (!c[k]) {             auto d = c;             d[k] = cl;             long long fn = norm(se(nx, 0, enc(d)));             ex[cl] = min(ex[cl], dp(fn));           }       }     }     if (ex[1] >= INF and ex[2] >= INF and ex[3] >= INF) {       return (mem[st]) = 0;     } else {       double zzprob = 1.0 / 6;       if (ex[1] == INF) zzprob += 1.0 / 6, ex[1] = 0;       if (ex[2] == INF) zzprob += 2.0 / 6, ex[2] = 0;       if (ex[3] == INF) zzprob += 2.0 / 6, ex[3] = 0;       (mem[st]) = (ex[1] * 1.0 / 6 + ex[2] * 2.0 / 6 + ex[3] * 2.0 / 6 + 1) /                   (1.0 - zzprob);       return (mem[st]);     }   }   int32_t main() {     do {       ios_base::sync_with_stdio(0);       cin.tie(0);     } while (0);     long long N;     cin >> N;     cout << fixed << setprecision(10);     long long t = 0;     for (long long i = 0; i < N; i++) {       string s;       cin >> s;       A3 a;       for (long long j = 0; j < 3; j++) {         long long z = s[j] ==  R  ? 1 : s[j] ==  G  ? 2 : 3;         a[j] = z;       }       (t <<= 6) += enc(a);     }     cout << dp(t) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f;   int main() {     int T;     cin >> T;     while (T--) {       int b, p, f, h, c;       cin >> b >> p >> f >> h >> c;       int ans = 0;       for (int i = 0; i <= p; ++i) {         int num1 = min(i, b / 2);         int num2 = min(f, (b - num1 * 2) / 2);         ans = max(ans, num1 * h + num2 * c);       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   stringstream output;   inline void eOP();   inline void solve() {     int n, x, y;     cin >> n >> x >> y;     string s;     cin >> s;     char p =  1 ;     long long cnt = 0;     for (char c : s) {       if (p ==  1  && c ==  0 ) {         ++cnt;       }       p = c;     }     long long result = 0;     if (cnt) {       result += y;       --cnt;     }     result += cnt * (min(x, y));     output << result;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     size_t t = 1;     for (int i = 0; i < t; ++i) {       solve();     }     eOP();   }   inline void eOP() {     cout << output.str();     output.str(string());     exit(0);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<pair<int, int> > v;     int n, i, c = 1, ans = 0;     vector<pair<int, int> >::iterator it;     cin >> n;     for (i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       v.push_back(make_pair(y, x));     }     sort(v.begin(), v.end());     for (i = n - 1; i >= 0; i--) {       if (c == 0) {         break;       }       c = c - 1 + v[i].first;       ans = ans + v[i].second;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   double x[101010], y[101010];   double maxn[101010], minn[101010];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lf , &maxn[i]);     for (int i = 1; i <= n; i++) scanf( %lf , &minn[i]);     for (int i = n - 1; i >= 1; i--) minn[i] += minn[i + 1];     double resx = 1, resy = 1, getx = 0, gety = 0;     maxn[0] = 0;     bool key = false;     for (int i = 1; i < n; i++) {       maxn[i] += maxn[i - 1];       double k1 = maxn[i];       double k2 = minn[i];       double a = 0, b = 0, c = 0;       a += 1;       b += minn[i + 1] - maxn[i] - 1;       c += maxn[i];       double det = b * b - 4 * a * c;       if (det < 0) {         if (det < -0.01) {           printf( %.3f-- n , det);           key = true;         }         det = 0;       }       double ans1 = (-b + sqrt(det)) / (2 * a);       double ans2 = (-b - sqrt(det)) / (2 * a);       x[i] = ans1;       y[i] = ans2;     }     y[n] = x[n] = 1;     for (int i = n; i >= 1; i--) {       x[i] = x[i] - x[i - 1];       y[i] -= y[i - 1];     }     for (int i = 1; i <= n; i++) {       printf( %.8f , y[i]);       if (i == n)         printf(  n );       else         printf(   );     }     for (int i = 1; i <= n; i++) {       printf( %.8f , x[i]);       if (i == n)         printf(  n );       else         printf(   );     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e5 + 10;   long long arr[MAX];   int cur[MAX], want[MAX];   int n;   vector<vector<int> > adj(MAX);   long long ans = 0;   array<int, 2> dfs(int node, int par, long long Min) {     array<int, 2> a, b;     a[0] = 0, a[1] = 0;     if (cur[node] != want[node]) a[cur[node]]++;     for (auto &child : adj[node]) {       if (child == par) continue;       b = dfs(child, node, min(Min, arr[node]));       a[0] += b[0], a[1] += b[1];     }     if (arr[node] < Min) {       int x = min(a[0], a[1]);       ans += x * 2ll * arr[node];       a[0] -= x, a[1] -= x;     }     return a;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; ++i) cin >> arr[i] >> cur[i] >> want[i];     for (int i = 0; i < n - 1; ++i) {       int x, y;       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     array<int, 2> a = dfs(1, -1, 2e9);     if (a[0] || a[1])       cout << -1 <<   n ;     else       cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     long long x, id;   } a[200005];   long long st[200005], top;   bool cmp(node a, node b) { return a.x < b.x; }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long T;     cin >> T;     while (T--) {       top = 0;       long long n, w, sum = 0;       cin >> n >> w;       for (long long i = 1; i <= n; i++) {         cin >> a[i].x;         a[i].id = i;       }       for (long long i = 1; i <= n; i++) {         if ((w + 1) / 2 <= a[i].x && a[i].x <= w) {           cout <<  1 n  << i <<   n ;           goto loop;         }       }       sort(a + 1, a + n + 1, cmp);       while (a[n].x >= w) {         n--;       }       for (long long i = n; i >= 1; i--) {         if (sum + a[i].x <= w) {           sum += a[i].x;           st[++top] = a[i].id;         }         if ((w + 1) / 2 <= sum) {           cout << top <<   n ;           for (long long i = 1; i <= top; i++) {             cout << st[i] <<    ;           }           cout <<   n ;           goto loop;         }       }       cout <<  -1 n ;     loop:;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     unsigned long long i, j, k, l, r, n, m;     scanf( %llu , &l);     scanf( %llu , &r);     scanf( %llu , &k);     j = k;     n = ceil(log(l) / (double)log(k));     unsigned long long chq = 0;     chq = max(chq, (unsigned long long)(floor(log(r) / (double)log(k))));     if (chq < n) {       puts( -1 );       return 0;     }     k = pow(j, n);     bool ok = false;     for (i = n; i <= chq; i++) {       if (k > r) break;       ok = true;       printf( %llu , k);       printf(   );       ;       k *= j;     }     if (k == r) printf( %llu , k);     if (!ok) printf( -1 );     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   char f;   string tas[1000], mas;   long a, b, kol, m, n, pos, mi, ma, nn, kola, kolb;   double k;   long long ans;   int main() {     cin >> mas;     for (int a = 0; a < (10); a++) cin >> tas[a];     for (int a = 0; a < (8); a++) {       for (int b = 0; b < (10); b++) {         if (mas.substr(a * 10, 10) == tas[b]) cout << b;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, k, l;       cin >> n >> k >> l;       vector<int> d(n + 1), safe = {0};       for (int i = 1; i <= n; ++i) {         cin >> d[i];         if (d[i] + k <= l) safe.push_back(i);       }       safe.push_back(n + 1);       bool ok = true;       for (size_t i = 1; i < safe.size() && ok; ++i) {         int tide = k;         bool down = true;         for (int j = safe[i - 1] + 1; j < safe[i]; ++j) {           tide += down ? -1 : +1;           if (down) tide -= max(0, d[j] + tide - l);           if (tide < 0 || d[j] + tide > l) {             ok = false;             break;           }           if (tide == 0) down = false;         }       }       if (ok)         cout <<  Yes n ;       else         cout <<  No n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a = 0, b = 0, x = 0, y = 0;     cin >> a >> b;     x = min(a, b);     y = max(a, b);     cout << x <<     << (y - x) / 2 << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   const int INF = (int)1e9;   const long long LINF = (long long)1e18;   const long double PI = acos((long double)-1);   const long double EPS = 1e-9;   inline long long gcd(long long a, long long b) {     long long r;     while (b) {       r = a % b;       a = b;       b = r;     }     return a;   }   inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   inline long long fpow(long long n, long long k, int p = MOD) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   template <class T>   inline int chkmin(T& a, const T& val) {     return val < a ? a = val, 1 : 0;   }   template <class T>   inline int chkmax(T& a, const T& val) {     return a < val ? a = val, 1 : 0;   }   template <class T>   inline T isqrt(T k) {     T r = sqrt(k) + 1;     while (r * r > k) r--;     return r;   }   template <class T>   inline T icbrt(T k) {     T r = cbrt(k) + 1;     while (r * r * r > k) r--;     return r;   }   inline void addmod(int& a, int val, int p = MOD) {     if ((a = (a + val)) >= p) a -= p;   }   inline void submod(int& a, int val, int p = MOD) {     if ((a = (a - val)) < 0) a += p;   }   inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }   inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }   void solve() {     long long r, h;     cin >> r >> h;     long double rr = r, hh = h;     long long ans = 0;     if (2 * h >= r) {       long long tmp = (long long)floor((hh - rr / 2) / rr + EPS) + 1;       long double z = hh - rr / 2 - tmp * rr;       chkmax(ans, 2 * tmp);       if (z >= rr * (sqrt(3) / 2 - 0.5) - EPS) {         chkmax(ans, 2 * tmp + 1);       }     }     hh += rr * (1 - sqrt(3) / 2);     long long tmp = (long long)floor(hh / rr + EPS);     long double z = hh - tmp * rr;     chkmax(ans, 2 * tmp + 1);     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O999 )   using namespace std;   int main() {     ios::sync_with_stdio(0);     cout <<  INTERCAL ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     cin >> n >> m;     int mn = min(n, m);     if (mn % 2 == 0) {       cout <<  Malvika ;     } else {       cout <<  Akshat ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, o[1010][1010], a[1010][1010], b[1010][1010], siza[1010], sizb[1010];   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         scanf( %d , &o[i][j]);         a[i][j] = b[j][i] = o[i][j];       }     }     for (int i = 0; i < n; i++) {       sort(a[i], a[i] + m);       siza[i] = unique(a[i], a[i] + m) - a[i];     }     for (int i = 0; i < m; i++) {       sort(b[i], b[i] + n);       sizb[i] = unique(b[i], b[i] + n) - b[i];     }     int x, y;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         x = lower_bound(a[i], a[i] + siza[i], o[i][j]) - a[i];         y = lower_bound(b[j], b[j] + sizb[j], o[i][j]) - b[j];         printf( %d  , max(x, y) + max(siza[i] - x, sizb[j] - y));       }       putchar(  n );     }     return 0;   }


#include <bits/stdc++.h>   const long long MOD = 1e9 + 7;   using namespace std;   long long n, u, v, ans, dp[100005], cntt[100005];   vector<vector<long long> > g(100005);   bool used[100005];   long long bpow(long long x, long long p) {     if (p == 0) return 1;     long long cur = bpow(x, p >> 1);     cur = (cur * cur) % MOD;     if (p & 1) cur = (cur * x) % MOD;     return cur;   }   void countDp(long long x) {     used[x] = true;     long long cans = 1, cnt = 0;     ;     for (int i = 0; i < g[x].size(); i++) {       if (!used[g[x][i]]) {         countDp(g[x][i]);         cnt++;         cans = (cans * dp[g[x][i]]) % MOD;       }     }     if (cnt != 0) cans = (2 * cans) % MOD;     cntt[x] = cnt;     dp[x] = cans;   }   void countAns(long long x, long long mlt, bool root) {     used[x] = true;     if (!root && cntt[x] == 0) {       dp[x] = (dp[x] * 2) % MOD;     }     dp[x] = (dp[x] * mlt) % MOD;     ans = (ans + dp[x]) % MOD;     for (int i = 0; i < g[x].size(); i++) {       if (!used[g[x][i]]) {         if (root && cntt[x] == 1)           countAns(               g[x][i],               (((dp[x] * bpow(dp[g[x][i]], MOD - 2)) % MOD) * bpow(2, MOD - 2)) %                   MOD,               0);         else           countAns(g[x][i], (dp[x] * bpow(dp[g[x][i]], MOD - 2)) % MOD, 0);       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 0; i < n - 1; i++) {       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     countDp(1);     for (int i = 1; i <= n; i++) {       used[i] = false;     }     countAns(1, 1, 1);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   template <class T>   T gcd(T a, T b) {     while (a && b)       if (a > b)         a %= b;       else         b %= a;     return a + b;   }   using namespace std;   long long k, n[3], t[3], ans[11111][3], i, j;   int main() {     cin >> k >> n[0] >> n[1] >> n[2] >> t[0] >> t[1] >> t[2];     for (i = 0; i < k; i++)       for (j = 0; j < 3; j++) {         if (i == 0 && j == 0)           ans[i][j] = t[0];         else if (i == 0)           ans[i][j] = ans[i][j - 1] + t[j];         else if (i < n[j])           if (j == 0)             ans[i][j] = t[j];           else             ans[i][j] = ans[i][j - 1] + t[j];         else if (j == 0)           ans[i][j] = ans[i - n[j]][j] + t[j];         else           ans[i][j] = max(ans[i - n[j]][j] + t[j], ans[i][j - 1] + t[j]);       }     cout << ans[k - 1][2];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int mod = 1e9 + 7;   long long int casei(long long int tc) {     long long int n, i, trn = 1, fct = 1;     cin >> n;     for (i = 1; i <= n; i++) {       if (i < n) trn *= 2;       fct *= i;       trn %= mod;       fct %= mod;     }     long long int ans = fct - trn;     if (ans < 0) ans += mod;     cout << ans <<   n ;     return 0;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int tc, x;     tc = 1;     while (tc--) casei(x - tc);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int N = 5e3 + 5;   int n, vis[26][26][N];   string s;   long double ans;   int main() {     ios::sync_with_stdio(0);     cout << fixed << setprecision(12);     cin >> s;     n = s.size();     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) vis[s[0] -  a ][s[j] -  a ][j]++;       s.push_back(s.front());       s.erase(s.begin());     }     for (int i = 0; i < 26; i++) {       int mx = 0;       for (int j = 0; j < n; j++) {         int cnt = 0;         for (int k = 0; k < 26; k++) {           cnt += (vis[i][k][j] == 1);         }         mx = max(mx, cnt);       }       ans += mx;     }     cout << ans / (long double)n;     return 0;   }


#include <bits/stdc++.h>   int main() {     long long t = 1;     scanf( %lld , &t);     while (t--) {       long long n, a = 0;       scanf( %lld , &n);       while (n > 0) {         int r = n % 2;         if (r == 1) a++;         n = n / 2;       }       long long ans = pow(2, a);       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 7;   pair<int, int> edges[N];   int type[N];   bool inv[N];   vector<int> e[N];   int vis[N];   int used[N];   inline int other(int id, int u) {     return edges[id].first == u ? edges[id].second : edges[id].first;   }   int ans1 = 0, ans2 = 0;   void dfs(int u) {     vis[u] = 1;     ans1++;     for (int ed : e[u]) {       int v = other(ed, u);       if (!vis[v]) {         used[ed] = v;         dfs(v);       }     }   }   void dfs2(int u) {     vis[u] = 1;     ans2++;     for (int ed : e[u]) {       int v = other(ed, u);       if (!vis[v]) {         if (type[ed] == 1) {           dfs2(v);         } else {           used[ed] = v;         }       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m, s;     cin >> n >> m >> s;     for (int i = 0; i < m; ++i) {       int t, u, v;       cin >> t >> u >> v;       type[i] = t;       edges[i] = pair<int, int>(u, v);       if (t == 1)         e[u].push_back(i);       else {         e[u].push_back(i);         e[v].push_back(i);       }     }     dfs(s);     cout << ans1 << endl;     for (int i = 0; i < m; ++i) {       if (type[i] == 2) {         if (used[i] == other(i, edges[i].first))           cout <<  + ;         else           cout <<  - ;       }     }     cout << endl;     memset(vis, 0, sizeof vis);     memset(used, 0, sizeof used);     dfs2(s);     cout << ans2 << endl;     for (int i = 0; i < m; ++i) {       if (type[i] == 2) {         if (used[i] == other(i, edges[i].first))           cout <<  - ;         else           cout <<  + ;       }     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const int INF = 0x3f3f3f3f;   const int MOD = 1e9 + 7;   const double EPS = 1e-9;   int n, a[100015];   int main() {     scanf( %d , &n);     if (n % 4) {       printf( ! -1 n );       fflush(stdout);     } else {       printf( ? %d n , 1);       fflush(stdout);       scanf( %d , &a[1]);       printf( ? %d n , 1 + n / 2);       fflush(stdout);       scanf( %d , &a[1 + n / 2]);       int s, e;       if (a[1] == a[1 + n / 2]) {         printf( ! 1 n );         fflush(stdout);         return 0;       } else {         if (a[1] < a[1 + n / 2]) {           s = 1, e = 1 + n / 2;         } else {           s = 1 + n / 2, e = 1 + n;         }       }       while (s <= e) {         int mi = s + e >> 1;         int x = (mi + n - 1) % n + 1;         int y = (mi + n + n / 2 - 1) % n + 1;         printf( ? %d n , x);         fflush(stdout);         scanf( %d , &a[x]);         printf( ? %d n , y);         fflush(stdout);         scanf( %d , &a[y]);         if (a[x] == a[y]) {           printf( ! %d n , x);           fflush(stdout);           return 0;         } else if (a[x] < a[y]) {           s = mi + 1;         } else {           e = mi - 1;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, p;     cin >> s >> p;     int slen = s.length(), plen = p.length();     int max = 0;     if (plen > slen) {       int k = slen - 1;       while (k >= 0) {         int n = 0;         for (int i = k; i < slen; i++) {           if (p[i - k] == s[i]) n++;         }         if (n > max) max = n;         k--;       }       k = plen - slen;       while (k >= 0) {         int n = 0;         for (int i = 0; i < slen; i++) {           if (p[i + k] == s[i]) n++;         }         if (n > max) max = n;         k--;       }       k = slen;       while (k >= 0) {         int n = 0;         for (int i = plen - k; i < plen; i++) {           if (p[i] == s[i - plen + k]) n++;         }         if (n > max) max = n;         k--;       }     } else {       int k = plen;       while (k >= 0) {         int n = 0;         for (int i = k; i < plen; i++) {           if (s[i - k] == p[i]) n++;         }         if (n > max) max = n;         k--;       }       k = slen - plen;       while (k >= 0) {         int n = 0;         for (int i = 0; i < plen; i++) {           if (s[i + k] == p[i]) n++;         }         if (n > max) max = n;         k--;       }       k = plen;       while (k >= 0) {         int n = 0;         for (int i = slen - k; i < slen; i++) {           if (s[i] == p[i - slen + k]) n++;         }         if (n > max) max = n;         k--;       }     }     int change = plen - max;     cout << change;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e6 + 5;   const int mod = 51123987;   char s[maxn];   struct Pam {     vector<pair<int, int> > next[maxn];     int fail[maxn];     int len[maxn];     int num[maxn];     int S[maxn];     long long a[maxn], b[maxn];     int last, n, p;     int newNode(int l) {       next[p].clear();       len[p] = l;       return p++;     }     void init() {       n = last = p = 0;       newNode(0);       newNode(-1);       S[n] = -1;       fail[0] = 1;     }     int getFail(int x) {       while (S[n - len[x] - 1] != S[n]) {         x = fail[x];       }       return x;     }     int find(int u, int c) {       vector<pair<int, int> >& x = next[u];       int sz = x.size();       for (int i = 0; i < sz; ++i) {         if (x[i].first == c) return x[i].second;       }       return 0;     }     int add(int c) {       S[++n] = c;       int cur = getFail(last);       int x = find(cur, c);       if (!x) {         int now = newNode(len[cur] + 2);         x = now;         fail[now] = find(getFail(fail[cur]), c);         next[cur].push_back(make_pair(c, now));         num[now] = num[fail[now]] + 1;       }       last = x;       return num[last];     }     void solve(int len) {       memset(a, 0, sizeof(a));       memset(b, 0, sizeof(b));       init();       for (int i = 0; i < len; i++) {         a[i] = add(s[i] -  a );       }       init();       for (int i = len - 1; i >= 0; i--) {         b[i] = (b[i + 1] + add(s[i] -  a )) % mod;       }       long long ans = (b[0] * (b[0] - 1) / 2) % mod;       for (int i = 0; i < len; i++) {         ans = ((ans - (a[i] * b[i + 1]) + mod) % mod) % mod;       }       printf( %lld n , ans);     }   } pam;   int main() {     int n;     while (~scanf( %d , &n)) {       scanf( %s , s);       pam.solve(n);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > c;   vector<int> sort_cyclic_shifts(string const& s) {     int n = s.size();     const int alphabet = 256;     vector<int> p(n), cnt(alphabet, 0);     c.clear();     c.emplace_back();     c[0].resize(n);     for (int i = 0; i < n; i++) cnt[s[i]]++;     for (int i = 1; i < alphabet; i++) cnt[i] += cnt[i - 1];     for (int i = 0; i < n; i++) p[--cnt[s[i]]] = i;     c[0][p[0]] = 0;     int classes = 1;     for (int i = 1; i < n; i++) {       if (s[p[i]] != s[p[i - 1]]) classes++;       c[0][p[i]] = classes - 1;     }     vector<int> pn(n), cn(n);     cnt.resize(n);     for (int h = 0; (1 << h) < n; ++h) {       for (int i = 0; i < n; i++) {         pn[i] = p[i] - (1 << h);         if (pn[i] < 0) pn[i] += n;       }       fill(cnt.begin(), cnt.end(), 0);       for (int i = 0; i < n; i++) cnt[c[h][pn[i]]]++;       for (int i = 1; i < classes; i++) cnt[i] += cnt[i - 1];       for (int i = n - 1; i >= 0; i--) p[--cnt[c[h][pn[i]]]] = pn[i];       cn[p[0]] = 0;       classes = 1;       for (int i = 1; i < n; i++) {         pair<int, int> cur = {c[h][p[i]], c[h][(p[i] + (1 << h)) % n]};         pair<int, int> prev = {c[h][p[i - 1]], c[h][(p[i - 1] + (1 << h)) % n]};         if (cur != prev) ++classes;         cn[p[i]] = classes - 1;       }       c.push_back(cn);     }     return p;   }   vector<int> suffix_array_construction(string s) {     s +=  ! ;     vector<int> sorted_shifts = sort_cyclic_shifts(s);     sorted_shifts.erase(sorted_shifts.begin());     return sorted_shifts;   }   int compare(int i, int j, int n, int k) {     pair<int, int> a = {c[k][i], c[k][(i + 1 - (1 << k)) % n]};     pair<int, int> b = {c[k][j], c[k][(j + 1 - (1 << k)) % n]};     return a == b ? 0 : a < b ? -1 : 1;   }   int lcp(int i, int j) {     int log_n = c.size() - 1;     int ans = 0;     for (int k = log_n; k >= 0; k--) {       if (c[k][i] == c[k][j]) {         ans += 1 << k;         i += 1 << k;         j += 1 << k;       }     }     return ans;   }   vector<int> lcp_construction(string const& s, vector<int> const& p) {     int n = s.size();     vector<int> rank(n, 0);     for (int i = 0; i < n; i++) rank[p[i]] = i;     int k = 0;     vector<int> lcp(n - 1, 0);     for (int i = 0; i < n; i++) {       if (rank[i] == n - 1) {         k = 0;         continue;       }       int j = p[rank[i] + 1];       while (i + k < n && j + k < n && s[i + k] == s[j + k]) k++;       lcp[rank[i]] = k;       if (k) k--;     }     return lcp;   }   int main() {     string s;     cin >> s;     int K;     cin >> K;     int n = s.size();     vector<int> p = suffix_array_construction(s);     vector<int> lcp = lcp_construction(s, p);     for (int i = 0; i < p.size(); i++) {       for (int j = 1 + (i > 0 ? lcp[i - 1] : 0); j <= n - p[i]; j++) {         if (K == 1) {           cout << s.substr(p[i], j) << endl;           return 0;         }         K--;         int mn = j;         for (int x = i + 1; x < p.size(); x++) {           mn = min(mn, lcp[x - 1]);           if (mn < j) break;           if (K == 1) {             cout << s.substr(p[x], j) << endl;             return 0;           }           K--;         }       }     }     cout <<  No such line.  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 5e5 + 100, INF = 1e9;   int N, M, X[MX], cnt;   map<int, int> mp;   struct Seg {     int z;     int l, r;     Seg *L, *R;     void update(int x) { z = min(z, x); }     void pushdown() { L->update(z), R->update(z); }     void init(int a, int b);     void Min(int a, int b, int x);     int ask(int a);   } T[MX << 1], *Cnt = T;   Seg* New() { return ++Cnt; }   void Seg::init(int a, int b) {     l = a, r = b, z = INF;     if (l == r) return;     int m = (l + r) >> 1;     L = New(), L->init(l, m);     R = New(), R->init(m + 1, r);   }   void Seg::Min(int a, int b, int x) {     if (a <= l && r <= b) {       update(x);       return;     }     pushdown();     if (a <= L->r) L->Min(a, b, x);     if (b >= R->l) R->Min(a, b, x);   }   int Seg::ask(int a) {     if (l == r) return z;     pushdown();     if (a <= L->r)       return L->ask(a);     else       return R->ask(a);   }   struct Query {     int id, l, nx;   } Q[MX];   int H[MX], qc;   void add(int id, int l, int r) {     Q[++qc].id = id, Q[qc].l = l, Q[qc].nx = H[r], H[r] = qc;   }   int ans[MX];   int A[MX];   void Solve() {     for (int i = (1); i <= (N); ++i) {       int c = X[i];       if (A[c]) {         int delta = i - A[c];         T->Min(1, A[c], delta);       }       A[c] = i;       for (int j = H[i]; j; j = Q[j].nx) ans[Q[j].id] = T->ask(Q[j].l);     }   }   int main() {     scanf( %d%d , &N, &M);     int x;     for (int i = (1); i <= (N); ++i) {       scanf( %d , &x);       if (!mp.count(x)) mp[x] = ++cnt;       X[i] = mp[x];     }     T->init(1, N);     int l, r;     for (int i = (1); i <= (M); ++i) {       scanf( %d%d , &l, &r);       add(i, l, r);     }     Solve();     for (int i = (1); i <= (M); ++i)       printf( %d n , (ans[i] == INF ? -1 : ans[i]));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e9 + 7;   const int maxn = 1e5 + 5;   int n, m;   int a[maxn];   int num[maxn];   int main() {     cin >> n;     long long sum1 = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       sum1 += a[i];     }     num[n] = a[n];     long long sum2 = 0;     for (int i = n - 1; i >= 1; i--) {       num[i] = max(a[i], num[i + 1] - 1);     }     for (int i = 1; i < n; i++) {       if (num[i] > num[i + 1]) {         num[i + 1] = num[i];       }     }     for (int i = 1; i <= n; i++) {       sum2 += num[i] + 1;     }     cout << sum2 - sum1 - n << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[30][30];   int a, b;   int main() {     while (~scanf( %d%d , &a, &b)) {       for (int i = 0; i < a; i++) scanf( %s , s[i]);       int ss = 0;       for (int i = 0; i < a; i++) {         for (int j = 0; j < b; j++) {           int d = 99999999;           if (s[i][j] ==  0 ) {             for (int k = 0; k <= i; k++) {               if (s[i - k][j] ==  1 ) break;               int l;               for (l = 1; l <= j; l++) {                 if (s[i - k][j - l] ==  1 ) break;               }               d = min(d, l);               ss = max(ss, d * 2 + (k + 1) * 2);             }           }         }       }       printf( %d n , ss);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 7010;   map<long long, int> cnt;   int n;   long long ar[N], br[N];   bitset<N> bit[N];   bitset<N> res;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> ar[i];       cnt[ar[i]]++;     }     for (int i = 1; i <= n; i++) {       cin >> br[i];     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if ((ar[i] | ar[j]) == ar[i]) {           bit[i][j] = 1;         } else {           bit[i][j] = 0;         }       }     }     for (int i = 1; i <= n; i++) {       if (cnt[ar[i]] >= 2) {         res = (res | bit[i]);       }     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       if (res[i]) {         ans += br[i];       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int n, ans = 0;   vector<pair<int, int>> b;   vector<int> a(26);   int main() {     cin >> s >> n;     for (int i = 0; i < s.length(); ++i) {       a[s[i] -  a ]++;     }     for (int i = 0; i < 26; ++i) {       b.push_back(make_pair(a[i], i));     }     sort(b.begin(), b.end());     for (int i = 0; i < 26; ++i) {       if (n >= b[i].first) {         n -= b[i].first;         b[i].first = 0;       }     }     for (int i = 0; i < 26; ++i) {       if (b[i].first != 0) ans++;     }     cout << ans << endl;     for (int i = 0; i < s.length(); ++i) {       for (int j = 0; j < 26; ++j) {         if (s[i] -  a  == b[j].second && b[j].first > 0) {           cout << s[i];         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e3 + 5;   struct node {     int op;     int l;     int r;     int d;   } cmd[maxn];   ;   int a[maxn];   int b[maxn];   int main() {     ios::sync_with_stdio(0);     int n, m;     cin >> n >> m;     for (int i = 1; i <= m; i++)       cin >> cmd[i].op >> cmd[i].l >> cmd[i].r >> cmd[i].d;     for (int i = 1; i <= n; i++) a[i] = 100000000;     for (int i = 1; i <= m; i++) {       if (cmd[i].op == 1) {         for (int j = cmd[i].l; j <= cmd[i].r; j++) b[j] += cmd[i].d;       } else {         for (int j = cmd[i].l; j <= cmd[i].r; j++) {           a[j] = min(a[j], cmd[i].d - b[j]);         }       }     }     for (int i = 1; i <= n; i++) b[i] = a[i];     for (int i = 1; i <= m; i++) {       if (cmd[i].op == 1) {         for (int j = cmd[i].l; j <= cmd[i].r; j++) b[j] += cmd[i].d;       } else {         int flag = INT_MIN;         for (int j = cmd[i].l; j <= cmd[i].r; j++) flag = max(flag, b[j]);         if (flag != cmd[i].d) {           cout <<  NO ;           return 0;         }       }     }     cout <<  YES  << endl;     for (int i = 1; i <= n; i++) cout << a[i] <<    ;     return 0;   }


/*   Creater :        ANSHUMAN MISHRA    All Losses In this World Are Due To Lack Of Ability.   If You Want To Curse Someone , Curse Your Own Weakness    */         #include <bits/stdc++.h>   using namespace std;      #define ll long long   #define pii pair<int,int>   #define yes cout<< YES n    #define no cout<< NO n       const int N=1e5+5;   int cnt[26][N];      signed main(){       ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);       #ifndef ONLINE_JUDGE           freopen( in.txt , r ,stdin);       #endif          int t=1;cin>>t;       while(t--){           int n,m;           cin>>n>>m;           for (int i=0;i<m;++i) for (int j=0;j<26;++j) cnt[j][i]=0;              string s;           for (int i=0;i<n;++i){               cin>>s;               for (int j=0;j<m;++j)                   cnt[s[j]- a ][j]++;           }           /*           for (int i=0;i<m;++i){               for (int j=0;j<26;++j){                   /*                   if (cnt[j][i]==1){                       ans+= (j+ a );                       break;                   }                   cout<<cnt[j][i]<<   ;               }               cout<<  n ;           }*/              for (int i=0;i<n-1;++i){               cin>>s;               for (int j=0;j<m;++j)                   cnt[s[j]- a ][j]--;           }                            string ans=  ;           for (int i=0;i<m;++i){               for (int j=0;j<26;++j){                                      if (cnt[j][i]==1){                       ans+= (j+ a );                       break;                   }                   //cout<<cnt[j][i]<<   ;               }               //cout<<  n ;           }           cout<<ans<<endl;           cout.flush();          }             return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1010], b[1010];   bool vis[1010];   int main() {     int n, i, ans, nn, lb;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + n + 1);     memset(vis, false, sizeof(vis));     ans = 0;     nn = 0;     while (1) {       lb = 0;       b[0] = 0;       for (i = 1; i <= n; i++)         if (vis[i] == false && a[i] > b[lb]) {           b[++lb] = a[i];           vis[i] = true;           nn++;         }       ans += (lb - 1);       if (nn == n) break;     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const int INF = 0x3f3f3f3f;   const int maxn = 100010;   inline int read() {     int x = 0, f = 1;     char ch = 0;     while (!isdigit(ch)) {       ch = getchar();       if (ch ==  - ) f = -1;     }     while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();     return x * f;   }   int n, m;   int a[maxn], b[maxn], low[maxn], pre[maxn], f[maxn], la[maxn];   int gap[maxn];   void work() {     memset(low, 63, sizeof(low));     pre[1] = low[1] = 0, f[1] = la[1] = 1;     for (int k = 2; k <= n; ++k) {       if (a[k] + 1) {         int L = 1, R = n;         while (L <= R) {           int mid = (L + R) >> 1;           if (low[mid] < a[k])             L = mid + 1;           else             R = mid - 1;         }         pre[k] = la[L - 1];         la[L] = k;         f[k] = L, low[L] = a[k];       } else {         pre[k] = -1, f[k] = -1;         int j = n;         for (int i = m; i >= 1; i--) {           while (low[j] >= b[i]) j--;           low[j + 1] = b[i], la[j + 1] = -1;         }       }     }   }   void work2() {     int L, R, rem = m;     int x = n;     while (x)       if (a[x] + 1) {         if (pre[x] >= 0) {           x = pre[x];           continue;         }         R = lower_bound(b + 1, b + rem + 1, a[x]) - b - 1;         for (int y = x - 1; y != 0; y--) {           if (a[y] == -1 || a[y] >= a[x]) continue;           L = upper_bound(b + 1, b + rem + 1, a[y]) - b;           if (f[x] - f[y] - 1 == min(R - L + 1, gap[x] - gap[y])) {             for (int i = y, j = L; i <= x && j <= R; i++)               if (a[i] == -1) a[i] = b[j], b[j] = -1, j++;             x = y;             rem = L - 1;             break;           }         }       }     for (int i = 1, j = 1; i <= n; ++i) {       if (a[i] + 1) continue;       while (b[j] == -1) ++j;       a[i] = b[j];       b[j++] = -1;     }   }   int main() {     n = read();     a[1] = 0;     a[n + 2] = INF;     for (int i = 2; i <= n + 1; ++i)       a[i] = read(), gap[i] = gap[i - 1] + (a[i] == -1);     m = read();     gap[n + 2] = gap[n + 1];     n += 2;     for (int i = 1; i <= m; ++i) b[i] = read();     sort(b + 1, b + m + 1);     m = unique(b + 1, b + m + 1) - b - 1;     work();     work2();     for (int i = 2; i < n; ++i) printf( %d  , a[i]);   }


#include <bits/stdc++.h>   using namespace std;   long long t, n, m;   int a[200003];   pair<int, int> p[200003];   int main() {     cin >> t;     while (t--) {       cin >> n;       for (int i = 1; i <= n; ++i) {         cin >> a[i];       }       long long re = 0;       for (int i = 1; i <= n;) {         int val = a[i], j;         for (j = i; j <= n && 1ll * a[j] * a[i] > 0; ++j) val = max(val, a[j]);         re += val;         i = j;       }       cout << re <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, a, cf, cm, m;     cin >> n >> a >> cf >> cm >> m;     vector<vector<long long> > stat(n, vector<long long>(2));     for (int i = 0; i < n; i++) {       cin >> stat[i][0];       stat[i][1] = i;     }     stable_sort(stat.begin(), stat.end());     vector<long long> mi(n);     mi[0] = 0;     for (int i = 1; i < n; i++) {       mi[i] = (stat[i][0] - stat[i - 1][0]) * i + mi[i - 1];     }     vector<long long> ma(n);     ma[n - 1] = a - stat[n - 1][0];     for (int i = n - 2; i >= 0; i--) {       ma[i] = ma[i + 1] + a - stat[i][0];     }     if (ma[0] <= m) {       cout << n * cf + a * cm << endl;       for (int i = 0; i < n; i++) {         cout << a <<    ;       }       return 0;     }     long long otv = 0;     long long votv = -1;     long long mn = 0;     long long mn1 = 0;     if (mi[n - 1] > m) {       for (int i = n - 1; i >= 0; i--) {         if (mi[i] <= m) {           otv = (stat[i][0] + (m - mi[i]) / (i + 1)) * cm;           mn = i;           mn1 = (stat[i][0] + (m - mi[i]) / (i + 1));           votv = otv;           break;         }       }     }     if (mi[n - 1] <= m) otv = (stat[n - 1][0] + (m - mi[n - 1]) / n) * cm;     for (int i = n - 1; i >= 0; i--) {       if (m - ma[i] >= 0) {         int nom = upper_bound(mi.begin(), mi.end(), m - ma[i]) - mi.begin();         if (nom >= n || m - ma[i] < mi[nom]) nom--;         if (nom >= i) {           long long h =               (n - i) * cf + (stat[i][0] + (m - mi[i] - ma[i]) / i) * cm;           otv = max(otv,                     (n - i) * cf + (stat[i][0] + (m - mi[i] - ma[i]) / i) * cm);         } else {           long long h = (stat[nom][0] + (m - mi[nom] - ma[i]) / (nom + 1)) * cm +                         (n - i) * cf;           otv = max(otv, (stat[nom][0] + (m - mi[nom] - ma[i]) / (nom + 1)) * cm +                              (n - i) * cf);         }       }     }     if (votv == otv) {       cout << otv << endl;       for (int i = 0; i < n; i++) {         if (i <= mn) stat[i][0] = mn1;       }       for (int i = 0; i < n; i++) {         swap(stat[i][0], stat[i][1]);       }       stable_sort(stat.begin(), stat.end());       for (int i = 0; i < n; i++) {         cout << stat[i][1] <<    ;       }       return 0;     }     if (otv == (stat[n - 1][0] + (m - mi[n - 1]) / n) * cm) {       cout << otv << endl;       for (int i = 0; i < n; i++) {         cout << stat[n - 1][0] + (m - mi[n - 1]) / n <<    ;       }       return 0;     }     long long otv1 = 0;     if (mi[n - 1] <= m) otv1 = stat[n - 1][0] * cm;     for (int i = n - 1; i >= 0; i--) {       if (m - ma[i] >= 0) {         int nom = upper_bound(mi.begin(), mi.end(), m - ma[i]) - mi.begin();         if (nom >= n || m - ma[i] < mi[nom]) nom--;         if (nom >= i) {           otv1 = max(otv1,                      (n - i) * cf + (stat[i][0] + (m - mi[i] - ma[i]) / i) * cm);           if (otv1 == otv) {             for (int j = 0; j < n; j++) {               if (j < i)                 stat[j][0] = stat[i][0] + (m - mi[i] - ma[i]) / i;               else                 stat[j][0] = a;             }             break;           }         } else {           otv1 =               max(otv1, (stat[nom][0] + (m - mi[nom] - ma[i]) / (nom + 1)) * cm +                             (n - i) * cf);           if (otv1 == otv) {             for (int j = 0; j < n; j++) {               if (j <= nom)                 stat[j][0] = stat[nom][0] + (m - mi[nom] - ma[i]) / (nom + 1);               if (j >= i) stat[j][0] = a;             }             break;           }         }       }     }     for (int i = 0; i < n; i++) {       swap(stat[i][0], stat[i][1]);     }     stable_sort(stat.begin(), stat.end());     cout << otv << endl;     for (int i = 0; i < n; i++) {       cout << stat[i][1] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     set<string> s0;     for (int i = 0; i < n; i++) {       cin >> s;       unordered_set<char> s1;       s.erase(remove_if(s.begin(), s.end(),                         [&](char const c) { return !(s1.insert(c).second); }),               s.end());       sort(s.begin(), s.end());       s0.insert(s);     }     cout << s0.size() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define intt long long int   #define F first    #define S second   #define pb push_back      int main()   {       int n;cin>>n;       int arr[n+1];              vector<int> pos;       pos.pb(-1);          for(int i=1;i<=n;i++) {cin>>arr[i];if(arr[i]==1) pos.pb(i); }       int m=pos.size()-1; // no. of 1s          int dp[n][m+1]; // dp[][]== ith posn tak use karke , pehle j 1 s ko shift karna hai .          for(int i=0;i<=n;i++)dp[i][0]=0;       for(int i=1;i<=m;i++) dp[0][i]=1e9;          for(int i=1;i<=n;i++)       {           for(int j=1;j<=m;j++)           {                  if(arr[i]==1)               dp[i][j]=dp[i-1][j];               else                dp[i][j]=min(dp[i-1][j],dp[i-1][j-1]+abs(pos[j]-i));           }       }       cout<<dp[n][m]<<endl;       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   string t[6] = { lios ,  liala ,  etr ,  etra ,  initis ,  inites };   bool mark[3];   int md = -1;   int typ(string s) {     for (int i = 0; i < 6; i++)       if (t[i].size() <= s.size()) {         bool flag = true;         for (int j = 0; j < t[i].size(); j++)           if (t[i][j] != s[s.size() - t[i].size() + j]) flag = false;         if (flag) return i;       }     return -1;   }   int main() {     ios::sync_with_stdio(false);     string s;     bool flag = true;     bool x = false;     int cnt = 0;     while (cin >> s) {       cnt++;       int p = typ(s);       if (p == -1)         flag = false, x = true;       else if (md != -1 && p % 2 != md)         flag = false;       else if (p / 2 == 0 && (mark[1] || mark[2]))         flag = false;       else if (p / 2 == 1 && (mark[1] || mark[2]))         flag = false;       else if (p / 2 == 2 && !mark[1])         flag = false;       if (flag) {         md = p % 2;         mark[p / 2] = true;       }     }     if ((!mark[1] && cnt > 1) || x || (cnt > 1 && !flag)) {       cout <<  NO n ;       return 0;     }     cout <<  YES n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long INF = 1LL << 60;   long long MOD = 1e9 + 7;   namespace output {   void pr(short x) { cout << x; }   void pr(signed x) { cout << x; }   void pr(long x) { cout << x; }   void pr(long long x) { cout << x; }   void pr(unsigned short x) { cout << x; }   void pr(unsigned x) { cout << x; }   void pr(unsigned long x) { cout << x; }   void pr(unsigned long long x) { cout << x; }   void pr(float x) { cout << x; }   void pr(double x) { cout << x; }   void pr(long double x) { cout << x; }   void pr(char x) { cout << x; }   void pr(const char* x) { cout << x; }   void pr(const string& x) { cout << x; }   void pr(bool x) { cout << x; }   template <size_t sz>   void pr(const bitset<sz>& x) {     cout << x;   }   template <class T>   void pr(const complex<T>& x) {     cout << x;   }   template <class T1, class T2>   void pr(const pair<T1, T2>& x);   template <class T1, class T2, class T3>   void pr(const tuple<T1, T2, T3>& x);   template <class T>   void pr(const T& x);   template <class T, class... Ts>   void pr(const T& t, const Ts&... ts) {     pr(t);     pr(ts...);   }   template <class T1, class T2>   void pr(const pair<T1, T2>& x) {     pr( ( , x.first,  ,  , x.second,  ) );   }   template <class T1, class T2, class T3>   void pr(const tuple<T1, T2, T3>& x) {     pr( ( , get<0>(x),  ,  , get<1>(x),  ,  , get<2>(x),  ) );   }   template <class T>   void pr(const T& x) {     pr( [ );     bool fst = 1;     for (const auto& a : x) pr(!fst ?  ,   :   , a), fst = 0;     pr( ] );   }   void print() { pr(  n ); }   template <class T, class... Ts>   void print(const T& t, const Ts&... ts) {     pr(t);     if (sizeof...(ts)) pr(   );     print(ts...);   }   }  // namespace output   using namespace output;   template <class T1, class T2>   istream& operator>>(istream& is, pair<T1, T2>& x) {     is >> x.first >> x.second;     return is;   }   template <class T1, class T2, class T3>   istream& operator>>(istream& is, tuple<T1, T2, T3>& x) {     is >> get<0>(x) >> get<1>(x) >> get<2>(x);     return is;   }   template <class T>   istream& operator>>(istream& is, vector<T>& v) {     for (auto& x : v) is >> x;     return is;   }   long long powa(long long base, long long exp) {     long long res = 1;     while (exp) {       if (exp & 1) res = res * base % MOD;       base = base * base % MOD;       exp >>= 1;     }     return res;   }   bool mini(long long& a, long long b) { return b < a ? a = b, 1 : 0; }   bool maxi(long long& a, long long b) { return b > a ? a = b, 1 : 0; }   signed main() {     ios::sync_with_stdio(0), cin.tie(0);     vector<vector<long long> > silly = {{1, 2, 4}, {5, 3, 8}, {9, 6, 7}};     long long n;     cin >> n;     if (n <= 2)       print(-1);     else {       vector<vector<long long> > grid(n, vector<long long>(n));       long long cnt = 1;       bool vert = false;       for (long long(i) = (n - 1); (i) > (2); --(i)) {         if (!vert) {           for (long long(j) = (0); (j) < (i + 1); ++(j)) grid[i][j] = cnt++;           for (long long(j) = (i - 1); (j) > (-1); --(j)) grid[j][i] = cnt++;         } else {           for (long long(j) = (0); (j) < (i + 1); ++(j)) grid[j][i] = cnt++;           for (long long(j) = (i - 1); (j) > (-1); --(j)) grid[i][j] = cnt++;         }         vert = !vert;       }       for (long long(i) = (0); (i) < (3); ++(i))         for (long long(j) = (0); (j) < (3); ++(j))           grid[i][j] = silly[i][j] + cnt - 1;       for (long long(i) = (0); (i) < (n); ++(i)) {         for (long long(j) = (0); (j) < (n); ++(j)) cout << grid[i][j] <<    ;         cout <<   n ;       }     }   }


#include<bits/stdc++.h>   using namespace std;   typedef long long ll;   typedef long double ld;   #define rep(a, b) for(ll a = 0; a < (b); ++a)   #define pb push_back   #define st first   #define nd second   #define all(a) a.begin(), a.end()   #define lg(a) (31-__builtin_clz(a))   void solve() {           int n;           cin >> n;           ll T[n];           rep(i, n) cin >> T[i];           sort(T, T+n);           ll ans=0, odejmij=0;           rep(i, n-1) ans+=T[i+1]-T[i];           rep(i, n) {                   ans-=i*T[i]-odejmij;                   odejmij+=T[i];           }           cout << ans <<   n ;   }   int main() {           ios_base::sync_with_stdio(0); cin.tie(0);           int _=1;           cin >> _;           while(_--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int c = 1, mx = 0;     string s;     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] !=  A  && s[i] !=  O  && s[i] !=  I  && s[i] !=  U  &&           s[i] !=  Y  && s[i] !=  E ) {         c++;       } else {         if (c > mx) mx = c;         c = 1;       }     }     if (c > mx) mx = c;     cout << mx;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, s, i, a[1003], res, x;   int main() {     cin >> n >> x;     for (i = 1; i <= n; i++) {       cin >> a[i];       s += a[i];     }     if (s <= 0) s *= (-1);     res = s / x;     if (s % x > 0) res++;     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   struct node {     int s, r, no;   } xx[500001], dance[500001], fire[500001];   bool cmp(node x, node y) { return x.s > y.s || (x.s == y.s && x.r > y.r); }   int S[500001];   int ans[500001];   int mal = 0;   int k;   int q;   bool yes[500001];   double eps = 1e-6;   int h, t;   map<int, int> X;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> xx[i].s >> xx[i].r;     for (int i = 1; i <= n; i++) xx[i].no = i;     sort(xx + 1, xx + n + 1, cmp);     for (int i = 1; i <= n; i++) {       if (mal > xx[i].r) continue;       if (mal == xx[i].r && q == xx[i].s) {         dance[++k] = xx[i];         continue;       }       if (q == xx[i].s) continue;       if (mal == xx[i].r) continue;       {         dance[++k] = xx[i];         mal = xx[i].r;         q = xx[i].s;       }     }     h = 1;     fire[++t] = dance[1];     for (int i = 2; i <= k; i++) {       if (h <= t && dance[i].r <= fire[t].r) continue;       while (h < t) {         long long s1 = fire[t - 1].s, s2 = fire[t].s, r1 = fire[t - 1].r,                   r2 = fire[t].r;         long long s3 = dance[i].s, r3 = dance[i].r;         long long k1 = (s3 - s2) * (r1 - r2) * r3 * s1;         long long k2 = (s1 - s2) * (r3 - r2) * r1 * s3;         if (k1 < k2)           t--;         else           break;       }       fire[++t] = dance[i];     }     int xxx = 0;     for (int i = 1; i <= t; i++) {       X[fire[i].s] = fire[i].r;     }     for (int i = 1; i <= n; i++) {       if (X[xx[i].s] == xx[i].r) ans[++xxx] = xx[i].no;     }     sort(ans + 1, ans + xxx + 1);     for (int i = 1; i <= xxx; i++) cout << ans[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   const int maxn = 2e5 + 10;   template <class T>   inline T read() {     int f = 1;     T ret = 0;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       ret = (ret << 1) + (ret << 3) + ch -  0 ;       ch = getchar();     }     ret *= f;     return ret;   }   template <class T>   inline void write(T n) {     if (n < 0) {       putchar( - );       n = -n;     }     if (n >= 10) {       write(n / 10);     }     putchar(n % 10 +  0 );   }   template <class T>   inline void writeln(const T &n) {     write(n);     puts(  );   }   template <typename T>   void _write(const T &t) {     write(t);   }   template <typename T, typename... Args>   void _write(const T &t, Args... args) {     write(t), putchar(   );     _write(args...);   }   template <typename T, typename... Args>   inline void write_line(const T &t, const Args &...data) {     _write(t, data...);   }   char s[maxn];   int pre, last;   int r, l;   int main(int argc, char const *argv[]) {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n;     cin >> s + 1;     for (int i = 1; i <= n / 2; i++)       if (s[i] ==  ? )         ++l;       else         pre += s[i] -  0 ;     for (int i = n / 2 + 1; i <= n; i++)       if (s[i] ==  ? )         ++r;       else         last += s[i] -  0 ;     if (pre == last) {       if (l == r)         cout <<  Bicarp n ;       else         cout <<  Monocarp n ;       return 0;     } else {       if (pre > last) swap(pre, last), swap(l, r);       if (l <= r)         cout <<  Monocarp n ;       else {         int left = last - pre;         l -= r;         l /= 2;         if (l * 9 == left)           cout <<  Bicarp n ;         else           cout <<  Monocarp n ;       }     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int n, m;     pair<int, int> tl = {-100, -100}, br = {-100, -100};     cin >> n >> m;     char paper[n][m];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> paper[i][j];         if (paper[i][j] ==  *  && (tl.first == -100 && tl.second == -100))           tl = {i, j};         else if (j < tl.second && paper[i][j] ==  * )           tl = {tl.first, j};         if (paper[i][j] ==  *  && (i >= br.first && j > br.second))           br = {i, j};         else if (paper[i][j] ==  *  && (i > br.first))           br = {i, br.second};         else if (paper[i][j] ==  *  && (j > br.second))           br = {br.first, j};       }     }     for (int i = tl.first; i <= br.first; i++) {       for (int j = tl.second; j <= br.second; j++) {         cout << paper[i][j];       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200010;   const int maxv = 1000000010;   int a[maxn];   int l[maxn], r[maxn];   int rj[maxn];   stack<int> s;   int main() {     int n;     cin >> n;     a[0] = 0;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     a[n + 1] = 0;     s.push(0);     for (int i = 1; i < n + 1; i++) {       while (a[s.top()] >= a[i]) s.pop();       l[i] = s.top();       s.push(i);     }     while (s.size()) s.pop();     s.push(n + 1);     for (int i = n; i > 0; i--) {       while (a[s.top()] >= a[i]) s.pop();       r[i] = s.top();       s.push(i);     }     for (int i = 1; i <= n; i++)       rj[r[i] - l[i] - 1] = max(rj[r[i] - l[i] - 1], a[i]);     int val = 0;     for (int i = n; i > 0; i--) {       val = max(val, rj[i]);       rj[i] = val;     }     for (int i = 1; i <= n; i++) printf( %d  , rj[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long a[n], b[n];       long long m = INT_MAX;       for (int i = 0; i < n; i++) {         cin >> a[i];         b[i] = a[i];         m = min(m, a[i]);       }       sort(b, b + n);       long long flag = 0;       for (int i = 0; i < n; i++)         if (a[i] != b[i] && a[i] % m > 0) flag = 1;       if (flag)         cout <<  NO  << endl;       else         cout <<  YES  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Point {     int x;     int y;   };   bool onSegment(Point p, Point q, Point r) {     if (q.x <= max(p.x, r.x) && q.x >= min(p.x, r.x) && q.y <= max(p.y, r.y) &&         q.y >= min(p.y, r.y))       return true;     return false;   }   int orientation(Point p, Point q, Point r) {     int val = (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);     if (val == 0) return 0;     return (val > 0) ? 1 : 2;   }   bool doIntersect(Point p1, Point q1, Point p2, Point q2) {     int o1 = orientation(p1, q1, p2);     int o2 = orientation(p1, q1, q2);     int o3 = orientation(p2, q2, p1);     int o4 = orientation(p2, q2, q1);     if (o1 != o2 && o3 != o4) return true;     if (o1 == 0 && onSegment(p1, p2, q1)) return true;     if (o2 == 0 && onSegment(p1, q2, q1)) return true;     if (o3 == 0 && onSegment(p2, p1, q2)) return true;     if (o4 == 0 && onSegment(p2, q1, q2)) return true;     return false;   }   bool isInside(Point polygon[], int n, Point p) {     if (n < 3) return false;     Point extreme = {10000, p.y};     int count = 0, i = 0;     do {       int next = (i + 1) % n;       if (doIntersect(polygon[i], polygon[next], p, extreme)) {         if (orientation(polygon[i], p, polygon[next]) == 0)           return onSegment(polygon[i], p, polygon[next]);         count++;       }       i = next;     } while (i != 0);     return count & 1;   }   int main() {     Point s1[4];     Point s2[4];     for (__typeof(0) i = 0; i <= 3; i++) cin >> s1[i].x >> s1[i].y;     for (__typeof(0) i = 0; i <= 3; i++) cin >> s2[i].x >> s2[i].y;     for (__typeof(0) i = 0; i <= 3; i++) {       for (__typeof(0) j = 0; j <= 3; j++) {         if (doIntersect(s1[i], s1[(i + 1) % 4], s2[j], s2[(j + 1) % 4])) {           cout <<  YES n ;           return 0;         }       }     }     if (isInside(s1, 4, s2[0]) || isInside(s2, 4, s1[0]))       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int d[105], n, sum1 = 0, sum2 = 0, begin, end;     cin >> n;     for (int i = 1; i <= n; i++) cin >> d[i];     cin >> begin >> end;     if (begin > end) {       int t;       t = begin;       begin = end;       end = t;     }     for (int i = begin; i < end; i++) sum1 += d[i];     for (int i = end; i != begin; i++) {       sum2 += d[i];       if (i >= n) i = 0;     }     sum1 = sum1 > sum2 ? sum2 : sum1;     cout << sum1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 1e5 + 5;   struct Edge {     int v, nxt;   } E[MX * 2];   int Head[MX], erear;   void edge_init() {     erear = 0;     memset(Head, -1, sizeof(Head));   }   void edge_add(int u, int v) {     E[erear].v = v;     E[erear].nxt = Head[u];     Head[u] = erear++;   }   int siz[MX];   double ans[MX];   void DFS1(int u, int f) {     siz[u] = 1;     for (int i = Head[u]; ~i; i = E[i].nxt) {       int v = E[i].v;       if (v == f) continue;       DFS1(v, u);       siz[u] += siz[v];     }   }   void DFS2(int u, int f) {     for (int i = Head[u]; ~i; i = E[i].nxt) {       int v = E[i].v;       if (v == f) continue;       ans[v] = ans[u] + 1 + (siz[u] - siz[v] - 1) / 2.0;       DFS2(v, u);     }   }   int main() {     int n;     edge_init();     scanf( %d , &n);     for (int i = 2; i <= n; i++) {       int t;       scanf( %d , &t);       edge_add(i, t);       edge_add(t, i);     }     ans[1] = 1;     DFS1(1, -1);     DFS2(1, -1);     for (int i = 1; i <= n; i++) {       printf( %.8lf%c , ans[i], i == n ?   n  :    );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int test;   int n, k;   string s;   int tipus[200009];   int darab[3];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> test;     for (int tt = 1; tt <= test; tt++) {       cin >> n;       int minx = -100000;       int maxx = 100000;       int miny = -100000;       int maxy = 100000;       for (int i = 1; i <= n; i++) {         int x, y;         int a, b, c, d;         cin >> x >> y >> a >> b >> c >> d;         if (a == 0) minx = max(minx, x);         if (b == 0) maxy = min(maxy, y);         if (c == 0) maxx = min(maxx, x);         if (d == 0) miny = max(miny, y);       }       if (minx <= maxx && miny <= maxy) {         cout << 1 <<     << minx <<     << miny << endl;       } else {         cout << 0 << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long n2(int n) { return (n * 1ll * (n + 1)) / 2; }   const int N = 2e5;   vector<int> f(N + 1);   long long get(int pos) {     long long res = 0;     for (; pos >= 0; pos = (pos & (pos + 1)) - 1) res += f[pos];     return res;   }   long long get(int l, int r) { return get(r) - (l ? get(l - 1) : 0); }   void update(int pos, int val) {     for (; pos < int(f.size()); pos |= pos + 1) f[pos] += val;   }   void solve() {     int n;     cin >> n;     map<int, vector<int> > My;     map<int, int> cntx;     vector<int> indComp(n);     for (int i = 0; i < n; ++i) {       int x, y;       cin >> x >> y;       indComp[i] = x;       cntx[x]++;       My[y].push_back(x);     }     sort(indComp.begin(), indComp.end());     indComp.resize(unique(indComp.begin(), indComp.end()) - indComp.begin());     for (pair<int, int> p : cntx) {       int i =           lower_bound(indComp.begin(), indComp.end(), p.first) - indComp.begin();       update(i, 1);     }     long long ans = 0;     for (auto &vp : My) {       sort(vp.second.begin(), vp.second.end());       int lst = -1;       for (int x : vp.second) {         int i = lower_bound(indComp.begin(), indComp.end(), x) - indComp.begin();         int l = get(lst + 1, i);         int r = get(i, N);         ans += l * 1ll * r;         lst = i;         cntx[x]--;         if (cntx[x] == 0) update(i, -1);       }     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int T = 1, tc = 1;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class Graph {    public:     vector<vector<int>> a;     vector<int> vis;     int N, M;     int n;     int R(int i) { return i; }     int C(int i) { return i + N; }     void addEdge(int l, int r) {       a[R(l)].push_back(C(r));       a[C(r)].push_back(R(l));     }     Graph() {       cin >> N >> M;       n = N + M;       a.assign(n, vector<int>());       vis.assign(n, 0);       for (int i = 0; i < int(N); i++) {         cin.get();         for (int j = 0; j < int(M); j++) {           char c = cin.get();           if (c ==  . ) continue;           addEdge(i, j);         }       }     }     bool dfs(int v, set<int> &r, set<int> &c) {       vis[v] = 1;       if (v < N && a[v].size() != c.size()) return 0;       if (v >= N && a[v].size() != r.size()) return 0;       for (int to : a[v]) {         if (!vis[to] && !dfs(to, r, c)) return 0;         if (v < N && !c.count(to)) return 0;         if (v >= N && !r.count(to)) return 0;       }       return 1;     }     bool isCompleteBipariate(int v) {       if (a[v].empty()) return 1;       set<int> c((a[v]).begin(), (a[v]).end());       set<int> r((a[a[v][0]]).begin(), (a[a[v][0]]).end());       return dfs(v, r, c);     }     void solve() {       for (int i = 0; i < int(N); i++)         if (!vis[i] && !isCompleteBipariate(i)) {           cout <<  No  << endl;           return;         }       cout <<  Yes  << endl;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     Graph g;     g.solve();   }


#include <bits/stdc++.h>   using namespace std;   const int maxs = 405;   const int inf = 1e9 + 7;   int dp[maxs][maxs];   string s, t, x, y;   int slen, tlen;   int nxt[maxs][26];   int g(int x) { return x + 1; }   int f(int a, int b) {     if (a == -1 && b == -1) return 0;     if (a < -1 || b < -1) return inf;     int& r = dp[g(a)][g(b)];     if (r == -1) {       r = inf;       int idx;       if (a >= 0) {         idx = f(a - 1, b);         if (idx < inf) r = min(r, nxt[idx][x[a] -  a ] + 1);       }       if (b >= 0) {         idx = f(a, b - 1);         if (idx < inf) r = min(r, nxt[idx][y[b] -  a ] + 1);       }     }     return r;   }   int main(void) {     ios_base::sync_with_stdio(0);     cin.tie(0);     int T;     cin >> T;     while (T--) {       cin >> s >> t;       int i = 0, j = 0;       slen = s.size(), tlen = t.size();       while (i < slen && j < tlen) {         if (s[i] == t[j]) ++j;         ++i;       }       if (j == tlen) {         cout <<  YES n ;         continue;       }       for (int i = 0; i <= slen; ++i)         for (int j = 0; j < 26; ++j) nxt[i][j] = inf;       for (int i = slen - 1; i >= 0; --i) {         for (int j = 0; j < 26; ++j) nxt[i][j] = nxt[i + 1][j];         nxt[i][s[i] -  a ] = i;       }       bool yes = false;       for (int i = 1; i < tlen; ++i) {         for (int j = 0; j <= tlen; ++j)           for (int k = 0; k <= tlen; ++k) dp[j][k] = -1;         x = t.substr(0, i);         y = t.substr(i, tlen - i);         if (f(i - 1, tlen - i - 1) < inf) {           yes = true;           break;         }       }       cout << (yes ?  YES n  :  NO n );     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000000,100000000000 )   using namespace std;   const double eps = 1E-9;   const double Exp = 2.718281828459045;   const double Pi = 3.1415926535897932;   const int NMAX = 100 + 5;   const int MMAX = 100000 + 5;   const int INF = 1000000000;   const int BS = 1000000007;   template <typename T>   inline T abs(const T a) {     if (a < 0) return -a;     return a;   }   template <typename T>   inline T sqr(const T& a) {     return a * a;   }   int a[NMAX][NMAX];   int b[NMAX][NMAX];   int c[NMAX][NMAX];   void mult(int n, int m, int k) {     int i, j, t;     for (i = 1; i <= n; i++) {       for (j = 1; j <= k; j++) {         c[i][j] = 0;         for (t = 1; t <= m; t++) {           c[i][j] = (c[i][j] + a[i][t] * 1ll * b[t][j]) % BS;         }       }     }   }   const int BORD = 102;   void pw(int p) {     int i, j;     if (0 == p) {       for (i = 1; i <= BORD; i++) {         for (j = 1; j <= BORD; j++) {           c[i][j] = (i == j);         }       }       return;     }     if (1 == p) {       for (i = 1; i <= BORD; i++) {         for (j = 1; j <= BORD; j++) {           c[i][j] = a[i][j];         }       }       return;     }     if (p & 1) {       int buf[NMAX][NMAX];       for (i = 1; i <= BORD; i++) {         for (j = 1; j <= BORD; j++) {           buf[i][j] = a[i][j];         }       }       pw(p - 1);       for (i = 1; i <= BORD; i++) {         for (j = 1; j <= BORD; j++) {           a[i][j] = buf[i][j];         }       }       for (i = 1; i <= BORD; i++) {         for (j = 1; j <= BORD; j++) {           b[i][j] = c[i][j];         }       }       mult(BORD, BORD, BORD);     } else {       pw(p / 2);       for (i = 1; i <= BORD; i++) {         for (j = 1; j <= BORD; j++) {           a[i][j] = c[i][j];         }       }       for (i = 1; i <= BORD; i++) {         for (j = 1; j <= BORD; j++) {           b[i][j] = c[i][j];         }       }       mult(BORD, BORD, BORD);     }   }   int main() {     ios::sync_with_stdio(false);     int n, x;     int d[NMAX] = {0};     int i, j, y;     cin >> n >> x;     for (i = 1; i <= n; i++) {       cin >> y;       d[y]++;     }     int beg[NMAX];     beg[0] = 1;     for (i = 1; i <= 100; i++) {       beg[i] = 1;       for (j = 1; j <= i; j++) {         beg[i] = (beg[i] + beg[i - j] * 1ll * d[j]) % BS;       }     }     memset(a, 0, sizeof(a));     a[1][1] = 1;     for (i = 2; i <= BORD; i++) {       for (j = 2; j <= BORD; j++) {         if (i == j + 1)           a[i][j] = 1;         else           a[i][j] = 0;       }     }     a[1][BORD] = 1;     for (i = 2; i <= BORD; i++) {       a[i][BORD] = d[BORD - i + 1];     }     pw(x);     for (i = 1; i <= BORD; i++) {       for (j = 1; j <= BORD; j++) {         b[i][j] = c[i][j];       }     }     a[1][1] = 1;     for (j = 2; j <= BORD; j++) {       a[1][j] = beg[j - 2];     }     mult(1, BORD, BORD);     cout << c[1][2] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int c[1010100], cc[1010100];   int lowbit(int x) { return x & (-x); }   void upd(int v, int idx, int a[]) {     while (idx <= n) {       a[idx] += v;       idx += lowbit(idx);     }   }   int qu(int idx, int a[]) {     int sum = 0;     if (idx == 0) return 0;     while (idx > 0) {       sum += a[idx];       idx -= lowbit(idx);     }     return sum;   }   struct Node {     int v, id;   } arr[1010100];   int cmp(Node a, Node b) { return a.v < b.v; }   int find() {     int ll = 1, rr = n + 1, mid, ans = n;     while (ll < rr) {       mid = (ll + rr) / 2;       if (qu(mid, cc) < mid)         ans = rr = mid;       else         ll = mid + 1;     }     return ans;   }   int vis[1010100];   int main() {     int i, j;     while (scanf( %d %d , &n, &m) != EOF) {       memset(vis, 0, sizeof(vis));       for (i = 1; i <= n; i++) scanf( %d , &arr[i].v), arr[i].id = i;       for (i = 1; i <= m; i++) scanf( %d , &j), vis[j] = 1;       sort(arr + 1, arr + 1 + n, cmp);       memset(c, 0, sizeof(c));       memset(cc, 0, sizeof(cc));       long long sum = 0;       for (i = 1; i <= n; i++) {         if (vis[arr[i].v]) {           upd(1, arr[i].id, c);         } else {           int ll = 0, rr = arr[i].id, mid;           int v = qu(rr, c), x = rr;           while (ll < rr) {             mid = (ll + rr) / 2;             if (qu(mid, c) == v)               x = rr = mid;             else               ll = mid + 1;           }           if (qu(n, c) == 0) x = 0;           ll = arr[i].id, rr = n + 1;           v = qu(ll, c);           int y = ll;           while (ll < rr) {             mid = (ll + rr) / 2;             if (qu(mid, c) == v)               y = mid, ll = mid + 1;             else               rr = mid;           }           y = y - qu(y, cc);           x = max(find() - 1, x);           x = x - qu(x, cc);           sum = sum + (y - x);           upd(1, arr[i].id, cc);         }       }       printf( %I64d n , sum);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 10200;   const int mod = 1e9 + 7;   int dp[N];   int len[N];   inline int get_len(int x) {     if (x == 0) return 1;     int res = 0;     while (x) res++, x /= 10;     return res;   }   vector<int> del[N];   vector<int> calc_prefix(string s) {     int n = (int)s.length();     vector<int> 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);     string s;     cin >> s;     int n = s.length();     for (int i = 0; i <= n; ++i) len[i] = get_len(i);     for (int i = 1; i <= n; ++i)       for (int j = i; j <= n; j += i) del[j].push_back(i);     for (int i = 1; i <= n; ++i) dp[i] = 1e9;     dp[0] = 0;     string t;     vector<int> p;     for (int i = 1; i <= n; ++i) {       int cur_len = 0, times;       int period;       t =   ;       for (int j = i; j <= n; ++j) t += s[j - 1];       p = calc_prefix(t);       for (int j = i; j <= n; ++j) {         cur_len++;         dp[j] = min(dp[j], dp[i - 1] + cur_len + 1);         period = cur_len - p[j - i];         if (cur_len % period != 0) continue;         dp[j] = min(dp[j], dp[i - 1] + len[cur_len / period] + period);       }     }     cout << dp[n];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 8e+1000;   int n, k, x, c[1000];   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> k >> x;     for (int i = 0; i < n; i++) cin >> c[i];     int res = 0;     for (int i = 0; i < n - 1; i++) {       if (c[i] == c[i + 1] && c[i] == x) {         int l = i - 1, r = i + 2;         while (l >= 0 && r < n) {           bool mark = false;           if (c[l] != c[r]) break;           if (l > 0 && c[l - 1] == c[l]) l--, mark = true;           if (r < n - 1 && c[r + 1] == c[r]) r++, mark = true;           if (mark == false) break;           l--, r++;         }         res = max(res, r - l - 1);       }     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   #define endl   n    #define IOS ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr)   using namespace std;   typedef long long LL;   typedef pair<int, int> PII;   const int maxn = 1e3 + 5;      string input;   int cnt[maxn], mx;   double a, b;      inline double randrand(){       return (double ) rand() / RAND_MAX;   }      int main(){       IOS;       srand(time(nullptr));       int n, m, c1, c2;       char c;       cin >> n >> m;       for(int j = 0; j < m; j++){           cin >> input;           a = b = 0;           if(j){               for (int i = 0; i < n; i++){                   if (input[i] ==  0 ) {                       a += pow(0.9, cnt[i]);                   } else {                       b += pow(0.9, cnt[i]);                   }               }           }           if(a == b) cout << 1 << endl;           else cout << (randrand() <= a / (a + b) ? 0 : 1) << endl;           cout.flush();           cin >> c;           for(int i = 0; i < n; i++){               cnt[i] += (input[i] != c);           }       }   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> afis[1503];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, cnt = 0, i, x = 1;     cin >> n;     afis[++cnt] = {0, 0};     while (x <= n + 1) {       afis[++cnt] = {x, x};       afis[++cnt] = {x, x - 1};       afis[++cnt] = {x - 1, x};       x++;     }     cout << cnt <<   n ;     for (i = 1; i <= cnt; i++)       cout << afis[i].first <<     << afis[i].second <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n, m, k, a[N];   long long rem, cnt, sum;   double ans;   int main() {     cin >> n >> k >> m;     for (int i = 1; i <= n; ++i) {       scanf( %d , a + i);       sum += a[i];     }     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; ++i) {       cnt = n - i + 1;       rem = m - i + 1;       if (rem < 0) {         break;       }       ans = max(ans, (sum + min(rem, cnt * k)) * 1.0 / cnt);       sum -= a[i];     }     printf( %0.9lf , ans);     return 0;   }


#include <bits/stdc++.h>   #include <string>      using namespace std;      bool susp() {       int n;       cin >> n;       string days;       cin >> days;       for (int i = 0; i < n - 1; i++) {           for (int j = i + 1; j < n; j++) {               if (days[j] == days[i] && days[j - 1] != days[i])                   return false;           }       }       return true;   }      int main()   {       int t;       cin >> t;       bool cases[t];       for (int i = 0; i < t; i++) {           cases[i] = susp();       }       for (bool b : cases) {           if (b)               cout <<  YES  << endl;           else               cout <<  NO  << endl;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     set<string> s;     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       string ss;       cin >> ss;       s.insert(ss);     }     cout << 6 - n <<   n ;     if (s.find( purple ) == s.end()) {       cout <<  Power n ;     }     if (s.find( green ) == s.end()) {       cout <<  Time n ;     }     if (s.find( blue ) == s.end()) {       cout <<  Space n ;     }     if (s.find( orange ) == s.end()) {       cout <<  Soul n ;     }     if (s.find( red ) == s.end()) {       cout <<  Reality n ;     }     if (s.find( yellow ) == s.end()) {       cout <<  Mind n ;     }     return 0;   }