#include <bits/stdc++.h> n using namespace std; n char s[100005]; n int main() { n   int n; n   scanf( %d , &n); n   scanf( %s , s); n   s[n] =  # ; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  a  || s[i] ==  e  || s[i] ==  i  || s[i] ==  o  || n         s[i] ==  u  || s[i] ==  y ) { n       if (s[i] ==  e  || s[i] ==  o ) { n         int same = 1; n         if (i != n - 1) { n           if (s[i + 1] == s[i]) same++; n         } n         if (same == 2) { n           if (i != n - 2) { n             if (s[i + 2] == s[i]) { n               printf( %c , s[i]); n               for (int j = i + 2; j <= n; j++) { n                 if (s[j] != s[i]) { n                   i = j - 1; n                   break; n                 } n               } n             } else { n               printf( %c%c , s[i], s[i]); n               i++; n             } n           } else { n             printf( %c%c , s[i], s[i]); n             i++; n           } n         } else n           printf( %c , s[i]); n       } else { n         printf( %c , s[i]); n         for (int j = i + 1; j <= n; j++) { n           if (s[i] != s[j]) { n             i = j - 1; n             break; n           } n         } n       } n     } else n       printf( %c , s[i]); n   } n } n


#include <bits/stdc++.h> n #pragma GCC optimize(2) n #pragma GCC optimize(3) n #pragma GCC target( avx ) n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n template <typename _T> n inline void read(_T &f) { n   f = 0; n   _T fu = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) fu = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     f = (f << 3) + (f << 1) + (c & 15); n     c = getchar(); n   } n   f *= fu; n } n template <typename T> n void print(T x) { n   if (x < 0) putchar( - ), x = -x; n   if (x < 10) n     putchar(x + 48); n   else n     print(x / 10), putchar(x % 10 + 48); n } n template <typename T> n void print(T x, char t) { n   print(x); n   putchar(t); n } n const int N = 4005, md = 998244853; n inline int add(int x, int y) { n   x += y; n   if (x >= md) x -= md; n   return x; n } n inline int sub(int x, int y) { n   x -= y; n   if (x < 0) x += md; n   return x; n } n inline int mul(int x, int y) { return 1ll * x * y % md; } n inline int fpow(int x, int y) { n   int ans = 1; n   while (y) { n     if (y & 1) ans = mul(ans, x); n     y >>= 1; n     x = mul(x, x); n   } n   return ans; n } n int fac[N], inv[N]; n int n, m, ans; n inline int C(int n, int m) { return mul(fac[n], mul(inv[m], inv[n - m])); } n int main() { n   read(n); n   read(m); n   fac[0] = 1; n   for (register int i = 1; i <= n + m; i++) fac[i] = mul(fac[i - 1], i); n   inv[n + m] = fpow(fac[n + m], md - 2); n   for (register int i = n + m; i >= 1; i--) inv[i - 1] = mul(inv[i], i); n   for (register int i = 1; i <= n; i++) { n     if (n - m >= i) n       ans = add(ans, C(n + m, m)); n     else n       ans = add(ans, C(n + m, i + m)); n   } n   print(ans,   n ); n   return 0; n } n


#include <bits/stdc++.h> n const int N = 1000; n bool vis[N + 100]; n int v[N + 100]; n int top = 0; n int n = 0; n int main() { n   scanf( %d , &n); n   for (int i = 2; i <= n; i++) { n     if (!vis[i]) { n       vis[i] = true; n       for (int j = 0; j < n; j++) { n         if (!vis[j]) continue; n         if (i * j > n) break; n         if ((j % i == 0) || (i % j == 0)) continue; n         vis[i * j] = true; n       } n       v[top++] = i; n     } n   } n   printf( %d n , top); n   for (int i = 0; i < top; i++) { n     printf( %d  , v[i]); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long min(long long a, long long b) { n   if (a < b) n     return a; n   else n     return b; n } n static long long gcd(long long a, long long b) { n   long long r; n   while (b != 0) { n     r = a % b; n     a = b; n     b = r; n   } n   return a; n } n long long lcm(long long a, long long b) { n   long long temp = gcd(a, b); n   return temp ? (a / temp * b) : 0; n } n int solve() { n   long long n; n   cin >> n; n   long long k; n   cin >> k; n   long long maxans = (n * (n - 1)) / 2LL; n   if (k > maxans) { n     cout <<  Impossible ; n     return 0; n   } n   long long cnt = 0; n   long long tmp; n   for (long long i = 1; i <= n; i++) { n     if (((i * (i - 1)) / 2LL) <= k) { n       tmp = i; n     } else { n       break; n     } n   } n   long long open = tmp; n   cnt = open; n   k = k - ((tmp * (tmp - 1)) / 2LL); n   string s; n   for (int i = 0; i < open; i++) { n     s.push_back( ( ); n   } n   if (open >= 1) { n     s.push_back( ) ); n     open--; n   } n   while (k > 0 && open > 0 && cnt <= n) { n     if (open <= k) { n       s.push_back( ( ); n       s.push_back( ) ); n       cnt++; n       k = k - open; n     } else { n       open--; n       s.push_back( ) ); n     } n   } n   if (k == 0 && cnt <= n) { n     for (int i = 0; i < open; i++) { n       s.push_back( ) ); n     } n     for (int i = 0; i < (n - cnt); i++) { n       s.push_back( ( ); n       s.push_back( ) ); n     } n     cout << s; n     return 0; n   } else { n     cout <<  Impossible ; n     return 0; n   } n   return 0; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t = 1; n   for (int i = 1; i <= t; i++) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n #define int long long n using pii=std::pair<int,int>; n using namespace std; n  n const int maxn = 2e5 + 5; n  n int n, u, v, a[maxn], in[maxn], out[maxn], order[maxn], timer = -1, st[4 * maxn], need[4 * maxn]; n vector<int> adj[maxn]; n map<int, vector<int>> avals; n  n void dfs(int x, int p) n { n     in[x] = ++timer; n     order[timer] = x; n     avals[a[x]].push_back(x); n     for(auto v : adj[x]) n         if(v != p) n             dfs(v, x); n     out[x] = timer; n } n  n int is_ancestor(int u, int v) n { n     return (in[u] <= in[v] && out[u] >= out[v]); n } n  n void build(int tl, int tr, int v) n { n     if(tl == tr) n         st[v] = 1; n     else n     { n         int tmid = (tl + tr) / 2; n         build(tl, tmid, 2 * v); n         build(tmid + 1, tr, 2 * v + 1); n         st[v] = 1; n     } n } n  n void push(int v) n { n     if(need[v]) n     { n         st[2 * v] = st[2 * v + 1] = st[v]; n         need[2 * v] = need[2 * v + 1] = need[v]; n         need[v] = 0; n     } n } n  n void update(int tl, int tr, int l, int r, int v, int val) n { n     if(l > r) n         return; n     if(tl == l && tr == r) n     { n         st[v] = val; n         need[v] = 1; n     } n     else n     { n         push(v); n         int tmid = (tl + tr) / 2; n         update(tl, tmid, l, min(r, tmid), 2 * v, val); n         update(tmid + 1, tr, max(l, tmid + 1), r, 2 * v + 1, val); n     } n } n  n int get(int tl, int tr, int v, int pos) n { n     if(tl == tr) n     { n         assert(tl == pos); n         return st[v]; n     } n     else n     { n         push(v); n         int tmid = (tl + tr) / 2; n         if(pos <= tmid) n             return get(tl, tmid, 2 * v, pos); n         else n             return get(tmid + 1, tr, 2 * v + 1, pos); n     } n } n  n int32_t main() n { n     ios_base::sync_with_stdio(false); n     cin.tie(0); n     cin >> n; n     for(int i = 0; i < n; i++) n         cin >> a[i]; n     for(int i = 0; i < n - 1; i++) n     { n         cin >> u >> v; n         u--; v--; n         adj[u].push_back(v); n         adj[v].push_back(u); n     } n     dfs(0, -1); n     build(0, n - 1, 1); n     for(auto x : avals) n         if(x.second.size() > 1) n         { n             for(int i = 0; i < x.second.size(); i++) n             { n                 int pre = x.second[i]; n                 int cur = x.second[(i + 1) % x.second.size()]; n                 if(is_ancestor(cur, pre)) n                     swap(cur, pre); n     if(is_ancestor(pre, cur)) n                 { n                     int pathchild = -1; n                     for(auto v : adj[pre]) n                         if(is_ancestor(v, cur) && !is_ancestor(v, pre)) n                         { n                             pathchild = v; n                             break; n                         } n      assert(pathchild != -1); n                     update(0, n - 1, 0, in[pathchild] - 1, 1, 0); n                     update(0, n - 1, out[pathchild] + 1, n - 1, 1, 0); n                     update(0, n - 1, in[cur], out[cur], 1, 0); n                 } n                 else n                 { n                     update(0, n - 1, in[cur], out[cur], 1, 0); n                     update(0, n - 1, in[pre], out[pre], 1, 0); n                 } n             } n         } n     int ans = 0; n     for(int i = 0; i < n; i++) n         ans += get(0, n - 1, 1, i); n     cout << ans <<   n ; n     return 0; n }


#include <bits/stdc++.h> n #pragma GCC target( avx ) n #pragma GCC optimize( O3 ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n using std::cin; n using std::cout; n using std::lower_bound; n using std::string; n using std::upper_bound; n using std::vector; n using vi = vector<long long>; n using vii = vector<vi>; n using pii = std::pair<long long, long long>; n constexpr long long MOD = 998244353; n constexpr long long MAX = 1e7; n constexpr long long INF = (1ll << 62); n template <class T> n class prique : public std::priority_queue<T, std::vector<T>, std::greater<T>> { n }; n template <typename T> n struct Segment_tree { n   long long N; n   T mem; n   vector<T> node; n   Segment_tree(vector<T> &X, T m) : mem(m) { n     long long sz = X.size(); n     N = 1; n     while (N < sz) N *= 2; n     node.resize(2 * N - 1, mem); n     for (int i = (int)(0); i < (int)(sz); i++) node[N - 1 + i] = X[i]; n     for (int i = (int)(N - 2); (int)(0) <= i; i--) { n       node[i] = Compare(node[i * 2 + 1], node[i * 2 + 2]); n     } n   } n   T Compare(T &A, T &B) { return std::max(A, B); } n   void update(long long X, T val) { n     X += N - 1; n     node[X] = val; n     while (X > 0) { n       X = (X - 1) / 2; n       node[X] = Compare(node[X * 2 + 1], node[X * 2 + 2]); n     } n   } n   T Query(long long a, long long b, long long now, long long l, long long r) { n     if (r < 0) r = N; n     if (r <= a || b <= l) return mem; n     if (a <= l && r <= b) return node[now]; n     auto vl = Query(a, b, now * 2 + 1, l, (l + r) / 2), n          vr = Query(a, b, now * 2 + 2, (l + r) / 2, r); n     return Compare(vl, vr); n   } n }; n struct Binary_indexed_tree { n   int N; n   vi bit; n   Binary_indexed_tree(int n) : N(n) { bit.resize(N + 1, 0); } n   void add(int x, int a) { n     for (x; x <= N; x += (x & -x)) bit[x] += a; n   } n   long long sum(int x) { n     long long ret = 0; n     for (x; x > 0; x -= (x & -x)) ret += bit[x]; n     return ret; n   } n   long long lower_bound(long long X) { n     if (sum(N) < X) return -1; n     long long ret = 0, memo = 1, sum = 0; n     while (memo * 2 <= N) memo *= 2; n     while (memo > 0) { n       if (memo + ret <= N && sum + bit[memo + ret] < X) { n         sum += bit[memo + ret]; n         ret += memo; n       } n       memo /= 2; n     } n     return ret + 1; n   } n }; n struct Union_Find { n   long long N; n   vi par; n   vi siz; n   Union_Find(int n) : N(n) { n     par.resize(N); n     siz.resize(N, 1); n     for (int i = (int)(0); i < (int)(N); i++) par[i] = i; n   } n   long long root(long long X) { n     if (par[X] == X) return X; n     return par[X] = root(par[X]); n   } n   bool same(long long X, long long Y) { return root(X) == root(Y); } n   void unite(long long X, long long Y) { n     X = root(X); n     Y = root(Y); n     if (X == Y) return; n     par[X] = Y; n     siz[Y] += siz[X]; n     siz[X] = 0; n   } n   long long size(long long X) { return siz[root(X)]; } n }; n long long modpow(long long a, long long n, long long mod) { n   long long res = 1; n   while (n > 0) { n     if (n & 1) res = res * a % mod; n     a = a * a % mod; n     n >>= 1; n   } n   return res; n } n vi fac, finv, inv; n void COMinit() { n   fac.resize(MAX); n   finv.resize(MAX); n   inv.resize(MAX); n   fac[0] = fac[1] = 1; n   finv[0] = finv[1] = 1; n   inv[1] = 1; n   for (int i = 2; i < MAX; i++) { n     fac[i] = fac[i - 1] * i % MOD; n     inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; n     finv[i] = finv[i - 1] * inv[i] % MOD; n   } n } n long long COM(long long n, long long r) { n   if (n < r || n < 0 || r < 0) return 0; n   return fac[n] * finv[r] % MOD * finv[n - r] % MOD; n } n long long modinv(long long a, long long m) { n   long long b = m, u = 1, v = 0; n   while (b) { n     long long t = a / b; n     a -= t * b; n     std::swap(a, b); n     u -= t * v; n     std::swap(u, v); n   } n   u %= m; n   if (u < 0) u += m; n   return u; n } n int main() { n   std::ios::sync_with_stdio(false); n   std::cin.tie(nullptr); n   long long T; n   cin >> T; n   while (T--) { n     long long N; n     cin >> N; n     vi A(N); n     for (int i = (int)(0); i < (int)(N); i++) cin >> A[i]; n     vii sum(N + 1, vi(27)); n     for (int i = (int)(0); i < (int)(N); i++) { n       for (int j = (int)(0); j < (int)(27); j++) sum[i + 1][j] = sum[i][j]; n       sum[i + 1][A[i]]++; n     } n     long long ans = 0; n     for (int i = (int)(1); i <= (int)(N); i++) { n       for (int j = (int)(0); j < (int)(i); j++) { n         long long memo = 0; n         for (int k = (int)(0); k < (int)(27); k++) n           memo = std::max(memo, sum[i][k] - sum[j][k]); n         for (int k = (int)(0); k < (int)(27); k++) { n           ans = std::max(ans, n                          std::min(sum[j][k], sum[N][k] - sum[i][k]) * 2 + memo); n         } n       } n     } n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e5 + 5; n int n, m, k; n int x[MAXN], y[MAXN]; n void read_input() { n   cin >> n >> m >> k; n   for (int i = 0; i < k; i++) { n     cin >> x[i] >> y[i]; n   } n } n const int INF = 1e9; n int pref[2][MAXN]; n void update(int x, int val) { n   for (int i = x; i <= m; i += (i & -i)) { n     pref[0][i] = min(pref[0][i], val); n   } n } n int query(int r) { n   int ans = INF; n   for (int i = r; i > 0; i -= (i & -i)) { n     ans = min(ans, pref[0][i]); n   } n   return ans; n } n void update2(int x, int val) { n   for (int i = x; i <= m; i += (i & -i)) { n     pref[1][i] = max(pref[1][i], val); n   } n } n int query2(int r) { n   int ans = 0; n   for (int i = r; i > 0; i -= (i & -i)) { n     ans = max(ans, pref[1][i]); n   } n   return ans; n } n int mi_y[MAXN], ma_y[MAXN]; n void solve() { n   for (int i = 0; i <= m; i++) { n     mi_y[i] = INF; n     ma_y[i] = 0; n     pref[0][i] = INF; n     pref[1][i] = 0; n   } n   bool fl = true; n   for (int i = 0; i < k; i++) { n     if (fl) { n       int tmpX = (x[i] + 1) / 2; n       int tmpY = (y[i] + 1) / 2; n       if (x[i] % 2 == 1) { n         mi_y[tmpY] = min(mi_y[tmpY], tmpX); n         update(tmpY, mi_y[tmpY]); n       } n       int rev = m - tmpY + 1; n       if (x[i] % 2 == 0) { n         ma_y[rev] = max(ma_y[rev], tmpX); n         update2(rev, ma_y[rev]); n       } n       if (query(tmpY) <= query2(rev)) { n         fl = false; n       } n     } n     if (!fl) { n       cout <<  NO n ; n     } else { n       cout <<  YES n ; n     } n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   read_input(); n   solve(); n   return 0; n } n


