#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9 + 7; n const int MAXN = 1e6 + 7; n const double EPS = 1e-6; n const int M = 15; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   srand(time(0)); n   vector<vector<int> > dp(M + 1); n   vector<vector<pair<int, int> > > nxt(M + 1); n   for (int m = 0; m <= M; m++) { n     int N = (1 << m); n     dp[m].resize(N, INF); n     nxt[m].resize(N); n     queue<int> q; n     if (m < M) { n       q.push(0); n       dp[m][0] = 0; n     } else { n       for (int i = 0; i < 8; i++) { n         q.push(i << 12); n         dp[M][i << 12] = 0; n       } n     } n     while (!q.empty()) { n       int mask = q.front(); n       q.pop(); n       for (int a = 0; a < m; a++) { n         for (int k = 1; k < m; k++) { n           int b = a + k, c = a + 2 * k; n           if (c >= m) break; n           int mask1 = mask; n           mask1 ^= (1 << a); n           mask1 ^= (1 << b); n           mask1 ^= (1 << c); n           if (dp[m][mask1] != INF) continue; n           dp[m][mask1] = dp[m][mask] + 1; n           nxt[m][mask1] = {a, k}; n           q.push(mask1); n         } n       } n     } n   } n   int n; n   cin >> n; n   vector<int> all(n); n   for (int i = 0; i < n; i++) { n     cin >> all[i]; n   } n   if (n < 15) { n     int mask = 0; n     for (int i = n - 1; i >= 0; i--) { n       mask = mask * 2 + all[i]; n     } n     if (dp[n][mask] == INF) { n       cout <<  NO n ; n       return 0; n     } n     cout <<  YES n ; n     cout << dp[n][mask] <<   n ; n     while (mask) { n       int a = nxt[n][mask].first, k = nxt[n][mask].second; n       mask ^= (1 << a); n       mask ^= (1 << (a + k)); n       mask ^= (1 << (a + 2 * k)); n       cout << a + 1 <<     << a + 1 + k <<     << a + 1 + 2 * k <<   n ; n     } n     return 0; n   } n   cout <<  YES n ; n   vector<pair<int, int> > res; n   for (int i = 0, sz = M, fl = false; !fl; i += 12) { n     if (i >= n - 14) { n       sz = 14; n       i = n - 14; n       fl = true; n     } n     int mask = 0; n     for (int j = sz - 1; j >= 0; j--) { n       mask = mask * 2 + all[i + j]; n     } n     assert(dp[sz][mask] != INF); n     while (dp[sz][mask]) { n       int a = nxt[sz][mask].first, k = nxt[sz][mask].second; n       int b = a + k, c = a + 2 * k; n       all[i + a] ^= 1; n       all[i + b] ^= 1; n       all[i + c] ^= 1; n       mask ^= (1 << a); n       mask ^= (1 << b); n       mask ^= (1 << c); n       res.push_back({i + a, k}); n     } n   } n   for (int i = 0; i < n; i++) { n     assert(!all[i]); n   } n   cout << res.size() <<   n ; n   for (auto p : res) { n     int a = p.first, k = p.second; n     cout << a + 1 <<     << a + k + 1 <<     << a + 2 * k + 1 <<   n ; n   } n } n


# include <algorithm> n # include <iostream> n # include <numeric> n # include <vector> n # include <set> n  n using namespace std; n  n int main() { n   int n, a, b; n   while (cin >> n >> a >> b) { n     string s; n     cin >> s; n     set<char> chars_set; n     for (char c : s) { n       chars_set.insert(c); n     } n     vector<char> chars(chars_set.begin(), chars_set.end()); n     int cc = (int)chars.size(); n     vector<int> L(cc, n + 1); n     vector<int> R(cc, -1); n     vector<int> cnt(cc, 0); n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < cc; j++) { n         if (s[i] == chars[j]) { n           L[j] = min(L[j], i); n           R[j] = max(R[j], i); n           cnt[j] += 1; n         } n       } n     } n     vector<int> order(cc); n     iota(order.begin(), order.end(), 0); n     sort(order.begin(), order.end(), [&](int i, int j) { n       return L[i] < L[j]; n     }); n     vector<int> order2 = order; n     sort(order2.begin(), order2.end(), [&](int i, int j) { n       return R[i] < R[j]; n     }); n     vector<int> order3 = order; n     sort(order3.begin(), order3.end(), [&](int i, int j) { n       return (L[i] + R[i]) / 2 < (L[j] + R[j]) / 2; n     }); n     vector<int> order4 = order; n     sort(order4.begin(), order4.end(), [&](int i, int j) { n       return cnt[i] < cnt[j]; n     }); n     vector<bool> can(1 << cc, 0); n     can[0] = 1; n     for (int t = 1; t < (1 << cc); t++) { n       int max_R = -1; n       int min_L = -1; n       int total = 0; n       for (int i : order) { n         if (!(t & (1 << i))) { n           continue; n         } n         if (min_L == -1) { n           min_L = L[i]; n         } n         total += cnt[i]; n         max_R = max(max_R, R[i]); n       } n       int len = max_R - min_L + 1; n       if (total * b >= a * len) { n         can[t] = 0; n         for (int i = 0; i < cc; i++) { n           if (t & (1 << i)) { n             if (can[t ^ (1 << i)]) { n               can[t] = 1; n               break; n             } n           } n         } n         if (can[t]) { n           continue; n         } n       } n       int nt = 0; n       for (auto& v : {order, order2, order3, order4}) { n         for (int i : v) { n           if (!(t & (1 << i))) { n             continue; n           } n           nt |= (1 << i); n           if (nt != t && can[nt] && can[t ^ nt]) { n             can[t] = 1; n             break; n           } n         } n       } n     } n     string ret =   ; n     for (int i = 0; i < cc; i++) { n       if (can[(1 << cc) - 1 - (1 << i)]) { n         ret += chars[i]; n       } n     } n     cout << ret.size(); n     for (char c : ret) { n       cout <<     << c; n     } n     cout <<   n ; n   } n   return 0; n } //


#include <bits/stdc++.h> n const int maxn = 10010; n const int mod = 1000000007; n int n; n char ch[4][maxn]; n int f[maxn][8][2]; n int obs[maxn]; n int ot, vt; n void part0() { n   memset(obs, 0, sizeof(obs)); n   for (int j = 1; j <= n; j++) n     for (int i = 3; i >= 1; i--) n       obs[j] = (obs[j] << 1) + ((ch[i][j] !=  . ) ? 1 : 0); n   for (int i = 1; i <= 3; i++) n     for (int j = 1; j <= n; j++) n       if (ch[i][j] ==  O ) { n         ot = j; n         vt = 1 << (i - 1); n       } n } n void init() { n   scanf( %d , &n); n   for (int i = 1; i <= 3; i++) scanf( %s , ch[i] + 1); n } n void solve() { n   part0(); n   memset(f, 0, sizeof(f)); n   f[0][7][0] = 1; n   for (int i = 1; i <= n; i++) n     for (int j = 0; j < 8; j++) n       for (int k = 0; k < 2; k++) { n         if (!f[i - 1][j][k]) continue; n         int cnt = j ^ 7; n         if (cnt & obs[i]) continue; n         int oc = cnt | obs[i]; n         for (int c = 0; c <= 6; c += 3) { n           if (oc & c) continue; n           int oct = oc | c; n           if ((i == ot - 1) && (cnt & vt) || n               (i == ot) && (!(oc ^ vt)) && (vt != 2) || n               (i - 2 == ot) && (cnt & vt)) { n             f[i][oct][1] = (f[i][oct][1] + f[i - 1][j][k]) % mod; n           } else n             f[i][oct][k] = (f[i][oct][k] + f[i - 1][j][k]) % mod; n         } n       } n } n void print() { printf( %d n , f[n][7][1]); } n int main() { n   init(); n   solve(); n   print(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int bs(int arr[], int n, int target) { n   int left = 0, mid, right = n - 1; n   while (left <= right) { n     mid = left + (right - left) / 2; n     if (arr[mid] < target) n       left = mid + 1; n     else n       right = mid - 1; n   } n   return left + 1; n } n int main() { n   int n, m; n   cin >> n >> m; n   int songs[n]; n   int c, t, sum = 0; n   for (int i = 0; i < n; i++) { n     cin >> c >> t; n     sum += (c * t); n     songs[i] = sum; n   } n   int query; n   while (m--) { n     cin >> query; n     cout << bs(songs, n, query) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n const int N = 5e5; n int main() { n   long long n, a, b, c, t; n   cin >> n >> a >> b >> c >> t; n   long long arr[n + 1]; n   for (long long i = 1; i <= n; i++) { n     cin >> arr[i]; n   } n   long long s = n * a; n   if (b >= c) { n     cout << s << endl; n   } else { n     long long q = 1; n     long long s2 = 0; n     long long q2 = 1; n     long long s3 = 0; n     for (long long i = 1; i <= n; i++) { n       if (arr[i] != t) { n         s2 += (t - arr[i]) * c; n         q++; n       } n     } n     for (long long i = 1; i <= n; i++) { n       arr[i] = a - (t - arr[i]) * b; n     } n     for (long long i = 1; i <= n; i++) { n       s3 += arr[i]; n     } n     cout << s2 + s3; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e9; n int main() { n   int n, d, h; n   cin >> n >> d >> h; n   if (h * 2 < d || h > n || d > n || h > d || n < d + 1 || n       (h == 1 && d == 1 && (n != 2))) n     cout << -1; n   else { n     if (h == 1) { n       for (int i = 2; i <= n; i++) cout << 1 <<     << i << endl; n       return 0; n     } n     for (int i = 1; i <= h; i++) cout << i <<     << i + 1 << endl; n     for (int i = 1; i <= d - h; i++) n       cout << ((i == 1) ? 1 : i + h) <<     << i + h + 1 << endl; n     for (int i = 0; i < n - d - 1; i++) cout << 2 <<     << n - i << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC target( sse2 ) n using namespace std; n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   std::cerr << name <<   :   << arg1 <<   n ; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   std::cerr.write(names, comma - names) <<   :   << arg1 <<   |  ; n   __f(comma + 1, args...); n } n long long max(long long a, long long b) { return (a > b) ? a : b; } n long long min(long long a, long long b) { return (a < b) ? a : b; } n void amax(long long& a, long long b) { a = max(a, b) % 1000000007; } n void amin(long long& a, long long b) { a = min(a, b) % 1000000007; } n void inc(long long& a, long long b) { a = (a + b) % 1000000007; } n void dec(long long& a, long long b) { a = (a - b + 1000000007) % 1000000007; } n long long solve() { n   long long n, p; n   cin >> n >> p; n   vector<long long> in(n + 10, 1e9), out(n + 10, 0); n   for (long long i = 0; i < p; i++) { n     long long x; n     cin >> x; n     amin(in[x], i + 1); n     amax(out[x], i + 1); n   } n   long long ans = 0; n   for (long long i = 1; i < n + 1; i++) { n     if (out[i] == 0) { n       ans++; n     } n     long long cur = out[i]; n     if (in[i] > out[i + 1] && i + 1 <= n) ans++; n     if (in[i] > out[i - 1] && i > 1) ans++; n   } n   cout << ans; n   return 0; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, res; n   cin >> n; n   while (1) { n     if (n % 3 != 0) { n       res = (n / 3) + 1; n       break; n     } n     n = n / 3; n   } n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, arr[206]; n char str[206]; n inline bool check1() { n   for (int i = 0; i < (n >> 1); ++i) { n     if (arr[i] >= arr[i + (n >> 1)]) return 0; n   } n   return 1; n } n inline bool check2() { n   for (int i = 0; i < (n >> 1); ++i) { n     if (arr[i] <= arr[i + (n >> 1)]) return 0; n   } n   return 1; n } n int main() { n   scanf( %d , &n); n   scanf( %s , str); n   n = strlen(str); n   for (int i = 0; i < n; ++i) arr[i] = (int)(str[i] -  0 ); n   sort(arr, arr + (n / 2)); n   sort(arr + (n / 2), arr + n); n   puts((check1() || check2()) ?  YES  :  NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int n, k; n void inp() { n   cin >> n >> k; n   return; n } n void solve() { n   set<long long int> second; n   for (long long int i = 1; i <= k; i++) n     if (second.count(n % i)) n       return void(cout <<  No n ); n     else n       second.insert(n % i); n   cout <<  Yes n ; n   return; n } n int main() { n   clock_t beg = clock(); n   { n     cin.tie(0); n     ios_base::sync_with_stdio(false); n   }; n   inp(); n   solve(); n   clock_t end = clock(); n   fprintf(stderr,  %.3f sec n , (double)(end - beg) / CLOCKS_PER_SEC); n   return 0; n } n


