#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n const ld eps = 1e-8; n template <class U, class V> n ostream& operator<<(ostream& out, const pair<U, V>& p) { n   return out <<  (  << p.first <<  ,   << p.second <<  ) ; n } n template <size_t i, class T> n ostream& print_tuple_utils(ostream& out, const T& tup) { n   if constexpr (i == tuple_size<T>::value) n     return out <<  ) ; n   else n     return print_tuple_utils<i + 1, T>(out << (i ?  ,   :  ( ) << get<i>(tup), n                                        tup); n } n template <class... U> n ostream& operator<<(ostream& out, const tuple<U...>& tup) { n   return print_tuple_utils<0, tuple<U...>>(out, tup); n } n template <class Con, class = decltype(begin(declval<Con>()))> n typename enable_if<!is_same<Con, string>::value, ostream&>::type operator<<( n     ostream& out, const Con& container) { n   out <<  { ; n   for (auto it = container.begin(); it != container.end(); ++it) n     out << (it == container.begin() ?    :  ,  ) << *it; n   return out <<  } ; n } n template <int mod_> n struct modint { n   static constexpr int mod = mod_; n   int x; n   modint(int xx = 0) : x(xx) {} n   modint(ll xx) : x((int)(xx % mod)) {} n   friend inline modint operator+(modint u, const modint& v) { return u += v; } n   modint& operator+=(const modint& o) { n     if ((x += o.x) >= mod) x -= mod; n     return *this; n   } n   friend inline modint operator-(modint u, const modint& v) { return u -= v; } n   modint& operator-=(const modint& o) { n     if ((x -= o.x) < 0) x += mod; n     return *this; n   } n   friend inline modint operator*(modint u, const modint& v) { return u *= v; } n   modint& operator*=(const modint& o) { return *this = modint(1ll * x * o.x); } n   modint pow(ll exp) const { n     modint base = *this, ans = 1; n     for (; exp > 0; exp >>= 1, base *= base) n       if (exp & 1) ans *= base; n     return ans; n   } n   friend inline modint operator/(modint u, const modint& v) { return u /= v; } n   modint& operator/=(const modint& o) { return *this *= o.pow(mod - 2); } n   friend bool operator==(const modint& u, const modint& v) { n     return u.x == v.x; n   } n   friend ostream& operator<<(ostream& out, const modint& u) { n     return out << u.x; n   } n }; n using mint = modint<(int)1e9 + 7>; n const int maxn = 696; n mint comb[maxn][maxn]; n mint fac[maxn]; n void precal() { n   for (int i = (int)(0); i < (int)(maxn); ++i) { n     comb[i][0] = 1; n     for (int f = (int)(1); f < (int)(i + 1); ++f) { n       comb[i][f] = comb[i - 1][f] + comb[i - 1][f - 1]; n     } n   } n   fac[0] = 1; n   for (int i = (int)(1); i < (int)(maxn); ++i) fac[i] = fac[i - 1] * i; n } n int reduce_factor(int num) { n   int ans = 1; n   for (int i = 2; i * i <= num; ++i) { n     if (num % i) continue; n     int cnt = 0; n     while (num % i == 0) { n       num /= i; n       cnt ^= 1; n     } n     if (cnt) ans *= i; n   } n   if (num > 1) ans *= num; n   return ans; n } n mint brute(const vector<int>& a) { n   auto is_perfect_sqr = [&](ll num) { n     ll x = (ll)round(sqrt(num)); n     return x * x == num; n   }; n   vector<int> pos(((int)a.size())); n   for (int i = (int)(0); i < (int)(((int)a.size())); ++i) pos[i] = i; n   mint ans = 0; n   do { n     bool ok = true; n     for (int i = (int)(0); i < (int)(((int)a.size()) - 1); ++i) { n       if (!is_perfect_sqr(1ll * a[pos[i]] * a[pos[i + 1]])) continue; n       ok = false; n       break; n     } n     ans += ok; n   } while (next_permutation((pos).begin(), (pos).end())); n   return ans; n } n mint solve(const vector<int>& a) { n   map<int, int> cnt; n   for (auto i : a) { n     int rd = reduce_factor(i); n     if (0) n       cerr <<  [  n                i  n                 =   n            << (i) <<  ]   n            <<  [  n                rd  n                 =   n            << (rd) <<  ]   << endl; n     cnt[rd]++; n   } n   vector<mint> dp = {1}; n   int cnt_have = 0; n   for (auto [val, cur_cnt] : cnt) { n     ; n     if (0) n       cerr <<  [  n                val  n                 =   n            << (val) <<  ]   n            <<  [  n                cur_cnt  n                 =   n            << (cur_cnt) <<  ]   << endl; n     vector<mint> new_dp(((int)a.size()) + 2); n     auto cur_fac = fac[cur_cnt]; n     for (int prev_same_pos = (int)(0); prev_same_pos < (int)(((int)dp.size())); n          ++prev_same_pos) { n       if (dp[prev_same_pos] == 0) continue; n       int prev_res_pos = cnt_have + 1 - prev_same_pos; n       for (int cnt_group = (int)(1); cnt_group < (int)(cur_cnt + 1); n            ++cnt_group) { n         ; n         if (0) n           cerr <<  [  n                    cnt_group  n                     =   n                << (cnt_group) <<  ]   << endl; n         int add_same_pos = cur_cnt - cnt_group; n         for (int choose_same_pos = (int)(0); n              choose_same_pos < (int)(prev_same_pos + 1); ++choose_same_pos) { n           int choose_res_pos = cnt_group - choose_same_pos; n           if (choose_res_pos < 0) break; n           if (choose_res_pos > prev_res_pos) continue; n           int new_same_pos = prev_same_pos + add_same_pos - choose_same_pos; n           mint cur_ans = comb[prev_same_pos][choose_same_pos] * n                          comb[prev_res_pos][choose_res_pos] * n                          comb[cur_cnt - 1][cnt_group - 1] * dp[prev_same_pos]; n           if (0) n             cerr <<  [  n                      choose_same_pos  n                       =   n                  << (choose_same_pos) <<  ]   n                  <<  [  n                      new_same_pos  n                       =   n                  << (new_same_pos) <<  ]   n                  <<  [  n                      cur_ans  n                       =   n                  << (cur_ans) <<  ]   << endl; n           new_dp[new_same_pos] += cur_fac * cur_ans; n         } n       } n     } n     swap(dp, new_dp); n     while (dp.size() and dp.back() == 0) dp.pop_back(); n     cnt_have += cur_cnt; n     if (0) n       cerr <<  [  n                dp  n                 =   n            << (dp) <<  ]   << endl; n     if (0) n       cerr <<  [  n                cnt_have  n                 =   n            << (cnt_have) <<  ]   << endl; n   } n   return dp[0]; n } n mt19937 rng; n void check() { n   while (true) { n     int n = ((int)(rng() >> 1)) % 5 + 1; n     vector<int> a(n); n     for (int i = (int)(0); i < (int)(n); ++i) n       a[i] = ((int)(rng() >> 1)) % 100 + 1; n     ofstream inp( main.inp ); n     inp << n << endl; n     for (int i = (int)(0); i < (int)(n); ++i) inp << a[i] <<    ; n     inp << endl; n     auto ans = solve(a); n     auto exp = brute(a); n     inp <<  [  n             ans  n              =   n         << (ans) <<  ]   n         <<  [  n             exp  n              =   n         << (exp) <<  ]   << endl; n     inp.close(); n     if (ans == exp) { n       cout <<  OK  << endl; n       continue; n     } n     cout <<  FAILED  << endl; n     exit(0); n   } n } n int main() { n   precal(); n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   vector<int> a(n); n   for (int i = (int)(0); i < (int)(n); ++i) cin >> a[i]; n   cout << solve(a) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long int> factors(long long int n) { n   vector<long long int> v; n   for (long long int i = 1; i * i <= n; i++) { n     if (n % i == 0) { n       if (i * i == n) n         v.push_back(i); n       else { n         v.push_back(i); n         v.push_back(n / i); n       } n     } n   } n   sort(v.begin(), v.end()); n   return v; n } n long long gcd(long long a, long long b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n int main() { n   std::ios_base::sync_with_stdio(false); n   long long int t; n   cin >> t; n   while (t--) { n     long long int n; n     cin >> n; n     long long int a[n], i, j; n     for (i = 0; i < n; i++) { n       cin >> a[i]; n     } n     sort(a, a + n); n     map<long long int, long long int> m; n     long long int temp = a[n - 1]; n     vector<long long int> sol; n     m[n - 1] = 1; n     sol.push_back(temp); n     long long int ans = temp, index; n     for (i = 0; i < n; i++) { n       long long int temp_gcd = INT_MIN; n       for (j = 0; j < n; j++) { n         if (m[j] == 0) { n           long long int temp = gcd(ans, a[j]); n           if (temp > temp_gcd) { n             temp_gcd = temp; n             index = j; n           } n         } n       } n       m[index] = 1; n       sol.push_back(a[index]); n       ans = temp_gcd; n     } n     for (i = 0; i < n; i++) { n       cout << sol[i] <<    ; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using vec_i = vector<int>; n using pii = pair<int, int>; n using ll = long long; n using vec_ii = vector<pii>; n using vec_ll = vector<ll>; n template <typename T> n using vec = vector<T>; n ll gcd(ll x, ll y) { n   ll m; n   while (y > 0) { n     m = x % y; n     x = y; n     y = m; n   } n   return x; n } n ll powm(ll x, ll n, ll m) { n   ll r = 1; n   while (n > 0) { n     if (n & 1) r = r * x % m; n     x = x * x % m; n     n /= 2; n   } n   return r; n } n static const int MOD = 1000000000 + 7; n static const int P = 343434; n const int PA = 257, PB = 983, MODA = 1e9 + 7, MODB = 1e9 + 9; n int n, m; n char ss[256][256]; n int tt[256][256]; n bool pal[256]; n int hash_a[256], hash_b[256]; n ll hash_lalaku[256]; n int pa_pows[256], pb_pows[256]; n inline bool is_pow2(int val) { return val != 0 && (val & (val - 1)) == 0; } n inline bool is_pal(int val, bool odd) { n   return (odd && is_pow2(val)) || ((!odd) && (val == 0)); n } n int solve() { n   pa_pows[0] = 1; n   pb_pows[0] = 1; n   for (int i = 1; i < 256; ++i) { n     pa_pows[i] = pa_pows[i - 1] * 1ll * PA % MODA; n     pb_pows[i] = pb_pows[i - 1] * 1ll * PB % MODB; n   } n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; ++i) { n     scanf( %s , ss[i] + 1); n   } n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) { n       int val, c; n       c = ss[i][j] -  a  + 1; n       val = (1 << c); n       tt[i][j] = tt[i][j - 1] ^ val; n     } n   } n   ll ans = 0; n   for (int i = 1; i <= m; ++i) { n     memset(hash_a, 0, sizeof(hash_a)); n     memset(hash_b, 0, sizeof(hash_b)); n     for (int j = i; j <= m; ++j) { n       bool all_same = true; n       for (int k = 1; k <= n; ++k) { n         pal[k] = is_pal(tt[k][j] ^ tt[k][i - 1], (j - i + 1) & 1); n         hash_a[k] += pa_pows[ss[k][j] -  a  + 1]; n         hash_b[k] += pb_pows[ss[k][j] -  a  + 1]; n         if (hash_a[k] >= MODA) hash_a[k] -= MODA; n         if (hash_b[k] >= MODB) hash_b[k] -= MODB; n         hash_lalaku[k] = ((ll)hash_a[k] << 32) | (hash_b[k]); n         all_same = (all_same) && pal[k] && n                    (k == 1 || hash_lalaku[k] == hash_lalaku[k - 1]); n       } n       if (all_same) { n         ans += (n * (n + 1)) / 2; n         continue; n       } n       for (int k = 1; k <= n; ++k) { n         if (pal[k]) { n           int l = k, r = k; n           while (l > 1 && r < n && pal[l - 1] && pal[r + 1] && n                  hash_lalaku[l - 1] == hash_lalaku[r + 1]) { n             --l; n             ++r; n           } n           ans += (r - l + 1 + 1) / 2; n         } n         if (k < n && pal[k + 1] && hash_lalaku[k] == hash_lalaku[k + 1]) { n           int l = k, r = k + 1; n           while (l > 1 && r < n && pal[l - 1] && pal[r + 1] && n                  hash_lalaku[l - 1] == hash_lalaku[r + 1]) { n             --l; n             ++r; n           } n           ans += (r - l + 1) / 2; n         } n       } n     } n   } n   printf( %lld n , ans); n   return 0; n } n int main(int argc, char* argv[]) { n   ::std::ios::sync_with_stdio(false); n   ::std::cin.tie(0); n   ::std::cout.tie(0); n   int test_count = 1; n   while (test_count--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  ||  9  < ch) f = (ch ^  - ) ? f : -1, ch = getchar(); n   while ( 0  <= ch && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar(); n   return x * f; n } n int const N = 310; n double const EPS = 1e-8; n bool equal0(double x) { return -EPS < x && x < EPS; } n int n, m, T; n double a[N][N]; n int b[N], id[N << 1]; n void pivot(int x, int y) { n   swap(id[n + x], id[y]); n   double t = a[x][y]; n   a[x][y] = 1; n   for (int i = 0; i <= n; i++) a[x][i] /= t; n   for (int i = 0; i <= m; i++) { n     if (i == x || equal0(a[i][y])) continue; n     t = a[i][y], a[i][y] = 0; n     for (int j = 0; j <= n; j++) a[i][j] -= a[x][j] * t; n   } n } n bool simplex() { n   while (true) { n     int x = 0, y = 0; n     for (int j = 1; !y && j <= n; j++) n       if (a[0][j] > EPS) y = j; n     if (!y) return true; n     double minX = 1e18; n     for (int i = 1; i <= m; i++) n       if (a[i][y] > EPS && minX > a[i][0] / a[i][y]) n         minX = a[i][0] / a[i][y], x = i; n     if (!x) { n       puts( Unbounded ); n       return false; n     } n     pivot(x, y); n   } n } n bool solve() { n   for (int i = 1; i <= n; i++) id[i] = i; n   while (true) { n     int x = 0, y = 0; n     for (int i = 1; i <= m; i++) n       if (a[i][0] < -EPS && (!x || rand() & 1)) x = i; n     if (!x) return simplex(); n     for (int j = 1; j <= n; j++) n       if (a[x][j] < -EPS && (!y || rand() & 1)) y = j; n     if (!y) { n       puts( Infeasible ); n       return false; n     } n     pivot(x, y); n   } n } n double ans[N]; n int main() { n   scanf( %d%d , &n, &m); n   int _a, _b, _d; n   memset(a, 0, sizeof a); n   for (int i = 1; i <= m; i++) { n     a[i][0] = -1; n   } n   for (int i = 1; i <= m; i++) { n     scanf( %d%d%d , &_a, &_b, &_d); n     a[0][_a] -= _d; n     a[0][_b] += _d; n     a[i][_a] = -1; n     a[i][_b] = 1; n   } n   T = 1; n   if (solve()) { n     if (!T) return 0; n     for (int i = 1; i <= m; i++) ans[id[n + i]] = a[i][0]; n     for (int i = 1; i <= n; i++) printf( %d  , (int)ans[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n multiset<int, greater<int> > s1; n multiset<int> s2; n int bs1, bs2, n, a[500500], b[500500], ct, nomb[500500], cr, noma[500500]; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     noma[a[i]] = i; n   } n   for (int i = 0; i < n; i++) { n     scanf( %d , &b[i]); n     nomb[b[i]] = i; n   } n   s1.clear(); n   s2.clear(); n   bs1 = 0; n   bs2 = 0; n   for (int i = 0; i < n; i++) { n     ct = nomb[a[i]] - i; n     if (ct <= 0) n       s1.insert(ct); n     else n       s2.insert(ct); n   } n   for (int i = 0; i < n; i++) { n     cr = 1000000000; n     if (!s1.empty()) { n       int qt = *s1.begin(); n       cr = min(cr, (-(qt - bs1))); n     } n     if (!s2.empty()) cr = min(cr, (*s2.begin()) - bs2); n     printf( %d n , cr); n     ct = 0 - noma[b[i]] + bs1; n     s1.erase(s1.find(ct)); n     ct = n - 1 - noma[b[i]] + bs2 + 1; n     s2.insert(ct); n     bs1++; n     bs2++; n     while ((!s2.empty()) && (*s2.begin() == bs2)) { n       s2.erase(s2.begin()); n       s1.insert(0 + bs1); n     } n   } n } n


