#include <bits/stdc++.h> n using namespace std; n long long a[500005], inc[1002], n, q, d; n vector<pair<long long, long long> > v[1002]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(), cout.tie(); n   cin >> n >> q; n   d = sqrt(n); n   long long cnt = 1; n   for (int i = 1; i <= n; i++) { n     long long x; n     cin >> x; n     v[cnt].push_back({x, i}); n     if (i % d == 0) { n       sort(v[cnt].begin(), v[cnt].end()); n       cnt++; n     } n   } n   sort(v[cnt].begin(), v[cnt].end()); n   while (q--) { n     long long t, l, r, x; n     cin >> t; n     if (t == 1) { n       cin >> l >> r >> x; n       long long lower = ceil(l / (double)d); n       long long upper = ceil(r / (double)d); n       for (int i = 0; i < v[lower].size(); i++) { n         if (v[lower][i].second >= l && v[lower][i].second <= r) n           v[lower][i].first += x; n       } n       sort(v[lower].begin(), v[lower].end()); n       if (upper != lower) { n         for (int i = 0; i < v[upper].size(); i++) { n           if (v[upper][i].second >= l && v[upper][i].second <= r) n             v[upper][i].first += x; n         } n         sort(v[upper].begin(), v[upper].end()); n       } n       for (int i = lower + 1; i < upper; i++) inc[i] += x; n     } else { n       cin >> x; n       long long l = 1e18, r = -1e18; n       for (int i = 1; i <= cnt; i++) { n         x -= inc[i]; n         if (v[i].size() == 0) continue; n         long long lo = 0, hi = v[i].size() - 1; n         while (lo <= hi) { n           long long mid = (lo + hi) / 2; n           if (v[i][mid].first == x) { n             l = min(l, v[i][mid].second); n             hi = mid - 1; n           } else if (v[i][mid].first > x) n             hi = mid - 1; n           else n             lo = mid + 1; n         } n         lo = 0, hi = v[i].size() - 1; n         while (lo <= hi) { n           long long mid = (lo + hi) / 2; n           if (v[i][mid].first == x) { n             r = max(r, v[i][mid].second); n             lo = mid + 1; n           } else if (v[i][mid].first > x) n             hi = mid - 1; n           else n             lo = mid + 1; n         } n         x += inc[i]; n       } n       if (l == 1e18) n         cout << -1 << endl; n       else n         cout << r - l << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void UpdateMax(T& a, T b) { n   if (a < b) a = b; n } n template <typename T> n void UpdateMin(T& a, T b) { n   if (a > b) a = b; n } n template <typename T> n inline void read(T& x) { n   x = 0; n   char c = getchar(); n   int flag = 1; n   while (!isdigit(c)) { n     if (c ==  - ) flag = -1; n     c = getchar(); n   } n   while (isdigit(c)) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   x *= flag; n } n template <typename T> n void Unique(vector<T>& vec) { n   sort(vec.begin(), vec.end()); n   vec.erase(unique(vec.begin(), vec.end()), vec.end()); n } n template <typename T> n void Relabel(vector<T>& vec, T& value) { n   value = lower_bound(vec.begin(), vec.end(), value) - vec.begin() + 1; n } n template <typename T, typename V> n void Print(const pair<T, V>& x) { n   cout << x.first <<   @   << x.second <<   |  ; n } n template <typename T> n void Print(const T& x) { n   cout << x <<    ; n } n template <typename T> n void Pcon(const T& x) { n   cout <<   nsize:   << x.size() << endl; n   for (const auto& item : x) Print(item); n } n std::vector<int> LABS; n template <typename T> n void Print(const T* x, int offset, int loop) { n   for (int i = 0; i <= loop; i++) { n     cout <<  [ ; n     for (int item : LABS) cout << item - offset <<  , ; n     cout << i - offset <<  ]: ; n     cout << x[i] <<    ; n   } n } n template <typename T, typename... Args> n void Print(const T* f, int offset, int loop, Args... args) { n   for (int i = 0; i <= loop; i++) { n     LABS.push_back(i); n     Print(f[i], offset, args...); n     cout << endl; n     LABS.pop_back(); n   } n } n template <typename T, typename V> n bool Has(T& cluster, const V& item) { n   return cluster.find(item) != cluster.end(); n } n int Logn(long long x) { n   int cnt = 0; n   while (x) { n     ++cnt; n     x >>= 1; n   } n   return cnt; n } n const int MOD = 1e9 + 7; n const int N = 2e5 + 5; n const int dir[4][2] = {{-1, 0}, {0, -1}, {1, 0}, {1, 0}}; n struct Edg { n   int x, y, z; n   friend bool operator<(const Edg& lhs, const Edg& rhs) { n     return lhs.z < rhs.z; n   } n } edg[N]; n bool vis[N], used[N]; n clock_t start_time; n int t, n, m; n int f[N], a[N]; n vector<int> G[N]; n inline void SetClock() { start_time = clock(); } n bool TimeOut(size_t ms) { n   if (1000 * (clock() - start_time) >= ms * ((clock_t)1000)) return true; n   return false; n } n inline pair<int, int> DeSerialize(int c) { return {(c) / m, (c) % m}; } n template <typename T, typename V> n inline void Add(T& v, const V& delta) { n   v += delta; n   if (v >= MOD) v -= MOD; n } n template <typename T, typename V> n inline void Dec(T& v, const V& delta) { n   v -= delta; n   if (v < 0) v += MOD; n } n long long ksm(long long a, long long b) { n   long long cnt = 1; n   while (b) { n     if (b & 1) cnt = cnt * a % MOD; n     b >>= 1; n     a = a * a % MOD; n   } n   return cnt; n } n int main() { n   srand(time(0)); n   SetClock(); n   cin.sync_with_stdio(false); n   cin >> n; n   for (int(i) = 1; (i) <= (n); ++(i)) { n     cin >> a[i]; n     ++f[a[i]]; n   } n   for (int(i) = 1; (i) <= (100000); ++(i)) { n     f[i] += f[i - 1]; n   } n   long long ans = 0; n   for (int p = 100000; p >= 1; --p) { n     vector<int> facs; n     for (int i = 1; i * i <= p; ++i) { n       if (p % i == 0) { n         facs.emplace_back(i); n         if (i * i != p) { n           facs.emplace_back(p / i); n         } n       } n     } n     sort(facs.begin(), facs.end()); n     long long tmp = 1, tmp2 = 1; n     for (size_t i = 0; i < facs.size(); ++i) { n       long long t = i == facs.size() - 1 ? n - f[facs[i] - 1] n                                          : f[facs[i + 1] - 1] - f[facs[i] - 1]; n       if (i == facs.size() - 1) { n         tmp2 = (tmp * ksm(i, t)) % MOD; n       } n       tmp = (tmp * ksm(i + 1, t)) % MOD; n     } n     Dec(tmp, tmp2); n     Add(ans, tmp); n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n void enter(vector<long long int> &ar) { n   long long int n = ar.size(); n   for (long long int i = 0; i < n; i++) { n     cin >> ar[i]; n   } n } n void show(vector<long long int> &a) { n   long long int n = a.size(); n   for (long long int i = 0; i < n; i++) { n     cout << a[i] <<    ; n   } n   cout <<   n ; n } n void SieveOfEratosthenes(int n, vector<long long int> &pri) { n   vector<bool> prime(n + 1, true); n   for (int p = 2; p * p <= n; p++) { n     if (prime[p] == true) { n       pri.push_back(p); n       for (int i = p * p; i <= n; i += p) prime[i] = false; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int t; n   cin >> t; n   while (t--) { n     long long int n, k; n     cin >> n >> k; n     string s; n     cin >> ws; n     cin >> s; n     cin >> ws; n     vector<long long int> a(n); n     for (long long int i = 0; i < n; i++) { n       a[i] = s[i] -  0 ; n     } n     vector<long long int> sum(n, 0); n     sum[0] = a[0]; n     for (long long int i = 1; i < n; i++) { n       sum[i] = sum[i - 1] + a[i]; n     } n     vector<long long int> dp(n); n     for (long long int i = n - 1; i >= 0; i--) { n       long long int add_one = a[i]; n       if (i + k <= n - 1) { n         dp[i] = min(dp[i + k] + ((a[i] == 1) ? 0 : 1) + sum[i + k - 1] - sum[i], n                     ((a[i] == 1) ? 1 : 0) + sum[n - 1] - sum[i]); n       } else { n         dp[i] = min(((a[i] == 1) ? 0 : 1) + sum[n - 1] - sum[i], n                     ((a[i] == 1) ? 1 : 0) + sum[n - 1] - sum[i]); n       } n     } n     long long int ans; n     for (long long int i = 0; i < n; i++) { n       if (i) { n         dp[i] += sum[i - 1]; n         ans = min(ans, dp[i]); n       } else { n         ans = dp[i]; n       } n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char c[110][110][110]; n bool a[110][110][110]; n bool b[110][110][110]; n int main() { n   int n, m, k; n   cin >> n >> m >> k; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) scanf( %s , c[i][j]); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) n       for (int s = 0; s < k; s++) n         if (c[i][j][s] ==  1 ) a[i + 1][j + 1][s + 1] = true; n   int di[3] = {1, 0, 0}; n   int dj[3] = {0, 1, 0}; n   int ds[3] = {0, 0, 1}; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       for (int s = 1; s <= k; s++) { n         if (!a[i][j][s]) continue; n         for (int p = 0; p < 3; p++) { n           if (a[i + di[p]][j + dj[p]][s + ds[p]] && n               a[i - di[p]][j - dj[p]][s - ds[p]]) { n             b[i][j][s] = true; n           } n         } n         for (int p = 0; p < 3; p++) n           for (int l = 0; l < 3; l++) n             if (a[i - di[p]][j - dj[p]][s - ds[p]] && n                 a[i + di[l]][j + dj[l]][s + ds[l]] && n                 !a[i - di[p] + di[l]][j - dj[p] + dj[l]][s - ds[p] + ds[l]]) { n               b[i][j][s] = true; n             } n       } n   int answ = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       for (int s = 1; s <= k; s++) { n         if (b[i][j][s]) answ++; n       } n     } n   } n   cout << answ << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline void read(int &x) { n   register char c = getchar(); n   x = 0; n   for (; c <  0  || c >  9 ; c = getchar()) n     ; n   for (; c >=  0  && c <=  9 ; c = getchar()) x = (x << 1) + (x << 3) + c -  0 ; n } n priority_queue<int> q; n int main() { n   priority_queue<int> pq; n   int n, a, b, c, d; n   long long z = 0; n   read(n); n   while (n--) { n     read(a); n     read(b); n     read(c); n     read(d); n     if (a + b < c + d) n       z += max(0, a - d) - max(0, b - c); n     else { n       z += a + c; n       q.push(a + b); n       q.push(c + d); n     } n   } n   while (!q.empty()) { n     q.pop(); n     z -= q.top(); n     q.pop(); n   } n   printf( %I64d , z); n } n


