#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e6 + 5;   const long long MAXM = 4e7 + 5;   const int MOD = 998244353;   long long n, m, p;   struct node1 {     long long x, c;   } a[MAXN], b[MAXN];   struct node2 {     long long x, y, z;   } c[MAXN];   struct node {     long long l, r, val, mark;   } t[MAXN << 2];   void build(long long rt, long long l, long long r) {     t[rt].l = l, t[rt].r = r;     t[rt].mark = 0;     if (l == r) {       t[rt].val = -b[l].c;       return;     }     long long mid = (t[rt].l + t[rt].r) >> 1;     build(rt << 1, l, mid);     build(rt << 1 | 1, mid + 1, r);     t[rt].val = max(t[rt << 1].val, t[rt << 1 | 1].val);   }   void spread(long long rt) {     t[rt << 1].val += t[rt].mark;     t[rt << 1 | 1].val += t[rt].mark;     t[rt << 1].mark += t[rt].mark;     t[rt << 1 | 1].mark += t[rt].mark;     t[rt].mark = 0;   }   void update(long long rt, long long l, long long r, long long val) {     if (l > r) return;     if (t[rt].l >= l && t[rt].r <= r) {       t[rt].val += val;       t[rt].mark += val;       return;     }     spread(rt);     long long mid = (t[rt].l + t[rt].r) >> 1;     if (l <= mid) update(rt << 1, l, r, val);     if (r > mid) update(rt << 1 | 1, l, r, val);     t[rt].val = max(t[rt << 1].val, t[rt << 1 | 1].val);   }   bool cmp(node1 a, node1 b) { return a.x < b.x; }   bool cmp1(node2 a, node2 b) { return a.x < b.x; }   long long q[MAXN];   int main() {     while (~scanf( %I64d%I64d%I64d , &n, &m, &p)) {       for (long long i = 1; i <= n; i++) scanf( %I64d%I64d , &a[i].x, &a[i].c);       for (long long i = 1; i <= m; i++) scanf( %I64d%I64d , &b[i].x, &b[i].c);       sort(a + 1, a + n + 1, cmp);       sort(b + 1, b + m + 1, cmp);       for (long long i = 1; i <= m; i++) q[i] = b[i].x;       build(1, 1, m);       for (long long i = 1; i <= p; i++) {         scanf( %I64d%I64d%I64d , &c[i].x, &c[i].y, &c[i].z);       }       sort(c + 1, c + p + 1, cmp1);       long long pos = 1;       long long ans = -1ll << 62;       for (long long i = 1; i <= n; i++) {         while (pos <= p && c[pos].x < a[i].x) {           long long pp = upper_bound(q + 1, q + m + 1, c[pos].y) - q;           update(1, pp, m, c[pos].z);           pos++;         }         ans = max(ans, (long long)t[1].val - a[i].c);       }       printf( %I64d n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int r, c, x, y;     string s;     cin >> r >> c >> x >> y;     cin >> s;     vector<int> visited(r * c + 1, 0);     cout <<  1  ;     int t, n = s.size();     visited[c * (x - 1) + y] = 1;     for (int i = 0; i < n - 1; i++) {       if (s[i] ==  U  && (x - 1 >= 1 && x - 1 <= r)) {         x -= 1;         t = c * (x - 1) + y;         if (visited[t])           cout <<  0  ;         else {           visited[t] = 1;           cout <<  1  ;         }       } else if (s[i] ==  U )         cout <<  0  ;       else if (s[i] ==  D  && (x + 1 >= 1 && x + 1 <= r)) {         x += 1;         t = c * (x - 1) + y;         if (visited[t])           cout <<  0  ;         else {           visited[t] = 1;           cout <<  1  ;         }       } else if (s[i] ==  D )         cout <<  0  ;       else if (s[i] ==  L  && (y - 1 >= 1 && y - 1 <= c)) {         y -= 1;         t = c * (x - 1) + y;         if (visited[t])           cout <<  0  ;         else {           visited[t] = 1;           cout <<  1  ;         }       } else if (s[i] ==  L )         cout <<  0  ;       else if (s[i] ==  R  && (y + 1 >= 1 && y + 1 <= c)) {         y += 1;         t = c * (x - 1) + y;         if (visited[t])           cout <<  0  ;         else {           visited[t] = 1;           cout <<  1  ;         }       } else         cout <<  0  ;     }     t = 0;     for (int i = 1; i <= r * c; i++) {       if (visited[i] == 1) t++;     }     cout << r * c - t;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long x, xxxxx = 0;   string s, word;   long long indx = 0, lmt;   string v[100009], out =   ;   bool f_int = false;   bool ok() {     if (indx > lmt) return xxxxx = 1, false;     bool o1, o2;     o1 = o2 = false;     if (v[indx] ==  int  and indx != 1) {       out +=  int ;       f_int = true;       return true;     }     ++indx;     out +=  pair< ;     o1 = ok();     ++indx;     out +=  , ;     o2 = ok();     if (!o2) xxxxx = 1, out +=  XXX ;     out +=  > ;     return true;   }   int main() {     cin >> x;     getchar();     getline(cin, s);     stringstream ss(s);     while (ss >> word) {       v[++indx] = word;     }     if (indx == 1) {       if (v[1] ==  int )         cout <<  int ;       else         cout <<  Error occurred ;       return 0;     }     lmt = indx;     indx = 1;     ok();     if (xxxxx || !f_int || indx != lmt)       cout <<  Error occurred ;     else       cout << out;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 5000;   const int MAXN = 200, MAXE = 2 * MAXN;   int src, snk, nNode, nEdge;   int Q[MAXN], fin[MAXN], pro[MAXN], dist[MAXN];   int flow[MAXE], cap[MAXE], Next[MAXE], to[MAXE];   inline void init(int _src, int _snk, int _n) {     src = _src, snk = _snk, nNode = _n, nEdge = 0;     memset(fin, -1, sizeof(fin));   }   inline void add(int u, int v, int c) {     to[nEdge] = v, cap[nEdge] = c, flow[nEdge] = 0, Next[nEdge] = fin[u],     fin[u] = nEdge++;     to[nEdge] = u, cap[nEdge] = 0, flow[nEdge] = 0, Next[nEdge] = fin[v],     fin[v] = nEdge++;   }   bool bfs() {     int st, en;     memset(dist, -1, sizeof(dist));     dist[src] = st = en = 0;     Q[en++] = src;     while (st < en) {       int u = Q[st++];       for (int i = fin[u]; i >= 0; i = Next[i]) {         int v = to[i];         if (flow[i] < cap[i] && dist[v] == -1) {           dist[v] = dist[u] + 1;           Q[en++] = v;         }       }     }     return (dist[snk] != -1);   }   int dfs(int u, int fl) {     if (u == snk) return fl;     for (int &e = pro[u]; e >= 0; e = Next[e]) {       int v = to[e];       if (flow[e] < cap[e] && dist[v] == dist[u] + 1) {         int df = dfs(v, min(cap[e] - flow[e], fl));         if (df > 0) {           flow[e] += df;           flow[e ^ 1] -= df;           return df;         }       }     }     return 0;   }   long long dinitz() {     long long ret = 0;     while (bfs()) {       for (int i = 0; i <= nNode; i++) pro[i] = fin[i];       while (true) {         int df = dfs(src, inf);         if (df)           ret += (long long)df;         else           break;       }     }     return ret;   }   int arr[MAXN], x[MAXN], y[MAXN];   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &arr[i]);     for (int i = 1; i <= m; i++) {       scanf( %d %d , &x[i], &y[i]);       if (x[i] % 2 == 0) swap(x[i], y[i]);     }     set<int> prime;     for (int i = 1; i <= n; i++) {       int nw = arr[i];       for (int p = 2; p * p <= nw; p++) {         int cnt = 0;         while (nw % p == 0) {           ++cnt, nw /= p;         }         if (cnt) prime.insert(p);       }       if (nw > 1) prime.insert(nw);     }     long long tot = 0;     for (set<int>::iterator it = prime.begin(); it != prime.end(); it++) {       int p = *it;       int s = 0, t = n + 1;       init(s, t, n + 2);       for (int i = 1; i <= n; i++) {         int nw = arr[i], cnt = 0;         while (nw % p == 0) ++cnt, nw /= p;         if (cnt) {           if (i % 2 == 1)             add(s, i, cnt);           else             add(i, t, cnt);         }       }       for (int i = 1; i <= m; i++) {         add(x[i], y[i], inf);       }       tot += dinitz();     }     printf( %lld n , tot);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:36777216 )   const int Nmax = 100100;   const int Drection[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};   int h, q;   long long minV[55], maxV[55];   long long leftDown(long long L, int hg) {     if (hg == h) return L;     return leftDown(L << 1ll, hg + 1);   }   long long rightDown(long long R, int hg) {     if (hg == h) return R;     return rightDown((R << 1ll) + 1, hg + 1);   }   inline void end(long long x) {     if (x == 0)       cout <<  Data not sufficient!  << endl;     else if (x == -1)       cout <<  Game cheated!  << endl;     else       cout << x << endl;     exit(0);   }   inline void add(long long x) {     static long long extra = -1;     if (x <= 0) end(extra);     if (extra != -1) end(0);     extra = x;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> h >> q;     minV[1] = maxV[1] = 1;     for (int i = 2; i <= h; i++) {       minV[i] = minV[i - 1] * 2ll;       maxV[i] = maxV[i - 1] * 2ll + 1;     }     vector<pair<long long, long long> > list;     for (int i = 1; i <= q; i++) {       long long lv, L, R, ans;       cin >> lv >> L >> R >> ans;       if (ans == 1) {         if (minV[lv] <= L - 1)           list.push_back(make_pair(leftDown(minV[lv], lv), rightDown(L - 1, lv)));         if (R + 1 <= maxV[lv])           list.push_back(make_pair(leftDown(R + 1, lv), rightDown(maxV[lv], lv)));       } else         list.push_back(make_pair(leftDown(L, lv), rightDown(R, lv)));     }     sort(list.begin(), list.end());     long long L = leftDown(1, 1);     long long R = rightDown(1, 1);     for (int i = 0; i < list.size(); i++) {       if (list[i].first > L) {         add(L++);         i--;         continue;       }       L = max(L, list[i].second + 1);     }     while (L <= R) add(L++);     add(-10);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353, N = 5e5;   int qmod1(const int &x) { return x >= mod ? x - mod : x; }   int qmod2(const int &x) { return x + (x >> 31 & mod); }   int qpower(int a, int b) {     int ans = 1;     for (; b; b >>= 1, a = 1ll * a * a % mod)       if (b & 1) ans = 1ll * ans * a % mod;     return ans;   }   struct Z {     int x;     Z(int v = 0) { x = qmod2(v % mod); }     int qmod1(const int &x) const { return x >= mod ? x - mod : x; }     int qmod2(const int &x) const { return x + (x >> 31 & mod); }     int qpower(int a, int b) const {       int ans = 1;       for (; b; b >>= 1, a = 1ll * a * a % mod)         if (b & 1) ans = 1ll * ans * a % mod;       return ans;     }     Z operator+(const Z &b) const { return (Z){qmod1(x + b.x)}; }     Z &operator+=(const Z &b) {       x += b.x;       if (x >= mod) x -= mod;       return *this;     }     Z operator-(const Z &b) const { return (Z){qmod2(x - b.x)}; }     Z &operator-=(const Z &b) {       x -= b.x;       x += x >> 31 & mod;       return *this;     }     Z operator*(const Z &b) const { return (Z){(int)(1ll * x * b.x % mod)}; }     Z &operator*=(const Z &b) {       x = 1ll * x * b.x % mod;       return *this;     }     int inv() const {       assert(x != 0);       return qpower(x, mod - 2);     }     Z operator/(const Z &b) const { return (Z){(int)(1ll * x * b.inv() % mod)}; }     Z &operator/=(const Z &b) {       x = 1ll * x * b.inv() % mod;       return *this;     }     Z operator-() const { return (Z){qmod2(-x)}; }   };   bool zero(const Z &a) { return !a.x; }   void print(const Z &a) { printf( %d , a.x); }   Z inv[N], fac[N], ifac[N];   void prework(int n) {     fac[0] = 1;     for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * Z(i);     inv[1] = 1;     for (int i = 2; i <= n; i++) inv[i] = Z(mod - mod / i) * inv[mod % i];     ifac[0] = 1;     for (int i = 1; i <= n; i++) ifac[i] = ifac[i - 1] * inv[i];   }   template <typename T>   void simplify(T &a) {     while (a.size() && zero(a[-1])) a.pop_back();   }   template <typename T>   bool zero(const T &a) {     int n = a.size() - 1;     while (n >= 0 && zero(a[n])) --n;     return n < 0;   }   int limn = 0;   void setn(const int &n) { limn = n; }   template <class T>   struct Poly {     vector<T> a;     Poly() { a.resize(0); }     Poly(const T &u, const T &v) {       a.resize(2);       a[0] = u, a[1] = v;     }     Poly(const int &u, const int &v) {       a.resize(2);       a[0] = u, a[1] = v;     }     Poly(const int &x) {       a.resize(1);       a[0] = T(x);     }     Poly(const T &x) {       a.resize(1);       a[0] = x;     }     int size() const { return a.size(); }     void resize(const int &x) { a.resize(x); }     void clear() { vector<T>().swap(a); }     void pop_back() { a.pop_back(); }     T operator[](const int &x) const {       assert(x < (int)a.size());       if (x >= 0) return a[x];       assert(-x <= (int)a.size());       return a[a.size() + x];     }     T &operator[](const int &x) {       assert(x < (int)a.size());       if (x >= 0) return a[x];       assert(-x <= (int)a.size());       return a[a.size() + x];     }     Poly<T> operator*(const Poly<T> &b) const {       Poly<T> c;       if (!a.size() || !b.size()) return c;       int n = a.size(), m = b.size();       c.resize(n + m - 1);       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) c[i + j] += a[i] * b[j];       simplify(c);       return c;     }     Poly<T> operator*(const T &b) const {       Poly<T> c;       int n = a.size();       c.resize(n);       for (int i = 0; i < (int)a.size(); i++) c[i] = a[i] * b;       return c;     }     Poly<T> operator+(const Poly &b) const {       Poly c;       int n = a.size(), m = b.size();       c.resize(max(n, m));       for (int i = 0; i < n && i < m; i++) c[i] = a[i] + b[i];       if (n < m)         copy(b.a.begin() + n, b.a.end(), c.a.begin() + n);       else         copy(a.begin() + m, a.end(), c.a.begin() + m);       simplify(c);       return c;     }     Poly<T> operator-() const {       Poly c;       int n = a.size();       c.resize(n);       for (int i = 0; i < n; i++) c[i] = -a[i];       return c;     }     Poly<T> operator-(const Poly<T> &b) const {       Poly c;       int n = a.size(), m = b.size();       c.resize(max(n, m));       for (int i = 0; i < n && i < m; i++) c[i] = a[i] - b[i];       if (n < m)         for (int i = n; i < m; i++) c[i] = -b[i];       else         copy(a.begin() + m, a.end(), c.a.begin() + m);       simplify(c);       return c;     }     Poly<T> operator/(const Poly<T> &b) const {       assert(!zero(b));       Poly c;       int n = a.size(), m = b.size();       if (n < m) return c;       Poly<T> tmp = *this;       c.resize(n - m + 1);       for (int i = n - 1; i >= m - 1; i--) {         T t = tmp[i] / b[m - 1];         c[i - m + 1] = t;         for (int j = 0; j < m; j++) tmp[i - j] -= b[m - 1 - j] * t;       }       return c;     }     Poly<T> operator%(const Poly<T> &b) const {       assert(!zero(b));       Poly<T> c;       int n = a.size(), m = b.size();       c = *this;       for (int i = n - 1; i >= m - 1; i--) {         T t = c[i] / b[m - 1];         for (int j = 0; j < m; j++) c[i - j] -= b[m - 1 - j] * t;       }       simplify(c);       return c;     }     Poly<T> &operator+=(const Poly<T> &b) {       *this = *this + b;       return *this;     }     Poly<T> &operator-=(const Poly<T> &b) {       *this = *this - b;       return *this;     }     Poly<T> &operator*=(const Poly<T> &b) {       *this = *this * b;       return *this;     }     Poly<T> &operator*=(const T &b) {       *this = *this * b;       return *this;     }     Poly<T> &operator/=(const Poly<T> &b) {       *this = *this / b;       return *this;     }     Poly<T> &operator%=(const Poly<T> &b) {       *this = *this % b;       return *this;     }     template <typename S>     S operator()(const S &b) const {       S ans;       Poly<T> a = *this;       int n = limn ? limn : a.size();       a.resize(n);       for (int i = n - 1; i >= 0; i--) {         ans = ans * b + S(a[i]);         if (limn) ans.resize(limn);       }       return ans;     }   };   void print(const Poly<Z> &a) {     int n = a.size();     if (!n) {       printf( 0 );       return;     }     for (int i = n - 1; i >= 1; i--) print(a[i]), printf( x^%d +  , i);     print(a[0]);   }   template <typename T>   Poly<T> monic(const Poly<T> &a) {     Poly<T> ans = a;     simplify(ans);     if (zero(ans)) return ans;     T t = ans[-1].inv();     for (int i = 0; i < ans.size(); i++) ans[i] = a[i] * t;     return ans;   }   template <typename T>   Poly<T> gcd(const Poly<T> &a, const Poly<T> &b) {     if (zero(b)) return monic(a);     return gcd(b, a % b);   }   template <typename T>   Poly<T> lcm(const Poly<T> &a, const Poly<T> &b) {     if (zero(a) || zero(b)) return Poly<T>();     return a * b / gcd(a, b);   }   template <typename T>   pair<Poly<T>, Poly<T> > exgcd(const Poly<T> &a, const Poly<T> &b,                                 const Poly<T> &c = Poly<T>(1)) {     if (zero(b)) {       assert(zero(c % a));       return make_pair(c / a, 0);     }     pair<Poly<T>, Poly<T> > t = exgcd(b, a % b, c);     return make_pair(t.second, t.first - a / b * t.second);   }   Poly<Z> Der(const Poly<Z> &a) {     Poly<Z> ans;     int n = a.size();     if (n <= 1) return ans;     ans.resize(n - 1);     for (int i = 0; i < n - 1; i++) ans[i] = a[i + 1] * (Z(i + 1));     return ans;   }   Poly<Z> Ln(const Poly<Z> &A) {     Poly<Z> a = A;     int n = limn ? limn : a.size();     a.resize(n);     Poly<Z> ans;     ans.resize(n);     ans[0] = 0;     assert(a[0].x == 1);     for (int i = 1; i < n; i++) {       ans[i] = Z(i) * a[i];       for (int j = 0; j < i; j++) ans[i] -= ans[j] * a[i - j];     }     for (int i = 1; i < n; i++) ans[i] *= inv[i];     return ans;   }   Poly<Z> Exp(const Poly<Z> &A) {     Poly<Z> a = A;     int n = limn ? limn : a.size();     a.resize(n);     Poly<Z> ans;     ans.resize(n);     ans[0] = 1;     assert(a[0].x == 0);     for (int i = 1; i < n; i++) {       for (int j = 0; j < i; j++) ans[i] += ans[j] * a[i - j] * Z(i - j);       ans[i] *= inv[i];     }     return ans;   }   Poly<Z> Inv(const Poly<Z> &A) {     Poly<Z> a = A;     int n = limn ? limn : a.size();     a.resize(n);     Poly<Z> ans;     ans.resize(n);     Z iv = a[0].inv();     ans[0] = iv;     for (int i = 1; i < n; i++) {       for (int j = 0; j < i; j++) ans[i] -= ans[j] * a[i - j];       ans[i] *= iv;     }     return ans;   }   Poly<Z> Pow(const Poly<Z> &A, const int &K) {     Poly<Z> a = A;     int n = limn ? limn : a.size();     a.resize(n);     Poly<Z> tmp = a;     simplify(tmp);     if (zero(tmp)) return tmp;     int pos = 0;     for (int i = 0; i < tmp.size(); i++)       if (!zero(tmp[i])) {         pos = i;         break;       }     copy(tmp.a.begin() + pos, tmp.a.end(), tmp.a.begin());     tmp.resize(tmp.size() - pos);     Z iv = tmp[0].inv();     for (int i = 0; i < tmp.size(); i++) tmp[i] * iv;     Poly<Z> ans = tmp;     ans.resize(n);     ans = Ln(ans);     for (int i = 1; i < n; i++) ans[i] *= K;     ans = Exp(ans);     if (pos * K >= n) return Poly<Z>();     ans.resize(ans.size() + pos * K);     copy(ans.a.begin(), ans.a.end(), ans.a.begin() + pos * K);     ans.resize(n);     iv = iv.inv();     iv = qpower(iv.x, K);     for (int i = 0; i < n; i++) ans[i] *= iv;     return ans;   }   Poly<Z> Sqrt(const Poly<Z> &a) { return Pow(a, (mod + 1) >> 1); }   Poly<Z> mul(const Poly<Z> &A, const Poly<Z> &B) {     Poly<Z> a = A, b = B;     int n;     if (limn)       n = limn, a.resize(n), b.resize(n);     else       n = a.size() + b.size() - 1, a.resize(n), b.resize(n);     Poly<Z> ans;     ans.resize(n);     for (int i = 0; i < n; i++)       for (int j = 0; j + i < n; j++) ans[i + j] += a[i] * b[j];     return ans;   }   struct FRAC {     Poly<Z> u, v;     FRAC(const Z &x) {       u = x;       v = Z(1);     }     FRAC(const int &x) {       u = Z(x);       v = Z(1);     }     FRAC() { u = Z(0), v = Z(1); }     FRAC(const Poly<Z> &_u) {       u = _u;       v = Z(1);     }     FRAC(const Poly<Z> &_u, const Poly<Z> &_v) {       u = _u, v = _v;       simplify(u), simplify(v);       if (zero(u)) {         v = 1;         return;       }       Poly<Z> d = gcd(u, v);       u /= d, v /= d;       Poly<Z> c = v[-1];       u /= c, v /= c;     }     FRAC operator+(const FRAC &a) const {       return (FRAC){u * a.v + v * a.u, v * a.v};     }     FRAC operator-(const FRAC &a) const {       return (FRAC){u * a.v - v * a.u, v * a.v};     }     FRAC operator*(const FRAC &a) const { return (FRAC){u * a.u, v * a.v}; }     FRAC operator/(const FRAC &a) const { return (FRAC){u * a.v, v * a.u}; }     FRAC operator-() const { return (FRAC){-u, v}; }     FRAC operator()(const FRAC &a) const {       FRAC fz, fm;       for (int i = (int)u.size() - 1; i >= 0; i--) fz = fz * a + (FRAC){u[i]};       for (int i = (int)v.size() - 1; i >= 0; i--) fm = fm * a + (FRAC){v[i]};       return fz / fm;     }     FRAC inv() { return (FRAC){v, u}; }   };   bool zero(const FRAC &a) { return zero(a.u); }   FRAC &operator+=(FRAC &a, const FRAC &b) {     a = a + b;     return a;   }   FRAC &operator-=(FRAC &a, const FRAC &b) {     a = a - b;     return a;   }   FRAC &operator*=(FRAC &a, const FRAC &b) {     a = a * b;     return a;   }   FRAC &operator/=(FRAC &a, const FRAC &b) {     a = a / b;     return a;   }   FRAC Der(const FRAC &a) {     return (FRAC){Der(a.u) * a.v - a.u * Der(a.v), a.v * a.v};   }   void print(const FRAC &a) {     putchar( ( ), print(a.u), printf( ) / ( );     print(a.v);     putchar( ) );   }   struct Basis {     vector<Poly<FRAC> > a;     vector<Poly<FRAC> > c;     int n;     Basis(int _n) {       n = _n;       a.resize(n);       for (int i = 0; i < n; i++) a[i].resize(n);       c.resize(n);       for (int i = 0; i < n; i++) c[i].resize(n);     }     pair<bool, Poly<FRAC> > ins(Poly<FRAC> x) {       Poly<FRAC> tc;       tc.resize(n);       for (int i = 0; i < n; i++) {         if (zero(x[i])) continue;         if (zero(a[i])) {           a[i] = x;           c[i] = tc;           c[i][i] = 1;           return make_pair(1, 0);         }         FRAC t = -x[i] / a[i][i];         tc[i] = t;         x += a[i] * t;         x.resize(n);       }       for (int j = 0; j < n; j++) tc[j] = -tc[j];       Poly<FRAC> ans;       ans.resize(n);       setn(n);       for (int j = 0; j < n; j++) ans += c[j] * tc[j];       setn(0);       simplify(ans);       return make_pair(0, ans);     }   };   template <typename T>   int mindeg(const Poly<T> &a) {     int n = a.size() - 1;     for (int i = 0; i < n; i++)       if (!zero(a[i])) return i;     return -1;   }   struct ODE {     Poly<FRAC> a;     int size() const { return a.size(); }     int length() const {       Poly<Z> t = 1;       for (int i = 0; i < (int)a.size(); i++) t = lcm(t, a[i].v);       Poly<FRAC> tmpa = a;       for (int i = 0; i < (int)tmpa.size(); i++) tmpa[i] *= (FRAC){t};       int mxpos = tmpa.size() - mindeg(t), mipos = tmpa.size() - (t.size() - 1);       for (int i = 0; i < (int)tmpa.size(); i++)         if (!zero(tmpa[i]))           mxpos = max(mxpos, i - mindeg(tmpa[i].u)),           mipos = min(mipos, i - (int)(tmpa[i].u.size() - 1));       return mxpos - mipos;     }     Poly<Z> geta(const Poly<Z> &a0, const int &n) const {       int m = a0.size();       Poly<Z> t = 1;       for (int i = 0; i < (int)a.size(); i++) t = lcm(t, a[i].v);       Poly<FRAC> tmpa = a;       for (int i = 0; i < (int)tmpa.size(); i++) tmpa[i] *= (FRAC){t};       int mxpos = tmpa.size() - mindeg(t), mipos = tmpa.size() - (t.size() - 1);       for (int i = 0; i < (int)tmpa.size(); i++)         if (!zero(a[i]))           mxpos = max(mxpos, i - mindeg(tmpa[i].u)),           mipos = min(mipos, i - (int)(tmpa[i].u.size() - 1));       assert(m >= mxpos - mipos);       vector<vector<Z> > pw;       pw.resize(n + 1);       for (int i = 0; i <= n; i++) {         pw[i].resize(tmpa.size() + 1);         pw[i][0] = 1;         for (int j = 1; j < (int)pw[i].size(); j++)           pw[i][j] = pw[i][j - 1] * (Z){i - j + 1};       }       Poly<Z> ans = a0;       ans.resize(n + 1);       for (int i = m; i <= n; i++) {         Z u = 0, v = 0;         for (int j = 0; j < t.size(); j++) {           if (zero(t[j])) continue;           int d = mxpos - (tmpa.size() - j);           if (!d)             u += t[j] * pw[i][tmpa.size()];           else             v -= pw[i - d][tmpa.size()] * t[j] * ans[i - d];         }         for (int j = 0; j < (int)tmpa.size(); j++)           for (int k = 0; k < tmpa[j].u.size(); k++) {             if (zero(tmpa[j].u[k])) continue;             int d = mxpos - (j - k);             if (!d)               u -= tmpa[j].u[k] * pw[i][j];             else               v += ans[i - d] * pw[i - d][j] * tmpa[j].u[k];           }         assert(!zero(u) || zero(v));         if (!zero(u))           ans[i] = v / u;         else           ans[i] = 1;       }       return ans;     }   };   bool zero(const ODE &a) { return zero(a.a); }   void print(const ODE &a) {     if (!a.size()) {       puts( F=0 );       return;     }     int n = a.size();     printf( F(%d) = , n);     putchar( ( ), print(a.a[0]);     printf( )F );     for (int i = 1; i < n; i++)       printf(  +  ), printf( ( ), print(a.a[i]), printf( )F(%d) , i);     puts(  );   }   ODE operator+(const ODE &A, const ODE &B) {     if (zero(A)) return B;     if (zero(B)) return A;     Poly<FRAC> a = A.a, b = B.a;     int n = a.size(), m = b.size();     ODE ans;     Poly<FRAC> tmp;     tmp.resize(n + m);     tmp[0] = 1, tmp[n] = 1;     Basis bs(n + m);     for (;;) {       pair<bool, Poly<FRAC> > t = bs.ins(tmp);       if (!t.first) {         ans.a = t.second;         break;       }       FRAC u = tmp[n - 1];       tmp[n - 1] = Der(tmp[n - 1]);       for (int i = n - 2; i >= 0; i--) tmp[i + 1] += tmp[i], tmp[i] = Der(tmp[i]);       for (int i = 0; i < n; i++) tmp[i] += u * a[i];       u = tmp[n + m - 1];       tmp[n + m - 1] = Der(tmp[n + m - 1]);       for (int i = n + m - 2; i >= n; i--)         tmp[i + 1] += tmp[i], tmp[i] = Der(tmp[i]);       for (int i = n; i < n + m; i++) tmp[i] += u * b[i - n];     }     return ans;   }   ODE operator*(const ODE &A, const ODE &B) {     if (zero(A)) return B;     if (zero(B)) return A;     Poly<FRAC> a = A.a, b = B.a;     int n = a.size(), m = b.size();     ODE ans;     Poly<FRAC> tmp;     tmp.resize(n * m);     tmp[0] = 1;     Basis bs(n * m);     for (int T = 0;; ++T) {       pair<bool, Poly<FRAC> > t = bs.ins(tmp);       if (!t.first) {         ans.a = t.second;         break;       }       Poly<FRAC> ttmp = tmp;       tmp.clear();       tmp.resize(n * m);       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) {           tmp[i * m + j] += Der(ttmp[i * m + j]);           if (i != n - 1)             tmp[(i + 1) * m + j] += ttmp[i * m + j];           else {             for (int k = 0; k < n; k++) tmp[k * m + j] += ttmp[i * m + j] * a[k];           }           if (j != m - 1)             tmp[i * m + j + 1] += ttmp[i * m + j];           else {             for (int k = 0; k < m; k++) tmp[i * m + k] += ttmp[i * m + j] * b[k];           }         }     }     return ans;   }   ODE composite(const ODE &A, const FRAC &b) {     if (zero(A)) return A;     ODE ans;     Poly<FRAC> tmp;     Poly<FRAC> a = A.a;     int n = a.size();     FRAC db = Der(b);     tmp.resize(n);     tmp[0] = 1;     Basis bs(n);     for (;;) {       pair<bool, Poly<FRAC> > t = bs.ins(tmp);       if (!t.first) {         ans.a = t.second;         break;       }       FRAC u = tmp[n - 1] * db;       tmp[n - 1] = Der(tmp[n - 1]);       for (int i = n - 2; i >= 0; i--)         tmp[i + 1] += tmp[i] * db, tmp[i] = Der(tmp[i]);       if (!zero(u))         for (int i = 0; i < n; i++) tmp[i] += a[i](b) * u;     }     return ans;   }   Poly<FRAC> trans_vector(const vector<Poly<FRAC> > &a, const int &n,                           const int &m) {     Poly<FRAC> ans;     ans.resize(n * m);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         ans[i * m + j] = a[i][j];       }     return ans;   }   Poly<FRAC> composite(const FRAC &a, const Poly<FRAC> &b) {     Poly<FRAC> u, v;     u.resize(a.u.size()), v.resize(a.v.size());     for (int i = 0; i < a.u.size(); i++) u[i] = a.u[i];     for (int i = 0; i < a.v.size(); i++) v[i] = a.v[i];     return exgcd(v % b, b, u % b).first % b;   }   void print(const Poly<FRAC> &a) {     int n = a.size();     putchar( ( ), print(a[0]), putchar( ) );     for (int i = 1; i < n; i++) printf(  + ( ), print(a[i]), printf( )u^%d , i);     puts(  );   }   ODE composite(const ODE &A, const Poly<FRAC> &B) {     if (!A.size()) return A;     Poly<FRAC> b = monic(B);     assert(b.size() > 1);     Poly<FRAC> a = A.a;     ODE ans;     vector<Poly<FRAC> > tmp;     assert(b.size() > 1);     int n = a.size(), m = b.size();     Poly<FRAC> du;     {       Poly<FRAC> u = b;       for (int i = 0; i < m; i++) u[i] = Der(u[i]);       simplify(u);       Poly<FRAC> v = b;       for (int i = 0; i < m - 1; i++) v[i] = v[i + 1] * FRAC(Poly<Z>(i + 1));       v.pop_back();       du = exgcd(v, b, -u).first % b;     }     --m;     tmp.resize(n);     tmp[0] = Poly<FRAC>(1);     for (int i = 0; i < n; i++) tmp[i].resize(m);     Basis bs(n * m);     int T = 0;     for (;;) {       pair<bool, Poly<FRAC> > t = bs.ins(trans_vector(tmp, n, m));       if (!t.first) {         ans.a = t.second;         break;       }       vector<Poly<FRAC> > ttmp = tmp;       tmp.clear();       tmp.resize(n);       for (int i = 0; i < n; i++) tmp[i].resize(m);       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) tmp[i][j] += Der(ttmp[i][j]);       for (int i = 0; i < n - 1; i++) {         Poly<FRAC> t = du * ttmp[i] % b;         tmp[i + 1] += t;       }       for (int i = 0; i < n; i++)         tmp[i] += composite(a[i], b) * du * ttmp[n - 1] % b;       for (int i = 0; i < n; i++) {         Poly<FRAC> t = ttmp[i];         for (int j = 0; j < t.size() - 1; j++) t[j] = FRAC(j + 1) * t[j + 1];         t.pop_back();         tmp[i] += t * du % b;       }       for (int i = 0; i < n; i++) tmp[i].resize(m);     }     return ans;   }   Poly<Z> calc0(const int &n, const int &len) {     setn(len);     Poly<Z> X(0, 1);     Poly<Z> t;     t.resize(3);     t[0] = 1, t[1] = 6, t[2] = 1;     t = Sqrt(t);     Poly<Z> r = (Poly<Z>(1, 1) + t) * Z((mod + 1) >> 1);     return mul(Pow(r, n), Inv(t));   }   ODE getODE(const int &n) {     Poly<Z> X(0, 1);     ODE ans;     ODE t;     t.a = Poly<FRAC>(FRAC(n, X));     Poly<FRAC> tf;     tf.resize(3);     tf[0] = -X, tf[1] = Poly<Z>(-1, -1), tf[2] = 1;     ans = ans * composite(t, tf);     t.a = Poly<FRAC>(FRAC((mod - 1) >> 1, X));     FRAC tx;     tx.u.resize(3);     tx.u[0] = 1, tx.u[1] = 6, tx.u[2] = 1;     ans = ans * composite(t, tx);     return ans;   }   int main() {     int n, K;     scanf( %d%d , &n, &K);     int tK = K;     K = min(K, n);     prework(20);     ODE h = getODE(n + 1);     Poly<Z> ans = h.geta(calc0(n + 1, h.length()), K);     for (int i = 1; i <= K; i++) print(ans[i]), putchar(   );     for (int i = K + 1; i <= tK; i++) putchar( 0 ), putchar(   );     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     if (k >= (n - 1) * n / 2) {       cout <<  no solution n ;     } else {       for (int i = 1; i <= n; i++) {         cout << 0 <<     << i <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using ll = long long;   const int MV = 1e6;   const int p10[] = {1, 10, 100, 1000, 10000, 100000};   int K, Q, F[6];   ll dp[MV];   ll val(int x) {     ll f = 0;     for (int i = 0; x; ++i, x /= 10) {       int d = x % 10;       if (d % 3 == 0) f += (ll)F[i] * d / 3;     }     return f;   }   struct info {    public:     int k;     ll v;   };   std::deque<info> q;   int main() {     scanf( %d , &K);     for (int i = 0; i < 6; ++i) scanf( %d , F + i);     --K;     K *= 3;     for (int i = 0; i < MV; ++i) dp[i] = val(i);     for (int i = 0; i < 6; ++i) {       for (int j = 0; j < 3 * p10[i]; ++j) {         int mv = 1 + (MV - j - 1) / (3 * p10[i]);         std::function<ll&(int)> get = [&](int x) -> ll& {           assert(j + x * 3 * p10[i] < MV);           return dp[j + x * 3 * p10[i]];         };         for (int k = 0; k < mv; ++k) {           for (; !q.empty() && k - q.front().k > K;) q.pop_front();           for (;                !q.empty() && get(k) >= q.back().v + (ll)F[i] * (k - q.back().k);)             q.pop_back();           q.push_back({k, get(k)});           get(k) = q.front().v + (ll)F[i] * (k - q.front().k);         }         q.clear();       }     }     scanf( %d , &Q);     for (int i = 0; i < Q; ++i) {       int N;       scanf( %d , &N);       printf( %lld n , dp[N]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long c[2000], d[2000];   long long u[2000], b[2000];   int main() {     long long n, m, d;     long long lpl = 0;     cin >> n >> m >> d;     for (int i = 0; i < m; i++) {       cin >> c[i];       lpl += c[i];     }     if (lpl == n) {       cout <<  YES  << endl;       for (int i = 0; i < m; i++) {         for (int j = 0; j < c[i]; j++) {           cout << i + 1 <<    ;         }       }       cout << endl;       return 0;     }     long long st = 0;     long long flag = 0;     for (int i = 0; i < m; i++) {       long long op = c[i];       op = n - (lpl - op) - 1;       long long to = st + d;       long long ss = op - c[i] + 1;       if (to > ss) {         u[i] = ss;         st = ss + c[i] - 1;       }       if (to <= ss) {         u[i] = to;         st = to + c[i] - 1;       }       lpl -= c[i];     }     if (st + d > n) {       cout <<  YES  << endl;       for (int i = 0; i < m; i++) {         for (int j = u[i]; j < u[i] + c[i]; j++) {           b[j] = i + 1;         }       }       for (int i = 1; i <= n; i++) {         cout << b[i] <<    ;       }       cout << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   const int _ = 1e4 + 5;   const long long INF = 1ll << 60;   inline long long min(long long a, long long b) { return a < b ? a : b; }   int n, c, s[_], t[_];   long long dp[2][_];   int main() {     scanf( %d %d , &n, &c);     for (int i = 1; i <= n; ++i) scanf( %d , s + i);     for (int i = 1; i <= n; ++i) scanf( %d , t + i);     for (int i = 1; i <= n; ++i) {       memset(dp[i & 1], 0x3f, sizeof dp[i & 1]);       dp[i & 1][0] = dp[(i - 1) & 1][0] + s[i];       for (int j = 1; j <= i; ++j)         dp[i & 1][j] = min(dp[(i - 1) & 1][j] + 1ll * c * j + s[i],                            dp[(i - 1) & 1][j - 1] + t[i]);     }     long long ans = INF;     for (int i = 0; i <= n; ++i) ans = min(ans, dp[n & 1][i]);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     srand(time(NULL));     ;     int T = 1;     cin >> T;     while (T--) {       int n, r = 0, c = 0;       string s;       cin >> n >> s;       for (int i = 0; i < int(n); i++) r += s[i] ==  R ;       if (r > 0 && r < n) {         int j = 0;         while (s[(j - 1 + n) % n] ==  R  || s[j] ==  L ) j++;         s = s.substr(j, n - j) + s.substr(0, j);         char d =  R ;         for (int i = 0; i < int(n); i++) {           int j = i;           while (j < n && s[j] == d) j++;           c += (j - i) / 3;           d = (d ==  R ) ?  L  :  R ;           i = j - 1;         }         cout << c << endl;       } else         cout << (n + 2) / 3 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string first, secound;     string arr1[100], arr2[100], arr3[100], arr4[100];     int counter1 = 0, counter2 = 0, counter3 = 0, counter4 = 0;     for (int i = 0; i < n; i++) {       cin >> first >> secound;       if (secound ==  rat )         arr1[counter1++] = first;       else if ((secound ==  woman ) || (secound ==  child )) {         arr2[counter2++] = first;       } else if (secound ==  man ) {         arr3[counter3++] = first;       } else {         arr4[counter4++] = first;       }     }     for (int k = 0; k < counter1; k++) cout << arr1[k] << endl;     for (int i = 0; i < counter2; i++) {       cout << arr2[i] << endl;     }     for (int j = 0; j < counter3; j++) {       cout << arr3[j] << endl;     }     for (int m = 0; m < counter4; m++) cout << arr4[m] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300000;   long long abss(long long a) {     if (a < 0) {       a = -a;     }     return a;   }   long long n;   long long xx;   long long aa[N + 5] = {0}, su[N + 5];   long long mm[105] = {0};   int main() {     mm[0] = 1;     scanf( %lld , &n);     long long ans = 0;     su[0] = 0;     for (int i = 1; i <= n; ++i) {       scanf( %lld , &xx);       while (xx) {         if (xx & 1) {           ++aa[i];         }         xx >>= 1;       }       su[i] = su[i - 1] + aa[i];     }     long long l[2] = {1, 0};     aa[0] = 0;     for (int i = 1; i <= n; ++i) {       int bitt = su[i] & 1;       ans += l[bitt];       long long mx = aa[i];       long long rem = 0;       for (int j = i - 1; j >= 0 && j >= i - 63; --j) {         if ((su[i] - su[j]) % 2 == 0 && rem < mx) {           --ans;         }         if (mx < aa[j]) {           rem += mx;           mx = aa[j];         } else {           rem += aa[j];           ;         }       }       ++l[bitt];       ;     }     printf( %lld , ans);     ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,unroll-loops )   #pragma GCC target( avx,avx2,fma )   using namespace std;   const long long sz = 3e3 + 10, mod = 998244353;   char s[sz], t[sz];   long long dp[sz][sz];   long long solve(long long l, long long r) {     if (l > r) return 1;     long long &ret = dp[l][r];     if (ret != -1) return ret;     long long rt = 0, idx = r - l + 1;     if (s[idx] == t[r] || t[r] ==  $ ) rt = (rt + solve(l, r - 1)) % mod;     if (s[idx] == t[l] || t[l] ==  $ ) rt = (rt + solve(l + 1, r)) % mod;     return ret = rt;   }   int main() {     scanf( %s , s + 1);     scanf( %s , t + 1);     long long n = strlen(s + 1), m = strlen(t + 1);     long long m2 = m;     while (m2 < n) t[++m2] =  $ ;     memset(dp, -1, sizeof(dp));     long long tot = 0;     for (long long i = m; i <= n; i++) tot = (tot + solve(1, i)) % mod;     cout << tot << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     printf( %d 0 0 , n);   }


