#include <bits/stdc++.h> n class Scanner { n  private: n   static const int BUFFER_SIZE = 1 << 18; n   char buff[BUFFER_SIZE]; n   char *buffPos, *buffLim; n   FILE* file; n  n  public: n   Scanner(FILE* file) { n     this->file = file; n     buffLim = buff + fread(buff, 1, BUFFER_SIZE, file); n     buffPos = buff; n   } n  n  private: n   inline void flushBuff() { n     buffLim = buff + fread(buff, 1, BUFFER_SIZE, file); n     if (buffLim == buff) { n       *buffLim++ =   n ; n     } n     buffPos = buff; n   } n   inline bool isWS(char t) { return t <=    ; } n   inline bool isDig(char t) { return t >=  0  && t <=  9 ; } n   inline void nextPos() { n     buffPos++; n     if (buffPos == buffLim) { n       flushBuff(); n     } n   } n  n  public: n   inline char getchar() { n     char ch = *buffPos; n     nextPos(); n     return ch; n   } n   inline void next(char* s) { n     while (isWS(*buffPos)) { n       nextPos(); n     } n     while (!isWS(*buffPos)) { n       *s = *buffPos; n       s++; n       nextPos(); n     } n     *s =   0 ; n   } n   inline void nextLine(char* s) { n     while (*buffPos !=   n ) { n       nextPos(); n     } n     if (*buffPos ==   n ) { n       nextPos(); n     } n     while (*buffPos !=   n ) { n       *s++ = *buffPos; n       nextPos(); n     } n     *s =   0 ; n   } n   inline int nextInt() { n     while (!isDig(*buffPos) && *buffPos !=  - ) { n       nextPos(); n     } n     int sign = (*buffPos ==  - ) ? nextPos(), -1 : 1; n     int res = 0; n     while (isDig(*buffPos)) { n       res = res * 10 + *buffPos -  0 ; n       nextPos(); n     } n     return res * sign; n   } n   inline long long nextLong() { n     while (!isDig(*buffPos) && *buffPos !=  - ) { n       nextPos(); n     } n     long long sign = (*buffPos ==  - ) ? nextPos(), -1 : 1; n     long long res = 0; n     while (isDig(*buffPos)) { n       res = res * 10 + *buffPos -  0 ; n       nextPos(); n     } n     return res * sign; n   } n   inline int n() { n     while (*buffPos <  0  || *buffPos >  9 ) { n       buffPos++; n       if (buffPos == buffLim) { n         flushBuff(); n       } n     } n     int res = 0; n     while (*buffPos >=  0  && *buffPos <=  9 ) { n       res = res * 10 + (*buffPos -  0 ); n       buffPos++; n       if (buffPos == buffLim) { n         flushBuff(); n       } n     } n     return res; n   } n   inline long long nl() { n     while (*buffPos <  0  || *buffPos >  9 ) { n       buffPos++; n       if (buffPos == buffLim) { n         flushBuff(); n       } n     } n     long long res = 0; n     while (*buffPos >=  0  && *buffPos <=  9 ) { n       res = res * 10 + (*buffPos -  0 ); n       buffPos++; n       if (buffPos == buffLim) { n         flushBuff(); n       } n     } n     return res; n   } n   inline long long nlm(const int MOD) { n     while (*buffPos <  0  || *buffPos >  9 ) { n       buffPos++; n       if (buffPos == buffLim) { n         flushBuff(); n       } n     } n     long long res = 0; n     while (*buffPos >=  0  && *buffPos <=  9 ) { n       res = (res * 10 + (*buffPos -  0 )) % MOD; n       buffPos++; n       if (buffPos == buffLim) { n         flushBuff(); n       } n     } n     return res; n   } n   inline double nextDouble() { n     while (isWS(*buffPos)) { n       nextPos(); n     } n     int sign = (*buffPos ==  - ) ? nextPos(), -1 : 1; n     double res = 0; n     while (isDig(*buffPos)) { n       res = res * 10 + *buffPos -  0 ; n       nextPos(); n     } n     if (*buffPos ==  . ) { n       nextPos(); n       double ep = 1; n       while (isDig(*buffPos)) { n         ep *= 0.1; n         res += ep * (*buffPos -  0 ); n         nextPos(); n       } n     } n     return sign * res; n   } n   inline char nextChar() { n     while (isWS(*buffPos)) nextPos(); n     char res = *buffPos; n     nextPos(); n     return res; n   } n   ~Scanner() { fclose(file); } n }; n Scanner sc(stdin); n template <class __TyFirst, class __TySecond> n std::ostream& operator<<(std::ostream& out, n                          const std::pair<__TyFirst, __TySecond>& o); n static std::string cout_list_sep =    ; n template < n     class IterateType, typename = decltype(std::declval<IterateType>().begin()), n     typename = decltype(std::declval<IterateType>().end()), n     typename = typename std::enable_if<std::is_convertible< n         typename std::iterator_traits< n             typename IterateType::iterator>::iterator_category, n         std::input_iterator_tag>::value>::type, n     typename = typename std::enable_if<!std::is_base_of< n         std::string, typename std::decay<IterateType>::type>::value>::type, n     typename value_type = typename IterateType::value_type> n std::ostream& operator<<(std::ostream& out, const IterateType& a) { n   for (const auto& i : a) out << i << cout_list_sep; n   return out; n } n template <class __TyFirst, class __TySecond> n std::ostream& operator<<(std::ostream& out, n                          const std::pair<__TyFirst, __TySecond>& o) { n   out <<  (  << o.first <<  ,  << o.second <<  ) ; n   return out; n } n template <typename _ForwardIterator> n void logArray(_ForwardIterator, _ForwardIterator, const char* = 0) {} n namespace Temps { n template <typename _IntType> n class RangeInt { n   static_assert(std::is_integral<_IntType>::value, n                  RangeInt object must have integral value type ); n  n  public: n   class iterator : public std::iterator<std::input_iterator_tag, _IntType, n                                         _IntType, const _IntType*, _IntType> { n     _IntType val, step; n  n    public: n     using typename std::iterator<std::input_iterator_tag, _IntType, _IntType, n                                  const _IntType*, _IntType>::reference; n     explicit constexpr iterator(int val, int step) noexcept n         : val(val), step(step) {} n     constexpr iterator& operator++() noexcept { n       val += step; n       return *this; n     } n     constexpr iterator operator++(int) noexcept { n       iterator ret = *this; n       val += step; n       return ret; n     } n     constexpr bool operator==(const iterator& rhs) const noexcept { n       return val == rhs.val; n     } n     constexpr bool operator!=(const iterator& rhs) const noexcept { n       return val != rhs.val; n     } n     constexpr reference operator*() const { return val; } n   }; n   const _IntType _begin, _step, _end; n   explicit constexpr RangeInt(const _IntType end) noexcept n       : _begin(0), _step(1), _end(end > 0 ? end : 0) {} n   explicit constexpr RangeInt(const _IntType begin, const _IntType end) noexcept n       : _begin(begin), _step(1), _end(end > begin ? end : begin) {} n   explicit constexpr RangeInt(const _IntType begin, const _IntType end, n                               const _IntType step) n       : _begin(begin), n         _step(step), n         _end(((step > 0 && end <= begin) || (step < 0 && end >= begin)) n                  ? begin n                  : (step > 0 n                         ? begin + (end - begin + step - 1) / step * step n                         : begin + (begin - end - step - 1) / (-step) * step)) {} n   constexpr iterator begin() const noexcept { return iterator(_begin, _step); } n   constexpr iterator end() const noexcept { return iterator(_end, _step); } n   constexpr _IntType size() const noexcept { return (_end - _begin) / _step; } n }; n template <class IntType, typename = typename std::enable_if< n                              std::is_integral<IntType>::value>::type> n inline constexpr RangeInt<IntType> range(IntType arg1) { n   return RangeInt<IntType>(arg1); n } n template <class IntType, typename = typename std::enable_if< n                              std::is_integral<IntType>::value>::type> n inline constexpr RangeInt<IntType> range(IntType arg1, IntType arg2) { n   return RangeInt<IntType>(arg1, arg2); n } n template <class IntType, typename = typename std::enable_if< n                              std::is_integral<IntType>::value>::type> n inline constexpr RangeInt<IntType> range(IntType arg1, IntType arg2, n                                          IntType arg3) { n   return RangeInt<IntType>(arg1, arg2, arg3); n } n }  // namespace Temps n using Temps::range; n namespace Temps { n template <class T> n inline bool checkMin(T& a, T b) { n   return (b < a ? a = b, 1 : 0); n } n template <class T> n inline bool checkMax(T& a, T b) { n   return (a < b ? a = b, 1 : 0); n } n template <class IntType, typename = typename std::enable_if< n                              std::is_integral<IntType>::value>::type> n IntType gcd(const IntType a, const IntType b) { n   return b == 0 ? a : gcd(b, a % b); n } n template <class ForwardIterator, class OutputIterator> n void dissociate(ForwardIterator __begin, ForwardIterator __end, n                 OutputIterator __dest) { n   std::vector<typename std::iterator_traits<ForwardIterator>::_IntType> values( n       __begin, __end); n   std::sort(values.begin(), values.end()); n   std::unique(values.begin(), values.end()); n   while (__begin != __end) { n     *__dest = n         static_cast<typename std::iterator_traits<OutputIterator>::_IntType>( n             std::distance( n                 values.begin(), n                 std::lower_bound(values.begin(), values.end(), *__begin))); n     __dest++; n     __begin++; n   } n } n }  // namespace Temps n using Temps::checkMax; n using Temps::checkMin; n namespace Temps { n template <class Type> n class Vector { n   static_assert(std::is_trivial<Type>::value, n                  Temps::Vector can only be used for trival types ); n  n  public: n   typedef Type& reference; n   typedef const Type& const_reference; n   class iterator : public std::iterator<std::random_access_iterator_tag, Type> { n    public: n     friend class Vector; n     using typename std::iterator<std::random_access_iterator_tag, n                                  Type>::difference_type; n     using n         typename std::iterator<std::random_access_iterator_tag, Type>::pointer; n     using typename std::iterator<std::random_access_iterator_tag, n                                  Type>::reference; n  n    private: n     pointer ptr; n     iterator(pointer ptr) : ptr(ptr) {} n  n    public: n     bool operator==(const iterator rhs) const { return ptr == rhs.ptr; } n     bool operator!=(const iterator rhs) const { return ptr != rhs.ptr; } n     bool operator<(const iterator rhs) const { return ptr < rhs.ptr; } n     bool operator<=(const iterator rhs) const { return ptr <= rhs.ptr; } n     bool operator>(const iterator rhs) const { return ptr > rhs.ptr; } n     bool operator>=(const iterator rhs) const { return ptr >= rhs.ptr; } n     iterator operator++() { return iterator(++ptr); } n     iterator operator++(int) { return iterator(ptr++); } n     iterator operator--() { return iterator(--ptr); } n     iterator operator--(int) { return iterator(ptr--); } n     iterator operator+(const difference_type dif) const { n       return iterator(ptr + dif); n     } n     iterator operator-(const difference_type dif) const { n       return iterator(ptr - dif); n     } n     iterator operator+=(const difference_type dif) { n       ptr += dif; n       return *this; n     } n     iterator operator-=(const difference_type dif) { n       ptr -= dif; n       return *this; n     } n     difference_type operator-(const iterator& rhs) const { n       return ptr - rhs.ptr; n     } n     operator pointer() { return ptr; } n   }; n  n  protected: n   Type* a = nullptr; n   unsigned int _capacity = 0, _size = 0; n   void __grow_capacity(unsigned int least_size) { n     if (_capacity >= least_size) { n       return; n     } n     if (_capacity == 0) { n       _capacity = 1; n     } n     while (_capacity < least_size) { n       _capacity = _capacity * 2; n     } n     a = static_cast<Type*>(realloc(a, sizeof(Type) * _capacity)); n   } n  n  public: n   Vector() = default; n   explicit Vector(unsigned int size, const Type& initial_value = Type()) n       : _capacity(size), _size(size) { n     a = static_cast<Type*>(malloc(sizeof(Type) * _capacity)); n     Type *__first = a, *const __last = a + _size; n     while (__first != __last) { n       *__first++ = initial_value; n     } n   } n   Vector(const Vector& rhs) : _capacity(rhs._size), _size(rhs._size) { n     a = static_cast<Type*>(malloc(sizeof(Type) * _capacity)); n     Type *__first = a, *__r_p = rhs.a, *const __last = a + _size; n     while (__first != __last) { n       *__first++ = *__r_p++; n     } n   } n   Vector(Vector&& rhs) : _capacity(rhs._capacity), _size(rhs._size) { n     a = rhs.a; n     rhs.a = nullptr; n   } n   Vector(const std::initializer_list<Type>& list) n       : _capacity( n             static_cast<unsigned int>(std::distance(list.begin(), list.end()))), n         _size(_capacity) { n     a = static_cast<Type*>(malloc(sizeof(Type) * _capacity)); n     Type* p = a; n     for (const auto& i : list) { n       *p++ = i; n     } n   } n   template <typename Container, n             typename = decltype(std::declval<Container>().begin(), n                                 std::declval<Container>().end())> n   Vector(const Container& list) n       : _capacity( n             static_cast<unsigned int>(std::distance(list.begin(), list.end()))), n         _size(_capacity) { n     a = static_cast<Type*>(malloc(sizeof(Type) * _capacity)); n     Type* p = a; n     for (const auto& i : list) { n       *p++ = i; n     } n   } n   template < n       typename _InputIterator, n       typename = typename std::enable_if<std::is_convertible< n           typename std::iterator_traits<_InputIterator>::iterator_category, n           std::input_iterator_tag>::value>::type> n   explicit Vector(_InputIterator __first, _InputIterator __last) { n     _size = _capacity = n         static_cast<unsigned int>(std::distance(__first, __last)); n     a = static_cast<Type*>(malloc(sizeof(Type) * _capacity)); n     Type* p = a; n     while (__first != __last) { n       *p++ = *__first++; n     } n   } n   inline bool empty() const { return _size == 0; } n   inline unsigned int size() const { return _size; } n   inline unsigned int capacity() const { return _capacity; } n   void reserve(unsigned int __capacity) { n     _capacity = __capacity; n     if (_size > _capacity) { n       _size = _capacity; n     } n     a = static_cast<Type*>(realloc(a, sizeof(Type) * _capacity)); n   } n   void resize(unsigned int __size) { n     if (_size > __size) { n       _size = __size; n       return; n     } n     __grow_capacity(__size); n     Type *__un = a + _size, *const __ed = a + __size; n     while (__un != __ed) { n       *__un++ = Type(); n     } n     _size = __size; n   } n   inline void clear() { resize(0); } n   Vector& operator=(const Vector& rhs) { n     __grow_capacity(rhs._size); n     _size = rhs._size; n     Type* __first = a; n     const Type *const __last = a + _size, *__r_p = rhs.a; n     while (__first != __last) { n       *__first++ = *__r_p++; n     } n     return *this; n   } n   Vector& operator=(Vector&& rhs) { n     _size = rhs._size; n     _capacity = rhs._capacity; n     free(a); n     a = rhs.a; n     rhs.a = nullptr; n     return *this; n   } n   Type operator[](const unsigned int id) const { return a[id]; } n   Type& operator[](const unsigned int id) { return a[id]; } n   Type front() const { return a[0]; } n   Type& front() { return a[0]; } n   Type back() const { return a[_size - 1]; } n   Type& back() { return a[_size - 1]; } n   void pop_back() { _size--; } n   Vector& push_back(const Type& b) { n     __grow_capacity(_size + 1); n     a[_size] = b; n     _size++; n     return *this; n   } n   Vector& push_back(const Vector& rhs) { n     __grow_capacity(_size + rhs._size); n     for (const auto& i : rhs) { n       a[_size++] = i; n     } n     return *this; n   } n   Vector& push_back(const std::initializer_list<Type>& rhs) { n     __grow_capacity(_size + rhs.size()); n     for (const auto& i : rhs) { n       a[_size++] = i; n     } n     return *this; n   } n   inline iterator begin() const { return iterator(a); } n   inline iterator end() const { return iterator(a + _size); } n   ~Vector() { free(a); } n }; n }  // namespace Temps n using Temps::Vector; n void preInit(); n void init(); n void solve(); n int32_t main() { n   preInit(); n   init(); n   solve(); n   return 0; n } n constexpr long long N = 100005; n struct dp_t { n   long long ss = 0, sub_sr = 0, ss_sr = 0; n   dp_t() = default; n   dp_t(long long val) : ss(val), sub_sr(val), ss_sr(val) {} n }; n std::vector<long long> e[N]; n long long n, w[N], ans = 0; n void preInit() {} n void init() { n   n = sc.n(); n   for (long long i = 1; i <= n; i++) w[i] = sc.n(); n   for (long long i = 1; i < n; i++) { n     long long u = sc.n(), v = sc.n(); n     e[u].push_back(v); n     e[v].push_back(u); n   } n } n dp_t dp[N]; n void dfs(long long u, long long f) { n   dp[u] = dp_t(w[u]); n   long long pre_v_sub_sr = 0; n   for (long long v : e[u]) n     if (v != f) { n       dfs(v, u); n       const dp_t& dv = dp[v]; n       dp_t du; n       du.ss = std::max(dp[u].ss, w[u] + dv.ss); n       du.sub_sr = std::max({dp[u].sub_sr, dp[u].ss + dv.ss, dv.sub_sr}); n       du.ss_sr = std::max({dp[u].ss_sr, dp[u].ss + dv.sub_sr, n                            pre_v_sub_sr + w[u] + dv.ss, dv.ss_sr + w[u]}); n       pre_v_sub_sr = std::max(pre_v_sub_sr, dv.sub_sr); n       ans = std::max({ans, dp[u].sub_sr + dv.sub_sr, dp[u].ss_sr + dv.ss, n                       dp[u].ss + dv.ss_sr}); n       dp[u] = du; n     } n } n void solve() { n   dfs(1, 0); n   printf( %lld n , ans); n } n


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


