#include <bits/stdc++.h>   using namespace std;   struct edge {     int u, v, l, id;     edge() {}     edge(int a, int b, int c, int d) { u = a, v = b, l = c, id = d; }     bool operator<(const edge &p) const {       return l < p.l || (l == p.l && id < p.id);     }   };   char *p1, *p2, buffer[10000009];   int n, m, cur;   int l[1200009], r[1200009];   vector<int> v[1200009];   edge e[300009];   int ans[300009];   int f[100009], sz[100009];   pair<int, int> bf[29][100009], bsz[29][100009];   int tp[29];   void rd(int &x) {     char ch = 0;     x = 0;     while (ch <  0  || ch >  9 )       ch = (p1 == p2 && (p2 = (p1 = buffer) + fread(buffer, 1, 10000000, stdin),                          p1 == p2)                 ? EOF                 : *p1++);     while (ch >=  0  && ch <=  9 )       x = x * 10 + (ch & 15),       ch = (p1 == p2 && (p2 = (p1 = buffer) + fread(buffer, 1, 10000000, stdin),                          p1 == p2)                 ? EOF                 : *p1++);   }   int fnd(int x) { return x == f[x] ? x : fnd(f[x]); }   int uni(int d, int a, int b) {     a = fnd(a), b = fnd(b);     if (a == b) return 0;     if (sz[a] > sz[b]) swap(a, b);     int ret = 0;     if ((sz[a] & 1) && (sz[b] & 1)) ret = 2;     bf[d][++tp[d]] = pair<int, int>(a, f[a]);     bsz[d][tp[d]] = pair<int, int>(b, sz[b]);     f[a] = b;     sz[b] += sz[a];     return ret;   }   void roll(int d) {     for (int &i = tp[d]; i >= 1; i--) {       pair<int, int> tf = bf[d][i], tsz = bsz[d][i];       f[tf.first] = tf.second;       sz[tsz.first] = tsz.second;     }   }   void build(int a, int ll, int rr) {     l[a] = ll;     r[a] = rr;     if (ll < rr) {       int mid = (ll + rr) >> 1;       build(a << 1, ll, mid);       build(a << 1 | 1, mid + 1, rr);     }   }   void add(int a, int ll, int rr, int val) {     if (ll > rr) return;     if (l[a] > rr || r[a] < ll) return;     if (l[a] >= ll && r[a] <= rr) {       v[a].push_back(val);       return;     }     add(a << 1, ll, rr, val);     add(a << 1 | 1, ll, rr, val);   }   void solve(int d, int sm, int a) {     int tsm = sm;     for (int i = 0; i < (int)v[a].size(); i++) {       int p = v[a][i];       tsm -= uni(d, e[p].u, e[p].v);     }     if (l[a] != r[a])       solve(d + 1, tsm, a << 1 | 1), solve(d + 1, tsm, a << 1);     else {       while (cur <= m && tsm) {         cur++;         if (e[cur].id > l[a])           continue;         else {           tsm -= uni(d, e[cur].u, e[cur].v);           add(1, e[cur].id, l[a] - 1, cur);         }       }       ans[l[a]] = cur > m ? -1 : e[cur].l;     }     roll(d);   }   int main() {     rd(n), rd(m);     if (n & 1) {       for (int i = 1; i <= m; i++) printf( -1 n );       return 0;     }     for (int i = 1; i <= n; i++) f[i] = i, sz[i] = 1;     for (int i = 1, a, b, c; i <= m; i++) {       rd(a), rd(b), rd(c);       e[i] = edge(a, b, c, i);     }     sort(e + 1, e + m + 1);     build(1, 1, m);     solve(1, n, 1);     for (int i = 1; i <= m; i++) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, t;     cin >> s >> t;     vector<int> p;     int a[27] = {0};     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  ? ) {         p.push_back(i);       } else {         a[int(s[i]) - 96]++;       }     }     if (p.size() == 0) {       cout << s;       return 0;     }     int i = 0, j = 0;     while (j < p.size()) {       if (i == t.size()) {         i = 0;       }       if (a[int(t[i]) - 96] > 0) {         a[int(t[i]) - 96]--;       } else {         s[p[j]] = t[i];         j++;       }       i++;     }     cout << s << endl;   }


#include <bits/stdc++.h>   const int MAXN = 2e5 + 7;   int a[MAXN];   int main() {     int N;     scanf( %d , &N);     for (int i = 1; i <= N; ++i) scanf( %d , &a[i]);     int ans = 0;     int j = 1, i;     for (i = 2; i <= N;) {       while (i <= N && a[i] <= 2 * a[i - 1]) {         ++i;         ans = (ans > i - j ? ans : i - j);       }       j = i;       ++i;     }     ans = (ans > i - j ? ans : i - j);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 7, POWN = (1 << N), MOD = 1000 * 1000 * 1000 + 7;   int ans[POWN], res[POWN], a[POWN][POWN], b[POWN][POWN], c[POWN][POWN];   void powm(int p, int n) {     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         b[i][j] = a[i][j];         a[i][j] = (i == j);       }     while (p) {       if (p & 1) {         for (int i = 0; i < n; i++)           for (int j = 0; j < n; j++) {             c[i][j] = 0;             for (int k = 0; k < n; k++)               c[i][j] = (c[i][j] + (long long)a[i][k] * b[k][j]) % MOD;           }         for (int i = 0; i < n; i++)           for (int j = 0; j < n; j++) a[i][j] = c[i][j];       }       p >>= 1;       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++) {           c[i][j] = 0;           for (int k = 0; k < n; k++)             c[i][j] = (c[i][j] + (long long)b[i][k] * b[k][j]) % MOD;         }       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++) b[i][j] = c[i][j];     }   }   void mul(int n) {     for (int i = 0; i < n; i++) {       res[i] = 0;       for (int j = 0; j < n; j++)         res[i] = (res[i] + (long long)ans[j] * a[j][i]) % MOD;     }     for (int i = 0; i < n; i++) ans[i] = res[i];   }   int main() {     ios_base::sync_with_stdio(false);     ans[0] = 1;     for (int i = 0; i < N; i++) {       for (int j = 0; j < (1 << i); j++) {         ans[j | (1 << i)] = ans[j];         ans[j] = 0;       }       int w;       cin >> w;       if (!w) continue;       for (int j = 0; j < (1 << (i + 1)); j++)         for (int k = 0; k < (1 << (i + 1)); k++) {           a[j][k] = 0;           for (int l = 0; l < (1 << i); l++) {             int msk = ((1 << (i + 1)) | (l << 1) | 1);             bool ok = true;             for (int m = 0; m < i + 1; m++)               if ((j & (1 << m)) && (k & (1 << m)) && (msk & (1 << m)) &&                   (msk & (1 << (m + 1)))) {                 ok = false;                 break;               }             if (ok) a[j][k]++;           }         }       powm(w, 1 << (i + 1));       mul(1 << (i + 1));     }     cout << ans[(1 << N) - 1] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, s, t, g;   int dl[200009], head, last, q[20009];   int dep[20010];   int h[20010], top = 1;   struct edge {     int to, net;     long long w;   } es[200009];   void add(int u, int v, long long w) {     top++;     es[top].w = w;     es[top].net = h[u];     h[u] = top;     es[top].to = v;     return;   }   inline int read() {     int sum = 0, fh = 1;     char c = getchar();     while (c >  9  || c <  0 ) {       if (c ==  - ) fh = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       sum *= 10;       sum += c -  0 ;       c = getchar();     }     return sum * fh;   }   bool bfs() {     for (int i = 1; i <= t; i++) dep[i] = 0;     head = 1;     last = 1;     dl[1] = s;     dep[s] = 1;     while (head <= last) {       int u = dl[head];       head++;       for (int i = h[u]; i; i = es[i].net) {         if (dep[es[i].to] == 0 && es[i].w) {           dep[es[i].to] = dep[u] + 1;           last++;           dl[last] = es[i].to;         }       }     }     return dep[t];   }   long long ans = 0, ssm = 0;   long long dfs(int now, long long zg) {     if (now == t) {       return zg;     }     long long sum = 0;     for (int i = h[now]; i; i = es[i].net) {       int v = es[i].to;       if (dep[v] == dep[now] + 1 && es[i].w) {         long long res = dfs(v, min(es[i].w, zg));         sum += res;         zg -= res;         es[i].w -= res;         es[i ^ 1].w += res;       }     }     if (sum == 0) dep[now] = 0;     return sum;   }   int main() {     n = read();     m = read();     g = read();     s = 0;     t = n + m + 2;     for (int i = 1; i <= n; i++) q[i] = read();     for (int i = 1; i <= n; i++) {       int x = read();       if (q[i] == 0)         add(s, i, x), add(i, s, 0);       else         add(i, t, x), add(t, i, 0);     }     for (int i = 1; i <= m; i++) {       int opt = read(), w = read(), k = read();       ssm += w;       for (int j = 1; j <= k; j++) {         int x = read();         if (opt == 0) {           add(n + i, x, 1e18);           add(x, n + i, 0);         } else {           add(x, n + i, 1e18);           add(n + i, x, 0);         }       }       int gt = read();       if (opt == 0) {         add(s, n + i, w + g * gt);         add(n + i, s, 0);       } else {         add(n + i, t, w + g * gt);         add(t, n + i, 0);       }     }     while (bfs()) {       ans += dfs(s, 1e18);     }     cout << ssm - ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int r, c, n, mnm, x, y, ret = 0;     cin >> r >> c >> n >> mnm;     vector<vector<int> > mapa(r, vector<int>(c, 1));     for (int i = 0; i < n; i++) {       cin >> x >> y;       mapa[x - 1][y - 1] = 2;     }     for (int i = 1; i <= r; i++) {       for (int j = 1; j <= c; j++) {         for (int k = 0; k < r - (i - 1); k++) {           for (int l = 0; l < c - (j - 1); l++) {             int cnt = 0;             for (int m = 0; m < i; m++) {               for (int n = 0; n < j; n++) {                 if (mapa[k + m][l + n] == 2) cnt++;               }             }             if (cnt >= mnm) ret++;           }         }       }     }     cout << ret << endl;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<pair<long long, long long> > v(n);     for (long long i = 0; i < n; i++) {       cin >> v[i].first >> v[i].second;     }     long long sum = 0;     for (long long i = 0; i < n; i++) {       for (long long j = i + 1; j < n; j++) {         pair<long long, long long> p1 = v[i], p2 = v[j];         bool flag = true;         if (p1.first > p2.first || p1.first == p2.first && i < j) {           swap(p1, p2);           flag = false;         }         vector<pair<long long, pair<long long, long long> > > p(4);         if (flag) {           p[0] = {p1.first, {-i, 1}};           p[1] = {p1.first + p1.second, {-i, 2}};           p[2] = {p2.first, {-j, 3}};           p[3] = {p2.first + p2.second, {-j, 4}};         } else {           p[0] = {p1.first, {-j, 1}};           p[1] = {p1.first + p1.second, {-j, 2}};           p[2] = {p2.first, {-i, 3}};           p[3] = {p2.first + p2.second, {-i, 4}};         }         sort(p.begin(), p.end());         vector<long long> g(4);         for (long long h = 0; h < 4; h++) {           g[h] = p[h].second.second;         }         if (g[0] == 1 && g[2] == 2 && g[1] == 3 && g[3] == 4 ||             g[0] == 2 && g[2] == 1 && g[3] == 3 && g[1] == 4)           sum += 2;         else if (g[0] == 1 && g[3] == 2 || g[1] == 2 && g[2] == 1 ||                  g[1] == 1 && g[2] == 2 ||                  g[1] == 1 && g[2] == 3 && g[3] == 2 && g[0] == 4 ||                  g[0] == 1 && g[2] == 2 && g[3] == 3 && g[1] == 4)           sum++;       }     }     cout << sum;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const long long mod = 1e9 + 7;   const long long modd = 1;   const long long N = 1e5 + 5;   void solve() {     long long n, m;     cin >> n >> m;     long long a[n + 1][m + 1];     for (long long i = 0; i < n; i++)       for (long long j = 0; j < m; j++) cin >> a[i][j];     for (long long i = 0; i < n; i++) a[i][m] = a[i][m - 1] + 1;     for (long long i = 0; i < m; i++) a[n][i] = a[n - 1][i] + 1;     long long ans = 0;     for (long long i = n - 1; i >= 0; i = i - 1) {       for (long long j = m - 1; j >= 0; j = j - 1) {         if (a[i][j] == 0) a[i][j] = min(a[i + 1][j], a[i][j + 1]) - 1;         if (a[i][j] >= a[i + 1][j] || a[i][j] >= a[i][j + 1]) {           cout << -1;           return;         }         ans = ans + a[i][j];       }     }     cout << ans;   }   int32_t main() {     std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long t = 1;     for (long long i = 1; i <= t; i = i + 1) {       solve();       cout << endl;     }   }


