#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e6 + 50;   const long long inf = 0x3f3f3f3f3f3f3f3f;   const long long mod = 1e9 + 7;   const long double eps = 1e-20;   const long long HASH = 131;   using namespace std;   long long a[maxn];   signed main() {     std::ios::sync_with_stdio(false);     long long t;     cin >> t;     while (t--) {       long long a, b;       cin >> a >> b;       if ((a & 1)) {         long long tmp = b % 4;         if (tmp == 1) {           cout << a + b << endl;         } else if (tmp == 2) {           cout << a - 1 << endl;         } else if (tmp == 3) {           cout << a - 1 - b << endl;         } else           cout << a << endl;       } else {         long long tmp = b % 4;         if (tmp == 1) {           cout << a - b << endl;         } else if (tmp == 2) {           cout << a + 1 << endl;         } else if (tmp == 3) {           cout << a + 1 + b << endl;         } else           cout << a << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   using ii = pair<long long, long long>;   using ll = long long;   using ull = unsigned long long;   using ld = long double;   using vec = vector<long long>;   using vecc = vector<vector<long long> >;   namespace royyaha {   template <typename T>   void pr(const T& x) {     cout << x;   }   template <typename T1, typename T2>   void pr(const pair<T1, T2>& x) {     cout << x.first <<     << x.second;   }   template <typename T, typename... Args>   void pr(const T& x, const Args&... rest) {     pr(x);     pr(rest...);   }   template <typename T>   void ou(const T& x) {     pr(x);     cout << endl;   }   template <typename T, typename... Args>   void ou(const T& x, const Args&... rest) {     pr(x,    );     ou(rest...);   }   template <typename T>   void ou(const vector<T>& v, long long n = 0) {     n = (n ? n : v.size());     for (auto it = v.begin(); it != v.begin() + n; ++it) {       if (it + 1 == v.end())         ou(*it);       else         pr(*it,    );     }   }   }  // namespace royyaha   using namespace royyaha;   bool intersection(ii a, ii b) {     return !(a.first > b.second || a.second < b.first);   }   const long long maxn = 2e5 + 50;   vec depth(maxn);   vec son(maxn);   vec e[maxn];   void dfs(long long u, long long pre) {     depth[u] = depth[pre] + 1;     son[u] = 1;     for (auto v : e[u])       if (v != pre) {         dfs(v, u);         son[u] += son[v];       }   }   signed main() {     long long n, k;     cin >> n >> k;     for (long long i = 0; i < n - 1; ++i) {       long long u, v;       cin >> u >> v;       u--, v--;       e[u].push_back(v);       e[v].push_back(u);     }     dfs(0, 0);     vec f(n);     for (long long i = 0; i < n; ++i) f[i] = depth[i] - son[i];     sort(f.begin(), f.end());     reverse(f.begin(), f.end());     cout << accumulate(f.begin(), f.begin() + k, 0ll) << endl;   }


#include <bits/stdc++.h>   using namespace std;   void AWAD() {     std::ios::sync_with_stdio(false);     cin.tie(0);   }   bool cmp(long long int a, long long int b) {     if (a > b) return true;     return false;   }   int a[1000001], b[1000001];   int main() {     AWAD();     string input;     long long int c4 = 0, c7 = 0;     cin >> input;     for (int i = 0; i < input.size(); i++)       if (input[i] ==  4 )         ++c4;       else if (input[i] ==  7 )         ++c7;     if (!c4 && !c7)       cout <<  -1 n ;     else if (c4 >= c7)       cout << 4 << endl;     else       cout << 7 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char c;   int mo = 1000003;   int main() {     int pre = 0;     while (scanf( %c , &c) != EOF) {       if (c < 32 || c > 126) break;       int w = c;       int tmp = 0;       for (int j = 0; j < 8; j++) {         tmp = tmp * 2 + w % 2;         w /= 2;       }       w = tmp;       tmp = pre - tmp;       pre = w;       if (tmp < 0) tmp += 256;       printf( %d n , tmp);     }     return 0;   }


#include <bits/stdc++.h>   int A, B, M = 6, N;   int main() {     scanf( %d%d%d , &N, &A, &B);     int nda = N / A;     for (int i = 1; (i <= 2) && (B * i <= N); ++i)       M = std::min((i ^ 3) + (4 - ((N - B * i) / A) * (i ^ 3) + nda - 1) / nda,                    M);     printf( %d n , M);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000009;   const int SGZ = 26;   const int M = 10009;   int n, m, nxt[N][SGZ], crt[N][SGZ], q[M], ans[M];   vector<int> val;   char s[N], qy[SGZ];   inline int read() {     char c = getchar();     int ret = 0, f = 1;     while (c <  0  || c >  9 ) {       f = c ==  -  ? -1 : 1;       c = getchar();     }     while ( 0  <= c && c <=  9 ) {       ret = ret * 10 + c -  0 ;       c = getchar();     }     return ret * f;   }   inline int index(int x) {     for (int l = 0, r = val.size() - 1, mid; l <= r;) {       mid = l + r >> 1;       if (val[mid] == x) {         return mid;       } else if (val[mid] < x) {         l = mid + 1;       } else {         r = mid - 1;       }     }     return -1;   }   int main() {     scanf( %s , s);     n = strlen(s);     m = read();     for (int i = 1; i <= m; i++) {       scanf( %s , qy);       int len = strlen(qy);       for (int j = 0; j < len; j++) {         q[i] |= 1 << qy[j] -  a ;       }       val.push_back(q[i]);     }     sort(val.begin(), val.end());     val.resize(unique(val.begin(), val.end()) - val.begin());     int last_position[SGZ];     fill(last_position, last_position + SGZ, n);     for (int i = n - 1; ~i; i--) {       last_position[s[i] -  a ] = i;       for (int j = 0; j < SGZ; j++) {         nxt[i][j] = last_position[j];       }     }     memset(crt, -1, sizeof(crt));     for (int i = 0; i < n; i++) {       for (int j = 0, p = i, sta = 0; j < 26 && p < n; j++) {         int np = n, c = -1;         for (int k = 0; k < 26; k++) {           if ((sta >> k & 1) == 0) {             if (np > nxt[p][k]) {               c = k;               np = nxt[p][k];             }           }         }         if (~c) {           sta |= 1 << c;           p = np;           crt[i][j] = sta;           if (!i || crt[i - 1][j] != sta) {             int idx = index(sta);             if (~idx) {               ans[idx]++;             }           }         }       }     }     for (int i = 1; i <= m; i++) {       printf( %d n , ans[index(q[i])]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, k, x, s = 0;     cin >> n >> k;     map<long long, long long> m;     queue<long long> q;     for (long long i = 0; 0 < n ? i < n : i > n; 0 < n ? i += 1 : i -= 1) {       cin >> x;       q.push(x);       m[x] = 0;     }     while (1) {       x = q.front();       q.pop();       if (!m.count(x + 1)) {         q.push(x + 1);         m[x + 1] = m[x] + 1;       }       if (m.size() >= n + k) break;       if (!m.count(x - 1)) {         q.push(x - 1);         m[x - 1] = m[x] + 1;       }       if (m.size() >= n + k) break;     }     for (auto i : m) s += i.second;     cout << s <<   n ;     for (auto i : m)       if (i.second != 0) cout << i.first <<    ;   }


