#include <bits/stdc++.h> n using namespace std; n int min(int a, int b) { n   if (a < b) return a; n   return b; n } n double min(double a, double b) { n   if (a < b) return a; n   return b; n } n int max(int a, int b) { n   if (a > b) return a; n   return b; n } n int ABS(int a) { n   if (a < 0) return -a; n   return a; n } n int parent[100004], h[100005]; n void make_set(int v) { parent[v] = v; } n int find_set(int v) { n   if (v == parent[v]) return v; n   return parent[v] = find_set(parent[v]); n } n void union_sets(int a, int b) { n   a = find_set(a); n   b = find_set(b); n   if (a != b) { n     if (h[a] > h[b]) swap(a, b); n     parent[b] = a; n   } n } n pair<int, int> getCharHash(int p1, int p2, char c) { n   return make_pair(p1 * (c -  a ), p2 * (c -  a )); n } n vector<pair<int, int> > p; n int double_area(int x1, int y1, int x2, int y2, int x3, int y3) { n   return (x1 - x2) * (y2 + y1) + (x2 - x3) * (y3 + y2) + (x3 - x1) * (y1 + y3); n } n int tree[4000000]; n int c[1000004]; n int pref_xors[1000004]; n int next_pos[1000004]; n int pref_unique_xors[1000006]; n map<int, int> M; n set<int> uniques; n vector<pair<pair<int, int>, int> > q; n vector<pair<int, int> > ans; n int suf_sum(int l, int r, int nl, int nr, int node) { n   if (l == nl && r == nr) { n     return tree[node]; n   } n   int m = (nr + nl) / 2; n   if (r <= m) { n     return suf_sum(l, r, nl, m, node * 2); n   } n   if (l > m) { n     return suf_sum(l, r, m + 1, nr, node * 2 + 1); n   } n   return suf_sum(l, m, nl, m, node * 2) ^ n          suf_sum(m + 1, r, m + 1, nr, node * 2 + 1); n } n void update(int l, int r, int node, int pos, int value) { n   if (l == r) { n     tree[node] ^= value; n     return; n   } n   int m = (l + r) / 2; n   if (pos <= m) { n     update(l, m, node * 2, pos, value); n   } else { n     update(m + 1, r, node * 2 + 1, pos, value); n   } n   tree[node] = tree[node * 2] ^ tree[node * 2 + 1]; n   return; n } n int XOR(int i, int j) { n   if (i == 0) { n     return pref_xors[j]; n   } n   return pref_xors[j] ^ pref_xors[i - 1]; n } n int main() { n   int n; n   int p = 1; n   scanf( %d , &n); n   while (p <= n) p *= 2; n   for (int i = 0; i < n; ++i) { n     scanf( %d , c + i); n     if (i == 0) n       pref_xors[0] = c[0]; n     else n       pref_xors[i] = pref_xors[i - 1] ^ c[i]; n   } n   for (int i = n - 1; i >= 0; --i) { n     if (M[c[i]]) { n       next_pos[i] = M[c[i]]; n     } else { n       next_pos[i] = n; n     } n     M[c[i]] = i; n   } n   int m; n   scanf( %d , &m); n   int a, b; n   for (int i = 0; i < m; ++i) { n     scanf( %d%d , &a, &b); n     a--; n     b--; n     q.push_back(make_pair(make_pair(a, b), i)); n   } n   sort(q.begin(), q.end()); n   for (int i = q[0].first.first; i < n; ++i) { n     if (i == 0) { n       pref_unique_xors[0] = c[0]; n       uniques.insert(c[0]); n     } else { n       if (uniques.find(c[i]) != uniques.end()) { n         pref_unique_xors[i] = pref_unique_xors[i - 1]; n       } else { n         pref_unique_xors[i] = pref_unique_xors[i - 1] ^ c[i]; n         uniques.insert(c[i]); n       } n     } n   } n   int j = q[0].first.first; n   for (int i = 0; i < m; ++i) { n     a = q[i].first.first; n     b = q[i].first.second; n     if (a != j) { n       for (int k = j; k < a; ++k) { n         update(0, p - 1, 1, next_pos[k], c[k]); n       } n       j = a; n     } n     int answer = n         XOR(a, b) ^ pref_unique_xors[b] ^ suf_sum(b + 1, p - 1, 0, p - 1, 1); n     ans.push_back(make_pair(q[i].second, answer)); n   } n   sort(ans.begin(), ans.end()); n   for (int i = 0; i < m; ++i) { n     printf( %d n , ans[i].second); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long k, a, b; n   cin >> k >> a >> b; n   if (k == 1) { n     cout << a + b << endl; n     return 0; n   } n   long long ret = (a / k) + (b / k); n   long long la = a % k, lb = b % k; n   if ((la / (k - 1) + (la % (k - 1) > 0)) <= b / k && n       (lb / (k - 1) + (lb % (k - 1) > 0)) <= a / k) n     cout << ret << endl; n   else n     cout << -1 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n template <typename T> n struct modular { n   constexpr modular() : val(0) {} n   constexpr modular(const modular<T>& _m) : val(_m.val) {} n   template <typename U> n   constexpr modular(const U& _r = U()) { n     val = -MOD <= _r && _r < MOD ? _r : _r % MOD; n     if (val < 0) { n       val += MOD; n     } n   } n   const T operator()() { return val; } n   template <typename U> n   explicit operator U() const { n     return static_cast<U>(val); n   } n   modular<T>& operator+=(const modular<T>& _m) { n     if ((val += _m.val) >= MOD) { n       val -= MOD; n     } n     return *this; n   } n   modular<T>& operator-=(const modular<T>& _m) { n     if ((val -= _m.val) < 0) { n       val += MOD; n     } n     return *this; n   } n   modular<T>& operator*=(const modular<T>& _m) { n     val = modular<T>(static_cast<int64_t>(val) * static_cast<int64_t>(_m.val)) n               .val; n     return *this; n   } n   modular<T>& operator/=(const modular<T>& _m) { n     T a = _m.val, b = MOD, u = 0, v = 1; n     while (a != 0) { n       T q = b / a; n       b -= q * a; n       swap(a, b); n       u -= q * v; n       swap(u, v); n     } n     return *this *= u; n   } n   modular<T>& operator=(const modular<T>& _m) { n     val = _m.val; n     return *this; n   } n   template <typename U> n   modular<T>& operator+=(const U& _r) { n     return *this += modular<T>(_r); n   } n   template <typename U> n   modular<T>& operator-=(const U& _r) { n     return *this -= modular<T>(_r); n   } n   template <typename U> n   modular<T>& operator*=(const U& _r) { n     return *this *= modular<T>(_r); n   } n   template <typename U> n   modular<T>& operator/=(const U& _r) { n     return *this /= modular<T>(_r); n   } n   template <typename U> n   modular<T>& operator=(const U& _r) { n     val = modular<T>(_r).val; n     return *this; n   } n   modular<T> operator-() { return modular<T>(-val); } n   template <typename U> n   friend bool operator==(const modular<U>&, const modular<U>&); n   friend std::istream& operator>>(std::istream& os, modular<T>& _m) { n     os >> _m.val; n     _m *= 1; n     return os; n   } n   friend std::ostream& operator<<(std::ostream& os, const modular<T>& _m) { n     return os << _m.val; n   } n   template <typename U> n   modular<T> exp(U e) { n     modular<T> res = 1; n     modular<T> b = val; n     if (e < 0) { n       b = 1 / b; n       e *= -1; n     } n     for (; e; e >>= 1) { n       if (e & 1) { n         res *= b; n       } n       b *= b; n     } n     return res; n   } n  n  private: n   T val; n }; n template <typename T> n inline modular<T> operator+(const modular<T>& _lhs, const modular<T>& _rhs) { n   return modular<T>(_lhs) += _rhs; n } n template <typename T, typename U> n inline modular<T> operator+(const modular<T>& _lhs, const U& _rhs) { n   return modular<T>(_lhs) += _rhs; n } n template <typename T, typename U> n inline modular<T> operator+(const U& _lhs, const modular<T>& _rhs) { n   return modular<T>(_lhs) += _rhs; n } n template <typename T> n inline modular<T> operator-(const modular<T>& _lhs, const modular<T>& _rhs) { n   return modular<T>(_lhs) -= _rhs; n } n template <typename T, typename U> n inline modular<T> operator-(const modular<T>& _lhs, const U& _rhs) { n   return modular<T>(_lhs) -= _rhs; n } n template <typename T, typename U> n inline modular<T> operator-(const U& _lhs, const modular<T>& _rhs) { n   return modular<T>(_lhs) -= _rhs; n } n template <typename T> n inline modular<T> operator*(const modular<T>& _lhs, const modular<T>& _rhs) { n   return modular<T>(_lhs) *= _rhs; n } n template <typename T, typename U> n inline modular<T> operator*(const modular<T>& _lhs, const U& _rhs) { n   return modular<T>(_lhs) *= _rhs; n } n template <typename T, typename U> n inline modular<T> operator*(const U& _lhs, const modular<T>& _rhs) { n   return modular<T>(_lhs) *= _rhs; n } n template <typename T> n inline modular<T> operator/(const modular<T>& _lhs, const modular<T>& _rhs) { n   return modular<T>(_lhs) /= _rhs; n } n template <typename T, typename U> n inline modular<T> operator/(const modular<T>& _lhs, const U& _rhs) { n   return modular<T>(_lhs) /= _rhs; n } n template <typename T, typename U> n inline modular<T> operator/(const U& _lhs, const modular<T>& _rhs) { n   return modular<T>(_lhs) /= _rhs; n } n template <typename T> n inline bool operator==(const modular<T>& _lhs, const modular<T>& _rhs) { n   return _lhs.val == _rhs.val; n } n template <typename T, typename U> n inline bool operator==(const modular<T>& _lhs, const U& _rhs) { n   return _lhs == modular<T>(_rhs); n } n template <typename T, typename U> n inline bool operator==(const U& _lhs, const modular<T>& _rhs) { n   return modular<T>(_lhs) == _rhs; n } n template <typename T> n inline bool operator!=(const modular<T>& _lhs, const modular<T>& _rhs) { n   return !(_lhs == _rhs); n } n template <typename T, typename U> n inline bool operator!=(const modular<T>& _lhs, const U& _rhs) { n   return !(_lhs == _rhs); n } n template <typename T, typename U> n inline bool operator!=(const U& _lhs, const modular<T>& _rhs) { n   return !(_lhs == _rhs); n } n void __solve() { n   int n; n   cin >> n; n   vector<int> pa(n); n   pa[0] = -1; n   vector<vector<int>> g(n); n   for (int i = 1; i < n; i++) { n     int x; n     cin >> x; n     x--; n     pa[i] = x; n     g[x].push_back(i); n   } n   vector<array<modular<int>, 2>> dn(n); n   for (int u = n - 1; u >= 0; u--) { n     modular<int> x = 1, z = 1; n     for (int v : g[u]) { n       x *= dn[v][0] + dn[v][1]; n       z *= dn[v][0]; n     } n     dn[u][0] = z; n     dn[u][1] = x; n   } n   vector<array<modular<int>, 2>> up(n); n   up[0][0] = up[0][1] = 1; n   for (int u = 0; u < n; u++) { n     int m = g[u].size(); n     { n       vector<modular<int>> pref(m + 1), suff(m + 1); n       pref[0] = suff[m] = 1; n       for (int i = 0; i < m; i++) { n         pref[i + 1] = pref[i] * dn[g[u][i]][0]; n       } n       for (int i = m - 1; i >= 0; i--) { n         suff[i] = suff[i + 1] * dn[g[u][i]][0]; n       } n       for (int i = 0; i < m; i++) { n         int v = g[u][i]; n         up[v][0] = up[u][0] * pref[i] * suff[i + 1]; n       } n     } n     { n       vector<modular<int>> pref(m + 1), suff(m + 1); n       pref[0] = suff[m] = 1; n       for (int i = 0; i < m; i++) { n         pref[i + 1] = pref[i] * (dn[g[u][i]][0] + dn[g[u][i]][1]); n       } n       for (int i = m - 1; i >= 0; i--) { n         suff[i] = suff[i + 1] * (dn[g[u][i]][0] + dn[g[u][i]][1]); n       } n       for (int i = 0; i < m; i++) { n         int v = g[u][i]; n         up[v][1] = up[v][0] + up[u][1] * pref[i] * suff[i + 1]; n       } n     } n   } n   for (int i = 0; i < n; i++) { n     modular<int> res = dn[i][1] * up[i][1]; n     cout << res <<    ; n   } n } n void solve() { n   int n; n   cin >> n; n   vector<int> pa(n); n   pa[0] = -1; n   vector<vector<int>> g(n); n   for (int i = 1; i < n; i++) { n     int x; n     cin >> x; n     x--; n     pa[i] = x; n     g[x].push_back(i); n   } n   vector<modular<int>> dn(n); n   for (int u = n - 1; u >= 0; u--) { n     dn[u] = 1; n     for (int v : g[u]) { n       dn[u] *= dn[v] + 1; n     } n   } n   vector<modular<int>> up(n); n   up[0] = 1; n   for (int u = 0; u < n; u++) { n     int m = g[u].size(); n     vector<modular<int>> pref(m + 1), suff(m + 1); n     pref[0] = suff[m] = 1; n     for (int i = 0; i < m; i++) { n       int v = g[u][i]; n       pref[i + 1] = pref[i] * (dn[v] + 1); n     } n     for (int i = m - 1; i >= 0; i--) { n       int v = g[u][i]; n       suff[i] = suff[i + 1] * (dn[v] + 1); n     } n     for (int i = 0; i < m; i++) { n       int v = g[u][i]; n       up[v] = 1 + up[u] * pref[i] * suff[i + 1]; n     } n   } n   for (int i = 0; i < n; i++) { n     cout << dn[i] * up[i] <<    ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N; n vector<string> a; n vector<int> big; n vector<int> mark; n string s; n string t; n int main() { n   cin >> N; n   string s1; n   for (int i = 0; i < N; i++) { n     cin >> s1; n     a.push_back(s1); n   } n   cin >> s; n   cin >> t; n   for (int i = 0; i < s.size(); i++) { n     string s1 = s.substr(i, 1); n     if (s1[0] <=  Z ) { n       big.push_back(1); n     } else { n       big.push_back(0); n     } n   } n   for (int i = 0; i < s.length(); i++) mark.push_back(0); n   transform(s.begin(), s.end(), s.begin(), ::tolower); n   for (int i = 0; i < N; i++) n     transform(a[i].begin(), a[i].end(), a[i].begin(), ::tolower); n   for (int i = 0; i < N; i++) { n     int start = 0; n     while (s.substr(start).find(a[i]) != -1) { n       start += s.substr(start).find(a[i]) + 1; n       for (int j = start - 1; j <= start + a[i].length() - 2; j++) mark[j] = 1; n     } n   } n   string answ; n   for (int i = 0; i < s.length(); i++) { n     if (mark[i] == 0) n       answ.append(s.substr(i, 1)); n     else { n       if (s.substr(i, 1) == t) { n         if (t ==  a ) n           answ.append( b ); n         else n           answ.append( a ); n       } else { n         answ.append(t); n       } n     } n   } n   for (int i = 0; i < answ.length(); i++) { n     if (big[i]) { n       string s1 = answ.substr(i, 1); n       transform(s1.begin(), s1.end(), s1.begin(), ::toupper); n       string s2 = answ.substr(0, i); n       s2.append(s1); n       if (i + 1 < answ.length()) s2.append(answ.substr(i + 1)); n       answ = s2; n     } n   } n   cout << answ << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct w { n   int c, mi; n } tr[1010 * 1010 * 8]; n struct ww { n   int h, b, l, r, x, y; n } c[1010 * 1010]; n int i, j, k, n, m, s, vx, vy, t, ans; n int a[1010][1010], b[1010][1010]; n double d[1010 * 1010]; n long long an; n inline bool cc1(const ww &a, const ww &b) { return a.b > b.b; } n inline void update(int x) { tr[x].mi = min(tr[x * 2].mi, tr[x * 2 + 1].mi); } n inline void Cover(int x, int y) { n   tr[x].c = max(tr[x].c, y); n   tr[x].mi = max(tr[x].mi, y); n } n inline void renew(int x) { n   if (tr[x].c) Cover(x * 2, tr[x].c), Cover(x * 2 + 1, tr[x].c); n   tr[x].c = 0; n } n void cover(int q, int x, int y, int l, int r, int h) { n   if (l <= x && y <= r) { n     Cover(q, h); n     return; n   } n   renew(q); n   int mid = (x + y) / 2; n   if (l <= mid) cover(q * 2, x, mid, l, r, h); n   if (mid < r) cover(q * 2 + 1, mid + 1, y, l, r, h); n   update(q); n } n void cal(int q, int x, int y, int l, int r) { n   if (l <= x && y <= r) { n     ans = min(ans, tr[q].mi); n     return; n   } n   renew(q); n   int mid = (x + y) / 2; n   if (l <= mid) cal(q * 2, x, mid, l, r); n   if (mid < r) cal(q * 2 + 1, mid + 1, y, l, r); n } n int main() { n   scanf( %d%d%d , &n, &vx, &vy); n   for (i = 1; i <= n; i++) n     for (j = 1; j <= n; j++) scanf( %d , &a[i][j]); n   vx = -vx, vy = -vy; n   if (vx < 0) { n     vx = -vx; n     for (j = 1; j <= n; j++) n       for (i = 1; i <= n / 2; i++) swap(a[i][j], a[n - i + 1][j]); n   } n   if (vy < 0) { n     vy = -vy; n     for (i = 1; i <= n; i++) n       for (j = 1; j <= n / 2; j++) swap(a[i][j], a[i][n - j + 1]); n   } n   if (!vx) { n     swap(vx, vy); n     for (i = 1; i <= n; i++) n       for (j = 1; j <= n; j++) b[i][j] = a[i][j]; n     for (i = 1; i <= n; i++) n       for (j = 1; j <= n; j++) a[j][n - i + 1] = b[i][j]; n   } n   sort(d + 1, d + t + 1); n   for (i = 1; i <= t; i++) n     if (!m || d[m] < d[i]) d[++m] = d[i]; n   double ay = 1. * vy / vx; n   for (i = 0; i <= n; i++) n     for (j = 0; j <= n; j++) d[++m] = j - i * ay; n   sort(d + 1, d + m + 1); n   for (i = 1; i <= m; i++) n     if (!t || d[t] + (1e-9) < d[i]) d[++t] = d[i]; n   for (i = 1; i <= n; i++) n     for (j = 0; j <= n - 1; j++) { n       int l = lower_bound(d + 1, d + t + 1, j - i * ay - (1e-9)) - d; n       int r = lower_bound(d + 1, d + t + 1, j + 1 - (i - 1) * ay - (1e-9)) - d; n       c[++s] = (ww){a[i][j + 1], i + j, l * 2, r * 2}; n     } n   m = t * 2; n   sort(c + 1, c + s + 1, cc1); n   for (i = 1; i <= s; i++) { n     ans = 2000000000; n     cal(1, 1, m, c[i].l, c[i].r); n     if (ans < c[i].h) an += c[i].h - ans; n     cover(1, 1, m, c[i].l, c[i].r, c[i].h); n   } n   printf( %I64d n , an); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long arr[1000007]; n long long cs[1000007]; n long long ps[1000007]; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     for (int i = 1; i <= n; i++) cin >> arr[i]; n     for (int i = 1; i <= n; i++) { n       if (i % 2) { n         if (arr[i] > 0) n           cout << -1 * arr[i] <<    ; n         else n           cout << arr[i] <<    ; n       } else { n         if (arr[i] < 0) n           cout << -1 * arr[i] <<    ; n         else n           cout << arr[i] <<    ; n       } n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n double const PI = 4 * atan(1.0); n using namespace std; n int main() { n   long long a, b, x1, y1, x2, y2; n   scanf( %I64d %I64d %I64d %I64d %I64d %I64d , &a, &b, &x1, &y1, &x2, &y2); n   a = 2 * a; n   b = 2 * b; n   long long t1 = (x1 + y1); n   long long t2 = (x2 + y2); n   long long g1 = (x1 - y1); n   long long g2 = (x2 - y2); n   if (t1 < 0) n     t1 = t1 / a - 1; n   else n     t1 = t1 / a; n   if (t2 < 0) n     t2 = t2 / a - 1; n   else n     t2 = t2 / a; n   if (g1 < 0) n     g1 = g1 / b - 1; n   else n     g1 = g1 / b; n   if (g2 < 0) n     g2 = g2 / b - 1; n   else n     g2 = g2 / b; n   printf( %I64d , max(abs(t1 - t2), abs(g1 - g2))); 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 int n, c; n   cin >> n >> c; n   long int ar[n], i, sum = 0; n   for (i = 0; i < n; ++i) { n     cin >> ar[i]; n     if (i != 0) { n       if ((ar[i] - ar[i - 1]) > c) n         sum = 0; n       else n         sum++; n     } n   } n   cout << sum + 1; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5; n const long long mol = 1e9 + 7; n int fa[maxn + 11], siz[maxn + 11], x[maxn + 11], y[maxn + 11]; n bool cir[maxn + 11]; n vector<int> row, cul; n int get(int x) { return x == fa[x] ? x : fa[x] = get(fa[x]); } n void merge(int x, int y) { n   int fax = get(x); n   int fay = get(y); n   if (fax == fay) { n     cir[fax] = true; n     return; n   } n   fa[fay] = fax; n   cir[fax] |= cir[fay]; n   siz[fax] += siz[fay]; n } n long long qpow(long long a, long long b) { n   long long ans = 1; n   while (b) { n     if (b & 1) ans = ans * a % mol; n     a = a * a % mol; n     b >>= 1; n   } n   return ans; n } n long long sub(long long a, long long b) { n   a -= b; n   if (a < 0) a += mol; n   return a; n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d %d , &x[i], &y[i]); n     row.emplace_back(x[i]); n     cul.emplace_back(y[i]); n   } n   sort((row).begin(), (row).end()); n   row.erase(unique((row).begin(), (row).end()), row.end()); n   sort((cul).begin(), (cul).end()); n   cul.erase(unique((cul).begin(), (cul).end()), cul.end()); n   int m = row.size() + cul.size(); n   for (int i = 1; i <= m; i++) fa[i] = i, siz[i] = 1, cir[i] = false; n   for (int i = 1; i <= n; i++) { n     x[i] = lower_bound((row).begin(), (row).end(), x[i]) - row.begin() + 1; n     y[i] = lower_bound((cul).begin(), (cul).end(), y[i]) - cul.begin() + n            row.size() + 1; n     merge(x[i], y[i]); n   } n   long long ans = 1; n   for (int i = 1; i <= m; i++) n     if (get(i) == i) { n       int p = siz[i]; n       long long t = qpow(2, p); n       if (!cir[i]) t = sub(t, 1); n       ans = ans * t % mol; n     } n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T gcd(T a, T b) { n   T r; n   while (b != 0) { n     r = a % b; n     a = b; n     b = r; n   } n   return a; n } n template <class T> n T lcm(T a, T b) { n   return a / gcd(a, b) * b; n } n template <class T> n int getbit(T s, int i) { n   return (s >> i) & 1; n } n template <class T> n T onbit(T s, int i) { n   return s | (T(1) << i); n } n template <class T> n T offbit(T s, int i) { n   return s & (~(T(1) << i)); n } n const double PI = 2 * acos(0.0); n const double eps = 1e-9; n const int infi = (1 << 31) - 1; n const long long Linfi = (long long)1e18; n const int MOD = 1000000007; n int n, cnt = 0; n int a[110005], p[110005], u[110005], vitri[110005]; n vector<pair<int, int> > ans; n void sang(int n) { n   memset(p, 0, sizeof(p)); n   for (int i = 2; i <= sqrt(n); i++) { n     if (p[i] == 0) { n       for (int j = i * i; j <= n; j += i) p[j] = 1; n     } n   } n   for (int i = 2; i <= n; i++) n     if (p[i] == 0) u[++cnt] = i - 1; n } n void solve() { n   for (int i = 1; i <= n; i++) { n     int pos = vitri[i]; n     if (pos == i) continue; n     int delta = pos - i; n     int tmp = lower_bound(u + 1, u + cnt + 1, delta) - u; n     if (u[tmp] > delta) tmp--; n     int x = u[tmp]; n     int k = pos - x; n     swap(a[k], a[pos]); n     ans.push_back(make_pair(k, pos)); n     swap(vitri[a[k]], vitri[a[pos]]); n     while (k > i) { n       while (u[tmp] > k - i) tmp--; n       x = u[tmp]; n       if (x == 0) break; n       swap(a[k], a[k - x]); n       ans.push_back(make_pair(k - x, k)); n       swap(vitri[a[k]], vitri[a[k - x]]); n       k -= x; n       if (k == i) break; n       if (ans.size() >= 500000) return; n     } n   } n   cout << ans.size() << endl; n   for (int i = 0; i < ans.size(); i++) { n     printf( %d %d n , ans[i].first, ans[i].second); n   } n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     vitri[a[i]] = i; n   } n   sang(110001); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[3005]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n   } n   int ans = 0; n   for (int i = 1; i < n; i++) { n     for (int j = 0; j < i; j++) { n       if (a[i] < a[j]) { n         ans++; n       } n     } n   } n   if (ans & 1) n     ans = (ans << 1) - 1; n   else n     ans <<= 1; n   printf( %.6f n , (double)ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = int(1e5) + 5; n const int INF = int(1e9) + 7; n const long long MINF = 1e18; n vector<int> g[N]; n set<int> x; n int a[N]; n int b[N]; n vector<int> ans; n void solve() { n   int n, m; n   cin >> n >> m; n   for (int i = 1; i <= m; i++) { n     int l, r; n     cin >> l >> r; n     g[l].push_back(r); n     g[r].push_back(l); n   } n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     if (a[i] == 0) { n       x.insert(i); n     } n   } n   int kol = 0; n   while (x.size() != 0) { n     int num = *x.begin(); n     x.erase(num); n     ans.push_back(num); n     kol++; n     b[num]++; n     int v = num; n     for (int i = 0; i < g[v].size(); i++) { n       if (b[g[v][i]] == a[g[v][i]]) { n         b[g[v][i]]++; n         x.erase(g[v][i]); n       } else { n         b[g[v][i]]++; n         if (b[g[v][i]] == a[g[v][i]]) { n           x.insert(g[v][i]); n         } n       } n     } n     if (kol == n && x.size() != 0) { n       cout << -1; n       return; n     } n   } n   cout << ans.size() << endl; n   for (int i = 0; i < ans.size(); i++) cout << ans[i] <<    ; n } n int main() { n   ios_base::sync_with_stdio(0); n   int TT = 1; n   while (TT--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k; n int main() { n   cin >> n >> k; n   long long falta = (n % k); n   long long ans = n + (k - falta); n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1 << 24; n int n, f[MAXN], Tohka; n bool p[MAXN]; n int lowbit(int first) { return first & -first; } n int main() { n   cin >> n; n   char str[4]; n   for (int i = 1; i <= n; ++i) { n     scanf( %s , str); n     int s = 0; n     for (int j = 0; j < 3; ++j) s |= 1 << (str[j] -  a ); n     ++f[s]; n   } n   for (int i = 0; i < 24; ++i) n     for (int j = 1; j < MAXN; ++j) n       if (!(j & (1 << i))) f[j] += f[j + (1 << i)]; n   p[0] = 0; n   for (int i = 1; i < MAXN; ++i) n     p[i] = p[i - lowbit(i)] ^ 1, f[i] *= (p[i]) ? 1 : -1; n   for (int i = 0; i < 24; ++i) n     for (int j = MAXN - 1; j >= 0; --j) n       if (j & (1 << i)) f[j] += f[j - (1 << i)]; n   for (int i = 0; i < MAXN; ++i) Tohka ^= f[i] * f[i]; n   cout << Tohka << endl; n   fclose(stdin); n   fclose(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int T; n   cin >> T; n   for (int x = 0; x < T; x++) { n     vector<long long> arry(7); n     for (int i = 0; i < 7; i++) cin >> arry[i]; n     long long least, all_sum; n     all_sum = arry[6]; n     least = arry[0]; n     vector<long long> a(3); n     a[0] = least; n     long long ab = all_sum - least; n     a[1] = arry[1]; n     a[2] = all_sum - a[1] - a[0]; n     cout << a[0] <<     << a[1] <<     << a[2] << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100000 + 15; n struct Node { n   int x0, y0, x1, y1; n   int num; n   int nex; n   int x, y; n   int tim; n   Node() { x0 = y0 = x1 = y1 = num = nex = tim = x = y = 0; } n   Node(int x0, int y0, int x1, int y1, int num) n       : x0(x0), y0(y0), x1(x1), y1(y1), num(num) {} n   int clear() { n     nex = x = y = tim = 0; n     return 0; n   } n } sz[maxn]; n struct Que { n   int x0, y0; n   long long tt; n   int dx, dy; n   int nex, x, y, tim; n   Que() { x0 = y0 = tt = dx = dy = nex = x = y = tim = 0; } n   Que(int x0, int y0, int dx, int dy, long long tt) n       : x0(x0), y0(y0), dx(dx), dy(dy), tt(tt) {} n   int clear() { n     nex = x = y = tim = 0; n     return 0; n   } n } que[maxn]; n struct Bj { n   int key1, key2; n   int num; n   int sy; n } bj[2 * maxn], bj2[2 * maxn]; n int sum, ss; n int n, bod, m; n struct TT { n   int wz; n   int x, y; n   long long tim; n } lca[52][maxn]; n int abs(int x) { n   if (x < 0) return -x; n   return x; n } n bool cmp(Bj a, Bj b) { n   if (a.key1 == b.key1) return a.key2 < b.key2; n   return a.key1 < b.key1; n } n bool sam(int x, int y) { n   if (x == 0 && y == 0) return true; n   if (x == 0 || y == 0) return false; n   return 1ll * x * y > 0; n } n int tree[maxn * 4]; n int down(int root) { n   if (tree[root] == 0) return 0; n   int x = tree[root]; n   tree[root << 1] = tree[root << 1 | 1] = x; n   tree[root] = 0; n   return 0; n } n int ins(int root, int l, int r, int x, int y, int z) { n   if (l > y || r < x) return 0; n   if (x <= l && r <= y) { n     tree[root] = z; n     return 0; n   } n   down(root); n   int mid = (l + r) >> 1; n   ins(root << 1, l, mid, x, y, z); n   ins(root << 1 | 1, mid + 1, r, x, y, z); n   return 0; n } n int found(int root, int l, int r, int x) { n   if (l > x || r < x) return 0; n   if (l == r) return tree[root]; n   down(root); n   int mid = (l + r) >> 1; n   if (mid >= x) return found(root << 1, l, mid, x); n   return found(root << 1 | 1, mid + 1, r, x); n } n int done(int ddx, int ddy) { n   sum = 0; n   memset(tree, 0, sizeof(tree)); n   for (int i = 1; i <= n; i++) n     if (!sam(ddx, sz[i].x1 - sz[i].x0) && !sam(ddy, sz[i].y1 - sz[i].y0)) { n       sum++; n       bj[sum].sy = 0; n       bj[sum].num = i; n       bj[sum].key1 = -ddx * sz[i].x0; n       bj[sum].key2 = -ddy * sz[i].y0; n     } n   sort(bj + 1, bj + sum + 1, cmp); n   ss = 0; n   for (int i = 1; i <= n; i++) n     if (sam(ddx, sz[i].x1 - sz[i].x0) && sam(ddy, sz[i].y1 - sz[i].y0)) { n       ss++; n       bj2[ss].sy = 0; n       bj2[ss].num = i; n       bj2[ss].key1 = -ddx * sz[i].x0; n       bj2[ss].key2 = -ddy * sz[i].y0; n     } n   for (int i = 1; i <= m; i++) n     if (sam(ddx, que[i].dx) && sam(ddy, que[i].dy)) { n       ss++; n       bj2[ss].sy = 1; n       bj2[ss].num = i; n       bj2[ss].key1 = -ddx * que[i].x0; n       bj2[ss].key2 = -ddy * que[i].y0; n     } n   sort(bj2 + 1, bj2 + ss + 1, cmp); n   int kk = 1; n   for (int i = 1; i <= ss; i++) { n     while (kk <= sum && n            (bj[kk].key1 <= bj2[i].key1 && bj[kk].key2 <= bj2[i].key2)) { n       int ge = bj[kk].num; n       if (ddx == 0) n         ins(1, 0, bod, min(sz[ge].x1, sz[ge].x0), max(sz[ge].x1, sz[ge].x0), n             ge); n       else n         ins(1, 0, bod, min(sz[ge].y1, sz[ge].y0), max(sz[ge].y1, sz[ge].y0), n             ge); n       kk++; n     } n     int ge = bj2[i].num, gs = bj2[i].sy; n     if (gs == 0) { n       if (ddx == 0) { n         sz[ge].nex = found(1, 0, bod, sz[ge].x0); n         if (sz[ge].nex == 0) continue; n         sz[ge].x = sz[ge].x0; n         sz[ge].y = sz[sz[ge].nex].y0; n         sz[ge].tim = abs(sz[ge].y - sz[ge].y1); n       } else { n         sz[ge].nex = found(1, 0, bod, sz[ge].y0); n         if (sz[ge].nex == 0) continue; n         sz[ge].x = sz[sz[ge].nex].x0; n         sz[ge].y = sz[ge].y0; n         sz[ge].tim = abs(sz[ge].x - sz[ge].x1); n       } n     } else { n       if (ddx == 0) { n         que[ge].nex = found(1, 0, bod, que[ge].x0); n         if (que[ge].nex == 0) continue; n         que[ge].x = que[ge].x0; n         que[ge].y = sz[que[ge].nex].y0; n         que[ge].tim = abs(que[ge].y - que[ge].y0); n       } else { n         que[ge].nex = found(1, 0, bod, que[ge].y0); n         if (que[ge].nex == 0) continue; n         que[ge].x = sz[que[ge].nex].x0; n         que[ge].y = que[ge].y0; n         que[ge].tim = abs(que[ge].x - que[ge].x0); n       } n     } n   } n   return 0; n } n int pre[maxn * 2], nex[maxn * 2]; n int done2() { n   sum = 0; n   for (int i = 1; i <= n; i++) n     if (sz[i].x0 == sz[i].x1) { n       sum++; n       bj[sum].key1 = sz[i].x0; n       bj[sum].key2 = sz[i].y0; n       bj[sum].num = i; n       bj[sum].sy = 0; n     } n   for (int i = 1; i <= m; i++) n     if (que[i].dx == 0) { n       sum++; n       bj[sum].key1 = que[i].x0; n       bj[sum].key2 = que[i].y0; n       bj[sum].num = i; n       bj[sum].sy = 1; n     } n   sort(bj + 1, bj + sum + 1, cmp); n   for (int i = 1; i <= sum; i++) n     if (i != 1 && bj[i].key1 == bj[i - 1].key1) { n       if (bj[i - 1].sy == 0) n         pre[i] = i - 1; n       else n         pre[i] = pre[i - 1]; n     } else n       pre[i] = 0; n   for (int i = sum; i >= 1; i--) n     if (i != sum && bj[i].key1 == bj[i + 1].key1) { n       if (bj[i + 1].sy == 0) n         nex[i] = i + 1; n       else n         nex[i] = nex[i + 1]; n     } else n       nex[i] = 0; n   for (int i = 1; i <= sum; i++) n     if (bj[i].sy == 0) { n       int q = bj[i].num, pr = bj[pre[i]].num, ne = bj[nex[i]].num; n       if (sz[q].y1 > sz[q].y0 && ne != 0 && n           (min(sz[ne].y0, sz[ne].y1) - sz[q].y1 < sz[q].tim || n            sz[q].nex == 0)) { n         sz[q].tim = min(sz[ne].y0, sz[ne].y1) - sz[q].y1; n         sz[q].nex = ne; n         sz[q].y = min(sz[ne].y0, sz[ne].y1); n         sz[q].x = sz[q].x0; n       } n       if (sz[q].y1 < sz[q].y0 && pr != 0 && n           (sz[q].y1 - max(sz[pr].y0, sz[pr].y1) < sz[q].tim || n            sz[q].nex == 0)) { n         sz[q].tim = sz[q].y1 - max(sz[pr].y0, sz[pr].y1); n         sz[q].nex = pr; n         sz[q].y = max(sz[pr].y0, sz[pr].y1); n         sz[q].x = sz[q].x0; n       } n     } else { n       int q = bj[i].num, pr = bj[pre[i]].num, ne = bj[nex[i]].num; n       if (ne != 0 && que[q].y0 >= min(sz[ne].y0, sz[ne].y1) && n           que[q].y0 <= max(sz[ne].y0, sz[ne].y1)) { n         que[q].tim = 0; n         que[q].nex = ne; n         que[q].y = que[q].y0; n         que[q].x = que[q].x0; n       } else if (pr != 0 && que[q].y0 >= min(sz[pr].y0, sz[pr].y1) && n                  que[q].y0 <= max(sz[pr].y0, sz[pr].y1)) { n         que[q].tim = 0; n         que[q].nex = pr; n         que[q].y = que[q].y0; n         que[q].x = que[q].x0; n       } else if (que[q].dy == 1 && ne != 0 && n                  (min(sz[ne].y0, sz[ne].y1) - que[q].y0 < que[q].tim || n                   que[q].nex == 0)) { n         que[q].tim = min(sz[ne].y0, sz[ne].y1) - que[q].y0; n         que[q].nex = ne; n         que[q].y = min(sz[ne].y0, sz[ne].y1); n         que[q].x = que[q].x0; n       } else if (que[q].dy == -1 && pr != 0 && n                  (que[q].y0 - max(sz[pr].y0, sz[pr].y1) < que[q].tim || n                   que[q].nex == 0)) { n         que[q].tim = que[q].y0 - max(sz[pr].y0, sz[pr].y1); n         que[q].nex = pr; n         que[q].y = max(sz[pr].y0, sz[pr].y1); n         que[q].x = que[q].x0; n       } n     } n   sum = 0; n   for (int i = 1; i <= n; i++) n     if (sz[i].y0 == sz[i].y1) { n       sum++; n       bj[sum].key1 = sz[i].y0; n       bj[sum].key2 = sz[i].x0; n       bj[sum].num = i; n       bj[sum].sy = 0; n     } n   for (int i = 1; i <= m; i++) n     if (que[i].dy == 0) { n       sum++; n       bj[sum].key1 = que[i].y0; n       bj[sum].key2 = que[i].x0; n       bj[sum].num = i; n       bj[sum].sy = 1; n     } n   sort(bj + 1, bj + sum + 1, cmp); n   for (int i = 1; i <= sum; i++) n     if (i != 1 && bj[i].key1 == bj[i - 1].key1) { n       if (bj[i - 1].sy == 0) n         pre[i] = i - 1; n       else n         pre[i] = pre[i - 1]; n     } else n       pre[i] = 0; n   for (int i = sum; i >= 1; i--) n     if (i != sum && bj[i].key1 == bj[i + 1].key1) { n       if (bj[i + 1].sy == 0) n         nex[i] = i + 1; n       else n         nex[i] = nex[i + 1]; n     } else n       nex[i] = 0; n   for (int i = 1; i <= sum; i++) n     if (bj[i].sy == 0) { n       int q = bj[i].num, pr = bj[pre[i]].num, ne = bj[nex[i]].num; n       if (sz[q].x1 > sz[q].x0 && ne != 0 && n           (min(sz[ne].x0, sz[ne].x1) - sz[q].x1 < sz[q].tim || n            sz[q].nex == 0)) { n         sz[q].tim = min(sz[ne].x0, sz[ne].x1) - sz[q].x1; n         sz[q].nex = ne; n         sz[q].x = min(sz[ne].x0, sz[ne].x1); n         sz[q].y = sz[q].y0; n       } n       if (sz[q].x1 < sz[q].x0 && pr != 0 && n           (sz[q].x1 - max(sz[pr].x0, sz[pr].x1) < sz[q].tim || n            sz[q].nex == 0)) { n         sz[q].tim = sz[q].x1 - max(sz[pr].x0, sz[pr].x1); n         sz[q].nex = pr; n         sz[q].x = max(sz[pr].x0, sz[pr].x1); n         sz[q].y = sz[q].y0; n       } n     } else { n       int q = bj[i].num, pr = bj[pre[i]].num, ne = bj[nex[i]].num; n       if (ne != 0 && que[q].x0 >= min(sz[ne].x0, sz[ne].x1) && n           que[q].x0 <= max(sz[ne].x0, sz[ne].x1)) { n         que[q].tim = 0; n         que[q].nex = ne; n         que[q].x = que[q].x0; n         que[q].y = que[q].y0; n       } else if (pr != 0 && que[q].x0 >= min(sz[pr].x0, sz[pr].x1) && n                  que[q].x0 <= max(sz[pr].x0, sz[pr].x1)) { n         que[q].tim = 0; n         que[q].nex = pr; n         que[q].x = que[q].x0; n         que[q].y = que[q].y0; n       } else if (que[q].dx == 1 && ne != 0 && n                  (min(sz[ne].x0, sz[ne].x1) - que[q].x0 < que[q].tim || n                   que[q].nex == 0)) { n         que[q].tim = min(sz[ne].x0, sz[ne].x1) - que[q].x0; n         que[q].nex = ne; n         que[q].x = min(sz[ne].x0, sz[ne].x1); n         que[q].y = que[q].y0; n       } else if (que[q].dx == -1 && pr != 0 && n                  (que[q].x0 - max(sz[pr].x0, sz[pr].x1) < que[q].tim || n                   que[q].nex == 0)) { n         que[q].tim = que[q].x0 - max(sz[pr].x0, sz[pr].x1); n         que[q].nex = pr; n         que[q].x = max(sz[pr].x0, sz[pr].x1); n         que[q].y = que[q].y0; n       } n     } n   return 0; n } n const long long oo = 10000000000000000ll; n int ycl() { n   for (int i = 1; i <= n; i++) n     lca[0][i].wz = sz[i].nex, lca[0][i].x = sz[i].x, lca[0][i].y = sz[i].y, n     lca[0][i].tim = sz[i].tim; n   for (int i = 1; i <= 50; i++) n     for (int j = 1; j <= n; j++) n       if (lca[i - 1][j].wz != 0 && lca[i - 1][lca[i - 1][j].wz].wz != 0) { n         lca[i][j].wz = lca[i - 1][lca[i - 1][j].wz].wz; n         lca[i][j].x = lca[i - 1][lca[i - 1][j].wz].x; n         lca[i][j].y = lca[i - 1][lca[i - 1][j].wz].y; n         int g = lca[i - 1][j].wz; n         int x1 = lca[i - 1][j].x, y1 = lca[i - 1][j].y, x2 = sz[g].x1, n             y2 = sz[g].y1; n         lca[i][j].tim = n             lca[i - 1][j].tim + lca[i - 1][g].tim + abs(x1 - x2) + abs(y1 - y2); n         if (lca[i][j].tim >= oo) lca[i][j].wz = 0; n       } n   return 0; n } n int main() { n   scanf( %d%d , &n, &bod); n   for (int i = 1; i <= n; i++) { n     int x0, y0, x1, y1; n     scanf( %d%d%d%d , &x0, &y0, &x1, &y1); n     sz[i] = Node(x0, y0, x1, y1, i); n     sz[i].clear(); n   } n   scanf( %d , &m); n   for (int i = 1; i <= m; i++) { n     int x, y; n     long long t; n     char ch[2]; n     scanf( %d%d%s%I64d , &x, &y, ch, &t); n     int dx, dy; n     if (ch[0] ==  L ) dx = -1, dy = 0; n     if (ch[0] ==  R ) dx = 1, dy = 0; n     if (ch[0] ==  U ) dx = 0, dy = 1; n     if (ch[0] ==  D ) dx = 0, dy = -1; n     que[i] = Que(x, y, dx, dy, t); n     que[i].clear(); n   } n   done(0, 1); n   done(0, -1); n   done(1, 0); n   done(-1, 0); n   done2(); n   ycl(); n   for (int i = 1; i <= m; i++) { n     int x = que[i].x0, y = que[i].y0; n     long long tt = que[i].tt; n     if (que[i].nex == 0) { n       int dx = que[i].dx, dy = que[i].dy; n       tt = min(tt, (long long)bod); n       if (dx == 0) { n         if (dy > 0) n           y = min(bod, y + (int)tt); n         else n           y = max(0, y - (int)tt); n       } else if (dx > 0) n         x = min(bod, x + (int)tt); n       else n         x = max(0, x - (int)tt); n       printf( %d %d n , x, y); n       continue; n     } n     int xx = que[i].x, yy = que[i].y; n     if (tt < que[i].tim) { n       if (x == xx) n         printf( %d  , x); n       else if (x < xx) n         printf( %d  , x + (int)tt); n       else n         printf( %d  , x - (int)tt); n       if (y == yy) n         printf( %d n , y); n       else if (y < yy) n         printf( %d n , y + (int)tt); n       else n         printf( %d n , y - (int)tt); n       continue; n     } else { n       tt -= que[i].tim; n       x = xx; n       y = yy; n     } n     int sy = que[i].nex; n     for (int i = 50; i >= 0; i--) n       if (lca[i][sy].wz != 0) { n         long long degt = n             lca[i][sy].tim + abs(x - sz[sy].x1) + abs(y - sz[sy].y1); n         if (degt > tt) continue; n         tt -= degt; n         x = lca[i][sy].x; n         y = lca[i][sy].y; n         sy = lca[i][sy].wz; n       } n     tt = min(tt, (long long)bod); n     if (sz[sy].x0 == sz[sy].x1) { n       if (sz[sy].y0 > sz[sy].y1) n         y = max(0, y - (int)tt); n       else n         y = min(bod, y + (int)tt); n     } else if (sz[sy].x0 > sz[sy].x1) n       x = max(0, x - (int)tt); n     else n       x = min(bod, x + (int)tt); n     printf( %d %d n , x, y); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = n     3.14159265358979323846264338327950288419716939937510582097494459230; n struct debugger { n   static void call(const char *arg) {} n   template <typename T, typename... aT> n   static void call(const char *it, T a, aT... rest) { n     string b; n     for (; *it && (*it) !=  , ; it++) { n       b += *it; n     } n     cerr << b <<   =   << a <<    ; n     call(++it, rest...); n   } n }; n int main() { n   int n, b, m; n   cin >> n >> b; n   int ar[n]; n   m = b; n   for (int i = 0; i < (n); i++) { n     cin >> ar[i]; n   } n   for (int i = 0; i < (n); i++) { n     int c = b / ar[i], r = b % ar[i]; n     for (int j = (i + 1); j < (n); j++) { n       int w = ar[j] * c; n       w = w + r; n       m = max(w, m); n     } n   } n   cout << m; n } n


