#include <bits/stdc++.h>   using namespace std;   const int M = 100000 + 5;   map<long long int, int> mp;   queue<int> Q;   int vis[M];   long long int dk[M];   vector<long long int> step;   long long int a[M];   int rch[M];   struct TREE {     int lc;     int rc;     long long int l;     long long int r;     long long int idx;     long long int val;   } tree[20 * M];   int tot = 1;   void update(long long int l, long long int r, int node, long long int val,               long long int idx) {     if (l == r) {       tree[node].val += val;       tree[node].l = l;       tree[node].r = r;       tree[node].idx = idx;       tree[node].lc = node;       tree[node].rc = node;       return;     }     long long int m = (l + r) / 2;     if (tree[node].lc == 0) {       tot++;       tree[node].lc = tot;     }     if (tree[node].rc == 0) {       tot++;       tree[node].rc = tot;     }     if (idx <= m) {       update(l, m, tree[node].lc, val, idx);     } else {       update(m + 1, r, tree[node].rc, val, idx);     }     int lc = tree[node].lc;     int rc = tree[node].rc;     if (tree[lc].val < tree[rc].val) {       tree[node].idx = tree[rc].idx;       tree[node].val = tree[rc].val;     } else {       tree[node].idx = tree[lc].idx;       tree[node].val = tree[lc].val;     }     return;   }   int main() {     time_t t_start, t_end;     t_start = clock();     long long int h;     cin >> h;     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       long long int ai;       int ci;       cin >> ai >> ci;       a[i + 1] = ai;       mp[ai] = ci;       if (ai % k == 1) {         rch[i + 1] = 1;         update(1, M, 1, ci, i + 1);       }     }     step.push_back(k);     for (int q = 0; q < m; q++) {       int ty;       cin >> ty;       if (ty == 1) {         long long int x;         cin >> x;         step.push_back(x);         for (int i = 0; i < M; i++) {           vis[i] = 0;           dk[i] = -1;         }         Q.push(1);         dk[1] = 0;         while (!Q.empty()) {           int u = Q.front();           vis[u] = 0;           Q.pop();           for (int i = 0; i < step.size(); i++) {             long long int dx = step[i];             int nxtu = (u + dx) % k;             long long int nxty = (u + dk[u] * k + dx) / k;             if (dk[nxtu] == -1 || dk[nxtu] > nxty) {               dk[nxtu] = nxty;               if (vis[nxtu] == 0) {                 Q.push(nxtu);                 vis[nxtu] = 1;               }             }           }         }         for (int i = 1; i <= n; i++) {           long long int ai = a[i];           int u = ai % k;           if (dk[u] != -1) {             long long int yy = dk[u] * k + u;             if (ai >= yy && rch[i] == 0) {               rch[i] = 1;               update(1, M, 1, mp[ai], i);             }           }         }       }       if (ty == 2) {         int x;         long long int y;         cin >> x >> y;         long long int ai = a[x];         mp[ai] = mp[ai] - y;         if (rch[x] == 1) {           update(1, M, 1, -y, x);         }       }       if (ty == 3) {         long long int res = tree[1].val;         cout << res << endl;         update(1, M, 1, -res, tree[1].idx);       }     }     t_end = clock();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e9 + 113;   const long long maxn = 5000 + 113;   bool used[maxn];   int main() {     srand(time(NULL));     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<pair<pair<int, int>, int>> we;     for (int i = 0; i < n; i++) {       cout <<  ? 0   << i << endl;       cout.flush();       int s;       cin >> s;       we.push_back({{0, i}, s});     }     for (int i = 1; i < n; i++) {       cout <<  ?   << i <<   0  << endl;       cout.flush();       int s;       cin >> s;       we.push_back({{i, 0}, s});     }     int k = 1;     vector<int> p, b;     vector<int> ansp;     ansp.resize(n);     long long ans = 0;     p.resize(n), b.resize(n);     for (int x = 0; x < n; x++) {       for (int i = 0; i < n; i++) p[i] = 0, b[i] = 0;       p[0] = x;       for (int j = 0; j < we.size(); j++) {         if (we[j].first.first == 0)           b[we[j].first.second] = p[0] ^ we[j].second;         else           p[we[j].first.first] = b[0] ^ we[j].second;       }       bool tr = true;       for (int i = 0; i < n; i++) {         if (used[p[i]] == k || p[i] >= n) {           tr = false;           break;         }         used[p[i]] = k;       }       k++;       if (!tr) continue;       for (int i = 0; i < n; i++) {         if (used[b[i]] == k || b[i] >= n) {           tr = false;           break;         }         used[b[i]] = k;       }       k++;       if (!tr) continue;       for (int i = 0; i < n; i++) {         if (p[b[i]] != i) {           tr = false;           break;         }       }       if (!tr) continue;       if (!ans)         for (int i = 0; i < n; i++) ansp[i] = p[i];       ans++;     }     cout <<  !  << endl;     cout << ans << endl;     for (int i = 0; i < n; i++) cout << ansp[i] <<    ;     cout << endl;     cout.flush();   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7;   void add(int &a, int b) {     a += b;     if (a >= M) a -= M;   }   int mypow(int x, int t) {     int ans = 1, res = x;     while (t) {       if (t & 1) ans = (long long)ans * res % M;       res = (long long)res * res % M, t >>= 1;     }     return ans;   }   int n;   int fac[103], inv[103], p2[53], d[53], s1[53], s2[53], coef[53];   int f[53][53], g[53][103];   void init() {     fac[0] = 1;     for (int i = 1; i <= 100; i++) fac[i] = (long long)fac[i - 1] * i % M;     inv[100] = mypow(fac[100], M - 2);     for (int i = 99; ~i; i--) inv[i] = (long long)inv[i + 1] * (i + 1) % M;     p2[0] = 1;     for (int i = 1; i <= n; i++) p2[i] = (long long)p2[i - 1] * inv[2] % M;   }   int main() {     scanf( %d , &n);     init();     for (int i = 1; i <= n; i++) {       scanf( %d , &d[i]);       if (i > 1) {         d[i]--;         s1[i] = s1[i - 1], s2[i] = s2[i - 1];         if (d[i] == 1)           s1[i]++;         else           s2[i]++;       }     }     for (int s = 0; s <= n; s++)       for (int p = 0; p * 2 <= s; p++) {         int q = s - 2 * p, t = (long long)inv[p] * inv[q] % M;         if ((p + q) & 1)           add(coef[s], M - t);         else           add(coef[s], t);       }     f[1][d[1]] = 1;     for (int i = 1; i <= n; i++) {       for (int j = 0; j <= 2 * n; j++)         if (g[i][j])           for (int d = 0; d * 2 <= j; d++)             add(f[i][j - d * 2], (long long)g[i][j] * inv[d] % M * p2[d] % M);       for (int j = 1; i + j <= n; j++)         if (f[i][j]) {           int x = s1[i + j] - s1[i], y = s2[i + j] - s2[i];           int res = (long long)f[i][j] * fac[y] % M;           for (int s = 0; s <= y; s++)             add(g[i + j][x + 2 * y - 2 * s], (long long)res * coef[s] % M *                                                  fac[x + 2 * y - 2 * s] % M *                                                  inv[y - s] % M);         }     }     int ans = f[n][0];     for (int i = 2; i <= n; i++) ans = (long long)ans * inv[d[i]] % M;     printf( %d , ans);   }


#include <bits/stdc++.h>   using namespace std;   int n, rt, ra, ca, b;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int t;       scanf( %d , &t);       if (t != rt) {         rt = t;         ra = ca;         ca = 0;       }       ca++;       b = max(b, min(ra, ca) * 2);     }     printf( %d , b);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mabs(int a) {     if (a < 0)       return -a;     else       return a;   }   bool vis[4010];   int main() {     int x, k;     int t, n1, n2;     cin >> x >> k;     for (int i = 0; i < k; ++i) {       cin >> t;       if (t == 2) {         cin >> n2;         vis[n2] = true;       } else {         cin >> n2 >> n1;         vis[n2] = vis[n1] = true;       }     }     vector<int> v;     for (int i = 1; i < x; ++i)       if (!vis[i]) v.push_back(i);     int ret = 0;     for (int i = 1; i < v.size(); ++i) {       if (v[i] - v[i - 1] == 1) ++ret, ++i;     }     cout << ret + v.size() - ret * 2 <<     << v.size() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[200], b[200], res[200];   int main() {     int n, count, i, j, m, k, ans;     cin >> n >> m >> k;     for (i = 0; i < m; i++) cin >> a[i];     for (i = 0; i < k; i++) cin >> b[i];     for (i = 0; i < m; i++) {       for (j = 0; j < k; j++) {         if (b[j] % a[i] == 0) res[i]++;       }     }     ans = res[0];     for (i = 0; i < m; i++) ans = min(res[i], ans);     count = 0;     for (i = 0; i < m; i++)       if (res[i] == ans) count++;     cout << count <<   n ;     for (i = 0; i < m; i++)       if (ans == res[i]) cout << i + 1 <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long inf;   const double eps = 1e-8;   const double pi = acos(-1.0);   template <class T>   long long chkmin(T &a, T b) {     return a > b ? a = b, 1 : 0;   }   template <class T>   long long chkmax(T &a, T b) {     return a < b ? a = b, 1 : 0;   }   template <class T>   T sqr(T a) {     return a * a;   }   template <class T>   T mmin(T a, T b) {     return a < b ? a : b;   }   template <class T>   T mmax(T a, T b) {     return a > b ? a : b;   }   template <class T>   T aabs(T a) {     return a < 0 ? -a : a;   }   template <class T>   long long dcmp(T a, T b) {     return a > b;   }   template <long long *a>   long long cmp_a(long long first, long long second) {     return a[first] < a[second];   }   struct __INIT__ {     __INIT__() { memset(&inf, 0x3f, sizeof(inf)); }   } __INIT___;   namespace io {   const long long SIZE = (1 << 21) + 1;   char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c,                                          qu[55];   long long f, qr;   inline void flush() {     fwrite(obuf, 1, oS - obuf, stdout);     oS = obuf;   }   inline void putc(char first) {     *oS++ = first;     if (oS == oT) flush();   }   template <typename A>   inline bool read(A &first) {     for (f = 1, c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),                                 (iS == iT ? EOF : *iS++))                               : *iS++);          c <  0  || c >  9 ;          c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),                          (iS == iT ? EOF : *iS++))                        : *iS++))       if (c ==  - )         f = -1;       else if (c == EOF)         return 0;     for (first = 0; c <=  9  && c >=  0 ;          c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),                          (iS == iT ? EOF : *iS++))                        : *iS++))       first = first * 10 + (c & 15);     first *= f;     return 1;   }   inline bool read(char &first) {     while ((first = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),                                  (iS == iT ? EOF : *iS++))                               : *iS++)) ==     ||            first ==   n  || first ==   r )       ;     return first != EOF;   }   inline bool read(char *first) {     while ((*first = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),                                   (iS == iT ? EOF : *iS++))                                : *iS++)) ==   n  ||            *first ==     || *first ==   r )       ;     if (*first == EOF) return 0;     while (!(*first ==   n  || *first ==     || *first ==   r ))       *(++first) = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),                                 (iS == iT ? EOF : *iS++))                              : *iS++);     *first = 0;     return 1;   }   template <typename A, typename... B>   inline bool read(A &first, B &...second) {     return read(first) && read(second...);   }   template <typename A>   inline bool write(A first) {     if (!first) putc( 0 );     if (first < 0) putc( - ), first = -first;     while (first) qu[++qr] = first % 10 +  0 , first /= 10;     while (qr) putc(qu[qr--]);     return 0;   }   inline bool write(char first) {     putc(first);     return 0;   }   inline bool write(const char *first) {     while (*first) {       putc(*first);       ++first;     }     return 0;   }   inline bool write(char *first) {     while (*first) {       putc(*first);       ++first;     }     return 0;   }   template <typename A, typename... B>   inline bool write(A first, B... second) {     return write(first) || write(second...);   }   struct Flusher_ {     ~Flusher_() { flush(); }   } io_flusher_;   }  // namespace io   using io ::putc;   using io ::read;   using io ::write;   long long a[3005], b[3005];   vector<long long> to[3005];   pair<long long, long long> f[3005][3005], g[3005];   long long siz[3005];   pair<long long, long long> operator+(pair<long long, long long> a,                                        pair<long long, long long> b) {     return make_pair(a.first + b.first, a.second + b.second);   }   void dfs(long long first, long long fa) {     f[first][0] = make_pair(0, b[first]);     siz[first] = 0;     for (auto i : to[first])       if (i != fa) {         dfs(i, first);         for (long long j = 0; j <= siz[first] + siz[i] + 1; ++j)           g[j] = make_pair(-1, -1);         for (long long j = 0; j <= siz[first]; ++j)           for (long long k = 0; k <= siz[i]; ++k) {             chkmax(g[j + k], f[first][j] + f[i][k]);             chkmax(g[j + k + 1], make_pair(f[first][j].first + f[i][k].first +                                                (f[i][k].second > 0),                                            f[first][j].second));           }         for (long long j = 0; j <= siz[first] + siz[i] + 1; ++j)           f[first][j] = g[j];         siz[first] += siz[i] + 1;       }   }   signed main() {     long long t, n, m, u, v;     read(t);     for (; t; --t) {       read(n, m);       for (long long i = 1; i <= n; ++i) read(a[i]);       for (long long i = 1; i <= n; ++i) {         read(b[i]);         b[i] -= a[i];         to[i].clear();       }       for (long long i = 1; i < n; ++i) {         read(u, v);         to[u].push_back(v);         to[v].push_back(u);       }       dfs(1, 0);       write(f[1][m - 1].first + (f[1][m - 1].second > 0),   n );     }     return 0;   }