#include <bits/stdc++.h>   using namespace std;   char s[2000006];   char t[1000006];   int len[100005], pos[100005];   vector<pair<int, int>> e;   int main() {     int n;     scanf( %d , &n);     int tp = 0;     for (int i = 0; i < n; i++) {       scanf( %s , t + tp);       len[i] = strlen(t + tp);       pos[i] = tp;       tp += len[i];       int ki;       scanf( %d , &ki);       while (ki--) {         int xij;         scanf( %d , &xij);         e.push_back({xij - 1, i});       }     }     int p = 0;     sort(e.begin(), e.end());     int esz = (int)e.size();     tp = -1;     int te = -1, sp = 0;     while (p < esz) {       int f = e[p].first;       while (sp < f) {         if (tp != -1) {           s[sp++] = t[tp++];           if (tp >= te) tp = te = -1;         } else           s[sp++] =  a ;       }       if (tp == -1) {         tp = pos[e[p].second];         te = pos[e[p].second] + len[e[p].second];       } else if (len[e[p].second] > te - tp) {         tp = pos[e[p].second];         te = pos[e[p].second] + len[e[p].second];       }       while (p + 1 < esz && e[p + 1].first == e[p].first) {         p++;         if (len[e[p].second] > te - tp) {           tp = pos[e[p].second];           te = pos[e[p].second] + len[e[p].second];         }       }       p++;     }     while (tp < te) s[sp++] = t[tp++];     s[sp] =   0 ;     printf( %s , s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e3 + 5;   const int mod = 998244353;   inline long long fpm(long long a, long long p) {     long long r = 1;     while (p) {       if (p & 1) r = r * a % mod;       a = a * a % mod;       p /= 2;     }     return r;   }   int k, n, m;   int s[maxn][maxn];   inline void init() {     s[0][0] = 1;     for (int i = 1; i <= k; i++) {       for (int j = 1; j <= i; j++) {         s[i][j] = (s[i - 1][j - 1] + 1ll * j * s[i - 1][j] % mod) % mod;       }     }   }   int main() {     cin >> n >> m >> k;     init();     long long ans = 0, cur = 1;     long long invm = fpm(m, mod - 2);     for (int i = 0; i <= k; i++) {       ans = (ans + 1ll * cur * s[k][i] % mod * fpm(invm, i) % mod) % mod;       cur = 1ll * cur * (n - i) % mod;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   using vint = vector<long long>;   using pint = pair<long long, long long>;   using vpint = vector<pint>;   template <typename A, typename B>   inline void chmin(A& a, B b) {     if (a > b) a = b;   }   template <typename A, typename B>   inline void chmax(A& a, B b) {     if (a < b) a = b;   }   template <class A, class B>   ostream& operator<<(ostream& ost, const pair<A, B>& p) {     ost <<  {  << p.first <<  ,  << p.second <<  } ;     return ost;   }   template <class T>   ostream& operator<<(ostream& ost, const vector<T>& v) {     ost <<  { ;     for (long long i = 0; i < v.size(); i++) {       if (i) ost <<  , ;       ost << v[i];     }     ost <<  } ;     return ost;   }   inline long long topbit(unsigned long long x) {     return x ? 63 - __builtin_clzll(x) : -1;   }   inline long long popcount(unsigned long long x) {     return __builtin_popcountll(x);   }   inline long long parity(unsigned long long x) { return __builtin_parity(x); }   signed main() {     long long N, K;     cin >> N >> K;     if (K > 1000000 || K * (K + 1) / 2 > N) {       cout << -1 << endl;       return 0;     }     long long s = K * (K + 1) / 2;     long long G = 0;     for (long long g = 1; g * g <= N; g++) {       if (N % g) continue;       if (N / s >= g) chmax(G, g);       if (N / s >= N / g) chmax(G, N / g);     }     vint ans(K);     iota((ans).begin(), (ans).end(), 1);     ans[K - 1] += N / G - s;     for (long long i = 0; i < (K); i++) ans[i] *= G;     for (long long i = 0; i < (K); i++) {       if (i) cout <<    ;       cout << ans[i];     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[100002];   int mini[100002][21];   vector<pair<int, int> > vp;   int f(int l, int r, int m) {     if (l == r) {       for (int i = 0; i < a[l] - m; i++) {         vp.push_back(make_pair(l, r));       }       return a[l] - m;     }     int i = 0;     for (i = 0;; i++)       if (l + (1 << i) > r) break;     int minIndex = -1;     if (a[mini[l][i - 1]] < a[mini[r - (1 << (i - 1)) + 1][i - 1]]) {       minIndex = mini[l][i - 1];     } else {       minIndex = mini[r - (1 << (i - 1)) + 1][i - 1];     }     for (int i = 0; i < a[minIndex] - m; i++) {       vp.push_back(make_pair(l, r));     }     if (minIndex == l) {       return a[minIndex] - m + f(l + 1, r, a[minIndex]);     }     if (minIndex == r) {       return a[minIndex] - m + f(l, r - 1, a[minIndex]);     } else {       return a[minIndex] - m + f(l, minIndex - 1, a[minIndex]) +              f(minIndex + 1, r, a[minIndex]);     }   }   int main() {     cout << setprecision(9);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) mini[i][0] = i;     for (int i = 1; i < 21; i++) {       for (int j = 0; j + (1 << i) - 1 < n; j++) {         if (a[mini[j][i - 1]] < a[mini[j + (1 << (i - 1))][i - 1]]) {           mini[j][i] = mini[j][i - 1];         } else {           mini[j][i] = mini[j + (1 << (i - 1))][i - 1];         }       }     }     cout << f(0, n - 1, 0) << endl;     for (int i = 0; i < vp.size(); i++)       cout << 1 + vp[i].first <<     << 1 + vp[i].second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct custom_hash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   const int maxn = 2e5 + 5;   const long long mod = 1e9 + 7;   long long gcd(long long a, long long b) {     if (!b) return a;     return gcd(b, a % b);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     long long maxl = 1e18 + 2;     for (int i = 0; i < n; i++) {       long long p, q, b;       cin >> p >> q >> b;       if (p % q == 0) {         cout <<  Finite  << endl;         continue;       }       long long g = gcd(p, q);       p /= g;       q /= g;       while (true) {         if (q == 1) {           cout <<  Finite  << endl;           break;         }         g = gcd(b, q);         if (g == 1) {           cout <<  Infinite  << endl;           break;         }         q /= g;         b = g;       }     }   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int n;   char s[N], t[N];   bitset<N> c[30], ans;   int main() {     scanf( %s%d , s + 1, &n);     for (int i = 1, _ = strlen(s + 1); i <= _; i++) c[s[i] -  a ][i] = 1;     int op, x, y;     while (n--) {       scanf( %d , &op);       if (op == 1) {         scanf( %d%s , &x, t + 1);         c[s[x] -  a ].reset(x);         s[x] = t[1];         c[s[x] -  a ].set(x);       } else {         scanf( %d%d%s , &x, &y, t + 1);         int len = strlen(t + 1);         ans.set();         y = y - len + 1;         for (int i = 1; i <= len; i++) ans &= c[t[i] -  a ] >> (i - 1);         printf( %d n ,                max(0, (int)((ans >> x).count() - (ans >> (y + 1)).count())));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1000005;   long long pw(long long b, long long r, long long md) {     long long ans = 1;     while (r) {       if (r & 1) ans = (ans * b) % md;       b = (b * b) % md;       r >>= 1;     }     return ans;   }   bool cmp(pair<long long, long long> a, pair<long long, long long> b) {     if (a.first == b.first) return a.second < b.second;     return a.first > b.first;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m, k;     cin >> n >> m >> k;     long long dp[n][k + 1];     for (long long i = 0; i <= n - 1; ++i)       for (long long j = 0; j <= k; ++j) dp[i][j] = -1e18;     long long arr[n];     for (long long i = 0; i <= n - 1; ++i) cin >> arr[i];     long long pref[n];     pref[0] = arr[0];     for (long long i = 1; i <= n - 1; ++i) pref[i] = pref[i - 1] + arr[i];     for (long long i = 0; i <= n - 1; ++i) dp[i][0] = 0;     dp[m - 1][1] = pref[m - 1];     long long ans = 0;     for (long long i = m; i <= n - 1; ++i) {       for (long long j = 0; j <= k; ++j) {         dp[i][j] = dp[i - 1][j];         if (j == 0) continue;         dp[i][j] = max(dp[i][j], dp[i - m][j - 1] + pref[i] - pref[i - m]);       }     }     for (long long i = 0; i <= n - 1; ++i) ans = max(ans, dp[i][k]);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   template <class T>   inline bool Min(T &a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   inline bool Max(T &a, T b) {     return a < b ? (a = b, true) : false;   }   inline int ni() {     int a;     scanf( %d , &a);     return a;   }   inline ll nl() {     ll a;     scanf( %lld , &a);     return a;   }   inline double nd() {     double a;     scanf( %lf , &a);     return a;   }   inline void pi(int a) { printf( %d  , a); }   inline void pl(ll a) { printf( %lld  , a); }   inline void pd(double a) { printf( %.12lf  , a); }   const int N = 1e5 + 10;   using ld = long double;   void solve() {     ld x, y, z;     cin >> x >> y >> z;     ld ans[10];     ans[1] = log(x) * pow(y, z);     ans[2] = log(x) * pow(z, y);     ans[3] = log(x) * y * z;     ans[4] = log(y) * pow(x, z);     ans[5] = log(y) * pow(z, x);     ans[6] = log(y) * x * z;     ans[7] = log(z) * pow(x, y);     ans[8] = log(z) * pow(y, x);     ans[9] = log(z) * x * y;     ans[0] = ans[1];     int t = 1;     for (int i = 1; i <= 9; i++)       if (Max(ans[0], ans[i])) t = i;     if (t == 1) puts( x^y^z );     if (t == 2) puts( x^z^y );     if (t == 3) puts( (x^y)^z );     if (t == 4) puts( y^x^z );     if (t == 5) puts( y^z^x );     if (t == 6) puts( (y^x)^z );     if (t == 7) puts( z^x^y );     if (t == 8) puts( z^y^x );     if (t == 9) puts( (z^x)^y );   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int powm[100005];   int fact[100005];   int sum[100005];   string s;   void powers_of_10(int m) {     powm[0] = 1;     for (int i = 1; i <= m; i++) powm[i] = 1LL * powm[i - 1] * 10 % 1000000007;   }   void factorials(int m) {     fact[0] = 1;     for (int i = 1; i <= m; i++) fact[i] = 1LL * i * fact[i - 1] % 1000000007;   }   void sums(int m) {     sum[0] = s[0] -  0 ;     for (int i = 1; i < m; i++) {       sum[i] = sum[i - 1] + (s[i] -  0 );       if (sum[i] >= 1000000007) sum[i] -= 1000000007;     }   }   void euclid(int a, int b, long long& x, long long& y) {     if (b == 0) {       x = 1;       y = 0;     } else {       long long x0, y0;       euclid(b, a % b, x0, y0);       x = y0;       y = x0 - (a / b) * y0;     }   }   int invers_modular(int n) {     long long x, y;     euclid(n, 1000000007, x, y);     while (x < 0) x += 1000000007;     return (int)x;   }   int comb(int n, int k) {     if (k > n) return 0;     int Ret = fact[n];     Ret = 1LL * Ret * invers_modular(fact[n - k]) % 1000000007;     Ret = 1LL * Ret * invers_modular(fact[k]) % 1000000007;     return Ret;   }   int main() {     ios_base::sync_with_stdio(false);     int n, k;     cin >> n >> k;     cin >> s;     powers_of_10(n);     factorials(n);     sums(n);     int FirstSum = 0;     int SecondSum = 0;     for (int i = 0; i < n; i++) {       FirstSum += 1LL * (s[i] -  0 ) * powm[n - 1 - i] * comb(i, k) % 1000000007;       if (FirstSum >= 1000000007) FirstSum -= 1000000007;     }     for (int i = 0; i <= n - 2; i++) {       SecondSum += 1LL * (1LL * sum[n - i - 2] * powm[i] % 1000000007) *                    comb(n - i - 2, k - 1) % 1000000007;       if (SecondSum >= 1000000007) SecondSum -= 1000000007;     }     cout << (SecondSum + FirstSum) % 1000000007;   }


