#include <bits/stdc++.h>   using namespace std;   const double pi = 2 * acos(0);   const int oo = 2e9;   const int N = 205;   const int AL = 26;   vector<int> idx[AL];   vector<int> adj[N];   int clr[N];   bool dfs(int u, int c = 0);   int main() {     int n;     scanf( %d , &(n));     string s(n,    );     for (int i = 0; i < n; i++) scanf(  %c , &s[i]);     memset(clr, -1, sizeof(clr));     for (int i = 0; i < n; i++) {       int x = s[i] -  a ;       for (int c = x + 1; c < AL; c++) {         for (auto& j : idx[c]) {           adj[i].push_back(j);           adj[j].push_back(i);         }       }       idx[x].push_back(i);     }     bool valid = true;     for (int i = 0; i < n; i++) {       if (clr[i] == -1) valid &= dfs(i);     }     if (valid) {       puts( YES );       for (int i = 0; i < n; i++) {         printf( %d , clr[i]);       }       printf(  n );     } else       printf( NO n );     return 0;   }   bool dfs(int u, int c) {     clr[u] = c;     bool ret = true;     for (auto& v : adj[u]) {       if (clr[v] == -1)         ret &= dfs(v, !c);       else if (c == clr[v])         return false;     }     return ret;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   long long int rev[N], fac[N], mod = 1e9 + 7;   long long int wop(long long int x, long long int y) {     if (y == 0) return 1;     long long int ret = wop(x, y / 2);     ret %= mod;     ret *= ret;     ret %= mod;     if (y & 1) ret *= x;     ret %= mod;     return ret;   }   long long int chos(long long int r, long long int n) {     return (fac[n] * ((rev[r] * rev[n - r]) % mod)) % mod;   }   int main() {     long long int n, m;     cin >> n >> m;     rev[0] = fac[0] = 1;     for (int i = 1; i < 2e3; i++) {       fac[i] = fac[i - 1] * i;       fac[i] %= mod;       rev[i] = wop(fac[i], mod - 2);     }     long long int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = i; j <= n; j++) {         long long int f1 = chos(i - 1, i + m - 2);         long long int f2 = chos(n - j, n + m - j - 1);         ans += (f1 * f2) % mod;         ans %= mod;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 505 * 505 * 4;   int n;   using vi = vector<int>;   vi G[maxn];   int dfn[maxn];   int low[maxn];   int scc[maxn];   int scnt[maxn];   int ntime;   int scc_cnt;   int sta[maxn];   int sz;   void tarjan(int u) {     dfn[u] = low[u] = ++ntime;     sta[sz++] = u;     for (int i = 0; i < G[u].size(); i++) {       int v = G[u][i];       if (!dfn[v]) {         tarjan(v);         low[u] = min(low[u], low[v]);       } else if (!scc[v]) {         low[u] = min(low[u], dfn[v]);       }     }     if (low[u] == dfn[u]) {       scc_cnt++;       int tmp;       do {         --sz;         tmp = sta[sz];         scc[tmp] = scc_cnt;         scnt[scc_cnt]++;       } while (tmp != u);     }   }   bool find_bcc() {     sz = 0;     memset(scc, 0, sizeof(scc));     memset(dfn, 0, sizeof(dfn));     memset(scnt, 0, sizeof(scnt));     ntime = scc_cnt = 0;     for (int i = 1; i <= n; ++i)       if (!dfn[i]) tarjan(i);     for (int i = 1; i <= n; i += 2) {       if (scc[i] == scc[i + 1]) return false;     }     return true;   }   char s[505][505];   int w, h;   int id(int x, int y) { return (x - 1) * w + y; }   int res[505][505];   int dx[4] = {1, 0, -1, 0};   int dy[4] = {0, 1, 0, -1};   int main() {     scanf( %d %d , &h, &w);     n = 2 * h * w;     for (int i = 1; i <= h; i += 1) {       scanf( %s , s[i] + 1);     }     for (int i = 1; i <= h; i += 1) {       for (int j = 1; j <= w; j += 1) {         if (s[i][j] ==  . ) continue;         int cnt = 0;         vector<int> lst;         for (int k = 0; k < 4; k += 1) {           int nx = i + dx[k];           int ny = j + dy[k];           if (s[nx][ny] ==  . ) {             cnt += 1;             lst.emplace_back(id(nx, ny));           }         }         if (cnt == 1 || cnt == 3) {           puts( NO );           return 0;         }         if (!cnt) continue;         if (cnt == 2) {           G[lst[0] * 2 - 1].emplace_back(lst[1] * 2);           G[lst[1] * 2 - 1].emplace_back(lst[0] * 2);           G[lst[0] * 2].emplace_back(lst[1] * 2 - 1);           G[lst[1] * 2].emplace_back(lst[0] * 2 - 1);         }         if (cnt == 4) {           for (int i = 0; i < 2; i += 1) {             G[2 * lst[i]].emplace_back(2 * lst[i + 2]);             G[2 * lst[i] - 1].emplace_back(2 * lst[i + 2] - 1);             G[2 * lst[i + 2]].emplace_back(2 * lst[i]);             G[2 * lst[i + 2] - 1].emplace_back(2 * lst[i] - 1);           }           for (int i = 0; i < 4; i += 2) {             int nx = lst[(i + 1) % 4];             G[2 * lst[i] - 1].emplace_back(2 * nx);             G[2 * lst[i]].emplace_back(2 * nx - 1);             nx = lst[(i + 3) % 4];             G[2 * lst[i] - 1].emplace_back(2 * nx);             G[2 * lst[i]].emplace_back(2 * nx - 1);           }         }       }     }     if (!find_bcc())       puts( NO );     else {       puts( YES );       for (int i = 1; i <= h; i += 1) {         for (int j = 1; j <= w; j += 1) {           if (s[i][j] ==  X ) continue;           int cur = id(i, j);           if (scc[2 * cur - 1] < scc[2 * cur])             res[i][j] = 1;           else             res[i][j] = 4;         }       }       for (int i = 1; i <= h; i += 1) {         for (int j = 1; j <= w; j += 1) {           if (s[i][j] ==  . ) continue;           for (int k = 0; k < 4; k += 1) {             int nx = i + dx[k];             int ny = j + dy[k];             if (s[nx][ny] ==  X ) continue;             res[i][j] += res[nx][ny];           }         }       }       for (int i = 1; i <= h; i += 1) {         for (int j = 1; j <= w; j += 1) {           printf( %d%c , res[i][j],    n [j == w]);         }       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( tune=native )   using namespace std;   const int MAX = 1e6 + 5;   const long long MOD = 1000000007;   const long long MOD2 = 2010405347;   const long long INF = 2e18;   const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};   const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0};   const double pi = acos(-1);   const double EPS = 1e-9;   const int block = 315;   inline long long pw(long long x, long long y, long long md = MOD) {     long long ret = 1;     while (y) {       if (y & 1) ret = ret * x % md;       x = x * x % md, y >>= 1;     }     return ret;   }   int n, x[MAX], y[MAX], z[MAX], nw;   long long ans;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = (1); i <= (n); ++i) {       cin >> x[i];       y[i] = max(y[i - 1], x[i] + 1);     }     for (int i = (n); i >= (1); --i) {       nw = max(nw - 1, x[i] + 1);       z[i] = nw;     }     for (int i = (1); i <= (n); ++i) {       nw = max(y[i], z[i]);       ans += nw - x[i] - 1;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void chkmax(T& x, T y) {     if (x < y) x = y;   }   template <typename T>   void chkmin(T& x, T y) {     if (x > y) x = y;   }   inline int read() {     int x = 0;     char c = getchar();     bool f = 0;     while (c < 48) f |= c ==  - , c = getchar();     while (c > 47) x = x * 10 + (c ^ 48), c = getchar();     return f ? -x : x;   }   int N, p[114];   long long getv(long long x) {     long long res = 0;     for (int i = (N - 1), iend = (0); i >= iend; --i) {       if ((long double)res * x + p[i] > 1e18) return -1;       res = res * x + p[i];     }     return res;   }   void solve() {     long long t, a, b;     cin >> t >> a >> b;     int res = a == b ? 1 : 0, tt = -1, ct = 0;     if (t > a || a > b || (t == a && a == 1 && b > 1))       return printf( %d n , res), void();     if (b == 1) return puts( inf ), void();     if (a != 1) {       for (long long tp = b; tp; tp /= a) p[N++] = tp % a, ct += tp % a != 0;       res += getv(t) == a && getv(a) == b;       if (ct == 1) tt = N - 1;     }     long long zzh = 1, yyh = 1;     for (int i = (1), iend = (60); i <= iend; ++i) {       if ((long double)yyh * a > 1e18) break;       zzh *= t, yyh *= a;       if (i != tt && a % zzh == 0 && b % yyh == 0 && a / zzh == b / yyh) res++;     }     cout << res << endl;   }   signed main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 1000000007;   long long dp[2001][2001];   long long dp1[2001][2001];   int main() {     int N, K;     string S;     cin >> N >> K >> S;     memset(dp, 0, sizeof(dp));     memset(dp1, 0, sizeof(dp1));     dp[0][0] = dp1[0][0] = 1;     for (int n = 1; n <= N; ++n) {       for (int k = 0; k <= K; ++k) {         dp[n][k] = dp1[n - 1][k] * (long long)(S[n - 1] -  a ) % MOD;       }       for (int i = 0; i < n; ++i) {         int delta = (n - i) * (N - n + 1);         for (int k = 0; k + delta <= K; ++k) {           dp[n][k + delta] += dp[i][k] * (long long)( z  - S[n - 1]) % MOD;           dp[n][k + delta] %= MOD;         }       }       for (int k = 0; k <= K; ++k) {         dp1[n][k] = (dp1[n - 1][k] + dp[n][k]) % MOD;       }     }     cout << dp1[N][K] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   int type[N], n, p[N], out[N];   int go(int u, bool print = false) {     int res = p[u] == -1 || out[p[u]] > 1 ? 1 : go(p[u], print) + 1;     if (print) cout << u + 1 <<    ;     return res;   }   int main() {     cin >> n;     for (int i = 0; i < n; ++i) cin >> type[i];     for (int i = 0; i < n; ++i) {       cin >> p[i];       if (--p[i] >= 0) ++out[p[i]];     }     int res = -1;     for (int i = 0; i < n; ++i)       if (type[i] == 1)         if (res == -1 || go(i) > go(res)) res = i;     cout << go(res) << endl;     go(res, true);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   const int MAXN = 1e5 + 5;   using namespace std;   struct node {     int i;     node *l, *r;   };   node *newN(int i) {     node *x = new node;     x->i = i;     x->r = x->l = NULL;     return x;   }   node *insert(node *actual, int i, bool k) {     if (!actual) return newN(i);     if (k)       return actual->r = newN(i);     else       return actual->l = newN(i);   }   void inorder(node *root) {     if (!root) return;     inorder(root->l);     cout << root->i <<   n ;     inorder(root->r);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     string a;     cin >> a;     node *root = newN(1), *actual = root;     for (int i = 0; i < (int)a.size() - 1; i++) {       if (a[i] ==  l )         actual = insert(actual, i + 2, 0);       else         actual = insert(actual, i + 2, 1);     }     inorder(root);     return 0;   }


