#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k;     cin >> n >> k;     if (n / k % 2 == 0) {       cout <<  NO ;     } else {       cout <<  YES ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int n;   int A[N];   int main() {     int t;     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       n *= 2;       for (int i = 1; i <= n; i++) {         scanf( %d , &A[i]);       }       sort(A + 1, A + 1 + n);       n /= 2;       printf( %d n , A[n + 1] - A[n]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1.12e5;   const int LEN = 6.4 * N;   int len;   int c[N], sz[N];   int s[LEN], sa[LEN], *rk, ht[LEN], v[2][LEN], ct[LEN];   long long co[LEN];   void build_sa(int n, int m) {     int *x = v[0], *y = v[1];     fill_n(ct, m, 0);     for (int i = (0); i != (n); ++i) ++ct[x[i] = s[i]];     for (int i = (1); i != (m); ++i) ct[i] += ct[i - 1];     for (int i = (n - 1); i != (-1); --i) sa[--ct[x[i]]] = i;     for (int k = 1; k < n; k <<= 1) {       int p = 0;       for (int i = (n - k); i != (n); ++i) y[p++] = i;       for (int i = (0); i != (n); ++i)         if (sa[i] >= k) y[p++] = sa[i] - k;       fill_n(ct, m, 0);       for (int i = (0); i != (n); ++i) ++ct[x[y[i]]];       for (int i = (1); i != (n); ++i) ct[i] += ct[i - 1];       for (int i = (n - 1); i != (-1); --i) sa[--ct[x[y[i]]]] = y[i];       swap(x, y);       x[sa[0]] = 0;       p = 1;       for (int i = (1); i != (n); ++i)         x[sa[i]] = y[sa[i]] == y[sa[i - 1]] && y[sa[i] + k] == y[sa[i - 1] + k]                        ? p - 1                        : p++;       if ((m = p) == n) {         rk = x;         break;       }     }     int h = 0;     ht[0] = 0;     for (int i = (0); i != (n); ++i) {       if (!rk[i]) {         h = 0;         continue;       }       while (s[i + h] == s[sa[rk[i] - 1] + h]) ++h;       ht[rk[i]] = h;       if (h) --h;     }   }   int ls[LEN], rs[LEN];   int min(int a, int b) { return a < b ? a : b; }   int max(int a, int b) { return a > b ? a : b; }   typedef int (*func)(int, int);   struct BIT {     func f;     int t[LEN], v;     void init(func _f, int _v) {       f = _f;       v = _v;       fill_n(t, len + 1, v);     }     void add(int i, int x) {       for (; i <= len; i += i & -i) t[i] = f(t[i], x);     }     int qry(int i) {       int ret = v;       for (; i; i ^= i & -i) ret = f(ret, t[i]);       return ret;     }   } bit;   int main() {     int n;     scanf( %d  , &n);     len = 0;     for (int i = (0); i != (n); ++i) {       int ch;       int la = len;       while ((ch = getchar()) !=   n ) s[len++] = n + ch -  a ;       sz[i] = len - la;       s[len++] = i;     }     long long ans = 0;     for (int i = (0); i != (n); ++i) scanf( %d , c + i);     build_sa(len, n + 26);     int la = 0;     for (int i = (0); i != (n); ++i) {       if (ht[rk[la]] != sz[i] && ht[rk[la] + 1] != sz[i])         ans = max(ans, sz[i] * 1LL * c[i]);       la += sz[i] + 1;     }     int idx = n - 1;     for (int i = (len - 1); i != (-1); --i) co[rk[i]] = c[idx = min(idx, s[i])];     for (int i = (1); i != (len); ++i) co[i] += co[i - 1];     bit.init(max, -1);     for (int i = (0); i != (len); ++i) {       ls[i] = bit.qry(ht[i]);       bit.add(ht[i] + 1, i);     }     bit.init(min, len);     for (int i = (len - 1); i != (-1); --i) {       rs[i] = bit.qry(ht[i]);       bit.add(ht[i] + 1, i);     }     for (int i = (0); i != (len); ++i)       if (ht[i]) ans = max(ans, ht[i] * (co[rs[i] - 1] - co[ls[i] - 1]));     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   long long tree[400020][21], lazy[400020][21], arr[100005];   void build(int l, int r, int node, int i) {     if (l == r) {       tree[node][i] = 0;       if (arr[l] & (1 << i)) {         tree[node][i] = 1;       }       return;     }     int mid = (l + r) >> 1;     build(l, mid, 2 * node, i);     build(mid + 1, r, 2 * node + 1, i);     tree[node][i] = tree[2 * node][i] + tree[2 * node + 1][i];     return;   }   void update(int l, int r, int ql, int qr, int node, int i) {     if (lazy[node][i]) {       tree[node][i] = (r - l + 1) - tree[node][i];       if (l != r) {         lazy[2 * node][i] ^= 1;         lazy[2 * node + 1][i] ^= 1;       }       lazy[node][i] = 0;     }     if (l > qr || r < ql) return;     if (ql <= l && r <= qr) {       tree[node][i] = (r - l + 1) - tree[node][i];       if (l != r) {         lazy[2 * node][i] ^= 1;         lazy[2 * node + 1][i] ^= 1;       }       lazy[node][i] = 0;       return;     }     int mid = (l + r) >> 1;     update(l, mid, ql, qr, 2 * node, i);     update(mid + 1, r, ql, qr, 2 * node + 1, i);     tree[node][i] = tree[2 * node][i] + tree[2 * node + 1][i];     return;   }   long long query(int l, int r, int ql, int qr, int node, int i) {     if (lazy[node][i]) {       tree[node][i] = (r - l + 1) - tree[node][i];       if (l != r) {         lazy[2 * node][i] ^= 1;         lazy[2 * node + 1][i] ^= 1;       }       lazy[node][i] = 0;     }     if (l > qr || r < ql) return 0;     if (ql <= l && r <= qr) return tree[node][i];     int mid = (l + r) >> 1;     return query(l, mid, ql, qr, 2 * node, i) +            query(mid + 1, r, ql, qr, 2 * node + 1, i);   }   int main(int argc, char const *argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> arr[i];     }     for (int i = 0; i < 20; ++i) {       build(0, n - 1, 1, i);     }     int q;     cin >> q;     while (q--) {       int id, l, r;       long long x;       cin >> id;       if (id == 1) {         cin >> l >> r;         l--, r--;         long long ans = 0;         for (int i = 0; i < 20; i++)           ans += (query(0, n - 1, l, r, 1, i)) * (1LL << i);         cout << ans <<   n ;       } else {         cin >> l >> r >> x;         l--, r--;         for (int i = 0; i < 20; ++i) {           if (x & (1LL << i)) {             update(0, n - 1, l, r, 1, i);           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     while (n--) {       int c, sum;       scanf( %d %d , &c, &sum);       if (sum % c == 0)         cout << c * (sum / c * sum / c) << endl;       else {         int temp = sum / c;         long long int total = (temp * temp) * c;         int mod = sum % c;         total += mod * ((temp + 1) * (temp + 1));         total -= mod * (temp * temp);         cout << total << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 10;   const long double inf = 1e9 + 10;   bool use(long double &f, long double w, long double a);   int a[N], b[N];   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     for (int i = 1; i <= n; ++i) {       cin >> b[i];     }     b[n + 1] = b[1];     long double lo = 0, hi = inf;     for (int t = 0; t < 60; ++t) {       long double mid = (lo + hi) / 2;       long double f = mid;       bool ok = true;       for (int i = 1; i <= n; ++i) {         if (!use(f, m, a[i])) {           ok = false;           break;         }         if (!use(f, m, b[i + 1])) {           ok = false;           break;         }       }       if (ok) {         hi = mid;       } else {         lo = mid;       }     }     if (lo > 1e9) {       cout << -1 << endl;     } else {       cout << fixed << setprecision(10) << lo << endl;     }   }   bool use(long double &f, long double w, long double a) {     if (f * a < f + w) {       return false;     }     f -= (f + w) / a;     return true;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     long long int n, m;     long long int b = 1;     while (t--) {       cin >> m >> n;       while (true) {         if ((m | b) <= n)           m = m | b;         else           break;         b <<= 1;       }       cout << m <<   n ;       b = 1;     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long int LINF = 0x3f3f3f3f3f3f3f3fll;   const long double pi = acos(-1);   const int MOD = 1e9 + 7;   int n, k;   long long int g[41];   long long int dp[(1 << 20)];   long long int dp2[(1 << 20)];   int t1, t2;   long long int Adam_Sendler() {     t1 = n / 2;     t2 = n - t1;     long long int r = 0;     for (long long int mask = 1; mask < (1ll << t1); mask++) {       for (long long int j = 0; j < t1; j++)         if (mask & (1ll << j)) {           long long int outra = mask - (1ll << j);           long long int r1 = __builtin_popcountll(dp[mask]);           long long int r2 = __builtin_popcountll(dp[outra]);           if (r2 > r1) dp[mask] = dp[outra];         }       bool click = true;       for (long long int j = 0; j < t1; j++)         if ((1ll << j) & mask)           if (((g[j] ^ mask) & mask)) click = false;       if (click) dp[mask] = mask;       long long int r1 = __builtin_popcountll(dp[mask]);       r = max(r, r1);     }     for (long long int mask = 1; mask < (1ll << t2); mask++) {       for (long long int j = 0; j < t2; j++)         if (mask & (1ll << j)) {           long long int outra = mask - (1ll << j);           long long int r1 = __builtin_popcountll(dp2[mask]);           long long int r2 = __builtin_popcountll(dp2[outra]);           if (r2 > r1) dp2[mask] = dp2[outra];         }       bool click = true;       for (long long int j = 0; j < t2; j++) {         if ((1ll << j) & mask) {           long long int m1 = g[j + t1];           long long int cara = mask << t1;           if ((m1 ^ cara) & cara) {             click = false;           }         }       }       if (click) {         dp2[mask] = mask;       }       long long int r1 = __builtin_popcountll(dp2[mask]);       if (r1 == 0)         cerr <<  mask               <<   ==   << mask << endl;       r = max(r, r1);     }     for (long long int mask = 0; mask < (1ll << t1); mask++) {       long long int tudo = (1ll << n) - 1;       for (long long int j = 0; j < t1; j++)         if ((1ll << j) & mask) tudo &= g[j];       tudo >>= t1;       long long int x = __builtin_popcountll(dp[mask]);       long long int y = __builtin_popcountll(dp2[tudo]);       r = max(r, x + y);     }     return r;   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) {       g[i] |= (1ll << i);       for (int j = 0; j < n; j++) {         int x;         scanf( %d , &x);         if (x) {           g[i] |= (1ll << j);         }       }     }     int m = Adam_Sendler();     cout << fixed << setprecision(10);     cout << (k * k * (m - 1)) / (2.0 * m) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long min(long long a, long long b) { return a < b ? a : b; }   int ceil(int a, int b) { return (a + b - 1) / b; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, k;     cin >> n >> k;     string s;     cin >> s;     if (!k) {       cout << s;       return 0;     }     if (s.length() == 1) {       cout << 0;       return 0;     }     int cnt = 0;     if (s[0] !=  1 ) s[0] =  1 , cnt++;     for (int i = 1; i <= s.length(); i++) {       if (cnt == k) break;       if (s[i] !=  0 ) s[i] =  0 , cnt++;     }     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3100;   const int inf = 1e9 + 100;   struct node {     int a, b;   } l[maxn];   int s[maxn * 2 + 10], dp[maxn][maxn * 2 + 10], to[maxn];   int cmp(node a, node b) {     if (a.b != b.b)       return a.b < b.b;     else {       return a.a > b.a;     }   }   int main() {     int num, T, top, n;     scanf( %d , &T);     while (T--) {       scanf( %d , &n);       top = 0;       for (int i = 1; i <= n; i++) {         scanf( %d%d , &l[i].a, &l[i].b);         s[++top] = l[i].a;         s[++top] = l[i].b;       }       sort(s + 1, s + top + 1);       num = unique(s + 1, s + top + 1) - s - 1;       sort(l + 1, l + n + 1, cmp);       for (int i = 1; i <= n; i++) {         l[i].a = lower_bound(s + 1, s + num + 1, l[i].a) - s;         l[i].b = lower_bound(s + 1, s + num + 1, l[i].b) - s;       }       for (int i = 1; i <= n; i++) {         to[i] = 0;         for (int j = i - 1; j >= 1; j--) {           if (l[j].b < l[i].a) {             to[i] = j;             break;           }         }       }       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= num; j++) {           dp[i][j] = 0;         }       }       for (int i = 1; i <= n; i++) {         for (int j = l[i].b; j >= 1; j--) {           dp[i][j] = dp[i - 1][j];           if (l[i].a >= j) {             dp[i][j] = max(dp[i][j], dp[to[i]][j] + dp[i - 1][l[i].a] + 1);           }         }       }       printf( %d n , dp[n][1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3000 + 10;   int n, a[N], dt[N], st[N][14], pos[N][14], mark[N], lg[N];   pair<int, int> nd[N];   bool cmp1(const pair<int, int> &a, const pair<int, int> &b) {     return a.first > b.first;   }   bool unfix(int l, int r) { return l > r; }   int query(int l, int r) {     int lg1 = lg[r - l + 1];     return max(st[l][lg1], st[r - (1 << lg1) + 1][lg1]);   }   bool ok(int a, int b, int c, int d, int e, int f) {     if (a != d) return d > a;     if (b != e) return e > b;     if (c != f) return f > c;     return 1;   }   int posquery(int l, int r) {     int lg1 = lg[r - l + 1];     if (st[l][lg1] > st[r - (1 << lg1) + 1][lg1])       return pos[l][lg1];     else       return pos[r - (1 << lg1) + 1][lg1];   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), nd[i] = {a[i], i};     sort(nd + 1, nd + n + 1, cmp1);     for (int i = 1; i <= n; i++) a[i] = nd[i].first;     for (int i = n; i >= 1; i--)       dt[i] = a[i] - a[i + 1], st[i][0] = dt[i], pos[i][0] = i;     st[n][0] = dt[n];     pos[n][0] = n;     for (int i = 2; i <= n; i++) lg[i] = lg[i >> 1] + 1;     int LG = lg[n];     for (int j = 1; j <= LG; j++) {       for (int i = 1; i <= n; i++) {         st[i][j] = max(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);         if (st[i][j - 1] > st[i + (1 << (j - 1))][j - 1])           pos[i][j] = pos[i][j - 1];         else           pos[i][j] = pos[i + (1 << (j - 1))][j - 1];       }     }     int ans1 = 0, ans2 = 0, ans3 = 0;     int pos1 = 0, pos2 = 0, pos3 = 0;     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         int cnta = i, cntb = j - i;         if (cnta > 2 * cntb || cntb > 2 * cnta) continue;         if (unfix(max((cnta + 1) / 2, (cntb + 1) / 2),                   min(min(2 * cnta, 2 * cntb), n)))           continue;         int l = max(j + 1, j + max((cnta + 1) / 2, (cntb + 1) / 2)),             r = min(j + min(2 * cnta, 2 * cntb), n);         if (unfix(l, r)) continue;         int gap1 = a[i] - a[i + 1], gap2 = a[j] - a[j + 1], gap3 = query(l, r);         if (ok(ans1, ans2, ans3, gap1, gap2, gap3)) {           ans1 = gap1;           ans2 = gap2;           ans3 = gap3;           pos1 = i;           pos2 = j;           pos3 = posquery(l, r);         }       }     }     for (int i = 1; i <= n; i++) {       if (i <= pos1)         mark[nd[i].second] = 1;       else if (i <= pos2)         mark[nd[i].second] = 2;       else if (i <= pos3)         mark[nd[i].second] = 3;       else         mark[nd[i].second] = -1;     }     for (int i = 1; i <= n; i++) cout << mark[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   int arr[250];   int ans[250];   int main() {     int num;     int clr;     scanf( %d%d , &num, &clr);     for (int i = 1; i <= num; ++i) {       scanf( %d , &arr[i]);     }     int res = 0;     for (int i = 1; i <= clr; ++i) {       scanf( %d , &ans[i]);       res += ans[i];     }     std::queue<int> que;     for (int i = 1; i <= num; ++i) {       --ans[arr[i]];       --res;       que.push(arr[i]);       while (ans[arr[i]] < 0) {         int now = que.front();         que.pop();         ++ans[now];         ++res;       }       if (res == 0) {         puts( YES );         return 0;       }     }     puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200200;   const long long MOD = (int)1e9 + 7;   const long long INF = (long long)2e18;   const int C = 2e4 + 10;   long long add(long long a, long long b) { return (a + b) % MOD; }   long long sub(long long a, long long b) {     a -= b;     a %= MOD;     if (a < 0) a += MOD;     return a;   }   long long mult(long long a, long long b) { return (a * b) % MOD; }   long long bin_pow(long long a, long long n) {     long long res = 1;     while (n) {       if (n & 1) res = mult(res, a);       a = mult(a, a);       n /= 2;     }     return res;   }   long long divide(long long a, long long b) {     return mult(a, bin_pow(b, MOD - 2));   }   bool is_inf(long long a, long long b) {     if ((long double)a * b > 2 * INF) return true;     return a * b > INF;   }   int n;   long long a[MAXN];   int nxt[MAXN];   void solve() {     long long k;     scanf( %d%lld , &n, &k);     for (int i = 0; i < n; ++i) scanf( %lld , &a[i]);     nxt[n] = n;     for (int i = n - 1; i >= 0; --i) {       if (a[i] != 1)         nxt[i] = i;       else         nxt[i] = nxt[i + 1];     }     long long ans = 0;     for (int i = 0; i < n; ++i) {       long long p = a[i];       long long s = a[i] * k;       for (int j = i + 1; j <= n; ++j) {         if (p == s) ++ans;         if (j == n) break;         if (is_inf(p, a[j])) break;         if (a[j] == 1) {           long long len = nxt[j] - j;           if (p > s && p < s + len * k) {             if ((p - s) % k == 0) ++ans;           }           s += len * k;           j = nxt[j] - 1;           continue;         }         p *= a[j];         s += a[j] * k;       }     }     printf( %lld n , ans);   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000005;   long long fac[N], dp[N];   int mod = 1000000007;   long long pow(int a, int b, int MOD) {     long long x = 1, y = a;     while (b > 0) {       if (b % 2 == 1) {         x = (x * y);         if (x > MOD) x %= MOD;       }       y = (y * y);       if (y > MOD) y %= MOD;       b /= 2;     }     return x % MOD;   }   long long ncr(int n, int r) {     long long temp = (fac[r] * fac[n - r]) % mod;     return (fac[n] * pow(temp, mod - 2, mod)) % mod;   }   int main() {     int n, i, k;     long long temp;     fac[0] = 1;     for (i = 1; i < N; i++) {       fac[i] = (fac[i - 1] * i) % mod;     }     scanf( %d%d , &n, &k);     for (i = k + 1; i <= n; i++) {       dp[i] = (i * dp[i - 1]) % mod;       temp = (fac[k] * ncr(i - 1, k)) % mod;       dp[i] += (((fac[i - k - 1] - dp[i - k - 1]) % mod + mod) * temp) % mod;       dp[i] %= mod;     }     long long ans = 0;     for (i = 1; i <= n; i++) {       temp = (ncr(n - 1, i - 1) * dp[i - 1]) % mod;       temp = (temp * fac[n - i]) % mod;       ans += temp;       ans %= mod;     }     printf( %lld , ans);   }


