#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 22;   const int INF = 1e9 + 2;   long long n, ans, mark[MAXN];   char str[MAXN];   int main() {     cin >> n;     cin >> str;     for (int i = 0; i < n; i++) {       if (mark[str[i]] == 0) {         mark[str[i]] = 1;         ans++;       }     }     if (n > 26)       cout << -1;     else       cout << n - ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   using DD = long double;   using pii = pair<int, int>;   const LL INFLL = 0x7f7f7f7f7f7f7f7fLL;   const int INFint = 0x7f7f7f7f;   LL exactMatchingSubranges(vector<int> &cumulative, int match) {     LL rr = 0;     for (int i = 0; i < int((int((cumulative).size()))); ++i) {       int looking_for = match ^ cumulative[i];       int p = lower_bound((cumulative).begin(), (cumulative).end(), looking_for) -               cumulative.begin();       int q = upper_bound((cumulative).begin(), (cumulative).end(), looking_for) -               cumulative.begin();       rr += q - p;     }     return rr;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.precision(16);     int n, k;     cin >> n >> k;     vector<int> aa(n, 0);     for (int i = 0; i < int(n); ++i) cin >> aa[i];     vector<int> cumulative((int((aa).size())), 0);     cumulative[0] = aa[0];     int amax = 0;     for (int i = int(1); i < int((int((aa).size()))); ++i) {       cumulative[i] = cumulative[i - 1] ^ aa[i];       amax = max(amax, aa[i]);     }     cumulative.push_back(0);     sort((cumulative).begin(), (cumulative).end());     LL rr = exactMatchingSubranges(cumulative, k);     while (true) {       if ((k & 1) == 0) {         k |= 1;         rr += exactMatchingSubranges(cumulative, k);       }       k >>= 1;       amax >>= 1;       if (amax == 0) break;       for (int i = 0; i < int((int((cumulative).size()))); ++i)         cumulative[i] >>= 1;     }     cout << rr / 2 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5, maxm = 4e5 + 5;   int head[maxn], nume;   struct edge {     int v, w, c, next;   } e[maxm];   inline void init_edge() {     memset(head, -1, sizeof head);     nume = 0;   }   inline void add_edge(int u, int v, int w = 0, int c = 0) {     e[nume].v = v;     e[nume].w = w;     e[nume].c = c;     e[nume].next = head[u];     head[u] = nume++;   }   int dep[maxn], dp[maxn][20], numpow = 19;   void dfs(int u, int f) {     dep[u] = dep[f] + 1;     dp[u][0] = f;     for (int i = 1; i <= numpow; ++i) dp[u][i] = dp[dp[u][i - 1]][i - 1];     for (int i = head[u]; ~i; i = e[i].next) {       int v = e[i].v;       if (v == f) continue;       dfs(v, u);     }   }   int lca(int u, int v) {     if (dep[u] > dep[v]) swap(u, v);     if (dep[u] < dep[v]) {       int tmp = dep[v] - dep[u];       for (int i = 0; i <= numpow; ++i)         if (tmp & (1 << i)) v = dp[v][i];     }     if (u != v) {       for (int i = numpow; ~i; --i)         if (dp[u][i] != dp[v][i]) u = dp[u][i], v = dp[v][i];       u = v = dp[u][0];     }     return u;   }   int ff(int u, int num) {     for (int i = 0; (1 << i) <= num; i++) {       if (num & (1 << i)) u = dp[u][i];     }     return u;   }   int f[maxn];   int find(int x) {     if (x == f[x]) return x;     return f[x] = find(f[x]);   }   int he(int u, int v) {     u = find(u);     v = find(v);     if (u != v) f[u] = v;   }   queue<int> que;   int n, k, r, q;   int vis[maxn];   int main() {     scanf( %d%d%d , &n, &k, &r);     init_edge();     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       add_edge(u, v);       add_edge(v, u);     }     memset(vis, -1, sizeof vis);     for (int i = 1; i <= r; i++) {       int u;       scanf( %d , &u);       vis[u] = 0;       que.push(u);     }     while (!que.empty()) {       int u = que.front();       que.pop();       for (int i = head[u]; ~i; i = e[i].next) {         int v = e[i].v;         if (vis[v] == -1) {           vis[v] = vis[u] + 1;           que.push(v);         }       }     }     for (int i = 1; i <= n; i++) f[i] = i;     for (int u = 1; u <= n; u++) {       for (int i = head[u]; ~i; i = e[i].next) {         int v = e[i].v;         if (vis[u] + vis[v] < k) {           he(u, v);         }       }     }     dfs(1, 0);     scanf( %d , &q);     while (q--) {       int u, v, Lca, U, V;       scanf( %d%d , &u, &v);       Lca = lca(u, v);       if (dep[u] + dep[v] - 2 * dep[Lca] <= k)         printf( YES n );       else {         if (dep[u] - dep[Lca] >= (k + 1) / 2)           U = ff(u, (k + 1) / 2);         else           U = ff(v, dep[u] + dep[v] - 2 * dep[Lca] - (k + 1) / 2);         if (dep[v] - dep[Lca] >= (k + 1) / 2)           V = ff(v, (k + 1) / 2);         else           V = ff(u, dep[u] + dep[v] - 2 * dep[Lca] - (k + 1) / 2);         if (find(U) == find(V) && vis[U] <= k / 2 && vis[V] <= k / 2)           printf( YES n );         else           printf( NO n );       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k, n, w, q, cem = 0;     cin >> k >> n >> w;     for (int i = 1; i <= w; i++) {       cem = cem + i * k;     }     if (n <= cem) {       cout << cem - n;     } else       cout << 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt_occur(string s, string t) {     int cnt = 0;     for (int i = 0; i < s.size(); ++i) {       if (s.substr(i, 3) == t) cnt++;     }     return cnt;   }   long max(int a, int b) { return a >= b ? a : b; }   void swap(int &a, int &b) {     int temp = a;     a = b;     b = temp;   }   int power(int x, unsigned int y) {     int temp;     if (y == 0) return 1;     temp = power(x, y / 2);     if (y % 2 == 0)       return temp * temp;     else       return x * temp * temp;   }   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   void soE(int n, bool f[]) {     for (int i = 0; i < n; ++i) f[i] = true;     f[0] = f[1] = false;     for (int p = 2; p * p <= n; p++) {       if (f[p] == true) {         for (int i = p * p; i <= n; i += p) f[i] = false;       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     ;     while (t--) {       long long a;       cin >> a;       long long cnt = 0;       long long temp = a;       while (a) {         if (temp % 2 == 0) {           if (a % 2 == 0) {             if ((a / 2) % 2 != 0 or a == 4) {               cnt += a / 2;               if (a == 4) {                 a = a / 2;               } else                 a = a / 2 - 1;             } else {               cnt += 1;               a -= 2;             }           }         } else {           if (a == 5) {             cnt += 2;             break;           }           cnt += 1;           a = a - 1;           if (a == 0) break;           if ((a / 2) % 2 == 0)             a -= 1;           else             a = a / 2;         }       }       cout << cnt << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void RI() {}   template <typename... T>   void RI(int& head, T&... tail) {     scanf( %d , &head);     RI(tail...);   }   void RLL() {}   template <typename... T>   void RLL(long long& head, T&... tail) {     scanf( %lld , &head);     RLL(tail...);   }   void print() { putchar(  n ); }   template <typename T, typename... U>   void print(T head, U... tail) {     cout << head <<    ;     print(tail...);   }   const int MOD = 1000000007;   int main() {     int k, ans = 0;     RI(k);     for (int i = 0; i < (int)(k); i++) {       int r;       RI(r);       ans = max(ans, r - 25);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int K, N, M, Q;   map<string, int> Basic, F[111];   string st, Comp_St[60];   vector<pair<string, int> > Comp[60];   int main() {     cin >> K >> N >> M >> Q;     for (int i = 1; i <= N; i++) {       cin >> st;       Basic[st] = i;     }     for (int i = 0, k; i < M; i++) {       cin >> st;       st = st.substr(0, st.size() - 1);       Comp_St[i] = st;       for (string stt; cin >> stt;) {         cin >> k;         Comp[i].push_back(make_pair(stt, k));         char ch;         scanf( %c , &ch);         if (ch !=  , ) break;       }     }     for (int i = 0, p; i < Q; i++) {       cin >> p >> st;       F[p][st]++;       for (int j = 0; j < M; j++) {         st = Comp_St[j];         bool flag = true;         for (int k = 0; k < Comp[j].size(); k++)           if (F[p][Comp[j][k].first] < Comp[j][k].second) flag = false;         if (flag) {           F[p][st]++;           for (int k = 0; k < Comp[j].size(); k++)             F[p][Comp[j][k].first] -= Comp[j][k].second;         }       }     }     for (int i = 1; i <= K; i++) {       int TOT = 0;       for (map<string, int>::iterator it = F[i].begin(); it != F[i].end(); it++)         if (it->second > 0) TOT++;       printf( %d n , TOT);       for (map<string, int>::iterator it = F[i].begin(); it != F[i].end(); it++)         if (it->second > 0) cout << it->first <<     << it->second << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct team {     string name;     int score;     int goals_for;     int goals_against;     int goal_diff() const { return goals_for - goals_against; }   };   bool operator<(const team &A, const team &B) {     if (A.score != B.score) return A.score > B.score;     if (A.goal_diff() != B.goal_diff()) return A.goal_diff() > B.goal_diff();     return A.goals_for > B.goals_for;   }   map<string, team> m;   int main(void) {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       static char buff[128];       scanf( %s , buff);       team T;       T.name = string(buff);       T.score = T.goals_against = T.goals_for = 0;       m[T.name] = T;     }     for (int i = 0; i < n * (n - 1) / 2; ++i) {       static char buff[128];       int ga, gb;       scanf( %s %d:%d , buff, &ga, &gb);       string s(buff);       int f = s.find( - );       team &a = m[s.substr(0, f)];       team &b = m[s.substr(f + 1)];       a.goals_for += ga;       a.goals_against += gb;       b.goals_for += gb;       b.goals_against += ga;       if (ga > gb)         a.score += 3;       else if (ga < gb)         b.score += 3;       else {         a.score += 1;         b.score += 1;       }     }     vector<team> teams;     for (map<string, team>::iterator it = m.begin(); it != m.end(); ++it)       teams.push_back(it->second);     sort(teams.begin(), teams.end());     vector<string> ret;     for (int i = 0; i < n / 2; ++i) ret.push_back(teams[i].name);     sort(ret.begin(), ret.end());     for (int i = 0; i < n / 2; ++i) printf( %s n , ret[i].c_str());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int tot = 0, fh = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) fh = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       tot = tot * 10 + c -  0 ;       c = getchar();     }     return tot * fh;   }   void getstr(char *a) {     char c = getchar();     int len = 0;     while (!((c >=  A  && c <=  Z ) || (c >=  a  && c <=  z ) ||              (c >=  0  && c <=  9 )))       c = getchar();     while ((c >=  A  && c <=  Z ) || (c >=  a  && c <=  z ) ||            (c >=  0  && c <=  9 )) {       a[++len] = c;       c = getchar();     }   }   const int maxn = 200100;   int n, t, q, ans, block, num, belong[maxn];   long long a[maxn], L[2000], R[2000], sum[2000], tag[2000];   void build() {     block = sqrt(n);     num = n / block;     if (num * block != n) num++;     for (int i = 1; i <= num; i++) {       L[i] = block * (i - 1) + 1;       R[i] = block * i;       R[num] = n;       for (int j = L[i]; j <= R[i]; j++) {         belong[j] = i;         sum[i] += a[j];       }     }   }   int fd(int l, int r, int lim) {}   int main() {     n = read();     q = read();     for (int i = 1; i <= n; i++) a[i] = read();     build();     while (q--) {       t = read();       if (t == 1) {         int x = read();         long long y = read();         for (int i = 1; i < belong[x]; i++)           if (tag[i] == 0) {             if (a[R[i]] < y) {               if (a[L[i]] <= y) {                 tag[i] = y;                 sum[i] = (R[i] - L[i] + 1ll) * tag[i];               } else {                 sum[i] = 0;                 for (int j = L[i]; j <= R[i]; j++) {                   a[j] = max(a[j], y);                   sum[i] += a[j];                 }               }             }           } else {             if (tag[i] < y) {               tag[i] = y;               sum[i] = (R[i] - L[i] + 1ll) * tag[i];             }           }         int cur = belong[x];         sum[cur] = 0;         for (int i = L[cur]; i <= R[cur]; i++)           if (i <= x) {             a[i] = max(a[i], max(y, tag[cur]));             sum[cur] += a[i];           } else {             a[i] = max(a[i], tag[cur]);             sum[cur] += a[i];           }         tag[cur] = 0;       } else {         int x = read();         long long y = read();         ans = 0;         int cur = belong[x];         for (int i = x; i <= R[cur]; i++) {           long long tmp = max(tag[cur], a[i]);           if (y >= tmp) {             y -= tmp;             ans++;             tmp = max(tag[cur], a[R[cur]]);             if (tmp > y) break;           }         }         for (int i = belong[x] + 1; i <= num; i++) {           long long tmp = sum[i];           if (y >= tmp) {             y -= tmp;             ans += R[i] - L[i] + 1;           } else {             tmp = max(tag[i], a[R[i]]);             if (tmp > y) continue;             for (int j = L[i]; j <= R[i]; j++) {               tmp = max(tag[i], a[j]);               if (y >= tmp) {                 y -= tmp;                 ans++;                 tmp = max(tag[i], a[R[i]]);                 if (tmp > y) break;               }             }           }         }         cout << ans << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct BIT {     static const int N = 200006;     long long a[N];     int n;     void init(int _n) {       n = _n;       memset(a, 0, sizeof(a));     }     void update(int pos, long long val) {       for (int i = pos; n >= i; i += i & (-i)) {         a[i] += val;       }     }     long long query(int pos) {       long long ret = 0;       for (int i = pos; i > 0; i -= i & (-i)) {         ret += a[i];       }       return ret;     }   } bit;   const int N = 200006;   const int P = 32;   set<pair<long long, long long> > st[P];   long long a[N];   void addd(long long val, int pos) {     if (!val)       st[0].insert(make_pair(pos, val));     else {       for (int i = P - 1; i >= 1; i--) {         if (val >= (1LL << (i - 1))) {           st[i].insert(make_pair(pos, val));           break;         }       }     }   }   void dell(long long val, int pos) {     if (!val)       st[0].erase(make_pair(pos, val));     else {       for (int i = P - 1; i >= 1; i--) {         if (val >= (1LL << (i - 1))) {           st[i].erase(make_pair(pos, val));           break;         }       }     }   }   int main() {     int n, q;     scanf( %d %d , &n, &q);     bit.init(n);     for (int i = 1; n >= i; i++) {       scanf( %lld , &a[i]);       bit.update(i, a[i]);       addd(a[i], i);     }     while (q--) {       int p, x;       scanf( %d %d , &p, &x);       dell(a[p], p);       bit.update(p, -a[p]);       a[p] = x;       addd(a[p], p);       bit.update(p, a[p]);       int ans = -1;       for (int i = 0; P > i; i++) {         auto iter = st[i].begin();         int cnt = 2;         while (cnt--) {           if (iter == st[i].end()) break;           pair<long long, long long> p = (*iter);           if (bit.query(p.first - 1) == p.second) {             ans = p.first;             break;           }           ++iter;         }       }       printf( %d n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   struct P {     int x, y;   };   P me;   P other;   bool white;   int N, M;   P operator+(P a, P b) { return {a.x + b.x, a.y + b.y}; }   P operator-(P a, P b) { return {a.x - b.x, a.y - b.y}; }   bool operator==(P a, P b) { return a.x == b.x && a.y == b.y; }   bool isItAStep(P a, P b) {     a = a - b;     int dx = abs(a.x);     int dy = abs(a.y);     return (dx == 1 && dy == 2) || (dx == 2 && dy == 1);   }   P winWhite, winBlack;   void step(P newP) {     if (white && isItAStep(winWhite, me)) {       cout << winWhite.x <<     << winWhite.y << endl << flush;       exit(0);     }     if (!white && isItAStep(winBlack, me)) {       cout << winBlack.x <<     << winBlack.y << endl << flush;       exit(0);     }     if (isItAStep(other, me)) {       cout << other.x <<     << other.y << endl << flush;       exit(0);     }     me = newP;     cout << me.x <<     << me.y << endl << flush;     if (white && me.x == N / 2 && me.y == M / 2) exit(0);     if (!white && me.x == N / 2 + 1 && me.y == M / 2) exit(0);   }   void getStep() {     cin >> other.x >> other.y;     if (other == me) exit(1);     if (other.x == -1) exit(0);   }   const vector<P> ize = {       {+1, +2}, {-1, +2}, {+1, -2}, {-1, -2},       {+2, +1}, {-2, +1}, {+2, -1}, {-2, -1},   };   vector<P> dfs(P from, P to, int K) {     if (from == to) return vector<P>(1, to);     if (K == 0) return vector<P>();     vector<P> best;     for (const P& x : ize) {       P to2 = to + x;       if (to2.x < 1 || to2.y < 1) continue;       if (to2.x > N || to2.y > M) continue;       vector<P> c = dfs(from, to2, K - 1);       if (best.size() == 0 || (!c.empty() && c.size() < best.size())) best = c;     }     if (best.empty()) return best;     best.push_back(to);     return best;   }   vector<P> closestDistance_(P from, P to) {     int dx = abs(to.x - from.x);     int dy = abs(to.y - from.y);     int ix = (to.x > from.x ? 1 : -1);     int iy = (to.y > from.y ? 1 : -1);     vector<P> S;     while (dx > 5 || dy > 5) {       int wx = 2, wy = 1;       if (dx < dy) {         wx = 1;         wy = 2;       }       ix = (to.x > from.x ? 1 : -1);       iy = (to.y > from.y ? 1 : -1);       from.x += wx * ix;       from.y += wy * iy;       S.push_back(from);       dx = abs(to.x - from.x);       dy = abs(to.y - from.y);     }     vector<P> ize = dfs(from, to, 6);     assert(!ize.empty());     auto it = ize.begin(), end = ize.end();     it++;     while (it != end) {       S.push_back(*it);       it++;     }     return S;   }   void check(vector<P>& S, P from, P to) {     if (S.empty()) return;     P last = from;     assert(to == S.back());     for (const P& p : S) {       assert(isItAStep(last, p));       last = p;     }   }   int main() {     int xw, yw, xb, yb;     cin >> N >> M;     cin >> xw >> yw >> xb >> yb;     winWhite = {N / 2, M / 2};     winBlack = {N / 2 + 1, M / 2};     P whitee = {xw, yw};     P blackk = {xb, yb};     vector<P> cdww = closestDistance_(whitee, winWhite);     vector<P> cdbw = closestDistance_(blackk, winWhite);     vector<P> cdwb = closestDistance_(whitee, winBlack);     vector<P> cdbb = closestDistance_(blackk, winBlack);     vector<P> cd;     white = true;     bool white_kerget = ((xw ^ xb ^ yw ^ yb) & 1) == 1;     cerr <<  W->w:   << cdww.size() << endl;     cerr <<  W->b:   << cdwb.size() << endl;     cerr <<  B->w:   << cdbw.size() << endl;     cerr <<  B->b:   << cdbb.size() << endl;     cerr << (white_kerget ?  White kerget  :  Black kerget ) << endl;     if (white_kerget) {       cerr <<  white kerget  << endl;       if (cdwb.size() <= cdbb.size() + 1) {         cerr <<  white bevarja  << endl;         white = true;         cd = move(cdwb);       } else if (cdww.size() <= cdbb.size()) {         cerr <<  white megelozi  << endl;         white = true;         cd = move(cdww);       } else {         white = false;         cd = move(cdbb);       }     } else {       cerr <<  black kerget  << endl;       if (cdbw.size() <= cdww.size()) {         cerr <<  black bevarja  << endl;         white = false;         cd = move(cdbw);       } else if (cdbb.size() < cdww.size()) {         cerr <<  black megelozi  << endl;         white = false;         cd = move(cdbb);       } else {         white = true;         cd = move(cdww);       }     }     cdww.clear();     cdwb.clear();     cdbw.clear();     cdbb.clear();     if (white) {       me = whitee;       other = blackk;       cout <<  WHITE  << endl;     } else {       me = blackk;       other = whitee;       cout <<  BLACK  << endl;       getStep();     }     if (!white) {       cd.push_back(winWhite + P{2, 1});       cd.push_back(winWhite + P{0, 2});       cd.push_back(winWhite + P{1, 0});     } else if (white) {       cd.push_back(winBlack - P{2, 1});       cd.push_back(winBlack - P{0, 2});       cd.push_back(winBlack - P{1, 0});     }     int i = 0;     while (i < cd.size()) {       step(cd[i]);       getStep();       i++;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[200005];   bool vis[200005];   int a[200005];   int n, m;   double p;   void doit() {     memset(vis, 0, sizeof(vis));     for (int i = 1; i <= n; ++i) {       scanf( %s , s);       if (s[0] !=  ? ) {         a[i] = atoi(s);         vis[i] = 1;       }     }     for (int i = 1; i <= m; ++i) {       a[n + i] = 1001000000;       vis[n + i] = 1;     }     n += m;     long long ans = 0;     for (int i = 1; i <= m; ++i) {       int last = -1001000000, ff, t = 0;       for (int j = i; j <= n; j += m)         if (vis[j]) {           if (a[j] - last <= t) {             printf( Incorrect sequence n );             return;           }           if (!t) {             last = a[j];             continue;           }           if (last <= 0 && a[j] >= 0) {             if (last < 0 && a[j] > 0) t--;             if (!t) {               for (int k = ff; k < j; k += m) a[k] = 0;               last = a[j];               continue;             }             int k1 = max(0, last + 1), k2 = 0;             while (t) {               if (k2 + 1 < a[j]) k2++, t--;               if (!t) break;               if (k1 - 1 > last) k1--, t--;             }             last = k1 - 1;             for (int k = ff; k < j; k += m) a[k] = ++last;             last = a[j];           } else if (last > 0) {             for (int k = ff; k < j; k += m) a[k] = ++last;             last = a[j];             t = 0;           } else {             last = a[j];             for (int k = j - m; k >= ff; k -= m) a[k] = --last;             last = a[j];             t = 0;           }         } else {           t++;           if (t == 1) ff = j;         }     }     n -= m;     for (int i = 1; i <= n - 1; ++i) printf( %d  , a[i]);     printf( %d n , a[n]);   }   int main() {     while (scanf( %d%d , &n, &m) != EOF) doit();   }