#include <bits/stdc++.h>   const double eps = 1e-10;   const float epsf = 1e-6;   using namespace std;   inline long long int __gcd(long long int a, long long int b) {     if (a == 0 || b == 0) {       return max(a, b);     }     long long int tempa, tempb;     while (1) {       if (a % b == 0)         return b;       else {         tempa = a;         tempb = b;         a = tempb;         b = tempa % tempb;       }     }   }   inline int compfloat(float& x, float& y) {     if (fabs(x - y) < epsf)       return 0;     else if (x - y > 0)       return 1;     return -1;   }   inline int compdouble(double x, double y) {     if (fabs(x - y) < eps)       return 0;     else if (x - y > 0)       return 1;     else       return -1;   }   bool prime(long long int k) {     for (long long int i = 2; i * i <= k; i++)       if (k % i == 0) {         return false;       }     return true;   }   void pdash(int n = 1) {     for (int i = 0; i < n; i++) {       for (int j = 0; j < 30; j++) {         cout <<  - ;       }       cout <<   n ;     }   }   void solve() {     long long int n;     cin >> n;     long long int arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     long long int dpi[n], dpd[n];     dpi[0] = 0;     dpd[n - 1] = 0;     for (int i = 1; i < n; i++)       dpi[i] = max(dpi[i - 1] + arr[i - 1] + 1 - arr[i], (long long int)0);     for (int i = (int)n - 2; i >= 0; i--)       dpd[i] = max(dpd[i + 1] + arr[i + 1] + 1 - arr[i], (long long int)0);     long long int sumi[n], sumd[n];     sumi[0] = dpi[0];     sumd[n - 1] = dpd[n - 1];     for (int i = 1; i < n; i++) sumi[i] = sumi[i - 1] + dpi[i];     for (int i = (int)n - 2; i >= 0; i--) sumd[i] = sumd[i + 1] + dpd[i];     long long int ans = numeric_limits<long long int>::max();     for (int i = 1; i < n - 1; i++)       ans = min(ans, sumi[i - 1] + sumd[i + 1] + max(dpi[i], dpd[i]));     ans = min({sumd[0], sumi[n - 1], ans});     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100007;   struct LinkCutTree {     struct Node {       int L, R, P, lazyFlip;       int PP;     };     Node LCT[MAXN];     void normalize(int u) {       assert(u != -1);       if (LCT[u].L != -1) LCT[LCT[u].L].P = u;       if (LCT[u].R != -1) LCT[LCT[u].R].P = u;     }     void setLeftChild(int p, int v) {       LCT[p].L = v;       normalize(p);     }     void setRightChild(int p, int v) {       LCT[p].R = v;       normalize(p);     }     void pushLazy(int u) {       if (!LCT[u].lazyFlip) return;       swap(LCT[u].L, LCT[u].R);       LCT[u].lazyFlip = 0;       if (LCT[u].L != -1) LCT[LCT[u].L].lazyFlip ^= 1;       if (LCT[u].R != -1) LCT[LCT[u].R].lazyFlip ^= 1;     }     void make_tree(int v) {       LCT[v].L = LCT[v].R = LCT[v].P = LCT[v].PP = -1;       LCT[v].lazyFlip = 0;     }     void rotate(int v) {       if (LCT[v].P == -1) return;       int p = LCT[v].P;       int g = LCT[p].P;       if (LCT[p].L == v) {         setLeftChild(p, LCT[v].R);         setRightChild(v, p);       } else {         setRightChild(p, LCT[v].L);         setLeftChild(v, p);       }       LCT[v].P = g;       if (g != -1) {         if (LCT[g].L == p) {           setLeftChild(g, v);         } else {           setRightChild(g, v);         }       }       LCT[v].PP = LCT[p].PP;       LCT[p].PP = -1;     }     void pushEmAll(int v) {       if (LCT[v].P != -1) pushEmAll(LCT[v].P);       pushLazy(v);     }     void splay(int v) {       pushLazy(v);       while (LCT[v].P != -1) {         int p = LCT[v].P;         int g = LCT[p].P;         if (g != -1) pushLazy(g);         pushLazy(p);         pushLazy(v);         if (g == -1) {           rotate(v);         } else if ((LCT[p].L == v) == (LCT[g].L == p)) {           rotate(p);           rotate(v);         } else {           rotate(v);           rotate(v);         }       }     }     vector<int> access(int v, bool doIt = false) {       splay(v);       int _v = v, _r = -1;       if (LCT[v].R != -1) {         if (doIt) {           _r = LCT[v].R;         }         LCT[LCT[v].R].PP = v;         LCT[LCT[v].R].P = -1;         setRightChild(v, -1);       }       vector<int> ret;       while (LCT[v].PP != -1) {         int w = LCT[v].PP;         splay(w);         ret.push_back(w);         if (LCT[w].R != -1) {           LCT[LCT[w].R].PP = w;           LCT[LCT[w].R].P = -1;         }         LCT[v].PP = -1;         setRightChild(w, v);         splay(v);       }       if (_r != -1) {         splay(_v);         assert(LCT[_v].R == -1);         setRightChild(_v, _r);         LCT[_r].PP = -1;       }       return ret;     }     int find_root(int v) {       access(v);       int ret = v;       while (LCT[ret].L != -1) {         ret = LCT[ret].L;         pushLazy(ret);       }       access(ret);       return ret;     }     void link(int v, int w) {       access(w);       setLeftChild(v, w);       LCT[w].PP = -1;     }     void cut(int v) {       access(v);       if (LCT[v].L != -1) {         LCT[LCT[v].L].P = -1;         LCT[LCT[v].L].PP = -1;         setLeftChild(v, -1);       }     }     void make_root(int v) {       access(v);       int l = LCT[v].L;       if (l != -1) {         setLeftChild(v, -1);         LCT[l].P = -1;         LCT[l].PP = v;         LCT[l].lazyFlip ^= 1;       }     }     bool isConnected(int p, int q) { return find_root(p) == find_root(q); }     int LCA(int p, int q) {       access(p);       return access(q).back();     }   };   vector<pair<int, int> > edg[MAXN];   long long depth[MAXN];   LinkCutTree lct;   int bap[MAXN];   vector<int> accessOrder;   int st[MAXN], ed[MAXN];   int tym;   void dfs(int u, int p) {     st[u] = ++tym;     bap[u] = p;     bool called = false;     for (pair<int, int> pr : edg[u]) {       if (p == pr.first) continue;       called = true;       depth[pr.first] = depth[u] + pr.second;       lct.link(pr.first, u);       dfs(pr.first, u);     }     if (!called) accessOrder.push_back(u);     ed[u] = tym;   }   map<long long, long long> vacancy;   bool makePlace(long long l, long long r) {     auto it = vacancy.lower_bound(l);     if (l <= prev(it)->second) {       it = prev(it);       long long _l = it->first;       long long _r = it->second;       vacancy.erase(it);       if (_l < l) vacancy[_l] = l - 1;       if (l < _r) vacancy[l + 1] = _r;       return true;     } else {       assert(it != vacancy.end());       long long _l = it->first;       long long _r = it->second;       if (r < _l) return false;       vacancy.erase(it);       if (_l < _r) vacancy[_l + 1] = _r;       return true;     }     assert(false);   }   set<int> tr[4 * MAXN];   void update(int u, int l, int r, int i, int t) {     tr[u].insert(t);     if (l == r) return;     int mid = (l + r) / 2;     if (i <= mid)       update(u * 2, l, mid, i, t);     else       update(u * 2 + 1, mid + 1, r, i, t);   }   int ask(int u, int l, int r, int x, int y, int t) {     if (y < l || r < x) return 0;     if (x <= l && r <= y) {       auto it = tr[u].lower_bound(t);       if (it == tr[u].begin()) return 0;       return *prev(it);     }     int mid = (l + r) / 2;     return max(ask(u * 2, l, mid, x, y, t), ask(u * 2 + 1, mid + 1, r, x, y, t));   }   void printEdges(int s) {     while (s != 1) {       cout << s <<  @  << depth[s] <<   <-  ;       s = bap[s];     }     cout << 1;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 1; i < n; i++) {       int u, v, w;       cin >> u >> v >> w;       edg[u].emplace_back(v, w);       edg[v].emplace_back(u, w);     }     for (int i = 1; i <= n; i++) lct.make_tree(i);     dfs(1, 0);     for (int leaf : accessOrder) {       lct.access(leaf);     }     map<long long, vector<long long> > mp;     for (int _m = 0; _m < m; _m++) {       int s, t;       cin >> s >> t;       if (s == 1) continue;       vector<int> need = lct.access(s, true);       for (int p : need) {         int l = ask(1, 1, n, st[p], ed[p], t);         if (l > 0)           mp[t + depth[p]].push_back(l + 1 + depth[p]);         else           mp[t + depth[p]].push_back(1);       }       update(1, 1, n, st[bap[s]], t);     }     vacancy[0] = 1e15;     int ans = 0;     for (pair<const long long, vector<long long> >& pr : mp) {       sort(pr.second.begin(), pr.second.end());       bool okay = true;       for (long long x : pr.second) {         if (!makePlace(x, pr.first)) {           okay = false;           break;         }       }       if (!okay) {         cout << pr.first <<     << ans << endl;         return 0;       }       ans += pr.second.size();     }     cout << -1 <<     << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 10;   long long arr[MAX], arr2[MAX];   int n, m;   bool check(long long mid) {     int prv = 0;     for (int i = 0; i < n; ++i) {       while (prv < m && arr2[prv] + mid < arr[i]) ++prv;       if (prv == m || arr2[prv] - mid > arr[i]) return 0;     }     return 1;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < n; ++i) cin >> arr[i];     for (int i = 0; i < m; ++i) cin >> arr2[i];     sort(arr, arr + n);     sort(arr2, arr2 + m);     long long l = 0, r = 2e9;     long long ans = r;     while (l <= r) {       long long mid = (l + r) >> 1;       if (check(mid))         ans = mid, r = mid - 1;       else         l = mid + 1;     }     return cout << ans <<   n , 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 2;   int a[maxn << 1];   long long vis[maxn];   int main(void) {     std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int n, m;     while (cin >> n >> m) {       int k = 0;       int t;       vector<int> a(n + m + 1);       vector<long long> vis(m);       for (int i = 1; i <= n + m; i++) cin >> a[i];       for (int i = 1; i <= n + m; i++) cin >> t, t ? vis[k++] = a[i] : 1;       vis[k] = (int)1e18;       for (int i = 1, j = 0; i <= n + m; j++) {         int cnt = 0;         while (a[i] < vis[j]) cnt++, i++;         i++;         while (a[i] - vis[j] <= vis[j + 1] - a[i] && i <= n + m) cnt++, i++;         cout << cnt <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   bool isprime[N] = {1, 1, 0};   int sum[N] = {};   void YesIcan() {     for (int i = 2; i * i <= N; ++i) {       for (int j = i * i; j <= N; j += i) isprime[j] = true;     }   }   int main() {     YesIcan();     int a, b, k;     cin >> a >> b >> k;     for (int i = a; i <= b; ++i) {       sum[i] = sum[i - 1];       if (!isprime[i]) ++sum[i];     }     if (sum[b] < k) {       cout << -1;       return 0;     }     int i = a - 1, l = 1;     for (; i <= b - l; ++i) {       while (sum[i + l] - sum[i] < k && l <= b - a + 1 && i + l <= b) ++l;     }     cout << l;   }


