#include <bits/stdc++.h>   namespace test {   struct Poly {    public:     using value_type = unsigned int;     using ptr_type = value_type *;     using const_ptr_type = value_type const *;     using cast_type = unsigned long long;     using size_type = unsigned int;     using arr_type = value_type[1 << 21];     using iterator = ptr_type;     using const_iterator = const_ptr_type;     static constexpr value_type P = 998244353, G = 3;       private:     iterator _Start, _Finish, _End;     static inline arr_type ROOT, IROOT;     Poly &dft(size_type len) { return resize(len), _dft(len, _Start), *this; }     Poly &idft(size_type len) { return _idft(len, _Start), *this; }     Poly &revbin() { return _revbin(size(), _Start), *this; }     value_type horner(value_type x) const {       value_type res = *(end() - 1);       for (const_iterator i = end() - 1, e = begin(); i != e; --i)         res = (static_cast<cast_type>(res) * x + *(i - 1)) % P;       return res;     }     using v_it = std::vector<value_type>::const_iterator;     static void segment_tree_build(std::vector<Poly> &, size_type, v_it, v_it);     static void segment_tree_solve(const std::vector<Poly> &, size_type, v_it,                                    v_it, const Poly &, std::vector<value_type> &);     static size_type _get_len(size_type);     static value_type _mod_pow(value_type, long long);     static value_type _legendre_symbol(value_type);     static value_type _tonelli_shanks(value_type);     static void _revbin(size_type, ptr_type);     static void _dif_ntt(size_type, ptr_type, ptr_type);     static void _dit_ntt(size_type, ptr_type, ptr_type);     static void _init_root_of_unity(size_type);     static void _dft(size_type, ptr_type);     static void _idft(size_type, ptr_type);       public:     iterator begin() { return _Start; }     iterator end() { return _Finish; }     const_iterator begin() const { return const_cast<const_iterator>(_Start); }     const_iterator end() const { return const_cast<const_iterator>(_Finish); }     size_type size() const { return _Finish - _Start; }     size_type capacity() const { return _End - _Start; }     value_type &operator[](size_type x) { return *(_Start + x); }     value_type operator[](size_type x) const { return *(_Start + x); }     Poly &remove_trailing_zeros() {       while (size() > 1 && *(_Finish - 1) == 0) --_Finish;       return *this;     }     Poly &resize(size_type new_size) {       assert(new_size > 0);       if (new_size > capacity()) {         size_t old_capacity = capacity(), new_capacity = _get_len(new_size);         _Start = static_cast<iterator>(             std::realloc(_Start, sizeof(value_type) * new_capacity));         assert(_Start != nullptr);         _End = _Start + new_capacity;         std::memset(_Start + old_capacity, 0,                     sizeof(value_type) * (new_capacity - old_capacity));       } else if (size() > new_size)         std::memset(_Start + new_size, 0,                     sizeof(value_type) * (size() - new_size));       return _Finish = _Start + new_size, *this;     }     explicit Poly(size_type _reserved)         : _Start(static_cast<iterator>(               std::calloc(_get_len(_reserved), sizeof(value_type)))),           _Finish(_Start + _reserved),           _End(_Start + _get_len(_reserved)) {       assert((_reserved > 0 && _Start != nullptr));     }     Poly(const_iterator _first, const_iterator _last)         : _Start(static_cast<iterator>(               std::malloc(sizeof(value_type) * _get_len(_last - _first)))),           _Finish(_Start + (_last - _first)),           _End(_Start + _get_len(_last - _first)) {       assert((_last - _first > 0 && _Start != nullptr));       std::memcpy(_Start, _first, sizeof(value_type) * (_last - _first));       std::memset(_Finish, 0, sizeof(value_type) * (_End - _Finish));     }     Poly(const Poly &rhs) : Poly(rhs.begin(), rhs.end()) {}     Poly(Poly &&rhs) : _Start(rhs._Start), _Finish(rhs._Finish), _End(rhs._End) {       rhs._Start = rhs._Finish = rhs._End = nullptr;     }     Poly(std::initializer_list<value_type> l) : Poly(l.begin(), l.end()) {}     ~Poly() {       if (_Start != nullptr) std::free(_Start);     }     Poly &operator=(const Poly &rhs) {       if (this == &rhs) return *this;       return resize(rhs.size()),              std::memcpy(this->_Start, rhs.begin(),                          sizeof(value_type) * rhs.size()),              *this;     }     Poly operator-() const {       Poly res(*this);       for (iterator i = res.begin(), e = res.end(); i != e; ++i)         if (*i != 0) *i = P - *i;       return res;     }     Poly &operator+=(const Poly &rhs) {       if (size() < rhs.size()) resize(rhs.size());       for (size_type i = 0, e = rhs.size(); i != e; ++i)         *(this->_Start + i) = (*(this->_Start + i) + *(rhs._Start + i)) % P;       return *this;     }     Poly &operator-=(const Poly &rhs) {       if (size() < rhs.size()) resize(rhs.size());       for (size_type i = 0, e = rhs.size(); i != e; ++i)         *(this->_Start + i) = (*(this->_Start + i) + P - *(rhs._Start + i)) % P;       return *this;     }     Poly &operator*=(const Poly &);     Poly &operator/=(const Poly &);     Poly &operator%=(const Poly &);     Poly quo(const Poly &) const;     std::pair<Poly, Poly> quo_with_rem(const Poly &) const;     Poly deriv() const;     Poly integr() const;     Poly inv() const;     Poly log() const;     Poly exp() const;     Poly sqrt() const;     Poly isqrt() const;     std::vector<value_type> eval(const std::vector<value_type> &) const;     static Poly inter(const std::vector<value_type> &,                       const std::vector<value_type> &);     friend Poly operator+(const Poly &lhs, const Poly &rhs) {       return Poly(lhs) += rhs;     }     friend Poly operator-(const Poly &lhs, const Poly &rhs) {       return Poly(lhs) -= rhs;     }     friend Poly operator*(const Poly &lhs, const Poly &rhs) {       return Poly(lhs) *= rhs;     }     friend Poly operator/(const Poly &lhs, const Poly &rhs) {       return Poly(lhs) /= rhs;     }     friend Poly operator%(const Poly &lhs, const Poly &rhs) {       return Poly(lhs) %= rhs;     }     friend void swap(Poly &lhs, Poly &rhs) {       iterator tmp;       tmp = lhs._Start, lhs._Start = rhs._Start, rhs._Start = tmp;       tmp = lhs._Finish, lhs._Finish = rhs._Finish, rhs._Finish = tmp;       tmp = lhs._End, lhs._End = rhs._End, rhs._End = tmp;     }     friend std::istream &operator>>(std::istream &is, Poly &rhs) {       for (iterator i = rhs.begin(), e = rhs.end(); i != e; ++i) is >> *i;       return is;     }     friend std::ostream &operator<<(std::ostream &os, const Poly &rhs) {       for (const_iterator i = rhs.begin(), e = rhs.end(); i != e; ++i)         os << *i <<    ;       return os;     }   };   Poly::size_type Poly::_get_len(size_type x) {     size_type res = 1;     while (res < x) res <<= 1;     return res;   }   Poly::value_type Poly::_mod_pow(value_type x, long long y) {     if ((y %= static_cast<long long>(P - 1)) < 0) y += P - 1;     value_type res = 1;     for (; y; y >>= 1, x = static_cast<cast_type>(x) * x % P)       if (y & 1) res = static_cast<cast_type>(res) * x % P;     return res;   }   Poly::value_type Poly::_legendre_symbol(value_type x) {     return x == 0 ? 0 : _mod_pow(x, P - 1 >> 1);   }   Poly::value_type Poly::_tonelli_shanks(value_type a) {     if (_legendre_symbol(a) != 1) return 0;     value_type q = P - 1, t = 0, n, z;     while ((q & 1) == 0) q >>= 1, ++t;     if (t == 1) return _mod_pow(a, P + 1 >> 2);     for (n = 1; n != P; ++n)       if (_legendre_symbol(n) == P - 1) {         z = _mod_pow(n, q);         break;       }     value_type y = z, r = t, x = _mod_pow(a, q - 1 >> 1), b = x;     x = static_cast<cast_type>(x) * a % P, b = static_cast<cast_type>(x) * b % P;     while (true) {       if (b == 1) return x < P - x ? x : P - x;       value_type m = 1;       for (; m < r; ++m)         if (_mod_pow(b, 1 << m) == 1) break;       value_type v = _mod_pow(y, 1 << r - m - 1);       y = static_cast<cast_type>(v) * v % P, r = m,       x = static_cast<cast_type>(x) * v % P,       b = static_cast<cast_type>(b) * y % P;     }   }   void Poly::_dif_ntt(size_type n, ptr_type x, ptr_type root) {     for (size_type i = n; i != 1; i >>= 1)       for (size_type j = 0, l = i >> 1; j != n; j += i)         for (size_type k = 0; k != l; ++k) {           value_type u = *(x + j + k), v = *(x + j + k + l);           *(x + j + k) = (u + v >= P ? u + v - P : u + v),                     *(x + j + k + l) =                         (static_cast<cast_type>(u) + P - v) * *(root + l + k) % P;         }   }   void Poly::_dit_ntt(size_type n, ptr_type x, ptr_type root) {     for (size_type i = 2; i <= n; i <<= 1)       for (size_type j = 0, l = i >> 1; j != n; j += i)         for (size_type k = 0; k != l; ++k) {           value_type u = *(x + j + k),                      v = static_cast<cast_type>(*(root + l + k)) *                          *(x + j + k + l) % P;           *(x + j + k) = (u + v >= P ? u + v - P : u + v),                     *(x + j + k + l) = (u >= v ? u - v : u + P - v);         }   }   void Poly::_init_root_of_unity(size_type n) {     static size_type lim = 1;     if (lim < n) {       const size_type l = n >> 1;       value_type g = _mod_pow(G, (P - 1) / n),                  ig = _mod_pow(G, -static_cast<int>((P - 1) / n));       ROOT[l] = IROOT[l] = 1;       for (size_type i = l + 1; i < n; ++i)         ROOT[i] = static_cast<cast_type>(ROOT[i - 1]) * g % P,         IROOT[i] = static_cast<cast_type>(IROOT[i - 1]) * ig % P;       for (size_type i = l - 1; i >= lim; --i)         ROOT[i] = ROOT[i << 1], IROOT[i] = IROOT[i << 1];       lim = n;     }   }   void Poly::_revbin(size_type n, ptr_type x) {     for (size_type i = 0, j = 0; i != n; ++i) {       if (i < j) std::swap(*(x + i), *(x + j));       for (size_type k = n >> 1; (j ^= k) < k; k >>= 1) {       }     }   }   void Poly::_dft(size_type n, ptr_type x) {     _init_root_of_unity(n), _dif_ntt(n, x, ROOT);   }   void Poly::_idft(size_type n, ptr_type x) {     _dit_ntt(n, x, IROOT);     value_type in = P - (P - 1) / n;     for (ptr_type i = x, e = x + n; i != e; ++i)       *i = static_cast<cast_type>(*i) * in % P;   }   Poly &Poly::operator*=(const Poly &rhs) {     size_type n = size(), m = rhs.size(), len = _get_len(n + m - 1);     if (n + m - 1 <= 128 || std::min(n, m) <= 8) {       Poly res(n + m - 1);       for (size_type i = 0; i != n; ++i)         for (size_type j = 0; j != m; ++j)           *(res._Start + i + j) =               (*(res._Start + i + j) +                static_cast<cast_type>(*(this->_Start + i)) * *(rhs._Start + j)) %               P;       return this->operator=(res);     } else {       Poly rhs_cpy(rhs);       dft(len), rhs_cpy.dft(len);       for (size_type i = 0; i != len; ++i)         *(_Start + i) = static_cast<cast_type>(*(this->_Start + i)) *                         *(rhs_cpy._Start + i) % P;       return idft(len).resize(n + m - 1);     }   }   Poly &Poly::operator/=(const Poly &rhs) {     if (size() < rhs.size()) return this->operator=(Poly{0});     if (rhs.size() == 1) return this->operator*=(rhs.inv());     size_type n = size() - rhs.size() + 1;     Poly rhs_cpy(rhs);     std::reverse(begin(), end()), std::reverse(rhs_cpy.begin(), rhs_cpy.end());     Poly res = resize(n).quo(rhs_cpy);     std::reverse(res.begin(), res.end());     return this->operator=(res);   }   Poly &Poly::operator%=(const Poly &rhs) {     return this->operator=(quo_with_rem(rhs).second);   }   std::pair<Poly, Poly> Poly::quo_with_rem(const Poly &rhs) const {     if (size() < rhs.size()) return {{0}, *this};     Poly q = *this / rhs;     if (rhs.size() == 1) return {q, {0}};     size_type len = _get_len(std::max(q.size(), rhs.size()));     int overlap = static_cast<int>(q.size() + rhs.size() - 1) - len;     Poly q_cpy(q), rhs_cpy(rhs);     q_cpy.dft(len), rhs_cpy.dft(len);     for (size_type i = 0; i != len; ++i)       *(q_cpy._Start + i) =           static_cast<cast_type>(*(q_cpy._Start + i)) * *(rhs_cpy._Start + i) % P;     q_cpy.idft(len).resize(rhs.size() - 1);     if (overlap > 0)       for (size_type i = 0; i != overlap && q_cpy.begin() + i != q_cpy.end(); ++i)         *(q_cpy._Start + i) =             (*(q_cpy._Start + i) + P - this->operator[](len + i)) % P;     for (size_type i = 0, e = q_cpy.size(); i != e; ++i)       *(q_cpy._Start + i) = (this->operator[](i) + P - *(q_cpy._Start + i)) % P;     return {q, q_cpy};   }   Poly Poly::deriv() const {     if (size() == 1) return {0};     Poly res(size() - 1);     for (size_type i = 1, len = size(); i != len; ++i)       *(res._Start + i - 1) = static_cast<cast_type>(this->operator[](i)) * i % P;     return res;   }   Poly Poly::integr() const {     static size_type lim = 0;     static arr_type INV{0, 1};     size_type len = size() + 1;     Poly res(len);     if (lim < len)       for (size_type i = (lim < 2 ? 2 : lim); i < len; ++i)         INV[i] = static_cast<cast_type>(P - P / i) * INV[P % i] % P;     for (size_type i = 1; i != len; ++i)       *(res._Start + i) =           static_cast<cast_type>(this->operator[](i - 1)) * INV[i] % P;     return res;   }   Poly Poly::inv() const {     assert(*begin() != 0);     size_type len = _get_len(size());     Poly res(len);     res[0] = _mod_pow(*this->_Start, -1);     res.resize(1);     for (size_type i = 2; i <= len; i <<= 1) {       Poly cpy(begin(), begin() + i), res_cpy(res);       res_cpy.dft(i), cpy.dft(i);       for (size_type j = 0; j != i; ++j)         *(cpy._Start + j) =             static_cast<cast_type>(*(cpy._Start + j)) * *(res_cpy._Start + j) % P;       cpy.idft(i);       std::memset(cpy.begin(), 0, sizeof(value_type) * (i >> 1));       cpy.dft(i);       for (size_type j = 0; j != i; ++j)         *(cpy._Start + j) =             static_cast<cast_type>(*(cpy._Start + j)) * *(res_cpy._Start + j) % P;       cpy.idft(i), res.resize(i);       for (iterator j = cpy.begin() + (i >> 1), e = cpy.end(); j != e; ++j)         if (*j != 0) *j = P - *j;       std::memcpy(res.begin() + (i >> 1), cpy.begin() + (i >> 1),                   sizeof(value_type) * (i >> 1));     }     return res.resize(size());   }   Poly Poly::quo(const Poly &rhs) const {     if (size() == 1)       return Poly{static_cast<value_type>(static_cast<cast_type>(*begin()) *                                           _mod_pow(*rhs.begin(), -1) % P)};     Poly rhs_cpy(rhs);     size_type len = _get_len(size()), len_2 = len >> 1;     rhs_cpy.resize(len);     Poly rhs_inv = Poly(rhs_cpy.begin(), rhs_cpy.begin() + len_2).inv(),          q(begin(), begin() + len_2);     rhs_inv.dft(len), q.dft(len);     for (size_type i = 0; i != len; ++i)       *(q._Start + i) =           static_cast<cast_type>(*(q._Start + i)) * *(rhs_inv._Start + i) % P;     q.idft(len).resize(len_2).resize(size());     Poly q_cpy(q);     q_cpy.dft(len), rhs_cpy.dft(len);     for (size_type i = 0; i != len; ++i)       *(q_cpy._Start + i) =           static_cast<cast_type>(*(q_cpy._Start + i)) * *(rhs_cpy._Start + i) % P;     q_cpy.idft(len);     std::memset(q_cpy.begin(), 0, sizeof(value_type) * len_2);     for (size_type i = len_2; i < size() && i != len; ++i)       *(q_cpy._Start + i) = (*(q_cpy._Start + i) + P - this->operator[](i)) % P;     q_cpy.dft(len);     for (size_type i = 0; i != len; ++i)       *(q_cpy._Start + i) =           static_cast<cast_type>(*(q_cpy._Start + i)) * *(rhs_inv._Start + i) % P;     q_cpy.idft(len);     for (iterator i = q_cpy.begin() + len_2, e = q_cpy.begin() + size(); i != e;          ++i)       if (*i != 0) *i = P - *i;     std::memcpy(q.begin() + len_2, q_cpy.begin() + len_2,                 sizeof(value_type) * (size() - len_2));     return q;   }   Poly Poly::log() const {     assert(*begin() == 1);     return deriv().quo(*this).integr();   }   Poly Poly::exp() const {     assert(*begin() == 0);     if (size() == 1) return {1};     size_type len = _get_len(size());     Poly res(len), res_inv(len), der(deriv()), g0(len);     res.operator=(Poly{1, this->operator[](1)}), res_inv.operator=(res.inv()),     g0.operator=(res);     g0.dft(4);     for (size_type i = 4; i <= len; i <<= 1) {       Poly h0(res_inv), g0p(res.deriv()),           f0p(der.begin(), der.begin() + (i >> 1) - 1), g0f0p(i);       h0.dft(i), f0p.dft(i >> 1);       for (size_type j = 0; j != i >> 1; ++j)         *(g0f0p._Start + j) =             static_cast<cast_type>(*(g0._Start + j)) * *(f0p._Start + j) % P;       g0f0p.idft(i >> 1).resize(i);       for (size_type j = 0; j != (i >> 1) - 1; ++j)         *(g0f0p._Start + j) = (*(g0f0p._Start + j) + P - *(g0p._Start + j)) % P;       std::memcpy(g0f0p.begin() + (i >> 1), g0f0p.begin(),                   sizeof(value_type) * ((i >> 1) - 2));       std::memset(g0f0p.begin(), 0, sizeof(value_type) * ((i >> 1) - 2));       for (iterator j = g0f0p.begin() + ((i >> 1) - 1), e = g0f0p.end(); j != e;            ++j)         if (*j != 0) *j = P - *j;       g0f0p.dft(i);       for (size_type j = 0; j != i; ++j)         *(g0f0p._Start + j) =             static_cast<cast_type>(*(g0f0p._Start + j)) * *(h0._Start + j) % P;       g0f0p.idft(i);       Poly imf(g0f0p.resize(i - 1).integr());       std::memset(imf.begin(), 0, sizeof(value_type) * (i >> 1));       for (size_type j = i >> 1; j != i; ++j)         *(imf._Start + j) = (*(imf._Start + j) + P - this->operator[](j)) % P;       imf.dft(i);       for (size_type j = 0; j != i; ++j)         *(imf._Start + j) =             static_cast<cast_type>(*(imf._Start + j)) * *(g0._Start + j) % P;       imf.idft(i), res.resize(i);       for (iterator j = imf.begin() + (i >> 1), e = imf.end(); j != e; ++j)         if (*j != 0) *j = P - *j;       std::memcpy(res.begin() + (i >> 1), imf.begin() + (i >> 1),                   sizeof(value_type) * (i >> 1));       if (i != len) {         g0.operator=(res).dft(i << 1);         Poly g0_half(i);         for (size_type j = 0; j != i; ++j)           *(g0_half._Start + j) =               static_cast<cast_type>(*(g0._Start + j)) * *(h0._Start + j) % P;         g0_half.idft(i);         std::memset(g0_half.begin(), 0, sizeof(value_type) * (i >> 1));         g0_half.dft(i);         for (size_type j = 0; j != i; ++j)           *(g0_half._Start + j) = static_cast<cast_type>(*(g0_half._Start + j)) *                                   *(h0._Start + j) % P;         g0_half.idft(i), res_inv.resize(i);         for (iterator j = g0_half.begin() + (i >> 1), e = g0_half.end(); j != e;              ++j)           if (*j != 0) *j = P - *j;         std::memcpy(res_inv.begin() + (i >> 1), g0_half.begin() + (i >> 1),                     sizeof(value_type) * (i >> 1));       }     }     return res.resize(size());   }   Poly Poly::sqrt() const {     assert(_legendre_symbol(*begin()) != 0);     size_type len = _get_len(size());     Poly res(len), res_inv(len), g0(len);     res.operator=(Poly{_tonelli_shanks(*begin())}),     res_inv.operator=(Poly{_mod_pow(res.operator[](0), -1)}), g0.operator=(res);     g0.dft(2);     const value_type inv2 = P - (P - 1) / 2;     for (size_type i = 2; i <= len; i <<= 1) {       Poly g0_2(i), res_inv_cpy(res_inv);       for (size_type j = 0; j != i >> 1; ++j)         *(g0_2._Start + j) =             (static_cast<cast_type>(*(g0._Start + j)) * *(g0._Start + j)) % P;       g0_2.idft(i >> 1).resize(i);       for (size_type j = 0; j != i >> 1; ++j)         *(g0_2._Start + j) = (*(g0_2._Start + j) + P - this->operator[](j)) % P;       std::memcpy(g0_2.begin() + (i >> 1), g0_2.begin(),                   sizeof(value_type) * ((i >> 1) - 1));       std::memset(g0_2.begin(), 0, sizeof(value_type) * ((i >> 1) - 1));       for (size_type j = i >> 1; j != i; ++j)         *(g0_2._Start + j) = (*(g0_2._Start + j) + P - this->operator[](j)) % P;       g0_2.dft(i), res_inv_cpy.dft(i);       for (size_type j = 0; j != i; ++j)         *(g0_2._Start + j) = static_cast<cast_type>(*(g0_2._Start + j)) *                              *(res_inv_cpy._Start + j) % P;       g0_2.idft(i), res.resize(i);       for (iterator j = g0_2.begin() + (i >> 1), e = g0_2.end(); j != e; ++j)         if (*j != 0) *j = static_cast<cast_type>(P - *j) * inv2 % P;       std::memcpy(res.begin() + (i >> 1), g0_2.begin() + (i >> 1),                   sizeof(value_type) * (i >> 1));       if (i != len) {         g0.operator=(res).dft(i);         for (size_type j = 0; j != i; ++j)           *(g0_2._Start + j) = static_cast<cast_type>(*(g0._Start + j)) *                                *(res_inv_cpy._Start + j) % P;         g0_2.idft(i);         std::memset(g0_2.begin(), 0, sizeof(value_type) * (i >> 1));         g0_2.dft(i);         for (size_type j = 0; j != i; ++j)           *(g0_2._Start + j) = static_cast<cast_type>(*(g0_2._Start + j)) *                                *(res_inv_cpy._Start + j) % P;         g0_2.idft(i), res_inv.resize(i);         for (iterator j = g0_2.begin() + (i >> 1), e = g0_2.end(); j != e; ++j)           if (*j != 0) *j = P - *j;         std::memcpy(res_inv.begin() + (i >> 1), g0_2.begin() + (i >> 1),                     sizeof(value_type) * (i >> 1));       }     }     return res.resize(size());   }   void Poly::segment_tree_build(std::vector<Poly> &vp, size_type pos, v_it left,                                 v_it right) {     if (right - left == 1) {       vp[pos] = Poly{*left == 0 ? 0 : P - *left, 1};       return;     }     v_it mid = left + (right - left >> 1);     segment_tree_build(vp, pos << 1, left, mid),         segment_tree_build(vp, pos << 1 | 1, mid, right);     vp[pos] = vp[pos << 1] * vp[pos << 1 | 1];   }   void Poly::segment_tree_solve(const std::vector<Poly> &vp, size_type pos,                                 v_it left, v_it right, const Poly &r,                                 std::vector<value_type> &res) {     if (right - left <= 128) {       for (v_it it = left; it != right; ++it) res.push_back(r.horner(*it));       return;     }     v_it mid = left + (right - left >> 1);     segment_tree_solve(vp, pos << 1, left, mid, r % vp[pos << 1], res),         segment_tree_solve(vp, pos << 1 | 1, mid, right, r % vp[pos << 1 | 1],                            res);   }   std::vector<Poly::value_type> Poly::eval(       const std::vector<value_type> &points) const {     std::vector<Poly> vp(points.size() << 2, Poly{0});     segment_tree_build(vp, 1, points.begin(), points.end());     std::vector<value_type> res;     segment_tree_solve(vp, 1, points.begin(), points.end(), *this % vp[1], res);     return res;   }   Poly Poly::inter(const std::vector<value_type> &x,                    const std::vector<value_type> &y) {     size_type n = x.size();     assert(y.size() == n);     std::vector<Poly> vp(n << 2, Poly{0});     segment_tree_build(vp, 1, x.begin(), x.end());     std::vector<value_type> v;     segment_tree_solve(vp, 1, x.begin(), x.end(), vp[1].deriv() % vp[1], v);     for (size_type i = 0; i != n; ++i)       v[i] = _mod_pow(v[i], -1) * static_cast<cast_type>(y[i]) % P;     std::function<Poly(size_type, v_it, v_it)> inter_rec =         [&inter_rec, &vp](size_type pos, v_it left, v_it right) {           if (right - left == 1) return Poly{*left};           return inter_rec(pos << 1, left, left + (right - left >> 1)) *                      vp[pos << 1 | 1] +                  inter_rec(pos << 1 | 1, left + (right - left >> 1), right) *                      vp[pos << 1];         };     return inter_rec(1, v.begin(), v.end());   }   }  // namespace test   using test::Poly;   using namespace std;   using ll = long long;   using ull = unsigned long long;   const int N = 2e5 + 5;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     int t;     Poly a(m + 1);     for (int i = 0; i < n; ++i) {       cin >> t;       if (t <= m) a[t] = 1;     }     Poly ans = Poly{2} * (Poly{1} + (Poly{1} - Poly{4} * a).sqrt()).inv();     for (int i = 1; i != m + 1; ++i) cout << ans[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 505, MOD = 1e9 + 7;   struct node {     node *ch[20], *fail;     int cnt, id;     node(node* son = NULL) {       for (int i = 0; i <= 19; i++) ch[i] = son;       fail = son;       cnt = id = 0;     }   } nil, *null = &nil, *root = null, *nd[maxn];   typedef node* P_node;   queue<P_node> que;   void Build() {     root->fail = root;     root->id = 0;     nd[0] = root;     for (int i = 0; i <= 19; i++)       if (root->ch[i] != null) {         P_node v = root->ch[i];         que.push(v);         v->fail = root;       } else         root->ch[i] = root;     while (!que.empty()) {       P_node p = que.front();       que.pop();       for (int i = 0; i <= 19; i++)         if (p->ch[i] != null) {           P_node v = p->ch[i];           que.push(v);           v->fail = p->fail->ch[i];           v->cnt += v->fail->cnt;         } else           p->ch[i] = p->fail->ch[i];     }   }   int a[maxn], b[maxn], c[maxn], n, m, K, tot;   int f[2][205][705][2][2];   int Calc(int a[]) {     memset(f, 0, sizeof(f));     f[0][0][0][0][0] = 1;     for (int i = 0, o = 0; i <= a[0] - 1; i++, o ^= 1) {       memset(f[o ^ 1], 0, sizeof(f[o ^ 1]));       for (int j = 0; j <= tot; j++)         for (int k = 0; k <= K; k++)           for (int t1 = 0; t1 <= 1; t1++)             for (int t2 = 0; t2 <= 1; t2++)               if (f[o][j][k][t1][t2]) {                 for (int t = 0; t <= (t2 ? m - 1 : a[i + 1]); t++) {                   int v = (t1 | (t > 0)) ? nd[j]->ch[t]->id : 0;                   (f[o ^ 1][v][k + nd[v]->cnt][t1 | (t > 0)]                     [t2 | (t < a[i + 1])] += f[o][j][k][t1][t2]) %= MOD;                 }               }     }     int res = 0;     for (int i = 0; i <= tot; i++)       for (int j = 0; j <= K; j++)         for (int k = 0; k <= 1; k++)           for (int t = 0; t <= 1; t++) (res += f[a[0] & 1][i][j][k][t]) %= MOD;     return res;   }   int main() {     scanf( %d%d%d , &n, &m, &K);     scanf( %d , &a[0]);     for (int i = 1; i <= a[0]; i++) scanf( %d , &a[i]);     scanf( %d , &b[0]);     for (int i = 1; i <= b[0]; i++) scanf( %d , &b[i]);     a[a[0]]--;     for (int i = a[0]; i >= 1; i--)       if (a[i] < 0) a[i] += m, a[i - 1]--;     nil = node(null);     for (int i = 1; i <= n; i++) {       int t, x;       scanf( %d , &t);       P_node now = root;       while (t--) {         scanf( %d , &x);         if (now->ch[x] == null) {           now = now->ch[x] = new node(null);           now->id = ++tot;           nd[tot] = now;         } else           now = now->ch[x];       }       scanf( %d , &x);       now->cnt += x;     }     Build();     printf( %d n , ((Calc(b) - Calc(a)) % MOD + MOD) % MOD);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 1;   int sp[N];   int dp[N];   int main() {     ios_base::sync_with_stdio(0);     const int N = 1e6 + 1;     int n;     cin >> n;     int a[n + 1];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     a[n] = N;     for (int i = 2; i < N; i++) {       sp[i] = i;     }     for (long long i = 2; i * i < N; i++) {       if (sp[i] == i) {         for (long long j = i * i; j < N; j += i) {           if (sp[j] == j) {             sp[j] = i;           }         }       }     }     int ans = 0;     for (int i = 1, j = 0; i < N; i++) {       int num = i;       int maxi = 0;       while (num > 1) {         maxi = max(maxi, dp[i / sp[num]]);         num /= sp[num];       }       dp[i] = maxi;       if (i == a[j]) {         dp[i]++;         j++;       }       ans = max(ans, dp[i]);     }     cout << ans;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, c = 0;     cin >> n >> x;     int j = 1;     for (int i = 0; i < n; i++) {       int r, l;       cin >> r >> l;       c += l - r + 1;       while (j + x <= r) {         j += x;       }       c += r - j;       j = l + 1;     }     cout << c << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long NMAX = 1000;   pair<long long, long long> func[NMAX + 5];   pair<long long, long long> tmp_func[NMAX + 5];   long long initial[NMAX + 5];   pair<long long, long long> ans[NMAX + 5];   map<pair<long long, long long>, long long> memo;   int cnt_queries = 0;   long long singular_query(long long id, long long wh) {     if (memo.count({id, wh}) == 0) {       cout <<  ?   << id <<     << wh << endl;       cin >> memo[{id, wh}];       cnt_queries++;     }     return memo[{id, wh}];   }   void query_fun(long long fst, long long lst, long long wh) {     for (long long i = fst; i <= lst; i++) {       func[i].first = singular_query(func[i].second, wh);     }   }   void solve(long long fst, long long lst, long long l, long long r,              long long buck) {     if (fst == lst) {       ans[func[fst].second] = {l, r};       return;     }     long long target_split = (lst + fst) / 2;     long long st = l + 1LL * (target_split - fst + 1) * buck - 1,               dr = r - 1LL * (lst - target_split) * buck + 1;     while (dr - st > 1) {       long long mid = (st + dr) / 2;       for (long long i = fst; i <= lst; i++) {         map<pair<long long, long long>, long long>::iterator it =             memo.lower_bound({func[i].second, mid});         if (it != memo.end() && it->first.first == func[i].second &&             it->second - initial[func[i].second] <                 buck * (target_split - fst + 1)) {           func[i].first = it->second;         } else if (it != memo.begin()) {           it--;           if (it->first.first == func[i].second &&               it->second - initial[func[i].second] >=                   buck * (target_split - fst + 1)) {             func[i].first = it->second;           } else {             func[i].first = singular_query(func[i].second, mid);           }         } else {           func[i].first = singular_query(func[i].second, mid);         }       }       sort(func + fst, func + 1 + lst,            [&](pair<long long, long long> &a, pair<long long, long long> &b) {              return a.first - initial[a.second] > b.first - initial[b.second];            });       if (func[target_split].first - initial[func[target_split].second] >=           buck * (target_split - fst + 1)) {         dr = mid;         for (long long i = fst; i <= lst; i++) {           tmp_func[i] = func[i];         }       } else {         st = mid;       }     }     for (long long i = fst; i <= lst; i++) {       func[i] = tmp_func[i];     }     for (int i = target_split + 1; i <= lst; i++) {       initial[func[i].second] += buck * (target_split - fst + 1);     }     solve(fst, target_split, l, dr, buck);     solve(target_split + 1, lst, dr, r, buck);   }   int main() {     long long n;     long long l;     scanf( %lld %lld , &n, &l);     for (long long i = 1; i <= n; i++) {       func[i] = {0, i};       memo[{i, 0}] = 0;       memo[{i, 1e18}] = l;     }     solve(1, n, 0, 1e18, l / n);     cout <<  !  << endl;     for (long long i = 1; i <= n; i++) {       cout << ans[i].first <<     << ans[i].second << endl;     }     cerr <<  total queries   << cnt_queries << endl;     return 0;   }