#include <bits/stdc++.h>   using namespace std;   int n, k, d, t;   int a[1000005], b[1000005], c[1000005];   char ch[1000005], ans[1000005];   void mul(int* a, int* b) {     for (int i = 0; i < n; ++i) {       c[i] = b[a[i]];     }     for (int i = 0; i < n; ++i) {       a[i] = c[i];     }   }   int main() {     scanf( %s , ch);     n = strlen(ch);     scanf( %d , &t);     while (t--) {       scanf( %d%d , &k, &d);       int now = 0;       for (int i = 0; i < d; ++i) {         for (int j = i; j < k; j += d) {           a[j] = now++;         }       }       for (int i = k; i < n; ++i) {         a[i] = i;       }       for (int i = 0; i < n; ++i) {         a[i] = (a[i] - 1 + n) % n;       }       for (int i = 0; i < n; ++i) {         b[i] = i;       }       now = (n - k + 1);       while (now) {         if (now & 1) {           mul(b, a);         }         mul(a, a);         now >>= 1;       }       for (int i = 0; i < n; ++i) {         ans[(b[i] + n - k + 1) % n] = ch[i];       }       for (int i = 0; i < n; ++i) {         ch[i] = ans[i];       }       printf( %s n , ch);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long M[110000 * 4];   long long lazy[110000 * 4];   void down(int x) {     if (lazy[x] != -1) {       M[x * 2] = max(M[x * 2], lazy[x]);       M[x * 2 + 1] = max(M[x * 2 + 1], lazy[x]);       lazy[x * 2] = max(lazy[x], lazy[x * 2]);       lazy[x * 2 + 1] = max(lazy[x], lazy[x * 2 + 1]);       lazy[x] = -1;     }   }   void up(int x) { M[x] = max(M[x * 2], M[x * 2 + 1]); }   void cover(int now, int l, int r, int x, int y, long long v) {     down(now);     if (x <= l && r <= y) {       M[now] = v;       lazy[now] = v;       return;     }     int mid = (l + r) >> 1;     if (x <= mid) cover(now * 2, l, mid, x, y, v);     if (y > mid) cover(now * 2 + 1, mid + 1, r, x, y, v);     up(now);   }   long long ask(int now, int l, int r, int x, int y) {     down(now);     if (x <= l && r <= y) return M[now];     int mid = (l + r) >> 1;     long long res = 0;     if (x <= mid) res = max(res, ask(now * 2, l, mid, x, y));     if (y > mid) res = max(res, ask(now * 2 + 1, mid + 1, r, x, y));     return res;   }   int main() {     memset(lazy, -1, sizeof lazy);     int n, m;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int v;       scanf( %d , &v);       cover(1, 1, n, i, i, v);     }     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       int w, h;       scanf( %d%d , &w, &h);       long long res = ask(1, 1, n, 1, w);       printf( %I64d n , res);       cover(1, 1, n, 1, w, h + res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fre() {     freopen( c://test//input.in ,  r , stdin);     freopen( c://test//output.out ,  w , stdout);   }   template <class T1, class T2>   inline void gmax(T1 &a, T2 b) {     if (b > a) a = b;   }   template <class T1, class T2>   inline void gmin(T1 &a, T2 b) {     if (b < a) a = b;   }   const int N = 4040, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;   int n, m;   int y, x;   int ln[1010], ls[1010];   vector<int> a[N];   int p[N];   bool e[N];   int hungary(int x) {     e[x] = 1;     for (int i = a[x].size() - 1; ~i; i--) {       int y = a[x][i];       if (p[y] == -1) {         p[y] = x;         return 1;       }     }     for (int i = a[x].size() - 1; ~i; i--) {       int y = a[x][i];       if (!e[p[y]] && hungary(p[y])) {         p[y] = x;         return 1;       }     }     return 0;   }   void ins(int x, int y) { a[x].push_back(y); }   int main() {     while (~scanf( %d%d , &n, &m)) {       memset(ln, 1, sizeof(ln));       memset(ls, 1, sizeof(ls));       int n2 = n * 2;       int n3 = n * 3;       int n4 = n * 4;       for (int i = 1; i <= n4; ++i) a[i].clear();       for (int i = 1; i <= m; ++i) {         scanf( %d%d , &y, &x);         ln[y] = 0;         ls[x] = 0;       }       for (int i = 2; i < n; ++i)         if (ln[i]) {           ins(i, i + n);           ins(i + n, i);           if (ls[i]) {             ins(i, i + n2);             ins(i + n2, i);           }           if (ls[n + 1 - i]) {             ins(i, i + n3);             ins(i + n3, i);           }           if (ls[n + 1 - i]) {             ins(i + n, i + n3);             ins(i + n3, i + n);           }           if (ls[n + 1 - i]) {             ins(i + n, n + 1 - i + n2);             ins(n + 1 - i + n2, i + n);           }         }       for (int j = 2; j < n; ++j)         if (ls[j]) {           ins(n + n + j, n + n + n + j);           ins(n + n + n + j, n + n + j);         }       memset(p, -1, sizeof(p));       int ans = 0;       for (int i = 1; i <= n4; i++) {         memset(e, 0, sizeof(e));         if (hungary(i)) ans++;       }       ans /= 2;       if (n & 1) {         if (ln[n / 2 + 1] && ls[n / 2 + 1]) --ans;       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> vv[3001];   int graf[3001][3001];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int f, t;       cin >> f >> t;       vv[f].push_back(t);       graf[f][t] = 1;     }     long long ans(0);     for (int a = 1; a <= n; a++)       for (int c = 1; c <= n; c++) {         if (a == c) continue;         int cnt(0);         for (int i = 0; i < vv[a].size(); i++) {           int b = vv[a][i];           if (graf[b][c]) {             cnt++;           }         }         ans += 1LL * cnt * (cnt - 1) / 2;       }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = LLONG_MAX;   const long long base = 1e9;   const double PI = acos(-1);   const long long MOD = 1e9 + 7;   const long long N = 1e5 + 10;   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     long long a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     if (a[0] != 0) {       cout <<  1  << endl;       return 0;     }     long long mx = 0;     for (int i = 1; i < n; i++) {       mx = max(mx, a[i - 1]);       if (a[i] - mx > 1) {         cout << i + 1 << endl;         return 0;       }     }     cout <<  -1  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 755, M = 10000005;   char s[M];   bool e[N][N];   int n;   struct ACAutomaton {     int trie[M][2], id[M], idx, pos[M], fa[M];     void ins(char *s, int t) {       int cur = 0, l = strlen(s + 1);       for (int i = 1; i <= l; i++) {         if (!trie[cur][s[i] -  a ]) trie[cur][s[i] -  a ] = ++idx, fa[idx] = cur;         cur = trie[cur][s[i] -  a ];       }       id[cur] = t;       pos[t] = cur;     }     int fail[M];     void build_fail() {       queue<int> q;       for (int i = 0; i < 2; i++)         if (trie[0][i]) q.push(trie[0][i]);       while (!q.empty()) {         int nd = q.front();         q.pop();         for (int i = 0; i < 2; i++)           if (trie[nd][i])             fail[trie[nd][i]] = trie[fail[nd]][i], q.push(trie[nd][i]);           else             trie[nd][i] = trie[fail[nd]][i];       }     }     int f[M];     int getf(int v) { return f[v] == v ? v : f[v] = getf(f[v]); }     void build_tr() {       for (int i = 1; i <= idx; i++) f[i] = id[i] ? i : fail[i];       for (int i = 1; i <= n; i++) {         int p = pos[i];         if (id[getf(fail[p])]) e[i][id[getf(fail[p])]] = 1;         p = fa[pos[i]];         while (p) {           if (id[p]) {             e[i][id[p]] = 1;             break;           }           if (id[getf(p)]) e[i][id[getf(p)]] = 1;           p = fa[p];         }       }     }   } t;   int mat[N], mat2[N];   bool vis[N];   int find(int pos) {     if (vis[pos]) return 0;     vis[pos] = 1;     for (int i = 1; i <= n; i++)       if (e[pos][i] && (!mat[i] || find(mat[i]))) {         mat[i] = pos;         return 1;       }     return 0;   }   bool vis1[N], vis2[N];   void dfs(int pos) {     if (vis1[pos]) return;     vis1[pos] = 1;     for (int i = 1; i <= n; i++)       if (e[pos][i] && mat2[pos] != i && !vis2[i]) {         vis2[i] = 1;         if (mat[i]) dfs(mat[i]);       }   }   int ans[N], idx;   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) cin >> (s + 1), t.ins(s, i);     t.build_fail();     t.build_tr();     for (int k = 1; k <= n; k++)       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++) e[i][j] |= e[i][k] & e[k][j];     for (int i = 1; i <= n; i++) memset(vis, 0, sizeof(vis)), find(i);     for (int i = 1; i <= n; i++)       if (mat[i]) mat2[mat[i]] = i;     for (int i = 1; i <= n; i++)       if (!mat2[i]) dfs(i);     for (int i = 1; i <= n; i++)       if (vis1[i] && !vis2[i]) ans[++idx] = i;     cout << idx << endl;     for (int i = 1; i <= idx; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   int n, ans, lst[5010][2];   int comp(const void *a, const void *b) {     int x = ((int *)a)[0] - ((int *)b)[0];     if (x) return x;     return ((int *)a)[1] - ((int *)b)[1];   }   int main() {     int i;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d%d , &lst[i][0], &lst[i][1]);     qsort(lst + 1, n, sizeof(lst[0]), comp);     for (i = 1; i <= n; i++) {       if (lst[i][1] >= ans)         ans = lst[i][1];       else         ans = lst[i][0];     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   int ATTENTION() {   http:     return 0;   }   using namespace std;   const int iinf = 0x7fffffff;   const long long linf = ~(1LL << 63);   template <typename T>   inline T gcd(T a, T b) {     if (a < 0) return gcd(-a, b);     if (b < 0) return gcd(a, -b);     if (a < b) return gcd(b, a);     if (b == 0) return a;     return gcd(b, a % b);   }   long long qpow(long long a, long long n, long long mod) {     a %= mod;     long long ans = 1LL;     while (n) {       if (n & 1) ans = (ans * a % mod);       a = (a * a % mod);       n >>= 1;     }     return ans;   }   inline long long rev(long long a, long long p) { return qpow(a, p - 2, p); }   template <typename T>   inline void BPS(T* DST, T* SRC, int N, int s = 0) {     DST[s] = SRC[s];     for (int i = 1; i < N; i++) DST[s + i] = DST[s + i - 1] + SRC[s + i];   }   inline int in() {     int x;     cin >> x;     return x;   }   inline void tic() {}   inline void toc() {}   bitset<100000001> is_prime;   int n, A, B, C, D;   void unset_prime(unsigned int v) { is_prime.reset(v / 3); }   unsigned int f(unsigned int x) {     return ((((unsigned int)A * x + (unsigned int)B)) * x + (unsigned int)C) * x +            (unsigned int)D;   }   int main() {     scanf( %u%u%u%u%u , &n, &A, &B, &C, &D);     is_prime.set();     unsigned int res = 0;     unsigned int t = n;     unsigned int p2 = 2;     unsigned int fp = f(2);     while (t >= p2) {       res += t / p2 * fp;       p2 *= 2;     }     p2 = 3;     fp = f(3);     while (t >= p2) {       res += t / p2 * fp;       p2 *= 3;     }     for (unsigned int i = 5; i <= n; i += 2) {       if (is_prime[i / 3] == 0) {         if (i % 3 == 1) i += 2;         continue;       }       for (unsigned int j = 5 * i, k = 5; j <= n; j += 2 * i, k += 2) {         unset_prime(j);         if (k % 3 == 1) {           k += 2;           j += 2 * i;         }       }       t = n;       long long pi = i;       fp = f(i);       while (t >= pi) {         res += t / pi * fp;         pi *= i;       }       if (i % 3 == 1) i += 2;     }     printf( %u n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[4] = {0, 0, 1, -1};   int dy[4] = {1, -1, 0, 0};   const int mod = (int)1e9 + 7;   long long INF64 = 3e18;   void smxl(long long &a, long long b) {     if (a < b) a = b;   }   void smnl(long long &a, long long b) {     if (a > b) a = b;   }   void adsl(long long &a, long long b) {     a += b;     if (a >= mod) a -= mod;   }   void misl(long long &a, long long b) {     a -= b;     if (a >= mod) a -= mod;     if (a < 0) a += mod;   }   void smx(long long &a, long long b) {     if (a < b) a = b;   }   void smn(long long &a, long long b) {     if (a > b) a = b;   }   void ads(long long &a, long long b) {     a += b;     if (a >= mod) a -= mod;   }   void mis(long long &a, long long b) {     a -= b;     if (a >= mod) a -= mod;     if (a < 0) a += mod;   }   long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }   long long egcd(long long a, long long b, long long &x, long long &y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     long long x1, y1;     long long d = egcd(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return d;   }   long long mbinp(long long a, long long b) {     a %= mod;     if (b == 0) return 1;     long long ans = mbinp(a, b / 2);     long long tmp = (ans * ans) % mod;     if (b % 2) return ((tmp * a) % mod);     return ((tmp) % mod);   }   long long C(int n, int m) {     long long ret = 1;     for (int i = 1; i <= m; i++) {       ret *= (n - i + 1);       ret /= i;     }     return ret;   }   long long binp(long long a, int b) {     long long res = 1;     while (b) {       if (b & 1) {         if (res < INF64 / a)           res *= a;         else           return INF64;       }       if (b > 1) {         if (a < INF64 / a)           a *= a;         else           return INF64;       }       b >>= 1;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     vector<int> primes(100, 0);     vector<int> mu(100, 0);     for (int i = 2; i < 100; i++) {       if (primes[i] == 0) {         mu[i]++;         for (int j = 2 * i; j < 100; j += i) {           primes[j] = 1;           if (mu[j] != -1) mu[j]++;         }         for (int z = i * i; z < 100; z += i * i) mu[z] = -1;       }     }     mu[1] = 2;     vector<pair<long long, int> > all(n);     for (int i = 0; i < n; i++) {       cin >> all[i].first;       all[i].second = i;     }     sort(all.rbegin(), all.rend());     vector<long long> poss(62);     for (int i = 3; i < 62; i++)       poss[i] = (long long)ceil(pow((long double)1e18, 1.0 / i));     vector<long long> ans(n);     for (int i = 0; i < n; i++) {       long long skr = -1;       long long low = 0;       long long hi = 1e9 + 10;       while (low <= hi) {         long long mid = (low + hi) / 2;         if (mid * mid <= all[i].first) {           if (mid > skr) skr = mid;           low = mid + 1;         } else           hi = mid - 1;       }       poss[1] = all[i].first;       poss[2] = skr;       for (int j = 3; j < 62; j++) {         while (poss[j] > 0 && binp(poss[j], j) > all[i].first) poss[j]--;       }       long long out = 0;       for (int j = 1; j < 62; j++) {         out += (poss[j] - 1) * (mu[j] == -1 ? 0 : (mu[j] % 2 == 1 ? -1 : 1));       }       ans[all[i].second] = out;     }     for (int i = 0; i < n; i++) cout << ans[i] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     long long int i;     while (t--) {       string a, b, c;       cin >> a >> b >> c;       long long int n = a.length(), f = 0;       for (i = 0; i < n; i++) {         if (a[i] != c[i] && b[i] != c[i]) {           cout <<  NO n ;           f = 1;           break;         } else if (a[i] == c[i])           swap(b[i], c[i]);         else           swap(a[i], c[i]);       }       if (f != 1) cout <<  YES n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[200005];   int main() {     long long k, sum, subs, di;     int i, n, rel;     cin >> n >> k;     int n1 = n;     for (i = 1; i <= n; i++) cin >> a[i];     i = 1;     sum = 0;     rel = 1;     while (1) {       if (i > n1) break;       subs = (n - rel) * a[i] * (rel - 1);       di = sum - subs;       if (di < k) {         n--;         rel--;         printf( %d n , i);       } else {         sum = sum + a[i] * (rel - 1);       }       i++;       rel++;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 500 + 10;   const int INF = 0x3f3f3f3f;   const int mod = 1000000007;   int n, m;   int a[maxn][maxn], b[maxn][maxn];   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> a[i][j];       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> b[i][j];         a[i][j] ^= b[i][j];       }     }     int flag = 0;     for (int i = 1; i <= n; i++) {       int tm = 0;       for (int j = 1; j <= m; j++) {         tm += a[i][j];       }       if (tm % 2) flag = 1;     }     for (int i = 1; i <= m; i++) {       int tm = 0;       for (int j = 1; j <= n; j++) {         tm += a[j][i];       }       if (tm % 2) flag = 1;     }     if (flag)       cout <<  No n ;     else       cout <<  Yes n ;     return 0;   }


