#include <bits/stdc++.h> n const int BARIER = 0; n class Rng { n  private: n   static std::mt19937 engine; n  n  public: n   static std::mt19937& get_engine() { return engine; } n   template <typename T> n   static void set_seed(T const& seed) { n     engine = std::mt19937(seed); n   } n   static void timebased_seed() { n     engine = std::mt19937( n         std::chrono::duration_cast<std::chrono::nanoseconds>( n             std::chrono::high_resolution_clock::now().time_since_epoch()) n             .count()); n   } n   template <typename T> n   static typename std::enable_if<std::is_integral<T>::value, T>::type uniform( n       T l, T r) { n     return std::uniform_int_distribution<T>(l, r)(engine); n   } n   template <typename T> n   static typename std::enable_if<std::is_floating_point<T>::value, T>::type n   uniform(T l, T r) { n     return std::uniform_real_distribution<T>(l, r)(engine); n   } n }; n std::mt19937 Rng::engine( n     std::chrono::duration_cast<std::chrono::nanoseconds>( n         std::chrono::high_resolution_clock::now().time_since_epoch()) n         .count()); n class Timer { n  public: n   template <typename S, typename T, typename... U> n   static S execute_timed(T func, std::string const& name, U&&... u) { n     auto time_begin = std::chrono::high_resolution_clock::now(); n     S ret = func(std::forward<U>(u)...); n     auto time_end = std::chrono::high_resolution_clock::now(); n     auto timespan = std::chrono::duration_cast<std::chrono::nanoseconds>( n         time_end - time_begin); n     std::cerr <<  Execution of    << name <<    took   << std::fixed n               << std::setprecision(6) << timespan.count() * 1e-9 <<   n ; n     return ret; n   } n }; n using namespace std; n class Bigint_base10 { n  public: n   static constexpr int64_t BASE = 1e18; n   static constexpr int DIGITS = 18; n  n  private: n   bool is_neg; n   vector<int64_t> data; n  n  public: n   Bigint_base10() : is_neg(false), data(1, 0) {} n   Bigint_base10(int64_t const& val) : is_neg(val < 0) { n     int64_t abs_val = abs(val); n     if (abs_val < BASE) { n       data = {abs_val}; n     } else { n       data = {abs_val % BASE, abs_val / BASE}; n     } n   } n   Bigint_base10 operator+(Bigint_base10 const& o) const { n     Bigint_base10 ret; n     ret.is_neg = is_neg; n     ret.data.assign(1 + max(data.size(), o.data.size()), 0); n     copy(data.begin(), data.end(), ret.data.begin()); n     int64_t carry = 0; n     for (unsigned int i = 0; i < o.data.size(); ++i) { n       ret.data[i] += o.data[i] + carry; n       carry = 0; n       if (ret.data[i] >= BASE) { n         carry = 1; n         ret.data[i] -= BASE; n       } n     } n     for (unsigned int i = o.data.size(); carry; ++i) { n       ret.data[i] += carry; n       carry = 0; n       if (ret.data[i] >= BASE) { n         carry = 1; n         ret.data[i] -= BASE; n       } n     } n     return ret.trim(); n   } n   Bigint_base10 operator*(int64_t const& o) const { n     if (o == 0) { n       return Bigint_base10(0); n     } n     if (o < 0) { n       return operator*(-o).negate(); n     } n     if (o & 1) { n       return operator+(operator*(o - 1)); n     } n     return operator+(*this) * (o / 2); n   } n   Bigint_base10& operator+=(Bigint_base10 const& o) { n     *this = operator+(o); n     return *this; n   } n   Bigint_base10& operator*=(int64_t const& o) { n     *this = operator*(o); n     return *this; n   } n   Bigint_base10& trim() { n     while (data.size() > 1 && data.back() == 0) { n       data.pop_back(); n     } n     return *this; n   } n   bool is_zero() const { n     for (auto const& e : data) n       if (e) return false; n     return true; n   } n   Bigint_base10& negate() { n     is_neg = !is_neg; n     if (is_zero()) is_neg = false; n     return *this; n   } n   friend ostream& operator<<(ostream& o, Bigint_base10 const& b) { n     if (b.is_neg) o <<  - ; n     o << b.data.back(); n     o << setfill( 0 ); n     for (auto it = next(b.data.rbegin()); it != b.data.rend(); ++it) { n       o << setw(9) << *it; n     } n     o << setw(0) << setfill(   ); n     return o; n   } n   friend istream& operator>>(istream& in, Bigint_base10& b) { n     static string tmp; n     in >> tmp; n     if (tmp[0] ==  - ) { n       b.is_neg = true; n       tmp = tmp.substr(1, -1); n     } else { n       b.is_neg = false; n     } n     b.data.resize((tmp.size() + DIGITS - 1) / DIGITS); n     unsigned int i, j; n     for (i = tmp.size() - DIGITS, j = 0; i > 0; i -= DIGITS, ++j) { n       b.data[j] = stoll(tmp.substr(i, DIGITS)); n     } n     b.data[j] = stoll(tmp.substr(0, i + DIGITS)); n     return in; n   } n }; n template <size_t len> n struct Bigint_Fixedsize { n   unsigned int data[len]; n   static constexpr unsigned int bits = 31; n   Bigint_Fixedsize() { memset(data, 0, sizeof(data)); } n   Bigint_Fixedsize(long long const& _a) { n     memset(data, 0, sizeof(data)); n     unsigned long long a = _a; n     data[0] = a & ((1u << bits) - 1); n     data[1] = a >> bits; n     data[1] &= ~(1u << bits); n     if (a > ~a) { n       for (size_t i = 2; i < len; ++i) { n         data[i] = (1u << bits) - 1; n       } n     } n   } n   Bigint_Fixedsize& operator+=(Bigint_Fixedsize const& o) { n     unsigned int carry = 0; n     for (size_t i = 0; i < len; ++i) { n       data[i] += o.data[i] + carry; n       carry = data[i] >> bits; n       data[i] &= ~(1u << bits); n     } n     return *this; n   } n   Bigint_Fixedsize& operator-=(Bigint_Fixedsize const& o) { n     unsigned int carry = 0; n     for (size_t i = 0; i < len; ++i) { n       data[i] -= o.data[i] + carry; n       carry = data[i] >> bits; n       data[i] &= ~(1u << bits); n     } n     return *this; n   } n   Bigint_Fixedsize operator+(Bigint_Fixedsize const& o) const { n     Bigint_Fixedsize ret(*this); n     ret += o; n     return ret; n   } n   Bigint_Fixedsize operator-(Bigint_Fixedsize const& o) const { n     Bigint_Fixedsize ret(*this); n     ret -= o; n     return ret; n   } n   void multo(Bigint_Fixedsize const& o, Bigint_Fixedsize& ret) const { n     static unsigned int tmp[len + 1]; n     memset(tmp, 0, sizeof(tmp)); n     for (size_t i = 0; i < len; ++i) { n       unsigned long long val = 0; n       for (size_t j = 0; j < len - i; ++j) { n         val += data[i] * (unsigned long long)o.data[j] + tmp[i + j]; n         tmp[i + j] = val & ((1u << bits) - 1); n         val >>= bits; n       } n     } n     memcpy(ret.data, tmp, sizeof(ret.data)); n   } n   Bigint_Fixedsize& operator*=(Bigint_Fixedsize const& o) { n     multo(o, *this); n     return *this; n   } n   Bigint_Fixedsize operator*(Bigint_Fixedsize const& o) const { n     Bigint_Fixedsize ret; n     multo(o, ret); n     return ret; n   } n   Bigint_Fixedsize& negate() { n     unsigned int carry = 0; n     for (size_t i = 0; i < len; ++i) { n       data[i] = ~data[i] + !carry; n       carry = (data[i] >> bits); n       data[i] &= ~(1u << bits); n     } n     return *this; n   } n   Bigint_Fixedsize operator-() const { n     Bigint_Fixedsize ret(*this); n     ret.negate(); n     return ret; n   } n   bool operator<(Bigint_Fixedsize const& o) const { n     if (data[len - 1] >> (bits - 1) != o.data[len - 1] >> (bits - 1)) { n       return data[len - 1] >> (bits - 1); n     } n     for (size_t i = len - 1; ~i; --i) { n       if (data[i] != o.data[i]) return data[i] < o.data[i]; n     } n     return false; n   } n   bool operator>(Bigint_Fixedsize const& o) const { return o < *this; } n   bool operator<=(Bigint_Fixedsize const& o) const { return !(operator>(o)); } n   bool operator>=(Bigint_Fixedsize const& o) const { return !(operator<(o)); } n   bool operator==(Bigint_Fixedsize const& o) const { n     for (size_t i = 0; i < len; ++i) { n       if (data[i] != o.data[i]) return false; n     } n     return true; n   } n   bool operator!=(Bigint_Fixedsize const& o) const { return !operator==(o); } n   bool operator!() const { n     for (size_t i = 0; i < len; ++i) { n       if (data[i]) return false; n     } n     return true; n   } n   bool is_negative() const { return data[len - 1] >> (bits - 1); } n   void print_binary(ostream& o, Bigint_Fixedsize const& b) { n     o <<  [ ; n     for (size_t i = len; i > 0; --i) { n       o << bitset<bits>(b.data[i - 1]); n     } n     o <<  ] ; n   } n   friend ostream& operator<<(ostream& o, Bigint_Fixedsize const& b) { n     if (b.is_negative()) { n       return o <<  -  << -b <<   n ; n     } n     Bigint_base10 ret(0); n     int64_t base = 1u << bits; n     for (int i = len - 1; i >= 0; --i) { n       ret *= base; n       ret += Bigint_base10(b.data[i]); n     } n     o << ret; n     return o; n   } n   explicit operator long double() const { n     if (is_negative()) { n       return (long double)operator-(); n     } n     long double ret = 0.0; n     long double base = 1u << bits; n     for (int i = len - 1; i >= 0; --i) { n       ret = ret * base + data[i]; n     } n     return ret; n   } n   friend istream& operator>>(istream& i, Bigint_Fixedsize& b) { n     int64_t tmp; n     i >> tmp; n     b = Bigint_Fixedsize(tmp); n     return i; n   } n }; n template <size_t len> n struct Bigint_Fixedsize_Fast { n   unsigned int data[len]; n   uint16_t siz; n   bool sign; n   static constexpr unsigned int bits = 32; n   Bigint_Fixedsize_Fast() { n     data[0] = 0; n     siz = 1; n     sign = false; n   } n   Bigint_Fixedsize_Fast(long long a) { n     sign = false; n     if (a < 0) { n       sign = true; n       a = -a; n     } n     siz = 0; n     do { n       long long b = a >> bits; n       data[siz] = a - (b << bits); n       a = b; n       ++siz; n     } while (a); n   } n   void trim() { n     while (siz > 1 && !data[siz - 1]) --siz; n   } n   int comp_unsigned(Bigint_Fixedsize_Fast const& o) const { n     uint16_t lim = min(siz, o.siz); n     for (unsigned int i = lim; i < siz; ++i) { n       if (data[i]) { n         return 1; n       } n     } n     for (unsigned int i = lim; i < o.siz; ++i) { n       if (o.data[i]) { n         return -1; n       } n     } n     for (unsigned int i = lim - 1; i + 1; --i) { n       if (data[i] != o.data[i]) { n         return data[i] < o.data[i] ? -1 : 1; n       } n     } n     return 0; n   } n   int comp(Bigint_Fixedsize_Fast const& o) const { n     int sign_mul = 1 - 2 * sign; n     if (sign != o.sign) { n       return sign_mul; n     } n     return sign_mul * comp_unsigned(o); n   } n   bool operator<(Bigint_Fixedsize_Fast const& o) const { return comp(o) < 0; } n   bool operator>(Bigint_Fixedsize_Fast const& o) const { return comp(o) > 0; } n   bool operator<=(Bigint_Fixedsize_Fast const& o) const { return comp(o) <= 0; } n   bool operator>=(Bigint_Fixedsize_Fast const& o) const { return comp(o) >= 0; } n   bool operator==(Bigint_Fixedsize_Fast const& o) const { return comp(o) == 0; } n   bool operator!=(Bigint_Fixedsize_Fast const& o) const { return comp(o) != 0; } n   bool operator!() const { return operator==(ZERO); } n   Bigint_Fixedsize_Fast operator-() const { n     Bigint_Fixedsize_Fast ret(*this); n     if (!!ret) { n       ret.sign ^= 1; n     } n     return ret; n   } n   Bigint_Fixedsize_Fast operator*(Bigint_Fixedsize_Fast const& o) const { n     Bigint_Fixedsize_Fast ret; n     ret.siz = min(siz + o.siz, (int)len); n     ret.sign = (sign != o.sign); n     fill(ret.data, ret.data + ret.siz, 0); n     for (unsigned int i = 0; i < siz; ++i) { n       unsigned long long carry = 0, carry_2; n       for (unsigned int j = 0; j < o.siz; ++j) { n         carry += data[i] * (unsigned long long)o.data[j] + ret.data[i + j]; n         carry_2 = carry >> bits; n         ret.data[i + j] = carry - (carry_2 << bits); n         carry = carry_2; n       } n       for (unsigned int j = i + o.siz; carry; ++j) { n         carry += ret.data[j]; n         carry_2 = carry >> bits; n         ret.data[j] = carry - (carry_2 << bits); n         carry = carry_2; n       } n     } n     ret.trim(); n     return ret; n   } n   Bigint_Fixedsize_Fast& operator*=(Bigint_Fixedsize_Fast const& o) { n     *this = operator*(o); n     return *this; n   } n   static void unsigned_add(Bigint_Fixedsize_Fast& ret, n                            Bigint_Fixedsize_Fast const& A, n                            Bigint_Fixedsize_Fast const& B) { n     const Bigint_Fixedsize_Fast *a = &A, *b = &B; n     if (a->siz < b->siz) swap(a, b); n     ret.sign = A.sign; n     unsigned long long carry = 0, carry_2; n     unsigned int j; n     for (j = 0; j < b->siz; ++j) { n       carry += (unsigned long long)a->data[j] + (unsigned long long)b->data[j]; n       carry_2 = carry >> bits; n       ret.data[j] = carry - (carry_2 << bits); n       carry = carry_2; n     } n     for (; j < a->siz; ++j) { n       carry += a->data[j]; n       carry_2 = carry >> bits; n       ret.data[j] = carry - (carry_2 << bits); n       carry = carry_2; n     } n     if (carry) { n       ret.data[j++] = carry; n     } n     ret.siz = j; n     ret.trim(); n   } n   static void unsigned_subtract(Bigint_Fixedsize_Fast& ret, n                                 Bigint_Fixedsize_Fast const& A, n                                 Bigint_Fixedsize_Fast const& B) { n     int com = A.comp_unsigned(B); n     if (com == 0) { n       ret.sign = false; n       ret.siz = 1; n       ret.data[0] = 0; n       return; n     } n     ret.sign = A.sign; n     const Bigint_Fixedsize_Fast *a = &A, *b = &B; n     if (com < 0) { n       ret.sign ^= true; n       swap(a, b); n     } n     unsigned int min_siz = min(A.siz, B.siz); n     unsigned long long carry = 0, carry_2; n     unsigned int j; n     for (j = 0; j < min_siz; ++j) { n       carry += (unsigned long long)a->data[j] - (unsigned long long)b->data[j]; n       carry_2 = carry >> bits; n       ret.data[j] = carry - (carry_2 << bits); n       carry = -(carry_2 & 1u); n     } n     for (; carry; ++j) { n       carry += a->data[j]; n       carry_2 = carry >> bits; n       ret.data[j] = carry - (carry_2 << bits); n       carry = -(carry_2 & 1u); n     } n     copy(a->data + j, a->data + a->siz, ret.data + j); n     ret.siz = a->siz; n     ret.trim(); n   } n   static void add(Bigint_Fixedsize_Fast& ret, Bigint_Fixedsize_Fast const& A, n                   Bigint_Fixedsize_Fast const& B) { n     if (A.sign == B.sign) { n       unsigned_add(ret, A, B); n     } else { n       unsigned_subtract(ret, A, B); n     } n   } n   static void sub(Bigint_Fixedsize_Fast& ret, Bigint_Fixedsize_Fast const& A, n                   Bigint_Fixedsize_Fast const& B) { n     if (A.sign != B.sign) { n       unsigned_add(ret, A, B); n     } else { n       unsigned_subtract(ret, A, B); n     } n   } n   Bigint_Fixedsize_Fast operator+(Bigint_Fixedsize_Fast const& o) const { n     Bigint_Fixedsize_Fast ret; n     add(ret, *this, o); n     return ret; n   } n   Bigint_Fixedsize_Fast& operator+=(Bigint_Fixedsize_Fast const& o) { n     add(*this, *this, o); n     return *this; n   } n   Bigint_Fixedsize_Fast operator-(Bigint_Fixedsize_Fast const& o) const { n     Bigint_Fixedsize_Fast ret; n     sub(ret, *this, o); n     return ret; n   } n   Bigint_Fixedsize_Fast operator-=(Bigint_Fixedsize_Fast const& o) { n     sub(*this, *this, o); n     return *this; n   } n   void print_binary(ostream& o, Bigint_Fixedsize_Fast const& b) { n     o <<  [ ; n     o << sign <<  /  << len <<  / ; n     for (size_t i = siz; i > 0; --i) { n       o << bitset<bits>(b.data[i - 1]); n     } n     o <<  ] ; n   } n   friend ostream& operator<<(ostream& o, Bigint_Fixedsize_Fast const& b) { n     if (b.sign) { n       return o <<  -  << -b; n     } n     Bigint_base10 ret(0); n     int64_t base = 1ll << bits; n     for (int i = b.siz - 1; i >= 0; --i) { n       ret *= base; n       ret += Bigint_base10(b.data[i]); n     } n     o << ret; n     return o; n   } n   explicit operator long double() const { n     if (sign) { n       return (long double)operator-(); n     } n     long double ret = 0.0; n     long double base = 1ll << bits; n     for (int i = siz - 1; i >= 0; --i) { n       ret = ret * base + data[i]; n     } n     return ret; n   } n   friend istream& operator>>(istream& i, Bigint_Fixedsize_Fast& b) { n     int64_t tmp; n     i >> tmp; n     b = Bigint_Fixedsize_Fast(tmp); n     return i; n   } n   static const Bigint_Fixedsize_Fast ZERO; n }; n template <size_t len> n const Bigint_Fixedsize_Fast<len> Bigint_Fixedsize_Fast<len>::ZERO(0); n template <typename FLOAT> n class Lp_Seidel { n  private: n   vector<FLOAT> proj_down(vector<FLOAT> const& vec, vector<FLOAT> const& plane, n                           size_t j) { n     vector<FLOAT> ret(vec.size() - 1); n     if (plane[j] < FLOAT(0)) { n       for (size_t i = 0; i + 1 < vec.size(); ++i) { n         ret[i] = vec[j] * plane[i + (i >= j)] - vec[i + (i >= j)] * plane[j]; n       } n     } else { n       for (size_t i = 0; i + 1 < vec.size(); ++i) { n         ret[i] = vec[i + (i >= j)] * plane[j] - vec[j] * plane[i + (i >= j)]; n       } n     } n     return ret; n   } n   vector<FLOAT> proj_up(vector<FLOAT> const& vec, vector<FLOAT> const& plane, n                         size_t j) { n     vector<FLOAT> ret(vec.size() + 1); n     copy(vec.begin(), vec.begin() + j, ret.begin()); n     copy(vec.begin() + j, vec.end(), ret.begin() + j + 1); n     for (size_t i = 0; i < vec.size(); ++i) { n       ret[j] += vec[i] * plane[i + (i >= j)]; n     } n     FLOAT denom = plane[j]; n     if (denom < FLOAT(0)) { n       denom = -denom; n     } n     for (size_t i = 0; i < vec.size(); ++i) { n       ret[i + (i >= j)] *= denom; n     } n     if (plane[j] >= FLOAT(0)) { n       ret[j] = -ret[j]; n     } n     return ret; n   } n   FLOAT planescal(vector<FLOAT> const& x, vector<FLOAT> const& a) { n     FLOAT ret = 0; n     for (size_t i = 0; i < x.size(); ++i) { n       ret += x[i] * a[i]; n     } n     return ret; n   } n   vector<FLOAT> solve(vector<vector<FLOAT>> const& A, vector<FLOAT> const& c, n                       int d, FLOAT const& barier_loc) { n     int n = A.size(); n     if (d == 1) { n       vector<FLOAT> ret(2); n       ret[0] = (c[0] < FLOAT(0) ? -barier_loc : barier_loc); n       ret[1] = 1ull; n       for (int i = 0; i < n; ++i) { n         if (ret[0] * A[i][0] + ret[1] * A[i].back() > FLOAT(0)) { n           if (!A[i][0]) { n             do { n             } while (0); n             return vector<FLOAT>(); n           } n           ret[0] = -A[i].back(); n           ret[1] = A[i][0]; n           if (ret[1] < FLOAT(0)) { n             ret[1] = -ret[1]; n             ret[0] = -ret[0]; n           } n           do { n           } while (0); n         } n       } n       for (int i = 0; i < n; ++i) { n         if (ret[0] * A[i][0] + ret[1] * A[i].back() > FLOAT(0)) { n           do { n           } while (0); n           return vector<FLOAT>(); n         } n       } n       return ret; n     } n     FLOAT barier_next = barier_loc * barier_loc; n     vector<FLOAT> x(d + 1); n     for (int i = 0; i < d; ++i) { n       x[i] = (c[i] < FLOAT(0) ? -barier_loc : barier_loc); n     } n     x.back() = FLOAT(1); n     for (size_t i = 0; i < A.size(); ++i) { n       if (planescal(x, A[i]) > FLOAT(0)) { n         int k = 0; n         while (k < d && !A[i][k]) ++k; n         if (k == d) { n           do { n           } while (0); n           return vector<FLOAT>(); n         } n         vector<vector<FLOAT>> A2(i); n         for (size_t j = 0; j < A2.size(); ++j) { n           A2[j] = proj_down(A[j], A[i], k); n         } n         shuffle(A2.begin(), A2.end(), Rng::get_engine()); n         do { n         } while (0); n         vector<FLOAT> c2 = proj_down(c, A[i], k); n         vector<FLOAT> x2 = solve(A2, c2, d - 1, barier_next); n         if (x2.empty()) return x2; n         x = proj_up(x2, A[i], k); n         do { n         } while (0); n         do { n         } while (0); n         do { n         } while (0); n       } n     } n     return x; n   } n  n  public: n   vector<FLOAT> solve(vector<vector<FLOAT>> const& A, vector<FLOAT> const& c, n                       const FLOAT& barier = FLOAT((long long)1e9)) { n     return solve(A, c, c.size(), barier); n   } n   vector<FLOAT> solve(vector<vector<FLOAT>> A, vector<FLOAT> const& b, n                       vector<FLOAT> const& c) { n     for (unsigned int i = 0; i < A.size(); ++i) { n       A[i].push_back(-b[i]); n     } n     return solve(A, c); n   } n }; n template <typename Big_Int> n class Lp_Clarkson { n  private: n   vector<int> sample_subset(vector<int64_t> const& weight, unsigned int siz) { n     int64_t total_weight = accumulate(weight.begin(), weight.end(), 0ll); n     vector<int64_t> samples; n     while (samples.size() < siz) { n       int64_t new_sample = Rng::uniform<int64_t>(0, total_weight - 1); n       if (find(samples.begin(), samples.end(), new_sample) == samples.end()) { n         samples.push_back(new_sample); n       } n     } n     sort(samples.begin(), samples.end()); n     vector<int> ret; n     int64_t left_weight = 0; n     for (unsigned int i = 0, j = 0; i < weight.size() && j < samples.size();) { n       if (samples[j] < left_weight + weight[i]) { n         ret.push_back(i); n         ++j; n       } else { n         left_weight += weight[i]; n         ++i; n       } n     } n     return ret; n   } n   bool is_satisfied(vector<Big_Int> const& x, vector<Big_Int> const& a) { n     Big_Int ret = 0; n     for (size_t i = 0; i < x.size(); ++i) { n       ret += x[i] * a[i]; n     } n     return ret <= Big_Int(0); n   } n   vector<Big_Int> solve(vector<vector<Big_Int>> const& A, n                         vector<Big_Int> const& c, n                         const unsigned int sample_size) { n     Lp_Seidel<Big_Int> sub_lp; n     if (A.size() < sample_size) { n       return sub_lp.solve(A, c); n     } else { n       int equations = A.size(); n       int variables = c.size(); n       vector<int64_t> weight(equations, 1); n       vector<Big_Int> x; n       vector<vector<Big_Int>> subproblem_A; n       vector<char> is_violated(equations, 0); n       for (unsigned int iteration = 1;; ++iteration) { n         subproblem_A.clear(); n         vector<int> subspace = sample_subset(weight, sample_size); n         for (int const& e : subspace) { n           subproblem_A.push_back(A[e]); n         } n         x = sub_lp.solve(subproblem_A, c); n         if (x.empty()) { n           return x; n         } n         int64_t total_violated = 0; n         for (int i = 0; i < equations; ++i) { n           is_violated[i] = !is_satisfied(x, A[i]); n           if (is_violated[i]) { n             total_violated += weight[i]; n           } n         } n         if (total_violated == 0) { n           cerr <<  Iterations:   << iteration; n           cerr <<  , max weight:   << *max_element(weight.begin(), weight.end()) n                <<   n ; n           break; n         } n         if (total_violated * 3 * variables <= n             accumulate(weight.begin(), weight.end(), 0ll)) { n           for (int i = 0; i < equations; ++i) { n             if (is_violated[i]) { n               weight[i] *= 2; n             } n           } n         } n       } n       return x; n     } n   } n  n  public: n   vector<Big_Int> solve(vector<vector<Big_Int>> const& A, n                         vector<Big_Int> const& c) { n     return solve(A, c, c.size() * c.size() * 4); n   } n   vector<Big_Int> solve(vector<vector<Big_Int>> A, vector<Big_Int> const& b, n                         vector<Big_Int> const& c) { n     for (unsigned int i = 0; i < A.size(); ++i) { n       A[i].push_back(-b[i]); n     } n     return solve(A, c); n   } n }; n template <typename Big_Int> n void test_factorial(unsigned int n, bool debug = false) { n   std::cout <<  Computing   << n <<  ! n ; n   Big_Int val(1); n   for (unsigned int i = 1; i <= n; ++i) { n     val *= i; n     if (debug) std::cerr << i <<   :   << val <<   n ; n   } n   std::cerr <<  Printing n ; n   std::cout << val << endl; n } n template <typename Big_Int> n void test_addsub(int n) { n   Big_Int a(5432123456789ll); n   Big_Int b(9876543210123ll); n   Big_Int c; n   for (int it = 0; it < 4 * n; ++it) { n     std::cout << a <<   +   << b <<   =   << a + b <<   n ; n     std::cout << b <<   +   << a <<   =   << b + a <<   n ; n     std::cout << a <<   -   << b <<   =   << a - b <<   n ; n     std::cout << b <<   -   << a <<   =   << b - a <<   n ; n     c = a; n     c += b; n     std::cout << a <<   +   << b <<   =   << c <<   n ; n     c = b; n     c += a; n     std::cout << b <<   +   << a <<   =   << c <<   n ; n     c = a; n     c -= b; n     std::cout << a <<   -   << b <<   =   << c <<   n ; n     c = b; n     c -= a; n     std::cout << b <<   -   << a <<   =   << c <<   n ; n     a = -a; n     if (it % 4 == 3) { n       a *= it; n     } else { n       swap(a, b); n     } n   } n } n template <typename Big_Int> n void test_addmul(int n, int k) { n   std::cout <<  Addmul test   << n <<     << k <<   n ; n   ; n   Rng::set_seed(635241); n   Big_Int ret(0); n   for (int i = 0; i < n; ++i) { n     Big_Int cur(1); n     for (int j = 0; j < k; ++j) { n       Big_Int mu(Rng::uniform(1ll, (long long)1e15)); n       cur *= mu; n     } n     ret += cur; n   } n   std::cout << ret <<   n ; n } n void test_timer() { n   std::function<int64_t(int64_t)> fib = [&](int64_t x) { n     return x < 2 ? x : fib(x - 1) + fib(x - 2); n   }; n   Timer::execute_timed<int64_t>(fib,  Timer test , 35); n   Timer::execute_timed<int64_t>(fib,  Timer test , 40); n } n template <typename Big_Int, typename Solver> n void test_lp(std::string const& path) { n   std::cerr <<  LP Test:   << path <<   n ; n   std::ifstream in; n   in.open(path.c_str()); n   int variables, constraints; n   in >> variables >> constraints; n   std::vector<std::vector<Big_Int>> A(constraints, n                                       std::vector<Big_Int>(variables)); n   std::vector<Big_Int> b(constraints), c(variables); n   for (auto& e : c) in >> e; n   for (int i = 0; i < constraints; ++i) { n     for (auto& e : A[i]) in >> e; n     in >> b[i]; n   } n   std::function<std::vector<Big_Int>()> solve = [&]() { n     Solver solver; n     return solver.solve(A, b, c); n   }; n   std::vector<Big_Int> solution = n       Timer::execute_timed<vector<Big_Int>>(solve,  solve LP ); n   std::cerr <<  Solution: n ; n   for (auto& e : solution) { n     std::cerr << e <<    ; n   } n   cerr <<   n ; n } n template <typename Big_Int, typename Solver> n void test_enclosing_annulus(int n) { n   cerr <<  Enclosing annulus test (  << n <<  ) n ; n   cerr <<  Int:   << typeid(Big_Int).name() n        <<  , Solver:   << typeid(Solver).name() <<   n ; n   Rng::set_seed(1234); n   vector<pair<int, int>> pts(n); n   for (auto& e : pts) { n     e.first = Rng::uniform(-10000, 10000); n     e.second = Rng::uniform(-10000, 10000); n   } n   Rng::set_seed(24680); n   vector<vector<Big_Int>> A; n   vector<Big_Int> b, c; n   c = {Big_Int(0), Big_Int(0), -1, 1}; n   for (auto const& e : pts) { n     A.push_back({Big_Int(-2 * e.first), Big_Int(-2 * e.second), -1, 0}); n     b.emplace_back(-e.first * e.first - e.second * e.second); n     A.push_back({Big_Int(2 * e.first), Big_Int(2 * e.second), 0, 1}); n     b.emplace_back(e.first * e.first + e.second * e.second); n   } n   std::function<std::vector<Big_Int>()> solve = [&]() { n     Solver solver; n     return solver.solve(A, b, c); n   }; n   std::vector<Big_Int> solution = n       Timer::execute_timed<vector<Big_Int>>(solve,  solve enclosing circle LP ); n   std::cerr <<  Solution: n ; n   for (auto& e : solution) { n     std::cerr << e <<    ; n   } n   cerr <<   n ; n   if (!solution.empty()) { n     Big_Int r_sq = solution[2] * solution[4] - solution[1] * solution[1] + n                    solution[2] * solution[2]; n     Big_Int R_sq = solution[3] * solution[4] - solution[1] * solution[1] + n                    solution[2] * solution[2]; n     Big_Int area_numerator = solution[3] - solution[2]; n     cerr <<  area^2:   << (long double)area_numerator / (long double)solution[4] n          <<   n ; n     cerr <<  r^2:   n          << (long double)r_sq / (long double)(solution[4] * solution[4]) n          <<   n ; n     cerr <<  R^2:   n          << (long double)R_sq / (long double)(solution[4] * solution[4]) n          <<   n ; n   } n   cerr <<   n ; n } n void test_codeforces_549E() { n   auto codeforces_549E = [&]() { n     using DOUBLE = Bigint_Fixedsize_Fast<12>; n     int N, M; n     cin >> N >> M; n     vector<vector<DOUBLE>> A; n     vector<DOUBLE> b, c(4); n     A.reserve(N + M); n     vector<pair<int, int>> p2(N), p(M); n     for (int i = 0; i < N; ++i) { n       cin >> p2[i].first >> p2[i].second; n     } n     for (int i = 0; i < M; ++i) { n       cin >> p[i].first >> p[i].second; n     } n     for (int it = 0; it < 2; ++it) { n       N = p.size(); n       M = p2.size(); n       A.clear(); n       b.clear(); n       for (int i = 0; i < N; ++i) { n         int x, y, z; n         tie(x, y) = p[i]; n         z = x * x + y * y; n         A.push_back({x, y, 1, 1}); n         b.push_back(z); n       } n       for (int i = 0; i < M; ++i) { n         int x, y, z; n         tie(x, y) = p2[i]; n         z = x * x + y * y; n         A.push_back({-x, -y, -1, 1}); n         b.push_back(-z); n       } n       c[3] = 1; n       Lp_Clarkson<DOUBLE> solver; n       vector<DOUBLE> x = solver.solve(A, b, c); n       if (!x.empty()) { n         DOUBLE res = 0; n         for (size_t i = 0; i < c.size(); ++i) res += x[i] * c[i]; n         DOUBLE dist = res; n         if (dist > DOUBLE(0)) { n           cout <<  YES n ; n           return; n         } n       } else { n       } n       p.swap(p2); n     } n     cout <<  NO n ; n   }; n   int TTT = 1; n   while (TTT--) { n     codeforces_549E(); n   } n } n signed test_codejam_2017_4_D() { n   using DOUBLE = Bigint_Fixedsize_Fast<25>; n   freopen( codejam_d.in ,  r , stdin); n   freopen( codejam_d.out ,  w , stdout); n   cin.tie(0); n   ios_base::sync_with_stdio(false); n   int T; n   cin >> T; n   for (int cas = 1; cas <= T; ++cas) { n     cout <<  Case #  << cas <<  :  ; n     cerr <<  Case #  << cas <<  :  ; n     int n; n     cin >> n; n     vector<vector<DOUBLE>> A; n     vector<DOUBLE> b, c(4); n     A.reserve(n); n     do { n     } while (0); n     for (int i = 0; i < n; ++i) { n       int x, y, z; n       cin >> x >> y >> z; n       A.push_back({x, y, z, 1}); n       b.push_back(0); n     } n     c[3] = 1; n     Lp_Clarkson<DOUBLE> solver; n     vector<DOUBLE> x = solver.solve(A, b, c); n     bool did = false; n     if (!x.empty()) { n       if (x[3] > DOUBLE(0)) { n         did = true; n       } n     } n     if (did) n       cout <<  NO n ; n     else n       cout <<  YES n ; n     cerr << (did ?  NO n  :  YES n ); n   } n   return 0; n } n using namespace std; n int main() { n   test_codeforces_549E(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double gr = (1 + sqrt(5)) / 2; n long long n, k, c, res[107], mres; n string s; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> k >> s; n   c = 1; n   for (int i = 0; i < n; i++) { n     if (i > 0) { n       if (s[i] == s[i - 1]) { n         c++; n         if (c == k) { n           c = 0; n           res[s[i] -  a  + 1]++; n         } n       } else n         c = 1; n     } n     if (c == k) { n       c = 0; n       res[s[i] -  a  + 1]++; n     } n   } n   for (int i = 1; i <= 26; i++) mres = max(mres, res[i]); n   cout << mres << endl; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> primes; n void sieve() { n   vector<int> a(1000000, 0); n   for (int u = 2; u <= 1000000; u++) { n     if (a[u]) continue; n     for (int i = 2 * u; i <= 1000000; i += u) a[i] = u; n   } n   for (int i = 2; i <= 1000000; i++) { n     if (!a[i]) primes.push_back(i); n   } n } n int gcd(int a, int b) { n   while (1) { n     if (a == 0) return b; n     b %= a; n     if (b == 0) return a; n     a %= b; n   } n } n int lcm(int a, int b) { n   int g = gcd(a, b); n   return ((a * b) / g); n } n int digitCount(int n) { n   int c = 0; n   while (n != 0) { n     c += n % 10; n     n /= 10; n   } n   return c; n } n int main() { n   int n; n   vector<int> ary = {0,   70,  140, 210,  280,  350,  601,  671, 741, n                      811, 881, 951, 1202, 1272, 1342, 1412, 1440}; n   string str; n   cin >> str; n   n = (str[4] - 48) + (str[3] - 48) * 10 + (str[1] - 48) * 60 + n       (str[0] - 48) * 600; n   for (int i = 0; i < ary.size(); i++) { n     if (n <= ary[i]) { n       cout << ary[i] - n << endl; n       return 0; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n char s[105]; n int main(void) { n   int n, f; n   while (cin >> n) { n     scanf( %s , s); n     f = 0; n     for (int l = (1); l <= (n); ++l) { n       for (int j = (0); j <= (n - 4 * l - 1); ++j) { n         if (j + 4 * l >= n) break; n         if (s[j] ==  *  && s[j + l] ==  *  && s[j + 2 * l] ==  *  && n             s[j + 3 * l] ==  *  && s[j + 4 * l] ==  * ) { n           f = 1; n           break; n         } n       } n       if (f) break; n     } n     if (f) n       cout <<  yes n ; n     else n       cout <<  no n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> thing[20005 * 4], query[20005 * 4]; n struct Thing { n   int cost, happy; n } d[20005]; n int cost[20005], f[4005], tree[20005 * 4], tmp[16][4005], ans[20005]; n int x, i, n, m, p, y; n void build1(int k, int l, int r) { n   if (x <= l && r <= y) { n     thing[k].push_back(i); n     return; n   } n   int mid = (l + r) >> 1; n   if (x <= mid) build1(k << 1, l, mid); n   if (y > mid) build1(k << 1 | 1, mid + 1, r); n } n void build2(int k, int l, int r) { n   tree[k] = 1; n   int mid = (l + r) >> 1; n   if (l == r) { n     query[k].push_back(i); n     return; n   } n   if (x <= mid) n     build2(k << 1, l, mid); n   else n     build2(k << 1 | 1, mid + 1, r); n } n void work(int k, int l, int r, int dep) { n   if (thing[k].size()) { n     memcpy(tmp[dep], f, sizeof(f)); n     for (int i = 0; i < thing[k].size(); i++) { n       int lose = d[thing[k][i]].cost, win = d[thing[k][i]].happy; n       for (int j = 4000; j >= lose; j--) f[j] = max(f[j], f[j - lose] + win); n     } n   } n   if (l == r) { n     for (int i = 0; i < query[k].size(); i++) n       ans[query[k][i]] = f[cost[query[k][i]]]; n     if (thing[k].size()) memcpy(f, tmp[dep], sizeof(tmp[dep])); n     return; n   } n   int mid = (l + r) >> 1; n   work(k << 1, l, mid, dep + 1); n   work(k << 1 | 1, mid + 1, r, dep + 1); n   if (thing[k].size()) memcpy(f, tmp[dep], sizeof(tmp[dep])); n } n int main() { n   scanf( %d %d , &n, &p); n   for (i = 1; i <= n; i++) { n     scanf( %d%d%d , &d[i].cost, &d[i].happy, &x); n     y = x + p - 1; n     build1(1, 1, 20000); n   } n   scanf( %d , &m); n   for (i = 1; i <= m; i++) { n     scanf( %d%d , &x, &cost[i]); n     build2(1, 1, 20000); n   } n   work(1, 1, 20000, 0); n   for (i = 1; i <= m; i++) printf( %d n , ans[i]); n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T sqr(T a) { n   return a * a; n } n #pragma comment(linker,  /STACK:16777216 ) n int n; n char s[105]; n string str; n int main() { n   gets(s); n   str = s; n   n = strlen(s); n   for (int i = n - 1; i > 0; --i) n     for (int j = 0; j <= n - i; ++j) n       for (int k = j + 1; k <= n - i; ++k) n         if (str.substr(j, i) == str.substr(k, i)) { n           printf( %d , i); n           return 0; n         } n   printf( 0 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 205; n int read() { n   int x = 0, f = 1; n   char ch; n   while (!isdigit(ch = getchar())) (ch ==  - ) && (f = -f); n   for (x = ch ^ 48; isdigit(ch = getchar()); n        x = (x << 3) + (x << 1) + (ch ^ 48)) n     ; n   return x * f; n } n vector<int> vec[N]; n int n, s, t, tim, cnt = 1, a[N], head[N], vis[N], level[N], is[20010]; n struct edge { n   int v, w, nxt; n } e[N * N]; n void add(int x, int y, int w) { n   e[++cnt] = (edge){y, w, head[x]}; n   head[x] = cnt; n   e[++cnt] = (edge){x, 0, head[y]}; n   head[y] = cnt; n } n void init(int n) { n   is[1] = 1; n   for (int i = 2; i <= n; ++i) { n     if (is[i]) continue; n     for (int j = i + i; j <= n; j += i) is[j] = 1; n   } n } n int bfs() { n   queue<int> Q; n   Q.push(s); n   memset(level, 0, sizeof(level)); n   level[s] = 1; n   while (!Q.empty()) { n     int x = Q.front(); n     Q.pop(); n     for (int i = head[x]; i; i = e[i].nxt) { n       int v = e[i].v, w = e[i].w; n       if (w && !level[v]) level[v] = level[x] + 1, Q.push(v); n     } n   } n   return level[t] != 0; n } n int dfs(int x, int flow) { n   if (x == t || !flow) return flow; n   int up = 0; n   for (int i = head[x]; i; i = e[i].nxt) { n     int v = e[i].v, w = e[i].w; n     if (w && level[v] == level[x] + 1) { n       int tmp = dfs(v, min(flow, w)); n       e[i].w -= tmp, e[i ^ 1].w += tmp; n       flow -= tmp, up += tmp; n       if (!flow) break; n     } n   } n   if (!up) level[x] = 0; n   return up; n } n int Dinic() { n   int maxflow = 0; n   while (bfs()) maxflow += dfs(s, 2e9); n   return maxflow; n } n void find(int x) { n   vis[x] = 1; n   vec[tim].push_back(x); n   for (int i = head[x]; i; i = e[i].nxt) n     if (!vis[e[i].v] && e[i | 1].w == 1) find(e[i].v); n } n int main() { n   n = read(); n   s = 0; n   t = n + 1; n   init(20000); n   for (int i = 1; i <= n; ++i) a[i] = read(); n   for (int i = 1; i <= n; ++i) n     if (a[i] & 1) n       add(i, t, 2); n     else n       add(s, i, 2); n   for (int i = 1; i <= n; ++i) { n     if (a[i] & 1) continue; n     for (int j = 1; j <= n; ++j) n       if (!is[a[i] + a[j]]) add(i, j, 1); n   } n   if (Dinic() != n) return puts( Impossible ), 0; n   for (int i = 1; i <= n; ++i) n     if (!vis[i]) ++tim, find(i); n   printf( %d n , tim); n   for (int i = 1; i <= tim; ++i) { n     printf( %d  , vec[i].size()); n     for (int j = 0; j < vec[i].size(); ++j) printf( %d  , vec[i][j]); n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int const maxn = (int)1e4 + 111; n int const inf = (1 << 30) - 1; n int k; n int a[4]; n int t[4]; n int d[maxn][4]; n int first[maxn][4]; n int main() { n   cin >> k; n   for (int i = 1; i <= 3; i++) cin >> a[i]; n   for (int i = 1; i <= 3; i++) cin >> t[i]; n   for (int j = 1; j <= 3; j++) { n     for (int i = 1; i <= k; i++) { n       int v = -1; n       for (int q = 1; q <= a[j]; q++) { n         if (v == -1 || first[q][j] < first[v][j]) { n           v = q; n         } n       } n       d[i][j] = max(d[i][j - 1], first[v][j]) + t[j]; n       first[v][j] = d[i][j]; n     } n   } n   cout << d[k][3] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b, qa, qb, answer; n int i, j, p, k, lcm, d; n int dist[1000000]; n char inq[1000000]; n int gcd(int x, int y) { n   if ((x % y) == 0) return y; n   return gcd(y, x % y); n } n void ComputeDist() { n   for (i = 0; i <= lcm; i++) { n     dist[i] = lcm + 1; n     inq[i] = 0; n   } n   dist[0] = 0; n   queue<int> q; n   q.push(0); n   inq[0] = 1; n   while (q.size() > 0) { n     i = q.front(); n     q.pop(); n     inq[i] = 0; n     if (i + 1 <= lcm && (1 + dist[i] < dist[i + 1])) { n       dist[i + 1] = 1 + dist[i]; n       if (!inq[i + 1]) { n         q.push(i + 1); n         inq[i + 1] = 1; n       } n     } n     for (j = 2; j <= k; j++) n       if (i % j == 0) { n         for (p = 1; p < j; p++) n           if (i + p <= lcm && (1 + dist[i] < dist[i + p])) { n             dist[i + p] = 1 + dist[i]; n             if (!inq[i + p]) { n               q.push(i + p); n               inq[i + p] = 1; n             } n           } n       } n   } n } n void ComputeDist2(int end, int start) { n   for (i = 0; i <= start; i++) { n     dist[i] = start + 1; n     inq[i] = 0; n   } n   dist[start] = 0; n   queue<int> q; n   q.push(start); n   inq[start] = 1; n   while (q.size() > 0) { n     i = q.front(); n     q.pop(); n     inq[i] = 0; n     if (i - 1 >= end && (1 + dist[i] < dist[i - 1])) { n       dist[i - 1] = 1 + dist[i]; n       if (!inq[i - 1]) { n         q.push(i - 1); n         inq[i - 1] = 1; n       } n     } n     for (j = 2; j <= k; j++) n       if (i % j > 0) { n         p = i % j; n         if (i - p >= end && (1 + dist[i] < dist[i - p])) { n           dist[i - p] = 1 + dist[i]; n           if (!inq[i - p]) { n             q.push(i - p); n             inq[i - p] = 1; n           } n         } n       } n   } n } n int main() { n   scanf( %I64d %I64d %d , &a, &b, &k); n   lcm = 1; n   for (i = 2; i <= k; i++) { n     d = gcd(i, lcm); n     lcm *= (i / d); n   } n   ComputeDist(); n   qa = a / lcm; n   qb = b / lcm; n   answer = 0; n   if (qa > qb + 1) { n     answer += dist[a % lcm]; n     answer += dist[lcm] * (qa - qb - 1); n     a = (qb + 1) * lcm; n   } n   ComputeDist2(b % lcm, a - qb * lcm); n   answer += dist[b % lcm]; n   printf( %I64d n , answer); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MaxN = 100005, LOG = 22; n int n, fth[MaxN], poz[MaxN], fr[MaxN], w[MaxN], sz[MaxN], nrzone = 1; n pair<int, int> v[MaxN]; n int Find(int x) { n   if (!fth[x]) return x; n   return fth[x] = Find(fth[x]); n } n void Join(int x, int y) { n   int X = Find(x), Y = Find(y); n   if (X != Y) fth[X] = Y; n } n void Solve(int a, int b) { n   if (a < b) { n     fr[sz[Find(a)]]--; n     fr[sz[Find(b)]]--; n     nrzone--; n     fr[sz[Find(a)] + sz[Find(b)]]++; n     sz[Find(b)] += sz[Find(a)]; n     Join(a, b); n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     cin >> v[i].first; n     w[i] = v[i].first; n     v[i].second = i; n   } n   if (n == 1) { n     cout << v[1].first + 1 <<   n ; n     return 0; n   } n   sort(v + 1, v + n + 1); n   v[n + 1].first = v[n].first + 1; n   for (int i = 1; i <= n; ++i) { n     poz[i] = v[i].second; n     w[v[i].second] = i; n   } n   int maxk = 1, nrzonemax = 1; n   fr[1] = 1; n   sz[1] = 1; n   for (int k = 2; k < n; ++k) { n     int pozz = poz[k]; n     fr[1]++; n     nrzone++; n     sz[k] = 1; n     if (pozz != 1) Solve(w[pozz - 1], k); n     if (pozz != n) Solve(w[pozz + 1], k); n     if (fr[sz[Find(k)]] == nrzone && nrzone > nrzonemax) { n       maxk = k; n       nrzonemax = nrzone; n     } n   } n   cout << v[maxk].first + 1 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1000006; n const long long MOD = 1000000007; n struct Query { n   int a, t, x, id; n } query[MAXN]; n map<int, int> cnt; n int n, ans[MAXN], qcnt; n void solve(int l, int r) { n   ; n   if (l != r - 1) { n     int mid = (l + r) >> 1; n     solve(l, mid); n     solve(mid, r); n     cnt.clear(); n     int lp = l, rp = mid; n     while (rp < r) { n       if (lp == mid || query[lp].t > query[rp].t) { n         if (query[rp].a == 3) { n           ; n           ans[query[rp].id] += cnt[query[rp].x]; n         } n         rp++; n       } else { n         if (query[lp].a == 1) { n           cnt[query[lp].x]++; n         } else if (query[lp].a == 2) { n           cnt[query[lp].x]--; n         } n         lp++; n       } n     }; n     sort(query + l, query + r, [&](Query q1, Query q2) { return q1.t < q2.t; }); n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   ; n   cin >> n; n   for (int i = 0; i < n; i++) { n     int a, t, x; n     cin >> a >> t >> x; n     query[i] = {a, t, x, qcnt}; n     ; n     if (a == 3) { n       qcnt++; n     } n   } n   solve(0, n); n   for (int i = 0; i < qcnt; i++) { n     cout << ans[i] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int m; n int a[1 << 7]; n int min_k, max_k; n bool ok(int ask) { n   int need = 0; n   for (int i = 0; i < n; i++) { n     if (a[i] > ask) { n       return false; n     } n     if (ask > a[i]) { n       need += ask - a[i]; n     } n   } n   if (need >= m) { n     return true; n   } n   return false; n } n void read(void) { n   cin >> n; n   cin >> m; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n } n void solve(void) { n   for (int i = 0; i < n; i++) { n     max_k = max(max_k, a[i] + m); n   } n   for (int k = 1; k <= 10100; k++) { n     if (ok(k)) { n       min_k = k; n       break; n     } n   } n } n void print(void) { cout << min_k <<     << max_k << endl; } n int main() { n   read(); n   solve(); n   print(); n   return 0; n } n