#include <bits/stdc++.h> n const int MAXN = 5; n const double eps = 1e-4; n struct node { n   double x, y; n   node(double x = 0, double y = 0) : x(x), y(y) {} n   inline bool operator<(const node &rhs) const { n     if (fabs(x - rhs.x) >= eps) return x < rhs.x; n     if (fabs(y - rhs.y) >= eps) return y < rhs.y; n     return 0; n   } n   inline bool operator==(const node &rhs) const { n     return !(*this < rhs) && !(rhs < *this); n   } n } p[MAXN * MAXN << 1]; n struct circle { n   double a, b, r; n   circle(double a = 0, double b = 0, double r = 0) : a(a), b(b), r(r) {} n } c[MAXN]; n std::vector<node> ans; n inline void getcircle_intersection(circle x, circle y) { n   if (x.r < y.r) std::swap(x, y); n   if (fabs((x.r + y.r) * (x.r + y.r) - (x.a - y.a) * (x.a - y.a) - n            (x.b - y.b) * (x.b - y.b)) < eps) { n     const double dx = (y.a - x.a), dy = (y.b - x.b), k = x.r / (x.r + y.r); n     ans.push_back(node(x.a + dx * k, x.b + dy * k)); n     return; n   } n   if (fabs(y.r + sqrt((x.a - y.a) * (x.a - y.a) + (x.b - y.b) * (x.b - y.b)) - n            x.r) < eps) { n     const double dx = (y.a - x.a), dy = (y.b - x.b), k = x.r / (x.r - y.r); n     ans.push_back(node(x.a + dx * k, x.b + dy * k)); n     return; n   } n   if ((x.r + y.r) * (x.r + y.r) < n       (x.a - y.a) * (x.a - y.a) + (x.b - y.b) * (x.b - y.b)) n     return; n   if (y.r + sqrt((x.a - y.a) * (x.a - y.a) + (x.b - y.b) * (x.b - y.b)) < x.r) n     return; n   const double lk = (x.a - y.a) / (y.b - x.b), n                lb = (x.r * x.r - y.r * y.r + y.a * y.a - x.a * x.a + y.b * y.b - n                      x.b * x.b) / n                     (2 * y.b - 2 * x.b); n   const double fa = lk * lk + 1, fb = 2 * lk * lb - 2 * x.a - 2 * x.b * lk, n                fc = x.a * x.a + x.b * x.b + lb * lb - 2 * x.b * lb - x.r * x.r; n   double dt = fb * fb - 4 * fa * fc; n   if (fabs(dt) > eps && dt < 0) return; n   dt = fabs(dt); n   const double ax1 = (-fb + sqrt(dt)) / (2 * fa), n                ax2 = (-fb - sqrt(dt)) / (2 * fa); n   ans.push_back(node(ax1, lk * ax1 + lb)); n   ans.push_back(node(ax2, lk * ax2 + lb)); n } n inline bool point_on_circle(const node &x, const circle &y) { n   return fabs((x.x - y.a) * (x.x - y.a) + (x.y - y.b) * (x.y - y.b) - n               y.r * y.r) <= eps; n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     double a, b, r; n     scanf( %lf%lf%lf , &a, &b, &r); n     c[i].a = a * cos(233) + b * sin(233); n     c[i].b = -a * sin(233) + b * cos(233); n     c[i].r = r; n   } n   for (int i = 1; i <= n; i++) n     for (int j = i + 1; j <= n; j++) getcircle_intersection(c[i], c[j]); n   std::sort(ans.begin(), ans.end()); n   int sz = std::unique(ans.begin(), ans.end()) - ans.begin(); n   int tot = 0; n   for (int i = 1; i <= n; i++) { n     int ptot = 0; n     for (unsigned j = 0; j < sz; j++) ptot += point_on_circle(ans[j], c[i]); n     tot += ptot + !ptot; n   } n   if (sz == 0) tot--; n   printf( %d n , tot - sz + 2); n   return 0; n } n


#include <bits/stdc++.h> n const int maxn = 2e5 + 5; n using namespace std; n int a[maxn * 2]; n int main() { n   int n; n   cin >> n; n   int flag = 0; n   for (int t = 0; t < n; t++) { n     scanf( %d , &a[t]); n     if (a[t] == 1) { n       flag = 1; n     } n   } n   for (int t = n; t < 2 * n; t++) { n     a[t] = a[t - n]; n   } n   int s = 1; n   int maxnn = -1; n   for (int t = 1; t < 2 * n; t++) { n     if (a[t] == a[t - 1] && a[t] == 1) { n       s++; n     } else { n       s = 1; n     } n     if (s > maxnn) { n       maxnn = s; n     } n   } n   if (maxnn > n) { n     maxnn = n; n   } n   if (flag == 1) n     cout << maxnn << endl; n   else { n     cout <<  0  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> computer(100, 0); n int n, q, free_computers; n long s; n int t, k, d; n void question() { n   cin >> t >> k >> d; n   free_computers = 0; n   for (int j = 0; j < n && free_computers < k; j++) { n     if (computer[j] <= t) free_computers++; n   } n   if (k > free_computers) n     cout << -1 <<   n ; n   else { n     s = 0; n     for (int j = 0; j < n && k != 0; j++) { n       if (computer[j] <= t) { n         k--; n         computer[j] = d + t; n         s += j + 1; n       } n     } n     cout << s <<   n ; n   } n } n int main() { n   cin >> n >> q; n   for (int i = 0; i < q; i++) question(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int Int() { n   int x; n   cin >> x; n   return x; n } n double din() { n   double x; n   cin >> x; n   return x; n } n string Str() { n   string x; n   getline(cin, x); n   return x; n } n char Ch() { n   char x; n   cin >> x; n   return x; n } n int main() { n   int h1 = Int(); n   char ch = Ch(); n   int m1 = Int(); n   int h2 = Int(); n   ch = Ch(); n   int m2 = Int(); n   int x = (((h2 * 60) + m2) - ((h1 * 60) + m1)) / 2; n   int y = ((h1 * 60) + m1) + x; n   int z; n   h1 = y / 60; n   m1 = y % 60; n   cout << setfill( 0 ) << setw(2) << h1 <<  :  << setfill( 0 ) << setw(2) << m1 n        << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[200008], sign[200008]; n int b[200008]; n int main() { n   int n; n   scanf( %d , &n); n   int t; n   memset(a, 0, sizeof(a)); n   memset(sign, 0, sizeof(sign)); n   for (int i = 0; i < n; i++) { n     scanf( %d , &t); n     int k = t; n     int time = 0; n     b[i] = t; n     while (k) { n       a[k] += time; n       sign[k]++; n       if (k & 1 && k > 1) { n         int kk = k / 2 * 2, tim = time + 2; n         while (kk < 200008) { n           a[kk] += tim; n           sign[kk]++; n           kk <<= 1; n           tim++; n         } n       } n       k >>= 1; n       time++; n     } n     k = t, time = 0; n     while (k < 200008) { n       a[k] += time; n       sign[k]++; n       k <<= 1; n       time++; n     } n     sign[t]--; n   } n   int res = 0x3f3f3f3f; n   for (int i = 1; i < 200008; i++) { n     if (sign[i] == n) { n       res = min(res, a[i]); n     } n   } n   printf( %d n , res); n } n


#include <bits/stdc++.h> n using namespace std; n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   cerr << name <<   :   << arg1 <<   n ; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cout.write(names, comma - names) <<   :   << arg1 <<   |  ; n   __f(comma + 1, args...); n } n long long pows(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) { 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 modInverse(long long a, long long m = 1000000007) { n   if (m == 1) return 0; n   long long m0 = m, y = 0, x = 1; n   while (a > 1) { n     long long q = a / m, t = m; n     m = a % m, a = t; n     t = y; n     y = x - q * y; n     x = t; n   } n   if (x < 0) x += m0; n   return x; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, m, i, j, k, x, y, z, e, f, p, q, g, l, r, w, h, n       count1 = 0, prod = 1, a, b, c, d, index, x1, x2, diff, ans = 0, sum = 0, n       sum1 = 0, sum2 = 0, flag = 0, flag1 = 0, flag2 = 0; n   string s, s1, s2; n   cin >> n; n   if (n == 1) { n     cout <<  1 ; n     return 0; n   } else { n     ans = 1; n     k = 3; n     for (i = 2; i <= n; i++) { n       ans += k * 4; n       k += 3; n     } n     cout << ans; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n template <typename A, size_t N, typename T> n void Fill(A (&array)[N], const T &val) { n   std::fill((T *)array, (T *)(array + N), val); n } n class Graph { n  public: n   int vn; n   int sumcost = 0; n   vector<vector<pair<int, int>>> g; n   Graph(int n) { n     vn = n; n     g.resize(n); n   } n   virtual void con(int a, int b, int w) = 0; n   int getWeight(int f, int t) { n     auto itr = lower_bound((g[f]).begin(), (g[f]).end(), make_pair(t, INT_MIN)); n     if (itr != g[f].end()) return itr->second; n     return INT_MIN; n   } n   int Costsum() { return sumcost; } n   void scan(int edcount, bool oindexed, bool w) { n     for (int i = (0); (edcount) > i; i++) { n       int a, b, c = 1; n       scanf( %d %d , &a, &b); n       if (w) scanf( %d , &c); n       con(a - oindexed, b - oindexed, c); n     } n   } n }; n class BiDGraph : public Graph { n  public: n   BiDGraph(int n) : Graph(n) {} n   void con(int a, int b, int w = 1) { n     g[a].push_back({b, w}); n     g[b].push_back({a, w}); n     sumcost++; n   } n }; n class DGraph : public Graph { n  public: n   DGraph(int n) : Graph(n) {} n   void con(int a, int b, int w = 1) { n     g[a].push_back({b, w}); n     sumcost++; n   } n }; n signed main() { n   int n; n   scanf( %d , &n); n   printf( %d n , (n - 1) / 2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<int> arr; n   int n, a; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a; n     arr.push_back(a); n   } n   sort(arr.begin(), arr.end()); n   cout << arr[n - 1] << endl; n   arr.clear(); n   return 0; n } n


#include <bits/stdc++.h> n int len, p; n char s[111111], buf[111111]; n void add(char ch) { buf[len++] = ch; } n void out() { n   printf( < ); n   for (int i = 0; i < len; i++) printf( %c , buf[i]); n   printf( > n ); n   len = 0; n } n int main() { n   gets(s); n   len = p = 0; n   for (p = 0; s[p]; p++) { n     if (s[p] ==    ) { n       p++; n       while (s[p] !=    ) { n         add(s[p]); n         p++; n       } n       out(); n     } else if (s[p] ==    ) { n       if (len) out(); n     } else n       add(s[p]); n   } n   if (len) out(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s1, s2, s3, s4; n   long long int n; n   cin >> s1 >> s2; n   cin >> n; n   for (long long int i = 0; i < n; i++) { n     cout << s1 <<     << s2 << endl; n     cin >> s3 >> s4; n     if (s1.compare(s3) == 0) { n       s1 = s4; n     } else { n       s2 = s4; n     } n   } n   cout << s1 <<     << s2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100; n char s[maxn]; n int l; n long long make(int x, long long u) { n   int z = l - x; n   long long k = 1, u1 = 0; n   for (int i = 0; i < z; i++) { n     u1 += (s[l - 1 - i] -  0 ) * k; n     k *= 10; n   } n   u1 += u / k * k; n   if (u1 <= u) u1 += k; n   return u1; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     scanf( %s , s); n     l = strlen(s); n     long long u = 1988; n     for (int i = l - 1; i >= 4; i--) { n       u = make(i, u); n     } n     cout << u << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, q, g[13][13], lca[13][13]; n long long dp[1 << 13][13]; n long long f(int s, int root) { n   s &= ~(1 << root); n   if (s == 0) return 1; n   if (dp[s][root] != -1) return dp[s][root]; n   long long res = 0; n   int must = 0; n   for (int i = (0); i < (n); i++) n     if (s & 1 << i) { n       must = i; n       break; n     } n   for (int x = (0); x < (1 << n); x++) n     if (((x | s) == s) && (x & 1 << must)) { n       int ny = s ^ x; n       int y = ny | 1 << root; n       bool bad = false; n       for (int i = (0); i < (n); i++) n         for (int j = (0); j < (n); j++) n           if ((x & 1 << i) && (x & 1 << j)) { n             if (lca[i][j] != -1 && (y & 1 << lca[i][j])) { n               bad = true; n             } n           } n       for (int i = (0); i < (n); i++) n         for (int j = (0); j < (n); j++) n           if ((x & 1 << i) && (y & 1 << j)) { n             if (lca[i][j] != -1 && lca[i][j] != root) { n               bad = true; n             } n           } n       for (int i = (0); i < (n); i++) n         for (int j = (0); j < (n); j++) n           if ((x & 1 << i) && (ny & 1 << j)) { n             if (g[i][j]) bad = true; n           } n       int c = 0, x_root = -1; n       for (int i = (0); i < (n); i++) n         if (x & 1 << i) { n           if (g[root][i]) { n             c++; n             x_root = i; n           } n         } n       if (c >= 2) bad = true; n       if (bad) continue; n       for (int i = (0); i < (n); i++) n         if (x & 1 << i) { n           if (x_root != -1 && i != x_root) continue; n           res += f(x, i) * f(y, root); n         } n     } n   return dp[s][root] = res; n } n int main() { n   cin >> n >> m >> q; n   for (int i = (0); i < (m); i++) { n     int u, v; n     cin >> u >> v; n     u--; n     v--; n     g[u][v] = g[v][u] = 1; n   } n   memset(lca, -1, sizeof(lca)); n   for (int i = (0); i < (n); i++) lca[i][i] = i; n   for (int i = (0); i < (q); i++) { n     int a, b, c; n     cin >> a >> b >> c; n     a--; n     b--; n     c--; n     if (lca[a][b] != -1 && lca[a][b] != c) { n       cout << 0 << endl; n       return 0; n     } n     lca[a][b] = lca[b][a] = c; n   } n   memset(dp, -1, sizeof(dp)); n   cout << f((1 << n) - 1, 0) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long MOD = 1e9 + 7; n long long MAX = 1e17; n string s1, s2, v; n int dp[101][101][101], pre[101][101][101]; n void prt(int a, int b, int c) { n   if (a == 0 or b == 0) return; n   int x = pre[a][b][c]; n   if (x == 0) { n     prt(a - 1, b - 1, c); n   } else if (x == 1) { n     prt(a - 1, b - 1, c - 1); n     cout << s1[a - 1]; n   } else if (x == 2) { n     prt(a - 1, b, c); n   } else if (x == 3) { n     prt(a, b - 1, c); n   } else if (x < 0) { n     x = -x - 1; n     prt(a - 1, b - 1, x); n     cout << s1[a - 1]; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   ; n   cin >> s1 >> s2 >> v; n   int n, m, k; n   n = s1.size(); n   m = s2.size(); n   k = v.size(); n   int lps[k]; n   int p = 0, q2 = 1; n   lps[0] = 0; n   while (q2 < k) { n     if (v[p] == v[q2]) n       lps[q2++] = ++p; n     else if (p == 0) n       lps[q2++] = 0; n     else n       p = lps[p - 1]; n   } n   for (int i = 1; i < n + 1; i++) { n     for (int j = 1; j < m + 1; j++) { n       for (int l = 0; l < k; l++) { n         if (i < l or j < l) continue; n         if (l == 0) { n           if (s1[i - 1] == s2[j - 1]) { n             char q = s1[i - 1]; n             int x = dp[i - 1][j - 1][0], z = 0; n             for (int f = 0; f < k; f++) { n               int y = dp[i - 1][j - 1][f]; n               int p = f; n               while (p >= 0) { n                 if (q == v[p]) break; n                 if (p == 0) { n                   if (1 + y > x) z = -1 - f; n                   x = max(x, 1 + y); n                   break; n                 } n                 p = lps[p - 1]; n               } n             } n             dp[i][j][0] = x; n             pre[i][j][0] = z; n           } else { n             if (dp[i - 1][j][l] > dp[i][j - 1][l]) n               pre[i][j][l] = 2; n             else n               pre[i][j][l] = 3; n             dp[i][j][l] = max(dp[i - 1][j][l], dp[i][j - 1][l]); n           } n         } else { n           if (s1[i - 1] == s2[j - 1]) { n             char q = s1[i - 1]; n             int x = dp[i - 1][j - 1][l], z = 0; n             for (int f = l - 1; f < k; f++) { n               if (q != v[l - 1]) break; n               int y = dp[i - 1][j - 1][f]; n               int p = f; n               while (p >= l - 1) { n                 if (q == v[p] and p > l - 1) break; n                 if (p == l - 1) { n                   if (1 + y > x) z = -1 - f; n                   x = max(x, 1 + y); n                   break; n                 } n                 p = lps[p - 1]; n               } n             } n             dp[i][j][l] = x; n             pre[i][j][l] = z; n           } else { n             if (dp[i - 1][j][l] > dp[i][j - 1][l]) n               pre[i][j][l] = 2; n             else n               pre[i][j][l] = 3; n             dp[i][j][l] = max(dp[i - 1][j][l], dp[i][j - 1][l]); n           } n         } n       } n     } n   } n   int maxx = -1, crt = 0; n   for (int i = 0; i < k; i++) n     if (dp[n][m][i] > maxx) { n       crt = i; n       maxx = dp[n][m][i]; n     } n   if (dp[n][m][crt] == 0) n     cout << 0; n   else n     prt(n, m, crt); n   cout << endl; n } n