#include <bits/stdc++.h> n int main() { n   int numDominoes; n   char dominoes[3005]; n   int fallen = 0; n   int count = 0; n   int isL = 0; n   int seenR = 0; n   scanf( %d , &numDominoes); n   for (int i = 0; i <= numDominoes; i++) { n     scanf( %c , &dominoes[i]); n   } n   for (int i = 1; i <= numDominoes; i++) { n     if (dominoes[i] ==  . ) { n       count++; n     } else if (dominoes[i] ==  R ) { n       count = 0; n       fallen++; n       for (int j = i; j <= numDominoes; j++) { n         if (dominoes[j] ==  L ) { n           isL = 1; n           break; n         } n       } n       if (isL == 0) { n         fallen += numDominoes - i; n       } n       isL = 0; n       seenR = 1; n     } else if (dominoes[i] ==  L ) { n       fallen++; n       if (count > 0 && seenR == 1) { n         if (count % 2 == 0) { n           fallen += count; n         } else { n           fallen += count - 1; n         } n       } else { n         fallen += count; n       } n       count = 0; n     } n   } n   printf( %d n , numDominoes - fallen); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a, b; n int M[256 + 1]; n int main() { n   scanf( %d %d %d , &n, &a, &b); n   if (a & 1) a++; n   if (b & 1) b++; n   int round = 1; n   for (;;) { n     a /= 2; n     b /= 2; n     if (a == b) break; n     round++; n     if (a & 1) a++; n     if (b & 1) b++; n   } n   if (round == (int)log2(n)) n     printf( Final! n ); n   else n     printf( %d n , round); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a, b, diff, n_div; n int main() { n   int i; n   cin >> a >> b; n   diff = a - b; n   if (diff < 0) { n     cout <<  0  << endl; n   } else if (diff == 0) { n     cout <<  infinity  << endl; n     return 0; n   } else { n     for (i = 1; i * i <= diff; i++) n       if (diff % i == 0) { n         if (i > b) n_div++; n         if (diff / i > b && diff / i != i) n_div++; n       } n     cout << n_div << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2010; n vector<int> G[maxn]; n int n, m, d[maxn], par[maxn], a[maxn], vis[maxn], flag = 1; n char s[1005][1005]; n int find(int u) { n   if (par[u] != u) par[u] = find(par[u]); n   return par[u]; n } n struct node { n   int u, w; n   node(int a, int b) { u = a, w = b; } n }; n void topo() { n   queue<node> q; n   for (int i = 1; i <= n + m; i++) { n     int fa = find(i); n     if (!d[fa] && !vis[fa]) q.push(node(fa, 1)), vis[fa] = 1; n   } n   while (!q.empty()) { n     node e = q.front(); n     q.pop(); n     int u = e.u; n     a[u] = max(a[u], e.w); n     for (int i = 0; i < G[u].size(); i++) { n       int v = G[u][i]; n       a[v] = max(a[u] + 1, a[v]); n       d[v]--; n       if (d[v] == 0) q.push(node(v, a[v])); n     } n   } n   for (int i = 1; i <= n + m; i++) n     if (d[i]) puts( No ), exit(0); n } n void add(int i, int j) { n   int fa = find(i), fb = find(j); n   if (fa == fb) puts( No ), exit(0); n   d[fa]++; n   G[fb].push_back(fa); n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n + m; i++) par[i] = i; n   for (int i = 1; i <= n; i++) { n     scanf( %s , s[i] + 1); n     for (int j = 1; j <= m; j++) n       if (s[i][j] ==  = ) { n         int fa = find(i), fb = find(j + n); n         par[fa] = fb; n       } n   } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       if (s[i][j] ==  > ) n         add(i, n + j); n       else if (s[i][j] ==  < ) n         add(n + j, i); n   topo(); n   puts( Yes ); n   for (int i = 1; i < n; i++) printf( %d  , a[find(i)]); n   printf( %d n , a[find(n)]); n   for (int i = 1; i < m; i++) printf( %d  , a[find(i + n)]); n   printf( %d n , a[find(n + m)]); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   cin >> n; n   long long prod = 1; n   for (int i = 1; i < n; i++) prod *= i; n   prod *= 2; n   prod /= n; n   cout << prod << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long M = 1e9 + 7; n const double eps = 1e-8; n const int maxn = 1e6 + 5; n const int INF = 1e9; n const int maxnode = 7e6 + 5; n const int sigma_size = 2; n void tran2(int num, int s[]) { n   for (int i = 0; i < 31; i++) { n     s[i] = (num >> (30 - i)) & 1; n   } n } n struct Trie { n   int ch[maxnode][sigma_size]; n   int val[maxnode], able[maxnode]; n   int sz; n   void init() { n     sz = 1; n     memset(ch, 0, sizeof(ch)); n     memset(val, 0, sizeof(val)); n     memset(able, 0, sizeof(able)); n   } n   int idx(int c) { return c; } n   void insert(int *s) { n     int u = 0, n = 31; n     for (int i = 0; i < n; i++) { n       able[u]++; n       int c = idx(s[i]); n       if (!ch[u][c]) { n         val[sz] = 0; n         ch[u][c] = sz++; n       } n       u = ch[u][c]; n     } n     able[u]++; n     val[u]++; n   } n   void del(int *s) { n     int u = 0, n = 31; n     for (int i = 0; i < n; i++) { n       able[u]--; n       int c = idx(s[i]); n       u = ch[u][c]; n     } n     able[u]--; n     val[u]--; n   } n   int find_min(int *s) { n     int u = 0, i = 1, num = 0; n     int k = 0; n     int r = 0; n     for (k = 0; k < 31; k++) { n       int y = idx(s[k]); n       int x = y ^ 1; n       able[u]--; n       if (ch[u][y] && able[ch[u][y]] > 0) { n         u = ch[u][y]; n       } else { n         r += 1 << (30 - k); n         u = ch[u][x]; n       } n     } n     able[u]--; n     val[u]--; n     return r; n   } n } trie; n int a[maxn], p[maxn], n, s[maxn]; n int main(void) { n   scanf( %d , &n); n   trie.init(); n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n   } n   for (int i = 0; i < n; i++) { n     scanf( %d , &p[i]); n     tran2(p[i], s); n     trie.insert(s); n   } n   int tmp; n   for (int i = 0; i < n; i++) { n     tran2(a[i], s); n     tmp = trie.find_min(s); n     printf( %d  , tmp); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 4 * 100000 + 10; n char ss[MAXN]; n int main() { n   scanf( %s , ss); n   int cis; n   int len = strlen(ss); n   int l = len; n   for (int i = 0; i < len; i++) { n     ss[i + len] = ss[i]; n   } n   len = strlen(ss); n   int ans = 1; n   int maxx = 1; n   for (int i = 1; i < len; i++) { n     if (ss[i] != ss[i - 1]) { n       maxx++; n       int dadasdsadadsadada; n       ans = max(ans, maxx); n     } else { n       int sdd; n       maxx = 1; n     } n   } n   ans = min(ans, l); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, ptr; n bool mark[100010]; n bool bad[100010]; n int ord[100010]; n vector<int> dir[100010]; n vector<int> rev[100010]; n vector<int> adj[100010]; n bool dfs(int idx) { n   bool ret = bad[idx]; n   mark[idx] = true; n   for (int i = 0; i < adj[idx].size(); i++) n     if (!mark[adj[idx][i]]) ret |= dfs(adj[idx][i]); n   return ret; n } n void setOrd(int idx) { n   mark[idx] = true; n   for (int i = 0; i < dir[idx].size(); i++) n     if (!mark[dir[idx][i]]) setOrd(dir[idx][i]); n   ord[--ptr] = idx; n } n int ccf(int idx) { n   int cnt = 1; n   mark[idx] = true; n   for (int i = 0; i < rev[idx].size(); i++) n     if (!mark[rev[idx][i]]) cnt += ccf(rev[idx][i]); n   return cnt; n } n int main() { n   cin >> n >> m; n   ptr = n; n   int a, b; n   for (int i = 0; i < m; i++) { n     cin >> a >> b; n     a--, b--; n     dir[a].push_back(b); n     rev[b].push_back(a); n     adj[a].push_back(b); n     adj[b].push_back(a); n   } n   int res = n; n   for (int i = 0; i < n; i++) n     if (!mark[i]) setOrd(i); n   memset(mark, false, sizeof mark); n   for (int i = 0; i < n; i++) { n     if (!mark[ord[i]]) { n       int tmp = ccf(ord[i]); n       if (tmp > 1) bad[ord[i]] = true; n     } n   } n   memset(mark, false, sizeof mark); n   for (int i = 0; i < n; i++) n     if (!mark[i] && !dfs(i)) res--; n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n static int io_sync_off = []() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   return 0; n }(); n long long Pow(long long a, long long b, long long mod) { n   long long res = 1; n   a %= mod; n   while (b) { n     if (b & 1) (res *= a) %= mod; n     (a *= a) %= mod; n     b >>= 1; n   } n   return res % mod; n } n long long inv(long long a, long long p) { n   if (a == 1) return 1; n   return (p - p / a) * inv(p % a, p) % p; n } n long long C(long long n, long long m, long long p) { n   long long res = 1; n   for (long long i = 1, j = n - m + 1; i <= m; ++i, ++j) { n     res = res * inv(i, p) % p * j % p; n   } n   return res; n } n const int N = 2e5 + 10; n struct M { n   bool operator<(const M &t) const { return x < t.x; } n   int x, y, z; n }; n long long Max[N * 4], tag[N * 4]; n void push_down(int o) { n   int lc = 2 * o, rc = 2 * o + 1; n   tag[lc] += tag[o]; n   tag[rc] += tag[o]; n   Max[lc] += tag[o]; n   Max[rc] += tag[o]; n   tag[o] = 0; n } n void update(int a, int b, int v, int o, int l, int r) { n   if (a == b) return; n   if (a <= l && b >= r) { n     tag[o] += v; n     Max[o] += v; n     return; n   } n   push_down(o); n   int mid = (l + r) >> 1, lc = 2 * o, rc = 2 * o + 1; n   if (a < mid) update(a, b, v, lc, l, mid); n   if (b > mid) update(a, b, v, rc, mid, r); n   Max[o] = max(Max[lc], Max[rc]); n } n M Mon[N]; n pair<long long, long long> a[N], b[N]; n int d[N]; n void build(int o, int l, int r) { n   if (r - l == 1) { n     Max[o] = -b[l].second; n     return; n   } n   int mid = (l + r) >> 1, lc = 2 * o, rc = 2 * o + 1; n   build(lc, l, mid); n   build(rc, mid, r); n   Max[o] = max(Max[lc], Max[rc]); n } n int main() { n   int n, m, p; n   scanf( %d%d , &n, &m); n   scanf( %d , &p); n   for (int i = 0; i < n; ++i) scanf( %d%d , &a[i].first, &a[i].second); n   for (int i = 0; i < m; ++i) scanf( %d%d , &b[i].first, &b[i].second); n   for (int i = 0; i < p; ++i) scanf( %d%d%d , &Mon[i].x, &Mon[i].y, &Mon[i].z); n   sort(a, a + n); n   sort(b, b + m); n   sort(Mon, Mon + p); n   for (int i = 0; i < m; ++i) d[i] = b[i].first; n   build(1, 0, m); n   long long ans = -1e18; n   int j = 0; n   for (int i = 0; i < n; ++i) { n     while (j < p && Mon[j].x < a[i].first) { n       int l = upper_bound(d, d + m, Mon[j].y) - d; n       update(l, m, Mon[j++].z, 1, 0, m); n     } n     ans = max(ans, Max[1] - a[i].second); n   } n   printf( %lld , ans); n   return 0; n } n