#include <bits/stdc++.h> n constexpr int Maxn = 1e5 + 7; n constexpr int Mod = 1e9 + 7; n int fac[Maxn], ifac[Maxn]; n inline int fpm(int a, int b) { n   int res = 1; n   while (b) { n     if (b & 1) res = 1LL * res * a % Mod; n     a = 1LL * a * a % Mod; n     b >>= 1; n   } n   return res; n } n inline int C(int n, int m) { n   if (n < 0 || m < 0 || n < m) return 0; n   return 1LL * fac[n] * ifac[m] % Mod * ifac[n - m] % Mod; n } n std::unordered_map<int, int> cnt, mp; n int n, m, k, f[Maxn], p[Maxn], s[Maxn]; n int solve(int x) { n   if (mp.count(x)) return mp[x]; n   int res = 0; n   for (int i = 0; i <= m; ++i) res = (res + 1LL * p[i] * s[i + x] % Mod) % Mod; n   return mp[x] = res; n } n int main() { n   scanf( %d%d , &n, &k); n   fac[0] = 1; n   for (int i = 1; i <= n; ++i) fac[i] = 1LL * i * fac[i - 1] % Mod; n   ifac[n] = fpm(fac[n], Mod - 2); n   for (int i = n - 1; i >= 0; --i) ifac[i] = 1LL * (i + 1) * ifac[i + 1] % Mod; n   for (int i = 1, x; i <= n; ++i) { n     scanf( %d , &x); n     ++cnt[x]; n   } n   f[0] = k - 1; n   for (int i = 1; i < n; ++i) { n     int p = 1LL * i * fpm(n, Mod - 2) % Mod; n     int q = 1LL * (n - i) * fpm(n, Mod - 2) % Mod * fpm(k - 1, Mod - 2) % Mod; n     f[i] = (1LL * p * f[i - 1] % Mod + 1) * fpm(q, Mod - 2) % Mod; n   } n   for (int i = n; i; --i) s[i - 1] = (s[i] + f[i - 1]) % Mod; n   m = cnt[-1]; n   for (int i = 0; i <= m; ++i) n     p[i] = n         1LL * C(m, i) * fpm(k - 1, m - i) % Mod * fpm(fpm(k, m), Mod - 2) % Mod; n   int res = 0, tot = k; n   for (auto x : cnt) n     if (x.first != -1) { n       res = (res + solve(x.second)) % Mod; n       --tot; n     } n   res = (res + 1LL * tot * solve(0) % Mod) % Mod; n   res = (res - 1LL * (k - 1) * s[0] % Mod + Mod) % Mod; n   printf( %d n , 1LL * res * fpm(k - 1, Mod - 2) % Mod); n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n int main() { n y: n   cin.tie(0); n   cout.tie(0); n   cin.sync_with_stdio(0); n   ; n   ll n = 0, k = 0; n   cin >> n >> k; n   ll a = 0, b = 0; n   ll sum = 0; n   ll pos = 0; n   for (int i = 0; i < k; ++i) { n     cin >> a >> b; n     sum += b; n     pos += a * b; n   } n   if (sum < n) n     cout << 1 <<   n ; n   else { n     if (!(pos % n == (n * (n - 1)) / 2 % n)) n       cout << -1 <<   n ; n     else n       cout << 1 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   int a, n; n   cin >> n >> s; n   for (int i = 0; i < n; ++i) { n     for (int j = 1; j < n + 1; ++j) { n       if (i + 4 * j >= n) break; n       if (s[i] ==  *  && s[i + j] ==  *  && s[i + 2 * j] ==  *  && n           s[i + 3 * j] ==  *  && s[i + 4 * j] ==  * ) { n         printf( yes n ); n         return 0; n       } n     } n   } n   printf( no n ); n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n, m; n   cin >> n >> m; n   vector<vector<vector<int>>> dp(n + 1, n                                  vector<vector<int>>(m + 1, vector<int>(2, 0))); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       dp[i][j][1] = dp[i][j - 1][0] + 1; n       dp[i][j][0] = dp[i - 1][j][1] + 1; n     } n   int ans = 0; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       ans += dp[i][j][0] + dp[i][j][1]; n     } n   ans -= n * m; n   int q; n   cin >> q; n   vector<vector<int>> a(n, vector<int>(m, 1)); n   auto calc_len = [&](int x, int y, int dx, int dy) { n     int res = 0; n     while (1) { n       x += dx; n       y += dy; n       if (x < 0 || y < 0 || x >= n || y >= m || a[x][y] == 0) { n         break; n       } n       res++; n       swap(dx, dy); n     } n     return res; n   }; n   while (q--) { n     int i, j; n     cin >> i >> j; n     i--, j--; n     { n       int x = calc_len(i, j, -1, 0); n       int y = calc_len(i, j, 0, 1); n       ans += (a[i][j] == 1 ? -1 : 1) * ((x + 1) * (y + 1)); n     } n     { n       int x = calc_len(i, j, 0, -1); n       int y = calc_len(i, j, 1, 0); n       ans += (a[i][j] == 1 ? -1 : 1) * ((x + 1) * (y + 1)); n     } n     ans += (a[i][j] == 1 ? 1 : -1); n     a[i][j] ^= 1; n     cout << ans << endl; n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int T = 1; n   while (T--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, a, ans; n set<pair<int, int> > s; n int x, m; n bool used[1000000]; n int solve(int x) { return (x + 1) / (a + 1); } n void go(int x) { n   set<pair<int, int> >::iterator it = s.upper_bound(make_pair(x, 1000000000)); n   --it; n   pair<int, int> cur = *it; n   s.erase(it); n   ans -= solve(cur.second - cur.first + 1); n   if (x != cur.first) { n     ans += solve(x - cur.first); n     s.insert(make_pair(cur.first, x - 1)); n   } n   if (x != cur.second) { n     ans += solve(cur.second - x); n     s.insert(make_pair(x + 1, cur.second)); n   } n } n int main() { n   cin >> n >> k >> a; n   s.insert(make_pair(1, n)); n   ans = solve(n); n   cin >> m; n   for (int i = 1; i <= m; i++) { n     cin >> x; n     if (used[x]) continue; n     used[x] = 1; n     go(x); n     if (ans < k) { n       cout << i; n       return 0; n     } n   } n   cout << -1; n } n


