#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   const int dx[4] = {1, -1, 0, 0};   const int dy[4] = {0, 0, 1, -1};   int read() {     int s = 0;     char c = getchar(), lc =  + ;     while (c <  0  ||  9  < c) lc = c, c = getchar();     while ( 0  <= c && c <=  9 ) s = s * 10 + c -  0 , c = getchar();     return lc ==  -  ? -s : s;   }   void write(int x) {     if (x < 0) putchar( - ), x = -x;     if (x < 10)       putchar(x +  0 );     else       write(x / 10), putchar(x % 10 +  0 );   }   void print(int x, char c =   n ) {     write(x);     putchar(c);   }   void error() { puts( -1 ), exit(0); }   pair<int, int> q[N];   int dis[N], tot[N], tt, a[N];   int id(int n, int m, int x, int y) { return (x - 1) * m + y; }   void check(int n, int m, int x, int y) {     if (x > n || y > m) return;     for (int i = 1; i <= tt; i++) dis[i] = -1, tot[i] = 0;     dis[id(n, m, x, y)] = 0;     int h = 1, t = 1;     q[1] = make_pair(x, y);     while (h <= t) {       int x = q[h].first, y = q[h++].second;       for (int i = 0; i < 4; i++)         if (1 <= x + dx[i] && x + dx[i] <= n)           if (1 <= y + dy[i] && y + dy[i] <= m)             if (!~dis[id(n, m, x + dx[i], y + dy[i])]) {               dis[id(n, m, x + dx[i], y + dy[i])] = dis[id(n, m, x, y)] + 1;               q[++t] = make_pair(x + dx[i], y + dy[i]);             }     }     for (int i = 1; i <= tt; i++) tot[dis[i]]++;     for (int i = 1; i <= tt; i++)       if (tot[i] != a[i]) return;     print(n,    ), print(m);     print(x,    ), print(y);     exit(0);   }   signed main(signed Recall, char *_902_[]) {     (void)Recall, (void)_902_;     tt = read();     for (int i = 1; i <= tt; i++) a[read()]++;     int x = 0, mx = 0;     for (int i = 0; i <= tt; i++)       if (a[i]) mx = i;     for (int i = 0; i <= tt; i++) {       if (a[i] > i * 4 + !i) error();       if (a[i] < i * 4 + !i) {         x = i;         break;       }     }     if (x == 0) error();     for (int i = 1; i <= tt; i++)       if (tt % i == 0) check(i, tt / i, x, i + tt / i - x - mx);     puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 212345, MAXL = 20, INF = 1123456789;   vector<int> grafo[MAXN], peso[MAXN];   int dp[MAXN][MAXL], mx[MAXN][MAXL], dist[MAXN], prof[MAXN];   long long int pmst;   pair<int, pair<int, int> > ar[MAXN];   int lca(int a, int b) {     int resp = 0;     if (prof[a] < prof[b]) swap(a, b);     int d = prof[a] - prof[b];     for (int i = MAXL - 1; i >= 0; i--) {       if (d & (1 << i)) {         resp = max(resp, mx[a][i]);         a = dp[a][i];       }     }     if (a == b) return resp;     for (int i = MAXL - 1; i >= 0; i--) {       if (dp[a][i] != dp[b][i]) {         resp = max(resp, max(mx[a][i], mx[b][i]));         a = dp[a][i];         b = dp[b][i];       }     }     resp = max(resp, max(mx[a][0], mx[b][0]));     return resp;   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       int a, b, p;       scanf( %d %d %d , &a, &b, &p);       a--;       b--;       grafo[a].push_back(b);       grafo[b].push_back(a);       peso[a].push_back(p);       peso[b].push_back(p);       ar[i] = make_pair(p, make_pair(a, b));     }     set<pair<int, int> > s;     dist[0] = 0;     s.insert(make_pair(0, 0));     for (int i = 1; i < n; i++) {       dist[i] = INF;       s.insert(make_pair(INF, i));     }     dp[0][0] = 0;     prof[0] = 0;     while (!s.empty()) {       int cur = (*s.begin()).second;       s.erase(s.begin());       pmst += dist[cur];       dist[cur] = 0;       for (int i = 0; i < grafo[cur].size(); i++) {         int viz = grafo[cur][i], p = peso[cur][i];         if (dist[viz] > p) {           s.erase(make_pair(dist[viz], viz));           dist[viz] = p;           s.insert(make_pair(dist[viz], viz));           dp[viz][0] = cur;           mx[viz][0] = p;           prof[viz] = prof[cur] + 1;         }       }     }     for (int j = 1; j < MAXL; j++) {       for (int i = 0; i < n; i++) {         dp[i][j] = dp[dp[i][j - 1]][j - 1];         mx[i][j] = max(mx[i][j - 1], mx[dp[i][j - 1]][j - 1]);       }     }     for (int i = 0; i < m; i++) {       printf( %lld n ,              pmst - lca(ar[i].second.first, ar[i].second.second) + ar[i].first);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int tree[500005 << 2];   struct P {     int x, y, z;     int id;   } p[500005];   bool cmp1(P a, P b) {     if (a.x != b.x)       return a.x > b.x;     else if (a.y != b.y)       return a.y > b.y;     else       return a.z > b.z;   }   bool cmp2(P a, P b) { return a.y < b.y; }   void push_up(int rt) { tree[rt] = max(tree[rt << 1], tree[rt << 1 | 1]); }   void update(int pos, int x, int l, int r, int rt) {     if (l == r) {       tree[rt] = max(tree[rt], x);       return;     }     int m = (l + r) >> 1;     if (pos <= m)       update(pos, x, l, m, rt << 1);     else       update(pos, x, m + 1, r, rt << 1 | 1);     push_up(rt);   }   int query(int L, int R, int l, int r, int rt) {     if (L <= l && R >= r) return tree[rt];     int m = (l + r) >> 1;     int ans = 0;     if (L <= m) ans = max(ans, query(L, R, l, m, rt << 1));     if (R > m) ans = max(ans, query(L, R, m + 1, r, rt << 1 | 1));     return ans;   }   int main() {     int i, j, n, ans, cnt, pre;     while (~scanf( %d , &n)) {       ans = 0;       cnt = 1;       memset(tree, 0, sizeof(tree));       for (i = 0; i < n; i++) scanf( %d , &p[i].x), p[i].id = i;       for (i = 0; i < n; i++) scanf( %d , &p[i].y);       for (i = 0; i < n; i++) scanf( %d , &p[i].z);       sort(p, p + n, cmp2);       pre = p[0].y;       p[0].y = 1;       for (i = 1; i < n; i++)         if (p[i].y == pre) {           pre = p[i].y;           p[i].y = cnt;         } else {           pre = p[i].y;           p[i].y = ++cnt;         }       sort(p, p + n, cmp1);       for (i = 0; i < n;) {         for (j = i; j < n && p[i].x == p[j].x; j++) {           if (query(p[j].y + 1, cnt, 1, cnt, 1) > p[j].z) ans++;         }         for (; i < j; i++) update(p[i].y, p[i].z, 1, cnt, 1);       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200009;   int a[N], pos[N];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       pos[x] = i;     }     for (int i = 1; i <= n; i++) a[i] = pos[a[i]];     int ans = 0;     for (int i = 2; i <= n; i++) {       if (a[i] < a[i - 1]) {         i--;         cout << n - i << endl;         return 0;       }     }     cout << 0 << endl;   }


