#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9;   const long long llinf = (long long)3e18;   const int N = (int)1e6 + 111;   const long double PI = (long double)acos(-1);   int cnt1[N], cnt[N];   int main() {     int t, x, mx = 0, len = 0, n, m;     scanf( %d , &t);     for (int i = 0; i < t; i++) {       scanf( %d , &x);       cnt[x]++;       mx = max(mx, x);     }     n = mx;     for (int i = 1; i < mx; i++)       if (4 * i != cnt[i]) {         len = i - 1;         break;       }     for (n = 1; n * n <= t; n++)       if (t % n == 0) {         m = t / n;         for (int i = 0; i < n; i++)           for (int j = 0; j < m; j++)             if (min(min(i, n - 1 - i), min(j, m - 1 - j)) == len &&                 max(i, n - 1 - i) + max(j, n - 1 - j) == mx) {               for (int cur = 0; cur <= mx; cur++) cnt1[cur] = 0;               bool ok = true;               for (int ii = 0; ii < n; ii++)                 for (int jj = 0; jj < m; jj++) cnt1[abs(i - ii) + abs(j - jj)]++;               for (int cur = 0; cur <= mx; cur++)                 if (cnt1[cur] != cnt[cur]) ok = false;               if (ok) {                 printf( %d %d n%d %d , n, m, i + 1, j + 1);                 return 0;               }             }       }     printf( -1 );   }


#include <bits/stdc++.h>   using namespace std;   const int Inf = 0x3f3f3f3f;   const long long INF = 0x3f3f3f3f3f3f3f3fll;   const int jt = 1000000007;   void inline add(int &a, int b) {     a += b - jt;     a += (a >> 31) & jt;   }   void inline sub(int &a, int b) {     a -= b;     a += (a >> 31) & jt;   }   void inline mul(int &a, int b) { a = (long long)a * b % jt; }   int inline Add(int a, int b) { return a + b >= jt ? a + b - jt : a + b; }   int inline Sub(int a, int b) { return a - b < 0 ? a - b + jt : a - b; }   int inline Mul(int a, int b) { return (long long)a * b % jt; }   int inline ksmii(int a, int b) {     int res = 1;     while (b) {       if (b & 1) mul(res, a);       mul(a, a);       b >>= 1;     }     return res;   }   int n, m;   int main() {     scanf( %d%d , &n, &m);     int fn = ksmii(n + 1, jt - 2);     printf( %d n , Mul(Sub(1, Mul(fn, m)), ksmii(Mul(2, n + 1), m)));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 1;     char ch;     for (ch = getchar(); (ch <  0  || ch >  9 ) && ch !=  - ; ch = getchar())       ;     if (ch ==  - ) f = 0, ch = getchar();     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return f ? x : -x;   }   long long n, res;   long long a[500010], l[500010], r[500010];   long long fl[500010][21];   long long fr[500010][21];   long long st[500010], top;   signed main() {     n = read();     a[0] = a[n + 1] = 1e9 + 7;     for (long long i = 1; i <= n; ++i) {       a[i] = read();       fl[i][0] = fr[i][0] = a[i];       while (a[i] >= a[st[top]] && top) --top;       l[i] = st[top] + 1;       st[++top] = i;     }     top = 0;     st[top] = n + 1;     for (long long i = n; i >= 1; --i) {       while (a[i] > a[st[top]] && top) --top;       r[i] = st[top] - 1;       st[++top] = i;     }     for (long long i = 1; i <= 18; ++i) {       for (long long j = 1; j <= n; ++j) {         fl[j][i] = fl[j][i - 1] | fl[j + (1 << (i - 1))][i - 1];       }       for (long long j = n; j >= 1; --j) {         fr[j][i] = fr[j][i - 1];         if (j >= (1 << (i - 1)))           fr[j][i] = fr[j][i - 1] | fr[j - (1 << (i - 1))][i - 1];       }     }     for (long long i = 1; i <= n; ++i) {       if (i - l[i] <= r[i] - i) {         for (long long k = l[i]; k <= i; ++k) {           long long now = k;           long long sum = a[k];           for (long long d = 18; d >= 0; --d) {             if (now + (1 << d) <= r[i] && (sum | fl[now + 1][d]) <= a[i]) {               sum |= fl[now + 1][d];               now += (1 << d);             }           }           if (now >= i) res += (now - i + 1);         }       } else {         for (long long k = i; k <= r[i]; ++k) {           long long now = k;           long long sum = a[k];           for (long long d = 18; d >= 0; --d) {             if (now - (1 << d) >= l[i] && (sum | fr[now - 1][d]) <= a[i]) {               sum |= fr[now - 1][d];               now -= (1 << d);             }           }           if (now <= i) res += (i - now + 1);         }       }     }     printf( %lld n , (n) * (n + 1) / 2 - res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int t[n + 1];     for (int i = 0; i < n; i++) {       cin >> t[i];     }     for (int i = 0; i < n; i++) {       int tt = t[i];       for (int j = 1; j <= tt; j++) cout << j <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100000 + 77, Mod = 1000000007;   struct SegmentTree {     int nn;     vector<int> LC, RC, S, lz;     int cur = 0;     inline void __init() { AddNode(); }     inline void AddNode() {       ++cur;       LC.push_back(-1);       RC.push_back(-1);       S.push_back(0);       lz.push_back(0);     }     inline void Clear() {       LC.clear();       LC.shrink_to_fit();       RC.clear();       RC.shrink_to_fit();       S.clear();       S.shrink_to_fit();       lz.clear();       lz.shrink_to_fit();     }     inline void AddLeft(int id) {       if (LC[id] != -1) return;       LC[id] = cur;       AddNode();     }     inline void AddRight(int id) {       if (RC[id] != -1) return;       RC[id] = cur;       AddNode();     }     inline void Shift(int l, int r, int id) {       int x = lz[id];       lz[id] = 0;       S[id] = (S[id] + (r - l) * 1ll * x) % Mod;       if (r - l > 1)         AddRight(id), AddLeft(id), lz[LC[id]] = (lz[LC[id]] + x) % Mod,                                    lz[RC[id]] = (lz[RC[id]] + x) % Mod;     }     void Add(int ql, int qr, int x, int l, int r, int id) {       Shift(l, r, id);       if (qr <= l || r <= ql) return;       if (ql <= l && r <= qr) {         lz[id] = (lz[id] + x) % Mod;         Shift(l, r, id);         return;       }       int mid = ((l + r) >> 1);       assert(LC[id] != -1);       assert(RC[id] != -1);       Add(ql, qr, x, l, mid, LC[id]);       Add(ql, qr, x, mid, r, RC[id]);       S[id] = (S[LC[id]] + S[RC[id]]) % Mod;     }     int Get(int ql, int qr, int l, int r, int id) {       Shift(l, r, id);       if (qr <= l || r <= ql) return 0;       if (ql <= l && r <= qr) return S[id];       int mid = ((l + r) >> 1);       return (Get(ql, qr, l, mid, LC[id]) + Get(ql, qr, mid, r, RC[id])) % Mod;     }     inline void Add(int ql, int qr, int x) { Add(ql, qr, x, 1, nn + 1, 0); }     inline int Get(int ql, int qr) { return Get(ql, qr, 1, nn + 1, 0); }   };   int n, A, L[N], R[N], a[N], d[N], XX = 1;   vector<int> adj[N], V[N];   SegmentTree Sv;   SegmentTree S[N];   inline int Pow(int x, long long y) {     int r = 1;     for (; y; y >>= 1, x = x * 1ll * x % Mod)       if (y & 1) r = r * 1ll * x % Mod;     return r;   }   void dfs(int v, int prev = -1) {     for (int u : adj[v])       if (u != prev) d[u] = d[v] + 1, dfs(u, v);   }   void dfs2(int v, int prev = -1) {     S[v].Add(L[v], R[v] + 1, a[v]);     V[v].push_back(v);     for (int u : adj[v]) {       if (u == prev) continue;       dfs2(u, v);       if ((int)V[u].size() > (int)V[v].size()) swap(V[v], V[u]), swap(S[v], S[u]);       for (int x : V[u]) {         int val = S[v].Get(L[x], R[x] + 1) * 1ll * a[x] % Mod;         val = val * 2ll * d[v] % Mod;         A = (A - val + Mod) % Mod;       }       for (int x : V[u]) {         V[v].push_back(x);         S[v].Add(L[x], R[x] + 1, a[x]);       }       V[u].clear();       V[u].shrink_to_fit();       S[u].Clear();     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i)       scanf( %d %d , L + i, R + i), XX = XX * 1ll * (R[i] - L[i] + 1) % Mod,                                     a[i] = Pow(R[i] - L[i] + 1, Mod - 2);     for (int u, v, i = 1; i < n; ++i)       scanf( %d %d , &v, &u), adj[v].push_back(u), adj[u].push_back(v);     dfs(1);     Sv.nn = N - 2;     Sv.__init();     for (int i = 1; i <= n; ++i) S[i].nn = N - 2, S[i].__init();     for (int i = 1; i <= n; ++i) Sv.Add(L[i], R[i] + 1, a[i]);     for (int i = 1; i <= n; ++i) {       int val = Sv.Get(L[i], R[i] + 1);       val = (val - a[i] * 1ll * (R[i] - L[i] + 1)) % Mod;       if (val < 0) val += Mod;       A = (A + d[i] * 1ll * a[i] % Mod * 1ll * val) % Mod;     }     dfs2(1);     A = ((A % Mod) + Mod) % Mod;     A = A * 1ll * XX % Mod;     printf( %d n , A);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Q {     int r1, r2, c1, c2, idx;   };   int n, m, k, q;   Q qs[200000];   vector<int> qAtRow[100001];   vector<int> qAtCol[100001];   vector<int> atCol[100001];   vector<int> atRow[100001];   bool must[200000];   bool res[200000];   int v[100001];   int Z = 400001;   int seg[400001];   int at, val;   void update(int n, int s, int e) {     if (at < s || at > e) return;     if (s == e) {       if (seg[n] == (1 << 29))         seg[n] = val;       else         seg[n] = val;       return;     }     update(n * 2, s, (s + e) / 2);     update(n * 2 + 1, (s + e) / 2 + 1, e);     seg[n] = max(seg[n * 2], seg[n * 2 + 1]);   }   int l, r;   int get(int n, int s, int e) {     if (l > e || r < s) return -1;     if (s >= l && e <= r) return seg[n];     return max(get(n * 2, s, (s + e) / 2), get(n * 2 + 1, (s + e) / 2 + 1, e));   }   int main() {     scanf( %d%d%d%d , &n, &m, &k, &q);     for (int i = 0; i < k; ++i) {       int r, c;       scanf( %d%d , &r, &c);       atCol[c].push_back(r);       atRow[r].push_back(c);     }     for (int i = 0; i < q; ++i) {       Q &t = qs[i];       scanf( %d%d%d%d , &t.r1, &t.c1, &t.r2, &t.c2);       t.idx = i;       qAtCol[t.c1].push_back(i);       qAtRow[t.r1].push_back(i);     }     for (int i = 0; i < Z; ++i) seg[i] = 1 << 29;     for (int i = n; i > 0; --i) {       for (int j = 0; j < atRow[i].size(); ++j) {         at = atRow[i][j];         val = i;         update(1, 1, m);       }       for (int j = 0; j < qAtRow[i].size(); ++j) {         Q &t = qs[qAtRow[i][j]];         l = t.c1;         r = t.c2;         int a = get(1, 1, m);         if (a <= 0 || a > t.r2) must[t.idx] = true;       }     }     for (int i = 0; i < Z; ++i) seg[i] = 1 << 29;     for (int i = m; i > 0; --i) {       for (int j = 0; j < atCol[i].size(); ++j) {         at = atCol[i][j];         val = i;         update(1, 1, n);       }       for (int j = 0; j < qAtCol[i].size(); ++j) {         Q &t = qs[qAtCol[i][j]];         l = t.r1;         r = t.r2;         int a = get(1, 1, n);         if (must[t.idx] && (a <= 0 || a > t.c2)) res[t.idx] = true;       }     }     for (int i = 0; i < q; ++i)       if (res[i])         puts( NO );       else         puts( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[300005];   vector<int> v[300005];   int cnt;   int main(int argc, char** argv) {     int T;     cin >> T;     while (T--) {       int n;       cin >> n;       a[0] = {-1, 0};       for (int i = 1; i <= n; i++) scanf( %d , &a[i].first), a[i].second = i;       sort(a + 1, a + n + 1);       for (int i = 1; i <= cnt + 1; i++) v[i].clear();       cnt = 0;       for (int i = 1; i <= n; i++) {         if (a[i].first != a[i - 1].first) ++cnt;         v[cnt].push_back(a[i].second);       }       int lst = 1, now = 0, ans = 0;       v[cnt + 1].push_back(-1);       for (int i = 1; i <= cnt + 1; i++) {         if (!v[i - 1].size() || v[i][0] > v[i - 1][v[i - 1].size() - 1])           now += v[i].size();         else {           for (auto x : v[i])             if (x > v[i - 1][v[i - 1].size() - 1]) ++now;           for (auto x : v[lst - 1])             if (x < v[lst][0]) ++now;           ans = max(ans, now);           lst = i, now = v[i].size();         }         int nw = 0;         for (int j = 0; j < v[i].size(); j++) {           while (nw < v[i + 1].size() && v[i + 1][nw] <= v[i][j]) ++nw;           ans = max(ans, j + (int)v[i + 1].size() - nw + 1);         }       }       cout << n - ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long spf[21];   long long fac[21];   void sieve() {     spf[1] = 1;     for (long long i = 2; i < 21; i++) spf[i] = i;     for (long long i = 4; i < 21; i += 2) spf[i] = 2;     for (long long i = 3; i * i < 21; i++) {       if (spf[i] == i) {         for (long long j = i * i; j < 21; j += i)           if (spf[j] == j) spf[j] = i;       }     }   }   map<long long, long long> getfactor(long long a) {     map<long long, long long> m;     while (a > 1) {       m[spf[a]]++;       a /= spf[a];     }     return m;   }   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long inverse(long long a, long long p) { return power(a, p - 2, p); }   long long ncr(long long n, long long r, long long p) {     if (r == 0) return 1;     return (fac[n] * inverse(fac[r], p) % p * inverse(fac[n - r], p) % p) % p;   }   long long seg[500000];   void update(long long v, long long l, long long r, long long pos,               long long val) {     if (l == r) {       seg[v] = val;       return;     }     long long mid = (l + r) / 2;     if (pos <= mid)       update(v * 2, l, mid, pos, val);     else       update(v * 2 + 1, mid + 1, r, pos, val);     seg[v] = max(seg[v * 2], seg[v * 2 + 1]);   }   long long query(long long v, long long l, long long r, long long posl,                   long long posr) {     if (l >= posl && r <= posr)       return seg[v];     else if (l > posr || r < posl)       return 0;     long long mid = (l + r) / 2;     return max(query(v * 2, l, mid, posl, posr),                query(v * 2 + 1, mid + 1, r, posl, posr));   }   void solve() {     long long n, temp = 0;     cin >> n;     vector<pair<pair<long long, long long>, long long> > v(n);     memset(seg, 0, sizeof(seg));     long long dp[n];     memset(dp, 0, sizeof(dp));     for (long long i = 0; i < n; i++) {       cin >> v[i].first.first;       cin >> v[i].first.second;       v[i].second = i;       v[i].first.second *= -1;     }     long long p;     sort(v.begin(), v.end());     vector<long long> v1(n);     for (long long i = 0; i < n; i++) v1[i] = v[i].first.first;     for (long long i = n - 1; i >= 0; i--) {       p = v[i].first.first - v[i].first.second - 1;       long long t = upper_bound(v1.begin(), v1.end(), p) - v1.begin();       long long ss = query(1, 1, n, i + 1, t);       if (ss == 0) ss = i + 1;       dp[v[i].second] = ss - i;       update(1, 1, n, i + 1, ss);     }     for (long long i = 0; i < n; i++) {       cout << dp[i] <<    ;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int NAX = 2e5 + 5, MOD = 1000000007;   struct Solution {     Solution() {}     void solveCase() {       set<string> ss;       for (size_t i = 0; i <= 100; i += 4) {         auto I = to_string(i);         ss.insert(I);         if (i < 10) {           I =  0  + I;           ss.insert(I);         }       }       string str;       cin >> str;       char prev =   0 ;       ll res = 0;       ;       for (size_t i = 0; i < str.size(); i++) {         string curr =   ;         curr += str[i];         if (ss.count(curr)) res++;         if (i > 0) {           curr = prev + curr;           if (ss.count(curr)) res += i;         };         prev = str[i];       }       cout << res <<   n ;     }   };   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t = 1;     Solution mySolver;     for (int i = 1; i <= t; ++i) {       mySolver.solveCase();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp[(1 << 22)], a[1000000];   int main() {     int N;     while (scanf( %d , &N) != EOF) {       memset(dp, -1, sizeof(dp));       for (int i = int(0); i < int(N); i++) {         scanf( %d , a + i);         dp[a[i]] = a[i];       }       for (int i = int(0); i < int(22); i++) {         for (int j = int(0); j < int((1 << 22)); j++) {           if (~dp[j]) dp[j | 1 << i] = dp[j];         }       }       for (int i = int(0); i < int(N); i++) {         printf( %d%c , dp[~a[i] & (1 << 22) - 1],    n [i == N - 1]);       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:200000000 )   using namespace std;   template <typename T>   inline T Abs(T x) {     return (x >= 0) ? x : -x;   }   template <typename T>   inline T sqr(T x) {     return x * x;   }   template <typename T>   string toStr(T x) {     stringstream st;     st << x;     string s;     st >> s;     return s;   }   inline int nextInt() {     int x;     if (scanf( %d , &x) != 1) throw;     return x;   }   inline long long nextInt64() {     long long x;     if (scanf( %I64d , &x) != 1) throw;     return x;   }   inline double nextDouble() {     double x;     if (scanf( %lf , &x) != 1) throw;     return x;   }   const int INF = (int)1E9;   const long long INF64 = (long long)1E18;   const long double EPS = 1E-9;   const long double PI = 3.1415926535897932384626433832795;   const int MAXN = 3000100;   int n, a[MAXN], l[MAXN], r[MAXN];   int tree[MAXN];   int get(int x) {     int ans = 0;     if (x < 0) return ans;     for (; x >= 0; x = (x & (x + 1)) - 1) ans += tree[x];     return ans;   }   int get(int l, int r) {     int ans = get(r);     if (l > 0) ans -= get(l - 1);     return ans;   }   void update(int x, int value) {     for (; x < 3 * n; x = (x | (x + 1))) tree[x] += value;   }   int main() {     n = nextInt();     for (int i = 0; i < (int)(n); i++) a[i + n] = a[i + 2 * n] = a[i] = nextInt();     int n1 = n / 2, n2 = n - n1;     vector<pair<int, int> > st;     for (int i = 0; i < (int)(3 * n); i++) {       while (!st.empty() && st.back().first <= a[i]) st.pop_back();       if (st.empty())         l[i] = i - n1 + 1;       else         l[i] = st.back().second;       st.push_back(make_pair(a[i], i));     }     st.clear();     for (int i = (int)(3 * n) - 1; i >= 0; i--) {       while (!st.empty() && st.back().first <= a[i]) st.pop_back();       if (st.empty())         r[i] = i + n2;       else         r[i] = st.back().second;       st.push_back(make_pair(a[i], i));     }     st.clear();     for (int i = 0; i < (int)(n); i++) {       update(i, +1);       update(i + n, +1);       update(i + 2 * n, +1);       st.push_back(make_pair(a[i], i));     }     long long ans = 0;     sort((st).begin(), (st).end());     for (int i = 0; i < (int)(n); i++) {       int x = st[i].second;       int ll = l[x + n], rr = r[x + n];       if ((ll % n) == (rr % n)) ll++;       update(x, -1);       update(x + n, -1);       update(x + 2 * n, -1);       ans += get(ll, rr);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return f * x;   }   inline void chmax(int &x, int y) { x = max(x, y); }   inline void chmin(int &x, int y) { x = min(x, y); }   inline void pls(int &x, int y, int Mod) {     x = (x + y >= Mod) ? (x + y - Mod) : (x + y);   }   inline void red(int &x, int y, int Mod) {     x = (x - y < 0) ? (x - y + Mod) : (x - y);   }   const int MAXN = 200005;   int n, m;   vector<int> G[MAXN];   int fa[MAXN];   inline int find(int x) {     if (fa[x] == x) return x;     return fa[x] = find(fa[x]);   }   pair<int, int> lk[MAXN];   inline void del(int x) {     lk[lk[x].first].second = lk[x].second;     lk[lk[x].second].first = lk[x].first;   }   bool vis1[MAXN], vis2[MAXN];   int cnt[MAXN];   signed main() {     n = read(), m = read();     for (int i = 1; i <= m; i++) {       int x = read(), y = read();       G[x].push_back(y);       G[y].push_back(x);     }     for (int i = 1; i <= n; i++) {       fa[i] = i;       lk[i - 1].second = i;       lk[i].first = i - 1;     }     queue<int> q;     while (lk[0].second) {       int now = lk[0].second;       del(now);       q.push(now);       while (!q.empty()) {         int p = q.front();         q.pop();         vis1[p] = true;         for (int i : G[p])           if (!vis1[i]) vis2[i] = true;         int cur = lk[0].second;         while (cur) {           if (!vis2[cur]) {             fa[find(cur)] = find(p);             del(cur);             q.push(cur);           }           cur = lk[cur].second;         }         for (int i : G[p]) vis2[i] = false;       }     }     vector<int> ans;     memset(vis1, false, sizeof(vis1));     for (int i = 1; i <= n; i++) cnt[find(i)]++;     for (int i = 1; i <= n; i++)       if (cnt[i]) ans.push_back(cnt[i]);     sort(ans.begin(), ans.end());     cout << (int)ans.size() << endl;     for (int i : ans) cout << i <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int k[3];     scanf( %d%d%d , k, k + 1, k + 2);     sort(k, k + 3);     if (k[0] == 1)       printf( YES n );     else if (k[0] == 2) {       if (k[1] == 2)         printf( YES n );       else if (k[1] == 4 && k[2] == 4)         printf( YES n );       else         printf( NO n );     } else if (k[0] == 3 && k[1] == 3 && k[2] == 3)       printf( YES n );     else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char c[51];     int n;     scanf( %s , c);     scanf( %d , &n);     for (int i = 0; i < strlen(c); i++) {       if (c[i] <  a ) c[i] +=  a  -  A ;       if (c[i] < 97 + n) c[i] +=  A  -  a ;     }     printf( %s , c);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int h, m;     scanf( %d:%d , &h, &m);     double dm = (m) / 60.0, dh = (h % 12 + dm) / 12;     cout << 360 * (dh) <<     << 360 * (dm) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1005], b[1005];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     for (int i = 0; i < n; i++) {       scanf( %d , &b[i]);     }     int ans = 0;     for (int i = 0; i < n; i++) {       int p = 0;       int q = 0;       for (int j = i; j < n; j++) {         p |= a[j];         q |= b[j];         ans = max(ans, p + q);       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const long long inf = LLONG_MAX;   void IO() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cout.setf(ios::fixed);     srand(chrono::high_resolution_clock::now().time_since_epoch().count());   }   long long pw(long long x, long long y, long long p = inf) {     long long res = 1;     x = x % p;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long invmod(long long a, long long m) { return pw(a, m - 2, m); }   long long cl(long long a, long long x) {     return a % x == 0 ? a / x : a / x + 1;   }   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   void run_time_terror() {     long long n;     cin >> n;     cout <<  ? 1 3  << endl;     long long a, b;     cin >> a;     vector<long long> ans(n);     cout <<  ? 2 3  << endl;     cin >> b;     ans[0] = a - b;     for (long long i = 0; i < n - 1; ++i) {       long long x;       if (i == 1) {         x = b;       } else {         cout <<  ?   << i + 1 <<     << i + 2 << endl;         cin >> x;       }       ans[i + 1] = x - ans[i];     }     cout <<  !  ;     for (long long i = 0; i < n; ++i) {       cout << ans[i] <<    ;     }   }   int32_t main() {     cout << setprecision(0);     long long tt = 1;     for (long long case_no = 1; case_no <= tt; case_no++) {       run_time_terror();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int i, cnt = 0, p = 0, n;     cin >> n;     cin >> s;     for (i = 0; i < n; i++)       if (s[i] ==  0 )         cnt++;       else         p++;     if (p > 0) {       cout << 1;       for (i = 0; i < cnt; i++) cout << 0;       cout << endl;     } else       cout << 0 << endl;   }


