#include <bits/stdc++.h> n using namespace std; n using lint = long long; n using pint = pair<int, int>; n using plint = pair<lint, lint>; n struct fast_ios { n   fast_ios() { n     cin.tie(nullptr), ios::sync_with_stdio(false), n         cout << fixed << setprecision(20); n   }; n } fast_ios_; n template <typename T, typename V> n void ndarray(vector<T> &vec, const V &val, int len) { n   vec.assign(len, val); n } n template <typename T, typename V, typename... Args> n void ndarray(vector<T> &vec, const V &val, int len, Args... args) { n   vec.resize(len), n       for_each(begin(vec), end(vec), [&](T &v) { ndarray(v, val, args...); }); n } n template <typename T> n bool chmax(T &m, const T q) { n   return m < q ? (m = q, true) : false; n } n template <typename T> n bool chmin(T &m, const T q) { n   return m > q ? (m = q, true) : false; n } n int floor_lg(long long x) { return x <= 0 ? -1 : 63 - __builtin_clzll(x); } n template <typename T1, typename T2> n pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { n   return make_pair(l.first + r.first, l.second + r.second); n } n template <typename T1, typename T2> n pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { n   return make_pair(l.first - r.first, l.second - r.second); n } n template <typename T> n vector<T> sort_unique(vector<T> vec) { n   sort(vec.begin(), vec.end()), n       vec.erase(unique(vec.begin(), vec.end()), vec.end()); n   return vec; n } n template <typename T> n int arglb(const std::vector<T> &v, const T &x) { n   return std::distance(v.begin(), std::lower_bound(v.begin(), v.end(), x)); n } n template <typename T> n int argub(const std::vector<T> &v, const T &x) { n   return std::distance(v.begin(), std::upper_bound(v.begin(), v.end(), x)); n } n template <typename T> n istream &operator>>(istream &is, vector<T> &vec) { n   for (auto &v : vec) is >> v; n   return is; n } n template <typename T> n ostream &operator<<(ostream &os, const vector<T> &vec) { n   os <<  [ ; n   for (auto v : vec) os << v <<  , ; n   os <<  ] ; n   return os; n } n template <typename T, size_t sz> n ostream &operator<<(ostream &os, const array<T, sz> &arr) { n   os <<  [ ; n   for (auto v : arr) os << v <<  , ; n   os <<  ] ; n   return os; n } n template <typename T> n ostream &operator<<(ostream &os, const deque<T> &vec) { n   os <<  deq[ ; n   for (auto v : vec) os << v <<  , ; n   os <<  ] ; n   return os; n } n template <typename T> n ostream &operator<<(ostream &os, const set<T> &vec) { n   os <<  { ; n   for (auto v : vec) os << v <<  , ; n   os <<  } ; n   return os; n } n template <typename T, typename TH> n ostream &operator<<(ostream &os, const unordered_set<T, TH> &vec) { n   os <<  { ; n   for (auto v : vec) os << v <<  , ; n   os <<  } ; n   return os; n } n template <typename T> n ostream &operator<<(ostream &os, const multiset<T> &vec) { n   os <<  { ; n   for (auto v : vec) os << v <<  , ; n   os <<  } ; n   return os; n } n template <typename T> n ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) { n   os <<  { ; n   for (auto v : vec) os << v <<  , ; n   os <<  } ; n   return os; n } n template <typename T1, typename T2> n ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { n   os <<  (  << pa.first <<  ,  << pa.second <<  ) ; n   return os; n } n template <typename TK, typename TV> n ostream &operator<<(ostream &os, const map<TK, TV> &mp) { n   os <<  { ; n   for (auto v : mp) os << v.first <<  =>  << v.second <<  , ; n   os <<  } ; n   return os; n } n template <typename TK, typename TV, typename TH> n ostream &operator<<(ostream &os, const unordered_map<TK, TV, TH> &mp) { n   os <<  { ; n   for (auto v : mp) os << v.first <<  =>  << v.second <<  , ; n   os <<  } ; n   return os; n } n template <int md> n struct ModInt { n   using lint = long long; n   static int mod() { return md; } n   static int get_primitive_root() { n     static int primitive_root = 0; n     if (!primitive_root) { n       primitive_root = [&]() { n         std::set<int> fac; n         int v = md - 1; n         for (lint i = 2; i * i <= v; i++) n           while (v % i == 0) fac.insert(i), v /= i; n         if (v > 1) fac.insert(v); n         for (int g = 1; g < md; g++) { n           bool ok = true; n           for (auto i : fac) n             if (ModInt(g).pow((md - 1) / i) == 1) { n               ok = false; n               break; n             } n           if (ok) return g; n         } n         return -1; n       }(); n     } n     return primitive_root; n   } n   int val; n   ModInt() : val(0) {} n   ModInt &_setval(lint v) { return val = (v >= md ? v - md : v), *this; } n   ModInt(lint v) { _setval(v % md + md); } n   explicit operator bool() const { return val != 0; } n   ModInt operator+(const ModInt &x) const { n     return ModInt()._setval((lint)val + x.val); n   } n   ModInt operator-(const ModInt &x) const { n     return ModInt()._setval((lint)val - x.val + md); n   } n   ModInt operator*(const ModInt &x) const { n     return ModInt()._setval((lint)val * x.val % md); n   } n   ModInt operator/(const ModInt &x) const { n     return ModInt()._setval((lint)val * x.inv() % md); n   } n   ModInt operator-() const { return ModInt()._setval(md - val); } n   ModInt &operator+=(const ModInt &x) { return *this = *this + x; } n   ModInt &operator-=(const ModInt &x) { return *this = *this - x; } n   ModInt &operator*=(const ModInt &x) { return *this = *this * x; } n   ModInt &operator/=(const ModInt &x) { return *this = *this / x; } n   friend ModInt operator+(lint a, const ModInt &x) { n     return ModInt()._setval(a % md + x.val); n   } n   friend ModInt operator-(lint a, const ModInt &x) { n     return ModInt()._setval(a % md - x.val + md); n   } n   friend ModInt operator*(lint a, const ModInt &x) { n     return ModInt()._setval(a % md * x.val % md); n   } n   friend ModInt operator/(lint a, const ModInt &x) { n     return ModInt()._setval(a % md * x.inv() % md); n   } n   bool operator==(const ModInt &x) const { return val == x.val; } n   bool operator!=(const ModInt &x) const { return val != x.val; } n   bool operator<(const ModInt &x) const { return val < x.val; } n   friend std::istream &operator>>(std::istream &is, ModInt &x) { n     lint t; n     return is >> t, x = ModInt(t), is; n   } n   friend std::ostream &operator<<(std::ostream &os, const ModInt &x) { n     return os << x.val; n   } n   ModInt pow(lint n) const { n     ModInt ans = 1, tmp = *this; n     while (n) { n       if (n & 1) ans *= tmp; n       tmp *= tmp, n >>= 1; n     } n     return ans; n   } n   static std::vector<ModInt> facs, facinvs, invs; n   static void _precalculation(int N) { n     int l0 = facs.size(); n     if (N > md) N = md; n     if (N <= l0) return; n     facs.resize(N), facinvs.resize(N), invs.resize(N); n     for (int i = l0; i < N; i++) facs[i] = facs[i - 1] * i; n     facinvs[N - 1] = facs.back().pow(md - 2); n     for (int i = N - 2; i >= l0; i--) facinvs[i] = facinvs[i + 1] * (i + 1); n     for (int i = N - 1; i >= l0; i--) invs[i] = facinvs[i] * facs[i - 1]; n   } n   lint inv() const { n     if (this->val < std::min(md >> 1, 1 << 21)) { n       while (this->val >= int(facs.size())) _precalculation(facs.size() * 2); n       return invs[this->val].val; n     } else { n       return this->pow(md - 2).val; n     } n   } n   ModInt fac() const { n     while (this->val >= int(facs.size())) _precalculation(facs.size() * 2); n     return facs[this->val]; n   } n   ModInt facinv() const { n     while (this->val >= int(facs.size())) _precalculation(facs.size() * 2); n     return facinvs[this->val]; n   } n   ModInt doublefac() const { n     lint k = (this->val + 1) / 2; n     return (this->val & 1) n                ? ModInt(k * 2).fac() / (ModInt(2).pow(k) * ModInt(k).fac()) n                : ModInt(k).fac() * ModInt(2).pow(k); n   } n   ModInt nCr(const ModInt &r) const { n     return (this->val < r.val) n                ? 0 n                : this->fac() * (*this - r).facinv() * r.facinv(); n   } n   ModInt nPr(const ModInt &r) const { n     return (this->val < r.val) ? 0 : this->fac() * (*this - r).facinv(); n   } n   ModInt sqrt() const { n     if (val == 0) return 0; n     if (md == 2) return val; n     if (pow((md - 1) / 2) != 1) return 0; n     ModInt b = 1; n     while (b.pow((md - 1) / 2) == 1) b += 1; n     int e = 0, m = md - 1; n     while (m % 2 == 0) m >>= 1, e++; n     ModInt x = pow((m - 1) / 2), y = (*this) * x * x; n     x *= (*this); n     ModInt z = b.pow(m); n     while (y != 1) { n       int j = 0; n       ModInt t = y; n       while (t != 1) j++, t *= t; n       z = z.pow(1LL << (e - j - 1)); n       x *= z, z *= z, y *= z; n       e = j; n     } n     return ModInt(std::min(x.val, md - x.val)); n   } n }; n template <int md> n std::vector<ModInt<md>> ModInt<md>::facs = {1}; n template <int md> n std::vector<ModInt<md>> ModInt<md>::facinvs = {1}; n template <int md> n std::vector<ModInt<md>> ModInt<md>::invs = {0}; n using mint = ModInt<998244353>; n template <int LEN, class S, S (*op)(S, S), class F, S (*reversal)(S), n           S (*mapping)(F, S), F (*composition)(F, F), F (*id)()> n struct lazy_rbst { n   inline uint32_t _rand() { n     static uint32_t x = 123456789, y = 362436069, z = 521288629, w = 88675123; n     uint32_t t = x ^ (x << 11); n     x = y; n     y = z; n     z = w; n     return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); n   } n   struct Node { n     Node *l, *r; n     S val, sum; n     F lz; n     bool is_reversed; n     int sz; n     Node(const S &v) n         : l(nullptr), n           r(nullptr), n           val(v), n           sum(v), n           lz(id()), n           is_reversed(false), n           sz(1) {} n     Node() : l(nullptr), r(nullptr), lz(id()), is_reversed(false), sz(0) {} n     template <class OStream> n     friend OStream &operator<<(OStream &os, const Node &n) { n       os <<  [ ; n       if (n.l) os << *(n.l) <<  , ; n       os << n.val <<  , ; n       if (n.r) os << *(n.r); n       return os <<  ] ; n     } n   }; n   using Nptr = Node *; n   std::array<Node, LEN> data; n   int d_ptr; n   int size(Nptr t) const { return t != nullptr ? t->sz : 0; } n   lazy_rbst() : d_ptr(0) {} n  n  protected: n   Nptr update(Nptr t) { n     t->sz = 1; n     t->sum = t->val; n     if (t->l) { n       t->sz += t->l->sz; n       t->sum = op(t->l->sum, t->sum); n     } n     if (t->r) { n       t->sz += t->r->sz; n       t->sum = op(t->sum, t->r->sum); n     } n     return t; n   } n   void all_apply(Nptr t, F f) { n     t->val = mapping(f, t->val); n     t->sum = mapping(f, t->sum); n     t->lz = composition(f, t->lz); n   } n   void _toggle(Nptr t) { n     auto tmp = t->l; n     t->l = t->r, t->r = tmp; n     t->sum = reversal(t->sum); n     t->is_reversed ^= true; n   } n   void push(Nptr &t) { n     _duplicate_node(t); n     if (t->lz != id()) { n       if (t->l) { n         _duplicate_node(t->l); n         all_apply(t->l, t->lz); n       } n       if (t->r) { n         _duplicate_node(t->r); n         all_apply(t->r, t->lz); n       } n       t->lz = id(); n     } n     if (t->is_reversed) { n       if (t->l) _toggle(t->l); n       if (t->r) _toggle(t->r); n       t->is_reversed = false; n     } n   } n   virtual void _duplicate_node(Nptr &) {} n   Nptr _make_node(const S &val) { n     if (d_ptr >= LEN) throw; n     return &(data[d_ptr++] = Node(val)); n   } n  n  public: n   Nptr new_tree() { return nullptr; } n   int mem_used() const { return d_ptr; } n   bool empty(Nptr t) const { return t == nullptr; } n   Nptr merge(Nptr l, Nptr r) { n     if (l == nullptr or r == nullptr) return l != nullptr ? l : r; n     if (_rand() % uint32_t(l->sz + r->sz) < uint32_t(l->sz)) { n       push(l); n       l->r = merge(l->r, r); n       return update(l); n     } else { n       push(r); n       r->l = merge(l, r->l); n       return update(r); n     } n   } n   std::pair<Nptr, Nptr> split(Nptr &root, int k) { n     if (root == nullptr) return std::make_pair(nullptr, nullptr); n     push(root); n     if (k <= size(root->l)) { n       auto p = split(root->l, k); n       root->l = p.second; n       return std::make_pair(p.first, update(root)); n     } else { n       auto p = split(root->r, k - size(root->l) - 1); n       root->r = p.first; n       return std::make_pair(update(root), p.second); n     } n   } n   void insert(Nptr &root, int pos, const S &x) { n     auto p = split(root, pos); n     root = merge(p.first, merge(_make_node(x), p.second)); n   } n   void erase(Nptr &root, int pos) { n     auto p = split(root, pos); n     auto p2 = split(p.second, 1); n     root = merge(p.first, p2.second); n   } n   void set(Nptr &root, int pos, const S &x) { n     auto p = split(root, pos); n     auto p2 = split(p.second, 1); n     _duplicate_node(p2.first); n     *p2.first = Node(x); n     root = merge(p.first, merge(p2.first, p2.second)); n   } n   void apply(Nptr &root, int l, int r, const F &f) { n     auto p = split(root, l); n     auto p2 = split(p.second, r - l); n     all_apply(p2.first, f); n     root = merge(p.first, merge(p2.first, p2.second)); n   } n   S prod(Nptr &root, int l, int r) { n     auto p = split(root, l); n     auto p2 = split(p.second, r - l); n     if (p2.first != nullptr) push(p2.first); n     S res = p2.first->sum; n     root = merge(p.first, merge(p2.first, p2.second)); n     return res; n   } n   S get(Nptr &root, int pos) { return prod(root, pos, pos + 1); } n   void reverse(Nptr &root) { _duplicate_node(root), _toggle(root); } n   void reverse(Nptr &root, int l, int r) { n     auto p2 = split(root, r); n     auto p1 = split(p2.first, l); n     reverse(p1.second); n     root = merge(merge(p1.first, p1.second), p2.second); n   } n   void assign(Nptr &root, const std::vector<S> &init) { n     d_ptr = 0; n     int N = init.size(); n     root = N ? _assign_range(0, N, init) : new_tree(); n   } n   Nptr _assign_range(int l, int r, const std::vector<S> &init) { n     if (r - l == 1) { n       Nptr t = _make_node(init[l]); n       return update(t); n     } n     return merge(_assign_range(l, (l + r) / 2, init), n                  _assign_range((l + r) / 2, r, init)); n   } n   void dump(Nptr &t, std::vector<S> &vec) { n     if (t == nullptr) return; n     push(t); n     dump(t->l, vec); n     vec.push_back(t->val); n     dump(t->r, vec); n   } n   void re_alloc(Nptr &root) { n     std::vector<S> mem; n     dump(root, mem); n     assign(root, mem); n   } n }; n using S = int; n S op(S l, S r) { return l > r ? l : r; } n using F = pair<bool, int>; n S reversal(S x) { return x; } n S mapping(F f, S x) { return f.first ? f.second + x : x; } n F composition(F f, F g) { n   if (!f.first) return g; n   if (!g.first) return f; n   return {true, f.second + g.second}; n } n F id() { return {false, 0}; } n lazy_rbst<2000000, S, op, F, reversal, mapping, composition, id> tree; n mint solve() { n   int N, M; n   cin >> N >> M; n   vector<pint> xy(M); n   for (auto &[x, y] : xy) cin >> x >> y; n   auto root = tree.new_tree(); n   tree.assign(root, {0}); n   for (auto [x, y] : xy) { n     const int len = root->sz; n     int lo = 1, hi = len + 1; n     while (hi - lo > 1) { n       int c = (lo + hi) / 2; n       (tree.prod(root, 0, c) < y - 1 ? lo : hi) = c; n     } n     if (lo == len) { n       tree.insert(root, len, y); n     } else if (tree.get(root, lo) == y - 1) { n       tree.apply(root, lo, len, {true, 1}); n     } else { n       tree.apply(root, lo, len, {true, 1}); n       tree.insert(root, lo, y); n     } n   } n   int sz = root->sz; n   if (tree.get(root, 0) == 0) sz--; n   sz = N - 1 - sz; n   return mint(N + sz).nCr(sz); n } n int main() { n   int T; n   cin >> T; n   while (T--) cout << solve() <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, test, n, m, value; n   cin >> test; n   while (test--) { n     int s = 0; n     cin >> n >> m; n     for (i = 1; i <= n; i++) { n       cin >> value; n       s += value; n     } n     if (s == m) { n       printf( YES n ); n     } else { n       printf( NO n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e4 + 5; n int a[maxn]; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n   } n   while (m--) { n     int l, r, x; n     scanf( %d%d%d , &l, &r, &x); n     int cnt1 = 0, cnt2 = 0; n     for (int i = l; i <= r; i++) { n       if (a[i] < a[x]) cnt1++; n       if (a[i] == a[x]) cnt2++; n     } n     if (cnt1 + l - 1 < x && cnt2 + cnt1 + l - 1 >= x) n       puts( Yes ); n     else n       puts( No ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<long long, int> getFactors(long long n) { n   long long num = n; n   long long sqrn = sqrt(n); n   map<long long, int> ret; n   for (long long i = 2; i <= sqrn; i++) n     while (num % i == 0) { n       ret[i]++; n       num /= i; n     } n   if (num > 1 && num != n) ret[num]++; n   return ret; n } n void solve(long long n) { n   map<long long, int> factors = getFactors(n); n   if (factors.size() == 0) { n     cout << 1 <<   n  << 0 <<   n ; n     return; n   } n   vector<long long> keys; n   for (auto &p : factors) keys.push_back(p.first); n   if (keys.size() > 2 || n       (keys.size() == 2 && (factors[keys[0]] > 1 || factors[keys[1]] > 1))) { n     cout << 1 <<   n ; n     cout << keys[0] * keys[1] <<   n ; n     return; n   } n   if (keys.size() == 1 && factors[keys[0]] > 2) { n     cout << 1 <<   n ; n     cout << keys[0] * keys[0] <<   n ; n     return; n   } n   cout << 2 <<   n ; n } n int main() { n   std::ios_base::sync_with_stdio(false); n   cin.tie(0); n   long long n; n   cin >> n; n   solve(n); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int v[100005], u[100005], w[100005], dist[100005]; n vector<pair<int, int> > edges[100005]; n priority_queue<pair<int, int>, vector<pair<int, int> >, n                greater<pair<int, int> > > n     pq; n int main() { n   int n, m, s, l; n   while (cin >> n >> m >> s) { n     for (int i = 0; i < m; ++i) { n       cin >> v[i] >> u[i] >> w[i]; n       edges[v[i]].push_back(make_pair(u[i], w[i])); n       edges[u[i]].push_back(make_pair(v[i], w[i])); n     } n     cin >> l; n     pq.push(make_pair(0, s)); n     memset(dist, 0x3f, sizeof(dist)); n     dist[s] = 0; n     int c, d, nxt; n     while (pq.size()) { n       c = pq.top().second; n       pq.pop(); n       for (int i = 0; i < edges[c].size(); ++i) { n         nxt = edges[c][i].first; n         if (dist[nxt] > dist[c] + edges[c][i].second) { n           dist[nxt] = dist[c] + edges[c][i].second; n           pq.push(make_pair(dist[nxt], nxt)); n         } n       } n     } n     int tmp; n     int cnt = 0; n     for (int i = 1; i <= n; ++i) n       if (dist[i] == l) ++cnt; n     for (int i = 0; i < m; ++i) { n       if (dist[u[i]] < l && dist[u[i]] + w[i] > l) { n         tmp = dist[u[i]] + w[i]; n         if (dist[v[i]] + tmp - l >= l) ++cnt; n       } n       if (dist[v[i]] < l && dist[v[i]] + w[i] > l) { n         tmp = dist[v[i]] + w[i]; n         if (dist[u[i]] + tmp - l > l) ++cnt; n       } n     } n     cout << cnt <<   n ; n     for (int i = 1; i <= n; ++i) edges[i].clear(); n     while (pq.size()) pq.pop(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 1000000 + 10; n const int Mod = 998244353; n const int alp = 3; n int n, S; n int C[MAX]; n int dp[MAX]; n namespace opt { n int N; n int a[MAX], b[MAX], w[MAX], tmp[MAX]; n int Pow(int a, int b) { n   int k = 1; n   for (; b; b /= 2, a = (long long)a * a % Mod) n     if (b % 2 == 1) k = (long long)k * a % Mod; n   return k; n } n void FFT(int *a, int S, int d) { n   if (d == N) return; n   FFT(a, S, d << 1); n   FFT(a, S + d, d << 1); n   for (int i = S, j = S, p = 0; i < N / 2; i += d, j += d << 1, p += d) { n     int G = a[j], K = a[j + d]; n     tmp[i] = ((long long)G + (long long)w[p] * K) % Mod; n     tmp[i + N / 2] = ((long long)G + (long long)w[p + N / 2] * K) % Mod; n   } n   for (int i = S; i < N; i += d) a[i] = tmp[i]; n } n void conv(int *aa, int *bb, int *c, int n) { n   for (int i = 0; i < n; ++i) a[i] = aa[i], b[i] = bb[i]; n   if (n <= 500) { n     for (int i = 0; i < n * 2; ++i) c[i] = 0; n     for (int i = 0; i < n; ++i) n       for (int j = 0; j < n; ++j) n         c[i + j] = (c[i + j] + (long long)a[i] * b[j]) % Mod; n     for (int i = 0; i < n; ++i) a[i] = b[i] = 0; n     return; n   } n   N = 1; n   for (; N < n; N <<= 1) n     ; n   N <<= 1; n   w[0] = 1; n   w[1] = Pow(alp, (Mod - 1) / N); n   for (int i = 2; i <= N; ++i) w[i] = (long long)w[i - 1] * w[1] % Mod; n   FFT(a, 0, 1); n   FFT(b, 0, 1); n   for (int i = 0; i < N; ++i) a[i] = (long long)a[i] * b[i] % Mod; n   for (int i = 0; i < N; ++i) b[i] = a[i ? (N - i) : 0]; n   FFT(b, 0, 1); n   int InvN = Pow(N, Mod - 2); n   for (int i = 0; i < N; ++i) { n     c[i] = (long long)b[i] * InvN % Mod; n     a[i] = b[i] = 0; n   } n } n }  // namespace opt n int a[MAX], b[MAX], c[MAX]; n void solve(int l, int r) { n   if (r == l + 1) return; n   int mid = (l + r) / 2; n   solve(l, mid); n   int i; n   int need = r - l; n   for (long long i = 0; i < need; i++) a[i] = b[i] = 0; n   if (l > 0) { n     for (long long i = 0; i < mid - l; i++) a[i] = dp[i + l]; n     for (long long i = 0; i < need; i++) b[i] = dp[i]; n     opt::conv(a, b, c, need); n     for (long long i = 0; i < need; i++) { n       c[i] *= 2; n       if (c[i] >= Mod) c[i] -= Mod; n     } n   } else { n     for (long long i = 0; i < mid - l; i++) a[i] = b[i] = dp[i + l]; n     opt::conv(a, b, c, need); n   } n   for (long long i = 0; i < need; i++) { n     a[i] = c[i]; n     b[i] = C[i]; n   } n   opt::conv(a, b, c, need); n   for (long long i = mid; i < r; i++) { n     dp[i] += c[i - l]; n     if (dp[i] >= Mod) dp[i] -= Mod; n   } n   solve(mid, r); n } n int main() { n   int i; n   scanf( %d%d , &n, &S); n   for (long long i = 1; i <= n; i++) { n     int a; n     scanf( %d , &a); n     C[a] = 1; n   } n   int N = 1; n   for (; N <= S; N *= 2) n     ; n   dp[0] = 1; n   solve(0, N); n   for (long long i = 1; i <= S; i++) printf( %d n , dp[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long aX[100001]; n long long aY[100001]; n int main() { n   long long n, k; n   cin >> n >> k; n   long long x, y; n   cin >> x >> y; n   long long mod = n * 2; n   for (int i = 0; i < n; i++) cin >> aX[i] >> aY[i]; n   k = k % mod; n   long long cx = 0, cy = 0; n   for (int i = 1; i <= k; i++) { n     cx = 2 * aX[(i - 1) % n] - cx; n     cy = 2 * aY[(i - 1) % n] - cy; n   } n   if (k % 2 == 1) n     cx -= x, cy -= y; n   else n     cx += x, cy += y; n   cout << cx <<     << cy << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int arr[100005]; n long long int l1[100005]; n long long int l2[100005]; n long long int d[100005]; n long long int e[100005]; n long long int tree[100005]; n long long int tree2[100005]; n void update(long long int idx, long long int val, long long int n) { n   while (idx <= n) { n     tree[idx] += val; n     idx += (idx & -idx); n   } n } n long long int read(long long int idx) { n   long long int sum = 0; n   while (idx > 0) { n     sum += tree[idx]; n     idx -= (idx & -idx); n   } n   return sum; n } n void update2(long long int idx, long long int val, long long int n) { n   while (idx <= n) { n     tree2[idx] += val; n     idx += (idx & -idx); n   } n } n long long int read2(long long int idx) { n   long long int sum = 0; n   while (idx > 0) { n     sum += tree2[idx]; n     idx -= (idx & -idx); n   } n   return sum; n } n int corona(int x, int y) { n   long long int s = 0, s1, s2; n   for (int i = x + 1; i <= y; i++) { n     if (l1[i] < l1[i - 1]) { n       s++; n       break; n     } n   } n   if (s == 0) n     return abs(y - x) + 1; n   else { n     s1 = corona(x, (x + y) / 2); n     s2 = corona(((x + y) / 2) + 1, y); n     return max(s1, s2); n   } n } n int main() { n   long long int n, a, q, b, t, c, m, k, x, y, x3 = 0, x4 = 0, x5 = 0; n   string s3, s4; n   cin >> t; n   while (t--) { n     cin >> n >> a >> b >> c; n     cin >> s3; n     for (int i = 0; i < s3.size(); i++) { n       if (s3[i] ==  R ) { n         if (b > 0) { n           b--; n           x3++; n           l1[i] =  P ; n         } n       } else if (s3[i] ==  P ) { n         if (c > 0) { n           c--; n           x3++; n           l1[i] =  S ; n         } n       } else if (s3[i] ==  S ) { n         if (a > 0) { n           a--; n           x3++; n           l1[i] =  R ; n         } n       } n     } n     if (x3 >= ceil(n / 2.0)) { n       cout <<  YES n ; n       for (int i = 0; i < s3.size(); i++) { n         if (l1[i] == 0 && a > 0) { n           l1[i] =  R ; n           a--; n         } else if (l1[i] == 0 && b > 0) { n           l1[i] =  P ; n           b--; n         } else if (l1[i] == 0 && c > 0) { n           l1[i] =  S ; n           c--; n         } n         s4 += (char)l1[i]; n       } n       cout << s4 << endl; n     } else n       cout <<  NO n ; n     x3 = 0; n     s4 =   ; n     memset(l1, 0, sizeof l1); n   } n   return 0; n } n