#include <bits/stdc++.h>   int a, b, i, j, n;   std::string s;   bool isgood(int n) {     int i;     for (i = 2; i < n; i++)       if (n % i == 0) return false;     return true;   }   void sol() {     if (!isgood(b)) {       printf( NO  );       return;     }     for (i = a + 1; i < b; i++)       if (isgood(i)) {         printf( NO  );         return;       }     printf( YES  );   }   int main() {   #pragma comment(linker,  /STACK:16777216 )     while (scanf( %d %d  , &a, &b) != EOF) {       sol();     }   }


#include <bits/stdc++.h>   using namespace std;   long long par[200000];   long long ran[200000];   long long cnt[200000];   void init(long long n) {     for (long long i = 0; i <= n; i++) {       par[i] = i;       ran[i] = 0;     }   }   long long finds(long long x) {     if (par[x] == x)       return x;     else       return par[x] = finds(par[x]);   }   void unite(long long x, long long y) {     x = finds(x);     y = finds(y);     if (x == y) return;     if (ran[x] < ran[y]) {       par[x] = y;     } else {       par[y] = x;       if (ran[x] == ran[y]) ran[x]++;     }   }   long long quick_mod(long long a, long long n) {     long long tmp = a;     long long ans = 1;     while (n) {       if (n % 2 == 1) ans = (tmp * ans) % 1000000007;       n /= 2;       tmp = (tmp * tmp) % 1000000007;     }     return ans;   }   int main() {     long long n, k;     scanf( %lld%lld , &n, &k);     init(n);     for (long long i = 0; i < n - 1; i++) {       long long a, b, c;       scanf( %lld%lld%lld , &a, &b, &c);       if (c == 0) unite(a, b);     }     for (long long i = 1; i <= n; i++) {       finds(i);       cnt[par[i]]++;     }     long long ans = quick_mod(n, k);     for (long long i = 1; i <= n; i++) {       ans = (ans + 1000000007 - quick_mod(cnt[i], k)) % 1000000007;     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   const int P = 29;   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, k, cnt;   int a[20];   int main() {     n = read();     k = read();     for (int i = 1; i <= n; i++) {       int x = 0, base = 1;       for (int j = 1; j <= k; j++) {         int p = read();         x = x * base + p;         base *= 2;       }       bool flag = 0;       for (int j = 1; j <= cnt; j++)         if (a[j] == x) flag = 1;       if (!flag) a[++cnt] = x;     }     for (int i = 1; i <= cnt; i++)       for (int j = 1; j <= cnt; j++)         if ((a[i] & a[j]) == 0) {           cout <<  YES  << endl;           return 0;         }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int execute() {     int n;     cin >> n;     string s;     s.assign(n / 2 - 1,  1 );     if (n % 2) {       cout << 7;     } else {       cout << 1;     }     cout << s << endl;     return 0;   }   int TE = true;   bool mTest = true;   int main() {     ios_base::sync_with_stdio(false);     if (mTest) cin >> TE;     while (TE--) {       execute();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3 * 100010;   const int maxm = 3 * 100010;   const int BUFF = 10 * 1010 * 1010;   const int block = 400;   int n, m;   int ans[maxm];   struct DSU {     int fa[maxn], rk[maxn];     int *where[BUFF], val[BUFF];     int tot;     void init() {       tot = 0;       for (int i = 0; i <= n; i++) fa[i] = i, rk[i] = 1;     }     int Find(int x) { return x == fa[x] ? x : Find(fa[x]); }     int FastFind(int x) {       if (x == fa[x]) return x;       return fa[x] = Find(fa[x]);     }     void Union(int x, int y) {       int a = Find(x), b = Find(y);       if (a < b) swap(a, b);       val[tot] = rk[a];       where[tot++] = &rk[a];       val[tot] = fa[b];       where[tot++] = &fa[b];       assert(tot <= BUFF);       rk[a] += rk[b];       fa[b] = a;     }     void FastUnion(int x, int y) {       int a = Find(x), b = Find(y);       if (a < b) swap(a, b);       rk[a] += rk[b];       fa[b] = a;     }     void rollback() {       while (tot) {         *where[tot - 1] = val[tot - 1];         tot--;       }     }   };   DSU dsu;   struct Query {     int op, x, y;     int e0, e1;   };   Query q[maxm];   struct EDGE {     int u, v;     EDGE() {}     EDGE(int u, int v) : u(u), v(v) {}     bool operator<(const EDGE &rhs) const {       if (u == rhs.u) return v < rhs.v;       return u < rhs.u;     }   };   EDGE edge[maxm * 2];   map<EDGE, int> id;   vector<int> cur;   int addEdge(struct EDGE e) {     if (e.u > e.v) swap(e.u, e.v);     if (!id.count(e)) {       int k = id.size();       edge[k] = e;       id[e] = k;     }     return id[e];   }   int used[maxm * 2];   int state[maxm * 2];   void rebuild(int l) {     int r = min(l + block - 1, m);     dsu.init();     memset(used, 0, sizeof(used));     memset(state, 0, sizeof(state));     for (int i = 1; i < l; i++) {       if (q[i].op == 1) {         int e = ans[i - 1] == 1 ? q[i].e1 : q[i].e0;         used[e] = 1;         state[e] ^= 1;       }     }     for (int i = l; i <= r; i++) {       if (q[i].op == 1) {         used[q[i].e0] = used[q[i].e1] = 0;       }     }     cur.clear();     for (int i = 1; i < l; i++) {       int e = ans[i - 1] == 1 ? q[i].e1 : q[i].e0;       if (used[e] && state[e]) {         state[e] = 0;         dsu.FastUnion(edge[e].u, edge[e].v);       }       if (!used[e] && state[e]) {         state[e] = 0;         cur.push_back(e);       }     }   }   vector<int> ask;   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d %d %d , &q[i].op, &q[i].x, &q[i].y);       if (q[i].op == 1) {         EDGE e = EDGE(q[i].x % n + 1, q[i].y % n + 1);         q[i].e1 = addEdge(e);         e = EDGE((q[i].x - 1) % n + 1, (q[i].y - 1) % n + 1);         q[i].e0 = addEdge(e);       } else         ask.push_back(i);     }     for (int i = 1; i <= m; i++) {       if ((i - 1) % block == 0) {         rebuild(i);       }       if (q[i].op == 1) {         dsu.rollback();         int e = (ans[i - 1] == 1 ? q[i].e1 : q[i].e0);         auto it = find(cur.begin(), cur.end(), e);         if (it == cur.end())           cur.push_back(e);         else           cur.erase(it);         ans[i] = ans[i - 1];       } else {         for (int i = 0; i < (int)cur.size(); i++) {           int e = cur[i];           dsu.Union(edge[e].u, edge[e].v);         }         int u = (q[i].x + ans[i - 1] - 1) % n + 1;         int v = (q[i].y + ans[i - 1] - 1) % n + 1;         ans[i] = (dsu.Find(u) == dsu.Find(v));       }     }     for (int i = 0; i < (int)ask.size(); i++) {       printf( %d , ans[ask[i]]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class node>   struct link_cut_tree {     bool connected(node* u, node* v) { return lca(u, v) != NULL; }     int depth(node* u) {       access(u);       return get_sz(u->ch[0]);     }     node* get_root(node* u) {       access(u);       while (u->ch[0]) u = u->ch[0], u->push();       return access(u), u;     }     node* ancestor(node* u, int k) {       k = depth(u) - k;       assert(k >= 0);       for (;; u->push()) {         int sz = get_sz(u->ch[0]);         if (sz == k) return access(u), u;         if (sz < k)           k -= sz + 1, u = u->ch[1];         else           u = u->ch[0];       }       assert(0);     }     node* lca(node* u, node* v) {       if (u == v) return u;       access(u);       access(v);       if (!u->p) return NULL;       u->splay();       return u->p ?: u;     }     void link(node* u, node* v) {       make_root(v);       access(u);       set_link(v, u, 0);       v->update();     }     void cut(node* u) {       access(u);       u->ch[0]->p = NULL;       u->ch[0] = NULL;       u->update();     }     void cut(node* u, node* v) { cut(depth(u) > depth(v) ? u : v); }     void make_root(node* u) {       access(u);       u->reverse();       access(u);       assert(!u->ch[0] && !u->ch[1]);     }     void access(node* u) {       for (node *v = u, *pre = NULL; v; v = v->p) {         node* tmp = v;         while (!tmp->is_root()) tmp = tmp->p;         swap(v->parent, tmp->parent);         v->splay();         if (pre) v->update_vsub(pre, false);         if (v->ch[1]) v->update_vsub(v->ch[1], true);         v->ch[1] = pre;         v->update();         pre = v;       }       u->splay();       assert(!u->ch[1]);     }     node* operator[](int i) { return &data[i]; }     int operator[](node* i) { return i - &data[0]; }     vector<node> data;     link_cut_tree(int n) : data(n) {}   };   template <typename pnode>   struct splay_tree {     pnode ch[2], p;     splay_tree() { ch[0] = ch[1] = p = NULL; }     virtual void update() {}     virtual void push() {}     int dir() {       if (!p) return -2;       if (p->ch[0] == this) return 0;       if (p->ch[1] == this) return 1;       return -1;     }     bool is_root() { return dir() < 0; }     friend void set_link(pnode u, pnode v, int d) {       if (v) v->p = u;       if (d >= 0) u->ch[d] = v;     }     void rotate() {       assert(!is_root());       int x = dir();       pnode g = p;       set_link(g->p, static_cast<pnode>(this), g->dir());       set_link(g, ch[x ^ 1], x);       set_link(static_cast<pnode>(this), g, x ^ 1);       g->update();     }     void splay() {       while (!is_root() && !p->is_root()) {         p->p->push(), p->push(), push();         dir() == p->dir() ? p->rotate() : rotate();         rotate();       }       if (!is_root()) p->push(), push(), rotate();       push();       update();     }   };   template <typename pnode>   struct splay_tree_lct : splay_tree<pnode> {     using splay_tree<pnode>::ch;     bool rev;     splay_tree_lct() : splay_tree<pnode>() { rev = 0; }     virtual void update() override {}     virtual void push() override {       if (rev) {         if (ch[0]) ch[0]->reverse();         if (ch[1]) ch[1]->reverse();         rev = 0;       }     }     virtual void reverse() {       rev ^= 1;       swap(ch[0], ch[1]);     }   };   const int inf = -1e8;   template <typename pnode>   struct splay_tree_vchs : splay_tree<splay_tree_vchs<pnode>*> {     using splay_tree<splay_tree_vchs<pnode>*>::ch;     pnode key;     int x;     array<int, 4> y;     splay_tree_vchs(const pnode& key)         : splay_tree<splay_tree_vchs<pnode>*>(), key(key) {       build();     }     void build() {       x = key->x;       y[0] = key->pp[0];       y[1] = 0;       y[2] = key->pp[1];       y[3] = inf;     }     void update() override {       build();       for (int c = 0; c < 2; ++c)         if (ch[c]) {           x = max(x, ch[c]->x);           for (int i = 0; i < 4; i += 2) {             if (ch[c]->y[i] > y[i]) {               y[i + 1] = y[i];               y[i] = ch[c]->y[i];               if (ch[c]->y[i + 1] > y[i + 1]) y[i + 1] = ch[c]->y[i + 1];             } else if (ch[c]->y[i] > y[i + 1])               y[i + 1] = ch[c]->y[i];           }         }     }     void push() override {}     static void push_back(splay_tree_vchs*& u, const pnode& key) {       if (!u) {         u = new splay_tree_vchs(key);         return;       }       while (u->ch[1]) u = u->ch[1];       u->ch[1] = new splay_tree_vchs(key);       u->ch[1]->p = u;       u = u->ch[1];       u->splay();     }     static void erase(splay_tree_vchs*& u, splay_tree_vchs* v) {       v->splay();       if (!v->ch[0]) {         u = v->ch[1];       } else if (!v->ch[1]) {         u = v->ch[0];       } else {         u = v->ch[0];         u->p = NULL;         while (u->ch[1]) u = u->ch[1];         u->ch[1] = v->ch[1];         v->ch[1]->p = u;         u->splay();       }       if (u) u->p = NULL;       delete v;     }   };   const array<int, 4> ainf = {0, inf, 0, inf};   struct node : splay_tree_lct<node*> {     bool val, len, sval;     int slen;     int x;     array<int, 4> pp;     splay_tree_vchs<node*>*root, *parent;     node() : splay_tree_lct() {       root = parent = NULL;       val = len = sval = 0;       slen = x = 0;       pp = ainf;     }     void update() override {       splay_tree::update();       x = 0;       sval = val;       slen = len;       array<int, 4> up = ainf, dw = ainf;       array<int, 2> v1 = {0, inf}, v2 = v1;       bool upsval = val;       int upslen = len;       bool dwsval = val;       int dwslen = len;       if (ch[0]) {         x = max(x, ch[0]->x);         up = ch[0]->pp;         sval ^= ch[0]->sval;         slen += ch[0]->slen;         upsval ^= ch[0]->sval;         upslen += ch[0]->slen;       }       if (ch[1]) {         x = max(x, ch[1]->x);         dw = ch[1]->pp;         sval ^= ch[1]->sval;         slen += ch[1]->slen;         dwsval ^= ch[1]->sval;         dwslen += ch[1]->slen;       }       if (root) {         x = max(x, root->x);         v1[0] = root->y[0];         v1[1] = root->y[2];         v2[0] = root->y[1];         v2[1] = root->y[3];       }       pp[0] = up[0], pp[1] = up[1];       pp[2] = dw[2], pp[3] = dw[3];       for (int i = 0; i < 2; ++i) {         x = max(x, len + max({up[2 + i] + dw[i ^ val], up[2 + i] + v1[i ^ val],                               dw[i] + v1[i ^ val], v1[i] + v2[i ^ val]}));         pp[i ^ upsval] = max(pp[i ^ upsval], upslen + max(dw[i], v1[i]));         pp[2 + (i ^ dwsval)] =             max(pp[2 + (i ^ dwsval)], dwslen + max(up[2 + i], v1[i]));       }     }     void update_vsub(node* v, bool add) {       if (add) {         splay_tree_vchs<node*>::push_back(root, v);         v->parent = root;       } else {         splay_tree_vchs<node*>::erase(root, v->parent);         v->parent = NULL;       }     }     void push() override { splay_tree_lct::push(); }     void reverse() override {       splay_tree_lct::reverse();       swap(pp[0], pp[2]);       swap(pp[1], pp[3]);     }   };   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int n;     cin >> n;     link_cut_tree<node> lct(2 * n);     for (int i = 1, u, v, w; i < n; ++i) {       cin >> u >> v >> w;       --u, --v;       lct[n + i]->val = w;       lct[n + i]->len = true;       lct[n + i]->update();       lct.link(lct[u], lct[n + i]);       lct.link(lct[n + i], lct[v]);     }     int q;     cin >> q;     for (int i = 0, u; i < q; ++i) {       cin >> u;       lct.access(lct[n + u]);       lct[n + u]->val ^= 1;       lct[n + u]->update();       cout << lct[n + u]->x <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 5;   int n, m;   namespace BCC {   const int N = 202020;   vector<int> bcc[N];   vector<int> k;   int cnt, dfn[N], low[N], id[N], st[N], _st, _, to[N];   void dfs(int c, int dep, vector<int> g[]) {     int cc = 0;     st[_st++] = c;     dfn[c] = low[c] = dep;     for (auto t : g[c]) {       if (!dfn[t]) {         dfs(t, dep + 1, g);         low[c] = min(low[c], low[t]);       } else if (dfn[t] != dfn[c] - 1 || cc++)         low[c] = min(low[c], dfn[t]);     }     if (low[c] == dfn[c]) {       to[_] = st[_st - 1];       do {         id[st[--_st]] = _;       } while (st[_st] != c);       _++;     }   }   int solve(int n, vector<int> g[]) {     cnt = 0;     fill_n(dfn, n, _ = 0);     fill_n(low, n, _st = 0);     fill_n(bcc, n, vector<int>());     for (int i = (0); i < (n); i++)       if (!dfn[i]) dfs(i, 1, g), cnt++;     for (int i = (0); i < (n); i++)       for (auto j : g[i])         if (id[i] != id[j]) bcc[id[i]].push_back(id[j]);     return cnt;   }   }  // namespace BCC   vector<int> g[N];   int main() {     cin >> n >> m;     if (n == 2) {       cout << -1;       return 0;     }     for (int i = (1); i < (m + 1); i++) {       int u, v;       cin >> u >> v;       u--, v--;       g[u].push_back(v);       g[v].push_back(u);     }     BCC::solve(n, g);     int leaf = 0;     vector<int> s;     for (int i = (0); i < (BCC::_); i++) {       if ((int)BCC::bcc[i].size() == 1) leaf++, s.push_back(BCC::to[i] + 1);     }     int ans = (leaf + 1) / 2;     cout << ans <<   n ;     if (leaf & 1) ans--;     for (int i = ans; i <= leaf - 1; ++i)       cout << s[i] <<     << s[i - ans] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2548;   bool g[N][N], c[N][N], v[N][N];   int ng[N][N], sg[N][N], sc[N][N];   int c_square, c_circle, n;   template <class T>   inline T sqr(T x) {     return x * x;   }   int qx[N * N], qy[N * N], tcnt;   inline void solve(int x, int y) {     const int dx[4] = {0, 0, 1, -1}, dy[4] = {-1, 1, 0, 0};     int l(0), r(0);     pair<int, int> aux(x, y);     ++r;     qx[r] = x;     qy[r] = y;     v[x][y] = true;     while (l < r) {       ++l;       int cx(qx[l]), cy(qy[l]);       for (int i = 0; i < 4; ++i) {         int nx = cx + dx[i], ny = cy + dy[i];         if (!v[nx][ny] && g[nx][ny]) {           ++r;           qx[r] = nx;           qy[r] = ny;           v[nx][ny] = true;         }       }     }     int sqdmax(0), s(r);     if (s < 120) {       ++tcnt;       return;     }     for (int i = 1; i <= r; ++i) aux = min(aux, pair<int, int>(qx[i], qy[i]));     for (int i = 1; i <= r; ++i)       sqdmax = max(sqdmax, sqr(qx[i] - aux.first) + sqr(qy[i] - aux.second));     if (s < (double)sqdmax * 0.4 || s > (double)sqdmax * 0.86) return;     if (s > (double)sqdmax * 0.73)       ++c_circle;     else       ++c_square;   }   double calcRatio(int xl, int yl, int xr, int yr) {     return double(sg[xr][yr] - sg[xl - 1][yr] - sg[xr][yl - 1] +                   sg[xl - 1][yl - 1]) /            double(sc[xr][yr] - sc[xl - 1][yr] - sc[xr][yl - 1] +                   sc[xl - 1][yl - 1]);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) {         int t;         scanf( %d , &t);         g[i][j] = t;         c[i][j] = 1;         sg[i][j] = sg[i - 1][j] + sg[i][j - 1] - sg[i - 1][j - 1] + g[i][j];         sc[i][j] = sc[i - 1][j] + sc[i][j - 1] - sc[i - 1][j - 1] + c[i][j];       }     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) {         ng[i][j] |= calcRatio(i - 2, j - 2, i + 2, j + 2) > 0.9;         ng[i][j] |= calcRatio(i, j, i + 4, j + 4) > 0.6;         ng[i][j] |= calcRatio(i - 4, j - 4, i, j) > 0.6;         ng[i][j] |= calcRatio(i - 4, j, i, j + 4) > 0.6;         ng[i][j] |= calcRatio(i, j - 4, i + 4, j) > 0.6;       }     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) g[i][j] = ng[i][j];     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j)         if (!v[i][j] && g[i][j]) solve(i, j);     printf( %d %d n , c_circle, c_square);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 4;   int main() {     int n;     cin >> n;     int sum[101] = {0};     for (int i = 0, num; i < n; ++i) {       cin >> num;       sum[i + 1] = sum[i] + num;     }     if (sum[n] != 0) {       cout <<  YES n1 n ;       cout <<  1   << n << endl;       return 0;     }     int i;     for (i = 1; i < n; ++i) {       if (sum[i] != 0 && sum[n] - sum[i] != 0) break;     }     if (i == n)       cout <<  NO n ;     else {       cout <<  YES n2 n ;       cout <<  1   << i << endl;       cout << i + 1 <<     << n << endl;     }     return 0;   }


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