#include <bits/stdc++.h>   using namespace std;   int t;   long long b[3000000];   pair<long long, long long> a[3000000];   int main() {     cin >> t;     while (t--) {       int n;       cin >> n;       for (int i = 0; i < n; ++i) {         scanf( %lld%lld , &a[i].first, &a[i].second);       }       for (int i = 0; i < n; ++i) {         b[(i + 1) % n] = a[(i + 1) % n].first - a[i].second;       }       long long ans = a[0].first, anw = 1e18;       for (int i = 1; i < n; ++i) {         if (b[i] > 0) {           ans += b[i];         }       }       anw = min(ans, anw);       for (int i = 1; i < n; ++i) {         ans -= a[i - 1].first;         if (b[i] > 0) {           ans -= b[i];         }         ans += a[i].first;         if (b[i - 1] > 0) {           ans += b[i - 1];         }         anw = min(ans, anw);       }       printf( %lld n , anw);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a, b, k, q;   int added[200055];   struct BIT {     int dat[200055];     void add(int id, int val) {       while (id < n) {         dat[id] += val;         id |= (id + 1);       }     }     int sum(int id) {       int ret = 0;       while (id >= 0) {         ret += dat[id];         id = (id & (id + 1)) - 1;       }       return ret;     }   } B1, B2;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> k >> a >> b >> q;     int ope, x, y;     while (q--) {       cin >> ope;       if (ope == 1) {         cin >> x >> y;         x--;         if (added[x] < b) {           B2.add(x, min(y, b - added[x]));         }         if (added[x] < a) {           B1.add(x, min(y, a - added[x]));           added[x] = min(a, added[x] + y);         }       } else {         cin >> x;         x--;         y = x + k - 1;         cout << B1.sum(n - 1) - B1.sum(y) + B2.sum(x - 1) <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   int h, w;   vector<vector<int> > f;   const int dx[] = {1, 0, -1, 0};   const int dy[] = {0, 1, 0, -1};   bool check(int x, int y) {     return 0 <= x && x < w && 0 <= y && y < h && f[y][x];   }   vector<vector<int> > was;   double sumx, sumy;   int cnt;   void dfs1(int x, int y) {     if (was[y][x] >= 1) return;     was[y][x] = 1;     sumx += x;     sumy += y;     cnt++;     for (int i = 0; i < 4; i++) {       int nx = x + dx[i], ny = y + dy[i];       if (!check(nx, ny)) continue;       dfs1(nx, ny);     }   }   vector<pair<int, int> > pts;   void dfs2(int x, int y) {     if (was[y][x] >= 2) return;     was[y][x] = 2;     bool bord = false;     for (int i = 0; i < 4; i++) {       int nx = x + dx[i], ny = y + dy[i];       if (!check(nx, ny)) {         bord = true;         continue;       }       dfs2(nx, ny);     }     if (bord) {       pts.push_back(make_pair(x, y));     }   }   int main() {     while (scanf( %d , &h) >= 1) {       w = h;       f = vector<vector<int> >(h, vector<int>(w));       for (int y = 0; y < h; y++)         for (int x = 0; x < w; x++) scanf( %d , &f[y][x]);       vector<vector<int> > f2(h, vector<int>(w, 0));       for (int y = 0; y < h; y++) {         for (int x = 0; x < w; x++) {           for (int dx = -2; dx <= 2; dx++)             for (int dy = -2; dy <= 2; dy++) {               if (x + dx < 0 || x + dx >= w) continue;               if (y + dy < 0 || y + dy >= h) continue;               f2[y][x] += f[y + dy][x + dx];             }           f2[y][x] = (f2[y][x] >= 10);         }       }       f = f2;       int c1 = 0, c2 = 0;       was = vector<vector<int> >(h, vector<int>(w, 0));       for (int y = 0; y < h; y++)         for (int x = 0; x < w; x++)           if (!was[y][x] && f[y][x]) {             sumx = 0, sumy = 0;             cnt = 0;             dfs1(x, y);             assert(cnt > 0);             if (cnt < 140) continue;             sumx /= cnt, sumy /= cnt;             pts.clear();             dfs2(x, y);             double maxd = 0;             for (int a = 0; a < ((int)(pts).size()); a++)               for (int b = 0; b < ((int)(pts).size()); b++)                 maxd = max(maxd, (double)(((pts[a].first - pts[b].first) *                                            (pts[a].first - pts[b].first)) +                                           ((pts[a].second - pts[b].second) *                                            (pts[a].second - pts[b].second))));             maxd = sqrt(maxd);             double minw = 1e100;             for (int A = -5; A <= 5; A++)               for (int B = -5; B <= 5; B++)                 if (A || B) {                   double l = 1e100, r = -1e100;                   for (int i = 0; i < ((int)(pts).size()); i++) {                     double c = A * pts[i].first + B * pts[i].second;                     l = min(l, c);                     r = max(r, c);                   }                   double D = sqrt(A * A + B * B);                   l /= D;                   r /= D;                   minw = min(minw, r - l);                 }             double k = maxd / minw;             fprintf(stderr,  %.2lf %.2lf;  %.2lf n , minw, maxd, k);             if (k > 1.12)               c2++;             else               c1++;           }       printf( %d %d n , c1, c2);     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( O3 )   using namespace std;   const double eps = 1e-9;   const double pi = acos(-1.0);   const int inf = 2e5 + 10;   int mod = 1e9 + 7;   const int MAXN = 1e5 + 7;   long double C(int n, int k) {     long double res = 1.;     if (2 * k > n) k = n - k;     for (int i = 1; i <= k; ++i) {       res *= n - k + i;       res /= i;     }     return res;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cout << fixed << setprecision(10);     cin.tie(0);     int n, m;     cin >> n >> m;     long double res = 0;     for (int k = 1; k <= min(n, m); ++k) {       res += C(m, k) * C(m * (n - 1), n - k) * k * k;     }     res /= n;     res /= C(n * m, n);     cout << res;     return 0;   }