#include <bits/stdc++.h>   template <class T>   inline void read(T &res) {     char ch;     while (ch = getchar(), !isdigit(ch))       ;     res = ch ^ 48;     while (ch = getchar(), isdigit(ch)) res = res * 10 + ch - 48;   }   template <class T>   inline void put(T x) {     if (x > 9) put(x / 10);     putchar(x % 10 + 48);   }   const int N = 1e6 + 5;   int a[N], vis[N], nxt[N], pre[N], suf[N];   int n, m, now = 1;   inline void Fail() {     puts( no );     exit(0);   }   inline int Get() {     while (vis[now]) ++now;     if (now > n) Fail();     vis[now] = 1;     return now;   }   inline void Delete(int l, int r) {     int tl = pre[l], tr = suf[r];     suf[tl] = tr, pre[tr] = tl;   }   inline void Merge(int l, int r, int &x) {     while (x > l && suf[suf[x]] && suf[suf[x]] <= r && !a[x] && a[suf[x]] &&            a[suf[suf[x]]]) {       a[x] = a[suf[suf[x]]];       Delete(suf[x], suf[suf[x]]);       x = pre[x] > l ? pre[pre[x]] : pre[x];     }     while (x > l && suf[suf[x]] && suf[suf[x]] <= r && a[x] && a[suf[x]] &&            !a[suf[suf[x]]]) {       a[suf[suf[x]]] = a[x];       Delete(suf[x], suf[suf[x]]);       x = pre[x] > l ? pre[pre[x]] : pre[x];     }   }   inline void solve(int l, int r) {     if (r - l & 1) Fail();     for (int i = l; i <= r; i = suf[i])       while (nxt[i]) {         if (nxt[i] > r) Fail();         solve(suf[i], pre[nxt[i]]);         Delete(suf[i], nxt[i]);         nxt[i] = nxt[nxt[i]];       }     int num1 = 0, num2 = 0, rt = a[pre[l]];     for (int i = l; i <= r; i = suf[i]) num1 += a[i] > 0, ++num2;     num2 = (num2 >> 1) + 1;     if (num1 > num2) Fail();     num2 -= num1;     for (int i = l; num2 && i <= r; i = suf[i])       if (!a[i]) a[i] = Get(), --num2;     if (!a[l]) {       for (int i = suf[l]; i <= r; i = suf[i]) Merge(l, r, i);       Merge(l - 1, r, l);     } else {       for (int i = l; i <= r; i = suf[i]) Merge(l - 1, r, i);     }     for (int i = l; i <= r; i = suf[i])       if (!a[i]) a[i] = rt;   }   int main() {     read(n);     if (n == 1) return puts( yes n1 ), 0;     m = (n << 1) - 1;     for (int i = 1; i <= m; ++i) read(a[i]);     for (int i = 2; i <= m; ++i)       if (a[i] && a[i - 1] && a[i] == a[i - 1]) Fail();     if (a[1] && a[m] && a[1] != a[m]) Fail();     a[1] = a[m] = a[1] | a[m];     for (int i = 0; i <= m + 1; ++i) pre[i] = i - 1, suf[i] = i + 1;     pre[0] = 0;     for (int i = m; i >= 1; --i)       if (a[i]) {         nxt[i] = vis[a[i]];         vis[a[i]] = i;       }     solve(1, m);     puts( yes );     for (int i = 1; i <= m; ++i) put(a[i]), putchar(   );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long fact[200010], cnt, cnt1[200010], cnt2[200010];   void precalc() {     fact[0] = 1;     for (int i = 1; i < 200010; i++) {       fact[i] = (i * fact[i - 1]) % 1000000007;     }   }   long long power(long long a, long long b, long long p) {     if (b == 0) return 1;     long long ret = power(a, b / 2, p);     ret = (ret * ret) % p;     if ((b % 2) == 1) ret = (ret * a) % p;     return ret % p;   }   long long ncr(long long n, long long r) {     if (n < r) {       return 0;     }     long long ans = fact[n];     long long den = (fact[n - r] * fact[r]) % 1000000007;     ans = (ans * power(den, 1000000007 - 2, 1000000007)) % 1000000007;     return ans;   }   int main() {     precalc();     string str;     cin >> str;     long long n = str.length();     cnt = 0;     long long ans = 0;     for (int i = 0; i < n; i++) {       if (str[i] ==  ( ) {         cnt++;       }       cnt1[i] = cnt;     }     cnt = 0;     for (int i = n - 1; i >= 0; i--) {       if (str[i] ==  ) ) {         cnt++;       }       cnt2[i] = cnt;     }     for (int i = 0; i < n; i++) {       if (str[i] ==  ( ) {         long long x = cnt1[i];         long long y = cnt2[i];         ans = (ans + ncr(x + y - 1, x)) % 1000000007;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[101];   int d[101];   int main() {     int N;     cin >> N;     for (int i = 0; i < N; ++i) cin >> arr[i];     for (int i = 1; i < N; ++i) d[i] = arr[i] - arr[i - 1];     int ans = 1001;     for (int i = 1; i < N - 1; ++i) {       int temp1 = 0;       for (int j = 1; j < N; ++j) {         int temp2;         if (i == j) {           temp2 = d[j] + d[j + 1];           j++;         } else           temp2 = d[j];         temp1 = max(temp1, temp2);       }       ans = min(ans, temp1);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     scanf( %I64d %I64d , &n, &m);     long long a = min(n, m);     long long b = max(n, m);     long long ans;     if (a == 1) {       ans = b / 6 * 6;       if (b % 6 == 4)         ans += 2;       else if (b % 6 == 5)         ans += 4;     } else if (a == 2) {       if (b == 2)         ans = 0;       else if (b == 3)         ans = 4;       else if (b == 7)         ans = 12;       else         ans = a * b;     } else {       ans = a * b / 2 * 2;     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     vector<int> prime(n + 2, 1);     prime[0] = 0;     prime[1] = 0;     long long ans = 1;     for (long long i = 2; i <= n + 1; i++) {       if (prime[i] == 1 && i * i <= n + 1) {         for (long long j = i * i; j <= n + 1; j += i) {           prime[j] = 2;         }         ans = 2;       }     }     cout << ans << endl;     for (long long i = 2; i <= n + 1; i++) cout << prime[i] <<    ;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     vector<int> arr(n);     for (auto &x : arr) cin >> x;     int height = 1;     for (int i = 0; i < n; i++) {       if (i > 0 and !arr[i - 1] and !arr[i]) {         cout << -1 <<   n ;         return;       }       height += arr[i] + (i > 0 and arr[i] and arr[i - 1] ? 4 : 0);     }     cout << height << endl;   }   int main(int argc, char const *argv[]) {     int tc;     cin >> tc;     while (tc--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e9 + 55;   const int inf = 1e9 + 77;   const int MOD = 1e9 + 7;   const double PI = acos(-1.0);   const double eps = 1e-7;   vector<int> primes;   bitset<int(1e7) + 2> isprime;   void seive() {     isprime[0] = isprime[1] = 1;     for (int i = 2; i < int(1e6); ++i) {       if (!isprime.test(i)) {         primes.push_back(i);         for (int j = i * 2; j < int(1e6) + 2; j += i) {           isprime.set(j);         }       }     }   }   const int n = 1e6 + 55;   int p[2][n];   bool check(int n) {     if (n < int(1e6)) return !isprime.test(n);     for (auto i : primes)       if (n % i == 0) return false;     return true;   }   void factor(int a, int f) {     long long id = 0, pf = primes[0];     while (pf * pf <= a) {       while (a % pf == 0) {         a /= pf;         p[f][pf]++;       }       pf = primes[++id];     }     if (a != 1) p[f][a]++;   }   int main() {     seive();     int a, b;     scanf( %d , &a);     scanf( %d , &b);     bool t1 = true;     if (!check(a)) {       factor(a, 0);       t1 = false;     }     bool t2 = true;     if (!check(b)) {       factor(b, 1);       t2 = false;     }     if (t1 && t2) {       printf( -1 );       return 0;     }     if (t1 || t2) {       if (t1) {         if (t1 > int(1e6)) {           printf( -1 );           return 0;         }       } else {         if (t2 > int(1e6)) {           printf( -1 );           return 0;         }       }     }     if (t1) factor(a, 0);     if (t2) factor(b, 1);     int res1 = 0;     for (int i = 7; i < n; ++i) {       if (abs(p[1][i] - p[0][i]) > 0) {         res1 = -1;         break;       }     }     if (res1 == -1) {       printf( -1 );       return 0;     }     for (int i = 2; i <= 5; ++i) {       res1 += abs(p[0][i] - p[1][i]);     }     printf( %d , res1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long L, R;     int n;     cin >> n;     while (n--) {       cin >> L >> R;       for (long long k = 0; k <= 60; ++k) {         if ((1LL << k) & (L)) {           continue;         } else {           if ((1LL << k) + L <= R) {             L += (1LL << k);           } else {             break;           }         }       }       cout << L <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 3.14159265358979;   const double PI2 = 6.28318530717958;   const double PId2 = 1.570796326794895;   inline long long pw(long long n, int p) {     long long ans = 1;     for (int i = 0; i < p; i++) ans *= n;     return ans;   }   inline vector<int> ReadVI(int count) {     vector<int> arrayname(count);     for (int i = 0; i < int(count); i++) cin >> arrayname[i];     return arrayname;   };   inline vector<long long> ReadVlong(int count) {     vector<long long> arrayname(count);     for (int i = 0; i < int(count); i++) cin >> arrayname[i];     return arrayname;   };   inline vector<pair<int, int> > ReadVII(int count) {     vector<pair<int, int> > arrayname(count);     for (int i = 0; i < int(count); i++) {       cin >> arrayname[i].first;       arrayname[i].second = i;     }     return arrayname;   };   const int MOD = 1000000007;   const int MAXVALUE = 101;   int main() {     int f[5];     cin >> f[0] >> f[1] >> f[2] >> f[3] >> f[4];     int n;     cin >> n;     string a[5] = { S ,  M ,  L ,  XL ,  XXL };     int d[9] = {0, 1, -1, 2, -2, 3, -3, 4, -4};     string ts;     int t;     for (int i = 0; i < n; i++) {       cin >> ts;       t = 0;       for (; t < 5; t++)         if (a[t] == ts) break;       for (int j = 0; j < 9; j++) {         int k = t;         k += d[j];         if (k < 0 || k > 4) continue;         if (f[k]) {           f[k]--;           cout << a[k] << endl;           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void debug_out() { cerr <<   n ; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << H;     debug_out(T...);   }   const long long MAXN = 1e2 + 10, INF = 1e9;   long long n, m, k, a, b, u, v, floyd[MAXN][MAXN], second[MAXN], t[MAXN],       dp[2][MAXN];   bool bo[MAXN][MAXN];   vector<long long> h[MAXN];   void update(long long id) {     if (floyd[second[id]][t[id]] == INF) return;     for (long long i = 0; i <= floyd[second[id]][t[id]]; i++) h[i].clear();     for (long long i = 1; i <= n; i++) dp[1][i] = INF;     for (long long i = 1; i <= n; i++)       if (floyd[second[id]][i] + floyd[i][t[id]] == floyd[second[id]][t[id]])         h[floyd[second[id]][i]].push_back(i);     dp[1][t[id]] = dp[0][t[id]];     for (long long i = floyd[second[id]][t[id]] - 1; i >= 0; i--) {       for (auto u : h[i]) {         dp[1][u] = -1;         for (auto v : h[i + 1])           if (bo[u][v]) dp[1][u] = max(dp[1][u], dp[1][v]);         if (dp[1][u] == -1)           dp[1][u] = dp[0][u];         else           dp[1][u] = min(dp[1][u], dp[0][u]);       }       if ((long long)h[i].size() == 1)         dp[0][h[i][0]] = min(dp[0][h[i][0]], dp[1][h[i][0]] + 1);     }     return;   }   void pre_Floyd() {     for (long long i = 1; i <= n; i++)       for (long long j = 1; j <= n; j++) floyd[i][j] = INF, floyd[j][j] = 0;     return;   }   void Floyd_update() {     for (long long k = 1; k <= n; k++)       for (long long i = 1; i <= n; i++)         for (long long j = 1; j <= n; j++)           floyd[i][j] = min(floyd[i][j], floyd[i][k] + floyd[k][j]);     return;   }   int32_t main() {     cin >> n >> m >> a >> b, pre_Floyd();     for (long long i = 1; i <= n; i++) dp[0][i] = INF;     for (long long i = 1; i <= m; i++)       cin >> u >> v, floyd[u][v] = 1, bo[u][v] = true;     cin >> k;     for (long long i = 1; i <= k; i++) cin >> second[i] >> t[i];     Floyd_update(), dp[0][b] = 0;     for (long long i = 1; i <= n; i++)       for (long long j = 1; j <= k; j++) update(j);     if (dp[0][a] == INF) return cout << -1 <<   n , 0;     return cout << dp[0][a] <<   n , 0;   }


