#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, n; n   long long k, time, maks, tot, ar[10005], ans, temp, m; n   bool cek; n   scanf( %d %I64d %I64d , &n, &m, &k); n   for (i = 0; i < n; ++i) scanf( %I64d , &ar[i]); n   if ((n % 2) == 0) n     printf( 0 n ); n   else { n     ans = 0; n     time = (n + 1) / 2; n     if (time > m) n       printf( 0 n ); n     else { n       temp = m / time; n       maks = temp * k; n       ans = ar[0]; n       for (i = 2; i < n; i += 2) ans = min(ans, ar[i]); n       ans = min(ans, maks); n       printf( %I64d n , ans); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string str; n vector<int> graph[26], rgraph[26]; n bool visited[26]; n bool present[26]; n void dfs(int i) { n   visited[i] = true; n   if (graph[i].size() >= 1 && !visited[graph[i][0]]) dfs(graph[i][0]); n   str.insert(str.begin(), (char)( a  + i)); n } n void rdfs(int i) { n   visited[i] = true; n   if (rgraph[i].size() >= 1 && !visited[rgraph[i][0]]) { n     str.insert(str.begin(), (char)( a  + rgraph[i][0])); n     rdfs(rgraph[i][0]); n   } n } n int main() { n   int n; n   cin >> n; n   string s[n]; n   for (int i = 0; i < n; i++) cin >> s[i]; n   memset(present, false, sizeof(present)); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < s[i].length() - 1; j++) { n       graph[s[i][j] -  a ].push_back(s[i][j + 1] -  a ); n       rgraph[s[i][j + 1] -  a ].push_back(s[i][j] -  a ); n       present[s[i][j] -  a ] = true; n     } n     present[s[i][s[i].length() - 1] -  a ] = true; n   } n   memset(visited, 0, sizeof(visited)); n   for (int i = 0; i < 26; i++) { n     if (present[i] && !visited[i]) { n       dfs(i); n       rdfs(i); n     } n   } n   cout << str; n } n


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


#include <bits/stdc++.h> n namespace mem { n namespace stdval { n using i32 = int; n using i64 = long long int; n using u32 = unsigned int; n using u64 = unsigned long long int; n using f32 = float; n using f64 = double; n using f96 = long double; n using i128 = __int128_t; n using u128 = __uint128_t; n }  // namespace stdval n namespace utils { n using std::accumulate; n using std::cerr; n using std::cin; n using std::cout; n using std::endl; n using std::function; n using std::get; 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::unique; n using std::upper_bound; n }  // namespace utils n namespace random { n const int LuckyNumber = 20040726; 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 io { n template <const int mod> n inline void read(modint::Z<mod> &x) { n   read(x.x); n } n template <const int mod> n inline void print(modint::Z<mod> x) { n   print(x.x); n } n }  // namespace io 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::get; n using std::make_pair; n using std::make_tuple; n using std::map; n using std::pair; n using std::priority_queue; n using std::queue; n using std::set; n using std::stack; n using std::tie; 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 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   template <class Function> n   inline void forEach(Function func) { n     for (const auto &it : *this) func(it); 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 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 struct string : std::string { n   using std::string::string; n   string() : std::string(  ) {} n   string(const std::string &plain) : std::string(plain) {} n   template <class T> n   inline string join(const vector<T> &vet) const; n   vector<string> split(const string &dim) 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[dim.length() + 1]; n     strcpy(tar, dim.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 long 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 int &x) { return std::to_string(x); } n inline string to_string(const unsigned long long int &x) { n   return std::to_string(x); n } n inline string to_string(const string &s) { return s; } n inline string to_string(const char *s) { return string(s); } n inline string to_string(const std::string &s) { return string(s); } n template <const int mod> n inline string to_string(const mem::modint::Z<mod> &v) { n   return std::to_string(v.x); n } n template <class T> n inline string to_string(const vector<T> &ctn) { n   return  [  + string( , ).join(ctn) +  ] ; n } n template <class T> n inline string to_string(const set<T> &ctn) { n   string result =  { ; n   bool flag = false; n   for (const auto &it : ctn) { n     if (flag) result +=  , ; n     flag = true; n     result += to_string(it); n   } n   return result +  } ; n } n template <class T1, class T2> n inline string to_string(const map<T1, T2> &ctn) { n   string result =  { ; n   bool flag = false; n   for (const auto &it : ctn) { n     if (flag) result +=  , ; n     flag = true; n     result += to_string(it.first) +  :  + to_string(it.second); n   } n   return result +  } ; 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 inline string operator   _s(const char *s) { return string(s); } n inline string operator   _s(const char *s, size_t len) { n   return string(s, len); n } n inline string operator   _s(long double x) { return to_string(x); } n inline string operator   _s(unsigned long long int x) { return to_string(x); } n }  // namespace container n namespace io { n namespace fastio { n const int BUFFER = 1 << 18; 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 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 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 long long 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(char &x) { x = getc(); } n inline void read(char *s) { n   char c = getc(); n   while (~c && !isspace(c)) *s++ = c, c = getc(); n   *s++ =   0 ; n } n inline void read(container::string &s) { n   char c = getc(); n   s =   ; n   while (~c && !isspace(c)) s += c, c = getc(); n } 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 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 long long 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(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 container::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...), putc(  n ); n } n template <class... Args> n inline void printfm(const char *formatter, Args... arguments) { n   print(container::string().format(formatter, arguments...)); n } n template <class... Args> n inline void printfm(const container::string &formatter, Args... arguments) { n   print(container::string().format(formatter, arguments...)); n } n }  // namespace io n namespace logger { n enum ConsoleColor { n   NOPE = -1, n   BLACK, n   RED, n   GREEN, n   YELLOW, n   BLUE, n   PURPLE, n   DEEPBLUE n }; n template <const ConsoleColor color = NOPE, class... Args> n inline void log(const char *formatter, Args... args) { n   if (~color) { n     fprintf(stderr,   033[%dm , 30 + color); n     fprintf(stderr, formatter, args...); n     fprintf(stderr,   033[0m ); n   } else { n     fprintf(stderr, formatter, args...); n   } n } n template <const ConsoleColor color = NOPE, class... Args> n inline void logln(const char *formatter, Args... args) { n   if (~color) { n     fprintf(stderr,   033[%dm , 30 + color); n     fprintf(stderr, formatter, args...); n     fprintf(stderr,   033[0m n ); n   } else { n     fprintf(stderr, formatter, args...); n     fprintf(stderr,   n ); n   } n } n template <class T> n inline void logs(const T &x) { n   fprintf(stderr, container::to_string(x).c_str()); n } n template <class T, class... Args> n inline void logs(const T &x, Args... args) { n   logs(x), logs(args...); n } n template <class... Args> n inline void logsln(Args... args) { n   logs(args...); n   fprintf(stderr,   n ); n } n }  // namespace logger n using namespace io; n using namespace math; n using namespace utils; n using namespace modint; n using namespace random; n using namespace stdval; n using namespace logger; n using namespace container; n }  // namespace mem n using namespace mem; n const int N = 1e6 + 10; n const long long inf = 1e18; n int k, q, f[6], stk[N << 1]; n long long dp[6][N]; n inline int weight(int k) { return k % 3 == 0 ? k / 3 : 0; } n inline long long calc(int s) { n   if ((s + 8) / 9 > k) { n     return -inf; n   } n   int t = s / 9; n   s -= t * 9; n   if (t + 2 > k) { n     return t * 3 + weight(s); n   } else { n     return t * 3 + s / 3; n   } n } n inline vector<long long> transform(vector<long long> dp, int val) { n   vector<vector<long long>> g(3, vector<long long>(dp.size(), -inf)); n   for (int r = 0; r < 9; r++) n     for (int cas = 0; cas < 3; cas++) { n       int u = 1, v = 0; n       for (int j = r, l = 0; j < dp.size(); j += 9, l++) { n         while (u <= v && n                dp[j] - 3ll * l * val > dp[stk[v] * 9 + r] - 3ll * stk[v] * val) n           --v; n         stk[++v] = l; n         while (u <= v && k - cas < l - stk[u]) ++u; n         if (u <= v) { n           g[cas][j] = 3ll * l * val + dp[stk[u] * 9 + r] - 3ll * val * stk[u]; n         } n       } n     } n   for (int i = 0; i < dp.size(); i++) { n     dp[i] = max(dp[i], g[0][i]); n     for (int j = i; j >= max<int>(0, i - 9); j--) { n       dp[i] = max(dp[i], g[1][j] + (long long)weight(i - j) * val); n     } n     for (int j = i; j >= max<int>(0, i - 9); j--) { n       dp[i] = max(dp[i], g[2][j] + (long long)(i - j) / 3 * val); n     } n   } n   return dp; n } n int32_t main() { n   read(k); n   for (int i = 0; i < 6; i++) { n     read(f[i]); n   } n   for (int i = 0; i < 1000000; i++) { n     long long t = calc(i); n     if (t < 0) { n       dp[0][i] = -inf; n     } else { n       dp[0][i] = (long long)t * f[0]; n     } n   } n   int w = 10; n   for (int k = 1; k < 6; k++, w *= 10) { n     for (int r = 0; r < w; r++) { n       vector<long long> src; n       for (int i = r; i < 1000000; i += w) { n         src.push_back(dp[k - 1][i]); n       } n       vector<long long> rsp = transform(src, f[k]); n       for (int i = r, j = 0; i < 1000000; i += w, j++) { n         dp[k][i] = rsp[j]; n       } n     } n   } n   read(q); n   while (q-- > 0) { n     int x; n     read(x); n     print(dp[5][x],   n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3e5 + 5; n const int inf = 0x3f3f3f3f; n const int mod = 1e9 + 7; n char s[maxn]; n int ans[maxn]; n void solve() { n   int n, k; n   scanf( %d%d , &n, &k); n   scanf( %s , s + 1); n   memset(ans, -1, sizeof(ans)); n   for (int i = 1; i <= n; i++) { n     if (s[i] ==  ? ) continue; n     if (ans[i % k + 1] == -1) n       ans[i % k + 1] = s[i] -  0 ; n     else { n       if (s[i] -  0  != ans[i % k + 1]) { n         printf( No n ); n         return; n       } n     } n   } n   int cnt1 = 0, cnt0 = 0; n   for (int i = 1; i <= k; i++) { n     if (ans[i] == 1) cnt1++; n     if (ans[i] == 0) cnt0++; n   } n   if (cnt1 > k / 2 || cnt0 > k / 2 || k & 1) { n     printf( No n ); n     return; n   } n   printf( Yes n ); n } n int main() { n   int T; n   scanf( %d , &T); n   while (T--) solve(); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   int s[n]; n   int m[n]; n   string st; n   cin >> st; n   for (int i = 0; i < n; i++) s[i] = st[i] -  0 ; n   cin >> st; n   for (int i = 0; i < n; i++) m[i] = st[i] -  0 ; n   sort(s, s + n); n   sort(m, m + n); n   int sher = 0; n   int mor = 0; n   int pos = 0; n   for (int i = 0; i < n; i++) { n     if (s[pos] < m[i]) { n       sher++; n       pos++; n     } n   } n   pos = 0; n   mor = n; n   for (int i = 0; i < n; i++) { n     if (m[i] >= s[pos]) mor--, pos++; n   } n   cout << mor <<   n  << sher; n } n


#include <bits/stdc++.h> n using namespace std; n long long mpow(long long a, long long b) { n   if (b == 1) return a; n   if (b == 0) return 1; n   return mpow(a, b - 1); n } n int main() { n   long long n; n   cin >> n; n   cout << (n / 2520); n } n


