#include <bits/stdc++.h> n using namespace std; n pair<int, long long> da; n inline long long p(long long x) { return x * x * x; } n long long m; n void dfs(long long now, int sum, long long maxnum) { n   if (!now) n     da = max(da, make_pair(sum, maxnum)); n   else { n     long long i = 1; n     for (; p(i + 1) <= now; ++i) n       ; n     dfs(now - p(i), sum + 1, maxnum + p(i)); n     if (now) dfs(p(i) - p(i - 1) - 1, sum + 1, maxnum + p(i - 1)); n   } n } n int main() { n   scanf( %lld , &m); n   dfs(m, 0, 0); n   printf( %d %lld , da.first, da.second); n } n


#include <bits/stdc++.h> n std::map<std::string, std::string> opcodes; n std::string next(std::string s) { n   std::string res = s; n   res[res.size() - 1]++; n   for (int i = (int)res.size() - 1; i >= 0; i--) { n     if (res[i] >  f ) { n       res[i] =  a ; n       res[i - 1]++; n     } n   } n   return res; n } n int check(std::string s) { n   if (s.size() == 1) return !!(s[0] ==  a ); n   std::string f = s.substr(0, 2); n   s.erase(0, 2); n   auto it = opcodes.find(f); n   if (it == opcodes.end()) return 0; n   s = it->second + s; n   return check(s); n } n int main() { n   std::ios_base::sync_with_stdio(0); n   int n, q; n   std::cin >> n >> q; n   std::string str =   , fff, a, b; n   for (int i = 0; i < n; i++) str.push_back( a ); n   for (int i = 0; i < n; i++) fff.push_back( f ); n   for (int i = 0; i < q; i++) { n     std::cin >> a >> b; n     opcodes[a] = b; n   } n   int ans = 0; n   while (true) { n     ans += check(str); n     if (str == fff) n       break; n     else n       str = next(str); n   } n   std::cout << ans << std::endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int MOD = 1e9 + 7; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int n; n   cin >> n; n   long long int a[n]; n   for (long long int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   if (n == 1) { n     cout << 1 <<   n ; n     return 0; n   } n   long long int pre[n + 5]; n   long long int suf[n + 5]; n   long long int ans = 1; n   pre[0] = 1; n   suf[n - 1] = 1; n   for (long long int i = 1; i < n; i++) { n     if (a[i] > a[i - 1]) { n       pre[i] = pre[i - 1]; n       pre[i]++; n     } else { n       pre[i] = 1; n     } n     ans = max(pre[i], ans); n   } n   for (long long int i = n - 2; i >= 0; i--) { n     if (a[i] < a[i + 1]) { n       suf[i] = suf[i + 1]; n       suf[i]++; n     } else { n       suf[i] = 1; n     } n     ans = max(pre[i], ans); n   } n   for (long long int i = 1; i + 1 < n; i++) { n     if (a[i + 1] - a[i - 1] >= 2) { n       ans = max(ans, 1 + pre[i - 1] + suf[i + 1]); n     } n     ans = max(ans, 1 + pre[i - 1]); n     ans = max(ans, 1 + suf[i + 1]); n   } n   ans = max(ans, 1 + suf[1]); n   ans = max(ans, 1 + pre[n - 2]); n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double EPS = 1e-8; n const int mod = 1e9 + 7; n const int N = 1e6 + 10; n const long long INF = 1e18; n long long power(long long x, long long y) { n   long long t = 1; n   while (y > 0) { n     if (y % 2) n       y -= 1, t = t * x % mod; n     else n       y /= 2, x = x * x % mod; n   } n   return t; n } n vector<int> G[N]; n vector<long long> snd[N]; n long long sub[N], sum[N], red[N], dol[N]; n long long mns[N], mxs[N]; n int lol[N]; n vector<pair<int, pair<long long, long long> > > edges; n void done() { n   printf( -1 n ); n   exit(0); n } n void dfs(int v) { n   for (int i = 0; i < G[v].size(); ++i) { n     int ed = G[v][i]; n     dfs(edges[ed].first); n     long long &w = edges[ed].second.first, &p = edges[ed].second.second; n     if (mns[edges[ed].first] > p) done(); n     long long z = min(w - 1, p - mns[edges[ed].first]); n     mns[v] += mns[edges[ed].first] + w - z; n     snd[v].push_back(mns[edges[ed].first] + w - z); n     mxs[v] += w + min(p, mxs[edges[ed].first]); n     assert(mns[v] <= mxs[v]); n   } n } n void dfs1(int v, long long nd) { n   for (int i = 0; i < G[v].size(); ++i) nd -= snd[v][i]; n   for (int i = 0; i < G[v].size(); ++i) { n     int ed = G[v][i], to = edges[ed].first; n     long long &w = edges[ed].second.first, &p = edges[ed].second.second; n     long long z = min(w - 1, p - mns[edges[ed].first]); n     w -= z; n     p -= z; n     long long k = min(nd, z); n     w += k; n     p += k; n     nd -= k; n     k = min(min(nd, p - mns[edges[ed].first]), n             mxs[edges[ed].first] - mns[edges[ed].first]); n     dfs1(to, mns[edges[ed].first] + k); n     nd -= k; n   } n   assert(nd == 0); n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n - 1; ++i) { n     int x, y; n     long long w, p; n     scanf( %d%d%lld%lld , &x, &y, &w, &p); n     x--; n     y--; n     G[x].push_back(edges.size()); n     lol[i] = x; n     edges.push_back(make_pair(y, make_pair(w, p))); n   } n   dfs(0); n   dfs1(0, mxs[0]); n   printf( %d n , n); n   for (int i = 0; i < n - 1; ++i) { n     printf( %d %d %lld %lld n , lol[i] + 1, edges[i].first + 1, n            edges[i].second.first, edges[i].second.second); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long M = 5005; n const int MOD = 998244353; n const int MX = 3e5 + 5; n const long long INF = 1e18; n const long double PI = acos((long double)-1); n void msm() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n } n int sol(); n int main() { n   msm(); n   sol(); n   return 0; n } n int sol() { n   long long n; n   cin >> n; n   ; n   long long ar[105], arr[105][5005]; n   for (long long i = (0); i < (n); ++i) { n     long long a; n     cin >> a; n     ; n     ar[a]++; n     arr[a][ar[a]] = i + 1; n   } n   long long y = min(ar[1], min(ar[2], ar[3])); n   cout << y << endl; n   for (long long i = (1); i <= (y); ++i) n     cout << arr[1][i] <<     << arr[2][i] <<     << arr[3][i] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T1, typename T2> n inline void chkmin(T1 &x, T2 y) { n   if (x > y) x = y; n } n template <typename T1, typename T2> n inline void chkmax(T1 &x, T2 y) { n   if (x < y) x = y; n } n template <typename T, typename U> n inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) { n   _out << _p.first <<     << _p.second; n   return _out; n } n template <typename T, typename U> n inline istream &operator>>(istream &_in, pair<T, U> &_p) { n   _in >> _p.first >> _p.second; n   return _in; n } n template <typename T> n inline ostream &operator<<(ostream &_out, const vector<T> &_v) { n   if (_v.empty()) { n     return _out; n   } n   _out << _v.front(); n   for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { n     _out <<     << *_it; n   } n   return _out; n } n template <typename T> n inline istream &operator>>(istream &_in, vector<T> &_v) { n   for (auto &_i : _v) { n     _in >> _i; n   } n   return _in; n } n template <typename T> n inline ostream &operator<<(ostream &_out, const set<T> &_s) { n   if (_s.empty()) { n     return _out; n   } n   _out << *_s.begin(); n   for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { n     _out <<     << *_it; n   } n   return _out; n } n template <typename T> n inline ostream &operator<<(ostream &_out, const multiset<T> &_s) { n   if (_s.empty()) { n     return _out; n   } n   _out << *_s.begin(); n   for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { n     _out <<     << *_it; n   } n   return _out; n } n template <typename T> n inline ostream &operator<<(ostream &_out, const unordered_set<T> &_s) { n   if (_s.empty()) { n     return _out; n   } n   _out << *_s.begin(); n   for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { n     _out <<     << *_it; n   } n   return _out; n } n template <typename T> n inline ostream &operator<<(ostream &_out, const unordered_multiset<T> &_s) { n   if (_s.empty()) { n     return _out; n   } n   _out << *_s.begin(); n   for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { n     _out <<     << *_it; n   } n   return _out; n } n template <typename T, typename U> n inline ostream &operator<<(ostream &_out, const map<T, U> &_m) { n   if (_m.empty()) { n     return _out; n   } n   _out <<  (  << _m.begin()->first <<  :   << _m.begin()->second <<  ) ; n   for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { n     _out <<  , (  << _it->first <<  :   << _it->second <<  ) ; n   } n   return _out; n } n template <typename T, typename U> n inline ostream &operator<<(ostream &_out, const unordered_map<T, U> &_m) { n   if (_m.empty()) { n     return _out; n   } n   _out <<  (  << _m.begin()->first <<  :   << _m.begin()->second <<  ) ; n   for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { n     _out <<  , (  << _it->first <<  :   << _it->second <<  ) ; n   } n   return _out; n } n const string FILENAME =  input ; n const int MAXN = 100001; n int n; n int x[MAXN], y[MAXN]; n int c[MAXN]; n int a[MAXN]; n int id[MAXN]; n int reals[MAXN]; n int xs[MAXN], ys[MAXN]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   int curx = 0, cury = 0; n   int last = 0; n   int st = 0; n   for (int i = 0; i < n; i++) { n     cin >> x[i] >> y[i]; n     id[i] = i; n     xs[i] = x[i]; n     ys[i] = y[i]; n   } n   while (true) { n     random_shuffle(id, id + n); n     for (int i = 0; i < n; i++) { n       x[i] = xs[i]; n       y[i] = ys[i]; n     } n     long long lst = 0; n     curx = 0; n     cury = 0; n     last = 0; n     st = 0; n     for (int i1 = 0; i1 < n; i1++) { n       int i = id[i1]; n       long long res = 1e18; n       for (int t = 0; t < 2; t++) { n         for (int t1 = 0; t1 < 2; t1++) { n           int nx = curx + x[i]; n           int ny = cury + y[i]; n           chkmin(res, 1LL * nx * nx + 1LL * ny * ny); n           x[i] *= -1; n           y[i] *= -1; n         } n         curx *= -1; n         cury *= -1; n       } n       bool was = false; n       for (int t = 0; t < 2; t++) { n         int nx = curx + x[i]; n         int ny = cury + y[i]; n         if ((1LL * nx * nx + 1LL * ny * ny) == res) { n           c[i1] = last ^ t; n           if (i == 0) { n             st = t; n           } n           was = true; n           curx = nx; n           cury = ny; n           last = t; n           break; n         } n         x[i] *= -1; n         y[i] *= -1; n       } n       if (!was) { n         st ^= 1; n         last ^= 1; n         curx *= -1; n         cury *= -1; n         for (int t = 0; t < 2; t++) { n           int nx = curx + x[i]; n           int ny = cury + y[i]; n           if ((1LL * nx * nx + 1LL * ny * ny) == res) { n             c[i1] = t ^ last; n             if (i == 0) { n               st = t; n             } n             was = true; n             curx = nx; n             cury = ny; n             last = t; n             break; n           } n           x[i] *= -1; n           y[i] *= -1; n         } n       } n       lst = res; n     } n     if (lst <= 1500000LL * 1500000LL) { n       break; n     } n   } n   for (int i = 0; i < n; i++) { n     if (i == 0) { n       a[i] = st; n     } else { n       if (c[i]) { n         a[i] = a[i - 1] ^ 1; n       } else { n         a[i] = a[i - 1]; n       } n     } n     reals[id[i]] = a[i]; n   } n   for (int i = 0; i < n; i++) { n     if (reals[i] == 0) { n       cout << 1 <<    ; n     } else { n       cout << -1 <<    ; n     } n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, d, l; n int main() { n   cin >> n >> d >> m >> l; n   long long x = 0; n   for (long long i = 0; i < n; i++) { n     if (x < i * m) { n       break; n     } n     while (x <= i * m + l) x = (((i * m + l) / d) + 1) * d; n   } n   cout << x << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 40; n const int M = 20; n long long incident_mask[N]; n vector<int> g[N]; n int n, m, used[N]; n long long ans = 0; n long long cntmask[1 << M]; n template <typename T> n inline void chkmax(T &x, T y) { n   x = max(x, y); n } n template <typename T> n inline void chkmin(T &x, T y) { n   x = min(x, y); n } n template <typename T> n inline void read(T &x) { n   T f = 1; n   x = 0; n   char c = getchar(); n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) f = -f; n   for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c -  0 ; n   x *= f; n } n inline long long binpow(long long a, long long n) { n   long long res = 1; n   for (; n; n >>= 1, a = (long long)a * a) n     if (n & 1) res = (long long)res * a; n   return res; n } n inline void dfs(int x, int c) { n   if (used[x]) return; n   used[x] = c; n   for (int y : g[x]) dfs(y, 3 - c); n } n inline long long CountIsolated() { n   long long ans = 0; n   for (int i = 0; i < n; ++i) n     if (g[i].empty()) ++ans; n   return ans; n } n inline long long CountComponents() { n   memset(used, 0, sizeof(used)); n   long long ans = 0; n   for (int i = 0; i < n; ++i) n     if (!used[i]) { n       ++ans; n       dfs(i, 1); n     } n   return ans; n } n inline bool bipartite() { n   memset(used, 0, sizeof(used)); n   for (int i = 0; i < n; ++i) n     if (!used[i]) dfs(i, 1); n   for (int i = 0; i < n; ++i) n     for (int j : g[i]) n       if (used[i] == used[j]) return false; n   return true; n } n inline long long CountIndependentSets() { n   int m1 = min(n, 20); n   int m2 = n - m1; n   memset(cntmask, 0, sizeof(cntmask)); n   for (int i = 0; i < (1 << m1); ++i) { n     long long curmask = 0; n     bool good = true; n     for (int j = 0; j < m1; ++j) { n       if ((i & (1 << j)) == 0) continue; n       if (curmask & (1 << j)) good = false; n       curmask |= ((1 << j) | incident_mask[j]); n     } n     if (good) ++cntmask[curmask >> m1]; n   } n   for (int i = 0; i < m2; ++i) n     for (int j = 0; j < (1 << m2); ++j) n       if (j & (1 << i)) cntmask[j] += cntmask[j ^ (1 << i)]; n   long long ans = 0; n   for (int i = 0; i < (1 << m2); i++) { n     long long curmask = 0; n     bool good = true; n     for (int j = m1; j < n; j++) { n       if ((i & (1 << (j - m1))) == 0) continue; n       if (curmask & (1LL << j)) good = false; n       curmask |= (1LL << j) | incident_mask[j]; n     } n     if (good) ans += cntmask[(i ^ ((1 << m2) - 1))]; n   } n   return ans; n } n inline long long calc(int mask) { n   if (mask == 0) return binpow(2, n); n   if (mask == 1 || mask == 4) return CountIndependentSets(); n   if (mask == 2) return binpow(2, CountComponents()); n   if (mask == 3 || mask == 6) return binpow(2, CountIsolated()); n   if (mask == 5) return (bipartite() ? binpow(2, CountComponents()) : 0); n   if (mask == 7) return (m == 0 ? binpow(2, n) : 0); n   return 0; n } n int main() { n   read(n); n   read(m); n   for (int i = 0; i < m; ++i) { n     int u, v; n     read(u), read(v); n     --u, --v; n     g[u].emplace_back(v); n     g[v].emplace_back(u); n     incident_mask[u] ^= (1LL << v); n     incident_mask[v] ^= (1LL << u); n   } n   long long ans = 0; n   for (int i = 0; i < 8; ++i) n     if (__builtin_popcount(i) % 2 == 0) n       ans += calc(i); n     else n       ans -= calc(i); n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1E9; n int main() { n   int n; n   string s; n   cin >> n >> s; n   for (int len = 1; len <= n; len++) { n     bool ok = true; n     for (int i = 0; i < n; i++) { n       if (i + len * 4 < n && s[i] ==  *  && s[i] == s[i + len] && n           s[i] == s[i + len + len] && s[i] == s[i + len * 3] && n           s[i] == s[i + len * 4]) { n         ok = 0; n         break; n       } n     } n     if (!ok) { n       puts( yes ); n       return 0; n     } n   } n   puts( no ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e7 + 100; n const int INF = 0x3FFFFFFF; n bool vis[MAXN]; n int main() { n   long long a, b, m; n   cin >> a >> b >> m; n   for (int i = 1; i <= a; i++) { n     long long t = 1e9; n     long long mod = i * t % m; n     if (vis[mod]) break; n     vis[mod] = 1; n     if (b + mod < m && mod) { n       cout <<  1  ; n       int cnt = 0; n       int temp = i; n       while (i) { n         i /= 10; n         cnt++; n       } n       for (int j = 1; j <= 9 - cnt; j++) cout << 0; n       cout << temp << endl; n       return 0; n     } n   } n   cout << 2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 710, size = 1 << 20, mod = (int)1e9 + 7, inf = 2e9; n const long long INF = 1e15; n template <class o> n void qr(o& x) { n   char c = getchar(); n   x = 0; n   int f = 1; n   while (!isdigit(c)) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (isdigit(c)) x = x * 10 + c -  0 , c = getchar(); n   x *= f; n } n template <class o, class... O> n void qr(o& x, O&... y) { n   qr(x); n   qr(y...); n } n template <class o> n void qw(o x) { n   if (x / 10) qw(x / 10); n   putchar(x % 10 +  0 ); n } n template <class o> n void pr1(o x) { n   if (x < 0) x = -x, putchar( - ); n   qw(x); n   putchar(   ); n } n template <class o, class... O> n void pr1(o x, O... y) { n   pr1(x); n   pr1(y...); n } n template <class o> n void pr2(o x) { n   if (x < 0) x = -x, putchar( - ); n   qw(x); n   putchar(  n ); n } n template <class o, class... O> n void pr2(o x, O... y) { n   pr2(x); n   pr2(y...); n } n long long gcd(long long a, long long b) { return !a ? b : gcd(b % a, a); } n long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n long long power(long long a, long long b = mod - 2, long long p = mod) { n   long long c = 1; n   while (b) { n     if (b & 1) c = c * a % p; n     b /= 2; n     a = a * a % p; n   } n   return c; n } n long long exgcd(long long a, long long b, long long& x, long long& y) { n   if (!a) { n     x = 0; n     y = 1; n     return b; n   } n   long long d = exgcd(b % a, a, y, x); n   x -= b / a * y; n   return d; n } n long long INV(long long n, long long p = mod) { n   long long x, y; n   exgcd(n, p, x, y); n   return (x % p + p) % p; n } n template <class o> n void cmax(o& x, o y) { n   if (x < y) x = y; n } n template <class o> n void cmin(o& x, o y) { n   if (x > y) x = y; n } n template <typename t1, typename t2> n void ad(t1& x, t2 y) { n   x += y; n   if (x >= mod) x -= mod; n } n template <typename t1, typename t2> n void dl(t1& x, t2 y) { n   x -= y; n   if (x < 0) x += mod; n } n char str[N]; n int n, a[N], cnt[10], f[N][N][10][2]; n void solve() { n   scanf( %s , str + 1); n   int n = strlen(str + 1); n   for (int i = 1; i <= n; i++) a[i] = str[i] -  0 ; n   for (int i = 1; i <= 9; i++) f[0][0][i][0] = 1; n   for (int i = 0; i <= n - 1; i++) n     for (int j = 0; j <= i; j++) n       for (int k = 1; k <= 9; k++) n         for (int l = 0; l <= 1; l++) n           if (f[i][j][k][l]) n             for (int v = !l ? a[i + 1] : 9; v >= 0; v--) n               ad(f[i + 1][j + (v >= k)][k][l | (v < a[i + 1])], f[i][j][k][l]); n   long long p = 1, ans = 0; n   for (int i = 1; i <= n; i++) { n     long long sum = 0; n     for (int j = 1; j <= 9; j++) sum += f[n][i][j][0] + f[n][i][j][1]; n     sum %= mod; n     ans = (ans + sum * p) % mod; n     p = (p * 10 + 1) % mod; n   } n   pr2(ans); n } n int main() { n   int T = 1; n   while (T--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100005], ans[100005], ti[100005], app[100005], t, n; n int cnt(int k) { n   int ret = 1, count = 0; n   ++t; n   for (int i = 1; i <= n; i++) { n     if (ti[a[i]] != t) { n       ti[a[i]] = t; n       app[a[i]] = false; n     } n     if (!app[a[i]]) { n       if (count == k) { n         count = 0; n         ret++; n         ti[a[i]] = ++t; n       } n       count++; n     } n     app[a[i]] = true; n   } n   return ret; n } n void solve(int l, int r, int lo, int hi) { n   if (l > r) return; n   int mid = (l + r) / 2; n   int res = lo == hi ? lo : cnt(mid); n   ans[mid] = res; n   solve(l, mid - 1, res, hi); n   solve(mid + 1, r, lo, res); n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   solve(1, n, 1, n); n   for (int i = 1; i <= n; i++) { n     if (i > 1) printf(   ); n     printf( %d , ans[i]); n   } n   cout << endl; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(2) n using namespace std; n inline void read(long long &x) { n   x = 0; n   long long f = 1; n   char s = getchar(); n   while (s <  0  || s >  9 ) { n     if (s ==  - ) f = -1; n     s = getchar(); n   } n   while (s >=  0  && s <=  9 ) { n     x = (x << 3) + (x << 1) + (s ^ 48); n     s = getchar(); n   } n   x *= f; n } n inline long long Max(long long x, long long y) { return x > y ? x : y; } n inline long long Min(long long x, long long y) { return x < y ? x : y; } n long long Gcd(long long a, long long b) { n   if (!b) return a; n   return Gcd(b, a % b); n } n inline long long Abs(long long x) { n   if (x < 0) return -x; n   return x; n } n inline double Fabs(double x) { n   if (x > 0) return x; n   return -x; n } n long long a[100005]; n int main() { n   long long n; n   read(n); n   long long XiangMeiHaoGuai = 1; n   if (XiangMeiHaoGuai + 1 == 3) printf( SXYYouYiGeQiaoPiGu ); n   for (register int i = 1; i <= n; ++i) read(a[i]); n   if (XiangMeiHaoGuai + 1 == 3) printf( SXYYouYiGeQiaoPiGu ); n   sort(a + 1, a + 1 + n); n   if (XiangMeiHaoGuai + 1 == 3) printf( SXYYouYiGeQiaoPiGu ); n   long long FuckingAns = a[2] - a[1]; n   if (XiangMeiHaoGuai + 1 == 3) printf( SXYYouYiGeQiaoPiGu ); n   for (register int i = 3; i <= n; ++i) n     FuckingAns = Gcd(FuckingAns, a[i] - a[i - 1]); n   if (XiangMeiHaoGuai + 1 == 3) printf( SXYYouYiGeQiaoPiGu ); n   long long FuckingDis = a[n] - a[1], Sucky = 1 - n; n   printf( %lld , FuckingDis / FuckingAns + Sucky); n   if (XiangMeiHaoGuai + 1 == 3) printf( SXYYouYiGeQiaoPiGu ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   string s[4]; n   for (int i = 0; i < 4; i++) cin >> s[i]; n   int x = 0; n   for (int i = 0; i < 3; i++) { n     for (int j = 0; j < 3; j++) { n       x = s[i][j] ==  # ; n       x += s[i + 1][j] ==  # ; n       x += s[i][j + 1] ==  # ; n       x += s[i + 1][j + 1] ==  # ; n       if (x != 2) return cout <<  YES , 0; n     } n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, S; n   cin >> n >> S; n   vector<int> a(n); n   for (int i = 0; i < n; i++) cin >> a[i]; n   long long z = LLONG_MAX; n   sort(a.begin(), a.end()); n   long long fh = 0, sh = 0; n   for (int i = 0; i < n / 2; i++) { n     if (a[i] > S) fh += a[i] - S; n     if (a[n - 1 - i] < S) sh += S - a[n - 1 - i]; n   } n   cout << fh + sh + abs(a[n / 2] - S); n   return 0; n } n