#include <bits/stdc++.h> n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx ) n using namespace std; n inline bool isDigit(char c) { return  0  <= c && c <=  9 ; } n template <class T> n inline T sqr(T x) { n   return x * x; n } n template <class T> n inline bool isSquare(T x) { n   int y = sqrt(x + 0.5); n   return (y * y) == x; n } n template <class T1, class T2> n inline T1 gcd(T1 a, T2 b) { n   return b ? gcd(b, a % b) : a; n } n template <class T1, class T2> n inline T1 eqMin(T1& x, const T2& y) { n   if (T1(y) < x) return x = y; n   return x; n } n template <class T1, class T2> n inline T1 eqMax(T1& x, const T2& y) { n   if (T1(y) > x) return x = y; n   return x; n } n template <class T1, class T2> n inline T1 min(const T1& x, const T2& y) { n   return x < (T1)y ? x : (T1)y; n } n template <class T1, class T2> n inline T1 max(T1& x, const T2& y) { n   return x > (T1)y ? x : (T1)y; n } n template <typename T> n inline T getint() { n   T x = 0, p = 1; n   char ch; n   do { n     ch = getchar(); n   } while (ch <=    ); n   if (ch ==  - ) p = -1, ch = getchar(); n   while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar(); n   return x * p; n } n template <class T1, class T2> n ostream& operator<<(ostream& os, const pair<T1, T2>& p) { n   return os <<  (  << p.first <<  ,   << p.second <<  ) ; n } n template <class T> n ostream& operator<<(ostream& os, const vector<T>& v) { n   os <<  { ; n   bool was = false; n   for (const T& x : v) { n     if (was) os <<  ,  ; n     was = true; n     os << x; n   } n   os <<  } ; n   return os; n } n template <class T> n ostream& operator<<(ostream& os, const set<T>& v) { n   os <<  [ ; n   bool was = false; n   for (const T& x : v) { n     if (was) os <<  ,  ; n     was = true; n     os << x; n   } n   os <<  ] ; n   return os; n } n template <class T> n ostream& operator<<(ostream& os, const multiset<T>& v) { n   os <<  [ ; n   bool was = false; n   for (const T& x : v) { n     if (was) os <<  ,  ; n     was = true; n     os << x; n   } n   os <<  ] ; n   return os; n } n template <class T1, class T2> n ostream& operator<<(ostream& os, const map<T1, T2>& m) { n   os <<  < ; n   bool was = false; n   for (const auto& x : m) { n     if (was) os <<  ,  ; n     was = true; n     os << x; n   } n   os <<  > ; n   return os; n } n template <size_t sz> n ostream& operator<<(ostream& os, const bitset<sz>& bit) { n   os <<  / ; n   for (int i = 0; i < sz; i++) os << bit[i]; n   os <<     ; n   return os; n } n const double PI = acos(-1); n const double EPS = 1e-8; n const int INF = (int)2e9; n const long long LINF = (long long)2e18; n const int MOD = (int)1e9 + 7; n const int MAXN = (int)1e5 + 10; n int n, s, x; n int val[MAXN], nxt[MAXN]; n int p[MAXN]; n bool us[MAXN]; n int cnt = 0; n void read(int x) { n   if (us[x]) return; n   us[x] = true; n   cout <<  ?   << x <<   n ; n   cout.flush(); n   cin >> val[x] >> nxt[x]; n   cout.flush(); n } n int main() { n   ios_base::sync_with_stdio(false); n   srand(time(NULL)); n   cin >> n >> s >> x; n   cout.flush(); n   for (int i = 1; i <= n; i++) { n     p[i] = i; n   } n   random_shuffle(p + 1, p + n + 1); n   read(s); n   int ss = s; n   s = 0; n   val[0] = -1; n   for (int i = 1; i <= min(n / 2, 1300); i++) { n     read(p[i]); n     if (val[p[i]] < x && val[p[i]] > val[s]) { n       s = p[i]; n     } n   } n   if (val[ss] < x && val[ss] > val[s]) { n     s = ss; n   } n   if (s) { n     while (val[s] < x) { n       s = nxt[s]; n       if (s == -1) { n         cout <<  ! -1  n              <<   n ; n         cout.flush(); n         return 0; n       } n       read(s); n       if (val[s] >= x) { n         cout <<  !   << val[s] <<   n ; n         cout.flush(); n         return 0; n       } n       if (nxt[s] == -1) { n         cout <<  ! -1  n              <<   n ; n         cout.flush(); n         return 0; n       } n     } n   } n   cout <<  !   << val[ss] <<   n ; n   cout.flush(); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 510, mod = 1LL * 1000 * 1000 * 1000 + 7; n int dp[N][N], n, b[N], num[N][N]; n int main() { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   cin >> n; n   for (int i = 0; i < n; i++) cin >> b[i]; n   for (int j = 1; j <= n; j++) n     for (int i = j - 1; i >= 0; i--) { n       if (j - i <= 2) { n         dp[i][j] = num[i][j] = 1; n         continue; n       } n       for (int k = i + 1; k + 1 < j; k++) n         if (b[k] < b[j - 1]) n           (num[i][j] += 1LL * num[i][k + 1] * dp[k][j - 1] % mod) %= mod; n       for (int k = i + 1; k < j; k++) n         (dp[i][j] += 1LL * num[i][k + 1] * dp[k][j] % mod) %= mod; n     } n   cout << dp[0][n] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int mini; n map<char, int> M; n set<int> s; n int n; n void rec(int ind, vector<int> c, vector<int> d) { n   if (ind == 10) { n     int rem = n; n     int X = c.size() + d.size(); n     int i, j; n     set<int> S = s; n     set<int>::iterator it; n     for (i = 0; i < c.size(); i++) { n       for (j = 0; j < d.size(); j++) { n         if (S.find(5 * c[i] + d[j]) != S.end()) { n           S.erase(5 * c[i] + d[j]); n         } n       } n     } n     for (i = 0; i < c.size(); i++) { n       int count = 0, flag; n       for (j = 0; j < 5; j++) { n         if (S.find(5 * c[i] + j) != S.end()) { n           count++; n           flag = j; n         } n       } n       if (count == 1) { n         S.erase(5 * c[i] + flag); n       } n     } n     for (i = 0; i < d.size(); i++) { n       int count = 0, flag; n       for (j = 0; j < 5; j++) { n         if (S.find(5 * j + d[i]) != S.end()) { n           count++; n           flag = j; n         } n       } n       if (count == 1) { n         S.erase(5 * flag + d[i]); n       } n     } n     if (S.size() == 1 || S.size() == 0) { n       mini = min(mini, X); n     } n     return; n   } n   if (ind < 5) { n     rec(ind + 1, c, d); n     c.push_back(ind); n     rec(ind + 1, c, d); n   } else { n     rec(ind + 1, c, d); n     d.push_back(ind - 5); n     rec(ind + 1, c, d); n   } n } n int main() { n   mini = 10; n   M[ R ] = 0; n   M[ G ] = 1; n   M[ B ] = 2; n   M[ Y ] = 3; n   M[ W ] = 4; n   cin >> n; n   int i; n   string st; n   for (i = 0; i < n; i++) { n     cin >> st; n     s.insert(5 * M[st[0]] + st[1] -  1 ); n   } n   vector<int> c; n   vector<int> d; n   rec(0, c, d); n   cout << mini << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 110000; n const int M = 1100000; n const long long mod = 1e9 + 7; n int n, m; n vector<pair<int, int> > g[N]; n int edge[N]; n int col[N], dep[N]; n int val[N], f[N]; n void dfs(int x, int fa) { n   f[x] = fa; n   dep[x] = dep[fa] + 1; n   for (auto p : g[x]) { n     int y = p.first, id = p.second; n     if (y == fa) continue; n     edge[y] = id; n     dfs(y, x); n   } n } n struct query { n   int x, y, w; n   friend bool operator<(query a, query b) { return a.w < b.w; } n } a[N], b[N]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i < n; i++) { n     int x, y; n     scanf( %d %d , &x, &y); n     g[x].push_back(make_pair(y, i)), g[y].push_back(make_pair(x, i)); n   } n   dfs(1, 0); n   scanf( %d , &m); n   for (int i = 1; i <= n; i++) val[i] = 1e6; n   for (int i = 1; i <= m; i++) { n     scanf( %d %d %d , &a[i].x, &a[i].y, &a[i].w); n     b[i] = a[i]; n   } n   sort(a + 1, a + 1 + m); n   for (int i = 1; i <= m; i++) { n     int nx = a[i].x, ny = a[i].y; n     while (dep[nx] != dep[ny]) { n       if (dep[nx] > dep[ny]) n         val[edge[nx]] = a[i].w, nx = f[nx]; n       else n         val[edge[ny]] = a[i].w, ny = f[ny]; n     } n     while (nx != ny) { n       val[edge[nx]] = a[i].w, nx = f[nx]; n       val[edge[ny]] = a[i].w, ny = f[ny]; n     } n   } n   int flag = 0; n   for (int i = 1; i <= m; i++) { n     int nx = b[i].x, ny = b[i].y; n     int mn = 1e9; n     while (dep[nx] != dep[ny]) { n       if (dep[nx] > dep[ny]) n         mn = min(mn, val[edge[nx]]), nx = f[nx]; n       else n         mn = min(mn, val[edge[ny]]), ny = f[ny]; n     } n     while (nx != ny) { n       mn = min(mn, val[edge[nx]]), nx = f[nx]; n       mn = min(mn, val[edge[ny]]), ny = f[ny]; n     } n     if (mn != b[i].w) flag = 1; n   } n   if (flag) n     printf( -1 n ); n   else { n     for (int i = 1; i < n; i++) printf( %d  , val[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, t; n   cin >> t; n   while (t--) { n     cin >> n; n     if (n % 7) n       cout << (n / 7) + 1 <<   n ; n     else n       cout << n / 7 <<   n ; n   } n   return 0; n } n