#include <bits/stdc++.h> n using namespace std; n const double EPS = 1e-9; n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long n; n   cin >> n; n   using T = tuple<long long, long long, long long, long long>; n   vector<long long> x(n), y(n), z(n); n   for (long long i = (0); i < ((n)); ++i) cin >> x[i] >> y[i] >> z[i]; n   vector<long long> flag(n, 0); n   vector<pair<long long, long long> > ans; n   for (long long i = (0); i < ((n)); ++i) { n     if (flag[i]) continue; n     flag[i]++; n     bool check = true; n     long long X = (1LL << 60), Y, Z, id; n     for (long long j = (0); j < ((n)); ++j) { n       if (flag[j]) continue; n       if (X == (1LL << 60)) { n         X = x[j], Y = y[j], Z = z[j]; n         id = j; n         continue; n       } n       if (((min(x[i], X)) <= (x[j]) && (x[j]) < (max(x[i], X) + 1)) && n           ((min(y[i], Y)) <= (y[j]) && (y[j]) < (max(y[i], Y) + 1)) && n           ((min(z[i], Z)) <= (z[j]) && (z[j]) < (max(z[i], Z) + 1))) { n         X = x[j], Y = y[j], Z = z[j]; n         id = j; n         continue; n       } n     } n     flag[id]++; n     ans.push_back(pair<long long, long long>(i + 1, id + 1)); n   } n   for (long long i = (0); i < ((n / 2)); ++i) n     cout << ans[i].first <<     << ans[i].second << endl; 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     int cnt = 0; n     set <int> s; n     while(n) { n         s.insert(n % m); n         cnt++; n         n /= m; n     } n     if(s.size() == cnt) cout <<  YES n ; n     else cout <<  NO n ; n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1E9 + 7; n template <class C> n void mini(C& a4, C b4) { n   a4 = min(a4, b4); n } n template <class C> n void maxi(C& a4, C b4) { n   a4 = max(a4, b4); n } n int n, k; n int il[2]; n const long long mod = 1E9 + 7; n int best[2][55][55]; n int ile[2][55][55]; n int a, b; n int binom[55][55]; n int main() { n   ios_base::sync_with_stdio(false); n   binom[0][0] = 1; n   for (int i = (1); i <= (55 - 1); ++i) { n     binom[i][0] = 1; n     for (int j = (1); j <= (55 - 1); ++j) { n       binom[i][j] = (binom[i - 1][j] + binom[i - 1][j - 1]) % mod; n     } n   } n   cin >> n >> k; n   for (int i = (1); i <= (n); ++i) { n     int x; n     cin >> x; n     if (x == 50) n       il[0]++; n     else n       il[1]++; n   } n   for (int s = (0); s <= (1); ++s) n     for (int i = (0); i <= (55 - 1); ++i) n       for (int j = (0); j <= (55 - 1); ++j) best[s][i][j] = INF; n   a = il[0]; n   b = il[1]; n   best[0][a][b] = 0; n   ile[0][a][b] = 1; n   for (int moves = (0); moves <= (55 * 55 * 10); ++moves) { n     for (int s = (0); s <= (1); ++s) n       for (int i = (0); i <= (a); ++i) n         for (int j = (0); j <= (b); ++j) { n           if (best[s][i][j] == moves) { n             for (int ii = (0); ii <= (i); ++ii) n               for (int jj = (0); jj <= (j); ++jj) n                 if (ii || jj) { n                   if (ii * 50 + jj * 100 > k) break; n                   int x = a - i; n                   int y = b - j; n                   x += ii; n                   y += jj; n                   long long il = (binom[i][ii] * (long long)binom[j][jj]) % mod; n                   if (moves + 1 < best[1 - s][x][y]) { n                     best[1 - s][x][y] = moves + 1; n                     ile[1 - s][x][y] = (ile[s][i][j] * il) % mod; n                   } else if (moves + 1 == best[1 - s][x][y]) { n                     ile[1 - s][x][y] += (ile[s][i][j] * il) % mod; n                     ile[1 - s][x][y] %= (int)mod; n                   } n                 } n           } n         } n   } n   if (best[1][a][b] == INF) best[1][a][b] = -1; n   cout << best[1][a][b] << endl << ile[1][a][b] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1007; n int c[N], t[N]; n bool cmp(int i, int j) { return c[i] > c[j]; } n int main() { n   int n, k; n   cin >> n >> k; n   vector<int> v[3]; n   for (int i = 0; i < n; ++i) { n     cin >> c[i] >> t[i]; n     v[t[i]].push_back(i); n   } n   sort((v[1]).begin(), (v[1]).end(), cmp); n   int sz = (int)((v[1]).size()), uu = (int)((v[2]).size()); n   double sum = 0; n   if (sz < k) { n     for (int i = 0; i < sz; ++i) sum += (double)c[v[1][i]] / 2; n     for (int i = 0; i < uu; ++i) sum += c[v[2][i]]; n     cout << fixed << setprecision(1) << sum <<   n ; n     for (int i = 0; i < sz; ++i) cout << 1 <<     << v[1][i] + 1 <<   n ; n     for (int i = 0; i < k - sz - 1; ++i) n       cout << 1 <<     << v[2][i] + 1 <<   n ; n     cout << (n - (k - 1)) <<    ; n     for (int i = k - sz - 1; i < n - sz; ++i) cout << v[2][i] + 1 <<    ; n     cout <<   n ; n   } else { n     for (int i = 0; i < k - 1; ++i) sum += (double)c[v[1][i]] / 2; n     int mini = 1000000000; n     for (int i = k - 1; i < sz; ++i) { n       sum += c[v[1][i]]; n       mini = min(mini, c[v[1][i]]); n     } n     for (int i = 0; i < uu; ++i) { n       sum += c[v[2][i]]; n       mini = min(mini, c[v[2][i]]); n     } n     sum -= (double)mini / 2; n     cout << fixed << setprecision(1) << sum <<   n ; n     for (int i = 0; i < k - 1; ++i) cout << 1 <<     << v[1][i] + 1 <<   n ; n     cout << (n - (k - 1)) <<    ; n     for (int i = k - 1; i < sz; ++i) cout << v[1][i] + 1 <<    ; n     for (int i = 0; i < uu; ++i) cout << v[2][i] + 1 <<    ; n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n bool is_vowel(const char c) { n   for (const char vowel : { a ,  e ,  i ,  o ,  u }) n     if (c == vowel) return true; n   return false; n } n bool is_block_ok(const array<char, 3> cs) { n   for (const char c : cs) n     if (is_vowel(c)) return true; n   return cs[0] == cs[1] && cs[1] == cs[2]; n } n int main() { n   string s; n   cin >> s; n   const int n = int(s.length()); n   int start = 0; n   for (int i = 0; i < n; i++) { n     if (i >= start + 2 && !is_block_ok({s[i - 2], s[i - 1], s[i]})) { n       cout <<    ; n       start = i; n     } n     cout << s[i]; n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n; n   long long int k; n   cin >> n >> k; n   vector<pair<int, int> > a(n); n   for (int i = 0; i < n; i++) { n     cin >> a[i].first >> a[i].second; n   } n   sort(a.begin(), a.end()); n   int ans = -1; n   long long int l = 0, r = 2e9; n   for (int i = 0; i < 60; i++) { n     long long int m = l + (r - l) / 2; n     int less = 0, right = 0, center = 0; n     long long int money = 0; n     vector<int> c; n     for (auto &e : a) { n       if (e.second < m) { n         money += e.first; n       } else if (e.first >= m) { n         money += e.first; n         right++; n       } else if (e.first < m && m <= e.second) { n         c.push_back(e.first); n       } n     } n     int need = max(0, (n + 1) / 2 - right); n     if (need > c.size()) { n       r = m - 1; n     } else { n       for (int i = 0; i < c.size(); i++) { n         if (i < c.size() - need) n           money += c[i]; n         else n           money += m; n       } n       if (money <= k) { n         ans = m; n         l = m + 1; n       } else { n         r = m - 1; n       } n     } n   } n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } n int n, m, c; n int A[1111]; n int pref = 0, post = 0; n bool end() { n   bool ans = true; n   for (int(i) = 0; (i) < (n); (i)++) n     if (A[i] == -1 || (i < n - 1 && A[i + 1] < A[i])) ans = false; n   return ans; n } n int main() { n   memset(A, -1, sizeof(A)); n   scanf( %d%d%d , &n, &m, &c); n   int H = (c + 1) / 2; n   for (int(i) = 0; (i) < (m); (i)++) { n     int x; n     scanf( %d , &x); n     if (x <= H) { n       int i = 0; n       while (i < n && (A[i] <= x && A[i] != -1)) i++; n       A[i] = x; n       printf( %d n , i + 1); n       fflush(stdout); n       if (end()) return 0; n     } else { n       int i = n - 1; n       while (i >= 0 && (A[i] >= x && A[i] != -1)) i--; n       A[i] = x; n       printf( %d n , i + 1); n       fflush(stdout); n       if (end()) return 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n int a[N]; n int main() { n   ios::sync_with_stdio(0); n   int tt; n   cin >> tt; n   while (tt--) { n     int n; n     cin >> n; n     if (n % 2 == 0) { n       cout << n / 2 <<     << n / 2 << endl; n     } else { n       int lim = sqrt(n + 0.5), fg = 0; n       for (int i = 3; i <= lim; ++i) { n         if (n % i == 0) { n           cout << (n / i) <<     << (n / i) * (i - 1) << endl; n           fg = 1; n           break; n         } n       } n       if (!fg) { n         cout << 1 <<     << n - 1 << endl; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, char *argv[]) { n   string a; n   cin >> a; n   int n = 0, m = 0, first = 0, last = 0; n   bool b = true; n   for (int i = 0; i < a.size(); i++) { n     if (a[i] ==  H ) n++; n     if (a[i] ==  Q ) m++; n   } n   int sm = int(sqrt(m)); n   int i = 0; n   i = a.size() - 1; n   while ((i >= 0) && (a[i] ==  H )) { n     last++; n     i--; n   }; n   last /= 2; n   i = 0; n   while ((i < a.size()) && (a[i] ==  H )) { n     first++; n     i++; n   }; n   first /= 2; n   if (m == 0) n     cout <<  Yes ; n   else { n     if (!((sm * sm == m) && (n % (sm + 1) == 0))) n       cout <<  No ; n     else { n       string middle =   ; n       int counter = 0; n       while (counter < sm) { n         if (a[i] ==  Q ) counter++; n         middle += a[i]; n         i++; n       } n       string str; n       str = middle; n       for (int i = 0; i < first; i++) { n         str =  H  + str; n       } n       for (int i = 0; i < last; i++) { n         str = str +  H ; n       } n       string out =   ; n       for (int i = 0; i < str.size(); i++) { n         if (str[i] ==  H ) n           out = out +  H ; n         else n           out += str; n       }; n       if (out == a) n         cout <<  Yes ; n       else n         cout <<  No ; n     }; n   } n   return EXIT_SUCCESS; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 1000, MAX_M = 1000; n int N, M; n int a[MAX_N][MAX_M], mxx[MAX_N], mxy[MAX_M], cmpx[MAX_N][MAX_M], n     cmpy[MAX_N][MAX_M]; n vector<int> cmp; n int main() { n   scanf( %d %d , &N, &M); n   for (int i = (0); i < (N); i++) n     for (int j = (0); j < (M); j++) { n       scanf( %d , &a[i][j]); n     } n   for (int i = (0); i < (N); i++) { n     cmp.clear(); n     for (int j = (0); j < (M); j++) { n       cmp.push_back(a[i][j]); n     } n     sort(cmp.begin(), cmp.end()); n     cmp.erase(unique(cmp.begin(), cmp.end()), cmp.end()); n     mxx[i] = (int)cmp.size(); n     for (int j = (0); j < (M); j++) { n       cmpx[i][j] = n           lower_bound(cmp.begin(), cmp.end(), a[i][j]) - cmp.begin() + 1; n     } n   } n   for (int i = (0); i < (M); i++) { n     cmp.clear(); n     for (int j = (0); j < (N); j++) { n       cmp.push_back(a[j][i]); n     } n     sort(cmp.begin(), cmp.end()); n     cmp.erase(unique(cmp.begin(), cmp.end()), cmp.end()); n     mxy[i] = (int)cmp.size(); n     for (int j = (0); j < (N); j++) { n       cmpy[j][i] = n           lower_bound(cmp.begin(), cmp.end(), a[j][i]) - cmp.begin() + 1; n     } n   } n   for (int i = (0); i < (N); i++) { n     for (int j = (0); j < (M); j++) { n       if (j) printf(   ); n       int mx = max(cmpx[i][j], cmpy[i][j]); n       printf( %d , mx + max(mxx[i] - cmpx[i][j], mxy[j] - cmpy[i][j])); n     } n     printf(  n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100010; n int n, howMany[N]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n; n   vector<pair<int, int> > beacons; n   for (int i = 0; i < n; i++) { n     int x, p; n     cin >> x >> p; n     beacons.push_back({x, p}); n   } n   sort(beacons.begin(), beacons.end()); n   howMany[0] = 0; n   auto it = beacons.begin(); n   for (int i = 1; i < n; i++) { n     int now = beacons[i].first, power = beacons[i].second; n     auto it = n         lower_bound(beacons.begin(), beacons.end(), make_pair(now - power, -1)); n     int idx = it - beacons.begin(); n     if (idx == 0) { n       howMany[i] = i; n     } else { n       howMany[i] = howMany[idx - 1] + (i - idx); n     } n   } n   int ans = n; n   for (int i = 0; i < n; i++) { n     ans = min(ans, howMany[i] + (n - i - 1)); n   } n   cout << ans <<   n ; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 6; n int n, k, h[N]; n long long p, m, t, a[N], b[N]; n struct xd { n   int z, i; n   bool operator<(const xd &d) const { return z > d.z; } n } tmp, nw; n inline int read() { n   int T = 0, F = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) F = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) n     T = (T << 3) + (T << 1) + (ch - 48), ch = getchar(); n   return F * T; n } n bool check(long long x) { n   priority_queue<xd> q; n   memset(b, 0, sizeof(b)); n   for (int i = 1; i <= n; ++i) n     if (x - a[i] * m < h[i]) tmp.z = x / a[i], tmp.i = i, q.push(tmp); n   for (int i = 1; i <= m && !q.empty(); ++i) n     for (int j = 1; j <= k && !q.empty(); ++j) { n       tmp = q.top(), q.pop(); n       if (tmp.z < i) return 0; n       ++b[tmp.i]; n       if (x + b[tmp.i] * p - a[tmp.i] * m < h[tmp.i]) n         tmp.z = (x + b[tmp.i] * p) / a[tmp.i], q.push(tmp); n     } n   return q.empty(); n } n long long ef(long long l, long long r) { n   if (l == r) return l; n   long long mid = l + r >> 1ll; n   if (check(mid)) return ef(l, mid); n   return ef(mid + 1, r); n } n int main() { n   n = read(), m = read(), k = read(), p = read(); n   for (int i = 1; i <= n; ++i) h[i] = read(), a[i] = read(); n   printf( %lld n , ef(0, 5e12 + 1e9 + 1)); n   return 0; n } n


