#include <bits/stdc++.h> n using namespace std; n int main() { n   string s =   ; n   cin >> s; n   int y = 0; n   while (s[y] ==  a  && y <= s.length()) ++y; n   for (int i = y; i < s.length(); ++i) { n     if (s[i] ==  a ) n       break; n     else n       --s[i]; n   } n   if (y == s.length()) s[s.length() - 1] =  z ; n   cout << s << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int n; n   cin >> n; n   long long int a[n], b[n]; n   long long int sum_1 = 0, sum_2 = 0, c = 0; n   for (long long int i = 0; i <= n - 1; i++) { n     cin >> a[i] >> b[i]; n     sum_1 += a[i]; n     sum_2 += b[i]; n   } n   if (sum_1 % 2 == 0 && sum_2 % 2 == 0) { n     cout <<  0  <<   n ; n   } else if (n == 1) { n     cout <<  -1  <<   n ; n   } else { n     for (long long int i = 0; i <= n - 1; i++) { n       sum_1 -= a[i]; n       sum_1 += b[i]; n       sum_2 -= b[i]; n       sum_2 += a[i]; n       c++; n       if (sum_1 % 2 == 0 && sum_2 % 2 == 0) { n         cout << c <<   n ; n         return 0; n       } n       c--; n       sum_1 -= b[i]; n       sum_1 += a[i]; n       sum_2 -= a[i]; n       sum_2 += b[i]; n     } n     cout <<  -1  <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<int, int> mp; n int f[210000 * 4], mn[210000 * 4]; n void add(int u, int L, int R, int l, int r, int k) { n   l = max(l, L); n   r = min(r, R); n   if (l >= r) return; n   if (l == L && R == r) { n     mn[u] += k; n     f[u] += k; n     return; n   } n   add(u * 2, L, ((L + R) >> 1), l, r, k); n   add(u * 2 + 1, ((L + R) >> 1), R, l, r, k); n   mn[u] = min(mn[u * 2], mn[u * 2 + 1]) + f[u]; n } n int calc(int u, int L, int R, int k) { n   if (L + 1 == R) return L; n   k -= f[u]; n   if (mn[u * 2] <= k) return calc(u * 2, L, ((L + R) >> 1), k); n   return calc(u * 2 + 1, ((L + R) >> 1), R, k); n } n int sa[210000], sb[210000], na, nb, a[210000]; n int ans, st, ed; n int i, last, n, m, d; n int main() { n   scanf( %d%d%d , &n, &m, &d); n   for (int i = (1); i < (n + 1); i++) scanf( %d , a + i); n   if (!d) { n     for (int i = (1); i < (n + 1); i++) { n       if (i == 1 || a[i] != a[i - 1]) last = i; n       if (ans < i - last + 1) ans = i - last + 1, st = last, ed = i; n     } n   } else { n     for (int i = (1); i < (n + 1); i++) { n       if (i != 1 && (a[i] - a[i - 1]) % d) { n         add(1, 1, n + 1, last + 1, i, 1100000); n         last = i - 1; n       } n       if (mp[a[i]] > last) { n         add(1, 1, n + 1, last + 1, mp[a[i]] + 1, 1100000); n         last = mp[a[i]]; n       } n       mp[a[i]] = i; n       while (na && a[i] > a[sa[na]]) { n         add(1, 1, n + 1, sa[na - 1] + 1, sa[na] + 1, (a[i] - a[sa[na]]) / d); n         na--; n       } n       while (nb && a[i] < a[sb[nb]]) { n         add(1, 1, n + 1, sb[nb - 1] + 1, sb[nb] + 1, (a[sb[nb]] - a[i]) / d); n         nb--; n       } n       sa[++na] = sb[++nb] = i; n       add(1, 1, n + 1, i, i + 1, i); n       int tmp = calc(1, 1, n + 1, i + m); n       if (i - tmp + 1 > ans) { n         ans = i - tmp + 1; n         st = tmp; n         ed = i; n       } n     } n   } n   printf( %d %d n , st, ed); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 2e9; n const long long Inf = 1e10; n const int N = 500005; n const double pi = acos(-1); n inline int IN() { n   int x = 0; n   int ch = 0, f = 0; n   for (ch = getchar(); ch != -1 && (ch < 48 || ch > 57); ch = getchar()) n     f = (ch ==  - ); n   for (; ch >= 48 && ch <= 57; ch = getchar()) n     x = (x << 1) + (x << 3) + ch -  0 ; n   return f ? (-x) : x; n } n int Pow(int x, int y, int p) { n   int a = 1; n   for (; y; y >>= 1, x = (long long)x * x % p) n     if (y & 1) a = (long long)a * x % p; n   return a; n } n int n, a; n double rad[N], dis[N], ang[N]; n struct po { n   double x, y; n   po(double xv = 0, double yv = 0) { x = xv, y = yv; } n   double norm() { return sqrt(x * x + y * y); } n   po operator-(const po &a) const { return (po){x - a.x, y - a.y}; } n } b[N], P, Q; n pair<double, double> A[N]; n int tot; n set<double> st; n int check(double rng) { n   tot = 0; n   st.clear(); n   for (int i = (int)(1); i <= (int)(n); i++) { n     if (dis[i] >= rng + rad[i]) continue; n     if (dis[i] <= fabs(rng - rad[i])) continue; n     double bet = n         (rng * rng + dis[i] * dis[i] - rad[i] * rad[i]) / (2 * rng * dis[i]); n     double alp = ang[i]; n     bet = acos(bet); n     double l = alp - bet, r = alp + bet; n     if (l < 0) l += 2 * pi; n     if (r < 0) r += 2 * pi; n     if (l > r) swap(l, r); n     A[++tot] = make_pair(l, r); n   } n   sort(A + 1, A + tot + 1); n   for (int i = (int)(1); i <= (int)(tot); i++) { n     auto t = st.lower_bound(A[i].first); n     if (t != st.end() && *t < A[i].second) return 1; n     st.insert(A[i].second); n   } n   return 0; n } n int main() { n   scanf( %d%d , &n, &a); n   P = po(a, 0); n   Q = po(-a, 0); n   for (int i = (int)(1); i <= (int)(n); i++) { n     double x, y; n     scanf( %lf%lf , &x, &y); n     b[i] = po(x, y); n     rad[i] = (b[i] - Q).norm(); n     b[i] = b[i] - P; n     ang[i] = atan2(b[i].y, b[i].x); n     dis[i] = b[i].norm(); n   } n   double l = 0, r = 2 * a; n   for (int i = (int)(1); i <= (int)(100); i++) { n     double md = (l + r) / 2.; n     if (check(md)) n       r = md; n     else n       l = md; n   } n   printf( %.10lf n , (l + r) / 2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5e5 + 5; n const int inf = 1e9 + 5e5 + 19; n int n, k; n int a[maxn]; n bool in_b[maxn]; n struct fenwick { n   int n; n   vector<int> val; n   void init(int _n) { n     n = _n; n     val.assign(n + 5, -1); n   } n   void update(int x, int k) { n     for (; x <= n; x += x & -x) val[x] = max(val[x], k); n   } n   int get(int x) { n     int res = -1; n     for (; x > 0; x -= x & -x) res = max(res, val[x]); n     return res; n   } n } tree; n void read_input() { n   cin >> n >> k; n   for (int i = 1; i <= n; ++i) cin >> a[i]; n   for (; k > 0; --k) { n     int x; n     cin >> x; n     in_b[x] = true; n   } n   in_b[0] = in_b[n + 1] = true; n   a[0] = -inf; n   a[n + 1] = inf; n } n int calc(const vector<int>& arr, int L, int R) { n   if ((int)arr.size() == 0) return 0; n   vector<int> vals; n   for (int i = 0; i < (int)arr.size(); ++i) vals.push_back(arr[i] - i); n   sort(vals.begin(), vals.end()); n   vals.erase(unique(vals.begin(), vals.end()), vals.end()); n   tree.init((int)vals.size()); n   int max_val = 0; n   for (int i = 0; i < (int)arr.size(); ++i) { n     if (arr[i] <= L || arr[i] >= R) continue; n     if (arr[i] - L - 1 >= i && R - arr[i] - 1 >= (int)arr.size() - i - 1) { n       int val = 1; n       int p = n           lower_bound(vals.begin(), vals.end(), arr[i] - i) - vals.begin() + 1; n       val = max(val, tree.get(p) + 1); n       tree.update(p, val); n       max_val = max(max_val, val); n     } n   } n   return (int)arr.size() - max_val; n } n void solve() { n   int ans = 0; n   for (int i = 0; i <= n;) { n     int j = i + 1; n     while (j <= n && !in_b[j]) ++j; n     int L = a[i], R = a[j]; n     if (R - L < j - i) { n       cout <<  -1 n ; n       return; n     } n     vector<int> arr; n     ++i; n     for (; i < j; ++i) arr.push_back(a[i]); n     ans += calc(arr, L, R); n   } n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   read_input(); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int prime[500000]; n long long gcd(long long x, long long y) { n   if (y == 0) return x; n   return gcd(y, x % y); n } n int main() { n   long long n; n   cin >> n; n   long long x = n; n   for (long long i = 2; i * i <= n; i++) n     if (n % i == 0) { n       x = gcd(x, i); n       x = gcd(x, n / i); n     } n   cout << x << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int ts, kk = 1; n template <class T> n inline T _sq(T a) { n   return a * a; n } n template <class T, class X> n inline T _pow(T a, X y) { n   T z = 1; n   for (int i = 1; i <= y; i++) { n     z *= a; n   } n   return z; n } n template <class T> n inline T _gcd(T a, T b) { n   a = _abs(a); n   b = _abs(b); n   if (!b) return a; n   return _gcd(b, a % b); n } n template <class T> n inline T _lcm(T a, T b) { n   a = _abs(a); n   b = _abs(b); n   return (a / _gcd(a, b)) * b; n } n template <class T> n inline T _extended(T a, T b, T &x, T &y) { n   a = _abs(a); n   b = _abs(b); n   T g, x1, y1; n   if (!b) { n     x = 1; n     y = 0; n     g = a; n     return g; n   } n   g = _extended(b, a % b, x1, y1); n   x = y1; n   y = x1 - (a / b) * y1; n   return g; n } n template <class T, class X> n inline bool getbit(T a, X i) { n   T t = 1; n   return ((a & (t << i)) > 0); n } n template <class T, class X> n inline T setbit(T a, X i) { n   T t = 1; n   return (a | (t << i)); n } n template <class T, class X> n inline T resetbit(T a, X i) { n   T t = 1; n   return (a & (~(t << i))); n } n template <class T, class X> n inline T togglebit(T a, X i) { n   T t = 1; n   return (a ^ (t << i)); n } n template <class T, class X, class Y> n inline T _bigmod(T n, X m, Y mod) { n   unsigned long long ret = 1, a = n % mod; n   while (m) { n     if (m & 1) ret = (ret * a) % mod; n     m >>= 1; n     a = (a * a) % mod; n   } n   ret %= mod; n   return (T)ret; n } n template <class T, class Y> n inline T _modinv(T n, Y mod) { n   return _bigmod(n, mod - 2, mod); n } n const int bit = 10000; n int son[800], x, y, N, c[120]; n vector<int> E[800]; n struct HugeInt { n   int a[60], len; n   void set(int x) { n     len = 0; n     while (x) a[++len] = x % bit, x /= bit; n   } n   void operator*=(const HugeInt &b) { n     memset(c, 0, sizeof c); n     for (int i = 1; i <= len; i++) n       for (int j = 1; j <= b.len; j++) n         c[i + j - 1] += a[i] * b.a[j], c[i + j] += c[i + j - 1] / bit, n             c[i + j - 1] %= bit; n     len += b.len; n     while (len > 1 && c[len] == 0) len--; n     while (c[len] >= bit) { n       ++len; n       c[len] = c[len - 1] / bit; n       c[len - 1] %= bit; n     } n     for (int i = 1; i <= len; i++) a[i] = c[i]; n   } n   void operator*=(int b) { n     for (int i = 1; i <= len; i++) a[i] *= b; n     for (int i = 1; i <= len; i++) a[i + 1] += a[i] / bit, a[i] %= bit; n     len++; n     while (len > 1 && !a[len]) len--; n     while (a[len] >= bit) { n       ++len; n       a[len] = a[len - 1] / bit; n       a[len - 1] %= bit; n     } n   } n   void out() { n     printf( %d , a[len]); n     for (int i = len - 1; i >= 1; i--) printf( %04d , a[i]); n     puts(  ); n   } n } dp[800][800]; n void upd(HugeInt &a, HugeInt b) { n   int flag = 0; n   for (int i = max(a.len, b.len); i >= 1; i--) n     if (b.a[i] > a.a[i]) { n       a = b; n       return; n     } else if (b.a[i] < a.a[i]) n       return; n } n void dfs(int u, int fa) { n   dp[u][1].set(1); n   son[u] = 1; n   for (int i = 0; i < E[u].size(); ++i) n     if (E[u][i] != fa) { n       int v = E[u][i]; n       dfs(v, u); n       for (int j = son[u]; j >= 0; j--) n         for (int k = son[v]; k >= 0; k--) { n           HugeInt tmp = dp[v][k]; n           tmp *= dp[u][j]; n           upd(dp[u][j + k], tmp); n         } n       son[u] += son[v]; n     } n   for (int i = 0; i <= son[u]; i++) { n     HugeInt tmp = dp[u][i]; n     tmp *= i; n     upd(dp[u][0], tmp); n   } n } n int main() { n   scanf( %d , &N); n   for (int i = 1; i <= N - 1; i++) n     scanf( %d%d , &x, &y), E[x].push_back(y), E[y].push_back(x); n   dfs(1, 0); n   dp[1][0].out(); n   return 0; n } n