#include <bits/stdc++.h>   const long long int MOD = 1e9 + 7;   int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};   int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1};   int dx4[] = {0, 0, 1, -1};   int dy4[] = {1, -1, 0, 0};   using namespace std;   void vok() {     ios_base::sync_with_stdio(false);     cout.tie(NULL);     cin.tie(NULL);   }   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long int lcm(long long int a, long long int b) {     return ((a * b) / gcd(a, b));   }   vector<long long int> pp;   void gen() {     vector<bool> prime(33000, true);     prime[0] = prime[1] = false;     for (int p = 0; p * p <= 33000; p++) {       if (prime[p]) {         for (int i = p * p; i <= 33000; i += p) prime[i] = false;       }     }     for (int i = 0; i < 33000; i++)       if (prime[i]) pp.push_back(i);   }   long long int find(vector<int>& A, int n) {}   void solve() {     long long int n, m, x, y, a, b, k;     a = b = x = y = k = 0;     long long int ans = 0, res = 0;     string s1, s2;     cin >> s1 >> s2;     n = s1.size();     if (s1 == s2) {       cout <<  YES  << endl;       return;     }     if (n == 1 and s1 != s2) {       cout <<  NO  << endl;       return;     }     int dp[26]{0};     for (int i = 0; i < n; i++) {       dp[s1[i] -  a ]++;     }     for (int i = 0; i < n; i++) {       if (dp[s2[i] -  a ] >= 1) {         cout <<  YES  << endl;         return;       }     }     cout <<  NO  << endl;   }   int main() {     vok();     int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005, M = 50005;   const int inf = 0x3f3f3f3f;   const long long INF = 1000000000000000000ll;   const long long mod = 998244353;   const double pi = acos(-1.0);   const double eps = 1e-6;   vector<int> rec;   struct OP {     char str[4];     int num;     void get() {       scanf( %s , str);       if (str[0] ==  a  || str[0] ==  d ) {         scanf( %d , &num);       }     }   } op[N];   struct node {     int l, r, cnt;     long long num[5];     int nt;     void init() {       memset(num, 0, sizeof(num));       cnt = 0;     }     node() {}     node(int l, int r, int nt) {       this->l = l;       this->r = r;       this->nt = nt;     }     void Equal(node tmp) {       for (int i = 0; i < 5; i++) {         num[i] = tmp.num[i];       }       nt = tmp.nt;       cnt = tmp.cnt;     }   };   struct segTree {     node tree[N * 4];     void build(int l, int r, int id) {       tree[id] = node(l, r, 1);       tree[id].init();       if (l == r) return;       int mid = ((l + r) >> 1);       build(l, mid, (id << 1));       build(mid + 1, r, (id << 1 | 1));     }     void pushUp(int id) {       tree[id].Equal(tree[(id << 1)]);       int nt = tree[(id << 1)].nt;       for (int i = 1, j = nt, cnt = 1; cnt <= 5;            i = (i + 1) % 5, j = (j + 1) % 5, cnt++) {         if (tree[(id << 1 | 1)].num[i] == 0) break;         tree[id].num[j] += tree[(id << 1 | 1)].num[i];       }       tree[id].cnt += tree[(id << 1 | 1)].cnt;       tree[id].nt = (tree[id].nt + tree[(id << 1 | 1)].cnt) % 5;     }     void update(int id, int pos, int val) {       int l = tree[id].l, r = tree[id].r;       if (l == r) {         tree[id].num[1] += val;         if (val > 0)           tree[id].nt++, tree[id].cnt++;         else           tree[id].nt--, tree[id].cnt--;         return;       }       int mid = ((l + r) >> 1);       if (pos <= mid)         update((id << 1), pos, val);       else         update((id << 1 | 1), pos, val);       pushUp(id);     }   } segT;   map<int, int> mp;   void discre() {     sort(rec.begin(), rec.end());     int siz = rec.size();     for (int i = 0; i < siz; i++) {       mp.insert(pair<int, int>(rec[i], i));     }   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       op[i].get();       if (op[i].str[0] ==  a ) rec.push_back(op[i].num);     }     discre();     if (rec.size() == 0) {       printf( 0 n );       return 0;     }     segT.build(0, rec.size() - 1, 1);     for (int i = 1; i <= n; i++) {       if (op[i].str[0] ==  a ) {         segT.update(1, mp[op[i].num], op[i].num);       } else if (op[i].str[0] ==  d ) {         segT.update(1, mp[op[i].num], -op[i].num);       } else {         printf( %lld n , segT.tree[1].num[3]);       }     }   }