#include <bits/stdc++.h>      using namespace std;   #define int long long      int scalar(int Ax, int Ay, int Bx, int By) {       return Ax * Bx + Ay * By;   }      bool isok(int x1, int y1, int x2, int y2, int x3, int y3) {       int Ax = x1 - x2;       int Ay = y1 - y2;       int Bx = x3 - x2;       int By = y3 - y2;       if (scalar(Ax, Ay, Bx, By) <= 0) {           return false;       } else {           return true;       }   }      vector<pair<int, int>> points;   vector<int> per;      void add(int id) {       if (per.size() <= 1) {           per.push_back(id);           return;       }       vector<int> new_p;       for (int i = per.size() - 2; i >= 0; --i) {           if (isok(points[per[i]].first, points[per[i]].second, points[per[i + 1]].first, points[per[i + 1]].second,                    points[id].first, points[id].second)) {               for (int j = 0; j <= i + 1; ++j) {                   new_p.push_back(per[j]);               }               new_p.push_back(id);               for (int k = i + 2; k < per.size(); ++k) {                   new_p.push_back(per[k]);               }               break;           }       }       if (new_p.size() == 0) {           reverse(per.begin(), per.end());           for (int i = per.size() - 2; i >= 0; --i) {               if (isok(points[per[i]].first, points[per[i]].second, points[per[i + 1]].first, points[per[i + 1]].second,                        points[id].first, points[id].second)) {                   for (int j = 0; j <= i + 1; ++j) {                       new_p.push_back(per[j]);                   }                   new_p.push_back(id);                   for (int k = i + 2; k < per.size(); ++k) {                       new_p.push_back(per[k]);                   }                   break;               }           }       }       per = new_p;   }      signed main() {       cin.tie();       cout.tie();       ios_base::sync_with_stdio(false);       int n;       cin >> n;       for (int i = 0; i < n; ++i) {           int x, y;           cin >> x >> y;           points.push_back({x, y});           add(i);       }       for (int j = 0; j < per.size(); ++j) {           cout << per[j] + 1 <<    ;       }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int k;     cin >> k;     int a[26];     int maxi = 0;     for (int i = 0; i < 26; ++i) {       cin >> a[i];       maxi = max(maxi, a[i]);     }     int val = 0;     for (int i = 0; i < s.size(); ++i) {       val += a[s[i] - 97] * (i + 1);     }     for (int i = 0; i < k; ++i) {       val += maxi * (s.size() + i + 1);     }     cout << val;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0;     char ch = getchar();     bool positive = 1;     for (; ch <  0  || ch >  9 ; ch = getchar())       if (ch ==  - ) positive = 0;     for (; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch -  0 ;     return positive ? x : -x;   }   inline char RC() {     char c = getchar();     while (c ==     || c ==   n ) c = getchar();     return c;   }   inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   inline long long lcm(long long a, long long b, long long MOD) {     return a / gcd(a, b) * b % MOD;   }   inline long long Sub(long long x, long long y, long long mod) {     long long res = x - y;     while (res < 0) res += mod;     return res;   }   inline long long Add(long long x, long long y, long long mod) {     long long res = x + y;     while (res >= mod) res -= mod;     return res;   }   inline long long POW_MOD(long long x, long long y, long long mod) {     long long ret = 1;     while (y > 0) {       if (y & 1) ret = ret * x % mod;       x = x * x % mod;       y >>= 1;     }     return ret;   }   const int N = 6005;   const int inf = 2100000000;   const long long INF = 1LL << 62;   const double PI = 3.14159265358;   int n, m;   int dis[N][N];   vector<pair<int, int> > fr[N], to[N];   vector<int> e[N];   bool vis[N];   void spfa(int u) {     memset(vis, false, sizeof(vis));     queue<int> q;     q.push(u);     vis[u] = true;     dis[u][u] = 0;     while (q.size()) {       int cur = q.front();       q.pop();       vis[cur] = false;       for (int i = 0; i < e[cur].size(); ++i) {         int v = e[cur][i];         if (dis[u][v] > dis[u][cur] + 1) {           dis[u][v] = dis[u][cur] + 1;           if (!vis[v]) {             q.push(v);           }         }       }     }   }   void init() {     for (int i = 0; i <= n; ++i) {       for (int j = 0; j <= n; ++j) {         dis[i][j] = inf;       }     }   }   bool judge(int a, int b, int c, int d) {     if (a == b || a == c || a == d || b == c || b == d || c == d) return false;     return true;   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; ++i) {       int u, v;       cin >> u >> v;       e[u].push_back(v);     }     init();     for (int i = 1; i <= n; ++i) {       spfa(i);     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         if (dis[i][j] == inf) continue;         fr[i].push_back(make_pair(dis[i][j], j));         to[j].push_back(make_pair(dis[i][j], i));       }       sort(fr[i].begin(), fr[i].end());     }     for (int i = 1; i <= n; ++i) sort(to[i].begin(), to[i].end());     int ans = 0;     int a, b, c, d;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         if (i == j || dis[i][j] == inf) continue;         for (int p = to[i].size() - 1; p >= max(0, (int)to[i].size() - 1 - 3);              --p) {           for (int q = fr[j].size() - 1; q >= max(0, (int)fr[j].size() - 4);                --q) {             int ii = to[i][p].second, jj = fr[j][q].second;             if (judge(ii, i, j, jj)) {               long long temp = dis[ii][i] + dis[i][j] + dis[j][jj];               if (temp > ans) {                 ans = temp;                 a = ii, b = i, c = j, d = jj;               }             }           }         }       }     }     cout << a <<     << b <<     << c <<     << d << 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;   }   const long long INF = 1e16;   const int maxn = (2e5) + 10;   int n, m, k, s[maxn], t[maxn], d[maxn], w[maxn], t1, t2;   long long dp[maxn / 2][210], ans;   struct cmp {     bool operator()(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {       if (a > b) return 0;       return 1;     }   };   priority_queue<pair<pair<int, int>, int>, vector<pair<pair<int, int>, int> >,                  cmp>       q;   struct node {     int pos, P;   } a[maxn], b[maxn];   int vis[maxn], u[maxn];   bool cmp2(node x, node y) { return x.pos < y.pos; }   int main() {     read(n);     read(m);     read(k);     for (int i = 1; i <= k; i++) {       read(s[i]), read(t[i]), read(d[i]), read(w[i]);       a[++t1] = (node){s[i], i};       b[++t2] = (node){t[i], i};     }     sort(a + 1, a + t1 + 1, cmp2);     sort(b + 1, b + t2 + 1, cmp2);     int I1 = 1, I2 = 1;     for (int i = 1; i <= n; i++) {       while (I1 <= t1 && a[I1].pos == i) {         q.push(make_pair(make_pair(w[a[I1].P], d[a[I1].P]), a[I1].P));         I1++;       }       u[i] = -1;       while (!q.empty()) {         pair<pair<int, int>, int> A = q.top();         u[i] = A.second;         if (!vis[u[i]])           break;         else           q.pop(), u[i] = -1;       }       while (I2 <= t2 && b[I2].pos == i) {         vis[b[I2].P] = 1;         I2++;       }     }     ans = INF;     for (int i = n; i >= 1; i--) {       for (int j = 0; j <= m; j++) {         if (u[i] != -1)           dp[i][j] = dp[d[u[i]] + 1][j] + w[u[i]];         else           dp[i][j] = dp[i + 1][j];         if (j) dp[i][j] = min(dp[i + 1][j - 1], dp[i][j]);         if (i == 1) ans = min(ans, dp[i][j]);       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long M = 2e5 + 7, MOD = 1e9;   long long cnt = 0;   long long arr[M], arrr[M];   long long sum, sum1, mx = 0;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long t;     cin >> t;     for (int i = 0; i < t; i++) cin >> arr[i];     for (int i = 0; i < t; i++) {       cin >> arrr[i];     }     for (int i = 0; i < t; i++) {       sum = arr[i];       sum1 = arrr[i];       mx = max(mx, sum + sum1);       for (int j = i + 1; j < t; j++) {         sum = sum | arr[j];         sum1 = sum1 | arrr[j];         mx = max(mx, sum + sum1);       }     }     cout << mx << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 50;   vector<int> g[maxn];   int n, k;   int ans = 0;   int dfs(int u, int p) {     if (g[u].size() == 1) return 0;     vector<int> vt;     for (auto it : g[u]) {       if (it != p) {         vt.push_back(dfs(it, u) + 1);       }     }     sort(vt.begin(), vt.end());     while (int(vt.size()) >= 2) {       if (vt.back() + vt[int(vt.size()) - 2] <= k) break;       ++ans;       vt.pop_back();     }     return vt.back();   }   int main() {     ios::sync_with_stdio(false);     cin.tie();     cout.tie();     cin >> n >> k;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     for (int i = 1; i <= n; i++) {       if (int(g[i].size()) > 1) {         dfs(i, -1);         break;       }     }     cout << ans + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   queue<int> fila[100000 + 10];   int bit[100000 + 10];   int rsp[100000 + 10];   pair<pair<int, int>, int> q[100000 + 10];   int v[100000 + 10];   int ls[100000 + 10];   void add(int p, int v) {     if (p == 0) return;     for (; p <= 100000; p += (p & (-p))) bit[p] += v;   }   int get(int p) {     int ret = 0;     for (; p > 0; p -= (p & (-p))) ret += bit[p];     return ret;   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     memset(bit, 0, sizeof(bit));     for (int i = 1; i <= n; i++) scanf( %d , &v[i]), ls[i] = -1, fila[i].push(0);     for (int i = 1; i <= m; i++) {       scanf( %d %d , &q[i - 1].first.second, &q[i - 1].first.first);       q[i - 1].second = i - 1;     }     sort(q, q + m);     int ind = 0;     for (int i = 1; i <= n; i++) {       if (v[i] <= n) {         if (ls[v[i]] != -1) {           add(ls[v[i]] + 1, -1);           add(fila[v[i]].front() + 1, +1);         }         if (fila[v[i]].size() == v[i]) {           add(fila[v[i]].front() + 1, +1);           ls[v[i]] = fila[v[i]].front();           fila[v[i]].pop();           fila[v[i]].push(i);           add(fila[v[i]].front() + 1, -1);         } else           fila[v[i]].push(i);       }       while (ind < m && q[ind].first.first == i) {         rsp[q[ind].second] = get(q[ind].first.second);         ind++;       }     }     for (int i = 0; i < m; i++) {       printf( %d n , rsp[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int res = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -f;       ch = getchar();     }     while (isdigit(ch)) {       res = (res << 1) + (res << 3) + (ch ^ 48);       ch = getchar();     }     return res * f;   }   const int N = 200005;   int n, m, root;   int ls[N], rs[N], val[N], key[N], cnt[N], add[N], ans[N];   inline void pushdown(int v) {     if (add[v]) {       add[ls[v]] += add[v];       add[rs[v]] += add[v];       val[ls[v]] += add[v];       val[rs[v]] += add[v];       add[v] = 0;     }     if (ans[v]) {       ans[ls[v]] += ans[v];       ans[rs[v]] += ans[v];       cnt[ls[v]] += ans[v];       cnt[rs[v]] += ans[v];       ans[v] = 0;     }   }   void split(int k, int &x, int &y, int v) {     if (!k) {       x = y = 0;       return;     }     pushdown(k);     if (val[k] < v)       x = k, split(rs[k], rs[x], y, v);     else       y = k, split(ls[k], x, ls[y], v);   }   int merge(int x, int y) {     if (!x || !y) return x + y;     if (key[x] < key[y]) {       pushdown(x);       rs[x] = merge(rs[x], y);       return x;     } else {       pushdown(y);       ls[y] = merge(x, ls[y]);       return y;     }   }   int insert(int x, int y) {     int rt1 = 0, rt2 = 0;     split(x, rt1, rt2, val[y]);     rt1 = merge(rt1, y);     x = merge(rt1, rt2);     return x;   }   int build(int v, int y) {     if (!v) return y;     pushdown(v);     y = build(ls[v], y);     y = build(rs[v], y);     ls[v] = rs[v] = 0;     return insert(y, v);   }   void dfs(int v) {     if (!v) return;     pushdown(v);     dfs(ls[v]);     dfs(rs[v]);   }   pair<int, int> a[N];   int main() {     scanf( %d , &n);     for (int i = 1, c, q; i <= n; i++) {       scanf( %d%d , &c, &q);       a[i] = make_pair(-q, c);     }     sort(a + 1, a + 1 + n);     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       scanf( %d , &val[i]);       key[i] = rand();       root = insert(root, i);     }     for (int i = 1; i <= n; i++) {       int c = a[i].second;       int r1 = 0, r2 = 0, r3 = 0, r4 = 0;       split(root, r1, r2, c);       val[r2] -= c;       add[r2] -= c;       cnt[r2]++;       ans[r2]++;       split(r2, r3, r4, c - 1);       r1 = build(r3, r1);       root = merge(r1, r4);     }     dfs(root);     for (int i = 1; i <= m; i++) printf( %d  , cnt[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int Ans, Cap[55][55], From[55], K, N, T[55];   vector<int> E[55];   bool dijkstra() {     priority_queue<pair<int, int>, vector<pair<int, int>>,                    greater<pair<int, int>>>         q;     vector<int> d(55, 1005);     d[1] = 0;     q.push(make_pair(0, 1));     while (!q.empty()) {       pair<int, int> p = q.top();       q.pop();       int n = p.second, c = p.first;       if (n == N) return true;       for (int i = 1; i <= N; i++)         if (Cap[n][i] && c < d[i]) {           d[i] = c;           From[i] = n;           T[i] = 0;           q.push(make_pair(c, i));         }       for (int v : E[n])         if (c + 1 < d[v]) {           d[v] = c + 1;           From[v] = n;           T[v] = 1;           q.push(make_pair(c + 1, v));         }     }     return false;   }   int main() {     cin >> N >> K;     for (int i = 1; i <= N; i++)       for (int j = 1; j <= N; j++) {         cin >> Cap[i][j];         if (Cap[i][j]) E[i].push_back(j);       }     while (true) {       if (!dijkstra()) break;       int cost = 0, flow = 1000000, n = N;       while (From[n] > 0) {         if (T[n] == 0) flow = min(flow, Cap[From[n]][n]);         n = From[n];       }       n = N;       while (From[n] > 0) {         if (T[n])           cost++;         else           Cap[From[n]][n] -= flow, Cap[n][From[n]] += flow;         n = From[n];       }       if (cost * flow <= K) {         K -= cost * flow;         Ans += flow;       } else {         Ans += K / cost;         break;       }     }     cout << Ans;   }