#include <bits/stdc++.h> n using namespace std; n const int N =9999999; n const double pi=acos(-1); n   n int n,t,ans,a[N],k,s1,s2; n int main(){ n  cin>>t; n  while(t--){ n   cin>>n>>k; n   if(n%2==1)cout<<((k-1)+((k-1))/(n/2))%n+1<<endl; n   else cout<<(k-1)%n+1<<endl; n  } n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n inline long long int StrToInt(string& s) { n   long long int ans = 0; n   for (int i = 0; i < s.size(); i++) ans = ans * 10 + s[i] -  0 ; n   return ans; n } n vector<long long int> v, t, pref; n long long int bp(long long int mo) { n   long long int l = 0, r = v.size(), m; n   while (r - l > 1) { n     m = (r + l) / 2; n     if (v[m] > mo) n       r = m; n     else n       l = m; n   } n   return l; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   long long int n; n   cin >> n; n   v.resize(n); n   t.resize(n); n   pref.resize(n + 1); n   for (int i = 0; i < n; i++) cin >> v[i]; n   for (int j = 0; j < n; j++) cin >> t[j]; n   pref[0] = 0; n   for (int i = 1; i <= n; ++i) { n     pref[i] = pref[i - 1] + t[i - 1]; n     v[i - 1] += pref[i - 1]; n   } n   sort(v.begin(), v.end()); n   long long int ans = 0; n   for (int i = 0; i < n; i++) { n     ans = 0; n     long long int m = upper_bound(v.begin(), v.end(), pref[i]) - v.begin(); n     long long int mm = upper_bound(v.begin(), v.end(), pref[i + 1]) - v.begin(); n     ans += (i - mm + 1) * t[i]; n     for (int j = m; j < mm; j++) ans += v[j] - pref[i]; n     cout << ans <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e6 + 10; n string rs; n int pre[maxn]; n void matchprefix() { n   int n = rs.length(); n   pre[0] = 0; n   int k = 0; n   for (int i = 1; i < n; i++) { n     while (k > 0 && rs[k] != rs[i]) k = pre[k - 1]; n     if (rs[k] == rs[i]) k++; n     pre[i] = k; n   } n } n int z[maxn]; n void Z_function() { n   int n = rs.length(); n   z[0] = 0; n   int L = 0, R = 0; n   for (int i = 1; i < n; i++) { n     z[i] = 0; n     if (i <= R) { n       if (z[i - L] < R - i + 1) n         z[i] = z[i - L]; n       else { n         z[i] = min(z[i - L], R - i + 1); n         while (i + z[i] < n && rs[i + z[i]] == rs[z[i]]) z[i]++; n         L = i; n         R = i + z[i] - 1; n       } n     } else { n       while (i + z[i] < n && rs[i + z[i]] == rs[z[i]]) z[i]++; n       L = i; n       R = i + z[i] - 1; n     } n   } n } n int main() { n   string s, t; n   getline(cin, s); n   getline(cin, t); n   int n = s.length(); n   if (n != t.length()) { n     cout <<  -1 -1 ; n     return 0; n   } n   rs = s; n   reverse(rs.begin(), rs.end()); n   rs.push_back(  n ); n   rs += t; n   matchprefix(); n   rs = t +   n  + s +   n ; n   Z_function(); n   int ansi = -1, ansj = -1; n   for (int i = 0; i + 1 < n; i++) { n     if (s[i] != t[n - 1 - i]) break; n     int len_0_i = i + 1; n     int len_i_j = z[n + i + 2]; n     int len_j_n = pre[n + n - i - 1]; n     if (len_j_n > 0 && len_0_i + len_i_j + len_j_n >= n) { n       ansi = i; n       ansj = n - len_j_n; n     } n   } n   cout << ansi <<     << ansj; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s1; n   int count = 0; n   cin >> s1; n   char c = s1[0]; n   for (int i = 0; i < s1.length(); i++) { n     if (s1[i] == c) n       count++; n     else if (s1[i] > c) { n       count = 1; n       c = s1[i]; n     } n   } n   cout << string(count, c); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,no-stack-protector ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC optimize( fast-math ) n #pragma GCC optimize( move-loop-invariants ) n std::mt19937 rnd(237); n using namespace std; n using ll = long long; n using ld = long double; n const int inf = 1e9 + 8; n const ll linf = 4e18 + 18; n const int N = 1e6 + 6; n const double pi = acos(-1.0); n int n; n vector<int> a, b, p, pp; n vector<vector<int>> g; n vector<ll> sum; n ll ans = 0; n void dfs(int v, int par = -1) { n   sum[v] = a[v]; n   for (auto &u : g[v]) { n     if (u != par) dfs(u, v); n   } n   if (sum[v] > 0) { n     if (~par) sum[par] += sum[v]; n     p.push_back(v); n   } else n     pp.push_back(v); n   ans += sum[v]; n } n void solve() { n   cin >> n; n   a.resize(n); n   b = a; n   for (int i = 0; i < n; ++i) { n     cin >> a[i]; n   } n   g.assign(n, {}); n   vector<int> indeg(n, 0); n   for (int i = 0; i < n; ++i) { n     cin >> b[i]; n     if (~b[i]) { n       g[b[i] - 1].push_back(i); n       indeg[i]++; n     } n   } n   sum.resize(n); n   for (int i = 0; i < n; ++i) { n     if (!indeg[i]) dfs(i); n   } n   cout << ans <<   n ; n   for (auto &x : p) cout << x + 1 <<    ; n   for (int i = (int)pp.size() - 1; ~i; --i) cout << pp[i] + 1 <<    ; n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int test_case = 1; n   for (int t = 0; t < test_case; ++t) { n     solve(); n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int f[3][4] = {{0, 3, 1, 2}, {}, {0, 2, 3, 1}}; n void solve(long long x, int y) { n   if (y == 1) { n     printf( %lld n , x); n     return; n   } n   long long ans = 0, p = 1; n   while (x) { n     ans += f[y][x % 4] * p; n     x >>= 2, p <<= 2; n   } n   printf( %lld n , ans); n } n int main() { n   int t; n   scanf( %d , &t); n   while (t--) { n     long long n; n     scanf( %lld , &n); n     long long j = 1, a; n     while (j <= n) j <<= 2; n     j >>= 2; n     if (j + 2 >= n) n       a = j; n     else n       a = j + (n - j) / 3; n     solve(a, n % 3); n   } n } n