#include <bits/stdc++.h>   using namespace std;   namespace io {   void _(int &k) {     char c;     int e = 1;     k = 0;     while ((c = getchar()) >  9  || c <  0 )       if (c ==  - ) e = -1;     k = c -  0 ;     while ((c = getchar()) <=  9  && c >=  0 ) {       k *= 10;       k += c -  0 ;     }     k *= e;   }   void _(long long &k) {     char c;     int e = 1;     k = 0;     while ((c = getchar()) >  9  || c <  0 )       if (c ==  - ) e = -1;     k = c -  0 ;     while ((c = getchar()) <=  9  && c >=  0 ) {       k *= 10;       k += c -  0 ;     }     k *= e;   }   void _(char &c) {     while ((c = getchar()) ==     || c ==   n )       ;   }   void _(double &c) { scanf( %lf , &c); }   void _(char *s) {     char c;     while ((c = getchar()) != EOF && c !=     && c != 10) *s++ = c;   }   template <class t1, class t2>   void _(t1 &a, t2 &b) {     _(a);     _(b);   }   template <class t1, class t2, class t3>   void _(t1 &a, t2 &b, t3 &c) {     _(a);     _(b);     _(c);   }   template <class t1, class t2, class t3, class t4>   void _(t1 &a, t2 &b, t3 &c, t4 &d) {     _(a);     _(b);     _(c);     _(d);   }   template <class t1, class t2, class t3, class t4, class t5>   void _(t1 &a, t2 &b, t3 &c, t4 &d, t5 &e) {     _(a);     _(b);     _(c);     _(d);     _(e);   }   void _p(double k) { printf( %.6lf , k); }   void _p(char *c) {     for (; *c; putchar(*c++))       ;   }   void _p(const char *c) {     for (; *c; putchar(*c++))       ;   }   void _p(char c) { putchar(c); }   template <class T>   void _p0(T k) {     if (k >= 10) _p0(k / 10);     putchar(k % 10 +  0 );   }   template <class T>   void _p(T k) {     if (k < 0) {       putchar( - );       _p0(-k);     } else       _p0(k);   }   template <class T>   void __p(T k) {     _p(k);     putchar(   );   }   template <class T>   void _pn(T k) {     _p(k);     putchar(  n );   }   template <class t1, class t2>   void _p(t1 a, t2 b) {     __p(a);     _pn(b);   }   template <class t1, class t2, class t3>   void _p(t1 a, t2 b, t3 c) {     __p(a);     __p(b);     _pn(c);   }   template <class t1, class t2, class t3, class t4>   void _p(t1 a, t2 b, t3 c, t4 d) {     __p(a);     __p(b);     __p(c);     _pn(d);   }   template <class T>   void op(T *a, int n) {     int i;     n--;     for (i = 1; i <= n; i++) __p(a[i]);     _pn(a[n + 1]);   }   int gi() {     int first;     _(first);     return first;   }   long long gll() {     long long first;     _(first);     return first;   }   }  // namespace io   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   void fcl() {     fclose(stdin);     fclose(stdout);   }   void fop(const char *s) {     char c[256], d[256];     memset(c, 0, sizeof(c));     memset(d, 0, sizeof(d));     strcpy(c, s);     strcpy(d, s);     freopen(strcat(c,  .in ),  r , stdin);     freopen(strcat(d,  .out ),  w , stdout);   }   int eq(double a, double b) {     return a + 0.00000000001 >= b && b + 0.00000000001 >= a;   }   template <class T>   void _ma(T &a, T b) {     if (a < b) a = b;   }   template <class T>   void _mi(T &a, T b) {     if (a > b) a = b;   }   const int N = 1234567, EE = 100000000, GG = 1000000000, ima = 2147483647;   using namespace io;   int n, m, a[N], f[N], an, T;   char s[555][555];   int main() {     int i, j, a1, a2;     _(n);     for (i = 1; i <= n; i++)       for (j = 1; j <= n; j++) _(s[i][j]);     for (i = 1; i <= n; i++)       for (j = 1; j <= n; j++)         an += s[i][j] ==  X  && s[i + 1][j + 1] ==  X  &&               s[i + 1][j - 1] ==  X  && s[i - 1][j + 1] ==  X  &&               s[i - 1][j - 1] ==  X ;     _pn(an);   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 100010;   long long n, a[N];   double bit[N];   inline void add(long long x, double val) {     for (; x <= n; x += x & -x) bit[x] += val;   }   inline double ask(long long x) {     double sum = 0;     for (; x; x -= x & -x) sum += bit[x];     return sum;   }   int main() {     scanf( %lld , &n);     double tt = 0.0;     for (long long i = 1; i <= n; i++) {       scanf( %lld , a + i);       tt += (ask(n) - ask(a[i]));       add(a[i], 1.0);     }     double ans = 0.0;     for (long long i = 1; i <= n; i++) {       ans += (0.25 * i * (i - 1) + tt) * (n - i + 1);     }     memset(bit, 0, sizeof(bit));     double cur = 0.0;     for (long long i = 1; i <= n; i++) {       double tmp = ask(n) - ask(a[i]) + cur;       ans -= tmp;       add(a[i], i);       cur = tmp;     }     ans = ans / n / (n + 1) * 2.0;     printf( %.12lf n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int mas[100][100], n, used[100], p = 0, s = 0, to;   vector<vector<int> > g;   void dfs(int from) {     used[from] = 1;     for (int i = 0; i < 2; i++) {       to = g[from][i];       if (!used[to]) {         p += mas[from][to];         dfs(to);       }     }   }   int main() {     cin >> n;     g.resize(n);     for (int i = 0; i < n; i++) {       int a, b, c;       cin >> a >> b >> c;       g[a - 1].push_back(b - 1);       g[b - 1].push_back(a - 1);       mas[a - 1][b - 1] = c;       s += c;     }     dfs(0);     p += mas[to][0];     cout << min(p, s - p) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int insig;   void Out(vector<long long int> x) {     for (long long int i = 0; i < x.size(); i++) {       cout << x[i] <<    ;     }     cout << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int N;     cin >> N;     vector<pair<long long int, long long int> > p;     long long int c1, c2;     for (long long int i = 0; i < N; i++) {       cin >> c1 >> c2;       p.push_back(make_pair(c1, c2));     }     long long int ans =         (long long int)(N * (N - 1LL) * (N - 2LL) * (N - 3LL) * (N - 4LL)) /         120LL;     ans *= 5;     long long int l;     long long int a = 1;     long long int b = -1;     long double val;     for (long long int i = 0; i < N; i++) {       long long int x = p[i].first;       long long int y = p[i].second;       vector<long double> t1, t2, t3, t4, t5, t6, t7, t8;       long double val;       for (long long int j = 0; j < N; j++) {         if (j == i) {           continue;         }         if (p[j].first != x) {           val = (long double)(((long double)(p[j].second - y)) /                               ((long double)(p[j].first - x)));         }         if (p[j].first == x && p[j].second > y) {           t6.push_back(0);         } else if (p[j].first == x && p[j].second < y) {           t8.push_back(0);         } else if (p[j].first > x && p[j].second == y) {           t5.push_back(val);         } else if (p[j].first < x && p[j].second == y) {           t7.push_back(val);         } else if (p[j].first > x && p[j].second > y) {           t1.push_back(val);         } else if (p[j].first > x && p[j].second < y) {           t4.push_back(-val);         } else if (p[j].first < x && p[j].second > y) {           t2.push_back(-val);         } else if (p[j].first < x && p[j].second < y) {           t3.push_back(val);         }       }       sort(t1.begin(), t1.end());       sort(t2.begin(), t2.end());       sort(t3.begin(), t3.end());       sort(t4.begin(), t4.end());       for (long long int j = 0; j < t1.size(); j++) {         l = (j + t5.size() + t4.size() + t8.size() +              (long long int)(t3.end() -                              lower_bound(t3.begin(), t3.end(), t1[j])));         ans -= (long long int)(l * (l - 1LL) * (l - 2LL)) / 6LL;       }       for (long long int j = 0; j < t2.size(); j++) {         l = (t2.size() - j - 1 + t6.size() + t1.size() + t5.size() +              (long long int)(lower_bound(t4.begin(), t4.end(), t2[j]) -                              t4.begin()));         ans -= (long long int)(l * (l - 1LL) * (l - 2LL)) / 6LL;       }       for (long long int j = 0; j < t3.size(); j++) {         l = (j + t7.size() + t2.size() + t6.size() +              (long long int)(t1.end() -                              lower_bound(t1.begin(), t1.end(), t3[j])));         ans -= (long long int)(l * (l - 1LL) * (l - 2LL)) / 6LL;       }       for (long long int j = 0; j < t4.size(); j++) {         l = (t4.size() - j - 1 + t8.size() + t3.size() + t7.size() +              (long long int)(lower_bound(t2.begin(), t2.end(), t4[j]) -                              t2.begin()));         ans -= (long long int)(l * (l - 1LL) * (l - 2LL)) / 6LL;       }       if (t5.size() == 1) {         l = (t4.size() + t8.size() + t3.size());         ans -= (long long int)(l * (l - 1LL) * (l - 2LL)) / 6LL;       }       if (t6.size() == 1) {         l = (t1.size() + t5.size() + t4.size());         ans -= (long long int)(l * (l - 1LL) * (l - 2LL)) / 6LL;       }       if (t7.size() == 1) {         l = (t2.size() + t6.size() + t1.size());         ans -= (long long int)(l * (l - 1LL) * (l - 2LL)) / 6LL;       }       if (t8.size() == 1) {         l = (t3.size() + t7.size() + t2.size());         ans -= (long long int)(l * (l - 1LL) * (l - 2LL)) / 6LL;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e5 + 10;   const long long INF = (long long)1e9;   struct Point {     long long x, y;     Point() : x(), y() {}     void scan() { scanf( %lld%lld , &x, &y); }     bool operator<(const Point &a) const {       return y < a.y || (y == a.y && x < a.x);     }   };   long long sqr(long long a) { return a * a; }   Point p[N];   long long prefMinX[N], prefMaxX[N];   long long suffMinX[N], suffMaxX[N];   int n;   void precalc() {     for (int i = 0; i < n; i++) {       prefMinX[i] = (i == 0 ? p[i].x : min(prefMinX[i - 1], p[i].x));       prefMaxX[i] = (i == 0 ? p[i].x : max(prefMaxX[i - 1], p[i].x));     }     for (int i = n - 1; i >= 0; i--) {       suffMinX[i] = (i == n - 1 ? p[i].x : min(suffMinX[i + 1], p[i].x));       suffMaxX[i] = (i == n - 1 ? p[i].x : max(suffMaxX[i + 1], p[i].x));     }   }   long long getMaxD(long long y1, long long y2, long long x1, long long x2) {     long long d = max(sqr(y1 - y2), sqr(x1 - x2));     d = max(d, max(sqr(y1), sqr(y2)) + max(sqr(x1), sqr(x2)));     return d;   }   bool check(long long d) {     long long xD = sqr(prefMinX[n - 1] - prefMaxX[n - 1]);     if (xD <= d) return true;     int it = 0;     int kek = n;     42;     for (int i = 0; i < n; i++) 42;     42;     for (int i = 0; i < n; i++) {       if (i != 0 && p[i].y == p[i - 1].y) continue;       while (it < n && (it <= i || (sqr(p[it].y - p[i].y) <= d))) it++;       while (kek > 0 && llabs(p[kek - 1].y) > llabs(p[i].y)) kek--;       int cur = min(kek, it);       42;       if (cur < i) break;       long long y1 = p[i].y;       long long y2 = p[cur - 1].y;       if (i == 0 && cur == n) return true;       long long x1, x2;       if (i == 0) {         x1 = suffMinX[cur];         x2 = suffMaxX[cur];       } else if (cur == n) {         x1 = prefMinX[i - 1];         x2 = prefMaxX[i - 1];       } else {         x1 = min(suffMinX[cur], prefMinX[i - 1]);         x2 = max(suffMaxX[cur], prefMaxX[i - 1]);       }       long long curD = getMaxD(y1, y2, x1, x2);       if (curD <= d) return true;     }     it = n - 1;     kek = -1;     42;     for (int i = n - 1; i >= 0; i--) {       if (i != n - 1 && p[i].y == p[i + 1].y) continue;       while (it >= 0 && (it >= i || (sqr(p[it].y - p[i].y) <= d))) it--;       while (kek<n - 1 & llabs(p[kek + 1].y)> llabs(p[i].y)) kek++;       int cur = max(kek, it);       42;       if (cur > i) break;       long long y1 = p[i].y;       long long y2 = p[cur + 1].y;       if (i == n - 1 && cur == -1) return true;       long long x1, x2;       if (i == n - 1) {         x1 = prefMinX[cur];         x2 = prefMaxX[cur];       } else if (cur == -1) {         x1 = suffMinX[i + 1];         x2 = suffMaxX[i + 1];       } else {         x1 = min(prefMinX[cur], suffMinX[i + 1]);         x2 = max(prefMaxX[cur], suffMaxX[i + 1]);       }       long long curD = getMaxD(y1, y2, x1, x2);       if (curD <= d) return true;     }     return false;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       p[i].scan();     }     sort(p, p + n);     precalc();     long long l = -1, r = (long long)1e18;     while (r - l > 1) {       long long mid = (l + r) / 2;       if (check(mid))         r = mid;       else         l = mid;     }     printf( %lld n , r);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( avx2 )   #pragma GCC optimize( unroll-loops )   using namespace std;   const long long MN = 3005;   long long a[2], b[2], c[2], d[8], first[8], ra[2], rb[2], rc[2];   inline bool check(long long f3, long long f5, long long f6) {     for (long long i = 0; i < 2; i++) ra[i] = a[i], rb[i] = b[i], rc[i] = c[i];     ra[0] -= f5 + f6, rb[0] -= f3 + f6, rc[0] -= f3 + f5;     if (ra[0] < 0 || rb[0] < 0 || rc[0] < 0) return 0;     memset(first, 0, sizeof(first));     first[3] = f3, first[5] = f5, first[6] = f6;     first[7] = min({d[7], ra[0], rb[0], rc[0]});     ra[0] -= first[7], rb[0] -= first[7], rc[0] -= first[7];     first[4] = min(d[4], ra[0]);     first[2] = min(d[2], rb[0]);     first[1] = min(d[1], rc[0]);     long long sa = 0, sb = 0, sc = 0;     for (long long i = 1; i <= 7; i++) {       long long second = d[i] - first[i];       if (i & 1) sc += second;       if (i & 2) sb += second;       if (i & 4) sa += second;     }     if (sa > a[1] || sb > b[1] || sc > c[1]) return 0;     for (long long i = 7; i >= 1; i--) printf( %lld  , first[i]);     printf(  n );     return 1;   }   int32_t main() {     cin.tie(0), cin.sync_with_stdio(0);     long long t;     cin >> t;   outer:     while (t--) {       cin >> a[0] >> b[0] >> c[0] >> a[1] >> b[1] >> c[1];       for (long long i = 1; i <= 7; i++) cin >> d[8 - i];       long long tota = 0, totb = 0, totc = 0;       for (long long i = 1; i <= 7; i++) {         if (i & 1) totc += d[i];         if (i & 2) totb += d[i];         if (i & 4) tota += d[i];       }       if (tota > a[0] + a[1] || totb > b[0] + b[1] || totc > c[0] + c[1]) {         printf( -1 n );         continue;       }       for (long long i = 0; i <= d[3]; i++) {         for (long long j = 0; j <= d[5]; j++) {           for (long long k = 0; k <= d[6]; k++) {             if (check(i, j, k)) goto outer;           }         }       }       printf( -1 n );     }     return 0;   }


