#include <bits/stdc++.h> n  n using namespace std; n  n typedef long long ll; n  n int get_next_state(bool s1, bool s2, bool b1, bool b2) { n   if (s1 && b1) { n     return -1; n   } n   if (s2 && b2) { n     return -1; n   } n   bool a1 = s1 | b1; n   bool a2 = s2 | b2; n   if ((a1 && a2) || (!a1 && !a2)) { n     return 0; n   } n   if (a1) { n     return 1; n   } n   return 2; n } n  n bool solve_dp(int n, const vector<pair<int, int>>& cr) { n   const bool S1[3] = {false, false, true}; n   const bool S2[3] = {false, true, false}; n   vector<vector<bool>> filled(2, vector<bool>(n, false)); n   int m = cr.size(); n   for (int i = 0; i < m; ++i) { n     filled[cr[i].second][cr[i].first] = true; n   } n   /* n   for (int r = 0; r < 2; ++r) { n     for (int i = 0; i < n; ++i) { n       if (filled[r][i]) { n  cout <<  # ; n       } n       else { n  cout <<  . ; n       } n     } n     cout << endl; n     } */ n   vector<uint8_t> dp(n+1); n   dp[n] = 1; n   for (int i = n-1; i >= 0; --i) { n     dp[i] = 0; n     for (int state = 0; state < 3; ++state) { n       int next_state = get_next_state(S1[state], S2[state], filled[0][i], filled[1][i]); n       //cout <<  next_state[  << i <<  ][  << state <<  ] =   << next_state << endl; n       if (next_state >= 0) { n  dp[i] |= ((dp[i+1] >> next_state) & 1) << state; n       } n     } n     //cout << dp[i] <<    ; n   } n   //cout << endl; n   return (dp[0] & 1) == 1; n } n  n bool solve_dp2(int n, const vector<pair<int, int>>& cr) { n   int m = cr.size(); n   int prv_state = 0; n   int prv_posish = 0; n   int p = 0; n   while (p < m) { n     int posish = cr[p].first; n     int state = 0; n     if ((p < (m-1)) && (cr[p+1].first == posish)) { n       p += 2; n     } n     else { n       state = cr[p].second+1; n       p++; n     } n     if (state == 0) { n       if (prv_state != 0) { n  return false; n       } n     } n     else { n       if (prv_state == 0) { n  prv_state = 3-state; n       } n       else { n  if (((posish - prv_posish) % 2) == 1) { n    prv_state = 3-prv_state; n  } n  if (prv_state != state) { n    return false; n  } n  prv_state = 0; n       } n     } n     prv_posish = posish; n   } n   return (prv_state == 0); n } n  n bool solve(int n, const vector<int>& r, const vector<int>& c) { n   int m = r.size(); n   vector<pair<int, int>> cr(m); n   for (int i = 0; i < m; ++i) { n     cr[i] = make_pair(c[i], r[i]); n   } n   sort(cr.begin(), cr.end()); n   return solve_dp2(n, cr); n   vector<pair<int, int>> ccr(m); n   int prv_c = 0; n   int compress = 0; n   for (int i = 0; i < m; ++i) { n     if ((cr[i].first - prv_c) >= 2) { n       compress += ((cr[i].first - prv_c - 2) / 2) * 2; n     } n     prv_c = cr[i].first; n     ccr[i] = make_pair(cr[i].first-compress, cr[i].second); n   } n   return solve_dp(n-compress, ccr); n } n  n void test_case() { n   int n, m; n   cin >> n >> m; n   vector<int> r(m), c(m); n   for (int i = 0; i < m; ++i) { n     cin >> r[i] >> c[i]; n     --r[i]; n     --c[i]; n   } n   if (solve(n, r, c)) { n     cout <<  YES  << endl; n   } n   else { n     cout <<  NO  << endl; n   } n } n  n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   for (int i = 0; i < t; ++i) { n     test_case(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MODULO = 998244353; n const int N_MAX = 200010; n vector<int> neighbors[N_MAX]; n int factorials[N_MAX]; n int n; n int calculateBranch(int x, int par) { n   int perm = factorials[neighbors[x].size()]; n   for (int y : neighbors[x]) { n     if (y != par) { n       perm = ((long long)perm * calculateBranch(y, x)) % MODULO; n     } n   } n   return perm; n } n void outerInit() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   auto fi = new ifstream( test.inp ); n   if (*fi) { n     cin.rdbuf(fi->rdbuf()); n   } n } n void readData() { n   cin >> n; n   for (int i = 1; i < n; ++i) { n     int x, y; n     cin >> x >> y; n     neighbors[x].push_back(y); n     neighbors[y].push_back(x); n   } n } n void initData() { n   factorials[0] = 1; n   for (int i = 1; i <= n; ++i) { n     factorials[i] = ((long long)factorials[i - 1] * i) % MODULO; n   } n } n void solveData() { cout << ((long long)n * calculateBranch(1, 0)) % MODULO; } n int main() { n   outerInit(); n   readData(); n   initData(); n   solveData(); n } n


