#include <bits/stdc++.h> n using namespace std; n double inf = 1e+10; n double eps = 1e-10; n inline int sgn(const double& x) { return (x > +eps) - (x < -eps); } n const int MAXN = 500; n const int MAXM = 501; n int n, m; n double A[MAXM + 1][MAXN + 1]; n int basis[MAXM + 1], out[MAXN + 1]; n void pivot(int a, int b) { n   for (int i = 0; i <= m; ++i) n     if (i != a && sgn(A[i][b])) n       for (int j = 0; j <= n; ++j) n         if (j != b) A[i][j] -= A[a][j] * A[i][b] / A[a][b]; n   for (int i = 0; i <= m; ++i) n     if (i != a) A[i][b] /= -A[a][b]; n   for (int j = 0; j <= n; ++j) n     if (j != b) A[a][j] /= A[a][b]; n   A[a][b] = 1 / A[a][b]; n   swap(basis[a], out[b]); n } n double simplex() { n   for (int j = 0; j < n; ++j) A[0][j] = -A[0][j]; n   for (int i = 0; i <= m; ++i) basis[i] = -i; n   for (int j = 0; j <= n; ++j) out[j] = j; n   while (true) { n     int a = 1, b = 0; n     for (int i = 1; i <= m; ++i) n       if (make_pair(A[i][n], basis[i]) < make_pair(A[a][n], basis[a])) a = i; n     if (A[a][n] >= 0) break; n     for (int j = 0; j < n; ++j) n       if (A[a][j] < A[a][b]) b = j; n     if (A[a][b] >= 0) return -inf; n     pivot(a, b); n   } n   while (true) { n     int a = 1, b = 0; n     for (int j = 0; j < n; ++j) n       if (A[0][j] < A[0][b] || A[0][j] == A[0][b] && out[j] < out[b]) b = j; n     if (A[0][b] >= 0) break; n     for (int i = 1; i <= m; ++i) n       if (A[i][b] > 0 && n           (A[a][b] <= 0 || make_pair(A[i][n] / A[i][b], basis[i]) < n                                make_pair(A[a][n] / A[a][b], basis[a]))) n         a = i; n     if (A[a][b] <= 0) return +inf; n     pivot(a, b); n   } n   return A[0][n]; n } n int d; n vector<int> adj[500]; n vector<int> wei[500]; n void dfs(double A[], int u, int p, int d) { n   if (d >= 0) { n     A[u]--; n     for (int i = 0; i < ((int((adj[u]).size()))); ++i) { n       int v = adj[u][i]; n       if (v != p) { n         dfs(A, v, u, d - wei[u][i]); n       } n     } n   } n } n int main() { n   scanf( %d%d , &n, &d); n   int ttl = 0; n   for (int i = 0; i < (n); ++i) { n     int ti; n     scanf( %d , &ti), A[0][i] = ti - 1, ttl += ti; n   } n   for (int i = 0; i < (n - 1); ++i) { n     int u, v, w; n     scanf( %d%d%d , &u, &v, &w), --u, --v; n     adj[u].push_back(v), adj[v].push_back(u); n     wei[u].push_back(w), wei[v].push_back(w); n   } n   A[0][n] = 0; n   for (int i = 0; i < (n); ++i) { n     dfs(A[i + 1], i, -1, d); n     A[i + 1][n] = -1; n   } n   for (int i = 0; i < (n); ++i) A[n + 1][i] = 1; n   A[n + 1][n] = ttl; n   m = n + 1; n   double get = simplex(); n   int ans; n   if (get == -inf) n     ans = -1; n   else n     ans = -get + 0.5; n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3e5 + 5; n const char choice[6][2] = {{ A ,  C }, { A ,  G }, { A ,  T }, n                            { C ,  G }, { C ,  T }, { G ,  T }}; n int n, m; n string str[maxn]; n int ord[2][maxn][6], cnt[2][maxn]; n string out[maxn]; n void print(int rc, int k) { n   for (int i = 0; i < n; i++) out[i] =   ; n   if (rc == 0) { n     for (int i = 0; i < n; i++) n       for (int j = 0; j < m; j++) n         out[i] += choice[(i & 1) ? 5 - k : k][(j & 1) ^ ord[0][i][k]]; n   } else { n     for (int j = 0; j < m; j++) n       for (int i = 0; i < n; i++) n         out[i] += choice[(j & 1) ? 5 - k : k][(i & 1) ^ ord[1][j][k]]; n   } n   for (int i = 0; i < n; i++) cout << out[i] << endl; n } n int main() { n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> str[i]; n   memset(cnt, 0, sizeof(cnt)); n   for (int i = 0; i < n; i++) { n     for (int k = 0; k < 6; k++) { n       int now1 = 0, now2 = 0; n       for (int j = 0; j < m; j++) { n         now1 += (str[i][j] != choice[(i & 1) ? 5 - k : k][j & 1]); n         now2 += (str[i][j] != choice[(i & 1) ? 5 - k : k][(j & 1) ^ 1]); n       } n       ord[0][i][k] = now1 < now2 ? 0 : 1; n       cnt[0][k] += min(now1, now2); n     } n   } n   for (int j = 0; j < m; j++) { n     for (int k = 0; k < 6; k++) { n       int now1 = 0, now2 = 0; n       for (int i = 0; i < n; i++) { n         now1 += (str[i][j] != choice[(j & 1) ? 5 - k : k][i & 1]); n         now2 += (str[i][j] != choice[(j & 1) ? 5 - k : k][(i & 1) ^ 1]); n       } n       ord[1][j][k] = now1 < now2 ? 0 : 1; n       cnt[1][k] += min(now1, now2); n     } n   } n   int ans = 0x3f3f3f3f, RC, K; n   for (int rc = 0; rc <= 1; rc++) { n     for (int k = 0; k < 6; k++) { n       if (cnt[rc][k] < ans) ans = cnt[rc][k], RC = rc, K = k; n     } n   } n   print(RC, K); n } n


#include <bits/stdc++.h> n using namespace std; n int n; n vector<vector<int>> adj; n vector<long long> d; n vector<bool> visited; n bitset<5000> sol; n void dfs(int m) { n   bitset<5000> tmp; n   d[m] = 1; n   tmp[0] = 1; n   for (auto l : adj[m]) { n     if (!visited[l]) { n       visited[l] = 1; n       dfs(l); n       d[m] += d[l]; n       tmp |= (tmp << d[l]); n     } n   } n   tmp |= (tmp << (n - d[m])); n   sol |= tmp; n } n int main(int argc, const char* argv[]) { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int a, b; n   cin >> n; n   adj = vector<vector<int>>(n + 2); n   d = vector<long long>(n + 1); n   visited = vector<bool>(n + 1, false); n   int p = n; n   while (--n) { n     cin >> a >> b; n     adj[a].push_back(b); n     adj[b].push_back(a); n   } n   n = p; n   visited[a] = 1; n   dfs(a); n   int counter = 0; n   for (int i = 1; i < n - 1; i++) { n     if (sol[i]) { n       counter++; n     } n   } n   cout << counter <<   n ; n   for (int i = 1; i < n - 1; i++) { n     if (sol[i]) { n       cout << i <<     << n - i - 1 <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mx = 1e6 + 50; n bool tot[10000050]; n vector<int> prime; n void seive() { n   for (int i = 2; i * i <= mx; i++) { n     if (!tot[i]) { n       for (int j = (2 * i); j <= mx; j += i) { n         tot[j] = true; n       } n     } n   } n   for (int i = 2; i <= mx; i++) { n     if (!tot[i]) { n       prime.push_back(i); n     } n   } n } n vector<int> g[mx]; n map<int, bool> mp; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n, m; n   seive(); n   cin >> n >> m; n   long long int sum = 0; n   for (int i = 1; i < n - 1; i++) { n     sum += 2; n   } n   int p = upper_bound(prime.begin(), prime.end(), sum) - prime.begin(); n   int x = prime[p] - sum; n   cout << 2 <<     << prime[p] << endl; n   cout << 1 <<     << n <<     << 2 << endl; n   for (int i = 2; i <= n - 1; i++) { n     cout << 1 <<     << i <<     << ((i == 2) ? x : 2) << endl; n   } n   m -= n - 1; n   long long int tot = (int)1e6 + 10; n   int j = 2; n   mp[1] = true; n   int t = 3; n   int f = 0; n   for (int i = 2; i < n; i++) { n     for (int j = i + 1; j <= n; j++) { n       if (f == m) { n         return 0; n       } n       f++; n       cout << i <<     << j <<     << (++tot) << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1}; n const int dc[] = {0, 1, 0, -1, 1, -1, -1, 1}; n const double eps = 1e-9; n const int INF = 0x7FFFFFFF; n const long long INFLL = 0x7FFFFFFFFFFFFFFFLL; n const double pi = acos(-1); n template <class T> n T take(queue<T> &O) { n   T tmp = O.front(); n   O.pop(); n   return tmp; n } n template <class T> n T take(stack<T> &O) { n   T tmp = O.top(); n   O.pop(); n   return tmp; n } n template <class T> n T take(priority_queue<T> &O) { n   T tmp = O.top(); n   O.pop(); n   return tmp; n } n template <class T> n inline void getint(T &num) { n   bool neg = 0; n   num = 0; n   char c; n   while ((c = getchar_unlocked()) && (!isdigit(c) && c !=  - )) n     ; n   if (c ==  - ) { n     neg = 1; n     c = getchar_unlocked(); n   } n   do num = num * 10 + c -  0 ; n   while ((c = getchar_unlocked()) && isdigit(c)); n   num *= (neg) ? -1 : 1; n } n template <class T> n inline bool inRange(T z, T a, T b) { n   return a <= z && z <= b; n } n void OPEN(string in =  input.txt , string out =  output.txt ) { n   freopen(in.c_str(),  r , stdin); n   freopen(out.c_str(),  w , stdout); n   return; n } n int n; n int main(int argc, const char *argv[]) { n   cin >> n; n   if (n < 4) n     cout <<  NO n ; n   else { n     cout <<  YES n ; n     int cnt = 0, nao; n     if (n & 1) { n       cnt = n - 5, nao = 6; n       for (int(i) = (0), _t = (cnt / 2); i < (_t); ++(i)) { n         cout << nao + 1 <<   -   << nao <<   = 1 n ; n         nao += 2; n       } n       cout <<  4 + 1 = 5 n  n                5 * 5 = 25 n  n                3 - 2 = 1 n  n                25 - 1 = 24 n ; n       for (int(i) = (0), _t = (cnt / 2); i < (_t); ++(i)) n         cout <<  24 * 1 = 24 n ; n     } else { n       cout <<  1 * 2 = 2 n  n                2 * 3 = 6 n  n                6 * 4 = 24 n ; n       cnt = n - 4, nao = 5; n       for (int(i) = (0), _t = (cnt / 2); i < (_t); ++(i)) { n         cout << nao + 1 <<   -   << nao <<   = 1 n ; n         nao += 2; n       } n       for (int(i) = (0), _t = (cnt / 2); i < (_t); ++(i)) n         cout <<  24 * 1 = 24 n ; n     } n   } 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   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     cin.sync(); n     string s; n     cin >> s; n     stack<char> ss; n     for (int i = 0; i < s.size(); i++) { n       if (s[i] ==  ( ) ss.push(s[i]); n       if (!ss.empty()) { n         if (s[i] ==  ) ) { n           if (ss.top() ==  ( ) { n             ss.pop(); n           } n         } n       } n     } n     cout << ss.size() << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dx[8] = {1, -1, 0, 0, 1, -1, 1, -1}; n int dy[8] = {0, 0, -1, 1, 1, -1, -1, 1}; n int n, k, f; n vector<int> v; n int main(void) { n   scanf( %d%d , &n, &k); n   for (int i = 0; i < n; i++) { n     scanf( %d , &f); n     v.push_back(f); n   } n   long long ans = 0; n   sort(v.rbegin(), v.rend()); n   int to = 0; n   for (int i = 0; i < v.size(); i++) { n     to++; n     if (to == k || i + 1 == v.size()) { n       ans += 2 * (v[i - to + 1] - 1); n       to = 0; n     } n   } n   cout << ans << endl; 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(NULL); n   long long int n, n1, n2, c, b; n   cin >> n >> n1 >> n2; n   c = n1; n   b = n2; n   long double sum = 0, sum1 = 0; n   long long int a[n]; n   for (int i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   if (n1 >= n2) { n     long long int i = 0; n     while (b > 0) { n       sum += a[n - i - 1]; n       i++; n       b--; n     } n     sum = sum / n2; n     while (c > 0) { n       sum1 += a[n - i - 1]; n       i++; n       c--; n     } n     sum1 = sum1 / n1; n     cout << fixed << setprecision(8) << sum + sum1 << endl; n   } else { n     long long int i = 0; n     while (c > 0) { n       sum += a[n - i - 1]; n       i++; n       c--; n     } n     sum = sum / n1; n     while (b > 0) { n       sum1 += a[n - i - 1]; n       i++; n       b--; n     } n     sum1 = sum1 / n2; n     cout << fixed << setprecision(8) << sum + sum1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1000001; n int n, t; n int p[MAXN], s[MAXN]; n stack<int> st; n int main() { n   scanf( %d n , &n); n   for (int i = 1; i <= n; ++i) scanf( %d , &p[i]); n   scanf( %d , &t); n   for (int i = 1; i <= t; ++i) { n     int x; n     scanf( %d , &x); n     p[x] = -p[x]; n   } n   for (int i = n; i >= 1; --i) n     if (p[i] < 0) n       st.push(-p[i]); n     else { n       if (!st.empty() && st.top() == p[i]) { n         st.pop(); n       } else n         p[i] = -p[i], st.push(-p[i]); n     } n   if (st.empty()) { n     printf( YES n ); n     for (int i = 1; i <= n; ++i) printf( %d%s , p[i], (i < n) ?     :   n ); n   } else n     printf( NO n ); n   fclose(stdin); n   fclose(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1000000 + 10; n long long a[MAXN]; n long long b[MAXN]; n void add(long long k, long long val, int start, int end) { n   if (start > end) return; n   a[start] += k; n   a[end + 1] -= k; n   long long bias = val - start * k; n   b[start] += bias; n   b[end + 1] -= bias; n } n int main() { n   int n, num; n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &num); n     if (num >= i) { n       add(-1, num - i, 0, num - i); n       add(1, 1, num - i + 1, n - i); n       add(-1, num - 1, n - i + 1, n - 1); n     } else { n       add(1, i - num, 0, n - i); n       add(-1, num - 1, n - i + 1, n + num - i); n       add(1, 1, n + num - i + 1, n - 1); n     } n   } n   int pos = 0; n   long long val = b[0]; n   for (int i = 1; i < n; i++) { n     a[i] += a[i - 1]; n     b[i] += b[i - 1]; n     if (a[i] * i + b[i] < val) { n       val = a[i] * i + b[i]; n       pos = i; n     } n   } n   cout << val <<     << pos << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double r, L; n double b, u, A; n double x, y, a; n double D[95], B[95]; n struct st { n   double x, y, a; n }; n st bear[50]; n int t; n double fun(int i, double l) { n   x = bear[i].x; n   y = bear[i].y; n   t = bear[i].a; n   a = B[t]; n   b = (fabs(l - x) / y); n   A = D[t]; n   if (x < l) n     u = ((A + b) / (1 - A * b)) * y - l + x; n   else { n     if (a < b) n       u = x - l - ((b - A) / (1 + b * A)) * y; n     else n       u = ((A - b) / (1 + A * b)) * y + x - l; n   } n   if (u < 0) return 1e9; n   return u; n } n const int N = (1 << 20) + 10; n double d[N][22]; n int main() { n   for (int i = 1; i <= 90; i++) { n     B[i] = i * acosl(-1) / 180; n     D[i] = tan(B[i]); n   } n   double l; n   int n; n   cin >> n >> l >> r; n   L = l; n   for (int i = 0; i < n; i++) cin >> bear[i].x >> bear[i].y >> bear[i].a; n   int m = (1 << n) - 1, i, j, k; n   double ans = -1e9; n   for (i = 1; i <= m; i++) { n     for (j = 0; j < n; j++) { n       if (((1 << j) & i)) { n         d[i][j] = -1e9; n         if ((1 << j) == i) { n           d[i][j] = l + fun(j, l); n           ans = max(ans, d[i][j]); n         } else { n           for (k = 0; k < n; k++) { n             if (((1 << k) & i) && j != k) { n               d[i][j] = n                   max(d[i][j], d[i ^ (1 << j)][k] + fun(j, d[i ^ (1 << j)][k])); n               ans = max(ans, d[i][j]); n             } n           } n         } n       } n     } n   } n   printf( %.6f , min(ans - L, r - L)); n } n


