#include <bits/stdc++.h> n using namespace std; n template <class T> n using vec = vector<T>; n template <typename Iter> n ostream &_IterOutput_(ostream &o, Iter b, Iter e, const string ss =   , n                       const string se =   ) { n   o << ss; n   for (auto it = b; it != e; it++) o << (it == b ?    :  ,  ) << *it; n   return o << se; n } n template <typename T1, typename T2> n ostream &operator<<(ostream &o, const pair<T1, T2> &pair) { n   return o <<  (  << pair.first <<  ,   << pair.second <<  ) ; n } n template <typename T> n ostream &operator<<(ostream &o, const vector<T> &vec) { n   return _IterOutput_(o, begin(vec), end(vec),  [ ,  ] ); n } n template <typename T> n ostream &operator<<(ostream &o, const set<T> &st) { n   return _IterOutput_(o, begin(st), end(st),  { ,  } ); n } n template <typename T, size_t N> n ostream &operator<<(ostream &o, const array<T, N> &arr) { n   return _IterOutput_(o, begin(arr), end(arr),  | ,  | ); n } n template <typename T1, typename T2> n ostream &operator<<(ostream &o, const map<T1, T2> &mp) { n   o <<  { ; n   for (auto it = mp.begin(); it != mp.end(); it++) { n     o << (it == mp.begin() ?    :  ,  ) << it->first <<  :  << it->second; n   } n   o <<  } ; n   return o; n } n using A3 = array<long long, 3>; n inline long long get(long long x, long long i) { n   return (x & (63LL << (i * 6))) >> (i * 6); n } n inline long long se(long long x, long long i, long long w) { n   long long sh = (i * 6); n   (x &= ~(63LL << sh)) ^= w << sh; n   return x; n } n inline long long del(long long x, long long i) { n   long long sh = i * 6; n   long long rm = x & ((1LL << sh) - 1); n   ((x >>= sh + 6) <<= sh) |= rm; n   return x; n } n A3 dec(long long x) { return {x & 3, (x >> 2) & 3, (x >> 4) & 3}; } n inline long long enc(A3 a) { n   if (a[2] > a[0]) swap(a[2], a[0]); n   return a[0] + (a[1] << 2) + (a[2] << 4); n } n unordered_map<long long, double> mem; n const double INF = 1e9; n long long norm(long long x) { n   static long long Z[30]; n   long long i = 1, p; n   for (; p = get(x, i); i++) { n     Z[i] = p; n   } n   sort(Z + 1, Z + i); n   for (long long j = 1; j < i; j++) { n     x = se(x, j, Z[j]); n   } n   return x; n } n long long zz = 0; n double dp(long long st) { n   if (mem.count(st)) return mem[st]; n   double ex[4] = {0, INF, INF, INF}; n   for (long long i = 1, p; p = get(st, i); i++) { n     auto a = dec(p); n     if (!a[1] or (!a[0] and !a[2])) continue; n     for (long long j = 0; j < 3; j++) { n       if (!a[j]) continue; n       if (a[2] == 0 and j == 1) continue; n       long long cl = a[j]; n       auto b = a; n       b[j] = 0; n       long long nx; n       if (!b[1] or (!b[0] and !b[2])) { n         nx = del(st, i); n       } else { n         nx = se(st, i, enc(b)); n       } n       long long top = get(nx, 0); n       auto c = dec(top); n       if (c[0] and c[1] and c[2]) { n         top <<= 6; n         nx <<= 6; n         c = dec(top); n       } n       for (long long k = 0; k < 3; k++) n         if (!c[k]) { n           auto d = c; n           d[k] = cl; n           long long fn = norm(se(nx, 0, enc(d))); n           ex[cl] = min(ex[cl], dp(fn)); n         } n     } n   } n   if (ex[1] >= INF and ex[2] >= INF and ex[3] >= INF) { n     return (mem[st]) = 0; n   } else { n     double zzprob = 1.0 / 6; n     if (ex[1] == INF) zzprob += 1.0 / 6, ex[1] = 0; n     if (ex[2] == INF) zzprob += 2.0 / 6, ex[2] = 0; n     if (ex[3] == INF) zzprob += 2.0 / 6, ex[3] = 0; n     (mem[st]) = (ex[1] * 1.0 / 6 + ex[2] * 2.0 / 6 + ex[3] * 2.0 / 6 + 1) / n                 (1.0 - zzprob); n     return (mem[st]); n   } n } n int32_t main() { n   do { n     ios_base::sync_with_stdio(0); n     cin.tie(0); n   } while (0); n   long long N; n   cin >> N; n   cout << fixed << setprecision(10); n   long long t = 0; n   for (long long i = 0; i < N; i++) { n     string s; n     cin >> s; n     A3 a; n     for (long long j = 0; j < 3; j++) { n       long long z = s[j] ==  R  ? 1 : s[j] ==  G  ? 2 : 3; n       a[j] = z; n     } n     (t <<= 6) += enc(a); n   } n   cout << dp(t) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f; n int main() { n   int T; n   cin >> T; n   while (T--) { n     int b, p, f, h, c; n     cin >> b >> p >> f >> h >> c; n     int ans = 0; n     for (int i = 0; i <= p; ++i) { n       int num1 = min(i, b / 2); n       int num2 = min(f, (b - num1 * 2) / 2); n       ans = max(ans, num1 * h + num2 * c); n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n stringstream output; n inline void eOP(); n inline void solve() { n   int n, x, y; n   cin >> n >> x >> y; n   string s; n   cin >> s; n   char p =  1 ; n   long long cnt = 0; n   for (char c : s) { n     if (p ==  1  && c ==  0 ) { n       ++cnt; n     } n     p = c; n   } n   long long result = 0; n   if (cnt) { n     result += y; n     --cnt; n   } n   result += cnt * (min(x, y)); n   output << result; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   size_t t = 1; n   for (int i = 0; i < t; ++i) { n     solve(); n   } n   eOP(); n } n inline void eOP() { n   cout << output.str(); n   output.str(string()); n   exit(0); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<pair<int, int> > v; n   int n, i, c = 1, ans = 0; n   vector<pair<int, int> >::iterator it; n   cin >> n; n   for (i = 0; i < n; i++) { n     int x, y; n     cin >> x >> y; n     v.push_back(make_pair(y, x)); n   } n   sort(v.begin(), v.end()); n   for (i = n - 1; i >= 0; i--) { n     if (c == 0) { n       break; n     } n     c = c - 1 + v[i].first; n     ans = ans + v[i].second; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n double x[101010], y[101010]; n double maxn[101010], minn[101010]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %lf , &maxn[i]); n   for (int i = 1; i <= n; i++) scanf( %lf , &minn[i]); n   for (int i = n - 1; i >= 1; i--) minn[i] += minn[i + 1]; n   double resx = 1, resy = 1, getx = 0, gety = 0; n   maxn[0] = 0; n   bool key = false; n   for (int i = 1; i < n; i++) { n     maxn[i] += maxn[i - 1]; n     double k1 = maxn[i]; n     double k2 = minn[i]; n     double a = 0, b = 0, c = 0; n     a += 1; n     b += minn[i + 1] - maxn[i] - 1; n     c += maxn[i]; n     double det = b * b - 4 * a * c; n     if (det < 0) { n       if (det < -0.01) { n         printf( %.3f-- n , det); n         key = true; n       } n       det = 0; n     } n     double ans1 = (-b + sqrt(det)) / (2 * a); n     double ans2 = (-b - sqrt(det)) / (2 * a); n     x[i] = ans1; n     y[i] = ans2; n   } n   y[n] = x[n] = 1; n   for (int i = n; i >= 1; i--) { n     x[i] = x[i] - x[i - 1]; n     y[i] -= y[i - 1]; n   } n   for (int i = 1; i <= n; i++) { n     printf( %.8f , y[i]); n     if (i == n) n       printf(  n ); n     else n       printf(   ); n   } n   for (int i = 1; i <= n; i++) { n     printf( %.8f , x[i]); n     if (i == n) n       printf(  n ); n     else n       printf(   ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 2e5 + 10; n long long arr[MAX]; n int cur[MAX], want[MAX]; n int n; n vector<vector<int> > adj(MAX); n long long ans = 0; n array<int, 2> dfs(int node, int par, long long Min) { n   array<int, 2> a, b; n   a[0] = 0, a[1] = 0; n   if (cur[node] != want[node]) a[cur[node]]++; n   for (auto &child : adj[node]) { n     if (child == par) continue; n     b = dfs(child, node, min(Min, arr[node])); n     a[0] += b[0], a[1] += b[1]; n   } n   if (arr[node] < Min) { n     int x = min(a[0], a[1]); n     ans += x * 2ll * arr[node]; n     a[0] -= x, a[1] -= x; n   } n   return a; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   for (int i = 1; i <= n; ++i) cin >> arr[i] >> cur[i] >> want[i]; n   for (int i = 0; i < n - 1; ++i) { n     int x, y; n     cin >> x >> y; n     adj[x].push_back(y); n     adj[y].push_back(x); n   } n   array<int, 2> a = dfs(1, -1, 2e9); n   if (a[0] || a[1]) n     cout << -1 <<   n ; n   else n     cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   long long x, id; n } a[200005]; n long long st[200005], top; n bool cmp(node a, node b) { return a.x < b.x; } n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long T; n   cin >> T; n   while (T--) { n     top = 0; n     long long n, w, sum = 0; n     cin >> n >> w; n     for (long long i = 1; i <= n; i++) { n       cin >> a[i].x; n       a[i].id = i; n     } n     for (long long i = 1; i <= n; i++) { n       if ((w + 1) / 2 <= a[i].x && a[i].x <= w) { n         cout <<  1 n  << i <<   n ; n         goto loop; n       } n     } n     sort(a + 1, a + n + 1, cmp); n     while (a[n].x >= w) { n       n--; n     } n     for (long long i = n; i >= 1; i--) { n       if (sum + a[i].x <= w) { n         sum += a[i].x; n         st[++top] = a[i].id; n       } n       if ((w + 1) / 2 <= sum) { n         cout << top <<   n ; n         for (long long i = 1; i <= top; i++) { n           cout << st[i] <<    ; n         } n         cout <<   n ; n         goto loop; n       } n     } n     cout <<  -1 n ; n   loop:; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   unsigned long long i, j, k, l, r, n, m; n   scanf( %llu , &l); n   scanf( %llu , &r); n   scanf( %llu , &k); n   j = k; n   n = ceil(log(l) / (double)log(k)); n   unsigned long long chq = 0; n   chq = max(chq, (unsigned long long)(floor(log(r) / (double)log(k)))); n   if (chq < n) { n     puts( -1 ); n     return 0; n   } n   k = pow(j, n); n   bool ok = false; n   for (i = n; i <= chq; i++) { n     if (k > r) break; n     ok = true; n     printf( %llu , k); n     printf(   ); n     ; n     k *= j; n   } n   if (k == r) printf( %llu , k); n   if (!ok) printf( -1 ); n   printf(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n char f; n string tas[1000], mas; n long a, b, kol, m, n, pos, mi, ma, nn, kola, kolb; n double k; n long long ans; n int main() { n   cin >> mas; n   for (int a = 0; a < (10); a++) cin >> tas[a]; n   for (int a = 0; a < (8); a++) { n     for (int b = 0; b < (10); b++) { n       if (mas.substr(a * 10, 10) == tas[b]) cout << b; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = (1 << 16) + 5, maxm = 125; n int n, f[maxn][maxm], sa[maxn], sb[maxn], va, vb; n struct node { n   int id, r, b; n } a[20]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     char ch = getchar(); n     while (ch !=  R  && ch !=  B ) ch = getchar(); n     a[i].id = (ch ==  B ); n     scanf( %d%d , &a[i].r, &a[i].b); n   } n   for (int i = 1; i < (1 << n); i++) { n     for (int j = 1; j <= n; j++) n       if (i & (1 << j - 1)) { n         if (a[j].id == 0) n           sa[i]++; n         else n           sb[i]++; n         ; n       } n   } n   for (int i = 1; i <= n; i++) va += a[i].r, vb += a[i].b; n   memset(f, 255, sizeof(f)); n   f[0][0] = 0; n   for (int i = 0; i < (1 << n) - 1; i++) { n     for (int j = 0; j <= n * (n - 1) / 2; j++) n       if (f[i][j] != -1) { n         for (int k = 1; k <= n; k++) n           if (!(i & (1 << k - 1))) { n             int p = (i | (1 << k - 1)); n             f[p][j + min(sa[i], a[k].r)] = n                 max(f[p][j + min(a[k].r, sa[i])], f[i][j] + min(sb[i], a[k].b)); n           } n       } n   } n   int ans = (1 << 30); n   for (int i = 0; i <= n * (n - 1) / 2; i++) n     if (f[(1 << n) - 1][i] != -1) { n       ans = min(ans, max(va - i, vb - f[(1 << n) - 1][i]) + n); n     } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n, k, l; n     cin >> n >> k >> l; n     vector<int> d(n + 1), safe = {0}; n     for (int i = 1; i <= n; ++i) { n       cin >> d[i]; n       if (d[i] + k <= l) safe.push_back(i); n     } n     safe.push_back(n + 1); n     bool ok = true; n     for (size_t i = 1; i < safe.size() && ok; ++i) { n       int tide = k; n       bool down = true; n       for (int j = safe[i - 1] + 1; j < safe[i]; ++j) { n         tide += down ? -1 : +1; n         if (down) tide -= max(0, d[j] + tide - l); n         if (tide < 0 || d[j] + tide > l) { n           ok = false; n           break; n         } n         if (tide == 0) down = false; n       } n     } n     if (ok) n       cout <<  Yes n ; n     else n       cout <<  No n ; n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long a, b; n   cin >> a >> b; n   long long count = 0; n   while (a != b) { n     if (a == 0 || b == 0) break; n     if (a < b) { n       count += b / a; n       b = b % a; n     } else { n       count += a / b; n       a = a % b; n     } n   } n   if (a > 0 && a == b) count++; n   cout << count << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = (int)1e9 + 7; n const int INF = (int)1e9; n const long long LINF = (long long)1e18; n const long double PI = acos((long double)-1); n const long double EPS = 1e-9; n inline long long gcd(long long a, long long b) { n   long long r; n   while (b) { n     r = a % b; n     a = b; n     b = r; n   } n   return a; n } n inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n inline long long fpow(long long n, long long k, int p = MOD) { n   long long r = 1; n   for (; k; k >>= 1) { n     if (k & 1) r = r * n % p; n     n = n * n % p; n   } n   return r; n } n template <class T> n inline int chkmin(T& a, const T& val) { n   return val < a ? a = val, 1 : 0; n } n template <class T> n inline int chkmax(T& a, const T& val) { n   return a < val ? a = val, 1 : 0; n } n template <class T> n inline T isqrt(T k) { n   T r = sqrt(k) + 1; n   while (r * r > k) r--; n   return r; n } n template <class T> n inline T icbrt(T k) { n   T r = cbrt(k) + 1; n   while (r * r * r > k) r--; n   return r; n } n inline void addmod(int& a, int val, int p = MOD) { n   if ((a = (a + val)) >= p) a -= p; n } n inline void submod(int& a, int val, int p = MOD) { n   if ((a = (a - val)) < 0) a += p; n } n inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; } n inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); } n void solve() { n   long long r, h; n   cin >> r >> h; n   long double rr = r, hh = h; n   long long ans = 0; n   if (2 * h >= r) { n     long long tmp = (long long)floor((hh - rr / 2) / rr + EPS) + 1; n     long double z = hh - rr / 2 - tmp * rr; n     chkmax(ans, 2 * tmp); n     if (z >= rr * (sqrt(3) / 2 - 0.5) - EPS) { n       chkmax(ans, 2 * tmp + 1); n     } n   } n   hh += rr * (1 - sqrt(3) / 2); n   long long tmp = (long long)floor(hh / rr + EPS); n   long double z = hh - tmp * rr; n   chkmax(ans, 2 * tmp + 1); n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O999 ) n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cout <<  INTERCAL ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, m; n   cin >> n >> m; n   int mn = min(n, m); n   if (mn % 2 == 0) { n     cout <<  Malvika ; n   } else { n     cout <<  Akshat ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, o[1010][1010], a[1010][1010], b[1010][1010], siza[1010], sizb[1010]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       scanf( %d , &o[i][j]); n       a[i][j] = b[j][i] = o[i][j]; n     } n   } n   for (int i = 0; i < n; i++) { n     sort(a[i], a[i] + m); n     siza[i] = unique(a[i], a[i] + m) - a[i]; n   } n   for (int i = 0; i < m; i++) { n     sort(b[i], b[i] + n); n     sizb[i] = unique(b[i], b[i] + n) - b[i]; n   } n   int x, y; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       x = lower_bound(a[i], a[i] + siza[i], o[i][j]) - a[i]; n       y = lower_bound(b[j], b[j] + sizb[j], o[i][j]) - b[j]; n       printf( %d  , max(x, y) + max(siza[i] - x, sizb[j] - y)); n     } n     putchar(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n const long long MOD = 1e9 + 7; n using namespace std; n long long n, u, v, ans, dp[100005], cntt[100005]; n vector<vector<long long> > g(100005); n bool used[100005]; n long long bpow(long long x, long long p) { n   if (p == 0) return 1; n   long long cur = bpow(x, p >> 1); n   cur = (cur * cur) % MOD; n   if (p & 1) cur = (cur * x) % MOD; n   return cur; n } n void countDp(long long x) { n   used[x] = true; n   long long cans = 1, cnt = 0; n   ; n   for (int i = 0; i < g[x].size(); i++) { n     if (!used[g[x][i]]) { n       countDp(g[x][i]); n       cnt++; n       cans = (cans * dp[g[x][i]]) % MOD; n     } n   } n   if (cnt != 0) cans = (2 * cans) % MOD; n   cntt[x] = cnt; n   dp[x] = cans; n } n void countAns(long long x, long long mlt, bool root) { n   used[x] = true; n   if (!root && cntt[x] == 0) { n     dp[x] = (dp[x] * 2) % MOD; n   } n   dp[x] = (dp[x] * mlt) % MOD; n   ans = (ans + dp[x]) % MOD; n   for (int i = 0; i < g[x].size(); i++) { n     if (!used[g[x][i]]) { n       if (root && cntt[x] == 1) n         countAns( n             g[x][i], n             (((dp[x] * bpow(dp[g[x][i]], MOD - 2)) % MOD) * bpow(2, MOD - 2)) % n                 MOD, n             0); n       else n         countAns(g[x][i], (dp[x] * bpow(dp[g[x][i]], MOD - 2)) % MOD, 0); n     } n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n; n   for (int i = 0; i < n - 1; i++) { n     cin >> u >> v; n     g[u].push_back(v); n     g[v].push_back(u); n   } n   countDp(1); n   for (int i = 1; i <= n; i++) { n     used[i] = false; n   } n   countAns(1, 1, 1); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n template <class T> n T gcd(T a, T b) { n   while (a && b) n     if (a > b) n       a %= b; n     else n       b %= a; n   return a + b; n } n using namespace std; n long long k, n[3], t[3], ans[11111][3], i, j; n int main() { n   cin >> k >> n[0] >> n[1] >> n[2] >> t[0] >> t[1] >> t[2]; n   for (i = 0; i < k; i++) n     for (j = 0; j < 3; j++) { n       if (i == 0 && j == 0) n         ans[i][j] = t[0]; n       else if (i == 0) n         ans[i][j] = ans[i][j - 1] + t[j]; n       else if (i < n[j]) n         if (j == 0) n           ans[i][j] = t[j]; n         else n           ans[i][j] = ans[i][j - 1] + t[j]; n       else if (j == 0) n         ans[i][j] = ans[i - n[j]][j] + t[j]; n       else n         ans[i][j] = max(ans[i - n[j]][j] + t[j], ans[i][j - 1] + t[j]); n     } n   cout << ans[k - 1][2]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int mod = 1e9 + 7; n long long int casei(long long int tc) { n   long long int n, i, trn = 1, fct = 1; n   cin >> n; n   for (i = 1; i <= n; i++) { n     if (i < n) trn *= 2; n     fct *= i; n     trn %= mod; n     fct %= mod; n   } n   long long int ans = fct - trn; n   if (ans < 0) ans += mod; n   cout << ans <<   n ; n   return 0; n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long int tc, x; n   tc = 1; n   while (tc--) casei(x - tc); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n const int N = 5e3 + 5; n int n, vis[26][26][N]; n string s; n long double ans; n int main() { n   ios::sync_with_stdio(0); n   cout << fixed << setprecision(12); n   cin >> s; n   n = s.size(); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) vis[s[0] -  a ][s[j] -  a ][j]++; n     s.push_back(s.front()); n     s.erase(s.begin()); n   } n   for (int i = 0; i < 26; i++) { n     int mx = 0; n     for (int j = 0; j < n; j++) { n       int cnt = 0; n       for (int k = 0; k < 26; k++) { n         cnt += (vis[i][k][j] == 1); n       } n       mx = max(mx, cnt); n     } n     ans += mx; n   } n   cout << ans / (long double)n; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   long long t = 1; n   scanf( %lld , &t); n   while (t--) { n     long long n, a = 0; n     scanf( %lld , &n); n     while (n > 0) { n       int r = n % 2; n       if (r == 1) a++; n       n = n / 2; n     } n     long long ans = pow(2, a); n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 7; n pair<int, int> edges[N]; n int type[N]; n bool inv[N]; n vector<int> e[N]; n int vis[N]; n int used[N]; n inline int other(int id, int u) { n   return edges[id].first == u ? edges[id].second : edges[id].first; n } n int ans1 = 0, ans2 = 0; n void dfs(int u) { n   vis[u] = 1; n   ans1++; n   for (int ed : e[u]) { n     int v = other(ed, u); n     if (!vis[v]) { n       used[ed] = v; n       dfs(v); n     } n   } n } n void dfs2(int u) { n   vis[u] = 1; n   ans2++; n   for (int ed : e[u]) { n     int v = other(ed, u); n     if (!vis[v]) { n       if (type[ed] == 1) { n         dfs2(v); n       } else { n         used[ed] = v; n       } n     } n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n, m, s; n   cin >> n >> m >> s; n   for (int i = 0; i < m; ++i) { n     int t, u, v; n     cin >> t >> u >> v; n     type[i] = t; n     edges[i] = pair<int, int>(u, v); n     if (t == 1) n       e[u].push_back(i); n     else { n       e[u].push_back(i); n       e[v].push_back(i); n     } n   } n   dfs(s); n   cout << ans1 << endl; n   for (int i = 0; i < m; ++i) { n     if (type[i] == 2) { n       if (used[i] == other(i, edges[i].first)) n         cout <<  + ; n       else n         cout <<  - ; n     } n   } n   cout << endl; n   memset(vis, 0, sizeof vis); n   memset(used, 0, sizeof used); n   dfs2(s); n   cout << ans2 << endl; n   for (int i = 0; i < m; ++i) { n     if (type[i] == 2) { n       if (used[i] == other(i, edges[i].first)) n         cout <<  - ; n       else n         cout <<  + ; n     } n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n const int INF = 0x3f3f3f3f; n const int MOD = 1e9 + 7; n const double EPS = 1e-9; n int n, a[100015]; n int main() { n   scanf( %d , &n); n   if (n % 4) { n     printf( ! -1 n ); n     fflush(stdout); n   } else { n     printf( ? %d n , 1); n     fflush(stdout); n     scanf( %d , &a[1]); n     printf( ? %d n , 1 + n / 2); n     fflush(stdout); n     scanf( %d , &a[1 + n / 2]); n     int s, e; n     if (a[1] == a[1 + n / 2]) { n       printf( ! 1 n ); n       fflush(stdout); n       return 0; n     } else { n       if (a[1] < a[1 + n / 2]) { n         s = 1, e = 1 + n / 2; n       } else { n         s = 1 + n / 2, e = 1 + n; n       } n     } n     while (s <= e) { n       int mi = s + e >> 1; n       int x = (mi + n - 1) % n + 1; n       int y = (mi + n + n / 2 - 1) % n + 1; n       printf( ? %d n , x); n       fflush(stdout); n       scanf( %d , &a[x]); n       printf( ? %d n , y); n       fflush(stdout); n       scanf( %d , &a[y]); n       if (a[x] == a[y]) { n         printf( ! %d n , x); n         fflush(stdout); n         return 0; n       } else if (a[x] < a[y]) { n         s = mi + 1; n       } else { n         e = mi - 1; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s, p; n   cin >> s >> p; n   int slen = s.length(), plen = p.length(); n   int max = 0; n   if (plen > slen) { n     int k = slen - 1; n     while (k >= 0) { n       int n = 0; n       for (int i = k; i < slen; i++) { n         if (p[i - k] == s[i]) n++; n       } n       if (n > max) max = n; n       k--; n     } n     k = plen - slen; n     while (k >= 0) { n       int n = 0; n       for (int i = 0; i < slen; i++) { n         if (p[i + k] == s[i]) n++; n       } n       if (n > max) max = n; n       k--; n     } n     k = slen; n     while (k >= 0) { n       int n = 0; n       for (int i = plen - k; i < plen; i++) { n         if (p[i] == s[i - plen + k]) n++; n       } n       if (n > max) max = n; n       k--; n     } n   } else { n     int k = plen; n     while (k >= 0) { n       int n = 0; n       for (int i = k; i < plen; i++) { n         if (s[i - k] == p[i]) n++; n       } n       if (n > max) max = n; n       k--; n     } n     k = slen - plen; n     while (k >= 0) { n       int n = 0; n       for (int i = 0; i < plen; i++) { n         if (s[i + k] == p[i]) n++; n       } n       if (n > max) max = n; n       k--; n     } n     k = plen; n     while (k >= 0) { n       int n = 0; n       for (int i = slen - k; i < slen; i++) { n         if (s[i] == p[i - slen + k]) n++; n       } n       if (n > max) max = n; n       k--; n     } n   } n   int change = plen - max; n   cout << change; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e6 + 5; n const int mod = 51123987; n char s[maxn]; n struct Pam { n   vector<pair<int, int> > next[maxn]; n   int fail[maxn]; n   int len[maxn]; n   int num[maxn]; n   int S[maxn]; n   long long a[maxn], b[maxn]; n   int last, n, p; n   int newNode(int l) { n     next[p].clear(); n     len[p] = l; n     return p++; n   } n   void init() { n     n = last = p = 0; n     newNode(0); n     newNode(-1); n     S[n] = -1; n     fail[0] = 1; n   } n   int getFail(int x) { n     while (S[n - len[x] - 1] != S[n]) { n       x = fail[x]; n     } n     return x; n   } n   int find(int u, int c) { n     vector<pair<int, int> >& x = next[u]; n     int sz = x.size(); n     for (int i = 0; i < sz; ++i) { n       if (x[i].first == c) return x[i].second; n     } n     return 0; n   } n   int add(int c) { n     S[++n] = c; n     int cur = getFail(last); n     int x = find(cur, c); n     if (!x) { n       int now = newNode(len[cur] + 2); n       x = now; n       fail[now] = find(getFail(fail[cur]), c); n       next[cur].push_back(make_pair(c, now)); n       num[now] = num[fail[now]] + 1; n     } n     last = x; n     return num[last]; n   } n   void solve(int len) { n     memset(a, 0, sizeof(a)); n     memset(b, 0, sizeof(b)); n     init(); n     for (int i = 0; i < len; i++) { n       a[i] = add(s[i] -  a ); n     } n     init(); n     for (int i = len - 1; i >= 0; i--) { n       b[i] = (b[i + 1] + add(s[i] -  a )) % mod; n     } n     long long ans = (b[0] * (b[0] - 1) / 2) % mod; n     for (int i = 0; i < len; i++) { n       ans = ((ans - (a[i] * b[i + 1]) + mod) % mod) % mod; n     } n     printf( %lld n , ans); n   } n } pam; n int main() { n   int n; n   while (~scanf( %d , &n)) { n     scanf( %s , s); n     pam.solve(n); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<int> > c; n vector<int> sort_cyclic_shifts(string const& s) { n   int n = s.size(); n   const int alphabet = 256; n   vector<int> p(n), cnt(alphabet, 0); n   c.clear(); n   c.emplace_back(); n   c[0].resize(n); n   for (int i = 0; i < n; i++) cnt[s[i]]++; n   for (int i = 1; i < alphabet; i++) cnt[i] += cnt[i - 1]; n   for (int i = 0; i < n; i++) p[--cnt[s[i]]] = i; n   c[0][p[0]] = 0; n   int classes = 1; n   for (int i = 1; i < n; i++) { n     if (s[p[i]] != s[p[i - 1]]) classes++; n     c[0][p[i]] = classes - 1; n   } n   vector<int> pn(n), cn(n); n   cnt.resize(n); n   for (int h = 0; (1 << h) < n; ++h) { n     for (int i = 0; i < n; i++) { n       pn[i] = p[i] - (1 << h); n       if (pn[i] < 0) pn[i] += n; n     } n     fill(cnt.begin(), cnt.end(), 0); n     for (int i = 0; i < n; i++) cnt[c[h][pn[i]]]++; n     for (int i = 1; i < classes; i++) cnt[i] += cnt[i - 1]; n     for (int i = n - 1; i >= 0; i--) p[--cnt[c[h][pn[i]]]] = pn[i]; n     cn[p[0]] = 0; n     classes = 1; n     for (int i = 1; i < n; i++) { n       pair<int, int> cur = {c[h][p[i]], c[h][(p[i] + (1 << h)) % n]}; n       pair<int, int> prev = {c[h][p[i - 1]], c[h][(p[i - 1] + (1 << h)) % n]}; n       if (cur != prev) ++classes; n       cn[p[i]] = classes - 1; n     } n     c.push_back(cn); n   } n   return p; n } n vector<int> suffix_array_construction(string s) { n   s +=  ! ; n   vector<int> sorted_shifts = sort_cyclic_shifts(s); n   sorted_shifts.erase(sorted_shifts.begin()); n   return sorted_shifts; n } n int compare(int i, int j, int n, int k) { n   pair<int, int> a = {c[k][i], c[k][(i + 1 - (1 << k)) % n]}; n   pair<int, int> b = {c[k][j], c[k][(j + 1 - (1 << k)) % n]}; n   return a == b ? 0 : a < b ? -1 : 1; n } n int lcp(int i, int j) { n   int log_n = c.size() - 1; n   int ans = 0; n   for (int k = log_n; k >= 0; k--) { n     if (c[k][i] == c[k][j]) { n       ans += 1 << k; n       i += 1 << k; n       j += 1 << k; n     } n   } n   return ans; n } n vector<int> lcp_construction(string const& s, vector<int> const& p) { n   int n = s.size(); n   vector<int> rank(n, 0); n   for (int i = 0; i < n; i++) rank[p[i]] = i; n   int k = 0; n   vector<int> lcp(n - 1, 0); n   for (int i = 0; i < n; i++) { n     if (rank[i] == n - 1) { n       k = 0; n       continue; n     } n     int j = p[rank[i] + 1]; n     while (i + k < n && j + k < n && s[i + k] == s[j + k]) k++; n     lcp[rank[i]] = k; n     if (k) k--; n   } n   return lcp; n } n int main() { n   string s; n   cin >> s; n   int K; n   cin >> K; n   int n = s.size(); n   vector<int> p = suffix_array_construction(s); n   vector<int> lcp = lcp_construction(s, p); n   for (int i = 0; i < p.size(); i++) { n     for (int j = 1 + (i > 0 ? lcp[i - 1] : 0); j <= n - p[i]; j++) { n       if (K == 1) { n         cout << s.substr(p[i], j) << endl; n         return 0; n       } n       K--; n       int mn = j; n       for (int x = i + 1; x < p.size(); x++) { n         mn = min(mn, lcp[x - 1]); n         if (mn < j) break; n         if (K == 1) { n           cout << s.substr(p[x], j) << endl; n           return 0; n         } n         K--; n       } n     } n   } n   cout <<  No such line.  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MX = 5e5 + 100, INF = 1e9; n int N, M, X[MX], cnt; n map<int, int> mp; n struct Seg { n   int z; n   int l, r; n   Seg *L, *R; n   void update(int x) { z = min(z, x); } n   void pushdown() { L->update(z), R->update(z); } n   void init(int a, int b); n   void Min(int a, int b, int x); n   int ask(int a); n } T[MX << 1], *Cnt = T; n Seg* New() { return ++Cnt; } n void Seg::init(int a, int b) { n   l = a, r = b, z = INF; n   if (l == r) return; n   int m = (l + r) >> 1; n   L = New(), L->init(l, m); n   R = New(), R->init(m + 1, r); n } n void Seg::Min(int a, int b, int x) { n   if (a <= l && r <= b) { n     update(x); n     return; n   } n   pushdown(); n   if (a <= L->r) L->Min(a, b, x); n   if (b >= R->l) R->Min(a, b, x); n } n int Seg::ask(int a) { n   if (l == r) return z; n   pushdown(); n   if (a <= L->r) n     return L->ask(a); n   else n     return R->ask(a); n } n struct Query { n   int id, l, nx; n } Q[MX]; n int H[MX], qc; n void add(int id, int l, int r) { n   Q[++qc].id = id, Q[qc].l = l, Q[qc].nx = H[r], H[r] = qc; n } n int ans[MX]; n int A[MX]; n void Solve() { n   for (int i = (1); i <= (N); ++i) { n     int c = X[i]; n     if (A[c]) { n       int delta = i - A[c]; n       T->Min(1, A[c], delta); n     } n     A[c] = i; n     for (int j = H[i]; j; j = Q[j].nx) ans[Q[j].id] = T->ask(Q[j].l); n   } n } n int main() { n   scanf( %d%d , &N, &M); n   int x; n   for (int i = (1); i <= (N); ++i) { n     scanf( %d , &x); n     if (!mp.count(x)) mp[x] = ++cnt; n     X[i] = mp[x]; n   } n   T->init(1, N); n   int l, r; n   for (int i = (1); i <= (M); ++i) { n     scanf( %d%d , &l, &r); n     add(i, l, r); n   } n   Solve(); n   for (int i = (1); i <= (M); ++i) n     printf( %d n , (ans[i] == INF ? -1 : ans[i])); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e9 + 7; n const int maxn = 1e5 + 5; n int n, m; n int a[maxn]; n int num[maxn]; n int main() { n   cin >> n; n   long long sum1 = 0; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     sum1 += a[i]; n   } n   num[n] = a[n]; n   long long sum2 = 0; n   for (int i = n - 1; i >= 1; i--) { n     num[i] = max(a[i], num[i + 1] - 1); n   } n   for (int i = 1; i < n; i++) { n     if (num[i] > num[i + 1]) { n       num[i + 1] = num[i]; n     } n   } n   for (int i = 1; i <= n; i++) { n     sum2 += num[i] + 1; n   } n   cout << sum2 - sum1 - n << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[30][30]; n int a, b; n int main() { n   while (~scanf( %d%d , &a, &b)) { n     for (int i = 0; i < a; i++) scanf( %s , s[i]); n     int ss = 0; n     for (int i = 0; i < a; i++) { n       for (int j = 0; j < b; j++) { n         int d = 99999999; n         if (s[i][j] ==  0 ) { n           for (int k = 0; k <= i; k++) { n             if (s[i - k][j] ==  1 ) break; n             int l; n             for (l = 1; l <= j; l++) { n               if (s[i - k][j - l] ==  1 ) break; n             } n             d = min(d, l); n             ss = max(ss, d * 2 + (k + 1) * 2); n           } n         } n       } n     } n     printf( %d n , ss); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 7010; n map<long long, int> cnt; n int n; n long long ar[N], br[N]; n bitset<N> bit[N]; n bitset<N> res; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> ar[i]; n     cnt[ar[i]]++; n   } n   for (int i = 1; i <= n; i++) { n     cin >> br[i]; n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       if ((ar[i] | ar[j]) == ar[i]) { n         bit[i][j] = 1; n       } else { n         bit[i][j] = 0; n       } n     } n   } n   for (int i = 1; i <= n; i++) { n     if (cnt[ar[i]] >= 2) { n       res = (res | bit[i]); n     } n   } n   long long ans = 0; n   for (int i = 1; i <= n; i++) { n     if (res[i]) { n       ans += br[i]; n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s; n int n, ans = 0; n vector<pair<int, int>> b; n vector<int> a(26); n int main() { n   cin >> s >> n; n   for (int i = 0; i < s.length(); ++i) { n     a[s[i] -  a ]++; n   } n   for (int i = 0; i < 26; ++i) { n     b.push_back(make_pair(a[i], i)); n   } n   sort(b.begin(), b.end()); n   for (int i = 0; i < 26; ++i) { n     if (n >= b[i].first) { n       n -= b[i].first; n       b[i].first = 0; n     } n   } n   for (int i = 0; i < 26; ++i) { n     if (b[i].first != 0) ans++; n   } n   cout << ans << endl; n   for (int i = 0; i < s.length(); ++i) { n     for (int j = 0; j < 26; ++j) { n       if (s[i] -  a  == b[j].second && b[j].first > 0) { n         cout << s[i]; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5e3 + 5; n struct node { n   int op; n   int l; n   int r; n   int d; n } cmd[maxn]; n ; n int a[maxn]; n int b[maxn]; n int main() { n   ios::sync_with_stdio(0); n   int n, m; n   cin >> n >> m; n   for (int i = 1; i <= m; i++) n     cin >> cmd[i].op >> cmd[i].l >> cmd[i].r >> cmd[i].d; n   for (int i = 1; i <= n; i++) a[i] = 100000000; n   for (int i = 1; i <= m; i++) { n     if (cmd[i].op == 1) { n       for (int j = cmd[i].l; j <= cmd[i].r; j++) b[j] += cmd[i].d; n     } else { n       for (int j = cmd[i].l; j <= cmd[i].r; j++) { n         a[j] = min(a[j], cmd[i].d - b[j]); n       } n     } n   } n   for (int i = 1; i <= n; i++) b[i] = a[i]; n   for (int i = 1; i <= m; i++) { n     if (cmd[i].op == 1) { n       for (int j = cmd[i].l; j <= cmd[i].r; j++) b[j] += cmd[i].d; n     } else { n       int flag = INT_MIN; n       for (int j = cmd[i].l; j <= cmd[i].r; j++) flag = max(flag, b[j]); n       if (flag != cmd[i].d) { n         cout <<  NO ; n         return 0; n       } n     } n   } n   cout <<  YES  << endl; n   for (int i = 1; i <= n; i++) cout << a[i] <<    ; n   return 0; n } n