#include <iostream> n #include <cmath> n  n using namespace std; n  n typedef long long int ll; n  n int main(){ n  int cases; n  ll num; n  double temp; n  cin >> cases; n  bool cube = false; n  for(int a = 0; a < cases; a++){ n   cin >> num; n   cube = false; n   for(ll b = max(int(cbrt(double(num/2))), 1); b < cbrt(num) && cube == false; b++){ n    temp = cbrt(num - pow(b, 3)); n    if(abs(temp - int(temp)) < pow(10, -9)) cube = true; n   } n   printf(cube ?  YES n  :  NO n ); n  } n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n template <typename... T> n void see(T&... args) { n   ((cin >> args), ...); n } n template <typename... T> n void put(T&&... args) { n   ((cout << args <<    ), ...); n   cout <<   n ; n } n void err(istream_iterator<string> it) {} n template <typename T, typename... Args> n void err(istream_iterator<string> it, T a, Args... args) { n   cerr << *it <<  =  << a <<  ,  ; n   err(++it, args...); n } n const long long inf = INT_MAX; n const long double ep = 0.0000001; n const long double pi = acos(-1.0); n const long long md = 1000000007; n vector<string> add = { 1869 ,  1968 ,  6918 ,  6198 ,  1698 ,  1986 ,  1896 }; n void solve() { n   string s; n   see(s); n   long long a = 0, b = 0, c = 0, d = 0; n   string s1 =   ; n   for (long long i = 0; i < s.size(); ++i) { n     if (s[i] ==  1  && !a) { n       a = 1; n     } else if (s[i] ==  6  && !b) { n       b = 1; n     } else if (s[i] ==  8  && !c) { n       c = 1; n     } else if (s[i] ==  9  && !d) { n       d = 1; n     } else n       s1 += s[i]; n   } n   long long s3; n   for (long long j = 0; j < 7; ++j) { n     s3 = j; n     for (long long i = 0; i < s1.size(); ++i) { n       s3 = (s3 * 10 + (s1[i] -  0 )) % 7; n     } n     if (s3 == 0) { n       s3 = j; n       break; n     } n   } n   s1 = add[s3] + s1; n   cout << s1; n } n signed main() { n   ios_base::sync_with_stdio(false); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int s, v = 0; n   int arr[n]; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   for (int i = 0; i < n - 1; i++) { n     if (arr[i] > arr[i + 1]) { n       s = i + 1; n       v++; n     } n   } n   if (arr[n - 1] > arr[0]) { n     s = n; n     v++; n   } n   if (v == 0) n     cout <<  0  << endl; n   else { n     if (v > 1) n       cout <<  -1  << endl; n     else n       cout << n - s << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string t1, t2, t3, t4; n   cin >> t1 >> t2 >> t3 >> t4; n   string b = t1 + t2[1] + t2[0], e = t3 + t4[1] + t4[0]; n   b.erase(b.find( X ), 1); n   e.erase(e.find( X ), 1); n   for (int i = 0; i < 3; ++i) { n     string a1 = e.substr(i); n     string a2 = e.substr(0, i); n     if (b == a1 + a2) { n       cout <<  YES  << endl; n       return 0; n     } n   } n   cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T0, typename T1> n std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { n   for (typename map<T0, T1>::const_iterator p = v.begin(); p != v.end(); p++) { n     os << p->first <<  :   << p->second <<    ; n   } n   return os; n } n template <typename T0, typename T1> n std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { n   os << v.first <<  :   << v.second <<    ; n   return os; n } n template <typename T> n std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { n   for (int i = 0; i < (int)v.size(); i++) { n     os << v[i] << endl; n   } n   return os; n } n template <typename T> n std::ostream& operator<<(std::ostream& os, const vector<T>& v) { n   for (int i = 0; i < (int)v.size(); i++) { n     os << v[i] <<    ; n   } n   return os; n } n template <typename T> n std::ostream& operator<<(std::ostream& os, const set<T>& v) { n   vector<T> tmp(v.begin(), v.end()); n   os << tmp; n   return os; n } n template <typename T> n std::ostream& operator<<(std::ostream& os, const deque<T>& v) { n   vector<T> tmp(v.begin(), v.end()); n   os << tmp; n   return os; n } n int main() { n   long long N, M; n   while (cin >> N >> M) { n     long long lo = 1, hi = M + 1; n     while (lo + 1 < hi) { n       long long mid = (lo + hi) / 2; n       long long edges = mid * (mid - 1) / 2; n       if (mid % 2 == 0 && mid - 2 > 0) edges += (mid - 2) / 2; n       if (edges <= N - 1) n         lo = mid; n       else n         hi = mid; n     } n     vector<long long> w(M); n     for (int i = 0, _n = (M); (i) < (int)_n; ++i) { n       long long v; n       cin >> v >> w[i]; n     } n     sort((w).rbegin(), (w).rend()); n     cout << accumulate(&w[0], &w[lo], 0) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string st, st1; n   cin >> st >> st1; n   if (st == st1) { n     cout << st << endl; n   } else { n     cout <<  1  << endl; n   } n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n template <class c> n struct rge { n   c b, e; n }; n template <class c> n rge<c> range(c i, c j) { n   return rge<c>{i, j}; n } n template <class c> n auto dud(c* x) -> decltype(cerr << *x, 0); n template <class c> n char dud(...); n struct debug { n   template <class c> n   debug& operator<<(const c&) { n     return *this; n   } n }; n long long n, p; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long te; n   cin >> te; n   while (te--) { n     cin >> n >> p; n     vector<pair<long long, long long> > ans; n     for (long long i = 1; i <= n; i++) { n       for (long long j = i + 1; j <= n; j++) { n         ans.push_back({i, j}); n       } n     } n     for (long long i = 0; i < 2 * n + p; i++) n       cout << ans[i].first <<     << ans[i].second <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double pi = 3.1415926535897932384626433832795; n const long double eps = 0.000000001; n const int INF = 1E9; n const int MAXN = 100000; n int ans, a[2], mn; n string s[2]; n char c; n bool f[2]; n int getn(char c) { return ( 0  <= c && c <=  9 ) ? (c -  0 ) : (c -  A  + 10); } n int main() { n   c = getchar(); n   while (c !=  : ) { n     s[0] += c; n     c = getchar(); n   } n   cin >> s[1]; n   for (int k = 0; k < (int)(2); k++) n     for (int i = 0; i < (int)(s[k].size() - 1); i++) n       if (s[k][i] !=  0 ) f[k] = 1; n   if (f[0] || f[1]) { n     f[0] = 1; n     for (int i = (int)(2); i <= (int)(60); i++) { n       f[1] = 1; n       for (int j = 0; j < (int)(2); j++) { n         mn = 1; n         a[j] = 0; n         for (int k = (int)(s[j].size()) - 1; k >= 0; k--) { n           if (getn(s[j][k]) >= i) f[1] = 0; n           a[j] += mn * getn(s[j][k]); n           mn *= i; n         } n       } n       if (f[1] && a[0] <= 23 && a[1] <= 59) { n         cout << i <<    ; n         f[0] = 0; n       } n     } n     if (f[0]) cout << 0 << endl; n   } else { n     if (getn(s[0][s[0].size() - 1]) <= 23) n       cout << -1; n     else n       cout << 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t, n; n string s; n int main() { n   cin >> t; n   for (int tc = 0; tc < t; ++tc) { n     cin >> n >> s; n     int res = n - 1; n     for (int i = 0; i < n; ++i) n       if (s[i] ==  >  || s[n - 1 - i] ==  < ) res = min(res, i); n     cout << res << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(int, char**) { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   string s; n   cin >> s; n   ; n   int k; n   cin >> k; n   ; n   int out = 0; n   long long d = 1; n   for (int i = 0; i < k; i++) { n     d *= 10; n   } n   while (atoi(s.c_str()) % d != 0) { n     for (string::reverse_iterator i = s.rbegin(); i != s.rend(); i++) { n       if (*i !=  0 ) { n         s.erase((i.base()) - 1); n         out++; n         break; n       } n     } n   } n   if (atoi(s.c_str()) == 0) { n     out += s.length() - 1; n   } n   cout << out <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int in[201000]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < (n); i++) { n     scanf( %d , &in[i]); n     in[i] += i; n   } n   sort(in, in + n); n   for (int i = 0; i < (n - 1); i++) { n     if (in[i] == in[i + 1]) { n       puts( :( ); n       return 0; n     } n   } n   for (int i = 0; i < (n); i++) n     printf( %d%c , in[i] - i, ((i == n - 1) ?   n  :    )); 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   const int maxn = 1e6 + 5e5; n   vector<int> pr(maxn); n   iota(pr.begin(), pr.end(), 0); n   for (long long i = 2; i < maxn; ++i) n     if (pr[i] == i) n       for (long long j = i * i; j < maxn; j += i) pr[j] = i; n   vector<bool> good(maxn, true); n   good[0] = good[1] = false; n   auto fill = [&](int x) { n     while (x > 1) { n       int p = pr[x]; n       while (x % p == 0) x /= p; n       if (good[p]) n         for (int x = p; x < maxn; x += p) good[x] = false; n     } n   }; n   bool ok = true; n   int n; n   cin >> n; n   for (int i = 0; i < n; ++i) { n     int x; n     cin >> x; n     if (!ok) continue; n     if (good[x]) { n       cout << x <<    n [i + 1 == n]; n       fill(x); n     } else { n       ok = false; n       while (!good[x]) ++x; n       cout << x <<    n [i + 1 == n]; n       fill(x); n       for (int j = i + 1, p = 2; j < n; ++j) { n         while (!good[p]) ++p; n         cout << p <<    n [j + 1 == n]; n         fill(p); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using std::cin; n using std::cout; n using std::string; n using std::vector; n static const int MOD = 1000000000 + 7; n static long long gcd(long long x, long long y) { n   return (!y) ? x : gcd(y, x % y); n } n int read_int() { n   int x = 0, c = 0; n   c = getchar(); n   while (c <= 32) c = getchar(); n   while (c >=  0  && c <=  9 ) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   return x; n } n static const int N = 300000 + 8; n static const int SH = 20; n int n, c1, c2; n int dep[N], fa[N][SH], p1[N], p2[N]; n int lca(int a, int b) { n   if (dep[a] < dep[b]) ::std::swap(a, b); n   int dif = dep[a] - dep[b]; n   for (int i = 0; (1 << i) <= dif; i++) { n     if (dif & (1 << i)) a = fa[a][i]; n   } n   if (a == b) return a; n   for (int i = SH - 1; i >= 0; i--) { n     if (fa[a][i] ^ fa[b][i]) { n       a = fa[a][i]; n       b = fa[b][i]; n     } n   } n   return fa[a][0]; n } n int get(int a, int b) { return dep[a] + dep[b] - 2 * dep[lca(a, b)]; } n int solve() { n   int mx = 0; n   n = read_int(); n   p1[++c1] = 1; n   for (int i = 2; i <= n + 1; i++) { n     int pos = read_int(); n     fa[i][0] = pos; n     dep[i] = dep[pos] + 1; n     for (int j = 1; (1 << j) <= dep[i]; j++) { n       fa[i][j] = fa[fa[i][j - 1]][j - 1]; n     } n     int d1 = (c1 == 0 ? 0 : get(p1[1], i)); n     int d2 = (c2 == 0 ? 0 : get(p2[1], i)); n     if (d1 > mx) { n       for (int j = 1; j <= c2; j++) { n         if (get(p2[j], i) == d1) { n           p1[++c1] = p2[j]; n         } n       } n       c2 = 1; n       p2[1] = i; n     } else if (d2 > mx) { n       for (int j = 1; j <= c1; j++) { n         if (get(p1[j], i) == d2) { n           p2[++c2] = p1[j]; n         } n       } n       c1 = 1; n       p1[1] = i; n     } else if (d1 == mx) n       p2[++c2] = i; n     else if (d2 == mx) n       p1[++c1] = i; n     mx = ::std::max(mx, ::std::max(d1, d2)); n     printf( %d n , c1 + c2); n   } n   return 0; n } n int main(int argc, char* argv[]) { n   ::std::ios::sync_with_stdio(false); n   ::std::cin.tie(0); n   ::std::cout.tie(0); n   int test_count = 1; n   while (test_count--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b; n   cin >> a >> b; n   int n = a + b + 1; n   int A[100000] = {0}; n   int x = n - a; n   for (int i = 0; i < a + 1; i++) { n     A[i] = x; n     x++; n   } n   x = n - a - 1; n   for (int i = a + 1; i < n; i++) { n     A[i] = x; n     x--; n   } n   for (int i = 0; i < n; i++) cout << A[i] <<    ; n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long int a, b, c, d, m, n, p, q, r, x, y, z, aa, bb, cc, dd; n   double pp, qq, rr, xx, yy, zz; n   char ch1, ch2, ch3, ch4, ch5; n   long long int i, j, k, l; n   long long int cnt = 0, cnt1 = 0, cnt2 = 0, cnt3 = 0, sum = 0, sum2 = 0, n                 mx = LLONG_MIN, mn = LLONG_MAX; n   long long int flag = 0, flag2 = 0; n   vector<long long int> vec1, vec2, vec3; n   string s1, s2, s3; n   cin >> n; n   for (long long int i = (long long int)(0); i < (long long int)(n); ++i) { n     cin >> x; n     vec1.push_back(x); n   } n   for (long long int i = (long long int)(0); i < (long long int)(n); ++i) { n     cin >> x; n     vec2.push_back(x); n   } n   if (n == 1) { n     cout <<  0 n ; n     return; n   } n   for (long long int i = (long long int)(n - 1); i >= (long long int)(0); --i) { n     sum += vec1[i]; n     vec1[i] = sum; n   } n   sum = 0; n   for (long long int i = (long long int)(0); i < (long long int)(n); ++i) { n     sum += vec2[i]; n     vec2[i] = sum; n   } n   for (long long int i = (long long int)(0); i < (long long int)(n - 2); ++i) { n     mx = max(vec2[i], vec1[i + 2]); n     mn = min(mn, mx); n   } n   mn = min(mn, vec1[1]); n   mn = min(mn, vec2[n - 2]); n   cout << mn << endl; n } n int main() { n   ios::sync_with_stdio(false); n   long long int t = 1; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   char s1[3000][11], s2[3000][10], s3[3000][11]; n   int m, n, i, j, k; n   int len1, len2; n   scanf( %d %d , &m, &n); n   for (i = 0; i < n; i++) { n     scanf( %s  , &s1[i]); n     gets(s2[i]); n   } n   for (i = 0; i < m - 1; i++) { n     scanf( %s  , &s3[i]); n   } n   gets(s3[m - 1]); n   for (i = 0; i < m; i++) { n     for (j = 0; j < n; j++) { n       if (strcmp(s3[i], s1[j]) == 0 || strcmp(s3[i], s2[j]) == 0) { n         len1 = strlen(s1[j]); n         len2 = strlen(s2[j]); n         if (len1 < len2) { n           k = 0; n           while (s1[j][k]) { n             printf( %c , s1[j][k]); n             k++; n           } n           printf(   ); n         } else if (len1 == len2) { n           k = 0; n           while (s1[j][k]) { n             printf( %c , s1[j][k]); n             k++; n           } n           printf(   ); n         } else { n           k = 0; n           while (s2[j][k]) { n             printf( %c , s2[j][k]); n             k++; n           } n           printf(   ); n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n int main(void) { n   int i, j, k, m, n, mm[110][110]; n   mm[0][0] = mm[1][0] = 0; n   mm[1][1] = 1; n   mm[0][1] = 2; n   for (i = 2; i <= 100; i++) { n     if (i == 2) k = 5; n     for (j = 0; j <= i; j++) mm[i][j] = k; n     for (j = i - 1; j >= 0; j--) mm[j][i] = k + 1; n     k = mm[i][0] + 4; n   } n   while (scanf( %d%d , &i, &j) != EOF) { n     if (i >= 0 && j >= 0) n       printf( %d n , mm[i][j]); n     else if (i == -1 && j == 0) n       printf( 3 n ); n     else if (i < 0) { n       if (j > -i) n         printf( %d n , mm[-i][j]); n       else if (j == -i) n         printf( %d n , mm[-i][j] + 1); n       else if (j >= 0) n         printf( %d n , mm[-i][j] + 2); n       else n         printf( %d n , mm[-i][-j] + 2); n     } else { n       if (i < -j) n         printf( %d n , mm[i][-j] + 2); n       else if (i == -j) n         printf( %d n , mm[i][-j] + 3); n       else if (i == -j + 1) n         printf( %d n , mm[i][-j] - 1); n       else n         printf( %d n , mm[i][-j]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n const long long int mx = 1e9 + 7; n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   int n, t; n   cin >> t; n   while (t--) { n     int n, k; n     cin >> n >> k; n     vector<pair<int, int>> vp, vpAns; n     map<int, int> mp, mpAns, mpCnt; n     int A[n + 2], x = n / k; n     for (int i = 0; i < n; i++) { n       cin >> A[i]; n       vp.push_back(make_pair(A[i], i)); n     } n     sort(vp.begin(), vp.end()); n     int cnt = 0, cn = 0; n     for (int i = 0; i < n; i++) { n       int a = vp[i].first, b = vp[i].second; n       mp[a]++; n       if (mp[a] > k) { n         vpAns.push_back(make_pair(b, 0)); n         continue; n       } n       cnt++; n       vpAns.push_back(make_pair(b, cnt)); n       mpCnt[cnt]++; n       if (cnt == k) cnt = 0; n     } n     int mn = 10000000; n     for (auto u : mpCnt) { n       mn = min(mn, u.second); n     } n     sort(vpAns.begin(), vpAns.end()); n     for (int i = 0; i < vpAns.size(); i++) { n       int b = vpAns[i].second; n       mpAns[b]++; n       if (mpAns[b] > mn) n         cout << 0 <<    ; n       else n         cout << vpAns[i].second <<    ; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 100; n const int mod = 1e9 + 7; n int t; n int n; n int m; n long long p[maxn]; n int size[maxn]; n vector<int> g[maxn]; n void dfs(int u, int pre) { n   size[u] = 1; n   for (int v : g[u]) { n     if (v == pre) continue; n     dfs(v, u); n     size[u] += size[v]; n   } n } n struct node { n   long long x, y; n   bool operator<(const node &r) const { n     return (long long)x * y > (long long)r.x * r.y; n   } n } Node[maxn]; n bool cmp(int x, int y) { return x > y; } n int main() { n   scanf( %d , &t); n   while (t--) { n     scanf( %d , &n); n     for (int i = 1; i <= n; i++) g[i].clear(); n     for (int i = 1; i < n; i++) { n       int x, y; n       scanf( %d%d , &x, &y); n       g[x].push_back(y); n       g[y].push_back(x); n     } n     scanf( %d , &m); n     for (int i = 1; i <= m; i++) scanf( %lld , p + i); n     sort(p + 1, p + m + 1, cmp); n     dfs(1, 0); n     int tot = 0; n     for (int i = 2; i <= n; i++) n       Node[++tot] = {(long long)n - size[i], (long long)size[i]}; n     sort(Node + 1, Node + tot + 1); n     long long ans = 0; n     if (n - 1 >= m) { n       for (int i = 1; i <= m; i++) { n         ans += (long long)p[i] * Node[i].x * Node[i].y; n         ans %= mod; n       } n       for (int i = m + 1; i <= tot; i++) { n         ans += (long long)Node[i].x * Node[i].y; n         ans %= mod; n       } n     } else { n       long long tt = 1; n       for (int i = 1; i <= (m - n + 2); i++) { n         tt *= p[i]; n         tt %= mod; n       } n       ans += (long long)tt * Node[1].x % mod * Node[1].y; n       ans %= mod; n       for (int i = m - n + 3; i <= m; i++) { n         ans += n             (long long)p[i] * Node[i - (m - n + 1)].x * Node[i - (m - n + 1)].y; n         ans %= mod; n       } n     } n     printf( %lld n , ans); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int S[100009], cnt[1 << 7], num[1 << 7]; n char s[100009]; n int len, n, nu; n inline long long rd() { n   long long x = 0; n   char c = getchar(); n   bool f = 0; n   while (!isdigit(c)) { n     if (c ==  - ) f = 1; n     c = getchar(); n   } n   while (isdigit(c)) { n     x = (x << 1) + (x << 3) + (c ^ 48); n     c = getchar(); n   } n   return f ? -x : x; n } n int main() { n   scanf( %s , s + 1); n   len = strlen(s + 1); n   int x; n   int maxn = (1 << 6) - 1; n   for (int i = 1; i <= len; ++i) { n     int x = s[i] -  a ; n     for (int j = 1; j <= maxn; ++j) n       if (j & (1 << x)) cnt[j]++; n   } n   n = rd(); n   for (int i = 1; i <= n; ++i) { n     x = rd(); n     scanf( %s , s + 1); n     int xx = strlen(s + 1); n     for (int j = 1; j <= xx; ++j) S[x] |= (1 << (s[j] -  a )); n     for (int j = 1; j <= maxn; ++j) n       if ((j & S[x]) == S[x]) num[j]++; n   } n   for (int i = 1; i <= len; ++i) n     if (!S[i]) { n       S[i] = maxn; n       num[S[i]]++; n     } n   for (int i = 1; i <= len; ++i) { n     bool tag = 0; n     for (int j = 0; j < 6; ++j) n       if ((1 << j) & S[i]) { n         bool tg = 0; n         for (int k = 1; k <= maxn; ++k) { n           int x = (k & (1 << j)) ? cnt[k] - 1 : cnt[k], n               y = ((k & S[i]) == S[i]) ? num[k] - 1 : num[k]; n           if (x < y) { n             tg = 1; n             break; n           } n         } n         if (!tg) { n           tag = 1; n           s[++nu] = j +  a ; n           for (int k = 1; k <= maxn; ++k) { n             if ((1 << j) & k) cnt[k]--; n             if ((S[i] & k) == S[i]) num[k]--; n           } n           break; n         } n       } n     if (!tag) { n       puts( Impossible ); n       return 0; n     } n   } n   for (int i = 1; i <= nu; ++i) printf( %c , s[i]); n   return 0; n } n


