#include <bits/stdc++.h>   using namespace std;   double n, sum = 0;   int a[21], b[21];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       cin >> b[i];     }     for (int i = 0; i < 1000000; i++) {       for (int j = 0; j < n; j++) {         if (i % a[j] == b[j]) {           sum++;           break;         }       }     }     printf( %.6f , (double)sum / 1000000.0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxc = 1000000000;   int main() {     long long n, k, l, r;     scanf( %lld%lld%lld%lld , &n, &l, &r, &k);     long long d = r - l + 1;     if (l > r) {       d = n - l + 1 + r;     }     if (d == n) {       long long ans = -1;       for (long long i = 1; i * i <= k + 1; i++) {         if (k % i == 0) {           if (i >= n && i <= 2 * n) ans = max(ans, i - n);           if (k / i >= n && k / i <= 2 * n) ans = max(ans, k / i - n);         }         if ((k + 1) % i == 0) {           if (i > n && i <= 2 * n) ans = max(ans, i - n);           if ((k + 1) / i > n && (k + 1) / i <= 2 * n)             ans = max(ans, (k + 1) / i - n);         }       }       printf( %lld n , ans);       return 0;     }     if (n < 3e7) {       long long ans = -1;       for (int i = 0; i <= n; i++) {         long long res = k % (n + i);         if (res < d) continue;         if (res > 2 * d) continue;         long long u = res - d;         if (u > i) continue;         long long uu = i - u;         if (n - d < uu - 1) continue;         ans = i;       }       printf( %lld n , ans);       return 0;     }     long long best = -1;     for (int cyc = 0; cyc < 5000; cyc++) {       long long l = -1, r = 1e12;       long long lo = 0, hi = n + 1;       while (lo != hi) {         long long mid = (lo + hi) / 2;         int ok = 1;         if (k / (n + mid) > cyc) ok = 0;         long long res = k - (long long)cyc * (n + mid);         if (res > 2 * d) ok = 0;         if (res > d + mid) ok = 0;         if (ok)           hi = mid;         else           lo = mid + 1;       }       l = lo;       lo = -1, hi = n + 1;       while (lo != hi) {         long long mid = (lo + hi + 1) / 2;         int ok = 1;         if (k / (n + mid) < cyc) ok = 0;         long long res = k - (long long)cyc * (n + mid);         if (res < d) ok = 0;         long long need = max(0ll, mid - (n - d) - 1);         if (cyc == 0 && mid == 5) ( ! %lld %lld n , need, res);         if (res < d + need) ok = 0;         if (ok)           lo = mid;         else           hi = mid - 1;       }       r = lo;       if (l == n + 1 || k < (long long)cyc * n) r = -1;       ( cyc %d l %lld r %lld n , cyc, l, r);       if (l > r) continue;       best = max(best, r);       ;     }     printf( %lld n , best);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   signed main() {     int a, b, c, d, e, f;     cin >> a >> b >> c >> d >> e >> f;     int ans = 0;     if (e >= f) {       int dec = min(a, d);       a -= dec;       d -= dec;       ans += dec * e;       ans += min(min(b, c), d) * f;     } else {       int dec = min(min(b, c), d);       b -= dec, c -= dec, d -= dec;       ans += dec * f;       ans += min(a, d) * e;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7;   template <class T>   T ABS(const T& x) {     return x > 0 ? x : -x;   }   long long int gcd(long long int n1, long long int n2) {     return n2 == 0 ? ABS(n1) : gcd(n2, n1 % n2);   }   long long int lcm(long long int n1, long long int n2) {     return n1 == 0 && n2 == 0 ? 0 : ABS(n1 * n2) / gcd(n1, n2);   }   long long int ceil2(long long int a, long long int b) {     return (a + b - 1) / b;   }   int n;   void divisors(vector<int>& d) {     vector<int> v;     for (int i = 1; i <= sqrt(n); ++i) {       if (n % i == 0) {         if (n / i == i) {           d.push_back(i);         } else {           d.push_back(i);           v.push_back(n / i);         }       }     }     for (int i = v.size() - 1; i >= 0; --i) {       d.push_back(v[i]);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     int arr[n];     for (int i = 0; i < (n); ++i) {       cin >> arr[i];     }     vector<int> d;     divisors(d);     bool v[n];     for (int i = d.size() - 1; i >= 0; --i) {       int size = n / d[i];       if (size < 3) continue;       memset(v, false, sizeof(v));       int k = d[i], cnt = 0;       for (int l = 0; l < n; ++l) {         int prev = (l - k + n) % n, next = (l + k) % n;         if (arr[l] && arr[prev] && arr[next]) {           v[l] = true;           cnt++;         } else {           v[l] = false;         }       }       if (cnt >= size) {         cout <<  YES n ;         return 0;       }     }     cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace jyy {   const int mod = 998244353, N = 600010;   const double eps = 1e-8;   inline int read() {     static int x = 0, f = 1;     x = 0, f = 1;     static char ch = getchar();     while (ch <  0  || ch >  9 ) {       (ch ==  - ) ? f *= -1 : f;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + int(ch - 48), ch = getchar();     return x * f;   }   inline void fw(int x) {     if (x < 0) putchar( - ), x = -x;     x >= 10 ? fw(x / 10), 1 : 0;     putchar(char(x % 10 + 48));   }   inline int qmo(int x) { return x + ((x >> 31) & mod); }   inline int ksm(int x, int y) {     int tmp = 1;     for (; y; y >>= 1, x = 1ll * x * x % mod)       if (y & 1) tmp = 1ll * tmp * x % mod;     return tmp;   }   inline int inv(int x) { return ksm(x, mod - 2); }   int tot, head[N], fa[N];   struct edge {     int to, next;   } dat[N * 2];   void add_edge(int x, int y) { dat[++tot] = (edge){y, head[x]}, head[x] = tot; }   inline int find(int x) { return fa[x] ? fa[x] = find(fa[x]) : x; }   inline int merge(int x, int y) {     return find(x) != find(y) ? fa[find(x)] = find(y), 0 : 1;   }   inline int low(int x) { return x & -x; }   int ifac[N], fac[N];   inline void init(int x) {     fac[0] = ifac[0] = 1;     for (int i = 1; i <= x; i++) fac[i] = 1ll * fac[i - 1] * i % mod;     ifac[x] = inv(fac[x]);     for (int i = x - 1; i >= 1; i--) ifac[i] = 1ll * ifac[i + 1] * (i + 1) % mod;   }   inline int C(int x, int y) {     return (x < y || y < 0 || x < 0)                ? 0                : 1ll * fac[x] * ifac[y] % mod * ifac[x - y] % mod;   }   }  // namespace jyy   using namespace jyy;   int pd[N], n, R[N], a[N], vis[N], dep[N], m, b[N];   char c[N];   void dfs(int x, int f) {     vis[x] = 1;     dep[x] = dep[f] + 1;     fa[x] = f;     for (int i = head[x]; i; i = dat[i].next) {       int t = dat[i].to;       if (t == f || vis[t]) continue;       dfs(t, x);     }   }   void work(int x, int y) {     deque<int> q1, q2;     while (dep[x] > dep[y]) q1.push_back(x), x = fa[x];     while (dep[x] < dep[y]) q2.push_front(y), y = fa[y];     while (x != y) q1.push_back(x), q2.push_front(y), x = fa[x], y = fa[y];     q1.push_back(x);     cout << q1.size() + q2.size() << endl;     while (q1.size()) printf( %d  , q1.front()), q1.pop_front();     while (q2.size()) printf( %d  , q2.front()), q2.pop_front();     puts(  );   }   void solve() {     n = read(), m = read();     for (int i = 1, x, y; i <= m; i++)       x = read(), y = read(), add_edge(x, y), add_edge(y, x);     dfs(1, 0);     int q = read();     for (int i = 1; i <= q; i++) {       a[i] = read(), b[i] = read();       pd[a[i]] ^= 1;       pd[b[i]] ^= 1;     }     int cnt = 0;     for (int i = 1; i <= n; i++) cnt += pd[i];     if (cnt) {       puts( NO );       cout << cnt / 2 << endl;       return;     }     puts( YES );     for (int i = 1; i <= q; i++) {       work(a[i], b[i]);     }   }   int main() {     int T = 1;     while (T--) solve();   }


