#include <bits/stdc++.h>   using namespace std;   int main() {     int a[200010], s[200010], b[200010];     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       s[a[i]] = i;     }     int j = 0;     for (int i = 1; i <= n; i++) {       cin >> b[i];       int ans = s[b[i]] - j;       if (ans < 0)         ans = 0;       else         j = s[b[i]];       cout << ans <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m;     cin >> n >> m;     vector<string> v, l, b;     for (long long int i = 0; i < n; i++) {       string s;       cin >> s;       v.push_back(s);     }     long long int c = -1;     for (long long int i = 0; i < n; i++) {       for (long long int j = 0; j < m + 2; j++) {         if (v[i][j] ==  1 ) {           c = i;           break;         }       }       if (c != -1) break;     }     if (c == -1) {       cout << 0;       return 0;     }     for (long long int i = c; i < n; i++) {       l.push_back(v[i]);     }     n = n - c;     long long int f = n;     for (long long int i = n - 1; i >= 0; i--) {       for (long long int j = 0; j < m + 2; j++) {         if (l[i][j] ==  1 ) {           f = i;           break;         }       }       if (f != n) break;     }     if (f == n) {       cout << 0;       return 0;     }     for (long long int i = 0; i <= f; i++) {       b.push_back(l[i]);     }     long long int g = n;     n = f + 1;     long long int k = 0;     for (long long int i = m + 1; i >= 0; i--) {       if (b[n - 1][i] ==  1 ) {         k = i;         break;       }     }     if (n == 1) {       cout << k + g - 1 - f;     } else {       long long int a[n][m + 2];       memset(a, 0, sizeof(a));       a[n - 1][0] = 2 * k;       a[n - 1][m + 1] = m + 1;       a[n - 2][0] = 2 * k + 1;       a[n - 2][m + 1] = m + 2;       for (long long int i = n - 2; i > 0; i--) {         long long int x1 = 0;         long long int x2 = m + 1;         for (long long int j = m + 1; j >= 0; j--) {           if (b[i][j] ==  1 ) {             x1 = j;             break;           }         }         for (long long int j = 0; j <= (m + 1); j++) {           if (b[i][j] ==  1 ) {             x2 = j;             break;           }         }         a[i - 1][0] = 1 + min(m + 1 + a[i][m + 1], a[i][0] + 2 * x1);         a[i - 1][m + 1] =             1 + min(m + 1 + a[i][0], a[i][m + 1] + 2 * (m + 1 - x2));       }       long long int x1 = 0;       long long int x2 = m + 1;       for (long long int j = m + 1; j >= 0; j--) {         if (b[0][j] ==  1 ) {           x1 = j;           break;         }       }       for (long long int j = 0; j <= (m + 1); j++) {         if (b[0][j] ==  1 ) {           x2 = j;           break;         }       }       cout << min(a[0][0] + x1, a[0][m + 1] + m + 1 - x2) + g - 1 - f << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> m >> n;     vector<string> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     string s =   ;     for (int i = 0; i < n; i++) s +=    ;     vector<string> ans(m, s);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         ans[j][n - i - 1] = a[i][j];       }     swap(n, m);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m / 2; j++) {         swap(ans[i][j], ans[i][m - j - 1]);       }     }     string ss =   ;     for (int i = 0; i < 2 * m; i++) {       ss +=    ;     }     vector<string> ansx2(2 * n, ss);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         ansx2[2 * i][j] = ans[i][j];         ansx2[2 * i + 1][j] = ans[i][j];       }       for (int j = 0; j < m; j++) {         ansx2[2 * i][2 * j] = ans[i][j];         ansx2[2 * i][2 * j + 1] = ans[i][j];         ansx2[2 * i + 1][2 * j] = ans[i][j];         ansx2[2 * i + 1][2 * j + 1] = ans[i][j];       }     }     for (int i = 0; i < 2 * n; i++) {       for (int j = 0; j < 2 * m; j++) {         cout << ansx2[i][j];       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long x = 8 * 9 * 7 * 5;     long long n;     cin >> n;     cout << n / x <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef long long ll;   const int N = 1000;   const int MAX_WEIGHT = 20000;   const ll INF =10000000000000;      int n, m;   vector<int> b[2], a[2];   vector<int> suff[2];   map<int,bool> exist;      int get(int i, int j, int c) {     int result = 0;     int value = b[i][j] + c - 1;     int s = j, e = b[i].size() - 1, mid ,best = j;     while (s <= e) {       mid = s + e;       mid >>= 1;       if (b[i][mid] <= value) {         best = mid;         s = mid + 1;       } else {         e = mid - 1;       }     }     result = best - j + 1;     return result;   }      void solve() {     for (int i = 0 ; i < 2 ; i++) {       sort(a[i].begin(), a[i].end());       sort(b[i].begin(), b[i].end());       suff[i].clear();       suff[i].resize(a[i].size() + 1);     }        suff[0][a[0].size()] = suff[1][a[1].size()] = 0;        for (int j = 0 ; j < 2 ; j++)       for (int i = a[j].size() - 1 ; i >= 0 ; i--) {         suff[j][i] = suff[j][i + 1] + exist[(j == 0 ? 1 : -1) * a[j][i]];       }     int answer = 0;     for (int i = 0 ; i < 2 ; i++) {       if (a[i].size() == 0)         continue;       int last_moved = 0;       int mx = 0;       int num_moved = 1;       for (int j = 0 ; j < (int) b[i].size() ; j++) {         if (b[i][j] < a[i][0])           continue;         while (last_moved != (int) a[i].size() && a[i][last_moved] < b[i][j] + num_moved)           last_moved++, num_moved++;         num_moved--;         last_moved--;         mx = max(mx, suff[i][last_moved + 1] + get(i, j, num_moved));       }       answer += mx;     }     cout << answer << endl;      }      void read() {     cin >> n>> m;     a[0].clear();     b[0].clear();     a[1].clear();     b[1].clear();     exist.clear();     for (int i = 0, a ; i < n ; i++) {       scanf( %d , &a);       ::a[a < 0].push_back(a * (a < 0 ? -1 : 1));     }     for (int i = 0, b ; i < m ; i++) {       scanf( %d , &b);       exist[b] = true;       ::b[b < 0].push_back(b * (b < 0 ? -1 : 1));     }   }      signed main() {     int t = 1;     cin >> t;     while (t--) {       read();       solve();     }        return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int maxn = 1e5 + 15;   const int maxm = 1e6 + 15;   const int mod = 1e9 + 7;   struct Edge {     int to, next;   } edge[maxm];   int head[maxn], dfn[maxn], bccno[maxn], low[maxn];   int ecnt, cnt, bcnt;   void add(int u, int v) {     edge[ecnt].to = v;     edge[ecnt].next = head[u];     head[u] = ecnt++;   }   void init() {     ecnt = 0;     memset(dfn, 0, sizeof dfn);     memset(head, -1, sizeof head);   }   stack<int> Stack;   void tarjan(int fa, int u) {     dfn[u] = low[u] = ++cnt;     Stack.push(u);     for (int i = head[u]; ~i; i = edge[i].next) {       int v = edge[i].to;       if (!dfn[v]) {         tarjan(u, v);         low[u] = min(low[u], low[v]);       } else if (v != fa)         low[u] = min(low[u], dfn[v]);     }     if (low[u] == dfn[u]) {       int v;       bcnt++;       do {         v = Stack.top();         Stack.pop();         bccno[v] = bcnt;       } while (v != u);     }   }   long long quickMod(long long y) {     long long res = 1, x = 2;     while (y) {       if (y & 1) res = res * x % mod;       x = x * x % mod;       y >>= 1;     }     return res;   }   int w[maxn], x[maxn], y[maxn];   namespace hld {   int son[maxn], par[maxn], size[maxn], top[maxn];   int tid[maxn], dep[maxn], c[maxn], tot, n;   void init(int _n) {     n = _n, tot = 0;     memset(tid, 0, sizeof tid);     memset(c, 0, sizeof c);   }   void dfs1(int u, int fa, int depth = 0) {     par[u] = fa;     dep[u] = depth;     size[u] = 1;     son[u] = 0;     int maxx = 0;     for (int i = head[u]; ~i; i = edge[i].next) {       int v = edge[i].to;       if (v == fa) continue;       dfs1(v, u, depth + 1);       size[u] += size[v];       if (size[v] > maxx) {         maxx = size[v];         son[u] = v;       }     }   }   int lowbit(int x) { return x & -x; }   void Add(int x, int y) {     for (; x <= n; x += lowbit(x)) c[x] += y;   }   void dfs2(int u, int acs) {     tid[u] = ++tot, top[u] = acs;     if (w[u]) Add(tot, 1);     if (!son[u]) return;     dfs2(son[u], acs);     for (int i = head[u]; ~i; i = edge[i].next) {       int v = edge[i].to;       if (tid[v]) continue;       dfs2(v, v);     }   }   int sum(int x) {     int res = 0;     for (; x; x -= lowbit(x)) res += c[x];     return res;   }   int query(int u, int v) {     int f1 = top[u], f2 = top[v], res = 0;     while (f1 != f2) {       if (dep[f1] < dep[f2]) swap(f1, f2), swap(u, v);       res += sum(tid[u]) - sum(tid[f1] - 1);       u = par[f1], f1 = top[u];     }     if (dep[u] > dep[v]) swap(u, v);     return res += sum(tid[v]) - sum(tid[u] - 1);   }   }  // namespace hld   int main() {     int n, m;     scanf( %d %d , &n, &m);     init();     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d %d , &u, &v);       add(u, v);       add(v, u);       x[i] = u, y[i] = v;     }     for (int i = 1; i <= n; i++)       if (!dfn[i]) tarjan(0, i);     for (int i = 1; i <= n; i++) w[bccno[i]]++;     for (int i = 1; i <= bcnt; i++) w[i] = (w[i] == 1 ? 0 : 1);     ecnt = 0;     memset(head, -1, sizeof head);     for (int i = 1; i <= m; i++) {       int u = bccno[x[i]], v = bccno[y[i]];       if (u == v) continue;       add(u, v), add(v, u);     }     int k;     scanf( %d , &k);     hld::init(n);     hld::dfs1(1, 0), hld::dfs2(1, 1);     while (k--) {       int u, v;       scanf( %d %d , &u, &v);       long long ans = quickMod(hld::query(bccno[u], bccno[v]));       if (ans >= mod) ans -= mod;       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 55;   int n;   int xi[maxn], yi[maxn];   int ans1 = 0, ans2 = 0;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &xi[i]), ans1 += xi[i];     for (int i = 1; i <= n; i++) scanf( %d , &yi[i]), ans2 += yi[i];     if (ans1 < ans2)       printf( No n );     else       printf( Yes n );     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   template <class T1, class T2>   ostream &operator<<(ostream &os, const pair<T1, T2> &p) {     os <<  {  << p.first <<  ,  << p.second <<  } ;     return os;   }   const int N = 3e5 + 5;   const int oo = 1e9 + 7;   int a[N];   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int tot1 = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i];       tot1 += a[i];     }     bool res = a[1];     for (int i = 2; i <= n; i++) {       res = !res or a[i];     }     if (res == 0) {       cout <<  YES n  << a[1];       for (int i = 2; i <= n; i++) cout <<  ->  << a[i];       cout <<   n ;     } else if (a[n] == 1 or n <= 2 or (a[n - 2] == 1 and tot1 == n - 2)) {       cout <<  NO n ;     } else if (a[n - 2] == 0) {       cout <<  YES n  << a[1];       for (int i = 2; i <= n - 3; i++) cout <<  ->  << a[i];       cout <<  ->(  << a[n - 2] <<  ->  << a[n - 1] <<  )->  << a[n] <<   n ;     } else {       int zero = -1;       for (int i = n - 3; i >= 1; i--)         if (a[i] == 0) {           zero = i;           break;         }       assert(zero != -1);       cout <<  YES n ;       if (zero > 1) {         cout << a[1];         for (int i = 2; i < zero; i++) {           cout <<  ->  << a[i];         }         cout <<  -> ;       }       cout <<  (  << a[zero] <<  ->((  << a[zero + 1];       for (int i = zero + 2; i <= n - 2; i++) cout <<  ->  << a[i];       cout <<  )->  << a[n - 1] <<  ))->  << a[n] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 502;   vector<int> adj[maxn];   bool vis[maxn];   bool fin[maxn];   vector<pair<int, int> > edgesInCycle;   int n;   bool dfs(int node) {     vis[node] = 1;     for (int ch : adj[node]) {       edgesInCycle.push_back({node, ch});       if (!vis[ch]) {         if (dfs(ch)) return 1;       } else if (!fin[ch])         return 1;       edgesInCycle.pop_back();     }     fin[node] = 1;     return 0;   }   bool checkDag() {     memset(vis, 0, sizeof(vis));     memset(fin, 0, sizeof(fin));     for (int i = 1; i <= n; ++i) {       if (!vis[i] && dfs(i)) return 0;     }     return 1;   }   bool solve() {     if (checkDag()) return 1;     vector<pair<int, int> > edges = edgesInCycle;     for (pair<int, int> edge : edges) {       int u = edge.first;       int v = edge.second;       auto it = find(adj[u].begin(), adj[u].end(), v);       assert(it != adj[u].end());       adj[u].erase(it);       if (checkDag()) return 1;       adj[u].push_back(v);     }     return 0;   }   int main() {     int m;     cin >> n >> m;     int u, v;     for (int i = 0; i < m; ++i) {       cin >> u >> v;       adj[u].push_back(v);     }     cout << (solve() ?  YES n  :  NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t;     cin >> n >> t;     if (n == 1 && t == 10) {       cout <<  -1  << endl;       return 0;     }     cout << ((t == 10) ? 1 : t);     while (n-- > 1) {       cout <<  0 ;     }     return 0;   }


