#include <bits/stdc++.h>   using namespace std;   const int inf = INT_MAX;   const int mod = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[2][n];       int sum[2][n];       for (int i = 0; i < 2; i++) {         for (int j = 0; j < n; j++) {           cin >> arr[i][j];           if (j == 0)             sum[i][j] = arr[i][j];           else             sum[i][j] = sum[i][j - 1] + arr[i][j];         }       }       int move1 = sum[0][n - 1];       int move2 = sum[1][n - 1];       int ans = min(move1 - arr[0][0], move2 - arr[1][n - 1]);       for (int i = 1; i < n; i++) {         int temp1 = move1 - sum[0][i];         int temp2 = sum[1][i - 1];         ans = min(ans, max(temp1, temp2));       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:167772160 )   using namespace std;   int main() {     int n;     cin >> n;     pair<int, int> x[1111];     for (int i = 0; i < n; ++i) cin >> x[i].first >> x[i].second;     long long p = 0, maxx = -1;     int j = 0;     for (int i = 0; i < x[n - 1].first; i++) {       if (p != 0) --p;       if (i == x[j].first - 1) {         p += x[j].second;         ++j;       }       if (p > maxx) maxx = p;     }     cout << x[n - 1].first + p <<     << maxx << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, k, a, b;   vector<long long int> arr;   long long int rec(long long int l, long long int r) {     long long int i = lower_bound(arr.begin(), arr.end(), l) - arr.begin();     long long int j = upper_bound(arr.begin(), arr.end(), r) - arr.begin();     long long int x = j - i;     long long int val;     if (x == 0) {       val = a;     } else {       val = b * x * (r - l + 1);     }     if (l == r || x == 0) {       return val;     }     long long int mid = (l + r) / 2;     return min(val, rec(l, mid) + rec(mid + 1, r));   }   int main() {     cin >> n >> k >> a >> b;     for (int i = 0; i < k; i++) {       int x;       cin >> x;       arr.push_back(x);     }     sort(arr.begin(), arr.end());     long long int start = 1;     long long int end = pow(2, n);     cout << rec(start, end) << endl;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   char s[N];   int main() {     vector<int> v1, v2;     scanf( %s , s);     int len = strlen(s);     for (int i = 0; i < len; i++) {       if (s[i] ==  l ) {         v1.push_back(i + 1);       } else         v2.push_back(i + 1);     }     for (int x : v2) printf( %d n , x);     for (int i = (int)v1.size() - 1; i >= 0; i--) printf( %d n , v1[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   int n, p[4], bx[N], wx, by[N], wy, sum[N][4];   vector<int> wh[N];   struct node {     int x, y, c;   } sh[N];   bool cmp(node a, node b) { return a.x < b.x; }   inline int read() {     int f = 1, x = 0;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f = -1;       s = getchar();     }     while (s >=  0  && s <=  9 ) {       x = x * 10 + s -  0 ;       s = getchar();     }     return x * f;   }   struct bit {     int sh[N];     void init() { memset(sh, 0, sizeof(sh)); }     int lowbit(int x) { return x & (-x); }     void change(int x, int v) {       while (x <= n) sh[x] += v, x += lowbit(x);     }     int query(int x) {       int ans = 0;       while (x) ans += sh[x], x -= lowbit(x);       return ans;     }     int ask(int l, int r) { return query(r) - query(l - 1); }   } T[4];   int g(int l, int r, int c) { return sum[r][c] - sum[l - 1][c]; }   void init() {     memset(sum, 0, sizeof(sum));     wx = wy = 0;     for (int i = 1; i <= n; i++) bx[++wx] = sh[i].x;     sort(bx + 1, bx + 1 + wx);     wx = unique(bx + 1, bx + 1 + wx) - bx - 1;     for (int i = 1; i <= n; i++)       sh[i].x = lower_bound(bx + 1, bx + 1 + wx, sh[i].x) - bx;     for (int i = 1; i <= n; i++) by[++wy] = sh[i].y;     sort(by + 1, by + 1 + wy);     wy = unique(by + 1, by + 1 + wy) - by - 1;     for (int i = 1; i <= n; i++)       sh[i].y = lower_bound(by + 1, by + 1 + wy, sh[i].y) - by;     sort(sh + 1, sh + 1 + n, cmp);     for (int i = 1; i <= n; i++) sum[sh[i].x][sh[i].c]++;     for (int i = 1; i <= wx; i++)       for (int j = 1; j <= 3; j++) sum[i][j] += sum[i - 1][j];   }   int solve() {     for (int i = 1; i <= wx; i++) wh[i].clear();     for (int i = 1; i <= n; i++) wh[sh[i].x].push_back(i);     for (int i = 1; i <= 3; i++) p[i] = i;     int ans = 1;     do {       for (int i = 2; i <= wx; i++) {         int A = sum[i - 1][p[1]], l = i, r = wx - 1;         while (l < r) {           int mid = l + ((r - l + 1) >> 1);           if (g(i, mid, p[2]) <= g(mid + 1, wx, p[3]))             l = mid;           else             r = mid - 1;         }         ans = max(ans, min({A, g(i, l, p[2]), g(l + 1, wx, p[3])}));         l++;         ans = max(ans, min({A, g(i, l, p[2]), g(l + 1, wx, p[3])}));       }     } while (next_permutation(p + 1, p + 4));     for (int i = 1; i <= 3; i++) p[i] = i;     auto find = [](int A, int &ans) {       int l = 1, r = wy - 1;       while (l < r) {         int mid = l + ((r - l + 1) >> 1);         if (T[p[2]].ask(1, mid) <= T[p[3]].ask(mid + 1, wy))           l = mid;         else           r = mid - 1;       }       ans = max(ans, min({A, T[p[2]].ask(1, l), T[p[3]].ask(l + 1, wy)}));       l++;       ans = max(ans, min({A, T[p[2]].ask(1, l), T[p[3]].ask(l + 1, wy)}));     };     do {       T[p[2]].init();       T[p[3]].init();       for (int i = wx; i >= 1; i--) {         int A = g(1, i, p[1]);         find(A, ans);         for (int j : wh[i])           if (sh[j].c != p[1]) T[sh[j].c].change(sh[j].y, 1);       }     } while (next_permutation(p + 1, p + 4));     for (int i = 1; i <= 3; i++) p[i] = i;     do {       T[p[2]].init();       T[p[3]].init();       for (int i = 1; i <= wx; i++) {         int A = g(i, wx, p[1]);         find(A, ans);         for (int j : wh[i])           if (sh[j].c != p[1]) T[sh[j].c].change(sh[j].y, 1);       }     } while (next_permutation(p + 1, p + 4));     return ans;   }   signed main() {     n = read();     for (int i = 1; i <= n; i++) sh[i] = (node){read(), read(), read()};     init();     int ans = solve();     for (int i = 1; i <= n; i++) swap(sh[i].x, sh[i].y);     init();     ans = max(ans, solve());     printf( %d n , ans * 3);   }