#include <bits/stdc++.h> n double pi = 3.1415926535897931159979635; n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long cf = 0, cs = 0, c47 = 0, c74 = 0; n   string a; n   cin >> a; n   long long s = a.size(); n   for (int i = 0; i < s; i++) { n     if (a[i] ==  4 ) { n       cf++; n       if (a[i - 1] ==  7  && i > 0) c74++; n     } else if (a[i] ==  7 ) { n       cs++; n       if (a[i - 1] ==  4  && i > 0) c47++; n     } n   } n   if (cf == 0 && cs == 0) n     cout <<  -1 n ; n   else n     s = max(c47, max(c74, max(cf, cs))); n   if (s == cf) n     cout <<  4 n ; n   else if (s == cs) n     cout <<  7 n ; n   else if (s == c47) n     cout <<  47 n ; n   else if (s == c74) n     cout <<  74 n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int heights(long long int n) { n   long long int count = 0, m, k; n   for (long long int x = 1; x <= n; x++) { n     m = 3 * x * x + x; n     if (m > 2 * n) n       break; n     else { n       k = x + n; n       if (k % 3 == 0) count++; n     } n   } n   return count; n } n int main() { n   long long int n; n   cin >> n; n   cout << heights(n); n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int w; n string ch(string s, char x, string b) { n   int n = s.size(); n   bool cx = 0; n   char mina =  z ; n   for (int i = 0; i < n; i++) { n     if (s[i] == x && b[i] > s[i]) { n       cx = 1; n       mina = min(mina, b[i]); n     } n   } n   if (!cx) { n     return s; n   } n   w++; n   for (int i = 0; i < n; i++) { n     if (s[i] == x) s[i] = mina; n   } n   return s; n } n void solve() { n   w = 0; n   int n; n   cin >> n; n   string a, b; n   cin >> a >> b; n   for (int i = 0; i < n; i++) { n     if (b[i] < a[i]) { n       cout <<  -1 n ; n       return; n     } n   } n   for (int i = 0; i < 20; i++) { n     a = ch(a, ((char)i + 97), b); n   } n   cout << w <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t) { n     t--; n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int SIZE = 84; n const int VERTS = SIZE * SIZE; n int n, m; n int v, s, t; n int pict[SIZE][SIZE]; n const int dir[4][2] = {{1, 0}, {-1, 0}, {0, -1}, {0, 1}}; n inline bool good(int x, int y) { return x >= 0 && y >= 0 && x < n && y < m; } n struct Edge { n   int a, b; n   int flow; n   int cap, cost; n   int anti; n }; n vector<Edge> edges; n vector<int> nbr[VERTS]; n void AddEdge(int a, int b, int cap, int cost) { n   Edge e1; n   e1.a = a; n   e1.b = b; n   e1.flow = 0; n   e1.cap = cap; n   e1.cost = cost; n   e1.anti = edges.size() + 1; n   Edge e2; n   e2.a = b; n   e2.b = a; n   e2.flow = 0; n   e2.cap = 0; n   e2.cost = -cost; n   e2.anti = edges.size(); n   nbr[a].push_back(edges.size()); n   nbr[b].push_back(edges.size() + 1); n   edges.push_back(e1); n   edges.push_back(e2); n } n bool used[VERTS]; n int dist[VERTS]; n int father[VERTS]; n int deq[VERTS]; n bool Dijkstra(int &allFlow, int &allCost) { n   memset(dist, 63, sizeof(dist)); n   memset(father, -1, sizeof(father)); n   memset(used, false, sizeof(used)); n   dist[s] = 0; n   int l = 0, r = 1; n   deq[0] = s; n   while (l < r) { n     int best = deq[l++]; n     used[best] = true; n     for (int i = 0; i < nbr[best].size(); i++) { n       int eidx = nbr[best][i]; n       const Edge &e = edges[eidx]; n       if (e.flow == e.cap) continue; n       int newd = dist[best] + e.cost; n       if (dist[e.b] > newd) { n         bool first = dist[e.b] > 1000000000; n         dist[e.b] = newd; n         father[e.b] = eidx; n         if (used[e.b]) { n           used[e.b] = false; n           deq[--l] = e.b; n         } n         if (first) deq[r++] = e.b; n       } n     } n   } n   if (!used[t]) return false; n   allFlow++; n   int curr = t; n   while (curr != s) { n     int eidx = father[curr]; n     Edge &e = edges[eidx]; n     int pp = e.a; n     e.flow++; n     edges[e.anti].flow--; n     allCost += e.cost; n     curr = pp; n   } n   return true; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) scanf( %d , &pict[i][j]); n   s = n * m; n   t = n * m + 1; n   v = n * m + 2; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       if ((i + j) & 1) { n         AddEdge(s, i * m + j, 1, 0); n         for (int d = 0; d < 4; d++) { n           int ni = i + dir[d][0]; n           int nj = j + dir[d][1]; n           if (!good(ni, nj)) continue; n           AddEdge(i * m + j, ni * m + nj, 1, pict[i][j] != pict[ni][nj]); n         } n       } else n         AddEdge(i * m + j, t, 1, 0); n     } n   int tflow = 0, tcost = 0; n   while (Dijkstra(tflow, tcost)) n     ; n   printf( %d n , tcost); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 998244353; n const double oula = 0.57721566490153286060651209; n using namespace std; n map<long long, string> mp; n int main() { n   std::ios::sync_with_stdio(false); n   long long n; n   cin >> n; n   long long nn = sqrt(n); n   string tmp; n   for (long long i = 2; i <= nn; i++) { n     long long num = i * i; n     int co = 2; n     while (num <= n) { n       tmp = to_string(i) +  ^  + to_string(co); n       if (!mp.count(num)) mp[num] = to_string(num); n       if (mp[num].size() > tmp.size()) mp[num] = tmp; n       co++; n       num *= i; n     } n   } n   string ans = to_string(n); n   map<long long, string>::iterator it; n   for (it = mp.begin(); it != mp.end(); it++) { n     tmp =   ; n     long long a = n / it->first, b = n % it->first; n     if (a > 1) { n       if (mp.count(a)) n         tmp = mp[a]; n       else n         tmp = to_string(a); n       tmp +=  * ; n     } n     tmp += it->second; n     if (b) tmp = tmp +  +  + (mp.count(b) ? mp[b] : to_string(b)); n     if (ans.size() > tmp.size()) ans = tmp; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int N; n int axor[1 << 16]; n int degree[1 << 16], s[1 << 16]; n vector<pair<int, int>> edge; n set<pair<int, int>> q; n int main() { n   scanf( %d , &N); n   for (int i = 0; i < N; i++) { n     scanf( %d %d , &degree[i], &s[i]); n     q.insert({degree[i], i}); n   } n   for (int i = 0; i < N; i++) { n     int x, y; n     x = (*q.begin()).second; n     if (degree[x] == 0) { n       q.erase({degree[x], x}); n       continue; n     } n     if (degree[x] > 1) n       while (true) n         ; n     y = s[x] ^ axor[x]; n     axor[x] ^= y; n     if (axor[x] != s[x]) n       while (true) n         ; n     axor[y] ^= x; n     q.erase({degree[y], y}); n     q.erase({degree[x], x}); n     degree[x]--; n     degree[y]--; n     q.insert({degree[y], y}); n     if (x == y) n       while (true) n         ; n     edge.push_back({x, y}); n   } n   for (int i = 0; i < N; i++) n     if (axor[i] != s[i]) n       while (true) n         ; n   printf( %d n , edge.size()); n   for (auto i : edge) { n     printf( %d %d n , i.first, i.second); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n unsigned long long int gcd(unsigned long long int a, unsigned long long int b) { n   unsigned long long int max = a > b ? a : b; n   unsigned long long int min = a < b ? a : b; n   if (max % min == 0) return min; n   if (max % min == 1) return 1; n   return gcd(min, max % min); n } n int main() { n   int flag = 0; n   unsigned long long int l, r; n   cin >> l >> r; n   if (l - r < 2) { n     cout <<  -1 ; n     return 0; n   } n   unsigned long long int i, j, k; n   for (i = l; i <= r - 2; i++) { n     for (j = i + 1; j <= r - 1; j++) { n       if (gcd(i, j) == 1) { n         for (k = j + 1; k <= r; k++) { n           if (gcd(j, k) == 1 && gcd(i, k) != 1) { n             flag = 1; n             cout << i <<     << j <<     << k; n             break; n           } n         } n       } n       if (flag == 1) break; n     } n     if (flag == 1) break; n   } n   if (flag == 0) cout <<  -1 ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b, c, n, m, k = 0, T, maxx = -0x3f3f3f3f; n int main() { n   scanf( %lld , &T); n   while (T--) { n     scanf( %lld%lld , &n, &k); n     long long t = 0, tmp = 0; n     if (n == 2 && k == 3) { n       cout <<  No  << endl; n       continue; n     } n     while (t < k) { n       t = t * 4 + 1; n       if (t > k) break; n       tmp++; n     } n     if (tmp > n || (tmp == n && k != t)) n       cout <<  NO n ; n     else { n       if (t > k) t = (t - 1) / 4; n       cout <<  YES  ; n       long long s = ((1ll) << tmp); n       tmp = n - tmp; n       t = k - t; n       if (t >= 2 * s - 1) n         cout << tmp - 1 << endl; n       else n         cout << tmp << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n map<vector<long long>, long long> mp; n int main() { n   long long n; n   cin >> n; n   long long a[] = {2, 3, 5, 7}; n   vector<long long> t; n   for (long long mask = 1; mask < (1 << 4); mask++) { n     t.clear(); n     for (long long j = 0; j < 4; j++) { n       if (mask & (1 << j)) t.push_back(a[j]); n     } n     sort(t.begin(), t.end()); n     long long y = 1; n     for (auto v : t) y *= v; n     mp[t] += n / y; n   } n   for (auto x : mp) { n     if (x.first.size() % 2) { n       n -= x.second; n       continue; n     } n     n += x.second; n   } n   cout << n << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxN = 2005; n const int dx[10] = {0, 0, 0, 1, -1, 1, 1, -1, -1}; n const int dy[10] = {0, 1, -1, 0, 0, -1, 1, -1, 1}; n int n, area, sx, sy; n bool p[maxN][maxN], vis[maxN][maxN]; n void init() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= n; ++j) scanf( %d , &p[i][j]); n } n void fixNoise() { n   int cnt; n   for (int tme = 1; tme <= 5; ++tme) n     for (int i = 1; i <= n; ++i) n       for (int j = 1; j <= n; ++j) { n         cnt = 0; n         for (int k = 0; k <= 8; ++k) cnt += p[i + dx[k]][j + dy[k]]; n         if (cnt < 5) n           p[i][j] = 0; n         else n           p[i][j] = 1; n       } n } n void dfs(int x, int y) { n   int xx, yy; n   vis[x][y] = 1; n   ++area; n   sx += x; n   sy += y; n   for (int i = 1; i <= 4; ++i) { n     xx = x + dx[i]; n     yy = y + dy[i]; n     if (xx < 1 || yy < 1 || xx > n || yy > n || !p[xx][yy] || vis[xx][yy]) n       continue; n     dfs(xx, yy); n   } n } n void work() { n   double ox, oy, r; n   int circle = 0, rectangle = 0; n   fixNoise(); n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= n; ++j) n       if (p[i][j] && !vis[i][j]) { n         area = 0; n         sx = 0; n         sy = 0; n         dfs(i, j); n         if (area >= 158) { n           ox = double(sx) / area; n           oy = double(sy) / area; n           r = ((i - ox) * (i - ox)) + ((j - oy) * (j - oy)); n           if (area / r > 2.9) n             ++circle; n           else n             ++rectangle; n         } n       } n   printf( %d %d n , circle, rectangle); n } n int main() { n   init(); n   work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n, k; n     cin >> n >> k; n     int sum = n - n % k; n     sum += min(n % k, k / 2); n     cout << sum << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n, m; n   cin >> n >> m; n   int floor[n][2 * m]; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < 2 * m; j++) { n       cin >> floor[i][j]; n     } n   } n   int count = 0; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < 2 * m - 1; j += 2) { n       if (floor[i][j] == 1 || floor[i][j + 1] == 1) { n         count++; n       } n     } n   } n   cout << count <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n; n   cin >> n; n   map<int, int> mx, my; n   map<pair<int, int>, int> mp; n   for (int i = 0; i < n; i++) { n     int first, second; n     cin >> first >> second; n     mx[first]++; n     my[second]++; n     mp[{first, second}]++; n   }; n   long long ans = 0; n   for (auto it : mx) { n     ans += (long long)it.second * (it.second - 1) / 2; n   } n   for (auto it : my) { n     ans += (long long)it.second * (it.second - 1) / 2; n   } n   for (auto it : mp) { n     ans -= (long long)it.second * (it.second - 1) / 2; n   } n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int up[200005]; n int down[200005]; n vector<int> answer; n bool done = true; n ; n int main() { n   int n; n   cin >> n; n   for (int i = 1; i < n; i++) { n     cin >> up[i]; n   } n   for (int i = 1; i < n; i++) { n     cin >> down[i]; n   } n   answer.push_back(0); n   int previous = 0; n   for (int i = 1; i < n; i++) { n     if (!done) { n       break; n     } n     done = false; n     for (int j = 0; j < 4; j++) { n       int x = previous & j; n       int z = previous | j; n       if ((x == down[i]) && (z == up[i])) { n         previous = j; n         done = true; n         answer.push_back(previous); n         break; n       } n     } n   } n   if (done) { n     cout <<  YES  << endl; n     for (int i = 0; i < answer.size(); i++) { n       cout << answer[i] <<    ; n     } n   } else { n     answer.clear(); n     previous = 1; n     answer.push_back(1); n     done = true; n     for (int i = 1; i < n; i++) { n       if (!done) { n         break; n       } n       done = false; n       for (int j = 0; j < 4; j++) { n         int x = previous & j; n         int z = previous | j; n         if ((x == down[i]) && (z == up[i])) { n           previous = j; n           done = true; n           answer.push_back(previous); n           break; n         } n       } n     } n     if (done) { n       cout <<  YES  << endl; n       for (int i = 0; i < answer.size(); i++) { n         cout << answer[i] <<    ; n       } n     } else { n       answer.clear(); n       previous = 2; n       answer.push_back(2); n       done = true; n       for (int i = 1; i < n; i++) { n         if (!done) { n           break; n         } n         done = false; n         for (int j = 0; j < 4; j++) { n           int x = previous & j; n           int z = previous | j; n           if ((x == down[i]) && (z == up[i])) { n             previous = j; n             done = true; n             answer.push_back(previous); n             break; n           } n         } n       } n       if (done) { n         cout <<  YES  << endl; n         for (int i = 0; i < answer.size(); i++) { n           cout << answer[i] <<    ; n         } n       } else { n         answer.clear(); n         previous = 3; n         answer.push_back(3); n         done = true; n         for (int i = 1; i < n; i++) { n           if (!done) { n             break; n           } n           done = false; n           for (int j = 0; j < 4; j++) { n             int x = previous & j; n             int z = previous | j; n             if ((x == down[i]) && (z == up[i])) { n               previous = j; n               done = true; n               answer.push_back(previous); n               break; n             } n           } n         } n         if (done) { n           cout <<  YES  << endl; n           for (int i = 0; i < answer.size(); i++) { n             cout << answer[i] <<    ; n           } n         } else { n           cout <<  NO  << endl; n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int modexpo(long long int x, long long int y) { n   if (y == 0) return 1; n   if (y % 2) { n     long long int viky = modexpo(x, y / 2); n     return (((x * viky) % 1000000000) * viky) % 1000000000; n   } else { n     long long int viky = modexpo(x, y / 2); n     return (viky * viky) % 1000000000; n   } n } n long long int a[1111]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int t, i, j, l, m, n, r, q, k, c, x; n   cin >> n; n   for (i = 1; i < n; i++) { n     cin >> l >> r; n     a[r]++; n     a[l]++; n   } n   c = 0; n   for (i = 1; i <= n; i++) { n     if (a[i] == 1) c++; n   } n   cout << c; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int ax, ay, bx, by, cx, cy; n double k1, k2, k3; n int main() { n   long long int dis_ab, dis_ac, dis_bc, max_dis = -1; n   cin >> ax >> ay >> bx >> by >> cx >> cy; n   dis_ab = (ax - bx) * (ax - bx) + (ay - by) * (ay - by); n   k1 = (double)(ax - bx) / (ay - by); n   dis_ac = (ax - cx) * (ax - cx) + (ay - cy) * (ay - cy); n   k2 = (double)(ax - cx) / (ay - cy); n   dis_bc = (bx - cx) * (bx - cx) + (by - cy) * (by - cy); n   k3 = (double)(bx - cx) / (by - cy); n   if (k1 == k2 && k2 == k3) n     cout <<  No ; n   else { n     if (dis_ab == dis_bc) n       cout <<  Yes ; n     else n       cout <<  No ; n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int INF = 1000000001; n const double EPS = 10e-9; n const int MAXN = 100005; n pair<int, int> t[MAXN << 1]; n int MOD; n void rob() { n   int n; n   scanf( %d , &n); n   int tmp; n   for (typeof(0) i = (0); i < (n); ++i) { n     scanf( %d , &tmp); n     t[i] = make_pair(tmp, i); n   } n   for (typeof(0) i = (0); i < (n); ++i) { n     scanf( %d , &tmp); n     t[n + i] = make_pair(tmp, i); n   } n   scanf( %d , &MOD); n   n <<= 1; n   sort(t, t + n); n   long long res = 1; n   int i = 0; n   int pow; n   int fac; n   while (i < n) { n     fac = 1; n     pow = 0; n     for (++i; i < n; ++i) { n       if (t[i].first != t[i - 1].first) break; n       if (t[i].second == t[i - 1].second) ++pow; n       ++fac; n     } n     for (typeof(1) j = (1); j <= (fac); ++j) { n       if (pow && !(j & 1)) { n         res = (res * (j >> 1)) % MOD; n         --pow; n       } else { n         res = (res * j) % MOD; n       } n     } n   } n   printf( %I64d n , res); n } n int main() { n   int test = 1; n   while (test--) rob(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 1e5 + 10; n int arr[MAX]; n int n; n int query(int x, int y, int z) { n   cout <<  ?   << x <<     << y <<     << z << endl; n   int a; n   cin >> a; n   return a; n } n array<int, 3> col[2]; n int ans[MAX]; n vector<int> v; n int main() { n   int t; n   cin >> t; n   while (t--) { n     v.clear(); n     col[0] = col[1] = {-1, -1, -1}; n     cin >> n; n     for (int i = 1; i <= n; i += 3) { n       arr[i] = query(i, i + 1, i + 2); n       col[arr[i]] = {i, i + 1, i + 2}; n     } n     int x = -1, y = -1; n     for (int i = 0; i < 3; ++i) { n       if (query(col[0][0], col[0][1], col[1][i])) { n         y = col[1][i]; n         break; n       } n     } n     if (y == -1) { n       x = col[0][0]; n       if (query(col[1][0], col[1][1], x)) n         y = col[1][0]; n       else if (query(col[1][0], col[1][2], x)) n         y = col[1][0]; n       else n         y = col[1][1]; n     } else n       x = col[0][2]; n     ans[x] = 0, ans[y] = 1; n     for (int i = 1; i <= n; i += 3) { n       if (i == col[arr[i]][0]) { n         for (int j = i; j <= i + 2; ++j) { n           if (j == x || j == y) continue; n           ans[j] = query(x, y, j); n         } n         continue; n       } n       int c = x; n       if (!arr[i]) c = y; n       int a = query(i, i + 1, c); n       int b = query(i, i + 2, c); n       int idx = -1; n       if (a != arr[i] && b != arr[i]) n         idx = i; n       else if (a != arr[i]) n         idx = i + 1; n       else if (b != arr[i]) n         idx = i + 2; n       for (int j = i; j <= i + 2; ++j) { n         if (idx == j) n           ans[j] = !arr[i]; n         else n           ans[j] = arr[i]; n       } n     } n     for (int i = 1; i <= n; ++i) { n       if (!ans[i]) v.push_back(i); n     } n     cout <<  !   << v.size() <<    ; n     for (auto &i : v) cout << i <<    ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1010; n struct node { n   double x; n   double y; n   double t; n   double p; n   bool operator<(const node& W) const { return t < W.t; } n } q[N]; n double dp[N]; n bool check(node a, node b) { n   double dx = a.x - b.x; n   double dy = a.y - b.y; n   return sqrt(dx * dx + dy * dy) <= b.t - a.t; n } n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> q[i].x >> q[i].y >> q[i].t >> q[i].p; n   } n   sort(q + 1, q + n + 1); n   dp[1] = q[1].p; n   for (int i = 2; i <= n; i++) { n     dp[i] = q[i].p; n     for (int j = 1; j <= i - 1; j++) n       if (check(q[j], q[i])) dp[i] = max(dp[i], dp[j] + q[i].p); n   } n   double res = 0; n   for (int i = 1; i <= n; i++) res = max(res, dp[i]); n   printf( %.6lf n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k; n int x[505], y[505]; n int x_koord[1005], y_koord[1005], kk, kkx, kky; n int z[1055][1055]; n bool popuni(int sz) { n   kk = 0; n   for (int i = 1; i <= k; i++) { n     int xl = x[i] - sz; n     if (xl < 1) { n       xl = 1; n     } n     int xr = x[i] + sz + 1; n     if (xr > n + 1) { n       xr = n + 1; n     } n     int yl = y[i] - sz; n     if (yl < 1) { n       yl = 1; n     } n     int yr = y[i] + sz + 1; n     if (yr > m + 1) { n       yr = m + 1; n     } n     kk++; n     x_koord[kk] = xl; n     y_koord[kk] = yl; n     kk++; n     x_koord[kk] = xr; n     y_koord[kk] = yr; n   } n   kk++; n   x_koord[kk] = 1; n   y_koord[kk] = 1; n   kk++; n   x_koord[kk] = n + 1; n   y_koord[kk] = m + 1; n   sort(x_koord + 1, x_koord + kk + 1); n   kkx = unique(x_koord + 1, x_koord + kk + 1) - x_koord - 1; n   sort(y_koord + 1, y_koord + kk + 1); n   kky = unique(y_koord + 1, y_koord + kk + 1) - y_koord - 1; n   memset(z, 0, sizeof(z)); n   for (int i = 1; i <= k; i++) { n     int xl = x[i] - sz; n     if (xl < 1) { n       xl = 1; n     } n     int xr = x[i] + sz + 1; n     if (xr > n + 1) { n       xr = n + 1; n     } n     int yl = y[i] - sz; n     if (yl < 1) { n       yl = 1; n     } n     int yr = y[i] + sz + 1; n     if (yr > m + 1) { n       yr = m + 1; n     } n     xl = lower_bound(x_koord + 1, x_koord + kkx + 1, xl) - x_koord; n     xr = lower_bound(x_koord + 1, x_koord + kkx + 1, xr) - x_koord; n     yl = lower_bound(y_koord + 1, y_koord + kky + 1, yl) - y_koord; n     yr = lower_bound(y_koord + 1, y_koord + kky + 1, yr) - y_koord; n     z[xl][yl]++; n     z[xl][yr]--; n     z[xr][yl]--; n     z[xr][yr]++; n   } n   int loy = 2e9, hiy = -2e9, lox = 2e9, hix = -2e9; n   int any = 0; n   for (int i = 1; i < kkx; i++) { n     for (int j = 1; j < kky; j++) { n       z[i][j] += z[i - 1][j] + z[i][j - 1] - z[i - 1][j - 1]; n       if (z[i][j] == 0) { n         any = 1; n         lox = min(lox, x_koord[i]); n         hix = max(hix, x_koord[i + 1]); n         loy = min(loy, y_koord[j]); n         hiy = max(hiy, y_koord[j + 1]); n       } n     } n   } n   if (!any) { n     return true; n   } n   cerr << sz <<     << lox <<     << hix <<     << loy <<     << hiy <<   n ; n   return max(hiy - loy, hix - lox) / 2 <= sz; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   cerr.tie(nullptr); n   cin >> n >> m >> k; n   for (int i = 1; i <= k; i++) { n     cin >> x[i] >> y[i]; n   } n   int l = 0, r = 1e9, o = 1e9; n   while (l <= r) { n     int m = (l + r) / 2; n     if (popuni(m)) { n       o = m; n       r = m - 1; n     } else { n       l = m + 1; n     } n   } n   cout << o; n } n