/* n  problem : CF1466I The Riddle of the Sphinx n  reference : https://www.luogu.com.cn/blog/CXY07/solution-cf1466i n */ n #include <bits/stdc++.h> n #define mp std::make_pair n #define pb push_back n #define fi first n #define se second n #define gc getchar n #define pc putchar n #define ep emplace n #define eb emplace_back n #define ctz __builtin_ctz n typedef unsigned char u8; n typedef unsigned short u16; n typedef unsigned int u32; n typedef long long ll; n typedef long double ld; n typedef unsigned long long ull; n typedef std::pair <int, int> pii; n typedef std::pair <int, ll> pil; n typedef std::pair <ll, int> pli; n typedef std::pair <ll, ll> pll; n const int max_N = 207; n int n, b; n std::string ans; n int read() { n  char c = gc(); int ans = 0; bool flag = true; n  while (!isdigit(c)) flag &= (c !=  - ), c = gc(); n  while (isdigit(c)) ans = ans * 10 + c -  0 , c = gc(); n  return flag ? ans : -ans; n } n void Write(int x) { n  if (x < 0) pc( - ), x = -x; n  if (x < 10) pc(x +  0 ); n  else Write(x / 10), pc(x % 10 +  0 ); n } n int min(int x, int y) {return x < y ? x : y;} n int max(int x, int y) {return x > y ? x : y;} n void _min(int &x, int y) {if (x > y) x = y;} n void _max(int &x, int y) {if (x < y) x = y;} n namespace Interactive { n  bool compare(int x, std::string y) { n   std::cout << x <<     << y << std::endl; n   return std::cin >> y, y ==  yes ; n  } n  bool compare_less(int x, std::string y) { n   if (!std::count(y.begin(), y.end(),  1 )) return false; n   for (int pos = y.size() - 1; y[pos] ==  0  ? (y[pos] =  1 , true) : (y[pos] =  0 , false); pos--);  n   return y.insert(y.end(), b - y.size(),  1 ), !compare(x, y); n  } n  bool compare_greater(int x, std::string y) { n   if (!std::count(y.begin(), y.end(),  0 )) return false; n   return y.insert(y.end(), b - y.size(),  1 ), compare(x, y); n  } n  void report(std::string x) { n   std::cout << 0 <<     << x << std::endl; n  } n } n void solve(std::vector <int> vec, int w) { n  std::vector <int> stack; n  for (auto i : vec) { n   while (!stack.empty() && Interactive::compare_greater(i, n    (std::string) {ans.begin(), ans.begin() + w + stack.size()})) stack.pop_back(); n   if (w + stack.size() < b) n    ans[w + stack.size()] = !Interactive::compare_less(i, n     (std::string) {ans.begin(), ans.begin() + w + stack.size()} +  1 ) +  0 , stack.pb(i); n  } n  for (int i = stack.size() - 1; i >= 0; i--) n   if (Interactive::compare_greater(stack[i], n    (std::string) {ans.begin(), ans.begin() + w + stack.size()})) stack.resize(i + 1); n  if (w + stack.size() < b) solve(stack, w + stack.size()); n } n int main() { n  std::cin >> n >> b; n  std::vector <int> vec; vec.resize(n); n  std::iota(vec.begin(), vec.end(), 1); n  ans.resize(b); solve(vec, 0); n  return Interactive::report(ans), 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxn = 3e5 + 30; n long long N, M, T, X[maxn], ans[maxn], shift; n char W[maxn]; n vector<pair<long long, long long> > v; n vector<long long> last; n int main() { n   cin >> N >> M >> T; n   for (long long i = 1; i <= N; i++) { n     scanf( %lld %c , &X[i], &W[i]); n     v.push_back(pair<long long, long long>(X[i], i)); n     W[i] = W[i] ==  L  ? -1 : 1; n   } n   for (long long i = 1; i <= N; i++) { n     long long a = (X[i] + T * W[i]), plus = 0; n     if (W[i] == -1) { n       a = a <= 0 ? (-a) / M + 1 : 0; n     } else n       plus = -(!(a % M)), a /= M; n     shift += W[i] * a + plus; n   } n   T %= M; n   for (long long i = 1; i <= N; i++) { n     long long a = X[i] + T * W[i] + M; n     a = (a - 1) % M + 1; n     last.push_back(a); n   } n   sort(v.begin(), v.end()); n   sort(last.begin(), last.end()); n   if (shift) shift = shift / abs(shift) * (abs(shift) % N); n   long long beg = ((-shift + N + 1) - 1) % N + 1; n   long long j = 0; n   for (long long i = beg - 1; i < N; i++) ans[v[i].second] = last[j++]; n   for (long long i = 0; i < beg - 1; i++) ans[v[i].second] = last[j++]; n   for (long long i = 1; i <= N; i++) printf( %lld  , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<double, pair<int, int> > > s; n int n, x; n pair<double, pair<int, int> > tmp; n signed main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> n; n   for (register int i = 1; (1 < n) ? (i <= n) : (i >= n); n        i += (1 < n) ? 1 : (-1)) { n     cin >> x; n     s.push_back(make_pair(x, make_pair(i, i))); n     while (s.size() > 1 && s[s.size() - 2] > s.back()) { n       tmp = s.back(); n       s.pop_back(); n       tmp = make_pair((tmp.first * (tmp.second.second - tmp.second.first + 1) + n                        s.back().first * (s.back().second.second - n                                          s.back().second.first + 1)) / n                           (tmp.second.second - s.back().second.first + 1), n                       make_pair(s.back().second.first, tmp.second.second)); n       s.pop_back(); n       s.push_back(tmp); n     } n   } n   for (auto i : s) { n     for (register int j = 1; (1 < i.second.second - i.second.first + 1) n                                  ? (j <= i.second.second - i.second.first + 1) n                                  : (j >= i.second.second - i.second.first + 1); n          j += (1 < i.second.second - i.second.first + 1) ? 1 : (-1)) { n       printf( %.9lf n , i.first); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long X[(int)1e5 + 9]; n long long C[(int)1e5 + 9]; n int main() { n   ios_base::sync_with_stdio(NULL); n   cin.tie(NULL); n   cout.tie(NULL); n   long long n, k, a, c, cost; n   cin >> n >> k; n   for (int i = 1; i <= n; i++) { n     cin >> X[i]; n   } n   cin >> a; n   for (int i = 1; i <= n; i++) { n     cin >> C[i]; n   } n   c = k; n   priority_queue<long long, vector<long long>, greater<long long> > Q; n   cost = 0; n   bool ans_ase = true; n   for (int i = 1; i <= n; i++) { n     Q.push(C[i]); n     if (c < X[i]) { n       if (Q.size() * a + c >= X[i]) { n         while (c < X[i]) { n           c += a; n           cost += Q.top(); n           Q.pop(); n         } n       } else { n         ans_ase = 0; n         break; n       } n     } n   } n   if (ans_ase) n     cout << cost <<   n ; n   else n     cout << -1 <<   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 ans = 0; n   long long a = 1, b = 2, c; n   while (b <= n) { n     ans++; n     c = a + b; n     a = b; n     b = c; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1000000009; n vector<long long> vec; n long long powmod(long long a, long long m) { n   long long ret = 1 % MOD; n   for (; m; m >>= 1) { n     if (m & 1) { n       ret *= a; n       if (ret >= MOD) ret %= MOD; n     } n     a *= a; n     if (a >= MOD) a %= MOD; n   } n   return ret; n } n int main() { n   long long n, m, k; n   vec.clear(); n   cin >> n >> m >> k; n   m = n - m; n   if (m >= n) { n     cout <<  0  << endl; n     return 0; n   } n   long long p = (long long)(n / k); n   if (m >= p) { n     cout << n - m << endl; n     return 0; n   } n   long long pos = n - m * k; n   long long div = pos / k; n   long long mod = pos % k; n   long long mul = (powmod(2, div) - 1) * k % MOD * 2 % MOD; n   mul = (mul + MOD) % MOD; n   mul = (mul + mod) % MOD; n   long long ans = (mul + n - pos - m) % MOD; n   ans = (ans + MOD) % MOD; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int d[100008] = {0}; n   int n = 0, f = 0; n   cin >> n; n   for (f = 0; f < n; f++) cin >> d[f]; n   sort(d, d + n); n   if (d[n - 1] >= d[n - 2] + d[n - 3]) n     cout <<  NO ; n   else { n     cout <<  YES n ; n     for (f = n - 1; f >= 0; f -= 2) cout << d[f] <<    ; n     f = n % 2; n     for (; f < n; f += 2) { n       cout << d[f]; n       if (f != n - 2) cout <<    ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 7; n const int inf = INT_MAX; n const long long inff = 1e18; n const long long mod = 1e9 + 7; n int p[30]; n int n; n string s; n int used[40]; n int Find(int x) { return p[x] == x ? x : p[x] = Find(p[x]); } n void Union(int x, int y) { p[Find(x)] = Find(y); } n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   for (int i = 1; i <= 26; i++) p[i] = i; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> s; n     int N = s.length(); n     for (int i = 0; i < N; i++) { n       used[s[i] -  a  + 1]++; n     } n     for (int i = 0; i < N - 1; i++) { n       Union(s[i] -  a  + 1, s[i + 1] -  a  + 1); n     } n   } n   set<int> second; n   for (int i = 1; i <= 26; i++) { n     if (used[i]) { n       second.insert(Find(i)); n     } n   } n   cout << ((int)(second).size()) <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 100, M = 52 + 10, LG = 30, base = 2; n const int MOD = 1e9 + 7, mod = 1e9 + 9; n const long long INF = 1e9, inf = 1e18; n long long p, q, m, k; n string w, s, t; n vector<long long> a, b; n vector<long long> ans; n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   ; n   cin >> w >> s >> t; n   while (p = w.find(s, p) + 1) a.push_back(p); n   while (q = w.find(t, q) + 1) b.push_back(q); n   for (int i = 0; i < a.size(); i++) { n     m = 0, k = 0; n     for (int j = a[i]; j <= w.size(); j++) { n       while (k < b.size() && b[k] < j) k++; n       if (k < b.size() && b[k] == j && j + t.size() >= a[i] + s.size()) n         ans.push_back(m); n       m = m * mod + (w[j - 1] -  a  + 1); n     } n   } n   sort(ans.begin(), ans.end()); n   cout << unique(ans.begin(), ans.end()) - ans.begin(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long cal(long long a, long long b) { n   long long sign = 1; n   if (a < 0) { n     a = -a; n     sign = -sign; n   } n   if (b < 0) { n     b = -b; n     sign = -sign; n   } n   unsigned long long n = (unsigned long long)a * b; n   long long r = n % 4000000000LL; n   return sign < 0 ? -r : r; n } n long long a[200001], BIT[200001], lazy[5 * 200001]; n void update(long long i, long long n, long long val) { n   while (i <= n) { n     BIT[i] += val; n     i += i & -i; n   } n } n long get(long long i) { n   long long ret = 0; n   while (i) { n     ret += BIT[i]; n     i -= i & -i; n   } n   return ret; n } n struct Num { n   long long a, b, c; n   Num() {} n   Num(long long x, long long y, long long z) { n     a = x; n     b = y; n     c = z; n   } n   Num operator+(const Num &n) { n     Num ret = *this; n     Num t = n; n     long long dif = ret.c - t.c; n     if (dif > 0) { n       long long k = 1LL << dif; n       t.a *= k; n       t.b *= k; n     } else if (dif < 0) { n       dif = -dif; n       long long k = 1LL << dif; n       ret.a *= k; n       ret.b *= k; n       ret.c = t.c; n     } n     ret.a += t.a; n     ret.b += t.b; n     if (ret.c && !(ret.a & 1) && !(ret.b & 1)) { n       ret.c--; n       ret.a >>= 1; n       ret.b >>= 1; n     } n     ret.a %= 4000000000LL; n     ret.b %= 4000000000LL; n     return ret; n   } n   Num operator-(const Num &n) { return *this + Num(-n.a, -n.b, n.c); } n   Num operator*(const Num &n) { n     long long x = (cal(a, n.a) + 5 * cal(b, n.b)) % 4000000000LL; n     long long y = (cal(a, n.b) + cal(b, n.a)) % 4000000000LL; n     long long z = c + n.c; n     while (z && !(x & 1) && !(y & 1)) { n       z--; n       x >>= 1; n       y >>= 1; n     } n     return Num(x, y, z); n   } n   Num operator*(long long n) { n     Num ret = Num(a, b, c); n     if (!n) { n       return Num(0, 0, 0); n     } n     if (ret.c && !(n & 1)) { n       ret.c--; n       n >>= 1; n     } n     ret.a = cal(ret.a, n); n     ret.b = cal(ret.b, n); n     return ret; n   } n   long long get() { n     if (c) n       return ((b / (1LL << (c - 1))) % 1000000000 + 1000000000) % 1000000000; n     return (((b << 1) / (1LL << c)) % 1000000000 + 1000000000) % 1000000000; n   } n }; n Num x(1, 1, 1); n Num sx[200001], Sx[200001]; n struct Segment { n   long long i, l, r; n   Num val; n   Segment() {} n   Segment(int k, int a, int b, Num c) { n     i = k; n     l = a; n     r = b; n     val = c; n   } n   long long len() { return r - l + 1; } n   void update() { n     if (lazy[i] == 0) return; n     val = val + (Sx[r - l + 1] * lazy[i]); n     if (l < r) { n       lazy[i << 1] += lazy[i]; n       lazy[(i << 1) + 1] += lazy[i]; n     } n     lazy[i] = 0; n   } n }; n Segment T[5 * 200001]; n void go(long long i, long long l, long long r) { n   if (l == r) { n     T[i] = Segment(i, l, r, x * a[l]); n     return; n   } n   long long m = (l + r) >> 1; n   go(i << 1, l, m); n   go((i << 1) + 1, m + 1, r); n   Num x = T[i << 1].val + (sx[m - l + 1] * T[(i << 1) + 1].val); n   T[i] = Segment(i, l, r, x); n } n Num get(long long i, long long l, long long r) { n   T[i].update(); n   if (l == T[i].l && r == T[i].r) { n     return T[i].val; n   } n   long long m = (T[i].l + T[i].r) >> 1; n   if (r <= m) return get(i << 1, l, r); n   if (l > m) return get((i << 1) + 1, l, r); n   Num left = get(i << 1, l, m); n   Num right = get((i << 1) + 1, m + 1, r); n   return left + (sx[m - l + 1] * right); n } n void update(long long i, long long l, long long r, long long val) { n   if (l == T[i].l && r == T[i].r) { n     lazy[i] += val; n     return; n   } n   long long m = (T[i].l + T[i].r) >> 1; n   if (r <= m) { n     update(i << 1, l, r, val); n   } else if (l > m) { n     update((i << 1) + 1, l, r, val); n   } else { n     update(i << 1, l, m, val); n     update((i << 1) + 1, m + 1, r, val); n   } n   T[i << 1].update(); n   T[(i << 1) + 1].update(); n   T[i].val = T[i << 1].val + (sx[T[i << 1].len()] * T[(i << 1) + 1].val); n } n int main() { n   long long n, q, i, k, t, v, l, r, d, add; n   scanf( %lld %lld , &n, &q); n   sx[1] = Sx[1] = x; n   for (i = 2; i <= n; i++) { n     sx[i] = sx[i - 1] * x; n     Sx[i] = Sx[i - 1] + sx[i]; n   } n   for (i = 1; i <= n; i++) { n     scanf( %lld , a + i); n     update(i, n, a[i]); n     update(i + 1, n, -a[i]); n   } n   go(1, 1, n); n   while (q--) { n     scanf( %lld , &t); n     if (t == 1) { n       scanf( %lld %lld , &k, &v); n       add = v - get(k); n       update(k, n, add); n       update(k + 1, n, -add); n       update(1, k, k, add); n     } else { n       scanf( %lld %lld , &l, &r); n       if (t == 2) { n         printf( %lld n , get(1, l, r).get()); n       } else { n         scanf( %lld , &d); n         update(l, n, d); n         update(r + 1, n, -d); n         update(1, l, r, d); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int NR = 1005; n int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = (x << 3) + (x << 1) + (ch ^ 48); n     ch = getchar(); n   } n   return x * f; n } n int n, m, a, b; n int h[NR][NR]; n int num[NR][NR]; n int mn[NR][NR]; n struct Nd { n   int id, x; n }; n Nd md(int id, int x) { n   Nd tmp; n   tmp.id = id, tmp.x = x; n   return tmp; n } n int all; n struct Mashiro { n   int x, y; n   long long ans; n   bool operator<(const Mashiro& A) const { n     return (ans == A.ans) ? ((x == A.x) ? y < A.y : x < A.x) : ans < A.ans; n   } n } p[NR * NR]; n bool flag[NR][NR]; n Mashiro Md(int x, int y, long long ans) { n   Mashiro tmp; n   tmp.x = x, tmp.y = y, tmp.ans = ans; n   return tmp; n } n long long sum[NR][NR]; n long long getsum(int l1, int r1, int l2, int r2) { n   return sum[l2][r2] + sum[l1 - 1][r1 - 1] - sum[l2][r1 - 1] - sum[l1 - 1][r2]; n } n int tot; n int posx[NR * NR], posy[NR * NR]; n long long ans[NR * NR]; n void add(int x, int y, long long num) { n   tot++; n   posx[tot] = x, posy[tot] = y, ans[tot] = num; n } n void print() { n   printf( %d n , tot); n   for (int i = 1; i <= tot; i++) n     printf( %d %d %lld n , posx[i], posy[i], ans[i]); n } n int main() { n   n = read(), m = read(), a = read(), b = read(); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) h[i][j] = read(); n   for (int i = 1; i <= n; i++) { n     deque<Nd> q; n     for (int j = 1; j <= b; j++) { n       while (!q.empty() && h[i][j] < q.back().x) q.pop_back(); n       q.push_back(md(j, h[i][j])); n     } n     num[i][1] = q.front().x; n     for (int j = b + 1; j <= m; j++) { n       while (!q.empty() && q.front().id <= j - b) q.pop_front(); n       while (!q.empty() && h[i][j] < q.back().x) q.pop_back(); n       q.push_back(md(j, h[i][j])); n       num[i][j - b + 1] = q.front().x; n     } n   } n   for (int i = 1; i <= m - b + 1; i++) { n     deque<Nd> q; n     for (int j = 1; j <= a; j++) { n       while (!q.empty() && num[j][i] < q.back().x) q.pop_back(); n       q.push_back(md(j, num[j][i])); n     } n     mn[1][i] = q.front().x; n     for (int j = a + 1; j <= n; j++) { n       while (!q.empty() && q.front().id <= j - a) q.pop_front(); n       while (!q.empty() && num[j][i] < q.back().x) q.pop_back(); n       q.push_back(md(j, num[j][i])); n       mn[j - a + 1][i] = q.front().x; n     } n   } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + h[i][j]; n   for (int i = 1; i <= n - a + 1; i++) n     for (int j = 1; j <= m - b + 1; j++) n       p[++all] = n           Md(i, j, getsum(i, j, i + a - 1, j + b - 1) - 1ll * mn[i][j] * a * b); n   sort(p + 1, p + all + 1); n   for (int i = 1; i <= all; i++) { n     if (flag[p[i].x][p[i].y]) continue; n     add(p[i].x, p[i].y, p[i].ans); n     for (int j = max(1, p[i].x - a + 1); j <= min(n, p[i].x + a - 1); j++) n       for (int k = max(1, p[i].y - b + 1); k <= min(m, p[i].y + b - 1); k++) n         flag[j][k] = 1; n   } n   print(); n   return 0; n } n