#include <bits/stdc++.h>   static const int MAXN = 50004;   static const int MAXE = 100004 * 2;   static const int MAXL = 20;   static const int MAXT = 1000005;   int n, e;   int head[MAXN], dest[MAXE], next[MAXE];   int l[MAXN], t[MAXN][MAXL];   int T = 0;   int p[MAXN];   int conf[MAXN], team[MAXN];   int team_conf[MAXT];   inline void add_edge(int u, int v) {     static int w = 0;     dest[w] = v;     next[w] = head[u];     head[u] = w++;   }   int main() {     scanf( %d%d , &n, &e);     for (int i = 0; i < n; ++i) head[i] = -1;     int u, v;     for (int i = 0; i < e; ++i) {       scanf( %d%d , &u, &v);       --u, --v;       add_edge(u, v);       add_edge(v, u);     }     for (int i = 0; i < n; ++i) {       scanf( %d , &l[i]);       for (int j = 0; j < l[i]; ++j) {         scanf( %d , &t[i][j]);         --t[i][j];         T = std::max(T, t[i][j]);       }     }     ++T;     srand(87665544);     for (int i = 0; i < n; ++i) p[i] = i;     for (int attempts = 0;; ++attempts) {       if (attempts % 16 == 0) {         std::random_shuffle(p, p + n);         std::fill(conf, conf + n, -1);         int ct[2];         for (int i = 0; i < n; ++i) {           ct[0] = ct[1] = 0;           for (int w = head[p[i]]; w != -1; w = next[w]) {             if (conf[dest[w]] != -1) ++ct[conf[dest[w]]];           }           conf[p[i]] = (ct[0] > ct[1] ? 1 : 0);         }       }       for (int i = 0; i < T; ++i) team_conf[i] = rand() % 2;       bool valid = true;       for (int i = 0; i < n; ++i) {         team[i] = -1;         for (int j = 0; j < l[i]; ++j)           if (conf[i] == team_conf[t[i][j]]) {             team[i] = t[i][j];             break;           }         if (team[i] == -1) {           valid = false;           break;         }       }       if (!valid) continue;       for (int i = 0; i < n; ++i)         printf( %d%c , team[i] + 1, i == n - 1 ?   n  :    );       for (int i = 0; i < T; ++i)         printf( %d%c , team_conf[i] + 1, i == T - 1 ?   n  :    );       break;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int ans = 654;   vector<int> a, b, us(10);   int main() {     cin >> n >> m;     a.resize(n);     b.resize(m);     for (int i = 0; i < n; ++i) {       cin >> a[i];       us[a[i]] = 1;     }     for (int j = 0; j < m; ++j) {       cin >> b[j];       if (us[b[j]] == 1) {         ans = min(ans, b[j]);       }     }     sort(a.begin(), a.end());     sort(b.begin(), b.end());     cout << min({(a[0] * 10) + b[0], (b[0] * 10) + a[0], ans});   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   int dp[1001][2010];   int digit[1002], k;   void init() { memset(dp, -1, sizeof dp); }   int dfs(int pos, int dist, bool doing) {     if (pos == -1) return dist == 0;     if (!doing && dp[pos][dist] != -1) return dp[pos][dist];     int ans = 0;     int end = doing ? digit[pos] : 9;     for (int i = 0; i <= end; i++) {       int nextdist = dist == 0 ? 0 : dist + 1;       if (i == 4 || i == 7) {         if (dist <= k)           nextdist = 0;         else           nextdist = 1;       }       ans = (ans + dfs(pos - 1, nextdist, doing && i == end)) % MOD;     }     if (!doing) dp[pos][dist] = ans;     return ans;   }   int cal(char x[]) {     int pos = 0, l = strlen(x);     while (pos < l) {       digit[pos] = x[l - pos - 1] -  0 ;       pos++;     }     return dfs(pos - 1, k + 2, 1);   }   bool check(char x[]) {     int dist = k + 1;     for (int i = 0; i < strlen(x); i++) {       if (!dist) break;       if (x[i] ==  4  || x[i] ==  7 ) {         if (dist <= k)           dist = 0;         else           dist = 1;       } else         dist++;     }     return dist == 0;   }   int main() {     int T;     init();     char a[1002], b[1002];     scanf( %d %d , &T, &k);     while (T--) {       scanf( %s %s , a, b);       int ansa = cal(a);       int ansb = cal(b);       if (check(a)) ansa--;       ansb = ((ansb - ansa) % MOD + MOD) % MOD;       printf( %d n , ansb);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<string> vec_splitter(string s) {     s +=  , ;     vector<string> res;     while (!s.empty()) {       res.push_back(s.substr(0, s.find( , )));       s = s.substr(s.find( , ) + 1);     }     return res;   }   void debug_out(vector<string> __attribute__((unused)) args,                  __attribute__((unused)) int idx,                  __attribute__((unused)) int LINE_NUM) {     cerr <<   n ;   }   template <typename Head, typename... Tail>   void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {     if (idx > 0)       cerr <<  ,  ;     else       cerr <<  Line(  << LINE_NUM <<  )  ;     stringstream ss;     ss << H;     cerr << args[idx] <<   =   << ss.str();     debug_out(args, idx + 1, LINE_NUM, T...);   }   void run() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr), cout.tie(nullptr);   }   const int N = 5e4 + 4, MOD = 1e9 + 7, mod2 = 998244353;   int dp[N][503];   int n, k;   vector<int> adj[N];   long long ans;   void dfs(int u, int p) {     dp[u][0] = 1;     for (auto &v : adj[u]) {       if (v == p) continue;       dfs(v, u);       for (int i = 0; i < k; ++i) {         dp[u][i + 1] += dp[v][i];       }     }     long long sum = 0;     for (auto &v : adj[u]) {       if (v == p) continue;       for (int i = 1; i < k; ++i) {         sum += dp[v][i - 1] * (dp[u][k - i] - dp[v][k - i - 1]);       }     }     ans += dp[u][k] + sum / 2;   }   int main() {     run();     cin >> n >> k;     for (int i = 0; i < (int)(n - 1); ++i) {       int u, v;       cin >> u >> v;       adj[v].push_back(u);       adj[u].push_back(v);     }     dfs(1, -1);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   void Genawy() {     std::ios_base::sync_with_stdio(0);     cin.tie(NULL);   }   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int n, cost[305];   int length[305];   map<pair<int, int>, int> dp;   int solve(int ind, int gc) {     if (ind == n) return gc == 1 ? 0 : 1e9;     if (dp.find({ind, gc}) != dp.end()) return dp[{ind, gc}];     dp[{ind, gc}] = solve(ind + 1, gc);     dp[{ind, gc}] =         min(dp[{ind, gc}], solve(ind + 1, gcd(gc, length[ind])) + cost[ind]);     return dp[{ind, gc}];   }   int main() {     Genawy();     cin >> n;     for (int i = 0; i < n; i++) cin >> length[i];     for (int i = 0; i < n; i++) cin >> cost[i];     int ans = solve(0, 0);     if (ans >= 1e9) ans = -1;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   int compare(const void *a, const void *b) {     long long la = *(long long *)a;     long long lb = *(long long *)b;     return la == lb ? 0 : la < lb ? -1 : 1;   }   long long aa[8], aa_[8];   int bb[8], dp[8][1 << (8 - 1)];   char pp[8];   int n, ans = 0x3f3f3f3f;   void solve(int i) {     int j;     if (i == n) {       int cnt, sum;       cnt = 0, sum = 0;       for (i = 0; i < n; i++) {         int k;         if (!pp[i]) cnt++;         k = dp[i][bb[i]];         sum += k == 1 && bb[i] == 0 ? 1 : k + 1;       }       if (cnt >= 2) sum++;       if (ans > sum) ans = sum;       return;     }     solve(i + 1);     pp[i] = 1;     for (j = i + 1; j < n; j++)       if (aa_[j] % aa[i] == 0) {         aa_[j] /= aa[i], bb[j] ^= 1 << i;         solve(i + 1);         aa_[j] *= aa[i], bb[j] ^= 1 << i;       }     pp[i] = 0;   }   int main() {     int i, j;     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %lld , &aa[i]);     qsort(aa, n, sizeof *aa, compare);     for (i = 0; i < n; i++) {       long long a;       int k, p, b;       a = aa[i];       k = 0;       for (p = 2; p <= a / p; p++)         while (a % p == 0) {           k++;           a /= p;         }       if (a > 1) k++;       dp[i][0] = k;       for (b = 1; b < 1 << i; b++) {         a = aa[i];         k = dp[i][0];         for (j = 0; j < i; j++)           if ((b & 1 << j)) {             if (a % aa[j] != 0) {               k = -1;               break;             }             a /= aa[j];             k -= dp[j][0];           }         dp[i][b] = k;       }     }     for (i = 0; i < n; i++) aa_[i] = aa[i];     solve(0);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<string> v;   int main() {     string x, y;     int cnt = 0;     char temp;     int n;     cin >> n;     n = n + n - 1;     for (int i = 0; i < n; i++) {       cin >> x;       if (x ==  ** ) continue;       cin >> y;       x += y;       sort(v.begin(), v.end());       if (binary_search(v.begin(), v.end(), x)) continue;       cnt++;       v.push_back(x);       for (int j = 1; j <= 3; j++) {         y =   ;         if (j == 1) {           y += x[2];           y += x[0];           y += x[3];           y += x[1];           v.push_back(y);         } else if (j == 2) {           y += x[3];           y += x[2];           y += x[1];           y += x[0];           v.push_back(y);         } else if (j == 3) {           y += x[1];           y += x[3];           y += x[0];           y += x[2];           v.push_back(y);         }       }     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const int inf = 1 << 30;   int n, qn, tot = 0, head[N], col[N], nowHead[N], deg[N], seq[N];   int dfsc = 0, id[N], siz[N], fa[N], son[N], dep[N], top[N];   bool vis[N];   struct Edge {     int to, nxt;   } e[N << 1];   inline void add(int from, int to) {     e[++tot].to = to;     e[tot].nxt = head[from];     head[from] = tot;   }   struct Seg {     int l, r, c;     inline Seg(int L = 0, int R = 0, int C = 0) { l = L, r = R, c = C; }     friend bool operator<(const Seg x, const Seg y) { return x.l < y.l; }   };   set<Seg> seg[N];   template <typename T>   inline void read(T &X) {     X = 0;     char ch = 0;     T op = 1;     for (; ch >  9  || ch <  0 ; ch = getchar())       if (ch ==  - ) op = -1;     for (; ch >=  0  && ch <=  9 ; ch = getchar())       X = (X << 3) + (X << 1) + ch - 48;     X *= op;   }   namespace Bit {   int s[N << 1];   inline void modify(int p, int v) {     if (!p) return;     for (; p < (N << 1); p += (p & (-p))) s[p] += v;   }   inline int query(int p) {     int res = 0;     for (; p > 0; p -= (p & (-p))) res += s[p];     return res;   }   }  // namespace Bit   void dfs1(int x, int fat, int depth) {     fa[x] = fat, dep[x] = depth, siz[x] = 1;     int maxson = -1;     for (int i = head[x]; i; i = e[i].nxt) {       int y = e[i].to;       if (y == fat) continue;       dfs1(y, x, depth + 1);       siz[x] += siz[y];       if (siz[y] > maxson) {         maxson = siz[y];         son[x] = y;       }     }   }   void dfs2(int x, int topf) {     top[x] = topf, id[x] = ++dfsc;     if (!son[x]) return;     dfs2(son[x], topf);     for (int i = head[x]; i; i = e[i].nxt) {       int y = e[i].to;       if (y == fa[x] || y == son[x]) continue;       dfs2(y, y);     }   }   inline int getLca(int x, int y) {     for (; top[x] != top[y];) {       if (dep[top[x]] < dep[top[y]]) swap(x, y);       x = fa[top[x]];     }     return dep[x] < dep[y] ? x : y;   }   inline int getDis(int x, int y) {     return dep[x] + dep[y] - 2 * dep[getLca(x, y)];   }   inline set<Seg>::iterator getSeg(set<Seg> &s, int l) {     set<Seg>::iterator it = s.lower_bound(Seg(l, inf, 0));     if (it != s.end() && it->l == l) return it;     --it;     int nowl = it->l, nowr = it->r, nowc = it->c;     s.erase(it);     if (l - 1 >= nowl) s.insert(Seg(nowl, l - 1, nowc));     s.insert(Seg(l, nowr, nowc));     return s.lower_bound(Seg(l, nowr, nowc));   }   inline void ins(set<Seg> &s, int l, int r, int c, int st) {     set<Seg>::iterator itl = getSeg(s, l), itr;     if (r + 1 <= id[st] + siz[st] - 1)       itr = getSeg(s, r + 1);     else       itr = s.end();     for (set<Seg>::iterator it = itl; it != itr; ++it) {       Bit ::modify(it->c, -((it->r) - (it->l) + 1));     }     Bit ::modify(c, r - l + 1);     s.erase(itl, itr), s.insert(Seg(l, r, c));   }   inline void modify(int x, int y, int c) {     nowHead[c] = y;     for (; top[x] != top[y];) {       if (dep[top[x]] < dep[top[y]]) swap(x, y);       ins(seg[top[x]], id[top[x]], id[x], c, top[x]);       x = fa[top[x]];     }     if (dep[x] > dep[y]) swap(x, y);     ins(seg[top[x]], id[x], id[y], c, top[x]);   }   inline int solve(int x) {     int c = getSeg(seg[top[x]], id[x])->c;     return Bit ::query(c - 1) + getDis(x, nowHead[c]) + 1;   }   int main() {     read(n), read(qn);     for (int x, y, i = 1; i < n; i++) {       read(x), read(y);       ++deg[x], ++deg[y];       add(x, y), add(y, x);     }     dfs1(1, 0, 1), dfs2(1, 1);     int cnt = 0;     set<int> q;     for (int i = 1; i <= n; i++)       if (deg[i] == 1) q.insert(i), vis[i] = 1;     for (; !q.empty();) {       int now = (*q.begin());       q.erase(*q.begin());       seq[now] = ++cnt;       nowHead[cnt] = now;       seg[top[now]].insert(Seg(id[now], id[now], cnt));       Bit ::modify(cnt, 1);       for (int i = head[now]; i; i = e[i].nxt) {         if (vis[e[i].to]) continue;         --deg[e[i].to];         if (deg[e[i].to] == 1 && !vis[e[i].to])           q.insert(e[i].to), vis[e[i].to] = 1;       }     }     int lst = n;     for (char op[9]; qn--;) {       scanf( %s , op);       if (op[0] ==  u ) {         int x;         read(x);         modify(x, lst, ++cnt);         lst = x;       }       if (op[0] ==  w ) {         int x;         read(x);         printf( %d n , solve(x));       }       if (op[0] ==  c ) {         int x, y;         read(x), read(y);         printf( %d n , solve(x) < solve(y) ? x : y);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9 + 7;   int up(int n) {     int r = 1;     while (r < n) r <<= 1;     return r;   }   class segtree {     vector<int> arr;     vector<bool> laz;     void inv(int l, int r, int cl, int cr, int v) {       if (r <= cl || cr <= l) return;       push(v);       if (l <= cl && cr <= r) {         laz[v] = !laz[v];         return;       }       int ct = (cl + cr) / 2;       inv(l, r, cl, ct, 2 * v);       inv(l, r, ct, cr, 2 * v + 1);       upd(v);     }     int cnt(int l, int r, int cl, int cr, int v) {       if (r <= cl || cr <= l) return 0;       push(v);       if (l <= cl && cr <= r) return arr[v];       int ct = (cl + cr) / 2;       ct = cnt(l, r, cl, ct, 2 * v) + cnt(l, r, ct, cr, 2 * v + 1);       upd(v);       return ct;     }     void push(int v) {       if (laz[v]) {         laz[v] = false;         arr[v] = arr.size() / up(v + 1) - arr[v];         if (v < (int)arr.size() / 2) {           laz[2 * v] = !laz[2 * v];           laz[2 * v + 1] = !laz[2 * v + 1];         }       }     }     void upd(int v) {       if (v < (int)arr.size() / 2) {         push(2 * v);         push(2 * v + 1);         arr[v] = arr[2 * v] + arr[2 * v + 1];       }     }       public:     segtree(int n) : arr(2 * up(n)), laz(2 * up(n)) {}     void inv(int l, int r) { inv(l, r, 0, arr.size() / 2, 1); }     int cnt(int l, int r) { return cnt(l, r, 0, arr.size() / 2, 1); }   };   void dfs(const vector<vector<int>> &gr, int v, vector<int> &in,            vector<int> &out, int &cnt) {     in[v] = cnt++;     for (auto it : gr[v]) dfs(gr, it, in, out, cnt);     out[v] = ++cnt;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<vector<int>> gr(n);     for (int i = 1; i < n; i++) {       int p;       cin >> p;       p--;       gr[p].push_back(i);     }     vector<int> in(n), out(n);     n = 0;     dfs(gr, 0, in, out, n);     segtree st(n);     n /= 2;     for (int i = 0; i < n; i++) {       int t;       cin >> t;       if (t == 1) {         st.inv(in[i], in[i] + 1);         st.inv(out[i] - 1, out[i]);       }     }     int q;     cin >> q;     for (int i = 0; i < q; i++) {       string s;       int t;       cin >> s >> t;       t--;       if (s ==  get ) {         cout << st.cnt(in[t], out[t]) / 2 << endl;       } else {         assert(s ==  pow );         st.inv(in[t], out[t]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       long long int a[n], sum = 0, fg = 0, cnt = 0, ind = 1, ans = 0;       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n; i++) {         if (a[i] <= ind) {           ind++;           continue;         }         ans = ans + a[i] - ind;         ind = a[i] + 1;       }       cout << ans;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     s =  *  + s;     int add = 0;     int n = (s.length()) - 1;     for (int i = 1; i + i <= n; i++) {       if (s[i] != s[s.size() - i]) {         add++;       }     }     if (add <= 1 && (n & 1) || add == 1)       cout <<  YES n ;     else       cout <<  NO n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, i, j, arr[300] = {0}, p = 0, k = 0, c, d;     cin >> n >> a;     for (i = 1; i < n + 1; i++) {       cin >> arr[i];     }     arr[0] = 1, arr[n + 1] = 1;     j = min(a, n - a + 1);     for (i = j; i < n + 1; i++) {       c = a + k;       d = a - k;       if (d < 1) d = 0;       if (c > n) c = n + 1;       if (arr[d] == arr[c] and arr[c]) {         if (c != d and c <= n and d > 0)           p += 2;         else           p++;       }       k++;     }     cout << p << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int x, y;   } arr[104];   vector<int> graph[105];   int visited[105] = {0};   void dfs(int i) {     visited[i] = 1;     int j = 0;     while (j < graph[i].size()) {       if (visited[graph[i][j]] == 0) {         dfs(graph[i][j]);       }       j++;     }   }   int main() {     int n;     scanf( %d , &n);     int x, y;     for (int i = 0; i < n; i++) {       scanf( %d%d , &x, &y);       arr[i].x = x;       arr[i].y = y;     }     int hash[102] = {0};     int ct = 0;     for (int i = 0; i < n; i++) {       int flag = 0;       for (int j = 0; j < n; j++) {         if (i == j) continue;         if (arr[j].x == arr[i].x || arr[j].y == arr[i].y) {           graph[i].push_back(j);           graph[j].push_back(i);           flag = 1;         }       }       if (flag == 0) visited[i] = 1;     }     for (int i = 0; i < n; i++) {       if (visited[i] == 0) {         dfs(i);         ct++;       }     }     int c = 0;     for (int i = 0; i < n; i++) {       if (!graph[i].size()) c++;     }     printf( %d n , c - 1 + ct);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXT = (1 << 18) + 5;   int icT[MAXT], dcT[MAXT];   const int MAXN = 100010;   int a[MAXN], idxofa[MAXN], b[MAXN];   int n;   priority_queue<pair<int, int> > dc, ic;   int main() {     scanf( %d , &n);     for (int i = 1; i <= (int)(n); i++) {       scanf( %d , &a[i]);       idxofa[a[i]] = i;     }     for (int i = 0; i < (int)(MAXT); i++) icT[i] = dcT[i] = 1000000000;     int NN = (1 << 17) - 1;     for (int i = 1; i <= (int)(n); i++) {       scanf( %d , &b[i]);       if (i > idxofa[b[i]]) {         dc.push(make_pair(-(i - idxofa[b[i]]), b[i]));         dcT[NN + b[i]] = abs(i - idxofa[b[i]]);         for (int node = (NN + b[i]) / 2; node; node >>= 1)           dcT[node] = min(dcT[2 * node], dcT[2 * node + 1]);       } else {         ic.push(make_pair(-(i - 1), b[i]));         icT[NN + b[i]] = abs(i - idxofa[b[i]]);         for (int node = (NN + b[i]) / 2; node; node >>= 1)           icT[node] = min(icT[2 * node], icT[2 * node + 1]);       }     }     for (int t = 0; t < n; t++) {       int dcres = dcT[1] - t;       int icres = icT[1] + t;       printf( %d n , min(dcres, icres));       while (dc.size() > 0 && -dc.top().first == t) {         pair<int, int> qt = dc.top();         dc.pop();         ic.push(make_pair(-t - (idxofa[qt.second] - 1), qt.second));         dcT[NN + qt.second] = 1000000000;         icT[NN + qt.second] = -t;         for (int node = (NN + qt.second) / 2; node; node >>= 1)           icT[node] = min(icT[2 * node], icT[2 * node + 1]);         for (int node = (NN + qt.second) / 2; node; node >>= 1)           dcT[node] = min(dcT[2 * node], dcT[2 * node + 1]);       }       while (ic.size() > 0 && -ic.top().first == t) {         pair<int, int> qt = ic.top();         ic.pop();         dc.push(make_pair(-t - (n - idxofa[qt.second]) - 1, qt.second));         icT[NN + qt.second] = 1000000000;         dcT[NN + qt.second] = t + 1 + n - idxofa[qt.second];         for (int node = (NN + qt.second) / 2; node; node >>= 1)           icT[node] = min(icT[2 * node], icT[2 * node + 1]);         for (int node = (NN + qt.second) / 2; node; node >>= 1)           dcT[node] = min(dcT[2 * node], dcT[2 * node + 1]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   const long long inf = 0x3f3f3f3f3f3f3f3f;   int n, k, b, c;   int a[N], A[N], cost[N];   long long ans = inf;   void solve(int x) {     for (int i = 1; i <= n; ++i) {       A[i] = a[i];       cost[i] = 0;       while (A[i] % 5 != x) ++A[i], cost[i] += c;     }     priority_queue<long long> heap;     long long res = 0;     for (int i = 1; i <= k; ++i) {       long long val = 5 * cost[i] - 1LL * b * A[i];       res += val;       heap.push(val);     }     ans = min(ans, (res + 1LL * k * b * A[k]) / 5);     for (int i = k + 1; i <= n; ++i) {       long long val = 5 * cost[i] - 1LL * b * A[i];       if (val < heap.top()) {         res -= heap.top();         heap.pop();         heap.push(val);         res += val;       }       ans = min(ans, (res + 1LL * k * b * A[i]) / 5);     }   }   int main() {     cin >> n >> k >> b >> c;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       a[i] += 1e9;     }     sort(a + 1, a + n + 1);     b = min(b, c * 5);     for (int i = 0; i < 5; ++i) solve(i);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   const int N = 1e5 + 5;   const int OO = 1e9 + 7;   using namespace std;   long long n, m, dishes[N], cost[N];   priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,                  greater<pair<long long, long long>>>       q;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> dishes[i];     for (int i = 0; i < n; i++) cin >> cost[i], q.push({cost[i], i});     for (int i = 0; i < m; i++) {       long long kind, numofdishes, COST = 0;       cin >> kind >> numofdishes;       kind--;       if (numofdishes <= dishes[kind]) {         COST += (numofdishes * cost[kind]);         dishes[kind] -= numofdishes;         cout << COST <<   n ;       } else {         COST += (dishes[kind] * cost[kind]);         numofdishes -= dishes[kind];         dishes[kind] = 0;         while (!q.empty() && numofdishes > 0) {           if (dishes[q.top().second] <= 0) {             q.pop();             continue;           }           if (numofdishes <= dishes[q.top().second]) {             COST += (numofdishes * q.top().first);             dishes[q.top().second] -= numofdishes;             numofdishes = 0;           } else {             COST += (dishes[q.top().second] * q.top().first);             numofdishes -= dishes[q.top().second];             dishes[q.top().second] = 0;           }           if (dishes[q.top().second] <= 0) {             q.pop();             continue;           }         }         if (numofdishes > 0)           cout << 0 <<   n ;         else           cout << COST <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   void myswap(int& a, int& b) {     int temp;     temp = a;     a = b;     b = temp;   }   void fun(vector<int>& vec, int k, int l, int r) {     if (k <= 1 || l >= r - 1) {       return;     }     int mid = (l + r) / 2;     if (k == 3) {       myswap(vec[mid - 1], vec[mid]);       return;     }     k--;     int p = k / 2;     if (p % 2 == 1) {       fun(vec, p, l, mid);       fun(vec, p, mid, r);     } else if (mid - l >= r - mid) {       fun(vec, p + 1, l, mid);       fun(vec, p - 1, mid, r);     } else {       fun(vec, p - 1, l, mid);       fun(vec, p + 1, mid, r);     }   }   int _count(int l, int r) {     if (l >= r) {       return 0;     }     if (l == r - 1) {       return 1;     }     int mid = (l + r) / 2;     return 1 + _count(l, mid) + _count(mid, r);   }   int main() {     int n, k, i, j;     cin >> n >> k;     if (k % 2 == 0) {       cout << -1;     } else if (k == 1) {       for (i = 1; i <= n; i++) {         cout << i <<    ;       }     } else {       int mm = _count(0, n);       if (k > mm) {         cout << -1;       } else {         vector<int> vec;         for (i = 1; i <= n; i++) {           vec.push_back(i);         }         fun(vec, k, 0, n);         for (i = 0; i < n; i++) {           cout << vec[i] <<    ;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       string s;       cin >> s;       int freq[26] = {0};       vector<int> v;       for (int i = 0; i < s.length(); ++i) {         freq[s[i] -  a ]++;       }       for (int i = 0; i < 26; ++i) {         v.push_back(freq[i]);       }       sort(v.begin(), v.end());       int maxAns = 1;       for (int i = 1; i <= k; ++i) {         if (k % i == 0) {           for (int j = i; j <= n; j += i) {             int ans = 0;             int div = j / i;             for (int k = 0; k < v.size(); ++k) {               ans += v[k] / div;             }             if (ans >= i) {               maxAns = max(maxAns, j);             }           }         }       }       cout << maxAns << endl;     }   }