#include <bits/stdc++.h> n using namespace std; n void BFS(double, double, double &a); n double pSquares(double, double); n double n, m, k, r; n struct queue_compare { n   bool operator()(const pair<double, double> &p1, n                   const pair<double, double> &p2) const { n     return pSquares(p1.first, p1.second) < pSquares(p2.first, p2.second); n   } n } typedef pqc; n struct set_compare { n   bool operator()(const pair<double, double> &p1, n                   const pair<double, double> &p2) const { n     if (p1.first != p2.first) { n       return p1.first < p2.first; n     } else { n       return p1.second < p2.second; n     } n   } n } typedef sc; n int main() { n   cin >> n >> m >> r >> k; n   double numer = 0; n   double denom = (n - r + 1) * (m - r + 1); n   BFS(floor((m + 1) / 2), floor((n + 1) / 2), numer); n   cout << setprecision(15) << (numer / denom) << endl; n } n double pSquares(double i, double j) { n   double x, y; n   y = abs(min(j - 1, r - 1) + 1 - (r - (min(n - j, r - 1)))) + 1; n   x = abs(min(i - 1, r - 1) + 1 - (r - (min(m - i, r - 1)))) + 1; n   return x * y; n } n void BFS(double i, double j, double &numerator) { n   priority_queue<pair<double, double>, vector<pair<double, double> >, pqc> pq; n   set<pair<double, double>, sc> s; n   pair<double, double> p(i, j); n   pq.push(p); n   s.insert(p); n   for (int i = 0; i < k; i++) { n     pair<double, double> tp = pq.top(); n     pq.pop(); n     numerator += pSquares(tp.first, tp.second); n     pair<double, double> left(tp.first, tp.second - 1); n     pair<double, double> right(tp.first, tp.second + 1); n     pair<double, double> above(tp.first - 1, tp.second); n     pair<double, double> bot(tp.first + 1, tp.second); n     if (tp.second - 1 >= 1 && s.find(left) == s.end()) { n       s.insert(left); n       pq.push(left); n     } n     if (tp.first - 1 >= 1 && s.find(above) == s.end()) { n       s.insert(above); n       pq.push(above); n     } n     if (tp.first + 1 <= m && s.find(bot) == s.end()) { n       s.insert(bot); n       pq.push(bot); n     } n     if (tp.second + 1 <= n && s.find(right) == s.end()) { n       s.insert(right); n       pq.push(right); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long linf = 1e18 + 5; n const int mod = (int)1e9 + 7; n const int logN = 17; n const int inf = 1e9; n const int N = 2e5 + 5; n int temp[1 << 7][1 << 7], res[1 << 7][1 << 7], cur[1 << 7][1 << 7], x; n void mul(int res[][1 << 7], int cur[][1 << 7], int t) { n   t = 1 << t; n   --t; n   memset(temp, 0, sizeof temp); n   for (int i = 0; i <= t; i++) n     for (int j = 0; j <= t; j++) n       for (int k = 0; k <= t; k++) n         temp[i][j] = n             (temp[i][j] + res[i][k] * (long long)cur[k][j] % mod) % mod; n   memcpy(res, temp, sizeof temp); n } n int main() { n   for (int i = 0; i <= (1 << 7) - 1; i++) res[i][i] = 1; n   for (int i = 1; i <= 7; i++) { n     scanf( %d , &x); n     for (int a = 0; a <= (1 << i) - 1; a++) n       for (int b = 0; b <= (1 << i) - 1; b++) { n         cur[a][b] = 0; n         for (int poke = 0; poke <= (1 << i + 1) - 1; poke++) { n           if ((poke & 1) || (poke & (1 << i))) continue; n           if ((((a | b | poke | (poke >> 1)) & ((1 << i) - 1))) == (1 << i) - 1) n             cur[a][b]++; n         } n       } n     while (x) { n       if (x & 1) mul(res, cur, i); n       x >>= 1; n       mul(cur, cur, i); n     } n   } n   cout << res[0][0] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma warning(disable : 4996) n using namespace std; n template <typename T, typename U> n pair<T, U> operator+(const pair<T, U> &l, const pair<T, U> &r) { n   return make_pair(l.first + r.first, l.second + r.second); n } n template <typename T, typename U> n pair<T, U> operator-(const pair<T, U> &l, const pair<T, U> &r) { n   return make_pair(l.first - r.first, l.second - r.second); n } n template <typename T, typename U> n pair<T, U> operator*(const pair<T, U> &l, const long long &r) { n   return make_pair(l.first * r, l.second * r); n } n template <typename T, typename U> n pair<T, U> operator*(const pair<T, U> &l, const pair<T, U> &r) { n   return make_pair(l.first * r.first, l.second * r.second); n } n template <typename T, typename U> n pair<T, U> operator%(const pair<T, U> &l, const int &r) { n   return make_pair(l.first % r, l.second % r); n } n long long n, m; n pair<long long, long long> a[6000]; n long long ccw(pair<long long, long long> x, pair<long long, long long> y, n               pair<long long, long long> z) { n   return (y.first - x.first) * (z.second - x.second) - n          (z.first - x.first) * (y.second - x.second); n } n int main() { n   int i, j, k, l; n   cin >> n >> m; n   for (i = 0; i < n; i++) scanf( %lld%lld , &a[i].first, &a[i].second); n   sort(a, a + n); n   sort(a + 1, a + n, n        [&](pair<long long, long long> x, pair<long long, long long> y) { n          if (ccw(a[0], x, y) == 0) n            return x < y; n          else n            return ccw(a[0], x, y) > 0; n        }); n   vector<pair<long long, long long> > hull; n   hull.push_back(a[0]); n   for (i = 1; i < n; i++) { n     while (hull.size() >= 2 && n            ccw(hull[hull.size() - 2], hull[hull.size() - 1], a[i]) <= 0) n       hull.pop_back(); n     hull.push_back(a[i]); n   } n   for (i = 0; i * 2 < hull.size(); i++) hull.push_back(hull[i]); n   long long ma = 0; n   pair<long long, long long> ax, ay, az; n   int u = hull.size() / 2; n   for (i = 0; i < u; i++) { n     int now = i + 1; n     for (j = i + 1; j < i + u; j++) { n       for (; now < i + u; now++) { n         if (now == i + u - 1 || ccw(hull[i], hull[j], hull[now]) > n                                     ccw(hull[i], hull[j], hull[now + 1])) n           break; n       } n       if (ma < ccw(hull[i], hull[j], hull[now])) { n         ma = ccw(hull[i], hull[j], hull[now]); n         ax = hull[i], ay = hull[j], az = hull[now]; n       } n     } n   } n   pair<long long, long long> dx, dy, dz; n   dz = ax + ay - az; n   dy = ax + az - ay; n   dx = ay + az - ax; n   printf( %lld %lld n%lld %lld n%lld %lld , dx.first, dx.second, dy.first, n          dy.second, dz.first, dz.second); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n template <class t, class u> n void chmax(t& first, u second) { n   if (first < second) first = second; n } n template <class t, class u> n void chmin(t& first, u second) { n   if (second < first) first = second; n } n template <class t> n using vc = vector<t>; n template <class t> n using vvc = vc<vc<t>>; n using pi = pair<ll, ll>; n using vi = vc<ll>; n template <class t, class u> n ostream& operator<<(ostream& os, const pair<t, u>& p) { n   return os <<  {  << p.first <<  ,  << p.second <<  } ; n } n template <class t> n ostream& operator<<(ostream& os, const vc<t>& v) { n   os <<  { ; n   for (auto e : v) os << e <<  , ; n   return os <<  } ; n } n using uint = unsigned; n using ull = unsigned long long; n template <class t, size_t n> n ostream& operator<<(ostream& os, const array<t, n>& first) { n   return os << vc<t>(first.begin(), first.end()); n } n template <ll i, class T> n void print_tuple(ostream&, const T&) {} n template <ll i, class T, class H, class... Args> n void print_tuple(ostream& os, const T& t) { n   if (i) os <<  , ; n   os << get<i>(t); n   print_tuple<i + 1, T, Args...>(os, t); n } n template <class... Args> n ostream& operator<<(ostream& os, const tuple<Args...>& t) { n   os <<  { ; n   print_tuple<0, tuple<Args...>, Args...>(os, t); n   return os <<  } ; n } n template <class t> n void print(t x, ll suc = 1) { n   cout << x; n   if (suc == 1) cout <<   n ; n   if (suc == 2) cout <<    ; n } n ll read() { n   ll i; n   cin >> i; n   return i; n } n vi readvi(ll n, ll off = 0) { n   vi v(n); n   for (ll i = ll(0); i < ll(n); i++) v[i] = read() + off; n   return v; n } n template <class T> n void print(const vector<T>& v, ll suc = 1) { n   for (ll i = ll(0); i < ll(v.size()); i++) n     print(v[i], i == ll(v.size()) - 1 ? suc : 2); n } n string readString() { n   string s; n   cin >> s; n   return s; n } n template <class T> n T sq(const T& t) { n   return t * t; n } n void yes(bool ex = true) { n   cout <<  Yes  n        <<   n ; n   if (ex) exit(0); n } n void no(bool ex = true) { n   cout <<  No  n        <<   n ; n   if (ex) exit(0); n } n void possible(bool ex = true) { n   cout <<  Possible  n        <<   n ; n   if (ex) exit(0); n } n void impossible(bool ex = true) { n   cout <<  Impossible  n        <<   n ; n   if (ex) exit(0); n } n constexpr ll ten(ll n) { return n == 0 ? 1 : ten(n - 1) * 10; } n const ll infLL = LLONG_MAX / 3; n const ll inf = infLL; n ll topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); } n ll topbit(ll t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); } n ll botbit(signed first) { return first == 0 ? 32 : __builtin_ctz(first); } n ll botbit(ll first) { return first == 0 ? 64 : __builtin_ctzll(first); } n ll popcount(signed t) { return __builtin_popcount(t); } n ll popcount(ll t) { return __builtin_popcountll(t); } n bool ispow2(ll i) { return i && (i & -i) == i; } n ll mask(ll i) { return (ll(1) << i) - 1; } n bool inc(ll first, ll second, ll c) { return first <= second && second <= c; } n template <class t> n void mkuni(vc<t>& v) { n   sort(v.begin(), v.end()); n   v.erase(unique(v.begin(), v.end()), v.end()); n } n ll rand_int(ll l, ll r) { n   static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count()); n   return uniform_int_distribution<ll>(l, r)(gen); n } n template <class t> n void myshuffle(vc<t>& first) { n   for (ll i = ll(0); i < ll(ll(first.size())); i++) n     swap(first[i], first[rand_int(0, i)]); n } n template <class t> n ll lwb(const vc<t>& v, const t& first) { n   return lower_bound(v.begin(), v.end(), first) - v.begin(); n } n signed main() { n   cin.tie(0); n   ios::sync_with_stdio(0); n   cout << fixed << setprecision(20); n   ll n, m; n   cin >> n >> m; n   ll q; n   cin >> q; n   string vt[2], hr[2]; n   for (ll i = ll(0); i < ll(2); i++) cin >> vt[i]; n   for (ll i = ll(0); i < ll(2); i++) cin >> hr[i]; n   ll ans = inf; n   for (ll _ = ll(0); _ < ll(2); _++) { n     ll dp[2]; n     for (ll i = ll(0); i < ll(m); i++) { n       ll nx[2]{0, 0}; n       if (i == 0) { n         nx[0] = count(vt[0].begin(), vt[0].end(),  B ); n         nx[1] = count(vt[0].begin(), vt[0].end(),  R ); n       } else { n         for (ll j = ll(0); j < ll(2); j++) { n           nx[j] = inf; n           for (ll k = ll(0); k < ll(2); k++) { n             chmin(nx[j], dp[k] + abs(j - k) * n); n           } n         } n       } n       for (ll j = ll(0); j < ll(2); j++) n         if (hr[j][i] ==  R ) n           nx[1]++; n         else n           nx[0]++; n       swap(dp, nx); n     } n     dp[0] += count(vt[1].begin(), vt[1].end(),  B ); n     dp[1] += count(vt[1].begin(), vt[1].end(),  R ); n     chmin(ans, dp[0]); n     chmin(ans, dp[1]); n     swap(n, m); n     for (ll i = ll(0); i < ll(2); i++) swap(vt[i], hr[i]); n   } n   print(ans); n } n