#include <bits/stdc++.h>   const int MAX = 1e6 + 105;   const int INF = 1e9 + 5;   const double M = 4e18;   using namespace std;   const int MOD = 1e9 + 7;   const double eps = 0.000000001;   int n, k;   bool query(int x, int y) {     if (x < 0 || y > n) return false;     string re;     cout << 1 <<     << x <<     << y <<   n ;     cin >> re;     return re ==  TAK ;   }   int get(int l, int r) {     if (l > r) return -1;     while (l < r) {       int mid = (l + r) / 2;       if (query(mid, mid + 1))         r = mid;       else         l = mid + 1;     }     return l;   }   int main() {     scanf( %d%d , &n, &k);     int x, y;     x = get(1, n);     y = get(1, x - 1);     if (!query(y, x)) y = get(x + 1, n);     printf( 2 %d %d n , x, y);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   signed main() {     cin.tie(0);     std::ios_base::sync_with_stdio(0);     long long n;     cin >> n;     long long cnt = 10;     vector<long long> ans;     ans.push_back(10);     if (n < 2) {       cout << 10;       return 0;     }     ans.push_back(180);     long long one_neigh = 1800, two_neighs = 810;     for (long long ii = 2; ii < n; ++ii) {       long long cnt = 1LL * one_neigh;       cnt += 1LL * two_neighs * (ii - 1LL);       one_neigh *= 10;       two_neighs *= 10;       two_neighs %= mod;       one_neigh %= mod;       cnt %= mod;       ans.push_back(cnt);     }     for (long long ii = n - 1; ii >= 0; --ii) {       cout << ans[ii] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     register long long data = 0, w = 1;     char ch = 0;     while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar();     if (ch ==  - ) w = -1, ch = getchar();     while (ch >=  0  && ch <=  9 )       data = (data << 1) + (data << 3) + (ch ^ 48), ch = getchar();     return data * w;   }   long long st1[1000005], st2[1000005], top1, top2, js[1000005], mi[1000005],       ans[1000005], ti[1000005], ad[1000005];   void pushup(long long x) {     long long l = x << 1, r = x << 1 | 1;     ans[x] = ans[l] + ans[r];     mi[x] = min(mi[l], mi[r]);     js[x] = 0;     if (mi[l] == mi[x]) js[x] += js[l];     if (mi[r] == mi[x]) js[x] += js[r];   }   void add(long long x, long long v) {     mi[x] += v;     ad[x] += v;   }   void addti(long long x, long long v) {     ans[x] += v * js[x];     ti[x] += v;   }   void pushdown(long long x) {     if (ad[x]) add(x << 1, ad[x]), add(x << 1 | 1, ad[x]);     if (ti[x]) {       if (mi[x << 1] == mi[x]) addti(x << 1, ti[x]);       if (mi[x << 1 | 1] == mi[x]) addti(x << 1 | 1, ti[x]);     }     ad[x] = ti[x] = 0;   }   void build(long long x, long long l, long long r) {     js[x] = 1;     mi[x] = l;     if (l == r) return;     long long mid = l + r >> 1;     build(x << 1, l, mid);     build(x << 1 | 1, mid + 1, r);   }   void add(long long x, long long l, long long r, long long ql, long long qr,            long long v) {     if (ql <= l && r <= qr) return add(x, v);     long long mid = l + r >> 1;     pushdown(x);     if (ql <= mid) add(x << 1, l, mid, ql, qr, v);     if (mid < qr) add(x << 1 | 1, mid + 1, r, ql, qr, v);     pushup(x);   }   long long ask(long long x, long long l, long long r, long long ql,                 long long qr) {     if (ql > r || qr < l) return 0;     if (ql <= l && r <= qr) return ans[x];     pushdown(x);     long long mid = l + r >> 1;     return ask(x << 1, l, mid, ql, qr) + ask(x << 1 | 1, mid + 1, r, ql, qr);   }   long long a[1000005], Ans[1000005];   struct que {     long long l, r, id;   } q[1000005];   int main() {     long long n = read();     for (long long i = 1; i <= n; i++) a[i] = read();     build(1, 1, n);     long long Q = read();     for (long long i = 1; i <= Q; i++)       q[i].l = read(), q[i].r = read(), q[i].id = i;     sort(q + 1, q + Q + 1, [](que A, que B) { return A.r < B.r; });     long long j = 1;     for (long long i = 1; i <= n; i++) {       add(1, -1);       while (top1 && a[i] > a[st1[top1]])         add(1, 1, n, st1[top1 - 1] + 1, st1[top1], a[i] - a[st1[top1]]), --top1;       st1[++top1] = i;       while (top2 && a[i] < a[st2[top2]])         add(1, 1, n, st2[top2 - 1] + 1, st2[top2], a[st2[top2]] - a[i]), --top2;       st2[++top2] = i;       addti(1, 1);       while (j <= Q && q[j].r == i)         Ans[q[j].id] = ask(1, 1, n, q[j].l, q[j].r), ++j;     }     for (long long i = 1; i <= Q; i++) cout << Ans[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k, i, l;     cin >> n >> k;     string s;     cin >> s;     long long max = 0;     for (i = 1; i < n; i++) {       long long temp = 0;       for (l = 0; l < n; l++) {         if (i + l < n) {           if (s[i + l] == s[l]) {             temp++;           }         } else           break;       }       if (temp == n - i) {         max = n - i;         break;       }     }     string ans = s;     for (i = 1; i < k; i++) {       ans += s.substr(max, n - max);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void speed() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   int compare(pair<long long int, long long int> a,               pair<long long int, long long int> b) {     return a.first > b.first;   }   int main() {     speed();     long long int n;     cin >> n;     vector<pair<long long int, long long int> > a;     for (long long int i = 0; i < n; i++) {       long long int temp;       cin >> temp;       a.push_back({temp, i});     }     sort(a.begin(), a.end(), compare);     long long int k = 0;     long long int tk = 0;     for (long long int i = 0; i < n; i++) {       k = (a[i].first) * i + 1;       tk += k;     }     cout << tk <<   n ;     for (long long int i = 0; i < n; i++) {       cout << a[i].second + 1 <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300005;   const int MD = 1000000007;   int n, a[N];   long long s[N], k;   int ft[N];   long long all[N];   int gt(int first) {     int res = 0;     for (int i = first; i >= 0; i &= i + 1, --i) res += ft[i];     return res;   }   void upd(int first, int v) {     for (int i = first; i < N; i |= i + 1) ft[i] += v;   }   long long chk(long long first) {     memset(ft, 0, sizeof ft);     for (int _tmp = (n), i = (0); i <= _tmp; ++i) all[i] = s[i];     sort(all, all + n + 1);     upd(lower_bound(all, all + n + 1, s[0]) - all, +1);     long long res = 0;     for (int _tmp = (n), i = (1); i <= _tmp; ++i) {       res += gt(upper_bound(all, all + n + 1, s[i] - first) - all - 1);       upd(lower_bound(all, all + n + 1, s[i]) - all, +1);     }     return res;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     for (int _tmp = (n), i = (1); i <= _tmp; ++i) {       cin >> a[i];       s[i] = a[i] + s[i - 1];     }     long long l = -1e14, r = 1e14, rs = 0;     while (l <= r) {       long long m = (l + r) / 2;       if (chk(m) >= k) {         l = m + 1;         rs = m;       } else {         r = m - 1;       }     }     cout << rs << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool F[2001][2001];   bool D[2001][2001];   int C[2001];   vector<int> V[2001];   int n;   void f(int v, int c) {     if (C[v]) return;     C[v] = c;     V[c].push_back(v);     for (int i = 1; i <= n; ++i)       if (F[v][i]) f(i, c);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     int k;     cin >> k;     while (k--) {       int a, b;       cin >> a >> b;       F[a][b] = 1;       F[b][a] = 1;     }     cin >> k;     while (k--) {       int a, b;       cin >> a >> b;       D[a][b] = 1;       D[b][a] = 1;     }     int ans = 0;     for (int i = 1; i <= n; ++i) {       f(i, i);       int t = V[i].size();       for (int j = 0; j < t; ++j)         for (int l = 0; l < t; ++l)           if (D[V[i][j]][V[i][l]]) goto skip;       ans = max(ans, t);     skip:;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[5010], n, s = 0, i;   int main() {     cin >> n >> i;     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     for (i = 0; i < n; i++) s += a[i] != a[(i + n / 2) % n];     cout << s << endl;     for (i = 0; i < n; i++) cout << a[i] <<     << a[(i + n / 2) % n] << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   void chkmin(T1 &x, T2 y) {     if (x > y) x = y;   }   template <typename T1, typename T2>   void chkmax(T1 &x, T2 y) {     if (x < y) x = y;   }   namespace fastio {   char rbuf[1 << 23], *p1 = rbuf, *p2 = rbuf, wbuf[1 << 23], *p3 = wbuf;   inline char getc() {     return p1 == p2 &&                    (p2 = (p1 = rbuf) + fread(rbuf, 1, 1 << 23, stdin), p1 == p2)                ? -1                : *p1++;   }   inline void putc(char x) { (*p3++ = x); }   template <typename T>   void read(T &x) {     x = 0;     char c = getchar();     T neg = 0;     while (!isdigit(c)) neg |= !(c ^  - ), c = getchar();     while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();     if (neg) x = (~x) + 1;   }   template <typename T>   void recursive_print(T x) {     if (!x) return;     recursive_print(x / 10);     putc(x % 10 ^ 48);   }   template <typename T>   void print(T x) {     if (!x) putc( 0 );     if (x < 0) putc( - ), x = ~x + 1;     recursive_print(x);   }   void print_final() { fwrite(wbuf, 1, p3 - wbuf, stdout); }   }  // namespace fastio   const int MAXN = 3e3;   int R, C, n, k, x[MAXN + 5], y[MAXN + 5];   vector<int> vr[MAXN + 5], vc[MAXN + 5];   int l[MAXN + 5], r[MAXN + 5];   long long ans = 0;   int main() {     scanf( %d%d%d%d , &R, &C, &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &x[i], &y[i]);       vr[x[i]].push_back(i);       vc[y[i]].push_back(i);     }     for (int i = 1; i <= MAXN; i++)       sort(vr[i].begin(), vr[i].end(),            [](int lhs, int rhs) { return y[lhs] > y[rhs]; });     for (int i = 1; i <= MAXN; i++)       sort(vc[i].begin(), vc[i].end(),            [](int lhs, int rhs) { return x[lhs] < x[rhs]; });     for (int i = 1; i <= R; i++) {       memset(l, 0, sizeof(l));       memset(r, 0, sizeof(r));       int pre = 0;       for (int j = 1; j <= C; j++)         for (int t = 0; t < vc[j].size(); t++)           if (x[vc[j][t]] >= i) {             int id = vc[j][t];             l[id] = pre;             if (pre) r[pre] = id;             pre = id;           }       long long ret = 0;       for (int j = 1; j <= C; j++)         for (int t = 0; t < vc[j].size(); t++)           if (x[vc[j][t]] >= i) {             int id = vc[j][t], cur = id;             for (int stp = 1; stp < k; stp++) cur = r[cur];             if (cur) ret += 1ll * (C - y[cur] + 1) * (y[id] - y[l[id]]);           }       ans += ret;       for (int j = R; j >= i; j--) {         for (int t = 0; t < vr[j].size(); t++) {           int id = vr[j][t];           if (!r[id]) {             int cur = id;             for (int stp = 1; stp < k; stp++) cur = l[cur];             if (cur) ret -= 1ll * (y[cur] - y[l[cur]]) * (C - y[id] + 1);             if (r[id]) l[r[id]] = l[id];             if (l[id]) r[l[id]] = r[id];             continue;           }           int cr = r[id], cl = r[id], stp = 0;           while (stp < k - 1) {             if (!r[cr]) break;             cr = r[cr];             ++stp;           }           for (int o = 1; o <= k - 1 - stp; o++) cl = l[cl];           if (cl) ret -= 1ll * (C - y[cr] + 1) * (y[cl] - y[l[cl]]);           for (int o = 1; o <= stp + 1; o++) {             cr = l[cr];             cl = l[cl];             if (cl) ret -= 1ll * (C - y[cr] + 1) * (y[cl] - y[l[cl]]);           }           if (r[id]) l[r[id]] = l[id];           if (l[id]) r[l[id]] = r[id];           if (!r[id]) continue;           cr = r[id], cl = r[id], stp = 0;           while (stp < k - 1) {             if (!r[cr]) break;             cr = r[cr];             ++stp;           }           for (int o = 1; o <= k - 1 - stp; o++) cl = l[cl];           if (cl) ret += 1ll * (C - y[cr] + 1) * (y[cl] - y[l[cl]]);           for (int o = 1; o <= stp; o++) {             cr = l[cr];             cl = l[cl];             if (cl) ret += 1ll * (C - y[cr] + 1) * (y[cl] - y[l[cl]]);           }         }         ans += ret;       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     map<int, vector<pair<int, int> > > mapa;     for (int i = 0; i < n; i++) {       int suma = 0;       for (int j = i; j < n; j++) {         suma += v[j];         mapa[suma].push_back({j, i});       }     }     vector<pair<int, int> > maxRes;     for (auto i : mapa) {       auto vec = i.second;       sort(vec.begin(), vec.end());       vector<pair<int, int> > usable;       for (int j = 0; j < vec.size(); j++) {         if (usable.size() == 0) {           usable.push_back(vec[j]);         } else {           if (usable.back().first < vec[j].second) {             usable.push_back(vec[j]);           }         }       }       if (usable.size() > maxRes.size()) {         maxRes = usable;       }     }     cout << maxRes.size() << endl;     for (auto i : maxRes) cout << i.second + 1 <<     << i.first + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline bool invowel(char ch) {     ch = tolower(ch);     return (ch ==  a  || ch ==  e  || ch ==  i  || ch ==  o  || ch ==  u );   }   inline bool isprime(int n) {     if (n < 2 || (n % 2 == 0 && n != 2)) return false;     for (int i = 3; i * i <= n; i += 2)       if (n % i == 0) return false;     return true;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());     int t;     t = 1;     while (t--) {       int n, i;       cin >> n;       vector<int> x(n), y(n);       for (i = 0; i < n; i++) {         cin >> x[i] >> y[i];       }       if (n & 1) {         cout <<  No n ;         break;       }       for (i = 0; i < n / 2; i++) {         if (x[0] + x[n / 2] != x[i] + x[i + n / 2] ||             y[0] + y[n / 2] != y[i] + y[i + n / 2]) {           cout <<  No n ;           return 0;         }       }       cout <<  Yes n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long r;     cin >> r;     vector<long long> ans;     for (int i = 1; i < sqrt(r); i++) {       long long rem = r - ((i * i) + i + 1);       if (rem % 2 == 0 && rem > 0) {         ans.push_back(i);         ans.push_back(rem / 2);         break;       }     }     if (ans.empty())       cout <<  NO ;     else       for (int i = 0; i < ans.size(); i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10, mod = 1e9 + 7;   int n, m, k, t;   char a[maxn];   long long h[maxn], h1[maxn], xp[maxn];   long long get(long long h[], int pos, int len, int len1) {     return (h[pos + len - 1] - h[pos - 1] * xp[len1] % mod + mod) % mod;   }   int cnt[maxn];   int main() {     int i, j;     xp[0] = 1;     for (i = 1; i < maxn; i++) xp[i] = xp[i - 1] * 229 % mod;     scanf( %d%s , &n, a + 1);     h[0] = h1[0] = 1;     for (i = 1; i <= n; i++) {       if (a[i] ==  0 ) {         h[i] = h[i - 1] * 229 % mod + (i & 1) + 1;         h1[i] = h1[i - 1] * 229 % mod + (i & 1 ^ 1) + 1;         cnt[i] = cnt[i - 1] + 1;       } else         h[i] = h[i - 1], h1[i] = h1[i - 1], cnt[i] = cnt[i - 1];     }     int q;     scanf( %d , &q);     while (q--) {       int l1, l2, len;       scanf( %d%d%d , &l1, &l2, &len);       if (get(h, l1, len, cnt[l1 + len - 1] - cnt[l1 - 1]) ==           get(((l1 ^ l2) & 1 ? h1 : h), l2, len,               cnt[l2 + len - 1] - cnt[l2 - 1])) {         puts( Yes );       } else         puts( No );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, k;   vector<vector<pair<long long, long long>>> graph;   long long ok[10][10];   long long fine[10][10][10][10];   bitset<(long long)(2e5 + 5)> incoming[10][10];   long long answer = 0;   vector<long long> temp;   void dfs() {     if (temp.size() == k) {       answer++;       return;     }     long long ind = temp.size() + 1;     for (long long i = 0; i < ind; i++) {       bool flag = true;       for (long long j = 1; j < ind; j++) {         if (!fine[ind][i][j][temp[j - 1]]) {           flag = false;           break;         }       }       if (!flag) continue;       if (ok[ind][i]) {         temp.push_back(i);         dfs();         temp.pop_back();       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m >> k;     graph.resize(n + 1);     for (long long i = 0; i < m; i++) {       long long u, v, w;       cin >> u >> v >> w;       graph[u].push_back({w, v});     }     for (long long i = 1; i < n + 1; i++) {       if (graph[i].size() == 0) {         cout << 0 <<   n ;         return 0;       }       sort(graph[i].begin(), graph[i].end());     }     for (long long i = 1; i < k + 1; i++)       for (long long j = 0; j < i; j++) ok[i][j] = 1;     for (long long out = 1; out < k + 1; out++) {       for (long long i = 1; i < n + 1; i++) {         if (graph[i].size() == out) {           for (long long j = 0; j < graph[i].size(); j++) {             long long ver = graph[i][j].second;             if (incoming[out][j][ver]) {               ok[out][j] = 0;               continue;             }             incoming[out][j][ver] = 1;           }         }       }     }     for (long long a = 1; a < k + 1; a++)       for (long long b = 0; b < a; b++)         for (long long c = a; c < k + 1; c++)           for (long long d = 0; d < c; d++) {             if ((incoming[a][b] & incoming[c][d]) == 0) {               fine[a][b][c][d] = fine[c][d][a][b] = 1;             }           }     dfs();     cout << answer <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   void in(long long int *a, long long int n) {     for (long long int i = 0; i < n; i++) {       cin >> a[i];     }   }   void out(long long int *a, long long int n) {     for (long long int i = 0; i < n; i++) {       cout << a[i] <<    ;     }   }   long long int count(long long int n) {     long long int add = 0;     while (n > 0) {       if (n % 10 == 9)         add = add + 1;       else         break;       n = n / 10;     }     return add;   }   int main() {     fast();     long long int tc = 1;     while (tc--) {       long long int n, m;       cin >> n >> m;       n = n * (n + 1) / 2;       long long int t = m % n;       for (long long int i = 1; i <= m; i++) {         if (t < i) break;         t = t - i;       }       cout << t <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int kol[10], ans = -1, ans0 = 0;   vector<int> a, b;   int main() {     memset(kol, 0, sizeof(kol));     char c;     while (cin >> c) kol[c -  0 ]++;     for (int i = 1; i < 10; i++) {       vector<int> c, d;       int K1[10], K2[10], res = 0, nul = 0;       for (int j = 0; j < 10; j++) {         K1[j] = kol[j];         K2[j] = kol[j];       }       if (K1[i] > 0 && K2[10 - i] > 0) {         c.push_back(i);         d.push_back(10 - i);         K1[i]--;         K2[10 - i]--;         res++;         for (int j = 0; j < 10; j++) {           while (K1[j] > 0 && K2[9 - j] > 0) {             K1[j]--;             K2[9 - j]--;             c.push_back(j);             d.push_back(9 - j);             res++;           }         }       }       while (K1[0] > 0 && K2[0] > 0) {         K1[0]--;         K2[0]--;         res++;         nul++;       }       for (int j = 0; j < 10; j++) {         while (K1[j] > 0) {           K1[j]--;           c.push_back(j);         }         while (K2[j] > 0) {           K2[j]--;           d.push_back(j);         }       }       if (res > ans) {         ans = res;         ans0 = nul;         a.swap(c);         b.swap(d);       }     }     for (int i = a.size() - 1; i >= 0; i--) cout << a[i];     for (int i = 0; i < ans0; i++) cout << 0;     cout << endl;     for (int i = a.size() - 1; i >= 0; i--) cout << b[i];     for (int i = 0; i < ans0; i++) cout << 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     long n, k;     cin >> t;     while (t--) {       cin >> n >> k;       bool win = true;       if (k % 3 == 0) {         int np = n % (k + 1);         if (np % 3 == 0 && np != k) win = false;       } else {         int np = n % 3;         if (np == 0) win = false;       }       puts(win ?  Alice  :  Bob );     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1010, max_range = 1000001;   int edge[maxn][3 * maxn], reached[maxn], start[3 * maxn], len[3 * maxn],       vert[3 * maxn][2], n, m, res;   FILE *in;   int nb(int v, int e) {     if (vert[e][0] == v)       return vert[e][1];     else       return vert[e][0];   }   int dfs(int sz, int x, int v) {     reached[v] = 1;     if (v == n) return 1;     int e, u;     for (int i = 1; i <= edge[v][0]; i++) {       e = edge[v][i];       u = nb(v, e);       if (reached[u] == 0 && x >= start[e] && x - start[e] <= len[e] - sz) {         if (dfs(sz, x, u) == 1) return 1;       }     }     return 0;   }   bool check(int sz) {     int res = 0;     for (int i = 1; i <= m; i++)       if (len[i] >= sz) {         memset(reached, 0, sizeof(reached));         res = dfs(sz, start[i], 1);         if (res == 1) break;       }     return res == 1;   }   void init() {     int x, y, l, r;     fscanf(in,  %d %d , &n, &m);     for (int i = 1; i <= m; i++) {       fscanf(in,  %d %d %d %d , &x, &y, &l, &r);       edge[x][0]++;       edge[x][edge[x][0]] = i;       edge[y][0]++;       edge[y][edge[y][0]] = i;       start[i] = l;       len[i] = r - l + 1;       vert[i][0] = x;       vert[i][1] = y;     }   }   int solve() {     int l = 0, r = max_range, s = (l + r) / 2;     while (r - l > 1) {       if (check(s))         l = s;       else         r = s;       s = (l + r) / 2;     }     return s;   }   int main() {     in = stdin;     init();     res = solve();     if (res == 0)       printf( Nice work, Dima! n );     else       printf( %d , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct pt {     int x, y;     pt() {}     pt(int x, int y) : x(x), y(y) {}   };   int get_pos(int i, int n) {     if (i >= n) i -= n;     return ((i >= 0) ? i : n - i - 1);   }   void solve() {     int n;     cin >> n;     vector<pt> v(n);     for (int i = 0; i < n; ++i) {       cin >> v[i].x >> v[i].y;     }     if (n & 1) {       cout <<  NO ;       return;     }     for (int i = 0; i < n; ++i) {       pt a = v[get_pos(i, n)], b = v[get_pos(i + 1, n)];       pt c = v[get_pos(i + n / 2, n)], d = v[get_pos(i + n / 2 + 1, n)];       int A1 = b.y - a.y, B1 = b.x - a.x;       int A2 = c.y - d.y, B2 = c.x - d.x;       if (!(A1 == A2 && B1 == B2)) {         cout <<  No  << endl;         return;       }     }     cout <<  YES ;   }   int main() {     int t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   map<long long, long long> mp1, mp2;   long long n, k;   long long a[200001];   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> k;     long long res = 0;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = n; i >= 1; --i) {       res += mp1[a[i] * k];       if (a[i] % k == 0) mp1[a[i]] += mp2[a[i] * k];       if (a[i] % (k * k) == 0) ++mp2[a[i]];     }     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void in(T &x) {     bool f = 0;     x = 0;     char c = getchar();     while ((c <  0  || c >  9 ) && c !=  - ) c = getchar();     if (c ==  - ) {       f = 1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     if (f) x = -x;     return;   }   template <typename T1, typename T2>   void in(T1 &x, T2 &y) {     in(x);     return in(y);   }   template <typename T1, typename T2, typename T3>   void in(T1 &x, T2 &y, T3 &z) {     in(x);     in(y);     return in(z);   }   template <typename T1, typename T2, typename T3, typename T4>   void in(T1 &x, T2 &y, T3 &z, T4 &w) {     in(x);     in(y);     in(z);     return in(w);   }   int a[200009], b[200009], d[200009];   int main() {     int n, k, cnt = 0;     in(n, k);     for (int i = 0; i < n; i++) in(a[i]);     for (int i = 0; i < n; i++) in(b[i]);     int j = 0;     for (int i = 0; i < n; i++)       if (a[i] <= b[i])         k--;       else         d[j++] = a[i] - b[i];     sort(d, d + j);     for (int i = 0; i < j && k > 0; i++) cnt += d[i], k--;     for (int i = 0; i < n; i++) cnt += min(a[i], b[i]);     printf( %d n , cnt);     return 0;   }


