#include <bits/stdc++.h>   using namespace std;   int sum[501000 << 2], sum2[501000 << 2];   void pushUp(int rt) { sum[rt] = max(sum[rt * 2], sum[rt * 2 + 1]); }   void updata(int l, int r, int rt, int q, int val) {     if (l == q && r == q) {       sum[rt] = val;       return;     }     int m = (l + r) / 2;     if (q <= m) updata(l, m, rt * 2, q, val);     if (q > m) updata(m + 1, r, rt * 2 + 1, q, val);     pushUp(rt);   }   int query(int l, int r, int rt, int ql, int qr) {     if (l > qr || r < ql) return 0;     if (l >= ql && r <= qr) return sum[rt];     int m = (l + r) / 2;     return max(query(l, m, rt * 2, ql, qr), query(m + 1, r, rt * 2 + 1, ql, qr));   }   void build(int l, int r, int rt) {     if (l == r) {       sum[rt] = 0;       return;     }     int m = (l + r) / 2;     build(l, m, rt * 2);     build(m + 1, r, rt * 2 + 1);     pushUp(rt);   }   void pushUp2(int rt) { sum2[rt] = min(sum2[rt * 2], sum2[rt * 2 + 1]); }   void updata2(int l, int r, int rt, int q, int val) {     if (l == q && r == q) {       sum2[rt] = val;       return;     }     int m = (l + r) / 2;     if (q <= m) updata2(l, m, rt * 2, q, val);     if (q > m) updata2(m + 1, r, rt * 2 + 1, q, val);     pushUp2(rt);   }   int query2(int l, int r, int rt, int ql, int qr) {     if (l > qr || r < ql) return 0;     if (l >= ql && r <= qr) return sum2[rt];     int m = (l + r) / 2;     return min(query2(l, m, rt * 2, ql, qr),                query2(m + 1, r, rt * 2 + 1, ql, qr));   }   void build2(int l, int r, int rt) {     if (l == r) {       sum2[rt] = 0;       return;     }     int m = (l + r) / 2;     build2(l, m, rt * 2);     build2(m + 1, r, rt * 2 + 1);     pushUp2(rt);   }   struct edge {     int to;     int next;   } e[501000 << 1];   int box[501000], cnt, tot;   int siz[501000], top[501000], son[501000], dep[501000], fa[501000], w[501000];   int we[501000];   int ww = 0;   void init() {     tot = 0;     son[0] = dep[0] = 0;     memset(box, -1, sizeof(box));     cnt = 0;   }   void add(int from, int to) {     e[cnt].to = to;     e[cnt].next = box[from];     box[from] = cnt++;   }   void dfs(int now, int pre) {     siz[now] = 1;     fa[now] = pre;     son[now] = 0;     dep[now] = dep[pre] + 1;     int t, v;     for (t = box[now]; t + 1; t = e[t].next) {       v = e[t].to;       if (v != pre) {         dfs(v, now);         siz[now] += siz[v];         if (siz[son[now]] < siz[v]) {           son[now] = v;         }       }     }   }   void dfs2(int now, int tp) {     w[now] = ++ww;     top[now] = tp;     if (son[now]) dfs2(son[now], top[now]);     int t, v;     for (t = box[now]; t + 1; t = e[t].next) {       v = e[t].to;       if (v != fa[now] && v != son[now]) dfs2(v, v);     }     we[now] = ww;   }   int n, m;   int solve(int a, int b) {     int ma = 0;     while (top[a] != top[b]) {       if (dep[top[a]] < dep[top[b]]) swap(a, b);       ma = max(ma, query(1, n, 1, w[top[a]], w[a]));       a = fa[top[a]];     }     if (dep[a] > dep[b]) swap(a, b);     ma = max(ma, query(1, n, 1, w[a], w[b]));     return ma;   }   int main() {     scanf( %d , &n);     init();     for (int i = 0; i < n - 1; i++) {       int x, y;       scanf( %d%d , &x, &y);       add(x, y);       add(y, x);     }     build(1, n, 1);     build2(1, n, 1);     dfs(1, 0);     dfs2(1, 1);     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       int q, x;       scanf( %d%d , &q, &x);       if (q == 1) {         updata(1, n, 1, w[x], i);       } else if (q == 2) {         updata2(1, n, 1, w[x], -1 * i);       } else {         int zs = query2(1, n, 1, w[x], we[x]);         int zx = solve(1, x);         if (zx + zs > 0) {           printf( 1 n );         } else           printf( 0 n );       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, n, k, s = 0, m;     vector<pair<int, int> > v(110);     scanf( %d , &n);     scanf( %d , &k);     for (i = 0; i < n; ++i) {       scanf( %d , &v[i].first);       v[i].second = i + 1;     }     sort(v.begin(), v.begin() + n);     for (i = 0; s <= k && i < n; ++i) s = s + v[i].first;     m = i;     if (s > k) --m;     printf( %d n , m);     for (i = 0; i < m; ++i) printf( %d  , v[i].second);   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int v = 0, f = 1;     char c = getchar();     while (c < 48 || 57 < c) {       if (c ==  - ) f = -1;       c = getchar();     }     while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();     return v * f;   }   const int N = 5e5 + 100, INF = 2e9;   int val[N], a[N], b[N], n, m;   set<pair<int, int> > S;   struct node {     node *ch[2], *fa;     int sum, a, maxID, id;     bool rev;     node() {       ch[0] = ch[1] = fa = this;       sum = a = maxID = id = rev = 0;     }     node(int _a, int _id);   };   node *null = new node;   node *pool[N];   node ::node(int _a, int _id) {     ch[0] = ch[1] = fa = null;     sum = _a;     a = _a;     maxID = _id;     id = _id;     rev = 0;   }   bool isRoot(node *u) { return (u->fa->ch[0] != u) && (u->fa->ch[1] != u); }   bool cmp(int x, int y) { return val[x] < val[y]; }   void up(node *u) {     u->sum = u->ch[0]->sum + u->ch[1]->sum + u->a;     int t[3] = {u->ch[0]->maxID, u->ch[1]->maxID, u->id};     sort(t, t + 3, cmp);     u->maxID = t[2];   }   void putRev(node *u) {     if (u == null) return;     swap(u->ch[0], u->ch[1]);     u->rev ^= 1;   }   void dn(node *u) {     if (u->rev) {       putRev(u->ch[0]);       putRev(u->ch[1]);       u->rev = 0;     }   }   void rotate(node *u) {     node *v = u->fa;     bool w = u == v->ch[0];     if (!isRoot(v))       if (v->fa->ch[0] == v)         v->fa->ch[0] = u;       else         v->fa->ch[1] = u;     u->fa = v->fa;     v->ch[!w] = u->ch[w];     u->ch[w]->fa = v;     u->ch[w] = v;     v->fa = u;     up(v);     up(u);   }   void splay(node *u) {     static node *stk[N];     int top = 1;     stk[1] = u;     for (node *i = u; !isRoot(i); i = i->fa) stk[++top] = i->fa;     for (int i = top; i >= 1; i--) dn(stk[i]);     for (node *i; i = u->fa, !isRoot(u); rotate(u))       if (!isRoot(i)) rotate(u == i->ch[0] ^ i == i->fa->ch[0] ? u : i);   }   void access(node *u) {     for (node *t = null; u != null; t = u, u = u->fa) {       splay(u);       u->a -= t->sum;       u->a += u->ch[1]->sum;       u->ch[1] = t;       up(u);     }   }   void makeRoot(node *u) {     access(u);     splay(u);     putRev(u);   }   void link(node *u, node *v) {     makeRoot(v);     access(u);     splay(u);     u->a += v->sum;     u->sum += v->sum;     v->fa = u;   }   void cut(node *u, node *v) {     makeRoot(u);     access(v);     splay(v);     v->ch[0] = null;     up(v);     u->fa = null;   }   node *getRoot(node *u) {     access(u);     splay(u);     while (u->ch[0] != null) u = u->ch[0];     return u;   }   int querySize(node *u) {     access(u);     splay(u);     return u->sum;   }   bool queryOdd(int u) {     cut(pool[n + u], pool[a[u]]);     bool re = querySize(pool[a[u]]) & 1;     link(pool[n + u], pool[a[u]]);     return re;   }   int main() {     n = read(), m = read();     if (n & 1) {       while (m--) puts( -1 );       return 0;     }     for (int i = 1; i <= n; i++) pool[i] = new node(1, 0);     int num = n;     for (int i = 1; i <= m; i++) {       a[i] = read(), b[i] = read(), val[i] = read();       node *u = pool[a[i]], *v = pool[b[i]];       if (getRoot(u) != getRoot(v)) {         int sizU = querySize(u), sizV = querySize(v);         pool[n + i] = new node(0, i);         link(pool[n + i], u);         link(pool[n + i], v);         S.insert(make_pair(-val[i], i));         if ((sizU & 1) && (sizV & 1)) num -= 2;       } else {         makeRoot(u);         access(v);         splay(v);         int t = v->maxID;         if (val[i] < val[t]) {           pool[n + i] = new node(0, i);           S.erase(make_pair(-val[t], t));           cut(pool[n + t], pool[a[t]]);           cut(pool[n + t], pool[b[t]]);           S.insert(make_pair(-val[i], i));           link(pool[n + i], pool[a[i]]);           link(pool[n + i], pool[b[i]]);         }       }       if (num)         puts( -1 );       else {         while (1) {           int t = (*S.begin()).second;           if (!queryOdd(t)) {             cut(pool[n + t], pool[a[t]]);             cut(pool[n + t], pool[b[t]]);             S.erase(S.begin());           } else {             printf( %d n , val[t]);             break;           }         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   string s[110];   int n, d;   int m;   int main() {     cin >> n >> d;     cin >> m;     for (int i = 0; i < m; ++i) {       int x, y;       cin >> x >> y;       bool t = false;       if (!((x - y) <= d && (x - y) >= -d)) t = true;       if (!((x + y) <= n + n - d && (x + y) >= d)) t = true;       if (t == true)         s[i] =  NO ;       else         s[i] =  YES ;     }     for (int i = 0; i < m; i++) cout << s[i] << endl;     return 0;   }


#include <bits/stdc++.h>   const int a = 1 << 18;   using namespace std;   long long odp[a], n, k, res;   vector<int> v[a];   void dfs(int x, int pop) {     for (int i = 0; i < v[x].size(); i++) {       if (v[x][i] != pop)         dfs(v[x][i], x), odp[x] += odp[v[x][i]],             res += min(odp[v[x][i]], k - odp[v[x][i]]);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cin >> n >> k;     k *= 2;     for (int i = 0; i < k; i++) {       int b;       cin >> b;       odp[b] = 1;     }     for (int i = 1; i < n; i++) {       int x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     dfs(1, 1);     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   int b[8];   string str;   int main() {     int n, i;     cin >> n >> str;     for (i = 0; i <= (n - 1); i++) switch (str[i]) {         case  2 :           b[2]++;           break;         case  3 :           b[3]++;           break;         case  4 :           b[2] += 2, b[3]++;           break;         case  5 :           b[5]++;           break;         case  6 :           b[5]++, b[3]++;           break;         case  7 :           b[7]++;           break;         case  8 :           b[7]++, b[2] += 3;           break;         case  9 : {           b[7]++;           b[2]++;           b[3] += 2;         }       }     while (b[7]--) putchar( 7 );     while (b[5]--) putchar( 5 );     while (b[3]--) putchar( 3 );     while (b[2]--) putchar( 2 );     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   #pragma GCC optimize( O2 )   using namespace std;   const int maxn = 1e4 + 123;   int n, k;   int a[maxn];   vector<int> ve[4];   long long sum;   int main(int argc, char const *argv[]) {     std::cin >> n;     for (int i = 0; i < n; i++) {       char s[3];       int val;       std::cin >> s >> val;       int id = 2 * (s[0] -  0 ) + (s[1] -  0 );       ve[id].push_back(val);     }     if (ve[1].size() < ve[2].size()) {       swap(ve[1], ve[2]);     }     for (int i = 0; i <= 3; i++) {       sort(ve[i].begin(), ve[i].end());     }     long long cur = (long long)ve[3].size();     while (ve[3].size() > 0) {       sum += ve[3][(long long)ve[3].size() - 1];       ve[3].pop_back();     }     while (ve[2].size() > 0) {       sum += ve[2][ve[2].size() - 1] + ve[1][(long long)ve[1].size() - 1];       ve[1].pop_back();       ve[2].pop_back();     }     for (int i = 0; i < (int)ve[1].size(); i++) {       ve[0].push_back(ve[1][i]);     }     sort(ve[0].begin(), ve[0].end());     while (cur > 0 && ve[0].size() > 0) {       sum += ve[0][ve[0].size() - 1];       ve[0].pop_back();       cur--;     }     std::cout << sum <<   n ;     return 0;   }