#include <bits/stdc++.h>   int t;   long long n, k, d1, d2, td1, td2, x1, x2, x3;   bool solve() {     if (n % 3) return false;     for (int i = -1; i <= 1; ++i)       for (int j = -1; j <= 1; ++j) {         if (i == 0 || j == 0) continue;         d1 = i * td1;         d2 = j * td2;         if ((d1 * 2 + d2 + k) % 3 || (d2 - d1 + k) % 3 || (k - d1 - 2 * d2) % 3)           continue;         x1 = d1 * 2 + d2 + k;         x2 = d2 - d1 + k;         x3 = k - d1 - 2 * d2;         if (x1 <= n && x2 <= n && x3 <= n && x1 >= 0 && x2 >= 0 && x3 >= 0)           return true;       }     return false;   }   int main() {     scanf( %d , &t);     while (t--) {       scanf( %lld%lld%lld%lld , &n, &k, &td1, &td2);       puts(solve() ?  yes  :  no );     }     return 0;   }


#include <bits/stdc++.h>   int n;   char str[50];   int F[50], sz[50];   inline int find(int x) { return x == F[x] ? x : F[x] = find(F[x]); }   inline void merge(int x, int y) {     x = find(x);     y = find(y);     if (x == y) return;     F[y] = x;     sz[x] += sz[y];   }   std::vector<int> G[55];   int id[66];   int e[25];   int f[(1 << 23) + 5], g[(1 << 23) + 5], coe[(1 << 23) + 5];   int main() {     scanf( %d , &n);     for (int i = 0; i <= n - 1; ++i) F[i] = i, sz[i] = 1;     for (int i = 0; i <= n - 1; ++i) {       scanf( %s , str);       for (int j = i + 1; j <= n - 1; ++j) {         if (str[j] ==  A ) merge(i, j);         if (str[j] ==  X ) G[i].emplace_back(j), G[j].emplace_back(i);       }     }     int ans = n - 1;     n = 0;     for (int i = 0; i <= ans; ++i) id[i] = find(i);     for (int i = 0; i <= ans; ++i)       for (auto x : G[i])         if (id[i] == id[x]) {           puts( -1 );           exit(0);         }     for (int i = 0; i <= ans; ++i) {       if (sz[id[i]] == 1) {         id[i] = -1;         continue;       }       if (id[i] != i) {         id[i] = id[id[i]];         continue;       }       id[i] = n++;     }     if (n <= 1) {       printf( %d n , ans + n);       return 0;     }     assert(n <= 23);     for (int i = 0; i <= ans; ++i)       for (auto x : G[i])         if (~id[i] && ~id[x]) e[id[i]] |= (1 << id[x]);     f[0] = coe[0] = 1;     for (int S = 1; S <= (1 << n) - 1; ++S) {       int lb = __builtin_ctz(S);       f[S] = (!(e[lb] & S)) & f[S ^ (1 << lb)];       coe[S] = -coe[S ^ (1 << lb)];     }     for (int i = 0; i <= n - 1; ++i) {       for (int S = 0; S <= (1 << n) - 1; ++S) {         if ((S >> i) & 1) f[S] += f[S ^ (1 << i)];       }     }     for (int i = 0; i <= (1 << n) - 1; ++i) g[i] = f[i];     for (int k = 1; k <= n; ++k) {       auto chk = [&]() {         int ans = 0;         for (int S = 0; S <= (1 << n) - 1; ++S) ans += g[S] * coe[S];         return ans != 0;       };       if (chk()) {         printf( %d n , ans + k);         return 0;       }       for (int S = 0; S <= (1 << n) - 1; ++S) g[S] *= f[S];     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     while (scanf( %d , &n) != EOF) {       if (n % 2 == 1) {         printf( -1 n );         continue;       }       printf( 2 1 );       for (int i = 3; i < n; i = i + 2) printf(  %d %d , i + 1, i);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> Map;   pair<int, int> a[250001];   vector<int> b[250001], t[250001];   char type;   long long ans;   int len[250001], n, m, i, q, l, r, d, mid, nom, nomN, zn, sum;   bool pole[250001];   int get(int tl, int tr, int nom, int l, int r, int nomT) {     if (tl > tr) return 0;     if (tl > r || tr < l) return 0;     if (l <= tl && tr <= r) return t[nomT][nom];     int mid = (tl + tr) / 2;     return get(tl, mid, nom * 2, l, r, nomT) +            get(mid + 1, tr, nom * 2 + 1, l, r, nomT);   }   void update(int tl, int tr, int nom, int nomN, int zn, int nomT) {     if (tl > tr) return;     if (tl > nomN || tr < nomN) return;     t[nomT][nom] += zn;     if (tl == tr) return;     int mid = (tl + tr) / 2;     update(tl, mid, nom * 2, nomN, zn, nomT);     update(mid + 1, tr, nom * 2 + 1, nomN, zn, nomT);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> q;     for (i = 0; i < n; i++)       if (!pole[i]) {         nom = i;         d++;         t[d].push_back(0);         b[d].push_back(0);         while (!pole[nom]) {           pole[nom] = true;           len[d]++;           a[nom + 1] = make_pair(d, len[d]);           b[d].push_back(nom);           t[d].push_back(0);           t[d].push_back(0);           t[d].push_back(0);           t[d].push_back(0);           nom = (nom + m) % n;         }       }     while (q--) {       cin >> type;       if (type ==  + ) {         cin >> zn >> nom;         nom++;         sum = 0;         if (get(1, len[a[nom].first], 1, a[nom].second, len[a[nom].first],                 a[nom].first) != len[a[nom].first] - a[nom].second + 1) {           l = a[nom].second;           r = len[a[nom].first];           while (l <= r) {             mid = (l + r) / 2;             if (get(1, len[a[nom].first], 1, a[nom].second, mid, a[nom].first) !=                 mid - a[nom].second + 1) {               r = mid - 1;               sum = mid - a[nom].second;             } else               l = mid + 1;           }           update(1, len[a[nom].first], 1, a[nom].second + sum, 1, a[nom].first);           Map[zn] = b[a[nom].first][a[nom].second + sum] + 1;         } else {           ans += len[a[nom].first] - a[nom].second + 1;           l = 1;           r = a[nom].second - 1;           while (l <= r) {             mid = (l + r) / 2;             if (get(1, len[a[nom].first], 1, 1, mid, a[nom].first) != mid) {               r = mid - 1;               sum = mid - 1;             } else               l = mid + 1;           }           update(1, len[a[nom].first], 1, sum + 1, 1, a[nom].first);           Map[zn] = b[a[nom].first][sum + 1] + 1;         }         ans += sum;       } else {         cin >> zn;         nom = Map[zn];         update(1, len[a[nom].first], 1, a[nom].second, -1, a[nom].first);       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int nax = 1e5 + 5;   void solve() {     long long int n;     cin >> n;     vector<long long int> a(n);     for (auto &x : a) cin >> x;     long long int sum = 0, mx = 0;     for (long long int i = 0; i < n - 1; i++) {       sum += max((long long int)0, a[i] - a[i + 1]);     }     cout << sum <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t = 1;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int n = 0, f = 1, ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       n = n * 10 + ch -  0 ;       ch = getchar();     }     return n * f;   }   char a[2000005], b[2000005];   int n;   int c[2000005];   int get(int x) {     int cur = 0, res = 0;     for (int i = 1; i <= n; i++) {       cur += x * c[i];       res = max(res, cur);       if (cur < 0) cur = 0;     }     return res;   }   int main() {     int s1 = 0, s2 = 0;     n = read();     scanf( %s%s , a + 1, b + 1);     for (int i = 1; i <= n; i++) {       if (a[i] != b[i] && a[i] ==  0 )         c[i] = -1, s1++;       else if (a[i] != b[i] && a[i] ==  1 )         c[i] = 1, s2++;     }     if (s1 != s2) {       printf( -1 n );       return 0;     }     printf( %d n , max(get(1), get(-1)));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long double sq(long double a) { return a * a; }   long double dist(pair<long double, long double> a,                    pair<long double, long double> b) {     return sqrt((long double)(sq(a.second - b.second) + sq(a.first - b.first)));   }   long double mandist(pair<long long, long long> a,                       pair<long long, long long> b) {     return abs(a.second - b.second) + abs(a.first - b.first);   }   long long a, b, c;   pair<long long, long long> p1, p2;   int main() {     scanf(  %lld%lld%lld , &a, &b, &c);     scanf(  %lld%lld%lld%lld , &p1.first, &p1.second, &p2.first, &p2.second);     if (a == 0 || b == 0)       printf( %.20Lf n , mandist(p1, p2));     else {       long double res = mandist(p1, p2);       long double interhoriz1 =           ((long double)(-c - a * p1.first)) / ((long double)b);       long double interhoriz2 =           ((long double)(-c - a * p2.first)) / ((long double)b);       long double intervert1 =           ((long double)(-c - b * p1.second)) / ((long double)a);       long double intervert2 =           ((long double)(-c - b * p2.second)) / ((long double)a);       res = min(res, abs((long double)p1.second - interhoriz1) +                          abs((long double)p2.second - interhoriz2) +                          dist(make_pair((long double)p1.first, interhoriz1),                               make_pair((long double)p2.first, interhoriz2)));       res = min(res, abs((long double)p1.second - interhoriz1) +                          abs((long double)p2.first - intervert2) +                          dist(make_pair((long double)p1.first, interhoriz1),                               make_pair(intervert2, (long double)p2.second)));       res = min(res, abs((long double)p1.first - intervert1) +                          abs((long double)p2.first - intervert2) +                          dist(make_pair(intervert1, (long double)p1.second),                               make_pair(intervert2, (long double)p2.second)));       res = min(res, abs((long double)p1.first - intervert1) +                          abs((long double)p2.second - interhoriz2) +                          dist(make_pair(intervert1, (long double)p1.second),                               make_pair((long double)p2.first, interhoriz2)));       printf( %.20Lf n , res);     }   }