#include <bits/stdc++.h>   using namespace std;   int main() {   #ifdef LOCAL     freopen( ../IO/d.in ,  r , stdin);   //  freopen( ../IO/d.out ,  w , stdout);   #else     std::ios_base::sync_with_stdio(false);     std::cin.tie(nullptr);     std::cout.tie(nullptr);   #endif     int number_of_tests;     cin >> number_of_tests;        while (number_of_tests--) {       int n;       cin >> n;       std::vector<int> b(n);       std::vector<int> used(2 * n);       for (int &i : b) cin >> i, --i, used[i] = 1;       std::vector<int> unused;       unused.reserve(n);       for (int i = 0; i < 2 * n; ++i) {         if (!used[i]) unused.push_back(i);       }       vector<int> c(n + 1, true);       int l = -1, r = -1;       auto check1 = [&](int x) {         deque<int> dq(unused.begin(), unused.end());         bool ok = true;         for (int i = x - 1; i >= 0; --i) {           ok &= b[i] < dq.back();           dq.pop_back();         }         return ok;       };       auto check2 = [&](int x) {         deque<int> dq(unused.begin(), unused.end());         bool ok = true;         for (int i = x; i < n; ++i) {           ok &= b[i] > dq.front();           dq.pop_front();         }         return ok;       };       int lo = -1, hi = n + 1;       while (hi - lo > 1) {         int x = (lo + hi) / 2;         if (check1(x)) {           lo = x;         } else {           hi = x;         }       }       l = 0, r = lo;       lo = -1, hi = n + 1;       while (hi - lo > 1) {         int x = (lo + hi) / 2;         if (check2(x)) {           hi = x;         } else {           lo = x;         }       }       l = std::max(l, hi);   //    std::cout << l <<     << r <<   n ;       std::cout << std::max(0, r - l + 1) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   int gcd(int a, int b) {     if (b == 0) return a;     gcd(b, a % b);   }   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int q;     cin >> q;     while (q--) {       int a, b;       cin >> a >> b;       if (gcd(a, b) != 1)         cout <<  INFINITE  << endl;       else         cout <<  FINITE  << endl;     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16000000 )   using namespace std;   const int Maxn = 1000005;   const int Maxm = 4194304;   const int Inf = 1000000000;   int n, c;   pair<int, int> lef[Maxn], rig[Maxn];   int me[Maxn];   int res[Maxn], rlen;   int st[Maxm];   void Insert(int v, int l, int r, int x, int val) {     if (l == r)       st[v] = val;     else {       int m = l + r >> 1;       if (x <= m)         Insert(2 * v, l, m, x, val);       else         Insert(2 * v + 1, m + 1, r, x, val);       st[v] = max(st[2 * v], st[2 * v + 1]);     }   }   int Get(int v, int l, int r, int a, int b) {     if (l == a && r == b)       return st[v];     else {       int res = -Inf;       int m = l + r >> 1;       if (a <= m) res = max(res, Get(2 * v, l, m, a, min(m, b)));       if (m + 1 <= b) res = max(res, Get(2 * v + 1, m + 1, r, max(m + 1, a), b));       return res;     }   }   bool isNull(const pair<int, int> &p) { return p == pair<int, int>(Inf, -Inf); }   void Print(int l, int r) {     if (l > r) return;     if (l == r)       res[rlen++] = l;     else {       int from = l + 1;       if (!isNull(lef[l])) {         Print(l + 1, lef[l].second);         from = lef[l].second + 1;       }       res[rlen++] = l;       Print(from, r);     }   }   int main() {     scanf( %d %d , &n, &c);     for (int i = 1; i <= n; i++) {       lef[i] = pair<int, int>(Inf, -Inf);       rig[i] = pair<int, int>(Inf, -Inf);     }     int a, b;     char s[10];     while (c--) {       scanf( %d %d %s , &a, &b, s);       if (s[0] ==  L ) {         lef[a].first = min(lef[a].first, b);         lef[a].second = max(lef[a].second, b);       } else {         rig[a].first = min(rig[a].first, b);         rig[a].second = max(rig[a].second, b);       }     }     for (int i = n; i >= 1; i--) {       if (isNull(lef[i]) && isNull(rig[i]))         me[i] = i;       else if (isNull(lef[i]))         if (rig[i].first <= i) {           printf( IMPOSSIBLE n );           return 0;         } else           me[i] = Get(1, 1, n, i + 1, rig[i].second);       else if (isNull(rig[i]))         if (lef[i].first <= i) {           printf( IMPOSSIBLE n );           return 0;         } else {           lef[i].second = Get(1, 1, n, i + 1, lef[i].second);           me[i] = lef[i].second;         }       else if (lef[i].first <= i) {         printf( IMPOSSIBLE n );         return 0;       } else {         lef[i].second = Get(1, 1, n, i + 1, lef[i].second);         if (lef[i].second >= rig[i].first) {           printf( IMPOSSIBLE n );           return 0;         } else           me[i] = Get(1, 1, n, lef[i].second + 1, rig[i].second);       }       Insert(1, 1, n, i, me[i]);     }     Print(1, n);     for (int i = 0; i < rlen; i++)       printf( %d%c , res[i], i + 1 < rlen ?     :   n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int sz = 7e5;   long long int sum[sz];   long long int mi[sz];   long long int arr[sz];   void build(long long int node, long long int l, long long int r) {     if (l == r) {       sum[node] = arr[l];     } else {       long long int mid = (l + r) / 2;       build(2 * node, l, mid);       build(2 * node + 1, mid + 1, r);       sum[node] = sum[node * 2] + sum[node * 2 + 1];     }   }   long long int query(long long int node, long long int l, long long int r,                       long long int tl, long long int tr) {     if (l > tr || r < tl)       return 0;     else if (l >= tl && r <= tr)       return sum[node];     else       return (query(node * 2, l, (l + r) / 2, tl, tr) +               query(node * 2 + 1, (l + r) / 2 + 1, r, tl, tr));   }   void build2(long long int node, long long int l, long long int r) {     if (l == r) {       mi[node] = arr[l];     } else {       long long int mid = (l + r) / 2;       build2(2 * node, l, mid);       build2(2 * node + 1, mid + 1, r);       mi[node] = min(mi[node * 2], mi[node * 2 + 1]);     }   }   long long int query2(long long int node, long long int l, long long int r,                        long long int tl, long long int tr) {     if (l > tr || r < tl)       return 0;     else if (l >= tl && r <= tr)       return mi[node];     else       return min(query2(node * 2, l, (l + r) / 2, tl, tr),                  query2(node * 2 + 1, (l + r) / 2 + 1, r, tl, tr));   }   long long int pre[sz];   int main() {     std::ios::sync_with_stdio(false);     long long int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> arr[i];     build(1, 1, n);     build2(1, 1, n);     sort(arr, arr + n + 1);     for (int i = 1; i <= n; i++) {       pre[i] = pre[i - 1] + arr[i];     }     long long int q;     cin >> q;     while (q--) {       long long int t;       cin >> t;       if (t == 1) {         long long int l, r;         cin >> l >> r;         cout << query(1, 1, n, l, r) << endl;       } else {         long long int l, r;         cin >> l >> r;         cout << pre[r] - pre[l - 1] << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   const int inf = 0x3f3f3f3f;   const long long INF = 1e18;   template <typename T>   void read(T &x) {     x = 0;     int s = 1, c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) s = -1;     for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;     x *= s;   }   template <typename T>   void write(T x) {     if (x < 0) x = -x, putchar( - );     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   template <typename T>   void writeln(T x) {     write(x);     puts(  );   }   const int maxn = 1e5 + 5, maxm = 1e6 + 5;   struct Edge {     int u, v, c, id;     bool operator<(const Edge &rhs) const { return c < rhs.c; }   } e[maxm];   int n, m;   int fa[maxn];   vector<pair<int, int> > adj[maxn];   int f[maxn][20], dis[maxn][20], d[maxn];   vector<Edge> v;   int find(int v) { return v == fa[v] ? v : fa[v] = find(fa[v]); }   void dfs(int u, int fa) {     d[u] = d[fa] + 1;     for (pair<int, int> x : adj[u])       if (x.first ^ fa) {         int v = x.first, c = x.second;         f[v][0] = u;         dis[v][0] = c;         dfs(v, u);       }   }   int LCA(int x, int y, int op) {     int res = 0;     if (d[x] > d[y]) swap(x, y);     for (int t = 19; t >= 0; t--)       if (d[x] <= d[f[y][t]]) {         res = max(res, dis[y][t]);         y = f[y][t];       }     if (x == y) return op ? res : x;     for (int t = 19; t >= 0; t--)       if (f[x][t] != f[y][t]) {         res = max(res, max(dis[x][t], dis[y][t]));         x = f[x][t], y = f[y][t];       }     res = max(res, max(dis[x][0], dis[y][0]));     return op ? res : f[x][0];   }   int main() {     read(n), read(m);     for (int i = 1; i <= m; i++) {       read(e[i].u), read(e[i].v), read(e[i].c);       e[i].id = i;     }     sort(e + 1, e + 1 + m);     for (int i = 1; i <= n; i++) fa[i] = i;     for (int i = 1; i <= m; i++) {       int p = find(e[i].u), t = find(e[i].v);       if (p != t) {         adj[e[i].u].emplace_back(e[i].v, e[i].c);         adj[e[i].v].emplace_back(e[i].u, e[i].c);         fa[p] = t;       } else         v.emplace_back(e[i]);     }     dfs(1, 0);     for (int j = 1; j <= 19; j++)       for (int i = 1; i <= n; i++) {         f[i][j] = f[f[i][j - 1]][j - 1];         dis[i][j] = max(dis[i][j - 1], dis[f[i][j - 1]][j - 1]);       }     sort((v.begin()), (v.end()), [&](Edge x, Edge y) { return x.id < y.id; });     for (auto i : v) {       int lca = LCA(i.u, i.v, 0);       printf( %d n , max(LCA(i.u, lca, 1), LCA(i.v, lca, 1)));     }   }