#include <bits/stdc++.h>   int main() {     int l, i, flag = 0;     char s[50];     scanf( %s , s);     l = strlen(s);     for (i = 0; i < l; i++) {       if (s[0] == s[i]) flag = flag + 1;     }     if (flag == l) {       printf( %d , 0);       return 0;     }     flag = 0;     for (i = 0; i < (l / 2); i++) {       if (s[i] != s[l - i - 1]) {         flag = flag + 1;         break;       }     }     if (flag == 0)       printf( %d , l - 1);     else       printf( %d , l);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int flag = 0, i, k;     string str, s;     cin >> str;     if (str.at(0) ==  - ) {       flag = 1;       str.erase(0, 1);     }     if (flag == 1) cout <<  ( ;     cout <<  $ ;     if ((int)str.find( . ) != -1)       s = str.substr(0, str.find( . ));     else       s = str.substr(0);     k = s.length() % 3;     for (i = 0; i < s.length(); i++) {       if (i % 3 == k && i != 0) cout <<  , ;       cout << str.at(i);     }     cout <<  . ;     if (str.find( . ) == -1) {       cout <<  00 ;       goto jump;     }     s = str.substr(str.find( . ) + 1);     s +=  0 ;     s = s.substr(0, 2);     cout << s;   jump:     if (flag == 1) cout <<  ) ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char str[100400];   int len;   long long k;   int r, ret;   long long calc(int x) { return len - x; }   int Q[100400];   char res[100400];   void solve(int x) {     int i, j;     for (j = 0; j < 26; j++) {       long long sum = 0;       queue<int> q;       for (i = 0; i < r; i++) {         if (Q[i] + 1 < len && str[Q[i] + 1] ==  a  + j) {           sum += calc(Q[i] + 1);           q.push(Q[i] + 1);         }       }       if (sum >= k) {         r = 0;         while (!q.empty()) {           Q[r++] = q.front();           q.pop();         }         break;       } else {         k -= sum;       }     }     res[ret++] =  a  + j;     k -= r;     if (k > 0) solve(j);   }   int main() {     int i, j;     while (scanf( %s , str) != EOF) {       scanf( %d , &k);       len = strlen(str);       ret = 0;       if (k > (1LL * (len + 1) * len) / 2) {         cout <<  No such line.  << endl;         continue;       }       for (j = 0; j < 26; j++) {         long long sum = 0;         r = 0;         for (i = 0; i < len; i++) {           if (str[i] ==  a  + j) {             sum += calc(i);             Q[r++] = i;           }         }         if (sum >= k) {           break;         } else {           k -= sum;         }       }       res[ret++] =  a  + j;       k -= r;       if (k > 0) solve(j);       res[ret] =   0 ;       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = int(1e9);   const double eps = 1e-4;   const double pi = 4 * atan(double(1));   const int N = int(3e5) + 100;   const int M = int(1e6) + 100;   const int sizes[] = {3600, 60, 1, -1};   const int MOD1 = int(1e9) + 7;   const int X1 = 4243;   struct _hash {     int a;     _hash() {}     _hash(int a) : a(a) {}   };   _hash operator+(const _hash& a, const _hash& b) {     _hash c(a.a + b.a);     if (c.a >= MOD1) {       c.a -= MOD1;     }     return c;   }   _hash operator-(const _hash& a, const _hash& b) {     _hash c(a.a - b.a);     if (c.a < 0) {       c.a += MOD1;     }     return c;   }   _hash operator*(const _hash& a, const _hash& b) {     return _hash((1LL * a.a * b.a) % MOD1);   }   bool operator==(const _hash& a, const _hash& b) { return a.a == b.a; }   struct tq {     int a, b, ab, c, d, cd;   };   struct node {     int val;     node** _next;   };   const _hash X(X1);   int n;   int h[N], _prev[N], _rank[N], val[N], p[N];   bool used[N];   _hash st[N], rev_st[N];   _hash pw[2 * N];   vector<pair<int, int*> > lca[N];   node* ver[N];   vector<int> g[N];   tq q[M];   char s[N];   int get(int a) {     if (_prev[a] != a) {       _prev[a] = get(_prev[a]);     }     return _prev[a];   }   inline void merge(int a, int b, int c) {     a = get(a);     b = get(b);     if (_rank[a] < _rank[b]) {       swap(a, b);     }     _prev[b] = a;     if (_rank[a] == _rank[b]) {       ++_rank[a];     }     val[a] = c;   }   inline node* clone(node* v, int lev) {     node* res = new node();     res->val = v->val;     if (sizes[lev] != -1) {       int cnt =           max(((lev == 0 ? n : sizes[lev - 1]) + sizes[lev] - 1) / sizes[lev], 1);       res->_next = new node*[cnt];       for (int i = 0; i < cnt; ++i) {         res->_next[i] = v->_next[i];       }     }     return res;   }   node* set_val(node* v, int lev, int pos, int val) {     v = clone(v, lev);     if (sizes[lev] == -1) {       v->val = val;       return v;     }     v->_next[pos / sizes[lev]] =         set_val(v->_next[pos / sizes[lev]], lev + 1, pos % sizes[lev], val);     return v;   }   int get_val(node* v, int pos) {     int lev = 0;     while (sizes[lev] != -1) {       v = v->_next[pos / sizes[lev]];       pos %= sizes[lev];       ++lev;     }     return v->val;   }   void dfs(int v, int pv, node* cur) {     used[v] = true;     p[v] = pv;     if (pv != -1) {       g[v].erase(find((g[v]).begin(), (g[v]).end(), pv));       h[v] = h[pv] + 1;     } else {       h[v] = 0;     }     cur = set_val(cur, 0, h[v], v);     ver[v] = cur;     st[v] = (pv == -1 ? _hash(0) : st[pv]) + pw[h[v]] * _hash(s[v]);     rev_st[v] = (pv == -1 ? _hash(0) : rev_st[pv]) + pw[n - h[v]] * _hash(s[v]);     for (int i = 0; i < int((lca[v]).size()); ++i) {       if (used[lca[v][i].first]) {         *(lca[v][i].second) = val[get(lca[v][i].first)];       }     }     for (int i = 0; i < int((g[v]).size()); ++i) {       dfs(g[v][i], v, cur);       merge(g[v][i], v, v);     }   }   inline int len(int a, int b, int ab) { return h[a] + h[b] - 2 * h[ab] + 1; }   inline _hash get(int v, int lca) {     return (rev_st[v] - (p[lca] == -1 ? _hash(0) : rev_st[p[lca]])) * pw[h[v]];   }   inline int get_ver(int v, int len) {     len = h[v] - len + 1;     return get_val(ver[v], len);   }   inline _hash get_hash(int a, int b, int ab, int len) {     int first = h[a] - h[ab] + 1;     if (len <= first) {       return get(a, get_ver(a, len));     }     len -= first;     int ver = get_ver(b, h[b] - h[ab] + 1 - len);     return get(a, ab) + (st[ver] - st[ab]) * pw[n + first - (h[ab] + 1)];   }   int main() {     scanf( %d , &n);     gets(s);     gets(s);     for (int i = 0; i < n - 1; ++i) {       int a, b;       scanf( %d %d , &a, &b);       --a;       --b;       g[a].push_back(b);       g[b].push_back(a);     }     pw[0] = _hash(1);     for (int i = 1; i <= 2 * n; ++i) {       pw[i] = pw[i - 1] * X;     }     int m;     scanf( %d , &m);     for (int i = 0; i < m; ++i) {       scanf( %d %d %d %d , &q[i].a, &q[i].b, &q[i].c, &q[i].d);       --q[i].a;       --q[i].b;       --q[i].c;       --q[i].d;       lca[q[i].a].push_back(make_pair(q[i].b, &q[i].ab));       lca[q[i].b].push_back(make_pair(q[i].a, &q[i].ab));       lca[q[i].c].push_back(make_pair(q[i].d, &q[i].cd));       lca[q[i].d].push_back(make_pair(q[i].c, &q[i].cd));     }     for (int i = 0; i < n; ++i) {       _prev[i] = i;       _rank[i] = 1;       val[i] = i;     }     int root = 0;     node* vers = new node[100];     int lev;     for (lev = 0; sizes[lev] != -1; ++lev) {       vers[lev]._next = new node*[max(           ((lev == 0 ? n : sizes[lev - 1]) + sizes[lev] - 1) / sizes[lev], 1)];     }     for (--lev; lev >= 0; --lev) {       for (int j = 0; j < max(((lev == 0 ? n : sizes[lev - 1]) + sizes[lev] - 1) /                                   sizes[lev],                               1);            ++j) {         vers[lev]._next[j] = &vers[lev + 1];       }     }     dfs(root, -1, &vers[0]);     for (int i = 0; i < m; ++i) {       int ans = 0, l = 1,           r = min(len(q[i].a, q[i].b, q[i].ab), len(q[i].c, q[i].d, q[i].cd));       while (l <= r) {         int mid = (l + r) / 2;         _hash h1 = get_hash(q[i].a, q[i].b, q[i].ab, mid);         _hash h2 = get_hash(q[i].c, q[i].d, q[i].cd, mid);         if (h1 == h2) {           ans = mid;           l = mid + 1;         } else {           r = mid - 1;         }       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void readn(int &x) {     char c;     x = 0;     do {       c = getchar();     } while (c <  0  || c >  9 );     do {       x = x * 10 + c -  0 ;       c = getchar();     } while (c <=  9  && c >=  0 );   }   const int MAXN = 101 * 1000;   int k, n, maxb, t, out = 0;   int a[MAXN], fen[MAXN], v[MAXN];   inline void add(int pos, int val) {     if (val > out) out = val;     v[pos] = val;     while (pos <= maxb) {       if (fen[pos] < val) fen[pos] = val;       pos += pos & -pos;     }   }   inline int rmax(int pos) {     int tot = 0;     while (pos) {       if (tot < fen[pos]) tot = fen[pos];       pos -= pos & -pos;     }     return tot;   }   int solve() {     memset(fen, 0, sizeof fen);     memset(v, 0, sizeof v);     out = 0;     for (register int rep = (0); rep < (int)(t); ++rep)       for (register int i = (0); i < (int)(n); ++i)         if (a[i]) {           add(a[i], rmax(a[i] - 1) + 1);           if (rep + 1 >= a[i] || v[a[i]] == a[i]) a[i] = 0;           if (out == n || out == maxb) break;         }     return out;   }   int main() {     scanf( %d %d %d %d , &k, &n, &maxb, &t);     t = min(n, min(t, maxb));     while (k--) {       for (register int i = (0); i < (int)(n); ++i) readn(a[i]);       printf( %d n , solve());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long n, k, m, f[100005][15][20];   long long count(long long x) {     long long sum = 0;     while (x) sum++, x -= (x & -x);     return sum;   }   signed main() {     scanf( %lld%lld%lld , &n, &k, &m);     f[0][0][0] = 1;     for (long long i = 0; i < n; i++) {       for (long long j = 0; j <= k; j++) {         for (long long s = 0; s < (1 << m); s++) {           f[i + 1][j][s >> 1] = (f[i + 1][j][s >> 1] + f[i][j][s]) % mod;           f[i + 1][j + 1][(s >> 1) | (1 << (m - 1))] =               (f[i + 1][j + 1][(s >> 1) | (1 << (m - 1))] +                (1ll + count(s)) * f[i][j][s]) %               mod;         }       }     }     long long ans = 0;     for (long long i = 0; i < (1 << m); i++) ans = (ans + f[n][k][i]) % mod;     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 700000;   int n, g, r;   int l[MAXN];   long long sum[MAXN];   long long d[MAXN];   long long cycle;   int m;   long long q[MAXN], code[MAXN];   int minv[MAXN];   void build(int l, int r, int v) {     minv[v] = n + 1;     if (l != r)       build(l, (l + r) >> 1, v << 1), build(((l + r) >> 1) + 1, r, (v << 1) + 1);   }   void change(int p, int l, int r, int v, int x) {     if (l > p || r < p) return;     minv[v] = x;     if (l != r)       change(p, l, (l + r) >> 1, v << 1, x),           change(p, ((l + r) >> 1) + 1, r, (v << 1) + 1, x);   }   int getmin(int L, int R, int l, int r, int v) {     if (L > r || l > R) return n + 1;     if (L <= l && r <= R) return minv[v];     return min(getmin(L, R, l, (l + r) >> 1, v << 1),                getmin(L, R, ((l + r) >> 1) + 1, r, (v << 1) + 1));   }   int process(int u, int curt) {     assert(curt < g);     int l, r;     l = g - curt;     r = cycle - 1 - curt;     l = (1LL * l + code[u]) % cycle;     r = (1LL * r + code[u]) % cycle;     int p1, p2;     p1 = lower_bound(q, q + m, l) - q;     p2 = lower_bound(q, q + m, r + 1) - q - 1;     if (l <= r) {       if (p1 > p2) return n + 1;       return getmin(p1, p2, 0, m - 1, 1);     }     int ret = n + 1;     if (p1 < m) ret = min(ret, getmin(p1, m - 1, 0, m - 1, 1));     assert(p2 >= 0);     ret = min(ret, getmin(0, p2, 0, m - 1, 1));     return ret;   }   int main() {     scanf( %d%d%d , &n, &g, &r);     cycle = g + r;     for (int i = 0; i <= n; i++) scanf( %d , l + i);     for (int i = 1; i <= n + 1; i++) sum[i] = sum[i - 1] + l[i - 1];     for (int i = 1; i <= n + 1; i++) code[i] = sum[i] % cycle;     for (int i = 0; i <= n + 1; i++) q[m++] = code[i];     sort(q, q + m);     m = unique(q, q + m) - q;     build(0, m - 1, 1);     for (int i = n, pos; i > 1; i--) {       pos = process(i, 0);       assert(pos == n + 1 || (sum[pos] - sum[i]) % cycle >= g);       assert(pos > i);       d[i] = d[pos] + sum[pos] - sum[i];       if (pos != n + 1) d[i] += cycle - (sum[pos] - sum[i]) % cycle;       change(lower_bound(q, q + m, code[i]) - q, 0, m - 1, 1, i);     }     int test_num;     scanf( %d , &test_num);     for (int pos; test_num--;) {       long long tim;       scanf( %I64d , &tim);       tim += sum[1];       if (tim % cycle >= g) tim += cycle - tim % cycle;       pos = process(1, tim % cycle);       assert(pos);       assert((sum[pos] - sum[1] + tim) % cycle >= g || pos == n + 1);       long long res = d[pos] + sum[pos] - sum[1] + tim;       if (pos != n + 1) res += cycle - (sum[pos] - sum[1] + tim) % cycle;       printf( %I64d n , res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class Solver {    public:     void input() {       cin >> n;       a.resize(n);       for (int i = 0; i < n; i++) {         cin >> a[i];       }     }     void print() { cout << solve() << endl; }       private:     vector<int> a;     int n;     long long f(int x) {       long long ans = 0;       for (int i = 0; i < n; i++) {         int j = lower_bound(a.begin(), a.end(), x - a[i]) - a.begin();         if (i < j) {           ans += j - i - 1;         } else {           break;         }       }       return ans;     }     int solve() {       int ans = 0;       for (int i = 30; i >= 0; i--) {         for (int j = 0; j < n; j++) {           a[j] = (a[j] & ((1 << (i + 1)) - 1));         }         sort(a.begin(), a.end());         long long cur = f(1 << (i + 1)) - f(1 << i);         cur += f(1 << (i + 2)) - f((1 << i) + (1 << (i + 1)));         if (cur & 1) {           ans = (ans | (1 << i));         }       }       return ans;     }   };   int main() {     ios::sync_with_stdio(false);     Solver solver;     solver.input();     solver.print();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-6;   const double PI = 3.14159265358979323846264338f;   const double pi = acos(-1.0);   const int inf = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   const int MAXN = 1005;   inline int read() {     int c = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       c = c * 10 + ch -  0 ;       ch = getchar();     }     return c * f;   }   struct node {     int w, h;   } e[MAXN];   int n;   int ans = inf;   bool vis[MAXN];   int main() {     n = read();     for (int i = 1; i <= n; i++) {       e[i].w = read();       e[i].h = read();     }     auto solve = [](int x) -> void {       memset(vis, false, sizeof(vis));       priority_queue<int> q;       int tot = 0;       int w = 0;       for (int i = 1; i <= n; i++) {         if (e[i].h > x) {           vis[i] = true;           tot++;           w += e[i].h;           if (e[i].w > x) return;         }       }       for (int i = 1; i <= n; i++) {         if (!vis[i]) {           if (e[i].w <= x) q.push(e[i].w - e[i].h);           w += e[i].w;         }       }       while (tot < n / 2 && !q.empty()) {         int ww = q.top();         q.pop();         if (ww > 0) {           w -= ww;           tot++;         } else           break;       }       if (tot <= n / 2) ans = min(ans, w * x);     };     for (int i = 1; i <= 1000; i++) {       solve(i);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int l = 0, r = 0;     string s, t;     cin >> s >> t;     int i = 0;     for (int j = 0; j < t.length(); j++) {       if (s[i] == t[j]) {         if (i == s.length() - 1) {           i = s.length() - 1;           l = j + 1;           break;         } else           i++;       }     }     for (int j = t.length() - 1; j > l - 1; j--) {       if (s[i] == t[j]) {         if (i == 0) {           i = 0;           r = t.length() - j;           break;         } else           i--;       }     }     if (l == 0 || r == 0) {       cout << 0;       return 0;     }     int ans;     ans = t.length() - l - r + 1;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isLeaf[100001] = {0};   bool isCorrect[100001] = {0};   bool nowCorrect[100001] = {0};   bool allVisited[100001] = {0};   bool visited = false;   vector<int> solution;   vector<vector<int> > old_pony_ville, pony_ville;   bool dfs(int nodo) {     if (!isLeaf[nodo]) {       solution.push_back(nodo);       nowCorrect[nodo] = !nowCorrect[nodo];       for (int i = 0; i < pony_ville[nodo].size(); i++) {         do {           visited = dfs(pony_ville[nodo][i]);         } while (!isLeaf[pony_ville[nodo][i]]);         if (visited) {           solution.push_back(nodo);           nowCorrect[nodo] = !nowCorrect[nodo];           if (!allVisited[pony_ville[nodo][i]]) {             visited = dfs(pony_ville[nodo][i]);             if (visited) {               solution.push_back(nodo);               nowCorrect[nodo] = !nowCorrect[nodo];             }           }         }       }       isLeaf[nodo] = true;       return true;     } else {       allVisited[nodo] = true;       if (nowCorrect[nodo] == isCorrect[nodo])         return false;       else {         nowCorrect[nodo] = !nowCorrect[nodo];         solution.push_back(nodo);         return true;       }     }   }   void MST(int start) {     bool isVisited[100001] = {0};     vector<int> visits;     visits.push_back(start);     while (!visits.empty()) {       start = visits.back();       isVisited[start] = true;       visits.pop_back();       for (int i = 0; i < old_pony_ville[start].size(); i++) {         if (!isVisited[old_pony_ville[start][i]]) {           pony_ville[start].push_back(old_pony_ville[start][i]);           visits.push_back(old_pony_ville[start][i]);           isVisited[old_pony_ville[start][i]] = true;         }       }     }   }   int main() {     int n, m, a, b, start = 0;     bool x;     cin >> n >> m;     n++;     old_pony_ville.resize(n);     pony_ville.resize(n);     for (int i = 0; i < m; i++) {       cin >> a >> b;       old_pony_ville[a].push_back(b);       old_pony_ville[b].push_back(a);     }     for (int i = 1; i < n; i++) {       cin >> x;       if (x) start = i;       isCorrect[i] = x;     }     MST(start);     for (int i = 1; i < n; i++) {       if (pony_ville[i].size() == 0) isLeaf[i] = true;     }     dfs(start);     allVisited[start] = true;     if (nowCorrect[start] != isCorrect[start]) solution.pop_back();     for (int i = 1; i < n; i++) {       if (!allVisited[i] && isCorrect[i]) {         cout << -1;         return 0;       }     }     cout << solution.size() << endl;     for (int i = 0; i < solution.size(); i++) {       cout << solution[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INFLL = 2 * (long long)1e18 + 100;   const long long INFINT = 2 * (long long)1e9 + 100;   const double PI = atan(1) * 4;   const double EPS = 1e-6;   const long long SEED = (long long)1e3 + 7;   const long long MOD = 998244353;   const long long NMAX = (long long)1e5 + 5;   vector<long long> v;   long long sum[NMAX];   long long solve(long long n) {     vector<long long> temp;     for (long long i = 1; i <= n; i++) temp.push_back(i);     do {       for (auto i : temp) v.push_back(i);     } while (next_permutation(temp.begin(), temp.end()));     long long sol = 0;     for (long long i = 1; i <= v.size(); i++) {       sum[i] = sum[i - 1] + v[i - 1];       if (i >= n) {         long long here = sum[i] - sum[i - n];         if (here == n * (n + 1) / 2) sol++;       }     }     return sol;   }   long long fact(long long x) {     if (x == 1) return 1;     return x * fact(x - 1) % MOD;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     long long sol = n * fact(n) % MOD;     long long prev = 1;     for (long long i = n; i >= 2; i--) {       prev = prev * i % MOD;       sol = sol - prev;       if (sol < 0) sol += MOD;     }     cout << sol;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void positionInFraction();   int main() {     positionInFraction();     return 0;   }   void positionInFraction() {     int b, c, rpta, division;     long long a, posicion;     cin >> a >> b >> c;     bool hayRpta = false;     posicion = 1;     while (posicion < 100000 and !hayRpta) {       a = a * 10;       division = a / b;       if (division % 10 == c) {         cout << posicion;         hayRpta = true;         break;       }       a = a % b;       posicion++;     }     if (hayRpta) {     } else {       cout << -1;     }   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-5;   template <typename T>   void cmin(T &x, const T &y) {     if (y < x) x = y;   }   template <typename T>   void cmax(T &x, const T &y) {     if (y > x) x = y;   }   template <typename T>   void read(T &x) {     x = 0;     char c = getchar();     bool f = 0;     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - ) f = 1, c = getchar();     while (isdigit(c)) x = x * 10 + c -  0 , c = getchar();     if (f) x = -x;   }   struct vec {     double x, y;     vec(const double &x0 = 0, const double &y0 = 0) : x(x0), y(y0) {}     vec operator+(const vec &t) const { return vec(x + t.x, y + t.y); }     vec operator-(const vec &t) const { return vec(x - t.x, y - t.y); }     vec operator*(const double &t) const { return vec(x * t, y * t); }     double len2() const { return x * x + y * y; }     bool operator<(const vec &t) const {       return (fabs(x - t.x) > eps) ? (x < t.x) : (y < t.y);     }     vec rot_90_a() const { return vec(-y, x); }   };   double crs(const vec &a, const vec &b) { return a.x * b.y - a.y * b.x; }   double dot(const vec &a, const vec &b) { return a.x * b.x + a.y * b.y; }   vector<vec> convex(vector<vec> src) {     vector<vec> stk;     sort(src.begin(), src.end());     for (auto i = src.begin(); i != src.end(); i++) {       while (stk.size() >= 2 &&              crs(*i - stk.end()[-1], stk.end()[-1] - stk.end()[-2]) >= -eps)         stk.pop_back();       stk.emplace_back(*i);     }     int top = stk.size();     for (auto i = src.rbegin(); i != src.rend(); i++) {       while (stk.size() > top &&              crs(*i - stk.end()[-1], stk.end()[-1] - stk.end()[-2]) >= -eps)         stk.pop_back();       stk.emplace_back(*i);     }     stk.pop_back();     return stk;   }   int n, m;   vector<vec> A, B;   void input() {     read(n), read(m);     for (int i = 1; i <= n; i++) {       vec tmp;       read(tmp.x), read(tmp.y);       A.emplace_back(tmp);     }     for (int i = 1; i <= m; i++) {       vec tmp;       read(tmp.x), read(tmp.y);       B.emplace_back(tmp);     }   }   vec lin_lin_int(vec p1, vec v1, vec p2, vec v2) {     double k = crs(p2 - p1, v2) / crs(v1, v2);     return p1 + v1 * k;   }   bool try_plain(vec a, vec b, const vector<vec> &in, const vector<vec> &out) {     double mxc = +1e30, mnc = -1e30;     vec mid = (a + b) * 0.5, per = (b - a).rot_90_a();     for (auto i : in)       if (crs(b - a, i - a) > eps)         cmax(mnc,              crs(b - a,                  lin_lin_int((i + a) * 0.5, (i - a).rot_90_a(), mid, per) - a));       else if (crs(b - a, i - a) < -eps)         cmin(mxc,              crs(b - a,                  lin_lin_int((i + a) * 0.5, (i - a).rot_90_a(), mid, per) - a));       else if (dot(b - a, i - a) > dot(b - a, b - a) || dot(b - a, i - a) < 0)         return false;     for (auto i : out)       if (crs(b - a, i - a) > eps)         cmin(mxc,              crs(b - a,                  lin_lin_int((i + a) * 0.5, (i - a).rot_90_a(), mid, per) - a));       else if (crs(b - a, i - a) < -eps)         cmax(mnc,              crs(b - a,                  lin_lin_int((i + a) * 0.5, (i - a).rot_90_a(), mid, per) - a));       else if (dot(b - a, i - a) < dot(b - a, b - a) && dot(b - a, i - a) > 0)         return false;     if (mxc > mnc + eps)       return true;     else       return false;   }   bool check(vector<vec>::iterator in_beg, vector<vec>::iterator in_end,              const vector<vec> &in, const vector<vec> &out) {     if (try_plain(*in_beg, *(in_end - 1), in, out)) return true;     if (in_end - in_beg < 3) return 0;     vec lft = *in_beg, rgt = *(in_end - 1);     double mxd = -1e18, tmp;     vector<vec>::iterator mxp;     for (auto i = in_beg + 1; i != in_end - 1; i++) {       double val = -dot(*i - lft, *i - rgt) / crs(*i - lft, *i - rgt);       if (val > mxd) mxd = val, mxp = i;     }     if (check(in_beg, mxp + 1, in, out) || check(mxp, in_end, in, out))       return true;     else       return false;   }   int main() {     input();     vector<vec> cA = convex(A), cB = convex(B);     if (check(cA.begin(), cA.end(), A, B))       puts( YES );     else if (check(cB.begin(), cB.end(), B, A))       puts( YES );     else       puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1600;   int dr[] = {-1, 0, 1, 0}, dc[] = {0, 1, 0, -1};   int n, m, pr[M][M], pc[M][M];   char g[M][M], f[M][M];   bool dfs(int r, int c) {     int u = (r % n + n) % n, v = (c % m + m) % m;     if ( #  == g[u][v]) return 0;     if (f[u][v]) return r != pr[u][v] || c != pc[u][v];     f[u][v] = 1, pr[u][v] = r, pc[u][v] = c;     for (int d = 0; d < 4; ++d)       if (dfs(r + dr[d], c + dc[d])) return 1;     return 0;   }   int main(void) {     cin >> n >> m;     for (int i = 0; i < n; ++i) cin >> g[i];     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j)         if ( S  == g[i][j])           cout << (dfs(i + n * 2, j + m * 2) ?  Yes  :  No ) << endl;   }