#include <bits/stdc++.h>   int main() {     int k, x, n;     scanf( %d %d , &n, &k);     int p = k;     while (p >= 1) {       x = k * n / p + p;       if (n == ((x / k) * (x % k))) break;       p--;     }     printf( %d , x);   }


#include <bits/stdc++.h>   inline long long read() {     long long x = 0;     char c = getchar(), f = 1;     for (; c <  0  ||  9  < c; c = getchar())       if (c ==  - ) f = -1;     for (;  0  <= c && c <=  9 ; c = getchar()) x = x * 10 + c -  0 ;     return x * f;   }   inline void write(long long x) {     static char buf[20];     int len = 0;     if (x < 0) putchar( - ), x = -x;     for (; x; x /= 10) buf[len++] = x % 10 +  0 ;     if (!len)       putchar( 0 );     else       while (len) putchar(buf[--len]);   }   inline void writesp(long long x) {     write(x);     putchar(   );   }   inline void writeln(long long x) {     write(x);     putchar(  n );   }   struct Query {     int l, r, id;   } q[200010];   long long s[200010], inv[200010], power[200010];   int a[200010];   int pos[200010], len[200010];   long long cur[200010], sum[200010];   int ans[200010];   int n, m;   bool cmp(Query a, Query b) { return a.r < b.r; }   long long calc(int l, int r) {     return (s[r] - s[l - 1] + 1000000007) * inv[l - 1] % 1000000007;   }   int main() {     n = read();     m = read();     for (int i = 1; i <= n; i++) a[i] = read();     s[0] = 0;     inv[0] = power[0] = 1;     for (int i = 1; i <= n; i++) {       inv[i] = inv[i - 1] * ((1000000007 + 1) / 2) % 1000000007;       power[i] = power[i - 1] * 2 % 1000000007;       s[i] = (s[i - 1] + (a[i] * power[i - 1] % 1000000007) + 1000000007) %              1000000007;     }     for (int i = 1; i <= m; i++) q[i].l = read(), q[i].r = read(), q[i].id = i;     std::sort(q + 1, q + m + 1, cmp);     int tot = 0, last = 1;     for (int i = 1; i <= n; i++) {       pos[++tot] = i;       len[tot] = 1;       cur[tot] = a[i];       sum[tot] = (sum[tot - 1] + cur[tot] % 1000000007 + 1000000007) % 1000000007;       while (tot > 1 && cur[tot] >= 0) {         if ((len[tot - 1] > 30 && cur[tot] > 0) ||             (cur[tot - 1] + (cur[tot] << len[tot - 1])) > 0x7fffffff)           cur[tot - 1] = 0x7fffffff;         else           cur[tot - 1] = (cur[tot - 1] + (cur[tot] << len[tot - 1]));         sum[tot - 1] = (sum[tot - 1] + (sum[tot] - sum[tot - 1] + 1000000007) *                                            power[len[tot - 1]]) %                        1000000007;         len[tot - 1] += len[tot];         --tot;       }       while (last <= m && q[last].r <= i) {         int l = 1, r = tot;         while (l < r) {           int mid = (l + r + 1) >> 1;           if (pos[mid] <= q[last].l)             l = mid;           else             r = mid - 1;         }         ans[q[last].id] = ((sum[tot] - sum[l] + 1000000007) * 2 +                            calc(q[last].l, pos[l] + len[l] - 1)) %                           1000000007;         ++last;       }     }     for (int i = 1; i <= m; i++) writeln(ans[i]);     putchar(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int left[n], right[n];     int leftOpen = 0, leftClose = 0, rightOpen = 0, rightClose = 0;     for (int i = 0; i < n; i++) {       cin >> left[i];       cin >> right[i];       if (left[i])         leftOpen += 1;       else         leftClose += 1;       if (right[i])         rightOpen += 1;       else         rightClose += 1;     }     int minCount = 0;     if (leftOpen > leftClose)       minCount += leftClose;     else       minCount += leftOpen;     if (rightOpen > rightClose)       minCount += rightClose;     else       minCount += rightOpen;     cout << minCount << endl;   }


