#include <bits/stdc++.h> n namespace mem { n namespace stdval { n using i32 = int; n using i64 = long long; n using u32 = unsigned int; n using u64 = unsigned long long; n using f32 = float; n using f64 = double; n using i128 = __int128_t; n using u128 = __uint128_t; n }  // namespace stdval n namespace utils { n using std::cerr; n using std::cin; n using std::cout; n using std::endl; n using std::function; n using std::lower_bound; n using std::make_pair; n using std::make_tuple; n using std::max_element; n using std::min_element; n using std::reverse; n using std::shuffle; n using std::sort; n using std::swap; n using std::tie; n using std::upper_bound; n }  // namespace utils n namespace io { n namespace fastio { n const int BUFFER = 1 << 21; n char ibuf[BUFFER], *iS, *iT; n inline int getc() { n   if (iS == iT) { n     iT = (iS = ibuf) + fread(ibuf, 1, BUFFER, stdin); n     return iS == iT ? EOF : *iS++; n   } else { n     return *iS++; n   } n } n char obuf[BUFFER], *oS = obuf, *oT = oS + BUFFER - 1; n inline void flush() { n   fwrite(obuf, 1, oS - obuf, stdout); n   oS = obuf; n } n inline void putc(int x) { n   *oS++ = x; n   if (oS == oT) flush(); n } n struct Flusher { n   ~Flusher() { flush(); } n } flusher; n }  // namespace fastio n using fastio::getc; n using fastio::putc; n template <class T> n inline void readDigit(T &x) { n   x = getc(); n   while (!isdigit(x)) x = getc(); n } n inline int readDigit() { n   int x; n   readDigit(x); n   return x; n } n template <class T> n inline void readAlpha(T &x) { n   x = getc(); n   while (!isalpha(x)) x = getc(); n } n inline int readAlpha() { n   int x; n   readAlpha(x); n   return x; n } n template <class T> n inline void readInt(T &x) { n   x = 0; n   bool f = 0; n   char c = getc(); n   while (!isdigit(c)) f ^= c ==  - , c = getc(); n   while (isdigit(c)) x = x * 10 + c -  0 , c = getc(); n   if (f) x = -x; n } n inline void read(int &x) { n   x = 0; n   bool f = 0; n   char c = getc(); n   while (!isdigit(c)) f ^= c ==  - , c = getc(); n   while (isdigit(c)) x = x * 10 + c -  0 , c = getc(); n   if (f) x = -x; n } n inline void read(unsigned int &x) { n   x = 0; n   bool f = 0; n   char c = getc(); n   while (!isdigit(c)) f ^= c ==  - , c = getc(); n   while (isdigit(c)) x = x * 10 + c -  0 , c = getc(); n   if (f) x = -x; n } n inline void read(long long &x) { n   x = 0; n   bool f = 0; n   char c = getc(); n   while (!isdigit(c)) f ^= c ==  - , c = getc(); n   while (isdigit(c)) x = x * 10 + c -  0 , c = getc(); n   if (f) x = -x; n } n inline void read(unsigned long long &x) { n   x = 0; n   bool f = 0; n   char c = getc(); n   while (!isdigit(c)) f ^= c ==  - , c = getc(); n   while (isdigit(c)) x = x * 10 + c -  0 , c = getc(); n   if (f) x = -x; n } n inline void read(char &x) { x = getc(); } n template <class T = int> n inline T read() { n   T x; n   read(x); n   return x; n } n template <class T, class... Args> n inline void read(T &x, Args &...args) { n   read(x), read(args...); n } n inline void print(int x) { n   if (x < 0) putc( - ), x = -x; n   if (x > 9) print(x / 10); n   putc( 0  + x % 10); n } n inline void print(unsigned int x) { n   if (x < 0) putc( - ), x = -x; n   if (x > 9) print(x / 10); n   putc( 0  + x % 10); n } n inline void print(long long x) { n   if (x < 0) putc( - ), x = -x; n   if (x > 9) print(x / 10); n   putc( 0  + x % 10); n } n inline void print(unsigned long long x) { n   if (x < 0) putc( - ), x = -x; n   if (x > 9) print(x / 10); n   putc( 0  + x % 10); n } n inline void print(char x) { putc(x); } n inline void print(const char *s) { n   int len = strlen(s); n   for (int i = 0; i < len; i++) putc(s[i]); n } n inline void print(const std::string &s) { n   for (int i = 0; i < s.length(); i++) putc(s[i]); n } n template <class T, class... Args> n inline void print(const T &x, Args... args) { n   print(x), print(args...); n } n template <class... Args> n inline void println(Args... args) { n   print(args...), putchar(  n ); n } n }  // namespace io n namespace random { n const int LuckyNumber = 20040725; n std::mt19937 rng(LuckyNumber ^ n                  std::chrono::steady_clock::now().time_since_epoch().count()); n std::mt19937_64 rng64( n     LuckyNumber ^ std::chrono::steady_clock::now().time_since_epoch().count()); n template <class T> n inline T rand(T l, T r) { n   return std::uniform_int_distribution<T>(l, r)(rng); n } n template <class T> n inline T rand64(T l, T r) { n   return std::uniform_int_distribution<T>(l, r)(rng); n } n }  // namespace random n namespace modint { n template <const int mod> n struct Z { n   int x; n   inline Z() { x = 0; } n   inline Z(int t) { x = t; } n   inline void operator-=(Z a) { (x -= a.x) < 0 && (x += mod); } n   inline void operator+=(Z a) { (x += a.x) >= mod && (x -= mod); } n   inline void operator*=(Z a) { x = (long long)x * a.x % mod; } n   friend inline Z operator*(Z a, Z b) { return (long long)a.x * b.x % mod; } n   friend inline Z operator-(Z a, Z b) { n     return ((a.x -= b.x) < 0 && (a.x += mod)), a; n   } n   friend inline Z operator+(Z a, Z b) { n     return ((a.x += b.x) >= mod && (a.x -= mod)), a; n   } n }; n template <const int mod> n inline Z<mod> finv(Z<mod> x) { n   if (x.x < 2) return x; n   return (mod - mod / x.x) * finv(mod % x.x); n } n template <const int mod> n inline Z<mod> fpow(Z<mod> a, int b) { n   Z<mod> s = 1; n   for (; b; b >>= 1, a = a * a) n     if (b & 1) s = s * a; n   return s; n } n template <const int mod> n inline void init_inverse(int n, Z<mod> *inv) { n   inv[0] = inv[1] = 1; n   for (int i = 2; i < n; i++) inv[i] = (mod - mod / i) * inv[mod % i]; n } n template <const int mod> n inline void init_factorial(int n, Z<mod> *fac, Z<mod> *ifac) { n   fac[0] = 1, init_inverse(n, ifac); n   for (int i = 1; i < n; i++) n     fac[i] = fac[i - 1] * i, ifac[i] = ifac[i - 1] * ifac[i]; n } n }  // namespace modint n namespace math { n using std::max; n using std::min; n template <class T> n inline T abs(T x) { n   return x < 0 ? -x : x; n } n template <class T> n inline T gcd(T n, T m) { n   return m ? gcd(m, n % m) : n; n } n template <class T> n inline T lcm(T n, T m) { n   return n / gcd(n, m) * m; n } n template <const stdval::u64 p> n struct FastDiv { n   stdval::u64 t, i; n   inline FastDiv() : t(stdval::u64(-1) / p), i(mul_inv(p)) {} n   inline bool divide(stdval::u64 n) { return n * i <= t; } n   inline bool divide(stdval::i64 n) { n     return stdval::u64(n < 0 ? -n : n) * i <= t; n   } n   inline stdval::u64 mul_inv(stdval::u64 n) { n     stdval::u64 x = n; n     for (int i = 0; i < 5; ++i) x *= 2 - n * x; n     return x; n   } n }; n template <const stdval::u64 b> n struct FastMod { n   stdval::u64 m; n   inline FastMod() : m(stdval::u64((stdval::u128(1) << 64) / b)) {} n   inline stdval::u64 reduce(stdval::u64 a) { n     stdval::u64 q = (stdval::u64)((stdval::u128(m) * a) >> 64); n     stdval::u64 r = a - q * b; n     return r >= b ? r - b : r; n   } n }; n }  // namespace math n namespace container { n using std::map; n using std::pair; n using std::set; n using std::tuple; n using std::unordered_map; n using std::unordered_set; n template <class T> n struct vector : std::vector<T> { n   using std::vector<T>::vector; n   vector() : std::vector<T>() {} n   vector(const std::vector<T> &plain) : std::vector<T>(plain) {} n   inline void read(int s = -1) { n     if (~s) this->resize(s); n     for (size_t i = 0; i < this->size(); i++) { n       io::read(this->operator[](i)); n     } n   } n   inline void print(char pt0 =    , char pt1 =   n ) { n     for (size_t i = 0; i < this->size(); i++) { n       io::print(this->operator[](i)); n       if (i + 1 < this->size()) io::putc(pt0); n     } n     io::putc(pt1); n   } n   inline void sort() { std::sort(this->begin(), this->end()); } n   inline void concat(const vector &rhs) { n     this->insert(this->end(), rhs.begin(), rhs.end()); n   } n   inline bool includes(const T &x) const { n     return std::find(this->begin(), this->end(), x) != this->end(); n   } n   inline vector slice(int l, int r) const { n     if (l > r) return {}; n     if (r < this->size()) return vector(this->begin() + l, this->begin() + r); n     vector<int> rsp = (this->begin() + l, this->end()); n     return rsp.resize(r - l), rsp; n   } n   inline void from(const std::set<T> &src) { n     this->resize(src.size()); n     auto it = this->begin(); n     for (const T e : src) *it++ = e; n   } n   template <class Function> n   inline void forEach(Function func) { n     for (const auto &it : *this) func(it); n   } n   template <class R, class Function> n   inline vector<R> _map(Function func) const { n     vector<R> res(this->size()); n     for (size_t i = 0; i < this->size(); i++) n       res[i] = func(this->operator[](i)); n     return res; n   } n   template <class R> n   inline vector<R> map(R func(T)) const { n     return this->_map<R>(func); n   } n   template <class R> n   inline vector<R> map(const std::function<R(T)> &func) const { n     return this->_map<R>(func); n   } n }; n }  // namespace container n namespace str { n using namespace mem::container; n struct string : std::string { n   using std::string::string; n   string() : std::string(  ) {} n   string(const std::string &plain) : std::string(plain) {} n   inline string join(const vector<string> &) const; n   inline string join(const std::vector<string> &) const; n   template <class T> n   inline string join(const vector<T> &) const; n   template <class T> n   inline string join(const std::vector<T> &) const; n   vector<string> split(const string &delim) const { n     if (this->empty()) return {}; n     char *src = new char[this->length() + 1]; n     strcpy(src, this->c_str()); n     char *tar = new char[delim.length() + 1]; n     strcpy(tar, delim.c_str()); n     vector<string> rsp; n     for (char *pos = strtok(src, tar); pos; pos = strtok(nullptr, tar)) n       rsp.push_back(string(pos)); n     delete[] src; n     delete[] tar; n     return rsp; n   } n   template <class... Args> n   static inline string format(const char *fm, Args... args) { n     int len = snprintf(nullptr, 0, fm, args...); n     char *buf = new char[len + 1]; n     snprintf(buf, len + 1, fm, args...); n     string str(buf); n     delete[] buf; n     return str; n   } n   template <class... Args> n   static inline string format(const string &fm, Args... args) { n     return format(fm.c_str(), args...); n   } n }; n inline string to_string(const float &x) { return std::to_string(x); } n inline string to_string(const double &x) { return std::to_string(x); } n inline string to_string(const int &x) { return std::to_string(x); } n inline string to_string(const unsigned int &x) { return std::to_string(x); } n inline string to_string(const long long &x) { return std::to_string(x); } n inline string to_string(const unsigned long long &x) { n   return std::to_string(x); n } n template <class T> n inline string to_string(const vector<T> &vet) { n   return  {  + string( , ).join(vet) +  } ; n } n template <class T> n inline string to_string(const std::vector<T> &vet) { n   return to_string(vector<T>(vet.begin(), vet.end())); n } n template <const int mod> n inline string to_string(const mem::modint::Z<mod> &zval) { n   return std::to_string(zval.x); n } n inline string string::join(const vector<string> &vet) const { n   if (!vet.size()) return   ; n   string res = string(vet[0]); n   for (size_t i = 1; i < vet.size(); i++) { n     res += *this; n     res += string(vet[i]); n   } n   return res; n } n inline string string::join(const std::vector<string> &vet) const { n   if (!vet.size()) return   ; n   string res = string(vet[0]); n   for (size_t i = 1; i < vet.size(); i++) { n     res += *this; n     res += string(vet[i]); n   } n   return res; n } n template <class T> n inline string string::join(const vector<T> &vet) const { n   if (!vet.size()) return   ; n   string res = to_string(vet[0]); n   for (size_t i = 1; i < vet.size(); i++) { n     res += *this; n     res += to_string(vet[i]); n   } n   return res; n } n template <class T> n inline string string::join(const std::vector<T> &vet) const { n   if (!vet.size()) return   ; n   string res = to_string(vet[0]); n   for (size_t i = 1; i < vet.size(); i++) { n     res += *this; n     res += to_string(vet[i]); n   } n   return res; n } n inline void print(const str::string &s) { n   for (size_t i = 0; i < s.length(); i++) mem::io::putc(s[i]); n } n template <class... Args> n inline void printfm(const char *fm, Args... args) { n   print(str::string().format(fm, args...)); n } n template <class... Args> n inline void printfm(const string &fm, Args... args) { n   print(str::string().format(fm, args...)); n } n template <class... Args> n inline void printfm(const std::string &fm, Args... args) { n   print(str::string().format(fm, args...)); n } n }  // namespace str n using namespace io; n using namespace str; n using namespace math; n using namespace utils; n using namespace modint; n using namespace random; n using namespace stdval; n using namespace container; n }  // namespace mem n const int N = 5e5 + 10; n using namespace mem::io; n using namespace mem::container; n int n, m, q, p[N], anc[N]; n bool mrk[N], vis[N]; n vector<int> ele[N]; n pair<vector<int>, int> dat[N]; n struct cmp { n  public: n   inline bool operator()(const int x, const int y) { return p[x] < p[y]; } n }; n std::priority_queue<int, std::vector<int>, cmp> f[N], g[N]; n struct Edge { n   int u, v; n } e[N]; n struct Query { n   int o, x; n } y[N]; n int find(int x) { n   if (x == anc[x]) return x; n   return find(anc[x]); n } n int pop(int k) { n   while (f[k].size() && g[k].size()) { n     if (f[k].top() == g[k].top()) { n       f[k].pop(), g[k].pop(); n     } else { n       int x = f[k].top(); n       f[k].pop(); n       return x; n     } n   } n   if (f[k].size()) { n     int x = f[k].top(); n     f[k].pop(); n     return x; n   } else { n     return 0; n   } n } n pair<vector<int>, int> merge(int u, int v) { n   u = find(u), v = find(v); n   if (u == v) return {{}, -1}; n   if (ele[u].size() > ele[v].size()) std::swap(u, v); n   ele[v].insert(ele[v].end(), ele[u].begin(), ele[u].end()); n   anc[u] = v; n   return {ele[u], u}; n } n int main() { n   read(n, m, q); n   for (int i = 1; i <= n; i++) read(p[i]); n   for (int i = 1; i <= m; i++) read(e[i].u), read(e[i].v); n   for (int i = 1; i <= q; i++) { n     read(y[i].o), read(y[i].x); n     if (y[i].o == 2) mrk[y[i].x] = true; n   } n   for (int i = 1; i <= n; i++) { n     anc[i] = i; n     ele[i].push_back(i); n   } n   for (int i = 1; i <= m; i++) n     if (!mrk[i]) { n       merge(e[i].u, e[i].v); n     } n   for (int i = q; i >= 1; i--) { n     if (y[i].o == 2) { n       dat[i] = merge(e[y[i].x].u, e[y[i].x].v); n     } n   } n   for (int i = 1; i <= n; i++) { n     f[find(i)].push(i); n   } n   for (int i = 1; i <= q; i++) { n     if (y[i].o == 1) { n       int ans = pop(find(y[i].x)); n       vis[ans] = true; n       print(p[ans],   n ); n     } else { n       int src = find(e[y[i].x].u); n       for (int x : dat[i].first) { n         anc[x] = dat[i].second; n         if (!vis[x]) { n           f[dat[i].second].push(x); n           g[src].push(x); n         } n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long n, v, cost, i; n   cin >> n >> v; n   if (v >= (n - 1)) n     cout << n - 1; n   else { n     cost = v; n     for (i = 2; i <= n; i++) { n       v--; n       if ((n - i) <= v) { n         cout << cost; n         break; n       } else { n         cost += i; n         v++; n       } n     } n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma comment(linker,  /stack:200000000 ) n int t, n, m, j, ans, k, a, b, c, d, e, f, sum, i, sz, row, col, l; n string s, s2, s3, s4; n deque<pair<int, int> > v; n void brainfuck(); n int main() { n   ios_base::sync_with_stdio(NULL); n   cin.tie(NULL); n   cout.tie(NULL); n   brainfuck(); n   return 0; n } n void brainfuck() { n   cin >> n >> m >> k; n   for (i = 1; i <= n; i++) { n     for (j = 1; i & 1 && j <= m; j++) v.push_back({i, j}); n     for (j = m; i % 2 == 0 && j >= 1; j--) v.push_back({i, j}); n   } n   for (j = 1; j <= k; j++) { n     if (j != k) n       a = 2; n     else n       a = v.size(); n     cout << a; n     while (a--) { n       cout <<     << v.front().first <<     << v.front().second; n       v.pop_front(); n     } n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int s[18257 + 1]; n int main() { n   memset(s, 0, sizeof(s)); n   s[1] = 1; n   for (int i = 2; i <= 18257; i++) { n     s[i] = (2 * i - 3) * 6 + 6; n   } n   int a; n   scanf( %d , &a); n   if (a == 1) { n     cout << s[1] << endl; n   } else { n     int sum = 0; n     for (int i = 1; i <= a; i++) { n       sum += s[i]; n     } n     cout << sum << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 210, MAX_K = 1010, MOD = 1e9 + 7; n int N, K, arr[MAX_N], dp[MAX_N][MAX_N][MAX_K]; n void add(int& a, long long b) { n   b %= MOD; n   a = (a + b) % MOD; n } n int solve() { n   sort(arr + 1, arr + N + 1); n   dp[0][0][0] = 1; n   for (int i = 1; i <= N; i++) { n     for (int j = 0; j <= i; j++) { n       for (int k = 0; k <= K; k++) { n         int v = dp[i - 1][j][k]; n         int nk = k + j * (arr[i] - arr[i - 1]); n         if (nk > K) continue; n         add(dp[i][j][nk], v); n         add(dp[i][j][nk], 1LL * j * v); n         add(dp[i][j + 1][nk], v); n         if (j) add(dp[i][j - 1][nk], 1LL * j * v); n       } n     } n   } n   int ret = 0; n   for (int k = 0; k <= K; k++) { n     add(ret, dp[N][0][k]); n   } n   return ret; n } n void read() { n   cin >> N >> K; n   for (int i = 1; i <= N; i++) cin >> arr[i]; n } n int main() { n   read(); n   cout << solve() << endl; n   return (0); n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n const int mod = 1000000007; n const int N = 5e5 + 5; n int n, m, q, ans[N]; n struct node { n   int cnt, id; n } c[N]; n struct ask { n   int id; n   long long x; n } Q[N]; n int st[N << 2]; n void update(int o, int l, int r, int pos) { n   if (l == r) { n     ++st[o]; n     return; n   } n   int mid = l + r >> 1; n   if (pos <= mid) n     update(o << 1, l, mid, pos); n   else n     update(o << 1 | 1, mid + 1, r, pos); n   st[o] = st[o << 1] + st[o << 1 | 1]; n } n int query(int o, int l, int r, int k) { n   if (l == r) return l; n   int mid = l + r >> 1; n   if (k <= st[o << 1]) n     return query(o << 1, l, mid, k); n   else n     return query(o << 1 | 1, mid + 1, r, k - st[o << 1]); n } n int main() { n   scanf( %d%d%d , &n, &m, &q); n   for (int i = 1; i <= n; i++) { n     int x; n     scanf( %d , &x); n     ++c[x].cnt; n   } n   for (int i = 1; i <= m; i++) c[i].id = i; n   for (int i = 1; i <= q; i++) { n     long long x; n     scanf( %lld , &x); n     Q[i].id = i, Q[i].x = x; n   } n   sort(c + 1, c + 1 + m, [](const node& a, const node& b) { n     return a.cnt == b.cnt ? a.id < b.id : a.cnt < b.cnt; n   }); n   sort(Q + 1, Q + 1 + q, [](const ask& a, const ask& b) { return a.x < b.x; }); n   long long now = n; n   int j = 1; n   for (int i = 1; i <= m; i++) { n     long long nxt = (i == m ? 2e18 : 1ll * (c[i + 1].cnt - c[i].cnt) * i + now); n     update(1, 1, m, c[i].id); n     while (j <= q && Q[j].x <= nxt) { n       long long x = Q[j].x; n       int tmp = (x - now) % i; n       if (!tmp) tmp = i; n       ans[Q[j].id] = query(1, 1, m, tmp); n       ++j; n     } n     now = nxt; n   } n   for (int i = 1; i <= q; i++) printf( %d n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char str[1000005]; n int num[1000005]; n int main() { n   int i, j, len, ans; n   while (scanf( %s , str) != EOF) { n     len = strlen(str); n     for (i = 0, j = len - 1; i < j; i++, j--) { n       swap(str[i], str[j]); n     } n     str[len] =  0 ; n     memset(num, 0, sizeof(num)); n     ans = 0; n     for (i = 0; i <= len; i++) { n       if (str[i] ==  1 ) { n         for (j = i + 1; j <= len; j++) { n           if (str[j] ==  0 ) break; n         } n         if (j != i + 1) { n           num[j] = 1; n           num[i] = -1; n           str[j] =  1 ; n         } else { n           num[i] = 1; n         } n         i = j - 1; n       } n     } n     for (i = 0; i <= len; i++) { n       if (num[i]) ans++; n     } n     printf( %d n , ans); n     for (i = 0; i <= len; i++) { n       if (num[i]) { n         if (num[i] == 1) printf( + ); n         if (num[i] == -1) printf( - ); n         printf( 2^%d n , i); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> z; n vector<int> pr; n vector<vector<int>> ans; n int s, f; n long long pow(long long n, long long s) { n   if (s == 0) n     return 1; n   else { n     if (s % 2 == 1) { n       return (n * (pow(n, s - 1))) % 1000000007; n     } n     if (s % 2 == 0) { n       long long k = (pow(n, s / 2)) % 1000000007; n       return (k * k) % 1000000007; n     } n   } n } n void prfix(string s) { n   for (int i = 1; i < s.size(); i++) { n     pr[i] = pr[i - 1]; n     while (pr[i] > 0 && s[i] != s[pr[i]]) { n       pr[i] = pr[pr[i] - 1]; n     } n     if (s[i] == s[pr[i]]) pr[i]++; n   } n } n void zet(string s) { n   int l = 0, r = 0; n   for (int i = 1; i < s.size(); i++) { n     if (i <= r) { n       z[i] = min(z[i - l], r - i + 1); n     } n     for (; z[i] + i < s.size() && s[z[i] + i] == s[z[i]]; z[i]++) n       ; n     if (i + z[i] - 1 >= r) { n       l = i; n       r = i + z[i] - 1; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long double R, x1, y1, x2, y2; n   cin >> R >> x1 >> y1 >> x2 >> y2; n   if (sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) >= R) { n     cout << x1 <<     << y1 <<     << R; n     return 0; n   } n   if (x1 == x2 && y1 == y2) { n     long double y3 = y1 + R / 2; n     cout << x1 <<     << y3 <<     << R / 2; n     return 0; n   } n   long double c = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); n   long double x4 = (x1 - x2) * (R + c) / 2 / c + x2; n   long double y4 = (y1 - y2) * (R + c) / 2 / c + y2; n   cout.precision(10); n   cout << fixed << x4 <<     << y4 <<     << (R + c) / 2; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i = 0, n; n   bool ok(false); n   cin >> n; n   while (i * (i + 1) / 2 <= n && ok == false) { n     if (i * (i + 1) / 2 == n) { n       ok = true; n     } n     i++; n   } n   (ok == true) ? cout <<  YES  : cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = (int)1e9 + 7; n template <class X, class Y> n void minimize(X &x, const Y &y) { n   if (x > y) x = y; n } n template <class X, class Y> n void maximize(X &x, const Y &y) { n   if (x < y) x = y; n } n vector<int> adj[5050]; n int nLeaf[5050]; n int f[5050][5050][2]; n int tmp[5050][2]; n int n; n void loadTree(void) { n   scanf( %d , &n); n   for (int love = 0, _n = (n - 1); love < _n; love = love + 1) { n     int u, v; n     scanf( %d%d , &u, &v); n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   if (n == 2) { n     printf( 1 n ); n     exit(0); n   } n   memset(f, 0x3f, sizeof f); n } n void dfs(int u, int p) { n   bool leaf = true; n   for (__typeof((adj[u]).begin()) it = (adj[u]).begin(); it != (adj[u]).end(); n        it++) n     if (*it != p) { n       int v = *it; n       dfs(v, u); n       leaf = false; n     } n   if (leaf) { n     nLeaf[u] = 1; n     for (int i = 0, _n = (2); i < _n; i = i + 1) f[u][i][i] = 0; n     return; n   } n   for (int i = 0, _n = (2); i < _n; i = i + 1) f[u][0][i] = 0; n   for (__typeof((adj[u]).begin()) it = (adj[u]).begin(); it != (adj[u]).end(); n        it++) n     if (*it != p) { n       int v = *it; n       for (int i = 0, _n = (nLeaf[u] + 1); i < _n; i = i + 1) n         for (int j = 0, _n = (2); j < _n; j = j + 1) { n           tmp[i][j] = f[u][i][j]; n           f[u][i][j] = INF; n         } n       for (int i = 0, _n = (nLeaf[u] + 1); i < _n; i = i + 1) n         for (int j = 0, _n = (2); j < _n; j = j + 1) n           for (int k = 0, _n = (nLeaf[v] + 1); k < _n; k = k + 1) n             for (int l = 0, _n = (2); l < _n; l = l + 1) n               minimize(f[u][i + k][j], tmp[i][j] + f[v][k][l] + (j != l)); n       nLeaf[u] += nLeaf[v]; n     } n } n void process(void) { n   for (int i = (1), _b = (n); i <= _b; i = i + 1) n     if (adj[i].size() > 1) { n       dfs(i, -1); n       printf( %d n , min(f[i][nLeaf[i] / 2][0], f[i][nLeaf[i] / 2][1])); n       return; n     } n   assert(false); n } n int main(void) { n   loadTree(); n   process(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline bool chkmin(T &x, T y) { n   return y < x ? x = y, 1 : 0; n } n template <typename T> n inline bool chkmax(T &x, T y) { n   return x < y ? x = y, 1 : 0; n } n const int INF = 0x3f3f3f3f; n const int N = 1e2 + 10, Node = 2e3 + 10, Edge = Node * Node / 2; n int Dis[N][N], p[Node], a[Node], f[Node]; n int to[Edge], nex[Edge], beg[Node], flow[Edge], dis[Node], cur[Node]; n int S, T, e = 1; n inline int read() { n   int x = 0, flag = 1; n   char ch = getchar(); n   while (!isdigit(ch) && ch !=  - ) ch = getchar(); n   if (ch ==  - ) flag = -1, ch = getchar(); n   while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch -  0 ), ch = getchar(); n   return x * flag; n } n inline void add(int x, int y, int z) { n   to[++e] = y, nex[e] = beg[x], beg[x] = e, flow[e] = z; n   to[++e] = x, nex[e] = beg[y], beg[y] = e, flow[e] = 0; n } n inline bool bfs() { n   queue<int> q; n   memset(dis, 0, sizeof(dis)); n   dis[S] = 1; n   q.push(S); n   while (!q.empty()) { n     int x = q.front(); n     q.pop(); n     for (int i = beg[x]; i; i = nex[i]) n       if (flow[i] && !dis[to[i]]) dis[to[i]] = dis[x] + 1, q.push(to[i]); n   } n   return dis[T]; n } n inline int dfs(int x, int f) { n   if (x == T) return f; n   int res = f; n   for (int &i = cur[x]; i; i = nex[i]) n     if (flow[i] && dis[to[i]] == dis[x] + 1) { n       int v = dfs(to[i], min(f, flow[i])); n       flow[i] -= v, flow[i ^ 1] += v, f -= v; n       if (!f) return res; n     } n   return res - f; n } n int main() { n   int n = read(), m = read(); n   memset(dis, 63, sizeof(dis)); n   for (int i = (1), iend = (m); i <= iend; i++) { n     int u = read(), v = read(); n     Dis[u][v] = Dis[v][u] = 1; n   } n   for (int i = (1), iend = (n); i <= iend; i++) Dis[i][i] = 0; n   for (int k = (1), kend = (n); k <= kend; k++) n     for (int i = (1), iend = (n); i <= iend; i++) n       for (int j = (1), jend = (n); j <= jend; j++) n         chkmin(Dis[i][j], Dis[i][k] + Dis[k][j]); n   int A = read(), B = read(), k = read(), h = read(); n   S = A + B + 1, T = A + B + 2; n   for (int i = (1), iend = (A); i <= iend; i++) n     p[i] = read(), a[i] = read(), f[i] = read(), add(S, i, 1); n   for (int i = (1), iend = (B); i <= iend; i++) { n     add(i + A, T, 1); n     int x = read(), d = read(); n     for (int j = (1), jend = (A); j <= jend; j++) n       if (Dis[p[j]][x] <= f[j] && a[j] >= d) add(j, i + A, 1); n   } n   int ans = 0; n   while (bfs()) { n     memcpy(cur, beg, sizeof(cur)); n     ans += dfs(S, 1e9); n   } n   long long Ans = 1e18; n   for (int i = (0), iend = (A); i <= iend; i++) n     chkmin(Ans, 1ll * k * min(A - i, ans) + 1ll * i * h); n   printf( %lld n , Ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n namespace io { n const int SIZE = (1 << 21) + 1; n char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1; n inline char getc() { n   return (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), n                       (iS == iT ? EOF : *iS++)) n                    : *iS++); n } n inline void flush() { n   fwrite(obuf, 1, oS - obuf, stdout); n   oS = obuf; n } n inline void putc(char x) { n   *oS++ = x; n   if (oS == oT) flush(); n } n template <class T> n inline void read(T &x) { n   char ch; n   int f = 1; n   x = 0; n   while (isspace(ch = getc())) n     ; n   if (ch ==  - ) ch = getc(), f = -1; n   do x = x * 10 + ch -  0 ; n   while (isdigit(ch = getc())); n   x *= f; n } n template <class T, class... Args> n inline void read(T &x, Args &...args) { n   read(x); n   read(args...); n } n template <class T> n inline void write(T x) { n   static char stk[128]; n   int top = 0; n   if (x == 0) { n     putc( 0 ); n     return; n   } n   if (x < 0) putc( - ), x = -x; n   while (x) stk[top++] = x % 10, x /= 10; n   while (top) putc(stk[--top] +  0 ); n } n template <class T, class... Args> n inline void write(T x, Args... args) { n   write(x); n   putc(   ); n   write(args...); n } n inline void space() { putc(   ); } n inline void endl() { putc(  n ); } n struct _flush { n   ~_flush() { flush(); } n } __flush; n };  // namespace io n using io::endl; n using io::flush; n using io::getc; n using io::putc; n using io::read; n using io::space; n using io::write; n const int M = 1000000007; n inline int add(int x, int y) { return x + y >= M ? x + y - M : x + y; } n template <class... Args> n inline int add(int x, int y, Args... args) { n   return add(add(x, y), args...); n } n inline int sub(int x, int y) { return x - y < 0 ? x - y + M : x - y; } n inline int mul(int x, int y) { return 1LL * x * y % M; } n template <class... Args> n inline int mul(int x, int y, Args... args) { n   return mul(mul(x, y), args...); n } n inline void inc(int &x, int y = 1) { n   x += y; n   if (x >= M) x -= M; n } n inline void dec(int &x, int y = 1) { n   x -= y; n   if (x < 0) x += M; n } n inline int power(int x, int y) { n   int res = 1; n   for (; y; y >>= 1, x = mul(x, x)) n     if (y & 1) res = mul(res, x); n   return res; n } n inline int inv(int x) { return power(x, M - 2); } n const int N = 4005; n int _g[N * 2], *g = _g + N; n int n, m; n struct DP { n   int a[N * 2]; n   int *f; n   DP() { n     f = a + N; n     fill(f - m, f + m + 1, 0); n     f[0] = 1; n   } n   void update(int x) { n     fill(g - m, g + m + 1, 0); n     for (int i = -m + x; i <= m - x; ++i) g[i - x] = (g[i - x] + f[i]) % M; n     for (int i = -m + x; i <= m - x; ++i) g[i + x] = (g[i + x] + f[i]) % M; n     for (int i = -m; i <= m; ++i) f[i] = (f[i] + g[i]) % M; n   } n   void select(int x) { n     fill(g - m, g + m + 1, 0); n     for (int i = -m + x; i <= m; ++i) g[i - x] = (g[i - x] + f[i]) % M; n     for (int i = -m; i <= m - x; ++i) g[i + x] = (g[i + x] + f[i]) % M; n     for (int i = -m; i <= m; ++i) f[i] = g[i]; n   } n   void operator=(const DP &r) { n     for (int i = -m; i <= m; ++i) f[i] = r.f[i]; n   } n   int query(int x) { n     int res = 0; n     for (int i = 2 - x; i <= x - 2; ++i) inc(res, f[i]); n     return res; n   } n }; n vector<int> G[N]; n int a[N]; n bool vis[N]; n DP f; n DP stk[20]; n int top = 0; n int dfs(int x, int fa) { n   vis[x] = true; n   for (int v : G[x]) { n     if (v == fa) continue; n     if (v == 1) return 1; n     return dfs(v, x) + 1; n   } n   return 1; n } n int res = 0; n void solve(int l, int r) { n   if (l == r) { n     inc(res, f.query(a[l])); n     return; n   } n   stk[top] = f; n   ++top; n   int mid = (l + r) >> 1; n   for (int i = l; i <= mid; ++i) f.update(a[i]); n   solve(mid + 1, r); n   f = stk[top - 1]; n   for (int i = mid + 1; i <= r; ++i) f.update(a[i]); n   solve(l, mid); n   --top; n } n void solve2(int l, int r) { n   if (l == r) { n     inc(res, add(f.f[a[l]], f.f[a[l] - 1], f.f[1 - a[l]], f.f[-a[l]])); n     inc(res, add(f.f[a[l]], f.f[a[l] - 1], f.f[1 - a[l]], f.f[-a[l]])); n     return; n   } n   stk[top] = f; n   ++top; n   int mid = (l + r) >> 1; n   for (int i = l; i <= mid; ++i) f.select(a[i]); n   solve2(mid + 1, r); n   f = stk[top - 1]; n   for (int i = mid + 1; i <= r; ++i) f.select(a[i]); n   solve2(l, mid); n   --top; n } n int main() { n   read(n, m); n   for (int i = 1; i <= m; ++i) { n     int u, v; n     read(u, v); n     G[u].push_back(v); n     G[v].push_back(u); n   } n   int cnt = 0; n   for (int v : G[1]) { n     if (!vis[v]) a[++cnt] = dfs(v, 1) + 1; n   } n   solve(1, cnt); n   res = mul(res, 2); n   if ((m & 1) == 0) { n     f = DP(); n     for (int i = 1; i <= cnt; ++i) f.select(a[i]); n     inc(res, f.f[0]); n   } else { n     f = DP(); n     solve2(1, cnt); n   } n   write(res), endl(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char sign[1000][1000], cpy[1000][1000]; n int n, m; n void tryFill(int i, int j) { n   for (int ii = i - 1; ii <= i + 1; ii++) { n     for (int jj = j - 1; jj <= j + 1; jj++) { n       if (i == ii && j == jj) { n         continue; n       } n       if (sign[ii][jj] ==  . ) { n         return; n       } n     } n   } n   for (int ii = i - 1; ii <= i + 1; ii++) { n     for (int jj = j - 1; jj <= j + 1; jj++) { n       if (i == ii && j == jj) { n         continue; n       } n       cpy[ii][jj] =  # ; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> sign[i][j]; n       cpy[i][j] =  . ; n     } n   } n   for (int i = 1; i < n - 1; i++) { n     for (int j = 1; j < m - 1; j++) { n       tryFill(i, j); n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (sign[i][j] != cpy[i][j]) { n         cout <<  NO ; n         return 0; n       } n     } n   } n   cout <<  YES ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T, class T2> n inline int chkmax(T &x, const T2 &y) { n   return x < y ? x = y, 1 : 0; n } n template <class T, class T2> n inline int chkmin(T &x, const T2 &y) { n   return x > y ? x = y, 1 : 0; n } n const int MAXN = (1 << 20); n int n; n void read() { cin >> n; } n vector<pair<int, int> > change_list = { n     {0, 0}, {0, 1}, {0, 2}, {1, 0}, {1, 3}, {0, 3}, {1, 2}, {2, 0}, n     {3, 1}, {2, 1}, {1, 1}, {2, 2}, {3, 0}, {3, 3}, {2, 3}, {3, 2}, n }; n void solve() { n   if (n % 4 >= 2) { n     cout <<  NO  <<   n ; n     return; n   } n   cout <<  YES  <<   n ; n   bool odd_flag = n % 2; n   for (int i = 0; i < (n / 4); i++) { n     int a = i * 4 + 1, b = i * 4 + 2, c = i * 4 + 3, d = i * 4 + 4; n     if (odd_flag) cout << a <<     << n <<   n ; n     cout << a <<     << c <<   n ; n     if (odd_flag) cout << c <<     << n <<   n ; n     if (odd_flag) cout << b <<     << n <<   n ; n     cout << b <<     << d <<   n ; n     if (odd_flag) cout << d <<     << n <<   n ; n     cout << a <<     << b <<   n ; n     cout << c <<     << d <<   n ; n     cout << a <<     << d <<   n ; n     cout << b <<     << c <<   n ; n   } n   for (int i = 0; i < (n / 4); i++) n     for (int j = i + 1; j < (n / 4); j++) n       for (auto it : change_list) n         cout << 4 * i + 1 + it.first <<     << 4 * j + 1 + it.second <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   read(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T1, typename T2> n pair<T1, T2> operator+(pair<T1, T2> a, pair<T1, T2> b) { n   return make_pair(a.first + b.first, a.second + b.second); n } n template <typename T1, typename T2> n pair<T1, T2> operator-(pair<T1, T2> a, pair<T1, T2> b) { n   return make_pair(a.first - b.first, a.second - b.second); n } n template <typename T1, typename T2> n ostream& operator<<(ostream& out, pair<T1, T2> p) { n   out << p.first <<     << p.second; n   return out; n } n template <typename T1, typename T2> n istream& operator>>(istream& in, pair<T1, T2>& p) { n   in >> p.first >> p.second; n   return in; n } n template <typename T> n ostream& operator<<(ostream& out, vector<T> v) { n   for (auto a : v) out << a <<    ; n   return out; n } n template <typename T> n istream& operator>>(istream& in, vector<T>& v) { n   for (auto& a : v) in >> a; n   return in; n } n template <typename T> n ostream& operator<<(ostream& out, multiset<T> S) { n   for (auto a : S) out << a <<    ; n   return out; n } n template <typename T> n ostream& operator<<(ostream& out, set<T> S) { n   for (auto a : S) out << a <<    ; n   return out; n } n template <typename T> n set<T> operator+(set<T> A, set<T> B) { n   for (auto b : B) A.insert(b); n   return A; n } n int main() { n   string s, t; n   cin >> s >> t; n   int i = 0; n   for (int j = 0; j < t.size(); j++) { n     if (s[i] == t[j]) i++; n   } n   cout << i + 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n, l, k; n   cin >> n >> l >> k; n   vector<int> cnt(26, 0); n   for (int i = 0; i < n * l; ++i) { n     char c; n     cin >> c; n     cnt[c -  a ]++; n   } n   int last = 0; n   int cur = 0; n   vector<string> ans(n, string(l,  # )); n   for (int i = 0; i < l; ++i) { n     while (!cnt[cur]) cur++; n     while (cnt[cur] < k - last && k - last > 0) { n       for (int j = 0; j < cnt[cur]; ++j) { n         ans[last + j][i] = char( a  + cur); n       } n       last += cnt[cur]; n       cur++; n     } n     for (int j = 0; j < k - last; ++j) { n       ans[j + last][i] = char( a  + cur); n     } n     cnt[cur] -= k - last; n   } n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < l; ++j) { n       if (ans[i][j] ==  # ) { n         cnt[cur]--; n         cout << char( a  + cur); n       } else n         cout << ans[i][j]; n       while (!cnt[cur]) cur++; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   long long int n, i, m, j, f, k; n   cin >> n; n   m = n * n; n   vector<long long int> v[n]; n   for (i = m; i >= n; i -= n) { n     if (f == 0) { n       k = 0; n       for (j = i; j > (i - n); j--, k++) { n         v[k].push_back(j); n       } n     } else { n       k = n - 1; n       for (j = i; j > (i - n); j--, k--) { n         v[k].push_back(j); n       } n     } n     (f == 0) ? f = 1 : f = 0; n   } n   for (i = 0; i < n; i++) { n     for (j = 0; j < n; j++) cout << v[i][j] <<    ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 15e4 + 4; n const int MAXQ = MAXN; n const int MAXK = 6 + 2; n int n, k, q; n int t[MAXN]; n set<int, greater<int> > st; n int main() { n   scanf( %d%d%d , &n, &k, &q); n   for (int i = 0; i < n; ++i) scanf( %d , t + i); n   while (q--) { n     int op, id; n     scanf( %d%d , &op, &id); n     --id; n     if (op == 1) { n       st.insert(t[id]); n     } else { n       if (!st.count(t[id])) { n         puts( NO ); n         continue; n       } n       int cnt = k; n       bool ok = false; n       for (auto it : st) { n         if (it == t[id]) { n           puts( YES ); n           ok = true; n           break; n         } n         --cnt; n         if (ok) break; n         if (cnt == 0) break; n       } n       if (!ok) puts( NO ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( avx,avx2,fma ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n using namespace std; n using pl = pair<long long, long long>; n using vll = vector<long long>; n using mll = map<long long, long long>; n using vpl = vector<pl>; n long long mod = 1000000007; n long long modu(long long a, long long b) { n   long long c = a % b; n   return (c < 0) ? c + b : c; n } n long long ipow(long long a, long long b) { n   long long ans = 1; n   while (b--) { n     ans = ans * a; n   } n   return ans; n } n long long getmx(long long i, long long j, long long i1, long long j1, n                 long long i2, long long j2) { n   long long ans = 0; n   ans += abs(i - i1) + abs(j - j1); n   ans += abs(i1 - i2) + abs(j1 - j2); n   ans += abs(i - i2) + abs(j - j2); n   return ans; n } 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 isleap(long long n) { n   if (n % 400 == 0) return true; n   if (n % 4 == 0 && n % 100 != 0) return true; n   return false; n } n void solve() { n   long long n, dif = 0; n   cin >> n; n   for (long long i = n + 1;; i++) { n     if (isleap(i)) { n       dif += 2; n     } else { n       dif++; n     } n     if (dif % 7 == 0 && (isleap(i) == isleap(n))) { n       cout << i <<   n ; n       return; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, a, b, i, x, t, rem; n   cin >> n >> a >> b; n   for (i = 0; i < n; i++) { n     cin >> x; n     t = (x * a) % b; n     if (t / a >= 1) n       rem = t / a; n     else n       rem = 0; n     cout << rem <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void scanint(long long int &x); n map<long long int, long long int> vv; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   multiset<long long int> ms; n   long long int n; n   scanint(n); n   long long int a[n]; n   long long int curr = 1; n   long long int i = 0; n   for (i = 0; i < n; i++) { n     scanint(a[i]); n     if (!vv[a[i]] && a[i] >= 1 && a[i] <= n) n       vv[a[i]]++; n     else n       ms.insert(a[i]); n   } n   long long int ans = 0; n   multiset<long long int>::iterator itr; n   for (itr = ms.begin(); itr != ms.end(); itr++) { n     while (vv[curr]) curr++; n     ans += abs(*itr - curr); n     vv[curr]++; n   } n   cout << ans << endl; n   return 0; n } n void scanint(long long int &x) { n   register int c = getchar(); n   x = 0; n   int neg = 0; n   for (; ((c < 48 || c > 57) && c !=  - ); c = getchar()) n     ; n   if (c ==  - ) { n     neg = 1; n     c = getchar(); n   } n   for (; c > 47 && c < 58; c = getchar()) { n     x = (x << 1) + (x << 3) + c - 48; n   } n   if (neg) x = -x; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a, mid, ans = 0; n   int all[100001]; n   all[0] = 0; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a; n     all[i] = all[i - 1] + a; n   } n   if (all[n] % 2 == 1) { n     cout << 0; n     return 0; n   } n   mid = all[n] / 2; n   for (int i = 1; i < n; i++) { n     if (all[i] == all[n] - all[i]) ans++; n   } n   cout << ans; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n inline int add(int x, int y) { n   x += y; n   if (x >= mod) x -= mod; n   return x; n } n inline int mul(int x, int y) { return ((long long)x) * y % mod; } n const int N = 1e6 + 5; n int fac[N + 5], ifac[N + 5], p[N + 5]; n int Pow(int a, int b) { n   int x = 1; n   for (; b > 0; b >>= 1) { n     if (b & 1) x = mul(x, a); n     a = mul(a, a); n   } n   return x; n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0); n   int n, m; n   cin >> n >> m; n   fac[0] = ifac[0] = p[0] = 1; n   for (int i = 1; i < N; ++i) { n     fac[i] = mul(fac[i - 1], i); n     ifac[i] = Pow(fac[i], mod - 2); n     p[i] = mul(p[i - 1], m); n   } n   auto comb = [&](int x, int y) { n     return mul(mul(fac[x], ifac[x - y]), ifac[y]); n   }; n   auto f = [&](int x, int y) { n     if (x == y) return 1; n     return mul(y, Pow(x, x - y - 1)); n   }; n   int ans = 0; n   for (int k = 1; k < n; ++k) n     if (m >= k) { n       int g = mul(mul(comb(m - 1, m - k), comb(n - 2, k - 1)), n                   mul(mul(fac[k - 1], p[n - k - 1]), f(n, k + 1))); n       ans = add(ans, g); n     } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[27]; n int main() { n   long long n; n   string s; n   cin >> n; n   cin >> s; n   long long c = 0, i, d; n   for (i = 0; i < (2 * n) - 2; i++) { n     if (s[i] >=  a  && s[i] <=  z ) { n       d = s[i] -  a ; n       a[d]++; n     } else { n       d = s[i] -  A ; n       if (a[d] > 0) { n         a[d]--; n       } else { n         c++; n       } n     } n   } n   cout << c << endl; n } n