#include <bits/stdc++.h>   using namespace std;   bool comp(int a, int b) { return (a < b); }   int max(int a, int b) {     if (a > b) return a;     return b;   }   int min(int a, int b) {     if (a < b) return a;     return b;   }   long long power(long long a, int x) {     while (x--) {       a *= a;     }     return a;   }   int main() {     int n, i = 0, x;     cin >> n;     string s, c;     cin >> s;     while (i < n) {       x = i;       if (s[i] ==  o )         while (s[i + 1] ==  g  && s[i + 2] ==  o ) i += 2;       if (x < i)         c +=  *** ;       else         c += s[i];       i++;     }     cout << c;   }


#include <bits/stdc++.h>   using namespace std;   long long int arr[378999];   long long int arr2[234597];   long long int ab[10];   vector<long long int> adj[22222];   map<long long int, long long int> mp, mp2;   map<long long int, long long int>::iterator it;   vector<long long int> vec;   string s;   long long int gcd(long long int a, long long int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int t, i, loss, j, diff;     cin >> t;     while (t--) {       long long int n, x, y, k, maxi = INT_MIN, mini = INT_MAX, two = 0, one1 = 0,                                 one2 = 0, zero = 0, p;       long long int cs, cw, w;       mp.clear();       mp2.clear();       string s, ans =   ;       cin >> s;       cin >> x;       long long int len = s.length();       for (i = 0; i < len; i++) {         ans +=  1 ;       }       long long int f = 0;       for (i = 0; i < len; i++) {         if (s[i] ==  1 ) {           continue;         } else if (s[i] ==  0 ) {           if (i - x >= 0) {             ans[i - x] =  0 ;           }           if (i + x < len) {             ans[i + x] =  0 ;           }         }       }       for (i = 0; i < len; i++) {         if (s[i] ==  1 ) {           if ((i - x >= 0 && ans[i - x] ==  1 ) ||               (i + x < len && ans[i + x] ==  1 ))             continue;           else {             f = 1;             break;           }         }       }       if (f == 1)         cout <<  -1 n ;       else         cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1505];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     int ans = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= i - 1; j++)         if (a[j] > a[i]) ans ^= 1;     int q;     scanf( %d , &q);     while (q--) {       int a, b;       scanf( %d%d , &a, &b);       int sz = b - a + 1;       sz = sz * (sz - 1) / 2;       if (sz % 2 == 1) ans ^= 1;       if (ans == 0)         printf( even n );       else         printf( odd n );     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   string str;   int main() {     cin >> str;     n = str.length();     string str1 = str + str;     reverse(str.begin(), str.end());     string str2 = str + str;     int ans = 0;     int dp[2][2 * n];     for (int i = 0; i < 2 * n - 1; i++) {       dp[0][i] = 1;       if (i > 0 && str1[i] != str1[i - 1]) {         dp[0][i] += min(n - 1, dp[0][i - 1]);       }       ans = max(ans, dp[0][i]);     }     for (int i = 0; i < 2 * n - 1; i++) {       dp[1][i] = 1;       if (i > 0 && str2[i] != str2[i - 1]) {         dp[1][i] += min(n - 1, dp[1][i - 1]);       }       ans = max(ans, dp[1][i]);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[1111111];   bool curr_state[22];   long long sum_inversions[22];   long long sum_non_inversions[22];   int tmp_array1[1111111];   int tmp_array2[1111111];   int binary_search(int i, int sz) {     if (tmp_array2[0] >= tmp_array1[i]) return -1;     int low = 0;     int high = sz - 1;     while (low < high) {       int mid = (low + high + 1) / 2;       if (tmp_array2[mid] >= tmp_array1[i])         high = mid - 1;       else         low = mid;     }     return low;   }   long long find_num_inversions(int sz) {     sort(tmp_array2, tmp_array2 + sz);     long long answer = 0;     for (int i = 0; i < sz; i++) {       int j = binary_search(i, sz);       answer += j + 1;     }     return answer;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < (1 << n); i++) scanf( %d , &a[i]);     for (int level = 1; level <= n; level++) {       sum_inversions[level - 1] = 0;       sum_non_inversions[level - 1] = 0;       for (int j = 0; j < (1 << n); j += (1 << (n - level + 1))) {         int l1 = j;         int u1 = j + (1 << (n - level)) - 1;         int l2 = j + (1 << (n - level));         int u2 = j + (1 << (n - level + 1)) - 1;         for (int i = l1; i <= u1; i++) {           tmp_array1[i - l1] = a[i];         }         for (int j = l2; j <= u2; j++) {           tmp_array2[j - l2] = a[j];         }         sum_inversions[level - 1] += find_num_inversions(u1 - l1 + 1);         for (int i = l1; i <= u1; i++) {           tmp_array2[i - l1] = a[i];         }         for (int j = l2; j <= u2; j++) {           tmp_array1[j - l2] = a[j];         }         sum_non_inversions[level - 1] += find_num_inversions(u1 - l1 + 1);       }     }     for (int i = 0; i <= n - 1; i++) {       curr_state[i] = false;     }     int m;     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       int q;       scanf( %d , &q);       for (int j = n - q; j <= n - 1; j++) curr_state[j] = (!curr_state[j]);       long long answer = 0;       for (int level = 0; level <= n - 1; level++)         answer += (curr_state[level] ? sum_non_inversions[level]                                      : sum_inversions[level]);       cout << answer << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> t;   int rec(int k, int sz, int n = 0) {     if (t[n] <= k) return k - t[n];     if (n >= sz && t[n]) return n;     int a = rec(k, sz, 2 * n + 1);     if (a >= sz)       return a;     else       return rec(a, sz, 2 * n + 2);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int n, m, q1 = 0, q2 = 0, k = 1;     cin >> n >> m;     vector<int> a(m), el;     for (int i = 0; i < m; ++i) cin >> a[i];     while (k < n) k *= 2;     k *= 2;     k--;     t.resize(k);     for (int i = 0; i < n; ++i) {       int p;       cin >> p;       if (p == 0 || p == 1) {         el.push_back(p);         int index = k / 2 + q1;         t[index] = 1;         while (index != 0) {           index = index / 2 - (index % 2 == 0);           t[index] = t[2 * index + 1] + t[2 * index + 2];         }         q1++;         q2++;       } else {         vector<int> rm;         int l = -1, r = m;         while (l + 1 < r) {           int mid = (l + r) / 2;           if (a[mid] > q2)             r = mid;           else             l = mid;         }         q2 -= l + 1;         for (int j = 0; j <= l; ++j) rm.push_back(rec(a[j] - 1, k / 2));         for (int x : rm) {           t[x] = 0;           while (x != 0) {             x = x / 2 - (x % 2 == 0);             t[x] = t[2 * x + 1] + t[2 * x + 2];           }         }       }     }     bool empty = true;     for (int i = 0; i < el.size(); ++i)       if (t[k / 2 + i]) empty = false, cout << el[i];     if (empty) cout <<  Poor stack! ;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     char ch = getchar();     long long nega = 1;     while (!isdigit(ch)) {       if (ch ==  - ) nega = -1;       ch = getchar();     }     long long ans = 0;     while (isdigit(ch)) {       ans = ans * 10 + ch - 48;       ch = getchar();     }     if (nega == -1) return -ans;     return ans;   }   long long a[40005], b[40005];   long long u[40005], v[40005], n, m;   signed main() {     cin >> n >> m;     for (long long i = 1; i <= n; i++) a[i] = read();     for (long long j = 1; j <= m; j++) b[j] = read();     vector<long long> s;     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= m; j++) {         s.push_back(a[i] + b[j]);         u[a[i] + b[j] + 20000] |= (1LL << (i - 1));         v[a[i] + b[j] + 20000] |= (1LL << (j - 1));       }     }     sort(s.begin(), s.end());     s.erase(unique(s.begin(), s.end()), s.end());     long long ans = 0;     for (long long i : s) {       for (long long j : s) {         long long r = u[i + 20000] | u[j + 20000],                   s = v[i + 20000] | v[j + 20000];         ans = max(ans, 0LL + __builtin_popcountll(r) + __builtin_popcountll(s));       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline bool uin(T& a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   inline bool uax(T& a, T b) {     return a < b ? (a = b, true) : false;   }   const int nax = 2e5 + 10;   vector<int> offer[nax];   int K[nax];   int N, M;   bool can(int day) {     vector<int> last(N, -1);     for (int i = 0; i <= min(day, nax - 1); ++i) {       for (int x : offer[i]) {         last[x] = i;       }     }     vector<int> need(K, K + N);     vector<int> temp_offer[nax];     for (int i = 0; i < N; ++i)       if (last[i] != -1) temp_offer[last[i]].push_back(i);     int money = 0;     for (int d = 0; d <= day; ++d) {       ++money;       if (d > 2e5) continue;       for (int x : temp_offer[d]) {         if (money >= need[x]) {           money -= need[x];           need[x] = 0;         } else {           need[x] -= money;           money = 0;           break;         }       }     }     for (int i = 0; i < N; ++i)       ;     ;     return money >= 2 * accumulate(need.begin(), need.end(), 0);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> N >> M;     for (int i = 0; i < N; ++i) cin >> K[i];     for (int d, t, i = 0; i < M; ++i) {       cin >> d >> t;       --d, --t;       offer[d].push_back(t);     }     for (int i = 0; i < 10; ++i)       ;     int l = 0, r = 4e5;     while (l < r) {       int m = (l + r) / 2;       ;       if (can(m))         r = m;       else         l = m + 1;     }     cout << r + 1 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   struct modint {     int n;     modint() : n(0) {}     modint(int n) : n(n) {}   };   modint operator+(modint a, modint b) {     return modint((a.n += b.n) >= mod ? a.n - mod : a.n);   }   modint operator*(modint a, modint b) { return modint(1LL * a.n * b.n % mod); }   bool operator<(modint a, modint b) { return a.n < b.n; }   bool operator!=(modint a, modint b) { return a.n != b.n; }   const int S = 4;   using modints = array<modint, S>;   modints operator+(modints a, modints b) {     modints ret;     for (int i = 0; i < S; i++) {       ret[i] = a[i] + b[i];     }     return ret;   }   modints operator*(modints a, modints b) {     modints ret;     for (int i = 0; i < S; i++) {       ret[i] = a[i] * b[i];     }     return ret;   }   bool operator<(modints a, modints b) {     for (int i = 0; i < S; i++) {       if (a[i] != b[i]) return a[i] < b[i];     }     return false;   }   const int N = 1e5;   int n;   vector<int> g[N];   vector<int> gg[N];   modints rnd[N];   int height[N];   vector<int> h;   modints val[N];   modints one;   map<modints, int> mp;   pair<int, int> ans;   int cnt = 0;   void add(modints a) {     if (mp[a]++ == 0) {       cnt++;     }   }   void del(modints a) {     if (mp[a]-- == 1) {       cnt--;     }     assert(mp[a] >= 0);   }   void dfs(int u, int p) {     for (int v : g[u])       if (v != p) {         dfs(v, u);         height[u] = max(height[u], height[v] + 1);       }     val[u] = one;     for (int v : g[u])       if (v != p) {         val[u] = val[u] * (rnd[height[u]] + val[v]);       }     add(val[u]);   }   void dfs2(int u, int p) {     auto tmp = val[u];     del(tmp);     int n = g[u].size();     h.clear();     h.push_back(0);     for (int v : g[u]) {       h.push_back(height[v] + 1);     }     sort(h.rbegin(), h.rend());     int h0 = h[0];     int h1 = h[1];     modints L0 = one;     modints L1 = one;     vector<modints> R0(n);     vector<modints> R1(n);     R0[n - 1] = one;     R1[n - 1] = one;     for (int i = n - 2; i >= 0; i--) {       R0[i] = R0[i + 1] * (rnd[h0] + val[g[u][i + 1]]);       R1[i] = R1[i + 1] * (rnd[h1] + val[g[u][i + 1]]);     }     ans = max(ans, make_pair(cnt, u));     for (int i = 0; i < n; i++) {       int v = g[u][i];       if (height[v] + 1 != h0) {         height[u] = h0;         val[u] = L0 * R0[i];       } else {         height[u] = h1;         val[u] = L1 * R1[i];       }       L0 = L0 * (rnd[h0] + val[v]);       L1 = L1 * (rnd[h1] + val[v]);       if (v == p) continue;       add(val[u]);       dfs2(v, u);       del(val[u]);     }     add(tmp);   }   int main() {     mt19937 mt(time(NULL) ^ 1234567);     uniform_int_distribution<int> uni(0, mod - 1);     for (int i = 0; i < N; i++) {       for (int j = 0; j < S; j++) {         rnd[i][j] = uni(mt);       }     }     for (int i = 0; i < S; i++) {       one[i] = 1;     }     cin >> n;     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d %d , &u, &v);       u--;       v--;       g[u].push_back(v);       g[v].push_back(u);     }     if (n == 1) {       cout << 1 << endl;       return 0;     }     dfs(0, -1);     dfs2(0, -1);     cout << ans.second + 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, ta;     cin >> a >> ta;     int b, tb, h = 0, m = 0, num = 0;     int totmin;     cin >> b >> tb;     string s;     cin >> s;     for (int i = 0; i < 2; i++) {       h = h * 10 + (s[i] -  0 );     }     for (int i = 3; i < 5; i++) {       m = m * 10 + (s[i] -  0 );     }     totmin = h * 60 + m;     for (int i = 5 * 60; i <= 1439; i += b) {       if ((i <= totmin && i + tb > totmin) || (i >= totmin && i < totmin + ta))         num++;     }     cout << num;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = (1ll << 32);   const int LOGN = 14;   const long long INF = (1ll << 62);   long long __gcd(long long a, long long b) {     if (b == 0) return a;     return __gcd(b, a % b);   }   bool comp(pair<int, unordered_set<int> >& a,             pair<int, unordered_set<int> >& b) {     return a.second.size() > b.second.size();   }   int main() {     std ::ios_base ::sync_with_stdio(false);     cin.tie(NULL), cout.tie(NULL);     int n, m;     cin >> n >> m;     vector<pair<int, unordered_set<int> > > a(n);     int sz;     int ct = 0;     int ct_p1 = 0;     for (int i = 0; i < n; ++i) {       cin >> sz;       ct += sz;       a[i].first = i;       int x;       for (int j = 0; j < sz; ++j) {         cin >> x;         a[i].second.insert(x);       }     }     ct_p1 = ct % n;     ct /= n;     sort(a.begin(), a.end(), comp);     int l = 0;     int r = n - 1;     vector<vector<int> > ans;     while (l < r) {       int req_l_size = ct;       int req_r_size = ct;       if (l < ct_p1) req_l_size++;       if (r < ct_p1) req_r_size++;       vector<int> temp;       for (auto it : a[l].second) {         if ((int)a[l].second.size() - (int)temp.size() == req_l_size) break;         if (a[r].second.size() == req_r_size) break;         if (a[r].second.find(it) == a[r].second.end()) {           temp.push_back(it);           a[r].second.insert(it);           vector<int> x;           x.push_back(a[l].first);           x.push_back(a[r].first);           x.push_back(it);           ans.push_back(x);         }       }       for (int i = 0; i < temp.size(); ++i) a[l].second.erase(temp[i]);       if (a[r].second.size() == req_r_size) r--;       if (a[l].second.size() == req_l_size) l++;     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); ++i)       cout << ans[i][0] + 1 <<     << ans[i][1] + 1 <<     << ans[i][2] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     string s1, s2;     cin >> s1 >> s2;     int temp;     vector<int> index;     for (int i = 0; i < t; i++) {       temp = -1;       if (s1[i] == s2[i]) {         continue;       }       for (int j = i + 1; j < t; j++) {         if (s1[j] == s2[i]) {           temp = j;           break;         }       }       if (temp == -1) {         printf( %d , temp);         return 0;       }       for (int j = temp - 1; j >= i; j--) {         swap(s1[j], s1[j + 1]);         index.push_back(j + 1);       }     }     printf( %d n , index.size());     for (int i = 0; i < index.size(); i++) {       printf( %d  , index[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   const long long inf = 9223372036854775807;   const long long mod = 1000000007;   const double pi = acos(-1);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     long long n, k;     cin >> n >> k;     long long val = n - (n % 2);     if (n == 1) {       if (k == 0) {         cout << 1;       } else {         cout << -1;       }       return 0;     }     if (val / 2 > k) {       cout << -1;     } else {       long long x = (val / 2 - 1);       cout << k - x <<     << (k - x) * 2 <<    ;       set<long long> s;       s.insert(k - x);       s.insert((k - x) * 2);       long long t = 2;       for (int i = 0; i < x; i++) {         if (s.find(t) == s.end() && s.find(t + 1) == s.end()) {           cout << t <<     << t + 1 <<    ;           s.insert(t);           s.insert(t + 1);           t += 2;         } else {           t += 2;           i--;         }       }       t += 2;       if (n % 2 != 0) {         while (t == (k - x) || t == (k - x) * 2) {           t++;         }         cout << t;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool ckmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   void solve() {     int n, k;     cin >> n >> k;     vector<int> a(n);     for (int i = 0; i < (int)(n); ++i) cin >> a[i];     set<int> st;     vector<int> ans;     for (int i = 0; i < (int)(n); ++i) {       if (st.find(a[i]) == st.end()) {         ans.push_back(i + 1);       }       st.insert(a[i]);     }     if (ans.size() < k)       cout <<  NO ;     else {       cout <<  YES  <<   n ;       for (int i = 0; i < (int)(k); ++i) cout << ans[i] <<    ;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.precision(10);     int T = 1;     while (T--) {       solve();       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 100;   const int MX = 200503;   int N, M, k;   int arr[MX];   int cnt[MX];   vector<int> G[MX];   int vis[MX];   vector<int> sr;   void dfs(int x) {     vis[x] = 1;     for (int i = 0; i < G[x].size(); i++) {       int ch = G[x][i];       if (vis[ch] == 1) {         sr.push_back(ch);       } else if (!vis[ch])         dfs(ch);     }     vis[x] = 2;   }   int get(int x, int p) {     int ret = arr[x];     vis[x] = 1;     for (int i = 0; i < G[x].size(); i++) {       int ch = G[x][i];       if (vis[ch]) continue;       ret = min(ret, get(ch, x));     }     return ret;   }   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) {       scanf( %d , &arr[i]);     }     for (int i = 1; i <= N; i++) {       int x;       scanf( %d , &x);       G[i].push_back(x);     }     long long an = 0;     for (int i = 1; i <= N; i++)       if (vis[i] == 0) dfs(i);     memset(vis, 0, sizeof vis);     for (int i = 0; i < sr.size(); i++) an += get(sr[i], -1);     cout << an <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long nChooseR(int n, int k);   long long gcd(long long a, long long b);   vector<string> split(string target, char c);   bool isPrime(long long g);   long long n, k, r, l, t, x, y, m, a[100003];   long long ans;   int main() {     string s;     cin >> s;     reverse(((s).begin()), ((s).end()));     ans = s[0] ==  1 ;     n = ((int)((s).size()));     x = 1;     for (int i = 0; i < (int)(n - 1); i++) {       x *= 4;       x %= 1000000007;       if (s[i + 1] ==  1 )         ans = ans * 2 + x;       else         ans *= 2;       ans %= 1000000007;     }     cout << ans;     return 0;   }   long long nChooseR(int n, int k) {     if (k > n) return 0;     if (k * 2 > n) k = n - k;     if (k == 0) return 1;     long long result = n;     for (int i = 2; i <= k; ++i) {       result *= (n - i + 1);       result /= i;     }     return result;   }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   vector<string> split(string target, char c) {     string d =   ;     vector<string> arr;     for (auto n : target) {       if (n != c)         d += n;       else if (d !=   )         arr.push_back(d), d =   ;     }     if (d !=   ) arr.push_back(d), d =   ;     return arr;   }   bool isPrime(long long g) {     if ((g % 2 == 0 && g > 2) || g == 1) return 0;     for (int i = 3; i * i <= g; i += 2)       if (g % i == 0) return 0;     return 1;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   vector<int> v;   vector<vector<int>> g;   int in[N], out[N], col[N], is[N], dp[18][N], depth[N], z;   struct node {     int l, r, id;     node(int a = 0, int b = 0, int c = 0) {       l = a;       r = b;       id = c;     }     bool operator<(const node& e) const {       int a = l / z, b = e.l / z;       if (a != b) return a < b;       if (a & 1) return r > e.r;       return r < e.r;     }   };   vector<node> q;   void dfs(int u, int p) {     dp[0][u] = p;     in[u] = v.size();     v.push_back(u);     for (int i = 1; i < 18; i++)       dp[i][u] = dp[i - 1][u] + 1 ? dp[i - 1][dp[i - 1][u]] : -1;     for (auto i : g[u])       if (i != p) depth[i] = depth[u] + 1, dfs(i, u);     out[u] = v.size();     v.push_back(u);   }   int lca(int a, int b) {     if (depth[a] < depth[b]) swap(a, b);     for (int i = 17; i + 1; i--)       if (depth[a] - (1 << i) >= depth[b]) a = dp[i][a];     if (a == b) return a;     for (int i = 17; i + 1; i--)       if (dp[i][a] != dp[i][b]) a = dp[i][a], b = dp[i][b];     return dp[0][a];   }   int main() {     int n;     scanf( %d , &n);     g.resize(n);     for (int i = 0; i < n; i++) scanf( %d , is + i);     for (int i = 0; i < n; i++) scanf( %d , col + i);     for (int i = 1; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       g[--a].push_back(--b);       g[b].push_back(a);     }     dfs(0, -1);     scanf( %d , &n);     z = sqrt(v.size()) + 1;     for (int i = 0; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       --a;       --b;       if (in[a] > in[b]) swap(a, b);       q.push_back(node(in[a] + 1, in[b], i));     }     sort(q.begin(), q.end());     long long ans[N] = {}, temp = 0, freq[N] = {};     int l = 0, r = -1;     unordered_map<int, int> mp[2];     for (auto i : q) {       if (i.l - 1 == i.r) continue;       while (r < i.r) {         r++;         int a = is[v[r]];         int b = col[v[r]];         if (freq[v[r]]++) {           temp -= mp[!a][b];           mp[a][b]--;         } else {           temp += mp[!a][b];           mp[a][b]++;         }       }       while (r > i.r) {         int a = is[v[r]];         int b = col[v[r]];         if (--freq[v[r]]) {           temp += mp[!a][b];           mp[a][b]++;         } else {           temp -= mp[!a][b];           mp[a][b]--;         }         r--;       }       while (l < i.l) {         int a = is[v[l]];         int b = col[v[l]];         if (--freq[v[l]]) {           temp += mp[!a][b];           mp[a][b]++;         } else {           temp -= mp[!a][b];           mp[a][b]--;         }         l++;       }       while (l > i.l) {         l--;         int a = is[v[l]];         int b = col[v[l]];         if (freq[v[l]]++) {           temp -= mp[!a][b];           mp[a][b]--;         } else {           temp += mp[!a][b];           mp[a][b]++;         }       }       int LCA = lca(v[i.l - 1], v[i.r]);       int lol = mp[!is[LCA]][col[LCA]];       ans[i.id] = temp + lol;     }     for (int i = 0; i < q.size(); i++) printf( %lld n , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   int n, ls, tp, cx, yy, qq;   char s[64];   string ans, cur, st[55555][2], tt;   bool quot, found;   int main() {     scanf( %d n , &n);     tp = -1;     found = false;     qq = 0;     for (int _ = 0; _ < n; ++_) {       gets(s);       ls = strlen(s);       quot = false;       cur =   ;       for (int i = 0; i < ls; ++i)         if (quot) {           if (s[i] ==    )             quot = false;           else             cur += s[i];         } else {           if (s[i] ==    )             quot = true;           else if (s[i] !=    )             cur += s[i];         }       if (!cur.find( try )) {         tp += !found;         qq += found;       } else if (!cur.find( catch )) {         if (qq) {           --qq;           continue;         }         if (found) {           st[tp][0] =   ;           cx = 6;           while (cur[cx] !=  , ) st[tp][0] += cur[cx++];           ++cx;           st[tp][1] =   ;           while (cur[cx] !=  ) ) st[tp][1] += cur[cx++];           if (!tp) break;         }         --tp;       } else if (!cur.find( throw )) {         found = true;         yy = tp;         cx = 6;         tt =   ;         while (cur[cx] !=  ) ) tt += cur[cx++];       }     }     ans =  Unhandled Exception ;     for (int i = yy; i >= 0; --i)       if (st[i][0] == tt) {         ans = st[i][1];         break;       }     printf( %s , ans.c_str());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxL = 70;   int mod = 1e9 + 7;   long long mod1 = 1e9 + 7;   const int inf = 1.2e18;   const int maxn = 6e5 + 100;   const int baze = 330;   const int base = 3;   int from[maxn];   int to[maxn];   int w[maxn];   int dis[maxn];   int head[maxn];   int sdfgf[maxn];   int backup[maxn];   int chiz[maxn];   int eof, source = maxn - 1, sink = maxn - 2;   void add_edge(int u, int v, int W) {     from[eof] = u, to[eof] = v, w[eof] = W, sdfgf[eof] = head[u], head[u] = eof++;     swap(u, v);     W = 0;     from[eof] = u, to[eof] = v, w[eof] = W, sdfgf[eof] = head[u], head[u] = eof++;   }   bool bfs() {     int st = 0, en = 1;     chiz[0] = source;     memset(dis, 63, sizeof dis);     dis[source] = 0;     while (st < en) {       int v = chiz[st++];       for (int e = head[v]; ~e; e = sdfgf[e])         if (w[e] && dis[to[e]] > dis[v] + 1) {           dis[to[e]] = dis[v] + 1;           chiz[en++] = to[e];           if (to[e] == sink) return true;         }     }     return false;   }   int dfs(int v, int mn = 1000000) {     if (!mn || v == sink) return mn;     int ret = 0;     for (int &e = head[v]; ~e; e = sdfgf[e])       if (dis[to[e]] == dis[v] + 1) {         int x = dfs(to[e], min(mn, w[e]));         ret += x;         w[e] -= x;         w[e ^ 1] += x;         mn -= x;         if (mn == 0) break;       }     return ret;   }   int flow() {     memcpy(backup, head, sizeof head);     int ret = 0;     while (bfs()) {       ret += dfs(source);       memcpy(head, backup, sizeof head);     }     return ret;   }   int ar[60];   string t[maxn];   int pos[maxn];   int n;   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     memset(head, -1, sizeof head);     map<string, int> mp;     mp[ S ] = 0;     mp[ M ] = 1;     mp[ L ] = 2;     mp[ XL ] = 3;     mp[ XXL ] = 4;     mp[ XXXL ] = 5;     for (int i = 0; i < 6; i++) cin >> ar[i], add_edge(source, i, ar[i]);     cin >> n;     vector<int> vc;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       t[i] = s;       pos[i] = ((int)((s).size()));       if (s.find( , ) < ((int)((s).size()))) {         int x = s.find( , );         pos[i] = x;         vc.push_back(eof);         add_edge(mp[s.substr(0, x)], i + 10, 1);         add_edge(mp[s.substr(x + 1, ((int)((s).size())))], i + 10, 1);         add_edge(i + 10, sink, 1);       } else         vc.push_back(eof), add_edge(mp[s], sink, 1);     }     int ans = flow();     if (ans != n) return cout <<  NO  << endl, 0;     cout <<  YES  << endl;     int hlp = 0;     for (int x : vc) {       if (w[x] == 0)         cout << t[hlp].substr(0, pos[hlp]) <<   n ;       else         cout << t[hlp].substr(pos[hlp] + 1, ((int)((t[hlp]).size()))) <<   n ;       hlp++;     }   }