#include <bits/stdc++.h>   using namespace std;   inline char gc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline long long read() {     long long x = 0;     char ch = getchar();     bool positive = 1;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) positive = 0;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return positive ? x : -x;   }   inline void write(long long a) {     if (a < 0) {       a = -a;       putchar( - );     }     if (a >= 10) write(a / 10);     putchar( 0  + a % 10);   }   inline void writeln(long long a) {     write(a);     puts(  );   }   inline void wri(long long a) {     write(a);     putchar(   );   }   long long t, l, r;   long long dp[35][2][2];   long long calc(long long x, long long y) {     if (x < 0 || y < 0) return 0;     memset(dp, 0, sizeof(dp));     dp[32][1][1] = 1;     for (long long i = 31; i >= 0; i--) {       for (int j = 0; j <= 1; j++) {         for (int k = 0; k <= 1; k++) {           long long nextj = (j && !((x >> i) & 1));           long long nextk = (k && !((y >> i) & 1));           dp[i][nextj][nextk] += dp[i + 1][j][k];           if (!j || ((x >> i) & 1)) dp[i][j][nextk] += dp[i + 1][j][k];           if (!k || ((y >> i) & 1)) dp[i][nextj][k] += dp[i + 1][j][k];         }       }     }     return dp[0][0][0] + dp[0][0][1] + dp[0][1][0] + dp[0][1][1];   }   int main() {     t = read();     while (t--) {       l = read(), r = read();       writeln(calc(r, r) - 2 * calc(l - 1, r) + calc(l - 1, l - 1));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = (int)1010;   set<int> ans;   int n, m;   char a[MAXN][MAXN];   int posk[MAXN];   int posG[MAXN];   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];         if (a[i][j] ==  S ) {           posk[i] = j;         }         if (a[i][j] ==  G ) {           posG[i] = j;         }       }     }     for (int i = 0; i < n; i++) {       if (posG[i] > posk[i]) {         cout << -1;         return 0;       } else {         ans.insert((int)posG[i] - posk[i] + 1);       }     }     cout << ans.size();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     bool flag = 0;     long long sum1 = 0, sum2 = 0;     void operator+=(const node& rhs) {       flag |= rhs.flag;       sum1 += rhs.sum1;       sum2 = max(sum2, rhs.sum2);     }   };   const int N = 200200;   int n, m, s, T;   int par[N], siz[N];   int tin[N], low[N];   long long a[N];   vector<int> edges[N], tree[N];   vector<pair<int, int>> bridges;   int findSetId(int u) { return (par[u] == u ? u : par[u] = findSetId(par[u])); }   void findBridges(int u = 1, int p = -1) {     tin[u] = low[u] = ++T;     for (int v : edges[u]) {       if (v == p) {         continue;       }       if (tin[v] == 0) {         findBridges(v, u);         if (low[v] > tin[u]) {           bridges.push_back({u, v});         } else {           int x = findSetId(u);           int y = findSetId(v);           if (x != y) {             par[y] = x;             siz[x] += siz[y];             a[x] += a[y];           }         }       }       low[u] = min(low[u], low[v]);     }   }   void buildBridgeTree() {     for (int i = 1; i <= n; ++i) {       par[i] = i, siz[i] = 1;     }     findBridges();     for (auto& b : bridges) {       int u = findSetId(b.first);       int v = findSetId(b.second);       tree[u].push_back(v);       tree[v].push_back(u);     }   }   node solve(int u = s, int p = -1) {     node ret;     for (int v : tree[u]) {       if (v == p) {         continue;       }       ret += solve(v, u);     }     if (siz[u] > 1 || ret.flag) {       ret.sum1 += a[u], ret.flag = 1;     } else {       ret.sum2 += a[u];     }     return ret;   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       scanf( %lld , a + i);     }     while (m--) {       int u, v;       scanf( %d %d , &u, &v);       edges[u].push_back(v);       edges[v].push_back(u);     }     cin >> s;     buildBridgeTree();     auto out = solve(findSetId(s));     cout << out.sum1 + out.sum2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long double n;     cin >> n;     if (n <= 127) {       cout <<  byte ;     } else if (n <= 32767) {       cout <<  short ;     } else if (n <= 2147483647) {       cout <<  int ;     } else if (n <= 9223372036854775807LL) {       cout <<  long ;     } else {       cout <<  BigInteger ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       if (n <= 6)         cout << 15 << endl;       else {         long long int r = n % 6;         long long int y = ((n - r - 6) / 6) * 15;         if (r != 0) long long int y = ((n - r - 6) / 6) * 15;         if (r + 6 <= 6)           y = y + 15;         else if (r + 6 <= 8)           y = y + 20;         else if (r + 6 <= 10)           y = y + 25;         else           y = y + 30;         cout << y << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   char a[1005];   char b[1005];   int t[1005];   int sum[1005];   int main() {     memset(t, 0, sizeof(t));     int p, n, m;     cin >> n >> m >> p;     cin >> a >> b;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i + j] != b[j])           break;         else if (j == m - 1)           t[i] = 1;       }     }     sum[0] = t[0];     for (int i = 1; i < n; i++) sum[i] = sum[i - 1] + t[i];     while (p--) {       int l, r;       scanf( %d%d , &l, &r);       l--, r--;       if (n < m || r - l + 1 < m)         cout << 0 << endl;       else         cout << sum[r - m + 1] - sum[l - 1] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200006;   int a[MAXN], b[MAXN];   int N;   int main() {     while (scanf( %d , &N) != EOF) {       int i, j;       int x;       int n = 0, m = 0;       long long suma = 0, sumb = 0;       int win = 0;       int last;       for (i = 1; i <= N; i++) {         scanf( %d , &x);         if (x > 0) {           a[++n] = x;           suma += x;           last = 1;         } else {           b[++m] = -x;           sumb += (-x);           last = 2;         }       }       if (suma > sumb)         win = 1;       else if (suma < sumb)         win = 2;       else {         for (i = 1, j = 1; i <= n && j <= m; i++, j++) {           if (a[i] > b[j]) {             win = 1;             break;           } else if (a[i] < b[j]) {             win = 2;             break;           }         }         if (i > n && j > m)           win = last;         else if (i > n && j <= m)           win = 2;         else if (i <= n && j > m)           win = 1;       }       if (win == 1)         printf( first n );       else if (win == 2)         printf( second n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double eps = 1e-6;   const int MAXN = 1e5 + 10;   const int MAXM = 1e6 + 10;   const long long mod = 1e9 + 7;   int a[1010];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     int ans = 0;     for (int i = 1; i < n - 1; i++) {       if (a[i] > a[i - 1] && a[i] > a[i + 1]) ans++;       if (a[i] < a[i - 1] && a[i] < a[i + 1]) ans++;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double eps = 1e-20;   int main() {     int n, a, d;     cin >> n >> a >> d;     int *t = new int[n];     int *v = new int[n];     double ans = -1.0;     for (int i = 0; i < n; i++) cin >> t[i] >> v[i];     for (int i = 0; i < n; i++) {       double t1 = (v[i] + 0.0) / (a + 0.0);       double t2 = (d - a * t1 * t1 * 0.5) / (v[i] + 0.0);       if (a * t1 * t1 * 0.5 >= d) {         t1 = sqrt(2.0 * d / (a + 0.0));         t2 = 0;       }       double tt = t1 + t2 + t[i];       if (tt > ans) {         printf( %.6f n , tt);         ans = tt;       } else         printf( %.6f n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 110;   const int M = 1010;   double f[N][M * N], sum[N * M];   int a[N], n, m, s;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , a + i);       s += a[i];     }     f[0][0] = 1;     sum[0] = 1.0;     for (int j = 1; j < s; j++) sum[j] = sum[j - 1] + f[0][j];     for (int i = 1; i <= n; i++) {       for (int j = i; j < s; j++) {         int l = min(m, j - i + 1);         int r = max(-1, j - l - 1);         double tmp = sum[j - 1] - ((r == -1) ? 0 : sum[r]);         if (l < a[i])           f[i][j] = tmp / (m - 1);         else           f[i][j] = (tmp - f[i - 1][j - a[i]]) / (m - 1);       }       sum[0] = 0;       for (int j = 1; j < s; j++) {         sum[j] = sum[j - 1] + f[i][j];       }     }     double ans = 0;     for (int i = n; i < s; i++) {       ans += f[n][i];     }     printf( %.10f n , 1 + ans * (m - 1));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[111], x[111], saven;   long double f[2][100111], sum[2][100111];   int main() {     ios ::sync_with_stdio(0);     cin.tie(0);     cout << (fixed) << setprecision(12);     while (cin >> n >> m) {       int sumA = 0;       for (int i = (1), _b = (n); i <= _b; ++i) {         int x;         cin >> x;         --x;         a[i] = x;         sumA += x;       }       if (m == 1) {         cout << 1.0 << endl;         continue;       }       for (int i = (1), _b = (n); i <= _b; ++i) {         int cur = i % 2;         memset(f[cur], 0, sizeof f[cur]);         if (i == 1) {           for (int val = 0, _a = (m * i); val < _a; ++val)             if (val < m && val != a[i]) f[cur][val] = 1;         } else {           for (int val = 0, _a = (m * i); val < _a; ++val) {             f[cur][val] = sum[1 - cur][val];             if (val >= m) f[cur][val] -= sum[1 - cur][val - m];             f[cur][val] -= f[1 - cur][val - a[i]];           }         }         for (int val = 0, _a = (m * (i + 1)); val < _a; ++val) {           sum[cur][val] = f[cur][val];           if (val > 0) sum[cur][val] += sum[cur][val - 1];         }       }       long double t = sum[n % 2][sumA - 1];       for (int turn = 0, _a = (n); turn < _a; ++turn) t /= (m - 1);       cout << t * (m - 1.0) + 1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;      int n, k;      void solve(){       cin >> n >> k;          int cnt = 1;          int query = 0;          for(int i = 0; i < n; i++){           if(i) query = i ^ (i - 1);           cout << query << endl;           int r;           cin >> r;           if(r == 1) return;       }   }      int main(){       // freopen( inp.txt ,  r , stdin);       // freopen( out.txt ,  w , stdout);       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);          int t;       cin >> t;       while(t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int n, m, i, x, y, k, a, q, h, l, r, j, p, s[400];   vector<int> ve[51][51];   bool ok1, ok2, Find, ok[51][51];   void get(int x, int y, int z) {     q = 105;     h = 104;     for (int i = 1; i < ve[x][y].size(); i++) {       s[++h] = ve[x][y][i];       if (i == z) l = h, r = h + 1;     }     while (q != l && h - q + 1 <= 2 * n) {       if (ve[s[l - 1]][s[l]].size() == 0) return;       for (int i = ve[s[l - 1]][s[l]].size() - 1; i; i--)         s[--q] = ve[s[l - 1]][s[l]][i];       l--;     }     if (h - q + 1 > 2 * n) return;     while (h != r && h - q + 1 <= 2 * n) {       if (ve[s[r]][s[r + 1]].size() == 0) return;       for (int i = 1; i < ve[s[r]][s[r + 1]].size(); i++)         s[++h] = ve[s[r]][s[r + 1]][i];       r++;     }     if (h - q + 1 > 2 * n) return;     Find = true;   }   int main() {     scanf( %d%d , &n, &m);     for (i = 1; i <= m; i++) {       scanf( %d%d%d , &x, &y, &k);       ok1 = false;       ok2 = false;       ve[x][y].push_back(0);       a = 0;       while (k--) {         if (a != x)           ok1 = false;         else           ok1 = true;         scanf( %d , &a);         if (a == y && ok1) ok2 = true;         ve[x][y].push_back(a);       }       if (ok2) ok[x][y] = true;     }     for (i = 1; i <= n; i++)       for (j = 1; j <= n; j++)         if (ok[i][j])           for (p = 1; p < ve[i][j].size() - 1; p++)             if (ve[i][j][p] == i && ve[i][j][p + 1] == j) {               get(i, j, p);               if (Find) {                 printf( %d n , h - q + 1);                 for (i = q; i <= h; i++) printf( %d  , s[i]);                 printf(  n );                 return 0;               }             }     printf( 0 n );   }