#include <bits/stdc++.h>   long long INF = (long long)1e18;   struct node {     int n;     double rat;   };   bool operator<(const node& n1, const node& n2) { return n1.rat > n2.rat; }   std::vector<int> edge[100010];   int ch[100010], ne[100010];   int main() {     int x, a, b, k, n, m, q, t, num, in = 0, to, i;     double d, s;     scanf( %d%d%d , &n, &m, &q);     for (k = 1; k <= q; k++) {       scanf( %d , &x);       ch[x] = -1;     }     for (k = 1; k <= m; k++) {       scanf( %d%d , &a, &b);       edge[a].push_back(b);       edge[b].push_back(a);     }     double max = -1;     std::priority_queue<node> PQ;     for (k = 1; k <= n; k++) {       if (ch[k] == -1) continue;       t = 0;       for (i = 0; i < edge[k].size(); i++) {         int j = edge[k][i];         if (ch[j] == 0) t++;       }       ne[k] = t;       PQ.push(node{k, (double)t / (double)edge[k].size()});     }     num = n - q;     in = 1;     while (num != 0) {       a = PQ.top().n;       d = PQ.top().rat;       PQ.pop();       if (ch[a] != 0) continue;       ch[a] = in++;       if (d > max) {         max = d;         to = in;       }       num--;       for (i = 0; i < edge[a].size(); i++) {         int j = edge[a][i];         if (ch[j] != 0) continue;         ne[j]--;         s = (double)ne[j] / (double)edge[j].size();         PQ.push(node{j, s});       }     }     int ans = 0;     for (k = 1; k <= n; k++) {       if (ch[k] >= to - 1) ans++;     }     printf( %d n , ans);     for (k = 1; k <= n; k++) {       if (ch[k] >= to - 1) printf( %d  , k);     }   }