#include <bits/stdc++.h>   using namespace std;   bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {     return (a.first > b.first);   }   double gcd(double a, double b) {     if (b == 0) return a;     return gcd(b, double(int(a) % int(b)));   }   long long int power(long long int b, long long int e, long long int m) {     if (e == 0) return 1;     if (e & 1) return b * power(b * b % m, e / 2, m) % m;     return power(b * b % m, e / 2, m);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long int a;     cin >> a;     ;     long long int b;     cin >> b;     ;     long long int c;     cin >> c;     ;     long long int d;     cin >> d;     ;     long long int e;     cin >> e;     ;     long long int f;     cin >> f;     ;     long long int z = 0, ans = 0;     if (f >= e) {       z = min(c, d);       z = min(z, b);       ans += (f * z);       d -= z;       z = min(d, a);       ans += (e * z);     } else {       z = min(a, d);       ans += (e * z);       d -= z;       z = min(b, c);       z = min(z, d);       ans += (f * z);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, k, p;     cin >> n >> k >> p;     bool odd = false, even = false;     string ans =   ;     if (n % 2 == 0)       even = true;     else {       odd = true;       k--;     }     for (int i = 0; i < p; i++) {       long long tmp;       cin >> tmp;       if (even) {         if (tmp % 2 == 0 && n - 2 * k < tmp)           ans +=  X ;         else if (tmp % 2 == 1 && n - 2 * (k - n / 2) < tmp)           ans +=  X ;         else           ans +=  . ;       } else {         if (tmp == n && k >= 0) {           ans +=  X ;           continue;         }         if (tmp % 2 == 0 && n - 2 * k <= tmp)           ans +=  X ;         else if (tmp % 2 == 1 && n - 2 * (k - n / 2) <= tmp)           ans +=  X ;         else           ans +=  . ;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int n, start, x;   int order[50005];   pair<int, int> ask(int idx) {     printf( ? %d n , idx);     fflush(stdout);     int val, nxt;     scanf( %d%d , &val, &nxt);     return pair<int, int>(val, nxt);   }   int main() {     srand(time(0));     for (int i = 1; i < 50005; i++) order[i] = i;     scanf( %d%d%d , &n, &start, &x);     random_shuffle(order + 1, order + n + 1);     int ptr = start, ptr_val = INT_MIN;     for (int i = 1; i <= min(n, 1200); i++) {       pair<int, int> p = ask(order[i]);       if (p.first <= x && p.first >= ptr_val) ptr = order[i], ptr_val = p.first;     }     int ans = -1;     while (ptr != -1) {       pair<int, int> y = ask(ptr);       if (y.first >= x) {         ans = y.first;         break;       }       ptr = y.second;     }     printf( ! %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   void optIO() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   const long long mod = 1e9 + 7, mod2 = 998244353, mod3 = 1e9 + 9;   long long p[5020], pp = 31, hh[5020];   long long p2[5020], pp2 = 37, hh2[5020];   int dp[5020];   bool can[5020][5020];   map<long long, bool> ms;   void solve() {     int n, a, b;     cin >> n >> a >> b;     string s;     cin >> s;     p[0] = 1;     p2[0] = 1;     for (int i = 1; i < n + 1; ++i) {       p[i] = (p[i - 1] * pp) % mod;       p2[i] = (p2[i - 1] * pp2) % mod2;       hh[i] = (hh[i - 1] + (s[i - 1] -  a  + 1) * p[i]) % mod;       hh2[i] = (hh2[i - 1] + (s[i - 1] -  a  + 1) * p2[i]) % mod2;     }     for (int j = 1; j < n + 1; ++j) {       for (int i = 1; i < n + 1; ++i) {         if (i - 2 * j < 0) continue;         long long y =             ((hh[i - j] - hh[i - 2 * j] + mod) % mod * p[n - (i - j)]) % mod;         long long y2 =             ((hh2[i - j] - hh2[i - 2 * j] + mod2) % mod2 * p2[n - (i - j)]) %             mod2;         ms[y * mod2 + y2] = 1;         long long x = ((hh[i] - hh[i - j] + mod) % mod * p[n - i]) % mod;         long long x2 = ((hh2[i] - hh2[i - j] + mod2) % mod2 * p2[n - i]) % mod2;         if (ms.find(x * mod2 + x2) != ms.end()) can[i][j] = 1;       }       ms.clear();     }     for (int i = 1; i < n + 1; ++i) {       dp[i] = dp[i - 1] + a;       for (int j = 1; j < i + 1; ++j) {         if (can[i][j]) dp[i] = min(dp[i], dp[i - j] + b);       }     }     cout << dp[n] <<   n ;   }   int main() {     optIO();     int t = 1;     while (t--) {       solve();     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int M = 6e5;   int n, d, f[M];   int main() {     cin >> n >> d;     f[0] = 1;     int now = 0, times = 0;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       for (int j = M - 1; j >= x; j--) f[j] |= f[j - x];     }     while (1) {       int old = now;       for (int i = 1; i <= d; i++)         if (f[i + old]) now = old + i;       if (now == old) break;       times++;     }     cout << now <<     << times << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     double x, y;     point operator-(point A) { return (point){x - A.x, y - A.y}; }     double operator*(point A) { return x * A.y - y * A.x; }     double dis() { return sqrt(x * x + y * y); }   } a[1005][1005], t[1005], E[1005];   int n, vis[1005][1005];   double r[1005][1005];   point Mid(point a, point b) {     return (point){(a.x + b.x) / 2, (a.y + b.y) / 2};   }   double disline(int i, point A) { return abs(E[i] * (A - t[i]) / E[i].dis()); }   int ch(int R) { return R % n ? R % n : n; }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) scanf( %lf%lf , &t[i].x, &t[i].y);     for (int i = 1; i <= 2 * n; i++) t[n + i] = t[i];     for (int i = 1; i <= 3 * n; i++) E[i] = t[i + 1] - t[i];     for (int L = 1, R = L + 1, nw = L; L <= n; L++)       for (R--, nw = max(L, nw); R == L || E[L] * E[R] > 0.5; R++) {         while (nw < R && disline(L, t[nw + 1]) < disline(R, t[nw + 1])) ++nw;         point le = t[nw], ri = t[nw + 1];         for (int j = 1; j <= 42; j++) {           point mid = Mid(le, ri);           if (disline(L, mid) < disline(R, mid))             le = mid;           else             ri = mid;         }         point P = Mid(le, ri);         a[L][ch(R)] = P;         r[L][ch(R)] = max(disline(L, P), disline(R, P));         vis[L][ch(R)] = 1;       }     double ans = 1e7;     point a1, a2;     for (int L = 1; L <= n; L++)       for (int R = L; R <= L + n; R++)         if (vis[L][ch(R)] && vis[ch(R + 1)][ch(L - 1 + n)]) {           double newr = max(r[L][ch(R)], r[ch(R + 1)][ch(L - 1 + n)]);           if (newr < ans)             ans = newr, a1 = a[L][ch(R)], a2 = a[ch(R + 1)][ch(L - 1 + n)];         }     printf( %.10f n%.10f %.10f n%.10f %.10f n , ans, a1.x, a1.y, a2.x, a2.y);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int Solve(int n) {     int ten = 1;     int ans = 0;     while (n != 0) {       if (n % 10 != 0) {         ans += (ten * (n % 10));         ten *= 10;       }       n /= 10;     }     return ans;   }   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   bool prime(long long int i) {     if (i == 1) return false;     if ((i == 2) || (i == 3)) return true;     if ((i % 2 == 0) || (i % 3 == 0))       return false;     else {       for (long long int j = 5; j * j <= i; j += 6)         if ((i % j == 0) || (i % (j + 2) == 0)) return false;     }     return true;   }   int main() {     int flag = 0;     bool ok;     int n, m, test, sum = 0, id1 = 0, id2 = 0, id3 = 0, dig1, dig2, dig3;     int a, b;     cin >> a >> b;     int c = a + b;     dig1 = Solve(a);     dig2 = Solve(b);     dig3 = Solve(c);     if (dig1 + dig2 == dig3) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n;   long long calcCards(long long x) { return x * (x + 1) + (x - 1) * x / 2; }   bool P(int x) { return calcCards(x) <= n; }   long long bs(long long l = 0, long long h = n) {     long long m;     while (l < h) {       m = (l + h + 1) / 2;       if (P(m))         l = m;       else         h = m - 1;     }     return l;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cout << fixed;     cout << setprecision(10);     int t;     cin >> t;     while (t--) {       cin >> n;       int ans = 0;       while (n >= 2) {         ans++;         n -= calcCards(bs());       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   void Fast() {     std::ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   long long fact(long long n) {     long long f = 1;     for (int i = 2; i <= n; i++) {       f *= i;     }     return f;   }   long long ncr(long long n, long long r) {     return fact(n) / (fact(r) * fact(n - r));   }   long long npr(long long n, long long r) { return fact(n) / fact(n - r); }   bool prime(long long n) {     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) {         return 0;         break;       }     }     return 1;   }   char arr[55][55];   void solve() {     int n, m;     cin >> n >> m;     int r1 = INT_MIN, r2 = INT_MAX, c1 = INT_MIN, c2 = INT_MAX;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> arr[i][j];         if (arr[i][j] ==  * ) {           r1 = max(r1, i);           r2 = min(r2, i);           c1 = max(c1, j);           c2 = min(c2, j);         }       }     }     for (int i = r2; i <= r1; i++) {       for (int j = c2; j <= c1; j++) {         cout << arr[i][j];       }       cout <<   n ;     }   }   int main() {     Fast();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, d;       cin >> n >> d;       int ld = 0, rd = n * (n - 1) / 2;       for (int i = 1, cd = 0; i <= n; ++i) {         if (!(i & (i - 1))) ++cd;         ld += cd - 1;       }       if (!(ld <= d && d <= rd)) {         cout <<  NO  << endl;         continue;       }       vector<int> par(n);       iota(par.begin(), par.end(), -1);       vector<int> cnt(n, 1);       cnt[n - 1] = 0;       vector<int> bad(n);       vector<int> dep(n);       iota(dep.begin(), dep.end(), 0);       int cur = n * (n - 1) / 2;       while (cur > d) {         int v = -1;         for (int i = 0; i < n; ++i) {           if (!bad[i] && cnt[i] == 0 && (v == -1 || dep[v] > dep[i])) {             v = i;           }         }         assert(v != -1);         int p = -1;         for (int i = 0; i < n; ++i) {           if (cnt[i] < 2 && dep[i] < dep[v] - 1 && (p == -1 || dep[p] < dep[i])) {             p = i;           }         }         if (p == -1) {           bad[v] = 1;           continue;         }         assert(dep[v] - dep[p] == 2);         --cnt[par[v]];         --dep[v];         ++cnt[p];         par[v] = p;         --cur;       }       cout <<  YES  << endl;       for (int i = 1; i < n; ++i) cout << par[i] + 1 <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, K, D[1010], S[1010], ans, tt, crtMax;   int main() {     int i;     scanf( %i %i , &N, &K);     for (i = 1; i <= N; i++) scanf( %i , &D[i]);     for (i = 1; i <= N; i++) scanf( %i , &S[i]);     for (i = 1; i <= N; i++) {       crtMax = max(crtMax, S[i]);       ans += S[i];       while (ans < D[i]) {         ans += crtMax;         tt += K;       }       tt += D[i];       ans -= D[i];     }     printf( %i n , tt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long fast_power(long long x, long long y) {     if (y == 0) return 1;     long long temp = fast_power(x, y / 2);     temp = ((temp % 1000000007) * (temp % 1000000007)) % 1000000007;     if (y % 2 != 0) temp = ((temp % 1000000007) * (x % 1000000007)) % 1000000007;     return temp;   }   long long f[1000001];   long long inv[1000001];   long long ncr(long long n, long long r) {     return ((((f[n] % 1000000007) * (inv[n - r] % 1000000007)) % 1000000007) *             inv[r]) %            1000000007;   }   long long nCr(long long n, long long r) {     long long f = 1;     long long x = 1;     for (long long i = n; i > n - r; i--) {       f *= i;       f /= x++;     }     return f;   }   long long npr(long long n, long long r) {     return (f[n] % 1000000007 * inv[n - r] % 1000000007) % 1000000007;   }   int main() {     long long n, r, t;     cin >> n >> r >> t;     f[0] = 1;     inv[0] = 1;     for (long long i = 1; i <= n; i++) {       f[i] = (f[i - 1] * i) % 1000000007;       inv[i] = fast_power(f[i], 1000000007 - 2);     }     long long sum = 0;     if (n >= 4)       for (long long i = 4; i < t; i++) {         if (t - i <= r) sum += nCr(n, i) * nCr(r, t - i);       }     cout << sum <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n, m;     cin >> n >> m;     vector<int> a(n);     for (auto& x : a) cin >> x, --x;     vector<int> k(m);     for (auto& x : k) cin >> x;     for (int i = 0; i < n; ++i)       for (int j = i + 1; j <= n; ++j) {         vector<int> cur(m);         for (int l = i; l < j; ++l) ++cur[a[l]];         if (cur == k) {           cout <<  YES n ;           return 0;         }       }     cout <<  NO n ;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void nexts(T *, int);   template <typename T>   void dump(T *arr, int cnt, char sep =    );   void __init__(bool, bool);   const int MAXMAXMAX = 1000 * 1000 * 1000;   string a, b, c;   char ans[100015];   vector<int> cnt_a(26);   vector<int> cnt_b(26);   vector<int> cnt_c(26);   int main() {     __init__(1, 0);     cin >> a >> b >> c;     for (int(i) = (0); (i) < (a.size()); ++(i)) ++cnt_a[a[i] -  a ];     for (int(i) = (0); (i) < (b.size()); ++(i)) ++cnt_b[b[i] -  a ];     for (int(i) = (0); (i) < (c.size()); ++(i)) ++cnt_c[c[i] -  a ];     int b_max = MAXMAXMAX;     for (int(i) = (0); (i) < (26); ++(i))       if (cnt_b[i] != 0) b_max = min(b_max, cnt_a[i] / cnt_b[i]);     int max_ans = 0;     int max_b = 0;     int max_c = 0;     if (b_max == MAXMAXMAX) b_max = 0;     vector<int> tmp = cnt_a;     for (int(i) = (0); (i) < (b_max + 1); ++(i)) {       if (i != 0)         for (int(i) = (0); (i) < (26); ++(i)) tmp[i] -= cnt_b[i];       int c_max = MAXMAXMAX;       for (int(i) = (0); (i) < (26); ++(i))         if (cnt_c[i] != 0) c_max = min(c_max, tmp[i] / cnt_c[i]);       if (c_max == MAXMAXMAX) b_max = 0;       if (i + c_max > max_ans) {         max_ans = i + c_max;         max_b = i;         max_c = c_max;       }     }     for (int(i) = (0); (i) < (max_b); ++(i)) cout << b;     for (int(i) = (0); (i) < (max_c); ++(i)) cout << c;     for (int(i) = (0); (i) < (26); ++(i)) {       cnt_a[i] -= max_b * cnt_b[i] + max_c * cnt_c[i];       for (int(j) = (0); (j) < (cnt_a[i]); ++(j)) cout << (char)( a  + i);     }     cout <<   n ;     return 0;   }   template <typename T>   void nexts(T *arr, int cnt) {     for (int i = 0; i < cnt; ++i) cin >> arr[i];   }   template <typename T>   void dump(T *arr, int cnt, char sep) {     for (int i = 0; i < cnt; ++i) cout << arr[i] << sep;   }   void __init__(bool fastIOstream, bool acmp) {     if (fastIOstream) {       ios_base::sync_with_stdio(false);       cin.tie(0);     }     if (acmp) {       freopen( INPUT.TXT ,  rt , stdin);       freopen( OUTPUT.TXT ,  wt , stdout);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     cin >> a >> b >> c;     int x = sqrt(a * c / b), y = sqrt(a * b / c), z = sqrt(b * c / a);     cout << (x + y + z) * 4;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long nMod = 1e9 + 7;   inline long long GCD(long long a, long long b) {     while (b != 0) {       long long c = a % b;       a = b;       b = c;     }     return a;   };   inline long long LCM(long long a, long long b) { return (a / GCD(a, b)) * b; };   int m, n, k;   vector<set<int>> st(55);   void vietnakid() {     cin >> m >> n;     for (int i = 0; i < m; i++) {       cin >> k;       for (int j = 0; j < k; j++) {         int x;         cin >> x;         st[i].insert(x);       }     }     bool check = true;     for (int i = 0; i < m; i++) {       if (!check) break;       for (int j = 0; j < m; j++) {         bool ok = false;         for (auto x : st[i]) {           if (ok) break;           if (st[j].count(x)) {             ok = true;           }         }         if (!ok) {           check = false;           break;         }       }     }     if (check) {       cout <<  possible n ;     } else {       cout <<  impossible n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     vietnakid();     cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3,unroll-loops )   #pragma pack(0)   using namespace std;   vector<string> v[1000001];   string s;   int ptr = 0, maxd = 0;   void dfs(int dis) {     maxd = max(maxd, dis);     int k = 0, f = ptr;     for (; ptr < s.length(); ptr++)       if (s[ptr] ==  , ) break;     string t = s.substr(f, ptr - f);     ptr++;     for (; ptr < s.length(); ptr++) {       if (s[ptr] ==  , ) break;       k = k * 10 + (s[ptr] -  0 );     }     ptr++;     v[dis].emplace_back(t);     for (int i = 1; i <= k; i++) dfs(dis + 1);   }   signed main() {     ios::sync_with_stdio(0), cin.tie(0);     cin >> s;     while (ptr < s.length()) dfs(0);     cout << maxd + 1 <<   n ;     for (int i = 0; !v[i].empty(); i++) {       for (auto j : v[i]) cout << j <<    ;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   class Solution {     int n, x[2];     vector<pair<long long, int>> A;       public:     void run() {       cin >> n >> x[0] >> x[1];       for (int i = 0; i < n; ++i) {         int c;         cin >> c;         A.emplace_back(c, i);       }       sort(A.begin(), A.end());       for (int i = 0; i < n; ++i) {         int a = A[i].first;         int j = (x[0] + a - 1) / a + i;         if (j < n and x[1] <= A[j].first * (n - j)) {           cout <<  Yes n ;           cout << j - i <<     << n - j <<   n ;           for (int k = i; k < j; ++k)             cout << A[k].second + 1 <<    n [k == j - 1];           for (int k = j; k < n; ++k)             cout << A[k].second + 1 <<    n [k == n - 1];           return;         }         j = (x[1] + a - 1) / a + i;         if (j < n and x[0] <= A[j].first * (n - j)) {           cout <<  Yes n ;           cout << n - j <<     << j - i <<   n ;           for (int k = j; k < n; ++k)             cout << A[k].second + 1 <<    n [k == n - 1];           for (int k = i; k < j; ++k)             cout << A[k].second + 1 <<    n [k == j - 1];           return;         }       }       cout <<  No n ;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     Solution().run();   }