#include <bits/stdc++.h>   using namespace std;   long long mod1(long long x) {     if (x >= 0) {       return x;     }     return -x;   }   vector<long long> countDigit(long long n) {     vector<long long> ret;     while (n != 0) {       ret.push_back(n % 10);       n = n / 10;     }     return ret;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm1(long long a, long long b) { return (a / gcd(a, b)) * b; }   bool prime[1000000];   void SieveOfEratosthenes(long long n) {     memset(prime, true, sizeof(prime));     prime[1] = false;     for (long long p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (long long i = p * p; i <= n; i += p) prime[i] = false;       }     }   }   bool isPowerOfTwo(long long n) {     if (n == 0) return false;     return (ceil(log2(n)) == floor(log2(n)));   }   bool PowerOfFour(long long num) {     if (num <= 0) return false;     while (num != 1) {       if (num % 4 != 0) return false;       num = num / 4;     }     return true;   }   bool compare(pair<long long, long long> p1, pair<long long, long long> p2) {     if (p1.first != p2.first) {       return p1.first > p2.first;     } else {       p1.second > p2.second;     }   }   bool compare1(pair<long long, long long> p1, pair<long long, long long> p2) {     if (p1.second != p2.second) {       return p1.second < p2.second;     } else {       p1.first < p2.first;     }   }   bool isPalindrome(string str) {     long long l = 0;     long long h = str.size() - 1;     while (h > l) {       if (str[l++] != str[h--]) {         return false;       }     }     return true;   }   vector<long long> primef(long long n) {     vector<long long> v;     if (n == 1) {       return v;     }     while (n % 2 == 0) {       v.push_back(2);       n = n / 2;     }     for (long long i = 3; i <= sqrt(n); i = i + 2) {       while (n % i == 0) {         v.push_back(i);         n = n / i;       }     }     if (n > 2) v.push_back(n);     return v;   }   long long mod = 1000000007;   long long fact1(long long x) {     if (x < 2) {       return 1;     }     return (x * fact1(x - 1)) % mod;   }   long long power1(long long x, long long y) {     long long r = 1;     while (y > 0) {       r = (r % mod * x % mod) % mod;       y--;     }     return r;   }   bool isp(long long x) {     if (x >= 0) {       long long sr = sqrt(x);       return (sr * sr == x);     }     return false;   }   bool isPri(long long n) {     if (n <= 1) return false;     for (long long i = 2; i < n; i++)       if (n % i == 0) return false;     return true;   }   long long power2(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long gcdExtended(long long a, long long b, long long *x, long long *y) {     if (a == 0) {       *x = 0, *y = 1;       return b;     }     long long x1, y1;     long long gcd = gcdExtended(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     return gcd;   }   long long modInverse(long long b, long long m) {     long long x, y;     long long g = gcdExtended(b, m, &x, &y);     if (g != 1) return -1;     return (x % m + m) % m;   }   long long ask(long long val) {     cout << val << endl;     fflush(stdout);     long long x;     cin >> x;     return x;   }   void solve() {     long long n;     cin >> n;     string s;     cin >> s;     long long ret = INT_MAX;     for (long long i = 0; i < 26; i++) {       long long l = 0;       long long r = n - 1;       long long c = 0;       while (l <= r) {         if (s[l] == s[r]) {           l++;           r--;           continue;         }         if (s[l] == i +  a ) {           l++;           c++;           continue;         }         if (s[r] == i +  a ) {           r--;           c++;           continue;         }         c = INT_MAX;         break;       }       ret = min(ret, c);     }     if (ret == INT_MAX) {       cout <<  -1  << endl;     } else {       cout << ret << endl;     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long base, long long pow, long long mo) {     long long res = 1;     while (pow) {       if (pow % 2 != 0) res = (res * base) % mo;       base = (base * base) % mo;       pow /= 2;     }     return res;   }   long long inv(long long i) { return power(i, 1000000007 - 2, 1000000007); }   std::string str =  All Good Till Here ;   void solve() {     long long i, j, x, n;     cin >> n;     long long a[n], p[n];     for (long long c1 = 0; c1 < n; c1++) cin >> a[c1];     ;     for (long long i = 0; i < n; i++) {       p[a[i] - 1] = i;     }     long long ans = 0, max2 = 1;     for (long long i = 1; i < n; i++) {       if (p[i] > p[i - 1]) {         max2++;       } else {         ans = max(max2, ans);         max2 = 1;       }     }     ans = max(max2, ans);     cout << n - ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long tt;     tt = 1;     while (tt--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 100010;   const int N = 100010;   struct e {     int v;     e *nxt;   } es[N << 1], *fir[N];   map<pair<int, int>, int> mp;   struct node {     int ls, rs;     int l, r;     int sum;     int mid() { return (l + r) >> 1; }   } nodes[N << 2];   int n, en, val[N];   int que[N], par[N], dep[N], root[N], seg[N], st[N], ed[N], top[N], sons[N],       id[N];   int ln, cnt, tr;   inline void init() {     en = 0;     memset(fir, 0, sizeof(fir));   }   inline void add_e(int u, int v) {     es[en].v = v;     es[en].nxt = fir[u];     fir[u] = &es[en++];   }   inline void newNode(int &id, int l, int r) {     nodes[cnt].ls = nodes[cnt].rs = -1;     nodes[cnt].l = l;     nodes[cnt].r = r;     id = cnt++;   }   void build(int &id, int l, int r) {     newNode(id, l, r);     if (l + 1 >= r) {       nodes[id].sum = 1;       return;     }     int mid = (l + r) >> 1;     build(nodes[id].ls, l, mid);     build(nodes[id].rs, mid, r);     nodes[id].sum = nodes[nodes[id].ls].sum + nodes[nodes[id].rs].sum;   }   void initTree() {     int l, r, u, v, i;     e *cur;     l = r = 0;     tr = 1;     que[r++] = tr;     par[tr] = -1;     dep[tr] = 0;     while (l != r) {       u = que[l++];       for (cur = fir[u]; cur; cur = cur->nxt) {         if ((v = cur->v) != par[u]) {           que[r++] = v;           par[v] = u;           dep[v] = dep[u] + 1;         }       }     }     for (i = 1; i <= n; i++) {       sons[i] = 1;       id[i] = -1;     }     for (i = r - 1; i >= 0; i--) {       u = que[i];       if (par[u] >= 0) {         sons[par[u]] += sons[u];       }     }     l = r = 0;     que[r++] = tr;     ln = cnt = 0;     while (l != r) {       u = que[l++];       st[ln] = dep[u];       top[ln] = u;       while (u >= 0) {         id[u] = ln;         ed[ln] = dep[u];         seg[dep[u]] = u;         int best;         for (cur = fir[u], best = -1; cur; cur = cur->nxt) {           if (id[v = cur->v] == -1) {             if (best == -1 || (best >= 0 && sons[v] > sons[best])) {               best = v;             }           }         }         if (best >= 0) {           for (cur = fir[u]; cur; cur = cur->nxt) {             if (id[v = cur->v] == -1 && best != v) {               que[r++] = v;             }           }         }         u = best;       }       root[ln] = -1;       build(root[ln], st[ln], ed[ln]);       ln++;     }   }   int S;   void lqry(int &id, int ql, int qr) {     if (id == -1) return;     if (ql == qr) return;     if (ql <= nodes[id].l && nodes[id].r <= qr) {       S += nodes[id].sum;       if (S > inf) S = inf;       return;     }     if (nodes[id].l + 1 == nodes[id].r) {       S += nodes[id].sum;       if (S > inf) S = inf;       return;     }     int mid = (nodes[id].l + nodes[id].r) >> 1;     if (ql < mid) {       lqry(nodes[id].ls, ql, qr);     }     if (qr > mid) {       lqry(nodes[id].rs, ql, qr);     }   }   void update(int id, int x, int y, int val) {     if (id == -1) return;     if (nodes[id].l + 1 == nodes[id].r) {       nodes[id].sum = val;       return;     }     int mid = (nodes[id].l + nodes[id].r) >> 1;     if (mid <= x)       update(nodes[id].rs, x, y, val);     else if (mid >= y)       update(nodes[id].ls, x, y, val);     nodes[id].sum = nodes[nodes[id].ls].sum + nodes[nodes[id].rs].sum;     if (nodes[id].sum > inf) nodes[id].sum = inf;   }   void qry(int u, int v) {     while (id[u] != id[v]) {       if (id[u] > id[v]) {         swap(u, v);       }       int b = id[v];       lqry(root[b], st[b], dep[v]);       v = par[top[b]];       if (mp.find(make_pair(top[b], par[top[b]])) != mp.end())         S += val[mp[make_pair(top[b], par[top[b]])]];       else         S += val[mp[make_pair(par[top[b]], top[b])]];       if (S > inf) S = inf;     }     if (dep[u] > dep[v]) {       swap(u, v);     }     lqry(root[id[u]], dep[u], dep[v]);   }   struct ee {     int x, y;   } edge[100010];   int main() {     int m, x, y, ty;     scanf( %d , &n);     init();     for (int i = 1; i < n; i++) {       scanf( %d%d , &x, &y);       mp[make_pair(x, y)] = i;       val[i] = 1;       edge[i].x = x;       edge[i].y = y;       add_e(x, y);       add_e(y, x);     }     initTree();     scanf( %d , &m);     for (int i = 0; i < m; i++) {       scanf( %d , &ty);       if (ty == 3) {         scanf( %d%d , &x, &y);         S = 0;         qry(x, y);         if (S >= inf)           printf( -1 n );         else           printf( %d n , S);       } else if (ty == 1) {         scanf( %d , &x);         int u = edge[x].x;         int v = edge[x].y;         val[x] = 1;         if (dep[u] > dep[v]) {           swap(u, v);         }         if (id[u] == id[v]) update(root[id[u]], dep[u], dep[u], 1);       } else {         scanf( %d , &x);         int u = edge[x].x;         int v = edge[x].y;         val[x] = inf;         if (dep[u] > dep[v]) {           swap(u, v);         }         if (id[u] == id[v]) update(root[id[u]], dep[u], dep[v], inf);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     bitset<6> a(n);     string s = a.to_string();     swap(s[1], s[5]);     swap(s[2], s[3]);     bitset<6> b(s);     cout << static_cast<int>(b.to_ulong()) <<   n ;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   int main() {     int n;     scanf( %d , &n);     printf( %d , n);     for (int i = 1; i < n; i++) printf(  %d , i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int tux;     cin >> tux;     int foo, bar, baz, quz, pur, oo;     foo = bar = baz = 0;     quz = 1;     while (tux) {       cin >> pur;       foo += pur;       bar++;       if (foo * quz > bar * baz) {         baz = foo;         quz = bar;       }       tux--;     }     cout.precision(5);     cout << fixed << (baz * 1. / quz);     return 0;   }