#include <bits/stdc++.h> n using namespace std; n char s[1000010]; n int n, p[1000010]; n int main() { n   scanf( %s , s), n = strlen(s); n   for (int i = 0; i < n; i++) n     if (s[i] ==  1 ) p[n - 1 - i] = 1; n   for (int i = 0, j; i < n + 2;) n     if (!p[i]) n       i++; n     else { n       j = i; n       while (p[j]) j++; n       if (j - i >= 2) { n         p[i] = -1; n         for (int k = i + 1; k < j; k++) p[k] = 0; n         p[j] = 1; n       } n       i = j; n     } n   int S = 0; n   for (int i = 0; i < n + 2; i++) n     if (p[i] != 0) S++; n   printf( %d n , S); n   for (int i = 0; i < n + 2; i++) n     if (p[i] != 0) n       if (p[i] > 0) n         printf( +2^%d n , i); n       else n         printf( -2^%d n , i); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   int i, j, k; n   int n; n   cin >> n; n   int x = n / 4; n   string s =  abcd ; n   string ans =   ; n   if (n % 4 == 0) n     for (i = 0; i < x; i++) ans += s; n   else { n     if (n % 4 == 1) { n       for (i = 0; i < x; i++) ans += s; n       ans +=  a ; n     } n     if (n % 4 == 2) { n       for (i = 0; i < x; i++) ans += s; n       ans +=  ab ; n     } n     if (n % 4 == 3) { n       for (i = 0; i < x; i++) ans += s; n       ans +=  abc ; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void debug_out() { cerr << endl; } n template <typename Head, typename... Tail> n void debug_out(Head H, Tail... T) { n   cerr <<     << H; n   debug_out(T...); n } n const int INF = 1e9; n const long long MOD = 1e9 + 7; n const int N = 1e5 + 5, MO = 350, SQ = 650; n int n, q, A[N], QL[N], QR[N], P[N], T[N], C[N], K[N], Q[N]; n vector<int> B, X, Y; n bool CMP(int i, int j) { n   if (QL[i] / MO != QL[j] / MO) return QL[i] < QL[j]; n   return (QL[i] / MO) % 2 ? QR[i] > QR[j] : QR[i] < QR[j]; n } n void Update(int x, int y) { T[C[x]]--, C[x] += y, T[C[x]]++; } n void Insert(int x, int y) { n   if (x >= SQ && !K[x]) Y.push_back(x); n   K[x] += y; n } n int Huf() { n   X.clear(), Y.clear(); n   for (int i : B) n     if (C[i] >= SQ) X.push_back(C[i]), K[C[i]]++; n   sort(X.begin(), X.end()); n   int huf = 0, c = 0, x = 0, y = 0; n   for (int i = 1; i < SQ; i++) n     if (K[i] + T[i]) { n       K[i] += T[i]; n       if (c) huf += i + c, K[i]--, Insert(i + c, 1), c = 0; n       if (K[i] & 1) c = i, K[i]--; n       if (K[i]) huf += i * K[i], Insert(i + i, K[i] >> 1), K[i] = 0; n     } n   while (x < (int)(X.size()) || y < (int)(Y.size())) { n     while (x + 1 < (int)(X.size()) && X[x + 1] == X[x]) x++; n     while (y + 1 < (int)(Y.size()) && Y[y + 1] == Y[y]) y++; n     int i = 0; n     if (x == (int)(X.size())) n       i = Y[y++]; n     else if (y == (int)(Y.size())) n       i = X[x++]; n     else if (X[x] < Y[y]) n       i = X[x++]; n     else n       i = Y[y++]; n     if (c) huf += i + c, K[i]--, Insert(i + c, 1), c = 0; n     if (K[i] & 1) c = i, K[i]--; n     if (K[i]) huf += i * K[i], Insert(i + i, K[i] >> 1), K[i] = 0; n   } n   return huf; n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   mt19937 Rnd(time(0)); n   cin >> n; n   for (int i = 0; i < n; i++) cin >> A[i], C[A[i]]++; n   for (int i = 0; i < N; i++) n     if (C[i] >= SQ) B.push_back(i); n   for (int i = 0; i < n; i++) C[A[i]]--; n   cin >> q; n   for (int i = 0; i < q; i++) cin >> QL[i] >> QR[i], QL[i]--, P[i] = i; n   sort(P, P + q, CMP); n   int L = 0, R = 0; n   for (int i = 0; i < q; i++) { n     int l = QL[P[i]], r = QR[P[i]]; n     while (l < L) Update(A[--L], +1); n     while (R < r) Update(A[R++], +1); n     while (L < l) Update(A[L++], -1); n     while (r < R) Update(A[--R], -1); n     Q[P[i]] = Huf(); n   } n   for (int i = 0; i < q; i++) cout << Q[i] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   long long t, n, i, j, flag = 0, temp, nodes, a, b, m, k, sz, sm, res; n   long long mn, mx; n   long long l, r; n   long long x, y, z; n   long long c, d; n   t = 1; n   vector<pair<int, int>> v; n   string s; n   char ch; n   while (t--) { n     flag = 0; n     v.clear(); n     cin >> n; n     int A = INT_MAX, B = INT_MIN; n     for (i = 0; i < n; i++) { n       cin >> a >> b; n       v.push_back({a, b}); n       if (a < A) A = a; n       if (B < b) B = b; n     } n     for (i = 0; i < v.size(); i++) { n       if (v[i].first == A && v[i].second == B) { n         flag = 1; n         break; n       } n     } n     if (flag == 1) { n       cout << i + 1 << endl; n       continue; n     } else { n       cout <<  -1 ; n       continue; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10; n char a[N], b[N]; n int s[N][26]; n void init() { n   int n = strlen(a + 1); n   memset(s, 0, sizeof(s)); n   for (int i = n; i >= 1; i--) { n     for (int j = 0; j < 26; j++) { n       s[i - 1][j] = s[i][j]; n     } n     s[i - 1][a[i] -  a ] = i; n   } n } n int main() { n   int T; n   cin >> T; n   while (T--) { n     scanf( %s %s , a + 1, b + 1); n     init(); n     int flg = 0; n     int p = 0; n     int ans = 1; n     for (int i = 1; i <= strlen(b + 1); i++) { n       int t = b[i] -  a ; n       int tt = s[p][t]; n       if (tt == 0 && p == 0) { n         flg = 1; n         break; n       } n       if (tt == 0) { n         i--; n         ans++; n         p = 0; n       } else { n         p = tt; n       } n     } n     if (flg == 1) { n       printf( -1 n ); n       continue; n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int N = 500009; n const long long int mod = 1000000007; n long long int n, k; n string s; n string see; n vector<long long int> v; n void pre() { n   see = s; n   for (auto i : s) see += i; n   for (auto i : s) see += i; n } n int32_t main() { n   cin >> n >> k >> s; n   pre(); n   for (long long int i = 0; i < 3 * n;) { n     long long int j = i; n     long long int pahla = i; n     long long int doosra = i - 1; n     long long int idharhi = 0; n     while (doosra < (3 * n - 1)) { n       if (see[i] == see[doosra + 1]) n         doosra++; n       else n         break; n     } n     if (doosra == pahla) { n       i++; n       continue; n     } n     for (long long int k = i; k <= doosra; k++) { n       v.push_back(k); n     } n     i = doosra + 1; n   } n   if (v.size() == 0) { n     if (k % 2 == 0) { n       cout << s <<   n ; n       return 0; n     } else { n       for (auto i : s) { n         if (i ==  W ) n           cout <<  B ; n         else n           cout <<  W ; n       } n       cout <<   n ; n       return 0; n     } n   } n   string ans =   ; n   for (long long int i = n; i < 2 * n; i++) { n     auto it = lower_bound(v.begin(), v.end(), i); n     long long int is = it - v.begin(); n     if (v[is] == i) { n       ans += see[i]; n       continue; n     } n     is--; n     long long int dis1 = i - v[is]; n     is++; n     long long int dis2 = v[is] - i; n     assert(dis1 > 0 and dis2 > 0); n     if (dis1 > k && dis2 > k) { n       if (k % 2 == 0) { n         ans += see[i]; n       } else { n         if (see[i] ==  W ) n           ans +=  B ; n         else n           ans +=  W ; n       } n       continue; n     } else if (dis1 <= k && dis1 < dis2) { n       ans += see[v[is - 1]]; n     } else if (dis2 <= k && dis2 < dis1) { n       ans += see[v[is]]; n     } else { n       ans += see[v[is]]; n     } n   } n   assert((long long int)ans.length() == n); n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int nod(int a, int b) { n   int c; n   if (a > b) swap(a, b); n   for (;;) { n     c = b % a; n     b = a; n     a = c; n     if (a == 0) return b; n   } n } n int main() { n   int x, y, a, b; n   cin >> x >> y >> a >> b; n   int d = x * y / nod(x, y); n   int c = b / d - (a - 1) / d; n   if (c < 0) c = 0; n   cout << c; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n = 0, a, tc; n int p[100005]; n vector<int> cho[6][100005]; n int sum[6]; n int ret = 0; n void doit(int x, int cur) { n   if (x == n - 1) { n     ret += cho[x + 5 - n][cur].size(); n     return; n   } n   for (int i = 0; i < cho[x + 5 - n][cur].size(); i++) { n     int ti = cho[x + 5 - n][cur][i]; n     for (int j = 0; j < n - x - 1; j++) { n       sum[n - 1 - j] = sum[n - 1 - j] * 10 + ti % 10; n       ti /= 10; n     } n     doit(x + 1, sum[x + 1]); n     for (int j = 0; j < n - x - 1; j++) { n       sum[n - 1 - j] /= 10; n     } n   } n } n int main() { n   scanf( %d , &tc); n   for (int i = 0; i <= 100000; i++) p[i] = 1; n   p[0] = p[1] = 0; n   for (int i = 2; i <= 100000; i++) n     if (p[i] == 1) { n       int ti = i; n       for (int j = 0; j < 5; j++) { n         cho[5 - j][ti].push_back(i); n         ti /= 10; n       } n       for (int j = i + i; j <= 100000; j += i) p[j] = 0; n     } n   while (tc--) { n     scanf( %d , &a); n     int ti = a; n     ret = 0; n     n = 0; n     while (ti > 0) { n       sum[n] = ti % 10; n       ti /= 10; n       n++; n     } n     for (int i = 0; i < n / 2; i++) swap(sum[i], sum[n - 1 - i]); n     doit(1, sum[1]); n     printf( %d n , ret); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5e5 + 10; n int n, q, k; n vector<pair<int, int> > tree[N << 2]; n int ask[N], ans[N]; n struct que { n   int x, y, times, l; n }; n queue<que> Q; n int fa[N], h[N], siz[N]; n int find(int o) { n   if (o != fa[o]) { n     return find(fa[o]); n   } n   return o; n } n struct gu { n   int first, second, val; n }; n gu merge(int x, int y) { n   x = find(x); n   y = find(y); n   gu re; n   re.val = -1; n   if (x == y) return re; n   if (h[x] > h[y]) swap(x, y); n   fa[x] = y; n   siz[y] += siz[x]; n   re.val = h[x] == h[y]; n   h[y] += h[x] == h[y]; n   re.first = x; n   re.second = y; n   return re; n } n void del(int x, int y, int val) { n   h[y] -= val; n   siz[y] -= siz[x]; n   fa[x] = x; n } n void add(int o, int l, int r, int L, int R, pair<int, int> x) { n   if (l >= L && r <= R) { n     tree[o].push_back(x); n     return; n   } n   int mid = (l + r) >> 1; n   if (mid >= L) add(o << 1, l, mid, L, R, x); n   if (mid < R) add(o << 1 | 1, mid + 1, r, L, R, x); n } n int tp; n gu s[1000100]; n void qu(int o, int l, int r) { n   int now = tp, sf = 0; n   for (int i = 0; i < tree[o].size(); ++i) { n     pair<int, int> now = tree[o][i]; n     s[++tp] = merge(now.first, now.second); n   } n   if (l == r) { n     ans[l] = siz[find(ask[l])]; n   } else { n     int mid = (l + r) >> 1; n     qu(o << 1, l, mid); n     qu(o << 1 | 1, mid + 1, r); n   } n   while (tp != now) { n     if (s[tp].val != -1) del(s[tp].first, s[tp].second, s[tp].val); n     --tp; n   } n } n int main() { n   scanf( %d%d%d , &n, &q, &k); n   for (int i = 1; i <= n; ++i) fa[i] = i, siz[i] = 1, h[i] = 1; n   int days = 1; n   for (int i = 1; i <= q; ++i) { n     int op; n     scanf( %d , &op); n     if (op == 1) { n       int x, y; n       scanf( %d%d , &x, &y); n       Q.push((que){x, y, days, i}); n     } n     if (op == 2) { n       int o; n       scanf( %d , &o); n       ask[i] = o; n     } n     if (op == 3) { n       ++days; n       while (!Q.empty() && Q.front().times <= days - k) { n         add(1, 1, q, Q.front().l, i - 1, make_pair(Q.front().x, Q.front().y)); n         Q.pop(); n       } n     } n   } n   while (!Q.empty()) { n     add(1, 1, q, Q.front().l, q, make_pair(Q.front().x, Q.front().y)); n     Q.pop(); n   } n   qu(1, 1, q); n   for (int i = 1; i <= q; ++i) { n     if (ask[i]) printf( %d n , ans[i]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int s_size = 1e5 + 5; n const int mod = 1e9 + 7; n int f[(s_size + 1) >> 1] = {1}, t[(s_size + 1) >> 1], g[(s_size + 1) >> 1]; n int fac[s_size] = {1}, inv[s_size], ans[s_size]; n int num(char c); n void fac_inv(void); n int qpow(int a, int b); n int main(void) { n   int q, x, y, cnt[55] = {0}, plan[55][55]; n   string s; n   cin >> s >> q; n   s =  0  + s; n   int length = s.size() - 1, upper = (length >> 1); n   for (int i = 1; i <= length; i++) cnt[num(s[i])]++; n   fac_inv(); n   int coe = (static_cast<long long>(fac[upper]) * fac[upper]) % mod; n   for (int i = 1; i <= 52; i++) n     if (cnt[i] > 0) { n       coe = (static_cast<long long>(coe) * inv[cnt[i]]) % mod; n       for (int j = upper; j >= cnt[i]; j--) f[j] = (f[j] + f[j - cnt[i]]) % mod; n     } n   for (int i = 1; i <= 52; i++) n     if (cnt[i] > 0) { n       plan[i][i] = f[upper]; n       for (int j = 0; j <= upper; j++) n         if (j >= cnt[i]) n           t[j] = (static_cast<long long>(f[j]) - t[j - cnt[i]] + mod) % mod; n         else n           t[j] = f[j]; n       for (int j = i + 1; j <= 52; j++) n         if (cnt[j] > 0) { n           for (int k = 0; k <= upper; k++) { n             if (k >= cnt[j]) n               g[k] = (static_cast<long long>(t[k]) - g[k - cnt[j]] + mod) % mod; n             else n               g[k] = t[k]; n             plan[i][j] = (static_cast<long long>(2) * g[upper]) % mod; n             plan[j][i] = plan[i][j]; n           } n         } n     } n   for (int i = 1; i <= q; i++) { n     cin >> x >> y; n     ans[i] = (static_cast<long long>(coe) * plan[num(s[x])][num(s[y])]) % mod; n   } n   for (int i = 1; i <= q; i++) cout << ans[i] << endl; n   return 0; n } n inline int num(char c) { return islower(c) ? c -  a  + 1 : c -  A  + 27; } n void fac_inv(void) { n   for (int i = 1; i <= s_size - 5; i++) n     fac[i] = (static_cast<long long>(fac[i - 1]) * i) % mod; n   inv[s_size - 5] = qpow(fac[s_size - 5], mod - 2); n   for (int i = s_size - 6; i >= 0; i--) n     inv[i] = (static_cast<long long>(inv[i + 1]) * (i + 1)) % mod; n } n int qpow(int a, int b) { n   int ret = 1; n   while (b > 0) { n     if ((b & 1) == 1) ret = (static_cast<long long>(ret) * a) % mod; n     a = (static_cast<long long>(a) * a) % mod; n     b >>= 1; n   } n   return ret; n } n


