#include <bits/stdc++.h> n using namespace std; n template <class T> n void gi(T &x) { n   int f; n   char c; n   for (f = 1, c = getchar(); c <  0  || c >  9 ; c = getchar()) n     if (c ==  - ) f = -1; n   for (x = 0; c <=  9  && c >=  0 ; c = getchar()) x = x * 10 + (c & 15); n   x *= f; n } n const int N = 4e5 + 10, mod = 998244353; n inline int qm(int x, int k) { n   int sum = 1; n   for (; k; k >>= 1, x = 1ll * x * x % mod) n     if (k & 1) sum = 1ll * sum * x % mod; n   return sum; n } n int n, a[20][N], R[N], L = 0; n inline int C(int n, int m) { n   if (n < m || n < 0 || m < 0) return 0; n   int ret = 1, I = 1; n   for (int i = 1; i <= m; i++) n     ret = 1ll * ret * (n - i + 1) % mod, I = 1ll * I * i % mod; n   return 1ll * ret * qm(I, mod - 2) % mod; n } n inline void NTT(int *A) { n   for (int i = 0; i < n; i++) n     if (i < R[i]) swap(A[i], A[R[i]]); n   for (int i = 1; i < n; i <<= 1) { n     int t0 = qm(3, (mod - 1) / (i << 1)), x, y; n     for (int j = 0; j < n; j += i << 1) { n       int t = 1; n       for (int k = 0; k < i; k++, t = 1ll * t * t0 % mod) { n         x = A[j + k]; n         y = 1ll * A[j + k + i] * t % mod; n         A[j + k] = (x + y) % mod; n         A[j + k + i] = (x - y + mod) % mod; n       } n     } n   } n } n inline void mul(int *A, int *B) { n   NTT(A); n   NTT(B); n   for (int i = 0; i < n; i++) A[i] = 1ll * A[i] * B[i] % mod; n   NTT(A); n   reverse(A + 1, A + n); n   for (int i = 0, t = qm(n, mod - 2); i < n; i++) A[i] = 1ll * A[i] * t % mod; n } n inline void solve(int l, int r, int d) { n   if (l == r) { n     a[d][0] = l; n     a[d][1] = 1; n     return; n   } n   int mid = (l + r) >> 1, m = r - l + 1; n   solve(l, mid, d + 1); n   for (int i = 0; i <= m; i++) a[d][i] = a[d + 1][i]; n   solve(mid + 1, r, d + 1); n   for (n = 1, L = 0; n <= m; n <<= 1) L++; n   for (int i = mid - l + 2; i < n; i++) a[d][i] = 0; n   for (int i = r - mid + 1; i < n; i++) a[d + 1][i] = 0; n   for (int i = 0; i < n; i++) R[i] = (R[i >> 1] >> 1) | ((i & 1) << (L - 1)); n   mul(a[d], a[d + 1]); n } n int A, B; n int main() { n   cin >> n >> A >> B; n   if (n == 1) { n     if (A + B - 2 >= 0) n       puts( 1 ); n     else n       puts( 0 ); n     exit(0); n   } n   solve(0, n - 2, 0); n   cout << 1ll * a[0][A + B - 2] * C(A + B - 2, A - 1) % mod; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, ans = 0, pot; n   long long a, b, c, e; n   cin >> n; n   if (n <= 2) { n     cout << n; n     return 0; n   } n   for (long long i = n - 1e3; i <= n; i++) { n     a = i; n     b = i - 1; n     e = a * b; n     for (long long j = max(1LL, i - 50); j <= i - 2; j++) { n       c = j; n       pot = (e * c) / gcd(e, c); n       ans = max(ans, pot); n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 100000; n const long long INFLL = 1e15; n int N, Q; n long long a[MAX_N + 1], b[MAX_N + 1]; n long long S = 0; n long long zero(long long x) { return (x > 0) ? x : -x; } n struct SEG1 { n   struct NODE { n     int l, r; n     bool b; n   }; n   vector<NODE> seg; n   int SZ; n   void add() { seg.push_back({-1, -1, false}); } n   void Init(int x) { n     SZ = x; n     add(); n     init(0, 1, SZ); n   } n   void init(int idx, int s, int e) { n     if (s == e) return; n     seg[idx].l = seg.size(); n     add(); n     seg[idx].r = seg.size(); n     add(); n     init(seg[idx].l, s, (s + e) / 2); n     init(seg[idx].r, (s + e) / 2 + 1, e); n   } n   void Update(int x, bool y) { update(0, 1, SZ, x, y); } n   void update(int idx, int s, int e, int x, bool y) { n     if (s == e) { n       seg[idx].b = y; n       return; n     } n     if (x <= (s + e) / 2) { n       update(seg[idx].l, s, (s + e) / 2, x, y); n     } else { n       update(seg[idx].r, (s + e) / 2 + 1, e, x, y); n     } n     seg[idx].b = (seg[seg[idx].l].b | seg[seg[idx].r].b); n   } n   bool Ret(int x, int y) { return ret(0, 1, SZ, x, y); } n   bool ret(int idx, int s, int e, int x, int y) { n     if (x <= s && e <= y) { n       return seg[idx].b; n     } n     if (x > e || y < s) return false; n     return (ret(seg[idx].l, s, (s + e) / 2, x, y) | n             ret(seg[idx].r, (s + e) / 2 + 1, e, x, y)); n   } n } Seg1; n struct SEG2 { n   struct NODE { n     int l, r; n     long long mn; n   }; n   int SZ; n   vector<NODE> seg; n   void add() { seg.push_back({-1, -1, INFLL}); } n   void Init(int x) { n     SZ = x; n     add(); n     init(0, 1, SZ); n   } n   void init(int idx, int s, int e) { n     if (s == e) return; n     seg[idx].l = seg.size(); n     add(); n     seg[idx].r = seg.size(); n     add(); n     init(seg[idx].l, s, (s + e) / 2); n     init(seg[idx].r, (s + e) / 2 + 1, e); n   } n   void Update(int x, long long y) { update(0, 1, SZ, x, y); } n   void update(int idx, int s, int e, int x, long long y) { n     if (s == e) { n       seg[idx].mn = y; n       return; n     } n     if (x <= (s + e) / 2) { n       update(seg[idx].l, s, (s + e) / 2, x, y); n     } else { n       update(seg[idx].r, (s + e) / 2 + 1, e, x, y); n     } n     seg[idx].mn = min(seg[seg[idx].l].mn, seg[seg[idx].r].mn); n   } n   long long Mn(int x, int y) { return mn(0, 1, SZ, x, y); } n   long long mn(int idx, int s, int e, int x, int y) { n     if (x <= s && e <= y) return seg[idx].mn; n     if (x > e || y < s) return INFLL; n     return min(mn(seg[idx].l, s, (s + e) / 2, x, y), n                mn(seg[idx].r, (s + e) / 2 + 1, e, x, y)); n   } n } Seg2; n void make(int x) { n   if (b[x - 1] >= 0 && b[x] <= 0) { n     Seg2.Update(x, INFLL); n     Seg1.Update(x, true); n     return; n   } n   Seg1.Update(x, false); n   if (b[x - 1] < 0 && b[x] > 0) { n     Seg2.Update(x, 2LL * b[x] - 2LL * b[x - 1]); n     return; n   } n   if (b[x - 1] >= 0) { n     Seg2.Update(x, 2LL * b[x]); n   } else { n     Seg2.Update(x, -2LL * b[x - 1]); n   } n } n int main() { n   scanf( %d , &N); n   Seg1.Init(N); n   Seg2.Init(N); n   for (int i = 1; i <= N; i++) { n     scanf( %lld , &a[i]); n     if (i >= 2) { n       b[i - 1] = a[i] - a[i - 1]; n       S += zero(b[i - 1]); n     } n   } n   for (int i = 2; i < N; i++) { n     make(i); n   } n   scanf( %d , &Q); n   for (int i = 1; i <= Q; i++) { n     int t, l, r; n     long long x; n     scanf( %d%d%d%lld , &t, &l, &r, &x); n     if (t == 1) { n       if (l == r) { n         if (l == 1) { n           printf( %lld n , S - zero(b[1]) + zero(b[1] - x)); n         } else if (l == N) { n           printf( %lld n , S - zero(b[N - 1]) + zero(b[N - 1] + x)); n         } else { n           printf( %lld n , S - zero(b[l]) - zero(b[l - 1]) + zero(b[l] - x) + n                                zero(b[l - 1] + x)); n         } n       } else if (Seg1.Ret(l, r)) { n         printf( %lld n , S + x * 2LL); n       } else { n         long long mx = 0LL; n         long long t = Seg2.Mn(l, r); n         mx = max(mx, 2LL * x - t); n         if (l == 1) { n           mx = max(mx, zero(b[1] - x) - zero(b[1])); n         } n         if (r == N) { n           mx = max(mx, zero(x + b[N - 1]) - zero(b[N - 1])); n         } n         printf( %lld n , S + mx); n       } n     } else { n       if (l != 1) { n         S -= zero(b[l - 1]); n         b[l - 1] += x; n         S += zero(b[l - 1]); n         make(l); n         if (l != 2) make(l - 1); n       } n       if (r != N) { n         S -= zero(b[r]); n         b[r] -= x; n         S += zero(b[r]); n         make(r); n         if (r != N - 1) make(r + 1); n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int intmax = 0x3f3f3f3f; n const long long lldmax = 0x3f3f3f3f3f3f3f3fll; n double eps = 1e-8; n template <class T> n inline void checkmin(T &a, T b) { n   if (b < a) a = b; n } n template <class T> n inline void checkmax(T &a, T b) { n   if (b > a) a = b; n } n template <class T> n inline T sqr(T x) { n   return x * x; n } n template <class T> n inline T lowbit(T n) { n   return (n ^ (n - 1)) & n; n } n template <class T> n inline int countbit(T n) { n   return (n == 0) ? 0 : (1 + countbit(n & (n - 1))); n } n template <class T> n inline T checkmod(T n, T m) { n   return (n % m + m) % m; n } n template <class T> n inline T gcd(T a, T b) { n   if (a < 0) return gcd(-a, b); n   if (b < 0) return gcd(a, -b); n   return (b == 0) ? a : gcd(b, a % b); n } n template <class T> n inline T euclid(T a, T b, T &x, T &y) { n   if (a < 0) { n     T d = euclid(-a, b, x, y); n     x = -x; n     return d; n   } n   if (b < 0) { n     T d = euclid(a, -b, x, y); n     y = -y; n     return d; n   } n   if (b == 0) { n     x = 1; n     y = 0; n     return a; n   } else { n     T d = euclid(b, a % b, x, y); n     T t = x; n     x = y; n     y = t - (a / b) * y; n     return d; n   } n } n template <class T> n inline int dblcmp(T a, const T b) { n   a -= b; n   return a > eps ? 1 : (a < -eps ? -1 : 0); n } n template <class T> n inline int sgn(T a) { n   return a > eps ? 1 : (a < -eps ? -1 : 0); n } n long long ans[4]; n long long x, y; n long long n, m, a, b; n long long dis(long long x1, long long y1, long long x2, long long y2) { n   return sqr(x * 2 - x1 - x2) + sqr(y * 2 - y1 - y2); n } n void update(long long x1, long long y1, long long x2, long long y2) { n   bool copy = false; n   long long tmp[4]; n   tmp[0] = x1, tmp[1] = y1, tmp[2] = x2, tmp[3] = y2; n   if (x1 < 0 || x1 > n) return; n   if (x2 < 0 || x2 > n) return; n   if (y1 < 0 || y1 > m) return; n   if (y2 < 0 || y2 > m) return; n   if (x1 > x || x2 < x) return; n   if (y1 > y || y2 < y) return; n   if (x1 == x2 || y1 == y2) return; n   long long dy = y2 - y1, dx = x2 - x1; n   long long g = gcd(dy, dx); n   dy /= g, dx /= g; n   if (dy * a != dx * b) { n     return; n   } n   if (ans[0] == -1) { n     copy = true; n   } else { n     long long da = dis(ans[0], ans[1], ans[2], ans[3]); n     long long db = dis(x1, y1, x2, y2); n     if (db < da) { n       copy = true; n     } else if (db == da) { n       for (long long i = 0; i < 4; ++i) { n         if (tmp[i] < ans[i]) { n           copy = true; n         } n         if (tmp[i] != ans[i]) break; n       } n     } n   } n   if (copy) { n     for (long long i = 0; i < 4; ++i) ans[i] = tmp[i]; n   } n } n int main() { n   memset(ans, 0xff, sizeof(ans)); n   cin >> n >> m >> x >> y >> a >> b; n   long long g = gcd(a, b); n   a /= g; n   b /= g; n   long long mul = lldmax; n   checkmin(mul, n / a); n   checkmin(mul, m / b); n   a *= mul, b *= mul; n   update(0, 0, a, b); n   update(0, m - b, a, m); n   update(n - a, 0, n, b); n   update(n - a, m - b, n, m); n   int ta = a / 2, tb = b / 2; n   update(x - ta, y - tb, x + a - ta, y + b - tb); n   update(0, y - tb, a, y + b - tb); n   update(n - a, y - tb, n, y + b - tb); n   update(x - ta, 0, x + a - ta, b); n   update(x - ta, m - b, x + a - ta, m); n   ta++; n   update(x - ta, y - tb, x + a - ta, y + b - tb); n   update(0, y - tb, a, y + b - tb); n   update(n - a, y - tb, n, y + b - tb); n   update(x - ta, 0, x + a - ta, b); n   update(x - ta, m - b, x + a - ta, m); n   tb++; n   update(x - ta, y - tb, x + a - ta, y + b - tb); n   update(0, y - tb, a, y + b - tb); n   update(n - a, y - tb, n, y + b - tb); n   update(x - ta, 0, x + a - ta, b); n   update(x - ta, m - b, x + a - ta, m); n   ta--; n   update(x - ta, y - tb, x + a - ta, y + b - tb); n   update(0, y - tb, a, y + b - tb); n   update(n - a, y - tb, n, y + b - tb); n   update(x - ta, 0, x + a - ta, b); n   update(x - ta, m - b, x + a - ta, m); n   for (int i = 0; i < 4; ++i) { n     cout << ans[i] <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long fast_expo(long long base, long long exp, long long module) { n   long long ans = 1; n   while (exp) { n     if (exp & 1) ans = (ans * base) % module; n     base = (base * base) % module; n     exp >>= 1; n   } n   return ans; n } n bool primes[100001]; n void seive() { n   memset(primes, true, sizeof(primes)); n   primes[0] = false; n   primes[1] = false; n   for (int i = 2; i * i <= 100000; i++) { n     if (primes[i]) { n       for (int j = i * i; j <= 100000; j += i) primes[j] = false; n     } n   } n } n bool isprime(int n) { n   if (n == 1) return false; n   if (n == 2) return true; n   if (n % 2 == 0) return false; n   for (int i = 3; i * i <= n; i += 2) n     if (n % i == 0) return false; n   return true; n } n long long gcd(long long a, long long b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n long long f[100001]; n long long fib(long long n) { n   if (n == 0) return 0; n   if (n == 1 || n == 2) return (f[n] = 1); n   if (f[n]) return f[n]; n   long long k = (n & 1) ? (n + 1) / 2 : n / 2; n   f[n] = (n & 1) ? (fib(k) * fib(k) + fib(k - 1) * fib(k - 1)) n                  : (2 * fib(k - 1) + fib(k)) * fib(k); n   return f[n]; n } n int main() { n   ios_base::sync_with_stdio(false); n   int n; n   cin >> n; n   int t1 = n % 10; n   int t2 = t1; n   int cnt1 = 0, cnt2 = 0; n   if (t1 == 0) { n     cout << n << endl; n     return 0; n   } n   while (t1 <= 10) { n     cnt1++; n     t1++; n   } n   while (t2 > 0) { n     t2--; n     cnt2++; n   } n   if (cnt1 <= cnt2) n     cout << (n + cnt1 - 1) << endl; n   else n     cout << (n - cnt2) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int MOD = 1000000007; n long long int gcd(long long int a, long long int b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n long long int lcm(long long int a, long long int b) { n   return a / gcd(a, b) * b; n } n long long int power(long long int a, long long int n) { n   if (n == 0) return 1; n   long long int p = power(a, n / 2); n   p = (p * p) % MOD; n   if (n % 2) n     return (p * a) % MOD; n   else n     return p % MOD; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   long long int test = 1; n   while (test--) { n     long long int n, m, q; n     cin >> n >> m >> q; n     long long int c = gcd(n, m); n     long long int q1 = n / c; n     long long int q2 = m / c; n     while (q--) { n       long long int x1, y1, x2, y2; n       cin >> x1 >> y1 >> x2 >> y2; n       y1--; n       y2--; n       long long int secno1, secno2; n       if (x1 == 1) { n         secno1 = y1 / q1; n       } else { n         secno1 = y1 / q2; n       } n       if (x2 == 1) { n         secno2 = y2 / q1; n       } else { n         secno2 = y2 / q2; n       } n       if (secno1 != secno2) { n         cout <<  NO ; n       } else { n         cout <<  YES ; n       } n       cout <<   n ; n     } n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n long long a, b; n bool used[1000005]; n int main() { n   cin >> a >> b; n   long long max_num = 0, s = 0, max_id; n   for (;; max_num++) { n     if (s + max_num + 1 > a + b) break; n     s += max_num + 1; n     max_id = max_num; n   } n   s = 0; n   int cnt = 0; n   for (long long i = max_num + 1; i > 1; i--) { n     if (s + i - 1 > a) { n       used[a - s] = 1; n       if (a - s) cnt++; n       break; n     } n     used[i - 1] = 1; n     cnt++; n     s += i - 1; n   } n   cout << cnt <<   n ; n   for (int i = 1; i <= max_num; i++) { n     if (used[i]) { n       cout << i <<    ; n     } n   } n   cout <<   n  << max_num - cnt <<   n ; n   for (int i = 1; i <= max_num; i++) { n     if (!used[i]) { n       cout << i <<    ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n char BUF[500010]; n int n, m; n int up[500010], down[500010], L[500010], R[500010]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; ++i) { n     scanf( %s , &BUF); n     for (int j = 0; j < m; ++j) switch (BUF[j]) { n         case  1 : n           if (j & 1) n             R[i] = 1; n           else n             L[i] = 1; n           if (i & 1) n             down[j] = 1; n           else n             up[j] = 1; n           break; n         case  2 : n           if (j & 1) n             R[i] = 1; n           else n             L[i] = 1; n           if (i & 1) n             up[j] = 1; n           else n             down[j] = 1; n           break; n         case  3 : n           if (j & 1) n             L[i] = 1; n           else n             R[i] = 1; n           if (i & 1) n             up[j] = 1; n           else n             down[j] = 1; n           break; n         case  4 : n           if (j & 1) n             L[i] = 1; n           else n             R[i] = 1; n           if (i & 1) n             down[j] = 1; n           else n             up[j] = 1; n           break; n       } n   } n   int ans = 1; n   for (int i = 0; i < n; ++i) ans = (ans * (2 - L[i] - R[i])) % 1000003; n   for (int i = 0; i < m; ++i) ans = (ans * (2 - up[i] - down[i])) % 1000003; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 11, mod = 1e9 + 7; n const double EPS = 1e-7; n const int INF = 2e9; n const int base = 500; n const int dx[] = {1, -1, 0, 0}; n const int dy[] = {0, 0, 1, -1}; n int m, t, r, w[333], ans; n bool ct[333 + base + 11]; n int main() { n   if (fopen( string  n              .in , n              r )) n     freopen( n          string  n          .in , n          r , stdin), n         freopen( n              string  n              .out , n              w , stdout); n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> m >> t >> r; n   for (int i = 1; i <= m; ++i) { n     cin >> w[i]; n   } n   for (int i = 1; i <= m; ++i) { n     int candles = 0; n     for (int j = w[i] - 1; j >= w[i] - t; --j) { n       candles += ct[j + base]; n     } n     if (candles < r) { n       for (int j = w[i] - 1; j >= w[i] - t; --j) { n         if (!ct[j + base] && candles < r) { n           ct[j + base] = 1; n           ++ans; n           ++candles; n         } n       } n       if (candles < r) { n         return cout << -1, 0; n       } n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n const int MX = 2e5 + 5; n const long long INF = 1e18; n const long double PI = 4 * atan((long double)1); n template <class T> n bool ckmin(T& a, const T& b) { n   return a > b ? a = b, 1 : 0; n } n template <class T> n bool ckmax(T& a, const T& b) { n   return a < b ? a = b, 1 : 0; n } n set<int> v[26]; n string ans; n int visited[26] = {0}; n void dfs(int s) { n   visited[s] = true; n   ans += s +  a ; n   for (auto& i : v[s]) { n     if (visited[i] == false) dfs(i); n   } n } n int main() { n   int test; n   cin >> test; n   while (test--) { n     string str; n     cin >> str; n     for (int i = 0; i < 26; i++) { n       visited[i] = 0; n       v[i].clear(); n     } n     ans.clear(); n     int num1 = str.size(); n     for (int i = 1; i < num1; i++) { n       v[str[i] -  a ].insert(str[i - 1] -  a ); n       v[str[i - 1] -  a ].insert(str[i] -  a ); n     } n     int ok = 0; n     for (int i = 0; i < 26; i++) { n       if (v[i].size() > 2) { n         ok = 1; n         break; n       } n     } n     if (ok == 1) { n       cout <<  NO  << endl; n     } else { n       for (int i = 0; i < 26; i++) { n         if (visited[i] == 0 && v[i].size() < 2) { n           dfs(i); n         } n       } n       bool ok = true; n       for (int i = 0; i < 26; i++) { n         if (visited[i] == 0) { n           ok = false; n         } n       } n       if (ok == false) { n         cout <<  NO  << endl; n       } else { n         cout <<  YES  << endl; n         cout << ans << endl; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n bool win(long long a, long long b) { n   if (a < b) swap(a, b); n   if (!b) return (false); n   if (!win(b, a % b)) return (true); n   long long p = a / b; n   return (p % (b + 1) % 2 == 0); n } n int main() { n   int T; n   scanf( %d , &T); n   while (T--) { n     long long a, b; n     scanf( %I64d%I64d , &a, &b); n     printf( %s n , win(a, b) ?  First  :  Second ); n   } n   return (0); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   if (n == 1) n     cout << 5; n   else n     cout << 25; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   long long n, m; n   cin >> n >> m; n   long long on[n + 2]; n   long long is[n + 1]; n   int inst[n + 2]; n   is[0] = 1; n   int pval = m; n   inst[0] = 0; n   for (int i(1); i <= n; i++) { n     cin >> inst[i]; n     if (is[i - 1] == 0) { n       is[i] = 1; n     } else n       is[i] = 0; n   } n   inst[n + 1] = m; n   if (is[n] == 1) { n     on[n] = m - inst[n]; n     pval = inst[n]; n   } else { n     on[n] = 0; n     pval = inst[n]; n   } n   for (int i(n - 1); i >= 1; --i) { n     if (is[i] == 1) { n       on[i] = on[i + 1] + (pval - inst[i]); n       pval = inst[i]; n     } else { n       on[i] = on[i + 1]; n       pval = inst[i]; n     } n   } n   on[0] = on[1] + inst[1] - 0; n   pval = 0; n   on[n + 1] = 0; n   long long ans = on[0]; n   for (int i(0); i <= n; i++) { n     if (inst[i + 1] - inst[i] < 2) { n       continue; n     } else { n       long long l, m1, r; n       l = on[0] - on[i]; n       m1 = inst[i + 1] - inst[i] - 1; n       r = m - inst[i + 1] - on[i + 1]; n       ans = max(ans, l + m1 + r); n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n long long read() { n   long long a = 0, b = getchar(), c = 1; n   while (!isdigit(b)) c = b ==  -  ? -1 : 1, b = getchar(); n   while (isdigit(b)) a = a * 10 + b -  0 , b = getchar(); n   return a * c; n } n long long n, ans, p[200005]; n pair<long long, long long> a[200005]; n int main() { n   n = read(); n   for (int i = 1; i <= n; i++) { n     a[i].second = read(); n     p[i] = a[i].second; n   } n   for (int i = 1; i <= n; i++) a[i].first = read(); n   sort(a + 1, a + n + 1); n   sort(p + 1, p + n + 1); n   for (int i = 1; i <= n; i++) n     ans += (lower_bound(p + 1, p + n + 1, a[i].second) - p - n + i - 1) * n            a[i].second; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline T abs(T t) { n   return t < 0 ? -t : t; n } n const long long modn = 1000000007; n inline long long mod(long long x) { return x % modn; } n const int MAXN = 212345; n int n, m, k; n pair<long long, long long> s[MAXN]; n long long d, v, V; n set<pair<long long, long long> > q; n void fail() { n   puts( -1 ); n   exit(0); n } n int main() { n   long long res = 0; n   scanf( %lld %lld %d , &d, &v, &n); n   V = v; n   for (int a = 0; a < n; a++) scanf( %lld %lld , &s[a].first, &s[a].second); n   sort(s, s + n); n   s[n].first = d; n   s[n].second = INT_MAX; n   int i = 0, j = 0; n   long long up = v; n   while (i <= n && s[i].first <= v) { n     q.insert(pair<long long, long long>(s[i].second, s[i].first)); n     i++; n     ; n   } n   long long ult = 0; n   while (j <= n) { n     ; n     v -= s[j].first - ult; n     if (v < 0) { n       ; n       fail(); n     } n     if (j == n) break; n     pair<long long, long long> top = *q.begin(); n     swap(top.first, top.second); n     while (i <= n && v < V && top == s[j]) { n       ; n       if (i <= n && v + s[i].first - up <= V) { n         res += s[j].second * (s[i].first - up); n         v += s[i].first - up; n         up = s[i].first; n         q.insert(pair<long long, long long>(s[i].second, s[i].first)); n         i++; n       } else if (i <= n) { n         res += s[j].second * (V - v); n         up += V - v; n         v = V; n       } n       top = *q.begin(); n       swap(top.first, top.second); n     } n     ult = s[j].first; n     q.erase(pair<long long, long long>(s[j].second, s[j].first)); n     j++; n   } n   printf( %lld n , res); n } n