#include <bits/stdc++.h>   using namespace std;   set<string> st;   int main() {     string s;     cin >> s;     string a = s + s;     for (int i = 0; i < a.size() - s.size(); i++) {       string k =   ;       for (int j = i; j < i + s.size(); j++) k += a[j];       st.insert(k);     }     cout << st.size();   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long k, n, w;     cin >> k >> n >> w;     long long req = ((w * (w + 1)) / 2) * k;     req = req - n;     if (req > 0)       cout << req;     else       cout <<  0 ;   }


#include <bits/stdc++.h>      using namespace std;   typedef long long ll;      void solve() {       int a, b, k; cin >> a >> b >> k;       vector<int> A(k);       vector<int> B(k);       vector<int> cA(a + 1);       vector<int> cB(b + 1);       ll ans = 0;       for (int i = 0; i < k; i++) {           cin >> A[i];           cA[A[i]]++;       }       for (int i = 0; i < k; i++) {           cin >> B[i];           cB[B[i]]++;       }       for (int i = 0; i < k; i++) {           ans += k - cA[A[i]] - cB[B[i]] + 1;       }       cout << ans / 2 <<   n ;   }      int main() {       ios::sync_with_stdio(false);       cin.tie(nullptr);       int t; cin >> t;       while(t--) solve();       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t-- > 0) {       int n;       cin >> n;       int a[n];       cin >> a[0];       for (int i = 1; i < n; i++) {         cin >> a[i];       }       vector<int> v;       for (int i = 1; i < n - 1; i++) {         if ((a[i] > a[i - 1] && a[i] > a[i + 1]) ||             (a[i] < a[i - 1] && a[i] < a[i + 1]))           v.push_back(a[i]);       }       cout << v.size() + 2 << endl;       cout << a[0] <<    ;       for (auto i = v.begin(); i != v.end(); ++i) {         cout << *i <<    ;       }       cout << a[n - 1] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int e = 0; e < t; e++) {       long long n;       cin >> n;       vector<bool> used(n + 2, false);       long long q;       long long last = -1;       vector<long long> ans;       long long index = 1;       for (int i = 0; i < n; i++) {         cin >> q;         if (q != last) {           ans.push_back(q);           last = q;           used[q] = true;           continue;         }         while (used[index]) {           index++;           if (index >= q) {             index = -1;             break;           }         }         if (index == -1) {           cout << -1 << endl;           while (i < n - 1) {             cin >> q;             i++;           }           break;         }         ans.push_back(index);         used[index] = true;         continue;       }       if (index != -1)         for (int i = 0; i < ans.size(); i++) {           cout << ans[i] <<    ;         }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T read() {     T sum = 0, fl = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) fl = -1;     for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch -  0 ;     return sum * fl;   }   const int maxn = 5000 + 5;   const int maxm = 1e5 + 5;   int n, m, k, c;   long long mx[maxn];   bool del[maxm << 1], no[maxm];   int fa[maxn], id[maxm << 1];   vector<int> vec, E;   int he[maxn], ne[maxm << 1], to[maxm << 1], w[maxm << 1];   struct EDGE {     int u, v, w, id;   } e[maxm];   bool operator<(const EDGE& a, const EDGE& b) { return a.w < b.w; }   void add_edge(int u, int v, int val) {     ne[++c] = he[u];     he[u] = c;     to[c] = v;     w[c] = val;     ne[++c] = he[v];     he[v] = c;     to[c] = u;     w[c] = val;   }   int find(int first) {     return fa[first] == first ? first : fa[first] = find(fa[first]);   }   void forest() {     for (int i = 1; i <= n; ++i) fa[i] = i;     sort(e + 1, e + m + 1);     for (int i = 1; i <= m; ++i) {       int u = find(e[i].u), v = find(e[i].v);       if (u == v || u == 1 || v == 1) continue;       fa[u] = v;       E.push_back(e[i].id);       add_edge(e[i].u, e[i].v, e[i].w);       id[c] = id[c - 1] = e[i].id;     }   }   void get_max(int p, int f) {     for (int i = he[p]; i; i = ne[i]) {       if (to[i] == f || del[i] || to[i] == 1) continue;       if (w[i] >= w[mx[p]])         mx[to[i]] = i;       else         mx[to[i]] = mx[p];       get_max(to[i], p);     }   }   void Solve() {     n = read<int>(), m = read<int>(), k = read<int>();     c = 1;     for (int i = 1; i <= m; ++i)       e[i] = (EDGE){read<int>(), read<int>(), read<int>(), i};     forest();     for (int i = 1; i <= m; ++i) {       if (e[i].u != 1 && e[i].v != 1) continue;       int u = find(e[i].u), v = find(e[i].v);       if (u == v)         vec.push_back(i);       else         fa[u] = v, add_edge(e[i].u, e[i].v, e[i].w), E.push_back(e[i].id), --k;     }     for (int i = 2; i <= n; ++i)       if (find(i) != find(i - 1)) return (void)printf( -1 );     if (k < 0) return (void)printf( -1 );     for (int i = 1; i <= k; ++i) {       memset(mx, 0, sizeof(mx));       for (int j = he[1]; j; j = ne[j]) get_max(to[j], 1);       int now = -1, ans = 2147483647;       for (int j = vec.size() - 1; j >= 0; --j) {         int p = vec[j], var = max(e[p].u, e[p].v);         if (e[p].w - w[mx[var]] < ans) ans = e[p].w - w[mx[var]], now = j;       }       int p = vec[now], var = e[p].u == 1 ? e[p].v : e[p].u;       add_edge(e[p].v, e[p].u, e[p].w);       E.push_back(e[p].id);       no[id[mx[var]]] = 1;       del[mx[var]] = del[mx[var] ^ 1] = 1;       vec.erase(vec.begin() + now);     }     printf( %d n , n - 1);     for (int i = E.size() - 1; i >= 0; --i)       if (!no[E[i]]) printf( %d  , E[i]);   }   int main() {     Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k, a[10000];     cin >> n;     cin >> m;     string s[1000], f[1000];     for (int i = 0; i < n; i++) {       cin >> s[i];     }     for (int i = 0; i < m; i++) {       cin >> f[i];     }     cin >> k;     for (int i = 0; i < k; i++) {       cin >> a[i];     }     for (int i = 0; i < k; i++) {       a[i]--;       cout << s[a[i] % n] << f[a[i] % m] << endl;     }   }