/* n Creater :  n     ANSHUMAN MISHRA n  All Losses In this World Are Due To Lack Of Ability. n If You Want To Curse Someone , Curse Your Own Weakness  n */ n  n  n #include <bits/stdc++.h> n using namespace std; n  n #define ll long long n #define pii pair<int,int> n #define yes cout<< YES n  n #define no cout<< NO n  n  n const int N=1e5+5; n int cnt[26][N]; n  n signed main(){ n     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); n     #ifndef ONLINE_JUDGE n         freopen( in.txt , r ,stdin); n     #endif n  n     int t=1;cin>>t; n     while(t--){ n         int n,m; n         cin>>n>>m; n         for (int i=0;i<m;++i) for (int j=0;j<26;++j) cnt[j][i]=0; n  n         string s; n         for (int i=0;i<n;++i){ n             cin>>s; n             for (int j=0;j<m;++j) n                 cnt[s[j]- a ][j]++; n         } n         /* n         for (int i=0;i<m;++i){ n             for (int j=0;j<26;++j){ n                 /* n                 if (cnt[j][i]==1){ n                     ans+= (j+ a ); n                     break; n                 } n                 cout<<cnt[j][i]<<   ; n             } n             cout<<  n ; n         }*/ n  n         for (int i=0;i<n-1;++i){ n             cin>>s; n             for (int j=0;j<m;++j) n                 cnt[s[j]- a ][j]--; n         } n  n          n  n         string ans=  ; n         for (int i=0;i<m;++i){ n             for (int j=0;j<26;++j){ n                  n                 if (cnt[j][i]==1){ n                     ans+= (j+ a ); n                     break; n                 } n                 //cout<<cnt[j][i]<<   ; n             } n             //cout<<  n ; n         } n         cout<<ans<<endl; n         cout.flush(); n  n     } n  n  n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int a[1010], b[1010]; n bool vis[1010]; n int main() { n   int n, i, ans, nn, lb; n   scanf( %d , &n); n   for (i = 1; i <= n; i++) scanf( %d , &a[i]); n   sort(a + 1, a + n + 1); n   memset(vis, false, sizeof(vis)); n   ans = 0; n   nn = 0; n   while (1) { n     lb = 0; n     b[0] = 0; n     for (i = 1; i <= n; i++) n       if (vis[i] == false && a[i] > b[lb]) { n         b[++lb] = a[i]; n         vis[i] = true; n         nn++; n       } n     ans += (lb - 1); n     if (nn == n) break; n   } n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(2) n using namespace std; n const int INF = 0x3f3f3f3f; n const int maxn = 100010; n inline int read() { n   int x = 0, f = 1; n   char ch = 0; n   while (!isdigit(ch)) { n     ch = getchar(); n     if (ch ==  - ) f = -1; n   } n   while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); n   return x * f; n } n int n, m; n int a[maxn], b[maxn], low[maxn], pre[maxn], f[maxn], la[maxn]; n int gap[maxn]; n void work() { n   memset(low, 63, sizeof(low)); n   pre[1] = low[1] = 0, f[1] = la[1] = 1; n   for (int k = 2; k <= n; ++k) { n     if (a[k] + 1) { n       int L = 1, R = n; n       while (L <= R) { n         int mid = (L + R) >> 1; n         if (low[mid] < a[k]) n           L = mid + 1; n         else n           R = mid - 1; n       } n       pre[k] = la[L - 1]; n       la[L] = k; n       f[k] = L, low[L] = a[k]; n     } else { n       pre[k] = -1, f[k] = -1; n       int j = n; n       for (int i = m; i >= 1; i--) { n         while (low[j] >= b[i]) j--; n         low[j + 1] = b[i], la[j + 1] = -1; n       } n     } n   } n } n void work2() { n   int L, R, rem = m; n   int x = n; n   while (x) n     if (a[x] + 1) { n       if (pre[x] >= 0) { n         x = pre[x]; n         continue; n       } n       R = lower_bound(b + 1, b + rem + 1, a[x]) - b - 1; n       for (int y = x - 1; y != 0; y--) { n         if (a[y] == -1 || a[y] >= a[x]) continue; n         L = upper_bound(b + 1, b + rem + 1, a[y]) - b; n         if (f[x] - f[y] - 1 == min(R - L + 1, gap[x] - gap[y])) { n           for (int i = y, j = L; i <= x && j <= R; i++) n             if (a[i] == -1) a[i] = b[j], b[j] = -1, j++; n           x = y; n           rem = L - 1; n           break; n         } n       } n     } n   for (int i = 1, j = 1; i <= n; ++i) { n     if (a[i] + 1) continue; n     while (b[j] == -1) ++j; n     a[i] = b[j]; n     b[j++] = -1; n   } n } n int main() { n   n = read(); n   a[1] = 0; n   a[n + 2] = INF; n   for (int i = 2; i <= n + 1; ++i) n     a[i] = read(), gap[i] = gap[i - 1] + (a[i] == -1); n   m = read(); n   gap[n + 2] = gap[n + 1]; n   n += 2; n   for (int i = 1; i <= m; ++i) b[i] = read(); n   sort(b + 1, b + m + 1); n   m = unique(b + 1, b + m + 1) - b - 1; n   work(); n   work2(); n   for (int i = 2; i < n; ++i) printf( %d  , a[i]); n } n