#include<bits/stdc++.h> n #define ll long long n #define ld long double n #define ull unsigned long long n #define izq nod * 2 n #define der nod * 2 + 1 n #define md (( a + b ) >> 1) n #define oo (1LL<<30LL) n #define len(X) (int)(X).size() n using namespace std; n  n const ll MOD = 998244353; n  n const int MX = 2 * 1e5+5; n  n ll F[MX],iF[MX]; n  n ll pot( ll base, ll e){ n     ll ans = 1ll; n      n     while( e ){ n         if( e & 1ll ) ans = (ans * base) % MOD; n         base = (base * base) % MOD; n         e>>=1ll;     n     }  n      n     return ans;   n } n  n int main(){ n   n  ios_base::sync_with_stdio(0); n  cin.tie(0); n   n  int t; n  cin>>t; n   n  F[0] = iF[0] = 1; n   n  for ( ll i = 1; i <= 2e5; i++ ){ n       F[i] = ( F[i-1] * i )%MOD;  n       iF[i] = pot ( F[i], MOD-2LL ); n  } n   n  while ( t-- ){ n           int n; n           cin>>n; n            n           string s; n           cin>>s; n            n           int c0 = 0,c1 = 0; n            n           for ( int i = 0; i < len(s); i++ ){ n          if ( s[i] ==  1  && i < len(s)-1 && s[i+1] ==  1  ){  n           c1++; i++; n       } n       if ( s[i] ==  0  )c0++;  n     } n      n     cout<<F[c0+c1] * iF[c0] % MOD * iF[c1] % MOD<<  n ;; n            n     } n   n return 0;  n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n enum { MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009 }; n template <typename T> n class FenwickTree { n   vector<T> tree; n  n  public: n   FenwickTree<T>() : tree() {} n   FenwickTree<T>(vector<T> a) : tree(a.size() + 1, 0) { n     for (size_t i = 0; i < a.size(); ++i) { n       add(i, a[i]); n     } n   } n   size_t size() const { return tree.size() ? tree.size() - 1 : 0; } n   void add(size_t index, T value) { n     for (; ++index <= size(); index |= index - 1) { n       tree[index] += value; n     } n   } n   T sum(size_t right) { n     T ret{}; n     for (; right; right &= right - 1) { n       ret += tree[right]; n     } n     return ret; n   } n   T sum(size_t left, size_t right) { return sum(right) - sum(left); } n }; n int a[200000]; n FenwickTree<long long> ft; n int t[800000]; n int n; n void build(int x = 0, int L = 0, int R = n - 1) { n   if (L == R) { n     t[x] = a[L]; n     return; n   } n   int M = (L + R) / 2; n   build(2 * x + 1, L, M); n   build(2 * x + 2, M + 1, R); n   t[x] = max(t[2 * x + 1], t[2 * x + 2]); n } n void upd(int index, int val, int x = 0, int L = 0, int R = n - 1) { n   if (L == R) { n     t[x] = val; n     return; n   } n   int M = (L + R) / 2; n   if (index <= M) { n     upd(index, val, 2 * x + 1, L, M); n   } else { n     upd(index, val, 2 * x + 2, M + 1, R); n   } n   t[x] = max(t[2 * x + 1], t[2 * x + 2]); n } n int get(long long val, int from, int x = 0, int L = 0, int R = n - 1) { n   if (t[x] < val || R < from) { n     return n; n   } else if (L == R) { n     return L; n   } n   int M = (L + R) / 2; n   if (M < from) { n     return get(val, from, 2 * x + 2, M + 1, R); n   } else if (t[2 * x + 1] >= val) { n     int s = get(val, from, 2 * x + 1, L, M); n     if (s < n) { n       return s; n     } n   } n   return get(val, from, 2 * x + 2, M + 1, R); n } n int get_ans() { n   long long cur = 0; n   int index = 0; n   if (a[0] == 0) { n     return 1; n   } n   while (index < n) { n     cur += a[index]; n     index = get(cur, index + 1); n     cur = ft.sum(index); n     if (a[index] == cur) { n       break; n     } n   } n   return index >= n ? -1 : index + 1; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   int q; n   cin >> n >> q; n   vector<long long> b; n   for (int i = 0; i < n; ++i) { n     cin >> a[i]; n     b.push_back(a[i]); n   } n   ft = FenwickTree<long long>(b); n   build(); n   while (q--) { n     int p, x; n     cin >> p >> x; n     --p; n     ft.add(p, x - a[p]); n     a[p] = x; n     upd(p, x); n     cout << get_ans() <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10; n const long long mod = 1e9 + 7; n long long qpow(long long a, long long b) { n   long long res = 1; n   while (b) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n     b >>= 1; n   } n   return res; n } n int n; n int vis[N], prime[N], num, mu[N], inv[N]; n void makeMobius(int siz) { n   mu[1] = 1, num = 0; n   for (int i = 2; i <= siz; i++) { n     if (!vis[i]) prime[++num] = i, mu[i] = -1; n     for (int j = 1; j <= num && i * prime[j] <= siz; j++) { n       vis[i * prime[j]] = 1; n       if (i % prime[j] == 0) { n         mu[i * prime[j]] = 0; n         break; n       } else n         mu[i * prime[j]] = mu[i] * mu[prime[j]]; n     } n   } n   inv[1] = 1; n   for (int i = 2; i <= siz; i++) inv[i] = qpow(i, mod - 2); n } n long long calc(long long d) { n   long long y = n / d; n   return y * inv[n - y] % mod; n } n int main() { n   scanf( %d , &n); n   makeMobius(n); n   long long ans = 1; n   for (int d = 2; d <= n; d++) ans = (ans - calc(d) * mu[d] % mod + mod) % mod; n   printf( %lld n , (ans + mod) % mod); 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 n, k, b, e; n   cin >> n >> k; n   if (n == 1) { n     cout <<  0  << endl; n     return 0; n   } n   long long p = ((k - 1) * k) / 2 - 1; n   if (n >= 2 && n <= (p + 2)) { n     b = 2; n     e = k - 2; n     if (n == p + 2) n       cout << k - 1 << endl; n     else if (n >= 2 && n <= k) n       cout <<  1  << endl; n     else { n       while (b <= e) { n         long long mid = (e + b) / 2; n         long long g = k - mid + 1; n         long long begin = (k * (k + 1)) / 2 - (g * (g + 1)) / 2; n         long long f = mid - 2; n         begin = begin - f + 1; n         g--; n         long long end = (k * (k + 1)) / 2 - (g * (g + 1)) / 2; n         long long f2 = mid - 1; n         end = end - f2; n         if (n >= begin && n <= end) { n           cout << mid << endl; n           break; n         } else if (n > end) n           b = mid + 1; n         else n           e = mid - 1; n       } n     } n   } else n     cout <<  -1  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct custom_hash { n   static uint64_t splitmix64(uint64_t x) { n     x += 0x9e3779b97f4a7c15; n     x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; n     x = (x ^ (x >> 27)) * 0x94d049bb133111eb; n     return x ^ (x >> 31); n   } n   size_t operator()(uint64_t x) const { n     static const uint64_t FIXED_RANDOM = n         chrono::steady_clock::now().time_since_epoch().count(); n     return splitmix64(x + FIXED_RANDOM); n   } n }; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long tc; n   cin >> tc; n   while (tc--) { n     long long n, m; n     cin >> n >> m; n     string s; n     cin >> s; n     long long arr[m]; n     for (long long i = 0; i < m; i++) cin >> arr[i]; n     long long MM = 97; n     long long dp[n + 1][26]; n     unordered_map<long long, long long, custom_hash> mp; n     for (auto ch : s) mp[ch % MM]++; n     for (long long i = 0; i < 26; i++) { n       dp[n][i] = mp[i]; n     } n     for (long long i = n - 1; i >= 1; i--) { n       long long target = s[i] % MM; n       for (long long j = 0; j < 26; j++) { n         if (target == j) { n           dp[i][j] = dp[i + 1][j] - 1; n         } else { n           dp[i][j] = dp[i + 1][j]; n         } n       } n     } n     long long res[26]; n     for (long long i = 0; i < 26; i++) { n       res[i] = dp[n][i]; n     } n     for (long long i = 0; i < m; i++) { n       long long l = arr[i]; n       for (long long j = 0; j < 26; j++) res[j] += dp[l][j]; n     } n     for (long long i = 0; i < 26; i++) cout << res[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 100; n const int mod = 1e9 + 7; n mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); n int q, n = 1000000; n long long seg[maxn * 4], lazy[maxn * 4]; n void build(int id = 1, int l = 1, int r = n) { n   if (l == r) { n     seg[id] = l; n     return; n   } n   int mid = (l + r) / 2; n   build(id * 2, l, mid); n   build(id * 2 + 1, mid + 1, r); n   seg[id] = max(seg[id * 2], seg[id * 2 + 1]); n } n void upd(int id, long long val) { n   seg[id] += val; n   lazy[id] += val; n } n void shift(int id) { n   if (!lazy[id]) return; n   upd(id * 2, lazy[id]); n   upd(id * 2 + 1, lazy[id]); n   lazy[id] = 0; n } n void modify(int first, int second, long long val, int id = 1, int l = 1, n             int r = n) { n   if (l > second || r < first) return; n   if (l >= first && r <= second) { n     upd(id, val); n     return; n   } n   shift(id); n   int mid = (l + r) / 2; n   modify(first, second, val, id * 2, l, mid); n   modify(first, second, val, id * 2 + 1, mid + 1, r); n   seg[id] = max(seg[id * 2], seg[id * 2 + 1]); n } n long long query(int first, int second, int id = 1, int l = 1, int r = n) { n   if (l > second || r < first) return 0; n   if (l >= first && r <= second) return seg[id]; n   shift(id); n   int mid = (l + r) / 2; n   return max(query(first, second, id * 2, l, mid), n              query(first, second, id * 2 + 1, mid + 1, r)); n } n long long f[maxn]; n void add(int i, long long a) { n   for (; i <= n; i += i & -i) f[i] += a; n } n long long get(int i) { n   long long ret = 0; n   for (; i > 0; i -= i & -i) ret += f[i]; n   return ret; n } n long long get(int l, int r) { return get(r) - get(l - 1); } n pair<int, int> que[300005]; n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0); n   build(); n   cin >> q; n   for (int i = 1; i <= q; i++) { n     char type; n     cin >> type; n     if (type ==  + ) { n       int pos, d; n       cin >> pos >> d; n       modify(1, pos, d); n       add(pos, d); n       que[i] = {pos, d}; n     } else if (type ==  - ) { n       int id, pos, d; n       cin >> id; n       tie(pos, d) = que[id]; n       modify(1, pos, -d); n       add(pos, -d); n     } else { n       int pos; n       cin >> pos; n       long long sum = query(1, pos); n       sum -= get(pos + 1, n); n       cout << sum - pos <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using INT = long long; n string a[111]; n int main() { n   int n; n   string s; n   cin >> s; n   cin >> n; n   int flag = 0; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     if (a[i] == s) flag |= 3; n     if (a[i][1] == s[0]) flag |= 1; n     if (a[i][0] == s[1]) flag |= 2; n   } n   if (flag == 3) return puts( YES ), 0; n   return puts( NO ), 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, a, b, res = 0, ans = 0; n int main() { n   cin >> n >> m; n   a = n % m; n   b = n / m; n   ans = (m - a) * b * (b - 1) / 2 + a * b * (b + 1) / 2; n   res = (n - m + 1) * (n - m) / 2; n   cout << ans <<     << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long double gimmearea(long double x1, long double y1, long double r1, n                       long double x2, long double y2, long double r2, n                       long double c) { n   long double t1, t2, p1, p2; n   t1 = acos((r1 * r1 + c - r2 * r2) / (2 * r1 * sqrt(c))); n   t2 = acos((r2 * r2 + c - r1 * r1) / (2 * r2 * sqrt(c))); n   p1 = sin(2 * t1); n   p2 = sin(2 * t2); n   return (r1 * r1 * t1 + r2 * r2 * t2) - 0.5 * (r1 * r1 * p1 + r2 * r2 * p2); n } n int main() { n   long double x1, y1, r1, x2, y2, r2, c, ans; n   cin >> x1 >> y1 >> r1 >> x2 >> y2 >> r2; n   c = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); n   if (c >= (r1 + r2) * (r1 + r2)) { n     ans = 0; n   } else if (sqrt(c) <= fabs(r1 - r2)) { n     if (r2 < r1) r1 = r2; n     ans = 3.14159265358979323846264338 * r1 * r1; n   } else { n     ans = gimmearea(x1, y1, r1, x2, y2, r2, c); n   } n   cout << fixed << setprecision(15); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, j, k, l, m, n, ok = 0; n   char s1[110], s2[110], ans[110]; n   scanf( %s , s1); n   scanf( %s , s2); n   l = strlen(s1); n   for (i = 0; i < l; i++) { n     if (s1[i] > s2[i]) { n       ans[i] = s2[i]; n     } else if (s1[i] < s2[i]) { n       ok = 1; n       break; n     } else n       ans[i] = s1[i]; n   } n   ans[l] =   0 ; n   if (ok) n     printf( -1 n ); n   else n     puts(ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mm = 1000000007; n const long long inf = 1e18; n long long read() { n   long long x = 0, f = 1; n   char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n vector<int> e[6005]; n int a[6005], q[6005], n, ans; n void dfs(int u, int top, int fa) { n   int pos, tmp; n   if (!top || a[u] > q[top]) { n     pos = ++top; n     tmp = q[top]; n     q[top] = a[u]; n     ans = max(ans, top); n   } else { n     pos = lower_bound(q + 1, q + 1 + top, a[u]) - q; n     tmp = q[pos]; n     q[pos] = a[u]; n   } n   for (int i = 0; i < (int)e[u].size(); i++) { n     int v = e[u][i]; n     if (v == fa) continue; n     dfs(v, top, u); n   } n   q[pos] = tmp; n } n int main() { n   n = read(); n   for (int i = 1; i <= n; i++) a[i] = read(); n   for (int i = 1; i <= n - 1; i++) { n     int x = read(), y = read(); n     e[x].push_back(y); n     e[y].push_back(x); n   } n   for (int i = 1; i <= n; i++) dfs(i, 0, 0); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n const int N = 1e5 + 7; n const int inf = INT_MAX / 2; n const long long INF = LLONG_MAX / 3; n const int MOD = 998244353; n const long double eps = 1e-6; n const pair<int, int> dir[] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; n signed main() { n   cout << fixed << setprecision(9); n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   int q; n   cin >> q; n   while (q--) { n     long long n; n     cin >> n; n     cout << (n % 4 == 0 ?  YES n  :  NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n long double eps = 1e-8; n int main() { n   int n, k; n   std::cin >> n >> k; n   std::vector<long double> probabilities(n); n   for (long double& probability : probabilities) { n     std::cin >> probability; n   } n   long long max_size = (1 << n); n   std::vector<std::vector<long double>> dp(n, n                                            std::vector<long double>(max_size)); n   std::vector<long double> result(n, 0.0); n   for (int i = 0; i < n; ++i) { n     dp[i][0] = probabilities[i]; n     result[i] += dp[i][0]; n   } n   for (int mask = 1; mask < max_size; ++mask) { n     long double mask_probability = 0; n     if (__builtin_popcount(mask) >= k) { n       continue; n     } n     for (int i = 0; i < n; ++i) { n       if (mask & (1 << i)) { n         mask_probability += probabilities[i]; n       } n     } n     for (int k = 0; k < n; ++k) { n       if (mask & (1 << k)) { n         continue; n       } n       long double sum = 0; n       for (int j = 0; j < n; ++j) { n         if (!(mask & (1 << j))) { n           continue; n         } n         sum += dp[j][mask - (1 << j)]; n       } n       if (mask_probability > 1.0 - eps) { n         sum = 0; n       } else { n         sum *= probabilities[k] / (1 - mask_probability); n       } n       dp[k][mask] = sum; n       result[k] += dp[k][mask]; n     } n   } n   std::cout.precision(20); n   std::cout << std::fixed; n   for (int i = 0; i < n; ++i) { n     std::cout << result[i] <<    ; n   } n   std::cout << std::endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int read() { n   int kkk = 0, x = 1; n   char c = getchar(); n   while ((c <  0  || c >  9 ) && c !=  - ) c = getchar(); n   if (c ==  - ) c = getchar(), x = -1; n   while (c >=  0  && c <=  9 ) n     kkk = (kkk << 3) + (kkk << 1) + (c -  0 ), c = getchar(); n   return kkk * x; n } n int n, can[200001], maxn, ans, sum[200001], a[200001], minn[400001]; n int c1[200001], c2[200001]; n void check(int v) { n   memset(c1, 0, sizeof(c1)); n   memset(c2, 0, sizeof(c2)); n   int L = 1; n   c2[0] = n; n   for (int i = 1; i <= n; ++i) { n     if (a[i] == maxn && c1[a[i]] == v) { n       while (a[L] != maxn) { n         --c2[c1[a[L]]]; n         --c1[a[L]]; n         ++c2[c1[a[L]]]; n         ++L; n       } n       ++L; n     } else { n       --c2[c1[a[i]]]; n       ++c1[a[i]]; n       ++c2[c1[a[i]]]; n     } n     if (c1[maxn] == v && c2[c1[maxn]] >= 2) ans = max(ans, i - L + 1); n   } n } n int main() { n   n = read(); n   for (int i = 1; i <= n; ++i) { n     a[i] = read(); n     ++can[a[i]]; n     if (can[a[i]] > can[maxn]) maxn = a[i]; n   } n   for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + (a[i] == maxn); n   int lim = sqrt(n); n   for (int col = 1; col <= n; ++col) { n     if (col == maxn) continue; n     if (can[col] >= lim) { n       for (int i = 1; i <= 2 * n; ++i) minn[i] = n + 1; n       minn[n] = 0; n       int sumv = 0; n       for (int i = 1; i <= n; ++i) { n         sumv += (a[i] == col); n         int v = sumv - sum[i] + n; n         ans = max(ans, i - minn[v]); n         minn[v] = min(minn[v], i); n       } n     } n   } n   for (int i = 1; i <= lim; ++i) check(i); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n using str = string; n using pi = pair<int, int>; n using pl = pair<ll, ll>; n using pd = pair<ld, ld>; n using vi = vector<int>; n using vb = vector<bool>; n using vl = vector<ll>; n using vd = vector<ld>; n using vs = vector<str>; n using vpi = vector<pi>; n using vpl = vector<pl>; n using vpd = vector<pd>; n str Tout[2] = { NO ,  YES }; n str tout[2] = { No ,  Yes }; n int main() { n   ll n, k; n   cin >> n >> k; n   ll a[n + 17]; n   for (int i = (0); i < (n); i++) cin >> a[i]; n   if (k == 2) { n     cout << max(a[0], a[n - 1]); n     return 0; n   } n   sort(a, a + n); n   if (k == 1) n     cout << a[0]; n   else n     cout << a[n - 1]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long x[100005], y[100005], q[100005], N = ((long long)1 << 40) - 1; n struct node { n   long long r, l, v, sum; n } tree[400005]; n void buildtree(int i, int l, int r) { n   tree[i].l = l; n   tree[i].r = r; n   tree[i].v = 0; n   if (tree[i].r == tree[i].l) { n     tree[i].sum = 0; n     return; n   } n   buildtree(i * 2, l, (r + l) / 2); n   buildtree(i * 2 + 1, (l + r) / 2 + 1, r); n   tree[i].sum = tree[i * 2].sum & tree[i * 2 + 1].sum; n } n void downadd(long long v) { n   tree[v * 2].v |= tree[v].v; n   tree[v * 2 + 1].v |= tree[v].v; n   tree[v * 2].sum |= tree[v].v; n   tree[v * 2 + 1].sum |= tree[v].v; n   tree[v].v = 0; n } n void update(long long i, long long l, long long r, long long k) { n   if (tree[i].l >= l && tree[i].r <= r) { n     tree[i].sum |= k; n     tree[i].v |= k; n     return; n   } n   downadd(i); n   long long m = (tree[i].l + tree[i].r) / 2; n   if (l <= m) update(i * 2, l, r, k); n   if (r > m) update(i * 2 + 1, l, r, k); n   tree[i].sum = tree[i * 2].sum & tree[i * 2 + 1].sum; n } n long long query(long long i, long long l, long long r) { n   if (tree[i].l >= l && tree[i].r <= r) { n     return tree[i].sum; n   } n   downadd(i); n   long long ans = N, m = (tree[i].r + tree[i].l) / 2; n   if (l <= m) ans &= query(i * 2, l, r); n   if (r > m) ans &= query(i * 2 + 1, l, r); n   return ans; n } n int main() { n   int n, m; n   cin >> n >> m; n   buildtree(1, 1, n); n   for (int i = 1; i <= m; i++) { n     cin >> x[i] >> y[i] >> q[i]; n     update(1, x[i], y[i], q[i]); n   } n   for (int i = 1; i <= m; i++) { n     long long v = query(1, x[i], y[i]); n     if (v != q[i]) { n       cout <<  NO  << endl; n       return 0; n     } n   } n   cout <<  YES  << endl; n   for (int i = 1; i <= n; i++) { n     cout << query(1, i, i) <<    ; n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n char op[600001]; n long long id[600001], ans[600001], s[600001]; n long long n, m, t; n bool cmp(long long x, long long y) { n   long long pa, pb; n   if (op[x] ==  L ) { n     pa = ((s[x] - t) % m + m) % m; n   } else n     pa = (s[x] + t) % m; n   if (op[y] ==  L ) { n     pb = ((s[y] - t) % m + m) % m; n   } else n     pb = (s[y] + t) % m; n   if (pa != pb) return pa < pb; n   return op[x] ==  L ; n } n long long id2[300001]; n bool cmp2(long long x, long long y) { n   if (s[x] != s[y]) { n     return s[x] < s[y]; n   } n   return op[x] ==  L ; n } n signed main() { n   cin >> n >> m >> t; n   for (long long i = 0; i < n; i++) { n     cin >> s[i] >> op[i]; n     s[i]--; n     id[i] = id2[i] = i; n   } n   sort(id, id + n, cmp); n   sort(id2, id2 + n, cmp2); n   long long pos = 0; n   if (op[0] ==  L ) { n     long long x = s[0] - t; n     for (long long i = 0; i < n; i++) n       if (op[i] ==  R ) { n         long long y = s[i] + t; n         if (s[i] > s[0]) y -= m; n         if (y < x) continue; n         pos = (pos + (y - x) / m + 1) % n; n       } n     pos = (n - pos) % n; n   } else { n     long long x = s[0] + t; n     for (long long i = 0; i < n; i++) { n       if (op[i] ==  L ) { n         long long y = s[i] - t; n         if (s[i] < s[0]) y += m; n         if (y > x) continue; n         pos = (pos + (x - y) / m + 1) % n; n       } n     } n   } n   long long p = 0; n   for (long long i = 0; i < n; i++) { n     if (id2[i] == 0) p = i; n   } n   p = (p + pos) % n; n   long long q = 0; n   for (long long i = 0; i < n; i++) { n     if (id[i] == 0) q = i; n   } n   for (long long i = 0; i < n; i++) { n     long long j = id[(q + i) % n]; n     long long x = (q + i) % n, y; n     if (op[j] ==  L ) n       y = ((s[j] - t) % m + m) % m; n     else n       y = (s[j] + t) % m; n     long long z = id2[(p + i) % n]; n     ans[z] = y + 1; n   } n   for (long long i = 0; i < n; i++) { n     cout << ans[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = (int)1e6 + 5; n long long add[N << 2], sum[N << 2], color[N << 1]; n int n, m; n void down(int rt, int len) { n   if (add[rt]) { n     add[(rt << 1)] += add[rt]; n     add[(rt << 1 | 1)] += add[rt]; n     sum[(rt << 1)] += add[rt] * (len - (len >> 1)); n     sum[(rt << 1 | 1)] += add[rt] * (len >> 1); n     add[rt] = 0; n     color[(rt << 1)] = color[(rt << 1 | 1)] = color[rt]; n     color[rt] = 0; n   } n } n void build(int rt, int l, int r) { n   if (l == r) { n     color[rt] = l; n     return; n   } n   int mid = (l + r) >> 1; n   build((rt << 1), l, mid); n   build((rt << 1 | 1), mid + 1, r); n   color[rt] = (color[(rt << 1)] == color[(rt << 1 | 1)]) ? color[(rt << 1)] : 0; n   sum[rt] = sum[(rt << 1)] + sum[(rt << 1 | 1)]; n } n void modify(int rt, int l, int r, int L, int R, int x) { n   if (L <= l && r <= R && color[rt]) { n     add[rt] += abs(color[rt] - x); n     sum[rt] += (r - l + 1) * abs(color[rt] - x); n     color[rt] = x; n     return; n   } n   down(rt, r - l + 1); n   int mid = (l + r) >> 1; n   if (L <= mid) modify((rt << 1), l, mid, L, R, x); n   if (mid < R) modify((rt << 1 | 1), mid + 1, r, L, R, x); n   color[rt] = (color[(rt << 1)] == color[(rt << 1 | 1)]) ? color[(rt << 1)] : 0; n   sum[rt] = sum[(rt << 1)] + sum[(rt << 1 | 1)]; n } n long long query(int rt, int l, int r, int L, int R) { n   if (L <= l && r <= R) { n     return sum[rt]; n   } n   down(rt, r - l + 1); n   long long t = 0ll; n   int mid = (l + r) >> 1; n   if (L <= mid) t += query((rt << 1), l, mid, L, R); n   if (mid < R) t += query((rt << 1 | 1), mid + 1, r, L, R); n   return t; n } n int main() { n   scanf( %d%d , &n, &m); n   build(1, 1, n); n   while (m--) { n     int op, l, r, x; n     scanf( %d , &op); n     if (op == 1) { n       scanf( %d%d%d , &l, &r, &x); n       modify(1, 1, n, l, r, x); n     } else { n       scanf( %d%d , &l, &r); n       printf( %I64d n , query(1, 1, n, l, r)); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long ans; n int a, b; n int main() { n   cin >> a >> b; n   int c = min(a, b); n   ans = 1; n   for (int i = 1; i <= c; i++) ans *= i; n   cout << ans; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k, i, x = 0, m, num; n   cin >> n >> k; n   map<int, int> mp; n   int arr[1000000]; n   for (i = 0; (i < n) && (x < k); i++) { n     cin >> num; n     if (mp[num] == 0) { n       arr[x] = num; n       mp[num] = 1; n       x++; n     } n   } n   int j = 0; n   for (m = i; m <= (n - 1); m++) { n     cin >> num; n     if (mp[num] == 1) { n       continue; n     } else if ((mp[num] == 0) && ((x - j) != k)) { n       arr[x] = num; n       mp[num] = 1; n       x++; n     } else { n       mp[arr[j]] = 0; n       j++; n       arr[x] = num; n       x++; n       mp[num] = 1; n     } n   } n   cout << x - j <<   n ; n   for (m = x - 1; m >= j; m--) { n     cout << arr[m] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, q; n vector<int> style; n vector<vector<int> > place; n vector<int> base; n vector<vector<int> > t; n void read() { n   cin >> n >> k; n   style.resize(n + 1); n   place.resize(100001); n   base.resize(n + 1); n   t.resize(n * 4 + 4); n   for (int i = 1; i < n + 1; i++) cin >> style[i]; n   cin >> q; n } n void build(int v, int tl, int tr) { n   if (tl == tr) { n     t[v] = vector<int>(1, base[tl]); n   } else { n     int tm = (tl + tr) / 2; n     build(v * 2, tl, tm); n     build(v * 2 + 1, tm + 1, tr); n     merge(t[v * 2].begin(), t[v * 2].end(), t[v * 2 + 1].begin(), n           t[v * 2 + 1].end(), back_inserter(t[v])); n   } n } n int query(int v, int tl, int tr, int l, int r, int x) { n   if (l > r) return 0; n   if (tl == l && tr == r) { n     vector<int>::iterator pos = lower_bound(t[v].begin(), t[v].end(), x); n     return pos - t[v].begin(); n   } else { n     int tm = (tl + tr) / 2; n     return (query(v * 2, tl, tm, l, min(tm, r), x) + n             query(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, x)); n   } n } n int main() { n   int x, y, last = 0; n   int l, r; n   read(); n   for (int i = 1; i < n + 1; i++) place[style[i]].push_back(i); n   for (int i = 1; i < 100001; i++) { n     for (int j = 0; j < place[i].size(); j++) { n       if (j >= k) n         base[place[i][j]] = place[i][j - k]; n       else n         base[place[i][j]] = -1; n     } n   } n   place.clear(); n   style.clear(); n   build(1, 1, n); n   while (q--) { n     cin >> x >> y; n     l = ((x + last) % n) + 1; n     r = ((y + last) % n) + 1; n     if (l > r) swap(l, r); n     last = query(1, 1, n, l, r, l); n     cout << last << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(void) { n   char a; n   int k = 0; n   vector<int> s; n   while (1) { n     cin >> a >> a; n     k++; n     if (a ==  + ) n       s.push_back(1); n     else if (a ==  - ) n       s.push_back(-1); n     else n       break; n   } n   int n; n   cin >> n; n   int plus = 0, minus = 0; n   for (int i = 0; i < k - 1; i++) { n     if (s[i] == 1) n       plus++; n     else n       minus++; n   } n   if (minus > n * plus || plus + 1 > n * (minus + 1)) { n     cout <<  Impossible  << endl; n     return 0; n   } n   if (plus + 1 > n + minus) { n     cout <<  Possible  << endl; n     int x = n + n * minus - plus - 1; n     if (x > n - 1) { n       cout << n; n       x -= (n - 1); n     } else { n       cout << x + 1; n       x = 0; n     } n     for (int i = 0; i < k - 1; i++) { n       if (s[i] == 1) { n         cout <<   +  ; n         if (x > n - 1) { n           cout << n; n           x -= (n - 1); n         } else { n           cout << x + 1; n           x = 0; n         } n       } else { n         cout <<   -   << n; n       } n     } n     cout <<   =   << n << endl; n     return 0; n   } n   cout <<  Possible  << endl; n   int x = n + minus - plus - 1; n   if (x > n - 1) { n     cout << n; n     x -= (n - 1); n   } else { n     cout << x + 1; n     x = 0; n   } n   for (int i = 0; i < k - 1; i++) { n     if (s[i] == 1) { n       cout <<   +  ; n       if (x > n - 1) { n         cout << n; n         x -= (n - 1); n       } else { n         cout << x + 1; n         x = 0; n       } n     } else { n       cout <<   - 1 ; n     } n   } n   cout <<   =   << n << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 545; n int a[MAX_N]; n int main() { n   int n, minus = 0; n   cin >> n; n   int sum = 0; n   for (int i = (0); i < (int)(2 * n - 1); ++i) { n     cin >> a[i]; n     if (a[i] < 0) { n       a[i] = abs(a[i]); n       minus++; n     } n     sum += a[i]; n   } n   sort(a, a + (2 * n) - 1); n   if (n % 2 == 0 && minus % 2) sum -= (a[0] * 2); n   cout << sum << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 1000000007; n const int MM = 998244353; n template <typename T, typename U> n static inline void amin(T &x, U y) { n   if (y < x) x = y; n } n template <typename T, typename U> n static inline void amax(T &x, U y) { n   if (x < y) x = y; n } n map<int, map<int, pair<int, int>>> mask; n int _runtimeTerror_() { n   int n; n   cin >> n; n   vector<long long> b(n); n   vector<int> even, odd; n   set<int> s; n   for (int i = 0; i < n; ++i) { n     cin >> b[i]; n     if (!s.count(b[i])) { n       if (b[i] & 1) { n         odd.push_back(b[i]); n       } else { n         even.push_back(b[i]); n       } n     } n     s.insert(b[i]); n   } n   if ((long long)s.size() < n) { n     vector<int> ans(n, 1e8); n     ans[0] = 0; n     s.clear(); n     int cur = 1; n     for (int i = 0; i < n; ++i) { n       if (s.count(b[i])) { n         continue; n       } n       ans[cur] = b[i]; n       ++cur; n       s.insert(b[i]); n     } n     cout <<  YES n ; n     for (int i = 0; i < n; ++i) { n       cout << ans[i] <<    ; n     } n     cout <<   n ; n     return 0; n   } n   if (n == 2) { n     cout <<  NO n ; n     return 0; n   } n   if (n == 3) { n     int sum = b[0] + b[1] + b[2]; n     if (sum % 2) { n       cout <<  NO n ; n       return 0; n     } n     sum /= 2; n     cout <<  YES n ; n     cout << sum - b[0] <<     << sum - b[1] <<     << sum - b[2] <<   n ; n     return 0; n   } n   assert(n >= 4); n   if (even.empty()) { n     int nn = min(n, 24); n     vector<int> left, right; n     for (int i = 0; i < (nn + 1) / 2; ++i) { n       left.push_back(b[i]); n     } n     for (int i = 0; i < nn / 2; ++i) { n       right.push_back(b[nn - 1 - i]); n     } n     reverse(right.begin(), right.end()); n     int tmp = (long long)right.size(); n     assert((long long)left.size() + (long long)right.size() == nn); n     mask[0][0] = {0, 0}; n     for (int i = 0; i < (1 << tmp); ++i) { n       for (int j = i; j; j = (j - 1) & i) { n         int val = 0, f = 0; n         for (int k = 0; k < tmp; ++k) { n           if ((i & (1 << k)) && ((j & (1 << k)) == 0)) { n             val += right[k]; n             ++f; n           } else if (i & (1 << k)) { n             val -= right[k]; n             --f; n           } n         } n         mask[f][val] = {i, j}; n       } n     } n     tmp = (long long)left.size(); n     pair<int, int> ans = {-1, -1}; n     if (mask[0][0].first != 0) { n       ans = mask[0][0]; n       ans.first <<= tmp; n       ans.second <<= tmp; n     } n     for (int i = 0; i < (1 << tmp); ++i) { n       if (ans.first != -1) { n         break; n       } n       for (int j = i; j; j = (j - 1) & i) { n         int val = 0, f = 0; n         for (int k = 0; k < tmp; ++k) { n           if ((i & (1 << k)) && ((j & (1 << k)) == 0)) { n             val += left[k]; n             ++f; n           } else if (i & (1 << k)) { n             val -= left[k]; n             --f; n           } n         } n         if (mask.count(-f) && mask[-f].count(-val)) { n           ans = mask[-f][-val]; n           ans.first <<= tmp; n           ans.second <<= tmp; n           ans.first |= i; n           ans.second |= j; n           break; n         } n       } n       if (ans.first != -1) { n         break; n       } n     } n     if (ans.first == -1) { n       cout <<  NO n ; n       return 0; n     } n     assert(__builtin_popcountll(ans.first) == n            2 * __builtin_popcountll(ans.second)); n     vector<int> lx, rx, tt; n     for (int i = 0; i < nn; ++i) { n       if ((ans.first & (1 << i)) && (ans.second & (1 << i))) { n         rx.push_back(b[i]); n       } else if (ans.first & (1 << i)) { n         lx.push_back(b[i]); n       } else { n         tt.push_back(b[i]); n       } n     } n     assert((long long)lx.size() == (long long)rx.size()); n     cout <<  YES n ; n     int cur = 0; n     for (int i = 0; i < (long long)lx.size(); ++i) { n       cout << lx[i] - cur <<    ; n       cur = lx[i] - cur; n       cout << rx[i] - cur <<    ; n       cur = rx[i] - cur; n     } n     for (auto &j : tt) { n       cout << j - cur <<    ; n     } n     for (int i = nn; i < n; ++i) { n       cout << b[i] - cur <<    ; n     } n     cout <<   n ; n     return 0; n   } n   vector<int> t; n   int cnt = min(3ll, (long long)even.size()); n   for (int i = 0; i < cnt; ++i) { n     t.push_back(even.back()); n     even.pop_back(); n   } n   if ((long long)t.size() % 2 == 0) { n     even.push_back(t.back()); n     t.pop_back(); n   } n   while ((long long)t.size() < 3) { n     t.push_back(odd.back()); n     odd.pop_back(); n   } n   int sum = accumulate(t.begin(), t.end(), 0); n   assert(sum % 2 == 0); n   cout <<  YES n ; n   sum /= 2; n   cout << sum - t[0] <<     << sum - t[1] <<     << sum - t[2] <<    ; n   for (int i : even) { n     cout << i - (sum - t[0]) <<    ; n   } n   for (int i : odd) { n     cout << i - (sum - t[0]) <<    ; n   } n   return 0; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int TESTS = 1; n   while (TESTS--) _runtimeTerror_(); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const long long N_MAX = 1123; n const long long MOD = 998244353; n long long w; n long long h; n long long result = 1; n int main() { n   ios_base::sync_with_stdio(0); n   cin >> w; n   cin >> h; n   for (long long i = 1; i <= w; i++) { n     for (long long j = 1; j <= h; j++) { n       if (i == 1 && j == 1) { n         result *= 4; n       } else if (i == 1) { n         result *= 2; n       } else if (j == 1) { n         result *= 2; n       } n       result %= MOD; n     } n   } n   cout << result <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> g[100005]; n bool vis[100005]; n long long min_val; n void dfs(int v, long long* arr) { n   min_val = min(arr[v], min_val); n   vis[v] = true; n   for (int i = 0; i < g[v].size(); i++) { n     int neig = g[v][i]; n     if (!vis[neig]) { n       dfs(neig, arr); n     } n   } n } n int main() { n   std::ios::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   int n, m, x, y; n   cin >> n >> m; n   long long* v = new long long[n + 1](); n   for (int i = 1; i <= n; i++) { n     cin >> v[i]; n   } n   for (int i = 0; i < m; i++) { n     cin >> x >> y; n     g[x].push_back(y); n     g[y].push_back(x); n   } n   long long ans = 0; n   memset(vis, false, sizeof(vis)); n   for (int i = 1; i <= n; i++) { n     if (!vis[i]) { n       min_val = LONG_MAX; n       dfs(i, v); n       ans += min_val; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5; n int ans, n, m, k, a[12]; n struct Edge { n   int to, t; n   Edge() { to = t = 0; } n   Edge(int _to, int _t) { n     to = _to; n     t = _t; n   } n   bool operator<(const Edge &z) const { return t < z.t; } n }; n vector<Edge> vec[N]; n int d[N][12][12]; n bool vis[12][12][12][12]; n inline void dfs(int x) { n   if (k + 1 == x) { n     for (int i = 1; i <= k; i++) n       for (int j = 1; j <= k; j++) n         if (vis[i][a[i]][j][a[j]]) return; n     ans++; n     return; n   } n   for (int i = 1; i <= x; i++) a[x] = i, dfs(x + 1); n } n int main() { n   scanf( %d%d%d , &n, &m, &k); n   int s, e, t; n   for (int i = 1; i <= m; i++) n     scanf( %d%d%d , &s, &e, &t), vec[s].push_back(Edge(e, t)); n   for (int i = 1; i <= n; i++) { n     sort(vec[i].begin(), vec[i].end()); n     for (int j = 0; j < vec[i].size(); j++) n       d[vec[i][j].to][vec[i].size()][j + 1]++; n   } n   for (int i = 1; i <= n; i++) n     for (int j = 0; j < vec[i].size(); j++) n       for (int t = 1; t <= k; t++) n         for (int l = 1; l <= k; l++) n           if (d[vec[i][j].to][t][l]) { n             if (t ^ vec[i].size()) n               vis[vec[i].size()][j + 1][t][l] = 1; n             else if (d[vec[i][j].to][t][l] > 1) n               vis[vec[i].size()][j + 1][t][l] = 1; n           } n   dfs(1); n   return printf( %d n , ans), 0; n } n