#include <bits/stdc++.h> n using namespace std; n const double PI{3.1415926535897932384626433832795}; n const int MOD{static_cast<int>(1e9 + 7)}; n const double EPS{1e-9}; n template <typename T> n T ModAdd(const T &a, const T &b, const int &mod = MOD) { n   return ((a) % mod + (a) % mod) % mod; n } n template <typename T> n T ModSub(const T &a, const T &b, const int &mod = MOD) { n   return ((((a % mod) - (b % mod)) % mod) + mod) % mod; n } n template <typename T> n T ModMul(const T &a, const T &b, const int &mod = MOD) { n   return ((a % mod) * (b % mod)) % mod; n } n template <typename T> n bool AdditionLimitFlow(const T &a, const T &x) { n   T MAXIMUM_INT{a}, MINIMUM_INT{a}; n   switch (sizeof(a)) { n     case 8: n       MAXIMUM_INT = LLONG_MAX; n       MINIMUM_INT = LLONG_MIN; n       break; n     case 4: n       MAXIMUM_INT = INT_MAX; n       MINIMUM_INT = INT_MIN; n       break; n     default: n       cerr <<  PARAMETER SHOULD BE EITHER int OR long long !!  << endl; n       assert(0); n       break; n   } n   bool overflow{false}, underflow{false}; n   if ((x > 0) && (a > MAXIMUM_INT - x)) overflow = true; n   if ((x < 0) && (a < MINIMUM_INT - x)) underflow = true; n   if (overflow) { n     cerr <<  OVERFLOW: [  << a <<  ,   << x <<  ]  << endl; n     return overflow; n   } n   if (underflow) { n     cerr <<  UNDERFLOW: [  << a <<  ,   << x <<  ]  << endl; n     return underflow; n   } n   return false; n } n template <typename T> n bool SubstractionLimitFlow(const T &a, const T &x) { n   T MAXIMUM_INT{}, MINIMUM_INT{}; n   switch (sizeof(a)) { n     case 8: n       MAXIMUM_INT = LLONG_MAX; n       MINIMUM_INT = LLONG_MIN; n       break; n     case 4: n       MAXIMUM_INT = INT_MAX; n       MINIMUM_INT = INT_MIN; n       break; n     default: n       cerr <<  PARAMETER SHOULD BE EITHER int OR long long !!  << endl; n       assert(0); n       break; n   } n   bool overflow{false}, underflow{false}; n   if ((x < 0) && (a > MAXIMUM_INT + x)) overflow = true; n   if ((x > 0) && (a < MINIMUM_INT + x)) underflow = true; n   if (overflow) { n     cerr <<  OVERFLOW: [  << a <<  ,   << x <<  ]  << endl; n     return overflow; n   } n   if (underflow) { n     cerr <<  UNDERFLOW: [  << a <<  ,   << x <<  ]  << endl; n     return underflow; n   } n   return false; n } n template <typename T> n bool MultiplicationLimitFlow(const T &a, const T &x) { n   T MAXIMUM_INT{}, MINIMUM_INT{}; n   switch (sizeof(a)) { n     case 8: n       MAXIMUM_INT = LLONG_MAX; n       MINIMUM_INT = LLONG_MIN; n       break; n     case 4: n       MAXIMUM_INT = INT_MAX; n       MINIMUM_INT = INT_MIN; n       break; n     default: n       cerr <<  PARAMETER SHOULD BE EITHER int OR long long !!  << endl; n       assert(0); n       break; n   } n   bool overflow{false}, underflow{false}; n   if ((a == -1) && (x == MINIMUM_INT)) overflow = true; n   if ((x == -1) && (a == MINIMUM_INT)) overflow = true; n   if (a > MAXIMUM_INT / x) overflow = true; n   if (a < MINIMUM_INT / x) underflow = true; n   if (overflow) { n     cerr <<  OVERFLOW: [  << a <<  ,   << x <<  ]  << endl; n     return overflow; n   } n   if (underflow) { n     cerr <<  UNDERFLOW: [  << a <<  ,   << x <<  ]  << endl; n     return underflow; n   } n   return false; n } n template <typename T, size_t N> n istream &operator>>(istream &is, array<T, N> &ARR) { n   for (T &a : ARR) is >> a; n   return is; n } n template <typename T, size_t N> n ostream &operator<<(ostream &os, array<T, N> &ARR) { n   for (T const &a : ARR) os << a <<    ; n   return os; n } n template <typename T> n istream &operator>>(istream &is, vector<T> &VEC) { n   for (T &v : VEC) is >> v; n   return is; n } n template <typename T> n ostream &operator<<(ostream &os, const vector<T> &VEC) { n   for (T const &v : VEC) os << v <<    ; n   return os; n } n template <typename T> n istream &operator>>(istream &is, deque<T> &DEQ) { n   for (T &d : DEQ) is >> d; n   return is; n } n template <typename T> n ostream &operator<<(ostream &os, const deque<T> &DEQ) { n   for (const T &d : DEQ) os << d <<    ; n   return os; n } n template <typename T> n istream &operator>>(istream &is, list<T> &LIS) { n   for (T &l : LIS) is >> l; n   return is; n } n template <typename T> n ostream &operator<<(ostream &os, const list<T> &LIS) { n   for (T const &l : LIS) os << l <<    ; n   return os; n } n template <typename T> n ostream &operator<<(ostream &os, const set<T> &ST) { n   for (auto const &s : ST) os << s <<    ; n   return os; n } n template <typename T> n ostream &operator<<(ostream &os, const unordered_set<T> &U_ST) { n   for (T const &us : U_ST) os << us <<    ; n   return os; n } n template <typename T1, typename T2> n istream &operator>>(istream &is, pair<T1, T2> &PR) { n   is >> PR.first >> PR.second; n   return is; n } n template <typename T1, typename T2> n ostream &operator<<(ostream &os, const pair<T1, T2> &PR) { n   os <<  [  << PR.first <<  :   << PR.second <<  ] ; n   return os; n } n template <typename T1, typename T2> n ostream &operator<<(ostream &os, const map<T1, T2> &MP) { n   os <<  [  ; n   for (pair<T1, T2> const &m : MP) os << m <<    ; n   os <<  ] ; n   return os; n } n template <typename T1, typename T2> n ostream &operator<<(ostream &os, const unordered_map<T1, T2> &U_MP) { n   os <<  [  ; n   for (pair<T1, T2> const &um : U_MP) os << um <<    ; n   os <<  ] ; n   return os; n } n template <typename T> n ostream &operator<<(ostream &os, stack<T> STACK) { n   while (!STACK.empty()) { n     os << STACK.top() <<    ; n     STACK.pop(); n   } n   return os; n } n template <typename T> n ostream &operator<<(ostream &os, queue<T> QUEUE) { n   while (!QUEUE.empty()) { n     os << QUEUE.front() <<    ; n     QUEUE.pop(); n   } n   return os; n } n template <typename T, size_t R, size_t C> n ostream &operator<<(ostream &os, array<array<T, C>, R> &MAT) { n   for (array<T, C> &ROW : MAT) os << ROW << endl; n   return os; n } n template <typename T> n ostream &operator<<(ostream &os, vector<vector<T>> &MAT) { n   for (vector<T> &ROW : MAT) os << ROW << endl; n   return os; n } n template <typename T> n T max(const T &A, const T &B, const T &C) { n   T mx{A}; n   (mx < B) && (mx = B); n   (mx < C) && (mx = C); n   return mx; n } n template <typename T> n T min(const T &A, const T &B, const T &C) { n   T mn{A}; n   (mn > B) && (mn = B); n   (mn > C) && (mn = C); n   return mn; n } n template <typename T> n int cntDigits(const T &N) { n   return (static_cast<int>(log10(N)) + 1); n } n template <typename T> n bool isPowOfTwo(const T &N) { n   return (N && (!(N & (N - 1)))); n } n template <typename T> n bool dblEqual(const T &a, const T &b) { n   return abs(a - b) < EPS; n } n void TEST_CASES() { n   int n{}; n   cin >> n; n   string s{}; n   cin >> s; n   vector<int> jump(n); n   for (auto &val : jump) cin >> val; n   vector<bool> reached(n); n   string res{ FINITE }; n   int ind{}; n   while (ind >= 0 && ind < n) { n     if (!reached.at(ind)) { n       reached.at(ind) = true; n       if (s.at(ind) ==  < ) n         ind -= jump.at(ind); n       else n         ind += jump.at(ind); n     } else { n       res =  IN  + res; n       break; n     } n   } n   cout << res << endl; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cerr.setf(std::ios::boolalpha); n   cout << std::fixed; n   cout << std::setprecision(6); n   unsigned TT{1}; n   while (TT--) { n     TEST_CASES(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 5100; n long long n, s, t, x[N], a[N], b[N], c[N], d[N], w[N]; n long long dp[N][N]; n inline void print(long long a[]) { n   for (long long i = 1; i <= n; i++) printf( %lld  , a[i]); n   printf(  n ); n } n inline long long read() { n   long long f = 1, x = 0; n   char s = getchar(); n   while (s <  0  || s >  9 ) { n     if (s ==  - ) f = -1; n     s = getchar(); n   } n   while (s >=  0  && s <=  9 ) { n     x = x * 10 + s -  0 ; n     s = getchar(); n   } n   return x * f; n } n signed main() { n   n = read(); n   s = read(); n   t = read(); n   for (long long i = 1; i <= n; i++) x[i] = read(); n   for (long long i = 1; i <= n; i++) a[i] = read() + x[i]; n   for (long long i = 1; i <= n; i++) b[i] = read() - x[i]; n   for (long long i = 1; i <= n; i++) c[i] = read() + x[i]; n   for (long long i = 1; i <= n; i++) d[i] = read() - x[i]; n   long long x = 0, y = 0; n   for (long long i = 0; i <= n; i++) n     for (long long j = 0; j <= n; j++) dp[i][j] = 1e18; n   if (s == 1) n     dp[1][1] = d[1], x--; n   else if (t == 1) n     dp[1][1] = b[1], y--; n   else n     dp[1][1] = b[1] + d[1]; n   for (long long i = 2; i < n; i++) { n     if (i == s) { n       for (long long j = 1; j <= i; j++) { n         if (j > 1) dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + d[i]); n         dp[i][j] = min(dp[i][j], dp[i - 1][j] + c[i]); n       } n       x--; n       continue; n     } n     if (i == t) { n       for (long long j = 1; j <= i; j++) { n         if (j > 1) dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + b[i]); n         dp[i][j] = min(dp[i][j], dp[i - 1][j] + a[i]); n       } n       y--; n       continue; n     } n     for (long long j = 1 + (i > s && i > t); j <= i; j++) { n       long long in = j + x, out = j + y; n       if (j > 1 || out) dp[i][j] = min(dp[i][j], dp[i - 1][j] + a[i] + d[i]); n       if (j > 1 || in) dp[i][j] = min(dp[i][j], dp[i - 1][j] + c[i] + b[i]); n       dp[i][j + 1] = min(dp[i][j + 1], dp[i - 1][j] + b[i] + d[i]); n       if (j > 1) dp[i][j - 1] = min(dp[i][j - 1], dp[i - 1][j] + a[i] + c[i]); n     } n   } n   long long ans = 1e18; n   if (s == n) n     ans = min(ans, dp[n - 1][1] + c[n]); n   else if (t == n) n     ans = min(ans, dp[n - 1][1] + a[n]); n   else n     ans = min(ans, dp[n - 1][2] + a[n] + c[n]); n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k[101], m, mi = 1000000; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> k[i]; n   for (int i = 0; i < n; i++) { n     int c = 0, s = 0; n     for (int j = 0; j < k[i]; j++) { n       cin >> m; n       s += m * 5; n       c++; n     } n     s += c * 15; n     mi = min(s, mi); n   } n   cout << mi; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long p = 131; n const int N = 210000; n int n, m; n char sr1[N], sr2[N]; n unsigned long long hash1[N][28], hash2[N][28], Q[N]; n int Ans[N], ans; n int main() { n   int i, j, k, x, y; n   cin >> n >> m; n   scanf( %s%s , sr1 + 1, sr2 + 1); n   Q[0] = 1; n   for (i = 1; i <= n; ++i) Q[i] = Q[i - 1] * p; n   for (j = 0; j <= 25; ++j) n     for (i = 1; i <= n; ++i) { n       hash1[i][j] = hash1[i - 1][j] * p; n       if (sr1[i] -  a  == j) hash1[i][j] += 1; n     } n   for (j = 0; j <= 25; ++j) n     for (i = 1; i <= m; ++i) { n       hash2[i][j] = hash2[i - 1][j] * p; n       if (sr2[i] -  a  == j) hash2[i][j] += 1; n     } n   int cnt; n   for (i = 1; i <= n - m + 1; ++i) { n     cnt = 0; n     for (x = 0; x < 26; ++x) { n       if (cnt != x) break; n       for (y = 0; y < 26; ++y) n         if (hash2[m][x] == hash1[i + m - 1][y] - hash1[i - 1][y] * Q[m]) n           if (hash2[m][y] == hash1[i + m - 1][x] - hash1[i - 1][x] * Q[m]) { n             cnt++; n             break; n           } n     } n     if (cnt == 26) Ans[++ans] = i; n   } n   cout << ans << endl; n   for (i = 1; i < ans; ++i) printf( %d  , Ans[i]); n   if (ans != 0) printf( %d , Ans[ans]); n } n