#include <bits/stdc++.h>   using std::sort;   int n;   char s[100000 + 1];   struct SH {     unsigned int s, h;   };   struct SH cnt[100000 + 1];   unsigned long long ans;   void read() {     scanf( %d , &n);     ans = 0;     for (int i = 1; i <= n; ++i) {       scanf( %s , s);       int l = strlen(s);       unsigned int sum = 0;       for (int j = 0; j < l; ++j)         if (s[j] ==  s )           ++sum;         else           ans += sum;       cnt[i].s = sum;       cnt[i].h = l - sum;     }   }   bool compareSH(struct SH &x, struct SH &y) { return x.s * y.h > y.s * x.h; }   void chief() {     sort(&cnt[1], &cnt[n] + 1, compareSH);     unsigned int sum = 0;     for (int i = 1; i <= n; ++i) {       ans += (unsigned long long)sum * cnt[i].h;       sum += cnt[i].s;     }   }   void write() { printf( %I64u n , ans); }   int main() {     read();     chief();     write();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Data {     long long l, r;   } a[200100];   long long n, s, rmax, lmin;   void Docfile() {     scanf( %lld%lld , &n, &s);     rmax = 0;     lmin = 1e18;     for (int i = 1; i <= n; i++) {       scanf( %lld%lld , &a[i].l, &a[i].r);       rmax = max(rmax, a[i].r);       lmin = min(lmin, a[i].l);     }   }   bool cmp(Data &a, Data &b) {     return ((a.l < b.l) || ((a.l == b.l) && (a.r < b.r)));   }   void Xuli() {     sort(a + 1, a + 1 + n, cmp);     long long sum1, sum2, dem1, dem2, dem3, F[200100];     long long d = lmin, c = rmax, g, kq = 0;     while (d <= c) {       g = (d + c) / 2;       dem1 = dem2 = dem3 = sum1 = sum2 = 0;       F[0] = 0;       for (int i = 1; i <= n; i++) {         if (a[i].r < g) {           dem1++;           sum1 += a[i].l;         } else {           if (a[i].l > g) {             dem2++;             sum2 += a[i].l;           } else {             dem3++;             F[dem3] = F[dem3 - 1] + a[i].l;           }         }       }       if (dem1 > n / 2) {         c = g - 1;         continue;       }       if (dem2 > n / 2) {         d = g + 1;         continue;       }       if (dem1 < n / 2) sum1 += F[n / 2 - dem1];       if (dem2 < n / 2) sum2 += g * (n / 2 - dem2);       if (sum1 + sum2 + g <= s) {         kq = max(kq, g);         d = g + 1;       } else         c = g - 1;     }     printf( %lld n , kq);   }   int main() {     long t;     scanf( %d , &t);     for (int i = 1; i <= t; i++) {       Docfile();       Xuli();     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   int size(T& a) {     return (int)a.size();   }   template <typename T>   T sqr(T a) {     return a * a;   }   #pragma comment(linker,  /STACK:60777216 )   const int INF = int(1e9);   char s[10][10];   bool can(int i, int j) { return i >= 0 && i < 8 && j >= 0 && j < 8; }   bool statue(int i, int j, int t) {     for (int u = 0; u < 8; ++u) {       if (s[u][j] ==  S ) {         int dif = (i - u);         if (t == dif) {           return false;         }       }     }     return true;   }   struct pos {     int i, j, t;     pos() {}     pos(int i, int j, int t) : i(i), j(j), t(t) {}   };   int dist[8][8][200];   int dj[9] = {+1, +1, 0, -1, -1, -1, 0, 1, 0};   int di[9] = {0, +1, +1, +1, 0, -1, -1, -1, 0};   int main() {     queue<pos> q;     for (int i = (0); i < (8); ++i) gets(s[i]);     memset((dist), (255), sizeof(dist));     for (int i = (0); i < (8); ++i)       for (int j = (0); j < (8); ++j)         if (s[i][j] ==  M ) {           q.push(pos(i, j, 0));           dist[i][j][0] = 0;         }     while (size(q)) {       pos p = q.front();       q.pop();       if (s[p.i][p.j] ==  A ) {         cout <<  WIN ;         exit(0);       }       for (int u = (0); u < (9); ++u) {         int ni = p.i + di[u];         int nj = p.j + dj[u];         if (can(ni, nj) && statue(ni, nj, p.t) && statue(ni, nj, p.t + 1) &&             dist[ni][nj][p.t + 1] == -1) {           dist[ni][nj][p.t + 1] = 1;           q.push(pos(ni, nj, p.t + 1));         }       }     }     for (int i = (0); i < (8); ++i)       for (int j = (0); j < (8); ++j)         if (s[i][j] ==  A ) {           for (int t = (0); t < (200); ++t)             if (dist[i][j][t] != -1) {               cout <<  WIN ;               exit(0);             }         }     cout <<  LOSE ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int dot = -1;     for (int i = 0; i < (int)(s).size(); ++i) {       if (s[i] ==  . ) {         dot = i;       }     }     int deg = 0;     if (dot == -1) {       deg = (int)(s).size();       string t =  0.  + s;       s = t;     } else {       deg = dot;       string t =  0. ;       for (int i = 0; i < (int)(s).size(); ++i) {         if (s[i] !=  . ) {           t += s[i];         }       }       s = t;     }     int lst = (int)(s).size() - 1;     while (s[lst] ==  0 ) {       --lst;     }     s = s.substr(0, lst + 1);     if (s ==  0. ) {       cout <<  0 n ;       return 0;     }     int fst = 2;     while (s[fst] ==  0 ) {       ++fst;     }     s = s.substr(fst);     deg -= fst - 1;     cout << s[0];     if ((int)(s).size() > 1) {       cout <<  . ;       for (int i = 1; i < (int)(s).size(); ++i) {         cout << s[i];       }     }     if (deg) {       cout <<  E  << deg;     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   namespace node_tre {   int tre[100005] = {};   void update(int x, int val) { tre[x] += val; }   int ask(int x) { return tre[x]; }   void cover(int x) { tre[x] = 0; }   };  // namespace node_tre   using namespace node_tre;   struct node {     int ty;     int id;     int tim;     int val;     int w;   } a[100005], b[100005];   int n;   int ans[100005];   int cnt;   map<int, int> has;   void cdq(int l, int r) {     if (r == l) return;     int mid = (l + r) >> 1;     cdq(l, mid);     cdq(mid + 1, r);     int indl = l, indr = mid + 1, indb = l;     while (indl <= mid && indr <= r) {       if (a[indl].tim <= a[indr].tim) {         if (a[indl].ty == 1) update(a[indl].val, a[indl].w);         b[indb++] = a[indl++];       } else {         if (a[indr].ty == 2) ans[a[indr].id] += ask(a[indr].val);         b[indb++] = a[indr++];       }     }     while (indl <= mid) b[indb++] = a[indl++];     while (indr <= r) {       if (a[indr].ty == 2) ans[a[indr].id] += ask(a[indr].val);       b[indb++] = a[indr++];     }     for (int i = l; i <= r; i++) {       a[i] = b[i];       cover(a[i].val);     }   }   int main() {     memset(ans, -1, sizeof(ans));     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i].ty >> a[i].tim >> a[i].val;       a[i].id = i;       if (a[i].ty == 1) {         a[i].w = 1;         continue;       }       if (a[i].ty == 2) {         a[i].ty = 1;         a[i].w = -1;         continue;       }       if (a[i].ty == 3) {         ans[i] = 0;         a[i].ty = 2;         continue;       }     }     for (int i = 1; i <= n; i++) {       if (has[a[i].val] == 0) has[a[i].val] = ++cnt;       a[i].val = has[a[i].val];     }     cdq(1, n);     for (int i = 1; i <= n; i++)       if (ans[i] != -1) cout << ans[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   int main() {     int m, n, i, j, c;     int coordenadas[3][2];     scanf( %d%d , &n, &m);     char ciudad[n][m];     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         scanf(  n%c , &ciudad[i][j]);       }     }     c = 0;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         if (ciudad[i][j] ==  * ) {           coordenadas[c][0] = i;           coordenadas[c][1] = j;           c++;         }       }     }     if (coordenadas[0][0] != coordenadas[1][0] &&         coordenadas[0][0] != coordenadas[2][0])       printf( %d , coordenadas[0][0] + 1);     else if (coordenadas[1][0] != coordenadas[0][0] &&              coordenadas[1][0] != coordenadas[2][0])       printf( %d , coordenadas[1][0] + 1);     else       printf( %d , coordenadas[2][0] + 1);     printf(   );     if (coordenadas[0][1] != coordenadas[1][1] &&         coordenadas[0][1] != coordenadas[2][1])       printf( %d , coordenadas[0][1] + 1);     else if (coordenadas[1][1] != coordenadas[0][1] &&              coordenadas[1][1] != coordenadas[2][1])       printf( %d , coordenadas[1][1] + 1);     else       printf( %d , coordenadas[2][1] + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, k;     cin >> n >> k;     string s;     cin >> s;     long long x = -1;     for (long long i = 97; i <= 122; ++i) {       char c = char(i);       long long cnt = 0;       for (long long i = 0; i < n; ++i) {         if (s[i] == c) {           long long c1 = 0;           while (s[i] == c && c1 < k && i < n) {             i++;             c1++;           }           if (c1 == k) {             cnt++;             i--;           }         }       }       x = max(x, cnt);     }     cout << x <<   n ;     return 0;   }