#include<bits/stdc++.h>   using namespace std;   typedef long long ll;   const int maxn = 1e6+5;   const int mod = 1e9+7;   const int inf = 0x3f3f3f3f;   #define for1(i,n) for(int i=1;i<=n;i++)   #define forn(i,n) for(int i=0;i<n;i++)      int a[maxn], n,m;   ll add[maxn];   vector<ll> ans;   void dfs(int L, int R){       int mid = (a[L]+a[R])>>1;       int idx = upper_bound(a+L,a+R+1,mid) - a;           //printf( [%d %d], [%d %d] n ,L,idx-1,idx,R);       //printf( [%d %d] n ,L,R);       ans.push_back(add[R]-add[L-1]);       //ans.push_back(add[R]-add[idx-1]);       if(idx>R) return;       if(L<=idx-1) dfs(L,idx-1);        if(idx<=R) dfs(idx,R);   }   int main(){       int t; scanf( %d ,&t);while(t--){           ans.clear();                scanf( %d%d ,&n,&m);           for1(i,n){               scanf( %d ,&a[i]);           }           sort(a+1,a+n+1);           for1(i,n) add[i] = add[i-1] + a[i];           //int L=1, R=n;           dfs(1,n);           //for(auto v : ans) cout << v << endl;           sort(ans.begin(),ans.end());           for1(i,m){               int q; scanf( %d ,&q);               if(binary_search(ans.begin(),ans.end(),q)) printf( Yes n );               else printf( No n );           }       }   }   /*2   5 5   1 2 3 4 5   1   8   9   12   6   5 5   3 1 3 1 3   1   2   3   9   11   */