#include<bits/stdc++.h> n #define ll long long n #define pll pair<ll,ll> n #define pii pair<int,int> n #define rep(i,a,b) for(int i=a;i<=b;++i) n #define per(i,a,b) for(int i=a;i>=b;--i) n #define mem0(x) memset(x,0,sizeof(x)) n #define meminf(x) memset(x,0x3f,sizeof(x)) n #define VI vector<int> n #define VL vector<ll> n #define pb push_back n #define YES(n) cout << ((n) ?  YES  :  NO   ) << endl n #define Yes(n) cout << ((n) ?  Yes  :  No   ) << endl n #define endl   n  n #define pb push_back n #define fi first  n #define se second n  n #define dump(x)  cerr << #x <<   =   << (x) << endl; n #define debug(x) cerr << #x <<   =   << (x) <<   (L  << __LINE__ <<  )  <<     << __FILE__ << endl; n //#define DEBUG n using namespace  std; n  n  n const int N = 150+5, inf = 0x3f3f3f3f; n  n int n,k; n ll a[N],b[N],tmm[N]; n  n void solve(){ n     cin>>n; n     rep(i,1,n){ n      cin>>a[i]>>b[i]; n     } n     rep(i,1,n){ n      cin>>tmm[i]; n     } n      n     ll tim = 0; n  n     rep(i,1,n){ n      tim += a[i]-b[i-1]+tmm[i]; n      if(n == i) break; n      ll lim = max(b[i]-tim, (b[i]-a[i]+1)/2); n      tim += lim; n     } n     cout << tim <<endl; n      n } n  n  n int main(){ n     ios::sync_with_stdio(0); n     int tt;cin>>tt; n     while(tt--){ n         solve(); n     } n }