#include <bits/stdc++.h>   using namespace std;   long long pw(int x, int y, int z) {     if (y == 0) return 1 % z;     long long a = pw(x, y / 2, z);     if (y % 2 == 0)       return (a * a) % z;     else       return (((a * a) % z) * x % z) % z;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       long long n;       cin >> n;       vector<vector<long long>> arr(n, vector<long long>(2));       for (int i = 0; i < n; ++i) cin >> arr[i][0] >> arr[i][1];       map<long long, long long> l, r;       for (int i = 0; i < n; ++i) {         l[arr[i][0]]++;         r[arr[i][1]]++;       }       sort(arr.begin(), arr.end());       long long ans = (n * (n - 1) * (n - 2)) / 6;       sort(arr.begin(), arr.end());       for (int i = 0; i < n; ++i) {         long long curl = arr[i][0];         long long nos = l[curl];         long long othel = 0;         if (nos >= 2) {           for (int j = i; j < i + nos; ++j) {             othel += (r[arr[j][1]] - 1);           }         }         ans -= ((nos - 1) * othel);         i += nos - 1;       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   struct info {     long long tp, ii, jj, qn, nxt, prv;   } d;   long long cn[1002][1002], n, m;   long long rev[1003], cnt[1003], tot, an[100003];   long long vis[100002];   long long par[100002];   vector<info> v[100005];   long long go(long long nd, long long pr, long long j, long long dec) {     vis[nd] = 1;     long long s, i, r, is, dtot;     info cd;     an[nd] = tot;     dtot = tot;     if (v[nd].size() == 0) {       cd = v[pr][j];       if (cd.tp == 1) {         if (dec) {           cn[cd.ii][cd.jj] = cn[cd.ii][cd.jj] ^ 1LL;           cnt[cd.ii]--;           tot--;         }       } else if (cd.tp == 2) {         if (dec) {           cn[cd.ii][cd.jj] = cn[cd.ii][cd.jj] ^ 1LL;           cnt[cd.ii]++;           tot++;         }       } else if (cd.tp == 3) {         rev[cd.ii]--;         tot -= cnt[cd.ii];         cnt[cd.ii] = m - cnt[cd.ii];         tot += cnt[cd.ii];       }       return 1;     }     for (i = 0; i <= v[nd].size() - 1; i++) {       is = 0;       cd = v[nd][i];       if (cd.tp == 4) {         an[cd.qn] = dtot;         continue;       }       if (cd.tp == 1) {         if (rev[cd.ii] % 2) {           if (cn[cd.ii][cd.jj]) {             cn[cd.ii][cd.jj] = 0;             is = 1;             tot++;             cnt[cd.ii]++;           }         } else {           if (!cn[cd.ii][cd.jj]) {             cn[cd.ii][cd.jj] = 1;             is = 1;             tot++;             cnt[cd.ii]++;           }         }         r = go(cd.qn, nd, i, is);       } else if (cd.tp == 2) {         if (rev[cd.ii] % 2) {           if (!cn[cd.ii][cd.jj]) {             is = 1;             cn[cd.ii][cd.jj] = 1;             cnt[cd.ii]--;             tot--;           }         } else {           if (cn[cd.ii][cd.jj]) {             cn[cd.ii][cd.jj] = 0;             is = 1;             tot--;             cnt[cd.ii]--;           }         }         r = go(cd.qn, nd, i, is);       } else if (cd.tp == 3) {         rev[cd.ii]++;         tot -= cnt[cd.ii];         cnt[cd.ii] = m - cnt[cd.ii];         tot += cnt[cd.ii];         r = go(cd.qn, nd, i, dec);       }     }     if (pr == -1) return 1;     cd = v[pr][j];     if (cd.tp == 1) {       if (dec) {         cn[cd.ii][cd.jj] = cn[cd.ii][cd.jj] ^ 1LL;         cnt[cd.ii]--;         tot--;       }     } else if (cd.tp == 2) {       if (dec) {         cn[cd.ii][cd.jj] = cn[cd.ii][cd.jj] ^ 1LL;         cnt[cd.ii]++;         tot++;       }     } else if (cd.tp == 3) {       rev[cd.ii]--;       tot -= cnt[cd.ii];       cnt[cd.ii] = m - cnt[cd.ii];       tot += cnt[cd.ii];     }     return 1;   }   int main() {     ios_base::sync_with_stdio(0);     long long int i, j, x, cnt = 0, y, k, g, flg, q, cnd;     cin >> n >> m >> q;     cnd = 0;     for (i = 1; i <= q; i++) {       par[i] = -1;     }     for (i = 1; i <= q; i++) {       cin >> k;       d.tp = k;       if (k == 4) {         cin >> y;         cnd = y;         d.nxt = -1;         d.qn = i;         if (par[y] != -1)           cnd = par[i] = par[y];         else           cnd = par[i] = y;         v[cnd].push_back(d);       } else if (k == 1 || k == 2) {         cin >> x >> y;         d.ii = x;         d.jj = y;         d.qn = i;         d.prv = cnd;         v[cnd].push_back(d);         cnd = i;       } else if (k == 3) {         cin >> x;         d.ii = x;         d.qn = i;         d.prv = cnd;         v[cnd].push_back(d);         cnd = i;       }     }     x = go(0, -1, 0, 0);     for (i = 1; i <= q; i++) {       cout << an[i] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<long long int> v, primev;   int prime[2750150];   map<long long int, long long int> mp;   void FindPrime() {     long long int n = 2750140;     for (long long int i = 4; i <= n; i += 2) {       prime[i] = true;     }     prime[1] = true;     for (long long int i = 3; i * i <= n; i += 2) {       if (!prime[i]) {         for (long long int j = 2; i * j <= n; j++) {           prime[i * j] = true;         }       }     }     primev.push_back(2);     prime[2] = 2;     int c = 3;     for (long long int i = 3; i <= n; i = i + 2) {       if (!prime[i]) {         prime[i] = c;         c++;         primev.push_back(i);       }     }   }   long long int divisor(long long int a) {     long long int chk = sqrt(a + 1);     for (long long int i = 0; primev[i] <= chk; i++) {       if (a % primev[i] == 0) {         long long int res = a / primev[i];         return res;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int a, b, c, d, e, i, j, test;     FindPrime();     cin >> a;     for (i = 0; i < a * 2; i++) {       cin >> b;       mp[b]++;       v.push_back(b);     }     sort(v.rbegin(), v.rend());     for (i = 0; i < v.size(); i++) {       if (mp[v[i]] > 0) {         if (prime[v[i]] != 1) {           long long int id = prime[v[i]];           id--;           cout << id <<    ;           mp[id]--;           mp[v[i]]--;         } else {           long long int id = divisor(v[i]);           cout << v[i] <<    ;           mp[id]--;           mp[v[i]]--;         }       }     }     return 0;   }