#include <bits/stdc++.h>   using namespace std;   int n;   string s1, s2;   int main() {     cin >> n;     if (n == 1) {       cout <<  a na nb nb ;       return 0;     }     s1 = s2 =   ;     int m = n;     while (m > 1) {       if (s1 ==    || s1[s1.size() - 1] ==  b )         s1 +=  aa ;       else         s1 +=  bb ;       m -= 2;     }     if (m) s1 +=  e ;     cout << s1 << endl;     for (char i : s1) {       if (i ==  a )         cout <<  c ;       else if (i ==  b )         cout <<  d ;       else         cout <<  e ;     }     s2 =  z ;     n -= 1;     cout << endl;     while (n > 1) {       if (s2[s2.size() - 1] ==  z  || s2[s2.size() - 1] ==  x )         s2 +=  yy ;       else         s2 +=  xx ;       n -= 2;     }     if (n) s2 +=  k ;     cout << s2 << endl;     for (char i : s2) {       if (i ==  x )         cout <<  y ;       else if (i ==  y )         cout <<  x ;       else         cout << i;     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   int s[1005];   int us[1005];   int t[1005];   int ut[1005];   int a[1005];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &s[i]);       us[s[i]]++;     }     for (int i = 0; i < n; i++) {       scanf( %d , &t[i]);       ut[t[i]]++;     }     int t1 = 0;     for (int i = 1; i <= n; i++) {       if (us[i] == 0) {         t1 = i;       }     }     vector<int> dif;     for (int i = 0; i < n; i++) {       a[i] = s[i];       if (us[s[i]] == 2) {         dif.push_back(i);       }     }     int tmp;     for (auto i : dif) {       tmp = a[i];       a[i] = t1;       int cnt = 0;       for (int j = 0; j < n; j++) {         if (a[j] != t[j]) cnt++;       }       if (cnt == 1) {         for (int j = 0; j < n; j++) {           printf( %d%c , a[j], (   n [j == n - 1]));         }         return 0;       }       a[i] = tmp;     }   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-10;   const double PI = atan(1.0) * 4;   const int inf = 2147483647 / 2;   const int maxn = 207;   const int maxs = 20;   const int mod = 1000000007;   template <class T>   bool chmin(T &a, const T &b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool chmax(T &a, const T &b) {     return b > a ? a = b, 1 : 0;   }   template <class T>   int sgn(T first) {     return (first > eps) - (first < -eps);   }   int M, K;   int dig_l[205], dig_r[205];   int d[205][205][505];   inline void add(int &a, int b) {     a += b;     if (a >= mod) a -= mod;   }   struct nod {     nod *ch[maxs], *f;     nod *jump[maxs];     int v;     nod *go(int c);   } * bat;   nod *nod::go(int c) {     if (ch[c] == 0)       ch[c] = bat++, memset(ch[c]->ch, 0, sizeof(ch[c]->ch)), ch[c]->v = 0;     return ch[c];   }   struct AC {     nod an[maxn], *rt, *q[maxn];     void newnod(nod *&o) {       o = bat++;       memset(o->ch, 0, sizeof(o->ch));       o->v = 0;     }     void init() {       bat = an;       newnod(rt);     }     int idx(nod *first) { return first - an; }     void insert(int *s, int n, int v) {       nod *first = rt;       for (int i = (0); i <= (int)(n - 1); i++) first = first->go(s[i]);       first->v += v;     }     void build() {       int ql = 0, qr = 0;       q[qr++] = rt;       while (ql != qr) {         nod *first = q[ql++];         for (int c = (0); c <= (int)(maxs - 1); c++) {           nod *v = first->ch[c];           if (!v) continue;           nod *last = first->f;           while (last && last->ch[c] == 0) last = last->f;           if (last)             v->f = last->ch[c];           else             v->f = rt;           q[qr++] = v;         }       }       for (int i = (0); i <= (int)(maxs - 1); i++)         rt->jump[i] = rt->ch[i] ? rt->ch[i] : rt;       for (int i = (1); i <= (int)(qr - 1); i++) {         nod *first = q[i];         for (int j = (0); j <= (int)(maxs - 1); j++)           if (first->ch[j])             first->jump[j] = first->ch[j];           else             first->jump[j] = first->f->jump[j];       }       for (int i = (0); i <= (int)(qr - 1); i++) {         nod *first = q[i];         if (first->f) first->v += first->f->v;       }     }     int dfs(int p, nod *u, int k, bool first, bool sl, bool sr) {       if (p == -1) return 1;       int safe = !(sl || sr);       int s = idx(u);       if (safe && ~d[p][s][k]) return d[p][s][k];       int ret = 0;       for (int i = (0); i <= (int)(M - 1); i++) {         if (sl && i < dig_l[p]) continue;         if (sr && i > dig_r[p]) continue;         nod *v = u;         if (!first || i) v = u->jump[i];         if (k + v->v <= K)           add(ret, dfs(p - 1, v, k + v->v, first && (!i), sl && i == dig_l[p],                        sr && i == dig_r[p]));       }       return safe ? d[p][s][k] = ret : ret;     }   } gao;   int td[205];   int main() {     int n;     while (~scanf( %d%d%d , &n, &M, &K)) {       int l1, l2;       scanf( %d , &l1);       for (int i = (l1 - 1); i >= (int)(0); i--) scanf( %d , dig_l + i);       scanf( %d , &l2);       for (int i = (l2 - 1); i >= (int)(0); i--) scanf( %d , dig_r + i);       while (l1 < l2) dig_l[l1++] = 0;       gao.init();       for (int i = (0); i <= (int)(n - 1); i++) {         int l, val;         scanf( %d , &l);         for (int j = (0); j <= (int)(l - 1); j++) scanf( %d , td + j);         scanf( %d , &val);         gao.insert(td, l, val);       }       gao.build();       memset(d, -1, sizeof(d));       printf( %d n , gao.dfs(l2 - 1, gao.rt, 0, 1, 1, 1));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   const int INF = 0x3f3f3f3f;   const int iinf = 1 << 30;   const long long linf = 2e18;   const int MOD = 1000000007;   void print(int x) {     cout << x << endl;     exit(0);   }   void PRINT(string x) {     cout << x << endl;     exit(0);   }   void douout(double x) { printf( %lf n , x + 0.0000000001); }   char s[N], t[N];   int nxt[N], val[N], f[N], sum[N];   int n, m;   signed main() {     scanf( %s , s + 1);     scanf( %s , t + 1);     n = strlen(s + 1);     m = strlen(t + 1);     nxt[1] = 0;     for (int i = 2, j = 0; i <= m; i++) {       while (j && t[i] != t[j + 1]) j = nxt[j];       if (t[i] == t[j + 1]) j++;       nxt[i] = j;     }     for (int i = 1, j = 0; i <= n; i++) {       while (j && s[i] != t[j + 1]) j = nxt[j];       if (s[i] == t[j + 1]) j++;       if (j == m) {         val[i] = i - m + 1;         j = nxt[j];       }     }     for (int i = 1; i <= n; i++)       if (!val[i]) val[i] = val[i - 1];     for (int i = 1; i <= n; i++) {       f[i] = f[i - 1];       if (val[i]) f[i] = (f[i] + sum[val[i] - 1] + val[i]) % MOD;       sum[i] = (sum[i] + sum[i - 1] + f[i]) % MOD;     }     printf( %d n , f[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, n, m, a[15], ans, b[10010];   char s[15][10010];   struct P {     int val, id;   } p[10010];   inline bool cmp(P x, P y) { return x.val < y.val; }   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d%d , &n, &m);       ans = 0;       for (int i = 0; i < n; i++) scanf( %d , &a[i]);       for (int i = 0; i < n; i++) scanf( %s , s[i] + 1);       for (int i = 0; i < 1 << n; i++) {         int sum = 0;         for (int j = 1; j <= m; j++) {           p[j].val = 0;           p[j].id = j;         }         for (int j = 0; j < n; j++) {           if (i & (1 << j)) {             sum += a[j];             for (int k = 1; k <= m; k++)               if (s[j][k] ==  1 ) p[k].val--;           } else {             sum -= a[j];             for (int k = 1; k <= m; k++)               if (s[j][k] ==  1 ) p[k].val++;           }         }         sort(p + 1, p + m + 1, cmp);         for (int j = 1; j <= m; j++) sum += j * p[j].val;         if (sum >= ans) {           ans = sum;           for (int j = 1; j <= m; j++) b[p[j].id] = j;         }       }       for (int i = 1; i <= m; i++) printf( %d  , b[i]);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int W, H;     while (cin >> W >> H) {       vector<pair<int, int>> pset;       for (int dy = 0; dy < (int)(2); ++dy)         for (int dx = 0; dx < (int)(2); ++dx) {           if (dx <= W && dy <= H) pset.push_back(pair<int, int>(dx, dy));         }       for (int dy = 0; dy < (int)(2); ++dy)         for (int dx = 0; dx < (int)(2); ++dx) {           if (dx <= W && H - dy >= 0) pset.push_back(pair<int, int>(dx, H - dy));         }       for (int dy = 0; dy < (int)(2); ++dy)         for (int dx = 0; dx < (int)(2); ++dx) {           if (W - dx >= 0 && dy <= H) pset.push_back(pair<int, int>(W - dx, dy));         }       for (int dy = 0; dy < (int)(2); ++dy)         for (int dx = 0; dx < (int)(2); ++dx) {           if (W - dx >= 0 && H - dy >= 0)             pset.push_back(pair<int, int>(W - dx, H - dy));         }       sort(pset.begin(), pset.end());       pset.erase(unique(pset.begin(), pset.end()), pset.end());       vector<pair<double, vector<pair<int, int>>>> ans;       for (int comb = (1 << 4) - 1; comb < (1 << pset.size());) {         vector<pair<int, int>> ps;         for (int i = 0; i < (int)(pset.size()); ++i)           if (comb >> i & 1) {             ps.push_back(pset[i]);           }         sort(ps.begin(), ps.end());         do {           double len = 0;           for (int i = 0; i < (int)(3); ++i) {             len += hypot(ps[i].first - ps[i + 1].first,                          ps[i].second - ps[i + 1].second);           }           ans.push_back(make_pair(len, ps));         } while (next_permutation(ps.begin(), ps.end()));         int x = comb & -comb, y = comb + x;         comb = ((comb & ~y) / x >> 1) | y;       }       sort(ans.begin(), ans.end());       vector<pair<int, int>> ps = ans.back().second;       for (int i = 0; i < (int)(4); ++i) {         cout << ps[i].first <<     << ps[i].second << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void print(vector<int> v) {     size_t sz = v.size();     for (int i : v) {       cout << i <<    ;     }   }   vector<int> a, b, c;   int main(void) {     int n, m;     scanf( %d , &n);     a.resize(n);     int x;     for (unsigned i = 0; i < n; i++) {       scanf( %d , &x);       a[i] = x;       c.push_back(x);     }     scanf( %d , &m);     b.resize(m);     for (unsigned i = 0; i < m; i++) {       scanf( %d , &x);       b[i] = x;       c.push_back(x);     }     int a1 = 0, a2 = 0;     int ans = INT_MIN;     int co = m + n;     sort(a.begin(), a.end());     sort(b.begin(), b.end());     sort(c.begin(), c.end());     c.push_back(c[co - 1] + 1);     co++;     int i = 0;     for (i = 0; i < co; i++) {       int p1, p2 = 0;       int val = c[i] - 1;       int l = 0, h = n - 1, mid;       while (l <= h) {         mid = (l + h) / 2;         if (a[mid] <= val)           l = mid + 1;         else           h = mid - 1;       }       p1 = 3 * (n - l) + 2 * l;       l = 0;       h = m - 1;       while (l <= h) {         mid = (l + h) / 2;         if (b[mid] <= val)           l = mid + 1;         else           h = mid - 1;       }       p2 = 3 * (m - l) + 2 * l;       if ((p1 - p2) > ans) {         ans = p1 - p2;         a1 = p1;         a2 = p2;       } else if ((p1 - p2) == ans) {         if (p1 > a1) {           a1 = p1;           a2 = p2;         }       }     }     printf( %d:%d , a1, a2);   }