#include <bits/stdc++.h> n using namespace std; n priority_queue<pair<int, int> > a; n priority_queue<pair<int, int> > b; n vector<pair<int, int> > A; n vector<pair<int, int> > B; n int main() { n   int n, x; n   scanf( %d%d , &n, &x); n   int x0 = x; n   for (int i = 0; i < n; i++) { n     int t; n     int h, m; n     scanf( %d%d%d , &t, &h, &m); n     if (t == 0) n       A.push_back(pair<int, int>(h, m)); n     else n       B.push_back(pair<int, int>(h, m)); n   } n   int pa = 0, push_back = 0; n   sort(A.begin(), A.end()); n   sort(B.begin(), B.end()); n   int ans = 0; n   while (pa < A.size() && A[pa].first <= x) n     a.push(pair<int, int>(A[pa].second, A[pa].first)), pa++; n   while (push_back < B.size() && B[push_back].first <= x) n     b.push(pair<int, int>(B[push_back].second, B[push_back].first)), n         push_back++; n   int nn = 0; n   int cur = 0; n   while (nn < 2) { n     pair<int, int> k; n     if (cur == 0) { n       if (a.size() == 0) { n         nn++; n         continue; n       } n       k = a.top(); n       a.pop(); n     } n     if (cur == 1) { n       if (b.size() == 0) { n         nn++; n         continue; n       } n       k = b.top(); n       b.pop(); n     } n     x += k.first; n     ans++; n     while (pa < A.size() && A[pa].first <= x) n       a.push(pair<int, int>(A[pa].second, A[pa].first)), pa++; n     while (push_back < B.size() && B[push_back].first <= x) n       b.push(pair<int, int>(B[push_back].second, B[push_back].first)), n           push_back++; n     cur ^= 1; n     nn = 0; n   } n   int ans2 = 0; n   cur = 1; n   nn = 0; n   while (a.size()) a.pop(); n   while (b.size()) b.pop(); n   pa = push_back = 0; n   x = x0; n   while (pa < A.size() && A[pa].first <= x) n     a.push(pair<int, int>(A[pa].second, A[pa].first)), pa++; n   while (push_back < B.size() && B[push_back].first <= x) n     b.push(pair<int, int>(B[push_back].second, B[push_back].first)), n         push_back++; n   while (nn < 2) { n     pair<int, int> k; n     if (cur == 0) { n       if (a.size() == 0) { n         nn++; n         continue; n       } n       k = a.top(); n       a.pop(); n     } n     if (cur == 1) { n       if (b.size() == 0) { n         nn++; n         continue; n       } n       k = b.top(); n       b.pop(); n     } n     x += k.first; n     ans2++; n     while (pa < A.size() && A[pa].first <= x) n       a.push(pair<int, int>(A[pa].second, A[pa].first)), pa++; n     while (push_back < B.size() && B[push_back].first <= x) n       b.push(pair<int, int>(B[push_back].second, B[push_back].first)), n           push_back++; n     cur ^= 1; n     nn = 0; n   } n   printf( %d n , max(ans, ans2)); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, q, num; n   cin >> n >> q; n   vector<int> a(n), b(n), c(n); n   for (int i = 0; i < n; ++i) cin >> a[i]; n   b[0] = a[0]; n   for (int i = 1; i < n; ++i) { n     b[i] = max(a[i], b[i - 1]); n     if (b[i] == a[i]) n       c[i - 1] = b[i - 1]; n     else n       c[i - 1] = a[i]; n   } n   while (q--) { n     cin >> num; n     if (num < n) n       cout << b[num - 1] <<     << a[num] << endl; n     else n       cout << b[n - 1] <<     << c[(num - 1) % (n - 1)] << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n using uint = unsigned int; n using ll = long long; n using ull = unsigned long long; n template <class T = ll> n constexpr T TEN(int n) { n   return (n == 0) ? 1 : 10 * TEN<T>(n - 1); n } n ll calc(string s) { n   int n = int(s.size()); n   if (n == 1) { n     if (s[0] ==  9 ) { n       return 1989; n     } else { n       return 1990 + s[0] -  0 ; n     } n   } n   ll u = calc(s.substr(1)); n   u += TEN(n - 1); n   while (true) { n     if (u / TEN(n - 1) % 10 == s[0] -  0 ) break; n     u += TEN(n - 1); n   } n   return u; n } n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     string s; n     cin >> s; n     s = s.substr(4); n     cout << calc(s) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     long long int n; n     cin >> n; n     long long int mn = 0; n     for (int i = 1; i <= n; i++) { n       long long int temp; n       cin >> temp; n       mn = max(mn, (temp - i)); n     } n     cout << mn << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 10; n int k, a[N], b[N]; n char s[N], t[N]; n int main() { n   cin >> k; n   scanf( %s , s + 1); n   scanf( %s , t + 1); n   for (int i = k; i; i--) { n     a[i] = t[i] - s[i]; n     if (a[i] < 0) { n       a[i] += 26; n       t[i - 1]--; n     } n   } n   for (int i = 1; i <= k; i++) { n     a[i + 1] += (a[i] % 2) * 26; n     a[i] /= 2; n   } n   for (int i = k; i; i--) { n     b[i] += s[i] -  a  + a[i]; n     b[i - 1] += b[i] / 26; n     b[i] %= 26; n   } n   for (int i = 1; i <= k; i++) printf( %c ,  a  + b[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool myfunction(int i, int j) { return (i < j); } n int main() { n   int n, a, b, h; n   cin >> n >> a >> b; n   vector<int> myvector(n); n   for (int i = 0; i < n; ++i) { n     cin >> h; n     myvector.at(i) = h; n   } n   sort(myvector.begin(), myvector.end(), myfunction); n   cout << myvector.at(b) - myvector.at(b - 1) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mxN = 5005; n deque<deque<int> > Painter(mxN); n vector<bool> Painted(mxN); n vector<vector<int> > cnt(mxN, vector<int>(mxN, 0)); n int main() { n   int n, q; n   cin >> n >> q; n   for (int i = 0; i < q; i++) { n     int l, r; n     cin >> l >> r; n     for (int j = l; j <= r; j++) { n       if ((int)Painter[j].size() < 3) { n         Painter[j].push_back(i); n       } n       Painted[j] = true; n     } n   } n   int total_sections = 0; n   for (int i = 1; i <= n; i++) { n     total_sections += (Painted[i] == true); n   } n   for (int i = 1; i <= n; i++) { n     if ((int)Painter[i].size() == 3 || (int)Painter[i].size() == 0) { n       continue; n     } n     assert((int)Painter[i].size() < 3); n     if ((int)Painter[i].size() == 1) { n       for (int j = 0; j < q; j++) { n         if (j == Painter[i].back()) { n           continue; n         } n         cnt[Painter[i].back()][j]++; n         cnt[j][Painter[i].back()]++; n       } n     } else { n       cnt[Painter[i].back()][Painter[i].front()]++; n       cnt[Painter[i].front()][Painter[i].back()]++; n     } n   } n   int Min = 1e9; n   for (int i = 0; i < q; i++) { n     for (int j = i + 1; j < q; j++) { n       Min = min(Min, cnt[i][j]); n     } n   } n   assert(Min != 1e9); n   cout << total_sections - Min <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n const long long int INF = (1e9 + 12312), MOD = 1e9 + 7; n const long double EPS = 0.0000000001; n using namespace std; n vector<pair<long long int, long long int> > a; n pair<long long int, pair<long long int, long long int> > l(long long int x, n                                                            long long int y) { n   long long int x1, x2, y1, y2; n   x1 = a[x].first; n   x2 = a[y].first; n   y1 = a[x].second; n   y2 = a[y].second; n   long long int a = y2 - y1; n   long long int b = x1 - x2; n   long long int c = x2 * y1 - x1 * y2; n   return make_pair(a, make_pair(b, c)); n } n bool can(long long int x, long long int y) { n   auto ff = l(x, y); n   long long int a1, b1, c1; n   a1 = ff.first; n   b1 = ff.second.first; n   c1 = ff.second.second; n   vector<long long int> rer; n   for (long long int i = 0; i < (long long int)a.size(); i++) { n     if (a1 * a[i].first + b1 * a[i].second + c1 != 0) { n       rer.push_back(i); n     } n   } n   if ((long long int)rer.size() < 3) { n     return 1; n   } n   auto f2 = l(rer[0], rer[1]); n   long long int a2, b2, c2; n   a2 = f2.first; n   b2 = f2.second.first; n   c2 = f2.second.second; n   for (long long int i = 0; i < (long long int)a.size(); i++) { n     if (a1 * a[i].first + b1 * a[i].second + c1 != 0) { n       if (a2 * a[i].first + b2 * a[i].second + c2 != 0) { n         return 0; n       } n     } n   } n   return 1; n } n int main() { n   long long int n; n   cin >> n; n   if (n < 3) { n     cout <<  YES n ; n     return 0; n   } n   for (long long int i = 0; i < n; i++) { n     long long int x, y; n     cin >> x >> y; n     a.push_back(make_pair(x, y)); n   } n   if (can(0, 1)) { n     cout <<  YES n ; n     return 0; n   } n   if (can(1, 2)) { n     cout <<  YES n ; n     return 0; n   } n   if (can(0, 2)) { n     cout <<  YES n ; n     return 0; n   } n   cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n const double PI = 3.14159265359; n int oneCt = 0, n; n class File { n  public: n   string name; n   int type; n   bool isNum; n   int numVal; n   File(string _name, int _type) : name(_name), type(_type), isNum(true) { n     int sz = name.size(); n     string s = name; n     numVal = 0; n     if (s[0] ==  0 ) { n       isNum = false; n     } else { n       for (int i = sz - 1, mult = 1; i >= 0; i--, mult *= 10) { n         if (s[i] >=  0  && s[i] <=  9 ) { n           numVal += mult * (s[i] -  0 ); n         } else { n           isNum = false; n         } n       } n     } n   } n }; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   vector<bool> avail(n + 1, true); n   vector<File> files; n   for (int i = 0; i < n; i++) { n     int x; n     string s; n     cin >> s >> x; n     oneCt += x; n     File f(s, x); n     files.push_back(f); n   } n   vector<File> ob, zb; n   for (auto f : files) { n     if (f.isNum) { n       int nv = f.numVal; n       if (nv <= n) avail[nv] = false; n       if (nv > oneCt && f.type) n         ob.push_back(f); n       else if (!f.type && (nv <= oneCt || nv > n)) { n         zb.push_back(f); n       } n     } else if (f.type) n       ob.push_back(f); n     else n       zb.push_back(f); n   } n   vector<string> operations; n   queue<File> qob, qob2, qzb, qzb2; n   for (auto f : ob) { n     if (f.isNum && f.numVal > oneCt && f.numVal <= n) { n       qob.push(f); n     } else { n       qob2.push(f); n     } n   } n   while (qob2.size()) { n     qob.push(qob2.front()); n     qob2.pop(); n   } n   for (auto f : zb) { n     if (f.isNum && f.numVal <= oneCt) { n       qzb.push(f); n     } else { n       qzb2.push(f); n     } n   } n   while (qzb2.size()) { n     qzb.push(qzb2.front()); n     qzb2.pop(); n   } n   stack<int> oneAvail, zeroAvail; n   for (int i = 1; i <= n; i++) { n     if (i <= oneCt && avail[i]) n       oneAvail.push(i); n     else if (i > oneCt && avail[i]) n       zeroAvail.push(i); n   } n   while (qob.size() || qzb.size()) { n     if (qob.size() && oneAvail.size()) { n       auto f = qob.front(); n       if (f.isNum && f.numVal <= n) { n         zeroAvail.push(f.numVal); n       } n       string s =  move  ; n       s += f.name; n       s +=    ; n       s += to_string(oneAvail.top()); n       operations.push_back(s); n       qob.pop(); n       oneAvail.pop(); n     } else if (qzb.size() && zeroAvail.size()) { n       auto f = qzb.front(); n       if (f.isNum && f.numVal <= oneCt) { n         oneAvail.push(f.numVal); n       } n       string s =  move  ; n       s += f.name; n       s +=    ; n       s += to_string(zeroAvail.top()); n       operations.push_back(s); n       qzb.pop(); n       zeroAvail.pop(); n     } else { n       auto f = qob.front(); n       if (f.isNum && f.numVal <= n) { n         zeroAvail.push(f.numVal); n       } n       string s =  move  ; n       s += f.name; n       s +=   aaaaaa ; n       operations.push_back(s); n       f.name =  aaaaaa ; n       f.isNum = false; n       qob.pop(); n       qob.push(f); n     } n   } n   cout << operations.size() << endl; n   for (string s : operations) { n     cout << s << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long ans = 1e18; n vector<char> ops; n void solve(vector<long long> a, int pos) { n   if (pos == 3) { n     ans = min(ans, a[0]); n     return; n   } n   for (int i = 0; i < (int)(a).size(); ++i) { n     for (int j = i + 1; j < (int)(a).size(); ++j) { n       long long val = a[i]; n       if (ops[pos] ==  * ) { n         val *= a[j]; n       } else { n         val += a[j]; n       } n       vector<long long> b; n       for (int k = 0; k < (int)(a).size(); ++k) { n         if (i == k || j == k) { n           continue; n         } n         b.push_back(a[k]); n       } n       b.push_back(val); n       solve(b, pos + 1); n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   vector<long long> a(4); n   for (int i = 0; i < 4; ++i) { n     cin >> a[i]; n   } n   for (int i = 0; i < 3; ++i) { n     char c; n     cin >> c; n     ops.push_back(c); n   } n   solve(a, 0); n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n long long INF = 9999999999; n double EPSILON = 0.00000001; n int sint(string s) { n   int num = 0; n   istringstream myStream(s); n   (myStream >> num); n   return num; n } n string str(int num) { n   ostringstream oss; n   oss << num; n   return oss.str(); n } n vector<string> split(string s) { n   vector<string> tokens; n   stringstream os(s); n   string temp; n   while (os >> temp) { n     tokens.push_back(temp); n   } n   return tokens; n } n int maxv(vector<int> v) { n   int m = -9999999; n   for (int i = 0; i < v.size(); i++) m = max(m, v[i]); n   return m; n } n int minv(vector<int> v) { n   int m = 9999999; n   for (int i = 0; i < v.size(); i++) m = min(m, v[i]); n   return m; n } n int main() { n   long long n; n   cin >> n; n   long long s = 0; n   while (n != 1) { n     s += n; n     long long root = sqrt(n); n     bool found = false; n     for (long long r = 2; r <= root; r++) { n       if (n % r == 0) { n         n /= r; n         found = true; n         break; n       } n     } n     if (not found) n = 1; n   } n   cout << s + 1 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char str[100005]; n char notValid[15] = { B ,  C ,  D ,  E ,  F ,  G ,  J ,  K , n                       L ,  N ,  P ,  Q ,  R ,  S ,  Z }; n bool valid(char c) { n   static int i; n   for (i = 0; i < 15; ++i) n     if (c == notValid[i]) return false; n   return true; n } n bool check(char *s) { n   int i; n   int len = strlen(s); n   int lend2 = len / 2; n   for (i = 0; i < lend2; ++i) { n     if (!valid(s[i]) || !valid(s[len - i - 1]) || (s[i] != s[len - i - 1])) n       return false; n   } n   if (len & 1) return valid(s[lend2]); n   return true; n } n int main(void) { n   int i; n   while (scanf( %s , str) == 1) { n     printf( %s n , check(str) ?  YES  :  NO ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline char gc() { n   static char buf[100000], *p1 = buf, *p2 = buf; n   return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) n              ? EOF n              : *p1++; n } n inline int read() { n   int x = 0; n   char ch = getchar(); n   bool positive = 1; n   for (; !isdigit(ch); ch = getchar()) n     if (ch ==  - ) positive = 0; n   for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ; n   return positive ? x : -x; n } n inline void write(int a) { n   if (a >= 10) write(a / 10); n   putchar( 0  + a % 10); n } n inline void writeln(int a) { n   if (a < 0) { n     a = -a; n     putchar( - ); n   } n   write(a); n   puts(  ); n } n const int N = 200005, oo = 1e9; n int ans[N], fa[N]; n pair<pair<int, int>, int> a[N]; n int nedge, wson[N], ed[N], nextt[N], son[N], tree[N << 2], lazy[N << 2], peo[N], n     deep[N], ti, n, m, pos[N], father[N], in[N], top[N]; n inline void aedge(int a, int b) { n   nextt[++nedge] = son[a]; n   son[a] = nedge; n   ed[nedge] = b; n } n inline void cao(int nod, int r, int x) { n   tree[nod] = x + deep[pos[r]] * 2; n   lazy[nod] = x; n } n inline void pushdown(int nod, int l, int r) { n   if (lazy[nod] == -oo) return; n   int mid = (l + r) >> 1; n   cao(nod << 1, mid, lazy[nod]); n   cao(nod << 1 | 1, r, lazy[nod]); n   lazy[nod] = -oo; n } n inline int ask(int l, int r, int i, int j, int s, int nod) { n   if (l > 1 && tree[nod] <= s) return 0; n   if (l == r) return pos[l]; n   pushdown(nod, l, r); n   int mid = (l + r) >> 1; n   if (j <= mid) n     return ask(l, mid, i, j, s, nod << 1); n   else if (i > mid) n     return ask(mid + 1, r, i, j, s, nod << 1 | 1); n   int t = ask(mid + 1, r, mid + 1, j, s, nod << 1 | 1); n   if (t) return t; n   return ask(l, mid, i, mid, s, nod << 1); n } n inline void insert(int l, int r, int i, int j, int s, int nod) { n   if (l == i && r == j) { n     lazy[nod] = s; n     cao(nod, r, s); n     return; n   } n   pushdown(nod, l, r); n   int mid = (l + r) >> 1; n   if (j <= mid) n     insert(l, mid, i, j, s, nod << 1); n   else if (i > mid) n     insert(mid + 1, r, i, j, s, nod << 1 | 1); n   else { n     insert(l, mid, i, mid, s, nod << 1); n     insert(mid + 1, r, mid + 1, j, s, nod << 1 | 1); n   } n   tree[nod] = max(tree[nod << 1], tree[nod << 1 | 1]); n } n void dfs1(int p) { n   peo[p] = 1; n   wson[p] = -1; n   for (int i = son[p]; i; i = nextt[i]) { n     deep[ed[i]] = deep[p] + 1; n     dfs1(ed[i]); n     peo[p] += peo[ed[i]]; n     if (wson[p] == -1 || peo[ed[i]] > peo[wson[p]]) wson[p] = ed[i]; n   } n } n void dfs2(int p) { n   pos[in[p] = ++ti] = p; n   if (p == wson[father[p]]) n     top[p] = top[father[p]]; n   else n     top[p] = p; n   if (wson[p] != -1) dfs2(wson[p]); n   for (int i = son[p]; i; i = nextt[i]) n     if (ed[i] != wson[p]) dfs2(ed[i]); n } n inline bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) { n   return a.first.second + deep[a.first.first] == n                  b.first.second + deep[b.first.first] n              ? a.first.first < b.first.first n              : a.first.second + deep[a.first.first] < n                    b.first.second + deep[b.first.first]; n } n void update(int u, int v, int x) { n   while (top[u] != top[v]) { n     insert(1, n, in[top[u]], in[u], x, 1); n     u = father[top[u]]; n   } n   if (u != v) insert(1, n, in[v] + 1, in[u], x, 1); n } n int query(int u, int t) { n   int ans = deep[u] + t; n   while (1) { n     int t = ask(1, n, in[top[u]], in[u], ans, 1); n     if (t) return t; n     u = father[top[u]]; n   } n } n int main() { n   n = read() + 1; n   m = read(); n   for (int i = 1; i < (N << 2); i++) lazy[i] = -oo; n   for (int i = 2; i <= n; i++) { n     deep[i] = deep[father[i] = read() + 1] + 1; n     aedge(father[i], i); n   } n   dfs1(1); n   dfs2(1); n   for (int i = 1; i <= m; i++) { n     a[i].first.first = read() + 1; n     a[i].first.second = read(); n     a[i].second = i; n   } n   sort(&a[1], &a[m + 1], cmp); n   for (int i = 1; i <= m; i++) { n     int t = query(a[i].first.first, a[i].first.second); n     ans[a[i].second] = n         a[i].first.second + (deep[a[i].first.first] - deep[t]) * 2; n     update(a[i].first.first, t, ans[a[i].second] - deep[a[i].first.first]); n   } n   for (int i = 1; i <= m; i++) write(ans[i]), putchar(   ); n } n