n // Problem: A. Dense Array n // Contest: Codeforces - Codeforces Round #702 (Div. 3) n // URL: https://codeforces.com/contest/1490/problem/A n // Memory Limit: 256 MB n // Time Limit: 2000 ms n // Powered by CP Editor (https://github.com/cpeditor/cpeditor) n  n #include <bits/stdc++.h> n #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n #define ll          long long n #define pb          push_back n #define eb    emplace_back n #define mp    make_pair n #define pii         pair<ll,ll> n #define vi          vector<int> n #define vii         vector<pii> n #define mi          map<ll,ll> n #define mii         map<pii,ll> n #define all(a)      (a).begin(),(a).end() n #define fi          first n #define si          second n #define sz(x)       (ll)x.size() n #define endl          n  n #define checkbit(n, b) ((n >> b) & 1) n #define mod        1000000007 n #define inf        1000000000000000000 n #define puts(n)  cout<<n; n #define um           unordered_map<ll,ll> n #define rep(i,a,b)  for(int i=a;i<b;i++) n #define setbits(x) __builtin_popcount(x) n #define mset(m,v) memset(m,v,sizeof(m)) n #define int ll  n #define deb(x) cout << #x <<  =  << x << endl n #define deb2(x, y) cout << #x <<  =  << x <<  ,  << #y <<  =  << y << endl n using namespace std; n int power(int base, int exp);  n   n //======================= n   n  // USED UNORDERED_MAP???????? n  // INT_MAX and LONG_MAX range??? n  //gcd(x,y)=gcd(x-y,y) n  //gcd(x,y,z...)=gcd(x,y-x,z-x,...) n void solve() { n  int n; n  cin>>n; n  vi arr(n,0); n  rep(i,0,n) n  { n   cin>>arr[i]; n  } n  int cnt=0; n  rep(i,0,n-1) n  { n   int x=max(arr[i],arr[i+1]); n   int y=min(arr[i],arr[i+1]); n   while(y*2<x) n   { n    x=(x+1)/2; n    cnt++; n   } n  } n  cout<<cnt<<endl; n } n   n int32_t main() { n     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n     srand(chrono::high_resolution_clock::now().time_since_epoch().count()); n   n    int t = 1; n     cin >> t; n     while(t--) { n       solve(); n     } n   n     return 0; n } n   n int power(int base, int exp) { n   base %= mod; n   int result = 1; n   while (exp > 0) { n     if (exp & 1) result = ((ll)result * base) % mod; n     base = ((ll)base * base) % mod; n     exp >>= 1; n   } n   return result; n }