#include <bits/stdc++.h> n using namespace std; n long long int gcd(long long int x, long long int y) { n   if (x < y) swap(x, y); n   if (x % y == 0) return y; n   return gcd(y, x % y); n } n long long int pwm(long long int a, long long int n) { n   long long int ans = 1; n   while (n > 0) { n     if (n % 2 == 1) { n       ans = (ans * a) % 1000000007; n     } n     a = (a * a) % 1000000007; n     n /= 2; n   } n   return ans % 1000000007; n } n const int pwn = 100010; n long long int pw[pwn]; n void pwtwo() { n   pw[0] = 1; n   for (int i = 1; i < pwn; i++) { n     pw[i] = (pw[i - 1] * 2) % 1000000007; n   } n } n long long int gcdExtended(long long int a, long long int b, long long int *x, n                           long long int *y); n long long int modInverse(long long int a, long long int m) { n   if (a == 1) return 1; n   long long int x, y; n   long long int g = gcdExtended(a, m, &x, &y); n   if (g != 1) { n     return -1; n   } else { n     long long int res = (x % m + m) % m; n     return res; n   } n } n long long int gcdExtended(long long int a, long long int b, long long int *x, n                           long long int *y) { n   if (a == 0) { n     *x = 0, *y = 1; n     return b; n   } n   long long int x1, y1; n   long long int gcd = gcdExtended(b % a, a, &x1, &y1); n   *x = y1 - (b / a) * x1; n   *y = x1; n   return gcd; n } n long long int fact[1010]; n long long int init() { n   fact[0] = 1; n   for (int i = 1; i < 1010; i++) fact[i] = (fact[i - 1] * i) % 1000000007; n } n long long int ncr(long long int n, long long int r) { n   long long int ans = fact[n]; n   ans = (ans * modInverse(fact[r], 1000000007)) % 1000000007; n   ans = (ans * modInverse(fact[n - r], 1000000007)) % 1000000007; n   return ans; n } n long long int t[42]; n bool check(int x) { n   for (int i = 1; i <= 40; i++) { n     if (x == t[i] - 1) return true; n   } n   return false; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int a, b; n   cin >> a >> b; n   if (a == 1 || b == 1) { n     cout << 0 << endl; n     return 0; n   } n   if (a == b) { n     cout << 0 << endl; n     return 0; n   } n   long long int x = abs(b - a); n   long long int ans = a * b; n   ans = ans / gcd(a, b); n   long long int c = 0; n   for (int i = 1; i <= sqrt(x); i++) { n     if ((x % i) == 0) { n       long long int y = a % i; n       y = (i - y) % i; n       long long int k = (a + y) * (b + y); n       k = k / gcd(a + y, b + y); n       if (ans > k) { n         ans = k; n         c = y; n       } n       int z = x / i; n       y = a % z; n       y = (z - y) % z; n       k = (a + y) * (b + y); n       k = k / gcd(a + y, b + y); n       if (ans > k) { n         ans = k; n         c = y; n       } n     } n   } n   cout << c << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e7 + 9, MAXN = 1e6; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n; n   unsigned long long int k, x; n   cin >> n; n   while (n--) { n     cin >> k >> x; n     cout << x + 9 * (k - 1) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int tree[1000000 + 5], a[1000000 + 5], data[1000000 + 5], rear, sum; n int lowbit(int x) { return (x & -x); } n void modify(int x, int value) { n   for (int i = x; i <= 1000000; i += lowbit(i)) tree[i] += value; n   return; n } n int query(int x) { n   int sum = 0; n   for (int i = x; i; i -= lowbit(i)) sum += tree[i]; n   return sum; n } n void del(int rear, int x) { n   int l = 1, r = rear, mid; n   while (l < r) { n     mid = (l + r) / 2; n     if (query(mid) < x) n       l = mid + 1; n     else n       r = mid; n   } n   modify(l, -1); n   data[l] = -1; n   return; n } n int main() { n   int n, m, i, j, ch; n   scanf( %d%d , &n, &m); n   for (i = 1; i <= m; i++) scanf( %d , &a[i]); n   a[i] = 1000005; n   for (i = 1; i <= n; i++) { n     scanf( %d , &ch); n     if (ch == -1) { n       for (j = 1; a[j] <= sum; j++) del(rear, a[j] - j + 1); n       sum -= (j - 1); n     } else { n       modify(++rear, 1); n       data[rear] = ch; n       sum++; n     } n   } n   if (!sum) n     printf( Poor stack! n ); n   else { n     for (i = 1; i <= rear; i++) n       if (data[i] != -1) printf( %d , data[i]); n     printf(  n ); n   } n   return 0; n } n