#include <bits/stdc++.h>   using namespace std;   bool isPrime(int a, int p) {     return (a <= p) || ((a % p != 0) && (isPrime(a, p + 1)));   }   int main() {     const int N = 256;     int freq[N] = {0};     string s;     cin >> s;     int len = s.size();     for (int p = 0; p < len; p++) {       ++freq[s[p]];     }     string t(len, 0);     int *m = max_element(freq, freq + N);     for (int p = 1; p < len; p++) {       if ((p < len / 2) || (!isPrime(p + 1, 2))) {         t[p] = m - freq;         (*m)--;       }     }     if (*m < 0) {       cout <<  NO  << endl;     } else {       int q = 0;       for (int p = 0; p < len; p++) {         if (!t[p]) {           while (!freq[q]) {             q++;           }           freq[t[p] = q]--;         }       }       cout <<  YES  << endl << t << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   bool cmp(pair<int, int> a, pair<int, int> b) {     if (a.first != b.first) return a.first > b.first;     return a.second < b.second;   }   bool cmp2(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     vector<pair<int, int> > v;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       v.push_back({x, i});     }     sort(v.begin(), v.end(), cmp);     cin >> m;     while (m--) {       int k, pos;       cin >> k >> pos;       vector<pair<int, int> > res;       for (int i = 0; i < k; i++) {         res.push_back(v[i]);       }       sort(res.begin(), res.end(), cmp2);       cout << res[pos - 1].first <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using PII = pair<int, int>;   const int mod = 998244353;   const int inf = 1 << 30;   const int maxn = 200000 + 5;   int n, tot, tin[maxn], tout[maxn], rid[maxn], vis[maxn], deg[maxn];   vector<int> edge[maxn];   int query(int x, int y) {     cout <<  ?   << x <<     << y << endl;     cin >> x;     assert(x >= 1 && x <= n);     return x;   }   int ok[maxn];   void dfs(int u, int f) {     tin[u] = ++tot;     rid[tot] = u;     for (int v : edge[u]) {       if (v == f) continue;       dfs(v, u);     }     tout[u] = tot;   }   bool check(int x, int y) { return tin[x] <= tin[y] && tout[y] <= tout[x]; }   int main() {     scanf( %d , &n);     ok[1] = true;     for (int i = 2, u, v; i <= n; i++) {       scanf( %d%d , &u, &v);       ok[i] = true;       edge[u].push_back(v);       edge[v].push_back(u);       deg[u]++;       deg[v]++;     }     dfs(1, 0);     vector<int> v;     for (int i = 1; i <= n; i++)       if (deg[i] == 1) v.push_back(i);     assert(v.size() >= 2);     for (int i = 1; i < (int)v.size(); i += 2) {       int ans = query(v[i - 1], v[i]);       for (int y : edge[ans]) {         if (check(ans, y)) {           if (check(y, v[i - 1]) || check(y, v[i])) {             for (int j = tin[y]; j <= tout[y]; j++) {               ok[rid[j]] = false;             }           }         } else {           if (!check(ans, v[i - 1]) || !check(ans, v[i])) {             for (int j = 1; j < tin[ans]; j++) {               ok[rid[j]] = false;             }             for (int j = tout[ans] + 1; j <= n; j++) {               ok[rid[j]] = false;             }           }         }       }     }     v.clear();     for (int i = 1; i <= n; i++) {       if (!ok[i]) continue;       int c = 0;       for (int v : edge[i]) {         if (ok[v]) c++;       }       assert(c <= 2);       if (c == 1) {         v.push_back(i);       }     }     if (v.size() == 0) {       for (int i = 1; i <= n; i++) {         if (ok[i]) {           cout <<  !   << i << endl;           return 0;         }       }     } else if (v.size() == 2) {       int r = query(v[0], v[1]);       cout <<  !   << r << endl;     } else {       assert(false);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   const long long LINF = 4000000000000000000LL;   const double eps = 1e-9;   void prepare() {}   int a, n;   int day[10000008];   void read() { scanf( %d%d , &a, &n); }   void solve() {     read();     for (int i = 1; i * i < a + n; i++) {       int ii = i * i;       for (int j = ii; j < a + n; j += ii) day[j] = i * i;     }     long long res = 0;     for (int i = a; i < a + n; i++) res += i / day[i];     cout << res << endl;   }   int main() {     prepare();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 100005;   long long t, l, i, j, k, p, q, u, v, n, color[1000005];   string s;   vector<long long> zro;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> q;     for (l = 1; l <= q; l++) {       cin >> n >> k >> s;       for (i = 0; i < n; i++) {         if (s[i] ==  0 )           zro.push_back(i);         else           color[i] = 1;       }       u = 0;       v = 0;       for (i = 0; i < zro.size(); i++) {         if (u == n || k == 0) break;         for (; u < n; u++) {           if (zro[i] < u) break;           if (color[u] == 1 && zro[i] - u <= k) {             k -= (zro[i] - u);             color[zro[i]] = 1;             color[u] = 0;             swap(s[u], s[zro[i]]);             u++;             break;           }         }       }       cout << s << endl;       for (i = 0; i <= n; i++) color[i] = 0;       zro.clear();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, sum = 0;     string s;     cin >> a;     for (int i = 0; i < a; i++) {       cin >> s;       if (s ==  Tetrahedron )         sum = sum + 4;       else if (s ==  Cube )         sum = sum + 6;       else if (s ==  Octahedron )         sum = sum + 8;       else if (s ==  Dodecahedron )         sum = sum + 12;       else if (s ==  Icosahedron )         sum = sum + 20;     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 ,  unroll-loops )   using namespace std;   namespace {   const int MOD107 = 1000000007;   const int MOD998 = 998244353;   using ll = long long;   using ull = unsigned long long;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   template <class T>   using minheap = priority_queue<T, vector<T>, greater<T>>;   template <class T>   using maxheap = priority_queue<T, vector<T>, less<T>>;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   struct Modular {    private:     long long MODVALUE = 0;     long long val = 0;     Modular initModular(long long val) const { return Modular(val, MODVALUE); }     inline void validate() const {}     inline void validate(const Modular& other) const {}       public:     explicit operator long long() const { return val; }     template <class T>     Modular& operator=(const T& other) {       val = (other % MODVALUE + MODVALUE) % MODVALUE;       return *this;     }     long long getMod() { return MODVALUE; }     template <class T>     void setMod(const T& MOD) {       MODVALUE = MOD;     }     bool operator==(const Modular& other) const {       validate(other);       return val == other.val;     }     bool operator!=(const Modular& other) const { return !(*this == other); }     Modular& operator+=(const Modular& other) {       validate(other);       val += other.val;       if (val >= MODVALUE) val -= MODVALUE;       return *this;     }     Modular operator+(const Modular& other) const {       Modular tmp = *this;       return tmp += other;     }     template <class T>     Modular& operator+=(const T& other) {       return *this += initModular(other);     }     template <class T>     Modular operator+(const T& other) const {       return *this + initModular(other);     }     template <class T>     friend Modular operator+(const T& other, const Modular& m) {       return m.initModular(other) + m;     }     Modular& operator++() { return *this += 1; }     Modular operator++(int) {       Modular tmp = *this;       ++*this;       return tmp;     }     Modular operator-() const { return initModular(-val); }     Modular& operator-=(const Modular& other) {       validate(other);       val -= other.val;       if (val < 0) val += MODVALUE;       return *this;     }     Modular operator-(const Modular& other) const {       Modular tmp = *this;       return tmp -= other;     }     template <class T>     Modular& operator-=(const T& other) {       return *this -= initModular(other);     }     template <class T>     Modular operator-(const T& other) const {       return *this - initModular(other);     }     template <class T>     friend Modular operator-(const T& other, const Modular& m) {       return m.initModular(other) - m;     }     Modular& operator--() { return *this -= 1; }     Modular operator--(int) {       Modular tmp = *this;       --*this;       return tmp;     }     Modular& operator*=(const Modular& other) {       validate(other);       val *= other.val;       val %= MODVALUE;       if (val < 0) val += MODVALUE;       return *this;     }     Modular operator*(const Modular& other) const {       Modular tmp = *this;       return tmp *= other;     }     template <class T>     Modular& operator*=(const T& other) {       return *this *= initModular(other);     }     template <class T>     Modular operator*(const T& other) const {       return *this * initModular(other);     }     template <class T>     friend Modular operator*(const T& other, const Modular& m) {       return m.initModular(other) * m;     }     Modular pow(long long power) const {       Modular m = *this, ans = initModular(1);       while (power) {         if (power & 1) ans *= m;         m *= m;         power >>= 1;       }       return ans;     }     Modular pow(const Modular& other) const { return pow(other.val); }     Modular inv() const { return pow(MODVALUE - 2); }     Modular& operator/=(const Modular& other) {       val *= other.inv().val;       val %= MODVALUE;       if (val < 0) val += MODVALUE;       return *this;     }     Modular operator/(const Modular& other) const {       Modular tmp = *this;       return tmp /= other;     }     template <class T>     Modular& operator/=(const T& other) {       return *this /= initModular(other);     }     template <class T>     Modular operator/(const T& other) const {       return *this / initModular(other);     }     template <class T>     friend Modular operator/(const T& other, const Modular& m) {       return m.initModular(other) / m;     }     friend istream& operator>>(istream& in, Modular& m) {       in >> m.val;       m.val %= m.MODVALUE;       if (m.val < 0) m.val += m.MODVALUE;       return in;     }     friend ostream& operator<<(ostream& out, const Modular& m) {       return out << m.val;     }     Modular() {       val = 0;       MODVALUE = 0;     }     Modular(long long val, long long MOD)         : MODVALUE(MOD), val((val % MOD + MOD) % MOD) {}   };   using Mint = Modular;   inline ll binpow(ll b, ll p, ll mod) {     b %= mod;     ll ans = 1;     for (; p > 0; p >>= 1) {       if (p & 1) {         ans *= b;         ans %= mod;       }       b *= b;       b %= mod;     }     return ans;   }   inline ll max(ll a, int b) { return (a > b ? a : b); }   inline ll max(int a, ll b) { return (a > b ? a : b); }   inline ll min(ll a, int b) { return (a < b ? a : b); }   inline ll min(int a, ll b) { return (a < b ? a : b); }   template <class T>   inline bool chkmin(T& x, const T& y) {     return y < x ? x = y, 1 : 0;   }   template <class T>   inline bool chkmax(T& x, const T& y) {     return x < y ? x = y, 1 : 0;   }   }  // namespace   namespace IO {   struct InputWrapper {    private:     istream& in;       public:     template <class T>     inline void _R(T& x) {       in >> x;     }     template <class T1, class T2>     inline void _R(pair<T1, T2>& x) {       _R(x.first);       _R(x.second);     }     template <class T>     inline void _R(vector<T>& x) {       for (auto& i : x) _R(i);     }     template <class T>     inline void _R(deque<T>& x) {       for (auto& i : x) _R(i);     }     inline void R() {}     template <class T1, class... T2>     inline void R(T1& x, T2&... y) {       _R(x);       R(y...);     }     template <class... T>     inline void operator()(T&... x) {       R(x...);     }     InputWrapper(istream& in) : in(in) {}   } R(cin);   struct OutputWrapper {    private:     ostream& out;       public:     template <class Container>     inline void printContainer(const Container& x) {       bool isFirst = 1;       for (auto i : x) {         if (!isFirst) out <<    ;         isFirst = 0;         _W(i);       }     }     template <class T>     inline void _W(const T& x) {       out << x;     }     template <class T1, class T2>     inline void _W(const pair<T1, T2>& p) {       _W(p.first);       _W(   );       _W(p.second);     }     template <class... T>     inline void _W(const vector<T...>& x) {       printContainer(x);     }     template <class... T>     inline void _W(const deque<T...>& x) {       printContainer(x);     }     template <class... T>     inline void _W(const forward_list<T...>& x) {       printContainer(x);     }     template <class... T>     inline void _W(const list<T...>& x) {       printContainer(x);     }     template <class... T>     inline void _W(const set<T...>& x) {       printContainer(x);     }     template <class... T>     inline void _W(const multiset<T...>& x) {       printContainer(x);     }     template <class... T>     inline void _W(const unordered_set<T...>& x) {       printContainer(x);     }     template <class... T>     inline void _W(const unordered_multiset<T...>& x) {       printContainer(x);     }     template <class... T>     inline void _W(const map<T...>& x) {       printContainer(x);     }     template <class... T>     inline void _W(const multimap<T...>& x) {       printContainer(x);     }     template <class... T>     inline void _W(const unordered_map<T...>& x) {       printContainer(x);     }     template <class... T>     inline void _W(const unordered_multimap<T...>& x) {       printContainer(x);     }     inline void W() { out <<   n ; }     template <class T>     inline void W(const T& x) {       _W(x);       W();     }     template <class T1, class... T2>     inline void W(const T1& x, const T2&... y) {       _W(x);       _W(   );       W(y...);     }     template <class... T>     inline void operator()(const T&... x) {       W(x...);     }     OutputWrapper(ostream& out) : out(out) {}   } W(cout), D(cerr);   }  // namespace IO   using namespace IO;   namespace outputFormat {   inline string Case(int tc) { return  Case #  + to_string(tc) +  : ; }   inline string YN(bool b) { return b ?  Yes  :  No ; }   }  // namespace outputFormat   using namespace outputFormat;   namespace std {   template <class T1, class T2>   struct hash<pair<T1, T2>> {     std::size_t operator()(pair<T1, T2> _) const {       return hash<T1>{}(_.first) ^ hash<T2>{}(_.second);     }   };   }  // namespace std   int main() {     int t;     cin >> t;     while (t--) {       int n;       R(n);       string s, t;       R(s, t);       vector<vector<Mint>> cnt_table(n + 1,                                      vector<Mint>(2 * n + 7, Mint(0, MOD107))),           sum_table = cnt_table;       vector<Mint*> cnt(n + 1), sum(n + 1);       for (int i = 0; i <= n; i++) {         cnt[i] = &cnt_table[i][n + 3];         sum[i] = &sum_table[i][n + 3];       }       cnt[0][0] = 1;       vector<vector<bool>> can(4, vector<bool>(n + 1, false));       for (int i = 1; i <= n; i++) {         can[0][i] = s[i - 1] !=  1  && t[i - 1] !=  1 ;         can[1][i] = s[i - 1] !=  1  && t[i - 1] !=  0 ;         can[2][i] = s[i - 1] !=  0  && t[i - 1] !=  1 ;         can[3][i] = s[i - 1] !=  0  && t[i - 1] !=  0 ;         if (i % 2 == 1) swap(can[1][i], can[2][i]);       }       for (int i = 1; i <= n; i++) {         for (int j = -i; j <= i; j++) {           if (can[0][i]) {             cnt[i][j] += cnt[i - 1][j];             sum[i][j] += sum[i - 1][j];           }           if (can[1][i]) {             cnt[i][j] += cnt[i - 1][j - 1];             sum[i][j] += sum[i - 1][j - 1] +                          cnt[i - 1][j - 1] * i * (abs(j) < abs(j - 1) ? +1 : -1);           }           if (can[2][i]) {             cnt[i][j] += cnt[i - 1][j + 1];             sum[i][j] += sum[i - 1][j + 1] +                          cnt[i - 1][j + 1] * i * (abs(j) < abs(j + 1) ? +1 : -1);           }           if (can[3][i]) {             cnt[i][j] += cnt[i - 1][j];             sum[i][j] += sum[i - 1][j];           }         }       }       W(sum[n][0]);     }     return 0;   }   static auto __init__ = []() {     ios::sync_with_stdio(false);     cin.tie(0);     cout << fixed << setprecision(10);     return 42;   }();