#include <bits/stdc++.h> n using namespace std; n long long t, n, m; n int a[200003]; n pair<int, int> p[200003]; n int main() { n   cin >> t; n   while (t--) { n     cin >> n; n     for (int i = 1; i <= n; ++i) { n       cin >> a[i]; n     } n     long long re = 0; n     for (int i = 1; i <= n;) { n       int val = a[i], j; n       for (j = i; j <= n && 1ll * a[j] * a[i] > 0; ++j) val = max(val, a[j]); n       re += val; n       i = j; n     } n     cout << re <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, a, cf, cm, m; n   cin >> n >> a >> cf >> cm >> m; n   vector<vector<long long> > stat(n, vector<long long>(2)); n   for (int i = 0; i < n; i++) { n     cin >> stat[i][0]; n     stat[i][1] = i; n   } n   stable_sort(stat.begin(), stat.end()); n   vector<long long> mi(n); n   mi[0] = 0; n   for (int i = 1; i < n; i++) { n     mi[i] = (stat[i][0] - stat[i - 1][0]) * i + mi[i - 1]; n   } n   vector<long long> ma(n); n   ma[n - 1] = a - stat[n - 1][0]; n   for (int i = n - 2; i >= 0; i--) { n     ma[i] = ma[i + 1] + a - stat[i][0]; n   } n   if (ma[0] <= m) { n     cout << n * cf + a * cm << endl; n     for (int i = 0; i < n; i++) { n       cout << a <<    ; n     } n     return 0; n   } n   long long otv = 0; n   long long votv = -1; n   long long mn = 0; n   long long mn1 = 0; n   if (mi[n - 1] > m) { n     for (int i = n - 1; i >= 0; i--) { n       if (mi[i] <= m) { n         otv = (stat[i][0] + (m - mi[i]) / (i + 1)) * cm; n         mn = i; n         mn1 = (stat[i][0] + (m - mi[i]) / (i + 1)); n         votv = otv; n         break; n       } n     } n   } n   if (mi[n - 1] <= m) otv = (stat[n - 1][0] + (m - mi[n - 1]) / n) * cm; n   for (int i = n - 1; i >= 0; i--) { n     if (m - ma[i] >= 0) { n       int nom = upper_bound(mi.begin(), mi.end(), m - ma[i]) - mi.begin(); n       if (nom >= n || m - ma[i] < mi[nom]) nom--; n       if (nom >= i) { n         long long h = n             (n - i) * cf + (stat[i][0] + (m - mi[i] - ma[i]) / i) * cm; n         otv = max(otv, n                   (n - i) * cf + (stat[i][0] + (m - mi[i] - ma[i]) / i) * cm); n       } else { n         long long h = (stat[nom][0] + (m - mi[nom] - ma[i]) / (nom + 1)) * cm + n                       (n - i) * cf; n         otv = max(otv, (stat[nom][0] + (m - mi[nom] - ma[i]) / (nom + 1)) * cm + n                            (n - i) * cf); n       } n     } n   } n   if (votv == otv) { n     cout << otv << endl; n     for (int i = 0; i < n; i++) { n       if (i <= mn) stat[i][0] = mn1; n     } n     for (int i = 0; i < n; i++) { n       swap(stat[i][0], stat[i][1]); n     } n     stable_sort(stat.begin(), stat.end()); n     for (int i = 0; i < n; i++) { n       cout << stat[i][1] <<    ; n     } n     return 0; n   } n   if (otv == (stat[n - 1][0] + (m - mi[n - 1]) / n) * cm) { n     cout << otv << endl; n     for (int i = 0; i < n; i++) { n       cout << stat[n - 1][0] + (m - mi[n - 1]) / n <<    ; n     } n     return 0; n   } n   long long otv1 = 0; n   if (mi[n - 1] <= m) otv1 = stat[n - 1][0] * cm; n   for (int i = n - 1; i >= 0; i--) { n     if (m - ma[i] >= 0) { n       int nom = upper_bound(mi.begin(), mi.end(), m - ma[i]) - mi.begin(); n       if (nom >= n || m - ma[i] < mi[nom]) nom--; n       if (nom >= i) { n         otv1 = max(otv1, n                    (n - i) * cf + (stat[i][0] + (m - mi[i] - ma[i]) / i) * cm); n         if (otv1 == otv) { n           for (int j = 0; j < n; j++) { n             if (j < i) n               stat[j][0] = stat[i][0] + (m - mi[i] - ma[i]) / i; n             else n               stat[j][0] = a; n           } n           break; n         } n       } else { n         otv1 = n             max(otv1, (stat[nom][0] + (m - mi[nom] - ma[i]) / (nom + 1)) * cm + n                           (n - i) * cf); n         if (otv1 == otv) { n           for (int j = 0; j < n; j++) { n             if (j <= nom) n               stat[j][0] = stat[nom][0] + (m - mi[nom] - ma[i]) / (nom + 1); n             if (j >= i) stat[j][0] = a; n           } n           break; n         } n       } n     } n   } n   for (int i = 0; i < n; i++) { n     swap(stat[i][0], stat[i][1]); n   } n   stable_sort(stat.begin(), stat.end()); n   cout << otv << endl; n   for (int i = 0; i < n; i++) { n     cout << stat[i][1] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string s; n   set<string> s0; n   for (int i = 0; i < n; i++) { n     cin >> s; n     unordered_set<char> s1; n     s.erase(remove_if(s.begin(), s.end(), n                       [&](char const c) { return !(s1.insert(c).second); }), n             s.end()); n     sort(s.begin(), s.end()); n     s0.insert(s); n   } n   cout << s0.size() << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #define intt long long int n #define F first  n #define S second n #define pb push_back n  n int main() n { n     int n;cin>>n; n     int arr[n+1]; n      n     vector<int> pos; n     pos.pb(-1); n  n     for(int i=1;i<=n;i++) {cin>>arr[i];if(arr[i]==1) pos.pb(i); } n     int m=pos.size()-1; // no. of 1s n  n     int dp[n][m+1]; // dp[][]== ith posn tak use karke , pehle j 1 s ko shift karna hai . n  n     for(int i=0;i<=n;i++)dp[i][0]=0; n     for(int i=1;i<=m;i++) dp[0][i]=1e9; n  n     for(int i=1;i<=n;i++) n     { n         for(int j=1;j<=m;j++) n         {    n             if(arr[i]==1) n             dp[i][j]=dp[i-1][j]; n             else  n             dp[i][j]=min(dp[i-1][j],dp[i-1][j-1]+abs(pos[j]-i)); n         } n     } n     cout<<dp[n][m]<<endl; n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 7; n string t[6] = { lios ,  liala ,  etr ,  etra ,  initis ,  inites }; n bool mark[3]; n int md = -1; n int typ(string s) { n   for (int i = 0; i < 6; i++) n     if (t[i].size() <= s.size()) { n       bool flag = true; n       for (int j = 0; j < t[i].size(); j++) n         if (t[i][j] != s[s.size() - t[i].size() + j]) flag = false; n       if (flag) return i; n     } n   return -1; n } n int main() { n   ios::sync_with_stdio(false); n   string s; n   bool flag = true; n   bool x = false; n   int cnt = 0; n   while (cin >> s) { n     cnt++; n     int p = typ(s); n     if (p == -1) n       flag = false, x = true; n     else if (md != -1 && p % 2 != md) n       flag = false; n     else if (p / 2 == 0 && (mark[1] || mark[2])) n       flag = false; n     else if (p / 2 == 1 && (mark[1] || mark[2])) n       flag = false; n     else if (p / 2 == 2 && !mark[1]) n       flag = false; n     if (flag) { n       md = p % 2; n       mark[p / 2] = true; n     } n   } n   if ((!mark[1] && cnt > 1) || x || (cnt > 1 && !flag)) { n     cout <<  NO n ; n     return 0; n   } n   cout <<  YES n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long INF = 1LL << 60; n long long MOD = 1e9 + 7; n namespace output { n void pr(short x) { cout << x; } n void pr(signed x) { cout << x; } n void pr(long x) { cout << x; } n void pr(long long x) { cout << x; } n void pr(unsigned short x) { cout << x; } n void pr(unsigned x) { cout << x; } n void pr(unsigned long x) { cout << x; } n void pr(unsigned long long x) { cout << x; } n void pr(float x) { cout << x; } n void pr(double x) { cout << x; } n void pr(long double x) { cout << x; } n void pr(char x) { cout << x; } n void pr(const char* x) { cout << x; } n void pr(const string& x) { cout << x; } n void pr(bool x) { cout << x; } n template <size_t sz> n void pr(const bitset<sz>& x) { n   cout << x; n } n template <class T> n void pr(const complex<T>& x) { n   cout << x; n } n template <class T1, class T2> n void pr(const pair<T1, T2>& x); n template <class T1, class T2, class T3> n void pr(const tuple<T1, T2, T3>& x); n template <class T> n void pr(const T& x); n template <class T, class... Ts> n void pr(const T& t, const Ts&... ts) { n   pr(t); n   pr(ts...); n } n template <class T1, class T2> n void pr(const pair<T1, T2>& x) { n   pr( ( , x.first,  ,  , x.second,  ) ); n } n template <class T1, class T2, class T3> n void pr(const tuple<T1, T2, T3>& x) { n   pr( ( , get<0>(x),  ,  , get<1>(x),  ,  , get<2>(x),  ) ); n } n template <class T> n void pr(const T& x) { n   pr( [ ); n   bool fst = 1; n   for (const auto& a : x) pr(!fst ?  ,   :   , a), fst = 0; n   pr( ] ); n } n void print() { pr(  n ); } n template <class T, class... Ts> n void print(const T& t, const Ts&... ts) { n   pr(t); n   if (sizeof...(ts)) pr(   ); n   print(ts...); n } n }  // namespace output n using namespace output; n template <class T1, class T2> n istream& operator>>(istream& is, pair<T1, T2>& x) { n   is >> x.first >> x.second; n   return is; n } n template <class T1, class T2, class T3> n istream& operator>>(istream& is, tuple<T1, T2, T3>& x) { n   is >> get<0>(x) >> get<1>(x) >> get<2>(x); n   return is; n } n template <class T> n istream& operator>>(istream& is, vector<T>& v) { n   for (auto& x : v) is >> x; n   return is; n } n long long powa(long long base, long long exp) { n   long long res = 1; n   while (exp) { n     if (exp & 1) res = res * base % MOD; n     base = base * base % MOD; n     exp >>= 1; n   } n   return res; n } n bool mini(long long& a, long long b) { return b < a ? a = b, 1 : 0; } n bool maxi(long long& a, long long b) { return b > a ? a = b, 1 : 0; } n signed main() { n   ios::sync_with_stdio(0), cin.tie(0); n   vector<vector<long long> > silly = {{1, 2, 4}, {5, 3, 8}, {9, 6, 7}}; n   long long n; n   cin >> n; n   if (n <= 2) n     print(-1); n   else { n     vector<vector<long long> > grid(n, vector<long long>(n)); n     long long cnt = 1; n     bool vert = false; n     for (long long(i) = (n - 1); (i) > (2); --(i)) { n       if (!vert) { n         for (long long(j) = (0); (j) < (i + 1); ++(j)) grid[i][j] = cnt++; n         for (long long(j) = (i - 1); (j) > (-1); --(j)) grid[j][i] = cnt++; n       } else { n         for (long long(j) = (0); (j) < (i + 1); ++(j)) grid[j][i] = cnt++; n         for (long long(j) = (i - 1); (j) > (-1); --(j)) grid[i][j] = cnt++; n       } n       vert = !vert; n     } n     for (long long(i) = (0); (i) < (3); ++(i)) n       for (long long(j) = (0); (j) < (3); ++(j)) n         grid[i][j] = silly[i][j] + cnt - 1; n     for (long long(i) = (0); (i) < (n); ++(i)) { n       for (long long(j) = (0); (j) < (n); ++(j)) cout << grid[i][j] <<    ; n       cout <<   n ; n     } n   } n } n