#include <bits/stdc++.h>   using namespace std;   string i2s(int x) {     stringstream ss;     ss << x;     return ss.str();   }   int s2i(string str) {     istringstream ss(str);     int nro;     ss >> nro;     return nro;   }   int n;   int NRO5(int nro) {     int cnt = 0;     while (nro % 5 == 0) {       cnt++;       nro /= 5;     }     return cnt;   }   int main() {     int A[500005];     map<int, vector<int> > mapa;     map<int, vector<int> >::iterator it;     for (int i = 1; i < 500005; i++) {       A[i] = A[i - 1] + NRO5(i);       mapa[A[i]].push_back(i);     }     scanf( %d n , &n);     if (mapa[n].size() == 0) {       putchar( 0 );       putchar(  n );     } else {       printf( %d n , (int)mapa[n].size());       for (int i = 0; i < mapa[n].size(); i++) {         printf( %d%c , mapa[n][i], i == mapa[n].size() - 1 ? 10 : 32);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   long long int n;   long long int t[2 * N];   int main() {     long long int n, k;     cin >> n >> k;     long long int a[k], ans = 1e18, g = 0;     for (int i = 0; i < k; i++) {       cin >> a[i];       if (n % a[i] < ans) {         ans = n % a[i];         g = i;       }     }     cout << g + 1 <<     << n / a[g] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 10;   int n;   set<pair<pair<int, int>, int> > a;   int ans[MAXN];   inline pair<pair<int, int>, int> mpi(int a, int b, int c) {     return make_pair(make_pair(a, b), c);   }   void exit() {     cout <<  Impossible ;     exit(0);   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       pair<pair<int, int>, int> x;       scanf( %d , &x.first.second);       x.first.first = x.first.second % 3;       x.second = i;       a.insert(x);     }     a.insert(mpi(1000, 1000, 1000));     a.insert(mpi(-1000, -1000, -1000));     pair<pair<int, int>, int> x;     int olimp = 0;     for (int i = 0; i < n; i++) {       set<pair<pair<int, int>, int> >::iterator it =           a.lower_bound(mpi(i % 3, i - olimp, 0));       x = *it;       if (i % 3 != x.first.first) {         it--;         x = *it;       }       if (i % 3 != x.first.first) exit();       bool flag = false;       while (i - olimp + 1 < x.first.second) {         it--;         x = *it;         flag = true;       }       if (x.first.second < 0 || i % 3 != x.first.first) exit();       olimp = i + 1 - x.first.second;       ans[i + 1] = x.second;       a.erase(it);     }     cout <<  Possible  << endl;     for (int i = 1; i <= n; i++) printf( %d  , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   const double pp = 0.00000001;   const int maxn = 100005;   double ans, xo, da, mid;   int ci, w, i, n, x[maxn], y[maxn];   bool pd(double k) {     double ww, l = -1e9, r = 1e9;     int i;     for (i = 1; i <= n; i++) {       if (k * k < (y[i] - k) * (y[i] - k)) {         return 0;       }       ww = -1.0 * y[i] * y[i] + 2 * y[i] * k;       ww = sqrt(ww);       if (l < x[i] - ww) l = x[i] - ww;       if (r > x[i] + ww) r = x[i] + ww;     }     if (l <= r)       return true;     else       return false;   }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d%d , &x[i], &y[i]);       if (y[i] > 0)         w++;       else         y[i] = -y[i];     }     if (w != 0 && w != n) {       printf( -1 n );       return 0;     }     xo = 0;     da = 50000000000000.4949989;     ci = 0;     while (ci <= 100) {       ci++;       mid = (xo + da) / 2;       if (pd(mid)) {         ans = mid;         da = mid;       } else         xo = mid;     }     printf( %lf n , mid);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int64_t t, a[200005], n;     cin >> t;     while (t--) {       int64_t dem = 1;       cin >> n;       for (int i = 1; i <= n; i++) cin >> a[i];       sort(a + 1, a + n + 1);       for (int i = 1; i < n; i++) {         if (a[i] != a[i + 1]) dem++;       }       cout << dem << endl;     }   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n;     cin >> n;     long long int a[n], b[n];     long long int sum_1 = 0, sum_2 = 0, c = 0;     for (long long int i = 0; i <= n - 1; i++) {       cin >> a[i] >> b[i];       sum_1 += a[i];       sum_2 += b[i];     }     if (sum_1 % 2 == 0 && sum_2 % 2 == 0) {       cout <<  0  <<   n ;     } else if (n == 1) {       cout <<  -1  <<   n ;     } else {       for (long long int i = 0; i <= n - 1; i++) {         sum_1 -= a[i];         sum_1 += b[i];         sum_2 -= b[i];         sum_2 += a[i];         c++;         if (sum_1 % 2 == 0 && sum_2 % 2 == 0) {           cout << c <<   n ;           return 0;         }         c--;         sum_1 -= b[i];         sum_1 += a[i];         sum_2 -= a[i];         sum_2 += b[i];       }       cout <<  -1  <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 2e9;   const long long Inf = 1e10;   const int N = 500005;   const double pi = acos(-1);   inline int IN() {     int x = 0;     int ch = 0, f = 0;     for (ch = getchar(); ch != -1 && (ch < 48 || ch > 57); ch = getchar())       f = (ch ==  - );     for (; ch >= 48 && ch <= 57; ch = getchar())       x = (x << 1) + (x << 3) + ch -  0 ;     return f ? (-x) : x;   }   int Pow(int x, int y, int p) {     int a = 1;     for (; y; y >>= 1, x = (long long)x * x % p)       if (y & 1) a = (long long)a * x % p;     return a;   }   int n, a;   double rad[N], dis[N], ang[N];   struct po {     double x, y;     po(double xv = 0, double yv = 0) { x = xv, y = yv; }     double norm() { return sqrt(x * x + y * y); }     po operator-(const po &a) const { return (po){x - a.x, y - a.y}; }   } b[N], P, Q;   pair<double, double> A[N];   int tot;   set<double> st;   int check(double rng) {     tot = 0;     st.clear();     for (int i = (int)(1); i <= (int)(n); i++) {       if (dis[i] >= rng + rad[i]) continue;       if (dis[i] <= fabs(rng - rad[i])) continue;       double bet =           (rng * rng + dis[i] * dis[i] - rad[i] * rad[i]) / (2 * rng * dis[i]);       double alp = ang[i];       bet = acos(bet);       double l = alp - bet, r = alp + bet;       if (l < 0) l += 2 * pi;       if (r < 0) r += 2 * pi;       if (l > r) swap(l, r);       A[++tot] = make_pair(l, r);     }     sort(A + 1, A + tot + 1);     for (int i = (int)(1); i <= (int)(tot); i++) {       auto t = st.lower_bound(A[i].first);       if (t != st.end() && *t < A[i].second) return 1;       st.insert(A[i].second);     }     return 0;   }   int main() {     scanf( %d%d , &n, &a);     P = po(a, 0);     Q = po(-a, 0);     for (int i = (int)(1); i <= (int)(n); i++) {       double x, y;       scanf( %lf%lf , &x, &y);       b[i] = po(x, y);       rad[i] = (b[i] - Q).norm();       b[i] = b[i] - P;       ang[i] = atan2(b[i].y, b[i].x);       dis[i] = b[i].norm();     }     double l = 0, r = 2 * a;     for (int i = (int)(1); i <= (int)(100); i++) {       double md = (l + r) / 2.;       if (check(md))         r = md;       else         l = md;     }     printf( %.10lf n , (l + r) / 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 5;   const int inf = 1e9 + 5e5 + 19;   int n, k;   int a[maxn];   bool in_b[maxn];   struct fenwick {     int n;     vector<int> val;     void init(int _n) {       n = _n;       val.assign(n + 5, -1);     }     void update(int x, int k) {       for (; x <= n; x += x & -x) val[x] = max(val[x], k);     }     int get(int x) {       int res = -1;       for (; x > 0; x -= x & -x) res = max(res, val[x]);       return res;     }   } tree;   void read_input() {     cin >> n >> k;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (; k > 0; --k) {       int x;       cin >> x;       in_b[x] = true;     }     in_b[0] = in_b[n + 1] = true;     a[0] = -inf;     a[n + 1] = inf;   }   int calc(const vector<int>& arr, int L, int R) {     if ((int)arr.size() == 0) return 0;     vector<int> vals;     for (int i = 0; i < (int)arr.size(); ++i) vals.push_back(arr[i] - i);     sort(vals.begin(), vals.end());     vals.erase(unique(vals.begin(), vals.end()), vals.end());     tree.init((int)vals.size());     int max_val = 0;     for (int i = 0; i < (int)arr.size(); ++i) {       if (arr[i] <= L || arr[i] >= R) continue;       if (arr[i] - L - 1 >= i && R - arr[i] - 1 >= (int)arr.size() - i - 1) {         int val = 1;         int p =             lower_bound(vals.begin(), vals.end(), arr[i] - i) - vals.begin() + 1;         val = max(val, tree.get(p) + 1);         tree.update(p, val);         max_val = max(max_val, val);       }     }     return (int)arr.size() - max_val;   }   void solve() {     int ans = 0;     for (int i = 0; i <= n;) {       int j = i + 1;       while (j <= n && !in_b[j]) ++j;       int L = a[i], R = a[j];       if (R - L < j - i) {         cout <<  -1 n ;         return;       }       vector<int> arr;       ++i;       for (; i < j; ++i) arr.push_back(a[i]);       ans += calc(arr, L, R);     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     read_input();     solve();   }