#include <bits/stdc++.h> n using namespace std; n string s; n struct SUM { n   int n; n   bool pp; n } b; n vector<SUM> a; n bool cmp(SUM u, SUM v) { return u.n < v.n; } n int main() { n   std::ios::sync_with_stdio(false); n   int i, j, k, m; n   cin >> m >> s; n   s = s[0] ==  -  ? s :  +  + s; n   for (i = 0; i < s.size();) { n     j = i + 1; n     if (s[i + 1] <  0  || s[i + 1] >  9 ) n       k = 1; n     else { n       for (k = 0; s[j] >=  0  && s[j] <=  9 ; ++j) k = k * 10 + s[j] -  0 ; n       ++j; n     } n     if (s[i] ==  - ) k = -k; n     b.n = k; n     b.pp = s[j] !=  a ; n     a.push_back(b); n     i = j + 3; n   } n   sort(a.begin(), a.end(), cmp); n   for (k = 0, i = 0; i < a.size(); ++i) { n     if (a[i].pp) n       k += a[i].n * ++m; n     else n       k += a[i].n * m++; n   } n   cout << k << endl; n   return 0; n } n


#include <iostream> n #include <bits/stdc++.h> n using namespace std; n  n int main() n { n     int t; cin >> t; n     while (t--){ n         //int n; cin >> n; n         string s; cin >> s; n         string res =   ; n         for (int i=0;i<s.size();i++){ n             if (i%2==0){ n                 if (s[i]== a ){ n                     res +=  b ; n                 } else { n                     res +=  a ; n                 } n             } else { n                 if (s[i]== z ){ n                     res +=  y ; n                 } else { n                     res +=  z ; n                 } n             } n  n  n         } n         cout << res << endl; n  n  n  n  n     } n } n