#include <bits/stdc++.h>   int main() {     int count;     std::vector<int> visitors;     std::cin >> count;     for (int i = 0; i < 2 * count; ++i) {       int value;       std::cin >> value;       visitors.push_back(value);     }     int counter = 0;     for (int i = 0; i < 2 * count; i += 2) {       if (visitors[i] != visitors[i + 1]) {         for (int j = 2 * count - 1; j > i + 1; j--) {           if (visitors[j] == visitors[i]) {             for (int k = j; k > i + 1; k--) {               std::swap(visitors[k], visitors[k - 1]);               counter++;             }             break;           }         }       }     }     std::cout << counter << std::endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<vector<int>> v(n);     int mat[4][4] = {         {8, 9, 1, 13}, {3, 12, 7, 5}, {0, 2, 4, 11}, {6, 10, 15, 14}};     int ans[n][n];     for (int i = 0; i < n * n; i++) {       int x = i / n;       v[x].push_back(i);     }     int count = 0;     for (int i = 0; i < n; i += 4) {       for (int j = 0; j < n; j += 4) {         for (int k = i; k < i + 4; k++) {           for (int l = j; l < j + 4; l++) {             ans[k][l] = count++;           }         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (j == 0)           cout << ans[i][j];         else           cout <<     << ans[i][j];       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int A[maxn], MAX = 0;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> A[i];     sort(A, A + n);     int ans = 0;     for (int i = 0; i < n; i++)       if (ans * A[i] + ans <= i) ans++;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, q, i, s1, s[100010], a[100010], k[100010], t, at, dp, sum, now;   bool cmp(long long a, long long b) { return a > b; }   int main() {     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];     }     cin >> q;     for (i = 0; i < q; i++) {       cin >> k[i];     }     sort(a, a + n, cmp);     s[0] = 0;     for (i = 0; i < n; i++) {       s[i + 1] = s[i] + a[i];     }     s1 = 0;     for (i = 0; i < n; i++) {       s1 += a[i] * i;     }     for (i = 0; i < q; i++) {       if (i != 0) cout <<    ;       if (k[i] == 1) {         cout << s1;         continue;       }       t = 1;       dp = 1;       now = k[i];       sum = 0;       while (t + now < n) {         at = s[t + now] - s[t];         at = at * dp;         sum += at;         t = t + now;         now = now * k[i];         dp++;       }       at = s[n] - s[t];       at = at * dp;       sum += at;       cout << sum;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000 + 5;   int arr[maxn][maxn];   int main() {     int m, n, k, p, sum = 0;     bool bol = false;     cin >> n >> m >> k;     if (n % 2 != m % 2) {       cout << 0 << endl;       return 0;     }     if (m > n) {       bol = true;       swap(n, m);     }     for (int i = 0; i < k; i++) {       int x, y, z;       cin >> x >> y >> z;       if (bol) swap(x, y);       arr[x - 1][y - 1] = z;     }     cin >> p;     for (int i = 0, x, tmp; i < n; i++) {       x = 0;       tmp = 1;       for (int j = 0; j < m; j++) {         tmp *= arr[i][j];         if (arr[i][j]) x++;       }       if (x != m)         sum += m - x - 1;       else if (tmp != -1) {         cout << 0 << endl;         return 0;       }     }     sum -= m - 1;     int ans = 1;     for (int i = 0; i < sum; i++) {       ans *= 2;       ans %= p;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   const long long INF = 1e17, N = 2e5 + 1;   using namespace std;   int a[N], n, m, k, sum[N], t[N];   int getime(int idx) { return min(idx, n - idx + 1); }   int getlen(int l, int r) {     if (l > r) swap(l, r);     int tmp = (r - l) / m;     if ((r - l) % m != 0) tmp++;     return tmp;   }   int f(int tmp) {     for (int i = 1; i <= n; i++) {       sum[i] = 0;     }     for (int i = 1; i <= n; i++) {       a[i] = t[i];     }     int idx = 1;     for (int i = (n / 2) - tmp + 1; i <= ((n + 1) / 2) + tmp; i++) {       while (sum[i] != k && idx <= n) {         if (a[idx] == 0 || getlen(idx, i) > getime(i)) {           idx++;         } else {           int tmp = min(k - sum[i], a[idx]);           a[idx] -= tmp;           sum[i] += tmp;         }       }       if (sum[i] != k) {         return 0;       }     }     return 1;   }   int main() {     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       cin >> t[i];     }     int l = 0, r = n / 2;     while (l != r) {       int mid = (l + r + 1) >> 1;       if (f(mid)) {         l = mid;       } else {         r = mid - 1;       }     }     cout << (n / 2) - l;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> tree;   void build(vector<long long> &arr, long long ind, long long l, long long r) {     if (l == r) {       tree[ind] = arr[l];       return;     }     long long mid = (l + r) / 2;     build(arr, ind * 2, l, mid);     build(arr, ind * 2 + 1, mid + 1, r);     tree[ind] = max(tree[ind * 2], tree[ind * 2 + 1]);   }   long long getMax(long long ind, long long tl, long long tr, long long l,                    long long r) {     if (l > r) return 0;     if (l == tl && r == tr) return tree[ind];     long long tm = (tl + tr) / 2;     long long a = getMax(ind * 2, tl, tm, l, min(r, tm));     long long b = getMax(ind * 2 + 1, tm + 1, tr, max(l, tm + 1), r);     return max(a, b);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n;     cin >> n;     vector<long long> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     long long count = 1;     for (int i = n - 2; i >= 0; i--) {       if (a[i] < a[i + 1]) {         count++;       } else {         break;       }     }     cout << n - count;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[26] = {0};     string s;     cin >> s;     transform(s.begin(), s.end(), s.begin(), ::tolower);     for (int i = 0; i < n; i++) arr[s[i] -  a ]++;     for (int i = 0; i < 26; i++) {       if (arr[i] == 0) {         puts( NO );         return 0;       }     }     puts( YES );   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const double pi = acos(-1);   int n, i, j, k, t;   long double a[100004], b[100004], val[100003];   int x[100004], c[100003];   vector<int> adj[100005];   int par[100003];   bool bisa = true;   void dfs(int v, int p) {     val[v] = b[v] - a[v];     for (int x : adj[v]) {       if (x != p) {         dfs(x, v);         if (val[x] > 0)           val[v] += val[x];         else           val[v] += val[x] * c[x];       }     }     if (val[v] < 0 && fabsl(val[v]) > 1e17L / c[v]) {       puts( NO );       exit(0);     }   }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; ++i) scanf( %Lf , b + i);     for (i = 1; i <= n; ++i) scanf( %Lf , a + i);     for (i = 2; i <= n; ++i) {       scanf( %d %d , x + i, c + i);       adj[x[i]].push_back(i);       adj[i].push_back(x[i]);     }     dfs(1, 1);     puts(val[1] >= 0 ?  YES  :  NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }   long long lcm(long long a, long long b) { return (a * (b / gcd(a, b))); }   long long bigmod(long long b, long long p, long long m) {     if (p == 0) return 1;     if (p % 2 == 0) {       long long temp = bigmod(b, p / 2, m);       return (temp * temp) % m;     }     return (bigmod(b, p - 1, m) * (b % m)) % m;   }   char inp[10010];   string scan() {     scanf( %s , inp);     string s;     for (int i = 0; inp[i]; i++) s += inp[i];     return s;   }   vector<vector<int> > v;   vector<bool> visited;   int visit[100];   void dfs(int node) {     visit[node] = 1;     for (int i = 0; i < (int)v[node].size(); i++)       if (!visit[v[node][i]]) dfs(v[node][i]);   }   int connectedcomponenetscnt(int head) {     int cnt = 0;     for (int i = 1; i < 500; i++) {       if (!visit[i]) {         dfs(i);         cnt++;       }     }     return cnt;   }   int com(string s, string t) {     for (int i = 0; i < min(s.length(), t.length()); i++) {       if (s[i] > t[i]) return 1;       if (s[i] < t[i]) return 0;     }     if (s.length() > t.length()) return 1;     return 0;   }   int n, m, x;   int a[1001];   int memo[1001][1001][2];   int dp(int i, int sum, int k) {     if (sum % m == 0 && k) return 1;     if (i == m) return 0;     int &ret = memo[i][sum][k];     if (ret != -1) return ret;     ret = 0;     for (int j = 0; j <= a[i]; j++) {       if (j > 0 || k)         ret = ret + dp(i + 1, (sum + i * j) % m, 1);       else         ret = ret + dp(i + 1, (sum + i * j) % m, 0);     }     return ret;   }   int main() {     memset(memo, -1, sizeof(memo));     memset(a, 0, sizeof(a));     cin >> n >> m;     int yes = 0;     for (int i = 0; i < n; i++) {       scanf( %d , &x);       x = x % m;       if (x == 0) yes = 1;       a[x]++;     }     for (int i = 1; i < m; i++)       if (a[i] >= m) yes = 1;     if (yes)       cout <<  YES ;     else if (dp(1, 0, 0))       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   template <class Q>   Q _min(Q x, Q y) {     return x < y ? x : y;   }   template <class Q>   Q _max(Q x, Q y) {     return x > y ? x : y;   }   set<long long int> S;   long long int a[1005][1005], b[1005][1005];   long long int lights[1005000];   long long int ans = 0, lreg;   long long int tn;   long long int T[4200000], bj[4200000], dep[4200000];   void up(long long int x) {     long long int i;     for (i = x >> 1; i; i >>= 1) T[i] = _min(T[i << 1], T[i << 1 | 1]);   }   void seta(long long int x, long long int b) {     if (b < T[x]) return;     T[x] = bj[x] = b;   }   void down(long long int x) {     long long int i, v;     for (i = dep[x]; i; i--) {       v = x >> i;       if (bj[v]) {         seta(v << 1, bj[v]);         seta(v << 1 | 1, bj[v]);         bj[v] = 0;       }     }   }   long long int f_s(long long int s, long long int t) {     for (; s ^ t ^ 1; s >>= 1, t >>= 1)       if (~s & 1) return s ^ 1;     return 0;   }   long long int f_t(long long int s, long long int t) {     for (; s ^ t ^ 1; s >>= 1, t >>= 1)       if (t & 1) return t ^ 1;     return 1;   }   void change(long long int l, long long int r, long long int L) {     long long int s = l + tn - 1, t = r + tn + 1;     long long int ss = f_s(s, t), tt = f_t(s, t);     down(ss);     down(tt);     for (; s ^ t ^ 1; s >>= 1, t >>= 1) {       if (~s & 1) seta(s ^ 1, L);       if (t & 1) seta(t ^ 1, L);     }     up(ss);     up(tt);   }   long long int Q(long long int l, long long int r) {     long long int s = l + tn - 1, t = r + tn + 1, M = 1000000000;     long long int ss = f_s(s, t), tt = f_t(s, t);     down(ss);     down(tt);     for (; s ^ t ^ 1; s >>= 1, t >>= 1) {       if (~s & 1) M = _min(M, T[s ^ 1]);       if (t & 1) M = _min(M, T[t ^ 1]);     }     return M;   }   long long int bsc(long long int x) {     long long int l = 1, r = lreg, mid;     while (r - l > 1) {       mid = (l + r) >> 1;       if (lights[mid] < x)         l = mid;       else         r = mid;     }     if (lights[r] == x)       return r;     else       return l;   }   int main() {     long long int n, vx, vy, i, j, k, l, M;     cin >> n >> vx >> vy;     if (vx == 0) {       for (i = 1; i <= n; i++) {         M = 0;         for (j = 1; j <= n; j++) {           cin >> a[i][j];           if (a[i][j] > M) M = a[i][j];         }         ans += M;       }       cout << ans;       return 0;     } else if (vy == 0) {       for (i = 1; i <= n; i++)         for (j = 1; j <= n; j++) cin >> a[i][j];       for (j = 1; j <= n; j++) {         M = 0;         for (i = 1; i <= n; i++)           if (a[i][j] > M) M = a[i][j];         ans += M;       }       cout << ans;       return 0;     }     for (i = 0; i <= n; i++)       for (j = 0; j <= n; j++) {         if (vx > 0)           b[i][j] = vx * j - vy * i;         else           b[i][j] = vy * i - vx * j;         if (S.find(b[i][j]) == S.end())           lights[++lreg] = b[i][j], S.insert(b[i][j]);       }     sort(lights + 1, lights + lreg + 1);     for (tn = 1; tn <= lreg + lreg; tn <<= 1)       ;     tn--;     for (i = 1; i <= tn + tn + 1; i++) dep[i] = dep[i >> 1] + 1;     for (i = 0; i <= n; i++)       for (j = 0; j <= n; j++) b[i][j] = bsc(b[i][j]);     for (i = 1; i <= n; i++)       for (j = 1; j <= n; j++) cin >> a[i][j];     if (vx < 0)       i = n;     else       i = 1;     if (vy < 0)       j = n;     else       j = 1;     for (long long int cnt = 1; cnt <= n * n; cnt++) {       long long int M = 1000000001;       long long int L =           _min(_min(b[i - 1][j - 1], b[i - 1][j]), _min(b[i][j - 1], b[i][j]));       long long int R =           _max(_max(b[i - 1][j - 1], b[i - 1][j]), _max(b[i][j - 1], b[i][j]));       M = Q((L << 1), (R << 1));       change((L << 1), (R << 1), a[i][j]);       if (a[i][j] > M) ans += a[i][j] - M;       if (vy < 0)         j--;       else         j++;       if (j < 1 || j > n) {         if (j < 1)           j += n;         else           j -= n;         if (vx < 0)           i--;         else           i++;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int>> vc;   vector<pair<int, int>> vc2;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       vc.push_back(make_pair(x, y));     }     vc2 = vc;     sort(vc.begin(), vc.end(),          [](const pair<int, int> &left, const pair<int, int> &right) {            if (left.first != right.first)              return left.first < right.first;            else              return left.second > right.second;          });     int mini = vc[0].first;     int maxi = vc[0].second;     for (int i = 1; i < vc.size(); i++) {       if (vc[i].first >= mini && vc[i].second <= maxi)         continue;       else {         cout << -1;         return 0;       }     }     for (int i = 0; i < vc2.size(); i++) {       if (vc2[i].first == mini && vc2[i].second == maxi) {         cout << i + 1;         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   int N, M;   int pwr[MAXN], jump[MAXN], cnt[MAXN];   int len;   void recalc(int pos) {     int nxt = pos + pwr[pos];     if (nxt < N && (nxt / len) == (pos / len)) {       jump[pos] = jump[nxt];       cnt[pos] = cnt[nxt] + 1;     } else {       jump[pos] = nxt;       cnt[pos] = 1;     }   }   int main(int argc, char *argv[]) {     scanf( %d%d , &N, &M);     for (int i = 0, _i = N; i < _i; ++i) {       scanf( %d , pwr + i);     }     len = (int)sqrt((double)N);     for (int i = N - 1; i >= 0; i--) {       recalc(i);     }     for (int i = 0, _i = M; i < _i; ++i) {       int type, a;       scanf( %d%d , &type, &a);       --a;       if (type) {         int cur = a, ret = 0;         while (true) {           ret += cnt[cur];           if (jump[cur] >= N) break;           cur = jump[cur];         }         while (cur + pwr[cur] < N) cur += pwr[cur];         printf( %d %d n , cur + 1, ret);       } else {         int b;         scanf( %d , &b);         pwr[a] = b;         int ablock = a / len;         for (int i = a; i >= 0 && (i / len) == ablock; i--) recalc(i);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e17 + 9;   double ans = 0;   vector<int> adj[100009];   int vis[100009];   double dfs(int x, double prof) {     vis[x] = 1;     double ret = 1 / prof;     for (auto e : adj[x]) {       if (vis[e] == -1) ret += dfs(e, prof + 1);     }     return ret;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     memset(vis, -1, sizeof vis);     cout << fixed << setprecision(6);     long long n;     cin >> n;     long long m = n - 1;     while (m--) {       long long a, b;       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     cout << dfs(1, 1) <<   n ;     return 0;   }