#include <bits/stdc++.h> n using namespace std; n const int mv4[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; n const int mv8[8][2] = {{0, 1}, {0, -1}, {1, 0},  {-1, 0}, n                        {1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; n const int inf = (int)1e9; n const char *boo[2] = { NO ,  YES }; n const char *inv =  Impossible ; n inline void term(string msg = inv) { n   cout << msg << endl; n   exit(0); n } n const char *in =  in.txt ; n const char *out =  out.txt ; n struct Point { n   long long y, x; n   Point(long long y = 0, long long x = 0) : y(y), x(x) {} n   Point operator-(const Point &a) { return Point(y - a.y, x - a.x); } n }; n inline unsigned long long sq(long long d) { return d * d; } n inline unsigned long long sqdist(const Point &a, const Point &b) { n   return sq(a.x - b.x) + sq(a.y - b.y); n } n inline long long dot(const Point &a, const Point &b) { n   return a.x * b.x + a.y * b.y; n } n const int MAX = 1000; n int main() { n   cin.sync_with_stdio(0); n   cout.sync_with_stdio(0); n   int n; n   unsigned long long r = 0; n   cin >> n; n   vector<Point> v(n); n   unordered_map<int, int> dup, ddown; n   for (int i = 0; i < n; i++) { n     cin >> v[i].x >> v[i].y; n     dup[v[i].y - v[i].x]++; n     ddown[v[i].y + v[i].x]++; n   } n   for (auto e : dup) { n     unsigned long long t = (e.second * (e.second - 1)) / 2; n     r += t; n   } n   for (auto e : ddown) { n     unsigned long long t = (e.second * (e.second - 1)) / 2; n     r += t; n   } n   cout << r <<   n ; n   exit(0); n } n