#include <bits/stdc++.h> n using namespace std; n void ch_max(int &x, int y) { n   if (x < y) x = y; n } n void ch_min(int &x, int y) { n   if (x > y) x = y; n } n const double pi = acos(-1.0); n const double eps = 1e-9; n bool solve(long long a, long long b) { n   if (a == 0 || b == 0) return false; n   if (a < b) swap(a, b); n   if (a % b == 0) return true; n   if (!solve(a % b, b)) return true; n   long long t0 = a / b; n   long long t1 = t0 % (b + 1); n   if (t1 % 2) return false; n   return true; n } n int main() { n   int i, j, k, t, nc = 0; n   scanf( %d , &t); n   while (t--) { n     long long a, b; n     scanf( %I64d%I64d , &a, &b); n     if (solve(a, b)) n       printf( First n ); n     else n       printf( Second n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using LL = long long; n void err() { cout << endl; } n template <template <typename...> class T, typename t, typename... Args> n void err(T<t> a, Args... args) { n   for (auto x : a) cout << x <<    ; n   err(args...); n } n template <typename T, typename... Args> n void err(T a, Args... args) { n   cout << a <<    ; n   err(args...); n } n struct P { n   int a, b, item; n }; n const int N = 1E5 + 100; n int n, m, dm[N]; n set<int> S[N]; n int orders[N]; n int main() { n   cin >> n >> m; n   int tot = 0; n   for (decay<decltype(n + 1)>::type i = (1), _i = (n + 1); i < _i; ++i) { n     int sz; n     scanf( %d , &sz); n     for (decay<decltype(sz)>::type j = (0), _j = (sz); j < _j; ++j) { n       int x; n       scanf( %d , &x); n       S[i].insert(x); n     } n     tot += sz; n   } n   for (decay<decltype(n + 1)>::type i = (1), _i = (n + 1); i < _i; ++i) n     orders[i] = i; n   sort(orders + 1, orders + n + 1, n        [](const int& x, const int& y) { return S[x].size() > S[y].size(); }); n   int ll = 1, rr = n; n   int at_least = tot / n; n   for (decay<decltype(n + 1)>::type i = (1), _i = (n + 1); i < _i; ++i) { n     if (i <= tot % n) n       dm[orders[i]] = at_least + 1; n     else n       dm[orders[i]] = at_least; n   } n   vector<P> gather; n   while (ll < rr) { n     vector<P> adds; n     int rrrrrrrrr = orders[rr], lllllllll = orders[ll]; n     ; n     if (int((S[rrrrrrrrr]).size()) >= dm[rrrrrrrrr] && n         int((S[lllllllll]).size()) <= dm[lllllllll]) n       break; n     vector<set<int>::iterator> vs; n     vs.push_back(S[lllllllll].begin()); n     for (int v : S[rrrrrrrrr]) { n       auto it = S[lllllllll].upper_bound(v); n       if (it != S[lllllllll].end()) vs.push_back(it); n     } n     vector<int> dec; n     for (auto it : vs) n       while (int((S[lllllllll]).size()) - int((dec).size()) > dm[lllllllll] && n              int((S[rrrrrrrrr]).size()) < dm[rrrrrrrrr] && n              S[rrrrrrrrr].find(*it) == S[rrrrrrrrr].end()) { n         S[rrrrrrrrr].insert(*it); n         dec.push_back(*it++); n       } n     for (int v : dec) { n       S[lllllllll].erase(v); n       gather.push_back({lllllllll, rrrrrrrrr, v}); n     }; n     if (int((S[lllllllll]).size()) == dm[lllllllll]) ll++; n     if (int((S[rrrrrrrrr]).size()) == dm[rrrrrrrrr]) rr--; n   } n   cout << gather.size() << endl; n   for (decay<decltype(gather.size())>::type i = (0), _i = (gather.size()); n        i < _i; ++i) n     printf( %d %d %d n , gather[i].a, gather[i].b, gather[i].item); n } n


#include <bits/stdc++.h> n using namespace std; n int n, head[100005], tot, de[100005], le[100005], lf[100005]; n struct node { n   int to, next; n } edge[100005 * 2]; n void add_edge(int u, int v) { n   de[u]++; n   edge[tot].to = v; n   edge[tot].next = head[u]; n   head[u] = tot++; n } n void dfs(int cnt, int pre) { n   lf[cnt] = 1; n   for (int i = head[cnt]; i != -1; i = edge[i].next) { n     int j = edge[i].to; n     if (j == pre) continue; n     if (de[j] <= 2) dfs(j, cnt); n   } n } n int main() { n   while (cin >> n) { n     tot = 0; n     memset(head, -1, sizeof(head)); n     memset(de, 0, sizeof(de)); n     memset(lf, 0, sizeof(lf)); n     memset(le, 0, sizeof(le)); n     for (int i = 1; i < n; i++) { n       int u, v; n       cin >> u >> v; n       add_edge(u, v); n       add_edge(v, u); n     } n     for (int i = 1; i <= n; i++) { n       if (de[i] == 1) dfs(i, 0); n     } n     for (int i = 1; i <= n; i++) { n       for (int j = head[i]; j != -1; j = edge[j].next) { n         int k = edge[j].to; n         if (lf[k]) le[i]++; n       } n     } n     int flag = 0; n     for (int i = 1; i <= n && !flag; i++) { n       if (lf[i]) continue; n       int cn = 0; n       for (int j = head[i]; j != -1; j = edge[j].next) { n         int k = edge[j].to; n         if (lf[k] == 0 && de[k] - min(2, le[k]) >= 2) cn++; n         if (cn > 2) { n           flag = 1; n           break; n         } n       } n     } n     if (flag) n       cout <<  NO n ; n     else n       cout <<  YES n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 3e5 + 10; n long long n, a, d[MAXN], v[MAXN], P[MAXN]; n vector<pair<int, long long> > vc; n long long ans; n int main() { n   cin >> n >> a; n   vc.push_back({0, 0}); n   P[0] = -1e18; n   for (int i = 0; i < n; i++) { n     cin >> d[i] >> v[i]; n     ans = max(ans, a - v[i]); n     v[i] -= a; n     if (i == 0) continue; n     v[i] += v[i - 1]; n     long long mn; n     if (i >= 2) n       mn = v[i - 2]; n     else n       mn = 0; n     while (!vc.empty() && vc.back().first <= d[i] - d[i - 1]) n       mn = max(mn, vc.back().second), vc.pop_back(); n     vc.push_back({d[i] - d[i - 1], mn}); n     mn -= (d[i] - d[i - 1]) * (d[i] - d[i - 1]); n     P[vc.size()] = max(P[vc.size() - 1], mn); n     ans = max(ans, -v[i] + P[vc.size()]); n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   long long n; n   cin >> n; n   long long ans = 0; n   long long L = -4 * 45, R = 45; n   map<long long, long long> vls; n   for (long long i = L; i <= R; i++) vls[i] = 1e18; n   for (long long i = 0; i < 100; i++) { n     for (long long j = 0; j < 100; j++) { n       for (long long k = 0; k < 100; k++) { n         long long nm = -4 * i + 5 * j + 45 * k; n         if (nm >= L && nm <= R) vls[nm] = min(vls[nm], i + j + k); n       } n     } n   } n   for (long long i = L; i <= R; i++) { n     if (vls[i] <= n) { n       ans++; n     } n   } n   for (long long i = L; i < L + 4; i++) { n     long long op = vls[i]; n     if (op < n) ans += n - op; n   } n   for (long long i = R - 44; i <= R; i++) { n     long long op = vls[i]; n     if (op < n) ans += n - op; n   } n   cout << ans; n   return 0; n } n