#include <bits/stdc++.h>      using namespace std;      typedef long long ll;   typedef long double ld;   typedef pair<int, int> pii;   typedef pair<ll, ll> pll;   typedef vector<int> vi;   typedef vector<ll> vl;   typedef vector<pii> vii;   typedef vector<vi> vvi;   typedef vector<pll> vll;   typedef vector<vl> vvl;      #define fori(i, n) for (int i = 0; i < n; i++)   #define ford(i, n) for (int i = n - 1; i >= 0; i--)   #define rep(i, a, b) for (int i = a; i <= b; i++)   #define repd(i, a, b) for (int i = a; i >= b; i--)   #define trav(x, a) for (auto &x : a)   #define all(x) (x).begin(), (x).end()   #define pb push_back   #define eb emplace_back   #define endl   n    #define sz(a) (int)(a).size()   #define fi first   #define se second      clock_t time_p = clock();   void time_taken()   {       time_p = clock() - time_p;       cerr <<  Time Taken :   << (float)(time_p) / CLOCKS_PER_SEC <<   n ;   }      const ll mod = 1e9 + 7;   const ll INF = 1e18;      int main()   {       ios_base::sync_with_stdio(false), cin.tie(nullptr);          int n, d;       cin >> n >> d;          vi a(n);       fori(i, n) cin >> a[i];          vector<vector<ld>> dp(n + 1, vector<ld>(10, -1));       vvi prv(n + 1, vi(10));       vvi taken(n + 1, vi(10));       dp[0][1] = 0;          for (int i = 0; i < n; i++)       {           for (int j = 0; j < 10; j++)           {               if (dp[i][j] == -1)                   continue;               int to = (j * a[i]) % 10;               ld maybe = dp[i][j] + log2l(a[i]);               if (maybe > dp[i + 1][to])               {                   dp[i + 1][to] = maybe;                   taken[i + 1][to] = 1;                   prv[i + 1][to] = j;               }                  to = j;               maybe = dp[i][j];               if (maybe > dp[i + 1][to])               {                   dp[i + 1][to] = maybe;                   taken[i + 1][to] = 0;                   prv[i + 1][to] = j;               }           }       }          if (dp[n][d] == -1)       {           cout <<  -1  << endl;           return 0;       }          int i = n, j = d;          vi ans;       while (i)       {           if (taken[i][j])           {               ans.pb(a[i - 1]);           }           j = prv[i][j];           i--;       }          if(sz(ans) == 0){           cout << -1 << endl;           return 0;       }          cout << sz(ans) << endl;       for (int x : ans)       {           cout << x <<    ;       }       cout << endl;          time_taken();       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, sz, timer;   int p[1000005];   vector<int> v[1000005];   int tin[1000005], tout[1000005];   int t[4000005], tt[4000005];   int depth[1000005];   int a[1000005];   pair<int, int> q[1000005];   bool used[1000005];   void dfs(int x, int y = 0) {     used[x] = true;     tin[x] = ++timer;     depth[x] = depth[y] + 1;     for (int i = 0; i < v[x].size(); ++i) {       int to = v[x][i];       dfs(to, x);     }     tout[x] = timer;     return;   }   void update(int x, int y) {     x += sz - 1;     t[x] = y;     x >>= 1;     while (x) {       t[x] = max(t[x + x], t[x + x + 1]);       x >>= 1;     }     return;   }   int get(int l, int r, int ll, int rr, int x) {     if (l > r || ll > r || l > rr || ll > rr) return 0;     if (l >= ll && r <= rr) return t[x];     int mid = (l + r) >> 1;     return max(get(l, mid, ll, rr, x + x), get(mid + 1, r, ll, rr, x + x + 1));   }   void update2(int x, int y) {     x += sz - 1;     tt[x] = y;     x >>= 1;     while (x) {       tt[x] = max(tt[x + x], tt[x + x + 1]);       x >>= 1;     }     return;   }   int get_pred(int x) {     if (x == p[x]) return x;     return p[x] = get_pred(p[x]);   }   void update_val(int x) {     int val = get(1, sz, tin[x], tout[x], 1) - depth[x] + 1;     update2(x, val);     return;   }   void add_vertex(int x) {     for (int i = 0; i < v[x].size(); ++i) {       int to = v[x][i];       update2(to, 0);       to = get_pred(to);       p[to] = x;     }     update(tin[x], depth[x]);     update_val(x);     return;   }   void del_vertex(int x) {     update(tin[x], 0);     x = get_pred(x);     update_val(x);     return;   }   int main(int argc, const char* argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     q[0] = {1e9, n + 1};     for (int i = n; i > 0; --i) {       while (sz > 0 && q[sz].first <= a[i]) --sz;       v[q[sz].second].push_back(i);       q[++sz] = {a[i], i};     }     for (int i = n + 1; i > 0; --i)       if (!used[i]) dfs(i);     for (int i = 1; i <= n + 1; ++i) p[i] = i;     sz = 1;     while (sz < n + 1) sz += sz;     for (int i = 1; i <= m; ++i) {       add_vertex(i);     }     cout << tt[1] <<    ;     for (int i = m + 1; i <= n; ++i) {       add_vertex(i);       del_vertex(i - m);       cout << tt[1] <<    ;     }     cout <<   n ;   }