#include <bits/stdc++.h>   using namespace std;   const long double PI = 3.141592653589793238462643383;   int w;   int visit[37] = {0};   int Ceil(int a, int b) {     if (a % b == 0)       return a / b;     else       return (a / b) + 1;   }   struct TrieNode {     struct TrieNode *children[37];     bool isEndofWord;     int cnt[37];     int snum[37];     int visit[37];   };   TrieNode *getNode() {     TrieNode *x = new TrieNode;     x->isEndofWord = false;     for (int i = 0; i < (37); ++i) x->children[i] = NULL;     for (int i = 0; i < (37); ++i) x->cnt[i] = 0;     for (int i = 0; i < (37); ++i) x->snum[i] = -1;     for (int i = 0; i < (37); ++i) x->visit[i] = -1;     return x;   }   int find(char c) {     if (c ==  . ) {       return 26;     }     if (c >=  a  && c <=  z ) {       return c -  a ;     }     return 27 + c -  0 ;   }   void insert(TrieNode *root, string s, int num) {     TrieNode *p = root;     for (int i = 0; i < (s.size()); ++i) {       int index;       index = find(s[i]);       if (!p->children[index]) {         p->children[index] = getNode();       }       if (p->visit[index] != num) p->cnt[index]++;       p->snum[index] = num;       p->visit[index] = num;       p = p->children[index];     }     p->isEndofWord = true;   }   int search(TrieNode *root, string s) {     TrieNode *p = root;     int ans;     for (int i = 0; i < (s.size()); ++i) {       int index;       index = find(s[i]);       if (!p->children[index]) {         return 0;       }       ans = p->cnt[index];       w = p->snum[index];       p = p->children[index];     }     return ans;   }   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cin.exceptions(cin.failbit);     int n;     cin >> n;     string a[n];     TrieNode *root = getNode();     int e = 0;     while (n--) {       string s;       cin >> s;       a[e] = s;       e++;       int y = s.size() - 1;       for (int i = 0; i < (s.size()); ++i) {         string str;         int x = s.size() - i;         str.resize(x);         int q = 0;         for (int j = i; j <= (y); ++j) {           str[q] = s[j];           q++;         }         insert(root, str, e);       }     }     int q;     cin >> q;     while (q--) {       string s;       cin >> s;       int y = search(root, s);       if (y == 0) {         cout <<  0 -  <<   n ;       } else {         cout << y <<     << a[w - 1] <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:64000000 )   using namespace std;   int main() {     long long n;     cin >> n;     vector<long long> v;     long long mx = -1, mn = -1;     for (long long i = 1; i * i <= n; i++)       if (n % i == 0) {         v.push_back(i);         v.push_back(n / i);       }     sort((v).begin(), (v).end());     for (int i = 0; i < (int)(v).size(); i++) {       long long rest = n / v[i];       for (int j = 0; j < (int)(v).size(); j++)         if (rest % v[j] == 0) {           long long a = v[i] + 1;           long long b = v[j] + 2;           long long c = rest / v[j] + 2;           mx = max(mx, a * b * c - (a - 1) * (b - 2) * (c - 2));           if (mn == -1) mn = a * b * c - (a - 1) * (b - 2) * (c - 2);           mn = min(mn, a * b * c - (a - 1) * (b - 2) * (c - 2));         }     }     cout << mn <<     << mx;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10, inf = 1e9 + 10, P = 53, MOD = 1e9 + 7;   int n, a, b, k, q, seg1[4 * maxn], seg2[4 * maxn];   inline void update(int ind) {     seg1[ind] = seg1[((ind) * (2))] + seg1[(((ind) * (2)) + 1)];     seg2[ind] = seg2[((ind) * (2))] + seg2[(((ind) * (2)) + 1)];   }   void add(int s, int e, int ind, int l, int r, int x) {     if (s >= r || e <= l) return;     if (s >= l && e <= r) {       seg1[ind] += x;       seg2[ind] += x;       seg1[ind] = min(seg1[ind], b);       seg2[ind] = min(seg2[ind], a);       return;     }     int mid = (s + e) / 2;     add(s, mid, ((ind) * (2)), l, r, x);     add(mid, e, (((ind) * (2)) + 1), l, r, x);     update(ind);   }   int query(int type, int s, int e, int ind, int l, int r) {     if (s >= r || e <= l) return 0;     if (s >= l && e <= r) {       if (type == 1)         return seg1[ind];       else         return seg2[ind];     }     int mid = (s + e) / 2;     return query(type, s, mid, ((ind) * (2)), l, r) +            query(type, mid, e, (((ind) * (2)) + 1), l, r);   }   int main() {     scanf( %d%d%d%d%d , &n, &k, &a, &b, &q);     while (q--) {       int type, l, x;       scanf( %d , &type);       if (type == 1) {         scanf( %d%d , &l, &x);         add(0, n, 1, l - 1, l, x);       } else {         scanf( %d , &x);         x--;         printf( %d n , query(1, 0, n, 1, 0, x) + query(2, 0, n, 1, x + k, n));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 100;   struct node {     int x, y;   } point[maxn];   bool check(node a, node b, node c, node d) {     if (a.x - b.x == c.x - d.x && a.y - b.y == c.y - d.y) return true;     return false;   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) cin >> point[i].x >> point[i].y;     if (n & 1) {       cout <<  nO  << endl;     } else {       bool flag = true;       for (int i = 0; i < n; ++i) {         if (!check(point[(i + 1) % n], point[i], point[(i + n / 2) % n],                    point[(i + n / 2 + 1) % n]))           flag = false;       }       if (flag)         cout <<  YES  << endl;       else         cout <<  nO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e3 + 10;   const long long M = 1e9 + 7;   long long Max(long long a, long long b) {     if (a > b) return a;     return b;   }   long long Min(long long a, long long b) {     if (a > b) return b;     return a;   }   long long big_mul(long long a, long long b, long long m) {     long long x = 0, y = a % m;     while (b > 0) {       if (b & 1) x = (x + y) % m;       y = (2 * y) % m;       b >>= 1;     }     return x % m;   }   long long big_mod(long long a, long long b, long long m) {     long long x = 1, y = a % m;     while (b > 0) {       if (b & 1) x = (x * y) % m;       y = (y * y) % m;       b >>= 1;     }     return x % m;   }   long long Big_mod(long long a, long long b, long long m) {     long long x = 1, y = a % m;     while (b > 0) {       if (b & 1) x = big_mul(x, y, m);       y = big_mul(y, y, m);       b >>= 1;     }     return x % m;   }   long long mod_inverse(long long a, long long m) { return big_mod(a, m - 2, m); }   unordered_map<string, bool> Map;   int a, b, c, d, e, f, g, h;   vector<pair<int, int> > vec;   vector<pair<pair<int, int>, int> > save;   void fnct(int x1, int y1, int x2, int y2) {     if (x1 < x2 && y1 > y2) {       a = x1;       b = y2;       c = x1;       d = y1;       e = x2;       f = y1;       g = x2;       h = y2;     } else if (x1 > x2 && y1 < y2) {       a = x2;       b = y1;       c = x2;       d = y2;       e = x1;       f = y2;       g = x1;       h = y1;     } else if (x1 < x2 && y1 < y2) {       a = x1;       b = y1;       c = x1;       d = y2;       e = x2;       f = y2;       g = x2;       h = y1;     } else {       a = x2;       b = y2;       c = x2;       d = y1;       e = x1;       f = y1;       g = x1;       h = y2;     }   }   double dis(double w, double z, double p, double q) {     double n = w - p;     double m = z - q;     return sqrt(n * n + m * m);   }   bool check(double p, double q) {     for (int i = 0; i < save.size(); i++) {       double w = (double)(save[i].first.first);       double z = (double)(save[i].first.second);       double r = (double)(save[i].second);       if (dis(w, z, p, q) <= r) return true;     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     fnct(x1, y1, x2, y2);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int w, z, r;       cin >> w >> z >> r;       if (Map[to_string(w) + to_string(z) + to_string(r)] == false)         save.push_back(make_pair(make_pair(w, z), r));       Map[to_string(w) + to_string(z) + to_string(r)] = true;     }     for (int i = c; i <= e; i++) vec.push_back(make_pair(i, d));     for (int i = a; i <= g; i++) vec.push_back(make_pair(i, b));     for (int i = d - 1; i > b; i--) vec.push_back(make_pair(a, i));     for (int i = f - 1; i > h; i--) vec.push_back(make_pair(e, i));     int ans = 0;     for (int i = 0; i < vec.size(); i++) {       double p = (double)(vec[i].first);       double q = (double)(vec[i].second);       if (check(p, q) == false) ans++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[100010];   bool b[100010];   long long gcd(long long a, long long b) { return a % b ? gcd(b, a % b) : b; }   int main() {     long long n, t;     scanf( %lld , &n);     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       b[i] = a[i] % 2;     }     long long ans = gcd(abs(a[1]), abs(a[2]));     for (int i = 3; i <= n; i++) ans = gcd(ans, abs(a[i]));     if (ans > 1)       printf( YES n0 n );     else {       int num = 0;       for (int i = 1; i < n; i++)         while (b[i] == 1) {           if (b[i + 1] == 1) {             b[i] = 0;             b[i + 1] = 0;           } else {             b[i + 1] = 1;           }           ++num;         }       if (b[n] == 1) num += 2;       printf( YES n%d n , num);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const long long INF = 1000000007;   const long long INF2 = 1000000007LL * 1000000007LL;   const long double EPS = 1e-9;   const int SIZE = 1001000;   int n, a, b;   string fn[SIZE];   int val[SIZE], ans[SIZE];   int z[SIZE];   vector<int> g[SIZE];   void setVal(int v) {     if (fn[v][0] ==  I ) {       return;     }     for (auto& i : g[v]) setVal(i);     if (fn[v][0] ==  A ) {       val[v] = val[g[v][0]] && val[g[v][1]];       return;     }     if (fn[v][0] ==  O ) {       val[v] = val[g[v][0]] || val[g[v][1]];       return;     }     if (fn[v][0] ==  X ) {       val[v] = (val[g[v][0]] + val[g[v][1]]) % 2;       return;     }     val[v] = !val[g[v][0]];   }   void dfs(int v, int zn) {     if (fn[v][0] ==  I ) {       z[v] = zn;       return;     }     if (zn == 0) {       for (auto& i : g[v]) dfs(i, 0);       return;     }     if (fn[v][0] ==  A ) {       if (val[v] == 1) {         for (auto& i : g[v]) dfs(i, 1);       } else {         if (!val[g[v][0]] && val[g[v][1]]) {           dfs(g[v][0], 1);           dfs(g[v][1], 0);         } else if (val[g[v][0]] && !val[g[v][1]]) {           dfs(g[v][0], 0);           dfs(g[v][1], 1);         } else {           for (auto& i : g[v]) dfs(i, 0);         }       }       return;     }     if (fn[v][0] ==  O ) {       if (val[v] == 0) {         for (auto& i : g[v]) dfs(i, 1);       } else {         if (val[g[v][0]] && val[g[v][1]]) {           dfs(g[v][0], 0);           dfs(g[v][1], 0);         } else if (!val[g[v][0]] && val[g[v][1]]) {           dfs(g[v][0], 0);           dfs(g[v][1], 1);         } else if (val[g[v][0]] && !val[g[v][1]]) {           dfs(g[v][0], 1);           dfs(g[v][1], 0);         }       }       return;     }     for (auto& i : g[v]) dfs(i, zn);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> fn[i];       if (fn[i] ==  IN ) {         cin >> val[i];       } else if (fn[i] ==  NOT ) {         cin >> a;         --a;         g[i].push_back(a);       } else {         cin >> a;         --a;         g[i].push_back(a);         cin >> a;         --a;         g[i].push_back(a);       }     }     setVal(0);     dfs(0, 1);     for (int i = 0; i < n; ++i) {       if (fn[i][0] ==  I ) {         if (z[i])           cout << !val[0];         else           cout << val[0];       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 202;   const int MAXM = 50005;   struct edge {     int a, b;     long long int g, s;     edge(int a_ = 0, int b_ = 0, long long int g_ = 0LL, long long int s_ = 0LL) {       a = a_, b = b_, g = g_, s = s_;     }   };   int N, M, cnt;   int dad[MAXN];   long long int G, S, res = 1LL << 62;   edge g[MAXM];   edge way[MAXM];   inline bool compare(const edge &a, const edge &b) { return a.g < b.g; }   inline int find(int a) {     if (a == dad[a]) return a;     return dad[a] = find(dad[a]);   }   int main() {     scanf(  %d %d %I64d %I64d , &N, &M, &G, &S);     for (int i = 1; i <= M; i++) {       scanf(  %d %d %I64d %I64d , &way[i].a, &way[i].b, &way[i].g, &way[i].s);       way[i].g *= G;       way[i].s *= S;     }     sort(way + 1, way + M + 1, compare);     for (int i = 1; i <= M; i++) {       g[++cnt] = way[i];       for (int j = cnt; j > 1; j--) {         if (g[j].s < g[j - 1].s)           swap(g[j], g[j - 1]);         else           break;       }       if (i >= N - 1) {         long long int ss;         for (int j = 1; j <= N; j++) dad[j] = j;         int c = 0;         int ncnt = 0;         for (int j = 1; j <= cnt; j++)           if (find(g[j].a) != find(g[j].b)) {             c++;             g[++ncnt] = g[j];             ss = g[j].s;             dad[find(g[j].a)] = g[j].b;           }         cnt = ncnt;         if (c == N - 1) res = min(res, way[i].g + ss);       }     }     if (res == 1LL << 62)       printf( -1 n );     else       printf( %I64d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, id, nxt[100005], num[100005], mark[100005];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &nxt[i]);       if (nxt[i] == i) {         puts( YES );         for (int j = 1; j <= n; j++)           if (j != i) printf( %d %d n , i, j);         return 0;       }     }     for (int i = 1; i <= n; i++) {       if (num[i]) continue;       int j = nxt[i], t = 1;       while (j != i) j = nxt[j], t++;       while (!num[j]) num[j] = t, j = nxt[j];       if (t & 1) {         puts( NO );         return 0;       }       if (t == 2) id = i;     }     if (!id) {       puts( NO );       return 0;     }     puts( YES );     printf( %d %d n , id, nxt[id]);     for (int i = 1; i <= n; i++) {       if (i == id || i == nxt[id] || mark[i]) continue;       int a = id, b = i;       while (num[i]--) {         printf( %d %d n , a, b);         mark[b] = 1;         a = nxt[a];         b = nxt[b];       }     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     int ara[n];     int temp, j;     int i = 0;     while (i < n) {       scanf( %d , &ara[i]);       i++;     }     i = 0;     while (i < (n - 1)) {       j = 0;       while (j < (n - 1)) {         if (ara[j] > ara[j + 1]) {           temp = ara[j];           ara[j] = ara[j + 1];           ara[j + 1] = temp;         }         j++;       }       i++;     }     i = 0;     while (i < n) {       printf( %d  , ara[i]);       i++;     }     return 0;   }


#include <bits/stdc++.h>   #define MP make_pair   using namespace std;      #define rep(i, n) for (int i = 0; i < (int)(n); ++ i)   #define rep1(i, n) for (int i = 1; i <= (int)(n); ++ i)   #define foreach(itr, c) for (__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); ++ itr)      typedef long long LL;   typedef pair<int, int> pii;      const int MAXN = 2e5 + 5;      int N;   string str[MAXN];   map<string, vector<string> > grps;   LL ans;      int solve_pair(const string& s1, const string& s2)   {       int prefix = 0, suffix = 0, n = s1.size();          while (s1[prefix] == s2[prefix]) prefix ++;       while (s1[n - suffix - 1] == s2[n - suffix - 1]) suffix ++;          return is_sorted(s1.begin() + prefix, s1.end() - suffix) || is_sorted(s2.begin() + prefix, s2.end() - suffix) ? 1ll : 2ll;   }   void solve(vector<string>& grp)   {       int n = grp.size(), len = grp[0].size();       ans -= 1ll * (n - 1) * n / 2 * 1337;          if (n <= 200 * len) {           rep(i, n) for (int j = i + 1; j < n; ++ j) {               ans += solve_pair(grp[i], grp[j]);           }       } else {           sort(grp.begin(), grp.end());           ans += 1ll * (n - 1) * n / 2 * 2;              for (auto& s : grp) {               rep(i, len) for (int j = i + 2; j <= len; ++ j) {                   string sorted = s;                   sort(sorted.begin() + i, sorted.begin() + j);                   ans -= (sorted[i] != s[i] && sorted[j - 1] != s[j - 1] && binary_search(grp.begin(), grp.end(), sorted));               }           }       }   };      int main()   {       scanf( %d , &N);       rep(i, N) {           cin >> str[i];           string sorted = str[i];           sort(sorted.begin(), sorted.end());           grps[sorted].push_back(str[i]);       }          ans = 1ll * (N - 1) * N / 2 * 1337;          for (auto& grp : grps) solve(grp.second);          printf( %lld n , ans);              return 0;   }