#include <bits/stdc++.h>   using namespace std;   template <typename... T>   void read(T &...args) {     ((cin >> args), ...);   }   template <typename... T>   void write(T... args) {     ((cout << args <<    ), ...);     cout <<   n ;   }   long long gcd(long long a, long long b) {     if (b > a) {       return gcd(b, a);     }     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   long long add(long long a, long long b) {     a = a % 1000000007;     b = b % 1000000007;     return (((a + b) % 1000000007) + 1000000007) % 1000000007;   }   long long sub(long long a, long long b) {     a = a % 1000000007;     b = b % 1000000007;     return (((a - b) % 1000000007) + 1000000007) % 1000000007;   }   long long mul(long long a, long long b) {     a = a % 1000000007;     b = b % 1000000007;     return (((a * b) % 1000000007) + 1000000007) % 1000000007;   }   long long power(long long x, long long y) {     long long res = 1;     x = x % 1000000007;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) {         res = (res * x) % 1000000007;       }       y = y >> 1;       x = (x * x) % 1000000007;     }     return res;   }   long long find(vector<long long> &parent, long long x) {     if (parent[x] != x) parent[x] = find(parent, parent[x]);     return parent[x];   }   void join(vector<long long> &parent, vector<long long> &rank, long long x,             long long y) {     long long xParent = find(parent, x);     long long yParent = find(parent, y);     if (xParent == yParent) return;     if (rank[xParent] > rank[yParent]) {       parent[yParent] = xParent;     } else if (rank[xParent] < rank[yParent]) {       parent[xParent] = yParent;     } else {       parent[xParent] = yParent;       rank[yParent]++;     }   }   void solve() {     long long n, m, k;     read(n, m, k);     vector<vector<long long> > mat(n, vector<long long>(m, 0));     for (long long i = 0; i < n; i++) {       string str;       cin >> str;       for (long long j = 0; j < m; j++) {         if (str[j] ==  * ) mat[i][j] = 1;       }     }     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         if (mat[i][j] == 0) continue;         long long len = 0;         while (j - len >= 0 && i - len >= 0 && j + len < m) {           if (mat[i - len][j - len] == 0 || mat[i - len][j + len] == 0) break;           len++;         }         len--;         if (len >= k) {           for (long long p = 0; p < len + 1; p++) {             mat[i - p][j - p] = 2;             mat[i - p][j + p] = 2;           }         }       }     }     bool found = false;     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         if (mat[i][j] == 1) found = true;       }     }     if (found)       write( NO );     else       write( YES );   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long iter;     cin >> iter;     while (iter) {       solve();       iter--;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, last = 0, count = 0, sum, sum1;       cin >> n;       while (n >= 10) {         last = n / 10;         n = n / 10;         count += 1;       }       if (count + 1 == 1)         sum1 = 1;       else if (count + 1 == 2)         sum1 = 3;       else if (count + 1 == 3)         sum1 = 6;       else if (count + 1 == 4)         sum1 = 10;       sum = (last - 1) * 10 + sum1;       if (n > 10)         cout << sum << endl;       else {         last = n;         sum = (last - 1) * 10 + sum1;         cout << sum << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   struct line {     long long x, y, dx, dy, s;   } a[25000];   struct point {     int i;     bool f;     long double x;   } b[50000], c[25000];   bool comp(point a, point b) {     if (a.x == b.x) {       if (a.f == b.f) return (a.i < b.i);       return (a.f < b.f);     }     return (a.x < b.x);   }   long double x;   bool operator<(point y, point z) {     long double y1, y2, dy, dx, ix, iy;     dy = a[y.i].dy;     dx = a[y.i].dx;     ix = a[y.i].x;     iy = a[y.i].y;     y1 = iy + (x - ix) * (dy / dx);     dy = a[z.i].dy;     dx = a[z.i].dx;     ix = a[z.i].x;     iy = a[z.i].y;     y2 = iy + (x - ix) * (dy / dx);     if (y1 == y2) return (y.i < z.i);     return (y1 < y2);   }   long double compute(line a, long long xn, long long xd, long long yn,                       long long yd) {     long double x = xn;     x = x / xd;     x = (a.x - x) * (a.x - x);     long double y = yn;     y = y / yd;     y = (a.y - y) * (a.y - y);     long double ans = x + y;     ans = sqrt(ans);     ans = ans / a.s;     return ans;   }   bool check(int i, int j, long double t) {     long long xn, xd, yn, yd;     long double t1 = -1, t2 = -1;     if (a[i].dx * a[j].dy != a[j].dx * a[i].dy) {       xn = a[i].dx * a[j].dy * a[j].x - a[j].dx * a[i].dy * a[i].x +            a[j].dx * a[i].dx * (a[i].y - a[j].y);       xd = a[i].dx * a[j].dy - a[j].dx * a[i].dy;       yn = a[i].dy * a[j].dy * (a[j].x - a[i].x) + a[j].dy * a[i].dx * a[i].y -            a[i].dy * a[j].dx * a[j].y;       yd = a[i].dx * a[j].dy - a[j].dx * a[i].dy;       if (xd < 0) {         xn *= -1;         xd *= -1;       }       if (yd < 0) {         yn *= -1;         yd *= -1;       }       if (((a[i].dx > 0 && (xn - xd * a[i].x) >= 0) ||            (a[i].dx < 0 && (xn - xd * a[i].x) <= 0)) &&           ((a[i].dy > 0 && (yn - yd * a[i].y) >= 0) ||            (a[i].dy < 0 && (yn - yd * a[i].y) <= 0)))         t1 = compute(a[i], xn, xd, yn, yd);       if (((a[j].dx > 0 && (xn - xd * a[j].x) >= 0) ||            (a[j].dx < 0 && (xn - xd * a[j].x) <= 0)) &&           ((a[j].dy > 0 && (yn - yd * a[j].y) >= 0) ||            (a[j].dy < 0 && (yn - yd * a[j].y) <= 0)))         t2 = compute(a[j], xn, xd, yn, yd);     } else if ((a[i].dx * (a[j].y - a[i].y)) == (a[i].dy * (a[j].x - a[i].x))) {       bool f1 = false;       xn = a[j].x;       xd = 1;       yn = a[j].y;       yd = 1;       if (((a[i].dx > 0 && (xn - xd * a[i].x) >= 0) ||            (a[i].dx < 0 && (xn - xd * a[i].x) <= 0)) &&           ((a[i].dy > 0 && (yn - yd * a[i].y) >= 0) ||            (a[i].dy < 0 && (yn - yd * a[i].y) <= 0)))         f1 = true;       bool f2 = false;       xn = a[i].x;       xd = 1;       yn = a[i].y;       yd = 1;       if (((a[j].dx > 0 && (xn - xd * a[j].x) >= 0) ||            (a[j].dx < 0 && (xn - xd * a[j].x) <= 0)) &&           ((a[j].dy > 0 && (yn - yd * a[j].y) >= 0) ||            (a[j].dy < 0 && (yn - yd * a[j].y) <= 0)))         f2 = true;       if (f1 && f2) {         xn = a[i].x * a[j].s + a[j].x * a[i].s;         xd = a[i].s + a[j].s;         yn = a[i].y * a[j].s + a[j].y * a[i].s;         yd = a[i].s + a[j].s;         t1 = compute(a[i], xn, xd, yn, yd);         t2 = compute(a[j], xn, xd, yn, yd);       } else if (f1) {         xn = a[j].x;         xd = 1;         yn = a[j].y;         yd = 1;         t1 = compute(a[i], xn, xd, yn, yd);         t2 = 0;       } else if (f2) {         xn = a[i].x;         xd = 1;         yn = a[i].y;         yd = 1;         t1 = 0;         t2 = compute(a[j], xn, xd, yn, yd);       }     }     if (t1 >= 0 && t2 >= 0 && max(t1, t2) <= t) return true;     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     bool flag = false;     int n, i, j, z;     cin >> n;     for (i = 0; i < n; i++)       cin >> a[i].x >> a[i].y >> a[i].dx >> a[i].dy >> a[i].s;     long double l = 0, h = 1e13, m, dx, dy, s;     set<point> t;     set<point>::iterator it, it1, it2;     for (z = 0; z < 70; z++) {       m = (l + h) / 2;       for (i = 0; i < n; i++) {         b[2 * i].i = b[2 * i + 1].i = i;         b[2 * i].x = a[i].x;         dx = a[i].dx;         dy = a[i].dy;         s = a[i].s;         b[2 * i + 1].x = b[2 * i].x + ((dx * s * m) / sqrt(dx * dx + dy * dy));         if (b[2 * i].x < b[2 * i + 1].x) {           b[2 * i].f = 0;           b[2 * i + 1].f = 1;         } else {           b[2 * i].f = 1;           b[2 * i + 1].f = 0;         }       }       j = 2 * n;       sort(b, b + j, comp);       for (i = 0; i < j; i++) {         if (b[i].f) {           x = b[i].x;           it = t.lower_bound(c[b[i].i]);           it1 = it;           it1++;           if (it != t.begin() && it1 != t.end()) {             it2 = it;             it2--;             if (check(it1->i, it2->i, m)) break;           }           t.erase(it);         } else {           x = b[i].x;           t.insert(b[i]);           it = t.lower_bound(b[i]);           it1 = it;           it1++;           if (it1 != t.end() && check(it->i, it1->i, m)) break;           if (it != t.begin()) {             it1 = it;             it1--;             if (check(it->i, it1->i, m)) break;           }           c[b[i].i] = b[i];         }       }       if (i < j) {         flag = true;         h = m;       } else         l = m;       t.clear();     }     if (!flag)       cout <<  No show :( ;     else {       cout << fixed;       cout << setprecision(15);       cout << l;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     long long int M, k, Q, sum = 0, a = 1, W;     vector<int> x;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %lld , &W);       for (int j = 0; j < W; j++) {         x.push_back(i);       }     }     scanf( %lld , &M);     for (k = 1; k <= M; k++) {       scanf( %lld , &Q);       printf( %d n , x[Q - 1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, K, P[2100], S[2100], ans[(int)4e6 + 100], cost = 0;   int abs(int a) { return a > 0 ? a : -a; }   void swap(int i, int j) {     cost += abs(i - j);     ans[++K] = i;     ans[++K] = j;     P[i] ^= P[j];     P[j] ^= P[i];     P[i] ^= P[j];   }   stack<int> box;   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) scanf( %d , P + i);     for (int i = 1; i <= N; i++) {       int tmp;       scanf( %d , &tmp);       S[tmp] = i;     }     for (int i = 1; i <= N; i++) P[i] = S[P[i]];     for (int i = 1; i <= N; i++) {       if (P[i] > i) box.push(i);       int pos = i;       while (box.size() && P[pos] <= box.top() && P[box.top()] >= pos) {         swap(box.top(), pos);         i = pos - 1;         pos = box.top();         box.pop();       }     }     printf( %d n%d n , cost, K >> 1);     for (int i = 1; i <= K; i++) printf( %d%c , ans[i], i & 1 ? 32 : 10);   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5e5 + 5;   struct edge {     int next, v;   } e[MAXN << 1];   int n, q, root, cnt, head[MAXN], dep[MAXN], anc[MAXN][30];   void addEdge(int x, int y) {     e[++cnt].v = y;     e[cnt].next = head[x];     head[x] = cnt;   }   void dfs(int x) {     for (int i = head[x]; i != -1; i = e[i].next) {       int y = e[i].v;       if (y == anc[x][0]) continue;       dep[y] = dep[x] + 1;       anc[y][0] = x;       dfs(y);     }   }   void init() {     cnt = 0;     root = 1;     memset(head, -1, sizeof(head));   }   int lca(int a, int b) {     if (dep[a] > dep[b]) swap(a, b);     int h = dep[b] - dep[a];     for (int i = 0; (1 << i) <= h; i++)       if ((1 << i) & h) b = anc[b][i];     if (a != b) {       for (int i = (int)log2(dep[a]); i >= 0; i--) {         if (anc[a][i] != anc[b][i]) {           a = anc[a][i];           b = anc[b][i];         }       }       a = anc[a][0];     }     return a;   }   int dist(int x, int y) { return dep[x] + dep[y] - 2 * dep[lca(x, y)]; }   int main() {     init();     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d %d , &x, &y);       addEdge(x, y);       addEdge(y, x);     }     dep[root] = 0;     dfs(root);     for (int j = 1; (1 << j) <= n; j++) {       for (int i = 1; i <= n; i++) {         anc[i][j] = anc[anc[i][j - 1]][j - 1];       }     }     scanf( %d , &q);     for (int kk = 1; kk < 10; kk++) int jj = kk + 1;     for (int i = 1; i <= q; i++) {       int x, y, a, b, k;       scanf( %d %d %d %d %d , &x, &y, &a, &b, &k);       int temp1 = dist(a, b);       int temp2 = min(dist(a, x) + dist(y, b), dist(a, y) + dist(x, b)) + 1;       int ans = k + 1;       if (k % 2 == temp1 % 2) ans = min(ans, temp1);       if (k % 2 == temp2 % 2) ans = min(ans, temp2);       if (ans <= k)         puts( YES );       else         puts( NO );     }   }