#include<iostream> n #include<algorithm> n using namespace std; n long long cmp(long long a,long long b) n { n  return a > b; n } n int main() n { n  int t,n,i; n  long long array[200000],alice,bob; n  cin>>t; n  while(t--) n  { n   alice=0; n   bob=0; n   cin>>n; n   for(i=0;i<n;i++) n   { n    scanf( %lld ,&array[i]); n   } n   sort(array,array+n,cmp); n   for(i=0;i<n;i++) n   { n    if(i%2==0) n    { n     if(array[i]%2==0)alice+=array[i]; n    } n    else n    { n     if(array[i]%2!=0)bob+=array[i]; n    } n   } n   if(alice>bob)cout<< Alice <<endl; n   else if(alice<bob)cout<< Bob <<endl; n   else cout<< Tie <<endl; n  } n } n


#include <bits/stdc++.h> n using namespace std; n static inline void canhazfast() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n } n template <typename T> n T gcd(T a, T b) { n   return b == 0 ? a : gcd(b, a % b); n } n template <typename T> n T extgcd(T a, T b, T &x, T &y) { n   T x0 = 1, y0 = 0, x1 = 0, y1 = 1; n   while (b) { n     T q = a / b; n     a %= b; n     swap(a, b); n     x0 -= q * x1; n     swap(x0, x1); n     y0 -= q * y1; n     swap(y0, y1); n   } n   x = x0; n   y = y0; n   return a; n } n static inline int ctz(unsigned x) { return __builtin_ctz(x); } n static inline int ctzll(unsigned long long x) { return __builtin_ctzll(x); } n static inline int clz(unsigned x) { return __builtin_clz(x); } n static inline int clzll(unsigned long long x) { return __builtin_clzll(x); } n static inline int popcnt(unsigned x) { return __builtin_popcount(x); } n static inline int popcntll(unsigned long long x) { n   return __builtin_popcountll(x); n } n static inline int bsr(unsigned x) { return 31 ^ clz(x); } n static inline int bsrll(unsigned long long x) { return 63 ^ clzll(x); } n struct Node { n   long long mx, lz; n }; n Node t[1 << 19]; n int a[1 << 18]; n long long build(int u, int b, int e, long long s = 0) { n   if (b + 1 == e) { n     t[u].mx = a[b] - s; n     return s + a[b]; n   } n   int m = (b + e) / 2, lc = 2 * u, rc = 2 * u + 1; n   s = build(lc, b, m, s); n   s = build(rc, m, e, s); n   t[u].mx = max(t[lc].mx, t[rc].mx); n   return s; n } n void push(int u, int sz) { n   if (!t[u].lz) return; n   t[u].mx += t[u].lz; n   if (sz > 1) { n     t[2 * u].lz += t[u].lz; n     t[2 * u + 1].lz += t[u].lz; n   } n   t[u].lz = 0; n } n void upd(int u, int b, int e, int pos, int d) { n   int sz = e - b; n   if (pos >= e) return push(u, e - b); n   if (pos < b) return t[u].lz -= d, push(u, sz); n   if (sz == 1) return t[u].lz += d, push(u, sz); n   push(u, sz); n   int m = (b + e) / 2, lc = 2 * u, rc = 2 * u + 1; n   upd(lc, b, m, pos, d); n   upd(rc, m, e, pos, d); n   t[u].mx = max(t[lc].mx, t[rc].mx); n } n int get(int u, int b, int e) { n   push(u, e - b); n   if (t[u].mx < 0) return -2; n   if (b + 1 == e) return t[u].mx == 0 ? b : -2; n   int m = (b + e) / 2, lc = 2 * u, rc = 2 * u + 1; n   int res = get(lc, b, m); n   if (res < 0) res = get(rc, m, e); n   return res; n } n int main() { n   canhazfast(); n   int n, q; n   cin >> n >> q; n   for (int i = 0; i < n; ++i) cin >> a[i]; n   build(1, 0, n); n   for (; q; --q) { n     int p, x; n     cin >> p >> x; n     --p; n     upd(1, 0, n, p, x - a[p]); n     a[p] = x; n     cout << get(1, 0, n) + 1 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   string t; n   cin >> t; n   int n = t.size(); n   int start = (n % 2) ? n / 2 : n / 2 - 1; n   int j = 1; n   int k = n / 2; n   putchar(t[start]); n   while (k--) { n     if (start + j <= n - 1) { n       putchar(t[start + j]); n     } n     if (start - j >= 0) { n       putchar(t[start - j]); n     } n     ++j; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long n, c[long(1e7 + 50)], cnt; n void sieve() { n   c[1] = 1; n   for (long i = 2; i <= long(1e7); ++i) n     if (!c[i]) n       for (long j = 2; i * j <= long(1e7); ++j) c[i * j] = 1; n } n bool Prime(long x) { n   if (x < long(1e7)) { n     if (c[x]) return false; n     return true; n   } n   for (long i = 2; i <= trunc(sqrt(x)); ++i) n     if (!(x % i)) return false; n   return true; n } n int main() { n   scanf( %ld , &n); n   if (n <= 7) n     printf( 1 n%ld , n); n   else { n     printf( 3 n ); n     sieve(); n     n -= 3; n     for (long i = n; i >= 1; --i) n       if (Prime(i) && Prime(n - i)) { n         printf( %ld %ld %ld , i, n - i, 3); n         return 0; n       } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int const maxn = 1e5 + 5; n int n, m, k, p[105], second[105], mx[105]; n int ans; n int main() { n   scanf( %d%d%d , &n, &m, &k); n   for (int i = 1; i <= n; ++i) scanf( %d , &p[i]); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &second[i]); n     if (mx[second[i]] < p[i]) mx[second[i]] = p[i]; n   } n   for (int i = 1; i <= k; ++i) { n     int v; n     scanf( %d , &v); n     if (mx[second[v]] > p[v]) ans++; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e18; n const long double PI = 4 * atan((long double)1); n const long long mod = 1e9 + 7; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long tt = 1; n   while ((tt)--) { n     long long n, m; n     cin >> n >> m; n     if (min(n, m) & 1) { n       cout <<  Akshat  <<   n ; n     } else { n       cout <<  Malvika  <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a[205], max1, n, k, t; n int main() { n   cin >> t; n   while (t > 0) { n     t--; n     scanf( %d%d , &n, &k); n     for (int i = 0; i < k; i++) scanf( %d , &a[i]); n     max1 = 0; n     if (k == 1) n       cout << max(n - a[0] + 1, a[0]) << endl; n     else { n       for (int i = 1; i < k; i++) { n         if ((a[i] - a[i - 1]) / 2 + 1 > max1) max1 = (a[i] - a[i - 1]) / 2 + 1; n       } n       int d = max(n - a[k - 1] + 1, a[0]); n       if (d > max1) n         cout << d << endl; n       else { n         cout << max1 << endl; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[500010], b[500010], l[500010], lb[39], at[39]; n vector<int> v[500010]; n int main() { n   int n, q, p = 0, i, r, x, y; n   cin >> n; n   for (i = 1; i <= n; i++) scanf( %d , &a[i]); n   cin >> q; n   for (i = 1; i <= q; i++) { n     scanf( %d%d , &l[i], &x); n     v[x].push_back(i); n   } n   for (r = 1; r <= n; r++) { n     x = a[r]; n     p = r; n     for (i = 20; ~i; i--) n       if ((1 << i) & x) { n         if (!lb[i]) { n           lb[i] = x; n           at[i] = p; n           break; n         } n         if (at[i] < p) swap(lb[i], x), swap(at[i], p); n         x ^= lb[i]; n       } n     for (auto x : v[r]) n       for (i = 20; ~i; --i) n         if (at[i] >= l[x]) b[x] = max(b[x], b[x] ^ lb[i]); n   } n   for (i = 1; i <= q; i++) printf( %d n , b[i]); n } n