#include <bits/stdc++.h>   using namespace std;   int a[202020], f[202020];   int s[202020];   bool br[202020];   int n, doe, ans;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]), ++f[a[i]];     doe = 1;     while (f[doe] != 0) ++doe;     for (int i = 1; i <= n; ++i) {       if (f[a[i]] == 1 && br[a[i]] == 0) {         s[i] = a[i];         br[a[i]] = 1;         continue;       }       if (a[i] < doe && br[a[i]] == 0) {         s[i] = a[i];         br[a[i]] = 1;         --f[a[i]];         continue;       }       ++ans;       s[i] = doe;       --f[a[i]];       br[doe] = 1;       ++doe;       while (f[doe] != 0) ++doe;     }     printf( %d n , ans);     printf( %d , s[1]);     for (int i = 2; i <= n; ++i) printf(  %d , s[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct ljb {     int dest, flow, cost;     ljb *next, *other;   };   int n, s, ans1, ans2, flag[10000], cost[10000], flow[10000], u[100000],       hh[10000], lim[10000];   ljb *p, *head[10000], *tail[10000], *hu[10000];   string ct, cs[10000];   void push(int x, int y, int z, int w) {     ljb *p, *q;     p = new ljb;     p->dest = y;     p->flow = z;     p->cost = w;     p->next = 0;     tail[x]->next = p;     tail[x] = p;     q = new ljb;     q->dest = x;     q->flow = 0;     q->cost = -w;     q->next = 0;     tail[y]->next = q;     tail[y] = q;     p->other = q;     q->other = p;   }   void spfa() {     int rc, fc, uu;     ljb *p;     while (true) {       memset(flow, 0, sizeof(flow));       for (int i = 0; i <= s; i++) cost[i] = 2147483647;       memset(flag, 0, sizeof(flag));       cost[0] = 0;       flow[0] = 2147483647;       rc = 1;       fc = 1;       u[rc] = 0;       while (rc <= fc) {         flag[u[rc]] = 0;         p = head[u[rc]]->next;         while (p != 0) {           if ((p->flow > 0) && (cost[u[rc]] + p->cost < cost[p->dest])) {             cost[p->dest] = cost[u[rc]] + p->cost;             flow[p->dest] = min(flow[u[rc]], p->flow);             hu[p->dest] = p;             if (flag[p->dest] == 0) {               ++fc;               u[fc] = p->dest;               flag[p->dest] = 1;             }           }           p = p->next;         }         ++rc;       }       if (flow[s] == 0) break;       ans1 += flow[s];       ans2 += flow[s] * cost[s];       uu = s;       while (uu != 0) {         hu[uu]->flow -= flow[s];         hu[uu]->other->flow += flow[s];         uu = hu[uu]->other->dest;       }     }   }   int main() {     string ct;     cin >> ct;     cin >> n;     for (int i = 1; i <= n; i++) cin >> cs[i] >> lim[i];     s = n + 27;     for (int i = 0; i <= s; i++) {       p = new ljb;       p->dest = 0;       p->cost = 0;       p->flow = 0;       p->next = 0;       p->other = 0;       head[i] = p;       tail[i] = p;     }     for (int i = 1; i <= n; i++) push(0, i, lim[i], 0);     for (int i = 1; i <= n; i++) {       memset(hh, 0, sizeof(hh));       for (int j = 0; j < cs[i].size(); j++) ++hh[cs[i][j] - 96];       for (int j = 1; j <= 26; j++) push(i, j + n, hh[j], i);     }     memset(hh, 0, sizeof(hh));     for (int i = 0; i < ct.size(); i++) ++hh[ct[i] - 96];     for (int i = 1; i <= 26; i++) push(i + n, s, hh[i], 0);     spfa();     if (ans1 != ct.size()) ans2 = -1;     cout << ans2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N;   void ro(vector<string> &b) {     vector<string> c(N, string(N,    ));     for (int i = 0; i < N; i++) {       for (int j = N - 1; j >= 0; j--) {         c[N - 1 - j][i] = b[i][j];       }     }     b = c;   }   void fl(vector<string> &b) { reverse(b.begin(), b.end()); }   int main() {     cin >> N;     vector<string> b1(N), b2(N);     int i;     for (i = 0; i < N; i++) {       string s;       cin >> s;       b1[i] = s;     }     for (i = 0; i < N; i++) {       string s;       cin >> s;       b2[i] = s;     }     for (i = 0; i < 4; i++) {       ro(b1);       if (b1 == b2) {         break;       }     }     if (i >= 4) {       fl(b1);       for (i = 0; i < 4; i++) {         ro(b1);         if (b1 == b2) {           break;         }       }     }     cout << (i < 4 ?  Yes  :  No ) << endl;     return (0);   }


#include <bits/stdc++.h>   using namespace std;   const int M = 100005;   int read() {     int x = 0, flag = 1;     char c;     while ((c = getchar()) <  0  || c >  9 )       if (c ==  - ) flag = -1;     while (c >=  0  && c <=  9 )       x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();     return x * flag;   }   int n, m, q, l[M], r[M], u[M], d[M];   char s[M];   void get(int n, int *a) {     scanf( %s , s + 1);     for (int i = 1; i <= n; i++) a[i] = (s[i] ==  R );   }   int cal() {     int f0 = 0, f1 = 0, g0, g1;     for (int i = 1; i <= m; i++) f0 += u[i], f1 += (!u[i]);     for (int i = 1; i <= n; i++) {       g0 = f0;       g1 = f1;       f0 = min(g0, g1 + m) + l[i] + r[i];       f1 = min(g0 + m, g1) + (!l[i]) + (!r[i]);     }     for (int i = 1; i <= m; i++) f0 += d[i], f1 += (!d[i]);     return min(f0, f1);   }   signed main() {     n = read();     m = read();     q = read();     get(n, l);     get(n, r);     get(m, u);     get(m, d);     int ans = cal();     swap(n, m);     swap(l, u);     swap(r, d);     ans = min(ans, cal());     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   ostream& operator<<(ostream& os, const pair<T, U>& _p) {     return os <<  (  << _p.first <<  ,  << _p.second <<  ) ;   }   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& _V) {     bool f = true;     os <<  [ ;     for (auto v : _V) {       os << (f ?    :  , ) << v;       f = false;     }     return os <<  ] ;   }   template <typename T>   ostream& operator<<(ostream& os, const set<T>& _S) {     bool f = true;     os <<  ( ;     for (auto s : _S) {       os << (f ?    :  , ) << s;       f = false;     }     return os <<  ) ;   }   template <typename T, typename U>   ostream& operator<<(ostream& os, const map<T, U>& _M) {     return os << set<pair<T, U>>(_M.begin(), _M.end());   }   const signed long long INF = 1000000100;   const long double EPS = 1e-9;   template <typename T, typename F>   T bin_search(T a, T b, F f) {     while (a < b) {       T c = a + (b - a) / 2;       if (f(c)) {         b = c;       } else {         a = c + 1;       }     }     return a;   }   const int MAXN = 1000100;   int A[MAXN];   int S1[MAXN];   int S2[MAXN];   int N;   void read_data() {     scanf( %d , &N);     for (int(i) = (1); (i) <= (N); (i)++) scanf( %d , A + i);   }   void solve() {     vector<pair<int, int>> results;     for (int(i) = (1); (i) <= (N); (i)++) S1[i] = S1[i - 1] + (A[i] == 1);     for (int(i) = (1); (i) <= (N); (i)++) S2[i] = S2[i - 1] + (A[i] == 2);     for (int(i) = (N); (i) >= (1); (i)--) {       int t = 0;       int z1 = 0;       int z2 = 0;       bool fail = false;       int last = -1;       while (t < N) {         int k1 = bin_search(t + 1, N + 1, [&](int x) {           return x == N + 1 or S1[x] - S1[t] >= i;         });         int k2 = bin_search(t + 1, N + 1, [&](int x) {           return x == N + 1 or S2[x] - S2[t] >= i;         });         if (k1 < k2) {           if (S1[k1] - S1[t] != i) {             fail = true;             break;           }           ++z1;           last = 1;         } else if (k1 > k2) {           if (S2[k2] - S2[t] != i) {             fail = true;             break;           }           ++z2;           last = 2;         } else           fail = true;         t = min(k1, k2);       }       if (z1 > z2 and last != 1) continue;       if (z1 < z2 and last != 2) continue;       if (fail) continue;       if (z1 == z2) continue;       results.emplace_back(max(z1, z2), i);     }     sort(results.begin(), results.end());     printf( %d n , int(results.size()));     for (auto r : results) printf( %d %d n , r.first, r.second);   }   int main() {     read_data();     solve();   }