#include <bits/stdc++.h> n using namespace std; n void bogo(vector<int>& a) { n   for (int i = 0; i < a.size() - 1; i++) { n     int biggest = i; n     for (int j = i + 1; j < a.size(); j++) n       if (a[biggest] < a[j]) biggest = j; n     if (biggest != i) swap(a[i], a[biggest]); n   } n } n int main(int argc, char** argv) { n   int t = 0; n   cin >> t; n   for (int i = 0; i < t; i++) { n     int n = 0; n     cin >> n; n     vector<int> a; n     for (int j = 0; j < n; j++) { n       int v = 0; n       cin >> v; n       a.push_back(v); n     } n     bogo(a); n     for (auto v : a) cout << v <<    ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int N = 52, M = 106, INF = 2000000000; n inline int f(char c) { n   if ( a  <= c && c <=  z ) return c -  a  + 1; n   return c -  A  + 27; n } n inline char rf(int i) { n   if (i <= 26) return  a  + i - 1; n   return  A  + i - 27; n } n struct edge { n   int capacity, cost, flow; n   edge() {} n   edge(int capacity, int cost, int flow) n       : capacity(capacity), cost(cost), flow(flow) {} n }; n edge g[M][M]; n int cnt[N + 1][N + 1]; n std::vector<int> d(M); n std::vector<std::pair<int, int>> G; n void add_edge(int a, int b, int cap, int cost) { n   g[a][b] = edge(cap, cost, 0); n   g[b][a] = edge(0, -cost, 0); n   G.emplace_back(std::make_pair(a, b)); n   G.emplace_back(std::make_pair(b, a)); n } n class comp { n  public: n   bool operator()(int a, int b) { n     if (d[a] != d[b]) n       return d[a] > d[b]; n     else n       return a > b; n   } n }; n int main() { n   std::ios_base::sync_with_stdio(0); n   int n, k; n   std::string s, t; n   std::cin >> n >> k; n   std::cin >> s >> t; n   for (int i = 0; i < n; ++i) ++cnt[f(s[i])][f(t[i])]; n   for (int i = 1; i <= k; ++i) { n     add_edge(0, i, 1, 0); n     add_edge(i + N, 105, 1, 0); n     for (int j = 1; j <= k; ++j) add_edge(i, j + N, 1, cnt[i][j]); n   } n   int flow = 0, cost = 0; n   while (flow < k) { n     std::vector<int> p(M, -1); n     d.assign(M, -INF); n     d[0] = 0; n     bool kek = true; n     while (kek) { n       kek = false; n       for (int i = 0, a, b, curcap; i < G.size(); ++i) { n         a = G[i].first; n         b = G[i].second; n         curcap = g[a][b].capacity - g[a][b].flow; n         if (curcap > 0 && d[a] != -INF && d[b] < d[a] + g[a][b].cost) { n           d[b] = d[a] + g[a][b].cost; n           p[b] = a; n           kek = true; n         } n       } n     } n     cost += d[M - 1]; n     ++flow; n     int cur = M - 1; n     while (p[cur] != -1) { n       g[p[cur]][cur].flow++; n       g[cur][p[cur]].flow--; n       cur = p[cur]; n     } n   } n   std::cout << cost <<   n ; n   for (int i = 1; i <= N; ++i) n     for (int j = 1; j <= N; ++j) n       if (g[i][j + N].flow) std::cout << rf(j); n   std::cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = (1 << 30) - 1; n const int maxn = 110; n int n, m, K; n long long f[maxn][maxn][maxn]; n int col[maxn]; n long long p[maxn][maxn]; n int main() { n   scanf( %d%d%d , &n, &m, &K); n   for (int i = 1; i <= n; i++) scanf( %d , &col[i]); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) scanf( %I64d , &p[i][j]); n   memset(f, 0x3f, sizeof(f)); n   long long INF = f[0][0][0]; n   f[0][0][0] = 0; n   for (int i = 1; i <= n; i++) n     for (int j = 0; j <= m; j++) n       for (int k = 0; k <= K; k++) { n         if (col[i]) n           f[i][col[i]][k + (j != col[i])] = n               min(f[i][col[i]][k + (j != col[i])], f[i - 1][j][k]); n         else n           for (int w = 1; w <= m; w++) n             f[i][w][k + (j != w)] = n                 min(f[i][w][k + (j != w)], f[i - 1][j][k] + p[i][w]); n       } n   long long ans = INF; n   for (int i = 0; i <= m; i++) ans = min(ans, f[n][i][K]); n   if (ans == INF) ans = -1; n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 1e5 + 5; n int n, m, i; n int k1, k2, k3, t1, t2, t3; n long long a[MAX], b[MAX], t[MAX]; n int main() { n   cin >> k1 >> k2 >> k3 >> t1 >> t2 >> t3 >> n; n   for (i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     b[i] = a[i]; n   } n   for (i = 0; i < n; i++) { n     a[i] = max(a[i], t[i % k1]) + t1; n     t[i % k1] = a[i]; n   } n   for (i = 0; i < n; i++) t[i] = 0; n   for (i = 0; i < n; i++) { n     a[i] = max(a[i], t[i % k2]) + t2; n     t[i % k2] = a[i]; n   } n   for (i = 0; i < n; i++) t[i] = 0; n   long long ans = 0; n   for (i = 0; i < n; i++) { n     a[i] = max(a[i], t[i % k3]) + t3; n     t[i % k3] = a[i]; n     ans = max(ans, a[i] - b[i]); n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b, c; n long long n, m, k; n int arr[100050]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0), cout.tie(0); n   cin >> n; n   bool odd = false, even = false; n   for (int i = 1; i <= n; i++) { n     cin >> arr[i]; n     if ((arr[i] -  0 ) % 2 == 0) n       odd = true; n     else n       even = true; n   } n   if (odd && even) { n     sort(arr + 1, arr + 1 + n); n     for (int i = 1; i <= n; i++) cout << arr[i] <<    ; n   } else { n     for (int i = 1; i <= n; i++) cout << arr[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int p[300], a[300], num[300]; n int find(int x) { n   if (p[x] == 0) n     return x; n   else { n     p[x] = find(p[x]); n     return p[x]; n   } n } n void merge(int x, int y) { n   x = find(x); n   y = find(y); n   if (x != y) p[x] = y; n } n int main() { n   int n, m, ans, i, x, j, k; n   scanf( %d%d , &n, &m); n   ans = 0; n   for (i = 1; i <= n; ++i) { n     scanf( %d , &x); n     for (j = 1; j <= x; ++j) { n       scanf( %d , &a[j]); n       ++num[a[j]]; n     } n     if (x == 0) { n       ++ans; n       continue; n     } n     for (k = 2; k <= x; ++k) merge(a[1], a[k]); n   } n   bool flag = false; n   for (i = 1; i <= m; ++i) { n     if (p[i] == 0 && num[i] > 0) { n       ++ans; n       flag = true; n     } n   } n   if (flag) --ans; n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1000003; n char in[2010]; n int catlen[2010]; n long long fac[4010], inv[4010], rf[4010]; n int t[2010], tc; n int first[2010], stc; n long long dp[2010][2010]; n inline int solve() { n   int n = strlen(in); n   tc = 0; n   bool isn = 0, ist; n   for (int i = (0); i < (int)(n); ++i) { n     ist = 0; n     if (in[i] <=  9  && in[i] >=  0 ) n       isn = 1; n     else { n       if (isn) { n         t[tc++] = 0; n         isn = 0; n       } n       if (i == 0 || !(in[i - 1] <=  9  && in[i - 1] >=  0 )) { n         if (in[i] ==  *  || in[i] ==  / ) return 0; n         t[tc++] = 1; n       } else n         ist = 1; n     } n   } n   if (isn) t[tc++] = 0; n   if (t[tc - 1] == 1 || ist) return 0; n   stc = 0; n   for (int i = (0); i < (int)(tc); ++i) n     if (t[i] == 0) n       first[stc]++; n     else n       stc++; n   if (stc == 0) return catlen[tc]; n   dp[stc + 1][0] = 1; n   int ms = 0; n   for (int i = (int)(stc + 1) - 1; i >= 0; --i) { n     int r = first[i]; n     if (i) { n       ms += r; n       for (int j = (1); j < (int)(ms + 1); ++j) { n         for (int k = max(r - j, 0); k <= ms - j; k++) { n           dp[i][k + 1] += (dp[i + 1][k + j - r] * catlen[j]) % mod; n           if (dp[i][k + 1] >= mod) dp[i][k + 1] -= mod; n         } n       } n     } else { n       for (int j = (0); j < (int)(ms + 1); ++j) dp[i][j + r] = dp[i + 1][j]; n       ms += r; n     } n   } n   int ret = 0; n   for (int i = (1); i < (int)(tc + 1); ++i) n     ret = (ret + dp[0][i] * catlen[i]) % mod; n   return ret; n } n int main() { n   inv[1] = 1; n   for (int i = 2; i <= 4000; i++) n     inv[i] = (inv[mod % i] * (mod - mod / i)) % mod; n   fac[0] = rf[0] = 1; n   for (int i = 1; i <= 4000; i++) { n     fac[i] = (fac[i - 1] * i) % mod; n     rf[i] = (rf[i - 1] * inv[i]) % mod; n   } n   catlen[1] = 1; n   for (int i = 1; i <= 2000; i++) n     catlen[i + 1] = n         (inv[i + 1] * (((fac[2 * i] * rf[i]) % mod * rf[i]) % mod)) % mod; n   scanf( %s , in); n   printf( %d n , solve()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int read() { n   int nm = 0, fh = 1; n   char cw = getchar(); n   for (; !isdigit(cw); cw = getchar()) n     if (cw ==  - ) fh = -fh; n   for (; isdigit(cw); cw = getchar()) nm = nm * 10 + (cw -  0 ); n   return nm * fh; n } n struct node { n   int x, y, w; n } p[1000010]; n int fa[1000010], cnt[1000010], vis[1000010], n, m, k; n bool cmp(node x1, node x2) { return x1.w < x2.w; } n int fd(int x) { return x == fa[x] ? x : fa[x] = fd(fa[x]); } n bool merge(int x, int y) { n   int t1 = fd(x), t2 = fd(y); n   if (t1 == t2) return false; n   fa[t1] = t2; n   cnt[t2] += cnt[t1]; n   if (cnt[t2] == k) return true; n   return false; n } n int main() { n   n = read(), m = read(), k = read(); n   for (int i = 1; i <= k; i++) vis[read()] = 1; n   for (int i = 1; i <= n; i++) { n     fa[i] = i; n     if (vis[i]) cnt[i] = 1; n   } n   for (int i = 1; i <= m; i++) n     p[i].x = read(), p[i].y = read(), p[i].w = read(); n   sort(p + 1, p + m + 1, cmp); n   for (int i = 1; i <= m; i++) { n     if (merge(p[i].x, p[i].y)) { n       for (int j = 1; j <= k; j++) printf( %d  , p[i].w); n       return 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n  n using namespace std; n  n const int N = 300; n int a[N]; n  n void solve(){ n     int n; n     cin >> n; n     for(int i = 0; i < n; i++){ n         cin >> a[i]; n     } n  n     int left = 0, right = n - 1, index = 1; n     while(left <= right){ n         if(index++ % 2){ n             cout << a[left++] <<    ; n         } n         else{ n             cout << a[right--] <<    ; n         } n     } n     cout <<   n ; n } n int main(void){ n     ios::sync_with_stdio(false); cin.tie(NULL); n     int t; n     cin >> t; n     while(t--) solve(); n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n long n, m; n char c; n long hi[600000][3], hj[600000][3], ans; n long temp; n long l, u; n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n >> m; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       cin >> c; n       if (c ==  . ) continue; n       temp = c - 48; n       if (temp < 3) n         l = 1; n       else n         l = 0; n       if (l % 2 == j % 2) n         hi[i][1] = 1; n       else n         hi[i][0] = 1; n       if (temp == 1 || temp == 4) n         u = 1; n       else n         u = 0; n       if (u % 2 == i % 2) n         hj[j][1] = 1; n       else n         hj[j][0] = 1; n     } n   ans = 1; n   for (int i = 1; i <= n; i++) { n     temp = 2; n     temp -= hi[i][0] + hi[i][1]; n     ans = ans * temp % 1000003; n   } n   for (int i = 1; i <= m; i++) { n     temp = 2; n     temp -= hj[i][0] + hj[i][1]; n     ans = ans * temp % 1000003; n   } n   cout << ans << endl; n   cin.get(); n   cin.get(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string a, b; n bool x, y; n bool solve(string a, string b) { n   char x =  e , y =  e ; n   if (a[0] !=  X ) { n     x = a[0]; n   } n   if (a[1] !=  X ) { n     if (x ==  e ) n       x = a[1]; n     else n       y = a[1]; n   } n   if (b[1] !=  X ) { n     if (y ==  e ) y = b[1]; n   } n   return (x ==  A  && y ==  B ) || (x ==  B  && y ==  C ) || n          (x ==  C  && y ==  A ); n } n int main() { n   cin >> a >> b; n   x = solve(a, b); n   cin >> a >> b; n   y = solve(a, b); n   if (x == y) { n     cout <<  YES  << endl; n   } else { n     cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n struct rec { n   int x1, y1, x2, y2; n }; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(0); n   vector<rec> v; n   int n; n   cin >> n; n   multiset<int> x1, x2, y1, y2; n   for (int i = 0; i < n; i++) { n     rec r; n     cin >> r.x1 >> r.y1 >> r.x2 >> r.y2; n     v.push_back(r); n     x1.insert(r.x1); n     x2.insert(r.x2); n     y1.insert(r.y1); n     y2.insert(r.y2); n   } n   for (auto i : v) { n     x1.erase(x1.find(i.x1)); n     x2.erase(x2.find(i.x2)); n     y1.erase(y1.find(i.y1)); n     y2.erase(y2.find(i.y2)); n     if (*x1.rbegin() <= *x2.begin() and *y1.rbegin() <= *y2.begin()) { n       cout << *x1.rbegin() <<     << *y1.rbegin() <<   n ; n       return 0; n     } n     x1.insert(i.x1); n     x2.insert(i.x2); n     y1.insert(i.y1); n     y2.insert(i.y2); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int l[200100], r[200100]; n bool cmp(int a, int b) { n   if (l[a] == l[b]) n     return r[a] < r[b]; n   else n     return l[a] < l[b]; n } n int main() { n   int n, i, j, k; n   int h[200100]; n   cin >> n; n   for (i = 1; i <= n; i++) { n     scanf( %d%d , &l[i], &r[i]); n     h[i] = i; n   } n   sort(h + 1, h + n + 1, cmp); n   for (i = 2; i <= n; i++) { n     if (l[h[i - 1]] == l[h[i]]) { n       cout << h[i - 1] << endl; n       return 0; n     } n     if (r[h[i - 1]] >= r[h[i]]) { n       cout << h[i] << endl; n       return 0; n     } n   } n   for (i = 2; i < n; i++) { n     if (r[h[i - 1]] + 1 >= l[h[i + 1]]) { n       cout << h[i] << endl; n       return 0; n     } n   } n   cout << -1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   double a[20] = {0}; n   int i = 0; n   for (i = 0; i < 16; i++) cin >> a[i]; n   double x1 = a[0], x2 = a[2], x3 = a[4], x4 = a[6]; n   double y1 = a[1], y2 = a[3], y3 = a[5], y4 = a[7]; n   double maxx = max(x1, (max(x2, max(x3, x4)))); n   double minx = min(x1, (min(x2, min(x3, x4)))); n   double maxy = max(y1, (max(y2, max(y3, y4)))); n   double miny = min(y1, (min(y2, min(y3, y4)))); n   double centre2x = (a[8] + a[12]) / 2.00; n   double centre2y = (a[9] + a[13]) / 2.00; n   if (minx <= centre2x && centre2x <= maxx && miny <= centre2y && n       centre2y <= maxy) { n     cout <<  YES  <<   n ; n     return 0; n   } n   if (minx <= a[8] && a[8] <= maxx && miny <= a[9] && a[9] <= maxy) { n     cout <<  YES  <<   n ; n     return 0; n   } n   if (minx <= a[10] && a[10] <= maxx && miny <= a[11] && a[11] <= maxy) { n     cout <<  YES  <<   n ; n     return 0; n   } n   if (minx <= a[12] && a[12] <= maxx && miny <= a[13] && a[13] <= maxy) { n     cout <<  YES  <<   n ; n     return 0; n   } n   if (minx <= a[14] && a[14] <= maxx && miny <= a[15] && a[15] <= maxy) { n     cout <<  YES  <<   n ; n     return 0; n   } n   for (i = 0; i < 16; i += 2) { n     double x = (a[i] + a[i + 1]) / sqrt(2); n     double y = (a[i] - a[i + 1]) / sqrt(2); n     a[i] = x; n     a[i + 1] = y; n   } n   x1 = a[0 + 8], x2 = a[2 + 8], x3 = a[4 + 8], x4 = a[6 + 8]; n   y1 = a[1 + 8], y2 = a[3 + 8], y3 = a[5 + 8], y4 = a[7 + 8]; n   maxx = max(x1, (max(x2, max(x3, x4)))); n   minx = min(x1, (min(x2, min(x3, x4)))); n   maxy = max(y1, (max(y2, max(y3, y4)))); n   miny = min(y1, (min(y2, min(y3, y4)))); n   centre2x = (a[8 - 8] + a[12 - 8]) / 2.00; n   centre2y = (a[9 - 8] + a[13 - 8]) / 2.00; n   if (minx <= centre2x && centre2x <= maxx && miny <= centre2y && n       centre2y <= maxy) { n     cout <<  YES  <<   n ; n     return 0; n   } n   if (minx <= a[8 - 8] && a[8 - 8] <= maxx && miny <= a[9 - 8] && n       a[9 - 8] <= maxy) { n     cout <<  YES  <<   n ; n     return 0; n   } n   if (minx <= a[10 - 8] && a[10 - 8] <= maxx && miny <= a[11 - 8] && n       a[11 - 8] <= maxy) { n     cout <<  YES  <<   n ; n     return 0; n   } n   if (minx <= a[12 - 8] && a[12 - 8] <= maxx && miny <= a[13 - 8] && n       a[13 - 8] <= maxy) { n     cout <<  YES  <<   n ; n     return 0; n   } n   if (minx <= a[14 - 8] && a[14 - 8] <= maxx && miny <= a[15 - 8] && n       a[15 - 8] <= maxy) { n     cout <<  YES  <<   n ; n     return 0; n   } n   cout <<  NO  <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int tam = 100010; n const int MOD = 1000000007; n const int MOD1 = 998244353; n const double EPS = 1e-9; n const double PI = acos(-1); n const int sq = 500; n int ar[tam]; n int res[tam]; n bool comp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) { n   if (a.first.first / sq == b.first.first / sq) n     return a.first.second < b.first.second; n   return a.first.first / sq < b.first.first / sq; n } n struct trie { n   int maxo, mino, nam; n   trie* ce; n   trie* un; n   trie() { n     ce = un = NULL; n     maxo = 0; n     mino = MOD; n   } n }; n typedef trie* ptrie; n void del(ptrie t) { n   if (t) { n     del(t->ce); n     del(t->un); n     delete t; n   } n } n void add(string& second, int ind, int num, ptrie t, int nam) { n   if (ind < second.size()) { n     ptrie go; n     if (second[ind] ==  0 ) { n       if (t->ce == NULL) t->ce = new trie(); n       go = t->ce; n     } else { n       if (t->un == NULL) t->un = new trie(); n       go = t->un; n     } n     add(second, ind + 1, num, go, nam); n   } else n     t->nam = nam; n   t->maxo = max(max(t->ce ? t->ce->maxo : 0, t->un ? t->un->maxo : 0), num); n   t->mino = min(min(t->ce ? t->ce->mino : MOD, t->un ? t->un->mino : MOD), num); n } n int ask1(string& second, int ind, int num, ptrie t) { n   if (ind == second.size()) return t->nam; n   ptrie go; n   if (second[ind] ==  0 ) { n     if (t->un != NULL && t->un->maxo > num) n       go = t->un; n     else if (t->ce != NULL && t->ce->maxo > num) n       go = t->ce; n     else n       return -1; n   } else { n     if (t->ce != NULL && t->ce->maxo > num) n       go = t->ce; n     else if (t->un != NULL && t->un->maxo > num) n       go = t->un; n     else n       return -1; n   } n   return ask1(second, ind + 1, num, go); n } n int ask2(string& second, int ind, int num, ptrie t) { n   if (ind == second.size()) return t->nam; n   ptrie go; n   if (second[ind] ==  0 ) { n     if (t->un != NULL && t->un->mino < num) n       go = t->un; n     else if (t->ce != NULL && t->ce->mino < num) n       go = t->ce; n     else n       return -1; n   } else { n     if (t->ce != NULL && t->ce->mino < num) n       go = t->ce; n     else if (t->un != NULL && t->un->mino < num) n       go = t->un; n     else n       return -1; n   } n   return ask2(second, ind + 1, num, go); n } n string tost(int n) { n   string res =   ; n   while (n > 0) { n     res += (n % 2) +  0 ; n     n /= 2; n   } n   while (res.size() < 22) res +=  0 ; n   reverse((res).begin(), (res).end()); n   return res; n } n int xo[1000010]; n int ros[tam]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   for (int i = 1; i < 1000010; i++) xo[i] = xo[i - 1] ^ i; n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> ar[i]; n   int a, b; n   vector<pair<pair<int, int>, int>> que; n   ptrie t1 = 0, t2 = 0; n   int ras; n   string s1, s2; n   int x, y, x1, y1; n   for (int i = 0; i < m; i++) { n     cin >> a >> b; n     a--; n     b--; n     if (b - a < sq) { n       del(t1); n       del(t2); n       t1 = new trie(); n       t2 = new trie(); n       ras = 0; n       for (int i = a; i < b + 1; i++) { n         x = ar[i] - 1; n         y = ar[i]; n         s1 = tost(xo[x]); n         s2 = tost(xo[y]); n         add(s1, 0, x, t2, xo[x]); n         add(s2, 0, y, t1, xo[y]); n         x1 = ask1(s1, 0, x, t1); n         y1 = ask2(s2, 0, y, t2); n         ras = max(ras, n                   max(xo[x] ^ ask1(s1, 0, x, t1), xo[y] ^ ask2(s2, 0, y, t2))); n       } n       res[i] = ras; n     } else n       que.push_back({{a, b}, i}); n   } n   sort((que).begin(), (que).end(), comp); n   int level = 0; n   int nu = sq; n   while (nu <= n) { n     for (int i = nu - 1; i > nu - sq - 1; i--) { n       ros[i] = ros[i + 1]; n       for (int j = i; j < nu; j++) n         ros[i] = max(ros[i], ar[i] > ar[j] ? xo[ar[i]] ^ xo[ar[j] - 1] n                                            : xo[ar[i] - 1] ^ xo[ar[j]]); n     } n     nu += sq; n   } n   int divo = -1, lasto = -1, rus; n   for (int i = 0; i < que.size(); i++) { n     if (que[i].first.first / sq != divo) { n       divo = que[i].first.first / sq; n       lasto = que[i].first.first / sq * sq + sq; n       del(t1); n       del(t2); n       t1 = new trie(); n       t2 = new trie(); n       ras = 0; n     } n     while (que[i].first.second >= lasto) { n       x = ar[lasto] - 1; n       y = ar[lasto]; n       s1 = tost(xo[x]); n       s2 = tost(xo[y]); n       add(s1, 0, x, t2, xo[x]); n       add(s2, 0, y, t1, xo[y]); n       ras = n           max(ras, max(xo[x] ^ ask1(s1, 0, x, t1), xo[y] ^ ask2(s2, 0, y, t2))); n       lasto++; n     } n     rus = ros[que[i].first.first]; n     for (int j = que[i].first.first; j < que[i].first.first / sq * sq + sq; n          j++) { n       x = ar[j] - 1; n       y = ar[j]; n       s1 = tost(xo[x]); n       s2 = tost(xo[y]); n       rus = n           max(rus, max(xo[x] ^ ask1(s1, 0, x, t1), xo[y] ^ ask2(s2, 0, y, t2))); n     } n     res[que[i].second] = max(rus, ras); n   } n   for (int i = 0; i < m; i++) cout << res[i] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, a[100010]; n map<string, int> mp; n int tot, cnt[100010]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   sort(a + 1, a + n + 1); n   char f[110]; n   string s; n   for (int i = 1; i <= m; i++) { n     scanf( %s , f); n     s = f; n     if (!mp[s]) mp[s] = ++tot; n     ++cnt[mp[s]]; n   } n   sort(cnt + 1, cnt + tot + 1); n   int minans = 0, maxans = 0; n   for (int i = tot, j = 1; i >= 1; i--, j++) { n     minans += cnt[i] * a[j]; n     maxans += cnt[i] * a[n - j + 1]; n   } n   printf( %d %d n , minans, maxans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 998244353; n const int C = 26; n void add(int &x, int y) { n   x += y; n   while (x >= MOD) x -= MOD; n   while (x < 0) x += MOD; n } n int fix(int x) { n   while (x >= MOD) x -= MOD; n   while (x < 0) x += MOD; n   return x; n } n int pw(int a, int b) { n   int ret = 1; n   while (b) { n     if (b & 1) ret = 1ll * ret * a % MOD; n     b >>= 1; n     a = 1ll * a * a % MOD; n   } n   return ret; n } n int inv(int a) { return pw(a, MOD - 2); } n int mul(int a, int b) { return (long long)a * b % MOD; } n const int MAXN = 2e5 + 10; n const int LOG = 20; n int n, q, p[MAXN]; n int tab[MAXN][LOG]; n int get(int l, int r) { n   int ans = 1; n   for (int i = LOG - 1; ~i; --i) n     if (l + (1 << i) <= r) ans = mul(ans, tab[l][i]), l += 1 << i; n   return ans; n } n int st[MAXN << 2], lz[MAXN << 2]; n int pr[MAXN]; n void plant(int v, int b, int e) { n   if (e - b == 1) { n     st[v] = pr[b]; n     return; n   } n   int m = (b + e) >> 1; n   plant(v << 1, b, m); n   plant(v << 1 ^ 1, m, e); n   st[v] = fix(st[v << 1] + st[v << 1 ^ 1]); n } n void weed(int v) { n   for (int u : {v << 1, v << 1 ^ 1}) { n     st[u] = mul(st[u], lz[v]); n     lz[u] = mul(lz[u], lz[v]); n   } n   lz[v] = 1; n } n void water(int v, int b, int e, int l, int r, int x) { n   if (l >= r) return; n   if (b == l && e == r) { n     st[v] = mul(st[v], x); n     lz[v] = mul(lz[v], x); n     return; n   } n   weed(v); n   int m = (b + e) >> 1; n   water(v << 1, b, m, l, min(r, m), x); n   water(v << 1 ^ 1, m, e, max(l, m), r, x); n   st[v] = fix(st[v << 1] + st[v << 1 ^ 1]); n } n int smoke(int v, int b, int e, int l, int r) { n   if (l >= r) return 0; n   if (b == l && e == r) return st[v]; n   weed(v); n   int m = (b + e) >> 1; n   return fix(smoke(v << 1, b, m, l, min(r, m)) + n              smoke(v << 1 ^ 1, m, e, max(l, m), r)); n } n void solve() { n   cin >> n >> q; n   for (int i = 0; i < n; i++) cin >> p[i]; n   for (int i = 0; i < n; i++) p[i] = mul(p[i], inv(100)); n   for (int i = 0; i < n; i++) tab[i][0] = p[i]; n   for (int j = 1; j < LOG; j++) n     for (int i = 0; i < n; i++) n       if (i + (1 << j) <= n) n         tab[i][j] = mul(tab[i][j - 1], tab[i + (1 << (j - 1))][j - 1]); n       else n         tab[i][j] = tab[i][j - 1]; n   fill(lz, lz + (MAXN << 2), 1); n   pr[n - 1] = inv(p[n - 1]); n   for (int i = n - 2; ~i; --i) pr[i] = mul(pr[i + 1], inv(p[i])); n   plant(1, 0, n); n   set<int> pts; n   pts.insert(0); n   pts.insert(n); n   while (q--) { n     int u; n     cin >> u; n     --u; n     if (pts.count(u)) { n       auto prv = --pts.lower_bound(u); n       water(1, 0, n, *prv, u, smoke(1, 0, n, u, u + 1)); n       pts.erase(u); n     } else { n       auto prv = --pts.lower_bound(u); n       water(1, 0, n, *prv, u, inv(smoke(1, 0, n, u, u + 1))); n       pts.insert(u); n     } n     cout << st[1] <<   n ; n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int te = 1; n   for (int w = 1; w <= te; w++) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n void solve() { n   int n, m, k, x, y; n   cin >> n >> m >> k; n   for (int i = 0; i < 2 * k; i++) cin >> x >> y; n   string ans =   ; n   ans += (string(n - 1,  U ) + string(m - 1,  L )); n   for (int i = 0; i < n; i++) { n     if (i & 1) n       ans += string(m - 1,  L ); n     else n       ans += string(m - 1,  R ); n     if (i != n - 1) ans +=  D ; n   } n   cout << ans.size() <<   n ; n   cout << ans <<   n ; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n int w[505]; n int book[505]; n int v[1005]; n int used[505]; n int main(void) { n   int n, m; n   int k; n   int r = 0; n   scanf(  %d %d , &n, &m); n   for (int i = 1; i <= n; i++) { n     used[i] = 0; n     scanf(  %d , &w[i]); n   } n   for (int i = 1; i <= m; i++) { n     scanf(  %d , &v[i]); n   } n   k = 1; n   for (int i = 1; i <= m; i++) { n     if (!used[v[i]]) { n       used[v[i]] = 1; n       book[k++] = v[i]; n     } n   } n   for (int i = 1; i <= m; i++) { n     for (int j = 1; j < k; j++) { n       if (book[j] == v[i]) { n         for (int p = j - 1; p >= 1; p--) { n           r += w[book[p]]; n           book[p + 1] = book[p]; n         } n         book[1] = v[i]; n         break; n       } n     } n   } n   printf( %d n , r); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char b[1000050], a[1000050]; n int n, m, p, P; n bool c[2050], ans[2050], Ans; n bool Calc(int x, int y, int z, int o, int u) { n   for (; o >= z; o--) { n     bool Flag = false; n     while (y >= x) { n       bool flag = true; n       for (int j = y, k = o; j <= n && k <= m; j += p, k += u) n         if (a[j] != b[k] || ((j + p > n) ^ (k + u > m))) { n           flag = false; n           break; n         } n       if (flag) { n         c[y] = 1; n         y--; n         Flag = true; n         break; n       } n       y--; n     } n     if (!Flag) return false; n   } n   return true; n } n void Put() { n   for (int i = 1; i <= P; i++) putchar(ans[i] ?  1  :  0 ); n   puts(  ); n } n void PUUUUUT() { n   if (Ans) n     for (int i = 1; i <= p; i++) n       if (ans[i] && !c[i]) n         break; n       else if (!ans[i] && c[i]) n         return; n   for (int i = 1; i <= p; i++) ans[i] = c[i]; n   Ans = true; n } n void Solve() { n   int k = n / p, l = n % p; n   for (int i = 0; i <= l; i++) n     if ((m - i) % k == 0 && (m - i) / k - i <= p - l) { n       if (Calc(1, l, 1, i, (m - i) / k) && n           Calc(l + 1, p, i + 1, (m - i) / k, (m - i) / k)) n         PUUUUUT(); n       memset(c, 0, sizeof(c)); n     } n   return; n } n int main() { n   gets(a + 1); n   gets(b + 1); n   scanf( %d , &P); n   n = strlen(a + 1); n   m = strlen(b + 1); n   p = min(P, n); n   Solve(); n   if (!Ans) n     puts( 0 ); n   else n     Put(); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   std::ios::sync_with_stdio(false); n   std::cin.tie(0); n   int n, k; n   cin >> n >> k; n   for (int i = 1; i <= k; ++i) cout << 2 * i <<     << 2 * i - 1 <<    ; n   for (int i = 2 * k + 1; i <= 2 * n; ++i) cout << i <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_SIZE = 10; n int n; n unsigned long long adj[200010], k; n struct Matrix { n   unsigned long long a[MAX_SIZE][MAX_SIZE]; n   Matrix() { n     for (int i = 0; i < MAX_SIZE; i++) n       for (int j = 0; j < MAX_SIZE; j++) a[i][j] = 0; n   } n   Matrix mul(Matrix m) { n     Matrix res = Matrix(); n     for (int i = 0; i < MAX_SIZE; i++) { n       for (int j = 0; j < MAX_SIZE; j++) { n         for (int z = 0; z < MAX_SIZE; z++) { n           if (a[i][z] != 0 && m.a[z][j] != 0 && n               (a[i][z] >= k || m.a[z][j] >= k || (a[i][z] > k / m.a[z][j]) || n                res.a[i][j] >= (k - a[i][z] * m.a[z][j]))) n             res.a[i][j] = k; n           else n             res.a[i][j] += a[i][z] * m.a[z][j]; n           res.a[i][j] = min(res.a[i][j], k); n           if (res.a[i][j] == k) break; n         } n       } n     } n     return res; n   } n   void toIndentity() { n     for (int i = 0; i < MAX_SIZE; i++) n       for (int j = 0; j < MAX_SIZE; j++) a[i][j] = i == j ? 1 : 0; n   } n   void toRightMatrix() { n     for (int i = 0; i < MAX_SIZE; i++) n       for (int j = 0; j < MAX_SIZE; j++) a[i][j] = i <= j ? 1 : 0; n   } n }; n struct Vector { n   unsigned long long a[MAX_SIZE]; n   int size; n   Vector(int _size = MAX_SIZE) { n     size = _size; n     for (int i = 0; i < MAX_SIZE; i++) a[i] = 0; n   } n   Vector mul(Matrix m) { n     Vector res = Vector(size); n     for (int i = 0; i < size; i++) { n       for (int j = 0; j < size; j++) { n         if (m.a[j][i] != 0 && a[j] != 0 && n             (m.a[j][i] >= k || a[j] >= k || m.a[j][i] > k / a[j] || n              res.a[i] >= (k - m.a[j][i] * a[j]))) n           res.a[i] = k; n         else n           res.a[i] += m.a[j][i] * a[j]; n         res.a[i] = min(res.a[i], k); n         if (res.a[i] == k) break; n       } n     } n     return res; n   } n   bool hasSolution() { n     int res = false; n     for (int i = 0; i < size; i++) n       if (a[i] >= k) { n         res = true; n         break; n       } n     return res; n   } n }; n Matrix pow(Matrix m, unsigned long long p) { n   Matrix res = Matrix(); n   res.toIndentity(); n   while (p > 0) { n     if (p % 2 == 0) { n       m = m.mul(m); n       p /= 2; n     } else { n       res = res.mul(m); n       p--; n     } n   } n   return res; n } n bool solve(Vector v, unsigned long long p) { n   Matrix m = Matrix(); n   m.toRightMatrix(); n   m = pow(m, p); n   return v.mul(m).hasSolution(); n } n int main() { n   cin >> n >> k; n   for (int i = 0; i < n; i++) cin >> adj[i]; n   unsigned long long res = 0; n   for (int i = 0; i < n; i++) n     if (adj[i] >= k) { n       cout << res; n       return 0; n     } n   int j = 0; n   for (int i = 0; i < n; i++) n     if (adj[i] != 0) { n       j = i; n       break; n     } n   for (int i = 0; i < n - j; i++) adj[i] = adj[i + j]; n   n -= j; n   if (n > MAX_SIZE) { n     while (true) { n       res++; n       for (int i = 1; i < n; i++) { n         adj[i] += adj[i - 1]; n         if (adj[i] >= k) { n           cout << res; n           return 0; n         } n       } n     } n   } else { n     Vector v = Vector(n); n     for (int i = 0; i < n; i++) v.a[i] = adj[i]; n     unsigned long long l = 1, r = k, m; n     while (l + 1 < r) { n       m = (l + r) / 2; n       if (solve(v, m)) n         r = m; n       else n         l = m + 1; n     } n     res = (l < r && solve(v, l)) ? l : r; n     cout << res; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n const long long LL_INF = 0x3f3f3f3f3f3f3f3f; n const int INF = 0x3f3f3f3f; n inline void cmin(int &x, int y) { n   if (y < x) x = y; n } n inline void cmax(int &x, int y) { n   if (y > x) x = y; n } n bool isvowel(char a) { n   if (a ==  a  || a ==  e  || a ==  i  || a ==  o  || a ==  u ) return true; n   return false; n } n int main() { n   string s, t; n   cin >> s >> t; n   if (s.size() != t.size()) return !printf( No ); n   for (int i = 0; i < s.size(); i++) { n     if (isvowel(s[i]) == isvowel(t[i])) n       continue; n     else n       return !printf( No ); n   } n   printf( Yes ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace ::std; n const long long maxn = 1e5 + 500; n const long long mod = 1e9 + 7; n const long long inf = 1e9 + 500; n const long long rad = 330; n long long a[maxn]; n long long t[maxn]; n bool cmp(pair<long long, long long> a, pair<long long, long long> b) { n   if (a.first / rad == b.first / rad) { n     return (a.second < b.second); n   } n   return (a.first < b.first); n } n long long ml[maxn]; n pair<long long, long long> sque[maxn]; n map<pair<long long, long long>, long long> anss; n long long lastid[maxn]; n long long nextid[maxn]; n long long id[maxn]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, k; n   cin >> n >> k; n   for (long long i = 1; i <= n; i++) { n     cin >> t[i]; n   } n   for (long long i = 1; i <= n; i++) { n     cin >> a[i]; n     if (t[i] == 2) { n       a[i] *= -1; n     } n   } n   for (long long i = 1; i <= n; i++) { n     a[i] += a[i - 1]; n   } n   vector<long long> vec; n   for (long long i = 0; i <= n; i++) { n     vec.push_back(a[i]); n   } n   { n     sort(vec.begin(), vec.end()); n     auto it = unique(vec.begin(), vec.end()); n     vec.resize(distance(vec.begin(), it)); n   } n   vector<long long>::iterator it; n   for (long long i = 0; i <= n; i++) { n     id[i] = lower_bound(vec.begin(), vec.end(), a[i]) - vec.begin(); n     it = lower_bound(vec.begin(), vec.end(), a[i] + k); n     if (it != vec.end() && (*it) == a[i] + k) { n       nextid[i] = it - vec.begin(); n     } else { n       nextid[i] = maxn - 1; n     } n     it = lower_bound(vec.begin(), vec.end(), a[i] - k); n     if (it != vec.end() && (*it) == a[i] - k) { n       lastid[i] = it - vec.begin(); n     } else { n       lastid[i] = maxn - 1; n     } n   } n   long long q; n   cin >> q; n   vector<pair<long long, long long> > que; n   for (long long i = 0; i < q; i++) { n     long long l, r; n     cin >> l >> r; n     l--; n     sque[i] = make_pair(l, r); n     que.push_back(make_pair(l, r)); n   } n   sort(que.begin(), que.end(), cmp); n   long long res = 0; n   long long l = 0; n   long long r = 0; n   for (auto b : que) { n     long long L = b.first; n     long long R = b.second; n     while (r <= R) { n       res += ml[lastid[r]]; n       ml[id[r]]++; n       r++; n     } n     while (L < l) { n       l--; n       res += ml[nextid[l]]; n       ml[id[l]]++; n     } n     while (R + 1 < r) { n       r--; n       ml[id[r]]--; n       res -= ml[lastid[r]]; n     } n     while (l < L) { n       ml[id[l]]--; n       res -= ml[nextid[l]]; n       l++; n     } n     anss[make_pair(L, R)] = res; n   } n   for (long long i = 0; i < q; i++) { n     cout << anss[sque[i]] << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int N; n int Move[100005], cnt, P[100005]; n vector<int> G[100005]; n int TT[100005], Next[100005]; n int DP[100005], Stack[100005], top; n void Read() { n   scanf( %d , &N); n   for (int i = 1; i < N; i++) { n     int father; n     scanf( %d , &father); n     ++father; n     G[father].push_back(i + 1); n     TT[i + 1] = father; n   } n } n void DFS(int node) { n   for (int i = 0; i < G[node].size(); i++) { n     int neighb = G[node][i]; n     DFS(neighb); n     DP[node] = max(DP[node], DP[neighb] + 1); n   } n } n void precalcPath() { n   int node = 1; n   while (G[node].size() != 0) { n     Stack[++top] = node; n     for (int i = 0; i < G[node].size(); i++) { n       int neighb = G[node][i]; n       if (DP[neighb] == DP[node] - 1) { n         swap(G[node][i], G[node][G[node].size() - 1]); n         G[node].pop_back(); n         node = neighb; n         break; n       } n     } n   } n   Stack[++top] = node; n } n void Solve(int node, int next) { n   int last = next; n   for (int i = 0; i < G[node].size(); i++) { n     int neighb = G[node][i]; n     TT[last] = neighb; n     Move[++cnt] = last; n     last = neighb; n   } n   for (int i = G[node].size() - 1; i >= 1; i--) n     Solve(G[node][i], G[node][i - 1]); n   if (G[node].size() > 0) Solve(G[node][0], next); n } n void printSol() { n   int node = 1; n   for (int i = 1; i <= N; i++) Next[TT[i]] = i; n   for (int i = 1; i <= N; i++) { n     printf( %d  , node - 1); n     node = Next[node]; n   } n   printf(  n%d n , cnt); n   for (int i = cnt; i >= 1; i--) printf( %d  , Move[i] - 1); n   printf(  n ); n } n int main() { n   Read(); n   DFS(1); n   precalcPath(); n   for (int i = 1; i < top; i++) Solve(Stack[i], Stack[i + 1]); n   printSol(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000005; n const int mod = 1e9 + 7; n struct point { n   int x, y; n   inline friend long long operator*(point a, point b) { n     return 1ll * a.x * b.y - 1ll * a.y * b.x; n   } n } p[N]; n long long sx[N], sy[N], s[N], ans, sum, area; n int n; n inline long long getS(int l, int r) { return s[r] - s[l] + (p[r] * p[l]); } n inline int chk(int l, int r) { n   long long L = getS(l, r), R = getS(r, l + n); n   if (L < R) return 1; n   if (L == R && r <= n) return 1; n   return 0; n } n inline long long cro(int k, int l, int r) { n   long long xy = (sx[r] - sx[l - 1]) * p[k].y; n   long long yx = (sy[r] - sy[l - 1]) * p[k].x; n   return (xy % mod - yx % mod + mod) % mod; n } n int main() { n   scanf( %d , &n); n   for (int i = (1); i <= (n); i++) scanf( %d%d , &p[i].x, &p[i].y); n   for (int i = (1); i <= (n / 2); i++) swap(p[i], p[n + 1 - i]); n   for (int i = (1); i <= (n); i++) p[i + n] = p[i]; n   p[0] = p[n]; n   for (int i = (0); i < (n); i++) area = (area + (p[i] * p[i + 1])) % mod; n   sx[0] = p[0].x, sy[0] = p[0].y; n   for (int i = (1); i <= (2 * n); i++) { n     sx[i] = (sx[i - 1] + p[i].x) % mod; n     sy[i] = (sy[i - 1] + p[i].y) % mod; n     s[i] = s[i - 1] + (p[i - 1] * p[i]); n   } n   int r = 0; n   for (int l = (1); l <= (n); l++) { n     if (r <= l + 1) sum = 0, r = l + 1; n     while (chk(l, r + 1)) sum = (sum + s[++r] - s[l] + mod) % mod; n     ans = (ans + sum + cro(l, l + 2, r)) % mod; n     sum = (sum - (p[l] * p[l + 1]) % mod * (r - l - 1) % mod - n            (p[l + 1] * p[l + 2]) % mod + 2ll * mod) % n           mod; n   } n   ans = (1ll * n * (n - 3) / 2) % mod * area - 2 * ans; n   ans = (ans % mod + mod) % mod; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     int r, p, s; n     cin >> r >> p >> s; n     string q; n     cin >> q; n     int lastn = ceil(n / 2.0); n     int R = 0, P = 0, S = 0; n     for (long long i = 0; i < q.size(); i++) { n       if (q[i] ==  R ) { n         R++; n       } else if (q[i] ==  S ) { n         S++; n       } else { n         P++; n       } n     } n     int total = min(R, p) + min(P, s) + min(S, r); n     if (total < lastn) { n       cout <<  NO  << endl; n       ; n       continue; n     } else { n       char ans[q.size()]; n       memset(ans,  0 , sizeof(ans)); n       for (int i = 0; i < q.size(); i++) { n         if (q[i] ==  S ) { n           if (r > 0) { n             ans[i] =  R ; n             r--; n           } n         } else if (q[i] ==  R ) { n           if (p > 0) { n             ans[i] =  P ; n             p--; n           } n         } else { n           if (s > 0) { n             ans[i] =  S ; n             s--; n           } n         } n       } n       for (int i = 0; i < q.size(); i++) { n         if (ans[i] ==  0 ) { n           if (r > 0) { n             ans[i] =  R ; n             r--; n           } else if (p > 0) { n             ans[i] =  P ; n             p--; n           } else if (s > 0) { n             ans[i] =  S ; n             s--; n           } n         } n       } n       cout <<  YES  << endl; n       ; n       for (int i = 0; i < q.size(); i++) { n         cout << ans[i]; n       } n       cout << endl; n     } n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   solve(); n } n