#include <bits/stdc++.h>   using namespace std;   long long int n, k;   long long int a[200100];   bool check(long long int x) {     long long int moves = 0;     for (__typeof(n + 1) i = (n / 2 + 1) - ((n / 2 + 1) > (n + 1));          i != (n + 1) - ((n / 2 + 1) > (n + 1));          i += 1 - 2 * ((n / 2 + 1) > (n + 1))) {       moves += max((long long int)0, x - a[i]);       if (moves > k) return false;     }     if (moves <= k) return true;     return false;   }   void solve() {     cin >> n >> k;     for (__typeof(n + 1) i = (1) - ((1) > (n + 1));          i != (n + 1) - ((1) > (n + 1)); i += 1 - 2 * ((1) > (n + 1))) {       cin >> a[i];     }     sort(a + 1, a + n + 1);     long long int l = 1, r = 2e9;     bool can = false;     while (l < r) {       long long int mid = (l + r + 1) / 2;       if (check(mid)) {         l = mid;       } else {         r = mid - 1;       }     }     cout << l << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   char s[1000002];   int o = 0, len;   int main() {     cin >> s;     if ((s[0] ==  1 ) && (strlen(s) == 1)) {       cout << 0;       return 0;     }     for (int i = strlen(s); i >= 0; i--) {       s[i + 1] = s[i];     }     s[0] =  0 ;     int i = strlen(s) - 1;     while (i > 0) {       if (s[i] ==  0 ) {         o += 1;         i--;       } else {         if (i == 1) break;         o++;         while (s[i] ==  1 ) {           o++;           i--;         }         s[i] =  1 ;       }     }     cout << o;   }


#include <bits/stdc++.h>   using namespace std;       #define all(cont) cont.begin(), cont.end()   #define rall(cont) cont.end(), cont.begin()   #define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)   #define IN(A, B, C) assert(B <= A && A <= C)   #define SORT(v) sort(v.begin(), v.end())   #define MP make_pair   #define PB push_back   #define INF (int)1e9   #define EPS 1e-9   #define PI 3.1415926535897932384626433832795   #define MOD 1000000007   const double pi = acos(-1.0);   typedef long int int32;   typedef unsigned long int uint32;   typedef long long int int64;   typedef unsigned long long int uint64;   const int N = 1e5 + 5;       void solve() {           int64 n, q, l, r;           cin>>n>>q;           string s;           cin>>s;           vector<int64> v, v1(n);           while(n--){               v.PB(s[s.size()-n-1]-96);           }           partial_sum(v.begin(), v.end(), v1.begin());           while(q--){               cin>>l>>r;               cout<<v1[r-1]-v1[l-1]+v[l-1]<<  n ;           }                         }       int main() {           solve();       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     long long int i = 1;     long long int a[n];     while (i <= n) {       cin >> a[i];       i++;     }     cout << n + 1 << endl;     cout << 1 <<     << n <<     << 5600 << endl;     i = 1;     while (i <= n) {       cout << 2 <<     << i <<     << a[i] + 5600 - i << endl;       i++;     }   }


#include <bits/stdc++.h>   using namespace std;   int dist[551000];   long long int sum = 0;   set<long long int> ans;   int fTemp[551000];   int freq[551000];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> dist[i + 1];       if (i + 1 >= 2) {         dist[i] = dist[i + 1] - dist[i];         sum += dist[i];       }     }     int m;     cin >> m;     for (int i = 0; i < m; i++) {       int p;       cin >> p;       freq[p]++;     }     int dir = 1;     int stop = 1;     int end = -1;     set<int> good;     long long int d = 0;     for (int i = 0; i < m; i++) {       fTemp[stop]++;       if (i == m - 1) {         end = stop;         break;       }       if (stop + dir <= n && stop + dir >= 1) {         d += dist[((stop > stop + dir) ? stop + dir : stop)];         stop += dir;       }       if (stop == n)         dir = -1;       else if (stop == 1)         dir = 1;     }     for (int i = 1; i < n + 1; i++) {       if (fTemp[i] == freq[i]) good.insert(i);     }     if (good.size() == n) {       ans.insert(d);     }     if (end == n)       dir = -1;     else if (end == 1)       dir = -1;     for (int i = 2; i < n + 1; i++) {       fTemp[i - 1]--;       d -= dist[i - 1];       if (end == n) {         dir = -1;       } else if (end == 1) {         dir = 1;       }       fTemp[end + dir]++;       d += dist[((end + dir > end) ? end : end + dir)];       if (fTemp[i - 1] == freq[i - 1])         good.insert(i - 1);       else {         good.erase(i - 1);       }       if (fTemp[end + dir] == freq[end + dir])         good.insert(end + dir);       else {         good.erase(end + dir);       }       if (good.size() == n) {         ans.insert(d);       }       end += dir;     }     if (end == n)       dir = -1;     else if (end == 1)       dir = -1;     for (int i = n - 1; i > 1; i--) {       fTemp[i + 1]--;       d -= dist[i];       if (end == n) {         dir = -1;       } else if (end == 1) {         dir = 1;       }       fTemp[end + dir]++;       d += dist[((end + dir > end) ? end : end + dir)];       if (fTemp[i + 1] == freq[i + 1])         good.insert(i + 1);       else {         good.erase(i + 1);       }       if (fTemp[end + dir] == freq[end + dir])         good.insert(end + dir);       else {         good.erase(end + dir);       }       if (good.size() == n) {         ans.insert(d);       }       end += dir;     }     if (ans.size() > 1) {       cout << -1;     } else {       cout << *ans.begin();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int md1 = 1e9 + 7, md2 = 1e9 + 9, B = 130;   struct H {     int x, y;     H(int a = 0, int b = 0) : x(a), y(b) {}     bool operator==(H o) { return x == o.x && y == o.y; }     void operator+=(char c) {       x = ((long long)x * B + c) % md1;       y = ((long long)y * B + c) % md2;     }   } h[2000];   char p[1000001], s[201];   int k, n, m;   inline void no() { printf( 0 n ), exit(0); }   H gth(int i, int o) {     H h;     for (int j = i; j < m; j += o) h += s[j];     return h;   }   string gt(int o) {     string an(k,  0 );     int z = o;     for (int i = k - 1; i >= 0 && z; --i)       if (gth(z - 1, o) == h[i]) an[i] =  1 , --z;     if (z) return string();     return an;   }   int main() {     gets(p);     gets(s);     scanf( %d , &k);     n = strlen(p);     m = strlen(s);     if (m > n) no();     for (int i = 0; i < (int)(k); ++i)       for (int j = i; j < n; j += k) h[i] += p[j];     int z = (n + k - 1) / k;     int a = (m + z - 1) / z, b = z - 1 ? m / (z - 1) : a;     string an;     for (int i = a; i < (int)(b + 1); ++i) {       string t = gt(i);       if (!t.empty() && (an.empty() || t < an)) an.swap(t);     }     if (an.empty()) no();     printf( %s n , an.c_str());   }