#include <bits/stdc++.h>   const int inf = 0x3f3f3f3f, Inf = 0x7fffffff;   const long long INF = 0x3f3f3f3f3f3f3f3f;   __inline__ __attribute__((always_inline)) unsigned int rnd() {     static unsigned int seed = 416;     return seed ^= seed >> 5, seed ^= seed << 17, seed ^= seed >> 13;   }   template <typename _Tp>   _Tp gcd(const _Tp &a, const _Tp &b) {     return (!b) ? a : gcd(b, a % b);   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) _Tp abs(const _Tp &a) {     return a >= 0 ? a : -a;   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) _Tp max(const _Tp &a, const _Tp &b) {     return a < b ? b : a;   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) _Tp min(const _Tp &a, const _Tp &b) {     return a < b ? a : b;   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) void chmax(_Tp &a, const _Tp &b) {     (a < b) && (a = b);   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) void chmin(_Tp &a, const _Tp &b) {     (b < a) && (a = b);   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) void read(_Tp &x) {     char ch(getchar());     bool f(false);     while (ch < 48 || ch > 57) f |= ch == 45, ch = getchar();     x = ch & 15, ch = getchar();     while (ch >= 48 && ch <= 57)       x = (((x << 2) + x) << 1) + (ch & 15), ch = getchar();     if (f) x = -x;   }   template <typename _Tp, typename... Args>   __inline__ __attribute__((always_inline)) void read(_Tp &t, Args &...args) {     read(t);     read(args...);   }   template <typename _Tp, typename... Args>   __inline__ __attribute__((always_inline)) _Tp min(const _Tp &a, const _Tp &b,                                                     const Args &...args) {     return a < b ? min(a, args...) : min(b, args...);   }   template <typename _Tp, typename... Args>   __inline__ __attribute__((always_inline)) _Tp max(const _Tp &a, const _Tp &b,                                                     const Args &...args) {     return a < b ? max(b, args...) : max(a, args...);   }   __inline__ __attribute__((always_inline)) int read_str(char *s) {     char ch(getchar());     while (ch ==     || ch ==   r  || ch ==   n ) ch = getchar();     char *tar = s;     *tar = ch, ch = getchar();     while (ch !=     && ch !=   r  && ch !=   n  && ch != EOF)       *(++tar) = ch, ch = getchar();     return tar - s + 1;   }   const int N = 4000005;   const int mod = 998244353;   template <typename _Tp1, typename _Tp2>   __inline__ __attribute__((always_inline)) void add(_Tp1 &a, _Tp2 b) {     (a += b) >= mod && (a -= mod);   }   template <typename _Tp1, typename _Tp2>   __inline__ __attribute__((always_inline)) void sub(_Tp1 &a, _Tp2 b) {     (a -= b) < 0 && (a += mod);   }   long long ksm(long long a, long long b = mod - 2) {     long long res = 1;     while (b) {       if (b & 1) res = res * a % mod;       a = a * a % mod, b >>= 1;     }     return res;   }   long long fac[N], inv[N], ifac[N];   void init() {     fac[0] = fac[1] = inv[0] = inv[1] = ifac[0] = ifac[1] = 1;     for (int i = 2; i < N; ++i) {       fac[i] = fac[i - 1] * i % mod;       inv[i] = inv[mod % i] * (mod - mod / i) % mod;       ifac[i] = ifac[i - 1] * inv[i] % mod;     }   }   __inline__ __attribute__((always_inline)) long long C(int n, int m) {     if (n < m) return 0;     return fac[n] * ifac[m] % mod * ifac[n - m] % mod;   }   long long f[N];   long long s1[N], s2[N], s3[N];   int main() {     init();     long long n, m;     read(n, m);     for (int i = 0; i <= n; ++i) {       if (i) s1[i] = s1[i - 1];       add(s1[i], fac[m + i - 1] * ifac[i] % mod);       if (i) s2[i] = s2[i - 1], add(s2[i], fac[m + i - 1] * ifac[i - 1] % mod);       long long _ = m * fac[i] % mod * fac[n - i] % mod * ifac[n + m] % mod;       long long tmp = _ * C(n + m + 1, m + i + 1) % mod *                       (s1[i] * (i + 1) % mod - s2[i] + mod) % mod;       long long coef =           (mod + 1 -            _ * C(n + m, m + i) % mod * ifac[i] % mod * fac[m + i - 1] % mod);       f[i] = (tmp + _ * C(n + m, m + i) % mod * s3[i] % mod) * ksm(coef) % mod;       s3[i + 1] = s3[i],              add(s3[i + 1], fac[m + i - 1] * ifac[i] % mod * f[i] % mod);     }     printf( %lld n , f[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   vector<pair<pair<int, int>, pair<int, int> > > a[300005];   vector<int> g1[300005];   vector<int> g2[300005];   string Max =   , Min =   ;   int ansMax = 0;   int ansMin = 0;   bool used[300005];   void getMax(int cur) {     ansMax++;     used[cur]++;     for (auto it : g1[cur]) {       if (!used[it]) {         getMax(it);       }     }   }   void getMin(int cur) {     ansMin++;     used[cur]++;     for (auto it : g2[cur]) {       if (!used[it]) {         getMin(it);       }     }   }   void updateMax(int s) {     queue<int> q;     q.push(s);     while (!q.empty()) {       int u = q.front();       q.pop();       if (used[u]) {         continue;       }       used[u]++;       for (auto it : a[u]) {         if (it.first.first == 1) {           if (!used[it.second.second]) {             q.push(it.second.second);             g1[u].push_back(it.second.second);           }         } else {           if (u == it.second.first) {             if (!used[it.second.second]) {               q.push(it.second.second);               g1[u].push_back(it.second.second);             }           } else {             if (!used[it.second.first]) {               q.push(it.second.first);               g1[u].push_back(it.second.first);               Max[it.first.second] =  - ;             }           }         }       }     }   }   void updateMin(int s) {     queue<int> q;     q.push(s);     while (!q.empty()) {       int u = q.front();       q.pop();       if (used[u]) {         continue;       }       used[u]++;       for (auto it : a[u]) {         if (it.first.first == 2) {           if (u == it.second.first) {             if (!used[it.second.second]) {               Min[it.first.second] =  - ;             }           }         }       }       for (auto it : a[u]) {         if (it.first.first == 1 && !used[it.second.second]) {           g2[u].push_back(it.second.second);           q.push(it.second.second);         }       }     }   }   int main() {     int n, m, s;     scanf( %d%d%d , &n, &m, &s);     int i, t, u, v;     int d = 0;     for (i = 0; i < m; i++) {       scanf( %d%d%d , &t, &u, &v);       if (t == 1) {         a[u].push_back({{t, i}, {u, v}});       } else {         a[u].push_back({{t, d}, {u, v}});         a[v].push_back({{t, d}, {u, v}});         d++;         Max +=  + ;         Min +=  + ;       }     }     updateMax(s);     memset(used, 0, sizeof used);     getMax(s);     printf( %d n , ansMax);     cout << Max << endl;     memset(used, 0, sizeof used);     updateMin(s);     memset(used, 0, sizeof used);     getMin(s);     printf( %d n , ansMin);     cout << Min;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 110000;   int t[4 * maxN], m;   int get(int k) {     int res = 0;     for (int i = k; i >= 0; i = (i & (i + 1)) - 1) {       res = max(res, t[i]);     }     return res;   }   void update(int k, int delta) {     for (int i = k; i <= m; i |= (i + 1)) {       t[i] = max(t[i], delta);     }   }   int calculate(vector<pair<int, int> > borders) {     pair<int, int> start = borders[0];     sort(borders.rbegin(), borders.rend());     for (int i = 0; i < borders.size(); ++i) {       int current = get(borders[i].second - 1);       update(borders[i].second, current + 1);       if (borders[i] == start) {         return current;       }     }   }   int a, b, c, d, n;   struct rational {     long long x, y;     rational(long long x, long long y) : x(x), y(y) {}     rational() : x(0), y(1) {}     bool operator<(const rational &other) const {       return x * other.y < other.x * y;     }   };   vector<pair<int, int> > compress(vector<rational> a, vector<rational> b) {     set<rational> S;     for (int i = 0; i < a.size(); ++i) {       S.insert(a[i]);       S.insert(b[i]);     }     map<rational, int> M;     m = 0;     for (set<rational>::iterator it = S.begin(); it != S.end(); ++it) {       M[*it] = ++m;     }     vector<pair<int, int> > borders;     for (int i = 0; i < a.size(); ++i) {       borders.push_back(make_pair(M[a[i]], M[b[i]]));     }     return borders;   }   int main() {     scanf( %d , &n);     scanf( %d/%d%d/%d , &a, &b, &c, &d);     vector<rational> u, v;     for (int i = 0; i <= n; ++i) {       long long x, y;       if (i == 0) {         x = y = 0;       } else {         cin >> x >> y;       }       u.push_back(rational(1000000LL * a + y * b - x * a, a + b));       v.push_back(rational(1000000LL * c + y * d - x * c, c + d));     }     printf( %d n , calculate(compress(u, v)));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int in() {     int x, y;     y = scanf( %d , &x);     return x;   }   const int N = 300003;   int n, m, k;   vector<int> g[N], gr[N];   int to[N], from[N], mark[N], res[N], din[N], rem;   int x[N], r[N], y[N];   void out() {     cout <<  -1 n ;     exit(0);   }   void dfs(int v) {     mark[v] = 1;     for (int u : g[v])       if (mark[u] == 1)         out();       else {         if (!mark[u]) dfs(u);         from[v] = max(from[v], from[u]);       }     from[v]++;     if (r[v] > 0) {       if (from[v] > r[v]) out();       from[v] = r[v];     }     if (from[v] > k) out();     mark[v] = 2;   }   bool seen[N];   set<pair<int, int>> ss, qs;   void updateRem() {     while (rem > 0 && seen[rem]) {       rem--;       while (qs.size() && qs.rbegin()->first >= rem) {         int v = qs.rbegin()->second;         qs.erase({to[v], v});         ss.insert({from[v], v});       }     }   }   void addSource(int v) {     int x = to[v];     if (x >= rem)       ss.insert({from[v], v});     else       qs.insert({x, v});   }   int main() {     cin >> n >> m >> k;     for (int i = 0; i < n; i++) r[i] = in();     for (int i = 0; i < m; i++) {       x[i] = in() - 1;       y[i] = in() - 1;       g[x[i]].push_back(y[i]);       gr[y[i]].push_back(x[i]);       din[y[i]]++;     }     for (int i = 0; i < n; i++)       if (!mark[i]) dfs(i);     rem = k;     fill(to, to + n, k);     for (int i = 0; i < n; i++) {       if (r[i] > 0) to[i] = min(to[i], r[i]);       if (!din[i]) addSource(i);     }     for (int i = 0; i < n; i++) {       if (ss.empty()) out();       int v = ss.rbegin()->second;       ss.erase({from[v], v});       assert(to[v] >= rem);       if (r[v] > 0)         res[v] = r[v];       else         res[v] = max(rem, from[v]);       seen[res[v]] = true;       updateRem();       for (int u : g[v]) {         din[u]--;         to[u] = min(to[u], res[v] - 1);         if (to[u] < from[u]) out();         if (din[u] == 0) addSource(u);       }     }     if (rem != 0) out();     for (int i = 0; i < m; i++)       if (res[x[i]] <= res[y[i]]) out();     for (int i = 0; i < n; i++) cout << res[i] <<    ;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 4e5 + 5;   pair<long long, long long> arr[N];   long long l[N];   long long s[N];   long long dp[N];   long long bit[N];   long long n;   void update(long long idx, long long val) {     while (idx <= n) {       bit[idx] = max(bit[idx], val);       idx += idx & -idx;     }   }   long long query(long long idx) {     long long res = 0;     while (idx) {       res = max(res, bit[idx]);       idx -= idx & -idx;     }     return res;   }   int main() {     scanf( %lld , &n);     for (long long i = 1; i <= n; i++) {       long long r, h;       scanf( %lld%lld , &r, &h);       arr[i] = pair<long long, long long>(r * r * h, -i);     }     sort(arr + 1, arr + n + 1);     for (long long i = 1; i <= n; i++) {       dp[i] = max(arr[i].first, query(-arr[i].second) + arr[i].first);       update(-arr[i].second, dp[i]);     }     printf( %.7lf n , 3.14159265358979323846 * query(n));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt[100001];   int main() {     int n, k;     cin >> n;     int ans = 1;     int m = n;     while (n--) {       cin >> k;       cnt[k] = cnt[k - 1] + 1;       ans = max(ans, cnt[k]);     }     cout << m - ans;   }