#include <bits/stdc++.h>   const size_t max_vertices = 1 << 16;   int degree[max_vertices], xor_sum[max_vertices];   std::queue<int> queue;   std::vector<std::pair<int, int>> result;   int main() {     int vcount = 0;     std::cin >> vcount;     for (int i = 0; i < vcount; i++) {       std::cin >> degree[i] >> xor_sum[i];       if (degree[i] == 1) {         queue.push(i);       }     }     while (!queue.empty()) {       int cur = queue.front();       queue.pop();       int next = xor_sum[cur];       if (degree[cur] > 0 && degree[next] > 0) {         result.push_back(std::make_pair(cur, next));         degree[next]--;         degree[cur]--;         xor_sum[next] ^= cur;       }       if (degree[next] == 1) {         queue.push(next);       }     }     std::cout << result.size() << std::endl;     for (int i = 0; i < result.size(); i++) {       std::cout << result[i].first <<     << result[i].second << std::endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long isPrime(long long x) {     long long i, flag = 1;     if (x == 0 || x == 1) {       flag = 0;     }     for (i = 2; i <= sqrt(x); i++) {       if (x % i == 0) {         flag = 0;         break;       }     }     return flag;   }   long long fact(long long n) {     long long ans = 1;     for (long long i = 2; i <= n; i++) {       ans *= i;     }     return ans;   }   const long long INF = 1e18;   const long long N = 2 * 1e5;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     {       long long n;       cin >> n;       if (n == 0) {         cout << 1 <<   n ;         return 0;       }       if (n % 4 == 1) {         cout << 8 <<   n ;       } else if (n % 4 == 2) {         cout << 4 <<   n ;       } else if (n % 4 == 3) {         cout << 2 <<   n ;       } else if (n % 4 == 0) {         cout << 6 <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[6], b[6], ord[6], c[6];   vector<pair<int, int> > v, nv;   struct S {     vector<pair<int, int> > v;     int from;     S(vector<pair<int, int> > v, int from) : v(v), from(from) {}     S() {}   };   vector<S> s;   void pr(int a, int b) {     if (a == 1) {       printf( inc %d n , ord[b] + 1);     } else {       printf( dec %d n , ord[b] + 1);     }   }   S hor, ver, res;   bool invI, invJ;   void _incI() {     assert(ver.from < (int)ver.v.size());     res.v.push_back(ver.v[ver.from++]);   }   void _decI() {     assert(ver.from > 0);     pair<int, int> p = ver.v[--ver.from];     p.first = -p.first;     res.v.push_back(p);   }   void _incJ() {     assert(hor.from < (int)hor.v.size());     res.v.push_back(hor.v[hor.from++]);   }   void _decJ() {     assert(hor.from > 0);     pair<int, int> p = hor.v[--hor.from];     p.first = -p.first;     res.v.push_back(p);   }   void decI() {     if (invI)       _incI();     else       _decI();   }   void incI() {     if (invI)       _decI();     else       _incI();   }   void decJ() {     if (invJ)       _incJ();     else       _decJ();   }   void incJ() {     if (invJ)       _decJ();     else       _incJ();   }   S merge() {     res.v.clear();     res.from = 0;     int i = ver.from;     int j = hor.from;     int n = (int)ver.v.size() + 1;     int m = (int)hor.v.size() + 1;     assert(i % 2 == j % 2);     invI = invJ = false;     if (i % 2 == 1) {       for (int jj = j; jj >= 0; --jj) {         if (jj & 1) {           for (int _ = 0; _ < (int)(i); ++_) decI();         } else {           for (int _ = 0; _ < (int)(i); ++_) incI();         }         if (jj != 0)           decJ();         else           incI();       }       for (int ii = i + 1; ii < n; ++ii) {         if (ii & 1) {           for (int _ = 0; _ < (int)(j); ++_) decJ();         } else {           for (int _ = 0; _ < (int)(j); ++_) incJ();         }         if (ii != n - 1)           incI();         else           incJ();       }       for (int jj = j + 1; jj < m; ++jj) {         if (jj & 1) {           for (int _ = 0; _ < (int)(n - 1); ++_) incI();         } else {           for (int _ = 0; _ < (int)(n - 1); ++_) decI();         }         if (jj != m - 1) incJ();       }     } else {       if (i == n - 1) {         i = 0;         invI = true;       }       if (j == 0) {         j = m - 1;         invJ = true;       }       for (int _ = 0; _ < (int)(i); ++_) decI();       decJ();       for (int ii = 0; ii < (int)(i + 1); ++ii) {         if (ii & 1) {           for (int _ = 0; _ < (int)(j - 1); ++_) incJ();         } else {           for (int _ = 0; _ < (int)(j - 1); ++_) decJ();         }         incI();       }       for (int jj = 0; jj < (int)(j + 1); ++jj) {         if (jj & 1) {           for (int _ = 0; _ < (int)(n - i - 2); ++_) decI();         } else {           for (int _ = 0; _ < (int)(n - i - 2); ++_) incI();         }         if (jj != j) incJ();       }       if (j != m - 1) {         incJ();         for (int jj = j + 1; jj < m; ++jj) {           if (jj & 1) {             for (int _ = 0; _ < (int)(n - 1); ++_) decI();           } else {             for (int _ = 0; _ < (int)(n - 1); ++_) incI();           }           if (jj != m - 1) incJ();         }       }     }     return res;   }   int main() {     cin >> n;     for (int i = 0; i < (int)(n); ++i) cin >> a[i];     for (int i = 0; i < (int)(n); ++i) cin >> b[i];     if (n == 1) {       if (a[0] == 2) {         cout <<  Cycle  << endl;         if (b[0] == 1) {           cout <<  inc 1  << endl;           cout <<  dec 1  << endl;         } else {           cout <<  dec 1  << endl;           cout <<  inc 1  << endl;         }       } else {         if (b[0] == 1) {           cout <<  Path  << endl;           for (int i = 0; i < (int)(a[0] - 1); ++i) {             cout <<  inc 1 n ;           }         } else if (b[0] == a[0]) {           cout <<  Path  << endl;           for (int i = 0; i < (int)(a[0] - 1); ++i) {             cout <<  dec 1 n ;           }         } else {           cout <<  No  << endl;         }       }       return 0;     }     for (int i = 0; i < (int)(n); ++i) ord[i] = i;     for (int i = 0; i < (int)(n - 1); ++i)       if (a[i] % 2 == 0) {         swap(a[i], a[n - 1]);         swap(b[i], b[n - 1]);         swap(ord[i], ord[n - 1]);         break;       }     if (a[n - 1] % 2 == 0) {       for (int i = 0; i < (int)(n - 1); ++i) {         nv.clear();         for (int j = 0; j < (int)(a[i]); ++j) {           if (j & 1) {             reverse(v.begin(), v.end());             for (pair<int, int> p : v) {               nv.push_back(make_pair(-p.first, p.second));             }             reverse(v.begin(), v.end());           } else {             for (pair<int, int> p : v) {               nv.push_back(p);             }           }           if (j != a[i] - 1) {             nv.push_back(make_pair(1, i));           }         }         v = nv;       }       nv.clear();       for (pair<int, int> p : v) {         nv.push_back(p);       }       for (int i = 0; i < (int)(a[n - 1] - 1); ++i) {         nv.push_back(make_pair(1, n - 1));         if (i & 1) {           for (int j = 1; j < (int)v.size(); ++j) {             nv.push_back(v[j]);           }         } else {           for (int j = (int)v.size() - 1; j >= 1; --j) {             nv.push_back(make_pair(-v[j].first, v[j].second));           }         }       }       nv.push_back(make_pair(-v[0].first, v[0].second));       for (int i = 0; i < (int)(a[n - 1] - 1); ++i) {         nv.push_back(make_pair(-1, n - 1));       }       for (int i = 0; i < (int)(n); ++i) c[i] = 1;       v = nv;       int ind = 0;       while (true) {         bool ok = true;         for (int j = 0; j < (int)(n); ++j)           if (c[j] != b[j]) {             ok = false;             break;           }         if (ok) break;         c[v[ind].second] += v[ind].first;         ++ind;       }       printf( Cycle n );       for (int i = ind; i < (int)v.size(); ++i) {         pr(v[i].first, v[i].second);       }       for (int i = 0; i < ind; ++i) {         pr(v[i].first, v[i].second);       }       return 0;     }     int sum = 0;     for (int i = 0; i < (int)(n); ++i) sum += b[i] - 1;     if (sum % 2 == 1) {       cout <<  No  << endl;       return 0;     }     cout <<  Path  << endl;     for (int i = 0; i < (int)(n); ++i) {       vector<pair<int, int> > cur;       for (int j = 0; j < (int)(a[i] - 1); ++j) {         cur.push_back(make_pair(1, i));       }       s.push_back(S(cur, b[i] - 1));     }     while ((int)s.size() > 1) {       bool done = false;       for (int i = 0; i < (int)(s.size()); ++i) {         for (int j = 0; j < (int)(i); ++j) {           if ((s[i].from + s[j].from) % 2 == 0) {             hor = s[i];             ver = s[j];             s[i] = merge();             swap(s[j], s.back());             s.pop_back();             done = true;             break;           }         }         if (done) {           break;         }       }       assert(done);     }     for (pair<int, int> p : s[0].v) {       pr(p.first, p.second);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3fffffff;   const int inf = -INF;   const int N = 100005;   const int M = 2005;   const int mod = 1000000007;   const double pi = acos(-1.0);   int mp1[N], mp2[N];   int main() {     int n, m;     int d, p;     char s[2];     scanf( %d %d , &n, &m);     memset(mp1, 0, sizeof(mp1));     memset(mp2, 0, sizeof(mp2));     for (int i = 1; i <= n; i++) {       scanf( %s %d %d , &s, &p, &d);       if (s[0] ==  S )         mp1[p] += d;       else         mp2[p] += d;     }     int k = 0, t = 0;     for (int it = 0; it < N, t < m; it++) {       if (it > 100000) break;       if (mp1[it] > 0) t++, k = it;     }     for (int j = k; j >= 0; j--)       if (mp1[j] > 0) printf( S %d %d n , j, mp1[j]);     t = 0;     for (int it = N; it >= 0 && t < m; it--) {       if (mp2[it] > 0) printf( B %d %d n , it, mp2[it]), t++;     }   }