#include <bits/stdc++.h> n using namespace std; n long long read() { n   long long x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = 10 * x + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n int gcd(int x, int y) { return y ? gcd(y, x % y) : x; } n int power(int x, int y) { n   int t = 1; n   for (; y; y >>= 1, x = x * x % 1000000007) n     if (y & 1) t = t * x % 1000000007; n   return t; n } n long long n, m; n int main() { n   n = read(); n   m = read(); n   if (min(n, m) == 1) { n     long long ans = 6 * (max(n, m) / 6); n     ans += max((long long)0, 2 * ((max(n, m) % 6) - 3)); n     cout << ans << endl; n   } else if (min(n, m) == 2) { n     if (max(n, m) == 3) n       cout << 4 << endl; n     else if (max(n, m) == 7) n       cout << 12 << endl; n     else if (max(n, m) == 2) n       cout << 0 << endl; n     else n       cout << n * m << endl; n   } else { n     if ((n * m) % 2 == 0) n       cout << n * m << endl; n     else n       cout << n * m - 1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dx[10] = {1, -1, 0, 0}; n int dy[10] = {0, 0, 1, -1}; n const long long mod = 1e9 + 7; n long long cur; n long long tich = 1; n vector<int> G[300005]; n int n, h, m; n int a[105][105]; n int b[105][105]; n int ans; n int main() { n   cin >> n >> m; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) cin >> a[i][j]; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       cin >> b[i][j]; n       if (b[i][j] < a[i][j]) { n         int tmp = b[i][j]; n         b[i][j] = a[i][j]; n         a[i][j] = tmp; n       } n     } n   for (int i = 1; i < n; i++) n     for (int j = 1; j <= m; j++) { n       if (a[i][j] >= a[i + 1][j]) { n         cout <<  Impossible ; n         return 0; n       } n       if (b[i][j] >= b[i + 1][j]) { n         cout <<  Impossible ; n         return 0; n       } n     } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j < m; j++) { n       if (a[i][j] >= a[i][j + 1]) { n         cout <<  Impossible ; n         return 0; n       } n       if (b[i][j] >= b[i][j + 1]) { n         cout <<  Impossible ; n         return 0; n       } n     } n   cout <<  Possible ; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3fffffff; n const int SINF = 0x7fffffff; n const long long LINF = 0x3fffffffffffffff; n const long long SLINF = 0x7fffffffffffffff; n const int MAXN = 300007; n const int MAX = 130; n int n; n int a[MAXN]; n int ps[MAXN]; n int pc[MAXN][2]; n void init(); n void input(); n void work(); n int main() { n   init(); n   input(); n   work(); n } n void init() { ios::sync_with_stdio(false); } n void input() { n   scanf( %d , &n); n   long long x; n   for (int i = 1; i <= n; ++i) { n     scanf( %I64d , &x); n     a[i] = __builtin_popcountll(x); n   } n } n void work() { n   for (int i = 1; i <= n; ++i) ps[i] = ps[i - 1] + a[i]; n   int mx; n   long long ans = 0; n   for (int i = 1; i <= n; ++i) { n     int j = i - 1; n     mx = a[i]; n     for (; j && i - j <= MAX; --j) { n       mx = (((mx) > (a[j])) ? (mx) : (a[j])); n       if ((ps[i] & 1) == (ps[j - 1] & 1) && mx * 2 <= ps[i] - ps[j - 1]) ++ans; n     } n     ans += pc[j][ps[i] & 1]; n     pc[i][0] = pc[i - 1][0], pc[i][1] = pc[i - 1][1]; n     ++pc[i][ps[i - 1] & 1]; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5e5 + 10; n struct edge { n   int v, nxt; n } e[maxn << 1]; n int head[maxn], ecnt = 0; n void add(int u, int v) { e[++ecnt] = (edge){v, head[u]}, head[u] = ecnt; } n vector<int> p[maxn]; n int pos[maxn]; n int tree[maxn]; n void update(int x, int v) { n   for (; x < maxn; x += x & -x) tree[x] += v; n } n long long query(int x) { n   long long ret = 0; n   for (; x; x -= x & -x) ret += tree[x]; n   return ret; n } n namespace ACAM { n int son[maxn][26], fail[maxn], cnt; n void insert(char *s, int id) { n   int len = strlen(s + 1), u = 0; n   p[id].push_back(u); n   for (int i = 1; i <= len; i++) { n     int c = s[i] -  a ; n     if (!son[u][c]) son[u][c] = ++cnt; n     u = son[u][c]; n     p[id].push_back(u); n   } n   pos[id] = u; n } n void build() { n   queue<int> que; n   for (int c = 0; c < 26; c++) { n     int u = son[0][c]; n     if (u) que.push(u); n   } n   while (!que.empty()) { n     int u = que.front(); n     que.pop(); n     for (int c = 0; c < 26; c++) { n       int v = son[u][c]; n       if (!v) n         son[u][c] = son[fail[u]][c]; n       else n         fail[v] = son[fail[u]][c], que.push(v); n     } n   } n   for (int i = 1; i <= cnt; i++) add(fail[i], i); n } n }  // namespace ACAM n int n, q, siz[maxn], dfn[maxn], idx = 0; n char s[maxn]; n vector<pair<int, int> > op[maxn]; n void dfs(int u) { n   siz[u] = 1, dfn[u] = ++idx; n   for (int i = head[u]; ~i; i = e[i].nxt) { n     int v = e[i].v; n     dfs(v); n     siz[u] += siz[v]; n   } n } n long long ans[maxn]; n int main() { n   memset(head, -1, sizeof(head)); n   scanf( %d%d , &n, &q); n   for (int i = 1; i <= n; i++) { n     scanf( %s , s + 1); n     ACAM::insert(s, i); n   } n   ACAM::build(); n   for (int i = 1; i <= q; i++) { n     int k, l, r; n     scanf( %d%d%d , &l, &r, &k); n     op[l - 1].push_back(make_pair(i, -k)); n     op[r].push_back(make_pair(i, k)); n   } n   dfs(0); n   for (int i = 1; i <= n; i++) { n     for (auto t : p[i]) update(dfn[t], 1); n     for (auto qr : op[i]) { n       int id = qr.first, u = qr.second; n       if (u < 0) n         u = -u, u = pos[u], n         ans[id] -= query(dfn[u] + siz[u] - 1) - query(dfn[u] - 1); n       else n         u = pos[u], ans[id] += query(dfn[u] + siz[u] - 1) - query(dfn[u] - 1); n     } n   } n   for (int i = 1; i <= q; i++) printf( %lld n , ans[i]); n } n