#include <bits/stdc++.h>   using namespace std;   template <class Int>   Int MAX(Int a, Int b) {     return (a > b) ? a : b;   }   template <class Int>   Int MIN(Int a, Int b) {     return (a < b) ? a : b;   }   const double PI = 2 * acos(0.0);   const int INF = 1 << 30;   int main(void) {     int l, d, v, g, r;     double tl;     int i, j, k, s;     bool f;     while (scanf( %d %d %d %d %d , &l, &d, &v, &g, &r) != EOF) {       tl = (double)d / (double)v;       j = floor(tl);       k = 0;       for (i = 0;; i++) {         if (i % 2 == 0) {           if (k + g <= j)             k += g;           else {             s = g;             f = true;             break;           }         } else {           if (k + r < j)             k += r;           else {             s = r;             f = false;             break;           }         }       }       if (f) {         tl += (double)((double)l - (double)d) / (double)v;       } else {         tl += (double)r - (double)((double)tl - (double)k);         tl += (double)((double)l - (double)d) / (double)v;       }       printf( %.8lf n , tl);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int two(int n) { return 1 << n; }   inline int test(int n, int b) { return (n >> b) & 1; }   inline void set_bit(int& n, int b) { n |= two(b); }   inline void unset_bit(int& n, int b) { n &= ~two(b); }   inline int last_bit(int n) { return n & (-n); }   inline int ones(int n) {     int res = 0;     while (n && ++res) n -= n & (-n);     return res;   }   const long double PI = 3.1415926535897932384626;   const long long int MAX = 1000000000 + 7;   char s[105][105];   int main() {     long long int n, m;     scanf( %lld , &n);     scanf( %lld , &m);     for (long long int i = 0; i <= n; i++) s[i][0] =  - ;     for (long long int j = 0; j <= m; j++) s[0][j] =  - ;     char x;     scanf( %c , &x);     for (long long int i = 1; i <= n; i++) {       for (long long int j = 1; j <= m; j++) {         scanf( %c , &s[i][j]);       }       scanf( %c , &x);     }     for (long long int i = 1; i <= n; i++) {       for (long long int j = 1; j <= m; j++) {         if (s[i][j] ==  . ) {           if (i % 2 == 1 and j % 2 == 1)             s[i][j] =  B ;           else if (i % 2 == 1 and (j % 2 == 0))             s[i][j] =  W ;           else if ((i % 2 == 0) and j % 2 == 1)             s[i][j] =  W ;           else if ((i % 2 == 0) and (j % 2 == 0))             s[i][j] =  B ;         }       }     }     for (long long int i = 1; i <= n; i++) {       for (long long int j = 1; j <= m; j++) printf( %c , s[i][j]);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using pii = pair<int, int>;   using ll = long long;   int kmp(string const& s) {     int n = s.size();     vector<int> lps(n, 0);     for (int i = 1; i < n; i++) {       int j = lps[i - 1];       while (j > 0 && s[i] != s[j]) j = lps[j - 1];       if (s[i] == s[j]) j++;       lps[i] = j;     }     return lps.back();   }   bool cmp(vector<int>& a, vector<int>& b) {     for (int i = 0; i < a.size(); i++)       if (a[i] > b[i]) return false;     return true;   }   void sub(vector<int>& a, vector<int>& b) {     for (int i = 0; i < a.size(); i++) a[i] -= b[i];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     string s, t;     cin >> s >> t;     int k = kmp(t);     string t1 = t.substr(0, k);     string t2 = t.substr(k, t.size() - k);     vector<int> cnts(2, 0), cntt1(2, 0), cntt2(2, 0);     for (char c : s) cnts[c -  0 ]++;     for (char c : t1) cntt1[c -  0 ]++;     for (char c : t2) cntt2[c -  0 ]++;     string ans =   ;     if (cmp(cntt1, cnts)) ans = t1, sub(cnts, cntt1);     while (cmp(cntt2, cnts)) {       for (char c : t2) ans += c;       sub(cnts, cntt2);     }     while (cnts[0] > 0) ans +=  0 , cnts[0]--;     while (cnts[1] > 0) ans +=  1 , cnts[1]--;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else {       return gcd(b, a % b);     }   }   int main() {     multiset<long long> s;     multiset<long long>::iterator it;     long long n, arr[100000], i, ache = 0, Max = -1, z, churi1, churi2, chilo,                                  haraise, a, y;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a;       s.insert(a);       if (a > Max) Max = a;       ache += a;     }     chilo = n * Max;     it = s.begin();     churi1 = Max - *it;     for (it = s.begin(); it != s.end(); it++) {       churi1 = gcd(churi1, Max - (*it));     }     haraise = chilo - ache;     y = haraise / churi1;     cout << y <<     << churi1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     return b == 0 ? abs(a) : gcd(b, a % b);   }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   long long div_count(long long n) {     long long cunt = 0;     while (n > 1) {       if (n % 2 == 0) {         n = n / 2;       } else if (n % 3 == 0) {         n = 2 * n / 3;       } else if (n % 5 == 0) {         n = n * 4 / 5;       } else {         n = -1;       }       cunt++;     }     if (n == 1) {       return cunt;     }     return -1;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int q;     long long n;     std::cin >> q;     for (int i = 0; i < q; i++) {       std::cin >> n;       cout << div_count(n) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline int size(const T& c) {     return c.size();   }   template <class T>   inline int length(const T& c) {     return c.length();   }   unsigned long long l, r, k, m;   vector<unsigned long long> can;   struct matrix {     unsigned long long val[2][2];     friend matrix operator*(const matrix a, const matrix b) {       matrix ret;       for (int i = (0), _b = ((2) - 1); i <= _b; i++)         for (int j = (0), _b = ((2) - 1); j <= _b; j++) {           ret.val[i][j] = 0;           for (int k = (0), _b = ((2) - 1); k <= _b; k++)             ret.val[i][j] = (ret.val[i][j] + a.val[i][k] * b.val[k][j]) % m;         }       return ret;     }     friend matrix operator^(const matrix a, const unsigned long long n) {       if (n == 1) return a;       matrix ret = a ^ (n / 2);       ret = ret * ret;       if (n % 2 == 1) ret = ret * a;       return ret;     }   };   unsigned long long fibo(unsigned long long n) {     if (n <= 2)       return 1 % m;     else if (n == 3)       return 2 % m;     else {       matrix a;       a.val[0][0] = 0;       a.val[0][1] = 1;       a.val[1][0] = 1;       a.val[1][1] = 1;       n -= 3;       a = a ^ n;       return (a.val[1][0] + 2 * a.val[1][1]) % m;     }   }   int main() {     while (cin >> m >> l >> r >> k) {       can.clear();       for (unsigned long long i = 1; i * i <= r; i++) {         (can).push_back((i));         (can).push_back((r / i));         if (i * i <= l)           if (l % i == 0)             (can).push_back((l / i));           else             (can).push_back((l / (i - 1)));       }       unsigned long long ret = 1;       for (int i = (0), _b = ((can.size()) - 1); i <= _b; i++) {         unsigned long long a = l / can[i];         if (l % can[i] != 0) a++;         unsigned long long b = r / can[i];         if (b - a + 1 >= k) ret = max(ret, can[i]);       }       cout << fibo(ret) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s[n];     for (int i = 0; i < n; i++) {       cin >> s[i];       bool b = false;       if (i == 0) {         cout <<  NO  << endl;         continue;       }       for (int j = 0; j < i; j++) {         if (s[j] == s[i]) {           cout <<  YES  << endl;           b = true;           break;         }       }       if (!b) {         cout <<  NO  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     long long p;     cin >> n >> p;     vector<pair<long long, int> > ar;     vector<long long> ans(n);     for (int i = 0; i < n; i++) {       long long x;       cin >> x;       ar.push_back(make_pair(x, i));     }     sort(ar.begin(), ar.end());     set<int> waiting;     int q_smallest = n + 1;     queue<int> q;     long long time = 0;     int turn;     for (int i = 0; i < n || waiting.size() != 0 || q.size() != 0;) {       if (q.size() == 0 && waiting.size() == 0) {         q.push(ar[i].second);         q_smallest = ar[i].second;         time = ar[i++].first;       }       if (q.size() != 0) {         turn = q.front();         if (q_smallest == q.front()) q_smallest = n + 1;         q.pop();       } else if (waiting.size() != 0) {         turn = *(waiting.begin());         waiting.erase(waiting.begin());       }       time += p;       ans[turn] = time;       while (i < n && ar[i].first <= time) {         if ((q.size() == 0 || (q.size() > 0 && q_smallest > ar[i].second)) &&             turn > ar[i].second) {           q.push(ar[i].second);           q_smallest = ar[i].second;         } else {           waiting.insert(ar[i].second);         }         i++;       }     }     for (int i = 0; i < n; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n;     cin >> t;     while (t--) {       int n, m, aux1, aux2;       int q;       cin >> q;       string ans =   ;       vector<pair<int, int> > v;       for (int i = 0; i < q; i++) {         cin >> n >> m;         v.push_back(make_pair(n, m));       }       sort(v.begin(), v.end());       bool f1 = true;       bool f2 = true;       int contr = 0;       for (auto i = v.begin(); i != v.end(); i++) {         if (f1) {           aux1 = i->first;           aux2 = i->second;           contr = aux2;           f1 = false;           for (int k = 0; k < aux1; k++) ans +=  R ;         } else {           if (aux2 > (i->second)) {             cout <<  NO  << endl;             f2 = false;             break;           }           if (aux1 != i->first) {             for (int k = 0; k < contr; k++) ans +=  U ;             contr = 0;           }           contr += (i->second - aux2);           for (int k = aux1; k < i->first; k++) ans +=  R ;           aux1 = i->first;           aux2 = i->second;         }       }       if (f2) {         for (int k = 0; k < contr; k++) ans +=  U ;         cout <<  YES  << endl;         cout << ans << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 5;   const int mod = 998244353;   unsigned long long p[55];   unsigned long long f[55];   int d[55], to[55], used[55];   void upd(unsigned long long &x, unsigned long long y, unsigned long long w) {     if ((double)y * w > 2e18)       x += 2e18;     else       x += y * w;     if (x > 2e18) x = 2e18;   }   int ff(int x) {     if (to[x] != x) to[x] = ff(to[x]);     return to[x];   }   void solve2(int l, int r, unsigned long long id) {     d[l] = r;     memset(to, 0, sizeof(to));     memset(used, 0, sizeof(used));     for (int i = l; i <= r; ++i) to[i] = i;     to[l] = r;     used[r] = 1;     for (int i = l + 1; i <= r; ++i) {       if (i == r) {         for (int j = l; j <= r; ++j) {           if (!used[j]) {             d[i] = j;             return;           }         }       }       unsigned long long w = p[max(r - i - 1, 0)];       for (int j = l; j <= r; ++j) {         if (!used[j] && ff(j) != i) {           if (w < id)             id -= w;           else {             to[i] = j;             d[i] = j;             used[j] = 1;             break;           }         }       }     }   }   void solve(int i, int n, unsigned long long k) {     if (i > n) return;     for (int j = 0; j <= n - i; ++j) {       unsigned long long w = 0;       upd(w, f[n - i - j], p[max(j - 1, 0)]);       if (k < w) {         unsigned long long id = k / f[n - i - j] + 1;         k %= f[n - i - j];         solve2(i, i + j, id);         solve(i + j + 1, n, k);         return;       } else         k -= w;     }   }   int main() {     p[0] = 1;     for (int i = 1; i <= 50; ++i) upd(p[i], p[i - 1], i);     f[0] = 1;     for (int i = 0; i < 50; ++i) {       for (int j = 1; i + j <= 50; ++j) {         upd(f[i + j], f[i], p[max(j - 2, 0)]);       }     }     int t, n;     long long k;     scanf( %d , &t);     while (t--) {       scanf( %d%lld , &n, &k);       if (f[n] < k) {         puts( -1 );         continue;       }       solve(1, n, k - 1);       for (int i = 1; i <= n; ++i) printf( %d  , d[i]);       puts(  );     };     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 22, maxm = (1 << 21) + 5;   int n, plc[maxm];   unsigned long long a[maxm], b[maxm], c[maxn];   char s[maxm];   void FMT(unsigned long long *a, int sgn) {     for (int i = 0; i < n; i++)       for (int j = 0; j < (1 << n); j++)         if (!(j & (1 << i))) a[j | (1 << i)] = a[j | (1 << i)] + sgn * a[j];   }   int main() {     scanf( %d , &n);     plc[0] = 0;     for (int i = 1; i < (1 << n); i++) plc[i] = plc[i >> 1] + ((i & 1) << 1);     scanf( %s , s);     for (int i = 0; i < (1 << n); i++)       a[i] = ((unsigned long long)(s[i] -  0 ) << plc[i]);     scanf( %s , s);     for (int i = 0; i < (1 << n); i++)       b[i] |= ((unsigned long long)(s[i] -  0 ) << plc[i]);     FMT(a, 1);     FMT(b, 1);     for (int i = 0; i < (1 << n); i++) c[i] = a[i] * b[i];     FMT(c, -1);     for (int i = 0; i < (1 << n); i++) printf( %lld , (c[i] >> plc[i]) % 4);     puts(  );     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:60000000 )   using namespace std;   const int MAXN = 10 + 100000;   const int INF = int(1e9);   const int m = 4;   int k, t, d;   int a[5][5], i, j, n;   void nhap() {     scanf( %d , &n);     for (int i = (1), _b = (m); i <= m; ++i)       scanf( %d%d%d%d , &a[i][1], &a[i][2], &a[i][3], &a[i][4]);   }   void xuli() {}   int main() {     nhap();     xuli();     for (int i = (1), _b = (m); i <= m; ++i) {       t = min(a[i][1], a[i][2]);       d = min(a[i][3], a[i][4]);       if (n - t >= d) {         cout << i <<     << t <<     << n - t;         return 0;       }     }     printf( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   using ll = long long;   struct TNode {     int l, r;     ll v;   } t[N << 2];   inline int lc(int pos) { return pos << 1; }   inline int rc(int pos) { return pos << 1 | 1; }   int a[N], n, m;   ll sum[N], lazy[N << 2];   inline void pushup(int pos) { t[pos].v = max(t[lc(pos)].v, t[rc(pos)].v); }   void build(int pos, int l, int r) {     t[pos].l = l;     t[pos].r = r;     if (l == r) {       t[pos].v = a[l] - sum[l - 1];       return;     }     int mid = (l + r) >> 1;     build(lc(pos), l, mid);     build(rc(pos), mid + 1, r);     pushup(pos);   }   inline void pushdown(int pos) {     t[lc(pos)].v += lazy[pos];     t[rc(pos)].v += lazy[pos];     lazy[lc(pos)] += lazy[pos];     lazy[rc(pos)] += lazy[pos];     lazy[pos] = 0;   }   void modify(int pos, int l, int r, int v) {     if (t[pos].l == l && t[pos].r == r) {       t[pos].v += v;       lazy[pos] += v;       return;     }     int mid = (t[pos].l + t[pos].r) >> 1;     pushdown(pos);     if (r <= mid)       modify(lc(pos), l, r, v);     else if (l > mid)       modify(rc(pos), l, r, v);     else       modify(lc(pos), l, mid, v), modify(rc(pos), mid + 1, r, v);     pushup(pos);   }   int query(int pos) {     if (t[pos].v < 0) return -1;     if (t[pos].l == t[pos].r) return t[pos].v ? -1 : t[pos].l;     pushdown(pos);     int ret = query(lc(pos));     if (ret == -1) ret = query(rc(pos));     return ret;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i], sum[i] = sum[i - 1] + a[i];     build(1, 1, n);     int t1, t2;     for (int i = 1; i <= m; i++) {       cin >> t1 >> t2;       t2 = t2 - a[t1];       a[t1] += t2;       modify(1, t1, t1, t2);       if (t1 < n) modify(1, t1 + 1, n, -t2);       cout << query(1) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[5010], b[5010], d[110][110];   double mat[110][110], res[110], flow[110][110], c[5010], ans;   bool used[110];   void input() {     memset(flow, 0x7f, sizeof(flow));     cin >> n >> m;     for (int i = 0; i < m; ++i) {       cin >> a[i] >> b[i] >> c[i];       ++d[a[i]][b[i]], ++d[b[i]][a[i]];       flow[a[i]][b[i]] = flow[b[i]][a[i]] = min(flow[a[i]][b[i]], c[i]);     }   }   bool achievable(int x) {     bool flg = (x == n);     used[x] = 1;     for (int i = 1; i <= n; ++i)       if (!used[i] && d[x][i]) flg |= achievable(i);     return flg;   }   void check() {     if (!achievable(1)) {       for (int i = 0; i <= m; puts( 0.00000 ), ++i)         ;       exit(0);     }   }   void potential() {     res[1] = 1.0, mat[n][n] = 1.0;     for (int i = 1; i < n; ++i) {       if (!used[i]) {         mat[i][i] = 1.0;         continue;       }       for (int j = 1; j <= n; ++j)         if (j != i) mat[i][i] += 1.0 * d[i][j], mat[i][j] -= 1.0 * d[i][j];     }   }   void Gauss() {     for (int i = 1; i <= n; ++i) {       int ind = i;       for (int j = i + 1; j <= n; ++j)         if (((mat[j][i]) > 0 ? (mat[j][i]) : (-mat[j][i])) >             ((mat[ind][i]) > 0 ? (mat[ind][i]) : (-mat[ind][i])))           ind = j;       if (ind != i)         for (int j = i; j <= n; ++j) swap(mat[ind][j], mat[i][j]);       swap(res[ind], res[i]);       for (int j = 1; j <= n; ++j) {         if (i == j) continue;         double ratio = -mat[j][i] / mat[i][i];         for (int k = i; k <= n; ++k) mat[j][k] += ratio * mat[i][k];         res[j] += ratio * res[i];       }     }     for (int i = 1; i <= n; ++i)       if (((mat[i][i]) > 0 ? (mat[i][i]) : (-mat[i][i])) > 1e-8)         res[i] /= mat[i][i];   }   void output() {     ans = 1.0e9;     for (int i = 0; i < m; ++i)       if ((((res[a[i]] - res[b[i]])) > 0 ? ((res[a[i]] - res[b[i]]))                                          : (-(res[a[i]] - res[b[i]]))) > 1e-8)         ans = min(ans, flow[a[i]][b[i]] / (((res[a[i]] - res[b[i]])) > 0                                                ? ((res[a[i]] - res[b[i]]))                                                : (-(res[a[i]] - res[b[i]]))));     cout << fixed << setprecision(9) << ans << endl;     for (int i = 0; i < m; ++i)       cout << fixed << setprecision(9) << (res[a[i]] - res[b[i]]) * ans << endl;   }   int main() {     input();     check();     potential();     Gauss();     output();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, d[40005], v[4005], p[4005], cur, val, use[4005], cnt;   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) cin >> v[i] >> d[i] >> p[i];     for (int i = 1; i <= n; ++i)       if (!use[i]) {         cur = v[i];         for (int j = i + 1; j <= n; ++j)           if (!use[j]) {             if (cur == 0) break;             p[j] -= cur;             cur--;           }         for (int j = i + 1; j <= n; ++j)           if (p[j] < 0 && !use[j]) {             use[j] = 1;             val = d[j];             for (int k = j + 1; k <= n; ++k)               if (!use[k]) {                 p[k] -= val;                 if (p[k] < 0) {                   use[k] = 1;                   val += d[k];                 }               }             break;           }       }     for (int i = 1; i <= n; ++i)       if (p[i] >= 0) cnt++;     cout << cnt << endl;     for (int i = 1; i <= n; ++i)       if (p[i] >= 0) cout << i <<    ;   }