#include <bits/stdc++.h> n long long nmax[11] = {0,      9,       99,       999,       9999,        99999, n                       999999, 9999999, 99999999, 999999999, 9999999999LL}; n long long P[11][11]; n long long cnt[11][11][11], C[11][11], totalcnt[11][11], tmp; n long long nsel[11][11][11][11][11], fact[11], nways; n int N, x, y, len, i, j, jstart, nx, ny, cnx, cny, difx, dify, nextx, nexty; n void ComputeComb() { n   int i, j; n   C[0][0] = 1; n   for (i = 1; i < 11; i++) { n     C[i][0] = 1; n     for (j = 1; j <= i; j++) { n       C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 1000000007; n     } n   } n } n inline int extended_gcd(long long A, long long B, long long &X, long long &Y) { n   if (B == 0) { n     X = 1; n     Y = 0; n     return A; n   } n   long long X0, Y0, D; n   D = extended_gcd(B, A % B, X0, Y0); n   X = Y0; n   Y = X0 - (A / B) * Y0; n   return D; n } n long long inv[11]; n void ComputeInv() { n   long long garbage; n   for (int i = 1; i < 11; i++) { n     extended_gcd(i, 1000000007, inv[i], garbage); n     inv[i] %= 1000000007; n     while (inv[i] < 0) inv[i] += 1000000007; n   } n } n void ComputeFact() { n   fact[0] = 1; n   for (int i = 1; i < 11; i++) { n     fact[i] = (fact[i - 1] * i) % 1000000007; n   } n } n void ComputeP() { n   int i, j; n   for (i = 0; i < 11; i++) { n     P[i][0] = 1; n     for (j = 1; j < 11; j++) P[i][j] = (P[i][j - 1] * i) % 1000000007; n   } n } n int digits[11], ndigits; n void GetN(int N) { n   ndigits = 0; n   while (N > 0) { n     digits[ndigits] = N % 10; n     N /= 10; n     ndigits++; n   } n } n long long totalcnt2[11][11]; n void TestBruteForce() { n   int x, y, i, j; n   for (i = 1; i <= N; i++) { n     x = y = 0; n     j = i; n     while (j > 0) { n       if (j % 10 == 4) n         x++; n       else if (j % 10 == 7) n         y++; n       j /= 10; n     } n     totalcnt2[x][y]++; n   } n   for (x = 0; x < 11; x++) n     for (y = 0; y < 11; y++) n       if (totalcnt[x][y] != totalcnt2[x][y]) { n         fprintf(stderr,  !!! x=%d y=%d: %I64d %I64d n , x, y, totalcnt[x][y], n                 totalcnt2[x][y]); n       } n } n int main() { n   ComputeComb(); n   ComputeInv(); n   ComputeFact(); n   ComputeP(); n   scanf( %d , &N); n   GetN(N); n   for (len = 1; len < 11; len++) n     for (x = 0; x < 11 && x <= len; x++) n       for (y = 0; y < 11 && x + y <= len; y++) { n         cnt[len][x][y] = 0; n         if (len < ndigits) { n           if (x == 0 && y == 0) n             tmp = P[8][len] % 1000000007; n           else { n             tmp = (C[len][x] * C[len - x][y]); n             tmp = (tmp * P[8][len - x - y]); n           } n           cnt[len][x][y] = tmp; n         } else if (len == ndigits) { n           nx = ny = 0; n           for (i = ndigits - 1; i >= 0; i--) { n             if (i == ndigits - 1) n               jstart = 1; n             else n               jstart = 0; n             for (j = jstart; j < digits[i]; j++) { n               cnx = nx; n               cny = ny; n               if (j == 4) n                 cnx++; n               else if (j == 7) n                 cny++; n               if (cnx <= x && cny <= y) { n                 difx = x - cnx; n                 dify = y - cny; n                 if (difx == 0 && dify == 0) n                   cnt[len][x][y] = (cnt[len][x][y] + P[8][i]); n                 else n                   cnt[len][x][y] = (cnt[len][x][y] + cnt[i][difx][dify]); n               } n             } n             if (digits[i] == 4) n               nx++; n             else if (digits[i] == 7) n               ny++; n           } n           if (nx == x && ny == y) cnt[len][x][y]++; n         } n         if (len >= ndigits - 1) { n           totalcnt[x][y] += cnt[len][x][y]; n           if (x == 0 && y == 0 && len == ndigits - 1) totalcnt[x][y]--; n         } n       } n   for (x = 0; x < 11; x++) n     for (y = 0; y < 11; y++) n       if (totalcnt[x][y] > 0) { n       } n   nways = 1; n   for (i = 0; i <= 6; i++) { n     if (i > 0) { n       nways = (nways * (totalcnt[0][0] - i + 1)) % 1000000007; n       nways = (nways * inv[i]) % 1000000007; n     } n     nsel[0][0][0][0][i] = nways; n   } n   for (x = 0; x < 11; x++) n     for (y = 0; y < 11; y++) n       for (nx = 0; nx < 11; nx++) n         for (ny = 0; ny < 11; ny++) n           for (i = 0; i <= 6; i++) n             if (nsel[x][y][nx][ny][i] > 0) { n               cnx = x; n               cny = y + 1; n               if (cny >= 11) { n                 cnx++; n                 cny = 0; n               } n               if (cnx >= 11) break; n               nways = 1; n               for (j = 0; j <= 6; j++) { n                 nextx = nx + j * cnx; n                 nexty = ny + j * cny; n                 if (nextx >= 11 || nexty >= 11 || i + j > 6) break; n                 if (j > 0) { n                   nways = (nways * (totalcnt[cnx][cny] - j + 1)) % 1000000007; n                   nways = (nways * inv[j]) % 1000000007; n                 } n                 tmp = (nways * nsel[x][y][nx][ny][i]) % 1000000007; n                 nsel[cnx][cny][nextx][nexty][i + j] = n                     (nsel[cnx][cny][nextx][nexty][i + j] + tmp) % 1000000007; n               } n             } n   long long answer = 0; n   for (x = 0; x < 11; x++) n     for (y = 0; y < 11; y++) n       for (nx = 0; nx < 11; nx++) n         for (ny = 0; ny < 11; ny++) n           if (nx + ny < x + y) { n             tmp = totalcnt[x][y]; n             tmp = (tmp * nsel[11 - 1][11 - 1][nx][ny][6]) % 1000000007; n             answer = (answer + tmp) % 1000000007; n           } n   printf( %I64d n , (answer * fact[6]) % 1000000007); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, n; n   cin >> a >> b >> n; n   cout << min(b, n) - n + min(a, n) + 1 <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   cin >> n; n   int a[n]; n   vector<int> ans; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   sort(a, a + n); n   ans.push_back(a[0]); n   for (int i = 1; i < n; i++) { n     if (a[i] != ans.back()) ans.push_back(a[i]); n   } n   bool got = false; n   int len = ans.size(); n   for (int i = 0; i < len - 2; i++) { n     if ((ans[i + 1] - ans[i] < 3 && ans[i + 2] - ans[i] < 3 && n          ans[i + 2] - ans[i + 1] < 3)) { n       got = true; n       break; n     } n   } n   cout << (got ?  YES n  :  NO 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   int cnt = 0, count = 0; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  8 ) cnt++; n   } n   while (cnt) { n     n = n - 1; n     cnt = cnt - 1; n     if (n / 10 > 0) { n       count++; n       n = n - 10; n     } n   } n   cout << count; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 50, mo = 998244353; n int head[N], nn[N << 1][2], cnt; n void link(int u, int v) { n   nn[++cnt][1] = v, nn[cnt][0] = head[u], head[u] = cnt; n   nn[++cnt][1] = u, nn[cnt][0] = head[v], head[v] = cnt; n   return; n } n int f[N][3]; n void dfs(int x, int fa) { n   f[x][0] = 1; n   for (int i = head[x], y; i; i = nn[i][0]) n     if ((y = nn[i][1]) != fa) { n       dfs(y, x); n       int s1 = f[x][1], s2 = f[x][2]; n       f[x][1] = (1ll * (f[x][0] + s2) * (f[y][0] + f[y][2]) % mo + n                  2ll * s1 * f[y][1] % mo + 1ll * s1 * f[y][0]) % n                 mo; n       f[x][2] = n           (2ll * s2 * f[y][1] + 1ll * f[x][0] * f[y][1] + 1ll * s2 * f[y][0]) % n           mo; n       f[x][0] = 1ll * f[x][0] * (f[y][0] + f[y][1]) % mo; n     } n   return; n } n int main() { n   int n, u, v; n   cin >> n; n   for (int i = 1; i < n; ++i) scanf( %d%d , &u, &v), link(u, v); n   dfs(1, 0); n   cout << (f[1][0] + f[1][1]) % mo; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n long long m, x, p[22], a[22], b[22], len, res = 1; n map<long long, int> Map[22]; n inline void init(long long n) { n   for (register long long i = 2; i * i <= n; i++) n     if (n % i == 0) { n       len++; n       p[len] = i; n       while (n % i == 0) n /= i, a[len]++; n     } n   if (n > 1) len++, p[len] = n, a[len] = 1; n } n inline void init2(long long n, int tp) { n   for (register long long i = 2; i * i <= n; i++) { n     while (n % i == 0) Map[tp][i]++, n /= i; n   } n   if (n > 1) Map[tp][n]++; n } n inline long long mul(long long a, long long n, long long mo) { n   long long res = 0; n   n %= mo; n   a %= mo; n   if (mo <= 2000000000) return a * n % mo; n   while (n) { n     if (n & 1) res = res + a < mo ? res + a : res + a; n     a = a + a < mo ? a + a : a + a - mo; n     n >>= 1; n   } n   return res % mo; n } n inline long long power(long long a, long long n, long long mo) { n   long long res = 1; n   if (mo == 1) return 0; n   n %= mo - 1; n   while (n) { n     if (n & 1) res = mul(res, a, mo); n     a = mul(a, a, mo); n     n >>= 1; n   } n   return res; n } n inline void dfs(int dep, long long d) { n   if (dep > len) { n     if (d == 1) return; n     map<long long, int> fac; n     for (register int i = 1; i <= (len); i++) n       if (b[i]) { n         if (b[i] - 1) fac[p[i]] += b[i] - 1; n         for (map<long long, int>::iterator it = Map[i].begin(); n              it != Map[i].end(); it++) n           fac[(*it).first] += (*it).second; n       } n     static long long c[22]; n     int tot = 0; n     long long phi = 1; n     for (map<long long, int>::iterator it = fac.begin(); it != fac.end(); n          it++) { n       tot++, c[tot] = (*it).first; n       for (register int i = 1; i <= ((*it).second); i++) phi *= c[tot]; n     } n     long long k = phi; n     for (register int i = 1; i <= (tot); i++) { n       while (k % c[i] == 0 && power(x, k / c[i], d) == 1) k /= c[i]; n     } n     res += phi / k; n     return; n   } n   for (register int i = 0; i <= (a[dep]); i++) n     b[dep] = i, dfs(dep + 1, d), d *= p[dep], b[dep] = 0; n } n int main() { n   scanf( %lld%lld , &m, &x); n   init(m); n   for (register int i = 1; i <= (len); i++) init2(p[i] - 1, i); n   dfs(1, 1); n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e9; n const int M = 1000010; n const int MAX = M; n struct BIT { n   int bit[MAX + 1], N; n   BIT() {} n   BIT(int N) : N(N) { memset(bit, 0, sizeof(bit)); } n   int sum(int i) { n     i++; n     int ret = 0; n     while (i) { n       ret += bit[i]; n       i -= i & -i; n     } n     return ret; n   } n   int sum(int i, int j) { return sum(j - 1) - sum(i - 1); } n   void add(int i, int x) { n     i++; n     while (i <= N) { n       bit[i] += x; n       i += i & -i; n     } n   } n   int find(int i) { n     int lb = -1, ub = N, mid; n     while (ub - lb > 1) { n       mid = (lb + ub) / 2; n       if (sum(mid) >= i) n         ub = mid; n       else n         lb = mid; n     } n     return ub; n   } n }; n int n, m, a[M], seq[M], k[M]; n int len, ns, ms; n BIT b; n void solve() { n   if (!len) { n     puts( Poor stack! ); n     return; n   } n   b = BIT(ns); n   for (int i = (int)(0); i < (int)(ns); i++) b.add(i, 1); n   for (int i = (int)(0); i < (int)(ms); i++) { n     for (int j = k[i] - 1; j >= 0; --j) { n       int pos = b.find(a[j]); n       b.add(pos, -1); n     } n   } n   for (int i = (int)(0); i < (int)(ns); i++) n     if (b.sum(i, i + 1)) printf( %d , seq[i]); n   puts(  ); n } n void input() { n   scanf( %d%d , &n, &m); n   for (int i = (int)(0); i < (int)(m); i++) scanf( %d , a + i); n   for (int i = (int)(0); i < (int)(n); i++) { n     scanf( %d , seq + ns); n     if (seq[ns] < 0) { n       if (a[0] > len) continue; n       k[ms] = lower_bound(a, a + m, len + 1) - a; n       len -= k[ms++]; n     } else n       ++len, ++ns; n   } n } n int main() { n   input(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<int> newvec; n   int n; n   int x; n   int ans; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> x; n     newvec.push_back(x); n   } n   sort(newvec.begin(), newvec.end()); n   if (newvec.size() % 2 == 1) { n     ans = newvec[newvec.size() / 2]; n   } else { n     ans = newvec[newvec.size() / 2 - 1]; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = pow(10, 9) + 7; n long long fac[1001]; n template <typename T, typename U> n static inline void amin(T &x, U y) { n   if (y < x) x = y; n } n template <typename T, typename U> n static inline void amax(T &x, U y) { n   if (x < y) x = y; n } n void SieveOfEratosthenes(long long n) { n   bool prime[n + 1]; n   memset(prime, true, sizeof(prime)); n   for (long long p = 2; p * p <= n; p++) { n     if (prime[p] == true) { n       for (long long i = p * p; i <= n; i += p) prime[i] = false; n     } n   } n   for (long long p = 2; p <= n; p++) n     if (prime[p]) n       ; n } n long long power(long long x, long long y, long long p) { n   long long res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n long long modInverse(long long n, long long p) { return power(n, p - 2, p); } n long long nCrModPFermat(long long n, long long r, long long p) { n   if (n < r) return 0; n   if (r == 0) return 1; n   return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % n          p; n } n void dfs(long long v, vector<vector<long long>> &adj, vector<long long> &used, n          vector<long long> &maxD) { n   for (long long u : adj[v]) { n     if (!used[u]) { n       used[u] = 1; n       if (adj[u].size() == 1 && u != 1) { n         maxD[u] = 0; n         amax(maxD[v], 1 + maxD[u]); n       } else { n         dfs(u, adj, used, maxD); n         amax(maxD[v], 1 + maxD[u]); n       } n     } n   } n } n void solve() { n   long long n, x, i; n   cin >> n >> x; n   vector<vector<long long>> adj(n + 1); n   long long u, v; n   for (i = 2; i <= n; i++) { n     cin >> u >> v; n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   vector<long long> d(n + 1); n   d[1] = 0; n   vector<long long> visited(n + 1); n   vector<long long> parent(n + 1); n   visited[1] = 1; n   parent[1] = 0; n   queue<long long> q; n   q.push(1); n   while (!q.empty()) { n     long long p = q.front(); n     q.pop(); n     for (auto el : adj[p]) { n       if (!visited[el]) { n         visited[el] = 1; n         q.push(el); n         d[el] = d[p] + 1; n         parent[el] = p; n       } n     } n   } n   vector<long long> maxD(n + 1), used(n + 1); n   used[1] = 1; n   dfs(1, adj, used, maxD); n   long long f = 1, ans = max(maxD[x] * 2, (abs(d[1] - d[x]) + maxD[x]) * 2), n             start = x; n   while (f) { n     long long el = parent[x]; n     if (abs(d[el] - d[1]) > abs(d[el] - d[start])) { n       long long z = max(maxD[el] * 2, (abs(d[1] - d[el]) + maxD[el]) * 2); n       amax(ans, z); n       x = el; n     } else { n       f = 0; n       break; n     } n   } n   cout << ans << endl; n   return; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long test = 1; n   switch (test) { n     case 1: n       solve(); n       break; n     case 2: { n       long long t; n       cin >> t; n       while (t--) { n         solve(); n       } n     }; break; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int T; n int n; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> T; n   while (T--) { n     cin >> n; n     float FloatN = n; n     int Num8 = ceil(FloatN / 4); n     int Num9 = n - Num8; n     for (int i = 0; i < Num9; ++i) { n       cout << 9; n     } n     for (int i = 0; i < Num8; ++i) { n       cout << 8; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 12; n int b[MAXN][MAXN][MAXN], ans, k, n, m; n bool mark[MAXN][MAXN][MAXN]; n void dfs(int i, int j, int l) { n   mark[i][j][l] = true; n   if (j > 0) n     if (b[i][j - 1][l] == 0 && !mark[i][j - 1][l]) { n       ans++; n       dfs(i, j - 1, l); n     } n   if (l > 0) n     if (b[i][j][l - 1] == 0 && !mark[i][j][l - 1]) { n       ans++; n       dfs(i, j, l - 1); n     } n   if (j < n - 1) n     if (b[i][j + 1][l] == 0 && !mark[i][j + 1][l]) { n       ans++; n       dfs(i, j + 1, l); n     } n   if (l < m - 1) n     if (b[i][j][l + 1] == 0 && !mark[i][j][l + 1]) { n       ans++; n       dfs(i, j, l + 1); n     } n   if (i > 0) n     if (b[i - 1][j][l] == 0 && !mark[i - 1][j][l]) { n       ans++; n       dfs(i - 1, j, l); n     } n   if (i < k - 1) n     if (b[i + 1][j][l] == 0 && !mark[i + 1][j][l]) { n       ans++; n       dfs(i + 1, j, l); n     } n } n int main() { n   cin >> k >> n >> m; n   for (int i = 0; i < k; i++) { n     for (int j = 0; j < n; j++) { n       for (int l = 0; l < m; l++) { n         char ch; n         cin >> ch; n         if (ch ==  # ) b[i][j][l] = 1; n       } n     } n   } n   int x, y; n   cin >> x >> y; n   x--; n   y--; n   dfs(0, x, y); n   cout << ans + 1; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(3) n #pragma GCC optimize(2) n #pragma GCC optimize( Ofast ) n using namespace std; n vector<int> g[2097312]; n int a[2097312][2]; n char st[2097312]; n int f[2097312]; n int find(int x) { n   if (f[x] == x) return x; n   return f[x] = find(f[x]); n } n int main() { n   int n, i, j, cnt; n   scanf( %d , &n); n   scanf( %s , st + 1); n   for (i = n; i >= 1; --i) { n     if (st[i] !=  1 ) { n       a[i][0] = a[i + 1][0] + 1; n     } n     if (st[i] !=  0 ) { n       a[i][1] = a[i + 1][1] + 1; n     } n     g[max(a[i][1], a[i][0])].push_back(i); n     f[i] = i; n   } n   f[n + 1] = n + 1; n   for (i = 1; i <= n; ++i) { n     j = 1, cnt = 0; n     while (j <= n) { n       j = find(j); n       if (j > n) { n         break; n       } n       cnt++; n       j += i; n     } n     printf( %d  , cnt); n     for (auto v : g[i]) { n       f[v] = v + 1; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     long long a[n], b[n]; n     for (int i = 0; i < n; i++) cin >> a[i]; n     for (int i = 0; i < n; i++) cin >> b[i]; n     long long flag = 0, p = 0, ne = 0; n     if (a[0] != b[0]) { n       flag = 1; n       cout <<  NO  << endl; n       continue; n     } n     if (a[0] == 1) p++; n     if (a[0] == -1) ne++; n     for (int i = 1; i < n; i++) { n       if ((a[i] > b[i] && ne == 0) || (a[i] < b[i] && p == 0)) { n         flag = 1; n         cout <<  NO  << endl; n         break; n       } n       if (a[i] == 1) p++; n       if (a[i] == -1) ne++; n     } n     if (flag == 0) cout <<  YES  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int sum = 0, p = 1; n   char ch = getchar(); n   while (!(( 0  <= ch && ch <=  9 ) || ch ==  - )) ch = getchar(); n   if (ch ==  - ) p = -1, ch = getchar(); n   while ( 0  <= ch && ch <=  9 ) sum = sum * 10 + ch - 48, ch = getchar(); n   return sum * p; n } n const int maxn = 52; n const int mod = 1e9 + 7; n int n, f[maxn][maxn][maxn], g[maxn][maxn], d[maxn], dp[maxn][maxn][maxn], n     jc[maxn], jcn[maxn], inv[maxn]; n inline int C(int n, int m) { n   return (long long)jc[n] * jcn[m] % mod * jcn[n - m] % mod; n } n inline int power(int a, int b) { n   int ans = 1; n   while (b) { n     if (b & 1) ans = (long long)ans * a % mod; n     b >>= 1; n     a = (long long)a * a % mod; n   } n   return ans; n } n inline void init() { n   n = read(); n   for (int i = (1), _end_ = (n); i <= _end_; i++) d[i] = read(); n   jc[0] = jc[1] = jcn[0] = jcn[1] = inv[1] = 1; n   for (int i = (2), _end_ = (50); i <= _end_; i++) n     jc[i] = (long long)i * jc[i - 1] % mod, n     inv[i] = (long long)(mod - mod / i) * inv[mod % i] % mod, n     jcn[i] = (long long)inv[i] * jcn[i - 1] % mod; n   f[0][0][0] = 1; n   for (int k = (2), _end_ = (50); k <= _end_; k++) n     if (~k & 1) f[0][0][k] = (long long)f[0][0][k - 2] * (k - 1) % mod; n   for (int j = (1), _end_ = (50); j <= _end_; j++) n     for (int k = (0), _end_ = (50); k <= _end_; k++) n       if (~k & 1) { n         if (k >= 2) n           f[0][j][k] = n               (f[0][j][k] + (long long)f[0][j - 1][k - 2] * C(k, 2)) % mod; n         if (j >= 2) n           f[0][j][k] = n               (f[0][j][k] + (long long)f[0][j - 2][k] * (j - 1) * k) % mod; n         if (j >= 3) n           f[0][j][k] = n               (f[0][j][k] + (long long)f[0][j - 3][k + 2] * C(j - 1, 2)) % mod; n       } n   for (int i = (1), _end_ = (50); i <= _end_; i++) n     for (int j = (0), _end_ = (50); j <= _end_; j++) n       for (int k = (0), _end_ = (50); k <= _end_; k++) n         f[i][j][k] = ((j ? (long long)f[i - 1][j - 1][k + 1] * j : 0) + n                       (k ? (long long)f[i - 1][j][k - 1] * k : 0)) % n                      mod; n } n inline void doing() { n   dp[1][1][1] = 1; n   if (d[1] == 2) { n     dp[2][3][2] = 1; n   } else { n     dp[2][4][3] = 1; n   } n   for (int i = (3), _end_ = (n); i <= _end_; i++) { n     for (int j = (i), _end_ = (n); j <= _end_; j++) { n       for (int k = (1), _end_ = (j); k <= _end_; k++) { n         int A = 0, B = 0; n         for (int l = (1), _end_ = (j - k); l <= _end_; l++) { n           (d[j - k - l + 1] == 2 ? B : A)++; n           dp[i][j][k] = n               (dp[i][j][k] + (long long)dp[i - 1][j - k][l] * f[k][A][B]) % mod; n         } n       } n     } n   } n   int ans = 0; n   for (int i = (2), _end_ = (n); i <= _end_; i++) { n     int A = 0, B = 0; n     for (int k = (1), _end_ = (n); k <= _end_; k++) { n       (d[n - k + 1] == 2 ? B : A)++; n       ans = (ans + (long long)dp[i][n][k] * f[0][A][B]) % mod; n     } n   } n   printf( %d n , ans); n } n int main() { n   init(); n   doing(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n bool go(int x, multiset<int> &hand, deque<int> &dq) { n   if (hand.find(x) == hand.end()) return false; n   hand.erase(hand.find(x)); n   hand.insert(dq.front()); n   dq.pop_front(); n   dq.push_back(x); n   return true; n } n multiset<int> hand; n deque<int> dq; n int Try() { n   multiset<int> hand1 = hand; n   deque<int> dq1 = dq; n   int pos = -1; n   for (int i = 0; i < n; i++) { n     if (dq[i] == 1) pos = i; n   } n   if (pos == -1) return -1; n   for (int i = pos; i < n; i++) n     if (dq[i] != i - pos + 1) return -1; n   int done = n - pos; n   int ans = 0; n   while (done < n) { n     ++done; n     ++ans; n     if (!go(done, hand1, dq1)) return -1; n   } n   return ans; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     int x; n     cin >> x; n     hand.insert(x); n   } n   for (int i = 1; i <= n; i++) { n     int x; n     cin >> x; n     dq.push_back(x); n   } n   int ans = Try(); n   if (ans != -1) { n     cout << ans << endl; n     return 0; n   } n   ans = 0; n   while (hand.find(1) == hand.end()) { n     assert(go(0, hand, dq)); n     ans++; n   } n   int mx = n; n   for (int i = 0; i < n; i++) { n     if (dq[i] == 0) continue; n     int cur = i + 1 + (n + 1 - dq[i]); n     mx = max(mx, cur); n   } n   cout << ans + mx << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 2147483647, dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1}; n const int N = 100005, M = 1000005, K = 200005, mod = 1000000007; n const long long llinf = 9223372036854775807ll; n long long n, m, s, ans, ar; n long long f(long long a, long long b) { return (n - a + 1) * (m - b + 1); } n int main() { n   cin >> n >> m >> s; n   for (int i = 1; i <= n; i += 2) n     for (int j = 1; j <= m; j += 2) { n       if (i * j == s) n         ans += f(i, j) * (((i + 1) * (j + 1) / 2) - 1); n       else if (i * j > s) { n         ar = (i * j - s); n         if (ar % 4 != 0) continue; n         ar /= 4; n         for (int l = 1; l <= (i - 1) / 2; l++) n           if ((ar % l) == 0 && (ar / l) <= (j - 1) / 2) ans += f(i, j) * 2; n       } n     } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 300005; n pair<long long, long long> dif[maxn]; n long long x[maxn], y[maxn], pref[maxn], suff[maxn], ans[maxn]; n vector<int> adj[maxn]; n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= n; i++) { n     scanf( %lld %lld , &x[i], &y[i]); n     dif[i] = {y[i] - x[i], i}; n   } n   for (int i = 1; i <= m; i++) { n     int u, v; n     scanf( %d %d , &u, &v); n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   sort(dif + 1, dif + n + 1); n   for (int i = 1; i <= n; i++) { n     pref[i] = pref[i - 1] + y[dif[i].second]; n   } n   for (int i = n; i >= 1; i--) { n     suff[i] = suff[i + 1] + x[dif[i].second]; n   } n   for (int i = 1; i <= n; i++) { n     int u = dif[i].second; n     long long res = n         pref[i - 1] + suff[i + 1] + 1ll * (i - 1) * x[u] + 1ll * (n - i) * y[u]; n     for (auto v : adj[u]) { n       res -= min(x[u] + y[v], x[v] + y[u]); n     } n     ans[u] = res; n   } n   for (int i = 1; i <= n; i++) { n     printf( %lld  , ans[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   int ans = -1; n   int sum = 7; n   int i = 1; n   while (sum <= n) { n     int y = n - sum; n     if (y % 4 == 0) ans = i; n     sum += 7; n     i++; n   } n   if (ans != -1) { n     int s = 7 * ans; n     int y = n - s; n     int x = y / 4; n     while (x--) { n       cout <<  4 ; n     } n     while (ans--) { n       cout <<  7 ; n     } n     return 0; n   } n   if (n % 7 == 0) { n     int x = n / 7; n     while (x--) cout <<  7 ; n     return 0; n   } n   if (n % 4 == 0) { n     int x = n / 4; n     while (x--) cout <<  4 ; n     return 0; n   } n   cout <<  -1 ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string vow =  aeiou ; n const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2}; n const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1}; n const int dx[] = {-1, 0, 0, 1}; n const int dy[] = {0, -1, 1, 0}; n const long double pie = 3.14159265358979; n const long long mod = 1e9 + 7; n void solve(int test_case) { n   int k; n   cin >> k; n   string s; n   cin >> s; n   int n = s.size(); n   vector<int> pref(n + 1); n   for (int i = 1; i < n + 1; i++) pref[i] = pref[i - 1] + s[i - 1] -  0 ; n   long long ans = 0; n   for (int i = 0; i < n; i++) { n     int x = pref[i + 1]; n     int val = x - k; n     if (val < 0) continue; n     ; n     int ans_indx = -1; n     for (int lo = 0, hi = i; lo <= hi;) { n       int mid = lo + hi >> 1; n       if (pref[mid] > val) n         hi = mid - 1; n       else if (pref[mid] == val) n         ans_indx = mid, hi = mid - 1; n       else n         lo = mid + 1; n     } n     if (ans_indx == -1) continue; n     ; n     long long L = ans_indx; n     ans_indx = -1; n     for (int lo = 0, hi = i; lo <= hi;) { n       int mid = lo + hi >> 1; n       if (pref[mid] == val) n         ans_indx = mid, lo = mid + 1; n       else if (pref[mid] < val) n         lo = mid + 1; n       else n         hi = mid - 1; n     } n     if (ans_indx == -1) continue; n     ; n     long long R = ans_indx; n     ans += R - L + 1; n   } n   cout << ans; n   cout <<   n ; n } n int main() { n   int t = 1; n   for (int i = 0; i < t; i++) solve(i); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int x = 0, flag = 1; n   char ch = getchar(); n   for (; ch >  9  || ch <  0 ; ch = getchar()) n     if (ch ==  - ) flag = -1; n   for (; ch >=  0  && ch <=  9 ; ch = getchar()) n     x = (x << 3) + (x << 1) + ch -  0 ; n   return x * flag; n } n const int MAXN = 2e5 + 50, B = 317, INF = 998244353; n int n, m, Ans[MAXN], rt, cnt = 0; n int XX[MAXN], YY[MAXN], DY[MAXN], Cl = 0; n struct Point { n   int x, y, id; n } P[MAXN]; n struct Ques { n   int X1, Y1, X2, Y2, id, h; n } Q[MAXN]; n struct Tree { n   int X, Y, Min, ls, rs, dat, fa; n   int mx[2], my[2]; n   void clean() { n     X = Y = ls = rs = mx[1] = my[1] = 0; n     mx[0] = my[0] = dat = Min = INF; n   } n } T[MAXN]; n int MIN(int a, int b) { return a < b ? a : b; } n bool cmp3(Point a, Point b) { return a.y < b.y; } n bool cmp2(Point a, Point b) { return a.x < b.x; } n bool cmp(Ques a, Ques b) { return a.h < b.h; } n void update(int cur) { n   T[cur].Min = MIN(T[T[cur].rs].Min, T[T[cur].ls].Min); n   T[cur].Min = MIN(T[cur].Min, T[cur].dat); n   T[cur].mx[0] = MIN(MIN(T[T[cur].rs].mx[0], T[T[cur].ls].mx[0]), T[cur].mx[0]); n   T[cur].my[0] = MIN(MIN(T[T[cur].rs].my[0], T[T[cur].ls].my[0]), T[cur].my[0]); n   T[cur].mx[1] = max(max(T[T[cur].rs].mx[1], T[T[cur].ls].mx[1]), T[cur].mx[1]); n   T[cur].my[1] = max(max(T[T[cur].rs].my[1], T[T[cur].ls].my[1]), T[cur].my[1]); n } n void build(int &cur, int L, int R, int D, int fa) { n   if (L > R) return; n   if (!cur) cur = ++cnt; n   int mid = (L + R) >> 1; n   T[cur].fa = fa; n   if (L == R) { n     int x = P[L].x, y = P[L].y; n     T[cur].mx[0] = T[cur].mx[1] = T[cur].X = x; n     T[cur].my[0] = T[cur].my[1] = T[cur].Y = y; n     T[cur].dat = T[cur].Min = P[L].id; n     DY[P[L].id] = cur; n     return; n   } n   if (D == 0) n     nth_element(P + L, P + mid, P + 1 + R, cmp2); n   else n     nth_element(P + L, P + mid, P + 1 + R, cmp3); n   T[cur].dat = P[mid].id, T[cur].X = P[mid].x, T[cur].Y = P[mid].y; n   T[cur].mx[0] = T[cur].mx[1] = T[cur].X; n   T[cur].my[0] = T[cur].my[1] = T[cur].Y; n   DY[P[mid].id] = cur; n   build(T[cur].ls, L, mid - 1, D ^ 1, cur); n   build(T[cur].rs, mid + 1, R, D ^ 1, cur); n   update(cur); n   return; n } n bool out(int x, int X1, int Y1, int X2, int Y2) { n   return (T[x].mx[0] > X2 || T[x].mx[1] < X1 || T[x].my[0] > Y2 || n           T[x].my[1] < Y1); n } n bool in(int x, int X1, int Y1, int X2, int Y2) { n   return (T[x].mx[0] >= X1 && T[x].mx[1] <= X2 && T[x].my[0] >= Y1 && n           T[x].my[1] <= Y2); n } n int query(int now, int X1, int Y1, int X2, int Y2) { n   int Min = INF; n   if (T[now].X >= X1 && T[now].Y >= Y1 && T[now].X <= X2 && T[now].Y <= Y2) n     Min = T[now].dat; n   if (out(now, X1, Y1, X2, Y2) || !now) return Min; n   if (in(now, X1, Y1, X2, Y2)) return min(T[now].Min, T[now].dat); n   if (T[now].ls) Min = MIN(Min, query(T[now].ls, X1, Y1, X2, Y2)); n   if (T[now].rs) Min = MIN(Min, query(T[now].rs, X1, Y1, X2, Y2)); n   return Min; n } n void Go(int x, int t) { n   if (!x) return; n   if (T[x].dat == t) T[x].dat = INF; n   update(x); n   Go(T[x].fa, t); n   return; n } n void clean() { n   for (int i = 1; i <= cnt; i++) T[i].clean(); n   cnt = 0; n } n int main() { n   n = read(); n   T[0].clean(); n   for (int i = 1; i <= n; i++) Ans[i] = -1; n   for (int i = 1; i <= n; i++) { n     Q[i].X1 = read(), Q[i].X2 = read(); n     Q[i].Y1 = read(), Q[i].Y2 = read(); n     Q[i].h = read(), Q[i].id = i; n   } n   rt = 0; n   m = read(); n   sort(Q + 1, Q + 1 + n, cmp); n   for (int i = 1; i <= m; i++) { n     XX[i] = P[i].x = read(), YY[i] = P[i].y = read(); n     P[i].id = i; n   } n   build(rt, 1, m, 0, 0); n   for (int i = 1; i <= n; i++) { n     int t = query(rt, Q[i].X1, Q[i].Y1, Q[i].X2, Q[i].Y2); n     if (t == 998244353 || !t) continue; n     Ans[t] = Q[i].id, Go(DY[t], t); n   } n   for (int i = 1; i <= m; i++) printf( %d n , max(Ans[i], 0)); n   return 0; n } n