#include <bits/stdc++.h> n using namespace std; n void update(int* Bit, int index) { n   for (; index <= 100000; index += (index & (-index))) { n     Bit[index] += 1; n   } n } n int query(int* Bit, int index) { n   int sum = 0; n   for (; index > 0; index -= (index & -index)) sum += Bit[index]; n   return sum; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     int n, m; n     cin >> n >> m; n     int maxx; n     for (int i = 31; i >= 0; i--) { n       if (n & (1 << i)) { n         maxx = i; n         break; n       } n     } n     long long ans = 1; n     for (int i = 0; i < maxx; i++) { n       ans = (ans + ans * (1 << i)) % m; n     } n     ans = (ans + m - 1) % m; n     long long d = n - (1 << maxx) + 1; n     ans = (((d + 1) * ans) % m + d) % m; n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a[1000]; n   int n, k; n   scanf( %d , &n); n   scanf( %d , &k); n   for (int i = 0; i < 2 * n + 1; i++) { n     scanf( %d , &a[i]); n   } n   for (int i = 1; i < 2 * n + 1; i += 2) { n     if (a[i] - 1 > a[i + 1] && a[i] - 1 > a[i - 1]) { n       a[i]--; n       k--; n     } n     if (k == 0) { n       break; n     } n   } n   for (int i = 0; i < 2 * n + 1; i++) { n     if (i) { n       printf(   ); n     } n     printf( %d , a[i]); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n int a[N]; n int main() { n   int i, j, k = 0, n; n   cin >> n; n   long long s = 0, t; n   for (i = 1; i <= n; i++) { n     cin >> a[i]; n     s += a[i]; n   } n   if (s % 2 == 1) { n     cout <<  0 n ; n     return 0; n   } n   t = 0; n   for (i = 1; i < n; i++) { n     s -= a[i]; n     t += a[i]; n     if (s == t) k++; n   } n   cout << k << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 257, MOD = 1e9 + 7; n int pk[MAXN * MAXN], pk1[MAXN * MAXN], n, k, f[MAXN][MAXN], C[MAXN][MAXN]; n int mul(int a, int b) { return 1LL * a * b % MOD; } n void add(int &a, const int &b) { n   a += b; n   if (a >= MOD) a -= MOD; n } n void sub(int &a, const int &b) { n   a -= b; n   if (a < 0) a += MOD; n } n int subs(int a, int b) { n   a -= b; n   if (a < 0) a += MOD; n   return a; n } n int pw(int cs, int sm) { n   if (sm == 0) return 1; n   int hpw = pw(cs, sm >> 1); n   hpw = 1LL * hpw * hpw % MOD; n   if (sm & 1) hpw = 1LL * hpw * cs % MOD; n   return hpw; n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> n >> k; n   pk[0] = pk1[0] = 1; n   for (int i = 1; i <= n * n; ++i) { n     pk[i] = 1LL * pk[i - 1] * k % MOD; n     pk1[i] = 1LL * pk1[i - 1] * (k - 1) % MOD; n   } n   C[0][0] = 1; n   for (int i = 1; i <= n; ++i) { n     C[i][0] = C[i][i] = 1; n     for (int j = 1; j < i; ++j) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD; n   } n   int res = 0; n   for (int i = 0; i <= n; ++i) { n     int cur = mul(C[n][i], pw(subs(mul(pk[n - i], pk1[i]), pk1[n]), n)); n     if (i & 1) n       sub(res, cur); n     else n       add(res, cur); n   } n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int N = 1e5 + 100, M = 1e14 + 10; n long long int n, k, l, r, mid, x, y, f[N], p[N], a[N]; n vector<long long int> v; n void add(long long int v, long long int c) { n   if (v == 0) return; n   for (; v < N; v += v & -v) f[v] += c; n } n long long int get(long long int ind) { n   long long int ret = 0; n   for (; ind; ind -= ind & -ind) ret += f[ind]; n   return ret; n } n int main() { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   cin >> n >> k; n   p[0] = M; n   v.push_back(p[0]); n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     p[i] = p[i - 1] + a[i]; n     v.push_back(p[i]); n   } n   sort(v.begin(), v.end()); n   v.resize(unique(v.begin(), v.end()) - v.begin()); n   l = -M; n   r = M; n   while (r - l > 1) { n     mid = l + r >> 1; n     y = 0; n     fill(f, f + N, 0); n     for (int i = n; i >= 0; i--) { n       x = upper_bound(v.begin(), v.end(), p[i] + mid - 1) - v.begin(); n       y += get(N - 1) - get(x + 1); n       x = upper_bound(v.begin(), v.end(), p[i]) - v.begin(); n       add(x + 1, 1); n     } n     if (y >= k) n       l = mid; n     else n       r = mid; n   } n   cout << l << endl; 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   ; n   string s; n   getline(cin, s); n   set<char> st; n   for (int i = 0; i < s.length(); i++) { n     if (s[i] ==  {  || s[i] ==  }  || s[i] ==  ,  || s[i] ==    ) { n       continue; n     } else { n       st.insert(s[i]); n     } n   } n   cout << st.size(); n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k; n int per; n int main() { n   cin >> n >> m >> k; n   per = 2; n   int flag = 0; n   int sum = 0; n   int ff = 0; n   int a = 1; n   for (int i = 1; i <= n; ++i) { n     if (!flag) { n       for (int j = 1; j <= m; ++j) { n         if (sum % 2 == 0 && a == k) { n           if (ff++) cout << endl; n           cout << n * m - 2 * (k - 1); n           a++; n         } n         if (sum % 2 == 0 && a < k) { n           if (ff++) cout << endl; n           cout <<  2 ; n           a++; n         } n         cout <<     << i <<     << j; n         sum++; n       } n       flag = 1; n       continue; n     } n     if (flag) { n       for (int j = m; j >= 1; --j) { n         if (sum % 2 == 0 && a == k) { n           if (ff++) cout << endl; n           cout << n * m - 2 * (k - 1); n           a++; n         } n         if (sum % 2 == 0 && a < k) { n           if (ff++) cout << endl; n           cout <<  2 ; n           a++; n         } n         cout <<     << i <<     << j; n         sum++; n       } n       flag = 0; n       continue; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long md = 1e9 + 7; n long long ans = 0; n long long st[1000000 + 5]; n long long dp[1000000 + 5]; n vector<long long> d[1000000 + 5]; n long long n; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin >> n; n   for (long long i = 0; i < n - 1; i++) { n     long long l, r; n     cin >> l >> r; n     l--; n     r--; n     d[l].push_back(r); n     d[r].push_back(l); n   } n   st[0] = 1; n   for (long long i = 1; i <= n; i++) { n     st[i] = st[i - 1] * 2; n     st[i] %= md; n   } n   long long l = 0; n   for (long long i = 0; i < n; i++) { n     if (d[i].size() == 1) l++; n   } n   long long ans = l * st[n - l + 1] + (n - l) * st[n - l]; n   ans %= md; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   long long x = 0, f = 1; n   char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) { n     x = (x << 1) + (x << 3) + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n const long long maxn = 2e5 + 1e2; n struct Node { n   long long a, b, w; n }; n struct stt { n   long long f[4 * maxn]; n   long long add[4 * maxn]; n   long long val[4 * maxn]; n   void up(long long root) { f[root] = min(f[root << 1], f[root << 1 | 1]); } n   void pushdown(long long root, long long l, long long r) { n     if (add[root]) { n       add[root << 1] += add[root]; n       add[root << 1 | 1] += add[root]; n       f[root << 1] += add[root]; n       f[root << 1 | 1] += add[root]; n       add[root] = 0; n     } n   } n   void build(long long root, long long l, long long r) { n     if (l == r) { n       f[root] = val[l]; n       return; n     } n     long long mid = l + r >> 1; n     build(root << 1, l, mid); n     build(root << 1 | 1, mid + 1, r); n     up(root); n   } n   void update(long long root, long long l, long long r, long long x, n               long long y, long long p) { n     if (x <= l && r <= y) { n       f[root] += p; n       add[root] += p; n       return; n     } n     pushdown(root, l, r); n     long long mid = l + r >> 1; n     if (x <= mid) update(root << 1, l, mid, x, y, p); n     if (y > mid) update(root << 1 | 1, mid + 1, r, x, y, p); n     up(root); n   } n }; n stt a, b; n Node ymh[maxn]; n long long n, m, cnt; n long long pp[maxn]; n long long q; n vector<pair<long long, long long> > v[maxn]; n void print(long long x) { n   if (x >= 10) print(x / 10); n   putchar(x % 10 +  0 ); n } n signed main() { n   n = read(), m = read(); n   q = read(); n   for (register long long i = 1; i < n; ++i) n     a.val[i] = read(), pp[i] = a.val[i], b.val[i + 1] = read(); n   for (register long long i = 1; i <= m; ++i) { n     ymh[i].a = read(), ymh[i].b = read(), ymh[i].w = read(); n     v[ymh[i].a].push_back(make_pair(ymh[i].b, ymh[i].w)); n   } n   b.build(1, 1, n); n   for (register long long i = 1; i <= n; ++i) { n     for (register long long j = 0; j < v[i].size(); ++j) { n       b.update(1, 1, n, 1, v[i][j].first, v[i][j].second); n     } n     a.val[i] += b.f[1]; n   } n   a.build(1, 1, n); n   cout << a.f[1] << endl; n   for (long long i = 1; i <= q; i++) { n     long long x = read(), y = read(); n     a.update(1, 1, n, x, x, y - pp[x]); n     pp[x] = y; n     print(a.f[1]); n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c, n; n   cin >> n >> a >> b >> c; n   int count = 0; n   for (int i = 0; i <= b; i++) { n     for (int j = 0; j <= c; j++) { n       int num = n - i - 2 * j; n       if (num >= 0 && 2 * num <= a) count++; n     } n   } n   cout << count << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxN = 2e5 + 7; n const long long segN = 8e5 + 7; n const long long moD = 1e9 + 7; n struct query { n   long long t, x, y; n }; n long long n; n long long st[maxN], fi[maxN], sum[segN], deg[maxN], mul[segN], laz[segN], n     val[maxN]; n vector<long long> chi[maxN]; n vector<query> que; n long long wop(long long x, long long y) { n   if (y == 0) return 1; n   long long res = wop(x, y / 2); n   return res * res % moD * (y % 2 == 1 ? x : 1) % moD; n } n long long dfs(long long v) { n   fi[v] = st[v] + 1; n   for (long long u : chi[v]) { n     st[u] = fi[v]; n     fi[v] = dfs(u); n   } n   return fi[v]; n } n void merge(long long x) { sum[x] = (sum[x << 1] + sum[x << 1 | 1]) % moD; } n void upd(long long x, long long val) { n   sum[x] = sum[x] * val % moD; n   mul[x] = mul[x] * val % moD; n   laz[x] = laz[x] * val % moD; n } n void shift(long long x) { n   upd(x << 1, laz[x]); n   upd(x << 1 | 1, laz[x]); n   laz[x] = 1; n } n void add(long long idx, long long val, long long x = 1, long long xl = 0, n          long long xr = n) { n   if (xr - xl == 1) { n     sum[x] = (sum[x] + val) % moD; n     return; n   } n   long long xm = (xl + xr) >> 1; n   shift(x); n   if (idx < xm) n     add(idx, val, x << 1, xl, xm); n   else n     add(idx, val, x << 1 | 1, xm, xr); n   merge(x); n } n void mult(long long ql, long long qr, long long qv, long long x = 1, n           long long xl = 0, long long xr = n) { n   if (xl >= qr || xr <= ql) return; n   if (ql <= xl && qr >= xr) { n     sum[x] = sum[x] * qv % moD; n     laz[x] = laz[x] * qv % moD; n     mul[x] = mul[x] * qv % moD; n     return; n   } n   shift(x); n   long long xm = (xl + xr) >> 1; n   mult(ql, qr, qv, x << 1, xl, xm); n   mult(ql, qr, qv, x << 1 | 1, xm, xr); n   merge(x); n } n long long get_mul(long long idx, long long x = 1, long long xl = 0, n                   long long xr = n) { n   if (xr - xl == 1) return mul[x]; n   long long xm = (xl + xr) >> 1; n   shift(x); n   if (idx < xm) return get_mul(idx, x << 1, xl, xm); n   return get_mul(idx, x << 1 | 1, xm, xr); n } n long long get_sum(long long ql, long long qr, long long x = 1, long long xl = 0, n                   long long xr = n) { n   if (xl >= qr || xr <= ql) return 0; n   if (ql <= xl && qr >= xr) return sum[x]; n   long long xm = (xl + xr) >> 1; n   shift(x); n   long long res = 0; n   res += get_sum(ql, qr, x << 1, xl, xm); n   res += get_sum(ql, qr, x << 1 | 1, xm, xr); n   return res % moD; n } n long long inv(long long x) { return wop(x, moD - 2); } n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   long long q; n   cin >> val[0] >> q; n   que.resize(q); n   for (long long i = 0; i < q; ++i) { n     cin >> que[i].t >> que[i].x; n     que[i].x--; n     if (que[i].t == 1) { n       n++; n       cin >> que[i].y; n       chi[que[i].x].push_back(n); n       val[n] = que[i].y; n     } n   } n   n++; n   for (long long i = 0; i < segN; ++i) laz[i] = mul[i] = 1; n   dfs(0); n   mul[0] = deg[0] = 1; n   add(st[0], val[0]); n   long long c = 0; n   for (long long i = 0; i < q; ++i) { n     long long v = que[i].x; n     if (que[i].t == 1) { n       c++; n       deg[c] = 1; n       mult(st[v], fi[v], inv(deg[v]) * (deg[v] + 1) % moD); n       deg[v]++; n       add(st[c], val[c] * get_mul(st[c]) % moD); n     } else n       cout << get_sum(st[v], fi[v]) * inv(get_mul(st[v])) % moD * deg[v] % moD n            <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int tc; n   cin >> tc; n   while (tc--) { n     int n; n     cin >> n; n     string s, t; n     cin >> s >> t; n     vector<int> v, c; n     for (int i = 1; i < n; i++) { n       if (s[i] != s[i - 1]) v.push_back(i); n     } n     if (s[n - 1] != t[n - 1]) v.push_back(n); n     for (int i = 1; i < n; i++) { n       if (t[i] != t[i - 1]) c.push_back(i); n     } n     reverse(c.begin(), c.end()); n     cout << (int)v.size() + (int)c.size() <<    ; n     for (int val : v) cout << val <<    ; n     for (int val : c) cout << val <<    ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int LIM = 5e+5 + 10; n int sz[LIM]; n int main() { n   ios_base::sync_with_stdio(false); n   int n; n   cin >> n; n   for (int i = 0; i < n; ++i) cin >> sz[i]; n   sort(sz, sz + n); n   int pairs = 0; n   int l = 0; n   int lb = n / 2 + (n % 2); n   int r = lb; n   int rb = n; n   while (l < lb && r < rb) { n     if (sz[l] * 2 <= sz[r]) { n       ++pairs; n       ++l; n       ++r; n     } else { n       ++r; n     } n   } n   cout << n - pairs << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; 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 istream &operator>>(istream &in, vector<T> &v) { n   for (auto &x : v) in >> x; n   return in; n } n template <typename T1, typename T2> n ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) { n   out <<  [  << p.first <<  ,   << p.second <<  ]  n       <<   n ; n   return out; n } n inline int gc() { n   static const int BUF = 1e7; n   static char buf[BUF], *bg = buf + BUF, *ed = bg; n   if (bg == ed) fread(bg = buf, 1, BUF, stdin); n   return *bg++; n } n inline int ri() { n   int x = 0, f = 1, c = gc(); n   for (; c < 48 || c > 57; f = c ==  -  ? -1 : f, c = gc()) n     ; n   for (; c > 47 && c < 58; x = x * 10 + c - 48, c = gc()) n     ; n   return x * f; n } n const double EPS = 1e-10; n const double PI = acos(-1.0); n const long long mod = 1e9 + 7; n const int inf = 0x3f3f3f3f; n const long long infLL = 0x3f3f3f3f3f3f3f3fLL; n const long long ONE = 1; n const int maxN = 2e5 + 7; n int n, m, k, ans; n int a[maxN], sumA[2007]; n pair<int, int> offers[maxN]; n map<int, int> mii; n int dp[2007]; n int getSum(int x, int y) { n   if (x > y) return 0; n   return sumA[y] - sumA[x - 1]; n } n inline bool cmp1(const pair<int, int> &x, const pair<int, int> &y) { n   return x.first < y.first; n } n inline bool cmp2(const pair<int, int> &x, const pair<int, int> &y) { n   return x.first - x.second < y.first - y.second; n } n void CompletePack(int cost, int weight) { n   for (int i = (cost); i <= (k); ++i) { n     int x = dp[i - cost] + getSum(i - (cost - weight) + 1, i); n     dp[i] = min(dp[i], x); n   } n } n int main() { n   std::ios::sync_with_stdio(false); n   std::cin.tie(0); n   ; n   cin >> n >> m >> k; n   for (int i = (1); i <= (n); ++i) cin >> a[i]; n   for (int i = (1); i <= (m); ++i) { n     cin >> offers[i]; n     if (offers[i].first > k) { n       --m; n       --i; n     } else if (mii.find(offers[i].first) != mii.end()) { n       offers[mii[offers[i].first]].second = n           max(offers[mii[offers[i].first]].second, offers[i].second); n       --m; n       --i; n     } else { n       mii[offers[i].first] = i; n     } n   } n   sort(a + 1, a + n + 1); n   n = k; n   for (int i = (1); i <= (n); ++i) { n     dp[i] = dp[i - 1] + a[i]; n     sumA[i] = dp[i]; n   } n   sort(offers + 1, offers + m + 1, cmp1); n   for (int i = (1); i <= (m); ++i) { n     CompletePack(offers[i].first, offers[i].second); n   } n   sort(offers + 1, offers + m + 1, cmp2); n   for (int i = (1); i <= (m); ++i) { n     CompletePack(offers[i].first, offers[i].second); n   } n   cout << dp[k] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a1, a2, k1, k2; n   int n; n   cin >> a1 >> a2 >> k1 >> k2 >> n; n   int n1 = n, n2 = n; n   n1 -= (a1 * (k1 - 1)); n   n1 -= (a2 * (k2 - 1)); n   if (n1 <= 0) n     cout << 0 <<    ; n   else n     cout << n1 <<    ; n   if (k1 > k2) { n     if (n2 < k2) { n       cout << 0; n       return 0; n     } else { n       n2 /= k2; n       if (n2 >= a2) { n         n -= (a2 * k2); n         if (n >= k1) { n           n /= k1; n           if (n >= a1) { n             cout << a1 + a2 <<    ; n           } else { n             cout << a2 + n <<    ; n           } n         } else { n           cout << a2 <<    ; n         } n       } else { n         cout << n2 <<    ; n       } n     } n   } else { n     if (n2 < k1) { n       cout << 0; n       return 0; n     } else { n       n2 /= k1; n       if (n2 >= a1) { n         n -= (a1 * k1); n         if (n >= k2) { n           n /= k2; n           if (n >= a2) { n             cout << a1 + a2 <<    ; n           } else { n             cout << a1 + n <<    ; n           } n         } else { n           cout << a1 <<    ; n         } n       } else { n         cout << n2 <<    ; n       } n     } n   } n   return 0; n } n