#include <bits/stdc++.h>   using namespace std;   char arr[300001];   int main(void) {     int N;     scanf( %d , &N);     scanf( %s , arr);     int i;     char _max = 0;     int idx = -1;     for (i = 0; i < N; i++) {       if (_max < arr[i]) {         _max = arr[i];         idx = i;       }       if (idx != -1 && _max > arr[i]) {         printf( YES n );         printf( %d %d n , idx + 1, i + 1);         return 0;       }     }     printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mo = 1000000007;   const int Maxn = 1010;   int f[110000], g[110000];   int a[Maxn * 2], b[Maxn * 2];   int sum[110000];   char st[Maxn];   int n, m, cnt;   bool Check(int s) {     for (int i = 0; i < n; ++i)       if (a[s + i] != b[i]) return false;     return true;   }   void Update(int &x, int y) {     if (y < 0) y += mo;     x += y;     if (x >= mo) x -= mo;   }   int main() {     scanf( %s , st);     n = strlen(st);     for (int i = 0; i < n; ++i) a[i] = st[i] -  a ;     for (int i = 0; i < n; ++i) a[i + n] = a[i];     scanf( %s , st);     for (int i = 0; i < n; ++i) b[i] = st[i] -  a ;     scanf( %d , &m);     sum[0] = 1;     for (int i = 1; i <= m; ++i) sum[i] = (long long)sum[i - 1] * (n - 1) % mo;     f[0] = 0;     f[1] = 1;     for (int i = 2; i <= m; ++i) {       f[i] = sum[i - 1] - f[i - 1];       if (f[i] < 0) f[i] += mo;     }     g[0] = 1;     g[1] = 0;     for (int i = 2; i <= m; ++i) {       g[i] = sum[i - 1] - g[i - 1];       if (g[i] < 0) g[i] += mo;     }     if (!m) {       if (Check(0))         printf( 1 n );       else         printf( 0 n );       return 0;     }     int ans = 0;     if (Check(0)) Update(ans, g[m]);     for (int i = 1; i < n; ++i)       if (Check(i)) Update(ans, f[m]);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int w = 1, s = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = 0;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       s = (s << 1) + (s << 3) + ch -  0 ;       ch = getchar();     }     return w ? s : -s;   }   const int N = 1001;   struct point {     int x, y, num;   } p[N];   struct square {     int x, y, r;   } s[N];   int opp[N], bel[N];   bool num[N];   int n, m, k, ans;   vector<int> f[N];   bool cmp1(point a, point b) { return a.x < b.x; }   bool cmp2(square a, square b) { return a.x - a.r < b.x - b.r; }   bool solve(int x) {     if (x == 0) return 1;     return 0;   }   void content() {     n = read(), m = read(), k = read();     for (int i = 1; i <= n; i++) p[i].x = read(), p[i].y = read(), p[i].num = i;     sort(p + 1, p + n + 1, cmp1);     for (int i = 1; i <= n; i++) opp[p[i].num] = i;     for (int i = 1; i <= m; i++) {       s[i].r = read();       s[i].x = read(), s[i].y = read();     }     sort(s + 1, s + m + 1, cmp2);     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= n; j++) {         if (p[j].x < s[i].x - s[i].r) continue;         if (p[j].x > s[i].x + s[i].r) break;         int a = p[j].x, b = p[j].y, c = s[i].x, d = s[i].y;         double lc = sqrt(pow((a - c), 2) + pow((b - d), 2));         if (lc < s[i].r) f[p[j].num].push_back(i);       }     }     for (int i = 1; i <= k; i++) {       int x = read(), y = read();       for (int j = 0; j < f[x].size(); j++) num[f[x][j]] = solve(num[f[x][j]]);       for (int j = 0; j < f[y].size(); j++) num[f[y][j]] = solve(num[f[y][j]]);       for (int j = 1; j <= m; j++)         if (num[j]) ans++;       printf( %d n , ans);       ans = 0;       memset(num, 0, sizeof(num));     }   }   int main() {     content();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int k[3];   long long t[200000];   long long c[200000];   int n;   long long T[3];   long long nt[200000];   multiset<long long> s;   int main(void) {     for (int i = 0; i < 3; i++) scanf(  %d , &k[i]);     for (int i = 0; i < 3; i++) scanf(  %I64d , &T[i]);     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %I64d , &c[i]), nt[i] = c[i];     for (int i = 0; i < 3; i++) k[i] = min(k[i], n + 1);     for (int step = 0; step < 3; step++) {       s.clear();       for (int i = 0; i < k[step]; i++) {         s.insert(0ll);       }       for (int i = 0; i < n; i++) t[i] = nt[i];       for (int i = 0; i < n; i++) {         long long TM = max(*s.begin(), t[i]);         nt[i] = TM + T[step];         s.erase(s.begin());         s.insert(nt[i]);       }     }     long long ans = 0;     for (int i = 0; i < n; i++) {       ans = max(ans, nt[i] - c[i]);     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void print(T a) {     for (auto x : a) cout << x <<    ;     cout <<   n ;   }   void solve() {     int n, m;     cin >> n >> m;     char a[n][m];     short down[n][m], up[n][m];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];         down[i][j] = 0;         up[i][j] = 0;       }     }     short l[m], r[m];     for (int j = 0; j < m; j++) up[0][j] = 1;     int ans = 0;     for (int i = 1; i < n; i++) {       for (int j = 0; j < m; j++) {         if (j == 0 || (a[i][j - 1] != a[i][j]))           l[j] = j;         else           l[j] = l[j - 1];       }       for (int j = m - 1; j >= 0; j--) {         if (j == m - 1 || (a[i][j + 1] != a[i][j]))           r[j] = j;         else           r[j] = r[j + 1];       }       for (int j = 0; j < m; j++) {         int x = 1;         if (a[i - 1][j] == a[i][j]) x = up[i - 1][j] + 1;         x = min(x, j - l[j] + 1);         x = min(x, r[j] - j + 1);         up[i][j] = x;       }     }     for (int j = 0; j < m; j++) down[n - 1][j] = 1;     for (int i = n - 2; i >= 0; i--) {       for (int j = 0; j < m; j++) {         if (j == 0 || (a[i][j - 1] != a[i][j]))           l[j] = j;         else           l[j] = l[j - 1];       }       for (int j = m - 1; j >= 0; j--) {         if (j == m - 1 || (a[i][j + 1] != a[i][j]))           r[j] = j;         else           r[j] = r[j + 1];       }       for (int j = 0; j < m; j++) {         int x = 1;         if (a[i + 1][j] == a[i][j]) x = down[i + 1][j] + 1;         x = min(x, j - l[j] + 1);         x = min(x, r[j] - j + 1);         down[i][j] = x;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         short res = min(up[i][j], down[i][j]);         ans += res;       }     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     for (int i = 0; i < t; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 30;   const int p = 10000007;   pair<long long, int> c[500005];   pair<long long, long long> sum[500005];   int id[500005];   long long a[500005], b[500005], ans[500005];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = (int)1; i <= (int)n; i++) {       scanf( %I64d%I64d , &a[i], &b[i]);       c[i] = make_pair(a[i] - b[i], i);     }     sort(c + 1, c + n + 1);     for (int i = (int)1; i <= (int)n; i++) id[c[i].second] = i;     sum[0] = make_pair(0, 0);     sum[n + 1] = make_pair(0, 0);     for (int i = (int)1; i <= (int)n; i++)       sum[i].first = sum[i - 1].first + a[c[i].second];     for (int i = (int)n; i >= (int)1; i--)       sum[i].second = sum[i + 1].second + b[c[i].second];     for (int i = (int)1; i <= (int)n; i++)       ans[i] = a[i] * (n - id[i]) + b[i] * (id[i] - 1) + sum[id[i] - 1].first +                sum[id[i] + 1].second;     for (int times = (int)1; times <= (int)m; times++) {       int x, y;       scanf( %d%d , &x, &y);       if (id[x] < id[y])         ans[x] -= a[x] + b[y], ans[y] -= a[x] + b[y];       else         ans[x] -= a[y] + b[x], ans[y] -= a[y] + b[x];     }     for (int i = (int)1; i <= (int)n; i++) printf( %I64d  , ans[i]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a >> b;     string s;     cin >> s;     while (b--) {       for (int i = 0; i < a - 1; i++) {         if (s[i] ==  B  && s[i + 1] ==  G ) {           int t;           t = s[i];           s[i] = s[i + 1];           s[i + 1] = t;           i++;         }       }     }     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int abss(int n) {     if (n < 0)       return -n;     else       return n;   }   const int maxn = 3e5 + 10;   int _min(int a, int b) {     if (a < b)       return a;     else       return b;   }   int _max(int a, int b) {     if (a > b)       return a;     else       return b;   }   char s[maxn];   int main() {     int a, b, x;     cin >> a >> b >> x;     int w = _min(a, b);     if (a > b) {       int c0 = 0, c1 = 0;       int tail = 0;       printf( 0 );       c0++;       for (int i = 1; i <= x - 1; i++) {         if (i % 2 == 1)           printf( 1 ), c1++, tail = 1;         else           printf( 0 ), c0++, tail = 0;       }       if (tail == 0 || x - 1 == 0) {         int temp = a - c0;         while (temp--) printf( 0 );         temp = b - c1;         while (temp--) printf( 1 );       } else {         int temp = b - c1;         while (temp--) printf( 1 );         temp = a - c0;         while (temp--) printf( 0 );       }       printf(  n );     } else {       int c0 = 0, c1 = 0;       printf( 1 );       c1++;       int tail = 1;       for (int i = 1; i <= x - 1; i++) {         if (i % 2 == 1)           printf( 0 ), c0++, tail = 0;         else           printf( 1 ), c1++, tail = 1;       }       if (tail == 0 && x - 1 != 0) {         int temp = a - c0;         while (temp > 0) printf( 0 ), temp--;         temp = b - c1;         while (temp > 0) printf( 1 ), temp--;       } else {         int temp = b - c1;         while (temp > 0) printf( 1 ), temp--;         temp = a - c0;         while (temp > 0) printf( 0 ), temp--;       }       printf(  n );     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int nn[2000000];   int ans[2000000];   string ss;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> nn[i];     int se = 0, en = n - 1;     int noa = 0;     ans[noa] = 0;     while ((nn[se] > ans[noa] || nn[en] > ans[noa]) && en != se) {       if (nn[se] > ans[noa] && nn[se] < nn[en]) {         ans[++noa] = nn[se];         se++;         ss.append( L );       } else if (nn[en] > ans[noa]) {         ans[++noa] = nn[en];         en--;         ss.append( R );       } else {         ans[++noa] = nn[se];         se++;         ss.append( L );       }     }     if (en == se)       if (nn[se] > ans[noa]) {         noa++;         ss.append( L );       }     cout << noa << endl;     cout << ss << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 355001;   const int SQRTN = 320;   const int LOGN = 20;   const long double PI = acos(-1);   const long double TAU = 2 * PI;   int n, a[N], idx[N], last, m, an[N];   long long ans;   signed main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       scanf( %d , a + i);       idx[a[i]] = i;       an[i] = n + 1;     }     for (int j = 0, x, y; j < m; j++) {       scanf( %d%d , &x, &y);       if (idx[x] > idx[y]) swap(x, y);       an[idx[x]] = min(an[idx[x]], idx[y]);     }     int x = n + 1;     ans = -(n * 1ll * (n + 1)) >> 1;     for (int i = n; i > 0; i--) x = min(x, an[i]), ans += x;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   void propagate(int node, const map<int, set<int> >& idToChildren,                  set<int>& leaves) {     map<int, set<int> >::const_iterator it = idToChildren.find(node);     if (it == idToChildren.end()) {       leaves.insert(node);       return;     }     const set<int>& s = (*it).second;     for (set<int>::const_iterator cit = s.begin(); cit != s.end(); ++cit) {       propagate(*cit, idToChildren, leaves);     }   }   int main() {     int n;     cin >> n;     int f[n + 1];     char visited[n + 1];     char inLoop[n + 1];     int tag[n + 1];     char hasParent[n + 1];     char hasChild[n + 1];     for (int i = 1; i <= n; i++) {       cin >> f[i];       visited[i] = inLoop[i] = 0;       tag[i] = i;       hasParent[i] = hasChild[i] = 0;     }     for (int i = 1; i <= n; i++) {       if (visited[i]) continue;       bool found = false;       set<int> traversed;       visited[i] = 1;       traversed.insert(i);       int x = i;       int confluence = -1;       while (1) {         int xTemp = f[x];         if (inLoop[xTemp]) {           f[x] = tag[xTemp];           break;         } else if (traversed.find(xTemp) != traversed.end()) {           found = true;           confluence = xTemp;           break;         } else if (visited[xTemp]) {           break;         } else {           x = xTemp;           visited[x] = 1;           traversed.insert(x);         }       }       if (found) {         int y = confluence;         do {           tag[y] = confluence;           inLoop[y] = 1;           y = f[y];         } while (y != confluence);       }     }     map<int, set<int> > idToChildren;     map<int, set<int> > rootToLeaves;     for (int i = 1; i <= n; i++) {       if (inLoop[i]) continue;       hasParent[i] = hasChild[f[i]] = 1;       idToChildren[f[i]].insert(i);     }     set<int> roots;     set<int> leaves;     for (int i = 1; i <= n; i++) {       if (tag[i] != i) continue;       if (!hasParent[i]) {         roots.insert(i);       }       if (!hasChild[i]) {         leaves.insert(i);       }     }     for (set<int>::const_iterator it = roots.begin(); it != roots.end(); ++it) {       propagate(*it, idToChildren, rootToLeaves[*it]);     }     if (leaves.size() == 1 && *leaves.begin() == *roots.begin()) {       cout << 0 << endl;       return 0;     }     cout << leaves.size() << endl;     int firstRoot = *roots.begin();     int prevRoot = firstRoot;     {       set<int>::const_iterator it = roots.begin();       advance(it, 1);       for (; it != roots.end(); ++it) {         for (set<int>::const_iterator lit = rootToLeaves[*it].begin();              lit != rootToLeaves[*it].end(); ++lit) {           cout << prevRoot <<     << *lit << endl;         }         prevRoot = *it;       }     }     for (set<int>::const_iterator it = rootToLeaves[firstRoot].begin();          it != rootToLeaves[firstRoot].end(); ++it) {       cout << prevRoot <<     << *it << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, i = 0;     cin >> n;     for (i = n + 1; i <= (2 * n); i++) cout << i <<    ;     return (0);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 600010, inf = N;   int n, m;   int head[N], cnt = 1;   struct edge {     int to, next;   } e[N << 1];   void adde(int a, int b) {     e[++cnt].to = b;     e[cnt].next = head[a];     head[a] = cnt;   }   int nxt[N], st[N], vis[N], top, mn, mx, in[N];   void dfs(int k, int fa) {     vis[k] = 1;     st[++top] = k;     for (int i = head[k]; i; i = e[i].next) {       int v = e[i].to;       if (v == fa) continue;       if (!vis[v])         dfs(v, k);       else if (!in[v]) {         mx = 0;         mn = inf;         while (top) {           mx = max(st[top], mx);           mn = min(mn, st[top]);           in[st[top]] = 1;           top--;           if (st[top + 1] == v) break;         }         nxt[mn] = min(nxt[mn], mx);       }     }     if (!in[k]) top--;   }   long long sum[N];   int main() {     scanf( %d%d , &n, &m);     int u, v, q;     for (int i = 1; i <= m; i++) {       scanf( %d%d , &u, &v);       adde(u, v);       adde(v, u);     }     for (int i = 1; i <= n + 1; i++) nxt[i] = n + 1;     for (int i = 1; i <= n; i++)       if (!vis[i]) dfs(i, 0);     for (int i = n; i; i--) nxt[i] = min(nxt[i + 1], nxt[i]);     for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + nxt[i];     scanf( %d , &q);     int L, R;     while (q--) {       scanf( %d%d , &L, &R);       int l = L, r = R, res = L - 1;       while (l <= r) {         int mid = l + r >> 1;         if (nxt[mid] > R)           r = mid - 1;         else           l = mid + 1, res = mid;       }       printf( %lld n , 1ll * (R - res) * (R - res + 1) / 2 + sum[res] -                            sum[L - 1] - 1ll * (res + L) * (res - L + 1) / 2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s1, s2;     cin >> s1 >> s2;     int a, b, c, d;     a = s1[0] -  0 ;     b = s1[1] -  0 ;     c = s2[1] -  0 ;     d = s2[0] -  0 ;     vector<int> v1({a, b, c, d});     map<vector<int>, int> mp;     mp[{a, b, c, d}] = 1;     n--;     while (n--) {       string s;       cin >> s;       cin >> s1 >> s2;       a = s1[0] -  0 ;       b = s1[1] -  0 ;       c = s2[1] -  0 ;       d = s2[0] -  0 ;       vector<int> v1({a, b, c, d});       vector<int> v2({b, c, d, a});       vector<int> v3({c, d, a, b});       vector<int> v4({d, a, b, c});       if (mp.find({a, b, c, d}) != mp.end()) {         continue;       } else if (mp.find({b, c, d, a}) != mp.end()) {         continue;       } else if (mp.find({c, d, a, b}) != mp.end()) {         continue;       } else if (mp.find({d, a, b, c}) != mp.end()) {         continue;       } else         mp[{a, b, c, d}] = 1;     }     cout << mp.size() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     long long t, j = 0;     cin >> t;     cin >> s;     for (long long i = 0; i < s.size(); i++) {       if (s[i] ==  F )         if (s[i + 1] ==  S ) j--;       if (s[i] ==  S )         if (s[i + 1] ==  F ) j++;     }     if (j <= 0)       cout <<  NO ;     else if (j > 0)       cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mas[1010][1010];   int mas1[1001][1001];   bool check(int i, int j) {     return mas[i][j] && mas[i + 1][j] && mas[i + 2][j] && mas[i + 2][j + 1] &&            mas[i + 2][j + 2] && mas[i + 1][j + 2] && mas[i][j + 2] &&            mas[i][j + 1];   }   void draw(int i, int j) {     mas1[i][j] = mas1[i + 1][j] = mas1[i + 2][j] = mas1[i + 2][j + 1] =         mas1[i + 2][j + 2] = mas1[i + 1][j + 2] = mas1[i][j + 2] =             mas1[i][j + 1] = 1;   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) {         char temp;         cin >> temp;         if (temp ==  # )           mas[i][j] = 1;         else           mas[i][j] = 0;       }     for (int i = 1; i <= n - 2; ++i)       for (int j = 1; j <= m - 2; ++j) {         if (check(i, j)) draw(i, j);       }     bool f = 1;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) {         if (mas[i][j] && !mas1[i][j]) f = 0;       }     if (f)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2004;   int pa[N];   int n, m, x, y, op, pos = 1, ans = 0;   pair<int, int> p[N];   bool b[N];   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n * 2; i++) {       scanf( %d , &p[i].first);       p[i].second = i;     }     for (int i = 0; i < m; i++) {       scanf( %d %d , &x, &y);       pa[x] = y;       pa[y] = x;     }     sort(p + 1, p + 2 * n + 1, greater<pair<int, int> >());     scanf( %d , &op);     for (int i = 1; i <= n; i++) {       if (op == 1) {         bool g = 0;         for (int i = pos; i <= 2 * n; i++)           if (!b[p[i].second] && pa[p[i].second] != 0) {             ans = p[i].second;             g = 1;             break;           }         if (!g) {           for (; pos <= 2 * n && b[p[pos].second]; ++pos)             ;           ans = p[pos].second;         }         b[ans] = 1;         cout << ans << endl;         scanf( %d , &x);         b[x] = 1;       } else {         scanf( %d , &x);         b[x] = 1;         if (pa[x] == 0 || b[pa[x]]) {           bool g = 0;           for (int i = pos; i <= 2 * n; i++)             if (!b[p[i].second] && pa[p[i].second] != 0) {               ans = p[i].second;               g = 1;               break;             }           if (!g) {             for (; pos <= 2 * n && b[p[pos].second]; ++pos)               ;             ans = p[pos].second;           }         } else {           ans = pa[x];           b[pa[x]] = 1;         }         b[ans] = 1;         cout << ans << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     vector<int> segs;     int numNeg = 0;     int curLen = 0;     for (int i = 0; i < n; i++) {       int a;       scanf( %d , &a);       if (a < 0) {         if (numNeg == 2) {           segs.push_back(curLen);           curLen = 1;           numNeg = 1;         } else {           numNeg += 1;           curLen += 1;         }       } else {         curLen += 1;       }     }     if (curLen != 0) {       segs.push_back(curLen);     }     printf( %d n , segs.size());     for (int s : segs) {       printf( %d  , s);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000, INF = 2000000000;   struct edge {     int x;     int y;     int w;     int o;   };   vector<vector<edge> > G(MAXN + 1);   int n, m, depth[MAXN + 1], low[MAXN + 1], s, t, previous[MAXN + 1],       prevCost[MAXN + 1], cntEdges[MAXN + 1][MAXN + 1], c, sons[MAXN + 1],       p1 = -1, p2;   bool vis[MAXN + 1];   edge removedEdge = {0, 0, 0, -1}, e1, e2, prevEdge[MAXN + 1];   vector<edge> edgesOnPath, currentPath, allEdges;   bool eq(edge a, edge b) {     return a.w == b.w && min(a.x, a.y) == min(b.x, b.y) &&            max(a.x, a.y) == max(b.x, b.y);   }   void redo() {     memset(prevCost, 0, sizeof(prevCost));     memset(previous, 0, sizeof(previous));     memset(vis, 0, sizeof(vis));     memset(depth, 0, sizeof(depth));     memset(low, 0, sizeof(low));     memset(sons, 0, sizeof(sons));     currentPath.clear();   }   bool isBridge(edge e) {     if (cntEdges[e.x][e.y] == 1) {       if (low[e.x] > depth[e.y] || low[e.y] > depth[e.x]) return true;     } else {       if (cntEdges[e.x][e.y] != 2) return false;       if (min(removedEdge.x, removedEdge.y) != min(e.x, e.y) ||           max(removedEdge.x, removedEdge.y) != max(e.x, e.y))         return false;       if (low[e.x] > depth[e.y] || low[e.y] > depth[e.x]) return true;     }     return false;   }   int getEdgeOrder(edge e) {     for (int i = 0; i < allEdges.size(); i++)       if (eq(e, allEdges[i]) == true && (i + 1 != p1)) return i + 1;   }   void dfs(int node) {     vis[node] = true;     for (int i = 0; i < G[node].size(); i++) {       int nextNode = G[node][i].y;       if (G[node][i].o != removedEdge.o) {         if (vis[nextNode] == false) {           sons[node]++;           depth[nextNode] = depth[node] + 1;           low[nextNode] = depth[nextNode];           previous[nextNode] = node;           prevCost[nextNode] = G[node][i].w;           prevEdge[nextNode] = G[node][i];           dfs(nextNode);           low[node] = min(low[node], low[nextNode]);         } else {           if (previous[node] != nextNode)             low[node] = min(low[node], low[nextNode]);         }       }     }   }   void findPath(int x, int y, vector<edge> &e) {     int node = t;     while (node != x) {       e.push_back(prevEdge[node]);       node = previous[node];     }   }   int answer = -1;   void solve() {     if (m == 0) {       cout << 0 << endl << 0;       return;     }     dfs(s);     if (vis[t] == false) {       cout << 0 << endl << 0;       return;     }     findPath(s, t, edgesOnPath);     for (int i = 0; i < edgesOnPath.size(); i++)       if (isBridge(edgesOnPath[i]) == true) {         if (answer == -1 || answer > edgesOnPath[i].w) {           answer = edgesOnPath[i].w;           c = 1;           e1 = edgesOnPath[i];         }       }     for (int i = 0; i < edgesOnPath.size(); i++) {       removedEdge = edgesOnPath[i];       redo();       dfs(s);       if (vis[t] == true) findPath(s, t, currentPath);       for (int j = 0; j < currentPath.size(); j++)         if (isBridge(currentPath[j]) == true) {           if (answer == -1 || removedEdge.w + currentPath[j].w < answer) {             answer = removedEdge.w + currentPath[j].w;             c = 2;             e1 = removedEdge;             e2 = currentPath[j];           }         }     }     cout << answer << endl;     if (c != 0) cout << c << endl;     if (c == 1) cout << e1.o;     if (c == 2) {       cout << e2.o <<     << e1.o;     }   }   void readData() {     scanf( %d %d %d %d , &n, &m, &s, &t);     for (int i = 1; i <= m; i++) {       int x, y, w;       scanf( %d %d %d , &x, &y, &w);       allEdges.push_back({min(x, y), max(x, y), w, i});       if (x != y) {         cntEdges[x][y]++;         cntEdges[y][x]++;         G[x].push_back({x, y, w, i});         G[y].push_back({y, x, w, i});         G[x][G[x].size() - 1].o = i;         G[y][G[y].size() - 1].o = i;       }     }   }   int main() {     readData();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     long long p;     cin >> p;     long long keys[2001], people[1001];     for (int i = 0; i < n; i++) cin >> people[i];     for (int i = 0; i < k; i++) cin >> keys[i];     sort(keys, keys + k);     sort(people, people + n);     long long fin = 3e9;     for (int i = 0; i + n <= k; i++) {       long long ans = -1;       for (int j = 0; j < n; j++)         ans = max(ans, abs(people[j] - keys[i + j]) + abs(keys[i + j] - p));       fin = min(fin, ans);     }     cout << fin << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[100100], d[100100];   int main() {     cin >> n;     int mn = 1000111222, mx = 0;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       mn = min(mn, a[i]);       mx = max(mx, a[i]);     }     for (int i = 0; i < n; i++) {       a[i] -= mn;       if (a[i] > n) {         puts( NO );         return 0;       }       d[a[i]]++;     }     mx -= mn;     d[0]--;     d[mx]--;     for (int i = 1; i <= mx - 1; i++)       if (d[i] < 2) {         puts( NO );         return 0;       } else         d[i] -= 2;     for (int i = 0; i <= mx; i++)       if (d[i]) {         if (d[i] > d[i + 1]) {           puts( NO );           return 0;         }         d[i + 1] -= d[i];       }     puts( YES );   }