#include <bits/stdc++.h>      using namespace std;      #define inf          1e15   #define mod          1000000007   #define N            100001   #define ll           long long int   #define vint         vector<int>   #define vll          vector<ll>   #define vstr         vector<string>   #define vvint        vector<vector<int> >   #define vvll         vector<vector<ll> >   #define vint_pair    vector<pair<int,int> >   #define input(arr)   for(auto &x:arr) cin>>x;   #define all(x)       (x).begin(), (x).end()   #define rall(x)      (x).rbegin(), (x).rend()      int main() {       ios_base::sync_with_stdio(false);       cin.tie(0);       cout.tie(0);       int t=1;       cin>>t;       while(t--){           int n;           cin>>n;           set<int>num;           vint arr(n);           for(int i=0;i<n;++i){               cin>>arr[i];               num.insert(arr[i]);           }           int vis[n+1];           memset(vis, 0, sizeof(vis));           int l = 1;           for(int i=0;i<n;++i){               if(vis[arr[i]]){                   cout<<l<<   ;                   vis[l] = 1;               }               else{                   cout<<arr[i]<<   ;                   vis[arr[i]] = 1;               }               while(vis[l]){                   ++l;               }           }           cout<<  n ;           set<int>st;           memset(vis, 0, sizeof(vis));           for(int i=1;i<=n;++i){               if(num.find(i)==num.end()){                   st.insert(i);               }           }           for(int i=0;i<n;++i){               if(!vis[arr[i]]){                   cout<<arr[i]<<   ;                   vis[arr[i]] = 1;               }               else{                   auto it = st.lower_bound(arr[i]);                   --it;                   int tmp = *it;                   cout<<tmp<<   ;                   vis[tmp] = 1;                   st.erase(tmp);               }           }           cout<<  n ;       }   }


#include <bits/stdc++.h>   using namespace std;   int sumdigs(int x) {     int c = 0;     while (x) {       c += x % 10;       x /= 10;     }     return c;   }   int main() {     int a;     cin >> a;     if (sumdigs(a) % 4 == 0)       cout << a;     else {       for (int i = a; i < 1000000; i++) {         if (sumdigs(i) % 4 == 0) {           cout << i;           return 0;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e3 + 5;   int n, m, k;   int a[maxn], c[maxn];   int ans, tmp, cnt, rt, sum, ma;   int flag;   char s[maxn];   bool ok[maxn];   vector<int> vc[maxn], vv[maxn];   template <typename T>   inline void read(T &X) {     X = 0;     int w = 0;     char ch = 0;     while (!isdigit(ch)) {       w |= ch ==  - ;       ch = getchar();     }     while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();     if (w) X = -X;   }   pair<int, int> query(int id) {     printf( ? %d , vv[id].size());     for (int i = 0; i < vv[id].size(); i++) {       printf(  %d , vv[id][i]);     }     puts(  );     fflush(stdout);     int x, y;     read(x);     read(y);     return make_pair(x, y);   }   void dfs(int u, int fa, int dep) {     ma = max(ma, dep);     vv[dep].push_back(u);     for (int i = 0; i < vc[u].size(); i++) {       int v = vc[u][i];       if (v == fa) continue;       dfs(v, u, dep + 1);     }   }   int jud(int as) {     pair<int, int> k = query(as);     if (k.second > sum) return 1;     rt = k.first;     return 0;   }   int main() {     int T, cas = 1;     cin >> T;     while (T--) {       read(n);       ans = 0;       for (int i = (0); i <= (n + 1); i++) {         vc[i].clear();         vv[i].clear();       }       for (int i = (1); i <= (n - 1); i++) {         int x, y;         read(x);         read(y);         vc[x].push_back(y);         vc[y].push_back(x);         vv[n + 1].push_back(i);       }       vv[n + 1].push_back(n);       pair<int, int> tp = query(n + 1);       rt = tp.first;       sum = tp.second;       ma = 0;       dfs(rt, -1, 0);       ma = min(ma, sum);       int l = (sum + 1) / 2, r = ma + 1, tmp;       while (l < r) {         int mid = (l + r) >> 1;         if (jud(mid)) {           r = mid;         } else {           l = mid + 1;           tmp = mid;         }       }       for (int i = (0); i <= (n); i++) vv[i].clear();       dfs(rt, -1, 0);       tp = query(sum);       printf( ! %d %d n , rt, tp.first);       fflush(stdout);       scanf( %s , s);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void si(T &x) {     register int c = getchar();     x = 0;     int neg = 0;     for (; ((c<48 | c> 57) && c !=  - ); c = getchar())       ;     if (c ==  - ) {       neg = 1;       c = getchar();     }     for (; c > 47 && c < 58; c = getchar()) {       x = (x << 1) + (x << 3) + c - 48;     }     if (neg) x = -x;   }   long long bigmod(long long p, long long e, long long M) {     long long ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % M;       p = (p * p) % M;     }     return ret;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long modinverse(long long a, long long M) { return bigmod(a, M - 2, M); }   void io() { freopen( /Users/MyMac/Desktop/in.txt ,  r , stdin); }   const int N = 1e6 + 6;   long long nxt[N];   const long long MOD = 1e9 + 7;   bool vis[N];   void dfs(int u) {     if (vis[u]) return;     vis[u] = 1;     dfs(nxt[u]);   }   int main() {     long long p, k;     cin >> p >> k;     if (k == 0) {       long long ans = 1;       for (int i = 0; i < p - 1; i++) {         ans *= p;         ans %= MOD;       }       cout << ans << endl;       return 0;     }     if (k == 1) {       long long ans = 1;       for (int i = 0; i < p; i++) {         ans *= p;         ans %= MOD;       }       cout << ans << endl;       return 0;     }     for (long long i = 0; i < p; i++) {       nxt[i * k % p] = i;     }     long long ans = 1;     for (int i = 1; i < p; i++) {       if (vis[i] == 0) {         dfs(i);         ans *= p;         ans %= MOD;       }     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3F3F3F3F;   const long long INF_LL = 0x3F3F3F3F3F3F3F3FLL;   const int N = 4e5 + 50;   bool check(const string &s, const string &t) {     int match = 0;     for (int i = 0; i < s.size() && match < t.size(); ++i) {       if (s[i] == t[match]) ++match;     }     return match == t.size();   }   int main() {     string s, t;     cin >> s >> t;     int ans = 0;     for (int i = 0; i < int(s.size()); ++i) {       for (int j = i; j < int(s.size()); ++j) {         string tmp = s;         tmp.erase(tmp.begin() + i, tmp.begin() + j + 1);         if (check(tmp, t)) ans = max(ans, j - i + 1);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 10, LOG = 20;   int n, q, F[N], T[N], P[N], D[N], Par[LOG][N];   pair<int, int> Q[N];   vector<int> Adj[N], Ap[N], V[N << 2];   void Pre(int v) {     for (int i = 1; i < LOG; i++) Par[i][v] = Par[i - 1][Par[i - 1][v]];     for (auto X : Adj[v])       if (X != Par[0][v]) Par[0][X] = v, D[X] = D[v] + 1, Pre(X);   }   int LCA(int v, int u) {     if (D[v] < D[u]) return (LCA(u, v));     for (int i = 0; i < LOG; i++)       if ((D[v] - D[u]) & (1 << i)) v = Par[i][v];     if (v == u) return (v);     for (int i = LOG - 1; ~i; i--)       if (Par[i][v] != Par[i][u]) v = Par[i][v], u = Par[i][u];     return (Par[0][v]);   }   int Dist(int v, int u) { return (D[v] + D[u] - 2 * D[LCA(v, u)]); }   int Find(int v) {     if (P[v] < 0) return (v);     return (Find(P[v]));   }   void Add(int i, int le, int ri, int id = 1, int l = 0, int r = q + 2) {     if (ri <= l || r <= le) return;     if (le <= l && r <= ri) {       V[id].push_back(i);       return;     }     Add(i, le, ri, id * 2, l, (l + r) >> 1);     Add(i, le, ri, id * 2 + 1, (l + r) >> 1, r);   }   void DFS(int id, int l = 0, int r = q + 2) {     vector<pair<int, pair<int, int> > > Op;     for (auto i : V[id])       if (Find(F[i]) != Find(T[i])) {         int v = Find(F[i]), u = Find(T[i]);         if (P[v] > P[u]) swap(v, u);         Op.push_back({u, {v, P[u]}});         P[v] += P[u];         P[u] = v;       }     if (r - l == 1)       if (Q[l].first > 0) {         if (Find(Q[l].first) == Find(Q[l].second))           printf( %d n , Dist(Q[l].first, Q[l].second));         else           puts( -1 );       }     if (r - l > 1) DFS(id * 2, l, (l + r) >> 1), DFS(id * 2 + 1, (l + r) >> 1, r);     reverse(Op.begin(), Op.end());     for (auto X : Op)       P[X.first] = X.second.second, P[X.second.first] -= P[X.first];   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++)       scanf( %d%d , &F[i], &T[i]), Ap[i].push_back(0), Adj[F[i]].push_back(T[i]),           Adj[T[i]].push_back(F[i]);     scanf( %d , &q);     int tp, v, u;     for (int i = 1; i <= q; i++) {       scanf( %d%d , &tp, &v);       if (tp < 3)         Ap[v].push_back(i);       else         scanf( %d , &u), Q[i] = {v, u};     }     for (int i = 1; i < n; i++) {       Ap[i].push_back(q + 1);       for (int j = 1; j < Ap[i].size(); j += 2) Add(i, Ap[i][j - 1], Ap[i][j]);     }     memset(P, -1, sizeof(P));     Pre(1);     DFS(1);     return (0);   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   template <class T>   void chkmin(T &x, const T &y) {     if (y < x) {       x = y;     }   }   template <class T>   void chkmax(T &x, const T &y) {     if (y > x) {       x = y;     }   }   template <class T>   void sort(vector<T> &a) {     sort(a.begin(), a.end());   }   template <class T, class Cmp>   void sort(vector<T> &a, Cmp cmp) {     sort(a.begin(), a.end(), cmp);   }   template <class T>   void unique(vector<T> &a) {     a.resize(unique(a.begin(), a.end()) - a.begin());   }   int readInt() {     int x = 0;     char c = getchar();     while (!isdigit(c)) {       c = getchar();     }     while (isdigit(c)) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x;   }   string readString() {     string s;     char c = getchar();     while (isspace(c)) {       c = getchar();     }     while (!isspace(c)) {       s += c;       c = getchar();     }     return s;   }   void solve_single_test(int test_id = 1) {     int a = readInt();     int b = readInt();     int n = a + b;     int ans = 0;     for (int l = 1, r; l <= n; l = r + 1) {       int t = n / l;       r = n / t;       if ((a + t) / (t + 1) > a / t || (b + t) / (t + 1) > b / t) {         continue;       }       int L = max(l, (a + t) / (t + 1) + (b + t) / (t + 1));       int R = min(r, a / t + b / t) + 1;       if (L < R) {         ans += R - L;       }     }     printf( %d n , ans);   }   void solve_multiple_tests() {     int n_tests;     scanf( %d , &n_tests);     for (int i = 1; i <= n_tests; ++i) {       solve_single_test(i);     }   }   int main() {     solve_single_test();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, i, k, u, v, cnt;   int head[300005], a[300005];   long long f[300005], ans;   struct ff {     int to, nxt;   } e[2 * 300005];   int fast() {     int res = 0, fl = 1;     char c = getchar();     while (c < 48 || c > 57) {       if (c ==  - ) fl = -1;       c = getchar();     }     while (c >= 48 && c <= 57) res = res * 10 + c - 48, c = getchar();     return res * fl;   }   void write(long long x) {     if (x > 9) write(x / 10);     putchar(x % 10 + 48);   }   void add(int u, int v) {     e[++cnt] = (ff){v, head[u]};     head[u] = cnt;   }   void dfs(int now, int fa, int fl) {     f[now] = a[now];     for (int i = head[now]; i; i = e[i].nxt) {       int v = e[i].to;       if (v == fa) continue;       dfs(v, now, fl);       if (f[v] > 0) f[now] += f[v];     }     if (fl)       ans = max(ans, f[now]);     else if (ans == f[now])       k++, f[now] = -1;   }   int main() {     n = fast();     for (i = 1; i <= n; i++) a[i] = fast();     for (i = 1; i < n; i++) {       u = fast(), v = fast();       add(u, v), add(v, u);     }     ans = -(long long)1e16;     dfs(1, 0, 1);     dfs(1, 0, 0);     printf( %lld %d n , ans * k, k);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     bool flag = true;     while (cin >> n >> m) {       for (int i = 0; i < n; i++) {         for (int j = 1; j <= m; j++) {           if (i % 2 && j < m && flag)             cout <<  . ;           else if (i % 2 && j == m && flag)             cout <<  # ;           else if (i % 2 && j == 1 && !flag)             cout <<  # ;           else if (i % 2 && j > 1 && !flag)             cout <<  . ;           else             cout <<  # ;         }         if (i % 2) flag = !flag;         cout <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int max_x = 1000, inf = 1000111222;   const int max_bal = 2222;   const int sd = max_bal / 2;   int a;   pair<int, pair<int, int>> par[max_x][max_bal];   bool dp[max_x][max_bal];   int get_sum(int x) {     int sum = 0;     while (x) {       sum += x % 10;       x /= 10;     }     return sum;   }   int main() {     cin >> a;     queue<pair<int, int>> q;     dp[0][sd] = 1;     q.push({0, sd});     while (!q.empty()) {       pair<int, int> p = q.front();       q.pop();       for (int d = 0; d <= 9; ++d) {         int y = p.first + a * d;         int to = y / 10;         int w = d - a * (y % 10);         if (p.second + w >= 0 && p.second + w < max_bal &&             !dp[to][p.second + w]) {           dp[to][p.second + w] = 1;           par[to][p.second + w] = {d, p};           q.push({to, p.second + w});         }       }     }     for (int i = 1; i < max_x; ++i) {       int need = get_sum(i) * a + sd;       if (need < max_bal && dp[i][need]) {         string ans;         int x = i, bal = need;         while (x != 0 || bal != sd) {           ans +=  0  + par[x][bal].first;           if (ans ==  0 ) {             ans =   ;           }           int nx = par[x][bal].second.first;           int nbal = par[x][bal].second.second;           x = nx;           bal = nbal;         }         cout << ans << endl;         return 0;       }     }     cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int INF = 1000000000;   vector<vector<int> > v;   int* dist;   void bfs(int ver, int n) {     bool vis[n];     for (int i = 0; i < n; i++) vis[i] = false;     vis[ver] = true;     queue<pair<int, int> > q;     q.push(make_pair(ver, 0));     while (!q.empty()) {       pair<int, int> p = q.front();       q.pop();       int a = p.first, b = p.second;       dist[a] = b;       for (int i = 0; i < v[a].size(); i++) {         if (vis[v[a][i]] == false) {           vis[v[a][i]] = true;           q.push(make_pair(v[a][i], b + 1));         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int n, m;     cin >> n >> m;     vector<vector<int> > vt(n);     v = vt;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       x -= 1;       y -= 1;       v[y].push_back(x);       vt[x].push_back(y);     }     int k;     cin >> k;     vector<int> path(k);     for (int i = 0; i < k; i++) {       int x;       cin >> x;       x -= 1;       path[i] = x;     }     dist = new int[n];     bfs(path[k - 1], n);     vector<pair<int, int> > pos(k, make_pair(0, 0));     for (int i = 1; i < k; i++) {       int ver = path[i - 1], pver = path[i];       vector<pair<int, int> > t;       for (int j = 0; j < vt[ver].size(); j++)         t.push_back(make_pair(dist[vt[ver][j]], vt[ver][j]));       int md = t[0].first;       for (int j = 1; j < t.size(); j++) md = min(md, t[j].first);       for (int j = 0; j < t.size(); j++) {         if (t[j].first == md and t[j].second == pver) pos[i].first = 1;         if (t[j].first == md and t[j].second != pver) pos[i].second = 1;       }     }     int mans = 0, Mans = 0;     for (int i = 1; i < k; i++) {       if (pos[i].first != 1) mans += 1;       if (pos[i].second == 1) Mans += 1;     }     cout << mans <<     << Mans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int arr[100005];   int ans[100005][3], alen;   struct node {     int n, cnt;     bool friend operator<(node a, node b) { return a.cnt < b.cnt; }   } n1, n2, n3;   priority_queue<node> qu;   int blen = 0;   int main() {     scanf( %d , &n);     int i, j;     for (i = 0; i < n; i++) scanf( %d , arr + i);     sort(arr, arr + n);     n1.n = arr[0];     n1.cnt = 1;     for (i = 1; i < n; i++) {       if (arr[i] == arr[i - 1]) {         n1.cnt++;       } else {         qu.push(n1);         n1.cnt = 1;         n1.n = arr[i];       }     }     qu.push(n1);     while (qu.size() > 2) {       n1 = qu.top();       qu.pop();       n2 = qu.top();       qu.pop();       n3 = qu.top();       qu.pop();       ans[alen][0] = n1.n;       ans[alen][1] = n2.n;       ans[alen][2] = n3.n;       sort(ans[alen], ans[alen] + 3);       alen++;       n1.cnt--;       n2.cnt--;       n3.cnt--;       if (n1.cnt != 0) qu.push(n1);       if (n2.cnt != 0) qu.push(n2);       if (n3.cnt != 0) qu.push(n3);     }     printf( %d n , alen);     for (i = 0; i < alen; i++) {       for (j = 2; j > 0; j--) {         printf( %d  , ans[i][j]);       }       printf( %d n , ans[i][0]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n = 6;     int x, f[12] = {0};     for (int i = 0; i < n; i++) {       cin >> x;       f[x]++;     }     bool res = 0;     for (int i = 0; i < 10; i++) {       if (f[i] >= 4) {         res = 1;         f[i] -= 4;         for (int j = 0; j < 10; j++) {           if (f[j] == 2) {             cout <<  Elephant n ;             return 0;           } else if (f[j]) {             cout <<  Bear n ;             return 0;           }         }       }     }     cout <<  Alien n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m = 0, m1 = 0, l, q[1000], t;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> q[i];     }     cin >> t;     sort(q, q + n);     for (int i = 0; i < n; i++) {       l = 1;       for (int j = i + 1; j < n; j++) {         if (q[j] - q[i] <= t) l++;       }       if (l > m) m = l;     }     cout << m;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void debug_out() { cerr <<   n ; }   template <typename H, typename... T>   void debug_out(H h, T... t) {     cerr <<     << (h);     debug_out(t...);   }   int n;   string a, b;   char flip(char ch) { return (char)( 0  + ( 1  - ch)); }   char ch(int i, int cnt) { return (char)( 0  + ((a[i] -  0  + cnt) % 2)); }   void solve() {     cin >> n >> a >> b;     vector<int> res;     int first = 0;     int last = n - 1;     int cnt = 0;     for (int i = n - 1; i >= 0; i--) {       if (ch(last, cnt) != b[i]) {         if (ch(first, cnt) == b[i]) {           res.push_back(1);           a[first] = flip(a[first]);         }         if (i or ch(first, cnt) != b[i]) {           res.push_back(i + 1);           cnt++;           swap(first, last);         }       }       if (cnt % 2) {         last++;       } else {         last--;       }     }     cout << res.size();     for (auto i : res) cout <<     << i;     cout <<   n ;   }   int main() {     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n < 998)       cout << n + 2;     else       cout << n - 2;   }