#include <bits/stdc++.h>   int sta[1000001], head, ans[1000001];   char s[1000001];   int main() {     int ans1 = 0, ans2 = 1;     scanf( %s , s);     for (int i = 0; s[i]; ++i) {       if (s[i] ==  ) ) {         if (!head) continue;         head--;         ans[i] = i - sta[head] + 1 + ans[sta[head] - 1];         if (ans1 == ans[i])           ans2++;         else if (ans1 < ans[i]) {           ans1 = ans[i];           ans2 = 1;         }       } else         sta[head++] = i;     }     printf( %d %d , ans1, ans2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, n;   int a[200004];   int main() {     cin >> t;     while (t--) {       cin >> n;       for (int i = 0; i < 2 * n; i++) cin >> a[i];       sort(a, a + 2 * n);       cout << a[n] - a[n - 1] <<   n ;     }     cin >> t;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int T, n, a[30005], b[30005];   long long sum[2];   int main() {     scanf( %d , &T);     while (T--) {       scanf( %d , &n);       for (int i = 1; i <= n; i++) scanf( %d , &a[i]);       a[n + 1] = 0;       for (int i = 1; i <= n + 1; i++) b[i] = a[i] - a[i - 1];       sum[0] = sum[1] = 0;       for (int i = 2; i <= n; i++) {         if (b[i] > 0)           sum[0] += b[i];         else           sum[1] -= b[i];       }       if (b[1] >= sum[1] && -b[n + 1] >= sum[0]) {         printf( YES n );       } else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000000, M = 1000000007, D3 = (M + 1) / 3;   int T, n, m;   int pd[N + 5], pr[N], pn, phi[N + 5];   int f[N + 5], s0[N + 5], s1[N + 5], s2[N + 5];   void init() {     phi[1] = 1;     for (int i = 2; i <= N; i++) {       if (!pd[i]) phi[i] = i - 1, pr[++pn] = i;       for (int j = 1; j <= pn && i * pr[j] <= N; j++) {         pd[i * pr[j]] = pr[j];         if (i % pr[j] == 0) {           phi[i * pr[j]] = phi[i] * pr[j];           break;         } else           phi[i * pr[j]] = phi[i] * phi[pr[j]];       }     }     for (int d = 1; d <= N; d++)       for (int k = d; k <= N; k += d) f[k] += d * phi[k / d];     for (int L = 1; L <= N; L++) {       f[L] =           (((long long)L * L - L - L) % M * L % M -            (long long)(L + 1) * L % M * L % M +            (long long)L * (L + 1) % M * (L + L + 1) % M * D3 % M + 2LL * f[L]) %           M;       if (f[L] < 0) f[L] += M;     }     for (int i = 1; i <= N; i++) {       s0[i] = (s0[i - 1] + (long long)f[i]) % M;       s1[i] = (s1[i - 1] + (long long)i * f[i]) % M;       s2[i] = (s2[i - 1] + (long long)i * i % M * f[i]) % M;     }   }   int main() {     init();     for (scanf( %d , &T); T--;) {       scanf( %d%d , &n, &m);       if (n > m) swap(n, m);       long long ans = (long long)(n + 1) * (m + 1) % M * s0[n] % M;       ans -= (long long)(n + m + 2) * s1[n] % M;       ans += s2[n];       ans = (ans % M + M) % M;       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int n, m;   vector<int> tr[1000005];   vector<int> vr[1000005];   pair<int, int> pr[1000005];   int high;   long long team[1000005], ir[1000005];   int main() {     scanf( %d %d , &n, &m);     int x, y;     for (int i = 0; i < m; i++) {       scanf( %d %d , &x, &y);       if (x < y) swap(x, y);       vr[x].push_back(y);     }     for (int i = 1; i < n + 1; i++) {       scanf( %d , &x);       for (int j = 0; j < x; j++) {         scanf( %d , &y);         tr[i].push_back(y);         high = max(high, y);       }     }     while (1) {       int tot = 0;       for (int i = 1; i < high + 1; i++) team[i] = rng() % 2 + 1;       for (int i = 1; i < n + 1; i++) {         ir[i] = tr[i][rng() % tr[i].size()];         for (int j = 0; j < vr[i].size(); j++) {           if (team[ir[vr[i][j]]] != team[ir[i]]) tot++;         }       }       if (tot >= m / 2 + (m % 2)) break;     }     for (int i = 1; i < n + 1; i++) printf( %d  , ir[i]);     printf(  n );     for (int i = 1; i < high + 1; i++) printf( %d  , team[i]);   }