#include<bits/stdc++.h> n using namespace std; n typedef long long ll; n typedef long double ld; n #define rep(a, b) for(ll a = 0; a < (b); ++a) n #define pb push_back n #define st first n #define nd second n #define all(a) a.begin(), a.end() n #define lg(a) (31-__builtin_clz(a)) n void solve() { n         int n; n         cin >> n; n         ll T[n]; n         rep(i, n) cin >> T[i]; n         sort(T, T+n); n         ll ans=0, odejmij=0; n         rep(i, n-1) ans+=T[i+1]-T[i]; n         rep(i, n) { n                 ans-=i*T[i]-odejmij; n                 odejmij+=T[i]; n         } n         cout << ans <<   n ; n } n int main() { n         ios_base::sync_with_stdio(0); cin.tie(0); n         int _=1; n         cin >> _; n         while(_--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int c = 1, mx = 0; n   string s; n   cin >> s; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] !=  A  && s[i] !=  O  && s[i] !=  I  && s[i] !=  U  && n         s[i] !=  Y  && s[i] !=  E ) { n       c++; n     } else { n       if (c > mx) mx = c; n       c = 1; n     } n   } n   if (c > mx) mx = c; n   cout << mx; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, s, i, a[1003], res, x; n int main() { n   cin >> n >> x; n   for (i = 1; i <= n; i++) { n     cin >> a[i]; n     s += a[i]; n   } n   if (s <= 0) s *= (-1); n   res = s / x; n   if (s % x > 0) res++; n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n struct node { n   int s, r, no; n } xx[500001], dance[500001], fire[500001]; n bool cmp(node x, node y) { return x.s > y.s || (x.s == y.s && x.r > y.r); } n int S[500001]; n int ans[500001]; n int mal = 0; n int k; n int q; n bool yes[500001]; n double eps = 1e-6; n int h, t; n map<int, int> X; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> xx[i].s >> xx[i].r; n   for (int i = 1; i <= n; i++) xx[i].no = i; n   sort(xx + 1, xx + n + 1, cmp); n   for (int i = 1; i <= n; i++) { n     if (mal > xx[i].r) continue; n     if (mal == xx[i].r && q == xx[i].s) { n       dance[++k] = xx[i]; n       continue; n     } n     if (q == xx[i].s) continue; n     if (mal == xx[i].r) continue; n     { n       dance[++k] = xx[i]; n       mal = xx[i].r; n       q = xx[i].s; n     } n   } n   h = 1; n   fire[++t] = dance[1]; n   for (int i = 2; i <= k; i++) { n     if (h <= t && dance[i].r <= fire[t].r) continue; n     while (h < t) { n       long long s1 = fire[t - 1].s, s2 = fire[t].s, r1 = fire[t - 1].r, n                 r2 = fire[t].r; n       long long s3 = dance[i].s, r3 = dance[i].r; n       long long k1 = (s3 - s2) * (r1 - r2) * r3 * s1; n       long long k2 = (s1 - s2) * (r3 - r2) * r1 * s3; n       if (k1 < k2) n         t--; n       else n         break; n     } n     fire[++t] = dance[i]; n   } n   int xxx = 0; n   for (int i = 1; i <= t; i++) { n     X[fire[i].s] = fire[i].r; n   } n   for (int i = 1; i <= n; i++) { n     if (X[xx[i].s] == xx[i].r) ans[++xxx] = xx[i].no; n   } n   sort(ans + 1, ans + xxx + 1); n   for (int i = 1; i <= xxx; i++) cout << ans[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k; n const int maxn = 2e5 + 10; n template <class T> n inline T read() { n   int f = 1; n   T ret = 0; n   char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) { n     ret = (ret << 1) + (ret << 3) + ch -  0 ; n     ch = getchar(); n   } n   ret *= f; n   return ret; n } n template <class T> n inline void write(T n) { n   if (n < 0) { n     putchar( - ); n     n = -n; n   } n   if (n >= 10) { n     write(n / 10); n   } n   putchar(n % 10 +  0 ); n } n template <class T> n inline void writeln(const T &n) { n   write(n); n   puts(  ); n } n template <typename T> n void _write(const T &t) { n   write(t); n } n template <typename T, typename... Args> n void _write(const T &t, Args... args) { n   write(t), putchar(   ); n   _write(args...); n } n template <typename T, typename... Args> n inline void write_line(const T &t, const Args &...data) { n   _write(t, data...); n } n char s[maxn]; n int pre, last; n int r, l; n int main(int argc, char const *argv[]) { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   cin >> n; n   cin >> s + 1; n   for (int i = 1; i <= n / 2; i++) n     if (s[i] ==  ? ) n       ++l; n     else n       pre += s[i] -  0 ; n   for (int i = n / 2 + 1; i <= n; i++) n     if (s[i] ==  ? ) n       ++r; n     else n       last += s[i] -  0 ; n   if (pre == last) { n     if (l == r) n       cout <<  Bicarp n ; n     else n       cout <<  Monocarp n ; n     return 0; n   } else { n     if (pre > last) swap(pre, last), swap(l, r); n     if (l <= r) n       cout <<  Monocarp n ; n     else { n       int left = last - pre; n       l -= r; n       l /= 2; n       if (l * 9 == left) n         cout <<  Bicarp n ; n       else n         cout <<  Monocarp n ; n     } n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   int n, m; n   pair<int, int> tl = {-100, -100}, br = {-100, -100}; n   cin >> n >> m; n   char paper[n][m]; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> paper[i][j]; n       if (paper[i][j] ==  *  && (tl.first == -100 && tl.second == -100)) n         tl = {i, j}; n       else if (j < tl.second && paper[i][j] ==  * ) n         tl = {tl.first, j}; n       if (paper[i][j] ==  *  && (i >= br.first && j > br.second)) n         br = {i, j}; n       else if (paper[i][j] ==  *  && (i > br.first)) n         br = {i, br.second}; n       else if (paper[i][j] ==  *  && (j > br.second)) n         br = {br.first, j}; n     } n   } n   for (int i = tl.first; i <= br.first; i++) { n     for (int j = tl.second; j <= br.second; j++) { n       cout << paper[i][j]; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 200010; n const int maxv = 1000000010; n int a[maxn]; n int l[maxn], r[maxn]; n int rj[maxn]; n stack<int> s; n int main() { n   int n; n   cin >> n; n   a[0] = 0; n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   a[n + 1] = 0; n   s.push(0); n   for (int i = 1; i < n + 1; i++) { n     while (a[s.top()] >= a[i]) s.pop(); n     l[i] = s.top(); n     s.push(i); n   } n   while (s.size()) s.pop(); n   s.push(n + 1); n   for (int i = n; i > 0; i--) { n     while (a[s.top()] >= a[i]) s.pop(); n     r[i] = s.top(); n     s.push(i); n   } n   for (int i = 1; i <= n; i++) n     rj[r[i] - l[i] - 1] = max(rj[r[i] - l[i] - 1], a[i]); n   int val = 0; n   for (int i = n; i > 0; i--) { n     val = max(val, rj[i]); n     rj[i] = val; n   } n   for (int i = 1; i <= n; i++) printf( %d  , rj[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 5; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     long long a[n], b[n]; n     long long m = INT_MAX; n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n       b[i] = a[i]; n       m = min(m, a[i]); n     } n     sort(b, b + n); n     long long flag = 0; n     for (int i = 0; i < n; i++) n       if (a[i] != b[i] && a[i] % m > 0) flag = 1; n     if (flag) n       cout <<  NO  << endl; n     else n       cout <<  YES  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Point { n   int x; n   int y; n }; n bool onSegment(Point p, Point q, Point r) { n   if (q.x <= max(p.x, r.x) && q.x >= min(p.x, r.x) && q.y <= max(p.y, r.y) && n       q.y >= min(p.y, r.y)) n     return true; n   return false; n } n int orientation(Point p, Point q, Point r) { n   int val = (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y); n   if (val == 0) return 0; n   return (val > 0) ? 1 : 2; n } n bool doIntersect(Point p1, Point q1, Point p2, Point q2) { n   int o1 = orientation(p1, q1, p2); n   int o2 = orientation(p1, q1, q2); n   int o3 = orientation(p2, q2, p1); n   int o4 = orientation(p2, q2, q1); n   if (o1 != o2 && o3 != o4) return true; n   if (o1 == 0 && onSegment(p1, p2, q1)) return true; n   if (o2 == 0 && onSegment(p1, q2, q1)) return true; n   if (o3 == 0 && onSegment(p2, p1, q2)) return true; n   if (o4 == 0 && onSegment(p2, q1, q2)) return true; n   return false; n } n bool isInside(Point polygon[], int n, Point p) { n   if (n < 3) return false; n   Point extreme = {10000, p.y}; n   int count = 0, i = 0; n   do { n     int next = (i + 1) % n; n     if (doIntersect(polygon[i], polygon[next], p, extreme)) { n       if (orientation(polygon[i], p, polygon[next]) == 0) n         return onSegment(polygon[i], p, polygon[next]); n       count++; n     } n     i = next; n   } while (i != 0); n   return count & 1; n } n int main() { n   Point s1[4]; n   Point s2[4]; n   for (__typeof(0) i = 0; i <= 3; i++) cin >> s1[i].x >> s1[i].y; n   for (__typeof(0) i = 0; i <= 3; i++) cin >> s2[i].x >> s2[i].y; n   for (__typeof(0) i = 0; i <= 3; i++) { n     for (__typeof(0) j = 0; j <= 3; j++) { n       if (doIntersect(s1[i], s1[(i + 1) % 4], s2[j], s2[(j + 1) % 4])) { n         cout <<  YES n ; n         return 0; n       } n     } n   } n   if (isInside(s1, 4, s2[0]) || isInside(s2, 4, s1[0])) n     cout <<  YES n ; n   else n     cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int d[105], n, sum1 = 0, sum2 = 0, begin, end; n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> d[i]; n   cin >> begin >> end; n   if (begin > end) { n     int t; n     t = begin; n     begin = end; n     end = t; n   } n   for (int i = begin; i < end; i++) sum1 += d[i]; n   for (int i = end; i != begin; i++) { n     sum2 += d[i]; n     if (i >= n) i = 0; n   } n   sum1 = sum1 > sum2 ? sum2 : sum1; n   cout << sum1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MX = 1e5 + 5; n struct Edge { n   int v, nxt; n } E[MX * 2]; n int Head[MX], erear; n void edge_init() { n   erear = 0; n   memset(Head, -1, sizeof(Head)); n } n void edge_add(int u, int v) { n   E[erear].v = v; n   E[erear].nxt = Head[u]; n   Head[u] = erear++; n } n int siz[MX]; n double ans[MX]; n void DFS1(int u, int f) { n   siz[u] = 1; n   for (int i = Head[u]; ~i; i = E[i].nxt) { n     int v = E[i].v; n     if (v == f) continue; n     DFS1(v, u); n     siz[u] += siz[v]; n   } n } n void DFS2(int u, int f) { n   for (int i = Head[u]; ~i; i = E[i].nxt) { n     int v = E[i].v; n     if (v == f) continue; n     ans[v] = ans[u] + 1 + (siz[u] - siz[v] - 1) / 2.0; n     DFS2(v, u); n   } n } n int main() { n   int n; n   edge_init(); n   scanf( %d , &n); n   for (int i = 2; i <= n; i++) { n     int t; n     scanf( %d , &t); n     edge_add(i, t); n     edge_add(t, i); n   } n   ans[1] = 1; n   DFS1(1, -1); n   DFS2(1, -1); n   for (int i = 1; i <= n; i++) { n     printf( %.8lf%c , ans[i], i == n ?   n  :    ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int test; n int n, k; n string s; n int tipus[200009]; n int darab[3]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> test; n   for (int tt = 1; tt <= test; tt++) { n     cin >> n; n     int minx = -100000; n     int maxx = 100000; n     int miny = -100000; n     int maxy = 100000; n     for (int i = 1; i <= n; i++) { n       int x, y; n       int a, b, c, d; n       cin >> x >> y >> a >> b >> c >> d; n       if (a == 0) minx = max(minx, x); n       if (b == 0) maxy = min(maxy, y); n       if (c == 0) maxx = min(maxx, x); n       if (d == 0) miny = max(miny, y); n     } n     if (minx <= maxx && miny <= maxy) { n       cout << 1 <<     << minx <<     << miny << endl; n     } else { n       cout << 0 << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long n2(int n) { return (n * 1ll * (n + 1)) / 2; } n const int N = 2e5; n vector<int> f(N + 1); n long long get(int pos) { n   long long res = 0; n   for (; pos >= 0; pos = (pos & (pos + 1)) - 1) res += f[pos]; n   return res; n } n long long get(int l, int r) { return get(r) - (l ? get(l - 1) : 0); } n void update(int pos, int val) { n   for (; pos < int(f.size()); pos |= pos + 1) f[pos] += val; n } n void solve() { n   int n; n   cin >> n; n   map<int, vector<int> > My; n   map<int, int> cntx; n   vector<int> indComp(n); n   for (int i = 0; i < n; ++i) { n     int x, y; n     cin >> x >> y; n     indComp[i] = x; n     cntx[x]++; n     My[y].push_back(x); n   } n   sort(indComp.begin(), indComp.end()); n   indComp.resize(unique(indComp.begin(), indComp.end()) - indComp.begin()); n   for (pair<int, int> p : cntx) { n     int i = n         lower_bound(indComp.begin(), indComp.end(), p.first) - indComp.begin(); n     update(i, 1); n   } n   long long ans = 0; n   for (auto &vp : My) { n     sort(vp.second.begin(), vp.second.end()); n     int lst = -1; n     for (int x : vp.second) { n       int i = lower_bound(indComp.begin(), indComp.end(), x) - indComp.begin(); n       int l = get(lst + 1, i); n       int r = get(i, N); n       ans += l * 1ll * r; n       lst = i; n       cntx[x]--; n       if (cntx[x] == 0) update(i, -1); n     } n   } n   cout << ans << endl; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int T = 1, tc = 1; n   while (T--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n class Graph { n  public: n   vector<vector<int>> a; n   vector<int> vis; n   int N, M; n   int n; n   int R(int i) { return i; } n   int C(int i) { return i + N; } n   void addEdge(int l, int r) { n     a[R(l)].push_back(C(r)); n     a[C(r)].push_back(R(l)); n   } n   Graph() { n     cin >> N >> M; n     n = N + M; n     a.assign(n, vector<int>()); n     vis.assign(n, 0); n     for (int i = 0; i < int(N); i++) { n       cin.get(); n       for (int j = 0; j < int(M); j++) { n         char c = cin.get(); n         if (c ==  . ) continue; n         addEdge(i, j); n       } n     } n   } n   bool dfs(int v, set<int> &r, set<int> &c) { n     vis[v] = 1; n     if (v < N && a[v].size() != c.size()) return 0; n     if (v >= N && a[v].size() != r.size()) return 0; n     for (int to : a[v]) { n       if (!vis[to] && !dfs(to, r, c)) return 0; n       if (v < N && !c.count(to)) return 0; n       if (v >= N && !r.count(to)) return 0; n     } n     return 1; n   } n   bool isCompleteBipariate(int v) { n     if (a[v].empty()) return 1; n     set<int> c((a[v]).begin(), (a[v]).end()); n     set<int> r((a[a[v][0]]).begin(), (a[a[v][0]]).end()); n     return dfs(v, r, c); n   } n   void solve() { n     for (int i = 0; i < int(N); i++) n       if (!vis[i] && !isCompleteBipariate(i)) { n         cout <<  No  << endl; n         return; n       } n     cout <<  Yes  << endl; n   } n }; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   Graph g; n   g.solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxs = 405; n const int inf = 1e9 + 7; n int dp[maxs][maxs]; n string s, t, x, y; n int slen, tlen; n int nxt[maxs][26]; n int g(int x) { return x + 1; } n int f(int a, int b) { n   if (a == -1 && b == -1) return 0; n   if (a < -1 || b < -1) return inf; n   int& r = dp[g(a)][g(b)]; n   if (r == -1) { n     r = inf; n     int idx; n     if (a >= 0) { n       idx = f(a - 1, b); n       if (idx < inf) r = min(r, nxt[idx][x[a] -  a ] + 1); n     } n     if (b >= 0) { n       idx = f(a, b - 1); n       if (idx < inf) r = min(r, nxt[idx][y[b] -  a ] + 1); n     } n   } n   return r; n } n int main(void) { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int T; n   cin >> T; n   while (T--) { n     cin >> s >> t; n     int i = 0, j = 0; n     slen = s.size(), tlen = t.size(); n     while (i < slen && j < tlen) { n       if (s[i] == t[j]) ++j; n       ++i; n     } n     if (j == tlen) { n       cout <<  YES n ; n       continue; n     } n     for (int i = 0; i <= slen; ++i) n       for (int j = 0; j < 26; ++j) nxt[i][j] = inf; n     for (int i = slen - 1; i >= 0; --i) { n       for (int j = 0; j < 26; ++j) nxt[i][j] = nxt[i + 1][j]; n       nxt[i][s[i] -  a ] = i; n     } n     bool yes = false; n     for (int i = 1; i < tlen; ++i) { n       for (int j = 0; j <= tlen; ++j) n         for (int k = 0; k <= tlen; ++k) dp[j][k] = -1; n       x = t.substr(0, i); n       y = t.substr(i, tlen - i); n       if (f(i - 1, tlen - i - 1) < inf) { n         yes = true; n         break; n       } n     } n     cout << (yes ?  YES n  :  NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:100000000000,100000000000 ) n using namespace std; n const double eps = 1E-9; n const double Exp = 2.718281828459045; n const double Pi = 3.1415926535897932; n const int NMAX = 100 + 5; n const int MMAX = 100000 + 5; n const int INF = 1000000000; n const int BS = 1000000007; n template <typename T> n inline T abs(const T a) { n   if (a < 0) return -a; n   return a; n } n template <typename T> n inline T sqr(const T& a) { n   return a * a; n } n int a[NMAX][NMAX]; n int b[NMAX][NMAX]; n int c[NMAX][NMAX]; n void mult(int n, int m, int k) { n   int i, j, t; n   for (i = 1; i <= n; i++) { n     for (j = 1; j <= k; j++) { n       c[i][j] = 0; n       for (t = 1; t <= m; t++) { n         c[i][j] = (c[i][j] + a[i][t] * 1ll * b[t][j]) % BS; n       } n     } n   } n } n const int BORD = 102; n void pw(int p) { n   int i, j; n   if (0 == p) { n     for (i = 1; i <= BORD; i++) { n       for (j = 1; j <= BORD; j++) { n         c[i][j] = (i == j); n       } n     } n     return; n   } n   if (1 == p) { n     for (i = 1; i <= BORD; i++) { n       for (j = 1; j <= BORD; j++) { n         c[i][j] = a[i][j]; n       } n     } n     return; n   } n   if (p & 1) { n     int buf[NMAX][NMAX]; n     for (i = 1; i <= BORD; i++) { n       for (j = 1; j <= BORD; j++) { n         buf[i][j] = a[i][j]; n       } n     } n     pw(p - 1); n     for (i = 1; i <= BORD; i++) { n       for (j = 1; j <= BORD; j++) { n         a[i][j] = buf[i][j]; n       } n     } n     for (i = 1; i <= BORD; i++) { n       for (j = 1; j <= BORD; j++) { n         b[i][j] = c[i][j]; n       } n     } n     mult(BORD, BORD, BORD); n   } else { n     pw(p / 2); n     for (i = 1; i <= BORD; i++) { n       for (j = 1; j <= BORD; j++) { n         a[i][j] = c[i][j]; n       } n     } n     for (i = 1; i <= BORD; i++) { n       for (j = 1; j <= BORD; j++) { n         b[i][j] = c[i][j]; n       } n     } n     mult(BORD, BORD, BORD); n   } n } n int main() { n   ios::sync_with_stdio(false); n   int n, x; n   int d[NMAX] = {0}; n   int i, j, y; n   cin >> n >> x; n   for (i = 1; i <= n; i++) { n     cin >> y; n     d[y]++; n   } n   int beg[NMAX]; n   beg[0] = 1; n   for (i = 1; i <= 100; i++) { n     beg[i] = 1; n     for (j = 1; j <= i; j++) { n       beg[i] = (beg[i] + beg[i - j] * 1ll * d[j]) % BS; n     } n   } n   memset(a, 0, sizeof(a)); n   a[1][1] = 1; n   for (i = 2; i <= BORD; i++) { n     for (j = 2; j <= BORD; j++) { n       if (i == j + 1) n         a[i][j] = 1; n       else n         a[i][j] = 0; n     } n   } n   a[1][BORD] = 1; n   for (i = 2; i <= BORD; i++) { n     a[i][BORD] = d[BORD - i + 1]; n   } n   pw(x); n   for (i = 1; i <= BORD; i++) { n     for (j = 1; j <= BORD; j++) { n       b[i][j] = c[i][j]; n     } n   } n   a[1][1] = 1; n   for (j = 2; j <= BORD; j++) { n     a[1][j] = beg[j - 2]; n   } n   mult(1, BORD, BORD); n   cout << c[1][2] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int c[1010100], cc[1010100]; n int lowbit(int x) { return x & (-x); } n void upd(int v, int idx, int a[]) { n   while (idx <= n) { n     a[idx] += v; n     idx += lowbit(idx); n   } n } n int qu(int idx, int a[]) { n   int sum = 0; n   if (idx == 0) return 0; n   while (idx > 0) { n     sum += a[idx]; n     idx -= lowbit(idx); n   } n   return sum; n } n struct Node { n   int v, id; n } arr[1010100]; n int cmp(Node a, Node b) { return a.v < b.v; } n int find() { n   int ll = 1, rr = n + 1, mid, ans = n; n   while (ll < rr) { n     mid = (ll + rr) / 2; n     if (qu(mid, cc) < mid) n       ans = rr = mid; n     else n       ll = mid + 1; n   } n   return ans; n } n int vis[1010100]; n int main() { n   int i, j; n   while (scanf( %d %d , &n, &m) != EOF) { n     memset(vis, 0, sizeof(vis)); n     for (i = 1; i <= n; i++) scanf( %d , &arr[i].v), arr[i].id = i; n     for (i = 1; i <= m; i++) scanf( %d , &j), vis[j] = 1; n     sort(arr + 1, arr + 1 + n, cmp); n     memset(c, 0, sizeof(c)); n     memset(cc, 0, sizeof(cc)); n     long long sum = 0; n     for (i = 1; i <= n; i++) { n       if (vis[arr[i].v]) { n         upd(1, arr[i].id, c); n       } else { n         int ll = 0, rr = arr[i].id, mid; n         int v = qu(rr, c), x = rr; n         while (ll < rr) { n           mid = (ll + rr) / 2; n           if (qu(mid, c) == v) n             x = rr = mid; n           else n             ll = mid + 1; n         } n         if (qu(n, c) == 0) x = 0; n         ll = arr[i].id, rr = n + 1; n         v = qu(ll, c); n         int y = ll; n         while (ll < rr) { n           mid = (ll + rr) / 2; n           if (qu(mid, c) == v) n             y = mid, ll = mid + 1; n           else n             rr = mid; n         } n         y = y - qu(y, cc); n         x = max(find() - 1, x); n         x = x - qu(x, cc); n         sum = sum + (y - x); n         upd(1, arr[i].id, cc); n       } n     } n     printf( %I64d n , sum); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 10200; n const int mod = 1e9 + 7; n int dp[N]; n int len[N]; n inline int get_len(int x) { n   if (x == 0) return 1; n   int res = 0; n   while (x) res++, x /= 10; n   return res; n } n vector<int> del[N]; n vector<int> calc_prefix(string s) { n   int n = (int)s.length(); n   vector<int> pi(n); n   for (int i = 1; i < n; ++i) { n     int j = pi[i - 1]; n     while (j > 0 && s[i] != s[j]) j = pi[j - 1]; n     if (s[i] == s[j]) ++j; n     pi[i] = j; n   } n   return pi; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   string s; n   cin >> s; n   int n = s.length(); n   for (int i = 0; i <= n; ++i) len[i] = get_len(i); n   for (int i = 1; i <= n; ++i) n     for (int j = i; j <= n; j += i) del[j].push_back(i); n   for (int i = 1; i <= n; ++i) dp[i] = 1e9; n   dp[0] = 0; n   string t; n   vector<int> p; n   for (int i = 1; i <= n; ++i) { n     int cur_len = 0, times; n     int period; n     t =   ; n     for (int j = i; j <= n; ++j) t += s[j - 1]; n     p = calc_prefix(t); n     for (int j = i; j <= n; ++j) { n       cur_len++; n       dp[j] = min(dp[j], dp[i - 1] + cur_len + 1); n       period = cur_len - p[j - i]; n       if (cur_len % period != 0) continue; n       dp[j] = min(dp[j], dp[i - 1] + len[cur_len / period] + period); n     } n   } n   cout << dp[n]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 8e+1000; n int n, k, x, c[1000]; n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> k >> x; n   for (int i = 0; i < n; i++) cin >> c[i]; n   int res = 0; n   for (int i = 0; i < n - 1; i++) { n     if (c[i] == c[i + 1] && c[i] == x) { n       int l = i - 1, r = i + 2; n       while (l >= 0 && r < n) { n         bool mark = false; n         if (c[l] != c[r]) break; n         if (l > 0 && c[l - 1] == c[l]) l--, mark = true; n         if (r < n - 1 && c[r + 1] == c[r]) r++, mark = true; n         if (mark == false) break; n         l--, r++; n       } n       res = max(res, r - l - 1); n     } n   } n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n #define endl   n  n #define IOS ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr) n using namespace std; n typedef long long LL; n typedef pair<int, int> PII; n const int maxn = 1e3 + 5; n  n string input; n int cnt[maxn], mx; n double a, b; n  n inline double randrand(){ n     return (double ) rand() / RAND_MAX; n } n  n int main(){ n     IOS; n     srand(time(nullptr)); n     int n, m, c1, c2; n     char c; n     cin >> n >> m; n     for(int j = 0; j < m; j++){ n         cin >> input; n         a = b = 0; n         if(j){ n             for (int i = 0; i < n; i++){ n                 if (input[i] ==  0 ) { n                     a += pow(0.9, cnt[i]); n                 } else { n                     b += pow(0.9, cnt[i]); n                 } n             } n         } n         if(a == b) cout << 1 << endl; n         else cout << (randrand() <= a / (a + b) ? 0 : 1) << endl; n         cout.flush(); n         cin >> c; n         for(int i = 0; i < n; i++){ n             cnt[i] += (input[i] != c); n         } n     } n }