#include <bits/stdc++.h>   using namespace std;   struct Edge {     int u, v, w;   };   const int N = 500005;   int n, m, q;   Edge edge[N];   vector<int> sorted_edge[N];   vector<pair<int, vector<int>>> query[N];   bool npos[N];   int par[N], rnk[N];   vector<int> rnk_roll, par_roll;   void init() {     for (int i = 1; i <= n; i++) par[i] = i, rnk[i] = 1;   }   int get(int u, bool roll = false) {     if (u == par[u]) return u;     if (roll) return get(par[u], roll);     return par[u] = get(par[u], roll);   }   bool merge(int u, int v, bool roll = false) {     u = get(u, roll), v = get(v, roll);     if (u == v) return false;     if (rnk[u] < rnk[v]) swap(u, v);     if (roll) par_roll.push_back(v);     par[v] = u;     if (rnk[u] == rnk[v]) {       rnk[u]++;       rnk_roll.push_back(u);     }     return true;   }   void rollback() {     for (auto u : rnk_roll) rnk[u]--;     for (auto u : par_roll) par[u] = u;     rnk_roll.clear();     par_roll.clear();   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &edge[i].u, &edge[i].v, &edge[i].w);       sorted_edge[edge[i].w].push_back(i);     }     scanf( %d , &q);     for (int i = 0, k; i < q; i++) {       scanf( %d , &k);       vector<int> elt(k);       for (int i = 0; i < k; i++) scanf( %d , &elt[i]);       sort(elt.begin(), elt.end(),            [](int i, int j) { return edge[i].w < edge[j].w; });       int it = 0, j;       do {         vector<int> ei;         for (j = it; j < k && edge[elt[j]].w == edge[elt[it]].w; j++)           ei.push_back(elt[j]);         query[edge[elt[it]].w].push_back({i, ei});         it = j;       } while (it < k);     }     init();     for (int i = 1; i < N; i++) {       for (auto qq : query[i]) {         int qid = qq.first;         for (auto e : qq.second) {           if (!merge(edge[e].u, edge[e].v, true)) {             npos[qid] = true;             break;           }         }         rollback();       }       for (auto e : sorted_edge[i]) merge(edge[e].u, edge[e].v);     }     for (int i = 0; i < q; i++) {       printf( %s n , npos[i] ?  NO  :  YES );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long points[1002][2];   long long circle[1002][3];   vector<long long> tree[1002];   bool mark[1002];   vector<long long> paths[1002];   long long inside[1002];   long long dist2(long long a, long long b, long long c, long long d) {     return (a - c) * (a - c) + (b - d) * (b - d);   }   void dfs(long long v, long long parent) {     mark[v] = 1;     if (parent != -1) paths[v] = paths[parent];     paths[v].push_back(v);     for (long long i = 0; i < tree[v].size(); i++)       if (!mark[tree[v][i]]) dfs(tree[v][i], v);   }   int main() {     long long n, m, k, a, b, p;     cin >> n >> m >> k;     for (long long i = 0; i < n; i++) cin >> points[i][0] >> points[i][1];     for (long long i = 0; i < m; i++)       cin >> circle[i][0] >> circle[i][1] >> circle[i][2];     for (long long i = 0; i < m; i++) {       long long parent = m;       long long min_radius = 2000000000;       for (long long j = 0; j < m; j++) {         if (circle[j][0] <= circle[i][0]) continue;         if (dist2(circle[i][1], circle[i][2], circle[j][1], circle[j][2]) >             circle[j][0] * circle[j][0])           continue;         if (min_radius > circle[j][0]) {           parent = j;           min_radius = circle[j][0];         }       }       tree[parent].push_back(i);     }     for (long long i = 0; i < n; i++) {       long long parent = m;       long long min_radius = 2000000000;       for (long long j = 0; j < m; j++) {         if (dist2(points[i][0], points[i][1], circle[j][1], circle[j][2]) >             circle[j][0] * circle[j][0])           continue;         if (min_radius > circle[j][0]) {           parent = j;           min_radius = circle[j][0];         }       }       inside[i] = parent;     }     dfs(m, -1);     for (long long i = 0; i < k; i++) {       cin >> a >> b;       a = inside[a - 1];       b = inside[b - 1];       p = 0;       while (p < min(paths[a].size(), paths[b].size()) &&              paths[a][p] == paths[b][p])         p++;       cout << (long long)paths[a].size() + (long long)paths[b].size() - p - p            << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod(long long x, long long MOD) {     if (x > MOD) x -= MOD;     return x;   }   long long _ceil(long long x, long long y) { return x / y + (x % y != 0); }   void wrt() {     cout <<   n ;     return;   }   template <typename T1, typename... T2>   void wrt(T1 x, T2... args) {     ((cout << x <<    ), wrt(args...));   }   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& v) {     for (auto& i : v) os << i <<    ;     return os;   }   template <typename T>   istream& operator>>(istream& in, vector<T>& v) {     for (auto& e : v) in >> e;     return in;   }   const long long MOD = 998244353;   const long long N = 1e6 + 5, inf = 1e18 + 2;   long long n, m, x, u, v, k, p, q, i, j;   string s, t;   long long ans;   long long a[N];   vector<long long> arr(7, 0);   bool f(long long i, long long j, long long k) {     long long x;     vector<long long> res;     res.push_back(arr[i]);     res.push_back(arr[j]);     res.push_back(arr[k]);     res.push_back(arr[i] + arr[j]);     res.push_back(arr[j] + arr[k]);     res.push_back(arr[i] + arr[k]);     res.push_back(arr[i] + arr[j] + arr[k]);     sort((res).begin(), (res).end());     for (long long i = 0; i < (((long long)(res).size())); ++i) {       if (res[i] != arr[i]) return false;     }     return true;   }   void solve() {     for (long long i = 0; i < (7); ++i) arr[i] = 0;     cin >> arr;     sort((arr).begin(), (arr).end());     for (long long i = 0; i < (7); ++i) {       for (long long j = (i + 1); j < (7); ++j) {         for (long long k = (j + 1); k < (7); ++k) {           if (f(i, j, k)) {             wrt(arr[i], arr[j], arr[k]);             return;           }         }       }     }   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T INT_LEN(T v) {     int len = 1;     while (v /= 10) ++len;     return len;   }   int t1, t2, x1, x2, t0;   int less_than(double va, double vb) { return va <= vb + 1e-10; }   int binary_found(int lt, int rt, int y2, double &pre) {     int y1;     bool flag = false;     double t;     while (lt <= rt) {       y1 = (lt + rt) >> 1;       t = ((double)t1 * y1 + (double)t2 * y2) / (y1 + y2);       if (t >= t0)         lt = -~y1;       else         rt = ~-y1;     }     t = ((double)t1 * rt + (double)t2 * y2) / (rt + y2);     if (less_than(fabs(t - t0), fabs(pre - t0))) {       flag = true;       pre = t;     }     return flag ? rt : -1;   }   void solve() {     int i, j, mx = 0;     int y1, y2;     if (t1 == t2)       printf( %d %d n , x1, x2);     else if (t0 == t1)       printf( %d %d n , x1, 0);     else if (t0 == t2)       printf( %d %d n , 0, x2);     else {       double pre = t2;       y2 = 0;       for (i = 1; i <= x2; i++) {         j = binary_found(0, x1, i, pre);         if (~j && i + j > mx) {           mx = i + j;           y1 = j;           y2 = i;         }       }       printf( %d %d n , y1, y2);     }   }   int main(void) {     while (5 == scanf( %d%d%d%d%d , &t1, &t2, &x1, &x2, &t0)) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   inline void gn(long long &first) {     int sg = 1;     char c;     while (((c = getchar()) <  0  || c >  9 ) && c !=  - )       ;     c ==  -  ? (sg = -1, first = 0) : (first = c -  0 );     while ((c = getchar()) >=  0  && c <=  9 ) first = first * 10 + c -  0 ;     first *= sg;   }   inline void gn(int &first) {     long long t;     gn(t);     first = t;   }   inline void gn(unsigned long long &first) {     long long t;     gn(t);     first = t;   }   inline void gn(double &first) {     double t;     scanf( %lf , &t);     first = t;   }   inline void gn(long double &first) {     double t;     scanf( %lf , &t);     first = t;   }   int power(int a, int b, int m, int ans = 1) {     for (; b; b >>= 1, a = 1LL * a * a % m)       if (b & 1) ans = 1LL * ans * a % m;     return ans;   }   int main() {     long long k, b, n, t, m;     scanf( %I64d%I64d%I64d%I64d , &k, &b, &n, &t);     if (k == 1) {       m = n - (t - 1) / b;       if (m < 0) m = 0;       cout << m << endl;       return 0;     }     double u = 1.0 * (t - t * k - b) / (1 - k - b);     double v = log(u) / log(1.0 * k);     m = n - floor(v);     if (m < 0) m = 0;     printf( %I64d n , m);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 5;   const long long MOD = 998244353;   int n, k;   vector<int> a, b;   long long ans[MAXN][3][5];   bool found[MAXN][3][5];   long long mul(long long a, long long b) { return (a * b) % MOD; }   long long dp(int pos, int last, int var) {     if (pos == 1) return (last == 1) ? 1LL : 0LL;     if (found[pos][last][var]) return ans[pos][last][var];     found[pos][last][var] = true;     ans[pos][last][var] = 0LL;     for (int i = 0; i < var; ++i)       if (last == 0 || i != last) {         long long koef = 1;         if (i == 0) koef = k - var + 1;         if (last == 0 && i == 0) koef--;         koef = max(koef, 0LL);         ans[pos][last][var] =             (ans[pos][last][var] + mul(dp(pos - 1, i, var), koef)) % MOD;       }     return ans[pos][last][var];   }   long long calc(const vector<int> &A) {     vector<pair<int, int> > fixed;     fixed.push_back(pair<int, int>(0, -1));     for (int i = 0; i < A.size(); ++i) {       if (A[i] != -1) {         fixed.push_back(pair<int, int>(A[i], i));       }     }     fixed.push_back(pair<int, int>(0, A.size()));     long long tmpAns = 1LL;     for (int i = 0; i < fixed.size() - 1; ++i) {       int l = fixed[i].second, r = fixed[i + 1].second;       if (fixed[i].first == 0 && fixed[i + 1].first == 0) {         tmpAns = mul(tmpAns, k);         for (int j = l + 2; j < r; ++j) tmpAns = mul(tmpAns, k - 1);       } else if (fixed[i].first == 0 || fixed[i + 1].first == 0) {         for (int j = l + 1; j < r; ++j) tmpAns = mul(tmpAns, k - 1);       } else {         if (A[l] == A[r]) {           tmpAns = mul(tmpAns, dp(r - l + 1, 1, 2));         } else {           tmpAns = mul(tmpAns, dp(r - l + 1, 2, 3));         }       }     }     return tmpAns;   }   int main() {     scanf( %d %d , &n, &k);     for (int i = 0; i < n; ++i) {       int tmp;       scanf( %d , &tmp);       if (i % 2)         a.push_back(tmp);       else         b.push_back(tmp);     }     printf( %lld n , mul(calc(a), calc(b)));   }