#include <iostream> n #include <bits/stdc++.h> n using namespace std; n  n #define int long long  n  n void solve(){ n    // int n; n     //cin>>n; n      n     /*int a[n]; n     for(int i=0;i<n;i++) n     cin>>a[i]; */ n     string s; n     cin>>s; n     int n=s.length(); n      n     cout << n << endl; n     n } n  n int32_t main() { n  n     ios_base::sync_with_stdio(false); n     cin.tie(NULL); n      n     int t; n     cin>>t; n     while(t){ n         t--; n      solve(); n       n     } n      n      n } n


#include <bits/stdc++.h> n using namespace std; n string st; n int main() { n   cin >> st; n   char q[11] = { A ,  I ,  O ,  M ,  H ,  U ,  V ,  W ,  X ,  Y ,  T }; n   set<char> s(q, q + 11); n   for (long long i = 0; i < st.size() / 2 + 1; i++) { n     if (st[i] != st[st.size() - i - 1] || s.count(st[i]) == 0) { n       cout <<  NO ; n       return 0; n     } n   } n   if (st.size() == 1) { n     if (s.count(st[0]) == 0) { n       cout <<  NO ; n       return 0; n     } n   } n   cout <<  YES ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t; n   cin >> t; n   while (t--) { n     long long n, sum = 0; n     cin >> n; n     for (int i = 0; i < 60; i++) { n       long long x = 1LL << i; n       if (n & x) { n         sum += (1LL << (i + 1)) - 1; n       } n     } n     cout << sum << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k, q, a, b, x, y, i = 1, j, p[150000], mas[150005]; n pair<int, int> m[10]; n int main() { n   cin >> n >> k >> q; n   while (i <= n) { n     cin >> p[i]; n     i++; n   } n   i = 0; n   while (i < q) { n     cin >> a >> b; n     if (a == 1) { n       if (p[b] > m[k - 1].first) { n         mas[m[k - 1].second] = 0; n         mas[b] = 1; n         m[k - 1].first = p[b]; n         m[k - 1].second = b; n         sort(m, m + k); n         reverse(m, m + k); n       } n     } n     if (a == 2) { n       if (mas[b] == 0) { n         cout <<  NO  << endl; n       } else { n         cout <<  YES  << endl; n       } n     } n     i++; n   } n } n