#include <bits/stdc++.h>   using namespace std;   void solve();   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout << fixed;     cout.precision(12);     solve();     return 0;   }   template <typename T>   void prv(vector<T> v) {     for (int __ii = 0; __ii < ((int)v.size()); __ii++) {       if (__ii) cout <<    ;       cout << v[__ii];     }     cout <<   n ;   }   template <typename T>   void prm(vector<vector<T>> v) {     for (int __ii = 0; __ii < ((int)v.size()); __ii++) {       for (int __jj = 0; __jj < v[__ii].size(); __jj++) {         if (__jj) cout <<    ;         cout << v[__ii][__jj];       }       cout <<   n ;     }   }   template <typename T>   void sc(T& x) {     cin >> x;   }   template <typename Head, typename... Tail>   void sc(Head& head, Tail&... tail) {     cin >> head;     sc(tail...);   }   template <typename T>   void pr(const T& x) {     cout << x <<   n ;   }   template <typename Head, typename... Tail>   void pr(const Head& head, const Tail&... tail) {     cout << head <<    ;     pr(tail...);   }   template <typename... T>   void err(const T&... cod) {     pr(cod...);     exit(0);   }   void solve() {     int n, m, y, x;     sc(n, m, y, x);     string s;     sc(s);     int dx = (s[1] ==  L  ? -1 : 1);     int dy = (s[0] ==  U  ? -1 : 1);     const int MAX_ITER = 1e6 + 10;     set<pair<int, int>> st;     long long ans = 1;     for (int i = 0; i < MAX_ITER; i++) {       st.emplace(y, x);       if (((int)st.size()) == n + m - 2) err(ans);       int u = (dy == -1 ? y - 1 : n - y);       int v = (dx == -1 ? x - 1 : m - x);       int w = min(u, v);       x += dx * w;       y += dy * w;       ans += w;       if (v == w) dx *= -1;       if (u == w) dy *= -1;     }     pr(-1);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     string s;     cin >> s;     string v =  aeiou ;     string c =  bcdfghjklmnpqrstvwxyz ;     map<char, int> cnt;     map<char, int> mp;     for (auto i : v) mp[i] = 1;     for (auto i : c) mp[i] = 0;     string temp =   ;     int vc = 0;     int cc = 0;     int dc = 0;     vector<string> ans;     for (int i = 0; i < s.size(); i++) {       if (mp[s[i]] == 1) {         cc = 0;         dc = 0;         for (auto j : c) cnt[j] = 0;       } else {         if (cnt[s[i]] == 0) {           cnt[s[i]]++;           dc++;           cc++;         } else {           cnt[s[i]]++;           cc++;         }       }       if (cc > 2 && dc > 1) {         ans.push_back(temp);         for (auto j : c) cnt[j] = 0;         cnt[s[i]] = 1;         cc = 1;         dc = 1;         temp = s[i];       } else         temp += s[i];     }     ans.push_back(temp);     for (auto i : ans) cout << i <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 5;   string s[10005];   int vis[10005];   int main() {     ios::sync_with_stdio(0);     int n, sum(0);     cin >> n;     for (long long i = 0; i < n; ++i) cin >> s[i], sum += s[i].size();     char c;     cin >> c;     for (long long i = 0; i < n; ++i) s[i] += c;     sort(s, s + n);     sum = sum * 2 / n + 1;     for (long long i = 0; i < n; ++i)       if (!vis[i]) {         cout << s[i];         vis[i]++;         for (long long j = i + 1; j < n; ++j)           if (!vis[j] && sum - s[i].size() == s[j].size() - 1) {             cout << s[j].substr(0, s[j].size() - 1) <<   n ;             vis[j]++;             break;           }       }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) cin >> a[i];     map<int, int> used;     int ans = 0;     for (int i = n - 1; i >= 0; --i) {       if (used[a[i]] == 0) {         used[a[i]] = i;         ans = a[i];       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double E = 1e-7;   const int MOD = 1e9 + 7;   const long long MAX = 1e6 + 1;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n, k;     cin >> n >> k;     int ar[n];     for (int i = 0; i < n; i++) cin >> ar[i];     int ans = INT_MIN;     int a[n], b[n];     for (int i = 0; i < n; i++)       for (int j = i; j < n; j++) {         int A = j - i + 1;         int B = n - A;         copy(ar + i, ar + j + 1, a);         copy(ar, ar + i, b);         copy(ar + j + 1, ar + n, b + i);         sort(a, a + A);         sort(b, b + B);         for (int l = 0, r = B - 1, q = k; l < A && r >= 0 && a[l] < b[r] && q;              l++, r--, --q)           swap(a[l], b[r]);         int sum = 0;         for (int i = 0; i < A; i++) sum += a[i];         ans = max(ans, sum);       }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int x, int y) {     if (x > y)       return gcd(x - y, y);     else if (x == y)       return x;     else       return gcd(x, y - x);   }   int main() {     int n, m, z;     cin >> n >> m >> z;     cout << (gcd(n, m) * z) / (n * m) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, cnt, flag = 0;     cin >> n;     int a, b, c = 0;     for (int i = 1; i <= n; i++) {       cin >> a >> b;       if (b - a >= 2) ++c;     }     cout << c << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, p = 0, ans = 0;     string s, dvg, answ, r_dvg;     cin >> n >> s;     for (int i = 0; i < n - 1; i++) {       dvg = s.substr(i, 2);       for (int j = i; j < n - 1; j++) {         r_dvg = s.substr(j, 2);         if (dvg == r_dvg) {           p++;         }       }       if (p > ans) {         ans = p;         answ = dvg;       }       p = 0;     }     cout << answ << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Point {     long long x, y;     void read() { scanf( %lld%lld , &x, &y); }   };   long long product(const Point &o, const Point &a, const Point &b) {     return (a.x - o.x) * (b.y - o.y) - (b.x - o.x) * (a.y - o.y);   }   bool intersect(const Point &a, const Point &b, const Point &c, const Point &d) {     bool insect1 = product(a, c, d) * product(b, c, d) < 0;     bool insect2 = product(c, a, b) * product(d, a, b) < 0;     return insect1 && insect2;   }   int main() {     ios ::sync_with_stdio(false);     cout << fixed << setprecision(16);     int R, B;     scanf( %d%d , &R, &B);     vector<Point> bases(B);     vector<Point> ships(R);     vector<int> b(R);     for (int i = 0; i < R; i++) {       ships[i].read();     }     for (int i = 0; i < B; i++) {       bases[i].read();     }     if (B != R) {       puts( No );       return 0;     }     for (int i = 0; i < R; i++) {       b[i] = i;     }     bool yes = false;     do {       bool ok = true;       for (int i = 0; i < B; i++) {         for (int j = i + 1; j < B; j++) {           if (intersect(ships[b[i]], bases[i], ships[b[j]], bases[j])) {             ok = false;           }         }       }       if (ok) {         yes = true;         break;       }     } while (next_permutation(b.begin(), b.end()));     puts(yes ?  Yes  :  No );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 305000;   long long mod = 1e9 + 7;   long long h, w, n;   long long dp[maxn], f[maxn], inv[maxn];   struct stu {     long long x, y;   } a[maxn];   long long cmp(stu a, stu b) {     if (a.x != b.x)       return a.x < b.x;     else       return a.y < b.y;   }   long long ksm(long long base, long long b, long long mod) {     long long ans = 1;     while (b) {       if (b & 1) {         ans *= base;         ans %= mod;       }       base *= base;       base %= mod;       b >>= 1;     }     return ans;   }   void init() {     f[0] = 1, inv[0] = 1;     for (long long i = 1; i <= 200000; i++) {       f[i] = f[i - 1] * i % mod;       inv[i] = ksm(f[i], mod - 2, mod);     }   }   long long c(long long x, long long y) {     if (x < y)       return 0;     else       return f[x] * inv[y] % mod * inv[x - y] % mod;   }   signed main() {     cin >> h >> w >> n;     init();     for (long long i = 1; i <= n; i++) cin >> a[i].x >> a[i].y;     sort(a + 1, a + n + 1, cmp);     a[n + 1].x = h, a[n + 1].y = w;     for (long long i = 1; i <= n + 1; i++) {       dp[i] = c(a[i].x + a[i].y - 2, a[i].x - 1);       for (long long j = 1; j < i; j++) {         if (a[j].x > a[i].x || a[j].y > a[i].y) continue;         dp[i] = (dp[i] -                  dp[j] * c(a[i].x + a[i].y - a[j].x - a[j].y, a[i].x - a[j].x)) %                 mod;       }     }     cout << (dp[n + 1] + mod) % mod << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int v[3005], inv = 0, n;   double sol;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> v[i];     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++)         if (v[i] > v[j]) inv++;     sol = double(inv) - inv / 2 + (inv / 2) * 3.0;     cout << fixed;     cout << setprecision(6);     cout << sol <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000 * 1000 * 1000;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     pair<int, int> minp1(INF, INF), minp2(INF, INF);     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       minp1 = min(minp1, pair<int, int>(x, y));     }     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       x *= -1;       y *= -1;       minp2 = min(minp2, pair<int, int>(x, y));     }     cout << minp1.first - minp2.first <<     << minp1.second - minp2.second;   }