#include <bits/stdc++.h>   const int N = 1e6;   const int M = 2e5 + 10;   const int mod = 1e9 + 7;   long long n, a[M], cnt[N], cnt2[N], sol[N];   long long brzo_stepenovanje(long long x, long long k) {     if (k == 0) return 1;     if (k == 1) return x;     if (k % 2)       return (x * brzo_stepenovanje((x * x) % mod, k / 2)) % mod;     else       return brzo_stepenovanje((x * x) % mod, k / 2) % mod;   }   int main() {     scanf( %lld , &n);     for (int i = 1; i <= n; i++) cnt[i] = 0, cnt2[i] = 0;     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       cnt2[a[i]]++;     }     for (int i = 2; i <= N; i++)       for (int j = i; j <= N; j += i) {         cnt[i] += cnt2[j];       }     for (int i = 1; i <= N; i++) sol[i] = 0;     for (int i = 2; i <= N; i++)       sol[i] = (cnt[i] * brzo_stepenovanje(2, cnt[i] - 1)) % mod;     for (int i = N / 2; i >= 2; i--)       for (int j = i + i; j <= N; j += i) {         sol[i] -= sol[j];         if (sol[i] < 0) sol[i] += mod;       }     long long ans = 0;     for (int i = 2; i <= N; i++) {       ans += (sol[i] * i) % mod;       ans %= mod;     }     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     string name;     vector<struct node *> sub;   };   typedef struct node *NODE;   class cf56c {    public:     int ans = 0;     void solve(std::istream &in, std::ostream &out) {       string s;       int n;       in >> s;       n = s.length();       stack<struct node *> stk;       int p = 0;       string word;       while (s[p] >=  A  && s[p] <=  Z ) {         word += s[p];         p++;       }       NODE root = new struct node;       root->name = word;       stk.push(root);       while (p < n) {         string t;         NODE latest = stk.top();         if (s[p] ==  ,  || s[p] ==  : ) {           p++;           while (s[p] >=  A  && s[p] <=  Z  && p < n) {             t += s[p];             p++;           }           NODE child = new struct node;           child->name = t;           latest->sub.push_back(child);           stk.push(child);         }         if (s[p] ==  . ) {           stk.pop();           p++;         }       }       unordered_map<string, int> visited;       dfs(root, visited);       out << ans;     }     void dfs(NODE root, unordered_map<string, int> visited) {       string employee = root->name;       vector<NODE> children = root->sub;       ans += visited[employee];       visited[employee]++;       for (auto &i : children) {         dfs(i, visited);       }     }   };   int main() {     ios_base::sync_with_stdio(false);     cf56c solver;     std::istream &in(std::cin);     std::ostream &out(std::cout);     solver.solve(in, out);     return 0;   }