#include <bits/stdc++.h> n using namespace std; n int n, f; n long long ans; n long long k, l; n long long d[100001]; n int main() { n   cin >> n >> f; n   for (int i = 1; i <= n; i++) { n     cin >> k >> l; n     d[i] = -min(k, l - k); n     ans = ans + min(k, l); n   } n   sort(d + 1, d + n + 1); n   for (int i = 1; i <= f; i++) ans = ans + max(-d[i], (long long)(0)); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<char, int> M; n char t[7] = { B ,  u ,  l ,  b ,  a ,  s ,  r }; n int num[7] = {1, 2, 1, 1, 2, 1, 1}; n char ch[200020]; n int main() { n   scanf( %s , ch); n   int n = strlen(ch); n   for (int i = 0; i < n; i++) M[ch[i]]++; n   int ans = 1 << 30; n   for (int i = 0; i < 7; i++) ans = min(ans, M[t[i]] / num[i]); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class X, class Y> n void amax(X& x, const Y& y) { n   if (x < y) x = y; n } n template <class X, class Y> n void amin(X& x, const Y& y) { n   if (x > y) x = y; n } n const int INF = 1e9 + 10; n const long long INFL = 1e18 + 10; n const int MAX = 1e6 + 10; n int n; n int a[MAX], prv[MAX], pos[MAX]; n long long gt[MAX * 4], lazy[MAX * 4]; n void update(int id, int l, int r, int u, int v) { n   if (v < l || u > r) return; n   if (u <= l && r <= v) { n     lazy[id]++; n     gt[id] += (r - l + 1); n     return; n   } n   int mid = (l + r) / 2; n   update(id * 2, l, mid, u, v); n   update(id * 2 + 1, mid + 1, r, u, v); n   gt[id] = gt[id * 2] + gt[id * 2 + 1] + lazy[id] * (r - l + 1); n } n long long query(int id, int l, int r, int u, int v) { n   if (v < l || u > r) return 0; n   if (u <= l && r <= v) return gt[id]; n   int mid = (l + r) / 2; n   return query(id * 2, l, mid, u, v) + query(id * 2 + 1, mid + 1, r, u, v) + n          lazy[id] * (min(r, v) - max(u, l) + 1); n } n void process() { n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= n; i++) { n     prv[i] = pos[a[i]]; n     pos[a[i]] = i; n   } n   long double sum = 0; n   long double choose = (long long)n * n; n   for (int i = 1; i <= n; i++) { n     update(1, 1, n, prv[i] + 1, i); n     sum = sum + (query(1, 1, n, 1, i) * 2 - 1) / choose; n   } n   cout << fixed << setprecision(10) << sum <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   process(); n } n


#include <iostream> n #include <vector> n using namespace std; n int t,k,n,m; n vector<int> a,b,v; n int main() { n     ios_base::sync_with_stdio(false); n     cin.tie(nullptr); n     cin>>t; n     while (t--) { n         cin>>k>>n>>m; n         a.resize(n); n         b.resize(m); n         for (int &x:a) cin>>x; n         for (int &x:b) cin>>x; n         auto solve=[&]()->vector<int> { n             vector<int> sequences; n             int l=0,r=0,cur=k; n             while (true) { n                 if (l==n && r==m) break; n                 if (l!=n && a[l]>=0 && a[l]<=cur) { n                     if (a[l]==0) cur++; n                     sequences.emplace_back(a[l++]); n                 } n                 else if (r!=m && b[r]>=0 && b[r]<=cur) { n                     if (b[r]==0) cur++; n                     sequences.emplace_back(b[r++]); n                 } n                 else return vector<int> {-1}; n             } n             return sequences; n         }; n         v=solve(); n         for (int i=0;i<(int)v.size();i++) cout<<v[i]<<   n [i==(int)v.size()-1]; n     } n }