#include <bits/stdc++.h>   const int MAXN = 100100;   struct Gao {     int p[MAXN], q[MAXN];     bool r[MAXN];     void init(int n) {       for (int i = 0; i < n; ++i) {         q[i] = 1;         r[i] = true;       }     }     void next(int i) {       if (!r[p[i]] && p[i] != i) {         next(p[i]);         q[i] += q[p[i]];         p[i] = p[p[i]];       }     }     void kill(int i) {       if (r[i]) {         next(i);         r[i] = false;       }     }   } gao;   int main() {     int n, m, x, y, z;     static int a[MAXN], b[MAXN];     scanf( %d%d , &n, &m);     gao.init(n);     for (int i = 0; i < n; ++i) {       scanf( %d , &gao.p[i]);       --gao.p[i];     }     for (int i = 0; i < m; ++i) {       scanf( %d , &a[i]);       --a[i];     }     for (int i = 0; i < m; ++i) {       scanf( %d , &b[i]);     }     z = 0;     for (int i = 0; i < m; ++i) {       x = (a[i] + z) % n;       y = b[i];       z = 0;       while (true) {         if (!gao.r[x]) {           gao.next(x);           y -= gao.q[x];           x = gao.p[x];         }         if (gao.r[x] && y > 0) {           ++z;           gao.kill(x);         } else {           break;         }       }       printf( %d n , z);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 4e4 + 5;   int pr[N], ps = 0;   bool np[N];   bool check(int n) {     if (n == 1 || n == 0) return false;     for (int i = 0; pr[i] * pr[i] <= n; ++i)       if (n % pr[i] == 0) return false;     return true;   }   int main() {     for (int i = 2; i < N; ++i)       if (!np[i]) {         pr[ps++] = i;         for (int j = i + i; j < N; j += i) np[j] = 1;       }     int n;     cin >> n;     if (check(n)) {       cout <<  1 n  << n << endl;       return 0;     }     for (int i = 0; i < ps && pr[i] <= n; ++i) {       if (check(n - pr[i])) {         cout <<  2 n  << pr[i] <<     << n - pr[i] << endl;         return 0;       }       if (pr[i] % 2 == 1 && check((n - pr[i]) / 2)) {         cout <<  3 n               << pr[i] <<     << (n - pr[i]) / 2 <<     << (n - pr[i]) / 2 << endl;         return 0;       }     }     cout <<  lol nope n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mk = 100005;   long long n;   vector<long long> g[mk];   long long find(long long A) {     if (A == 0) return 0;     long long tmp = A & 3;     long long R = (find(A / 4) << 2);     if (tmp == 0) return R;     if (tmp == 1) return (R | 2);     if (tmp == 2) return (R | 3);     if (tmp == 3) return (R | 1);   }   void init() {     long long test;     cin >> test;     for (long long i = 1; i <= test; i++) {       long long n;       cin >> n;       long long root = 1;       while (root * 4 <= n) root *= 4;       n -= (root - 1);       long long A = (root | ((n - 1) / 3));       long long B = find(A);       long long C = A ^ B;       if (n % 3 == 1) cout << A;       if (n % 3 == 2) cout << B;       if (n % 3 == 0) cout << C;       cout <<   n ;     }   }   signed main() { init(); }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e4 + 5;   pair<int, int> p[maxn];   set<pair<int, int> > s;   void solve(int l, int r) {     if (r - l < 2) return;     int mid = (l + r) / 2;     solve(l, mid), solve(mid, r);     for (int i = l; i < r; i++) s.insert(make_pair(p[mid].first, p[i].second));   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++)       cin >> p[i].first >> p[i].second,           s.insert(make_pair(p[i].first, p[i].second));     sort(p, p + n);     solve(0, n);     cout << s.size() << endl;     for (pair<int, int> now : s) cout << now.first <<     << now.second << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     long long int s;     scanf( %d , &n);     s = 6 * n * (n - 1) + 1;     printf( %I64d , s);     return 0;   }


#include <bits/stdc++.h>   template <class C, class E>   inline bool contains(const C& container, const E& element) {     return container.find(element) != container.end();   }   template <class T>   inline void checkmin(T& a, T b) {     if (b < a) a = b;   }   template <class T>   inline void checkmax(T& a, T b) {     if (b > a) a = b;   }   using namespace std;   class UnionFind {    public:     UnionFind(int elements) : _subsets(elements), _setCount(elements) {       for (int i = 0; i < elements; ++i) {         _subsets[i].parent = i;         _subsets[i].rank = 0;       }     }     int Find(int i) {       if (_subsets[i].parent != i) _subsets[i].parent = Find(_subsets[i].parent);       return _subsets[i].parent;     }     void Union(int x, int y) {       int xroot = Find(x);       int yroot = Find(y);       if (xroot == yroot) return;       --_setCount;       if (_subsets[xroot].rank < _subsets[yroot].rank)         _subsets[xroot].parent = yroot;       else if (_subsets[xroot].rank > _subsets[yroot].rank)         _subsets[yroot].parent = xroot;       else {         _subsets[yroot].parent = xroot;         _subsets[xroot].rank++;       }     }     struct subset {       int parent;       int rank;     };     void Trace() {       for (int i = (0), _b = ((_subsets.size()) - 1); i <= _b; i++)         cout << i <<  :  << Find(i) <<   | ;       cout << endl;     }     vector<subset> _subsets;     int _setCount;   };   struct SetInfo {     set<int> _yc;     set<int> _xc;   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout << std::setprecision(15);     cout << std::fixed;     long long xs, ys, q;     cin >> xs >> ys >> q;     UnionFind uf(xs + ys);     vector<pair<int, int> > p(q);     for (int i = (0), _b = ((q)-1); i <= _b; i++) {       int x, y;       cin >> p[i].first >> p[i].second;       --p[i].first;       --p[i].second;       uf.Union(p[i].first, xs + p[i].second);     }     map<int, SetInfo> ss;     for (int i = (0), _b = ((q)-1); i <= _b; i++) {       int id = uf.Find(p[i].first);       SetInfo& setInfo = ss[id];       setInfo._xc.insert(p[i].first);       setInfo._yc.insert(p[i].second);     }     long long got = 0;     long long totX = 0, totY = 0;     for (auto& p : ss) {       totX += (long long)p.second._xc.size();       totY += (long long)p.second._yc.size();     }     long long remX = xs - totX;     long long remY = ys - totY;     long long res = remX + remY - 1 + ss.size();     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T sqr(T x) {     return x * x;   }   template <typename T>   T abs(T x) {     return x < 0 ? -x : x;   }   template <typename T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <typename T>   bool chmin(T& x, const T& y) {     if (x > y) {       x = y;       return true;     }     return false;   }   template <typename T>   bool chmax(T& x, const T& y) {     if (x < y) {       x = y;       return true;     }     return false;   }   string to_bin(int x) {     string ret;     while (x) {       ret = ret + (char)((x % 2) +  0 );       x /= 2;     }     return ret;   }   int main(int, char**) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long m = (n - 1) / 3;       int k = 0;       long long p = 1;       while (m >= p) {         m -= p;         k += 1;         p *= 4;       }       vector<long long> a;       for (int i = 0; i < k; ++i) {         a.push_back(m % 4);         m /= 4;       }       long long A, B;       A = 1LL << (2 * k);       B = 1LL << (2 * k + 1);       vector<long long> b = {0, 2, 3, 1};       for (int i = 0; i < k; ++i) {         A ^= a[i] << (2 * i);         B ^= b[a[i]] << (2 * i);       }       long long C = A ^ B;       long long ans;       if (n % 3 == 1) {         ans = A;       } else if (n % 3 == 2) {         ans = B;       } else {         ans = C;       }       cout << ans <<   n ;     }     cerr <<  Time execute:   << clock() / (double)CLOCKS_PER_SEC <<   sec           << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double n, m, a, b;     cin >> n >> m >> a >> b;     double s = n / m;     long long int s1 = floor(s) * m;     long long int s2 = ceil(s) * m;     long long int a1 = (n - s1) * b;     long long int a2 = (s2 - n) * a;     cout << (min(a1, a2));   }