#include <bits/stdc++.h> n using namespace std; n long long modpow(long long b, long long e, long long m) { n   b %= m; n   if (e == 0) return 1; n   if (e % 2 == 1) return (b * modpow(b, e - 1, m)) % m; n   return modpow((b * b) % m, e / 2, m); n } n long long powten[1005]; n vector<long long> mods; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   int n, k, m; n   cin >> n >> k >> m; n   for (int i = 0; i < 1005; i++) { n     if (i == 0) n       powten[i] = 1; n     else n       powten[i] = (10 * powten[i - 1]) % k; n   } n   mods.resize(k, 0); n   for (int i = 0; i < 10; i++) { n     if (i % k != 0 or i == 0) mods[i % k] = (mods[i % k] + 1) % m; n   } n   for (int i = 1; i < n; i++) { n     vector<long long> temp; n     temp.resize(k, 0); n     for (int j = 0; j < 10; j++) { n       if (i == n - 1 and j == 0) continue; n       long long del = (j * powten[i]) % k; n       for (int prev = 0; prev < k; prev++) n         temp[(prev + del) % k] = (temp[(prev + del) % k] + mods[prev]) % m; n     } n     temp[0] = ((i == n - 1) ? 0 : 1); n     mods = temp; n   } n   if (n == 1) mods[0] = 0; n   long long total = (9 * modpow(10, n - 1, m)) % m; n   for (int i = 0; i < k; i++) total = (total - mods[i] + m) % m; n   cout << total <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool sortin(const pair<long long int, long long int> &e, n             const pair<long long int, long long int> &f) { n   return (e.first < f.first); n } n bool POT(long long int x) { return x && (!(x & (x - 1))); } n long long int a, b, c, i, j, k, l, m, n, p, q, r, x, y, z, ts, mn = 10e17, n                                                                mod = 10e8 + 7; n long long int ar[1000002], br[1000002], xr[1000002]; n int main() { n   { n     ios_base::sync_with_stdio(false); n     cin.tie(0); n     cout.tie(0); n   }; n   string s; n   cin >> s >> a >> b; n   n = s.size(); n   p = 1; n   for (long long int i = n - 1; i >= 0; i--) { n     xr[i] = ((s[i] -  0 ) * p + xr[i + 1]) % b; n     p = (p * 10) % b; n   } n   xr[n] = 1; n   p = 0; n   for (long long int i = 0; i <= n - 2; i++) { n     p = (p * 10 + s[i] -  0 ) % a; n     if (p == 0 and xr[i + 1] == 0 and s[i + 1] !=  0 ) { n       cout <<  YES ; n       cout << endl; n       cout << s.substr(0, i + 1); n       cout << endl; n       cout << s.substr(i + 1, n - i - 1); n       return 0; n     } n   } n   cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma GCC target( avx2 ) n #pragma GCC optimization( O3 ) n #pragma GCC optimization( unrolled-loops ) n int n, m, b, w, color[200010], ok[200010]; n vector<int> a[200010]; n void dfs(int u, int c) { n   color[u] = c; n   ok[u] = 1; n   b += (c == 0); n   w += (c == 1); n   for (int i = 0; i < a[u].size(); i++) n     if (!ok[a[u][i]]) dfs(a[u][i], 1 - c); n } n void solve() { n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     a[i].clear(); n     color[i] = 0; n     ok[i] = 0; n   } n   int u, v; n   for (int i = 0; i < m; i++) { n     cin >> u >> v; n     a[u].push_back(v); n     a[v].push_back(u); n   } n   b = 0; n   w = 0; n   dfs(1, 0); n   cout << min(b, w) <<   n ; n   if (b < w) n     for (int i = 1; i <= n; i++) { n       if (!color[i]) cout << i <<    ; n     } n   else n     for (int i = 1; i <= n; i++) { n       if (color[i]) cout << i <<    ; n     } n   cout <<   n ; n } n int main() { n   int t; n   cin >> t; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n inline int Get() { n   int res = 0, q = 1; n   char ch = getchar(); n   while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar(); n   if (ch ==  - ) q = -1, ch = getchar(); n   while (ch >=  0  && ch <=  9 ) res = res * 10 + ch -  0 , ch = getchar(); n   return res * q; n } n const double eps = 1e-12, pi = M_PI; n const int oo = (int)2e9, mod = (int)1e9 + 7; n const long long INF = (long long)1e17; n int T; n long long a, n, p, h; n long long Calc(long long a, long long n, long long p) { n   long long rd = a * n / p; n   if (!rd) return ((a) > (p - a * n) ? (a) : (p - a * n)); n   long long dt = a * n % p, st = p - p % a - a; n   if (dt < st) --rd; n   return Calc(min(a - p % a, p % a), rd, a); n } n int main() { n   for (scanf( %d  n                n , n              &T); n        T--;) { n     scanf( n          %I64d  n          %I64d  n          %I64d  n          %I64d  n           n , n         &a, &n, &p, &h), n         a %= p; n     if (a * n < p) n       printf( %s n , a <= h ?  YES  :  NO ); n     else n       printf( %s n , Calc(a, n, p) <= h ?  YES  :  NO ); n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int mex(set<int> s) { n   int v = 0; n   while (s.count(v) > 0) v++; n   return v; n } n int g[65]{0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4,  4,  5,  5,  5,  5, 5, 5, n           6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,  7,  8,  8,  8,  8, 8, 8, n           8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10}; n const int MAXN = 1000007; n int s[MAXN]; n map<pair<int, long long>, int> dp; n int grundy(pair<int, long long> s) { n   if (dp.find(s) != dp.end()) return dp[s]; n   long long mask = s.second; n   int &res = dp[s]; n   set<int> S; n   for (int i = 1; i <= 60; i++) { n     if (!(mask & (1ll << i)) && s.first >= i) { n       S.insert(grundy(make_pair(s.first - i, (mask | (1ll << i))))); n     } n   } n   while (S.count(res) > 0) res++; n   return res; n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &s[i]); n   } n   if (n == 1) n     printf( NO n ); n   else { n     int XOR = 0; n     for (int i = 0; i < n; i++) { n       XOR ^= grundy(make_pair(s[i], 0)); n     } n     if (XOR == 0) n       printf( YES n ); n     else n       printf( NO n ); n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int a[1000000]; n int ans[1000000]; n int cnt; n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     ans[a[i]]++; n   } n   for (int j = 1; j <= n; j++) n     if (ans[j] == 0) cnt++; n   cout << cnt << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct habijabi { n   long int start_time, end_time; n } work[500500]; n bool cmp(habijabi a, habijabi b) { n   if (a.end_time == b.end_time) { n     return a.start_time < b.start_time; n   } n   return a.end_time < b.end_time; n } n int main() { n   long int t, n, i, j; n   scanf( %ld , &n); n   for (i = 0; i < n; i++) { n     scanf( %ld %ld , &work[i].start_time, &work[i].end_time); n   } n   sort(work, work + n, cmp); n   int ans = 0, prev_end = -1; n   for (i = 0; i < n; i++) { n     if (work[i].start_time > prev_end) { n       ans++; n       prev_end = work[i].end_time; n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n const int INF = 0x3f3f3f3f; n using namespace std; n int v[5005]; n int main() { n   int t1; n   cin >> t1; n   for (int t = 1; t <= t1; t++) { n     int n, d; n     cin >> n >> d; n     memset(v, 0, sizeof(v)); n     int l = 1, nr = n - 1; n     v[0] = 1; n     for (; nr >= v[l - 1] * 2; l++) { n       v[l] = v[l - 1] * 2; n       d -= v[l] * l; n       nr -= v[l]; n     } n     if (nr == 0) n       l--; n     else n       d -= nr * l, v[l] = nr; n     if (d < 0) { n       cout <<  NO n ; n       continue; n     } n     int l2; n     for (l2 = l; d > 0 && l >= 1; l--) { n       if (v[l] == 1) continue; n       if (l2 + 1 - l > d) { n         v[l]--; n         v[l + d]++; n         d = 0; n         break; n       } n       v[++l2] = 1; n       d -= l2 - l; n       v[l]--; n       l++; n     } n     if (d == 0) { n       cout <<  YES n ; n       queue<int> p[5005]; n       p[0].push(1); n       p[0].push(1); n       for (int i = 1, node = 2; i <= l2; i++) n         if (v[i] > 0) { n           cout << p[i - 1].front() <<    ; n           p[i - 1].pop(); n           p[i].push(node); n           p[i].push(node); n           v[i--]--; n           node++; n         } n       cout <<   n ; n     } else { n       cout <<  NO n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long a, i, j, n, mx, p, b[1001], m; n   cin >> n >> m; n   for (i = 1; i <= 1000; i++) b[i] = 0; n   for (i = 1; i <= m; i++) { n     mx = -1; n     p = -1; n     for (j = 1; j <= n; j++) { n       cin >> a; n       if (a > mx) { n         mx = a; n         p = j; n       } n     } n     b[p]++; n   } n   int bmax = b[1], pmax = 1; n   for (i = 2; i <= 1000; i++) n     if (b[i] > bmax) { n       bmax = b[i]; n       pmax = i; n     } n   cout << pmax; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e6 + 5; n bool solve(int, int); n bool trySolve(int, int); n bool trySolve(int w, int m) { return (m % w == 0 && solve(w, m / w)); } n bool solve(int w, int m) { n   return (w <= 3 || m == 1 || trySolve(w, m - 1) || trySolve(w, m) || n           trySolve(w, m + 1)); n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int w, m; n   cin >> w >> m; n   if (w == 2 || w == 3) n     cout <<  YES ; n   else { n     if (solve(w, m)) n       cout <<  YES ; n     else n       cout <<  NO ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, v[1010]; n long double p[1010][1010], a[1010], d[1010]; n int work() { n   int k; n   long double x = 1e100L; n   for (int i = 1; i <= n; i++) n     if (!v[i] && (d[i] + a[i]) / (1 - a[i]) <= x) n       x = (d[i] + a[i]) / (1 - a[i]), k = i; n   v[k] = 1, d[k] = (d[k] + a[k]) / (1 - a[k]); n   if (k == 1) return 1; n   for (int i = 1; i <= n; i++) n     if (!v[i]) d[i] += a[i] * p[i][k] * (d[k] + 1), a[i] *= 1 - p[i][k]; n   return 0; n } n int main() { n   cin >> n; n   for (int i = 1, x; i <= n; i++) { n     for (int j = 1; j <= n; j++) cin >> x, p[i][j] = 0.01L * x; n     a[i] = 1; n   } n   a[n] = 0; n   for (int i = 1; i <= n; i++) n     if (work()) { n       cout << fixed << setprecision(15) << d[1]; n       return 0; n     } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int c, d, x, y, a, b; n   cin >> a >> b >> x >> y >> c >> d; n   if (c == 0 and d == 0) { n     if ((a == x and b == y) or (a == -x and b == -y) or (a == y and b == -x) or n         (a == -y and b == x)) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n     return 0; n   } n   bool possible = false; n   long long int X = x, Y = y; n   if ((c * (x - a) + d * (y - b)) % (c * c + d * d) == 0 and n       (d * (x - a) - c * (y - b)) % (c * c + d * d) == 0) n     possible = true; n   x = -Y, y = X; n   if ((c * (x - a) + d * (y - b)) % (c * c + d * d) == 0 and n       (d * (x - a) - c * (y - b)) % (c * c + d * d) == 0) n     possible = true; n   x = -X, y = -Y; n   if ((c * (x - a) + d * (y - b)) % (c * c + d * d) == 0 and n       (d * (x - a) - c * (y - b)) % (c * c + d * d) == 0) n     possible = true; n   x = Y, y = -X; n   if ((c * (x - a) + d * (y - b)) % (c * c + d * d) == 0 and n       (d * (x - a) - c * (y - b)) % (c * c + d * d) == 0) n     possible = true; n   if (possible) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n int chkmax(T& a, T b) { n   if (b > a) { n     a = b; n     return 1; n   } n   return 0; n } n template <class T> n int chkmin(T& a, T b) { n   if (b < a) { n     a = b; n     return 1; n   } n   return 0; n } n template <class iterator> n void output(iterator begin, iterator end, ostream& out = cerr) { n   while (begin != end) { n     out << (*begin) <<    ; n     begin++; n   } n   out << endl; n } n template <class T> n void output(T x, ostream& out = cerr) { n   output(x.begin(), x.end(), out); n } n void fast_io() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n const int INF = 1e9; n const int N = 26; n const int A = 5e4 + 10; n vector<int> value; n int p[N][A * N]; n signed main() { n   fast_io(); n   int n; n   cin >> n; n   for (int i = 0; i < 2 * n; ++i) { n     int x; n     cin >> x; n     value.push_back(x); n   } n   sort(value.begin(), value.end()); n   int sum = 0; n   for (int i = 2; i < 2 * n; ++i) { n     sum += value[i]; n   } n   for (int i = 0; i < N; ++i) { n     for (int j = 0; j < A * N; ++j) { n       p[i][j] = -1; n     } n   } n   p[0][0] = -2; n   for (int i = 2; i < value.size(); ++i) { n     int cur = value[i]; n     for (int j = n - 1; j > 0; --j) { n       for (int x = cur; x < A * N; ++x) { n         if (p[j - 1][x - cur] != -1 && p[j][x] == -1) { n           p[j][x] = i; n         } n       } n     } n   } n   int best = INF; n   for (int i = 0; i < N * A; ++i) { n     if (abs(i - (sum - i)) < abs(best - (sum - best)) && p[n - 1][i] != -1) { n       best = i; n     } n   } n   vector<int> type(2 * n); n   type[1] = 1; n   for (int i = n - 1; i > 0; --i) { n     type[p[i][best]] = 1; n     best -= value[p[i][best]]; n   } n   vector<vector<int> > ans(2); n   for (int i = 0; i < 2 * n; ++i) { n     ans[type[i]].push_back(value[i]); n   } n   sort(ans[0].begin(), ans[0].end()); n   sort(ans[1].rbegin(), ans[1].rend()); n   for (auto v : ans) { n     for (auto x : v) { n       cout << x <<    ; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   vector<int> a(n); n   for (int i = 0; i < n; i++) cin >> a[i]; n   int sum = accumulate(a.begin(), a.end(), 0); n   vector<vector<int>> dp(n + 1, vector<int>(2, -1)); n   function<int(int, int)> solve = [&](int idx, int cur) { n     if (idx == n) return 0; n     if (dp[idx][cur] != -1) return dp[idx][cur]; n     int res = 0; n     if (cur == 0) n       res = max(a[idx] + solve(idx + 1, !cur), solve(idx + 1, cur)); n     else n       res = min(solve(idx + 1, !cur), a[idx] + solve(idx + 1, cur)); n     return dp[idx][cur] = res; n   }; n   int ans = solve(0, 0); n   cout << sum - ans <<     << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int nmax = 3e5 + 42; n int n, m; n struct edge { n   int u, v, c; n }; n edge inp[nmax]; n edge make_edge(int u, int v, int c) { n   edge x; n   x.u = u; n   x.v = v; n   x.c = c; n   return x; n } n bool cmp(edge a, edge b) { return a.c < b.c; } n int ans[nmax], new_values[nmax]; n int main() { n   cin >> n >> m; n   int a, b, c; n   for (int i = 1; i <= m; i++) { n     scanf( %i%i%i , &a, &b, &c); n     inp[i] = make_edge(a, b, c); n   } n   sort(inp + 1, inp + m + 1, cmp); n   for (int i = 1; i <= m; i++) { n     int j = i + 1; n     while (j <= m && inp[i].c == inp[j].c) j++; n     for (int k = i; k < j; k++) { n       new_values[inp[k].v] = max(new_values[inp[k].v], ans[inp[k].u] + 1); n     } n     for (int k = i; k < j; k++) { n       ans[inp[k].v] = new_values[inp[k].v]; n     } n     i = j - 1; n   } n   int outp = 0; n   for (int i = 1; i <= n; i++) outp = max(outp, ans[i]); n   cout << outp << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1 << 28; n int x[24 + 2], y[24 + 2]; n int dist[24 + 2][24 + 2]; n int dp[(1 << 24) + 2]; n int nxt[(1 << 24) + 2]; n int n; n int sqr_dis(int a, int b) { n   return (x[a] - x[b]) * (x[a] - x[b]) + (y[a] - y[b]) * (y[a] - y[b]); n } n int solve(int mask) { n   if (!mask) return 0; n   int &ret = dp[mask]; n   if (ret != -1) return ret; n   int i, j, k; n   ret = inf; n   for (i = 0; i < n; i++) n     if (mask & (1 << i)) { n       for (j = 0; j < n; j++) n         if (mask & (1 << j)) { n           k = dist[0][i + 1] + dist[i + 1][j + 1] + dist[j + 1][0] + n               solve((mask & ~(1 << i)) & ~(1 << j)); n           if (k < ret) { n             ret = k; n             nxt[mask] = (1 << i) | (1 << j); n           } n         } n       break; n     } n   return ret; n } n int main() { n   int i, j, k; n   scanf( %d %d %d , &x[0], &y[0], &n); n   for (i = 1; i <= n; i++) scanf( %d %d , &x[i], &y[i]); n   for (i = 0; i <= n; i++) n     for (j = 0; j <= n; j++) dist[i][j] = dist[j][i] = sqr_dis(i, j); n   k = 1 << n; n   for (i = 0; i < k; i++) dp[i] = -1; n   printf( %d n , solve(k - 1)); n   printf( 0 ); n   k--; n   while (k) { n     for (i = 0; i < n; i++) n       if (nxt[k] & (1 << i)) printf(  %d , i + 1); n     printf(  0 ); n     k ^= nxt[k]; n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, arr[1000], dp[1000][10]; n int solve(int i, int flag) { n   if (i >= n) return 0; n   if (dp[i][flag] != -1) return dp[i][flag]; n   if (arr[i] == 0) n     dp[i][flag] = 1 + solve(i + 1, 0); n   else if (arr[i] == 1) { n     if (flag == 0 || flag == 1) { n       dp[i][flag] = min(solve(i + 1, 2), 1 + solve(i + 1, 0)); n     } else n       dp[i][flag] = 1 + solve(i + 1, 0); n   } else if (arr[i] == 2) { n     if (flag == 0 || flag == 2) { n       dp[i][flag] = min(1 + solve(i + 1, 0), solve(i + 1, 1)); n     } else n       dp[i][flag] = 1 + solve(i + 1, 0); n   } else { n     if (flag == 0) { n       dp[i][flag] = n           min(solve(i + 1, 2), min(1 + solve(i + 1, 0), solve(i + 1, 1))); n     } else if (flag == 1) { n       dp[i][flag] = min(solve(i + 1, 2), 1 + solve(i + 1, 0)); n     } else { n       dp[i][flag] = min(solve(i + 1, 1), 1 + solve(i + 1, 0)); n     } n   } n   return dp[i][flag]; n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) cin >> arr[i]; n   memset(dp, -1, sizeof(dp)); n   cout << solve(0, 0) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void hike() { n   int64_t n; n   cin >> n; n   string s, t; n   cin >> s >> t; n   vector<int64_t> f; n   for (int64_t i = 0; i < n; ++i) { n     if (s[i] != t[i]) { n       f.push_back(i); n     } n   } n   if (f.size() != 2) { n     cout <<  No n ; n     return; n   } n   char x1 = s[f[0]], y1 = t[f[0]]; n   char x2 = s[f[1]], y2 = t[f[1]]; n   s[f[0]] = y2; n   t[f[1]] = x1; n   if (s == t) { n     cout <<  Yes n ; n     return; n   } n   s[f[0]] = x1; n   t[f[1]] = y2; n   s[f[1]] = y1; n   t[f[0]] = x2; n   if (s == t) { n     cout <<  Yes n ; n     return; n   } n   cout <<  No n ; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   int64_t t = 1; n   cin >> t; n   while (t--) hike(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace chrono; n const int infinity = (int)1e9 + 42; n const int64_t llInfinity = (int64_t)1e18 + 256; n const int module = (int)1e9 + 7; n const long double eps = 1e-8; n mt19937_64 randGen(system_clock().now().time_since_epoch().count()); n inline void raiseError(string errorCode) { n   cerr <<  Error :   << errorCode << endl; n   exit(42); n } n struct Treap { n   int x, y; n   int size; n   int64_t sum; n   Treap *l, *r; n   Treap(int x) : x(x), y(randGen()), size(1), sum(x), l(nullptr), r(nullptr) {} n   ~Treap() { n     if (l != nullptr) { n       delete l; n     } n     if (r != nullptr) { n       delete r; n     } n   } n }; n typedef Treap* pTreap; n inline int getSize(pTreap t) { return (t != nullptr) ? t->size : 0; } n inline int64_t getSum(pTreap t) { return (t != nullptr) ? t->sum : 0; } n inline void update(pTreap t) { n   if (t != nullptr) { n     t->size = getSize(t->l) + 1 + getSize(t->r); n     t->sum = getSum(t->l) + t->x + getSum(t->r); n   } n } n inline void split(pTreap t, pTreap& l, pTreap& r, int x) { n   if (t == nullptr) { n     l = r = nullptr; n   } else if (x <= t->x) { n     split(t->l, l, t->l, x); n     r = t; n   } else { n     split(t->r, t->r, r, x); n     l = t; n   } n   update(l); n   update(r); n } n inline void splitSize(pTreap t, pTreap& l, pTreap& r, int count) { n   if (t == nullptr) { n     l = r = nullptr; n   } else if (count <= getSize(t->l)) { n     splitSize(t->l, l, t->l, count); n     r = t; n   } else { n     splitSize(t->r, t->r, r, count - getSize(t->l) - 1); n     l = t; n   } n   update(l); n   update(r); n } n void merge(pTreap& t, pTreap l, pTreap r) { n   if (l == nullptr || r == nullptr) { n     t = (l != nullptr) ? l : r; n   } else if (l->y > r->y) { n     merge(l->r, l->r, r); n     t = l; n   } else { n     merge(r->l, l, r->l); n     t = r; n   } n   update(t); n } n inline void insert(pTreap& t, pTreap it) { n   if (t == nullptr) { n     t = it; n   } else if (it->y > t->y) { n     split(t, it->l, it->r, it->x); n     t = it; n   } else if (it->x <= t->x) { n     insert(t->l, it); n   } else { n     insert(t->r, it); n   } n   update(t); n } n inline void erase(pTreap& t, int x) { n   if (t != nullptr) { n     if (x == t->x) { n       pTreap oldT = t; n       merge(t, t->l, t->r); n       oldT->l = oldT->r = nullptr; n       delete oldT; n     } else if (x < t->x) { n       erase(t->l, x); n     } else { n       erase(t->r, x); n     } n   } n   update(t); n } n inline void unite(pTreap& t, pTreap l, pTreap r) { n   if (l == nullptr || r == nullptr) { n     t = (l != nullptr) ? l : r; n   } else { n     if (r->y > l->y) { n       swap(l, r); n     } n     pTreap rl, rr; n     split(r, rl, rr, l->x); n     unite(l->l, l->l, rl); n     unite(l->r, l->r, rr); n     t = l; n   } n   update(t); n } n void outItem(pTreap t) { cout << t->x <<    ; } n void out(pTreap t) { n   if (t != nullptr) { n     out(t->l); n     outItem(t); n     out(t->r); n   } n } n pTreap nthElement(pTreap t, int n) { n   if (t == nullptr) { n     return nullptr; n   } else if (n == getSize(t->l)) { n     return t; n   } else if (n < getSize(t->l)) { n     return nthElement(t->l, n); n   } else { n     return nthElement(t->r, n - getSize(t->l) - 1); n   } n } n pTreap find(pTreap t, int x) { n   if (t == nullptr) { n     return nullptr; n   } else if (x == t->x) { n     return t; n   } else if (x < t->x) { n     return find(t->l, x); n   } else { n     return find(t->r, x); n   } n } n signed main() { n   ios_base::sync_with_stdio(false); n   int64_t n, m; n   cin >> n >> m; n   vector<int64_t> l(n); n   for (int64_t i = 1; i < n; i++) { n     cin >> l[i]; n   } n   vector<pair<int64_t, int64_t> > q(m); n   for (int64_t i = 0; i < m; i++) { n     cin >> q[i].first >> q[i].second; n     q[i].first--; n   } n   vector<vector<pair<int64_t, int64_t> > > sumByLen(n); n   for (int64_t i = 0; i < m; i++) { n     int64_t v = q[i].first; n     int64_t rng = q[i].second; n     int64_t len = 0; n     sumByLen[v].emplace_back(rng, -1); n     while (v != 0) { n       int64_t p = (v - 1) / 2; n       len += l[v]; n       int64_t pL = p * 2 + 1, pR = p * 2 + 2; n       int64_t q = -1; n       if (pL < n && pL != v) { n         q = pL; n       } else if (pR < n && pR != v) { n         q = pR; n       } n       if (q >= 0) { n         sumByLen[q].emplace_back(rng - len - l[q], -1); n       } n       v = p; n     } n   } n   for (int64_t i = 0; i < n; i++) { n     sort(sumByLen[i].begin(), sumByLen[i].end()); n   } n   function<pTreap(int64_t, int64_t)> dfs = [&](int64_t v, int64_t fUp) { n     pTreap p = new Treap(fUp); n     for (int64_t i = 1; i <= 2; i++) { n       if (v * 2 + i < n) { n         pTreap add = dfs(v * 2 + i, fUp + l[v * 2 + i]); n         unite(p, p, add); n       } n     } n     vector<pTreap> pieces; n     pieces.reserve(sumByLen[v].size()); n     int64_t cumSize = 0, cumSum = 0; n     for (auto& it : sumByLen[v]) { n       int64_t val = it.first + fUp; n       int64_t& res = it.second; n       pieces.push_back(nullptr); n       split(p, pieces.back(), p, val); n       cumSize += getSize(pieces.back()); n       cumSum += getSum(pieces.back()); n       res = (int64_t)val * cumSize - cumSum; n     } n     pTreap q = nullptr; n     for (auto it : pieces) { n       merge(q, q, it); n     } n     merge(q, q, p); n     return q; n   }; n   dfs(0, 0); n   vector<int64_t> answers(m); n   for (int64_t i = 0; i < m; i++) { n     int64_t v = q[i].first; n     int64_t rng = q[i].second; n     int64_t len = 0; n     answers[i] += lower_bound(sumByLen[v].begin(), sumByLen[v].end(), n                               make_pair(rng, (int64_t)-1)) n                       ->second; n     while (v != 0) { n       int64_t p = (v - 1) / 2; n       len += l[v]; n       if (rng >= len) { n         answers[i] += rng - len; n       } n       int64_t pL = p * 2 + 1, pR = p * 2 + 2; n       int64_t q = -1; n       if (pL < n && pL != v) { n         q = pL; n       } else if (pR < n && pR != v) { n         q = pR; n       } n       if (q >= 0) { n         answers[i] += lower_bound(sumByLen[q].begin(), sumByLen[q].end(), n                                   make_pair(rng - len - l[q], (int64_t)-1)) n                           ->second; n       } n       v = p; n     } n     cout << answers[i] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, i; n   cin >> t; n   for (i = 0; i < t; i++) { n     string s; n     cin >> s; n     int j = 0, k, l = s.length(), sum = 0; n     while (j < l) { n       if (s[j] ==  1 ) { n         k = j; n         j++; n         while (s[j] ==  0 ) j++; n         if (j - k > 1 && s[j] ==  1 ) sum = sum + j - k - 1; n       } else n         j++; n     } n     cout << sum << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 100; n long long int v[N]; n inline void outv(vector<long long int> v) { n   for (long long int i = 0; i < v.size(); i++) { n     cout << v[i] <<    ; n   } n   cout <<   n ; n } n inline long long int pow(long long int x, long long int n) { n   long long int ans = 1; n   while (n > 0) { n     if (n & 1) ans *= x; n     x *= x; n     n >>= 1; n   } n   return ans; n } n int solve() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   ; n   string n; n   cin >> n; n   int even = 0; n   int s = 0; n   int z = 0; n   for (auto c : n) { n     if ((c) % 2 == 0) even++; n     s += c -  0 ; n     if (c ==  0 ) z++; n   } n   if (s % 3 == 0 && even > 1 && z > 0) return cout <<  red  <<   n , 0; n   ; n   return cout <<  cyan  <<   n , 0; n   ; n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   ; n   int t = 1; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n, k; n   scanf( %d %d , &n, &k); n   switch (k) { n     case 1: n       printf( -1 n ); n       break; n     case 2: n       if (n < 5) { n         printf( -1 n ); n         break; n       } n       printf( %d n , n - 1); n       for (int i = 1; i < n; i++) printf( %d %d n , i, i + 1); n       break; n     case 3: n       if (n < 4) { n         printf( -1 n ); n         break; n       } n       printf( %d n1 2 n2 3 n , n - 1); n       for (int i = 4; i <= n; i++) printf( 3 %d n , i); n       break; n     default: n       printf( -1 n ); n       break; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1); n const int INF = 1000 * 1000 * 1000 + 7; n const long long LINF = INF * (long long)INF; n const int MAX = 1000 * 100 + 47; n long long A[MAX]; n long long P[MAX]; n long long Q[MAX]; n long long R[MAX]; n int main() { n   int n; n   long long p, q, r; n   cin >> n >> p >> q >> r; n   for (int i = (0); i < (n); i++) cin >> A[i]; n   for (int i = (0); i < (n); i++) { n     P[i] = p * A[i]; n     if (i) P[i] = max(P[i], P[i - 1]); n     Q[i] = P[i] + q * A[i]; n     if (i) Q[i] = max(Q[i], Q[i - 1]); n     R[i] = Q[i] + r * A[i]; n     if (i) R[i] = max(R[i], R[i - 1]); n   } n   cout << R[n - 1] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool ma[101][101]; n int m, n; n bool a[101][101]; n int steluta(int i, int j) { n   int t = 1; n   while (j + t <= m && j - t >= 1 && i + t <= n && i - t >= 1 && n          ma[i][j + t] == 1 && ma[i][j - t] == 1 && ma[i - t][j] == 1 && n          ma[i + t][j] == 1) { n     a[i][j + t] = 1; n     a[i][j - t] = 1; n     a[i - t][j] = 1; n     a[i + t][j] = 1; n     t++; n   } n   t--; n   if (t) a[i][j] = 1; n   return t; n } n int main() { n   int i, j, ramas = 0, c = 0; n   char ch; n   cin >> n >> m; n   for (i = 1; i <= n; i++) { n     for (j = 1; j <= m; j++) { n       cin >> ch; n       if (ch ==  * ) { n         ma[i][j] = 1; n       } n     } n   } n   for (i = 1; i <= n; i++) { n     for (j = 1; j <= m; j++) { n       if (ma[i][j] == 1) { n         int val = steluta(i, j); n         if (val) { n           for (int w = val; w <= val; w++) { n             c++; n           } n         } n       } n     } n   } n   for (i = 1; i <= n; i++) { n     for (j = 1; j <= m; j++) { n       if (a[i][j] == 0 && ma[i][j] == 1) { n         ramas++; n       } n     } n   } n   if (ramas > 0) { n     cout <<  -1 ; n   } else { n     cout << c <<   n ; n     for (i = 1; i <= n; i++) { n       for (j = 1; j <= m; j++) { n         if (ma[i][j] == 1) { n           int val = steluta(i, j); n           if (val) { n             for (int w = val; w <= val; w++) { n               cout << i <<     << j <<     << w <<   n ; n             } n           } n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double dist(double a, double b, double c, double d) { n   return sqrt((a - c) * (a - c) + (b - d) * (b - d)); n } n int main() { n   double x, y, r, a, b, c, d; n   cin >> x >> y >> r >> a >> b >> c; n   d = dist(x, y, a, b); n   if (d - r - c > 0) n     printf( %.9lf n , (d - r - c) / 2); n   else { n     if (d >= abs(r - c) && d <= r + c) n       printf( 0.000000000000 n ); n     else { n       if (r > c) n         printf( %.9lf n , (r - (d + c)) / 2); n       else n         printf( %.9lf n , (c - (d + r)) / 2); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T sqr(const T &a) { n   return a * a; n } n int x, k, timer, n[3], t[3], y[3], head[3], tail[3]; n pair<int, int> z[3][100000]; n int main() { n   scanf( %d%d%d%d%d%d%d , &k, &n[0], &n[1], &n[2], &t[0], &t[1], &t[2]); n   while (1) { n     timer++; n     if (timer >= t[0] + t[1] + t[2]) { n       for (int i = 0; i < (int)3; i++) n         if (z[i][tail[i]].first == timer) n           y[i] -= z[i][tail[i]].second, tail[i]++; n       x = min(n[2] - y[2], min(n[1] - y[1], n[0] - y[0])); n       if (x) { n         k -= x; n         y[2] += x, y[1] += x, y[0] += x; n         z[0][head[0]++] = make_pair(timer + t[0], x); n         z[1][head[1]++] = make_pair(timer + t[1], x); n         z[2][head[2]++] = make_pair(timer + t[2], x); n       } n       if (k <= 0) { n         printf( %d n , timer); n         return 0; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 55; n const int MAXM = 105; n const int inf = 0x3f3f3f3fLL; n struct NODE { n   long long a, b; n   int c, id; n }; n struct ANS { n   int prei, prej, prek; n   long long val; n   ANS() {} n   ANS(int _i, int _j, int _k, long long _val) n       : prei(_i), prej(_j), prek(_k), val(_val) {} n }; n NODE a[MAXN]; n long long d[MAXN][MAXN][MAXM]; n ANS pre[MAXN][MAXN][MAXM]; n bool cmp(NODE a, NODE b) { return a.c < b.c; } n void update(int i, int j, int k, int x, int y, int z, long long val) { n   if (j == y) { n     j = y; n   } n   if (d[i][j][k] == -1 || d[i][j][k] < d[x][y][z] + val) { n     d[i][j][k] = d[x][y][z] + val; n     pre[i][j][k] = ANS(x, y, z, val); n   } n } n void printans(int i, int j, int k) { n   if (i == 0) return; n   printans(i - 1, pre[i][j][k].prej, pre[i][j][k].prek); n   printf( %d %I64d n , a[j].id, pre[i][j][k].val); n } n void solved(int cas) { n   int n, m; n   long long K; n   scanf( %d %d %I64d , &m, &n, &K); n   for (int i = 1; i <= n; i++) { n     scanf( %I64d %I64d %d , &a[i].a, &a[i].b, &a[i].c); n     a[i].id = i; n   } n   sort(a + 1, a + n + 1, cmp); n   memset(d, -1, sizeof(d)); n   a[0].a = a[0].b = 0; n   for (int i = 1; i <= n; i++) n     for (long long j = a[i].a; j <= a[i].b; j++) { n       d[1][i][j - a[i].a] = j; n       pre[1][i][j - a[i].a] = ANS(0, -1, -1, j); n     } n   for (int i = 1; i < m; i++) { n     for (int j = i; j <= n; j++) { n       for (int k = 0; k <= a[j].b - a[j].a; k++) { n         if (d[i][j][k] == -1) continue; n         long long lastnum = a[j].a + k; n         for (int l = j + 1; l <= n; l++) { n           if (a[l].c == a[j].c) continue; n           long long temp = lastnum + K; n           if (temp >= a[l].a && temp <= a[l].b) n             update(i + 1, l, temp - a[l].a, i, j, k, temp); n           temp = lastnum * K; n           if (temp >= a[l].a && temp <= a[l].b) n             update(i + 1, l, temp - a[l].a, i, j, k, temp); n         } n       } n     } n   } n   long long ans = -1; n   int ansi, ansj; n   for (int i = m; i <= n; i++) n     for (int j = 0; j <= 100; j++) { n       if (d[m][i][j] > ans) { n         ans = d[m][i][j]; n         ansi = i; n         ansj = j; n       } n     } n   if (ans == -1) n     printf( NO n ); n   else { n     printf( YES n ); n     printans(m, ansi, ansj); n   } n } n int main() { n   int nT = 1; n   for (int i = 1; i <= nT; i++) solved(i); n } n