#include <bits/stdc++.h>   int main() {     int a, b, c, d;     scanf( %d%d%d%d , &a, &b, &c, &d);     int ans = 0;     if (a == b) {       ans++;     } else if (b == c) {       ans++;     } else if (b == d) {       ans++;     }     if (a == c) {       ans++;     } else if (c == d) {       ans++;     }     if (a == d) {       ans++;     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Node {     int l, r, x, id;   } a[1000005];   bool operator<(const Node& t1, const Node& t2) {     if (t1.l != t2.l) return t1.l < t2.l;     if (t1.x != t2.x) return t1.x > t2.x;     if (t1.r != t2.r) return t1.l < t2.r;     return t1.x > t2.x;   }   struct Node1 {     Node1(int a, int b, int c) {       r = a;       x = b;       id = c;     }     int r, x, id;   };   bool operator<(const Node1& t1, const Node1& t2) {     if (t1.r != t2.r) return t1.r < t2.r;     return t1.id < t2.id;   }   set<Node1> iset;   int ans[100005];   int main() {     int n, m;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i].l >> a[i].r;       a[i].x = -1;       a[i].id = i;     }     cin >> m;     for (int i = 0; i < m; i++) {       cin >> a[i + n].l >> a[i + n].r >> a[i + n].x;       a[n + i].id = i + 1;     }     sort(a, a + m + n);     for (int i = 0; i < m + n; i++) {       if (a[i].x != -1)         iset.insert(Node1(a[i].r, a[i].x, a[i].id));       else {         set<Node1>::iterator it = iset.lower_bound(Node1(a[i].r, 0, 0));         if (it != iset.end()) {           Node1 t = *it;           iset.erase(it);           ans[a[i].id] = t.id;           t.x--;           if (t.x != 0) iset.insert(t);         } else {           cout <<  NO  << endl;           return 0;         }       }     }     cout <<  YES  << endl;     for (int i = 0; i < n - 1; i++) cout << ans[i] <<    ;     cout << ans[n - 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int ntests;     cin >> ntests;     while (ntests--) {       int n, k, a, b;       cin >> k >> n >> a >> b;       if (k <= 1ll * n * b)         cout << -1 << endl;       else {         long long x = (k - 1ll * n * b - 1) / (a - b);         if (x > n) x = n;         cout << x << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long tree[100002] = {0};   long long findcf(long long ind) {     long long sum = 0;     while (ind > 0) {       sum += tree[ind];       ind -= (ind & (-ind));     }     return sum;   }   void update(long long ind, long long val) {     while (ind <= 100000) {       tree[ind] += val;       ind += (ind & (-ind));     }   }   void incFreqFromTo(long long a, long long b, long long delta) {     update(a, delta);     update(b + 1, -delta);   }   long long getFreqAt(long long index) { return findcf(index); }   int main() {     ios::sync_with_stdio(false);     long long t, i, j, n, m, x;     cin >> n >> m;     for (i = 1; i <= n; ++i) {       cin >> t;       incFreqFromTo(i, i, t);     }     for (i = 0; i < m; ++i) {       cin >> t;       if (t == 1) {         cin >> j >> x;         incFreqFromTo(j, j, x - getFreqAt(j));       } else if (t == 2) {         cin >> x;         incFreqFromTo(1, n, x);       } else {         cin >> j;         cout << getFreqAt(j) <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct LINE {     int start;     int end;   };   int ans = 0;   vector<int> res;   string shift(string s, int p1, int p2) {     char t;     for (int f = p2; f > p1; f--) {       ans++;       res.push_back(f);       t = s[f];       s[f] = s[f - 1];       s[f - 1] = t;     }     return s;   }   int main() {     string s, t;     int a1[27];     int a2[27];     for (int i = 0; i < 27; i++) {       a2[i] = 0;       a1[i] = 0;     }     getline(std::cin, s);     getline(std::cin, s);     getline(std::cin, t);     for (int i = 0; i < s.length(); i++) {       a1[((int)s[i]) - 97]++;     }     for (int i = 0; i < t.length(); i++) {       a2[((int)t[i]) - 97]++;     }     for (int i = 0; i < 27; i++) {       if (a1[i] != a2[i]) {         cout << -1;         return 0;       }     }     for (int i = 0; i < s.length(); i++) {       if (s[i] == t[i]) continue;       int a = s.find(t[i], i);       s = shift(s, i, a);     }     cout << ans <<   n ;     for (int i = 0; i < res.size(); i++) {       cout << res[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i;   char s[100005];   int main() {     scanf( %s , s);     int l = strlen(s);     for (i = 0; i < l; i++) {       if (s[i] == s[l - 1 - i]) continue;       return 0 * printf( NO n );     }     for (i = 0; i < l; i++) {       if (s[i] ==  A  || s[i] ==  H  || s[i] ==  I  || s[i] ==  M  ||           s[i] ==  O  || s[i] ==  T  || s[i] ==  U  || s[i] ==  V  ||           s[i] ==  W  || s[i] ==  X  || s[i] ==  Y )         continue;       return 0 * printf( NO n );     }     printf( YES n );   }


#include <bits/stdc++.h>   using namespace std;   int n;   char in[100005];   int main() {     scanf( %d %s , &n, in);     for (int i = 1; i < n; i++) {       if (in[i] == in[i - 1]) {         for (int j = i;; j++) {           in[j] = 1 - (in[j] -  0 ) +  0 ;           if (in[j + 1] != in[j]) break;         }         break;       }     }     char prv =  2 ;     int cnt = 0;     for (int i = 0; i < n; i++)       if (in[i] != prv) {         prv = in[i];         cnt++;       }     printf( %d , cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7, maxn = 1e6 + 6;   int n, m, k, x, res = 1, fact[maxn];   map<vector<int>, int> f;   vector<int> a[maxn];   int main() {     fact[0] = 1;     for (int i = 1; i < maxn; ++i) fact[i] = 1LL * fact[i - 1] * i % mod;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) {       scanf( %d , &k);       for (int j = 1; j <= k; ++j) {         scanf( %d , &x);         a[x].push_back(i);       }     }     for (int i = 1; i <= m; ++i) sort(a[i].begin(), a[i].end()), ++f[a[i]];     for (map<vector<int>, int>::iterator it = f.begin(); it != f.end(); ++it) {       res = 1LL * res * fact[it->second] % mod;     }     printf( %d , res);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, a[100], b[100], i;     cin >> t;     string s1, s2;     while (t--) {       set<char> track;       string s3 =   , s4;       int flag = 0;       cin >> s1 >> s2;       if (s1.size() > s2.size()) {         cout <<  NO  << endl;         continue;       }       s4 = s1;       sort(s4.begin(), s4.end());       for (i = 0; s1[i]; i++) track.insert(s1[i]);       for (i = 0; i <= s2.size() - s1.size(); i++) {         int cnt = 0, k = i;         s3 =   ;         for (int j = 0; j < s1.size(); j++) {           s3 += s2[k++];         }         sort(s3.begin(), s3.end());         if (s4 == s3) {           cout <<  YES  << endl;           flag = 1;           break;         }       }       if (flag == 0) cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 5, M = 5e5 + 5;   bool vis[N];   int q[N], tot, fa[N];   int n, m, k, head[N], ne[M << 1], to[M << 1], cnt, d[N];   inline int read() {     int x, f = 1;     char ch;     while (!(isdigit(ch = getchar()))) ch ==  -  ? f = -1 : f;     x = ch ^ 48;     while ((isdigit(ch = getchar()))) x = (x << 1) + (x << 3) + (ch ^ 48);     return f * x;   }   inline void ins(int x, int y) {     ne[++cnt] = head[x];     head[x] = cnt;     to[cnt] = y;   }   inline void dfs(int x) {     vis[x] = 1;     if (d[x] >= (n + k - 1) / k) {       puts( PATH );       printf( %d n , d[x]);       while (x) printf( %d  , x), x = fa[x];       exit(0);     }     bool pd = 0;     for (int i = head[x]; i; i = ne[i]) {       if (fa[x] == to[i] || vis[to[i]]) continue;       fa[to[i]] = x;       d[to[i]] = d[x] + 1;       pd = 1;       dfs(to[i]);     }     if (!pd) q[++tot] = x;   }   int main() {     n = read();     m = read();     k = read();     for (int i = 1; i <= m; i++) {       int x = read(), y = read();       ins(x, y);       ins(y, x);     }     d[1] = 1;     dfs(1);     puts( CYCLES );     for (int j = 1; j <= k; j++) {       int x = q[j], y = 0, z = 0;       for (int i = head[x]; i; i = ne[i]) {         if (fa[x] == to[i]) continue;         if (!y)           y = to[i];         else           z = to[i];       }       int res = d[x] - d[y] + 1;       if (res % 3) {         printf( %d n , res);         while (x != y) {           printf( %d  , x);           x = fa[x];         }         printf( %d n , y);         continue;       }       res = d[x] - d[z] + 1;       if (res % 3) {         printf( %d n , res);         while (x != z) {           printf( %d  , x);           x = fa[x];         }         printf( %d n , z);         continue;       }       if (d[y] < d[z]) swap(y, z);       res = d[y] - d[z] + 2;       printf( %d n , res);       while (y != z) {         printf( %d  , y);         y = fa[y];       }       printf( %d %d n , z, x);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 5;   const int INF = 2e9;   const int MOD = 1e9 + 7;   int main() {     vector<int> RES;     string S =   ;     cin >> S;     int N = S.size(), last = -1, depth = 0;     for (int i = 0; i < N; i++) {       if (S[i] ==  ( )         depth++;       else {         if (S[i] ==  # ) last = i;         depth--;       }       if (depth < 0) return printf( -1 ), 0;     }     int val = depth;     depth = 0;     for (int i = 0; i < N; i++) {       if (S[i] ==  ( )         depth++;       else {         int removeIt = (i == last && S[i] ==  #  ? val : 0) + 1;         depth -= removeIt;         if (S[i] ==  # ) RES.push_back(removeIt);       }       if (depth < 0) return printf( -1 ), 0;     }     for (int i = 0; i < RES.size(); i++) printf( %i n , RES[i]);     return 0;   }