#include <bits/stdc++.h> n bool commonDigits(long a, long b) { n   bool digits[10] = {0}; n   bool output(0); n   while (a > 0) { n     digits[a % 10] = 1; n     a /= 10; n   } n   while (b > 0) { n     if (digits[b % 10]) { n       output = 1; n       break; n     }; n     b /= 10; n   } n   return output; n } n int main() { n   long n(0); n   scanf( %ld , &n); n   long total(0); n   std::vector<long> divisors; n   for (long k = 1; k <= sqrt(n); k++) { n     if (n % k == 0) { n       divisors.push_back(k); n       if (n / k > k) { n         divisors.push_back(n / k); n       } n     } n   } n   for (long k = 0; k < divisors.size(); k++) { n     if (commonDigits(n, divisors[k])) { n       ++total; n     } n   } n   printf( %ld n , total); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1000002; n long long memo[MAXN]; n long long cost[MAXN]; n int tin[MAXN]; n int low[MAXN]; n bool in_stack[MAXN]; n int Stack[MAXN]; n int comp[MAXN]; n vector<pair<int, int> > g[MAXN]; n vector<pair<int, int> > t[MAXN]; n int n, m, s; n int u, v, w; n int SCC, T, top; n void fast_io() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n } n long long contrib(int o) { n   int lo = 0, hi = o; n   int n = -1; n   while (lo <= hi) { n     int mid = (lo + hi) >> 1; n     if (1LL * mid * (mid + 1) <= (o << 1)) n       n = mid, lo = mid + 1; n     else n       hi = mid - 1; n   } n   return 1LL * o * (n + 1) - 1LL * n * (n + 1) * (n + 2) / 6; n } n void tarjan(int u) { n   low[u] = tin[u] = ++T; n   Stack[top++] = u, in_stack[u] = 1; n   for (auto v : g[u]) { n     if (!tin[v.first]) tarjan(v.first); n     if (in_stack[v.first]) low[u] = min(low[u], low[v.first]); n   } n   if (tin[u] == low[u]) { n     ++SCC; n     while (top) { n       int v = Stack[--top]; n       in_stack[v] = 0, comp[v] = SCC; n       if (u == v) break; n     } n   } n } n long long solve(int u) { n   if (memo[u] != -1) return memo[u]; n   long long res = cost[u]; n   for (auto v : t[u]) { n     res = max(res, cost[u] + v.second + solve(v.first)); n   } n   return memo[u] = res; n } n int main() { n   fast_io(); n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     cin >> u >> v >> w; n     g[u].push_back(make_pair(v, w)); n   } n   cin >> s; n   tarjan(s); n   for (int i = 1; i <= n; i++) { n     if (!tin[i]) continue; n     int u = comp[i]; n     for (auto v : g[i]) { n       int to = comp[v.first]; n       if (u != to) n         t[u].push_back(make_pair(to, v.second)); n       else n         cost[u] += contrib(v.second); n     } n   } n   memset(memo, -1, sizeof(memo)); n   printf( %lld n , solve(comp[s])); n   return 0; n } n