#include <bits/stdc++.h>   using namespace std;   int prime[500000];   long long gcd(long long x, long long y) {     if (y == 0) return x;     return gcd(y, x % y);   }   int main() {     long long n;     cin >> n;     long long x = n;     for (long long i = 2; i * i <= n; i++)       if (n % i == 0) {         x = gcd(x, i);         x = gcd(x, n / i);       }     cout << x << endl;   }


#include <bits/stdc++.h>   using namespace std;   int ts, kk = 1;   template <class T>   inline T _sq(T a) {     return a * a;   }   template <class T, class X>   inline T _pow(T a, X y) {     T z = 1;     for (int i = 1; i <= y; i++) {       z *= a;     }     return z;   }   template <class T>   inline T _gcd(T a, T b) {     a = _abs(a);     b = _abs(b);     if (!b) return a;     return _gcd(b, a % b);   }   template <class T>   inline T _lcm(T a, T b) {     a = _abs(a);     b = _abs(b);     return (a / _gcd(a, b)) * b;   }   template <class T>   inline T _extended(T a, T b, T &x, T &y) {     a = _abs(a);     b = _abs(b);     T g, x1, y1;     if (!b) {       x = 1;       y = 0;       g = a;       return g;     }     g = _extended(b, a % b, x1, y1);     x = y1;     y = x1 - (a / b) * y1;     return g;   }   template <class T, class X>   inline bool getbit(T a, X i) {     T t = 1;     return ((a & (t << i)) > 0);   }   template <class T, class X>   inline T setbit(T a, X i) {     T t = 1;     return (a | (t << i));   }   template <class T, class X>   inline T resetbit(T a, X i) {     T t = 1;     return (a & (~(t << i)));   }   template <class T, class X>   inline T togglebit(T a, X i) {     T t = 1;     return (a ^ (t << i));   }   template <class T, class X, class Y>   inline T _bigmod(T n, X m, Y mod) {     unsigned long long ret = 1, a = n % mod;     while (m) {       if (m & 1) ret = (ret * a) % mod;       m >>= 1;       a = (a * a) % mod;     }     ret %= mod;     return (T)ret;   }   template <class T, class Y>   inline T _modinv(T n, Y mod) {     return _bigmod(n, mod - 2, mod);   }   const int bit = 10000;   int son[800], x, y, N, c[120];   vector<int> E[800];   struct HugeInt {     int a[60], len;     void set(int x) {       len = 0;       while (x) a[++len] = x % bit, x /= bit;     }     void operator*=(const HugeInt &b) {       memset(c, 0, sizeof c);       for (int i = 1; i <= len; i++)         for (int j = 1; j <= b.len; j++)           c[i + j - 1] += a[i] * b.a[j], c[i + j] += c[i + j - 1] / bit,               c[i + j - 1] %= bit;       len += b.len;       while (len > 1 && c[len] == 0) len--;       while (c[len] >= bit) {         ++len;         c[len] = c[len - 1] / bit;         c[len - 1] %= bit;       }       for (int i = 1; i <= len; i++) a[i] = c[i];     }     void operator*=(int b) {       for (int i = 1; i <= len; i++) a[i] *= b;       for (int i = 1; i <= len; i++) a[i + 1] += a[i] / bit, a[i] %= bit;       len++;       while (len > 1 && !a[len]) len--;       while (a[len] >= bit) {         ++len;         a[len] = a[len - 1] / bit;         a[len - 1] %= bit;       }     }     void out() {       printf( %d , a[len]);       for (int i = len - 1; i >= 1; i--) printf( %04d , a[i]);       puts(  );     }   } dp[800][800];   void upd(HugeInt &a, HugeInt b) {     int flag = 0;     for (int i = max(a.len, b.len); i >= 1; i--)       if (b.a[i] > a.a[i]) {         a = b;         return;       } else if (b.a[i] < a.a[i])         return;   }   void dfs(int u, int fa) {     dp[u][1].set(1);     son[u] = 1;     for (int i = 0; i < E[u].size(); ++i)       if (E[u][i] != fa) {         int v = E[u][i];         dfs(v, u);         for (int j = son[u]; j >= 0; j--)           for (int k = son[v]; k >= 0; k--) {             HugeInt tmp = dp[v][k];             tmp *= dp[u][j];             upd(dp[u][j + k], tmp);           }         son[u] += son[v];       }     for (int i = 0; i <= son[u]; i++) {       HugeInt tmp = dp[u][i];       tmp *= i;       upd(dp[u][0], tmp);     }   }   int main() {     scanf( %d , &N);     for (int i = 1; i <= N - 1; i++)       scanf( %d%d , &x, &y), E[x].push_back(y), E[y].push_back(x);     dfs(1, 0);     dp[1][0].out();     return 0;   }