#include <bits/stdc++.h> n int n; n char s[11]; n int main() { n   scanf( %d , &n); n   int pos = 20000; n   for (int i = 1; i <= n; i++) { n     int num; n     scanf( %d%s , &num, s + 1); n     if (s[1] ==  N ) { n       if (pos + num > 20000) { n         puts( NO ); n         return 0; n       } else n         pos += num; n     } else if (s[1] ==  S ) { n       if (pos - num < 0) { n         puts( NO ); n         return 0; n       } else n         pos -= num; n     } else { n       if (pos == 0 || pos == 20000) { n         puts( NO ); n         return 0; n       } n     } n   } n   if (pos == 20000) n     puts( YES ); n   else n     puts( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool cmp(pair<long long, long long> a, pair<long long, long long> b) { n   if (a.first != b.first) { n     return a.first < b.first; n   } n   return a.second > b.second; n } n const int maxn = (int)1e7; n struct vt { n   int ed[2]; n   bool term; n   vt() { n     ed[0] = ed[1] = -1; n     term = false; n   } n }; n vt mas[maxn]; n int posit = 0; n int my_new() { n   if (posit == maxn) { n     throw 1; n   } n   return posit++; n } n void add(int t, long long x, int b, int mb) { n   if (b == mb) { n     mas[t].term = true; n     return; n   } n   int c = (x >> b) & 1; n   if (mas[t].ed[c] == -1) { n     mas[t].ed[c] = my_new(); n   } n   add(mas[t].ed[c], x, b - 1, mb); n } n void make(vector<pair<long long, long long> > &a) { n   sort(a.begin(), a.end(), cmp); n   long long rm = -1; n   vector<pair<long long, long long> > res; n   for (int i = 0; i < (int)a.size(); i++) { n     if (a[i].second <= rm) { n       continue; n     } else { n       rm = a[i].second; n       res.push_back(a[i]); n     } n   } n   a = res; n } n int t; n void calc(long long la, long long ra, long long lb, long long rb) { n   add(t, la ^ lb, 59, -1); n   add(t, ra ^ rb, 59, -1); n   add(t, la ^ rb, 59, -1); n   add(t, ra ^ lb, 59, -1); n   for (int b = 59; b >= 0; b--) { n     long long lx = (la >> b); n     long long ly = (lb >> b); n     long long rx = (ra >> b); n     long long ry = (rb >> b); n     if (lx != rx && (lx + 1) != rx) { n       if ((lx & 1) == 0) { n         add(t, ((lx + 1) ^ ly) << b, 59, b - 1); n         add(t, ((lx + 1) ^ ry) << b, 59, b - 1); n       } n       if ((rx & 1) == 1) { n         add(t, ((rx - 1) ^ ly) << b, 59, b - 1); n         add(t, ((rx - 1) ^ ry) << b, 59, b - 1); n       } n     } n     if (ly != ry && (ly + 1) != ry) { n       if ((ly & 1) == 0) { n         add(t, (lx ^ (ly + 1)) << b, 59, b - 1); n         add(t, (rx ^ (ly + 1)) << b, 59, b - 1); n       } n       if (ry & 1) { n         add(t, (lx ^ (ry - 1)) << b, 59, b - 1); n         add(t, (rx ^ (ry - 1)) << b, 59, b - 1); n       } n     } n     if (lx != rx && (lx + 1) != rx && ly != ry && (ly + 1) != ry) { n       if ((lx & 1) == 0 && (ly & 1) == 0) { n         add(t, ((lx + 1) ^ (ly + 1)) << b, 59, b - 1); n       } n       if ((lx & 1) == 0 && (ry & 1) == 1) { n         add(t, ((lx + 1) ^ (ry - 1)) << b, 59, b - 1); n       } n       if ((rx & 1) == 1) { n         if ((ly & 1) == 0) { n           add(t, ((rx - 1) ^ (ly + 1)) << b, 59, b - 1); n         } n         if ((ry & 1) == 1) { n           add(t, ((rx - 1) ^ (ry - 1)) << b, 59, b - 1); n         } n       } n     } n   } n } n const int mod = 998244353; n const int maxlog = 135; n int st[maxlog]; n int build(int t, int b, long long x) { n   if (mas[t].term) { n     int y = x % mod; n     y = (long long)y * st[b + 1] % mod; n     int ans = (long long)y * st[b + 1] % mod; n     ans += (long long)st[b] * (st[b + 1] - 1) % mod; n     ans %= mod; n     if (ans < 0) { n       ans += mod; n     } n     return ans; n   } n   int ans = 0; n   if (mas[t].ed[0] != -1) { n     ans = build(mas[t].ed[0], b - 1, x << 1); n   } n   if (mas[t].ed[1] != -1) { n     ans += build(mas[t].ed[1], b - 1, (x << 1) + 1); n     if (ans >= mod) { n       ans -= mod; n     } n   } n   return ans; n } n signed main() { n   t = my_new(); n   int n; n   cin >> n; n   vector<pair<long long, long long> > a(n); n   for (int i = 0; i < n; i++) { n     cin >> a[i].first >> a[i].second; n   } n   int m; n   cin >> m; n   vector<pair<long long, long long> > b(m); n   for (int i = 0; i < m; i++) { n     cin >> b[i].first >> b[i].second; n   } n   make(a); n   make(b); n   n = (int)a.size(); n   m = (int)b.size(); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       calc(a[i].first, a[i].second, b[j].first, b[j].second); n     } n   } n   st[0] = 1; n   for (int i = 1; i < maxlog; i++) { n     st[i] = st[i - 1] * 2 % mod; n   } n   int ans = build(t, 59, 0); n   cout << ans << endl; n } n


#include <bits/stdc++.h> n int a[100010], b[100010]; n bool check(int *a, int n, int id) { n   int cntt = 0; n   for (int i = 0; i < n; i++) { n     if (i == id) continue; n     b[cntt++] = a[i]; n   } n   if (cntt == 1) return true; n   for (int i = 1; i < cntt; i++) n     if (b[i - 1] == 0 && b[i] != 0) return false; n   if (cntt == 2) return true; n   for (int i = 1; i < cntt - 1; i++) { n     int num = b[i] * b[i]; n     if (num != b[i - 1] * b[i + 1]) return false; n   } n   return true; n } n bool check2(int *aa, int n) { n   for (int i = 0; i < n; i++) b[i] = aa[i]; n   int cntt = 0; n   if (b[0] == 0 && b[1] != 0) return false; n   if (b[1] == 0 && b[2] != 0) return false; n   if (b[1] * b[1] != b[0] * b[2]) return false; n   bool zero = true; n   int zeros = 0; n   for (int i = 0; i < 3; i++) { n     if (b[i] != 0) n       zero = false; n     else n       zeros++; n   } n   if (zeros != 0) { n     int cntt = 0; n     for (int i = 3; i < n; i++) n       if (b[i] != 0) cntt++; n     if (cntt == 1) return true; n     return false; n   } n   for (int i = 2; i < n; i++) { n     int next = b[i - 1] * b[i - 1]; n     if (next % b[i - 2] != 0) return false; n     next = next / b[i - 2]; n     if (next != b[i]) { n       cntt++; n       if (i != n - 1 && next != b[i + 1]) return false; n       i++; n       b[i - 1] = b[i - 2]; n     } n   } n   if (cntt == 1) return true; n   return false; n } n int main() { n   int n; n   while (scanf( %d , &n) == 1) { n     for (int i = 0; i < n; i++) scanf( %d , &a[i]); n     int zeros = 0; n     for (int i = 0; i < n; i++) n       if (a[i] == 0) zeros++; n     if (n == 1) { n       puts( 0 ); n       continue; n     } n     if (zeros == n) { n       puts( 0 ); n       continue; n     } n     if (zeros == n - 1 && a[0] == 0) { n       puts( 1 ); n       continue; n     } n     if (check(a, n, -1)) { n       puts( 0 ); n       continue; n     } n     if (check(a, n, 0) || check(a, n, 1) || check(a, n, 2)) { n       puts( 1 ); n       continue; n     } n     if (check2(a, n)) { n       puts( 1 ); n       continue; n     } n     puts( 2 ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, k, i, j; n   long long int flag = 0; n   cin >> n >> k; n   long long int m = n * n; n   long long int p; n   char a[1000][1000]; n   if (m % 2 == 0) { n     p = m / 2; n   } else { n     p = (m + 1) / 2; n   } n   if (k > p) { n     cout <<  NO  << endl; n   } else { n     cout <<  YES  << endl; n     for (i = 1; i <= n; i++) { n       for (j = 1; j <= n; j++) { n         a[i][j] =  S ; n       } n     } n     long long int c = 0; n     for (i = 1; i <= n; i++) { n       for (j = 1; j <= n; j++) { n         if (c == k) { n           flag = 1; n           break; n         } n         if (i % 2 != 0 && j % 2 != 0) { n           a[i][j] =  L ; n           c++; n         } n         if (i % 2 == 0 && j % 2 == 0) { n           a[i][j] =  L ; n           c++; n         } n       } n       if (flag == 1) { n         break; n       } n     } n     for (i = 1; i <= n; i++) { n       for (j = 1; j <= n; j++) { n         cout << a[i][j]; n       } n       cout << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   int ans = ((n - 1) * n * (n + 1)) / 3 - 2; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n const int MN = 2e2 + 10; n template <typename T> n bool ckmin(T& a, const T& b) { n   return b < a ? a = b, 1 : 0; n } n template <typename T> n bool ckmax(T& a, const T& b) { n   return b > a ? a = b, 1 : 0; n } n template <typename F, int MN, int MM> n struct MaxFlow { n  public: n   int hd[MN], to[MM * 2], nx[MM * 2], q[MN], cur[MN], lvl[MN], N, M, S, T; n   F flow[MM * 2], cap[MM * 2]; n   void init(int _N) { n     N = _N; n     memset(hd, -1, N * sizeof *hd); n   } n   void add1(int u, int v, F c) { n     flow[M] = 0, cap[M] = c; n     nx[M] = hd[u], to[M] = v, hd[u] = M++; n   } n   void adde(int u, int v, F c) { n     add1(u, v, c); n     add1(v, u, 0); n   } n   bool bfs() { n     memset(lvl, 0, N * sizeof *lvl); n     lvl[S] = 1; n     q[0] = S; n     for (int i = 0, Q = 1, x, y; i < Q; ++i) { n       x = q[i]; n       for (int j = hd[x]; ~j; j = nx[j]) n         if (cap[j] - flow[j] > 0 && !lvl[y = to[j]]) n           lvl[y] = lvl[x] + 1, q[Q++] = y; n     } n     return lvl[T]; n   } n   F dfs(int n, F f) { n     if (n == T) return f; n     for (int &i = cur[n], x; ~i; i = nx[i]) n       if (cap[i] - flow[i] > 0 && lvl[x = to[i]] == lvl[n] + 1) { n         F r = dfs(x, std::min(f, cap[i] - flow[i])); n         if (r > 0) return flow[i] += r, flow[1 ^ i] -= r, r; n       } n     return 0; n   } n   F saturate(int _S, int _T) { n     S = _S, T = _T; n     F ans = 0; n     while (bfs()) { n       F x; n       memcpy(cur, hd, N * sizeof *hd); n       for (bool ok = 0; x = dfs(S, 1);) n         if (x) n           ans += x, ok = 1; n         else if (ok) n           break; n         else n           return ans; n     } n     return ans; n   } n }; n MaxFlow<int, MN * MN * 2, MN * MN * 6> maxflow; n int N, M, cnt; n char a[MN][MN]; n int main() { n   scanf( %d%d , &N, &M); n   maxflow.init(N * M * 2 + 2); n   for (int i = 0; i < N; ++i) scanf(  %s , a[i]); n   for (int i = 0; i < N; ++i) n     for (int j = 0; j < M; ++j) n       if (a[i][j] ==  # ) { n         int u = i && a[i - 1][j] ==  #  ? i * M + j << 1 : -1; n         int d = i + 1 < N && a[i + 1][j] ==  #  ? (i + 1) * M + j << 1 : -1; n         int l = j && a[i][j - 1] ==  #  ? i * M + j << 1 | 1 : -1; n         int r = j + 1 < M && a[i][j + 1] ==  #  ? i * M + j + 1 << 1 | 1 : -1; n         if (~u && ~r) maxflow.adde(u, r, 1); n         if (~u && ~l) maxflow.adde(u, l, 1); n         if (~d && ~r) maxflow.adde(d, r, 1); n         if (~d && ~l) maxflow.adde(d, l, 1); n         ++cnt; n         cnt -= (u != -1) + (l != -1); n       } n   for (int i = 0; i < N * M; ++i) { n     maxflow.adde(N * M * 2, i * 2, 1); n     maxflow.adde(i * 2 + 1, N * M * 2 + 1, 1); n   } n   printf( %d n , cnt + maxflow.saturate(N * M * 2, N * M * 2 + 1)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n, x; n   cin >> n >> x; n   long long a[n]; n   for (auto &i : a) cin >> i; n   long long pre[n + 1]; n   pre[0] = 0; n   for (long long i = 1; i <= n; i++) pre[i] = (pre[i - 1] + a[i - 1]) % x; n   long long ans = 0; n   for (long long i = 1; i <= n; i++) { n     if (pre[i] != 0) ans = max(ans, i); n   } n   for (long long i = n; i >= 0; i--) { n     if (pre[i] != pre[n]) ans = max(ans, n - i); n   } n   if (ans == 0) n     cout << -1 <<   n ; n   else n     cout << ans <<   n ; n } n int32_t main() { n   long long t; n   cin >> t; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3fffffff; n const int SINF = 0x7fffffff; n const long long LINF = 0x3fffffffffffffff; n const long long SLINF = 0x7fffffffffffffff; n const long double DINF = pow(2, 100); n const int MAXN = 100007; n const long double EPS = 1e-17; n const long double AEPS = 1e-7; n const int TMS = 80; n const long double MAX = 4e9; n const long double PI = acos(-1.0); n class ftT { n  public: n   void clear() { memset(data, 0, sizeof(data)); } n   void upd(int p, int x) { n     for (; p < MAXN; p += p & -p) data[p] += x; n   } n   int sum(int p) { n     int ans = 0; n     for (; p; p ^= p & -p) ans += data[p]; n     return ans; n   } n   int query(int l, int r) { return sum(r) - sum(l - 1); } n  n  private: n   int data[MAXN]; n } ft; n struct eT { n   void setd(long double _t, long double _r, int _tp, int _id) { n     t = _t, r = _r, tp = _tp, id = _id; n   } n   bool operator<(const eT &a) const { n     return ((((t - a.t) >= 0) ? (t - a.t) : (-(t - a.t))) > EPS) ? t < a.t n            : (tp ^ a.tp)                                         ? (tp > a.tp) n                                                                  : (r < a.r); n   } n   long double t, r; n   int tp, id; n } ev[MAXN]; n int n, m; n int ke; n long double sx, sy; n long double la[MAXN], lb[MAXN]; n long double al[MAXN], ar[MAXN]; n int pl[MAXN], pr[MAXN]; n void init(); n void input(); n void work(); n void precheck(long double tst); n long long check(long double tst); n long double getsum(long double cr); n long double adj(long double ang); n long double getdist(int i, int j); n int main() { n   init(); n   input(); n   work(); n } n void init() { ios::sync_with_stdio(false); } n void input() { n   scanf( %d , &n); n   int tx, ty; n   scanf( %d%d%d , &tx, &ty, &m), sx = static_cast<long double>(tx) / 1000, n                                  sy = static_cast<long double>(ty) / 1000; n   for (int i = 1; i <= n; ++i) n     scanf( %d%d , &tx, &ty), la[i] = static_cast<long double>(tx) / 1000, n                              lb[i] = static_cast<long double>(ty) / 1000; n } n void work() { n   long double l = 0, r = MAX, mid; n   for (int _t = 0; _t < TMS; ++_t) { n     mid = l + (r - l) / 2; n     if (check(mid) >= m) n       r = mid; n     else n       l = mid; n   } n   long double maxd = l; n   while (check(l) >= m) l -= (((1) > (l)) ? (1) : (l)) * AEPS; n   int nc = check(l); n   cout << setprecision(13) << fixed << (getsum(l) + maxd * (m - nc)) << endl; n } n void precheck(long double tst) { n   long double sd, oa, da, a1, a2; n   for (int i = 1; i <= n; ++i) { n     sd = abs(la[i] * sx - sy + lb[i]) / sqrt(la[i] * la[i] + 1); n     if (sd > tst - EPS) n       al[i] = ar[i] = -DINF; n     else { n       if ((((la[i]) >= 0) ? (la[i]) : (-(la[i]))) < EPS) n         oa = PI / 2; n       else n         oa = atan(-1 / la[i]); n       if (oa < -EPS) oa += PI; n       if (la[i] * sx + lb[i] - sy < -EPS) oa += PI; n       da = acos(sd / tst); n       a1 = adj(oa + da), a2 = adj(oa - da); n       if (a1 > a2) swap(a1, a2); n       al[i] = a1, ar[i] = a2; n     } n   } n   ke = 0; n   for (int i = 1; i <= n; ++i) n     if (al[i] != -DINF) n       ev[++ke].setd(al[i], ar[i], 1, i), ev[++ke].setd(ar[i], ar[i], 0, i); n   sort(ev + 1, ev + 1 + ke); n   for (int i = 1; i <= ke; ++i) { n     if (ev[i].tp) n       pl[ev[i].id] = i; n     else n       pr[ev[i].id] = i; n   } n } n long long check(long double tst) { n   precheck(tst); n   long long ans = 0; n   int ni; n   ft.clear(); n   for (int i = 1; i <= ke; ++i) { n     if (ev[i].tp) { n       ni = ev[i].id; n       ans += ft.query(pl[ni], pr[ni]); n       ft.upd(pr[ni], 1); n     } n   } n   return ans; n } n long double getsum(long double cr) { n   precheck(cr); n   long double ans = 0; n   vector<pair<int, int> > ar; n   int ni, li; n   for (int i = 1; i <= ke; ++i) { n     if (ev[i].tp) { n       ni = ev[i].id; n       li = lower_bound(ar.begin(), ar.end(), make_pair(i, 0)) - ar.begin(); n       for (int j = li; j < ar.size() && ar[j].first <= pr[ni]; ++j) n         ans += getdist(ar[j].second, ni); n       ar.insert(upper_bound(ar.begin(), ar.end(), make_pair(pr[ni], INF)), n                 make_pair(pr[ni], ni)); n     } n   } n   return ans; n } n long double adj(long double ang) { n   while (ang < -EPS) ang += 2 * PI; n   while (ang > 2 * PI - EPS) ang -= 2 * PI; n   return ang; n } n long double getdist(int i, int j) { n   long double x = (lb[i] - lb[j]) / (la[j] - la[i]); n   long double y = (la[j] * lb[i] - la[i] * lb[j]) / (la[j] - la[i]); n   return sqrt((x - sx) * (x - sx) + (y - sy) * (y - sy)); n } n


