#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:100000000 ) n using namespace std; n int ri() { n   int x; n   scanf( %d , &x); n   return x; n } n int cnt[1000100]; n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   long long ans = (long long)n * (long long)(n - 1) * (long long)(n - 2) / 6LL; n   for (int i = 0; i < m; i++) { n     int a, b; n     scanf( %d %d , &a, &b); n     cnt[a]++; n     cnt[b]++; n   } n   long long sub = 0; n   for (int i = 1; i <= n; i++) { n     if (cnt[i] != 0) { n       sub += (long long)cnt[i] * (n - 1 - (long long)cnt[i]); n     } n   } n   ans -= sub / 2LL; n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long solve() { n   long long n, T, a, b; n   cin >> n >> T >> a >> b; n   vector<long long> hard(n); n   long long x; n   long long hardcount = 0, easycount = 0; n   for (int i = 0; i < n; ++i) { n     cin >> x; n     if (x) { n       hard[i] = b; n       ++hardcount; n     } else { n       hard[i] = a; n       ++easycount; n     } n   } n   vector<long long> mand(n); n   for (int i = 0; i < n; ++i) { n     cin >> mand[i]; n   } n   vector<pair<long long, long long>> prob(n); n   for (int i = 0; i < n; ++i) { n     prob[i] = make_pair(mand[i], hard[i]); n   } n   sort(prob.begin(), prob.end()); n   int m_easy = 0, m_hard = 0; n   long long res = 0; n   long long musttime = 0; n   for (int i = 0; i < n; ++i) { n     long long time = prob[i].first - musttime; n     if (time > 0) { n       long long solved = m_easy + m_hard; n       --time; n       solved += min(time / a, easycount - m_easy); n       time -= min(time / a, easycount - m_easy) * a; n       solved += min(time / b, hardcount - m_hard); n       time -= min(time / b, hardcount - m_hard) * b; n       res = max(res, solved); n     } n     if (prob[i].second == b) { n       ++m_hard; n       musttime += b; n     } else { n       ++m_easy; n       musttime += a; n     } n   } n   long long time = T - musttime; n   if (time >= 0) res = n; n   return res; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.precision(30); n   cout << fixed; n   int t; n   cin >> t; n   while (t--) { n     cout << solve() << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void read(T& x) { n   cin >> x; n } n template <class H, class T> n void read(pair<H, T>& x) { n   read(x.first); n   read(x.second); n } n template <class A> n void read(vector<A>& v) { n   for (auto& x : v) read(x); n } n template <class H, class... T> n void read(H& h, T&... t) { n   read(h); n   read(t...); n } n string to_string(const char* c) { return (string)c; } n string to_string(char c) { return (string)    + c; } n string to_string(string second) { return second; } n string to_string(bool b) { return b ?  True  :  False ; } n template <class A> n string to_string(vector<A> v) { n   string second; n   for (auto& x : v) second += to_string(x) +    ; n   return second; n } n template <class H, class... T> n string to_string(H& h, T&... t) { n   string second; n   second += to_string(h); n   second +=    ; n   second += to_string(t...); n   return second; n } n void print(string second) { cout << second <<   n ; } n template <class... A> n void print(A... a) { n   print(to_string(a...)); n } n int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); } n string tb(int x) { n   string ans; n   int c = x; n   for (int i = log2(x); i >= 0; --i) { n     if (pow(2, i) <= c) { n       ans +=  1 ; n       c -= pow(2, i); n     } else { n       ans +=  0 ; n     } n   } n   return ans; n } n bool ispr(int x) { n   if (x <= 1) { n     return false; n   } n   for (int i = 2; i <= sqrt(x); ++i) { n     if (x % i == 0) { n       return false; n     } n   } n   return true; n } n struct point { n   int x; n   int y; n }; n const int MOD = 1e9 + 7; n const int MX = 2e5 + 5; n const long long INF = 1e18; n void solve() { n   double n, k; n   cin >> n >> k; n   double dist = 0; n   point prev; n   read(prev.x, prev.y); n   for (int i = 1; i < n; ++i) { n     point now; n     read(now.x, now.y); n     dist += sqrt((now.x - prev.x) * (now.x - prev.x) + n                  (now.y - prev.y) * (now.y - prev.y)); n     prev = now; n   } n   printf( %.9f , (dist * k) / 50); n } n int main() { n   std::ios::sync_with_stdio(0); n   std::cin.tie(0); n   bool isT = 0; n   if (isT) { n     int t; n     cin >> t; n     while (t--) { n       solve(); n     } n     return 0; n   } n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int A[100010]; n int gcd(int a, int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t = 1, n, i, j; n   cin >> n; n   int cnt = 0; n   for (i = 0; i < n; i++) { n     cin >> A[i]; n     if (A[i] == 1) cnt++; n   } n   if (cnt) { n     cout << n - cnt <<   n ; n   } else { n     int cur = 0; n     for (i = 0; i < n; i++) cur = gcd(cur, A[i]); n     if (cur != 1) { n       cout <<  -1 n ; n     } else { n       int mn = n; n       for (i = 0; i < n; i++) { n         cur = A[i]; n         for (int j = i + 1; j < n; j++) { n           cur = gcd(cur, A[j]); n           if (cur == 1) { n             mn = min(mn, j - i); n             break; n           } n         } n       } n       cout << mn + n - 1 <<   n ; n     } n   } n   return 0; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, lft, curr = 1; n   scanf( %d , &n); n   lft = n; n   while (lft) { n     if (lft == 3) break; n     for (int j = 1; j <= (lft + 1) / 2; j++) { n       printf( %d  , curr); n     } n     curr *= 2; n     lft -= (lft + 1) / 2; n   } n   if (lft == 3) { n     printf( %d %d %d n , curr, curr, curr * 3); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n const long long INF = 1e18; n const int MOD = 1e9 + 7; n const long long dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; n const long long Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, n                 Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; n long long in() { n   long long x; n   cin >> x; n   return x; n } n void print() { cout <<   n ; } n template <class Head, class... Tail> n void print(Head &&head, Tail &&...tail) { n   cout << head; n   if (sizeof...(tail) != 0) cout <<    ; n   print(forward<Tail>(tail)...); n } n template <class T> n void print(vector<T> &vec) { n   for (auto &a : vec) { n     cout << a; n     if (&a != &vec.back()) cout <<    ; n   } n   cout <<   n ; n } n template <class T> n void print(set<T> &set) { n   for (auto &a : set) { n     cout << a <<    ; n   } n   cout <<   n ; n } n template <class T> n void print(vector<vector<T>> &df) { n   for (auto &vec : df) { n     print(vec); n   } n } n long long power(long long x, long long n) { n   long long ret = 1; n   while (n > 0) { n     if (n & 1) ret *= x; n     x *= x; n     n >>= 1; n   } n   return ret; n } n long long comb(long long n, long long k) { n   vector<vector<long long>> v(n + 1, vector<long long>(n + 1, 0)); n   for (long long i = 0; i < (long long)((v).size()); i++) { n     v[i][0] = 1; n     v[i][i] = 1; n   } n   for (long long k = 1; k < (long long)((v).size()); k++) { n     for (long long j = 1; j < k; j++) { n       v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]); n     } n   } n   return v[n][k]; n } n void add(long long &a, long long b) { n   a += b; n   if (a >= MOD) a -= MOD; n } n template <class T> n inline bool chmin(T &a, T b) { n   if (a > b) { n     a = b; n     return true; n   } n   return false; n } n template <class T> n inline bool chmax(T &a, T b) { n   if (a < b) { n     a = b; n     return true; n   } n   return false; n } n long long ceildiv(long long a, long long b) { n   if (b < 0) a = -a, b = -b; n   if (a >= 0) n     return (a + b - 1) / b; n   else n     return a / b; n } n long long floordiv(long long a, long long b) { n   if (b < 0) a = -a, b = -b; n   if (a >= 0) n     return a / b; n   else n     return (a - b + 1) / b; n } n long long floorsqrt(long long x) { n   assert(x >= 0); n   long long ok = 0; n   long long ng = 1; n   while (ng * ng <= x) ng <<= 1; n   while (ng - ok > 1) { n     long long mid = (ng + ok) >> 1; n     if (mid * mid <= x) n       ok = mid; n     else n       ng = mid; n   } n   return ok; n } n template <class T> n bool contain(const std::string &s, const T &v) { n   return s.find(v) != std::string::npos; n } n __attribute__((constructor)) void faster_io() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n } n long long n, m, p; n vector<string> fld; n vector<long long> s; n vector<vector<long long>> vis; n vector<queue<pair<pair<long long, long long>, long long>>> q(9); n void bfs() { n   bool changed = true; n   while (changed) { n     changed = false; n     for (long long ni = 0; ni < (long long)(9); ni++) { n       while ((!q[ni].empty()) and (q[ni].front().second < s[ni])) { n         auto current_pos = q[ni].front(); n         long long x = current_pos.first.first; n         long long y = current_pos.first.second; n         long long step = current_pos.second; n         q[ni].pop(); n         for (long long dir = 0; dir < 4; ++dir) { n           long long nx = x + dx[dir]; n           long long ny = y + dy[dir]; n           if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue; n           if (fld[nx][ny] ==  # ) continue; n           if (vis[nx][ny] == -1) { n             q[ni].push(make_pair(make_pair(nx, ny), step + 1)); n             vis[nx][ny] = ni; n             changed = true; n           } n         } n       } n       long long sz = (long long)((q[ni]).size()); n       vector<pair<long long, long long>> tmp; n       for (long long si = 0; si < (long long)(sz); si++) { n         auto current_pos = q[ni].front(); n         long long x = current_pos.first.first; n         long long y = current_pos.first.second; n         long long step = current_pos.second; n         q[ni].pop(); n         tmp.push_back(make_pair(x, y)); n       } n       for (auto i : tmp) { n         q[ni].push(make_pair(i, 0LL)); n       } n     } n   } n } n signed main() { n   cin >> n >> m >> p; n   s.assign(p, 0); n   vis.assign(n, vector<long long>(m, -1)); n   for (long long pi = 0; pi < (long long)(p); pi++) { n     cin >> s[pi]; n   } n   for (long long ni = 0; ni < (long long)(n); ni++) { n     string ss; n     cin >> ss; n     fld.push_back(ss); n   } n   for (long long ni = 0; ni < (long long)(n); ni++) { n     for (long long mi = 0; mi < (long long)(m); mi++) { n       if (fld[ni][mi] !=  .  and fld[ni][mi] !=  # ) { n         q[fld[ni][mi] -  1 ].push(make_pair(make_pair(ni, mi), 0LL)); n         vis[ni][mi] = fld[ni][mi] -  1 ; n       } n     } n   } n   bfs(); n   vector<long long> ans(p); n   for (long long ni = 0; ni < (long long)(n); ni++) { n     for (long long mi = 0; mi < (long long)(m); mi++) { n       if (vis[ni][mi] != -1) ans[vis[ni][mi]]++; n     } n   } n   print(ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int l[105], r[105]; n int dp[105][100005]; n int temp[100005]; n int q[100005][2], cntl, cntr; n int main() { n   int n, k; n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= k; i++) scanf( %d%d , &l[i], &r[i]); n   k++; n   l[k] = r[k] = 2 * n; n   for (int i = 1; i <= 100005; i++) dp[0][i] = 1005; n   dp[0][0] = 0; n   for (int i = 1; i <= k; i++) { n     for (int j = 0; j <= n; j++) { n       dp[i][j] = 1005; n       if (j >= l[i] - r[i - 1]) n         dp[i][j] = min(dp[i][j], dp[i - 1][j - (l[i] - r[i - 1])]); n       if (r[i - 1] >= j) dp[i][j] = min(dp[i][j], dp[i - 1][r[i - 1] - j] + 1); n     } n     if (r[i] != l[i]) { n       for (int j = 0; j <= n; j++) { n         temp[j] = 1005; n         if (j >= r[i] - l[i]) temp[j] = min(temp[j], dp[i][j - (r[i] - l[i])]); n         if (l[i] >= j) temp[j] = min(temp[j], dp[i][l[i] - j] + 1); n       } n       cntl = 0; n       cntr = 0; n       for (int j = 0; j <= n; j++) { n         if (j <= l[i]) { n           while (cntl != cntr && q[cntr][1] >= dp[i][l[i] - j] + 1) cntr--; n           cntr++; n           q[cntr][0] = j; n           q[cntr][1] = dp[i][l[i] - j] + 1; n         } n         if (cntl != cntr && q[cntl + 1][0] + r[i] - l[i] == j) cntl++; n         if (cntl != cntr) temp[j] = min(q[cntl + 1][1], temp[j]); n       } n       for (int j = 0; j <= n; j++) dp[i][j] = temp[j]; n     } n   } n   if (dp[k][n] > 3 * k) n     printf( Hungry n ); n   else n     printf( Full n%d n , dp[k][n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k, idx = 0; n   cin >> n >> k; n   pair<int, int> inst[n]; n   vector<int> v; n   for (int i = 1; i <= n; i++) { n     int t; n     cin >> t; n     inst[i - 1] = make_pair(t, i); n   } n   sort(inst, inst + n); n   while (k >= inst[idx].first && idx < n) { n     v.push_back(inst[idx].second); n     k -= inst[idx].first; n     idx++; n   } n   cout << v.size() << endl; n   for (int i = 0; i < v.size(); i++) cout << v[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long i, j, n, a[100001], b[100001], c[100001], d[100001]; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n     b[i] = c[i] = a[i]; n   } n   for (i = 0; i < n - 1; i++) { n     if (b[i] >= b[i + 1]) b[i + 1] = b[i] + 1; n   } n   for (i = n - 1; i > 0; i--) { n     if (c[i] >= c[i - 1]) c[i - 1] = c[i] + 1; n   } n   for (i = 0; i < n; i++) { n     if (b[i] >= c[i]) { n       j = i; n       break; n     } n   } n   for (i = 0; i <= j; i++) d[i] = b[i]; n   for (i = j + 1; i < n; i++) d[i] = c[i]; n   long long sum = 0; n   for (i = 0; i < n; i++) { n     sum += (d[i] - a[i]); n   } n   cout << sum << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef long long ll; n ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } n ll my_exp(ll a, ll b) { n   if (b == 0) { n     return 1; n   } else { n     ll temp = my_exp(a, b / 2); n     temp *= temp; n     if (b % 2 == 1) { n       temp *= a; n     } n     return temp; n   } n } n class mycomparison { n   bool reverse; n  n  public: n   mycomparison(const bool& revparam = false) { reverse = revparam; } n   bool operator()(const ll& lhs, const ll& rhs) const { n     if (reverse) n       return (lhs > rhs); n     else n       return (lhs < rhs); n   } n }; n int main() { n   std::priority_queue<ll, std::vector<ll>, greater<ll> > fourth; n   ll n, m; n   vector<ll> insert, getMin, removeMin; n   vector<pair<ll, ll> > order; n   std::cin >> n; n   string a; n   for (ll i = 0; i < n; ++i) { n     std::cin >> a; n     if (a !=  removeMin ) scanf(  %lld n , &m); n     if (a ==  insert ) { n       order.push_back(make_pair(0, m)); n       fourth.push(m); n     } n     if (a ==  removeMin ) { n       if (fourth.empty()) { n         order.push_back(make_pair(0, 1)); n         fourth.push(1); n       } n       order.push_back(make_pair(1, 1)); n       fourth.pop(); n     } n     if (a ==  getMin ) { n       if (fourth.empty()) { n         order.push_back(make_pair(0, m)); n         fourth.push(m); n       } n       while (fourth.top() < m) { n         fourth.pop(); n         order.push_back(make_pair(1, m)); n         if (fourth.empty()) { n           order.push_back(make_pair(0, m)); n           fourth.push(m); n         } n       } n       if (fourth.top() == m) { n         order.push_back(make_pair(3, m)); n       } else { n         fourth.push(m); n         order.push_back(make_pair(0, m)); n         order.push_back(make_pair(3, m)); n       } n     } n   } n   std::cout << (ll)order.size() << std::endl; n   for (typeof(order.begin()) it = order.begin(); it != order.end(); it++) { n     if ((*it).first == 0) { n       std::cout <<  insert   << (*it).second << std::endl; n     } n     if ((*it).first == 1) { n       std::cout <<  removeMin  << std::endl; n     } n     if ((*it).first == 3) { n       std::cout <<  getMin   << (*it).second << std::endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int d[] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6}; n int a, b, res; n int main() { n   scanf( %d%d , &a, &b); n   for (int i = a; i <= b; i++) { n     int t = i; n     while (t) { n       res += d[t % 10]; n       t /= 10; n     } n   } n   printf( %d n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void read() { n   freopen( in.txt ,  r , stdin); n   freopen( out.txt ,  w , stdout); n } n bool voi(char c) { n   return (c ==  a  || c ==  e  || c ==  i  || c ==  y  || c ==  o  || c ==  u ); n } n long long log_pow(long long b, long long p) { n   if (p == 0) return 1; n   if (p == 1) return b; n   if (p % 2) return b * log_pow(b, p - 1); n   long long r = log_pow(b, p / 2); n   return r * r; n } n int d5l_i() { n   int x; n   scanf( %d , &x); n   return x; n } n long long d5l_l() { n   long long x; n   scanf( %lld , &x); n   return x; n } n char d5l_c() { n   char x; n   scanf( %c , &x); n   return x; n } n long long fact(int n) { n   long long fc = 1; n   for (int i = 2; i <= n; i++) fc *= i; n   return fc; n } n int len(long long n) { n   int c = 0; n   while (n) { n     n /= 2; n     c++; n   } n   return c; n } n bool why(int a, int b, int c) { n   return ((long long)a + b > c && (long long)c + b > a && (long long)c + a > b); n } n int a[100005]; n long long ans; n int main() { n   int n = d5l_i(), m = d5l_i(); n   for (int i = 0; i < n; i++) a[i] = d5l_i(); n   sort(a, a + n); n   vector<int> v; n   bool flag = false, ops = false; n   for (int i = 1; i < a[0]; i++) { n     if (ans + i > m) { n       ops = true; n       break; n     } n     ans += i; n     v.push_back(i); n   } n   if (!ops) n     for (int i = 0; i < n - 1; i++) { n       for (int j = a[i] + 1; j < a[i + 1]; j++) { n         if (ans + j > m) { n           flag = true; n           break; n         } n         ans += j; n         v.push_back(j); n       } n       if (flag) break; n     } n   if (!flag && !ops) n     for (int i = a[n - 1] + 1; i <= 1e9; i++) { n       if (ans + i > m) break; n       ans += i; n       v.push_back(i); n     } n   printf( %d n , v.size()); n   for (int i = 0; i < v.size(); i++) printf( %d  , v[i]); n } n