#include <bits/stdc++.h> n using namespace std; n const long long LIM = 1e5; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cout.precision(10); n   cout << fixed; n   long long n, r; n   cin >> n >> r; n   vector<long long> L(n); n   vector<long long> T(n); n   for (long long i = 0; i < n; i++) cin >> L[i]; n   for (long long i = 0; i < n; i++) cin >> T[i]; n   long long cnt = 0; n   vector<long long> ans; n   long long curTime = 0; n   long long timePotion = 0; n   for (long long i = 0; i < n; i++) { n     long long l = L[i]; n     long long t = T[i]; n     if (timePotion < l) { n       t -= timePotion; n       l -= timePotion; n       curTime += timePotion; n       if (t < 0) { n         cout << -1 <<   n ; n         return 0; n       } n       if (2 * l > t) { n         long long szz = ans.size(); n         long long timeNeedPotion = 2 * l - t; n         if (t - timeNeedPotion < 0) { n           cout << -1 <<   n ; n           return 0; n         } n         long long cntMoments = (timeNeedPotion / r) + (timeNeedPotion % r != 0); n         curTime = curTime + t - timeNeedPotion; n         cnt += cntMoments; n         for (long long i = 0; i < cntMoments; i++) { n           if (ans.size() < LIM) { n             ans.push_back(curTime + i * r); n           } else { n             break; n           } n         } n         curTime += timeNeedPotion; n         timePotion = r - (timeNeedPotion % r); n         if (timePotion == r) timePotion -= r; n       } else { n         curTime += l * 2; n         timePotion = 0; n       } n     } else { n       if (l > t) { n         cout << -1 <<   n ; n         return 0; n       } else { n         timePotion -= l; n         curTime += l; n       } n     } n   } n   cout << cnt <<   n ; n   if (cnt <= LIM) { n     for (long long xx : ans) cout << xx <<    ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long Length, X, Y; n long long Dp[10000001]; n int main(void) { n   register long long i; n   cin >> Length >> X >> Y; n   Dp[1] = X; n   for (i = 2; i <= Length; i++) { n     Dp[i] = Dp[i - 1] + X; n     if (i & 1) { n       Dp[i] = min(Dp[i], Dp[(i >> 1) + 1] + X + Y); n     } else { n       Dp[i] = min(Dp[i], Dp[i >> 1] + Y); n     } n   } n   cout << Dp[Length] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   int i1, i2, a1, a2; n   cout <<  ?  ; n   for (int i = 1; i <= k; ++i) cout << i <<    ; n   cout <<   n ; n   cout.flush(); n   cin >> i1 >> a1; n   cout <<  ?  ; n   for (int i = 1; i <= k + 1; ++i) { n     if (i == i1) ++i; n     cout << i <<    ; n   } n   cout <<   n ; n   cout.flush(); n   cin >> i2 >> a2; n   if (a1 < a2) { n     swap(i1, i2); n     swap(a1, a2); n   } n   int count = 0, c1 = 0, c2; n   for (int ch = 1; ch <= k + 10; ++ch) { n     if (ch == i1 || ch == i2) ++ch; n     if (ch == i1 || ch == i2) ++ch; n     ++c1; n     if (c1 > k - 1) break; n     cout <<  ?  ; n     c2 = 0; n     for (int i = 1; i <= k + 10; ++i) { n       ++c2; n       if (c2 > k) break; n       if (i == i2) ++i; n       if (i == ch) n         cout << i2 <<    ; n       else n         cout << i <<    ; n     } n     cout <<   n ; n     cout.flush(); n     int ich, ach; n     cin >> ich >> ach; n     if (ich == i1) ++count; n   } n   cout <<  !   << count + 1; n   cout.flush(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[110]; n map<int, bool> mp[3]; n bool Check(int x) { n   if (x < 10) { n     if (mp[0][x] || mp[1][x] || mp[2][x]) return true; n   } else if (x < 100) { n     int a = x / 10, b = x % 10; n     if (mp[0][a] && mp[1][b]) return true; n     if (mp[0][a] && mp[2][b]) return true; n     if ((mp[1][a] && mp[2][b]) || (mp[1][a] && mp[0][b])) return true; n     if ((mp[2][a] && mp[0][b]) || (mp[2][a] && mp[1][b])) return true; n   } n   return false; n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     for (int x, j = 0; j < 6; ++j) { n       scanf( %d , &x); n       mp[i][x] = true; n     } n   } n   int i; n   for (i = 1; i < 1000; ++i) { n     if (!Check(i)) break; n   } n   printf( %d n , i - 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   int a, b; n   int s[4010]; n   cin >> n; n   memset(s, 0, sizeof(s)); n   for (int i = 0; i < n; i++) { n     cin >> a >> b; n     s[a + b]++; n     s[a - b + 3000]++; n   } n   long long sum = 0; n   for (int i = 0; i <= 4000; i++) { n     if (s[i] > 1) sum += (s[i] * (s[i] - 1) / 2); n   } n   cout << sum << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long x, y, z; n   cin >> x >> y >> z; n   long long xx = x, yy = y; n   long long g1 = x % z, p1; n   if ((y + g1) / z > y / z) { n     y += g1; n     if (g1 - (y) % z > 0) g1 -= (y) % z; n   } else n     g1 = 0; n   p1 = (x / z) + (y / z); n   long long g2 = yy % z, p2; n   if ((xx + g2) / z > xx / z) { n     xx += g2; n     if (g2 - (xx) % z > 0) g2 -= (xx) % z; n   } else n     g2 = 0; n   p2 = (xx / z) + (yy / z); n   if (p1 > p2) n     cout << p1 <<     << g1; n   else if (p2 > p1) n     cout << p2 <<     << g2; n   else { n     cout << p1 <<    ; n     if (g1 < g2) n       cout << g1; n     else n       cout << g2; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long M = 1e6 + 5; n const long long mod = 1e9 + 7; n void solve() { n   long long n; n   cin >> n; n   long long a = n / 10; n   long long b = n % 10; n   long long ans = a + (b == 9); n   cout << ans; n } n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long T = 1; n   cin >> T; n   while (T-- > 0) { n     solve(); n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename TP> n inline bool rd(TP& r) { n   r = 0; n   char tmp = getchar(); n   while (tmp <  0  || tmp >  9 ) { n     if (tmp == EOF) return 0; n     tmp = getchar(); n   } n   while ( 0  <= tmp && tmp <=  9 ) { n     r = (r << 3) + (r << 1) + tmp -  0 ; n     tmp = getchar(); n   } n   return 1; n } n long long a[110], b[110], n; n long long dt[110 * 110]; n bool vis[1000100]; n long long ab(long long num) { n   if (num >= 0) return num; n   return -num; n } n int main() { n   int t; n   rd(t); n   int tot; n   int nb; n   while (t--) { n     rd(n); n     for (int i = 1; i <= n; i++) rd(a[i]); n     tot = 0; n     for (int i = 1; i <= n; i++) n       for (int j = 1; j < i; j++) dt[++tot] = ab(a[i] - a[j]); n     sort(dt + 1, dt + tot + 1); n     tot = unique(dt + 1, dt + tot + 1) - (dt + 1); n     memset(vis, 0, sizeof(vis)); n     nb = 0; n     for (int i = 1; i <= 1000000 && nb != n; i++) n       if (!vis[i]) { n         b[++nb] = i; n         for (int j = 1; j <= tot && i + dt[j] < 1000100; j++) n           vis[i + dt[j]] = 1; n       } n     if (nb != n) n       printf( NO n ); n     else { n       printf( YES n ); n       for (int i = 1; i <= n; i++) printf( %I64d  , b[i]); n       printf(  n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma warning(disable : 4996) n #pragma comment(linker,  /STACK:336777216 ) n using namespace std; n int IT_MAX = 1 << 17; n const long long MOD = 1000000007; n const int INF = 0x1f3f3f3f; n const long long LL_INF = 1034567890123456789ll; n const double PI = acos(-1); n const double ERR = 1E-11; n multiset<int> Sx; n int in[100050]; n int main() { n   int N, K, i, j; n   scanf( %d %d , &N, &K); n   for (i = 1; i <= N; i++) scanf( %d , &in[i]); n   int ans = -1; n   vector<int> Va; n   for (i = 1, j = 1; i <= N; i++) { n     while (j <= N) { n       if (Sx.empty()) { n         Sx.insert(in[j++]); n         continue; n       } n       auto it1 = Sx.begin(); n       auto it2 = Sx.end(); n       it2--; n       if (abs(in[j] - *it1) > K || abs(in[j] - *it2) > K) break; n       Sx.insert(in[j++]); n     } n     if (ans < j - i) { n       ans = j - i; n       Va.clear(); n     } n     if (ans == j - i) Va.push_back(i); n     Sx.erase(Sx.lower_bound(in[i])); n   } n   printf( %d %d n , ans, (int)Va.size()); n   for (auto it : Va) printf( %d %d n , it, it + ans - 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct info { n   int l, r, need, onemore, take; n }; n vector<string> solve(vector<int> a, int n) { n   vector<string> ans(n + 1, string(n,  0 )); n   vector<info> state = {{0, n, (n + 1) / 2, ((n + 1) & 1), 0}}; n   int pos = 0; n   for (auto i : a) { n     for (auto &j : state) n       while (j.need && i) { n         --i; n         --j.need; n         ++j.take; n       } n     for (auto &j : state) n       if (j.onemore && i) { n         --i; n         --j.onemore; n         ++j.take; n       } n     int j = 0; n     while (i > 0) { n       if (state[j].take != state[j].r - state[j].l + 1) { n         --i; n         ++state[j].take; n       } n       j = (j + 1) % state.size(); n     } n     vector<info> nstate; n     for (auto &k : state) { n       for (int p = k.l; p < k.l + k.take; ++p) ans[p][pos] =  1 ; n       if (k.take) nstate.push_back({k.l, k.l + k.take - 1, 0, 0, 0}); n       if (k.take < k.r - k.l + 1) n         nstate.push_back({k.l + k.take, k.r, 0, 0, 0}); n     } n     state = nstate; n     for (auto &k : state) { n       k.need = (k.r - k.l + 1) / 2; n       k.onemore = (k.r - k.l + 1) & 1; n       k.take = 0; n     } n     ++pos; n   } n   sort(ans.begin(), ans.end()); n   reverse(ans.begin(), ans.end()); n   while (!ans.empty() && ans.back() == string(n,  0 )) ans.pop_back(); n   return ans; n } n void validate(vector<int> a, int n, vector<string> ans) { n   for (auto &j : ans) n     for (int i = 0; i < n; ++i) n       if (j[i] ==  1 ) --a[i]; n   assert(count(a.begin(), a.end(), 0) == n); n   for (int i = 1; i < ans.size(); ++i) assert(ans[i - 1] != ans[i]); n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0); n   int n; n   cin >> n; n   vector<int> a(n); n   for (auto &i : a) cin >> i; n   auto ans = solve(a, n); n   validate(a, n, ans); n   cout << ans.size() <<   n ; n   for (auto i : ans) cout << i <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int cnt[ T  + 1]; n string p =  AGTC ; n int main() { n   int n; n   cin >> n; n   string s; n   cin >> s; n   for (int i = 0, __l = s.size(); i < __l; ++i) cnt[s[i]]++; n   int maxi = 0; n   for (int i = 0, __l = p.size(); i < __l; ++i) maxi = max(maxi, cnt[p[i]]); n   int x = 0; n   for (int i = 0, __l = p.size(); i < __l; ++i) x += cnt[p[i]] == maxi; n   long long ans = 1; n   for (int i = 0, __l = n; i < __l; ++i) (ans *= x) %= 1000000007; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double ESP = 1E-8; n long double cal(long double x, long double y, long double z) { n   return log(x) * pow(y, z); n } n long double ca(long double x, long double y, long double z) { n   return y * z * log(x); n } n int main() { n   const char* result[12] = { x^y^z ,  x^z^y ,  (x^y)^z ,  (x^z)^y , n                              y^x^z ,  y^z^x ,  (y^x)^z ,  (y^z)^x , n                              z^x^y ,  z^y^x ,  (z^x)^y ,  (z^y)^x }; n   long double a[20]; n   long double x, y, z; n   cin >> x >> y >> z; n   a[0] = cal(x, y, z); n   a[1] = cal(x, z, y); n   a[2] = ca(x, y, z); n   a[3] = ca(x, z, y); n   a[4] = cal(y, x, z); n   a[5] = cal(y, z, x); n   a[6] = ca(y, x, z); n   a[7] = ca(y, z, x); n   a[8] = cal(z, x, y); n   a[9] = cal(z, y, x); n   a[10] = ca(z, x, y); n   a[11] = ca(z, y, x); n   long double maxn = a[0]; n   int res = 0; n   for (int i = 1; i < 12; ++i) { n     if (maxn < a[i] - ESP) { n       maxn = a[i]; n       res = i; n     } n   } n   printf( %s , result[res]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const ll MOD = (int)1e9 + 7; n ll modAdd(ll a, ll b) { n   if (a + b >= MOD) n     return a + b - MOD; n   else n     return a + b; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n, m; n   cin >> n >> m; n   vector<int> sweetness(n); n   for (int& v : sweetness) cin >> v; n   vector<vector<pair<int, int>>> offs(n); n   for (int i = 0; i < m; ++i) { n     int s, h; n     cin >> s >> h; n     int a = 0; n     for (int need = h; a < n; ++a) { n       if (sweetness[a] == s) --need; n       if (need == 0) break; n     } n     int b = n - 1; n     for (int need = h; b >= 0; --b) { n       if (sweetness[b] == s) --need; n       if (need == 0) break; n     } n     offs[s - 1].push_back({a, b}); n   } n   vector<pair<int, ll>> res; n   for (int a = -1; a < n; ++a) { n     int cou = 0; n     ll v0 = (a != -1); n     ll v1 = (a == -1); n     for (auto& vec : offs) { n       ll dp[2][2][2]; n       for (int i = 0; i < 2; ++i) { n         for (int j = 0; j < 2; ++j) { n           for (int t = 0; t < 2; ++t) { n             dp[i][j][t] = 0; n           } n         } n       } n       dp[0][0][0] = v0; n       dp[0][0][1] = v1; n       for (auto pr : vec) { n         int le = (pr.first <= a) + (pr.first == a); n         int ri = (pr.second >= a + 1); n         for (int i = 1; i >= 0; --i) { n           for (int j = 1; j >= 0; --j) { n             for (int t = 1; t >= 0; --t) { n               if (le && i) { n                 if (le == 2 && t == 1) { n                   dp[i][j][t] = n                       modAdd(dp[i][j][t], modAdd(dp[0][j][0], dp[0][j][1])); n                 } else if (le == 1) { n                   dp[i][j][t] = modAdd(dp[i][j][t], dp[0][j][t]); n                 } n               } n               if (ri && j) { n                 dp[i][j][t] = modAdd(dp[i][j][t], dp[i][0][t]); n               } n             } n           } n         } n       } n       if (dp[1][1][0] || dp[1][1][1]) { n         cou += 2; n         v0 = dp[1][1][0]; n         v1 = dp[1][1][1]; n       } else if (dp[1][0][0] || dp[1][0][1] || dp[0][1][0] || dp[0][1][1]) { n         ++cou; n         v0 = modAdd(dp[1][0][0], dp[0][1][0]); n         v1 = modAdd(dp[1][0][1], dp[0][1][1]); n       } n     } n     res.push_back({cou, v1}); n   } n   sort(res.begin(), res.end()); n   ll ans = 0; n   int mc = res.back().first; n   while (!res.empty() && res.back().first == mc) { n     ans = modAdd(ans, res.back().second); n     res.pop_back(); n   } n   cout << mc <<     << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int N = 21; n long long int tot[N]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long int n; n   cin >> n; n   long long int i, j, a[n], b, c, ans = 0; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n     for (j = 0; j < N; j++) { n       if (a[i] & (1LL << j)) { n         tot[j]++; n       } n     } n   } n   for (i = 0; i < n; i++) { n     long long int cur = 0; n     for (j = 0; j < N; j++) { n       if (tot[j]) { n         cur += (1LL << j); n         tot[j]--; n       } n     } n     ans += (cur * cur); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool test_cases_exist = false; n void solve() { n   long long int i, j, n, m, k, x, y, ans; n   cin >> n; n   vector<long long int> v(n); n   for (auto &z : v) cin >> z; n   long long int bit = 23; n   long long int oneall = (1 << 23) - 1; n   vector<long long int> dp((1 << 23), -1); n   for (auto z : v) dp[z] = z; n   for (i = 0; i < (1 << bit); i++) { n     for (j = 0; j < bit; j++) { n       if (dp[i] != -1) break; n       if (i >> j & 1) dp[i] = dp[i ^ 1 << j]; n     } n   } n   for (auto z : v) cout << dp[oneall ^ z] <<    ; n   cout <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int t = 1; n   if (test_cases_exist) cin >> t; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, m; n   cin >> n >> m; n   long long a = 1; n   long long b = 1; n   long long c = 1000000007; n   for (int i = 0; i < n; i++) { n     b = b * (2 * m - 1); n     b = b + a; n     b = b % c; n     a = a * m; n     a = a % c; n   } n   cout << b; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dfn[2100], low[2100], tim, dis[2100], n, i, x, y, M, be[2100], m, j, ans, n     du[2100]; n vector<int> E[2100], e[2100], q; n void tarjan(int x, int ff) { n   dfn[x] = low[x] = ++tim; n   q.push_back(x); n   for (int i = 0; i < e[x].size(); ++i) n     if (e[x][i] != ff) { n       if (!dfn[e[x][i]]) { n         tarjan(e[x][i], x); n         low[x] = min(low[x], low[e[x][i]]); n       } else n         low[x] = min(low[x], dfn[e[x][i]]); n     } n   if (low[x] == dfn[x]) { n     ++M; n     for (;;) { n       int t = q.back(); n       q.pop_back(); n       be[t] = M; n       if (t == x) break; n     } n   } n } n void dfs(int p, int ff, int dis) { n   dfn[p] = 1; n   if (dis > y) y = dis, x = p; n   for (int i = 0; i < E[p].size(); ++i) n     if (E[p][i] != ff) dfs(E[p][i], p, dis + 1); n } n int main() { n   scanf( %d%d , &n, &m); n   for (i = 1; i <= m; ++i) { n     scanf( %d%d , &x, &y); n     e[x].push_back(y); n     e[y].push_back(x); n   } n   for (i = 1; i <= n; ++i) n     if (!dfn[i]) tarjan(i, 0); n   for (i = 1; i <= n; ++i) n     for (j = 0; j < e[i].size(); ++j) n       if (be[i] != be[e[i][j]]) E[be[i]].push_back(be[e[i][j]]), du[be[i]]++; n   memset(dfn, 0, sizeof(dfn)); n   for (i = 1; i <= M; ++i) { n     if (!dfn[i]) { n       y = 0; n       dfs(i, 0, 1); n       y = 0; n       dfs(x, 0, 1); n       if (y == 1) n         ans--; n       else n         ans += y - 2 - 1; n     } n     if (du[i] <= 1) ans++; n   } n   printf( %d n , n - ans - 1); n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100005; n const int INF = 1e9; n struct dot { n   int l, r; n }; n typedef int node; n const int neutro = 0; n struct RMQ { n   int sz; n   node t[4 * MAXN]; n   node &operator[](int p) { return t[sz + p]; } n   void init(int n) { n     sz = 1 << (32 - __builtin_clz(n)); n     for (int i = (0); i < (int)(2 * sz); i++) t[i] = neutro; n   } n   void updall() { n     for (int i = sz - 1; i >= 0; i--) { n       t[i] = (t[2 * i] ^ t[2 * i + 1]); n     } n   } n   node get(int i, int j) { return get(i, j, 1, 0, sz); } n   node get(int i, int j, int n, int a, int b) { n     if (j <= a || i >= b) return neutro; n     if (i <= a && b <= j) return t[n]; n     int c = (a + b) / 2; n     return (get(i, j, 2 * n, a, c) ^ get(i, j, 2 * n + 1, c, b)); n   } n   void set(int p, node val) { n     for (p += sz; p > 0 && t[p] != val;) { n       t[p] = val; n       p /= 2; n       val = (t[p * 2] ^ t[p * 2 + 1]); n     } n   } n } rmq; n int n, grundy[MAXN], ans[MAXN]; n vector<dot> events[MAXN]; n int main() { n   rmq.init(MAXN); n   rmq.updall(); n   for (int i = (1); i < (int)(MAXN); i++) { n     int s = i; n     for (int j = i; s < MAXN; j++, s += j) { n       if (j == i) continue; n       events[s].push_back({i, j}); n     } n   } n   grundy[1] = grundy[2] = 0; n   rmq.set(1, 0); n   rmq.set(2, 0); n   for (int i = (3); i < (int)(MAXN); i++) { n     ans[i] = INF; n     long long bm = 0; n     for (auto ev : events[i]) { n       long long v = rmq.get(ev.l, ev.r + 1); n       if (v < 0) { n         printf( %d %d %d : %d %d n , i, ev.l, ev.r, grundy[ev.l], grundy[ev.r]); n         exit(-1); n       } n       bm |= (1ll << v); n       if (v == 0) { n         if (ev.r - ev.l + 1 < ans[i]) { n           ans[i] = ev.r - ev.l + 1; n         } n       } n     } n     for (long long j = 0; j < 60; j++) { n       if ((bm & (1ll << j)) == 0) { n         grundy[i] = j; n         break; n       } n     } n     rmq.set(i, grundy[i]); n   } n   while (scanf( %d , &n) == 1) { n     printf( %d n , grundy[n] == 0 ? -1 : ans[n]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100005; n int n, v[N], id[N], now[N], p[N]; n bool is_lucky(int x) { n   while (x) { n     if (x % 10 != 7 && x % 10 != 4) return false; n     x /= 10; n   } n   return true; n } n void change(int pos1, int pos2) { n   swap(now[p[pos1]], now[p[pos2]]); n   swap(p[pos1], p[pos2]); n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %d , v + i), p[i] = id[i] = now[i] = i; n   if (is_sorted(v, v + n)) return printf( 0 n ), 0; n   sort(id, id + n, [](int a, int b) { return v[a] < v[b]; }); n   int c = -1; n   for (int i = 0; i < n; i++) n     if (is_lucky(v[i])) { n       c = i; n       break; n     } n   if (c == -1) return printf( -1 n ), 0; n   vector<pair<int, int>> ans; n   for (int i = 0; i < n; i++) { n     if (is_lucky(v[i])) { n       c = i; n       break; n     } n   } n   for (int i = 0; i < n; i++) n     if (p[i] != id[i]) { n       if (now[c] != i) { n         ans.emplace_back(now[c], i); n         change(now[c], i); n       } n       if (now[c] != now[id[i]]) { n         ans.emplace_back(now[c], now[id[i]]); n         change(now[c], now[id[i]]); n       } n     } n   printf( %d n , (int)ans.size()); n   for (auto x : ans) printf( %d %d n , x.first + 1, x.second + 1); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int a, b; n     cin >> a >> b; n     if (a == b) { n       cout << 0 <<   n ; n       continue; n     } n     if (a - b > 5) { n       int answ = 0; n       int cant = (a - b) / 5; n       answ = answ + cant; n       a = a - cant * 5; n       if (a - b == 1 or a - b == 2) n         answ = answ + 1; n       else { n         if (a != b) answ = answ + 2; n       } n       cout << answ <<   n ; n       continue; n     } n     if (b - a > 5) { n       int answ = 0; n       int cant = (b - a) / 5; n       a = a + cant * 5; n       answ = answ + cant; n       if (b - a == 1 or b - a == 2) n         answ = answ + 1; n       else { n         if (a != b) answ = answ + 2; n       } n       cout << answ <<   n ; n       continue; n     } n     if (abs(a - b) == 1 or abs(a - b) == 2 or abs(a - b) == 5) n       cout << 1 <<   n ; n     else n       cout << 2 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, m; n   cin >> n >> m; n   char a[n + 2][m + 2]; n   int flag = 0; n   for (long long int i = 0; i <= n + 1; i++) { n     for (long long int j = 0; j <= m + 1; j++) { n       a[i][j] =  . ; n     } n   } n   for (long long int i = 1; i <= n; i++) n     for (long long int j = 1; j <= m; j++) cin >> a[i][j]; n   for (long long int i = 1; i <= n; i++) { n     for (long long int j = 1; j <= m; j++) { n       if (a[i][j] ==  S ) { n         if (a[i - 1][j] ==  W  || a[i + 1][j] ==  W  || a[i][j - 1] ==  W  || n             a[i][j + 1] ==  W ) { n           flag = 1; n           break; n         } n       } n       if (a[i][j] ==  W ) { n         if (a[i - 1][j] ==  .  || a[i - 1][j] ==  D ) a[i - 1][j] =  D ; n         if (a[i + 1][j] ==  .  || a[i + 1][j] ==  D ) a[i + 1][j] =  D ; n         if (a[i][j - 1] ==  .  || a[i][j - 1] ==  D ) a[i][j - 1] =  D ; n         if (a[i][j + 1] ==  .  || a[i][j + 1] ==  D ) a[i][j + 1] =  D ; n       } n     } n     if (flag == 1) break; n   } n   if (flag == 1) n     cout <<  No  n          <<   n ; n   else { n     cout <<  Yes  n          <<   n ; n     for (long long int i = 1; i <= n; i++) { n       for (long long int j = 1; j <= m; j++) { n         cout << a[i][j]; n       } n       cout <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 6; n const int maxlog = 20; n const long long inf = 1e18; n const int mod = 1e9 + 7; n const long long base = 307; n map<long long, int> cnt1, cnt2; n set<int> st; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   int need = (n + 1) / 2; n   for (int i = 0; i < n; i++) { n     int x, y; n     cin >> x >> y; n     cnt1[x]++; n     if (y != x) cnt2[y]++; n     st.insert(x); n     st.insert(y); n   } n   int ans = mod; n   for (set<int>::iterator it = st.begin(); it != st.end(); it++) { n     int x = *it; n     int kol = cnt1[x] + cnt2[x]; n     if (kol < need) continue; n     int new_need = need - cnt1[x]; n     ans = min(ans, new_need); n   } n   if (ans == mod) n     cout << -1; n   else n     cout << max(0, ans); 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   cout.tie(0); n   long long int n, i, c = 0; n   cin >> n; n   long long int a[n]; n   for (i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   for (i = 0; i < n; i++) { n     if (a[i] == a[i + 1]) { n       c++; n       i++; n     } n   } n   cout << c / 2; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool prime(int x) { n   if (x == 1) n     return false; n   else if (x == 2) n     return true; n   for (int i = 2; i * i <= x; i++) { n     if (x % i == 0) return false; n   } n   return true; n } n void fun2(int t) { n   if (t == 1) { n     cout <<  * ; n     return; n   } n   cout <<  * ; n   return fun2(t - 1); n } n void fun(int s) { n   map<int, int> asd; n   map<int, int>::iterator ir; n   ir = asd.begin(); n   ir->first; n   if (s) { n     cout << s % 10 << endl; n     fun(s / 10); n   } n } n long long numb(long long i) { n   if (i == 2 || i == 1) n     return 1; n   else { n     long long n = i, z = 0; n     while (n > 1) { n       if (i % n == 0) { n         z++; n       } n       n--; n     } n     return z; n   } n } n int main() { n   std::ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   int r1, r2, c1, c2, d1, d2; n   cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; n   vector<vector<int>> v(2, vector<int>(2)); n   v[0][0] = (r1 - c2 + d1) / 2; n   v[0][1] = r1 - v[0][0]; n   v[1][0] = c1 - v[0][0]; n   v[1][1] = d1 - v[0][0]; n   bool b = true; n   for (int i = 0; i < 2; i++) { n     for (int j = 0; j < 2; j++) { n       for (int h = 0; h < 2; h++) { n         for (int g = 0; g < 2; g++) { n           if (i == h && j == g) continue; n           if (v[i][j] == v[h][g]) { n             b = false; n           } n         } n       } n     } n   } n   for (int i = 0; i < 2; i++) { n     for (int j = 0; j < 2; j++) { n       if (v[i][j] == 0 || v[i][j] > 9) b = false; n     } n   } n   if (r1 != v[0][0] + v[0][1] || r2 != v[1][0] + v[1][1] || n       c1 != v[0][0] + v[1][0] || c2 != v[0][1] + v[1][1] || n       d1 != v[0][0] + v[1][1] || d2 != v[0][1] + v[1][0]) n     b = false; n   if (b) { n     for (int i = 0; i < 2; i++) { n       for (int j = 0; j < 2; j++) { n         cout << v[i][j] <<    ; n       } n       cout << endl; n     } n   } else { n     cout << -1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<string> s(3e5 + 1); n vector<pair<int, int>> p; n int n; n vector<pair<int, int>> q; n int Kr(int kb, int kn) { n   int ans = 0; n   for (int i = 0; i < n; i++) { n     int r1 = q[i].first - kb; n     int r2 = q[i].second - kn; n     int r; n     if (r1 * r2 >= 0) n       r = max(abs(r1), abs(r2)); n     else n       r = abs(r1) + abs(r2); n     ans = max(ans, r); n   } n   return ans; n } n pair<int, int> F(int kb) { n   int Fl = 0, Fr = 5e5; n   if (!kb) Fl++; n   while (Fr - Fl > 2) { n     int m1 = Fl + (Fr - Fl) / 3; n     int m2 = Fr - (Fr - Fl) / 3; n     if (Kr(kb, m1) >= Kr(kb, m2)) n       Fl = m1; n     else n       Fr = m2; n   } n   return min(make_pair(Kr(kb, Fl), Fl), min(make_pair(Kr(kb, Fl + 1), Fl + 1), n                                             make_pair(Kr(kb, Fl + 2), Fl + 2))); n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> s[i]; n   } n   q.resize(n); n   for (int i = 0; i < n; i++) { n     int kb = 0; n     for (int j = 0; j < s[i].size(); j++) { n       if (s[i][j] ==  B ) ++kb; n     } n     q[i] = {kb, s[i].size() - kb}; n   } n   int l = 0, r = 5e5; n   while (r - l > 2) { n     int m1 = l + (r - l) / 3; n     int m2 = r - (r - l) / 3; n     if (F(m1) >= F(m2)) n       l = m1; n     else n       r = m2; n   } n   auto l0 = F(l); n   auto l1 = F(l + 1); n   auto l2 = F(l + 2); n   if (l0 <= l1 && l0 <= l2) { n     cout << l0.first <<   n ; n     for (int i = 0; i < l; i++) { n       cout <<  B ; n     } n     for (int i = 0; i < l0.second; i++) { n       cout <<  N ; n     } n   } else if (l1 <= l0 && l1 <= l2) { n     cout << l1.first <<   n ; n     for (int i = 0; i < l + 1; i++) { n       cout <<  B ; n     } n     for (int i = 0; i < l1.second; i++) { n       cout <<  N ; n     } n   } else { n     cout << l2.first <<   n ; n     for (int i = 0; i < l + 2; i++) { n       cout <<  B ; n     } n     for (int i = 0; i < l2.second; i++) { n       cout <<  N ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, char** argv) { n   long long n; n   cin >> n; n   long long sum = n * (n + 1) / 2; n   if (sum % 2 == 1) n     cout << 1; n   else n     cout << 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n using namespace std::chrono; n template <class e, class t, int N> n std::basic_istream<e, t>& operator>>(std::basic_istream<e, t>& in, n                                      const e (&literal)[N]) { n   std::array<e, N - 1> buffer; n   in >> buffer[0]; n   if (N > 2) in.read(&buffer[1], N - 2); n   if (strncmp(&buffer[0], literal, N - 1)) n     in.setstate(in.rdstate() | std::ios::badbit); n   return in; n } n template <class e, class t> n std::basic_istream<e, t>& operator>>(std::basic_istream<e, t>& in, n                                      const e& literal) { n   e buffer; n   in >> buffer; n   if (buffer != literal) in.setstate(in.rdstate() | std::ios::badbit); n   return in; n } n template <class e, class t, int N> n std::basic_istream<e, t>& operator>>(std::basic_istream<e, t>& in, n                                      e (&carray)[N]) { n   return std::operator>>(in, carray); n } n template <class t1, class t2> n istream& operator>>(istream& in, pair<t1, t2>& p) { n   in >> p.first >> p.second; n   return in; n } n template <class t> n istream& operator>>(istream& in, vector<t>& v) { n   for (int i = 0; i < v.size(); i++) { n     in >> v[i]; n   } n   return in; n } n template <class t> n ostream& operator<<(ostream& out, vector<t>& a) { n   for (auto x : a) { n     out << x <<    ; n   } n   return out; n } n template <class t1, class t2> n ostream& operator<<(ostream& out, map<t1, t2>& a) { n   for (auto x : a) { n     out << x <<    ; n   } n   return out; n } n template <class t> n ostream& operator<<(ostream& out, set<t>& a) { n   for (auto x : a) { n     out << x <<    ; n   } n   return out; n } n template <class t1, class t2> n ostream& operator<<(ostream& out, const pair<t1, t2>& a) { n   out << a.first <<     << a.second; n   return out; n } n template <class t1, class t2> n pair<t1, t2> operator+(const pair<t2, t1>& a, const pair<t1, t2>& b) { n   return {a.first + b.first, a.second + b.second}; n } n template <class t1, class t2> n pair<t1, t2> operator-(const pair<t2, t1>& a, const pair<t1, t2>& b) { n   return {a.first - b.first, a.second - b.second}; n } n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); } n long long fpow(long long b, long long e, long long m = (long long)(1e9 + 7)) { n   long long r = 1; n   while (e) { n     if (e & 1) r = (r * b) % m; n     e >>= 1; n     b = (b * b) % m; n   } n   return r; n } n long long n, m; n vector<long long> a; n long long c[100][100]; n long double dp[100][100][100]; n void init() { n   for (long long i = 0; i < (long long)60; i++) n     for (long long j = 0; j < (long long)60; j++) n       for (long long k = 0; k < (long long)70; k++) dp[i][j][k] = -2; n   for (long long i = 0; i < (long long)51; i++) { n     for (long long j = 0; j < (long long)51; j++) { n       if (j == 0) n         c[i][j] = 1; n       else if (i == 0) n         c[i][j] = 0; n       else n         c[i][j] = c[i - 1][j - 1] + c[i - 1][j]; n     } n   } n } n long double solve(long long i, long long k, long long mx) { n   if (i == m) return (!k ? mx : 0); n   long double& r = dp[i][k][mx]; n   if (r > -1) return r; n   long double p = 1; n   r = 0; n   for (long long j = 0; j < (long long)k + 1; j++) { n     long long len = (j + a[i] - 1) / a[i]; n     r += (c[k][j] * p * solve(i + 1, k - j, max(mx, len))); n     p /= m; n   } n   return r; n } n int32_t main(int32_t argc, char const* argv[]) { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> n >> m; n   a.resize(m); n   cin >> a; n   init(); n   cout << setprecision(15) << solve(0, n, 0) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool field[100][100][100]; n int n, m, k; n bool check(int x, int y, int z) { n   return (x >= 0 && x < n && y >= 0 && y < m && z >= 0 && z < k && n           field[x][y][z]); n } n int main() { n   cin.sync_with_stdio(false); n   cout.sync_with_stdio(false); n   cin >> n >> m >> k; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       for (int x = 0; x < k; x++) { n         char v; n         cin >> v; n         field[i][j][x] = (v ==  1 ); n       } n     } n   } n   int answer = 0; n   for (int x = 0; x < n; x++) { n     for (int y = 0; y < m; y++) { n       for (int z = 0; z < k; z++) { n         if (check(x, y, z)) { n           if ((check(x - 1, y, z) && check(x + 1, y, z)) || n               (check(x, y - 1, z) && check(x, y + 1, z)) || n               (check(x, y, z - 1) && check(x, y, z + 1))) { n             answer++; n             continue; n           } n           if (check(x - 1, y, z) && n               ((check(x, y + 1, z) && !check(x - 1, y + 1, z)) || n                (check(x, y, z + 1) && !check(x - 1, y, z + 1)))) { n             answer++; n             continue; n           } n           if (check(x, y - 1, z) && n               ((check(x + 1, y, z) && !check(x + 1, y - 1, z)) || n                (check(x, y, z + 1) && !check(x, y - 1, z + 1)))) { n             answer++; n             continue; n           } n           if (check(x, y, z - 1) && n               ((check(x, y + 1, z) && !check(x, y + 1, z - 1)) || n                (check(x + 1, y, z) && !check(x + 1, y, z - 1)))) { n             answer++; n             continue; n           } n         } n       } n     } n   } n   cout << answer <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1005; n char g[N][N]; n int l[N][N], r[N][N], up[N][N], dn[N][N]; n int jx[N][N], jy[N][N]; n struct Node { n   int x, y, len; n }; n vector<Node> p; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %s , g[i] + 1); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       if (g[i][j] ==  * ) { n         l[i][j] = l[i][j - 1] + 1; n         up[i][j] = up[i - 1][j] + 1; n       } n   for (int i = n; i >= 1; i--) n     for (int j = m; j >= 1; j--) n       if (g[i][j] ==  * ) { n         r[i][j] = r[i][j + 1] + 1; n         dn[i][j] = dn[i + 1][j] + 1; n       } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       if (g[i][j] ==  * ) { n         int len = min(min(l[i][j], r[i][j]), min(up[i][j], dn[i][j])); n         if (len > 1) { n           Node temp; n           temp = (Node){i, j, len - 1}; n           p.push_back(temp); n           jx[i - len + 1][j]++, jx[i + len][j]--; n           jy[i][j - len + 1]++, jy[i][j + len]--; n         } n       } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       jx[i][j] += jx[i - 1][j], jy[i][j] += jy[i][j - 1]; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       if (g[i][j] ==  *  && !jx[i][j] && !jy[i][j]) { n         printf( -1 n ); n         return 0; n       } n   printf( %d n , (int)p.size()); n   for (int i = 0; i < p.size(); i++) n     printf( %d %d %d n , p[i].x, p[i].y, p[i].len); n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n #define M 105 n  n int frq[M]; n  n int main() n { n     int t; n     scanf( %d , &t); n  n     while(t--) n     { n         int n, x; n         scanf( %d %d , &n, &x); n  n         memset(frq, 0, sizeof(frq)); n         for(int i = 1; i <= n; i++) n         { n             int p; n             scanf( %d , &p); n  n             frq[p]++; n         } n  n         vector<int> ans; n  n          n         for(int i = 1; i <= 100; i++) n         { n             while (frq[i] > 1) n             { n                 ans.push_back(i); n                 frq[i]--; n             } n         } n  n         for(int i = 1; i <= 100; i++) n         { n             if(frq[i]) n             { n                 ans.push_back(i); n                 frq[i]--; n             } n         } n  n         int ald = 0; n         for(int i = 0; i < n; i++) n         { n             ald += ans[i]; n             if(ald == x) n             { n                 swap(ans[i], ans[n-1]); n                 break; n             } n         } n  n         ald = 0; n         bool flag = true; n         for(int d: ans) n         { n             ald += d; n             if(ald == x) n             { n                 flag = false; n                 break; n             } n         } n  n         if(!flag) printf( NO n ); n         else n         { n             printf( YES n ); n             for(int d: ans) printf( %d  , d); n             printf(  n ); n         } n     } n  n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i, x, k = 0; n   cin >> n; n   vector<int> a; n   for (i = 0; i < n; i++) { n     cin >> x; n     a.push_back(x); n   } n   sort(a.begin(), a.end()); n   for (i = 0; i < n; i++) { n     if (a[i] % 2 != 0) k++; n   } n   int y = min(k, n - k); n   cout << y <<   n ; n   return 0; n } n