/*   n      _/_/_/_/_/_/  _/_/_/_/_/  _/_/_/_/_/  _/_/_/_/_/  _/_/_/_/_/  _/   _/ n       _/      _/  _/          _/          _/      _/  _/      _/  _/  _/ n      _/      _/  _/_/_/      _/_/_/      _/_/_/_/_/  _/_/_/_/_/  _/_/ n     _/      _/  _/          _/          _/          _/      _/  _/  _/ n  _/_/_/_/_/_/  _/_/_/_/_/  _/_/_/_/_/  _/          _/      _/  _/    _/ n */ n  n #include<bits/stdc++.h> n #include<math.h> n #define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); n #define int             long long n #define test            int t; cin>>t; while(t--) n #define vi              vector<int> v; n #define pb              push_back n #define input(arr)      int n; cin>>n; int arr[n]; for(int i=0; i<n; i++) {cin>>arr[i];} n #define f(n)            for(int i=0; i<n; i++) n #define OK              if(ok){cout<< YES <<endl;} else{cout<< NO <<endl;} n #define Ok              if(ok){cout<< Yes <<endl;} else{cout<< No <<endl;} n #define mod             1000000007 n #define endl   n  n using namespace std; n //----------------------------------------------------------------------------- n   n // to check prime number IN O(sqrt(n)) n //bool isPrime(int); n // n //// to get divisors of a number IN O(sqrt(n)) n //vector<int> divisors(int); n // n //// to find power using mod using Binary Exponential in TC O(logn) n //int power(int, int, int); n // n //// ternary search to find x in sorted array arr n //int ts(int, int, int, int); n // n //// to find frequencies of a substring in a string or to find all positions of all substrings n //vector<int> count_freq(string ,string); n // n ////to check palindrome n //bool palindrome(int, int); n //   #ifndef ONLINE_JUDGE n // if (fopen( input.txt ,  r )) n // { n //  freopen( input.txt ,  r , stdin); n //  freopen( output.txt ,  w , stdout); n // } n // #endif n   n //************************************************************************************************* n  n vector<int> printDivisors(int n, int temp)  n {  n   vector<int> vec; n     // Note that this loop runs till square root  n     for (int i=1; i<=sqrt(n); i++)  n     {  n         if (n%i == 0)  n         {  n             // If divisors are equal, print only one  n             if (n/i == i)  n             { n               if(i >= temp) n                 vec.pb(i); n             }  n    n             else // Otherwise print both  n             { n               if(i >= temp) n                 vec.pb(i); n               if((n/i) >= temp) n                 vec.pb(n/i); n             }  n         }  n     }  n     return vec; n } n  n int32_t main() n { n   IOS n   #ifndef ONLINE_JUDGE n  if (fopen( input.txt ,  r )) n  { n   freopen( input.txt ,  r , stdin); n   freopen( output.txt ,  w , stdout); n  } n  #endif n  n   test n   { n     int n; n     cin >> n; n     int arr[n]; n     int temp = 0; n     int sum = 0; n     f(n) n     { n       cin >> arr[i]; n       sum += arr[i]; n       temp = max(temp, arr[i]); n     } n  n     vector<int> v = printDivisors(sum, temp); n     sort(v.begin(), v.end()); n  n     int ans = 0; n     int j=0, add=0; n     int t1 = v[j]; n  n     for(int i=0; i<n; i++) n     { n       if(arr[i] != t1) n       { n         add += arr[i]; n         n          n         ans++; n         if(add > t1) n         { n           ans = 0; n           add = 0; n           i = -1; n           ++j; n           t1 = v[j]; n         } n         else if(add == t1) n         { n           ans--; n           add = 0; n         } n       } n       else if(add > 0) n       { n         add = 0; n         ans = 0; n         i = -1; n         ++j; n         t1 = v[j]; n       } n     } n     cout << ans << endl; n   } n   return 0; n } n  n  n //****************************************************************************** n   n //getchar() - uses for no extra comments in output section n //toupper() - converts a string in uppercase n //tolower() n //lower_bound((a, a+n, m)-a) - when you have to find total number of small values to m b/w range of a to a+n n //   or finds the lower position of num. eg 10 20 30 30 30 40 50 num=30, ans = 2; n //upper_bound - work as lower_bound but finds the upper position. eg 10 20 30 30 30 40 50 num=30, ans = 5;  n //shift+f6+enter - to change a word everywhere n //stringstream - to find number of words in a string or to find frequency of words n //s.substr(1, 3) - geeks - eek n //*max_element(v+2, v+4) - to find max element in an array n //*min_element n //__gcd(2, 10) - to find greatest common devisor, doesn t support float or double n //count(a, a+n, k) - to find frequency of k or frequency of a char in string in an array or in vector n //s =  aaaaa , a[2]++, s = aabaa n //compare() - to campare to string s size n //__builtin_popcountll(n) - number of bit 1 in n n //__builtin_ctzll(n) - number of bit 0 after last 1 n //cout<<fixed()<<setprecision(k)<<endl; n //log(n) - to find digits in binary repersatation, returns float value n //floor(1.3) - 3, floor(-1.2) - -2 n   n //****************************************************************************** n   n   n   n   n //// to check prime number n //bool isPrime(int n)  //IN  O(sqrt(n)) n //{ n //    if(n<=1) return false; n //    for(int i=2;i*i<=n;i++) n //        if(n%i==0) n //            return false; n // n //    return true; n //} n // n //// to get divisors of a number. Recall - it s not i sorted order n //// vector<int> v = divisors(n); function call n //vector<int> divisors(int n){    //IN  O(sqrt(n)) n // n //    vector<int> v; n //    for(int i=1;i*i<=n;i++) n //    { n //        if(n%i==0) n //        { n //            v.pb(i); n //            if((n/i)!=i) n //            v.pb(n/i); n //        } n //    } n //    return v; n //} n // n //// to find power using mod n //int power(int a, int n, int m)  // using Binary Exponential in TC O(logn) n //{ n //    int res=1; n //    while(n) n //    { n //        if(n%2) n //        res=(res*a)%m ,n--; n //        else n //        a=(a*a)%m ,n/=2; n //    } n //    return res; n //} n // n //// ternary search to find x in sorted array arr n //int ts(int arr[],int l,int r,int x) n //{ n // n //    while(l<=r) n //    { n //        int mid1= l+(r-l)/3; n //        int mid2= r -(r-l)/3; n //        if(arr[mid1]==x || arr[mid2]==x) n //            return 1; n //        if(x<arr[mid1]) n //            r=mid1-1; n //        else if(x>arr[mid2]) n //            l=mid2+1; n //        else n //        { n //            l=mid1+1; n //            r=mid2-1; n //        } n //    } n //    return 0; n //} n // n //// to find frequencies of a substring in a string or to find all positions of all substrings n //// vector<int> v = count_freq(s1 ,s2); function calling n //// position storing is 0 based indexing add 1 if required 1 based indexing. n ////This code is used to count the frequency of particular substring in a given string using the found function n //vector<int> count_freq(string &str ,string &substr) n //{ n // vector<int>pos; n // size_t found = str.find(substr,0); n // while(found!=string::npos) n // { n //  pos.pb(found); n //  found=str.find(substr,found+1); n //    } n //    return pos; n //} n // n // n //bool palindrome(int arr[], int n) n //{ n //    int flag = 0; n //    for (int i = 0; i <= n / 2 && n != 0; i++) { n //        if (arr[i] != arr[n - i - 1]) { n //            flag = 1; n //            break; n //        } n //    } n //    if (flag == 1) n //        return true; n //    else n //        return false; n //} n  n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int b, k; n   cin >> b >> k; n   int ans = 0; n   for (int i = 1; i <= k; i++) { n     int x; n     cin >> x; n     if (i != k) n       ans = (ans + b * x % 2) % 2; n     else n       ans = (ans + x % 2) % 2; n   } n   if (ans % 2 == 0) { n     cout <<  even ; n   } else n     cout <<  odd ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 105; n int n, m; n map<string, int> h; n string name[N], str[N], re[N]; n bool f[N][N]; n int g[N][N]; n void print(int x, int y) { n   if (x == 0) { n     return; n   } n   print(x - 1, g[x][y]); n   cout << name[y] << re[x - 1] << endl; n } n void work() { n   scanf( %d , &n); n   h.clear(); n   for (int i = 0; i < n; ++i) { n     cin >> name[i]; n     h[name[i]] = i; n   } n   scanf( %d n , &m); n   memset(f, 0, sizeof(f)); n   memset(g, 0, sizeof(g)); n   f[0][n] = 1; n   for (int i = 0; i < m; ++i) { n     getline(cin, str[i]); n     re[i].clear(); n   } n   for (int i = 0; i < m; ++i) { n     string usr, buf = str[i]; n     int p = 0; n     while (p < buf.size() && buf[p] !=  : ) { n       usr += buf[p++]; n     } n     int q = p; n     while (q < buf.size()) { n       re[i] += buf[q++]; n     } n     set<int> mention; n     while (p < buf.size()) { n       string word; n       while (p < buf.size() && isalnum(buf[p])) { n         word += buf[p++]; n       } n       if (h.count(word)) { n         mention.insert(h[word]); n       } n       if (p < buf.size()) ++p; n     } n     if (usr ==  ? ) { n       for (int j = 0; j <= n; ++j) { n         if (!f[i][j]) continue; n         for (int k = 0; k < n; ++k) { n           if (mention.count(k) || k == j) continue; n           f[i + 1][k] = 1; n           g[i + 1][k] = j; n         } n       } n     } else { n       if (!h.count(usr)) { n         puts( Impossible ); n         return; n       } n       int id = h[usr]; n       if (!mention.count(id)) { n         for (int j = 0; j <= n; ++j) { n           if (f[i][j] && id != j) { n             f[i + 1][id] = 1; n             g[i + 1][id] = j; n           } n         } n       } n     } n   } n   int x = -1; n   for (int i = 0; i < n; ++i) { n     if (f[m][i]) { n       x = i; n     } n   } n   if (x == -1) { n     puts( Impossible ); n   } else { n     print(m, x); n   } n } n int main() { n   int T; n   scanf( %d , &T); n   while (T--) { n     work(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int l, b, M, N; n   cin >> M; n   cin >> N; n   l = std::max(M, N); n   b = std::min(M, N); n   if (b >= 2) { n     cout << (b * (l / 2) + (b / 2) * (l % 2)); n   } else n     cout << (b * (l / 2)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int xa[300005] = {0}; n   for (int i = 1; i <= 300000; i++) { n     xa[i] = (xa[i - 1] ^ i); n   } n   int t; n   cin >> t; n   while (t--) { n     long long a, b; n     cin >> a >> b; n     long long x = xa[a - 1]; n     if (x == b) { n       cout << a << endl; n     } else { n       if ((x ^ b) == a) { n         cout << a + 2 << endl; n       } else { n         cout << a + 1 << endl; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, x[101]; n double e[2][101 * 1001], sume[101 * 1001]; n int main(int argc, const char* argv[]) { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) scanf( %d , x + i); n   if (m == 1) { n     puts( 1.00 ); n     return 0; n   } n   int cur = 0, pre = 1; n   e[pre][0] = m - 1; n   for (int i = 0; i < n; i++) { n     cur = i % 2; n     pre = 1 - cur; n     sume[0] = e[pre][0]; n     for (int j = 1; j <= (i + 1) * m; j++) sume[j] = sume[j - 1] + e[pre][j]; n     for (int s = 0; s <= (i + 1) * m; s++) { n       int l, r; n       if (s >= 1) { n         l = max(s - m, 0), r = s - 1; n         if (l - 1 >= 0) n           e[cur][s] = sume[r] - sume[l - 1]; n         else n           e[cur][s] = sume[r]; n         if (l <= s - x[i] && s - x[i] <= r) e[cur][s] -= e[pre][s - x[i]]; n         e[cur][s] /= (double)(m - 1.0); n       } else n         e[cur][s] = 0; n     } n   } n   int sum = 0; n   double ans = 0; n   for (int i = 0; i < n; i++) sum += x[i]; n   for (int i = 0; i < sum; i++) ans += e[cur][i]; n   printf( %.9lf n , ans + 1.0); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b, c, d, e, tp, f, g, h, p[100], pi, q[100], qi, pas; n map<pair<long long, long long>, long long> m; n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   cin >> a; n   for (b = 1; b <= a; b++) { n     cin >> tp; n     if (tp == 1) { n       cin >> c >> d >> e; n       pi = 0; n       while (c > 0) { n         pi++; n         p[pi] = c % 2; n         c /= 2; n       } n       c = d; n       for (d = 1; d <= pi / 2; d++) { n         swap(p[d], p[pi - d + 1]); n       } n       d = c; n       qi = 0; n       while (d > 0) { n         qi++; n         q[qi] = d % 2; n         d /= 2; n       } n       for (d = 1; d <= qi / 2; d++) { n         swap(q[d], q[qi - d + 1]); n       } n       c = 0; n       f = 0; n       for (d = 1; d <= min(pi, qi); d++) { n         if (p[d] == q[d]) { n           g = c; n           if (p[d] == 0) n             c = c * 2; n           else n             c = c * 2 + 1; n         } else { n           break; n         } n       } n       f = d; n       h = c; n       for (d = f; d <= pi; d++) { n         g = c; n         if (p[d] == 0) n           c = c * 2; n         else n           c = c * 2 + 1; n         m[make_pair(g, c)] += e; n       } n       c = h; n       for (d = f; d <= qi; d++) { n         g = c; n         if (q[d] == 0) n           c = c * 2; n         else n           c = c * 2 + 1; n         m[make_pair(g, c)] += e; n       } n     } else { n       cin >> c >> d; n       pas = 0; n       pi = 0; n       while (c > 0) { n         pi++; n         p[pi] = c % 2; n         c /= 2; n       } n       c = d; n       for (d = 1; d <= pi / 2; d++) { n         swap(p[d], p[pi - d + 1]); n       } n       d = c; n       qi = 0; n       while (d > 0) { n         qi++; n         q[qi] = d % 2; n         d /= 2; n       } n       for (d = 1; d <= qi / 2; d++) { n         swap(q[d], q[qi - d + 1]); n       } n       c = 0; n       f = 0; n       for (d = 1; d <= min(pi, qi); d++) { n         if (p[d] == q[d]) { n           g = c; n           if (p[d] == 0) n             c = c * 2; n           else n             c = c * 2 + 1; n         } else { n           break; n         } n       } n       f = d; n       h = c; n       for (d = f; d <= pi; d++) { n         g = c; n         if (p[d] == 0) n           c = c * 2; n         else n           c = c * 2 + 1; n         pas = pas + m[make_pair(g, c)]; n       } n       c = h; n       for (d = f; d <= qi; d++) { n         g = c; n         if (q[d] == 0) n           c = c * 2; n         else n           c = c * 2 + 1; n         pas = pas + m[make_pair(g, c)]; n       } n       cout << pas << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 7; n const int K = 20; n int go[N][K]; n int tin[N], tout[N]; n vector<int> g[N]; n int timer = 0; n int perm[N]; n int where[N]; n pair<int, int> t[4 * N]; n int n; n void dfs(int u, int p = 0) { n   go[u][0] = p; n   tin[u] = timer++; n   for (int i = 1; i < K; ++i) { n     go[u][i] = go[go[u][i - 1]][i - 1]; n   } n   for (auto v : g[u]) { n     if (v != p) { n       dfs(v, u); n     } n   } n   tout[u] = timer++; n } n bool anc(int a, int b) { return tin[a] <= tin[b] && tout[b] <= tout[a]; } n int lca(int a, int b) { n   if (anc(a, b)) return a; n   for (int k = K - 1; k >= 0; --k) { n     if (!anc(go[a][k], b)) { n       a = go[a][k]; n     } n   } n   return go[a][0]; n } n pair<int, int> null = {-1, -1}; n pair<int, int> empt = {-2, -2}; n int d; n bool on_path(int a, int b, int c) { n   return anc(d, c) && (anc(c, a) || anc(c, b)); n } n bool check(int l, int r, const pair<int, int> &a, const pair<int, int> &b) { n   d = lca(l, r); n   return on_path(l, r, a.first) && on_path(l, r, a.second) && n          on_path(l, r, b.first) && on_path(l, r, b.second); n } n pair<int, int> merge(const pair<int, int> &a, const pair<int, int> &b) { n   if (a == null || b == null) return null; n   if (a == empt) return b; n   if (b == empt) return a; n   if (check(a.first, a.second, a, b)) return a; n   if (check(b.first, b.second, a, b)) return b; n   if (check(a.first, b.first, a, b)) return {a.first, b.first}; n   if (check(a.second, b.second, a, b)) return {a.second, b.second}; n   if (check(a.first, b.second, a, b)) return {a.first, b.second}; n   if (check(a.second, b.first, a, b)) return {a.second, b.first}; n   return null; n } n void build(int l, int r, int v) { n   if (l == r) { n     t[v] = {where[l], where[l]}; n   } else { n     int m = (l + r) >> 1; n     build(l, m, 2 * v + 1); n     build(m + 1, r, 2 * v + 2); n     t[v] = merge(t[2 * v + 1], t[2 * v + 2]); n   } n } n void modify(int ind, int l, int r, int v) { n   if (l == r) { n     t[v] = {where[ind], where[ind]}; n   } else { n     int m = (l + r) >> 1; n     if (ind <= m) n       modify(ind, l, m, 2 * v + 1); n     else n       modify(ind, m + 1, r, 2 * v + 2); n     t[v] = merge(t[2 * v + 1], t[2 * v + 2]); n   } n } n void update(int a, int b) { n   int pa = perm[a]; n   int pb = perm[b]; n   swap(where[perm[a]], where[perm[b]]); n   swap(perm[a], perm[b]); n   modify(pa, 0, n - 1, 0); n   modify(pb, 0, n - 1, 0); n } n int get(int l, int r, int v, pair<int, int> &pth) { n   if (l == r) { n     pth = merge(pth, t[v]); n     if (pth == null) return l - 1; n     return l; n   } n   int m = (l + r) >> 1; n   auto cur = merge(pth, t[2 * v + 1]); n   if (cur.first != -1) { n     return get(m + 1, r, 2 * v + 2, cur); n   } n   return get(l, m, 2 * v + 1, pth); n } n int mex() { n   pair<int, int> cur = empt; n   return get(0, n - 1, 0, cur) + 1; n } n void init() { n   cin >> n; n   for (int i = 0; i < n; ++i) { n     cin >> perm[i]; n     where[perm[i]] = i; n   } n   for (int i = 1; i < n; ++i) { n     int p; n     cin >> p; n     --p; n     g[p].push_back(i); n   } n   dfs(0); n   build(0, n - 1, 0); n } n void solve() { n   int q; n   cin >> q; n   while (q--) { n     int t; n     cin >> t; n     if (t == 1) { n       int a, b; n       cin >> a >> b; n       --a, --b; n       update(a, b); n     } else { n       cout << mex() <<   n ; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.setf(ios::fixed); n   cout.precision(20); n   init(); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2e5 + 7; n int n; n int tmp[N]; n int a[N], val[N], sta[N]; n int dpl[N], dpr[N]; n void init(int n, int *dp) { n   int top = 0; n   int mx = 0; n   for (int i = 1; i <= n; i++) { n     int ma = 0; n     while (top && a[sta[top]] > a[i]) { n       ma = max(ma, val[top]); n       top--; n     } n     sta[++top] = i; n     if (ma == 0) n       val[top] = top; n     else n       val[top] = ma + 1; n     mx = max(mx, val[top]); n     dp[i] = mx; n   } n } n int main() { n   scanf( %d , &n); n   if (n == 1) { n     printf( %d %d n , 1, 0); n     return 0; n   } n   int mi = 1e9, rt; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &tmp[i]); n     if (tmp[i] < mi) mi = tmp[i], rt = i; n   } n   for (int i = 1, j = rt - 1; i < n; i++, j--) { n     if (j < 1) j += n; n     a[i] = tmp[j]; n   } n   init(n - 1, dpl); n   for (int i = 1, j = rt + 1; i < n; i++, j++) { n     if (j > n) j -= n; n     a[i] = tmp[j]; n   } n   init(n - 1, dpr); n   int ans = 1e9, shft; n   for (int i = 0; i < n; i++) { n     if (ans > max(dpl[i], dpr[n - 1 - i]) + 1) { n       ans = max(dpl[i], dpr[n - 1 - i]) + 1; n       shft = rt - (i + 1); n     } n   } n   if (shft < 0) shft += n; n   printf( %d %d n , ans, shft); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1000010; n char s[maxn]; n int tp[maxn >> 3], sz[maxn >> 3], n, cnt; n long long ans; n int main() { n   scanf( %d , &n); n   int l; n   for (int i = 1; i <= n; i++) { n     scanf( %s , s + 1); n     l = strlen(s + 1); n     for (int k = 1; k <= l; k++) tp[i] ^= (1 << (int)(s[k] -  a )); n   } n   sort(tp + 1, tp + 1 + n); n   cnt = 1; n   for (int i = 1; i <= n; i++) { n     if (tp[i] != tp[cnt]) tp[++cnt] = tp[i]; n     ++sz[cnt]; n   } n   for (int i = 1; i <= cnt; i++) { n     ans += 1LL * (sz[i] - 1) * sz[i] >> 1; n     for (int k = 0; k <= 25; k++) n       if (!((1 << k) & tp[i])) { n         int c = tp[i] | (1 << k); n         int p = lower_bound(tp + 1, tp + 1 + cnt, c) - tp; n         if (tp[p] != c) continue; n         ans += 1LL * sz[i] * sz[p]; n       } n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct comp1 { n   bool operator()(const long long &a, const long long &b) { return (a > b); } n }; n typedef struct node { n   long long num; n   vector<node *> des; n } node; n int n; n long long arr[8]; n int best; n node *root; n vector<node *> imp; n bool prime[1000000 + 1]; n set<long long> primes; n int breakInto(long long num) { n   if (num == 0) return 0; n   int cnt = 0; n   for (set<long long>::iterator i = primes.begin(); i != primes.end(); i++) { n     while (num % (*i) == 0) { n       cnt++; n       num /= (*i); n     } n     if (num == 1) break; n   } n   return cnt; n } n int count(node *curr) { n   int cnt = 0; n   if (curr->des.size() == 0) { n     int ret = breakInto(curr->num); n     if (ret == 1) n       return 1; n     else n       return ret + 1; n   } n   cnt = 1 + breakInto(curr->num); n   for (int i = 0; i < curr->des.size(); i++) cnt += count(curr->des[i]); n   return cnt; n } n void print(node *curr) { n   cout << curr->num <<  : ; n   for (int i = 0; i < curr->des.size(); i++) print(curr->des[i]); n } n void recurse(int i) { n   if (i == 0) { n     root = new node(); n     root->num = arr[0]; n     imp.push_back(root); n     recurse(i + 1); n     root->num = 0; n     node *nnode = new node(); n     nnode->num = arr[0]; n     root->des.push_back(nnode); n     imp.push_back(nnode); n     recurse(i + 1); n     return; n   } n   if (i == n) { n     best = min(best, count(root)); n     return; n   } n   for (int j = 0; j < imp.size(); j++) { n     long long nnum = imp[j]->num; n     if (nnum % arr[i] == 0) { n       node *nnode = new node(); n       nnode->num = arr[i]; n       imp[j]->des.push_back(nnode); n       imp.push_back(nnode); n       imp[j]->num /= arr[i]; n       recurse(i + 1); n       imp[j]->num *= arr[i]; n       imp[j]->des.pop_back(); n       imp.pop_back(); n     } n   } n } n void precompute(void) { n   for (int i = 0; i <= 1000000; i++) prime[i] = 1; n   prime[0] = prime[1] = 0; n   for (int i = 2; i * i <= 1000000; i++) { n     for (int j = i * i; j <= 1000000; j += i) prime[j] = 0; n   } n } n int main() { n   best = 1000; n   root = NULL; n   precompute(); n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %I64d , &arr[i]); n   sort(arr, arr + n, comp1()); n   for (int i = 0; i < n; i++) { n     long long num = arr[i]; n     for (long long j = 2; j * j <= num; j++) { n       if (prime[j]) { n         while (num % j == 0) { n           primes.insert(j); n           num /= j; n         } n       } n       if (num == 1) break; n     } n     if (num > 1) primes.insert(num); n   } n   recurse(0); n   printf( %d n , best); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 505, mod = 1e9 + 7; n long long c[N][N], s[N][N], p[N], inv[N]; n long long l, r; n long long k, ans; n long long add(long long a, long long b) { n   return a + b >= mod ? a + b - mod : a + b; n } n long long dec(long long a, long long b) { n   return a - b < 0 ? a - b + mod : a - b; n } n long long ksm(long long a, long long b) { n   long long ans = 1; n   while (b) { n     if (b & 1) ans = 1ll * ans * a % mod; n     a = 1ll * a * a % mod; n     b >>= 1; n   } n   return ans; n } n struct node { n   long long a, b; n   node() {} n   node(long long aa, long long bb) { a = aa, b = bb; } n   inline node operator+(const node& x) const { n     return node(add(a, x.a), add(b, x.b)); n   } n   inline node operator+(const long long& x) const { return node(add(a, x), b); } n   inline node operator-(const node& x) const { n     return node(dec(a, x.a), dec(b, x.b)); n   } n   inline node operator-(const long long& x) const { return node(dec(a, x), b); } n   inline node operator*(const node& x) const { n     node ans; n     ans.a = (a * x.a + b * x.b * 5) % mod; n     ans.b = (a * x.b + b * x.a) % mod; n     return ans; n   } n   inline node operator*(const long long& x) const { n     return node(a * x % mod, b * x % mod); n   } n   friend inline node operator/(const node& x, const node& y) { n     node ans, z = y; n     if (z.b != 0) z.b = mod - z.b; n     ans = x * z; n     return ans * ksm(dec(y.a * y.a % mod, y.b * y.b * 5 % mod), mod - 2); n   } n }; n node ksm(node a, long long b) { n   node ans = node(1, 0); n   while (b) { n     if (b & 1) ans = ans * a; n     a = a * a; n     b >>= 1; n   } n   return ans; n } n node sum(node a, long long b) { return (ksm(a, b + 1) - a) / (a - 1); } n node query(node x, long long l, long long r) { n   if (x.a == 1 && x.b == 0) return x * (r - l + 1); n   return sum(x, r) - sum(x, l - 1); n } n signed main() { n   scanf( %d%lld%lld , &k, &l, &r); n   l += 2, r += 2; n   p[0] = p[1] = inv[1] = 1; n   for (long long i = 2; i <= max(k, 5ll); i++) { n     p[i] = p[i - 1] * i % mod; n     inv[i] = (mod - mod / i) * inv[mod % i] % mod; n   } n   c[0][0] = c[1][0] = c[1][1] = s[0][0] = s[1][1] = 1; n   for (long long i = 2; i <= k; i++) { n     c[i][0] = 1, s[i][0] = 0; n     for (long long j = 1; j <= i; j++) n       c[i][j] = add(c[i - 1][j], c[i - 1][j - 1]), n       s[i][j] = dec(s[i - 1][j - 1], (i - 1) * s[i - 1][j] % mod); n   } n   node a = node(0, inv[5]), b = node(0, mod - inv[5]); n   node x = node(inv[2], inv[2]), y = node(inv[2], mod - inv[2]); n   for (long long i = 0; i <= k; i++) { n     node sum = node(0, 0); n     for (long long j = 0; j <= i; j++) { n       node ss = ksm(a, j) * ksm(b, i - j) * n                 query(ksm(x, j) * ksm(y, i - j), l, r) * c[i][j]; n       sum = sum + ss; n     } n     sum = sum * s[k][i]; n     ans = add(ans, sum.a); n   } n   ans = ans * ksm(p[k], mod - 2) % mod; n   printf( %lld , ans); n } n