#include <bits/stdc++.h>   int n;   char s[11];   int main() {     scanf( %d , &n);     int pos = 20000;     for (int i = 1; i <= n; i++) {       int num;       scanf( %d%s , &num, s + 1);       if (s[1] ==  N ) {         if (pos + num > 20000) {           puts( NO );           return 0;         } else           pos += num;       } else if (s[1] ==  S ) {         if (pos - num < 0) {           puts( NO );           return 0;         } else           pos -= num;       } else {         if (pos == 0 || pos == 20000) {           puts( NO );           return 0;         }       }     }     if (pos == 20000)       puts( YES );     else       puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool cmp(pair<long long, long long> a, pair<long long, long long> b) {     if (a.first != b.first) {       return a.first < b.first;     }     return a.second > b.second;   }   const int maxn = (int)1e7;   struct vt {     int ed[2];     bool term;     vt() {       ed[0] = ed[1] = -1;       term = false;     }   };   vt mas[maxn];   int posit = 0;   int my_new() {     if (posit == maxn) {       throw 1;     }     return posit++;   }   void add(int t, long long x, int b, int mb) {     if (b == mb) {       mas[t].term = true;       return;     }     int c = (x >> b) & 1;     if (mas[t].ed[c] == -1) {       mas[t].ed[c] = my_new();     }     add(mas[t].ed[c], x, b - 1, mb);   }   void make(vector<pair<long long, long long> > &a) {     sort(a.begin(), a.end(), cmp);     long long rm = -1;     vector<pair<long long, long long> > res;     for (int i = 0; i < (int)a.size(); i++) {       if (a[i].second <= rm) {         continue;       } else {         rm = a[i].second;         res.push_back(a[i]);       }     }     a = res;   }   int t;   void calc(long long la, long long ra, long long lb, long long rb) {     add(t, la ^ lb, 59, -1);     add(t, ra ^ rb, 59, -1);     add(t, la ^ rb, 59, -1);     add(t, ra ^ lb, 59, -1);     for (int b = 59; b >= 0; b--) {       long long lx = (la >> b);       long long ly = (lb >> b);       long long rx = (ra >> b);       long long ry = (rb >> b);       if (lx != rx && (lx + 1) != rx) {         if ((lx & 1) == 0) {           add(t, ((lx + 1) ^ ly) << b, 59, b - 1);           add(t, ((lx + 1) ^ ry) << b, 59, b - 1);         }         if ((rx & 1) == 1) {           add(t, ((rx - 1) ^ ly) << b, 59, b - 1);           add(t, ((rx - 1) ^ ry) << b, 59, b - 1);         }       }       if (ly != ry && (ly + 1) != ry) {         if ((ly & 1) == 0) {           add(t, (lx ^ (ly + 1)) << b, 59, b - 1);           add(t, (rx ^ (ly + 1)) << b, 59, b - 1);         }         if (ry & 1) {           add(t, (lx ^ (ry - 1)) << b, 59, b - 1);           add(t, (rx ^ (ry - 1)) << b, 59, b - 1);         }       }       if (lx != rx && (lx + 1) != rx && ly != ry && (ly + 1) != ry) {         if ((lx & 1) == 0 && (ly & 1) == 0) {           add(t, ((lx + 1) ^ (ly + 1)) << b, 59, b - 1);         }         if ((lx & 1) == 0 && (ry & 1) == 1) {           add(t, ((lx + 1) ^ (ry - 1)) << b, 59, b - 1);         }         if ((rx & 1) == 1) {           if ((ly & 1) == 0) {             add(t, ((rx - 1) ^ (ly + 1)) << b, 59, b - 1);           }           if ((ry & 1) == 1) {             add(t, ((rx - 1) ^ (ry - 1)) << b, 59, b - 1);           }         }       }     }   }   const int mod = 998244353;   const int maxlog = 135;   int st[maxlog];   int build(int t, int b, long long x) {     if (mas[t].term) {       int y = x % mod;       y = (long long)y * st[b + 1] % mod;       int ans = (long long)y * st[b + 1] % mod;       ans += (long long)st[b] * (st[b + 1] - 1) % mod;       ans %= mod;       if (ans < 0) {         ans += mod;       }       return ans;     }     int ans = 0;     if (mas[t].ed[0] != -1) {       ans = build(mas[t].ed[0], b - 1, x << 1);     }     if (mas[t].ed[1] != -1) {       ans += build(mas[t].ed[1], b - 1, (x << 1) + 1);       if (ans >= mod) {         ans -= mod;       }     }     return ans;   }   signed main() {     t = my_new();     int n;     cin >> n;     vector<pair<long long, long long> > a(n);     for (int i = 0; i < n; i++) {       cin >> a[i].first >> a[i].second;     }     int m;     cin >> m;     vector<pair<long long, long long> > b(m);     for (int i = 0; i < m; i++) {       cin >> b[i].first >> b[i].second;     }     make(a);     make(b);     n = (int)a.size();     m = (int)b.size();     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         calc(a[i].first, a[i].second, b[j].first, b[j].second);       }     }     st[0] = 1;     for (int i = 1; i < maxlog; i++) {       st[i] = st[i - 1] * 2 % mod;     }     int ans = build(t, 59, 0);     cout << ans << endl;   }