#include <bits/stdc++.h>   char year[10];   int main() {     scanf( %s , year);     int l = strlen(year) - 1;     int num = 0, num2 = 0;     for (int i = 0; i <= l; i++) {       num = num * 10 + year[i] -  0 ;     }     for (int i = 1; i <= l; i++) num2 = num2 * 10 + year[i] -  0 ;     int x = 1;     for (int i = 1; i <= l; i++) x *= 10;     printf( %d n , x - num2);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<tuple<int, int, int, int> > v(n);     vector<int> used(n, 0);     for (int i = 0; i < n; i++) {       int a, b, c;       cin >> a >> b >> c;       v[i] = make_tuple(a, b, c, i);     }     sort(v.begin(), v.end());     map<pair<int, int>, vector<int> > m;     for (int i = 0; i < n; i++) {       pair<int, int> t = {get<0>(v[i]), get<1>(v[i])};       if (m.find(t) == m.end()) m[t] = vector<int>();       m[t].push_back(i);     }     for (auto t : m) {       for (int i = 0; i + 1 < t.second.size(); i += 2) {         cout << get<3>(v[t.second[i]]) + 1 <<                  << get<3>(v[t.second[i + 1]]) + 1 <<   n ;         used[get<3>(v[t.second[i]])] = 1;         used[get<3>(v[t.second[i + 1]])] = 1;       }     }     vector<tuple<int, int, int, int> > v1;     for (int i = 0; i < v.size(); i++) {       if (used[get<3>(v[i])] == 0) v1.push_back(v[i]);     }     map<int, vector<int> > m1;     for (int i = 0; i < v1.size(); i++) {       if (m1.find(get<0>(v1[i])) == m1.end()) {         m1[get<0>(v1[i])] = vector<int>();       }       m1[get<0>(v1[i])].push_back(i);     }     for (auto t : m1) {       for (int i = 0; i + 1 < t.second.size(); i += 2) {         cout << get<3>(v1[t.second[i]]) + 1 <<                  << get<3>(v1[t.second[i + 1]]) + 1 <<   n ;         used[get<3>(v1[t.second[i]])] = 1;         used[get<3>(v1[t.second[i + 1]])] = 1;       }     }     vector<tuple<int, int, int, int> > v2;     for (int i = 0; i < v1.size(); i++) {       if (used[get<3>(v1[i])] == 0) {         v2.push_back(v1[i]);       }     }     for (int i = 0; i < v2.size(); i += 2) {       cout << get<3>(v2[i]) + 1 <<     << get<3>(v2[i + 1]) + 1 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int a = 26;   char c[10000], ans[10000];   int p[10000], ap[10000], perm[10000];   map<int, int> m;   int main() {     string s, st;     cin >> s;     int n = s.size(), x, t, last, y;     x = 17576;     for (int i = 0; i < 3; i++) {       x /= a;       t = 0;       last = -1;       cout <<  ?  ;       for (int j = 0; j < n; j++) {         if (j % x == 0 || last != c[j]) {           t = (t + 1) % a;         }         last = c[j];         c[j] = char(t +  a );         cout << c[j];       }       cout << endl;       cin >> st;       for (int j = 0; j < n; j++) {         y = st[j] -  a ;         p[j] = p[j] * a + y;         ap[j] = ap[j] * a + (c[j] -  a );       }     }     cout <<  !  ;     for (int i = 0; i < n; i++) m[ap[i]] = i;     for (int i = 0; i < n; i++) perm[i] = m[p[i]];     for (int i = 0; i < n; i++) ans[perm[i]] = s[i];     for (int i = 0; i < n; i++) cout << ans[i];     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int lim = 500000001;   class TMain {    private:     int n, m, f[505][505], dis[505][505], ans[505][505], now[505];       public:     int run() {       scanf( %d %d , &n, &m);       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++)           if (i == j)             f[i][j] = dis[i][j] = 0;           else             f[i][j] = dis[i][j] = lim;       for (int i = 1; i <= m; i++) {         int a, b, c;         scanf( %d %d %d , &a, &b, &c);         dis[a][b] = dis[b][a] = f[a][b] = f[b][a] = min(f[a][b], c);       }       for (int k = 1; k <= n; k++)         for (int i = 1; i <= n; i++)           for (int j = 1; j <= n; j++) f[i][j] = min(f[i][j], f[i][k] + f[k][j]);       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) now[j] = 0;         for (int j = 1; j <= n; j++)           for (int k = 1; k <= n; k++)             if (j != k && f[i][j] + dis[j][k] == f[i][k]) now[k]++;         for (int j = 1; j <= n; j++)           for (int k = 1; k <= n; k++)             if (f[i][j] + f[j][k] == f[i][k]) ans[i][k] += now[j];       }       for (int i = 1; i < n; i++)         for (int j = i + 1; j <= n; j++)           if (f[i][j] == lim)             printf( 0  );           else             printf( %d  , ans[i][j]);       printf(  n );       return 0;     }   } Main;   int main() { return Main.run(); }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long k, n, s, p;     cin >> k >> n >> s >> p;     long long w = n / s;     if (n % s != 0) w++;     w *= k;     long long ans = w / p;     if (w % p != 0) ans++;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)5e5 + 50;   int n;   int ans[N];   vector<int> G[N];   int q[N];   int dep[N];   vector<pair<int, int> > hist[N];   void upd(int u, int val) { q[u] = max(q[u], val); }   void calc(int v, int p) {     dep[v] = 0;     for (int nxt : G[v]) {       if (nxt == p) continue;       calc(nxt, v);       dep[v] = max(dep[nxt] + 1, dep[v]);     }   }   void merge(vector<pair<int, int> > h1, vector<pair<int, int> > h2) {     int r = 0;     for (int i = 0; i < h1.size(); i++) {       while (r < h2.size() && (h2[r].first >= h1[i].first)) {         r++;       }       if (r - 1 >= 0 && h2[r - 1].second > 1)         upd(2 * h1[i].first, h2[r - 1].second + h1[i].second - 2);     }   }   void dfs(int v, int p = -1, int up_dep = -1) {     vector<int> deps;     if (up_dep != -1) deps.push_back(up_dep + 1);     for (int nxt : G[v]) {       if (nxt != p) deps.push_back(dep[nxt] + 1);     }     sort(deps.begin(), deps.end(),          [](const int a, const int b) { return a > b; });     for (int i = 0; i < deps.size(); i++) {       upd(2 * deps[i], i + 1);       upd(2 * deps[i] - 1, i + 1);       if (i > 0 && deps[i - 1] > deps[i]) upd(2 * deps[i] + 1, i + 1);     }     for (int i = 0; i < deps.size(); i++) {       if (hist[v].empty() || hist[v].back().first != deps[i])         hist[v].push_back({deps[i], 1});       else         hist[v].back().second++;     }     for (int i = 1; i < hist[v].size(); i++)       hist[v][i].second += hist[v][i - 1].second;     for (int nxt : G[v]) {       if (nxt == p) continue;       dfs(nxt, v,           (deps.size() == 1 ? 0 : (deps[0] == dep[nxt] + 1 ? deps[1] : deps[0])));       merge(hist[nxt], hist[v]);       merge(hist[v], hist[nxt]);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       a--, b--;       G[a].push_back(b);       G[b].push_back(a);     }     for (int i = 0; i < n; i++) {       ans[1] = max(ans[1], (int)G[i].size() + 1);     }     calc(0, -1);     dfs(0);     int rmax = 0;     for (int i = (n - 1) / 2 * 2 + 1; i >= 2; i -= 2) {       rmax = max(rmax, q[i]);       ans[i] = rmax;     }     rmax = 0;     for (int i = n / 2 * 2; i >= 2; i -= 2) {       rmax = max(rmax, q[i]);       ans[i] = rmax;     }     for (int i = 1; i <= n; i++) cout << max(ans[i], 1) <<    ;   }


#include <cstdio>   #include <iostream>      #define ll long long      using namespace std;      int n , m , cnt = 0;      const int N = 5e5 + 5;   const int mod = 1e9 + 7;      ll pow2[N];      int num[N] , fa[N];      int find(int x){    if(fa[x] == x)     return x;    return fa[x] = find(fa[x]);   }      int main(){    pow2[0] = 1;    cin >> n >> m;    for(int i = 1; i < N; i++)     pow2[i] = 1ll * 2 * pow2[i - 1] % mod;    for(int i = 1; i <= m + 1; i++)     fa[i] = i;    for(int i = 1; i <= n; i++){     int k;     int x , y;     scanf( %d  , &k);     if(k == 1){      scanf( %d  , &x);      y = m + 1;     }     else      scanf( %d%d  , &x , &y);     int fx , fy;     fx = find(x);     fy = find(y);     if(fx == fy)      continue;     fa[fx] = fy;     num[++cnt] = i;    }    ll ans = pow2[cnt] % mod;    cout << ans <<     << cnt << endl;    for(int i = 1; i <= cnt; i++)     printf( %d   , num[i]);    return 0;   }


