#include <bits/stdc++.h> n const long long INF = 0x3f3f3f3f3f3f3f3fLL; n const int inf = 0x3f3f3f3f; n const int mod = 998244353; n const double eps = 1e-6; n void err() { puts(  ); } n template <typename T, typename... Args> n void err(const T &arg, const Args &...args) { n   std::cout << arg <<    ; n   err(args...); n } n template <typename T> n void read(T &x) { n   x = 0; n   char ch = getchar(); n   long long f = 1; n   while (!isdigit(ch)) { n     if (ch ==  - ) f *= -1; n     ch = getchar(); n   } n   while (isdigit(ch)) { n     x = x * 10 + ch - 48; n     ch = getchar(); n   } n   x *= f; n } n template <typename T, typename... Args> n void read(T &first, Args &...args) { n   read(first); n   read(args...); n } n using namespace std; n const int maxn = 710; n struct BigInteger { n   static const int BASE = 100000000; n   static const int WIDTH = 8; n   bool sign; n   size_t length; n   std::vector<int> num; n   BigInteger(long long x = 0) { *this = x; } n   BigInteger(const std::string &x) { *this = x; } n   BigInteger(const BigInteger &x) { *this = x; } n   void cutLeadingZero() { n     while (num.back() == 0 && num.size() != 1) { n       num.pop_back(); n     } n   } n   void setLength() { n     cutLeadingZero(); n     int tmp = num.back(); n     if (tmp == 0) { n       length = 1; n     } else { n       length = (num.size() - 1) * WIDTH; n       while (tmp > 0) { n         ++length; n         tmp /= 10; n       } n     } n   } n   BigInteger &operator=(long long x) { n     num.clear(); n     if (x >= 0) n       sign = true; n     else { n       sign = false; n       x = -x; n     } n     do { n       num.emplace_back(x % BASE); n       x /= BASE; n     } while (x > 0); n     setLength(); n     return *this; n   } n   BigInteger &operator=(const std::string &str) { n     num.clear(); n     sign = (str[0] !=  - ); n     int x, len = (str.size() - 1 - (!sign)) / WIDTH + 1; n     for (int i = 0; i < len; i++) { n       int End = str.length() - i * WIDTH; n       int start = std::max((int)(!sign), End - WIDTH); n       sscanf(str.substr(start, End - start).c_str(),  %d , &x); n       num.push_back(x); n     } n     setLength(); n     return *this; n   } n   BigInteger &operator=(const BigInteger &tmp) { n     num = tmp.num; n     sign = tmp.sign; n     length = tmp.length; n     return *this; n   } n   size_t size() const { return length; } n   BigInteger e(size_t n) const { n     int tmp = n % WIDTH; n     BigInteger ans; n     ans.length = n + 1; n     n /= WIDTH; n     while (ans.num.size() <= n) ans.num.push_back(0); n     ans.num[n] = 1; n     while (tmp--) ans.num[n] *= 10; n     return ans * (*this); n   } n   BigInteger abs() const { n     BigInteger ans(*this); n     ans.sign = true; n     return ans; n   } n   const BigInteger &operator+() const { return *this; } n   BigInteger operator+(const BigInteger &b) const { n     if (!b.sign) { n       return *this - (-b); n     } n     if (!sign) { n       return b - (-*this); n     } n     BigInteger ans; n     ans.num.clear(); n     for (int i = 0, g = 0;; i++) { n       if (g == 0 && i >= num.size() && i >= b.num.size()) break; n       int x = g; n       if (i < num.size()) x += num[i]; n       if (i < b.num.size()) x += b.num[i]; n       ans.num.push_back(x % BASE); n       g = x / BASE; n     } n     ans.setLength(); n     return ans; n   } n   BigInteger operator-() const { n     BigInteger ans(*this); n     if (ans != 0) ans.sign = !ans.sign; n     return ans; n   } n   BigInteger operator-(const BigInteger &b) const { n     if (!b.sign) { n       return *this + (-b); n     } n     if (!sign) { n       return -((-*this) + b); n     } n     if (*this < b) { n       return -(b - *this); n     } n     BigInteger ans; n     ans.num.clear(); n     for (int i = 0, g = 0;; i++) { n       if (g == 0 && i >= num.size() && i >= b.num.size()) break; n       int x = g; n       g = 0; n       if (i < num.size()) x += num[i]; n       if (i < b.num.size()) x -= b.num[i]; n       if (x < 0) { n         x += BASE; n         g = -1; n       } n       ans.num.push_back(x); n     } n     ans.setLength(); n     return ans; n   } n   BigInteger operator*(const BigInteger &b) const { n     int lena = num.size(), lenb = b.num.size(); n     std::vector<long long> ansLL; n     for (int i = 0; i < lena + lenb; i++) ansLL.push_back(0); n     for (int i = 0; i < lena; i++) { n       for (int j = 0; j < lenb; j++) { n         ansLL[i + j] += (long long)num[i] * (long long)b.num[j]; n       } n     } n     while (ansLL.back() == 0 && ansLL.size() != 1) ansLL.pop_back(); n     int len = ansLL.size(); n     long long g = 0, tmp; n     BigInteger ans; n     ans.sign = (ansLL.size() == 1 && ansLL[0] == 0) || (sign == b.sign); n     ans.num.clear(); n     for (int i = 0; i < len; i++) { n       tmp = ansLL[i]; n       ans.num.emplace_back((tmp + g) % BASE); n       g = (tmp + g) / BASE; n     } n     if (g > 0) ans.num.emplace_back(g); n     ans.setLength(); n     return ans; n   } n   BigInteger operator/(const long long &b) const { n     BigInteger c; n     c.num.clear(); n     for (int i = 0; i < num.size(); i++) { n       c.num.push_back(0); n     } n     long long g = 0; n     for (int i = num.size() - 1; i >= 0; i--) { n       c.num[i] = int((num[i] + g * BASE) / b); n       g = num[i] + g * BASE - c.num[i] * b; n     } n     for (int i = num.size() - 1; c.num[i] == 0; i--) { n       c.num.pop_back(); n     } n     return c; n   } n   BigInteger operator/(const BigInteger &b) const { n     BigInteger aa((*this).abs()); n     BigInteger bb(b.abs()); n     if (aa < bb) return 0; n     char *str = new char[aa.size() + 1]; n     memset(str, 0, sizeof(char) * (aa.size() + 1)); n     BigInteger tmp; n     int lena = aa.length, lenb = bb.length; n     for (int i = 0; i <= lena - lenb; i++) { n       tmp = bb.e(lena - lenb - i); n       while (aa >= tmp) { n         ++str[i]; n         aa = aa - tmp; n       } n       str[i] +=  0 ; n     } n     BigInteger ans(str); n     delete[] str; n     ans.sign = (ans == 0 || sign == b.sign); n     return ans; n   } n   BigInteger operator%(const long long &b) const { n     long long ans = 0; n     for (int i = num.size() - 1; i >= 0; i--) ans = (ans * BASE + num[i]) % b; n     return ans; n   } n   BigInteger operator%(const BigInteger &b) const { n     return *this - *this / b * b; n   } n   BigInteger &operator++() { n     *this = *this + 1; n     return *this; n   } n   BigInteger &operator--() { n     *this = *this - 1; n     return *this; n   } n   BigInteger &operator+=(const BigInteger &b) { n     *this = *this + b; n     return *this; n   } n   BigInteger &operator-=(const BigInteger &b) { n     *this = *this - b; n     return *this; n   } n   BigInteger &operator*=(const BigInteger &b) { n     *this = *this * b; n     return *this; n   } n   BigInteger &operator/=(const long long &b) { n     *this = *this / b; n     return *this; n   } n   BigInteger &operator/=(const BigInteger &b) { n     *this = *this / b; n     return *this; n   } n   BigInteger &operator%=(const long long &b) { n     *this = *this % b; n     return *this; n   } n   BigInteger &operator%=(const BigInteger &b) { n     *this = *this % b; n     return *this; n   } n   bool operator<(const BigInteger &b) const { n     if (sign && !b.sign) { n       return false; n     } else if (!sign && b.sign) { n       return true; n     } else if (!sign && !b.sign) { n       return -b < -*this; n     } n     if (num.size() != b.num.size()) return num.size() < b.num.size(); n     for (int i = num.size() - 1; i >= 0; i--) n       if (num[i] != b.num[i]) return num[i] < b.num[i]; n     return false; n   } n   bool operator>(const BigInteger &b) const { return b < *this; } n   bool operator<=(const BigInteger &b) const { return !(b < *this); } n   bool operator>=(const BigInteger &b) const { return !(*this < b); } n   bool operator!=(const BigInteger &b) const { return b < *this || *this < b; } n   bool operator==(const BigInteger &b) const { n     return !(b < *this) && !(*this < b); n   } n   bool operator||(const BigInteger &b) const { return *this != 0 || b != 0; } n   bool operator&&(const BigInteger &b) const { return *this != 0 && b != 0; } n   bool operator!() { return (bool)(*this == 0); } n   friend std::ostream &operator<<(std::ostream &out, const BigInteger &x) { n     if (!x.sign) out <<  - ; n     out << x.num.back(); n     for (int i = x.num.size() - 2; i >= 0; i--) { n       char buf[10]; n       sprintf(buf,  %08d , x.num[i]); n       for (int j = 0; j < strlen(buf); j++) out << buf[j]; n     } n     return out; n   } n   friend std::istream &operator>>(std::istream &in, BigInteger &x) { n     std::string str; n     in >> str; n     size_t len = str.size(); n     int start = 0; n     if (str[0] ==  - ) start = 1; n     if (str[start] ==   0 ) return in; n     for (int i = start; i < len; i++) { n       if (str[i] <  0  || str[i] >  9 ) return in; n     } n     x.sign = !start; n     x = str.c_str(); n     return in; n   } n   BigInteger pow(int n) { n     BigInteger ans = 1, base = *this; n     while (n) { n       if (n & 1) ans = ans * base; n       base = base * base; n       n >>= 1; n     } n     return ans; n   } n } dp[maxn][maxn], cur[maxn]; n struct EDGE { n   int next, to; n } edge[maxn << 1]; n int head[maxn], tot; n inline void addedge(int u, int v) { n   edge[tot] = {head[u], v}; n   head[u] = tot++; n } n int sz[maxn]; n void dfs(int u, int pre) { n   sz[u] = 1; n   dp[u][1] = 1; n   for (int i = head[u]; ~i; i = edge[i].next) { n     int v = edge[i].to; n     if (v == pre) continue; n     dfs(v, u); n     for (int j = 1; j <= sz[u]; ++j) cur[j] = dp[u][j]; n     for (int j = 1; j <= sz[u]; ++j) { n       for (int k = 1; k <= sz[v]; ++k) { n         dp[u][j + k] = max(dp[u][j + k], cur[j] / j * dp[v][k] / k * (j + k)); n         dp[u][j] = max(dp[u][j], cur[j] * dp[v][k]); n       } n     } n     sz[u] += sz[v]; n   } n } n int main() { n   memset(head, -1, sizeof head); n   int n; n   read(n); n   for (int i = 1; i < n; ++i) { n     int u, v; n     read(u, v); n     addedge(u, v); n     addedge(v, u); n   } n   dfs(1, 0); n   BigInteger ans = 0; n   for (int i = 1; i <= sz[1]; ++i) ans = max(ans, dp[1][i]); n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxN = 1e6 + 5; n const long long inf = 1e10; n const long long mod = 1e9 + 7; n long long n; n long long ans = 1; n long long res[maxN]; n void normalSieve(long long n) { n   for (long long i = 1; i <= n; i++) res[i] = 1; n   for (long long i = 2; i * i <= n; i++) { n     if (res[i] == 1) { n       for (long long j = i * i; j <= n; j += i) { n         res[j] = 2; n         ans = 2; n       } n     } n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n; n   normalSieve(n + 1); n   cout << ans << endl; n   for (long long i = 2; i <= n + 1; i++) cout << res[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n ifstream fin( input.txt ); n ofstream fout( output.txt ); n bool isPrime(long long int x) { n   if (x <= 4 || x % 2 == 0 || x % 3 == 0) return x == 2 || x == 3; n   for (int i = 5; i * i <= x; i += 6) n     if (x % i == 0 || x % (i + 2) == 0) return 0; n   return 1; n } n void primeFactors(long long n, set<long long> &Fac) { n   while (n % 2 == 0) { n     Fac.insert(2); n     n = n / 2; n   } n   for (int i = 3; i <= sqrt(n); i = i + 2) { n     while (n % i == 0) { n       Fac.insert(i); n       n = n / i; n     } n   } n   if (n > 2) Fac.insert(n); n } n int NumDigits(int x) { n   return ( n       x < 10 n           ? 1 n           : (x < 100 n                  ? 2 n                  : (x < 1000 n                         ? 3 n                         : (x < 10000 n                                ? 4 n                                : (x < 100000 n                                       ? 5 n                                       : (x < 1000000 n                                              ? 6 n                                              : (x < 10000000 n                                                     ? 7 n                                                     : (x < 100000000 n                                                            ? 8 n                                                            : (x < 1000000000 n                                                                   ? 9 n                                                                   : 10))))))))); n } n inline void boostIO() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cout.precision(10); n } n long long int Pow10[19] = { n     (long long int)0,    (long long int)1e1,  (long long int)1e2, n     (long long int)1e3,  (long long int)1e4,  (long long int)1e5, n     (long long int)1e6,  (long long int)1e7,  (long long int)1e8, n     (long long int)1e9,  (long long int)1e10, (long long int)1e11, n     (long long int)1e12, (long long int)1e13, (long long int)1e14, n     (long long int)1e15, (long long int)1e16, (long long int)1e17, n     (long long int)1e18}; n long long int gcd(long long int a, long long int b) { n   return b ? gcd(b, a % b) : a; n } n long long int lcm(long long int a, long long int b) { n   return a * b / gcd(a, b); n } n long long MOD = 1e9 + 7; n template <class T> n struct Fenwick { n   vector<T> V; n   Fenwick(long long n) : V(n) {} n   void add(size_t i, T x) { n     for (; i < V.size(); i |= i + 1) V[i] += x; n   } n   T sum(long long i) { n     T r = T(); n     for (--i; i >= 0; i = (i & (i + 1)) - 1) r += V[i]; n     return r; n   } n   T sum(long long l, long long r) { return sum(r) - sum(l); } n }; n long long f_Minimum(long long a, long long b) { return (min(a, b)); } n long long f_Maximum(long long a, long long b) { return (max(a, b)); } n long long f_Summarize(long long a, long long b) { return (a + b); } n class Parameter { n  public: n   long long InitialValue; n   long long (*Function)(long long a, long long b); n   Parameter(long long (*f)(long long a, long long b), long long value) { n     Function = f; n     InitialValue = value; n   } n  n  private: n }; n Parameter Minimum(f_Minimum, LONG_LONG_MAX); n Parameter Maximum(f_Maximum, LONG_LONG_MIN); n Parameter Summarize(f_Summarize, 0); n class SegmentTree { n  public: n   SegmentTree(long long size, Parameter p) { n     Function = p.Function; n     InitialValue = p.InitialValue; n     n = size; n     data = vector<long long>(2 * n, 0); n   } n   SegmentTree(vector<long long> array, Parameter p) { n     Function = p.Function; n     InitialValue = p.InitialValue; n     n = array.size(); n     ; n     data = vector<long long>(2 * n, 0); n     for (long long i = 0; i < (n); ++i) { n       data[n + i] = array[i]; n     } n     for (long long i = n - 1; i >= 1; ++i) { n       data[i] = Function(data[i * 2], data[i * 2] + 1); n     } n   } n   void Update(long long idx, long long value) { n     idx += n; n     data[idx] = value; n     while (idx > 1) { n       idx /= 2; n       data[idx] = Function(data[idx * 2], data[idx * 2 + 1]); n     } n   } n   long long Find(long long left, long long right) { n     left += n; n     right += n; n     long long value = InitialValue; n     while (left < right) { n       if (left % 2 == 1) { n         value = Function(left, value); n         left++; n       } n       if (right % 2 == 1) { n         value = Function(right, value); n         right--; n       } n       left /= 2; n       right /= 2; n     } n     return value; n   } n  n  private: n   long long n; n   vector<long long> data; n   long long (*Function)(long long a, long long b); n   long long InitialValue; n }; n int32_t main() { n   boostIO(); n   string s; n   cin >> s; n   string t; n   cin >> t; n   map<char, long long> Map; n   long long z = 0; n   for (auto c : s) { n     Map[c]++; n     if (c ==  ? ) z++; n   } n   map<char, long long> Map2; n   for (auto c : t) { n     Map2[c]++; n   } n   long long low = 0; n   long long high = 1e6 + 1; n   while (high - low > 1) { n     long long mid = (high + low) / 2; n     long long req = 0; n     for (long long c =  a ; c <=  z ; ++c) { n       req += max(0LL, mid * Map2[c] - Map[c]); n     } n     if (req > z) { n       high = mid; n     } else { n       low = mid; n     } n   } n   vector<char> B; n   for (char c =  a ; c <=  z ; ++c) { n     for (long long i = 0; i < (Map2[c] * low - Map[c]); ++i) { n       B.push_back(c); n     } n   } n   long long idx = 0; n   for (auto c : s) { n     if (c !=  ? ) { n       cout << c; n     } else { n       if (idx >= B.size()) { n         cout <<  a ; n       } else { n         cout << B[idx]; n         idx++; n       } n     } n   } n   cerr <<   n  <<  RUNTIME:   << 1.0 * clock() / CLOCKS_PER_SEC <<   s  <<   n ; n   return 0; n   ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, n, k, i, j, res[201], max = 0, diff; n   cin >> t; n   for (i = 0; i < t; i++) { n     cin >> n >> k; n     int x[k]; n     for (j = 0; j < k; j++) { n       cin >> x[j]; n       if (j == 0) { n         max = x[j]; n       } n       if ((j > 0) && (j < k)) { n         diff = (x[j] - x[j - 1]) / 2 + 1; n       } n       if (diff > max) { n         max = diff; n       } n       if (j == (k - 1)) { n         if ((n - x[j] + 1) > max) { n           max = n - x[j] + 1; n         } n       } n     } n     res[i] = max; n     diff = 0; n   } n   for (i = 0; i < t; i++) { n     cout << res[i] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5e5 + 5; n int nxt[maxn]; n int n, ans, m, l, r; n int rmq[maxn][30]; n int main() { n   ios::sync_with_stdio(false); n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     cin >> l >> r; n     nxt[l] = max(nxt[l], r); n   } n   for (int i = 0; i < maxn; i++) { n     nxt[i] = max(nxt[i], nxt[i - 1]); n     nxt[i] = max(nxt[i], i); n     rmq[i][0] = nxt[i]; n   } n   for (int i = 1; i <= 25; i++) n     for (int j = 0; j < maxn; j++) { n       rmq[j][i] = max(rmq[j][i - 1], rmq[rmq[j][i - 1]][i - 1]); n     } n   for (int i = 1; i <= m; i++) { n     cin >> l >> r; n     ans = 0; n     for (int j = 25; j >= 0; j--) { n       if (rmq[l][j] < r) { n         l = rmq[l][j]; n         ans = ans + (1 << j); n       } n     } n     if (l < r) { n       l = rmq[l][0]; n       ans++; n     } n     if (l >= r) n       cout << ans <<   n ; n     else n       cout << -1 <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct vertex { n   map<char, int> next, go; n   int p, link; n   char pch; n   vector<int> leaf; n   unordered_set<int> visited; n   vertex(int p = -1, char pch = -1) : p(p), pch(pch), link(-1) {} n }; n vector<vertex> t; n void aho_init() { n   t.clear(); n   t.push_back(vertex()); n } n int add_string(string s, int id) { n   int v = 0; n   for (char c : s) { n     if (!t[v].next.count(c)) { n       t[v].next[c] = t.size(); n       t.push_back(vertex(v, c)); n     } n     v = t[v].next[c]; n   } n   t[v].leaf.push_back(id); n   return v; n } n void add_visited(int v, int id) { t[v].visited.insert(id); } n int go(int v, char c); n int get_link(int v) { n   if (t[v].link < 0) n     if (!v || !t[v].p) n       t[v].link = 0; n     else n       t[v].link = go(get_link(t[v].p), t[v].pch); n   return t[v].link; n } n int go(int v, char c) { n   if (!t[v].go.count(c)) n     if (t[v].next.count(c)) n       t[v].go[c] = t[v].next[c]; n     else n       t[v].go[c] = v == 0 ? 0 : go(get_link(v), c); n   return t[v].go[c]; n } n const int N = 3e5; n vector<int> g[N]; n int last[N]; n string s[N]; n int n, q, B; n long long tot[400], sum[N]; n struct Query { n   int l, r, k, id; n }; n int dfs(int x, int i, vector<long long>& partials) { n   int cnt = 0; n   if (t[x].visited.count(i)) ++cnt, t[x].visited.erase(i); n   for (auto v : g[x]) cnt += dfs(v, i, partials); n   for (auto v : t[x].leaf) partials[v] += cnt; n   return cnt; n } n void solveLarge(vector<Query>& q, int i, vector<long long>& res) { n   vector<long long> partials(n + 1, 0); n   dfs(0, i, partials); n   for (int i = 1; i < n + 1; i++) partials[i] += partials[i - 1]; n   for (auto query : q) { n     res[query.id] = partials[query.r] - partials[query.l]; n   } n } n void add(int i, int val) { n   while (i < N && i % B) { n     sum[i++] += val; n   } n   i /= B; n   while (i <= n / B) tot[i++] += val; n } n int get(int i) { return sum[i] + tot[i / B]; } n void dfs2(int x, vector<vector<Query>>& queries, vector<long long>& res) { n   for (auto v : t[x].leaf) add(v, 1); n   for (auto v : t[x].visited) { n     for (auto q : queries[v]) { n       res[q.id] += get(q.r) - get(q.l); n     } n   } n   for (auto v : g[x]) dfs2(v, queries, res); n   for (auto v : t[x].leaf) add(v, -1); n } n void solveSmall(vector<vector<Query>>& queries, vector<long long>& res) { n   dfs2(0, queries, res); n } n int main() { n   cin >> n >> q; n   B = sqrt(n); n   for (int i = 0; i < n; i++) cin >> s[i]; n   aho_init(); n   for (int i = 0; i < n; i++) { n     add_string(s[i], i + 1); n   } n   for (int i = 0; i < n; i++) { n     int cur = 0; n     add_visited(cur, i); n     for (char c : s[i]) { n       cur = go(cur, c); n       add_visited(cur, i); n     } n     last[i] = cur; n   } n   for (int i = 1; i < ((int)t.size()); i++) { n     g[get_link(i)].push_back(i); n   } n   vector<Query> queries; n   for (int i = 0; i < q; i++) { n     int l, r, k; n     cin >> l >> r >> k; n     queries.push_back({l - 1, r, k - 1, i}); n   } n   vector<vector<Query>> large(n); n   vector<vector<Query>> small(n); n   for (auto query : queries) { n     if (((int)s[query.k].size()) >= B) { n       large[query.k].push_back(query); n     } else { n       small[query.k].push_back(query); n     } n   } n   vector<long long> res(q, 0); n   for (int i = 0; i < n; i++) { n     if (((int)large[i].size())) solveLarge(large[i], i, res); n   } n   solveSmall(small, res); n   for (int i = 0; i < q; i++) cout << res[i] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   long long n, a, b, c = 0; n   cin >> n >> a; n   for (int i = 1; i <= n; i++) { n     if (i * n >= a && a % i == 0) c++; n   } n   cout << c; n } n