#include <bits/stdc++.h> n char buf[1 << 21], *p1 = buf, *p2 = buf; n inline long long read() { n   long long ret = 0, ff = 1; n   char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) ff = -ff; n     ch = getchar(); n   } n   while (isdigit(ch)) { n     ret = (ret << 3) + (ret << 1) + ch -  0 ; n     ch = getchar(); n   } n   return ret * ff; n } n long long p, q, b; n long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); } n inline long long ksm(long long a, long long b) { n   long long res = 1, base = a; n   while (b) { n     if (b & 1) { n       res = (res * base) % q; n       if (res == 0) return 0; n     } n     base = (base * base) % q; n     b >>= 1; n   } n   return res; n } n int main() { n   int T = read(); n   while (T--) { n     p = read(), q = read(), b = read(); n     long long g = gcd(p, q); n     p /= g; n     q /= g; n     if (q == 1ll) { n       printf( Finite n ); n     } else { n       while (1) { n         g = gcd(q, b); n         if (g == 1) break; n         while (q % g == 0) q /= g; n         if (q == 1) break; n       } n       if (q == 1) { n         printf( Finite n ); n       } else { n         printf( Infinite n ); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   cin.tie(0)->sync_with_stdio(0); n   int n; n   cin >> n; n   vector<vector<int>> adj(n); n   for (int i = 1; i < n; ++i) { n     int u, v; n     cin >> u >> v, --u, --v; n     adj[u].push_back(v), adj[v].push_back(u); n   } n   array<int, 2> cnt{}; n   function<void(int, int, int)> dfs = [&](int u, int p, int c) { n     ++cnt[c]; n     for (auto v : adj[u]) { n       if (v != p) { n         dfs(v, u, !c); n       } n     } n   }; n   dfs(0, 0, 0); n   cout << min(cnt[0], cnt[1]) - 1 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   if (n == 1 && m == 1) n     cout << 1; n   else if (m + n < 5) n     cout << -1; n   else { n     int x = n * m / 2 + 1, y = 1; n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         if ((i + j) % 2 == 0) { n           cout << x <<    ; n           x++; n         } else { n           cout << y <<    ; n           y++; n         } n       } n       cout << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename G> n struct triple { n   G first, second, T; n }; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long d, n, m; n   cin >> d >> n >> m; n   vector<pair<long long, long long> > x(m + 2); n   x[m + 1].first = d; n   for (int i = 1; i <= m; i++) cin >> x[i].first >> x[i].second; n   sort(x.begin(), x.end()); n   vector<int> mn(m + 2); n   stack<int> s; n   for (int i = m + 1; i >= 0; i--) { n     while (!s.empty() && x[s.top()].second > x[i].second) s.pop(); n     if (!s.empty()) n       mn[i] = s.top(); n     else n       mn[i] = m + 2; n     s.push(i); n   } n   long long comb = n, ans = 0; n   for (int i = 0; i < m + 1; i++) { n     int p = mn[i]; n     long long t = min(n - comb, max(x[p].first - x[i].first - comb, 0LL)); n     ans += x[i].second * t; n     comb += t; n     comb -= x[i + 1].first - x[i].first; n     if (comb < 0) { n       cout <<  -1 n ; n       return 0; n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void run() { n   vector<string> v; n   for (int i = 0; i < 8; i++) { n     string s; n     cin >> s; n     v.push_back(s); n   } n   int a = INT_MAX, b = INT_MAX; n   for (int i = 0; i < 8; i++) { n     int c = 0; n     for (int j = 7; j >= 0; j--) { n       if (v[j][i] ==  B ) { n         b = min(b, c); n         break; n       } else if (v[j][i] ==  W ) n         break; n       c++; n     } n   } n   for (int i = 0; i < 8; i++) { n     int c = 0; n     for (int j = 0; j < 8; j++) { n       if (v[j][i] ==  W ) { n         a = min(a, c); n         break; n       } else if (v[j][i] ==  B ) n         break; n       c++; n     } n   } n   if (a <= b) n     cout <<  A ; n   else n     cout <<  B ; n   return; n } n int main() { n   run(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k; n struct Lesson { n   long long a, b; n   int c, id; n   bool operator<(const Lesson &t) const { return c < t.c; } n } ls[55]; n int fstc[110]; n long long dp[55][55][110]; n pair<int, int> trans[55][55][110]; n inline void upd(int x1, int y1, int z1, int y2, int z2, long long val) { n   if (dp[x1][y1][z1] < val) { n     dp[x1][y1][z1] = val; n     trans[x1][y1][z1] = make_pair(y2, z2); n   } n } n void Print(int lvl, int od, int ad) { n   if (lvl == 0) { n     printf( %d %I64d n , ls[od].id, ls[od].a + ad); n     return; n   } n   Print(lvl - 1, trans[lvl][od][ad].first, trans[lvl][od][ad].second); n   printf( %d %lld n , ls[od].id, ls[od].a + ad); n } n int main() { n   scanf( %d%d%d , &n, &m, &k); n   for (int i = 0; i < m; i++) { n     scanf( %I64d%I64d%d , &ls[i].a, &ls[i].b, &ls[i].c); n     ls[i].id = i + 1; n   } n   sort(ls, ls + m); n   memset(fstc, -1, sizeof(fstc)); n   for (int i = 0; i < m; i++) n     if (fstc[ls[i].c] == -1) fstc[ls[i].c] = i; n   for (int i = 0; i < m; i++) { n     for (int j = 0; j <= (int)(ls[i].b - ls[i].a); j++) { n       dp[0][i][j] = (ls[i].a + j); n     } n   } n   for (int i = 1; i < n; i++) { n     for (int j = 0; j < m; j++) { n       int c = ls[j].c; n       for (int task = 0; task <= 100; task++) n         if (dp[i - 1][j][task]) { n           long long val = ls[j].a + task; n           if (val > ls[j].b) continue; n           long long knval = val * 1ll * k; n           long long nvalk = val + 1ll * k; n           for (int nc = c + 1; nc <= 100; nc++) { n             if (fstc[nc] == -1) continue; n             for (int nj = fstc[nc]; nj < m && ls[nj].c == nc; nj++) { n               if (ls[nj].a <= knval && knval <= ls[nj].b) { n                 int ntask = (int)(knval - ls[nj].a); n                 upd(i, nj, ntask, j, task, dp[i - 1][j][task] + knval); n               } n               if (ls[nj].a <= nvalk && nvalk <= ls[nj].b) { n                 int ntask = (int)(nvalk - ls[nj].a); n                 upd(i, nj, ntask, j, task, dp[i - 1][j][task] + nvalk); n               } n             } n           } n         } n     } n   } n   long long ans = 0; n   int y = -1, z = -1; n   for (int i = 0; i < m; i++) n     for (int j = 0; j <= (int)(ls[i].b - ls[i].a); j++) { n       if (dp[n - 1][i][j] > ans) { n         ans = dp[n - 1][i][j]; n         y = i; n         z = j; n       } n     } n   if (ans == 0 || y == -1 || z == -1) { n     printf( NO n ); n     return 0; n   } n   printf( YES n ); n   Print(n - 1, y, z); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int Rand(int x) { return rand() * rand() % x + 1; } n const int INF = 0x3f3f3f3f, N = 5000005, M = 2000005, MOD = 1e9 + 7; n long long qpow(long long a, long long b) { n   long long ret = 1; n   for (; b; b >>= 1, a = a * a % MOD) n     if (b & 1) ret = ret * a % MOD; n   return ret; n } n long long val[N]; n map<int, int> g[N]; n map<long long, int> has; n int find(int id, int x) { n   if (x == g[id][x]) return x; n   return g[id][x] = find(id, g[id][x]); n } n void Union(int id, int x, int y) { n   int fx = find(id, x), fy = find(id, y); n   if (fx == fy) return; n   g[id][fy] = fx; n } n int cnt[N], ss; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0), cout.tie(0); n   int n, m, c; n   cin >> n >> m >> c; n   for (int i = 1; i <= n; i++) cin >> val[i]; n   long long ans = qpow(2, c) * qpow(2, n) % MOD; n   for (int i = 1; i <= m; i++) { n     int u, v; n     cin >> u >> v; n     long long x = val[u] ^ val[v]; n     if (!has.count(x)) has[x] = ++ss, cnt[ss] = n; n     x = has[x]; n     if (!g[x][u]) g[x][u] = u; n     if (!g[x][v]) g[x][v] = v; n     if (find(x, u) == find(x, v)) continue; n     Union(x, u, v); n     ans = (ans - qpow(2, cnt[x]) + MOD) % MOD; n     cnt[x]--; n     ans = (ans + qpow(2, cnt[x]) + MOD) % MOD; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, minx, h, m, ans; n   int a[105]; n   cin >> n >> minx; n   for (int i = 1; i <= n; i++) { n     cin >> h >> m; n     a[i] = h * 60 + m; n   } n   if (a[1] >= minx + 1) { n     cout << 0 <<     << 0 << endl; n     return 0; n   } n   for (int i = 2; i <= n; i++) { n     if (a[i] - a[i - 1] >= minx * 2 + 2) { n       ans = a[i - 1] + minx + 1; n       cout << ans / 60 <<     << ans % 60 << endl; n       return 0; n     } n   } n   ans = a[n] + minx + 1; n   cout << ans / 60 <<     << ans % 60 << endl; n   return 0; n } n