#include <bits/stdc++.h>   using namespace std;   template <class C>   void mini(C& _a4, C _b4) {     _a4 = min(_a4, _b4);   }   template <class C>   void maxi(C& _a4, C _b4) {     _a4 = max(_a4, _b4);   }   template <class TH>   void _dbg(const char* sdbg, TH h) {     cerr << sdbg <<  =  << h << endl;   }   template <class TH, class... TA>   void _dbg(const char* sdbg, TH h, TA... a) {     while (*sdbg !=  , ) cerr << *sdbg++;     cerr <<  =  << h <<  , ;     _dbg(sdbg + 1, a...);   }   template <class T>   ostream& operator<<(ostream& os, vector<T> V) {     os <<  [ ;     for (auto& vv : V) os << vv <<  , ;     os <<  ] ;     return os;   }   long long n, l;   long long war[401];   string z[401];   map<string, long long> ma;   long long il = 0;   void add(string x) {     auto xx = ma.find(x);     if (xx == ma.end()) {       (x, il);       ma[x] = il;       il++;     }   }   long long szu(string z) {     while (1) {       auto xx = ma.find(z);       if (xx != ma.end()) {         return xx->second;       }       z = z.substr(1);     }   }   long long ww[401];   long long t[401][401], pom2[401][401], res[401], pom[401];   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout << fixed << setprecision(11);     if (0) cout << fixed << setprecision(6);     cin >> n >> l;     for (long long i = (0); i <= ((long long)(n)-1); i++) {       cin >> war[i];     }     for (long long i = (0); i <= ((long long)(n)-1); i++) {       cin >> z[i];       for (long long j = (0);            j <= ((long long)(((long long)(z[i]).size()) + 1) - 1); j++) {         add(z[i].substr(0, j));       }     }     for (long long i = (0); i <= ((long long)(n)-1); i++) {       for (auto& x : ma) {         if (((long long)(z[i]).size()) > ((long long)(x.first).size())) continue;         if (z[i] == x.first.substr(((long long)(x.first).size()) -                                        ((long long)(z[i]).size()),                                    ((long long)(z[i]).size())))           ww[x.second] += war[i];       }     }     for (long long i = (0); i <= ((long long)(il)-1); i++)       for (long long j = (0); j <= ((long long)(il)-1); j++) t[i][j] = -1e18;     for (auto& x : ma) {       for (char k =  a ; k <=  z ; k++) {         string pom = x.first + k;         long long gd = szu(pom);         maxi(t[x.second][gd], ww[gd]);       }     }     for (long long i = (0); i <= ((long long)(il)-1); i++) res[i] = -1e18;     res[0] = 0;     while (l) {       if (l & 1) {         for (long long i = (0); i <= ((long long)(il)-1); i++) pom[i] = -1e18;         for (long long i = (0); i <= ((long long)(il)-1); i++)           for (long long j = (0); j <= ((long long)(il)-1); j++)             maxi(pom[j], res[i] + t[i][j]);         for (long long i = (0); i <= ((long long)(il)-1); i++) res[i] = pom[i];       }       l /= 2;       for (long long i = (0); i <= ((long long)(il)-1); i++)         for (long long j = (0); j <= ((long long)(il)-1); j++) pom2[i][j] = -1e18;       for (long long i = (0); i <= ((long long)(il)-1); i++)         for (long long j = (0); j <= ((long long)(il)-1); j++)           for (long long k = (0); k <= ((long long)(il)-1); k++)             maxi(pom2[i][k], t[i][j] + t[j][k]);       for (long long i = (0); i <= ((long long)(il)-1); i++)         for (long long j = (0); j <= ((long long)(il)-1); j++)           t[i][j] = pom2[i][j];     }     long long out = 0;     for (long long i = (0); i <= ((long long)(il)-1); i++) maxi(out, res[i]);     cout << out <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     long long n;     cin >> n;     string s;     cin >> s;     set<char> all;     for (auto c : s) all.insert(c);     const long long sz = all.size();     if (sz == 1) {       cout <<  1 n ;       return 0;     }     long long lo = 1;     long long hi = n;     long long a = n;     while (lo <= hi) {       long long mid = (lo + hi) / 2;       map<char, long long> freq;       bool poss = false;       long long dist = 0;       for (long long i = 0; i < mid; i++) {         freq[s[i]]++;         if (freq[s[i]] == 1) dist++;       }       for (long long i = mid; i < n; i++) {         if (dist == sz) poss = true;         if (--freq[s[i - mid]] == 0) dist--;         if (++freq[s[i]] == 1) dist++;         if (dist == sz) poss = true;       }       if (poss) {         a = min(a, mid);         hi = mid - 1;       } else         lo = mid + 1;     }     cout << a <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int k, n, m, ans = 0;   int dx[] = {0, 0, 0, 0, -1, 1};   int dy[] = {0, 0, 1, -1, 0, 0};   int dz[] = {1, -1, 0, 0, 0, 0};   char a[11][11][11];   bool vis[11][11][11];   void dfs(int x, int y, int z) {     if (x < 0 || y < 0 || z < 0 || x >= n || y >= m || z >= k ||         a[x][y][z] ==  #  || vis[x][y][z])       return;     vis[x][y][z] = 1;     ans++;     int xx, yy, zz;     for (int i = 0; i < 6; i++) {       xx = x + dx[i];       yy = y + dy[i];       zz = z + dz[i];       dfs(xx, yy, zz);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> k >> n >> m;     for (int t = 0; t < k; t++) {       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           cin >> a[i][j][t];         }       }     }     int x, y;     cin >> x >> y;     dfs(x - 1, y - 1, 0);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int n, a;   int main() {     scanf( %d %d , &n, &a);     if (a % 2 == 1) {       printf( %d , (a - 1) / 2 + 1);       return 0;     }     if (a % 2 == 0) {       printf( %d , n / 2 + 1 - a / 2);       return 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, ans;   struct Node {     int val, p, cnt;     int pre, nxt;   } a[N];   struct Comp {     bool operator()(const pair<int, int> &x, const pair<int, int> &y) {       return x.first == y.first ? x.second < y.second : x.first > y.first;     }   };   set<pair<int, int>, Comp> st;   void solve() {     scanf( %d , &n);     int p = -1, k = 0;     for (int i = 0; i < n; i++) {       int tmp;       scanf( %d , &tmp);       if (tmp != k) {         if (p != -1) a[p].nxt = i;         a[i].pre = p;         k = tmp;         p = i;         a[i].p = i;         a[i].val = tmp;         a[i].nxt = -1;         a[i].cnt = 1;       } else {         a[p].cnt++;       }     }     for (int i = 0; i < n; i++)       if (a[i].cnt) st.insert(make_pair(a[i].cnt, i));     while (!st.empty()) {       auto it = st.begin();       int pos = it->second;       int pp = a[pos].pre, nn = a[pos].nxt;       ans++;       st.erase(it);       if (pp != -1) a[pp].nxt = nn;       if (nn != -1) a[nn].pre = pp;       if (pp != -1 && nn != -1 && a[pp].val == a[nn].val) {         int nnn = a[nn].nxt;         a[nnn].pre = pp;         a[pp].nxt = nnn;         st.erase(st.find(make_pair(a[nn].cnt, nn)));         st.erase(st.find(make_pair(a[pp].cnt, pp)));         a[pp].cnt += a[nn].cnt;         st.insert(make_pair(a[pp].cnt, pp));       }     }     printf( %d n , ans);   }   int main() {     solve();     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     long long ele, i, j, ele1, k, n, a, b, q;     cin >> q;     for (i = 0; i < q; i++) {       cin >> n >> a >> b;       if (n == 1) {         cout << a << endl;         continue;       } else if (2 * a > b) {         ele = n % 2;         ele1 = n / 2;         if (ele == 0) {           cout << ele1 * b << endl;         } else {           cout << ele1 * b + a << endl;         }       } else if (2 * a <= b) {         cout << n * a << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   void solve(string a, string b, int m, int n) {     int lcs[m + 1][n + 1];     int result = 0;     for (int i = 0; i <= m; i++) {       for (int j = 0; j <= n; j++) {         if (i == 0 || j == 0)           lcs[i][j] = 0;         else if (a[i - 1] == b[j - 1]) {           lcs[i][j] = lcs[i - 1][j - 1] + 1;           result = max(result, lcs[i][j]);         } else           lcs[i][j] = 0;       }     }     int answer = m + n - 2 * result;     cout << answer <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin.exceptions(ios::badbit | ios::failbit);     int t = 1;     cin >> t;     while (t--) {       int n;       cin >> n;       string s, temp;       cin >> s;       temp = s;       sort(s.begin(), s.end());       int count = 0;       for (int i = 0; i < n; i++) {         if (temp[i] != s[i]) count++;       }       cout << count <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<long long, long long> add_pair(pair<long long, long long> a,                                       pair<long long, long long> b) {     return make_pair(a.first + b.first, a.second + b.second);   }   long long power(long long a, long long b) {     long long res = 1;     a = a % ((long long)1e9 + 7);     while (b > 0) {       if (b & 1) {         res = (res * a) % ((long long)1e9 + 7);         b--;       }       a = (a * a) % ((long long)1e9 + 7);       b >>= 1;     }     return res;   }   long long fermat_inv(long long y) { return power(y, ((long long)1e9 + 7) - 2); }   long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }   long long mul(long long a, long long b) {     return (a * (b % ((long long)1e9 + 7))) % ((long long)1e9 + 7);   }   long long sub(long long a, long long b) {     return ((a - b) % ((long long)1e9 + 7) + ((long long)1e9 + 7)) %            ((long long)1e9 + 7);   }   long long add(long long a, long long b) {     return ((a + b) % ((long long)1e9 + 7) + ((long long)1e9 + 7)) %            ((long long)1e9 + 7);   }   vector<vector<int> > G;   int n, ans;   void bfs(int rt) {     int x;     queue<int> q;     vector<int> d(n), par(n);     vector<bool> vis(n, false);     d[rt] = 0;     par[rt] = rt;     q.push(rt);     while (!q.empty()) {       x = q.front();       vis[x] = true;       q.pop();       for (auto it = (G[x]).begin(); it != (G[x]).end(); it++) {         if (!vis[*it]) {           d[*it] = d[x] + 1;           par[*it] = x;           vis[*it] = true;           q.push(*it);         } else {           if (*it != par[x] && par[*it] != x) {             ans = min(ans, d[x] + d[*it] + 1);             if (ans == 3) return;           }         }       }     }   }   void solve() {     int i, j;     long long x;     cin >> n;     vector<long long> a;     vector<int> cnt(61, 0ll);     for (i = (0); i < (n); i += (1)) {       cin >> x;       if (x == 0) continue;       a.push_back(x);       for (j = 0; j < 61; j++) {         if (x & (1ll << j)) {           cnt[j]++;         }       }     }     for (i = (0); i < (61); i += (1)) {       if (cnt[i] > 2) {         cout << 3 <<   n ;         return;       }     }     n = (a).size();     G = vector<vector<int> >(n, vector<int>());     ans = n + 1;     for (i = (0); i < (n); i += (1)) {       for (j = (0); j < (i); j += (1)) {         if (a[i] & a[j]) {           G[i].push_back(j);           G[j].push_back(i);         }       }     }     for (i = (0); i < (n); i += (1)) {       bfs(i);       if (ans == 3) break;     }     if (ans == n + 1)       cout << -1 <<   n ;     else       cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int max_n = 2000222, inf = 1000111222;   int t, n, a[max_n], b[max_n];   long long sum[max_n];   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       for (int i = 0; i < n; ++i) {         scanf( %d , &a[i]);       }       for (int i = 0; i < n; ++i) {         scanf( %d , &b[i]);       }       for (int i = n; i < 2 * n; ++i) {         a[i] = a[i - n];         b[i] = b[i - n];       }       a[2 * n] = b[2 * n] = 0;       for (int i = 0; i <= 2 * n; ++i) {         sum[i] = a[i] - b[i];         if (i) {           sum[i] += sum[i - 1];         }       }       bool ok = sum[n - 1] <= 0;       long long mx = sum[2 * n];       for (int i = 2 * n - 1; i >= 0; --i) {         long long res = mx - sum[i] - b[i];         if (res > 0) {           ok = false;           break;         }         mx = max(mx, sum[i]);       }       if (ok) {         puts( YES );       } else {         puts( NO );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define int long long   const int MAX = 1e6 + 7;   int num[MAX];   signed main()   {    int T;    cin >> T;    while (T--)    {     int N, u, v;     cin >> N >> u >> v;     for (int i = 1; i <= N; i++)     {      cin >> num[i];     }     int canget = 0;     int flag = 0;     for (int i = 1; i < N; i++)     {      if (abs(num[i] - num[i + 1]) > 1)      {       canget = 1;       cout << 0 <<   n ;       flag = 1;       break;      }     }     if (flag == 1)     {      continue;     }     if (canget)     {      continue;     }     int ban = 0;     for (int i = 1; i < N; i++)     {      if (num[i] != num[i + 1])      {       ban = 1;      }     }     if (ban)     {      cout << min(u, v) <<   n ;     }     else     {      cout << min(u + v, v * 2) <<   n ;     }    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   long long lgput(long long a, long long b, long long mod) {     long long ret = 1;     while (b) {       if (b & 1) ret = (ret * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return (ret % mod);   }   inline long long inv(long long x, long long MOD) {     return lgput(x, MOD - 2, MOD);   }   const long double PI = acos(-1);   const long double eps = 1e-6;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout.precision(12);     cout.fixed;     int n;     cin >> n;     vector<int> a(n);     vector<int> b(n);     for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];     vector<int> order(n);     for (int i = 0; i < n; ++i) order[i] = i;     sort(order.begin(), order.end(),          [&](int i, int j) -> bool { return a[i] + b[j] > a[j] + b[i]; });     long long ret = 0;     for (int i = 0; i < n; ++i) {       ret += 1ll * i * a[order[i]] + 1ll * (n - 1 - i) * b[order[i]];     }     cout << ret <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<string, int> M;   int eval(string s) {     int c1 = 0, c2 = 0;     string t;     int indl = 0;     while (indl < s.size() && s[indl] ==  & ) ++indl, ++c1;     int ind2 = s.size() - 1;     while (ind2 >= 0 && s[ind2] ==  * ) --ind2, ++c2;     t = s.substr(indl, ind2 - indl + 1);     if (!M.count(t)) return -1;     int x = M[t];     if (x == -1) return -1;     x += c2;     x -= c1;     if (x < 0) return -1;     return x;   }   int main() {     int n;     cin >> n;     M[ void ] = 0;     for (int i = 0; i < n; ++i) {       string ws;       cin >> ws;       if (ws ==  typeof ) {         string s;         cin >> s;         int x = eval(s);         if (x == -1)           printf( errtype n );         else {           printf( void );           for (int j = 0; j < x; ++j) printf( * );           printf(  n );         }       } else {         string s, t;         cin >> s >> t;         M[t] = eval(s);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double a[10100];   int main() {     int n, m;     cin >> n >> m;     double ans = 0.0;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= m; i++) {       int aa, bb;       double cc;       cin >> aa >> bb >> cc;       ans = max((a[aa] + a[bb]) / cc, ans);     }     cout << fixed << setprecision(15) << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {-1, 1, 0, 0};   int dy[] = {0, 0, -1, 1};   int n, m;   vector<long long> a;   void solve() {     long long cnt = 0;     vector<vector<pair<int, int>>> ps;     queue<pair<int, int>> buff;     ps.resize(m);     for (int i = 0; i < m; i++) ps[i].clear();     for (int i = 0; i < n; i++) ps[a[i] % m].push_back({a[i], i});     for (int i = 0; i < m; i++)       if ((int)ps[i].size() > n / m) {         for (int j = 0; j < m + m; j++) {           int cur = (i + j) % m;           while ((int)ps[cur].size() > n / m) {             pair<int, int> v = ps[cur].back();             ps[cur].pop_back();             buff.push(v);           }           while ((int)ps[cur].size() < n / m && (int)buff.size() > 0) {             pair<int, int> v = buff.front();             buff.pop();             int d = (cur + m - (v.first % m)) % m;             v.first += (long long)d;             ps[cur].push_back(v);             cnt += (long long)d;           }         }         break;       }     vector<long long> res;     res.resize(n);     for (int i = 0; i < m; i++) {       assert((int)ps[i].size() == n / m);       for (pair<int, int> j : ps[i]) {         res[j.second] = j.first;       }     }     cout << cnt << endl;     for (int i = 0; i < n; i++) {       if (i < n - 1)         cout << res[i] <<    ;       else         cout << res[i] << endl;     }   }   int main() {     cin >> n >> m;     a.resize(n);     for (int i = 0; i < n; i++) cin >> a[i];     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool clash[30][30];   int dp[100001][27];   string s;   int solve(int index, int lastchar) {     if (index == s.size()) {       return 0;     }     int mn = (1 << 30);     if (dp[index][lastchar] != -1) {       return dp[index][lastchar];     }     if (!clash[s[index] -  a ][lastchar])       mn = min(mn, solve(index + 1, s[index] -  a ));     mn = min(mn, solve(index + 1, lastchar) + 1);     return dp[index][lastchar] = mn;   }   int main() {     cin >> s;     int n;     cin >> n;     string s2;     int sum = 0;     memset(dp, -1, sizeof(dp));     for (int i = 0; i < n; i++) {       cin >> s2;       clash[s2[0] -  a ][s2[1] -  a ] = true;       clash[s2[1] -  a ][s2[0] -  a ] = true;     }     cout << solve(0, 26) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool _cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }   int main() {     int n, x, y;     scanf( %d , &n);     vector<pair<int, int> > V(n);     for (int i = 0; i < n; i++) {       scanf( %d %d , &x, &y);       V[i].first = min(x, y);       V[i].second = max(x, y);     }     sort(V.begin(), V.end(), _cmp);     bool U[n];     memset(U, false, sizeof U);     vector<int> Res;     for (int i = 0; i < n; i++) {       if (U[i]) continue;       Res.push_back(V[i].second);       for (int j = i + 1; j < n; j++)         if (V[j].first <= V[i].second) U[j] = true;     }     printf( %d n , Res.size());     for (int i = 0; i < Res.size(); i++)       printf( %s%d , (i == 0 ?    :    ), Res[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Q {     int a, b, c, d;     Q(int x, int y, int z, int w) : a(x), b(y), c(z), d(w) {}   };   pair<int, int> query(Q z) {     int u, v;     printf( %d%d%d%d n , z.a, z.b, z.c, z.d);     fflush(stdout);     scanf( %d%d , &u, &v);     return make_pair(u, v);   }   pair<int, int> dist(Q e, Q f) {     int bulls = 0, cows = 0;     if (e.a == f.a) bulls++;     if (e.b == f.b) bulls++;     if (e.c == f.c) bulls++;     if (e.d == f.d) bulls++;     if ((e.a == f.a) || (e.a == f.b) || (e.a == f.c) || (e.a == f.d)) cows++;     if ((e.b == f.a) || (e.b == f.b) || (e.b == f.c) || (e.b == f.d)) cows++;     if ((e.c == f.a) || (e.c == f.b) || (e.c == f.c) || (e.c == f.d)) cows++;     if ((e.d == f.a) || (e.d == f.b) || (e.d == f.c) || (e.d == f.d)) cows++;     return make_pair(bulls, cows - bulls);   }   int main() {     vector<Q> X;     for (int i = 0; i < 10; ++i)       for (int j = 0; j < 10; ++j)         if (i - j) {           for (int k = 0; k < 10; ++k)             if ((i - k) && (j - k)) {               for (int l = 0; l < 10; ++l)                 if ((i - l) && (j - l) && (k - l)) {                   Q h(i, j, k, l);                   X.push_back(h);                 }             }         }     int bulls = 0, cows = 0;     while (bulls < 4) {       pair<int, int> Z = query(X[0]);       bulls = Z.first;       cows = Z.second;       vector<Q> Y;       Q V = X[0];       for (int i = 0; i < X.size(); ++i) {         pair<int, int> T = dist(V, X[i]);         if (T.first == bulls && T.second == cows) Y.push_back(X[i]);       }       X = Y;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, A, cf, cm, m;   struct node {     long long x;     int i;   } a[100001];   long long sum[100001];   long long ans = 0;   bool cmp(node a, node b) { return a.x < b.x; }   bool cmp1(node a, node b) { return a.i < b.i; }   long long minc = 0;   long long bsearch(long long x) {     int l = 0;     int r = n;     while (l < r) {       int mid = l + (r - l) / 2;       if (a[mid].x > x)         r = mid;       else         l = mid + 1;     }     return l;   }   void solve() {     for (int i = 0; i < n; ++i) {       long long num = m - (A * (long long)i - (sum[n - 1] - sum[n - 1 - i]));       if (num < 0) break;       long long l = a[0].x - 1;       long long r = A;       while (l < r) {         long long mid = l + (r - l) / 2;         long long k = bsearch(mid) - 1;         if (k + i >= n) k = n - 1 - i;         long long sum1 = (mid * (k + 1) - sum[k]);         if (sum1 > num)           r = mid;         else           l = mid + 1;       }       l--;       if (ans <= (long long)i * cf + (long long)l * cm) {         ans = (long long)i * cf + (long long)l * cm;         minc = l;       }     }   }   int main() {     while (cin >> n >> A >> cf >> cm >> m) {       for (int i = 0; i < n; ++i) {         scanf( %lld , &a[i].x);         a[i].i = i;       }       a[n].x = A + 1;       a[n].i = n;       ans = 0;       sort(a, a + n, cmp);       sum[0] = a[0].x;       for (int i = 1; i < n; ++i) sum[i] = sum[i - 1] + a[i].x;       if (A * n <= sum[n - 1] + m) {         ans = n * cf + A * cm;         minc = A;       } else {         solve();       }       for (int i = 0; i < n; ++i) {         if (a[i].x < minc) {           m -= minc - a[i].x;           a[i].x = minc;         } else           break;       }       for (int i = n - 1; i >= 0; --i) {         if (A - a[i].x <= m) {           m -= A - a[i].x;           a[i].x = A;         } else {           a[i].x += m;           m = 0;           break;         }       }       sort(a, a + n, cmp1);       printf( %lld n , ans);       for (int i = 0; i < n; ++i) {         if (i == n - 1)           printf( %lld n , a[i].x);         else           printf( %lld  , a[i].x);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_L = 200;   map<int, pair<int, int> > ds;   int ops[MAX_L];   int powmod(int a, int n, int mod) {     int pm = 1;     while (n > 0) {       if (n & 1) pm = (long long)pm * a % mod;       a = (long long)a * a % mod;       n >>= 1;     }     return pm;   }   bool check(int v, int u, int uc, queue<int> &q, int &mst, int &mgl) {     map<int, pair<int, int> >::iterator mit = ds.find(v);     if (mit != ds.end()) {       if (uc * mit->second.first < 0) {         if (uc > 0)           mst = u, mgl = v;         else           mst = v, mgl = u;         return true;       }     } else {       ds[v] = pair<int, int>(uc, u);       q.push(v);     }     return false;   }   int getop(int u, int v, int p) {     if ((u + 1) % p == v) return 1;     if ((u + p - 1) % p == v) return 2;     return 3;   }   int main() {     int st, gl, p;     scanf( %d%d%d , &st, &gl, &p);     if (st == gl) {       puts( 2 n1 2 );       return 0;     }     ds[st] = pair<int, int>(1, -1);     ds[gl] = pair<int, int>(-1, -1);     queue<int> q;     q.push(st), q.push(gl);     int mst = -1, mgl = -1;     while (!q.empty()) {       int u = q.front();       q.pop();       pair<int, int> ud = ds[u];       int uc = ud.first, up = ud.second;       if (check((u + 1) % p, u, uc, q, mst, mgl) ||           check((u + p - 1) % p, u, uc, q, mst, mgl) ||           check(powmod(u, p - 2, p), u, uc, q, mst, mgl))         break;     }     vector<int> vst, vgl;     for (int u = mst; u >= 0; u = ds[u].second) vst.push_back(u);     for (int u = mgl; u >= 0; u = ds[u].second) vgl.push_back(u);     int l = 0;     for (int i = vst.size() - 1; i > 0; i--)       ops[l++] = getop(vst[i], vst[i - 1], p);     ops[l++] = getop(mst, mgl, p);     for (int i = 0; i + 1 < vgl.size(); i++)       ops[l++] = getop(vgl[i], vgl[i + 1], p);     printf( %d n , l);     for (int i = 0; i < l; i++) printf( %d%c , ops[i], (i + 1 < l) ?     :   n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1E5;   int a[MAXN];   long long pref[MAXN];   long long suff[MAXN];   int main() {     int n, d, m;     cin >> n >> d >> m;     int bigger = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] > m) bigger++;     }     sort(a, a + n);     long long ans = 0;     for (int i = 0; i < n; i++) {       if (i)         pref[i] = pref[i - 1] + a[i];       else         pref[i] = a[i];     }     if (bigger == 0) {       ans = 0;       for (int i = 0; i < n; i++) ans += a[i];       cout << ans <<   n ;       return 0;     }     long long lowSum = 0;     for (int i = 0; i < n; i++) {       if (a[i] <= m) lowSum += a[i];     }     for (int i = n - 1; i >= 0; i--) {       if (i == n - 1)         suff[i] = a[i];       else         suff[i] = a[i] + suff[i + 1];     }     int atLeast = (n + d) / (d + 1);     for (int i = 1; i <= min(bigger, atLeast); i++) {       int minShadow = max((i - 1) * d, bigger - i);       int maxShadow = min(i * d, n - i);       if (minShadow > maxShadow) continue;       long long temp = 0;       if (minShadow - (bigger - i) - 1 >= 0)         temp = suff[n - i] + lowSum - pref[minShadow - (bigger - i) - 1];       else         temp = suff[n - i] + lowSum;       ans = max(ans, temp);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     int k;     char a[101];     int i = 0;     scanf( %d %d , &n, &k);     scanf( %s , a);     if (k > n / 2) {       i = k;       while (i < n) {         printf( RIGHT n );         i++;       }     } else {       i = k;       while (i > 1) {         printf( LEFT n );         i--;       }     }     if (i == 1) {       i--;       printf( PRINT %c n , a[i]);       i++;       while (i < n) {         printf( RIGHT n );         printf( PRINT %c n , a[i]);         i++;       }     } else {       printf( PRINT %c n , a[i - 1]);       i--;       while (i > 0) {         printf( LEFT n );         printf( PRINT %c n , a[i - 1]);         i--;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef int arr[500005];   arr Next, a, Sa, Lcp, pos, tmp, S;   int n, len;   char P[500005];   vector<int> Val[2 * 500005];   bool cmp(int p, int q) {     if (pos[p] != pos[q]) return pos[p] < pos[q];     p += len;     q += len;     if (p <= n && q <= n) return pos[p] < pos[q];     return p > q;   }   void BuildSA() {     for (int i = 1; i <= n; i++) {       Sa[i] = i;       pos[i] = ((P[i] ==  ( ) ? 1 : 2);     }     for (len = 1; len <= n; len *= 2) {       sort(Sa + 1, Sa + n + 1, cmp);       for (int i = 1; i <= n; i++) tmp[i] = tmp[i - 1] + cmp(Sa[i - 1], Sa[i]);       for (int i = 1; i <= n; i++) pos[Sa[i]] = tmp[i];     }   }   void BuildLCP() {     int cur = 0;     for (int i = 1; i <= n; i++) {       int j = Sa[pos[i] - 1];       if (j == 0) continue;       while (P[i + cur] == P[j + cur]) cur++;       Lcp[pos[i]] = cur;       if (cur) cur--;     }   }   int Get(int V, int L, int R) {     int l = lower_bound(Val[V].begin(), Val[V].end(), L) - Val[V].begin();     int r = upper_bound(Val[V].begin(), Val[V].end(), R) - Val[V].begin();     return max(r - l, 0);   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> P[i];       a[i] = a[i - 1];       if (P[i] ==  ( ) a[i]++;       if (P[i] ==  ) ) a[i]--;       Val[a[i] + 500005].push_back(i);     }     int top = 0;     S[0] = n + 1;     for (int i = n; i >= 0; i--) {       while (a[i] <= a[S[top]] && top) top--;       Next[i] = S[top];       S[++top] = i;     }     BuildSA();     BuildLCP();     long long ans = 0;     for (int i = 1; i <= n; i++) {       int L = Sa[i] + Lcp[i];       int R = Next[Sa[i] - 1] - 1;       ans += Get(a[Sa[i]] - 1 + 500005, L, R);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int n;   pair<long long, long long> x[4000];   long long d[4000];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) cin >> x[i].first >> x[i].second;     sort(x + 1, x + n + 1);     d[n] = x[n].second;     for (int i = n - 1; i >= 1; i--) {       d[i] = 1000000000000000000LL;       long long s = 0;       for (int j = i + 1; j <= n; j++)         d[i] = min(d[i], s + d[j]), s += x[j].first - x[i].first;       d[i] = min(d[i], s);       d[i] += x[i].second;     }     cout << d[1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const long long N = 2e5 + 100;   const long long INF = 1e18;   long long x[N], p[N], a[N];   struct node {     long long ans = 0, pref = 0, suff = 0, sum = 0;     node() {}     node(long long x) {       pref = suff = sum = x;       ans = max(x, 0ll);     }   } t[4 * N];   node merge(node l, node r) {     node ret;     ret.ans = max(l.ans, r.ans);     ret.pref = max(l.pref, l.sum + r.pref);     ret.suff = max(r.suff, r.sum + l.suff);     ret.sum = l.sum + r.sum;     ret.ans = max({ret.ans, ret.pref, ret.suff});     ret.ans = max(ret.ans, l.suff + r.pref);     return ret;   }   void build(long long v, long long l, long long r) {     if (l + 1 == r) {       t[v] = node(a[l]);       return;     }     long long mid = (l + r) / 2;     build(v * 2 + 1, l, mid);     build(v * 2 + 2, mid, r);     t[v] = merge(t[v * 2 + 1], t[v * 2 + 2]);   }   node qu(long long v, long long l, long long r, long long ql, long long qr) {     if (qr <= l || r <= ql) return node();     if (ql <= l && r <= qr) return t[v];     long long mid = (l + r) / 2;     return merge(qu(v * 2 + 1, l, mid, ql, qr), qu(v * 2 + 2, mid, r, ql, qr));   }   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long n, m, c;     cin >> n >> m >> c;     for (long long i = 0; i < n; i++) {       cin >> x[i];     }     n--;     for (long long i = 0; i < n; i++) {       x[i] = 50 * (x[i + 1] - x[i]);     }     for (long long i = 0; i < n; i++) {       cin >> p[i];     }     for (long long i = 0; i < n; i++) {       a[i] = (x[i] - p[i] * c);     }     build(0, 0, n);     long long ans = 0;     for (long long i = 0; i < m; i++) {       long long l, r;       cin >> l >> r;       l--;       r--;       ans += qu(0, 0, n, l, r).ans;     }     cout << fixed << setprecision(20) << ans / 100.0 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const int N = 1e5 + 9;   vector<int> v[N];   bool visited[N];   int c = 0;   map<pair<int, int>, int> m;   void dfs(int x, int parent) {     visited[x] = true;     bool b = false;     for (int i = 0; i < v[x].size(); i++) {       if (!visited[v[x][i]]) {         b = true;         dfs(v[x][i], x);       }     }     if (!b) m[{parent, x}] = c++;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int x;     cin >> x;     int l[x - 1], r[x - 1];     for (int i = 0; i < x - 1; i++) {       cin >> l[i] >> r[i];       v[l[i]].push_back(r[i]);       v[r[i]].push_back(l[i]);     }     dfs(l[0], l[0]);     for (int i = 0; i < x - 1; i++) {       if (m.find({l[i], r[i]}) != m.end())         cout << m[{l[i], r[i]}] <<   n ;       else if (m.find({r[i], l[i]}) != m.end())         cout << m[{r[i], l[i]}] <<   n ;       else         cout << c++ <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cout <<  0 0  << endl;     string left;     cin >> left;     int l = 0, r = 1e9;     for (int i = 1; i < n; i++) {       int mid = (l + r) / 2;       cout << mid <<   1  << endl;       string s;       cin >> s;       if (s == left) {         l = mid;       } else {         r = mid;       }     }     cout << l <<   2   << r <<   0  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, const char* argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int a, b, c, x, y, z;     int spa = 0, spb = 0, spc = 0;     int req = 0;     cin >> a >> b >> c;     cin >> x >> y >> z;     if (a > x)       spa = a - x;     else       req += x - a;     if (b > y)       spb = b - y;     else       req += y - b;     if (c > z)       spc = c - z;     else       req += z - c;     if (spa > 0) req = req - spa / 2;     if (spb > 0) req = req - spb / 2;     if (spc > 0) req = req - spc / 2;     if (req <= 0)       cout <<  Yes ;     else       cout <<  No ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool comp(pair<long long int, long long int> a,             pair<long long int, long long int> b) {     if (a.first + a.second == b.first + b.second) {       return a.first < b.first;     }     return (a.first + a.second) < (b.first + b.second);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int q;     cin >> q;     while (q--) {       long long int n;       cin >> n;       vector<pair<long long int, long long int> > A(n + 1, {0, 0});       for (long long int i = 0; i < n; i++) {         long long int a, first;         cin >> a >> first;         if (first == 0) {           A[a].second++;         } else {           A[a].first++;         }       }       sort(A.rbegin(), A.rend(), comp);       pair<long long int, long long int> sol = {A[0].first + A[0].second,                                                 A[0].first};       for (long long int i = 1; i < n + 1; i++) {         if (A[i - 1].first + A[i - 1].second <= 1) break;         if (A[i].first + A[i].second < A[i - 1].first + A[i - 1].second) {           sol.first += A[i].first + A[i].second;           sol.second += A[i].first;         } else if (A[i].first + A[i].second >= A[i - 1].first + A[i - 1].second) {           long long int second = A[i - 1].first + A[i - 1].second - 1;           long long int ma = 0, mai = -1;           for (long long int j = i; j < n + 1; j++) {             if (second <= A[j].first + A[j].second) {               if (A[j].first >= ma) {                 mai = j;                 ma = A[j].first;               }             } else {               break;             }           }           if (A[mai].first >= second) {             A[mai].first = second;             A[mai].second = 0;             sol.first += second;             sol.second += second;           } else {             second = second - A[mai].first;             sol.first += A[mai].first;             sol.second += A[mai].first;             A[mai].second = second;             sol.first += second;           }           swap(A[i], A[mai]);         }       }       cout << sol.first <<     << sol.second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long dp[101][101][11][2];   long long k1, k2;   long long solve(long long n1, long long n2, long long count, long long flag) {     if (n1 < 0 || n2 < 0) {       return 0;     }     if (n1 == 0 && n2 == 0) {       return 1;     }     if (flag != -1 && dp[n1][n2][count][flag] != -1) {       return dp[n1][n2][count][flag];     }     long long i;     long long ans = 0;     if (flag != 1) {       for (i = 1; i <= k2; i++) {         ans += solve(n1, n2 - i, i, 1);         ans %= (long long)1e8;       }     }     if (flag != 0) {       for (i = 1; i <= k1; i++) {         ans += solve(n1 - i, n2, i, 0);         ans %= (long long)1e8;       }     }     if (flag != -1) dp[n1][n2][count][flag] = ans;     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n1, n2;     cin >> n1 >> n2 >> k1 >> k2;     memset(dp, -1, sizeof(dp));     cout << solve(n1, n2, 0, -1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char x[55];   int swim(char *c = x, int res = 0, int round = 0) {     int l = strlen(c);     if (round == 2) {       if (l == 0 || l > 7 || (c[0] ==  0  && l > 1)) return -1;       int ba2y;       sscanf(c,  %d , &ba2y);       if (ba2y > 1000000) return -1;       return ba2y + res;     }     int ma3aya = 0;     int nateg = -1;     for (; c[0]; c++) {       ma3aya *= 10;       ma3aya += c[0] -  0 ;       nateg = max(nateg, swim(c + 1, ma3aya + res, round + 1));       if (ma3aya == 0 || (ma3aya * 10) + (c[1]) -  0  > 1000000) break;     }     return nateg;   }   int main() {     scanf( %s , &x);     printf( %d , swim());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, const char* argv[]) {     char a[4];     char b[4];     char x;     int f = 0;     int r = 0;     for (int i = 0; i < 4; i++) {       cin >> x;       if (x !=  X ) {         a[r] = x;         r++;       } else {         if (i < 2) f = 1;       }     }     if (f) {       char t = a[1];       a[1] = a[2];       a[2] = t;       f = 0;     }     r = 0;     for (int i = 0; i < 4; i++) {       cin >> x;       if (x !=  X ) {         b[r] = x;         r++;       } else {         if (i < 2) f = 1;       }     }     if (f) {       char t = b[1];       b[1] = b[2];       b[2] = t;     }     int err = 0;     int j = 0;     for (int i = 0; i < 3; i++) {       if (!i) {         while (a[i] != b[j]) {           j++;         }       } else {         if (a[i] != b[j]) {           err = 1;           break;         }       }       j = (j + 1) % 3;     }     if (!err) {       cout <<  YES ;     } else {       cout <<  NO ;     }   }