#include <bits/stdc++.h>   using namespace std;   unordered_map<long long, int> mpSt;   unordered_map<long long, int> mpEnd;   set<long long> AllPoints;   long long K[200005];   int main() {     int N;     scanf( %d , &N);     for (int i = 0; i < N; i++) {       long long st, end;       scanf(  %lld %lld , &st, &end);       AllPoints.insert(st);       AllPoints.insert(end);       if (mpSt.count(st) > 0)         mpSt[st]++;       else         mpSt[st] = 1;       if (mpEnd.count(end) > 0)         mpEnd[end]++;       else         mpEnd[end] = 1;     }     if (N == 1) {       if (AllPoints.size() == 1) {         printf( 1 );       } else {         long long seg = *next(AllPoints.begin()) - *AllPoints.begin() + 1;         printf( %lld , seg);       }       return 0;     }     auto nextIt = next(AllPoints.begin());     long long cumulative = 0;     for (auto it = AllPoints.begin(); nextIt != AllPoints.end(); it++) {       long long cur = *it;       long long nxt = *nextIt;       cumulative += mpSt[cur];       K[cumulative] += 1;       cumulative -= mpEnd[cur];       long long middle = nxt - cur - 1;       K[cumulative] += middle;       nextIt = next(nextIt);     }     cumulative += mpSt[*prev(AllPoints.end())];     K[cumulative]++;     for (int i = 1; i <= N; i++) {       printf( %lld  , K[i]);     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, temp, count, i, len, len1, j;     char c, a[200], b[40];     strcpy(b,  qwertyuiopasdfghjkl;zxcvbnm,./ );     while (~scanf( %c , &c)) {       getchar();       gets(a);       len = strlen(a);       len1 = strlen(b);       if (c ==  R )         temp = -1;       else         temp = 1;       for (i = 0; i < len; i++) {         for (j = 0; j < len1; j++) {           if (a[i] == b[j]) printf( %c , b[j + temp]);         }       }       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j, x = 0;     char c[30][30] = {0};     scanf( %d n , &n);     for (i = 1; i <= n; i++) {       char temp[605] =   ;       cin.getline(temp, 605);       int length = strlen(temp);       for (j = 0; j < length; j++) {         c[0][temp[j] - 96] = 1;         if (j != length - 1) c[temp[j] - 96][temp[j + 1] - 96] = 1;       }     }     for (i = 0; i <= 26; i++) {       for (j = 1; j <= 26; j++) {         if (c[i][j] == 0 && i == 0) {           printf( %c n , j + 96);           x = 1;         } else if (c[i][j] == 0) {           printf( %c%c n , i + 96, j + 96);           x = 1;         }         if (x == 1) return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     t = 1;     while (t--) {       double n;       cin >> n;       double a[200001], sum = 0;       set<double> s;       for (int i = 0; i < n; i++) {         cin >> a[i];         sum += a[i];       }       for (int i = 0; i < n; i++) {         double z = sum - a[i];         double y = (z / (n - 1));         if (y == a[i]) s.insert(i + 1);       }       cout << s.size() << endl;       for (auto i : s) cout << i <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   namespace myland {   using namespace std;   namespace _abbr {}   using namespace _abbr;   namespace _constant {   const double EPS(1e-8);   const double PI(acos(-1.0));   const int INF(0x3f3f3f3f);   const long long INFL(0x3f3f3f3f3f3f3f3fll);   const int MOD(1e9 + 7);   const int dx[] = {-1, 0, 1, 0, -1, 1, 1, -1},             dy[] = {0, 1, 0, -1, 1, 1, -1, -1};   }  // namespace _constant   using namespace _constant;   namespace _solve {}   using namespace _solve;   namespace _calculate {   bool odd(long long x) { return x & 1; }   bool even(long long x) { return (x & 1) ^ 1; }   bool posi(long long x) { return x > 0; }   bool nega(long long x) { return x < 0; }   bool zero(long long x) { return x == 0; }   bool prime(long long x) {     if (x < 2) return 0;     for (int i = 2; i * i <= x; i++)       if (x % i == 0) return 0;     return 1;   }   long long droot(long long x) { return 1 + (x - 1) % 9; }   long long upd(long long a, long long b) { return a % b ? a / b + 1 : a / b; };   long long random(long long a, long long b) {     return a + rand() * rand() % (b - a + 1);   };   long long bitn(long long x) {     long long c = 0;     while (x) c++, x >>= 1;     return c;   }   template <class T>   T sqr(T x) {     return x * x;   }   long long qpow(long long a, long long n, long long mod = MOD) {     long long res(1);     while (n) {       if (n & 1) (res *= a) %= mod;       (a *= a) %= mod;       n >>= 1;     }     return res % mod;   }   long long inv(long long a, long long mod = MOD) { return qpow(a, mod - 2); }   template <class T>   void tomin(T& a, T b) {     if (b < a) a = b;   }   template <class T>   void tomax(T& a, T b) {     if (b > a) a = b;   }   }  // namespace _calculate   using namespace _calculate;   namespace _simple_algo {   long long sol(const string& s) {     long long x = 0;     for (char c : s) x = x * 10 + c - 48;     return x;   }   string los(long long x) {     string s =   ;     if (x == 0) return  0 ;     while (x) s = char(x % 10 + 48) + s, x /= 10;     return s;   }   bool pal(const string& s) {     int l = s.size();     for (int i = 0, j = l - 1; i < j; i++, j--)       if (s[i] != s[j]) return 0;     return 1;   }   }  // namespace _simple_algo   using namespace _simple_algo;   namespace _io {   template <class T>   void rd(T& x) {     cin >> x;   }   string srd() {     string s;     cin >> s;     return s;   }   long long rd() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   void rd(int& x) { x = rd(); }   void rd(long long& x) { x = rd(); }   template <class A, class B>   void rd(pair<A, B>& p) {     cin >> p.first >> p.second;   }   template <class A, class B>   void rd(A& a, B& b) {     rd(a), rd(b);   }   template <class A, class B, class C>   void rd(A& a, B& b, C& c) {     rd(a, b);     rd(c);   }   template <class T>   void wt(const T& x) {     cout << x << endl;   }   template <class T>   void wt(const T& x, char c) {     cout << x << c;   }   template <class T>   void wt(const T& x, const string& s) {     cout << x << s;   }   template <class T>   void wt(const T& x, int rnd) {     cout << fixed << setprecision(rnd) << x << endl;   }   template <class T>   void wt(const vector<T>& v) {     for (T x : v) wt(x,    );     wt(  );   }   template <class A, class B>   void wt(const pair<A, B>& make_pair) {     cout << make_pair.first <<     << make_pair.second << endl;   }   }  // namespace _io   using namespace _io;   }  // namespace myland   using namespace myland;   int n(rd()), m(rd()), r(rd());   int s[50], b[50];   int main() {     for (int i = 1; i <= n; i++) rd(s[i]);     for (int i = 1; i <= m; i++) rd(b[i]);     sort((s + 1), (s + n + 1));     sort((b + 1), (b + m + 1));     int t = r / s[1];     if (s[1] < b[m]) {       r -= t * s[1];       r += t * b[m];     }     wt(r);   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-6;   const int N = 101;   const int INF = 0x3f3f3f3f;   const int mod = 1000000007;   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   int a[N], maxf, ans;   int d[N];   bool mul;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int k, f;       cin >> k >> f;       a[k] = f;       maxf = max(maxf, f);     }     int now = 1;     for (; now <= 100; now++) {       int line = 1;       bool ok = 1;       for (int i = 1; i <= 100; i++) {         if (a[i] && a[i] != line) {           ok = 0;           break;         }         if (i == n && ans && d[n] != line) {           mul = 1;         }         if (i % now == 0) {           line++;         }       }       if (mul && ok) {         ans = -1;         break;       }       if (ok) {         line = 1;         for (int i = 1; i <= 100; i++) {           d[i] = line;           if (i % now == 0) {             line++;           }         }         ans = d[n];       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxl = 60, w = 10000;   struct Big {     int s[maxl], l;     Big() {       memset(s, 0, sizeof(s));       l = 1;     }     inline void fix() {       for (int i = 1; i < l; i++) {         if (s[i] >= w) {           s[i + 1] += s[i] / w;           s[i] %= w;         }       }       while (s[l] >= w) {         s[l + 1] += s[l] / w;         s[l] %= w;         l++;       }     }     void fuzhi(int x) {       s[1] = x;       l = 1;       fix();     }     inline void out() {       if (s[l] >= 1000) cout << s[l] / 1000 % 10;       if (s[l] >= 100) cout << s[l] / 100 % 10;       if (s[l] >= 10) cout << s[l] / 10 % 10;       cout << s[l] % 10;       for (int i = l - 1; i >= 1; i--) {         if (s[i] < 1000) cout << 0;         if (s[i] < 100) cout << 0;         if (s[i] < 10) cout << 0;         cout << s[i];       }       cout << endl;     }   };   inline Big operator*(const Big &x, const Big &y) {     Big ans;     ans.l = x.l + y.l - 1;     for (int i = 1; i <= x.l; i++) {       for (int j = 1; j <= y.l; j++) ans.s[i + j - 1] += x.s[i] * y.s[j];     }     ans.fix();     return ans;   }   inline bool operator<(const Big &x, const Big &y) {     if (x.l != y.l) return x.l < y.l;     for (int i = x.l; i >= 1; i--)       if (x.s[i] != y.s[i]) return x.s[i] < y.s[i];     return false;   }   inline Big tran(long long x) {     Big ans;     ans.fuzhi(x);     return ans;   }   const int maxn = 770;   struct E {     int from, to, next;   } e[maxn * 2];   int te = 1, n, point[maxn];   void add(int x, int y) {     te++;     e[te].from = x;     e[te].to = y;     e[te].next = point[x];     point[x] = te;   }   int size[maxn];   Big f[maxn][maxn];   void dfs(int p, int fa) {     size[p] = 1;     for (int i = 0; i <= n; i++) f[p][i].fuzhi(1);     for (int i = point[p]; i; i = e[i].next) {       int to = e[i].to;       if (to == fa) continue;       dfs(to, p);       for (int j = size[p]; j >= 0; j--)         for (int k = size[to]; k >= 0; k--)           f[p][j + k] = max(f[p][j + k], f[p][j] * f[to][k]);       size[p] += size[to];     }     for (int i = 1; i <= size[p]; i++) f[p][0] = max(f[p][0], f[p][i] * tran(i));   }   void ceshi() {     Big a, b;     int x, y;     cin >> x >> y;     a.fuzhi(x);     b.fuzhi(y);     a.out();     b.out();     a = a * b;     a.out();     exit(0);   }   int main() {     std::ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i < n; i++) {       int x, y;       cin >> x >> y;       add(x, y);       add(y, x);     }     dfs(1, 0);     f[1][0].out();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 105;   template <typename T>   inline void read(T &AKNOI) {     T x = 0, flag = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) flag = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     AKNOI = flag * x;   }   template <typename T>   inline void cmax(T &x, T y) {     if (x < y) x = y;   }   int n, m, lb[N][N], rb[N][N], dp[N][N];   void init() {     read(n);     read(m);     for (int i = 1; i <= n; ++i) {       int k;       read(k);       while (k--) {         int l, r;         read(l);         read(r);         for (int j = l; j <= r; ++j) {           lb[i][j] = l;           rb[i][j] = r;         }       }     }   }   void solve() {     for (int l = 1; l <= m; ++l) {       for (int i = 1, j = i + l - 1; j <= m; ++i, ++j) {         for (int k = i; k <= j; ++k) {           int cnt = 0;           for (int p = 1; p <= n; ++p) {             cnt += (i <= lb[p][k] && rb[p][k] <= j);           }           cmax(dp[i][j], dp[i][k - 1] + cnt * cnt + dp[k + 1][j]);         }       }     }     printf( %d n , dp[1][m]);   }   int main() {     init();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e5 + 123;   const long long INF = (long long)1e18 + 123;   const int inf = (int)1e9 + 123;   const int MOD = (int)1e9 + 7;   int n;   int main() {     cin >> n;     if (n % 2 == 0) {       cout <<  white n ;       cout <<  1 2 ;     } else       cout <<  black ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[300000 + 10], ans = 2e9;   vector<int> lj[300000 + 10];   multiset<int> s;   int main() {     int i;     scanf( %d , &n);     for (i = 1; i <= n; ++i) scanf( %d , &a[i]), s.insert(a[i]);     for (i = 1; i < n; ++i) {       int u, v;       scanf( %d%d , &u, &v);       lj[u].push_back(v);       lj[v].push_back(u);     }     for (i = 1; i <= n; ++i) {       int da = a[i];       s.erase(s.find(a[i]));       for (int j : lj[i]) da = max(da, a[j] + 1), s.erase(s.find(a[j]));       if (!s.empty()) da = max(da, *s.rbegin() + 2);       s.insert(a[i]);       for (int j : lj[i]) s.insert(a[j]);       ans = min(da, ans);     }     printf( %d , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     cout << (n - 2) * (n - 2);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e4 + 42;   int n, m, k;   int d[55][maxn], dp[55][maxn], s[55][maxn];   int val[maxn << 2], tag[maxn << 2];   int g;   void build(int day, int l, int r, int rt) {     if (l == r) {       val[rt] = dp[day][l] + s[day + 1][l + k - 1] - s[day + 1][l - 1];       return;     }     int mid = l + r >> 1;     build(day, l, mid, rt << 1);     build(day, mid + 1, r, rt << 1 | 1);     val[rt] = max(val[rt << 1], val[rt << 1 | 1]);   }   void pushd(int rt) {     if (!tag[rt]) return;     val[rt << 1] += tag[rt];     val[rt << 1 | 1] += tag[rt];     tag[rt << 1] += tag[rt];     tag[rt << 1 | 1] += tag[rt];     tag[rt] = 0;   }   void upd(int a, int b, int l, int r, int rt, int v) {     if (a <= l && r <= b) {       val[rt] += v, tag[rt] += v;       return;     }     pushd(rt);     int mid = l + r >> 1;     if (a <= mid) upd(a, b, l, mid, rt << 1, v);     if (b > mid) upd(a, b, mid + 1, r, rt << 1 | 1, v);     val[rt] = max(val[rt << 1], val[rt << 1 | 1]);   }   void upd(int day, int pos) {     if (pos) upd(max(1, pos - k + 1), min(g, pos), 1, g, 1, -d[day][pos]);   }   void del(int day, int pos) {     if (pos) upd(max(1, pos - k + 1), min(g, pos), 1, g, 1, d[day][pos]);   }   signed main() {     ios ::sync_with_stdio(false);     cin.tie(nullptr), cout.tie(nullptr);     cin >> n >> m >> k;     g = m - k + 1;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         cin >> d[i][j];         s[i][j] = s[i][j - 1] + d[i][j];       }     for (int i = 1; i <= n; i++) {       if (i > 1) {         for (int j = 1; j < k; j++) upd(i, j);       }       for (int j = 1; j + k - 1 <= m; j++) {         int l = j, r = j + k - 1;         if (i == 1)           dp[1][j] = s[1][r] - s[1][l - 1];         else {           del(i, l - 1);           upd(i, r);           dp[i][j] = s[i][r] - s[i][l - 1] + val[1];         }       }       memset(val, 0, sizeof(val));       memset(tag, 0, sizeof(tag));       if (i < n) build(i, 1, g, 1);     }     int ans = 0;     for (int i = 1; i <= g; i++) ans = max(ans, dp[n][i]);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   inline void mine(T1 &x, T2 y) {     if (x > y) x = y;   }   template <typename T1, typename T2>   inline void maxe(T1 &x, T2 y) {     if (x < y) x = y;   }   ostream &operator<<(ostream &a, const vector<long long> &b) {     for (auto k : b) cout << k <<    ;     return a;   }   const long long MOD = 1000000007;   const long long INF = 1000000050;   const long long BIG = (long long)2e18 + 50;   const long long MX = 2001;   const long double EPS = 1e-6;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   bool lt(long double x, long double y) { return x + EPS < y; }   bool eq(long double x, long double y) { return abs(x - y) < EPS; }   struct pt {     long double x;     long double y;     long double z;     pt(long double a, long double b, long double c) {       x = a;       y = b;       z = c;     }     bool operator<(const pt &p) const {       return lt(x, p.x) ||              (eq(x, p.x) && (lt(y, p.y) || (eq(y, p.y) && lt(z, p.z))));     }     bool operator==(const pt &p) const {       return eq(x, p.x) && eq(y, p.y) && eq(z, p.z);     }   };   long double vx[MX], vy[MX], x[MX], y[MX];   bool can[MX][MX];   long double tt[MX][MX];   bool cmp(pair<long double, long double> a, pair<long double, long double> b) {     return a.second < b.second;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     for (long long i = 0; i < n; i++) {       long double t1, x1, y1, t2, x2, y2;       cin >> t1 >> x1 >> y1 >> t2 >> x2 >> y2;       vy[i] = (y2 - y1) / (t2 - t1);       vx[i] = (x2 - x1) / (t2 - t1);       x[i] = x1 - vx[i] * t1;       y[i] = y1 - vy[i] * t1;     }     for (long long i = 0; i < n; i++) {       for (long long j = i + 1; j < n; j++) {         long double tim = 0;         if (!eq(vx[i], vx[j])) tim = (x[i] - x[j]) / (vx[j] - vx[i]);         if (!eq(vy[i], vy[j])) tim = (y[i] - y[j]) / (vy[j] - vy[i]);         long double xx = x[i] + vx[i] * tim;         long double yy = y[i] + vy[i] * tim;         if (eq(xx, x[j] + vx[j] * tim) && eq(yy, y[j] + vy[j] * tim)) {           can[i][j] = can[j][i] = true;           tt[i][j] = tt[j][i] = tim;         }       }     }     long long ans = 1;     for (long long i = 0; i < n; i++) {       vector<pair<long double, long double>> kek;       vector<long double> colis;       for (long long j = 0; j < n; j++) {         if (!can[i][j]) continue;         colis.push_back(tt[i][j]);         long double xx = vx[j] - vx[i];         long double yy = vy[j] - vy[i];         long double ang = atan2(yy, xx);         if (ang < -EPS) ang += 4 * atan(1);         kek.push_back({ang, sin(ang) * yy + cos(ang) * xx});       }       sort(colis.begin(), colis.end());       long long it = 0;       while (it < (long long)colis.size()) {         long long it2 = it + 1;         while (it2 < (long long)colis.size() && eq(colis[it2], colis[it])) ++it2;         maxe(ans, it2 - it + 1);         it = it2;       }       sort(kek.begin(), kek.end());       long long her = 0;       it = 0;       while (it < (long long)kek.size()) {         long long it2 = it + 1;         while (it2 < (long long)kek.size() &&                kek[it2].first - kek[it].first < EPS)           ++it2;         sort(kek.begin() + it, kek.begin() + it2, cmp);         long long dif = 1;         for (long long k = it + 1; k < it2; k++)           dif += !eq(kek[k].second, kek[k - 1].second);         maxe(her, dif + 1);         it = it2;       }       maxe(ans, her);     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     long long cnt = 0;     for (long long i = 0; i < s.length(); i++) {       if ((s[i] -  0 ) % 2 == 0) cnt++;     }     if (cnt == 0)       cout << -1 << endl;     else {       vector<char> v;       for (long long i = 0; i < s.length(); i++) v.push_back(s[i]);       char c = s[s.length() - 1];       for (long long i = 0; i < s.length(); i++) {         if ((s[i] -  0 ) % 2 == 0) {           cnt--;           if (s[i] < c || cnt == 0) {             v[i] = c;             v[s.length() - 1] = s[i];             break;           }         }       }       cout << string(v.begin(), v.end()) << endl;     }   }