#include <bits/stdc++.h> n int t1, t2, t3; n int g[88][88]; n int n, k; n int m; n int dp[88][88][88]; n int ans = 0x3f3f3f3f; n int main() { n   scanf( %d%d , &n, &k); n   scanf( %d , &m); n   for (int i = 0; i <= n + 1; i++) { n     for (int j = 0; j <= n + 1; j++) { n       g[i][j] = 0x3f3f3f3f; n       for (int kk = 0; kk <= k; kk++) dp[i][j][kk] = 0x3f3f3f3f; n     } n   } n   while (m--) { n     scanf( %d%d%d , &t1, &t2, &t3); n     g[t1][t2] = (g[t1][t2] <= t3 ? g[t1][t2] : t3); n   } n   for (int i = 1; i <= n; i++) { n     dp[i][0][1] = 0; n     dp[i][n + 1][1] = 0; n   } n   for (int diff = n; diff > 0; diff--) { n     for (int i = 1; i <= n; i++) { n       if (i + diff > n + 1) continue; n       for (int kk = 0; kk < k; kk++) { n         if (dp[i][i + diff][kk] == 0x3f3f3f3f) continue; n         for (int j = i + 1; j < i + diff; j++) { n           if (g[i][j] == 0x3f3f3f3f) continue; n           dp[j][i + diff][kk + 1] = n               (dp[j][i + diff][kk + 1] <= dp[i][i + diff][kk] + g[i][j] n                    ? dp[j][i + diff][kk + 1] n                    : dp[i][i + diff][kk] + g[i][j]); n           dp[j][i][kk + 1] = (dp[j][i][kk + 1] <= dp[i][i + diff][kk] + g[i][j] n                                   ? dp[j][i][kk + 1] n                                   : dp[i][i + diff][kk] + g[i][j]); n         } n       } n     } n     for (int i = 1; i <= n; i++) { n       if (i - diff < 0) continue; n       for (int kk = 0; kk < k; kk++) { n         if (dp[i][i - diff][kk] == 0x3f3f3f3f) continue; n         for (int j = i - 1; j > i - diff; j--) { n           if (g[i][j] == 0x3f3f3f3f) continue; n           dp[j][i - diff][kk + 1] = n               (dp[j][i - diff][kk + 1] <= dp[i][i - diff][kk] + g[i][j] n                    ? dp[j][i - diff][kk + 1] n                    : dp[i][i - diff][kk] + g[i][j]); n           dp[j][i][kk + 1] = (dp[j][i][kk + 1] <= dp[i][i - diff][kk] + g[i][j] n                                   ? dp[j][i][kk + 1] n                                   : dp[i][i - diff][kk] + g[i][j]); n         } n       } n     } n   } n   for (int i = 0; i <= n + 1; i++) { n     for (int j = 0; j <= n + 1; j++) { n       ans = (ans <= dp[i][j][k] ? ans : dp[i][j][k]); n     } n   } n   if (ans == 0x3f3f3f3f) n     printf( -1 ); n   else n     printf( %d , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[300010], s[300010], x[2]; n long long p; n int main() { n   int i, j; n   long long k; n   scanf( %d , &n); n   for (i = 1; i <= n; i++) { n     scanf( %lld , &k); n     for (j = 0; j <= 60; j++) n       if (k & (1ll << j)) a[i]++; n     s[i] = s[i - 1] + a[i]; n   } n   x[0] = 1; n   for (i = 1; i <= n; i++) { n     p += x[s[i] & 1]; n     x[s[i] & 1]++; n     for (j = i, k = 0; j > 0 && i - j <= 80; j--) { n       k = max(k, (long long)a[j]); n       if (!(s[i] - s[j - 1] & 1) && k * 2 > s[i] - s[j - 1]) p--; n     } n   } n   cout << p <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n int compare(const void *a, const void *b) { return *(int *)a - *(int *)b; } n int main() { n   int n, k; n   scanf( %d%d , &n, &k); n   int i; n   if ((n == 1 && k == 1)) { n     printf( -1 n ); n     return 0; n   } n   if (n == k) { n     printf( -1 n ); n     return 0; n   } n   if ((n - k) % 2 != 0) { n     printf( 1  ); n     for (i = 2; i <= ((n - k) - (n - k) % 2); i += 2) { n       printf( %d %d  , i + 1, i); n     } n     for (i = n - k + 1; i <= n; i++) printf( %d  , i); n   } else { n     for (i = 1; i <= (n - k); i += 2) { n       printf( %d %d  , i + 1, i); n     } n     for (i = n - k + 1; i <= n; i++) printf( %d  , i); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int print1() { n   cout << -1 << endl; n   return 0; n } n int main() { n   int n, m; n   cin >> n >> m; n   vector<vector<int> > e(n); n   int a, b; n   for (int i = 0; i < m; ++i) { n     cin >> a >> b; n     a--; n     b--; n     e[a].push_back(b); n     e[b].push_back(a); n   } n   vector<int> c(n, 0); n   vector<int> cnt(3, 0); n   cnt[0] = n; n   for (auto &v : e[0]) { n     c[v] = 2; n     cnt[0]--; n     cnt[2]++; n   } n   for (a = 0; a < n && c[a] == 0; ++a) n     ; n   if (a == n) return print1(); n   for (auto &v : e[a]) { n     if (c[v] == 2) { n       c[v] = 1; n       cnt[1]++; n       cnt[2]--; n     } n   } n   for (int j = 0; j < 3; ++j) n     if (cnt[j] == 0) return print1(); n   vector<int> loc(3, 0); n   for (int i = 0; i < n; ++i) { n     loc[0] = 0; n     loc[1] = 0; n     loc[2] = 0; n     for (auto &v : e[i]) loc[c[v]]++; n     if (loc[c[i]] != 0) return print1(); n     for (int j = 0; j < 3; ++j) n       if (c[i] != j && loc[j] != cnt[j]) return print1(); n   } n   for (int i = 0; i < n; ++i) cout << c[i] + 1 <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 55; n char a[maxn][maxn]; n int vis[maxn][maxn]; n int n, m; n inline void go(int x, int y) { n   if (vis[x][y] == 1) return; n   if (a[x][y] !=  # ) return; n   vis[x][y] = 1; n   go(x - 1, y); n   go(x + 1, y); n   go(x, y - 1); n   go(x, y + 1); n } n inline bool check(int x, int y) { n   a[x][y] =  . ; n   int sum = 0; n   memset(vis, 0, sizeof(vis)); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) n       if (a[i][j] ==  #  && vis[i][j] == 0) { n         sum++; n         go(i, j); n       } n   } n   a[x][y] =  # ; n   return sum > 1; n } n int main() { n   cin >> n >> m; n   int sum = 0; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       cin >> a[i][j]; n       if (a[i][j] ==  # ) sum++; n     } n   if (sum <= 2) { n     cout <<  -1  << endl; n     return 0; n   } n   int ans = 2; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       if (a[i][j] ==  # ) n         if (check(i, j)) ans = 1; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int max_dp = 2e5 + 1; n int dp[101][max_dp]; n int n, k; n int a[101], b[101]; n int solve(int num, int bal) { n   if (dp[num][bal] != -1) { n     return dp[num][bal]; n   } n   if (num == 0) { n     if (bal == 1e5) { n       return 0; n     } else { n       return -1e9; n     } n   } n   int x = solve(num - 1, bal); n   int y = a[num - 1] + solve(num - 1, bal + a[num - 1] - k * b[num - 1]); n   dp[num][bal] = max(x, y); n   return dp[num][bal]; n } n int main() { n   cin >> n >> k; n   memset(dp, -1, sizeof(dp)); n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < n; i++) cin >> b[i]; n   int ans = solve(n, 1e5); n   if (ans > 0) n     cout << ans << endl; n   else n     cout <<  -1 n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, v[1005], xi, yi; n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 0; i < n; i++) scanf( %d , &v[i]); n   int res = 0; n   while (m--) { n     scanf( %d %d , &xi, &yi); n     xi--, yi--; n     res += min(v[xi], v[yi]); n   } n   printf( %d n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int A[100][10000]; n int d[100][10000]; n int main() { n   int n, m; n   cin >> n >> m; n   string str; n   getline(cin, str); n   for (int i = 0; i < n; i++) { n     getline(cin, str); n     for (int j = 0; j < str.size(); j++) n       if (str[j] ==  1 ) n         A[i][j] = 1; n       else n         A[i][j] = 0; n   } n   for (int i = 0; i < n; i++) { n     int prev = 1000001; n     int prev2 = 100000; n     for (int j = m - 1; j >= 0; j--) n       if (A[i][j]) { n         prev = -(m - j); n         break; n       } n     if (prev == 1000001) { n       cout << -1 << endl; n       return 0; n     } n     bool first = true; n     for (int j = 0; j < m; j++) { n       if (A[i][j]) { n         if (first) { n           prev2 = j + 1 + m - 1; n           first = false; n         } n         d[i][j] = 0; n         prev = j; n       } else n         d[i][j] = j - prev; n     } n     for (int j = m - 1; j >= 0; j--) { n       d[i][j] = min(d[i][j], prev2 - j); n       if (A[i][j]) prev2 = j; n     } n   } n   int mindall = 1000000; n   for (int i = 0; i < m; i++) { n     int mind = 0; n     for (int j = 0; j < n; j++) { n       mind += d[j][i]; n     } n     mindall = min(mindall, mind); n   } n   cout << mindall << 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 n, tt; n   cin >> n >> tt; n   vector<int> a(1 << n); n   long long sum = 0; n   for (int i = 0; i < (1 << n); i++) { n     cin >> a[i]; n     sum += (long long)a[i]; n   } n   cout << fixed << setprecision(17) << (double)sum / (1 << n) <<   n ; n   while (tt--) { n     int x, y; n     cin >> x >> y; n     sum += y - a[x]; n     a[x] = y; n     cout << fixed << setprecision(17) << (double)sum / (1 << n) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   if (n >= 1 && n <= 10 || n >= 22 && n <= 25) n     cout <<  0 ; n   else if (n == 11) n     cout <<  4 ; n   else if (n == 20) n     cout <<  15 ; n   else n     cout <<  4 ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   int l = 0, u = 0; n   cin >> s; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] > 90) n       l++; n     else n       u++; n   } n   if (l >= u) { n     transform(s.begin(), s.end(), s.begin(), ::tolower); n     cout << s << endl; n   } else { n     transform(s.begin(), s.end(), s.begin(), ::toupper); n     cout << s << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int MN = 1e5 + 4; n int N, Q, ecnt, ch[MN], depth[MN], len[MN]; n long long rt, bit1[MN], *bit2[MN]; n std::vector<int> adj[MN]; n inline void upd(long long *bit, int ind, int cap, long long val) { n   for (; ind < cap; ind += ind & -ind) bit[ind] += val; n } n inline long long qry(long long *bit, int ind) { n   long long res = 0; n   for (; ind; ind -= ind & -ind) res += bit[ind]; n   return res; n } n void dfs1(int src, int p, int d, int b) { n   ++ecnt; n   ch[src] = b; n   depth[src] = d++; n   for (int i : adj[src]) { n     if (i == p) continue; n     dfs1(i, src, d, b); n   } n } n int main() { n   scanf( %d%d , &N, &Q); n   for (int i = 1, a, b; i < N; ++i) { n     scanf( %d%d , &a, &b); n     adj[a].emplace_back(b); n     adj[b].emplace_back(a); n   } n   int cnt = 0; n   for (int i : adj[1]) { n     dfs1(i, 1, 1, ++cnt); n     len[cnt] = ecnt + 1; n     bit2[cnt] = (long long *)calloc(ecnt + 1, sizeof(long long)); n     ecnt = 0; n   } n   for (int i = 0, a, b, c, d; i < Q; ++i) { n     scanf( %d , &a); n     if (a) { n       scanf( %d , &b); n       if (b == 1) n         printf( %lld n , rt); n       else n         printf( %lld n , qry(bit1, depth[b]) + qry(bit2[ch[b]], depth[b])); n     } else { n       scanf( %d%d%d , &b, &c, &d); n       if (b == 1) { n         upd(bit1, 1, MN, c); n         upd(bit1, d + 1, MN, -c); n         rt += c; n       } else { n         if (d < depth[b]) { n           upd(bit2[ch[b]], depth[b] - d, len[ch[b]], c); n           upd(bit2[ch[b]], depth[b] + d + 1, len[ch[b]], -c); n         } else { n           upd(bit2[ch[b]], 1, len[ch[b]], c); n           upd(bit2[ch[b]], depth[b] + d + 1, len[ch[b]], -c); n           if (depth[b] != d) { n             upd(bit1, 1, MN, c); n             upd(bit1, d - depth[b] + 1, MN, -c); n             upd(bit2[ch[b]], 1, len[ch[b]], -c); n             upd(bit2[ch[b]], d - depth[b] + 1, len[ch[b]], c); n           } n           rt += c; n         } n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int l, r; n   cin >> l >> r; n   long long int res = 0; n   for (long long int i = 1; i <= r; i *= 2) { n     for (long long int j = 1; j <= r; j *= 3) { n       if (i * j <= r && i * j >= l) { n         res++; n       } n     } n   } n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, pos, l, r; n   cin >> n >> pos >> l >> r; n   int result; n   if (l == 1 && r == n) { n     result = 0; n   } else if (l == 1) { n     result = abs(pos - r) + 1; n   } else if (r == n) { n     result = abs(pos - l) + 1; n   } else { n     result = min(abs(pos - l), abs(pos - r)) + r - l + 2; n   } n   cout << result << endl; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> graph[3123]; n vector<vector<int> > vCiclos; n int dist[3123]; n int vis[3123]; n vector<int> v; n int ciclo[3123]; n int tamanhoCiclo[3123]; n int cnt = 1; n int n; n bool cycle[3123]; n void dfs(int x, int pai) { n   vis[x] = 1; n   v.push_back(x); n   for (int i = 0; i < graph[x].size(); ++i) { n     int y = graph[x][i]; n     if (y == pai) continue; n     if (vis[y] == 0) { n       dfs(y, x); n     } else if (vis[y] == 1) { n       vector<int> aux; n       for (int j = v.size() - 1;; --j) { n         int vert = v[j]; n         ciclo[vert] = cnt; n         aux.push_back(v[j]); n         cycle[v[j]] = true; n         if (vert == y) break; n       } n       cnt++; n       vCiclos.push_back(aux); n     } n   } n   vis[x] = 2; n   v.pop_back(); n } n void dfs2(int x, int pai, int k) { n   dist[x] = k; n   for (int i = 0; i < graph[x].size(); i++) { n     int y = graph[x][i]; n     if (y == pai || cycle[y]) continue; n     dfs2(y, x, k + 1); n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     int x, y; n     scanf( %d %d , &x, &y); n     graph[x].push_back(y); n     graph[y].push_back(x); n   } n   dfs(1, 1); n   for (int i = 0; i < vCiclos.size(); i++) { n     for (int j = 0; j < vCiclos[i].size(); j++) { n       int y = vCiclos[i][j]; n       dfs2(y, y, 0); n     } n   } n   for (int i = 1; i <= n; i++) printf( %d  , dist[i]); n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 998244353, N = 200200, G = 3, Gi = 332748118; n long long power(long long base, long long b) { n   long long ret = 1; n   while (b) { n     if (b & 1) ret = ret * base % mod; n     base = base * base % mod; n     b >>= 1; n   } n   return ret; n } n int limit, len, last = -1, pos[N]; n long long G0[N], G1[N], G2[N], g[N], F0[N], F1[N], F2[N]; n long long w[N]; n void getlen(int n) { n   limit = 1, len = 0; n   while (limit < n) limit <<= 1, ++len; n   w[0] = 1; n   long long gg = power(G, (mod - 1) / limit); n   for (int i = 1; i < limit; ++i) { n     pos[i] = (pos[i >> 1] >> 1) | ((i & 1) << (len - 1)); n     w[i] = w[i - 1] * gg % mod; n   } n } n void ntt(long long *a, int n, int type) { n   for (int i = 0; i < limit; ++i) n     if (i < pos[i]) swap(a[i], a[pos[i]]); n   for (int mid = 1; mid < limit; mid <<= 1) n     for (int j = 0, r = mid << 1; j < limit; j += r) n       for (int k = 0; k < mid; ++k) { n         long long x = a[j + k], y = w[limit / r * k] * a[j + mid + k] % mod; n         a[j + k] = (x + y) % mod; n         a[j + mid + k] = (x - y + mod) % mod; n       } n   if (type == -1) { n     reverse(a + 1, a + limit); n     long long inv = power(limit, mod - 2); n     for (int i = 0; i < limit; ++i) a[i] = inv * a[i] % mod; n   } n } n long long f[N], h[N], tmp[N]; n void calc(long long *a, int n, long long *b, int m, long long *c, int nm = -1) { n   if (nm == -1) nm = n + m - 1; n   getlen(nm); n   for (int i = 0; i < n; ++i) f[i] = a[i]; n   for (int i = n; i < limit; ++i) f[i] = 0; n   for (int i = 0; i < m; ++i) h[i] = b[i]; n   for (int i = m; i < limit; ++i) h[i] = 0; n   ntt(f, nm, 1), ntt(h, nm, 1); n   for (int i = 0; i < limit; ++i) f[i] = f[i] * h[i] % mod; n   ntt(f, nm, -1); n   for (int i = 0; i < nm; ++i) c[i] = f[i]; n } n void CDQ(int l, int r) { n   if (l == r) { n     F0[l] = (F0[l] + G0[l]) % mod; n     F1[l] = (F1[l] + G1[l]) % mod; n     F2[l] = (F2[l] + G2[l]) % mod; n     return; n   } n   int mid = (l + r) >> 1; n   CDQ(l, mid); n   calc(F0 + l, mid - l + 1, G0, r - l + 1, tmp + l, r - l + 1); n   for (int i = mid + 1; i <= r; ++i) F0[i] = (F0[i] + tmp[i]) % mod; n   calc(F0 + l, mid - l + 1, G1, r - l + 1, tmp + l, r - l + 1); n   for (int i = mid + 1; i <= r; ++i) F1[i] = (F1[i] + tmp[i]) % mod; n   calc(F1 + l, mid - l + 1, G1, r - l + 1, tmp + l, r - l + 1); n   for (int i = mid + 1; i <= r; ++i) F0[i] = (F0[i] + tmp[i]) % mod; n   for (int i = mid + 1; i <= r; ++i) F2[i] = (F2[i] + tmp[i]) % mod; n   calc(F1 + l, mid - l + 1, G2, r - l + 1, tmp + l, r - l + 1); n   for (int i = mid + 1; i <= r; ++i) F1[i] = (F1[i] + tmp[i]) % mod; n   calc(F2 + l, mid - l + 1, G2, r - l + 1, tmp + l, r - l + 1); n   for (int i = mid + 1; i <= r; ++i) F2[i] = (F2[i] + tmp[i]) % mod; n   CDQ(mid + 1, r); n } n int n; n int main() { n   scanf( %d , &n); n   g[0] = g[2] = 1; n   for (int i = 4; i <= n; ++i) g[i] = (g[i - 2] + g[i - 4]) % mod; n   for (int i = 1; i <= n; ++i) n     G0[i] = 1LL * (i - 1) * (i - 1) % mod * g[i - 1] % mod; n   for (int i = 2; i <= n; ++i) n     G1[i] = 1LL * (i - 1) * (i - 1) % mod * g[i - 2] % mod; n   for (int i = 3; i <= n; ++i) n     G2[i] = 1LL * (i - 1) * (i - 1) % mod * g[i - 3] % mod; n   CDQ(1, n); n   long long Ans = 1LL * n * (G0[n] + G2[n]) % mod; n   for (int i = 2; i <= n - 2; ++i) { n     Ans = (Ans + (G0[i] * F0[n - i] % mod + 2LL * G1[i] * F1[n - i] % mod + n                   G2[i] * F2[n - i] % mod) * n                      (long long)i % mod) % n           mod; n   } n   printf( %lld n , (Ans % mod + mod) % mod); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string months[] = { January ,    February ,  March ,     April , n                       May ,        June ,      July ,      August , n                       September ,  October ,   November ,  December }; n   string s; n   int n, a; n   cin >> s >> n; n   for (int i = 0; i < 12; i++) { n     if (months[i].compare(s) == 0) { n       a = i + n; n       break; n     } n   } n   while (a > 11) { n     a = a - 12; n   } n   cout << months[a]; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n const int INF = 2e9 + 5; n const int MAXN = 100010; n int n; n long long a, r, m, h[MAXN]; n int main() { n   cin.sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> a >> r >> m; n   for (int i = 0; i < n; i++) { n     cin >> h[i]; n   } n   m = min(m, a + r); n   sort(h, h + n, greater<long long>()); n   long long sum = 0; n   for (int i = 0; i < n; i++) { n     sum += h[i]; n   } n   long long lbound = (sum + n - 1) / n; n   long long cur = (n * h[0] - sum) * a; n   long long ans = 1e18; n   long long run = 0; n   for (int i = 0; i < n; i++) { n     if (h[i] < lbound) break; n     long long lo = lbound; n     if (i + 1 < n) { n       lo = max(lo, h[i + 1]); n     } n     ans = min(ans, cur + run); n     long long delta = (i + 1) * m - n * a; n     run += delta * (h[i] - lo); n   } n   ans = min(ans, cur + run); n   reverse(h, h + n); n   long long ubound = sum / n; n   cur = (sum - n * h[0]) * r; n   run = 0; n   for (int i = 0; i < n; i++) { n     if (h[i] > ubound) break; n     long long hi = ubound; n     if (i + 1 < n) { n       hi = min(hi, h[i + 1]); n     } n     ans = min(ans, cur + run); n     long long delta = (i + 1) * m - n * r; n     run += delta * (hi - h[i]); n     ; n   } n   ans = min(ans, cur + run); n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using pii = pair<int, int>; n const int N = 2e5 + 10; n const int MX = 1e9; n int n, t; n int ar[N], mn[N]; n unordered_map<int, int> bit; n void upd(int x, int val) { n   x++; n   while (x <= t) { n     bit[x] += val; n     x += (x & (-x)); n   } n } n int ask(int x) { n   x++; n   int ret = 0; n   while (x) { n     ret += bit[x]; n     x -= (x & (-x)); n   } n   return ret; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> t; n   t = min(t, n + MX + 10); n   for (int i = 1; i <= n; i++) { n     cin >> ar[i]; n     mn[i] = max(ar[i] - i, 0); n   } n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     upd(mn[i], 1); n     int mul = t - i - 1; n     if (mul >= 0) { n       ans = max(ans, ask(mul)); n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int gets(string s) { n   int sum = 0; n   while ((s[0] ==  0 ) and (s.size() != 1)) s = s.substr(1, s.size() - 1); n   for (int i = 0; i < s.size(); i++) sum += s[i] - 48; n   return sum; n } n int main() { n   string s, s1, m; n   int kol; n   cin >> s; n   m = s; n   kol = gets(s); n   for (int i = 0; i < s.size(); i++) { n     s1 = s; n     int kol1 = 0; n     if (s1[i] !=  0 ) s1[i]--; n     for (int j = i + 1; j < s.size(); j++) s1[j] =  9 ; n     kol1 = gets(s1); n     while ((s1[0] ==  0 ) and (s1.size() != 1)) n       s1 = s1.substr(1, s1.size() - 1); n     if ((kol1 > kol) or n         ((kol == kol1) and n          ((s1.size() > m.size()) or ((s1 > m) and (s1.size() == m.size()))))) { n       m = s1; n       kol = kol1; n     } n   } n   cout << m; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n istream& operator>>(istream& is, vector<T>& a) { n   for (T& ai : a) is >> ai; n   return is; n } n template <typename T> n ostream& operator<<(ostream& os, vector<T> const& a) { n   os <<  [  ; n   for (const T& ai : a) os << ai <<    ; n   return os <<  ] ; n } n template <typename T1, typename T2> n istream& operator>>(istream& is, pair<T1, T2>& a) { n   return is >> a.first >> a.second; n } n template <typename T1, typename T2> n ostream& operator<<(ostream& os, pair<T1, T2> const& a) { n   return os <<  (  << a.first <<  ,   << a.second <<  ) ; n } n int f() { n   int n; n   cin >> n; n   vector<int> a(n); n   cin >> a; n   vector<int> val(a); n   sort((val).begin(), (val).end()); n   int m = unique((val).begin(), (val).end()) - val.begin(); n   val.resize(m); n   map<int, int> idx; n   for (int i = 0; i < m; ++i) idx[val[i]] = i; n   vector<vector<int> > tiers(m); n   for (int i = 0; i < n; ++i) tiers[idx[a[i]]].push_back(i); n   int i = 0, j = 1, r = 0; n   while (i < m) { n     while (j < m && tiers[j - 1].back() < tiers[j].front()) ++j; n     int s = 0, lb = tiers[i].front(), ub = tiers[j - 1].back(); n     for (int k = i; k < j; ++k) s += tiers[k].size(); n     if (i - 1 >= 0) { n       for (int x : tiers[i - 1]) { n         if (x < lb) ++s; n       } n     } n     if (j < m) { n       for (int x : tiers[j]) { n         if (x > ub) ++s; n       } n     } n     r = max(r, s); n     i = j++; n   } n   for (int i = 0; i < m - 1; ++i) { n     int j = 0, jz = tiers[i + 1].size(); n     int s = jz; n     for (int lhs : tiers[i]) { n       ++s; n       while (j < jz && tiers[i + 1][j] <= lhs) { n         ++j; n         --s; n       } n       r = max(r, s); n     } n   } n   return n - r; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) cout << f() <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t, a, b; n   cin >> t; n   while (t--) { n     cin >> a >> b; n     int f = 0; n     long long area = a * a - b * b; n     if ((a - b) != 1) n       cout <<  NO ; n     else { n       area = a + b; n       for (int i = 2; i <= sqrt(a + b); i++) { n         if (area % i == 0) { n           cout <<  NO ; n           f = 1; n           break; n         } n       } n       if (f == 0) cout <<  YES ; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long s(0), p, k; n int main() { n   cin >> k >> p; n   for (long long cz(1), i(0); i < k; ++i, ++cz) { n     string str = to_string(cz); n     string res(str); n     reverse(begin(str), end(str)); n     res += str; n     s += stoll(res) % p; n   } n   cout << s % p << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long xl, xr, yu, yd; n long long x, y; n int main() { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   long long n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> x >> y; n     if (i == 0) { n       xl = x; n       xr = x; n       yu = y; n       yd = y; n     } else { n       if (x < xl) xl = x; n       if (x > xr) xr = x; n       if (y > yu) yu = y; n       if (y < yd) yd = y; n     } n   } n   long long ans = max(yu - yd, xr - xl); n   cout << ans * ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int o, e, oC, eC, n, en; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> en; n     if (en % 2 == 0) { n       e = i; n       eC++; n     } else { n       o = i; n       oC++; n     } n   } n   if (oC == 1) n     cout << o; n   else n     cout << e; n } n