#include <bits/stdc++.h> n using namespace std; n bool chk[64] = {false}; n int comb[64][8]; n char s[128]; n int dp[16][128]; n char ans[8][32]; n int main() { n   for (int p = 0; p <= 6; p++) n     for (int q = 0; p + q <= 6; q++) { n       int r = 6 - p - q; n       int v = q * 4 + r * 7; n       chk[v] = true; n       for (int i = 0; i < p; i++) comb[v][i] = 0; n       for (int i = p; i < p + q; i++) comb[v][i] = 4; n       for (int i = p + q; i < p + q + r; i++) comb[v][i] = 7; n     } n   int T; n   scanf( %d , &T); n   while (T--) { n     s[0] =  0 ; n     scanf( %s , s + 1); n     int l = strlen(s); n     memset(dp, -1, sizeof(dp)); n     dp[0][0] = -2; n     for (int i = 1; i < l; i++) n       for (int j = 0; j < 10; j++) n         if (dp[j][i - 1] != -1) { n           int v = 10 * j + (s[i] -  0 ); n           for (int k = 0; k < 64; k++) n             if (chk[k] && v >= k && v - k < 10) dp[v - k][i] = k; n         } n     if (dp[0][l - 1] == -1) n       printf( -1 n ); n     else { n       int cv = 0; n       for (int j = 0; j < 6; j++) { n         ans[j][0] =  0 ; n         ans[j][l] =   0 ; n       } n       for (int i = l - 1; i > 0; i--) { n         int w = dp[cv][i]; n         for (int j = 0; j < 6; j++) ans[j][i] =  0  + comb[w][j]; n         cv += w; n         cv /= 10; n       } n       for (int j = 0; j < 6; j++) { n         long long pans; n         sscanf(ans[j],  %lld , &pans); n         printf(  %lld  + !j, pans); n       } n       printf(  n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long prime[500001]; n bool vis[500001]; n bool isPrime(long long x) { n   for (long long i = 2; i <= sqrt(x); i++) { n     if (x % i == 0) return false; n   } n   return true; n } n int main() { n   long long n; n   int cnt = 0; n   memset(vis, false, sizeof(vis)); n   memset(prime, 0, sizeof(prime)); n   for (int i = 2; i <= 110000; i++) { n     if (!vis[i]) prime[cnt++] = i; n     for (int j = 0; j < cnt && i * prime[j] <= 110000; j++) { n       vis[i * prime[j]] = true; n       if (i % prime[j] == 0) break; n     } n   } n   while (~scanf( %lld , &n)) { n     if (isPrime(n)) { n       printf( 1 n ); n     } else { n       for (int i = 0; i < cnt; i++) { n         if (n % prime[i] == 0) { n           printf( %lld n , 1 + (n - prime[i]) / 2); n           break; n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; 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 int inf = 0x3f3f3f3f; n const long long infLL = 0x3f3f3f3f3f3f3f3fLL; n const long long mod = 1e9 + 7; n const int maxN = 1e5 + 7; n int n; n int a[maxN]; n int ans[maxN]; n int BinarySearch(vector<int>& x, int k) { n   if (x.size() == 0 || a[x[0]] >= k) return -1; n   int l = 0, r = x.size() - 1; n   int mid = (l + r) >> 1; n   while (l < r) { n     if (a[x[mid]] >= k) { n       r = mid - 1; n       mid = (l + r) >> 1; n     } else { n       l = mid + 1; n       if (a[x[l]] >= k) return x[mid]; n       mid = (l + r) >> 1; n     } n   } n   return x[r]; n } n int main() { n   while (cin >> n) { n     for (int i = (1); i <= (n); ++i) cin >> a[i]; n     vector<int> vi; n     for (int i = (1); i <= (n); ++i) { n       if (vi.empty() || a[i] > a[vi.back()]) { n         vi.push_back(i); n       } else if (a[i] <= a[vi.back()]) { n         vi.pop_back(); n         --i; n       } n     } n     for (int i = (1); i <= (n); ++i) { n       ans[i] = BinarySearch(vi, a[i]); n       ans[i] -= i + 1; n       if (ans[i] < 0) ans[i] = -1; n       cout << ans[i] <<    ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n T in() { n   char ch; n   T n = 0; n   bool ng = false; n   while (1) { n     ch = getchar(); n     if (ch ==  - ) { n       ng = true; n       ch = getchar(); n       break; n     } n     if (ch >=  0  && ch <=  9 ) break; n   } n   while (1) { n     n = n * 10 + (ch -  0 ); n     ch = getchar(); n     if (ch <  0  || ch >  9 ) break; n   } n   return (ng ? -n : n); n } n template <typename T> n inline T POW(T B, T P) { n   if (P == 0) return 1; n   if (P & 1) n     return B * POW(B, P - 1); n   else n     return (POW(B, P / 2) * POW(B, P / 2)); n } n template <typename T> n inline T Gcd(T a, T b) { n   if (a < 0) return Gcd(-a, b); n   if (b < 0) return Gcd(a, -b); n   return (b == 0) ? a : Gcd(b, a % b); n } n template <typename T> n inline T Lcm(T a, T b) { n   if (a < 0) return Lcm(-a, b); n   if (b < 0) return Lcm(a, -b); n   return a * (b / Gcd(a, b)); n } n long long Bigmod(long long base, long long power, long long MOD) { n   long long ret = 1; n   while (power) { n     if (power & 1) ret = (ret * base) % MOD; n     base = (base * base) % MOD; n     power >>= 1; n   } n   return ret; n } n bool isVowel(char ch) { n   ch = toupper(ch); n   if (ch ==  A  || ch ==  U  || ch ==  I  || ch ==  O  || ch ==  E ) n     return true; n   return false; n } n long long ModInverse(long long number, long long MOD) { n   return Bigmod(number, MOD - 2, MOD); n } n bool isConst(char ch) { n   if (isalpha(ch) && !isVowel(ch)) return true; n   return false; n } n int toInt(string s) { n   int sm; n   stringstream second(s); n   second >> sm; n   return sm; n } n vector<int> A[500007]; n int a[500007]; n long long int Dp[500007]; n vector<pair<long long int, int> > dp[500007]; n void Dfs1(int u, int p, long long int vl) { n   long long int mx1 = -1, mx2 = -1; n   dp[u].push_back(make_pair(vl, p)); n   for (int i = 0; i < A[u].size(); i++) { n     int v = A[u][i]; n     if (v == p) continue; n     int Ln = dp[u].size() - 1; n     int lft = max(0, Ln - 5); n     long long int now = vl; n     for (int j = Ln; j >= lft; j--) { n       int tp = dp[u][j].second; n       if (tp == v) continue; n       now = max(now, dp[u][j].first); n     } n     Dfs1(v, u, now + a[u]); n   } n   sort(dp[u].begin(), dp[u].end()); n } n long long int Dfs(int u, int p) { n   long long int mx1 = -1, mx2 = -1; n   for (int i = 0; i < A[u].size(); i++) { n     int v = A[u][i]; n     if (v == p) continue; n     long long int tp = Dfs(v, u); n     dp[u].push_back(make_pair(tp, v)); n     if (tp > mx1) { n       mx2 = mx1; n       mx1 = tp; n     } else if (tp > mx2) { n       mx2 = tp; n     } n   } n   Dp[u] = max(0LL, mx1) + max(0LL, mx2) + a[u]; n   sort(dp[u].begin(), dp[u].end()); n   return ((0LL > mx1) ? 0LL : mx1) + a[u]; n } n void Wow(int u, int p) { n   for (int i = 0; i < A[u].size(); i++) { n     int v = A[u][i]; n     if (v == p) continue; n     Wow(v, u); n     Dp[u] = max(Dp[u], Dp[v]); n   } n } n long long int Ans; n void Dekhi(int u, int p) { n   for (int i = 0; i < A[u].size(); i++) { n     int v = A[u][i]; n     if (v == p) continue; n     Dekhi(v, u); n   } n   if (p) { n     int Ln = dp[p].size() - 1; n     int lft = max(0, Ln - 5); n     long long int now = Dp[u] + a[p]; n     for (int i = Ln; i >= lft; i--) { n       if (dp[p][i].second == u) continue; n       for (int j = i - 1; j >= lft; j--) { n         if (dp[p][j].second == u) continue; n         long long int tp = dp[p][i].first + dp[p][j].first; n         if (Ans < now + tp) { n           Ans = now + tp; n         } n       } n       long long int tp = dp[p][i].first; n       if (Ans < now + tp) { n         Ans = now + tp; n       } n     } n     Ans = max(Ans, now); n   } n   return; n } n int main() { n   int n; n   n = in<int>(); n   for (int i = 1; i <= n; i++) a[i] = in<int>(); n   for (int i = 1; i < n; i++) { n     int u, v; n     u = in<int>(), v = in<int>(); n     A[u].push_back(v); n     A[v].push_back(u); n   } n   vector<int> root; n   for (int i = 1; i <= n; i++) { n     if (A[i].size() == 1) { n       root.push_back(i); n     } n   } n   for (int i = 0; i < root.size(); i++) { n     for (int j = 1; j <= n; j++) { n       dp[j].clear(); n     } n     long long int tp = Dfs(root[i], 0); n     Dfs1(root[i], 0, 0); n     Wow(root[i], 0); n     Dekhi(root[i], 0); n     if (i == 10) break; n   } n   printf( %lld n , Ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   int n, k, s; n   cin >> n >> k >> s; n   vector<int> a(n); n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   s = min(s, n * n); n   vector<vector<int> > dp1(k + 1, vector<int>(s + 1, 1e9)); n   dp1[0][0] = 0; n   int ans = 1e9; n   for (int i = n - 1; i >= 0; i--) { n     for (int c = k; c >= 0; c--) { n       for (int j = s; j >= 0; j--) { n         if (j + c <= s) { n           dp1[c][j + c] = min(dp1[c][j + c], dp1[c][j]); n         } n         if (c + 1 <= k) { n           dp1[c + 1][j] = min(dp1[c + 1][j], dp1[c][j] + a[i]); n         } n         if (c != 0) { n           dp1[c][j] = 1e9; n         } n       } n     } n   } n   for (int j = 0; j <= s; j++) { n     ans = min(ans, dp1[k][j]); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n ll solve(ll n) { n   --n; n   ll index = n / 3; n   ll off = 1; n   for (; index - off >= 0; off <<= 2) { n     index -= off; n   } n   ll fi = index + off; n   ll se = off << 1; n   for (ll place = off >> 2; place >= 1; place >>= 2) { n     ll t = (index / place) % 4; n     if (t == 0) { n       se += 0 * place; n     } else if (t == 1) { n       se += 2 * place; n     } else if (t == 2) { n       se += 3 * place; n     } else if (t == 3) { n       se += 1 * place; n     } n   } n   ll th = fi ^ se; n   if (n % 3 == 0) n     return fi; n   else if (n % 3 == 1) n     return se; n   else n     return th; 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     ll n; n     cin >> n; n     cout << solve(n) <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void splitstr(const string &s, vector<T> &out) { n   istringstream in(s); n   out.clear(); n   copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out)); n } n template <class T> n T gcd(T a, T b) { n   return b ? gcd(b, a % b) : a; n } n static void redirect(int argc, const char **argv) { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   if (argc > 1) { n     static filebuf f; n     f.open(argv[1], ios::in); n     cin.rdbuf(&f); n     if (!cin) { n       cerr <<  Failed to open    << argv[1] <<     << endl; n       exit(1); n     } n   } n   if (argc > 2) { n     static filebuf f; n     f.open(argv[2], ios::out | ios::trunc); n     cout.rdbuf(&f); n     if (!cout) { n       cerr <<  Failed to open    << argv[2] <<     << endl; n     } n   } n } n class UnionFind { n  private: n   mutable std::vector<int> parent; n  n  public: n   explicit UnionFind(int size = 0) : parent(size, -1) {} n   int size() const { return parent.size(); } n   int find(int x) const { n     assert(x >= 0 && x < size()); n     int y = x; n     while (parent[y] >= 0) y = parent[y]; n     while (parent[x] >= 0) { n       int nxt = parent[x]; n       parent[x] = y; n       x = nxt; n     } n     return y; n   } n   bool merge(int x, int y) { n     x = find(x); n     y = find(y); n     if (x == y) return false; n     if (-parent[x] > -parent[y]) std::swap(x, y); n     parent[y] += parent[x]; n     parent[x] = y; n     return true; n   } n   int component_size(int x) const { return -parent[find(x)]; } n }; n template <typename T, typename C, T Modulus> n class MR { n  private: n   struct tag_plus {}; n   struct tag_minus {}; n   struct tag_good {}; n   T value; n   static_assert(std::numeric_limits<C>::max() / Modulus / Modulus > 0, n                  compute type is too small ); n   static_assert(Modulus < std::numeric_limits<T>::max() / 2, n                  storage type is too small ); n   void reduce(tag_plus) { n     if (value >= Modulus) value -= Modulus; n   } n   void reduce(tag_minus) { n     if (value < 0) value += Modulus; n   } n   void reduce(tag_good) {} n  n  public: n   static const T modulus = Modulus; n   MR() : value(0) {} n   MR(C value) : value(value % Modulus) { reduce(tag_minus()); } n   template <typename tag_t> n   MR(T value, tag_t tag) : value(value) { n     reduce(tag); n   } n   MR &operator=(C value) { n     this->value = value % Modulus; n     reduce(tag_minus()); n     return *this; n   } n   MR operator+(MR b) const { return MR(value + b.value, tag_plus()); } n   MR operator-(MR b) const { return MR(value - b.value, tag_minus()); } n   MR operator*(MR b) const { n     return MR(C(value) * C(b.value) % Modulus, tag_good()); n   } n   MR operator-() const { return MR(-value, tag_minus()); } n   MR &operator+=(MR b) { n     value += b.value; n     reduce(tag_plus()); n     return *this; n   } n   MR &operator-=(MR b) { n     value -= b.value; n     reduce(tag_minus()); n     return *this; n   } n   MR &operator*=(MR b) { n     value = C(value) * C(b.value) % Modulus; n     return *this; n   } n   bool operator==(MR b) const { return value == b.value; } n   bool operator!=(MR b) const { return value != b.value; } n   T get() const { return value; } n }; n static inline int bit(int x) { return 1 << x; } n static int min_colours(const vector<int> &edges) { n   int N = ((long long)(edges).size()); n   int M = 1 << N; n   vector<MR<int, long long, 1000000009> > a(M); n   a[0] = 1; n   for (int i = 1; i < M; i++) { n     int v = __builtin_ctz(i); n     a[i] = a[i & ~bit(v)] + a[i & ~bit(v) & ~edges[v]]; n   } n   vector<MR<int, long long, 1000000009> > ak(M, n                                              MR<int, long long, 1000000009>(1)); n   for (int k = 1;; k++) { n     MR<int, long long, 1000000009> sum = 0; n     for (int i = 0; i < M; i++) { n       ak[i] *= a[i]; n       sum += __builtin_parity(i) ? ak[i] : -ak[i]; n     } n     if (sum.get() != 0) return k; n   } n } n int main(int argc, const char **argv) { n   redirect(argc, argv); n   int N; n   cin >> N; n   vector<string> matrix(N); n   UnionFind scc(N); n   for (int i = 0; i < N; i++) { n     cin >> matrix[i]; n     for (int j = 0; j < i; j++) n       if (matrix[i][j] ==  A ) scc.merge(i, j); n   } n   vector<pair<int, int> > comps; n   for (int i = 0; i < N; i++) n     if (i == scc.find(i)) comps.emplace_back(scc.component_size(i), i); n   sort(begin(comps), end(comps)); n   reverse(begin(comps), end(comps)); n   vector<int> cmap(N); n   int C = ((long long)(comps).size()); n   int C2 = 0; n   while (C2 < C && comps[C2].first >= 2) C2++; n   for (int i = 0; i < C; i++) cmap[comps[i].second] = i; n   C = C2; n   vector<int> edge(C); n   for (int i = 0; i < N; i++) n     for (int j = 0; j < i; j++) n       if (matrix[i][j] ==  X ) { n         int p = cmap[scc.find(i)]; n         int q = cmap[scc.find(j)]; n         if (p == q) { n           cout <<  -1 n ; n           return 0; n         } n         if (p < C && q < C) { n           edge[p] |= bit(q); n           edge[q] |= bit(p); n         } n       } n   int mc = C2 ? min_colours(edge) : 0; n   cout << N - 1 + mc <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[1000 + 10]; n int ret[21][21]; n int pool[410], two[100]; n int main() { n   ios::sync_with_stdio(false); n   memset(a, 0, sizeof(a)); n   memset(ret, 0, sizeof(ret)); n   memset(pool, 0, sizeof(pool)); n   memset(two, 0, sizeof(two)); n   int n; n   cin >> n; n   int t, tag = 0, tt = 0; n   for (int i = 0; i < n * n; i++) { n     cin >> t; n     a[t]++; n   } n   if (n == 1) { n     cout <<  yes  n          <<   n ; n     cout << t <<   n ; n     return 0; n   } n   if (n % 2) { n     int cnt = 0; n     for (int i = 1; i <= 1000; i++) { n       if (a[i] % 4) { n         if (a[i] % 2) { n           if (cnt == 0) { n             ret[n / 2][n / 2] = i; n             a[i]--; n             cnt = 1; n           } else { n             cout <<  no  n                  <<   n ; n             return 0; n           } n         } n         if (a[i] % 4) { n           two[tt++] = i; n           a[i] -= 2; n           if (tt > (n - 1)) { n             cout <<  no  n                  <<   n ; n             return 0; n           } n         } n       } n       while (a[i] > 0) { n         pool[tag++] = i; n         a[i] -= 4; n       } n     } n     while (tt < (n - 1)) { n       two[tt++] = pool[--tag]; n       two[tt++] = pool[tag]; n     } n     int cnt2 = 0, cnt4 = 0; n     for (int i = 0; i * 2 < n; i++) { n       for (int j = 0; j * 2 < n; j++) { n         if (i == n / 2 && j == n / 2) continue; n         if (i == n / 2) { n           ret[i][j] = two[cnt2++]; n           ret[i][n - j - 1] = ret[i][j]; n         } else if (j == n / 2) { n           ret[i][j] = two[cnt2++]; n           ret[n - i - 1][j] = ret[i][j]; n         } else { n           ret[i][j] = pool[cnt4++]; n           ret[n - i - 1][n - j - 1] = ret[i][j]; n           ret[i][n - j - 1] = ret[i][j]; n           ret[n - i - 1][j] = ret[i][j]; n         } n       } n     } n   } else { n     bool can = true; n     for (int i = 1; i <= 1000; i++) { n       if (a[i] % 4) { n         cout <<  no  n              <<   n ; n         return 0; n       } n       while (a[i] > 0) { n         pool[tag++] = i; n         a[i] -= 4; n       } n     } n     for (int i = 0; i * 2 < n; i++) { n       for (int j = 0; j * 2 < n; j++) { n         ret[i][j] = pool[i * n / 2 + j]; n         ret[n - i - 1][n - j - 1] = ret[i][j]; n         ret[i][n - j - 1] = ret[i][j]; n         ret[n - i - 1][j] = ret[i][j]; n       } n     } n   } n   cout <<  yes  n        <<   n ; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       cout << ret[i][j]; n       if (j == n - 1) n         cout <<   n ; n       else n         cout <<    ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b; n   cin >> a >> b; n   if (a < b) swap(a, b); n   cout << b <<     << (a - b) / 2 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n struct player { n   string name; n   long long point; n   player() {} n   player(string n, long long p) { name = n, point = p; } n   bool operator<(const player &p) const { n     if (point == p.point) { n       return name < p.name; n     } n     return point > p.point; n   } n }; n vector<player> vec, tmp; n vector<long long> prize; n long long n, m, x; n string str; n int index_of() { n   for (int i = 0; i < vec.size(); i++) { n     if (tmp[i].name == str) return i; n   } n } n int find_first_pos(int in) { n   int j = 0; n   for (int i = in; i < tmp.size() && j < prize.size(); i++, j++) { n     tmp[i].point += prize[j]; n   } n   for (int i = in - 1; i >= 0 && j < prize.size(); i--, j++) { n     tmp[i].point += prize[j]; n   } n   sort(tmp.begin(), tmp.end()); n   return index_of() + 1; n } n int find_last_pos(int in) { n   tmp = vec; n   if (prize.size() >= tmp.size()) { n     tmp[in].point += prize[tmp.size() - 1]; n   } n   int j = 0; n   for (int i = tmp.size() - 1; i >= 0 && j < prize.size(); i--) { n     if (i != in) { n       player p(tmp[i].name, tmp[i].point + prize[j]); n       if (p < tmp[in]) { n         tmp[i].point += prize[j]; n         j++; n       } n     } n   } n   sort(tmp.begin(), tmp.end()); n   return index_of() + 1; n } n bool func(int x, int y) { return x > y; } n int main() { n   ios_base::sync_with_stdio(false); n   while (cin >> n) { n     for (int i = 0; i < n; i++) { n       cin >> str >> x; n       vec.push_back(player(str, x)); n     } n     sort(vec.begin(), vec.end()); n     cin >> m; n     for (int i = 0; i < m; i++) { n       cin >> x; n       prize.push_back(x); n     } n     sort(prize.begin(), prize.end(), func); n     cin >> str; n     tmp = vec; n     long long in = index_of(); n     long long fir, sec; n     fir = find_first_pos(in); n     sec = find_last_pos(in); n     cout << fir <<     << sec << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct cub { n   int c, h; n } nr[100100]; n vector<int> axnorm; n vector<pair<int, int> > cul[100100]; n struct cmp { n   bool operator()(pair<int, int> a, pair<int, int> b) { n     return (a.first > b.first); n   } n }; n priority_queue<pair<long long, int> > H[100100]; n int N, C; n int culoare1, culoare2, nrcub1, nrcub2; n long long solutie; n int caut(int x) { n   int p = -1, u = C, mij; n   while (u - p > 1) { n     mij = (p + u) / 2; n     if (axnorm[mij] < x) n       p = mij; n     else n       u = mij; n   } n   if (u == C || axnorm[u] != x) return -1; n   return u; n } n void prec() { n   long long sum; n   for (int i = 1; i <= C; ++i) { n     sum = 0; n     sort(cul[i].begin(), cul[i].end(), cmp()); n     for (size_t j = 0; j < cul[i].size(); ++j) { n       sum = (long long)(sum + cul[i][j].first); n       H[(int)(j + 1)].push(pair<long long, int>(sum, i)); n     } n   } n } n void solve() { n   sort(axnorm.begin(), axnorm.end()); n   axnorm.erase(unique(axnorm.begin(), axnorm.end()), axnorm.end()); n   C = (int)axnorm.size(); n   int i, cc, cc1; n   long long s, s1; n   for (i = 1; i <= N; ++i) n     cul[caut(nr[i].c) + 1].push_back(pair<int, int>(nr[i].h, i)); n   prec(); n   for (i = 1; i <= N; ++i) { n     if (H[i].size() < 2) break; n     s = H[i].top().first; n     cc = H[i].top().second; n     H[i].pop(); n     if (solutie < s + H[i].top().first) { n       solutie = s + H[i].top().first; n       culoare1 = cc; n       culoare2 = H[i].top().second; n       nrcub1 = nrcub2 = i; n     } n     H[i].push(pair<long long, int>(s, cc)); n   } n   for (i = 2; i <= N; ++i) { n     if (!H[i].size()) break; n     s = H[i].top().first; n     cc = H[i].top().second; n     H[i].pop(); n     s1 = H[i - 1].top().first; n     cc1 = H[i - 1].top().second; n     H[i - 1].pop(); n     if (cc == cc1) { n       if (H[i].size() > 0) { n         if (solutie < s1 + H[i].top().first) { n           solutie = s1 + H[i].top().first; n           culoare1 = H[i].top().first; n           culoare2 = cc1; n           nrcub1 = i; n           nrcub2 = i - 1; n         } n       } n       if (H[i - 1].size() > 0) { n         if (solutie < s + H[i - 1].top().first) { n           solutie = s + H[i - 1].top().first; n           culoare1 = cc1; n           culoare2 = H[i - 1].top().second; n           nrcub1 = i; n           nrcub2 = i - 1; n         } n       } n     } else { n       if (solutie < s + s1) { n         solutie = s + s1; n         culoare1 = cc; n         culoare2 = cc1; n         nrcub1 = i; n         nrcub2 = i - 1; n       } n     } n     H[i].push(pair<long long, int>(s, cc)); n     H[i - 1].push(pair<long long, int>(s1, cc1)); n   } n } n void afis() { n   size_t x, y; n   x = y = 0; n   cout << solutie <<   n ; n   cout << nrcub1 + nrcub2 <<   n ; n   while (nrcub1 || nrcub2) { n     if (nrcub1 > nrcub2) { n       cout << cul[culoare1][x].second <<    ; n       ++x; n       --nrcub1; n     } else { n       cout << cul[culoare2][y].second <<    ; n       ++y; n       --nrcub2; n     } n   } n } n int main() { n   int i; n   scanf( %d , &N); n   for (i = 1; i <= N; ++i) { n     scanf( %d%d , &nr[i].c, &nr[i].h); n     axnorm.push_back(nr[i].c); n   } n   solve(); n   afis(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, net, i, flag, d; n   string str; n   cin >> n; n   net = 0; n   flag = 0; n   for (i = 0; i < n; i++) { n     cin >> d; n     cin >> str; n     if ((net == 0) && (str !=  South )) flag = 1; n     if ((net == 20000) && (str !=  North )) flag = 1; n     if (str ==  South ) n       net += d; n     else if (str ==  North ) n       net -= d; n     if (net > 20000 || net < 0) flag = 1; n   } n   if (net != 0) flag = 1; n   if (flag == 1) n     cout <<  NO n ; n   else n     cout <<  YES n ; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   puts( 1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[1200005]; n long long num[30][30]; n int b[1200005], c[1200005], cnt, tot; n long long dp[1200005]; n int main() { n   memset(dp, 0x3f, sizeof dp); n   int n, m; n   scanf( %d%d , &n, &m); n   scanf( %s , s + 1); n   for (int i = 1; i <= n; i++) { n     if (i >= 2) { n       num[s[i - 1] -  a ][s[i] -  a ]++; n       num[s[i] -  a ][s[i - 1] -  a ]++; n     } n     if (i <= n - 1) { n       num[s[i + 1] -  a ][s[i] -  a ]++; n       num[s[i] -  a ][s[i + 1] -  a ]++; n     } n   } n   int all = (1 << m) - 1; n   dp[0] = 0; n   for (int i = 1; i <= all; i++) { n     tot = cnt = 0; n     dp[i] = 1e18; n     for (int j = 0; j < m; j++) { n       if ((i >> j) & 1) { n         b[++cnt] = j; n       } else { n         c[++tot] = j; n       } n     } n     for (int j = 1; j <= cnt; j++) { n       dp[i] = min(dp[i], dp[i ^ (1 << b[j])]); n     } n     for (int j = 1; j <= cnt; j++) { n       for (int k = 1; k <= tot; k++) { n         dp[i] += num[b[j]][c[k]] / 2; n       } n     } n   } n   cout << dp[all] << endl; n } n