#include <bits/stdc++.h>   using namespace std;   int res;   int tox[] = {0, 0, 1, -1};   int toy[] = {1, -1, 0, 0};   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr), cout.tie(nullptr);     string s;     cin >> s;     while (s.back() ==  0 ) s.erase(s.size() - 1, 1), res++;     while (s !=  1 ) {       while (s.size() && s.back() ==  1 ) s.erase(s.size() - 1, 1), res++;       res++;       if (!s.size()) break;       s.back() =  1 ;     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     deque<long long int> b, g;     long long int n;     cin >> n;     for (long long int i = 0; i < n; i++) {       long long int temp;       cin >> temp;       b.push_back(temp);     }     cin >> n;     for (long long int i = 0; i < n; i++) {       long long int temp;       cin >> temp;       g.push_back(temp);     }     sort(b.begin(), b.end());     sort(g.begin(), g.end());     long long int ans = 0;     while (b.size() && g.size()) {       if (abs(b.front() - g.front()) <= 1) {         ans++;         b.pop_front();         g.pop_front();       } else {         if (b.front() < g.front())           b.pop_front();         else           g.pop_front();       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   bool comp(pair<long long, long long> p1, pair<long long, long long> p2) {     if (p1.first != p2.first) {       return p1.first < p2.first;     } else       return p2.second < p1.second;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     map<long long, vector<pair<long long, long long>>> m;     for (long long i = 0; i < n; i++) {       long long x, y;       cin >> x >> y;       long long level = max(x, y);       m[level].push_back({x, y});     }     vector<pair<long long, long long>> v;     long long dp[200006][2];     memset(dp, INT_MAX, sizeof dp);     dp[0][0] = 0;     dp[0][1] = 0;     pair<long long, long long> p_start, p_end;     p_start = {0, 0};     p_start = {0, 0};     long long i = 1;     for (auto it : m) {       for (auto it1 : it.second) {         v.push_back(it1);       }       sort(v.begin(), v.end(), comp);       pair<long long, long long> start = v[0];       pair<long long, long long> end = v[v.size() - 1];       long long di =           abs(start.first - end.first) + abs(start.second - end.second);       long long a1 = dp[i - 1][0] + abs(p_start.first - end.first) +                      abs(p_start.second - end.second) + di;       long long a2 = dp[i - 1][1] + abs(p_end.first - end.first) +                      abs(p_end.second - end.second) + di;       dp[i][0] = min(a1, a2);       a1 = dp[i - 1][0] + abs(p_start.first - start.first) +            abs(p_start.second - start.second) + di;       a2 = dp[i - 1][1] + abs(p_end.first - start.first) +            abs(p_end.second - start.second) + di;       dp[i][1] = min(a1, a2);       p_start = start;       p_end = end;       v.clear();       i++;     }     cout << min(dp[i - 1][0], dp[i - 1][1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int INF = 9223372036854775807;   const long long int mod = 998244353;   long long int MOD(long long int a, long long int b) {     if (a > b)       return a - b;     else       return b - a;   }   long long int max3(long long int a, long long int b, long long int c) {     return max(c, max(a, b));   }   long long int min3(long long int a, long long int b, long long int c) {     return min(a, min(b, c));   }   long long int power(long long int x, long long int y) {     long long int res = 1;     while (y > 0) {       if (y & 1) res = (res * x);       y = y >> 1;       x = (x * x);     }     return res;   }   long long int power1(long long int x, long long int y) {     long long int res = 1;     while (y > 0) {       if (y & 1) res = (res * x) % mod;       y = y >> 1;       x = (x * x) % mod;     }     return res % mod;   }   long long int logg(long long int a) {     long long int x = 0;     while (a > 1) {       x++;       a /= 2;     }     return x;   }   long long int gcd(long long int a, long long int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long int abso(long long int x) {     if (x < 0) {       return -x;     }     return x;   }   long long int ceiling(long long int a, long long int b) {     if (a % b == 0) {       return a / b;     } else {       return a / b + 1;     }   }   long long int modinv(long long int x) { return power1(x, mod - 2); }   long long int par[20][400000];   long long int sum[20][400000];   long long int weight[400000];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t;     cin >> t;     long long int cnt = 1;     long long int last = 0;     par[0][1] = 1;     weight[1] = 0;     weight[0] = INF;     for (int i = 0; i < 20; i++) {       for (int j = 0; j < 400000; j++) {         par[i][j] = 0;       }     }     for (int i = 0; i < 20; i++) {       sum[i][1] = INF;     }     for (int i = 0; i < 20; i++) {       for (int j = 2; j < 400000; j++) {         sum[i][j] = 0;       }     }     while (t--) {       int ch;       cin >> ch;       long long int p, q;       cin >> p >> q;       p = p ^ last;       q = q ^ last;       if (ch == 1) {         cnt++;         weight[cnt] = q;         long long int curr = p;         if (weight[p] >= q) {           curr = p;           par[0][cnt] = curr;         } else {           for (int j = 19; j >= 0; j--) {             if (weight[par[j][curr]] < weight[cnt]) {               curr = par[j][curr];             }           }           par[0][cnt] = par[0][curr];         }         if (par[0][cnt] != 0) {           sum[0][cnt] = weight[par[0][cnt]];         } else {           sum[0][cnt] = INF;         }         for (int i = 1; i < 20; i++) {           par[i][cnt] = par[i - 1][par[i - 1][cnt]];         }         for (int i = 1; i < 20; i++) {           if (par[i][cnt] != 0 && sum[i - 1][cnt] != INF) {             sum[i][cnt] = sum[i - 1][cnt] + sum[i - 1][par[i - 1][cnt]];           } else {             sum[i][cnt] = INF;           }         }       } else {         long long int W = weight[p];         if (W > q) {           cout << 0 << endl;           last = 0;         } else {           long long int curr = p;           long long int ans = 1;           for (int j = 19; j >= 0; j--) {             if (sum[j][curr] != INF && sum[j][curr] + W <= q) {               ans += power(2, j);               W += sum[j][curr];               curr = par[j][curr];             }           }           cout << ans << endl;           last = ans;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   const int Q = 1e9 + 7;   struct Point {     int x, y;     Point(int _x = 0, int _y = 0) : x(_x), y(_y) {}     const int sign() const { return y < 0 || y == 0 && x < 0; }     Point operator-(const Point &R) { return Point(x - R.x, y - R.y); }     long long operator^(const Point &R) const {       return (long long)x * R.y - (long long)y * R.x;     }     bool operator<(const Point &R) const {       if (sign() != R.sign()) {         return sign() < R.sign();       }       return (*this ^ R) > 0;     }   };   inline void add(long long &A, long long B) { A += B; }   Point p[N];   int n;   long long f[6][N][N];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d%d , &p[i].x, &p[i].y);       f[0][i][i] = 1;     }     vector<tuple<Point, int, int>> v;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < i; ++j) {         v.emplace_back(p[j] - p[i], i, j);         v.emplace_back(p[i] - p[j], j, i);       }     }     sort(v.begin(), v.end());     for (auto &it : v) {       int x = get<1>(it);       int y = get<2>(it);       for (int i = 5; i > 0; --i) {         for (int j = 0; j < n; ++j) {           add(f[i][j][y], f[i - 1][j][x]);         }       }     }     long long res = 0;     for (int i = 0; i < n; ++i) {       add(res, f[5][i][i]);     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, l, r, sall, sk;     cin >> n >> k >> l >> r >> sall >> sk;     int el[n];     int div, mod, m, sm;     m = n - k;     sm = sall - sk;     if (k > 0) {       div = sk / k;       mod = sk % k;       for (int i = 0; i < k; i++) {         el[i] = div;         if (i < mod) {           el[i] += 1;         }       }     }     if (m > 0) {       div = sm / m;       mod = sm % m;       for (int i = 0; i < m; i++) {         el[i + k] = div;         if (i < mod) {           el[i + k] += 1;         }       }     }     for (int i = 0; i < n; i++) {       cout << el[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long ar[100005];   long long N;   int main() {     cin >> N;     for (long long i = 0; i < N; i++) cin >> ar[i];     long long ans = 0ll;     for (long long i = 0; i < N; i++) {       long long lft = (i == 0 ? 0 : ar[i - 1]);       if (ar[i] < lft) ans += (ar[i]) * (lft - ar[i]);       if (ar[i] > lft) ans += (ar[i] - lft) * (N - ar[i] + 1);     }     cout << ans << endl;     return (0);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, m;     cin >> n >> m;     for (long long int i = 0; i < n; i += 1) {       long long int s, f, t;       cin >> s >> f >> t;       long long int q = t / (m - 1);       long long int r = t % (m - 1);       if (s == f) {         cout << t <<   n ;         continue;       }       if (q % 2 == 0) {         long long int floor = r + 1;         if (s >= floor) {           t += (s - floor);           if (f >= s) {             t += (f - s);           } else {             t += (m - s) + (m - f);           }         } else {           t += (m - floor) + (m - s);           if (f > s) {             t += (s - 1) + (f - 1);           } else {             t += (s - f);           }         }       } else {         long long int floor = m - r;         if (s <= floor) {           t += (floor - s);           if (f <= s) {             t += (s - f);           } else {             t += (s - 1) + (f - 1);           }         } else {           t += (floor - 1) + (s - 1);           if (f >= s) {             t += (f - s);           } else {             t += (m - s) + (m - f);           }         }       }       cout << t <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e5 + 5;   long long add[N << 2], sum[N << 2], color[N << 2];   int n, m;   void down(int rt, int len) {     if (add[rt]) {       add[(rt << 1)] += add[rt];       add[(rt << 1 | 1)] += add[rt];       sum[(rt << 1)] += add[rt] * (len - (len >> 1));       sum[(rt << 1 | 1)] += add[rt] * (len >> 1);       add[rt] = 0;       color[(rt << 1)] = color[(rt << 1 | 1)] = color[rt];       color[rt] = 0;     }   }   void build(int rt, int l, int r) {     if (l == r) {       color[rt] = l;       return;     }     int mid = (l + r) >> 1;     build((rt << 1), l, mid);     build((rt << 1 | 1), mid + 1, r);   }   void modify(int rt, int l, int r, int L, int R, int x) {     if (L <= l && r <= R && color[rt]) {       add[rt] += abs(color[rt] - x);       sum[rt] += (r - l + 1) * abs(color[rt] - x);       color[rt] = x;       return;     }     down(rt, r - l + 1);     int mid = (l + r) >> 1;     if (L <= mid) modify((rt << 1), l, mid, L, R, x);     if (mid < R) modify((rt << 1 | 1), mid + 1, r, L, R, x);     color[rt] = (color[(rt << 1)] == color[(rt << 1 | 1)]) ? color[(rt << 1)] : 0;     sum[rt] = sum[(rt << 1)] + sum[(rt << 1 | 1)];   }   long long query(int rt, int l, int r, int L, int R) {     if (L <= l && r <= R) {       return sum[rt];     }     down(rt, r - l + 1);     long long t = 0ll;     int mid = (l + r) >> 1;     if (L <= mid) t += query((rt << 1), l, mid, L, R);     if (mid < R) t += query((rt << 1 | 1), mid + 1, r, L, R);     return t;   }   int main() {     scanf( %d%d , &n, &m);     build(1, 1, n);     while (m--) {       int op, l, r, x;       scanf( %d , &op);       if (op == 1) {         scanf( %d%d%d , &l, &r, &x);         modify(1, 1, n, l, r, x);       } else {         scanf( %d%d , &l, &r);         printf( %I64d n , query(1, 1, n, l, r));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool f[9000000];   int a[30];   bool check(int sta, int i) {     if (sta & (1 << (i - 1)))       ;     else       return false;     for (int j = 0; j < i; j++)       if (sta & (1 << j))         for (int k = j; k < i; k++)           if (sta & (1 << k))             if (a[j] + a[k] == a[i]) return true;     return false;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     memset(f, false, sizeof(f));     f[1] = true;     for (int i = 1; i < n; i++) {       int l = 1 << i, r = 1 << (i + 1);       for (int j = l; j < r; j++)         if (f[j - l] && check(j, i)) {           f[j] = true;           for (int k = 0; k < i; k++) f[j & (~(1 << k))] = true;         }     }     int ans = 30;     for (int i = (1 << (n - 1)); i < (1 << n); i++)       if (f[i]) {         int total = 0;         for (int j = 0; j < n; j++)           if (i & (1 << j)) total++;         ans = ((ans) < (total) ? (ans) : (total));       }     printf( %d n , ans == 30 ? -1 : ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 500 + 1;   int a[maxn], n;   bool check(int r) {     for (int i = 1; i <= n; i++)       if (a[i] % r > 0 && r - 1 - a[i] % r > a[i] / r) return 0;     return 1;   }   long long calc(int r) {     long long res = 0;     for (int i = 1; i <= n; i++) res += a[i] / r + (a[i] % r != 0);     return res;   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     int res = 1;     for (int i = 1, j, m = a[1]; i <= m; i = j + 1) {       int t = m / i;       j = m / t;       if (check(t + 1)) {         res = t + 1;         break;       }       if (check(t)) {         res = t;         break;       }     }     cout << calc(res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 1005;   int n, m, k;   long long s[Maxn][Maxn], sl[Maxn][Maxn], sr[Maxn][Maxn];   inline int get() {     char ch;     while (!isdigit(ch = getchar()))       ;     int v = ch - 48;     while (isdigit(ch = getchar())) v = v * 10 + ch - 48;     return v;   }   int main() {     n = get();     m = get();     k = get();     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         s[i][j] = get() + s[i][j - 1] + s[i - 1][j] - s[i - 1][j - 1];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         sl[i][j] =             sl[i - 1][j - 1] + s[i][j] - (i > k && j > k ? s[i - k][j - k] : 0);         sr[i][j] = sr[i - 1][j + 1] + s[i][j] -                    (i > k && j + k <= m ? s[i - k][j + k] : 0);       }       sr[i][0] = sr[i - 1][1] + s[i][0] - (i > k ? s[i - k][k] : 0);     }     int wx = 0, wy = 0;     long long maxv = -1;     for (int i = k; i <= n - k + 1; i++)       for (int j = k; j <= m - k + 1; j++) {         long long v = sr[i + k - 1][j] + sr[i - 1][j - k] - sl[i - 1][j + k - 1] -                       sl[i + k - 1][j - 1];         if (maxv < v) maxv = v, wx = i, wy = j;       }     cout << wx <<     << wy << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, sum[3] = {0};     cin >> n;     int *x = new int[n], *y = new int[n], *z = new int[n];     for (int i = 0; i < n; i++) {       cin >> x[i] >> y[i] >> z[i];       sum[0] += x[i];       sum[1] += y[i];       sum[2] += z[i];     }     if (sum[0] == 0 && sum[1] == 0 && sum[2] == 0)       cout <<  YES ;     else       cout <<  NO ;     delete[] x;     delete[] y;     delete[] z;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct man {     long long int m, s, I;   };   man a[131072];   bool cmp(man a, man b) {     if (a.m < b.m) return true;     if (a.m > b.m) return false;     if (a.I > b.I) return true;     if (a.I < b.I) return false;   }   int main() {     queue<man> x;     long long int n, d, i, tbr = 0, maxbr = 0;     cin >> n >> d;     for (i = 0; i < n; i++) {       cin >> a[i].m >> a[i].s;       a[i].I = i;     }     sort(a, a + n, cmp);     for (i = 0; i < n; i++) {       x.push(a[i]);       struct man m = x.front(), m2 = x.back();       while (m2.m - m.m >= d) {         tbr -= m.s;         x.pop();         m = x.front();         m2 = x.back();       }       tbr += m2.s;       if (tbr > maxbr) maxbr = tbr;     }     cout << maxbr << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   const long long INF = 1000000000;   struct wie {     int il_50, il_100, str;   };   int main() {     ios_base::sync_with_stdio(0);     int n, k;     cin >> n >> k;     int p = 0, s = 0;     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       if (x == 50)         ++p;       else         ++s;     }     vector<vector<long long> > C(51, vector<long long>(51));     for (int i = 0; i <= 50; ++i) {       for (int j = 0; j <= i; ++j) {         if (j == 0 || j == i)           C[i][j] = 1;         else           C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;       }     }     long long il[51][51][2];     long long odl[51][51][2];     bool odw[51][51][2];     for (int i = 0; i < 51; ++i) {       for (int j = 0; j < 51; ++j) {         for (int l = 0; l < 2; ++l) {           odw[i][j][l] = false;           odl[i][j][l] = -1;         }       }     }     queue<wie> Q;     Q.push({p, s, 1});     odw[p][s][1] = true;     while (!Q.empty()) {       wie akt = Q.front();       Q.pop();       if (akt.il_100 == s && akt.il_50 == p && akt.str == 1) {         odl[akt.il_50][akt.il_100][akt.str] = 0;         il[akt.il_50][akt.il_100][akt.str] = 1;         for (int i = 0; i <= akt.il_50; ++i) {           for (int j = 0; j <= akt.il_100; ++j) {             wie nowy = {p - akt.il_50 + i, s - akt.il_100 + j, (akt.str ^ 1)};             if (i + j != 0 && 50 * i + 100 * j <= k) {               Q.push(nowy);               odw[nowy.il_50][nowy.il_100][nowy.str] = true;             }           }         }       } else {         odl[akt.il_50][akt.il_100][akt.str] = INF;         il[akt.il_50][akt.il_100][akt.str] = 0;         for (int i = 0; i <= akt.il_50; ++i) {           for (int j = 0; j <= akt.il_100; ++j) {             wie nowy = {p - akt.il_50 + i, s - akt.il_100 + j, (akt.str ^ 1)};             if (i + j != 0 && 50 * i + 100 * j <= k) {               if (odw[nowy.il_50][nowy.il_100][nowy.str]) {                 if (odl[nowy.il_50][nowy.il_100][nowy.str] != -1) {                   odl[akt.il_50][akt.il_100][akt.str] =                       min(odl[akt.il_50][akt.il_100][akt.str],                           odl[nowy.il_50][nowy.il_100][nowy.str] + 1);                   il[akt.il_50][akt.il_100][akt.str] =                       (il[akt.il_50][akt.il_100][akt.str] +                        (C[akt.il_50][i] * C[akt.il_100][j]) % MOD *                            il[nowy.il_50][nowy.il_100][nowy.str]) %                       MOD;                 }               } else {                 Q.push(nowy);                 odw[nowy.il_50][nowy.il_100][nowy.str] = true;               }             }           }         }       }     }     if (odw[p][s][0])       cout << odl[p][s][0] <<     << il[p][s][0];     else       cout <<  -1 0 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1000 + 10, M = 998244353;   int t;   int n, m, q;   bool locked[N][N];   long long num[N][N][2];   long long ans = 0;   int calc(int i, int j, int t) {     if (i > n || j > m) return 0;     if (num[i][j][t] != 0) return num[i][j][t];     num[i][j][t] = 1;     if (t == 0)       num[i][j][t] += calc(i + 1, j, t ^ 1);     else       num[i][j][t] += calc(i, j + 1, t ^ 1);     return num[i][j][t];   }   void go(int i, int j, int t, int val) {     if (i <= 0 || j <= 0 || locked[i][j]) return;     if (t == 0) {       num[i][j][t] -= val;       ans -= val;       return go(i, j - 1, t ^ 1, val);     } else {       num[i][j][t] -= val;       ans -= val;       return go(i - 1, j, t ^ 1, val);     }   }   void go2(int i, int j, int t) {     num[i][j][t] = 1;     ans++;     if (t == 0) {       if (i < n) {         num[i][j][t] += num[i + 1][j][t ^ 1];         ans += num[i + 1][j][t ^ 1];       }     } else {       if (j < m) {         num[i][j][t] += num[i][j + 1][t ^ 1];         ans += num[i][j + 1][t ^ 1];       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m >> q;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         for (int k = 0; k < 2; k++) ans += calc(i, j, k);       }     }     long long free = n * m;     while (q--) {       int x, y;       cin >> x >> y;       if (!locked[x][y]) {         go(x, y, 0, num[x][y][0]);         go(x, y, 1, num[x][y][1]);         locked[x][y] = 1;         free--;       } else {         go2(x, y, 0);         go2(x, y, 1);         locked[x][y] = 0;         go(x, y, 0, -num[x][y][0]);         go(x, y, 1, -num[x][y][1]);         num[x][y][0] /= 2;         num[x][y][1] /= 2;         ans -= num[x][y][0] + num[x][y][1];         free++;       }       cout << ans - free <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int modulo = 1e9 + 7;   int n;   const int limite = 100001;   long long int cuantoshasta[limite], sumahasta[limite], valor[limite],       prodhasta[limite];   long long int cuatros[limite][10], sietes[limite][10], diezala[limite],       dosala[limite], sumahasta7[limite][10], prodhasta7[limite][10];   long long int d[limite];   long long int computa(string &s) {     for (int i = 0; i < n; i++) d[i] = s[n - 1 - i] -  0 ;     valor[0] = d[0];     if (d[0] == 4) {       cuantoshasta[0] = 1;       sumahasta[0] = 4;       prodhasta[0] = 0;     } else {       cuantoshasta[0] = 2;       sumahasta[0] = 11;       prodhasta[0] = 28;     }     for (int i = 1; i < n; i++) {       valor[i] = (valor[i - 1] + diezala[i] * d[i]) % modulo;       if (d[i] == 4) {         cuantoshasta[i] = cuantoshasta[i - 1];         sumahasta[i] =             (4 * diezala[i] % modulo * cuantoshasta[i - 1] + sumahasta[i - 1]) %             modulo;         prodhasta[i] =             (4 * diezala[i] % modulo *                  (2 * sumahasta[i - 1] - cuatros[i - 1][4] - valor[i - 1] +                   4 * diezala[i] % modulo * (cuantoshasta[i - 1] - 1) % modulo) %                  modulo +              prodhasta[i - 1]) %             modulo;       } else {         cuantoshasta[i] = (cuantoshasta[i - 1] + dosala[i]) % modulo;         sumahasta[i] =             (sumahasta7[i][4] + 7 * diezala[i] % modulo * cuantoshasta[i - 1] +              sumahasta[i - 1]) %             modulo;         prodhasta[i] =             (prodhasta7[i][4] + sietes[i][4] * cuatros[i][7] % modulo +              7 * diezala[i] % modulo *                  (2 * sumahasta[i - 1] - cuatros[i - 1][4] - valor[i - 1] +                   7 * diezala[i] % modulo * (cuantoshasta[i - 1] - 1) % modulo) %                  modulo +              prodhasta[i - 1]) %             modulo;       }     }     return prodhasta[n - 1];   }   int main() {     ios::sync_with_stdio(false);     string sl, sr;     cin >> sl >> sr;     n = int(sl.size());     cuatros[0][4] = 4;     cuatros[0][7] = 7;     sietes[0][4] = 4;     sietes[0][7] = 7;     diezala[0] = 1;     dosala[0] = 1;     sumahasta7[0][4] = 4;     sumahasta7[0][7] = 11;     prodhasta7[0][4] = 0;     prodhasta7[0][7] = 28;     for (int i = 1; i < n; i++) {       diezala[i] = (diezala[i - 1] * 10) % modulo;       dosala[i] = (dosala[i - 1] * 2) % modulo;       cuatros[i][4] = (cuatros[i - 1][4] + 4 * diezala[i]) % modulo;       cuatros[i][7] = (cuatros[i - 1][4] + 7 * diezala[i]) % modulo;       sietes[i][4] = (sietes[i - 1][7] + 4 * diezala[i]) % modulo;       sietes[i][7] = (sietes[i - 1][7] + 7 * diezala[i]) % modulo;       sumahasta7[i][4] =           (4 * diezala[i] % modulo * dosala[i] + sumahasta7[i - 1][7]) % modulo;       sumahasta7[i][7] = (sumahasta7[i][4] + 7 * diezala[i] % modulo * dosala[i] +                           sumahasta7[i - 1][7]) %                          modulo;       prodhasta7[i][4] =           (4 * diezala[i] % modulo *                (2 * sumahasta7[i - 1][7] - cuatros[i - 1][4] - sietes[i - 1][7] +                 4 * diezala[i] % modulo * (dosala[i] - 1) % modulo) %                modulo +            prodhasta7[i - 1][7]) %           modulo;       prodhasta7[i][7] =           (prodhasta7[i][4] + sietes[i][4] * cuatros[i][7] % modulo +            7 * diezala[i] % modulo *                (2 * sumahasta7[i - 1][7] - cuatros[i - 1][4] - sietes[i - 1][7] +                 7 * diezala[i] % modulo * (dosala[i] - 1) % modulo) %                modulo +            prodhasta7[i - 1][7]) %           modulo;     }     cout << ((computa(sr) - computa(sl)) % modulo + modulo) % modulo << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long x, y, z;     long long x1, y1, z1;     vector<long long> a(6);     long long sum = 0;     cin >> x >> y >> z;     cin >> x1 >> y1 >> z1;     for (int i = 0; i < 6; ++i) {       long long b;       cin >> b;       a[i] = b;     }     if (x < 0) {       sum += a[4];     } else if (x > x1) {       sum += a[5];     }     if (y < 0) {       sum += a[0];     } else if (y > y1) {       sum += a[1];     }     if (z < 0) {       sum += a[2];     } else if (z > z1) {       sum += a[3];     }     cout << sum;   }