#include <bits/stdc++.h> n using namespace std; n double px[1005], py[1005]; n double tx, ty; n int sum; n int pnpoly(int nvert, double *vertx, double *verty, double testx, n            double testy) { n   int i, j, c = 0; n   for (i = 0, j = nvert - 1; i < nvert; j = i++) { n     if (((verty[i] > testy) != (verty[j] > testy)) && n         (testx < n          (vertx[j] - vertx[i]) * (testy - verty[i]) / (verty[j] - verty[i]) + n              vertx[i])) n       c = !c; n   } n   return c; n } n int main() { n   ios::sync_with_stdio(false); n   int n; n   while (cin >> n) { n     sum = 0; n     memset(px, 0, sizeof(px)); n     memset(py, 0, sizeof(py)); n     for (int i = 0; i <= n; i++) { n       cin >> px[i] >> py[i]; n     } n     for (int i = 1; i < n; i++) { n       if (px[i] - px[i - 1] == 0) { n         tx = px[i]; n         ty = abs(py[i] - py[i - 1]) / (py[i] - py[i - 1]) * 0.1 + py[i]; n       } else if (py[i] - py[i - 1] == 0) { n         ty = py[i]; n         tx = abs(px[i] - px[i - 1]) / (px[i] - px[i - 1]) * 0.1 + px[i]; n       } n       if (pnpoly(n, px, py, tx, ty)) { n         sum++; n       } n     } n     cout << sum << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5; n int w[N], ne[N], la[N], len[N], cst[N], t = 1; n void alink(int x, int y, int z, int c) { n   w[++t] = y; n   ne[t] = la[x]; n   la[x] = t; n   len[t] = z; n   cst[t] = c; n } n void link(int x, int y, int z, int c) { n   alink(x, y, z, c); n   alink(y, x, 0, -c); n } n int d[N], vis[N], S, T, dep[N], s[N], cur[N], n, m; n int ind[N], oud[N]; n int spfa() { n   for (int i = 1; i <= T; i++) vis[i] = 0, s[i] = 1e9; n   s[S] = 0, vis[S] = 1; n   d[1] = S; n   int l = 0, r = 1; n   while (l < r) { n     int x = d[++l]; n     for (int y = la[x]; y; y = ne[y]) { n       int z = w[y]; n       if (s[z] > s[x] + cst[y] && len[y]) { n         s[z] = s[x] + cst[y]; n         if (!vis[z]) { n           vis[z] = 1; n           d[++r] = z; n         } n       } n     } n     vis[x] = 0; n   } n   l = 0, r = 1; n   vis[S] = 1; n   while (l < r) { n     int x = d[++l]; n     cur[x] = la[x]; n     for (int y = la[x]; y; y = ne[y]) { n       int z = w[y]; n       if (!vis[z] && s[z] == s[x] + cst[y] && len[y]) { n         vis[z] = 1; n         d[++r] = z; n         dep[z] = dep[x] + 1; n       } n     } n   } n   return vis[T]; n } n int ans; n int flow(int x, int val) { n   if (x == T) return val; n   int v1 = val; n   for (int y = cur[x]; y; cur[x] = y = ne[y]) { n     int z = w[y]; n     if (dep[z] != dep[x] + 1 || s[z] != s[x] + cst[y] || !len[y]) continue; n     int use = flow(z, min(val, len[y])); n     val -= use; n     len[y] -= use; n     len[y ^ 1] += use; n     ans += cst[y] * use; n     if (!val) break; n   } n   return v1 - val; n } n int main() { n   cin >> n >> m; n   S = n + 1, T = n + 2; n   for (int i = 1; i <= m; i++) { n     int x, y, c, f; n     scanf( %d%d%d%d , &x, &y, &c, &f); n     ind[y] += f; n     oud[x] += f; n     if (c >= f) { n       link(y, x, f, 1); n       link(x, y, c - f, 1); n       link(x, y, 1 << 30, 2); n     } else { n       ans += f - c; n       link(x, y, 1 << 30, 2); n       link(y, x, f - c, 0); n       link(y, x, c, 1); n     } n   } n   for (int i = 1; i <= n; i++) link(S, i, ind[i], 0), link(i, T, oud[i], 0); n   link(n, 1, 1 << 30, 0); n   while (spfa()) flow(S, 1 << 30); n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int IN() { n   int c, x; n   while (!isdigit(c = getchar())) n     ; n   x = c -  0 ; n   while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + c -  0 ; n   return x; n } n const int N = 1000 + 19, P = 1e9 + 7; n int A[N][N], s[N][N], f[N], c[N], b[N]; n int n, m, k, cnt, Ans; n void DFS(int x, int y, int col) { n   if (col > k) return; n   if (y == m + 1) { n     DFS(x + 1, 1, col); n     return; n   } n   if (x == n + 1) { n     int tmp = 1; n     for (int i = k - col + 1; i <= k - cnt; i++) tmp = 1LL * tmp * i % P; n     (Ans += tmp) %= P; n     return; n   } n   int &S = s[x][y]; n   S = s[x][y - 1] | s[x - 1][y]; n   if (A[x][y]) { n     int t = A[x][y]; n     if (c[t]) { n       if (!(S >> c[t] & 1)) S |= 1 << c[t], DFS(x, y + 1, col), S ^= 1 << c[t]; n     } else n       for (int i = 1; i < col + 2; i++) n         if (!(S >> i & 1) && !b[i]) n           S |= 1 << i, b[i] = 1, c[t] = i, DFS(x, y + 1, max(i, col)), n                        S ^= 1 << i, b[i] = 0, c[t] = 0; n   } else n     for (int i = 1; i < col + 2; i++) n       if (!(S >> i & 1)) S |= 1 << i, DFS(x, y + 1, max(i, col)), S ^= 1 << i; n } n int main() { n   n = IN(), m = IN(), k = IN(); n   if (n + m - 1 > k) return puts( 0 ), 0; n   for (int i = 1; i < n + 1; i++) n     for (int j = 1; j < m + 1; j++) f[A[i][j] = IN()] = 1; n   for (int i = 1; i < k + 1; i++) cnt += f[i]; n   DFS(1, 1, 0); n   printf( %d n , Ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e5 + 10, Mod = 1e9 + 7; n int t, n, k; n long long Pow(long long a, long long b) { n   a %= Mod; n   long long ans = 1; n   while (b) { n     if (b & 1) ans *= a, ans %= Mod; n     a *= a, a %= Mod; n     b >>= 1; n   } n   return ans; n } n long long jie[MAXN], ni[MAXN]; n void getall() { n   jie[0] = 1, ni[0] = 1; n   for (int i = 1; i < MAXN; ++i) jie[i] = (jie[i - 1] * i) % Mod; n   ni[MAXN - 1] = Pow(jie[MAXN - 1], Mod - 2); n   for (int i = MAXN - 2; i >= 1; --i) ni[i] = (ni[i + 1] * (i + 1)) % Mod; n } n long long calc(int a) { n   long long ans = jie[n]; n   ans *= ni[a], ans %= Mod; n   ans *= ni[n - a], ans %= Mod; n   return ans; n } n int main() { n   ios::sync_with_stdio(0); n   cin >> t; n   getall(); n   while (t--) { n     cin >> n >> k; n     if (k == 0) { n       cout << 1 << endl; n       continue; n     } n     long long ans = 0, tmp1, tmp2, tt = Pow(2, k); n     if (n & 1) { n       tmp1 = 1; n       for (int i = 0; i <= n; i += 2) tmp1 += calc(i), tmp1 %= Mod; n       cout << Pow(tmp1, k) << endl; n     } else { n       tmp1 = 0, tmp2 = 1, ans = 0; n       for (int i = 0; i < n; i += 2) tmp1 += calc(i), tmp1 %= Mod; n       ans = Pow(tmp1, k); n       for (int i = 1; i <= k; ++i) { n         ans += tmp2 * Pow(2, 1ll * (k - i) * n); n         ans %= Mod; n         tmp2 *= tmp1; n         tmp2 %= Mod; n       } n       cout << ans << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, l = 1; n string s; n int main() { n   cin >> n >> s; n   for (int i = 1; i <= n; i++) n     if (s.substr(0, i) == s.substr(i, i)) l = i; n   cout << n - l + 1; n   return 0; n } n