#include<iostream> n #include<bits/stdc++.h> n  n using namespace std; n  n #define ll long long n #define pb push_back n #define mp make_pair n #define ff first n #define ss second n #define MOD 1000000007 n  n // void func(){ n  n // } n  n void solution(){ n   ll a,b; cin>>a>>b; n   ll val = abs(a-b); n   if(val==0){ n     cout<< 0 0 <<endl; n     return; n   } n   ll count = min(val-(a%val),a%val); n   cout<<val<<   <<count<<endl; n } n  n int main(){ n  n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n  n   #ifndef ONLINE_JUDGE n   freopen( input.txt ,  r , stdin); n   freopen( output.txt ,  w , stdout); n   #endif n  n   int t; n   cin>>t; n   // func(); n   while(t--){ n     solution(); n   } n  n   return 0; n }


#include <bits/stdc++.h> n using namespace std; n const int nm = 100010; n int n, k; n long long x[nm], y[nm]; n set<pair<long long, int> > ngang, doc; n vector<int> xoa1, xoa2, xoa3, xoa4; n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= n; ++i) { n     int a, b, c, d; n     scanf( %d%d%d%d , &a, &b, &c, &d); n     x[i] = a + c; n     y[i] = b + d; n     ngang.insert(make_pair(y[i], i)); n     doc.insert(make_pair(x[i], i)); n   } n   long long res = LONG_LONG_MAX; n   for (int a = 0; a <= k; ++a) { n     for (int i = 1; i <= a; ++i) { n       int u = ngang.begin()->second; n       xoa1.push_back(u); n       ngang.erase(ngang.begin()); n       doc.erase(make_pair(x[u], u)); n     } n     for (int b = 0; a + b <= k; ++b) { n       for (int i = 1; i <= b; ++i) { n         multiset<pair<long long, int> >::iterator it = ngang.end(); n         it--; n         int u = it->second; n         xoa2.push_back(u); n         ngang.erase(it); n         doc.erase(make_pair(x[u], u)); n       } n       for (int c = 0; a + b + c <= k; ++c) { n         for (int i = 1; i <= c; ++i) { n           int u = doc.begin()->second; n           xoa3.push_back(u); n           doc.erase(doc.begin()); n           ngang.erase(make_pair(y[u], u)); n         } n         int d = k - a - b - c; n         for (int i = 1; i <= d; ++i) { n           multiset<pair<long long, int> >::iterator it = doc.end(); n           it--; n           int u = it->second; n           xoa4.push_back(u); n           doc.erase(it); n           ngang.erase(make_pair(y[u], u)); n         } n         multiset<pair<long long, int> >::iterator it = ngang.end(); n         it--; n         long long A = it->first - ngang.begin()->first; n         if (A & 1) A++; n         if (A == 0) A = 2; n         it = doc.end(); n         it--; n         long long B = it->first - doc.begin()->first; n         if (B & 1) B++; n         if (B == 0) B = 2; n         res = min(res, A * B); n         for (int i = int(xoa4.size()) - 1; i >= 0; --i) { n           int u = xoa4[i]; n           xoa4.pop_back(); n           doc.insert(make_pair(x[u], u)); n           ngang.insert(make_pair(y[u], u)); n         } n         for (int i = int(xoa3.size()) - 1; i >= 0; --i) { n           int u = xoa3[i]; n           xoa3.pop_back(); n           doc.insert(make_pair(x[u], u)); n           ngang.insert(make_pair(y[u], u)); n         } n       } n       for (int i = int(xoa2.size()) - 1; i >= 0; --i) { n         int u = xoa2[i]; n         xoa2.pop_back(); n         doc.insert(make_pair(x[u], u)); n         ngang.insert(make_pair(y[u], u)); n       } n     } n     for (int i = int(xoa1.size()) - 1; i >= 0; --i) { n       int u = xoa1[i]; n       xoa1.pop_back(); n       doc.insert(make_pair(x[u], u)); n       ngang.insert(make_pair(y[u], u)); n     } n   } n   printf( %I64d n , res / 4); n } n


#include <bits/stdc++.h> n using namespace std; n int used[111111]; n multiset<int> g[111111]; n multiset<int> vertex; n vector<int> ans; n void dfs(int v) { n   used[v] = 1; n   vertex.erase(v); n   ans.push_back(v); n   for (auto i = g[v].begin(); i != g[v].end(); ++i) n     if (!used[*i]) vertex.insert(*i); n   if (vertex.size()) dfs(*vertex.begin()); n } n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     int x, y; n     cin >> x >> y; n     g[x - 1].insert(y - 1); n     g[y - 1].insert(x - 1); n   } n   dfs(0); n   for (int i = 0; i < ans.size(); i++) cout << ans[i] + 1 <<    ; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int N = 200005; n char a[N], b[N]; n string arrange(string s) { n   int n = s.size(); n   if (n & 1) n     return s; n   else { n     int m = n / 2; n     string s1 = s.substr(0, m), s2 = s.substr(m, m); n     s1 = arrange(s1); n     s2 = arrange(s2); n     if (s1.compare(s2) <= 0) n       return s1 + s2; n     else n       return s2 + s1; n   } n } n int main() { n   scanf( %s , a); n   scanf( %s , b); n   const char *ans = arrange(a) == arrange(b) ?  YES  :  NO ; n   printf( %s n , ans); n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:16777216 ) n using namespace std; n int a[2 * 100010] = {0}; n int check(int x, int n) { n   if (x == 1) return 0; n   int cur = 0, ans = 0; n   while (cur < a[n - 1]) { n     cur += x; n     int pos = lower_bound(a, a + n, cur) - a; n     if (pos > 0 && a[pos - 1] >= x) ans = max(ans, a[pos - 1] % x); n   } n   return ans; n } n int Solve(int n) { n   int ans = 0, m = 1; n   sort(a, a + n); n   for (int i = 1; i < n; i++) n     if (a[m - 1] != a[i]) a[m++] = a[i]; n   for (int i = 0; i < m; i++) ans = max(ans, check(a[i], m)); n   return ans; n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %d , &a[i]); n   printf( %d n , Solve(n)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x7f7f7f7f; n int BigMod(long long int B, long long int P, long long int M) { n   long long int R = 1; n   while (P > 0) { n     if (P % 2 == 1) R = (R * B) % M; n     P /= 2; n     B = (B * B) % M; n   } n   return (int)R; n } n long long int maxDivide(long long int a, long long int b) { n   while (a % b == 0) a = a / b; n   return a; n } n long long int isUgly(long long int no) { n   no = maxDivide(no, 2); n   no = maxDivide(no, 3); n   no = maxDivide(no, 5); n   return (no == 1) ? 1 : 0; n } n long long int myXOR(long long int x, long long int y) { n   long long int res = 0; n   for (long long int i = 31; i >= 0; i--) { n     bool b1 = x & (1 << i); n     bool b2 = y & (1 << i); n     bool xoredBit = (b1 & b2) ? 0 : (b1 | b2); n     res <<= 1; n     res |= xoredBit; n   } n   return res; n } n long long int ar[110]; n int main() { n   long long int n, m, a, b, c, x, y; n   cin >> n >> m; n   x = 0; n   for (long long int i = 1; i <= n; i++) { n     cin >> ar[i]; n   } n   y = 0; n   for (long long int i = 1; i <= m; i++) { n     cin >> a >> b; n     x = 0; n     for (long long int j = a; j <= b; j++) { n       x += ar[j]; n     } n     if (x > 0) y += x; n   } n   cout << y << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int h1, m1, h2, m2, s1, s2, h, m; n   scanf( %d:%d , &h1, &m1); n   scanf( %d:%d , &h2, &m2); n   s1 = h1 * 60 + m1; n   s2 = h2 * 60 + m2; n   m = (s1 + s2) / 2; n   h = m / 60; n   m = m % 60; n   printf( %02d:%02d n , h, m); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   { n     int s, v1, v2, t1, t2; n     cin >> s >> v1 >> v2 >> t1 >> t2; n     int time1, time2; n     time1 = (s * v1) + (2 * t1); n     time2 = (s * v2) + (2 * t2); n     if (time1 < time2) n       cout <<  First  << endl; n     else if (time2 < time1) n       cout <<  Second  << endl; n     else n       cout <<  Friendship  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e18; n const int N = 1e6 + 20; n vector<int> v[N]; n map<int, int> mp, ml, mr; n long long n, m, k, a[N], b[N], f[N]; n int num[N]; n long long did[N]; n string s; n long long s1, s2, ans, flag, tot, t, sum; n int cnt; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n >> m >> k; n   long long x; n   for (int i = 0; i < m; i++) { n     cin >> x; n     if (x == 0) return cout << -1, 0; n     did[x] = 1; n   } n   for (int i = 1; i <= k; i++) cin >> a[i]; n   int cnt = 0; n   for (int i = 0; i <= n; i++) { n     if (did[i]) n       num[i] = num[i - 1] + 1; n     else n       num[i] = 0; n     cnt = max(cnt, num[i]); n   } n   long long ans = inf; n   for (int i = cnt + 1; i <= k; i++) { n     long long sum = 0; n     for (int j = 0; j < n; j += i) { n       if (did[j]) { n         j -= num[j]; n       } n       sum++; n     } n     ans = min(ans, a[i] * sum); n   } n   if (ans >= inf) n     cout << -1; n   else n     cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, q, t, x, y, b, c, d; n string s1, s2; n long long a[3]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> s1 >> s2; n     int l1 = s1.length(); n     int l2 = s2.length(); n     int j = 0, k = 0; n     int ok = 1; n     int lastok = -1; n     while (j < l1 && k < l2) { n       if (s1[j] == s2[k]) { n         j++; n         k++; n         lastok++; n       } else if (k && s2[k] == s2[k - 1]) { n         int tmp = k; n         while (tmp < l2 && s2[tmp] == s2[k]) tmp++; n         if (tmp == l2) { n           ok = 0; n           break; n         } n         lastok = tmp - 1; n         k = tmp; n       } else if (lastok == k - 1) { n         ok = 0; n         break; n       } n     } n     if (j < l1) ok = 0; n     while (k < l2) { n       if (k && s2[k] != s2[k - 1]) { n         ok = 0; n         break; n       } n       k++; n     } n     cout << (ok ?  YES  :  NO ) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 500010; n int n, m; n int pos[maxn]; n int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; n inline void read(int &k) { n   int f = 1; n   k = 0; n   char c = getchar(); n   while (c <  0  || c >  9 ) c ==  -  && (f = -1), c = getchar(); n   while (c <=  9  && c >=  0 ) k = k * 10 + c -  0 , c = getchar(); n   k *= f; n } n bool check(int i, int j) { n   int x = (i - 1) / m + 1, y = (i - 1) % m + 1, x2 = (j - 1) / m + 1, n       y2 = (j - 1) % m + 1; n   for (int k = 0; k < 4; k++) n     if (x + dx[k] == x2 && y + dy[k] == y2) return 1; n   return 0; n } n bool dfs(int i) { n   if (i == n * m + 1) return 1; n   int x = (i - 1) / m + 1, y = (i - 1) % m + 1; n   for (int j = i; j <= n * m; j++) { n     swap(pos[i], pos[j]); n     if (x != 1 && check(pos[i], pos[(x - 2) * m + y])) continue; n     if (y != 1 && check(pos[i], pos[(x - 1) * m + y - 1])) continue; n     if (dfs(i + 1)) return 1; n     swap(pos[i], pos[j]); n   } n   return 0; n } n int main() { n   read(n); n   read(m); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) pos[(i - 1) * m + j] = (i - 1) * m + j; n   if (!dfs(1)) return puts( NO ), 0; n   puts( YES ); n   for (int i = 1; i <= n; i++, puts(  )) n     for (int j = 1; j <= m; j++) printf( %d  , pos[(i - 1) * m + j]); n } n