#include <bits/stdc++.h>   void swap(long double& a, long double& b) {     long double tmp = a;     a = b, b = tmp;   }   long double solve(long double d, long double r, long double R) {     const long double EPS = 1e-9L;     if (d + EPS >= r + R) return 0;     if (r > R) swap(r, R);     if (R + EPS >= d + r) return acosl(-1.0) * r * r;     long double T = 2 * acosl((R * R + d * d - r * r) / (2 * R * d)),                 t = 2 * acosl((r * r + d * d - R * R) / (2 * r * d));     return .5 * (R * R * (T - sinl(T)) + r * r * (t - sinl(t)));   }   int main() {     long double x1, y1, r1, x2, y2, r2;     scanf( %Lf%Lf%Lf%Lf%Lf%Lf , &x1, &y1, &r1, &x2, &y2, &r2);     long double dx = x1 - x2, dy = y1 - y2;     printf( %.20Lf n , solve(sqrtl(dx * dx + dy * dy), r1, r2));   }


#include <bits/stdc++.h>   using namespace std;   const long long int inf = 1000000000;   const long long int mod = 1000000000 + 7;   inline void IO() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   inline int dcmp(long double x) { return x < -1e-12 ? -1 : (x > 1e-12); }   template <class T>   inline int CHECK(T MASK, int i) {     return (MASK >> i) & 1;   }   template <class T>   inline T ON(T MASK, int i) {     return MASK | (T(1) << i);   }   template <class T>   inline T OFF(T MASK, int i) {     return MASK & (~(T(1) << i));   }   template <typename T>   inline int CNT(T MASK) {     if (numeric_limits<T>::digits <= numeric_limits<unsigned int>::digits)       return __builtin_popcount(MASK);     else       return __builtin_popcountll(MASK);   }   template <class T>   inline int RIGHT(T MASK) {     return log2(MASK & -MASK);   }   int dx4[] = {0, 0, -1, +1};   int dy4[] = {+1, -1, 0, 0};   int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};   int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};   inline void I(int& a) { scanf( %d , &a); }   inline void I(long long int& a) { scanf( %I64d , &a); }   inline void I(unsigned long long int& a) { scanf( %I64u , &a); }   inline void I(char* a) { scanf( %s , a); }   char Iarr[2000010];   inline void I(string& a) {     scanf( %s , Iarr);     a = Iarr;   }   template <typename T, typename... Args>   void I(T& a, Args&... args) {     I(a);     I(args...);   }   inline void OUT(int a) { printf( %d , a); }   inline void OUT(long long int a) { printf( %I64d , a); }   inline void OUT(const char* a) { printf( %s , a); }   inline void OUT(char* a) { printf( %s , a); }   inline void OUT(bool a) { printf( %d , a); }   inline void OUT(string a) {     for (__typeof(a.end()) it = (a.begin()) - ((a.begin()) > (a.end()));          it != (a.end()) - ((a.begin()) > (a.end()));          it += 1 - 2 * ((a.begin()) > (a.end())))       printf( %c , *it);   }   inline void OUT(unsigned long long int a) { printf( %I64u , a); }   template <typename T, typename... Args>   void OUT(T a, Args... args) {     OUT(a);     OUT(   );     OUT(args...);   }   template <typename... Args>   void O(Args... args) {     OUT(args...);     OUT(  n );   }   template <typename T1, typename T2>   inline ostream& operator<<(ostream& os, pair<T1, T2> p) {     os <<  {  << p.first <<  ,   << p.second <<  } ;     return os;   }   template <typename T>   inline ostream& operator<<(ostream& os, vector<T>& a) {     os <<  [ ;     for (int i = 0; i < (int)a.size(); i++) {       if (i) os <<  ,  ;       os << a[i];     }     os <<  ] ;     return os;   }   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cout << *it <<   =   << a << endl;     err(++it, args...);   }   const int M = 100010;   vector<pair<long long int, pair<int, int> > > ans[51];   int n, p;   long double fnl = 0;   void func() {     for (int i = 1; i <= p; i++) {       for (pair<long long int, pair<int, int> > pp : ans[i]) {         long double res = i * pp.first;         int z = 1;         int zz = 1;         int curr = 1;         while (1) {           if (res > 0) {             if (curr != n + 1)               res /= curr++;             else if (z != pp.second.first + 1)               res *= z++;             else if (zz != pp.second.second + 1)               res *= zz++;             else               break;           } else {             if (z != pp.second.first + 1)               res *= z++;             else if (zz != pp.second.second + 1)               res *= zz++;             else if (curr != n + 1)               res /= curr++;             else               break;           }         }         fnl += res;       }     }   }   int main() {     IO();     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     cin >> p;     int sum = 0;     for (int i = 0; i < n; i++) {       sum += a[i];     }     if (sum <= p) {       cout << n << endl;       exit(0);     }     for (int i = 0; i < n; i++) {       vector<int> v;       for (int j = 0; j < n; j++) {         if (j != i) v.push_back(a[j]);       }       long long int dp[51][51][51] = {0};       for (int j = 0; j < n - 1; j++) {         for (int k = 0; k <= j + 1; k++) {           for (int l = 0; l <= 50; l++) {             if (j == 0) {               if (k == 1 && v[j] == l)                 dp[j][k][l] = 1;               else if (k == 0 && l == 0)                 dp[j][k][l] = 1;             } else if (k == 0) {               if (l == 0) dp[j][k][l] = 1;             } else {               dp[j][k][l] = dp[j - 1][k][l];               if (v[j] <= l) dp[j][k][l] += dp[j - 1][k - 1][l - v[j]];             }           }         }       }       for (int l = p - a[i] + 1; l <= p; l++) {         for (int gb = 1; gb <= n; gb++) {           if (l >= 0)             if ((n - 1 - gb) > 0 && (n - 2) >= 0)               ans[gb].push_back(                   make_pair(dp[n - 2][gb][l], make_pair(gb, n - 1 - gb)));             else if ((n - 1 - gb) == 0 && (n - 2) >= 0)               ans[gb].push_back(make_pair(dp[n - 2][gb][l], make_pair(gb, 1)));           int k = (int)ans[gb].size();           if (k != 0) {           }         }       }     }     func();     cout << setprecision(12) << fixed << fnl << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long d, k, tc, tf, tr, res = 100 * 100 * 100 * 100LL;     scanf( %lld , &d);     ;     scanf( %lld , &k);     ;     scanf( %lld , &tc);     ;     scanf( %lld , &tf);     ;     scanf( %lld , &tr);     ;     if (k >= d) return 0 * printf( %lld , d * tc);     if (k * tc + tr >= k * tf) return 0 * printf( %lld , k * tc + (d - k) * tf);     long long chk = d / k;     long long bach_gya = d % k;     printf( %lld , tr * (chk - 1) + tc * chk * k +                        min(bach_gya * tc + tr, bach_gya * tf));   }


#include <bits/stdc++.h>   using namespace std;   int f[100001], d[40], sor[100001];   int n, kq;   bool solve(int a, int b, int &x, int &y) {     if (a % 2 != b % 2) return false;     y = (a + b) / 2;     x = (a - b) / 2;     return true;   }   int main() {     scanf( %d , &n);     kq = -1;     for (int i = 3; i < n + 1; i++) {       memset(d, false, sizeof(d));       for (int j = 2; j * j <= 2 * i; j++)         if ((2 * i) % j == 0) {           int x, y;           if (solve((2 * i) / j, j - 1, x, y)) {             d[sor[y] ^ sor[x - 1]] = true;             if (i == n && sor[y] == sor[x - 1])               if (kq == -1 || j < kq) kq = j;           }         }       for (int j = 0; j < 40; j++)         if (!d[j]) {           f[i] = j;           sor[i] = sor[i - 1] ^ j;           if (i == n && f[i] == 0) kq = -1;           break;         }     }     cout << kq << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   const long long mod = 998244353;   int mp[maxn], a[maxn];   char s[maxn];   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n, x;       scanf( %d , &n);       scanf( %d , &x);       scanf( %s , s + 1);       int mn = 1e9, mx = -1e9;       for (int i = (1); i <= (n); i++) {         if (s[i] ==  0 )           a[i] = a[i - 1] + 1;         else           a[i] = a[i - 1] - 1;         mx = max(mx, a[i]), mn = min(mn, a[i]);       }       for (int i = (0); i <= (mx - mn); i++) mp[i] = 0;       for (int i = (1); i <= (n); i++) mp[a[i] - mn]++;       if (a[n] == 0) {         if (x < mn || x > mx || mp[x - mn] == 0) {           if (x != 0)             puts( 0 );           else             puts( 1 );         } else           puts( -1 );         continue;       }       if (a[n] > 0) {         int l = 0, r = 1e9, pos = -1;         while (l <= r) {           int mid = l + r >> 1;           if (x >= 1ll * mid * a[n] + mn && x <= 1ll * mid * a[n] + mx)             pos = mid, r = mid - 1;           else if (x < 1ll * mid * a[n] + mn)             r = mid - 1;           else             l = mid + 1;         }         long long ans = 0;         if (pos == -1)           ans = 0;         else {           int mpx = -1;           for (int i = pos * a[n] + mn; i <= pos * a[n] + mx; i++) {             if (i <= x)               mpx++;             else               break;           }           for (int i = mpx; i >= 0; i -= a[n]) ans += mp[i];         }         if (x == 0) ans++;         printf( %lld , ans);         puts(  );       } else {         int l = 0, r = 1e9, pos = -1;         while (l <= r) {           int mid = l + r >> 1;           if (x >= 1ll * mid * a[n] + mn && x <= 1ll * mid * a[n] + mx)             pos = mid, r = mid - 1;           else if (x < 1ll * mid * a[n] + mn)             l = mid + 1;           else             r = mid - 1;         }         long long ans = 0;         if (pos == -1)           ans = 0;         else {           int mpx = -1;           for (int i = pos * a[n] + mn; i <= pos * a[n] + mx; i++) {             if (i <= x)               mpx++;             else               break;           }           for (int i = mpx; i <= mx - mn; i += (-a[n])) ans += mp[i];         }         if (x == 0) ans++;         printf( %lld , ans);         puts(  );       }     }   }