#include <bits/stdc++.h> n using namespace std; n long long int GC(long long int a, long long int b) { n   if (b == 0) n     return a; n   else n     return GC(b, a % b); n } n long long int inv_gc(long long int a, long long int b) { n   return a / GC(a, b) * b; n } n long long int Ceil(long long int a, long long int b) { n   return a / b + (a % b != 0); n } n long long int fastModExp(long long int a, long long int b) { n   long long int res = 1; n   while (b > 0) { n     if (b & 1) res = (res * a) % 1000000007; n     a = (a * a) % 1000000007; n     b = b >> 1; n   } n   return res; n } n map<int, int> par, rk; n void make_set() { n   for (char i =  a ; i <=  z ; i++) { n     par[i] = i; n     rk[i] = 1; n   } n } n int find(char x) { n   if (x == par[x]) return x; n   char p = find(par[x]); n   par[x] = p; n   return p; n } n int uni(char x, char y) { n   char p1 = find(x); n   char p2 = find(y); n   if (p1 == p2) return 0; n   if (rk[p1] > rk[p2]) { n     par[p2] = p1; n     rk[p1] += rk[p2]; n   } else { n     par[p1] = p2; n     rk[p2] += rk[p1]; n   } n   return 1; n } n map<char, int> mpx; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   make_set(); n   int n; n   vector<string> v; n   cin >> n; n   string s; n   for (int i = 0; i < n; i++) { n     cin >> s; n     v.push_back(s); n     if (s.length() > 1) { n       for (int i = 0; i < s.length() - 1; i++) int r = uni(s[i], s[i + 1]); n     } n   } n   for (int i = 0; i < v.size(); i++) { n     mpx[find(v[i][0])] = 1; n   } n   long long int count = 0; n   for (auto it = mpx.begin(); it != mpx.end(); it++) n     if (it->second == 1) { n       count++; n     } n   cout << count << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10; n const int P = 998244353; n int T, n; n int ans[N]; n vector<int> e[N]; n int f[N]; n bool dfs(int x, int fa, int y) { n   for (auto v : e[x]) n     if (v != fa && !dfs(v, x, y)) return 0; n   if (f[x] % y == 0) { n     f[fa]--; n     return 1; n   } n   f[x]--; n   if (f[x] % y == 0) return 1; n   return 0; n } n int main() { n   std::ios::sync_with_stdio(false); n   std::cin.tie(nullptr); n   cin >> T; n   while (T--) { n     cin >> n; n     for (int i = 1; i <= n; i++) e[i].clear(); n     for (int i = 1; i < n; i++) { n       int u, v; n       cin >> u >> v; n       e[u].push_back(v); n       e[v].push_back(u); n     } n     if (n == 2) { n       cout << 2 <<     << 0 <<   n ; n     } else { n       int rt = 0; n       for (int i = 1; i <= n; i++) n         if (((int)e[i].size()) > 1) rt = i; n       for (int i = 1; i <= n; i++) ans[i] = 0; n       for (int i = 1; i * i <= (n - 1); i++) { n         if ((n - 1) % i) continue; n         for (int j = 1; j <= n; j++) f[j] = ((int)e[j].size()); n         if (dfs(rt, 0, i)) ans[i] = 1; n         for (int j = 1; j <= n; j++) f[j] = ((int)e[j].size()); n         if (dfs(rt, 0, (n - 1) / i)) ans[(n - 1) / i] = 1; n       } n       for (int i = 2; i <= n; i++) n         for (int j = i + i; j <= n; j += i) n           if (ans[j]) ans[i] = 0; n       for (int i = 1; i < n; i++) ans[1] = 2 * ans[1] % P; n       for (int i = 2; i <= n; i++) ans[1] = (ans[1] - ans[i] + P) % P; n       for (int i = 1; i <= n; i++) cout << ans[i] <<    n [i == n]; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c, d, e, f; n   cin >> a >> b >> c >> d >> e >> f; n   cout << (a + b + f) * (a + b + f) - b * b - d * d - f * f << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int __gcd(long long int a, long long int b) { n   return (a % b) ? __gcd(b, a % b) : b; n } n bool prime(long long int k) { n   for (long long int i = 2; i * i <= k; i++) n     if (k % i == 0) { n       return false; n     } n   return true; n } n void pdash(int n = 1) { n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < 30; j++) { n       cout <<  - ; n     } n     cout <<   n ; n   } n } n long long int cube_root(long long int a) { n   long long int r = 1000000, l = 1; n   long long int mid; n   while (r - l > 1) { n     mid = (r + l) >> 1; n     if (mid * mid * mid == a) { n       return mid; n     } else if (mid * mid * mid > a) { n       r = mid; n     } else n       l = mid; n   } n   if (l * l * l == a) return l; n   if (r * r * r == a) return r; n   return -1; n } n void solve() { n   int n; n   cin >> n; n   long long int a, b; n   while (n--) { n     cin >> a >> b; n     long long int c = cube_root(a * b); n     if (c != -1 && a % c == 0 && b % c == 0) { n       cout <<  Yes n ; n     } else n       cout <<  No n ; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t = 1; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200200; n int n, s[N] = {}, d[N] = {}, top = 0; n long long sum = 0; n int main() { n   scanf( %d , &n); n   s[++top] = 0; n   for (int i = 1, t, x, y; i <= n; ++i) { n     scanf( %d , &t); n     if (t == 1) n       scanf( %d%d , &x, &y), sum += x * y, d[x] += y; n     else if (t == 2) n       scanf( %d , &x), s[++top] = x, sum += x; n     else n       d[top - 1] += d[top], sum -= s[top] + d[top], d[top] = 0, --top; n     printf( %.12f n , sum * 1.0 / top); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c, n; n   cin >> a >> b >> c >> n; n   int tot = n - a - b + c; n   if (tot <= 0 || a < c || b < c) return 0 * puts( -1 ); n   cout << tot << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     vector<int> visited(n); n     vector<int> a(n); n     vector<int> ans(n); n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n       a[i]--; n     } n     for (int i = 0; i < n; i++) { n       if (visited[i] == 0) { n         vector<int> v; n         while (!visited[i]) { n           v.push_back(i); n           visited[i] = 1; n           i = a[i]; n         } n         for (auto x : v) ans[x] = v.size(); n       } n     } n     for (int i = 0; i < n; i++) cout << ans[i] <<    ; n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n const double eps = 1e-8; n const int T = 23; n inline double sqr(double x) { return x * x; } n inline int dcmp(double x) { return fabs(x) <= eps ? 0 : (x > 0 ? 1 : -1); } n int n; n double r, v, s, t; n bool check(double x) { n   double len = x; n   int tmp = (int)(x / (2.0 * pi * r)); n   x -= 2.0 * pi * r * tmp; n   double delta = x / r; n   len -= (t - s); n   len /= r; n   double y = sqrt(sqr(1 - cos(delta)) + sqr(sin(delta))); n   len /= y; n   double a = acos(len) - acos((1 - cos(delta)) / y); n   if (a - 2.0 * pi >= 0) a -= 2 * pi; n   if (a < 0) a += 2.0 * pi; n   return dcmp(pi - a) >= 0; n } n int main() { n   scanf( %d %lf %lf , &n, &r, &v); n   for (int i = 1; i <= n; i++) { n     scanf( %lf %lf , &s, &t); n     double l = 0.0, r = t - s - eps; n     for (int j = 1; j <= T; j++) { n       double mid = (l + r) / 2.0; n       if (check(mid)) n         r = mid; n       else n         l = mid; n     } n     printf( %.9f n , l / v); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename U> n inline void smin(T &a, const U &b) { n   if (a > b) a = b; n } n template <typename T, typename U> n inline void smax(T &a, const U &b) { n   if (a < b) a = b; n } n template <class T> n inline void gn(T &first) { n   char c, sg = 0; n   while (c = getchar(), (c >  9  || c <  0 ) && c !=  - ) n     ; n   for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ; n        c = getchar()) n     first = (first << 1) + (first << 3) + c -  0 ; n   if (sg) first = -first; n } n template <class T1, class T2> n inline void gn(T1 &x1, T2 &x2) { n   gn(x1), gn(x2); n } n int power(int a, int b, int m, int ans = 1) { n   for (; b; b >>= 1, a = 1LL * a * a % m) n     if (b & 1) ans = 1LL * ans * a % m; n   return ans; n } n const int mod = 1000000007; n vector<int> adj[111]; n int dp[111][50], k; n int tmp[50]; n inline void add(int &a, long long b) { a = (a + b) % mod; } n void dfs(int u, int f = 0) { n   dp[u][25 + k] = 1; n   dp[u][25 - 1] = 1; n   for (int v : adj[u]) { n     if (v == f) continue; n     dfs(v, u); n     for (int i = -k; i <= k; i++) n       tmp[25 + i] = dp[u][25 + i], dp[u][25 + i] = 0; n     for (int i = -k; i <= k; i++) n       for (int j = -k; j <= k; j++) { n         if (i + j >= 0) n           add(dp[u][25 + max(i, j - 1)], n               (long long)tmp[25 + i] * dp[v][25 + j]); n         else n           add(dp[u][25 + min(i, j - 1)], n               (long long)tmp[25 + i] * dp[v][25 + j]); n       } n   } n } n int main() { n   int n; n   cin >> n >> k; n   for (int i = 1; i < n; i++) { n     int u, v; n     gn(u, v); n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   dfs(1); n   int ans = 0; n   for (int i = 0; i <= k; i++) add(ans, dp[1][25 + i]); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string c =  abacaba ; n int f(string str) { n   int cnt = 0; n   for (int i = 0; i < str.size(); i++) { n     if (c.size() > str.size() - i) { n       break; n     } n     if (c == str.substr(i, c.size())) cnt++; n   } n   return cnt; n } n bool f1(string str) { n   for (int i = 0; i < str.size(); i++) { n     if (str[i] != c[i] && str[i] !=  ? ) return 0; n   } n   return 1; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     string s; n     cin >> n >> s; n     if (f(s) > 1) { n       cout <<  No n ; n       continue; n     } n     int cnt = 0; n     string ans =   ; n     for (int i = 0; i < s.size(); i++) { n       if (c.size() > s.size() - i) { n         break; n       } n       if (f1(s.substr(i, c.size()))) { n         string temp = s.substr(0, i) + c + s.substr(i + c.size()); n         if (f(temp) == 1) { n           ans = s.substr(0, i) + c + s.substr(i + c.size()); n           break; n         } n       } n     } n     if (ans ==   ) { n       cout <<  No n ; n     } else { n       cout <<  Yes n ; n       for (int i = 0; i < ans.size(); i++) { n         if (ans[i] ==  ? ) ans[i] =  z ; n         cout << ans[i]; n       } n       cout <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename U> n std::pair<T, U> operator+(const std::pair<T, U>& l, const std::pair<T, U>& r) { n   return {l.first + r.first, l.second + r.second}; n } n typedef void (*callback_function)(void); n const long long ZERO = 0LL; n const long long INF64 = 1e18; n const long long INF32 = 1e9; n const long long MOD = 1e9 + 7; n const long double PI = acos(-1.0L); n const long double EPS = static_cast<long double>(1e-9); n inline long long Pow(long long a, long long k) { n   long long s = 1; n   for (; k; k >>= 1) { n     k& 1 ? s = 1LL * s * a % MOD : 0; n     a = 1LL * a * a % MOD; n   } n   return s; n } n const long long N = 1e6 + 7; n void input() {} n void output() {} n void preprocess() {} n void debug() { n   if (true) { n   } n } n void solve() { n   preprocess(); n   long long n; n   cin >> n; n   long long a[n]; n   for (long long i = (0); i < (n); i++) { n     cin >> a[i]; n   } n   long long L = 0, R = n - 1, res = 0; n   while (L < R) { n     while (L < R and a[L] < a[L + 1]) { n       L++; n     } n     while (L < R and a[R] < a[R - 1]) { n       R--; n     } n     if (L == R) { n       break; n     } n     if (a[L] < a[R]) { n       long long b = a[L] + 1; n       res += b - a[L + 1]; n       a[L + 1] = b; n     } else { n       long long b = a[R] + 1; n       res += b - a[R - 1]; n       a[R - 1] = b; n     } n   } n   cout << res << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(); n   { n     input(); n     solve(); n     output(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 998244353; n const int N = 505; n int fac[N], inv_fac[N]; n int mod_pow(int b, int p) { n   int ans = 1; n   while (p) { n     if (p & 1) { n       ans = (1ll * ans * b) % mod; n       p--; n     } n     b = (1ll * b * b) % mod; n     p /= 2; n   } n   return ans; n } n void calc_fac() { n   fac[0] = 1; n   inv_fac[0] = 1; n   for (int i = 1; i < N; i++) { n     fac[i] = (1ll * fac[i - 1] * i) % mod; n     inv_fac[i] = mod_pow(fac[i], mod - 2); n   } n } n int nCr(int n, int r) { n   if (r > n) { n     return 0; n   } n   return 1ll * fac[n] * inv_fac[n - r] % mod * inv_fac[r] % mod; n } n void solve() { n   int n, k; n   cin >> n >> k; n   vector<vector<int>> POW(k + 5, vector<int>(n + 5)); n   for (int i = 1; i < k + 5; i++) { n     POW[i][0] = 1; n     for (int j = 1; j < n + 5; j++) { n       POW[i][j] = 1ll * POW[i][j - 1] * i % mod; n     } n   } n   vector<vector<int>> dp(n + 5, vector<int>(k + 5)); n   for (int initial_alive = 2; initial_alive < n + 5; initial_alive++) { n     for (int limit = 1; limit < k + 5; limit++) { n       if (limit < initial_alive) { n         dp[initial_alive][limit] = POW[limit][initial_alive]; n       } else { n         dp[initial_alive][limit] = POW[initial_alive - 1][initial_alive]; n         for (int alive = 1; alive <= initial_alive; alive++) { n           int killed = initial_alive - alive; n           dp[initial_alive][limit] = n               (0ll + dp[initial_alive][limit] + n                1ll * dp[alive][limit - (initial_alive - 1)] * n                    nCr(initial_alive, killed) % mod * n                    POW[initial_alive - 1][killed] % mod) % n               mod; n         } n       } n     } n   } n   cout << dp[n][k] <<   n ; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   calc_fac(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1100; n long long x, y; n int n; n int main() { n   std::ios::sync_with_stdio(false); n   while (cin >> n) { n     long long x1, x2, y1, y2; n     x1 = y1 = 1000000000; n     x2 = y2 = -1000000000; n     for (int i = 0; i < n; ++i) { n       cin >> x >> y; n       if (x < x1) x1 = x; n       if (y < y1) y1 = y; n       if (x > x2) x2 = x; n       if (y > y2) y2 = y; n     } n     unsigned long long s = max(abs(x2 - x1), abs(y2 - y1)); n     cout << s * s << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 40; n const int inf = 0x3fffffff; n void read(int &x) { n   char ch; n   bool flag = 0; n   for (ch = getchar(); !isdigit(ch) && ((flag |= (ch ==  - )) || 1); n        ch = getchar()) n     ; n   for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar()) n     ; n   x *= 1 - 2 * flag; n } n char mp[4][105]; n int n, m; n bool ans = 1; n bool check(int time, int x, int y) { n   y += 2 * time; n   if (y >= n || mp[x][y] ==  . ) return true; n   return false; n } n int vis[5][105]; n void dfs(int x, int y) { n   if (vis[x][y]) return; n   vis[x][y] = 1; n   if (y == n - 1) { n     ans = 0; n     return; n   } n   if (!check(y, x, y + 1)) return; n   for (int i = x - 1; i <= x + 1; i++) { n     if (i < 0 || i >= 3) continue; n     if (check(y, i, y + 1) && check(y + 1, i, y + 1)) dfs(i, y + 1); n   } n } n int main() { n   int t; n   read(t); n   while (t--) { n     ans = 1; n     memset(vis, 0, sizeof(vis)); n     read(n), read(m); n     int st = -1; n     ans = 1; n     for (int i = 0; i < 3; i++) { n       cin >> mp[i]; n       for (int j = 0; j < m; j++) { n         if (mp[i][j] ==  s ) { n           st = i; n         } n       } n     } n     mp[st][0] =  . ; n     dfs(st, 0); n     if (ans) n       puts( NO ); n     else n       puts( YES ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, d, h; n struct edge { n   int n1; n   int n2; n }; n edge vertices[100000]; n int main() { n   cin >> n >> d >> h; n   if (d > 2 * h || (h == 1 && d == 1 && n > 2)) n     cout <<  -1  << endl; n   else { n     int idx = 0; n     int usedNode = 1; n     for (int i = 0; i < h; i++) { n       vertices[idx++] = edge{usedNode - 1, usedNode++}; n     } n     if (d > h) { n       vertices[idx++] = edge{0, usedNode++}; n       for (int i = 1; i < (d - h); i++) { n         vertices[idx++] = edge{usedNode - 1, usedNode++}; n       } n     } n     int start = (h > 1) ? 1 : 0; n     for (int i = h + (d - h); i < n - 1; i++) { n       vertices[idx++] = edge{start, usedNode++}; n     } n     for (int i = 0; i < n - 1; i++) { n       cout << vertices[i].n1 + 1 <<     << vertices[i].n2 + 1 << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n stack<char> st; n string s, ans =   ; n char mn[111111]; n long long n; n int main() { n   cin >> s; n   n = s.size(); n   mn[n - 1] = s[n - 1]; n   for (int i = n - 2; i >= 0; i--) { n     mn[i] = min(mn[i + 1], s[i]); n   } n   for (int i = 0; i < n;) { n     if (st.empty()) { n       st.push(s[i]); n       i++; n     } else if (st.top() <= mn[i]) { n       ans += st.top(); n       st.pop(); n     } else { n       st.push(s[i]); n       i++; n     } n   } n   while (!st.empty()) { n     ans += st.top(); n     st.pop(); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long full, n, k, x, i, ans, a[100001], b[100001]; n void f(long long l, long long r, long long d) { n   if (l > r) return; n   if (l == 0) n     ans += r / d + 1; n   else n     ans += (r / d) - (l - 1) / d; n } n int main() { n   cin >> n >> k; n   for (i = 1; i <= n / k; i++) { n     cin >> a[i]; n   } n   x = 1; n   for (i = 1; i < k; i++) x *= 10; n   for (i = 1; i <= n / k; i++) { n     cin >> b[i]; n   } n   full = 1; n   for (i = 1; i <= n / k; i++) { n     ans = 0; n     f(0, b[i] * x - 1, a[i]); n     f((b[i] + 1) * x, 10 * x - 1, a[i]); n     full = ans * full % 1000000007; n   } n   cout << full; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   int n, m; n   cin >> n >> m; n   bool aOk = true, bOk = true; n   vector<vector<int>> a(n, vector<int>(m)), b(n, vector<int>(m)); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> a[i][j]; n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> b[i][j]; n       int t1 = a[i][j], t2 = b[i][j]; n       a[i][j] = min(t1, t2); n       b[i][j] = max(t1, t2); n       if ((i - 1) >= 0) { n         if (b[i][j] <= b[i - 1][j]) bOk = false; n         if (a[i][j] <= a[i - 1][j]) aOk = false; n       } n       if ((j - 1) >= 0) { n         if (b[i][j] <= b[i][j - 1]) bOk = false; n         if (a[i][j] <= a[i][j - 1]) aOk = false; n       } n     } n   } n   if (aOk and bOk) n     cout <<  Possible n ; n   else n     cout <<  Impossible n ; n } n