#include <bits/stdc++.h> n const double eps = 1e-10, pi = acos(-1.0); n const int maxS = 1e2 + 10; n const int maxS2 = 5e4 + 10; n const unsigned long long MOD = 1e9 + 7; n using namespace std; n struct point { n   int x, y, z; n }; n int n, m, i, j, k, x, y, z, T, ii, t, l, r, pos; n int tot = 0, cnt = 0, ans = 0, sum = 0; n bool chk, chk2[maxS], flag; n string s, s1, s2; n char c[maxS][maxS]; n vector<point> res; n void print(int x, int y, int l) { n   int i; n   for (i = x - l; i <= x + l; i++) c[i][y] =  # ; n   for (i = y - l; i <= y + l; i++) c[x][i] =  # ; n } n bool deal(int x, int y, int l) { n   int i; n   if (x - l < 0 || x + l >= n || y - l < 0 || y + l >= m) return false; n   for (i = x - l; i <= x + l; i++) n     if (c[i][y] ==  . ) return false; n   for (i = y - l; i <= y + l; i++) n     if (c[x][i] ==  . ) return false; n   print(x, y, l); n   res.push_back({x, y, l}); n   chk = true; n   return true; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n >> m; n   for (i = 0; i < n; i++) n     for (j = 0; j < m; j++) cin >> c[i][j]; n   for (i = 0; i < n; i++) n     for (j = 0; j < m; j++) n       if (c[i][j] ==  * ) { n         chk = false; n         for (k = 1; k < min(n, m); k++) n           if (deal(i, j, k)) break; n         if (!chk) n           for (k = 1; k < min(n, m); k++) n             if (deal(i + k, j, k)) break; n         if (!chk) n           for (k = 1; k < min(n, m); k++) n             if (deal(i - k, j, k)) break; n         if (!chk) n           for (k = 1; k < min(n, m); k++) n             if (deal(i, j + k, k)) break; n         if (!chk) n           for (k = 1; k < min(n, m); k++) n             if (deal(i, j - k, k)) break; n       } n   chk = true; n   for (i = 0; i < n; i++) n     for (j = 0; j < m; j++) n       if (c[i][j] ==  * ) chk = false; n   if (!chk) n     cout << -1 << endl; n   else { n     cout << res.size() << endl; n     for (i = 0; i < res.size(); i++) n       cout << res[i].x + 1 <<     << res[i].y + 1 <<     << res[i].z << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long l, r; n   cin >> l >> r; n   int t = 0; n   while (l != r) { n     r >>= 1; n     l >>= 1; n     ++t; n   } n   cout << ((1ll << t) - 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int oo = 1e9; n const int maxc = 77; n struct thang { n   int X, B; n }; n thang A[1010]; n double f[1010]; n int trace[1010], st[1010]; n int N, L; n void nhap() { n   scanf( %d%d , &N, &L); n   for (int i = 1; i <= N; i++) scanf( %d%d , &A[i].X, &A[i].B); n   A[0].X = 0; n } n void solve(double mid) { n   for (int i = 1; i <= N; i++) f[i] = oo; n   f[0] = 0; n   for (int i = 1; i <= N; i++) { n     int vt = 0; n     double t = oo; n     for (int j = i - 1; j >= 0; j--) n       if (f[j] + sqrt(abs((A[i].X - A[j].X) - L * 1.0)) - mid * 1.0 * A[i].B < n           t) { n         vt = j; n         t = f[j] + sqrt(abs((A[i].X - A[j].X) - L * 1.0)) - mid * 1.0 * A[i].B; n       } n     f[i] = t; n     trace[i] = vt; n   } n } n void chat() { n   double l = 0, r = oo; n   for (int i = 1; i <= maxc; i++) { n     double mid = (l + r) / 2; n     solve(mid); n     if (f[N] <= 0) n       r = mid; n     else n       l = mid; n   } n   int top = 0, i = N; n   while (i != 0) { n     st[++top] = i; n     i = trace[i]; n   } n   while (top > 0) printf( %d  , st[top--]); n } n int main() { n   nhap(); n   chat(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, a[300005], op, l, r; n long long fib[300005 + 100]; n struct wyh { n   long long tagl, tagr, sum; n } tree[300005 * 4]; n inline long long getint() { n   long long x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar(); n   return x * f; n } n inline void update(int x) { n   tree[x].sum = tree[x * 2].sum + tree[x * 2 + 1].sum; n   if (tree[x].sum >= 1000000009) tree[x].sum %= 1000000009; n } n inline void build(int x, int l, int r) { n   if (l == r) { n     tree[x].sum = a[l]; n     return; n   } n   int mid = (l + r) >> 1; n   build(x * 2, l, mid), build(x * 2 + 1, mid + 1, r); n   update(x); n } n inline void modify(int x, int l, int r, int s, int t, int c, int d); n inline void push(int x, int l, int r) { n   if (tree[x].tagl || tree[x].tagr) { n     int mid = (l + r) >> 1; n     modify(x * 2, l, mid, l, r, tree[x].tagl, tree[x].tagr); n     modify(x * 2 + 1, mid + 1, r, l, r, tree[x].tagl, tree[x].tagr); n     tree[x].tagl = tree[x].tagr = 0; n   } n } n inline long long get(int a, int b, int x) { n   if (x == 0) return a; n   if (x == 1) return b; n   return (a * fib[x - 1] % 1000000009 + b * fib[x] % 1000000009) % 1000000009; n } n inline void modify(int x, int l, int r, int s, int t, int c, int d) { n   if (s <= l && t >= r) { n     int first, second; n     first = get(c, d, l - s), second = get(c, d, l - s + 1); n     c = first, d = second; n     tree[x].tagl += c, tree[x].tagr += d; n     tree[x].tagl %= 1000000009, tree[x].tagr %= 1000000009; n     tree[x].sum = (tree[x].sum + get(c, d, r - l + 2) - d) % 1000000009; n     return; n   } n   push(x, l, r); n   int mid = (l + r) >> 1; n   if (s <= mid) modify(x * 2, l, mid, s, t, c, d); n   if (t > mid) modify(x * 2 + 1, mid + 1, r, s, t, c, d); n   update(x); n } n inline long long query(int x, int l, int r, int s, int t) { n   if (s <= l && t >= r) return tree[x].sum; n   int mid = (l + r) >> 1; n   push(x, l, r); n   long long tmp = 0; n   if (s <= mid) tmp += query(x * 2, l, mid, s, t); n   if (t > mid) tmp += query(x * 2 + 1, mid + 1, r, s, t); n   return tmp; n } n void work() { n   n = getint(), m = getint(); n   for (int i = 1; i <= n; ++i) a[i] = getint(); n   fib[1] = 1; n   for (int i = 2; i <= n + 5; ++i) n     fib[i] = (fib[i - 1] + fib[i - 2]) % 1000000009; n   build(1, 1, n); n   for (int i = 1; i <= m; ++i) { n     op = getint(), l = getint(), r = getint(); n     if (op == 1) n       modify(1, 1, n, l, r, 1, 1); n     else n       printf( %I64d n , n              (query(1, 1, n, l, r) % 1000000009 + 1000000009) % 1000000009); n   } n } n int main() { n   work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n long long size(const T& x) { n   return x.size(); n } n #pragma GCC optimize( Ofast ) n template <class T> n T smod(T a, T b) { n   return (a % b + b) % b; n } n long long pw(long long a, long long b) { n   long long res = 1; n   while (b > 0) { n     if (b % 2) res = (res * a) % 1000000007; n     b /= 2; n     a = a * a % 1000000007; n   } n   return res; n } n void solve() { n   long long n; n   cin >> n; n   string S; n   cin >> S; n   long long cntk = 0; n   for (long long i = (0); i < (n); ++i) cntk += (S[i] ==  ? ); n   vector<long long> A(n); n   A[0] = (S[0] ==  a ); n   for (long long i = (1); i < (n); ++i) A[i] = A[i - 1] + (S[i] ==  a ); n   vector<long long> C(n); n   C[n - 1] = (S[n - 1] ==  c ); n   for (long long i = (n - 2); i > -1; --i) C[i] = C[i + 1] + (S[i] ==  c ); n   vector<long long> KL(n); n   KL[0] = (S[0] ==  ? ); n   for (long long i = (1); i < (n); ++i) KL[i] = KL[i - 1] + (S[i] ==  ? ); n   vector<long long> KR(n); n   KR[n - 1] = (S[n - 1] ==  ? ); n   for (long long i = (n - 2); i > -1; --i) KR[i] = KR[i + 1] + (S[i] ==  ? ); n   long long ans = 0; n   for (long long i = (1); i < (n - 1); ++i) { n     if (S[i] ==  a  || S[i] ==  c ) continue; n     long long cnta = A[i - 1]; n     long long cntc = C[i + 1]; n     long long cntkl = KL[i - 1]; n     long long cntkr = KR[i + 1]; n     long long isk = (S[i] ==  ? ); n     ans = (ans + cnta * cntc * pw(3, cntk - isk)) % 1000000007; n     ans = (ans + cnta * cntkr * pw(3, cntk - 1 - isk)) % 1000000007; n     ans = (ans + cntkl * cntc * pw(3, cntk - 1 - isk)) % 1000000007; n     ans = (ans + cntkl * cntkr * pw(3, cntk - 2 - isk)) % 1000000007; n   } n   cout << ans << endl; n } n int main() { n   cin.sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   char s[101]; n   int cnt[2] = {}; n   scanf( %s , s); n   for (int i = 0; s[i]; i++) cnt[s[i] ==  - ]++; n   printf( %s n , cnt[0] && cnt[1] % cnt[0] ?  NO  :  YES ); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100010; n int p[maxn], w[maxn]; n vector<pair<pair<int, int>, int>> a; n int find(int x) { n   if (p[x] == x) n     return x; n   else { n     int ret = find(p[x]); n     w[x] ^= w[p[x]]; n     return p[x] = ret; n   } n } n int main() { n   int l, r, n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> l >> r; n     a.push_back(make_pair(make_pair(l, 0), i)); n     a.push_back(make_pair(make_pair(r, 1), i)); n   } n   sort(a.begin(), a.end()); n   for (int i = 0; i < n; i++) p[i] = i; n   for (int i = 0; i < a.size(); i += 2) n     if (a[i].second != a[i + 1].second) { n       int ret = a[i].first.second == a[i + 1].first.second; n       int u = a[i].second, v = a[i + 1].second; n       if (find(u) == find(v)) { n         if (w[u] ^ w[v] ^ ret) { n           cout << -1 << endl; n           return 0; n         } n       } else { n         w[p[v]] = ret ^ w[v]; n         p[p[v]] = u; n       } n     } n   for (int i = 0; i < n; i++) { n     find(i); n     cout << w[i] <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace IO { n const unsigned int Buffsize = 1 << 15, Output = 1 << 23; n static char Ch_[Buffsize], *S_ = Ch_, *T_ = Ch_; n static char Out[Output], *nowps = Out; n inline void flush() { n   fwrite(Out, 1, nowps - Out, stdout); n   nowps = Out; n } n template <class T> n inline bool chkmax(T &_, T __) { n   return _ < __ ? _ = __, 1 : 0; n } n template <class T> n inline bool chkmin(T &_, T __) { n   return _ > __ ? _ = __, 1 : 0; n } n template <class T> n inline T read(T &_) { n   _ = 0; n   static char __; n   T ___ = 1; n   for (__ = ((S_ == T_) && (T_ = (S_ = Ch_) + fread(Ch_, 1, Buffsize, stdin), n                            S_ == T_) n                  ? 0 n                  : *S_++); n        !isdigit(__); n        __ = ((S_ == T_) && (T_ = (S_ = Ch_) + fread(Ch_, 1, Buffsize, stdin), n                            S_ == T_) n                  ? 0 n                  : *S_++)) n     if (__ ==  - ) ___ = -1; n   for (; isdigit(__); n        __ = ((S_ == T_) && (T_ = (S_ = Ch_) + fread(Ch_, 1, Buffsize, stdin), n                            S_ == T_) n                  ? 0 n                  : *S_++)) n     _ = (_ << 3) + (_ << 1) + (__ ^ 48); n   return _ *= ___; n } n template <class T> n inline void write(T _, char __ =   n ) { n   if (!_) *nowps++ = ( 0 ); n   if (_ < 0) *nowps++ = ( - ), _ = -_; n   static unsigned int sta[111], tp; n   for (tp = 0; _; _ /= 10) sta[++tp] = _ % 10; n   for (; tp; *nowps++ = (sta[tp--] ^ 48)) n     ; n   *nowps++ = (__); n } n }  // namespace IO n inline void proStatus() { n   ifstream t( /proc/self/status ); n   cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()); n } n using namespace IO; n const int N = 1e5 + 10; n const int M = 3e5 + 10; n vector<pair<int, int> > Q[N]; n int n, q, root[N], a[N], ans[M]; n struct Fenwick_Tree { n   int S[N], res; n   Fenwick_Tree() { memset(S, (0x3f3f3f3f), sizeof(S)); } n   void update(int first, int second) { n     first = n - first + 1; n     for (; first < N; first += first & -first) chkmin(S[first], second); n   } n   int query(int first) { n     first = n - first + 1; n     for (res = (0x3f3f3f3f); first; first -= first & -first) n       chkmin(res, S[first]); n     return res; n   } n } T1; n struct Chairman_Tree { n   int cnt; n   struct node { n     int ch[2], pos; n   } T[N * 200]; n   void update(int &first, int pre, int l, int r, int pos, int val) { n     T[first = ++cnt] = T[pre], chkmax(T[first].pos, pos); n     if (l ^ r) { n       if (val <= ((l + r) >> 1)) n         update((T[first].ch[0]), (T[pre].ch[0]), l, ((l + r) >> 1), pos, val); n       else n         update((T[first].ch[1]), (T[pre].ch[1]), ((l + r) >> 1) + 1, r, pos, n                val); n     } n   } n   int query(int first, int l, int r, int mn, int mx) { n     if (mn > mx || !first) return 0; n     if (mn <= l && r <= mx) return T[first].pos; n     if (mx <= ((l + r) >> 1)) n       return query((T[first].ch[0]), l, ((l + r) >> 1), mn, mx); n     if (mn > ((l + r) >> 1)) n       return query((T[first].ch[1]), ((l + r) >> 1) + 1, r, mn, mx); n     return max( n         query((T[first].ch[0]), l, ((l + r) >> 1), mn, ((l + r) >> 1)), n         query((T[first].ch[1]), ((l + r) >> 1) + 1, r, ((l + r) >> 1), mx)); n   } n } T2; n int main() { n   int first, second; n   read(n); n   for (int i = 1; i <= n; ++i) n     T2.update(root[i], root[i - 1], 0, 1e9, i, read(a[i])); n   read(q); n   for (int i = 1; i <= q; ++i) n     read(first), Q[read(second)].push_back(make_pair(first, i)); n   for (int r = 1, pos, lim; r <= n; ++r) { n     pos = r, lim = (0x3f3f3f3f); n     while (pos = T2.query(root[pos - 1], 0, 1e9, a[r], lim)) n       T1.update(pos, a[pos] - a[r]), n           lim = (a[pos] + a[r]) / 2 - (((a[r] + a[pos] + 1) & 1)); n     pos = r, lim = -(0x3f3f3f3f); n     while (pos = T2.query(root[pos - 1], 0, 1e9, lim, a[r])) n       T1.update(pos, a[r] - a[pos]), n           lim = (a[pos] + a[r]) / 2 + (((a[r] + a[pos] + 1) & 1)); n     for (auto v : Q[r]) ans[v.second] = T1.query(v.first); n   } n   for (int i = 1; i <= q; ++i) write(ans[i]); n   return flush(), 0; n } n