#include <bits/stdc++.h> n using namespace std; n void chmax(int& a, int b) { a = max(a, b); } n void chmin(int& a, int b) { a = min(a, b); } n int nth_bit(int64_t num, int n) { return (num >> n) & 1; } n int main() { n   string S; n   int X; n   cin >> S >> X; n   int N = S.size(); n   vector<int> A(N); n   for (int i = 0; i < N; i++) A[i] = S[i] -  0 ; n   vector<int> ds; n   for (int i = 1; i < X; i++) n     if (X % i == 0) ds.push_back(i); n   if (X == 1) { n     cout << count(A.begin(), A.end(), 1) << endl; n     return 0; n   } n   int B = 1 << (X + 1); n   vector<int> valid; n   for (int b = 0; b < B; b++) { n     bool ok = true; n     for (int i = 0; i < X; i++) n       if (nth_bit(b, i) && nth_bit(b, i + 1)) ok = false; n     if (ok) valid.push_back(b); n   } n   vector<bool> ok(B); n   for (int b = 0; b < B; b++) { n     if (nth_bit(b, X) == 0) ok[b] = true; n     for (int d : ds) n       for (int i = 0; i < X; i++) n         if (nth_bit(b, i) && nth_bit(b, i + d)) ok[b] = true; n   } n   vector<int> dp(B), dp2(B); n   auto solve = [&](vector<int>& V) -> int { n     int N = V.size(); n     for (int b : valid) dp[b] = 1e9; n     dp[1] = 0; n     for (int i = 0; i < N; i++) { n       for (int b : valid) dp2[b] = dp[b] + 1; n       for (int b : valid) { n         int b2 = ((b << V[i]) | 1) & (B - 1); n         if (ok[b2]) chmin(dp2[b2], dp[b]); n       } n       for (int b : valid) dp[b] = dp2[b]; n     } n     int ans = 1e9; n     for (int b : valid) chmin(ans, dp[b]); n     return ans; n   }; n   int ans = 0; n   vector<int> V; n   for (int i = 0; i < N; i++) { n     if (A[i] == 1) { n       if (V.size()) ans += solve(V); n       V.clear(); n     } else { n       V.push_back(A[i]); n     } n   } n   if (V.size()) ans += solve(V); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long C[4005][4005]; n const int mod = 998244853; n long long dp[2005][2005]; n void norm(long long& x) { n   while (x < 0) x += mod; n   while (x >= mod) x -= mod; n } n int main() { n   int n, m; n   cin >> n >> m; n   C[1][0] = 1; n   C[1][1] = 1; n   for (int i = 2; i <= (n + m); i++) { n     C[i][0] = 1; n     for (int j = 1; j <= i; j++) { n       C[i][j] = C[i - 1][j] + C[i - 1][j - 1]; n       norm(C[i][j]); n     } n   } n   for (int i = 1; i <= n; i++) { n     dp[i][0] = i; n     for (int j = 1; j <= m; j++) { n       dp[i][j] = dp[i - 1][j] + C[i - 1 + j][j]; n       norm(dp[i][j]); n       dp[i][j] += dp[i][j - 1] - C[i - 1 + j][i]; n       norm(dp[i][j]); n       if (i <= j - 1) n         dp[i][j] += C[i + j - 1][j - 1] - C[i + j - 1][j], norm(dp[i][j]); n     } n   } n   cout << dp[n][m]; n } n