#include <bits/stdc++.h> n using namespace std; n int dp[111111]; n int main() { n   int n, m; n   cin >> n >> m; n   vector<int> a; n   for (int i = 0; i < n; i++) { n     int x; n     cin >> x; n     a.push_back(x); n   } n   reverse(a.begin(), a.end()); n   set<int> b; n   for (int i = 0; i < n; i++) { n     if (b.find(a[i]) == b.end()) dp[n - i - 1]++; n     if (i == n - 1) break; n     dp[n - i - 2] = dp[n - i - 1]; n     b.insert(a[i]); n   } n   for (int i = 0; i < m; i++) { n     int x; n     cin >> x; n     cout << dp[x - 1] <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long n; n   while (scanf( %ld , &n) != EOF) { n     int a, b, c1 = 0, c2 = 0, s1 = 0, s2 = 0, i, r; n     long x = 100000000; n     for (i = 0; i < n; i++) { n       scanf( %d%d , &a, &b); n       if (a == 0) n         c1++; n       else n         c2++; n       if (b == 0) n         s1++; n       else n         s2++; n     } n     r = c2; n     r = r + s1; n     if (r < x) x = r; n     r = c1; n     r = r + s2; n     if (r < x) x = r; n     r = c2 + s2; n     if (r < x) x = r; n     r = c1 + s1; n     if (r < x) x = r; n     printf( %ld n , x); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma warning(disable : 4996 4018) n using namespace std; n int n, mod = 1000000007; n long long arr[1001], cost[1001]; n int main() { n   cin.tie(0); n   ios_base::sync_with_stdio(0); n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> arr[i]; n   long long ans = 0; n   for (int i = 1; i <= n; i++) { n     for (int e = arr[i]; e != i; e++) cost[i] = (cost[i] + cost[e]) % mod; n     cost[i] = (cost[i] + 2) % mod; n     ans = (ans + cost[i]) % mod; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n pair<double, double> p[100100]; n double d[100100]; n double dist(pair<double, double> x, pair<double, double> y) { n   double val = pow((x.first - y.first) * (x.first - y.first) + n                        (x.second - y.second) * (x.second - y.second), n                    0.5); n   return val; n } n int main() { n   pair<double, double> a, b, t; n   cin >> a.first >> a.second >> b.first >> b.second >> t.first >> t.second; n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> p[i].first >> p[i].second; n   double ans = 0.0; n   for (int i = 0; i < n; i++) { n     d[i] = dist(t, p[i]); n     ans += d[i]; n   } n   double val = 100000000000000000; n   double ma1 = 0, ma2 = 0, mb1 = 0, mb2 = 0; n   int ia1 = -1, ia2 = -1, ib1 = -1, ib2 = -1; n   for (int i = 0; i < n; i++) { n     val = min(val, 2 * ans + dist(a, p[i]) - d[i]); n     if (ma2 < d[i] - dist(a, p[i])) ma2 = d[i] - dist(a, p[i]), ia2 = i; n     if (ma1 < ma2) swap(ma1, ma2), swap(ia1, ia2); n   } n   for (int i = 0; i < n; i++) { n     val = min(val, 2 * ans + dist(b, p[i]) - d[i]); n     if (mb2 < d[i] - dist(b, p[i])) mb2 = d[i] - dist(b, p[i]), ib2 = i; n     if (mb1 < mb2) swap(mb1, mb2), swap(ib1, ib2); n   } n   if (ia1 != ib1 && ia1 != -1 && ib1 != -1) val = min(val, 2 * ans - ma1 - mb1); n   if (ia1 != ib2 && ia1 != -1 && ib2 != -1) val = min(val, 2 * ans - ma1 - mb2); n   if (ia2 != ib1 && ia2 != -1 && ib1 != -1) val = min(val, 2 * ans - ma2 - mb1); n   if (ia2 != ib2 && ia2 != -1 && ib2 != -1) val = min(val, 2 * ans - ma2 - mb2); n   printf( %0.14lf , val); n } n