#include <bits/stdc++.h> n using namespace std; n string s[1000 + 5]; n int nsc[1000 + 5], nsl[1000 + 5]; n int main() { n   int n, m; n   cin >> n >> m; n   int i, j, z; n   for (i = 0; i < n; i++) cin >> s[i]; n   for (i = 0; i < n; i++) n     for (j = 0; j < m; j++) n       if (s[i][j] ==  * ) nsl[i]++, nsc[j]++; n   long long ans = 0; n   for (i = 0; i < n; i++) n     for (j = 0; j < m; j++) n       if (s[i][j] ==  * ) ans += 1LL * (nsl[i] - 1) * (nsc[j] - 1); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename A, typename B> n inline void chmin(A& a, B b) { n   if (a > b) a = b; n } n template <typename A, typename B> n inline void chmax(A& a, B b) { n   if (a < b) a = b; n } n template <class A, class B> n ostream& operator<<(ostream& ost, const pair<A, B>& p) { n   ost <<  {  << p.first <<  ,  << p.second <<  } ; n   return ost; n } n template <class T> n ostream& operator<<(ostream& ost, const vector<T>& v) { n   ost <<  { ; n   for (long long i = 0; i < v.size(); i++) { n     if (i) ost <<  , ; n     ost << v[i]; n   } n   ost <<  } ; n   return ost; n } n template <class T> n struct BinaryIndexedTree { n   long long n; n   vector<T> dat; n   BinaryIndexedTree(long long n = 0) : n(n), dat(n + 1) {} n   void add(long long k, T x) { n     for (k++; k <= n; k += k & -k) dat[k] += x; n   } n   T sum(long long k) { n     T ret{}; n     for (k++; k; k -= k & -k) ret += dat[k]; n     return ret; n   } n }; n long long N; n long long A[222222]; n long long K[222222], P[222222]; n long long Q; n signed main() { n   scanf( %lld , &N); n   for (long long i = 0; i < (N); i++) scanf( %lld , &A[i]); n   vector<long long> ord(N); n   iota((ord).begin(), (ord).end(), 0); n   sort((ord).begin(), (ord).end(), [&](long long i, long long j) { n     if (A[i] == A[j]) return i < j; n     return A[i] > A[j]; n   }); n   scanf( %lld , &Q); n   vector<vector<long long> > bucket(N); n   for (long long i = 0; i < (Q); i++) { n     scanf( %lld%lld , &K[i], &P[i]); n     K[i]--; n     P[i]--; n     bucket[K[i]].push_back(i); n   } n   BinaryIndexedTree<long long> bit(N + 114); n   vector<long long> ans(Q); n   for (long long i = 0; i < (N); i++) { n     bit.add(ord[i], 1); n     for (auto j : bucket[i]) { n       long long lb = 0, ub = N; n       while (ub - lb > 1) { n         long long mid = (ub + lb) / 2; n         if (bit.sum(mid - 1) <= P[j]) n           lb = mid; n         else n           ub = mid; n       } n       ans[j] = A[lb]; n     } n   } n   for (long long i = 0; i < (Q); i++) printf( %lld n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   long long ans = 0; n   for (int i = (0); i < (n); ++i) { n     long long t, T, x, cost; n     cin >> t >> T >> x >> cost; n     if (t >= T) { n       ans += cost + m * x; n       continue; n     } n     long long aux1 = cost; n     if (m > (T - t)) aux1 += m * x; n     long long aux2 = (long long)ceil((double)(m - (T - t)) / (T - t)) + 1; n     aux2 *= cost; n     ans += min(aux1, aux2); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n int cnt[2], v[2]; n bool f(ll val) { n   ll f[] = {val / v[0], val / v[1]}; n   ll b = v[0] * 1ll * v[1]; n   ll both = val / b; n   ll other = val - f[0] - f[1] + both; n   f[0] -= both; n   f[1] -= both; n   ll tcnt[] = {cnt[0] - f[1], cnt[1] - f[0]}; n   if (tcnt[0] < 0) tcnt[0] = 0; n   if (tcnt[1] < 0) tcnt[1] = 0; n   return (tcnt[0] + tcnt[1] <= other); n } n int main() { n   cin >> cnt[0] >> cnt[1] >> v[0] >> v[1]; n   ll l = 0; n   ll r = ll(1e18); n   while (r - l > 1) { n     ll mid = (l + r) >> 1; n     if (f(mid)) { n       r = mid; n     } else { n       l = mid; n     } n   } n   cout << r << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1); n const double eps = 1e-9; n const int inf = 2000000000; n const long long infLL = 9000000000000000000; n inline bool checkBit(long long n, int i) { return n & (1LL << i); } n inline long long setBit(long long n, int i) { n   return n | (1LL << i); n   ; n } n inline long long resetBit(long long n, int i) { return n & (~(1LL << i)); } n int dx[] = {0, 0, +1, -1}; n int dy[] = {+1, -1, 0, 0}; n inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } n inline bool isLeapYear(long long year) { n   return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0); n } n inline void normal(long long &a) { n   a %= 1000000007; n   (a < 0) && (a += 1000000007); n } n inline long long modMul(long long a, long long b) { n   a %= 1000000007, b %= 1000000007; n   normal(a), normal(b); n   return (a * b) % 1000000007; n } n inline long long modAdd(long long a, long long b) { n   a %= 1000000007, b %= 1000000007; n   normal(a), normal(b); n   return (a + b) % 1000000007; n } n inline long long modSub(long long a, long long b) { n   a %= 1000000007, b %= 1000000007; n   normal(a), normal(b); n   a -= b; n   normal(a); n   return a; n } n inline long long modPow(long long b, long long p) { n   long long r = 1; n   while (p) { n     if (p & 1) r = modMul(r, b); n     b = modMul(b, b); n     p >>= 1; n   } n   return r; n } n inline long long modInverse(long long a) { return modPow(a, 1000000007 - 2); } n inline long long modDiv(long long a, long long b) { n   return modMul(a, modInverse(b)); n } n const int MX = 10100; n int vis[5][5][5], l[5], r[5], curnum, n; n double dp[5][5][5]; n double func(int pos, int eNum, int bNum) { n   if (bNum > 1) return 0; n   if (pos == n) { n     if (eNum > 1 && !bNum) return 1; n     if (eNum && bNum) return 1; n     return 0; n   } n   if (vis[pos][eNum][bNum]) return dp[pos][eNum][bNum]; n   vis[pos][eNum][bNum] = 0; n   double &ret = dp[pos][eNum][bNum]; n   ret = 0; n   if (curnum >= l[pos] && curnum <= r[pos]) { n     double temp = (1.0 / (r[pos] - l[pos] + 1)); n     temp *= func(pos + 1, eNum + 1, bNum); n     ret += temp; n   } n   if (r[pos] > curnum) { n     double temp = 1; n     if (l[pos] <= curnum) { n       temp *= (double)(r[pos] - curnum) / (double)(r[pos] - l[pos] + 1); n     } n     temp *= func(pos + 1, eNum, bNum + 1); n     ret += temp; n   } n   if (l[pos] < curnum) { n     double temp = 1; n     if (r[pos] >= curnum) { n       temp *= (double)(curnum - l[pos]) / (double)(r[pos] - l[pos] + 1); n     } n     temp *= func(pos + 1, eNum, bNum); n     ret += temp; n   } n   return ret; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   cout.unsetf(ios::floatfield); n   cout.precision(10); n   cout.setf(ios::fixed, ios::floatfield); n   ; n   cin >> n; n   for (int i = 0; i < n; ++i) cin >> l[i] >> r[i]; n   double ans = 0; n   for (int i = 1; i < MX; ++i) { n     curnum = i; n     ans += i * func(0, 0, 0); n     ; n     memset(vis, 0, sizeof(vis)); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n const int N = 5050; n int n, t, v = -1, w, p[N], c[N], d[N], l[N]; n void U(int x, int* y) { n   for (int u = x + 1; u <= n; u += u & -u) ++y[u]; n } n int Q(int x, int* y) { n   int s = 0; n   while (x > 0) s += y[x], x -= x & -x; n   return s; n } n int main() { n   scanf( %d , &n); n   for (int i = 0, s; i < n && 1 == scanf( %d , &p[i]); ++i) n     s = Q(p[i], c), l[i] = s, t += i - s, U(p[i], c); n   for (int i = 0; i < n; U(p[i++], d)) n     for (int j = i + 1, a = 0, b; j < n; ++j) n       if (p[j] < p[i]) { n         b = l[j] - Q(p[j], d); n         if (a - b > v) n           v = a - b, w = 1; n         else if (a - b == v) n           ++w; n         ++a; n       } n   printf( %d %d n , t - v - v - 1, w); n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> ve[100005]; n long long vis[100005] = {0}, z = 0, i; n void solve() { n   vector<long long> v; n   vector<pair<long long, long long> > vp; n   map<long long, long long> mp, mpp; n   map<long long, long long>::iterator itr; n   long long n = 0, m = 0, i = 0, j = 0, k = 0, c = 0, l = 0, r = 0, p = 0, n             q = 0, x = 0, y = 0, z = 0, flag = 0, sum = 0; n   long long a[300005] = {0}, b[1005] = {0}, ans[25][25]; n   long long s, t; n   cin >> n; n   for (i = 0; i < pow(n, 2); i++) cin >> a[i]; n   for (i = 0; i < pow(n, 2); i++) b[a[i]]++; n   for (i = 0; i < 1001; i++) n     if (b[i] > 0) vp.push_back(make_pair(b[i], i)); n   sort(vp.begin(), vp.end()); n   z = vp.size() - 1; n   for (j = 0; j < n / 2; j++) { n     for (i = 0; i < n / 2; i++) { n       if (vp[z].first >= 4) { n         k = vp[z].second; n         vp[z].first -= 4; n         ans[i][j] = k; n         ans[n - i - 1][j] = k; n         ans[i][n - j - 1] = k; n         ans[n - i - 1][n - j - 1] = k; n       } else { n         z--; n         i--; n       } n       if (z == -1) { n         cout <<  No  << endl; n         return; n       } n     } n   } n   if (n % 2 == 1) { n     s = (n - 1) / 2; n     sort(vp.begin(), vp.end()); n     z = vp.size() - 1; n     for (i = 0; i < n / 2; i++) { n       if (vp[z].first >= 2) { n         k = vp[z].second; n         vp[z].first -= 2; n         ans[s][i] = k; n         ans[s][n - i - 1] = k; n       } else { n         z--; n         i--; n       } n       if (z == -1) { n         cout <<  No  << endl; n         return; n       } n     } n     sort(vp.begin(), vp.end()); n     z = vp.size() - 1; n     for (i = 0; i < n / 2; i++) { n       if (vp[z].first >= 2) { n         k = vp[z].second; n         vp[z].first -= 2; n         ans[i][s] = k; n         ans[n - i - 1][s] = k; n       } else { n         z--; n         i--; n       } n       if (z == -1) { n         cout <<  No  << endl; n         return; n       } n     } n     sort(vp.begin(), vp.end()); n     z = vp.size() - 1; n     ans[s][s] = vp[z].second; n   } n   for (i = 0; i < n; i++) n     for (j = 0; j < n; j++) n       if (ans[i][j] == 0) { n         cout <<  No  << endl; n         return; n       } n   cout <<  Yes  << endl; n   for (i = 0; i < n; i++) { n     for (j = 0; j < n; j++) cout << ans[i][j] <<     ; n     cout << endl; n   } n } n bool imp = false; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t = 1; n   if (imp) cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bitset<300000001> b; n int main() { n   int l, r, c = 0, i, j; n   cin >> l >> r; n   for (i = 3; i * i <= r; i += 2) n     for (j = i * i; b[i] == 0 and j <= r; j += i) b[j] = 1; n   if (l <= 2 and r >= 2) c = 1; n   for (i = 5; i <= r; i += 4) c += !b[i] and i >= l; n   cout << c; n } n