#include <bits/stdc++.h> n const int MAXN = 1e6 + 5; n std::vector<int> G[MAXN]; n int f[MAXN][26]; n void dfs(int v) { n   for (register int i = 1; i <= 20; ++i) { n     f[v][i] = f[f[v][i - 1]][i - 1]; n   } n   for (auto x : G[v]) { n     if (x == f[v][0]) continue; n     f[x][0] = v; n     dfs(x); n   } n } n int n, k; n bool vis[MAXN]; n int main() { n   scanf( %d%d , &n, &k); n   for (register int i = 1; i <= n - 1; ++i) { n     int u, v; n     scanf( %d%d , &u, &v); n     G[u].push_back(v); n     G[v].push_back(u); n   } n   int res = n - k; n   f[n][0] = n; n   dfs(n); n   vis[n] = true; n   res--; n   for (register int i = n - 1; i >= 1; --i) { n     if (vis[i]) continue; n     int len = 1, v = i; n     for (register int j = 20; j >= 0; --j) { n       if (vis[f[v][j]]) continue; n       v = f[v][j]; n       len += (1 << j); n     } n     if (len <= res) { n       res -= len; n       int x = i; n       while (true) { n         if (vis[x]) break; n         vis[x] = 1; n         x = f[x][0]; n       } n     } n   } n   for (register int i = 1; i <= n; ++i) n     if (!vis[i]) printf( %d  , i); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100005]; n int main() { n   int n, x; n   cin >> n >> x; n   long int sum = 0, zz; n   for (int i = 0; i < n; i++) cin >> zz, sum += zz; n   if (sum + n - 1 == x) n     cout <<  YES n ; n   else n     cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct qeury { n   int a, b, c; n }; n const int N = 5000 + 5; n int ans[N][N]; n int r[N], cc[N]; n int main() { n   ios_base ::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, m, k; n   cin >> n >> m >> k; n   vector<qeury> q; n   int a, b, c; n   for (int i = 0; i < k; i++) { n     cin >> a >> b >> c; n     q.push_back({a, b, c}); n   } n   reverse(q.begin(), q.end()); n   for (int i = 0; i < q.size(); i++) { n     a = q[i].a; n     b = q[i].b - 1; n     c = q[i].c; n     if (a == 1) { n       if (!r[b]) { n         r[b] = 1; n         for (int j = 0; j < m; j++) { n           if (!ans[b][j]) { n             ans[b][j] = c; n           } n         } n       } n     } else { n       if (!cc[b]) { n         cc[b] = 1; n         for (int j = 0; j < n; j++) { n           if (!ans[j][b]) { n             ans[j][b] = c; n           } n         } n       } n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cout << ans[i][j]; n       if (j < m - 1) cout <<    ; n     } n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int NMAX = 1e6 + 5; n const int MOD = 998244353; n long long lgput(long long b, long long p) { n   long long r = 1; n   while (p) { n     if (p & 1) { n       r = 1LL * r * b % MOD; n     } n     p >>= 1; n     b = b * b % MOD; n   } n   return r; n } n long long N; n vector<long long> lista[NMAX + 5]; n long long good_kids[NMAX + 5]; n long long cati[NMAX + 5]; n long long total = 0, special = 0; n long long answer = 0; n void solve() { n   cin >> N; n   for (long long i = 1; i <= N; ++i) { n     cin >> cati[i]; n     for (long long j = 1; j <= cati[i]; ++j) { n       long long x; n       cin >> x; n       good_kids[x]++; n       lista[i].push_back(x); n     } n     total = (total + 1LL * N * cati[i] % MOD) % MOD; n   } n   for (long long i = 1; i <= N; ++i) { n     for (auto gift : lista[i]) { n       long long expected = n           1LL * lgput(N, MOD - 2) * lgput(cati[i], MOD - 2) % MOD; n       expected = n           1LL * expected * lgput(N, MOD - 2) % MOD * good_kids[gift] % MOD; n       answer = (answer + expected) % MOD; n     } n   } n   cout << answer <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   long long t; n   t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 4, Mod = 1e9 + 7; n struct Mint { n   int res; n   Mint() { res = 0; } n   Mint(int a) : res(a) {} n   friend Mint operator+(Mint A, Mint B) { n     return Mint((A.res + B.res >= Mod) ? (A.res + B.res - Mod) n                                        : (A.res + B.res)); n   } n   friend Mint& operator+=(Mint& A, Mint B) { return A = A + B; } n   friend Mint operator-(Mint A, Mint B) { n     B.res = Mod - B.res; n     return A + B; n   } n   friend Mint operator-(Mint A) { return Mint(Mod - A.res); } n   friend Mint operator+(Mint A) { return A; } n   friend Mint& operator-=(Mint& A, Mint B) { return A = A - B; } n   friend Mint operator*(Mint A, Mint B) { return 1ll * A.res * B.res % Mod; } n   friend Mint& operator*=(Mint& A, Mint B) { return A = A * B; } n   friend Mint operator~(Mint A) { n     static Mint res; n     res = Mint(1); n     static int k; n     k = Mod - 2; n     for (; k; k >>= 1, A *= A) (k & 1) && (res = res * A, 0); n     return res; n   } n   friend Mint operator/(Mint A, Mint B) { return A * (~B); } n   friend Mint& operator/=(Mint& A, Mint B) { return A *= (~B); } n   friend Mint operator>>(Mint A, Mint B) { return Mint(A.res / B.res); } n   friend Mint& operator>>=(Mint& A, Mint B) { return A = A >> B; } n }; n Mint fac[N], ifac[N]; n inline Mint C(int n, int k) { return fac[n] * ifac[n - k] * ifac[k]; } n int n, k; n Mint dp[N], pre[N]; n int main() { n   scanf( %d%d , &n, &k); n   fac[0] = Mint(1); n   for (register int i = (1); i <= (n); ++i) fac[i] = fac[i - 1] * Mint(i); n   ifac[n] = ~fac[n]; n   for (register int i = (n - 1); i >= (0); --i) n     ifac[i] = ifac[i + 1] * Mint(i + 1); n   dp[0] = pre[0] = Mint(1); n   for (register int i = (1); i <= (n - 1); ++i) n     dp[i] = n         (pre[i - 1] - ((i - k > 0) ? pre[i - k - 1] : Mint(0))) * fac[i - 1], n     pre[i] = pre[i - 1] + dp[i] * ifac[i]; n   Mint res; n   for (register int i = (1); i <= (n); ++i) n     res += dp[i - 1] * fac[n - i] * C(n - 1, n - i); n   printf( %d n , (fac[n] - res).res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, char **argv) { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   ; n   int n; n   cin >> n; n   vector<int> indeg(n); n   queue<int> deg1; n   vector<int> xorV(n); n   for (int i = 0; i < n; i++) { n     cin >> indeg[i] >> xorV[i]; n     if (indeg[i] == 1) deg1.push(i); n   } n   set<pair<int, int> > edges; n   while (deg1.size() > 0) { n     int v = deg1.front(); n     deg1.pop(); n     int u = xorV[v]; n     if (--indeg[u] == 1) deg1.push(u); n     if (indeg[u] > 0) xorV[u] ^= v; n     if (v > u) swap(u, v); n     edges.insert({u, v}); n   } n   cout << edges.size() << endl; n   for (auto &edg : edges) { n     cout << edg.first <<     << edg.second << endl; n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n unsigned int ip[100005]; n unsigned int const one = -1; n int main() { n   int n, k; n   cin >> n >> k; n   for (int i = 0; i < n; i++) { n     unsigned int a, b, c, d; n     scanf( %u.%u.%u.%u , &a, &b, &c, &d); n     ip[i] = (a << 24) + (b << 16) + (c << 8) + d; n   } n   unsigned int mask = 0; n   set<unsigned int> S; n   for (int i = 1; i < 32; i++) { n     mask = one << (32 - i); n     for (int j = 0; j < n; j++) { n       S.insert(mask & ip[j]); n     } n     if (S.size() == k) { n       unsigned int a, b, c, d; n       a = mask >> 24; n       b = (mask << 8) >> 24; n       c = (mask << 16) >> 24; n       d = (mask << 24) >> 24; n       printf( %u.%u.%u.%u , a, b, c, d); n       return 0; n     } n     S.clear(); n   } n   cout << -1; n   return 0; n } n