#include <bits/stdc++.h>   int a[100010], b[100010];   bool check(int *a, int n, int id) {     int cntt = 0;     for (int i = 0; i < n; i++) {       if (i == id) continue;       b[cntt++] = a[i];     }     if (cntt == 1) return true;     for (int i = 1; i < cntt; i++)       if (b[i - 1] == 0 && b[i] != 0) return false;     if (cntt == 2) return true;     for (int i = 1; i < cntt - 1; i++) {       int num = b[i] * b[i];       if (num != b[i - 1] * b[i + 1]) return false;     }     return true;   }   bool check2(int *aa, int n) {     for (int i = 0; i < n; i++) b[i] = aa[i];     int cntt = 0;     if (b[0] == 0 && b[1] != 0) return false;     if (b[1] == 0 && b[2] != 0) return false;     if (b[1] * b[1] != b[0] * b[2]) return false;     bool zero = true;     int zeros = 0;     for (int i = 0; i < 3; i++) {       if (b[i] != 0)         zero = false;       else         zeros++;     }     if (zeros != 0) {       int cntt = 0;       for (int i = 3; i < n; i++)         if (b[i] != 0) cntt++;       if (cntt == 1) return true;       return false;     }     for (int i = 2; i < n; i++) {       int next = b[i - 1] * b[i - 1];       if (next % b[i - 2] != 0) return false;       next = next / b[i - 2];       if (next != b[i]) {         cntt++;         if (i != n - 1 && next != b[i + 1]) return false;         i++;         b[i - 1] = b[i - 2];       }     }     if (cntt == 1) return true;     return false;   }   int main() {     int n;     while (scanf( %d , &n) == 1) {       for (int i = 0; i < n; i++) scanf( %d , &a[i]);       int zeros = 0;       for (int i = 0; i < n; i++)         if (a[i] == 0) zeros++;       if (n == 1) {         puts( 0 );         continue;       }       if (zeros == n) {         puts( 0 );         continue;       }       if (zeros == n - 1 && a[0] == 0) {         puts( 1 );         continue;       }       if (check(a, n, -1)) {         puts( 0 );         continue;       }       if (check(a, n, 0) || check(a, n, 1) || check(a, n, 2)) {         puts( 1 );         continue;       }       if (check2(a, n)) {         puts( 1 );         continue;       }       puts( 2 );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k, i, j;     long long int flag = 0;     cin >> n >> k;     long long int m = n * n;     long long int p;     char a[1000][1000];     if (m % 2 == 0) {       p = m / 2;     } else {       p = (m + 1) / 2;     }     if (k > p) {       cout <<  NO  << endl;     } else {       cout <<  YES  << endl;       for (i = 1; i <= n; i++) {         for (j = 1; j <= n; j++) {           a[i][j] =  S ;         }       }       long long int c = 0;       for (i = 1; i <= n; i++) {         for (j = 1; j <= n; j++) {           if (c == k) {             flag = 1;             break;           }           if (i % 2 != 0 && j % 2 != 0) {             a[i][j] =  L ;             c++;           }           if (i % 2 == 0 && j % 2 == 0) {             a[i][j] =  L ;             c++;           }         }         if (flag == 1) {           break;         }       }       for (i = 1; i <= n; i++) {         for (j = 1; j <= n; j++) {           cout << a[i][j];         }         cout << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     int ans = ((n - 1) * n * (n + 1)) / 3 - 2;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   const int MN = 2e2 + 10;   template <typename T>   bool ckmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <typename T>   bool ckmax(T& a, const T& b) {     return b > a ? a = b, 1 : 0;   }   template <typename F, int MN, int MM>   struct MaxFlow {    public:     int hd[MN], to[MM * 2], nx[MM * 2], q[MN], cur[MN], lvl[MN], N, M, S, T;     F flow[MM * 2], cap[MM * 2];     void init(int _N) {       N = _N;       memset(hd, -1, N * sizeof *hd);     }     void add1(int u, int v, F c) {       flow[M] = 0, cap[M] = c;       nx[M] = hd[u], to[M] = v, hd[u] = M++;     }     void adde(int u, int v, F c) {       add1(u, v, c);       add1(v, u, 0);     }     bool bfs() {       memset(lvl, 0, N * sizeof *lvl);       lvl[S] = 1;       q[0] = S;       for (int i = 0, Q = 1, x, y; i < Q; ++i) {         x = q[i];         for (int j = hd[x]; ~j; j = nx[j])           if (cap[j] - flow[j] > 0 && !lvl[y = to[j]])             lvl[y] = lvl[x] + 1, q[Q++] = y;       }       return lvl[T];     }     F dfs(int n, F f) {       if (n == T) return f;       for (int &i = cur[n], x; ~i; i = nx[i])         if (cap[i] - flow[i] > 0 && lvl[x = to[i]] == lvl[n] + 1) {           F r = dfs(x, std::min(f, cap[i] - flow[i]));           if (r > 0) return flow[i] += r, flow[1 ^ i] -= r, r;         }       return 0;     }     F saturate(int _S, int _T) {       S = _S, T = _T;       F ans = 0;       while (bfs()) {         F x;         memcpy(cur, hd, N * sizeof *hd);         for (bool ok = 0; x = dfs(S, 1);)           if (x)             ans += x, ok = 1;           else if (ok)             break;           else             return ans;       }       return ans;     }   };   MaxFlow<int, MN * MN * 2, MN * MN * 6> maxflow;   int N, M, cnt;   char a[MN][MN];   int main() {     scanf( %d%d , &N, &M);     maxflow.init(N * M * 2 + 2);     for (int i = 0; i < N; ++i) scanf(  %s , a[i]);     for (int i = 0; i < N; ++i)       for (int j = 0; j < M; ++j)         if (a[i][j] ==  # ) {           int u = i && a[i - 1][j] ==  #  ? i * M + j << 1 : -1;           int d = i + 1 < N && a[i + 1][j] ==  #  ? (i + 1) * M + j << 1 : -1;           int l = j && a[i][j - 1] ==  #  ? i * M + j << 1 | 1 : -1;           int r = j + 1 < M && a[i][j + 1] ==  #  ? i * M + j + 1 << 1 | 1 : -1;           if (~u && ~r) maxflow.adde(u, r, 1);           if (~u && ~l) maxflow.adde(u, l, 1);           if (~d && ~r) maxflow.adde(d, r, 1);           if (~d && ~l) maxflow.adde(d, l, 1);           ++cnt;           cnt -= (u != -1) + (l != -1);         }     for (int i = 0; i < N * M; ++i) {       maxflow.adde(N * M * 2, i * 2, 1);       maxflow.adde(i * 2 + 1, N * M * 2 + 1, 1);     }     printf( %d n , cnt + maxflow.saturate(N * M * 2, N * M * 2 + 1));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, x;     cin >> n >> x;     long long a[n];     for (auto &i : a) cin >> i;     long long pre[n + 1];     pre[0] = 0;     for (long long i = 1; i <= n; i++) pre[i] = (pre[i - 1] + a[i - 1]) % x;     long long ans = 0;     for (long long i = 1; i <= n; i++) {       if (pre[i] != 0) ans = max(ans, i);     }     for (long long i = n; i >= 0; i--) {       if (pre[i] != pre[n]) ans = max(ans, n - i);     }     if (ans == 0)       cout << -1 <<   n ;     else       cout << ans <<   n ;   }   int32_t main() {     long long t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3fffffff;   const int SINF = 0x7fffffff;   const long long LINF = 0x3fffffffffffffff;   const long long SLINF = 0x7fffffffffffffff;   const long double DINF = pow(2, 100);   const int MAXN = 100007;   const long double EPS = 1e-17;   const long double AEPS = 1e-7;   const int TMS = 80;   const long double MAX = 4e9;   const long double PI = acos(-1.0);   class ftT {    public:     void clear() { memset(data, 0, sizeof(data)); }     void upd(int p, int x) {       for (; p < MAXN; p += p & -p) data[p] += x;     }     int sum(int p) {       int ans = 0;       for (; p; p ^= p & -p) ans += data[p];       return ans;     }     int query(int l, int r) { return sum(r) - sum(l - 1); }       private:     int data[MAXN];   } ft;   struct eT {     void setd(long double _t, long double _r, int _tp, int _id) {       t = _t, r = _r, tp = _tp, id = _id;     }     bool operator<(const eT &a) const {       return ((((t - a.t) >= 0) ? (t - a.t) : (-(t - a.t))) > EPS) ? t < a.t              : (tp ^ a.tp)                                         ? (tp > a.tp)                                                                    : (r < a.r);     }     long double t, r;     int tp, id;   } ev[MAXN];   int n, m;   int ke;   long double sx, sy;   long double la[MAXN], lb[MAXN];   long double al[MAXN], ar[MAXN];   int pl[MAXN], pr[MAXN];   void init();   void input();   void work();   void precheck(long double tst);   long long check(long double tst);   long double getsum(long double cr);   long double adj(long double ang);   long double getdist(int i, int j);   int main() {     init();     input();     work();   }   void init() { ios::sync_with_stdio(false); }   void input() {     scanf( %d , &n);     int tx, ty;     scanf( %d%d%d , &tx, &ty, &m), sx = static_cast<long double>(tx) / 1000,                                    sy = static_cast<long double>(ty) / 1000;     for (int i = 1; i <= n; ++i)       scanf( %d%d , &tx, &ty), la[i] = static_cast<long double>(tx) / 1000,                                lb[i] = static_cast<long double>(ty) / 1000;   }   void work() {     long double l = 0, r = MAX, mid;     for (int _t = 0; _t < TMS; ++_t) {       mid = l + (r - l) / 2;       if (check(mid) >= m)         r = mid;       else         l = mid;     }     long double maxd = l;     while (check(l) >= m) l -= (((1) > (l)) ? (1) : (l)) * AEPS;     int nc = check(l);     cout << setprecision(13) << fixed << (getsum(l) + maxd * (m - nc)) << endl;   }   void precheck(long double tst) {     long double sd, oa, da, a1, a2;     for (int i = 1; i <= n; ++i) {       sd = abs(la[i] * sx - sy + lb[i]) / sqrt(la[i] * la[i] + 1);       if (sd > tst - EPS)         al[i] = ar[i] = -DINF;       else {         if ((((la[i]) >= 0) ? (la[i]) : (-(la[i]))) < EPS)           oa = PI / 2;         else           oa = atan(-1 / la[i]);         if (oa < -EPS) oa += PI;         if (la[i] * sx + lb[i] - sy < -EPS) oa += PI;         da = acos(sd / tst);         a1 = adj(oa + da), a2 = adj(oa - da);         if (a1 > a2) swap(a1, a2);         al[i] = a1, ar[i] = a2;       }     }     ke = 0;     for (int i = 1; i <= n; ++i)       if (al[i] != -DINF)         ev[++ke].setd(al[i], ar[i], 1, i), ev[++ke].setd(ar[i], ar[i], 0, i);     sort(ev + 1, ev + 1 + ke);     for (int i = 1; i <= ke; ++i) {       if (ev[i].tp)         pl[ev[i].id] = i;       else         pr[ev[i].id] = i;     }   }   long long check(long double tst) {     precheck(tst);     long long ans = 0;     int ni;     ft.clear();     for (int i = 1; i <= ke; ++i) {       if (ev[i].tp) {         ni = ev[i].id;         ans += ft.query(pl[ni], pr[ni]);         ft.upd(pr[ni], 1);       }     }     return ans;   }   long double getsum(long double cr) {     precheck(cr);     long double ans = 0;     vector<pair<int, int> > ar;     int ni, li;     for (int i = 1; i <= ke; ++i) {       if (ev[i].tp) {         ni = ev[i].id;         li = lower_bound(ar.begin(), ar.end(), make_pair(i, 0)) - ar.begin();         for (int j = li; j < ar.size() && ar[j].first <= pr[ni]; ++j)           ans += getdist(ar[j].second, ni);         ar.insert(upper_bound(ar.begin(), ar.end(), make_pair(pr[ni], INF)),                   make_pair(pr[ni], ni));       }     }     return ans;   }   long double adj(long double ang) {     while (ang < -EPS) ang += 2 * PI;     while (ang > 2 * PI - EPS) ang -= 2 * PI;     return ang;   }   long double getdist(int i, int j) {     long double x = (lb[i] - lb[j]) / (la[j] - la[i]);     long double y = (la[j] * lb[i] - la[i] * lb[j]) / (la[j] - la[i]);     return sqrt((x - sx) * (x - sx) + (y - sy) * (y - sy));   }