#include <bits/stdc++.h> n using namespace std; n const long double pi = acos(-1.0L); n signed main() { n   long long n; n   cin >> n; n   long double x[n], y[n]; n   for (long long i = (0); i < (n); ++i) cin >> x[i] >> y[i]; n   long long ans = 0; n   for (long long i = (0); i < (n); ++i) { n     vector<long double> v; n     for (long long j = (0); j < (n); ++j) n       if (j != i) { n         v.push_back(atan2(y[j] - y[i], x[j] - x[i])); n       } n     sort(v.begin(), v.end()); n     long long f[n - 1], s[n - 1]; n     long long k = 0; n     for (long long j = (0); j < (n - 1); ++j) { n       while (k < n - 1 && v[k] < v[j] + pi) ++k; n       f[j] = k; n       s[j] = (j ? s[j - 1] : 0) + f[j]; n     } n     for (long long j = (0); j < (n - 1); ++j) { n       ans += (s[f[j] - 1] - s[j]) - (f[j]) * (f[j] - j - 1); n     } n   } n   cout << ans * (n - 4) / 2 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   long long f = 0, s = 0; n   char c = getchar(); n   while (c >  9  || c <  0 ) f = (c ==  - ), c = getchar(); n   while (c >=  0  && c <=  9 ) n     s = (s << 3) + (s << 1) + (c ^  0 ), c = getchar(); n   return f ? -s : s; n } n long long n, m, k; n vector<long long> ch[200005]; n vector<long long> he[200005]; n long long it1, it2; n long long t1, t2; n long long sx, sy, sfx; n long long tx, ty, tfx; n long long nx, ny; n char cc[5]; n long long ans = 0; n bool flag = 0; n inline long long ne(long long op, long long t, long long x) { n   if (op == 1) n     return ch[t][upper_bound(ch[t].begin(), ch[t].end(), x) - ch[t].begin()]; n   else n     return he[t][upper_bound(he[t].begin(), he[t].end(), x) - he[t].begin()]; n } n inline long long ft(long long op, long long t, long long x) { n   if (op == 1) n     return ch[t] n              [lower_bound(ch[t].begin(), ch[t].end(), x) - ch[t].begin() - 1]; n   else n     return he[t] n              [lower_bound(he[t].begin(), he[t].end(), x) - he[t].begin() - 1]; n } n inline long long fd(long long op, long long t, long long x) { n   if (op == 1) { n     long long tt = lower_bound(ch[t].begin(), ch[t].end(), x) - ch[t].begin(); n     if (tt >= ch[t].size()) return -1; n     if (ch[t][tt] == x) n       return tt; n     else n       return -1; n   } else { n     long long tt = lower_bound(he[t].begin(), he[t].end(), x) - he[t].begin(); n     if (tt >= he[t].size()) return -1; n     if (he[t][tt] == x) n       return tt; n     else n       return -1; n   } n } n bool ff = 1, fff = 1; n int main() { n   n = read(); n   m = read(); n   k = read(); n   for (int i = 1; i <= k; i++) { n     t1 = read(); n     t2 = read(); n     ch[t2 - t1 + n + 1].push_back(t1); n     he[t1 + t2].push_back(t1); n   } n   for (int i = 0; i <= n + 1; i++) { n     ch[m + 1 - i + n + 1].push_back(i); n     he[m + 1 + i].push_back(i); n     ch[-i + n + 1].push_back(i); n     he[i].push_back(i); n   } n   for (int i = 0; i <= m + 1; i++) { n     ch[i + n + 1].push_back(0); n     he[i].push_back(0); n     ch[i - n - 1 + n + 1].push_back(n + 1); n     he[n + 1 + i].push_back(n + 1); n   } n   for (int i = 0; i <= n + m + 2; i++) sort(he[i].begin(), he[i].end()); n   for (int i = 0; i <= m + n + 2; i++) sort(ch[i].begin(), ch[i].end()); n   sx = read(); n   sy = read(); n   scanf( %s , cc); n   if (cc[0] ==  N ) { n     if (cc[1] ==  E ) n       sfx = 0; n     else n       sfx = 1; n   } else { n     if (cc[1] ==  E ) n       sfx = 2; n     else n       sfx = 3; n   } n   tx = sx; n   ty = sy; n   tfx = sfx; n   sx = sy = sfx = -1; n   while (tx != sx || ty != sy || tfx != sfx || fff) { n     if (fff && tx == sx && ty == sy && tfx == sfx) fff = 0; n     if (tfx == 0) { n       nx = ne(2, tx + ty, tx); n       ny = tx + ty - nx; n       ans += nx - tx; n       it1 = fd(2, tx + ty - 1, nx - 1); n       it2 = fd(2, tx + ty + 1, nx); n       if (it1 != -1 && it2 != -1) { n         tfx = 3; n         tx = nx - 1; n         ty = ny + 1; n         flag = 1; n       } else if (it1 != -1) { n         tfx = 2; n         tx = nx; n         ty = ny + 1; n       } else if (it2 != -1) { n         tfx = 1; n         tx = nx - 1; n         ty = ny; n       } else { n         tfx = 3; n         tx = nx - 1; n         ty = ny + 1; n         flag = 1; n       } n     } else if (tfx == 3) { n       nx = ft(2, tx + ty, tx); n       ny = tx + ty - nx; n       ans += tx - nx; n       it1 = fd(2, tx + ty - 1, nx); n       it2 = fd(2, tx + ty + 1, nx + 1); n       if (it1 != -1 && it2 != -1) { n         tfx = 0; n         tx = nx + 1; n         ty = ny - 1; n         flag = 1; n       } else if (it1 != -1) { n         tfx = 2; n         tx = nx + 1; n         ty = ny; n       } else if (it2 != -1) { n         tfx = 1; n         tx = nx; n         ty = ny - 1; n       } else { n         tfx = 0; n         tx = nx + 1; n         ty = ny - 1; n         flag = 1; n       } n     } else if (tfx == 2) { n       nx = ne(1, ty - tx + n + 1, tx); n       ny = ty - tx + nx; n       ans += nx - tx; n       it1 = fd(1, ty - tx + n + 1 - 1, nx); n       it2 = fd(1, ty - tx + n + 1 + 1, nx - 1); n       if (it1 != -1 && it2 != -1) { n         tfx = 1; n         tx = nx - 1; n         ty = ny - 1; n         flag = 1; n       } else if (it1 != -1) { n         tfx = 3; n         tx = nx - 1; n         ty = ny; n       } else if (it2 != -1) { n         tfx = 0; n         tx = nx; n         ty = ny - 1; n       } else { n         tfx = 1; n         tx = nx - 1; n         ty = ny - 1; n         flag = 1; n       } n     } else if (tfx == 1) { n       nx = ft(1, ty - tx + n + 1, tx); n       ny = ty - tx + nx; n       ans += tx - nx; n       it1 = fd(1, ty - tx + n + 1 - 1, nx + 1); n       it2 = fd(1, ty - tx + n + 1 + 1, nx); n       if (it1 != -1 && it2 != -1) { n         tfx = 2; n         tx = nx + 1; n         ty = ny + 1; n         flag = 1; n       } else if (it1 != -1) { n         tfx = 3; n         tx = nx; n         ty = ny + 1; n       } else if (it2 != -1) { n         tfx = 0; n         tx = nx + 1; n         ty = ny; n       } else { n         tfx = 2; n         tx = nx + 1; n         ty = ny + 1; n         flag = 1; n       } n     } n     if (ff) { n       sx = tx; n       sy = ty; n       sfx = tfx; n       ff = 0; n       ans = 0; n     } n   } n   while (tx != sx || ty != sy || tfx != sfx) n     ; n   if (flag) n     printf( %lld , ans / 2); n   else n     printf( %lld , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5e5 + 5; n long long n, k, sum; n long long a[maxn]; n long long goal[maxn]; n long long max(long long x, long long y) { return x > y ? x : y; } n long long cntmx = -9e18, cntmn = 9e18; n void solve3() { n   long long m = k; n   for (register int i = n; i >= 1; --i) { n     if (m >= (n - i + 1) * (a[i] - a[i - 1])) { n       m -= (n - i + 1) * (a[i] - a[i - 1]); n     } else { n       cntmn = a[i] - m / (n - i + 1); n       break; n     } n   } n   if (cntmn == 9e18) cntmn = a[1] - m / n; n   m = k; n   for (register int i = 1; i <= n; ++i) { n     if (m >= i * (a[i + 1] - a[i])) { n       m -= i * (a[i + 1] - a[i]); n     } else { n       cntmx = a[i] + m / i; n       break; n     } n   } n   if (cntmx == -9e18) cntmx = a[n] + m; n   if (cntmn - cntmx <= 0) { n     if (sum % n == 0) n       printf( 0 n ); n     else n       printf( 1 n ); n   } else n     printf( %lld n , max(0LL, cntmn - cntmx)); n } n int main() { n   scanf( %lld%lld , &n, &k); n   for (register int i = 1; i <= n; ++i) scanf( %lld , &a[i]), sum += a[i]; n   sort(a + 1, a + n + 1); n   solve3(); n   fclose(stdin); n   fclose(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   char mi, ma; n   int max = 0, min = INT_MAX; n   pair<int, char> p[4]; n   for (int i = 0; i < 4; ++i) { n     cin >> s; n     p[i].first = s.length() - 2; n     p[i].second = s[0]; n   } n   sort(p, p + 4); n   int flag1 = 0, flag2 = 0; n   for (int j = 1; j < 4; ++j) { n     if (2 * (p[0].first) <= p[j].first) flag1 += 1; n   } n   for (int j = 0; j < 3; ++j) { n     if (p[3].first >= 2 * (p[j].first)) flag2 += 1; n   } n   if (flag1 == 3 && flag2 != 3) n     cout << p[0].second <<   n ; n   else if (flag2 == 3 && flag1 != 3) n     cout << p[3].second <<   n ; n   else n     cout <<  C n ; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int n, ji[300], k, qi, mz[400010]; n char s[400010], tp[400010]; n int main() { n   scanf( %d%s , &n, s + 1); n   for (int i = 1; i <= n; i++) { n     ji[s[i]]++; n   } n   for (int i = 0; i < 300; i++) n     if (ji[i] & 1) k++; n   qi = k; n   if (!qi) { n     for (k = 1;; k++) n       if (n % k == 0) break; n     n /= k; n     printf( %d n , k); n     if (n & 1) { n       for (int i = 0, tt = 0; i < 300; i++) { n         while (ji[i]) { n           mz[++tt] = i; n           ji[i]--; n           if (tt == k) goto qaz; n         } n       } n     qaz:; n       n >>= 1; n       for (int i = 1, p = 0; i <= k; i++) { n         for (int j = 1; j <= n; j++) { n           while (!ji[p]) p++; n           ji[p] -= 2; n           tp[j] = tp[n * 2 + 2 - j] = p; n         } n         tp[n + 1] = mz[i]; n         printf( %s  , tp + 1); n       } n       return 0; n     } n     n >>= 1; n     for (int i = 1, p = 0; i <= k; i++) { n       for (int j = 1; j <= n; j++) { n         while (!ji[p]) p++; n         ji[p] -= 2; n         tp[j] = tp[n * 2 + 1 - j] = p; n       } n       printf( %s  , tp + 1); n     } n     return 0; n   } n   for (;; k++) n     if (n % k == 0 && (n / k) & 1) break; n   printf( %d n , k); n   n /= k; n   int tt = 0; n   for (int i = 0; i < 300; i++) n     if (ji[i] & 1) { n       mz[++tt] = i; n       ji[i]--; n     } n   if (tt == k) goto qazz; n   for (int i = 0; i < 300; i++) { n     while (ji[i]) { n       mz[++tt] = i; n       ji[i]--; n       if (tt == k) goto qazz; n     } n   } n qazz:; n   n >>= 1; n   for (int i = 1, p = 0; i <= k; i++) { n     for (int j = 1; j <= n; j++) { n       while (!ji[p]) p++; n       ji[p] -= 2; n       tp[j] = tp[n * 2 + 2 - j] = p; n     } n     tp[n + 1] = mz[i]; n     printf( %s  , tp + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n // #include <ext/pb_ds/assoc_container.hpp> n // #include <ext/pb_ds/tree_policy.hpp> n using namespace std; n // using namespace __gnu_pbds; n #define lli long long int n #define llu unsigned long long int n #define pb push_back n #define rt return 0 n #define endln   n  n #define all(x) x.begin(), x.end() n #define sz(x) (lli)(x.size()) n #define len(x) (lli)(x.length()) n const lli MOD = 1e9 + 7; n const double PI = 2 * acos(0.0); n // cout << fixed << setprecision(0) << pi <<endl; n // typedef tree<int, null_type, less<int>, rb_tree_tag, n //              tree_order_statistics_node_update> n //     new_data_set; n // for multiset n // typedef tree<int, null_type, less_equal<int>, rb_tree_tag, n //              tree_order_statistics_node_update> n //     new_data_set; n // order_of_key(val): returns the number of values less than val n // find_by_order(k): returns an iterator to the kth largest element (0-based) n  n void solve() { n     lli n, a; n     cin >> n; n     vector<lli> v; n     for (lli i = 0; i < n; i++) { n         cin >> a; n         v.pb(a); n     } n  n     for (lli i = 0; i < n; i++) { n         lli tmp = v[i], ind = 0, one; n         while (tmp > 0) { n             if (tmp % 2 == 1) { n                 one = ind; n             } n             tmp /= 2; n             ind++; n         } n  n         lli p = pow(2, one); n         cout << p <<    ; n     } n     cout << endl; n } n  n int main(void) { n     ios::sync_with_stdio(0); n     cin.tie(0); n     cout.tie(0); n     lli t; n     cin >> t; n     while (t--) n         solve(); n     rt; n }