/*   {   ######################   #       Author       #   #        Gary        #   #        2021        #   ######################   */   #include<bits/stdc++.h>   #define rb(a,b,c) for(int a=b;a<=c;++a)   #define rl(a,b,c) for(int a=b;a>=c;--a)   #define LL long long   #define IT iterator   #define PB push_back   #define II(a,b) make_pair(a,b)   #define FIR first   #define SEC second   #define FREO freopen( check.out , w ,stdout)   #define rep(a,b) for(int a=0;a<b;++a)   #define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())   #define random(a) rng()%a   #define ALL(a) a.begin(),a.end()   #define POB pop_back   #define ff fflush(stdout)   #define fastio ios::sync_with_stdio(false)   #define check_min(a,b) a=min(a,b)   #define check_max(a,b) a=max(a,b)   using namespace std;   //inline int read(){   //    int x=0;   //    char ch=getchar();   //    while(ch< 0 ||ch> 9 ){   //        ch=getchar();   //    }   //    while(ch>= 0 &&ch<= 9 ){   //        x=(x<<1)+(x<<3)+(ch^48);   //        ch=getchar();   //    }   //    return x;   //}   const int INF=0x3f3f3f3f;   typedef pair<int,int> mp;   /*}   */   int root=1,cnt=1,ans[200000*41+233],lc[200000*41+233],rc[200000*41+233],depth[200000*41+233],r[200000*41+233],l[200000*41+233],tag[200000*41+233];   bool have[200000*41+233];   void pushdown(int idx){    if((tag[idx]>>depth[idx])&1) swap(lc[idx],rc[idx]);    if(lc[idx]) tag[lc[idx]]^=tag[idx];    if(rc[idx]) tag[rc[idx]]^=tag[idx];    int oldl=l[idx],oldr=r[idx];    r[idx]^=r[idx]&tag[idx];    l[idx]^=l[idx]&tag[idx];    r[idx]|=oldl&tag[idx];    l[idx]|=oldr&tag[idx];    tag[idx]=0;    assert(!(l[idx]&r[idx]));   }   void upd(int idx){    ans[idx]=have[idx];    if(depth[idx]==20) return ;    l[idx]=r[idx]=0;    assert(lc[idx]||rc[idx]);    if(lc[idx]) pushdown(lc[idx]),ans[idx]+=ans[lc[idx]],assert(!tag[lc[idx]]);    else r[idx]|=1<<depth[idx];    if(rc[idx]) pushdown(rc[idx]),ans[idx]+=ans[rc[idx]],assert(!tag[rc[idx]]);    else l[idx]|=1<<depth[idx];    if(lc[idx]&&rc[idx]) l[idx]|=l[lc[idx]]&l[rc[idx]],r[idx]|=r[lc[idx]]&r[rc[idx]];    else l[idx]|=l[max(lc[idx],rc[idx])],r[idx]|=r[max(lc[idx],rc[idx])];     assert(!(l[idx]&r[idx]));   }   void merge(int& u,int& v){//merge(u,v) -> v    if(!u||!v){     if(u){      v=u;      u=0;     }     if(v) pushdown(v);     return ;    }    pushdown(u),pushdown(v);    have[v]|=have[u];    merge(rc[u],rc[v]);    merge(lc[u],lc[v]);   // cout<<u<<   <<v<<   <<rc[v]<<   <<lc[v]<<   <<endl;    u=0;    upd(v);   }   int Rev(int x){    int ret=0;    rep(i,20){     ret|=((x>>i)&1)<<(19-i);    }    return ret;   }   void split(int rt,int val,int & x,int & y){    if(!rt){     x=y=0;     return ;    }    pushdown(rt);    if(depth[rt]==20){     x=rt,y=0;     return;    }    if((val>>depth[rt])&1){     x=rt;     y=++cnt;     depth[cnt]=depth[rt];     split(rc[rt],val,rc[x],rc[y]);    }    else{     x=++cnt;     y=rt;                                                                                depth[cnt]=depth[rt];     split(lc[rt],val,lc[x],lc[y]);    }    if(!lc[x]&&!rc[x]){     x=0;    }    if(!lc[y]&&!rc[y]){     y=0;    }    if(x) upd(x);    if(y) upd(y);   }   void getor(int idx,int x){    if(depth[idx]==20) return ;    pushdown(idx);        if((x&(l[idx]|r[idx]))==x){     tag[idx]^=x&l[idx];     pushdown(idx);     return ;    }        if((x>>depth[idx])&1);    else{     if(lc[idx]) getor(lc[idx],x);     if(rc[idx]) getor(rc[idx],x);     upd(idx);     return ;    }    if(lc[idx]&&rc[idx]){     merge(lc[idx],rc[idx]);     getor(rc[idx],x^(1<<depth[idx]));     upd(idx);     return ;    }    if(lc[idx]){     swap(lc[idx],rc[idx]);     getor(rc[idx],x^(1<<depth[idx]));     upd(idx);     return ;    }    assert(rc[idx]);    getor(rc[idx],x^(1<<depth[idx]));    upd(idx);   }   void insert(int rt,int val){    if(depth[rt]==20){     have[rt]=1;     upd(rt);     return ;     }    bool bt=(val>>depth[rt])&1;    if(bt){     if(!rc[rt]) rc[rt]=++cnt,depth[cnt]=depth[rt]+1;     insert(rc[rt],val);    }    else{     if(!lc[rt]) lc[rt]=++cnt,depth[cnt]=depth[rt]+1;     insert(lc[rt],val);    }    upd(rt);   }   int main(){    int n,q;    scanf( %d%d ,&n,&q);    rb(i,1,n){     int ai;     scanf( %d ,&ai);     insert(root,Rev(ai));    }    rb(i,1,q){     int ty,l,r;     scanf( %d%d%d ,&ty,&l,&r);     int x=0,y=0,z=0;     split(root,Rev(r),y,z);     if(l)     split(y,Rev(l-1),x,y);     else x=0;     if(ty<=3){      int X;      scanf( %d ,&X);   //   if(n==1000) cout<<ty<<   <<l<<   <<r<<   <<X<<endl;      if(y){       if(ty==1){        tag[y]^=(1<<20)-1;        getor(y,((1<<20)-1)^Rev(X));        tag[y]^=(1<<20)-1;       }       if(ty==2){        getor(y,Rev(X));       }       if(ty==3){        tag[y]^=Rev(X);       }       pushdown(y);      }     }     else{   //   if(n==1000) cout<<ty<<   <<l<<   <.<r<<endl;      printf( %d n ,ans[y]);     }     merge(x,y);     merge(y,z);     root=z;    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   long long a[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t, n, k;     cin >> t;     while (t--) {       cin >> n;       string ans, e, ant;       bool ok = 0;       for (int i = 0; i < (int)n - 2; i++) {         cin >> e;         if (!i)           ans += e[0];         else if (e[0] == ant[1])           ans += e[0];         else           ans += ant[1], ans += e[0], ok = 1;         ant = e;       }       ans += ant[1];       if (!ok) ans +=  b ;       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int MAXN = 1000;   int n;   set<int> s[4];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       int tmp;       for (int j = 1; j <= 6; j++) cin >> tmp, s[i].insert(tmp);     }     int i;     for (i = 1; i <= MAXN; i++) {       if (i == MAXN) break;       multiset<int> ms;       int t = i;       while (t > 0) {         ms.insert(t % 10);         t /= 10;       }       for (int j = 1; j <= n; j++) {         for (auto x : ms)           if (s[j].count(x) > 0) {             ms.erase(ms.find(x));             break;           }       }       if (ms.empty()) continue;       ms.clear();       t = i;       while (t > 0) {         ms.insert(t % 10);         t /= 10;       }       for (int j = n; j > 0; j--) {         for (auto x : ms)           if (s[j].count(x) > 0) {             ms.erase(ms.find(x));             break;           }       }       if (ms.empty()) continue;       break;     }     cout << i - 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   long long n;   long long fa[1010000], lg[1010000];   long long cnt[1010000], maxx = 0;   long long a[1010000];   long long find(long long x) {     if (x == fa[x]) return x;     return fa[x] = find(fa[x]);   }   signed main() {     n = read();     long long ans = 0;     for (long long i = 1; i <= n; i++)       a[i] = read(), maxx = max(maxx, a[i]), ans -= a[i], cnt[a[i]]++;     for (long long i = 1; i <= maxx; i++) fa[i] = i, lg[i] = lg[i >> 1] + 1;     cnt[0]++;     long long m = 1 << (lg[maxx] + 1);     for (register long long i = m - 1; ~i; i--) {       for (long long j = i; j * 2 > i; j = (j - 1) & i) {         long long x = j, y = i ^ j;         if (!cnt[x] || !cnt[y]) continue;         x = find(x), y = find(y);         if (x != y) {           ans += i * (cnt[x] + cnt[y] - 1);           fa[x] = y;           cnt[y] = 1;         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long q, n;   int main() {     cin >> q;     for (int i = 0; i < q; i++) {       cin >> n;       vector<long long> nums;       long long cSum = 0, power = 0;       while (cSum < n) {         cSum += pow(3, power);         nums.push_back(pow(3, power));         power++;       }       for (long long j = nums.size() - 1; j >= 0; j--) {         if (cSum - nums[j] >= n) cSum -= nums[j];       }       cout << cSum <<   n ;     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   template <class T>   T gcd(T a, T b) {     return ((b == 0) ? a : gcd(b, a % b));   }   int m[1005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<int> a(((n) * (n)));     memset(m, 0, sizeof(m));     for (int i = 0; i < (int)(((n) * (n))); i++) cin >> a[i], m[a[i]]++;     if (n & 1) {       vector<int> pos, pos1;       for (int i = 0; i < (int)(1005); i++) {         if (m[i])           for (int j = 0; j < (int)((m[i] / 4)); j++) pos.push_back(i);         m[i] %= 4;         while (m[i]--) pos1.push_back(i);       }       int ans[n][n];       for (int i = 0; i < (int)(n); i++)         for (int j = 0; j < (int)(n); j++) ans[i][j] = -1;       for (int i = 0; i < (int)(n / 2); i++)         for (int j = 0; j < (int)(n / 2); j++) {           if (!pos.size()) {             cout <<  NO  << endl;             return 0;           }           int now = pos[(int)pos.size() - 1];           pos.pop_back();           ans[i][j] = now;           ans[i][n - j - 1] = now;           ans[n - i - 1][j] = now;           ans[n - i - 1][n - j - 1] = now;         }       int m1[1005];       memset(m1, 0, sizeof(m1));       for (int i = 0; i < (int)(pos.size()); i++) {         for (int j = 0; j < (int)(4); j++) pos1.push_back(pos[i]);       }       for (int i = 0; i < (int)(pos1.size()); i++) m1[pos1[i]]++;       vector<int> pos2;       int sp = 0;       for (int i = 0; i < (int)(1005); i++) {         if (m1[i]) {           for (int j = 0; j < (int)((m1[i] / 2)); j++) pos2.push_back(i);           if (m1[i] & 1) sp = i;         }       }       ans[n / 2][n / 2] = sp;       for (int i = 0; i < (int)(n / 2); i++) {         if (!pos2.size()) {           cout <<  NO  << endl;           return 0;         }         int num = pos2[pos2.size() - 1];         pos2.pop_back();         ans[n / 2][i] = num;         ans[n / 2][n - i - 1] = num;       }       for (int i = 0; i < (int)(n / 2); i++) {         if (!pos2.size()) {           cout <<  NO  << endl;           return 0;         }         int num = pos2[pos2.size() - 1];         pos2.pop_back();         ans[i][n / 2] = num;         ans[n - i - 1][n / 2] = num;       }       cout <<  YES  << endl;       for (int i = 0; i < (int)(n); i++) {         for (int j = 0; j < (int)(n); j++) {           if (ans[i][j] == -1) {             cout <<  NO  << endl;             return 0;           }           cout << ans[i][j] <<    ;         }         cout << endl;       }     } else {       vector<int> pos;       for (int i = 0; i < (int)(1005); i++) {         if (m[i] % 4 != 0) {           cout <<  NO  << endl;           return 0;         } else if (m[i])           for (int j = 0; j < (int)((m[i] / 4)); j++) pos.push_back(i);       }       int ans[n][n];       for (int i = 0; i < (int)(n); i++)         for (int j = 0; j < (int)(n); j++) ans[i][j] = -1;       for (int i = 0; i < (int)(n / 2); i++)         for (int j = 0; j < (int)(n / 2); j++) {           if (!pos.size()) {             cout <<  NO  << endl;             return 0;           }           int now = pos[(int)pos.size() - 1];           pos.pop_back();           ans[i][j] = now;           ans[i][n - j - 1] = now;           ans[n - i - 1][j] = now;           ans[n - i - 1][n - j - 1] = now;         }       cout <<  YES  << endl;       for (int i = 0; i < (int)(n); i++) {         for (int j = 0; j < (int)(n); j++) {           if (ans[i][j] == -1) {             cout <<  NO  << endl;             return 0;           }           cout << ans[i][j] <<    ;         }         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4786)   using namespace std;   long long heads[100005], tracks[100005];   int n, m;   long long Abs(long long x) { return x < 0 ? -x : x; }   int check(long long x) {     int i, j = 0;     for (i = 0; i < n; i++) {       if (Abs(heads[i] - tracks[j]) > x) continue;       int lo = j, hi = m - 1, k = -1;       while (lo <= hi) {         int mid = (lo + hi) / 2;         long long t1 = Abs(heads[i] - tracks[mid]) + tracks[mid] - tracks[j];         long long t2 = Abs(heads[i] - tracks[j]) + tracks[mid] - tracks[j];         long long t = ((t1) < (t2) ? (t1) : (t2));         if (t <= x)           k = mid, lo = mid + 1;         else           hi = mid - 1;       }       if (k < 0) continue;       j = k + 1;       if (j == m) return 1;     }     return 0;   }   int main() {     int i, j, k, T;     cin >> n >> m;     for (i = 0; i < n; i++) cin >> heads[i];     for (i = 0; i < m; i++) cin >> tracks[i];     long long lo = 0, hi = 1;     for (i = 0; i < 16; i++) hi *= (long long)10;     long long ans = -1;     while (lo <= hi) {       long long mid = (lo + hi) / 2;       if (check(mid))         ans = mid, hi = mid - 1;       else         lo = mid + 1;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   const int mod = (int)1e9 + 7;   const long long INF = 10000005;   const int inf = 1 << 30;   char buf[1000];   const int N = 210;   vector<int> dep[N];   vector<int> computer[3];   bool completed[N];   int n;   int check(int start) {     int tot = 0, done = 0;     memset(completed, false, sizeof(completed));     while (done < n) {       bool found = true;       while (found) {         found = false;         for (vector<int>::iterator i = computer[start].begin();              i != computer[start].end(); ++i) {           if (!completed[*i]) {             bool cando = true;             for (vector<int>::iterator j = dep[*i].begin(); j != dep[*i].end();                  ++j) {               if (!completed[*j]) {                 cando = false;                 break;               }             }             if (cando) {               done++;               completed[*i] = true;               found = true;             }           }         }       }       if (done < n) {         tot++;         start = (start + 1) % 3;       }     }     return tot;   }   int main() {     cin >> n;     int tmp;     for (int i = 0; i < n; ++i) {       scanf( %d , &tmp);       computer[tmp - 1].push_back(i);     }     for (int i = 0; i < n; ++i) {       int d;       scanf( %d , &d);       for (int j = 0; j < d; ++j) {         scanf( %d , &tmp);         dep[i].push_back(tmp - 1);       }     }     cout << n + min(check(0), min(check(1), check(2))) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 500050;   const int inf = 0x3f3f3f3f;   const long long llinf = 0x3f3f3f3f3f3f3f3f;   const int mod = 998244353;   const int MOD = 1e9 + 7;   const double PI = acos(-1.0);   clock_t TIME__START, TIME__END;   void program_end() {}   const int Gmod = 3, maxn = (1 << 20) - 1;   inline int ksm(long long x, long long y) {     int ret = 1;     while (y) {       if (y & 1) ret = 1ll * ret * x % mod;       x = 1ll * x * x % mod;       y >>= 1;     }     return ret;   }   int rev[maxn], _lstN, P[maxn], iP[maxn];   inline void ntt(int *A, int polyN, int t) {     for (int i = 0; i < polyN; ++i)       if (rev[i] > i) std::swap(A[i], A[rev[i]]);     for (int o = 1; o < polyN; o <<= 1) {       int W = t ? P[o] : iP[o];       for (int *p = A; p != A + polyN; p += o << 1)         for (int i = 0, w = 1; i < o; ++i, w = 1ll * w * W % mod) {           int t = 1ll * w * p[i + o] % mod;           p[i + o] = (p[i] - t + mod) % mod;           p[i] = (p[i] + t) % mod;         }     }     if (!t) {       int inv = ksm(polyN, mod - 2);       for (int i = 0; i < polyN; ++i) A[i] = 1ll * A[i] * inv % mod;     }   }   int polyN, lg;   inline void setN(int n) {     polyN = 1, lg = 0;     while (polyN < n) polyN <<= 1, ++lg;     if (polyN != _lstN)       for (int i = 0; i < polyN; ++i)         rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (lg - 1));   }   inline void ntt(std::vector<int> &a, int t) {     static int A[maxn];     for (int i = 0; i < (int)a.size(); ++i) A[i] = a[i];     memset(A + a.size(), 0, 4 * (polyN - a.size()));     ntt(A, polyN, t);     a.resize(polyN);     for (int i = 0; i < polyN; ++i) a[i] = A[i];     int s = a.size();     while (s && !a[s - 1]) --s;     a.resize(s);   }   inline std::vector<int> mul(std::vector<int> a, std::vector<int> b,                               int newn = -1) {     if (newn == -1) newn = a.size() + b.size() - 1;     setN(a.size() + b.size() - 1);     ntt(a, 1), ntt(b, 1);     for (int i = 0; i < polyN; ++i) a[i] = 1ll * a[i] * b[i] % mod;     ntt(a, 0);     a.resize(newn);     return a;   }   inline std::vector<int> operator+(std::vector<int> a,                                     const std::vector<int> &b) {     if (a.size() < b.size()) a.resize(b.size());     for (int i = 0; i < (int)a.size(); ++i)       if (i < (int)b.size()) a[i] = (a[i] + b[i]) % mod;     return a;   }   inline std::vector<int> operator-(std::vector<int> a,                                     const std::vector<int> &b) {     if (a.size() < b.size()) a.resize(b.size());     for (int i = 0; i < (int)a.size(); ++i)       if (i < (int)b.size()) a[i] = (a[i] - b[i] + mod) % mod;     return a;   }   inline std::vector<int> operator*(std::vector<int> a, int b) {     for (auto &i : a) i = 1ll * i * b % mod;     return a;   }   inline std::vector<int> polydiff(std::vector<int> a) {     for (int i = 0; i < (int)a.size() - 1; ++i)       a[i] = 1ll * a[i + 1] * (i + 1) % mod;     a.erase(a.end() - 1);     return a;   }   inline std::vector<int> polyint(std::vector<int> a) {     a.insert(a.begin(), 0);     for (int i = 1; i < (int)a.size(); ++i)       a[i] = 1ll * a[i] * ksm(i, mod - 2) % mod;     return a;   }   inline std::vector<int> getinv(std::vector<int> a) {     if (a.size() == 1) return std::vector<int>(1, ksm(a[0], mod - 2));     int n = a.size(), m = (a.size() + 1) >> 1;     std::vector<int> _a(m);     for (int i = 0; i < m; ++i) _a[i] = a[i];     std::vector<int> b = getinv(_a);     setN(n + m * 2 - 2);     ntt(a, 1);     ntt(b, 1);     for (int i = 0; i < polyN; ++i) a[i] = 1ll * a[i] * b[i] % mod * b[i] % mod;     ntt(a, 0), ntt(b, 0);     a.resize(n);     return b * 2 - a;   }   inline std::vector<int> getln(std::vector<int> a, int n = -1) {     if (n == -1) n = a.size();     a.resize(n);     return polyint(mul(polydiff(a), getinv(a), n));   }   inline std::vector<int> getexp(std::vector<int> a) {     if (a.size() == 1) return a[0] = 1, a;     int m = (a.size() + 1) >> 1;     std::vector<int> _a(m);     for (int i = 0; i < m; ++i) _a[i] = a[i];     std::vector<int> b = getexp(_a);     return mul(b, std::vector<int>(1, 1) - getln(b, a.size()) + a, a.size());   }   inline std::vector<int> operator^(std::vector<int> a, int b) {     int n = a.size();     a = getexp(getln(a) * b);     a.resize(n);     return a;   }   inline std::vector<int> operator%(std::vector<int> a, std::vector<int> b) {     int n = a.size(), m = b.size();     if (n < m) return a;     std::reverse(a.begin(), a.end());     std::reverse(b.begin(), b.end());     b.resize(n);     std::vector<int> c = mul(a, getinv(b), n - m + 1);     std::reverse(a.begin(), a.end());     b.resize(m);     std::reverse(b.begin(), b.end());     std::reverse(c.begin(), c.end());     a = a - mul(b, c);     int s = a.size();     while (s && !a[s - 1]) --s;     a.resize(s);     return a;   }   inline std::vector<int> sqrt(std::vector<int> a) {     if (a.size() == 1) return a;     int n = a.size(), m = (a.size() + 1) >> 1;     std::vector<int> _a(m);     for (int i = 0; i < m; ++i) _a[i] = a[i];     std::vector<int> b = sqrt(_a);     b.resize(n);     return (b + mul(a, getinv(b), n)) * ((mod + 1) >> 1);   }   inline void poly_init() {     int G = Gmod, iG = ksm(G, mod - 2);     for (int i = 1; i < maxn; i <<= 1)       P[i] = ksm(G, (mod - 1) / (i << 1)), iP[i] = ksm(iG, (mod - 1) / (i << 1));   }   struct auto_poly_init {     auto_poly_init() { poly_init(); }   } __auto_init;   std::vector<int> F, G;   int n, m, c[N];   inline void solve() {     scanf( %d%d , &n, &m);     G.resize(100005, 0);     for (int i = 1; i <= n; ++i) scanf( %d , &c[i]);     for (int i = 1; i <= n; ++i) G[c[i]] = 1;     G = G * (-4);     G[0]++;     G = sqrt(G);     G[0]++;     G = getinv(G);     F = G * 2;     for (int i = 1; i <= m; ++i) cout << F[i] <<   n ;   }   int main() {     TIME__START = clock();     int Test = 1;     while (Test--) {       solve();     }     TIME__END = clock();     program_end();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x7fffffff;   const double eps = 1e-10;   const double pi = acos(-1.0);   inline int read() {     int x = 0, f = 1;     char ch;     ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = 0;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + (ch & 15);       ch = getchar();     }     if (f)       return x;     else       return -x;   }   const int N = 5010;   int n, a, b;   int val[N], nex[N], ans;   char s[N];   int main() {     n = read();     a = read();     b = read();     memset(val, 0x3f, sizeof(val));     val[0] = 0;     scanf( %s , s + 1);     for (int i = 1; i <= n; i++) {       val[i] = min(val[i], val[i - 1] + a);       nex[i] = i - 1;       int p = i - 1;       for (int j = i + 1; j <= n; j++) {         while (p >= i && s[j] != s[p + 1]) p = nex[p];         if (s[j] == s[p + 1]) p++;         nex[j] = p;       }       p = i - 1;       for (int j = 1; j <= i - 1; j++) {         while (p >= i && s[j] != s[p + 1]) p = nex[p];         if (s[j] == s[p + 1]) p++;         if (p >= i) val[p] = min(val[p], val[i - 1] + b);       }     }     printf( %d n , val[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[200004], n, m;   int c[400004];   long long greaterc(int m) {     long long ans = 0, add = 0;     memset(c, 0, sizeof(c));     int div = n;     c[n] = 1;     for (int i = 0; i < n; i++) {       if (a[i] < m)         div--, add -= c[div];       else         add += c[div], div++;       ans += add;       c[div]++;     }     return ans;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     cout << greaterc(m) - greaterc(m + 1) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353;   const int N = 100005;   const double PI = 4 * atan(1);   const double eps = 1e-7;   const long long oo = 1e18;   const int AlPHA = 26, B = 30;   long long n, m, L, sr, t;   long long adj[1005][1005];   long long yes[1005][1005];   long long dist[1005];   vector<long long> ad[N];   bool vis[1005];   vector<pair<long long, long long> > v;   void dijkstra(long long src) {     set<pair<long long, long long> > ss;     pair<long long, long long> ras;     for (int i = 0; i < n; i++) {       dist[i] = 1e17;       vis[i] = 0;     }     dist[src] = 0;     ss.insert(make_pair(0, src));     while (!ss.empty()) {       ras = *(ss.begin());       ss.erase(ss.begin());       src = ras.second;       long long w = ras.first;       if (vis[src]) continue;       vis[src] = 1;       for (auto u : ad[src]) {         if (dist[u] > w + adj[src][u]) {           dist[u] = w + adj[src][u];           ss.insert(make_pair(dist[u], u));         }       }     }   }   int main() {     ios::sync_with_stdio(0);     cin >> n >> m >> L >> sr >> t;     for (int i = 0; i < m; i++) {       long long x, y, z;       cin >> x >> y >> z;       ad[x].push_back(y);       ad[y].push_back(x);       if (z > 0) {         adj[x][y] = adj[y][x] = z;       } else {         adj[x][y] = adj[y][x] = 1;         yes[x][y] = yes[y][x] = 1;         v.push_back(make_pair(x, y));       }     }     dijkstra(sr);     long long x = dist[t];     long long i = 0;     while (i < v.size() && x < L) {       long long y = L - x + 1;       adj[v[i].first][v[i].second] = adj[v[i].second][v[i].first] = y;       dijkstra(sr);       x = dist[t];       i++;     }     if (x != L) {       cout <<  NO ;       return 0;     } else {       cout <<  YES n ;       for (int i = 0; i < n; i++) {         for (int j = i + 1; j < n; j++) {           if (adj[i][j]) cout << i <<     << j <<     << adj[i][j] <<   n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T read(T& x) {     x = 0;     int f = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) f |= (ch ==  - ), ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x = f ? -x : x;   }   const int N = 3e5 + 10;   int n, i, j, len, ans = -1, a[N];   int main() {     read(n);     for (i = 1; i <= n; ++i) read(a[i]);     int mn = -1;     for (i = 1, j = n, len = n - 1; i <= j; ++i, --j, --len) {       if (mn == -1)         mn = min(a[i], a[j]);       else         mn = min(mn, min(a[i], a[j]));       int k = mn / len;       if (k < 0) continue;       if (ans == -1)         ans = k;       else         ans = min(ans, k);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   int CASE = 1;   const int mxn = 2e5 + 1;   const long long INF = 1e18;   bool prime(int n) {     if (n <= 1) return false;     if (n == 2 or n == 3) return true;     if (n % 2 == 0 or n % 3 == 0) return false;     for (int i = 5; i * i <= n; i += 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   long long __gcd(long long a, long long b) { return !b ? a : __gcd(b, a % b); }   void solve() {     string s;     cin >> s;     vector<string> v;     while (s.find( > ) != -1) {       string str = s.substr(0, s.find( > ) + 1);       s.erase(0, str.length());       v.push_back(str);     }     int cnt = 0;     map<char, vector<int> > mp;     for (string str : v) {       if (str.find( / ) != -1) {         for (long long i = 0; i < mp[str[str.length() - 2]].back(); i++)           cout <<    ;         cout << str << endl;         mp[str[str.length() - 2]].pop_back();         cnt -= 2;       } else {         mp[str[str.length() - 2]].push_back(cnt);         for (long long i = 0; i < cnt; i++) cout <<    ;         cout << str << endl;         cnt += 2;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int T = 1;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n;   long long power(long long base, long long expo) {     if (base <= 1) return 1;     long long ans = 1;     while (expo) {       if (expo & 1) {         ans = (ans * base) % n;       }       base = (base * base) % n;       expo >>= 1;     }     return ans;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     if (n == 4) {       cout <<  YES n1 n3 n2 n4 n ;       return 0;     }     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) {         cout <<  NO ;         return 0;       }     }     vector<long long> mark(n);     cout <<  YES n ;     for (long long i = 1; i <= n; i++) {       long long prnt = i * power(i - 1, n - 2) % n;       assert(!mark[prnt]);       mark[prnt] = 1;       if (!prnt) prnt += n;       cout << prnt << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k = 0;     string ans =   ;     cin >> n;     while (n > 1) {       ans +=  8 ;       k += 1;       n -= 2;     }     if (n == 1) {       ans +=  9 ;       k++;       n--;     }     if (k < 19)       cout << ans;     else       cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int a, b, c, m;     cin >> a >> b >> c >> m;     vector<long long int> usb;     vector<long long int> p;     for (long long int i = 0; i < m; i++) {       string s;       long long int x;       cin >> x >> s;       if (s ==  USB )         usb.push_back(x);       else         p.push_back(x);     }     sort(usb.begin(), usb.end());     sort(p.begin(), p.end());     long long int pos1 = 0, pos2 = 0, sum = 0, cnt = 0;     for (int i = 0; i < usb.size() && i < a; i++) {       sum += usb[i];       pos1 = i + 1;       cnt++;     }     for (int i = 0; i < p.size() && i < b; i++) {       sum += p[i];       pos2 = i + 1;       cnt++;     }     if (pos1 < usb.size() && pos2 < p.size()) {       long long int cnt2 = 0;       while (pos1 < usb.size() && pos2 < p.size() && cnt2 < c) {         if (usb[pos1] <= p[pos2]) {           sum += usb[pos1];           cnt++;           cnt2++;           pos1++;         } else {           sum += p[pos2];           cnt++;           cnt2++;           pos2++;         }       }       while (pos1 < usb.size() && cnt2 < c) {         sum += usb[pos1];         cnt++;         cnt2++;         pos1++;       }       while (pos2 < p.size() && cnt2 < c) {         sum += p[pos2];         cnt++;         cnt2++;         pos2++;       }     } else if (pos1 < usb.size()) {       long long int cnt2 = 0;       while (pos1 < usb.size() && cnt2 < c) {         sum += usb[pos1];         cnt++;         cnt2++;         pos1++;       }     } else if (pos2 < p.size()) {       long long int cnt2 = 0;       while (pos2 < p.size() && cnt2 < c) {         sum += p[pos2];         cnt++;         cnt2++;         pos2++;       }     }     cout << cnt <<     << sum;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, vector<long long> > M;   set<long long> S;   const long long N = 1000001;   long long n, a[1000001], f[N];   void upd(long long i, long long mx) {     for (; i > 0; i -= (i & -i)) {       f[i] = max(f[i], mx);     }   }   long long get(long long i) {     long long mx = -N;     for (; i < N; i += (i & -i)) mx = max(mx, f[i]);     return mx;   }   signed main() {     ios_base ::sync_with_stdio(false);     cin.tie(0);     cin >> n;     vector<long long> v;     for (long long i = 1; i <= n; ++i) {       cin >> a[i];       v.push_back(a[i]);     }     sort(v.begin(), v.end());     v.resize(unique(v.begin(), v.end()) - v.begin());     for (long long i = 1; i <= n; ++i) {       a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1;     }     for (long long i = 1; i <= n; ++i) {       if ((abs(get(a[i]) - i) - 1) % 2 != 0) {         cout <<  NO ;         return 0;       }       upd(a[i], i);     }     for (long long i = 0; i < N; ++i) f[i] = -(n + 1);     for (long long i = n; i >= 1; --i) {       if ((abs(abs(get(a[i])) - i) - 1) % 2 != 0) {         cout <<  NO ;         return 0;       }       upd(a[i], -i);     }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   constexpr int Maxn = 53;   std::vector<int> e[Maxn];   int n, m;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1, u, v; i <= m; ++i) {       scanf( %d%d , &u, &v);       if (u <= 50 && v <= 50) {         e[u].emplace_back(v);         e[v].emplace_back(u);       }     }     n = std::min(n, 50);     for (int i = 1; i <= n; ++i) std::sort(e[i].begin(), e[i].end());     for (int i = 1; i <= n; ++i)       for (int j = 1; j < i; ++j)         for (int k = 1; k < j; ++k)           for (int l = 1; l < k; ++l)             for (int r = 1; r < l; ++r) {               std::vector<int> vec = {i, j, k, l, r};               int cnt = 0;               for (int x : {0, 1, 2, 3, 4})                 for (int y = 0; y < x; ++y) {                   auto iter = std::lower_bound(e[vec[x]].begin(), e[vec[x]].end(),                                                vec[y]);                   if (iter == e[vec[x]].end() || *iter != vec[y]) ++cnt;                 }               if (cnt == 0 || cnt == 10) {                 printf( %d %d %d %d %d n , i, j, k, l, r);                 return 0;               }             }     puts( -1 );   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int f = 0, num;     char ch;     while (ch = getchar(), !isdigit(ch))       if (ch ==  - ) f = 1;     num = ch -  0 ;     while (ch = getchar(), isdigit(ch)) num = num * 10 + ch -  0 ;     return f ? -num : num;   }   const int N = 103;   char s[N], ans[N], tmp[103];   char ch;   void is() {     ch = getchar();     while (ch !=   n ) ch = getchar();   }   int cnt, tot, T, f;   int main() {     T = read();     f = 0, cnt = 0;     while (T--) {       int f1 = 0;       tot = 0;       ch = getchar();       while (ch !=   n ) {         if (ch ==    ) f1 = 1;         if (f1)           s[tot++] = ch;         else if (ch !=    )           s[tot++] = ch;         ch = getchar();       }       s[tot++] =   0 ;       if (f) {         if (s[1] ==  r ) cnt++;         if (s[0] ==  c ) {           if (cnt)             cnt--;           else {             tot = 0;             int i = 6;             while (s[i] !=  , ) {               tmp[tot++] = s[i];               i++;             }             tmp[tot++] =   0 ;             if (!strcmp(tmp, ans)) {               int i = 7 + tot;               while (s[i] !=    ) {                 cout << s[i];                 i++;               }               cout << endl;               f = 0;             }           }         }       }       if (s[1] ==  h ) {         f = 1;         tot = 0;         for (int i = 6; s[i] !=  ) ; i++) ans[tot++] = s[i];         ans[tot++] =   0 ;       }     }     if (f) cout <<  Unhandled Exception  << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int cnt[30000];   int main() {     int n;     cin >> n;     cnt[0] = 1;     for (long long i = 0; i < n; ++i) {       int a;       cin >> a;       for (long long q = 0; q < 30000 - a; ++q) {         if (cnt[q] == 1) {           cnt[q + a] = 1;         }       }     }     for (int i = 0; i < 30000; ++i) {       if (cnt[i] == 0) {         cout << i << endl;         return 0;       }     }     cout << -1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   bool rev[35];   int main() {     int n, m;     cin >> m >> n;     for (int i = 0; i < n; i++) {       printf( 1 n );       fflush(stdout);       int x;       scanf( %d , &x);       if (x == 0) return 0;       if (x < 0)         rev[i] = true;       else         rev[i] = false;     }     int l = 1, r = m;     for (int i = n; i < 60; i++) {       int mid = (l + r) / 2;       printf( %d n , mid);       fflush(stdout);       int x;       scanf( %d , &x);       if (x == 0) return 0;       if (x < 0) {         if (rev[i % n]) {           l = mid + 1;         } else           r = mid - 1;       } else {         if (rev[i % n]) {           r = mid - 1;         } else           l = mid + 1;       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &x) {     x = 0;     char c = getchar();     bool flag = false;     while (!isdigit(c)) {       if (c ==  - ) flag = true;       c = getchar();     }     while (isdigit(c)) {       x = (x << 1) + (x << 3) + (c ^ 48);       c = getchar();     }     if (flag) x = -x;   }   int n, q, root = 1;   int a[1000010], mn[4000010], val[4000010], tag[4000010];   void pushup(int cur) {     if (mn[(cur << 1)] < mn[(cur << 1 | 1)])       mn[cur] = mn[(cur << 1)], val[cur] = val[(cur << 1)];     else if (mn[(cur << 1)] > mn[(cur << 1 | 1)])       mn[cur] = mn[(cur << 1 | 1)], val[cur] = val[(cur << 1 | 1)];     else       mn[cur] = mn[(cur << 1)], val[cur] = val[(cur << 1)] + val[(cur << 1 | 1)];   }   void pushtag(int cur, int v) { mn[cur] += v, tag[cur] += v; }   void pushdown(int cur) {     if (!tag[cur]) return;     pushtag((cur << 1), tag[cur]), pushtag((cur << 1 | 1), tag[cur]),         tag[cur] = 0;   }   void update(int l, int r, int pos, int v, int cur) {     if (l == r) {       val[cur] += v;       return;     }     pushdown(cur);     if (pos <= ((l + r) >> 1))       update(l, ((l + r) >> 1), pos, v, (cur << 1));     else       update(((l + r) >> 1) + 1, r, pos, v, (cur << 1 | 1));     pushup(cur);   }   void modify(int L, int R, int l, int r, int v, int cur) {     if (L > R) return;     if (L <= l && R >= r) {       pushtag(cur, v);       return;     }     pushdown(cur);     if (L <= ((l + r) >> 1)) modify(L, R, l, ((l + r) >> 1), v, (cur << 1));     if (R > ((l + r) >> 1))       modify(L, R, ((l + r) >> 1) + 1, r, v, (cur << 1 | 1));     pushup(cur);   }   int query(int L, int R, int l, int r, int cur) {     if (L <= l && R >= r) return mn[cur] == 1 ? val[cur] : 0;     int v = 0;     pushdown(cur);     if (L <= ((l + r) >> 1)) v += query(L, R, l, ((l + r) >> 1), (cur << 1));     if (R > ((l + r) >> 1))       v += query(L, R, ((l + r) >> 1) + 1, r, (cur << 1 | 1));     return v;   }   int main() {     read(n), read(q), a[0] = 1000001;     for (int i = 1; i <= n; ++i) read(a[i]), update(0, 1000001, a[i], 1, root);     for (int i = 0; i <= n; ++i)       modify(min(a[i], a[i + 1]), max(a[i], a[i + 1]) - 1, 0, 1000001, 1, root);     while (q--) {       int x;       read(x), update(0, 1000001, a[x], -1, root);       modify(min(a[x], a[x + 1]), max(a[x], a[x + 1]) - 1, 0, 1000001, -1, root);       modify(min(a[x - 1], a[x]), max(a[x - 1], a[x]) - 1, 0, 1000001, -1, root);       read(a[x]), update(0, 1000001, a[x], 1, root);       modify(min(a[x], a[x + 1]), max(a[x], a[x + 1]) - 1, 0, 1000001, 1, root);       modify(min(a[x - 1], a[x]), max(a[x - 1], a[x]) - 1, 0, 1000001, 1, root);       printf( %d n , query(1, 1000001 - 1, 0, 1000001, root));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   const long long mod = 1e9 + 7;   void __p(long long x) { cout << x; }   void __p(int32_t x) { cout << x; }   void __p(float x) { cout << x; }   void __p(double x) { cout << x; }   void __p(long double x) { cout << x; }   void __p(char x) { cout <<      << x <<     ; }   void __p(const char *x) { cout <<     << x <<    ; }   void __p(const string &x) { cout <<     << x <<    ; }   void __p(bool x) { cout << (x ?  true  :  false ); }   void _p() { cout <<  ] n ; }   template <typename T, typename V>   void __p(const pair<T, V> &x) {     cout <<  { ;     __p(x.first);     cout <<  , ;     __p(x.second);     cout <<  } ;   }   template <typename T>   void __p(const T &x) {     long long f = 0;     cout <<  { ;     for (auto &i : x) cout << (f++ ?  ,  :   ), __p(i);     cout <<  } ;   }   template <typename T, typename... V>   void _p(T t, V... v) {     __p(t);     if (sizeof...(v)) cout <<  ,  ;     _p(v...);   }   long long po(long long x, long long p) {     long long ans = 1;     x %= mod;     while (p > 0) {       if (p & 1) ans = (ans * x) % mod;       p = p >> 1;       x = (x * x) % mod;     }     return ans;   }   long long inv(long long x) { return po(x, mod - 2) % mod; }   const long long N = 1e6 + 6;   long long n, m, k, x, y, z, a, b, c, d, i, j, l, r, f, q;   void sol() {     string s;     cin >> n >> s;     map<long long, long long> m;     m[0] = 1;     long long pre = 0;     long long ans = 0;     for (i = 0; i < n; i++) {       pre += s[i] -  0 ;       ans += m[pre - (i + 1)];       m[pre - (i + 1)]++;     }     cout << ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) sol();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     char c = getchar();     int x = 0;     bool f = 0;     for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);     for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);     if (f) x = -x;     return x;   }   const int M = 4e6 + 10;   int n, maxn, pp[M], a[M], b[M], cnt, ppp[M];   int max1, max2, sum1, sum2, vis[M];   map<int, int> t;   vector<int> e[M];   void dfs(int u) {     if (vis[u]) return;     vis[u] = 1, sum2++;     max2 = max(max2, u);     if (max1 < max2) swap(max1, max2);     for (int i = 0; i < e[u].size(); i++) {       int to = e[u][i];       sum1++;       dfs(to);     }   }   signed main() {     n = read();     for (int i = 1; i <= n; i++)       pp[++cnt] = a[i] = read(), pp[++cnt] = b[i] = read();     sort(pp + 1, pp + 1 + cnt);     cnt = 0;     for (int i = 1; i <= 2 * n; i++)       if (pp[i] != pp[i - 1] || i == 1) t[pp[i]] = ++cnt, ppp[cnt] = pp[i];     for (int i = 1; i <= n; i++)       a[i] = t[a[i]], b[i] = t[b[i]], e[a[i]].push_back(b[i]),       e[b[i]].push_back(a[i]);     for (int i = 1; i <= cnt; i++)       if (!vis[i]) {         max1 = max2 = sum1 = sum2 = 0;         dfs(i);         sum1 /= 2;         if (sum2 == sum1)           maxn = max(maxn, max1);         else if (sum2 > sum1)           maxn = max(maxn, max2);         else           return puts( -1 ), 0;       }     cout << ppp[maxn] << endl;     return 0;   }