#include <bits/stdc++.h> n using namespace std; n int n, arr[100005], has[100005], t; n vector<int> v[100005]; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     int a; n     cin >> a; n     arr[a]++; n     has[i] = arr[a]; n     v[has[i]].push_back(a); n     t = max(t, has[i]); n   } n   for (int i = 0; i < 100000; i++) { n     int p = v[i].size(); n     if (p != 0) { n       int tmp = 0; n       for (int j = 0; j < p; j++) { n         tmp += v[i][j]; n       } n       if (tmp != ((p * (p + 1)) / 2)) { n         cout <<  -1  << endl; n         return 0; n       } n     } n   } n   cout << t << endl; n   for (int i = 1; i <= n; i++) cout << has[i] <<    ; n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void _R(T &x) { n   cin >> x; n } n void _R(int &x) { scanf( %d , &x); } n void _R(long long &x) { scanf( %  PRId64, &x); } n void _R(double &x) { scanf( %lf , &x); } n void _R(char &x) { scanf(  %c , &x); } n void _R(char *x) { scanf( %s , x); } n void R() {} n template <typename T, typename... U> n void R(T &head, U &...tail) { n   _R(head); n   R(tail...); n } n template <typename T> n void _W(const T &x) { n   cout << x; n } n void _W(const int &x) { printf( %d , x); } n template <typename T> n void _W(const vector<T> &x) { n   for (auto i = x.cbegin(); i != x.cend(); i++) { n     if (i != x.cbegin()) putchar(   ); n     _W(*i); n   } n } n void W() {} n template <typename T, typename... U> n void W(const T &head, const U &...tail) { n   _W(head); n   putchar(sizeof...(tail) ?     :   n ); n   W(tail...); n } n int ans; n inline void chkmax(int &a, int b) { n   if (b > ans) ans = b; n   if (b > a) a = b; n } n const int N = 1010; n const int K = 11; n int n, m, k, dp[K][N][N][2]; n char a[N], b[N]; n int main() { n   memset(dp, -1, sizeof(dp)); n   dp[0][0][0][0] = 0; n   R(n, m, k, a, b); n   for (int i = (0); i <= int(k); i++) n     for (int x = 0; x < int(n); x++) n       for (int y = 0; y < int(m); y++) n         for (int j = 0; j < int(2); j++) { n           int me = dp[i][x][y][j]; n           if (me == -1) continue; n           chkmax(dp[i][x + 1][y][0], me); n           chkmax(dp[i][x][y + 1][0], me); n           if (a[x] == b[y]) { n             int ni = i + (j == 0); n             if (ni <= k) chkmax(dp[i + (j == 0)][x + 1][y + 1][1], me + 1); n           } n         } n   W(ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n  n //.define n // #define FILE_IN_OUT n #define RET(_x) cout << (_x) <<   n ; return; n #define all(_obj) (_obj).begin(), (_obj).end() n #define loop(_n) for (int i = 0; i < (_n); ++i) n #define sz(_obj) static_cast<int>((_obj).size()) n #ifdef SHJ_LOCAL n #define debug(_x) std::cerr << (#_x) <<   =   << (_x) <<   n  << std::flush; n #else n #define debug(_x) {} n #endif n #define endl   n  n template <typename P, typename Q> n P CeilDiv(P _dividend, Q _divider) { n     return static_cast<P>((_dividend - 1LL + _divider) / _divider); n } n template <typename Tp> n inline void outarr(Tp _begin, Tp _end, const char* _delim =    ) { n     for (Tp current = _begin; current != _end; ++current) { n         std::cout << *current << _delim; n     } n     std::cout <<   n ; n } n  n //.constant n using ll = int64_t; n using pii = std::pair<int, int>; n constexpr int INF = 0x3f3f3f3f; n constexpr int MOD = static_cast<int>(1e9 + 7); n  n //.data n bool Ask(int l1, int r1, int l2, int r2) { n     cout <<  ?   << r1 - l1 + 1 <<     << r2 - l2 + 1 << endl; n     for (int i = l1; i <= r1; ++i) { n         cout << i <<    ; n     } n     cout << endl; n     for (int i = l2; i <= r2; ++i) { n         cout << i <<    ; n     } n     cout << endl << flush; n     int res; n     cin >> res; n     return res; n } n  n //.code n void SolveTask() { n     int n; n     cin >> n; n     int j = -1; n     for (int i = 2; i <= n; ++i) { n         if (Ask(1, i - 1, i, i)) { n             j = i; n             break; n         } n     } n     vector<int> ans; n     for (int i = j + 1; i <= n; ++i) { n         if (!Ask(j, j, i, i)) { n             ans.push_back(i); n         } n     } n     int l = 1; n     int r = j - 1; n     while (l <= r) { n         int mid = (l + r) >> 1; n         if (Ask(1, mid, j, j)) { n             r = mid - 1; n         } else { n             l = mid + 1; n         } n     } n     for (int i = 1; i <= r; ++i) { n         ans.push_back(i); n     } n     for (int i = r + 2; i < j; ++i) { n         ans.push_back(i); n     } n     cout <<  !   << sz(ans) <<    ; n     outarr(all(ans)); n     cout << flush; n } n  n int main() { n #ifdef FILE_IN_OUT n     std::ifstream cin( input.txt , std::ios::in); n     std::ofstream cout( output.txt , std::ios::out); n #else n     std::ios_base::sync_with_stdio(false); n     std::cin.tie(nullptr); n #endif n     int test_cases = 1; n     cin >> test_cases; n     for (int yt = 1; yt <= test_cases; ++yt) { n         SolveTask(); n     } n #ifdef FILE_IN_OUT n     cin.close(); n     cout.close(); n #endif n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n const int M = 5e3 + 10; n int a[M]; n int dp[M][M]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , a + i), dp[i][i] = a[i]; n   for (int d = 1; d < n; d++) { n     for (int i = 1; i + d <= n; i++) { n       int j = i + d; n       dp[i][j] = dp[i][j - 1] ^ dp[i + 1][j]; n     } n   } n   for (int d = 1; d < n; d++) { n     for (int i = 1; i + d <= n; i++) { n       int j = i + d; n       dp[i][j] = max({dp[i][j], dp[i + 1][j], dp[i][j - 1]}); n     } n   } n   int q, l, r; n   scanf( %d , &q); n   while (q--) { n     scanf( %d%d , &l, &r); n     printf( %d n , dp[l][r]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long eps = 1e9 + 7; n const double inf = 1e-12; n bool F(set<pair<int, int> > &a) { n   pair<int, int> p = *a.rbegin(); n   a.erase(p); n   --p.first; n   if (p.first != 0) { n     a.insert(p); n   } n   if (!a.empty() && a.rbegin()->first == a.begin()->first) { n     if (p.first != 0) { n       a.erase(p); n     } n     ++p.first; n     a.insert(p); n     return true; n   } n   if (p.first != 0) { n     a.erase(p); n   } n   ++p.first; n   a.insert(p); n   p = *a.begin(); n   a.erase(p); n   --p.first; n   if (p.first != 0) { n     a.insert(p); n   } n   if (!a.empty() && a.rbegin()->first == a.begin()->first) { n     if (p.first != 0) { n       a.erase(p); n     } n     ++p.first; n     a.insert(p); n     return true; n   } n   if (p.first != 0) { n     a.erase(p); n   } n   ++p.first; n   a.insert(p); n   return false; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   set<pair<int, int> > a; n   vector<int> b(1e5 + 5); n   int max1 = 1; n   for (int i = 1; i <= n; ++i) { n     int first; n     cin >> first; n     a.erase(pair<int, int>(b[first], first)); n     ++b[first]; n     a.insert(pair<int, int>(b[first], first)); n     if (F(a)) { n       max1 = i; n     } n   } n   cout << max1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int read() { n   bool f = 0; n   int x = 0; n   char c = getchar(); n   while (c <  0  ||  9  < c) { n     if (c ==  - ) f = 1; n     c = getchar(); n   } n   while ( 0  <= c && c <=  9 ) n     x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); n   return !f ? x : -x; n } n const int MAXN = 200000; n const int INF = 0x3f3f3f3f; n int fa[MAXN + 5], ch[MAXN + 5][2]; n long long a[MAXN + 5], siz[MAXN + 5], sum[MAXN + 5], ans[MAXN + 5], n     all[MAXN + 5], ad[MAXN + 5], de[MAXN + 5]; n bool pan(int u) { return ch[fa[u]][1] == u; } n bool isroot(int u) { return (ch[fa[u]][0] != u && ch[fa[u]][1] != u); } n void PushUp(int u) { n   sum[u] = sum[ch[u][0]] + sum[ch[u][1]] + siz[u]; n   all[u] = all[ch[u][0]] + all[ch[u][1]] + siz[u] * a[u]; n   ans[u] = ans[ch[u][0]] + ans[ch[u][1]] + ad[u] + n            a[u] * (siz[u] * siz[u] - de[u]) + n            2 * a[u] * siz[u] * sum[ch[u][1]] + n            2 * all[ch[u][0]] * (sum[u] - sum[ch[u][0]]); n   return; n } n void Rotate(int x) { n   int y = fa[x], z = fa[y], dx = pan(x), dy = pan(y), w = ch[x][dx ^ 1]; n   if (!isroot(y)) ch[z][dy] = x; n   ch[x][dx ^ 1] = y, ch[y][dx] = w; n   if (w) fa[w] = y; n   fa[y] = x, fa[x] = z; n   PushUp(y); n   return; n } n void Splay(int x) { n   for (int y = fa[x]; !isroot(x); Rotate(x), y = fa[x]) n     if (!isroot(y)) Rotate(pan(x) == pan(y) ? y : x); n   PushUp(x); n   return; n } n int Access(int x) { n   int y = 0; n   while (x) { n     Splay(x); n     siz[x] -= sum[y]; n     ad[x] -= ans[y]; n     de[x] -= sum[y] * sum[y]; n     siz[x] += sum[ch[x][1]]; n     ad[x] += ans[ch[x][1]]; n     de[x] += sum[ch[x][1]] * sum[ch[x][1]]; n     ch[x][1] = y, PushUp(x), y = x, x = fa[x]; n   } n   return y; n } n void Link(int x, int y) { n   Access(y); n   Splay(y); n   Access(x); n   Splay(x); n   fa[y] = x; n   siz[x] += sum[y]; n   ad[x] += ans[y]; n   de[x] += 1ll * sum[y] * sum[y]; n   PushUp(x); n   return; n } n void Cut(int x, int y) { n   Access(x); n   Splay(x); n   Splay(y); n   siz[x] -= sum[y]; n   ad[x] -= ans[y]; n   de[x] -= 1ll * sum[y] * sum[y]; n   fa[y] = 0; n   PushUp(x); n   return; n } n char Re[5]; n int f[MAXN + 5]; n bool check(int x, int y) { n   Access(y); n   Splay(y), Splay(x); n   return !isroot(y); n } n int main() { n   int n = read(); n   for (int i = 2; i <= n; i++) f[i] = read(); n   for (int i = 1; i <= n; i++) n     a[i] = read(), sum[i] = siz[i] = 1, ans[i] = all[i] = a[i]; n   for (int i = 2; i <= n; i++) Link(f[i], i); n   Access(1), Splay(1); n   printf( %.10f n , 1.0 * ans[1] / n / n); n   int m = read(); n   for (int i = 1; i <= m; i++) { n     scanf( %s , Re); n     if (Re[0] ==  P ) { n       int x = read(), y = read(); n       if (f[x] == y || f[y] == x) goto Break; n       if (check(x, y)) swap(x, y); n       Cut(f[x], x), f[x] = y; n       Link(f[x], x); n     } else { n       int x = read(), y = read(); n       Access(x), Splay(x); n       a[x] = y; n       PushUp(x); n     } n   Break: n     Access(1), Splay(1); n     printf( %.10f n , 1.0 * ans[1] / n / n); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 200005; n const int MOD = 1000000007; n long long fun(long long a, long long b) { n   if (a > b) return a; n   return b; n } n void swp(long long *a, long long *b) { n   long long temp = *a; n   *a = *b; n   *b = temp; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   int n; n   cin >> n; n   char ch; n   long long x, y; n   cin >> ch >> x >> y; n   if (x > y) swp(&x, &y); n   long long mx = x, my = y; n   n--; n   while (n--) { n     cin >> ch >> x >> y; n     if (x > y) swp(&x, &y); n     if (ch ==  + ) { n       mx = fun(mx, x); n       my = fun(my, y); n     } else { n       if ((x >= mx && y >= my) || (x >= my && y >= mx)) n         cout <<  YES n ; n       else n         cout <<  NO n ; n     } n   } n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) 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 long long power(long long b, long long e) { n   if (e == 0) return 1; n   if (e % 2) n     return ((b * power((b) * (b), (e - 1) / 2))); n   else n     return power((b) * (b), e / 2); n } n long long modpower(long long b, long long e, long long q) { n   long long MOD = q; n   if (e == 0) return 1; n   if (e % 2) n     return ((b % MOD) * modpower((b % MOD) * (b % MOD), (e - 1) / 2, q)) % MOD; n   else n     return modpower((b % MOD) * (b % MOD), e / 2, q) % MOD; n } n void dpv(vector<long long> v) { n   for (long long i = 0; i < v.size(); i++) { n     cout << v[i] <<    ; n   } n   cout <<   n ; n } n void dpv(vector<pair<long long, long long> > v) { n   for (long long i = 0; i < v.size(); i++) { n     cout << v[i].first <<     << v[i].second <<   n ; n   } n } n void dpv(set<long long> v) { n   for (auto i : v) { n     cout << i <<    ; n   } n   cout <<   n ; n } n void oblivious() { n   string s; n   cin >> s; n   long long p = 0, ans = 0, q = 1; n   for (long long i = 0; i <= s.length(); i++) { n     if (s[i] ==  +  || s[i] ==  -  || i == s.length()) { n       ans += p * q; n       p = 0; n       if (i == s.length()) { n         continue; n       } n       if (s[i] ==  + ) { n         q = 1; n       } else if (s[i] ==  - ) { n         q = -1; n       } n     } else { n       p = (10 * p + s[i] -  0 ); n     } n   } n   long long u = ans; n   long long y = 0; n   string s1; n   if (u == 0) { n     s1.push_back( 0 ); n   } else { n     while (u != 0) { n       s1.push_back(u % 10 +  0 ); n       u = u / 10; n     } n   } n   reverse(s1.begin(), s1.end()); n   for (long long i = 0; i < s1.length(); i++) { n     long long z = s1[i]; n     while (z--) { n       cout <<  + ; n     } n     cout <<  .> ; n     cout <<   n ; n   } n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   while (t--) { n     oblivious(); n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   for (int test = 0; test < t; test++) { n     bool answer = true; n     int n; n     cin >> n; n     vector<int> a(n); n     vector<int> b(n); n     for (int i = 0; i < n; i++) cin >> a[i]; n     for (int i = 0; i < n; i++) cin >> b[i]; n     unordered_map<int, int> keys_to_counts; n     keys_to_counts[1] = 0; n     keys_to_counts[-1] = 0; n     keys_to_counts[0] = 0; n     for (int x : a) { n       keys_to_counts[x]++; n     } n     keys_to_counts[a[n - 1]]--; n     for (int i = n - 1; i >= 0; i--) { n       if (b[i] > a[i]) { n         answer &= (keys_to_counts[1] > 0); n       } else if (b[i] < a[i]) { n         answer &= (keys_to_counts[-1] > 0); n       } n       if (i != 0) keys_to_counts[a[i - 1]]--; n     } n     if (answer) 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 unsigned long long arr[200000], cum[200000]; n unsigned long long forone; n unsigned long long n; n unsigned long long make(unsigned long long st, unsigned long long mult, n                         unsigned long long lim, unsigned long long level) { n   if (st > n) return 0; n   unsigned long long end = min(n, st + lim - 1); n   return make(end + 1, mult, lim * mult, level + 1) + n          (cum[end] - cum[st - 1]) * level; n } n bool comp(int p, int q) { return p > q; } n int main() { n   while (cin >> n) { n     unsigned long long i; n     for (i = 1; i <= n; i++) cin >> arr[i]; n     sort(&arr[1], &arr[n + 1], comp); n     cum[0] = 0; n     forone = 0; n     for (i = 1; i <= n; i++) { n       forone += (i - 1) * arr[i]; n       cum[i] = cum[i - 1] + arr[i]; n     } n     unsigned long long q; n     cin >> q; n     unsigned long long tem; n     for (i = 1; i <= q; i++) { n       cin >> tem; n       if (tem == 1) { n         cout << forone; n         if (i != q) cout <<    ; n         continue; n       } n       cout << make(2, tem, tem, 1); n       if (i != q) cout <<    ; n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int x, t, a, b, da, db, i, j, p, ans = 0; n int main() { n   scanf( %d %d %d %d %d %d , &x, &t, &a, &b, &da, &db); n   i = 0; n   for (i = 0; i < t; i++) n     for (j = 0; j < t; j++) { n       if (a - i * da + b - j * db == x) ans = 1; n     } n   for (i = 0; i < t; i++) n     if (a - i * da == x || b - i * db == x) ans = 1; n   if (ans == 1 || x == 0) n     printf( YES ); n   else n     printf( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long n, a, b; n   cin >> n >> a >> b; n   long long left = a; n   long long right = n - b - 1; n   long long end = max(left, right); n   long long ans = n - end; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int n, p, start[390000], fin[390000]; n map<pair<int, int>, int> mp; n int main() { n   scanf( %d %d , &n, &p); n   vector<int> cnt(n, 0); n   for (int i = 0; i < n; i++) { n     int x, y; n     scanf( %d %d , &x, &y); n     x--; n     y--; n     if (x > y) swap(x, y); n     start[i] = x; n     fin[i] = y; n     cnt[x]++; n     cnt[y]++; n     mp[make_pair(x, y)]++; n   } n   vector<int> cnt2(cnt.begin(), cnt.end()); n   sort(cnt.begin(), cnt.end()); n   long long ans = 0; n   int j = n; n   for (int i = 0; i < n; i++) { n     while (j - 1 >= i && cnt[i] + cnt[j - 1] >= p) j--; n     if (j < i + 1) j = i + 1; n     ans += n - j; n   } n   for (int i = 0; i < n; i++) { n     if (cnt2[start[i]] + cnt2[fin[i]] < p) continue; n     if (cnt2[start[i]] + cnt2[fin[i]] - mp[make_pair(start[i], fin[i])] < p) n       ans--; n     mp[make_pair(start[i], fin[i])] = 0; n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1000 + 5; n int main() { n   int n, que[maxn]; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %d , &que[i]); n   sort(que, que + n); n   if (n % 2 == 0) n--; n   printf( %d n , que[n / 2]); n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e5 + 5; n int n, k, x, y; n set<pair<int, int> > s; n vector<pair<int, int> > a[MAXN]; n vector<int> ans; n inline void start() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= n; i++) { n     scanf( %d%d , &x, &y); n     a[x].push_back({y, i}); n   } n } n inline void solve() { n   for (int i = 1; i <= 2e5 + 1; i++) { n     for (int j = 0; j < a[i].size(); j++) s.insert(a[i][j]); n     while (s.size() > k) { n       ans.push_back((--s.end())->second); n       s.erase(--s.end()); n     } n     while (!s.empty() && s.begin()->first == i) s.erase(s.begin()); n   } n   sort(ans.begin(), ans.end()); n   printf( %d n , ans.size()); n   for (int i = 0; i < ans.size(); i++) printf( %d  , ans[i]); n   puts(  ); n } n int main() { n   start(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i, j, k, sum = 0; n   cin >> n; n   pair<int, int> a[n]; n   for (i = 0; i < n; i++) { n     cin >> a[i].first; n     a[i].second = i; n   } n   sort(a, a + n); n   for (i = 0; i < n; i++) { n     sum = sum + ((a[n - i - 1].first * i) + 1); n   } n   cout << sum <<   n ; n   for (i = 0; i < n; i++) cout << a[n - i - 1].second + 1 <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = +100500; n const long long INF = 4e18; n long long a[MAXN]; n int main() { n   long long n, k; n   cin >> n >> k; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   if (k >= 3) { n     sort(a + 1, a + n + 1); n     cout << a[n]; n     return 0; n   } n   if (k == 1) { n     sort(a + 1, a + n + 1); n     cout << a[1]; n     return 0; n   } n   multiset<long long> b; n   multiset<long long> c; n   for (int i = 1; i <= n; i++) { n     c.insert(a[i]); n   } n   long long ans = -INF; n   long long pt = 1; n   while (pt < n) { n     b.insert(a[pt]); n     c.erase(c.equal_range(a[pt]).first); n     long long x = max(*c.begin(), *b.begin()); n     ans = max(ans, x); n     pt++; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b; n bool check(int k, int x, int y) { n   long long ca = 1LL * k * x; n   long long cb = 1LL * k * y; n   return ca <= a && cb <= b; n } n long long gcd(long long a, long long b) { n   if (!b) n     return a; n   else n     return gcd(b, a % b); n } n int main() { n   int x, y; n   cin >> a >> b >> x >> y; n   int l = 1, r = 2 * 1e9; n   long long ans = 2e9 + 1; n   long long g = gcd(x, y); n   x /= g; n   y /= g; n   while (l <= r) { n     int mid = (l + r) >> 1; n     if (check(mid, x, y)) { n       ans = mid; n       l = mid + 1; n     } else n       r = mid - 1; n   } n   if (ans == 2e9 + 1) n     cout <<  0 0  << endl; n   else n     cout << x * ans <<     << y * ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000005; n int n, k; n int v[N], c[N], p[N]; n double f[N]; n double C(int n, int m) { return f[n] - f[m] - f[n - m]; } n struct Node { n   int Max, Min; n } node[N * 4]; n void pushup(int x) { n   node[x].Max = max(node[((x << 1) + 1)].Max, node[((x << 1) + 2)].Max); n   node[x].Min = min(node[((x << 1) + 1)].Min, node[((x << 1) + 2)].Min); n } n void build(int l, int r, int x = 0) { n   if (l == r) { n     node[x].Max = v[l]; n     node[x].Min = c[l]; n     return; n   } n   int mid = (l + r) >> 1; n   build(l, mid, ((x << 1) + 1)); n   build(mid + 1, r, ((x << 1) + 2)); n   pushup(x); n } n int Max1, Min1; n void rmq(int l, int r, int L = 1, int R = n, int x = 0) { n   if (L >= l && R <= r) { n     Max1 = max(Max1, node[x].Max); n     Min1 = min(Min1, node[x].Min); n     return; n   } n   int mid = (L + R) >> 1; n   if (l <= mid) rmq(l, r, L, mid, ((x << 1) + 1)); n   if (r > mid) rmq(l, r, mid + 1, R, ((x << 1) + 2)); n } n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= n; i++) scanf( %d , &v[i]); n   for (int i = 1; i <= n; i++) scanf( %d , &c[i]); n   p[n] = min(v[n] * 100, c[n]); n   int pre = n; n   int Max = v[n], Min = c[n]; n   for (int i = n - 1; i >= 1; i--) { n     Max = max(Max, v[i]); n     Min = min(Min, c[i]); n     if (min(Max * 100, Min) < min(v[i] * 100, c[i])) Max = v[i], Min = c[i]; n     p[i] = min(Max * 100, Min); n   } n   sort(p + 1, p + 1 + n); n   for (int i = 1; i <= n; i++) f[i] = f[i - 1] + log(i * 1.0); n   double ans = 0; n   for (int i = 1; i <= n; i++) { n     if (k - 1 > n - i) break; n     ans += exp(log(p[i] * 1.0) + C(n - i, k - 1) - C(n, k)); n   } n   printf( %.12f n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int inv(long long int k) { n   long long int vl = 1000000007 - 2; n   long long int val = 1; n   long long int b = k; n   for (int i = 0; i < 63; i++) { n     if ((vl >> i) & 1) { n       val *= b; n       val %= 1000000007; n     } n     b = b * b; n     b %= 1000000007; n   } n   return val; n } n int main() { n   string s; n   cin >> s; n   long long int l = s.size(); n   vector<long long int> vr(l + 1), op(l + 1); n   vr[0] = 1; n   for (int i = 1; i <= l; i++) { n     vr[i] = i * vr[i - 1]; n     vr[i] %= 1000000007; n   } n   for (int i = 0; i < l; i++) { n     if (s[i] ==  ( ) op[i + 1]++; n     op[i + 1] += op[i]; n   } n   long long int ans = 0; n   for (int i = 0; i < l; i++) { n     if (s[i] ==  ) ) continue; n     long long int v = op[i + 1]; n     long long int v1 = op[l] - op[i + 1]; n     v1 = l - i - 1 - v1; n     if (v1 == 0) continue; n     long long int n = v + v1 - 1; n     long long int k = v; n     k = (vr[k] * vr[n - k]) % 1000000007; n     k = inv(k); n     k = (vr[n] * k) % 1000000007; n     ans += k; n     ans %= 1000000007; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, temp; n   cin >> n; n   long long int sum = 0, sum2 = 0; n   for (int i = 0; i < n; i++) { n     cin >> temp; n     sum += temp; n   } n   for (int i = 0; i < n - 1; i++) { n     cin >> temp; n     sum2 += temp; n   } n   cout << sum - sum2 << endl; n   sum = 0; n   for (int i = 0; i < n - 2; i++) { n     cin >> temp; n     sum += temp; n   } n   cout << sum2 - sum; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int inf_int = 1e9; n long long inf_ll = 1e16; n const double pi = 3.1415926535898; n const int mod = 1e9 + 9; n const int MAXN = 2e5 + 100; n bool debug = false; n char a[1005][1005]; n char used[1005][1005][4][3]; n int dx[] = {0, 0, 1, -1}; n int dy[] = {1, -1, 0, 0}; n int n, m; n inline bool is_ok(int x, int y, int d, int z) { n   return x >= 1 && x <= n && y >= 1 && y <= m && z <= 2 && a[x][y] !=  *  && n          !used[x][y][d][z]; n } n void solve() { n   cin >> n >> m; n   int x1, y1; n   for (int i = 1; i <= n; ++i) { n     for (int e = 1; e <= m; ++e) { n       cin >> a[i][e]; n       if (a[i][e] ==  S ) { n         x1 = i; n         y1 = e; n       } n     } n   } n   queue<pair<pair<int, int>, pair<int, int> > > q; n   used[x1][y1][0][0] = 1; n   used[x1][y1][1][0] = 1; n   used[x1][y1][2][0] = 1; n   used[x1][y1][3][0] = 1; n   q.push({{x1, y1}, {0, 0}}); n   q.push({{x1, y1}, {1, 0}}); n   q.push({{x1, y1}, {2, 0}}); n   q.push({{x1, y1}, {3, 0}}); n   while (!q.empty()) { n     int x = q.front().first.first, y = q.front().first.second; n     int d = q.front().second.first, z = q.front().second.second; n     q.pop(); n     if (is_ok(x + dx[d], y + dy[d], d, z)) { n       q.push({{x + dx[d], y + dy[d]}, {d, z}}); n       used[x + dx[d]][y + dy[d]][d][z] = 1; n     } n     for (int i = 0; i < 4; ++i) { n       if (is_ok(x + dx[i], y + dy[i], i, z + 1)) { n         q.push({{x + dx[i], y + dy[i]}, {i, z + 1}}); n         used[x + dx[i]][y + dy[i]][i][z + 1] = 1; n       } n     } n   } n   for (int i = 1; i <= n; ++i) { n     for (int e = 1; e <= m; ++e) { n       if (a[i][e] ==  T ) { n         for (int j = 0; j < 4; ++j) { n           for (int f = 0; f <= 2; ++f) { n             if (used[i][e][j][f]) { n               cout <<  YES ; n               return; n             } n           } n         } n       } n     } n   } n   cout <<  NO ; n } n int main() { n   if (!debug) { n     ios_base::sync_with_stdio(0); n     cin.tie(0); n     cout.tie(0); n   } n   int t = 1; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 300005; n int n, k, pos[N]; n long long c[N], ans; n vector<int> v; n priority_queue<pair<long long, int> > q; n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= n; i++) scanf( %lld , &c[i]); n   for (int i = 1; i <= n + k; i++) { n     if (i <= n) q.push(make_pair(c[i], i)); n     if (k < i) { n       int x = q.top().second; n       long long w = q.top().first; n       q.pop(); n       ans += w * ((long long)i - (long long)x); n       v.push_back(x); n     } n   } n   printf( %lld n , ans); n   for (int i = 0; i < v.size(); i++) pos[v[i]] = i + k + 1; n   for (int i = 1; i <= n; i++) printf( %d  , pos[i]); n   return 0; n } n