#include <bits/stdc++.h>   using namespace std;   class segmentTree {    public:     int* tree;     int N;     int size;     void update(int qidx, int val) { update(qidx, val, 0, N - 1, 0); }     void update(int qidx, int val, int left, int right, int idx) {       if (left == right && left == qidx) {         tree[idx] = val;       } else if (qidx >= left && qidx <= right) {         int mid = (left + right) / 2;         update(qidx, val, left, mid, 2 * idx + 1);         update(qidx, val, mid + 1, right, 2 * idx + 2);         tree[idx] = min(tree[2 * idx + 1], tree[2 * idx + 2]);       }     }     int query(int qleft, int qright) { return query(qleft, qright, 0, N - 1, 0); }     int query(int qleft, int qright, int left, int right, int index) {       if (left >= qleft && right <= qright) return tree[index];       if (right < qleft || left > qright) return INT_MAX;       int mid = (left + right) / 2;       return min(query(qleft, qright, left, mid, 2 * index + 1),                  query(qleft, qright, mid + 1, right, 2 * index + 2));     }     segmentTree(int n) {       N = n;       int start = 2;       while ((start - 1) < 2 * N) start *= 2;       size = start - 1;       tree = new int[size];       memset(tree, -1, sizeof(int) * size);     }   };   const int MX = 1e5 + 69;   int used[MX], used2[MX];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     memset(used, 0, sizeof used);     memset(used2, 0, sizeof used2);     int n;     cin >> n;     segmentTree tree = segmentTree(n + 1);     int totmex = 1;     vector<int> submex;     for (int i = 0; i < n; i++) {       int w;       cin >> w;       used[w]++;       while (used[totmex]) totmex++;       if (w != 1) {         submex.push_back(1);       } else {         tree.update(1, i);         continue;       }       int lastw = tree.query(w, w);       int minbelow = tree.query(1, w - 1);       if (minbelow > lastw) submex.push_back(w);       tree.update(w, i);     }     for (int w = 2; w <= n; w++) {       int lastw = tree.query(w, w);       int minbelow = tree.query(1, w - 1);       if (minbelow > lastw) submex.push_back(w);     }     submex.push_back(totmex);     for (int v : submex) used2[v]++;     for (int ans = 1; ans < 1e9; ans++)       if (!used2[ans]) {         cout << ans <<   n ;         exit(0);       }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200010;   char s[N];   vector<int> v[N];   set<int> s1, s2;   set<int>::iterator j;   inline int gi() {     int x = 0, o = 1;     char ch = getchar();     while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar();     if (ch ==  - ) o = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * o;   }   int main() {     scanf( %s , s + 1);     int n = strlen(s + 1), sum = 0, k = 0;     for (int i = 1; i <= n; i++) {       sum += s[i] -  0 ;       if (sum + sum > i) return puts( -1 ), 0;       if (s[i] ==  1 )         s1.insert(i);       else         s2.insert(i);     }     sum = 0;     for (int i = n; i; i--) {       sum += s[i] -  0 ;       if (sum + sum > n - i + 1) return puts( -1 ), 0;     }     while (!s1.empty()) {       int now = 0;       bool flg = 0;       ++k;       while (now <= n) {         if (!flg) {           j = s2.lower_bound(now);           if (j == s2.end()) break;           now = (*j) + 1;           v[k].push_back(*j);         } else {           j = s1.lower_bound(now);           if (j == s1.end()) break;           now = (*j) + 1;           v[k].push_back(*j);         }         flg ^= 1;       }       for (int i = 0; i < v[k].size(); i++) {         if (s[v[k][i]] ==  0 )           s2.erase(v[k][i]);         else           s1.erase(v[k][i]);       }     }     for (j = s2.begin(); j != s2.end(); j++) v[++k].push_back(*j);     cout << k << endl;     for (int i = 1; i <= k; i++) {       printf( %d  , (int)v[i].size());       for (int j = 0; j < v[i].size(); j++) printf( %d  , v[i][j]);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5 * 1000000 + 100;   char str[maxn << 1], s[maxn];   int p[maxn << 1];   int ans;   int n;   int f[maxn << 1];   void Init(void) {     str[0] =  $ , str[1] =  # ;     for (int i = 0; i < n; i++) {       str[i * 2 + 2] = s[i];       str[i * 2 + 3] =  # ;     }     int nn = 2 * n + 2;     str[nn] = 0;     int mx = 0, id;     for (int i = 1; i < nn; i++) {       if (mx > i) {         p[i] = min(p[2 * id - i], mx - i);       } else         p[i] = 1;       while (str[i + p[i]] == str[i - p[i]]) p[i]++;       if (i + p[i] > mx) mx = i + p[i], id = i;     }   }   void solve(void) {     long long ans = 0;     for (int i = 1; i <= n; i++) {       int l = 2, r = 2 * i;       int m = (l + r) >> 1;       if (p[m] * 2 - 1 >= r - l + 1) f[r] = f[m - 1 + ((m % 2) ? 0 : -1)] + 1;       ans += f[r];     }     printf( %I64d n , ans);   }   int main(void) {     scanf( %s , s);     n = strlen(s);     Init();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   const int Maxn = 100005;   char s[Maxn];   int n, q;   int seq[Maxn * 15];   int pos[Maxn * 15];   int sum[Maxn * 15][10];   int Mx[Maxn * 15];   int fir[Maxn];   int prv[Maxn], nxt[Maxn];   void Del(int np) {     prv[nxt[np]] = prv[np];     nxt[prv[np]] = nxt[np];   }   int Move(int np, int d) { return (d == 1) ? nxt[np] : prv[np]; }   int f(char c) { return (c ==  > ) ? 1 : -1; }   int tmin[Maxn * 60], tmax[Maxn * 60];   void build(int push, int l, int r) {     if (l == r) {       tmin[push] = tmax[push] = pos[l];       return;     }     int mid = l + r >> 1;     build(push * 2, l, mid);     build(push * 2 + 1, mid + 1, r);     tmin[push] = min(tmin[push * 2], tmin[push * 2 + 1]);     tmax[push] = max(tmax[push * 2], tmax[push * 2 + 1]);   }   int queryMin(int push, int l, int r, int lo, int lim) {     if (tmin[push] >= lim) {       return -1;     }     if (l == r) {       return l;     }     int mid = l + r >> 1;     if (lo <= mid) {       int ans = queryMin(push * 2, l, mid, lo, lim);       if (ans != -1) {         return ans;       }     }     return queryMin(push * 2 + 1, mid + 1, r, max(mid + 1, lo), lim);   }   int queryMax(int push, int l, int r, int lo, int lim) {     if (tmax[push] <= lim) {       return -1;     }     if (l == r) {       return l;     }     int mid = l + r >> 1;     if (lo <= mid) {       int ans = queryMax(push * 2, l, mid, lo, lim);       if (ans != -1) {         return ans;       }     }     return queryMax(push * 2 + 1, mid + 1, r, max(mid + 1, lo), lim);   }   int main() {     scanf( %d %d , &n, &q);     scanf( %s , s + 1);     memset(seq, -1, sizeof(seq));     for (int i = 1; i <= n; i++) {       fir[i] = 1e9;       prv[i] = i - 1;       nxt[i] = i + 1;     }     int np = 1, Mxp = 1;     int dir = 1;     int nst = 1;     while (1) {       for (;;) {         if (np == 0 || np == n + 1) {           pos[nst] = np;           Mxp = max(Mxp, np);           fir[Mxp] = min(fir[Mxp], nst);           Mx[nst++] = Mxp;           break;         }         if (s[np] >=  0  && s[np] <=  9 ) {           seq[nst] = s[np] -  0 ;           pos[nst] = np;           Mxp = max(Mxp, np);           if (s[np] !=  0 ) {             s[np]--;           } else {             Del(np);           }           np = Move(np, dir);           fir[Mxp] = min(fir[Mxp], nst);           Mx[nst++] = Mxp;         } else if (s[np] ==  >  || s[np] ==  < ) {           pos[nst] = np;           Mxp = max(Mxp, np);           fir[Mxp] = min(fir[Mxp], nst);           Mx[nst++] = Mxp;           dir = f(s[np]);           int newpos = Move(np, dir);           if (newpos >= 1 && newpos <= n &&               (s[newpos] ==  <  || s[newpos] ==  > )) {             Del(np);           }           np = newpos;         }       }       if (Mxp >= n) break;       np = Mxp + 1;       dir = 1;     }     nst--;     for (int i = 1; i <= nst; i++) {       for (int j = 0; j < 10; j++) {         sum[i][j] = sum[i - 1][j];       }       if (seq[i] >= 0 && seq[i] <= 9) {         sum[i][seq[i]]++;       }     }     build(1, 1, nst);     for (int i = 1; i <= q; i++) {       int l, r;       scanf( %d %d , &l, &r);       int st = fir[l];       int ed1 = queryMin(1, 1, nst, st + 1, l),           ed2 = queryMax(1, 1, nst, st + 1, r);       if (ed1 == -1) ed1 = nst + 1;       if (ed2 == -1) ed2 = nst + 1;       int ed = min(ed1, ed2) - 1;       for (int j = 0; j < 10; j++) {         printf( %d  , sum[ed][j] - sum[st - 1][j]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100005];   int t[400005];   int d[400005];   pair<int, int> p[305];   pair<int, int> cp[305];   int n;   void build(int l, int r, int i) {     d[i] = 0;     if (l == r)       t[i] = a[l];     else {       int m = (l + r) / 2;       int L = 2 * i;       build(l, m, L);       build(m + 1, r, L + 1);       t[i] = (t[L] < t[L + 1] ? t[L] : t[L + 1]);     }   }   void update(int l, int r, int p, int x, int y, int i) {     if (l > y || r < x) return;     if (l <= x && r >= y) {       d[i] += p;       t[i] += p;       return;     }     int m = (x + y) / 2;     int L = 2 * i;     update(l, r, p, x, m, L);     update(l, r, p, m + 1, y, L + 1);     t[i] = (t[L] < t[L + 1] ? t[L] : t[L + 1]) + d[i];   }   bool comp(pair<int, int> x, pair<int, int> y) { return (x.second < y.second); }   int main() {     ios::sync_with_stdio(false);     int m;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) {       cin >> p[i].first >> p[i].second;       p[i].first--;       p[i].second--;       cp[i] = p[i];     }     sort(p, p + m);     int v = 0, an = -1000000007;     build(0, n - 1, 1);     for (int j = m - 1, i = n - 1; i >= 0; i--) {       if (an < a[i] - t[1]) {         an = a[i] - t[1];         v = i;       }       while (j >= 0 && p[j].first >= i) {         update(p[j].first, p[j].second, -1, 0, n - 1, 1);         j--;       }     }     sort(p, p + m, comp);     build(0, n - 1, 1);     for (int j = 0, i = 0; i < n; i++) {       if (an < a[i] - t[1]) {         an = a[i] - t[1];         v = i;       }       while (j < m && p[j].second <= i) {         update(p[j].first, p[j].second, -1, 0, n - 1, 1);         j++;       }     }     cout << an << endl;     int c = 0;     for (int i = 0; i < m; i++) {       if (v < p[i].first || v > p[i].second) c++;     }     cout << c << endl;     for (int i = 0; i < m; i++) {       if (v < cp[i].first || v > cp[i].second) cout << i + 1 <<    ;     }   }