#include <bits/stdc++.h>   int a[2 * 1000010];   int main() {     int n, l, t, i, j, nn, k, left;     scanf( %d%d%d , &n, &l, &t);     nn = 2 * n;     for (i = 0; i < n; i++) scanf( %d , &a[i]);     for (i = n; i < nn; i++) a[i] = l + a[i - n];     k = 2 * t / l;     left = 2 * t - k * l;     double ans = 1.0 * (n - 1) * n * k;     for (i = 0, j = 0; i < n; i++) {       while (j < nn && a[j] - a[i] <= left) j++;       ans += j - 1 - i;     }     printf( %lf n , ans / 4);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int d = 5;   const int MAX = 1 << d;   const int TOTAL = 374;   inline int bit(unsigned int mask, int k) { return (mask >> k) & 1; }   int __builtin_fnz(unsigned int x) { return 31 - __builtin_clz(x); }   void printm(unsigned int mask, int k = d) {     for (int i = 0; i < k; ++i) printf( %d , bit(mask, i));     printf(  n );   }   int dim(unsigned int V) {     int res = 0;     for (; V != 1; ++res) V &= (1U << (1 << __builtin_fnz(__builtin_fnz(V)))) - 1;     return res;   }   unsigned int join_v(unsigned int U, int x) {     unsigned int X = U;     for (int v = 0; v < MAX; ++v)       if (bit(U, v)) X |= 1U << (v ^ x);     return X;   }   unsigned int join(unsigned int U, unsigned int V) {     unsigned int X = U;     int x;     while (V != 1) {       x = __builtin_fnz(V);       X |= join_v(X, x);       V &= (1U << (1U << __builtin_fnz(x))) - 1;     }     return X;   }   void show(unsigned int V) {     printf( %d n , dim(V));     printf( %u n , V);     printm(V, MAX);     for (int v = 0; v < MAX; ++v)       if (bit(V, v)) printm(v, d);     printf(  n );   }   const int MOD = (int)1e9 + 7;   void add(int& a, int b) {     a += b;     if (a >= MOD) a -= MOD;   }   void mult(int& a, int b) { a = (a * 1LL * b) % MOD; }   int prod(int a, int b) { return (a * 1LL * b) % MOD; }   const int N = (int)1e5;   vector<pair<int, int> > g[N];   int pref[N];   int tab[TOTAL][TOTAL];   int dp[2][TOTAL + 1];   int main() {     vector<unsigned int> subspaces;     subspaces.push_back(1);     for (int i = 0; i < d; ++i) {       vector<unsigned int> nsubspaces;       for (unsigned int U : subspaces) {         nsubspaces.push_back(U);         for (int v = (1 << i); v < (1 << (i + 1)); ++v)           nsubspaces.push_back(join_v(U, v));       }       sort((nsubspaces).begin(), (nsubspaces).end());       nsubspaces.erase(unique((nsubspaces).begin(), (nsubspaces).end()),                        nsubspaces.end());       subspaces = nsubspaces;     }     assert(TOTAL == (int)(subspaces).size());     function<int(unsigned int)> id = [&](unsigned int V) {       int i = lower_bound((subspaces).begin(), (subspaces).end(), V) -               subspaces.begin();       return i;     };     for (int i = 0; i < TOTAL; ++i)       for (int j = 0; j < TOTAL; ++j) {         if ((subspaces[i] & subspaces[j]) != 1)           tab[i][j] = TOTAL;         else           tab[i][j] = id(join(subspaces[i], subspaces[j]));       }     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < m; ++i) {       int u, v, w;       scanf( %d %d %d , &u, &v, &w);       --u;       --v;       g[u].push_back({v, w});       g[v].push_back({u, w});     }     int t = 0, nt = 1;     memset(dp[t], 0, sizeof dp[t]);     dp[t][id(1)] = 1;     memset(pref, -1, sizeof pref);     pref[0] = 0;     for (auto& [start, weight] : g[0]) {       if (pref[start] != -1) continue;       int vec = -1;       unsigned int V = 1;       function<void(int, int, bool&)> dfs = [&](int v, int par, bool& ok) {         for (auto& [u, w] : g[v]) {           if (pref[u] == -1) {             pref[u] = pref[v] ^ w;             dfs(u, v, ok);           } else {             if (u > v || u == par) continue;             int add = pref[u] ^ pref[v] ^ w;             if (u == 0) {               vec = add;             } else {               if (bit(V, add)) ok = false;               V = join_v(V, add);             }           }         }       };       pref[start] = weight;       bool ok = true;       dfs(start, 0, ok);       if (!ok) continue;       memcpy(dp[nt], dp[t], sizeof dp[t]);       int i = id(V);       if (vec == -1) {         for (int j = 0; j < TOTAL; ++j) {           add(dp[nt][tab[i][j]], dp[t][j]);         }       } else {         for (int j = 0; j < TOTAL; ++j) {           add(dp[nt][tab[i][j]], dp[t][j]);           add(dp[nt][tab[i][j]], dp[t][j]);         }         int with = id(join_v(V, vec));         if (i != with) {           V = subspaces[with];           for (int j = 0; j < TOTAL; ++j) {             add(dp[nt][tab[with][j]], dp[t][j]);           }         }       }       swap(t, nt);     }     int ans = 0;     for (int i = 0; i < TOTAL; ++i) add(ans, dp[t][i]);     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (int)(1e9 + 1337);   const long long LINF = (long long)(4e18);   const double EPS = (double)(1e-11);   int n;   int m;   int ans;   vector<vector<int> > g;   vector<set<int> > s;   vector<set<int> > fbd;   int a[1000010];   void dfs(int v, int p) {     int cur = 1;     for (auto &it : s[v]) {       if (a[it] != -1) fbd[v].insert(a[it]);     }     for (auto &it : s[v]) {       if (a[it] != -1) continue;       while (fbd[v].count(cur)) cur++;       ans = max(ans, cur);       a[it] = cur;       cur++;     }     for (int i = 0; i < (int)g[v].size(); i++) {       int to = g[v][i];       if (p == to) continue;       dfs(to, v);     }   }   void solve() {     cin >> n >> m;     g.resize(n + 1);     s.resize(n + 1);     fbd.resize(n + 1);     int tk = 0;     for (int i = 1; i <= n; i++) {       int k;       cin >> k;       tk = max(k, tk);       for (int j = 0; j < k; j++) {         int tt;         cin >> tt;         s[i].insert(tt);       }     }     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       g[a].push_back(b);       g[b].push_back(a);     }     memset(a, -1, sizeof a);     dfs(1, 0);     if (ans == 0) ans = 1;     cout << ans <<   n ;     for (int i = 1; i <= m; i++) {       if (a[i] == -1) a[i] = 1;       cout << a[i] <<    ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     int l, r, t, c;     int res = 0;     cin >> n >> m;     n++;     int a[n];     int b[n];     for (int i = 0; i < n; i++) {       a[i] = 10000;       b[i] = 0;     }     while (m--) {       cin >> l >> r >> t >> c;       for (int i = l; i <= r; i++) {         if (a[i] > t) {           a[i] = t;           b[i] = c;         }       }     }     for (int i = 0; i < n; i++) {       res += b[i];     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long MAX_N = 5e3 + 5;   struct edge {     long long to;     long long w;     long long idx;   };   long long cidx;   long long vr1, vr2;   long long vw;   vector<edge> adj[MAX_N];   long long vis[MAX_N];   pair<long long, long long> dp[MAX_N];   long long n;   void dfs(long long x) {     if (vis[x]) {       return;     }     vis[x] = 1;     for (auto e : adj[x]) {       if (e.idx == cidx) {         vr1 = x;         vr2 = e.to;         vw = e.w;         continue;       }       dfs(e.to);     }   }   pair<long long, long long> dfs0(long long x, long long p) {     long long cans = 0;     long long ccnt = 1;     for (auto e : adj[x]) {       if (e.idx == cidx || e.to == p) continue;       pair<long long, long long> ch = dfs0(e.to, x);       cans += ch.first;       cans += e.w * ch.second;       ccnt += ch.second;     }     return make_pair(cans, ccnt);   }   pair<long long, long long> dfs1(long long x, long long d) {     vis[x] = 1;     long long cans = 0;     long long ccnt = 1;     for (auto e : adj[x]) {       if (e.idx == cidx || vis[e.to]) continue;       pair<long long, long long> ch = dfs1(e.to, x);       cans += ch.first;       cans += e.w * ch.second;       ccnt += ch.second;     }     return dp[x] = make_pair(cans, ccnt);   }   long long mn;   long long vv;   void dfs2(long long x, long long p, long long ud, long long ucnt) {     long long acans = dp[x].first;     long long tw = ud;     long long tcnt = ucnt + 1;     if (dp[x].first + ud < mn) {       mn = dp[x].first + ud;       vv = x;     }     for (auto e : adj[x]) {       if (e.idx == cidx || e.to == p) {         continue;       }       tcnt += dp[e.to].second;       tw += dp[e.to].first + e.w * dp[e.to].second;     }     for (auto e : adj[x]) {       if (e.idx == cidx || e.to == p) {         continue;       }       long long ctcnt = tcnt - dp[e.to].second;       long long ctw =           dp[x].first + ud - dp[e.to].first - e.w * dp[e.to].second + ctcnt * e.w;       dfs2(e.to, x, ctw, ctcnt);     }   }   long long bidx;   pair<long long, long long> gans(long long x, long long p) {     long long cans = 0;     long long ccnt = 1;     for (auto e : adj[x]) {       if (e.to == p || e.idx == bidx) {         continue;       }       pair<long long, long long> ch = gans(e.to, x);       cans += ch.first;       cans += ch.second * e.w;       ccnt += ch.second;     }     return make_pair(cans, ccnt);   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     long long u, v, w;     for (long long i = 1; i < n; i++) {       cin >> u >> v >> w;       adj[u].push_back({v, w, i});       adj[v].push_back({u, w, i});     }     long long aidx = 1;     long long va1 = 1, va2 = 2;     long long mimp = -1;     long long bw = 0;     long long var1, var2;     for (long long i = 1; i < n; i++) {       cidx = i;       memset(vis, 0, sizeof(vis));       dfs(1);       long long r1 = vr1;       long long r2 = vr2;       memset(dp, 0, sizeof(dp));       memset(vis, 0, sizeof(vis));       dfs1(r1, 0);       dfs1(r2, 0);       auto res1 = dp[r1];       auto res2 = dp[r2];       long long pans = res1.second * (vw * res2.second + res2.first) +                        res1.first * res2.second;       mn = 1e18;       dfs2(r1, -1, 0, 0);       long long mn1 = mn;       long long mnr1 = vv;       mn = 1e18;       dfs2(r2, -1, 0, 0);       long long mn2 = mn;       long long mnr2 = vv;       long long nans = res1.second * (vw * res2.second + mn2) + mn1 * res2.second;       long long imp = pans - nans;       if (imp > mimp) {         mimp = imp;         va1 = vr1;         va2 = vr2;         var1 = mnr1;         var2 = mnr2;         bidx = cidx;         bw = vw;       }     }     adj[var1].push_back({var2, bw, n});     adj[var2].push_back({var1, bw, n});     long long ans = 0;     for (long long i = 1; i <= n; i++) {       ans += gans(i, -1).first;     }     cout << ans / 2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long max(long long x, long long y) { return x > y ? x : y; }   long long min(long long x, long long y) { return x < y ? x : y; }   void _(long long& a, long long b) {     a = (a % 1000000007 + b % 1000000007) % 1000000007;     a = (a + 1000000007) % 1000000007;   }   long long cl(long long a, long long b) { return (a / b) + (!(!(a % b))); }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     string s, t;     cin >> s >> t;     long long a, b;     a = b = 0;     for (long long i = 0; i < s.size(); ++i) {       a += s[i] ==  1 ;     }     for (long long i = 0; i < t.size(); ++i) {       b += t[i] ==  1 ;     }     if (a + (a & 1) >= b)       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s;     scanf( %d %d , &n, &s);     long long arr[n];     for (int i = 0; i < n; i++) scanf( %lld , &arr[i]);     sort(arr, arr + n);     long long val = arr[n / 2];     long long cnt = abs(s - val);     for (int i = 0; i < (n / 2); i++) {       if (arr[i] > s) {         cnt += abs(arr[i] - s);       }     }     for (int i = (n / 2) + 1; i < n; i++) {       if (arr[i] < s) {         cnt += abs(arr[i] - s);       }     }     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100;   const int inf = 0x3f3f3f3f;   const int mod = 1e9 + 7;   void MOD(int &x) {     if (x >= mod) x -= mod;   }   void MOD(long long &x) {     if (x >= mod) x -= mod;   }   long long powmod(long long x, long long n) {     long long ret = 1;     for (; n > 0; n >>= 1, x = x * x % mod)       if (n & 1) ret = ret * x % mod;     return ret;   }   int n, m, k;   vector<pair<int, int> > v[maxn];   bool vis[maxn];   struct edge {     int x, y, w;     long long sta;   } E[maxn];   int cnt = 0;   int dfs(int p, int w, int limt, long long sta) {     if (limt < w || cnt >= k) return 0;     if (p == m + 1) {       cnt++;       return 1;     }     int r = 0, u = E[p].x, v = E[p].y;     if (!(sta & E[p].sta)) {       r = dfs(p + 1, w + E[p].w, limt, sta | E[p].sta);     }     if (r >= k) return r;     r += dfs(p + 1, w, limt, sta);     return r;   }   int main() {     cin >> n >> m >> k;     for (int i = 1; i <= m; ++i) {       int x, y, w;       cin >> x >> y >> w;       E[i] = {x, y, w};       long long s = 1ll << (x + n);       s |= 1ll << y;       E[i].sta = s;     }     int l = 0, r = n * 1000;     while (l < r) {       int mid = l + r >> 1;       cnt = 0;       int x = dfs(1, 0, mid, 0);       x = cnt;       if (x >= k)         r = mid;       else         l = mid + 1;     }     cout << l <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (1e6) + 1, M = (1e7) + 1;   int n, k, a[N], dp[M];   bool check(int x) {     fill(dp + 1, dp + M, 0);     for (int i = x; i <= (1e7); i++) dp[i] = max(dp[i >> 1] + dp[i + 1 >> 1], 1);     long long sum = 0;     for (int i = 0; i < n; i++) sum += dp[a[i]];     return (sum >= k);   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) scanf( %d , a + i);     int l = 0, r = 1e7;     while (l < r) {       int mid = (l + r + 1) >> 1;       if (check(mid))         l = mid;       else         r = mid - 1;     }     if (!l)       printf( -1 );     else       printf( %d , l);   }