#include <bits/stdc++.h> n using namespace std; n const int Max_N = 1E6 + 10; n int n, m, ans = 1, p[Max_N], color[Max_N]; n vector<int> chil[Max_N]; n bool mark[Max_N]; n int dfs(int i) { n   int res = 0; n   mark[i] = true; n   for (int u : chil[i]) n     if (!mark[u] && color[i] != color[u]) ++res; n   return res; n } n int main() { n   cin >> n; n   for (int i = 1; i < n; i++) { n     cin >> p[i]; n     p[i]--; n     chil[p[i]].push_back(i); n   } n   for (int i = 0; i < n; i++) cin >> color[i]; n   for (int i = 0; i < n; i++) n     if (!mark[i]) ans += dfs(i); n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1010; n const int MAXK = 1000010; n int n, m, k, p, a[N][N], row[N], col[N]; n long long ans1[MAXK], ans2[MAXK]; n multiset<long long> Unis; n void solve(long long *ans, int n, int *a, int dta) { n   Unis.clear(); n   for (int i = 1; i <= n; ++i) { n     Unis.insert(-a[i]); n   } n   long long now = 0; n   for (int kk = 1; kk <= k; ++kk) { n     long long val = *Unis.begin(); n     now += val; n     Unis.erase(Unis.begin()); n     Unis.insert(val + dta); n     ans[kk] = -now; n   } n } n int main() { n   scanf( %d %d %d %d , &n, &m, &k, &p); n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) { n       scanf( %d , &a[i][j]); n       row[i] += a[i][j]; n       col[j] += a[i][j]; n     } n   solve(ans1, n, row, p * m); n   solve(ans2, m, col, p * n); n   long long zans = -1e18; n   for (int i = 0; i <= k; ++i) { n     zans = max(zans, ans1[i] + ans2[k - i] - (long long)i * (k - i) * p); n   } n   cout << zans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int c, hi, hb, wi, wb; n inline long long f(int x) { n   long long k1 = x; n   long long k2 = 1ll * (0ll + c - 1ll * x * wi) / wb; n   return k1 * hi + k2 * hb; n } n int main() { n   cin >> c >> hi >> hb >> wi >> wb; n   int kek1 = c / wi; n   int l = 0; n   int r = kek1; n   long long ans = 0; n   ans = max(ans, f(0)); n   ans = max(ans, f(kek1)); n   for (int i = 0; i <= 10000000; ++i) n     if (i <= kek1) ans = max(ans, f(i)); n   while (r - l > 1) { n     int m = (r - l + 1) / 3; n     int k1 = l + m; n     int k2 = r - m; n     if (f(k1) > f(k2)) n       r = k2; n     else n       l = k1; n   } n   for (int i = l - 9000000; i <= r + 9000000; ++i) n     if (i >= 0 && i <= kek1) ans = max(ans, f(i)); n   swap(wi, wb); n   swap(hi, hb); n   kek1 = c / wi; n   l = 0; n   r = kek1; n   for (int i = 0; i <= 10000000; ++i) n     if (i <= kek1) ans = max(ans, f(i)); n   while (r - l > 1) { n     int m = (r - l + 1) / 3; n     int k1 = l + m; n     int k2 = r - m; n     if (f(k1) > f(k2)) n       r = k2; n     else n       l = k1; n   } n   for (int i = l - 9000000; i <= r + 9000000; ++i) n     if (i >= 0 && i <= kek1) ans = max(ans, f(i)); n   ans = max(ans, f(0)); n   ans = max(ans, f(kek1)); n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, a[101000], tmp; n struct C { n   int b, p; n } c[101000]; n long long ans = 0, tot; n bool cmp(C c1, C c2) { return c1.b < c2.b; } n priority_queue<int, vector<int>, greater<int> > q; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (int i = 1; i <= m; i++) scanf( %d , &c[i].b); n   for (int i = 1; i <= m; i++) scanf( %d , &c[i].p); n   sort(c + 1, c + m + 1, cmp); n   int p, pos = 0; n   for (int now = n; now > 0; now = p - 1) { n     p = now; n     tot = a[p]; n     for (; a[p - 1] <= a[now] && p > 1;) tot += a[--p]; n     for (; pos < m && c[pos + 1].b <= a[now];) q.push(c[++pos].p); n     for (; !q.empty();) { n       if (tot >= q.top()) { n         ans++; n         tot -= q.top(); n         q.pop(); n       } else { n         tmp = q.top() - tot; n         q.pop(); n         q.push(tmp); n         tot = 0; n         break; n       } n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 10; n int t, n, a[N]; n int main() { n   ios::sync_with_stdio(false); n   for (cin >> t; t; t--) { n     cin >> n; n     long long l = 0, r = 0; n     for (int i = 1; i <= n; i++) { n       cin >> a[i]; n       l += a[i]; n       r ^= a[i]; n     } n     cout << 2 <<   n  << r <<     << (l + r) <<   n ; n   } n   return 0; n } n