#include<bits/stdc++.h> n #define fi first n #define se second n  n  n #define all(x) (x).begin(), (x).end() n #define rall(x) (x).rbegin(), (x).rend() n #define pb push_back n #define len(x) (int)(x).size() n typedef long long ll; n typedef long double ld; n using namespace std; n  n const int N = 1001; n const int mod = 998244353; n int g[N][N]; n int perm[N][N]; n int cnt[N][N]; n int n; n void add(int id, int val){ n     for(int x = 0; x < n; ++x){ n         cnt[x][perm[id][x]] += val; n     } n } n void md(int &a){ n     if(a >= mod) n         a-=mod; n } n void solve(){ n     cin >> n; n     for(int i = 0;  i < 2*n; ++i){ n         for(int j = 0 ; j < n; ++j){ n             cin >> perm[i][j]; n         } n         add(i , +1); n     } n     vector < bool > active(2*n, 1); n     int ans = 1; n     vector < int > answer; n     while(true){ n         bool have = 0; n         for(int x = 0; x < 2*n; ++x) n             if(active[x])have = 1; n         if(!have) n             break; n         int found = -1; n         for(int x = 0 ;x < 2 * n; ++x){ n             if(active[x]){ n                 for(int i = 0 ;i  < n; ++i){ n                     if(cnt[i][perm[x][i]] == 1){ n                         found = x; n                         break; n                     } n                 } n             } n         } n         if(found == -1){ n             ans *= 2, md(ans); n             for(int x = 0; x < 2*n; ++x) n                 if(active[x]) n                     found = x; n  n         } n         answer.pb(found); n         /// dell all shit n         for(int j = 0; j < 2*n;++j){ n             if(active[j]){ n                 bool del = 0; n                 for(int z = 0; z < n; ++z){ n                     if(perm[found][z] == perm[j][z]) n                         del = 1; n                 } n                 if(del) n                     active[j] = 0, add(j , -1); n             } n         } n     } n     cout << ans <<   n ; n     for(auto u : answer) n         cout << u + 1 <<    ; n     cout <<   n ; n } n signed main() n { n     ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); n     int t;cin >> t; n     while(t--){ n         solve(); n     } n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxN = 105; n int n, s, c[maxN], sum1, sum2; n vector<int> d; n bool cmp(int A, int B) { return A > B; } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> s; n     for (int j = 1; j <= s; j++) cin >> c[j]; n     for (int j = 1; j <= s / 2; j++) sum1 += c[j]; n     for (int j = (s + 1) / 2 + 1; j <= s; j++) sum2 += c[j]; n     if (s % 2 == 1) d.push_back(c[(s + 1) / 2]); n   } n   sort(d.begin(), d.end(), cmp); n   for (int i = 0; i < d.size(); i++) n     if (i % 2 == 0) n       sum1 += d[i]; n     else n       sum2 += d[i]; n   cout << sum1 <<     << sum2; 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   cout.tie(NULL); n   long long n, ans = 0; n   cin >> n; n   vector<int> a(n + 5), b(n + 5), c(n + 5); n   map<long long, long long> m; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= n; i++) cin >> b[i], m[b[i]] = i; n   for (int i = 0; i < n; i++) c[i + 1] = m[a[i + 1]]; n   for (int i = 0; i < n - 1; i++) n     if (c[i + 2] > c[i + 1]) n       ans++; n     else n       break; n   cout << n - ans - 1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n bool uin(T &a, T b) { n   return a <= b ? true : false; n } n template <class T> n bool uax(T &a, T b) { n   return a >= b ? true : false; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.precision(10); n   cout << fixed; n   long long H; n   int n; n   cin >> H >> n; n   vector<long long> a(n); n   long long sum = 0; n   long long gap = 0; n   long long h = H; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     sum -= a[i]; n     h += a[i]; n     if (h <= 0) { n       cout << i + 1 << endl; n       return 0; n     } n     gap = max(gap, sum); n   } n   if (sum <= 0) { n     cout << -1 << endl; n     return 0; n   } n   long long whole = (H - gap) / sum; n   H -= whole * sum; n   long long result = whole * n; n   for (int i = 0;; i++) { n     H += a[i % n]; n     result++; n     if (H <= 0) { n       cout << result << endl; n       break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long arr[1002][1002]; n long long store[2][1000002]; n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long n, m, k, p; n   cin >> n >> m >> k >> p; n   for (long long i = 1; i <= n; i++) n     for (long long j = 1; j <= m; j++) cin >> arr[i][j]; n   multiset<long long> s1, s2; n   for (long long i = 1; i <= n; i++) { n     long long s = 0; n     for (long long j = 1; j <= m; j++) s += arr[i][j]; n     s1.insert(s); n   } n   for (long long i = 1; i <= m; i++) { n     long long s = 0; n     for (long long j = 1; j <= n; j++) s += arr[j][i]; n     s2.insert(s); n   } n   for (long long i = 1; i <= k; i++) { n     long long a = *s1.rbegin(); n     store[0][i] += store[0][i - 1] + a; n     s1.erase(s1.find(a)); n     s1.insert(a - m * p); n     a = *s2.rbegin(); n     store[1][i] += store[1][i - 1] + a; n     s2.erase(s2.find(a)); n     s2.insert(a - n * p); n   } n   long long maxi = -1e18; n   for (long long i = 0; i <= k; i++) n     maxi = max(maxi, store[0][i] + store[1][k - i] - i * (k - i) * p); n   cout << maxi; n } n