#include <bits/stdc++.h> n int mod = 1000000007; n const double pi = 3.141592653689793238460; n const int inf = 0x3f3f3f3f; n using namespace std; n int gcd(int a, int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n, k; n   cin >> n >> k; n   int a[10005]; n   for (int i = 0; i < n; i++) cin >> a[i]; n   vector<int> pos; n   for (int i = 0; i < n; i++) { n     int x = a[i]; n     while (x > 0) { n       pos.push_back(x); n       x /= 2; n     } n   } n   int ans = inf; n   for (auto x : pos) { n     vector<int> cur; n     for (int i = 0; i < n; i++) { n       int cnt = 0; n       int y = a[i]; n       while (y > x) { n         y /= 2; n         cnt++; n       } n       if (y == x) { n         cur.push_back(cnt); n       } n     } n     if (cur.size() < k) continue; n     sort(cur.begin(), cur.end()); n     ans = min(ans, accumulate(cur.begin(), cur.begin() + k, 0)); n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100000 + 6; n int g[N]; n int main() { n   int n, m, v, i; n   cin >> n >> m >> v; n   long long top = 1 + (n - 1) * (n - 2) / 2; n   if (n - 1 > m || top < (long long)m) { n     cout << -1; n     return 0; n   } n   --v; n   for (i = 0; i < n; ++i) g[i] = i; n   swap(g[1], g[v]); n   for (i = 0; i < n - 1; ++i) { n     cout << g[i] + 1 <<     << g[i + 1] + 1 << endl; n     --m; n   } n   int j; n   for (i = 1; i < n - 1 && m; ++i) { n     for (j = i + 2; j < n && m; ++j) { n       cout << g[i] + 1 <<     << g[j] + 1 << endl; n       --m; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double M; n struct E { n   int x, y, z, tp, id; n   bool operator<(const E yy) const { n     double p1 = tp ? z : z + M, p2 = yy.tp ? yy.z : yy.z + M; n     return p1 < p2; n   } n } e[100005]; n int n, m, k, fa[50005], p[50005], d[50005]; n int gf(int x) { return fa[x] == x ? x : fa[x] = gf(fa[x]); } n int Calc(double mid, int r) { n   for (int i = 1; i <= n; i++) fa[i] = i; n   M = mid, sort(e + 1, e + m + 1); n   int ans[2] = {0}, w = n - 1; n   for (int i = 1; i <= m; i++) { n     int fx = gf(e[i].x), fy = gf(e[i].y); n     if (fx == fy) continue; n     ans[1] += e[i].z, ans[0] += !e[i].tp; n     if (r && ans[0] > k) { n       ans[1] -= e[i].z, ans[0] -= !e[i].tp; n       continue; n     } n     fa[fx] = fy, w--; n     if (r) p[++p[0]] = e[i].id; n   } n   if (w) puts( -1 ), exit(0); n   return ans[r]; n } n int main() { n   scanf( %d%d%d , &n, &m, &k); n   for (int i = 1, x, y, z; i <= m; i++) n     scanf( %d%d%d , &x, &y, &z), e[i] = {x, y, z, !(x == 1 || y == 1), i}, n                                  d[x]++, d[y]++; n   if (d[1] < k || (n > 1 && !k)) return puts( -1 ), 0; n   double l = -100001, r = 100001, ans = 0; n   while (r - l > 1e-8) { n     double mid = (l + r) / 2; n     int w = Calc(mid, 0); n     if (w == k) { n       ans = mid; n       break; n     } n     if (r - l < 0.1 && w > k) { n       ans = mid; n       break; n     } n     if (w < k) n       r = mid; n     else n       ans = mid, l = mid; n   } n   Calc(ans, 1); n   printf( %d n , n - 1); n   while (p[0]) printf( %d  , p[p[0]--]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int h, w, ii, jj, ans = 0; n   cin >> h >> w; n   char a[505][505]; n   for (int i = 0; i < h; i++) n     for (int j = 0; j < w; j++) cin >> a[i][j]; n   for (int i = 0; i < h; i++) { n     for (int j = 0; j < w; j++) { n       if (a[i][j] ==  * ) { n         if ((i - 1 >= 0 && a[i - 1][j] ==  * ) && n             (j - 1 >= 0 && a[i][j - 1] ==  * ) && n             (i + 1 <= h - 1 && a[i + 1][j] ==  * ) && n             (j + 1 <= w - 1 && a[i][j + 1] ==  * )) { n           ii = i; n           jj = j; n           ans = 1; n           while (ii >= 0 && a[ii][jj] ==  * ) { n             a[ii][jj] =  @ ; n             ii--; n           } n           ii = i; n           a[ii][jj] =  * ; n           while (jj >= 0 && a[ii][jj] ==  * ) { n             a[ii][jj] =  @ ; n             jj--; n           } n           jj = j; n           a[ii][jj] =  * ; n           while (ii < h && a[ii][jj] ==  * ) { n             a[ii][jj] =  @ ; n             ii++; n           } n           ii = i; n           a[ii][jj] =  * ; n           while (jj < w && a[ii][jj] ==  * ) { n             a[ii][jj] =  @ ; n             jj++; n           } n           jj = j; n           break; n         } n       } n     } n     if (ans == 1) break; n   } n   if (ans == 0) { n     cout <<  NO ; n     return 0; n   } n   for (int i = 0; i < h; i++) { n     for (int j = 0; j < w; j++) { n       if (a[i][j] ==  * ) ans = 0; n     } n   } n   if (ans == 0) { n     cout <<  NO ; n   } else n     cout <<  YES ; n } n