#include <bits/stdc++.h> n using namespace std; n int dx[] = {0, 0, -1, 1}; n int dy[] = {1, -1, 0, 0}; n int main() { n   int n; n   char mp[100][100]; n   cin >> n; n   for (int i = 0; i < n; ++i) cin >> mp[i]; n   auto isin = [&](int x) { return x >= 0 && x < n; }; n   auto isok = [&](int x, int y) { n     for (int i = 0; i < 4; ++i) { n       if (isin(x + dx[i]) && isin(y + dy[i])) { n         if (mp[x + dx[i]][y + dy[i]] !=  . ) return 0; n       } else n         return 0; n     } n     mp[x][y] =  # ; n     for (int i = 0; i < 4; ++i) { n       mp[x + dx[i]][y + dy[i]] =  # ; n     } n     return 1; n   }; n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < n; ++j) { n       if (mp[i][j] ==  . ) { n         isok(i, j); n       } n     } n   } n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < n; ++j) { n       if (mp[i][j] ==  . ) { n         cout <<  NO  << endl; n         return 0; n       } n     } n   } n   cout <<  YES  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5005; n vector<int> adj[N]; n bool visited[N]; n bool reach[N]; n pair<int, int> has[N]; n int cnt = 0; n void dfs(int s) { n   if (!visited[s]) { n     visited[s] = 1; n     reach[s] = 1; n     for (int i = 0; i < adj[s].size(); i++) { n       dfs(adj[s][i]); n     } n   } n } n void dfs2(int s, int a) { n   if (!visited[s]) { n     visited[s] = 1; n     if (reach[s] == 0) has[a].first++; n     for (int i = 0; i < adj[s].size(); i++) { n       dfs2(adj[s][i], a); n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n, m, s; n   cin >> n >> m >> s; n   s--; n   for (int i = 0; i < m; i++) { n     int a, b; n     cin >> a >> b; n     a--; n     b--; n     adj[a].push_back(b); n   } n   dfs(s); n   for (int i = 0; i < n; i++) { n     has[i].second = i; n   } n   for (int i = 0; i < n; i++) { n     if (!reach[i]) { n       memset(visited, 0, sizeof(visited)); n       dfs2(i, i); n     } n   } n   sort(has, has + N); n   reverse(has, has + N); n   int ans = 0; n   cnt = 0; n   memset(visited, 0, sizeof(visited)); n   for (int i = 0; i < n; i++) { n     if (!reach[has[i].second]) { n       dfs(has[i].second); n       memset(visited, 0, sizeof(visited)); n       ans++; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<unsigned long long> v; n   char x2[] =  47 ; n   do { n     v.push_back(stoi(x2)); n   } while (next_permutation(x2, x2 + 2)); n   char x4[] =  4477 ; n   do { n     v.push_back(stoi(x4)); n   } while (next_permutation(x4, x4 + 4)); n   char x6[] =  444777 ; n   do { n     v.push_back(stoi(x6)); n   } while (next_permutation(x6, x6 + 6)); n   char x8[] =  44447777 ; n   do { n     v.push_back(stoi(x8)); n   } while (next_permutation(x8, x8 + 8)); n   v.push_back(4444477777); n   sort(v.begin(), v.end()); n   string s; n   cin >> s; n   unsigned long long q = stoi(s); n   if (q <= v[0]) { n     cout << v[0]; n     return 0; n   } else n     for (int i = 0; i < v.size() - 1; i++) n       if (q == v[i + 1] || (q > v[i] && q < v[i + 1])) { n         cout << v[i + 1]; n         return 0; n       } n   cout << v[98]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char a[100][1000] = {0}; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   long long int t; n   cin >> t; n   while (t--) { n     long long int n, m, x, y; n     cin >> n >> m >> x >> y; n     for (long long int i = 1; i <= n; i++) { n       for (long long int j = 1; j <= m; j++) { n         cin >> a[i][j]; n       } n     } n     long long int ans = 0; 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] ==  . ) { n           long long int pos = j; n           for (long long int k = j; k <= m; k++) { n             if (a[i][k] ==  . ) { n               pos = k; n             } else { n               break; n             } n           } n           long long int temp = pos - j + 1; n           ans += min(temp * x, (temp / 2) * y + x * (temp % 2 == 1)); n           j = pos; n         } n       } n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int inf = int(1e9); n const int mod = inf + 7; n const double PI = acos(-1.0); n using namespace std; n const int N = 1e5 + 155; n template <typename T> n inline void read(T& x) { n   x = 0; n   int f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   x *= f; n } n string toForm(char c, bool ok) { n   string ans =   ; n   ans += char(60); n   if (!ok) ans += char(47); n   ans += (c); n   ans += char(62); n   return ans; n } n void solve() { n   string s; n   cin >> s; n   int cnt = 0; n   for (int i = 1; i < s.size(); i++) { n     if (s[i] !=  <  && s[i] !=  >  && s[i] !=  / ) { n       if (s[i - 1] !=  / ) { n         for (int i = 0; i < cnt; ++i) cout <<     ; n         cout << toForm(s[i], true); n         cout <<   n ; n         cnt++; n       } else { n         for (int i = 0; i < cnt - 1; ++i) cout <<     ; n         cout << toForm(s[i], false); n         cout <<   n ; n         cnt--; n       } n     } n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t = 1; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 111111; n const int oo = (int)(1e9); n int MOD = 1000000007; n const long double PI = 3.141592653589793; n template <typename TT> n void read(TT &x) { n   char ch; n   for (ch = getchar(); ch >  9  || ch <  0 ; ch = getchar()) n     ; n   for (x = 0; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch - 48; n } n vector<pair<int, int> > A[2]; n int n, a[111111], v[111111], nt[111111]; n void work(vector<pair<int, int> > &B, vector<pair<int, int> > &C) { n   C.clear(); n   sort(B.begin(), B.end()); n   for (int i = B.size() - 1; i >= 0; i--) { n     int x = B[i].first, y = B[i].second; n     if (v[x] + v[y] > 0) continue; n     v[y] = 1; n     while (v[nt[x]]) nt[x] = nt[nt[x]]; n     if (nt[x] < n && a[x] > a[nt[x]]) C.push_back(make_pair(x, nt[x])); n   } n } n void Init() { n   scanf( %d , &n); n   ; n   for (int i = 0; i < n; i++) scanf( %d , &a[i]); n   ; n   for (int i = 0; i < n; i++) { n     nt[i] = i + 1; n     if (nt[i] < n && a[i] > a[nt[i]]) A[0].push_back(make_pair(i, nt[i])); n   } n   int k = 0, ans = 0; n   memset(v, 0, sizeof(v)); n   ; n   while (A[k].size()) { n     ans++; n     work(A[k], A[1 - k]); n     k = 1 - k; n   } n   printf( %d , ans); n   ; n } n int main() { n   Init(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 15; n vector<int> g[N]; n int n, m, b[N], r[N], a[N], res; n void dfs(int v, int pa) { n   if (a[v] == 1) n     r[v]++; n   else if (a[v] == 2) n     b[v]++; n   for (int i : g[v]) { n     if (i == pa) continue; n     dfs(i, v); n     b[v] += b[i]; n     r[v] += r[i]; n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < n - 1; i++) { n     int x, y; n     cin >> x >> y; n     x--, y--; n     g[x].push_back(y); n     g[y].push_back(x); n   } n   dfs(0, -1); n   for (int i = 1; i < n; i++) { n     if (b[i] && r[i]) continue; n     int blue = b[0] - b[i], red = r[0] - r[i]; n     if (((!blue) && red) || (blue && (!red))) { n       res++; n     } n   } n   cout << res << endl; n } n