#include <bits/stdc++.h> n const long long N = 50050; n const long long Q = 2e18; n const long long mod = 1e9 + 7; n const long long MAGIC = 30; n using namespace std; n int a, b, c, n; n void solve() { n   cin >> a >> b >> c >> n; n   if (a + b - c >= n || c > a || c > b) { n     cout << -1 <<   n ; n   } else { n     cout << n - (a + b - c) <<   n ; n   } n } n bool mtest = false; n int main() { n   ios_base::sync_with_stdio(0); n   int TE = 1; n   if (mtest) cin >> TE; n   while (TE--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long int> vec; n map<long long int, long long int> mp; n int main() { n   long long int x = 0, y = 0, z = 0, sum = 0; n   cin >> x; n   for (int i = 0; i < x; i++) { n     cin >> y; n     vec.push_back(y); n     mp[y]++; n   } n   sort(vec.begin(), vec.end()); n   for (int i = 0; i < vec.size(); i++) { n     for (int j = 0; j <= 30; j++) { n       z = powl(2, j) - vec[i]; n       if (binary_search(vec.begin() + i + 1, vec.end(), z) == true) { n         if (z == vec[i]) { n           sum += --mp[z]; n         } else { n           sum += mp[z]; n         } n       } n     } n   } n   cout << sum << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   printf( n        YES nNO nNO nYES nNO nNO nNO nNO nNO nYES nYES nYES nYES nYES nYES nYES  n         nNO nYES nNO nYES nYES nNO nYES nNO nNO nYES nNO nNO nYES nYES nNO nYES  n         nNO nYES nNO nYES nYES nYES nNO nYES nYES nNO nYES nYES nNO nYES nYES n  n        YES nNO nYES nNO nNO nYES nYES nYES nYES nYES nYES nNO nNO nYES nNO nNO  n         nNO nNO nNO nNO nNO nNO nNO nYES nNO nYES nNO nNO nNO nYES nYES nNO nYE  n        S nYES nNO nNO nNO nNO nNO nNO nYES nYES nNO nYES nNO nYES nYES nNO nNO  n         nNO nYES nYES nYES nYES nYES nNO nNO nNO nYES nNO nYES nNO nYES nNO nYE  n        S nNO nNO nYES nYES nYES nYES nNO nNO nNO nYES nNO nYES nYES nYES nNO nY  n        ES nNO nNO nNO nYES nNO nNO nNO nYES nYES nYES nYES nYES nYES nYES nYES  n         nYES nYES nYES nNO nYES nNO nNO nNO nNO nNO nYES nNO nNO nYES nNO nYES  n         nNO nYES nNO nYES nNO nYES nYES nYES nNO nNO nYES nNO nNO nNO nNO nYES  n         nNO nYES nNO nNO nYES nNO nYES nYES nYES nNO nNO nNO nYES nYES nNO nYES  n         nNO nYES nYES nYES nNO nYES nYES nNO nYES nNO nYES nYES nNO nYES nYES n  n        NO nNO nYES nNO nNO nNO nYES nYES nNO nYES n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n struct State { n   int bk; n   string fr; n   int pos; n   int cnt; n }; n bool operator<(State lhs, State rhs) { n   if (lhs.bk != rhs.bk) return lhs.bk < rhs.bk; n   if (lhs.fr != rhs.fr) return lhs.fr < rhs.fr; n   if (lhs.pos != rhs.pos) return lhs.pos < rhs.pos; n   if (lhs.cnt != rhs.cnt) return lhs.cnt < rhs.cnt; n   return false; n } n int main() { n   int n; n   cin >> n; n   string s; n   cin >> s; n   vector<int> jump(s.size() + 1, 0); n   for (int i = 0; i <= s.size(); i++) { n     int to = 0; n     for (int j = 0; j < i; j++) { n       bool ok = true; n       for (int k = 0; k < j; k++) { n         ok &= (s[k] == s[i - j + k]); n       } n       if (i != s.size()) ok &= (s[j] != s[i]); n       if (ok) to = j + 1 - (int)(i == s.size()); n     } n     jump[i] = to; n   } n   set<string> subs; n   for (int i = 0; i < s.size(); i++) { n     for (int j = i + 1; j <= s.size(); j++) { n       string ss; n       for (int k = i; k < j; k++) { n         ss += s[k]; n       } n       subs.insert(ss); n     } n   } n   set<string> lasts; n   string ss; n   for (int i = s.size() - 1; i >= 0; i--) { n     ss = s[i] + ss; n     lasts.insert(ss); n   } n   map<State, ll> dp; n   dp[State{-1,   , 0, 0}] = 1; n   for (int i = 0; i < n; i++) { n     map<State, ll> next; n     for (auto &e : dp) { n       int bk = e.first.bk; n       string str = e.first.fr; n       int pos = e.first.pos; n       int cnt = e.first.cnt; n       if (str !=  @ ) { n         str += s[pos]; n         if (subs.count(str)) { n           if (lasts.count(str)) { n             bk = i; n           } n         } else { n           str =  @ ; n         } n       } n       if (++pos == s.size()) { n         pos = jump[pos]; n         cnt = true; n       } n       next[State{bk, str, pos, cnt}] += e.second; n       bk = e.first.bk; n       str = e.first.fr; n       pos = e.first.pos; n       cnt = e.first.cnt; n       if (str !=  @ ) { n         str += (s[pos] ==  0  ?  1  :  0 ); n         if (subs.count(str)) { n           if (lasts.count(str)) { n             bk = i; n           } n         } else { n           str =  @ ; n         } n       } n       pos = jump[pos]; n       next[State{bk, str, pos, cnt}] += e.second; n     } n     dp = next; n   } n   ll res = 0; n   for (auto &e : dp) { n     int bk = e.first.bk; n     string strs = e.first.fr; n     int pos = e.first.pos; n     int cnt = e.first.cnt; n     string str; n     for (int i = 0; i < e.first.pos; i++) { n       str += s[i]; n     } n     for (int i = s.size() - e.first.bk - 1; i < s.size(); i++) { n       str += s[i]; n     } n     for (int i = 0; i <= (int)str.size() - (int)s.size(); i++) { n       if (s == str.substr(i, s.size())) { n         cnt = true; n       } n     } n     if (cnt >= 1) { n       res += e.second; n     } n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using lli = long long int; n using pii = pair<int, int>; n using vi = vector<int>; n using vb = vector<bool>; n using vvi = vector<vector<int>>; n using vlli = vector<long long int>; n using vpii = vector<pair<int, int>>; n const int N = 200005; n const int blockSize = sqrt(N); n lli n, t, l, r, x, idx, L, R, res; n vlli a, ans, cnt(1000005); n vector<tuple<lli, lli, lli, lli>> q; n int get(int idx) { return idx / blockSize; } n void add(lli x) { res += x * (2 * (cnt[x]++) + 1); } n void del(lli x) { res += x * (-2 * (cnt[x]--) + 1); } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> t; n   a.resize(n); n   ans.resize(t); n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < t; i++) { n     cin >> l >> r; n     l--; n     r--; n     q.push_back(make_tuple(get(l), r, l, i)); n   } n   sort((q).begin(), (q).end()); n   L = R = 0; n   add(a[0]); n   for (int i = 0; i < t; i++) { n     tie(ignore, r, l, idx) = q[i]; n     while (L < l) del(a[L++]); n     while (L > l) add(a[--L]); n     while (R < r) add(a[++R]); n     while (R > r) del(a[R--]); n     ans[idx] = res; n   } n   for (int i = 0; i < t; i++) cout << ans[i] <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n long long bigmod(long long a, int p, long long int m) { n   if (p == 0) return 1; n   if (p & 1) { n     return ((a % m) * (bigmod(a, p - 1, m))) % m; n   } else { n     long long tmp = bigmod(a, p / 2, m); n     return (tmp * tmp) % m; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int n; n   cin >> n; n   pair<long long int, long long int> p[n]; n   for (long long int i = 0; i < n; i++) { n     long long int x; n     cin >> x; n     p[i].first = -x; n     p[i].second = i; n   } n   sort(p, p + n); n   vector<long long int> v[n]; n   vector<pair<long long int, long long int> > p1; n   for (long long int i = 0; i < n; i++) { n     p1.push_back(make_pair(p[i].second, p[i].first)); n     sort(p1.begin(), p1.end()); n     for (long long int t = 0; t < p1.size(); t++) { n       v[i].push_back(-p1[t].second); n     } n   } n   long long int m; n   cin >> m; n   while (m--) { n     long long int a; n     cin >> a; n     long long int b; n     cin >> b; n     cout << v[a - 1][b - 1]; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 3e-5; n double x, h, l; n int main() { n   scanf( %lf , &x); n   for (double h = 1; h <= 10 + eps; h++) { n     if (h + eps < x) continue; n     l = h / (sqrt((h * h) / (x * x) - 1)) * 2.0; n     for (double q = 1; q <= 10 + eps; q++) n       if (l - q < eps && q - l < eps) { n         printf( %d %d , (int)q, (int)h); n         return 0; n       } n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   if (a < b) n     return gcd(b, a); n   else if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n long long pow(long long b, long long e) { n   if (e == 0) n     return 1; n   else if (e % 2 == 0) { n     long long a = pow(b, e / 2); n     return a * a; n   } else { n     long long a = pow(b, e / 2); n     return b * a * a; n   } n } n long long powm(long long x, long long y, long long m = 1000000007) { n   x = x % m; n   long long res = 1; n   while (y) { n     if (y & 1) res = res * x; n     res %= m; n     y = y >> 1; n     x = x * x; n     x %= m; n   } n   return res; n } n long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } n long long modInverse(long long a, long long m) { return powm(a, m - 2, m); } n bool issq(long long n) { n   long long p = sqrt(n); n   return p * p == n; n } n long long MIN(long long a = 2e18, long long b = 2e18, long long c = 2e18, n               long long d = 2e18, long long e = 2e18) { n   return min(a, min(b, min(c, min(d, e)))); n } n long long MAX(long long a = -2e18, long long b = -2e18, long long c = -2e18, n               long long d = -2e18, long long e = -2e18) { n   return max(a, max(b, max(c, max(d, e)))); n } n vector<int> prime; n void seive(long long n) { n   prime.resize(n + 5, 0); n   long long j; n   for (long long i = 2; i <= n; i++) { n     if (!prime[i]) { n       prime[i] = i; n       for (j = i * i; j <= n; j += i) n         if (!prime[j]) prime[j] = i; n     } n   } n } n long long extended_GCD(long long a, long long b, long long &x, long long &y) { n   if (a == 0) { n     x = 0; n     y = 1; n     return b; n   } n   long long x1, y1; n   long long gcd = extended_GCD(b % a, a, x1, y1); n   x = y1 - (b / a) * x1; n   y = x1; n   return gcd; n } n long long mulInv(long long a, long long mod) { n   long long x, y; n   extended_GCD(a, mod, x, y); n   if (x < 0) x += mod; n   return x; n } n void __print(int x) { cout << x; } n void __print(long x) { cout << x; } n void __print(long long x) { cout << x; } n void __print(unsigned x) { cout << x; } n void __print(unsigned long x) { cout << x; } n void __print(unsigned long long x) { cout << x; } n void __print(float x) { cout << x; } n void __print(double x) { cout << x; } n void __print(long double x) { cout << x; } n void __print(char x) { cout <<     << x <<    ; } n void __print(const char *x) { cout <<     << x <<    ; } n void __print(const string &x) { cout <<     << x <<    ; } n void __print(bool x) { cout << (x ?  true  :  false ); } n template <typename T, typename V> n void __print(const pair<T, V> &x) { n   cout <<  { ; n   __print(x.first); n   cout <<  , ; n   __print(x.second); n   cout <<  } ; n } n template <typename T> n void __print(const T &x) { n   int f = 0; n   cout <<  { ; n   for (auto &i : x) cout << (f++ ?  ,  :   ), __print(i); n   cout <<  } ; n } n void _print() { cout <<  ] n ; } n template <typename T, typename... V> n void _print(T t, V... v) { n   __print(t); n   if (sizeof...(v)) cout <<  ,  ; n   _print(v...); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long n; n   cin >> n; n   long long a[n + 1]; n   long long f = 0; n   for (long long i = 1; i <= n; i++) { n     cin >> a[i]; n     if (a[1] != a[i]) f = 1; n   } n   if (f == 0) n     cout << -1; n   else { n     long long d = 15e6; n     seive(d); n     long long hcf = a[1]; n     for (long long i = 2; i <= n; i++) hcf = gcd(hcf, a[i]); n     map<long long, long long> mp; n     for (long long i = 1; i <= n; i++) { n       a[i] = a[i] / hcf; n       long long x = a[i]; n       while (x != 1) { n         long long p = prime[x]; n         mp[p]++; n         while (x % p == 0) x /= p; n       } n     } n     long long ans = 0; n     for (auto x : mp) ans = max(ans, x.second); n     cout << n - ans; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MID = 1e5; n const int MAX = 1e9; n int main() { n   int n; n   cin >> n; n   if (n % 2) { n     cout << n - 9 <<     << 9; n   } else { n     cout << n - 8 <<     << 8; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 7, M = 2e5 + 7; n int n, m, k, t; n vector<int> b; n struct Node { n   int in, out; n   long long h; n   Node() {} n   Node(int i, int o, long long _h) : in(i), out(o), h(_h) {} n } a[N]; n bool operator<(const Node &a, const Node &b) { n   if (a.out == b.out) return a.in < b.in; n   return a.out < b.out; n } n long long fen[M]; n void add(int i, long long v) { n   for (; i <= (int)b.size(); i += i & -i) fen[i] = max(fen[i], v); n } n long long get(int i) { n   long long res = 0; n   for (; i > 0; i -= i & -i) res = max(res, fen[i]); n   return res; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d%d%lld , &a[i].in, &a[i].out, &a[i].h); n     b.push_back(a[i].in), b.push_back(a[i].out); n   } n   sort(a + 1, a + n + 1); n   sort(b.begin(), b.end()), n       b.resize((int)(unique(b.begin(), b.end()) - b.begin())); n   for (int i = n; i > 0; i--) { n     k = (lower_bound(b.begin(), b.end(), a[i].out) - b.begin()) + 1; n     t = (lower_bound(b.begin(), b.end(), a[i].in) - b.begin()) + 1; n     add(t, get(k - 1) + a[i].h); n   } n   printf( %lld , get((int)b.size())); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n, m; n   cin >> n >> m; n   vector<long long> vect; n   vect.assign(n, 0); n   long long ans = 0; n   for (int i = 0; i < n; i++) cin >> vect[i]; n   for (int i = 0; i < m; i++) { n     int a, b; n     cin >> a >> b; n     ans += min(vect[a - 1], vect[b - 1]); n   } n   cout << ans << endl; n   return; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline T bigmod(T p, T e, T M) { n   T ret = 1; n   for (; e > 0; e >>= 1) { n     if (e & 1) ret = (ret * p) % M; n     p = (p * p) % M; n   } n   return (T)ret; n } n template <class T> n inline T gcd(T a, T b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n template <class T> n inline T modinverse(T a, T M) { n   return bigmod(a, M - 2, M); n } n template <class T> n inline T lcm(T a, T b) { n   a = abs(a); n   b = abs(b); n   return (a / gcd(a, b)) * b; n } n template <class T, class X> n inline bool getbit(T a, X i) { n   T t = 1; n   return ((a & (t << i)) > 0); n } n template <class T, class X> n inline T setbit(T a, X i) { n   T t = 1; n   return (a | (t << i)); n } n template <class T, class X> n inline T resetbit(T a, X i) { n   T t = 1; n   return (a & (~(t << i))); n } n inline long long power(long long a, long long b) { n   long long multiply = 1; n   for (int i = (1); i <= (b); i++) { n     multiply *= a; n   } n   return multiply; n } n inline long long ABS(long long a) { return (a >= 0) ? a : -a; } n long long n, in, m; n map<long long, vector<long long> > mp; n pair<long long, long long> fact[200003]; n int main() { n   scanf( %lld , &n); n   for (int i = (1); i <= (n); i++) { n     scanf( %lld , &in); n     mp[in].push_back(i); n   } n   for (int i = (1); i <= (n); i++) { n     scanf( %lld , &in); n     mp[in].push_back(i); n   } n   scanf( %lld , &m); n   fact[0] = make_pair(1, 0); n   long long ans = 1, cnt, temp; n   for (long long i = (1); i <= (200000); i++) { n     temp = i; n     cnt = 0; n     while (temp % 2 == 0) { n       temp /= 2; n       cnt++; n     } n     fact[i].first = (fact[i - 1].first * temp) % m; n     fact[i].second = cnt + fact[i - 1].second; n   } n   vector<long long> v; n   for (__typeof((mp).begin()) it = (mp).begin(); it != (mp).end(); it++) { n     v = it->second; n     if (v.size() == 1) continue; n     sort(v.begin(), v.end()); n     ans *= fact[v.size()].first; n     ans %= m; n     cnt = 0; n     for (int i = (1); i <= (v.size() - 1); i++) { n       if (v[i] == v[i - 1]) cnt++; n     } n     ans *= bigmod(2LL, fact[v.size()].second - cnt, m); n     ans %= m; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int u, s; n   node() { u = s = 0; } n   bool operator<(const node &temp) const { n     if (this->s < temp.s) return 1; n     return 0; n   } n }; n node black[100005]; n node white[100005]; n vector<vector<node> > adj; n int main() { n   int n; n   scanf( %d , &n); n   adj.resize(n); n   bool allzero = true; n   int w, b; n   w = b = 0; n   for (int i = 0; i < n; ++i) { n     int c; n     scanf( %d , &c); n     if (c == 0) { n       white[w].u = i; n       scanf( %d , &white[w].s); n       if (white[w].s) allzero = false; n       ++w; n     } else { n       black[b].u = i; n       scanf( %d , &black[b].s); n       if (black[b].s) allzero = false; n       ++b; n     } n   } n   if (allzero) { n     if (w < b) { n       for (int i = 0; i < b; ++i) n         cout << white[0].u + 1 <<     << black[i].u + 1 <<     << 0 << endl; n       for (int i = 1; i < w; ++i) n         cout << white[i].u + 1 <<     << black[i].u + 1 <<     << 0 << endl; n     } else { n       for (int i = 0; i < w; ++i) n         cout << black[0].u + 1 <<     << white[i].u + 1 <<     << 0 << endl; n       for (int i = 1; i < b; ++i) n         cout << black[i].u + 1 <<     << white[i].u + 1 <<     << 0 << endl; n     } n     return 0; n   } n   sort(black, black + b); n   sort(white, white + w); n   for (int indb = 0, indw = 0; indb < b && indw < w;) { n     if (white[indw].s < black[indb].s) { n       black[indb].s -= white[indw].s; n       adj[black[indb].u].push_back(white[indw]); n       ++indw; n     } else { n       white[indw].s -= black[indb].s; n       adj[white[indw].u].push_back(black[indb]); n       ++indb; n     } n   } n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < adj[i].size(); ++j) { n       printf( %d %d %d n , i + 1, adj[i][j].u + 1, adj[i][j].s); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<string> vs, vs2; n set<string> st; n map<string, int> mp, mp1; n long long i, j, k, x, y, m, n, a, b, c, d, e, f, g, h, l, o, p, q, t, u, v, w, n     z, r, ln, neg, pos, sm, ar[500000 + 5], br[500000 + 5], fr[60], cnt; n string s, s1, s2, s3; n int main() { n   while (getline(cin, s)) { n     ln = s.size(); n     long long in = 0; n     for (int i =  z ; i >=  a ; i--) { n       for (j = in; j < ln; j++) { n         if (i == (int)s[j]) { n           in = max(in, j); n           cout << s[j]; n         } n       } n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e6 + 22; n const int INF = 1e9 + 2; n long long n, ans, mark[MAXN]; n char str[MAXN]; n int main() { n   cin >> n; n   cin >> str; n   for (int i = 0; i < n; i++) { n     if (mark[str[i]] == 0) { n       mark[str[i]] = 1; n       ans++; n     } n   } n   if (n > 26) n     cout << -1; n   else n     cout << n - ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using LL = long long; n using DD = long double; n using pii = pair<int, int>; n const LL INFLL = 0x7f7f7f7f7f7f7f7fLL; n const int INFint = 0x7f7f7f7f; n LL exactMatchingSubranges(vector<int> &cumulative, int match) { n   LL rr = 0; n   for (int i = 0; i < int((int((cumulative).size()))); ++i) { n     int looking_for = match ^ cumulative[i]; n     int p = lower_bound((cumulative).begin(), (cumulative).end(), looking_for) - n             cumulative.begin(); n     int q = upper_bound((cumulative).begin(), (cumulative).end(), looking_for) - n             cumulative.begin(); n     rr += q - p; n   } n   return rr; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.precision(16); n   int n, k; n   cin >> n >> k; n   vector<int> aa(n, 0); n   for (int i = 0; i < int(n); ++i) cin >> aa[i]; n   vector<int> cumulative((int((aa).size())), 0); n   cumulative[0] = aa[0]; n   int amax = 0; n   for (int i = int(1); i < int((int((aa).size()))); ++i) { n     cumulative[i] = cumulative[i - 1] ^ aa[i]; n     amax = max(amax, aa[i]); n   } n   cumulative.push_back(0); n   sort((cumulative).begin(), (cumulative).end()); n   LL rr = exactMatchingSubranges(cumulative, k); n   while (true) { n     if ((k & 1) == 0) { n       k |= 1; n       rr += exactMatchingSubranges(cumulative, k); n     } n     k >>= 1; n     amax >>= 1; n     if (amax == 0) break; n     for (int i = 0; i < int((int((cumulative).size()))); ++i) n       cumulative[i] >>= 1; n   } n   cout << rr / 2 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 5, maxm = 4e5 + 5; n int head[maxn], nume; n struct edge { n   int v, w, c, next; n } e[maxm]; n inline void init_edge() { n   memset(head, -1, sizeof head); n   nume = 0; n } n inline void add_edge(int u, int v, int w = 0, int c = 0) { n   e[nume].v = v; n   e[nume].w = w; n   e[nume].c = c; n   e[nume].next = head[u]; n   head[u] = nume++; n } n int dep[maxn], dp[maxn][20], numpow = 19; n void dfs(int u, int f) { n   dep[u] = dep[f] + 1; n   dp[u][0] = f; n   for (int i = 1; i <= numpow; ++i) dp[u][i] = dp[dp[u][i - 1]][i - 1]; n   for (int i = head[u]; ~i; i = e[i].next) { n     int v = e[i].v; n     if (v == f) continue; n     dfs(v, u); n   } n } n int lca(int u, int v) { n   if (dep[u] > dep[v]) swap(u, v); n   if (dep[u] < dep[v]) { n     int tmp = dep[v] - dep[u]; n     for (int i = 0; i <= numpow; ++i) n       if (tmp & (1 << i)) v = dp[v][i]; n   } n   if (u != v) { n     for (int i = numpow; ~i; --i) n       if (dp[u][i] != dp[v][i]) u = dp[u][i], v = dp[v][i]; n     u = v = dp[u][0]; n   } n   return u; n } n int ff(int u, int num) { n   for (int i = 0; (1 << i) <= num; i++) { n     if (num & (1 << i)) u = dp[u][i]; n   } n   return u; n } n int f[maxn]; n int find(int x) { n   if (x == f[x]) return x; n   return f[x] = find(f[x]); n } n int he(int u, int v) { n   u = find(u); n   v = find(v); n   if (u != v) f[u] = v; n } n queue<int> que; n int n, k, r, q; n int vis[maxn]; n int main() { n   scanf( %d%d%d , &n, &k, &r); n   init_edge(); n   for (int i = 1; i < n; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     add_edge(u, v); n     add_edge(v, u); n   } n   memset(vis, -1, sizeof vis); n   for (int i = 1; i <= r; i++) { n     int u; n     scanf( %d , &u); n     vis[u] = 0; n     que.push(u); n   } n   while (!que.empty()) { n     int u = que.front(); n     que.pop(); n     for (int i = head[u]; ~i; i = e[i].next) { n       int v = e[i].v; n       if (vis[v] == -1) { n         vis[v] = vis[u] + 1; n         que.push(v); n       } n     } n   } n   for (int i = 1; i <= n; i++) f[i] = i; n   for (int u = 1; u <= n; u++) { n     for (int i = head[u]; ~i; i = e[i].next) { n       int v = e[i].v; n       if (vis[u] + vis[v] < k) { n         he(u, v); n       } n     } n   } n   dfs(1, 0); n   scanf( %d , &q); n   while (q--) { n     int u, v, Lca, U, V; n     scanf( %d%d , &u, &v); n     Lca = lca(u, v); n     if (dep[u] + dep[v] - 2 * dep[Lca] <= k) n       printf( YES n ); n     else { n       if (dep[u] - dep[Lca] >= (k + 1) / 2) n         U = ff(u, (k + 1) / 2); n       else n         U = ff(v, dep[u] + dep[v] - 2 * dep[Lca] - (k + 1) / 2); n       if (dep[v] - dep[Lca] >= (k + 1) / 2) n         V = ff(v, (k + 1) / 2); n       else n         V = ff(u, dep[u] + dep[v] - 2 * dep[Lca] - (k + 1) / 2); n       if (find(U) == find(V) && vis[U] <= k / 2 && vis[V] <= k / 2) n         printf( YES n ); n       else n         printf( NO n ); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int k, n, w, q, cem = 0; n   cin >> k >> n >> w; n   for (int i = 1; i <= w; i++) { n     cem = cem + i * k; n   } n   if (n <= cem) { n     cout << cem - n; n   } else n     cout << 0; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int cnt_occur(string s, string t) { n   int cnt = 0; n   for (int i = 0; i < s.size(); ++i) { n     if (s.substr(i, 3) == t) cnt++; n   } n   return cnt; n } n long max(int a, int b) { return a >= b ? a : b; } n void swap(int &a, int &b) { n   int temp = a; n   a = b; n   b = temp; n } n int power(int x, unsigned int y) { n   int temp; n   if (y == 0) return 1; n   temp = power(x, y / 2); n   if (y % 2 == 0) n     return temp * temp; n   else n     return x * temp * temp; n } n int gcd(int a, int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n void soE(int n, bool f[]) { n   for (int i = 0; i < n; ++i) f[i] = true; n   f[0] = f[1] = false; n   for (int p = 2; p * p <= n; p++) { n     if (f[p] == true) { n       for (int i = p * p; i <= n; i += p) f[i] = false; n     } n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   int t; n   cin >> t; n   ; n   while (t--) { n     long long a; n     cin >> a; n     long long cnt = 0; n     long long temp = a; n     while (a) { n       if (temp % 2 == 0) { n         if (a % 2 == 0) { n           if ((a / 2) % 2 != 0 or a == 4) { n             cnt += a / 2; n             if (a == 4) { n               a = a / 2; n             } else n               a = a / 2 - 1; n           } else { n             cnt += 1; n             a -= 2; n           } n         } n       } else { n         if (a == 5) { n           cnt += 2; n           break; n         } n         cnt += 1; n         a = a - 1; n         if (a == 0) break; n         if ((a / 2) % 2 == 0) n           a -= 1; n         else n           a = a / 2; n       } n     } n     cout << cnt << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void RI() {} n template <typename... T> n void RI(int& head, T&... tail) { n   scanf( %d , &head); n   RI(tail...); n } n void RLL() {} n template <typename... T> n void RLL(long long& head, T&... tail) { n   scanf( %lld , &head); n   RLL(tail...); n } n void print() { putchar(  n ); } n template <typename T, typename... U> n void print(T head, U... tail) { n   cout << head <<    ; n   print(tail...); n } n const int MOD = 1000000007; n int main() { n   int k, ans = 0; n   RI(k); n   for (int i = 0; i < (int)(k); i++) { n     int r; n     RI(r); n     ans = max(ans, r - 25); n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int K, N, M, Q; n map<string, int> Basic, F[111]; n string st, Comp_St[60]; n vector<pair<string, int> > Comp[60]; n int main() { n   cin >> K >> N >> M >> Q; n   for (int i = 1; i <= N; i++) { n     cin >> st; n     Basic[st] = i; n   } n   for (int i = 0, k; i < M; i++) { n     cin >> st; n     st = st.substr(0, st.size() - 1); n     Comp_St[i] = st; n     for (string stt; cin >> stt;) { n       cin >> k; n       Comp[i].push_back(make_pair(stt, k)); n       char ch; n       scanf( %c , &ch); n       if (ch !=  , ) break; n     } n   } n   for (int i = 0, p; i < Q; i++) { n     cin >> p >> st; n     F[p][st]++; n     for (int j = 0; j < M; j++) { n       st = Comp_St[j]; n       bool flag = true; n       for (int k = 0; k < Comp[j].size(); k++) n         if (F[p][Comp[j][k].first] < Comp[j][k].second) flag = false; n       if (flag) { n         F[p][st]++; n         for (int k = 0; k < Comp[j].size(); k++) n           F[p][Comp[j][k].first] -= Comp[j][k].second; n       } n     } n   } n   for (int i = 1; i <= K; i++) { n     int TOT = 0; n     for (map<string, int>::iterator it = F[i].begin(); it != F[i].end(); it++) n       if (it->second > 0) TOT++; n     printf( %d n , TOT); n     for (map<string, int>::iterator it = F[i].begin(); it != F[i].end(); it++) n       if (it->second > 0) cout << it->first <<     << it->second << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct team { n   string name; n   int score; n   int goals_for; n   int goals_against; n   int goal_diff() const { return goals_for - goals_against; } n }; n bool operator<(const team &A, const team &B) { n   if (A.score != B.score) return A.score > B.score; n   if (A.goal_diff() != B.goal_diff()) return A.goal_diff() > B.goal_diff(); n   return A.goals_for > B.goals_for; n } n map<string, team> m; n int main(void) { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     static char buff[128]; n     scanf( %s , buff); n     team T; n     T.name = string(buff); n     T.score = T.goals_against = T.goals_for = 0; n     m[T.name] = T; n   } n   for (int i = 0; i < n * (n - 1) / 2; ++i) { n     static char buff[128]; n     int ga, gb; n     scanf( %s %d:%d , buff, &ga, &gb); n     string s(buff); n     int f = s.find( - ); n     team &a = m[s.substr(0, f)]; n     team &b = m[s.substr(f + 1)]; n     a.goals_for += ga; n     a.goals_against += gb; n     b.goals_for += gb; n     b.goals_against += ga; n     if (ga > gb) n       a.score += 3; n     else if (ga < gb) n       b.score += 3; n     else { n       a.score += 1; n       b.score += 1; n     } n   } n   vector<team> teams; n   for (map<string, team>::iterator it = m.begin(); it != m.end(); ++it) n     teams.push_back(it->second); n   sort(teams.begin(), teams.end()); n   vector<string> ret; n   for (int i = 0; i < n / 2; ++i) ret.push_back(teams[i].name); n   sort(ret.begin(), ret.end()); n   for (int i = 0; i < n / 2; ++i) printf( %s n , ret[i].c_str()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int read() { n   int tot = 0, fh = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) fh = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     tot = tot * 10 + c -  0 ; n     c = getchar(); n   } n   return tot * fh; n } n void getstr(char *a) { n   char c = getchar(); n   int len = 0; n   while (!((c >=  A  && c <=  Z ) || (c >=  a  && c <=  z ) || n            (c >=  0  && c <=  9 ))) n     c = getchar(); n   while ((c >=  A  && c <=  Z ) || (c >=  a  && c <=  z ) || n          (c >=  0  && c <=  9 )) { n     a[++len] = c; n     c = getchar(); n   } n } n const int maxn = 200100; n int n, t, q, ans, block, num, belong[maxn]; n long long a[maxn], L[2000], R[2000], sum[2000], tag[2000]; n void build() { n   block = sqrt(n); n   num = n / block; n   if (num * block != n) num++; n   for (int i = 1; i <= num; i++) { n     L[i] = block * (i - 1) + 1; n     R[i] = block * i; n     R[num] = n; n     for (int j = L[i]; j <= R[i]; j++) { n       belong[j] = i; n       sum[i] += a[j]; n     } n   } n } n int fd(int l, int r, int lim) {} n int main() { n   n = read(); n   q = read(); n   for (int i = 1; i <= n; i++) a[i] = read(); n   build(); n   while (q--) { n     t = read(); n     if (t == 1) { n       int x = read(); n       long long y = read(); n       for (int i = 1; i < belong[x]; i++) n         if (tag[i] == 0) { n           if (a[R[i]] < y) { n             if (a[L[i]] <= y) { n               tag[i] = y; n               sum[i] = (R[i] - L[i] + 1ll) * tag[i]; n             } else { n               sum[i] = 0; n               for (int j = L[i]; j <= R[i]; j++) { n                 a[j] = max(a[j], y); n                 sum[i] += a[j]; n               } n             } n           } n         } else { n           if (tag[i] < y) { n             tag[i] = y; n             sum[i] = (R[i] - L[i] + 1ll) * tag[i]; n           } n         } n       int cur = belong[x]; n       sum[cur] = 0; n       for (int i = L[cur]; i <= R[cur]; i++) n         if (i <= x) { n           a[i] = max(a[i], max(y, tag[cur])); n           sum[cur] += a[i]; n         } else { n           a[i] = max(a[i], tag[cur]); n           sum[cur] += a[i]; n         } n       tag[cur] = 0; n     } else { n       int x = read(); n       long long y = read(); n       ans = 0; n       int cur = belong[x]; n       for (int i = x; i <= R[cur]; i++) { n         long long tmp = max(tag[cur], a[i]); n         if (y >= tmp) { n           y -= tmp; n           ans++; n           tmp = max(tag[cur], a[R[cur]]); n           if (tmp > y) break; n         } n       } n       for (int i = belong[x] + 1; i <= num; i++) { n         long long tmp = sum[i]; n         if (y >= tmp) { n           y -= tmp; n           ans += R[i] - L[i] + 1; n         } else { n           tmp = max(tag[i], a[R[i]]); n           if (tmp > y) continue; n           for (int j = L[i]; j <= R[i]; j++) { n             tmp = max(tag[i], a[j]); n             if (y >= tmp) { n               y -= tmp; n               ans++; n               tmp = max(tag[i], a[R[i]]); n               if (tmp > y) break; n             } n           } n         } n       } n       cout << ans << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct BIT { n   static const int N = 200006; n   long long a[N]; n   int n; n   void init(int _n) { n     n = _n; n     memset(a, 0, sizeof(a)); n   } n   void update(int pos, long long val) { n     for (int i = pos; n >= i; i += i & (-i)) { n       a[i] += val; n     } n   } n   long long query(int pos) { n     long long ret = 0; n     for (int i = pos; i > 0; i -= i & (-i)) { n       ret += a[i]; n     } n     return ret; n   } n } bit; n const int N = 200006; n const int P = 32; n set<pair<long long, long long> > st[P]; n long long a[N]; n void addd(long long val, int pos) { n   if (!val) n     st[0].insert(make_pair(pos, val)); n   else { n     for (int i = P - 1; i >= 1; i--) { n       if (val >= (1LL << (i - 1))) { n         st[i].insert(make_pair(pos, val)); n         break; n       } n     } n   } n } n void dell(long long val, int pos) { n   if (!val) n     st[0].erase(make_pair(pos, val)); n   else { n     for (int i = P - 1; i >= 1; i--) { n       if (val >= (1LL << (i - 1))) { n         st[i].erase(make_pair(pos, val)); n         break; n       } n     } n   } n } n int main() { n   int n, q; n   scanf( %d %d , &n, &q); n   bit.init(n); n   for (int i = 1; n >= i; i++) { n     scanf( %lld , &a[i]); n     bit.update(i, a[i]); n     addd(a[i], i); n   } n   while (q--) { n     int p, x; n     scanf( %d %d , &p, &x); n     dell(a[p], p); n     bit.update(p, -a[p]); n     a[p] = x; n     addd(a[p], p); n     bit.update(p, a[p]); n     int ans = -1; n     for (int i = 0; P > i; i++) { n       auto iter = st[i].begin(); n       int cnt = 2; n       while (cnt--) { n         if (iter == st[i].end()) break; n         pair<long long, long long> p = (*iter); n         if (bit.query(p.first - 1) == p.second) { n           ans = p.first; n           break; n         } n         ++iter; n       } n     } n     printf( %d n , ans); n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct P { n   int x, y; n }; n P me; n P other; n bool white; n int N, M; n P operator+(P a, P b) { return {a.x + b.x, a.y + b.y}; } n P operator-(P a, P b) { return {a.x - b.x, a.y - b.y}; } n bool operator==(P a, P b) { return a.x == b.x && a.y == b.y; } n bool isItAStep(P a, P b) { n   a = a - b; n   int dx = abs(a.x); n   int dy = abs(a.y); n   return (dx == 1 && dy == 2) || (dx == 2 && dy == 1); n } n P winWhite, winBlack; n void step(P newP) { n   if (white && isItAStep(winWhite, me)) { n     cout << winWhite.x <<     << winWhite.y << endl << flush; n     exit(0); n   } n   if (!white && isItAStep(winBlack, me)) { n     cout << winBlack.x <<     << winBlack.y << endl << flush; n     exit(0); n   } n   if (isItAStep(other, me)) { n     cout << other.x <<     << other.y << endl << flush; n     exit(0); n   } n   me = newP; n   cout << me.x <<     << me.y << endl << flush; n   if (white && me.x == N / 2 && me.y == M / 2) exit(0); n   if (!white && me.x == N / 2 + 1 && me.y == M / 2) exit(0); n } n void getStep() { n   cin >> other.x >> other.y; n   if (other == me) exit(1); n   if (other.x == -1) exit(0); n } n const vector<P> ize = { n     {+1, +2}, {-1, +2}, {+1, -2}, {-1, -2}, n     {+2, +1}, {-2, +1}, {+2, -1}, {-2, -1}, n }; n vector<P> dfs(P from, P to, int K) { n   if (from == to) return vector<P>(1, to); n   if (K == 0) return vector<P>(); n   vector<P> best; n   for (const P& x : ize) { n     P to2 = to + x; n     if (to2.x < 1 || to2.y < 1) continue; n     if (to2.x > N || to2.y > M) continue; n     vector<P> c = dfs(from, to2, K - 1); n     if (best.size() == 0 || (!c.empty() && c.size() < best.size())) best = c; n   } n   if (best.empty()) return best; n   best.push_back(to); n   return best; n } n vector<P> closestDistance_(P from, P to) { n   int dx = abs(to.x - from.x); n   int dy = abs(to.y - from.y); n   int ix = (to.x > from.x ? 1 : -1); n   int iy = (to.y > from.y ? 1 : -1); n   vector<P> S; n   while (dx > 5 || dy > 5) { n     int wx = 2, wy = 1; n     if (dx < dy) { n       wx = 1; n       wy = 2; n     } n     ix = (to.x > from.x ? 1 : -1); n     iy = (to.y > from.y ? 1 : -1); n     from.x += wx * ix; n     from.y += wy * iy; n     S.push_back(from); n     dx = abs(to.x - from.x); n     dy = abs(to.y - from.y); n   } n   vector<P> ize = dfs(from, to, 6); n   assert(!ize.empty()); n   auto it = ize.begin(), end = ize.end(); n   it++; n   while (it != end) { n     S.push_back(*it); n     it++; n   } n   return S; n } n void check(vector<P>& S, P from, P to) { n   if (S.empty()) return; n   P last = from; n   assert(to == S.back()); n   for (const P& p : S) { n     assert(isItAStep(last, p)); n     last = p; n   } n } n int main() { n   int xw, yw, xb, yb; n   cin >> N >> M; n   cin >> xw >> yw >> xb >> yb; n   winWhite = {N / 2, M / 2}; n   winBlack = {N / 2 + 1, M / 2}; n   P whitee = {xw, yw}; n   P blackk = {xb, yb}; n   vector<P> cdww = closestDistance_(whitee, winWhite); n   vector<P> cdbw = closestDistance_(blackk, winWhite); n   vector<P> cdwb = closestDistance_(whitee, winBlack); n   vector<P> cdbb = closestDistance_(blackk, winBlack); n   vector<P> cd; n   white = true; n   bool white_kerget = ((xw ^ xb ^ yw ^ yb) & 1) == 1; n   cerr <<  W->w:   << cdww.size() << endl; n   cerr <<  W->b:   << cdwb.size() << endl; n   cerr <<  B->w:   << cdbw.size() << endl; n   cerr <<  B->b:   << cdbb.size() << endl; n   cerr << (white_kerget ?  White kerget  :  Black kerget ) << endl; n   if (white_kerget) { n     cerr <<  white kerget  << endl; n     if (cdwb.size() <= cdbb.size() + 1) { n       cerr <<  white bevarja  << endl; n       white = true; n       cd = move(cdwb); n     } else if (cdww.size() <= cdbb.size()) { n       cerr <<  white megelozi  << endl; n       white = true; n       cd = move(cdww); n     } else { n       white = false; n       cd = move(cdbb); n     } n   } else { n     cerr <<  black kerget  << endl; n     if (cdbw.size() <= cdww.size()) { n       cerr <<  black bevarja  << endl; n       white = false; n       cd = move(cdbw); n     } else if (cdbb.size() < cdww.size()) { n       cerr <<  black megelozi  << endl; n       white = false; n       cd = move(cdbb); n     } else { n       white = true; n       cd = move(cdww); n     } n   } n   cdww.clear(); n   cdwb.clear(); n   cdbw.clear(); n   cdbb.clear(); n   if (white) { n     me = whitee; n     other = blackk; n     cout <<  WHITE  << endl; n   } else { n     me = blackk; n     other = whitee; n     cout <<  BLACK  << endl; n     getStep(); n   } n   if (!white) { n     cd.push_back(winWhite + P{2, 1}); n     cd.push_back(winWhite + P{0, 2}); n     cd.push_back(winWhite + P{1, 0}); n   } else if (white) { n     cd.push_back(winBlack - P{2, 1}); n     cd.push_back(winBlack - P{0, 2}); n     cd.push_back(winBlack - P{1, 0}); n   } n   int i = 0; n   while (i < cd.size()) { n     step(cd[i]); n     getStep(); n     i++; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[200005]; n bool vis[200005]; n int a[200005]; n int n, m; n double p; n void doit() { n   memset(vis, 0, sizeof(vis)); n   for (int i = 1; i <= n; ++i) { n     scanf( %s , s); n     if (s[0] !=  ? ) { n       a[i] = atoi(s); n       vis[i] = 1; n     } n   } n   for (int i = 1; i <= m; ++i) { n     a[n + i] = 1001000000; n     vis[n + i] = 1; n   } n   n += m; n   long long ans = 0; n   for (int i = 1; i <= m; ++i) { n     int last = -1001000000, ff, t = 0; n     for (int j = i; j <= n; j += m) n       if (vis[j]) { n         if (a[j] - last <= t) { n           printf( Incorrect sequence n ); n           return; n         } n         if (!t) { n           last = a[j]; n           continue; n         } n         if (last <= 0 && a[j] >= 0) { n           if (last < 0 && a[j] > 0) t--; n           if (!t) { n             for (int k = ff; k < j; k += m) a[k] = 0; n             last = a[j]; n             continue; n           } n           int k1 = max(0, last + 1), k2 = 0; n           while (t) { n             if (k2 + 1 < a[j]) k2++, t--; n             if (!t) break; n             if (k1 - 1 > last) k1--, t--; n           } n           last = k1 - 1; n           for (int k = ff; k < j; k += m) a[k] = ++last; n           last = a[j]; n         } else if (last > 0) { n           for (int k = ff; k < j; k += m) a[k] = ++last; n           last = a[j]; n           t = 0; n         } else { n           last = a[j]; n           for (int k = j - m; k >= ff; k -= m) a[k] = --last; n           last = a[j]; n           t = 0; n         } n       } else { n         t++; n         if (t == 1) ff = j; n       } n   } n   n -= m; n   for (int i = 1; i <= n - 1; ++i) printf( %d  , a[i]); n   printf( %d n , a[n]); n } n int main() { n   while (scanf( %d%d , &n, &m) != EOF) doit(); n } n