#include <bits/stdc++.h>   struct node {     double x, y, z;   } p[5005];   double d[5005];   double getlen(node a, node b) {     double len;     len = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) +           (a.z - b.z) * (a.z - b.z);     return sqrt(len);   }   int main() {     int n, i, j, a, b, c;     while (scanf( %d , &n) != EOF) {       for (i = 0; i < n; i++) {         scanf( %d %d %d , &a, &b, &c);         p[i].x = a * 1.0;         p[i].y = b * 1.0;         p[i].z = c * 1.0;       }       for (i = 1; i < n; i++) {         d[i] = getlen(p[0], p[i]);       }       double lenn;       double max = 9999999.0;       for (i = 1; i < n; i++) {         for (j = 1; j <= i; j++) {           if (j == i) continue;           lenn = d[i] + d[j] + getlen(p[i], p[j]);           if (max - lenn > 1e-6) max = lenn;         }       }       printf( %.10f n , max * 1.0 / 2.0);     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     if (n == 2) {       printf( -1 n );       return 0;     }     printf( 6 n10 n15 n );     for (int i = 4; i <= n; i++) {       printf( 6 );       for (int zero = 1; zero <= i - 4 + 1; zero++) printf( 0 );       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       int x;       cin >> x;       int a[s.length()];       for (int i = 0; i < s.length(); i++) {         a[i] = 1;       }       for (int i = 0; i < s.length(); i++) {         if (s[i] ==  0 ) {           if (i - x >= 0) {             a[i - x] = 0;           }           if (i + x < s.length()) {             a[i + x] = 0;           }         }       }       int tag = 0;       for (int i = 0; i < s.length(); i++) {         if (s[i] ==  1 ) {           int tag1 = 0;           if (i - x >= 0) {             if (a[i - x] == 1) {               a[i - x] = 1;               tag1++;             }           }           if (i + x < s.length()) {             if (a[i + x] == 1) {               tag1++;             }           }           if (tag1 == 0) {             tag = 1;             break;           }         }       }       if (tag == 1) {         cout <<  -1  << endl;       } else {         for (int i = 0; i < s.length(); i++) {           cout << a[i];         }         cout << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, a, b, c, d, e, R, B, P, ans;   char s;   inline long long read() {     long long sum = 0, x = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) x = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       sum = sum * 10 + ch -  0 ;       ch = getchar();     }     return sum * x;   }   inline void write(long long x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );     return;   }   signed main() {     n = read();     for (register long long i = 1; i <= n; ++i) {       m = read();       cin >> s;       if (s ==  P  || s ==  R ) {         if (R) {           ans += m - b;           a = max(a, m - b);         }         R = 1;         b = m;       }       if (s ==  P  || s ==  B ) {         if (B) {           ans += m - c;           d = max(d, m - c);         }         B = 1;         c = m;       }       if (s ==  P ) {         if (P) ans += min(0ll, m - e - d - a);         P = 1;         a = d = 0;         e = m;       }     }     write(ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fll;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, x, y;     cin >> n >> x >> y;     long long a1 = y - n + 1;     if (a1 <= 0 or a1 * a1 + n - 1 < x) return cout << -1 <<   n , 0;     cout << a1 <<   n ;     for (int i = 0; i < n - 1; i++) cout << 1 <<   n ;     exit(0);   }