#include <bits/stdc++.h>   using namespace std;   void read() { freopen( input.txt ,  r , stdin); }   bool check(string s) {     long long ans = s[0] -  0 ;     ans = ans * 10ll + (s[1] -  0 );     if (ans % 4 == 0) return true;     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     long long ans = 0;     for (long long i = 0; i < (long long)s.size(); i++) {       if ((s[i] -  0 ) % 4 == 0) ans++;     }     string temp =   ;     for (long long i = 0; i < (long long)s.size() - 1; i++) {       temp += s.substr(i, 2);       if (check(temp)) {         ans += i + 1;       }       temp =   ;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   inline long long quick(long long mul, long long b) {     long long c = 1;     while (b) {       if (b & 1) {         c = c * mul % mod;       }       mul = mul * mul % mod;       b /= 2;     }     return c;   }   int main() {     long long n, m;     cin >> n >> m;     cout << (quick(2 * n + 2, m) * (n - m + 1) % mod) * quick(n + 1, mod - 2) %                 mod;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace FGF {   int n, m;   int read() {     int s = 0, w = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) w = -w;       ch = getchar();     }     while (isdigit(ch)) {       s = s * 10 + ch -  0 ;       ch = getchar();     }     return s * w;   }   const int N = 1e5 + 5;   const int mo = 1e9 + 7;   char s[N];   int num[60];   inline int getnum(char c) { return c >=  a  ? c -  a  + 1 : c -  A  + 27; }   long long f[N], fac[N], inv[N], g[N], h[N], ans[60][60];   void init() {     fac[0] = inv[0] = inv[1] = 1;     for (int i = 1; i <= n / 2; i++) fac[i] = fac[i - 1] * i % mo;     for (int i = 2; i <= n / 2; i++) inv[i] = inv[mo % i] * (mo - mo / i) % mo;     for (int i = 2; i <= n / 2; i++) inv[i] = inv[i - 1] * inv[i] % mo;   }   void work() {     scanf( %s , s + 1);     n = strlen(s + 1);     for (int i = 1; i <= n; i++) num[getnum(s[i])]++;     init();     f[0] = 1;     for (int i = 1; i <= 52; i++)       for (int j = n / 2; j >= num[i]; j--)         if (num[i]) f[j] = (f[j] + f[j - num[i]]) % mo;     for (int i = 1; i <= 52; i++)       if (num[i]) {         ans[i][i] = f[n / 2];         for (int j = 0; j <= n / 2; j++)           if (j >= num[i])             g[j] = (f[j] - g[j - num[i]] + mo) % mo;           else             g[j] = f[j];         for (int j = i + 1; j <= 52; j++)           if (num[j]) {             for (int k = 0; k <= n / 2; k++)               if (k >= num[j])                 h[k] = (g[k] - h[k - num[j]] + mo) % mo;               else                 h[k] = g[k];             ans[j][i] = ans[i][j] = h[n / 2] * 2 % mo;           }       }     long long res = fac[n / 2] * fac[n / 2] % mo;     for (int i = 1; i <= 52; i++) res = res * inv[num[i]] % mo;     m = read();     while (m--) {       int x = read(), y = read();       printf( %lld n , res * ans[getnum(s[x])][getnum(s[y])] % mo);     }   }   }  // namespace FGF   int main() {     FGF::work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = (int)1e5 + 55;   const int INF = (int)1e9 + 77;   const int MOD = (int)1e9 + 7;   const double PI = 2 * acos(0.0);   const double EPS = 1e-7;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m;     string s;     cin >> n >> m >> s;     for (int i = 0; i < m; ++i) {       int l, r;       char ch1, ch2;       cin >> l >> r >> ch1 >> ch2;       --l;       --r;       for (int j = l; j <= r; ++j) {         if (s[j] == ch1) s[j] = ch2;       }     }     cout << s <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct edge {     int t;     edge *next;   };   struct obj {     int v, a, b;     obj() {}     obj(int a0, int b0, int v0) { v = v0, a = a0, b = b0; }   };   inline bool cmpObj(obj a, obj b) { return a.v < b.v; }   const int maxn = 1010;   const int maxm = 4010;   obj o[maxm];   edge *ep, *head[maxn];   int n, m, v[maxn], vis[maxn], vo, s;   void addEdge(int u, int v) {     ep->t = v;     ep->next = head[u];     head[u] = ep++;   }   bool reach(int st, int te) {     queue<int> q;     q.push(st);     vis[st] = vo;     while (!q.empty() && vis[te] != vo) {       int p = q.front();       q.pop();       for (edge *g = head[p]; g; g = g->next)         if (vis[g->t] != vo) {           vis[g->t] = vo;           q.push(g->t);         }     }     return vis[te] == (vo++);   }   int main() {     memset(vis, -1, sizeof(vis));     vo = 0;     ep = new edge[maxm];     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , v + i);     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d%d , &a, &b);       o[i << 1] = obj(a, b, v[b]);       o[(i << 1) + 1] = obj(b, a, v[a]);     }     sort(o, o + m * 2, cmpObj);     s = 0;     for (int i = 0; i < m * 2; i++)       if (!reach(o[i].b, o[i].a)) {         s += o[i].v;         addEdge(o[i].a, o[i].b);       }     printf( %d n , s);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string in;     cin >> in;     int sz = in.size();     long long max = -1;     for (int i = 1; i <= sz - 2; i++) {       for (int j = 1; j <= sz - 1 - i; j++) {         long long x, y, z;         {           stringstream ss(in.substr(0, i));           ss >> x;         }         {           stringstream ss;           ss << in.substr(i, j);           ss >> y;         }         {           stringstream ss;           ss << in.substr(i + j, sz - i - j);           ss >> z;         }         if ((in.substr(0, i)[0] ==  0  && i > 1) ||             (in.substr(i, j)[0] ==  0  && j > 1) ||             (in.substr(i + j, sz - i - j)[0] ==  0  && sz - i - j > 1))           continue;         if (x <= 1000000 && y <= 1000000 && z <= 1000000 && x + y + z > max)           max = x + y + z;       }     }     cout << max;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = (1e5) + 15;   const int mod = (1e9) + 7;   const int inf = (1e9) + 3;   long long int n, k, ans;   string s;   long long int a[maxn];   int main() {     ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     ;     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 1; i < n; i++) {       if (a[i] + a[i - 1] < k)         ans += (k - a[i] - a[i - 1]), a[i] += (k - a[i] - a[i - 1]);     }     cout << ans << endl;     for (int i = 0; i < n; i++) cout << a[i] <<    ;     cout << endl;     return 0;   }