#include <bits/stdc++.h>   using namespace std::chrono;   using namespace std;   const long long int mod = 998244353;   const int inf = 1e9 + 7;   long long int f(long long int x, long long int n) {     long long int r = 1;     while (n > 0) {       if (n % 2 == 1) r = (r * x) % mod;       x = (x * x) % mod;       n /= 2;     }     return r;   }   long long int fac[400010], invf[400010];   void buildfactorial() {     fac[0] = 1;     fac[1] = 1;     for (int i = 2; i < 400010; i++)       fac[i] = ((long long int)i * fac[i - 1]) % mod;     for (int i = 0; i < 400010; ++i) {       invf[i] = f(fac[i], mod - 2);     }   }   long long int C(int n, int r) {     if (n < r) return 0;     return (((fac[n] * invf[r]) % mod) * invf[n - r]) % mod;   }   long double dist(long double x1, long double y1, long double x2,                    long double y2) {     return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));   }   struct node {     int v, d, p;   };   void solve() {     int n;     cin >> n;     string s[n];     for (int i = 0; i < n; ++i) cin >> s[i];     for (int i = n - 2; i >= 0; --i) {       string t =   ;       for (int j = 0; j < min(s[i].length(), s[i + 1].length()); ++j) {         if (s[i][j] > s[i + 1][j])           break;         else if (s[i][j] < s[i + 1][j]) {           t = s[i];           break;         }         t += s[i][j];       }       s[i] = t;     }     for (int i = 0; i < n; ++i) cout << s[i] << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   int main() {     int s1, s2, s3, s4;     int a[4];     cin >> a[0] >> a[1] >> a[2] >> a[3];     int i, j, k = 0;     sort(a, a + 4);     j = a[0];     for (i = 1; i < 4; ++i) {       if (j == a[i]) {         k++;       } else         j = a[i];     }     cout << k;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e8;   const int MN = 2e+7;   int n, m, nn, mm;   int i, j, k, x, y, z, p, u, v;   int d[2000], tt;   char ss[2000][2000];   void change() {     int n = nn, m = mm;     if (x == 1) {       int tmp = u;       u = v;       v = n - tmp + 1;       swap(n, m);     }     if (x == 2) {       u = n - u + 1;       v = m - v + 1;     }     if (x == 3) {       int tmp = v;       v = u;       u = m - tmp + 1;       swap(n, m);     }     if (y == 1) {       v = m - v + 1;     }     if (z == 3) {       int tmp = u;       u = v;       v = n - tmp + 1;     }     if (z == 2) {       u = n - u + 1;       v = m - v + 1;     }     if (z == 1) {       int tmp = v;       v = u;       u = m - tmp + 1;     }   }   int main() {     scanf( %d%d%d%d%d%d , &n, &m, &x, &y, &z, &p);     nn = n;     mm = m;     x = x % 4;     y = y % 2;     z = z % 4;     for (i = 1; i <= p; i++) {       scanf( %d%d , &u, &v);       change();       printf( %d %d n , u, v);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> z;   const long long N = 5e3 + 7, M1 = 1e9 + 7, M2 = 1e9 + 9, b1 = 127, b2 = 239;   long long maxi1[N], maxi2[N], maxx[N];   pair<long long, long long> h1[N], h2[N];   pair<long long, long long> poww[N];   string best;   long long mod(long long x, long long m) {     x %= m;     if (x < 0) x += m;     return x;   }   pair<long long, long long> get_h(long long l, long long r) {     long long res1 =         mod(h1[r].first - h1[l - 1].first * poww[r - l + 1].first, M1);     long long res2 =         mod(h1[r].second - h1[l - 1].second * poww[r - l + 1].second, M2);     return {res1, res2};   }   pair<long long, long long> get_h2(long long l, long long r) {     long long res1 =         mod(h2[r].first - h2[l - 1].first * poww[r - l + 1].first, M1);     long long res2 =         mod(h2[r].second - h2[l - 1].second * poww[r - l + 1].second, M2);     return {res1, res2};   }   void solve(string s) {     long long n = s.length();     string t = s;     long long ser = (n + 1) / 2;     long long len = 0;     while (len != n && s[len] == s[n - len - 1]) {       len++;     }     if (len == n) {       best = s;       return;     }     if (2 * len > (long long)best.size()) {       best =   ;       for (long long i = 0; i < len; i++) best += s[i];       for (long long i = len - 1; i >= 0; i--) best += s[i];     }     for (long long i = 0; i < ser; i++) {       maxi1[i] = -1;       long long l = i, r = i;       while (l >= 0 && r < n && s[l] == s[r]) {         l--;         r++;         maxi1[i] += 2;         if (l < len) {           long long curlen = maxi1[i] + 2 * (l + 1);           if (curlen > (long long)best.size()) {             best =   ;             for (long long j = 0; j < r; j++) {               best += s[j];             }             for (long long j = l; j >= 0; j--) {               best += s[j];             }           }         }       }     }     if (n % 2 == 1) ser--;     for (long long i = 0; i < ser; i++) {       maxi2[i] = 0;       long long l = i, r = i + 1;       while (l >= 0 && r < n && s[l] == s[r]) {         l--;         r++;         maxi2[i] += 2;         if (l < len) {           long long curlen = maxi2[i] + 2 * (l + 1);           if (curlen > (long long)best.size()) {             best =   ;             for (long long j = 0; j < r; j++) {               best += s[j];             }             for (long long j = l; j >= 0; j--) {               best += s[j];             }           }         }       }     }   }   signed main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     for (long long i = 0; i < t; i++) {       string s;       cin >> s;       best = s[0];       solve(s);       reverse(s.begin(), s.end());       solve(s);       cout << best << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void chkmax(T& x, T y) {     x = x > y ? x : y;   }   template <class T>   void chkmin(T& x, T y) {     x = x < y ? x : y;   }   int n, m;   vector<string> s;   int calc(int mask, int j) {     int res = 0;     for (int i = 0; i < n; ++i)       if ((mask >> i & 1) != (s[i][j] -  0 )) ++res;     return res;   }   bool check(int a, int b) {     for (int i = 0; i < n - 1; ++i)       if (((a >> i & 1) + (a >> i + 1 & 1) + (b >> i & 1) + (b >> i + 1 & 1)) %               2 ==           0)         return 0;     return 1;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cin >> n >> m;     if (n >= 4) {       cout << -1 <<   n ;       return 0;     }     s.resize(n);     for (int i = 0; i < n; ++i) cin >> s[i];     vector<vector<int>> dp(m, vector<int>(1 << n, 1e9));     for (int mask = 0; mask < 1 << n; ++mask) dp[0][mask] = calc(mask, 0);     for (int i = 0; i < m - 1; ++i)       for (int c_mask = 0; c_mask < 1 << n; ++c_mask)         for (int n_mask = 0; n_mask < 1 << n; ++n_mask)           if (check(c_mask, n_mask))             chkmin(dp[i + 1][n_mask], dp[i][c_mask] + calc(n_mask, i + 1));     int ans = 1e9;     for (int mask = 0; mask < 1 << n; ++mask) chkmin(ans, dp[m - 1][mask]);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 987654321;   const long long int INF = 123456789987654321;   int N;   vector<int> arr, chk, chk2;   bool f(int l, int r) {     for (int i = 0; i < min(l, N - r - 1); i++) {       if (arr[i] != arr[N - i - 1]) return false;     }     chk = vector<int>(N, 0);     for (int i = min(l, N - r - 1); i <= max(r, N - l - 1); i++) {       chk[arr[i]]++;     }     chk2 = vector<int>(N, 0);     int len = max(r, N - l - 1) - min(l, N - r - 1) + 1;     if (len < 2 * (r - l + 1)) {       for (int i = min(l, N - r - 1); i <= max(r, N - l - 1); i++) {         if (i < l || r < i) {           chk2[arr[i]]++;           if (chk2[arr[i]] > chk[arr[i]] / 2) return false;         }       }     } else {       for (int i = min(l, N - r - 1); i < min(l, N - r - 1) + (r - l + 1); i++) {         chk2[arr[i]]++;       }       for (int i = min(l, N - r - 1); i < min(l, N - r - 1) + (r - l + 1); i++) {         chk2[arr[N - 1 - i]]--;       }       for (int i = 0; i < N; i++) {         if (chk2[i]) return false;       }       for (int i = min(l, N - r - 1) + (r - l + 1);            i <= max(r, N - l - 1) - (r - l + 1); i++) {         if (arr[i] != arr[N - 1 - i]) return false;       }     }     return true;   }   long long int ans = 0;   int main() {     scanf( %d , &N);     arr.resize(N);     chk = vector<int>(N, 0);     for (int i = 0; i < N; i++) {       scanf( %d , &arr[i]);       chk[--arr[i]]++;     }     if (N == 1) {       printf( 1 );       return 0;     }     int oddcnt = 0;     for (int i = 0; i < N; i++) {       if (chk[i] % 2) oddcnt++;     }     if (oddcnt > 1) {       printf( 0 );       return 0;     }     int s = 0, e = N - 1;     int idx;     while (s <= e) {       int m = (s + e) >> 1;       if (f(0, m)) {         idx = m;         e = m - 1;       } else         s = m + 1;     }     s = 0, e = N - 1;     int idx2;     while (s <= e) {       int m = (s + e) >> 1;       if (f(m, N - 1)) {         idx2 = m;         s = m + 1;       } else         e = m - 1;     }     int len = 0;     for (int i = 0; i < N / 2; i++) {       if (arr[i] != arr[N - 1 - i]) break;       len++;     }     if (len == N / 2) {       printf( %I64d , (long long int)N * (N + 1) / 2);       return 0;     }     long long int ans = len * len;     if (idx < N - len) ans += (len + 1) * (N - len - idx);     if (len <= idx2) ans += (len + 1) * (idx2 - len + 1);     if (idx < N - len && len <= idx2) ans--;     printf( %I64d , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr;     int a = 0, b = 0, i, j, k;     for (i = 0; i < n; i++) {       cin >> arr;       if (arr >= 0) {         a += arr;       } else {         b += arr;       }     }     cout << a - b << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, d;   long long x;   int a[100005], b[100005];   int a_index[100005], q[100005];   long long getNextX() {     x = (x * 37 + 10007) % 1000000007;     return x;   }   void initAB() {     for (int i = 0; i < n; i = i + 1) {       a[i] = i + 1;     }     for (int i = 0; i < n; i = i + 1) {       swap(a[i], a[getNextX() % (i + 1)]);     }     for (int i = 0; i < n; i = i + 1) {       if (i < d)         b[i] = 1;       else         b[i] = 0;     }     for (int i = 0; i < n; i = i + 1) {       swap(b[i], b[getNextX() % (i + 1)]);     }   }   int main() {     cin >> n >> d >> x;     initAB();     for (int i = 0; i < n; i++) {       a_index[a[i]] = i;     }     int s = 30;     for (int i = 0; i < n; i++)       if (b[i]) q[++q[0]] = i;     for (int i = 0; i < n; i++) {       int j;       for (j = n; j >= n - s; j--)         if (j > 0 && i >= a_index[j] && b[i - a_index[j]]) {           printf( %d n , j);           break;         }       if (j < n - s) {         int ma = 0;         for (j = 1; j <= q[0] && q[j] <= i; j++) ma = max(ma, a[i - q[j]]);         printf( %d n , ma);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, t, p[105], ans, x = 1, c;   pair<long long, long long> a[105];   int cmp(pair<long long, long long> a, pair<long long, long long> b) {     return a.first * a.second < b.first * b.second;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i].second >> a[i].first;     cin >> t;     for (int i = 1; i <= t; i++) cin >> p[i];     for (int i = t; i >= 1; i--) p[i] -= p[i - 1];     sort(a + 1, a + 1 + n);     p[t + 1] = 1000000000000000009;     for (int i = 1; i <= n; i++)       while (a[i].second) {         ans += min(a[i].second, p[x]) * x * a[i].first;         long long r = min(a[i].second, p[x]);         a[i].second -= r;         p[x] -= r;         if (!p[x]) x++;       }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool solve() {     char s[500];     if (scanf( %s , s) == EOF) return false;     int in = 0, out = 0;     for (int i = 0; s[i]; ++i) {       if (s[i] ==  + ) {         if (out) {           out--;           in++;         } else {           in++;         }       } else {         if (in) {           in--;           out++;         } else {           out++;         }       }     }     printf( %d n , in + out);     return true;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>      using namespace std;      typedef long long ll;   typedef long double ld;   #define mems(p) memset(p,-1,sizeof(p))   #define pb push_back   #define eb emplace_back   #define nl   n    #define sz(x) (int)(x).size()   #define all(x) x.begin(), x.end()   #define allr(x) x.rbegin(), x.rend()      using pi = pair<int,int>;   using pl = pair<ll,ll>;   using vi = vector<int>;   using vl = vector<ll>;   using vb = vector<bool>;   using vd = vector<double>;   using vc = vector<char>;   using vpi = vector<pi>;   using vpl = vector<pl>;   using vvi = vector<vector<int>>;   using vvl = vector<vector<ll>>;   using vvb = vector<vector<bool>>;   using vvd = vector<vector<double>>;   using vvc = vector<vector<char>>;   using vvpi = vector<vector<pi>>;   using vvpl = vector<vector<pl>>;   using vvvi = vector<vector<vector<int>>>;   using vvvl = vector<vector<vector<ll>>>;   using vvvb = vector<vector<vector<bool>>>;   using vvvd = vector<vector<vector<double>>>;   using vvvc = vector<vector<vector<char>>>;   using vvvpi = vector<vector<vector<pi>>>;   using vvvpl = vector<vector<vector<pl>>>;      const int mxN = 8e5 + 100;   const ll MOD = 1e9 + 7;      void fast()   {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}      ll gcd(ll a, ll b) {       return b ? gcd(b, a%b) : a;   }      vl factorial;      ll expo(ll x, ll exp, ll mod = MOD) {       if (exp <= 0) return 1;       ll tmp = (x*x) % mod;       if (exp%2) {           return (expo(tmp, exp/2, mod) * x) % mod;       }       return (expo(tmp, exp/2, mod)) % mod;   }      ll choice(ll n, ll r, ll mod = MOD) {       if (n < r) return 0;       ll numer = factorial[n];       ll denom = (factorial[r] * factorial[n-r]) % mod;       return numer * expo(denom, mod - 2, mod) % mod;   }      ll phi(ll n) {       ll result = n;       for (ll i = 2; i * i <= n; i++) {           if (n % i == 0) {               while (n % i == 0)                   n /= i;               result -= result / i;           }       }       if (n > 1)           result -= result / n;       return result;   }      ll store[5001][5001];   ll a[5001];   int n;      ll dp(int x, int k) {       if (k == 0) return 1;       if (store[x][k] != -1) return store[x][k];       ll res = 0;       if (x > 0) res += dp(x-1,k-1);       if (x < n - 1) res += dp(x+1,k-1);       if (res >= MOD) res -= MOD;       return store[x][k] = res;   }      int main() {       fast();       int k, q;       cin >> n >> k >> q;       for (int i = 0; i < n; ++i)       {           cin >> a[i];       }       mems(store);       ll ans = 0;       vl sum(n, 0);       for (int i = 0; i < n; ++i)       {           for (int j = 0; j <= k; ++j)           {               sum[i] += dp(i,j)*dp(i,k-j);               sum[i] %= MOD;           }           ans += sum[i]*a[i];           ans %= MOD;       }       //cout <<  init   << ans << nl;          int idx;       ll x;       for (int i = 0; i < q; ++i)       {           cin >> idx >> x;           --idx;           ll chng = x - a[idx];           if (chng < 0) chng += MOD;           ans += chng*sum[idx];           ans %= MOD;           cout << ans << nl;           a[idx] = x;       }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[300], ans[500][2], tot, v[300];   void sl(int p, int x) {     if (p == x || x == 0) return;     if (a[x] == 0 || a[x] == x) {       ans[tot][0] = p, ans[tot][1] = x;       a[x] = x;       a[p] = 0;       tot++;       return;     }     if (v[x]) {       ans[tot][0] = p, ans[tot][1] = n;       a[p] = 0;       a[n] = x;       tot++;       return;     }     v[p] = 1;     sl(x, a[x]);     ans[tot][0] = p, ans[tot][1] = x;     a[x] = x;     a[p] = 0;     tot++;     v[p] = 0;   }   int main() {     scanf( %d%d , &n, &m);     int p = 0, t, sum = 0;     for (int i = 0; i < m; i++) {       scanf( %d , &t);       sum += t;       while (t--) {         int x;         scanf( %d , &x);         a[x] = ++p;       }     }     for (int i = n; i > 0; i--) {       sl(i, a[i]);       sl(n, a[n]);     }     printf( %d n , tot);     for (int i = 0; i < tot; i++) {       printf( %d %d n , ans[i][0], ans[i][1]);     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   const double eps = 1e-6;   const double pi = acos(-1.0);   template <class Z>   inline Z SQ(Z &a) {     return a * a;   }   template <class Z>   inline bool checkmax(Z &a, Z b) {     if (a == -1 || a < b) {       a = b;       return true;     }     return false;   }   template <class Z>   inline bool checkmin(Z &a, Z b) {     if (a == -1 || a > b) {       a = b;       return true;     }     return false;   }   template <class Z>   inline bool mymax(Z &a, Z b) {     if (a < b) {       a = b;       return true;     }     return false;   }   template <class Z>   inline bool mymin(Z &a, Z b) {     if (a > b) {       a = b;       return true;     }     return false;   }   int a[100005];   int n, m;   struct SegTree {     long long tree[100005 << 2];     inline void PushUp(int rt) {       tree[rt] = tree[(rt << 1)] + tree[(rt << 1 | 1)];     }     void build(int s, int z, int l, int r, int rt) {       if (l == r) {         long long v = a[l];         int tt = (l + s) % (2 * z - 2);         if (tt == 0)           tree[rt] = v * 2;         else if (tt <= z)           tree[rt] = v * tt;         else           tree[rt] = v * (2 * z - tt);         return;       }       int m = (l + r) >> 1;       build(s, z, l, m, rt << 1);       build(s, z, m + 1, r, rt << 1 | 1);       PushUp(rt);     }     void update(int s, int z, long long val, int x, int l, int r, int rt) {       if (l == r) {         int tt = (x + s) % (2 * z - 2);         if (tt == 0)           tree[rt] = val * 2;         else if (tt <= z)           tree[rt] = val * tt;         else           tree[rt] = val * (2 * z - tt);         return;       }       int m = (l + r) >> 1;       if (x <= m)         update(s, z, val, x, l, m, rt << 1);       else         update(s, z, val, x, m + 1, r, rt << 1 | 1);       PushUp(rt);     }     long long query(int ll, int rr, int l, int r, int rt) {       if (ll <= l && r <= rr) {         return tree[rt];       }       long long sum = 0;       int m = (l + r) >> 1;       if (ll <= m) sum += query(ll, rr, l, m, rt << 1);       if (rr > m) sum += query(ll, rr, m + 1, r, rt << 1 | 1);       return sum;     }   } tree[4][8], t6[10];   void input() {     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }   }   void build() {     for (int z = 2; z <= 5; z++) {       for (int i = 0; i < 2 * z - 2; i++) {         tree[z - 2][i].build(i, z, 1, n, 1);       }     }     for (int i = 0; i < 10; i++) {       t6[i].build(i, 6, 1, n, 1);     }   }   void gao() {     scanf( %d , &m);     while (m--) {       int op;       scanf( %d , &op);       if (op == 1) {         int p, v;         scanf( %d%d , &p, &v);         for (int z = 2; z <= 5; z++) {           for (int i = 0; i < 2 * z - 2; i++) {             tree[z - 2][i].update(i, z, v, p, 1, n, 1);           }         }         for (int i = 0; i < 10; i++) {           t6[i].update(i, 6, v, p, 1, n, 1);         }       } else {         int l, r, z;         scanf( %d%d%d , &l, &r, &z);         int tp = l % (2 * z - 2);         if (tp == 0) tp = 2 * z - 2;         int s = (2 * z - 2) - tp + 1;         s %= (2 * z - 2);         if (z == 6)           printf( %I64d n , t6[s].query(l, r, 1, n, 1));         else           printf( %I64d n , tree[z - 2][s].query(l, r, 1, n, 1));       }     }   }   int main() {     while (~scanf( %d , &n)) {       input();       build();       gao();     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 5;   const int MOD = 1e9 + 7;   void solve() {     int n, m;     cin >> n >> m;     cout << (n % m ?  NO n  :  YES n );   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t = 1;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int n, m, f = 0;     cin >> n >> m;     cin >> s;     for (int i = 0; i < n; i++) {       if (s[i] ==  # )         f++;       else         f = 0;       if (f >= m) {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve();   void YN(bool b) {     if (b) {       cout <<  YES             <<   n ;       ;     } else {       cout <<  NO             <<   n ;       ;     }   };   void yn(bool b) {     if (b) {       cout <<  Yes             <<   n ;       ;     } else {       cout <<  No             <<   n ;       ;     }   };   void queries() {     int n;     cin >> n;     while (n--) solve();   }   const int maxn = 200200;   void solve() {     int n;     cin >> n;     vector<int> a(n);     vector<int> b;     map<int, int> m;     for (int i = 0; i < n; i++) {       cin >> a[i];       m[a[i]]++;     }     for (auto i : m) {       b.push_back(i.second);     }     map<int, bool> taken;     long long sum = 0;     sort(b.begin(), b.end());     for (int i = b.size() - 1; i >= 0; i--) {       if (!taken[b[i]]) {         sum += b[i];         taken[b[i]] = 1;       } else {         for (int j = b[i]; j > 0; j--) {           if (!taken[j]) {             sum += j;             taken[j] = 1;             break;           }         }       }     }     cout << sum <<   n ;     ;     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     queries();     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, j, k, n, m, a[110001], ans;   bool cmp(int a, int b) { return a > b; }   int main() {     scanf( %d%d , &n, &m);     for (i = 1; i <= m; i++) scanf( %d%d , &j, &a[i]);     sort(a + 1, a + 1 + m, cmp);     for (i = 1;; i++) {       if (i == 1)         k = 1;       else if (i == 2)         k = 2;       else {         k = min((i - 2) * (i / 2) + 2 * (1 + (i - 1) / 2),                 (i - 1) * (i / 2) + (2 + (i - 2) / 2));       }       if (k > n) break;     }     k = i - 1;     for (ans = 0, i = 1; i <= k; i++) ans += a[i];     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, q;     string a;     cin >> n;     map<string, int> m;     map<string, string> ma;     for (int i = 1; i <= n; i++) {       cin >> a;       int len = a.length();       for (int i = 0; i <= len; i++) {         for (int j = 0; j + i <= len; j++) {           string s1 = a.substr(i, j);           if (ma[s1] != a) {             m[s1]++;             ma[s1] = a;           }         }       }     }     cin >> q;     for (int i = 1; i <= q; i++) {       cin >> a;       if (m[a] != 0) {         cout << m[a] <<     << ma[a] << endl;       } else         printf( 0 - n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     n = (int)((double)n / 3 + 0.5);     cout << n / 12 <<     << n % 12 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   struct LinearBase {     const int n = 30;     vector<int> pivot = vector<int>(n);     void Insert(int curr) {       for (int bit = n - 1; bit >= 0 && curr != 0; --bit) {         if ((curr & (1 << bit)) != 0) {           curr ^= pivot[bit];         }       }       if (curr == 0) return;       int msb = 31 - __builtin_clz(curr);       assert(pivot[msb] == 0);       pivot[msb] = curr;       for (int bit = n - 1; bit > msb; --bit) {         if ((pivot[bit] & (1 << bit)) != 0) {           pivot[bit] ^= curr;         }       }     }     int Query(int ans) {       for (int bit = n - 1; bit >= 0; --bit) {         if ((ans & (1 << bit)) != 0) {           ans ^= pivot[bit];         }       }       return ans;     }   };   struct Graph {     int n;     LinearBase base;     vector<int> dist;     vector<vector<pair<int, int>>> adj;     Graph(int n_) : n(n_), dist(n, -1), adj(n) {}     void AddEdge(int a, int b, int w) {       adj[a].emplace_back(b, w);       adj[b].emplace_back(a, w);     }     void DFS(int node) {       for (auto &e : adj[node]) {         int x, w;         tie(x, w) = e;         if (dist[x] == -1) {           dist[x] = dist[node] ^ w;           DFS(x);         } else {           base.Insert(dist[node] ^ dist[x] ^ w);         }       }     }     int Solve() {       dist[0] = 0;       DFS(0);       return base.Query(dist[n - 1]);     }   };   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     Graph g(n);     for (int i = 0; i < m; ++i) {       int a, b, w;       cin >> a >> b >> w;       g.AddEdge(a - 1, b - 1, w);     }     cout << g.Solve() << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 7;   const int maxm = 1e9 + 7;   int n;   int a[maxn], b[maxn], c[maxn], ans[maxn];   map<int, int> mp;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       b[i] = a[i];     }     queue<int> q;     q.push(n);     mp[a[n]] = n;     for (int i = n; i >= 1; i--) {       if (a[i] < a[q.back()]) {         q.push(i);         mp[a[q.back()]] = i;       }     }     sort(b + 1, b + 1 + n);     int num = unique(b + 1, b + n + 1) - b;     int p = 0;     for (int i = 1; i <= num - 1; i++) {       int j = b[i];       if (!mp[j])         mp[j] = p;       else {         swap(mp[j], p);       }     }     for (int i = 1; i <= n; i++) {       if (i >= mp[a[i]])         printf( -1  );       else         printf( %d  , mp[a[i]] - i - 1);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.sync_with_stdio(false);     cin.tie(0);     long int n;     cin >> n;     const long int N = n;     char s[N];     int cnt0 = 0, cnt1 = 0;     for (int i = 0; i < n; i++) {       cin >> s[i];       if (s[i] ==  z ) {         cnt0++;       }       if (s[i] ==  n ) {         cnt1++;       }     }     for (int i = 0; i < cnt1; i++) cout <<  1  ;     for (int i = 0; i < cnt0; i++) cout <<  0  ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NMAX = 100007;   int v[NMAX];   int n;   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> v[i];     }     sort(v + 1, v + n + 1);     for (int i = 3; i <= n; ++i) {       if (v[i - 2] + v[i - 1] > v[i]) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   char s[100005];   vector<int> p, star;   void input() {     scanf( %s , s);     p.clear(), star.clear();     int l = strlen(s);     for (int i = 0; i < l; i++) {       if (s[i] ==  P ) p.push_back(i);       if (s[i] ==  * ) star.push_back(i);     }     n = p.size(), m = star.size();   }   bool can(int step) {     int now = 0;     for (int i = 0; i < n; i++) {       if (now == m) return 1;       if (p[i] - star[now] > step) return 0;       int j = now;       while (j < m) {         int MIN = min(abs(p[i] - star[now]), abs(p[i] - star[j]));         MIN += star[j] - star[now];         if (MIN <= step)           j++;         else           break;       }       now = j;       if (now == m) return 1;     }     return 0;   }   int binary(int l, int r) {     if (l == r) return l;     int m = (l + r) >> 1;     if (can(m)) return binary(l, m);     return binary(m + 1, r);   }   int main() {     int l;     while (cin >> l) {       input();       cout << binary(0, 2 * l) << endl;     }     return 0;   }