#include <bits/stdc++.h>   using namespace std;   int T;   priority_queue<int, vector<int>, greater<int> > q;   vector<int> g[1000005];   int main() {     scanf( %d , &T);     int n;     long long int ans;     while (T--) {       ans = 0;       scanf( %d , &n);       int x, y;       for (int i = 1; i <= n; i++) {         scanf( %d %d , &x, &y);         g[x].push_back(y);       }       for (int i = n - 1; i >= 0; i--) {         int sz = g[i].size();         for (int j = 0; j < sz; j++) q.push(g[i][j]);         while (q.size() > n - i) {           ans += q.top(), q.pop();         }       }       printf( %lld n , ans);       for (int i = 0; i < n; ++i) {         g[i].clear();         while (!q.empty()) q.pop();       }     }     return 0;   }


#include <bits/stdc++.h>   const double EPS = 1e-24;   const long long int MOD = 1000000007ll;   const long long int MOD1 = 1000000009ll;   const long long int MOD2 = 1100000009ll;   const double PI = 3.14159265359;   int INF = 2147483645;   long long int INFINF = 9223372036854775807;   template <class T>   T Max2(T a, T b) {     return a < b ? b : a;   }   template <class T>   T Min2(T a, T b) {     return a < b ? a : b;   }   template <class T>   T Max3(T a, T b, T c) {     return Max2(Max2(a, b), c);   }   template <class T>   T Min3(T a, T b, T c) {     return Min2(Min2(a, b), c);   }   template <class T>   T Max4(T a, T b, T c, T d) {     return Max2(Max2(a, b), Max2(c, d));   }   template <class T>   T Min4(T a, T b, T c, T d) {     return Min2(Min2(a, b), Min2(c, d));   }   using namespace std;   int bit_count(long long int _x) {     int _ret = 0;     while (_x) {       if (_x % 2 == 1) _ret++;       _x /= 2;     }     return _ret;   }   int bit(long long int _mask, long long int _i) {     return (_mask & (1 << _i)) == 0 ? 0 : 1;   }   long long int powermod(long long int _a, long long int _b, long long int _m) {     long long int _r = 1;     while (_b) {       if (_b % 2 == 1) _r = (_r * _a) % _m;       _b /= 2;       _a = (_a * _a) % _m;     }     return _r;   }   int x[5], y[5];   bool issquare[30010];   int sz, sz2;   char s[110][110];   char c[5];   void type2(int a1, int a2, int b1, int b2, int c1, int c2, int i1, int i2,              int i3) {     for (int i = 1; i <= a1; i++)       for (int j = 1; j <= a2; j++) s[i][j] = c[i1];     for (int i = a1 + 1; i <= a1 + b1; i++)       for (int j = 1; j <= b2; j++) s[i][j] = c[i2];     for (int i = 1; i <= c1; i++)       for (int j = a2 + 1; j <= a2 + c2; j++) s[i][j] = c[i3];   }   void print() {     cout << sz <<   n ;     for (int i = 1; i <= sz; i++) {       for (int j = 1; j <= sz; j++) cout << s[i][j];       cout <<   n ;     }   }   int main() {     std::ios::sync_with_stdio(false);     srand(time(NULL));     for (int i = 1; i <= 3; i++) cin >> x[i] >> y[i];     c[1] =  A ;     c[2] =  B ;     c[3] =  C ;     for (int i = 2; i * i <= 30010; i++) issquare[i * i] = true;     sz2 = 0;     for (int i = 1; i <= 3; i++) sz2 += x[i] * y[i];     if (!issquare[sz2]) {       cout <<  -1 ;       return 0;     }     for (int i = 2; i * i <= 30010; i++) {       if (i * i == sz2) {         sz = i;         break;       }     }     for (int i = 1; i <= 3; i++)       if (x[i] > y[i]) swap(x[i], y[i]);     if (y[1] == sz && y[2] == sz && y[3] == sz && x[1] + x[2] + x[3] == sz) {       cout << sz <<   n ;       for (int i = 1; i <= x[1]; i++) {         for (int j = 1; j <= y[1]; j++) cout <<  A ;         cout <<   n ;       }       for (int i = 1; i <= x[2]; i++) {         for (int j = 1; j <= y[2]; j++) cout <<  B ;         cout <<   n ;       }       for (int i = 1; i <= x[3]; i++) {         for (int j = 1; j <= y[3]; j++) cout <<  C ;         cout <<   n ;       }       return 0;     }     for (int i = 1; i <= 3; i++)       for (int j = 1; j <= 3; j++)         for (int k = 1; k <= 3; k++) {           if (i == j || j == k || i == k) continue;           if (x[j] + x[k] == sz && y[j] == y[k]) {             if (x[i] == sz && y[i] == sz - y[j]) {               type2(x[j], y[j], x[k], y[k], x[i], y[i], j, k, i);               print();               return 0;             }             if (y[i] == sz && x[i] == sz - y[j]) {               type2(x[j], y[j], x[k], y[k], y[i], x[i], j, k, i);               print();               return 0;             }           } else if (x[j] + y[k] == sz && y[j] == x[k]) {             if (x[i] == sz && y[i] == sz - y[j]) {               type2(x[j], y[j], y[k], x[k], x[i], y[i], j, k, i);               print();               return 0;             }             if (y[i] == sz && x[i] == sz - y[j]) {               type2(x[j], y[j], y[k], x[k], y[i], x[i], j, k, i);               print();               return 0;             }           } else if (y[j] + x[k] == sz && x[j] == y[k]) {             if (x[i] == sz && y[i] == sz - x[j]) {               type2(y[j], x[j], x[k], y[k], x[i], y[i], j, k, i);               print();               return 0;             }             if (y[i] == sz && x[i] == sz - x[j]) {               type2(y[j], x[j], x[k], y[k], y[i], x[i], j, k, i);               print();               return 0;             }           } else if (y[j] + y[k] == sz && x[j] == x[k]) {             if (x[i] == sz && y[i] == sz - x[j]) {               type2(y[j], x[j], y[k], x[k], x[i], y[i], j, k, i);               print();               return 0;             }             if (y[i] == sz && x[i] == sz - x[j]) {               type2(y[j], x[j], y[k], x[k], y[i], x[i], j, k, i);               print();               return 0;             }           }         }     cout <<  -1 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string s;     int l1, l, r, count = 0;     cin >> s;     l1 = s.size();     int arr[l1];     memset(arr, 0, sizeof(arr));     int last = -1;     for (int i = 0; i < l1;) {       if (s[i] == s[i + 1]) {         l = i;         r = i + 1;         while (s[l] == s[r] && l >= 0 && r < l1) {           count++;           s.erase(l, 1);           s.erase(l, 1);           l--;           r--;           l1 -= 2;         }         i = r - 1;         last = r - 1;       }       i++;     }     if (count % 2)       cout <<  Yes n ;     else       cout <<  No ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<long long int, long long int>> a;   vector<pair<long long int, long long int>> b;   vector<long long int> c;   long long int n, m, T;   bool solve(long long int d) {     priority_queue<long long int, vector<long long int>, greater<long long int>>         s;     long long int j = 0;     long long int sum = 0;     for (long long int i = 0; i < m; i = i + d) {       while (j < n && a[j].first >= b[i].first) {         s.push(c[a[j].second]);         j++;       }       if (s.empty()) return false;       long long int temp = s.top();       s.pop();       sum += temp;     }     return sum <= T;   }   signed main(void) {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     while (t--) {       cin >> n >> m >> T;       a.resize(0);       b.resize(0);       c.resize(n);       for (long long int i = 0; i < m; i++) {         long long int temp;         cin >> temp;         b.push_back({temp, i});       }       for (long long int i = 0; i < n; i++) {         long long int temp;         cin >> temp;         a.push_back({temp, i});       }       for (long long int i = 0; i < n; i++) cin >> c[i];       sort(b.begin(), b.end(), greater<pair<long long int, long long int>>());       sort(a.begin(), a.end(), greater<pair<long long int, long long int>>());       long long int l = 1;       long long int r = m;       long long int ans = -1;       while (l <= r) {         long long int mid = (l + r) / 2;         if (solve(mid)) {           r = mid - 1;           ans = mid;         } else           l = mid + 1;       }       if (ans == -1) {         cout <<  NO  << endl;         continue;       }       cout <<  YES  << endl;       priority_queue<pair<long long int, long long int>,                      vector<pair<long long int, long long int>>,                      greater<pair<long long int, long long int>>>           s;       long long int j = 0;       long long int sum = 0;       vector<long long int> p(m);       for (long long int i = 0; i < m; i = i + ans) {         while (j < n && a[j].first >= b[i].first) {           s.push({c[a[j].second], a[j].second});           j++;         }         long long int index = s.top().second;         s.pop();         for (long long int k = i; k < min(i + ans, m); k++) {           p[b[k].second] = index;         }       }       for (long long int i = 0; i < m; i++) cout << p[i] + 1 <<    ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 6e1;   map<string, int> mp;   int n;   int answer = 1;   string To(string a) {     for (int i = 0; i < a.size(); i++)       if (a[i] >  Z ) a[i] = a[i] - 32;     return a;   }   int main() {     mp[ POLYCARP ] = 1;     cin >> n;     for (int i = 0; i < n; i++) {       string n1, r, n2;       cin >> n1 >> r >> n2;       n1 = To(n1);       n2 = To(n2);       mp[n1] = mp[n2] + 1;       answer = max(answer, mp[n1]);     }     cout << answer;   }