#include <bits/stdc++.h> n using namespace std; n bool comp(int a, int b) { return (a < b); } n int max(int a, int b) { n   if (a > b) return a; n   return b; n } n int min(int a, int b) { n   if (a < b) return a; n   return b; n } n long long power(long long a, int x) { n   while (x--) { n     a *= a; n   } n   return a; n } n int main() { n   int n, i = 0, x; n   cin >> n; n   string s, c; n   cin >> s; n   while (i < n) { n     x = i; n     if (s[i] ==  o ) n       while (s[i + 1] ==  g  && s[i + 2] ==  o ) i += 2; n     if (x < i) n       c +=  *** ; n     else n       c += s[i]; n     i++; n   } n   cout << c; n } n


#include <bits/stdc++.h> n using namespace std; n long long int arr[378999]; n long long int arr2[234597]; n long long int ab[10]; n vector<long long int> adj[22222]; n map<long long int, long long int> mp, mp2; n map<long long int, long long int>::iterator it; n vector<long long int> vec; n string s; n long long int gcd(long long int a, long long int b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int t, i, loss, j, diff; n   cin >> t; n   while (t--) { n     long long int n, x, y, k, maxi = INT_MIN, mini = INT_MAX, two = 0, one1 = 0, n                               one2 = 0, zero = 0, p; n     long long int cs, cw, w; n     mp.clear(); n     mp2.clear(); n     string s, ans =   ; n     cin >> s; n     cin >> x; n     long long int len = s.length(); n     for (i = 0; i < len; i++) { n       ans +=  1 ; n     } n     long long int f = 0; n     for (i = 0; i < len; i++) { n       if (s[i] ==  1 ) { n         continue; n       } else if (s[i] ==  0 ) { n         if (i - x >= 0) { n           ans[i - x] =  0 ; n         } n         if (i + x < len) { n           ans[i + x] =  0 ; n         } n       } n     } n     for (i = 0; i < len; i++) { n       if (s[i] ==  1 ) { n         if ((i - x >= 0 && ans[i - x] ==  1 ) || n             (i + x < len && ans[i + x] ==  1 )) n           continue; n         else { n           f = 1; n           break; n         } n       } n     } n     if (f == 1) n       cout <<  -1 n ; n     else n       cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[1505]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   int ans = 0; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= i - 1; j++) n       if (a[j] > a[i]) ans ^= 1; n   int q; n   scanf( %d , &q); n   while (q--) { n     int a, b; n     scanf( %d%d , &a, &b); n     int sz = b - a + 1; n     sz = sz * (sz - 1) / 2; n     if (sz % 2 == 1) ans ^= 1; n     if (ans == 0) n       printf( even n ); n     else n       printf( odd n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n; n string str; n int main() { n   cin >> str; n   n = str.length(); n   string str1 = str + str; n   reverse(str.begin(), str.end()); n   string str2 = str + str; n   int ans = 0; n   int dp[2][2 * n]; n   for (int i = 0; i < 2 * n - 1; i++) { n     dp[0][i] = 1; n     if (i > 0 && str1[i] != str1[i - 1]) { n       dp[0][i] += min(n - 1, dp[0][i - 1]); n     } n     ans = max(ans, dp[0][i]); n   } n   for (int i = 0; i < 2 * n - 1; i++) { n     dp[1][i] = 1; n     if (i > 0 && str2[i] != str2[i - 1]) { n       dp[1][i] += min(n - 1, dp[1][i - 1]); n     } n     ans = max(ans, dp[1][i]); n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int a[1111111]; n bool curr_state[22]; n long long sum_inversions[22]; n long long sum_non_inversions[22]; n int tmp_array1[1111111]; n int tmp_array2[1111111]; n int binary_search(int i, int sz) { n   if (tmp_array2[0] >= tmp_array1[i]) return -1; n   int low = 0; n   int high = sz - 1; n   while (low < high) { n     int mid = (low + high + 1) / 2; n     if (tmp_array2[mid] >= tmp_array1[i]) n       high = mid - 1; n     else n       low = mid; n   } n   return low; n } n long long find_num_inversions(int sz) { n   sort(tmp_array2, tmp_array2 + sz); n   long long answer = 0; n   for (int i = 0; i < sz; i++) { n     int j = binary_search(i, sz); n     answer += j + 1; n   } n   return answer; n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < (1 << n); i++) scanf( %d , &a[i]); n   for (int level = 1; level <= n; level++) { n     sum_inversions[level - 1] = 0; n     sum_non_inversions[level - 1] = 0; n     for (int j = 0; j < (1 << n); j += (1 << (n - level + 1))) { n       int l1 = j; n       int u1 = j + (1 << (n - level)) - 1; n       int l2 = j + (1 << (n - level)); n       int u2 = j + (1 << (n - level + 1)) - 1; n       for (int i = l1; i <= u1; i++) { n         tmp_array1[i - l1] = a[i]; n       } n       for (int j = l2; j <= u2; j++) { n         tmp_array2[j - l2] = a[j]; n       } n       sum_inversions[level - 1] += find_num_inversions(u1 - l1 + 1); n       for (int i = l1; i <= u1; i++) { n         tmp_array2[i - l1] = a[i]; n       } n       for (int j = l2; j <= u2; j++) { n         tmp_array1[j - l2] = a[j]; n       } n       sum_non_inversions[level - 1] += find_num_inversions(u1 - l1 + 1); n     } n   } n   for (int i = 0; i <= n - 1; i++) { n     curr_state[i] = false; n   } n   int m; n   scanf( %d , &m); n   for (int i = 1; i <= m; i++) { n     int q; n     scanf( %d , &q); n     for (int j = n - q; j <= n - 1; j++) curr_state[j] = (!curr_state[j]); n     long long answer = 0; n     for (int level = 0; level <= n - 1; level++) n       answer += (curr_state[level] ? sum_non_inversions[level] n                                    : sum_inversions[level]); n     cout << answer << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> t; n int rec(int k, int sz, int n = 0) { n   if (t[n] <= k) return k - t[n]; n   if (n >= sz && t[n]) return n; n   int a = rec(k, sz, 2 * n + 1); n   if (a >= sz) n     return a; n   else n     return rec(a, sz, 2 * n + 2); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   int n, m, q1 = 0, q2 = 0, k = 1; n   cin >> n >> m; n   vector<int> a(m), el; n   for (int i = 0; i < m; ++i) cin >> a[i]; n   while (k < n) k *= 2; n   k *= 2; n   k--; n   t.resize(k); n   for (int i = 0; i < n; ++i) { n     int p; n     cin >> p; n     if (p == 0 || p == 1) { n       el.push_back(p); n       int index = k / 2 + q1; n       t[index] = 1; n       while (index != 0) { n         index = index / 2 - (index % 2 == 0); n         t[index] = t[2 * index + 1] + t[2 * index + 2]; n       } n       q1++; n       q2++; n     } else { n       vector<int> rm; n       int l = -1, r = m; n       while (l + 1 < r) { n         int mid = (l + r) / 2; n         if (a[mid] > q2) n           r = mid; n         else n           l = mid; n       } n       q2 -= l + 1; n       for (int j = 0; j <= l; ++j) rm.push_back(rec(a[j] - 1, k / 2)); n       for (int x : rm) { n         t[x] = 0; n         while (x != 0) { n           x = x / 2 - (x % 2 == 0); n           t[x] = t[2 * x + 1] + t[2 * x + 2]; n         } n       } n     } n   } n   bool empty = true; n   for (int i = 0; i < el.size(); ++i) n     if (t[k / 2 + i]) empty = false, cout << el[i]; n   if (empty) cout <<  Poor stack! ; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   char ch = getchar(); n   long long nega = 1; n   while (!isdigit(ch)) { n     if (ch ==  - ) nega = -1; n     ch = getchar(); n   } n   long long ans = 0; n   while (isdigit(ch)) { n     ans = ans * 10 + ch - 48; n     ch = getchar(); n   } n   if (nega == -1) return -ans; n   return ans; n } n long long a[40005], b[40005]; n long long u[40005], v[40005], n, m; n signed main() { n   cin >> n >> m; n   for (long long i = 1; i <= n; i++) a[i] = read(); n   for (long long j = 1; j <= m; j++) b[j] = read(); n   vector<long long> s; n   for (long long i = 1; i <= n; i++) { n     for (long long j = 1; j <= m; j++) { n       s.push_back(a[i] + b[j]); n       u[a[i] + b[j] + 20000] |= (1LL << (i - 1)); n       v[a[i] + b[j] + 20000] |= (1LL << (j - 1)); n     } n   } n   sort(s.begin(), s.end()); n   s.erase(unique(s.begin(), s.end()), s.end()); n   long long ans = 0; n   for (long long i : s) { n     for (long long j : s) { n       long long r = u[i + 20000] | u[j + 20000], n                 s = v[i + 20000] | v[j + 20000]; n       ans = max(ans, 0LL + __builtin_popcountll(r) + __builtin_popcountll(s)); n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline bool uin(T& a, T b) { n   return a > b ? (a = b, true) : false; n } n template <class T> n inline bool uax(T& a, T b) { n   return a < b ? (a = b, true) : false; n } n const int nax = 2e5 + 10; n vector<int> offer[nax]; n int K[nax]; n int N, M; n bool can(int day) { n   vector<int> last(N, -1); n   for (int i = 0; i <= min(day, nax - 1); ++i) { n     for (int x : offer[i]) { n       last[x] = i; n     } n   } n   vector<int> need(K, K + N); n   vector<int> temp_offer[nax]; n   for (int i = 0; i < N; ++i) n     if (last[i] != -1) temp_offer[last[i]].push_back(i); n   int money = 0; n   for (int d = 0; d <= day; ++d) { n     ++money; n     if (d > 2e5) continue; n     for (int x : temp_offer[d]) { n       if (money >= need[x]) { n         money -= need[x]; n         need[x] = 0; n       } else { n         need[x] -= money; n         money = 0; n         break; n       } n     } n   } n   for (int i = 0; i < N; ++i) n     ; n   ; n   return money >= 2 * accumulate(need.begin(), need.end(), 0); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> N >> M; n   for (int i = 0; i < N; ++i) cin >> K[i]; n   for (int d, t, i = 0; i < M; ++i) { n     cin >> d >> t; n     --d, --t; n     offer[d].push_back(t); n   } n   for (int i = 0; i < 10; ++i) n     ; n   int l = 0, r = 4e5; n   while (l < r) { n     int m = (l + r) / 2; n     ; n     if (can(m)) n       r = m; n     else n       l = m + 1; n   } n   cout << r + 1 <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n struct modint { n   int n; n   modint() : n(0) {} n   modint(int n) : n(n) {} n }; n modint operator+(modint a, modint b) { n   return modint((a.n += b.n) >= mod ? a.n - mod : a.n); n } n modint operator*(modint a, modint b) { return modint(1LL * a.n * b.n % mod); } n bool operator<(modint a, modint b) { return a.n < b.n; } n bool operator!=(modint a, modint b) { return a.n != b.n; } n const int S = 4; n using modints = array<modint, S>; n modints operator+(modints a, modints b) { n   modints ret; n   for (int i = 0; i < S; i++) { n     ret[i] = a[i] + b[i]; n   } n   return ret; n } n modints operator*(modints a, modints b) { n   modints ret; n   for (int i = 0; i < S; i++) { n     ret[i] = a[i] * b[i]; n   } n   return ret; n } n bool operator<(modints a, modints b) { n   for (int i = 0; i < S; i++) { n     if (a[i] != b[i]) return a[i] < b[i]; n   } n   return false; n } n const int N = 1e5; n int n; n vector<int> g[N]; n vector<int> gg[N]; n modints rnd[N]; n int height[N]; n vector<int> h; n modints val[N]; n modints one; n map<modints, int> mp; n pair<int, int> ans; n int cnt = 0; n void add(modints a) { n   if (mp[a]++ == 0) { n     cnt++; n   } n } n void del(modints a) { n   if (mp[a]-- == 1) { n     cnt--; n   } n   assert(mp[a] >= 0); n } n void dfs(int u, int p) { n   for (int v : g[u]) n     if (v != p) { n       dfs(v, u); n       height[u] = max(height[u], height[v] + 1); n     } n   val[u] = one; n   for (int v : g[u]) n     if (v != p) { n       val[u] = val[u] * (rnd[height[u]] + val[v]); n     } n   add(val[u]); n } n void dfs2(int u, int p) { n   auto tmp = val[u]; n   del(tmp); n   int n = g[u].size(); n   h.clear(); n   h.push_back(0); n   for (int v : g[u]) { n     h.push_back(height[v] + 1); n   } n   sort(h.rbegin(), h.rend()); n   int h0 = h[0]; n   int h1 = h[1]; n   modints L0 = one; n   modints L1 = one; n   vector<modints> R0(n); n   vector<modints> R1(n); n   R0[n - 1] = one; n   R1[n - 1] = one; n   for (int i = n - 2; i >= 0; i--) { n     R0[i] = R0[i + 1] * (rnd[h0] + val[g[u][i + 1]]); n     R1[i] = R1[i + 1] * (rnd[h1] + val[g[u][i + 1]]); n   } n   ans = max(ans, make_pair(cnt, u)); n   for (int i = 0; i < n; i++) { n     int v = g[u][i]; n     if (height[v] + 1 != h0) { n       height[u] = h0; n       val[u] = L0 * R0[i]; n     } else { n       height[u] = h1; n       val[u] = L1 * R1[i]; n     } n     L0 = L0 * (rnd[h0] + val[v]); n     L1 = L1 * (rnd[h1] + val[v]); n     if (v == p) continue; n     add(val[u]); n     dfs2(v, u); n     del(val[u]); n   } n   add(tmp); n } n int main() { n   mt19937 mt(time(NULL) ^ 1234567); n   uniform_int_distribution<int> uni(0, mod - 1); n   for (int i = 0; i < N; i++) { n     for (int j = 0; j < S; j++) { n       rnd[i][j] = uni(mt); n     } n   } n   for (int i = 0; i < S; i++) { n     one[i] = 1; n   } n   cin >> n; n   for (int i = 0; i < n - 1; i++) { n     int u, v; n     scanf( %d %d , &u, &v); n     u--; n     v--; n     g[u].push_back(v); n     g[v].push_back(u); n   } n   if (n == 1) { n     cout << 1 << endl; n     return 0; n   } n   dfs(0, -1); n   dfs2(0, -1); n   cout << ans.second + 1 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, ta; n   cin >> a >> ta; n   int b, tb, h = 0, m = 0, num = 0; n   int totmin; n   cin >> b >> tb; n   string s; n   cin >> s; n   for (int i = 0; i < 2; i++) { n     h = h * 10 + (s[i] -  0 ); n   } n   for (int i = 3; i < 5; i++) { n     m = m * 10 + (s[i] -  0 ); n   } n   totmin = h * 60 + m; n   for (int i = 5 * 60; i <= 1439; i += b) { n     if ((i <= totmin && i + tb > totmin) || (i >= totmin && i < totmin + ta)) n       num++; n   } n   cout << num; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = (1ll << 32); n const int LOGN = 14; n const long long INF = (1ll << 62); n long long __gcd(long long a, long long b) { n   if (b == 0) return a; n   return __gcd(b, a % b); n } n bool comp(pair<int, unordered_set<int> >& a, n           pair<int, unordered_set<int> >& b) { n   return a.second.size() > b.second.size(); n } n int main() { n   std ::ios_base ::sync_with_stdio(false); n   cin.tie(NULL), cout.tie(NULL); n   int n, m; n   cin >> n >> m; n   vector<pair<int, unordered_set<int> > > a(n); n   int sz; n   int ct = 0; n   int ct_p1 = 0; n   for (int i = 0; i < n; ++i) { n     cin >> sz; n     ct += sz; n     a[i].first = i; n     int x; n     for (int j = 0; j < sz; ++j) { n       cin >> x; n       a[i].second.insert(x); n     } n   } n   ct_p1 = ct % n; n   ct /= n; n   sort(a.begin(), a.end(), comp); n   int l = 0; n   int r = n - 1; n   vector<vector<int> > ans; n   while (l < r) { n     int req_l_size = ct; n     int req_r_size = ct; n     if (l < ct_p1) req_l_size++; n     if (r < ct_p1) req_r_size++; n     vector<int> temp; n     for (auto it : a[l].second) { n       if ((int)a[l].second.size() - (int)temp.size() == req_l_size) break; n       if (a[r].second.size() == req_r_size) break; n       if (a[r].second.find(it) == a[r].second.end()) { n         temp.push_back(it); n         a[r].second.insert(it); n         vector<int> x; n         x.push_back(a[l].first); n         x.push_back(a[r].first); n         x.push_back(it); n         ans.push_back(x); n       } n     } n     for (int i = 0; i < temp.size(); ++i) a[l].second.erase(temp[i]); n     if (a[r].second.size() == req_r_size) r--; n     if (a[l].second.size() == req_l_size) l++; n   } n   cout << ans.size() << endl; n   for (int i = 0; i < ans.size(); ++i) n     cout << ans[i][0] + 1 <<     << ans[i][1] + 1 <<     << ans[i][2] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   scanf( %d , &t); n   string s1, s2; n   cin >> s1 >> s2; n   int temp; n   vector<int> index; n   for (int i = 0; i < t; i++) { n     temp = -1; n     if (s1[i] == s2[i]) { n       continue; n     } n     for (int j = i + 1; j < t; j++) { n       if (s1[j] == s2[i]) { n         temp = j; n         break; n       } n     } n     if (temp == -1) { n       printf( %d , temp); n       return 0; n     } n     for (int j = temp - 1; j >= i; j--) { n       swap(s1[j], s1[j + 1]); n       index.push_back(j + 1); n     } n   } n   printf( %d n , index.size()); n   for (int i = 0; i < index.size(); i++) { n     printf( %d  , index[i]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n void __print(int x) { cerr << x; } n void __print(long x) { cerr << x; } n void __print(long long x) { cerr << x; } n void __print(float x) { cerr << x; } n void __print(double x) { cerr << x; } n void __print(long double x) { cerr << x; } n void __print(char x) { cerr <<      << x <<     ; } n void __print(const char *x) { cerr <<     << x <<    ; } n void __print(const string &x) { cerr <<     << x <<    ; } n void __print(bool x) { cerr << (x ?  true  :  false ); } n template <typename T, typename V> n void __print(const pair<T, V> &x) { n   cerr <<  { ; n   __print(x.first); n   cerr <<  , ; n   __print(x.second); n   cerr <<  } ; n } n template <typename T> n void __print(const T &x) { n   int f = 0; n   cerr <<  { ; n   for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i); n   cerr <<  } ; n } n void _print() { cerr <<  ] n ; } n template <typename T, typename... V> n void _print(T t, V... v) { n   __print(t); n   if (sizeof...(v)) cerr <<  ,  ; n   _print(v...); n } n const long long inf = 9223372036854775807; n const long long mod = 1000000007; n const double pi = acos(-1); n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(0); n   long long n, k; n   cin >> n >> k; n   long long val = n - (n % 2); n   if (n == 1) { n     if (k == 0) { n       cout << 1; n     } else { n       cout << -1; n     } n     return 0; n   } n   if (val / 2 > k) { n     cout << -1; n   } else { n     long long x = (val / 2 - 1); n     cout << k - x <<     << (k - x) * 2 <<    ; n     set<long long> s; n     s.insert(k - x); n     s.insert((k - x) * 2); n     long long t = 2; n     for (int i = 0; i < x; i++) { n       if (s.find(t) == s.end() && s.find(t + 1) == s.end()) { n         cout << t <<     << t + 1 <<    ; n         s.insert(t); n         s.insert(t + 1); n         t += 2; n       } else { n         t += 2; n         i--; n       } n     } n     t += 2; n     if (n % 2 != 0) { n       while (t == (k - x) || t == (k - x) * 2) { n         t++; n       } n       cout << t; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n bool ckmin(T& a, const T& b) { n   return b < a ? a = b, 1 : 0; n } n template <class T> n bool ckmax(T& a, const T& b) { n   return a < b ? a = b, 1 : 0; n } n void solve() { n   int n, k; n   cin >> n >> k; n   vector<int> a(n); n   for (int i = 0; i < (int)(n); ++i) cin >> a[i]; n   set<int> st; n   vector<int> ans; n   for (int i = 0; i < (int)(n); ++i) { n     if (st.find(a[i]) == st.end()) { n       ans.push_back(i + 1); n     } n     st.insert(a[i]); n   } n   if (ans.size() < k) n     cout <<  NO ; n   else { n     cout <<  YES  <<   n ; n     for (int i = 0; i < (int)(k); ++i) cout << ans[i] <<    ; n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.precision(10); n   int T = 1; n   while (T--) { n     solve(); n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e9 + 100; n const int MX = 200503; n int N, M, k; n int arr[MX]; n int cnt[MX]; n vector<int> G[MX]; n int vis[MX]; n vector<int> sr; n void dfs(int x) { n   vis[x] = 1; n   for (int i = 0; i < G[x].size(); i++) { n     int ch = G[x][i]; n     if (vis[ch] == 1) { n       sr.push_back(ch); n     } else if (!vis[ch]) n       dfs(ch); n   } n   vis[x] = 2; n } n int get(int x, int p) { n   int ret = arr[x]; n   vis[x] = 1; n   for (int i = 0; i < G[x].size(); i++) { n     int ch = G[x][i]; n     if (vis[ch]) continue; n     ret = min(ret, get(ch, x)); n   } n   return ret; n } n int main() { n   scanf( %d , &N); n   for (int i = 1; i <= N; i++) { n     scanf( %d , &arr[i]); n   } n   for (int i = 1; i <= N; i++) { n     int x; n     scanf( %d , &x); n     G[i].push_back(x); n   } n   long long an = 0; n   for (int i = 1; i <= N; i++) n     if (vis[i] == 0) dfs(i); n   memset(vis, 0, sizeof vis); n   for (int i = 0; i < sr.size(); i++) an += get(sr[i], -1); n   cout << an <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long nChooseR(int n, int k); n long long gcd(long long a, long long b); n vector<string> split(string target, char c); n bool isPrime(long long g); n long long n, k, r, l, t, x, y, m, a[100003]; n long long ans; n int main() { n   string s; n   cin >> s; n   reverse(((s).begin()), ((s).end())); n   ans = s[0] ==  1 ; n   n = ((int)((s).size())); n   x = 1; n   for (int i = 0; i < (int)(n - 1); i++) { n     x *= 4; n     x %= 1000000007; n     if (s[i + 1] ==  1 ) n       ans = ans * 2 + x; n     else n       ans *= 2; n     ans %= 1000000007; n   } n   cout << ans; n   return 0; n } n long long nChooseR(int n, int k) { n   if (k > n) return 0; n   if (k * 2 > n) k = n - k; n   if (k == 0) return 1; n   long long result = n; n   for (int i = 2; i <= k; ++i) { n     result *= (n - i + 1); n     result /= i; n   } n   return result; n } n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n vector<string> split(string target, char c) { n   string d =   ; n   vector<string> arr; n   for (auto n : target) { n     if (n != c) n       d += n; n     else if (d !=   ) n       arr.push_back(d), d =   ; n   } n   if (d !=   ) arr.push_back(d), d =   ; n   return arr; n } n bool isPrime(long long g) { n   if ((g % 2 == 0 && g > 2) || g == 1) return 0; n   for (int i = 3; i * i <= g; i += 2) n     if (g % i == 0) return 0; n   return 1; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n vector<int> v; n vector<vector<int>> g; n int in[N], out[N], col[N], is[N], dp[18][N], depth[N], z; n struct node { n   int l, r, id; n   node(int a = 0, int b = 0, int c = 0) { n     l = a; n     r = b; n     id = c; n   } n   bool operator<(const node& e) const { n     int a = l / z, b = e.l / z; n     if (a != b) return a < b; n     if (a & 1) return r > e.r; n     return r < e.r; n   } n }; n vector<node> q; n void dfs(int u, int p) { n   dp[0][u] = p; n   in[u] = v.size(); n   v.push_back(u); n   for (int i = 1; i < 18; i++) n     dp[i][u] = dp[i - 1][u] + 1 ? dp[i - 1][dp[i - 1][u]] : -1; n   for (auto i : g[u]) n     if (i != p) depth[i] = depth[u] + 1, dfs(i, u); n   out[u] = v.size(); n   v.push_back(u); n } n int lca(int a, int b) { n   if (depth[a] < depth[b]) swap(a, b); n   for (int i = 17; i + 1; i--) n     if (depth[a] - (1 << i) >= depth[b]) a = dp[i][a]; n   if (a == b) return a; n   for (int i = 17; i + 1; i--) n     if (dp[i][a] != dp[i][b]) a = dp[i][a], b = dp[i][b]; n   return dp[0][a]; n } n int main() { n   int n; n   scanf( %d , &n); n   g.resize(n); n   for (int i = 0; i < n; i++) scanf( %d , is + i); n   for (int i = 0; i < n; i++) scanf( %d , col + i); n   for (int i = 1; i < n; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     g[--a].push_back(--b); n     g[b].push_back(a); n   } n   dfs(0, -1); n   scanf( %d , &n); n   z = sqrt(v.size()) + 1; n   for (int i = 0; i < n; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     --a; n     --b; n     if (in[a] > in[b]) swap(a, b); n     q.push_back(node(in[a] + 1, in[b], i)); n   } n   sort(q.begin(), q.end()); n   long long ans[N] = {}, temp = 0, freq[N] = {}; n   int l = 0, r = -1; n   unordered_map<int, int> mp[2]; n   for (auto i : q) { n     if (i.l - 1 == i.r) continue; n     while (r < i.r) { n       r++; n       int a = is[v[r]]; n       int b = col[v[r]]; n       if (freq[v[r]]++) { n         temp -= mp[!a][b]; n         mp[a][b]--; n       } else { n         temp += mp[!a][b]; n         mp[a][b]++; n       } n     } n     while (r > i.r) { n       int a = is[v[r]]; n       int b = col[v[r]]; n       if (--freq[v[r]]) { n         temp += mp[!a][b]; n         mp[a][b]++; n       } else { n         temp -= mp[!a][b]; n         mp[a][b]--; n       } n       r--; n     } n     while (l < i.l) { n       int a = is[v[l]]; n       int b = col[v[l]]; n       if (--freq[v[l]]) { n         temp += mp[!a][b]; n         mp[a][b]++; n       } else { n         temp -= mp[!a][b]; n         mp[a][b]--; n       } n       l++; n     } n     while (l > i.l) { n       l--; n       int a = is[v[l]]; n       int b = col[v[l]]; n       if (freq[v[l]]++) { n         temp -= mp[!a][b]; n         mp[a][b]--; n       } else { n         temp += mp[!a][b]; n         mp[a][b]++; n       } n     } n     int LCA = lca(v[i.l - 1], v[i.r]); n     int lol = mp[!is[LCA]][col[LCA]]; n     ans[i.id] = temp + lol; n   } n   for (int i = 0; i < q.size(); i++) printf( %lld n , ans[i]); n } n