// #include<bits/stdc++.h> n #include<iostream> n #include<algorithm> n #include<cmath> n /* n #include<vector> n #include<set> n #include<map> n #include<unordered_map> n #define umap unordered_map n #include<unordered_set> n #define uset unordered_set n */ n #define pii pair<int,int> n #define F first n #define S second n #define fr(i,n) for(int i=0;i<n;++i) n #define pr cout<< n #define en <<  n  n #define sp <<    n using namespace std; n typedef long long ll; n  n int ar[200001]; n  n  n int main() n { n  // ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); n  int t=1,n,a ; n  cin>>t; n  while(t--) n  { n   cin>>n; n   int no=0, cnt=0,ans=0; n   fr(i,n){ n    cin>>a; n    if(a==no) cnt++; n    else{ n     ans=max(ans,cnt); n     cnt=1; n     no =a; n    } n   } n   ans=max(ans,cnt); n   pr ans en; n  } n } n  n  n  n  n  n  n  n


#include <bits/stdc++.h> n using namespace std; n int y; n int main() { n   long long int a, b, s; n   cin >> a >> b >> s; n   a = abs(a); n   b = abs(b); n   if (s >= a + b && (s - a - b) % 2 == 0) { n     cout <<  YES ; n   } else n     cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n bool cmp(int a, int b) { return a > b; } n const int maxen = 1e5 + 5, minn = 1e-5; n string a[1005]; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   int res = 0, mn = 13; n   for (int i = 0; i < n - 1; i++) { n     for (int j = i + 1; j < n; j++) { n       string b = a[i]; n       string c = a[j]; n       res = 0; n       for (int k = 0; k < 6; k++) n         if (b[k] != c[k]) res++; n       mn = min(mn, res); n     } n   } n   cout << (mn - 1) / 2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n #define pb push_back n #define mp make_pair n #define ll long long n #define mod 1000000007 n using namespace std; n void factorial(ll int *fact) n { n  fact[0]=1; n     for(ll int i=1;i<=200000;i++) n     { n      fact[i]=(fact[i-1]*i)%mod; n  } n } n int main()  n { n    int t=1; n    cin>>t; n    ll int fact[200001]; n    factorial(fact); n    while(t--) n    { n     ll int n; n   cin>>n; n   ll int i,j,a[n]; n   ll int mi=INT_MAX; n   for(i=0;i<n;i++) n   { n    cin>>a[i]; n    mi=min(mi,a[i]); n   } n   ll int c=0; n   ll int an=mi; n   for(i=0;i<n;i++) n   { n    if(a[i]==mi) n    c++; n    an=an&a[i]; n   } n   if(an!=mi && c>=2) n   { n    cout<<0<<endl; n   } n   else n   { n    cout<<((((((c*(c-1))/2)%mod)*fact[n-2])%mod)*2)%mod<<endl; n   } n  } n }


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long int n, i, t, j, p, q, a, b, m; n   cin >> t; n   while (t--) { n     cin >> n >> m; n     string s[n]; n     bool ck = true; n     ; n     p = (n * m); n     if (p % 2 == 0) n       a = (p / 2) - 1; n     else n       a = p / 2; n     for (i = 0; i < n; i++) { n       for (j = 0; j < m; j++) { n         if (!ck && a) { n           s[i] +=  W ; n           a--; n           ck = true; n           continue; n         } else { n           s[i] +=  B ; n           ck = false; n           continue; n         } n       } n     } n     if (p % 2 == 0) { n       s[n - 2][m - 2] =  W ; n       s[n - 2][m - 1] =  B ; n     } n     for (i = 0; i < n; i++) cout << s[i] << endl; n   } n   return; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<int> > arr; n double ans = 0; n void dfs(int x, int h, int p) { n   ans += 1.0 / h; n   for (int i = 0; i < arr[x].size(); i++) { n     if (arr[x][i] != p) dfs(arr[x][i], h + 1, x); n   } n } n int main() { n   int n; n   cin >> n; n   int x, y; n   arr.resize(n + 1); n   for (int i = 0; i < n - 1; i++) { n     cin >> x >> y; n     arr[x].push_back(y); n     arr[y].push_back(x); n   } n   dfs(1, 1, -1); n   printf( %0.7f , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int MOD = 1e9 + 7; n long long int power(long long int a, long long int b) { n   long long int res = 1; n   a = a % MOD; n   while (b > 0) { n     if (b & 1) { n       res = (res * a) % MOD; n       b--; n     } n     a = (a * a) % MOD; n     b >>= 1; n   } n   return res; n } n long long int fermat_inv(long long int y) { return power(y, MOD - 2); } n long long int gcd(long long int a, long long int b) { n   return (b == 0) ? a : gcd(b, a % b); n } n long long int min(long long int a, long long int b) { return (a > b) ? b : a; } n long long int max(long long int a, long long int b) { return (a > b) ? a : b; } n using cd = complex<double>; n const double PI = acos(-1); n void fft(vector<cd> &a, bool invert) { n   int n = a.size(); n   for (int i = 1, j = 0; i < n; i++) { n     int bit = n >> 1; n     for (; j & bit; bit >>= 1) j ^= bit; n     j ^= bit; n     if (i < j) swap(a[i], a[j]); n   } n   for (int len = 2; len <= n; len <<= 1) { n     double ang = 2 * PI / len * (invert ? -1 : 1); n     cd wlen(cos(ang), sin(ang)); n     for (int i = 0; i < n; i += len) { n       cd w(1); n       for (int j = 0; j < len / 2; j++) { n         cd u = a[i + j], v = a[i + j + len / 2] * w; n         a[i + j] = u + v; n         a[i + j + len / 2] = u - v; n         w *= wlen; n       } n     } n   } n   if (invert) { n     for (cd &x : a) x /= n; n   } n } n vector<int> mult(vector<int> &a, vector<int> &b) { n   int n = 1; n   while (n < 2 * max(a.size(), b.size())) n <<= 1; n   vector<cd> A((a).begin(), (a).end()), B((b).begin(), (b).end()); n   A.resize(n); n   B.resize(n); n   fft(A, false); n   fft(B, false); n   vector<cd> C(n); n   for (int i = 0; i < n; i++) C[i] = A[i] * B[i]; n   fft(C, true); n   vector<int> ans(n); n   for (int i = 0; i < n; i++) ans[i] = round(C[i].real()); n   return ans; n } n int f[1000005]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int te = 1; n   while (te--) { n     int n, x, y; n     cin >> n >> x >> y; n     vector<int> a(x + 1), b(x + 1); n     for (int i = 0; i <= n; i++) { n       int z; n       cin >> z; n       a[z] = 1; n       b[x - z] = 1; n     } n     vector<int> v = mult(a, b); n     fill(f, f + 1000005, -1); n     for (int i = x + 1; i < v.size(); i++) { n       if (v[i]) { n         int val = 2 * (i - x) + 2 * y; n         for (int j = val; j <= 1000000; j += val) f[j] = val; n       } n     } n     int q; n     cin >> q; n     for (int i = 0; i < q; i++) { n       int l; n       cin >> l; n       cout << f[l] <<    ; n     } n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> tree[2010]; n int cs[2010], ps[2010]; n int numDesc(int node) { n   int descendants = 0; n   for (int x : tree[node]) { n     descendants += 1 + numDesc(x); n   } n   if (descendants < cs[node]) return 10000; n   return descendants; n } n void solve(int node, vector<int>& order) { n   ps[node] = order[cs[node]]; n   order.erase(order.begin() + cs[node]); n   for (int x : tree[node]) solve(x, order); n } n int main() { n   int n; n   cin >> n; n   int root; n   for (int i = 1; i <= n; i++) { n     int p, c; n     cin >> p >> c; n     cs[i] = c; n     if (p == 0) { n       root = i; n       continue; n     } n     tree[p].push_back(i); n   } n   if (numDesc(root) > 5000) n     cout <<  NO ; n   else { n     vector<int> order(n); n     order[0] = 1; n     for (int i = 1; i < n; i++) order[i] = order[i - 1] + 1; n     solve(root, order); n     cout <<  YES n ; n     for (int i = 1; i < n; i++) cout << ps[i] <<    ; n     cout << ps[n]; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n char s[110]; n int main() { n   while (~scanf( %s , s) && s[0] !=  e ) { n     char op[10]; n     int x = 0, y = 0, p, ans = 0; n     for (int i = 0; i <= 30; i++) { n       x = (i == 0 ? 0 : 1 << (i - 1)); n       y = 1 << i; n       cout <<  ?   << x <<     << y << endl; n       cin >> op; n       if (op[0] ==  x ) { n         p = i - 1; n         break; n       } n     } n     if (p != -1) { n       ans = 1 << p; n       for (int i = p - 1; i >= 0; i--) { n         y = 1 << i; n         cout <<  ?   << ans <<     << ans + y << endl; n         cin >> op; n         if (op[0] ==  y ) ans += y; n       } n     } n     cout <<  !   << ans + 1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long t, n, m, u, v, cnt = 0; n long long head[400005], depth[200005], visited[200005]; n vector<long long> ve[5]; n struct edge { n   long long next; n   long long to; n } e[400005]; n queue<long long> q; n inline void add_edge(long long u, long long v) { n   cnt++; n   e[cnt].to = v; n   e[cnt].next = head[u]; n   head[u] = cnt; n } n inline void bfs() { n   q.push(1); n   depth[1] = 0; n   visited[1] = 1; n   while (!q.empty()) { n     long long now = q.front(); n     for (long long i = head[now]; i; i = e[i].next) { n       if (visited[e[i].to] == 0) { n         depth[e[i].to] = depth[now] + 1; n         q.push(e[i].to); n         visited[e[i].to] = 1; n       } n     } n     visited[now] = 1; n     q.pop(); n   } n } n signed main() { n   cin >> t; n   while (t--) { n     cin >> n >> m; n     cnt = 0; n     for (long long i = 0; i <= 1; i++) ve[i].clear(); n     for (long long i = 1; i <= n; i++) visited[i] = 0; n     for (long long i = 1; i <= 2 * n; i++) head[i] = e[i].next = e[i].to = 0; n     for (long long i = 1; i <= m; i++) { n       cin >> u >> v; n       add_edge(u, v); n       add_edge(v, u); n     } n     bfs(); n     for (long long i = 1; i <= n; i++) ve[depth[i] % 2].push_back(i); n     if (ve[0].size() <= ve[1].size()) { n       cout << ve[0].size() << endl; n       for (long long i = 0; i < ve[0].size(); i++) cout << ve[0][i] <<    ; n       cout << endl; n     } else { n       cout << ve[1].size() << endl; n       for (long long i = 0; i < ve[1].size(); i++) cout << ve[1][i] <<    ; n       cout << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 2e18; n const long long INFINT = 2e9; n const int N = 1000006; n const int NN = 1006; n const int MOD = 1000000007; n int main() { n   ios_base::sync_with_stdio(0); n   long double n, h; n   cin >> n >> h; n   long double s = 1.0 * 1 * h / 2; n   long double k = 1.0 * s / n; n   long double mda = k; n   for (int i = 0; i < n - 1; i++) { n     long double l = 0; n     long double r = h; n     for (int it = 0; it < 10000; it++) { n       long double mid = 1.0 * (l + r) / 2; n       if ((1.0 * mid / h) * mid / 2 < k) { n         l = mid; n       } else { n         r = mid; n       } n     } n     cout << fixed << setprecision(9) << l <<    ; n     k = mda * (i + 2); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = (int)1e5 + 9; n long long power(long long x, long long y) { n   if (y == 0) return 1; n   long long temp = power(x, y / 2); n   if (y % 2 == 1) n     return temp * temp * x; n   else n     return temp * temp; n } n bool check(string a, string b) { n   sort(a.begin(), a.end()); n   sort(b.begin(), b.end()); n   if (a == b) return true; n   return false; n } n string solve(string x) { n   int n = x.length(); n   if (n % 2) return x; n   string a = solve(x.substr(0, n / 2)); n   string b = solve(x.substr(n / 2, n)); n   return a < b ? (a + b) : (b + a); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   string a, b; n   cin >> a >> b; n   if (solve(a) == solve(b)) n     cout <<  YES ; n   else n     cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, p, q, c, x, y, mod, lo[100000], z[3005][3005]; n long long ans; n struct segment_tree { n   int a[3005][13]; n   void update(int x, int y) { a[x][0] = y; } n   void build(int n) { n     for (int i = 1; i <= lo[n]; i++) n       for (int j = 1; j + (1 << i) - 1 <= n; j++) n         a[j][i] = min(a[j][i - 1], a[j + (1 << (i - 1))][i - 1]); n   } n   long long find(int x, int y) { n     int len = lo[y - x + 1]; n     return min(a[x][len], a[y - (1 << len) + 1][len]); n   } n } a; n int main() { n   scanf( %d%d%d%d , &n, &m, &p, &q); n   scanf( %d%d%d%d , &c, &x, &y, &mod); n   a.update(1, c); n   for (int i = 2; i <= 10000; i++) lo[i] = lo[i >> 1] + 1; n   for (int i = 2; i <= m; i++) c = (1ll * c * x + y) % mod, a.update(i, c); n   a.build(m); n   for (int i = 1; i <= m - q + 1; i++) z[1][i] = a.find(i, i + q - 1); n   for (int i = 2; i <= n; i++) { n     for (int j = 1; j <= m; j++) c = (1ll * c * x + y) % mod, a.update(j, c); n     a.build(m); n     for (int j = 1; j <= m - q + 1; j++) z[i][j] = a.find(j, j + q - 1); n   } n   for (int i = 1; i <= m - q + 1; i++) { n     for (int j = 1; j <= n; j++) a.update(j, z[j][i]); n     a.build(n); n     for (int j = 1; j <= n - p + 1; j++) ans = ans + a.find(j, j + p - 1); n   } n   printf( %lld , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int t, k; n int main() { n   cin >> t; n   while (t--) { n     vector<vector<pair<int, int>>> graph; n     cin >> k; n     graph.resize(2 * k); n     for (int i = 0; i < 2 * k - 1; ++i) { n       int a, b, c; n       cin >> a >> b >> c; n       a--; n       b--; n       graph[a].emplace_back(b, c); n       graph[b].emplace_back(a, c); n     } n     vector<int> parent(2 * k, -1); n     vector<long long> cost(2 * k); n     vector<int> que(1, 0); n     parent[0] = 0; n     for (int i = 0; i < que.size(); ++i) { n       int t = que[i]; n       for (auto it : graph[t]) { n         if (parent[it.first] == -1) { n           parent[it.first] = t; n           cost[it.first] = it.second; n           que.emplace_back(it.first); n         } n       } n     } n     long long mn = 0, mx = 0; n     vector<int> size(2 * k, 1); n     reverse(que.begin(), que.end()); n     for (int i : que) { n       size[parent[i]] += size[i]; n       mx += cost[i] * min(2 * k - size[i], size[i]); n       mn += cost[i] * (size[i] & 1); n     } n     cout << mn <<     << mx << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int bit[200050]; n int n; n int lowbit(int x) { return x & (-x); } n int sum(int x) { n   int sum = 0; n   while (x > 0) { n     sum += bit[x]; n     x -= lowbit(x); n   } n   return sum; n } n void push(int pos, int num) { n   while (pos <= n) { n     bit[pos] += num; n     pos += lowbit(pos); n   } n } n int kth(int k) { n   int num = 0; n   int x = 0; n   for (int i = 1 << 18; i > 0; i >>= 1) { n     num += i; n     if (num >= n || x + bit[num] >= k) n       num -= i; n     else n       x += bit[num]; n   } n   return num + 1; n } n int main() { n   scanf( %d , &n); n   int a[200050]; n   int x; n   memset((bit), (0), sizeof((bit))); n   for (int i = 0; i < n; i++) { n     scanf( %d , &x); n     push(x + 1, 1); n     a[i] = x - sum(x); n   } n   memset((bit), (0), sizeof((bit))); n   for (int i = 0; i < n; i++) { n     scanf( %d , &x); n     push(x + 1, 1); n     a[i] += x - sum(x); n   } n   for (int i = n - 1; i > 0; i--) { n     if (a[i] >= n - i) { n       a[i - 1]++; n       a[i] -= n - i; n     } n   } n   if (a[0] >= n) a[0] -= n; n   for (int i = 0; i < n; i++) { n     int num = kth(a[i] + 1); n     printf( %d  , num - 1); n     push(num, -1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool prime(long long x) { n   if (x == 2) return 1; n   if (x % 2 == 0) return 0; n   for (long long j = 3; j * j <= x; j += 2) { n     if (x % j == 0) return 0; n   } n   return 1; n } n int main() { n   long long t; n   cin >> t; n   while (t--) { n     long long n, m; n     cin >> n >> m; n     if (n - m > 1) { n       cout <<  NO  << endl; n     } else { n       if (prime(n + m)) { n         cout <<  YES  << endl; n       } else { n         cout <<  NO  << endl; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rnd(time(0)); n const long long inf = 0x3f3f3f3f3f3f3f3fLL; n const long long N = 35; n const long long MOD = 1e9 + 7; n long long n, u, r, ans = -inf; n long long a[N], b[N], k[N], p[N], dp[N][N]; n void go(long long pos, long long lst) { n   if ((u - pos) % 2 == 0) { n     long long cur = 0; n     for (long long i = 1; i <= n; i++) cur += dp[pos][i] * k[i]; n     ans = max(ans, cur); n     if (pos == u) return; n   } n   if (!lst) { n     for (long long i = 1; i <= n; i++) dp[pos + 1][i] = dp[pos][i] ^ b[i]; n     go(pos + 1, 1); n   } n   for (long long i = 1; i <= n; i++) dp[pos + 1][i] = dp[pos][p[i]] + r; n   go(pos + 1, 0); n } n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n >> u >> r; n   for (long long i = 1; i <= n; i++) cin >> a[i], dp[0][i] = a[i]; n   for (long long i = 1; i <= n; i++) cin >> b[i]; n   for (long long i = 1; i <= n; i++) cin >> k[i]; n   for (long long i = 1; i <= n; i++) cin >> p[i]; n   go(0, 0); n   cout << ans; n   return 0; n } n


#include <iostream> n #include <algorithm> n #define int long long n using namespace std; n void solve () { n  int a, b, c, d; n  cin >> a >> b >> c >> d; n  int arr[4] = {a,b,c,d}; n  sort (arr, arr+4); n  int max1 = arr[4-1]; n  int max2 = arr[4-2]; n  int win1 = max (a, b); n  int win2 = max (c, d); n  if (win1 == max1 && win2 == max2){ n   cout <<  YES  <<   n ; n   return; n  } n  if (win1 == max2 && win2 == max1){ n   cout <<  YES  <<   n ; n   return; n  } n  cout <<  NO  <<   n ; n } n signed main () { n  ios_base::sync_with_stdio (0);cin.tie (0); n  int t; cin >> t; n  while (t--) { n   solve (); n  }  n }


#include <bits/stdc++.h> n using namespace std; n long long int MOD = 1e9 + 7; n long long int prime[10000000]; n long long int fac[200100], ifac[200100]; n long long int inv[200100]; n vector<long long int> primes; n long long int gcd(long long int a, long long int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n bool IsPrime(long long int x) { n   if (x == 1) return false; n   for (long long int i = 2; i * i <= x; i++) { n     if (x % i == 0) return false; n   } n   return true; n } n void seive(long long int n) { n   prime[0] = prime[1] = 1; n   for (long long int i = 2; i * i <= n; i++) n     if (!prime[i]) { n       primes.push_back(i); n       for (long long int j = i * i; j <= 1e6; j += i) prime[j] = 1; n     } n } n bool sortMa7boub(const pair<long double, int>& a, n                  const pair<long double, int>& b) { n   if (a.first == b.first) return (a.second < b.second); n   return (a.first > b.first); n } n bool IsVowel(char c) { n   return (c ==  a  || c ==  e  || c ==  i  || c ==  u  || c ==  o  || n           c ==  y  || c ==  A  || c ==  E  || c ==  I  || c ==  U  || n           c ==  O  || c ==  Y ); n } n bool IsEqual(string s1, string s2) { n   if (s1.length() != s2.length()) return 0; n   for (int i = 0; i < s1.length(); i++) n     if (s1[i] != s2[i]) return 0; n   return 1; n } n long long int powMod(long long int base, long long int pw) { n   long long int ret = 1; n   while (pw) { n     if (pw & 1) ret = (ret * base) % MOD; n     base = (base * base) % MOD; n     pw >>= 1; n   } n   return ret; n } n void makeFact() { n   fac[0] = ifac[0] = 1; n   for (long long int i = 1; i < 200100; i++) { n     fac[i] = (fac[i - 1] * i) % MOD; n     ifac[i] = powMod(fac[i], MOD - 2); n   } n } n inline void Init() { n   inv[1] = 1; n   for (int i = 2; i < 200100; ++i) n     inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD; n } n long long int C(long long int a, long long int b) { n   if (a < b) return 0; n   return (((fac[a] * ifac[b]) % MOD) * ifac[a - b]) % MOD; n } n long long int P(long long int a, long long int b) { n   if (a < b) return 0; n   return (fac[a] * ifac[a - b]) % MOD; n } n long long int sum(long long int k) { return (k % MOD) * ((k + 1) % MOD) / 2; } n long long int pascalDivisibility(long long int n, long long int p) { n   long long int ans = 1; n   long long int i = 0; n   while (n) { n     ans = (sum(n % p) % MOD) * (powMod(sum(p), i) % MOD) + n           ((n % p + 1) % MOD) * (ans % MOD); n     ans %= MOD; n     n /= p; n     i++; n   } n   return ans % MOD; n } n bool PointInRectangle(long double x1, long double y1, long double x2, n                       long double y2, long double x, long double y) { n   return (x >= x1 && x <= x2 && y >= y1 && y <= y2); n } n bool InRange(long long int a, long long int b, long long int c) { n   return a >= b && a <= c; n } n string AL =  ABCDEFGHIJKLMNOPQRSTUVWXYZ ; n long long int arr[200100]; n long long int level[200100]; n vector<long long int> rang; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int n, k, x, mx(0), mn(2 * 1e18); n   cin >> n >> k; n   set<long long int> ss; n   for (int i = 0; i < n; i++) n     cin >> x, arr[x]++, mx = max(mx, x), mn = min(mn, x); n   long long int sum = 0; n   for (int i = 200100 - 1; i > 0; i--) { n     sum += arr[i]; n   } n   long long int cnt(0); n   long long int sumi = 0; n   for (long long int i = mx; i > mn; i--) { n     sumi += arr[i]; n     level[i] = sumi; n   } n   for (long long int i = mx; i > mn;) { n     long long int sumo = 0; n     while (sumo < k) { n       sumo += level[i]; n       i--; n     } n     if (sumo > k) i++; n     cnt++; n   } n   cout << cnt << endl; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int c[25]; n bool vis[25]; n int n, m; n bool dfs(int p, int s, int k) { n   if (p > n) return m == n - 1; n   if (!k) return dfs(p + 1, p, c[p + 1]); n   for (; s; s--) n     if (!vis[s] && c[s] + 1 < c[p] && c[s] + 1 <= k) { n       vis[s] = true; n       k -= c[s] + 1; n       m++; n       if (dfs(p, s - 1, k)) return true; n       vis[s] = false; n       k += c[s] + 1; n       m--; n     } n   return false; n } n int main() { n   while (~scanf( %d , &n)) { n     for (int i = 1; i <= n; ++i) { n       scanf( %d , &c[i]); n       c[i]--; n     } n     sort(c + 1, c + 1 + n); n     memset(vis, false, sizeof(vis)); n     m = 0; n     puts(dfs(1, 0, c[1]) ?  YES  :  NO ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s; n class SegmentTree { n   struct data { n     int ans; n     int opened; n     int closed; n   }; n  n  public: n   data merge(data A, data B) { n     int extra = min(A.opened, B.closed); n     return data{A.ans + B.ans + extra, A.opened + B.opened - extra, n                 A.closed + B.closed - extra}; n   } n   data leafNodeValue(int index) { n     if (s[index] ==  ( ) n       return data{0, 1, 0}; n     else n       return data{0, 0, 1}; n   } n   void updateNode(data& node, int& value, int& start, int& end) {} n   void updateLazy(int& child, int& parent) {} n   data outOfRange; n   int defaultLazyValue; n   void setDefaultAndOutOfRange() { outOfRange = {0, 0, 0}; } n   SegmentTree(int n) { n     setDefaultAndOutOfRange(); n     size = n; n     tree = new data[n << 3]; n     lazy = new int[n << 3]; n     build(1, 0, size - 1); n   } n   void update(int start, int end, int value) { n     update(1, 0, size - 1, start, end, value); n   } n   data query(int start, int end) { return query(1, 0, size - 1, start, end); } n  n  private: n   void build(int node, int start, int end) { n     int into2 = node << 1, mid = (start + end) / 2; n     if (start == end) { n       tree[node] = leafNodeValue(start); n       lazy[node] = defaultLazyValue; n     } else { n       build(into2, start, mid), build(into2 + 1, mid + 1, end); n       lazy[node] = defaultLazyValue; n       tree[node] = merge(tree[into2], tree[into2 + 1]); n     } n   } n   void push(int node, int start, int end) { n     return; n     if (lazy[node] != defaultLazyValue) { n       updateNode(tree[node], lazy[node], start, end); n       if (start != end) { n         updateLazy(lazy[node + node], lazy[node]); n         updateLazy(lazy[node + node + 1], lazy[node]); n       } n       lazy[node] = defaultLazyValue; n     } n   } n   void update(int node, int start, int end, int rangestart, int rangeend, n               int value) { n     return; n     int into2 = node << 1, mid = (start + end) / 2; n     push(node, start, end); n     if (start > end || start > rangeend || end < rangestart) return; n     if (rangestart <= start && end <= rangeend) { n       updateNode(tree[node], value, start, end); n       if (start != end) { n         updateLazy(lazy[into2 + 1], value); n         updateLazy(lazy[into2], value); n       } n       return; n     } n     update(into2, start, mid, rangestart, rangeend, value), n         update(into2 + 1, mid + 1, end, rangestart, rangeend, value); n     tree[node] = merge(tree[into2], tree[into2 + 1]); n   } n   data query(int node, int start, int end, int rangestart, int rangeend) { n     int into2 = node << 1, mid = (start + end) / 2; n     if (start > end || start > rangeend || end < rangestart) return outOfRange; n     push(node, start, end); n     if (rangestart <= start && end <= rangeend) return tree[node]; n     return merge(query(into2, start, mid, rangestart, rangeend), n                  query(into2 + 1, mid + 1, end, rangestart, rangeend)); n   } n   long long int size; n   data* tree; n   int* lazy; n }; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   ; n   cin >> s; n   SegmentTree S(s.size()); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     int l, r; n     cin >> l >> r; n     cout << 2 * S.query(l - 1, r - 1).ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a; n   cin >> a; n   if (a > 36) { n     cout <<  -1 ; n   } else { n     while (a >= 2) { n       a -= 2; n       cout <<  8 ; n     } n     if (a == 1) { n       cout <<  4 ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string s; n   getline(cin, s); n   for (int i = 0; i < n; i++) { n     getline(cin, s); n     if (s.length() >= 5) { n       if ((s.substr(0, 5) ==  miao. ) && n           (s.substr(s.length() - 5, 5) !=  lala. )) n         cout <<  Rainbow s  << endl; n       else if ((s.substr(0, 5) !=  miao. ) && n                (s.substr(s.length() - 5, 5) ==  lala. )) n         cout <<  Freda s  << endl; n       else n         cout <<  OMG>.< I don t know!  << endl; n     } else n       cout <<  OMG>.< I don t know!  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1010; n char mtr[MAXN][MAXN]; n int main() { n   int n, m; n   cin >> n >> m; n   set<int> s; n   bool ok = true; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       cin >> mtr[i][j]; n     } n   } n   for (int i = 1; i <= n; i++) { n     int gnomo, doce; n     for (int j = 1; j <= m; j++) { n       if (mtr[i][j] ==  G ) gnomo = j; n       if (mtr[i][j] ==  S ) doce = j; n     } n     int r = doce - gnomo; n     if (r > 0) n       s.insert(r); n     else n       ok = false; n   } n   if (ok == false) { n     cout <<  -1  << endl; n     return 0; n   } n   cout << s.size() << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string a; n   int count = 0, c = 0; n   cin >> a; n   count = a.size(); n   for (int i = 0; a[i] !=   0 ; i++) { n     if (a[i] >=  A  && a[i] <=  Z ) c++; n   } n   if ((c == count) || ((c == count - 1) && (a[0] >=  a  && a[0] <=  z ))) { n     for (int i = 0; a[i] !=   0 ; i++) { n       if (a[i] >=  A  && a[i] <=  Z ) n         a[i] = a[i] + 32; n       else n         a[i] = a[i] - 32; n     } n   } n   for (int i = 0; a[i] !=   0 ; i++) { n     cout << a[i]; n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void chmin(T &x, const T &y) { n   if (x > y) x = y; n } n template <typename T> n void chmax(T &x, const T &y) { n   if (x < y) x = y; n } n char readc() { n   char c; n   while ((c = getchar()) <  - ) n     ; n   return c; n } n int read() { n   char c; n   while ((c = getchar()) <  - ) n     ; n   if (c ==  - ) { n     int x = (c = getchar()) -  0 ; n     while ((c = getchar()) >=  0 ) x = x * 10 + c -  0 ; n     return -x; n   } n   int x = c -  0 ; n   while ((c = getchar()) >=  0 ) x = x * 10 + c -  0 ; n   return x; n } n const int N = 2e5 + 5; n pair<int, int> p[N]; n long long s[N]; n int main() { n   int n, a, b; n   cin >> n >> a >> b; n   for (int i = 1; i <= n; ++i) { n     p[i].first = read(); n     p[i].second = read(); n     p[i].first -= p[i].second; n   } n   sort(p + 1, p + n + 1, greater<pair<int, int> >()); n   for (int i = 1; i <= n; ++i) s[i] = s[i - 1] + max(0, p[i].first); n   for (int i = n + 1; i <= b; ++i) s[i] = s[i - 1]; n   long long ans = s[b]; n   if (b) n     for (int i = 1; i <= n; ++i) n       chmax(ans, ((i < b) ? s[b] - max(0, p[i].first) : s[b - 1]) + n                      ((long long)(p[i].first + p[i].second) << a) - n                      p[i].second); n   for (int i = 1; i <= n; ++i) ans += p[i].second; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 150000 + 10; n int len, n, h; n int a[MAXN], b[MAXN]; n int dp[1 << 20], all[1 << 20]; n inline void go(int root, int lo, int hi, int s, int e, int key) { n   if (hi < s || e < lo) return; n   if (s <= lo && hi <= e) { n     all[root] += key; n     dp[root] += key; n     return; n   } n   int mid = (lo + hi) / 2; n   go(root * 2, lo, mid, s, e, key); n   go(root * 2 + 1, mid + 1, hi, s, e, key); n   dp[root] = min(dp[root * 2], dp[root * 2 + 1]) + all[root]; n } n inline void build(int root, int lo, int hi) { n   if (lo == hi) { n     dp[root] = -lo; n     return; n   } n   int mid = (lo + hi) / 2; n   build(root * 2, lo, mid); n   build(root * 2 + 1, mid + 1, hi); n   dp[root] = -hi; n } n int main() { n   cin >> n >> len >> h; n   for (int i = 0; i < len; i++) cin >> b[i]; n   for (int i = 0; i < n; i++) cin >> a[i]; n   sort(b, b + len); n   int ret = 0; n   build(1, 0, len - 1); n   for (int i = 0; i < n; i++) { n     int poi = lower_bound(b, b + len, h - a[i]) - b; n     go(1, 0, len - 1, poi, len - 1, 1); n     if (len <= i + 1) { n       ret += (dp[1] > 0); n       poi = lower_bound(b, b + len, h - a[i - len + 1]) - b; n       go(1, 0, len - 1, poi, len - 1, -1); n     } n   } n   cout << ret << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, q, ans, top[200005 << 1]; n int find(int u) { n   if (top[u] == u) return u; n   return top[u] = find(top[u]); n } n inline void work() { n   scanf( %d %d %d , &n, &m, &q); n   for (int i = 1; i <= n + m; i++) top[i] = i; n   for (int i = 1, u, v; i <= q; i++) { n     scanf( %d %d , &u, &v); n     v = v + n; n     int fu = find(u), fv = find(v); n     if (fu == fv) continue; n     top[fu] = fv; n   } n   for (int i = 1; i <= n + m; i++) n     if (top[i] == i) ans++; n   printf( %d , ans - 1); n } n int main() { n   work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int getMin(int l, int r, char a[], char ch) { n   int count = 0; n   for (int i = l; i <= r; i++) { n     if (a[i] != ch) { n       count++; n     } n   } n   return count; n } n int findans(int l, int r, char a[], char ch) { n   if (l == r) { n     if (a[l] == ch) { n       return 0; n     } else { n       return 1; n     } n   } n   int mid = (l + r) / 2; n   return min(getMin(l, mid, a, ch) + findans(mid + 1, r, a, ch + 1), n              getMin(mid + 1, r, a, ch) + findans(l, mid, a, ch + 1)); n } n int main() { n   long long int t; n   cin >> t; n   while (t--) { n     long long int n; n     cin >> n; n     char a[n]; n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n     } n     int ans = findans(0, n - 1, a,  a ); n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n void MAIN(); n int main() { n   MAIN(); n   return 0; n } n const long long N = 5e3 + 1, mod = 1e9 + 7; n int n, m, best[N][N], len[N][N]; n char s[N][N]; n void MAIN() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; ++i) { n     scanf( %s , s[i] + 1); n     for (int j = 1; j <= m; ++j) { n       if (s[i][j] ==  1 ) { n         len[i][j] = len[i][j - 1] + 1; n       } n       ++best[j][len[i][j]]; n     } n   } n   for (int i = m - 1; i >= 1; --i) { n     for (int j = 1; j <= m; ++j) { n       best[j][i] += best[j][i + 1]; n     } n   } n   int ans = 0; n   for (int i = 1; i <= m; ++i) { n     for (int len = 1; len <= m; ++len) { n       ans = max(ans, len * best[i][len]); n     } n   } n   printf( %d , ans); n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> parent; n vector<string> names; n void parse(int par) { n   string str; n   char c; n   while (isalpha(cin.peek())) { n     cin >> c; n     str += c; n   } n   names.push_back(str); n   parent.push_back(par); n   int id = names.size() - 1; n   while (cin.peek() ==  ,  || cin.peek() ==  : ) { n     cin >> c; n     parse(id); n   } n   cin >> c; n } n int main() { n   int ans = 0; n   parse(-1); n   for (int i = 0; i < names.size(); i++) { n     int j = parent[i]; n     while (j != -1) { n       ans += (names[j] == names[i]); n       j = parent[j]; n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long sz = 1e5 + 10; n long long ara[sz], n, p; n ; n bool isValid(long long now) { n   long long ptr = 1; n   for (long long i = 1; i <= n; ++i) { n     while (ptr <= n && ara[ptr] <= now) ptr++; n     if (ptr - i >= p) return 0; n     now++; n   } n   return 1; n } n int main() { n   cin >> n >> p; n   for (long long i = 1; i <= n; ++i) scanf( %lld , &ara[i]); n   sort(ara + 1, ara + n + 1); n   long long start = 1, now = start; n   for (long long i = 1; i <= n; ++i) { n     if (now < ara[i]) { n       long long diff = ara[i] - now; n       now += diff, start += diff; n     } n     now++; n   } n   long long lo = start, hi = 1e9, stop = -1; n   while (lo <= hi) { n     long long mid = lo + hi >> 1; n     if (isValid(mid)) { n       stop = mid; n       lo = mid + 1; n     } else n       hi = mid - 1; n   } n   cout << max(0LL, stop - start + 1) <<   n ; n   for (long long i = start; i <= stop; i += 1) { n     if (i != start) printf(   ); n     printf( %lld , i); n   } n   if (stop != -1) printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n struct state { n   int n : 24; n   int c : 8; n   state const *prev; n }; n state b[128][128][128] = {}; n void print(state const &s) { n   if (s.n) { n     state const &p = *s.prev; n     print(p); n     if (p.n < s.n) printf( %c , s.c); n   } n } n int main() { n   char s1[128]; n   char s2[128]; n   char sv[128]; n   scanf( %s%s%s , s1, s2, sv); n   unsigned int n1 = strlen(s1); n   unsigned int n2 = strlen(s2); n   unsigned int nv = strlen(sv); n   unsigned int fail[128] = {}; n   for (unsigned int i = 1, j = 0; i < nv;) n     if (sv[i] == sv[j]) n       fail[i++] = 1 + j++; n     else if (0 < j) n       j = fail[j - 1]; n     else n       fail[i++] = 0; n   b[0][0][0].n = 0; n   for (unsigned int i = 1; i <= nv; ++i) b[0][0][i].n = -4200; n   for (unsigned int i = 1; i <= n1; ++i) { n     for (unsigned int j = 1; j <= n2; ++j) { n       for (unsigned int k = 0; k < nv; ++k) { n         b[i][j][k] = b[i - 1][j][k]; n         if (b[i][j][k].n < b[i][j - 1][k].n) b[i][j][k] = b[i][j - 1][k]; n       } n       if (s1[i - 1] == s2[j - 1]) { n         for (unsigned int k = 0; k < nv; ++k) { n           unsigned int v = k; n           while (1) { n             if (s1[i - 1] == sv[v]) { n               ++v; n               break; n             } n             if (0 < v) n               v = fail[v - 1]; n             else n               break; n           } n           if (b[i][j][v].n < b[i - 1][j - 1][k].n + 1) { n             b[i][j][v].n = b[i - 1][j - 1][k].n + 1; n             b[i][j][v].c = s1[i - 1]; n             b[i][j][v].prev = &b[i - 1][j - 1][k]; n           } n         } n       } n     } n   } n   unsigned int v = 0; n   for (unsigned int i = 1; i < nv; ++i) n     if (b[n1][n2][v].n < b[n1][n2][i].n) v = i; n   if (0 < b[n1][n2][v].n) { n     print(b[n1][n2][v]); n     printf(  n ); n   } else n     printf( 0 n ); n } n


#include <bits/stdc++.h> n using namespace std; n set<pair<string, string> > m; n int n, z[2000], d, k, ans; n string a[2000], b[2000], zx[2000][5]; n int main() { n   cin >> n >> d; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     cin >> b[i]; n     cin >> z[i]; n   } n   for (int i = 0; i < n; i++) n     for (int j = i + 1; j < n; j++) n       if (z[j] - z[i] <= d) { n         if (a[i] == b[j] && a[j] == b[i] && z[i] != z[j]) n           m.insert(make_pair(min(a[i], b[i]), max(a[i], b[i]))); n       } else n         break; n   cout << m.size() << endl; n   for (set<pair<string, string> >::iterator i = m.begin(); i != m.end(); i++) n     cout << i->first <<     << i->second << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int x[100111]; n int num[100111], numl; n int ans[100111]; n map<int, int> HASH; n int main() { n   int i, temp; n   scanf( %d , &n); n   memset(num, 0, sizeof(num)); n   numl = 0; n   for (i = 0; i < n; i++) { n     scanf( %d , &temp); n     if (HASH.count(temp) == 0) { n       HASH[temp] = numl; n       x[numl] = temp; n       numl++; n     } n     num[HASH[temp]]++; n   } n   sort(x, x + numl); n   ans[0] = num[HASH[x[0]]]; n   for (i = 1; i < numl; i++) { n     ans[i] = ans[i - 1] + num[HASH[x[i]]]; n   } n   int m, q; n   int left, right, mid; n   scanf( %d , &q); n   for (i = 0; i < q; i++) { n     scanf( %d , &m); n     left = 0; n     right = numl - 1; n     while (left <= right) { n       mid = (left + right) / 2; n       if (x[mid] == m || n           (x[mid - 1] < m && x[mid + 1] > m && mid + 1 < numl && mid - 1 >= 0)) n         break; n       if (x[mid] > m) n         right = mid - 1; n       else n         left = mid + 1; n     } n     while (x[mid] > m && mid >= 0) mid--; n     while (x[mid + 1] <= m && mid + 1 < numl) mid++; n     if (mid >= 0 && mid < numl) printf( %d n , ans[mid]); n     if (mid < 0) printf( 0 n ); n     if (mid >= numl) printf( %d n , n); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void debug(int n) { printf( %d n ); } n bool cmp(pair<int, pair<int, int> > &a, pair<int, pair<int, int> > &b) { n   if (a.second.first == b.second.first) { n     return a.first < b.first; n   } n   return a.second.first < b.second.first; n } n int main() { n   int n, u, v, kase; n   scanf( %d , &kase); n   while (kase--) { n     scanf( %d , &n); n     vector<pair<int, pair<int, int> > > q; n     for (int i = 0; i < n; i++) { n       scanf( %d%d , &u, &v); n       q.push_back(make_pair(i, make_pair(u, v))); n     } n     sort(q.begin(), q.end(), cmp); n     vector<int> idx; n     int time = 0; n     for (int i = 0; i < n; i++) { n       time = max(time, q[i].second.first); n       if (time > q[i].second.second) { n         idx.push_back(0); n       } else { n         idx.push_back(time); n         time++; n       } n     } n     for (auto i : idx) printf( %d  , i); n     printf(  n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n const int INF = 2e9; n const long long INFLL = 1e18; n const int MAX_N = 100000; n vector<int> gp[MAX_N + 1]; n int N; n int p[MAX_N + 1]; n int cnt[MAX_N + 1]; n int lv[MAX_N + 1]; n void dfs(int x) { n   cnt[lv[x]]++; n   for (int i : gp[x]) { n     lv[i] = lv[x] + 1; n     dfs(i); n   } n } n int main() { n   scanf( %d , &N); n   for (int i = 2; i <= N; i++) { n     scanf( %d , &p[i]); n     gp[p[i]].push_back(i); n   } n   lv[1] = 1; n   dfs(1); n   int ans = 0; n   for (int i = 1; i <= N; i++) { n     ans += (cnt[i] % 2); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100002; n const int logN = 22; n vector<int> c; n map<int, int> m; n void solve() { n   int n; n   cin >> n; n   while (n--) { n     int x; n     cin >> x; n     m[x]++; n   } n   int ans = 0; n   for (const pair<int, int> &x : m) { n     bool f = false; n     for (const int &y : c) { n       if (y == x.first) { n         if (x.second >= 2) { n           f = true; n           break; n         } n         continue; n       } n       if (y != 2 * x.first && m.find(y - x.first) != m.end()) { n         f = true; n         break; n       } n     } n     if (!f) { n       ans += x.second; n     } n   } n   cout << ans << endl; n } n int main() { n   int t = 1; n   for (int i = 0; i <= 31; i++) { n     c.push_back(1 << i); n   } n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000050; n int go[N][2], a[N], b[N], n, i, j, p, sz[N], tsz; n long long k, x[N]; n int main() { n   scanf( %i %lld , &n, &k); n   for (i = 2; i <= n; i++) scanf( %i %lld , &p, &x[i]), x[i] ^= x[p]; n   for (i = 1; i <= n; i++) a[i] = b[i] = 1; n   long long ans = 0; n   for (j = 61; ~j; j--) { n     for (i = 1; i <= tsz; i++) go[i][0] = go[i][1] = sz[i] = 0; n     tsz = 0; n     for (i = 1; i <= n; i++) { n       int g = (x[i] >> j) & 1; n       if (!go[a[i]][g]) go[a[i]][g] = ++tsz; n       sz[a[i] = go[a[i]][g]]++; n     } n     long long sum = 0; n     for (i = 1; i <= n; i++) { n       int g = (x[i] >> j) & 1; n       sum += sz[go[b[i]][g]]; n     } n     if (sum < k) { n       ans += (long long)1 << j; n       k -= sum; n       for (i = 1; i <= n; i++) { n         int g = (x[i] >> j) & 1; n         b[i] = go[b[i]][g ^ 1]; n       } n     } else { n       for (i = 1; i <= n; i++) { n         int g = (x[i] >> j) & 1; n         b[i] = go[b[i]][g]; n       } n     } n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, p; n long long A[5001]; n long long a[5001]; n long long l[1000005]; n long long dp[2][5001]; n long long s[5001][5001]; n void work(long long *prev, long long *nxt) { n   long long total = 0, prev_total = 1; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= min(l[i], m); j++) { n       nxt[j] = (s[l[i]][j] * A[j] % p) * prev_total % p; n       if (j <= l[i - 1]) n         nxt[j] = (nxt[j] - ((prev[j] * a[j] % p) * s[l[i]][j]) % p + p) % p; n       total = (total + nxt[j]) % p; n     } n     swap(nxt, prev); n     memset(nxt, 0, sizeof(long long) * 5000); n     prev_total = total; n     total = 0; n   } n   printf( %I64d n , prev_total); n } n int main() { n   scanf( %I64d %I64d %I64d , &n, &m, &p); n   for (int i = 1; i <= n; i++) { n     scanf( %I64d , &l[i]); n   } n   a[0] = 1; n   A[0] = 1; n   for (int i = 1; i <= 5000; i++) { n     A[i] = A[i - 1] * (m - i + 1) % p; n     a[i] = a[i - 1] * i % p; n   } n   s[0][0] = 1; n   for (int i = 1; i <= 5000; i++) n     for (int j = 1; j <= i; j++) { n       s[i][j] = (s[i - 1][j - 1] + s[i - 1][j] * (j - 1) % p) % p; n     } n   work(dp[0], dp[1]); n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 100005, LOG = 25; n long long n, f[N][LOG + 5], cnt = 0, head[N], dep[N]; n long long size[N]; n struct CLANNAD { n   long long to, nxt; n } a[N << 1]; n inline void add(long long u, long long v) { n   a[++cnt].to = v; n   a[cnt].nxt = head[u]; n   head[u] = cnt; n } n inline long long getnode(long long x, long long deep) { n   for (long long i = LOG; i >= 0; i--) n     if (dep[f[x][i]] >= deep) x = f[x][i]; n   return x; n } n inline long long LCA(long long x, long long y) { n   if (dep[x] < dep[y]) swap(x, y); n   long long ox = x, oy = y; n   for (long long i = LOG; i >= 0; i--) n     if (dep[f[x][i]] >= dep[y]) x = f[x][i]; n   long long lca; n   if (x == y) n     lca = x; n   else { n     for (long long i = LOG; i >= 0; i--) n       if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i]; n     lca = f[x][0]; n   } n   long long dis = dep[ox] + dep[oy] - dep[lca] * 2; n   if (dis & 1) n     return 0; n   else if (oy == lca) { n     long long mid = (dep[ox] + dep[oy]) >> 1; n     return size[getnode(ox, mid)] - size[getnode(ox, mid + 1)]; n   } else if (dep[ox] != dep[oy]) { n     long long mid = dep[ox] - dis / 2; n     return size[getnode(ox, mid)] - size[getnode(ox, mid + 1)]; n   } else n     return n - size[getnode(ox, dep[lca] + 1)] - n            size[getnode(oy, dep[lca] + 1)]; n } n void dfs(long long x, long long fx) { n   size[x] = 1; n   dep[x] = dep[fx] + 1; n   f[x][0] = fx; n   for (long long i = 1; i <= LOG; i++) f[x][i] = f[f[x][i - 1]][i - 1]; n   for (long long i = head[x]; i; i = a[i].nxt) n     if (a[i].to != fx) dfs(a[i].to, x), size[x] += size[a[i].to]; n } n signed main() { n   cin >> n; n   long long u, v; n   for (long long i = 1; i <= n - 1; i++) n     scanf( %lld%lld , &u, &v), add(u, v), add(v, u); n   dfs(1, 0); n   long long T, x, y; n   cin >> T; n   while (T--) { n     scanf( %lld%lld , &x, &y); n     if (x == y) n       printf( %lld n , n); n     else n       printf( %lld n , LCA(x, y)); n   } n   return 0; n } n


#include <bits/stdc++.h> n const int N = 50005; n char s[N]; n int main() { n   scanf( %s , s); n   int i, j, n = strlen(s); n   for (j = 1; j <= n / 2; j++) { n     int t = 0, cnt = 0; n     for (i = 0; i + j < n; i++) { n       s[t++] = s[i]; n       if (s[i] == s[i + j]) n         cnt++; n       else n         cnt = 0; n       if (cnt == j) { n         t -= j; n         cnt = 0; n       } n     } n     for (; i < n; i++) s[t++] = s[i]; n     n = t; n   } n   s[n] = 0; n   puts(s); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int r; n int done = 1; n pair<int, int> tempo(int x, int y) { n   if (x >= y) { n     if (x % y == 0) { n       if (y == 1) n         return make_pair(x, x - 1); n       else n         return make_pair(1000000100, 1000000100); n     } n     pair<int, int> next = tempo(x % y, y); n     int num = x / y; n     next.first += num; n     next.second += num - 1; n     return next; n   } n   if (y % x == 0) { n     if (x == 1) { n       return make_pair(y, y - 2); n     } else n       return make_pair(1000000100, 1000000100); n   } n   pair<int, int> next = tempo(x, y % x); n   int num = y / x; n   next.first += num; n   next.second += num - 1; n   return next; n } n int main() { n   cin >> n >> r; n   if (r == 1) { n     if (n == 1) n       cout <<  0 nT ; n     else n       cout <<  IMPOSSIBLE ; n     return 0; n   } n   int minimo = 1000000100; n   int chos = 0; n   for (int i = 1; i < r; i++) { n     pair<int, int> ris = tempo(i, r - i); n     if (ris.first == n - 1 and ris.second < minimo) { n       minimo = ris.second; n       chos = i; n     } n   } n   if (chos == 0) { n     cout <<  IMPOSSIBLE ; n     return 0; n   } n   cout << minimo; n   cout << endl; n   vector<char> roba; n   int x = chos; n   int y = r - chos; n   while (x > 0) { n     if (x == 1 and y == 1) { n       x = 0; n       roba.push_back( T ); n     } else if (x > y) { n       roba.push_back( T ); n       x -= y; n     } else if (x < y) { n       roba.push_back( B ); n       y -= x; n     } n   } n   for (int i = int(roba.size()) - 1; i >= 0; i--) cout << roba[i]; n   if (roba[0] ==  T ) n     cout <<  B ; n   else n     cout <<  T ; n } n