#include <bits/stdc++.h> n int main() { n   int n, i, a[100001]; n   scanf( %d , &n); n   for (i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (i = 1; i <= n; i++) n     while (a[i] % 2 == 0) a[i] /= 2; n   for (i = 1; i <= n; i++) n     while (a[i] % 3 == 0) a[i] /= 3; n   for (i = 1; i <= n - 1; i++) n     if (a[i] != a[i + 1]) { n       printf( NO ); n       return 0; n     } n   printf( YES ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct data { n   int u, v, w; n } p[400500]; n int father[200100]; n int use[200100]; n int coo(struct data a, struct data b) { n   if (a.w > b.w) return 1; n   return 0; n } n int find(int x) { return x == father[x] ? x : father[x] = find(father[x]); } n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 1; i <= n; i++) father[i] = i; n   for (int i = 1; i <= m; i++) { n     scanf( %d%d%d , &p[i].u, &p[i].v, &p[i].w); n   } n   sort(p + 1, p + m + 1, coo); n   long long ans = 0; n   for (int i = 1; i <= m; i++) { n     int x = find(p[i].u), y = find(p[i].v); n     if (use[x] && use[y]) continue; n     if (x == y) n       use[x] = 1; n     else { n       father[x] = y; n       use[y] |= use[x]; n     } n     ans += p[i].w; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, K; n int A[202020]; n string S; n void solve() { n   int i, j, k, l, r, x, y; n   string s; n   cin >> N >> K; n   for (i = 0; i < (N); i++) cin >> A[i]; n   cin >> S; n   signed long long ret = 0; n   for (i = 0; i < N;) { n     j = i; n     vector<int> V; n     while (j < N && S[i] == S[j]) { n       V.push_back(A[j]); n       j++; n     } n     i = j; n     sort((V.begin()), (V.end())); n     reverse((V.begin()), (V.end())); n     for (j = 0; j < (min(K, (int)V.size())); j++) ret += V[j]; n   } n   cout << ret << endl; n } n int main(int argc, char** argv) { n   string s; n   int i; n   if (argc == 1) ios::sync_with_stdio(false), cin.tie(0); n   for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s +=   n ; n   for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin); n   cout.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int a[500005], b[500005], reach[500005][19]; n int tree[4 * 500005][19]; n void build(int i, int layer, int low, int high) { n   if (low == high) { n     tree[i][layer] = reach[low][layer]; n     return; n   } n   int mid = (low + high) / 2; n   build(2 * i, layer, low, mid); n   build(2 * i + 1, layer, mid + 1, high); n   tree[i][layer] = min(tree[2 * i][layer], tree[2 * i + 1][layer]); n } n int get(int i, int layer, int low, int high, int u, int v) { n   if (v < low || high < u) return 500005; n   if (u <= low && high <= v) return tree[i][layer]; n   int mid = (low + high) / 2; n   return min(get(2 * i, layer, low, mid, u, v), n              get(2 * i + 1, layer, mid + 1, high, u, v)); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     a[i + n] = a[i]; n   } n   m = 2 * n - 1; n   for (int i = 1; i <= m; i++) { n     b[i] = i - a[i]; n     reach[i][0] = max(1, b[i]); n   } n   build(1, 0, 1, m); n   for (int j = 1; j < 19; j++) { n     for (int i = 1; i <= m; i++) n       reach[i][j] = get(1, j - 1, 1, m, reach[i][j - 1], i); n     build(1, j, 1, m); n   } n   long long ret = 0; n   for (int end = n; end <= m; end++) { n     int moves = 0; n     int prev = end; n     for (int j = 19 - 1; j >= 0; j--) { n       int tmp = get(1, j, 1, m, prev, end); n       if (tmp > end - n + 1) { n         moves += 1 << j; n         prev = tmp; n       } n     } n     moves++; n     ret += moves; n   } n   cout << ret << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int mul(long long int a) { n   int mi = 10, ma = 0; n   while (a != 0) { n     int d = a % 10; n     mi = min(mi, d); n     ma = max(ma, d); n     a /= 10; n   } n   return mi * ma; n } n int main() { n   int t = 0; n   cin >> t; n   while (t--) { n     long long int n, k; n     cin >> n >> k; n     k--; n     while (k--) { n       int mult = mul(n); n       if (mult == 0) { n         break; n       } n       n += mult; n     } n     std::cout << n << std::endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:640000000 ) n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int a, b; n   cin >> a >> b; n   for (int _n((a)-1), i(0); i <= _n; ++i) cout << i + 1 <<    ; n   for (int i = (a + b + 1), _b = (a + 1); i >= _b; --i) cout << i <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> prime_Numbers; n bool primes[1000005]; n void prime(int n) { n   for (int i = 2; i <= n; i++) primes[i] = true; n   for (int i = 2; i <= n; i++) { n     if (primes[i] == true) { n       prime_Numbers.push_back(i); n       for (int j = i + i; j <= n; j += i) primes[j] = false; n     } n   } n } n int fib(int n) { n   if (n == 1 || n == 0) return n; n   return fib(n - 1) + fib(n - 2); n } n long long fastpower(int b, int p) { n   if (p == 0) return 1; n   long long term = fastpower(b, p / 2); n   term *= term; n   if (p % 2 != 0) return term *= b; n   return term; n } n long long arr[3005]; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n, k, d; n     cin >> n >> k >> d; n     int arr[n + 2]; n     set<int> st; n     map<int, int> mp; n     for (int i = 0; i < n; i++) { n       cin >> arr[i]; n     } n     for (int i = 0; i < d; i++) { n       st.insert(arr[i]); n       mp[arr[i]]++; n     } n     int mnm = st.size(); n     for (int i = d; i < n; i++) { n       mp[arr[i - d]]--; n       if (mp[arr[i - d]] == 0) st.erase(arr[i - d]); n       st.insert(arr[i]); n       mp[arr[i]]++; n       mnm = min(mnm, (int)st.size()); n     } n     cout << min(mnm, (int)st.size()) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n long long int add(long long int a, long long int b) { n   return a + b - (a + b >= 1000000007) * 1000000007; n } n long long int sub(long long int a, long long int b) { n   return a - b + (a - b < 0) * 1000000007; n } n long long int mult(long long int a, long long int b) { n   return (1LL * a * b) % 1000000007; n } n inline long long int gcd(long long int a, long long int b) { n   long long int t; n   while (b) { n     a = a % b; n     t = a; n     a = b; n     b = t; n   } n   return a; n } n long long int powmod(long long int a, long long int b) { n   long long int res = 1; n   a %= 1000000007; n   assert(b >= 0); n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % 1000000007; n     a = a * a % 1000000007; n   } n   return res; n } n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long int k; n   cin >> k; n   long long int q = (1000000007 - 1) / 2; n   long long int d = 2; n   for (long long int i = 0; i < k; i++) { n     long long int x; n     cin >> x; n     q = powmod(q, x); n     d = powmod(d, x); n   } n   d = d * powmod(2, 1000000007 - 2) % 1000000007; n   q = (q * 2 + 1) % 1000000007 * powmod(3, 1000000007 - 2) % 1000000007; n   long long int p = q * d % 1000000007; n   cout << p <<  /  << d; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e9 + 5; n const long long N = 205; n void solve(); n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   cout << fixed << setprecision(10); n   long long _ = 1; n   while (_--) solve(); n   return 0; n } n void solve() { n   string s; n   cin >> s; n   long long n = s.size(); n   long long ans = LLONG_MAX; n   for (long long loop = 0; loop < 26; loop++) { n     char ch =  a  + loop; n     long long cnt = 0, temp = 0; n     for (long long i = 0; i < n; i++) { n       cnt++; n       if (ch == s[i]) { n         temp = max(temp, cnt); n         cnt = 0; n       } n     } n     if (cnt) cnt++; n     temp = max(temp, cnt); n     ans = min(temp, ans); n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n long long a[100005]; n int main() { n   { n     cin >> n; n     for (int i = 0; i < n; i++) scanf( %lld , &a[i]); n     sort(a, a + n); n     long long ans = LLONG_MAX; n     for (int c = 1;; c++) { n       long long now = 1; n       long long tot = 0; n       bool ok = 1; n       for (int i = 0; i < n; i++) { n         tot += abs(now - a[i]); n         now = now * c; n         if (now > 1e14) { n           ok = 0; n           break; n         } n       } n       if (!ok) break; n       ans = min(ans, tot); n     } n     printf( %lld n , ans); n   } 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 vector<int> primes; n void solve() { n   int n; n   cin >> n; n   set<int> divisors; n   for (int i = 2; i * i <= n; i++) { n     if (n % i == 0) { n       divisors.insert(i); n       divisors.insert(n / i); n     } n   } n   auto prime = [&](int x) { n     if (x == 2 || x == 3) return true; n     for (int i = 2; i * i <= x; i++) { n       if (x % i == 0) return false; n     } n     return true; n   }; n   if (divisors.size() == 2) { n     if (prime(*divisors.begin()) && prime(*prev(divisors.end()))) { n       for (auto d : divisors) cout << d <<    ; n       cout << n << endl; n       cout << 1 << endl; n       return; n     } n   } n   divisors.insert(n); n   vector<int> primes; n   for (int i = 2; i * i <= n; i++) { n     if (n % i == 0) { n       primes.push_back(i); n       while (n % i == 0) n = n / i; n     } n   } n   if (n > 1) primes.push_back(n); n   vector<int> ans; n   unordered_set<int> avail(divisors.begin(), divisors.end()); n   for (int i = 0; i < primes.size(); i++) { n     int p = primes[i]; n     int q = primes[(i + 1) % primes.size()]; n     for (auto d : divisors) { n       if (avail.find(d) != avail.end() && d % p == 0 && d % q != 0) { n         ans.push_back(d); n         avail.erase(d); n       } n     } n     int r = p * q; n     if (avail.find(r) != avail.end()) { n       ans.push_back(r); n       avail.erase(r); n     } n   } n   for (auto d : divisors) { n     if (avail.find(d) != avail.end()) { n       ans.push_back(d); n       avail.erase(d); n     } n   } n   assert(avail.empty()); n   for (auto e : ans) cout << e <<    ; n   cout << endl; n   cout << 0 << endl; n } n int main() { n   srand(time(NULL)); n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma GCC optimize( O3,Ofast,no-stack-protector,unroll-loops,fast-math ) n const int maxn = 2e3 + 7; n int32_t main() { n   int n, d, e; n   cin >> n >> d >> e; n   int ans = 1e9 + 7; n   for (int i = 1; i * 5 * e <= n; i++) { n     int t = i * 5 * e; n     t = n - t; n     t %= (d); n     ans = min(ans, t); n   } n   int t = n % d; n   ans = min(ans, t); n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n constexpr int power(int x, int e) { return e ? x * power(x, e - 1) : 1; } n template <typename T> n void transpose(std::vector<std::vector<T>>& M) { n   auto tmp = M; n   M.resize(tmp[0].size()); n   for (auto& row : M) row.resize(tmp.size()); n   for (int i = 0; i < (int)M.size(); i++) { n     for (int j = 0; j < (int)M[0].size(); j++) { n       M[i][j] = tmp[j][i]; n     } n   } n } n class FFT { n  public: n   using cd = std::complex<double>; n   using vcd = std::vector<cd>; n   using vvcd = std::vector<vcd>; n   static int get_lg(int x) { return x ? 32 - __builtin_clz(x - 1) : 0; } n   static void precompute(int lg) { n     int size = 1 << lg; n     if ((int)reverse.size() <= lg) { n       reverse.resize(lg + 1); n       ws.resize(lg + 1); n     } n     if (reverse[lg].empty()) { n       reverse[lg].assign(size, 0); n       for (int i = 1, j = 0; i < size; i++) { n         int bit = size >> 1; n         for (; j & bit; bit >>= 1) j ^= bit; n         j ^= bit; n         reverse[lg][i] = j; n       } n     } n     if (ws[lg - 1].empty()) { n       ws[lg - 1].resize(size >> 1); n       for (int i = 0; i < (size >> 1); i++) { n         double ang = 2 * PI * i / size; n         ws[lg - 1][i] = {cos(ang), sin(ang)}; n       } n       for (int j = lg - 2; j >= 0 && ws[j].empty(); j--) { n         int sz_level = ws[j + 1].size() >> 1; n         ws[j].resize(sz_level); n         for (int i = 0; i < sz_level; i++) ws[j][i] = ws[j + 1][i << 1]; n       } n     } n   } n   static void fft(vcd& a, bool inv) { n     int lg = get_lg(a.size()); n     int size = 1 << lg; n     precompute(lg); n     auto& rev = reverse[lg]; n     for (int i = 0; i < size; i++) { n       if (i < rev[i]) swap(a[i], a[rev[i]]); n     } n     for (int k = 0; k < lg; k++) { n       int len = 1 << k; n       auto& w = ws[k]; n       for (int i = 0; i < size; i += 2 * len) { n         for (int j = 0; j < len; j++) { n           cd u = a[i + j], v = a[i + j + len] * w[j]; n           a[i + j] = u + v; n           a[i + j + len] = u - v; n         } n       } n     } n     if (inv) { n       for (cd& x : a) x /= size; n       std::reverse(a.begin() + 1, a.end()); n     } n   } n   static void multiply(vcd& fa, vcd& fb) { n     int result_size = fa.size() + fb.size() + 1; n     int size = 1 << get_lg(result_size); n     fa.resize(size); n     fb.resize(size); n     fft(fa, false); n     fft(fb, false); n     for (int i = 0; i < size; i++) fa[i] *= fb[i]; n     fft(fa, true); n     fa.resize(result_size); n   } n   template <typename T> n   static std::vector<long long> multiply_brute_force(std::vector<T> const& a, n                                                      std::vector<T> const& b) { n     vector<long long> result(a.size() + b.size() + 1, 0); n     for (auto i = 0u; i < a.size(); i++) { n       for (auto j = 0u; j < b.size(); j++) { n         result[i + j] += a[i] * b[j]; n       } n     } n     return result; n   } n   template <typename T> n   static std::vector<long long> multiply(std::vector<T> const& a, n                                          std::vector<T> const& b) { n     vector<long long> result; n     int result_size = a.size() + b.size() + 1; n     if (result_size <= 0) { n       result = multiply_brute_force(a, b); n     } else { n       vcd fa(a.begin(), a.end()), fb(b.begin(), b.end()); n       multiply(fa, fb); n       result.resize(result_size); n       for (int i = 0; i < result_size; i++) n         result[i] = std::llround(fa[i].real()); n     } n     return result; n   } n  n  private: n   static std::vector<std::vector<int>> reverse; n   static std::vector<vcd> ws; n   static const double PI; n }; n std::vector<std::vector<int>> FFT::reverse; n std::vector<FFT::vcd> FFT::ws; n const double FFT::PI = std::acos(-1); n class BigInteger { n  public: n   BigInteger(long long x = 0) { n     if (x > 0) n       sign = 1; n     else if (x == 0) n       sign = 0; n     else n       sign = -1; n     x *= sign; n     while (x) { n       data.push_back(x % BASE); n       x /= BASE; n     } n   } n   BigInteger& operator+=(BigInteger const& o) { n     data.resize(max(data.size(), o.data.size()) + 1, 0); n     int carry = 0; n     for (auto i = 0u; i < o.data.size() || carry; i++) { n       if (i < o.data.size()) carry += o.data[i]; n       if (i < data.size()) carry += data[i]; n       data[i] = carry % BASE; n       carry /= BASE; n     } n     pop_zeros(); n     return *this; n   } n   BigInteger& operator*=(int o) { n     if (o == 0) { n       sign = 0; n       data.clear(); n     } else { n       if (o < 0) { n         sign *= -1; n         o = std::abs(o); n       } n       int n = data.size(); n       data.resize(n + 9, 0); n       long long carry = 0; n       for (int i = 0; i < n || carry; i++) { n         carry += (long long)data[i] * o; n         data[i] = carry % BASE; n         carry /= BASE; n       } n       pop_zeros(); n     } n     return *this; n   } n   BigInteger& operator*=(BigInteger const& o) { n     sign *= o.sign; n     if (sign == 0) { n       data.clear(); n     } else { n       auto result = FFT::multiply(data, o.data); n       data.resize(result.size()); n       long long carry = 0; n       for (auto i = 0u; i < result.size(); i++) { n         carry += result[i]; n         data[i] = carry % BASE; n         carry /= BASE; n       } n       pop_zeros(); n     } n     return *this; n   } n   void pop_zeros() { n     while (!data.empty() && data.back() == 0) data.pop_back(); n   } n   friend std::ostream& operator<<(std::ostream& stream, BigInteger const& b) { n     if (b.data.empty()) { n       stream << 0; n     } else { n       if (b.sign == -1) stream <<  - ; n       stream << b.data.back(); n       for (int i = b.data.size() - 2; i >= 0; i--) { n         stream.width(DIGITS); n         stream.fill( 0 ); n         stream << b.data[i]; n       } n     } n     return stream; n   } n   friend std::istream& operator>>(std::istream& is, BigInteger& b) { n     std::string s; n     is >> s; n     int start = 0; n     if (s ==  0 ) { n       b.sign = 0; n       b.data.clear(); n     } else { n       if (s[0] ==  - ) { n         b.sign = -1; n         start++; n       } else { n         b.sign = 1; n       } n       b.data.resize((s.size() - start + DIGITS - 1) / DIGITS); n       for (int i = 0, idx = s.size() - 1; i < (int)b.data.size(); n            i++, idx -= DIGITS) { n         int value = 0; n         for (int j = max(start, idx - DIGITS + 1); j <= idx; j++) n           value = value * 10 + s[j] -  0 ; n         b.data[i] = value; n       } n     } n     return is; n   } n   unsigned int digits() const { n     if (data.empty()) return 0; n     unsigned int d = (data.size() - 1) * DIGITS; n     int x = data.back(); n     while (x > 0) { n       d++; n       x /= 10; n     } n     return d; n   } n   int compare(BigInteger const& o) const { n     if (sign < o.sign) return -1; n     if (sign > o.sign) return 1; n     if (data.size() != o.data.size()) n       return (data.size() < o.data.size()) == (sign == 1) ? -1 : 1; n     for (int i = data.size() - 1; i >= 0; i--) { n       if (data[i] != o.data[i]) n         return (data[i] < o.data[i]) == (sign == 1) ? -1 : 1; n     } n     return 0; n   } n   bool operator==(BigInteger const& o) const { return compare(o) == 0; } n   bool operator!=(BigInteger const& o) const { return compare(o) != 0; } n   bool operator<(BigInteger const& o) const { return compare(o) == -1; } n   bool operator<=(BigInteger const& o) const { return compare(o) <= 0; } n   bool operator>(BigInteger const& o) const { return compare(o) == 1; } n   bool operator>=(BigInteger const& o) const { return compare(o) >= 0; } n  n  private: n   static const int DIGITS = 4; n   static const int BASE = power(10, DIGITS); n   int sign; n   vector<int> data; n }; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   BigInteger a; n   cin >> a; n   if (a < 5) { n     cout << a <<   n ; n     return 0; n   } n   int p = max(0, (int)(a.digits() * log(10) / log(3) - 3)); n   int sum = p * 3; n   BigInteger x = 1; n   BigInteger base = 3; n   while (p) { n     if (p & 1) x *= base; n     base *= base; n     p >>= 1; n   } n   int best = std::numeric_limits<int>::max(); n   for (int twos = 0; twos < 3; twos++) { n     int sum_cur = sum; n     BigInteger y = x; n     for (int i = 0; i < twos; i++) { n       sum_cur += 2; n       y *= 2; n     } n     while (y < a) { n       sum_cur += 3; n       y *= 3; n     } n     best = min(best, sum_cur); n   } n   cout << best <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n using big = long long; n const int N = 200200; n int a[N]; n int f[N][2][2][2][2]; n int dfs(int n, int x, int y, int v1, int v2) { n   if (!n) { n     assert(!x && !y); n     return v1 > v2; n   } n   if (x && !dfs(n - 1, x - 1, y, v2, !v1)) { n     return true; n   } n   if (y && !dfs(n - 1, x, y - 1, v2, v1)) { n     return true; n   } n   return false; n } n vector<int> to_vec(int x, int y) { return {x % 4, y % 4}; } n map<vector<int>, int> init() { n   map<vector<int>, int> g; n   vector<vector<int>> ans; n   for (int n = 1; n <= 16; ++n) { n     for (int x = 1; x <= n; x += 2) { n       int y = n - x; n       int res = dfs(n, x, y, 0, 0); n       if (g.count(to_vec(x, y)) && g[to_vec(x, y)] != res) { n         cerr <<   ERRRR    << endl; n       } n       assert(!g.count(to_vec(x, y)) || g[to_vec(x, y)] == res); n       g[to_vec(x, y)] = res; n       ans.push_back({x, y, res}); n     } n   } n   return g; n } n int main() { n   ios_base::sync_with_stdio(false); n   auto g = init(); n   int cas; n   cin >> cas; n   memset(f, -1, sizeof(f)); n   while (cas--) { n     int n; n     cin >> n; n     int s = 0; n     for (int i = 0; i < n; ++i) { n       cin >> a[i]; n       s ^= a[i]; n     } n     int highest = 0; n     for (int i = 0; (1ll << i) <= s; ++i) { n       highest = i; n     } n     int cnt = 0; n     for (int i = 0; i < n; ++i) { n       if (a[i] >> highest & 1) { n         ++cnt; n       } n     } n     int other = n - cnt; n     if (!s) { n       cout <<  DRAW  n            <<   n ; n     } else { n       assert(cnt & 1); n       if (g[to_vec(cnt, other)]) { n         cout <<  WIN  n              <<   n ; n       } else { n         cout <<  LOSE  n              <<   n ; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAX = 123456789; n const long long inf = 123456789000000000; n const double EPS = 1e-10; n const double PI = 2 * asin(1.0); n const long long mod = 1e9 + 7; n inline int cmp(double x, double y = 0, double tol = EPS) { n   return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1; n } n int main() { n   string s; n   cin >> s; n   long long par, impar, ap, ai, bp, bi; n   par = impar = ap = ai = bp = bi = 0LL; n   for (int i = 0; i < ((int)s.size()); ++i) { n     impar++; n     if (i % 2 == 0) { n       if (s[i] ==  a ) { n         par += ai; n         impar += ap; n         ap++; n       } else { n         par += bi; n         impar += bp; n         bp++; n       } n     } else { n       if (s[i] ==  a ) { n         par += ap; n         impar += ai; n         ai++; n       } else { n         par += bp; n         impar += bi; n         bi++; n       } n     } n   } n   cout << par <<     << impar << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, a[100100], tmp, Ans, Odd, Even; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i] & 1) n       Odd++; n     else n       Even++; n   } n   tmp = min(Odd, Even); n   Ans += tmp; n   Odd -= tmp; n   Ans += Odd / 3; n   cout << Ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int a, x, y; n   cin >> a; n   while (a--) { n     cin >> x >> y; n     x = x - 1; n     while (x--) { n       y = y + 9; n     } n     cout << y << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200200; n int n, Q, cc = 1, tp, h[N], s[N]; n struct E { n   int v, nxt; n } e[N << 1]; n inline void add(int u, int v) { n   e[cc] = (E){v, h[u]}; n   h[u] = cc++; n } n struct st { n   int n, c[N << 1]; n   inline void upd(int x, int v) { n     for (; x <= n; x += x & -x) c[x] += v; n   } n   inline int qry(int x) { n     int r = 0; n     for (; x; x -= x & -x) r += c[x]; n     return r; n   } n } C; n struct tr { n   int ch[2], f, r, sz, c, tg; n } t[N]; n inline int isrt(int x) { return t[t[x].f].ch[0] != x && t[t[x].f].ch[1] != x; } n inline int wh(int x) { return t[t[x].f].ch[1] == x; } n inline void up(int x) { t[x].sz = t[t[x].ch[0]].sz + t[t[x].ch[1]].sz + 1; } n inline void rot(int x) { n   int y = t[x].f, z = t[y].f, c = wh(x); n   t[x].f = z; n   if (!isrt(y)) t[z].ch[wh(y)] = x; n   t[t[x].ch[c ^ 1]].f = y; n   t[y].ch[c] = t[x].ch[c ^ 1]; n   t[y].f = x; n   t[x].ch[c ^ 1] = y; n   up(y); n   up(x); n } n inline void rev(int x) { n   swap(t[x].ch[0], t[x].ch[1]); n   t[x].r ^= 1; n } n inline void cov(int x, int v) { t[x].c = t[x].tg = v; } n inline void dn(int x) { n   if (t[x].r) rev(t[x].ch[0]), rev(t[x].ch[1]), t[x].r ^= 1; n   if (t[x].tg) cov(t[x].ch[0], t[x].tg), cov(t[x].ch[1], t[x].tg), t[x].tg = 0; n } n inline void splay(int x) { n   for (int i = s[tp = 1] = x; !isrt(i); i = t[i].f) s[++tp] = t[i].f; n   while (tp) dn(s[tp--]); n   for (int y; !isrt(x); rot(x)) n     if (!isrt(y = t[x].f)) wh(x) ^ wh(y) ? rot(x) : rot(y); n } n inline void access(int x, int c) { n   for (int y = 0; x; x = t[y = x].f) { n     splay(x); n     t[x].ch[1] = 0; n     up(x); n     C.upd(t[x].c, -t[x].sz); n     cov(x, c); n     C.upd(t[x].c, t[x].sz); n     t[x].ch[1] = y; n     up(x); n   } n } n inline int qry(int x) { n   splay(x); n   return C.qry(t[x].c) - t[t[x].ch[0]].sz; n } n void dfs(int x, int p) { n   t[x].c = x; n   t[x].sz = 1; n   t[x].f = p; n   for (int i = h[x]; i; i = e[i].nxt) n     if (e[i].v != p) dfs(e[i].v, x), t[x].c = max(t[x].c, t[e[i].v].c); n   for (int i = h[x]; i; i = e[i].nxt) n     if (e[i].v != p && t[x].c == t[e[i].v].c) n       t[x].ch[1] = e[i].v, t[x].sz += t[e[i].v].sz; n   C.upd(t[x].c, 1); n } n int main() { n   scanf( %d%d , &n, &Q); n   C.n = n + Q + 1; n   for (int i = 1, u, v; i < n; i++) scanf( %d%d , &u, &v), add(u, v), add(v, u); n   dfs(n, 0); n   int c = n; n   while (Q--) { n     char o[10]; n     scanf( %s , o); n     int x, y; n     if (o[0] ==  u ) { n       scanf( %d , &x); n       access(x, c); n       splay(x); n       rev(x); n       dn(x); n       C.upd(t[x].c, -1); n       t[x].ch[1] = 0; n       cov(x, ++c); n       t[x].sz = 1; n       C.upd(t[x].c, 1); n     } else if (o[0] ==  w ) n       scanf( %d , &x), printf( %d n , qry(x)); n     else { n       scanf( %d%d , &x, &y); n       printf( %d n , qry(x) < qry(y) ? x : y); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e5 + 10, mod = 1e9 + 7, inf = 1e18; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long n, k, x, s = 0, flag = 0, ans = 0; n   cin >> n >> k; n   for (int i = 1; i <= n; i++) { n     cin >> x; n     s += x; n     if (s / k) flag = 0; n     ans += s / k; n     s %= k; n     if (flag) ans++, s = 0, flag = 0; n     if (s) flag = 1; n   } n   if (s) ans++; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int arr[3000000], a[3000000]; n vector<long long int> v; n int main() { n   long long int n, ans = 0; n   cin >> n; n   for (long long int i = 0; i < n; i++) cin >> arr[i]; n   a[0] = 1; n   for (long long int i = 0; i < n; i++) { n     v.clear(); n     for (long long int j = 1; j * j <= arr[i]; j++) { n       if (arr[i] % j == 0) { n         v.push_back(j); n         if (j != arr[i] / j) v.push_back(arr[i] / j); n       } n     } n     sort(v.begin(), v.end()); n     for (long long int j = v.size() - 1; j >= 0; j--) { n       a[v[j]] = (a[v[j]] % 1000000007 + a[v[j] - 1] % 1000000007) % 1000000007; n     } n   } n   for (int i = 1; i <= 1800000; i++) { n     ans = (ans % 1000000007 + a[i] % 1000000007) % 1000000007; n     ans = (ans % 1000000007 + 1000000007) % 1000000007; n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int mxn = 2 * 1e5 + 5; n long long int vis[mxn]; n vector<vector<long long int>> ad(mxn); n long long int leaf, ans = 0; n void dfs(long long int n, long long int d) { n   vis[n] = 1; n   for (auto child : ad[n]) n     if (!vis[child]) dfs(child, d + 1); n   if (d > ans) { n     ans = d; n     leaf = n; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int t = 1; n   while (t--) { n     long long int i, j, k, n, m; n     cin >> n >> k; n     vector<long long int> par(k + 1); n     for (j = 1; j <= k; j++) par[j] = j; n     vector<vector<long long int>> adj(n + 1); n     for (i = 1; i <= k; i++) { n       adj[n].emplace_back(i); n       ad[n].emplace_back(i); n       ad[i].emplace_back(n); n     } n     for (j = 0; i < n; i++, j++) { n       adj[par[j % k + 1]].emplace_back(i); n       ad[par[j % k + 1]].emplace_back(i); n       ad[i].emplace_back(par[j % k + 1]); n       par[j % k + 1] = i; n     } n     dfs(1, 0); n     ans = 0; n     memset(vis, 0, sizeof vis); n     dfs(leaf, 0); n     cout << ans <<   n ; n     for (i = 1; i <= n; i++) { n       for (auto j : adj[i]) cout << i <<     << j <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, A[100005]; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> A[i]; n   int mx = 0; n   long long sum = 0; n   for (int i = 0; i < n; i++) { n     sum += A[i]; n     if (A[i] > mx) mx = A[i]; n   } n   sum -= mx; n   if (sum <= mx) { n     cout << mx - sum + 1 << endl; n   } else { n     cout << 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n ; n using namespace std; n long long po(long long n, long long exp) { n   long long prod = 1; n   for (long long i = 0; i < exp; i++) prod = (prod * n); n   return prod; n } n double dis(long long x1, long long y1, long long x2, long long y2) { n   return sqrt(((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))); n } n signed main() { n   ios_base::sync_with_stdio(false); n   long long TESTS = 1; n   while (TESTS--) { n     long long n; n     cin >> n; n     long long a[n]; n     for (long long i = 0; i < n; i++) cin >> a[i]; n     long long p = 1, ans = 0; n     a[n] = 1e11; n     for (long long i = 0; i < n; i++) { n       if (a[i] == a[i + 1]) { n         p++; n       } else { n         ans += (p * p + p) / 2; n         p = 1; n       } n     } n     cout << ans; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long int n, k, s; n vector<long long int> v, ans; n void build(const int &last, const int &i, const int &k, n            const bool &increasing) { n   if (!k) n     return; n   else if (last != v[i] and int(v.size()) - i == k) n     ans.push_back(v[i]), build(v[i], i + 1, k - 1, increasing); n   else if (last == v[i]) n     build(last, i + 1, k, increasing ^ 1); n   else n     ans.push_back(last + (increasing ? 1 : -1)), n         build(last + (increasing ? 1 : -1), i, k - 1, increasing); n } n int main() { n   scanf( %lld %lld %lld , &n, &k, &s); n   if (k * (n - 1) < s or k > s) return printf( %s n ,  NO ), 0; n   for (int i = 0; i < k and s > n - 1; ++i, s -= (n - 1)) n     v.push_back((i & 1) ? 1 : n); n   if (int(v.size()) & 1) n     v.push_back(n - s); n   else n     v.push_back(1 + s); n   build(1, 0, k, 1); n   printf( %s n ,  YES ); n   for (int i = 0; i < int(ans.size()); ++i) n     printf( %lld%c , ans[i], (i == int(ans.size()) - 1) ?   n  :    ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   int n, m; n   cin >> n >> m; n   vector<vector<char>> arr(n + 2, vector<char>(m + 2)); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       cin >> arr[i][j]; n     } n   } n   for (int i = 0; i < n + 2; i++) { n     arr[i][0] = arr[i][m + 1] =  . ; n   } n   for (int i = 0; i < m + 2; i++) { n     arr[0][i] = arr[n + 1][i] =  . ; n   } n   n += 2, m += 2; n   int l = 0, r = n + m + 1; n   vector<vector<int>> dist(n, vector<int>(m)); n   queue<pair<int, int>> q; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (arr[i][j] ==  . ) { n         q.emplace(i, j); n         dist[i][j] = 0; n       } else { n         dist[i][j] = INF; n       } n     } n   } n   while (!q.empty()) { n     int i = q.front().first, j = q.front().second; n     q.pop(); n     vector<pair<int, int>> t = {{1, 0},  {1, 1},   {0, 1},  {-1, 1}, n                                 {-1, 0}, {-1, -1}, {0, -1}, {1, -1}}; n     for (auto &add : t) { n       int ni = i + add.first, nj = j + add.second; n       if (ni >= 0 && ni < n && nj >= 0 && nj < m && dist[ni][nj] == INF) { n         dist[ni][nj] = dist[i][j] + 1; n         q.emplace(ni, nj); n       } n     } n   } n   while (r - l > 1) { n     int t = (l + r) / 2; n     vector<vector<int>> dist_start(n, vector<int>(m)); n     deque<pair<int, int>> q; n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         if (arr[i][j] ==  X  && dist[i][j] > t) { n           q.emplace_back(i, j); n           dist_start[i][j] = 0; n         } else { n           dist_start[i][j] = INF; n         } n       } n     } n     while (!q.empty()) { n       int i = q.front().first, j = q.front().second; n       q.pop_front(); n       vector<pair<int, int>> t = {{1, 0},  {1, 1},   {0, 1},  {-1, 1}, n                                   {-1, 0}, {-1, -1}, {0, -1}, {1, -1}}; n       for (auto &add : t) { n         int ni = i + add.first, nj = j + add.second; n         if (ni >= 0 && ni < n && nj >= 0 && nj < m && n             dist_start[ni][nj] == INF) { n           dist_start[ni][nj] = dist_start[i][j] + 1; n           q.emplace_back(ni, nj); n         } n       } n     } n     bool flag = true; n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         if (arr[i][j] ==  X  && dist_start[i][j] > t) { n           flag = false; n         } n       } n     } n     if (flag) { n       l = t; n     } else { n       r = t; n     } n   } n   cout << l <<   n ; n   for (int i = 1; i < n - 1; i++) { n     for (int j = 1; j < m - 1; j++) { n       if (arr[i][j] ==  X  && dist[i][j] > l) { n         cout <<  X ; n       } else { n         cout <<  . ; n       } n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct yts { n   int v[300010], ne[2 * 300010], x[2 * 300010], y[2 * 300010]; n   bool val[2 * 300010]; n   int num; n   void put(int s, int t) { n     num++; n     x[num] = s; n     y[num] = t; n     ne[num] = v[s]; n     v[s] = num; n   } n } e1, e2; n int q[300010]; n bool vis[300010]; n char dir[300010]; n int S, n, m, undir; n char ty(int x) { return (x & 1) ?  -  :  + ; } n void bfs(int type) { n   int h = 0, w = 1; n   q[1] = S; n   vis[S] = 1; n   while (h != w) { n     int x = q[++h]; n     for (int i = e2.v[x]; i; i = e2.ne[i]) { n       if (!dir[i >> 1]) { n         if (type == 1) n           e2.val[i] = 1, e2.val[i ^ 1] = 0, dir[i >> 1] = ty(i); n         else n           e2.val[i] = 0, e2.val[i ^ 1] = 1, dir[i >> 1] = ty(i ^ 1); n       } n     } n     for (int i = e2.v[x]; i; i = e2.ne[i]) n       if (e2.val[i]) { n         int y = e2.y[i]; n         if (!vis[y]) vis[y] = 1, q[++w] = y; n       } n     for (int i = e1.v[x]; i; i = e1.ne[i]) { n       int y = e1.y[i]; n       if (!vis[y]) vis[y] = 1, q[++w] = y; n     } n   } n   int ans = 0; n   for (int i = 1; i <= n; i++) ans += vis[i]; n   printf( %d n , ans); n   for (int i = 1; i <= undir; i++) putchar(dir[i] ? dir[i] :  + ); n   puts(  ); n   memset(vis, 0, sizeof(vis)); n   memset(dir, 0, sizeof(dir)); n   memset(e2.val, 0, sizeof(e2.val)); n } n int main() { n   scanf( %d%d%d , &n, &m, &S); n   e2.num = 1; n   for (int i = 1; i <= m; i++) { n     int x, y, ty; n     scanf( %d%d%d , &ty, &x, &y); n     if (ty == 1) n       e1.put(x, y); n     else { n       undir++; n       e2.put(x, y); n       e2.put(y, x); n     } n   } n   bfs(1); n   bfs(2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int INF = 1e17; n const long long fact_table = 800008; n double Pi = 3.1415926535897932384626; n priority_queue<long long> pql; n priority_queue<pair<long long, long long> > pqp; n priority_queue<long long, vector<long long>, greater<long long> > pqls; n long long dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; n long long dy[8] = {0, 1, 0, -1, 1, -1, -1, 1}; n char dir[] =  DRUL ; n long long mod = 998244353; n long long rui(long long number1, long long number2) { n   if (number2 == 0) { n     return 1; n   } else { n     long long number3 = rui(number1, number2 / 2); n     number3 *= number3; n     number3 %= mod; n     if (number2 % 2 == 1) { n       number3 *= number1; n       number3 %= mod; n     } n     return number3; n   } n } n long long gcd(long long number1, long long number2) { n   if (number1 > number2) { n     swap(number1, number2); n   } n   if (number1 == 0 || number1 == number2) { n     return number2; n   } else { n     return gcd(number2 % number1, number1); n   } n } n void YES(bool condition) { n   if (condition) { n     cout <<  YES  n          <<   n ; n     ; n   } else { n     cout <<  NO  n          <<   n ; n     ; n   } n   return; n } n void Yes(bool condition) { n   if (condition) { n     cout <<  Yes  n          <<   n ; n     ; n   } else { n     cout <<  No  n          <<   n ; n     ; n   } n   return; n } n long long fact[fact_table + 5], rfact[fact_table + 5]; n void c3_init() { n   fact[0] = rfact[0] = 1; n   for (long long i = 1; i <= fact_table; i++) { n     fact[i] = (fact[i - 1] * i) % mod; n   } n   rfact[fact_table] = rui(fact[fact_table], mod - 2); n   for (long long i = fact_table; i >= 1; i--) { n     rfact[i - 1] = rfact[i] * i; n     rfact[i - 1] %= mod; n   } n   return; n } n long long c3(long long n, long long r) { n   return (((fact[n] * rfact[r]) % mod) * rfact[n - r]) % mod; n } n namespace NTT { n void DFT(long long m, long long root, vector<long long> &a, bool rev = false) { n   long long N = a.size(), h = 0; n   for (long long i = 0; 1 << i < N; i++) h++; n   for (long long i = 0; i < N; i++) { n     long long j = 0; n     for (long long k = 0; k < h; k++) j |= (i >> k & 1) << (h - 1 - k); n     if (i < j) swap(a[i], a[j]); n   } n   for (long long i = 1; i < N; i *= 2) { n     long long base = rui(root, (m - 1) / i / 2); n     if (rev) base = rui(base, m - 2); n     long long w = 1; n     for (long long j = 0; j < i; j++) { n       for (long long k = 0; k < N; k += i * 2) { n         long long s = a[j + k], t = a[j + k + i] * w % m; n         a[j + k + 0] = (s + t) % m; n         a[j + k + i] = (s - t + m) % m; n       } n       w = w * base % m; n     } n   } n   if (rev) { n     long long tmp = rui(N, m - 2); n     for (long long &v : a) v = v * tmp % m; n   } n } n vector<long long> conv(long long _mod, long long root, n                        const vector<long long> &a, const vector<long long> &b) { n   long long s = 1, t = a.size() + b.size() - 1; n   while (s < t) s *= 2; n   vector<long long> F(s), G(s); n   for (long long i = 0; i < (long long)a.size(); i++) F[i] = a[i]; n   for (long long i = 0; i < (long long)b.size(); i++) G[i] = b[i]; n   DFT(_mod, root, F); n   DFT(_mod, root, G); n   for (long long i = 0; i < s; i++) F[i] = (long long)F[i] * G[i] % _mod; n   DFT(_mod, root, F, true); n   return F; n } n };  // namespace NTT n long long n, m, num, sum, a, b, c, d, e, h, r, l, q; n long long k; n long long white[500005], red[500005]; n long long ans[500005]; n long long query[500005]; n int main() { n   cin >> n >> k; n   c3_init(); n   for (long long i = 0; i < n; i++) { n     cin >> white[i]; n   } n   for (long long i = 0; i < k; i++) { n     cin >> red[i]; n   } n   cin >> q; n   for (long long i = 0; i < q; i++) { n     cin >> query[i]; n   } n   sort(white, white + n); n   reverse(white, white + n); n   long long cnt = 1; n   vector<pair<long long, long long> > table; n   for (long long i = 0; i < n; i++) { n     if (white[i] != white[i + 1] || i == n - 1) { n       table.push_back(pair<long long, long long>(white[i], cnt)); n       cnt = 1; n     } else { n       cnt++; n     } n   } n   for (long long i = 0; i < k; i++) { n     long long a = 0, b = 0; n     for (long long j = 0; j < table.size(); j++) { n       if (table[j].first >= red[i]) continue; n       if (table[j].second >= 2) b++; n       if (table[j].second == 1) a++; n     } n     vector<long long> atable, btable; n     for (long long j = 0; j <= a; j++) { n       long long tmp = c3(a, j) * rui(2, j); n       tmp %= mod; n       atable.push_back(tmp); n     } n     for (long long j = 0; j <= 2 * b; j++) { n       long long tmp = c3(2 * b, j); n       btable.push_back(tmp); n     } n     auto res = NTT::conv(mod, 3ll, atable, btable); n     for (long long j = 0; j < q; j++) { n       long long cnt = query[j] / 2 - red[i] - 1; n       if (cnt < 0) continue; n       if (cnt > a + b * 2) continue; n       ans[j] += res[cnt]; n       ans[j] %= mod; n     } n   } n   for (long long i = 0; i < q; i++) { n     cout << ans[i] <<   n ; n     ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int ans = 1000001; n   for (int i = 0; i < n; i++) cout << ans + i <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long oo = 0x3f3f3f3f3f3f3f3fll; n const int LGN = 25; n const int MOD = 1e9 + 7; n const int N = 3e5 + 5; n int n, a[N], m, l[N], r[N]; n int mem[N * LGN], cnt; n int* alloc(int x) { n   int* p = mem + cnt; n   cnt += x; n   return p; n } n struct { n   int* a; n   int ans; n } st[4 * N]; n void build(int p = 1, int L = 1, int R = n) { n   if (R < L) return; n   if (L == R) { n     st[p].a = alloc(1); n     st[p].a[0] = ::a[L]; n     st[p].ans = oo; n     return; n   } n   int m = (L + R) >> 1; n   build(2 * p, L, m), build(2 * p + 1, m + 1, R); n   st[p].a = alloc(R - L + 1); n   int* lf = st[2 * p].a; n   int* ri = st[2 * p + 1].a; n   merge(lf, lf + (m - L + 1), ri, ri + (R - m), st[p].a); n   st[p].ans = oo; n   for (long long i = 1, __R = R - L; i <= __R; i++) n     st[p].ans = min(st[p].ans, st[p].a[i] - st[p].a[i - 1]); n } n int query(int l, int r, int p = 1, int L = 1, int R = n); n void update(int i, int v, int& d, int p = 1, int L = 1, int R = n) { n   if (R < L || i < L || R < i) return; n   if (L == R) { n     st[p].ans = min(st[p].ans, abs(st[p].a[0] - v)); n     d = min(d, st[p].ans); n     return; n   } n   int j = upper_bound(st[p].a, st[p].a + (R - L + 1), v) - st[p].a; n   if ((j == 0 || d <= v - st[p].a[j - 1]) && n       (j == R - L + 1 || d <= st[p].a[j] - v)) { n     d = min(d, query(L, i, p, L, R)); n     return; n   } n   int m = (L + R) >> 1; n   if (i <= m) n     update(i, v, d, 2 * p, L, m); n   else { n     update(i, v, d, 2 * p + 1, m + 1, R); n     update(m, v, d, 2 * p, L, m); n   } n   st[p].ans = min(st[p].ans, min(st[2 * p].ans, st[2 * p + 1].ans)); n } n int query(int l, int r, int p, int L, int R) { n   if (R < L || r < L || R < l) return oo; n   if (l <= L && R <= r) return st[p].ans; n   int m = (L + R) >> 1; n   return min(query(l, r, 2 * p, L, m), query(l, r, 2 * p + 1, m + 1, R)); n } n int main() { n   std::ios::sync_with_stdio(false); n   scanf( %d , &(n)); n   for (long long i = 1, __R = n; i <= __R; i++) scanf( %d , &(a[i])); n   build(); n   scanf( %d , &(m)); n   static int idx[N]; n   for (long long i = 1, __R = m; i <= __R; i++) n     scanf( %d%d , &(l[i]), &(r[i])), idx[i] = i; n   sort(idx + 1, idx + m + 1, [](int i, int j) { return r[i] < r[j]; }); n   int curr = 1; n   static int ans[N]; n   for (long long j = 1, __R = m; j <= __R; j++) { n     int i = idx[j]; n     while (curr < r[i]) { n       curr++; n       int d = oo; n       update(curr - 1, a[curr], d); n     } n     ans[i] = query(l[i], r[i]); n   } n   for (long long i = 1, __R = m; i <= __R; i++) printf( %d n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 10004; n int v[MAXN]; n int solve(int x, int y) { n   if (x == y) return 0; n   int mid = (x + y) >> 1; n   int left = 0, right = 0; n   for (int i = x; i < mid + 1; ++i) left = max(left, v[i]); n   for (int i = mid + 1; i < y + 1; ++i) right = max(right, v[i]); n   return abs(right - left) + solve(x, mid) + solve(mid + 1, y); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   while (cin >> n) { n     memset(v, 0, sizeof v); n     int m = (1 << (n + 1)) - 1; n     for (int i = 0; i < m - 1; ++i) { n       int x; n       cin >> x; n       int u = i + 2; n       int p = (u) >> 1; n       v[u] = v[p] + x; n     } n     cout << solve(1 << n, m) << endl; n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n const long long p = 998244353; n const long long N = 3e5; n long long fact[N + 1]; n int32_t main() { n   clock_t clk = clock(); n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   fact[0] = 1; n   for (long long i = 1; i <= N; i++) { n     fact[i] = (fact[i - 1] * i) % p; n   } n   long long n; n   cin >> n; n   vector<pair<long long, long long> > a(n); n   for (auto &it : a) cin >> it.first >> it.second; n   map<long long, vector<long long> > byA; n   map<long long, vector<long long> > byB; n   long long ans = 0; n   long long temp; n   for (pair<long long, long long> pa : a) { n     byA[pa.first].push_back(pa.second); n   } n   temp = 1; n   for (auto pa : byA) { n     temp = (temp * fact[pa.second.size()]) % p; n   } n   ans = (ans + temp) % p; n   for (pair<long long, long long> pa : a) { n     byB[pa.second].push_back(pa.first); n   } n   temp = 1; n   for (auto pa : byB) { n     temp = (temp * fact[pa.second.size()]) % p; n   } n   ans = (ans + temp) % p; n   bool isPossible = 1; n   for (auto it = byA.begin(); it != byA.end(); it++) { n     sort(it->second.begin(), it->second.end()); n     if (it == byA.begin()) continue; n     auto it2 = it; n     --it2; n     long long v1 = it2->second.back(); n     long long v2 = it->second[0]; n     if (v2 < v1) { n       isPossible = 0; n       break; n     } n   } n   temp = 0; n   if (isPossible) { n     temp = 1; n     for (auto pa : byA) { n       long long m = pa.second.size(); n       vector<long long> isLand; n       long long c = 1; n       long long flag = pa.second[0]; n       for (long long i = 1; i < m; i++) { n         if (flag == pa.second[i]) n           c++; n         else { n           isLand.push_back(c); n           c = 1; n           flag = pa.second[i]; n         } n       } n       if (c) isLand.push_back(c); n       long long temp3 = 1; n       for (long long x : isLand) { n         temp3 = (temp3 * fact[x]) % p; n       } n       temp = (temp * temp3) % p; n     } n     ans = (ans + p - temp) % p; n   } n   long long total = fact[n]; n   total = (total + p - ans) % p; n   cout << total; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct tree { n   queue<int> a; n }; n tree num[100005]; n long long apple[100005]; n int beg = 1; n void dfs(int nn, int beg) { n   if (num[nn].a.empty()) return; n   while (!num[nn].a.empty()) { n     int n1 = num[nn].a.front(); n     num[nn].a.pop(); n     apple[beg + 1]++; n     dfs(n1, beg + 1); n   } n } n int main() { n   int number; n   cin >> number; n   int num1; n   memset(apple, 0, sizeof(apple)); n   apple[1] = 1; n   for (int i = 2; i <= number; i++) { n     cin >> num1; n     num[num1].a.push(i); n   } n   long long ans = 0; n   dfs(1, beg); n   for (int i = 1; i <= number; i++) { n     if (apple[i] % 2 != 0) ans++; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Nmax = 2e5 + 10; n int n, k, a, b, q, i; n int tip, d, p, lll; n pair<int, int> arb[4 * Nmax]; n void update(int nod, int st, int dr, int val, int poz) { n   if (st >= dr) { n     arb[nod].first = min(b, arb[nod].first + val); n     arb[nod].second = min(a, arb[nod].second + val); n     return; n   } n   int mij = (st + dr) >> 1; n   if (poz <= mij) n     update((nod << 1), st, mij, val, poz); n   else n     update(((nod << 1) | 1), mij + 1, dr, val, poz); n   arb[nod].first = arb[(nod << 1)].first + arb[((nod << 1) | 1)].first; n   arb[nod].second = arb[(nod << 1)].second + arb[((nod << 1) | 1)].second; n } n int query(int nod, int st, int dr, int a, int b, int r) { n   if (a <= st && dr <= b) n     if (r == 0) n       return arb[nod].first; n     else n       return arb[nod].second; n   int mij = (st + dr) >> 1; n   int val1 = (a <= mij) ? query((nod << 1), st, mij, a, b, r) : 0; n   int val2 = (mij < b) ? query(((nod << 1) | 1), mij + 1, dr, a, b, r) : 0; n   return val1 + val2; n } n int main() { n   scanf( %d %d , &n, &k); n   scanf( %d %d , &a, &b); n   scanf( %d , &q); n   for (i = 1; i <= q; ++i) { n     scanf( %d , &tip); n     if (tip == 1) { n       scanf( %d %d , &d, &p); n       update(1, 1, n, p, d); n     } else { n       scanf( %d , &lll); n       int v = 0; n       if (lll > 1) v += query(1, 1, n, 1, lll - 1, 0); n       if (lll + k <= n) v += query(1, 1, n, lll + k, n, 1); n       printf( %d n , v); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   string l; n   cin >> l; n   sort(l.begin(), l.end()); n   int a = 0, ans = 0; n   char p = l[0]; n   for (;;) { n     if (l[0] == p) { n       a++; n       l.erase(l.begin()); n     } else { n       ans = max(ans, a); n       if (l.size() > 0) { n         p = l[0]; n         a = 0; n       } else n         break; n     } n   } n   if (ans > k) n     cout <<  NO ; n   else n     cout <<  YES ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mo = 1e9 + 7; n const int mx = 500010; n int n, m, k, a[1010], c[1010], ans, sum; n int jud[mx]; n set<int> s[mx]; n set<int>::iterator it; n vector<int> vc[mx]; n void dfs(int y, int pre) { n   vector<int> v; n   if (pre == -1) { n     int t = 1; n     for (it = s[y].begin(); it != s[y].end(); it++) { n       jud[*it] = t++; n       sum = max(sum, t - 1); n     } n   } else { n     for (it = s[y].begin(); it != s[y].end(); it++) { n       if (jud[(*it)]) v.push_back(jud[(*it)]); n     } n     int vn = v.size(); n     sort(v.begin(), v.end()); n     int f = 0, t = 1; n     for (it = s[y].begin(); it != s[y].end(); it++) { n       if (!jud[(*it)]) { n         while (f < vn && v[f] == t) { n           f++; n           t++; n         } n         jud[(*it)] = t++; n       } n       sum = max(sum, t - 1); n     } n   } n   int nm = vc[y].size(); n   for (int i = 0; i < nm; i++) { n     int vyi = vc[y][i]; n     if (vyi != pre) dfs(vyi, y); n   } n } n int dxy[8] = {1, 0, -1, 0, 0, 1, 0, -1}; n int main() { n   ios::sync_with_stdio(false); n   int t, i, j, l, q, x, y, ss; n   int cas = 1, flag; n   cin >> n >> m; n   { n     l = max(n, m); n     for (i = 0; i <= l; i++) { n       vc[i].clear(); n       jud[i] = 0; n     } n     sum = 1; n     for (i = 1; i <= n; i++) { n       cin >> ss; n       for (j = 0; j < ss; j++) { n         cin >> x; n         s[i].insert(x); n       } n     } n     for (i = 0; i < n - 1; i++) { n       cin >> x >> y; n       vc[x].push_back(y); n       vc[y].push_back(x); n     } n     dfs(1, -1); n     cout << sum << endl; n     for (i = 1; i <= m; i++) { n       if (jud[i]) n         cout << jud[i]; n       else n         cout <<  1 ; n       if (i != m) n         cout <<    ; n       else n         cout << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, w[101], i, j, S, Sum, k, C, a, t; n int main() { n   scanf( %d , &n); n   for (i = 1; i <= n; i++) { n     scanf( %d , &k); n     for (j = 1; j <= k; j++) { n       scanf( %d , &a); n       Sum += a; n       t = j * 2 - k; n       if (t == 1) n         w[C++] = -a; n       else if (t <= 0) n         S += a; n     } n   } n   sort(w, w + C); n   for (i = 0; i < C; i += 2) S -= w[i]; n   printf( %d %d n , S, Sum - S); n } n