#include<bits/stdc++.h>   using namespace std;   typedef pair<int,int> pi;   const int maxn=1e5+7;   double dp[maxn][10];   int pre[maxn][10];   int main()   {       ios::sync_with_stdio(false);       cin.tie(nullptr);       int n,d;       cin>>n>>d;       vector<int> a(n+1);       for(int i=0;i<maxn;i++) for(int j=0;j<10;j++) dp[i][j]=-1e9;       dp[0][1]=0;       for(int i=1;i<=n;i++)       {           cin>>a[i];           double val=log(a[i]);           for(int j=0;j<10;j++)           {               int nxt=j*a[i]%10;               if(dp[i-1][j]>dp[i][j])               {                   dp[i][j]=dp[i-1][j];                   pre[i][j]=j;               }               if(dp[i-1][j]+val>dp[i][nxt])               {                   dp[i][nxt]=dp[i-1][j]+val;                   pre[i][nxt]=j;               }           }       }       if(dp[n][d]<0)       {           cout<<-1<<  n ;           return 0;       }       vector<int> ans;       int cur=d;       for(int i=n;i>=1;i--)       {           int cc=a[i]%10;           if((pre[i][cur]*cc)%10==cur)           {               cur=pre[i][cur];               ans.push_back(a[i]);           }       }       if(ans.size()==0)       {           cout<<-1<<  n ;           return 0;       }       cout<<ans.size()<<  n ;       for(int i=0;i<ans.size();i++) cout<<ans[i]<<   n [i+1==ans.size()];      }


#include <bits/stdc++.h>   using namespace std;   inline char gc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline long long read() {     long long x = 0;     char ch = getchar();     bool positive = 1;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) positive = 0;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return positive ? x : -x;   }   inline void write(long long a) {     if (a < 0) {       a = -a;       putchar( - );     }     if (a >= 10) write(a / 10);     putchar( 0  + a % 10);   }   inline void writeln(long long a) {     write(a);     puts(  );   }   inline void wri(long long a) {     write(a);     putchar(   );   }   inline unsigned long long rnd() {     return ((unsigned long long)rand() << 30 ^ rand()) << 4 | rand() % 4;   }   const int N = 150005;   long double l[N], r[N];   struct data {     long long p, t, id;   } a[N], b[N];   int n;   long long T;   bool cmp(data a, data b) { return a.p < b.p; }   bool cmpt(data a, data b) {     long long A = (long long)a.t * b.p, B = (long long)b.t * a.p;     return A == B ? a.p < b.p : A < B;   }   bool check(long double c) {     long long sum = 0;     for (int i = 1, j; i <= n; i = j) {       j = i + 1;       while (j <= n && a[j].t * a[i].p == a[i].t * a[j].p) j++;       for (int k = (int)(i); k <= (int)(j - 1); k++)         r[a[k].id] = (1 - c * (sum + a[k].t) / T) * a[k].p;       for (int k = (int)(i); k <= (int)(j - 1); k++) sum += a[k].t;       for (int k = (int)(i); k <= (int)(j - 1); k++)         l[a[k].id] = (1 - c * sum / T) * a[k].p;     }     int dq = n;     long double mn = 1e100;     for (int i = (int)(n); i >= (int)(1); i--) {       while (b[dq].p > b[i].p) {         mn = min(mn, l[b[dq--].id]);       }       if (mn <= r[b[i].id]) return 0;     }     return 1;   }   int main() {     n = read();     for (int i = (int)(1); i <= (int)(n); i++) a[a[i].id = i].p = read();     for (int i = (int)(1); i <= (int)(n); i++) T += (a[i].t = read());     for (int i = (int)(1); i <= (int)(n); i++) b[i] = a[i];     sort(a + 1, a + n + 1, cmpt);     sort(b + 1, b + n + 1, cmp);     long double l = 0, r = 1;     for (int i = (int)(1); i <= (int)(80); i++) {       long double mid = (l + r) / 2;       if (check(mid))         l = mid;       else         r = mid;     }     printf( %.10f , (double)l);   }


#include<bits/stdc++.h>   using namespace std;      int check(vector<long long> a) {    for (int i = 0; i + 1 < a.size(); i++) {     if (a[i] > a[i + 1]) {      return 0;     }     a[i + 1] -= a[i];     a[i] = 0;    }    if (a.back() == 0)     return 1;    return 0;   }      void solve() {    int n;    cin >> n;    vector<long long> a(n);    for (int i = 0; i < n; i++) {     cin >> a[i];    }    if (check(a)) {     cout <<  YES n ;     return;    }    if (n == 1) {     cout <<  NO n ;     return;    }    swap(a[0], a[1]);    if (check(a)) {     cout <<  YES n ;     return;    }    swap(a[0], a[1]);    swap(a[n - 2], a[n - 1]);    if (check(a)) {     cout <<  YES n ;     return;    }    swap(a[n - 2], a[n - 1]);    vector<long long> p(n), s(n);    vector<long long> b = a;    p[0] = b[0];    for (int i = 1; i < n; i++) {     if (p[i - 1] == -1 || b[i - 1] > b[i]) {      p[i] = -1;     } else {      b[i] -= b[i - 1];      b[i - 1] = 0;      p[i] = b[i];     }    }    b = a;    s[n - 1] = b[n - 1];    for (int i = n - 2; i >= 0; i--) {     if (s[i + 1] == -1 || b[i + 1] > b[i]) {      s[i] = -1;     } else {      b[i] -= b[i + 1];      b[i + 1] = 0;      s[i] = b[i];     }    }    for (int i = 1; i + 2 < n; i++) {     vector<long long> c = {p[i - 1], a[i], a[i + 1], s[i + 2]};     if (p[i - 1] == -1 || s[i + 2] == -1) {      continue;     }     swap(c[1], c[2]);     if (check(c)) {      cout <<  YES n ;      return;     }    }    cout <<  NO n ;   }      int main() {    ios_base::sync_with_stdio(false);    cin.tie(0);    cout.tie(0);    int t;    cin >> t;    while (t--) {     solve();    }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 7;   set<int> a[N], b[N];   int maxa[N << 2], minb[N << 2];   int badv = 0;   bool bad(int v, int l, int r) {     if (l == r) {       return a[l].size() && b[l].size() && *a[l].rbegin() >= *b[l].begin();     } else {       return maxa[v * 2 + 2] >= minb[v * 2 + 1];     }   }   void relax(int v) {     maxa[v] = max(maxa[v * 2 + 1], maxa[v * 2 + 2]);     minb[v] = min(minb[v * 2 + 1], minb[v * 2 + 2]);   }   void upd_a(int v, int l, int r, int x, int y) {     if (l == r) {       badv -= bad(v, l, r);       if (a[x].find(y) == a[x].end())         a[x].insert(y);       else         a[x].erase(y);       if (a[x].empty())         maxa[v] = -N;       else         maxa[v] = *a[x].rbegin();       badv += bad(v, l, r);       return;     }     badv -= bad(v, l, r);     int m = (l + r) >> 1;     if (x <= m)       upd_a(v * 2 + 1, l, m, x, y);     else       upd_a(v * 2 + 2, m + 1, r, x, y);     relax(v);     badv += bad(v, l, r);   }   void upd_b(int v, int l, int r, int x, int y) {     if (l == r) {       badv -= bad(v, l, r);       if (b[x].find(y) == b[x].end())         b[x].insert(y);       else         b[x].erase(y);       if (b[x].empty())         minb[v] = N;       else         minb[v] = *b[x].begin();       badv += bad(v, l, r);       return;     }     badv -= bad(v, l, r);     int m = (l + r) >> 1;     if (x <= m)       upd_b(v * 2 + 1, l, m, x, y);     else       upd_b(v * 2 + 2, m + 1, r, x, y);     relax(v);     badv += bad(v, l, r);   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     for (int i = 0; i < (N << 2); ++i) {       maxa[i] = -N;       minb[i] = N;     }     int n, m, q;     cin >> n >> m >> q;     while (q--) {       int x, y;       cin >> x >> y;       --x;       --y;       if (x & 1) {         upd_a(0, 0, N, x / 2, y / 2);       } else {         upd_b(0, 0, N, x / 2, y / 2);       }       if (badv == 0)         cout <<  YES  <<   n ;       else         cout <<  NO  <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     cin >> a >> b >> c;     long long ans = 0;     for (int i = 1; i < min(b, c); i++) {       ans += a;       a++;     }     ans *= 2;     for (int i = min(b, c); i <= max(b, c); i++) {       ans += a;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 1e5;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int tc = 1;     for (long long int T = 1; T <= tc; T++) {       long long int n;       cin >> n;       string s;       cin >> s;       long long int cnt = 0, flag = 0;       for (long long int i = 0; i < n - 1; i++) {         if (s[i] == s[i + 1] and s[i] !=  ? ) {           flag = 1;           break;         }       }       if (flag) {         cout <<  No n ;         return 0;       }       if (s[0] ==  ?  or s[n - 1] ==  ? ) {         cout <<  Yes n ;         return 0;       }       long long int tot = 0, ok = 0;       char start =  $ , end =  $ ;       for (long long int i = 0; i < n; i++) {         if (s[i] !=  ?  and flag == 0) {           start = s[i];         } else if (s[i] ==  ? ) {           cnt++;           flag = 1;         } else {           end = s[i];           if (cnt == 1) {             if (start == end) {               ok = 1;               break;             }           } else {             ok = 1;             break;           }           start = end;           cnt = 0;           flag = 0;         }       }       if (ok)         cout <<  Yes n ;       else         cout <<  No n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int bs(vector<int>& a, int que) {     auto it = lower_bound(a.begin(), a.end(), que);     if (*it == que) {       return it - a.begin();     }     return -1;   }   bool isprime(int x) {     if (x == 2) return true;     if (x < 2) return false;     for (int i = 2; i * i <= x; i++)       if (x % i == 0) return false;     if (x == 0) return false;     return true;   }   int main() {     int n;     cin >> n;     int a[10001];     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     vector<int> sol;     sol.push_back(a[n]);     for (int i = n; i >= 2; i--) {       if (a[i] == 1) {         sol.push_back(a[i - 1]);       }     }     reverse(sol.begin(), sol.end());     cout << sol.size() << endl;     for (int i = 0; i <= sol.size() - 1; i++) {       cout << sol[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, k;     cin >> n >> k;     set<long long int> s;     map<long long int, long long int> mp;     long long int x;     for (long long int i = 0; i < n; i++) {       cin >> x;       s.insert(x);       mp[x] = i + 1;     }     if (s.size() < k) {       cout <<  NO  << endl;       return 0;     } else {       cout <<  YES  << endl;       map<long long int, long long int>::iterator it;       long long int c = 0;       for (it = mp.begin(); it != mp.end(); it++) {         if (c != k) {           cout << it->second <<    ;           c++;         } else           break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char a[2000][1000];   int main() {     int n, s;     cin >> n;     int nowx = 0, nowy = 1000;     int miny = 1000, maxy = 1000;     for (int i = 0; i < n; i++) {       cin >> s;       for (int j = nowx; j < nowx + s; j++)         if (i % 2 == 0)           a[nowy][j] =  / , maxy = max(maxy, nowy++);         else           a[--nowy][j] =     , miny = min(miny, nowy);       nowx += s;     }     for (int i = maxy; i >= miny; i--, cout << endl)       for (int j = 0; j < nowx; j++)         if (a[i][j])           cout << a[i][j];         else           cout <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     priority_queue<pair<unsigned long long int, int> > matches;     unsigned long long int n;     int m;     unsigned long long int a;     int b;     unsigned long long int max = 0;     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> a >> b;       pair<int, unsigned long long int> d;       d.first = b;       d.second = a;       matches.push(d);     }     while (matches.size() != 0 && m != 0) {       pair<int, unsigned long long int> d = matches.top();       if (d.second > n) {         max += n * d.first;         n = 0;       } else {         max += d.second * d.first;         n -= d.second;       }       matches.pop();     }     cout << max << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int v[2][1000000 + 10];   void solve(int n, int p) {     if (n == 0) {       v[p][0] = 0;       return;     }     if (!(n & (n + 1))) {       for (int i = 0; i <= n; ++i) {         v[p][i] = n - i;       }     } else {       int two = 1;       while (two * 2 < n + 1) two *= 2;       solve(n - two, p ^ 1);       for (int i = 0; i <= n - two; ++i) {         v[p][i] = two + v[p ^ 1][i];       }       int cur = two;       for (int i = two; i <= n; ++i) {         --cur;         v[p][i] = cur;       }       for (int i = n - two + 1; i < two; ++i) {         --cur;         v[p][i] = cur;       }     }   }   int main() {     cin >> n;     long long s = 0;     for (int i = 0; i <= n; ++i) s += i;     cout << s + s << endl;     solve(n, 0);     for (int i = 0; i <= n; ++i) {       printf( %d  , v[0][i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int n;     scanf( %d , &n);     vector<int> game(n + 1);     game[0] = game[1] = game[2] = 0;     vector<int> res(n + 1, -1);     for (int i = 3; i <= n; i++) {       int ok[300001];       memset(ok, 0, sizeof(0));       for (int j = 2; i - (j * (j - 1)) / 2 >= 0; j++) {         int x = i - ((j) * (j - 1)) / 2;         if (x % j == 0) {           x /= j;           int Xor = 0;           for (int k = 0; k < j; k++) {             Xor ^= game[x + k];           }           ok[Xor] = i;           if (Xor == 0 && res[i] == -1) {             res[i] = j;           }         }       }       int r = 0;       while (ok[r] == i) r++;       game[i] = r;       if (game[i] == 0) res[i] = -1;     }     printf( %d n , res[n]);   }