#include <bits/stdc++.h> n const int MAXN = 100010; n int head[MAXN], nxt[MAXN << 1], to[MAXN << 1], val[MAXN << 1], tot; n void addedge(int b, int e, int v) { n   nxt[++tot] = head[b]; n   to[head[b] = tot] = e; n   val[tot] = v; n   nxt[++tot] = head[e]; n   to[head[e] = tot] = b; n   val[tot] = v; n } n int n, Q; n std::pair<int, int> diameter(int u, int fa = 0) { n   std::pair<int, int> res(0, u); n   for (int i = head[u]; i; i = nxt[i]) n     if (to[i] != fa) { n       std::pair<int, int> t = diameter(to[i], u); n       t.first += val[i]; n       res = std::max(res, t); n     } n   return res; n } n struct TTT { n   int fa[MAXN], son[MAXN], top[MAXN], dep[MAXN], sonmax[MAXN]; n   int dis[MAXN]; n   void dfs1(int u) { n     for (int i = head[u]; i; i = nxt[i]) n       if (to[i] != fa[u]) { n         fa[to[i]] = u; n         dep[to[i]] = dep[u] + 1; n         dis[to[i]] = dis[u] + val[i]; n         dfs1(to[i]); n         sonmax[to[i]] += val[i]; n         if (sonmax[to[i]] > sonmax[son[u]]) son[u] = to[i]; n       } n     sonmax[u] = sonmax[son[u]]; n   } n   int down[MAXN]; n   void dfs2(int u) { n     down[top[u]] = u; n     if (son[u]) top[son[u]] = top[u], dfs2(son[u]); n     for (int i = head[u]; i; i = nxt[i]) n       if (to[i] != fa[u] && to[i] != son[u]) top[to[i]] = to[i], dfs2(to[i]); n   } n   int chv[MAXN], li[MAXN], rk[MAXN], bak, pre[MAXN]; n   void init(int rt) { n     dep[rt] = 1, top[rt] = rt; n     dfs1(rt); n     dfs2(rt); n     for (int i = 1; i <= n; ++i) n       if (i == top[i]) li[++bak] = i, chv[i] = dis[down[i]] - dis[fa[i]]; n     std::sort(li + 1, li + 1 + bak, n               [this](int a, int b) { return chv[a] > chv[b]; }); n     for (int i = 1; i <= bak; ++i) n       rk[li[i]] = i, pre[i] = pre[i - 1] + chv[li[i]]; n   } n   int solve(int u, int v) { n     int lans = 0; n     v = std::min(bak, v * 2 - 1); n     if (rk[top[u]] <= v) n       lans = pre[v]; n     else { n       lans = pre[v - 1] + chv[top[u]]; n       int now = u; n       while (rk[top[now]] > v) now = fa[top[now]]; n       int tv = pre[v] - dis[down[top[now]]] + dis[down[top[u]]]; n       tv = std::max(tv, pre[v - 1] - dis[now] + dis[down[top[u]]]); n       lans = std::max(lans, tv); n     } n     return lans; n   } n } t1, t2; n int main() { n   std::ios_base::sync_with_stdio(false), std::cin.tie(0); n   std::cin >> n >> Q; n   for (int i = 1, t1, t2, t3; i < n; ++i) { n     std::cin >> t1 >> t2 >> t3; n     addedge(t1, t2, t3); n   } n   int rt1 = diameter(1).second, rt2 = diameter(rt1).second; n   t1.init(rt1), t2.init(rt2); n   int lans = 0; n   while (Q-- > 0) { n     int u, v; n     std::cin >> u >> v; n     u = (u + lans - 1) % n + 1; n     v = (v + lans - 1) % n + 1; n     lans = std::max(t1.solve(u, v), t2.solve(u, v)); n     std::cout << lans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(2) n using namespace std; n void read(int &x) { n   x = 0; n   int f = 1; n   char ch = getchar(); n   for (; !isdigit(ch); ch = getchar()) n     if (ch ==  - ) f = -f; n   for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ; n   x *= f; n } n void print(int x) { n   if (x < 0) putchar( - ), x = -x; n   if (!x) return; n   print(x / 10), putchar(x % 10 + 48); n } n void write(int x) { n   if (!x) n     putchar( 0 ); n   else n     print(x); n   putchar(  n ); n } n const int maxn = 1e6 + 10; n const int inf = 1e9; n const double eps = 1e-8; n const int mod = 1e9 + 7; n const int B = 400; n int a[maxn], b[maxn], n, k, q; n int c[maxn], s[maxn], ans, res; n namespace pps { n void modify(int p, int x) { n   c[p] = x; n   for (int i = p; i <= n; i += k) { n     ans -= !(!s[i]); n     if (i + k > n) res -= !s[i]; n     s[i] = c[i] ^ (i >= k ? s[i - k] : 0); n     if (i + k > n) res += !s[i]; n     ans += !(!s[i]); n   } n } n void solve() { n   ans = n - ans; n   while (q--) { n     char op; n     int p, v; n     scanf( %c , &op), read(p), read(v); n     if (op ==  a ) n       a[p] = v; n     else n       b[p] = v; n     modify(p, (a[p] ^ b[p]) ^ (a[p - 1] ^ b[p - 1])); n     p++; n     modify(p, (a[p] ^ b[p]) ^ (a[p - 1] ^ b[p - 1])); n     write(res == k ? ans : -1); n   } n } n }  // namespace pps n namespace modpps { n struct block { n   vector<int> r, bel, val, w; n   vector<vector<int> > t; n   int tag[600], m; n   void init(int x) { n     if (!x) x = k; n     m = 0; n     for (int i = x; i <= n; i += k) m++; n     r.resize(m + 2), bel.resize(m + 2); n     val.resize(m + 2), w.resize(m + 2); n     for (int i = 1; i <= m; i++) bel[i] = (i - 1) / B + 1; n     for (int i = m; i; i--) r[i] = bel[i] == bel[i + 1] ? r[i + 1] : i; n     for (int i = 1; i <= m; i++) { n       w[i] = s[(i - 1) * k + x]; n       val[i] = c[(i - 1) * k + x]; n     } n     vector<int> et(1 << 14, 0); n     for (int i = 0; i <= bel[m]; i++) t.push_back(et); n     for (int i = 1; i <= m; i++) t[bel[i]][w[i]]++; n   } n   void modify(int x, int v) { n     x = x / k + (x % k != 0); n     int _ = v ^ val[x]; n     val[x] = v; n     v = _; n     res -= tag[bel[m]] == w[m]; n     for (int i = x; i <= r[x]; i++) { n       t[bel[i]][w[i]]--; n       if (w[i] == tag[bel[i]]) ans--; n       w[i] ^= v; n       t[bel[i]][w[i]]++; n       if (w[i] == tag[bel[i]]) ans++; n     } n     for (int i = bel[x] + 1; i <= bel[m]; i++) { n       ans -= t[i][tag[i]]; n       tag[i] ^= v; n       ans += t[i][tag[i]]; n     } n     res += tag[bel[m]] == w[m]; n   } n } s[402]; n void solve() { n   for (int i = 0; i < k; i++) s[i].init(i); n   cerr <<  OK  << endl; n   while (q--) { n     char op; n     int p, v; n     scanf( %c , &op), read(p), read(v); n     if (op ==  a ) n       a[p] = v; n     else n       b[p] = v; n     s[p % k].modify(p, (a[p] ^ b[p]) ^ (a[p - 1] ^ b[p - 1])); n     p++; n     s[p % k].modify(p, (a[p] ^ b[p]) ^ (a[p - 1] ^ b[p - 1])); n     write(res == k ? n - ans : -1); n     if (q % 10000 == 0) cerr << q << endl; n   } n } n }  // namespace modpps n int main() { n   int st = clock(); n   read(n), read(k), read(q); n   for (int i = 1; i <= n; i++) read(a[i]); n   for (int i = 1; i <= n; i++) read(b[i]); n   n++; n   for (int i = 1; i <= n; i++) c[i] = (a[i] ^ b[i]) ^ (a[i - 1] ^ b[i - 1]); n   for (int i = 1; i <= n; i++) n     s[i] = c[i] ^ (i >= k ? s[i - k] : 0), ans += !s[i]; n   for (int i = n - k + 1; i <= n; i++) res += !s[i]; n   write(res == k ? n - ans : -1); n   if (k > B) n     pps ::solve(); n   else n     modpps ::solve(); n   cerr << (double)(clock() - st) / 1e3 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline char gc() { n   static char buf[100000], *p1 = buf, *p2 = buf; n   return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) n              ? EOF n              : *p1++; n } n inline long long read() { n   long long x = 0; n   char ch = getchar(); n   bool positive = 1; n   for (; !isdigit(ch); ch = getchar()) n     if (ch ==  - ) positive = 0; n   for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ; n   return positive ? x : -x; n } n inline void write(long long a) { n   if (a < 0) { n     a = -a; n     putchar( - ); n   } n   if (a >= 10) write(a / 10); n   putchar( 0  + a % 10); n } n inline void writeln(long long a) { n   write(a); n   puts(  ); n } n inline void wri(long long a) { n   write(a); n   putchar(   ); n } n long long t, n, nl[100010], ml[100010], nll[100010], mll[100010]; n int main() { n   n = read(); n   for (int i = 1; i <= n; i++) { n     nl[i] = read(); n   } n   for (int i = 1; i <= n; i++) { n     ml[i] = read(); n   } n   for (int i = 1; i < n; i++) { n     nll[i] = nl[i + 1] - nl[i]; n     mll[i] = ml[i + 1] - ml[i]; n   } n   sort(nll + 1, nll + n); n   sort(mll + 1, mll + n); n   int pd = 0; n   for (int i = 1; i < n; i++) { n     if (nll[i] != mll[i]) pd = 1; n   } n   if (pd == 0 && nl[1] == ml[1] && nl[n] == ml[n]) { n     puts( Yes ); n   } else { n     puts( No ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 3e5 + 5; n const int mod = 1e9 + 7; n int n; n int num[MAXN]; n bool vis[MAXN]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %d , &num[i]); n   int e = n; n   printf( 1 ); n   int sum = 0; n   for (int i = 1; i <= n; ++i) { n     vis[num[i]] = 1; n     while (vis[e] && e >= 1) { n       sum++; n       e--; n     } n     printf(  %d , i - sum + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma comment(linker,  /STACK:102400000,102400000 ) n int Map[50002][7]; n int main() { n   int m, n; n   scanf( %d%d , &m, &n); n   for (int i = 1; i <= m; i++) n     for (int j = 1; j <= n; j++) scanf( %d , &Map[i][j]); n   for (int i = 1; i <= m; i++) Map[i][1] += Map[i - 1][1]; n   for (int j = 1; j <= n; j++) Map[1][j] += Map[1][j - 1]; n   for (int i = 2; i <= m; i++) n     for (int j = 2; j <= n; j++) Map[i][j] += max(Map[i - 1][j], Map[i][j - 1]); n   for (int i = 1; i <= m; i++) { n     if (i > 1) putchar(   ); n     printf( %d , Map[i][n]); n   } n   puts(  ); n } n