#include <iostream>   #include <algorithm>   #include <cstdio>   #include <vector>   #include <stack>   #include <string>   #include <cstring>   #include <queue>   #include <map>   #include <set>   #include <cmath>   #include <climits>   #include <functional>      typedef long long ll;      using namespace std;      int main()   {   #ifdef ONLINE_JUDGE   #else       freopen( in1.txt ,  r , stdin);       // freopen( w.txt ,  w , stdout);   #endif       // ios::sync_with_stdio(false);              ll T, d, k;       for (cin >> T; T--;) {           cin >> d >> k;              ll cnt = 0;           while ((cnt * k) * (cnt * k) * 2 <= d * d) {               ++cnt;           }           --cnt;                      ll res = (cnt * k) * (cnt * k) + (cnt * k + k) * (cnt * k + k);              cout << (res <= d * d ?  Ashish  :  Utkarsh ) << endl;          }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     static char data[100015];     static int a[100015];     static int b[100015];     memset(a, 0, sizeof(a));     memset(b, 0, sizeof(b));     int i, j, N, len;     N = 0;     scanf( %s n , data);     len = strlen(data);     if (len > N) N = len;     for (i = 0; i < len; i++) {       a[len - i - 1] = (int)(data[i] -  0 );     }     scanf( %s , data);     len = strlen(data);     if (len > N) N = len;     for (i = 0; i < len; i++) {       b[len - i - 1] = (int)(data[i] -  0 );     }     N += 5;     for (i = N; i >= 0; i--) {       j = i;       while ((a[j]) && (a[j + 1])) {         a[j] = 0;         a[j + 1] = 0;         a[j + 2] = 1;         j += 2;       }       j = i;       while ((b[j]) && (b[j + 1])) {         b[j] = 0;         b[j + 1] = 0;         b[j + 2] = 1;         j += 2;       }     }     i = N;     while ((i >= 0) && (a[i] == b[i])) i--;     if (i < 0)       printf( = );     else if (a[i] > b[i])       printf( > );     else       printf( < );     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long powr(long long a, long long b) {     long long res = 1;     while (b) {       if (b % 2 == 1) res = res * a % 1000000007;       a = a * a % 1000000007;       b /= 2;     }     return res;   }   int main() {     int p, k;     cin >> p >> k;     vector<int> g[p];     bool x[p];     memset(x, false, sizeof x);     vector<set<long long>> a;     if (k == 0) {       long long ans = powr(p, p - 1);       cout << ans <<   n ;       return 0;     }     for (int i = 0; i < p; ++i) {       if (x[i]) continue;       x[i] = 1;       long long yy = i;       set<long long> xz;       xz.insert(i);       do {         yy *= k;         yy %= p;         x[yy] = 1;         xz.insert(yy);       } while (yy != i);       a.push_back(xz);     }     long long ans = 1;     ans = powr(p, a.size() - 1);     if (k == 1) {       ans *= p;       ans %= 1000000007;     }     cout << ans <<   n ;   }


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


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using uint = unsigned int;   using rl = double;   using pii = pair<int, int>;   const int MAXN = 3 * 100009;   int n, m;   struct Vert {     vector<int> to;     vector<pair<int, int>> qlist;     int depth;     ll vsum;   } v[MAXN];   ll psum[2 * MAXN];   void dfs(int it, int p, ll sum) {     v[it].depth = v[p].depth + 1;     for (auto q : v[it].qlist) {       psum[v[it].depth] += q.first;       psum[v[it].depth + q.second + 1] -= q.first;     }     sum += psum[v[it].depth];     v[it].vsum = sum;     for (auto t : v[it].to) {       if (t == p) continue;       dfs(t, it, sum);     }     for (auto q : v[it].qlist) {       psum[v[it].depth] -= q.first;       psum[v[it].depth + q.second + 1] += q.first;     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int a, b;       scanf( %d %d , &a, &b);       v[a].to.push_back(b);       v[b].to.push_back(a);     }     scanf( %d , &m);     for (int i = 0; i < m; i++) {       int it, d, x;       scanf( %d %d %d , &it, &d, &x);       v[it].qlist.push_back({x, min(d, n - 1)});     }     dfs(1, 0, 0);     for (int i = 1; i <= n; i++) {       printf( %lld  , v[i].vsum);     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   char a[100005];   int b[100005];   map<pair<int, int>, int> maps;   int main() {     int nx, ny, x, y, x1, y1, n;     scanf( %d%d%d%d , &nx, &ny, &x, &y);     scanf(  %s , a);     for (int i = 0; i < 100005; i++) b[i] = 0;     b[0] = 1;     maps[make_pair(x, y)] = 1;     for (n = 0; a[n] !=   0 ; n++)       ;     for (int i = 0; i < n; i++) {       switch (a[i]) {         case  L :           y1 = y - 1;           x1 = x;           break;         case  R :           y1 = y + 1;           x1 = x;           break;         case  U :           x1 = x - 1;           y1 = y;           break;         case  D :           x1 = x + 1;           y1 = y;           break;       }       if (x1 <= nx && y1 <= ny && x1 > 0 && y1 > 0) {         if (maps[make_pair(x1, y1)] == 0) {           b[i + 1]++;           maps[make_pair(x1, y1)] = 1;         }         x = x1;         y = y1;       }     }     b[n] += nx * ny - maps.size();     for (int i = 0; i <= n; i++) printf( %d  , b[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     stack<char> st;     for (int i = 0; i < s.length(); i++) {       if (st.empty()) {         st.push(s[i]);       } else if (st.top() == s[i]) {         st.pop();       } else {         st.push(s[i]);       }     }     if (st.empty()) {       cout <<  Yes ;     } else {       cout <<  No ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 1e5 + 5;   const long long int mod = 1e15 + 7;   long long int dx[] = {1, -1, 0, 0};   long long int dy[] = {0, 0, 1, -1};   long long int y[N], yy[N], len[N];   long long int n, m, low, high, mid1, mid2;   double ans = (double)mod;   long long int ans_n, ans_m;   long long int a, b;   double find_distance(double x, double y, double u, double v) {     double temp = ((x - u) * (x - u) + (y - v) * (y - v));     temp = sqrt(temp);     return temp;   }   int main() {     cin >> n >> m >> a >> b;     for (long long int i = 1; i < n + 1; i++) {       cin >> y[i];     }     for (long long int i = 1; i < m + 1; i++) {       cin >> yy[i];     }     for (long long int i = 1; i < m + 1; i++) {       cin >> len[i];     }     for (long long int i = 1; i < m + 1; i++) {       low = 1;       high = n;       while ((high - low) > 5) {         mid1 = low + (high - low) / 3;         mid2 = low + 2 * (high - low) / 3;         double dis1 = find_distance(0, 0, a, y[mid1]) +                       find_distance(a, y[mid1], b, yy[i]) + len[i];         double dis2 = find_distance(0, 0, a, y[mid2]) +                       find_distance(a, y[mid2], b, yy[i]) + len[i];         if (dis1 < dis2) {           high = mid2;         } else {           low = mid1;         }       }       for (long long int zz = low; zz < high + 1; zz++) {         double temp = find_distance(0, 0, a, y[zz]) +                       find_distance(a, y[zz], b, yy[i]) + len[i];         if (temp < ans) {           ans = temp;           ans_n = zz;           ans_m = i;         }       }     }     cout << ans_n <<     << ans_m << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ii = tuple<long long, long long>;   const long long N = 1e6 + 7, inf = 1e9 + 42;   long long binpow(long long a, long long b) {     if (b == 0) return 1;     long long res = binpow(a, b / 2);     if (b % 2)       return (res * res * a) % 1000000007;     else       return (res * res) % 1000000007;   }   bool compare(pair<long long, long long> a, pair<long long, long long> b) {     return (a.first - a.second > b.first - b.second);   }   long long n;   vector<long long> prime_factors;   signed main() {     puts( Odd );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using pil = pair<long long, long long>;   using pii = pair<long long, long long>;   using pid = pair<double, double>;   long long mod = 1e9 + 7;   long long power(long long a, long long n) {     long long res = 1;     while (n) {       if (n % 2) res = (res * a) % mod;       a = (a * a) % mod;       n /= 2;     }     return res;   }   void solve() {     long long a, b;     cin >> a >> b;     long long B = (b * (b - 1) / 2) % mod;     long long A = ((a * (a + 1) / 2) % mod) * b + a;     A %= mod;     long long ans = (A * B) % mod;     cout << ans << endl;   }   int32_t main() {     long long t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 20;   int n, m;   struct line {     int type, x, y, lag;     line() { type = x = y = lag = 0; }     line(int a, int b, int c, int d) { type = a, x = b, y = c, lag = d; }     bool operator<(const line &a) const { return y > a.y; }   } t[7 * N];   int a[N], qu;   set<int> s[N];   long long f[N], ans[N];   void add(int x, int y) {     while (x <= n) {       f[x] += y;       x += x & (-x);     }   }   long long query(int x) {     long long ret = 0;     while (x) {       ret += f[x];       x -= x & (-x);     }     return ret;   }   void cdq(int l, int r) {     if (l == r) return;     int mid = l + r >> 1;     cdq(l, mid), cdq(mid + 1, r);     int j = l;     for (int i = mid + 1; i <= r; i++) {       while (j <= mid && t[j].y >= t[i].y) {         if (t[j].type == 0) add(t[j].x, (t[j].x - t[j].y) * t[j].lag);         j++;       }       if (t[i].type == 1) ans[t[i].lag] += query(t[i].x);     }     for (int i = l; i < j; i++)       if (t[i].type == 0) add(t[i].x, -(t[i].x - t[i].y) * t[i].lag);     sort(t + l, t + r + 1);   }   set<int>::iterator it;   int main() {     scanf( %d%d , &n, &m);     int cnt = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       if (s[a[i]].size()) {         it = s[a[i]].end();         it--;         t[++cnt] = line(0, i, *it, 1);       } else         t[++cnt] = line(0, i, 0, 1);       s[a[i]].insert(i);     }     int opt, x, y;     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &opt, &x, &y);       if (opt == 1) {         int L = 0, R = 0;         it = s[a[x]].find(x);         if (it != s[a[x]].begin()) t[++cnt] = line(0, x, L = *--it, -1), it++;         if (++it != s[a[x]].end()) t[++cnt] = line(0, R = *it, x, -1);         if (L && R) t[++cnt] = line(0, R, L, 1);         s[a[x]].erase(x);         s[a[x] = y].insert(x);         it = s[y].find(x), L = R = 0;         if (it != s[y].begin()) t[++cnt] = line(0, x, L = *--it, 1), it++;         if (++it != s[y].end()) t[++cnt] = line(0, R = *it, x, 1);         if (L && R) t[++cnt] = line(0, R, L, -1);       } else         t[++cnt] = line(1, y, x, ++qu);     }     cdq(1, cnt);     for (int i = 1; i <= qu; i++) printf( %lld n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &n) {     T w = 1;     n = 0;     char ch = getchar();     while (!isdigit(ch) && ch != EOF) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (isdigit(ch) && ch != EOF) {       n = (n << 3) + (n << 1) + (ch & 15);       ch = getchar();     }     n *= w;   }   template <typename T>   inline void write(T x) {     T l = 0;     unsigned long long y = 0;     if (!x) {       putchar(48);       return;     }     if (x < 0) {       x = -x;       putchar( - );     }     while (x) {       y = y * 10 + x % 10;       x /= 10;       ++l;     }     while (l) {       putchar(y % 10 + 48);       y /= 10;       --l;     }   }   template <typename T>   inline void writes(T x) {     write(x);     putchar(   );   }   template <typename T>   inline void writeln(T x) {     write(x);     puts(  );   }   template <typename T>   inline void checkmax(T &a, T b) {     a = a > b ? a : b;   }   template <typename T>   inline void checkmin(T &a, T b) {     a = a < b ? a : b;   }   const int N = 1e5 + 10, M = 2e5 + 10;   int n, m, cnt, head[N], nxt[M << 1], to[M << 1], vis[N], in[N], dep[N],       depth[N], depto[N], sum[N], ok[N];   inline int rd() {     return int((long long)(rand() % 100000) * (rand() % 100000) % 998244353);   }   inline void addedge(int x, int y) {     nxt[++cnt] = head[x];     to[cnt] = y;     head[x] = cnt;   }   inline bool check(int x) {     vis[x] = in[x] = 1;     bool f = 1;     for (int i = head[x]; i; i = nxt[i]) {       if (vis[to[i]] && !in[to[i]]) return 0;       if (vis[to[i]]) continue;       f &= check(to[i]);     }     in[x] = 0;     return f;   }   inline void dfs(int x) {     vis[x] = 1;     for (int i = head[x]; i; i = nxt[i]) {       if (vis[to[i]]) {         if (depth[to[i]] < dep[x]) {           dep[x] = depth[to[i]];           depto[x] = to[i];         }         sum[x]++;         sum[to[i]]--;         continue;       }       depth[to[i]] = depth[x] + 1;       dfs(to[i]);       sum[x] += sum[to[i]];       if (dep[x] > dep[to[i]]) {         dep[x] = dep[to[i]];         depto[x] = depto[to[i]];       }     }   }   inline void dfs2(int x) {     vis[x] = 1;     if (sum[x] >= 2 || (sum[x] == 1 && ok[depto[x]])) ok[x] = 1;     for (int i = head[x]; i; i = nxt[i]) {       if (vis[to[i]]) continue;       dfs2(to[i]);     }   }   inline void doit(int rt) {     for (int i = 1; i <= n; ++i) {       vis[i] = sum[i] = ok[i] = 0;       dep[i] = n * 2 + 1;     }     depth[rt] = 0;     dfs(rt);     for (int i = 1; i <= n; ++i) vis[i] = 0;     dfs2(rt);     int ans = 0;     for (int i = 1; i <= n; ++i)       if (!ok[i]) ++ans;     if (ans * 5 < n) {       puts( -1 );       return;     }     for (int i = 1; i <= n; ++i)       if (!ok[i]) writes(i);     puts(  );   }   inline void solve() {     read(n);     read(m);     for (int i = 1; i <= n; ++i) head[i] = vis[i] = in[i] = 0;     cnt = 0;     for (int i = 1; i <= m; ++i) {       int x, y;       read(x);       read(y);       addedge(x, y);     }     for (int i = 1; i <= 50; ++i) {       int num = rd() % n + 1;       for (int i = 1; i <= n; ++i) vis[i] = in[i] = 0;       if (check(num)) {         doit(num);         return;       }     }     puts( -1 );   }   int main() {     srand(time(0) + 1432433);     int t;     read(t);     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, n, i, p[1001], sz[1001], cnt[1001];   vector<pair<int, int> > v2;   vector<int> v;   int find_p(int a) {     if (p[a] == a) return a;     return p[a] = find_p(p[a]);   }   void unionn(int a, int b) {     int _a = a, _b = b;     a = find_p(a);     b = find_p(b);     if (a != b) {       if (sz[a] < sz[b]) swap(a, b);       p[b] = a;       sz[a] += sz[b];     } else       v2.push_back({_a, _b});   }   int main() {     cin >> n;     for (i = 1; i <= n; i++) p[i] = i, sz[i] = 1;     for (i = 1; i < n; i++) {       cin >> a >> b;       unionn(a, b);     }     cout << v2.size() << endl;     for (i = 1; i <= n; i++) {       p[i] = find_p(i);       if (!cnt[p[i]]) {         v.push_back(p[i]);         cnt[p[i]] = 1;       }     }     for (i = 0; i < v2.size(); i++) {       cout << v2[i].first <<     << v2[i].second <<     << v[i] <<     << v[i + 1]            << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   auto main() -> int {     int N, X, Y;     cin >> N;     vector<int> C(N);     for (int i = 0; i < N; i++) cin >> C[i];     cin >> X >> Y;     int l = 0;     int ret = 0;     for (int i = 0; i < N; i++) {       if (l < X) {         if (l + C[i] <= Y)           l += C[i];         else           break;       } else if (l >= X && l <= Y) {         int t = 0;         for (int j = i; j < N; j++) t += C[j];         if (t >= X && t <= Y) {           ret = i + 1;           break;         } else {           l += C[i];         }       }     }     cout << ret << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M, i, j;   int a, b, v[105];   bool ok = true;   int main() {     cin >> N >> M;     for (i = 1; i <= N; i++) {       cin >> a >> b;       a++;       v[a]++;       v[b + 1]--;     }     for (i = 1; i <= M; i++) {       v[i] += v[i - 1];       if (v[i] == 0) ok = false;     }     if (ok == true)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int OO = 1e9, N = 1e5;   int main() {     long long n, c = 0, o = 0;     cin >> n;     string s;     cin >> s;     queue<int> q;     for (int i = 0; i < n; i++) {       o += (s[i] ==  ( );       c += (s[i] ==  ) );     }     int sma7 = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  )  && !q.empty())         q.pop();       else if (s[i] ==  ) )         sma7++;       else         q.push(0);     }     if (o == c && sma7 <= 1)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[100009], x[100009], h[100009], id[100009], seg[400009];   void upd(int pos, int l, int r, int pp, int v) {     if (l == r) {       seg[pos] = v;       return;     }     int m = (l + r) / 2;     if (m >= pp)       upd(2 * pos + 1, l, m, pp, v);     else       upd(2 * pos + 2, m + 1, r, pp, v);     seg[pos] = max(seg[2 * pos + 1], seg[2 * pos + 2]);   }   int qu(int pos, int l, int r, int b, int e) {     if (b <= l && r <= e) return seg[pos];     int m = (l + r) / 2;     int r1 = 0, r2 = 0;     if (m >= b) r1 = qu(2 * pos + 1, l, m, b, e);     if (m < e) r2 = qu(2 * pos + 2, m + 1, r, b, e);     return max(r1, r2);   }   int ans[100009];   void bs(int i, int l, int r) {     int m;     int o = x[i] + h[i] - 1;     while (r - l > 1) {       m = (l + r) / 2;       if (o < x[m])         r = m;       else         l = m;     }     if (l == i)       ans[id[i]] = i;     else       ans[id[i]] = qu(0, 0, n - 1, i + 1, l);     upd(0, 0, n - 1, i, ans[id[i]]);     ans[id[i]] -= i;     ans[id[i]]++;   }   pair<int, pair<int, int> > p[100009];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x[i] >> h[i];       p[i] = {x[i], {h[i], i}};     }     sort(p, p + n);     for (int i = 0; i < n; i++) {       x[i] = p[i].first;       h[i] = p[i].second.first;       id[i] = p[i].second.second;     }     ans[id[n - 1]] = 1;     upd(0, 0, n - 1, n - 1, n - 1);     for (int i = n - 2; i >= 0; i--) {       bs(i, i, n);     }     for (int i = 0; i < n; i++) cout << ans[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int arr[1005];   int res[1005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; ++i) cin >> arr[i];     sort(arr, arr + n);     int ini = 0, fin = n - 1, idx = 0;     while (ini <= fin) {       res[idx] = arr[ini++];       res[idx + 1] = arr[fin--];       idx += 2;     }     for (int i = 0; i < n; ++i) cout << res[i] <<    ;     cout <<   n ;     return 0;   }


using namespace std;   #include <cstdio>   #include <cstring>   #include <algorithm>   #include <ctime>   #include <cstdlib>   #include <set>   #include <map>   #define N 1005   #define ll long long   ll mul(ll a,ll b,ll mo){    a%=mo,b%=mo;    ll c=a*b-(ll)((long double)a*b/mo)*mo;    if (c<0) c+=mo;    if (c>=mo) c-=mo;    return c;   }   ll qpow(ll x,ll y,ll mo){    ll r=1;    for (;y;y>>=1,x=mul(x,x,mo))     if (y&1)      r=mul(r,x,mo);    return r;   }   int n,k;   ll a[N];   ll p[N][100],np[N];   const int tst[10]={2,3,5,7,11,13,17,19,23,29};   bool mr(ll x){    if (x==1 || x==0)     return 0;    for (int i=0;i<10;++i){     if (x==tst[i])      return 1;     if (x%tst[i]==0)      return 0;    }    ll z=x-1,y=0;    while (z&1^1)     z>>=1,++y;    for (int i=0;i<10;++i){     ll t=qpow(tst[i],z,x);     if (t==1 || t==x-1)      continue;     for (int j=1;j<y;++j){      t=mul(t,t,x);      if (t==x-1)       break;     }     if (t!=x-1)      return 0;    }    return 1;   }   #define irand (rand()*RAND_MAX+rand())   ll gcd(ll a,ll b){    ll k;    while (b)     k=a%b,a=b,b=k;    return a;   }   ll pr(ll n){    while (1){     ll a=irand%n,c=irand%n,b=a,s=1;     for (int i=1,k=2;1;++i){      a=(mul(a,a,n)+c)%n;      if (a==b)       break;      ll t=mul(s,abs(a-b),n);      if (t==0)       return gcd(s,n);      s=t;      if (i==k){       ll g=gcd(s,n);       if (g!=1)        return g;       b=a;       k<<=1;       continue;      }      if (!(i&127)){       ll g=gcd(s,n);       if (g!=1)        return g;      }     }    }   }   void divide(ll x,int id){    if (x==1)     return;    if (mr(x)){     p[id][np[id]++]=x;     return;    }    ll d=pr(x);    divide(d,id);    divide(x/d,id);   }   map<int,pair<int,int> > S;   set<int> T;   bool legal[N];   bool b[N];   int main(){   // freopen( in.txt , r ,stdin);   // freopen( out.txt , w ,stdout);    srand(time(0)* *new(int));    scanf( %d%d ,&n,&k);    for (int i=1;i<=n;++i)     scanf( %lld ,&a[i]);    for (int i=1;i<=n;++i){     divide(a[i],i);     sort(p[i],p[i]+np[i]);     np[i]=unique(p[i],p[i]+np[i])-p[i];     if (np[i]==1){      auto q=S.find(p[i][0]);      if (q==S.end())       S[p[i][0]].first=i,b[i]=1;      else if (q->second.second==0)       q->second.second=i,b[i]=1;     }    }    for (auto q=S.begin();q!=S.end();)     if (q->second.second==0)      q=S.erase(q);     else      ++q;    int mn=0;    np[0]=77114514;    int ex=0;    for (int i=1;i<=n;++i){     legal[i]=1;     for (int j=0;j<np[i] && legal[i];++j){      auto q=S.find(p[i][j]);      if (q==S.end())       legal[i]=0;     }     if (legal[i]){      if (!b[i]){       ex++;       if (np[i]<np[mn])        mn=i;      }     }     else      b[i]=0;    }    static int ls[N];    if (k>=S.size()*2){     k-=S.size()*2;     if (k>ex){      printf( 0 n );      return 0;     }     for (int i=1;i<=n;++i){      if (!legal[i])       continue;      if (b[i])       printf( %lld  ,a[i]);      else if (k){       printf( %lld  ,a[i]);       k--;          }     }    }    else if (k>=np[mn]*2+(mn!=0)){     for (int i=0;i<np[mn];++i){      T.insert(p[mn][i]);      ls[i*2+1]=S[p[mn][i]].first;      ls[i*2+2]=S[p[mn][i]].second;     }     int i=np[mn]*2;     if (k&1)      ls[++i]=mn;     for (auto q=S.begin();q!=S.end() && i<k;++q)      if (T.find(q->first)==T.end()){       ls[i+1]=q->second.first;       ls[i+2]=q->second.second;       i+=2;      }     sort(ls+1,ls+k+1);     for (int i=1;i<=k;++i)      printf( %lld  ,a[ls[i]]);    }    else{     if (k&1)      printf( 0 );     else{      int i=0;      for (auto q=S.begin();q!=S.end() && i<k;++q,i+=2){       ls[i+1]=q->second.first;       ls[i+2]=q->second.second;      }      sort(ls+1,ls+k+1);      for (int i=1;i<=k;++i)       printf( %lld  ,a[ls[i]]);     }    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const double pi = acos(-1);   const long long inf = 0x3f3f3f3f3f3f3f3f;   const int INF = 0x3f3f3f3f;   const int MAX = 2e5 + 10;   const long long mod = 1e9 + 7;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   char c[3] = { R ,  G ,  B };   int main() {     int t;     cin >> t;     while (t--) {       int dif[3] = {0};       int n, k;       cin >> n >> k;       string s;       cin >> s;       for (int i = (0); i < (3); ++i) {         for (int j = (0); j < (k); ++j) {           if (s[j] != c[(j + i) % 3]) dif[i]++;         }       }       int ans = 0;       ans = min(dif[0], min(dif[1], dif[2]));       for (int i = 1; i + k - 1 < n; i++) {         int a0 = dif[0], a1 = dif[1], a2 = dif[2];         dif[0] = a2 - (s[i - 1] ==  B  ? 0 : 1) +                  (s[i + k - 1] == c[(k - 1) % 3] ? 0 : 1);         dif[1] =             a0 - (s[i - 1] ==  R  ? 0 : 1) + ((s[i + k - 1] == c[k % 3]) ? 0 : 1);         dif[2] = a1 - (s[i - 1] ==  G  ? 0 : 1) +                  ((s[i + k - 1] == c[(k + 1) % 3]) ? 0 : 1);         ans = min(ans, min(dif[0], min(dif[1], dif[2])));       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 500005, INF = 0x3f3f3f3f;   int ta, tb, n, T;   long long t[maxn], t1[maxn];   int main(void) {     cin >> n >> ta >> tb >> T;     string s;     char a;     cin >> a;     if (a ==  w ) T -= tb;     T--;     if (T < 0) {       cout << 0 << endl;       return 0;     }     cin >> s;     for (int i = 0; i < n - 1; i++) {       t[i] = t[i - 1] + 1 + ta;       if (s[i] ==  w ) t[i] += tb;     }     reverse(s.begin(), s.end());     for (int i = 0; i < n - 1; i++) {       t1[i] = t1[i - 1] + 1 + ta;       if (s[i] ==  w ) t1[i] += tb;     }     int res = 0;     for (int i = 0; i < n; i++) {       if (t1[i - 1] > T) break;       int l = 0, r = n - i;       while (l < r - 1) {         int mid = (l + r) / 2;         if (mid > 0 && t1[i - 1] + t[mid - 1] + i * ta <= T)           l = mid;         else           r = mid;       }       res = max(res, l + i);     }     for (int i = 0; i < n; i++) {       if (t[i - 1] > T) break;       int l = 0, r = n - i;       while (l < r - 1) {         int mid = (l + r) / 2;         if (mid > 0 && t[i - 1] + t1[mid - 1] + i * ta <= T)           l = mid;         else           r = mid;       }       res = max(res, l + i);     }     cout << res + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool dif[10];   int p[1005], n, x, y, ans1, ans2;   inline void chk(int p) {     int i, sz = 0, res;     for (i = 1; i <= n; i++) {       if (i & (1 << p)) {         sz++;       }     }     if (sz == 0) {       dif[p] = 0;       return;     }     printf( ? %d  , sz);     for (i = 1; i <= n; i++) {       if (i & (1 << p)) {         printf( %d  , i);       }     }     printf(  n );     fflush(stdout);     scanf( %d , &res);     if (sz & 1) {       if (res == x) {         dif[p] = 0;         return;       }       if (res == y) {         dif[p] = 1;         return;       }     } else {       if (res == (x ^ y)) {         dif[p] = 1;         return;       }       if (res == 0) {         dif[p] = 0;         return;       }     }   }   inline bool ok(int pr) {     int res, i;     printf( ? %d  , pr);     for (i = 1; i <= pr; i++) {       printf( %d  , p[i]);     }     printf(  n );     fflush(stdout);     scanf( %d , &res);     if (pr & 1) {       if (res == x) {         return 0;       }       if (res == y) {         return 1;       }     } else {       if (res == (x ^ y)) {         return 1;       }       if (res == 0) {         return 0;       }     }   }   inline int get(int x) {     int i, cnt = 0;     for (i = 1; i <= n; i++) {       if (!(i & (1 << x))) {         continue;       }       p[++cnt] = i;     }     int l = 1, r = cnt;     while (l <= r) {       int mid = (l + r) >> 1;       if (ok(mid)) {         r = mid - 1;       } else {         l = mid + 1;       }     }     return p[l];   }   int main() {     int i;     scanf( %d%d%d , &n, &x, &y);     for (i = 9; i >= 0; i--) {       chk(i);     }     for (i = 9; i >= 0; i--) {       if (dif[i]) {         ans1 = get(i);         break;       }     }     ans2 = ans1;     for (i = 9; i >= 0; i--) {       if (dif[i]) {         ans2 ^= (1 << i);       }     }     printf( ! %d %d n , ans2, ans1);     fflush(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   queue<char> q;   vector<int> sp;   int main() {     long long n, l = 0, r = 0, k = 0;     cin >> s;     if (s[0] !=  a  && s[0] !=  e  && s[0] !=  u  && s[0] !=  o  && s[0] !=  i ) {       q.push(s[0]);       k = 1;     }     for (int i = 1; i < s.size(); i++) {       if (s[i] !=  a  && s[i] !=  e  && s[i] !=  u  && s[i] !=  o  &&           s[i] !=  i ) {         if (s[i] != s[i - 1]) q.push(s[i]);         k++;         if (k >= 3 && q.size() > 1) {           sp.push_back(i);           n = q.size();           while (q.size() > 1) q.pop();           k = 1;         }       } else {         while (q.size() != 0) q.pop();         k = 0;       }     }     int j = 0;     sp.push_back(s.size());     for (int i = 0; i < s.size(); i++) {       while (i < sp[j]) {         cout << s[i];         i++;       }       j++;       if (i < s.size()) cout <<     << s[i];     }     return 0;   }


#include <iostream>   #include <string>   #include <vector>      constexpr int N = 1000005;   constexpr int p = 1000000007;      inline int add(int x, int y) { return (x += y) >= p ? x - p : x; }   inline int sub(int x, int y) { return (x -= y) < 0 ? x + p : x; }   inline int mul(int x, int y) { return (long long)x * y % p; }   inline int power(int x, int y) { int ans = 1; for (; y; y >>= 1) { if (y & 1) ans = mul(ans, x); x = mul(x, x); } return ans; }      int n, q, k;   std::string s0, t, w;   int pow2[N], nxt[N];   int sum[N][26];   std::vector<std::string> str;      int main() {       std::ios::sync_with_stdio(false), std::cin.tie(nullptr);       std::cin >> n >> q;       std::cin >> s0 >> t;       pow2[0] = 1;       for (int i = 1; i <= n; ++i) pow2[i] = add(pow2[i - 1], pow2[i - 1]);       for (int i = 1; i <= n; ++i) {           for (int j = 0; j < 26; ++j) sum[i][j] = sum[i - 1][j];           sum[i][t[i - 1] -  a ] = add(sum[i][t[i - 1] -  a ], power(pow2[i], p - 2));       }       std::string tmp = s0;       str.push_back(tmp);       int x = 0;       while (tmp.length() < N << 1) {           tmp = tmp + t[x++] + tmp;           str.push_back(tmp);       }       while (q--) {           std::cin >> k >> w;           int x = 0;           while (str[x].length() < w.length() && x < k) ++x;           nxt[0] = -1;           int now = -1;           for (int i = 1; i < w.length(); ++i) {               while (~now && w[now + 1] != w[i]) now = nxt[now];               if (w[now + 1] == w[i]) ++now;               nxt[i] = now;           }           now = -1;           int cnt0 = 0;           std::string& s = str[x];           for (int i = 0; i < s.length(); ++i) {               while (~now && w[now + 1] != s[i]) now = nxt[now];               if (w[now + 1] == s[i]) ++now;               if (now == w.length() - 1) {                   ++cnt0;                   now = nxt[now];               }           }           int index = s.length();           int ans = mul(cnt0, power(pow2[x], p - 2));           for (int i = 0; i < 26; ++i) {               int cnt = -cnt0 << 1;               now = -1;               for (int j = 0; j < str[x + 1].length(); ++j) {                   char tmp = str[x + 1][j];                   if (j == index) tmp =  a  + i;                   while (~now && w[now + 1] != tmp) now = nxt[now];                   if (w[now + 1] == tmp) ++now;                   if (now == w.length() - 1) {                       ++cnt;                       now = nxt[now];                   }               }               ans = add(ans, mul(cnt, sub(sum[k][i], sum[x][i])));           }           std::cout << mul(ans, pow2[k]) <<   n ;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<string> split(const string& s, char c) {     if (s.length() == 0) return vector<string>();     vector<string> v;     stringstream ss(s);     string x;     while (getline(ss, x, c)) {       v.emplace_back(x);     }     return std::move(v);   }   vector<int> splitInt(const string& s, char c) {     if (s.length() == 0) return vector<int>();     vector<int> v;     stringstream ss(s);     int x;     string str;     while (getline(ss, str, c)) {       stringstream si(str);       si >> x;       v.emplace_back(x);     }     return std::move(v);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 0;     cin >> t;     while (t-- > 0) {       int n;       cin >> n;       vector<int> arr(n, 0);       for (int i = 0; i < n; ++i) cin >> arr[i];       vector<long long> seen(3001, 0);       vector<vector<long long>> left(3001);       for (int i = 0; i < n; ++i) {         seen[arr[i]]++;         left[i] = seen;       }       seen = vector<long long>(3001, 0);       vector<vector<long long>> right(3001);       for (int i = n - 1; i >= 0; --i) {         seen[arr[i]]++;         right[i] = seen;       }       long long count = 0;       for (int j = 1; j < n; ++j) {         for (int k = j + 1; k + 1 < n; ++k) {           int aj = arr[j];           int ak = arr[k];           if (j - 1 >= 0 && k + 1 < n) {             count += left[j - 1][ak] * right[k + 1][aj];           }         }       }       cout << count <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int compare(const void* x1, const void* x2) { return (*(int*)x1 - *(int*)x2); }   int main() {     int n, a;     cin >> n >> a;     int k = n / 2;     if (a % 2 == 1)       cout << a / 2 + 1;     else       cout << (k - a / 2 + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x, y, d, T;   int main() {     cin >> T;     while (T--) {       cin >> n >> x >> y >> d;       int sum;       if ((abs(y - x)) % d == 0 || (n - y) % d == 0 || (y - 1) % d == 0) {         if ((abs(y - x)) % d == 0)           sum = (abs(y - x)) / d;         else {           int sxl, sxr;           if ((x - 1) % d)             sxl = (x - 1) / d + 1;           else             sxl = (x - 1) / d;           if ((n - x) % d)             sxr = (n - x) / d + 1;           else             sxr = (n - x) / d;           int fl = (y - 1) % d, fr = (n - y) % d;           if (fl == 0 && fr != 0) sum = sxl + (y - 1) / d;           if (fl != 0 && fr == 0) sum = sxr + (n - y) / d;           if (fl == 0 && fr == 0) {             sum = min(sxl + (y - 1) / d, sxr + (n - y) / d);           }         }         cout << sum << endl;       } else         cout <<  -1  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char s[100001];     int a[100001], m, l, r;     scanf( %s%d , s, &m);     int len = strlen(s);     a[1] = 0;     for (int i = 1; i < len; ++i) {       if (s[i] == s[i - 1]) {         a[i + 1] = a[i] + 1;       } else {         a[i + 1] = a[i];       }     }     while (m--) {       scanf( %d%d , &l, &r);       printf( %d n , a[r] - a[l]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     static char buf[1 << 21], *p1, *p2;     int f = 0, c = 1;     char ch =         (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)              ? EOF              : *p1++);     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) c = -1;       ch =           (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                ? EOF                : *p1++);     }     while (ch >=  0  && ch <=  9 ) {       f = f * 10 + ch -  0 ;       ch =           (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                ? EOF                : *p1++);     }     return c * f;   }   const int M = 3e5 + 10;   struct node {     long long k, b;     inline long long operator()(const long long &x) { return x * k + b; }     node(long long x = 0, long long y = 0) { k = x, b = y; }   } e, f[M * 4];   vector<int> v[M];   int fa[M], siz[M], mx[M], dep[M], belong[M], vis[M];   long long v1[M], v2[M], st[M], l[M], a[M], s[M];   int sz, n, x, y, md, top, rt;   long long ans;   void build(int o, int l, int r) {     f[o] = (node){0, 0};     if (l == r) return;     build((o << 1), l, ((l + r) >> 1));     build((o << 1 | 1), ((l + r) >> 1) + 1, r);   }   long long ask(int o, int l, int r, long long x) {     long long ans = f[o](x);     if (l == r) return ans;     if (x <= ((l + r) >> 1))       return max(ans, ask((o << 1), l, ((l + r) >> 1), x));     else       return max(ans, ask((o << 1 | 1), ((l + r) >> 1) + 1, r, x));   }   void insert(int o, int l, int r, node x) {     if (f[o](((l + r) >> 1)) < x(((l + r) >> 1))) swap(f[o], x);     if (l == r) return;     if (x.k < f[o].k)       insert((o << 1), l, ((l + r) >> 1), x);     else       insert((o << 1 | 1), ((l + r) >> 1) + 1, r, x);   }   void getroot(int x, int fa) {     siz[x] = 1;     mx[x] = 0;     for (int i = 0; i < v[x].size(); ++i) {       int y = v[x][i];       if (y == fa || vis[y]) continue;       getroot(y, x);       siz[x] += siz[y];       mx[x] = max(mx[x], siz[y]);     }     mx[x] = max(mx[x], sz - siz[x]);     if (mx[x] < mx[rt]) rt = x;   }   void dfs(int x, int fa, long long val1, long long val2, long long sum,            int from) {     if (x != rt && !from) from = x;     dep[x] = dep[fa] + 1;     md = max(md, dep[x]);     int f = 0;     siz[x] = 1;     for (int i = 0; i < v[x].size(); ++i) {       int y = v[x][i];       if (y == fa || vis[y]) continue;       dfs(y, x, val1 + sum + a[y], val2 + a[y] * dep[x], sum + a[y], from);       siz[x] += siz[y];       f = 1;     }     if (!f) {       st[++top] = x, v1[top] = val1, v2[top] = val2, s[top] = sum - a[rt],       l[top] = dep[x], belong[top] = from;     }   }   void dfz(int x) {     vis[x] = 1;     top = 0;     md = 0;     dfs(x, 0, a[x], 0, a[x], 0);     st[++top] = x;     v1[top] = a[x], l[top] = 1, v2[top] = s[top] = belong[top] = 0;     build(1, 1, md);     belong[top + 1] = belong[0] = -1;     for (int i = 1; i <= top;) {       int j = i;       while (belong[j] == belong[i])         ans = max(ans, ask(1, 1, md, l[j]) + v1[j]), ++j;       j = i;       while (belong[j] == belong[i]) insert(1, 1, md, node(s[j], v2[j])), ++j;       i = j;     }     build(1, 1, md);     for (int i = top; i >= 1;) {       int j = i;       while (belong[j] == belong[i])         ans = max(ans, ask(1, 1, md, l[j]) + v1[j]), --j;       j = i;       while (belong[i] == belong[j]) insert(1, 1, md, node(s[j], v2[j])), --j;       i = j;     }     for (int i = 0; i < v[x].size(); ++i) {       int y = v[x][i];       if (vis[y]) continue;       sz = siz[y];       rt = 0;       getroot(y, x);       dfz(rt);     }   }   int main() {     n = read();     for (int i = 1; i < n; ++i) {       x = read();       y = read();       v[x].push_back(y);       v[y].push_back(x);     }     for (int i = 1; i <= n; ++i) a[i] = read();     siz[0] = mx[0] = sz = n;     getroot(1, 0);     dfz(rt);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int vocala(char c) {     if (c ==  a  || c ==  A  || c ==  e  || c ==  E  || c ==  i  || c ==  I  ||         c ==  o  || c ==  O  || c ==  u  || c ==  U )       return 1;     if (c ==  y  || c ==  Y ) return 1;     return 0;   }   int isprime(long long n) {     if (n <= 1) return 0;     for (long long i = 2; i * i <= n; ++i)       if (n % i == 0) return 0;     return 1;   }   int isfibo(long long n) {     long long a = 5 * n * n + 4;     long long b = a - 8;     if (sqrt(a) == int(sqrt(a)) || sqrt(b) == int(sqrt(b))) return 1;     return 0;   }   int gcd(long long a, long long b) {     long long r;     while (b) {       r = a % b;       a = b;       b = r;     }     return a;   }   ifstream in( input.txt );   ofstream out( output.txt );   long long const nrmax = 1e18;   long long v[100005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> v[i];     }     long long cnt = 3e9;     sort(v + 1, v + n + 1);     cnt = min(cnt, v[n] - v[2]);     cnt = min(cnt, v[n - 1] - v[1]);     cout << cnt <<   n ;     in.close();     out.close();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   using vv = vector<vector<T>>;   template <class T>   ostream &operator<<(ostream &os, const vector<T> &t) {     os <<  { ;     for (int(i) = 0; (i) < (t.size()); ++(i)) {       os << t[i] <<  , ;     }     os <<  }  << endl;     return os;   }   template <class S, class T>   ostream &operator<<(ostream &os, const pair<S, T> &t) {     return os <<  (  << t.first <<  ,  << t.second <<  ) ;   }   template <class T>   inline bool MX(T &l, const T &r) {     return l < r ? l = r, 1 : 0;   }   template <class T>   inline bool MN(T &l, const T &r) {     return l > r ? l = r, 1 : 0;   }   vector<string> s_p_l_i_t(const string &s, char c) {     vector<string> v;     stringstream ss(s);     string x;     while (getline(ss, x, c)) v.emplace_back(x);     return move(v);   }   void e_r_r(vector<string>::iterator it) {}   template <typename T, typename... Args>   void e_r_r(vector<string>::iterator it, T a, Args... args) {     if (*it ==   1  || *it ==  1 )       cerr << endl;     else       cerr << it->substr((*it)[0] ==    , it->length()) <<   =   << a <<  ,  ;     e_r_r(++it, args...);   }   const long long MOD = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cout << fixed << setprecision(0);     int n;     cin >> n;     cout <<  YES  << endl;     int a, b, c, d;     for (int(i) = 0; (i) < (n); ++(i)) {       cin >> a >> b >> c >> d;       cout << abs(a) % 2 * 2 + abs(b) % 2 + 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, p;     cin >> n >> p;     string s;     cin >> s;     if (p > s.length() / 2) {       reverse(s.begin(), s.end());       p = (n - p) + 1;     }     int sum = 0;     int t[n], l = -1, r = 0;     for (int i = 0; i < s.length() / 2; i++) {       if (abs(int(s[i]) - int(s[n - i - 1])) > 13) {         t[i] = 26 - abs(int(s[i]) - int(s[n - i - 1]));       } else {         t[i] = abs(int(s[i]) - int(s[n - i - 1]));       }       if (t[i] > 0) {         r = i;         if (l < 0) {           l = i;         }       }       sum += t[i];     }     p--;     if (l <= p && p <= r && p - l > r - p) {       sum += r - p + r - l;     } else if (l <= p && p <= r && p - l <= r - p) {       sum += p - l + r - l;     } else if (p <= l) {       sum += r - p;     } else if (r <= p) {       sum += p - l;     }     if (l < 0) {       cout << 0;     } else {       cout << sum;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, c, d, x, y, g, h, i, j, k, n, t, z = 0, l, r, u;     cin >> t;     while (t--) {       cin >> n;       for (i = 0; i < n; i++) cout << 1 <<    ;       cout << endl;     }   }


#include<bits/stdc++.h>   #define mp make_pair   #define pr pair<int,int>   #define pb push_back   using namespace std;   int k[100005],all[200005];   vector<int>a[100005];   struct nd{    int val,id;    nd(){}    nd(int val,int id):val(val),id(id){}    bool operator <(const nd &x)const{     return val<x.val;    }   };   vector<nd>w[200005];   int prew[200005];   int vis[200005];   int main(){    int t;    scanf( %d ,&t);    while(t--){     int n;     scanf( %d ,&n);     for(int i=0;i<n;i++)a[i].clear();     for(int i=0;i<n;i++){      scanf( %d ,&k[i]);      a[i].resize(k[i]);      for(int j=0;j<k[i];j++)scanf( %d ,&a[i][j]);   //   for(int j=0;j<k[i];j++){   //    int x;   //    scanf( %d ,&x);   //    a[i].pb(x);   //   }      sort(a[i].begin(),a[i].end());     }     int m=0;     for(int i=0;i<n;i++)for(int j=0;j<k[i];j++)all[m++]=a[i][j];     sort(all,all+m);     int len=unique(all,all+m)-all;     for(int i=0;i<len;i++)w[i].clear();     for(int i=0;i<n;i++)for(int j=0;j<k[i];j++)a[i][j]=lower_bound(all,all+len,a[i][j])-all;     int D=sqrt(m)/6;     int flag=0;     for(int i=0;i<len;i++)vis[i]=0;     for(int i=0;i<n;i++){      if(k[i]>D){       for(int j=0;j<k[i];j++)vis[a[i][j]]=1;       for(int j=0;j<n;j++)if(j!=i){        int cnt=0;        for(int l=0;l<k[j];l++)if(vis[a[j][l]])cnt++;        if(cnt>=2){         flag=1;         printf( %d %d n ,i+1,j+1);         break;        }       }       if(flag)break;       for(int j=0;j<k[i];j++)vis[a[i][j]]=0;      }     }      if(flag)continue;   //  for(int i=0;i<n;i++)if(k[i]<=D)for(int j=0;j<k[i];j++)for(int l=j+1;l<k[i];l++)prew[a[i][j]]++;   //  for(int i=0;i<len;i++)w[i].resize(prew[i]);   //  for(int i=0;i<len;i++)prew[i]=0;   //  for(int i=0;i<n;i++)if(k[i]<=D)for(int j=0;j<k[i];j++)for(int l=j+1;l<k[i];l++)w[a[i][j]][prew[a[i][j]]++]=mp(a[i][l],i);     for(int i=0;i<n;i++)if(k[i]<=D)for(int j=0;j<k[i];j++)for(int l=j+1;l<k[i];l++)w[a[i][j]].pb(nd(a[i][l],i));     for(int i=0;i<len;i++)sort(w[i].begin(),w[i].end());     for(int i=0;i<len;i++){      int l=w[i].size();      for(int j=0;j<l-1;j++)if(w[i][j].val==w[i][j+1].val && w[i][j].id!=w[i][j+1].id){       flag=1;       printf( %d %d n ,w[i][j].id+1,w[i][j+1].id+1);       break;      }       if(flag)break;     }     if(!flag)printf( -1 n );    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 100;   vector<int> v[maxn], w[maxn];   long long a[maxn];   bool d[maxn];   long long c[maxn][5];   long long n, m;   bool mark[maxn][2];   void dfs1(long long i) {     c[i][0] = 1;     mark[i][0] = 1;     for (long long y = 0; y < v[i].size(); y++) {       if (!mark[v[i][y]][0]) {         dfs1(v[i][y]);       }     }   }   void dfs2(long long i) {     mark[i][1] = 1;     c[i][1] = 1;     if (a[i] == 1) return;     for (long long y = 0; y < w[i].size(); y++) {       if (!mark[w[i][y]][1]) {         dfs2(w[i][y]);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m;     for (long long y = 1; y <= n; y++) {       cin >> a[y];       if (a[y] == 1) {         v[100000 + 1].push_back(y);       }       if (a[y] == 2) {         w[100000 + 1].push_back(y);       }     }     while (m--) {       long long i, j;       cin >> i >> j;       v[i].push_back(j);       w[j].push_back(i);     }     dfs1(100000 + 1);     dfs2(100000 + 1);     for (long long y = 1; y <= n; y++) {       cout << (c[y][0] && c[y][1]) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, p1, p2, tot1, tot2;   long long L, W, ans, a[100005], b[100005];   int main() {     scanf( %d%lld%lld , &n, &L, &W);     long long t;     int v;     for (int i = 1; i <= n; ++i) {       scanf( %lld%d , &t, &v);       if (v == 1)         a[++tot1] = t;       else         b[++tot2] = t;     }     sort(a + 1, a + tot1 + 1), sort(b + 1, b + tot2 + 1);     for (p1 = p2 = 1; p1 <= tot1; ++p1) {       while (p2 <= tot2 && (b[p2] - a[p1] + L) * W <= abs(b[p2] + a[p1] + L) &&              (p2++, 1))         ;       ans += tot2 - p2 + 1;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long N = 1e2 + 10;   vector<long long> g[N];   void dfs(long long node, long long par, long long dd, vector<long long>& fre) {     fre[dd]++;     for (auto x : g[node])       if (x != par) dfs(x, node, dd + 1, fre);   }   long long n, k;   long long get(vector<long long>& arr) {     vector<long long> cur(k + 1, 0);     cur[0] = 1;     for (auto x : arr) {       for (long long i = k; i >= 1; i--) {         cur[i] += cur[i - 1] * x;         cur[i] %= MOD;       }     }     return cur[k];   }   long long solve(long long x) {     long long sz = g[x].size();     vector<vector<long long> > go(sz, vector<long long>(n + 1, 0));     for (long long i = 0; i < sz; i++) dfs(g[x][i], x, 1, go[i]);     long long res = 0;     for (long long i = 1; i <= n; i++) {       vector<long long> arr;       for (auto v : go)         if (v[i] > 0) arr.push_back(v[i]);       res += get(arr);       res %= MOD;     }     return res;   }   void solve() {     cin >> n >> k;     long long u, v;     for (long long i = 0; i < n - 1; i++) {       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     long long res = 0;     if (k == 2) {       res = (n * (n - 1)) / 2;       res %= MOD;     } else {       for (long long i = 1; i <= n; i++) {         res += solve(i);         res %= MOD;       }     }     cout << res <<   n ;     for (long long i = 1; i <= n; i++) g[i].clear();   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   inline T1 max(T1 a, T2 b) {     return a < b ? b : a;   }   template <typename T1, typename T2>   inline T1 min(T1 a, T2 b) {     return a < b ? a : b;   }   const char lf =   n ;   namespace ae86 {   const int bufl = 1 << 15;   char buf[bufl], *s = buf, *t = buf;   inline int fetch() {     if (s == t) {       t = (s = buf) + fread(buf, 1, bufl, stdin);       if (s == t) return EOF;     }     return *s++;   }   inline int ty() {     int a = 0;     int b = 1, c = fetch();     while (!isdigit(c)) b ^= c ==  - , c = fetch();     while (isdigit(c)) a = a * 10 + c - 48, c = fetch();     return b ? a : -a;   }   }  // namespace ae86   using ae86::ty;   const int _ = 123, mo = 1000000007;   int n, m, ps, cnts[_] = {0};   long long ans = 0;   bitset<_> alls;   inline bitset<_> rshl(bitset<_> a, int d) {     d %= m;     return ((a << d) | (a >> (m - d))) & alls;   }   inline bitset<_> rshr(bitset<_> a, int d) {     d %= m;     return ((a >> d) | (a << (m - d))) & alls;   }   void dfs(bitset<_> now, int las, long long d) {     ans = (ans + d) % mo;     for (int i = las; i + i <= m; i++)       if (cnts[i] && !now[i] && !now[m - i])         dfs(now | rshl(now, i) | rshr(now, i), i + 1, d * cnts[i] % mo);   }   int main() {     ios::sync_with_stdio(0), cout.tie(nullptr);     n = ty(), m = ty(), ps = ty();     for (int i = 1; i <= ps; i++) {       int a = ty() % m;       cnts[min(a, m - a)]++;     }     bitset<_> temp = 0;     temp[0] = 1;     alls = 0;     for (int i = 0; i < m; i++) alls[i] = 1;     dfs(temp, 0, 1), cout << ans << lf;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long price[200002];   long long a, b, x, y, k;   long long gcd(long long aa, long long bb) {     return (bb != 0) ? gcd(bb, aa % bb) : aa;   }   bool check(long long mid) {     long long tt = mid / (a * b / gcd(a, b));     long long ta = mid / a;     long long tb = mid / b;     long long total = 0;     for (int i = 1; i <= tt; i++) {       total += price[i] * (x + y);     }     for (int i = tt + 1; i <= ta; i++) {       total += price[i] * x;     }     for (int i = ta + 1; i <= ta + tb - tt; i++) {       total += price[i] * y;     }     if (total >= k) {       return true;     }     return false;   }   int main() {     int q, n;     cin >> q;     while (q--) {       cin >> n;       for (int i = 0; i < n; i++) {         cin >> price[i + 1];         price[i + 1] /= 100;       }       sort(price + 1, price + n + 1, greater<int>());       cin >> x >> a >> y >> b;       cin >> k;       if (x < y) {         swap(x, y);         swap(a, b);       }       int l = 1, r = n, res = -1;       while (l <= r) {         int mid = (l + r) >> 1;         if (check(mid)) {           res = mid;           r = mid - 1;         } else {           l = mid + 1;         }       }       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   const long long N = 2005;   long long n, K, ans, sum, sum2, f[N][N], g[N];   long long kuai(long long a, long long b) {     if (b == 0) return 1ll;     if (b == 1) return a;     long long x = kuai(a, b / 2);     if (b % 2 == 0) return x * x % mod;     return x * x % mod * a % mod;   }   signed main() {     scanf( %lld%lld , &n, &K);     K--;     for (long long i = 1; i <= n; i++) {       sum = 2;       f[i][1] = 2;       for (long long j = 2; j <= i; j++) {         f[i][j] = f[i][j - 1] * 2 % mod;         sum = (sum + f[i][j]) % mod;       }       for (long long j = i + 1; j <= n; j++) {         f[i][j] = sum;         sum = ((sum - f[i][j - i] + f[i][j]) % mod + mod) % mod;       }     }     for (long long i = 1; i <= n; i++) {       long long k = K / i;       k = min(k, n);       if (k == 0) continue;       sum2 = 2;       g[1] = 2;       for (long long j = 2; j <= k; j++) {         g[j] = g[j - 1] * 2 % mod;         sum2 = (sum2 + g[j]) % mod;       }       for (long long j = k + 1; j <= n; j++) {         g[j] = sum2;         sum2 = ((sum2 - g[j - k] + g[j]) % mod + mod) % mod;       }       ans = (ans + g[n] * (f[i][n] - f[i - 1][n] + mod) % mod) % mod;     }     cout << ans * kuai(2, mod - 2) % mod;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string ss[100];     int n, ans = 0, cur;     cin >> n;     for (int i = 0; i < n; i++) cin >> ss[i];     for (char a =  a ; a <=  z ; a++)       for (char b =  a ; b <=  z ; b++) {         cur = 0;         for (int i = 0; i < n; i++) {           int l = ss[i].length();           bool ok = true;           while (l--) {             if (ss[i][l] != a && ss[i][l] != b) ok = false;           }           if (ok) cur += ss[i].length();         }         ans = max(ans, cur);       }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   int main() {     int N;     cin >> N;     int suma = 0;     vector<int> a(N);     for (int i = 0; i < N; ++i) {       cin >> a[i];       suma += a[i];     }     if (suma == 1) {       cout << -1 << endl;     } else {       long long answer = LONG_LONG_MAX;       for (int tk = 2; tk <= suma; ++tk) {         if (suma % tk == 0) {           int currenti = 0;           long long cans = 0;           while (currenti < N) {             int currentsum = 0;             int median = -1;             int starti = currenti;             while (currentsum < tk) {               currentsum += a[currenti];               if (a[currenti] == 1 && currentsum == (tk + 1) / 2) {                 median = currenti;               }               currenti++;             }             long long steps = 0;             for (int i = starti; i < currenti; ++i) {               if (a[i] == 1) {                 steps += abs(median - i);               }             }             cans += steps;           }           answer = min(answer, cans);         }       }       cout << answer << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long DIM = 2e5 + 7;   long long n, used[27][DIM], a[DIM], tests;   int in;   int main() {     in = scanf( %lld , &tests);     for (long long test = 1; test <= tests; test++) {       in = scanf( %lld , &n);       long long result = 0;       for (long long i = 1; i <= n; i++) {         for (long long j = 1; j <= 26; j++) {           used[j][i] = used[j][i - 1];         }         in = scanf( %lld , &a[i]);         used[a[i]][i]++;       }       for (long long i = 1; i <= 26; i++) result = max(result, used[i][n]);       long long cntin = 0, cntout = 0;       for (long long l = 1; l <= n; l++) {         for (long long r = l; r <= n; r++) {           cntin = 0;           cntout = 0;           for (long long x = 1; x <= 26; x++) {             cntin = max(cntin, used[x][r] - used[x][l - 1]);           }           for (long long x = 1; x <= 26; x++)             cntout =                 max(cntout, min(used[x][l - 1], used[x][n] - used[x][r]) * 2);           result = max(result, cntout + cntin);         }       }       printf( %lld n , result);       for (long long i = 1; i <= n; i++) {         for (long long j = 1; j <= 26; j++) {           used[j][i] = 0;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = INT_MAX / 3;   const double EPS = 1e-14;   template <typename U, typename T>   void chmin(U &x, T y) {     x = min(x, y);   }   template <typename U, typename T>   void chmax(U &x, T y) {     x = max(x, y);   }   const long long int PRIMEMAX = 1e6;   long long int FACTOR[PRIMEMAX];   vector<long long int> Primes;   void sieve(long long int upb) {     FACTOR[0] = FACTOR[1] = -1;     for (long long int n = 2; n < upb; ++n) {       if (FACTOR[n] != 0) continue;       Primes.push_back(n);       long long int kn = n * n;       while (kn < PRIMEMAX) {         FACTOR[kn] = n;         kn += n;       }     }   }   bool is_prime(int n) {     if (PRIMEMAX > n) {       return FACTOR[n] == 0;     } else {       for (int p : Primes) {         if (n % p == 0) return false;       }       return true;     }   }   int main() {     cout << fixed << setprecision(12);     sieve(PRIMEMAX);     int n;     cin >> n;     vector<int> ps;     ps.push_back(n % 2 == 0 ? 2 : 3);     n -= ps[0];     if (n == 0) {       cout << 1 << endl;       cout << ps[0] << endl;       return 0;     }     if (is_prime(n)) {       cout << 2 << endl;       cout << ps[0] <<     << n << endl;       return 0;     }     for (int x : Primes) {       int y = n - x;       if (is_prime(y)) {         ps.push_back(x);         ps.push_back(y);         break;       }     }     cout << 3 << endl;     for (int i = 0; i < (3); i++) {       if (i > 0) cout <<    ;       cout << ps[i];     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void Get(int &T) {     char C;     bool F = 0;     for (; C = getchar(), C <  0  || C >  9 ;)       if (C ==  - ) F = 1;     for (T = C -  0 ; C = getchar(), C >=  0  && C <=  9 ; T = T * 10 + C -  0 )       ;     F && (T = -T);   }   int N, M;   int X[10005];   int Y[10005];   int G[1005][1005];   int A[10005];   void Debug() {     for (int i = 1; i <= N; i++) {       for (int j = 1; j <= N; j++) printf( %d  , G[i][j]);       puts(  );     }   }   void Init() {     Get(N);     Get(M);     for (int i = 2; i < N; i++) Get(A[i]);     for (int k = 1; k <= N; k++) {       Get(X[k]);       X[k] *= M;       Get(Y[k]);       Y[k] *= M;     }     for (int i = 1; i <= N; i++)       for (int j = 1; j <= N; j++)         if (i != j)           G[i][j] = std::abs(X[i] - X[j]) + std::abs(Y[i] - Y[j]) - A[i];   }   int Ans;   void Work() {     for (int k = 1; k <= N; k++)       for (int i = 1; i <= N; i++)         for (int j = 1; j <= N; j++)           if (G[i][j] > G[i][k] + G[k][j]) G[i][j] = G[i][k] + G[k][j];     Ans = G[1][N];   }   void Output() { printf( %d n , Ans); }   int main() {     Init();     Work();     Output();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char f[1111][1111];   bool black[1111][1111];   bool is_free(int i, int j) {     return f[i][j] !=  .  && (f[i][j] <  a  || f[i][j] >  d );   }   bool can_hor(int i, int j) {     return (is_free(i, j) && is_free(i, j + 1) && is_free(i, j + 2)) &&            !black[i][j] && black[i][j + 1] && !black[i][j + 2];   }   bool can_vec(int i, int j) {     return (is_free(i, j) && is_free(i + 1, j) && is_free(i + 2, j)) &&            !black[i][j] && black[i + 1][j] && !black[i + 2][j];   }   bool place_hor(int i, int j) {     if (can_hor(i, j)) {       char fr = 0;       for (char cur =  a ; cur <=  d ; cur++) {         bool can = true;         for (int kj = j; kj <= j + 2; kj++) {           if (f[i - 1][kj] == cur || f[i + 1][kj] == cur || f[i][j - 1] == cur ||               f[i][j + 3] == cur) {             can = false;             break;           }         }         if (can) {           fr = cur;           break;         }       }       if (!fr) return false;       for (int kj = j; kj <= j + 2; kj++) {         f[i][kj] = fr;       }       return true;     }     return false;   }   bool place_vec(int i, int j) {     if (can_vec(i, j)) {       char fr = 0;       for (char cur =  a ; cur <=  d ; cur++) {         bool can = true;         for (int ki = i; ki <= i + 2; ki++) {           if (f[ki][j - 1] == cur || f[ki][j + 1] == cur || f[i - 1][j] == cur ||               f[i + 3][j] == cur) {             can = false;             break;           }         }         if (can) {           fr = cur;           break;         }       }       if (!fr) return false;       for (int ki = i; ki <= i + 2; ki++) {         f[ki][j] = fr;       }       return true;     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     memset(f,  . , sizeof(f));     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> f[i][j];         if (f[i][j] ==  b )           black[i][j] = 1;         else if (f[i][j] ==  w )           black[i][j] = 0;         if (f[i][j] !=  . ) f[i][j] =    ;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (!is_free(i, j)) continue;         if (!place_hor(i, j)) {           if (!place_vec(i, j)) {             cout <<  NO ;             return 0;           }         }       }     }     cout <<  YES  << endl;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cout << f[i][j];       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n, a[N], to[N];   vector<int> idx[N];   int is[N];   bool ok() {     for (int i = 0; i < n; ++i) is[a[i]] ^= 1;     bool prv = 0;     for (int i = 1; i <= n; ++i) {       if (!is[i]) continue;       if (prv) return 0;       prv = 1;     }     return 1;   }   bool plind() {     for (int i = 0; i * 2 + 1 < n; ++i)       if (a[i] != a[n - i - 1]) return 0;     return 1;   }   bool vis[N];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , a + i);       idx[a[i]].push_back(i);     }     if (!ok()) return cout << 0, 0;     if (plind()) return cout << 1ll * n * (n + 1) / 2, 0;     int indx = n / 2;     for (int i = 1; i <= n; ++i) {       for (int j = 0; j * 2 + 1 < idx[i].size(); ++j) {         to[idx[i][j]] = idx[i][idx[i].size() - j - 1];         to[idx[i][idx[i].size() - j - 1]] = idx[i][j];       }       if (idx[i].size() % 2 == 0) continue;       indx = idx[i][idx[i].size() / 2];       to[idx[i][idx[i].size() / 2]] = n / 2;     }     for (int i = 0; i < n; ++i)       if (to[i] == n - i - 1) vis[i] = 1;     int prel = 0;     while (a[prel] == a[n - prel - 1]) ++prel;     int prer = prel;     if (n % 2 && indx != n / 2) prer = max(prer, indx);     if (n % 2 && indx == n / 2) vis[n / 2] = 1;     for (int i = n - 1; i >= 0; --i)       if (to[i] >= 0 && !vis[i]) {         prer = max(prer, to[i]);         vis[to[i]] = 1;       }     long long ans = 1ll * (prel + 1) * (n - prer);     int sufr = n - 1;     while (a[sufr] == a[n - sufr - 1]) --sufr;     int sufl = sufr;     if (n % 2 && indx != n / 2) sufl = min(sufl, indx);     memset(vis, 0, sizeof vis);     if (n % 2 && indx == n / 2) vis[n / 2] = 1;     for (int i = 0; i < n; ++i)       if (to[i] == n - i - 1) vis[i] = 1;     for (int i = 0; i < n; ++i)       if (to[i] >= 0 && !vis[i]) {         sufl = min(sufl, to[i]);         vis[to[i]] = 1;       }     if (sufl <= prel) return cout << ans, 0;     ans += 1ll * (n - sufr) * (sufl - prel);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10, size = 1 << 20, mod = 998244353, inf = 2e9;   const long long INF = 1e15;   template <class o>   void qr(o& x) {     char c = getchar();     x = 0;     int f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) x = x * 10 + c -  0 , c = getchar();     x *= f;   }   template <class o>   void qw(o x) {     if (x / 10) qw(x / 10);     putchar(x % 10 +  0 );   }   template <class o>   void pr1(o x) {     if (x < 0) x = -x, putchar( - );     qw(x);     putchar(   );   }   template <class o>   void pr2(o x) {     if (x < 0) x = -x, putchar( - );     qw(x);     putchar(  n );   }   long long gcd(long long a, long long b) { return !a ? b : gcd(b % a, a); }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   long long power(long long a, long long b = mod - 2, long long p = mod) {     long long c = 1;     while (b) {       if (b & 1) c = c * a % p;       b /= 2;       a = a * a % p;     }     return c;   }   template <class o>   void cmax(o& x, o y) {     if (x < y) x = y;   }   void cmax(int& x, int y) {     x = x - y >> 31 ? y : x;     ;   }   template <class o>   void cmin(o& x, o y) {     if (x > y) x = y;   }   void cmin(int& x, int y) { x = x - y >> 31 ? x : y; }   template <typename t1, typename t2>   void ad(t1& x, t2 y) {     x += y;     if (x >= mod) x -= mod;   }   template <typename t1, typename t2>   void dl(t1& x, t2 y) {     x -= y;     if (x < 0) x += mod;   }   int n, m;   int mx[N << 2];   void change(int x, int l, int r, int pos, int d) {     if (l == r) {       mx[x] = d;       return;     }     if (pos <= ((l + r) >> 1))       change((x << 1), l, ((l + r) >> 1), pos, d);     else       change((x << 1 | 1), ((l + r) >> 1) + 1, r, pos, d);     cmax(mx[x] = mx[(x << 1)], mx[(x << 1 | 1)]);   }   int ask(int x, int l, int r, int L, int R) {     if (L <= l && r <= R) return mx[x];     int s = 0;     if (L <= ((l + r) >> 1)) cmax(s, ask((x << 1), l, ((l + r) >> 1), L, R));     if (((l + r) >> 1) < R)       cmax(s, ask((x << 1 | 1), ((l + r) >> 1) + 1, r, L, R));     return s;   }   int trie[N][27], tot = 1, pos[N];   vector<int> name[N];   void insert(char* s, int now) {     int p = 1;     for (int i = 1; s[i]; i++) {       int c = s[i] -  a ;       if (!trie[p][c]) trie[p][c] = ++tot;       p = trie[p][c];     }     name[p].push_back(now);     pos[now] = p;   }   int fail[N];   void add(int x, int y);   void bfs() {     static int q[N], l, r;     q[l = r = 1] = 1;     for (int i = 0; i <= 25; i++) trie[0][i] = 1;     while (l <= r) {       int p = q[l++], x, y;       for (int c = 0; c <= 25; c++) {         x = trie[p][c];         if (!x) {           trie[p][c] = trie[fail[p]][c];           continue;         }         y = fail[p];         if (p == 1)           fail[x] = 1;         else           fail[x] = trie[fail[p]][c];         q[++r] = x;         add(fail[x], x);       }     }   }   int fa[N], dep[N], son[N], sz[N], top[N], dfn[N], id;   vector<int> e[N];   void add(int x, int y) { e[x].push_back(y); }   void dfs1(int x) {     sz[x] = ((int)name[x].size());     son[x] = 0;     for (int y : e[x]) {       fa[y] = x;       dep[y] = dep[x] + 1;       dfs1(y);       sz[x] += sz[y];       if (sz[y] > sz[son[x]]) son[x] = y;     }   }   int st[N], ed[N];   void dfs2(int x, int tp) {     top[x] = tp;     st[x] = id + 1;     for (int y : name[x]) dfn[y] = ++id;     ed[x] = id;     if (son[x]) dfs2(son[x], tp);     for (int y : e[x])       if (y ^ son[x]) dfs2(y, y);   }   int Max(int x) {     int ans = -1;     while (x) {       if (st[top[x]] <= ed[x]) cmax(ans, ask(1, 1, n, st[top[x]], ed[x]));       x = fa[top[x]];     }     return ans;   }   void solve() {     qr(n);     qr(m);     static char s[N];     for (int i = 1; i <= n; i++) {       scanf( %s , s + 1);       insert(s, i);     }     bfs();     dfs1(1);     dfs2(1, 1);     while (m--) {       int op, i, x;       qr(op);       if (op == 1) {         qr(i);         qr(x);         change(1, 1, n, dfn[i], x);       } else {         scanf( %s , s + 1);         int ans = -1;         for (int i = 1, p = 1; s[i]; i++) {           int c = s[i] -  a ;           p = trie[p][c];           cmax(ans, Max(p));         }         pr2(ans);       }     }   }   int main() {     int T = 1;     while (T--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int ar[n];       for (int i = 0; i < n; i++) cin >> ar[i];       for (int i = n - 1; i >= 0; i--) cout << ar[i] <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e3 + 10;   long long a[maxn], pre[maxn];   long long dp[maxn][maxn];   int main() {     int n, m, k;     while (~scanf( %d%d%d , &n, &m, &k)) {       for (int i = 1; i < n + 1; i++) {         scanf( %lld , &a[i]);         pre[i] = pre[i - 1] + a[i];       }       for (int i = 1; i <= n; ++i)         for (int j = 1; j <= i / m; ++j)           dp[i][j] = max(dp[i - 1][j], dp[i - m][j - 1] + pre[i] - pre[i - m]);       cout << dp[n][k] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char op[20];   char s[205];   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     getchar();     cin.getline(op, 15);     int dir;     if (op[3] ==  h ) {       dir = 0;     } else {       dir = 1;     }     scanf( %s , s);     int dir2 = m < k ? 0 : 1;     int len = strlen(s);     bool flag = false;     int t = 0;     for (int i = 0; i < len; ++i) {       ++t;       int lastk = k;       if (dir == 0) {         --k;         if (k == 0) k = 2, dir = 1;       } else {         ++k;         if (k == n + 1) k = n - 1, dir = 0;       }       if (s[i] ==  0 ) {         if (dir == 0) {           if (m > lastk && m < n)             ++m;           else if (m < lastk && m > 1)             --m;         } else {           if (m < lastk && m > 1)             --m;           else if (m > lastk && m < n)             ++m;         }       } else if (i != len - 1) {         if (dir == 0)           m = n;         else           m = 1;       }       if (m == k && i != len - 1) {         flag = true;         break;       }     }     if (!flag) {       puts( Stowaway );     } else {       printf( Controller %d n , t);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int Inf = 1e9 + 5;   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> a(n);       ll sum = 0;       for (int i = 0; i < n; i++) {         cin >> a[i];         sum += a[i];       }       ll mx = 0, s = 0;       for (int i = 1; i < n; i++) {         s += a[i];         if (s < 0) s = 0;         mx = max(mx, s);       }       bool f1 = 0;       if (sum > mx) {         f1 = 1;       }       mx = 0;       s = 0;       for (int i = 0; i < n - 1; i++) {         s += a[i];         if (s < 0) s = 0;         mx = max(mx, s);       }       if (sum > mx && f1) {         cout <<  YES  << endl;       } else {         cout <<  NO  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   constexpr int kN = int(2E5 + 10), kInf = int(1E9 + 10), kC = int(1E6 + 10);   struct seg_tree {     long long int val[kN << 2], flag[kN << 2];     void init() {       memset(val, 0, sizeof(val));       memset(flag, 0, sizeof(flag));       return;     }     void addtag(int n, long long int x) {       flag[n] += x;       val[n] += x;     }     void push(int n) {       if (flag[n]) {         addtag(n << 1, flag[n]);         addtag(n << 1 | 1, flag[n]);         flag[n] = 0;       }       return;     }     void pull(int n) {       val[n] = max(val[n << 1], val[n << 1 | 1]);       return;     }     void fix(int n, int l, int r, int L, int R, long long int x) {       if (L <= l && r <= R)         addtag(n, x);       else if (!(l > R || L > r)) {         int mid = (l + r) >> 1;         push(n);         fix(n << 1, l, mid, L, R, x);         fix(n << 1 | 1, mid + 1, r, L, R, x);         pull(n);       }       return;     }   };   pair<int, int> wep[kN], eqi[kN];   pair<pair<int, int>, int> mon[kN];   int pos[kC];   seg_tree sg;   int main() {     int n, m, p, now = 1;     long long int ans;     scanf( %d%d%d , &n, &m, &p);     for (int i = 1; i <= n; i++) scanf( %d%d , &wep[i].first, &wep[i].second);     for (int i = 1; i <= m; i++) scanf( %d%d , &eqi[i].first, &eqi[i].second);     for (int i = 1; i <= p; i++)       scanf( %d%d%d , &mon[i].first.first, &mon[i].first.second, &mon[i].second);     sort(wep + 1, wep + n + 1);     sort(eqi + 1, eqi + m + 1);     sort(mon + 1, mon + p + 1);     sg.init();     for (int i = 1; i <= m; i++) sg.fix(1, 1, m, i, i, -eqi[i].second);     for (int i = 0; i < kC; i++) {       while (now <= m) {         if (eqi[now].first <= i)           now++;         else           break;       }       pos[i] = now;     }     ans = -wep[1].second - eqi[1].second;     now = 1;     for (int i = 1; i <= n; i++) {       while (now <= p) {         if (mon[now].first.first < wep[i].first) {           if (pos[mon[now].first.second] <= m)             sg.fix(1, 1, m, pos[mon[now].first.second], m, mon[now].second);           now++;         } else           break;       }       ans = max(ans, sg.val[1] - wep[i].second);     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int n, a[25], d[25][25], f[1 << 25], ans = INT_MAX;   int popcnt(int x) {     int cnt = 0;     while (x > 0) cnt += (x & 1), x >>= 1;     return cnt;   }   int main() {     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];       for (int j = 0; j < i; ++j) d[i][j] = -1;       for (int j = 0; j < i; ++j)         for (int k = j; k < i; ++k)           if (a[j] + a[k] == a[i]) d[i][j] = k, d[i][k] = j;     }     f[1] = true;     for (int i = 1; i < n; ++i)       for (int j = 1 << (i - 1); j < (1 << i); ++j)         if (f[j] == true)           for (int k = 0; k < i; ++k)             if (j & (1 << k) && d[i][k] >= 0 && (j & (1 << d[i][k]))) {               for (int l = 0; l <= i; ++l) f[(j & (~(1 << l))) | (1 << i)] = true;               break;             }     for (int i = 1 << (n - 1); i < (1 << n); ++i)       if (f[i] == true) ans = min(ans, popcnt(i));     if (ans == INT_MAX)       cout << -1;     else       cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const double pi = 3.1415926535897932384626;   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   const int maxn = 1e2 + 5;   int t, n;   char s1[maxn], s2[maxn];   int main() {     t = read();     while (t--) {       n = read();       scanf( %s%s , s1, s2);       int minv = inf;       for (int i = 0; i < n; ++i) {         int k = i;         for (int j = 0; j < n; ++j) {           if (k < n && s1[j] == s2[k]) ++k;           minv = min(minv, n - k + i);         }       }       sort(s1, s1 + n);       sort(s2, s2 + n);       if (strcmp(s1, s2))         printf( -1 n );       else         printf( %d n , minv);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int ppl, s = 0, maxn = 0;     cin >> ppl;     int wel[ppl];     for (int j = 0; j < ppl; j++) {       cin >> wel[j];       if (maxn < wel[j]) {         maxn = wel[j];       }     }     for (int i = 0; i < ppl; i++) {       s = s + maxn - wel[i];     }     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10, size = 1 << 20;   template <class o>   void qr(o &x) {     char c = getchar();     x = 0;     int f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) x = x * 10 + c -  0 , c = getchar();     x *= f;   }   template <class o>   void qw(o x) {     if (x / 10) qw(x / 10);     putchar(x % 10 +  0 );   }   template <class o>   void pr1(o x) {     if (x < 0) x = -x, putchar( - );     qw(x);     putchar(   );   }   template <class o>   void pr2(o x) {     if (x < 0) x = -x, putchar( - );     qw(x);     puts(  );   }   int T, n, last, tot, f[N], b[N], c[N];   char s[N];   long long ans;   struct node {     int fa, len, v[26];   } tr[N];   void add(int c) {     int p = last, x = last = ++tot;     tr[x].len = tr[p].len + 1;     for (; p && tr[p].v[c] == 0; p = tr[p].fa) tr[p].v[c] = x;     if (!p)       tr[x].fa = 1;     else {       int q = tr[p].v[c], y;       if (tr[p].len + 1 == tr[q].len)         tr[x].fa = q;       else {         tr[y = ++tot] = tr[q];         tr[y].len = tr[p].len + 1;         tr[q].fa = tr[x].fa = y;         for (; p && tr[p].v[c] == q; p = tr[p].fa) tr[p].v[c] = y;       }     }   }   void init() {     memset(tr + 1, 0, tot * 28 << 2);     memset(f + 1, 0, tot << 2);     memset(c, 0, n + 1 << 2);     last = tot = 1;     ans = n = 0;   }   int main() {     qr(T);     while (T--) {       init();       scanf( %s , s + 1);       for (int i = 1; s[i]; i++) n++, add(s[i] -=  a ), f[last]++;       for (int i = 1; i <= tot; i++) c[tr[i].len]++;       for (int i = 1; i <= n; i++) c[i] += c[i - 1];       for (int i = tot; i; i--) b[c[tr[i].len]--] = i;       for (int i = tot, j; i; i--) {         j = b[i];         f[tr[j].fa] += f[j];         ans += (long long)f[j] * f[j] * (tr[j].len - tr[tr[j].fa].len);       }       pr2(ans);     }     return 0;   }


#include <bits/stdc++.h>   int H[10];   int main() {     memset(H, 0, sizeof(H));     for (int _n = 6, i = 0; i < _n; i++) {       int v;       scanf( %d , &v);       H[v]++;     }     bool n6, n4, n5, n2;     n6 = n4 = n5 = n2 = false;     for (int _n = 10, i = 0; i < _n; i++)       if (H[i] == 4)         n4 = true;       else if (H[i] == 6)         n6 = true;       else if (H[i] == 5)         n5 = true;       else if (H[i] == 2)         n2 = true;     if (n6 || (n4 && n2))       printf( Elephant n );     else if ((n4 && !n2) || n5)       printf( Bear n );     else       printf( Alien n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, k;     cin >> n;     long long int a[n], b[n], c[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       b[i] = 1;       c[i] = 1;     }     long long int ans = 1;     for (int i = 1; i < n; i++) {       if (a[i] > a[i - 1]) b[i] = b[i - 1] + 1;       ans = max(ans, b[i]);     }     c[n - 1] = 1;     for (int i = n - 2; i >= 0; i--) {       if (a[i + 1] > a[i]) c[i] = c[i + 1] + 1;       ans = max(ans, c[i]);     }     for (int i = 1; i <= n - 2; i++)       if (a[i + 1] > a[i - 1]) ans = max(ans, c[i + 1] + b[i - 1]);     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int i;     map<string, string> mp1to2;     map<string, string> mp2to1;     map<string, int> mp1p;     map<string, int> mp2p;     for (i = 1; i <= m; i++) {       string w1, w2;       cin >> w1 >> w2;       mp1to2[w1] = w2;       mp2to1[w2] = w1;       mp1p[w1]++;       mp2p[w2]++;     }     for (i = 1; i <= n; i++) {       string word;       cin >> word;       if (mp1p[word] > 0) {         int len1 = word.length();         int len2 = mp1to2[word].length();         if (len1 <= len2) {           printf( %s  , word.c_str());         } else {           printf( %s  , mp1to2[word].c_str());         }       } else {         int len1 = mp2to1[word].length();         int len2 = word.length();         if (len1 <= len2) {           printf( %s  , mp2to1[word].c_str());         } else {           printf( %s  , word.c_str());         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long fact(long long n) {     if (n == 0 || n == 1)       return 1;     else       return n * fact(n - 1);   }   long long gcd(long long a, long long b) {     if (a < 0) a = -a;     if (b < 0) b = -b;     if (a == 1 || b == 1)       return 1;     else if (a == 0)       return b;     else if (b == 0)       return a;     else {       long long r = a > b ? a % b : b % a;       if (r == 0)         return min(a, b);       else         return gcd(min(a, b), r);     }   }   bool Comparator(int a, int b) { return (a >= b); }   long long M = 1e9 + 7;   long long solve() {     int n;     cin >> n;     vector<int> inf(n, 0), tt(n, 0), ans(n, 0);     for (long long i = 1; i < n; i++) {       cin >> inf[i];       inf[i]--;     }     tt[1] = 1;     for (long long i = 2; i < n; i++) {       tt[i] = tt[inf[i]] + 1;     }     for (long long i = 0; i < n; i++) {       ans[tt[i]]++;     }     long long sum = 0;     for (long long i = 0; i < n; i++) {       sum += ans[i] % 2;     }     return sum;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       cout << solve() <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, x = 0;     char arra[10];     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %s , arra);       if (arra[0] ==  +  || arra[1] ==  + )         x = x + 1;       else if (arra[0] ==  -  || arra[1] ==  - )         x = x - 1;     }     printf( %d n , x);   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   vector<pair<long long, long long> > nums;   int main() {     cin >> n;     nums.resize(n);     for (int i = 0; i < n; i++) {       long long a, b;       cin >> a >> b;       nums[i] = make_pair(b, a);     }     sort(nums.begin(), nums.end());     long long res = 0;     long long left;     long long fac = 1;     long long last_left = 0;     cin >> k;     vector<long long> ks(k + 1);     for (int i = 0; i < k; i++) cin >> ks[i];     ks[k] = -1;     long long k_cnt = 0;     left = ks[0];     for (int i = 0; i < n; i++) {       if (left == -1) {         res += fac * nums[i].second * nums[i].first;         continue;       }       if (left <= nums[i].second) {         res += fac * left * nums[i].first;         nums[i].second -= left;         i--;         k_cnt++;         if (ks[k_cnt] == -1)           left = -1;         else           left = (ks[k_cnt] - ks[k_cnt - 1]);         fac++;       } else {         res += fac * nums[i].second * nums[i].first;         left -= nums[i].second;         nums[i].second = 0;       }     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 100;   int arr[maxn];   int cum[maxn], n, m, k;   int dp[2020];   map<int, int> offer;   int range(int l, int r) { return (cum[r] - cum[l]); }   int solve(int i) {     if (i == k) return 0;     int &ret = dp[i];     if (ret != -1) return ret;     ret = 1e9;     for (int j = i + 1; j <= k; j++) {       int buy = (j - i);       int of = offer[buy];       int taka = range(i, j);       int offtaka = range(i, i + of);       ret = min(ret, taka - offtaka + solve(j));     }     return ret;   }   int main() {     scanf( %d%d%d , &n, &m, &k);     memset(dp, -1, sizeof dp);     for (int i = 1; i <= n; i++) scanf( %d , &arr[i]);     sort(arr + 1, arr + n + 1);     for (int i = 1; i <= m; i++) {       int xi, yi;       scanf( %d%d , &xi, &yi);       offer[xi] = max(offer[xi], yi);     }     for (int i = 1; i <= k; i++) cum[i] = cum[i - 1] + arr[i];     cout << solve(0) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   FILE *in = stdin;   class node {    public:     long long sum[5], hnode;     node() {       sum[0] = sum[1] = sum[2] = sum[3] = sum[4] = hnode = 0;       return;     }     node(int x) {       for (int q = 0; q < 5; q++) {         sum[q] = 0;       }       sum[0] = x;       hnode = 1;       return;     }   };   node merge(node a, node b) {     node c;     c.hnode = a.hnode + b.hnode;     int left = a.hnode % 5;     for (int q = 0; q < 5; q++) {       c.sum[q] = a.sum[q] + b.sum[(5 - left + q) % 5];     }     return c;   }   class segment_tree {    public:     node tree[4 * 100000];     segment_tree() {       for (int q = 0; q < 4 * 100000; q++) {         tree[q] = node();       }       return;     }     void add(int i, int l, int r, int x, int v, int typ) {       if (l == r) {         if (typ == 0) {           tree[i] = node(v);         } else {           tree[i] = node();         }         return;       }       int mid = (l + r) >> 1;       if (x <= mid)         add(i * 2, l, mid, x, v, typ);       else         add(i * 2 + 1, mid + 1, r, x, v, typ);       tree[i] = merge(tree[i * 2], tree[i * 2 + 1]);       return;     }     long long sum() { return tree[1].sum[2]; }   };   int N, a[100000][2];   set<int> heap;   segment_tree seg;   map<int, int> ind;   int main() {     fscanf(in,  %d , &N);     for (int q = 0; q < N; q++) {       char qq[22];       int x;       fscanf(in,  %s , qq);       if (qq[0] ==  s ) {         a[q][0] = -1;       } else {         fscanf(in,  %d , &x);         if (qq[0] ==  a )           a[q][0] = 0;         else           a[q][0] = 1;         a[q][1] = x;         heap.insert(x);       }     }     int cind = 0;     for (set<int>::iterator it = heap.begin(); it != heap.end(); it++) {       ind[*it] = cind;       cind++;     }     for (int q = 0; q < N; q++) {       if (a[q][0] == -1) {         printf( %I64d n , seg.sum());       } else {         seg.add(1, 0, cind - 1, ind[a[q][1]], a[q][1], a[q][0]);       }     }     return 0;   }