#include <iostream>   #include <cmath>   #include <map>   #include <string>   #include <vector>   #include <algorithm>   #define int long long   using namespace std;   string s;   int a, b, c;   int n, m, k;   vector<int>vec, vec2;   int arr[4000000], mark[4000000];   signed main() {    ios_base::sync_with_stdio(false);    cin.tie(NULL);    cout.tie(NULL);    cin >> n >> m >> k;    for (int i = 0; i < n; i++) {     cin >> a;     vec.push_back(a);    }    for (int i = 0; i < m; i++) {     cin >> a;     vec2.push_back(a);    }    if (n < m) {     swap(n, m);     swap(vec, vec2);    }    int iter = 0;    for (auto i : vec) {     mark[iter] = m;     iter++;     arr[i] = iter;    }    iter = 0;    int pos;    for (auto i : vec2) {     iter++;     if (arr[i] != 0) {      pos = (arr[i] - iter + n) % n;      mark[pos]--;     }    }    pos = 0;    int sum = 0;    int len = 0;    while (true) {     sum += mark[pos];     pos += m;     len += m;     pos %= n;     if (pos == 0) {      break;     }    }    k -= 2;    int ans = (k / sum);    ans *= len;    k %= sum;    k += 2;    pos = 0;    while (k > mark[pos]) {     k -= mark[pos];     pos += m;     ans += m;     pos %= n;    }    int pos2 = 0;    while (k > 0) {     ans++;     if (vec[(pos + pos2) % n] != vec2[pos2 % m]) {      k--;     }     pos2++;    }    cout << ans;    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 15;   const int inf = 1e9;   const int md = 1e9 + 7;   const int shift = 1 << 17;   int n, m;   vector<vector<int> > g;   set<pair<int, int> > br;   int timer;   int tin[maxn], fup[maxn];   int used[maxn];   void dfs(int v, int p = -1) {     used[v] = 1;     tin[v] = fup[v] = timer++;     for (int i = 0; i < g[v].size(); ++i) {       int to = g[v][i];       if (to == p) continue;       if (used[to])         fup[v] = min(fup[v], tin[to]);       else {         dfs(to, v);         fup[v] = min(fup[v], fup[to]);         if (fup[to] > tin[v]) {           br.insert(make_pair(to, v));           br.insert(make_pair(v, to));         }       }     }   }   int color[maxn];   int first[maxn];   int d[maxn];   vector<int> eu;   int z[shift * 2];   int c;   void dfs2(int v, int tekc, int len, int p = -1) {     used[v] = 1;     color[v] = tekc;     d[tekc] = len;     for (int i = 0; i < g[v].size(); ++i) {       int to = g[v][i];       if (to == p) continue;       if (used[to]) continue;       if (br.find(make_pair(v, to)) != br.end()) {         eu.push_back(c + 1);         first[c + 1] = eu.size() - 1;         ++c;         dfs2(to, c, len + 1, v);         eu.push_back(tekc);       } else         dfs2(to, tekc, len, v);     }   }   void build() {     for (int i = 0; i < eu.size(); ++i) z[i + shift] = eu[i];     for (int i = eu.size(); i < shift; ++i) z[i + shift] = n + 1;     for (int i = shift - 1; i > 0; --i)       if (d[z[i * 2]] < d[z[i * 2 + 1]])         z[i] = z[i * 2];       else         z[i] = z[i * 2 + 1];   }   int get(int v, int tl, int tr, int l, int r) {     if (l > r) return n + 1;     if (l == tl && r == tr) return z[v];     int tm = (tl + tr) / 2;     int ans1 = get(v * 2, tl, tm, l, min(r, tm));     int ans2 = get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);     return d[ans1] < d[ans2] ? ans1 : ans2;   }   int main() {     cin >> n >> m;     g.resize(n);     for (int i = 0; i < m; ++i) {       int v, u;       cin >> v >> u;       --v, --u;       g[v].push_back(u);       g[u].push_back(v);     }     dfs(0);     memset(used, 0, sizeof(used));     memset(first, -1, sizeof(first));     eu.push_back(0);     first[0] = 0;     dfs2(0, 0, 0);     d[n + 1] = inf;     build();     int k;     cin >> k;     for (int i = 0; i < k; ++i) {       int s, l;       cin >> s >> l;       --s, --l;       int L = first[color[s]];       int R = first[color[l]];       if (L > R) swap(L, R);       int lca = get(1, 0, shift - 1, L, R);       cout << d[color[s]] + d[color[l]] - 2 * d[lca] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, siz[500010];   vector<int> v[500010];   class DS {    public:     long long dat[2][2];     DS() { memset(dat, 0, sizeof(dat)); }     DS(long long a00, long long a01, long long a10, long long a11) {       dat[0][0] = a00;       dat[0][1] = a01;       dat[1][0] = a10;       dat[1][1] = a11;     }     DS trans() {       return DS(dat[1][0], dat[0][0] + dat[1][1], dat[0][0], dat[0][1]);     }     DS operator*(const DS &t) const {       DS ret;       for (int i = 0; i < 2; i++) {         for (int j = 0; j < 2; j++) {           for (int k = 0; k + i < 2; k++) {             for (int l = 0; j + l < 2; l++) {               ret.dat[i + k][j + l] += dat[i][j] * t.dat[k][l];             }           }         }       }       return ret;     }   } f[500010], g[500010];   void dfs(int np, int fath) {     f[np] = DS(1, 0, 0, 0);     siz[np] = 1;     for (int &x : v[np]) {       if (x == fath) continue;       dfs(x, np);       siz[np] += siz[x];       f[np] = f[np] * f[x].trans();     }   }   void dfs2(int np, int fath) {     vector<DS> pre;     pre.push_back(DS(1, 0, 0, 0));     for (int i = 0; i < v[np].size(); i++) {       if (v[np][i] == fath)         pre.push_back(pre.back());       else         pre.push_back(pre.back() * f[v[np][i]].trans());     }     DS cur = fath ? g[np].trans() : DS(1, 0, 0, 0);     for (int i = (int)v[np].size() - 1; i >= 0; i--) {       if (v[np][i] == fath) continue;       g[v[np][i]] = cur * pre[i];       dfs2(v[np][i], np);       cur = cur * f[v[np][i]].trans();     }   }   int main() {     scanf( %d , &n);     if (n & 1) {       puts( 0 );       return 0;     }     for (int i = 1, a, b; i < n; i++) {       scanf( %d%d , &a, &b);       v[a].push_back(b);       v[b].push_back(a);     }     dfs(1, 0);     dfs2(1, 0);     long long ans = 0;     for (int i = 2; i <= n; i++) {       if (f[i].dat[1][0] == 1 && g[i].dat[1][0] == 1)         ans += (long long)siz[i] * (n - siz[i]);       else         ans +=             (f[i].dat[0][0] + f[i].dat[1][1]) * (g[i].dat[0][0] + g[i].dat[1][1]);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, u, a[300001], x, y;   long double ans = -1.0;   int main() {     cin >> n >> u;     for (int i = 0; i < n; ++i) cin >> a[i];     y = 1;     while (x < n - 2) {       while (y < n - 1 && a[y + 1] - a[x] <= u) ++y;       if (y - x >= 2 && a[y] - a[x] <= u)         ans =             max(ans, (long double)(a[y] - a[x + 1]) / (long double)(a[y] - a[x]));       ++x;     }     printf( %.9Lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 5;   int n, m, cnt, belong[N];   vector<int> g[N], ans[N];   int get(int x) { return belong[x] ? belong[x] = get(belong[x]) : x; }   void dfs(int i) {     ans[cnt].push_back(i);     belong[i] = i + 1;     for (int j = get(1), k = 0; j <= n; j = get(j + 1)) {       for (; k < g[i].size() && g[i][k] < j; k++)         ;       if (k < g[i].size() && g[i][k] == j) continue;       dfs(j);     }   }   int main() {     scanf( %d%d , &n, &m);     while (m--) {       int a, b;       scanf( %d%d , &a, &b);       g[a].push_back(b);       g[b].push_back(a);     }     for (int i = 1; i <= n; i++) sort(g[i].begin(), g[i].end());     for (int i = 1; i <= n; i++)       if (!belong[i]) {         dfs(i);         cnt++;       }     printf( %d n , cnt);     for (int i = 0; i < cnt; i++) {       printf( %u , ans[i].size());       for (int j = 0; j < ans[i].size(); j++) printf(  %d , ans[i][j]);       puts(  );     }   }


#include <bits/stdc++.h>   using namespace std;   int q, n;   int a[100010], b[100010];   int main() {     scanf( %d , &q);     while (q--) {       scanf( %d , &n);       for (int i = 1; i <= n; i++) scanf( %d , &a[i]);       for (int i = 1; i <= n; i++) scanf( %d , &b[i]);       int pos = 0, dis = 0, flag1 = 0, flag2 = 0;       for (int i = 1; i <= n; i++) {         if (a[i] != b[i] && flag1 == 0) {           pos = i;           dis = b[i] - a[i];           if (dis < 0) {             flag2 = 1;             break;           }           flag1 = 1;         } else if (a[i] != b[i] && flag1 == 1) {           if (b[i] - a[i] != dis || i != pos + 1) {             flag2 = 1;             break;           } else             pos = i;         }       }       if (flag2)         printf( NO n );       else         printf( YES n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int OO = (int)2e9;   const double eps = 1e-9;   int x[3], y[3];   int main() {     int i;     vector<pair<int, int> > V(8);     set<int> X;     set<int> Y;     for (i = 0; i < 8; i++) {       cin >> V[i].first >> V[i].second;       X.insert(V[i].first);       Y.insert(V[i].second);     }     i = 0;     for (__typeof((X).begin()) it = (X).begin(); it != (X).end(); ++it)       x[i++] = *it;     i = 0;     for (__typeof((Y).begin()) it = (Y).begin(); it != (Y).end(); ++it)       y[i++] = *it;     vector<pair<int, int> > C(8);     C[0] = make_pair(x[0], y[0]);     C[1] = make_pair(x[0], y[1]);     C[2] = make_pair(x[0], y[2]);     C[3] = make_pair(x[1], y[0]);     C[4] = make_pair(x[1], y[2]);     C[5] = make_pair(x[2], y[0]);     C[6] = make_pair(x[2], y[1]);     C[7] = make_pair(x[2], y[2]);     sort((V).begin(), (V).end());     if (((int)(X).size()) != 3 || ((int)(Y).size()) != 3 || V != C)       puts( ugly );     else       puts( respectable );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[4000];   int ans[4000][4000];   int main() {     cin >> n;     map<int, int> r;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (r.find(a[i]) == r.end()) {         int k = r.size();         r[a[i]] = k;       }       a[i] = r[a[i]];     }     int m = r.size();     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (ans[j][a[i]] + 1 > ans[a[i]][j]) {           ans[a[i]][j] = ans[j][a[i]] + 1;         }       }     }     int best = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (ans[i][j] > best) {           best = ans[i][j];         }       }     }     cout << best << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int a[100001], b[100001];   vector<long long int> v;   map<long long int, long long int> assign;   pair<long long int, long long int> dp[1001][7001];   inline long long int gcd(long long int a, long long int b) {     long long int tmp;     while (b) {       tmp = a % b;       a = b;       b = tmp;     }     return a;   }   int main() {     ios::sync_with_stdio(false);     ;     cin.tie(0);     ;     long long int i, j, n, k, x, y, temp, sz;     cin >> n >> k;     temp = k;     for (i = 1; i <= n; i++) {       cin >> a[i];       b[i] = gcd(a[i], k);       temp = temp / gcd(temp, a[i]);     }     if (temp != 1) {       cout <<  -1 ;       return 0;     }     if (k == 1) {       cout <<  1             <<   n ;       cout << min_element(a + 1, a + n + 1) - a;       return 0;     }     for (i = 1; i * i <= k; i++) {       if (k % i) continue;       v.push_back(i);       if (i != (k / i)) v.push_back(k / i);     }     sort(v.begin(), v.end());     sz = v.size();     for (i = 0; i < sz; i++) assign[v[i]] = i;     for (i = 1; i < sz; i++) dp[0][i] = make_pair(1000000000000, 0);     dp[0][0] = make_pair(0, 0);     for (i = 1; i <= n; i++) {       for (j = 0; j < sz; j++) {         dp[i][j] = dp[i - 1][j];         x = assign[v[j] / gcd(v[j], b[i])];         if (dp[i][j] >             make_pair(dp[i - 1][x].first + 1, dp[i - 1][x].second + a[i]))           dp[i][j] =               make_pair(dp[i - 1][x].first + 1, dp[i - 1][x].second + a[i]);       }     }     cout << dp[n][sz - 1].first <<   n ;     x = k;     for (i = n; i >= 1; i--) {       if (dp[i][assign[x]] == dp[i - 1][assign[x]]) continue;       cout << i <<    ;       x = x / gcd(x, b[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 30;   const int N = 200111;   struct node {     int i, j;     long long mn, ad = 0;     node *l, *r;     node(long long *a, int i, int j) : i(i), j(j) {       if (j - i == 1) {         l = r = NULL;         mn = a[i];       } else {         int k = i + j >> 1;         l = new node(a, i, k);         r = new node(a, k, j);         combine();       }     }     inline void combine() { mn = min(l->mn, r->mn); }     void visit() {       if (ad) {         mn += ad;         if (l) l->ad += ad, r->ad += ad;         ad = 0;       }     }     void inc(int I, int J, long long a) {       if (I <= i && j <= J) {         ad += a;         visit();       } else {         visit();         if (!(J <= i || j <= I)) {           l->inc(I, J, a);           r->inc(I, J, a);           combine();         }       }     }     int find() {       visit();       if (mn > 0) return INF;       if (!l) {         return mn == 0 ? i : INF;       } else {         int ans = INF;         if (ans >= INF) ans = l->find();         if (ans >= INF) ans = r->find();         return ans;       }     }   };   long long a[N], s[N];   int main() {     int n, q;     scanf( %d%d , &n, &q);     for (int i = 0; i < n; i++) {       scanf( %lld , &a[i]);       s[i + 1] = s[i] + a[i];     }     for (int i = 0; i < n; i++) {       s[i] -= a[i];     }     node *t = new node(s, 0, n);     while (q--) {       int i;       long long v;       scanf( %d%lld , &i, &v);       long long d = v - a[--i];       t->inc(i, i + 1, -d);       t->inc(i + 1, n, +d);       t->visit();       a[i] += d;       int ans = t->find();       printf( %d n , ans >= INF ? -1 : ans + 1);     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2501;   mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());   int n, p[2 * N], a[N][N], cur;   void no() {     puts( NOT MAGIC );     exit(0);   }   struct edge {     int u, v, w;     edge(int a = 0, int b = 0, int c = 0) {       u = a;       v = b;       w = c;     }     bool operator<(const edge &a) const { return w < a.w; }   };   int get(int u) { return u == p[u] ? u : p[u] = get(p[u]); }   vector<edge> e;   vector<pair<int, int>> g[2 * N];   void dfs(int u, int p, int mx) {     if (u >= n && a[cur][u - n] > mx) no();     for (auto i : g[u])       if (i.first != p) dfs(i.first, u, max(mx, i.second));   }   int main() {     for (int i = 0; i < 2 * N; i++) p[i] = i;     scanf( %d , &n);     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         scanf( %d , &a[i][j]);         e.push_back(edge(i, n + j, a[i][j]));       }     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         if (a[i][j] != a[j][i] || i == j && a[i][j]) no();       }     sort(e.begin(), e.end());     for (auto i : e) {       int a = get(i.u);       int b = get(i.v);       if (a != b) {         p[a] = b;         g[i.u].push_back({i.v, i.w});         g[i.v].push_back({i.u, i.w});       }     }     for (int i = 0; i < n; i++) {       cur = i;       dfs(i, -1, 0);     }     puts( MAGIC );   }