#include <bits/stdc++.h> n using namespace std; n double dis(double ax, double ay, double bx, double by) { n   return sqrt(pow(ax - bx, 2) + pow(ay - by, 2)); n } n bool f(double a, double b, double c) { n   if (a == sqrt(pow(b, 2) + pow(c, 2))) n     return true; n   else n     return false; n } n int main() { n   cout << fixed << setprecision(15); n   double ax, ay, bx, by, cx, cy; n   cin >> ax >> ay >> bx >> by >> cx >> cy; n   double ab = dis(ax, ay, bx, by), bc = dis(bx, by, cx, cy), n          ac = dis(ax, ay, cx, cy); n   bool res = true; n   if (ab == bc) { n     if (ay - by == 0) { n       if (ay == by && ay == cy) res = false; n     } else if (ax - bx == 0) { n       if (ax == bx && ax == cx) res = false; n     } else { n       double m = (ay - by) / (ax - bx); n       if (cy == (m * cx + ay - m * ax)) res = false; n     } n   } else n     res = false; n   if (res) n     cout <<  Yes  << endl; n   else n     cout <<  No  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int w = 26; n   int count = 0; n   char a[] = { a ,  b ,  c ,  d ,  e ,  f ,  g ,  h ,  i ,  j ,  k ,  l ,  m , n                n ,  o ,  p ,  q ,  r ,  s ,  t ,  u ,  v ,  w ,  x ,  y ,  z }; n   string b; n   cin >> b; n   for (char c : b) { n     for (int m = 0; m < w; m++) { n       if (c == a[m]) { n         a[m] =  1 ; n         count++; n       } n     } n   } n   if (count % 2 == 0) { n     cout <<  CHAT WITH HER! ; n   } else { n     cout <<  IGNORE HIM! ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s, x; n   cin >> s; n   int count = 0, sz = s.size(); n   for (int i = 0; i < sz; ++i) n     if (s[i] ==  1 ) ++count; n   for (int i = 0; i < sz; ++i) { n     if (s[i] ==  0 ) n       x +=  0 ; n     else if (s[i] ==  2 ) { n       while (count-- > 0) x +=  1 ; n       x +=  2 ; n     } n   } n   while (count-- > 0) x +=  1 ; n   cout << x; n   return (0); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100009; n int first[maxn], du[maxn], pre[maxn][2]; n struct edg { n   int next, to; n } e[maxn << 1]; n struct node { n   int x, opt; n }; n bool vis[maxn][2], ins[maxn], ok[maxn]; n queue<node> q; n int n, m, s, e_sum; n bool flag; n inline int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n void add_edg(int x, int y) { n   e_sum++; n   e[e_sum].next = first[x]; n   first[x] = e_sum; n   e[e_sum].to = y; n } n void print(int x, int opt) { n   if (x == s && opt == 0) { n     printf( %d  , x); n     return; n   } n   print(pre[x][opt], opt ^ 1); n   printf( %d  , x); n } n void dfs(int x) { n   ok[x] = ins[x] = 1; n   for (int i = first[x]; i; i = e[i].next) { n     int w = e[i].to; n     if (ins[w]) flag = 1; n     if (!ok[w]) dfs(w); n   } n   ins[x] = 0; n } n int main() { n   n = read(); n   m = read(); n   for (int i = 1; i <= n; i++) { n     du[i] = read(); n     for (int j = 1; j <= du[i]; j++) { n       int x = read(); n       add_edg(i, x); n     } n   } n   s = read(); n   q.push((node){s, 0}); n   vis[s][0] = 1; n   while (!q.empty()) { n     int x = q.front().x, opt = q.front().opt; n     q.pop(); n     for (int i = first[x]; i; i = e[i].next) { n       int w = e[i].to; n       if (!vis[w][opt ^ 1]) { n         vis[w][opt ^ 1] = 1; n         pre[w][opt ^ 1] = x; n         q.push((node){w, opt ^ 1}); n       } n     } n   } n   for (int i = 1; i <= n; i++) n     if (du[i] == 0 && vis[i][1]) { n       puts( Win ); n       print(i, 1); n       return 0; n     } n   dfs(s); n   if (flag) n     puts( Draw ); n   else n     puts( Lose ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, l, r, x, mid; n   cin >> n >> m; n   int a[n][2]; n   for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1]; n   int b[m]; n   for (int i = 0; i < m; i++) cin >> b[i]; n   int music[n]; n   for (int i = 0; i < n; i++) music[i] = 0; n   music[0] = a[0][0] * a[0][1]; n   for (int i = 1; i < n; i++) music[i] = music[i - 1] + a[i][0] * a[i][1]; n   for (int i = 0; i < m; i++) { n     x = b[i]; n     l = -1; n     r = n - 1; n     while (r - l > 1) { n       mid = (l + r) / 2; n       if (x <= music[mid]) n         r = mid; n       else n         l = mid; n     } n     cout << r + 1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,unroll-loops,no-stack-protector,fast-math,inline ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2 ) n using namespace std; n using ll = long long; n using vvi = vector<vector<int>>; n using vi = vector<int>; n using vvll = vector<vector<long long>>; n using vll = vector<long long>; n using vd = vector<double>; n using vvd = vector<vector<double>>; n using pii = pair<int, int>; n using vpii = vector<pair<int, int>>; n void __print(int x) { cerr << x; } n void __print(long x) { cerr << x; } n void __print(long long x) { cerr << x; } n void __print(unsigned x) { cerr << x; } n void __print(unsigned long x) { cerr << x; } n void __print(unsigned long long x) { cerr << x; } n void __print(float x) { cerr << x; } n void __print(double x) { cerr << x; } n void __print(long double x) { cerr << x; } n void __print(char x) { cerr <<      << x <<     ; } n void __print(const char *x) { cerr <<     << x <<    ; } n void __print(const string &x) { cerr <<     << x <<    ; } n void __print(bool x) { cerr << (x ?  true  :  false ); } n template <typename T, typename V> n void __print(const pair<T, V> &x) { n   cerr <<  { ; n   __print(x.first); n   cerr <<  , ; n   __print(x.second); n   cerr <<  } ; n } n template <typename T> n void __print(const T &x) { n   int f = 0; n   cerr <<  { ; n   for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i); n   cerr <<  } ; n } n void _print() { cerr <<  ] n ; } n template <typename T, typename... V> n void _print(T t, V... v) { n   __print(t); n   if (sizeof...(v)) cerr <<  ,  ; n   _print(v...); n } n ll MOD = 1e9 + 7; n vvll multiply(vvll a, vvll b) { n   int x = a.size(); n   int y = b.size(); n   int z = b[0].size(); n   assert(y == a[0].size()); n   vvll ans(x, vll(z)); n   for (int i = 0; i < x; i++) { n     for (int j = 0; j < z; j++) { n       for (int k = 0; k < y; k++) { n         ans[i][j] += a[i][k] * b[k][j]; n         ans[i][j] %= MOD; n       } n     } n   } n   return ans; n } n vvll binexp(vvll m, ll b) { n   int n = m.size(); n   vvll ans(n, vll(n)); n   for (int i = 0; i < n; i++) { n     ans[i][i] = 1; n   } n   while (b) { n     if (b & 1) { n       ans = multiply(ans, m); n     } n     m = multiply(m, m); n     b >>= 1; n   } n   return ans; n } n void solve() { n   int n, k, m; n   cin >> n >> k >> m; n   int d = (k + 1) * (1 << m); n   vvll mat(d + 1, vll(d + 1)); n   mat[d][d] = 1; n   mat[0][d] = 1; n   for (int j = 1; j <= k; j++) { n     for (int mask = 0; mask < (1 << m); mask++) { n       int row = j * (1 << m) + mask; n       if (mask & 1) { n         for (int b = 0; b < 2; b++) { n           mat[row][(j - 1) * (1 << m) + ((b << (m - 1)) | (mask >> 1))] = n               (__builtin_popcount((b << (m - 1)) | (mask >> 1)) + 1); n         } n       } else { n         for (int b = 0; b < 2; b++) { n           mat[row][j * (1 << m) + ((b << (m - 1)) | (mask >> 1))] = 1; n         } n       } n     } n   }; n   vvll v(d + 1, vll(1)); n   v[0][0] = 1; n   v[d][0] = 1; n   ; n   vvll e = binexp(mat, n); n   ; n   vvll res = multiply(e, v); n   ; n   ll ans = 0; n   for (int mask = 0; mask < (1 << m); mask++) { n     ans += res[k * (1 << m) + mask][0]; n   } n   cout << ans % MOD << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   solve(); n   return 0; n } n