#include <bits/stdc++.h>   struct vertex {     long long x, y;     int adj[4], k;   } vv[30];   void dfs(int p, int v, long long x, long long y, long long a, int d) {     int i;     vv[v].x = x;     vv[v].y = y;     d = (d + 2) % 4;     for (i = 0; i < vv[v].k; i++)       if (vv[v].adj[i] != p) {         long long x_ = x, y_ = y;         d = (d + 1) % 4;         if (d == 0)           x_ += a;         else if (d == 1)           y_ += a;         else if (d == 2)           x_ -= a;         else           y_ -= a;         dfs(v, vv[v].adj[i], x_, y_, a / 2, d);       }   }   int main() {     int n, i, yes;     scanf( %d , &n);     yes = 1;     for (i = 0; i < n; i++) vv[i].k = 0;     for (i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       u--, v--;       if (vv[u].k == 4 || vv[v].k == 4) {         yes = 0;         break;       }       vv[u].adj[vv[u].k++] = v;       vv[v].adj[vv[v].k++] = u;     }     printf( %s n , yes ?  YES  :  NO );     if (yes) {       dfs(-1, 0, 0, 0, 1LL << n, 0);       for (i = 0; i < n; i++) printf( %lld %lld n , vv[i].x, vv[i].y);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int maxn = 300000 + 10;   int n, m, s;   struct edge {     bool t;     int u, v;   } es[maxn];   bool vis[maxn];   vector<int> G[maxn];   char ans[maxn];   int cnt;   void dfsmax(int u) {     vis[u] = true;     cnt++;     for (int i = 0; i < G[u].size(); i++) {       edge& e = es[G[u][i]];       if (e.t) {         if (e.u == u) {           if (!vis[e.v]) {             ans[G[u][i]] =  + ;             dfsmax(e.v);           }         } else {           if (!vis[e.u]) {             ans[G[u][i]] =  - ;             dfsmax(e.u);           }         }       } else {         if (!vis[e.v]) {           dfsmax(e.v);         }       }     }   }   void dfsmin(int u) {     vis[u] = true;     cnt++;     for (int i = 0; i < G[u].size(); i++) {       edge& e = es[G[u][i]];       if (e.t) {         if (e.u == u) {           ans[G[u][i]] =  - ;         } else {           ans[G[u][i]] =  + ;         }       } else if (!vis[e.v]) {         dfsmin(e.v);       }     }   }   int main() {     scanf( %d%d%d , &n, &m, &s);     int tmp;     for (int i = 0; i < m; i++) {       scanf( %d%d%d , &tmp, &es[i].u, &es[i].v);       G[es[i].u].push_back(i);       es[i].t = (tmp == 2);       if (tmp == 2) G[es[i].v].push_back(i), ans[i] =  + ;     }     cnt = 0;     dfsmax(s);     printf( %d n , cnt);     for (int i = 0; i < m; i++) {       if (es[i].t) printf( %c , ans[i]);     }     printf(  n );     cnt = 0;     memset(vis, 0, sizeof(vis));     dfsmin(s);     printf( %d n , cnt);     for (int i = 0; i < m; i++) {       if (es[i].t) printf( %c , ans[i]);     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   int c[maxn], up[maxn], h[maxn];   bool visited[maxn];   set<int> s[maxn];   vector<int> g[maxn];   void dfs(int v, int par = -1) {     c[v] = v;     visited[v] = 1;     up[v] = h[v];     int cnt = 0;     for (auto u : g[v]) {       if (u == par)         cnt++;       else if (!visited[u]) {         h[u] = h[v] + 1;         dfs(u, v);         up[v] = min(up[v], up[u]);         if (s[c[u]].size() > s[c[v]].size()) c[v] = c[u];       } else         up[v] = min(up[v], h[u]);     }     if (cnt > 1) up[v] = min(up[v], h[v] - 1);     for (auto u : g[v]) {       if (h[u] == h[v] + 1 and c[u] != c[v]) {         for (auto it : s[c[u]]) {           if (s[c[v]].find(-it) != s[c[v]].end())             s[c[v]].erase(-it);           else             s[c[v]].insert(it);         }         s[c[u]].clear();       }     }     if (c[v] != v) {       for (auto it : s[v]) {         if (s[c[v]].find(-it) != s[c[v]].end())           s[c[v]].erase(-it);         else           s[c[v]].insert(it);       }       s[v].clear();     }     if (up[v] < h[v]) return;     if (s[c[v]].empty()) return;     int minimum = *s[c[v]].begin();     auto it = s[c[v]].end();     it--;     int maximum = *it;     if (minimum < 0 and maximum > 0) {       cout <<  No  << endl;       exit(0);     }   }   int par[maxn];   int get_par(int v) {     if (par[v] < 0) return v;     return par[v] = get_par(par[v]);   }   void merge(int v, int u) {     v = get_par(v), u = get_par(u);     if (v == u) return;     par[v] = u;   }   int main() {     ios_base::sync_with_stdio(false);     memset(par, -1, sizeof par);     int n, m, q;     cin >> n >> m >> q;     for (int i = 0; i < m; i++) {       int v, u;       cin >> v >> u;       g[v].push_back(u);       g[u].push_back(v);       merge(v, u);     }     string answer =  Yes ;     for (int i = 0; i < q; i++) {       int v, u;       cin >> v >> u;       if (get_par(v) != get_par(u)) answer =  No ;       s[v].insert(i + 1);       s[u].insert(-i - 1);     }     if (answer ==  No ) return cout << answer << endl, 0;     for (int v = 1; v <= n; v++)       if (!visited[v]) dfs(v);     cout <<  Yes  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, tt[1005];   vector<int> a[1005];   void dfs(int u) {     if (tt[u] == 1) {       printf( %d  , u);       return;     }     tt[u] = 1;     for (int i = 0; i < a[u].size(); ++i) dfs(a[u][i]);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       int x;       scanf( %d , &x);       a[i].push_back(x);     }     for (int i = 1; i <= n; ++i) {       dfs(i);       for (int j = 1; j <= n; ++j) tt[j] = 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[1000005];   long long c[2000015];   long long n;   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     long long ma = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       c[a[i]]++;       ma = max(ma, a[i]);     }     long long ans = 0;     for (int i = 0; i < 2000010; i++) {       if (c[i] % 2 == 1) {         c[i + 1] += c[i] / 2;         c[i] = 1;       } else {         c[i + 1] += c[i] / 2;         c[i] = 0;       }     }     for (int i = 0; i < 2000010; i++) {       ans += c[i];     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ct[300005];   vector<pair<int, int> > val;   int n, m;   bool check(int vl) {     for (int i = 0; i < 300005; i++) ct[i] = 0;     int count = 0;     for (int i = 0; i < m; i++) {       if (vl != val[i].first && vl != val[i].second) {         count++;         ct[val[i].first]++;         if (val[i].second != val[i].first) {           ct[val[i].second]++;         }       }     }     if (count == 0) return true;     for (int i = 1; i < 300001; i++) {       if (ct[i] == count) {         return true;       }     }     return false;   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       val.push_back(make_pair(a, b));     }     int first = val[0].first;     int second = val[0].second;     if (check(first)) {       cout <<  YES n ;     } else if (check(second)) {       cout <<  YES n ;     } else {       cout <<  NO n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long l[5001], dp[5001][5001];   void solve() {     int n, k, ans = 0;     cin >> n >> k;     vector<int> v(n, 0);     for (int i = 0; i < (int)(n); ++i) cin >> v[i];     sort(v.begin(), v.end());     for (int i = 0, j = 0; i < n; ++i) {       while (v[i] - v[j] > 5) {         j++;       }       l[i] = j;     }     for (int i = 1; i <= k; i++) {       for (int j = 1; j <= n; j++) {         dp[i][j] = max(dp[i][j - 1], dp[i - 1][l[j - 1]] + j - l[j - 1]);       }     }     cout << dp[k][n] <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, data, prev = 0, energy = 0;     cin >> n;     vector<long long int> v1(n);     long long int ans = 0;     for (long long int i = 0; i < n; i++) {       cin >> data;       if (energy < (data - prev)) {         ans += ((data - prev) - energy);         energy = 0;         prev = data;       } else {         energy += (prev - data);         prev = data;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 10, M = N, INF = 0x3f3f3f3f, mod = 1e9 + 7,                   base = 131;   long long n, t, ans;   long long a[N], s[N];   long long phi(long long n) {     long long res, a;     res = a = n;     for (long long i = 2; i <= a / i; i++) {       if (a % i) continue;       res = res / i * (i - 1);       while (a % i == 0) a /= i;     }     if (a > 1) res = res / a * (a - 1);     return res;   }   signed main() {     long long p;     cin >> p;     cout << phi(p - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x, y, t, l[205], qd[205 + 205], qn[205 + 205], h[205], b1, b2, d1, d2,       ret;   void build(int x, int y) { qd[++t] = y, qn[t] = l[x], l[x] = t; }   void dfs(int x, int y, int *d) {     h[x] = 0;     int mx1 = 0, mx2 = 0;     for (int i = l[x]; i; i = qn[i]) {       if (i == b1 || i == b2 || qd[i] == y) continue;       dfs(qd[i], x, d);       h[x] = max(h[x], h[qd[i]] + 1);       if (h[qd[i]] + 1 >= mx1)         mx2 = mx1, mx1 = h[qd[i]] + 1;       else if (h[qd[i]] + 1 > mx2)         mx2 = h[qd[i]] + 1;     }     *d = max(*d, mx1 + mx2);   }   int main() {     scanf( %d , &n);     t = 1;     for (int i = 1; i < n; i++) scanf( %d%d , &x, &y), build(x, y), build(y, x);     ret = 0;     for (int i = 1; i <= n; i++) {       for (int j = l[i]; j; j = qn[j]) {         b1 = j;         b2 = j ^ 1;         d1 = d2 = 0;         dfs(i, -1, &d1);         dfs(qd[j], -1, &d2);         ret = max(ret, d1 * d2);       }     }     printf( %d n , ret);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   const int maxn = 510005;   int n, m;   vector<int> g[maxn];   char s[maxn];   vector<int> dep[maxn];   vector<int> op[maxn];   int id[maxn][2];   int deep[maxn];   int mx[maxn];   int dfs_clock = 1;   void dfs(int u, int d) {     deep[u] = mx[u] = d;     id[u][0] = dfs_clock++;     dep[d].push_back(1 << (s[u] -  a ));     op[d].push_back(id[u][0]);     for (int i = 0; i < g[u].size(); i++) {       dfs(g[u][i], d + 1);       mx[u] = max(mx[u], mx[g[u][i]]);     }     id[u][1] = dfs_clock++;   }   int main() {     int p;     scanf( %d%d , &n, &m);     for (int i = 2; i <= n; i++) {       scanf( %d , &p);       g[p].push_back(i);     }     scanf( %s , s + 1);     dfs(1, 1);     for (int i = 1; i <= n; i++) {       for (int j = 1; j < dep[i].size(); j++) {         dep[i][j] ^= dep[i][j - 1];       }     }     int u, h;     for (int i = 0; i < m; i++) {       scanf( %d%d , &u, &h);       if (h <= deep[u] || h > mx[u]) {         printf( Yes n );       } else {         int i = upper_bound(op[h].begin(), op[h].end(), id[u][0]) - op[h].begin();         int j =             upper_bound(op[h].begin(), op[h].end(), id[u][1]) - op[h].begin() - 1;         int a;         if (i - 1 >= 0)           a = dep[h][j] ^ dep[h][i - 1];         else           a = dep[h][j];         int num = 0;         for (int i = 0; i < 26; i++) {           if (a & (1 << i)) num++;         }         if (num <= 1)           printf( Yes n );         else           printf( No n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000 * 1000 * 1000 + 7;   const int MAXN = 155;   int i, j, n, m, k, it1, it2, dp[MAXN][MAXN][MAXN][2][2], ans;   int partSum[2][2][MAXN][MAXN];   void add(int &a, int b) {     a += b;     if (a >= MOD) a -= MOD;   }   int getSum(int mon1, int mon2, int leftBound1, int rightBound1, int leftBound2,              int rightBound2) {     int ans = 0;     ans = partSum[mon1][mon2][rightBound1][rightBound2] -           partSum[mon1][mon2][rightBound1][leftBound2 - 1] -           partSum[mon1][mon2][leftBound1 - 1][rightBound2] +           partSum[mon1][mon2][leftBound1 - 1][leftBound2 - 1];     while (ans >= MOD) ans -= MOD;     while (ans < 0) ans += MOD;     return ans;   }   int main() {     scanf( %d %d , &n, &m);     for (i = 1; i <= m; ++i)       for (j = i; j <= m; ++j) {         dp[1][i][j][0][0] = 1;         ans += n;       }     for (i = 1; i <= m; ++i)       for (j = 1; j <= m; ++j)         partSum[0][0][i][j] = dp[1][i][j][0][0] + partSum[0][0][i - 1][j] +                               partSum[0][0][i][j - 1] -                               partSum[0][0][i - 1][j - 1];     for (i = 2; i <= n; ++i) {       int cnt = 0;       for (j = 1; j <= m; ++j)         for (k = j; k <= m; ++k) {           add(dp[i][j][k][0][0], getSum(0, 0, j, m, 1, k));           add(dp[i][j][k][1][1], getSum(1, 1, 1, j, k, m));           add(dp[i][j][k][1][1], getSum(0, 0, 1, j - 1, k + 1, m));           add(dp[i][j][k][1][1], getSum(0, 1, 1, j - 1, k, m));           add(dp[i][j][k][1][1], getSum(1, 0, 1, j, k + 1, m));           add(dp[i][j][k][0][1], getSum(0, 1, j, k, k, m));           add(dp[i][j][k][0][1], getSum(0, 0, j, k, k + 1, m));           add(dp[i][j][k][1][0], getSum(1, 0, 1, j, j, k));           add(dp[i][j][k][1][0], getSum(0, 0, 1, j - 1, j, k));         }       for (j = 1; j <= m; ++j)         for (k = 1; k <= m; ++k)           for (it1 = 0; it1 <= 1; ++it1)             for (it2 = 0; it2 <= 1; ++it2) {               partSum[it1][it2][j][k] = dp[i][j][k][it1][it2];               add(cnt, dp[i][j][k][it1][it2]);             }       add(ans, 1LL * cnt * (n - i + 1) % MOD);       for (it1 = 0; it1 <= 1; ++it1)         for (it2 = 0; it2 <= 1; ++it2)           for (j = 1; j <= m; ++j)             for (k = 1; k <= m; ++k) {               add(partSum[it1][it2][j][k], partSum[it1][it2][j - 1][k]);               add(partSum[it1][it2][j][k], partSum[it1][it2][j][k - 1]);               partSum[it1][it2][j][k] -= partSum[it1][it2][j - 1][k - 1];               if (partSum[it1][it2][j][k] < 0) partSum[it1][it2][j][k] += MOD;             }     }     for (i = 1; i <= n; ++i)       for (j = i; j <= n; ++j)         for (it1 = 0; it1 <= 1; ++it1)           for (it2 = 0; it2 <= 1; ++it2) {           }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = (1e5 + 5) * 2;   void Max(int &x, int y) {     if (x < y) x = y;   }   int n, m;   int a[MAXN];   int dp[MAXN];   bool chk1(int s, int x) {     memset(dp, 0, sizeof(dp));     for (int i = s, iend = s + n - 1; i <= iend; ++i) {       int d = a[i + 1] - a[i] - 1;       if (dp[i] + x < d) return false;       if (dp[i] >= d) Max(dp[i + 1], x);       if (dp[i] + x >= a[i + 2] - a[i] - 1)         Max(dp[i + 2], x - (a[i + 2] - a[i + 1]));     }     int t = s + n - 1, d = a[s] - a[s - 1] - 1;     if (dp[t] + x < d)       return false;     else       return true;   }   bool chk2(int s, int x) {     memset(dp, 0, sizeof(dp));     if (x < a[s + 1] - a[s] - 1) return false;     Max(dp[s + 1], x - (a[s + 1] - a[s]));     for (int i = s + 1, iend = s + n - 1; i <= iend; ++i) {       int d = a[i + 1] - a[i] - 1;       if (dp[i] + x < d) return false;       if (dp[i] >= d) Max(dp[i + 1], x);       if (dp[i] + x >= a[i + 2] - a[i] - 1)         Max(dp[i + 2], x - (a[i + 2] - a[i + 1]));     }     int t = s + n - 1, d = a[s + 1] - a[s - 1] - 1;     if (dp[t] + x < d)       return false;     else       return true;   }   bool check(int x) {     int s = -1;     for (int i = 1, iend = n; i <= iend; ++i) {       if (a[i + 1] - a[i] > x + 1) s = i + 1;     }     if (s == -1)       return true;     else       return chk1(s, x) || chk2(s, x);   }   int main() {     cin >> m >> n;     for (int i = 1, iend = n; i <= iend; ++i) scanf( %d , &a[i]);     for (int i = 1, iend = n; i <= iend; ++i) a[i + n] = m + a[i];     if (n == 1) {       cout << m - 1 << endl;       return 0;     }     int l = 0, r = m, res;     while (l <= r) {       int mid = (l + r) >> 1;       if (check(mid))         res = mid, r = mid - 1;       else         l = mid + 1;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     char a[n][m];     int c = 0;     int column_no;     int row_number;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> a[i][j];         if (a[i][j] ==  B  && c == 0) {           column_no = j + 1;           row_number = i + 1;         }         if (a[i][j] ==  B ) c++;       }     double s = sqrt(c);     if (c == 1)       cout << row_number <<     << column_no;     else {       int r = s / 2;       cout << row_number + r <<     << column_no + r;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXn = 3000;   vector<pair<int, bool> > adj[MAXn + 2];   int d[MAXn + 2][MAXn + 2], c[MAXn + 2][MAXn + 2], root;   bool mark[MAXn + 5];   void DFS(int v) {     int sum = 0, Min = INT_MAX;     mark[v] = true;     for (int i = 0; i < (int)adj[v].size(); i++)       if (!mark[adj[v][i].first]) {         DFS(adj[v][i].first);         sum += d[root][adj[v][i].first] + adj[v][i].second;       }     for (int i = 0; i < (int)adj[v].size(); i++)       if (!mark[adj[v][i].first])         Min = min(Min, c[root][adj[v][i].first] + !adj[v][i].second +                            (sum - d[root][adj[v][i].first] - adj[v][i].second));     d[root][v] = sum;     Min = min(Min, d[root][v]);     c[root][v] = Min;     mark[v] = false;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d%d , &u, &v);       u--;       v--;       adj[u].push_back(make_pair(v, 0));       adj[v].push_back(make_pair(u, 1));     }     for (int i = 0; i < n; i++) {       root = i;       DFS(i);     }     int Min = INT_MAX;     for (int i = 0; i < n; i++) Min = min(d[i][i], Min);     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (i != j) Min = min(Min, d[i][i] - d[i][j] + c[i][j]);     cout << Min << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1010, M = 200200;   int i, j, k, n, m, ch, now, q;   int a[N][N], ans[M];   struct cc {     int x, y;   } A[M];   struct dd {     int l, r, s, t, q;   } Q[M];   void R(int &x) {     x = 0;     ch = getchar();     while (ch <  0  ||  9  < ch) ch = getchar();     while ( 0  <= ch && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();   }   bool cmp(const dd &a, const dd &b) { return a.r < b.r; }   void work() {     now++;     int x = A[now].x, y = A[now].y;     a[x][y] = a[y][x] = now;     for (int i = 1; i <= n; i++) a[x][i] = a[y][i] = max(a[x][i], a[y][i]);   }   int main() {     R(n);     R(m);     R(q);     for (i = 1; i <= m; i++) R(A[i].x), R(A[i].y);     for (i = 1; i <= q; i++) {       R(Q[i].l);       R(Q[i].r);       R(Q[i].s);       R(Q[i].t);       Q[i].q = i;     }     sort(Q + 1, Q + q + 1, cmp);     now = 0;     for (i = 1; i <= q; i++) {       while (now < Q[i].r) work();       if (a[Q[i].t][Q[i].s] >= Q[i].l) ans[Q[i].q] = 1;     }     for (i = 1; i <= q; i++) {       if (ans[i])         puts( Yes );       else         puts( No );     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &x) {     x = 0;     char c = getchar();     bool flag = false;     while (!isdigit(c)) {       if (c ==  - ) flag = true;       c = getchar();     }     while (isdigit(c)) {       x = (x << 1) + (x << 3) + (c ^ 48);       c = getchar();     }     if (flag) x = -x;   }   int n, m, k, lim = 1, ans, root, tot, cnt;   int ls[3000010], rs[3000010], tag[3000010], sum[3000010], val[3000010];   struct node {     int x, l, r, v;   } p[100010];   bool cmp(const node &a, const node &b) { return a.x < b.x; }   int get(int l, int r) {     int v = 0;     for (int i = 1; i <= k; i <<= 1)       v |= (((r / i - (l - 1) / i) -              (i * 2 <= k ? r / i / 2 - (l - 1) / i / 2 : 0)) &             1) *            i;     return v;   }   void pushup(int cur, int l, int r) {     if (tag[cur])       sum[cur] = val[cur];     else       sum[cur] = sum[ls[cur]] ^ sum[rs[cur]];   }   void modify(int L, int R, int l, int r, int v, int &cur) {     if (!cur) cur = ++tot;     val[cur] = get(l, r);     if (L <= l && R >= r) {       tag[cur] += v, pushup(cur, l, r);       return;     }     if (L <= ((l + r) >> 1)) modify(L, R, l, ((l + r) >> 1), v, ls[cur]);     if (R > ((l + r) >> 1)) modify(L, R, ((l + r) >> 1) + 1, r, v, rs[cur]);     pushup(cur, l, r);   }   int main() {     read(n), read(m), read(k);     while (lim <= k) lim <<= 1;     for (int i = 1; i <= m; ++i) {       int u, d, l, r;       read(l), read(u), read(r), read(d);       p[++cnt] = {l, u, d, 1}, p[++cnt] = {r + 1, u, d, -1};     }     sort(p + 1, p + cnt + 1, cmp);     for (int i = 1; i <= cnt; ++i) {       if (p[i - 1].x != p[i].x) {         int v1 = sum[root], v2 = get(p[i - 1].x, p[i].x - 1), s1 = 0, s2 = 0;         for (int j = lim; j; j >>= 1) {           s1 += ((v1 & j) != 0), s2 += ((v2 & j) != 0);           if ((s1 * s2) & 1) ans ^= j;         }       }       modify(p[i].l, p[i].r, 1, n, p[i].v, root);     }     if (ans)       puts( Hamed );     else       puts( Malek );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool Check(int X1, int Y1, int X2, int Y2, int a, int b) {     bool answ = false;     if (X1 <= a && X2 <= a && Y1 <= b && Y2 <= b)       if (!(X1 + X2 > a) || !(Y1 + Y2 > b)) answ = true;     if (Y1 <= a && X2 <= a && X1 <= b && Y2 <= b)       if (!(Y1 + X2 > a) || !(X1 + Y2 > b)) answ = true;     if (X1 <= a && Y2 <= a && Y1 <= b && X2 <= b)       if (!(X1 + Y2 > a) || !(Y1 + X2 > b)) answ = true;     if (Y1 <= a && Y2 <= a && X1 <= b && X2 <= b)       if (!(Y1 + Y2 > a) || !(X1 + X2 > b)) answ = true;     return answ;   }   int main() {     int n, a, b;     cin >> n >> a >> b;     char XY[n][2];     for (int i = 0; i < n; i++) {       int Xi, Yi;       cin >> Xi >> Yi;       XY[i][0] = Xi;       XY[i][1] = Yi;     }     int maxS = 0;     for (int i = 0; i < n - 1; i++) {       int X1 = XY[i][0];       int Y1 = XY[i][1];       for (int j = i + 1; j < n; j++) {         int X2 = XY[j][0];         int Y2 = XY[j][1];         if (Check(X1, Y1, X2, Y2, a, b) == true) {           maxS = max(maxS, X1 * Y1 + X2 * Y2);         }       }     }     cout << maxS;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());   const int N = 2e5 + 10;   const int mod = 998244353;   int a[N], b[N], p[N], l[N];   int getMin(int l, int r) {     int x = a[l];     for (int i = l; i <= r; i++) x = min(x, a[i]);     return x;   }   void zero() {     cout << 0;     exit(0);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) cin >> b[i];     int ptr = m - 1;     for (int i = n - 1; i >= 0; i--) {       if (a[i] == b[ptr]) {         p[ptr--] = i;       }       if (ptr < 0) break;     }     if (ptr >= 0) {       zero();     }     l[0] = -1;     for (int i = m - 1; i >= 1; i--) {       int j = p[i];       while (b[i] <= a[j]) j--;       l[i] = j;     }     if (getMin(0, p[0]) != b[0] || getMin(p[m - 1], n - 1) != b[m - 1]) zero();     for (int i = 0; i < m - 1; i++) {       if (getMin(p[i], p[i + 1]) != b[i]) zero();     }     long long ans = 1;     for (int i = 1; i < m; i++) {       ans *= (p[i] - l[i]);       ans %= mod;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp[100100][102];   int main() {     cin.sync_with_stdio(false);     cout.sync_with_stdio(false);     cin.tie(0);     long long n;     cin >> n;     int ans = 0;     while (n) {       ans += (n % 10 == 7 || n % 10 == 4);       n /= 10;     }     cout << (ans == 4 || ans == 7 ?  YES  :  NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace fgraph {   const int MAXV = 50;   const int MAXE = 10 * MAXV * MAXV;   const int INF = (1 << 30);   struct edge {     int to, cap, flow, cost;     edge *nxt, *rev;   } edges[MAXE + 5], *adj[MAXV + 5], *cur[MAXV + 5], *ecnt = edges;   void addedge(int u, int v, int c, int w) {     edge *p = (++ecnt), *q = (++ecnt);     (*p) = (edge){v, c, 0, w, adj[u], q}, adj[u] = p;     (*q) = (edge){u, 0, 0, -w, adj[v], p}, adj[v] = q;   }   int d[MAXV + 5], h[MAXV + 5], s, t;   bool relabel() {     for (int i = s; i <= t; i++) h[i] += d[i], d[i] = INF, cur[i] = adj[i];     priority_queue<pair<int, int>, vector<pair<int, int> >,                    greater<pair<int, int> > >         que;     que.push(make_pair(d[t] = 0, t));     while (!que.empty()) {       int k = que.top().first, x = que.top().second;       que.pop();       if (k != d[x]) continue;       for (edge *p = adj[x]; p; p = p->nxt) {         if (p->rev->cap > p->rev->flow) {           int dis = k + p->rev->cost + (h[x] - h[p->to]);           if (dis < d[p->to]) que.push(make_pair(d[p->to] = dis, p->to));         }       }     }     return d[s] != INF;   }   bool vis[MAXV + 5];   int aug(int x, int tot) {     if (x == t) return tot;     vis[x] = true;     int sum = 0;     for (edge *&p = cur[x]; p; p = p->nxt) {       int dis = d[p->to] + p->cost + (h[p->to] - h[x]);       if (d[x] == dis && !vis[p->to] && p->cap > p->flow) {         int del = aug(p->to, min(tot - sum, p->cap - p->flow));         sum += del, p->flow += del, p->rev->flow -= del;         if (sum == tot) break;       }     }     vis[x] = false;     return sum;   }   }  // namespace fgraph   int f[55];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w);       fgraph::addedge(u, v, 1, w);     }     int cnt = 0;     fgraph::s = 1, fgraph::t = n;     for (cnt = 0; fgraph::relabel(); cnt++)       f[cnt + 1] = f[cnt] + fgraph::d[1] + fgraph::h[1], fgraph::aug(1, 1);     int q;     scanf( %d , &q);     for (int i = 1; i <= q; i++) {       int x;       scanf( %d , &x);       double ans = 1E12;       for (int j = 1; j <= cnt; j++) ans = min(ans, 1.0 * (x + f[j]) / j);       printf( %.9f n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 10;   const int INF = 1e9 + 9;   const int B = 1e9 + 7;   long long p[N], s[N];   int fp(int first) {     return first == p[first] ? first : p[first] = fp(p[first]);   }   void u(int a, int b, int d) {     s[fp(a)] += 4 * d;     if (fp(a) == fp(b)) return;     s[fp(b)] += s[fp(a)];     p[fp(a)] = fp(b);   }   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     vector<long long> a(n + 1);     long long ans = 0;     for (int i = int(2); i <= int(n); ++i) p[i] = i, s[i] = 0;     for (int i = int(n); i >= int(2); --i)       for (int j = 2; i * j <= n; ++j) u(i, i * j, j);     for (int i = int(2); i <= int(n); ++i) ans = max(ans, s[fp(i)]);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 1e8;   int main() {     ios::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     int tcase;     cin >> tcase;     while (tcase--) {       int n, k;       cin >> n >> k;       vector<int> a(n + 1), b(n + 1), id(n + 1);       for (int i = 1; i <= n; i++) cin >> a[i] >> b[i], id[i] = i;       sort(id.begin() + 1, id.begin() + n + 1,            [&](int u, int v) { return b[u] < b[v]; });       vector<vector<int>> dp(n + 1, vector<int>(k + 1, -INF)),           prv(n + 1, vector<int>(k + 1, 0));       dp[0][0] = 0;       for (int i = 1; i <= n; i++) {         for (int j = 0; j <= k; j++) {           dp[i][j] = dp[i - 1][j];           if (j) {             if (dp[i][j] < dp[i - 1][j - 1] + a[id[i]] - b[id[i]] * (k - j)) {               dp[i][j] = dp[i - 1][j - 1] + a[id[i]] - b[id[i]] * (k - j);               prv[i][j] = 1;             }           }         }       }       vector<int> chk(n + 1, 0);       int cur_i = n, cur_j = k;       while (cur_i) {         if (prv[cur_i][cur_j])           chk[cur_i] = 1, cur_i--, cur_j--;         else           cur_i--;       }       vector<int> ans1, ans2;       for (int i = 1; i <= n; i++)         if (chk[i]) ans1.push_back(id[i]);       for (int i = 1; i <= n; i++)         if (!chk[i]) ans2.push_back(id[i]);       vector<int> rlt;       for (int i = 0; i < ans1.size() - 1; i++) rlt.push_back(ans1[i]);       for (auto it : ans2) rlt.push_back(it), rlt.push_back(-it);       rlt.push_back(ans1[ans1.size() - 1]);       cout << rlt.size() <<   n ;       for (int i = 0; i < rlt.size(); i++)         cout << rlt[i] <<    n [i == rlt.size() - 1];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct edge {     int v, to, cap, scap;     edge(int a, int b, int c) { v = a, to = b, cap = c, scap = c; }     edge() {}   };   struct rect {     int x1, y1, x2, y2;   };   struct tri {     int y1, y2, x;   };   bool operator<(const tri &a, const tri &b) { return a.y1 < b.y1; };   const int N = 1e6 + 7;   const int INF = 1e9 + 7;   vector<edge> e;   vector<int> g[N];   int us[N];   int usbs = 1;   int d[N];   int q[N];   int ded[N];   int ptr[N];   vector<rect> fget[N];   int after_bfs = 1;   int visb = 1;   long long ans = 0;   int qh, qt;   int s, t;   int l;   bool bfs() {     qh = qt = 0;     us[s] = usbs;     q[qt++] = s;     d[s] = 0;     while (qh < qt) {       int v = q[qh++];       for (auto c : g[v]) {         if (us[e[c].to] != usbs && e[c].cap > 0) {           d[e[c].to] = d[v] + 1;           us[e[c].to] = usbs;           q[qt++] = e[c].to;         }       }     }     return (us[t] == usbs++);   }   int dfs(int v = s, int c = 1e9) {     if (!c) {       return 0;     }     if (v == t) {       ans += c;       return c;     }     if (ded[v] != after_bfs) {       ded[v] = after_bfs;       ptr[v] = 0;     }     for (; ptr[v] < (int)g[v].size(); ptr[v]++) {       int ind = g[v][ptr[v]];       if (e[ind].cap > 0 && d[e[ind].to] == d[v] + 1) {         int x = dfs(e[ind].to, min(c, e[ind].cap));         if (x) {           e[ind].cap -= x;           e[ind ^ 1].cap += x;           return x;         }       }     }     return 0;   }   void add_edge(int u, int v, int cap) {     g[u].push_back(e.size());     e.push_back({u, v, cap});     g[v].push_back(e.size());     e.push_back({v, u, 0});   }   long long dinic(int a, int b) {     s = a, t = b;     while (bfs()) {       after_bfs++;       while (dfs()) {         continue;       }     }     return ans;   }   vector<int> inds;   int lel(int v, int l, int r, int i) {     if (r - l == 1) {       return v;     } else {       int m = (l + r) / 2;       if (i < m) {         return lel(v * 2 + 1, l, m, i);       } else {         return lel(v * 2 + 2, m, r, i);       }     }   }   void get(int v, int l, int r, int tl, int tr) {     if (tl >= r || tr <= l) {       return;     }     if (tl >= l && tr <= r) {       inds.push_back(v);     } else {       int tm = (tl + tr) / 2;       get(v * 2 + 1, l, r, tl, tm);       get(v * 2 + 2, l, r, tm, tr);     }   }   void build(int v, int l, int r, int ax, int bx, int n) {     if (r - l == 1) {       add_edge(l, ax + v, 1);       add_edge(bx + v, n + l, 1);     } else {       int m = (l + r) / 2;       build(v * 2 + 1, l, m, ax, bx, n);       build(v * 2 + 2, m, r, ax, bx, n);       add_edge(ax + v * 2 + 1, ax + v, INF);       add_edge(ax + v * 2 + 2, ax + v, INF);       add_edge(bx + v, bx + v * 2 + 1, INF);       add_edge(bx + v, bx + v * 2 + 2, INF);     }   }   int main() {     vector<rect> fre;     int n, q;     cin >> n >> q;     for (int i = 0; i < q; i++) {       int x1, y1, x2, y2;       cin >> x1 >> y1 >> x2 >> y2;       x1--, y1--, x2--, y2--;       fget[x2].push_back({x1, y1, x2, y2});     }     set<tri> s;     s.insert({0, n - 1, 0});     for (int i = 0; i < n; i++) {       for (auto c : fget[i]) {         auto it = s.lower_bound({c.y1, -1, -1});         vector<tri> gt;         if (it != s.begin()) {           it--;           gt.push_back(*it);           it++;         }         bool b = false;         while (it != s.end() && (it->y2 <= c.y2 || !b)) {           gt.push_back(*it);           it++;           if (it != s.end()) {             if (it->y2 > c.y2) {               gt.push_back(*it);               b = true;             }           }         }         for (auto d : gt) {           if (max(d.y1, c.y1) > min(d.y2, c.y2)) {             continue;           }           s.erase(d);           if (c.y1 <= d.y1 && d.y2 <= c.y2) {             int a = d.x, b = c.x1 - 1;             if (a <= b) {               fre.push_back({a, d.y1, b, d.y2});             }           } else {             if (d.y1 <= c.y1 && c.y2 <= d.y2) {               auto was = d;               was.y2 = c.y1 - 1;               if (was.y1 <= was.y2) {                 s.insert(was);               }               was = d;               was.y1 = c.y2 + 1;               if (was.y1 <= was.y2) {                 s.insert(was);               }               int a = d.x, b = c.x1 - 1;               if (a <= b) {                 fre.push_back({a, c.y1, b, c.y2});               }             } else if (d.y2 > c.y2) {               auto was = d;               was.y1 = c.y2 + 1;               s.insert(was);               int a = d.x, b = c.x1 - 1;               if (a <= b) {                 fre.push_back({a, d.y1, b, c.y2});               }             } else if (d.y1 < c.y1) {               auto was = d;               was.y2 = c.y1 - 1;               s.insert(was);               int a = d.x, b = c.x1 - 1;               if (a <= b) {                 fre.push_back({a, c.y1, b, d.y2});               }             }           }         }         if (c.x2 != n - 1) {           s.insert({c.y1, c.y2, c.x2 + 1});         }       }     }     for (auto c : s) {       fre.push_back({c.x, c.y1, n - 1, c.y2});     }     inds.clear();     get(0, n - 1, n, 0, n);     int cnt = inds[0] + 1;     for (auto c : fre) {       int x1 = c.x1, y1 = c.y1, x2 = c.x2, y2 = c.y2;       inds.clear();       get(0, x1, x2 + 1, 0, n);       vector<int> a = inds;       inds.clear();       get(0, y1, y2 + 1, 0, n);       vector<int> b = inds;       for (auto c : a) {         for (auto d : b) {           add_edge(n + n + c, n + n + cnt + d, INF);         }       }     }     build(0, 0, n, n + n, n + n + cnt, n);     int st = n + n + cnt + cnt, en = n + n + cnt + cnt + 1;     for (int i = 0; i < n; i++) {       add_edge(st, i, 1);       add_edge(i + n, en, 1);     }     cout << dinic(st, en) << endl;   }