#include<bits/stdc++.h>   using namespace std;   typedef long long ll;   #define F first   #define S second   const int MXN = 200040;   int cnt[MXN];   bool b[MXN];      ll n,d;   int main(){          int t;       cin >> t;       while(t--){                      string s;           cin >> s;           int n = s.size();           int ans = 0;           bool b[n+3];           for(int i = 0 ; i < n+3 ; i++){               b[i] = 0;           }           for(int i = 1 ; i < n ; i++){               if(i == 1){                   if(s[i] == s[i-1]){                       b[i] = 1;                       ans++;                   }                   continue;               }               if(s[i] != s[i-1] && s[i] != s[i-2])continue;               if(s[i] == s[i-1] && s[i] == s[i-2]){                   if(b[i-1] && b[i-2])continue;                   b[i] = 1;                   ans++;                   continue;               }               if(s[i] == s[i-1] && s[i] != s[i-2]){                   if(b[i-1])continue;                   b[i] = 1;                   ans++;                   continue;               }               if(s[i] == s[i-2] && s[i] != s[i-1]){                   if(b[i-2])continue;                   b[i] = 1;                   ans++;                   continue;               }           }                      cout << ans <<   n ;                  }      }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   const int N = 1e6 + 5;   long long n, pw[N];   int t = 3;   void Solve() {     pw[n + 1] = 1;     for (long long i = n; i >= 3; i--) pw[i] = (pw[i + 1] * i) % mod;     long long res = 0;     res = (pw[3] * (n - 1)) % mod;     for (long long i = n - 2; i >= 1; i--) {       res = res + ((pw[t + 1] * (t - 1)) % mod * i) % mod;       t++;     }     cout << (res + 1) % mod <<   n ;   }   int main() {     cin >> n;     Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef long long ll;   typedef unsigned long long ull;   typedef unsigned int uint;   #define endl   n    #define lowbit(x) (x & -x)   #define ls(x) (x << 1)   #define rs(x) (x << 1 | 1)   #define ck(x) (x >= mod ? x - mod : x)   #define inf 0x3f3f3f3f   #define eps 1e-6   #define maxn 300200   #define maxm 10000100   #define G 3   #define invG 332748118   const int mod = 1e9 + 7;   const double PI = 4 * atan2(1.0, 1.0);   int t, n, dis1[maxn], dis2[maxn], dis3[maxn], dis4[maxn];   char s1[maxn], s2[maxn];   signed main() {       ios::sync_with_stdio(false);       cin.tie(nullptr);       cout.tie(nullptr);       cin >> t;       while (t--) {           cin >> n;           cin >> s1 + 1;           for (int i = 1; i <= n; i++) {               s2[i] = s1[i] ==  L  ?  R  :  L ;           }           for (int i = 0; i <= n; i++) {               dis1[i] = dis2[i] = dis3[i] = dis4[i] = 0;           }           dis1[0] = dis2[0] = 0;           for (int i = 1; i <= n; i++) {               if (s1[i] ==  L ) dis1[i] = dis2[i - 1] + 1;               if (s2[i] ==  L ) dis2[i] = dis1[i - 1] + 1;           }           dis3[n] = dis4[n] = 0;           for (int i = n; i >= 1; i--) {               if (s1[i] ==  R ) dis3[i - 1] = dis4[i] + 1;               if (s2[i] ==  R ) dis4[i - 1] = dis3[i] + 1;           }           for (int i = 0; i <= n; i++) {               cout << dis1[i] + dis3[i] + 1 <<    ;           }           cout << endl;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace rel_ops;   using ll = int64_t;   using Pii = pair<int, int>;   using ull = uint64_t;   using Vi = vector<int>;   void run();   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cout << fixed << setprecision(10);     run();     return 0;   }   int uplg(int n) { return 32 - __builtin_clz(n); }   int uplg(ll n) { return 64 - __builtin_clzll(n); }   int cmp(double a, double b, double eps = 1e-9) {     return (a > b + eps) - (a + eps < b);   }   char board[2001][2001];   int n, k;   int dp[2001][2001];   int lex[2001][2001];   bool toRight[2001][2001];   void run() {     cin >> n >> k;     for (int i = (0); i < (n); i++) cin >> board[i];     for (int i = (0); i < (n); i++)       for (int j = (0); j < (n); j++) {         if (i == 0 && j == 0) {           dp[i][j] = 0;         } else {           dp[i][j] = INT_MAX;         }         if (i > 0) {           dp[i][j] = min(dp[i][j], dp[i - 1][j]);         }         if (j > 0) {           dp[i][j] = min(dp[i][j], dp[i][j - 1]);         }         if (board[i][j] !=  a ) {           dp[i][j]++;         }       }     if (dp[n - 1][n - 1] <= k) {       for (int i = (0); i < (n * 2 - 1); i++) cout <<  a ;       cout << endl;       return;     }     lex[n][n] = 0;     Pii from{0, 0};     for (int sum = n * 2 - 1; sum >= 0; sum--) {       vector<pair<Pii, int>> pairs;       int best = INT_MAX;       Pii bestPos = {-1, -1};       for (int i = (0); i < (n); i++) {         int j = sum - i;         if (j < 0 || j >= n) continue;         int better = INT_MAX;         if (j + 1 < n) better = min(better, lex[i][j + 1]);         if (i + 1 < n) {           better = min(better, lex[i + 1][j]);           if (better == lex[i + 1][j]) toRight[i][j] = 1;         }         pairs.push_back({{board[i][j], better}, i});         if (dp[i][j] <= k) {           if (better < best) {             best = better;             bestPos = {i, j};           }         }       }       if (best < INT_MAX) {         from = bestPos;         if (toRight[bestPos.first][bestPos.second])           from.first++;         else           from.second++;         break;       }       sort((pairs).begin(), (pairs).end());       Pii last = {-1, -1};       int ind = 0;       for (auto& p : (pairs)) {         if (p.first != last) {           ind++;           last = p.first;         }         lex[p.second][sum - p.second] = ind;       }     }     for (int i = (0); i < (from.first + from.second); i++) cout <<  a ;     while (from.first != n - 1 || from.second != n - 1) {       cout << board[from.first][from.second];       if (toRight[from.first][from.second])         from.first++;       else         from.second++;     }     cout << board[n - 1][n - 1] << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, l;   double d;   double arr[1001];   int main() {     cin >> n >> l;     for (int i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     d = 0;     for (int i = 0; i < n - 1; i++) d = max(d, arr[i + 1] - arr[i]);     cout << fixed << setprecision(9) << max(d / 2, max(arr[0], l - arr[n - 1]));   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n > 36)       puts( -1 );     else {       int x = n / 2;       if (n & 1) printf( 4 );       while (x--) printf( 8 );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mod = 1e9 + 7;   const int N = 1005;   vector<pair<int, int>> graph[N];   vector<int> ans;   int vis[N];   int v[N];   void dfs(int pos) {     vis[pos] = 1;     v[pos] = 1;     for (auto& e : graph[pos]) {       if (vis[e.first] == 0) {         if (e.second == 0) {           int c = max(ans[e.first], ans[pos]);           ans[e.first] = c;           ans[pos] = c;         } else {           if (ans[e.first] <= ans[pos]) {             ans[e.first] = ans[pos] + 1;           }         }         dfs(e.first);       }     }     vis[pos] = 0;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       int n;       cin >> n;       string str;       cin >> str;       int cnt = 1;       for (int i = 0; i < n; i++) {         ans.push_back(1);       }       for (int i = 0; i < str.length(); i++) {         if (str[i] ==  = ) {           graph[cnt].push_back({cnt - 1, 0});           graph[cnt - 1].push_back({cnt, 0});         } else if (str[i] ==  L ) {           graph[cnt].push_back({cnt - 1, 1});         } else {           graph[cnt - 1].push_back({cnt, 1});         }         cnt++;       }       for (int i = 0; i < n; i++) {         if (v[i] == 0) {           dfs(i);         }       }       for (auto& e : ans) {         cout << e <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 0x3f3f3f3f3f3f3f3f;   const long long N = 5000;   long long n, m, s, t;   vector<pair<long long, long long> > nei[N + 1];   vector<long long> rv[N + 1];   void ae(long long x, long long y, long long z) {     nei[x].push_back(make_pair(y, z)), nei[y].push_back(make_pair(x, 0));     rv[x].push_back(nei[y].size() - 1), rv[y].push_back(nei[x].size() - 1);   }   long long dep[N + 1];   bool bfs() {     memset(dep, -1, sizeof(dep));     dep[s] = 0;     queue<long long> q;     q.push(s);     while (q.size()) {       long long x = q.front();       q.pop();       for (long long i = 0; i < nei[x].size(); i++) {         long long y = nei[x][i].first, c = nei[x][i].second;         if (c && !~dep[y]) dep[y] = dep[x] + 1, q.push(y);       }     }     return ~dep[t];   }   long long now[N + 1];   long long dfs(long long x = s, long long flw = inf) {     if (x == t || !flw) return flw;     long long res = 0, tmp;     for (long long &i = now[x]; i < nei[x].size(); i++) {       long long y = nei[x][i].first, &c = nei[x][i].second;       if (dep[y] == dep[x] + 1 && (tmp = dfs(y, min(flw, c)))) {         res += tmp, flw -= tmp;         c -= tmp, nei[y][rv[x][i]].second += tmp;         if (!flw) break;       }     }     return res;   }   long long dinic() {     long long res = 0;     while (bfs()) {       memset(now, 0, sizeof(now));       res += dfs();     }     return res;   }   long long a[N], b[N], c[N], d[N];   vector<long long> nums_x, nums_y;   void discrete() {     sort(nums_x.begin(), nums_x.end()), sort(nums_y.begin(), nums_y.end());     nums_x.resize(unique(nums_x.begin(), nums_x.end()) - nums_x.begin());     nums_y.resize(unique(nums_y.begin(), nums_y.end()) - nums_y.begin());     for (long long i = 1; i <= n; i++)       a[i] = lower_bound(nums_x.begin(), nums_x.end(), a[i] - 1) -              nums_x.begin() + 1,       b[i] = lower_bound(nums_y.begin(), nums_y.end(), b[i] - 1) -              nums_y.begin() + 1,       c[i] = lower_bound(nums_x.begin(), nums_x.end(), c[i]) - nums_x.begin(),       d[i] = lower_bound(nums_y.begin(), nums_y.end(), d[i]) - nums_y.begin();   }   long long row[N], col[N];   signed main() {     cin >> m >> n;     for (long long i = 1; i <= n; i++) {       cin >> a[i] >> b[i] >> c[i] >> d[i];       nums_x.push_back(a[i] - 1), nums_x.push_back(c[i]);       nums_y.push_back(b[i] - 1), nums_y.push_back(d[i]);     }     discrete();     s = 1, t = 2;     long long now = 2;     for (long long i = 1; i < nums_x.size(); i++)       row[i] = ++now, ae(s, now, nums_x[i] - nums_x[i - 1]);     for (long long i = 1; i < nums_y.size(); i++)       col[i] = ++now, ae(now, t, nums_y[i] - nums_y[i - 1]);     for (long long i = 1; i <= n; i++) {       for (long long j = a[i]; j <= c[i]; j++)         for (long long k = b[i]; k <= d[i]; k++) ae(row[j], col[k], inf);     }     cout << dinic();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int dp[50][2000], r[50], n;   const int inf = 1e6;   int abs(int a) { return a > 0 ? a : -a; }   int getTime(int id, int k) {     if (k <= 0) return 0;     if (dp[id][k]) return dp[id][k];     dp[id][k] = inf;     for (int i = 0; i < n; i++) {       if (s[i] == s[id] or r[i] <= r[id]) continue;       dp[id][k] = min(dp[id][k], abs(i - id) + getTime(i, k - r[i]));     }     return dp[id][k];   }   int solve(int st, int k) {     int ans = inf;     for (int id = 0; id < n; id++)       ans = min(ans, abs(st - id) + getTime(id, k - r[id]));     return ans == inf ? -1 : ans;   }   int main() {     int st, k;     cin >> n >> st >> k;     for (int i = 0; i < n; i++) cin >> r[i];     cin >> s;     cout << solve(st - 1, k) << endl;   }