#include <bits/stdc++.h> n using namespace std; n bool cmpDouble(const double& a, const double& b) { n   return std::fabs(a - b) < std::numeric_limits<double>::epsilon(); n } n int main() { n   int n, k; n   cin >> n >> k; n   int arr[5001]; n   int ans[5001]; n   for (int i = 0; i < n; ++i) { n     cin >> arr[i]; n     ans[i] = 0; n   } n   map<int, set<int>> seen; n   for (int i = 0; i < k; ++i) { n     ans[i] = i + 1; n     seen[arr[i]].insert(i + 1); n   } n   for (int i = k; i < n; ++i) { n     if (seen[arr[i]].size() >= k) { n       cout <<  NO  << endl; n       return 0; n     } n     for (int j = 1; j <= k; ++j) { n       if (seen[arr[i]].find(j) == seen[arr[i]].end()) { n         ans[i] = j; n         seen[arr[i]].insert(j); n         break; n       } n     } n   } n   cout <<  YES  << endl; n   for (int i = 0; i < n; ++i) { n     cout << ans[i] <<    ; n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n struct data { n   int info; n   int l, r; n   data() { n     info = 0; n     l = 0; n     r = 0; n   } n }; n data tr[100000 * 40]; n int avail = 0; n int update(int no, int s, int e, int in, int val) { n   int idx = no; n   if (!no) { n     idx = ++avail; n     tr[idx] = data(); n   } n   if (s == e) { n     tr[idx].info += val; n     return idx; n   } n   int mid = (s + e) / 2; n   if (mid >= in) { n     tr[idx].l = update(tr[idx].l, s, mid, in, val); n   } else { n     tr[idx].r = update(tr[idx].r, mid + 1, e, in, val); n   } n   tr[idx].info = (tr[tr[idx].l].info + tr[tr[idx].r].info); n   return idx; n } n int query(int idx, int s, int e, int st, int en) { n   if (idx == 0) return 0; n   if (s >= st && e <= en) return tr[idx].info; n   int mid = (s + e) / 2; n   if (mid >= en) n     return query(tr[idx].l, s, mid, st, en); n   else if (mid < st) n     return query(tr[idx].r, mid + 1, e, st, en); n   else n     return query(tr[idx].l, s, mid, st, mid) + n            query(tr[idx].r, mid + 1, e, mid + 1, en); n } n int main() { n   int n; n   cin >> n; n   map<int, int> mp; n   while (n--) { n     int x, y, z; n     cin >> x >> y >> z; n     if (x == 1) { n       mp[z] = update(mp[z], 1, 1e9 + 7, y, 1); n     } else if (x == 2) { n       mp[z] = update(mp[z], 1, 1e9 + 7, y, -1); n     } else { n       printf( %d n , query(mp[z], 1, 1e9 + 7, 1, y)); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   vector<int> a; n   map<int, int> mp; n   for (int i = 0; i < n; i++) { n     int val; n     cin >> val; n     if (mp.find(val) == mp.end()) { n       mp[val]++; n       a.push_back(val); n     } n   } n   sort(a.begin(), a.end()); n   int i = 0, sum = 0; n   int g = a.size(); n   while (i < min(g, k)) { n     int x = a[i] - sum; n     cout << x << endl; n     sum += x; n     i++; n   } n   while (i < k) { n     cout <<  0  << endl; n     i++; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int xpow(long long int a, long long int b) { n   if (b == 0) return 1; n   if (b % 2 == 0) { n     long long int k = xpow(a, b / 2); n     return k * k; n   } n   if (b % 2 != 0) return a * xpow(a, b - 1); n } n int main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); n   int n, sx, sy; n   cin >> n >> sx >> sy; n   int l = 0, r = 0, d = 0, u = 0; n   for (int i = 0; i < n; i++) { n     int x, y; n     cin >> x >> y; n     if (x > sx) r++; n     if (x < sx) l++; n     if (y > sy) u++; n     if (y < sy) d++; n   } n   int maxi = max({l, r, d, u}); n   cout << maxi << endl; n   if (l == maxi) n     sx--; n   else if (r == maxi) n     sx++; n   else if (u == maxi) n     sy++; n   else if (d == maxi) n     sy--; n   cout << sx <<     << sy << endl; n   return 0; 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   cout.tie(0); n   ; n   double a; n   int ans = 0; n   vector<int> v; n   int n, m; n   cin >> n; n   int ara1[n]; n   for (int i = 0; i < n; i++) cin >> ara1[i]; n   cin >> m; n   int ara2[m]; n   for (int i = 0; i < m; i++) cin >> ara2[i]; n   for (int i = 0; i < m; i++) { n     for (int j = 0; j < n; j++) { n       a = (double)ara2[i] / ara1[j]; n       if (a == (int)a) { n         int b = a; n         v.push_back(b); n       } n     } n   } n   sort(v.rbegin(), v.rend()); n   for (int i = 0; i < m; i++) { n     for (int j = 0; j < n; j++) { n       a = (double)ara2[i] / ara1[j]; n       if (a == v[0]) ans++; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int t; n   scanf( %d , &t); n   while (t--) { n     long long int n, i, j, k, f = 0; n     scanf( %lld , &n); n     long long int a[n]; n     for (i = 0; i < n; i++) scanf( %lld , &a[i]); n     for (i = 2; i < n; i++) { n       if (a[i] >= a[0] + a[1]) { n         f = 1; n         break; n       } n     } n     if (f == 1) n       printf( 1 2 %lld n , i + 1); n     else n       printf( -1 n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 5; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n, k; n   cin >> n >> k; n   int v = 0; n   int ans = 0, ans1 = 0; n   for (int i = 0; i < n; i++) { n     int a; n     cin >> a; n     if (i < k - 1 && a != 0) ans1++; n     if (i == k - 1) ans = a; n     if (i >= k - 1 && a == ans && ans > 0) v++; n   } n   cout << v + ans1 <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void pv(vector<T> &vec) { n   for (int i = 0; i < (int)(vec).size(); i++) n     cout << vec[i] << (i == (int)(vec).size() - 1 ?   n  :    ); n } n bool ok(int x) { return (x % 10 == 7); } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int a, b, x, ans = 0; n   cin >> x >> a >> b; n   while (1) { n     if (ok(a) || ok(b)) break; n     if (b >= x) n       b -= x; n     else { n       b = 60 - abs(b - x); n       a = (a ? a - 1 : 23); n     } n     ans++; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int sN = 1 << 19; n long long v[sN], d[sN], l[sN], r[sN], s[sN], w[sN]; n int n, m; n int t, Left, Right; n long long x; n void down(int a, int c1, int c2) { n   d[c1] += d[a]; n   d[c2] += d[a]; n   s[c1] += d[a] * w[c1]; n   s[c2] += d[a] * w[c2]; n   d[a] = 0; n   if (v[a] > 0) v[c1] = v[c2] = v[a]; n } n long long get(int a) { n   if (Right < l[a] or r[a] < Left) return 0ll; n   if (Left <= l[a] and r[a] <= Right) return s[a]; n   int c1 = a << 1, c2 = c1 + 1; n   down(a, c1, c2); n   return get(c1) + get(c2); n } n void update(int a) { n   if (Right < l[a] or r[a] < Left) return; n   if (Left <= l[a] and r[a] <= Right and v[a] > 0) { n     long long inc = x - v[a]; n     if (inc < 0) inc = -inc; n     d[a] += inc; n     s[a] += inc * w[a]; n     v[a] = x; n     return; n   } n   int c1 = a << 1, c2 = c1 + 1; n   down(a, c1, c2); n   update(c1); n   update(c2); n   s[a] = s[c1] + s[c2]; n   if (v[c1] == v[c2]) n     v[a] = v[c1]; n   else n     v[a] = 0; n } n int main() { n   scanf( %d %d , &n, &m); n   int nn = 1; n   for (; nn < n; nn <<= 1) n     ; n   n = nn--; n   for (int i = 1; i <= n; i++) n     v[nn + i] = l[nn + i] = r[nn + i] = i, w[nn + i] = 1; n   for (int i = nn, j = i << 1; i > 0; i--, j = i << 1) n     l[i] = l[j], r[i] = r[j + 1], w[i] = w[j] << 1; n   for (; m--;) { n     scanf( %d , &t); n     if (t == 1) { n       scanf( %d %d , &Left, &Right); n       scanf( %I64d , &x); n       update(1); n     } else { n       scanf( %d %d , &Left, &Right); n       printf( %I64d n , get(1)); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 10; n const int inf = 0x3f3f3f3f; n const int mod = 998244353; n int a[N], n, L; n bool check(double x, int id) { n   double s1 = 0, s2 = 0; n   double t = x; n   int s = 1; n   for (int i = 1; i <= n + 1; i++) { n     double cur = 1.0 * (a[i] - a[i - 1]) / s; n     if (cur <= t) { n       s1 = a[i]; n       t -= cur; n     } else { n       s1 += t * s; n       break; n     } n     s++; n   } n   s = 1; n   t = x; n   for (int i = n; i >= 0; i--) { n     double cur = 1.0 * (a[i + 1] - a[i]) / s; n     if (cur <= t) { n       s2 = L - a[i]; n       t -= cur; n     } else { n       s2 += t * s; n       break; n     } n     s++; n   } n   return s1 + s2 >= 1.0 * L; n } n void solve() { n   scanf( %d%d , &n, &L); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n   } n   a[n + 1] = L; n   double l = 0, r = L; n   double res = 1e9; n   for (int i = 1; i <= 100; i++) { n     double mid = 1.0 * (l + r) / 2; n     if (check(mid, i)) { n       res = mid; n       r = mid; n     } else n       l = mid; n   } n   printf( %.6f n , res); n } n int main() { n   int t; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, i, j, v[1005]; n char s[1005]; n int main() { n   scanf( %d n , &n); n   scanf( %s , s + 1); n   s[0] =  L ; n   s[n] =  R ; n   for (i = 1; i <= n; ++i) { n     j = i - 1; n     while (s[j] !=  L ) { n       if (s[j] ==  R ) ++v[i]; n       --j; n     } n     int aux = 0; n     j = i; n     while (s[j] !=  R ) { n       if (s[j] ==  L ) ++aux; n       ++j; n     } n     v[i] = max(v[i], aux); n     ++v[i]; n   } n   for (i = 1; i <= n; ++i) printf( %d  , v[i]); n } n