#include <bits/stdc++.h> n int pos = 1 << 17; n char buf[1 << 17]; n inline char nextch() { n   if (pos == 1 << 17) fread(buf, 1 << 17, 1, stdin), pos = 0; n   return buf[pos++]; n } n inline int read() { n   char ch; n   while (!isdigit(ch = nextch())) n     ; n   int x = ch -  0 ; n   while (isdigit(ch = nextch())) x = 10 * x + ch -  0 ; n   return x; n } n const int N = 1 << 17; n int ab[132000], de[132000], fr[132000], fib[132000]; n inline int lgput(int a, int n) { n   int r = 1; n   while (n) { n     if (n % 2) r = 1LL * r * a % 1000000007; n     n /= 2; n     a = 1LL * a * a % 1000000007; n   } n   return r; n } n void fwht(int *data, int dim) { n   for (int len = 1; 2 * len <= dim; len <<= 1) { n     for (int i = 0; i < dim; i += 2 * len) { n       for (int j = 0; j < len; j++) { n         int a = data[i + j]; n         int b = data[i + j + len]; n         data[i + j] = a + b; n         if (data[i + j] >= 1000000007) data[i + j] -= 1000000007; n         data[i + j + len] = a - b; n         if (data[i + j + len] < 0) data[i + j + len] += 1000000007; n       } n     } n   } n } n void to_transform(int dim, int *data) { n   int len, i, j, u, v; n   for (len = 1; 2 * len <= dim; len <<= 1) { n     for (i = 0; i < dim; i += 2 * len) { n       for (j = 0; j < len; j++) { n         u = data[i + j]; n         v = data[i + len + j]; n         data[i + j] = v; n         data[i + len + j] = u + v; n         if (data[i + len + j] >= 1000000007) data[i + len + j] -= 1000000007; n       } n     } n   } n } n void inv_transform(int dim, int *data) { n   int len, i, j, u, v; n   for (len = 1; 2 * len <= dim; len <<= 1) { n     for (i = 0; i < dim; i += 2 * len) { n       for (j = 0; j < len; j++) { n         u = data[i + j]; n         v = data[i + len + j]; n         data[i + j] = v - u; n         data[i + len + j] = u; n         if (data[i + j] < 0) data[i + j] += 1000000007; n       } n     } n   } n } n int main() { n   int n = read(); n   for (int i = 0; i < n; i++) fr[read()]++; n   for (int i = 0; i < N; i++) { n     for (int j = i; j; j = (j - 1) & i) n       ab[i] = (ab[i] + 1LL * fr[j] * fr[i ^ j]) % 1000000007; n     ab[i] = (ab[i] + 1LL * fr[0] * fr[i]) % 1000000007; n   } n   for (int i = 0; i < N; i++) de[i] = fr[i]; n   fwht(de, N); n   for (int i = 0; i < N; i++) de[i] = 1LL * de[i] * de[i] % 1000000007; n   fwht(de, N); n   int inv = lgput(N, 1000000007 - 2); n   for (int i = 0; i < N; i++) de[i] = 1LL * de[i] * inv % 1000000007; n   fib[1] = 1; n   for (int i = 2; i < N; i++) { n     fib[i] = fib[i - 1] + fib[i - 2]; n     if (fib[i] >= 1000000007) fib[i] -= 1000000007; n   } n   for (int i = 0; i < N; i++) ab[i] = 1LL * ab[i] * fib[i] % 1000000007; n   to_transform(N, ab); n   for (int i = 0; i < N; i++) fr[i] = 1LL * fr[i] * fib[i] % 1000000007; n   to_transform(N, fr); n   for (int i = 0; i < N; i++) ab[i] = 1LL * ab[i] * fr[i] % 1000000007; n   inv_transform(N, ab); n   to_transform(N, ab); n   for (int i = 0; i < N; i++) de[i] = 1LL * de[i] * fib[i] % 1000000007; n   to_transform(N, de); n   for (int i = 0; i < N; i++) ab[i] = 1LL * ab[i] * de[i] % 1000000007; n   inv_transform(N, ab); n   int ans = 0; n   for (int i = 1; i < N; i++) n     if (i - (i & (-i)) == 0) ans = (ans + ab[i]) % 1000000007; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n inline int read() { n   int f = 1, x = 0; n   char ch = getchar(); n   while (!(ch >=  0  && ch <=  9 )) { n     if (ch ==  - ) f *= -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return f * x; n } n int dx[8] = {1, 1, -1, -1, 2, 2, -2, -2}; n int dy[8] = {2, -2, 2, -2, 1, -1, 1, -1}; n struct Point { n   int x, y, c, fa; n   friend bool operator==(Point a, Point b) { n     return (a.x == b.x && a.y == b.y); n   } n } w[2], b[2], other, list[4][1000 * 1000 + 1]; n void readother() { std::cin >> other.x >> other.y; } n bool check(Point a, Point b) { n   int x = abs(a.x - b.x), y = abs(a.y - b.y); n   if (x <= 2 && y <= 2 && x + y == 3) { n     printf( %d %d n , b.x, b.y); n     return true; n   } n   return false; n } n int otherx, othery; n bool bk = false; n void printlist(int k, Point a) { n   if (a.fa == -1 || bk == true) return; n   if (a.fa != 1) printlist(k, list[k][a.fa]); n   if (check(a, other) == true) bk = true; n   if (bk == true) return; n   printf( %d %d n , a.x, a.y); n   readother(); n } n int n, m, head, tail, v[4][1000 + 1][1000 + 1]; n void closer(int k, Point st, Point ed) { n   Point a, b; n   head = tail = 1; n   memset(v[k], 0, sizeof(v[k])); n   v[k][st.x][st.y] = head; n   list[k][head] = st, list[k][head].c = 0, list[k][head].fa = -1; n   if (st == ed) return; n   while (head <= tail) { n     a = list[k][head]; n     for (int i = 0; i < 8; i++) { n       b = a, b.x += dx[i], b.y += dy[i], b.c++; n       if (b.x < 1 || b.y < 1 || b.x > n || b.y > m || v[k][b.x][b.y] != 0) n         continue; n       tail++; n       v[k][b.x][b.y] = tail; n       b.fa = head; n       list[k][tail] = b; n       if (b == ed) return; n     } n     head++; n   } n } n void printlast(int k) { n   Point a; n   if (k == 0) { n     a = b[0]; n     if (check(a, other) == false) { n       a = b[0], a.x -= 1, a.y += 2; n       printf( %d %d n , a.x, a.y), readother(); n     } else n       return; n     if (check(a, other) == false) { n       a = b[0], a.x -= 3, a.y += 1; n       printf( %d %d n , a.x, a.y), readother(); n     } else n       return; n     if (check(a, other) == false) { n       a = b[0], a.x -= 1; n       printf( %d %d n , a.x, a.y), readother(); n     } else n       return; n   } else { n     a = w[0]; n     if (check(a, other) == false) { n       a = w[0], a.x += 1, a.y += 2; n       printf( %d %d n , a.x, a.y), readother(); n     } else n       return; n     if (check(a, other) == false) { n       a = w[0], a.x += 3, a.y += 1; n       printf( %d %d n , a.x, a.y), readother(); n     } else n       return; n     if (check(a, other) == false) { n       a = w[0], a.x += 1; n       printf( %d %d n , a.x, a.y), readother(); n     } else n       return; n   } n } n bool choose; n int main() { n   n = read(), m = read(), w[1].x = read(), w[1].y = read(), b[1].x = read(), n   b[1].y = read(); n   w[0].x = n / 2, w[0].y = m / 2, b[0].x = n / 2 + 1, b[0].y = m / 2; n   closer(0, w[1], w[0]), closer(1, b[1], b[0]); n   closer(2, w[1], b[0]); n   closer(3, b[1], w[0]); n   if ((w[1].x + w[1].y) % 2 != (b[1].x + b[1].y) % 2) { n     if (list[0][v[0][w[0].x][w[0].y]].c <= list[1][v[1][b[0].x][b[0].y]].c) n       printf( WHITE n ), other = b[1], n                          printlist(0, list[0][v[0][w[0].x][w[0].y]]); n     else if (list[2][v[2][b[0].x][b[0].y]].c >= n              list[1][v[1][b[0].x][b[0].y]].c + 2) n       printf( BLACK n ), readother(), n           printlist(1, list[1][v[1][b[0].x][b[0].y]]); n     else n       printf( WHITE n ), other = b[1], n                          printlist(2, list[2][v[2][b[0].x][b[0].y]]), n                          printlast(0); n   } else { n     if (list[1][v[1][b[0].x][b[0].y]].c < list[0][v[0][w[0].x][w[0].y]].c) n       printf( BLACK n ), readother(), n           printlist(1, list[1][v[1][b[0].x][b[0].y]]); n     else if (list[3][v[3][w[0].x][w[0].y]].c > list[0][v[0][w[0].x][w[0].y]].c) n       printf( WHITE n ), other = b[1], n                          printlist(0, list[0][v[0][w[0].x][w[0].y]]); n     else n       printf( BLACK n ), readother(), n           printlist(3, list[3][v[3][w[0].x][w[0].y]]), printlast(1); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int modi = 1e9 + 7; n unsigned long long gcd(unsigned long long a, unsigned long long b) { n   return !b ? a : gcd(b, a % b); n } n int main() { n   ios::sync_with_stdio(false); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     int x; n     cin >> x; n     string str =   ; n     if (x % 2 == 1) { n       str +=  7 ; n       x -= 3; n     } n     while (x > 1) { n       str +=  1 ; n       x -= 2; n     } n     cout << str << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxx = 800010; n int t, n, m, k, b, u; n int ans = 0, total = 0, cnt = 0; n int a[maxx], sum[maxx]; n struct no { n   int num, l, r; n   bool operator<(const no &X) const { return r < X.r; } n }; n priority_queue<no> q; n struct node { n   int num; n   int l; n   int r; n } s[maxx]; n bool cmp(node a, node b) { return a.l < b.l; } n int main() { n   scanf( %d%d , &n, &k); n   for (register int i = 1; i <= n; i++) { n     scanf( %d%d , &s[i].l, &s[i].r); n     sum[s[i].l]++; n     sum[s[i].r + 1]--; n     s[i].num = i; n   } n   sort(s + 1, s + n + 1, cmp); n   cnt = 1; n   for (register int i = 1; i <= 200000; i++) { n     while (cnt <= n && s[cnt].l <= i) { n       q.push(no{s[cnt].num, s[cnt].l, s[cnt].r}); n       cnt++; n     } n     sum[i] += sum[i - 1]; n     while (sum[i] > k) { n       a[++total] = q.top().num; n       sum[i]--; n       sum[q.top().r + 1]++; n       q.pop(); n     } n   } n   sort(a + 1, a + total + 1); n   printf( %d n , total); n   for (register int i = 1; i <= total; i++) printf( %d  , a[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long min(long long a, long long b) { return (a < b) ? a : b; } n long long max(long long a, long long b) { return (a > b) ? a : b; } n int main() { n   long long t, n, m, i, j, k = 0, p = 0; n   cin >> n; n   string s, q, r; n   cin >> s; n   p = s.size(); n   if (p % n != 0) { n     for (i = 0; i < p / n + 1; i++) { n       r +=  1 ; n       for (j = 1; j < n; j++) r +=  0 ; n     } n     cout << r << endl; n     return 0; n   } n   for (i = 0; i < p; i++) n     if (s[i] !=  9 ) break; n   if (i == p) { n     for (i = 0; i < p + n; i++) { n       if (i % n == 0) n         r +=  1 ; n       else n         r +=  0 ; n     } n     cout << r << endl; n     return 0; n   } n   for (i = n; i < p; i++) { n     if (s[i] > s[i % n]) break; n     if (s[i] < s[i % n]) break; n   } n   if (i == p || s[i] > s[i % n]) { n     k = 1; n     for (i = n - 1; i >= 0; i--) { n       m = (s[i] - 48 + k); n       k = m / 10; n       s[i] = m % 10 + 48; n       if (k == 0) break; n     } n     for (i = n; i < p; i++) s[i] = s[i % n]; n     cout << s << endl; n     return 0; n   } n   for (i = n; i < p; i++) s[i] = s[i % n]; n   cout << s << endl; n } n


#include <bits/stdc++.h> n using namespace std; n void Solve() { n   long long T; n   cin >> T; n   while (T--) { n     long long b, w; n     cin >> b >> w; n     if (b > w * 3 + 1 || w > b * 3 + 1) { n       cout <<  NO n ; n       continue; n     } n     cout <<  YES n ; n     long long x = 2, y = 2; n     while (b && w) { n       cout << x <<     << y++ <<   n ; n       cout << x <<     << y++ <<   n ; n       b--, w--; n     } n     if (b) { n       cout <<  2 1 n ; n       b--; n       x = 1, y = 2; n       while (b) { n         cout << x <<     << y <<   n ; n         b--; n         if (b) { n           cout << x + 2 <<     << y <<   n ; n           b--; n         } n         y += 2; n       } n     } n     if (w) { n       cout << x <<     << y <<   n ; n       w--; n       x = 1, y = 3; n       while (w) { n         cout << x <<     << y <<   n ; n         w--; n         if (w) { n           cout << x + 2 <<     << y <<   n ; n           w--; n         } n         y += 2; n       } n     } n   } n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   Solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<string, string>> taken; n int main() { n   int n; n   scanf( %d , &n); n   int ans = 0; n   for (int i = 1; i <= n; ++i) { n     string s, t; n     cin >> s >> t; n     bool flag = 1; n     for (auto [x, y] : taken) { n       if (x == s && y == t) { n         flag = 0; n         break; n       } n     } n     if (flag) { n       ans++; n       taken.push_back({s, t}); n     } n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long m, s = -1, l = 1, r = 1e18; n   cin >> m; n   while (l <= r) { n     long long as = 0, i; n     long long mid = (l + r) / 2; n     for (i = 2; i * i * i <= mid; i++) as += mid / (i * i * i); n     if (as == m) s = mid; n     if (as >= m) n       r = mid - 1; n     else n       l = mid + 1; n   } n   cout << s; n } n