// Murabito-B 21/04/13 n #include <bits/stdc++.h> n using namespace std; n using ll = long long; n void solve() { n     int a, b, c; n     cin >> a >> b >> c; n     for (int i = 0; i <= a - c; ++i) cout << 1; n     for (int i = 1; i < c; ++i) cout << 0; n     cout <<   1 ; n     for (int i = 1; i < b; ++i) cout << 0; n     cout <<   n ; n } n int main() { n     ios_base::sync_with_stdio(false), cin.tie(0); n     int _; n     for (cin >> _; _--;) solve(); n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n const long double pi = acos(-1); n const long long M = 1e9 + 7; n const long long N = 5e5; n const long long INF = 1e9 + 1; n long long n, a[N], x[N], res, ans; n int main() { n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n   } n   for (int j = 1; j <= n; ++j) { n     for (int i = 1; i <= n; ++i) { n       if (x[i] != 1 && ans >= a[i]) { n         x[i] = 1; n         ans++; n       } n     } n     if (ans == n) { n       break; n     } n     res++; n     for (int i = n; i >= 1; --i) { n       if (x[i] != 1 && ans >= a[i]) { n         x[i] = 1; n         ans++; n       } n     } n     if (ans == n) { n       break; n     } n     res++; n   } n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); } n long long logg(long long x, long long y) { n   if (x == 0) return -1; n   return logg(x / y, y) + 1; n } n long long poww(long long a, long long b, long long m) { n   if (b == 0) return 1; n   long long ans = 1; n   ans = poww(a, b >> 1, m); n   ans = (ans * ans) % m; n   if (b & 1) ans = (ans * a) % m; n   return ans; n } n int32_t main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   long long n, k; n   cin >> n >> k; n   long long a[n], b[n]; n   for (long long i = 0; i < n; i++) cin >> a[i], b[i] = a[i]; n   sort(b, b + n, greater<long long>()); n   long long sum = 0; n   map<long long, long long> mp; n   for (long long i = 0; i < k; i++) sum += b[i], mp[b[i]]++; n   long long count = 0; n   vector<long long> ans; n   for (long long i = 0; i < n; i++) { n     if (k == 1) { n       ans.push_back(n - i); n       break; n     } n     if (mp.count(a[i])) n       count++, ans.push_back(count), count = 0, mp[a[i]]--, k--; n     else n       count++; n     if (mp[a[i]] == 0) mp.erase(a[i]); n   } n   cout << sum <<   n ; n   for (auto i : ans) cout << i <<    ; n } n