#include <bits/stdc++.h> n using namespace std; n int b[4], c, n, l = 0, a, i; n int main() { n   scanf( %d , &n); n   for (i = 0; i < n; i++) { n     scanf( %d , &a); n     b[a]++; n   } n   cout << n - max(b[1], max(b[2], b[3])) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1000 * 1000 * 1000 + 7; n const double EPS = 1e-9; n int bit_count(int first) { n   return first == 0 ? 0 : 1 + bit_count(first & (first - 1)); n } n inline int low_bit(int first) { return first & -first; } n inline int sign(double first) { n   return first < -EPS ? -1 : first > EPS ? 1 : 0; n } n inline int sign(int first) { return (first > 0) - (first < 0); } n int nextComb(int first) { n   if (!first) { n     fprintf(stderr,  nextComb(0) called n ); n     return ((1 << 30) - 1 + (1 << 30)); n   } n   int smallest = first & -first; n   int ripple = first + smallest; n   int ones = first ^ ripple; n   ones = (ones >> 2) / smallest; n   return ripple | ones; n } n template <class T> n inline T gcd(T a, T b) { n   a = abs(a); n   b = abs(b); n   while (b) { n     int r = a % b; n     a = b; n     b = r; n   } n   return a; n } n template <class T> n inline T lcm(T a, T b) { n   return a / gcd(a, b) * b; n } n inline int getInt() { n   int a; n   return scanf( %d , &a) ? a : (fprintf(stderr,  trying to read n ), -1); n } n inline double getDouble() { n   double a; n   return scanf( %lf , &a) ? a : (fprintf(stderr,  trying to read n ), -1.0); n } n inline double myRand() { n   return ((double)rand() / RAND_MAX) + ((double)rand() / RAND_MAX / RAND_MAX); n } n inline string getLine() { n   string ret; n   getline(cin, ret,  : ); n   return ret; n } n long long process(string s, int base) { n   long long ret = 0; n   for (int i = (int)0; i < (int)((int)(s).size()); ++i) { n     ret *= base; n     if (isdigit(s[i])) n       ret += s[i] -  0 ; n     else n       ret += s[i] -  A  + 10; n   } n   return ret; n } n bool isValid(string s, int base) { n   for (int i = (int)0; i < (int)((int)(s).size()); ++i) { n     if (isdigit(s[i]) && s[i] -  0  >= base) n       return false; n     else if (s[i] -  A  + 10 >= base) n       return false; n   } n   return true; n } n void myCode() { n   string hrs, mins; n   getline(cin, hrs,  : ); n   getline(cin, mins); n   vector<int> ret; n   if (((int)(hrs).size()) < 6 && ((int)(mins).size()) < 7) { n     for (int i = (int)2; i < (int)100; ++i) { n       if (isValid(hrs, i) == true && isValid(mins, i) == true) { n         if (process(hrs, i) < 24 && process(mins, i) < 60) { n           ret.push_back(i); n         } n       } n     } n   } n   if (ret.empty()) n     printf( 0 n ); n   else if (ret[((int)(ret).size()) - 1] == 99) n     printf( -1 n ); n   else n     for (int i = (int)0; i < (int)((int)(ret).size()); ++i) n       printf( %d%c , ret[i], i == ((int)(ret).size()) - 1 ?   n  :    ); n } n int main() { n   srand(time(NULL)); n   myCode(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, k; n   cin >> n >> k; n   bool count[26] = {0}; n   char c; n   for (int i = 0; i < n; i++) { n     cin >> c; n     count[c -  a ] = true; n   } n   int e = -4; n   int res = 0; n   for (int i = 0; i < 26; i++) { n     if ((!count[i]) || (i - e) < 2) continue; n     res += i + 1; n     e = i; n     k--; n     if (k == 0) break; n   } n   if (k > 0) { n     cout <<  -1 n ; n   } else n     cout << res <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   ; n   int n; n   cin >> n; n   int k; n   cin >> k; n   string s; n   cin >> s; n   int ig = -1, it = -1; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  G ) { n       ig = i; n     } n     if (s[i] ==  T ) { n       it = i; n     } n   } n   if (it % k != ig % k) { n     cout <<  NO  << endl; n   } else { n     if (ig < it) { n       swap(it, ig); n     } n     for (int i = it; i <= ig; i++) { n       if (s[i] ==  #  && (i % k) == (ig % k)) { n         cout <<  NO  << endl; n         return 0; n       } n     } n     cout <<  YES  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1005; n const long long mod = 1000000007; n int grid[maxn][maxn]; n inline void fast() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(0); n } n int main() { n   fast(); n   int h, w; n   cin >> h >> w; n   for (int i = 0; i < h; i++) { n     int x; n     cin >> x; n     for (int j = 0; j < x; j++) grid[i][j] = 1; n     grid[i][x] = 2; n   } n   for (int j = 0; j < w; j++) { n     int x; n     cin >> x; n     for (int i = 0; i < x; i++) { n       if (grid[i][j] == 2) { n         cout << 0 << endl; n         return 0; n       } n       grid[i][j] = 1; n     } n     if (grid[x][j] == 1) { n       cout << 0 << endl; n       return 0; n     } n     grid[x][j] = 2; n   } n   int ans = 1; n   for (int i = 0; i < h; i++) n     for (int j = 0; j < w; j++) { n       if (grid[i][j] == 0) { n         ans = ans * 2 % mod; n       } n     } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6; n string b[maxn]; n int p[maxn], n[maxn]; n void get_id(string); n bool is_legal(string); n int main() { n   int N; n   scanf( %d , &N); n   memset(p, 0, sizeof(p)); n   memset(n, 0, sizeof(n)); n   for (int i = 0; i < N; i++) { n     cin >> b[i]; n     get_id(b[i]); n   } n   int ans = 0; n   ans += (p[0] / 2); n   for (int i = 1; i < maxn; i++) { n     ans += min(p[i], n[i]); n   } n   printf( %d n , ans); n   return 0; n } n void get_id(string c) { n   if (is_legal(c)) { n     p[0]++; n     return; n   } n   int len = c.size(); n   int count = 0; n   bool find = false; n   for (int i = 0; i < len; i++) { n     if (c[i] ==  ( ) n       count++; n     else n       count--; n     if (count < 0) find = true; n   } n   if (count > 0 && !find) p[count]++; n   find = false; n   count = 0; n   for (int i = len - 1; i >= 0; i--) { n     if (c[i] ==  ) ) n       count++; n     else n       count--; n     if (count < 0) find = true; n   } n   if (count > 0 && !find) n[count]++; n } n bool is_legal(string c) { n   int len = c.size(); n   int count = 0; n   for (int i = 0; i < len; i++) { n     if (c[i] ==  ( ) n       count++; n     else n       count--; n     if (count < 0) return false; n   } n   if (!count) n     return true; n   else n     return false; n } n