#include <bits/stdc++.h> n using namespace std; n int n, p, p1, p2; n char s[201]; n int pd(char c) { n   if ((c >=  0  && c <=  9 ) || (c >=  A  && c <=  Z ) || n       (c >=  a  && c <=  z ) || (c ==  _ )) n     return 1; n   return 0; n } n int main() { n   cin >> s; n   n = strlen(s); n   if (n > 70) { n     cout <<  NO  << endl; n     return 0; n   } n   while (p < n && s[p] !=  @ ) p++; n   if (p == n) { n     cout <<  NO  << endl; n     return 0; n   } n   if (p < 1 || p > 16) { n     cout <<  NO  << endl; n     return 0; n   } n   for (int i = 0; i < p; i++) { n     if (!pd(s[i])) { n       cout <<  NO  << endl; n       return 0; n     } n   } n   p1 = p + 1; n   while (p < n && s[p] !=  / ) p++; n   if (p - p1 < 1 || p - p1 > 32) { n     cout <<  NO  << endl; n     return 0; n   } n   for (int i = p1; i < p; i++) { n     if (s[i] ==  . ) { n       if (p2 < 1 || p2 > 16) { n         cout <<  NO  << endl; n         return 0; n       } n       p2 = 0; n     } else { n       if (!pd(s[i])) { n         cout <<  NO  << endl; n         return 0; n       } n       p2++; n     } n   } n   if (p2 < 1 || p2 > 16) { n     cout <<  NO  << endl; n     return 0; n   } n   if (p < n) { n     p2 = 0; n     for (int i = p + 1; i < n; i++) { n       if (s[i] ==  / ) { n         if (p2 < 1 || p2 > 16) { n           cout <<  NO  << endl; n           return 0; n         } n         p2 = 0; n       } else { n         if (!pd(s[i])) { n           cout <<  NO  << endl; n           return 0; n         } n         p2++; n       } n     } n     if (p2 < 1 || p2 > 16) { n       cout <<  NO  << endl; n       return 0; n     } n   } n   cout <<  YES  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long first[60]; n void do_it(long long n2, long long k2, long long x) { n   if (n2 == 1) { n     cout << x + 1; n     return; n   } n   if (n2 == 2) { n     if (k2 == 1) n       cout << x + 2 <<     << x + 1; n     else n       cout << x + 1 <<     << x + 2; n     return; n   } n   if (k2 < first[n2 - 1]) { n     cout << x + 1 <<    ; n     do_it(n2 - 1, k2, x + 1); n   } else { n     k2 -= first[n2 - 1]; n     cout << x + 2 <<     << x + 1 <<    ; n     do_it(n2 - 2, k2, x + 2); n   } n } n long long n, k; n int main() { n   first[0] = 1, first[1] = 1; n   for (long long i = (2); i < (60); i++) first[i] = first[i - 1] + first[i - 2]; n   cin >> n >> k; n   k--; n   do_it(n, k, 0); n } n