#include <bits/stdc++.h> n using namespace std; n class segmentTree { n  public: n   int* tree; n   int N; n   int size; n   void update(int qidx, int val) { update(qidx, val, 0, N - 1, 0); } n   void update(int qidx, int val, int left, int right, int idx) { n     if (left == right && left == qidx) { n       tree[idx] = val; n     } else if (qidx >= left && qidx <= right) { n       int mid = (left + right) / 2; n       update(qidx, val, left, mid, 2 * idx + 1); n       update(qidx, val, mid + 1, right, 2 * idx + 2); n       tree[idx] = min(tree[2 * idx + 1], tree[2 * idx + 2]); n     } n   } n   int query(int qleft, int qright) { return query(qleft, qright, 0, N - 1, 0); } n   int query(int qleft, int qright, int left, int right, int index) { n     if (left >= qleft && right <= qright) return tree[index]; n     if (right < qleft || left > qright) return INT_MAX; n     int mid = (left + right) / 2; n     return min(query(qleft, qright, left, mid, 2 * index + 1), n                query(qleft, qright, mid + 1, right, 2 * index + 2)); n   } n   segmentTree(int n) { n     N = n; n     int start = 2; n     while ((start - 1) < 2 * N) start *= 2; n     size = start - 1; n     tree = new int[size]; n     memset(tree, -1, sizeof(int) * size); n   } n }; n const int MX = 1e5 + 69; n int used[MX], used2[MX]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   memset(used, 0, sizeof used); n   memset(used2, 0, sizeof used2); n   int n; n   cin >> n; n   segmentTree tree = segmentTree(n + 1); n   int totmex = 1; n   vector<int> submex; n   for (int i = 0; i < n; i++) { n     int w; n     cin >> w; n     used[w]++; n     while (used[totmex]) totmex++; n     if (w != 1) { n       submex.push_back(1); n     } else { n       tree.update(1, i); n       continue; n     } n     int lastw = tree.query(w, w); n     int minbelow = tree.query(1, w - 1); n     if (minbelow > lastw) submex.push_back(w); n     tree.update(w, i); n   } n   for (int w = 2; w <= n; w++) { n     int lastw = tree.query(w, w); n     int minbelow = tree.query(1, w - 1); n     if (minbelow > lastw) submex.push_back(w); n   } n   submex.push_back(totmex); n   for (int v : submex) used2[v]++; n   for (int ans = 1; ans < 1e9; ans++) n     if (!used2[ans]) { n       cout << ans <<   n ; n       exit(0); n     } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200010; n char s[N]; n vector<int> v[N]; n set<int> s1, s2; n set<int>::iterator j; n inline int gi() { n   int x = 0, o = 1; n   char ch = getchar(); n   while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar(); n   if (ch ==  - ) o = -1, ch = getchar(); n   while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar(); n   return x * o; n } n int main() { n   scanf( %s , s + 1); n   int n = strlen(s + 1), sum = 0, k = 0; n   for (int i = 1; i <= n; i++) { n     sum += s[i] -  0 ; n     if (sum + sum > i) return puts( -1 ), 0; n     if (s[i] ==  1 ) n       s1.insert(i); n     else n       s2.insert(i); n   } n   sum = 0; n   for (int i = n; i; i--) { n     sum += s[i] -  0 ; n     if (sum + sum > n - i + 1) return puts( -1 ), 0; n   } n   while (!s1.empty()) { n     int now = 0; n     bool flg = 0; n     ++k; n     while (now <= n) { n       if (!flg) { n         j = s2.lower_bound(now); n         if (j == s2.end()) break; n         now = (*j) + 1; n         v[k].push_back(*j); n       } else { n         j = s1.lower_bound(now); n         if (j == s1.end()) break; n         now = (*j) + 1; n         v[k].push_back(*j); n       } n       flg ^= 1; n     } n     for (int i = 0; i < v[k].size(); i++) { n       if (s[v[k][i]] ==  0 ) n         s2.erase(v[k][i]); n       else n         s1.erase(v[k][i]); n     } n   } n   for (j = s2.begin(); j != s2.end(); j++) v[++k].push_back(*j); n   cout << k << endl; n   for (int i = 1; i <= k; i++) { n     printf( %d  , (int)v[i].size()); n     for (int j = 0; j < v[i].size(); j++) printf( %d  , v[i][j]); n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5 * 1000000 + 100; n char str[maxn << 1], s[maxn]; n int p[maxn << 1]; n int ans; n int n; n int f[maxn << 1]; n void Init(void) { n   str[0] =  $ , str[1] =  # ; n   for (int i = 0; i < n; i++) { n     str[i * 2 + 2] = s[i]; n     str[i * 2 + 3] =  # ; n   } n   int nn = 2 * n + 2; n   str[nn] = 0; n   int mx = 0, id; n   for (int i = 1; i < nn; i++) { n     if (mx > i) { n       p[i] = min(p[2 * id - i], mx - i); n     } else n       p[i] = 1; n     while (str[i + p[i]] == str[i - p[i]]) p[i]++; n     if (i + p[i] > mx) mx = i + p[i], id = i; n   } n } n void solve(void) { n   long long ans = 0; n   for (int i = 1; i <= n; i++) { n     int l = 2, r = 2 * i; n     int m = (l + r) >> 1; n     if (p[m] * 2 - 1 >= r - l + 1) f[r] = f[m - 1 + ((m % 2) ? 0 : -1)] + 1; n     ans += f[r]; n   } n   printf( %I64d n , ans); n } n int main(void) { n   scanf( %s , s); n   n = strlen(s); n   Init(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n const int Maxn = 100005; n char s[Maxn]; n int n, q; n int seq[Maxn * 15]; n int pos[Maxn * 15]; n int sum[Maxn * 15][10]; n int Mx[Maxn * 15]; n int fir[Maxn]; n int prv[Maxn], nxt[Maxn]; n void Del(int np) { n   prv[nxt[np]] = prv[np]; n   nxt[prv[np]] = nxt[np]; n } n int Move(int np, int d) { return (d == 1) ? nxt[np] : prv[np]; } n int f(char c) { return (c ==  > ) ? 1 : -1; } n int tmin[Maxn * 60], tmax[Maxn * 60]; n void build(int push, int l, int r) { n   if (l == r) { n     tmin[push] = tmax[push] = pos[l]; n     return; n   } n   int mid = l + r >> 1; n   build(push * 2, l, mid); n   build(push * 2 + 1, mid + 1, r); n   tmin[push] = min(tmin[push * 2], tmin[push * 2 + 1]); n   tmax[push] = max(tmax[push * 2], tmax[push * 2 + 1]); n } n int queryMin(int push, int l, int r, int lo, int lim) { n   if (tmin[push] >= lim) { n     return -1; n   } n   if (l == r) { n     return l; n   } n   int mid = l + r >> 1; n   if (lo <= mid) { n     int ans = queryMin(push * 2, l, mid, lo, lim); n     if (ans != -1) { n       return ans; n     } n   } n   return queryMin(push * 2 + 1, mid + 1, r, max(mid + 1, lo), lim); n } n int queryMax(int push, int l, int r, int lo, int lim) { n   if (tmax[push] <= lim) { n     return -1; n   } n   if (l == r) { n     return l; n   } n   int mid = l + r >> 1; n   if (lo <= mid) { n     int ans = queryMax(push * 2, l, mid, lo, lim); n     if (ans != -1) { n       return ans; n     } n   } n   return queryMax(push * 2 + 1, mid + 1, r, max(mid + 1, lo), lim); n } n int main() { n   scanf( %d %d , &n, &q); n   scanf( %s , s + 1); n   memset(seq, -1, sizeof(seq)); n   for (int i = 1; i <= n; i++) { n     fir[i] = 1e9; n     prv[i] = i - 1; n     nxt[i] = i + 1; n   } n   int np = 1, Mxp = 1; n   int dir = 1; n   int nst = 1; n   while (1) { n     for (;;) { n       if (np == 0 || np == n + 1) { n         pos[nst] = np; n         Mxp = max(Mxp, np); n         fir[Mxp] = min(fir[Mxp], nst); n         Mx[nst++] = Mxp; n         break; n       } n       if (s[np] >=  0  && s[np] <=  9 ) { n         seq[nst] = s[np] -  0 ; n         pos[nst] = np; n         Mxp = max(Mxp, np); n         if (s[np] !=  0 ) { n           s[np]--; n         } else { n           Del(np); n         } n         np = Move(np, dir); n         fir[Mxp] = min(fir[Mxp], nst); n         Mx[nst++] = Mxp; n       } else if (s[np] ==  >  || s[np] ==  < ) { n         pos[nst] = np; n         Mxp = max(Mxp, np); n         fir[Mxp] = min(fir[Mxp], nst); n         Mx[nst++] = Mxp; n         dir = f(s[np]); n         int newpos = Move(np, dir); n         if (newpos >= 1 && newpos <= n && n             (s[newpos] ==  <  || s[newpos] ==  > )) { n           Del(np); n         } n         np = newpos; n       } n     } n     if (Mxp >= n) break; n     np = Mxp + 1; n     dir = 1; n   } n   nst--; n   for (int i = 1; i <= nst; i++) { n     for (int j = 0; j < 10; j++) { n       sum[i][j] = sum[i - 1][j]; n     } n     if (seq[i] >= 0 && seq[i] <= 9) { n       sum[i][seq[i]]++; n     } n   } n   build(1, 1, nst); n   for (int i = 1; i <= q; i++) { n     int l, r; n     scanf( %d %d , &l, &r); n     int st = fir[l]; n     int ed1 = queryMin(1, 1, nst, st + 1, l), n         ed2 = queryMax(1, 1, nst, st + 1, r); n     if (ed1 == -1) ed1 = nst + 1; n     if (ed2 == -1) ed2 = nst + 1; n     int ed = min(ed1, ed2) - 1; n     for (int j = 0; j < 10; j++) { n       printf( %d  , sum[ed][j] - sum[st - 1][j]); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100005]; n int t[400005]; n int d[400005]; n pair<int, int> p[305]; n pair<int, int> cp[305]; n int n; n void build(int l, int r, int i) { n   d[i] = 0; n   if (l == r) n     t[i] = a[l]; n   else { n     int m = (l + r) / 2; n     int L = 2 * i; n     build(l, m, L); n     build(m + 1, r, L + 1); n     t[i] = (t[L] < t[L + 1] ? t[L] : t[L + 1]); n   } n } n void update(int l, int r, int p, int x, int y, int i) { n   if (l > y || r < x) return; n   if (l <= x && r >= y) { n     d[i] += p; n     t[i] += p; n     return; n   } n   int m = (x + y) / 2; n   int L = 2 * i; n   update(l, r, p, x, m, L); n   update(l, r, p, m + 1, y, L + 1); n   t[i] = (t[L] < t[L + 1] ? t[L] : t[L + 1]) + d[i]; n } n bool comp(pair<int, int> x, pair<int, int> y) { return (x.second < y.second); } n int main() { n   ios::sync_with_stdio(false); n   int m; n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < m; i++) { n     cin >> p[i].first >> p[i].second; n     p[i].first--; n     p[i].second--; n     cp[i] = p[i]; n   } n   sort(p, p + m); n   int v = 0, an = -1000000007; n   build(0, n - 1, 1); n   for (int j = m - 1, i = n - 1; i >= 0; i--) { n     if (an < a[i] - t[1]) { n       an = a[i] - t[1]; n       v = i; n     } n     while (j >= 0 && p[j].first >= i) { n       update(p[j].first, p[j].second, -1, 0, n - 1, 1); n       j--; n     } n   } n   sort(p, p + m, comp); n   build(0, n - 1, 1); n   for (int j = 0, i = 0; i < n; i++) { n     if (an < a[i] - t[1]) { n       an = a[i] - t[1]; n       v = i; n     } n     while (j < m && p[j].second <= i) { n       update(p[j].first, p[j].second, -1, 0, n - 1, 1); n       j++; n     } n   } n   cout << an << endl; n   int c = 0; n   for (int i = 0; i < m; i++) { n     if (v < p[i].first || v > p[i].second) c++; n   } n   cout << c << endl; n   for (int i = 0; i < m; i++) { n     if (v < cp[i].first || v > cp[i].second) cout << i + 1 <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n vector<vector<pair<long long, long long>>> adj; n vector<long long> dist; n vector<bool> visited; n void djikstra(long long src) { n   priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, n                  greater<pair<long long, long long>>> n       s; n   s.push({0, src}); n   while (!s.empty()) { n     long long u = s.top().second; n     long long d_u = dist[u]; n     s.pop(); n     if (visited[u]) n       continue; n     else n       visited[u] = true; n     for (auto x : adj[u]) { n       long long v = x.first; n       long long w = x.second; n       if (dist[v] > (dist[u] + w)) { n         dist[v] = dist[u] + w; n         s.push({dist[v], v}); n       } n     } n   } n } n void solve() { n   long long n, m; n   cin >> n >> m; n   adj.resize(n + 1); n   dist.resize(n + 1, LLONG_MAX); n   visited.resize(n + 1, false); n   for (long long i = 0; i < m; ++i) { n     long long u, v, w; n     cin >> u >> v >> w; n     adj[u].push_back({v, 2 * w}); n     adj[v].push_back({u, 2 * w}); n   } n   for (long long i = 0; i < n; ++i) { n     long long temp; n     cin >> temp; n     adj[0].push_back({i + 1, temp}); n   } n   dist[0] = 0; n   djikstra(0); n   for (long long i = 1; i <= n; ++i) { n     cout << dist[i] <<    ; n   } n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t = 1; n   long long i, j; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x, y; n   cin >> x >> y; n   y--; n   if ((y > x) || y == -1 || (x - y) % 2 != 0 || (!y && x)) n     cout <<  NO ; n   else n     cout <<  YES ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   set<string> a; n   vector<string> s(n); n   for (int i = 0; i < n; i++) { n     cin >> s[i]; n   } n   for (int i = n - 1; i >= 0; i--) { n     if (a.count(s[i]) == 0) { n       cout << s[i] << endl; n       a.insert(s[i]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Z = (int)1e5 + 111; n const int INF = (int)1e9 * 2 + 111; n int n, m, k; n bool can(long long x) { n   int u = k; n   int one = x, two = max(x - k + 1, (long long)1); n   long long p = ((long long)one + two) * ((long long)one - two + 1) / 2; n   p += (long long)k - ((long long)one - two + 1); n   one = x; n   two = max(x - (n - k), (long long)1); n   p += ((long long)one + two) * ((long long)one - two + 1) / 2 - x; n   p += (long long)n - k - ((long long)one - two); n   if (p <= m) return 1; n   return 0; n } n int main() { n   cin >> n >> m >> k; n   int l = 1, r = m + 1; n   while (l < r - 1) { n     int mid = (l + r) / 2; n     if (can(mid)) n       l = mid; n     else n       r = mid; n   } n   cout << l; n   return 0; n } n