#include <bits/stdc++.h>   using namespace std;   ofstream file( debug.txt );   template <typename Int>   ostream &operator<<(ostream &s, const vector<Int> &v) {     s <<  [ ;     for (auto i = v.begin(); i != v.end(); i++) {       s << *i;       if (i != prev(v.end())) s <<  ,  ;     }     s <<  ] ;     return s;   }   template <typename Int, typename INT>   ostream &operator<<(ostream &s, const map<Int, INT> &mp) {     s <<  [ ;     for (auto &i : mp) {       s <<  [  << i.first <<  ,   << i.second <<  ] ;       if (i != *mp.rbegin()) s <<  ,  ;     }     s <<  ] ;     return s;   }   template <typename Int>   ostream &operator<<(ostream &s, const set<Int> &st) {     s <<  [ ;     for (auto &i : st) {       s << i;       if (i != *st.rbegin()) s <<  ,  ;     }     s <<  ] ;     s <<   n ;     return s;   }   template <typename Int, typename INt>   ostream &operator<<(ostream &s, const pair<Int, INt> &x) {     s <<  [  << x.first <<  ,   << x.second <<  ] ;     return s;   }   template <typename T>   void print(T *x, int n) {     for (int i = 0; i < n; i++) {       file << x[i] <<    n [i == n - 1];     }   }   template <typename T>   ostream &operator<<(ostream &s, const complex<T> &a) {     s <<  (  << a.real() <<  ,   << a.imag() <<  ) ;     return s;   }   template <typename T>   T debug(const T &x, const string &s =   ) {     file << s <<   =   << x <<   n  << flush;     return x;   }   const int dr[]{-1, -1, 0, 1, 1, 1, 0, -1};   const int dc[]{0, 1, 1, 1, 0, -1, -1, -1};   const int N = 2e5 + 10;   int n, m, q, ans;   bool dead[N];   set<int> edg[N];   void add(int u, int v) {     if (!dead[u]) {       dead[u] = 1;       ans--;     }     edg[u].insert(v);   }   void rem(int u, int v) {     if (dead[u] && edg[u].size() == 1) {       dead[u] = 0;       ans++;     }     edg[u].erase(v);   }   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     cin >> n >> m;     ans = n;     for (int i = 0, u, v; i < m; i++) {       cin >> u >> v;       if (u > v) swap(u, v);       add(u, v);     }     cin >> q;     while (q--) {       int t;       cin >> t;       if (t < 3) {         int u, v;         cin >> u >> v;         if (u > v) swap(u, v);         if (t == 1)           add(u, v);         else           rem(u, v);       } else         cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s, ans, x, y, a;     bool flag = false;     cin >> n >> s;     s = s * 100;     ans = -1;     for (int i = 0; i < n; i++) {       cin >> x >> y;       a = x * 100 + y;       if (a <= s) {         ans = max(ans, (100 - a % 100) % 100);       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   inline int read() {     char c = getchar();     int x = 0;     bool f = 0;     for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);     for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);     if (f) x = -x;     return x;   }   bool work() {     int a = read(), b = read();     if (a > b) swap(a, b);     if (a == 0) return (b == 0);     if (a * 2 < b) return 0;     if (a * 2 == b) return 1;     int c = (abs(b - a - a));     return (a + b) % 3 == 0;   }   signed main() {     int n = read();     while (n--)       if (work())         puts( YES );       else         puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 100010;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long n, m, p, a[N], b[N], q[N], yue[N], miu[N], f[N], tot;   long long ans;   long long power(long long a, long long b, long long m) {     long long re = 1;     while (b) {       if (b & 1) re = (long long)re * a % m;       a = (long long)a * a % m;       b >>= 1;     }     return re;   }   long long calc(long long x) {     long long i, j, k, l;     for (i = 1; i <= tot; i++)       if (power(x, yue[i], p) == 1) return yue[i];   }   int main() {     long long i, j, k;     scanf( %I64d%I64d%I64d , &n, &m, &p);     for (i = 1; i * i <= p - 1; i++) {       if ((p - 1) % i == 0) {         yue[++tot] = i;         if (i * i < p - 1) yue[++tot] = (p - 1) / i;       }     }     sort(yue + 1, yue + tot + 1);     for (i = 1; i <= n; i++) scanf( %I64d , &a[i]);     for (i = 1, k = 0; i <= m; i++) {       scanf( %I64d , &j);       k = gcd(k, j);     }     k = gcd(k, p - 1);     for (i = 1; i <= n; i++) {       q[i] = calc(a[i]);       a[i] = (p - 1) * gcd(q[i], k) / q[i];     }     for (i = 1; i <= tot; i++)       for (j = 1; j <= n; j++)         if (yue[i] % a[j] == 0) {           f[i] = 1;           break;         }     for (i = 1; i <= tot; i++) {       ans += (f[i] - miu[i]) * ((p - 1) / yue[i]);       for (j = i + 1; j <= tot; j++)         if (yue[j] % yue[i] == 0) miu[j] += (f[i] - miu[i]);       miu[i] += (f[i] - miu[i]);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const double pi = acos(-1.0);   int n, m;   bool check(int x) {     int a2 = x / 2, a3 = x / 3, a6 = x / 6;     a2 -= a6;     a3 -= a6;     if (max(n - a2, 0) + max(m - a3, 0) <= a6)       return true;     else       return false;   }   int main() {     cin >> n >> m;     int l = 1, r = 1e7;     int ans = -1;     while (l <= r) {       int mid = (l + r) / 2;       if (check(mid))         r = mid - 1;       else         l = mid + 1;     }     cout << l << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 10;   const int K = 23;   const long long INF = 1e18;   int id[N], a[N], b[N], w[N];   int n, m;   vector<int> pos[N];   long long dp[N];   int ls[N * K], rs[N * K], rootcnt = 0;   long long vs[N * K];   void copy(int root, int newroot) {     ls[newroot] = ls[root];     rs[newroot] = rs[root];     vs[newroot] = vs[root];   }   void updates(int root, int& newroot, int l, int r, int pos, int v) {     newroot = ++rootcnt;     copy(root, newroot);     vs[newroot] += v;     if (l == r || v == 0) return;     int m = (l + r) >> 1;     if (pos <= m)       updates(ls[root], ls[newroot], l, m, pos, v);     else       updates(rs[root], rs[newroot], m + 1, r, pos, v);   }   long long querys(int lt, int rt, int l, int r, int a, int b) {     if (l == a && r == b) {       return vs[rt] - vs[lt];     }     int m = (l + r) >> 1;     if (b <= m)       return querys(ls[lt], ls[rt], l, m, a, b);     else if (a > m)       return querys(rs[lt], rs[rt], m + 1, r, a, b);     else {       return querys(ls[lt], ls[rt], l, m, a, m) +              querys(rs[lt], rs[rt], m + 1, r, m + 1, b);     }   }   long long val[N << 2];   long long tag[N << 2];   void build(int root, int l, int r) {     val[root] = -INF;     tag[root] = 0;     if (l == r) return;     int m = (l + r) >> 1;     build((root << 1), l, m);     build((root << 1 | 1), m + 1, r);   }   void pushdown(int root) {     long long c = tag[root];     tag[root] = 0;     val[(root << 1)] += c;     tag[(root << 1)] += c;     val[(root << 1 | 1)] += c;     tag[(root << 1 | 1)] += c;   }   void setv(int root, int l, int r, int pos, long long v) {     if (l == r) {       val[root] = v;       return;     }     pushdown(root);     int m = (l + r) >> 1;     if (pos <= m)       setv((root << 1), l, m, pos, v);     else       setv((root << 1 | 1), m + 1, r, pos, v);     val[root] = max(val[(root << 1)], val[(root << 1 | 1)]);   }   void update(int root, int l, int r, int a, int b, long long v) {     if (v == 0) return;     if (a > b) return;     if (l == a && r == b) {       val[root] += v;       tag[root] += v;       return;     }     pushdown(root);     int m = (l + r) >> 1;     if (b <= m)       update((root << 1), l, m, a, b, v);     else if (a > m)       update((root << 1 | 1), m + 1, r, a, b, v);     else {       update((root << 1), l, m, a, m, v);       update((root << 1 | 1), m + 1, r, m + 1, b, v);     }     val[root] = max(val[(root << 1)], val[(root << 1 | 1)]);   }   long long query(int root, int l, int r, int a, int b) {     if (a > b) return -INF;     if (l == a && r == b) return val[root];     pushdown(root);     int m = (l + r) >> 1;     if (b <= m)       return query((root << 1), l, m, a, b);     else if (a > m)       return query((root << 1 | 1), m + 1, r, a, b);     else       return max(query((root << 1), l, m, a, m),                  query((root << 1 | 1), m + 1, r, m + 1, b));   }   bool hasAns() {     int len = 0;     for (int i = 1; i <= n && len < m; i++) {       if (a[i] == b[len + 1]) len++;     }     return len == m;   }   int root[N];   long long lessSum(int l, int r, int v) {     if (l > r || v <= 0) return 0;     return querys(root[l - 1], root[r], 1, n, 1, v);   }   void solve() {     scanf( %d , &n);     root[0] = 0;     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = 1; i <= n; i++) {       scanf( %d , w + i);       updates(root[i - 1], root[i], 1, n, a[i], max(0, w[i]));     }     scanf( %d , &m);     for (int i = 1; i <= m; i++) scanf( %d , b + i), id[b[i]] = i;     for (int i = 1; i <= n; i++) {       if (id[a[i]]) pos[id[a[i]]].push_back(i);     }     if (!hasAns()) {       printf( NO n );       return;     }     printf( YES n );     for (int i = 1; i <= n; i++) dp[i] = -INF;     build(1, 1, n);     for (auto p : pos[m]) {       dp[p] = lessSum(p + 1, n, b[m]) + w[p];       setv(1, 1, n, p, dp[p]);     }     for (int i = m - 1; i >= 1; i--) {       vector<int> vec;       for (auto j : pos[i + 1]) vec.push_back(j);       for (auto j : pos[i]) vec.push_back(j);       sort(vec.begin(), vec.end());       for (int j = (int)vec.size() - 2; j >= 0; j--) {         update(1, 1, n, vec[j + 1], n, lessSum(vec[j] + 1, vec[j + 1] - 1, b[i]));         if (a[vec[j]] == b[i]) {           dp[vec[j]] = query(1, 1, n, vec[j + 1], n) + w[vec[j]];           if (w[vec[j]] > 0) {             update(1, 1, n, vec[j + 1], n, w[vec[j]]);           }         }       }       for (int j = (int)vec.size() - 2; j >= 0; j--) {         update(1, 1, n, vec[j + 1], n,                -lessSum(vec[j] + 1, vec[j + 1] - 1, b[i]));         if (a[vec[j]] == b[i]) {           if (w[vec[j]] > 0) {             update(1, 1, n, vec[j + 1], n, -w[vec[j]]);           }         }       }       for (auto j : pos[i + 1]) {         setv(1, 1, n, j, -INF);       }       assert(val[1] == -INF);       for (auto j : pos[i]) {         setv(1, 1, n, j, dp[j]);       }     }     long long ans = 0;     for (int i = 1; i <= n; i++) ans += w[i];     ans -= val[1];     printf( %lld n , ans);   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long Pow_Mod(long long a, long long b) {     if (b == 0) return 1;     long long tmp = Pow_Mod(a, b / 2);     tmp = (tmp * tmp) % 1000003;     if (b % 2) return (tmp * a) % 1000003;     return tmp;   }   long long C(long long a, long long b) {     if (b == 0 || b == a) return 1;     long long ans = 1;     for (int i = 1; i <= b; i++) {       ans = (ans * (a - i + 1)) % 1000003;       ans = (ans * Pow_Mod(i, 1000003 - 2)) % 1000003;     }     return ans;   }   int main() {     long long a, b;     cin >> a >> b;     a += b;     cout << (C(a, b) - 1 + 1000003) % 1000003 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long t;     cin >> t;     while (t--) {       int n, k, x, rem;       cin >> n >> k;       x = k / (n - 1);       rem = k - x * (n - 1);       if (!rem)         cout << x * n - 1 <<   n ;       else         cout << x * n + rem <<   n ;     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   using namespace std;   using pii = pair<int, int>;   const int MOD = 1e9 + 7, N = 2e3 + 10;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<pair<long long, long long>> v(n);     for (long long i = 0; i < n; i++) {       long long x;       cin >> x;       long long cm = -1;       long long salary;       for (long long i = 0; i < x; i++) {         cin >> salary;         if (salary > cm) cm = salary;       }       v[i].first = cm;       v[i].second = x;     }     sort(v.begin(), v.end());     long long sum = 0;     for (long long i = 0; i < n; i++) {       sum += (v[n - 1].first - v[i].first) * v[i].second;     }     cout << sum;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 123;   const int mod = 1e9 + 9;   int n;   long long k, d;   int a[maxn];   int m;   int L[maxn];   long long t[maxn * 4];   long long ad[maxn * 4];   void build(int v, int l, int r) {     ad[v] = 0;     t[v] = 0;     if (l == r) {     } else {       int mid = (l + r) / 2;       build(v * 2, l, mid);       build(v * 2 + 1, mid + 1, r);     }   }   void push(int v, int tl, int tr) {     if (tl == tr) return;     t[v * 2] += ad[v];     t[v * 2 + 1] += ad[v];     ad[v * 2] += ad[v];     ad[v * 2 + 1] += ad[v];     ad[v] = 0;   }   int get(int v, int tl, int tr, int l, int r, long long k) {     push(v, tl, tr);     if (tl > r || l > tr) {       return -1;     }     if (t[v] > k) {       return -1;     }     if (tl == tr) {       return tl;     }     int mid = (tl + tr) / 2;     int res = get(v * 2, tl, mid, l, r, k);     if (res != -1) return res;     return get(v * 2 + 1, mid + 1, tr, l, r, k);   }   void add(int v, int tl, int tr, int l, int r, long long d) {     push(v, tl, tr);     if (tl > r || l > tr) {       return;     }     if (l <= tl && tr <= r) {       t[v] += d;       ad[v] += d;       return;     }     int mid = (tl + tr) / 2;     add(v * 2, tl, mid, l, r, d);     add(v * 2 + 1, mid + 1, tr, l, r, d);     t[v] = min(t[v * 2], t[v * 2 + 1]);   }   pair<int, int> calc(vector<int> b) {     m = b.size();     map<int, int> c;     for (int i = 0; i < m; i++) {       if (c.count(b[i]) == 0) {         L[i] = 0;       } else {         L[i] = c[b[i]] + 1;       }       c[b[i]] = i;     }     for (int i = 1; i < m; i++) {       L[i] = max(L[i], L[i - 1]);     }     build(1, 0, m - 1);     vector<int> mx;     vector<int> mi;     pair<int, int> ans = make_pair(0, 0);     for (int i = 0; i < m; i++) {       while (mx.size() > 0 && b[mx.back()] < b[i]) {         int cur = mx.back();         mx.pop_back();         if (mx.size() > 0) {           add(1, 0, m - 1, mx.back() + 1, cur, -b[cur]);         } else {           add(1, 0, m - 1, 0, cur, -b[cur]);         }       }       if (mx.size() > 0) {         add(1, 0, m - 1, mx.back() + 1, i, b[i]);       } else {         add(1, 0, m - 1, 0, i, b[i]);       }       mx.push_back(i);       while (mi.size() > 0 && b[mi.back()] > b[i]) {         int cur = mi.back();         mi.pop_back();         if (mi.size() > 0) {           add(1, 0, m - 1, mi.back() + 1, cur, b[cur]);         } else {           add(1, 0, m - 1, 0, cur, b[cur]);         }       }       if (mi.size() > 0) {         add(1, 0, m - 1, mi.back() + 1, i, -b[i]);       } else {         add(1, 0, m - 1, 0, i, -b[i]);       }       mi.push_back(i);       int cnt = i - get(1, 0, m - 1, L[i], i, k) + 1;       if (ans.first < cnt) {         ans.first = cnt;         ans.second = i;       }       add(1, 0, m - 1, 0, i, -1);     }     return ans;   }   void solve() {     cin >> n >> k >> d;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int mi = *min_element(a, a + n);     for (int i = 0; i < n; i++) {       a[i] -= mi;     }     pair<int, int> ans = make_pair(0, 0);     if (d == 0) {       int cnt = 1;       for (int i = 1; i < n; i++) {         if (a[i] != a[i - 1]) {           if (ans.first < cnt) {             ans.first = cnt;             ans.second = i - 1;           }           cnt = 1;         } else {           cnt++;         }       }       if (ans.first < cnt) {         ans.first = cnt;         ans.second = n - 1;       }       cout << ans.second - ans.first + 2 <<     << ans.second + 1 <<   n ;       return;     }     for (int i = 0; i < n;) {       int j = i;       vector<int> cur;       while (i < n && a[j] % d == a[i] % d) {         cur.push_back(a[i] / d);         i++;       }       pair<int, int> res = calc(cur);       res.second += j;       if (res.first > ans.first) {         ans = res;       }     }     cout << ans.second - ans.first + 2 <<     << ans.second + 1 <<   n ;   }   int main() {     int t = 1;     for (int i = 1; i <= t; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 123, BITS = 11, MAX = 7;   int c[N], num[N];   int a[MAX][MAX];   char s[N];   int bit(int x) {     int res = 0;     while (x != 0) {       res += x % 2;       x /= 2;     }     return res;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %s , s);       if (s[0] ==  R ) c[i] = 0;       if (s[0] ==  G ) c[i] = 1;       if (s[0] ==  B ) c[i] = 2;       if (s[0] ==  Y ) c[i] = 3;       if (s[0] ==  W ) c[i] = 4;       num[i] = s[1] -  1 ;     }     int m = 0;     for (int i = 0; i < n; ++i) {       if (a[c[i]][num[i]] == 0) {         ++m;         a[c[i]][num[i]] = 1;       }     }     int ans = 10;     for (int cnt = 0; cnt < (1 << BITS); ++cnt) {       int count = 0;       for (int i = 0; i < 5; ++i) {         for (int j = 0; j < 5; ++j) {           for (int k = 0; k < 5; ++k) {             for (int l = 0; l < 5; ++l) {               if (a[i][j] == 1 && a[k][l] == 1) {                 int tmp = 0;                 if (i != k)                   tmp = ((1 << (i + 5)) & cnt) || ((1 << (k + 5)) & cnt);                 int tmp2 = 0;                 if (j != l) tmp2 = ((1 << j) & cnt) || ((1 << l) & cnt);                 if (tmp || tmp2) ++count;               }             }           }         }       }       if (count == m * (m - 1)) {         int temp = bit(cnt);         if (ans > temp) ans = temp;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool graf[100][100];   int n, m;   bool visited[100];   bool spoken[100];   int stupid;   int tab[100];   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       if (x == 0) stupid++;       for (int j = 0; j < x; j++) {         cin >> tab[j];         tab[j]--;         spoken[tab[j]] = true;       }       for (int j = 0; j < x; j++) {         for (int q = j + 1; q < x; q++) {           graf[tab[j]][tab[q]] = true;           graf[tab[q]][tab[j]] = true;         }       }     }     queue<int> q;     int add = 0;     for (int i = 0; i < m; i++) {       if (!spoken[i] || visited[i]) continue;       q.push(i);       visited[i] = true;       add++;       while (!q.empty()) {         int v = q.front();         q.pop();         for (int j = 0; j < m; j++) {           if (graf[v][j] && !visited[j]) {             visited[j] = true;             q.push(j);           }         }       }     }     if (add > 0) add--;     stupid += add;     cout << stupid << endl;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, n, m, l, t;   bool check(int r) {     if (a + 1ll * b * (r - 1) <= t &&         (1ll * a * (r - l + 1) +          1ll * b * (1ll * r * (r - 1) / 2 - 1ll * (l - 1) * (l - 2) / 2)) <=             1ll * m * t)       return 1;     else       return 0;   }   int main() {     scanf( %d %d %d , &a, &b, &n);     int res;     while (n--) {       scanf( %d %d %d , &l, &t, &m);       res = l;       if (check(res) == 0)         cout <<  -1  << endl;       else {         int low = l;         int mid;         int up = 1000100;         while (low <= up) {           mid = (low + up) / 2;           if (check(mid) == 1) {             res = mid;             low = mid + 1;           } else {             up = mid - 1;           }         }         printf( %d n , res);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int a[100005];   set<long long> present;   int ans;   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     sort(a, a + n);     for (int i = n - 1; i >= 0; i--) {       if (present.find((long long)a[i] * k) == present.end()) {         ans++;         present.insert(a[i]);       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void pp(T v) {     for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)       cout << *it <<    ;     cout << endl;   }   template <class T>   void pp(T v, int n) {     for (int i = 0; i < (int)n; i++) cout << v[i] <<    ;     cout << endl;   }   const int INF = 1 << 28;   const double EPS = 1.0e-9;   bool solve(const vector<pair<int, string> > &data) {     const int n = data.size();     for (int i = 0; i < (int)n; i++) {       if (data[i].first > i) return false;     }     vector<int> height(n);     vector<int> ans;     for (int i = 0, h = n; i < n; i++, h--) {       ans.insert(ans.begin() + data[i].first, i);       height[i] = h;     }     for (int i = 0; i < (int)n; i++) {       cout << data[ans[i]].second <<     << height[ans[i]] << endl;     }     return true;   }   int main(void) {     int n;     cin >> n;     vector<pair<int, string> > data(n);     for (int i = 0; i < (int)n; i++) {       string name;       int a;       cin >> name >> a;       data[i] = make_pair(a, name);     }     sort((data).begin(), (data).end());     bool ans = solve(data);     if (ans == false) cout << -1 << endl;     return 0;   }