#include <cstdio> n #include <iostream> n #include <cstring> n #include <algorithm> n #include <vector> n using namespace std; n # define rep(i,a,b) for(int i=(a); i<=(b); ++i) n # define drep(i,a,b) for(int i=(a); i>=(b); --i) n typedef long long int_; n inline int readint(){ n  int a = 0; char c = getchar(), f = 1; n  for(; c< 0 ||c> 9 ; c=getchar()) n   if(c ==  - ) f = -f; n  for(;  0 <=c&&c<= 9 ; c=getchar()) n   a = (a<<3)+(a<<1)+(c^48); n  return a*f; n } n inline void getMin(int &a,const int &b){ n  if(a > b) a = b; n } n  n const int Mod = 998244353; n inline void add(int &x,const int &y){ n  (x += y) >= Mod ? x -= Mod : 0; n } n inline void mul(int &x,const int &y){ n  x = int_(x)*y%Mod; n } n int inv[4] = {0,1,(Mod+1)/2,(Mod+1)/3}; n inline int C(const int &n,const int &m){ n  int res = 1; n  rep(i,1,m) mul(res,inv[i]); n  rep(i,0,m-1) mul(res,n-i); n  return res; n } n  n const int MaxN = 1000005; n const int infty = (1<<30)-1; n int dp[MaxN][4]; // prefix sum n  n int main(){ n  int n = readint(), x; n  dp[0][0] = 1; // only one node n  rep(i,1,n) rep(j,0,3){ n   rep(k,x=0,2) // at most 2 n    add(x,dp[i-1][k]); n   dp[i][j] = C(j+x-1,j); n  } n  drep(i,n,1) rep(j,0,3) // get origin value n   add(dp[i][j],Mod-dp[i-1][j]); n  int ans = 0; n  rep(i,1,n) rep(j,2,3) rep(k,0,3-j) n   add(ans,1ll*dp[i][j]*dp[n-i][k]%Mod); n  rep(j,0,3) add(ans,dp[n][j]); n  printf( %d n ,ans); n  return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   long long x = 0, f = 1; n   char c = getchar(); n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) f = -1; n   for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ; n   return x * f; n } n const long long MAXN = 100010; n const long long INF = 2147483600; n long long N; n long long a[MAXN + 1]; n int f[63][MAXN + 1]; n int p[MAXN + 1], id[MAXN + 1], nwp[MAXN + 1]; n int t[2]; n long long sta[2][MAXN + 1]; n int cnt[2]; n inline void Sort(long long x) { n   t[0] = t[1] = 0; n   for (long long i = 1; i <= N; i++) { n     long long d = (a[p[i]] >> x) & 1; n     sta[d][++t[d]] = p[i]; n   } n   for (long long i = 1; i <= t[1]; i++) p[i] = sta[1][i]; n   for (long long i = 1; i <= t[0]; i++) p[i + t[1]] = sta[0][i]; n   return; n } n int main() { n   N = read(); n   for (long long i = 1; i <= N; i++) { n     a[i] = read(); n   } n   memset(f, 127, sizeof(f)); n   for (long long i = 1; i <= N; i++) p[i] = i; n   Sort(0); n   f[0][0] = t[0]; n   f[0][t[1]] = min(f[0][t[1]], t[1]); n   for (long long i = 1; i <= 62; i++) { n     for (long long j = 1; j <= N; j++) id[j] = p[j]; n     Sort(i); n     cnt[0] = cnt[1] = 0; n     for (long long j = 1; j <= N; j++) nwp[p[j]] = j; n     int mx1 = 0, mx0 = 0; n     for (long long j = 0; j <= N; j++) { n       if (j) { n         long long x = (a[id[j]] >> i) & 1; n         ++cnt[x]; n         if (x) mx1 = max(mx1, nwp[id[j]]); n         mx0 = max(mx0, nwp[id[j]]); n       } n       if (f[i - 1][j] <= i * N) { n         f[i][mx1] = min(f[i][mx1], f[i - 1][j] + cnt[1] + t[0] - cnt[0]); n         f[i][max(t[1], mx0)] = n             min(f[i][max(t[1], mx0)], f[i - 1][j] + cnt[0] + t[1] - cnt[1]); n       } n     } n   } n   printf( %d n , f[62][0]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int x, q; n vector<int> adj[205]; n bool visited[205]; n void dfs(int n) { n   visited[n] = 1; n   for (int i = 0; i < adj[n].size(); i++) { n     if (!visited[adj[n][i]]) { n       visited[adj[n][i]] = 1; n       dfs(adj[n][i]); n     } n   } n } n int main() { n   int n, m; n   cin >> n >> m; n   bool flag = 0; n   for (int i = m + 1; i <= n + m; i++) { n     cin >> q; n     while (q--) { n       cin >> x; n       if (x) { n         flag = 1; n       } n       adj[i].push_back(x); n       adj[x].push_back(i); n     } n   } n   if (!flag) { n     cout << n << endl; n     return 0; n   } n   int ans = -1; n   for (int i = m + 1; i <= n + m; i++) { n     if (!visited[i]) { n       dfs(i); n       ans++; n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n string ar[] = { zero ,     one ,      two ,        three ,     four , n                 five ,     six ,      seven ,      eight ,     nine , n                 ten ,      eleven ,   twelve ,     thirteen ,  fourteen , n                 fifteen ,  sixteen ,  seventeen ,  eighteen }; n string br[] = {  ,       ten ,    twenty ,   thirty ,  forty , n                 fifty ,  sixty ,  seventy ,  eighty ,  ninety }; n int main() { n   int q = 1; n   while (q--) { n     int n; n     cin >> n; n     if (n <= 18) { n       cout << ar[n]; n       continue; n     } n     if (n < 20) { n       cout << ar[n % 10] <<  teen ; n       continue; n     } n     int f = n / 10; n     if (n % 10 == 0) { n       cout << br[f]; n       continue; n     } n     cout << br[f] <<  -  << ar[n % 10]; n   } n } n