#include <bits/stdc++.h>   using namespace std;   void fun() {}   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     fun();     long long int c, v, u, a, l, p = 0, ans = 1;     cin >> c >> v >> u >> a >> l;     p += v;     while (p < c) {       v += a;       p += min(v, u) - l;       ans++;     }     cout << ans;     cerr <<  time elapsed :   << 1.0 * clock() / CLOCKS_PER_SEC <<   sec  n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   int sz[N];   vector<int> g[N], g2[N];   signed main() {     int n;     std::cin >> n;     int sum = 0;     vector<int> nonOnes, ones;     for (int i = 0; i < n; ++i) {       std::cin >> sz[i];       sum += sz[i];       if (sz[i] > 1) {         nonOnes.push_back(i);       } else {         ones.push_back(i);       }     }     if (sum < 2 * n - 2) {       std::cout <<  NO ;       return 0;     }     for (int i = 1; i < nonOnes.size(); ++i) {       sz[nonOnes[i - 1]]--;       sz[nonOnes[i]]--;       g[nonOnes[i - 1]].push_back(nonOnes[i]);       g2[nonOnes[i - 1]].push_back(nonOnes[i]);       g2[nonOnes[i]].push_back(nonOnes[i - 1]);     }     bool f = false, s = false;     for (auto d : ones) {       bool fl = false;       if (!f && sz[nonOnes[0]]) {         g[d].push_back(nonOnes[0]);         g2[d].push_back(nonOnes[0]);         g2[nonOnes[0]].push_back(d);         sz[nonOnes[0]]--;         f = true;         continue;       }       if (!s && sz[nonOnes.back()]) {         g[d].push_back(nonOnes.back());         g2[d].push_back(nonOnes.back());         g2[nonOnes.back()].push_back(d);         sz[nonOnes.back()]--;         s = true;         continue;       }       for (auto x : nonOnes) {         if (sz[x]) {           g[d].push_back(x);           g2[x].push_back(d);           g2[d].push_back(d);           sz[x]--;           fl = true;           break;         }       }       if (!fl) {         std::cout <<  NO ;         return 0;       }     }     int answ = 0, m = 0;     for (int i = 0; i < n; ++i) {       m += g[i].size();     }     for (int i = 0; i < n; ++i) {       vector<int> d(n, 1e9);       std::queue<int> bfs;       d[i] = 0;       bfs.push(i);       while (!bfs.empty()) {         int v = bfs.front();         bfs.pop();         for (auto e : g2[v]) {           if (d[e] > d[v] + 1) {             answ = std::max(answ, d[v] + 1);             d[e] = d[v] + 1;             bfs.push(e);           }         }       }     }     std::cout <<  YES   << answ <<   n  << m <<   n ;     for (int i = 0; i < n; ++i) {       for (auto e : g[i]) {         std::cout << i + 1 <<     << e + 1 <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1791791791;   const long long INFLL = 1791791791791791791ll;   template <int input_buf_size, int output_buf_size>   class FastIO {     char cbuf[input_buf_size + 1];     int icur = 0;     inline bool go_to_next_token() {       while (cbuf[icur] ==     || cbuf[icur] ==   n ) icur++;       while (cbuf[icur] == 0) {         icur = 0;         if (fgets(cbuf, sizeof(cbuf), stdin) != cbuf) return false;         while (cbuf[icur] ==     || cbuf[icur] ==   n ) icur++;       }       return true;     }       public:     string readString() {       assert(go_to_next_token());       string ans;       while (cbuf[icur] !=     && cbuf[icur] !=   n  && cbuf[icur] != 0)         ans.push_back(cbuf[icur++]);       ans.shrink_to_fit();       return ans;     }     template <class int_type>     int_type readInt() {       assert(go_to_next_token());       int_type x = 0;       bool m = cbuf[icur] ==  - ;       if (m) icur++;       while ( 0  <= cbuf[icur] && cbuf[icur] <=  9 ) {         x *= 10;         x += (cbuf[icur] -  0 );         icur++;       }       if (m) x = -x;       return x;     }     bool seekEof() { return !go_to_next_token(); }       private:     char obuf[output_buf_size + 1];     int ocur = 0;     inline void write_string(const char* str, size_t sz = 0) {       if (sz == 0) sz = strlen(str);       if (ocur + sz > output_buf_size) {         fputs(obuf, stdout);         fputs(str, stdout);         ocur = 0;         obuf[0] = 0;         return;       }       strcpy(obuf + ocur, str);       ocur += sz;       obuf[ocur] = 0;     }       public:     template <class int_type>     void writeInt(int_type x, bool sp = true) {       char buf[20];       int c = 0;       if (x < 0) {         buf[c++] =  - ;         x = -x;       }       int s = c;       if (x == 0) {         buf[c++] =  0 ;       }       while (x > 0) {         buf[c++] = (x % 10) +  0 ;         x /= 10;       }       for (int i = 0; 2 * i < c - s; i++) {         swap(buf[s + i], buf[c - 1 - i]);       }       buf[c] = 0;       write_string(buf, c);       if (sp) write_string(   , 1);     }     void writeString(string s, bool space = true) {       write_string(s.c_str(), s.size());       if (space) write_string(   , 1);     }     void writeEndl() { write_string(  n , 1); }     void flush() {       fputs(obuf, stdout);       ocur = 0;       obuf[0] = 0;     }       private:     bool lflush;       public:     FastIO(bool local_flush) {       obuf[0] = 0;       lflush = local_flush;     }     ~FastIO() { fputs(obuf, stdout); }   };   FastIO<10000000, 10000000> IO(true);   bool is_subsequence(const string& s, const string& t) {     int i = 0, j = 0;     while (i < (int)s.size() && j < (int)t.size()) {       if (s[i] == t[j]) j++;       i++;     }     return j == (int)t.size();   }   int main() {     string s, t;     s = IO.readString(), t = IO.readString();     int n = s.size();     vector<int> a(n);     for (int i = 0; i < ((int)(n)); ++i) a[i] = IO.readInt<int>() - 1;     int l = 0, r = n;     while (l < r - 1) {       int mid = (l + r) >> 1;       vector<int> b(a.begin() + mid, a.end());       sort((b).begin(), (b).end());       string ns;       for (int i : b) ns.push_back(s[i]);       if (is_subsequence(ns, t))         l = mid;       else         r = mid;     }     IO.writeInt(l);     IO.writeEndl();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d;     cin >> a >> b >> c >> d;     int arr[4];     arr[0] = a;     arr[1] = b;     arr[2] = c;     arr[3] = d;     int cmax = b;     if (c > b) cmax = c;     int k = 0;     if (b >= a) k++;     if (c >= d) k++;     if (a + c >= b) k++;     if (b + d >= c) k++;     int m = a + c - b - d;     int l = b + d - c - a;     if (a == 0 || b == 0 || c == 0 || d == 0) {       int ind = 0;       int brr[3], crr[3];       for (int u = 0; u < 4; u++) {         if (arr[u] != 0) {           brr[ind++] = arr[u];           crr[ind - 1] = u;         }       }       if (ind == 1 || ind == 2) {         if (ind == 1 && brr[0] == 1) {           cout <<  YES  << endl;           cout << crr[0];           return 0;         } else if (ind == 1 && brr[0] != 1) {           cout <<  NO ;           return 0;         } else {           if (crr[1] - crr[0] > 1) {             cout <<  NO ;             return 0;           } else {             if (abs(brr[1] - brr[0]) > 1) {               cout <<  NO ;               return 0;             } else {               cout <<  YES  << endl;               int ai = brr[0];               int bi = brr[1];               int ci = ai, ji = crr[1], ki = crr[0];               if (bi < ai) {                 ci = bi;                 ji = crr[0];                 ki = crr[1];               }               for (int i = 0; i < ci; i++) {                 cout << ji <<     << ki <<    ;               }               if (ai != bi) {                 cout << ji;               }               return 0;             }           }         }       } else {         int j = brr[0] + brr[2];         int u = brr[1];         for (int i = 1; i < 3; i++)           if (abs(crr[i] - crr[i - 1]) > 1) {             cout <<  NO ;             return 0;           }         if (abs(u - j) > 1) {           cout <<  NO ;           return 0;         } else {           int ii = 0;           int i = 0;           cout <<  YES  << endl;           if (u - j == 1) {             cout << crr[1] <<    ;             brr[1]--;           }           while (ii < 2) {             while (true) {               if (brr[i] == 0) break;               cout << crr[i] <<    ;               brr[i]--;               if (brr[i] == 0) break;               if (brr[i + 1] == 0) break;               cout << crr[i + 1] <<    ;               brr[i + 1]--;             }             ii++;             i++;           }           if (brr[2] == 1) {             cout << crr[2];           } else if (brr[1] == 1) {             cout << crr[1];           }           return 0;         }       }     } else if (k < 4)       cout <<  NO ;     else if (abs(m) > 1)       cout <<  NO ;     else if (abs(l) > 1)       cout <<  NO ;     else {       cout <<  YES  << endl;       int r = 0, i = 1;       bool f = false;       if ((c - d) < (b - a)) {         r = 1;         i = 0;         f = true;       }       int ii = 0;       while (ii < 3) {         while (true) {           cout << r <<    ;           arr[r]--;           if (arr[r] == 0) break;           cout << i <<    ;           arr[i]--;           if (arr[i] == 0) break;         }         ii++;         if (f) {           i = 2;           f = !f;         } else {           i++;           r++;         }       }       if (arr[2] == 1) cout <<  2 ;       if (arr[3] == 1) cout <<  3 ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, k;     cin >> n >> k;     vector<int> adj[n];     int deg[n];     for (int i = 0; i < n; i++) {       deg[i] = 0;     }     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       adj[a].push_back(b);       adj[b].push_back(a);       deg[a]++;       deg[b]++;     }     vector<int> li;     for (int i = 0; i < n; i++) {       if (deg[i] == 1) {         li.push_back(i);       }     }     for (int i = 0; i < li.size(); i++) {       int now = li[i];       for (int j = 0; j < adj[now].size(); j++) {         int to = adj[now][j];         deg[to]--;         if (deg[to] == 1) {           li.push_back(to);         }       }     }     if (li.size() != n) {       cout <<  No  << endl;       return 0;     }     bool v[n];     int deep[n];     for (int i = 0; i < n; i++) {       v[i] = false;       deep[i] = -1;     }     v[li[n - 1]] = true;     deep[li[n - 1]] = 0;     bool ok = true;     for (int i = n - 1; i >= 0; i--) {       int now = li[i];       if (!v[now] || deep[now] > k) {         ok = false;         break;       }       int red = adj[now].size();       if (i < n - 1) {         red--;       }       if (red < 3 && deep[now] != k) {         ok = false;         break;       }       for (int j = 0; j < adj[now].size(); j++) {         int to = adj[now][j];         if (!v[to]) {           v[to] = true;           deep[to] = deep[now] + 1;         }       }     }     cout << (ok ?  Yes  :  No ) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, a, k;   int x[200030], xx[200030];   bool judge(int m) {     for (int i = 1; i <= m; i++) xx[i] = x[i];     sort(xx + 1, xx + 1 + m);     int ans = 0;     xx[0] = 0;     for (int i = 1; i <= m; i++) ans += (xx[i] - xx[i - 1]) / (a + 1);     ans += (n - xx[m] + 1) / (a + 1);     return ans < k;   }   int main() {     int m;     scanf( %d%d%d , &n, &k, &a);     scanf( %d , &m);     for (int i = 1; i <= m; i++) scanf( %d , x + i);     int ans = 1 << 30;     int l = 1, r = m, mid;     while (l <= r) {       mid = (l + r) >> 1;       if (judge(mid))         ans = min(ans, mid), r = mid - 1;       else         l = mid + 1;     }     if (ans == (1 << 30)) ans = -1;     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100000;   const int inf = (int)1e9 + 1;   const long long big = (long long)1e18 + 1;   const int P = 239;   const int MOD = (int)1e9 + 7;   const int MOD1 = (int)1e9 + 9;   const double eps = 1e-9;   const double pi = atan2(0, -1);   const int ABC = 26;   int nim0[10] = {0, 1, 2, 0, 1, 0, 1, 0, 1, 0};   int nim1[10] = {0, 1, 0, 1, 2, 0, 2, 0, 1, 0};   int get0(int x) {     if (x < 10)       return nim0[x];     else       return (x % 2 == 0 ? 1 : 0);   }   int get1(int x) {     if (x < 10)       return nim1[x];     else {       if (x % 2 == 1) return 0;       int tmp = get1(x / 2);       int ans = 0;       while (ans == 0 || ans == tmp) ans++;       return ans;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.precision(20);     int n, k;     cin >> n >> k;     int ans = 0;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       if (k % 2 == 0)         ans ^= get0(x);       else         ans ^= get1(x);     }     cout << (ans ?  Kevin n  :  Nicky n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M;   int used[10];   int main() {     cin >> N >> M;     int len1 = 1, len2 = 1;     for (int a = 7; a < N; a *= 7) {       ++len1;     }     for (int b = 7; b < M; b *= 7) {       ++len2;     }     int answer = 0;     if (len1 + len2 <= 7) {       for (int i = 0; i != N; ++i) {         for (int j = 0; j != M; ++j) {           for (int k = 0; k <= 6; ++k) {             used[k] = 0;           }           for (int a = i, k = 0; k != len1; ++k, a /= 7) {             used[a % 7]++;           }           for (int b = j, k = 0; k != len2; ++k, b /= 7) {             used[b % 7]++;           }           int mx = 0;           for (int i = 0; i < 7; ++i) {             mx = max(mx, used[i]);           }           if (mx < 2) {             ++answer;           }         }       }     }     cout << answer <<   n ;     return 0;   }


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