#include <bits/stdc++.h>   using ll = long long;   const ll maxn = 1234;   const ll inf = 1e9 + 7;   int main(int argc, char *argv[]) {     ll n, m, a[maxn];     std::cin >> n >> m;     ll cur = 0, maxx = 0, minn = 0;     for (int i = 0; i < n; i++) {       std::cin >> a[i];       cur += a[i];       maxx = std::max(maxx, cur);       minn = std::min(minn, cur);     }     ll ans = maxx - minn;     if (maxx - minn > m) {       std::cout << 0;     } else {       std::cout << m - (maxx - minn) + 1;     }   }


/*   Author: QAQAutoMaton   Lang: C++   Code: F.cpp   Mail: lk@qaq-am.com   Blog: https://www.qaq-am.com/   */   #include<bits/stdc++.h>   #define int long long   #define debug(qaq...) fprintf(stderr,qaq)   #define DEBUG printf( Passing [%s] in LINE %d n ,__FUNCTION__,__LINE__)   #define Debug debug( Passing [%s] in LINE %d n ,__FUNCTION__,__LINE__)   #define all(x) x.begin(),x.end()   #define x first   #define y second   #define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())   using namespace std;   typedef unsigned uint;   typedef long long ll;   typedef unsigned long long ull;   typedef complex<double> cp;   typedef pair<int,int> pii;   int inf;   const double eps=1e-8;   const double pi=acos(-1.0);   template<class T,class T2>int chkmin(T &a,T2 b){return a>b?a=b,1:0;}   template<class T,class T2>int chkmax(T &a,T2 b){return a<b?a=b,1:0;}   template<class T>T sqr(T a){return a*a;}   template<class T,class T2>T mmin(T a,T2 b){return a<b?a:b;}   template<class T,class T2>T mmax(T a,T2 b){return a>b?a:b;}   template<class T>T aabs(T a){return a<0?-a:a;}   template<class T>int dcmp(T a,T b){return a>b;}   template<int *a>int cmp_a(int x,int y){return a[x]<a[y];}   template<class T>bool sort2(T &a,T &b){return a>b?swap(a,b),1:0;}   #define min mmin   #define max mmax   #define abs aabs   struct __INIT__{    __INIT__(){     fill((unsigned char*)&inf,(unsigned char*)&inf+sizeof(inf),0x3f);    }   }__INIT___;   namespace io {    const int SIZE = (1 << 21) + 1;    char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;    // getchar    #define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)    // print the remaining part    inline void flush () {     fwrite (obuf, 1, oS - obuf, stdout);     oS = obuf;    }    // putchar    inline void putc (char x) {     *oS ++ = x;     if (oS == oT) flush ();    }    template<typename A>    inline bool read (A &x) {     for (f = 1, c = gc(); c <  0  || c >  9 ; c = gc()) if (c ==  - ) f = -1;else if(c==EOF)return 0;     for (x = 0; c <=  9  && c >=  0 ; c = gc()) x = x * 10 + (c & 15); x *= f;     return 1;    }    inline bool read (char &x) {     while((x=gc())==   ||x==  n  || x==  r );     return x!=EOF;    }    inline bool read(char *x){     while((*x=gc())==  n  || *x==   ||*x==  r );     if(*x==EOF)return 0;     while(!(*x==  n ||*x==   ||*x==  r ||*x==EOF))*(++x)=gc();     *x=0;     return 1;    }    template<typename A,typename ...B>    inline bool read(A &x,B &...y){     return read(x)&&read(y...);    }    template<typename A>    inline bool write (A x) {     if (!x) putc ( 0 ); if (x < 0) putc ( - ), x = -x;     while (x) qu[++ qr] = x % 10 +  0 ,  x /= 10;     while (qr) putc (qu[qr --]);     return 0;    }    inline bool write (char x) {     putc(x);     return 0;    }    inline bool write(const char *x){     while(*x){putc(*x);++x;}     return 0;    }    inline bool write(char *x){     while(*x){putc(*x);++x;}     return 0;    }    template<typename A,typename ...B>    inline bool write(A x,B ...y){     return write(x)||write(y...);    }    //no need to call flush at the end manually!    struct Flusher_ {~Flusher_(){flush();}}io_flusher_;   }   using io :: read;   using io :: putc;   using io :: write;   int p[200005];   int a[200005],b[200005];   int to[200005],mn[200005];   int fa[19][200005],f[19][200005];   int stk[200005],cnt[200005];   int query(int l,int r){    if(l==r)return 0;    int ans=0;    for(int i=18;~i;--i)if(fa[i][l]<=r){     ans+=f[i][l];l=fa[i][l];    }    return ans;   }   int ans[200005];   vector<pii> xa[200005],xd[200005];   void add(int l,int r,int id){    xa[r].emplace_back(l,id);   }   void del(int l,int r,int id){    xd[r].emplace_back(l,id);   }   set<int> st;   bitset<200005>cur;   int t;   int ask(int x){    int v=lower_bound(stk+1,stk+t+1,x)-stk;    return cnt[t]-cnt[v]+query(x,stk[v]);   }   signed main(){   #ifdef QAQAutoMaton     freopen( F.in , r ,stdin);    freopen( F.out , w ,stdout);   #endif    int n,q;     read(n,q);    for(int i=1;i<=n;++i)read(p[i]);    p[n+1]=n+1;    for(int i=1;i<=n;++i)read(a[i]);    for(int i=1;i<=n;++i)read(b[i]);    stk[0]=n+1;    for(int i=0;i<=18;++i){     fa[i][n+1]=n+1;f[i][n+1]=0;    }    for(int i=n;i;--i){     while(p[stk[t]]<p[i])--t;     int j=stk[t];     stk[++t]=i;     to[i]=j;     mn[i]=min(b[i],a[i]+query(i+1,j));     f[0][i]=mn[i];fa[0][i]=to[i];     //write(i,   ,to[i],   ,mn[i],  n );     for(int j=1;j<=18;++j){fa[j][i]=fa[j-1][fa[j-1][i]];f[j][i]=f[j-1][i]+f[j-1][fa[j-1][i]];}    }    st.insert(1);st.insert(n+1);    add(1,n+1,0);    for(int i=1;i<=q;++i){     int x;     read(x);     if(x==1)continue;     if(cur[x]){      auto it=st.lower_bound(x);      auto l=it,r=it;      --l;++r;      add(*l,*r,i);      del(*l,x,i);      del(x,*r,i);      st.erase(it);      cur[x]=0;     }     else{      cur[x]=1;      auto r=st.lower_bound(x);      auto l=r;      --l;      del(*l,*r,i);      add(*l,x,i);      add(x,*r,i);      st.insert(x);     }    }    stk[t=0]=0;    p[0]=n+2;    for(int i=1;i<=n+1;++i){     while(p[stk[t]]<p[i]){      --t;      }     stk[++t]=i;     cnt[t]=cnt[t-1]+(a[stk[t-1]]+query(stk[t-1]+1,stk[t]));     for(auto x:xa[i]){ans[x.y]+=ask(x.x);}     for(auto x:xd[i]){ans[x.y]-=ask(x.x);}    }    for(int i=1;i<=q;++i){     ans[i]+=ans[i-1];     write(ans[i],  n );    }    return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   struct BIT {     vector<int> tree;     BIT(int sz) { tree = vector<int>(sz + 1, 0); }     void upd(int idx, int v) {       for (idx++; idx < tree.size(); idx += idx & -idx) {         tree[idx] += v;       }     }     int query(int idx) {       int res = 0;       for (idx++; idx > 0; idx -= idx & -idx) {         res += tree[idx];       }       return res;     }   };   int n, l, ss[100000];   long long w, res;   bool solved[100000];   vector<pair<int, long long> > adj[100000];   void dfs1(int node, int par = -1) {     ss[node] = 1;     for (const pair<int, long long> edge : adj[node]) {       int next = edge.first;       if (next != par && !solved[next]) {         dfs1(next, node);         ss[node] += ss[next];       }     }   }   int find(int node) {     dfs1(node);     int par = -1;     int total = ss[node];     while (1) {       bool breakout = true;       for (const pair<int, long long> edge : adj[node]) {         int next = edge.first;         if (!solved[next] && next != par && ss[next] * 2 > total) {           par = node;           node = next;           breakout = false;           break;         }       }       if (breakout) {         break;       }     }     return node;   }   vector<pair<int, long long> > combine(       vector<vector<pair<int, long long> > >& vec) {     vector<pair<int, long long> > res;     for (const vector<pair<int, long long> > v : vec) {       res.insert(res.end(), (v).begin(), (v).end());     }     return res;   }   long long count(const vector<pair<int, long long> >& _v) {     vector<pair<int, long long> > v(_v);     sort((v).begin(), (v).end(),          [](pair<int, long long>& a, pair<int, long long>& b) -> bool {            return make_pair(a.second, a.first) < make_pair(b.second, b.first);          });     vector<int> fVals;     for (const pair<int, long long> p : v) {       fVals.push_back(p.first);     }     sort((fVals).begin(), (fVals).end());     long long ret = 0;     int j = 0;     BIT x(fVals.size());     for (int i = (v.size()) - 1; i >= 0; i--) {       while (j < i && v[j].second + v[i].second <= w) {         x.upd(lower_bound((fVals).begin(), (fVals).end(), v[j++].first) -                   fVals.begin(),               1);       }       if (j > i) {         x.upd(lower_bound((fVals).begin(), (fVals).end(), v[--j].first) -                   fVals.begin(),               -1);       }       ret += x.query(upper_bound((fVals).begin(), (fVals).end(), l - v[i].first) -                      fVals.begin() - 1);     }     return ret;   }   void dfs2(int node, int par, vector<pair<int, long long> >& v, int depth = 0,             long long depth2 = 0) {     v.push_back(make_pair(depth, depth2));     for (const pair<int, long long> edge : adj[node]) {       int next = edge.first;       if (next != par && !solved[next]) {         dfs2(next, node, v, depth + 1, depth2 + edge.second);       }     }   }   void solve(int node) {     node = find(node);     vector<vector<pair<int, long long> > > vec;     vec.push_back(vector<pair<int, long long> >(1, make_pair(0, 0)));     for (const pair<int, long long> edge : adj[node]) {       int next = edge.first;       if (!solved[next]) {         vec.push_back(vector<pair<int, long long> >());         dfs2(next, node, vec.back(), 1, edge.second);       }     }     for (vector<pair<int, long long> >& v : vec) {       res -= count(v);     }     res += count(combine(vec));     solved[node] = true;     for (const pair<int, long long> edge : adj[node]) {       int next = edge.first;       if (!solved[next]) {         solve(next);       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> l >> w;     for (int i = 0; i < (n - 1); i++) {       int p;       long long weight;       cin >> p >> weight;       p--;       adj[p].push_back(make_pair(i + 1, weight));       adj[i + 1].push_back(make_pair(p, weight));     }     solve(0);     cout << res <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   void A() {     cout <<  tokitsukaze  << endl;     exit(0);   }   void B() {     cout <<  quailty  << endl;     exit(0);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, k;     cin >> n >> k;     string s;     cin >> s;     set<int> p[2];     for (int i = 0; i < n; ++i) {       p[s[i] -  0 ].insert(i);     }     int m[2], M[2];     if (p[0].empty() || p[1].empty()) {       A();     }     m[0] = *p[0].begin();     M[0] = *--p[0].end();     m[1] = *p[1].begin();     M[1] = *--p[1].end();     if (M[0] - m[0] + 1 <= k || M[1] - m[1] + 1 <= k) {       A();     }     bool b = true;     for (int i = 0; i < n - k + 1; ++i) {       bool ok = false;       int l, r;       l = min(m[0], i);       r = max(M[0], i + k - 1);       if (r - l + 1 <= k) {         ok = true;       }       if (m[1] < i) {         l = m[1];       } else {         l = *p[1].lower_bound(i + k);       }       if (M[1] >= i + k) {         r = M[1];       } else {         r = *--p[1].lower_bound(i);       }       if (r - l + 1 <= k) {         ok = true;       }       if (!ok) {         b = false;       }       ok = false;       l = min(m[1], i);       r = max(M[1], i + k - 1);       if (r - l + 1 <= k) {         ok = true;       }       if (m[0] < i) {         l = m[0];       } else {         l = *p[0].lower_bound(i + k);       }       if (M[0] >= i + k) {         r = M[0];       } else {         r = *--p[0].lower_bound(i);       }       if (r - l + 1 <= k) {         ok = true;       }       if (!ok) {         ok = false;       }     }     if (b) {       B();     }     cout <<  once again  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     char ch = getchar();     int f = 0, x = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) x = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       f = (f << 1) + (f << 3) + ch -  0 ;       ch = getchar();     }     return f * x;   }   int a[200005], b[600005], m, n;   bool check(int x) {     int l = 1, r = 3 * n;     for (int i = 1; i <= n; i++) {       while (a[i] - b[l] > x) l++;       while (b[r] - a[i] > x) r--;       l++;       r++;     }     return l <= r;   }   int main() {     n = read();     m = read();     for (int i = 1; i <= n; i++) a[i] = read();     for (int i = 1; i <= n; i++) b[i] = read();     for (int i = 1; i <= n; i++) {       b[i + n] = b[i] - m;       b[i + 2 * n] = b[i] + m;     }     sort(b + 1, b + 3 * n + 1);     sort(a + 1, a + n + 1);     int l = 0, r = (m + 1) >> 1, ans = 0;     while (l <= r) {       int mid = l + r >> 1;       if (check(mid)) {         ans = mid;         r = mid - 1;       } else         l = mid + 1;     }     cout << ans;   }