#include <bits/stdc++.h> n using namespace std; n struct point { n   long long x, y; n }; n point p[345678]; n vector<point> important, ugly; n vector<int> ilist; n int n; n long long ans[345678]; n long long distance(int i, int j) { n   return llabs(important[i].x - important[j].x) + n          llabs(important[i].y - important[j].y); n } n long long distance(point p, point q) { n   return llabs(p.x - q.x) + llabs(p.y - q.y); n } n long long dp[15][15][15][15]; n long long lovetourist(int i, int f, int l, int k) { n   if (k == 0) return distance(f, l); n   if (i == important.size()) return -1e17; n   if (dp[i + 1][f + 1][l + 1][k + 1] != -1) n     return dp[i + 1][f + 1][l + 1][k + 1]; n   long long ret = lovetourist(i + 1, f, l, k); n   if (f == -1) n     ret = max(ret, lovetourist(i + 1, i, i, k - 1)); n   else n     ret = max(ret, distance(l, i) + lovetourist(i + 1, f, i, k - 1)); n   return dp[i + 1][f + 1][l + 1][k + 1] = ret; n } n long long respecttourist() { n   long long res = -1e17; n   for (int i = 0; i < ilist.size(); i++) { n     for (int j = i + 1; j < ilist.size(); j++) { n       for (int k = 1; k <= n; k++) { n         if (k == ilist[i] || k == ilist[j]) continue; n         res = max(res, distance(p[ilist[i]], p[ilist[j]]) + n                            distance(p[ilist[i]], p[k]) + n                            distance(p[ilist[j]], p[k])); n       } n     } n   } n   return res; n } n int main() { n   cin >> n; n   long long minx, maxx, miny, maxy, sum = 0; n   for (int i = 1; i <= n; i++) { n     cin >> p[i].x >> p[i].y; n     if (i == 1) { n       minx = p[i].x; n       maxx = p[i].x; n       miny = p[i].y; n       maxy = p[i].y; n     } n     minx = min(minx, p[i].x); n     maxx = max(maxx, p[i].x); n     miny = min(miny, p[i].y); n     maxy = max(maxy, p[i].y); n   } n   p[n + 1] = p[1]; n   for (int i = 1; i <= n; i++) { n     sum += llabs(p[i].x - p[i + 1].x) + llabs(p[i].y - p[i + 1].y); n     ilist.push_back(i); n     if (p[i].x == minx) n       important.push_back(p[i]); n     else if (p[i].x == maxx) n       important.push_back(p[i]); n     else if (p[i].y == miny) n       important.push_back(p[i]); n     else if (p[i].y == maxy) n       important.push_back(p[i]); n     else { n       ugly.push_back(p[i]); n       ilist.pop_back(); n     } n   } n   memset(dp, -1, sizeof(dp)); n   long long res = lovetourist(0, -1, -1, important.size()); n   assert(2 <= important.size() && important.size() <= 8); n   int k = n; n   while (!ugly.empty()) { n     ans[k--] = res; n     ugly.pop_back(); n   } n   for (int i = important.size(); i >= 3; i--) n     ans[k--] = lovetourist(0, -1, -1, i); n   ans[3] = max(ans[3], respecttourist()); n   for (int i = 3; i <= n; i++) cout << ans[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n struct str { n   char s[110]; n } p[110]; n int n; n int ans[26], connect[26][26], v, e; n int toposort(int n, int mat[][26], int* ret) { n   int d[26], i, j, k; n   for (i = 0; i < n; i++) n     for (d[i] = j = 0; j < n; d[i] += mat[j++][i]) n       ; n   for (k = 0; k < n; ret[k++] = i) { n     for (i = 0; d[i] && i < n; i++) n       ; n     if (i == n) return 0; n     for (d[i] = -1, j = 0; j < n; j++) d[j] -= mat[i][j]; n   } n   return 1; n } n int main() { n   int i, j; n   bool ok = true; n   scanf( %d , &n); n   memset(connect, 0, sizeof(connect)); n   for (i = 0; i < n; ++i) { n     scanf( %s , p[i].s); n     if (i > 0 && ok) { n       for (j = 0; p[i].s[j] && p[i - 1].s[j]; ++j) { n         if (p[i].s[j] != p[i - 1].s[j]) { n           connect[p[i - 1].s[j] -  a ][p[i].s[j] -  a ] = 1; n           break; n         } n       } n       if (strlen(p[i].s) < strlen(p[i - 1].s) && j == strlen(p[i].s)) n         ok = false; n     } n   } n   if (ok && toposort(26, connect, ans)) { n     for (i = 0; i < 25; ++i) { n       printf( %c , ans[i] +  a ); n     } n     printf( %c n , ans[i] +  a ); n   } else { n     puts( Impossible ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, q, k, a[110000], cnt, tmp[110000]; n int edgenum = 1, vet[610000], val[610000], Next[610000], Head[110000]; n double ang[610000]; n bool vis[110000]; n map<pair<int, int>, int> rnk; n vector<long long> sum[110000]; n struct node { n   int x, y; n   node() {} n   node(int _x, int _y) : x(_x), y(_y) {} n } p[110000]; n node operator-(const node &a, const node &b) { n   return node(a.x - b.x, a.y - b.y); n } n char Getchar() { n   static char now[1 << 20], *S, *T; n   if (T == S) { n     T = (S = now) + fread(now, 1, 1 << 20, stdin); n     if (T == S) return EOF; n   } n   return *S++; n } n int read() { n   int x = 0, f = 1; n   char ch = Getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = Getchar(); n   } n   while (ch <=  9  && ch >=  0 ) x = x * 10 + ch -  0 , ch = Getchar(); n   return x * f; n } n void addedge(int u, int v) { n   vet[++edgenum] = v; n   Next[edgenum] = Head[u]; n   Head[u] = edgenum; n } n int dfs(int u) { n   vis[u] = true; n   int flow = 1, tmp; n   for (int e = Head[u]; e; e = Next[e]) n     if (!vis[vet[e]]) { n       tmp = dfs(vet[e]); n       val[e] += tmp; n       val[e ^ 1] -= tmp; n       flow += tmp; n     } n   return flow; n } n inline bool cmp(int a, int b) { return ang[a] < ang[b]; } n inline long long cross(node x, node y) { n   return 1ll * x.x * y.y - 1ll * x.y * y.x; n } n int main() { n   n = read(); n   m = read(); n   int u, v; n   for (int i = 1; i <= m; i++) { n     u = read(); n     v = read(); n     addedge(u, v); n     addedge(v, u); n   } n   for (int i = 1; i <= n; i++) p[i].x = read(), p[i].y = read(); n   int rt = 1; n   for (int i = 2; i <= n; i++) n     if (p[i].x < p[rt].x) rt = i; n   dfs(rt); n   for (int u = 1; u <= n; u++) { n     cnt = 0; n     for (int e = Head[u]; e; e = Next[e]) { n       tmp[++cnt] = e; n       v = vet[e]; n       ang[e] = atan2(p[v].y - p[u].y, p[v].x - p[u].x); n     } n     sort(tmp + 1, tmp + cnt + 1, cmp); n     sum[u].push_back(0); n     for (int i = 1; i <= cnt; i++) { n       rnk[pair<int, int>(u, vet[tmp[i]])] = i; n       sum[u].push_back(sum[u].back() + val[tmp[i]]); n     } n   } n   q = read(); n   int l, r; n   while (q--) { n     k = read(); n     for (int i = 1; i <= k; i++) a[i] = read(); n     long long s = 0, ans = k; n     for (int i = 2; i < k; i++) n       s += cross(p[a[i]] - p[a[1]], p[a[i + 1]] - p[a[1]]); n     if (s < 0) reverse(a + 1, a + k + 1); n     a[0] = a[k]; n     a[k + 1] = a[1]; n     for (int i = 1; i <= k; i++) { n       l = rnk[pair<int, int>(a[i], a[i + 1])]; n       r = rnk[pair<int, int>(a[i], a[i - 1])]; n       ans += sum[a[i]][r] - sum[a[i]][l - 1]; n       if (l > r) ans += sum[a[i]][(int)sum[a[i]].size() - 1]; n     } n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   if (m == 3) { n     if (n == 3) { n       cout << 0 <<     << 0 <<   n ; n       cout << 0 <<     << 1 <<   n ; n       cout << 1 <<     << 0 <<   n ; n       return 0; n     } else if (n == 4) { n       cout << 0 <<     << 0 <<   n ; n       cout << 0 <<     << 10 <<   n ; n       cout << 10 <<     << 0 <<   n ; n       cout << 1 <<     << 1 <<   n ; n       return 0; n     } else if (n >= 5) { n       cout << -1; n       return 0; n     } n   } n   int x = 1000000; n   for (int i = 0; i < m; i++) cout << i <<     << (i * i + x) <<   n ; n   for (int i = 0; i < n - m; i++) cout << i <<     << (-i * i - x) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, memo[100001]; n vector<long long> a; n long long x; n long long rek(int pos) { n   long long &ret = memo[pos]; n   if (ret != -1) return ret; n   ret = rek(pos - 1) + 20; n   x = upper_bound(a.begin(), a.end(), a[pos] - 90) - a.begin(); n   if (x) n     ret = min(ret, rek(x - 1) + 50); n   else n     ret = min(ret, 50LL); n   x = upper_bound(a.begin(), a.end(), a[pos] - 1440) - a.begin(); n   if (x) n     ret = min(ret, rek(x - 1) + 120); n   else n     ret = min(ret, 120LL); n   return ret; n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> x; n     a.push_back(x); n   } n   memset(memo, -1, sizeof(memo)); n   memo[0] = 20; n   rek(n - 1); n   for (int i = 0; i < n; i++) n     if (!i) n       cout << memo[i] << endl; n     else n       cout << memo[i] - memo[i - 1] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   map<int, int> mp; n   int n, k; n   cin >> n >> k; n   int c; n   cin >> c; n   for (int i = 1; i <= c; i++) { n     int x; n     cin >> x; n     mp[x] = 1; n   } n   int ans = 0; n   int t = 0; n   for (int i = 1; i <= n; i++) { n     t++; n     if (mp[i] == 1) { n       ans++; n       t = 0; n     } else if (t == k) { n       ans++; n       t = 0; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n template <typename T, typename TT> n inline ostream &operator<<(ostream &os, const pair<T, TT> &t) { n   return os << t.first <<     << t.second; n } n template <typename T> n inline ostream &operator<<(ostream &os, const vector<T> &t) { n   for (auto i : t) os << i <<    ; n   return os; n } n template <typename T> n inline istream &operator>>(istream &is, vector<T> &v) { n   for (T &t : v) is >> t; n   return is; n } n template <typename T1, typename T2> n inline istream &operator>>(istream &is, pair<T1, T2> &t) { n   is >> t.first >> t.second; n   return is; n } n const long long mod = 1e9 + 7; n void solve() { n   int n; n   cin >> n; n   vector<int> v(n); n   cin >> v; n   int mn = *min_element(v.begin(), v.end()), n       c = n - count(v.begin(), v.end(), mn); n   if (c >= n / 2) n     cout <<  Alice  <<   n ; n   else n     cout <<  Bob  <<   n ; n   return; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   ; n   int T = 1; n   while (T--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool mat[3001][3001]; n vector<int> v[3010]; n int main() { n   int n, m, a, b, result = 0; n   cin >> n >> m; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) mat[i][j] = false; n   for (int i = 0; i < m; i++) { n     cin >> a >> b; n     v[a].push_back(b); n     mat[a][b] = true; n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       if (i != j) { n         int r = 0; n         for (int k = 0; k < v[i].size(); k++) { n           if (mat[v[i][k]][j] == true) r++; n         } n         result += (r * (r - 1)) / 2; n       } n     } n   } n   cout << result; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n double P[1000]; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %lf , P + i); n   } n   sort(P, P + n); n   reverse(P, P + n); n   double x1 = 0; n   double x2 = 1; n   double res = 0; n   for (int i = 0; i < n; i++) { n     double s = (1 - P[i]); n     if (s == 0) s = 1; n     if (res == 1) break; n     x1 += P[i] / s; n     x2 *= s; n     res = max(res, x1 * x2); n   } n   printf( %.12lf n , res); n   return 0; n } n