#include <bits/stdc++.h> n using namespace std; n long long fac[100001]; n long long inv_fac[100001]; n int val[100001]; n vector<int> cnt(53, 0); n int l[100001]; n int r[100001]; n long long keep[53][53]; n long long dp[54][100001]; n long long dp1[54][100001]; n long long mod = 1e9 + 7; n inline void add(long long &a, long long b) { n   a += b; n   if (a >= mod) a -= mod; n } n inline void sub(long long &a, long long b) { n   a -= b; n   if (a < 0) a += mod; n } n long long pw(long long x, int p) { n   if (p == 0) return 1; n   if (p == 1) return x % mod; n   long long temp = pw(x, p / 2); n   temp = (temp * temp) % mod; n   if (p % 2 == 0) return temp; n   temp = (x * temp) % mod; n   return temp; n } n void calc() { n   fac[0] = fac[1] = 1; n   inv_fac[0] = inv_fac[1] = 1; n   for (int i = 2; i <= 100000; i++) { n     fac[i] = (i * fac[i - 1]) % mod; n     inv_fac[i] = pw(fac[i], mod - 2); n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   string s; n   cin >> s; n   int q; n   cin >> q; n   for (int i = 0; i < q; i++) cin >> l[i] >> r[i]; n   int n = s.size(); n   int mx = n / 2; n   calc(); n   for (int i = 0; i < n; i++) { n     if (s[i] >=  a  && s[i] <=  z ) { n       val[i + 1] = int(s[i] -  a ) + 1; n       cnt[int(s[i] -  a ) + 1]++; n     } else { n       val[i + 1] = 26 + int(s[i] -  A ) + 1; n       cnt[26 + int(s[i] -  A ) + 1]++; n     } n   } n   for (int i = 1; i <= 52; i++) { n     int temp = cnt[i]; n     if (temp > n / 2 || cnt[i] == 0) { n       continue; n     } n     temp = n / 2 - temp; n     for (int w = 0; w <= mx; w++) dp[0][w] = dp1[53][w] = 0; n     dp[0][0] = dp1[53][0] = 1; n     for (int k = 1; k <= 52; k++) { n       if (k == i || cnt[k] == 0) { n         for (int w = 0; w <= mx; w++) dp[k][w] = dp[k - 1][w]; n         continue; n       } n       for (int w = 0; w <= mx; w++) { n         dp[k][w] = dp[k - 1][w]; n         if (w >= cnt[k]) add(dp[k][w], dp[k - 1][w - cnt[k]]); n       } n     } n     for (int k = 52; k >= 1; k--) { n       if (k == i || cnt[k] == 0) { n         for (int w = 0; w <= mx; w++) dp1[k][w] = dp1[k + 1][w]; n         continue; n       } n       for (int w = 0; w <= mx; w++) { n         dp1[k][w] = dp1[k + 1][w]; n         if (w >= cnt[k]) add(dp1[k][w], dp1[k + 1][w - cnt[k]]); n       } n     } n     for (int k = i; k <= 52; k++) { n       if (k == i) { n         keep[k][i] = dp[52][temp]; n         continue; n       } n       long long t1 = 0; n       int rem = temp - cnt[k]; n       if (rem < 0) { n         keep[k][i] = keep[i][k] = 0; n         continue; n       } n       for (int w = 0; w <= rem; w++) { n         long long t2 = (dp[k - 1][w] * dp1[k + 1][rem - w]) % mod; n         add(t1, t2); n       } n       keep[i][k] = keep[k][i] = t1; n     } n   } n   long long ans = (fac[n / 2] * fac[n / 2]) % mod; n   for (int i = 1; i <= 52; i++) ans = (ans * inv_fac[cnt[i]]) % mod; n   ans = (2 * ans) % mod; n   for (int i = 0; i < q; i++) { n     int x = val[l[i]]; n     int y = val[r[i]]; n     long long temp = ans; n     temp = (temp * keep[x][y]) % mod; n     cout << temp << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 100010, M = 100010, inf = 1e18; n long long m, n, p, d[N], a[M], f[M], sum[M], g[M], x[M], y[M]; n inline long long read() { n   char ch = getchar(); n   long long as = 0, f = 1; n   for (; ch <  0  || ch >  9 ; ch = getchar()) n     if (ch ==  - ) f = -1; n   for (; ch >=  0  && ch <=  9 ; ch = getchar()) as = as * 10 + ch -  0 ; n   return as; n } n long long q[M << 1], l, r; n long long as = inf; n int main() { n   long long h, t; n   n = read(); n   m = read(); n   p = read(); n   for (long long i = 1; i < n; i++) d[i] = read(); n   for (long long i = n - 2; i; i--) d[i] += d[i + 1]; n   for (long long i = 1; i <= m; i++) { n     h = read(); n     t = read(); n     a[i] = t + d[h]; n   } n   sort(a + 1, a + m + 1); n   for (long long i = 1; i <= m; i++) sum[i] = sum[i - 1] + a[i], f[i] = inf; n   for (long long i = 1; i <= p; i++) { n     memcpy(g, f, sizeof(g)); n     l = M; n     r = M; n     for (long long j = 0; j <= m; j++) y[j] = g[j] + sum[j]; n     q[r] = 0; n     for (long long j = 1; j <= m; j++) { n       while (r > l) n         if ((y[q[l + 1]] - y[q[l]]) <= a[j] * (q[l + 1] - q[l])) n           l++; n         else n           break; n       f[j] = min(g[j], -a[j] * q[l] + y[q[l]] + a[j] * j - sum[j]); n       while (r > l) n         if ((y[q[r]] - y[q[r - 1]]) * (j - q[r]) >= n             (y[j] - y[q[r]]) * (q[r] - q[r - 1])) n           r--; n         else n           break; n       r++; n       q[r] = j; n     } n     as = min(as, f[m]); n   } n   printf( %lld , as); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 1e5 + 5; n vector<pair<long long, long long>> v; n int main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); n   long long x, y, bx, by, xs, ys, t, temp1, temp2, temp; n   long long ax, ay; n   int ans = 0; n   cin >> x >> y >> ax >> ay >> bx >> by >> xs >> ys >> t; n   while (x <= 5e16 && y <= 5e16) { n     v.push_back({x, y}); n     x = ax * x + bx; n     y = ay * y + by; n   } n   for (int i = 0; i < v.size(); i++) { n     for (int j = i; j < v.size(); j++) { n       temp = abs(v[i].first - v[j].first) + abs(v[i].second - v[j].second); n       temp1 = abs(v[i].first - xs) + abs(v[i].second - ys); n       temp2 = abs(xs - v[j].first) + abs(ys - v[j].second); n       if (temp + temp1 <= t) { n         ans = max(ans, j - i + 1); n       } n       if (temp + temp2 <= t) { n         ans = max(ans, j - i + 1); n       } n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int f[101010]; n long long s[101010]; n long long a[101010]; n int main() { n   ios_base::sync_with_stdio(0); n   long long n, l; n   cin >> n >> l; n   for (int i = 1; i <= n; ++i) cin >> a[i]; n   sort(a + 1, a + n + 1); n   if (n == 1) { n     cout << fixed << setprecision(10) << (long double)max(a[1], l - a[1]); n     return 0; n   } n   a[0] = 0; n   long long ans = 0; n   a[n + 1] = l; n   for (int i = 1; i <= n + 1; ++i) ans = max(ans, a[i] - a[i - 1]); n   ans = max(ans, max(a[1] * 2, (a[n + 1] - a[n]) * 2)); n   cout << fixed << setprecision(10) << (long double)(ans / 2.0); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 501; n int dp[maxn][maxn]; n int n; n int a[maxn]; n int dp2[maxn]; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i], dp[i][i] = a[i]; n   for (int len = 1; len <= n; len++) { n     for (int i = 1; i <= n - len + 1; i++) { n       for (int k = i; k < i + len - 1; k++) { n         if (dp[i][k] != 0 && dp[i][k] == dp[k + 1][i + len - 1]) { n           dp[i][i + len - 1] = dp[i][k] + 1; n         } n       } n     } n   } n   for (int i = 1; i <= n; i++) { n     dp2[i] = dp2[i - 1] + 1; n     for (int j = 1; j < i; j++) { n       if (dp[j][i] > 0) { n         dp2[i] = min(dp2[i], dp2[j - 1] + 1); n       } n     } n   } n   printf( %d n , dp2[n]); n   return 0; n } n