#include <bits/stdc++.h> n using namespace std; n int c[105], sum[105]; n pair<int, int> p[105]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &c[i]); n     sum[i] = sum[i - 1] + c[i]; n   } n   int st = 1, tot = 0; n   for (int i = 1; i <= n; i++) { n     if (sum[i] - sum[st - 1] < 0 && (c[i + 1] > 0 || i == n)) n       p[++tot].first = st, p[tot].second = i, st = i + 1; n     else if (sum[i] - sum[st - 1] > 0 && (c[i + 1] < 0 || i == n)) n       p[++tot].first = st, p[tot].second = i, st = i + 1; n   } n   if (st != n + 1) n     printf( NO ); n   else { n     printf( YES n%d n , tot); n     for (int i = 1; i <= tot; i++) printf( %d %d n , p[i].first, p[i].second); n   } n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n std::pair<int, int> DR[] = {{-1, 0}, {0, 1},   {1, 0}, {0, -1}, n                             {-1, 1}, {-1, -1}, {1, 1}, {1, -1}}; n using namespace std; n int n, x, a[1 << 19]; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cerr.tie(0); n   cout.tie(0); n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   multiset<int> ms; n   for (int i = 1; i <= n; i++) { n     cin >> x; n     ms.insert(x); n   } n   for (int i = 1; i <= n; i++) { n     auto it = ms.begin(); n     auto itt = ms.end(); n     itt--; n     int x = 0; n     for (int j = 29; j + 1; j--) { n       if (a[i] & (1LL << j)) { n         if (*itt >= x + (1LL << j)) { n           x += (1LL << j); n           auto luh = ms.lower_bound(x); n           if (*luh > *it) it = luh; n         } n       } else { n         if (*it < x + (1LL << j)) { n           auto luh = ms.lower_bound(x + (1LL << j)); n           luh--; n           if (*luh < *itt) itt = luh; n         } else n           x += (1LL << j); n       } n     } n     cout << (a[i] ^ (*it)) <<    ; n     ms.erase(it); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 512, M = 20000 + 10; n struct Stage { n   int p[N]; n } stage[N * 2]; n struct Edge { n   int u, v; n   void init() { scanf( %d%d , &u, &v); } n } edge[M]; n int preStg[M], postStg[M], nstg; n int p[N], num[N]; n int n, m; n int findr(int x, int* P) { n   int r = x; n   while (P[r]) r = P[r]; n   while (P[x]) { n     int t = P[x]; n     P[x] = r; n     x = t; n   } n   return r; n } n void join(int x, int y, int* P) { n   int r1 = findr(x, P); n   int r2 = findr(y, P); n   if (r1 == r2) return; n   if (num[r1] > num[r2]) { n     num[r1] += num[r2]; n     P[r2] = r1; n   } else { n     num[r2] += num[r1]; n     P[r1] = r2; n   } n } n int l, r; n int solve() { n   Stage st1 = stage[preStg[l]]; n   Stage st2 = stage[postStg[r]]; n   memset(num, 0, sizeof(num)); n   for (int i = 1; i <= n; ++i) { n     join(i, st2.p[i], st1.p); n   } n   int sum = 0; n   for (int i = 1; i <= n; ++i) { n     sum += (findr(i, st1.p) == i); n   } n   return sum; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; ++i) { n     edge[i].init(); n   } n   memset(p, 0, sizeof(p)); n   memset(num, 0, sizeof(num)); n   for (int i = 1; i <= n; ++i) { n     stage[nstg].p[i] = p[i]; n   } n   nstg++; n   for (int i = 1; i <= m; ++i) { n     preStg[i] = nstg - 1; n     if (findr(edge[i].u, p) != findr(edge[i].v, p)) { n       join(edge[i].u, edge[i].v, p); n       for (int j = 1; j <= n; ++j) { n         stage[nstg].p[j] = p[j]; n       } n       nstg++; n     } n   } n   memset(p, 0, sizeof(p)); n   memset(num, 0, sizeof(num)); n   for (int i = 1; i <= n; ++i) { n     stage[nstg].p[i] = p[i]; n   } n   nstg++; n   for (int i = m; i >= 1; --i) { n     postStg[i] = nstg - 1; n     if (findr(edge[i].u, p) != findr(edge[i].v, p)) { n       join(edge[i].u, edge[i].v, p); n       for (int j = 1; j <= n; ++j) { n         stage[nstg].p[j] = p[j]; n       } n       nstg++; n     } n   } n   int q; n   scanf( %d , &q); n   while (q--) { n     scanf( %d %d , &l, &r); n     printf( %d n , solve()); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, m, k, i, x, y, s, p; n   cin >> n >> m; n   s = 0; n   k = 1; n   for (i = 1; i <= n; i++) { n     cin >> x >> y; n     k = x - k; n     p = k % m; n     x -= p; n     s += y - x + 1; n     k = y + 1; n   } n   cout << s << endl; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:136777216 ) n using namespace std; n int bits(int x) { return x == 0 ? 0 : 1 + bits(x & (x - 1)); } n int v[30][30]; n int dp[2][26][111]; n int main() { n   const int ninf = -1000000; n   for (int(i) = 0; (i) < (30); (i)++) n     for (int(j) = 0; (j) < (30); (j)++) v[i][j] = 0; n   string s; n   int K, m; n   cin >> s >> K >> m; n   int n = (int)(s).size(); n   K = min(K, n); n   char a, b; n   int c; n   for (int(i) = 0; (i) < (m); (i)++) { n     cin >> a >> b >> c; n     v[a -  a ][b -  a ] = c; n   } n   for (int(j) = 0; (j) < (26); (j)++) n     for (int(k) = 0; (k) < (K + 1); (k)++) dp[0][j][k] = ninf; n   for (int(j) = 0; (j) < (26); (j)++) n     if (j == s[0] -  a ) n       dp[0][j][0] = 0; n     else n       dp[0][j][1] = 0; n   int add; n   for (int i = 1; i < n; i++) { n     int now = i % 2, bef = 1 - now; n     for (int(j) = 0; (j) < (26); (j)++) n       for (int(k) = 0; (k) < (K + 1); (k)++) dp[now][j][k] = ninf; n     for (int(prev) = 0; (prev) < (26); (prev)++) n       for (int(cur) = 0; (cur) < (26); (cur)++) { n         if (cur == s[i] -  a ) n           add = 0; n         else n           add = 1; n         if (add == 0) n           dp[now][cur][0] = n               max(dp[now][cur][0], dp[bef][prev][0] + v[prev][cur]); n         for (int(ch) = (1); (ch) < (K + 1); (ch)++) { n           dp[now][cur][ch] = n               max(dp[now][cur][ch], dp[bef][prev][ch - add] + v[prev][cur]); n         } n       } n   } n   int r = ninf, t = (n - 1) % 2; n   for (int(j) = 0; (j) < (26); (j)++) n     for (int(k) = 0; (k) < (K + 1); (k)++) r = max(r, dp[t][j][k]); n   cout << r; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, a = 0, b = 0, c = 0, d = 0, i, e = 0, mine = 0, mn = 0; n   cin >> n; n   string s; n   cin >> s; n   for (i = 0; i < s.size(); i++) { n     if (s[i] ==  z ) a++; n     if (s[i] ==  e ) b++; n     if (s[i] ==  r ) c++; n     if (s[i] ==  o ) d++; n     if (s[i] ==  n ) e++; n   } n   mn = min(min(d, c), min(a, b)); n   if (b > mn && d > mn && e > 0) { n     mine = min(min((b - mn), (d - mn)), e); n     for (i = 0; i < mine; i++) { n       cout <<  1  n            <<    ; n     } n   } n   if (mn > 0) { n     for (i = 0; i < mn; i++) { n       cout <<  0  n            <<    ; n     } n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int hm(string s) { n   int c = 0; n   for (int i = 0; i < s.length(); i++) { n     if (s[i] ==  a  || s[i] ==  e  || s[i] ==  i  || s[i] ==  o  || s[i] ==  u ) n       c++; n   } n   return c; n } n int main() { n   string s1, s2, s3; n   getline(cin, s1); n   getline(cin, s2); n   getline(cin, s3); n   if (hm(s1) == 5 && hm(s2) == 7 && hm(s3) == 5) n     cout <<  YES ; n   else n     cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long oll = 0; n bool comp(const pair<int, int> &a, const pair<int, int> &b) { n   return a.second < b.second; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   vector<long long> first, second; n   long long fr = 0, sc = 0; n   int lst = -1; n   for (long long i = 0; i < n; i++) { n     int temp; n     cin >> temp; n     if (temp > 0) { n       if (i == n - 1) { n         lst = 1; n       } n       first.push_back(temp); n       fr += temp; n     } else { n       if (i == n - 1) { n         lst = 2; n       } n       temp *= -1; n       second.push_back(temp); n       sc += (temp); n     } n   } n   if (fr > sc) { n     cout <<  first  n          <<   n ; n   } else if (fr < sc) { n     cout <<  second  n          <<   n ; n   } else { n     int win = -1; n     for (long long i = 0; i < min(first.size(), second.size()); i++) { n       if (first[i] > second[i]) { n         win = 1; n         break; n       } else if (first[i] < second[i]) { n         win = 2; n         break; n       } n     } n     if (win == 1) { n       cout <<  first  n            <<   n ; n     } else if (win == 2) { n       cout <<  second  n            <<   n ; n     } else { n       if (lst == 1) { n         cout <<  first  n              <<   n ; n       } else { n         cout <<  second  n              <<   n ; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dr[] = {-1, 0, 1, 0, -1, 1, 1, -1}; n int dc[] = {0, 1, 0, -1, 1, 1, -1, -1}; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n; n   while (cin >> n) { n     vector<int> arr; n     int st = 1; n     int ans = 0; n     for (int i = (0); i <= (2 * n - 1); i += (1)) { n       string s; n       cin >> s; n       if (s ==  remove ) { n         if (arr.empty()) { n           st++; n           continue; n         } n         if (st == arr[(int)arr.size() - 1]) { n           st++; n           arr.pop_back(); n         } else { n           arr.clear(); n           st++; n           ans++; n         } n       } else { n         int nn; n         cin >> nn; n         arr.push_back(nn); n       } n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   char a[100010]; n   int k; n   cin >> s; n   k = 0; n   for (int i = 0; i < s.length(); i++) { n     if (s[i] == a[k]) n       k--; n     else { n       k++; n       a[k] = s[i]; n     } n   } n   if (k == 0) n     cout <<  Yes ; n   else n     cout <<  No ; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T abs(T x) { n   if (x < 0) return -x; n   return x; n } n template <class T> n T sqr(T a) { n   return a * a; n } n const double pi = acos(-1.0); n const double eps = 1e-8; n int ar[150010]; n int flag[150010]; n int i, n; n int main() { n   while (1 == scanf( %d , &n)) { n     memset(flag, 0, sizeof flag); n     for (i = 0; i < n; i++) scanf( %d , &ar[i]); n     sort(&ar[0], &ar[n]); n     for (i = 0; i < n; i++) { n       if (flag[ar[i] - 1] == 0 && ar[i] > 1) n         flag[ar[i] - 1]++; n       else if (flag[ar[i]] == 0) n         flag[ar[i]]++; n       else if (flag[ar[i] + 1] == 0) n         flag[ar[i] + 1]++; n     } n     int cnt = 0; n     for (i = 1; i <= 150001; i++) n       if (flag[i]) cnt++; n     printf( %d n , cnt); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 2000000000; n const long double eps = 1e-07; n int n, m; n int a[2000]; n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 0; i < m; ++i) { n     int x, y; n     scanf( %d %d , &x, &y); n     ++a[x]; n     ++a[y]; n   } n   for (int i = 0; i < n; ++i) n     if (a[i + 1] == 0) { n       printf( %d n , n - 1); n       for (int j = 1; j <= n; ++j) { n         if (j != (i + 1)) printf( %d %d n , i + 1, j); n       } n       return 0; n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, L, a; n int t[int(1e5 + 9)], l[int(1e5 + 9)]; n int ans; n int main() { n   cin >> n >> L >> a; n   for (int i = 0; i < n; i++) { n     cin >> t[i] >> l[i]; n   } n   for (int i = 0; i + 1 < n; i++) { n     int st = t[i] + l[i]; n     int en = t[i + 1]; n     if (en - st >= a) { n       ans += (en - st) / a; n     } n   } n   if (t[0] >= a) ans += t[0] / a; n   if (L - (t[n - 1] + l[n - 1]) >= a) ans += (L - (t[n - 1] + l[n - 1])) / a; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void _print(long long t) { cerr << t; } n void _print(string t) { cerr << t; } n void _print(char t) { cerr << t; } n void _print(long double t) { cerr << t; } n void _print(double t) { cerr << t; } n void _print(unsigned long long t) { cerr << t; } n template <class T, class V> n void _print(pair<T, V> p); n template <class T> n void _print(vector<T> v); n template <class T> n void _print(set<T> v); n template <class T, class V> n void _print(map<T, V> v); n template <class T> n void _print(multiset<T> v); n template <class T, class V> n void _print(pair<T, V> p) { n   cerr <<  { ; n   _print(p.first); n   cerr <<  , ; n   _print(p.second); n   cerr <<  } ; n } n template <class T> n void _print(vector<T> v) { n   cerr <<  [  ; n   for (T i : v) { n     _print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n template <class T> n void _print(set<T> v) { n   cerr <<  [  ; n   for (T i : v) { n     _print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n template <class T> n void _print(multiset<T> v) { n   cerr <<  [  ; n   for (T i : v) { n     _print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n template <class T, class V> n void _print(map<T, V> v) { n   cerr <<  [  ; n   for (auto i : v) { n     _print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n long long n = 0; n const long long mod = 1e9 + 7; n long long tt = 0; n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long power(long long x, long long y, long long m) { n   if (y == 0) return 1; n   if (y == 1) return x; n   long long cur = power(x, y / 2, m); n   cur = (cur % m * cur % m); n   if ((y & 1)) cur = (cur % m * x % m) % m; n   return cur; n } n long long modinv(long long x, long long m) { return power(x, m - 2, m) % m; } n void pre_solve() {} n void sol(long long tc) { n   cin >> n; n   vector<vector<long long> > arr(n, vector<long long>(3)); n   for (long long i = 0; i < n; i++) { n     cin >> arr[i][0] >> arr[i][1]; n     arr[i][2] = i; n   } n   sort(arr.begin(), arr.end()); n   long long y = arr[0][1], idx = 0; n   for (idx = 1; idx < n; idx++) { n     if (arr[idx][0] > y) n       break; n     else { n       y = max(arr[idx][1], y); n     } n   } n   if (idx == n) n     cout << -1 << endl; n   else { n     long long ans[n]; n     for (long long i = 0; i < idx; i++) { n       ans[arr[i][2]] = 1; n     } n     for (long long i = idx; i < n; i++) ans[arr[i][2]] = 2; n     for (long long i = 0; i < n; i++) cout << ans[i] <<    ; n     cout << endl; n   } n   return; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   long long tc = 1; n   cin >> tc; n   while (tc--) { n     tt++; n     sol(tc); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MODULO = 1000000007; n void ftime() {} n void print_arr(int n, bool arr[]) { n   for (int i = 0; i < n; i++) { n     cout << arr[i] <<    ; n   } n   cout <<   n ; n } n void print_arr(int n, int arr[]) { n   for (int i = 0; i < n; i++) { n     cout << arr[i] <<    ; n   } n   cout <<   n ; n } n void print_vec(vector<int> &vec) { n   for (auto e : vec) { n     cout << e <<    ; n   } n   cout <<   n ; n } n void print_vec(vector<long long> &vec) { n   for (auto e : vec) { n     cout << e <<    ; n   } n   cout <<   n ; n } n void print_vec(vector<bool> &vec) { n   for (auto e : vec) { n     cout << e <<    ; n   } n   cout <<   n ; n } n static int speed_increase = []() { n   std::ios::sync_with_stdio(false); n   std::cin.tie(NULL); n   return 0; n }(); n void print_map(unordered_map<long long, long long> &comp) { n   for (auto e : comp) { n     cout << e.first <<   :   << e.second <<   n ; n   } n   cout <<   n ; n } n vector<long long> fdp(1000, -1); n long long fact(long long val) { n   if (fdp[val] > 0) { n     return fdp[val]; n   } n   if (val < 2) return 1; n   fdp[val] = (val * fact(val - 1)) % MODULO; n   return fdp[val]; n } n long long modexp(long long base, long long exponent) { n   long long res = 1; n   base = (base % MODULO + MODULO) % MODULO; n   while (exponent) { n     if (exponent & 1) res = (res * base) % MODULO; n     exponent >>= 1; n     base = (base * base) % MODULO; n   } n   return res; n } n int main() { n   int n, m; n   cin >> n >> m; n   vector<long long> vals(m + 1, 0); n   vector<long long> lights(m, 0); n   for (auto &x : lights) { n     cin >> x; n   } n   sort(lights.begin(), lights.end()); n   int last = 0; n   int curr; n   for (int i = 0; i < m; i++) { n     curr = lights[i]; n     vals[i] = curr - last - 1; n     last = curr; n   } n   vals[m] = n - last; n   long long sum = accumulate(vals.begin(), vals.end(), 0ll); n   long long ans = fact(sum) % MODULO; n   for (int i = 0; i < m + 1; i++) { n     if (vals[i] > 1) { n       ans *= modexp(fact(vals[i]), MODULO - 2); n       ans %= MODULO; n     } n     if (i != 0 && i != m && vals[i] > 1) { n       ans *= modexp(2, vals[i] - 1); n       ans %= MODULO; n     } n   } n   cout << ans; n   ftime(); n   return 0; n } n