#include<bits/stdc++.h> n using namespace std; n  n #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); n #define int long long n #define line cout<< [At  <<__LINE__<< ] <<endl; n #define size(x) ((int)x.size()) n  n namespace Debug{ n   void __print(signed x){cout << x;} n   void __print(long x){cout << x;} n   void __print(long long x){cout << x;} n   void __print(unsigned x){cout << x;} n   void __print(unsigned long x){cout << x;} n   void __print(unsigned long long x){cout << x;} n   void __print(float x){cout << x;} n   void __print(double x){cout << x;} n   void __print(long double x){cout << x;} n   void __print(char x){cout <<      << x <<     ;} n   void __print(const char *x){cout <<     << x <<    ;} n   void __print(const string &x){cout <<     << x <<    ;} n   void __print(bool x){cout << (x ?  true  :  false );} n   template<typename T, typename V> void __print(const pair<T, V> &x){cout <<  { ;__print(x.first);cout <<  , ;__print(x.second);cout <<  } ;} n   template<typename T> void __print(const T &x){int f = 0;cout <<  { ;for (auto &i : x) cout << (f++ ?  ,  :   ), __print(i);cout <<  } ;} n   void _print(){cout <<  ] <<endl;} n   template <typename T, typename... V> void _print(T t, V... v){__print(t);if (sizeof...(v)) cout <<  ,  ;_print(v...);} n    n   #define debug(x...) cout << Line: <<__LINE__<<   [  << #x <<  ] = [ ; _print(x); n   #define deb(x...) cout << [  << #x <<  ] = [ ; _print(x); n }using namespace Debug; n  n  n const int mod = (int)1e9 + 7ll; n  n int dp[2000][2000][2], n; n  n int shoot(int plane, int k, int dir){ n  if(plane > n || plane < 1 || k == 1) n   return 1l; n  n   if(dp[plane][k][dir] != -1) n    return dp[plane][k][dir]; n  n   int res = 0l; n  n   if(dir == 0){ n    res = shoot(plane + 1, k, dir); n    res += shoot(plane - 1, k - 1, 1 - dir); n   } n   else{ n    res = shoot(plane - 1, k, dir); n    res += shoot(plane + 1, k - 1, 1 - dir); n   } n  n   res %= mod; n   return dp[plane][k][dir] = res; n } n  n void process(){ n  int k; n  cin >> n >> k; n  cout << shoot(1, k, 0) <<   n ; n } n  n signed main() { n  IOS; n  int t = 1; n  cin >> t; n  while(t--){ n   memset(dp, -1, sizeof(dp)); n   process(); n  } n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n int n, m, c, a, b; n int main() { n   scanf( %d , &n); n   while (n--) { n     scanf( %d%d , &a, &b); n     if (a != b) n       if (a > b) n         m++; n       else n         c++; n   } n   if (m != c) n     if (m > c) n       printf( Mishka ); n     else n       printf( Chris ); n   else n     printf( Friendship is magic!^^ ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   stringstream ss; n   string s; n   cin >> s; n   for (int i = 0; i < s.length(); i++) { n     switch (s[i]) { n       case  > : n         ss << 1000; n         break; n       case  < : n         ss << 1001; n         break; n       case  + : n         ss << 1010; n         break; n       case  - : n         ss << 1011; n         break; n       case  . : n         ss << 1100; n         break; n       case  , : n         ss << 1101; n         break; n       case  [ : n         ss << 1110; n         break; n       case  ] : n         ss << 1111; n         break; n       default: n         break; n     } n   } n   string ans = ss.str(); n   int os = 1; n   long long jawab = 0; n   for (int i = ans.length() - 1; i >= 0; i--) { n     if (ans[i] ==  1 ) jawab = (jawab + os) % 1000003; n     os = (os * 2) % 1000003; n   } n   cout << jawab << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = 2.0 * acos(0.0); n const double EPS = 1e-9; n const int MOD = 1000000007; n const int INF = 1000000000; n const long long LINF = 1000000000000000000LL; n int main() { n   int r, h, ret, m, x; n   scanf( %d %d , &r, &h); n   r *= 2, h *= 2, ret = h / r * 2, m = h % r, x = m + r / 2; n   if (m >= r / 2) ret += 2, x -= r; n   if ((0.5 * r * (sqrt(3.0) + 1.0) - 1.0 * x - 1.0 * r) < EPS) ret++; n   printf( %d n , ret); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100005; n struct ask { n   int l, r, cur; n } tmp; n long long pre[maxn], suf[maxn], s[maxn], d[maxn], h[maxn], ans[maxn]; n vector<ask> V, W; n int n, m, a, b; n long long solve(int l, int r, vector<ask> &V) { n   if (l == r) return 0; n   int mid = (l + r) >> 1; n   long long best; n   vector<ask> Vl, Vr, Vt; n   pre[mid] = 0; n   for (int i = (mid + 1); i <= int(r); i++) n     pre[i] = max(pre[i - 1], s[i] - s[mid] + 2 * h[i]); n   suf[mid + 1] = 0; n   for (int i = (mid); i >= (l); i--) n     suf[i] = max(suf[i + 1], s[mid] - s[i] + 2 * h[i]); n   for (auto x : V) n     if (x.r <= mid) n       Vl.push_back(x); n     else if (mid + 1 <= x.l) n       Vr.push_back(x); n     else if (l != x.l || r != x.r) { n       ans[x.cur] = max(ans[x.cur], suf[x.l] + pre[x.r]); n       Vl.push_back((ask){x.l, mid, x.cur}); n       Vr.push_back((ask){mid + 1, x.r, x.cur}); n     } n   best = pre[r] + suf[l]; n   best = max(best, solve(l, mid, Vl)); n   best = max(best, solve(mid + 1, r, Vr)); n   for (auto x : V) n     if (l == x.l && r == x.r) ans[x.cur] = max(ans[x.cur], best); n   return best; n } n void solve2() { n   pre[0] = 0; n   for (int i = (1); i <= int(n); i++) n     pre[i] = max(pre[i - 1], s[i] - s[1] + 2 * h[i]); n   suf[n + 1] = 0; n   for (int i = (n); i >= (1); i--) n     suf[i] = max(suf[i + 1], s[n + 1] - s[i] + 2 * h[i]); n   for (auto x : W) ans[x.cur] = max(ans[x.cur], pre[x.l] + suf[x.r]); n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = (1); i <= int(n); i++) n     scanf( %I64d , &d[i]), s[i + 1] = s[i] + d[i]; n   for (int i = (1); i <= int(n); i++) scanf( %I64d , &h[i]); n   for (int i = (1); i <= int(m); i++) { n     scanf( %d%d , &a, &b); n     if (a <= b) { n       if (3 <= a) V.push_back((ask){1, a - 1, i}); n       if (b <= n - 2) V.push_back((ask){b + 1, n, i}); n       if (2 <= a && b <= n - 1) W.push_back((ask){a - 1, b + 1, i}); n     } else n       V.push_back((ask){b + 1, a - 1, i}); n   } n   solve(1, n, V); n   solve2(); n   for (int i = (1); i <= int(m); i++) printf( %I64d n , ans[i]); n   return 0; n } n