#include <bits/stdc++.h>   using namespace std;   void FastIO() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);   }   stack<pair<int, int> > stk;   string ip;   int length;   int main() {     FastIO();     cin >> ip;     length = ip.length();     int prev[length + 10], open[length + 10];     pair<int, int> ppp;     memset(open, 0, sizeof(open));     if (ip[0] ==  [ ) open[0]++;     for (int i = 1; i < length; i++) {       open[i] = open[i - 1];       if (ip[i] ==  [ ) open[i]++;     }     for (int i = 0; i < length; i++) {       prev[i] = -1;       if (ip[i] ==  ( )         stk.push(make_pair(1, i));       else if (ip[i] ==  [ )         stk.push(make_pair(2, i));       else if (ip[i] ==  ]  && !stk.empty()) {         ppp = stk.top();         if (ppp.first != 2) {           stk.push(make_pair(-1, -1));         }         if (ppp.first == 2) {           stk.pop();           prev[i] = ppp.second;         }       } else if (ip[i] ==  )  && !stk.empty()) {         ppp = stk.top();         if (ppp.first != 1) {           stk.push(make_pair(-1, -1));         }         if (ppp.first == 1) {           stk.pop();           prev[i] = ppp.second;         }       }     }     string anssubsr;     int ans = 0, t;     for (int i = 0; i < length; i++) {       if (prev[i] != -1) {         t = prev[i];         while (prev[t - 1] != -1 && t > 0) {           t = prev[t - 1];           if (t <= 0) break;         }         prev[i] = t;       }     }     int at, from;     for (int i = 0; i < length; i++) {       if (prev[i] != -1) {         t = prev[i];         prev[i]--;         if (prev[i] >= 0) open[i] -= open[prev[i]];         if (open[i] > ans) {           ans = open[i];           from = t;           at = i;         }       }     }     if (ans != 0) {       cout << ans << endl;       for (int k = from; k <= at; k++) cout << ip[k];       cout << endl;     } else       cout << 0 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, i;     cin >> t;     while (t--) {       int flag = 0;       string s, t, p;       cin >> s >> t >> p;       int a[26] = {0};       if (s.length() > t.length()) {         flag = 0;       } else {         for (i = 0; i < min(t.length(), s.length()) + 1; i++) {           if (s[i] != t[i]) {             for (int j = 0; j < p.length(); j++) {               if (p[j] == t[i]) {                 string d =   ;                 d = d + p[j];                 s.insert(i, d);                 p.erase(p.begin() + j);                 flag = 0;                 break;               }             }             if (flag == 1) {               cout <<  NO n ;               break;             }           }         }       }       if (s == t && flag == 0)         cout <<  YES n ;       else if (flag == 0)         cout <<  NO n ;     }   }


#include <bits/stdc++.h>   using namespace std;   struct Maxflow {     static const int MAXV = 20010;     long long INF = 1000000000000000ll;     struct Edge {       int v, r;       long long c;       Edge(int _v, long long _c, int _r) : v(_v), c(_c), r(_r) {}     };     int s, t;     vector<Edge> G[MAXV * 2];     int iter[MAXV * 2], d[MAXV * 2], gap[MAXV * 2], tot;     void init(int x) {       tot = x + 2;       s = x + 1, t = x + 2;       for (int i = 0; i <= tot; i++) {         G[i].clear();         iter[i] = d[i] = gap[i] = 0;       }     }     void addEdge(int u, int v, long long c) {       G[u].push_back(Edge(v, c, ((int)(G[v]).size())));       G[v].push_back(Edge(u, 0, ((int)(G[u]).size()) - 1));     }     long long dfs(int p, long long flow) {       if (p == t) return flow;       for (int &i = iter[p]; i < ((int)(G[p]).size()); i++) {         Edge &e = G[p][i];         if (e.c > 0 && d[p] == d[e.v] + 1) {           long long f = dfs(e.v, min(flow, e.c));           if (f) {             e.c -= f;             G[e.v][e.r].c += f;             return f;           }         }       }       if ((--gap[d[p]]) == 0)         d[s] = tot;       else {         d[p]++;         iter[p] = 0;         ++gap[d[p]];       }       return 0;     }     long long solve() {       long long res = 0;       gap[0] = tot;       for (res = 0; d[s] < tot; res += dfs(s, INF))         ;       return res;     }   } flow;   int n, m;   int main() {     cin >> n >> m;     flow.init(n + m + 5);     for (int i = 1; i <= n; i++) {       long long f;       scanf( %lld , &f);       flow.addEdge(m + i, flow.t, f);     }     long long tot = 0;     for (int i = 1; i <= m; i++) {       int x, y;       long long f;       scanf( %d%d%lld , &x, &y, &f);       flow.addEdge(flow.s, i, f);       flow.addEdge(i, m + x, flow.INF);       flow.addEdge(i, m + y, flow.INF);       tot += f;     }     printf( %lld n , tot - flow.solve());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long M = 1e8;   int main() {     long long n, i, j;     cin >> n;     vector<long long> ara;     for (i = 0; i < n; i++) {       cin >> j;       ara.push_back(j);     }     long long pre1[n + 1];     long long pre2[n + 1];     pre1[0] = 0;     pre2[0] = 0;     for (i = 1; i <= n; i++) pre1[i] = pre1[i - 1] + ara[i - 1];     sort(ara.begin(), ara.end());     for (i = 1; i <= n; i++) pre2[i] = pre2[i - 1] + ara[i - 1];     long long t;     cin >> t;     while (t--) {       long long l, h, type, ans = 0;       cin >> type >> l >> h;       if (type == 1) {         ans = pre1[h] - pre1[l - 1];       } else         ans = pre2[h] - pre2[l - 1];       cout << ans << endl;     }     return 0;   }