#include <bits/stdc++.h> n int main(void) { n   int size = 0; n   scanf( %ld , &size); n   char fmt[size + 1]; n   fmt[size] =   0 ; n   scanf( %s , fmt); n   int width = 0; n   int maxHeight = 1; n   int ithX[size]; n   int depth[size]; n   int currentDepth = 0; n   char ch =   0 ; n   for (size_t ith = 0; ith < size; ith += 1) { n     char thisCh = fmt[ith]; n     width += 1; n     if (thisCh ==  [ ) { n       currentDepth += 1; n       depth[ith] = currentDepth; n     } else { n       depth[ith] = currentDepth; n       currentDepth -= 1; n       if (ch ==  [ ) width += 3; n     } n     ithX[ith] = width; n     size_t thisHeight = (currentDepth << 1) + 1; n     if (maxHeight < thisHeight) maxHeight = thisHeight; n     ch = thisCh; n   } n   size_t outLen = width * maxHeight; n   char buffer[outLen + 1]; n   buffer[outLen] =   0 ; n   memset(buffer,    , outLen); n   for (size_t ith = 0; ith < size; ith += 1) { n     size_t x = ithX[ith] - 1; n     size_t d = depth[ith]; n     int lineEnd = maxHeight - d; n     int lineStart = maxHeight - (lineEnd + 1); n     int indexStart = x + lineStart * width; n     int indexEnd = x + lineEnd * width; n     if (fmt[ith] ==  [ ) n       buffer[indexStart + 1] = buffer[indexEnd + 1] =  - ; n     else n       buffer[indexEnd - 1] = buffer[indexStart - 1] =  - ; n     buffer[indexStart] = buffer[indexEnd] =  + ; n     for (size_t y = lineStart + 1; y < lineEnd; y += 1) n       buffer[x + y * width] =  | ; n   } n   for (size_t line = 0; line < maxHeight; line += 1) { n     fwrite(buffer + line * width, sizeof(char), width, stdout); n     puts(  ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int i, j, k, n, m, x, y, T, ans, mx, mi, cas, num, len; n bool flag; n int p, a[25][105], b[25][105], c[25][105]; n char s[1000]; n int dp[1005]; n int main() { n   scanf( %d%d%d , &n, &m, &p); n   for (i = 1; i <= n; i++) { n     scanf( %s , s); n     for (j = 1; j <= m; j++) { n       scanf( %d%d%d , &a[i][j], &b[i][j], &c[i][j]); n     } n   } n   int v; n   for (i = 1; i <= n; i++) { n     for (j = 1; j <= n; j++) { n       memset(dp, 0, sizeof(dp)); n       for (x = 1; x <= m; x++) { n         for (v = p; v >= 0; v--) { n           for (num = 0; num <= c[i][x]; num++) { n             int pro = b[j][x] - a[i][x]; n             if (v - num >= 0 && dp[v] < dp[v - num] + pro * num) { n               dp[v] = dp[v - num] + pro * num; n               ans = max(ans, dp[v]); n             } else if (v - num < 0) n               break; n           } n         } n       } n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long LLMAX = 9223372036854775807LL; n const int MOD = 1000000007; n const int maxn = 500001; n int n; n int a[maxn]; n pair<int, int> p[maxn]; n int pr[maxn], ne[maxn]; n int main() { n   scanf( %d , &(n)); n   for (int(i) = 0; (i) < (int)(n); ++(i)) scanf( %d , &(a[i])); n   for (int i = 0; i < n; ++i) { n     p[i] = make_pair((a[i]), (i)); n     pr[i] = i - 1; n     ne[i] = i + 1; n   } n   sort(p, p + n); n   long long ans = 0, l = 0, r = n - 1; n   for (int i = 0; i < n - 2; ++i) { n     int j = p[i].second; n     if (j == l) { n       ans += p[i].first; n       l = ne[j]; n     } else if (j == r) { n       ans += p[i].first; n       r = pr[r]; n     } else { n       ans += min(a[pr[j]], a[ne[j]]); n       pr[ne[j]] = pr[j]; n       ne[pr[j]] = ne[j]; n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   string a, b, c; n   vector<vector<long long> > arr(3, vector<long long>((26 * 2) + 1, 0)); n   cin >> n; n   cin >> a >> b >> c; n   long long len = a.length(); n   for (long long i = 0; i < len; i++) { n     char cur = a[i]; n     if (cur >=  a ) { n       arr[0][cur - 97]++; n     } else { n       arr[0][cur - 65 + 26]++; n     } n   } n   for (long long i = 0; i < len; i++) { n     char cur = b[i]; n     if (cur >=  a ) { n       arr[1][cur - 97]++; n     } else { n       arr[1][cur - 65 + 26]++; n     } n   } n   for (long long i = 0; i < len; i++) { n     char cur = c[i]; n     if (cur >=  a ) { n       arr[2][cur - 97]++; n     } else { n       arr[2][cur - 65 + 26]++; n     } n   } n   for (long long i = 0; i < 52; i++) { n     if (arr[0][i] > arr[0][52]) { n       arr[0][52] = arr[0][i]; n     } n     if (arr[1][i] > arr[1][52]) { n       arr[1][52] = arr[1][i]; n     } n     if (arr[2][i] > arr[2][52]) { n       arr[2][52] = arr[2][i]; n     } n   } n   long long x = arr[0][52], y = arr[1][52], z = arr[2][52]; n   if (n == 1 && x == len) { n     x = len - 1; n   } else if (x + n >= len) { n     x = len; n   } else { n     x += n; n   } n   if (n == 1 && y == len) { n     y = len - 1; n   } else if (y + n >= len) { n     y = len; n   } else { n     y += n; n   } n   if (n == 1 && z == len) { n     z = len - 1; n   } else if (z + n >= len) { n     z = len; n   } else { n     z += n; n   } n   if (x > y && x > z) { n     cout <<  Kuro n ; n   } else if (y > x && y > z) { n     cout <<  Shiro n ; n   } else if (z > x && z > y) { n     cout <<  Katie n ; n   } else { n     cout <<  Draw n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5e5 + 5; n const int inf = ~0U >> 1; n template <class U, class V> n struct MCMF { n   static const int N = 8000, M = 7001010; n   int h[N], ing[N], pre[N], to[M], ne[M], e, s, t, n; n   U cap[M]; n   V dis[N], cost[M]; n   void ini(int _n = N) { n     fill(h, h + (n = _n), -1); n     e = 0; n   } n   void liu(int u, int v, U c, V w) { n     to[e] = v; n     ne[e] = h[u]; n     cap[e] = c; n     cost[e] = w; n     h[u] = e++; n   } n   void link(int u, int v, U c, V w) { n     liu(u, v, c, w); n     liu(v, u, 0, -w); n   } n   bool spfa() { n     queue<int> Q; n     fill(dis, dis + n, -inf); n     Q.push(s), ing[s] = 1, dis[s] = 0; n     while (!Q.empty()) { n       int c = Q.front(); n       Q.pop(); n       ing[c] = 0; n       for (int k = h[c]; ~k; k = ne[k]) n         if (cap[k] > 0) { n           int v = to[k]; n           if (dis[c] + cost[k] > dis[v]) { n             dis[v] = dis[c] + cost[k]; n             pre[v] = k; n             if (!ing[v]) Q.push(v), ing[v] = 1; n           } n         } n     } n     return dis[t] != -inf; n   } n   U flow; n   V mincost; n   pair<U, V> run(int _s, int _t) { n     s = _s, t = _t; n     flow = mincost = 0; n     while (spfa()) { n       U pl = inf; n       int p, k; n       for (p = t; p != s; p = to[k ^ 1]) pl = min(pl, cap[k = pre[p]]); n       for (p = t; p != s; p = to[k ^ 1]) n         cap[k = pre[p]] -= pl, cap[k ^ 1] += pl; n       mincost += pl * dis[t]; n       flow += pl; n     } n     return make_pair(flow, mincost); n   } n }; n MCMF<int, int> flow; n int n, a[N]; n int can[3005][3005]; n int main() { n   scanf( %d , &n); n   for (int i = (1); i < (n + 1); i++) { n     scanf( %d , &a[i]); n   } n   flow.ini(n * 2 + 100); n   int t = flow.n - 1, s = t - 1, ss = s - 1; n   ; n   for (int i = (1); i < (n + 1); i++) { n     flow.link(i, i + n, 1, 1); n     flow.link(i, i + n, inf, 0); n     int f1 = 1, f2 = 1, f3 = 1; n     for (int j = (i + 1); j < (n + 1); j++) { n       if (a[j] - a[i] == 1 && f1) { n         f1 = 0; n         flow.link(i + n, j, 1, 0); n       } n       if (a[i] - a[j] == 1 && f2) { n         f2 = 0; n         flow.link(i + n, j, 1, 0); n       } n       if (a[i] - a[j] == 0 && f3) { n         f3 = 0; n         flow.link(i + n, j, 1, 0); n       } n     } n   } n   for (int j = (0); j < (7); j++) { n     int pre = 0; n     for (int i = (1); i < (n + 1); i++) { n       if (a[i] % 7 == j) { n         if (pre) flow.link(pre + n, i, 1, 0); n         pre = i; n       } n     } n   } n   for (int i = (1); i < (n + 1); i++) n     flow.link(ss, i, 1, 0), flow.link(i + n, t, 1, 0); n   flow.link(s, ss, 4, 0); n   int ans = flow.run(s, t).second; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   cin.tie(0); n   ios::sync_with_stdio(false); n   cout << setprecision(12); n   int l; n   cin >> l; n   string s; n   cin >> s; n   size_t t = 0; n   for (auto c : s) t += (c ==  1 ); n   if (t * 2 == s.length()) { n     cout << 2 << endl; n     cout << s[0] <<     << s.substr(1) << endl; n   } else { n     cout << 1 << endl; n     cout << s << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n inline void cmin(int &x, int y) { n   if (y < x) x = y; n } n inline void cmax(int &x, int y) { n   if (y > x) x = y; n } n const int N = 1000006; n int a[12][N], sum[N], tmp[N], bcj[N], f[N][22], id[N], n, m, T, i, j, l, r; n int inline read() { n   char ch = getchar(); n   int z = 0, f = 1; n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     z = z * 10 + ch -  0 ; n     ch = getchar(); n   } n   return z * f; n } n int find(int x) { n   if (bcj[x] == x) return x; n   return bcj[x] = find(bcj[x]); n } n int calc(int f[], int g[], int j, int k) { n   int i, ans = 0; n   for ((i) = (1); (i) <= (n + n); ++i) bcj[i] = f[i]; n   for ((i) = (1); (i) <= (n + n); ++i) bcj[n + n + i] = n + n + g[i]; n   for ((i) = (1); (i) <= (n); ++i) n     if (a[i][j] == a[i][k] && find(n + i) != find(n + n + i)) { n       ++ans; n       bcj[find(n + n + i)] = find(n + i); n     } n   return ans; n } n void build(int l, int r, int x) { n   int mid = l + r >> 1, i; n   if (l == r) { n     int ans = 1; n     for ((i) = (2); (i) <= (n); ++i) n       if (a[i][l] != a[i - 1][l]) ++ans; n     sum[x] = ans; n     for ((i) = (1); (i) <= (n); ++i) n       if (i == 1 || a[i][l] != a[i - 1][l]) n         f[x][i] = i; n       else n         f[x][i] = f[x][i - 1]; n     for ((i) = (1); (i) <= (n); ++i) f[x][n + i] = f[x][i]; n   } else { n     build(l, mid, x * 2); n     build(mid + 1, r, x * 2 + 1); n     sum[x] = sum[x * 2] + sum[x * 2 + 1]; n     sum[x] -= calc(f[x * 2], f[x * 2 + 1], mid, mid + 1); n     for ((i) = (1); (i) <= (n * 4); ++i) bcj[i] = find(i), id[i] = 0; n     for ((i) = (1); (i) <= (n); ++i) { n       int z = bcj[i]; n       if (!id[z]) id[z] = i; n       f[x][i] = id[z]; n     } n     for ((i) = (n + 1); (i) <= (n + n); ++i) { n       int z = bcj[n * 2 + i]; n       if (!id[z]) id[z] = i; n       f[x][i] = id[z]; n     } n   } n } n int query(int l, int r, int x, int s, int t, int g[]) { n   int i; n   if (s <= l && r <= t) { n     for ((i) = (1); (i) <= (n + n); ++i) g[i] = f[x][i]; n     return sum[x]; n   } n   int mid = l + r >> 1; n   if (t <= mid) return query(l, mid, x * 2, s, t, g); n   if (s > mid) return query(mid + 1, r, x * 2 + 1, s, t, g); n   int h1[22], h2[22]; n   int ans = n       query(l, mid, x * 2, s, t, h1) + query(mid + 1, r, x * 2 + 1, s, t, h2); n   ans -= calc(h1, h2, mid, mid + 1); n   for ((i) = (1); (i) <= (n * 4); ++i) bcj[i] = find(i), id[i] = 0; n   for ((i) = (1); (i) <= (n); ++i) { n     int z = bcj[i]; n     if (!id[z]) id[z] = i; n     g[i] = id[z]; n   } n   for ((i) = (n + 1); (i) <= (n + n); ++i) { n     int z = bcj[n * 2 + i]; n     if (!id[z]) id[z] = i; n     g[i] = id[z]; n   } n   return ans; n } n int main() { n   n = read(); n   m = read(); n   T = read(); n   for ((i) = (1); (i) <= (n); ++i) n     for ((j) = (1); (j) <= (m); ++j) a[i][j] = read(); n   build(1, m, 1); n   while (T--) { n     l = read(); n     r = read(); n     printf( %d n , query(1, m, 1, l, r, tmp)); n   } n   return 0; n } n