#include <bits/stdc++.h> n const int N = 1000010, P = 1000000007; n int n, i, j, x, ans, po[N], a[N], f[N]; n int main() { n   scanf( %d , &n); n   for (po[0] = i = 1; i <= n; i++) po[i] = 2 * po[i - 1] % P; n   while (n--) scanf( %d , &x), a[x]++; n   for (i = N - 1; i > 1; i--) { n     for (j = i, x = 0; j < N; j += i) x += a[j]; n     if (x) { n       f[i] = 1LL * x * po[x - 1] % P; n       for (j = i + i; j < N; j += i) f[i] = (f[i] - f[j] + P) % P; n       ans = (1LL * f[i] * i + ans) % P; n     } n   } n   printf( %d , ans); n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T __sqr(const T x) { n   return x * x; n } n template <class T, class X> n inline T __pow(T a, X y) { n   T z = 1; n   for (int i = 1; i <= y; i++) { n     z *= a; n   } n   return z; n } n template <class T> n inline T gcd(T a, T b) { n   a = abs(a); n   b = abs(b); n   if (!b) return a; n   return __gcd(b, a % b); n } n template <class T> n inline T lcm(T a, T b) { n   a = abs(a); n   b = abs(b); n   return (a / __gcd(a, b)) * b; n } n inline bool ispow2(int x) { return (x != 0 && (x & (x - 1)) == 0); } n template <class T> n void UpdateMin(T &x, T y) { n   if (y < x) { n     x = y; n   } n } n template <class T> n void UpdateMax(T &x, T y) { n   if (x < y) { n     x = y; n   } n } n template <class T, class X, class Y> n inline T bigmod(T n, X m, Y mod) { n   unsigned long long ret = 1, a = n % mod; n   while (m) { n     if (m & 1) ret = (ret * a) % mod; n     m >>= 1; n     a = (a * a) % mod; n   } n   ret %= mod; n   return (T)ret; n } n template <class T, class Y> n inline T modinv(T n, Y mod) { n   return bigmod(n, mod - 2, mod); n } n template <class T, class X> n int getbit(T s, X i) { n   return (s >> i) & 1; n } n template <class T, class X> n T onbit(T s, X i) { n   return s | (T(1) << i); n } n template <class T, class X> n T offbit(T s, X i) { n   return s & (~(T(1) << i)); n } n template <class T> n inline void read(T &n) { n   char c; n   for (c = getchar(); !(c >=  0  && c <=  9 ); c = getchar()) n     ; n   n = c -  0 ; n   for (c = getchar(); c >=  0  && c <=  9 ; c = getchar()) n = n * 10 + c -  0 ; n } n void extended_euclid(long long a, long long b, long long &x, long long &y) { n   if (!b) { n     x = 1, y = 0; n     return; n   } n   long long first, second; n   extended_euclid(b, a % b, first, second); n   x = second; n   y = first - (a / b) * second; n } n pair<long long, pair<long long, long long> > extendedEuclid(long long a, n                                                             long long b) { n   long long x = 1, y = 0; n   long long xLast = 0, yLast = 1; n   long long q, r, m, n; n   while (a != 0) { n     q = b / a; n     r = b % a; n     m = xLast - q * x; n     n = yLast - q * y; n     xLast = x, yLast = y; n     x = m, y = n; n     b = a, a = r; n   } n   return make_pair(b, make_pair(xLast, yLast)); n } n const long long mod[] = {0,          1000000007, 1000000009, n                          1000000021, 1000000033, 1000000097, n                          1000000093, 1000000097, 1000000103}; n const long long base[] = {0,       1000003, 1000033, 1000037, 1000039, n                           1000081, 1000099, 1000117, 1000121}; n int a[(2000 + 20)], b[(2000 + 20)], pos[(2000 + 20)], loc[(2000 + 20)]; n vector<pair<int, int> > ans; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , a + i); n   } n   for (int i = 1; i <= n; i++) { n     scanf( %d , b + i); n     swap(a[i], b[i]); n   } n   for (int i = 1; i <= n; i++) { n     pos[a[i]] = i; n   } n   for (int i = 1; i <= n; i++) { n     b[i] = pos[b[i]]; n     loc[b[i]] = i; n   } n   int tot = 0; n   for (int i = n; i >= 1; i--) { n     if (i == b[i]) continue; n     tot += i - loc[i]; n     int idx = loc[i]; n     for (int j = idx + 1; j <= i; j++) { n       if (b[j] <= 0) assert(0); n       if (idx >= b[j]) { n         if (idx > 2000) n           assert(1 > 0); n         else n           ans.push_back(make_pair(idx, j)); n         loc[b[j]] = idx; n         swap(b[j], b[idx]); n         idx = j; n       } n     } n   } n   printf( %d n , tot); n   printf( %d n , ans.size()); n   for (int i = 0; i < ((int)ans.size()); i++) { n     printf( %d %d n , ans[i].first, ans[i].second); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n istream& operator>>(istream& in, vector<T>& vec) { n   for (auto& v : vec) { n     in >> v; n   } n   return in; n } n template <class T> n ostream& operator<<(ostream& o, const vector<T>& vec) { n   o <<  [ ; n   for (const auto& v : vec) { n     o << v <<    ; n   } n   o <<  ] n ; n   return o; n } n int main() { n   int n, m, t; n   cin >> n >> m >> t; n   vector<vector<int>> mat(n, vector<int>(m)); n   vector<vector<int>> bsm(m); n   cin >> mat; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (mat[i][j] != 2) { n         bsm[j].push_back(i); n       } n     } n   } n   while (t--) { n     int colI, rowI = -1; n     cin >> colI; n     colI--; n     while (true) { n       int newRowI = n; n       { n         auto& bsv = bsm[colI]; n         int l = 0, r = bsv.size(), m; n         while (l < r) { n           m = (l + r) / 2; n           if (bsv[m] < rowI) { n             l = m + 1; n           } else { n             r = m; n           } n         } n         if (l < bsv.size()) { n           newRowI = bsv[l]; n           int i = l + 1; n           for (; i < bsv.size() && bsv[i] == bsv[l]; i++) { n           } n           if (i < bsv.size()) { n             for (int a = l; a < i; a++) { n               bsv[a] = bsv[i]; n             } n           } else { n             while (i-- > l) { n               bsv.pop_back(); n             } n           } n         } n       } n       rowI = newRowI; n       if (rowI >= n) { n         cout << colI + 1 <<    ; n         break; n       } else { n         if (mat[rowI][colI] == 1) { n           colI++; n         } else { n           colI--; n         } n       } n     } n   } n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2005; n int n, m, ans[N], h[N]; n bitset<N> a[N]; n vector<int> e[N]; n bool check1() { n   for (int i = (int)(1); i <= (int)(n); i++) n     if (e[i].size() & 1) return 0; n   return 1; n } n void gauss() { n   int it = 1; n   for (int i = (int)(1); i <= (int)(n); i++) { n     int j = it; n     for (; j <= n; j++) n       if (a[j][i]) break; n     if (j > n) continue; n     if (j > it) swap(a[j], a[it]); n     h[it] = i; n     for (int j = (int)(it + 1); j <= (int)(n); j++) n       if (a[j][i]) a[j] ^= a[it]; n     it++; n   } n   int las = n + 1; n   for (int i = (int)(it - 1); i >= (int)(1); i--) { n     for (int j = (int)(h[i] + 1); j <= (int)(las - 1); j++) ans[j] = 0; n     ans[h[i]] = a[i][0]; n     for (int j = (int)(1); j <= (int)(i - 1); j++) n       if (a[j][h[i]]) a[j] ^= a[i]; n     las = h[i]; n   } n   for (int i = (int)(1); i <= (int)(las - 1); i++) ans[i] = 0; n } n void solve() { n   scanf( %d%d , &n, &m); n   for (int i = (int)(1); i <= (int)(n); i++) e[i].clear(); n   for (int i = (int)(1); i <= (int)(m); i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     e[x].push_back(y); n     e[y].push_back(x); n   } n   if (check1()) { n     puts( 1 ); n     for (int i = (int)(1); i <= (int)(n); i++) printf( 1  ); n     puts(  ); n     return; n   } n   for (int i = (int)(1); i <= (int)(n); i++) { n     a[i] = 0; n     for (auto j : e[i]) a[i].set(j); n     if (e[i].size() & 1) a[i].set(i), a[i].set(0); n   } n   memset(ans, 0, sizeof(ans)); n   gauss(); n   puts( 2 ); n   for (int i = (int)(1); i <= (int)(n); i++) printf( %d  , ans[i] + 1); n   puts(  ); n } n int main() { n   int T; n   scanf( %d , &T); n   while (T--) solve(); n } n


#include <bits/stdc++.h> n #pragma warning(disable : 4786) n #pragma comment(linker,  /STACK:16777216 ) n using namespace std; n int A[100005]; n int I[100005]; n int D[100005]; n int n; n int max(int a, int b) { n   if (a > b) return a; n   return b; n } n int ABS(int a) { n   if (a < 0) return a = a * -1; n   return a; n } n int main() { n   int i, j, len, res, cur, res1; n   while (scanf( %d , &n) != EOF) { n     for (i = 0; i < n; i++) { n       scanf( %d , &A[i]); n     } n     I[0] = 1; n     for (i = 1; i < n; i++) { n       if (A[i] > A[i - 1]) { n         I[i] = I[i - 1] + 1; n       } else { n         I[i] = 1; n       } n     } n     D[n - 1] = 1; n     for (i = n - 1; i >= 0; i--) { n       if (A[i] < A[i + 1]) { n         D[i] = D[i + 1] + 1; n       } else { n         D[i] = 1; n       } n     } n     res = 1; n     for (i = 0; i < n; i++) { n       if (i == 0) { n         if (i + 1 < n) res = max(res, D[i + 1] + 1); n       } else if (i == n - 1) { n         if (i - 1 >= 0) res = max(res, I[i - 1] + 1); n       } else { n         int r = I[i - 1] + D[i + 1]; n         if (ABS(A[i - 1] - A[i + 1]) > 1 && A[i + 1] > A[i - 1]) { n           res = max(res, r + 1); n         } n         res = max(res, I[i - 1] + 1); n         res = max(res, D[i + 1] + 1); n       } n     } n     printf( %d n , res); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 998244353; n long long POW(long long a, long long b, long long MMM = MOD) { n   long long ret = 1; n   for (; b; b >>= 1, a = (a * a) % MMM) n     if (b & 1) ret = (ret * a) % MMM; n   return ret; n } n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n long long lcm(long long a, long long b) { n   if (a == 0 || b == 0) return a + b; n   return a * (b / gcd(a, b)); n } n int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, 1, -1}; n int ddx[] = {-1, -2, 1, -2, 2, -1, 2, 1}, ddy[] = {-2, -1, -2, 1, -1, 2, 1, 2}; n struct Edge { n   int to, r; n   Edge* ori; n   Edge* rev; n   Edge(int T, int R) { to = T, r = R; } n }; n vector<Edge*> v[2605]; n void addedge(int f, int t, int r) { n   Edge* ori = new Edge(t, r); n   Edge* rev = new Edge(f, 0); n   ori->rev = rev; n   rev->rev = ori; n   v[f].push_back(ori); n   v[t].push_back(rev); n } n const int S = 2603, T = 2604; n int level[2605], work[2605]; n bool bfs() { n   memset((level), -1, sizeof(level)); n   ; n   level[S] = 0; n   queue<int> q; n   q.push(S); n   while (!q.empty()) { n     int x = q.front(); n     q.pop(); n     for (auto& nn : v[x]) { n       int next = nn->to; n       if (level[next] == -1 && nn->r > 0) { n         level[next] = level[x] + 1; n         q.push(next); n       } n     } n   } n   return level[T] != -1; n } n int dfs(int N, int des, int flow) { n   if (N == des) return flow; n   for (int& i = work[N]; i < v[N].size(); i++) { n     int next = v[N][i]->to; n     if (level[next] == level[N] + 1 && v[N][i]->r > 0) { n       int df = dfs(next, des, min(v[N][i]->r, flow)); n       if (df > 0) { n         v[N][i]->r -= df; n         v[N][i]->rev->r += df; n         return df; n       } n     } n   } n   return 0; n } n int main() { n   int n, h, m; n   scanf( %d%d%d , &n, &h, &m); n   int ans = n * h * h; n   for (int(i) = (0); (i) <= (n - 1); (i) += (1)) { n     addedge(S, i * 51, h * h); n     for (int(j) = (1); (j) <= (h); (j) += (1)) n       addedge(51 * i + j - 1, 51 * i + j, h * h - j * j); n   } n   for (int(i) = (0); (i) <= (m - 1); (i) += (1)) { n     int x, y, z, w; n     scanf( %d%d%d%d , &x, &y, &z, &w); n     x--, y--; n     for (int(j) = (x); (j) <= (y); (j) += (1)) n       addedge(51 * j + z, 2551 + i, 987654321); n     addedge(2551 + i, T, w); n   } n   while (bfs()) { n     memset((work), 0, sizeof(work)); n     ; n     while (1) { n       int f = dfs(S, T, 987654321); n       if (f == 0) break; n       ans -= f; n     } n   } n   printf( %d n , ans); n } n