n #include <bits/stdc++.h> n #define int long long n #define ld long double n #define vc vector n #define s second n #define f first n  n  n //#include  prettyprint.hpp  n  n using namespace std; n  n  n typedef pair <int, int> pii; n int n, m; n int t(int a){ n     return a+n; n } n int mod=998244353; n vc< vc <int> > anz, suf, pref; n  n bool g (int a, int b){ n     if (a<0 || b<0) return false; n     if (a >n || b >=m) return false; n     return true; n } n  n int h (int a, int b){ n     if (a<0 || a>n) return 1; n     return 0; n } n  n int an(int a ,int b){ n     return g(a, b)? anz[a][b] : h(a, b); n } n  n int su(int a ,int b){ n     return g(a, b)? suf[a][b] : h(a, b); n } n  n int pre(int a ,int b){ n     return g(a, b)? pref[a][b] : h(a, b); n } n int plu (int & a, int b){ n     return a =(a+b)%mod; n } n  n int mult (int a, int b){ n     return a*b % mod; n } n  n int calc_inst(int i, int j){ n     int s1 = mult(mult(an(i, j), an(n-i+1, j-1)), su(n-i, m-j)); n  n     int s2 = mult(mult(an(i, j), an(i+1, m-j-1)), pre(i, m-j+1)); n  n     return plu(s1, s2); n  n } n int do_calc(){ n     anz = suf = pref = vc <vc <int> > (n+1, vc <int > (m+1)); n  n     vc <vc <int > > b (n+1, vc <int> (m)), c (n+1, vc <int> (m)); n  n     anz[0][0] = 1; n  n  n     for (int i=1; i<=n; i++){ n        anz[i][0] = anz[i-1][0]; n         for (int j=1; j<m; j++){ n             anz[i][j] = (anz[i][j-1]+anz[i-1][j])%mod; n         } n     } n     for (int i=1; i<=n; i++){ n         for (int j=1; j<m; j++){ n             b[i][j] = anz[i][j]*anz[n-i+1][j-1] % mod; n             suf[i][j] = (suf[i-1][j]+b[i][j])%mod; n         } n  n     } n  n  n     for (int i=1; i<n; i++){ n         for (int k=m-1; k>=2; k--){ n             c[i][k] = anz[n-i][k]*anz[n-i+1][m-k-1]%mod; n             pref[i][k]=(pref[i][k+1]+c[i][k])%mod; n         } n  n     } n  n  n  n     int ret = 0; n     for (int i=1; i<=n; i++){ n         for (int j=1; j<m; j++){ n             plu(ret, calc_inst(i, j)); n         } n     } n     return ret; n  n } n  n void do_test(){ n  n  n     cin >> n >> m; n     int res= do_calc(); n     //a1 = very_balanced(); n    // cout << res <<   n ; n     //swap(n, m); n   //  a2 = very_balanced(); n    // res1=do_calc(); n     //assert(a1 == a2); n //a1 = (n-1)*(m-1); n  n     res = 2*res%mod; n  n    // cout <<  res1   << res1 <<     << res2 <<   a   << a1 <<      << a2 <<     << endl; n  n     cout << res <<   n ; n  n     //cout << a << endl; n  n } n signed main(){ n     ios_base::sync_with_stdio(false); n  n  n     do_test(); n } n