#include <bits/stdc++.h> n using namespace std; n struct E { n   int a, b, c; n }; n struct unionfind { n   vector<int> p, s; n   int c; n   unionfind(int n) : p(n, -1), s(n, 1), c(n) {} n   int find(int a) { return p[a] == -1 ? a : find(p[a]); } n   vector<pair<int *, int>> buf; n   void save(int &a) { buf.emplace_back(&a, a); } n   int snapshot() { return buf.size(); } n   void rollback(int w) { n     while (buf.size() > w) { n       int *a, b; n       tie(a, b) = buf.back(); n       buf.pop_back(); n       *a = b; n     } n   } n   bool unite(int a, int b) { n     a = find(a); n     b = find(b); n     if (a == b) return false; n     if (s[a] < s[b]) swap(a, b); n     save(p[b]); n     save(s[a]); n     p[b] = a; n     s[a] += s[b]; n     return true; n   } n   bool same(int a, int b) { return find(a) == find(b); } n   int sz(int a) { return s[find(a)]; } n }; n int main() { n   cin.tie(0); n   ios::sync_with_stdio(0); n   int n, m; n   cin >> n >> m; n   vector<E> raw(m); n   map<int, vector<pair<int, int>>> es; n   for (int i = 0; i < m; ++i) { n     int a, b, c; n     cin >> a >> b >> c; n     a--; n     b--; n     es[c].push_back({a, b}); n     raw[i] = {a, b, c}; n   } n   map<int, vector<pair<int, vector<int>>>> qs; n   int q; n   cin >> q; n   vector<int> ans(q, 1); n   for (int i = 0; i < q; ++i) { n     int k; n     cin >> k; n     vector<int> idx(k); n     for (int j = 0; j < k; ++j) { n       cin >> idx[j]; n       idx[j]--; n     } n     sort(idx.begin(), idx.end(), n          [&](int a, int b) { return raw[a].c < raw[b].c; }); n     for (int j = 0; j < k;) { n       vector<int> w; n       int r = j; n       while (r < k && raw[idx[r]].c == raw[idx[j]].c) { n         w.push_back(idx[r++]); n       } n       qs[raw[idx[j]].c].emplace_back(i, w); n       j = r; n     } n   } n   unionfind uf(n); n   for (auto kv : es) { n     for (auto z : qs[kv.first]) { n       int s = uf.snapshot(); n       for (auto i : z.second) { n         if (!uf.unite(raw[i].a, raw[i].b)) { n           ans[z.first] = 0; n         } n       } n       uf.rollback(s); n     } n     for (auto e : kv.second) { n       uf.unite(e.first, e.second); n     } n   } n   for (int i = 0; i < q; ++i) { n     if (ans[i]) n       cout <<  YES  n            <<   n ; n     else n       cout <<  NO  n            <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std::chrono; n long long MOD = 1000000007; n struct mi { n   long long v; n   explicit operator long long() const { return v; } n   mi() { v = 0; } n   mi(long long _v) { n     v = (-MOD < _v && _v < MOD) ? _v : _v % MOD; n     if (v < 0) v += MOD; n   } n   friend bool operator==(const mi &a, const mi &b) { return a.v == b.v; } n   friend bool operator!=(const mi &a, const mi &b) { return !(a == b); } n   friend bool operator<(const mi &a, const mi &b) { return a.v < b.v; } n   mi &operator+=(const mi &m) { n     if ((v += m.v) >= MOD) v -= MOD; n     return *this; n   } n   mi &operator-=(const mi &m) { n     if ((v -= m.v) < 0) v += MOD; n     return *this; n   } n   mi &operator*=(const mi &m) { n     v = v * m.v % MOD; n     return *this; n   } n   mi &operator/=(const mi &m) { return (*this) *= inv(m); } n   friend mi pow(mi a, long long p) { n     mi ans = 1; n     assert(p >= 0); n     for (; p; p /= 2, a *= a) n       if (p & 1) ans *= a; n     return ans; n   } n   friend mi inv(const mi &a) { n     assert(a.v != 0); n     return pow(a, MOD - 2); n   } n   mi operator-() const { return mi(-v); } n   mi &operator++() { return *this += 1; } n   mi &operator--() { return *this -= 1; } n   mi operator++(int) { n     mi temp; n     temp.v = v++; n     return temp; n   } n   mi operator--(int) { n     mi temp; n     temp.v = v--; n     return temp; n   } n   friend mi operator+(mi a, const mi &b) { return a += b; } n   friend mi operator-(mi a, const mi &b) { return a -= b; } n   friend mi operator*(mi a, const mi &b) { return a *= b; } n   friend mi operator/(mi a, const mi &b) { return a /= b; } n   friend ostream &operator<<(ostream &os, const mi &m) { n     os << m.v; n     return os; n   } n   friend istream &operator>>(istream &is, mi &m) { n     long long x; n     is >> x; n     m.v = x; n     return is; n   } n }; n void solve() { n   long long n; n   cin >> n; n   long long m; n   cin >> m; n   MOD = m; n   vector<mi> dp(n + 1, 0); n   vector<mi> suffix(n + 2, 0); n   dp[n] = 1; n   suffix[n] = 1; n   mi sum = 0; n   for (long long i = (n)-1; i >= 1; i--) { n     sum = sum + dp[i + 1]; n     dp[i] = sum; n     for (long long j = 2; j < (n + 1); j++) { n       if (i * j > n) n         break; n       else { n         mi sf = suffix[i * j] - suffix[min(i * j + j, n + 1)]; n         dp[i] = dp[i] + sf; n       } n     } n     suffix[i] = suffix[i + 1] + dp[i]; n   } n   cout << dp[1] << endl; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n, m, k; n     cin >> n >> m >> k; n     vector<int> lx(n), ly(m); n     vector<int> x(k), y(k); n     for (int& i : lx) cin >> i; n     for (int& i : ly) cin >> i; n     for (int i = 0; i < k; i++) { n       cin >> x[i] >> y[i]; n     } n     sort(lx.begin(), lx.end()), sort(ly.begin(), ly.end()); n     vector<int> ind(k); n     iota(ind.begin(), ind.end(), 0); n     auto solve = [&](vector<int>& lx, vector<int>& y, vector<int>& x) { n       long long ans = 0; n       for (int i = 0, j = 0; i + 1 < lx.size(); i++) { n         int c = 0; n         map<int, int> com; n         int l = lx[i], r = lx[i + 1]; n         while (j < k && x[ind[j]] <= l) j++; n         while (j < k && x[ind[j]] < r) { n           ans += c++; n           ans -= com[y[ind[j]]]++; n           j++; n         } n       } n       return ans; n     }; n     sort(ind.begin(), ind.end(), [&](int i, int j) { return x[i] < x[j]; }); n     long long ans = solve(lx, y, x); n     sort(ind.begin(), ind.end(), [&](int i, int j) { return y[i] < y[j]; }); n     ans += solve(ly, x, y); n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, c, i, j = 1; n   cin >> n; n   cin >> c; n   int arr[n]; n   for (i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   for (i = 0; i < n - 1; i++) { n     if (arr[i + 1] - arr[i] <= c) n       j = j + 1; n     else if (arr[i + 1] - arr[i] != c && i <= n - 2) n       j = 1; n     else n       j = 0; n   } n   cout << j; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int n; n int main() { n   cin >> n; n   long long int s(0); n   long long int i = 1; n   while (true) { n     s += i; n     if (s >= n) { n       break; n     } n     i++; n   } n   long long int sk = s - n; n   if (sk != 0) { n     cout << i - 1 <<   n ; n   } else { n     cout << i <<   n ; n   } n   for (long long int I = 1; I <= i; I++) { n     if (I == sk) { n       continue; n     } n     cout << I <<    ; n   } n   cout <<   n ; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int n, m, t; n struct node { n   int l, r; n } a[20050]; n int cnt[90000], ans[20050]; n bool cmp(const node &a, const node &b) { return a.l < b.l; } n int main() { n   scanf( %d%d%d , &n, &m, &t); n   int x, y, z; n   for (int i = (1); i <= (n); i++) { n     scanf( %d:%d:%d , &x, &y, &z); n     int _ = x * 3600 + y * 60 + z; n     a[i] = (node){_, _ + t}; n     cnt[_]++; n     cnt[_ + t]--; n   } n   int sum = 0, nos = 1; n   for (int i = (0); i <= (86400); i++) { n     sum += cnt[i]; n     if (sum >= m) nos = 0; n     cnt[i] = 0; n   } n   if (nos) { n     cout <<  No solution  << endl; n     return 0; n   } n   sort(a + 1, a + n + 1, cmp); n   for (int i = (1); i <= (n); i++) cnt[a[i].r]--; n   sum = 0; n   int num = 0, j = 0, la = 0; n   for (int i = (0); i <= (86400); i++) { n     sum += cnt[i]; n     while (j + 1 <= n && a[j + 1].l == i) { n       j++; n       if (sum < m) { n         sum++; n         ans[la = j] = ++num; n       } else { n         cnt[a[la].r]++; n         ans[la = j] = num; n       } n     } n   } n   cout << num << endl; n   for (int i = (1); i <= (n); i++) printf( %d n , ans[i]); n   return 0; n } n


#pragma GCC optimize( O3 , Ofast , no-stack-protector , unroll-loops , omit-frame-pointer , inline ) //Optimization flags n #pragma GCC option( arch=native , tune=native , no-zero-upper ) //Enable AVX n // #pragma GCC target( avx2 ) //Enable AVX n  n #include <bits/stdc++.h> n  n #define int long long n  n using namespace std; n  n const int MOD = 1e9 + 7; n  n const int MAXN = 110; n  n int C[MAXN]; n  n int B[MAXN]; n  n int T[MAXN]; n  n int dp[MAXN][MAXN*MAXN]; n  n int32_t main() n { n     ios_base::sync_with_stdio(0); n     cin.tie(0); n  n  int N; n  cin >> N; n  n  for(int i = 1 ; i <= N ; i++) n  { n   cin >> C[i]; n  }     n  n  for(int i = 2 ; i <= N ; i++) n  { n   cin >> B[i]; n   T[i] = T[i-1]+B[i]; n  } n  n  for(int i = 1 ; i <= N ; i++) n  { n   T[i] += T[i-1]; n  } n  n  int ini = -T[N]/N - 50; n  int fin = (100*N-T[N])/N + 50; n  n  map<int,int> mp; n  n  for(int X = ini ; X <= fin ; X++) n  { n   for(int j = 0 ; j <= 10000 ; j++) n   { n    dp[0][j] = 1; n   } n  n   for(int i = 1 ; i <= N ; i++) n   { n    for(int j = 0 ; j <= 10000 ; j++) n    { n     dp[i][j] = 0; n     if(j-T[i] >= X*i) n     { n      int val = 0; n      if(j-C[i]-1 >= 0)val = dp[i-1][j-C[i]-1]; n  n      dp[i][j] = (dp[i-1][j]+MOD-val); n      dp[i][j] %= MOD; n     } n    } n  n    for(int j = 1 ; j <= 10000 ; j++) n    { n     dp[i][j] += dp[i][j-1]; n     dp[i][j] %= MOD; n    } n   } n  n   mp[X] = dp[N][10000]; n  } n  n  int Q; n  cin >> Q; n  n  for(int i = 1 ; i <= Q ; i++) n  { n   int X; n   cin >> X; n  n   if(X < ini)cout << mp[ini] <<   n ; n   else if(X > fin)cout << 0 <<   n ; n   else cout << mp[X] <<   n ; n  } n  n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, z; n   cin >> n >> m; n   z = 0; n   int* a = new int[n + 1]; n   int* s = new int[n + 1]; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   s[1] = a[1]; n   s[0] = 0; n   for (int i = 2; i <= n; i++) s[i] = a[i] + s[i - 1]; n   for (int i = 1; i <= m; i++) { n     int l, r; n     cin >> l >> r; n     int v = s[r] - s[l - 1]; n     if (v > 0) { n       z += v; n     } n   } n   cout << z << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int sum[26]; n char str[5002]; n char str_list[5002][5002]; n int main() { n   double ans = 0.0; n   scanf( %s , str), n = strlen(str); n   for (int i = 0; i < 26; i++) { n     int cnt = 0; n     int max_total = 0; n     for (int j = 0; j < n; j++) n       if (str[j] ==  a  + i) { n         for (int k = j; k < n; k++) str_list[cnt][k - j] = str[k]; n         for (int k = 0; k < j; k++) str_list[cnt][k + n - j] = str[k]; n         cnt++; n       } n     for (int j = 1; j < n; j++) { n       int total = 0; n       for (int k = 0; k < 26; k++) sum[k] = 0; n       for (int k = 0; k < cnt; k++) sum[(int)(str_list[k][j] -  a )]++; n       for (int k = 0; k < 26; k++) n         if (sum[k] == 1) total++; n       max_total = max(max_total, total); n     } n     ans += 1.0 * max_total / (1.0 * n); n   } n   printf( %.10lf n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   ; n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     if (n <= 3) n       cout << -1 <<   n ; n     else { n       if (n & 1) { n         for (long long i = 1; i <= n; i++) { n           if (i & 1) cout << i <<    ; n         } n         cout << n - 3 <<     << n - 1 <<    ; n         for (long long i = n - 4; i >= 1; i--) { n           if ((i & 1) == 0) cout << i <<    ; n         } n         cout <<   n ; n       } else { n         for (long long i = 1; i <= n; i++) { n           if ((i & 1) == 0) cout << i <<    ; n         } n         cout << n - 3 <<     << n - 1 <<    ; n         for (long long i = n - 4; i >= 1; i--) { n           if ((i & 1)) cout << i <<    ; n         } n         cout <<   n ; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int mx[4] = {1, 0, -1, 0}; n int my[4] = {0, 1, 0, -1}; n void dfs(int x, int y, vector<vector<char> > &b, vector<vector<int> > &val, n          int &c, int &v) { n   v++; n   val[x][y] = c; n   for (int i = 0; i < 4; i++) { n     int xt = x + mx[i]; n     int yt = y + my[i]; n     if (xt >= 0 && xt < b.size() && yt >= 0 && yt < b[0].size() && n         b[xt][yt] ==  .  && val[xt][yt] == 0) { n       dfs(xt, yt, b, val, c, v); n     } n   } n } n int main() { n   int n, m; n   while (cin >> n >> m) { n     vector<vector<char> > board(n, vector<char>(m,  . )); n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) cin >> board[i][j]; n     } n     vector<vector<int> > values(n, vector<int>(m, 0)); n     int color = 1; n     vector<int> colors(n * m, 0); n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         if (board[i][j] ==  .  && values[i][j] == 0) { n           int val = 0; n           dfs(i, j, board, values, color, val); n           colors[color] = val; n           color++; n         } n       } n     } n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         if (board[i][j] ==  . ) { n           cout <<  . ; n           continue; n         } else { n           int acu = 0; n           set<int> valA; n           for (int k = 0; k < 4; k++) { n             int xt = i + mx[k]; n             int yt = j + my[k]; n             if (xt >= 0 && xt < board.size() && yt >= 0 && n                 yt < board[0].size() && !valA.count(values[xt][yt])) { n               acu += colors[values[xt][yt]]; n               valA.insert(values[xt][yt]); n             } n           } n           cout << (acu + 1) % 10; n         } n       } n       cout << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n bool isOk(char c, int v) { return v == (c ==  B  ? -1 : 1); } n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   string a[n]; n   int v[n][m]; n   char ch; n   int vx; n   int nOp = 0; n   for (int i = 0; i < n; i++) { n     fill(v[i], v[i] + m, 0); n     cin >> a[i]; n   } n   for (int i = n - 1; i >= 0; i--) n     for (int j = m - 1; j >= 0; j--) { n       if (!isOk(a[i][j], v[i][j])) { n         ++nOp; n         vx = (a[i][j] ==  W  ? v[i][j] - 1 : v[i][j] + 1); n         for (int i1 = 0; i1 <= i; i1++) n           for (int j1 = 0; j1 <= j; j1++) v[i1][j1] -= vx; n       } n     } n   printf( %d n , nOp); n   return 0; n   return 0; n } n