#include <bits/stdc++.h> n using namespace std; n long long int arr[10000]; n int main() { n   std::ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int a, b, c, i, j, k, n, m, state = 0; n   for (i = 0; i < 6; i++) cin >> arr[i]; n   sort(arr, arr + 6); n   for (i = 0; i < 3; i++) { n     if (arr[i] == arr[i + 1] && arr[i + 1] == arr[i + 2] && n         arr[i + 2] == arr[i + 3] && state == 0) { n       state = 1; n       arr[i] = 0; n       arr[i + 1] = 0; n       arr[i + 2] = 0; n       arr[i + 3] = 0; n       break; n     } n   } n   if (state == 0) { n     cout <<  Alien  << endl; n     return 0; n   } n   long long int t1 = 0, t2 = 0; n   for (i = 0; i < 6; i++) { n     if (arr[i] != 0 && t1 == 0) n       t1 = arr[i]; n     else if (arr[i] != 0) n       t2 = arr[i]; n   } n   if (t1 == t2) n     cout <<  Elephant  << endl; n   else n     cout <<  Bear  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T Max(const T &a, const T &b) { n   return a > b ? a : b; n } n const int SN = 100000 + 10; n long long w[SN], f[SN][2], down[SN], g[SN], h[SN], head[SN]; n long long u, v, n, num; n bool vis[SN]; n struct Edge { n   int from, to, next; n } E[SN << 2]; n void Read(long long &x) { n   long long in = 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     in = in * 10 + ch -  0 ; n     ch = getchar(); n   } n   x = in * f; n } n void Add(int u, int v) { n   E[++num].from = u; n   E[num].to = v; n   E[num].next = head[u]; n   head[u] = num; n } n void dfs(int u) { n   vis[u] = 1; n   g[u] = f[u][0] = f[u][1] = down[u] = w[u]; n   for (int i = head[u]; i; i = E[i].next) { n     int to = E[i].to; n     if (vis[to]) continue; n     dfs(to); n     f[u][0] = Max(f[u][0], f[to][0]); n     f[u][0] = Max(f[u][0], f[u][1] + f[to][1]); n     f[u][0] = Max(f[u][0], g[to] + down[u]); n     f[u][0] = Max(f[u][0], down[to] + g[u]); n     f[u][1] = Max(f[u][1], f[to][1]); n     f[u][1] = Max(f[u][1], down[u] + down[to]); n     g[u] = Max(g[u], g[to] + w[u]); n     g[u] = Max(g[u], down[u] + f[to][1]); n     g[u] = Max(g[u], down[to] + w[u] + h[u]); n     h[u] = Max(h[u], f[to][1]); n     down[u] = Max(down[u], down[to] + w[u]); n   } n } n int main() { n   Read(n); n   for (int i = 1; i <= n; i++) Read(w[i]); n   for (int i = 1; i < n; i++) { n     Read(u), Read(v); n     Add(u, v), Add(v, u); n   } n   dfs(1); n   printf( %lld n , f[1][0]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n; n   cin >> n; n   vector<pair<long long, long long> > a(n); n   for (auto &x : a) cin >> x.first; n   for (auto &x : a) cin >> x.second; n   long long ans = 0; n   sort(a.begin(), a.end()); n   priority_queue<long long> pq; n   long long sum = 0; n   for (long long i = 0; i < n; ++i) { n     if (!pq.empty()) { n       long long dif = a[i].first - a[i - 1].first - 1; n       long long j = 0; n       while (!pq.empty()) { n         if (j >= dif) break; n         long long top = pq.top(); n         pq.pop(); n         ans += top * j; n         sum -= top; n         ++j; n       } n       assert(sum >= 0); n       ans += sum * dif; n     } n     long long j = i; n     while (j < n and a[i].first == a[j].first) { n       pq.push(a[j].second); n       sum += a[j].second; n       ++j; n     } n     long long top = pq.top(); n     pq.pop(); n     sum -= top; n     assert(sum >= 0); n     ans += sum; n     i = j - 1; n   } n   long long j = 0; n   while (!pq.empty()) { n     ans += pq.top() * j; n     ++j; n     pq.pop(); n   } n   cout << ans <<   n ; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t = 1; n   for (long long i = 0; i < t; ++i) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename P, typename Q> n ostream& operator<<(ostream& os, pair<P, Q> p) { n   os <<  (  << p.first <<  ,  << p.second <<  ) ; n   return os; n } n template <typename P, typename Q> n istream& operator>>(istream& is, pair<P, Q>& p) { n   is >> p.first >> p.second; n   return is; n } n template <typename T> n ostream& operator<<(ostream& os, vector<T> v) { n   os <<  ( ; n   for (auto& i : v) os << i <<  , ; n   os <<  ) ; n   return os; n } n template <typename T> n istream& operator>>(istream& is, vector<T>& v) { n   for (auto& i : v) is >> i; n   return is; n } n int f(string s) { n   int cnt = 0; n   for (int i = 0; i < s.size(); ++i) { n     for (int j = 0; j <= s.size(); ++j) { n       string t; n       for (int k = i; k < j; ++k) { n         t += s[k]; n       } n       if (t.size()) { n         string u = t; n         reverse(u.begin(), u.end()); n         cnt += (t == u); n       } n     } n   } n   return cnt; n } n void fn() { n   cout << f( ghghghg ) <<     << f( gggghhh ) << endl; n   cout << f( llooo ) <<     << f( ololo ) << endl; n   cout << f( gagadbcgghhchbdf ) <<     << f( abccbaghghghgdfd ) <<     n        << f( aabbccddfgggghhh ) << endl; n } n int main(int argc, char* argv[]) { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   string s; n   while (cin >> n >> s) { n     sort(s.begin(), s.end()); n     cout << s << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 105; n int n; n string s[MAXN]; n string ans =   ; n vector<int> g[MAXN]; n bool has[MAXN]; n bool used[MAXN]; n vector<int> tp; n void dfs(int v) { n   used[v] = true; n   for (int i = 0; i < g[v].size(); i++) { n     int to = g[v][i]; n     if (!used[to]) dfs(to); n   } n   tp.push_back(v); n } n void dfs2(int v) { n   used[v] = true; n   ans.append(1, (char)( a  + v)); n   for (int i = 0; i < (int)g[v].size(); i++) { n     int to = g[v][i]; n     if (!used[to]) dfs2(to); n   } n } n int main() { n   scanf( %d n , &n); n   for (int i = 1; i <= n; i++) { n     getline(cin, s[i]); n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j < s[i].length(); j++) { n       has[s[i][j] -  a ] = true; n       if (j + 1 < s[i].length()) { n         int from = s[i][j] -  a ; n         int to = s[i][j + 1] -  a ; n         g[from].push_back(to); n       } n     } n   } n   for (int i = 0; i < 26; i++) { n     if (has[i] && !used[i]) { n       dfs(i); n     } n   } n   reverse(tp.begin(), tp.end()); n   memset(used, false, sizeof(used)); n   for (int i = 0; i < (int)tp.size(); i++) { n     int cur = tp[i]; n     if (!used[cur]) dfs2(cur); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n int n; n long long l[100001], r[100001], ans = 0; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %I64d%I64d , &l[i], &r[i]); n   std::sort(l + 1, l + n + 1); n   std::sort(r + 1, r + n + 1); n   for (int i = 1; i <= n; i++) { n     ans += l[i] > r[i] ? l[i] : r[i]; n   } n   printf( %I64d n , ans + 1ll * n); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a, b, men, may; n vector<pair<int, int> > arr; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   men = 1000000009; n   for (int i = 0; i < n; i++) { n     cin >> a >> b; n     arr.push_back(make_pair(a, b)); n     men = min(a, men); n     may = max(may, b); n   } n   for (int i = 0; i < n; i++) { n     if (arr[i].first == men && arr[i].second == may) { n       cout << i + 1; n       return 0; n     } n   } n   cout << -1; n } n