#include <bits/stdc++.h> n using namespace std; n mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count()); n int a[105], vis[105]; n vector<int> v[105]; n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= 2 * n; ++i) cin >> a[i]; n   int ans = 0; n   for (int i = 1; i <= 2 * n; ++i) { n     if (vis[a[i]]) continue; n     vis[a[i]] = 1; n     for (int j = i + 1; a[j] != a[i]; ++j) n       if (!vis[a[j]]) ++ans; n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n const double PI = acos(-1.0); n const int maxn = 1e6; n const int INF = 0x3f3f3f; n const long long linf = 0x3f3f3f3f3f3f3f3f; n const int mod = 1e9 + 7; n using namespace std; n struct node { n   int a, b, color; n } edge[maxn]; n int n, m, ans; n int vis[maxn]; n vector<int> v[maxn]; n void dfs(int x, int fa) { n   if (vis[x]) { n     if (x == fa) ans = 2; n     return; n   } n   vis[x] = 1; n   for (int i = 0; i < v[x].size(); i++) dfs(v[x][i], fa); n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     edge[i].a = a; n     edge[i].b = b; n     edge[i].color = 1; n     v[a].push_back(b); n   } n   ans = 1; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) vis[j] = 0; n     dfs(i, i); n   } n   cout << ans << endl; n   if (ans == 1) { n     for (int i = 0; i < m; i++) cout << 1 <<    ; n     cout << endl; n   } else { n     for (int i = 1; i <= m; i++) { n       if (edge[i].a < edge[i].b) edge[i].color = 2; n     } n     for (int i = 1; i <= m; i++) cout << edge[i].color <<    ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n priority_queue<int, vector<int>, greater<int> > q1, q2; n int x[200005]; n int main() { n   int n, z, ans = 0; n   cin >> n >> z; n   for (int i = 0; i < n; i++) cin >> x[i]; n   sort(x, x + n); n   int l1 = n >> 1; n   for (int i = 0; i < l1; i++) q1.push(x[i]); n   for (int i = l1; i < n; i++) q2.push(x[i]); n   while (!q2.empty()) { n     if (!q1.empty() && q2.top() - q1.top() >= z) { n       ans++; n       q1.pop(); n       q2.pop(); n     } else { n       q1.push(q2.top()); n       q2.pop(); n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, m; n int a[100000]; n int base = int(1e9 + 7); n int lucky[2000]; n long long co[2000]; n long long f[2000][2000]; n long long unlucky; n long long frac[100001]; n long long c[100001]; n int size = 1100; n int r1, r2; n int getBit(int, int); n void create(); n int find(int); n long long inpow(long long, long long); n void calCombination(); n void dp(); n int main() { n   cin >> n >> k; n   create(); n   for (int i = 0; i < n; i++) { n     fscanf(stdin,  %d , &a[i]); n     int pos = find(a[i]); n     if (pos != -1) { n       co[pos]++; n     } else n       unlucky++; n   } n   calCombination(); n   dp(); n   long long res = 0; n   f[m - 1][0] = 1; n   for (int j = 0; j <= k; j++) { n     res = (res + f[m - 1][j] * c[k - j]) % base; n   } n   cout << res << endl; n   return 0; n } n int getBit(int x, int i) { return ((x & (1 << i)) != 0); } n void create() { n   m = 0; n   for (int ndig = 1; ndig <= 9; ndig++) n     for (int i = 0; i < (1 << ndig); i++) { n       int cur = 0; n       for (int j = ndig - 1; j >= 0; j--) n         if (getBit(i, j) == 0) n           cur = cur * 10 + 4; n         else n           cur = cur * 10 + 7; n       lucky[m++] = cur; n     } n } n int find(int x) { n   int lo, hi; n   lo = 0; n   hi = m - 1; n   while (lo <= hi) { n     int mid = (lo + hi) / 2; n     if (x == lucky[mid]) return mid; n     if (x < lucky[mid]) n       hi = mid - 1; n     else n       lo = mid + 1; n   } n   return -1; n } n long long inpow(long long x, long long p) { n   if (p == 1) return x % base; n   if (p % 2 == 0) { n     long long t = inpow(x, p / 2); n     return (t * t) % base; n   } else n     return (x * inpow(x, p - 1)) % base; n } n void calCombination() { n   frac[0] = 1; n   for (int i = 1; i <= unlucky; i++) frac[i] = (frac[i - 1] * i) % base; n   c[0] = 1; n   c[1] = unlucky; n   for (long long i = 2; i <= unlucky; i++) { n     c[i] = n         frac[unlucky] * inpow((frac[i] * frac[unlucky - i]) % base, base - 2); n     c[i] = c[i] % base; n   } n } n void dp() { n   for (int i = 0; i < m; i++) f[i][0] = 1; n   f[0][1] = co[0]; n   for (int i = 1; i < m; i++) n     for (int j = 1; j <= (i + 1); j++) n       f[i][j] = (f[i - 1][j - 1] * co[i] + f[i - 1][j]) % base; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[101]; n long long vis[101]; n long long judge(vector<long long> A) { n   if (A.empty()) return 0; n   for (long long i = 0; i < A.size(); i++) { n     if (A[i] != i) return i; n   } n   return A.size(); n } n signed main() { n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     for (long long i = 1; i <= n; i++) cin >> a[i]; n     sort(a + 1, a + n + 1); n     memset(vis, 0, sizeof vis); n     vector<long long> A, B; n     vis[1] = 1; n     A.push_back(a[1]); n     for (long long i = 2; i <= n; i++) { n       if (a[i] != a[i - 1]) { n         vis[i] = 1; n         A.push_back(a[i]); n       } n     } n     for (long long i = 1; i <= n; i++) { n       if (!vis[i]) { n         B.push_back(a[i]); n       } n     } n     B.erase(unique(B.begin(), B.end()), B.end()); n     cout << judge(A) + judge(B) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000 + 10; n int n, m; n int px[] = {0, 1, -1, 0}; n int py[] = {1, 0, 0, -1}; n bool dig[10]; n char a[N][N]; n bool inside(int x, int y) { return x >= 0 && y >= 0 && x < n && y < m; } n bool alone(int x, int y) { n   int k, x2, y2; n   for (k = 0; k < 4; k++) { n     x2 = x + px[k]; n     y2 = y + py[k]; n     if (!inside(x2, y2)) continue; n     if (a[x2][y2] ==  . ) return false; n   } n   return true; n } n void go(int x, int y) { n   a[x][y] =  * ; n   int k, x2, y2; n   for (k = 0; k < 4; k++) { n     x2 = x + px[k]; n     y2 = y + py[k]; n     if (!inside(x2, y2)) continue; n     if (a[x2][y2] ==  X ) go(x2, y2); n     if (isdigit(a[x2][y2])) dig[a[x2][y2] -  0 ] = 1; n   } n } n char getColor(int x, int y) { n   memset(dig, 0, sizeof(dig)); n   go(x, y); n   int i; n   for (i = 0; i < 10; i++) n     if (dig[i] == 0) return  0  + i; n   assert(false); n } n void fill(int x, int y, char c) { n   a[x][y] = c; n   int k, x2, y2; n   for (k = 0; k < 4; k++) { n     x2 = x + px[k]; n     y2 = y + py[k]; n     if (!inside(x2, y2)) continue; n     if (a[x2][y2] ==  * ) fill(x2, y2, c); n   } n } n void print() { n   int i; n   for (i = 0; i < n; i++) printf( %s n , a[i]); n   printf(  n n ); n } n int main() { n   scanf( %d%d , &n, &m); n   int i, j, k, t; n   for (i = 0; i < n; i++) scanf( %s , a[i]); n   int x[3], y[3]; n   for (i = 0; i < n; i++) n     for (j = 0; j < m; j++) { n       if (a[i][j] !=  . ) continue; n       x[0] = i; n       y[0] = j; n       for (k = 0; k < 2; k++) { n         x[1] = x[0] + px[k]; n         y[1] = y[0] + py[k]; n         if (!inside(x[1], y[1])) continue; n         if (a[x[1]][y[1]] ==  . ) break; n       } n       if (k == 2) { n         printf( -1 n ); n         return 0; n       } n       a[x[0]][y[0]] =  X ; n       a[x[1]][y[1]] =  X ; n       for (t = 0; t < 2; t++) { n         for (k = 0; k < 4; k++) { n           x[2] = x[t] + px[k]; n           y[2] = y[t] + py[k]; n           if (!inside(x[2], y[2])) continue; n           if (a[x[2]][y[2]] !=  . ) continue; n           if (alone(x[2], y[2])) a[x[2]][y[2]] =  X ; n         } n       } n       fill(x[0], y[0], getColor(x[0], y[0])); n     } n   for (i = 0; i < n; i++) printf( %s n , a[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[1000009]; n int pre[10000009]; n vector<long long> alr; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   reverse(a, a + n); n   long long ans = 0, ans1 = 0; n   int taken = 0; n   for (int i = 0; i < n; i++) { n     pre[a[i]]++; n   } n   for (int i = 0; i < n; i++) { n     if (pre[a[i]] % 2 == 1) { n       if (pre[a[i] - 1] > 0) n         pre[a[i]]--, pre[a[i] - 1]++; n       else n         pre[a[i]]--; n     } n   } n   int x = 0, y = 0, l = 0, r = 2; n   while (l < n && r < n) { n     if (pre[a[l]] >= 2 && pre[a[r]] >= 2) { n       if (a[l] == a[r] && pre[a[r]] < 4) { n         r++; n         continue; n       } n       pre[a[l]] -= 2; n       pre[a[r]] -= 2; n       ans += a[l] * a[r]; n     } else if (pre[a[r]] < 2 && pre[a[l]] >= 2) n       r++; n     else if (pre[a[r]] >= 2 && pre[a[l]] < 2) n       l++; n     else if (pre[a[r]] < 2 && pre[a[l]] < 2) n       l++, r++; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T inline sqr(T x) { n   return x * x; n } n template <class T> n inline void relaxMin(T &a, T b) { n   a = min(a, b); n } n template <class T> n inline void relaxMax(T &a, T b) { n   a = max(a, b); n } n string str(int i) { n   char s[100]; n   sprintf(s,  %d , i); n   return string(s); n } n inline int sign(int x) { return x > 0 ? 1 : (x < 0 ? -1 : 0); } n inline int myAbs(int a) { return a > 0 ? a : -a; } n const int mlen = (int)2e5 + 10; n int n; n char s[mlen]; n int main() { n   gets(s); n   n = strlen(s); n   int i = 0; n   while (i < n && s[i] <= 32) i++; n   while (i < n) { n     char ch = s[i]; n     int l; n     if (ch ==  , ) n       l = 1; n     else if (ch ==  . ) n       l = 3; n     else n       l = n; n     while (l > 0 && i < n && isdigit(ch) == isdigit(s[i])) putchar(s[i++]), l--; n     while (i < n && s[i] <= 32) i++; n     if (i < n && (ch ==  ,  || s[i] ==  .  || (isdigit(ch) && isdigit(s[i])))) n       putchar(   ); n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool ex[100]; n int att[100]; n int de[100]; n int jo[100]; n int n, m, n1, n2; n int ae() { n   int ina = 0; n   int inb = 0; n   pair<int, bool> mi[200]; n   for (int i = 0; i < n1; i++) mi[i].first = att[i], mi[i].second = 0; n   for (int i = n1; i < n1 + m; i++) { n     mi[i].first = jo[i - n1], mi[i].second = 1; n   } n   sort(mi, mi + m + n1); n   int v = 0; n   int y = 0; n   for (int i = 0; i < n1 + m; i++) { n     if (mi[i].second == 0) n       v++; n     else if (v) { n       v--; n       y++; n     } n   } n   int v1 = 0; n   int vt = 0; n   for (int i = 0; i < y; i++) { n     vt = jo[m - i - 1] - att[i]; n     if (vt > 0) v1 += vt; n   } n   return v1; n } n bool di() { n   int in1 = 0; n   int in2 = 0; n   while (true) { n     if (in2 == n2) return true; n     if (in1 == m) return false; n     while (jo[in1++] <= de[in2]) { n       if (in1 == m) return false; n     } n     in1--; n     ex[in1] = 1; n     in1++, in2++; n   } n } n bool di2() { n   int in1 = 0; n   int in2 = 0; n   while (true) { n     if (in2 == n1) return true; n     if (in1 == m) return false; n     while (ex[in1++] == 1) n       ; n     in1--; n     if (in1 == m) return 0; n     while (jo[in1++] < att[in2]) { n       if (in1 == m) return false; n     } n     in1--; n     in1++, in2++; n   } n } n int main() { n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     string s; n     int t; n     cin >> s >> t; n     if (s[0] ==  A ) { n       att[n1++] = t; n     } else { n       de[n2++] = t; n     } n   } n   for (int i = 0; i < m; i++) cin >> jo[i]; n   sort(jo, jo + m); n   sort(de, de + n2); n   sort(att, att + n1); n   int m1 = 0; n   if (di() && di2()) { n     for (int i = 0; i < m; i++) n       if (!(ex[i] == 1)) m1 += jo[i]; n     for (int i = 0; i < n1; i++) m1 -= att[i]; n   } n   cout << max(m1, ae()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const long long LINF = 0x3f3f3f3f3f3f3f3fll; n template <typename T, bool MULTI = false, typename SIZE_T = int> n struct sms_mo { n   static_assert(std::is_integral<T>::value,  Not an integral type ); n   static_assert(std::is_integral<SIZE_T>::value,  Not an integral type ); n   struct node { n     node* ch[2]; n     SIZE_T cnt; n     char d; n     T v, mi; n     node(int d_, T v_, SIZE_T cnt_) : cnt(cnt_), d(d_), v(v_), mi(v) { n       ch[0] = ch[1] = NULL; n     } n     node(node* x, bool b = true) : cnt(x->cnt), d(x->d), v(x->v), mi(x->mi) { n       if (b) n         ch[0] = x->ch[0], ch[1] = x->ch[1]; n       else n         ch[0] = ch[1] = NULL; n     } n     void update() { n       if (!ch[0] ^ !ch[1]) { n         for (int i = 0; i < 2; i++) n           if (ch[i]) { n             node* tmp = ch[i]; n             ch[0] = tmp->ch[0], ch[1] = tmp->ch[1]; n             d = tmp->d, v = tmp->v; n             cnt = tmp->cnt, mi = tmp->mi; n             delete tmp; n             return; n           } n       } n       cnt = 0; n       mi = std::numeric_limits<T>::max(); n       for (int i = 0; i < 2; i++) n         if (ch[i]) { n           cnt += ch[i]->cnt; n           mi = std::min(mi, ch[i]->mi); n         } n     } n   }; n   node* root; n   T N; n   char n; n   sms_mo() : root(NULL), N(0), n(0) {} n   sms_mo(T v) : sms_mo() { n     while (v >> n) n++, N = 2 * N + 1; n   } n   sms_mo(const sms_mo& t) : root(NULL), N(t.N), n(t.n) { n     if (!t.root) return; n     root = new node(t.root, false); n     std::vector<std::pair<node*, node*>> q = {{root, t.root}}; n     while (q.size()) { n       auto [x, y] = q.back(); n       q.pop_back(); n       for (int i = 0; i < 2; i++) n         if (y->ch[i]) { n           x->ch[i] = new node(y->ch[i], false); n           q.emplace_back(x->ch[i], y->ch[i]); n         } n     } n   } n   sms_mo(std::initializer_list<T> v) : sms_mo() { n     for (T i : v) insert(i); n   } n   ~sms_mo() { n     std::vector<node*> q = {root}; n     while (q.size()) { n       node* x = q.back(); n       q.pop_back(); n       if (!x) continue; n       q.push_back(x->ch[0]), q.push_back(x->ch[1]); n       delete x; n     } n   } n   friend void swap(sms_mo& a, sms_mo& b) { n     std::swap(a.root, b.root), std::swap(a.N, b.N), std::swap(a.n, b.n); n   } n   sms_mo& operator=(const sms_mo& v) { n     sms_mo tmp = v; n     swap(tmp, *this); n     return *this; n   } n   SIZE_T size() const { return root ? root->cnt : 0; } n   SIZE_T count(node* x) const { return x ? x->cnt : 0; } n   void clear() { n     sms_mo tmp; n     swap(*this, tmp); n   } n   void expand(T v) { n     while (v >> n) n++, N = 2 * N + 1; n   } n   char msb(T v, char l, char r) { n     for (char i = r; i > l; i--) n       if (v >> i & 1) return i; n     return -1; n   } n   void cut(node* at, T v, char i, node* prev = NULL) { n     char d = msb(v ^ at->v, prev ? std::max(at->d, prev->d) : at->d, i); n     if (d == -1) { n       if (!prev or prev->d <= at->d) return; n       d = prev->d, v = ~at->v; n     } n     node* nxt = new node(at); n     at->ch[v >> d & 1] = NULL; n     at->ch[!(v >> d & 1)] = nxt; n     at->d = d; n   } n   node* insert(node* at, T v, SIZE_T qt, char i) { n     if (!at) return new node(-1, v, qt); n     cut(at, v, i); n     if (at->d == -1) { n       at->cnt += qt; n       at->mi = v; n       if (!MULTI) at->cnt = 1; n       return at; n     } n     bool dir = v >> at->d & 1; n     at->ch[dir] = insert(at->ch[dir], v, qt, at->d - 1); n     at->update(); n     return at; n   } n   void insert(T v, SIZE_T qt = 1) { n     if (qt <= 0) return erase(v, -qt); n     expand(v); n     root = insert(root, v, qt, n - 1); n   } n   node* erase(node* at, T v, SIZE_T qt, char i) { n     if (!at) return at; n     if (at->d == -1) n       at->cnt = at->cnt < qt ? 0 : at->cnt - qt; n     else { n       bool dir = v >> at->d & 1; n       at->ch[dir] = erase(at->ch[dir], v, qt, i - 1); n       at->update(); n     } n     if (!at->cnt) delete at, at = NULL; n     return at; n   } n   void erase(T v, SIZE_T qt = 1) { n     if (v < 0 or v > N or !qt) return; n     if (qt < 0) insert(v, -qt); n     if (!count(v)) return; n     root = erase(root, v, qt, n - 1); n   } n   void erase_all(T v) { n     if (v < 0 or v > N or !count(v)) return; n     root = erase(root, v, std::numeric_limits<SIZE_T>::max(), n - 1); n   } n   SIZE_T count(node* at, T a, T b, T l, T r, char i) const { n     if (!at or b < l or r < a) return 0; n     if (a <= l and r <= b) return at->cnt; n     T m = l + (r - l) / 2; n     if (at->d < i) { n       if ((at->v >> i & 1) == 0) n         return count(at, a, b, l, m, i - 1); n       else n         return count(at, a, b, m + 1, r, i - 1); n     } n     return count(at->ch[0], a, b, l, m, i - 1) + n            count(at->ch[1], a, b, m + 1, r, i - 1); n   } n   SIZE_T count(T v) const { return count(root, v, v, 0, N, n - 1); } n   SIZE_T order_of_key(T v) { return count(root, 0, v - 1, 0, N, n - 1); } n   SIZE_T lower_bound(T v) { return order_of_key(v); } n   const T operator[](SIZE_T k) const { n     node* at = root; n     T l = 0, r = N; n     char i = n - 1; n     while (l < r) { n       T m = l + (r - l) / 2; n       if (at->d < i) { n         if ((at->v >> i & 1) == 0) n           r = m; n         else n           l = m + 1; n         i--; n         continue; n       } n       if (count(at->ch[0]) > k) n         at = at->ch[0], r = m; n       else { n         k -= count(at->ch[0]); n         at = at->ch[1]; n         l = m + 1; n       } n       i--; n     } n     return l; n   } n   node* merge(node* l, node* r, char i) { n     if (!l or !r) return l ? l : r; n     cut(l, r->v, i, r), cut(r, l->v, i, l); n     if (l->d == -1) { n       if (MULTI) l->cnt += r->cnt; n       delete r; n       return l; n     } n     for (int j = 0; j < 2; j++) l->ch[j] = merge(l->ch[j], r->ch[j], l->d - 1); n     l->update(), delete r; n     return l; n   } n   void merge(sms_mo& s) { n     if (N > s.N) swap(*this, s); n     expand(s.N); n     root = merge(root, s.root, n - 1); n     s.root = NULL; n   } n   node* split(node*& x, SIZE_T k) { n     if (k <= 0 or !x) return NULL; n     node* ret = new node(x); n     ret->ch[0] = ret->ch[1] = NULL; n     ret->cnt = 0; n     if (x->d == -1) n       x->cnt -= k, ret->cnt += k, ret->mi = x->mi; n     else { n       if (k <= count(x->ch[0])) n         ret->ch[0] = split(x->ch[0], k); n       else { n         ret->ch[1] = split(x->ch[1], k - count(x->ch[0])); n         std::swap(x->ch[0], ret->ch[0]); n       } n       ret->update(), x->update(); n     } n     if (!x->cnt) delete x, x = NULL; n     return ret; n   } n   void split(SIZE_T k, sms_mo& s) { n     s.clear(); n     s.root = split(root, std::min(k, size())); n     s.N = N, s.n = n; n   } n   void split_val(T k, sms_mo& s) { split(order_of_key(k), s); } n   T min() { return root->mi; }; n }; n std::mt19937 dyn_array_rng( n     (int)std::chrono::steady_clock::now().time_since_epoch().count()); n template <typename T, typename SIZE_T = int, n           typename SET = sms_mo<T, true, SIZE_T>> n struct dyn_array { n   static_assert(std::is_integral<T>::value,  Not an integral type ); n   static_assert(std::is_integral<SIZE_T>::value,  Not an integral type ); n   struct node { n     node *l, *r; n     int p; n     SIZE_T sz; n     bool rev, rev_lazy; n     SET val; n     T mi; n     node(SET& v) n         : l(NULL), r(NULL), p(dyn_array_rng()), sz(1), rev(0), rev_lazy(0) { n       swap(val, v); n       mi = val.min(); n     } n     node(node* x) n         : l(NULL), n           r(NULL), n           p(x->p), n           sz(x->sz), n           rev(x->rev), n           rev_lazy(x->rev_lazy), n           val(x->val), n           mi(x->mi) {} n     void prop() { n       if (rev_lazy) { n         rev ^= 1; n         std::swap(l, r); n         if (l) l->rev_lazy ^= 1; n         if (r) r->rev_lazy ^= 1; n       } n       rev_lazy = false; n     } n     void update() { n       sz = val.size(); n       mi = val.min(); n       if (l) sz += l->sz, mi = std::min(mi, l->mi); n       if (r) sz += r->sz, mi = std::min(mi, r->mi); n     } n   }; n   node* root; n   dyn_array() { root = NULL; } n   dyn_array(const dyn_array& v) : root(NULL) { n     if (!v.root) return; n     root = new node(v.root); n     std::vector<std::pair<node*, node*>> q = {{root, v.root}}; n     while (q.size()) { n       auto [x, y] = q.back(); n       q.pop_back(); n       if (y->l) { n         x->l = new node(y->l); n         q.emplace_back(x->l, y->l); n       } n       if (y->r) { n         x->r = new node(y->r); n         q.emplace_back(x->r, y->r); n       } n     } n   } n   dyn_array(std::initializer_list<T> v) : dyn_array() { n     for (T i : v) push_back(i); n   } n   ~dyn_array() { n     std::vector<node*> q = {root}; n     while (q.size()) { n       node* x = q.back(); n       q.pop_back(); n       if (!x) continue; n       q.push_back(x->l), q.push_back(x->r); n       delete x; n     } n   } n   friend void swap(dyn_array& a, dyn_array& b) { std::swap(a.root, b.root); } n   dyn_array& operator=(const dyn_array& v) { n     dyn_array tmp = v; n     swap(tmp, *this); n     return *this; n   } n   void clear() { n     dyn_array tmp; n     swap(tmp, *this); n   } n   SIZE_T size(node* x) const { return x ? x->sz : 0; } n   SIZE_T size() const { return size(root); } n   void join(node* l, node* r, node*& i) { n     if (!l or !r) return void(i = l ? l : r); n     l->prop(), r->prop(); n     if (l->p > r->p) n       join(l->r, r, l->r), i = l; n     else n       join(l, r->l, r->l), i = r; n     i->update(); n   } n   void concat(dyn_array& v) { n     join(root, v.root, root); n     v.root = NULL; n   } n   void split(node* i, node*& l, node*& r, SIZE_T idx) { n     if (!i) return void(r = l = NULL); n     i->prop(); n     if (size(i->l) + i->val.size() <= idx) { n       split(i->r, i->r, r, idx - size(i->l) - i->val.size()); n       l = i; n     } else if (size(i->l) >= idx) { n       split(i->l, l, i->l, idx); n       r = i; n     } else { n       SET L; n       if (!i->rev) n         i->val.split(idx - size(i->l), L); n       else { n         i->val.split(i->val.size() - (idx - size(i->l)), L); n         swap(L, i->val); n       } n       node* novo = new node(L); n       novo->rev = i->rev; n       novo->l = i->l; n       i->l = NULL; n       novo->update(); n       l = novo, r = i; n     } n     i->update(); n   } n   void split(SIZE_T k, dyn_array& v) { n     v.clear(); n     split(root, v.root, root, std::min(k, size())); n   } n   void push_back(T val, SIZE_T qt = 1) { n     SET v; n     v.insert(val, qt); n     node* i = new node(v); n     join(root, i, root); n   } n   T get(node* i, SIZE_T idx) const { n     i->prop(); n     if (size(i->l) + i->val.size() <= idx) n       return get(i->r, idx - size(i->l) - i->val.size()); n     if (size(i->l) > idx) return get(i->l, idx); n     if (!i->rev) return i->val[idx - size(i->l)]; n     return i->val[i->val.size() - 1 - (idx - size(i->l))]; n   } n   const T operator[](SIZE_T i) const { return get(root, i); } n   void update(SIZE_T idx, T val) { n     dyn_array L, M; n     split(idx + 1, M); n     M.split(idx, L); n     L.push_back(val); n     L.concat(*this); n     swap(*this, L); n   } n   void merge(node*& i, SET& v) { n     if (!i) return; n     i->prop(); n     merge(i->l, v), merge(i->r, v); n     v.merge(i->val); n     delete i; n     i = NULL; n   } n   void sort(bool reverse = false) { n     if (!root) return; n     root->prop(); n     merge(root->l, root->val); n     merge(root->r, root->val); n     root->rev = reverse; n     root->update(); n   } n   void sort(SIZE_T l, SIZE_T r, bool reverse = false) { n     dyn_array L, M; n     split(r + 1, M); n     M.split(l, L); n     M.sort(reverse); n     L.concat(M); n     L.concat(*this); n     swap(*this, L); n   } n   void reverse() { n     if (root) root->rev_lazy ^= 1; n   } n   void reverse(SIZE_T l, SIZE_T r) { n     dyn_array L, M; n     split(r + 1, M); n     M.split(l, L); n     M.reverse(); n     L.concat(M); n     L.concat(*this); n     swap(*this, L); n   } n   T min() { return root->mi; } n   T rmq(SIZE_T l, SIZE_T r) { n     dyn_array L, M; n     split(r + 1, M); n     M.split(l, L); n     T ans = M.min(); n     L.concat(M); n     L.concat(*this); n     swap(*this, L); n     return ans; n   } n }; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n, q; n   cin >> n >> q; n   map<int, int> ida, volta; n   vector<int> w(n); n   for (int& i : w) cin >> i; n   auto w2 = w; n   sort(w2.begin(), w2.end()); n   for (int i = 0; i < n; i++) ida[w2[i]] = i, volta[i] = w2[i]; n   dyn_array<int> v; n   for (int i = 0; i < n; i++) v.push_back(ida[w[i]]); n   while (q--) { n     int t, r; n     cin >> t >> r; n     r--; n     v.sort(0, r, t - 1); n   } n   for (int i = 0; i < n; i++) cout << volta[v[i]] <<    ; n   cout <<   n ; n   exit(0); n } n