#include <bits/stdc++.h>   const int MAXN = 100100;   char S[MAXN];   char T[MAXN];   int aS[MAXN], aT[MAXN];   int bS[MAXN], bT[MAXN];   bool go() {     int leftS, rightS, leftT, rightT;     scanf( %d %d %d %d , &leftS, &rightS, &leftT, &rightT);     int lengthS = rightS - leftS + 1;     int lengthT = rightT - leftT + 1;     int as = aS[rightS];     if (as > lengthS) as = lengthS;     int at = aT[rightT];     if (at > lengthT) at = lengthT;     int bs = bS[rightS] - bS[leftS - 1];     int bt = bT[rightT] - bT[leftT - 1];     if (bs % 2 != bt % 2) {       return false;     }     if (bs > bt) {       return false;     }     if (as < at) {       return false;     }     if (bs == bt) {       if (as % 3 != at % 3) {         return false;       }     } else {       if (bs == 0 && as == at) {         return false;       }     }     return true;   }   void goA(char *s, int *ar) {     int run = 0;     for (int i = 1; s[i]; ++i) {       if (s[i] ==  A )         ++run;       else         run = 0;       ar[i] = run;     }   }   void goB(char *s, int *ar) {     int run = 0;     for (int i = 1; s[i]; ++i) {       if (s[i] ==  B  || s[i] ==  C ) ++run;       ar[i] = run;     }   }   int main() {     scanf( %s , S + 1);     scanf( %s , T + 1);     goA(S, aS);     goA(T, aT);     goB(S, bS);     goB(T, bT);     int q;     scanf( %d , &q);     for (int i = 0; i < q; ++i) {       if (go()) {         printf( 1 );       } else {         printf( 0 );       }     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> a(n);       cout << 2 << endl;       int prev = (n + n - 1) / 2;       if ((n + n - 1) % 2 != 0) prev++;       cout << n <<     << n - 1 << endl;       for (int i = n - 2; i >= 1; i--) {         int ad = 0;         cout << i <<     << prev << endl;         if ((i + prev) % 2 != 0) ad = 1;         prev = (i + prev) / 2 + ad;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long int l, r;     cin >> l >> r;     long long int p = 1;     long long int sum = 0;     for (long long int i = 0; i < 32; i++) {       for (long long int j = 0; j < 32; j++) {         long long int x = pow(2, i) * pow(3, j);         if (x > r) break;         if (x >= l && x <= r) sum++;       }     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   struct rge {     T b, e;   };   template <class T>   rge<T> range(T i, T j) {     return rge<T>{i, j};   }   template <class T>   auto dud(T *x) -> decltype(cerr << *x, 0);   template <class T>   char dud(...);   struct debug {     template <class T>     debug &operator<<(const T &) {       return *this;     }   };   const int N = 1e5 + 5;   const int M = N;   const int inf = 1e9 + 7;   struct dsu {     vector<int> pr;     dsu(int n) : pr(n + 5) { iota(pr.begin(), pr.end(), 0); }     int find(int u) { return pr[u] == u ? u : pr[u] = find(pr[u]); }     void unite(int u, int v) {       u = find(u), v = find(v);       if (u != v) {         pr[v] = u;         debug() <<  the boss of                                         <<  v                      :                   << (v)                 <<                         is                                         <<  u                      :                   << (u) <<    ;       }     }   };   struct query {     int t, u, v, doc;   };   vector<int> graph[N];   int pr[N], dep[N], tot[N], heavy[N];   int head[N], pos[N], who[N];   set<pair<int, int> > st[N];   vector<query> queries;   int indeg[N];   int timer = 0;   int n, m;   int dfs(int u) {     tot[u] = 1, heavy[u] = head[u] = 0;     for (int v : graph[u])       if (v != pr[u]) {         pr[v] = u;         dep[v] = dep[u] + 1;         tot[u] += dfs(v);         if (tot[v] > tot[heavy[u]]) heavy[u] = v;       }     return tot[u];   }   void hld(int u, int h) {     head[u] = h, pos[u] = ++timer, who[timer] = u;     if (heavy[u] != 0) hld(heavy[u], h);     for (int v : graph[u])       if (v != pr[u] && v != heavy[u]) hld(v, v);   }   template <class F>   void process_path(int u, int v, F fun) {     for (; head[u] != head[v]; v = pr[head[v]]) {       if (dep[head[u]] > dep[head[v]]) swap(u, v);       fun(pos[head[v]], pos[v]);     }     if (dep[u] > dep[v]) swap(u, v);     if (u != v) fun(pos[heavy[u]], pos[v]);     fun(pos[u], pos[u]);   }   void update_path(int u, int v, int doc) {     debug() <<  sign from                                 <<  u                  :               << (u)             <<                     to                                 <<  v                  :               << (v)             <<                                    <<  doc                  :               << (doc) <<    ;     process_path(u, v, [&](int l, int r) { st[doc].insert({l, r}); });   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m;     int doc = 0;     for (auto i = (0) - ((0) > (m)); i != m - ((0) > (m));          i += 1 - 2 * ((0) > (m))) {       query q;       cin >> q.t >> q.u;       if (q.t == 1) {         cin >> q.v;         swap(q.u, q.v);         graph[q.u].push_back(q.v);         indeg[q.v]++;       } else if (q.t == 2) {         q.doc = ++doc;         st[doc].insert({-inf, -inf});         st[doc].insert({inf, inf});       } else if (q.t == 3)         cin >> q.doc;       queries.push_back(q);     }     for (auto u = (1) - ((1) > (n + 1)); u != n + 1 - ((1) > (n + 1));          u += 1 - 2 * ((1) > (n + 1)))       if (indeg[u] == 0) {         dfs(u);         hld(u, u);       }     dsu boss(n);     for (auto &q : queries) {       if (q.t == 1)         boss.unite(q.u, q.v);       else if (q.t == 2)         update_path(q.u, boss.find(q.u), q.doc);       else {         debug() <<                     <<  st[q.doc]                      :                   << (st[q.doc]) <<    ;         int k = pos[q.u];         auto it = --st[q.doc].upper_bound({k, inf});         debug() <<                     <<  k                      :                   << (k)                 <<                                            <<  *it                      :                   << (*it) <<    ;         for (auto jt : {prev(it), it, next(it)})           if (jt != st[q.doc].end())             if (jt->first <= k && k <= jt->second) {               k = inf;               break;             }         cout << (k == inf ?  YES  :  NO ) <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   int lcm(int a, int b) { return (a * b) / gcd(a, b); }   int fact(int n) {     if (n == 0 || n == 1)       return 1;     else       return n * fact(n - 1);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, a = 0, b = 0, l1 = 0, l2 = 0, c = 0, k = 0;       cin >> n;       deque<int> q;       for (int i = 0, x; i < n; i++) {         cin >> x;         q.push_back(x);       }       while (!q.empty()) {         while (l1 <= l2 && !q.empty()) {           a += q.front();           l1 += q.front();           q.pop_front();           k = 1;         }         c += k;         k = l2 = 0;         while (l2 <= l1 && !q.empty()) {           b += q.back();           l2 += q.back();           q.pop_back();           k = 1;         }         c += k;         k = l1 = 0;       }       cout << c <<     << a <<     << b << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, m, st[N], fn[N], timer, ans[N];   vector<int> adj[N], vec[N];   struct node {     long long sum, lazy, sz, one;     node() { sum = one = sz = lazy = 0; }   } seg[N << 2];   void dfs1(int v, int p = -1) {     st[v] = timer++;     for (auto u : adj[v]) {       if (u == p) continue;       dfs1(u, v);     }     fn[v] = timer;   }   void build(int id = 1, int b = 0, int e = n) {     if (e - b == 1) {       seg[id].sz = 1;       return;     }     int mid = (b + e) >> 1, lc = id * 2, rc = lc | 1;     build(lc, b, mid);     build(rc, mid, e);     seg[id].sz = seg[lc].sz + seg[rc].sz;     return;   }   void add(int l, int r, int val, int id = 1, int b = 0, int e = n) {     if (l >= e || b >= r) return;     if (l <= b && e <= r) {       seg[id].one += val;       return;     }     int mid = (b + e) >> 1, lc = id * 2, rc = lc | 1;     add(l, r, val, lc, b, mid);     add(l, r, val, rc, mid, e);     seg[id].sum = ((seg[lc].one) ? seg[lc].sz : seg[lc].sum) +                   ((seg[rc].one) ? seg[rc].sz : seg[rc].sum);     return;   }   void dfs2(int v, int p = -1) {     if (vec[v].size()) vec[v].push_back(v);     for (auto u : vec[v]) {       int l = st[u], r = fn[u];       add(l, r, 1);     }     ans[v] = ((seg[1].one) ? n : seg[1].sum);     if (ans[v]) ans[v]--;     for (auto u : adj[v]) {       if (u == p) continue;       dfs2(u, v);     }     for (auto u : vec[v]) {       int l = st[u], r = fn[u];       add(l, r, -1);     }   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m;     for (int i = 0; i < n - 1; i++) {       int v, u;       cin >> v >> u;       v--, u--;       adj[v].push_back(u);       adj[u].push_back(v);     }     dfs1(0);     build();     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       a--, b--;       int l = st[b], r = fn[b];       vec[a].push_back(b);       l = st[a], r = fn[a];       vec[b].push_back(a);     }     dfs2(0);     for (int i = 0; i < n; i++) cout << ans[i] <<    ;     cout <<   n ;   }