#include <bits/stdc++.h> n int main() { n   char s[20]; n   bool jizz = false; n   int value1[61] = {0}, value2[61] = {0}, k, max = 0; n   int m, n, a, b; n   scanf( %s , &s); n   for (m = 0; m < strlen(s); m++) { n     if (s[m] ==  : ) break; n     for (a = 2; a < 61; a++) { n       if (s[m] <=  Z  && s[m] >=  A ) n         k = s[m] -  A  + 10; n       else n         k = s[m] -  0 ; n       if (k > max) max = k; n       value1[a] = value1[a] * a + k; n     } n   } n   for (n = m + 1; n < strlen(s); n++) { n     for (a = 2; a < 61; a++) { n       if (s[n] <=  Z  && s[n] >=  A ) n         k = s[n] -  A  + 10; n       else n         k = s[n] -  0 ; n       if (k > max) max = k; n       value2[a] = value2[a] * a + k; n     } n   } n   if (value1[60] <= 23 && value2[60] <= 59) n     printf( -1 n ); n   else { n     for (a = max + 1; a < 60; a++) { n       if (value1[a] <= 23 && value2[a] <= 59) { n         jizz = true; n         break; n       } n     } n     if (jizz == false) printf( 0 n ); n     for (a = max + 1; a < 60; a++) { n       if (value1[a] <= 23 && value2[a] <= 59) { n         printf( %d  , a); n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n char s1[6], s2[6], ch; n int cnt = 0, ans, ok1, ok2; n bool func1(int sumA, int sumB, char s[]) { n   int dif = sumB - sumA; n   for (int i = 0; i < 3; i++) { n     bool fl = 0; n     ch = s[i]; n     while (ch <  9  && dif > 0) ch++, dif--, fl = 1; n     if (fl) cnt++; n   } n   return dif == 0; n } n bool func2(int sumA, int sumB, char s[]) { n   int dif = sumB - sumA; n   for (int i = 2; i >= 0; i--) { n     bool fl = 0; n     ch = s[i]; n     while (ch >  0  && dif > 0) ch--, dif--, fl = 1; n     if (fl) cnt++; n   } n   return dif == 0; n } n int main() { n   while (scanf( %3s%3s , s1, s2) == 2) { n     cerr << s1 <<     << s2 <<   n ; n     int sum = 0, sum1 = 0, sum2 = 0, ans = 9; n     for (int i = 0; i < 3; i++) sum1 += s1[i] -  0 ; n     for (int i = 0; i < 3; i++) sum2 += s2[i] -  0 ; n     sort(s1, s1 + 3), sort(s2, s2 + 3); n     sum = max(sum1, sum2); n     while (sum) { n       cnt = ok1 = ok2 = 0; n       if (sum1 <= sum) n         ok1 = func1(sum1, sum, s1); n       else n         ok1 = func2(sum, sum1, s1); n       if (sum2 <= sum) n         ok2 = func1(sum2, sum, s2); n       else n         ok2 = func2(sum, sum2, s2); n       if (ok1 && ok2) { n         cerr <<  cnt=   << cnt <<     << sum <<   n ; n         ans = min(ans, cnt); n       } n       sum--; n     } n     if (ans == 9) ans = 0; n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int MAX_LEN = 1010; n using namespace std; n template <typename U, typename V> n string to_string(pair<U, V>); n string to_string(const string& e_) { return     + e_ +    ; } n string to_string(char e_) { return      + string(1, e_) +     ; } n string to_string(bool e_) { return e_ ?  true  :  false ; } n template <typename T> n string to_string(T e_) { n   string s_ =  [  ; n   for (const auto& x_ : e_) s_ += to_string(x_) +    ; n   return s_ +  ] ; n } n template <typename U, typename V> n string to_string(pair<U, V> e_) { n   return  (  + to_string(e_.first) +  ,   + to_string(e_.second) +  ) ; n } n void dbg_str() { ; } n template <typename U, typename... V> n void dbg_str(U u, V... v) { n   ; n   dbg_str(v...); n } n long long int n, m; n long long int ans, mn; n long long int lx, hx, wx; n struct rd { n   long long int l; n   long long int w; n   long long int h; n }; n vector<rd> rooms; n vector<rd> rolls; n int main() { n   scanf( %lld , &n); n   for (int i = 0; i < n; i++) { n     scanf( %lld %lld %lld , &lx, &wx, &hx); n     rooms.push_back({lx, wx, hx}); n   } n   scanf( %lld , &m); n   for (int i = 0; i < m; i++) { n     scanf( %lld %lld %lld , &lx, &wx, &hx); n     rolls.push_back({lx, wx, hx}); n   } n   ans = 0; n   for (int i = 0; i < n; i++) { n     mn = 1e14; n     for (int j = 0; j < m; j++) { n       long long int totw = (rolls[j].l / rooms[i].h) * rolls[j].w; n       if (!totw) continue; n       long long int nr = n           (long long int)ceil(((double)2 * (rooms[i].l + rooms[i].w)) / totw); n       mn = min(mn, nr * rolls[j].h); n     } n     ans += mn; n   } n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n long long int M = 998244353, q, n, p[300001], d[300001], fans, products[300001], n               invproducts[300001]; n long long int power(long long int x, long long int n) { n   if (n == 0) n     return (long long)1; n   else if (n % 2 == 0) n     return power((x * x) % M, n / 2); n   else n     return (x * power((x * x) % M, (n - 1) / 2)) % M; n } n long long int cans(long long int p, long long int q) { n   return ((p * power(q, M - 2)) % M + M) % M; n } n void build() { n   products[0] = invproducts[0] = 1; n   for (long long int i = 1; i <= n; i++) { n     products[i] = (products[i - 1] * p[i]) % M; n     invproducts[i] = cans(1, products[i]); n   } n   return; n } n long long int querry(long long int l, long long int r) { n   return (products[r] * invproducts[l - 1]) % M; n } n long long int qvalue(long long int i, long long int j) { n   long long int prod = querry(i, j); n   long long int ans = (d[i - 1] * prod) % M; n   ans = ((d[j] - ans) % M + M) % M; n   return ans; n } n set<long long int> checkpoints; n void addcheckpoint(long long int id) { n   checkpoints.insert(id); n   auto it = checkpoints.find(id); n   auto it1 = prev(it); n   auto it2 = next(it); n   fans = ((fans - qvalue(*it1, *it2 - 1)) % M + M) % M; n   fans = (fans + qvalue(*it1, id - 1)) % M; n   fans = (fans + qvalue(id, *it2 - 1)) % M; n } n void delcheckpoint(long long int id) { n   auto it = checkpoints.find(id); n   auto it1 = prev(it); n   auto it2 = next(it); n   fans = ((fans + qvalue(*it1, *it2 - 1)) % M + M) % M; n   fans = ((fans - qvalue(*it1, id - 1)) % M + M) % M; n   fans = ((fans - qvalue(id, *it2 - 1)) % M + M) % M; n   checkpoints.erase(id); n } n int main() { n   cin >> n >> q; n   for (int i = 1; i <= n; i++) { n     long long int pr; n     cin >> pr; n     p[i] = cans(100, pr); n     d[i] = ((1 + d[i - 1]) * p[i]) % M; n   } n   build(); n   checkpoints.insert(1); n   checkpoints.insert(n + 1); n   fans = d[n]; n   while (q--) { n     long long int quer; n     cin >> quer; n     if (checkpoints.find(quer) == checkpoints.end()) n       addcheckpoint(quer); n     else n       delcheckpoint(quer); n     cout << fans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n int n, one, two[2], tmp, num, a[N]; n bool flag, f[N]; n int read() { n   int x = 0, f = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   return x * f; n } n int main() { n   n = read(); n   for (int i = 1; i <= n; i++) a[i] = read(); n   for (int i = 1; i <= n; i++) { n     if (f[i]) continue; n     f[i] = true; n     if (a[i] == i) { n       one = i; n       continue; n     } n     if (a[a[i]] == i) { n       two[0] = i; n       two[1] = a[i]; n       f[a[i]] = true; n       continue; n     } n     tmp = a[i]; n     num = 1; n     while (!f[tmp]) { n       f[tmp] = true; n       num++; n       tmp = a[tmp]; n     } n     if (num & 1) flag = true; n   } n   if (one) { n     printf( YES n ); n     for (int i = 1; i <= n; i++) n       if (i != one) printf( %d %d n , one, i); n     return 0; n   } n   if (flag || !two[0]) { n     printf( NO ); n     return 0; n   } n   printf( YES n%d %d n , two[0], two[1]); n   memset(f, 0, sizeof(f)); n   for (int i = 1; i <= n; i++) { n     if (f[i] || i == two[0] || i == two[1]) continue; n     tmp = i; n     num = 0; n     while (!f[tmp]) { n       printf( %d %d n , two[num & 1], a[tmp]); n       num++; n       f[tmp] = true; n       tmp = a[tmp]; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void getre() { n   int x = 0; n   printf( %d n , 1 / x); n } n void gettle() { n   int res = 1; n   while (1) res <<= 1; n   printf( %d n , res); n } n template <typename T, typename S> n inline bool upmin(T &a, const S &b) { n   return a > b ? a = b, 1 : 0; n } n template <typename T, typename S> n inline bool upmax(T &a, const S &b) { n   return a < b ? a = b, 1 : 0; n } n template <typename N, typename PN> n inline N flo(N a, PN b) { n   return a >= 0 ? a / b : -((-a - 1) / b) - 1; n } n template <typename N, typename PN> n inline N cei(N a, PN b) { n   return a > 0 ? (a - 1) / b + 1 : -(-a / b); n } n template <typename N> n N gcd(N a, N b) { n   return b ? gcd(b, a % b) : a; n } n template <typename N> n inline int sgn(N a) { n   return a > 0 ? 1 : (a < 0 ? -1 : 0); n } n inline void gn(long long &x) { n   int sg = 1; n   char c; n   while (((c = getchar()) <  0  || c >  9 ) && c !=  - ) n     ; n   c ==  -  ? (sg = -1, x = 0) : (x = c -  0 ); n   while ((c = getchar()) >=  0  && c <=  9 ) x = x * 10 + c -  0 ; n   x *= sg; n } n inline void gn(int &x) { n   long long t; n   gn(t); n   x = t; n } n inline void gn(unsigned long long &x) { n   long long t; n   gn(t); n   x = t; n } n inline void gn(double &x) { n   double t; n   scanf( %lf , &t); n   x = t; n } n inline void gn(long double &x) { n   double t; n   scanf( %lf , &t); n   x = t; n } n inline void gs(char *s) { scanf( %s , s); } n inline void gc(char &c) { n   while ((c = getchar()) > 126 || c < 33) n     ; n } n inline void pc(char c) { putchar(c); } n inline long long sqr(long long a) { return a * a; } n inline double sqrf(double a) { return a * a; } n const int inf = 0x3f3f3f3f; n const double pi = 3.14159265358979323846264338327950288L; n const double eps = 1e-6; n int n; n long long x[111111], y[111111], z[111111]; n int out = 0; n bool check(long long d, int par) { n   long long lz, rz; n   lz = -7e18, rz = 7e18; n   long long l10, r10, l20, r20; n   long long l1, r1, l2, r2; n   l1 = l2 = -7e18; n   r1 = r2 = 7e18; n   for (int i = (1), _ed = (n + 1); i < _ed; i++) { n     upmax(l1, x[i] + y[i] + z[i] - d); n     upmin(r1, x[i] + y[i] + z[i] + d); n     upmax(l2, x[i] + y[i] - z[i] - d); n     upmin(r2, x[i] + y[i] - z[i] + d); n   } n   if ((l1 & 1) != par) l1++; n   if ((l2 & 1) != par) l2++; n   if ((r1 & 1) != par) r1--; n   if ((r2 & 1) != par) r2--; n   if (l1 > r1 || l2 > r2) return 0; n   upmin(rz, (r1 - l2) / 2ll); n   upmax(lz, (l1 - r2) / 2ll); n   l10 = l1; n   r10 = r1; n   l20 = l2; n   r20 = r2; n   l1 = l2 = -7e18; n   r1 = r2 = 7e18; n   for (int i = (1), _ed = (n + 1); i < _ed; i++) { n     upmax(l1, x[i] - y[i] + z[i] - d); n     upmin(r1, x[i] - y[i] + z[i] + d); n     upmax(l2, x[i] - y[i] - z[i] - d); n     upmin(r2, x[i] - y[i] - z[i] + d); n   } n   if ((l1 & 1) != par) l1++; n   if ((l2 & 1) != par) l2++; n   if ((r1 & 1) != par) r1--; n   if ((r2 & 1) != par) r2--; n   if (l1 > r1 || l2 > r2) return 0; n   upmin(rz, (r1 - l2) / 2ll); n   upmax(lz, (l1 - r2) / 2ll); n   if (lz > rz) return 0; n   long long z = lz; n   long long lplu = max(l10 - z, l20 + z); n   long long rplu = min(r10 - z, r20 + z); n   long long lmin = max(l1 - z, l2 + z); n   long long rmin = min(r1 - z, r2 + z); n   long long x = (lplu + lmin) / 2, y = (lplu - lmin) / 2; n   if (out) { n     out = 0; n     printf( %I64d %I64d %I64d n , x, y, z); n   } n   return 1; n } n int main() { n   int te; n   gn(te); n   while (te--) { n     gn(n); n     for (int i = (1), _ed = (n + 1); i < _ed; i++) { n       gn(x[i]); n       gn(y[i]); n       gn(z[i]); n     } n     long long l = 0, r = 3.1e18; n     while (l <= r) { n       long long mid = l + r >> 1; n       if (check(mid, 0) || check(mid, 1)) n         r = mid - 1; n       else n         l = mid + 1; n     } n     out = 1; n     check(l, 0); n     check(l, 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<int> > adjl(500000); n int s[500000] = {0}; n long long int a[500000] = {0}; n map<pair<int, int>, long long int> mp; n int vis[500000] = {0}; n void dfs(int n, vector<pair<int, int> > &ans, int p, long long int sum, n          long long int mini) { n   if (sum - mini > a[n]) { n     ans.push_back(make_pair(n, p)); n   } n   for (int i = 0; i < adjl[n].size(); i++) { n     int ch = adjl[n][i]; n     if (ch != p) { n       dfs(ch, ans, n, sum + mp[make_pair(ch, n)], n           min(mini, sum + mp[make_pair(ch, n)])); n     } n   } n } n void dfs1(int n, int p, int &count) { n   vis[n] = 1; n   count++; n   for (int i = 0; i < adjl[n].size(); i++) { n     int ch = adjl[n][i]; n     if (ch != p) { n       dfs1(ch, n, count); n     } n   } n } n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i + 1]; n   } n   for (int i = 0; i < (n - 1); i++) { n     int a, c; n     cin >> a >> c; n     adjl[a].push_back(i + 2); n     adjl[i + 2].push_back(a); n     mp[make_pair(a, i + 2)] = c; n     mp[make_pair(i + 2, a)] = c; n   } n   vector<pair<int, int> > ans; n   dfs(1, ans, -1, 0, 0); n   long long int ans1 = 0; n   for (int i = 0; i < ans.size(); i++) { n     if (!vis[ans[i].first]) { n       int count = 0; n       dfs1(ans[i].first, ans[i].second, count); n       ans1 += count; n     } n   } n   cout << ans1 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long f[100]; n int s[100]; n long long dp[100][2]; n int main() { n   f[0] = f[1] = 1; n   for (int i = 2; i < 100; i++) { n     f[i] = f[i - 1] + f[i - 2]; n   } n   int cas; n   cin >> cas; n   while (cas--) { n     long long n; n     cin >> n; n     int cnt = 0; n     for (int i = 90; i >= 1; i--) { n       if (n >= f[i]) { n         n -= f[i]; n         s[++cnt] = i; n       } n     } n     reverse(s + 1, s + cnt + 1); n     dp[0][0] = 1; n     dp[0][1] = 0; n     for (int i = 1; i <= cnt; i++) { n       dp[i][0] = dp[i - 1][0] + dp[i - 1][1]; n       dp[i][1] = dp[i - 1][0] * ((s[i] - s[i - 1] - 1) / 2) + n                  dp[i - 1][1] * ((s[i] - s[i - 1]) / 2); n     } n     cout << dp[cnt][0] + dp[cnt][1] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long max(long long a, long long b) { n   if (a > b) { n     return a; n   } else { n     return b; n   } n } n long long min(long long a, long long b) { n   if (a < b) { n     return a; n   } else { n     return b; n   } n } n string int2str(int& i) { n   string s; n   stringstream ss(s); n   ss << i; n   return ss.str(); n } n int cnt; n bool done[100000000]; n void outputspec(int x) { n   if (!done[x]) { n     done[x] = 1; n     string u = int2str(x); n     while (u.length() < 8) { n       u =  0  + u; n     } n     cout << u << endl; n     cnt--; n   } n } n struct node { n   int dir; n   node* next; n }; n node *h[20001], *ba[20001]; n void insert(int data, int tar) { n   node* temp = new node; n   temp->next = NULL; n   temp->dir = data; n   ba[tar]->next = temp; n   ba[tar] = temp; n } n void trygen(int cur, int id, int act, int yes) { n   if (id == 0) { n     if ((cur <= 10000) && (cur >= -10000)) { n       insert(act, cur + 10000); n     } n   } else { n     for (long long i = 0; i <= 9; i++) { n       int cur2 = cur + i, id2 = id / 10, act2 = act + id * i; n       trygen(cur2, id2, act2, 0); n       cur2 = cur - i; n       id2 = id / 10; n       act2 = act + id * i; n       trygen(cur2, id2, act2, 0); n       if (yes) { n         cur2 = cur * 10 + i; n         id2 = id / 10; n         act2 = act + id * i; n         trygen(cur2, id2, act2, 1); n       } n       if (id != 1000) { n         cur2 = cur * i; n         id2 = id / 10; n         act2 = act + id * i; n         trygen(cur2, id2, act2, 0); n       } n     } n   } n } n int main() { n   int k, m; n   cin >> k >> m; n   for (long long i = 0; i <= 99999999; i++) { n     done[i] = 0; n   } n   if (k == 0) { n     for (long long i = 1; i <= m; i++) { n       outputspec(i); n     } n     return 0; n   } n   if (k != 0) { n     for (long long i = 0; i <= 20000; i++) { n       h[i] = new node; n       h[i]->next = NULL; n       ba[i] = h[i]; n     } n     trygen(0, 1000, 0, 1); n     cnt = m; n     for (long long j = 1; j <= 9999; j++) { n       node* a = h[j + 10000]; n       if (cnt == 0) { n         return 0; n       } else { n         while (a->next != NULL) { n           a = a->next; n           node* b = h[k + 10000 - j]; n           while (b->next != NULL) { n             b = b->next; n             outputspec(a->dir * 10000 + b->dir); n             if (cnt == 0) { n               return 0; n             } n           } n           b = h[-1 * k + j + 10000]; n           while (b->next != NULL) { n             b = b->next; n             outputspec(a->dir * 10000 + b->dir); n             if (cnt == 0) { n               return 0; n             } n           } n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n const long long INF = 1e18; n const long double PI = acos((long double)-1); n const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; n void setIO(string name =   ) { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   if ((int)(name).size()) { n     freopen((name +  .in ).c_str(),  r , stdin); n     freopen((name +  .out ).c_str(),  w , stdout); n   } n } n int main() { n   setIO(); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     int arr[n]; n     for (int i = (0); i < (n); i++) cin >> arr[i]; n     int last = 1; n     int cnt = 0, prev = 1, c = 0; n     for (int i = (1); i < (n - 1); i++) { n       if (arr[i] > arr[i + 1]) { n         cnt++; n       } n       c++; n       if (cnt >= prev) { n         last++; n         prev = c; n         c = 0; n         cnt = 0; n       } n     } n     cout << last <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int SQ = 350; n const int MAX_N = 100000; n deque<int> a[MAX_N / SQ + 10]; n int num[MAX_N / SQ + 10][MAX_N + 10]; n int N, Q, lastans = 0; n void print() { n   for (int i = 0; i <= N / SQ; i++) { n     for (int j = 0; j < a[i].size(); j++) { n       cout << a[i][j] <<    ; n     } n   } n   cout << endl; n   return; n } n int main() { n   scanf( %d , &N); n   for (int i = 0; i < N; i++) { n     int x = i / SQ, k; n     scanf( %d , &k); n     a[x].push_back(k); n     num[x][k]++; n   } n   scanf( %d , &Q); n   for (int i = 0; i < Q; i++) { n     int type, l, r, k; n     scanf( %d , &type); n     if (type == 1) { n       scanf( %d %d , &l, &r); n       l = (l + lastans - 1) % N; n       r = (r + lastans - 1) % N; n       if (l > r) swap(l, r); n       int lx = l / SQ, ly = l % SQ, rx = r / SQ, ry = r % SQ; n       if (lx == rx) { n         int f = a[rx][ry]; n         a[rx].erase(a[rx].begin() + ry); n         a[rx].insert(a[rx].begin() + ly, f); n       } else { n         int f = a[rx][ry]; n         a[rx].erase(a[rx].begin() + ry); n         num[rx][f]--; n         for (int j = lx; j < rx; j++) { n           int b = a[j].back(); n           a[j].pop_back(); n           a[j + 1].push_front(b); n           num[j][b]--; n           num[j + 1][b]++; n         } n         a[lx].insert(a[lx].begin() + ly, f); n         num[lx][f]++; n       } n     } else { n       scanf( %d %d %d , &l, &r, &k); n       l = (l + lastans - 1) % N; n       r = (r + lastans - 1) % N; n       k = (k + lastans - 1) % N + 1; n       if (l > r) swap(l, r); n       int lx = l / SQ, ly = l % SQ, rx = r / SQ, ry = r % SQ; n       int ans = 0; n       if (lx == rx) { n         for (int j = ly; j <= ry; j++) n           if (a[lx][j] == k) ans++; n       } else { n         for (int j = ly; j < SQ; j++) n           if (a[lx][j] == k) ans++; n         for (int j = lx + 1; j < rx; j++) ans += num[j][k]; n         for (int j = 0; j <= ry; j++) n           if (a[rx][j] == k) ans++; n       } n       lastans = ans; n       printf( %d n , ans); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b) { n   return make_pair(a.first + b.first, a.second + b.second); n } n pair<int, int> operator-(const pair<int, int> &a, const pair<int, int> &b) { n   return make_pair(a.first - b.first, a.second - b.second); n } n pair<int, int> &operator+=(pair<int, int> &a, const pair<int, int> &b) { n   a.first += b.first; n   a.second += b.second; n   return a; n } n pair<int, int> &operator-=(pair<int, int> &a, const pair<int, int> &b) { n   a.first -= b.first; n   a.second -= b.second; n   return a; n } n template <class T, class U> n bool cmp_second(const pair<T, U> &a, const pair<T, U> &b) { n   return a.second < b.second; n } n template <class T> n T gcd(T a, T b) { n   a = abs(a); n   b = abs(b); n   while (b) { n     T t = b; n     b = a % b; n     a = t; n   } n   return a; n } n template <class T> n pair<T, T> ext_gcd(T a, T b) { n   T a0 = 1, a1 = 0, b0 = 0, b1 = 1; n   if (a < 0) { n     a = -a; n     a0 = -1; n   } n   if (b < 0) { n     b = -b; n     b1 = -1; n   } n   while (b) { n     T t, q = a / b; n     t = b; n     b = a - b * q; n     a = t; n     t = b0; n     b0 = a0 - b0 * q; n     a0 = t; n     t = b1; n     b1 = a1 - b1 * q; n     a1 = t; n   } n   return make_pair(a0, a1); n } n inline int sg(int x) { return x ? (x > 0 ? 1 : -1) : 0; } n int main(void) { n   int len, skip; n   scanf( %d %d , &(len), &(skip)); n   len++; n   skip++; n   long long sol = 0; n   for (int a = skip; a <= len - a; a++) { n     int b = len - a; n     int ab3 = a * b * 3; n     int cnt = 0; n     for (int c = skip; c <= len - skip; c++) { n       int dmax = (ab3 - 1) / (a + c) - b; n       dmax = min(dmax, len - skip); n       dmax = max(dmax, skip - 1); n       if (dmax < skip) break; n       cnt += dmax - (skip - 1); n     } n     sol += cnt + (a < len - a ? cnt : 0); n   } n   sol *= 3; n   cout << sol << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2001111; n long long n, m, k; n long long md = 1000000007; n long long a[N]; n set<long long> s; n long long len[N]; n vector<long long> t[N]; n vector<long long> pref[N]; n void merge(vector<long long> &t, vector<long long> a, vector<long long> b, n            long long x, long long y) { n   long long i = 0; n   long long j = 0; n   while (i < a.size() && j < b.size()) { n     if (a[i] + x <= b[j] + y) { n       t.push_back(a[i] + x); n       i++; n     } else { n       t.push_back(b[j] + y); n       j++; n     } n   } n   while (i < a.size()) { n     t.push_back(a[i] + x); n     i++; n   } n   while (j < b.size()) { n     t.push_back(b[j] + y); n     j++; n   } n } n void build(long long x) { n   if (x * 2 <= n) { n     build(x * 2); n   } n   if (x * 2 + 1 <= n) { n     build(x * 2 + 1); n   } n   t[x].push_back(0); n   merge(t[x], t[x * 2], t[x * 2 + 1], len[x * 2], len[x * 2 + 1]); n   pref[x].push_back(t[x][0]); n   for (long long i = 1; i < t[x].size(); i++) { n     pref[x].push_back(t[x][i] + pref[x][i - 1]); n   } n } n signed main() { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   cin >> n >> m; n   for (long long i = 2; i <= n; i++) { n     cin >> len[i]; n   } n   build(1); n   long long ans = 0; n   for (long long i = 1; i <= m; i++) { n     long long x, h; n     cin >> x >> h; n     long long pos = upper_bound(t[x].begin(), t[x].end(), h) - t[x].begin() - 1; n     ans = ans + (pos + 1) * h - pref[x][pos]; n     long long prev = x; n     h -= len[x]; n     x /= 2; n     while (x >= 1) { n       if (h <= 0) { n         break; n       } n       ans += h; n       if (x * 2 != prev && x * 2 <= n) { n         h -= len[x * 2]; n         pos = upper_bound(t[x * 2].begin(), t[x * 2].end(), h) - n               t[x * 2].begin() - 1; n         if (pos >= 0) ans = ans + (pos + 1) * h - pref[2 * x][pos]; n         h += len[x * 2]; n       } n       if (x * 2 + 1 != prev && x * 2 + 1 <= n) { n         h -= len[x * 2 + 1]; n         pos = upper_bound(t[x * 2 + 1].begin(), t[x * 2 + 1].end(), h) - n               t[x * 2 + 1].begin() - 1; n         if (pos >= 0) ans = ans + (pos + 1) * h - pref[2 * x + 1][pos]; n         h += len[x * 2 + 1]; n       } n       h -= len[x]; n       prev = x; n       x /= 2; n     } n     cout << ans <<   n ; n     ans = 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int x, y; n vector<int> v1[200086], v2[200086]; n bool ins[200086]; n bool vis[200086], vis1[200086], vis2[200086]; n bool e[200086]; n int ans; n void dfs(int i) { n   vis[i] = ins[i] = true; n   for (int j = 0; j < v1[i].size(); j++) { n     int to = v1[i][j]; n     if (ins[to]) { n       printf( -1 ); n       exit(0); n     } n     if (!vis[to]) dfs(to); n   } n   ins[i] = false; n } n void dfs1(int i) { n   vis1[i] = true; n   for (int j = 0; j < v1[i].size(); j++) { n     int to = v1[i][j]; n     if (!vis1[to]) dfs1(to); n   } n } n void dfs2(int i) { n   vis2[i] = true; n   for (int j = 0; j < v2[i].size(); j++) { n     int to = v2[i][j]; n     if (!vis2[to]) dfs2(to); n   } n } n int main() { n   scanf( %d%d , &n, &m); n   ans = n; n   for (int i = 1; i <= m; i++) n     scanf( %d%d , &x, &y), v1[x].push_back(y), v2[y].push_back(x); n   for (int i = 1; i <= n; i++) n     if (!vis[i]) dfs(i); n   for (int i = 1; i <= n; i++) { n     if (vis1[i]) n       e[i] = true; n     else n       dfs1(i); n     if (vis2[i]) n       e[i] = true; n     else n       dfs2(i); n     if (e[i]) ans--; n   } n   printf( %d n , ans); n   for (int i = 1; i <= n; i++) printf( %c , e[i] ?  E  :  A ); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<char> vec(100001); n   vec[0] =  a ; n   int i = 1; n   while (i < 100001) { n     if (vec[i - 1] ==  a ) n       vec[i] =  b ; n     else if (vec[i - 1] ==  b ) n       vec[i] =  c ; n     else if (vec[i - 1] ==  c ) n       vec[i] =  d ; n     else if (vec[i - 1] ==  d ) n       vec[i] =  a ; n     i++; n   } n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cout << vec[i]; n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n map<long long, int> cont; n int n; n int ans; n int main() { n   while (~scanf( %d , &n)) { n     int a; n     long long num = 0; n     for (int i = 1; i <= n; i++) { n       scanf( %d , &a); n       num += a; n       ans = max(ans, ++cont[num]); n     } n     printf( %d n , n - ans); n   } n   cont.clear(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k, d1[200005], d2[200005], ty, re1, re2, re3; n long long s, a[200005], b[200005], te; n vector<pair<long long, int> > v1, v2; n vector<long long> v3; n void bs(int lo, int up) { n   int mid = (lo + up) / 2; n   if (lo == up) { n     v3.clear(); n     for (int i = 0; i < v2.size(); i++) v3.push_back(v2[i].first * b[mid]); n     for (int i = 0; i < v1.size(); i++) { n       if (v1[i].first * a[mid] > s) break; n       int k1 = upper_bound(v3.begin(), v3.end(), s - v1[i].first * a[mid]) - n                v3.begin(); n       if (i + 1 + k1 >= k) { n         re1 = i, re2 = k - i - 2, re3 = mid; n         return; n       } n     } n     if (v3.size() >= k && v3[k - 1] <= s) { n       re1 = -1, re2 = k - 1; n       re3 = mid; n       return; n     } n   } n   v3.clear(); n   for (int i = 0; i < v2.size(); i++) v3.push_back(v2[i].first * b[mid]); n   for (int i = 0; i < v1.size(); i++) { n     if (v1[i].first * a[mid] > s) break; n     int k1 = upper_bound(v3.begin(), v3.end(), s - v1[i].first * a[mid]) - n              v3.begin(); n     if (i + 1 + k1 >= k) { n       re1 = i, re2 = k - i - 2, re3 = mid; n       bs(lo, mid); n       return; n     } n   } n   if (v3.size() >= k && v3[k - 1] <= s) { n     re1 = -1, re2 = k - 1; n     re3 = mid; n     bs(lo, mid); n     return; n   } n   bs(mid + 1, up); n } n int main() { n   cin >> n >> m >> k >> s; n   a[0] = 1e9; n   b[0] = 1e9; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     if (a[i] < a[i - 1]) n       d1[i] = i; n     else n       a[i] = a[i - 1], d1[i] = d1[i - 1]; n   } n   v1.clear(); n   for (int i = 1; i <= n; i++) { n     cin >> b[i]; n     if (b[i] < b[i - 1]) n       d2[i] = i; n     else n       b[i] = b[i - 1], d2[i] = d2[i - 1]; n   } n   v2.clear(); n   for (int i = 1; i <= m; i++) { n     cin >> ty; n     if (ty == 1) { n       cin >> te; n       v1.push_back(pair<long long, int>(te, i)); n     } else { n       cin >> te; n       v2.push_back(pair<long long, int>(te, i)); n     } n   } n   sort(v1.begin(), v1.end()); n   sort(v2.begin(), v2.end()); n   for (int i = 1; i < v1.size(); i++) v1[i].first += v1[i - 1].first; n   for (int i = 1; i < v2.size(); i++) v2[i].first += v2[i - 1].first; n   re3 = 1e9; n   v3.clear(); n   for (int i = 0; i < v2.size(); i++) v3.push_back(v2[i].first * b[n]); n   for (int i = 0; i < v1.size(); i++) { n     if (v1[i].first * a[n] > s) break; n     int k1 = n         upper_bound(v3.begin(), v3.end(), s - v1[i].first * a[n]) - v3.begin(); n     if (i + 1 + k1 >= k) { n       re1 = i, re2 = k - i - 2, re3 = n; n       break; n     } n   } n   if (v3.size() >= k && v3[k - 1] <= s) { n     re1 = -1, re2 = k - 1; n     re3 = n; n   } n   if (re3 != 1e9) { n     bs(1, n); n     cout << re3 << endl; n     for (int i = 0; i <= re1; i++) n       cout << v1[i].second <<     << d1[re3] << endl; n     for (int i = 0; i <= re2; i++) n       cout << v2[i].second <<     << d2[re3] << endl; n   } else n     cout << -1 << endl; n   return 0; n } n


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