#include <bits/stdc++.h>   char s[100] =  bear , str[10000];   int check(int index) {     int i;     for (i = index; i <= index + 3; i++) {       if (str[i] != s[i - index]) return 0;     }     return 1;   }   int main() {     int len, i, j;     while (scanf( %s , str) != EOF) {       int ans = 0, index = 0;       int len = strlen(str);       for (i = 0; i <= len - 4; i++) {         if (check(i)) ans += (i + 1 - index) * (len - (i + 3)), index = i + 1;       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct p {     int L, R, U, D;   } point[5005], pos[5005];   string g[5005];   void DEL(int x) {     pos[pos[x].D].U = pos[x].U;     pos[pos[x].U].D = pos[x].D;     pos[pos[x].R].L = pos[x].L;     pos[pos[x].L].R = pos[x].R;   }   int main() {     int m, n, i, j, l, sx, sy;     scanf( %d%d , &m, &n);     for (i = 0; i < m; i++) cin >> g[i];     n = g[0].size();     for (i = 0; i < m; i++) {       for (j = 0; j < n; j++) {         if (g[i][j] !=  . ) {           for (l = i - 1; l >= 0; l--)             if (g[l][j] !=  . ) break;           if (l < 0)             point[i * n + j].U = -1;           else             point[i * n + j].U = l * n + j;           for (l = i + 1; l < m; l++)             if (g[l][j] !=  . ) break;           if (l >= m)             point[i * n + j].D = -1;           else             point[i * n + j].D = l * n + j;           for (l = j - 1; l >= 0; l--)             if (g[i][l] !=  . ) break;           if (l < 0)             point[i * n + j].L = -1;           else             point[i * n + j].L = i * n + l;           for (l = j + 1; l < n; l++)             if (g[i][l] !=  . ) break;           if (l >= n)             point[i * n + j].R = -1;           else             point[i * n + j].R = i * n + l;         }       }     }     int r1 = 0, r2 = 0, cnt, t, x, y;     for (sx = 0; sx < m; sx++) {       for (sy = 0; sy < n; sy++)         if (g[sx][sy] !=  . ) {           for (i = 0; i < m; i++) {             for (j = 0; j < n; j++) {               pos[i * n + j] = point[i * n + j];             }           }           if (g[sx][sy] ==  D )             t = pos[sx * n + sy].D;           else if (g[sx][sy] ==  U )             t = pos[sx * n + sy].U;           else if (g[sx][sy] ==  R )             t = pos[sx * n + sy].R;           else if (g[sx][sy] ==  L )             t = pos[sx * n + sy].L;           DEL(sx * n + sy);           cnt = 1;           while (t != -1) {             cnt++;             x = t / n;             y = t % n;             DEL(t);             if (g[x][y] ==  D )               t = pos[t].D;             else if (g[x][y] ==  U )               t = pos[t].U;             else if (g[x][y] ==  R )               t = pos[t].R;             else if (g[x][y] ==  L )               t = pos[t].L;           }           if (cnt > r1) {             r1 = cnt;             r2 = 1;           } else if (cnt == r1) {             r2++;           }         }     }     printf( %d %d n , r1, r2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e3 + 40;   int f[maxn][maxn];   int dp[maxn];   char s[maxn];   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n;       scanf( %d , &n);       scanf( %s , s + 1);       f[n][n + 1] = f[n + 1][n] = f[n + 1][n + 1] = 0;       for (int i = n; i >= 1; i--)         for (int j = n; j >= 1; j--) {           if (s[i] == s[j]) {             f[i][j] = f[i + 1][j + 1] + 1;           } else {             f[i][j] = 0;           }         }       int ans = 0;       for (int i = 1; i <= n; i++) {         dp[i] = n - i + 1;         for (int j = 1; j < i; j++) {           int len = f[i][j];           if (i + len - 1 >= n || s[i + len] <= s[j + len]) continue;           dp[i] = max(dp[i], dp[j] + n - i + 1 - len);         }         ans = max(ans, dp[i]);       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> primes;   bool sums[1003];   int n, k;   bool pr[1003];   void sieve() {     pr[1] = pr[0] = 1;     for (int i = 2; i <= n; i++)       if (!pr[i]) {         for (int j = i + i; j <= n; j += i) pr[j] = 1;         primes.push_back(i);       }     return;   }   int main() {     cin >> n >> k;     sieve();     for (int i = 1; i < primes.size(); i++)       if (primes[i] + primes[i - 1] <= n) sums[primes[i] + primes[i - 1]] = 1;     for (int i = 2; i <= n; ++i)       if (sums[i - 1] && !pr[i]) k--;     cout << (k <= 0 ?  YES  :  NO );   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> v(100003);   long long solve() {     long long n;     vector<long long> u;     string s;     cin >> n;     while (n > 0) {       auto itr = lower_bound((v).begin(), (v).end(), n);       long long a = itr - v.begin();       if (v[a] > n) a--;       u.push_back(a + 2);       n = n - v[a];     }     s.push_back( 1 );     long long j = 1;     for (long long i = 0; i < u[0]; i++) {       while (j < u.size() && i + u[j] == u[0]) {         s.push_back( 1 );         j++;       }       s.push_back( 3 );     }     s.push_back( 7 );     cout << s;     return 0;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long t = 1;     cin >> t;     v[0] = 1;     for (long long i = 1; i < 100003; i++) v[i] = v[i - 1] + i + 1;     while (t--) {       solve();       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 101010;   pair<int, int> arr[MAXN];   pair<int, int> a[MAXN], b[MAXN];   int N;   bool cmp(const pair<int, int> &a, const pair<int, int> &b) {     return a.second < b.second;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> N;     for (int i = 0; i < N; i++) {       cin >> arr[i].first;       arr[i].second = i;     }     sort(arr, arr + N);     int c3 = (N + 1) / 3;     int c6 = (2 * N + 1) / 3;     for (int i = 0; i < c3; i++) {       a[i].first = arr[i].first;       b[i].first = 0;     }     for (int i = c3; i < c6; i++) {       a[i].first = 0;       b[i].first = arr[i].first;     }     for (int i = c6; i < N; i++) {       b[i].first = N - i - 1;       a[i].first = arr[i].first - b[i].first;     }     for (int i = 0; i < N; i++) {       a[i].second = b[i].second = arr[i].second;     }     sort(a, a + N, cmp);     sort(b, b + N, cmp);     cout <<  YES  << endl;     for (int i = 0; i < N; i++) cout << a[i].first << (i == N - 1 ?   n  :    );     for (int i = 0; i < N; i++) cout << b[i].first << (i == N - 1 ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const double eps = 1e-9;   const int INF = inf;   const double EPS = eps;   struct __timestamper {};   class fenv_tree {     static int f(int x) { return x & -x; }     vector<int> tr;       public:     fenv_tree(int n) : tr(n + 1, -inf) {}     void relax(int x, int v) {       for (x++; x < ((int)(tr).size()); x += f(x)) tr[x] = max(tr[x], v);     }     int get(int x) {       int res = -inf;       for (x++; x > 0; x -= f(x)) res = max(res, tr[x]);       return res;     }   };   vector<vector<pair<int, int>>> rests;   int n;   vector<int> rig, spl;   vector<int> ans;   void restore(int v) {     if (v + 1 < spl[v]) {       rig[v + 1] = spl[v] - 1;       restore(v + 1);     }     ans.push_back(v);     if (spl[v] <= rig[v]) {       rig[spl[v]] = rig[v];       restore(spl[v]);     }   }   bool check() {     rig = vector<int>(n);     for (int i = 0; i < (n); i++) rig[i] = i;     spl = vector<int>(n);     fenv_tree tr(n);     for (int i = 0; i < (n); i++) tr.relax(i, rig[i]);     for (int i = n - 1; i >= 0; i--) {       for (pair<int, int> r : rests[i]) {         if (r.first <= i) return false;         rig[i] = max(rig[i], rig[r.first]);       }       rig[i] = tr.get(rig[i]);       tr.relax(i, rig[i]);       vector<pair<int, int>> seq;       for (int i2 = i + 1; i2 <= rig[i];) {         seq.push_back(make_pair(i2, rig[i2]));         i2 = rig[i2] + 1;       }       int b1 = 0, b2 = ((int)(seq).size());       for (pair<int, int> r : rests[i]) {         int id = upper_bound(seq.begin(), seq.end(), make_pair(r.first, inf)) -                  seq.begin() - 1;         if (r.second == 0) {           b1 = max(b1, id + 1);         } else {           b2 = min(b2, id);         }       }       if (b1 > b2) return false;       if (seq.empty()) {         spl[i] = i + 1;       } else {         spl[i] = b1 == ((int)(seq).size()) ? rig[i] + 1 : seq[b1].first;       }     }     ans.clear();     rig[0] = n - 1;     restore(0);     for (int i = 0; i < (n); i++) printf( %d%c , ans[i] + 1,   n  [i + 1 < n]);     return true;   }   int main() {     int m;     while (scanf( %d%d , &n, &m) == 2) {       rests = vector<vector<pair<int, int>>>(n);       for (int i = 0; i < (m); i++) {         int a, b;         char ty[10];         scanf( %d%d%s , &a, &b, ty), a--, b--;         rests[a].push_back(make_pair(b, !strcmp(ty,  LEFT ) ? 0 : 1));       }       if (!check()) {         printf( IMPOSSIBLE n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       for (int pw = 2; pw < 30; ++pw) {         int val = (1 << pw) - 1;         if (n % val == 0) {           cout << n / val << endl;           break;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = int(1.5 * 1e7);   const int inf = 1e9 + 7;   const long long ll_inf = 1e18 + 420;   const double eps = 1e-4;   const int N = 1e6;   const int MAX = 2e5 + 9;   const int MOD = 1e9 + 7;   const long double pi = 3.14159265359;   string s;   bool was[10][10];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> s;     for (int i0 = 0; i0 < s.size(); ++i0) {       int cnt = 0;       for (int i = 1; i <= 4; ++i, cnt = 0) {         for (int j = 1; j <= 4; ++j) {           cnt += was[i][j];         }         if (cnt == 4) {           for (int j = 1; j <= 4; ++j) {             was[i][j] = 0;           }         }       }       for (int i = 1; i <= 4; ++i, cnt = 0) {         for (int j = 1; j <= 4; ++j) {           cnt += was[j][i];         }         if (cnt == 4) {           for (int j = 1; j <= 4; ++j) {             was[j][i] = 0;           }         }       }       if (s[i0] ==  1 ) {         bool q = 0;         for (int i = 1; i <= 4; ++i) {           for (int j = 1; j <= 3; ++j) {             if (!was[i][j] && !was[i][j + 1]) {               was[i][j] = 1;               was[i][j + 1] = 1;               cout << i <<     << j <<   n ;               q = 1;               break;             }           }           if (q) break;         }       } else {         bool q = 0;         for (int i = 1; i <= 4; ++i) {           for (int j = 1; j <= 3; ++j) {             if (!was[j][i] && !was[j + 1][i]) {               was[j][i] = 1;               was[j + 1][i] = 1;               cout << j <<     << i <<   n ;               q = 1;               break;             }           }           if (q) break;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int T;     cin >> T;     while (T--) {       long long n, m;       cin >> n >> m;       if (m + 1 <= n) {         cout << 0 << endl;         continue;       }       m++;       bool flag = false;       for (int i = 32; i >= 0; --i) {         int x = n >> i & 1, y = m >> i & 1;         if (flag) {           m -= y << i;           m += x << i;         } else if (x > y) {           flag = 1;           m += (1 << i);         }       }       cout << (n ^ m) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   int n;   int a[maxn];   int c[maxn];   int main() {     int ans = 0;     int i, j, x;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     int id = 0;     for (i = 2; i <= n; i++) {       if (a[i] < a[i - 1]) id = i - 1;     }     printf( %d n , id);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 10;   const int MAXN = 1e4 + 10;   const int MOD = 1e9 + 7;   const int inf = 1e9;   const double pi = acos(-1.0);   const double eps = 1e-6;   int dx[] = {0, -1, 0, 1};   int dy[] = {1, 0, -1, 0};   long long dp[510][510];   int n;   int a[510];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) dp[i][i] = 1;     for (int j = 2; j <= n; j++)       for (int i = j - 1; i >= 1; i--) {         dp[i][j] = 0;         for (int k = i + 1; k <= j; k++)           if (a[i + 1] < a[k + 1] || k == j)             (dp[i][j] += (dp[i + 1][k] * dp[k][j]) % MOD) %= MOD;       }     cout << dp[1][n];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = (long long)1e18 + 7;   int n, m;   map<char, int> ch_num;   int main() {     int n;     cin >> n;     vector<string> ee(n);     for (int i = 0; i < n; i++) {       cin >> ee[i];     }     vector<int> can_zero(27, -1);     vector<pair<int, int> > let_sum(27);     for (int i = 0; i < 26; i++) {       let_sum[i] = make_pair(0, i);     }     for (auto cp : ee) {       for (int i = 0; i < (int)cp.size(); i++) {         if (i == 0) {           can_zero[cp[i] -  a ] = 0;         } else if (can_zero[cp[i] -  a ] != 0) {           can_zero[cp[i] -  a ] = 1;         }         let_sum[cp[i] -  a ].first += pow(10, (int)cp.size() - i - 1);       }     }     sort(let_sum.begin(), let_sum.end());     reverse(let_sum.begin(), let_sum.end());     bool z_used = false;     int cur_n = 1;     for (auto cp : let_sum) {       if (can_zero[cp.second] == -1) {         break;       }       if (can_zero[cp.second] && !z_used) {         ch_num[(char)( a  + cp.second)] = 0;         z_used = true;       } else {         ch_num[(char)( a  + cp.second)] = cur_n;         cur_n++;       }     }     int ans = 0;     for (auto hui : ee) {       for (int i = 0; i < (int)hui.size(); i++) {         ans += ch_num[hui[i]] * pow(10, (int)hui.size() - i - 1);       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     getline(cin, s);     int k = s.length();     int flag = 0;     for (int d = 0; d < k - 1; d++) {       if (s[d] ==    ) {         continue;       }       if (s[d] ==  a  || s[d] ==  e  || s[d] ==  i  || s[d] ==  o  ||           s[d] ==  u  || s[d] ==  y  || s[d] ==  A  || s[d] ==  E  ||           s[d] ==  I  || s[d] ==  O  || s[d] ==  U  || s[d] ==  Y ) {         flag = 1;       } else {         flag = 0;       }     }     if (flag == 1) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     long int l, r;     scanf( %ld %ld , &l, &r);     if (l == r)       printf( %ld n , r);     else       printf( 2 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1000000000000000;   int main() {     int n, m;     cin >> n >> m;     vector<int> x(n);     for (int i = 0; i < n; i++) {       cin >> x[i];     }     vector<int> p(m), c(m);     for (int i = 0; i < m; i++) {       cin >> p[i] >> c[i];     }     sort(x.begin(), x.end());     vector<pair<int, int>> P(m);     for (int i = 0; i < m; i++) {       P[i] = make_pair(p[i], c[i]);     }     sort(P.begin(), P.end());     for (int i = 0; i < m; i++) {       p[i] = P[i].first;       c[i] = P[i].second;     }     int sum = 0;     for (int i = 0; i < m; i++) {       sum += c[i];     }     if (sum < n) {       cout << -1 << endl;     } else {       vector<long long> dp(n + 1, INF);       dp[0] = 0;       for (int i = 0; i < m; i++) {         vector<long long> d(n);         for (int j = 0; j < n; j++) {           d[j] = abs(x[j] - p[i]);         }         vector<long long> S(n + 1);         S[0] = 0;         for (int j = 0; j < n; j++) {           S[j + 1] = S[j] + d[j];         }         vector<long long> a(n + 1);         for (int j = 0; j <= n; j++) {           a[j] = dp[j] - S[j];         }         deque<int> dq;         for (int j = 0; j <= n; j++) {           while (!dq.empty()) {             if (a[dq.back()] >= a[j]) {               dq.pop_back();             } else {               break;             }           }           dq.push_back(j);           dp[j] = a[dq.front()] + S[j];           if (dq.front() == j - c[i]) {             dq.pop_front();           }         }       }       cout << dp[n] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   vector<int> g[N];   int a[N], b[N], last[N], indx[N], lvl[N], ans[N];   int n, m, q;   void dfs(int node, int sz) {     lvl[sz++] = node;     for (int i = 0; i < g[node].size(); i++) {       dfs(g[node][i], sz);     }     if (sz >= n)       ans[node] = lvl[sz - n];     else       ans[node] = N;     sz--;   }   int tree[N << 2];   void build(int i, int l, int r) {     if (l == r) return void(tree[i] = ans[l]);     int mid = (l + r) >> 1;     build(i << 1, l, mid);     build(i << 1 | 1, mid + 1, r);     tree[i] = min(tree[i << 1], tree[i << 1 | 1]);   }   int get(int i, int l, int r, int a, int b) {     if (l > b || r < a) return N;     if (l >= a && r <= b) return tree[i];     int mid = (l + r) >> 1;     return min(get(i << 1, l, mid, a, b), get(i << 1 | 1, mid + 1, r, a, b));   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> q;     for (int i = 0; i < n; i++) cin >> a[i], indx[a[i]] = i;     for (int i = 0; i < m; i++) cin >> b[i];     memset(last, -1, sizeof last);     vector<int> roots;     for (int i = m - 1; i >= 0; i--) {       int x = a[(indx[b[i]] + 1) % n];       if (last[x] == -1)         roots.push_back(i);       else         g[last[x]].push_back(i);       last[b[i]] = i;     }     for (auto r : roots) dfs(r, 0);     build(1, 0, m - 1);     for (int i = 0, l, r; i < q; i++) {       cin >> l >> r;       l--, r--;       cout << (get(1, 0, m - 1, l, r) <= r);     }     return 0;   }