#include <bits/stdc++.h> n using namespace std; n pair<int, int> afis[1503]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n, cnt = 0, i, x = 1; n   cin >> n; n   afis[++cnt] = {0, 0}; n   while (x <= n + 1) { n     afis[++cnt] = {x, x}; n     afis[++cnt] = {x, x - 1}; n     afis[++cnt] = {x - 1, x}; n     x++; n   } n   cout << cnt <<   n ; n   for (i = 1; i <= cnt; i++) n     cout << afis[i].first <<     << afis[i].second <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n int n, m, k, a[N]; n long long rem, cnt, sum; n double ans; n int main() { n   cin >> n >> k >> m; n   for (int i = 1; i <= n; ++i) { n     scanf( %d , a + i); n     sum += a[i]; n   } n   sort(a + 1, a + n + 1); n   for (int i = 1; i <= n; ++i) { n     cnt = n - i + 1; n     rem = m - i + 1; n     if (rem < 0) { n       break; n     } n     ans = max(ans, (sum + min(rem, cnt * k)) * 1.0 / cnt); n     sum -= a[i]; n   } n   printf( %0.9lf , ans); n   return 0; n } n


#include <bits/stdc++.h> n #include <string> n  n using namespace std; n  n bool susp() { n     int n; n     cin >> n; n     string days; n     cin >> days; n     for (int i = 0; i < n - 1; i++) { n         for (int j = i + 1; j < n; j++) { n             if (days[j] == days[i] && days[j - 1] != days[i]) n                 return false; n         } n     } n     return true; n } n  n int main() n { n     int t; n     cin >> t; n     bool cases[t]; n     for (int i = 0; i < t; i++) { n         cases[i] = susp(); n     } n     for (bool b : cases) { n         if (b) n             cout <<  YES  << endl; n         else n             cout <<  NO  << endl; n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   set<string> s; n   int n; n   cin >> n; n   for (int i = 0; i < n; ++i) { n     string ss; n     cin >> ss; n     s.insert(ss); n   } n   cout << 6 - n <<   n ; n   if (s.find( purple ) == s.end()) { n     cout <<  Power n ; n   } n   if (s.find( green ) == s.end()) { n     cout <<  Time n ; n   } n   if (s.find( blue ) == s.end()) { n     cout <<  Space n ; n   } n   if (s.find( orange ) == s.end()) { n     cout <<  Soul n ; n   } n   if (s.find( red ) == s.end()) { n     cout <<  Reality n ; n   } n   if (s.find( yellow ) == s.end()) { n     cout <<  Mind n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5e5 + 5, mod = 1e9 + 7, lg = 22; n int n, suf[maxn], lcp[maxn], Rank[lg][maxn], pw2[30], rmq[lg][maxn], lst, n     seg[maxn * 4], klg[maxn], dp[maxn]; n string s; n vector<pair<pair<int, int>, int>> V2; n void raDix_Sort() { n   vector<vector<pair<pair<int, int>, int>>> V1(maxn), V3(maxn); n   for (auto i : V2) V1[i.first.second + 1].push_back(i); n   V2.clear(); n   for (int i = 0; i <= n; i++) n     for (auto j : V1[i]) V3[j.first.first].push_back(j); n   for (int i = 0; i < n; i++) n     for (auto j : V3[i]) V2.push_back(j); n } n void build_suffix_array() { n   vector<pair<int, int>> V; n   V2.resize(n); n   for (int i = 0; i < n; i++) V.push_back({s[i] -  a , i}); n   sort(V.begin(), V.end()); n   for (int i = 1; i < n; i++) n     Rank[0][V[i].second] = n         Rank[0][V[i - 1].second] + ((V[i].first) != (V[i - 1].first)); n   for (int i = 0; pw2[i] < n; i++) { n     for (int j = 0; j < n; j++) { n       int x = -1; n       if (j + pw2[i] < n) x = Rank[i][j + pw2[i]]; n       V2[j] = {{Rank[i][j], x}, j}; n     } n     raDix_Sort(); n     Rank[i + 1][V2[0].second] = 0; n     for (int j = 1; j < n; j++) n       Rank[i + 1][V2[j].second] = n           Rank[i + 1][V2[j - 1].second] + ((V2[j].first) != (V2[j - 1].first)); n     lst = i + 1; n     if (Rank[i + 1][V2[n - 1].second] == n - 1) break; n   } n   for (int i = 0; i < n; i++) suf[Rank[lst][i]] = i; n   for (int i = 0; i < n - 1; i++) { n     int p1 = suf[i], p2 = suf[i + 1]; n     for (int j = lst; j >= 0; j--) { n       if (Rank[j][p1] != Rank[j][p2]) continue; n       if (p1 >= n || p2 >= n) continue; n       p1 += pw2[j]; n       p2 += pw2[j]; n     } n     lcp[i] = p1 - suf[i]; n     rmq[0][i] = lcp[i]; n   } n   n--; n   for (int j = 1; j <= klg[n]; j++) { n     for (int i = 0; i <= n - pw2[j]; i++) n       rmq[j][i] = min(rmq[j - 1][i], rmq[j - 1][i + pw2[j - 1]]); n   } n   n++; n } n void fix(int p, int x, int v = 1, int s = 0, int e = n) { n   if (e - s == 1) { n     seg[v] = x; n     return; n   } n   int mid = (e + s) >> 1, lc = v << 1, rc = lc | 1; n   if (mid > p) n     fix(p, x, lc, s, mid); n   else n     fix(p, x, rc, mid, e); n   seg[v] = max(seg[lc], seg[rc]); n } n int get(int l, int r, int v = 1, int s = 0, int e = n) { n   if ((l >= e) || (r <= s)) return 0; n   if ((l <= s) && (e <= r)) return seg[v]; n   int mid = (e + s) >> 1, lc = v << 1, rc = lc | 1; n   return max(get(l, r, lc, s, mid), get(l, r, rc, mid, e)); n } n int get_mn(int l, int r) { n   return min(rmq[klg[r - l]][l], rmq[klg[r - l]][r - pw2[klg[r - l]]]); n } n bool check(int l, int r) { n   int len = r - l, p = Rank[lst][l], p1, p2, l1 = p, r1 = n; n   while (l1 != r1 - 1) { n     int mid = (l1 + r1) >> 1; n     if (get_mn(l1, mid) >= len) n       l1 = mid; n     else n       r1 = mid; n   } n   p2 = r1; n   l1 = -1; n   r1 = p; n   while (l1 != r1 - 1) { n     int mid = (l1 + r1) >> 1; n     if (get_mn(mid, r1) >= len) n       r1 = mid; n     else n       l1 = mid; n   } n   p1 = r1; n   if (get(p1, p2) >= len) n     return 1; n   else n     return 0; n } n int main() { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   pw2[0] = 1; n   klg[1] = 0; n   for (int i = 1; i < 25; i++) pw2[i] = (pw2[i - 1] * 2); n   for (int i = 2; i < maxn; i++) n     klg[i] = klg[i - 1] + (pw2[klg[i - 1]] * 2 == i); n   cin >> n >> s; n   build_suffix_array(); n   int ans = 1, l = n - 2, r = n - 1; n   dp[n - 1] = 1; n   fix(Rank[lst][n - 1], 1); n   while (l >= 0) { n     if (l == r - 1) { n       dp[l] = 1; n       l--; n       continue; n     } n     if (!check(l, r - 1)) { n       if (!check(l + 1, r)) { n         r--; n         fix(Rank[lst][r], dp[r]); n         continue; n       } n     } n     ans = max(ans, r - l); n     dp[l] = r - l; n     l--; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e5 + 7; n const long long inf = 1e9 + 7; n const long long mod = 1e9 + 7; n int n; n int m; n int x; n int y; n vector<int> g[N]; n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> m; n   for (int i = 1; i <= m; i++) { n     cin >> x >> y; n     g[x].push_back(y); n     g[y].push_back(x); n   } n   int badbus = 0, cnt = 0; n   for (int i = 1; i <= n; i++) { n     badbus |= (g[i].empty()); n     if ((int)g[i].size() == 1) { n       cnt++; n       continue; n     } n     badbus |= ((int)g[i].size() != 2); n   } n   if (cnt == 2 && badbus == 0) { n     cout <<  bus topology n ; n     return 0; n   } n   int badring = 0; n   for (int i = 1; i <= n; i++) { n     badring |= ((int)g[i].size() != 2); n   } n   if (badring == 0) { n     cout <<  ring topology n ; n     return 0; n   } n   cnt = 0; n   int badstar = 0; n   for (int i = 1; i <= n; i++) { n     if ((int)g[i].size() == n - 1) { n       cnt++; n       continue; n     } n     badstar |= ((int)g[i].size() != 1); n   } n   if (cnt == 1 && badstar == 0) { n     cout <<  star topology n ; n     return 0; n   } n   cout <<  unknown topology n ; n } n