#include <bits/stdc++.h> n #include<unordered_map> n //#pragma GCC optimize(2) n #define ll long long n #define sc(n) scanf( %d ,&n) n #define scl(n) scanf( %lld ,&n) n //#define int ll n using namespace std; n inline int rd() { int x = 0, f = 1; char c = getchar(); while (c !=  -  && c < 48)c = getchar(); if (c ==  - )f = -1, c = getchar(); while (c > 47)x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); return f * x; } n const int maxn = 500001, inf = 2147483647; n const ll mod = 0 ? 998244353 : 1000000007, linf = 9223372036854775807; n const double pi = acos(-1); n inline ll mi(ll a, ll b, ll mm = mod) { a %= mm; ll u = 1; while (b) { if (b & 1)u = u * a % mm; a = a * a % mm, b >>= 1; }return u; } n inline ll gcd(ll a, ll b) { ll c = a % b; while (c)a = b, b = c, c = a % b; return b; } n inline void mem(int* a, int p = 0, int len = maxn) { for (int i = 0; i < len; i++)a[i] = p; } n struct p { int r, c; }e[maxn]; n static bool cmp(p i, p j) { return i.r < j.r; }; n int t, n, m, a[maxn], b[maxn], c[maxn], x, y, xx, yy, su, q, k, u, l, r; n string s; n int g(int n) { n  int x = 1, y = n; n  while (y) n   x <<= 1, y >>= 1; n  x >>= 1; n  return x; n } n signed main() { n  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);//sf和cin混用会出错 n  cin >> t; n  while (t--) { n   cin >> n >> m; n   map<int, int>ma; n   for (int i = 0; i < n; i++) n    cin >> a[i], ma[a[i]]++; n   su = 0; n   while (n) { n    su++; n    y = m, x = g(m); n    while (x) { n     while (ma[x] && y >= x) n      y -= x, n--, ma[x]--; n     x >>= 1; n    } n   } n   cout << su << endl; n  } n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, j; n   long long n, a, b, ans; n   long long arr[50]; n   arr[0] = 1; n   for (i = 1; i < 40; i++) arr[i] = arr[i - 1] * 3; n   scanf( %I64d , &n); n   for (i = 0; i < 40; i++) { n     if (n == arr[i]) { n       printf( 1 n ); n       break; n     } else if (n % arr[i] != 0) { n       b = arr[i]; n       a = (n / arr[i]) + 1; n       printf( %I64d n , a); n       break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int ans, n; n string str; n char ch[101000]; n int a[101000]; n void init() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> ch[i]; n   } n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n } n void work() { n   int ti = 0; n   for (int i = 1; ti <= n; ti++) { n     if (ch[i] ==  > ) n       i += a[i]; n     else if (ch[i] ==  < ) { n       i -= a[i]; n     } n     if (i < 1 || i > n) { n       cout <<  FINITE  << endl; n       return; n     } n   } n   cout <<  INFINITE  << endl; n } n int main() { n   init(); n   work(); n   return 0; n } n


#include <bits/stdc++.h> n #include <iostream> n using namespace std; n const int MAX_N = 1e5 + 5; n const int MAX_L = 20; // ~ Log N n const long long MOD = 1e9 + 7; n const long long INF = 1e9 + 7; n typedef long long ll; n  n const int mx = 5e6 + 23; n const ll mod = 1e9 + 7; n  n int a[mx], team[mx], org[mx]; n int n, m; n ll s[2]; n  n int seed, base; n int rnd(){ n   int ret = seed; n   seed = (1ll * seed * base + 233) % mod; n   return ret; n } n  n void solve() { n   cin>>n>>m; n   int lastp = 0; n   for(int i=1,p,k,b,w;i<=m;i++){ n     cin>>p>>k>>b>>w; n     seed = b; n     base = w; n     for(int j=lastp;j<p;j++){ n       team[j] = rnd() % 2; n       s[team[j]] += (org[j] = a[j] = rnd() % k + 1); n     } n     lastp = p; n   } n   int st = 0; n   if(s[team[0]] > s[!team[0]]){ n     s[team[0]]--; n     a[0]--; n     while(team[0] == team[st] && st < n) n       st++; n   } n   int cur = st; n   ll sum = 0; n   if(st != n) n     while(s[team[st]]){ n       if(team[cur] == team[st]){ n         sum += a[cur]; n         a[cur] = 0; n       } n       else{ n         ll d = min(1ll * a[cur], sum); n         s[team[st]] -= d; n         sum -= d; n         a[cur] -= d; n       } n       cur = (cur + 1 == n ? 0 : cur + 1); n     } n     ll ans = 1; n     for(int i=0;i<n;i++){ n       ll qwq = (((org[i] - a[i]) ^ (1ll * (i + 1) * (i + 1))) + 1) % mod; n       ans = ans * qwq % mod; n     } n     cout<<ans; n } n int main()  n {  n    ios_base::sync_with_stdio(false);cin.tie(NULL);  n     n    #ifndef ONLINE_JUDGE  n    freopen( input.txt ,  r , stdin);  n    freopen( error.txt ,  w , stderr);  n    freopen( output.txt ,  w , stdout);  n    #endif  n     n    int t=1;  n  // cin>>t;  n    while(t--)  n    {  n       solve();  n      // cout<<  n ;  n    }  n     n    cerr<< time taken :  <<(float)clock()/CLOCKS_PER_SEC<<  secs <<endl;  n    return 0;  n }  n


#include <bits/stdc++.h> n using namespace std; n int n; n string s; n set<string> st; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> s; n     sort(s.begin(), s.end()); n     s.erase(unique(s.begin(), s.end()), s.end()); n     st.insert(s); n   } n   cout << st.size(); n } n


#include <bits/stdc++.h> n using namespace std; n string s; n int main() { n   long long ans = 0; n   string in; n   string un =  ><+-.,[] ; n   cin >> in; n   for (int i = 0; i < in.size(); i++) { n     ans = (16 * ans + (un.find(in[i]) + 8)) % 1000003; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n ostream &operator<<(ostream &os, const vector<T> &v) { n   os <<  { ; n   string sep; n   for (const auto &x : v) os << sep << x, sep =  ,  ; n   return os <<  } ; n } n template <typename T, size_t size> n ostream &operator<<(ostream &os, const array<T, size> &arr) { n   os <<  { ; n   string sep; n   for (const auto &x : arr) os << sep << x, sep =  ,  ; n   return os <<  } ; n } n template <typename A, typename B> n ostream &operator<<(ostream &os, const pair<A, B> &p) { n   return os <<  (  << p.first <<  ,   << p.second <<  ) ; n } n void dbg_out() { cerr << endl; } n template <typename Head, typename... Tail> n void dbg_out(Head H, Tail... T) { n   cerr <<     << H; n   dbg_out(T...); n } n auto random_address = [] { n   char *p = new char; n   delete p; n   return (uint64_t)p; n }; n mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count() * n                (random_address() | 1)); n template <typename T> n void output_vector(const vector<T> &v, bool add_one = false, int start = -1, n                    int end = -1) { n   if (start < 0) start = 0; n   if (end < 0) end = int(v.size()); n   for (int i = start; i < end; i++) n     cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ?     :   n ); n } n const int ATTEMPTS = 50; n int N, M; n vector<vector<int>> adj; n vector<int> tour_index; n vector<array<int, 2>> low_link; n vector<bool> in_stack; n int tour; n vector<int> tour_list; n array<int, 2> combine(array<int, 2> x, int y) { n   array<int, 3> a = {x[0], x[1], y}; n   sort(a.begin(), a.end()); n   return {a[0], a[1]}; n } n array<int, 2> combine(array<int, 2> x, array<int, 2> y) { n   array<int, 4> a = {x[0], x[1], y[0], y[1]}; n   sort(a.begin(), a.end()); n   return {a[0], a[1]}; n } n bool interesting_dfs(int node) { n   tour_index[node] = tour++; n   tour_list.push_back(node); n   low_link[node] = {tour_index[node], tour_index[node]}; n   in_stack[node] = true; n   for (int neighbor : adj[node]) n     if (tour_index[neighbor] < 0) { n       if (!interesting_dfs(neighbor)) return false; n       low_link[node] = combine(low_link[node], low_link[neighbor]); n     } else if (in_stack[neighbor]) { n       low_link[node] = combine(low_link[node], tour_index[neighbor]); n     } else { n       return false; n     } n   in_stack[node] = false; n   return true; n } n vector<int> save_interesting; n bool check_interesting(int node) { n   if (save_interesting[node] >= 0) return save_interesting[node]; n   tour_index.assign(N, -1); n   low_link.resize(N); n   in_stack.assign(N, false); n   tour = 0; n   tour_list.clear(); n   return (save_interesting[node] = interesting_dfs(node)); n } n void run_case() { n   cin >> N >> M; n   adj.assign(N, {}); n   for (int i = 0; i < M; i++) { n     int u, v; n     cin >> u >> v; n     u--; n     v--; n     adj[u].push_back(v); n   } n   save_interesting.assign(N, -1); n   int root = -1; n   for (int iter = 0; iter < ATTEMPTS; iter++) { n     root = int(rng() % N); n     if (check_interesting(root)) break; n     root = -1; n   } n   if (root < 0) { n     cout << -1 <<   n ; n     return; n   } n   vector<bool> bad(N, false); n   for (int x : tour_list) n     if (low_link[x][0] < tour_index[x] && low_link[x][1] < tour_index[x]) { n       bad[x] = true; n     } else { n       assert(low_link[x][1] == tour_index[x]); n       int above = tour_list[low_link[x][0]]; n       bad[x] = bad[above]; n     } n   vector<int> interesting; n   for (int i = 0; i < N; i++) n     if (!bad[i]) interesting.push_back(i); n   if (5 * int(interesting.size()) < N) n     cout << -1 <<   n ; n   else n     output_vector(interesting, true); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int tests; n   cin >> tests; n   while (tests-- > 0) run_case(); n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int a[50]; n int main() { n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     a[i] %= m; n   } n   sort(a, a + n); n   set<int> S1, S2; n   for (int i = 0; i < n; i++) { n     set<int> s = i < n / 2 ? S1 : S2; n     s.insert(a[i]); n     for (auto b : i < n / 2 ? S1 : S2) { n       s.insert((a[i] + b) % m); n     } n     if (i < n / 2) n       S1 = s; n     else n       S2 = s; n   } n   S1.insert(0); n   S2.insert(0); n   int best = 0; n   for (auto b : S1) { n     best = max(best, b + *(--S2.lower_bound(m - b))); n   } n   cout << best; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1000 * 100 + 10; n const int MOD = 1000 * 1000 * 1000 + 7; n long double n, m; n long double Pow(long double a, int b) { n   if (b == 0) return 1; n   long double x = Pow(a, b / 2); n   x *= x; n   if (b % 2) x *= a; n   return x; n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0), cout.tie(0); n   cout << fixed << setprecision(10); n   cin >> m >> n; n   long double ans = 0; n   for (long double i = 1; i < m; i++) { n     ans += Pow(i / m, n); n   } n   cout << m - ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x, y; n   cin >> n; n   long long sumX = 0; n   long long sumY = 0; n   long long sum = 0; n   for (int i = n; i > 0; i--) { n     cin >> x; n     cin >> y; n     sumX += x; n     sum += x * x; n     sumY += y; n     sum += y * y; n   } n   printf( %I64d , (n * sum) - (sumX * sumX) - (sumY * sumY)); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 2005; n bool a[MAX][MAX], row[MAX], col[MAX]; n int main() { n   ios::sync_with_stdio(false); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) { n       char c; n       cin >> c; n       a[i][j] = (c ==  1 ); n     } n   int ans = 0; n   for (int i = 0; i < n; i++) n     for (int j = n - 1; j > i; j--) n       if (a[i][j] ^ row[i] ^ col[j]) { n         a[i][j] = false; n         row[i] = !row[i]; n         col[j] = !col[j]; n         ans++; n       } n   for (int i = 0; i < n; i++) { n     a[i][i] ^= row[i] ^ col[i]; n     row[i] = col[i] = false; n   } n   for (int j = 0; j < n; j++) n     for (int i = n - 1; i > j; i--) n       if (a[i][j] ^ row[i] ^ col[j]) { n         a[i][j] = false; n         row[i] = !row[i]; n         col[j] = !col[j]; n         ans++; n       } n   for (int i = 0; i < n; i++) ans += (a[i][i] ^ row[i] ^ col[i]); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> digs; n   while (n % 10 != 0) { n     digs.push_back(n % 10); n     n /= 10; n   } n   reverse(digs.begin(), digs.end()); n   int ans = 1; n   for (int i = 0; i < digs.size(); i++) { n     ans *= 2; n     if (digs[i] == 7) { n       ans++; n     } n   } n   cout << ans - 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 105; n const int M = 2005; n pair<pair<int, int>, pair<int, int> > adj[N]; n int dp[M]; n vector<int> way[M]; n bool cmp(pair<pair<int, int>, pair<int, int> > a, n          pair<pair<int, int>, pair<int, int> > b) { n   return a.second.second < b.second.second; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     int t, d, p; n     cin >> t >> d >> p; n     adj[i] = make_pair(make_pair(t, i), make_pair(p, d)); n   } n   sort(adj + 1, adj + 1 + n, cmp); n   for (int i = 1; i <= n; i++) { n     for (int j = adj[i].second.second - 1; j >= adj[i].first.first; j--) { n       if (dp[j] < dp[j - adj[i].first.first] + adj[i].second.first) { n         dp[j] = dp[j - adj[i].first.first] + adj[i].second.first; n         way[j] = way[j - adj[i].first.first]; n         way[j].emplace_back(adj[i].first.second); n       } n     } n   } n   int ans1 = 0; n   vector<int> ans2; n   for (int i = 0; i <= M - 1; i++) { n     if (dp[i] > ans1) { n       ans1 = dp[i]; n       ans2 = way[i]; n     } n   } n   cout << ans1 <<   n  << ans2.size() <<   n ; n   for (auto op : ans2) { n     cout << op <<    ; n   } n } n