#include <bits/stdc++.h>   #define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);   #define F first   #define S second   #define V vector   #define PB push_back   #define MP make_pair   #define EB emplace_back   #define ALL(v) (v).begin(), (v).end()   #define debug(x) cerr <<  Line(  << __LINE__ <<  ) ->   << #x <<   is   << x << endl      using namespace std;      typedef long long ll;   typedef pair<int, int> pi;   typedef V<int> vi;      const int INF = 1e9 + 7, N = 4e5 + 7;      int p[N], cnt[N], vis[N];   vi G[N];      int find(int u) {    return p[u] == u ? u : p[u] = find(p[u]);   }      void unite(int x, int y) {    int rx = find(x), ry = find(y);    if(rx == ry) return;    cnt[ry] += cnt[rx];    p[rx] = ry;   }      signed main()   {    IO_OP;       int n;    cin >> n;    V<array<int, 3>> a;    for(int i = 1; i <= n; i++) {     int x, y;     cin >> x >> y;     a.PB({x, y, i});     a.PB({y, x, -i});    }    sort(ALL(a));    for(int i = 2; i <= 2 * n + 1; i++) p[i] = i;    for(int i = 1; i <= n; i++) cnt[i * 2] = 1;    set<array<int, 3>> stk;    for(int i = 0; i < n * 2; i++) {     int u = abs(a[i][2]) * 2, v = u + 1;     if(a[i][2] < 0) swap(u, v);     int y = a[i][1];     for(auto tt:stk) {      if(tt[0] > y) break;      unite(tt[1], v);      unite(tt[2], u);      if(find(u) == find(v)) {       cout << -1 <<   n ;       return 0;      }     }     stk.insert({y, u, v});    }    for(int i = 1; i <= n; i++) {     if(find(i * 2) == find(i * 2 + 1)) {      cout << -1 <<   n ;      return 0;     }    }    for(int i = 2; i <= n * 2 + 1; i++) {     G[find(i)].PB(i);    }    int ans = 0;    for(int i = 1; i <= n; i++) {     if(!vis[i]) {      int x = find(i * 2), y = find(i * 2 + 1);      ans += min(cnt[x], cnt[y]);      for(int u:G[x]) vis[u / 2] = 1;     }    }    cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> a;   int main() {     string s;     cin >> s;     int cur = 0, mul = 1;     for (int i = s.length() - 1; i >= 0; --i) {       if (s[i] ==  , ) {         a.push_back(cur);         mul = 1;         cur = 0;       } else {         cur += mul * (s[i] - 48);         mul *= 10;       }     }     a.push_back(cur);     sort(a.begin(), a.end());     int L;     int last = a[0];     bool ok = 0;     printf( %d , a[0]);     L = a[0];     for (int i = 1; i < a.size(); ++i) {       if (a[i] == last) continue;       if (a[i] == last + 1) {         ok = 1;         last = a[i];       } else {         if (ok && L != last) {           printf( -%d , last);           L = last;         }         last = a[i];         printf( ,%d , a[i]);         L = a[i];       }     }     if (ok && L != last) printf( -%d , last);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     string str;     cin >> str;     set<string> visited;     queue<string> s;     s.push(str);     visited.insert(str);     int count = 0, x = 0;     while (!s.empty() && count != k) {       string temp = s.front();       x = x + temp.length();       count++;       s.pop();       for (int i = 0; i < temp.length(); i++) {         string temp2 =   ;         for (int j = 0; j < temp.length(); j++) {           if (j != i) temp2 += temp[j];         }         if (visited.find(temp2) == visited.end()) {           s.push(temp2);           visited.insert(temp2);         }       }     }     if (s.empty() && count < k)       cout <<  -1 ;     else       cout << n * k - x;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m;   int main() {     cin >> n >> m;     if (n > m) {       swap(n, m);     }     if (n % 2 == 0 && m % 2 == 0) {       if (n == 2 && m == 2)         cout << 0 << endl;       else         cout << n * m << endl;       return 0;     }     if (n + m <= 4) {       cout << 0 << endl;       return 0;     }     if (n == 1) {       if (m % 6 == 1 || m % 6 == 5) {         cout << m - 1 << endl;       } else if (m % 6 == 2 || m % 6 == 4) {         cout << m - 2 << endl;       } else if (m % 6 == 3) {         cout << m - 3 << endl;       } else {         cout << m << endl;       }       return 0;     }     if (n % 2 == 1 && m % 2 == 0) {       swap(n, m);     }     if (n % 2 == 0) {       if (m == 3) {         if (n >= 4)           cout << m * n << endl;         else           cout << 4 << endl;         return 0;       }       if (n == 2) {         if (m == 7)           cout << 12 << endl;         else if (m == 3)           cout << 4 << endl;         else           cout << m * n << endl;         return 0;       }       if (n >= 4) {         cout << m * n << endl;         return 0;       }     }     if (n > m) swap(n, m);     cout << m * n - 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   const int mod = 1e9 + 7;   char str[maxn];   long long qp(long long a, long long b) {     long long ret = 1;     while (b) {       if (b & 1) ret = ret * a % mod;       a = a * a % mod;       b >>= 1;     }     return ret;   }   long long inv(long long a) { return qp(a, mod - 2); }   void solve(long long);   int main() {     scanf( %s , str);     long long k;     cin >> k;     solve(k);     return 0;   }   void solve(long long k) {     long long n = (long long)strlen(str);     long long ans = 0;     for (int i = 0; i < n; i++) {       if (str[i] ==  0  || str[i] ==  5 ) {         long long tmp = (qp(2, n * k + i) - qp(2, i) + mod) % mod;         tmp = tmp * inv(qp(2, n) - 1) % mod;         ans = (ans + tmp) % mod;         while (ans < 0) ans += mod;       }     }     cout << ans << endl;     return;   }