#include <bits/stdc++.h> n using namespace std; n long long int max(long long int a, long long int b) { n   if (a < b) swap(a, b); n   return a; n } n long long int min(long long int a, long long int b) { n   if (a >= b) swap(a, b); n   return a; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   string st, c; n   long long int len, k, y[29] = {0}, i; n   cin >> len >> k; n   cin >> st; n   c = st; n   sort(c.begin(), c.end()); n   for (i = 0; i < k; i++) { n     y[c[i] - 96] += 1; n   } n   for (i = 0; i < len; i++) { n     if (y[st[i] - 96]) n       y[st[i] - 96] -= 1; n     else n       cout << st[i]; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( -O3 ) n using namespace std; n void solve() { n   long long int n, k; n   cin >> n >> k; n   vector<long long int> a(n); n   for (long long int i = 0; i < n; i++) cin >> a[i]; n   sort(a.begin(), a.end()); n   long long int ones = 0; n   vector<long long int> b; n   for (long long int i = 0; i < k; i++) { n     long long int temp; n     cin >> temp; n     if (temp == 1) n       ones++; n     else n       b.push_back(temp); n   } n   sort(b.begin(), b.end(), greater<long long int>()); n   k = b.size(); n   long long int ans = accumulate(a.end() - 1 - ones + 1, a.end(), 0ll) * 2; n   long long int end = n - 1 - ones, beg = 0; n   for (long long int i = 0; i < k; i++) { n     long long int cur = b[i]; n     ans += (a[end]); n     cur--; n     end--; n     if (cur == 0) n       ans += (a[end + 1]); n     else { n       ans += a[beg]; n       beg += cur; n     } n   } n   cout << ans; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int __t; n   cin >> __t; n   while (__t--) { n     solve(); n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n ostream& operator<<(ostream& os, vector<T> V) { n   os <<  [  ; n   for (auto v : V) os << v <<    ; n   os <<  ] ; n   return os; n } n template <class T> n ostream& operator<<(ostream& os, set<T> second) { n   os <<  {  ; n   for (auto s : second) os << s <<    ; n   return os <<  } ; n } n template <class T> n ostream& operator<<(ostream& os, multiset<T> second) { n   os <<  {  ; n   for (auto s : second) os << s <<    ; n   return os <<  } ; n } n template <class L, class R> n ostream& operator<<(ostream& os, pair<L, R> P) { n   return os <<  (  << P.first <<  ,  << P.second <<  ) ; n } n template <class L, class R> n ostream& operator<<(ostream& os, map<L, R> M) { n   os <<  {  ; n   for (auto m : M) os <<  (  << m.first <<  :  << m.second <<  )  ; n   return os <<  } ; n } n template <class L, class R> n ostream& operator<<(ostream& os, unordered_map<L, R> M) { n   os <<  {  ; n   for (auto m : M) os <<  (  << m.first <<  :  << m.second <<  )  ; n   return os <<  } ; n } n const long long N = 2010, M = 1e9 + 7; n long long n, a[N][N], dp1[N][N], dp2[N][N], dp3[N][N]; n void solve() { n   cin >> n; n   for (long long i = (0); i <= n - 1; i++) n     for (long long j = (0); j <= n - 1; j++) cin >> a[i][j]; n   for (long long i = (0); i <= n - 1; i++) n     dp1[i][0] = a[i][0], dp1[0][i] = a[0][i], dp2[i][n - 1] = a[i][n - 1], n     dp2[0][n - i - 1] = a[0][n - i - 1]; n   for (long long i = (1); i <= n - 1; i++) n     for (long long j = (1); j <= n - 1; j++) n       dp1[i][j] = a[i][j] + dp1[i - 1][j - 1]; n   for (long long i = (1); i <= n - 1; i++) n     for (long long j = (0); j <= n - 2; j++) n       dp2[i][j] = a[i][j] + dp2[i - 1][j + 1]; n   for (long long i = (0); i <= n - 1; i++) n     for (long long j = (0); j <= n - 1; j++) { n       long long i1 = i + min(n - i - 1, n - j - 1); n       long long j1 = j + min(n - i - 1, n - j - 1); n       long long i2 = i + min(n - i - 1, j); n       long long j2 = j - min(n - i - 1, j); n       dp3[i][j] = dp1[i1][j1] + dp2[i2][j2] - a[i][j]; n     } n   long long ans1 = LLONG_MIN, ans2 = LLONG_MIN, posx1, posy1, posx2, posy2; n   for (long long i = (0); i <= n - 1; i++) n     for (long long j = (0); j <= n - 1; j++) { n       if ((i + j) % 2 == 0 && dp3[i][j] > ans1) { n         ans1 = max(ans1, dp3[i][j]); n         posx1 = i + 1; n         posy1 = j + 1; n       } else if ((i + j) % 2 == 1 && dp3[i][j] > ans2) { n         ans2 = max(ans2, dp3[i][j]); n         posx2 = i + 1; n         posy2 = j + 1; n       } n     } n   cout << ans1 + ans2 <<   n ; n   cout << posx1 <<     << posy1 <<     << posx2 <<     << posy2 <<   n ; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int a[2][2]; n   node() { a[0][0] = a[0][1] = a[1][0] = a[1][1] = 0; } n   int *operator[](const size_t &s) { return a[s]; } n }; n node segTree[400008], L[400008]; n node id, M, zero; n int a[100002]; n int lazy[400008]; n inline node operator+(node &a, node &b) { n   node res; n   for (int i = 0; i < 2; i++) n     for (int j = 0; j < 2; j++) res[i][j] = (a[i][j] + b[i][j]) % 1000000007; n   return res; n } n inline node operator*(node &a, node &b) { n   node res; n   for (int i = 0; i < 2; i++) n     for (int j = 0; j < 2; j++) n       for (int k = 0; k < 2; k++) n         res[i][j] = n             (res[i][j] + (1ll * a[i][k] * b[k][j]) % 1000000007) % 1000000007; n   return res; n } n inline node matPower(int n) { n   node res = id; n   node m = M; n   while (n > 0) { n     if (n & 1) res = res * m; n     m = m * m; n     n >>= 1; n   } n   return res; n } n inline void buildTree(int v, int s, int e) { n   L[v] = id; n   lazy[v] = 0; n   if (s == e) { n     segTree[v] = matPower(a[s]); n     return; n   } n   int m = (s + e) / 2; n   buildTree(2 * v, s, m); n   buildTree(2 * v + 1, m + 1, e); n   segTree[v] = segTree[2 * v] + segTree[2 * v + 1]; n } n inline void propogate(int v, int l, int r) { n   if (lazy[v] > 0) { n     segTree[v] = segTree[v] * L[v]; n     if (l != r) { n       lazy[2 * v] = lazy[2 * v + 1] = 1; n       L[2 * v] = L[2 * v] * L[v]; n       L[2 * v + 1] = L[2 * v + 1] * L[v]; n     } n     lazy[v] = 0; n     L[v] = id; n   } n   return; n } n inline void update(int v, int tl, int tr, int l, int r, node x) { n   propogate(v, tl, tr); n   if (l > r) return; n   if (tl == l && tr == r) { n     lazy[v] = 1; n     L[v] = x; n     propogate(v, tl, tr); n     return; n   } n   int tm = (tl + tr) / 2; n   update(2 * v, tl, tm, l, min(tm, r), x); n   update(2 * v + 1, tm + 1, tr, max(l, tm + 1), r, x); n   segTree[v] = segTree[2 * v] + segTree[2 * v + 1]; n } n inline node query(int v, int tl, int tr, int l, int r) { n   propogate(v, tl, tr); n   if (l > r) return zero; n   if (tl == l && tr == r) return segTree[v]; n   int tm = (tl + tr) / 2; n   node left = query(2 * v, tl, tm, l, min(tm, r)); n   node right = query(2 * v + 1, tm + 1, tr, max(l, tm + 1), r); n   return (left + right); n } n int main() { n   id[0][0] = id[1][1] = 1; n   M[0][0] = M[0][1] = M[1][0] = 1; n   ios::sync_with_stdio(false); n   int n, m, q, l, r, x; n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> a[i]; n   buildTree(1, 0, n - 1); n   while (m--) { n     cin >> q; n     if (q == 1) { n       cin >> l >> r >> x; n       node val = matPower(x); n       update(1, 0, n - 1, l - 1, r - 1, val); n     } else { n       cin >> l >> r; n       cout << query(1, 0, n - 1, l - 1, r - 1)[0][1] << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   cin >> n; n   long long s = 1; n   for (long long i = 1; i <= n; i++) { n     s += (i - 1) * 4; n   } n   cout << s; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 100; n int a[N]; n int main() { n   ios_base::sync_with_stdio(false); n   int n, U; n   cin >> n >> U; n   for (int i = 1; i <= n; ++i) cin >> a[i]; n   double ans = -1; n   for (int i = 1, j = 1; i + 1 <= n; ++i) { n     while (j + 1 <= n and a[j + 1] - a[i] <= U) ++j; n     if (j - i + 1 < 3) continue; n     ans = max(ans, (double)(a[j] - a[i + 1]) / (a[j] - a[i])); n   } n   cout << fixed << setprecision(9) << ans <<   n ; n } n