#include <bits/stdc++.h> n using namespace std; n const long long Max = 2e5 + 9, inf = 1e18; n long long A[Max], B[Max], d[Max]; n int find_nxt(long long id, long long x) { n   if (A[id] - B[id] >= x) return B[id] += x, id; n   d[id] = find_nxt(d[id], x - A[id] + B[id]), B[id] = A[id]; n   return d[id]; n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   long long n, m, a, id, x; n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> A[i], d[i] = i + 1; n   A[n + 1] = inf; n   cin >> m; n   while (m--) { n     cin >> a >> id; n     if (a == 1) { n       cin >> x; n       find_nxt(id, x); n     } else n       cout << B[id] <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100005; n int c1[MAXN], c2[MAXN]; n vector<pair<int, int> > ans; n int main() { n   int n; n   scanf( %d , &n); n   int in, winner; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &in); n     if (i == n) winner = in; n     c1[i] = c1[i - 1] + (in == 1); n     c2[i] = c2[i - 1] + (in == 2); n   } n   for (int t = 1; t <= n; t++) { n     int w1 = 0, w2 = 0, loc = 0; n     while (loc < n) { n       int loc1 = lower_bound(c1, c1 + n + 1, c1[loc] + t) - c1; n       int loc2 = lower_bound(c2, c2 + n + 1, c2[loc] + t) - c2; n       loc = min(loc1, loc2); n       if (loc > n) break; n       if (loc1 < loc2) n         w1++; n       else n         w2++; n     } n     if (loc == n) n       if ((winner == 1 && w1 > w2) || (winner == 2 && w1 < w2)) n         ans.push_back(make_pair(max(w1, w2), t)); n   } n   sort(ans.begin(), ans.end()); n   printf( %d n , ans.size()); n   for (int i = 0; i < ans.size(); i++) n     printf( %d %d n , ans[i].first, ans[i].second); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   int n, m; n   char x; n   cin >> n >> m; n   cin >> x; n   vector<vector<char> > c(n + 1); n   char gar; n   vector<char> u1(m + 1,  . ); n   for (int j = 0; j < (n + 1); ++j) c[j] = u1; n   bool b[n][m]; n   stack<pair<int, int> > s, t; n   for (int i = 0; i < (n); ++i) { n     scanf( %c , &gar); n     for (int j = 0; j < (m); ++j) { n       scanf( %c , &c[i][j]); n       if (c[i][j] == x) s.push({i, j}); n       b[i][j] = false; n     } n   } n   while (!s.empty()) { n     auto k = s.top(); n     int u = k.first; n     int v = k.second; n     s.pop(); n     if (u > 0 && c[u - 1][v] != x) t.push({u - 1, v}); n     if (v > 0 && c[u][v - 1] != x) t.push({u, v - 1}); n     if (u + 1 < n && c[u + 1][v] != x) t.push({u + 1, v}); n     if (v + 1 < m && c[u][v + 1] != x) t.push({u, v + 1}); n   } n   int cou = 0; n   while (!t.empty()) { n     auto k = t.top(); n     t.pop(); n     int u = k.first; n     int v = k.second; n     if (c[u][v] ==  . ) continue; n     if ((u > 0 && b[u - 1][v] == 1 && c[u - 1][v] == c[u][v]) || n         (v > 0 && c[u][v - 1] == c[u][v] && b[u][v - 1] == 1) || n         (u + 1 < n && c[u + 1][v] == c[u][v] && b[u + 1][v] == 1) || n         (v + 1 < m && c[u][v + 1] == c[u][v] && b[u][v + 1] == 1)) n       b[u][v] = 1; n     else { n       cou++; n       b[u][v] = 1; n     } n   } n   cout << cou <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Rect { n   int x1, y1, x2, y2; n   long long area() { return (long long)(x2 - x1) * (y2 - y1); } n }; n long long intersect(const Rect&, const Rect&); n Rect intersectingRect(const Rect&, const Rect&); n int main() { n   Rect white, black1, black2, b1Inside, b2Inside; n   long long b1Cover, b2Cover, totalCover; n   cin >> white.x1 >> white.y1 >> white.x2 >> white.y2; n   cin >> black1.x1 >> black1.y1 >> black1.x2 >> black1.y2; n   cin >> black2.x1 >> black2.y1 >> black2.x2 >> black2.y2; n   b1Cover = intersect(white, black1); n   b2Cover = intersect(white, black2); n   b1Inside = intersectingRect(white, black1); n   b2Inside = intersectingRect(white, black2); n   totalCover = b1Cover + b2Cover - intersect(b1Inside, b2Inside); n   if (white.area() - totalCover == 0) n     cout <<  NO ; n   else n     cout <<  YES ; n } n long long intersect(const Rect& rect1, const Rect& rect2) { n   long long x = max(0, min(rect1.x2, rect2.x2) - max(rect1.x1, rect2.x1)); n   long long y = max(0, min(rect1.y2, rect2.y2) - max(rect1.y1, rect2.y1)); n   return x * y; n } n Rect intersectingRect(const Rect& rect1, const Rect& rect2) { n   Rect rect; n   if (intersect(rect1, rect2)) { n     rect.x1 = max(rect1.x1, rect2.x1); n     rect.x2 = min(rect1.x2, rect2.x2); n     rect.y1 = max(rect1.y1, rect2.y1); n     rect.y2 = min(rect1.y2, rect2.y2); n   } else { n     rect.x1 = 0; n     rect.x2 = 0; n     rect.y1 = 0; n     rect.y2 = 0; n   } n   return rect; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const int N = 2e5 + 10; n const int INF = 0x3f3f3f3f; n const long long LINF = 0x3f3f3f3f3f3f3f3f; n inline int read() { n   static char buf[1000000], *p1 = buf, *p2 = buf; n   register int x = false; n   register char ch = n       p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) n           ? EOF n           : *p1++; n   ; n   register bool sgn = false; n   while (ch !=  -  && (ch <  0  || ch >  9 )) n     ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) n              ? EOF n              : *p1++; n   ; n   if (ch ==  - ) n     sgn = true, n     ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) n              ? EOF n              : *p1++; n   ; n   while (ch >=  0  && ch <=  9 ) n     x = (x << 1) + (x << 3) + (ch ^ 48), n     ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) n              ? EOF n              : *p1++; n   ; n   return sgn ? -x : x; n } n long long fpow(long long a, int b, int mod) { n   long long res = 1; n   for (; b > 0; b >>= 1) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n   } n   return res; n } n long long h[N][2]; n char s[N]; n long long base[N]; n int cnt[N]; n long long calc(int L, int R) { n   return (h[R][L & 1] - h[L - 1][L & 1] * base[cnt[R] - cnt[L - 1]] % mod + n           mod) % n          mod; n } n int main() { n   int n, m; n   cin >> n; n   scanf( %s , s + 1); n   cin >> m; n   base[0] = 1; n   for (int i = 1; i <= n; i++) { n     base[i] = base[i - 1] * 998244353 % mod; n     cnt[i] = cnt[i - 1]; n     h[i][0] = h[i - 1][0]; n     h[i][1] = h[i - 1][1]; n     if (s[i] ==  0 ) { n       cnt[i] = cnt[i - 1] + 1; n       h[i][0] = (h[i - 1][0] * 998244353 % mod + (i & 1) + 1) % mod; n       h[i][1] = (h[i - 1][1] * 998244353 % mod + (i & 1 ^ 1) + 1) % mod; n     } n   } n   while (m--) { n     int x, y, z; n     cin >> x >> y >> z; n     if (calc(x, x + z - 1) == calc(y, y + z - 1)) n       puts( YES ); n     else n       puts( NO ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int const maxn = 4e6; n int tr01[maxn][2], x; n int len, check[maxn], n, tot; n void insert(int x) { n   int ex, v = 0; n   for (int i = 29; i >= 0; i--) { n     ex = !!(x & (1 << i)); n     if (tr01[v][ex]) n       v = tr01[v][ex]; n     else { n       tr01[v][ex] = ++tot; n       v = tot; n     } n   } n } n void init() { n   tot = 0; n   memset(tr01, 0, sizeof(tr01)); n } n int work(int x, int wei) { n   if (!tr01[x][0] && !tr01[x][1]) return 0; n   if (tr01[x][0] == 0) return work(tr01[x][1], wei - 1); n   if (tr01[x][1] == 0) return work(tr01[x][0], wei - 1); n   return (1 << wei) + min(work(tr01[x][1], wei - 1), work(tr01[x][0], wei - 1)); n } n int main() { n   scanf( %d , &n); n   init(); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &x); n     insert(x); n   } n   printf( %d n , work(0, 29)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s; n inline void YES() { n   puts( Yes ); n   exit(0); n } n inline void NO() { n   puts( No ); n   exit(0); n } n int main() { n   cin >> s; n   int n = (int)s.length(); n   string baru =   ; n   int score = 0; n   int pl = -1, mn = 1; n   for (int i = n - 1; i >= 0; i--) { n     if (s[i] ==  - ) n       score += pl; n     else n       score += mn; n     swap(mn, pl); n   } n   if (score == 0) n     YES(); n   else n     NO(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int l, r, a; n   cin >> l >> r >> a; n   int total = 0; n   while (l > 0 && r > 0) { n     l--, r--, total += 2; n   } n   while (l > 0 && a > 0) { n     l--, a--, total += 2; n   } n   while (r > 0 && a > 0) { n     r--, a--, total += 2; n   } n   if (a > 0) n     if (a % 2 == 0) n       total += a; n     else n       total += a - 1; n   cout << total; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long mod(long int a) { return (a > 0 ? a : (-a)); } n long min(long int a, long int b) { return (a) > (b) ? (b) : (a); } n long max(long int a, long int b) { return (a) < (b) ? (b) : (a); } n bool sortbyff(const pair<int, int> &a, const pair<int, int> &b) { n   return (a.first < b.first); n } n long num[1000001], t[5001][2]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long n, m, k, i, j, l, r, a = -1, b = -1, c, d, s, u, w, x = 0, y, z, sum = 0, n                             p = 0, ans = 0, M = 10000000; n   cin >> n; n   cout << n <<    ; n   for (i = 1; i < n; i++) { n     cout << i <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200 + 5; n int n, m, p[N]; n double dp[N][N][N]; n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cout << fixed << setprecision(10); n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> p[i]; n   for (int i = 0; i < n; i++) n     for (int j = i + 1; j < n; j++) dp[j][i][0] = 1; n   long double pi = n * (n + 1) / 2; n   pi = 1 / pi; n   for (int k = 1; k <= m; k++) { n     for (int i = 0; i < n; i++) n       for (int j = 0; j < n; j++) { n         if (i == j) continue; n         for (int L = 0; L < n; L++) n           for (int R = L; R < n; R++) { n             int x = i, y = j; n             if (L <= x && x <= R) x = L + R - x; n             if (L <= y && y <= R) y = L + R - y; n             dp[i][j][k] += dp[x][y][k - 1] * pi; n           } n       } n   } n   long double ans = 0; n   for (int i = 0; i < n; i++) n     for (int j = i + 1; j < n; j++) { n       if (p[i] > p[j]) n         ans += dp[j][i][m]; n       else n         ans += dp[i][j][m]; n     } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n char s[100002]; n int main() { n   cin.getline(s, 100002); n   int l = strlen(s), flag; n   for (int i = 0; i < l; i++) { n     char c = s[i]; n     if (s[i] == s[l - i - 1] && n         (c ==  A  || c ==  H  || c ==  I  || c ==  M  || c ==  O  || c ==  T  || n          c ==  U  || c ==  V  || c ==  W  || c ==  X  || c ==  Y )) n       flag = 1; n     else { n       flag = 0; n       break; n     } n   } n   if (l % 2 == 1 && flag) { n     char c = s[l / 2]; n     if (c ==  A  || c ==  H  || c ==  I  || c ==  M  || c ==  O  || c ==  T  || n         c ==  U  || c ==  V  || c ==  W  || c ==  X  || c ==  Y ) n       flag = 1; n     else n       flag = 0; n   } n   if (flag) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct res { n   double l, r, w; n } T[800000]; n double x[210000], s[210000], p, c, ans, w; n int N, M, i, l, r; n int init(int i, int l, int r, int x, double w) { n   if (x < l || r < x) return 0; n   if (l == r) { n     T[i].w = T[i].l = T[i].r = w; n     return 0; n   } n   int mid = l + r >> 1; n   init(i * 2, l, mid, x, w); n   init(i * 2 + 1, mid + 1, r, x, w); n } n int build(int i, int l, int r) { n   if (l == r) return 0; n   int mid = l + r >> 1, ls = i << 1, rs = (i << 1) + 1; n   build(ls, l, mid); n   build(rs, mid + 1, r); n   T[i].l = max(T[ls].l, s[mid] - s[l - 1] + T[rs].l); n   T[i].r = max(T[rs].r, T[ls].r + s[r] - s[mid]); n   T[i].w = n       max(T[ls].r + T[rs].l, max(max(T[ls].w, T[rs].w), max(T[i].l, T[i].r))); n } n res get(int i, int l, int r, int x, int y) { n   if (x <= l && r <= y) return T[i]; n   int mid = l + r >> 1, ls = i << 1, rs = (i << 1) + 1; n   res X; n   if (y <= mid) n     X = get(ls, l, mid, x, y); n   else if (mid < x) n     X = get(rs, mid + 1, r, x, y); n   else { n     res L = get(ls, l, mid, x, mid); n     res R = get(rs, mid + 1, r, mid + 1, y); n     X.w = max(max(L.w, R.w), L.r + R.l); n     X.l = max(L.l, s[mid] - s[x - 1] + R.l); n     X.r = max(R.r, s[y] - s[mid] + L.r); n   } n   return X; n } n int main() { n   scanf( %d%d%lf , &N, &M, &c); n   for (i = 1; i <= N; i++) scanf( %lf , &x[i]); n   --N; n   for (i = 1; i <= N; i++) { n     scanf( %lf , &p); n     w = (x[i + 1] - x[i]) / 2.0 - p * c / 100.0; n     s[i] = s[i - 1] + w; n     init(1, 1, N, i, w); n   } n   build(1, 1, N); n   while (M--) { n     scanf( %d%d , &l, &r); n     res delta = get(1, 1, N, l, r - 1); n     ans += max(0.0, delta.w); n   } n   printf( %.8lf n , ans); n } n