#include<bits/stdc++.h>   using namespace std;   #define int long long   const int maxn = 2000005;   int tag[maxn],summ[maxn];   int len[maxn];   int n,k;   void push_up(int p){    summ[p] = summ[p<<1] + summ[p<<1|1];   }   void push_down(int p,int l,int r){    if(tag[p] == 0) return;    int x = tag[p];    tag[p] = 0; int mid = (l+r)>>1;    tag[p<<1] += x,tag[p<<1|1] += x;    summ[p<<1] += x * (mid - l + 1);    summ[p<<1|1] += x * (r - mid);   }   void build(int l,int r,int p)   {    tag[p] = 0;    if(l == r){     if(l == 1) summ[p] = 1;     else summ[p] = 0;     return;    }    int mid = (l+r)>>1;    build(l,mid,p<<1);    build(mid+1,r,p<<1|1);    push_up(p);   }   void gai(int l,int r,int p,int ll,int rr,int z){    if(ll > rr) return;    if(l != r) push_down(p,l,r);    if(ll <= l && r <= rr){     summ[p] += (r - l + 1) * z;     tag[p] += z;     if(l != r) push_down(p,l,r);     return;    }    int mid = (l+r)>>1;    if(ll <= mid) gai(l,mid,p<<1,ll,rr,z);    if(rr > mid) gai(mid+1,r,p<<1|1,ll,rr,z);    push_up(p);   }   int cha(int l,int r,int p,int z){   // printf( %lld %lld %lld n ,l,r,summ[p]);    if(l == r) return l;    else push_down(p,l,r);    int mid = (l+r)>>1;    if(z <= summ[p<<1]){     return cha(l,mid,p<<1,z);//第z小    }    z -= summ[p<<1];    return cha(mid+1,r,p<<1|1,z);   }   void chong(int l,int r,int p)   {    if(l == r) return;    push_down(p,l,r);    int mid = (l+r)>>1;    chong(l,mid,p<<1);    chong(mid+1,r,p<<1|1);   }   signed main()   {    scanf( %lld%lld ,&n,&k);    for(int i=1;i<=n;++i) scanf( %lld ,&len[i]);    sort(len + 1,len + n + 1);    reverse(len + 1,len + n + 1);    build(1,300000,1);    int ans = 1e9;   // for(int i=1;i<=n;++i) printf( %lld  ,len[i]);   // return 0;    for(int i=1;i<=n+1;++i){    // printf(  n n );     if(summ[1] >= k)     {      int ak = cha(1,300000,1,k);      ans = min(ans,ak);      //printf( %lld n ,ak);     }     if(n == i - 1) break;    // chong(1,300000,1);     int akk = cha(1,300000,1,1);     gai(1,300000,1,akk,akk,-1);//直接-1    // printf( %lld n ,akk);   //  return 0;     int x = len[i];     x --;     akk += 2;//在这里减     if(x % 2 == 0){      gai(1,300000,1,akk,akk + x/2 - 1,2);     }     else{     // printf( %lld n ,akk);      gai(1,300000,1,akk,akk + x/2-1,1);//3      gai(1,300000,1,akk,akk + x/2,1);//3 4     }    }    if(ans != 1e9)    printf( %lld n ,ans-1);    else printf( -1 );   }