#include <bits/stdc++.h> n int main() { n   int q; n   std::cin >> q; n   while (q--) { n     int n, ans(0); n     std::cin >> n; n     std::set<std::string> check, p; n     std::string s; n     std::vector<std::string> res, a(n); n     for (int i = 0; i < n; i++) { n       std::cin >> a[i]; n       check.insert(a[i]); n     } n     for (int i = 0; i < n; i++) { n       if (p.find(a[i]) != p.end()) { n         std::string t = a[i]; n         for (int x = 0; x < 10; x++) { n           if (check.find(t) == check.end()) { n             check.insert(t); n             p.insert(t); n             break; n           } n           t[0] = char( 0  + x); n         } n         ++ans; n         res.push_back(t); n       } else { n         res.push_back(a[i]); n         p.insert(a[i]); n       } n     } n     std::cout << ans << std::endl; n     for (int i = 0; i < res.size(); i++) { n       std::cout << res[i] << std::endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef long long int ll; n typedef unsigned long long int ull; n inline void smax(int &x, int y) { x = max(x, y); } n inline void smin(int &x, int y) { x = min(x, y); } n ll gcd(ll a, ll b) { return ((b == 0) ? a : gcd(b, a % b)); } n ll n, m, a, b; n vector<vector<int> > gr; n vector<int> vis; n ll con = 0; n int dfs(int s, int prt) { n   vis[s] = 1; n   con++; n   int f = 0; n   if (prt == s) f = 1; n   for (__typeof(gr[s].size()) i = (0) - ((0) > (gr[s].size())); n        i != (gr[s].size()) - ((0) > (gr[s].size())); n        i += 1 - 2 * ((0) > (gr[s].size()))) { n     int x = gr[s][i]; n     if (!vis[x]) { n       if (dfs(x, prt) == 1) f = 1; n     } n   } n   return f; n } n int main() { n   std::ios::sync_with_stdio(false); n   cin.tie(NULL); n   int tcase; n   cin >> tcase; n   for (__typeof(tcase + 1) tc = (1) - ((1) > (tcase + 1)); n        tc != (tcase + 1) - ((1) > (tcase + 1)); n        tc += 1 - 2 * ((1) > (tcase + 1))) { n     cin >> n >> m >> a >> b; n     gr.resize(0); n     vis.resize(0); n     gr.resize(n + 1); n     vis.resize(n + 1); n     for (__typeof(m) i = (0) - ((0) > (m)); i != (m) - ((0) > (m)); n          i += 1 - 2 * ((0) > (m))) { n       int x, y; n       cin >> x >> y; n       gr[x].push_back(y); n       gr[y].push_back(x); n     } n     ll con1 = 0; n     vis[a] = 1; n     for (__typeof(gr[a].size()) i = (0) - ((0) > (gr[a].size())); n          i != (gr[a].size()) - ((0) > (gr[a].size())); n          i += 1 - 2 * ((0) > (gr[a].size()))) { n       if (vis[gr[a][i]]) continue; n       con = 0; n       int tch = dfs(gr[a][i], b); n       if (tch == 0) { n         con1 += con; n       } n     } n     vis.resize(0); n     vis.resize(n + 1); n     vis[b] = 1; n     ll con2 = 0; n     for (__typeof(gr[b].size()) i = (0) - ((0) > (gr[b].size())); n          i != (gr[b].size()) - ((0) > (gr[b].size())); n          i += 1 - 2 * ((0) > (gr[b].size()))) { n       con = 0; n       if (vis[gr[b][i]]) continue; n       int tch = dfs(gr[b][i], a); n       if (tch == 0) { n         con2 += con; n       } n     } n     cout << con2 * con1 <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> SEC; n int main() { n   long long n, x, y; n   cin >> n >> x >> y; n   long long tedX = 0, tedY = 0; n   while (tedX + tedY < x + y) { n     if ((tedX + 1) * y > (tedY + 1) * x) { n       SEC.push_back(2); n       tedY++; n     } else if ((tedX + 1) * y < (tedY + 1) * x) { n       SEC.push_back(1); n       tedX++; n     } else { n       SEC.push_back(-1); n       SEC.push_back(-1); n       tedX++; n       tedY++; n     } n   } n   for (int i = 0; i < n; i++) { n     long long tmp; n     cin >> tmp; n     long long ans = SEC[(tmp - 1) % (x + y)]; n     if (ans == 1) { n       cout <<  Vanya  << endl; n     } else if (ans == 2) { n       cout <<  Vova  << endl; n     } else n       cout <<  Both  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 400010; n struct Event { n   int x, type, ind; n   Event() {} n   Event(int x, int type, int ind) : x(x), type(type), ind(ind) {} n   bool operator<(const Event &other) const { n     return make_pair(x, type) < make_pair(other.x, other.type); n   } n }; n int n, k; n int l[N], r[N]; n Event a[N]; n bool del[N]; n set<pair<int, int> > q; n vector<int> res; n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= n; i++) { n     scanf( %d%d , &l[i], &r[i]); n     a[2 * i - 1] = Event(l[i], 0, i); n     a[2 * i] = Event(r[i], 1, i); n   } n   sort(a + 1, a + 2 * n + 1); n   int cov = 0; n   int ans = 0; n   for (int i = 1; i <= n; i++) del[i] = false; n   for (int i = 1; i <= 2 * n; i++) { n     int j = a[i].ind; n     if (a[i].type == 0) { n       q.insert(make_pair(-r[j], j)); n       cov++; n       if (cov > k) { n         cov--; n         ans++; n         int ind = (*q.begin()).second; n         del[ind] = true; n         res.push_back(ind); n         q.erase(q.begin()); n       } n     } else if (!del[j]) { n       cov--; n       q.erase(make_pair(-r[j], j)); n     } n   } n   printf( %d n , ans); n   for (int x : res) printf( %d  , x); n   return 0; n } n