// Created by aadi      //  Never give up , Miracles never happen in real life.      #include<bits/stdc++.h>   using namespace std ;   #define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);   #define int long long int   #define MIN LLONG_MIN   #define MAX LLONG_MAX   #define set1D(a,val,n) { for(int i=0;i<n;i++) a[i]=val; }   #define set2D(a,val,n,m) { for(int i=0;i<n;i++) for(int j=0;j<m;j++)a[i][j]=val; }   const double pi = 3.14159265358979323846;   #define endl   n    #define db1(x) cout<<#x<< = <<x<<  n    #define db2(x,y) cout<<#x<< = <<x<< , <<#y<< = <<y<<  n    #define db3(x,y,z) cout<<#x<< = <<x<< , <<#y<< = <<y<< , <<#z<< = <<z<<  n    #define all(x) x.begin(),x.end()         int32_t main() {    //code;    FAST    int tt;    cin >> tt;    while (tt--) {     //write code     int n;     cin >> n;     string a, b;     cin >> a >> b;     int red = 0;     int blue = 0;     for (int i = 0; i < n; i++) {      if (a[i] -  0  > b[i] -  0 ) {       red++;      }      else if (a[i] -  0  < b[i] -  0 ) {       blue++;      }     }     if (red > blue) {      cout <<  RED ;     }     else if (blue > red) {      cout <<  BLUE ;     }     else {      cout <<  EQUAL ;     }     cout << endl;    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &t) {     t = 0;     char ch = getchar();     int f = 1;     while ( 0  > ch || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     do {       (t *= 10) += ch -  0 ;       ch = getchar();     } while ( 0  <= ch && ch <=  9 );     t *= f;   }   int n, pos, ans[2010], vis[2010];   struct node {     long long x, y;     bool operator<(node t) {       if (x != t.x) return y < t.y;       return x < t.x;     }     node operator-(node t) { return (node){x - t.x, y - t.y}; }     long long operator*(node t) { return x * t.y - y * t.x; }   } d[2010];   long long t;   char s[2010];   int main() {     read(n);     for (int i = 1; i <= n; i++) read(d[i].x), read(d[i].y);     scanf( %s , s + 1);     for (int i = 1; i <= n; i++)       if (!pos || d[i] < d[pos]) pos = i;     ans[1] = pos;     vis[pos] = 1;     int tmp;     for (int i = 2; i < n; i++) {       tmp = 0;       for (int j = 1; j <= n; j++)         if (!vis[j]) {           t = (d[j] - d[pos]) * (d[tmp] - d[pos]);           if (!tmp || (s[i - 1] ==  L  && t > 0) || (s[i - 1] ==  R  && t < 0))             tmp = j;         }       ans[i] = pos = tmp;       vis[pos] = 1;     }     for (int i = 1; i <= n; i++)       if (!vis[i]) {         ans[n] = i;         break;       }     for (int i = 1; i <= n; i++) printf( %d  , ans[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T0, typename T1>   std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) {     for (typename map<T0, T1>::const_iterator p = v.begin(); p != v.end(); p++) {       os << p->first <<  :   << p->second <<    ;     }     return os;   }   template <typename T0, typename T1>   std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) {     os << v.first <<  :   << v.second <<    ;     return os;   }   template <typename T>   std::ostream& operator<<(std::ostream& os, const vector<T>& v) {     for (int i = 0; i < (int)v.size(); i++) {       os << v[i] <<    ;     }     return os;   }   template <typename T>   std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) {     for (int i = 0; i < (int)v.size(); i++) {       os << v[i] << endl;     }     return os;   }   template <typename T>   std::ostream& operator<<(std::ostream& os, const set<T>& v) {     vector<T> tmp(v.begin(), v.end());     os << tmp;     return os;   }   template <typename T>   std::ostream& operator<<(std::ostream& os, const deque<T>& v) {     vector<T> tmp(v.begin(), v.end());     os << tmp;     return os;   }   int main() {     long long N, W, H;     while (cin >> H >> W) {       vector<string> w(H);       for (int y = 0, _n = (H); (y) < (int)_n; ++y) cin >> w[y];       vector<vector<long long> > tb(H, vector<long long>(W));       vector<vector<long long> > tbX(H, vector<long long>(W));       vector<vector<long long> > tbY(H, vector<long long>(W));       for (int y = 0, _n = (H); (y) < (int)_n; ++y)         for (int x = 0, _n = (W); (x) < (int)_n; ++x) {           {             long long v = 0;             if (0 <= y - 1) v += tb[y - 1][x];             if (0 <= y - 1 && w[y - 1][x] ==  .  && w[y][x] ==  . ) v++;             if (0 <= x - 1) v += tb[y][x - 1];             if (0 <= x - 1 && w[y][x - 1] ==  .  && w[y][x] ==  . ) v++;             if (0 <= x - 1 && 0 <= y - 1) v -= tb[y - 1][x - 1];             tb[y][x] = v;           }           {             long long v = 0;             if (0 <= x - 1) v += tbY[y][x - 1];             if (0 <= y - 1 && w[y - 1][x] ==  .  && w[y][x] ==  . ) v++;             tbY[y][x] = v;           }           {             long long v = 0;             if (0 <= y - 1) v += tbX[y - 1][x];             if (0 <= x - 1 && w[y][x - 1] ==  .  && w[y][x] ==  . ) v++;             tbX[y][x] = v;           }         }       cin >> N;       for (int i = 0, _n = (N); (i) < (int)_n; ++i) {         long long y1, x1, y2, x2;         cin >> y1 >> x1 >> y2 >> x2;         y1--;         x1--;         y2--;         x2--;         long long v = tb[y2][x2];         if (0 <= y1 - 1) v -= tb[y1 - 1][x2];         {           long long vv = tbY[y1][x2];           if (0 <= x1 - 1) vv -= tbY[y1][x1 - 1];           v -= vv;         }         if (0 <= x1 - 1) v -= tb[y2][x1 - 1];         {           long long vv = tbX[y2][x1];           if (0 <= y1 - 1) vv -= tbX[y1 - 1][x1];           v -= vv;         }         if (0 <= x1 - 1 && 0 <= y1 - 1) v += tb[y1 - 1][x1 - 1];         cout << v << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   int n, g, p, d, a, b, act, nxt;   long long res;   int Next[(1000000 + 6)];   pair<int, int> Stacje[(1000000 + 6)];   stack<int> S;   int main() {     scanf( %d %d %d , &d, &g, &n);     p = g;     for (int i = 1; i <= n; i++) {       scanf( %d %d , &a, &b);       Stacje[i] = make_pair(a, b);     }     Stacje[0] = make_pair(0, INF);     Stacje[n + 1] = make_pair(d, -INF);     sort(Stacje + 1, Stacje + n + 1);     for (int i = n + 1; i >= 0; i--) {       while (!S.empty() && Stacje[S.top()].second > Stacje[i].second) {         S.pop();       }       Next[i] = S.empty() ? -1 : S.top();       S.push(i);     }     while (act != n + 1) {       if (Stacje[Next[act]].first - Stacje[act].first <= g) {         int dis = Stacje[Next[act]].first - Stacje[act].first;         p -= dis;         if (p < 0) {           res += (-p) * (long long)Stacje[act].second;           p = 0;         }         act = Next[act];       } else {         int dis = Stacje[act + 1].first - Stacje[act].first;         if (dis > g) {           break;         }         res += (g - p) * (long long)Stacje[act].second;         p = g - dis;         act++;       }     }     printf( %lld n , act != n + 1 ? -1 : res);   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     char c = getchar();     T sig = 1;     for (; !isdigit(c); c = getchar())       if (c ==  - ) sig = -1;     for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c -  0 ;     x *= sig;   }   class Solution {    public:     void solve() {       int n;       read(n);       string s;       cin >> s;       string t(s);       for (int i = 0; i < n; ++i)         if (s[i] ==  ? ) s[i] =  0 , t[i] =  1 ;       vector<int> p(n + 2), q(n + 2);       for (int i = n; i >= 1; --i)         p[i] = s[i - 1] ==  0  ? p[i + 1] + 1 : 0,         q[i] = t[i - 1] ==  1  ? q[i + 1] + 1 : 0;       vector<int> np(n + 1), nq(n + 1);       for (int i = n, pp = 0x3f3f3f3f, qq = 0x3f3f3f3f, npp = 0x3f3f3f3f,                nqq = 0x3f3f3f3f;            i >= 1; --i) {         if (s[i - 1] ==  0 ) pp = i;         if (s[i - 1] ==  1 ) npp = pp;         np[i] = npp;         if (t[i - 1] ==  0 ) nqq = qq;         if (t[i - 1] ==  1 ) qq = i;         nq[i] = nqq;       }       printf( %d  , n);       for (int i = 2; i <= n; ++i) {         int cnt = 0, idx = 1, last = 0;         while (idx + i - 1 <= n) {           int delta = max(p[idx], q[idx]);           if (p[idx] <= i && np[last] == idx) np[last] = np[idx];           if (q[idx] <= i && nq[last] == idx) nq[last] = nq[idx];           last = idx;           if (delta >= i)             cnt += delta / i, idx += delta / i * i;           else             idx = min(np[idx], nq[idx]);         }         printf( %d  , cnt);       }     }   };   int main() {     Solution solution = Solution();     solution.solve();   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   template <typename T>   static T aabs(T x) {     if (x < 0) return -x;     return x;   }   template <typename T>   static void read(T &S) {     char K[1000009];     scanf( %s , &K);     S = K;   }   template <typename T, typename U>   static void amax(T &x, U y) {     if (x < y) x = y;   }   template <typename T, typename U>   static void amin(T &x, U y) {     if (x > y) x = y;   }   template <typename T, typename U>   static void aswap(T &x, U &y) {     T temp;     temp = x;     x = y;     y = temp;   }   template <typename T, typename U>   static long long gcd(T a, U b) {     long long r;     while (b) {       r = a % b;       a = b;       b = r;     }     return a;   }   template <typename T, typename U>   static long long lcm(T a, U b) {     return a / gcd(a, b) * b;   }   template <typename T, typename U>   static long long fpow(T n, U k, int p = MOD) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   const int N5 = 100009;   const int N6 = 1000009;   int st[2 * N5 * 4];   string s;   set<int> mst[200];   void build(int id, int l, int r) {     if (l == r) {       st[id] = 1;       return;     }     int mid = (l + r) / 2;     build(id * 2, l, mid);     build(id * 2 + 1, mid + 1, r);     st[id] = st[id * 2] + st[id * 2 + 1];   }   void update(int id, int l, int r, int pos, int value) {     if (r < pos || l > pos) return;     if (l == r) {       st[id] = value;       return;     }     int mid = (l + r) / 2;     update(id * 2, l, mid, pos, value);     update(id * 2 + 1, mid + 1, r, pos, value);     st[id] = st[id * 2] + st[id * 2 + 1];   }   int query(int id, int l, int r, int pos) {     if (l == r) return l;     int mid;     mid = (l + r) / 2;     if (pos > st[id * 2])       query(id * 2 + 1, mid + 1, r, pos - st[id * 2]);     else       query(id * 2, l, mid, pos);   }   void finish(int id, int l, int r) {     if (l == r) {       if (st[id]) printf( %c , s[l]);       return;     }     int mid;     mid = (l + r) / 2;     finish(id * 2, l, mid);     finish(id * 2 + 1, mid + 1, r);   }   int conv(char c) {     if (c >=  a  && c <=  z ) return c -  a ;     if (c >=  A  && c <=  z ) return c -  A  + 27;     return c -  0  + 55;   }   int main() {     int n, q;     scanf( %d%d , &n, &q);     string ss;     read(ss);     s =     + ss;     for (int i = 1; i <= n; i++) mst[conv(s[i])].insert(i);     for (int i = 0; i <= 100; i++) mst[i].insert(n + 1);     build(1, 1, n);     while (q--) {       int l, r;       string re;       char ch;       scanf( %d%d , &l, &r);       read(re);       ch = re[0];       l = query(1, 1, n, l);       r = query(1, 1, n, r);       set<int>::iterator it, ait;       it = mst[conv(ch)].lower_bound(l);       while (*it <= r) {         update(1, 1, n, *it, 0);         ait = it;         ++it;         mst[conv(ch)].erase(ait);       }     }     finish(1, 1, n);     return 0;     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     int S = 0;     for (int i = 1; S < n; ++i) S += i;     puts(S == n ?  YES  :  NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 2000000000;   struct pkt {     int k, r;   };   struct prze {     int k, r1, r2;   };   bool porownanie(pkt a, pkt b) {     if (a.k < b.k) return true;     if (a.k > b.k) return false;     if (a.r < b.r) return true;     return false;   }   int main() {     ios_base::sync_with_stdio(0);     int n, m;     cin >> n >> m;     vector<pkt> pkty(m);     for (int i = 0; i < m; ++i) {       cin >> pkty[i].r >> pkty[i].k;       --pkty[i].r;       --pkty[i].k;     }     sort(pkty.begin(), pkty.end(), porownanie);     vector<vector<prze> > zab;     for (int L = 0; L < m;) {       int P = L;       while (P < m && pkty[L].k == pkty[P].k) ++P;       --P;       vector<prze> t;       for (int l = L; l <= P;) {         int p = l;         while (p <= P && pkty[p].r - pkty[l].r == p - l) ++p;         --p;         t.push_back({pkty[l].k, pkty[l].r, pkty[p].r});         l = p + 1;       }       zab.push_back(t);       L = P + 1;     }     for (int i = 0; i < zab.size(); ++i) {       if (zab[i].size() == 1 && zab[i][0].r1 == 0 && zab[i][0].r2 == n - 1) {         cout <<  -1 ;         return 0;       }     }     vector<vector<prze> > doz;     if (zab[0][0].k != 0) {       vector<prze> t;       t.push_back({0, 0, n - 1});       doz.push_back(t);     }     for (int i = 0; i < zab.size(); ++i) {       if (i != 0) {         if (zab[i - 1][0].k != zab[i][0].k - 1) {           vector<prze> t;           t.push_back({zab[i][0].k - 1, 0, n - 1});           doz.push_back(t);         }       }       int ile_prze = zab[i].size();       vector<prze> t;       if (zab[i][0].r1 - 1 >= 0) t.push_back({zab[i][0].k, 0, zab[i][0].r1 - 1});       for (int j = 0; j < ile_prze - 1; ++j)         t.push_back({zab[i][0].k, zab[i][j].r2 + 1, zab[i][j + 1].r1 - 1});       if (zab[i][ile_prze - 1].r2 < n - 1)         t.push_back({zab[i][0].k, zab[i][ile_prze - 1].r2 + 1, n - 1});       doz.push_back(t);     }     if (zab.back()[0].k != n - 1) {       vector<prze> t;       t.push_back({n - 1, 0, n - 1});       doz.push_back(t);     }     zab.clear();     vector<vector<int> > lo(doz.size());     for (int i = 0; i < doz.size(); ++i)       for (int j = 0; j < doz[i].size(); ++j) lo[i].push_back(INF);     for (int i = 0; i < lo[0].size(); ++i) {       if (i == 0)         lo[0][i] = 0;       else         lo[0][i] = INF;     }     for (int i = 1; i < doz.size(); ++i) {       vector<int> g(doz[i].size(), INF);       int k = 0;       for (int j = 0; j < doz[i].size(); ++j) {         while (k < doz[i - 1].size() && doz[i - 1][k].r2 < doz[i][j].r1) ++k;         if (k < doz[i - 1].size()) g[j] = k;       }       vector<int> d(doz[i].size(), INF);       k = doz[i - 1].size() - 1;       for (int j = doz[i].size() - 1; j >= 0; --j) {         while (k >= 0 && doz[i - 1][k].r1 > doz[i][j].r2) --k;         if (k >= 0) d[j] = k;       }       for (int j = 0; j < doz[i].size(); ++j) {         if (d[j] != INF && g[j] != INF && g[j] <= d[j]) {           for (int k = g[j]; k <= d[j]; ++k) {             if (lo[i - 1][k] != INF) {               if (lo[i - 1][k] < doz[i][j].r1)                 lo[i][j] = min(lo[i][j], doz[i][j].r1);               else {                 if (lo[i - 1][k] <= doz[i][j].r2)                   lo[i][j] = min(lo[i][j], lo[i - 1][k]);               }             }           }         }       }     }     int x = doz.size();     int y = doz[x - 1].size();     if (doz[x - 1][y - 1].r2 == n - 1 && lo[x - 1][y - 1] != INF)       cout << 2 * (n - 1);     else       cout <<  -1 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxi = 1e6 + 10;   const long long mo = 1e9 + 7;   long long a[maxi];   long long m, l, r, k;   string s;   vector<int> v[maxi];   long long mat[53][3][3];   void mul_mat(int idx1, int idx2, int idx) {     for (int i = 1; i <= 2; i++)       for (int j = 1; j <= 2; j++)         for (int k = 1; k <= 2; k++)           mat[idx][i][j] += mat[idx1][i][k] * mat[idx2][k][j];     for (int i = 1; i <= 2; i++)       for (int j = 1; j <= 2; j++) mat[idx][i][j] %= m;   }   void fib(long long x) {     long long fi = 1;     long long fj = 1;     mat[51][1][1] = 1;     mat[51][2][2] = 1;     for (int i = 0; i <= 50; i++)       if (x & (1ll << i)) {         mul_mat(i, 51, 52);         for (int j = 1; j <= 2; j++)           for (int o = 1; o <= 2; o++) {             mat[51][j][o] = mat[52][j][o];             mat[52][j][o] = 0;           }       }     cout << mat[51][2][1] << endl;     return;   }   int main() {     cin >> m >> l >> r >> k;     long long x = 1;     mat[0][1][1] = 1;     mat[0][1][2] = 1;     mat[0][2][1] = 1;     mat[0][2][2] = 0;     for (long long i = 1; i * i <= r; i++) {       long long last = r / i;       long long first = (r / (i + 1)) + 1;       if (i - k >= 0) {         long long val = i - k;         long long li = last;         long long ri = first + 1;         while (li < ri - 1) {           long long mid = (li + ri) / 2;           if ((l - 1) / mid <= val)             li = mid;           else             ri = mid;         }         if ((l - 1) / li <= val) {           x = max(x, li);         }       }     }     long long sqr = floor(sqrt(r));     for (long long num = sqr; num > 0; num--) {       long long i = r / num;       long long last = r / i;       long long first = r / (i + 1) + 1;       if (i - k >= 0) {         long long val = i - k;         long long li = last;         long long ri = first + 1;         while (li < ri - 1) {           long long mid = (li + ri) / 2;           if ((l - 1) / mid <= val)             li = mid;           else             ri = mid;         }         if ((l - 1) / li <= val) {           x = max(x, li);         }       }     }     for (int i = 1; i <= 50; i++) mul_mat(i - 1, i - 1, i);     fib(x);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long read() {     char c = getchar();     long long x = 1;     long long s = 0;     while (c <  0  || c >  9 ) {       if (c ==  - ) x = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       s = s * 10 + c -  0 ;       c = getchar();     }     return s * x;   }   const long long N = 4e5 + 5;   vector<long long> v[N];   long long n, x, y, siz[N], tong;   void dfs(long long u, long long fa) {     long long cnt = 1, tmp = 0;     for (unsigned long long i = 0; i < v[u].size(); i++) {       if (v[u][i] == fa) continue;       dfs(v[u][i], u);       cnt++;       if (siz[v[u][i]] == 1) tmp++;     }     siz[u] = cnt;     if (tmp) {       tong = tong + tmp - 1;     } else {       siz[u] = 1;     }   }   void solve() {     n = read();     for (long long i = 1; i < n; i++) {       x = read();       y = read();       v[x].push_back(y);       v[y].push_back(x);     }     if (n == 2) {       cout << 1 <<   n ;     } else {       dfs(1, 0);       cout << tong + 1 <<   n ;     }     for (long long i = 1; i <= n; i++) v[i].clear(), siz[i] = 0;     tong = 0;   }   signed main() {     long long T;     cin >> T;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1100;   const long long MOD = 998244353;   int N, K;   int arr[MAXN];   int dp[MAXN][MAXN];   int ps[MAXN][MAXN];   long long figure(int k) {     if (k * (K - 1) > arr[N - 1]) return 0;     for (int i = 0; i <= N; i++)       for (int j = 0; j <= K; j++) dp[i][j] = ps[i][j] = 0;     for (int i = 1; i <= N; i++) dp[i][1] = 1;     int cstop = 0;     for (int i = 0; i < N; i++) {       while (cstop < i && arr[i] - arr[cstop] >= k) cstop++;       for (int j = 1; j < K; j++) {         dp[i + 1][j + 1] = ps[cstop][j];       }       for (int j = 0; j <= K; j++) {         ps[i + 1][j] = (ps[i][j] + dp[i + 1][j]) % MOD;       }     }     return ps[N][K];   }   int main() {     ios_base::sync_with_stdio(0);     cin >> N >> K;     for (int i = 0; i < N; i++) cin >> arr[i];     sort(arr, arr + N);     long long ans = 0;     for (int i = 1; i <= 100000; i++) ans = (ans + figure(i)) % MOD;     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200010;   inline int gi() {     register int x = 0;     register char c = getchar();     bool f = 0;     while (c !=  -  && (c <  0  || c >  9 )) c = getchar();     if (c ==  - ) c = getchar(), f = 1;     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return f ? -x : x;   }   struct node {     int to, next;   } g[N << 1];   int last[N], gl;   inline void add(int x, int y) {     g[++gl] = (node){y, last[x]};     last[x] = gl;     return;   }   int sum, f[N], siz[N], rt;   bool vis[N];   void getroot(int u, int fa) {     siz[u] = 1;     f[u] = 0;     for (int i = last[u]; i; i = g[i].next) {       int v = g[i].to;       if (v == fa || vis[v]) continue;       getroot(v, u);       f[u] = max(f[u], siz[v]);       siz[u] += siz[v];     }     f[u] = max(f[u], sum - siz[u]);     if (f[rt] > f[u]) rt = u;     return;   }   char a[N];   int s[N], t[10050000];   void dfs(int x, int fa, int p, int S) {     t[S ^= (1 << s[x])] += p;     for (int i = last[x]; i; i = g[i].next) {       int v = g[i].to;       if (v == fa || vis[v]) continue;       dfs(v, x, p, S);     }   }   long long ans[N];   long long calc(int x, int fa, int S) {     S ^= (1 << s[x]);     long long cnt = t[S];     for (int i = 0; i < 20; i++) cnt += t[S ^ (1 << i)];     for (int i = last[x]; i; i = g[i].next) {       int v = g[i].to;       if (v == fa || vis[v]) continue;       cnt += calc(v, x, S);     }     ans[x] += cnt;     return cnt;   }   void solve(int x) {     vis[x] = 1;     dfs(x, 0, 1, 0);     long long cnt = t[0];     for (int i = 0; i < 20; i++) cnt += t[1 << i];     for (int i = last[x]; i; i = g[i].next) {       int v = g[i].to;       if (vis[v]) continue;       dfs(v, x, -1, 1 << s[x]);       cnt += calc(v, x, 0);       dfs(v, x, 1, 1 << s[x]);     }     dfs(x, 0, -1, 0);     ans[x] += cnt / 2;     for (int i = last[x]; i; i = g[i].next) {       int v = g[i].to;       if (vis[v]) continue;       sum = siz[v];       rt = 0;       getroot(v, 0);       solve(rt);     }     return;   }   int main() {     int n = gi();     for (int i = 1; i < n; i++) {       int u = gi(), v = gi();       add(u, v);       add(v, u);     }     scanf( %s , a);     for (int i = 0; i < n; i++) s[i + 1] = a[i] -  a ;     f[0] = sum = n;     rt = 0;     getroot(1, 0);     solve(rt);     for (int i = 1; i <= n; i++) printf( %lld  , ans[i] + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int r[200], l[200];   int main() {     memset(l, 10, sizeof(l));     memset(r, -1, sizeof(r));     cin.sync_with_stdio(false);     cin >> n >> m;     string s;     int w = 0;     for (int i = 0; i < n; ++i) {       cin >> s;       for (int j = 0; j < m; ++j)         if (s[j] ==  W ) {           if (l[i] > m) l[i] = j;           r[i] = j;           w++;         }     }     if (!w) {       cout << 0;       return 0;     }     int e = 0;     for (int i = n - 1; i >= 0; --i)       if (l[i] < m) {         e = i + 1;         break;       }     int j = 0;     int res = 0;     for (int i = 0; i < n; ++i) {       if (i == e) {         --res;         break;       }       if (i & 1) {         if (i == n - 1)           res += j - l[i];         else {           int k = min(l[i], l[i + 1]);           if (k >= m) k = j;           res += abs(j - k) + 1;           j = k;         }       } else {         if (i == n - 1)           res += r[i] - j;         else {           int k = max(r[i], r[i + 1]);           if (k == -1) k = j;           res += abs(k - j) + 1;           j = k;         }       }     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class A, class B>   istream &operator>>(istream &o, pair<A, B> &p) {     o >> p.first >> p.second;     return o;   }   template <class type>   istream &operator>>(istream &o, vector<type> &v) {     for (int i = 0; i < (int)v.size(); i++) o >> v[i];     return o;   }   template <class A, class B>   ostream &operator<<(ostream &o, pair<A, B> p) {     o <<  (  << p.first <<  ,  << p.second <<  ) ;     return o;   }   template <class type>   ostream &operator<<(ostream &o, vector<type> v) {     o <<  { ;     for (int i = 0; i < (int)v.size(); i++) {       if (i > 0) o <<  , ;       o << v[i];     }     o <<  } ;     return o;   }   long long toNum(string a) {     if (a.size() == 0u) return 0;     long long ret = 0;     for (int i = (a[0] ==  - ); i < int(a.size()); i++)       ret = ret * 10 + a[i] -  0 ;     return ret * (a[0] ==  -  ? -1 : 1);   }   string toStr(long long a) {     string ret =   ;     bool sgn = a < 0;     a = a < 0 ? -a : a;     do {       ret.push_back(a % 10 +  0 );       a /= 10;     } while (a > 0);     if (sgn) ret.push_back( - );     reverse(ret.begin(), ret.end());     return ret;   }   int dp[1005][2][2];   vector<int> cost, a, b;   int countCost(int a, int t) {     switch (t) {       case 0:         return a * cost[t];       default:         return cost[t];     }   }   int solve(int n, int bs, int tr) {     if (n < 0) return 0;     if (bs == 1 && tr == 1) return 0;     int &ret = dp[n][bs][tr];     if (ret != -1) return ret;     ret = (1 << 30);     for (int i = 0; i < int(3); i++)       for (int j = 0; j < int(3); j++) {         int t = countCost(a[n] * (!bs), i) + countCost(b[n] * (!tr), j);         ret = min(ret, t + solve(n - 1, (i == 2) || bs, (j == 2) || tr));       }     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     cost = vector<int>(4);     cin >> cost;     int m, n;     cin >> m >> n;     a = b = vector<int>(max(m, n));     for (int i = 0; i < int(m); i++) cin >> a[i];     for (int i = 0; i < int(n); i++) cin >> b[i];     n = max(m, n);     memset(dp, -1, sizeof(dp));     cout << min(cost[3], solve(n - 1, 0, 0));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int S = 1003;   bool a[S];   bool b[S];   string s;   int k;   int i, j;   int main() {     cin >> s;     j = s.size() - 1;     while (i < j) {       if (s[i] ==  (  && s[j] ==  ) ) {         b[i] = 1;         b[j] = 1;         k++;         i++;         j--;       } else {         if (s[i] ==  ) ) i++;         if (s[j] ==  ( ) j--;       }     }     if (k == 0) {       cout <<  0 ;       return 0;     };     cout << 1 << endl;     cout << 2 * k << endl;     for (int i = 0; i < s.size(); i++)       if (b[i]) cout << i + 1 <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > b, c;   map<vector<pair<int, int> >, int> d;   ;   int n, m, ask, a[100086];   long long ans;   int main() {     scanf( %d %d , &n, &m);     ans = 0ll;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       b.clear();       c.clear();       int qs = a[i];       for (int j = 2; j * j <= qs; j++) {         if (a[i] % j == 0) {           int sum = 0;           while (a[i] % j == 0) {             a[i] /= j;             sum++;           }           sum %= m;           if (sum) {             b.push_back(make_pair(j, sum));             c.push_back(make_pair(j, m - sum));           }         }       }       if (a[i] > 1) {         b.push_back(make_pair(a[i], 1));         c.push_back(make_pair(a[i], m - 1));       }       ans = ans + 1ll * d[c];       d[b]++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long _pow(long long base, long long exp) {     return exp == 0 ? 1 : base * _pow(base, exp - 1);   }   string int_to_str(int x) {     string xs;     stringstream ss;     ss << x;     xs = ss.str();     return xs;   }   int str_vec_find(string x, vector<string> y) {     vector<string>::iterator it;     it = find(y.begin(), y.end(), x);     int pos = distance(y.begin(), it);     return pos;   }   int main() {     long long temp, tempa, tempb, maxa, maxb;     vector<long long> a, b;     int n;     cin >> n;     maxa = maxb = -1;     for (int i = 0; i < n; i++) {       cin >> tempa >> tempb;       if (tempa >= maxa) maxa = tempa;       if (tempb >= maxb) maxb = tempb;       a.push_back(tempa);       b.push_back(tempb);     }     for (int w = 0; w < b.size(); w++) {       for (int r = 0; r < b.size() - 1; r++) {         if (a[r] > a[r + 1]) {           temp = a[r];           a[r] = a[r + 1];           a[r + 1] = temp;           temp = b[r];           b[r] = b[r + 1];           b[r + 1] = temp;         }       }     }     if (n == 1)       cout << maxb << endl;     else {       long long stamp = b[0];       for (int i = 1; i < n; i++) {         if (b[i] >= stamp)           stamp = b[i];         else {           if (a[i] != a[i - 1]) stamp = a[i];         }       }       cout << stamp << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long nc2[(int)1e5];   void pre() {     for (long long i = 1; i < 1e5; ++i) {       nc2[i] = i * (i - 1) / 2;     }   }   int binSearch(int l, int r, int val) {     while (l <= r) {       int mid = (l + r) / 2;       if (nc2[mid] == val)         return mid;       else if (nc2[mid] < val)         l = mid + 1;       else         r = mid - 1;     }     return -1;   }   bool isPossible(int a00, int a01, int a10, int a11, int n, int m) {     if (a10 + a01 != n * m or abs(a10 - a01) % 2 != n * m % 2) {       return false;     }     if (!n) {       for (int i = 0; i < m; ++i) cout << 0;       return true;     }     if (!m) {       for (int i = 0; i < n; ++i) cout << 1;       return true;     }     for (int i = 0; i < a01 / n; ++i) cout << 0;     for (int i = 0; i < n - (a01 % n); ++i) cout << 1;     if (a01 / n < m) cout << 0;     for (int i = 0; i < a01 % n; ++i) cout << 1;     for (int i = 0; i < (m - a01 / n - 1); ++i) cout << 0;     return true;   }   int main() {     pre();     int a00, a01, a10, a11;     cin >> a00 >> a01 >> a10 >> a11;     int n = binSearch(1, 1e5 - 1, a11), m = binSearch(1, 1e5 - 1, a00);     if (n == -1 or m == -1 or (n == 0 and m == 0)) {       cout <<  Impossible ;       return 0;     }     if (!n) {       for (int i = 0; i < m; ++i) cout << 0;       return 0;     }     if (!m) {       for (int i = 0; i < n; ++i) cout << 1;       return 0;     }     bool ans = false;     if (n == 1 and m == 1) {       ans = ans or isPossible(a00, a01, a10, a11, n, m) or             isPossible(a00, a01, a10, a11, n, 0) or             isPossible(a00, a01, a10, a11, 0, m);       if (!ans) cout <<  Impossible ;     } else if (n == 1) {       ans = ans or isPossible(a00, a01, a10, a11, 0, m) or             isPossible(a00, a01, a10, a11, n, m);       if (!ans) cout <<  Impossible ;     } else if (m == 1) {       ans = ans or isPossible(a00, a01, a10, a11, n, 0) or             isPossible(a00, a01, a10, a11, n, m);       if (!ans) cout <<  Impossible ;     } else {       ans = isPossible(a00, a01, a10, a11, n, m);       if (!ans) cout <<  Impossible ;     }   }