#include <bits/stdc++.h> n const int Maxn = 1000 * 1000 + 10; n using namespace std; n int main() { n   vector<int> A[10000]; n   int B[10000]; n   int n; n   cin >> n; n   n *= 2; n   int e[10000]; n   for (int i = 0; i < n; i++) { n     int a; n     cin >> a; n     A[a].push_back(i); n     B[i] = a; n   } n   bool k = true; n   int size1 = 0, size2 = 0; n   int s1 = 0, s2 = 0; n   for (int i = 10; i <= 99; i++) { n     if (A[i].size() > 1) { n       for (int j = 0; j < 2; j++) { n         if (j % 2 == 0) n           e[A[i][A[i].size() - 1]] = 1; n         else n           e[A[i][A[i].size() - 1]] = 2; n         A[i].pop_back(); n       } n       s1++; n       s2++; n       size1++; n       size2++; n     } else if (A[i].size() == 0) n       continue; n     else { n       if (k) { n         e[A[i][0]] = 1; n         size1++; n         s1++; n       } else { n         s2++; n         size2++; n         e[A[i][0]] = 2; n       } n       k = !k; n       A[i].pop_back(); n     } n   } n   cout << s1 * s2 << endl; n   for (int i = 0; i < n; i++) { n     while (!A[B[i]].empty()) { n       if (size1 < n / 2) { n         e[A[B[i]][A[B[i]].size() - 1]] = 1; n         size1++; n         A[B[i]].pop_back(); n       } else { n         e[A[B[i]][A[B[i]].size() - 1]] = 2; n         size2++; n         A[B[i]].pop_back(); n       } n     } n   } n   for (int i = 0; i < n; i++) { n     cout << e[i] <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5001; n int n, k, a[N * 60]; n long long dp[N][N]; n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 0; i < n; i++) scanf( %d , a + i); n   sort(a, a + n); n   for (int i = 0; i < N; i++) n     for (int j = 0; j < N; j++) dp[i][j] = 5e18; n   dp[k - n % k][n % k] = 0; n   for (int i = k - n % k; i + 1; i--) n     for (int j = n % k; j + 1; j--) { n       if (i) { n         int last = n / k * (k - n % k - i) + (n / k + 1) * (n % k - j); n         dp[i - 1][j] = n             min(dp[i - 1][j], dp[i][j] + a[last + n / k - 1] - a[last]); n       } n       if (j) { n         int last = n / k * (k - n % k - i) + (n / k + 1) * (n % k - j); n         dp[i][j - 1] = min(dp[i][j - 1], dp[i][j] + a[last + n / k] - a[last]); n       } n     } n   printf( %lld n , dp[0][0]); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, s, a[1000]; n   int max = 0; n   scanf( %d%d , &n, &s); n   int sum = 0; n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     if (a[i] > max) max = a[i]; n   } n   int flag = 1; n   for (int i = 0; i < n; i++) { n     if (a[i] == max && flag) { n       flag = 0; n     } else { n       sum += a[i]; n     } n   } n   if (sum <= s) n     printf( YES n ); n   else n     printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int pos[200003]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n, x, l = 0, r = 0; n   char c; n   cin >> n; n   cin >> c >> x; n   n--; n   while (n--) { n     cin >> c >> x; n     if (c ==  L ) { n       pos[x] = --l; n     } else if (c ==  R ) { n       pos[x] = ++r; n     } else { n       cout << min(r - pos[x], pos[x] - l) <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int l[7]; n int main() { n   scanf( %d%d%d , &l[3], &l[4], &l[5]); n   double a, A, ap, r, anw = 0; n   for (int n = 3; n <= 5; n++) { n     a = acos(-1) / n; n     A = 1.0 * n / 4 * l[n] * l[n] / tan(a); n     ap = A * 2 / n / l[n]; n     r = ap / cos(a); n     anw += A * sqrt(l[n] * l[n] - r * r) / 3; n   } n   printf( %.10lf , anw); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(NULL); n   int tc; n   cin >> tc; n   while (tc--) { n     int n; n     cin >> n; n     int sum = (n % 10 - 1) * 10; n     if (1 <= n) sum += 1; n     if (10 <= n) sum += 2; n     if (100 <= n) sum += 3; n     if (1000 <= n) sum += 4; n     cout << sum <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 998244353, N = 510; n int n, m, a[N], st[N][12], g[N][12], dp[N][N]; n int solve(int l, int r) { n   if (dp[l][r]) return dp[l][r]; n   if (l > r) return 1; n   long long r1 = 0, r2 = 0; n   int pos, lo = log2(r - l + 1); n   if (st[l][lo] < st[r - (1 << lo) + 1][lo]) n     pos = g[l][lo]; n   else n     pos = g[r - (1 << lo) + 1][lo]; n   for (int i = l; i <= pos; i++) n     r1 += 1ll * solve(l, i - 1) * solve(i, pos - 1) % mod; n   for (int i = pos; i <= r; i++) n     r2 += 1ll * solve(pos + 1, i) * solve(i + 1, r) % mod; n   r1 %= mod; n   r2 %= mod; n   return dp[l][r] = 1ll * r1 * r2 % mod; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]), st[i][0] = a[i], g[i][0] = i; n   for (int i = 1; (1 << i) <= n; i++) { n     for (int j = 1; j + (1 << i) - 1 <= n; j++) { n       int y = j + (1 << (i - 1)); n       if (st[j][i - 1] < st[y][i - 1]) n         g[j][i] = g[j][i - 1]; n       else n         g[j][i] = g[y][i - 1]; n       st[j][i] = min(st[j][i - 1], st[y][i - 1]); n     } n   } n   printf( %d n , solve(1, n)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e6 + 7; n int cnt[N], a[N], idx, l, r, n; n long long ans, sum; n int main() { n   scanf( %d , &n); n   for (int i = (1); i <= (n); ++i) { n     scanf( %d , a + i); n     if (a[i] >= i) n       l++, cnt[a[i] - i]++; n     else n       r++; n     ans += abs(a[i] - i); n   } n   sum = ans, idx = 0; n   for (int i = (0); i <= ((n - 1)); ++i) { n     l -= cnt[i], r += cnt[i]; n     sum = sum - l + r - abs(a[n - i] - n) + a[n - i] - 2; n     cnt[a[n - i] + i]++, l++, r--; n     if (sum < ans) ans = sum, idx = i + 1; n   } n   printf( %lld %d n , ans, idx); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 10; n vector<long long> presum(maxn, 0); n int main() { n   int last = 0; n   for (long long i = 1; i < maxn; ++i) { n     presum[i] = presum[i - 1] + min(i, 9LL); n     if (i >= 10 && i < 100) { n       presum[i] = presum[i] + (2LL * (i - 9LL)); n     } else if (i >= 100 && i < 1000) { n       presum[i] = presum[i] + (2LL * 90LL) + (3LL * (i - 99LL)); n     } else if (i >= 1000 && i < 10000) { n       presum[i] = n           presum[i] + (2LL * 90LL) + (3LL * 900LL) + (4LL * (i - 999LL)); n     } else if (i >= 10000 && i < 100000) { n       presum[i] = presum[i] + (2LL * 90LL) + (3LL * 900LL) + (4LL * 9000LL) + n                   (5LL * (i - 9999LL)); n     } else if (i >= 100000 && i < 1000000) { n       presum[i] = presum[i] + (2LL * 90LL) + (3LL * 900LL) + (4LL * 9000LL) + n                   (5LL * 90000LL) + (6LL * (i - 99999LL)); n     } else if (i >= 1000000 && i < 10000000) { n       presum[i] = presum[i] + (2LL * 90LL) + (3LL * 900LL) + (4LL * 9000LL) + n                   (5LL * 90000LL) + (6LL * 900000LL) + (7LL * (i - 999999LL)); n     } n   } n   int q; n   cin >> q; n   while (q--) { n     long long k; n     cin >> k; n     int it = lower_bound(presum.begin(), presum.end(), k) - presum.begin(); n     string aux =   ; n     for (int i = 1; i <= it; ++i) { n       aux += to_string(i); n     } n     cout << aux[k - (presum[it - 1] + 1)] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /stack:200000000 ) n #pragma GCC optimize( Ofast ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n template <class T> n inline T bigmod(T p, T e, T M) { n   long long ret = 1; n   for (; e > 0; e >>= 1) { n     if (e & 1) ret = (ret * p) % M; n     p = (p * p) % M; n   } n   return (T)ret; n } n template <class T> n inline T gcd(T a, T b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n template <class T> n inline T modinverse(T a, T M) { n   return bigmod(a, M - 2, M); n } n template <class T> n inline T lcm(T a, T b) { n   a = abs(a); n   b = abs(b); n   return (a / gcd(a, b)) * b; n } n template <class T, class X> n inline bool getbit(T a, X i) { n   T t = 1; n   return ((a & (t << i)) > 0); n } n template <class T, class X> n inline T setbit(T a, X i) { n   T t = 1; n   return (a | (t << i)); n } n template <class T, class X> n inline T resetbit(T a, X i) { n   T t = 1; n   return (a & (~(t << i))); n } n inline long long getnum() { n   char c = getchar(); n   long long num, sign = 1; n   for (; c <  0  || c >  9 ; c = getchar()) n     if (c ==  - ) sign = -1; n   for (num = 0; c >=  0  && c <=  9 ;) { n     c -=  0 ; n     num = num * 10 + c; n     c = getchar(); n   } n   return num * sign; n } n inline long long power(long long a, long long b) { n   long long multiply = 1; n   for (int i = (0); i < (b); i++) { n     multiply *= a; n   } n   return multiply; n } n string s; n int ans = 1e6; n int main() { n   int test, cases = 1; n   cin >> s; n   int n = s.size(); n   for (int i = 0; i < 26; i++) { n     int last = 0, d = 0; n     for (int j = 0; j < n; j++) { n       if (s[j] -  a  == i) { n         d = max(d, j + 1 - last); n         last = j + 1; n       } n     } n     d = max(d, n + 1 - last); n     ans = min(ans, d); n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int len, cnt[8010], f[8010], nxt[8010]; n char st[8010]; n void kmp(char *st, int len, int nxt[]) { n   nxt[0] = nxt[1] = 0; n   for (int i = 1; i < len; i++) { n     int j = nxt[i]; n     while (j && st[i] != st[j]) { n       j = nxt[j]; n     } n     nxt[i + 1] = st[j] == st[i] ? j + 1 : 0; n   } n } n int main() { n   cin >> st; n   len = strlen(st); n   for (int i = 1; i <= len; i++) { n     cnt[i] = cnt[i / 10] + 1, f[i] = i + 1; n   } n   for (int i = 0; i < len; i++) { n     kmp(st + i, len - i, nxt); n     for (int j = 1; j + i <= len; j++) { n       if (j % (j - nxt[j]) == 0) { n         f[j + i] = min(f[j + i], f[i] + cnt[j / (j - nxt[j])] + (j - nxt[j])); n       } else { n         f[j + i] = min(f[j + i], f[i] + 1 + j); n       } n     } n   } n   cout << f[len]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct query { n   int Q, id; n   long long res; n }; n const int Nmax = 200001; n int n, m, parent[Nmax], Rank[Nmax]; n vector<pair<int, pair<int, int> > > edge; n bool cmpQ(const query &q1, const query &q2) { return q1.Q < q2.Q; } n bool ret(const query &q1, const query &q2) { return q1.id < q2.id; } n int Find(const int &i) { n   if (i == parent[i]) return i; n   return parent[i] = Find(parent[i]); n } n void Union(const int &i, const int &j) { n   int x = Find(i), y = Find(j); n   if (x != y) { n     if (Rank[x] > Rank[y]) { n       parent[y] = x; n       Rank[x] += Rank[y]; n     } else { n       parent[x] = y; n       Rank[y] += Rank[x]; n     } n   } n } n int main() { n   if (fopen( 1213G  n              .INP , n              r )) { n     freopen( n          1213G  n          .INP , n          r , stdin); n     freopen( n          1213G  n          .OUT , n          w , stdout); n   } n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   scanf( %d %d , &n, &m); n   for (int i = 1, _n = (n); i <= _n; ++i) parent[i] = i, Rank[i] = 1; n   edge.resize(n - 1); n   int u, v, w, q; n   for (int i = 0, _n = (n - 1); i < _n; ++i) n     scanf( %d %d %d , &edge[i].second.first, &edge[i].second.second, n           &edge[i].first); n   sort(edge.begin(), edge.end()); n   vector<query> qu(m); n   for (int i = 0, _n = (m); i < _n; ++i) { n     scanf( %d , &qu[i].Q); n     qu[i].id = i; n   } n   sort(qu.begin(), qu.end(), cmpQ); n   int j = 0; n   long long ans = 0; n   for (int i = 0, _n = (m); i < _n; ++i) { n     for (; j < n - 1; ++j) { n       if (edge[j].first <= qu[i].Q) { n         ans += (long long)Rank[Find(edge[j].second.first)] * n                Rank[Find(edge[j].second.second)]; n         Union(edge[j].second.first, edge[j].second.second); n       } else n         break; n     } n     qu[i].res = ans; n   } n   sort(qu.begin(), qu.end(), ret); n   for (int i = 0, _n = (m); i < _n; ++i) cout << qu[i].res <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s1, s2, s; n   int cnt, i; n   while (cin >> s1 >> s2) { n     sort(s1.begin(), s1.end()); n     for (s.clear(), cnt = i = 0; i < s1.size() && s1[i] ==  0 ; ++cnt, ++i) n       ; n     if (i < s1.size()) s += s1[i++]; n     while (cnt--) s +=  0 ; n     for (; i < s1.size(); s += s1[i], ++i) n       ; n     if (s == s2) n       cout <<  OK n ; n     else n       cout <<  WRONG_ANSWER n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int sol[] = {19, 873, 834, 665}; n int main() { n   int a, b; n   bool found = false; n   cin >> a >> b; n   for (int i = 0; i < (int)sizeof(sol) / (int)sizeof(int); i++) { n     found = true; n     break; n   } n   if (found) n     cout << a + b << endl; n   else n     cout << 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long x, y; n   cin >> x >> y; n   cout << (x + x % 2) * (y + y % 2) * (x / 2) / 2 * (y / 2) / 2; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000000000000003; n long long powmod(long long a, long long b) { n   long long res = 1; n   a %= mod; n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n   } n   return res; n } n const int N = 601000; n int n, m; n long long pw[N]; n char s[N]; n unordered_set<long long> ff; n int main() { n   scanf( %d%d , &n, &m); n   pw[0] = 1; n   for (int i = 1; i < 600001; i++) pw[i] = pw[i - 1] * 3 % mod; n   for (int i = 0; i < n; i++) { n     scanf( %s , s); n     int l = strlen(s); n     long long hs = 0; n     for (int j = 0; j < l; j++) hs = (hs * 3 + s[j] -  a ) % mod; n     ff.insert(hs); n   } n   for (int i = 0; i < m; i++) { n     scanf( %s , s); n     int l = strlen(s); n     long long hs = 0; n     bool fg = 0; n     for (int j = 0; j < l; j++) hs = (hs * 3 + s[j] -  a ) % mod; n     for (int j = 0; j < l; j++) { n       long long nhs = (hs - (s[l - 1 - j] -  a ) * pw[j]) % mod; n       if (nhs < 0) nhs += mod; n       for (int k = 0; k < 3; k++) n         if (s[l - 1 - j] -  a  != k) { n           if (ff.count((nhs + k * pw[j]) % mod)) fg = 1; n         } n       if (fg) break; n     } n     puts(fg ?  YES  :  NO ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int m, n; n   cin >> n >> m; n   int flag = 0, j, i; n   for (i = n + 1; i <= m; i++) { n     flag = 0; n     for (j = 2; j * j <= i; j++) { n       if (i % j == 0) { n         flag = 1; n         break; n       } n     } n     if (flag == 0) { n       break; n     } n   } n   if (i != m) n     cout <<  NO ; n   else n     cout <<  YES ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   long long n, k; n   cin >> n >> k; n   string s[n - k + 1]; n   for (long long i = 0; i <= n - k; i++) cin >> s[i]; n   string c[50]; n   long long i1 = 65; n   for (long long i = 0; i < 26; i++) { n     c[i] = i1; n     i1++; n   } n   i1 = 65; n   for (long long i = 26; i < 50; i++) { n     c[i] = i1; n     c[i] +=  a ; n     i1++; n   } n   string ans[n]; n   i1 = 0; n   for (long long i = 0; i < n; i++) { n     ans[i] = c[i1]; n     i1++; n   } n   for (long long i = 0; i <= n - k; i++) { n     if (s[i] ==  NO ) { n       ans[i + k - 1] = ans[i]; n     } n   } n   for (long long i = 0; i < n; i++) cout << ans[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[1000010]; n long long cnt[1000010]; n int main() { n   ios::sync_with_stdio(0); n   int n; n   cin >> n; n   long long s = 0; n   for (int i = 0; i < n; ++i) { n     cin >> a[i]; n     s += a[i]; n   } n   if (s % 3 != 0) n     cout <<  0 n ; n   else { n     s /= 3; n     long long ss = 0; n     for (int i = n - 1; i >= 0; --i) { n       ss += a[i]; n       if (ss == s) cnt[i] = 1; n     } n     for (int i = n - 2; i >= 0; --i) cnt[i] += cnt[i + 1]; n     long long ans = 0; n     ss = 0; n     for (int i = 0; i + 2 < n; ++i) { n       ss += a[i]; n       if (ss == s) ans += cnt[i + 2]; n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     if (i % 4 == 1 or i % 4 == 3) { n       for (int j = 0; j < m; j++) { n         cout <<  # ; n       } n       cout <<   n ; n     } else if (i % 4 == 2) { n       for (int k = 0; k < m - 1; k++) { n         cout <<  . ; n       } n       cout <<  #  <<   n ; n     } else if (i % 4 == 0) { n       cout <<  # ; n       for (int l = 0; l < m - 1; l++) { n         cout <<  . ; n       } n       cout <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   if (!b) return a; n   return gcd(b, a % b); n } n long long fpow(long long a, long long b, long long mod) { n   long long res = 1ll; n   while (b) { n     if (b & 1) res = (res * a) % mod; n     a = (a * a) % mod; n     b >>= 1; n   } n   return res; n } n long long mul(long long a, long long b, long long mod) { n   long long res = 0; n   while (b) { n     if (b & 1) res = (res + a) % mod; n     a = (a + a) % mod; n     b >>= 1; n   } n   return res; n } n const long long mod = 2015; n const double eps = 1e-3; n const double pi = acos(-1); n const long long N = 5005; n double dp[N]; n struct node { n   int x, y, ti; n   double pi; n   bool operator<(const node &o) const { return ti < o.ti; } n } a[N]; n double dis(long long x, long long y) { n   return sqrt((a[x].x - a[y].x) * (a[x].x - a[y].x) + n               (a[x].y - a[y].y) * (a[x].y - a[y].y)); n } n int main() { n   long long n; n   scanf( %lld , &n); n   for (long long i = 1; i <= n; i++) n     cin >> a[i].x >> a[i].y >> a[i].ti >> a[i].pi; n   sort(a + 1, a + 1 + n); n   double ans = 0; n   for (long long i = 1; i <= n; i++) { n     dp[i] = a[i].pi; n     for (long long j = 1; j <= i - 1; j++) { n       if (a[i].ti - a[j].ti - dis(i, j) > -eps) n         dp[i] = max(dp[j] + a[i].pi, dp[i]); n     } n     ans = max(dp[i], ans); n   } n   printf( %.8lf , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char a[100005], ans[100005]; n int main() { n   int n, m; n   cin >> n; n   while (n--) { n     cin >> a; n     m = strlen(a); n     for (int i = 0; i < m; i++) { n       if (a[i] !=  ? ) { n         if (ans[i] == 0) n           ans[i] = a[i]; n         else if (a[i] != ans[i]) n           ans[i] =  ? ; n       } n     } n   } n   ans[m] = 0; n   for (int i = 0; i < m; i++) { n     if (ans[i] == 0) ans[i] =  a ; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, l, minc, maxc; n   string s; n   cin >> n; n   map<int, int> dict; n   for (int i = 0; i < n; i++) { n     cin >> s; n     l = s.length(); n     if (l == 1) { n       cout <<  YES  n            <<   n ; n       continue; n     } n     for (int j = 0; j < l; j++) { n       if (j == 0) { n         minc = int(s[j]); n         maxc = int(s[j]); n         dict[int(s[j])] += 1; n         continue; n       } n       if (minc > int(s[j])) { n         minc = int(s[j]); n       } n       if (maxc < int(s[j])) { n         maxc = int(s[j]); n       } n       dict[int(s[j])] += 1; n     } n     for (int h = minc; h <= maxc; h++) { n       if (dict[h] == 1) { n         if (h == maxc) { n           cout <<  YES  n                <<   n ; n           break; n         } n         continue; n       } else { n         cout <<  NO  n              <<   n ; n         break; n       } n     } n     dict.clear(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double x[150], y[150], z[150], a = 0, b = 0, c = 0; n double dist(double x, double y, double z) { return x * x + y * y + z * z; } n int main() { n   int i, n, ij, j; n   double bit = 1, t, temp; n   cin >> n; n   for (i = 1; i <= n; i++) cin >> x[i] >> y[i] >> z[i]; n   for (i = 1; i <= 50000; i++) { n     t = -1; n     ij = 0; n     for (j = 1; j <= n; j++) { n       temp = dist(x[j] - a, y[j] - b, z[j] - c); n       if (temp > t) { n         t = temp; n         ij = j; n       } n     } n     a += bit * (x[ij] - a); n     b += bit * (y[ij] - b); n     c += bit * (z[ij] - c); n     bit *= 0.998; n   } n   printf( %.10f %.10f %.10f n , a, b, c); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s, t; n   cin >> s; n   cin >> t; n   long int n, m, sum; n   n = s.size(); n   m = t.size(); n   long int count = 0; n   if (s.size() == 0 && t.size() == 0) { n     cout << 0; n   } else if (s.size() == 0 && t.size() != 0) { n     cout << t.size(); n   } else if (t.size() == 0 && s.size() != 0) { n     cout << s.size(); n   } else if (s == t) { n     cout << 0; n   } else { n     while (s[n - 1] == t[m - 1]) { n       count++; n       n--; n       m--; n     } n     sum = (s.size() - count) + (t.size() - count); n     cout << sum; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int x = 0, ch; n   while (!isdigit(ch = getchar())) n     ; n   while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); n   return x; n } n const int MAXN = 500000; n const int mod = 1000000007; n int n; n int a[MAXN + 1]; n int v[MAXN + 1]; n int T[MAXN + 1]; n inline void Add(int& a, int b) { n   a += b; n   a -= a >= mod ? mod : 0; n } n inline void Modify(int p, int x) { n   while (p <= MAXN) Add(T[p], x), p += p & -p; n } n inline int Query(int p) { n   int res = 0; n   while (p) Add(res, T[p]), p ^= p & -p; n   return res; n } n inline int pos(int x) { return lower_bound(v + 1, v + 1 + n, x) - v; } n int main() { n   n = read(); n   int res = 0; n   for (int i = 1; i <= n; i++) n     a[i] = v[i] = read(), Add(res, 1LL * a[i] * i % mod * (n - i + 1) % mod); n   sort(v + 1, v + 1 + n); n   for (int i = 1; i <= n; i++) a[i] = pos(a[i]); n   for (int i = 1; i <= n; i++) { n     Add(res, 1LL * (n - i + 1) * (Query(n) - Query(a[i]) + mod) % mod); n     Modify(a[i], 1LL * v[a[i]] * i % mod); n   } n   memset(T, 0, sizeof(T)); n   for (int i = n; i >= 1; i--) { n     Add(res, 1LL * i * (Query(n) - Query(a[i]) + mod) % mod); n     Modify(a[i], 1LL * v[a[i]] * (n - i + 1) % mod); n   } n   printf( %d n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int m = 31623; n int nim[] = { n     0, 1, 2, 1, 4, 3, 2, 1, 5, 6,  2, 1, 8, 7,  5, n     9, 8, 7, 3, 4, 7, 4, 2, 1, 10, 9, 3, 6, 11, 12, n }; n bool isLarge[m]; n int n; n int main(void) { n   cin >> n; n   memset(isLarge, true, sizeof(isLarge)); n   for (int i = 2; i < m; i++) n     if (isLarge[i]) { n       for (int j = i * i; j < m; j *= i) isLarge[j] = false; n     } n   int ans = 0; n   int left = n; n   for (int i = 2; i < min(n + 1, m); i++) { n     if (isLarge[i]) { n       int cnt = 0; n       for (long long j = 1; j <= n; j *= i, cnt++) n         ; n       cnt--; n       ans = ans ^ nim[cnt]; n       left -= cnt; n     } n   } n   if (left % 2 == 1) ans = ans ^ 1; n   if (ans) n     cout <<  Vasya  << endl; n   else n     cout <<  Petya  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long f[505][505]; n int main() { n   int n, k; n   scanf( %d%d , &n, &k); n   for (int i = 0; i <= n; i++) f[0][i] = 1; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       for (int k = 0; k < j; k++) { n         (f[j][i] += f[k][i - 1] * f[j - k - 1][i - 1]); n       } n     } n   } n   printf( %lld , f[n][n] - f[n][k - 1]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1000000000; n int n; n int x[300010]; n int y[300010]; n pair<int, int> izq, der, down, up; n int ereccion(int i, int j, int k) { n   vector<int> pito, ura; n   pito.push_back(x[i]); n   pito.push_back(x[j]); n   pito.push_back(x[k]); n   ura.push_back(y[i]); n   ura.push_back(y[j]); n   ura.push_back(y[k]); n   sort(pito.begin(), pito.end()); n   sort(ura.begin(), ura.end()); n   return pito.back() - pito[0] + ura.back() - ura[0]; n } n int triangulo() { n   set<int> pingo; n   pingo.insert(der.second); n   pingo.insert(izq.second); n   pingo.insert(up.second); n   pingo.insert(down.second); n   if (pingo.size() != 4) { n     return 2 * (der.first - izq.first) + 2 * (up.first - down.first); n   } n   vector<int> concha; n   for (auto pito : pingo) { n     concha.push_back(pito); n   } n   int ans = -1; n   for (int i = 0; i < 4; i++) { n     for (int j = i + 1; j < 4; j++) { n       int u = concha[i]; n       int v = concha[j]; n       for (int k = 0; k < n; k++) { n         if (k != u && k != v) { n           ans = max(ans, ereccion(u, v, k)); n         } n       } n     } n   } n   return 2 * ans; n } n int main() { n   scanf( %d , &n); n   izq = make_pair(INF, 0); n   down = make_pair(INF, 0); n   der = make_pair(-INF, 0); n   up = make_pair(-INF, 0); n   for (int i = 0; i < n; i++) { n     scanf( %d %d , &x[i], &y[i]); n     down = min(down, make_pair(y[i], i)); n     up = max(up, make_pair(y[i], i)); n     der = max(der, make_pair(x[i], i)); n     izq = min(izq, make_pair(x[i], i)); n   } n   printf( %d  , triangulo()); n   int anss = 2 * (der.first - izq.first) + 2 * (up.first - down.first); n   for (int i = 4; i <= n; i++) { n     printf( %d  , anss); n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int solve() { n   long long n; n   cin >> n; n   vector<long long int> a, b; n   long long x; n   for (long long int i = 0; i < n; i++) { n     cin >> x; n     if (x > 0) n       a.push_back(x); n     else n       b.push_back(x); n   } n   long long sum1 = accumulate(a.begin(), a.end(), (long long)0); n   long long sum2 = abs(accumulate(b.begin(), b.end(), (long long)0)); n   if (sum1 > sum2) n     cout <<  first ; n   else if (sum2 > sum1) n     cout <<  second ; n   else { n     long long s = min((long long int)a.size(), (long long int)b.size()); n     for (long long int i = 0; i < s; i++) { n       if (a[i] > abs(b[i])) { n         cout <<  first ; n         return 0; n       } else if (a[i] < abs(b[i])) { n         cout <<  second ; n         return 0; n       } n     } n     if (x > 0) n       cout <<  first ; n     else n       cout <<  second ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const int sigma_size = 26; n const int N = 100 + 50; n const int MAXN = 100000 + 50; n const int inf = 0x3fffffff; n const double eps = 1e-8; n const int mod = 1000000000 + 7; n int n, k; n int a[N]; n double dp[N][N], res[N][N]; n int main() { n   while (~scanf( %d%d , &n, &k)) { n     for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n     memset(dp, 0, sizeof(dp)); n     for (int i = 1; i <= n; i++) n       for (int j = i + 1; j <= n; j++) dp[i][j] = 1; n     while (k--) { n       memcpy(res, dp, sizeof(dp)); n       memset(dp, 0, sizeof(dp)); n       for (int l = 1; l <= n; l++) n         for (int r = l; r <= n; r++) { n           for (int i = 1; i <= n; i++) n             for (int j = i + 1; j <= n; j++) { n               int x = i, y = j; n               if (l <= x && x <= r) x = l + r - x; n               if (l <= y && y <= r) y = l + r - y; n               if (x > y) swap(x, y); n               if (l <= x && y <= r) n                 dp[x][y] += (1 - res[i][j]) * 2.0 / (n + 1) / n; n               else n                 dp[x][y] += res[i][j] * 2.0 / (n + 1) / n; n             } n         } n     } n     double ans = 0; n     for (int i = 1; i <= n; i++) n       for (int j = i + 1; j <= n; j++) n         if (a[i] > a[j]) n           ans += dp[i][j]; n         else n           ans += 1.0 - dp[i][j]; n     printf( %.10f n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, a[5001], i, j, b[5001], ans; n int main() { n   scanf( %d%d , &n, &m); n   for (i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     b[i] = a[i]; n   } n   for (i = 1; i <= n; i++) n     if (a[i] == b[i]) n       for (j = 1; j <= n; j++) n         if (a[i] != b[j] && b[i] != a[j]) swap(b[i], b[j]); n   for (i = 1; i <= n; i++) n     if (a[i] != b[i]) ans++; n   printf( %d n , ans); n   for (i = 1; i <= n; i++) printf( %d %d n , a[i], b[i]); n } n