#include <bits/stdc++.h> n using namespace std; n int n, ls, tp, cx, yy, qq; n char s[64]; n string ans, cur, st[55555][2], tt; n bool quot, found; n int main() { n   scanf( %d n , &n); n   tp = -1; n   found = false; n   qq = 0; n   for (int _ = 0; _ < n; ++_) { n     gets(s); n     ls = strlen(s); n     quot = false; n     cur =   ; n     for (int i = 0; i < ls; ++i) n       if (quot) { n         if (s[i] ==    ) n           quot = false; n         else n           cur += s[i]; n       } else { n         if (s[i] ==    ) n           quot = true; n         else if (s[i] !=    ) n           cur += s[i]; n       } n     if (!cur.find( try )) { n       tp += !found; n       qq += found; n     } else if (!cur.find( catch )) { n       if (qq) { n         --qq; n         continue; n       } n       if (found) { n         st[tp][0] =   ; n         cx = 6; n         while (cur[cx] !=  , ) st[tp][0] += cur[cx++]; n         ++cx; n         st[tp][1] =   ; n         while (cur[cx] !=  ) ) st[tp][1] += cur[cx++]; n         if (!tp) break; n       } n       --tp; n     } else if (!cur.find( throw )) { n       found = true; n       yy = tp; n       cx = 6; n       tt =   ; n       while (cur[cx] !=  ) ) tt += cur[cx++]; n     } n   } n   ans =  Unhandled Exception ; n   for (int i = yy; i >= 0; --i) n     if (st[i][0] == tt) { n       ans = st[i][1]; n       break; n     } n   printf( %s , ans.c_str()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxL = 70; n int mod = 1e9 + 7; n long long mod1 = 1e9 + 7; n const int inf = 1.2e18; n const int maxn = 6e5 + 100; n const int baze = 330; n const int base = 3; n int from[maxn]; n int to[maxn]; n int w[maxn]; n int dis[maxn]; n int head[maxn]; n int sdfgf[maxn]; n int backup[maxn]; n int chiz[maxn]; n int eof, source = maxn - 1, sink = maxn - 2; n void add_edge(int u, int v, int W) { n   from[eof] = u, to[eof] = v, w[eof] = W, sdfgf[eof] = head[u], head[u] = eof++; n   swap(u, v); n   W = 0; n   from[eof] = u, to[eof] = v, w[eof] = W, sdfgf[eof] = head[u], head[u] = eof++; n } n bool bfs() { n   int st = 0, en = 1; n   chiz[0] = source; n   memset(dis, 63, sizeof dis); n   dis[source] = 0; n   while (st < en) { n     int v = chiz[st++]; n     for (int e = head[v]; ~e; e = sdfgf[e]) n       if (w[e] && dis[to[e]] > dis[v] + 1) { n         dis[to[e]] = dis[v] + 1; n         chiz[en++] = to[e]; n         if (to[e] == sink) return true; n       } n   } n   return false; n } n int dfs(int v, int mn = 1000000) { n   if (!mn || v == sink) return mn; n   int ret = 0; n   for (int &e = head[v]; ~e; e = sdfgf[e]) n     if (dis[to[e]] == dis[v] + 1) { n       int x = dfs(to[e], min(mn, w[e])); n       ret += x; n       w[e] -= x; n       w[e ^ 1] += x; n       mn -= x; n       if (mn == 0) break; n     } n   return ret; n } n int flow() { n   memcpy(backup, head, sizeof head); n   int ret = 0; n   while (bfs()) { n     ret += dfs(source); n     memcpy(head, backup, sizeof head); n   } n   return ret; n } n int ar[60]; n string t[maxn]; n int pos[maxn]; n int n; n int32_t main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   memset(head, -1, sizeof head); n   map<string, int> mp; n   mp[ S ] = 0; n   mp[ M ] = 1; n   mp[ L ] = 2; n   mp[ XL ] = 3; n   mp[ XXL ] = 4; n   mp[ XXXL ] = 5; n   for (int i = 0; i < 6; i++) cin >> ar[i], add_edge(source, i, ar[i]); n   cin >> n; n   vector<int> vc; n   for (int i = 0; i < n; i++) { n     string s; n     cin >> s; n     t[i] = s; n     pos[i] = ((int)((s).size())); n     if (s.find( , ) < ((int)((s).size()))) { n       int x = s.find( , ); n       pos[i] = x; n       vc.push_back(eof); n       add_edge(mp[s.substr(0, x)], i + 10, 1); n       add_edge(mp[s.substr(x + 1, ((int)((s).size())))], i + 10, 1); n       add_edge(i + 10, sink, 1); n     } else n       vc.push_back(eof), add_edge(mp[s], sink, 1); n   } n   int ans = flow(); n   if (ans != n) return cout <<  NO  << endl, 0; n   cout <<  YES  << endl; n   int hlp = 0; n   for (int x : vc) { n     if (w[x] == 0) n       cout << t[hlp].substr(0, pos[hlp]) <<   n ; n     else n       cout << t[hlp].substr(pos[hlp] + 1, ((int)((t[hlp]).size()))) <<   n ; n     hlp++; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long mod1(long long x) { n   if (x >= 0) { n     return x; n   } n   return -x; n } n vector<long long> countDigit(long long n) { n   vector<long long> ret; n   while (n != 0) { n     ret.push_back(n % 10); n     n = n / 10; n   } n   return ret; n } n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long lcm1(long long a, long long b) { return (a / gcd(a, b)) * b; } n bool prime[1000000]; n void SieveOfEratosthenes(long long n) { n   memset(prime, true, sizeof(prime)); n   prime[1] = false; n   for (long long p = 2; p * p <= n; p++) { n     if (prime[p] == true) { n       for (long long i = p * p; i <= n; i += p) prime[i] = false; n     } n   } n } n bool isPowerOfTwo(long long n) { n   if (n == 0) return false; n   return (ceil(log2(n)) == floor(log2(n))); n } n bool PowerOfFour(long long num) { n   if (num <= 0) return false; n   while (num != 1) { n     if (num % 4 != 0) return false; n     num = num / 4; n   } n   return true; n } n bool compare(pair<long long, long long> p1, pair<long long, long long> p2) { n   if (p1.first != p2.first) { n     return p1.first > p2.first; n   } else { n     p1.second > p2.second; n   } n } n bool compare1(pair<long long, long long> p1, pair<long long, long long> p2) { n   if (p1.second != p2.second) { n     return p1.second < p2.second; n   } else { n     p1.first < p2.first; n   } n } n bool isPalindrome(string str) { n   long long l = 0; n   long long h = str.size() - 1; n   while (h > l) { n     if (str[l++] != str[h--]) { n       return false; n     } n   } n   return true; n } n vector<long long> primef(long long n) { n   vector<long long> v; n   if (n == 1) { n     return v; n   } n   while (n % 2 == 0) { n     v.push_back(2); n     n = n / 2; n   } n   for (long long i = 3; i <= sqrt(n); i = i + 2) { n     while (n % i == 0) { n       v.push_back(i); n       n = n / i; n     } n   } n   if (n > 2) v.push_back(n); n   return v; n } n long long mod = 1000000007; n long long fact1(long long x) { n   if (x < 2) { n     return 1; n   } n   return (x * fact1(x - 1)) % mod; n } n long long power1(long long x, long long y) { n   long long r = 1; n   while (y > 0) { n     r = (r % mod * x % mod) % mod; n     y--; n   } n   return r; n } n bool isp(long long x) { n   if (x >= 0) { n     long long sr = sqrt(x); n     return (sr * sr == x); n   } n   return false; n } n bool isPri(long long n) { n   if (n <= 1) return false; n   for (long long i = 2; i < n; i++) n     if (n % i == 0) return false; n   return true; n } n long long power2(long long x, long long y, long long p) { n   long long res = 1; n   x = x % p; n   if (x == 0) return 0; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n long long gcdExtended(long long a, long long b, long long *x, long long *y) { n   if (a == 0) { n     *x = 0, *y = 1; n     return b; n   } n   long long x1, y1; n   long long gcd = gcdExtended(b % a, a, &x1, &y1); n   *x = y1 - (b / a) * x1; n   *y = x1; n   return gcd; n } n long long modInverse(long long b, long long m) { n   long long x, y; n   long long g = gcdExtended(b, m, &x, &y); n   if (g != 1) return -1; n   return (x % m + m) % m; n } n long long ask(long long val) { n   cout << val << endl; n   fflush(stdout); n   long long x; n   cin >> x; n   return x; n } n void solve() { n   long long n; n   cin >> n; n   string s; n   cin >> s; n   long long ret = INT_MAX; n   for (long long i = 0; i < 26; i++) { n     long long l = 0; n     long long r = n - 1; n     long long c = 0; n     while (l <= r) { n       if (s[l] == s[r]) { n         l++; n         r--; n         continue; n       } n       if (s[l] == i +  a ) { n         l++; n         c++; n         continue; n       } n       if (s[r] == i +  a ) { n         r--; n         c++; n         continue; n       } n       c = INT_MAX; n       break; n     } n     ret = min(ret, c); n   } n   if (ret == INT_MAX) { n     cout <<  -1  << endl; n   } else { n     cout << ret << endl; n   } n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long power(long long base, long long pow, long long mo) { n   long long res = 1; n   while (pow) { n     if (pow % 2 != 0) res = (res * base) % mo; n     base = (base * base) % mo; n     pow /= 2; n   } n   return res; n } n long long inv(long long i) { return power(i, 1000000007 - 2, 1000000007); } n std::string str =  All Good Till Here ; n void solve() { n   long long i, j, x, n; n   cin >> n; n   long long a[n], p[n]; n   for (long long c1 = 0; c1 < n; c1++) cin >> a[c1]; n   ; n   for (long long i = 0; i < n; i++) { n     p[a[i] - 1] = i; n   } n   long long ans = 0, max2 = 1; n   for (long long i = 1; i < n; i++) { n     if (p[i] > p[i - 1]) { n       max2++; n     } else { n       ans = max(max2, ans); n       max2 = 1; n     } n   } n   ans = max(max2, ans); n   cout << n - ans <<   n ; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long tt; n   tt = 1; n   while (tt--) { n     solve(); n   } n   return 0; n } n