#include <bits/stdc++.h> n int n, K; n int ch[60000][26]; n int val[60000]; n char st[1000]; n int f[60000][1000]; n int knum; n void add(char *st) { n   int m = strlen(st + 1); n   int u = 0; n   for (int i = 1; i <= m; i++) { n     if (!ch[u][st[i] -  a ]) { n       knum++; n       ch[u][st[i] -  a ] = knum; n     } n     u = ch[u][st[i] -  a ]; n   } n   val[u]++; n } n void dfs(int u) { n   for (int i = 0; i < 26; i++) { n     int v = ch[u][i]; n     if (v) { n       dfs(v); n     } n   } n   for (int i = 0; i <= K; i++) { n     f[u][i] = -1000000000; n   } n   f[u][0] = 0; n   for (int i = 0; i < 26; i++) { n     int v = ch[u][i]; n     if (v) { n       for (int j = K; j >= 0; j--) { n         for (int k = 0; k <= j; k++) { n           f[u][j] = std::max(f[u][j], f[u][j - k] + f[v][k] + k * (k - 1) / 2); n         } n       } n     } n   } n   for (int i = K; i >= 0; i--) { n     for (int j = 0; j <= std::min(i, val[u]); j++) { n       f[u][i] = std::max(f[u][i], f[u][i - j]); n     } n   } n } n int main() { n   knum = 0; n   scanf( %d%d , &n, &K); n   for (int i = 1; i <= n; i++) { n     scanf( %s , st + 1); n     add(st); n   } n   dfs(0); n   printf( %d n , f[0][K]); n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:100000000 ) n using namespace std; n int n; n string s; n string A[] = { 123456 ,  154236 ,  145326 ,  516324 ,  261453 ,  132546 }; n string B[] = { 123456 ,  523164 ,  623541 ,  423615 }; n vector<string> P; n vector<string> T; n vector<string> H; n bool BB[1000]; n bool F(string a, string b) { n   for (long long(i) = (0); (i) < (T.size()); ++(i)) { n     string t = a; n     for (long long(j) = (0); (j) < (6); ++(j)) t[j] = a[T[i][j] -  0 ]; n     if (t == b) return true; n   } n   return false; n } n int main() { n   cin >> s; n   int Q[6]; n   for (long long(i) = (0); (i) < (6); ++(i)) Q[i] = i; n   do { n     string p =   ; n     for (long long(i) = (0); (i) < (6); ++(i)) p += char( 0  + Q[i]); n     P.push_back(p); n   } while (next_permutation(Q, Q + 6)); n   for (long long(i) = (0); (i) < (6); ++(i)) n     for (long long(j) = (0); (j) < (4); ++(j)) { n       string t = A[i]; n       string p = t; n       for (long long(k) = (0); (k) < (6); ++(k)) { n         int x = B[j][k] -  0 ; n         x--; n         p[k] = t[x]; n         p[k]--; n       } n       T.push_back(p); n     } n   for (long long(i) = (0); (i) < (P.size()); ++(i)) { n     string t =   ; n     for (long long(j) = (0); (j) < (6); ++(j)) t += s[P[i][j] -  0 ]; n     H.push_back(t); n   } n   int res = 0; n   for (long long(i) = (0); (i) < (H.size()); ++(i)) n     if (BB[i] == false) { n       res++; n       for (long long(j) = (i + 1); (j) < (H.size()); ++(j)) n         if (F(H[i], H[j])) BB[j] = true; n     } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     long long a, b, c, d; n     cin >> a >> b >> c >> d; n     if (a > b * c) n       cout << -1 <<   n ; n     else { n       long long k = (a / (b * d)); n       cout << a * (k + 1) - k * (k + 1) / 2 * b * d <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long m, l, r, k, ans; n map<long long, long long> F; n long long f(long long n) { n   if (F.count(n)) return F[n]; n   long long k = n / 2; n   if (n % 2 == 0) return F[n] = (f(k) * f(k) + f(k - 1) * f(k - 1)) % m; n   return F[n] = (f(k) * f(k + 1) + f(k - 1) * f(k)) % m; n } n vector<long long> poss; n void get(long long x) { n   for (long long i = 1, la; i <= x; i = la + 1) { n     la = x / (x / i); n     poss.push_back(la); n   } n } n int32_t main() { n   cin >> m >> l >> r >> k; n   get(l - 1), get(r); n   for (auto i : poss) n     if (r / i - (l - 1) / i >= k) ans = max(ans, i); n   F[0] = F[1] = 1 % m; n   cout << f(ans - 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e6 + 3; n long long n, x, a, cnt, ans, sum; n string g; n deque<long long> v; n void DNM() { n   cin >> n; n   for (long long i = 0; i < n; i++) { n     cin >> a; n     v.push_back(a); n     if (a > 0) cnt = i; n   } n   for (long long i = 0; i <= cnt; i++) { n     if (i == cnt and i == n - 1) { n       for (long long j = 1; j <= v[i]; j++) { n         if (j == v[i]) n           g +=  P ; n         else n           g +=  P , g +=  L , g +=  R ; n       } n       break; n     } n     for (long long j = 0; j < v[i]; j++) { n       g +=  P ; n       g +=  R ; n       g +=  L ; n     } n     g +=  R ; n   } n   cout << g << endl; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   int Qu_l_uQ = 1; n   while (Qu_l_uQ--) DNM(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, l, r, p, q, w[100000 + 2], ans = 2100000000, sum = 0, sub = 0; n   scanf( %d%d%d%d%d , &n, &l, &r, &p, &q); n   for (int i = 0; i < n; i++) { n     scanf( %d , &w[i]); n     sum += w[i]; n   } n   for (int i = 0; i <= n; i++) { n     int ret = sum * r + sub * l; n     if (i <= n - i) { n       ret += max(0, n - i - i - 1) * q; n     } else { n       ret += max(0, i - n + i - 1) * p; n     } n     if (ret < ans) ans = ret; n     if (i != n) { n       sum -= w[i]; n       sub += w[i]; n     } n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     long long n, i, g = 0, s = 0, b = 0, j; n     cin >> n; n     long long a[n]; n     vector<long long> v(n, 1); n     for (i = 0; i < n; i++) { n       cin >> a[i]; n     } n     if (n < 6) n       cout <<  0 0 0 n ; n     else { n       for (i = 0; i < n - 1; i++) { n         if (a[i] == a[i + 1]) v[i + 1] = v[i] + 1; n       } n       for (i = 0; i < n - 1; i++) { n         if (a[i] != a[i + 1]) { n           g = g + v[i]; n           break; n         } n       } n       for (j = i + 1; j < n - 1; j++) { n         if (a[j] != a[j + 1] && j < n / 2) { n           s = s + v[j]; n           if (s > g) { n             break; n           } n         } n       } n       for (long long l = j + 1; l < n - 1; l++) { n         if (l < n / 2 && a[l] != a[l + 1]) { n           b = b + v[l]; n         } n       } n       if (g > 0 && s > 0 && b > 0 && g < s && g < b) { n         cout << g <<     << s <<     << b <<   n ; n       } else n         cout <<  0 0 0 n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   long long int n, k; n   cin >> n >> k; n   long long int arr1[n], arr2[n]; n   for (long long int i = 0; i < n; i++) cin >> arr1[i]; n   for (long long int i = 0; i < n; i++) cin >> arr2[i]; n   multiset<pair<long long int, pair<long long int, long long int> > > s; n   for (long long int i = 0; i < n; i++) { n     s.insert(make_pair(arr2[i] / arr1[i], make_pair(arr1[i], arr2[i]))); n   } n   multiset<pair<long long int, pair<long long int, long long int> > >::iterator n       it1; n   while (true) { n     pair<long long int, pair<long long int, long long int> > pp = *s.begin(); n     long long int num = pp.first, a = pp.second.first, b = pp.second.second; n     long long int req = a - (b % a); n     if (k >= req) { n       k -= req; n       s.erase(s.begin()); n       s.insert(make_pair(num + 1, make_pair(a, b + req))); n     } else { n       break; n     } n   } n   it1 = s.begin(); n   cout << it1->first; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[100010], w[100010], h[100010]; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) scanf( %d%d , &w[i], &h[i]); n   ; n   a[n] = min(w[n], h[n]); n   for (int i = n - 1; i >= 1; i--) { n     if (min(w[i], h[i]) >= a[i + 1]) n       a[i] = min(w[i], h[i]); n     else n       a[i] = max(w[i], h[i]); n     if (a[i] < a[i + 1]) { n       printf( NO ); n       return 0; n     } n   } n   printf( YES ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1000000 + 10; n const int inf = (-1u) >> 1; n bool v[maxn]; n int n, m, k, num; n vector<int> g[maxn]; n void dfs(int x) { n   v[x] = true; n   ++num; n   for (vector<int>::iterator it = g[x].begin(); it != g[x].end(); ++it) { n     if (!v[*it]) { n       dfs(*it); n     } n   } n } n int main() { n   while (scanf( %d%d%d , &n, &m, &k) != EOF) { n     for (int i = 0; i < (n); ++i) { n       g[i].clear(); n       v[i] = false; n     } n     for (int i = 0; i < (m); ++i) { n       int a, b; n       scanf( %d%d , &a, &b); n       --a, --b; n       g[a].push_back(b), g[b].push_back(a); n     } n     int cnt = 0, ecnt = 0, totcnt = 0; n     for (int i = 0; i < (n); ++i) n       if (!v[i]) { n         num = 0; n         dfs(i); n         ++totcnt; n         if (num == 1) { n           ++cnt; n         } else { n           ecnt += min(k, num) - 2; n         } n       } n     if (k >= 2) { n       ecnt += 2; n       cnt -= ecnt; n       if (totcnt > cnt) cnt += 2; n       printf( %d n , max(0, (cnt - 1) / 2)); n     } else { n       printf( %d n , max(0, totcnt - 2)); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 66; n long long n, k, a[maxn], d[maxn][maxn]; n int main(void) { n   cin >> n >> k; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n     a[i] += a[i - 1]; n   } n   long long rt = 0; n   for (int i = 55; i >= 0; --i) { n     rt += ((1LL * 1) << i); n     memset(d, 0, sizeof(d)); n     d[0][0] = 1; n     for (int j = 1; j <= n; ++j) { n       for (int q = 1; q <= j; ++q) { n         for (int w = j - 1; w >= q - 1; --w) { n           if (((a[j] - a[w]) & rt) < rt) continue; n           if (d[w][q - 1] == 1) d[j][q] = 1; n         } n       } n     } n     if (d[n][k] == 0) rt -= ((1LL * 1) << i); n   } n   cout << rt << endl; n } n