#include <bits/stdc++.h>   using namespace std;   char s[1000500];   int ones[1000500], zeros[1000500], dp[1000500];   inline int solve(const vector<int> &vt) {     int n = vt.size();     int cnt = 0;     for (int i = 0; i < n; i++) {       if (!vt[i]) cnt++;       zeros[i] = cnt;     }     cnt = 0;     for (int i = n - 1; i >= 0; i--) {       ones[i] = cnt;       if (vt[i]) cnt++;     }     cnt = n;     for (int i = n - 1; i >= 0; i--) {       cnt = min(cnt, zeros[i] + ones[i]);       dp[i] = cnt;     }     int ret = n;     cnt = 0;     dp[n] = n;     for (int i = 0; i <= n; i++) {       ret = min(ret, dp[i] + cnt);       if (vt[i]) cnt++;       if (!vt[i]) cnt--;     }     return ret;   }   int main() {     int test;     scanf( %d , &test);     while (test--) {       int n, k;       scanf( %d %d , &n, &k);       scanf( %s , s);       int cnt = 0;       for (int i = 0; i < n; i++) {         if (s[i] ==  1 ) cnt++;       }       int ans = n;       for (int i = 0; i < k; i++) {         int tem = 0;         vector<int> vt;         for (int j = i; j < n; j += k) {           if (s[j] ==  1 ) tem++;           vt.push_back((int)s[j] -  0 );         }         ans = min(ans, solve(vt) + cnt - tem);       }       printf( %d n , ans);       ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void intialize() {     cin.tie(0);     ios_base::sync_with_stdio(0);     cout.tie(0);   }   void clearArr(int arr[], int n);   bool arr[105][105];   bool farr[105];   queue<int> q;   queue<int> done;   int main() {     intialize();     string ans[2] = { No ,  Yes };     string s;     cin >> s;     int ss = s.length(), i;     stack<int> st;     int t = 0;     for (i = 0; i < ss; ++i) {       if (st.empty())         st.push(s[i]);       else {         if (s[i] == st.top()) {           t = (t + 1) % 2;           st.pop();         } else {           st.push(s[i]);         }       }     }     cout << ans[t] << endl;   }   void clearArr(int arr[], int n) {     for (int i = 0; i < n; ++i) arr[i] = 0;   }


#include <bits/stdc++.h>   int f[10005], c, d, n, m, k;   inline int min(int x, int y) { return x < y ? x : y; }   int main() {     scanf( %d %d %d %d %d , &c, &d, &n, &m, &k);     if (n * m <= k) {       puts( 0 );       return 0;     }     memset(f, 0x3f, sizeof(f));     f[0] = 0;     for (int i = 1; i <= n * m; ++i) {       if (i >= n) f[i] = f[i - n] + c;       f[i] = min(f[i], f[i - 1] + d);     }     int ans = 0x3f3f3f3f;     for (int i = n * m - k; i <= n * m; ++i)       if (f[i] < ans) ans = f[i];     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e6 + 1;   struct node {     int ans = 0;     int o = 0;     int c = 0;     node() : ans(0), o(0), c(0) {}     node(int x) : ans(0), o((x == 1 ? 1 : 0)), c((x == 1 ? 0 : 1)) {}   };   node t[2 * MAX];   int n;   node combine(node x, node y) {     node cur;     int t = min(x.o, y.c);     cur.ans = t + x.ans + y.ans;     cur.o = x.o + y.o - t;     cur.c = x.c + y.c - t;     return cur;   }   int query(int l, int r) {     node resl, resr;     for (l += n, r += n; l < r; l >>= 1, r >>= 1) {       if (l & 1) resl = combine(resl, t[l++]);       if (r & 1) resr = combine(t[--r], resr);     }     return combine(resl, resr).ans;   }   int main() {     string s;     cin >> s;     n = s.length();     for (int i = 0; i < n; i++) {       int ch = (s[i] ==  (  ? 1 : 0);       t[i + n] = node(ch);     }     for (int i = n - 1; i > 0; i--) {       int x = i << 1;       int y = i << 1 | 1;       if (x > y) {         t[i] = combine(t[y], t[x]);       } else {         t[i] = combine(t[x], t[y]);       }     }     int m;     cin >> m;     for (int i = 0; i < m; i++) {       int l, r;       scanf( %d%d , &l, &r);       printf( %d n , query(l - 1, r) * 2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9;   const double eps = 1e-9;   const int N = 1 << 19;   const int P = (int)1e9 + 7;   const int Z = 239;   inline int add(int a, int b) {     a += b;     if (a >= P) a -= P;     return a;   }   int powP[2 * N];   inline int shift(int a, int n) { return (a * (long long)powP[n]) % P; }   int hash1[2 * N];   int hash2[2 * N];   int len[2 * N];   inline void upd(int x, int dx) {     x += N;     hash1[x] = dx;     hash2[x] = dx;     while (x > 1) {       x >>= 1;       hash1[x] = add(hash1[2 * x], shift(hash1[2 * x + 1], len[2 * x]));       hash2[x] = add(hash2[2 * x + 1], shift(hash2[2 * x], len[2 * x]));     }   }   int vleft[2 * N], vleftc = 0;   int vright[2 * N], vrightc = 0;   inline int get1(int l, int r) {     if (l > r) return 0;     l += N;     r += N;     vleftc = 0;     vrightc = 0;     while (l <= r) {       if ((l & 1) == 1) vleft[vleftc++] = l;       if ((r & 1) == 0) vright[vrightc++] = r;       l = (l + 1) >> 1;       r = (r - 1) >> 1;     }     int res = 0;     int toshift = 0;     for (int i = 0; i < vleftc; ++i) {       int v = vleft[i];       res = add(res, shift(hash1[v], toshift));       toshift += len[v];     }     for (int i = vrightc - 1; i >= 0; --i) {       int v = vright[i];       res = add(res, shift(hash1[v], toshift));       toshift += len[v];     }     return res;   }   inline int get2(int l, int r) {     if (l > r) return 0;     l += N;     r += N;     vleftc = 0;     vrightc = 0;     while (l <= r) {       if ((l & 1) == 1) vleft[vleftc++] = l;       if ((r & 1) == 0) vright[vrightc++] = r;       l = (l + 1) >> 1;       r = (r - 1) >> 1;     }     int res = 0;     int toshift = 0;     for (int i = 0; i < vrightc; ++i) {       int v = vright[i];       res = add(res, shift(hash2[v], toshift));       toshift += len[v];     }     for (int i = vleftc - 1; i >= 0; --i) {       int v = vleft[i];       res = add(res, shift(hash2[v], toshift));       toshift += len[v];     }     return res;   }   int a[N];   int main() {     powP[0] = 1;     for (int i = 1; i <= N; ++i) powP[i] = (powP[i - 1] * (long long)Z) % P;     for (int i = 2 * N - 1; i >= 1; --i) {       if (i >= N)         len[i] = 1;       else         len[i] = 2 * len[2 * i];     }     int n;     scanf( %d , &n);     for (int i = 0; (i) < (n); ++i) scanf( %d , &a[i]);     for (int i = 0; (i) < (n); ++i) a[i] -= 1;     bool res = false;     for (int i = 0; (i) < (n); ++i) {       int val = a[i];       if (val <= n - val - 1) {         int left = get1(0, val - 1);         int right = get2(val + 1, 2 * val);         if (left != right) {           res = true;         }       } else {         int left = get1(val - (n - 1 - val), val - 1);         int right = get2(val + 1, n - 1);         if (left != right) {           res = true;         }       }       upd(val, 1);     }     if (res)       printf( YES n );     else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long int a[n], sum = 0;     vector<int> v;     vector<int> u;     for (int i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];       if (a[i] > 0)         u.push_back(a[i]);       else         v.push_back(0 - a[i]);     }     if (sum > 0)       cout <<  first ;     else if (sum < 0)       cout <<  second ;     else {       int f = 0, m = u.size();       if (m > v.size()) m = v.size();       for (int i = 0; i < m; i++) {         if (v[i] < u[i]) {           f = 1;           break;         } else if (v[i] > u[i]) {           f = 2;           break;         }       }       if (!f) {         if (u.size() > v.size())           f = 1;         else if (u.size() < v.size())           f = 2;         else {           if (a[n - 1] > 0)             f = 1;           else             f = 2;         }       }       if (f == 1)         cout <<  first ;       else         cout <<  second ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     string sub;     for (int i = 0; i < k; i++) {       sub.push_back( k );     }     long long int count = 0;     set<string> arra;     for (int i = 0; i < n; i++) {       string a;       cin >> a;       arra.insert(a);     }     set<string>::iterator it1, it2;     for (it1 = arra.begin(); it1 != arra.end(); it1++) {       for (it2 = arra.begin(); it2 != arra.end(); it2++) {         string a = *it1;         string b = *it2;         if (a != b) {           for (int i = 0; i < k; i++) {             if (a[i] == b[i]) {               sub[i] = a[i];             } else if ((a[i] ==  S  && b[i] ==  T ) ||                        (a[i] ==  T  && b[i] ==  S )) {               sub[i] =  E ;             } else if ((a[i] ==  S  && b[i] ==  E ) ||                        (a[i] ==  E  && b[i] ==  S )) {               sub[i] =  T ;             } else if ((a[i] ==  E  && b[i] ==  T ) ||                        (a[i] ==  T  && b[i] ==  E )) {               sub[i] =  S ;             }           }           if (arra.find(sub) != arra.end()) {             count++;           }         }       }     }     cout << count / 6 << endl;   }


#include <bits/stdc++.h>   int a[100], i, j, maxim, h, l, n, b;   int main() {     scanf( %d , &n);     scanf( %d , &l);     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     i = 0;     j = 0;     b = 0;     h = l;     maxim = l;     while (i < n) {       if (l % a[i] == 0) {         h = l / a[i];       }       if (h < maxim) maxim = h;       i++;     }     printf( %d , maxim);   }


#include <bits/stdc++.h>   using namespace std;   int b[255];   int main() {     string a;     cin >> a;     for (int i = 0; i < a.size(); i++) {       b[a[i]]++;     }     int u = b[ a ] - 1 + b[ a ];     int u2 = a.size();     cout << min(u, u2);     return 0;   }


#include <bits/stdc++.h>   #define ll long long   #define real long double   #define fr(i,l,n) for(ll i=l;i<n;i++)   #define br cout<<  n    #define al(fu) (fu).begin(), (fu).end()   #define prl(c) cout<<(c)<<  n    #define prv(v) {fr(qz,0,v.size()) cout<<(v)[qz]<<   ; br;}   #define alr(fu) (fu).rbegin(), (fu).rend()   #define mod 1000000007LL   #define mod1 998244353LL   #define nfi 1000000000000000013LL   #define skoree ios::sync_with_stdio(0); cin.tie(0)   #define danet(b) cout<<(b? YES : NO )   #define Danet(b) cout<<(b? Yes : No )   using namespace std;      char aq(char a){       if(a== 0 ) return  1 ;       else return  0 ;   }      int main(){       skoree;       ll o0o;       cin>>o0o;       while(o0o--){           ll n;           cin>>n;           vector<string> a(n),b(n);           fr(i,0,n) cin>>a[i];           fr(i,0,n) cin>>b[i];           fr(i,0,n) if(a[0][i]!=b[0][i]){               fr(j,0,n) a[j][i]=aq(a[j][i]);           }           bool bb=1;           fr(i,1,n) if(a[i]!=b[i]){               fr(j,0,n) a[i][j]=aq(a[i][j]);               if(a[i]!=b[i]) bb=0;           }           danet(bb);br;       }       return 0;   }   /*   */