#include <bits/stdc++.h> n int a[100]; n int main() { n   int n; n   scanf( %d%d%d , &a[0], &a[1], &n); n   for (int i = 2; i <= n; i++) { n     a[i] = a[i - 1] + a[i - 2]; n   } n   printf( %d n , a[n]); n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n int chkmax(T &a, T b) { n   if (b > a) { n     a = b; n     return 1; n   } n   return 0; n } n template <class T> n int chkmin(T &a, T b) { n   if (b < a) { n     a = b; n     return 1; n   } n   return 0; n } n template <class iterator> n void output(iterator begin, iterator end, ostream &out = cerr) { n   while (begin != end) { n     out << (*begin) <<    ; n     begin++; n   } n   out << endl; n } n template <class T> n void output(T x, ostream &out = cerr) { n   output(x.begin(), x.end(), out); n } n void fast_io() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n const int MOD = 1e9 + 7; n const int _2 = (MOD + 1) / 2; n void add(int &a, int b) { n   a += b; n   if (a >= MOD) { n     a -= MOD; n   } n } n int mul(int a, int b) { return (1LL * a * b) % MOD; } n const int mx = 2e3 + 10; n int n, m, cs, used[mx]; n vector<vector<int> > g; n vector<int> a; n void read() { n   cin >> n >> m; n   g.resize(n); n   for (int i = 0; i < m; ++i) { n     int u, v; n     cin >> u >> v; n     u--; n     v--; n     g[u].push_back(v); n     g[v].push_back(u); n   } n } n int dfs(int v) { n   int res = 1; n   used[v] = 1; n   for (auto v1 : g[v]) { n     if (used[v1] == 0) { n       res += dfs(v1); n     } n   } n   return res; n } n void find_cycles() { n   used[0] = 1; n   for (auto v : g[0]) { n     if (used[v] == 0) { n       int len = dfs(v); n       a.push_back(len + 1); n     } n   } n } n int dp[mx][2 * mx], dpPref[mx][2 * mx], dpSuf[mx][2 * mx]; n int dpPrefObl[mx][2 * mx], dpSufObl[mx][2 * mx]; n void update_dp(int len, int idx, int stay) { n   fill(dp[idx + 1], dp[idx + 1] + m + 1, 0); n   for (int delta = 0; delta <= m; ++delta) { n     if (dp[idx][delta]) { n       add(dp[idx + 1][delta + len], dp[idx][delta]); n       add(dp[idx + 1][abs(delta - len)], dp[idx][delta]); n       if (stay) { n         add(dp[idx + 1][delta], dp[idx][delta]); n       } n     } n   } n } n void calc_dp(int stay) { n   fill(dp[0], dp[0] + m + 1, 0); n   dp[0][0] = 1; n   for (int i = 0; i < cs; ++i) { n     update_dp(a[i], i, stay); n   } n } n void process() { n   cs = a.size(); n   calc_dp(1); n   for (int i = 0; i <= cs; ++i) { n     copy(dp[i], dp[i] + m + 1, dpPref[i]); n   } n   calc_dp(0); n   for (int i = 0; i <= cs; ++i) { n     copy(dp[i], dp[i] + m + 1, dpPrefObl[i]); n   } n   reverse(a.begin(), a.end()); n   calc_dp(1); n   for (int i = 0; i <= cs; ++i) { n     copy(dp[i], dp[i] + m + 1, dpSuf[i]); n   } n   calc_dp(0); n   for (int i = 0; i <= cs; ++i) { n     copy(dp[i], dp[i] + m + 1, dpSufObl[i]); n   } n   reverse(a.begin(), a.end()); n } n int ans; n int convert(int val, int pos) { return (pos == 0 ? val : mul(val, _2)); } n int merge(int pos, int sum) { n   int res = 0; n   for (int delta1 = -m; delta1 <= m; ++delta1) { n     int delta2 = sum - delta1; n     if (abs(delta2) <= m) { n       add(res, mul(convert(dpPref[pos][abs(delta1)], delta1), n                    convert(dpSuf[cs - 1 - pos][abs(delta2)], delta2))); n     } n   } n   return res; n } n int merge_obl(int pos, int sum) { n   int res = 0; n   for (int delta1 = -m; delta1 <= m; ++delta1) { n     int delta2 = sum - delta1; n     if (abs(delta2) <= m) { n       add(res, mul(convert(dpPrefObl[pos][abs(delta1)], delta1), n                    convert(dpSufObl[cs - 1 - pos][abs(delta2)], delta2))); n     } n   } n   return res; n } n void mergeAns() { n   add(ans, dpPrefObl[cs][0]); n   for (int i = 0; i < cs; ++i) { n     add(ans, mul(merge_obl(i, a[i] - 1), 4)); n     for (int diff = 2 - a[i]; diff <= a[i] - 2; ++diff) { n       add(ans, mul(merge(i, diff), 2)); n     } n   } n } n signed main() { n   fast_io(); n   read(); n   find_cycles(); n   process(); n   mergeAns(); n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5e5 + 100; n class Node { n  public: n   int l, r; n   bool operator<(const Node &a) const { return r < a.r; } n }; n Node n[maxn]; n int main() { n   int N; n   scanf( %d , &N); n   for (int i = 0; i < N; i++) scanf( %d%d , &n[i].l, &n[i].r); n   sort(n, n + N); n   int ans = 1, ps = 0; n   for (int i = 1; i < N; i++) n     if (n[i].l > n[ps].r) { n       ans++; n       ps = i; n     } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int a[210][210], n, m, s[110]; n bool dop(int x, int y) { return (x >= 0 && y >= 0 && x < 2 * n && y < 2 * m); } n void dfs(int x, int y, int cur) { n   s[cur]++; n   a[x][y] = cur; n   if (dop(x + 2, y) && a[x + 1][y] != -1 && a[x + 2][y] != cur) { n     dfs(x + 2, y, cur); n   } n   if (dop(x - 2, y) && a[x - 1][y] != -1 && a[x - 2][y] != cur) { n     dfs(x - 2, y, cur); n   } n   if (dop(x, y + 2) && a[x][y + 1] != -1 && a[x][y + 2] != cur) { n     dfs(x, y + 2, cur); n   } n   if (dop(x, y - 2) && a[x][y - 1] != -1 && a[x][y - 2] != cur) { n     dfs(x, y - 2, cur); n   } n } n void qsort(int first, int last) { n   int i = first, j = last, x = s[(i + j) / 2]; n   do { n     while (s[i] < x) { n       i++; n     } n     while (s[j] > x) { n       j--; n     } n     if (i <= j) { n       if (i != j) { n         swap(s[i], s[j]); n       } n       i++; n       j--; n     } n   } while (i <= j); n   if (i < last) { n     qsort(i, last); n   } n   if (j > first) { n     qsort(first, j); n   } n } n int main() { n   int x1, x2, y1, y2, t, i, j; n   cin >> n >> m >> t; n   for (i = 0; i < n * 2; i++) { n     for (j = 0; j < m * 2; j++) { n       a[i][j] = 0; n     } n   } n   for (i = 0; i < t; i++) { n     cin >> x1 >> y1 >> x2 >> y2; n     if (x1 == x2) { n       if (y1 > y2) { n         swap(y1, y2); n       } n       for (j = y1 * 2; j < y2 * 2; j++) { n         a[x1 * 2][j] = -1; n       } n     } else { n       if (x1 > x2) { n         swap(x1, x2); n       } n       for (j = x1 * 2; j < x2 * 2; j++) { n         a[j][y1 * 2] = -1; n       } n     } n   } n   for (i = 0; i < 100; i++) { n     s[i] = 0; n   } n   int curcol = 1; n   for (i = 1; i < 2 * n; i += 2) { n     for (j = 1; j < 2 * m; j += 2) { n       if (a[i][j] == 0) { n         dfs(i, j, curcol); n         curcol++; n       } n     } n   } n   qsort(1, curcol - 1); n   for (i = 1; i < curcol; i++) { n     cout << s[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 400005; n int N; n long long T; n long long A[MAXN]; n long long pre[MAXN]; n map<long long, int> mp; n int BIT[MAXN]; n void add(int idx) { n   for (; idx < MAXN; idx += idx & -idx) BIT[idx]++; n } n int get(int idx) { n   int ret = 0; n   for (; idx > 0; idx -= idx & -idx) ret += BIT[idx]; n   return ret; n } n int main() { n   ios::sync_with_stdio(0); n   cin >> N >> T; n   mp[-T] = 1; n   mp[0] = 1; n   for (int i = 1; i <= N; i++) { n     cin >> A[i]; n     pre[i] = pre[i - 1] + A[i]; n     mp[pre[i] - T] = 1; n     mp[pre[i]] = 1; n   } n   int ind = 0; n   for (map<long long, int>::iterator it = mp.begin(); it != mp.end(); it++) n     it->second = ++ind; n   long long ans = 0; n   add(mp[0]); n   for (int i = 1; i <= N; i++) { n     ans += i - get(mp[pre[i] - T]); n     add(mp[pre[i]]); n   } n   cout << ans <<   n ; n   return 0; n } n