#include <bits/stdc++.h> n using namespace std; n inline int in() { n   int32_t x; n   scanf( %d , &x); n   return x; n } n inline string get() { n   char ch[1000010]; n   scanf( %s , ch); n   return ch; n } n const int MAX_LG = 21; n const int maxn = 2e5 + 100; n const int base = 29; n const int mod = 1e9 + 7; n const int INF = 2e9 + 100; n int nxt[maxn]; n int sz[maxn]; n int deg[maxn]; n bool mark[maxn]; n bool dp[maxn]; n bool dp2[maxn]; n inline int root(int x) { return (nxt[x] == 0 ? x : nxt[x] = root(nxt[x])); } n inline void dfs(int v) { n   mark[v] = true; n   sz[v] = 1; n   if (nxt[v] == 0) return; n   int u = nxt[v]; n   if (mark[u]) n     sz[v] += sz[u]; n   else { n     dfs(u); n     sz[v] += sz[u]; n   } n } n int32_t main() { n   int n = in(), id = in(); n   for (int i = 1; i <= n; i++) nxt[i] = in(), deg[nxt[i]]++; n   for (int i = 1; i <= n; i++) { n     if (!mark[i]) dfs(i); n   } n   vector<int> vc; n   for (int i = 1; i <= n; i++) n     if (deg[i] == 0 && root(i) != root(id)) vc.push_back(sz[i]); n   dp[0] = true; n   for (int i = 0; i < vc.size(); i++) { n     for (int j = 0; j + vc[i] <= 1000; j++) dp2[j + vc[i]] |= dp[j]; n     for (int j = 0; j <= 1000; j++) dp[j] |= dp2[j], dp2[j] = false; n   } n   for (int x = 0; x <= 1000; x++) { n     if (dp[x]) { n       cout << x + sz[id] <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, c0, c1, C[70][50010]; n const int N = 60, M = 40000; n struct atom { n   long long w; n   int num; n } A[50]; n int len; n int check(long long lim) { n   int now = min(1ll * n, lim / c1); n   for (int i = 1; i <= N; i++) { n     int j = 0; n     while (1ll * i * c0 + 1ll * j * c1 <= lim && now < n) { n       now = min(n, now + C[i][j]); n       j++; n     } n   } n   return now; n } n int compare(atom k1, atom k2) { return k1.w < k2.w; } n long long calc(long long lim) { n   long long ans = 1ll * n * (c0 + c1); n   int len = 0; n   int k = lim / c1; n   A[++len] = (atom){1ll * k * c1, 1}; n   int rem = n; n   k--; n   if (k >= 0) ans += 1ll * (k + 1) * k / 2 * c1, rem -= k + 1; n   for (int i = 1; i <= N; i++) { n     int j = 0; n     while (1ll * i * c0 + 1ll * j * c1 <= lim) j++; n     j--; n     if (j < 0) continue; n     A[++len] = (atom){1ll * i * c0 + 1ll * j * c1, C[i][j]}; n     j--; n     while (j >= 0) { n       ans += (1ll * i * c0 + 1ll * j * c1) * C[i][j]; n       rem -= C[i][j]; n       j--; n     } n   } n   sort(A + 1, A + len + 1, compare); n   for (int i = 1; i <= len; i++) { n     int k = min(rem, A[i].num); n     ans += 1ll * k * A[i].w; n     rem -= k; n   } n   return ans; n } n int main() { n   scanf( %d%d%d , &n, &c0, &c1); n   if (c0 < c1) swap(c0, c1); n   n--; n   if (n == 0) { n     cout << 0 << endl; n     return 0; n   } n   if (c1 == 0) { n     cout << 1ll * n * c0 << endl; n     return 0; n   } n   for (int i = 0; i <= M; i++) C[0][i] = 1; n   for (int i = 1; i <= N; i++) { n     C[i][0] = 1; n     for (int j = 1; j <= M; j++) C[i][j] = min(C[i - 1][j] + C[i][j - 1], n); n   } n   long long l = 0, r = 1e17, ans = 0; n   while (l < r) { n     long long mid = l + r >> 1; n     if (check(mid) >= n) { n       ans = mid; n       r = mid; n     } else n       l = mid + 1; n   } n   cout << calc(ans) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n class input { n  private: n   bool fail; n   istream* stream; n  n  public: n   input(istream& stream_ = cin) { stream = &stream_; } n   istream& getStream() { return *stream; } n   template <typename T = int> n   T read() { n     T value; n     if (*stream >> value) { n       fail = false; n     } else { n       fail = true; n     } n     return value; n   } n   template <typename T = int> n   vector<T> readArray() { n     size_t size = read<size_t>(); n     return readArray<T>(size); n   } n   template <typename T = int> n   vector<T> readArray(size_t size) { n     vector<T> v(size); n     for (size_t i = 0; i < size; i++) { n       if (*stream >> v[i]) { n         fail = false; n       } else { n         fail = true; n       } n     } n     return v; n   } n   bool isFailed() { return fail; } n   static input& getStdin() { n     static input in(cin); n     return in; n   } n }; n class output { n  private: n   ostream* stream; n  n  public: n   output(ostream& stream_ = cout) { stream = &stream_; } n   ostream& getStream() { return *stream; } n   template <typename T> n   output& put(T& value) { n     *stream << value; n     return *this; n   } n   template <typename T> n   output& put(T& value, int precision) { n     *stream << setprecision(precision) << value; n     return *this; n   } n   output& flush() { n     stream->flush(); n     return *this; n   } n   template <typename T> n   output& write(const T& value) { n     *stream << value << endl; n     return *this; n   } n   template <typename T> n   output& write(T& value, int precision) { n     *stream << setprecision(precision) << fixed << value << endl; n     return *this; n   } n   template <typename T> n   output& writeArray(const vector<T>& v, bool appendSize = true) { n     if (appendSize) { n       write(v.size()); n     } n     for (auto& x : v) { n       *stream << x <<    ; n     } n     *stream << endl; n     return *this; n   } n   output& writeLine() { n     *stream << endl; n     return *this; n   } n   output getStdout() { n     output out(cout); n     return out; n   } n   output getStderr() { n     output err(cerr); n     return err; n   } n }; n namespace std { n template <> n struct hash<pair<string, int>> { n   size_t operator()(const pair<string, int>& x) const { n     return hash<string>()(x.first) ^ hash<int>()(x.second); n   } n }; n };  // namespace std n void solve(input in, output out, output err) { n   pair<string, int> root{}; n   unordered_map<pair<string, int>, vector<pair<string, int>>> data; n   int n = in.read(); n   for (int i = 0; i < n; i++) { n     string name = in.read<string>(); n     int ver = in.read(); n     pair<string, int> x = make_pair(name, ver); n     if (root.first.empty()) { n       root = x; n     } n     int x_deps_count = in.read(); n     vector<pair<string, int>> x_deps(x_deps_count); n     for (int j = 0; j < x_deps_count; j++) { n       string depName = in.read<string>(); n       int depVer = in.read(); n       x_deps[j] = make_pair(depName, depVer); n     } n     data[x] = x_deps; n   } n   vector<pair<string, pair<int, int>>> answer; n   unordered_map<string, pair<int, int>> info; n   queue<string> q; n   q.push(root.first); n   info[root.first] = make_pair(root.second, 0); n   while (!q.empty()) { n     auto& cur = q.front(); n     auto& curInfo = info[cur]; n     if (cur != root.first) { n       answer.emplace_back(cur, curInfo); n     } n     auto deps = data.find(make_pair(cur, curInfo.first)); n     if (deps != data.end()) { n       for (const auto& next : deps->second) { n         pair<int, int> nextInfo = make_pair(next.second, curInfo.second + 1); n         auto addPtr = info.emplace(next.first, nextInfo); n         if (!addPtr.second) { n           if (addPtr.first->second.second == nextInfo.second && n               addPtr.first->second.first < nextInfo.first) { n             info[next.first] = nextInfo; n           } n         } else { n           q.push(next.first); n         } n       } n     } n     q.pop(); n   } n   sort(answer.begin(), answer.end()); n   out.write(answer.size()); n   for (const auto& x : answer) { n     out.put(x.first).put(   ).write(x.second.first); n   } n } n int main() { n   input in(cin); n   output out(cout); n   output err(cerr); n   while (true) { n     auto startT = clock(); n     solve(in, out, err); n     auto endT = clock(); n     cerr << endl; n     cerr <<  Working time:   << (endT - startT) <<   ms  << endl; n     cerr <<  -------------------------  << endl; n     bool ok = false; n     while (!in.isFailed() && !ok) { n       ok = in.read<char>() ==  $ ; n     } n     if (!ok) { n       break; n     } n   } n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:64000000 ) n using namespace std; n const int INF = (int)1E9; n const long long INF64 = (long long)1E18; n const long double EPS = 1E-9; n const long double PI = 3.1415926535897932384626433832795; n const int MAXN = 100100; n map<int, vector<pair<int, int> > > m; n vector<pair<long long, int> > l[MAXN]; n void process(int c, vector<pair<int, int> > &a) { n   sort((a).rbegin(), (a).rend()); n   long long sum = 0; n   for (int i = 0; i < (int)(a.size()); i++) { n     sum += a[i].first; n     l[i + 1].push_back(make_pair(sum, c)); n   } n } n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < (int)(n); i++) { n     int c, s; n     scanf( %d%d , &c, &s); n     m[c].push_back(make_pair(s, i)); n   } n   for (map<int, vector<pair<int, int> > >::iterator i = m.begin(); i != m.end(); n        i++) n     process(i->first, i->second); n   for (int i = 0; i < (int)(n + 1); i++) sort((l[i]).rbegin(), (l[i]).rend()); n   long long sum = -INF; n   int c1, n1, c2, n2; n   for (int i = 1; i <= n; i++) n     for (int j = 0; j < (int)(min(2, (int)l[i].size())); j++) { n       for (int k = 0; k < (int)(min(2, (int)l[i].size())); k++) { n         long long cur = l[i][j].first + l[i][k].first; n         if (l[i][j].second != l[i][k].second && cur > sum) { n           sum = cur; n           c1 = l[i][j].second; n           n1 = i; n           c2 = l[i][k].second; n           n2 = i; n         } n       } n       for (int k = 0; k < (int)(min(2, (int)l[i - 1].size())); k++) { n         long long cur = l[i][j].first + l[i - 1][k].first; n         if (l[i][j].second != l[i - 1][k].second && cur > sum) { n           sum = cur; n           c1 = l[i][j].second; n           n1 = i; n           c2 = l[i - 1][k].second; n           n2 = i - 1; n         } n       } n     } n   cout << sum << endl << n1 + n2 << endl; n   vector<pair<int, int> > a1(m[c1].begin(), m[c1].begin() + n1); n   vector<pair<int, int> > a2(m[c2].begin(), m[c2].begin() + n2); n   for (int i = 0; i < (int)(min(n1, n2)); i++) { n     printf( %d  , a1[i].second + 1); n     printf( %d  , a2[i].second + 1); n   } n   if (n1 != n2) printf( %d , a1.back().second + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long l, r, u, d; n long long n, x, y, c; n long long sqr(long long x) { return x * x; } n long long tri(long long x) { return (x + 1) * x / 2; } n bool solve(long long t) { n   long long sum = t * t + (t + 1) * (t + 1); n   if (t > l) sum -= sqr(t - l); n   if (t > r) sum -= sqr(t - r); n   if (t > u) sum -= sqr(t - u); n   if (t > d) sum -= sqr(t - d); n   if (t > l + d) sum += tri(t - (l + d) - 1); n   if (t > l + u) sum += tri(t - (l + u) - 1); n   if (t > r + d) sum += tri(t - (r + d) - 1); n   if (t > r + u) sum += tri(t - (r + u) - 1); n   if (sum >= c) return true; n   return false; n } n int main() { n   scanf( %I64d%I64d%I64d%I64d , &n, &x, &y, &c); n   l = x - 1; n   r = n - x; n   u = y - 1; n   d = n - y; n   long long low = 0, high = 2 * n, mid; n   while (low <= high) { n     mid = (low + high) / 2; n     if (solve(mid)) n       high = mid - 1; n     else n       low = mid + 1; n   } n   printf( %I64d n , low); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool check(pair<int, int> a, pair<int, int> b) { n   if (a.first > b.first) n     return true; n   else if (a.first == b.first) n     return a.second < b.second; n   else n     return false; n } n int main() { n   int n, k; n   cin >> n >> k; n   pair<int, int> a[n]; n   map<pair<int, int>, int> mp; n   for (int i = 0; i < n; i++) { n     int p, t; n     cin >> p >> t; n     a[i] = make_pair(p, t); n     mp[a[i]]++; n   } n   sort(a, a + n, check); n   cout << mp[a[k - 1]] <<   n ; n   return 0; n } n