//   //  main.cpp   //  google-code-jam-2020   //   //  Created by Ali Naderi Parizi on 2/10/1400 AP.   //      #include <iostream>   #include <math.h>      int main(int argc, const char * argv[])   {       int t;       std::cin >> t;       for (int i = 0 ; i < t ; i++)       {           double r,b,d;           std::cin >> r >> b >> d;           double x = std::min(r, b) * d;              if(std::abs(r - b) <= x)           {               std::cout <<  YES  << std::endl;           }           else           {               std::cout <<  NO  << std::endl;           }       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int q = 1;     while (q--) {       long long int n, i, t, j, k = 0, maxm = 0, ans;       cin >> n;       vector<long long int> v(n), v1(30), v2;       map<long long int, long long int> m;       for (long long int i = 0; i < 30; i++) v1[i] = 0;       for (long long int i = 0; i < n; i++) {         cin >> v[i];         t = v[i];         j = 0;         while (t > 0) {           v1[j] = v1[j] + t % 2;           t = t / 2;           j++;         }       }       sort(v.begin(), v.end());       for (long long int i = 0; i < 30; i++) {         if (v1[i] == 1) v2.push_back(i);       }       if (v2.size() == 0) {         for (i = n - 1; i >= 0; i--) cout << v[i] <<    ;         return 0;       }       for (long long int i = 0; i < n; i++) {         t = v[i];         j = 0;         k = 0;         while (t > 0) {           if (j == v2[k]) {             if (t % 2 != 0) m[v[i]] += pow(2, j);             k++;           }           t = t / 2;           j++;         }       }       for (auto it = m.begin(); it != m.end(); it++) {         if ((it->second) > maxm) {           maxm = it->second;           ans = it->first;         }       }       cout << ans <<    ;       for (long long int i = 0; i < n; i++) {         if (v[i] == ans)           continue;         else           cout << v[i] <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000003;   long double pi = 3.1415926536;   const int mx = 1000003;   long long gcd(long long x, long long y) {     if (y == 0) return x;     return gcd(y, x % y);   }   long long bp(long long a, long long b) {     long long ans = 1;     while (b > 0) {       if (b & 1) ans = (ans * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return ans;   }   long long p(long long n) {     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) {         return n / i;       }     }     return 1;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, k;     cin >> n >> k;     long long a[n + 1], ans = 0;     for (long long i = 1; i <= n; i++) cin >> a[i];     while (1) {       bool t = 0;       for (long long i = n; i >= 1;) {         if (a[i] < k) {           long long x = a[i], j = i;           while (x == a[i] && i >= 1) {             x = a[i];             i--;           }           a[j]++;           t = 1;         } else {           i--;         }       }       if (t) ans++;       if (a[1] >= k) break;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a - (a / b * b));   }   long long mypow(long long a, long long b) {     long long p = 1;     if (b == 0) return 1;     for (long long i = 0; i < b; i++) p *= a;     return p;   }   long long zero(long long a) {     long long za = 0;     long long temp = a;     long long tens = 0;     while (temp > 0) {       if (temp % 10 != 0) {         za += ((temp % 10) * (mypow(10, tens)));         tens++;       }       temp /= 10;     }     return za;   }   int main() {     string st;     while (getline(cin, st)) {       int i = st.length() - 2;       while (st[i] ==    ) i--;       if (st[i] < 97) st[i] += 32;       if (st[i] ==  a  || st[i] ==  e  || st[i] ==  i  || st[i] ==  o  ||           st[i] ==  u  || st[i] ==  y )         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (1 << 30) - 1;   const long long linf = (1ll << 62) - 1;   const int N = 1e6 + 100;   int n, m;   int u[N], v[N];   set<int> g[N];   bool used[N];   int ts[N], tsLen = 0;   void topSort(int v) {     if (used[v]) {       return;     }     used[v] = true;     for (int to : g[v]) {       topSort(to);     }     ts[tsLen++] = v;   }   inline bool check(int m) {     for (int i = 0; i < n; i++) {       g[i].clear();     }     for (int i = 0; i < m; i++) {       g[u[i]].insert(v[i]);     }     fill_n(used, n, false);     tsLen = 0;     for (int i = 0; i < n; i++) {       if (!used[i]) {         topSort(i);       }     }     reverse(ts, ts + tsLen);     for (int i = 0; i < tsLen - 1; i++) {       if (g[ts[i]].count(ts[i + 1]) == 0) {         return false;       }     }     return true;   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       scanf( %d%d , &u[i], &v[i]);       u[i]--, v[i]--;     }     int l = 0, r = m;     while (r - l > 1) {       int x = (l + r) / 2;       if (check(x)) {         r = x;       } else {         l = x;       }     }     if (!check(r)) {       puts( -1 );     } else {       printf( %d n , r);     }     return 0;   }