#include <bits/stdc++.h> n const int inf = (1ll << 30) - 1; n const int maxn = (int)1e5 + 10; n using namespace std; n int dp[150][(1 << 16) + 100]; n int c[111]; n int r[111]; n int b[111]; n char temp[111]; n int cntR[(1 << 16) + 10]; n int cntB[(1 << 16) + 10]; n int n; n void solve() { n   memset(dp, -1, sizeof dp); n   queue<pair<pair<int, int>, int> > pq; n   scanf( %d , &n); n   int xx = 0; n   for (int i = 0; i < n; i++) { n     scanf( %s%d%d , temp, &r[i], &b[i]); n     c[i] = temp[0] ==  R  ? 1 : 0; n     xx += c[i]; n   } n   for (int i = 0; i < (1 << n); i++) { n     for (int j = 0; j < n; j++) { n       if (i & (1 << j)) { n         if (c[j]) n           cntR[i]++; n         else n           cntB[i]++; n       } n     } n   } n   dp[0][0] = 0; n   pq.push(make_pair(make_pair(0, 0), 0)); n   while (pq.size() > 0) { n     int x = pq.front().first.first; n     int y = pq.front().first.second; n     int mask = pq.front().second; n     pq.pop(); n     if (dp[x][mask] < y) continue; n     for (int i = 0; i < n; i++) { n       if (mask & (1 << i)) continue; n       int nmask = mask | (1 << i); n       int X = x, Y = y; n       if (r[i] >= cntR[mask]) { n         X += cntR[mask]; n       } else n         X += r[i]; n       if (b[i] >= cntB[mask]) { n         Y += cntB[mask]; n       } else n         Y += b[i]; n       if (dp[X][nmask] == -1 || dp[X][nmask] < Y) { n         dp[X][nmask] = Y; n         pq.push(make_pair(make_pair(X, Y), nmask)); n       } n     } n   } n   int sumA = 0, sumB = 0; n   for (int i = 0; i < n; i++) { n     sumA += r[i]; n     sumB += b[i]; n   } n   int ans = inf; n   for (int i = 0; i < 144; i++) { n     if (dp[i][(1 << n) - 1] == -1) continue; n     ans = min(ans, max(sumA - i, sumB - dp[i][(1 << n) - 1])); n   } n   printf( %d n , ans + n); n } n int main() { n   int t = 1; n   for (int i = 1; i <= t; i++) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> adj[300005]; n vector<int> vec; n int par[300005]; n int vis1[300005]; n int vis2[300005]; n int vis3[300005]; n int vis4[300005]; n int dia[300005]; n int root(int x) { return par[x] = ((par[x] == x) ? x : root(par[x])); } n void unite(int x, int y) { par[root(y)] = root(x); } n void dfs1(int x, int cnt, int &y, int &mx, int t) { n   if (t) n     vis1[x] = 1; n   else n     vis2[x] = 1; n   int i; n   for (i = 0; i < int(adj[x].size()); i++) { n     if ((!vis1[adj[x][i]] && t) || (!vis2[adj[x][i]] && !t)) { n       dfs1(adj[x][i], cnt + 1, y, mx, t); n     } n   } n   if (cnt > mx) { n     mx = cnt; n     y = x; n   } n } n bool dfs2(int x, int y) { n   if (x == y) { n     vec.push_back(y); n     return true; n   } n   vis3[x] = 1; n   int i; n   for (i = 0; i < int(adj[x].size()); i++) { n     if (!vis3[adj[x][i]]) { n       if (dfs2(adj[x][i], y)) { n         vec.push_back(adj[x][i]); n         return true; n       } n     } n   } n   return false; n } n void dfs3(int x, int y) { n   vis4[x] = 1; n   unite(y, x); n   int i; n   for (i = 0; i < int(adj[x].size()); i++) { n     if (!vis4[adj[x][i]]) { n       dfs3(adj[x][i], y); n     } n   } n } n int main() { n   int i, n, m, q, x, y, c; n   scanf( %d %d %d , &n, &m, &q); n   for (i = 0; i <= n; i++) par[i] = i; n   for (i = 0; i < m; i++) { n     scanf( %d %d , &x, &y); n     adj[x].push_back(y); n     adj[y].push_back(x); n   } n   int mx = 0; n   for (i = 1; i <= n; i++) { n     if (!vis1[i]) { n       vec.clear(); n       mx = 0; n       x = i; n       y = i; n       dfs1(i, 0, y, mx, 0); n       mx = 0; n       dfs1(y, 0, x, mx, 1); n       dfs2(x, y); n       int k = int(vec.size()); n       dfs3(x, vec[k / 2]); n       dia[vec[k / 2]] = k - 1; n     } n   } n   while (q--) { n     scanf( %d %d , &c, &x); n     if (c == 1) { n       x = root(x); n       printf( %d n , dia[x]); n     } else { n       scanf( %d , &y); n       x = root(x); n       y = root(y); n       if (x == y) continue; n       if (dia[x] >= dia[y]) { n         unite(x, y); n         dia[x] = max(dia[x], 1 + (dia[x] - dia[x] / 2) + (dia[y] - dia[y] / 2)); n       } else { n         unite(y, x); n         dia[y] = max(dia[y], 1 + (dia[x] - dia[x] / 2) + (dia[y] - dia[y] / 2)); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int n = 0, s = 0; n   cin >> n >> s; n   if (s > n) { n     if (s % n != 0) { n       cout << ((s / n) + 1); n     } else { n       cout << (s / n); n     } n   } else { n     cout << 1; n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n long long int solve(long long int a, long long int b) { n   long long int x = sqrt(8 * (a + b) + 1) - 1; n   return x / 2; n } n int main() { n   long long int a, b; n   cin >> a >> b; n   long long int x = solve(a, b); n   vector<long long int> w1, w2; n   for (long long int i = x; i > 0; i--) { n     if (a >= i) { n       a -= i; n       w1.push_back(i); n     } else { n       b -= i; n       w2.push_back(i); n     } n   } n   cout << w1.size() << endl; n   for (int i = 0; i < w1.size(); i++) cout << w1[i] <<    ; n   cout << endl; n   cout << w2.size() << endl; n   for (int i = 0; i < w2.size(); i++) cout << w2[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int m, n, a[200005], b[200005]; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   cin >> m; n   for (int i = 0; i < m; i++) cin >> b[i]; n   sort(a, a + n); n   sort(b, b + m); n   int x = 0, y = 0; n   int ans; n   int aa = (x * 2 + (n - x) * 3), bb = (y * 2 + (m - y) * 3); n   int max = aa - bb; n   for (int i = 0; i < m + n; i++) { n     if (a[x] == b[y]) { n       x++; n       while (a[x - 1] == a[x] && x != n) x++; n       y++; n       while (b[y - 1] == b[y] && y != m) y++; n     } else if (a[x] < b[y]) { n       x++; n       while (a[x - 1] == a[x] && x != n) x++; n     } else { n       y++; n       while (b[y - 1] == b[y] && y != m) y++; n     } n     ans = (x * 2 + (n - x) * 3) - (y * 2 + (m - y) * 3); n     if (ans > max) { n       max = ans; n       aa = (x * 2 + (n - x) * 3); n       bb = (y * 2 + (m - y) * 3); n     } n     if (x == n || y == m) break; n     i = x + y; n   } n   ans = n * 2 - m * 2; n   if (ans > max) { n     max = ans; n     aa = n * 2; n     bb = m * 2; n   } n   printf( %d:%d , aa, bb); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100500]; n int p[100500]; n int q[100500]; n vector<pair<int, int> > moves; n int n, h = -1; n bool asign(int x, int y) { return a[x] < a[y]; } n bool happy(int n) { n   if (n == 0) return true; n   if (n % 10 == 7 || n % 10 == 4) return happy(n / 10); n   return false; n } n void move(int x, int y) { n   if (x == y) return; n   moves.push_back(make_pair(x + 1, y + 1)); n   swap(q[x], q[y]); n   p[q[x]] = x; n   p[q[y]] = y; n   if (h == x) n     h = y; n   else if (h == y) n     h = x; n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     scanf( %d , &a[i]); n     p[i] = i; n     if (happy(a[i])) h = i; n   } n   sort(p, p + n, asign); n   if (h == -1) { n     for (int i = 0; i < n - 1; ++i) n       if (a[i] > a[i + 1]) { n         printf( -1 n ); n         return 0; n       } n     printf( 0 n ); n     return 0; n   } n   for (int i = 0; i < n; ++i) q[p[i]] = i; n   for (int i = 0; i < n; ++i) { n     if (p[i] == h) continue; n     move(i, h); n     move(h, p[i]); n   } n   printf( %d n , (int)moves.size()); n   for (int i = 0; i < moves.size(); ++i) n     printf( %d %d n , moves[i].first, moves[i].second); n   return 0; n } n