#include <bits/stdc++.h> n int n; n int m; n char str[3000100]; n int preveri(int x) { n   int stevec = 0; n   if (x - 1 >= 0 && str[x - 1] ==  . ) { n     stevec++; n   } n   if (x + 1 < n && str[x + 1] ==  . ) { n     stevec++; n   } n   return stevec; n } n int main() { n   scanf( %d , &n); n   scanf( %d , &m); n   scanf( %s , str); n   int vsota = 0; n   for (int i = 1; i < n; i++) { n     if (str[i - 1] ==  .  && str[i] ==  . ) { n       vsota++; n     } n   } n   for (int i = 0; i < m; i++) { n     int x; n     char c; n     scanf( %d %c , &x, &c); n     int a = preveri(x - 1); n     if (c ==  .  && str[x - 1] !=  . ) { n       vsota = vsota + a; n     } else if (c !=  .  && str[x - 1] ==  . ) { n       vsota = vsota - a; n     } n     str[x - 1] = c; n     printf( %d n , vsota); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 10, Mod = 1e9 + 7; n int n, m, k, A[N], P[N]; n map<int, int> M; n long long tot; n int main() { n   scanf( %d%d , &n, &k); n   m = (1 << k) - 1; n   for (int i = 1; i <= n; i++) n     scanf( %d , &A[i]), P[i] = P[i - 1] ^ A[i], M[min(P[i], m - P[i])]++; n   M[0]++; n   for (auto X : M) { n     int a = X.second >> 1; n     int b = X.second - a; n     tot += 1ll * a * (a - 1) / 2; n     tot += 1ll * b * (b - 1) / 2; n   } n   tot = 1ll * (n + 1) * n / 2 - tot; n   printf( %lld , tot); n   return (0); n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1000000007; n struct Interval { n   long long a, b, ind; n   bool operator<(const Interval& ano) const { return b < ano.b; } n } a[200010]; n bool used[200010]; n set<long long> st; n struct SEG { n   long long sum[1600010], tg1[1600010], tg2[1600010]; n   inline void pushup(long long u) { n     sum[u] = (sum[u << 1] + sum[u << 1 | 1]) % mod; n   } n   inline void pushdown(long long u, long long l, long long r) { n     long long mid = (l + r) >> 1; n     if (tg1[u]) { n       tg1[u << 1] = tg1[u], tg2[u << 1] = 0; n       sum[u << 1] = tg1[u] * (mid - l + 1) % mod; n       tg1[u << 1 | 1] = tg1[u], tg2[u << 1 | 1] = 0; n       sum[u << 1 | 1] = tg1[u] * (r - mid) % mod; n       tg1[u] = 0; n     } n     if (tg2[u]) { n       tg2[u << 1] = (tg2[u << 1] + tg2[u]) % mod; n       sum[u << 1] = (sum[u << 1] + (mid - l + 1) * tg2[u]) % mod; n       tg2[u << 1 | 1] = (tg2[u << 1 | 1] + tg2[u]) % mod; n       sum[u << 1 | 1] = (sum[u << 1 | 1] + (r - mid) * tg2[u]) % mod; n       tg2[u] = 0; n     } n   } n   void Build(long long u, long long l, long long r) { n     if (l == r) { n       sum[u] = tg1[u] = tg2[u] = 0; n       return; n     } n     long long mid = (l + r) >> 1; n     Build(u << 1, l, mid); n     Build(u << 1 | 1, mid + 1, r); n     pushup(u); n   } n   void Add(long long u, long long l, long long r, long long L, long long R, n            long long ad) { n     if (r < L || R < l) return; n     if (L <= l && r <= R) { n       tg2[u] = (tg2[u] + ad) % mod; n       sum[u] = (sum[u] + (r - l + 1) * ad) % mod; n       return; n     } n     pushdown(u, l, r); n     long long mid = (l + r) >> 1; n     Add(u << 1, l, mid, L, R, ad); n     Add(u << 1 | 1, mid + 1, r, L, R, ad); n     pushup(u); n   } n   void Assign(long long u, long long l, long long r, long long L, long long R, n               long long as) { n     if (r < L || R < l) return; n     if (L <= l && r <= R) { n       tg1[u] = as, tg2[u] = 0; n       sum[u] = (r - l + 1) * as % mod; n       return; n     } n     pushdown(u, l, r); n     long long mid = (l + r) >> 1; n     Assign(u << 1, l, mid, L, R, as); n     Assign(u << 1 | 1, mid + 1, r, L, R, as); n     pushup(u); n   } n   long long Query(long long u, long long l, long long r, long long L, n                   long long R) { n     if (r < L || R < l) return 0; n     if (L <= l && r <= R) return sum[u]; n     pushdown(u, l, r); n     long long mid = (l + r) >> 1, ans = 0; n     ans = Query(u << 1, l, mid, L, R); n     ans = (ans + Query(u << 1 | 1, mid + 1, r, L, R)) % mod; n     pushup(u); n     return ans; n   } n } S1, S2; n signed main() { n   long long n; n   scanf( %lld , &n); n   for (long long i = 1; i <= n; i++) n     scanf( %lld %lld , &a[i].a, &a[i].b), a[i].ind = i; n   sort(a + 1, a + n + 1); n   long long T; n   scanf( %lld , &T); n   while (T--) { n     long long x; n     scanf( %lld , &x); n     used[x] = true; n   } n   S1.Build(1, 1, n << 1), S2.Build(1, 1, n << 1); n   st.insert(2 * n); n   for (long long i = 1; i <= n; i++) { n     long long pos = *(st.lower_bound(a[i].a)); n     long long s1 = S1.Query(1, 1, n << 1, pos, pos), n               s2 = s1 - S2.Query(1, 1, n << 1, pos, pos); n     S1.Assign(1, 1, n << 1, a[i].a, a[i].a, (s1 * 2 + 1) % mod); n     if (used[a[i].ind]) n       S2.Assign(1, 1, n << 1, a[i].a, a[i].a, (s1 - s2 + mod) % mod); n     else n       S2.Assign(1, 1, n << 1, a[i].a, a[i].a, (s1 * 2 + 1 - s2 + mod) % mod); n     if (used[a[i].ind]) S2.Assign(1, 1, n << 1, 1, a[i].a - 1, mod - s2 - 1); n     S1.Add(1, 1, n << 1, 1, a[i].a - 1, (s1 + 1) % mod); n     S2.Add(1, 1, n << 1, 1, a[i].a - 1, (s1 + 1) % mod); n     st.insert(a[i].a); n   } n   printf( %lld n , n          (S1.Query(1, 1, n << 1, 1, 1) - S2.Query(1, 1, n << 1, 1, 1) + mod) % n              mod); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n class TaskD { n  public: n   void solve(std::istream &in, std::ostream &out) { n     long long n; n     in >> n; n     vector<long long> a(n), b(n), sa(n), sb(n); n     for (auto &i : a) in >> i; n     for (auto &i : b) in >> i; n     for (long long i = 0; i < n; ++i) { n       sa[i] = a[i] - b[i]; n       sb[i] = b[i] - a[i]; n     } n     sort((sa).begin(), (sa).end()); n     sort((sb).begin(), (sb).end()); n     long long ans = 0; n     for (long long i = 0; i < n; ++i) { n       ans += (long long)(sa.end() - n                          lower_bound((sa).begin(), (sa).end(), sb[i] + 1)); n       if (sb[i] < 0) ans -= 1; n     } n     out << ans / 2 << endl; n   } n }; n signed main() { n   TaskD solver; n   std::istream &in(std::cin); n   std::ostream &out(std::cout); n   solver.solve(in, out); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[400][400]; n int main() { n   int n; n   cin >> n; n   long long k = n * n; n   for (int j = 1; j <= n; j++) { n     if (j % 2 != 0) { n       for (int i = 1; i <= n; i++) { n         a[i][j] = k--; n       } n     } else { n       for (int i = n; i >= 1; i--) { n         a[i][j] = k--; n       } n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       cout << a[i][j] <<    ; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[20][110], b[20][110], c[20][110]; n vector<int> res; n int main() { n   int n, m, k; n   scanf( %d%d%d , &n, &m, &k); n   for (int i = 0; i < n; i++) { n     char st[15]; n     scanf( %s , st); n     for (int j = 0; j < m; j++) scanf( %d%d%d , &a[i][j], &b[i][j], &c[i][j]); n   } n   int ans = 0; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if (i == j) continue; n       res.clear(); n       for (int h = 0; h < m; h++) n         for (int ik = 0; ik < c[i][h]; ik++) res.push_back(b[j][h] - a[i][h]); n       sort(res.begin(), res.end()); n       reverse(res.begin(), res.end()); n       int v = 0; n       for (int kp = 0; kp < k && kp < (int)res.size(); kp++) n         v += max(res[kp], 0); n       ans = max(ans, v); n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> sorted; n vector<set<int> > v; n set<int> solve(int lf, int rg) { n   if (lf == rg) { n     return v[lf]; n   } n   int md = (lf + rg) >> 1; n   set<int> x = solve(lf, md); n   set<int> y = solve(md + 1, rg); n   for (int val : y) { n     v[md + 1].insert(val); n   } n   for (int val : x) { n     v[md].insert(val); n   } n   if ((int)(x).size() < (int)(y).size()) { n     for (int val : x) { n       v[md + 1].insert(val); n       y.insert(val); n     } n     return y; n   } else { n     for (int val : y) { n       v[md].insert(val); n       x.insert(val); n     } n     return x; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   vector<pair<int, int> > a(n); n   for (int i = 0; i < n; ++i) { n     int x, y; n     cin >> x >> y; n     sorted.push_back(x); n     a[i] = {x, y}; n   } n   sort((sorted).begin(), (sorted).end()); n   sorted.resize(unique((sorted).begin(), (sorted).end()) - sorted.begin()); n   v.resize((int)(sorted).size()); n   for (int i = 0; i < n; ++i) { n     a[i].first = lower_bound((sorted).begin(), (sorted).end(), a[i].first) - n                  sorted.begin(); n     v[a[i].first].insert(a[i].second); n   } n   solve(0, (int)(v).size() - 1); n   vector<pair<int, int> > ans; n   for (int i = 0; i < (int)(v).size(); ++i) { n     for (int y : v[i]) { n       ans.push_back({sorted[i], y}); n     } n   } n   cout << (int)(ans).size() <<   n ; n   for (int i = 0; i < (int)(ans).size(); ++i) { n     cout << ans[i].first <<     << ans[i].second <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 5; n const int N = 1e12; n string a[105]; n int dp1[105], dp2[105], dp3[105]; n int main() { n   int n, m, i, j, k; n   cin >> n >> m; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n     dp1[i] = maxn; n     dp2[i] = maxn; n     dp3[i] = maxn; n   } n   for (i = 0; i < n; i++) { n     for (j = 0; j < m; j++) { n       if (a[i][j] >=  a  && a[i][j] <=  z ) n         dp1[i] = min(dp1[i], min(j, m - j)); n       else if (a[i][j] >=  0  && a[i][j] <=  9 ) n         dp2[i] = min(dp2[i], min(j, m - j)); n       else n         dp3[i] = min(dp3[i], min(j, m - j)); n     } n   } n   int ans = INT_MAX; n   for (i = 0; i < n; i++) { n     for (j = 0; j < n; j++) { n       for (k = 0; k < n; k++) { n         if (i != j && j != k && i != k) n           ans = min(ans, dp1[i] + dp2[j] + dp3[k]); n       } n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n struct T { n   int l, h, a; n   void scan() { scanf( %d%d%d , &l, &h, &a); } n }; n const int INF = 1e9; n T Map[6][6]; n int F[6]; n int minF, maxC; n int cost; n int N; n void check() { n   for (int i = 1; i < N - 1; ++i) { n     if (F[i] != 0) return; n   } n   if (F[N - 1] < minF || F[N - 1] == minF && cost > maxC) { n     minF = F[N - 1]; n     maxC = cost; n   } n } n void rec(int from, int to) { n   if (F[0] < INF - minF) return; n   if (from == N - 1 && to == N) { n     check(); n   } n   if (from - 1 > 0 && F[from - 1] > 0) return; n   int nextF, nextT; n   nextT = to == N - 1 ? from + 2 : to + 1; n   nextF = to == N - 1 ? from + 1 : from; n   for (int i = Map[from][to].l; i <= Map[from][to].h && i <= F[from]; ++i) { n     int d; n     if (i == 0) n       d = 0; n     else { n       d = Map[from][to].a + i * i; n     } n     cost += d; n     F[from] -= i; n     F[to] += i; n     rec(nextF, nextT); n     cost -= d; n     F[from] += i; n     F[to] -= i; n   } n } n int main() { n   scanf( %d , &N); n   F[0] = INF; n   for (int i = 0; i < N * (N - 1) / 2; ++i) { n     int from, to; n     scanf( %d%d , &from, &to); n     --from; n     --to; n     Map[from][to].scan(); n   } n   minF = INF; n   maxC = -1; n   cost = 0; n   rec(0, 1); n   if (minF == INF) { n     printf( -1 -1 ); n     return 0; n   } n   printf( %d %d , minF, maxC); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long A[1000000]; n long long ncr(int n, int k) { n   long long ans = 1; n   k = k > n - k ? n - k : k; n   int j = 1; n   for (; j <= k; j++, n--) { n     if (n % j == 0) { n       ans *= n / j; n     } else if (ans % j == 0) { n       ans = ans / j * n; n     } else { n       ans = (ans * n) / j; n     } n   } n   return ans; n } n int main() { n   ios::sync_with_stdio(false); n   long long n, m, t; n   cin >> n >> m >> t; n   long long sum = 0; n   for (long long i = 4; i <= n; i++) n     for (long long j = 1; j <= m; j++) n       if (i + j == t) sum += ncr(n, i) * ncr(m, j); n   cout << sum << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MX = 1000001; n const int MI = 100001; n const int MT = 10001; n int main() { n   long long int n, ans = 0; n   cin >> n; n   ans = (n * (n + 1)) / 2; n   n--; n   for (int i = 0; i < n; ++i) { n     int x; n     scanf( %d , &x); n     ans -= x; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n const long long inf = 1e15; n const int N = 1e6 + 6; n int n, q, b[N], t; n queue<int> even, odd, ans; n int main() { n   scanf( %d%d , &n, &q); n   for (int i = 1; i <= n; i++) { n     if (i % 2) n       odd.push(i); n     else n       even.push(i); n   } n   int len, Lipoter = 1, flag = 1; n   for (int i = 1; i <= q; i++) { n     scanf( %d , &t); n     if (t == 1) { n       scanf( %d , &len); n       flag = (flag + len + n) % n; n       if (flag == 0) flag = n; n     } else { n       if (flag % 2) { n         if (Lipoter == 0) { n           even.push(even.front()); n           even.pop(); n         } else n           Lipoter = 0; n       } else { n         if (Lipoter == 1) { n           odd.push(odd.front()); n           odd.pop(); n         } else n           Lipoter = 1; n       } n       if (flag % 2) n         flag++; n       else n         flag--; n       if (flag == 0) flag = n; n     } n   } n   if (Lipoter) { n     while (!even.empty() && !odd.empty()) { n       ans.push(odd.front()); n       odd.pop(); n       ans.push(even.front()); n       even.pop(); n     } n   } else { n     while (!even.empty() && !odd.empty()) { n       ans.push(even.front()); n       even.pop(); n       ans.push(odd.front()); n       odd.pop(); n     } n   } n   while (1) { n     if (ans.front() == 1) n       break; n     else { n       ans.push(ans.front()); n       ans.pop(); n     } n   } n   while (flag <= n) { n     b[flag++] = ans.front(); n     ans.pop(); n   } n   int cnt = 1; n   while (!ans.empty()) { n     b[cnt++] = ans.front(); n     ans.pop(); n   } n   for (int i = 1; i <= n; i++) printf( %d  , b[i]); n   return 0; n } n