#include <bits/stdc++.h>      using namespace std;      const int N = 2e5+5;   const long long inf = 0x3f3f3f3f3f3f3f3f;   typedef long long ll;   #define pb push_back      int n, m;   int a[N];   int g[N], v[N<<1], nxt[N<<1], tot, fa[N];   vector<int> c[N];   ll f[N], ans;      inline void add(int x, int y) {    v[++tot] = y, nxt[tot] = g[x], g[x] = tot;   }      void dfs(int x, int ff, int dep) {    fa[x] = ff, c[dep].pb(x), m = max(m, dep);    for (int i = g[x]; i; i = nxt[i]) {     int y = v[i];     if (y == ff) continue;     dfs(y, x, dep + 1);    }   }      inline void solve() {    scanf( %d , &n);    for (int i = 2; i <= n; i++) {     int x;     scanf( %d , &x);     add(i, x), add(x, i);    }    for (int i = 2; i <= n; i++) scanf( %d , &a[i]);    dfs(1, 0, 0);    for (int r = 1; r <= m; r++) {     ll max0 = -inf, min0 = inf, max1 = -inf, max2 = -inf;     for (int i = 0; i < (int)c[r].size(); i++) {      int x = c[r][i];      max0 = max(max0, (ll)a[x]), min0 = min(min0, (ll)a[x]);      max1 = max(max1, f[fa[x]] + a[x]);      max2 = max(max2, f[fa[x]] - a[x]);     }     for (int i = 0; i < (int)c[r].size(); i++) {      int x = c[r][i];      f[x] = max(f[fa[x]] + max(max0 - a[x], a[x] - min0), max(max1 - a[x], max2 + a[x]));      if (r == m) ans = max(ans, f[x]);     }    }    printf( %lld n , ans);   }      inline void init() {    ans = m = tot = 0;    for (int i = 1; i <= n; i++) c[i].clear(), g[i] = 0, f[i] = 0;   }      int main()   {    int T;    scanf( %d , &T);    while (T--) {     init();     solve();    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[200005];   int v[200005];   int c[200005], lower;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cerr.tie(nullptr);     int sol = 123123123;     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= m; i++) {       cin >> v[i];       if (c[i] < v[i]) lower++;     }     int j = 0;     for (int i = 1; i <= n; i++) {       while (j < n && lower > 0) {         j++;         c[a[j]]++;         if (c[a[j]] == v[a[j]]) lower--;       }       if (!lower) sol = min(sol, j - i + 1);       c[a[i]]--;       if (c[a[i]] == v[a[i]] - 1) lower++;     }     if (sol == 123123123)       sol = -1;     else       sol = sol - accumulate(v + 1, v + m + 1, 0);     cout << sol <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long mo = 998244353;   const long long N = 2e6 + 5;   long long n, m, noden, tot;   set<long long> S;   long long sum, pre1, pre2, ans, cnt;   struct node {     long long lc, rc, rnd, val, sz;   } a[N];   long long giao[N];   long long fcc[N];   struct Tree {     long long maxv[100];     void pushup(long long rt) { maxv[rt] = max(maxv[(2 * rt)], maxv[(2 * rt)]); }     void update(long long rt, long long l, long long r, long long p,                 long long v) {       if (l == r) {         maxv[rt] = v;         return;       }       if (p <= ((l + r) / 2))         update((2 * rt), l, ((l + r) / 2), p, v);       else         update((2 * rt), ((l + r) / 2) + 1, r, p, v);       pushup(rt);     }     long long ask(long long rt, long long l, long long r, long long ql,                   long long qr) {       if (ql > qr) return -1e12;       if (l >= ql && r <= qr) return maxv[rt];       long long ans = -1e12;       if (ql <= ((l + r) / 2))         ans = max(ans, ask((2 * rt), l, ((l + r) / 2), ql, qr));       if (qr >= ((l + r) / 2) + 1)         ans = max(ans, ask((2 * rt), ((l + r) / 2) + 1, r, ql, qr));       return ans;     }   } xxx, yyy;   long long cc1, cc2;   struct fhq {     long long rt;     long long merge(long long x, long long y) {       if (!x || !y) return x | y;       giao[x] = a[x].rnd;       giao[0] = 0;       if (a[x].rnd < a[y].rnd && giao[0] == 0) {         giao[x] = a[x].rnd;         a[x].rc = merge(a[x].rc, y);         giao[x] = a[x].rnd;         pushup(x);         giao[x] = a[x].rnd;         return x;       } else {         giao[2] = a[2].rnd;         a[y].lc = merge(x, a[y].lc);         giao[123] = a[123].rnd;         pushup(y);         return y;       }     }     long long Find(long long val) {       long long res, x, y;       giao[23] = 23;       split(rt, val + 1, x, y);       if (giao[23] == 23) {         res = a[x].sz + 1;         rt = merge(x, y);       }       return res;     }     void split(long long now, long long val, long long &x, long long &y) {       if (!now) {         x = y = 0;         return;       }       if (a[now].val >= val) {         x = now;         split(a[now].rc, val, a[now].rc, y);       } else {         y = now;         split(a[now].lc, val, x, a[now].lc);       }       pushup(now);     }     long long NEW(long long val) {       a[++noden] = (node){0, 0, rand(), val, 1};       return noden;     }     void pushup(long long x) { a[x].sz = a[a[x].lc].sz + a[a[x].rc].sz + 1; }     long long getk(long long x, long long k) {       if (!k || k > a[rt].sz) return 0;       for (;;) {         if (k <= a[a[x].lc].sz)           x = a[x].lc;         else if (k == a[a[x].lc].sz + 1)           return x;         else {           k -= a[a[x].lc].sz + 1;           x = a[x].rc;         }       }     }     long long Kth(long long rank) { return a[getk(rt, rank)].val; }     void Del(long long val) {       long long x, y, z;       split(rt, val, x, z);       split(x, val + 1, x, y);       y = merge(a[y].lc, a[y].rc);       rt = merge(merge(x, y), z);     }     void insert(long long val) {       long long x, y;       split(rt, val, x, y);       rt = merge(merge(x, NEW(val)), y);     }   } T;   long long tree[100];   long long id[100];   long long lc[100];   long long rc[100];   long long merge(long long x, long long y, long long l, long long r) {     if (cc1 == cc2) return 0;     if (!x || !y) return x + y;     if (l == r) {       tree[x] += tree[y];       id[x] = l;       return x;     }     lc[x] = merge(lc[x], lc[y], l, ((l + r) / 2));     rc[x] = merge(rc[x], rc[y], ((l + r) / 2) + 1, r);     return x;   }   void fun() {     long long op, v, rk;     cin >> op;     cin >> v;     sum += v;     rk = T.Find(abs(v));     long long ff1 = 3;     long long ff2 = 233;     if (v > 0) {       if (rk <= cnt && fcc[3] == 233) pre1 += v - T.Kth(cnt);       if (rk <= cnt + 1 && fcc[3] == 233) pre2 += v - T.Kth(cnt + 1);       T.insert(v);       if (op && fcc[3] == 233) {         merge(1, 2, 1, 2);         cnt++;         pre1 += T.Kth(cnt);         merge(1, 1, 1, 1);         pre2 += T.Kth(cnt + 1);         S.insert(v);         merge(1, 3, 1, 3);       }       if (cnt && T.Find(*S.begin()) <= cnt)         ans = sum + pre2 - *S.begin();       else         ans = sum + pre1;       merge(5, 1, 4, 1);     } else {       v = -1 * v;       if (rk <= cnt && fcc[3] == 233)         pre1 -= v - 1 - T.Kth(cnt + 1) + 1, merge(1, 1, 1, 1);       if (rk <= cnt + 1 && fcc[3] == 233) pre2 -= v - 12 - T.Kth(cnt + 2) + 12;       if (fcc[3] == 233) T.Del(v), merge(1, 1, 1, 1);       if (op) {         merge(1, 1, 1, 1);         merge(3, 4, 1, 1);         if (fcc[ff1] == ff2)           merge(1, 1, 1, 1), pre1 -= T.Kth(cnt), pre2 -= T.Kth(cnt + 1);         merge(3, 4, 1, 1);         if (fcc[3] == 233) cnt--;         merge(3, 4, 1, 1);         if (fcc[ff1] == ff2) S.erase(v);       }       if (cnt && T.Find(*S.begin()) <= cnt && fcc[3] == 233)         ans = sum + pre2 - *S.begin(), merge(1, 1, 1, 1);       else         ans = sum + pre1;     }     cout << ans << endl;   }   struct St {     long long n;     long long m;     long long table[2][2][2][2];     long long lg[100];     St() {       lg[1] = 0;       for (long long i = 2; i < 3; ++i)         lg[i] = lg[i - 1] + (i == 1 << lg[i - 1] + 1);     }     void build(long long n, long long m, long long mat[][N]) {       this->n;       this->m = m;       for (long long i = 1; i <= n; ++i)         for (long long j = 1; j <= m; ++j) table[i][j][0][0] = mat[i][j];       for (long long ii = 0; (1 << ii) <= n; ii++)         for (long long jj = 0; (1 << jj) <= m; jj++)           if (ii + jj)             for (long long i = 1; i + (1 << ii) - 1 <= n; i++)               for (long long j = 1; j + (1 << jj) - 1 <= m; j++)                 if (ii)                   table[i][j][ii][jj] =                       max(table[i][j][ii - 1][jj],                           table[i + (1 << (ii - 1))][j][ii - 1][jj]);                 else                   table[i][j][ii][jj] =                       max(table[i][j][ii][jj - 1],                           table[i][j + (1 << (jj - 1))][ii][jj - 1]);     }     long long query(long long x1, long long y1, long long x2, long long y2) {       if (x1 > x2) return -10000;       if (y1 > y2) return -10000;       long long dx = lg[x2 - x1 + 1];       long long dy = lg[y2 - y1 + 1];       long long ret1 =           max(table[x1][y1][dx][dy], table[x1][y2 - (1 << dy) + 1][dx][dy]);       long long ret2 = max(table[x2 - (1 << dx) + 1][y1][dx][dy],                            table[x2 - (1 << dx) + 1][y2 - (1 << dy) + 1][dx][dy]);       return max(ret1, ret2);     }   } x1, x2;   int32_t main() {     cin >> n;     fcc[3] = 233;     for (long long i = 1; i <= n; ++i) fun();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 888888;   int n, m, i, j, e;   int ss[N], ff[N], dd[N], x[N], last[N], pred[N], good[N], deg[N], used[N];   int main() {     scanf( %d %d , &n, &m);     for (i = 1; i <= m; i++) {       scanf( %d %d %d , ss + i, ff + i, dd + i);       ss[i + m] = ff[i];       ff[i + m] = ss[i];       dd[i + m] = dd[i];     }     for (i = 1; i <= n; i++) last[i] = 0;     for (i = 1; i <= m + m; i++) {       good[i] = 0;       pred[i] = last[ss[i]];       last[ss[i]] = i;     }     for (i = 1; i <= n; i++) deg[i] = 0;     for (i = 1; i <= m + m; i++) deg[ss[i]] += dd[i];     for (i = 1; i <= n; i++) deg[i] /= 2;     for (i = 1; i <= n; i++) used[i] = 0;     deg[1] = deg[n] = 0;     i = 1;     e = 1;     x[1] = 1;     while (i <= e) {       j = last[x[i]];       while (j > 0) {         if (ff[j] == n) good[j] = 1;         if (used[ff[j]] < deg[ff[j]]) {           good[j] = 1;           used[ff[j]] += dd[j];           if (used[ff[j]] == deg[ff[j]]) {             e++;             x[e] = ff[j];           }         }         j = pred[j];       }       i++;     }     for (i = 1; i <= m; i++) printf( %d n , 1 - good[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, const U &b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, const U &b) {     if (a < b) a = b;   }   char s[100100], ss[4][100100];   int nxt[100100][26], N[4];   int dp[255][255][255], n;   inline void calc(int a_st, int a_ed, int b_st, int b_ed, int c_st, int c_ed) {     for (int i = a_st; i <= a_ed; i++) {       for (int j = b_st; j <= b_ed; j++) {         for (int k = c_st; k <= c_ed; k++) {           if (!i && !j && !k)             dp[i][j][k] = 0;           else {             dp[i][j][k] = 0x3f3f3f3f;             if (i && dp[i - 1][j][k] < n)               smin(dp[i][j][k], nxt[dp[i - 1][j][k] + 1][ss[1][i] -  a ]);             if (j && dp[i][j - 1][k] < n)               smin(dp[i][j][k], nxt[dp[i][j - 1][k] + 1][ss[2][j] -  a ]);             if (k && dp[i][j][k - 1] < n)               smin(dp[i][j][k], nxt[dp[i][j][k - 1] + 1][ss[3][k] -  a ]);           }         }       }     }   }   int main() {     int q;     scanf( %d %d %s , &n, &q, s + 1);     for (int i = 26; i--;) nxt[n + 1][i] = n + 1;     for (int i = n; i >= 1; i--) {       for (int j = 26; j--;) nxt[i][j] = nxt[i + 1][j];       nxt[i][s[i] -  a ] = i;     }     while (q--) {       char c;       scanf(  %c , &c);       if (c ==  + ) {         int id;         scanf( %d %c , &id, &c);         ss[id][++N[id]] = c;         if (id == 1) calc(N[1], N[1], 0, N[2], 0, N[3]);         if (id == 2) calc(0, N[1], N[2], N[2], 0, N[3]);         if (id == 3) calc(0, N[1], 0, N[2], N[3], N[3]);       } else {         int id;         scanf( %d , &id);         N[id]--;       }       puts(dp[N[1]][N[2]][N[3]] <= n ?  YES  :  NO );     }   }