#include <bits/stdc++.h> n using namespace std; n long long a[200001], b[200001], c[200001], d[200001], s, n, cnt[200001]; n int bit(int a, int j) { return (a & (1 << j)) >> j; } n int checkb() { n   int mb = 0; n   for (int i = 1; i <= n; ++i) { n     for (int j = 0; j <= 29; ++j) { n       int x = bit(a[i], j), y = bit(b[i], j); n       if (x != 0) mb += cnt[j]; n       if (y != mb % 2) return 0; n       mb /= 2; n     } n   } n   return 1; n } n int checkc() { n   int mc = 0; n   for (int i = 1; i <= n; ++i) { n     for (int j = 0; j <= 29; ++j) { n       int x = bit(a[i], j), y = bit(c[i], j); n       if (x != 1) n         mc += cnt[j]; n       else n         mc += n; n       if (y != mc % 2) return 0; n       mc /= 2; n     } n   } n   return 1; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   scanf( %I64d , &n); n   for (int i = 1; i <= n; ++i) scanf( %I64d , &b[i]); n   for (int i = 1; i <= n; ++i) scanf( %I64d , &c[i]); n   for (int i = 1; i <= n; ++i) d[i] = b[i] + c[i], s += d[i]; n   s = s / (2 * n); n   for (int i = 1; i <= n; ++i) a[i] = (d[i] - s) / n; n   for (int i = 1; i <= n; ++i) { n     for (int j = 0; j <= 29; ++j) { n       int x = bit(a[i], j); n       if (x) cnt[j]++; n     } n   } n   if (checkb() && checkc()) n     for (int i = 1; i <= n; ++i) printf( %I64d  , a[i]); n   else n     printf( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC optimize( Ofast ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n using namespace std; n long long int t, l, r, m[200005][26]; n string second; n int32_t main() { n   ios_base::sync_with_stdio(); n   cin.tie(); n   cout.tie(); n   ; n   cin >> second; n   cin >> t; n   for (long long int i = 0; i < second.size(); i++) { n     if (i != 0) { n       for (long long int j = 0; j <= 26; j++) { n         m[i][j] = m[i - 1][j]; n       } n     } n     m[i][second[i] -  a ]++; n   } n   while (t--) { n     cin >> l >> r; n     if (l == r || second[l - 1] != second[r - 1]) { n       cout <<  Yes  <<   n ; n     } else { n       long long int s1 = 0; n       for (long long int i = 0; i < 26; i++) { n         if (l == 1) { n           if (m[r - 1][i] != 0) { n             s1++; n           } n         } else { n           if (m[r - 1][i] - m[l - 2][i] != 0) { n             s1++; n           } n         } n       } n       if (s1 >= 3) { n         cout <<  Yes  <<   n ; n       } else n         cout <<  No  <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n  n /*<DEBUG>*/ n #define tem template <typename  n #define can_shift(_X_, ...) enable_if_t<sizeof test<_X_>(0) __VA_ARGS__ 8, debug&> operator<<(T i) n #define _op debug& operator<< n tem C > auto test(C *x) -> decltype(cerr << *x, 0LL); n tem C > char test(...); n tem C > struct itr{C begin, end; }; n tem C > itr<C> get_range(C b, C e) { return itr<C>{b, e}; } n struct debug{ n #ifdef _LOCAL n  ~debug(){ cerr << endl; } n  tem T > can_shift(T, ==){ cerr << boolalpha << i; return *this; } n  tem T> can_shift(T, !=){ return *this << get_range(begin(i), end(i)); } n  tem T, typename U > _op (pair<T, U> i){  n   return *this <<  <   << i.first <<   ,   << i.second <<   > ; } n  tem T> _op (itr<T> i){ n   *this <<   {  ; n   for(auto it = i.begin; it != i.end; it++){ n    *this <<   ,   + (it==i.begin?2:0) << *it; n   } n   return *this <<   } ; n  } n #else n tem T> _op (const T&) { return *this; } n #endif  n }; n  n string _ARR_(int* arr, int sz){ n  string ret =  {   + to_string(arr[0]);  n  for(int i = 1; i < sz; i++) ret +=   ,   +  to_string(arr[i]); n  ret +=   } ; return ret; n } n  n #define exp(...)   [   << #__VA_ARGS__ <<   :   << (__VA_ARGS__) <<   ]  n /*</DEBUG>*/ n  n typedef long long ll; n typedef unsigned long long ull; n typedef unsigned int uint; n typedef pair<int, int> pii; n //mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); n  n #define pb push_back n #define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) n #define TC int __TC__; cin >> __TC__; while(__TC__--) n #define ar array n  n const int INF = 1e9 + 7, N = 5e5; n  n ll x, y; n ll extended_euclid(ll a, ll b){ n  if(b == 0){ n   x = 1; n   y = 0; n   return a; n  } n  n  ll g = extended_euclid(b, a%b); n  ll nx, ny; n  nx = y; n  ny = x - (a/b)*y; n  x = nx; n  y = ny; n  return g; n } n  n ll a[N], b[N], g=0, l, sum=0; n vector<ll> same; n map<ll, ll> pos, issame; n  n  n int main(void) n { n  FAST; n  ll n, m, k; n  cin >> n >> m >> k; n  for(int i = 0; i < n; ++i) cin >> a[i]; n  for(int i = 0; i < m; ++i) cin >> b[i]; n  n  if(m < n){  n   swap(m, n); n   swap(a,b); n  } n  // n <= m n  // a is shorter than b n  n  for(int i = 0; i < m; ++i) pos[b[i]] = i; n  n  g = extended_euclid(n,m); n  l = n*m/g; n  debug() << exp(x) exp(y); n  n  ll posx, negx; n  if(x == 0){ n   x += m; n   y -= n; n  } n  n  if(x < 0){ n   negx = x; n   // n*x + m*y = g n    n   //x += m; n   //y -= n; n  n   ll times = (abs(x) + m)/m; n   x += times*m; n   y -= times*n; n   posx = x; n  }else{ n   posx = x; n   ll times = (x + m)/m; n  n   x -= times*m; n   y += times*n; n  n   negx = x; n  } n  debug() << exp(x) exp(y); n  // x > 0 n  n  for(ll i = 0; i < n; ++i){ n   if(pos.find(a[i]) != pos.end()){ n    ll p = pos[a[i]]; n    ll c = p - i; n  n    if(c == 0){ n     same.pb(i); n     issame[i] = 1; n    }else if(c<0 && abs(c) % g == 0){ n     c = abs(c); n     ll times = c/g; n     ll pos = (-negx*times)*n + i; n     pos %= l; n  n     same.pb(pos); n     issame[pos] = 1; n    }else if(c % g == 0){ n     ll times = c/g; n     ll pos = (posx * times) * n + i; n     pos %= l; n  n     same.pb(pos); n     issame[pos] = 1; n    } n   } n  } n  n  sort(same.begin(), same.end()); n  sum = n*(m/g) - same.size(); n  debug() << exp(same) exp(same.size()); n  n  ll ans = 0; n  ans += l*(k/sum); n  k = (k%sum); n  n  if(k == 0){ n   ans -= l; n   k += sum; n  } n  n  --k; n  // -> k = {0, 1, 2,..., sum-1} n  ll pos = k; n  // -> find the pos of the kth collision  n   n  auto it = lower_bound(same.begin(), same.end(), k); n  ll diff = 0; n  ll mv = (it - same.begin()); n  n  while(diff < mv || issame[pos]){ n   if(!issame[pos]) diff++; n   pos++; n  } n  n  ans += pos+1; // off by one error?; n  n  cout << ans <<   n ; 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   cin >> s; n   map<string, int> m; n   int groot = 0; n   string p =   ; n   vector<string> vec; n   for (int i = 1; i < s.size(); i++) { n     p.push_back(s[i - 1]); n     p.push_back(s[i]); n     m[p]++; n     groot = max(groot, m[p]); n     vec.push_back(p); n     p =   ; n   } n   for (int i = 0; i < vec.size(); i++) { n     if (m[vec[i]] == groot) { n       cout << vec[i] << endl; n       break; n     } n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n struct A { n   int fr, to, th; n   long long d; n   A() {} n   A(int a, int b, long long c, int d) : fr(a), to(b), d(c), th(d) {} n }; n const int N = 1003; n vector<A> edge, G[N], ze, all, ori; n int from[N]; n long long dis[N]; n void SPFA(int x) { n   queue<int> q; n   q.push(x); n   for (int i = 0; i < N; ++i) dis[i] = 1e15; n   dis[x] = 0; n   bool inq[N] = {}; n   while (!q.empty()) { n     int fr = q.front(); n     q.pop(); n     inq[fr] = 0; n     for (A e : G[fr]) { n       if (dis[e.to] > dis[e.fr] + all[e.th].d) { n         dis[e.to] = dis[e.fr] + all[e.th].d; n         if (!inq[e.to]) { n           inq[e.to] = 1; n           q.push(e.to); n         } n         from[e.to] = e.th; n       } n     } n   } n } n int main() { n   int n, m, s, t; n   long long L; n   scanf( %d%d%lld%d%d , &n, &m, &L, &s, &t); n   for (int i = 0, x, y; i < m; ++i) { n     long long d; n     scanf( %d%d%lld , &x, &y, &d); n     if (!d) n       ze.push_back(A(x, y, d, i)); n     else n       edge.push_back(A(x, y, d, i)); n     all.push_back(A(x, y, d, i)); n     ori.push_back(A(x, y, d, i)); n   } n   for (auto e : edge) { n     G[e.fr].push_back(e); n     G[e.to].push_back(A(e.to, e.fr, e.d, e.th)); n   } n   SPFA(s); n   if (dis[t] < L) { n     puts( NO ); n     return 0; n   } n   if (dis[t] == L) { n     puts( YES ); n     for (auto e : all) { n       printf( %d %d %lld n , e.fr, e.to, e.d ? e.d : (long long)(1e15)); n     } n     return 0; n   } n   for (int i = 0; i < ze.size(); ++i) { n     ze[i].d = 1; n     A e = ze[i]; n     all[e.th].d = 1; n     G[e.fr].push_back(e); n     G[e.to].push_back(A(e.to, e.fr, e.d, e.th)); n   } n   SPFA(s); n   if (dis[t] > L) { n     puts( NO ); n     return 0; n   } n   while (dis[t] != L) { n     vector<int> use; n     int p = t; n     while (p != s) { n       if (!ori[from[p]].d) { n         use.push_back(from[p]); n       } n       A e = ori[from[p]]; n       p = p == e.fr ? e.to : e.fr; n     } n     long long di = (L - dis[t]) / use.size(), mo = (L - dis[t]) % use.size(); n     all[use[0]].d += di + mo; n     for (int i = 1; i < use.size(); ++i) all[use[i]].d += di; n     SPFA(s); n   } n   puts( YES ); n   for (auto e : all) { n     printf( %d %d %lld n , e.fr, e.to, e.d); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, char const *argv[]) { n   long long n; n   cin >> n; n   vector<long long> a(n); n   for (int i = 0; i < n - 1; ++i) { n     long long u, v; n     cin >> u >> v; n     a[u - 1]++; n     a[v - 1]++; n   } n   for (int i = 0; i < n; ++i) { n     if (a[i] == 2) return cout <<  NO , 0; n   } n   cout <<  YES ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double dp[2020][2020]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n, t; n   double p; n   cin >> n >> p >> t; n   dp[0][0] = 1; n   for (int i = 1; i <= t; i++) dp[i][0] = dp[i - 1][0] * (1 - p); n   for (int i = 1; i <= t; i++) { n     for (int j = 1; j <= i; j++) n       dp[i][j] = dp[i - 1][j] * (j >= n ? 1 : (1 - p)) + dp[i - 1][j - 1] * p; n   } n   double ans = 0; n   for (int i = 1; i <= (n < t ? n : t); i++) ans += i * (dp[t][i]); n   printf( %.10lf , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   long long ans = 0; n   for (int i = (0); i < (n); ++i) { n     long long t, T, x, cost; n     cin >> t >> T >> x >> cost; n     if (t >= T) { n       ans += cost + m * x; n       continue; n     } n     long long aux1 = cost; n     if (m > (T - t)) aux1 += m * x; n     long long aux2 = (long long)ceil((double)(m - (T - t)) / (T - t)) + 1; n     aux2 *= cost; n     ans += min(aux1, aux2); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200010; n struct E { n   int to, nxt; n } e[N << 1]; n int n, m, head[N], cnt, l[N], r[N], ans[N], ans_cnt, fa[N]; n bool b[N]; n int Write[20], WRI; n void judge() { n   freopen( .in ,  r , stdin); n   freopen( .out ,  w , stdout); n } n int read() { n   int d = 0, f = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) d = d * 10 + c - 48, c = getchar(); n   return d * f; n } n void write(int x) { n   if (!x) { n     putchar( 0 ); n     return; n   } n   if (x < 0) putchar( - ), x = -x; n   for (WRI = 1; x; x /= 10, WRI++) Write[WRI] = x % 10; n   for (int i = WRI - 1; i; i--) putchar((char)(Write[i] + 48)); n } n void add(int x, int y) { n   e[++cnt] = (E){y, head[x]}; n   head[x] = cnt; n } n void addedge(int x, int y) { n   add(x, y); n   add(y, x); n } n void del(int x) { n   b[x] = 1; n   r[l[x]] = r[x]; n   l[r[x]] = l[x]; n } n void bfs(int ljj) { n   queue<int> q; n   int sum = 1; n   q.push(ljj); n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     for (int i = head[u]; i; i = e[i].nxt) { n       int v = e[i].to; n       fa[v] = u; n     } n     for (int i = r[0]; i <= n; i = r[i]) n       if (fa[i] != u && !b[i]) { n         q.push(i); n         del(i); n         sum++; n       } n   } n   ans[++ans_cnt] = sum; n } n int main() { n   n = read(); n   m = read(); n   for (int i = 1; i <= m; i++) addedge(read(), read()); n   for (int i = 0; i <= n; i++) l[i] = i - 1, r[i] = i + 1; n   for (int i = 1; i <= n; i = r[i]) n     if (!b[i]) { n       del(i); n       bfs(i); n     } n   sort(ans + 1, ans + 1 + ans_cnt); n   write(ans_cnt); n   puts(  ); n   for (int i = 1; i <= ans_cnt; i++) write(ans[i]), putchar(   ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int l, r, n, k, m, now, tot, all; n int a[200000], s[200000]; n struct fk { n   int num, val; n   bool operator==(const fk &b) { return (num + b.num == k && val == b.val); } n } tp[200000]; n int main() { n   scanf( %d%d%d , &n, &k, &m); n   for (int i = 1; i <= n; ++i) scanf( %d , a + i); n   all = 0; n   tp[0].num = tp[0].val = -1; n   for (int i = 1; i <= n; ++i) { n     if (a[i] == tp[all].val) { n       ++tp[all].num; n       if (tp[all].num == k) --all; n     } else { n       tp[++all].val = a[i]; n       tp[all].num = 1; n     } n   } n   n = 0; n   for (int i = 1; i <= all; ++i) n += tp[i].num; n   int p = 0; n   for (int i = 1; i <= all; ++i) { n     if (tp[i] == tp[all - i + 1]) n       p = i; n     else n       break; n   } n   long long ans = 0, temp; n   if (p >= (all + 1) / 2) { n     if (m % 2) n       for (int i = 1; i <= all; ++i) ans += tp[i].num; n   } else if (all % 2 == 1 && p == all / 2) { n     temp = m % k * tp[p + 1].num % k; n     if (temp % k == 0) n       ans = 0; n     else { n       ans = (long long)p * k; n       ans = ans + temp; n     } n   } else { n     ans = (long long)m * n; n     for (int i = 1; i <= p; ++i) ans -= (long long)p * k * (m - 1); n     ans -= (tp[p + 1].val == tp[all - p].val && n             tp[p + 1].num + tp[all - p].num >= k) n                ? (long long)k * (m - 1) n                : 0; n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   int ans = 0; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) n     for (int j = i; j <= n; j++) { n       int k = i ^ j; n       if (k <= n && k >= 1 && k >= j && i + j > k) ans++; n     } n   printf( %d , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   int n, c = 0; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> s; n     c = s ==  Tetrahedron  ? c += 4 : c; n     c = s ==  Cube  ? c += 6 : c; n     c = s ==  Octahedron  ? c += 8 : c; n     c = s ==  Dodecahedron  ? c += 12 : c; n     c = s ==  Icosahedron  ? c += 20 : c; n   } n   cout << c; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void imprimirVector(vector<int> v) { n   if (!v.empty()) { n     int p = v.size(); n     cout <<  [ ; n     for (int i = 0; i < (int)(p - 1); i++) cout << v[i] <<  , ; n     cout << v[p - 1] <<  ]  << endl; n   } else n     cout <<  []  << endl; n } n int toNumber(string s) { n   int Number; n   if (!(istringstream(s) >> Number)) Number = 0; n   return Number; n } n string toString(int number) { n   ostringstream ostr; n   ostr << number; n   return ostr.str(); n } n int main() { n   long long n; n   cin >> n; n   vector<bool> v(n + 1, false); n   vector<long long> a(n); n   vector<long long> ans(n); n   vector<long long> faltan; n   for (int i = 0; i < (int)(n); i++) { n     cin >> a[i]; n     if (a[i] <= n && !v[a[i]]) { n       ans[i] = a[i]; n       v[a[i]] = true; n     } else n       faltan.push_back(i); n   } n   for (int i = (1); i < (int)(n + 1); i++) { n     if (!v[i]) { n       long long r = faltan.back(); n       faltan.pop_back(); n       ans[r] = i; n     } n   } n   for (int i = 0; i < (int)(n); i++) { n     if (i) cout <<    ; n     cout << ans[i]; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC optimize( -Ofast ,  -funroll-all-loops ,  -ffast-math ) n using namespace std; n using LL = long long; n constexpr LL mod = 1e9 + 7; n long long ex_gcd(long long a, long long b, long long &x, long long &y) { n   if (!b) { n     x = 1; n     y = 0; n     return a; n   } n   long long ret = ex_gcd(b, a % b, y, x); n   y -= a / b * x; n   return ret; n } n LL mul(LL u, LL v, LL p) { n   return (u * v - LL((long double)u * v / p) * p + p) % p; n } n LL bin(LL x, LL n, LL MOD) { n   LL ret = MOD != 1; n   for (x %= MOD; n; n >>= 1, x = x * x % MOD) n     if (n & 1) ret = ret * x % MOD; n   return ret; n } n LL norm(LL x) { return x >= mod ? (x - mod) : x; } n inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); } n inline long long get_inv(long long a) { n   long long x, y; n   ex_gcd(a, mod, x, y); n   return norm(x + mod); n } n template <class T> n inline void umin(T &x, T y) { n   x = x > y ? y : x; n } n template <class T> n inline void umax(T &x, T y) { n   x = x < y ? y : x; n } n template <class T> n inline void dec(T &x, T y) { n   x -= y; n   if (x < 0) x += mod; n } n template <class T> n inline void add(T &x, T y) { n   x += y; n   if (x >= mod) x -= mod; n } n template <typename T> n void read(T &x) { n   cin >> x; n } n template <typename T, typename... Args> n void read(T &first, Args &...args) { n   read(first); n   read(args...); n } n template <class T> n LL ctz(T a) { n   return sizeof(T) > 2 ? __builtin_ctzll(a) : __builtin_ctz(a); n } n template <class T> n inline T gcd(T _a, T _b) { n   T a = abs(_a), b = abs(_b); n   LL shift = ctz(a | b); n   for (b >>= ctz(b), a >>= ctz(a); a; a -= b, a >>= ctz(a)) n     if (a < b) swap(a, b); n   return b << shift; n } n const double PI = acos(-1.0); n constexpr LL INF = 0x3f3f3f3f; n constexpr long long linf = 0x3f3f3f3f3f3f3f3f; n constexpr unsigned long long base = 2333, P_1 = 19260817, P_2 = 999998639; n constexpr LL maxn = 1e6 + 10; n LL n, ans, a[maxn], s[maxn]; n vector<LL> v[maxn]; n int32_t main() { n   std::ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr), n       cout << fixed << setprecision(10); n   cin >> n; n   for (LL i = (1), _i = (n + 1); i < _i; ++i) n     cin >> a[i], v[a[i]].emplace_back(i); n   LL mx = 0, mx_num = 0; n   for (LL i = 1; i <= n; i++) { n     if (int32_t(v[i].size()) > mx) n       mx_num = i, mx = int32_t(v[i].size()); n     else if (int32_t(v[i].size()) == mx) n       mx_num = -1; n   } n   if (mx_num == -1) { n     cout << n <<   12 ; n   } else { n     s[0] = 0; n     for (LL i = 1; i <= n; i++) { n       s[i] = s[i - 1] + (a[i] == mx_num); n     } n     for (LL i = 1; i <= n; i++) { n       if (int32_t(v[i].size()) and i != mx_num) { n         vector<LL> tp(400010), p(400010); n         tp[0] = 200000; n         for (LL j = 1; j <= n; j++) { n           tp[j] = tp[j - 1] + (a[j] == mx_num) - (a[j] == i); n         } n         for (LL j = n; j >= 0; j--) { n           if (!p[tp[j]]) n             p[tp[j]] = j; n           else n             umax(ans, p[tp[j]] - j); n         } n       } n     } n     cout << ans <<   12 ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n string toBin(long long a) { n   string res =   ; n   while (a) { n     res += char((a & 1) +  0 ); n     a >>= 1; n   } n   reverse(res.begin(), res.end()); n   return res; n } n const int mod = 1e9 + 7; n long long expo(long long base, long long pow) { n   long long ans = 1; n   while (pow != 0) { n     if (pow & 1 == 1) { n       ans = ans * base; n       ans = ans % mod; n     } n     base *= base; n     base %= mod; n     pow /= 2; n   } n   return ans; n } n long long inv(long long x) { return expo(x, mod - 2); } n double pi = 3.141592653589793238462643; n double error = 0.0000001; n const int M = 100001; n int main() { n   int k, a, b, v; n   cin >> k >> a >> b >> v; n   int tot = 0; n   int box = 0; n   while (true) { n     int sect = min(b + 1, k); n     b -= (sect - 1); n     tot += sect * v; n     box++; n     if (tot >= a) break; n   } n   cout << box; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1000010; n long long N, S; n long long fa[maxn], q[maxn], d[maxn], head, tail, sz[maxn], son[maxn]; n bool check(long long Mid) { n   long long tN = N, now = 1, p = 1, res = 0; n   while (tN) { n     res += min(p, tN) * now; n     if (res > S) return false; n     tN -= min(p, tN); n     p *= Mid; n     now++; n   } n   return true; n } n int main() { n   cin >> N >> S; n   long long Mn = N + N - 1; n   long long Mx = N * (N + 1) / 2; n   if (S < Mn || S > Mx) return puts( NO ), 0; n   long long L = 1, R = N - 1, Mid, res; n   while (L <= R) { n     Mid = (L + R) / 2; n     if (check(Mid)) n       res = Mid, R = Mid - 1; n     else n       L = Mid + 1; n   } n   puts( YES ); n   for (int i = 1; i <= N; i++) sz[i] = 1; n   long long Now = Mx, D = 2; n   for (int i = N;; i--) { n     if (Now == S) break; n     if (sz[D] == sz[D - 1] * res) D++; n     if (Now - S >= i - D) { n       sz[D]++; n       sz[i]--; n       Now -= (i - D); n     } else { n       sz[i]--; n       sz[i - (Now - S)]++; n       Now = S; n     } n   } n   head = tail = 1; n   q[head] = 1; n   d[1] = 1; n   long long p = 1; n   for (int i = 2; i <= N; i++) { n     if (sz[i] == 0) break; n     L = p + 1; n     R = p + sz[i]; n     for (int j = L; j <= R; j++) { n       while (d[q[head]] != i - 1 || son[q[head]] == res) { n         head++; n       } n       fa[j] = q[head]; n       son[q[head]]++; n       q[++tail] = j; n       d[j] = i; n     } n     p = R; n   } n   for (int i = 2; i <= N; i++) printf( %lld  , fa[i]); n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e9 + 7; n const int maxN = 2e6 + 5; n string s[maxN]; n int type[maxN]; n int n; n pair<int, int> rang[3]; n int sum[maxN]; n bool in_range(int x, int type) { n   return x >= rang[type].first && x <= rang[type].second; n } n int conv(string s) { n   if (s[0] ==  0 ) return inf; n   int pow = 1; n   int ans = 0; n   for (int i = ((int)s.size() - 1); i >= (0); --i) { n     if (s[i] <  0  || s[i] >  9 ) { n       return inf; n     } n     ans += (s[i] -  0 ) * pow; n     pow *= 10; n   } n   return ans; n } n vector<string> change[3]; n vector<string> empty1, empty0, _0to1_; n bool used[maxN]; n void print(vector<string> wek) { n   for (auto w : wek) cout << w <<    ; n   cout << endl; 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 >> s[i] >> type[i]; n     sum[type[i]]++; n   } n   rang[1] = pair<int, int>(1, sum[1]); n   rang[0] = pair<int, int>(sum[1] + 1, n); n   for (int i = (0); i <= ((n)-1); ++i) { n     int x = conv(s[i]); n     bool b = (s[i][0] ==  0 ); n     if (x <= n && !b) { n       if (!in_range(x, type[i])) { n         if (type[i] == 0) n           _0to1_.push_back(s[i]); n         else n           change[type[i]].push_back(s[i]); n       } n       used[x] = true; n     } else { n       change[type[i]].push_back(s[i]); n     } n   } n   for (int i = (1); i <= (sum[1]); ++i) { n     if (!used[i]) { n       empty1.push_back(to_string(i)); n     } n   } n   for (int i = (sum[1] + 1); i <= (n); ++i) { n     if (!used[i]) empty0.push_back(to_string(i)); n   } n   for (int i = (0); i <= (1); ++i) { n     vector<string> wek; n     for (auto v : change[i]) n       if (conv(v) <= n) wek.push_back(v); n     for (auto v : change[i]) n       if (conv(v) > n) wek.push_back(v); n     change[i] = wek; n   } n   vector<string> result; n   string tmp = to_string(n + 1); n   string prev = tmp; n   bool pom = false; n   for (auto v : change[1]) { n     if ((int)empty1.size() != 0) { n       result.push_back( move   + v +     + empty1.back()); n       empty1.pop_back(); n       int x = conv(v); n       if (x <= n && in_range(x, 0)) { n         empty0.push_back(v); n       } n     } else { n       if ((int)empty0.size() != 0) { n         result.push_back( move   + _0to1_.back() +     + empty0.back()); n         empty0.pop_back(); n         result.push_back( move   + v +     + _0to1_.back()); n         _0to1_.pop_back(); n         int x = conv(v); n         if (x <= n && in_range(x, 0)) { n           empty0.push_back(v); n         } n       } else { n         result.push_back( move   + v +     + prev); n         result.push_back( move   + _0to1_.back() +     + v); n         prev = _0to1_.back(); n         _0to1_.pop_back(); n         pom = true; n       } n     } n   } n   if (pom) { n     result.push_back( move   + tmp +     + prev); n   } n   for (auto v : change[0]) { n     result.push_back( move   + v +     + empty0.back()); n     empty0.pop_back(); n   } n   cout << (int)result.size() << endl; n   for (auto v : result) cout << v << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   int k = min(n, m); n   if (k & 1) n     printf( Akshat ); n   else n     printf( Malvika ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char a[1000005]; n char c[1000005]; n bool H(char a[], char c[], int i, int x) { n   int d = 0; n   for (int q = 0; q < i; q += x) { n     int s = 0; n     for (int o = 0; o < x; o++) { n       if (a[o + q] > c[o]) n         return 1; n       else if (a[o + q] == c[o]) n         s++; n       else if (a[o + q] < c[o]) n         break; n     } n     if (s == x) d++; n   } n   if (d == i / x) return 1; n   return 0; n } n int main() { n   int x, i = 0; n   cin >> x; n   while (cin >> a[i]) { n     i++; n   } n   bool K = 0; n   for (int j; j < i; j++) { n     if (a[j] !=  9 ) { n       K = 1; n       break; n     } n   } n   if (i % x == 0 && K) { n     bool A; n     for (int j = 0; j < x; j++) { n       c[j] = a[j]; n     } n     A = H(a, c, i, x); n     if (A) { n       for (int j = x - 1; j >= 0; j--) { n         if (c[j] ==  9 ) n           c[j] =  0 ; n         else { n           c[j] += 1; n           break; n         } n       } n     } n     for (int j = 0; j < i / x; j++) { n       for (int v = 0; v < x; v++) cout << c[v]; n     } n   } else { n     if (!K) i++; n     while (i % x != 0) { n       i++; n     } n     for (int j = 0; j < i / x; j++) { n       cout <<  1 ; n       for (int p = 0; p < x - 1; p++) { n         cout <<  0 ; n       } n     } n   } n   return 0; n } n