#include <bits/stdc++.h>   using namespace std;   class segtree {    public:     int val[(1 << 20) * 2];     int le[(1 << 20) * 2];     int ri[(1 << 20) * 2];     void update(int pos, int x) {       val[pos + (1 << 20) - 1] = 0;       le[pos + (1 << 20) - 1] = 1 - x;       ri[pos + (1 << 20) - 1] = x;     }     void up() {       for (int i = (1 << 20) - 2; i >= 0; i--) {         int add = min(le[i * 2 + 1], ri[i * 2 + 2]);         val[i] = val[i * 2 + 1] + val[i * 2 + 2] + add;         le[i] = le[i * 2 + 1] + le[i * 2 + 2] - add;         ri[i] = ri[i * 2 + 1] + ri[i * 2 + 2] - add;       }     }     pair<int, pair<int, int> > query(int a, int b, int k, int l, int r) {       pair<int, pair<int, int> > p = make_pair(0, make_pair(0, 0));       if (r < a || b < l) return p;       if (a <= l && r <= b) {         return make_pair(val[k], make_pair(le[k], ri[k]));       }       pair<int, pair<int, int> > x = query(a, b, k * 2 + 1, l, (l + r) / 2);       pair<int, pair<int, int> > y = query(a, b, k * 2 + 2, (l + r) / 2 + 1, r);       int z = min(x.second.first, y.second.second);       return make_pair(x.first + y.first + z,                        make_pair(x.second.first + y.second.first - z,                                  x.second.second + y.second.second - z));     }   } seg;   char ss[1000005];   int main() {     scanf( %s , &ss);     int n = strlen(ss);     for (int i = 0; i < n; i++) {       seg.update(i, (ss[i] ==  ) ));     }     seg.up();     int q;     scanf( %d , &q);     for (int i = 0; i < q; i++) {       int a, b;       scanf( %d %d , &a, &b);       a--;       b--;       printf( %d n , seg.query(a, b, 0, 0, (1 << 20) - 1).first * 2);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int a, b, c, d;       cin >> a >> b >> c >> d;       if ((a + b) % 2 == 0) {         cout <<  Tidak Tidak ;         if (b || c)           cout <<   Ya ;         else           cout <<   Tidak ;         if (a || d)           cout <<   Ya ;         else           cout <<   Tidak ;       } else {         if (a || d)           cout <<  Ya ;         else           cout <<   Tidak ;         if (b || c)           cout <<   Ya ;         else           cout <<   Tidak ;         cout <<   Tidak Tidak ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e6 + 10;   int n, ans;   void swap(int &x, int &y) {     int t = x;     x = y;     y = t;   }   int main() {     cin >> n;     vector<char> x(n), y(n);     for (auto &i : x) cin >> i;     for (auto &i : y) cin >> i;     for (int i = 0; i < n - 1; ++i) {       if (x[i] == y[i]) continue;       if (x[i + 1] == y[i + 1]) {         ans++;         continue;       }       if (x[i] == y[i + 1] && x[i + 1] == y[i])         swap(x[i], x[i + 1]), ans++;       else         ans++;     }     if (x[n - 1] != y[n - 1]) ans++;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const N = 202000;   set<int> s;   set<int>::iterator it;   int edg[N];   vector<int> g[N];   int ans[N];   int cur = 1;   int vis[N];   void dfs(int node) {     vis[node] = 1;     ans[cur]++;     vector<int> send;     for (it = s.begin(); it != s.end();) {       if (!binary_search(g[node].begin(), g[node].end(), *it)) {         send.push_back(*it);         s.erase(it++);       } else         it++;     }     for (int el : send) dfs(el);   }   int main() {     int n, e;     scanf( %d%d , &n, &e);     for (int i = 1; i <= n; ++i) s.insert(i);     for (int i = 0; i < e; ++i) {       int temp, temp1;       scanf( %d%d , &temp, &temp1);       edg[temp]++;       edg[temp1]++;       g[temp].push_back(temp1);       g[temp1].push_back(temp);     }     vector<pair<int, int>> go;     for (int i = 1; i <= n; i++) {       go.push_back(make_pair(edg[i], i));       sort(g[i].begin(), g[i].end());     }     sort(go.begin(), go.end());     for (auto el : go) {       if (vis[el.second]) continue;       s.erase(el.second);       ans[0]++;       dfs(el.second);       cur++;     }     cout << ans[0] <<   n ;     sort(ans + 1, ans + ans[0] + 1);     for (int i = 1; i <= ans[0]; i++) {       cout << ans[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, x, m, count;     scanf( %d %d , &n, &m);     for (x = 1, count = 0; x <= n; x++) {       if (m % x == 0 && (m / x) <= n) {         count = count + 1;       }     }     printf( %d , count);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int tt;     cin >> tt;     while (tt--) {       int n;       cin >> n;       vector<int> a(n);       for (int i = 0; i < n; ++i) {         cin >> a[i];       }       int ans = 0;       sort(a.begin(), a.end());       for (int i = 0, j = 0; j < n; j++) {         if (j - i + 1 >= a[j]) {           ++ans;           i = j + 1;         }       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char* argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long i, t, n, com, midc;     cin >> n;     map<int, int> m;     set<int> s;     vector<int> x(n);     vector<int> a(3);     for (i = 0; i < n; i++) {       cin >> x[i];       m[x[i]]++;       s.insert(x[i]);     }     t = s.size();     if (t == 1) {       cout << n << endl;       for (i = 0; i < n; i++) cout << x[i] <<    ;       cout << endl;     } else if (t == 2) {       i = 0;       for (set<int>::const_iterator it = s.begin(); it != s.end(); it++) {         a[i] = *it;         i++;       }       if (abs(a[0] - a[1]) == 1) {         cout << n << endl;         for (i = 0; i < n; i++) cout << x[i] <<    ;         cout << endl;       } else {         com = min(m[a[0]], m[a[1]]);         cout << n - (2 * com) << endl;         ;         for (i = 0; i < (2 * com); i++) cout << a[0] + 1 <<    ;         for (i = 0; i < m[a[0]] - com; i++) cout << a[0] <<    ;         for (i = 0; i < m[a[1]] - com; i++) cout << a[1] <<    ;         cout << endl;       }     } else {       i = 0;       for (set<int>::const_iterator it = s.begin(); it != s.end(); it++) {         a[i] = *it;         i++;       }       midc = m[a[1]] / 2;       com = min(m[a[0]], m[a[2]]);       if (midc > com) {         cout << n - (midc * 2) << endl;         for (i = 0; i < midc; i++) {           cout << a[0] <<    ;           cout << a[2] <<    ;         }         for (i = 0; i < m[a[0]]; i++) cout << a[0] <<    ;         for (i = 0; i < m[a[2]]; i++) cout << a[2] <<    ;         if (m[a[1]] % 2) cout << a[1];         cout << endl;       } else {         cout << n - (2 * com) << endl;         for (i = 0; i < m[a[1]]; i++) cout << a[1] <<    ;         for (i = 0; i < (2 * com); i++) cout << a[1] <<    ;         for (i = 0; i < m[a[0]] - com; i++) cout << a[0] <<    ;         for (i = 0; i < m[a[2]] - com; i++) cout << a[2] <<    ;         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const long long int INF = 1e12;   int n, k;   int memo[101][101][101];   int solve(string &str, int i, int N, int _max) {     _max = max(N, _max);     int &a = memo[i][N][_max];     if (a != -1) return a;     if (i == n) return a = (_max == k);     if (str[i] !=  N ) {       bool temp1 = solve(str, i + 1, 0, _max);       if (str[i] ==  Y  || temp1) return a = temp1;     }     return a = solve(str, i + 1, N + 1, _max);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     memset(memo, -1, sizeof(memo));     cin >> n >> k;     string str;     cin >> str;     cout << (solve(str, 0, 0, 0) ?  YES  :  NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double EPS = 1e-9;   int INF = 1000000000;   long long INFF = 8000000000000000000LL;   double PI = acos(-1);   int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};   int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};   inline string IntToString(int a) {     char x[100];     sprintf(x,  %d , a);     string s = x;     return s;   }   inline int StringToInt(string a) {     char x[100];     int res;     strcpy(x, a.c_str());     sscanf(x,  %d , &res);     return res;   }   inline string GetString(void) {     char x[1000005];     scanf( %s , x);     string s = x;     return s;   }   inline string uppercase(string s) {     int n = (int)s.size();     for (int(i) = (0); (i) < (n); ++(i))       if (s[i] >=  a  && s[i] <=  z ) s[i] = s[i] -  a  +  A ;     return s;   }   inline string lowercase(string s) {     int n = (int)s.size();     for (int(i) = (0); (i) < (n); ++(i))       if (s[i] >=  A  && s[i] <=  Z ) s[i] = s[i] -  A  +  a ;     return s;   }   inline void OPEN(string s) {     freopen((s +  .in ).c_str(),  r , stdin);     freopen((s +  .out ).c_str(),  w , stdout);   }   int k, n1, n2, n3, t1, t2, t3;   priority_queue<int, vector<int>, greater<int> > satu, dua, tiga;   int t[100005];   bool can(int T) {     if ((int)satu.size() == n1 && satu.top() + t1 > T) return false;     if ((int)dua.size() == n2 && dua.top() + t2 > T + t1) return false;     if ((int)tiga.size() == n3 && tiga.top() + t3 > T + t1 + t2) return false;     return true;   }   int main() {     scanf( %d %d %d %d %d %d %d , &k, &n1, &n2, &n3, &t1, &t2, &t3);     int bef = 0;     for (int(i) = (0); (i) < (k); ++(i)) {       int ambil = bef;       int L = t[i - 1];       int R = INF;       while (L <= R) {         int M = (L + R) >> 1;         if (can(M)) {           ambil = M;           R = M - 1;         } else           L = M + 1;       }       if ((int)satu.size() == n1) {         satu.pop();       }       satu.push(ambil);       if ((int)dua.size() == n2) {         dua.pop();       }       dua.push(ambil + t1);       if ((int)tiga.size() == n3) {         tiga.pop();       }       tiga.push(ambil + t1 + t2);       if (i == k - 1) {         printf( %d n , ambil + t1 + t2 + t3);       }       bef = ambil;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve(int x, int y, int n) {     vector<int> ans(n + 1);     ans[x] = 1;     ans[y] = 2;     for (int i = 1, j = 3; i <= n; i++) {       if (ans[i] == 0) {         ans[i] = j++;       }     }     for (int i = 1; i <= n; i++) {       cout << ans[i] <<    ;     }     cout <<   n ;     ans[y] = 1;     for (int i = 1; i <= n; i++) {       cout << ans[i] <<    ;     }     cout <<   n ;     exit(0);   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     if (n == 0 || n * (n - 1) / 2 == m) {       cout <<  NO n ;     } else {       cout <<  YES n ;       set<pair<int, int>> st;       for (int i = 0; i < m; i++) {         int x, y;         cin >> x >> y;         if (x > y) swap(x, y);         st.insert({x, y});       }       for (int i = 1; i <= n; i++) {         for (int j = i + 1; j <= n; j++) {           if (st.find({i, j}) == st.end()) {             solve(i, j, n);           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, long long> mp, vis;   vector<long double> vv;   vector<pair<long long, long long> > vp;   string s, q;   char c;   int main() {     long double t = 0, n, m, l, r, mn = 0, mx = 0, ans = 0, nm = 0, cnt = 0, x, y,                 z, d, v, g;     cin >> l >> d >> v >> g >> r;     l -= d;     t += d / v;     long long p = (long long)t / (long long)(g + r);     x = t - (p * (g + r));     if (x >= g) t += r - (x - g);     t += l / v;     cout << setprecision(10) << fixed << t;   }