#include <bits/stdc++.h> n using namespace std; n long long int INF = (long long int)1e16; n int n, m, r; n vector<int> s, b; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   s.clear(); n   b.clear(); n   cin >> n >> m >> r; n   int x, y; n   int bax = INT_MAX; n   int bay = INT_MIN; n   for (int i = 0; i < n; i++) { n     cin >> x; n     bax = min(bax, x); n   } n   for (int i = 0; i < m; i++) { n     cin >> y; n     bay = max(bay, y); n   } n   int bht = r / bax; n   int cost = bht * bay + r % bax; n   cout << max(cost, r) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int cont[1003], sum[1003]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int ans = 0; n   string s1, s2; n   cin >> s1 >> s2; n   int n = s1.size(); n   int m = s2.size(); n   for (int i = 0; i < n; i++) cont[s1[i] -  a ]++; n   for (int i = 0; i < m; i++) sum[s2[i] -  a ]++; n   for (int i = 0; i < 26; i++) { n     if (sum[i] > 0 && cont[i] == 0) { n       cout << -1 <<   n ; n       return 0; n     } n     if (sum[i] > cont[i]) n       ans += cont[i]; n     else n       ans += sum[i]; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long getint() { n   long long num = 0, flag = 1; n   char c; n   while ((c = getchar()) <  0  || c >  9 ) n     if (c ==  - ) flag = -1; n   while (c >=  0  && c <=  9 ) num = num * 10 + c - 48, c = getchar(); n   return num * flag; n } n int n, m, q, R; n int fir[600005], nxt[600005], to[600005], cnt; n int sz[600005], tp[600005], fa[600005], son[600005], dpt[600005], pos[600005], n     cur; n map<pair<int, int>, int> M; n int p[600005], V[600005]; n int P_stk[600005], P_Tp; n inline int rotate(int x) { n   x = (x + R) % n; n   return x ? x : x + n; n } n inline bool cmp(int x, int y) { return pos[x] < pos[y]; } n inline void newnode(int u, int v) { n   to[++cnt] = v, nxt[cnt] = fir[u], fir[u] = cnt; n } n inline void dfs1(int u) { n   sz[u] = 1; n   pos[u] = ++cur; n   for (int i = fir[u]; i; i = nxt[i]) n     if (to[i] != fa[u]) { n       fa[to[i]] = u, dpt[to[i]] = dpt[u] + 1; n       dfs1(to[i]), sz[u] += sz[to[i]]; n       if (sz[to[i]] > sz[son[u]]) son[u] = to[i]; n     } n } n inline void dfs2(int u, int ac) { n   tp[u] = ac; n   if (son[u]) dfs2(son[u], ac); n   for (int i = fir[u]; i; i = nxt[i]) n     if (to[i] != fa[u] && to[i] != son[u]) dfs2(to[i], to[i]); n } n inline int LCA(int u, int v) { n   for (; tp[u] != tp[v] && u && v; u = fa[tp[u]]) n     if (dpt[tp[u]] < dpt[tp[v]]) swap(u, v); n   if (!u || !v) return 0; n   return dpt[u] < dpt[v] ? u : v; n } n struct node { n   vector<int> G[600005], Id[600005]; n   int dfn[600005], low[600005], tim, vis[600005], sccno[600005], scccnt; n   int stk[600005], Tp; n   inline void tarjan(int u) { n     dfn[u] = low[u] = ++tim; n     stk[++Tp] = u; n     for (int i = 0, v; i < G[u].size(); i++) n       if (!vis[Id[u][i]]) { n         vis[Id[u][i]] = 1; n         if (!dfn[v = G[u][i]]) n           tarjan(v), low[u] = min(low[u], low[v]); n         else if (!sccno[v]) n           low[u] = min(low[u], dfn[v]); n       } n     if (dfn[u] == low[u]) { n       scccnt++; n       while (1) { n         sccno[stk[Tp]] = scccnt; n         if (stk[Tp--] == u) break; n       } n     } n   } n   inline void init() { n     for (int i = 1; i <= m; i++) { n       int u = getint(), v = getint(); n       G[u].push_back(v), G[v].push_back(u); n       Id[u].push_back(i), Id[v].push_back(i); n     } n     for (int i = 1; i <= n; i++) n       if (!dfn[i]) tarjan(i); n     for (int u = 1; u <= n; u++) n       for (int i = 0; i < G[u].size(); i++) n         if (sccno[G[u][i]] != sccno[u]) { n           int x = min(sccno[u], sccno[G[u][i]]), n               y = max(sccno[u], sccno[G[u][i]]); n           if (!M[make_pair(x, y)]) n             newnode(x, y), newnode(y, x), M[make_pair(x, y)] = 1; n         } n   } n } G, H; n int main() { n   n = getint(), m = getint(), q = getint(); n   G.init(); n   for (int i = 1; i <= G.scccnt; i++) n     if (!sz[i]) dfs1(i), dfs2(i, i); n   for (int t = 1; t <= q; t++) { n     int N = getint(), M = getint(), K = 0, tmp = 0; n     P_Tp = 0; n     for (int i = 1; i <= N; i++) { n       int x = G.sccno[rotate(getint())]; n       p[++K] = x, V[x] = 1; n     } n     for (int i = 1; i <= M; i++) { n       int x = G.sccno[rotate(getint())], y = G.sccno[rotate(getint())]; n       if (x == y) continue; n       p[++K] = x, p[++K] = y, tmp++; n       H.G[x].push_back(y), H.G[y].push_back(x); n       H.Id[x].push_back(tmp), H.Id[y].push_back(tmp); n     } n     sort(p + 1, p + K + 1, cmp), K = unique(p + 1, p + K + 1) - p - 1; n     for (int i = K - 1; i; i--) { n       int x = LCA(p[i], p[i + 1]); n       if (x) p[++K] = x; n     } n     sort(p + 1, p + K + 1, cmp), K = unique(p + 1, p + K + 1) - p - 1; n     for (int i = 1; i <= K; i++) { n       while (P_Tp && pos[P_stk[P_Tp]] + sz[P_stk[P_Tp]] <= pos[p[i]]) P_Tp--; n       if (P_Tp) { n         int x = P_stk[P_Tp], y = p[i]; n         tmp++; n         H.G[x].push_back(y), H.G[y].push_back(x); n         H.Id[x].push_back(tmp), H.Id[y].push_back(tmp); n       } n       P_stk[++P_Tp] = p[i]; n     } n     for (int i = 1; i <= K; i++) n       if (!H.dfn[p[i]]) H.tarjan(p[i]); n     int pp = 0; n     bool flg = 1; n     for (int i = 1; i <= K; i++) n       if (V[p[i]]) { n         if (!pp) n           pp = H.sccno[p[i]]; n         else if (pp != H.sccno[p[i]]) { n           flg = 0; n           break; n         } n       } n     for (int i = 1; i <= K; i++) { n       H.G[p[i]].clear(), H.Id[p[i]].clear(); n       H.dfn[p[i]] = H.low[p[i]] = H.sccno[p[i]] = V[p[i]] = 0; n     } n     for (int i = 1; i <= tmp; i++) H.vis[i] = 0; n     H.scccnt = H.tim = H.Tp = 0; n     R = (R + t * flg) % n; n     puts(flg ?  YES  :  NO ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n; n long long m; n int soln[51]; n long long mr = 0; n int main() { n   cin >> n >> m; n   --m; n   for (int k = 1; k < n; ++k) { n     mr = mr * 2 + (m & 1); n     m >>= 1; n   } n   int i = 1, j = n; n   for (int k = 1; k <= n; ++k) { n     if (mr & 1) n       soln[j--] = k; n     else n       soln[i++] = k; n     mr >>= 1; n   } n   for (int k = 1; k <= n; ++k) cout << soln[k] <<    ; n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k, x; n long long m[200010]; n long long answer; n struct node { n   long long pre; n   long long next; n } p[200010]; n int main() { n   long long a; n   while (~scanf( %I64d %I64d %I64d , &n, &k, &x)) { n     answer = p[1].pre = p[n].next = 0; n     a = x; n     for (long long i = k - 1; i > 0; i--) a *= x; n     for (long long i = 1; i <= n; i++) { n       scanf( %d , &m[i]); n       p[i].pre = (m[i - 1] | p[i - 1].pre); n     } n     for (long long i = n; i >= 1; i--) { n       if (i < n) p[i].next = (p[i + 1].next | m[i + 1]); n       answer = max(answer, (p[i].pre | p[i].next | m[i] * a)); n     } n     printf( %I64d n , answer); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x, y, z; n   cin >> x >> y >> z; n   if (z == 0) { n     if (x > y) n       cout <<  + ; n     else if (x < y) n       cout <<  - ; n     else n       cout <<  0 ; n   } else { n     if (x > y + z) n       cout <<  + ; n     else if (y > x + z) n       cout <<  - ; n     else n       cout <<  ? ; n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   char name[100], winner[100]; n   int sh, uh, a, b, v, c, d, e; n   int n, i; n   int sum; n   int total = sum; n   scanf( %d , &n); n   scanf( %s %d %d %d %d %d %d %d , name, &sh, &uh, &a, &b, &c, &d, &e); n   sum = sh * 100 - uh * 50 + a + b + c + d + e; n   total = sum; n   strcpy(winner, name); n   for (i = 0; i < n - 1; i++) { n     scanf( %s %d %d %d %d %d %d %d , name, &sh, &uh, &a, &b, &c, &d, &e); n     sum = sh * 100 - uh * 50 + a + b + c + d + e; n     if (sum > total) { n       total = sum; n       strcpy(winner, name); n     } n   } n   printf( %s , winner); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i, j = 0; n   char d; n   cin >> n; n   string s; n   cin >> s; n   char a[n][n + 1]; n   for (i = 0; i < n; i++) { n     s.copy(a[i], n - i, i), s.copy(a[i] + (n - i), i), a[i][n] = 0; n     d = ( 9  - a[i][0] + 1) % 10; n     for (j = 0; j < n; j++) n       a[i][j] = (((a[i][j] + d) >  9 ) ? (a[i][j] - 10) : a[i][j]) + d; n   } n   for (i = 1, j = 0; i < n; i++) j = ((strcmp(a[i], a[j]) < 0) ? i : j); n   puts(a[j]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T1> n void deb(T1 e) { n   cout << e << endl; n } n template <class T1, class T2> n void deb(T1 e1, T2 e2) { n   cout << e1 <<     << e2 << endl; n } n template <class T1, class T2, class T3> n void deb(T1 e1, T2 e2, T3 e3) { n   cout << e1 <<     << e2 <<     << e3 << endl; n } n template <class T1, class T2, class T3, class T4> n void deb(T1 e1, T2 e2, T3 e3, T4 e4) { n   cout << e1 <<     << e2 <<     << e3 <<     << e4 << endl; n } n template <class T1, class T2, class T3, class T4, class T5> n void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) { n   cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 << endl; n } n template <class T1, class T2, class T3, class T4, class T5, class T6> n void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) { n   cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 <<     << e6 n        << endl; n } n template <class T> n T Abs(T x) { n   return x > 0 ? x : -x; n } n template <class T> n inline T sqr(T x) { n   return x * x; n } n long long Pow(long long B, long long P) { n   long long R = 1; n   while (P > 0) { n     if (P % 2 == 1) R = (R * B); n     P /= 2; n     B = (B * B); n   } n   return R; n } n int BigMod(long long B, long long P, long long M) { n   long long R = 1; n   while (P > 0) { n     if (P % 2 == 1) { n       R = (R * B) % M; n     } n     P /= 2; n     B = (B * B) % M; n   } n   return (int)R; n } n int n, l, k; n vector<int> prize; n vector<double> prb; n double dp[202][202][202]; n double rec(int pos, int need_2_win, int bags) { n   if (pos >= n) { n     if (need_2_win >= l && bags + k >= need_2_win) n       return 1.00; n     else n       return 0.0; n   } n   double &ret = dp[pos][need_2_win][bags]; n   if (ret > -.5) return ret; n   ret = 0.0; n   ret += (prb[pos] / 100.0) * n          rec(pos + 1, need_2_win + 1, min(200, bags + prize[pos])); n   ret += (max(100.0 - prb[pos], 0.0) / 100.0) * rec(pos + 1, need_2_win, bags); n   return ret; n } n int main(void) { n   double val; n   int a; n   scanf( %d %d %d , &n, &l, &k); n   for (int i = 0; i < n; i++) { n     scanf( %lf , &val); n     prb.push_back(val); n   } n   for (int i = 0; i < n; i++) { n     scanf( %d , &a); n     prize.push_back(a + 1); n   } n   memset(dp, -1, sizeof dp); n   double ans = rec(0, 0, 0); n   printf( %.12lf n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 2000000000; n static inline int Rint() { n   struct X { n     int dig[256]; n     X() { n       for (int i =  0 ; i <=  9 ; ++i) dig[i] = 1; n       dig[ - ] = 1; n     } n   }; n   static X fuck; n   int s = 1, v = 0, c; n   for (; !fuck.dig[c = getchar()];) n     ; n   if (c ==  - ) n     s = 0; n   else if (fuck.dig[c]) n     v = c ^ 48; n   for (; fuck.dig[c = getchar()]; v = v * 10 + (c ^ 48)) n     ; n   return s ? v : -v; n } n template <typename T> n static inline void cmax(T& a, const T& b) { n   if (b > a) a = b; n } n template <typename T> n static inline void cmin(T& a, const T& b) { n   if (b < a) a = b; n } n char buff[1024][1024]; n char temp[1024][1024]; n int n, m; n int sol_row(int u, int v, int a, int b) { n   for (int j = 0; j < m; ++j) { n     int match1 = 1, match2 = 1; n     int p[2]; n     if (j % 2 == 0) n       p[0] = u, p[1] = v; n     else n       p[0] = a, p[1] = b; n     for (int i = 0; i < n; ++i) n       if (buff[i][j] !=  0 ) { n         if (buff[i][j] != p[i % 2]) match1 = 0; n         if (buff[i][j] != p[1 - i % 2]) match2 = 0; n       } n     if (!match1 && !match2) return 0; n     for (int i = 0; i < n; ++i) { n       if (match1) n         temp[i][j] = p[i % 2]; n       else n         temp[i][j] = p[1 - i % 2]; n     } n   } n   return 1; n } n int sol_col(int u, int v, int a, int b) { n   for (int i = 0; i < n; ++i) { n     int match1 = 1, match2 = 1; n     int p[2]; n     if (i % 2 == 0) n       p[0] = u, p[1] = v; n     else n       p[0] = a, p[1] = b; n     for (int j = 0; j < m; ++j) n       if (buff[i][j] !=  0 ) { n         if (buff[i][j] != p[j % 2]) match1 = 0; n         if (buff[i][j] != p[1 - j % 2]) match2 = 0; n       } n     if (!match1 && !match2) return 0; n     for (int j = 0; j < m; ++j) { n       if (match1) n         temp[i][j] = p[j % 2]; n       else n         temp[i][j] = p[1 - j % 2]; n     } n   } n   return 1; n } n int main() { n   n = Rint(), m = Rint(); n   for (int i = (0); i < (n); ++i) scanf( %s , buff[i]); n   int pattern[4] = { 1 ,  2 ,  3 ,  4 }; n   int solved = 0; n   do { n     if (sol_row(pattern[0], pattern[1], pattern[2], pattern[3])) { n       solved = 1; n       break; n     } n     if (sol_col(pattern[0], pattern[1], pattern[2], pattern[3])) { n       solved = 1; n       break; n     } n   } while (next_permutation(pattern, pattern + 4)); n   if (solved) n     for (int i = 0; i < n; ++i) puts(temp[i]); n   else n     puts( 0 ); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n, p, q, i, j; n   int cnt = 0; n   char s[1000]; n   scanf( %d %d %d n , &n, &p, &q); n   gets(s); n   while (n % q != 0 && n >= p) { n     ++cnt; n     n -= p; n   } n   if (n % q != 0) n     puts( -1 ); n   else { n     printf( %d n , cnt + n / q); n     for (i = 0; i < cnt; i++) { n       for (j = 0; j < p; j++) putchar(s[i * p + j]); n       printf(  n ); n     } n     for (i = 0; i < n / q; i++) { n       for (j = 0; j < q; j++) putchar(s[cnt * p + i * q + j]); n       printf(  n ); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n char a[4][100][100]; n int c[6]; n int check(int le, int s, char st) { n   int ct = 0; n   for (int i = 0; i < s; i++) { n     for (int j = 0; j < s; j++) { n       if ((i - (s - 1) / 2 + j - (s - 1) / 2) % 2 == 0 && a[le][i][j] != st) { n         ct++; n       } else if ((i - (s - 1) / 2 + j - (s - 1) / 2) % 2 != 0 && n                  a[le][i][j] == st) { n         ct++; n       } n     } n   } n   return ct; n } n int main() { n   int si; n   scanf( %d , &si); n   getchar(); n   for (int k = 0; k < 4; k++) { n     for (int i = 0; i < si; i++) { n       char s[101]; n       scanf( %s , &s); n       for (int r = 0; r < si; r++) a[k][i][r] = s[r]; n       getchar(); n     } n     if (k != 3) getchar(); n   } n   c[0] = check(0, si,  1 ) + check(1, si,  1 ) + check(2, si,  0 ) + n          check(3, si,  0 ); n   c[1] = check(0, si,  1 ) + check(1, si,  0 ) + check(2, si,  1 ) + n          check(3, si,  0 ); n   c[2] = check(0, si,  1 ) + check(1, si,  0 ) + check(2, si,  0 ) + n          check(3, si,  1 ); n   c[3] = check(0, si,  0 ) + check(1, si,  1 ) + check(2, si,  1 ) + n          check(3, si,  0 ); n   c[4] = check(0, si,  0 ) + check(1, si,  1 ) + check(2, si,  0 ) + n          check(3, si,  1 ); n   c[5] = check(0, si,  0 ) + check(1, si,  0 ) + check(2, si,  1 ) + n          check(3, si,  1 ); n   int ans = 40000; n   for (int i = 0; i < 6; i++) { n     ans = min(c[i], ans); n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, M, cnt, maxi; n char c; n int star[105][105]; n int lefted[105][105]; n int righted[105][105]; n int up[105][105]; n int down[105][105]; n int chk[105][105]; n struct ryunha { n   int x, y, r; n } ans; n vector<ryunha> res; n int main(void) { n   cin >> N >> M; n   for (int i = 1; i <= N; i++) { n     for (int j = 1; j <= M; j++) { n       cin >> c; n       while (c !=  .  && c !=  * ) cin >> c; n       star[i][j] = (c ==  .  ? 0 : 1); n       if (c ==  * ) chk[i][j] = 1; n     } n   } n   for (int i = 1; i <= N; i++) { n     cnt = 0; n     for (int j = 1; j <= M; j++) { n       if (star[i][j]) n         cnt++; n       else n         cnt = 0; n       lefted[i][j] = cnt; n     } n   } n   for (int i = 1; i <= N; i++) { n     cnt = 0; n     for (int j = M; j >= 1; j--) { n       if (star[i][j]) n         cnt++; n       else n         cnt = 0; n       righted[i][j] = cnt; n     } n   } n   for (int j = 1; j <= M; j++) { n     cnt = 0; n     for (int i = 1; i <= N; i++) { n       if (star[i][j]) n         cnt++; n       else n         cnt = 0; n       up[i][j] = cnt; n     } n   } n   for (int j = 1; j <= M; j++) { n     cnt = 0; n     for (int i = N; i >= 1; i--) { n       if (star[i][j]) n         cnt++; n       else n         cnt = 0; n       down[i][j] = cnt; n     } n   } n   for (int i = 1; i <= N; i++) { n     for (int j = 1; j <= M; j++) { n       if (star[i][j]) { n         maxi = min({lefted[i][j], righted[i][j], up[i][j], down[i][j]}); n         int change = 0; n         if (maxi >= 2) { n           if (chk[i][j]) chk[i][j] = 0, change = 1; n           for (int k = 1; k <= maxi - 1; k++) { n             if (chk[i + k][j]) chk[i + k][j] = 0, change = 1; n             if (chk[i - k][j]) chk[i - k][j] = 0, change = 1; n             if (chk[i][j - k]) chk[i][j - k] = 0, change = 1; n             if (chk[i][j + k]) chk[i][j + k] = 0, change = 1; n           } n         } n         if (change) { n           ans.x = i; n           ans.y = j; n           ans.r = maxi - 1; n           res.push_back(ans); n         } n       } n     } n   } n   for (int i = 1; i <= N; i++) { n     for (int j = 1; j <= M; j++) { n       if (chk[i][j]) return !printf( -1 ); n     } n   } n   printf( %d n , res.size()); n   for (int i = 0; i < res.size(); i++) n     printf( %d %d %d n , res[i].x, res[i].y, res[i].r); n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1000000007; n const long long linf = 1LL << 62; n const unsigned long long ulinf = 1ULL << 63; n const double eps = 0.000001; n const double pi = 3.14159265358979323846; n template <class T> n T abs(T a) { n   return a >= 0 ? a : -a; n } n template <class T> n T sqr(T a) { n   return a * a; n } n template <class T> n T gcd(T a, T b) { n   return b ? gcd(b, a % b) : a; n } n template <class T> n T mod(T a, T b) { n   return (a % b + b) % b; n } n template <class T> n T addmod(T a, T b, T c) { n   return (T)mod((long long)a + b, (long long)c); n } n template <class T> n T mulmod(T a, T b, T c) { n   return (T)mod((long long)a * b, (long long)c); n } n template <class T> n T powmod(T a, T b, T c) { n   return (T)mod( n       b ? mulmod(mod(sqr((long long)powmod(a, b >> 1, c)), (long long)c), n                  (b & 1LL) ? a : 1LL, (long long)c) n         : 1LL, n       (long long)c); n } n template <class T> n void maxe(T &a, T b) { n   a = max(a, b); n } n template <class T> n void mine(T &a, T b) { n   a = min(a, b); n } n template <class T> n void mode(T &a, T b) { n   a = mod(a, b); n } n template <class T> n void addmode(T &a, T b, T c) { n   a = addmod(a, b, c); n } n template <class T> n void mulmode(T &a, T b, T c) { n   a = mulmod(a, b, c); n } n template <class T> n void powmode(T &a, T b, T c) { n   a = powmod(a, b, c); n } n int iszero(double a) { return abs(a) <= eps; } n template <class T> n void geti(T &a) { n   a = 0; n   long long b = 1; n   char c = getchar(); n   if (c ==  - ) n     b = -1; n   else n     a = c - 48; n   while ((c = getchar()) !=     && c !=   n ) a = a * 10 + c - 48; n   a *= b; n } n void fileio_in_out() { n   freopen( .in ,  r , stdin); n   freopen( .out ,  w , stdout); n } n void fileio_txt() { n   freopen( input.txt ,  r , stdin); n   freopen( output.txt ,  w , stdout); n } n const int N = 1111111; n const int M = 1111111; n int test; n long long n, m, k, ans; n long long dp[N]; n long long s[N], sinv[N]; n const long long md = inf; n long long c(long long a, long long b) { n   return s[a] * (sinv[b] * sinv[a - b] % md) % md; n } n long long inv(long long a, long long p) { return powmod(a, p - 2, p); } n long long getans() { n   if (n == 0) return k ^ (m > 1); n   if (m == 0) return k ^ (n & 1); n   s[0] = sinv[0] = 1; n   for (long long i = 1; i <= n + m; i++) { n     s[i] = s[i - 1] * i % md; n     sinv[i] = sinv[i - 1] * inv(i, md) % md; n   } n   if (k) n--; n   dp[0] = (m > 1); n   for (long long i = 1; i <= n; i++) n     dp[i] = (c(i + m, i) - dp[i - 1] + md) % md; n   return dp[n]; n } n int main() { n   scanf( %I64d%I64d%I64d , &n, &m, &k); n   ans = getans(); n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 200500; n int inp[MAX]; n int out[MAX]; n bool flag[MAX]; n map<long long, int> ID; n map<long long, int> hasInp; n namespace hopcroftKarp { n int ptr[100011], next[200011], zu[200011]; n int n, m, match[100011], D[100011], q[100011]; n void init(int _n) { n   n = _n; n   m = 0; n   memset(ptr, ~0, sizeof(int) * (n + 1)); n } n void add_edge(int u, int v) { n   next[m] = ptr[u]; n   ptr[u] = m; n   zu[m] = v; n   ++m; n } n bool bfs() { n   int u, v; n   register int i; n   int qh = 0, qt = 0; n   for (i = 1; i <= n; i++) { n     if (!match[i]) { n       D[i] = 0; n       q[qt++] = i; n     } else n       D[i] = (1 << 28); n   } n   D[0] = (1 << 28); n   while (qh < qt) { n     u = q[qh++]; n     if (u != 0) { n       for (i = ptr[u]; ~i; i = next[i]) { n         v = zu[i]; n         if (D[match[v]] == (1 << 28)) { n           D[match[v]] = D[u] + 1; n           q[qt++] = match[v]; n         } n       } n     } n   } n   return D[0] != (1 << 28); n } n bool dfs(int u) { n   int v; n   register int i; n   if (u) { n     for (i = ptr[u]; ~i; i = next[i]) { n       v = zu[i]; n       if (D[match[v]] == D[u] + 1) { n         if (dfs(match[v])) { n           match[v] = u; n           match[u] = v; n           return true; n         } n       } n     } n     D[u] = (1 << 28); n     return false; n   } n   return true; n } n int run() { n   int matching = 0; n   register int i; n   while (bfs()) n     for (i = 1; i <= n; i++) n       if (!match[i] && dfs(i)) matching++; n   return matching; n } n void call(int N, long long a, long long b) { n   int x, y; n   long long vx, vy; n   for (int i = 1; i <= N; i++) { n     if (flag[i]) continue; n     x = i; n     y = match[x]; n     vx = inp[i]; n     vy = inp[y]; n     if (vx + vy == a) { n       out[x] = out[y] = 0; n     } else n       out[x] = out[y] = 1; n     flag[x] = flag[y] = true; n   } n   for (int i = 1; i <= N; i++) { n     if (i != 1) cout <<    ; n     cout << out[i]; n   } n   cout <<   n ; n   return; n } n };  // namespace hopcroftKarp n int main() { n   long long a, b; n   int n; n   std::ios_base::sync_with_stdio(false); n   cin >> n >> a >> b; n   for (int i = 1; i <= n; i++) { n     cin >> inp[i]; n     hasInp[inp[i]] = i; n   } n   long long x, rx, tx; n   int p = 0; n   hopcroftKarp::init(n); n   for (int i = 1; i <= n; i++) { n     x = inp[i]; n     rx = a - x; n     tx = b - x; n     if (hasInp.find(rx) != hasInp.end()) { n       hopcroftKarp::add_edge(i, hasInp[rx]); n     } n     if (hasInp.find(tx) != hasInp.end()) { n       hopcroftKarp::add_edge(i, hasInp[tx]); n     } n   } n   int cnt = hopcroftKarp::run(); n   if (2 * cnt >= (n)) { n     cout <<  YES n ; n     hopcroftKarp::call(n, a, b); n   } else n     cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dp[2][505][505]; n char mp[505][505]; n const int mod = 1000000007; n int dis(int a, int b, int c, int d) { return abs(a - c) + abs(b - d) <= 1; } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) scanf( %s , mp[i]); n   if (mp[0][0] != mp[n - 1][m - 1]) { n     printf( 0 n ); n     return 0; n   } n   memset(dp, 0, sizeof(dp)); n   dp[0][0][n - 1] = 1; n   int t = n + m; n   t /= 2; n   int ans = 0; n   for (int i = 1; i < t; i++) { n     for (int j = 0; j < n; j++) { n       for (int k = n - 1; k >= j; k--) dp[i & 1][j][k] = 0; n     } n     for (int j = 0; j < n; j++) { n       for (int k = n - 1; k >= j; k--) { n         int m1 = i - j; n         int m2 = (n + m - 2 - k - i); n         if (m1 > m - 1) continue; n         if (m2 > m - 1) continue; n         if (mp[j][m1] != mp[k][m2]) continue; n         if (j > 0 && k < n - 1) dp[i & 1][j][k] += dp[!(i & 1)][j - 1][k + 1]; n         if (j > 0 && m2 < m - 1) dp[i & 1][j][k] += dp[!(i & 1)][j - 1][k]; n         if (dp[i & 1][j][k] >= mod) dp[i & 1][j][k] -= mod; n         if (m1 > 0 && k < n - 1) dp[i & 1][j][k] += dp[!(i & 1)][j][k + 1]; n         if (dp[i & 1][j][k] >= mod) dp[i & 1][j][k] -= mod; n         if (m1 > 0 && m2 < m - 1) dp[i & 1][j][k] += dp[!(i & 1)][j][k]; n         if (dp[i & 1][j][k] >= mod) dp[i & 1][j][k] -= mod; n         if (i == t - 1 && dis(j, m1, k, m2)) ans += dp[i & 1][j][k]; n         if (ans >= mod) ans -= mod; n       } n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const long long LINF = 0x3f3f3f3f3f3f3f3f; n const int MOD = 1e9 + 7; n int dir[8][2] = {-1, 0, 1, 0, 0, -1, 0, 1, -1, -1, -1, 1, 1, -1, 1, 1}; n template <typename S, typename T> n ostream &operator<<(ostream &os, const pair<S, T> x) { n   os <<  (  << x.first <<  ,   << x.second <<  ) ; n   return os; n } n template <typename S, typename T> n inline bool Min(S &a, const T &b) { n   return a > b ? a = b, true : false; n } n template <typename S, typename T> n inline bool Max(S &a, const T &b) { n   return a < b ? a = b, true : false; n } n template <typename S, typename T> n inline void Adm(S &a, const T &b) { n   a = (a + b) % MOD; n   if (a < 0) a += MOD; n } n template <typename T> n inline bool IsPri(T x) { n   if (x < 2) return false; n   for (T i = 2; i * i <= x; ++i) n     if (x % i == 0) return false; n   return true; n } n template <typename T> n inline T _Gcd(T a, T b) { n   while (b) { n     T t = b; n     b = a % b; n     a = t; n   } n   return a; n } n template <typename T> n inline int _BitCnt(T x) { n   int cnt = 0; n   while (x) ++cnt, x &= x - 1; n   return cnt; n } n inline long long Pow(long long a, long long n) { n   long long t = 1; n   a %= MOD; n   while (n > 0) { n     if (n & 1) t = t * a % MOD; n     a = a * a % MOD, n >>= 1; n   } n   return t % MOD; n } n inline int read() { n   static char buf[1000000], *p1 = buf, *p2 = buf; n   register int x = false; n   register char ch = n       p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) n           ? EOF n           : *p1++; n   ; n   register bool sgn = false; n   while (ch !=  -  && (ch <  0  || ch >  9 )) n     ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) n              ? EOF n              : *p1++; n   ; n   if (ch ==  - ) n     sgn = true, n     ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) n              ? EOF n              : *p1++; n   ; n   while (ch >=  0  && ch <=  9 ) n     x = (x << 1) + (x << 3) + (ch ^ 48), n     ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) n              ? EOF n              : *p1++; n   ; n   return sgn ? -x : x; n } n const int N = 1e5 + 100; n char s[N]; n int main() { n   scanf( %s , s); n   int n = strlen(s); n   string str, ss; n   vector<int> pos; n   stack<pair<int, string>> stk; n   for (int i = n - 1; i >= 0; --i) { n     char c = s[i]; n     if (str.empty() || str.back() != c || pos.back() - i > 1) { n       str.push_back(c), pos.push_back(i); n       if (ss.empty() || ss.back() != c) ss.push_back(c); n     } else { n       if (((int)(ss).size()) == 1 || ss[((int)(ss).size()) - 2] < c) { n         str.pop_back(), pos.pop_back(); n         if (str.empty() || str.back() != ss.back()) ss.pop_back(); n       } else { n         str.push_back(c), pos.push_back(i); n         if (ss.empty() || ss.back() != c) ss.push_back(c); n       } n     } n     pair<int, string> now = {((int)(str).size()),   }; n     if (((int)(str).size()) <= 10) n       now.second = str; n     else n       now.second = n           str.substr(0, 2) +  ...  + str.substr(((int)(str).size()) - 5, 5); n     reverse((now.second).begin(), (now.second).end()); n     stk.push(now); n   } n   while (!stk.empty()) n     printf( %d %s n , stk.top().first, stk.top().second.c_str()), stk.pop(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3333; n int cnt[maxn][maxn][2], fuck[maxn], dep[maxn][maxn], dis[maxn][maxn]; n struct Edge { n   int t, next, v; n } edge[maxn << 1]; n int head[maxn], tot, n; n void new_edge(int a, int b, int t) { n   edge[tot].t = b; n   edge[tot].next = head[a]; n   edge[tot].v = t; n   head[a] = tot++; n } n void dfs(int u, int fa, int rt) { n   int i; n   for (i = head[u]; i != -1; i = edge[i].next) { n     int e = edge[i].t; n     if (e == fa) continue; n     dep[rt][e] = dep[rt][u] + 1; n     int add = edge[i].v; n     cnt[rt][e][1] = min(cnt[rt][u][0], cnt[rt][u][1]) + !add; n     cnt[rt][e][0] = cnt[rt][u][0] + add; n     dis[rt][e] = dis[rt][u] + add; n     fuck[rt] += add; n     dfs(e, u, rt); n   } n } n int main() { n   tot = 0; n   int i, j, k; n   memset(head, -1, sizeof(head)); n   scanf( %d , &n); n   for (i = 1; i < n; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     new_edge(a, b, 0); n     new_edge(b, a, 1); n   } n   for (i = 1; i <= n; i++) dfs(i, 0, i); n   int ans = 111111111; n   for (i = 1; i <= n; i++) n     for (j = 1; j <= n; j++) { n       ans = min(ans, fuck[i] - dis[i][j] + min(cnt[i][j][0], cnt[i][j][1])); n       ans = min(ans, fuck[i]); n     } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool besarDulu(const int &a, const int &b) { return a > b; } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     int h, m; n     cin >> h >> m; n     int minutes = (24 - h - 1) * 60 + (60 - m); n     cout << minutes <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool cur1; n int n, m, K; n int L[100005 * 120], R[100005 * 120], res[100005 * 120], tt, rt[100005 * 3]; n int update(int p, int l, int r, int x, int v) { n   int c = ++tt; n   L[c] = L[p], R[c] = R[p]; n   if (l == r) { n     res[c] = min((p ? res[p] : 0x3f3f3f3f), v); n     return c; n   } n   int mid = (l + r) >> 1; n   if (x <= mid) n     L[c] = update(L[p], l, mid, x, v); n   else n     R[c] = update(R[p], mid + 1, r, x, v); n   res[c] = max(res[L[c]], res[R[c]]); n   return c; n } n int query(int p, int u, int v, int l, int r) { n   if (u <= l && r <= v) { n     return res[p]; n   } n   int mid = (l + r) >> 1; n   int ans = 0; n   if (u <= mid) ans = max(ans, query(L[p], u, v, l, mid)); n   if (v > mid) ans = max(ans, query(R[p], u, v, mid + 1, r)); n   return ans; n } n struct seg { n   int a, b, c; n   bool operator<(const seg &_) const { n     if (a != _.a) return a < _.a; n     if (c != _.c) return c < _.c; n     if (b != _.b) return b > _.b; n   } n } Sg[100005 * 3]; n int B[100005 * 3]; n void solve() { n   tt = 0; n   int tot = 0; n   scanf( %d %d %d , &n, &m, &K); n   for (int a, b, c, i = 1; i <= K; i++) { n     scanf( %d %d %d , &a, &b, &c); n     B[i] = a; n     Sg[i] = (seg){a, b, c}; n   } n   sort(B + 1, B + K + 1); n   sort(Sg + 1, Sg + K + 1); n   tot = unique(B + 1, B + 1 + K) - B - 1; n   for (int i = 1; i <= n; i++) n     rt[tot + 1] = update(rt[tot + 1], 1, n, i, 0x3f3f3f3f); n   Sg[K + 1].a = 0x3f3f3f3f; n   for (int i = K; i >= 1; i--) { n     int t = lower_bound(B + 1, B + 1 + tot, Sg[i].a) - B; n     if (Sg[i].a != Sg[i + 1].a) { n       rt[t] = update(rt[t + 1], 1, n, Sg[i].c, Sg[i].b); n     } else n       rt[t] = update(rt[t], 1, n, Sg[i].c, Sg[i].b); n   } n   while (m--) { n     int a, b, c, d; n     scanf( %d %d %d %d , &a, &b, &c, &d); n     if (c > B[tot]) { n       puts( no ); n       fflush(stdout); n       continue; n     } else { n       int t = lower_bound(B + 1, B + 1 + tot, c) - B; n       if (query(rt[t], a, b, 1, n) <= d) n         puts( yes ); n       else n         puts( no ); n     } n     fflush(stdout); n   } n } n bool cur2; n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long MOD = 1e9 + 7; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   int t; n   cin >> t; n   while (t != 0) { n     t--; n     int n, k, l = -1, r = -1; n     cin >> n >> k; n     int c = k + 1, z, res = 0; n     string x; n     cin >> x; n     for (int i = 0; i < n; i++) { n       if (x[i] ==  1 ) { n         r = i; n         if (l == -1) n           z = r - l - 1 - k; n         else n           z = r - l - 1 - (2 * k); n         if (z > 0) { n           c = k + 1; n           for (int j = 0; j < z; j++) { n             if (c > k) { n               res++; n               c = 0; n             } n             c++; n           } n         } n         l = i; n         z = 0; n       } n     } n     r = n; n     if (l == -1) n       z = r - l - 1; n     else n       z = r - l - 1 - k; n     if (z > 0) { n       c = k + 1; n       for (int j = 0; j < z; j++) { n         if (c > k) { n           res++; n           c = 0; n         } n         c++; n       } n     } n     cout << res << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   cin >> n; n   long long b[n]; n   pair<long long, long long> arr[n]; n   for (long long i = 0; i < n; i++) { n     cin >> b[i]; n     arr[i].first = b[i] - i + 200000; n     arr[i].second = b[i]; n   } n   sort(arr, arr + n); n   long long maxi = 0; n   long long i = -1; n   while (i < (n - 1)) { n     i++; n     long long c = 0; n     c += arr[i].second; n     while (arr[i].first == arr[i + 1].first) { n       c += arr[i + 1].second; n       i++; n     } n     maxi = max(c, maxi); n   } n   if (n == 1) { n     cout << b[0]; n   } else { n     cout << maxi; n   } n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); n mt19937_64 rnd64( n     chrono::high_resolution_clock::now().time_since_epoch().count()); n long long power(long long a, long long m, long long mod) { n   long long ans = 1; n   while (m) { n     if (m % 2) { n       ans *= a; n       ans %= (mod); n     } n     a = (a * a) % (mod); n     m >>= 1; n   } n   return ans; n } n void init(long long* a, long long n, long long val) { n   for (long long i = 0; i < n; i++) a[i] = val; n } n void solve() { n   long long i, j, _, n; n   cin >> n; n   long long a[n], pre[n]; n   for (i = 0; i < n; i++) cin >> a[i]; n   vector<long long> ans; n   sort(a, a + n); n   j = 0; n   for (i = 0; i < n; i++) cin >> j, j += a[i], j %= 998244353, pre[i] = j; n   for (i = 1; i < n; i++) { n     long long k = 0; n     for (j = n - i - 1; j > -1; j -= i) k += pre[j], k %= 998244353; n     ans.push_back(k); n   } n   ans.push_back(0); n   n = power(n, 998244353 - 2, 998244353); n   for (auto& i : ans) i *= n, i %= 998244353, cout << i <<    ; n   cout << endl; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   long long T = 1; n   while (T--) { n     solve(); n   } n   return 0; n } n