#include <bits/stdc++.h> n using namespace std; n char xB[1 << 15], *xS = xB, *xTT = xB; n template <typename T> n inline void rd(T& xaa) { n   char xchh; n   T f = 1; n   xaa = 0; n   while (xchh = (xS == xTT && (xTT = (xS = xB) + fread(xB, 1, 1 << 15, stdin), n                                xS == xTT) n                      ? 0 n                      : *xS++), n          !((xchh >=  0  && xchh <=  9 ) || (xchh ==  - ))) n     ; n   if (xchh ==  - ) { n     f = -1; n     xchh = (xS == xTT && n                     (xTT = (xS = xB) + fread(xB, 1, 1 << 15, stdin), xS == xTT) n                 ? 0 n                 : *xS++); n   } n   xaa = xchh -  0 ; n   while (xchh = (xS == xTT && (xTT = (xS = xB) + fread(xB, 1, 1 << 15, stdin), n                                xS == xTT) n                      ? 0 n                      : *xS++), n          ((xchh >=  0  && xchh <=  9 ) || (xchh ==  - ))) n     xaa = xaa * 10 + xchh -  0 ; n   xaa *= f; n   return; n } n long long geta(long long x, long long y, long long a, long long b) { n   return x * a + y * b; n } n long long getb(long long x, long long y, long long a, long long b) { n   return x * b - y * a; n } n int n; n long long a, b, res; n int main() { n   rd(n); n   rd(a); n   rd(b); n   map<long long, vector<long long> > val; n   for (int i = 1; i <= n; i++) { n     long long e, x, y; n     rd(e); n     rd(x); n     rd(y); n     long long px = geta(x, y, 1, a), py = getb(x, y, 1, a); n     val[py].push_back(px); n   } n   long long res = 0; n   for (map<long long, vector<long long> >::iterator it = val.begin(); n        it != val.end(); it++) { n     vector<long long>& tv = it->second; n     sort(tv.begin(), tv.end()); n     long long nv = 0, nc = 0; n     bool st = 0; n     int len = static_cast<int>(tv.size()); n     for (vector<long long>::iterator it1 = tv.begin(); it1 != tv.end(); it1++) { n       if (!st) { n         nv = *it1; n         nc = 1; n         st = 1; n       } else { n         if (*it1 == nv) n           nc++; n         else { n           res += nc * (len - nc); n           nv = *it1; n           nc = 1; n         } n       } n     } n     res += nc * (len - nc); n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1000000007; n long long mod2 = 998244353; n long long mod3 = 1000003; n long long mod4 = 998244853; n long long inf = 1LL << 60; n long double pi = 3.14159265358979323846L; n double eps = 1e-12; n int dh[4] = {1, -1, 0, 0}; n int dw[4] = {0, 0, 1, -1}; n int ddh[8] = {-1, -1, -1, 0, 0, 1, 1, 1}; n int ddw[8] = {-1, 0, 1, -1, 1, -1, 0, 1}; n long long gcd(long long a, long long b) { n   if (a < b) swap(a, b); n   if (b == 0) return a; n   if (a % b == 0) return b; n   return gcd(b, a % b); n } n long long Pow(long long n, long long k) { n   long long ret = 1; n   long long now = n; n   while (k > 0) { n     if (k & 1) ret *= now; n     now *= now; n     k /= 2; n   } n   return ret; n } n long long beki(long long n, long long k, long long md) { n   long long ret = 1; n   long long now = n; n   while (k > 0) { n     if (k % 2 == 1) { n       ret *= now; n       ret %= md; n     } n     now *= now; n     now %= md; n     k /= 2; n   } n   return ret; n } n long long gyaku(long long n, long long md) { return beki(n, md - 2, md); } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   for (long long i = 0; i < t; i++) { n     long long n, m; n     cin >> n >> m; n     long long a[m]; n     long long sum = 0; n     unordered_map<long long, long long> mp; n     for (long long j = 0; j < m; j++) { n       cin >> a[j]; n       sum += a[j]; n       mp[a[j]]++; n     } n     if (sum < n) { n       cout << -1 << endl; n       continue; n     } n     unordered_map<long long, bool> ok; n     long long nn = n; n     for (long long j = 0; j < 60; j++) { n       long long now = 1LL << j; n       if (nn % 2) { n         ok[now] = false; n       } else n         ok[now] = true; n       nn /= 2; n     } n     long long now = 1; n     sum = 0; n     set<long long> st; n     long long ans = 0; n     for (;;) { n       sum += mp[now] * now; n       if (mp[now] > 0) { n         long long u = *st.begin(); n         long long uu = now; n         while (uu > u) { n           ans++; n           uu /= 2; n         } n         for (auto itr = st.begin(); itr != st.end(); itr++) { n           sum -= *itr; n         } n         st.clear(); n       } n       if (ok[now] == false) { n         if (sum >= now) { n           sum -= now; n           ok[now] = true; n         } else { n           st.insert(now); n         } n       } n       now *= 2; n       if (now > 1000000000000000000) break; n     } n     cout << ans << endl; n   } n } n