#include <bits/stdc++.h>   using namespace std;   long long int max(long long int a, long long int b) {     if (a > b)       return a;     else       return b;   }   long long int min(long long int a, long long int b) {     if (a < b)       return a;     else       return b;   }   int main() {     long long int t, a, b, x, y;     cin >> t;     while (t--) {       long long int k1 = 0, k2 = 0, k3 = 0, k4 = 0, k5 = 0, k6 = 0, k7 = 0, c1,                     c2, c3, c4;       cin >> a >> b >> x >> y;       c1 = max(x, y);       c2 = min(x, y);       c3 = max(a, b);       c4 = min(a, b);       if (min(a, b) >= max(x, y)) {         k1 = (a - x - 1) * b;         k2 = x * b;         k3 = (b - y - 1) * a;         k4 = y * a;         k5 = max(k1, k2);         k6 = max(k3, k4);         k7 = max(k5, k6);       } else {         k1 = (c3 - c1 - 1) * c4;         k2 = c1 * c4;         k3 = (c4 - c2 - 1) * c3;         k4 = c2 * c3;         k5 = max(k1, k2);         k6 = max(k3, k4);         k7 = max(k5, k6);       }       cout << k7;       if (t != 0) cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a[26][26] = {0}, n, mini = -1;     cin >> n;     while (n--) {       char c[11];       scanf( %s , c);       int k = strlen(c), i = c[0] -  a , j = c[k - 1] -  a ;       for (int m = 0; m < 26; m++)         if (a[m][i]) a[m][j] = max(a[m][j], a[m][i] + k);       a[i][j] = max(a[i][j], k);       mini = max(mini, a[j][j]);     }     cout << mini;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 500;   int dist[maxn][maxn];   long long ans;   void modify(int u, int v, int w) {     if (dist[u][v] > w) {       ans -= (dist[v][u] - w);       dist[u][v] = w;     }     return;   }   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         cin >> dist[i][j];         if (j > i) {           ans += dist[i][j];         }       }     }     int k;     cin >> k;     for (int i = 1; i <= k; i++) {       int u, v, w;       cin >> u >> v >> w;       modify(u, v, w);       if (dist[u][v] != dist[v][u]) {         dist[v][u] = dist[u][v];       }       for (int p = 1; p <= n; p++) {         for (int q = 1; q <= n; q++) {           modify(p, q, dist[p][u] + dist[v][q] + w);           if (dist[p][q] != dist[q][p]) {             dist[q][p] = dist[p][u] + dist[v][q] + w;           }         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000;   const int inf = (int)1e9 + 1;   const long long big = (long long)1e18 + 1;   const int P = 239;   const int MOD = (int)1e9 + 7;   const int MOD1 = (int)1e9 + 9;   const double eps = 1e-9;   const double pi = atan2(0, -1);   const int ABC = 26;   int cnt = 0, len, s, f;   vector<int> g[N];   void solve(int k) {     if (k == 1) {       g[0].push_back(1);       g[1].push_back(0);       s = 0;       f = 1;       len = 1;       cnt += 2;     } else if (k % 2 == 0) {       solve(k / 2);       g[cnt].push_back(s);       g[s].push_back(cnt);       g[cnt + 1].push_back(s);       g[s].push_back(cnt + 1);       g[cnt + 2].push_back(cnt);       g[cnt].push_back(cnt + 2);       g[cnt + 2].push_back(cnt + 1);       g[cnt + 1].push_back(cnt + 2);       s = cnt + 2;       len += 2;       cnt += 3;     } else {       solve(k - 1);       for (int i = 0; i < len; i++) {         if (i == len - 1) {           g[cnt - 1].push_back(f);           g[f].push_back(cnt - 1);         } else {           g[cnt - 1].push_back(cnt);           g[cnt].push_back(cnt - 1);           cnt++;         }       }     }   }   char ans[N][N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.precision(20);     int k;     cin >> k;     solve(k);     int id[cnt];     int curr = 2;     for (int i = 0; i < cnt; i++)       if (i == s)         id[i] = 0;       else if (i == f)         id[i] = 1;       else         id[i] = curr++;     for (int i = 0; i < cnt; i++)       for (int j = 0; j < cnt; j++) ans[i][j] =  N ;     for (int i = 0; i < cnt; i++)       for (int j : g[i]) ans[id[i]][id[j]] =  Y ;     cout << cnt <<   n ;     for (int i = 0; i < cnt; i++) {       for (int j = 0; j < cnt; j++) cout << ans[i][j];       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   inline int Get() {     char ch;     while ((ch = getchar()) <  0  || ch >  9 )       ;     int Num = ch -  0 ;     while ((ch = getchar()) >=  0  && ch <=  9 )       Num = (Num << 3) + (Num << 1) + ch -  0 ;     return Num;   }   const int N = 1e5 + 5;   int n, m, a[N], count[N << 2], sum[N << 2], rev[N << 2];   std ::vector<int> vec0[N], vec1[N];   void build(int k, int l, int r) {     sum[k] = r - l + 1;     if (l == r) return;     int mid = l + r >> 1;     build(k << 1, l, mid), build(k << 1 | 1, mid + 1, r);   }   void down(int k) {     if (rev[k]) {       count[k << 1] = sum[k << 1] - count[k << 1], rev[k << 1] ^= 1;       count[k << 1 | 1] = sum[k << 1 | 1] - count[k << 1 | 1],                      rev[k << 1 | 1] ^= 1;       rev[k] = 0;     }   }   void modify(int k, int l, int r, int x, int y) {     if (x <= l && r <= y) {       rev[k] ^= 1, count[k] = sum[k] - count[k];       return;     }     int mid = l + r >> 1;     down(k);     if (x <= mid) modify(k << 1, l, mid, x, y);     if (y > mid) modify(k << 1 | 1, mid + 1, r, x, y);     count[k] = count[k << 1] + count[k << 1 | 1];   }   int query(int k, int l, int r, int x, int y) {     if (x <= l && r <= y) return count[k];     int mid = l + r >> 1;     down(k);     if (y <= mid) return query(k << 1, l, mid, x, y);     if (x > mid) return query(k << 1 | 1, mid + 1, r, x, y);     return query(k << 1, l, mid, x, y) + query(k << 1 | 1, mid + 1, r, x, y);   }   int main() {     n = Get(), m = Get();     for (int i = 1; i <= n; ++i) a[i] = Get();     std ::sort(a + 1, a + n + 1);     for (int i = 1; i <= m; ++i) {       int l = std ::lower_bound(a + 1, a + n + 1, Get()) - a;       int r = std ::upper_bound(a + 1, a + n + 1, Get()) - a - 1;       if (1 <= l && l <= n && 1 <= r && r <= n && l <= r)         vec0[l].push_back(r), vec1[r].push_back(l);     }     long long ans = (long long)n * (n - 1) * (n - 2) / 6;     build(1, 1, n);     for (int i = 1; i <= n; ++i) {       for (int k = 0, sze = vec0[i].size(); k < sze; ++k)         modify(1, 1, n, i, vec0[i][k]);       int res = (i > 1 ? i - 1 - query(1, 1, n, 1, i - 1) : 0) +                 (i < n ? query(1, 1, n, i + 1, n) : 0);       ans -= (long long)res * (res - 1) / 2;       for (int k = 0, sze = vec1[i].size(); k < sze; ++k)         modify(1, 1, n, vec1[i][k], i);     }     printf( %I64d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   void upd(int& a, int b) { a = max(a, b); }   int main() {     int n, m;     cin >> n >> m;     vector<int> a(n), b(m);     for (int i = 0; i < (int)n; ++i) cin >> a[i];     for (int i = 0; i < (int)m; ++i) cin >> b[i];     sort(a.begin(), a.end());     sort(b.begin(), b.end());     vector<int> to_seg(n);     int seg = 0;     vector<int> start, end;     for (int i = 0; i < (int)a.size(); ++i) {       if (i == 0 || a[i] != a[i - 1] + 1) {         seg++;         if (i != 0) end.push_back(i - 1);         start.push_back(i);       }       to_seg[i] = seg - 1;     }     end.push_back(n - 1);     vector<int> z(start.size()), d(start.size());     for (int segment = 0; segment < (int)start.size(); ++segment) {       int first = -1;       int cnt = 0;       for (int i = 0; i < (int)m; ++i) {         if (b[i] < a[start[segment]])           first = i;         else if (b[i] <= a[end[segment]])           cnt++;       }       int cnt_orig = cnt;       upd(d[segment], cnt);       if (segment) upd(d[segment], cnt + z[segment - 1]);       if (first != -1) {         for (int i = first; i >= 0; --i) {           ++cnt;           int r = a[start[segment]];           int l = b[i];           if (start[segment] - (r - l) >= 0) {             int Q = 0;             int X = to_seg[start[segment] - (r - l)] - 1;             if (X >= 0) Q = z[X];             upd(d[segment], cnt + Q);           }         }       }       cnt = 0;       for (int i = first + cnt_orig + 1; i < m; ++i) {         ++cnt;         int l = a[end[segment]];         int r = b[i];         if (end[segment] + (r - l) < n) {           upd(z[to_seg[end[segment] + (r - l)]], d[segment] + cnt);         }       }       upd(z[segment], d[segment]);     }     cout << *max_element(z.begin(), z.end()) << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long calc2(long long a, long long b, long long c, long long ab,                   long long ac, long long bc, long long abc) {     long long parts[] = {a - ab - ac + abc,                          b - ab - bc + abc,                          c - ac - bc + abc,                          ab - abc,                          ac - abc,                          bc - abc,                          abc};     int masks[3] = {1 + 8 + 16 + 64, 2 + 8 + 32 + 64, 4 + 16 + 32 + 64};     static int mark[64 * 8] = {0};     static int id = 0;     ++id;     long long res = 0;     for (int i = 0; i < 7; ++i)       if ((masks[0] >> i) & 1)         for (int j = 0; j < 7; ++j)           if ((masks[1] >> j) & 1)             for (int k = 0; k < 7; ++k)               if ((masks[2] >> k) & 1) {                 int a1 = min(i, min(j, k));                 int a3 = max(i, max(j, k));                 int a2 = i + j + k - a1 - a3;                 if (mark[64 * a1 + 8 * a2 + a3] == id) continue;                 mark[64 * a1 + 8 * a2 + a3] = id;                 if (i == j && j == k) {                   long long x = parts[i];                   res += +x * (x - 1) * (x - 2) / 6 + x * (x - 1) + x;                 } else if (i == j || j == k || i == k) {                   long long x = parts[i];                   long long y = parts[j];                   if (i == j)                     y = parts[k];                   else if (j == k)                     swap(x, y);                   res += x * (x + 1) / 2 * y;                 } else {                   res += parts[i] * parts[j] * parts[k];                 }               }     return res;   }   int get_common_num(vector<int> &a, vector<int> &b) {     int ia = 0, ib = 0;     int res = 0;     while (ia < a.size() && ib < b.size()) {       if (a[ia] == b[ib]) {         ++res;         ++ia, ++ib;       } else if (a[ia] < b[ib])         ++ia;       else         ++ib;     }     return res;   }   int get_common_num(vector<int> &a, vector<int> &b, vector<int> &c) {     int ia = 0, ib = 0, ic = 0;     int res = 0;     while (ia < a.size() && ib < b.size() && ic < c.size()) {       if (a[ia] == b[ib] && b[ib] == c[ic]) {         ++res;         ++ia, ++ib, ++ic;       } else if (a[ia] <= min(b[ib], c[ic]))         ++ia;       else if (b[ib] <= min(a[ia], c[ic]))         ++ib;       else         ++ic;     }     return res;   }   vector<int> dividers[100111];   int main() {     ios::sync_with_stdio(false);     dividers[1].push_back(1);     vector<int> smallest_fact(100111 + 1, 0);     for (int i = 2; i < 100111; ++i) {       if (!smallest_fact[i]) {         smallest_fact[i] = i;         for (long long j = i * (long long)i; j < 100111; j += i) {           if (!smallest_fact[j]) smallest_fact[j] = i;         }       }       int p = smallest_fact[i];       int x = i;       while (x % p == 0) x /= p;       int y = i;       int pp = p;       dividers[i] = dividers[x];       while (y % p == 0) {         for (int d : dividers[x]) dividers[i].push_back(pp * d);         pp *= p;         y /= p;       }       sort(dividers[i].begin(), dividers[i].end());     }     int t;     cin >> t;     while (t--) {       int a, b, c;       cin >> a >> b >> c;       int x = dividers[a].size();       int y = dividers[b].size();       int z = dividers[c].size();       int xy = get_common_num(dividers[a], dividers[b]);       int xz = get_common_num(dividers[a], dividers[c]);       int yz = get_common_num(dividers[b], dividers[c]);       int xyz = get_common_num(dividers[a], dividers[b], dividers[c]);       long long ans = calc2(x, y, z, xy, xz, yz, xyz);       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<string, int> my;   int n, m;   string var[5006];   string bit[5006];   int op[5006][2];   int opera[5006];   int ans[5005][1003];   int print1[1005], print2[1005];   int main() {     scanf( %d , &n);     scanf( %d , &m);     for (int i = 1; i <= n; i++) {       string z;       cin >> z;       my[z] = i;       var[i] = z;       cin >> z;       cin >> z;       if (z[0] ==  ? ) {         op[i][0] = 0;         cin >> z;         if (z[0] ==  A )           opera[i] == 1;         else if (z[0] ==  O )           opera[i] = 2;         else           opera[i] = 3;         cin >> z;         if (z[0] ==  ? )           op[i][1] = 0;         else           op[i][1] = my[z];       } else if (z[0] ==  0  || z[0] ==  1 )         bit[i] = z;       else {         op[i][0] = my[z];         cin >> z;         if (z[0] ==  A )           opera[i] = 1;         else if (z[0] ==  O )           opera[i] = 2;         else           opera[i] = 3;         cin >> z;         if (z[0] ==  ? )           op[i][1] = 0;         else           op[i][1] = my[z];       }     }     for (int i = 0; i < m; i++) {       int cnt[2];       cnt[0] = cnt[1] = 0;       for (int j = 0; j <= 1; j++) {         for (int k = 1; k <= n; k++) {           if (opera[k] == 0) {             ans[k][i] = bit[k][i] -  0 ;             cnt[j] += ans[k][i];           } else {             int v1 = op[k][0], v2 = op[k][1];             if (v1 == 0) ans[v1][i] = j;             if (v2 == 0) ans[v2][i] = j;             if (opera[k] == 1)               ans[k][i] = ans[v1][i] & ans[v2][i];             else if (opera[k] == 2)               ans[k][i] = ans[v1][i] | ans[v2][i];             else               ans[k][i] = ans[v1][i] ^ ans[v2][i];             cnt[j] += ans[k][i];           }         }       }       if (cnt[0] > cnt[1]) {         print1[i] = 0;         print2[i] = 1;       } else if (cnt[0] < cnt[1]) {         print1[i] = 1;         print2[i] = 0;       } else {         print1[i] = 0;         print2[i] = 0;       }     }     for (int i = 0; i < m; i++) cout << print2[i];     cout << endl;     for (int i = 0; i < m; i++) cout << print1[i];   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   long long power(long long a, long long b) {     long long ans = 1;     while (b > 0) {       if (b & 1) ans *= a;       a = a * a;       b >>= 1;     }     return ans;   }   long long powm(long long a, long long b) {     a %= MOD;     long long ans = 1;     while (b > 0) {       if (b & 1) ans = (ans * a) % MOD;       a = (a * a) % MOD;       b >>= 1;     }     return ans;   }   void IO() {}   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     IO();     ;     long long n, k;     cin >> n >> k;     long long A[k];     for (long long &x : A) cin >> x;     long long pos = 0, res = LLONG_MAX;     for (long long i = 0; i < k; i++) {       if (n % A[i] < res) {         pos = i + 1;         res = n % A[i];       }     }     cout << pos <<     << n / A[pos - 1] <<   n ;     return 0;   }