#include <bits/stdc++.h>   using namespace std;   long long int power_mod(long long int a, long long int x) {     if (x == 0) return 1;     long long int y = power_mod(a, x / 2);     long long int ans = (y * y) % 1000000007;     if (x % 2) ans = (ans * a) % 1000000007;     return ans;   }   long long int inv(long long int a) { return power_mod(a, 1000000007 - 2); }   long long int power(long long int a, long long int x) {     if (x == 0) return 1;     long long int y = power(a, x / 2);     long long int ans = (y * y);     if (x % 2) ans *= a;     return ans;   }   const long long int N = 1 + 1ll << 18;   int level[20] = {};   long long int a[N] = {};   long long int tree[4 * N] = {};   void build(long long int st, long long int ed, long long int node) {     if (st == ed) {       tree[node] = a[st];       return;     }     long long int mid = (st + ed) / 2;     long long int left = 2 * node;     long long int right = 2 * node + 1;     build(st, mid, left);     build(mid + 1, ed, right);     tree[node] = tree[left] + tree[right];   }   inline void update(long long int st, long long int ed, long long int node,                      long long int dep, long long int i) {     if (i < st or i > ed) return;     if (st == ed) {       if (st == i) {         tree[node] = a[st];       }       return;     }     long long int mid = (st + ed) / 2;     long long int left = 2 * node;     long long int right = 2 * node + 1;     if (level[dep]) {       swap(left, right);     }     update(st, mid, left, dep - 1, i);     update(mid + 1, ed, right, dep - 1, i);     tree[node] = tree[left] + tree[right];   }   inline long long int query(long long int st, long long int ed, long long int l,                              long long int r, long long int node,                              long long int dep) {     if (ed < l or st > r) return 0;     if (st >= l and ed <= r) return tree[node];     long long int mid = (st + ed) / 2;     long long int left = 2 * node;     long long int right = 2 * node + 1;     long long int x = st, y = mid;     long long int go = left;     if (l > mid) {       x = mid + 1;       y = ed;       go = right;     }     if (level[dep]) {       if (go == left) {         go = right;       } else         go = left;     }     return query(x, y, l, r, go, dep - 1);   }   inline long long int get(long long int x, long long int n) {     if (x == 0) return 0;     long long int sum = 0;     long long int left = 1;     long long int m = 1 << n;     for (long long int i = 18; i >= 0; i--) {       if (x & (1 << i)) {         sum += query(1, m, left, left - 1 + (1 << i), 1, n);         left += (1 << i);       }     }     return sum;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, q;     cin >> n >> q;     long long int m = 1ll << n;     for (long long int i = 1; i <= m; i++) {       cin >> a[i];     }     build(1, m, 1);     while (q--) {       long long int c;       cin >> c;       if (c == 1) {         long long int x, k;         cin >> x >> k;         a[x] = k;         update(1, m, 1, n, x);       }       if (c == 2) {         long long int x;         cin >> x;         for (long long int i = 0; i <= x; i++) {           level[i] = 1 - level[i];         }       }       if (c == 3) {         long long int x;         cin >> x;         level[x + 1] = 1 - level[x + 1];       }       if (c == 4) {         long long int l, r;         cin >> l >> r;         long long int ans = get(r, n) - get(l - 1, n);         cout << ans << endl;       }     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast ,  unroll-loops )   using namespace std;   const int MOD = 1e9 + 7;   const int MAXN = 1010;   const double EPS = 0.000001;   double A[MAXN], B[MAXN];   int n, m;   bool can(double X) {     for (int i = 0; i < n; i++) {       double W_li = m + X;       double TO = W_li / A[i];       if (TO > X) return false;       X -= TO;       double W_la = W_li - TO;       double LN = W_la / B[(i + 1) % n];       if (LN > X) return false;       X -= LN;     }     return true;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> A[i] >> B[i];     double l = 0.0, r = 1e9 + 1;     double ans = 0.0;     bool flag = false;     while (l <= r) {       double mid = (l + r) / 2.0;       if (abs(r - l) < EPS) {         if (can(l)) {           ans = l;         } else if (can(r)) {           ans = r;         }         break;       }       if (can(mid)) {         flag = true;         ans = mid;         r = mid;       } else {         ans = mid;         l = mid;       }     }     if (flag)       cout << setprecision(20) << ans <<   n ;     else       cout << -1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000008;   int n, m, k, d, i, j, e;   int tmp[N], pos[N], p[N], c[N];   char s[N];   int main() {     scanf( %s %d , s, &m);     n = strlen(s);     while (m--) {       scanf( %d%d , &k, &d);       for (i = 0; i < n; i++) {         c[i] = (i + 1) % n;         pos[i] = p[i] = i;       }       int t = 0;       for (i = 0; i < d; i++)         for (j = i; j < k; t++, j += d) p[t] = j;       for (i = 0; i < n; ++i) {         c[i] = p[c[i]];       }       for (e = n - k + 1; e; e >>= 1) {         for (i = 0; i < n; ++i) tmp[i] = c[i];         if (e & 1)           for (i = 0; i < n; ++i) pos[i] = c[pos[i]];         for (i = 0; i < n; ++i) c[i] = tmp[c[i]];       }       for (i = 0; i < n; ++i) tmp[(i + n - k + 1) % n] = s[pos[i]];       for (i = 0; i < n; ++i) putchar(s[i] = (char)tmp[i]);       putchar(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5e5;   vector<int> G[MAXN];   int happiness[MAXN], f[MAXN], tmpAns = 0, ans = 0;   void dfs(int u, int par) {     int oldTmpAns = -1, oldF = -1, oldFPos = -1;     if (~par && f[tmpAns] < happiness[u])       oldTmpAns = tmpAns, f[++tmpAns] = happiness[u];     else {       int pos = lower_bound(f, f + tmpAns, happiness[u]) - f;       oldF = f[pos], oldFPos = pos;       f[pos] = happiness[u];     }     ans = max(ans, tmpAns);     for (int i = 0; i < G[u].size(); i++) {       int v = G[u][i];       if (v == par) continue;       dfs(v, u);     }     if (oldTmpAns != -1) tmpAns = oldTmpAns;     if (oldF != -1) f[oldFPos] = oldF;   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> happiness[i];     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       --x, --y;       G[x].push_back(y);       G[y].push_back(x);     }     for (int i = 0; i < n; i++) {       f[0] = happiness[i];       tmpAns = 0;       dfs(i, -1);     }     cout << ans + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, maxx, cmax;   int t[100010];   long long int sum[100010];   int binary_search1(int st, int dr, int pos, int x) {     int sol = 0;     while (st <= dr) {       int m = (st + dr) / 2;       long long int lsum = sum[pos] - sum[m - 1];       lsum = 1LL * (pos - m + 1) * x - lsum;       if (lsum <= k) {         sol = m;         dr = m - 1;       } else         st = m + 1;     }     return sol;   }   int main() {     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &t[i]);     sort(t + 1, t + n + 1);     for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + t[i];     maxx = 1;     cmax = t[1];     for (int i = 1; i <= n; i++) {       int pos = binary_search1(1, i - 1, i, t[i]);       if (pos > 0 && i - pos + 1 > maxx) {         maxx = i - pos + 1;         cmax = t[i];       }     }     printf( %d %d , maxx, cmax);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     long long int arr[n][2];     for (int i = 0; i < n; i++) {       cin >> arr[i][0] >> arr[i][1];     }     long long int x = max(arr[0][0], arr[0][1]);     vector<int> v1;     int fail = 0;     for (int i = 1; i < n; i++) {       long long int y = max(arr[i][0], arr[i][1]);       long long int k = min(arr[i][0], arr[i][1]);       if (y <= x) {         v1.push_back(y);         x = y;       } else if (k <= x) {         v1.push_back(k);         x = k;       } else {         fail = 1;         break;       }     }     if (fail == 1)       cout <<  NO ;     else       cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt, dfn[800005], ed[800005], tot, head[800005], tr[800005 * 4],       sum[800005 * 4], fuckljx, n, m, vis[800005], de[800005];   char c[800005];   vector<char> mp[800005];   struct edge {     int to, next;   } data[800005 * 2];   struct hh {     long long x, a, b, val;   } edge[800005 * 2];   bool operator<(hh A, hh B) { return A.x < B.x; }   void add_edge(int x, int y) {     if (!x || !y) return;     de[y]++;     data[++tot].next = head[x];     data[tot].to = y;     head[x] = tot;   }   int id(int x, int y) {     if (x < 1 || x > n || y < 1 || y > m) return 0;     return (x - 1) * m + y;   }   void dfs(int x, int f) {     vis[x] = 1;     dfn[x] = ++cnt;     for (int i = head[x]; i; i = data[i].next) {       int t = data[i].to;       if (t == f) continue;       dfs(t, x);     }     ed[x] = cnt;   }   void add(int x, int l, int r, int s, int t, int val) {     if (l > t || r < s) return;     if (s <= l && r <= t) {       if (val == 1) {         sum[x]++;         tr[x] = (r - l + 1);       } else {         sum[x]--;         if (!sum[x]) tr[x] = tr[x * 2] + tr[x * 2 + 1];       }       return;     }     int mid = (l + r) / 2;     add(x * 2, l, mid, s, t, val);     add(x * 2 + 1, mid + 1, r, s, t, val);     if (!sum[x])       tr[x] = tr[x * 2] + tr[x * 2 + 1];     else       tr[x] = (r - l + 1);   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       scanf( %s , c + 1);       for (int j = 1; j <= m; j++) {         if (c[j] ==  U ) add_edge(id(i - 1, j), id(i + 1, j));         if (c[j] ==  D ) add_edge(id(i + 1, j), id(i - 1, j));         if (c[j] ==  L ) add_edge(id(i, j - 1), id(i, j + 1));         if (c[j] ==  R ) add_edge(id(i, j + 1), id(i, j - 1));         mp[i].push_back(c[j]);       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (((i + j) & 1) && !de[id(i, j)]) dfs(id(i, j), 0);       }     }     cnt = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (!((i + j) & 1) && !de[id(i, j)]) dfs(id(i, j), 0);       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (mp[i][j - 1] ==  U ) {           if ((i + j) & 1) {             edge[++fuckljx] =                 (hh){dfn[id(i, j)], dfn[(id(i + 1, j))], ed[(id(i + 1, j))], 1};             edge[++fuckljx] = (hh){ed[id(i, j)] + 1, dfn[(id(i + 1, j))],                                    ed[(id(i + 1, j))], -1};           } else {             edge[++fuckljx] =                 (hh){dfn[id(i + 1, j)], dfn[(id(i, j))], ed[(id(i, j))], 1};             edge[++fuckljx] =                 (hh){ed[id(i + 1, j)] + 1, dfn[(id(i, j))], ed[(id(i, j))], -1};           }         }         if (mp[i][j - 1] ==  L ) {           if ((i + j) & 1) {             edge[++fuckljx] =                 (hh){dfn[id(i, j)], dfn[(id(i, j + 1))], ed[(id(i, j + 1))], 1};             edge[++fuckljx] = (hh){ed[id(i, j)] + 1, dfn[(id(i, j + 1))],                                    ed[(id(i, j + 1))], -1};           } else {             edge[++fuckljx] =                 (hh){dfn[id(i, j + 1)], dfn[(id(i, j))], ed[(id(i, j))], 1};             edge[++fuckljx] =                 (hh){ed[id(i, j + 1)] + 1, dfn[(id(i, j))], ed[(id(i, j))], -1};           }         }       }     }     sort(edge + 1, edge + 1 + fuckljx);     long long last = 0, ans = 0;     for (int i = 1; i <= fuckljx; i++) {       ans += (long long)tr[1] * (edge[i].x - last);       last = edge[i].x;       add(1, 1, cnt + 3, edge[i].a, edge[i].b, edge[i].val);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, r;     scanf( %d%d%d , &a, &b, &r);     printf( %s n , a >= 2 * r && b >= 2 * r ?  First  :  Second );   }


#include <bits/stdc++.h>   using namespace std;   int T;   long long r, b, k, g;   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   int main() {     scanf( %d , &T);     while (T--) {       scanf( %lld%lld%lld , &r, &b, &k);       if (r > b) swap(r, b);       g = gcd(r, b);       r /= g, b /= g;       if ((k - 1) * r + 1 >= b)         printf( OBEY n );       else         printf( REBEL n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int month, day;     int cheat[13] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};     cin >> month >> day;     int n = cheat[month] - 8 + day;     int ans = 1 + (n / 7) + ((n % 7) > 0);     cout << ans;     return 0;   }