#include <bits/stdc++.h> n const double eps = 1e-9; n using namespace std; n double f[2050], p[2050], q[2050]; n int fa[2050], fb[2050]; n int n, a, b; n void calc(double w1, double w2) { n   for (int i = 1; i <= n; i++) { n     f[i] = f[i - 1]; n     fa[i] = fa[i - 1]; n     fb[i] = fb[i - 1]; n     if (f[i - 1] + p[i] - w1 > f[i]) { n       f[i] = f[i - 1] + p[i] - w1; n       fa[i] = fa[i - 1] + 1; n       fb[i] = fb[i - 1]; n     } n     if (f[i - 1] + q[i] - w2 > f[i]) { n       f[i] = f[i - 1] + q[i] - w2; n       fa[i] = fa[i - 1]; n       fb[i] = fb[i - 1] + 1; n     } n     if (f[i - 1] + p[i] + q[i] - p[i] * q[i] - w1 - w2 > f[i]) { n       f[i] = f[i - 1] + p[i] + q[i] - p[i] * q[i] - w1 - w2; n       fa[i] = fa[i - 1] + 1; n       fb[i] = fb[i - 1] + 1; n     } n   } n } n int main() { n   scanf( %d%d%d , &n, &a, &b); n   for (int i = 1; i <= n; i++) scanf( %lf , &p[i]); n   for (int i = 1; i <= n; i++) scanf( %lf , &q[i]); n   double l1 = 0, r1 = 1, l2, r2; n   while (l1 + eps < r1) { n     double mid1 = (l1 + r1) / 2; n     l2 = 0, r2 = 1; n     while (l2 + eps < r2) { n       double mid2 = (l2 + r2) / 2; n       calc(mid1, mid2); n       if (fb[n] > b) n         l2 = mid2; n       else n         r2 = mid2; n     } n     calc(mid1, r2); n     if (fa[n] > a) n       l1 = mid1; n     else n       r1 = mid1; n   } n   calc(r1, r2); n   printf( %.10lf n , f[n] + a * r1 + b * r2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100 + 10; n int n, m; n int main() { n   cin >> n >> m; n   cout << n + m - 1 << endl; n   cout <<  1 1  << endl; n   for (int i = 2; i <= n; ++i) cout << i <<   1  << endl; n   for (int i = 2; i <= m; ++i) cout <<  1   << i << endl; n   fclose(stdin); n   fclose(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200005; n int n, ans, root; n int f[N], fa[N]; n inline int read() { n   int a = 0, f = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     a = a * 10 + c -  0 ; n     c = getchar(); n   } n   return a * f; n } n int find(int i) { return f[i] == i ? i : f[i] = find(f[i]); } n int main() { n   n = read(); n   for (int i = 1; i <= n; i++) f[i] = i; n   for (int i = 1; i <= n; i++) { n     fa[i] = read(); n     if (fa[i] == i) root = i; n   } n   for (int i = 1; i <= n; i++) { n     if (i != root) { n       int p = find(i), q = find(fa[i]); n       if (p == q) { n         ans++; n         if (!root) root = i; n         fa[i] = root; n       } else n         f[p] = q; n     } n   } n   printf( %d n , ans); n   for (int i = 1; i <= n; i++) printf( %d%c , fa[i], i == n ?   n  :    ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int nr, N, K, ap[100009], last_N; n pair<int, int> ans[10]; n struct line { n   int a, b, c, init; n }; n vector<line> v; n struct point { n   long long a, b, c, d; n   bool operator==(const point &other) const { n     return (1LL * a * other.b == 1LL * b * other.a && n             1LL * c * other.d == 1LL * d * other.c); n   } n   bool operator<(const point &other) const { n     if (1LL * a * other.b == 1LL * b * other.a) n       return (1LL * c * other.d < 1LL * d * other.c); n     return (1LL * a * other.b < 1LL * b * other.a); n   } n }; n bool OnLine(point p, line l) { n   return ((long long)1LL * l.a * p.a * p.d + 1LL * l.b * p.b * p.c + n               1LL * l.c * p.b * p.d == n           0LL); n } n bool Exist_Intersection(line p, line q) { n   return (1LL * p.a * q.b != 1LL * p.b * q.a); n } n point Intersect(line p, line q) { n   point ans; n   ans.c = (long long)1LL * q.c * p.a - 1LL * q.a * p.c; n   ans.d = (long long)1LL * p.b * q.a - 1LL * q.b * p.a; n   ans.a = (long long)1LL * q.c * p.b - 1LL * q.b * p.c; n   ans.b = (long long)1LL * p.a * q.b - 1LL * q.a * p.b; n   return ans; n } n void Push(int i, int j) { ans[++nr] = make_pair(i, j); } n void Pop() { nr--; } n bool back(int pos, int K, vector<line> v) { n   if (pos == v.size()) return 1; n   if (K < 0) return 0; n   if (ap[pos]) return back(pos + 1, K, v); n   point I; n   for (int i = pos + 1; i < N; i++) { n     if (ap[i]) continue; n     if (Exist_Intersection(v[i], v[pos]) == 0) continue; n     I = Intersect(v[i], v[pos]); n     for (int j = pos; j < N; j++) n       if (OnLine(I, v[j])) ap[j]++; n     Push(v[pos].init, v[i].init); n     if (back(pos + 1, K - 1, v) == 1) return 1; n     Pop(); n     for (int j = pos; j < N; j++) n       if (OnLine(I, v[j])) ap[j]--; n   } n   Push(v[pos].init, -1), ap[pos]++; n   if (back(pos + 1, K - 1, v) == 1) return 1; n   Pop(), ap[pos]--; n   return 0; n } n bool solve(int K, vector<line> v) { n   int N = v.size(); n   if (K >= N) { n     for (int i = 0; i < N; i++) Push(v[i].init, -1); n     return 1; n   } n   if (K < 0) return 0; n   if (N <= K * K) { n     if (back(0, K, v)) return 1; n     return 0; n   } n   int M = K * K + 1, needed = K + 1; n   set<point> inters; n   for (int i = 0; i < M; i++) n     for (int j = i + 1; j < M; j++) { n       if (Exist_Intersection(v[i], v[j]) == 0) continue; n       point curr = Intersect(v[i], v[j]); n       if (inters.count(curr)) continue; n       inters.insert(curr); n       int nr = 0; n       for (int p = i; p < M; p++) n         if (OnLine(curr, v[p])) nr++; n       if (nr >= needed) { n         vector<line> apel; n         for (int p = 0; p < N; p++) n           if (!OnLine(curr, v[p])) apel.push_back(v[p]); n         Push(v[i].init, v[j].init); n         if (solve(K - 1, apel)) return 1; n         Pop(); n         return 0; n       } n     } n   return 0; n } n int main() { n   scanf( %d %d , &N, &K); n   for (int i = 1; i <= N; i++) { n     line curr; n     scanf( %d %d %d , &curr.a, &curr.b, &curr.c), curr.init = i; n     v.push_back(curr); n   } n   if (solve(K, v)) { n     printf( YES n ); n     printf( %d n , nr); n     for (int i = 1; i <= nr; i++) n       printf( %d %d n , ans[i].first, ans[i].second); n     return 0; n   } n   printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e3 + 50; n const int INF = 1e9 + 7; n struct Edge { n   int from, to, cap, flow, cost; n   Edge(int from, int to, int cap, int flow, int cost) n       : from(from), to(to), cap(cap), flow(flow), cost(cost) {} n }; n struct MCMF { n   vector<Edge> edge; n   vector<int> g[maxn]; n   int a[maxn], p[maxn], c[maxn], inq[maxn], n; n   void init(int n) { n     this->n = n; n     edge.clear(); n     for (int i = 0; i <= n; i++) g[i].clear(); n   } n   void addedge(int from, int to, int cap, int cost) { n     edge.push_back(Edge(from, to, cap, 0, cost)); n     edge.push_back(Edge(to, from, 0, 0, -cost)); n     int m = edge.size(); n     g[from].push_back(m - 2); n     g[to].push_back(m - 1); n   } n   bool bellmanford(int s, int t, int limit_flow, int &flow, long long &cost) { n     memset(a, 0, sizeof(a)); n     memset(c, 126, sizeof(c)); n     memset(inq, 0, sizeof(inq)); n     queue<int> q; n     a[s] = INF; n     c[s] = 0; n     inq[s] = 1; n     q.push(s); n     while (!q.empty()) { n       int x = q.front(); n       inq[x] = 0; n       q.pop(); n       for (int i = 0; i < g[x].size(); i++) { n         Edge &e = edge[g[x][i]]; n         if (e.cap > e.flow && c[e.to] > c[x] + e.cost) { n           c[e.to] = c[x] + e.cost; n           p[e.to] = g[x][i]; n           a[e.to] = min(a[x], e.cap - e.flow); n           if (!inq[e.to]) { n             q.push(e.to); n             inq[e.to] = 1; n           } n         } n       } n     } n     if (c[t] >= INF) return false; n     if (a[t] + flow > limit_flow) a[t] = limit_flow - flow; n     for (int i = t; i != s; i = edge[p[i]].from) { n       edge[p[i]].flow += a[t]; n       edge[p[i] ^ 1].flow -= a[t]; n     } n     flow += a[t]; n     cost += (long long)c[t] * a[t]; n     return true; n   } n   int solve(int s, int t, int limit_flow, long long &cost) { n     int flow = 0; n     cost = 0; n     while (flow < limit_flow && bellmanford(s, t, limit_flow, flow, cost)) n       ; n     return flow; n   } n } solver; n struct tree { n   vector<int> g[maxn]; n   int need[maxn], id[maxn], father[maxn]; n   int n; n   void init(int n) { n     this->n = n; n     memset(need, 0, sizeof(need)); n     for (int i = 0; i <= n; i++) g[i].clear(); n   } n   void add(int u, int v) { n     g[u].push_back(v); n     g[v].push_back(u); n   } n   void update(int k, int x) { need[k] = x; } n   void _dfs(int s) { dfs(s, -1); } n   void dfs(int u, int fa) { n     if (fa != -1) id[u] = id[fa]; n     if (need[u]) id[u] = u; n     father[u] = fa; n     for (int i = 0; i < g[u].size(); i++) { n       int v = g[u][i]; n       if (v == fa) continue; n       dfs(v, u); n     } n   } n   int _dfs2(int u) { return dfs2(u, father[u], u); } n   int dfs2(int u, int fa, int cur) { n     if (u != cur && need[u]) return need[u]; n     int ret = 0; n     for (int i = 0; i < g[u].size(); i++) { n       int v = g[u][i]; n       if (v == fa) continue; n       ret += dfs2(v, u, cur); n     } n     return ret; n   } n   void debug() { n     for (int i = 1; i <= n; i++) printf( %d  , need[i]); n     printf(  n ); n     for (int i = 1; i <= n; i++) printf( %d  , id[i]); n     printf(  n ); n   } n } cand1, cand2; n int a[maxn]; n int main() { n   int n, x, y, q, u, v, k, p; n   scanf( %d%d%d , &n, &x, &y); n   solver.init(2 * n + 2); n   int s = 0, t = 2 * n + 1; n   cand1.init(n); n   cand2.init(n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (int i = 1; i < n; i++) { n     scanf( %d%d , &u, &v); n     cand1.add(u, v); n   } n   for (int i = 1; i < n; i++) { n     scanf( %d%d , &u, &v); n     cand2.add(u, v); n   } n   scanf( %d , &q); n   for (int i = 0; i < q; i++) { n     scanf( %d%d , &k, &p); n     cand1.update(k, p); n   } n   scanf( %d , &q); n   for (int i = 0; i < q; i++) { n     scanf( %d%d , &k, &p); n     cand2.update(k, p); n   } n   cand1._dfs(x); n   cand2._dfs(y); n   int flows = 0; n   bool flag = true; n   for (int i = 1; i <= n; i++) { n     if (cand1.need[i]) { n       solver.addedge(s, i, cand1.need[i] - cand1._dfs2(i), 0); n       if (cand1.need[i] - cand1._dfs2(i) < 0) flag = false; n       flows += cand1.need[i] - cand1._dfs2(i); n     } n   } n   int flowt = 0; n   for (int i = 1; i <= n; i++) { n     if (cand2.need[i]) { n       solver.addedge(i + n, t, cand2.need[i] - cand2._dfs2(i), 0); n       if (cand2.need[i] - cand2._dfs2(i) < 0) flag = false; n       flowt += cand2.need[i] - cand2._dfs2(i); n     } n   } n   for (int i = 1; i <= n; i++) n     solver.addedge(cand1.id[i], cand2.id[i] + n, 1, -a[i]); n   long long cost; n   if (!flag || flows != flowt || solver.solve(s, t, INF, cost) != flows) n     printf( -1 n ); n   else n     printf( %I64d n , -cost); n   return 0; n } n