#include<bits/stdc++.h> n #include<math.h> n  n using namespace std; n  n #define ll long long n  n #define endl   n  n  n #define pb push_back n  n #define eraseO(s, x) if(s.find(x) != s.end()) { s.erase(s.lower_bound(x)); } n  n #define vi vector<int> n  n #define vc vector<char> n  n #define vl vector<ll> n  n #define ip pair<int, int> n  n #define cip pair<int, char> n  n #define vip vector<ip> n  n #define msi multiset<int> n  n #define REP(d, i) for(int i = 0; i < d; ++i) n  n #define REPD(d, i) for(int i = d - 1; i >= 0; i--) n  n #define REPM(d, d1, i, j) for(int i = 0; i < d; ++i){for(int j = 0; j < d1; ++j) n  n #define REPV(v, i) REP(v.size(), i) n  n #define REPVD(v, i) REPD(v.size(), i) n  n #define FOR(d) REP(d, i) n  n #define FORD(d) REPD(d, i) n  n #define FORM(d, d1) REPM(d, d1, i, j) n  n #define FORV(v) REPV(v, i) n  n #define FORVD(v) REPVD(v, i) n  n #define INA(a, d) FOR(d) { cin >> a[i]; } n  n #define INM(a, d, d1) FORM(d, d1) { cin >> a[i][j];}} n  n #define OUTA(a, d) FOR(d) { cout << a[i] <<    ; } n  n #define OUTV(a) FORV(a) { cout << a[i] <<    ; } n  n #define OUTM(c, d, d1) FORM(d, d1) { cout << c[i][j] <<    ; } cout << endl;} n  n void solve() { n  n     int n; n     cin >> n; n  n     map<int, int> oc1; n     map<int, int> ec1; n     map<int, int> oc2; n     map<int, int> ec2; n  n     set<int> nums; n  n     int a[n]; n     INA(a, n); n  n     FOR(n) { n         if(i % 2) { n             oc1[a[i]]++; n         } else { n             ec1[a[i]]++; n         } n         nums.insert(a[i]); n     } n     sort(a, a + n); n  n     FOR(n) { n         if(i % 2) { n             oc2[a[i]]++; n         } else { n             ec2[a[i]]++; n         } n     } n  n     bool ok = 1; n  n     for(int i : nums) { n         if(oc1[i] != oc2[i] || ec1[i] != ec2[i]) { n             ok = 0; n         } n     } n  n     if(ok) { n         cout <<  YES  << endl; n     } else { n         cout <<  NO  << endl; n     } n } n  n int main() { n     ios_base::sync_with_stdio(false); n     cin.tie(NULL); n     int t; n     cin >> t; n     FOR(t) { n         solve(); n     } n } n


#include <bits/stdc++.h> n using namespace std; n int a[100] = {0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 15, 4}; n int n; n int main() { n   scanf( %d , &n); n   if (n <= 10) n     puts( 0 ); n   else n     printf( %d n , a[n - 10]); n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = (int)2e9; n const long long INFL = (long long)9e18; n const int MAXINT = ((~0) ^ (1 << 31)); n const long long MAXLL = ((~0) ^ ((long long)1 << 63)); n template <class T> n inline T pow2(T a) { n   return a * a; n } n template <class T> n inline bool mineq(T& a, T b) { n   return (a > b) ? (a = b, true) : false; n } n template <class T> n inline bool maxeq(T& a, T b) { n   return (a < b) ? (a = b, true) : false; n } n const int maxn = 2e2, maxn2 = 1e5, mod = 1e9 + 7; n long long n, b, k, x, m[40][maxn][maxn], a[maxn2], res[maxn][maxn]; n void mul(long long n, long long ans[maxn][maxn], long long a[maxn][maxn], n          long long b[maxn][maxn]) { n   long long t[maxn][maxn]; n   for (int i = 0; i < n; i++) memset(t[i], 0, sizeof t[i]); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       for (int z = 0; z < n; z++) n         t[i][j] = (t[i][j] + (a[i][z] * b[z][j] + mod) % mod + mod) % mod; n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) ans[i][j] = t[i][j]; n   } n } n void pow(long long n, long long ans[maxn][maxn], long long t[maxn][maxn], n          long long k) { n   for (int i = 0; i < n; i++) memset(ans[i], 0, sizeof ans[i]); n   if (k == 0) { n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < n; j++) ans[i][j] = (i == j); n     } n     return; n   } n   pow(n, ans, t, k / 2); n   mul(n, ans, ans, ans); n   if (k % 2 != 0) mul(n, ans, t, ans); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n >> b >> k >> x; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < x; i++) { n     for (int j = 0; j < n; j++) m[0][i][(10 * i + a[j]) % x]++; n   } n   for (int i = 1; i < 40; i++) mul(x, m[i], m[i - 1], m[i - 1]); n   pow(x, res, m[0], b); n   cout << res[0][k]; n } n


#include <bits/stdc++.h> n const int N = 5e4 + 5; n struct Point { n   int x, y, z, id; n   void input() { scanf( %d%d%d , &x, &y, &z); } n } a[N]; n int main() { n   std::map<std::pair<int, int>, std::vector<Point> > f; n   std::map<int, std::vector<Point> > g; n   std::vector<Point> h; n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     a[i].input(); n     a[i].id = i; n     f[std::pair<int, int>(a[i].x, a[i].y)].push_back(a[i]); n   } n   for (auto &p : f) { n     auto &v = p.second; n     std::sort(v.begin(), v.end(), n               [](const Point &a, const Point &b) { return a.z < b.z; }); n     if (v.size() & 1) g[v.back().x].push_back(v.back()), v.pop_back(); n     for (int i = 0; i < v.size(); i += 2) n       printf( %d %d n , v[i].id, v[i + 1].id); n   } n   for (auto &p : g) { n     auto &v = p.second; n     std::sort(v.begin(), v.end(), n               [](const Point &a, const Point &b) { return a.y < b.y; }); n     if (v.size() & 1) h.push_back(v.back()), v.pop_back(); n     for (int i = 0; i < v.size(); i += 2) n       printf( %d %d n , v[i].id, v[i + 1].id); n   } n   for (int i = 0; i < h.size(); i += 2) printf( %d %d n , h[i].id, h[i + 1].id); n   return 0; n } n