#include <bits/stdc++.h> n using ll = long long int; n using namespace std; n struct custom_hash { n   static uint64_t splitmix64(uint64_t x) { n     x += 0x9e3779b97f4a7c15; n     x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; n     x = (x ^ (x >> 27)) * 0x94d049bb133111eb; n     return x ^ (x >> 31); n   } n   size_t operator()(uint64_t x) const { n     static const uint64_t FIXED_RANDOM = n         chrono::steady_clock::now().time_since_epoch().count(); n     return splitmix64(x + FIXED_RANDOM); n   } n }; n bool printSub(int a[], int sum) { n   if (sum == 0) return true; n   if (sum < 0) return false; n   for (int i = 0; i < 3; ++i) { n     int rem = sum - a[i]; n     if (printSub(a, rem)) { n       cout << a[i] <<    ; n       return true; n     } n   } n } n void solve() { n   int n, ans = 0; n   cin >> n; n   int a[n]; n   for (int i = 0; i < n; ++i) cin >> a[i]; n   for (int i = 30; i > 0; --i) { n     int sum = 0; n     for (int j = 0; j < n; ++j) { n       if (a[j] > i) { n         sum = 0; n       } else n         sum = max(a[j], sum + a[j]); n       ans = max(ans, sum - i); n     } n   } n   cout << ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n int col[100002]; n int cal[5]; n int main() { n   int n, m, i, j, k; n   int inp[3]; n   scanf( %d%d , &n, &m); n   for (i = 0; i < m; i++) { n     for (j = 0; j <= 3; j++) { n       cal[j] = 0; n     } n     for (j = 0; j < 3; j++) { n       scanf( %d , inp + j); n       cal[col[inp[j]]]++; n     } n     k = 0; n     for (j = 1; j <= 3; j++) { n       if (cal[j] == 0) { n         while (col[inp[k]] != 0) { n           k++; n         } n         col[inp[k]] = j; n       } n     } n   } n   for (i = 1; i <= n; i++) { n     if (col[i] == 0) { n       col[i] = 1; n     } n     printf( %d  , col[i]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n, s; n   cin >> n >> s; n   int a[s]; n   memset(a, 0, sizeof a); n   for (int i = 0; i < n; i++) { n     int x, y; n     cin >> x >> y; n     a[x - 1] = max(a[x - 1], y); n   } n   int t = 0; n   for (int i = 0; i < s; i++) { n     t += max(a[s - i - 1] - t, 0); n     t++; n   } n   cout << t << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char grid[105][105]; n int dix[] = {-1, 1, 0, 0}, diy[] = {0, 0, -1, 1}, par[105][105], col[105][105], n     n, m; n char ddd[] =  UDLR ; n vector<int> vec; n void dfs(int xx, int yy) { n   int i, p, q; n   col[xx][yy] = 1; n   for (i = 0; i < 4; i++) { n     p = xx + dix[i]; n     q = yy + diy[i]; n     if (p >= 0 && p < n && q >= 0 && q < m && grid[p][q] !=  *  && !col[p][q]) { n       par[p][q] = i; n       dfs(p, q); n     } n   } n   return; n } n int main() { n   int i, j, k, p, q, x, y; n   scanf( %d %d , &n, &m); n   for (i = 0; i < n; i++) scanf( %s , grid[i]); n   for (i = 0; i < n; i++) { n     for (j = 0; j < m; j++) { n       if (grid[i][j] ==  F ) p = i, q = j; n     } n   } n   dfs(0, 0); n   while (p || q) { n     vec.push_back(par[p][q]); n     y = par[p][q]; n     p -= dix[y], q -= diy[y]; n   } n   reverse(vec.begin(), vec.end()); n   for (i = 0; i < vec.size(); i++) { n     printf( %c n , ddd[vec[i]]); n     fflush(stdout); n     scanf( %d %d , &x, &y); n     x--, y--; n     if (p == x && q == y) { n       swap(ddd[vec[i]], ddd[vec[i] - 1]); n       i--; n     } n     p = x, q = y; n   } 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   cout.tie(0); n   int q; n   cin >> q; n   for (int k = 0; k < q; ++k) { n     string s, t; n     cin >> s >> t; n     vector<bool> a(26), b(26); n     for (int i = 0; i < s.size(); ++i) { n       a[s[i] -  a ] = true; n       b[t[i] -  a ] = true; n     } n     bool flag = false; n     for (int i = 0; i < 26; ++i) { n       if (a[i] && b[i]) { n         flag = true; n         break; n       } n     } n     if (flag) n       cout <<  YES n ; n     else n       cout <<  NO n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct T { n   T *l, *r; n   long long d, sum, mx; n   bool pushed; n   void recalc(long long len, long long d) { n     this->d = d; n     sum = len * d; n     mx = max(0ll, sum); n   } n   T(long long len, long long d) { n     l = r = 0; n     this->d = d; n     sum = len * d; n     mx = max(0ll, sum); n     pushed = 0; n   } n   void push(int l, int r) { n     if (!pushed) return; n     int m = (l + r) / 2; n     this->l->recalc(m + 1 - l, d); n     this->r->recalc(r + 1 - m, d); n     this->l->pushed = 1; n     this->r->pushed = 1; n     pushed = 0; n   } n   void upd(int l, int r, int tl, int tr, long long x) { n     if (r < tl || tr < r) return; n     if (tl <= l && r <= tr) { n       d = x; n       sum = (r - l + 1) * d; n       mx = max(0ll, sum); n       pushed = 1; n     } n     int m = (l + r) / 2; n     if (!this->l) this->l = new T(m - l + 1, d); n     if (!this->r) this->r = new T(r - m + 1, d); n     push(l, r); n     this->l->upd(l, m, tl, tr, x); n     this->r->upd(m + 1, r, tl, tr, x); n     sum = this->l->sum + this->r->sum; n     mx = max(this->l->mx, this->l->sum + this->r->mx); n   } n }; n int main() { n   long long n; n   cin >> n; n   for (long long i = 2; i * i <= n; i++) { n     if (n % i == 0) { n       while (n % i == 0) n /= i; n       return cout << (n == 1 ? i : 1), 0; n     } n   } n   cout << n; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 5, M = N * 3; n int n, i, j, l, r, scnt, s1; n bool bb[M]; n int w1[M], bbel[M]; n unsigned long long w2[M]; n struct seg { n   int l, r, c, bel; n   bool operator<(const seg& rhs) const { return r < rhs.r; } n }; n set<seg> S; n vector<int> ve[N], in[N], out[N]; n void del(seg s) { n   S.erase(s); n   out[i].push_back(s.c); n } n void ins(seg s) { n   s.c = ++scnt; n   w1[scnt] = s.r - s.l + 1; n   w2[scnt] = 1ll * w1[scnt] * s.bel; n   bbel[scnt] = s.bel; n   S.insert(s); n   in[i].push_back(s.c); n   ve[s.bel].push_back(s.c); n } n unsigned long long s2, s3, s4, k; n void rmv(int x) { n   if (bb[x]) bb[x] = 0, s1 -= w1[x], s2 -= w2[x]; n } n void calc(int lm) { n   s1 = s2 = s3 = s4 = 0; n   memset(bb + 1, 0, scnt); n   for (i = 1, j = 0; i <= n; ++i) { n     for (int x : out[i]) rmv(x); n     for (int x : in[i]) n       if (bbel[x] >= j) bb[x] = 1, s1 += w1[x], s2 += w2[x]; n     for (; s1 > lm || !j; ++j) n       for (int x : ve[j]) rmv(x); n     s3 += s2 - 1ll * s1 * (j - 1); n     s4 += i - j + 1; n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> k; n   S.insert((seg){1, 1 << 30, 0, 0}); n   for (i = 1; i <= n; ++i) { n     cin >> l >> r; n     --r; n     auto it = S.lower_bound((seg){0, l, 0, 0}); n     if (it->l < l) ins((seg){it->l, l - 1, 0, it->bel}); n     if (it->r >= r) { n       seg tmp = *it; n       del(*it); n       if (r < tmp.r) tmp.l = r + 1, ins(tmp); n     } else { n       for (; it != S.end() && it->r <= r;) del(*it++); n       if (it != S.end() && it->l <= r) { n         seg tmp = *it; n         del(*it); n         tmp.l = r + 1; n         ins(tmp); n       } n     } n     ins((seg){l, r, 0, i}); n   } n   calc(1 << 30); n   unsigned long long ts3 = s3; n   k = s4 - k; n   int le = 0, ri = 1e9, mid; n   for (; le < ri;) { n     mid = le + ri >> 1; n     calc(mid); n     if (s4 >= k) n       ri = mid; n     else n       le = mid + 1; n   } n   calc(le); n   cout << ts3 - (s3 - 1ll * (s4 - k) * le) << endl; n   return 0; n } n