#include <bits/stdc++.h> n int n, m; n int a[2000]; n int b[2000]; n int can[2000]; n using namespace std; n int main() { n   int c = 0; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i] >> b[i]; n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if (i != j && !can[j] && b[i] == a[j]) { n         can[j] = 1; n         c++; n       } n     } n   } n   cout << n - c << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k, d[1010][1010], inf, sx, sy, tx, ty, dx[] = {1, -1, 0, 0}, n                                                  dy[] = {0, 0, 1, -1}; n char s[1010][1010]; n struct P { n   int x, y; n } u, v; n int tmp; n queue<P> q; n int main() { n   memset(d, 33, sizeof d); n   inf = d[0][0]; n   scanf( %d%d%d , &n, &m, &k); n   for (int i = 1; i <= n; i++) { n     scanf( %s , s[i] + 1); n   } n   scanf( %d%d%d%d , &sx, &sy, &tx, &ty); n   d[sx][sy] = 0; n   for (q.push((P){sx, sy}); !q.empty(); q.pop()) { n     u = q.front(); n     if (u.x == tx && u.y == ty) return 0 * printf( %d , d[tx][ty]); n     for (int di = 0; di < 4; di++) { n       for (int i = 1; i <= k; i++) { n         v = (P){u.x + dx[di] * i, u.y + dy[di] * i}; n         if (s[v.x][v.y] !=  .  || d[v.x][v.y] <= d[u.x][u.y]) break; n         if (d[v.x][v.y] > d[u.x][u.y] + 1) { n           d[v.x][v.y] = d[u.x][u.y] + 1; n           q.push(v); n         } n       } n     } n   } n   puts( -1 ); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   int n; n   cin >> n; n   int sum1 = 0, sum2 = 0, sum3 = 0; n   int flag1 = 1, flag2 = 0, flag3 = 0; n   for (int i = 1; i <= n; i++) { n     int a; n     cin >> a; n     if (flag1) { n       sum1 += a; n       flag1 = 0; n       flag2 = 1; n       continue; n     } n     if (flag2) { n       sum2 += a; n       flag2 = 0; n       flag3 = 1; n       continue; n     } n     if (flag3) { n       sum3 += a; n       flag3 = 0; n       flag1 = 1; n       continue; n     } n   } n   if (sum1 > sum2 && sum1 > sum3) { n     cout <<  chest n ; n   } else if (sum2 > sum1 && sum2 > sum3) { n     cout <<  biceps n ; n   } else { n     cout <<  back n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n long long binpow(long long a, long long b) { n   long long res = 1; n   while (b != 0) { n     if (b & 1) res *= a, res %= 1000000007; n     a *= a, a %= 1000000007; n     b >>= 1; n   } n   return res % 1000000007; n } n void fastio() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n void solve() { n   long long a, b, c; n   cin >> a >> b >> c; n   long long x = a + 2 * b + 3 * c; n   if (x % 2 == 0) n     cout << 0 <<   n ; n   else n     cout << 1 <<   n ; n } n signed main() { n   fastio(); n   long long t; n   cin >> t; n   for (long long i = 1; i <= t; i++) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e5 + 10; n int fn[2][MAXN], a[2][MAXN], ans[MAXN], fans[MAXN]; n void add(int p, int val, int id) { n   for (++p; p < MAXN; p += p & (-p)) fn[id][p] += val; n } n int get(int p, int id) { n   int res = 0; n   for (; p > 0; p -= p & (-p)) res += fn[id][p]; n   return res; n } n int calc(int ind, int n) { n   if (ind == n) return 0; n   int rem = calc(ind + 1, n), REM = 0; n   int id1 = get(a[0][ind], 0), id2 = get(a[1][ind], 01); n   if (id1 + id2 + rem >= n - ind) REM = 1; n   ans[ind] = (id1 + id2 + rem) % (n - ind); n   add(a[0][ind], 1, 0); n   add(a[1][ind], 1, 1); n   return REM; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[0][i]; n   for (int i = 0; i < n; i++) cin >> a[1][i]; n   calc(0, n); n   for (int i = 0; i < n; i++) { n     int num = ans[i] + 1; n     int l = -1, r = n - 1; n     while (r - l > 1) { n       int mid = (l + r) / 2; n       if (get(mid + 1, 0) >= num) n         r = mid; n       else n         l = mid; n     } n     fans[i] = r; n     add(r, -1, 0); n   } n   for (int i = 0; i < n; i++) cout << fans[i] <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n const int MAXN = 100005; n int n; n char s[MAXN]; n int B = 0, R = 0; n int main() { n   while (scanf( %d , &n) != EOF) { n     scanf( %s , s); n     int res = 0; n     B = 0, R = 0; n     char pre; n     for (int i = 0; i < n; i++) { n       if (i == 0) { n         pre = s[0]; n         continue; n       } n       if (s[i] != pre) { n         pre = s[i]; n         continue; n       } n       if (s[i] ==  r ) { n         if (R == 0) { n           res++; n           pre =  b ; n           B++; n         } else { n           pre =  b ; n           R--; n         } n       } else { n         if (B == 0) { n           res++; n           pre =  r ; n           R++; n         } else { n           pre =  r ; n           B--; n         } n       } n     } n     int ans = res; n     res = 0; n     B = 0, R = 0; n     for (int i = 0; i < n; i++) { n       if (i == 0) { n         if (s[0] ==  b ) { n           pre =  r ; n           R++; n           res++; n         } else { n           pre =  b ; n           B++; n           res++; n         } n         continue; n       } n       if (s[i] != pre) { n         pre = s[i]; n         continue; n       } n       if (s[i] ==  r ) { n         if (R == 0) { n           res++; n           pre =  b ; n           B++; n         } else { n           pre =  b ; n           R--; n         } n       } else { n         if (B == 0) { n           res++; n           pre =  r ; n           R++; n         } else { n           pre =  r ; n           B--; n         } n       } n     } n     printf( %d n , res < ans ? res : ans); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long mx = (1e5) + 1; n const long long mod = 1000000007; n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int a, b, x; n   cin >> a >> b >> x; n   if (x % 2 == 0) { n     if (a > b) { n       for (int i = 0; i < x / 2; i++) { n         cout <<  01 ; n       } n       cout << string(b - x / 2,  1 ); n       cout << string(a - x / 2,  0 ); n     } else { n       for (int i = 0; i < x / 2; i++) { n         cout <<  10 ; n       } n       cout << string(a - x / 2,  0 ); n       cout << string(b - x / 2,  1 ); n     } n   } else if (a > b) { n     for (int i = 0; i < x / 2; i++) { n       cout <<  01 ; n     } n     cout << string(a - x / 2,  0 ); n     cout << string(b - x / 2,  1 ); n   } else { n     for (int i = 0; i < x / 2; i++) { n       cout <<  10 ; n     } n     cout << string(b - x / 2,  1 ); n     cout << string(a - x / 2,  0 ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k, i, x, y, z, suma; n pair<int, pair<int, int> > r1, r2, tr0, v[35]; n map<pair<int, pair<int, int> >, pair<int, pair<int, int> > > mp; n pair<int, pair<int, int> > make_triplet(int x, int y, int z) { n   return make_pair(x, make_pair(y, z)); n } n int getSum(int bts) { n   int S = 0; n   int j = 0; n   for (j = 0; j < m; j++) n     if ((1 << j) & bts) S += v[j + 1].first; n   return S; n } n void bck1(int pas, int s1, int s2, int s3, int bt1, int bt2, int bt3) { n   if (pas > m) return; n   if (pas == m) { n     int minim = min(s1, min(s2, s3)); n     pair<int, pair<int, int> > sum = n         make_triplet(s1 - minim, s2 - minim, s3 - minim); n     pair<int, pair<int, int> > bt = make_triplet(bt1, bt2, bt3); n     int S = -((1 << 30) - 1 + (1 << 30)); n     if (mp.count(sum)) S = getSum(mp[sum].first); n     if (S < s1) mp[sum] = bt; n     return; n   } n   int i = pas + 1; n   bck1(pas + 1, s1 + v[i].first, s2 + v[i].second.first, s3, bt1 + (1 << pas), n        bt2 + (1 << pas), bt3); n   bck1(pas + 1, s1 + v[i].first, s2, s3 + v[i].second.second, bt1 + (1 << pas), n        bt2, bt3 + (1 << pas)); n   bck1(pas + 1, s1, s2 + v[i].second.first, s3 + v[i].second.second, bt1, n        bt2 + (1 << pas), bt3 + (1 << pas)); n } n void bck2(int pas, int s1, int s2, int s3, int bt1, int bt2, int bt3) { n   if (pas > k) return; n   if (pas == k) { n     int maxim = max(s1, max(s2, s3)); n     pair<int, pair<int, int> > sum = n         make_triplet(maxim - s1, maxim - s2, maxim - s3); n     if (mp.count(sum)) { n       pair<int, pair<int, int> > sum1 = mp[sum]; n       int S = getSum(sum1.first); n       if (S + s1 > suma) { n         suma = S + s1; n         r1 = sum1; n         r2 = make_triplet(bt1, bt2, bt3); n       } n     } n     return; n   } n   int i = pas + m + 1; n   bck2(pas + 1, s1 + v[i].first, s2 + v[i].second.first, s3, bt1 + (1 << pas), n        bt2 + (1 << pas), bt3); n   bck2(pas + 1, s1 + v[i].first, s2, s3 + v[i].second.second, bt1 + (1 << pas), n        bt2, bt3 + (1 << pas)); n   bck2(pas + 1, s1, s2 + v[i].second.first, s3 + v[i].second.second, bt1, n        bt2 + (1 << pas), bt3 + (1 << pas)); n } n int main() { n   scanf( %d , &n); n   for (i = 1; i <= n; i++) { n     scanf( %d%d%d , &x, &y, &z); n     v[i] = make_triplet(x, y, z); n   } n   m = (n + 1) / 2; n   bck1(0, 0, 0, 0, 0, 0, 0); n   k = n - m; n   suma = -((1 << 30) - 1 + (1 << 30)); n   bck2(0, 0, 0, 0, 0, 0, 0); n   if (r1.first || r1.second.first || r1.second.second) { n     for (i = 0; i < m; i++) { n       if ((1 << i) & r1.first) printf( L ); n       if ((1 << i) & r1.second.first) printf( M ); n       if ((1 << i) & r1.second.second) printf( W ); n       printf(  n ); n     } n     for (i = 0; i < k; i++) { n       if ((1 << i) & r2.first) printf( L ); n       if ((1 << i) & r2.second.first) printf( M ); n       if ((1 << i) & r2.second.second) printf( W ); n       printf(  n ); n     } n   } else n     printf( Impossible ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline void PAUSE() { n   char tmp; n   cin >> tmp; n } n int main() { n   int f1 = 0, f2 = 0, f3 = 0; n   char s[101]; n   cin >> s; n   int i = 0; n   while (s[i] !=   0 ) { n     if (s[i] -  0  >= 0 && s[i] -  0  <= 9) f1 = 1; n     if (s[i] >=  a  && s[i] <=  z ) f2 = 1; n     if (s[i] >=  A  && s[i] <=  Z ) f3 = 1; n     i++; n   } n   if (f1 && f2 && f3 && i >= 5) n     cout <<  Correct ; n   else n     cout <<  Too weak ; n   PAUSE(); n   return 0; n } n