#include  bits/stdc++.h  n using namespace std; n #define ll               long long int n #define pb                push_back n #define ppb               pop_back n #define pf                push_front n #define ppf               pop_front n #define all(x)            (x).begin(),(x).end() n #define uniq(v)           (v).erase(unique(all(v)),(v).end()) n #define sz(x)             (int)((x).size()) n #define fr                first n #define sc                second n #define pii               pair<int,int> n #define rep(i,a,b)        for(int i=a;i<b;i++) n #define mem1(a)           memset(a,-1,sizeof(a)) n #define mem0(a)           memset(a,0,sizeof(a)) n #define ppc               __builtin_popcount n #define ppcll             __builtin_popcountll n   n  n template<typename T,typename T1>T max_self(T &a,T1 b){if(b>a)a=b;return a;} n template<typename T,typename T1>T min_self(T &a,T1 b){if(b<a)a=b;return a;} n   n const long long int INF=1e9; n const int N=0; n const int modn=1e9+7; n  n   n   n   n void solve(){ n int n,m;cin>>n>>m; n  string s,t; n  cin>>s>>t; n  int left[m],right[m]; n  int i=0,j=0; n   while(j<m) n    {while(s[i]!=t[j])  n      i++; n      left[j]=i; n      j++,i++; n     } n    i=n-1; j=m-1; n    while(~j) n    { n     while(s[i]!=t[j]) n       i--; n       right[j]=i; n       i--,j--; n  }  n  int ans=0; n  //rep(i,0,m) n  //cout<<left[i]<<   ; n     rep(i,1,m) n     max_self(ans,right[i]-left[i-1]); n  cout<<ans<<  n  ; n   n } n int main(){ n  ios_base::sync_with_stdio(false); n  cin.tie(0);cout.tie(0); n  int t=1; n  //cin>>t; n  while(t--) solve(); n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long x, long long y) { n   if (y == 0) return x; n   return gcd(y, x % y); n } n long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n void XsliferX() { n   ios::sync_with_stdio(0); n   ios_base::sync_with_stdio(0); n   cin.tie(0), cout.tie(0); n } n long long f_p(long long x, int y) { n   if (y == 0) n     return 1; n   else if (y % 2 == 0) n     return f_p(x * x, y / 2); n   else n     return x * f_p(x * x, y / 2); n } n long long l_p(long long n) { n   n = n | (n >> 1); n   n = n | (n >> 2); n   n = n | (n >> 4); n   n = n | (n >> 8); n   return (n + 1) >> 1; n } n int dp[5005]; n int a[5005]; n int n; n int L[5005], R[5005]; n bool vis[5005]; n int solve(int idx) { n   int x = 0; n   int lft = L[a[idx]], rit = R[a[idx]]; n   if (idx == n) return 0; n   if (dp[idx] != -1) return dp[idx]; n   for (int i = L[a[idx]]; i <= R[a[idx]]; i++) { n     if (lft > L[a[i]]) lft = L[a[i]]; n     if (rit < R[a[i]]) rit = R[a[i]]; n   } n   bool v[5005] = {0}; n   if (idx == lft) { n     int xo = 0; n     for (int i = lft; i <= rit; i++) { n       if (!v[a[i]]) { n         xo ^= a[i]; n         v[a[i]] = 1; n       } n       vis[a[i]] = 1; n     } n     x = max(x, solve(rit + 1) + xo); n     for (int i = lft; i < rit; i++) { n       vis[a[i]] = 0; n     } n   } n   vis[a[idx]] = 1; n   x = max(x, solve(idx + 1)); n   vis[a[idx]] = 0; n   return dp[idx] = x; n } n int main() { n   memset(dp, -1, sizeof dp); n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i], R[a[i]] = i; n   memset(L, -1, sizeof L); n   for (int i = 0; i < n; i++) n     if (L[a[i]] == -1) L[a[i]] = i; n   cout << solve(0) <<   n ; n   return 0; n } n