#pragma GCC optimize( O3 ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx ) n   n #include <iostream> n #include <cstdio> n #include <vector> n #include <set> n #include <map> n #include <string> n #include <cstring> n #include <cstdlib> n #include <algorithm> n #include <cassert> n #include <cmath> n #include <queue> n #include <ctime> n #include <unordered_map> n #include <unordered_set> n #include <sstream> n   n using namespace std; n   n #define REP(i, n) for(int (i) = 0; (i) < (n); (i)++) n #define SZ(a) (int)(a).size() n #define ALL(a) (a).begin(), (a).end() n  n const int N = 5005; n long long a[N], b[N], d[N]; n short e[N][N]; n vector<long long> c[2 * N]; n   n int main() { n  ios::sync_with_stdio(false); n  cin.tie(nullptr); n  int n; n  cin >> n; n  REP(i, n) cin >> a[i]; n  REP(i, n) cin >> b[i]; n  REP(i, n) { n   int aidx = i, bidx = 0, cidx = i; n   c[cidx].reserve(i + 2); n   c[cidx].push_back(0); n   while (aidx >= 0) { n    e[aidx][bidx] = SZ(c[cidx]); n    c[cidx].push_back(c[cidx].back() + a[aidx] * b[bidx]); n    --aidx, ++bidx; n   } n  } n  for (int i = 1; i < n; i++) { n   int aidx = n - 1, bidx = i, cidx = n - 1 + i; n   c[cidx].reserve(n - i + 1); n   c[cidx].push_back(0); n   while (bidx < n) { n    e[aidx][bidx] = SZ(c[cidx]); n    c[cidx].push_back(c[cidx].back() + a[aidx] * b[bidx]); n    --aidx, ++bidx; n   } n  } n  d[0] = 0; n  for (int i = 1; i <= n; i++) { n   d[i] = d[i - 1] + a[i - 1] * b[i - 1]; n  } n  long long res = d[n]; n  REP(L, n) { n   for (int R = L; R < n; R++) { n    long long fs = d[n] - d[R + 1] + d[L]; n    int st = e[R][L], fn = e[L][R]; n    long long sc = c[L + R][fn] - c[L + R][st - 1]; n    res = max(res, fs + sc); n   } n  } n  cout << res << endl; n  return 0; n }


#include <bits/stdc++.h> n #pragma GCC optimize( 3 ,  inline ,  Ofast ) n using namespace std; n template <class T> n inline void read(T &x) { n   x = 0; n   T f = 1; n   char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); n   x *= f; n } n inline void Setfile(string Str =   ) { n   if (Str ==   ) return; n   freopen((Str +  .in ).c_str(),  r , stdin); n   freopen((Str +  .out ).c_str(),  w , stdout); n } n const int maxn = 500005, mod = 998244353; n int n, f[maxn][2], pw2[maxn], sz[maxn], ans; n vector<int> G[maxn]; n inline int Add(int x, int y) { return (x += y) >= mod ? x - mod : x; } n inline int Mul(int x, int y) { return 1ll * x * y % mod; } n inline void dfs(int u = 1, int p = 0) { n   f[u][0] = sz[u] = 1; n   for (int i = 0; i < (int)G[u].size(); ++i) { n     int v = G[u][i]; n     if (v == p) continue; n     dfs(v, u), sz[u] += sz[v], n         f[u][1] = Add(Mul(f[u][1], Mul(2, Add(f[v][0], f[v][1]))), n                       Mul(f[u][0], f[v][0])), n         f[u][0] = Mul(f[u][0], Add(Mul(f[v][1], 2), f[v][0])); n   } n   ans = Add(ans, Mul(f[u][1], pw2[n - sz[u] + 1])); n } n int main() { n   Setfile(); n   pw2[0] = 1; n   for (int i = 1; i < maxn; ++i) pw2[i] = Add(pw2[i - 1], pw2[i - 1]); n   read(n); n   for (int i = 1, x, y; i < n; ++i) n     read(x), read(y), G[x].push_back(y), G[y].push_back(x); n   dfs(), printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   ios::sync_with_stdio(NULL); n   cin.tie(0); n   cout.tie(0); n   int a, b, c; n   cin >> a >> b >> c; n   c -= 2; n   b -= 1; n   int ans = min({a, b, c}); n   if (ans < 0) { n     cout << 0; n   } else { n     ans = ans * 3 + 3; n     cout << ans; n   } n   return 0; n } n