#include <bits/stdc++.h>   using namespace std;   int a[123456];   int main() {     int n, ans = 0;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     a[n + 1] = a[0] = 0;     for (int i = 1; i <= n; i++)       a[i] = min(a[i], min(a[i - 1] + 1, a[i + 1] + 1));     for (int i = n; i > 0; i--) {       a[i] = min(a[i], min(a[i - 1] + 1, a[i + 1] + 1));       ans = max(ans, a[i]);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     while (scanf( %d %d , &n, &k) == 2) {       char s[1000005];       memset(s, 0, sizeof(s));       int t = 0;       if (n == 1 && k == 1)         printf( a n );       else if (k == 1)         printf( -1 n );       else if (n < k)         printf( -1 n );       else if (k == 2) {         int l = k - 2;         for (int i = 1; i <= n - l; i++) {           if (i & 1)             s[t++] =  a ;           else             s[t++] =  b ;         }         s[t] =   0 ;         printf( %s n , s);       } else if (k == 3) {         int l = k - 2;         for (int i = 1; i <= n - l; i++) {           if (i & 1)             s[t++] =  a ;           else             s[t++] =  b ;         }         for (int i = 1; i <= l; i++) {           s[t++] = char( b  + i);         }         s[t] =   0 ;         printf( %s n , s);       } else {         int l = k - 2;         for (int i = 1; i <= n - l; i++) {           if (i & 1)             s[t++] =  a ;           else             s[t++] =  b ;         }         for (int i = 1; i <= l; i++) {           s[t++] = char( b  + i);         }         s[t] =   0 ;         printf( %s n , s);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double pi = 3.14159265358979323;   const double EPS = 1e-12;   const int N = 1e6 + 5;   const int MOD = 1e9 + 7;   long long int n, m;   long long int dp[2005][2005];   long long int ad(long long int a, long long int b) {     return ((a % MOD + b % MOD) % MOD);   }   long long int go(long long int idx, long long int ct) {     long long int res = 0;     if (ct == m) {       return 1;     }     if (dp[idx][ct] != -1) return dp[idx][ct];     for (int i = idx; i <= n; i += idx) {       res = ad(res, go(i, ct + 1));     }     dp[idx][ct] = res;     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     memset(dp, -1, sizeof(dp));     cin >> n >> m;     cout << go(1, 0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long u, v;     cin >> u >> v;     if (v - u < 0 || (v - u) % 2) {       cout << -1;       return 0;     }     if (u == 0 && v == 0) {       cout << 0;       return 0;     }     if (v == u) {       cout << 1 <<   n  << v;       return 0;     }     long long x = (v - u) / 2;     if ((x & u) == 0) {       cout << 2 <<   n  << u + x <<     << x;     } else {       cout << 3 <<   n  << u <<     << x <<     << x;     }   }


#include <bits/stdc++.h>   using namespace std;   bool ok1, ok2, ok3, ok4, p1, p2;   int n, m, maxx, minx, maxy, miny;   string a[4002];   int main() {     cin >> n >> m;     minx = miny = 1000000;     maxx = maxy = -1000000;     for (int i = 0; i < n; ++i) {       cin >> a[i];       for (int j = 0; j < m; ++j) {         if (a[i][j] ==  w ) {           if (i > maxx) maxx = i;           if (i < minx) minx = i;           if (j > maxy) maxy = j;           if (j < miny) miny = j;         }       }     }     if (maxx == -1000000) return cout << -1, 0;     ok1 = ok2 = ok3 = ok4 = true;     p1 = p2 = false;     for (int j = 0; j < m; ++j) {       if (a[maxx][j] ==  w  && j != maxy && j != miny) ok1 = false;     }     for (int j = 0; j < m; ++j) {       if (a[minx][j] ==  w  && j != maxy && j != miny) ok2 = false;     }     if (minx == maxx && !ok1) {       ok1 = ok2 = true;       p1 = true;     }     for (int i = 0; i < n; ++i) {       if (a[i][maxy] ==  w  && i != maxx && i != minx) ok3 = false;     }     for (int i = 0; i < n; ++i) {       if (a[i][miny] ==  w  && i != maxx && i != minx) ok4 = false;     }     if (miny == maxy && !ok3) {       ok3 = ok4 = true;       p2 = true;     }     if (maxx - minx > maxy - miny) {       if (ok3) {         int oll = maxx - minx;         int y = maxy;         maxy = miny + oll;         if (maxy >= m && !p2) {           if (!ok4) return cout << -1, 0;           while (maxy >= m) {             maxy--;             miny--;           }           if (miny < 0) return cout << -1, 0;         } else if (maxy >= m) {           miny = y - oll;           maxy = y;           if (miny < 0 || !ok4) return cout << -1, 0;         }       } else if (ok4) {         miny = maxy - maxx + minx;         if (miny < 0) return cout << -1, 0;       } else         return cout << -1, 0;     } else if (maxx - minx < maxy - miny) {       if (ok1) {         int oll = maxy - miny;         int x = maxx;         maxx = minx + oll;         if (maxx >= n && !p1) {           if (!ok2) return cout << -1, 0;           while (maxx >= n) {             maxx--;             minx--;           }           if (minx < 0) return cout << -1, 0;         } else if (maxx >= n) {           minx = x - oll;           maxx = x;           if (minx < 0 || !ok2) return cout << -1, 0;         }       } else if (ok2) {         minx = maxx - maxy + miny;         if (minx < 0) return cout << -1, 0;       } else         return cout << -1, 0;     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (a[i][j] ==  w  && i != minx && i != maxx && j != miny && j != maxy)           return cout << -1, 0;       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (a[i][j] ==  w )           cout <<  w ;         else if (((i == minx || i == maxx) && (miny <= j && j <= maxy)) ||                  ((j == miny || j == maxy) && (minx <= i && i <= maxx)))           cout <<  + ;         else           cout <<  . ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   typedef struct Node {     int xi;     int yi;   };   int main() {     int s, n;     scanf( %d%d , &s, &n);     struct Node Q[n];     int i;     for (i = 0; i < n; i++) {       scanf( %d , &Q[i].xi);       scanf( %d , &Q[i].yi);     }     for (i = 0; i < n; i++) {       for (int j = 0; j < n - 1; j++) {         if (Q[j].xi > Q[j + 1].xi) {           int t_xi, t_yi;           t_xi = Q[j].xi;           t_yi = Q[j].yi;           Q[j].xi = Q[j + 1].xi;           Q[j].yi = Q[j + 1].yi;           Q[j + 1].xi = t_xi;           Q[j + 1].yi = t_yi;         }       }     }     for (i = 0; i < n; i++) {       if (Q[i].xi < s) {         s += Q[i].yi;       } else         break;     }     if (i == n) {       printf( YES );     } else       printf( NO );   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 7;   const int inf = 1e9;   const long long inff = 1e18;   const long long mod = 1e9 + 7;   int a[maxn];   vector<int> v[maxn];   vector<int> tmp;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     int _1 = 0, _2 = 0;     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = n; i >= 1; i--) {       if (a[i] == 1) {         v[_1 + 1].push_back(i);         _1++;       } else if (a[i] == 2) {         _2++;         if (_2 > _1) return cout << -1 << endl, 0;         v[_2].push_back(i);       } else if (a[i] == 3) {         if (_2 > 0) {           v[1].push_back(i);         } else {           v[1].push_back(i);           _2++;           if (_2 > _1) return cout << -1 << endl, 0;         }       }     }     int cntt = 1;     vector<pair<int, int> > ans;     for (int i = 1; i <= n; i++) {       reverse((v[i]).begin(), (v[i]).end());       for (int j = 0; j < ((int)(v[i]).size()); j++) {         if (a[v[i][j]] >= 2) {           ans.push_back({cntt, v[i][j]});           ans.push_back({cntt, v[i][j + 1]});           cntt++;         } else {           if (((int)(v[i]).size()) == 1 || a[v[i][j - 1]] == 3) {             ans.push_back({cntt, v[i][j]});             cntt++;           }         }       }     }     cout << ((int)(ans).size()) << endl;     for (pair<int, int> i : ans) cout << i.first <<     << i.second << endl;   }


#include <bits/stdc++.h>   int main() {     long long t, i, x, y, a, b;     scanf( %lld , &t);     for (i = 1; i <= t; i++) {       scanf( %lld%lld%lld%lld , &x, &y, &a, &b);       if ((y - x) % (a + b) == 0)         printf( %lld n , (y - x) / (a + b));       else         printf( -1 n );     }     return 0;   }