#include <bits/stdc++.h>   #define ll long long   #define F first   #define S second   #define pb push_back   #define P push   #define B break   #define C continue   #define R return   #define gcd(x,y) __gcd(x,y)   #define be(a) a.begin(),a.end()   #define lb(a,x) (lower_bound(be(a),x)-a.begin())   #define ub(a,x) (upper_bound(be(a),x)-a.begin())   #define uniq(a) a.resize(unique(be(a))-a.begin())   #define fast ios::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);   #define po(x) (x%mod+mod)%mod   #define SM(x,y) (po(x)+po(y))%mod   #define M(x,y)  (po(x)*po(y))%mod   using namespace std;   ll t,n,i,j,k,l,r,mid,mod=1e9+7,m,ans;   ll a[400005],f[400005],c[400005];   char ch;   map<ll,ll>mp;   //set<ll>s;   string s,st;   //vector<ll>v[300005],u;   double x,y,z,v,d[105][105],eps=1e-9;   bool b[106][105];   double dp(int i,int j){       double &ret=d[i][j];       if(b[i][j]) R ret;       b[i][j]=1;       ret=0;       double X,Y,Z;       Z=z+((i+j)*v)/2.0;       X=x+(j*v/2.0)-i*v;       Y=y+(i*v/2.0)-j*v;       if(X<eps) {           X*=-1;           Y-=X/2.0;           Z-=X/2.0;           X=1;           for(k=1;;k++) {               ret+=Z*X*(i+j+k);               if(Y<eps) R ret;               X*=Y;               Y-=v;               Z+=v;               Z=min(Z,1.0);           }           R ret;       }       if(Y<eps) {           Y*=-1;           X-=Y/2.0;           Z-=Y/2.0;           Y=1;           for(k=1;;k++) {               ret+=Z*Y*(i+j+k);               if(X<eps) R ret;               Y*=X;               X-=v;               Z+=v;               Z=min(Z,1.0);           }           R ret;       }       R ret=X*dp(i+1,j)+Y*dp(i,j+1)+Z*(i+j+1);   }   int ff(){       cin>>x>>y>>z>>v;       memset(b,0,sizeof b);       double ans=dp(0,0);       cout<<fixed<<setprecision(8)<<ans;       R 0;   }   int main()   {       fast       cin>>t;       while(t--){           ff();           cout<<  n ;       }   }   /**      */


#include <bits/stdc++.h>   using namespace std;   const long long linf = 1e18 + 9;   const int inf = 1e9 + 9;   const int N = 1e3 + 9;   int n, m, c[N], d[N], a[N], b[N], dp[N][N], ans;   int main() {     cin >> n >> m >> c[0] >> d[0];     for (int i = 1; i <= m; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         int mx = -inf;         for (int k = 0; k <= a[j] / b[j]; k++) {           if (i - c[j] * k < 0) continue;           mx = max(mx, dp[i - c[j] * k][j - 1] + d[j] * k);         }         dp[i][j] = mx;       }     }     for (int i = 0; i <= n; i++) ans = max(ans, dp[i][m] + (n - i) / c[0] * d[0]);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using ld = long double;   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& v) {     for (size_t i = 0; i < v.size(); ++i) {       os << v[i];       if (i + 1 != v.size()) {         os <<    ;       }     }     return os;   }   void solve() {     int n;     cin >> n;     vector<ll> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     vector<ll> v = a;     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     int m;     cin >> m;     while (m--) {       int k, pos;       cin >> k >> pos;       --k;       int mn = v[k];       int j = k - 1;       while (j >= 0 && v[k] == v[j]) {         --j;       }       int cnt = k - j;       for (int i = 0; i < n; ++i) {         if (a[i] > mn) {           --pos;         } else if (a[i] == mn) {           if (cnt > 0) {             --pos;             --cnt;           }         }         if (pos == 0) {           cout << a[i] <<   n ;           break;         }       }     }   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1);   const int INF = 1e9;   const double inf = 1e15;   const double eps = 1e-9;   const long long MOD = 1e9 + 7;   long long toNum(string s) {     stringstream ss(s);     long long ret;     ss >> ret;     return ret;   }   string toString(long long x) {     stringstream ss;     ss << x;     return ss.str();   }   long long mulMod(long long a, long long b) { return (a * b) % MOD; }   long long addMod(long long a, long long b) { return (a + b) % MOD; }   long long redMod(long long a, long long b) {     return addMod(addMod(a, -b), MOD);   }   long long fast(long long a, long long b) {     if (b == 0) return 1;     long long tmp = fast(a, b / 2);     tmp = mulMod(tmp, tmp);     if (b & 1) tmp = mulMod(tmp, a);     return tmp;   }   long long GCD(long long a, long long b) {     if (a == 0) return b;     return GCD(b % a, a);   }   const int N = 1e5 + 5;   const int BLOCK = 300;   const int CBLOCK = N / BLOCK + 5;   pair<int, int> jmp[N];   int arr[N];   int n, q;   vector<pair<int, int> > lst;   pair<int, int> query(int x) {     int cur = x;     int nxt = jmp[cur].first;     int nod = x, val = 1;     while (cur != nxt) {       val += jmp[cur].second;       nod = nxt;       cur = nxt;       nxt = jmp[cur].first;     }     return make_pair(nod, val);   }   void update(int a, int b) {     arr[a] = b;     int idx = (a - 1) / BLOCK;     int st = idx * BLOCK + 1;     int en = min(n, (idx + 1) * BLOCK);     for (int i = en; i >= st; i -= 1) {       int nxt = i + arr[i];       nxt = min(nxt, n + 1);       if (nxt == n + 1) {         jmp[i] = make_pair(i, 0);       } else {         if ((nxt - 1) / BLOCK != idx) {           jmp[i] = make_pair(nxt, 1);         } else {           jmp[i] = make_pair(jmp[nxt].first, jmp[nxt].second + 1);         }       }     }   }   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> q;     for (int i = 1; i <= n; i += 1) cin >> arr[i];     for (int i = n; i >= 1; i -= 1) {       int nxt = i + arr[i];       nxt = min(nxt, n + 1);       if (nxt == n + 1) {         jmp[i] = make_pair(i, 0);       } else {         if ((nxt - 1) / BLOCK != (i - 1) / BLOCK) {           jmp[i] = make_pair(nxt, 1);         } else {           jmp[i] = make_pair(jmp[nxt].first, jmp[nxt].second + 1);         }       }     }     int ins, a, b;     for (int i = 1; i <= q; i += 1) {       cin >> ins >> a;       if (ins == 0) {         cin >> b;         update(a, b);       } else {         pair<int, int> ans = query(a);         cout << ans.first <<     << ans.second << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long iinf = 1 << 29;   const long long inf = 1ll << 60;   const long long mod = 1e9 + 7;   void GG() {     cout <<  No n ;     exit(0);   }   long long mpow(long long a, long long n) {     long long re = 1;     while (n > 0) {       if (n & 1) re = re * a % mod;       a = a * a % mod;       n >>= 1;     }     return re;   }   long long inv(long long b) {     if (b == 1) return b;     return (mod - mod / b) * inv(mod % b) % mod;   }   const long long maxn = 5e6 + 1;   const double PI = acos(-1.0);   void FFT(vector<complex<double> > &a, bool rev = 0) {     long long n = (long long)a.size();     assert(__builtin_popcount(n) <= 1);     for (long long i = 1, j = 0; i < n; i++) {       long long bit = n / 2;       while (j >= bit) j -= bit, bit /= 2;       j += bit;       if (i < j) swap(a[i], a[j]);     }     for (long long B = 2; B <= n; B *= 2) {       double ang = 2 * PI / B * (rev ? -1 : 1);       complex<double> w0(cos(ang), sin(ang));       for (long long i = 0; i < n; i += B) {         complex<double> w(1, 0);         for (long long j = 0; j < B / 2; j++) {           complex<double> u = a[i + j], v = w * a[i + j + B / 2];           a[i + j] = u + v, a[i + j + B / 2] = u - v;           w *= w0;         }       }     }     if (rev)       for (long long i = 0; i < (n); i++) a[i] /= n;   }   vector<long long> mul(vector<long long> a, vector<long long> b) {     long long n = 1;     while (n < (long long)a.size() + (long long)b.size()) n *= 2;     vector<complex<double> > x(n), y(n);     for (long long i = 0; i < ((long long)a.size()); i++)       x[i] = complex<double>(a[i], 0);     for (long long j = 0; j < ((long long)b.size()); j++)       y[j] = complex<double>(b[j], 0);     FFT(x);     FFT(y);     for (long long i = 0; i < (n); i++) x[i] *= y[i];     FFT(x, 1);     vector<long long> re(n);     for (long long i = 0; i < (n); i++) re[i] = (long long)(round(x[i].real()));     while (re.size() > 1 && re.back() == 0) re.pop_back();     return re;   }   signed main() {     long long n, x;     cin >> n >> x;     vector<long long> a(n);     vector<long long> b;     long long cnt = 1;     long long zed = 0;     for (long long i = 0; i < (n); i++) {       cin >> a[i];       if (a[i] < x) {         b.push_back(cnt);         cnt = 0;       }       cnt++;     }     b.push_back(cnt);     for (long long y : b) zed += (y - 1) * (y) / 2;     vector<long long> c = b;     reverse(c.begin(), c.end());     vector<long long> d = mul(b, c);     cout << zed <<    ;     for (long long i = ((long long)b.size()); i < ((long long)b.size() + n);          i++) {       if (i < (long long)d.size())         cout << d[i] <<    ;       else         cout << 0 <<    ;     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   const double PI = acos(-1.0);   using namespace std;   const int N = 509, M = 1000000;   int n, m, dis[N][N], in[N][N], ans[N][N], t[N][N];   vector<int> adj[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     cin >> n >> m;     int u, v, d;     memset(dis,  ? , sizeof dis);     for (int i = 1; i <= m; i++) {       cin >> u >> v >> d;       adj[u].push_back(v);       adj[v].push_back(u);       dis[u][v] = dis[v][u] = d;       t[u][v] = t[v][u] = d;     }     for (int i = 1; i <= n; i++) dis[i][i] = 0;     for (int k = 1; k <= n; k++)       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++)           dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i == j) continue;         for (auto k : adj[j]) {           if (dis[i][k] + t[k][j] == dis[i][j]) in[i][j]++;         }       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         for (int k = 1; k <= n; k++) {           if (dis[i][k] + dis[k][j] == dis[i][j]) ans[i][j] += in[i][k];         }       }     }     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) {         if (dis[i][j] >= dis[502][502])           cout <<  0  ;         else           cout << ans[i][j] <<    ;       }     return 0;   }


#include <bits/stdc++.h>   int main() {     int tux;     scanf( %d , &tux);     int foo = 0, bar = 0, baz = 0, quz = 1;     for (int i = 0; i < tux; i++) {       int pur;       scanf( %d , &pur);       foo += pur;       bar++;       if (foo * quz >= bar * baz) {         baz = foo;         quz = bar;       }     }     printf( %.6lf n , (double)baz / quz);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[n];       for (int i = 0; i < n; i++) cin >> arr[i];       for (int i = 0; i < n; i++) arr[i] -= 1;       for (int i = 0; i < n; i++) {         int count = 1;         int index = arr[i];         while (i != index) {           index = arr[index];           count++;         }         cout << count <<    ;       }       cout << endl;       ;     }   }