#include <bits/stdc++.h>      n  n using namespace std; n  n const int N = 543; n const long long INF = (long long)(1e18); n  n struct Matching n { n   int n1, n2; n   vector<set<int>> g; n   vector<int> mt, used; n  n   void init() n   { n     mt = vector<int>(n2, -1); n   } n  n   int kuhn(int x) n   { n     if(used[x] == 1) return 0; n     used[x] = 1; n     for(auto y : g[x]) n      if(mt[y] == -1 || kuhn(mt[y]) == 1) n      { n        mt[y] = x; n        return 1; n      } n     return 0; n   } n  n   int calc() n   { n     init(); n     int sum = 0; n     for(int i = 0; i < n1; i++) n     { n      used = vector<int>(n1, 0); n      sum += kuhn(i); n     } n     return sum; n   } n  n   void remove_vertex(int v, bool right) n   { n     if(right) n     { n      for(int i = 0; i < n1; i++) n       g[i].erase(v); n     } n     else n      g[v].clear(); n   } n  n   void add_edge(int x, int y) n   { n    g[x].insert(y); n   } n  n   Matching() {}; n   Matching(int n1, int n2) : n1(n1), n2(n2) n   { n    g.resize(n1); n   }; n }; n  n int n, m, k; n long long dp[N][N]; n int p[N][N]; n vector<int> g[N]; n long long x[N], y[N]; n  n int main() n { n  cin >> n >> m >> k; n  for(int i = 0; i < m; i++) n  { n    int u, v; n    cin >> u >> v; n    --u; n    --v; n    g[u].push_back(v); n  } n  for(int i = 0; i < k; i++) n   cin >> x[i] >> y[i]; n  n  Matching mt(n, n); n  for(int i = 0; i < n; i++) n   for(auto j : g[i]) n    mt.add_edge(i, j); n  int cnt = mt.calc(); n  int cur = cnt; n  vector<int> seq; n  while(cur > 0) n  { n   int idx = 0; n   for(int i = 0; i < n; i++) n   { n     Matching mt2 = mt; n     mt2.remove_vertex(i, false); n     if(mt2.calc() < cur) n      idx = i + 1; n     mt2 = mt; n     mt2.remove_vertex(i, true); n     if(mt2.calc() < cur) n      idx = -(i + 1); n   } n   assert(idx != 0); n   seq.push_back(idx); n   mt.remove_vertex(abs(idx) - 1, idx < 0); n   cur--; n  }  n  reverse(seq.begin(), seq.end()); n  for(int i = 0; i <= k; i++) n   for(int j = 0; j <= cnt; j++) n    dp[i][j] = -INF; n  dp[0][cnt] = 0; n  for(int i = 0; i < k; i++) n   for(int j = 0; j <= cnt; j++) n   { n    if(dp[i][j] == -INF) continue; n    for(int z = 0; z <= j; z++) n    { n     if(i + 1 + z >= n) continue; n      int t = j - z; n      long long add = max(0ll, x[i] - t * y[i]); n      if(dp[i + 1][z] < dp[i][j] + add) n      { n        dp[i + 1][z] = dp[i][j] + add; n        p[i + 1][z] = j; n      } n    } n   } n  cur = max_element(dp[k], dp[k] + cnt + 1) - dp[k]; n  vector<int> res; n  for(int i = k; i > 0; i--) n  { n   res.push_back(0); n   for(int j = p[i][cur] - 1; j >= cur; j--) n    res.push_back(seq[j]); n   cur = p[i][cur];  n  } n  reverse(res.begin(), res.end()); n  cout << res.size() << endl; n  for(auto x : res) cout << x <<    ; n  cout << endl; n }


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 100; n int a[maxn], ans[2 * maxn]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n, m, c; n   cin >> n >> m >> c; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < m; i++) { n     int val; n     cin >> val; n     ans[i] += val; n     ans[i + n - m + 1] -= val; n   } n   ans[0] %= c; n   for (int i = 1; i < n; i++) ans[i] = (ans[i] + ans[i - 1]) % c; n   for (int i = 0; i < n; i++) cout << ((a[i] + ans[i]) % c + c) % c <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct point { n   int x, y; n   point() {} n   point(int _x, int _y) : x(_x), y(_y) {} n   point operator-(const point& other) const { n     return point(other.x - x, other.y - y); n   } n   long long operator/(const point& other) const { n     return x * 1LL * other.y - y * 1LL * other.x; n   } n   bool operator<(const point& other) const { n     if (x == other.x) return y < other.y; n     return x < other.x; n   } n   bool operator==(const point& other) const { n     return x == other.x && y == other.y; n   } n   bool operator!=(const point& other) const { return !(*this == other); } n }; n int gcd(int a, int b) { n   while (b != 0) { n     int r = a % b; n     a = b; n     b = r; n   } n   return a; n } n const int maxn = 4e5 + 5; n int n, c, d; n map<point, int> mp; n vector<point> p; n long long pref[maxn]; n void read_input() { n   cin >> n >> c >> d; n   for (int i = 0; i < n; ++i) { n     int x, y; n     cin >> x >> y; n     x -= c; n     y -= d; n     int t = gcd(abs(x), abs(y)); n     x /= t; n     y /= t; n     if (mp.count(point(x, y)) == 0) p.push_back(point(x, y)); n     ++mp[point(x, y)]; n   } n } n int up(point u) { n   if (u.y == 0) return u.x > 0; n   return u.y > 0; n } n bool cmp(const point& u, const point& v) { n   int up_u = up(u), up_v = up(v); n   if (up_u == up_v) return u / v > 0; n   return up_u > up_v; n } n void init() { n   sort(p.begin(), p.end(), cmp); n   pref[0] = 0; n   for (int i = 0; i < (int)p.size(); ++i) pref[i + 1] = pref[i] + mp[p[i]]; n } n point modify(point u) { return point(-u.x, -u.y); } n void solve() { n   long long ans = 0; n   long long total_cnt = 0; n   long long total = 0; n   for (int cur = 0, nxt = 0; cur < (int)p.size(); ++cur) { n     int t = lower_bound(p.begin(), p.end(), modify(p[cur]), cmp) - p.begin(); n     if (up(p[cur])) t = 0; n     total -= mp[p[cur]] * 1LL * pref[t]; n     total_cnt -= mp[p[cur]]; n     while (nxt < (int)p.size() && p[cur] / p[nxt] >= 0 && n            modify(p[cur]) != p[nxt]) { n       t = lower_bound(p.begin(), p.end(), modify(p[nxt]), cmp) - p.begin(); n       if (up(p[nxt])) t = 0; n       total += mp[p[nxt]] * 1LL * pref[t]; n       total_cnt += mp[p[nxt]]; n       ++nxt; n     } n     t = upper_bound(p.begin(), p.end(), modify(p[cur]), cmp) - p.begin(); n     if (up(p[cur])) t = 0; n     ans += mp[p[cur]] * 1LL * total; n     ans -= mp[p[cur]] * 1LL * pref[t] * total_cnt; n   } n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   read_input(); n   init(); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n long long int mod = 1000000007; n long long mod1 = 1000000000000000009; n long long poww(long long x, long long y) { n   if (y == 0) return 1; n   if (x == 1) return 1; n   if (x == 0) return 0; n   if (y == 1) return x; n   long long d = poww(x, y / 2); n   d %= mod; n   if (y % 2) return (((d * d) % mod) * x); n   return (d * d) % mod; n } n long long combaination(long long n, long long k) { n   long long f = 1; n   for (long long i = 0; i < k; i++) f *= n - i, f /= i + 1; n   return f; n } n long long a[300009]; n vector<pair<long long, long long> > v; n int main() { n   long long n; n   cin >> n; n   long long a[n]; n   long long x = 0, y = 0; n   for (long long i = 1; i <= n; i++) cin >> a[i]; n   long long i = 1; n   while (i <= n) { n     if (a[i] == i) { n       i++; n       continue; n     } n     if (abs(a[i] - i) >= n / 2) { n       v.push_back(make_pair(i, a[i])); n       swap(a[i], a[a[i]]); n     } else { n       if ((n - max(i, a[i])) >= n / 2) { n         x = i; n         y = a[i]; n         v.push_back(make_pair(x, n)); n         v.push_back(make_pair(n, y)); n         v.push_back(make_pair(x, n)); n         swap(a[x], a[n]); n         swap(a[y], a[n]); n         swap(a[x], a[n]); n       } else if (min(i, a[i]) - 1 >= n / 2) { n         x = i; n         y = a[i]; n         v.push_back(make_pair(x, 1)); n         v.push_back(make_pair(y, 1)); n         v.push_back(make_pair(x, 1)); n         swap(a[x], a[1]); n         swap(a[y], a[1]); n         swap(a[x], a[1]); n       } else { n         x = i, y = a[i]; n         if (x > y) swap(x, y); n         v.push_back(make_pair(y, 1)); n         v.push_back(make_pair(x, n)); n         v.push_back(make_pair(n, 1)); n         v.push_back(make_pair(y, 1)); n         v.push_back(make_pair(x, n)); n         swap(a[y], a[1]); n         swap(a[x], a[n]); n         swap(a[n], a[1]); n         swap(a[y], a[1]); n         swap(a[n], a[x]); n       } n     } n   } n   cout << v.size() << endl; n   for (long long i = 0; i < v.size(); i++) n     cout << v[i].first <<     << v[i].second << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n int main() { n   ios::sync_with_stdio(0), cin.tie(0); n   int tt; n   cin >> tt; n   while (tt--) { n     string s; n     cin >> s; n     int count = 0; n     for (int i = 0; i < s.size(); i++) { n       if (s[i] ==  1 ) { n         count++; n       } n     } n     int n = s.size(); n     if (min(count, n - count) % 2 == 1) { n       cout <<  DA ; n     } else { n       cout <<  NET ; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void print(T a) { n   for (auto x : a) cout << x <<    ; n   cout <<   n ; n } n vector<pair<long double, long double> > lines1; n vector<long double> dots1; n long double intersection(pair<long double, long double> l1, n                          pair<long double, long double> l2) { n   return (l2.second - l1.second) / (l1.first - l2.first); n } n void add_mx(long double k, long double b) { n   while ((long long)(lines1).size() >= 2) { n     long double x = n         intersection(lines1[(long long)(lines1).size() - 2], {k, b}); n     if (x <= dots1.back()) { n       dots1.pop_back(); n       lines1.pop_back(); n     } else n       break; n   } n   if ((long long)(lines1).size()) n     dots1.push_back( n         intersection(lines1[(long long)(lines1).size() - 1], {k, b})); n   lines1.push_back({k, b}); n } n long double get_mx(long double x) { n   long long id = lower_bound((dots1).begin(), (dots1).end(), x) - dots1.begin(); n   return lines1[id].first * x + lines1[id].second; n } n vector<pair<long double, long double> > lines2; n vector<long double> dots2; n void add_mn(long double k, long double b) { n   while ((long long)(lines2).size() >= 2) { n     long double x = n         intersection(lines2[(long long)(lines2).size() - 2], {k, b}); n     if (x <= dots2.back()) { n       dots2.pop_back(); n       lines2.pop_back(); n     } else n       break; n   } n   if ((long long)(lines2).size()) n     dots2.push_back( n         intersection(lines2[(long long)(lines2).size() - 1], {k, b})); n   lines2.push_back({k, b}); n } n long double get_mn(long double x) { n   long long id = lower_bound((dots2).begin(), (dots2).end(), x) - dots2.begin(); n   return lines2[id].first * x + lines2[id].second; n } n const long double PI = acos(-1); n long double get_angle(pair<long double, long double> v) { n   long double gyp = sqrt(v.first * v.first + v.second * v.second); n   long double cs = v.first / gyp; n   return acos(cs) * 180.0 / PI; n } n void solve() { n   long long n; n   cin >> n; n   vector<vector<long double> > s; n   vector<pair<long double, long double> > lines; n   long double left_most = 1e18, right_most = -1e18; n   for (long long i = 0; i < n; i++) { n     long double a, b, c; n     cin >> a >> b >> c; n     left_most = min(left_most, a); n     right_most = max(right_most, b); n     s.push_back({c, a, b}); n     lines.push_back({c, a}); n     lines.push_back({c, b}); n   } n   sort((lines).begin(), (lines).end()); n   vector<pair<long double, long double> > lines_mx, lines_mn; n   for (long long i = 0; i < (long long)(lines).size(); i++) { n     if (i != 0 && lines[i].first == lines[i - 1].first) { n       lines_mx.pop_back(); n       lines_mx.push_back(lines[i]); n     } else { n       lines_mx.push_back(lines[i]); n       lines_mn.push_back(lines[i]); n     } n   } n   for (long long i = 0; i < (long long)(lines_mx).size(); i++) n     add_mx(lines_mx[i].first, lines_mx[i].second); n   for (long long i = (long long)(lines_mn).size() - 1; i >= 0; i--) n     add_mn(lines_mn[i].first, lines_mn[i].second); n   sort((s).begin(), (s).end()); n   vector<pair<long double, long long> > event; n   for (long long i = 0; i < n; i++) { n     for (long long j = 0; j < i; j++) { n       if (s[j][0] == s[i][0]) continue; n       pair<long double, long double> v1(s[j][2] - s[i][1], s[j][0] - s[i][0]); n       pair<long double, long double> v2(s[j][1] - s[i][2], s[j][0] - s[i][0]); n       long double angle1 = get_angle(v1), angle2 = get_angle(v2); n       event.push_back({angle1, 1}); n       event.push_back({angle2, -1}); n     } n   } n   sort((event).begin(), (event).end()); n   if ((long long)(event).size() == 0) { n     cout << fixed << setprecision(10) << right_most - left_most; n     return; n   } n   long long balance = 0; n   vector<long double> angles; n   for (long long i = 0; i < (long long)(event).size(); i++) { n     if (event[i].second == 1) { n       if (balance == 0) angles.push_back(event[i].first); n       balance++; n     } else { n       balance--; n       if (balance == 0) angles.push_back(event[i].first); n     } n   } n   long double ans = 1e18; n   for (long double angle : angles) { n     long double ct = 1.L / tan(angle / 180.0 * PI); n     ans = min(ans, get_mx(ct) - get_mn(ct)); n   } n   cout << fixed << setprecision(10) << ans; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   for (long long i = 0; i < t; i++) { n     solve(); n   } 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   vector<long long> f(n); n   int u, v; n   long long z; n   while (m--) { n     cin >> u >> v >> z; n     f[--u] -= z; n     f[--v] += z; n   } n   vector<long long> a, b; n   for (int i = 0; i < n; i++) n     if (f[i] > 0) n       a.push_back(i); n     else if (f[i] < 0) n       b.push_back(i); n   vector<vector<long long> > ans; n   int id = 0; n   for (int i = 0; i < a.size(); i++) { n     while (id < b.size() && f[a[i]] > 0) { n       long long x = min(f[a[i]], -f[b[id]]); n       f[a[i]] -= x; n       f[b[id]] += x; n       ans.push_back({b[id], a[i], x}); n       if (f[b[id]] == 0) id++; n     } n   } n   cout << ans.size() <<   n ; n   for (auto x : ans) cout << x[0] + 1 <<     << x[1] + 1 <<     << x[2] <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 4e5 + 100; n const int D = 19; n struct QUE { n   int l, r, len, id; n   QUE(int _l, int _r, int _len, int _id) { n     l = _l; n     r = _r; n     len = _len; n     id = _id; n   } n }; n struct OPT { n   int x, y; n   OPT(int _x, int _y) { n     x = _x; n     y = _y; n   } n }; n bool cmpx(OPT &a, OPT &b) { return a.x < b.x; } n bool cmpy(OPT &a, OPT &b) { return a.x + a.y < b.x + b.y; } n bool cmpl(QUE &a, QUE &b) { return a.l < b.l; } n bool cmpr(QUE &a, QUE &b) { return a.r < b.r; } n struct BIT { n   long long bit[N] = n       { n           0, n   }, n             n; n   void add(int x, int v) { n     while (x <= n) { n       bit[x] += v; n       x += x & -x; n     } n   } n   long long sum(int x) { n     long long s = 0; n     while (x) { n       s += bit[x]; n       x -= x & -x; n     } n     return s; n   } n } b1, b2; n struct SAM { n   int next[N][26], fa[N], len[N], pos[N], n; n   int root, tot, last; n   vector<int> g[N]; n   vector<QUE> q[N]; n   vector<OPT> p[N]; n   long long ans[N]; n   int newnode(int l) { n     fa[tot] = -1; n     for (int i = 0; i < 26; ++i) next[tot][i] = -1; n     len[tot++] = l; n     return tot - 1; n   } n   void init() { n     tot = 0; n     last = root = newnode(0); n   } n   void extend(int x, int ep) { n     int p = last; n     int cur = newnode(len[p] + 1); n     while (p != -1 && next[p][x] == -1) { n       next[p][x] = cur; n       p = fa[p]; n     } n     if (p == -1) n       fa[cur] = root; n     else { n       int q = next[p][x]; n       if (len[q] == len[p] + 1) n         fa[cur] = q; n       else { n         int tmp = newnode(len[p] + 1); n         memcpy(next[tmp], next[q], sizeof(next[q])); n         fa[tmp] = fa[q]; n         fa[q] = fa[cur] = tmp; n         while (p != -1 && next[p][x] == q) { n           next[p][x] = tmp; n           p = fa[p]; n         } n       } n     } n     last = cur; n     pos[ep] = last; n   } n   int top[N], son[N], siz[N], par[N][D]; n   void dfs1(int u) { n     for (int i = 1; i < D; ++i) par[u][i] = par[par[u][i - 1]][i - 1]; n     son[u] = -1; n     siz[u] = 1; n     for (auto v : g[u]) { n       dfs1(v); n       siz[u] += siz[v]; n       if (son[u] == -1 || siz[v] > siz[son[u]]) son[u] = v; n     } n   } n   void dfs2(int u, int t) { n     top[u] = t; n     if (~son[u]) dfs2(son[u], t); n     for (auto v : g[u]) n       if (v != son[u]) dfs2(v, v); n   } n   void build() { n     for (int i = 0; i < tot; ++i) g[i].clear(); n     for (int i = 1; i < tot; ++i) g[fa[i]].push_back(i); n     for (int i = 0; i < tot; ++i) par[i][0] = fa[i]; n     for (auto v : g[0]) dfs1(v), dfs2(v, v); n   } n   int getpos(int l, int r) { n     r = r - l + 1; n     l = pos[l]; n     for (int i = D - 1; i >= 0; --i) n       if (len[par[l][i]] >= r) l = par[l][i]; n     return l; n   } n   void addque(int l, int r, int id) { n     int tp = r - l + 1, now = getpos(l, r); n     int up = top[now]; n     while (now) { n       q[up].push_back(QUE(l, r, min(len[now], tp) - len[fa[up]], id)); n       tp -= min(len[now], tp) - len[fa[up]]; n       now = fa[up]; n       up = top[now]; n     } n   } n   void addopt(int l) { n     int tp = n - l + 1, now = pos[l]; n     int up = top[now]; n     while (now) { n       p[up].push_back( n           OPT(l + len[fa[up]] + 1, min(len[now], tp) - len[fa[up]])); n       tp -= min(len[now], tp) - len[fa[up]]; n       now = fa[up]; n       up = top[now]; n     } n   } n   void solve() { n     memset(ans, 0, sizeof(ans)); n     for (int i = 1; i < tot; ++i) n       if (top[i] == i) { n         get(p[i], q[i], len[fa[i]] + 1); n       } n   } n   void get(vector<OPT> &p, vector<QUE> &q, int tp) { n     int i, j; n     sort(p.begin(), p.end(), cmpy); n     sort(q.begin(), q.end(), cmpr); n     for (i = 0, j = 0; i < q.size(); ++i) { n       while (j < p.size() && p[j].x + p[j].y <= q[i].r + 2) { n         b1.add(p[j].y, 1); n         b2.add(p[j].y, p[j].y); n         j++; n       } n       ans[q[i].id] += n           1LL * q[i].len * (j - b1.sum(q[i].len)) + b2.sum(q[i].len); n     } n     while (j--) { n       b1.add(p[j].y, -1); n       b2.add(p[j].y, -p[j].y); n     } n     reverse(p.begin(), p.end()); n     reverse(q.begin(), q.end()); n     for (i = 0, j = 0; i < q.size(); ++i) { n       while (j < p.size() && p[j].x + p[j].y > q[i].r + 2) { n         b1.add(b1.n - p[j].x, 1); n         b2.add(b2.n - p[j].x, p[j].x); n         j++; n       } n       int c1 = b1.sum(b1.n - q[i].r - 2 + q[i].len), n           c2 = b1.sum(b2.n - q[i].r - 2); n       ans[q[i].id] += 1LL * (j - c1) * q[i].len; n       ans[q[i].id] += n           1LL * (c1 - c2) * (q[i].r + 2) - n           (b2.sum(b2.n - q[i].r - 2 + q[i].len) - b2.sum(b2.n - q[i].r - 2)); n     } n     while (j--) { n       b1.add(b1.n - p[j].x, -1); n       b2.add(b2.n - p[j].x, -p[j].x); n     } n     for (i = 0; i < p.size(); ++i) p[i].x -= tp; n     sort(p.begin(), p.end(), cmpx); n     sort(q.begin(), q.end(), cmpl); n     for (i = 0, j = 0; i < q.size(); ++i) { n       while (j < p.size() && p[j].x < q[i].l) { n         b1.add(p[j].y, 1); n         b2.add(p[j].y, p[j].y); n         j++; n       } n       ans[q[i].id] -= n           1LL * (j - b1.sum(q[i].len)) * q[i].len + b2.sum(q[i].len); n     } n     while (j--) { n       b1.add(p[j].y, -1); n       b2.add(p[j].y, -p[j].y); n     } n   } n } sam; n char s[N]; n int n, m; n int l[N], r[N]; n int main() { n   scanf( %s , s + 1); n   n = strlen(s + 1); n   sam.init(); n   for (int i = n; i >= 1; --i) sam.extend(s[i] -  a , i); n   sam.build(); n   b1.n = b2.n = 2 * n + 2; n   sam.n = n; n   for (int i = 1; i <= n; ++i) sam.addopt(i); n   scanf( %d , &m); n   for (int i = 1; i <= m; ++i) { n     scanf( %d %d , &l[i], &r[i]); n     sam.addque(l[i], r[i], i); n   } n   sam.solve(); n   for (int i = 1; i <= m; ++i) printf( %lld n , sam.ans[i]); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   long n, i, k = 0, u = 0, d = 0, l = 0, r = 0; n   cin >> n; n   cin >> s; n   for (i = 0; i < s.size(); i++) { n     if (s[i] ==  U ) u++; n     if (s[i] ==  D ) d++; n     if (s[i] ==  L ) l++; n     if (s[i] ==  R ) r++; n   } n   k += min(d, u) * 2; n   k += min(r, l) * 2; n   cout << k; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T1, typename T2> n istream& operator>>(istream& in, pair<T1, T2>& a) { n   in >> a.first >> a.second; n   return in; n } n template <typename T1, typename T2> n ostream& operator<<(ostream& out, pair<T1, T2> a) { n   out << a.first <<     << a.second; n   return out; n } n template <typename T, typename T1> n T amax(T& a, T1 b) { n   if (b > a) a = b; n   return a; n } n template <typename T, typename T1> n T amin(T& a, T1 b) { n   if (b < a) a = b; n   return a; n } n const long long fx[] = {+1, -1, +0, +0}; n const long long fy[] = {+0, +0, +1, -1}; n const int32_t M = 1e9 + 7; n const int32_t MM = 998244353; n void solve() { n   long long n; n   cin >> n; n   vector<long long> a(n), b(n); n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (long long i = 0; i < n; i++) { n     cin >> b[i]; n   } n   vector<long long> points(n, 1); n   long long only_a = 0; n   long long pa = 0, push_back = 0; n   for (long long i = 0; i < n; i++) { n     if (a[i] == 1 && b[i] == 0) { n       only_a++; n     } n     if (a[i] == 1) pa++; n     if (b[i] == 1) push_back++; n   } n   if (pa > push_back) { n     cout << 1 <<   n ; n     return; n   } else if (only_a == 0 && pa <= push_back) { n     cout << -1 <<   n ; n   } else { n     long long diff = push_back - pa + 1; n     long long x = 1 + diff / only_a; n     if (diff % only_a != 0) x++; n     cout << x <<   n ; n   } n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n bool isPrime(long long n) { n   if (n < 2) return 0; n   if (n < 4) return 1; n   if (n % 2 == 0 or n % 3 == 0) return 0; n   for (long long i = 5; i * i <= n; i += 6) n     if (n % i == 0 or n % (i + 2) == 0) return 0; n   return 1; n } n long long modexpo(long long x, long long p) { n   long long res = 1; n   x = x % 1000000007; n   while (p) { n     if (p % 2) res = res * x; n     p >>= 1; n     x = x * x % 1000000007; n     res %= 1000000007; n   } n   return res; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   cin >> t; n   while (t--) { n     long long n, g, b; n     cin >> n >> g >> b; n     long long x = n / 2 + (n % 2); n     long long ans = 0; n     ans += (x / g) * g + ((x / g + (x % g ? 1 : 0)) - 1) * b; n     ans += x % g; n     if (n > ans) ans += n - ans; n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n string a[200009]; n int pre[1 << 20][22], cost[200009], n, m, dp[200009]; n int compute(string suf, string pre) { n   for (int k = int(0); k <= int(m - 1); k++) { n     int j = k, i = 0; n     while (j < m) { n       if (suf[j] == pre[i]) { n         j++; n         i++; n       } else n         break; n     } n     if (j == m) return k; n   } n   return m; n } n int calmask(string str, int len) { n   int mask = 0; n   for (int i = int(m - len); i <= int(m - 1); i++) { n     mask = mask * 2; n     if (str[i] ==  1 ) mask++; n   } n   return mask; n } n int calmask2(string str, int len) { n   int mask = 0; n   for (int i = int(0); i <= int(len - 1); i++) { n     mask = mask * 2; n     if (str[i] ==  1 ) mask++; n   } n   return mask; n } n int main() { n   std::ios::sync_with_stdio(false); n   int ans; n   cin >> n; n   for (int i = int(1); i <= int(n); i++) cin >> a[i]; n   m = a[1].length(); n   for (int i = int(0); i <= int((1 << m) - 1); i++) n     for (int j = int(0); j <= int(m); j++) pre[i][j] = 2000000000; n   cost[0] = 0; n   for (int i = int(1); i <= int(n - 1); i++) n     cost[i] = cost[i - 1] + compute(a[i], a[i + 1]); n   pre[0][0] = cost[n - 1]; n   ans = 2000000000; n   for (int i = int(n); i >= int(1); i--) { n     int mini = 2000000000; n     int mask = 0; n     for (int j = int(0); j <= int(m); j++) { n       if (i == 1 && j > 0) break; n       mini = min(mini, pre[mask][j] + m - j); n       if (m - j - 1 >= 0 && a[i - 1][m - j - 1] ==  1 ) mask |= (1 << j); n     } n     mini = mini - cost[i - 1]; n     dp[i] = mini; n     if (i - 2 >= 0) { n       mask = 0; n       for (int j = int(0); j <= int(m); j++) { n         pre[mask][j] = min(pre[mask][j], mini + cost[i - 2]); n         mask *= 2; n         if (j < m && a[i][j] ==  1 ) mask++; n       } n     } n   } n   cout << dp[1] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string a, b; n   cin >> a >> b; n   for (int i = 0; i < a.size(); i++) { n     a[i] = tolower(a[i]); n     b[i] = tolower(b[i]); n   } n   if (a.compare(b) == 0) n     cout <<  0  n          <<   n ; n   else { n     for (int i = 0; i < a.size(); i++) { n       if (a[i] < b[i]) { n         cout <<  -1  n              <<   n ; n         break; n       } n       if (a[i] > b[i]) { n         cout <<  1  n              <<   n ; n         break; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n inline int sbt(int x) { return __builtin_popcount(x); } n using namespace std; n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   cout << name <<   :   << arg1 << std::endl; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cout.write(names, comma - names) <<   :   << arg1 <<   |  ; n   __f(comma + 1, args...); n } n int main() { n   cin.sync_with_stdio(false); n   cout.sync_with_stdio(false); n   int t; n   cin >> t; n   while (t--) { n     int n, x, y, d; n     int res = 1000000007; n     cin >> n >> x >> y >> d; n     int dff = abs(x - y); n     if (!(dff % d)) res = min(res, dff / d); n     if (!((y - 1) % d)) n       res = min(res, (y - 1) / d + (x - 1) / d + (((x - 1) % d) > 0)); n     if (!((n - y) % d)) n       res = min(res, (n - x) / d + (n - y) / d + (((n - x) % d) > 0)); n     if (res == 1000000007) n       cout << -1; n     else n       cout << res; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int INFI = (1 << 29); n const long long INFL = (1LL << 62); n using namespace std; n long long f[1000010]; n void solve() { n   long long n, k, d, c = 0, r = INFL; n   cin >> n >> k >> d; n   vector<long long> v(n); n   for (long long i = 0; i < n; i++) cin >> v[i]; n   for (long long i = 0; i < n; i++) { n     f[v[i]]++; n     c += (f[v[i]] == 1); n     if (i >= d) { n       f[v[i - d]]--; n       c -= (!f[v[i - d]]); n     } n     if (i >= (d - 1)) r = min(r, c); n   } n   cout << r <<   n ; n   for (long long i = 0; i < n; i++) f[v[i]] = 0; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long casos; n   cin >> casos; n   while (casos--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int mod; n long long int power(long long int a, long long int b) { n   if (b == 0) return 1; n   if (b % 2 == 1) return (power(a, b - 1) * a) % mod; n   long long int q = power(a, b / 2); n   return (q * q) % mod; n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long int n; n   cin >> n; n   long long int a[n]; n   for (long long int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   long long int ans = 1; n   for (long long int i = 0; i < n; i++) { n     long long int cnt = 0; n     long long int prev = a[i]; n     for (long long int j = i - 1; j >= 0; j--) { n       if (a[j] <= prev) { n         prev = a[j]; n         cnt++; n       } else n         break; n     } n     prev = a[i]; n     for (long long int j = i + 1; j < n; j++) { n       if (a[j] <= prev) { n         prev = a[j]; n         cnt++; n       } else n         break; n     } n     cnt++; n     ans = max(ans, cnt); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   cerr << name <<   :   << arg1 << std::endl; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cerr.write(names, comma - names) <<   :   << arg1 <<   |  ; n   __f(comma + 1, args...); n } n template <class T> n ostream& operator<<(ostream& os, vector<T> V) { n   os <<  [  ; n   for (auto v : V) os << v <<    ; n   return os <<  ] ; n } n template <class L, class R> n ostream& operator<<(ostream& os, pair<L, R> P) { n   return os <<  (  << P.first <<  ,  << P.second <<  ) ; n } n const long long int mod = 998244353; n const long long int maxn = 200001; n long long int power(long long int x, long long int n) { n   long long int res = 1; n   for (; n > 0; n >>= 1) { n     if (n & 1) res = (res * x) % mod; n     x = (x * x) % mod; n   } n   return res; n } n long long int no_of_ways(long long int m, long long int x) { n   long long int ans = 0; n   for (long long int r = 2; r <= 1000000; r++) { n     long long int maxi = r * r * r; n     if (maxi > x) break; n     ans += (x / maxi); n   } n   return ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int m; n   cin >> m; n   long long int l = 1, r = 1e18; n   long long int ans = -1; n   while (r - l > 1) { n     long long int mid = (l + r) / 2; n     if (no_of_ways(m, mid) >= m) n       r = mid; n     else if (no_of_ways(m, mid) < m) n       l = mid + 1; n   } n   if (no_of_ways(m, l) == m) n     ans = l; n   else if (no_of_ways(m, r) == m) n     ans = r; n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   for (int i = 2; i < s.size(); i++) { n     int a = 0, b = 0, c = 0; n     for (int j = i; j >= i - 2; j--) { n       if (s[j] ==  A ) a++; n       if (s[j] ==  B ) b++; n       if (s[j] ==  C ) c++; n     } n     if (a > 0 && b > 0 && c > 0) { n       cout <<  Yes ; n       return 0; n     } n   } n   cout <<  No ; n   return 0; n } n


#include <bits/stdc++.h> n class point2D { n  public: n   long long x, y; n   point2D() {} n   point2D(long long x, long long y) : x(x), y(y) {} n   bool operator<(const point2D &other) const { n     return ((y == other.y) ? (x > other.x) : (y > other.y)); n   } n }; n point2D operator-(const point2D &u, const point2D &v) { n   return point2D(u.x - v.x, u.y - v.y); n } n long long det(const point2D &u, const point2D &v) { n   return u.x * v.y - v.x * u.y; n } n long long dir(const point2D &p, const point2D &u, const point2D &v) { n   return det(u - p, v - p); n } n bool contains(int n, point2D vertex, point2D polygon[]) { n   int l = 1, r = n - 1, m; n   while (l < r) { n     m = (l + r) / 2; n     if (dir(polygon[0], polygon[m], vertex) <= 0) n       r = m; n     else n       l = m + 1; n   } n   if (r == 1 || dir(polygon[0], polygon[n - 1], vertex) >= 0 || n       dir(polygon[r], polygon[r - 1], vertex) >= 0) n     return 0; n   return 1; n } n int n, m; n point2D polygonA[100000], vertexB; n int main() { n   std::cin >> n; n   for (int i = n - 1; i >= 0; i--) { n     std::cin >> polygonA[i].x >> polygonA[i].y; n   } n   std::cin >> m; n   for (int i = 0; i < m; i++) { n     std::cin >> vertexB.x >> vertexB.y; n     if (!contains(n, vertexB, polygonA)) { n       std::cout <<  NO  << std::endl; n       return 0; n     } n   } n   std::cout <<  YES  << std::endl; n   return 0; n } n