#include <bits/stdc++.h> n using namespace std; n template <typename A, typename B> n string to_string(pair<A, B> p); n template <typename A, typename B, typename C> n string to_string(tuple<A, B, C> p); n template <typename A, typename B, typename C, typename D> n string to_string(tuple<A, B, C, D> p); n string to_string(const string& s) { return     + s +    ; } n string to_string(const char* s) { return to_string((string)s); } n string to_string(bool b) { return (b ?  true  :  false ); } n string to_string(vector<bool> v) { n   bool first = true; n   string res =  { ; n   for (int i = 0; i < static_cast<int>(v.size()); i++) { n     if (!first) { n       res +=  ,  ; n     } n     first = false; n     res += to_string(v[i]); n   } n   res +=  } ; n   return res; n } n template <size_t N> n string to_string(bitset<N> v) { n   string res =   ; n   for (size_t i = 0; i < N; i++) { n     res += static_cast<char>( 0  + v[i]); n   } n   return res; n } n template <typename A> n string to_string(A v) { n   bool first = true; n   string res =  { ; n   for (const auto& x : v) { n     if (!first) { n       res +=  ,  ; n     } n     first = false; n     res += to_string(x); n   } n   res +=  } ; n   return res; n } n template <typename A, typename B> n string to_string(pair<A, B> p) { n   return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ; n } n template <typename A, typename B, typename C> n string to_string(tuple<A, B, C> p) { n   return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   + n          to_string(get<2>(p)) +  ) ; n } n template <typename A, typename B, typename C, typename D> n string to_string(tuple<A, B, C, D> p) { n   return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   + n          to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ; n } n void debug_out() { cerr << endl; } n template <typename Head, typename... Tail> n void debug_out(Head H, Tail... T) { n   cerr <<     << to_string(H); n   debug_out(T...); n } n template <typename T> n T inverse(T a, T m) { n   T u = 0, v = 1; n   while (a != 0) { n     T t = m / a; n     m -= t * a; n     swap(a, m); n     u -= t * v; n     swap(u, v); n   } n   assert(m == 1); n   return u; n } n template <typename T> n class Modular { n  public: n   using Type = typename decay<decltype(T::value)>::type; n   constexpr Modular() : value() {} n   template <typename U> n   Modular(const U& x) { n     value = normalize(x); n   } n   template <typename U> n   static Type normalize(const U& x) { n     Type v; n     if (-mod() <= x && x < mod()) n       v = static_cast<Type>(x); n     else n       v = static_cast<Type>(x % mod()); n     if (v < 0) v += mod(); n     return v; n   } n   const Type& operator()() const { return value; } n   template <typename U> n   explicit operator U() const { n     return static_cast<U>(value); n   } n   constexpr static Type mod() { return T::value; } n   Modular& operator+=(const Modular& other) { n     if ((value += other.value) >= mod()) value -= mod(); n     return *this; n   } n   Modular& operator-=(const Modular& other) { n     if ((value -= other.value) < 0) value += mod(); n     return *this; n   } n   template <typename U> n   Modular& operator+=(const U& other) { n     return *this += Modular(other); n   } n   template <typename U> n   Modular& operator-=(const U& other) { n     return *this -= Modular(other); n   } n   Modular& operator++() { return *this += 1; } n   Modular& operator--() { return *this -= 1; } n   Modular operator++(int) { n     Modular result(*this); n     *this += 1; n     return result; n   } n   Modular operator--(int) { n     Modular result(*this); n     *this -= 1; n     return result; n   } n   Modular operator-() const { return Modular(-value); } n   template <typename U = T> n   typename enable_if<is_same<typename Modular<U>::Type, int>::value, n                      Modular>::type& n   operator*=(const Modular& rhs) { n     value = normalize(static_cast<int64_t>(value) * n                       static_cast<int64_t>(rhs.value)); n     return *this; n   } n   template <typename U = T> n   typename enable_if<is_same<typename Modular<U>::Type, int64_t>::value, n                      Modular>::type& n   operator*=(const Modular& rhs) { n     int64_t q = static_cast<int64_t>(static_cast<long double>(value) * n                                      rhs.value / mod()); n     value = normalize(value * rhs.value - q * mod()); n     return *this; n   } n   template <typename U = T> n   typename enable_if<!is_integral<typename Modular<U>::Type>::value, n                      Modular>::type& n   operator*=(const Modular& rhs) { n     value = normalize(value * rhs.value); n     return *this; n   } n   Modular& operator/=(const Modular& other) { n     return *this *= Modular(inverse(other.value, mod())); n   } n   template <typename U> n   friend const Modular<U>& abs(const Modular<U>& v) { n     return v; n   } n   template <typename U> n   friend bool operator==(const Modular<U>& lhs, const Modular<U>& rhs); n   template <typename U> n   friend bool operator<(const Modular<U>& lhs, const Modular<U>& rhs); n   template <typename U> n   friend std::istream& operator>>(std::istream& stream, Modular<U>& number); n  n  private: n   Type value; n }; n template <typename T> n bool operator==(const Modular<T>& lhs, const Modular<T>& rhs) { n   return lhs.value == rhs.value; n } n template <typename T, typename U> n bool operator==(const Modular<T>& lhs, U rhs) { n   return lhs == Modular<T>(rhs); n } n template <typename T, typename U> n bool operator==(U lhs, const Modular<T>& rhs) { n   return Modular<T>(lhs) == rhs; n } n template <typename T> n bool operator!=(const Modular<T>& lhs, const Modular<T>& rhs) { n   return !(lhs == rhs); n } n template <typename T, typename U> n bool operator!=(const Modular<T>& lhs, U rhs) { n   return !(lhs == rhs); n } n template <typename T, typename U> n bool operator!=(U lhs, const Modular<T>& rhs) { n   return !(lhs == rhs); n } n template <typename T> n bool operator<(const Modular<T>& lhs, const Modular<T>& rhs) { n   return lhs.value < rhs.value; n } n template <typename T> n Modular<T> operator+(const Modular<T>& lhs, const Modular<T>& rhs) { n   return Modular<T>(lhs) += rhs; n } n template <typename T, typename U> n Modular<T> operator+(const Modular<T>& lhs, U rhs) { n   return Modular<T>(lhs) += rhs; n } n template <typename T, typename U> n Modular<T> operator+(U lhs, const Modular<T>& rhs) { n   return Modular<T>(lhs) += rhs; n } n template <typename T> n Modular<T> operator-(const Modular<T>& lhs, const Modular<T>& rhs) { n   return Modular<T>(lhs) -= rhs; n } n template <typename T, typename U> n Modular<T> operator-(const Modular<T>& lhs, U rhs) { n   return Modular<T>(lhs) -= rhs; n } n template <typename T, typename U> n Modular<T> operator-(U lhs, const Modular<T>& rhs) { n   return Modular<T>(lhs) -= rhs; n } n template <typename T> n Modular<T> operator*(const Modular<T>& lhs, const Modular<T>& rhs) { n   return Modular<T>(lhs) *= rhs; n } n template <typename T, typename U> n Modular<T> operator*(const Modular<T>& lhs, U rhs) { n   return Modular<T>(lhs) *= rhs; n } n template <typename T, typename U> n Modular<T> operator*(U lhs, const Modular<T>& rhs) { n   return Modular<T>(lhs) *= rhs; n } n template <typename T> n Modular<T> operator/(const Modular<T>& lhs, const Modular<T>& rhs) { n   return Modular<T>(lhs) /= rhs; n } n template <typename T, typename U> n Modular<T> operator/(const Modular<T>& lhs, U rhs) { n   return Modular<T>(lhs) /= rhs; n } n template <typename T, typename U> n Modular<T> operator/(U lhs, const Modular<T>& rhs) { n   return Modular<T>(lhs) /= rhs; n } n template <typename T, typename U> n Modular<T> power(const Modular<T>& a, const U& b) { n   assert(b >= 0); n   Modular<T> x = a, res = 1; n   U p = b; n   while (p > 0) { n     if (p & 1) res *= x; n     x *= x; n     p >>= 1; n   } n   return res; n } n template <typename T> n bool IsZero(const Modular<T>& number) { n   return number() == 0; n } n template <typename T> n string to_string(const Modular<T>& number) { n   return to_string(number()); n } n template <typename T> n std::ostream& operator<<(std::ostream& stream, const Modular<T>& number) { n   return stream << number(); n } n template <typename T> n std::istream& operator>>(std::istream& stream, Modular<T>& number) { n   typename common_type<typename Modular<T>::Type, int64_t>::type x; n   stream >> x; n   number.value = Modular<T>::normalize(x); n   return stream; n } n constexpr int md = (int)1e9 + 7; n using Mint = Modular<std::integral_constant<decay<decltype(md)>::type, md>>; n vector<Mint> fact(1, 1); n vector<Mint> inv_fact(1, 1); n Mint C(int n, int k) { n   if (k < 0 || k > n) { n     return 0; n   } n   while ((int)fact.size() < n + 1) { n     fact.push_back(fact.back() * (int)fact.size()); n     inv_fact.push_back(1 / fact.back()); n   } n   return fact[n] * inv_fact[k] * inv_fact[n - k]; n } n struct Point { n   int x; n   int y; n   int c; n }; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n, k, L; n   cin >> n >> k >> L; n   vector<Point> p(n); n   for (int i = 0; i < n; i++) { n     cin >> p[i].x >> p[i].y >> p[i].c; n     --p[i].c; n   } n   sort(p.begin(), p.end(), n        [&](const Point& a, const Point& b) { return a.y < b.y; }); n   Mint c2 = Mint(L) * (L + 1) / 2; n   auto C2 = [&](int x, int y) -> long long { n     if (x >= y) { n       return 0; n     } n     return ((long long)(y - x) * (y - x + 1)) >> 1; n   }; n   Mint ans = 0; n   for (int start = 0; start <= n - k; start++) { n     int coeff = p[start].y - (start == 0 ? -1 : p[start - 1].y); n     if (coeff == 0) { n       continue; n     } n     vector<multiset<int>> s(k); n     for (int i = 0; i < k; i++) { n       s[i].insert(-1); n       s[i].insert(L); n     } n     for (int i = start; i < n; i++) { n       s[p[i].c].insert(p[i].x); n     } n     set<pair<int, int>> segs; n     long long value = 0; n     auto Modify = [&](set<pair<int, int>>::iterator it, int q) { n       if (it != segs.begin()) { n         value -= q * C2(it->first, abs(prev(it)->second)); n       } n       if (next(it) != segs.end()) { n         value -= q * C2(next(it)->first, abs(it->second)); n       } n       if (it != segs.begin() && next(it) != segs.end()) { n         value += q * C2(next(it)->first, abs(prev(it)->second)); n       } n       value += q * C2(it->first, abs(it->second)); n     }; n     auto Erase = [&](set<pair<int, int>>::iterator it) { n       Modify(it, -1); n       segs.erase(it); n     }; n     auto Add = [&](int from, int to) { n       if (from >= to) { n         return; n       } n       pair<int, int> seg = make_pair(from, -to); n       auto it = segs.lower_bound(seg); n       while (it != segs.end() && abs(it->second) <= to) { n         Erase(it); n         it = segs.lower_bound(seg); n       } n       if (it != segs.begin()) { n         it = prev(it); n         if (abs(it->second) >= to) { n           return; n         } n       } n       auto ret = segs.insert(seg); n       assert(ret.second); n       it = ret.first; n       Modify(it, 1); n     }; n     bool have_all = true; n     for (int i = 0; i < k; i++) { n       if (s[i].size() == 2) { n         have_all = false; n         break; n       } n       auto it = s[i].begin(); n       while (*it < L) { n         int me = *it; n         ++it; n         int nxt = *it; n         Add(me + 1, nxt); n       } n     } n     if (!have_all) { n       break; n     } n     for (int finish = n - 1; finish >= start; finish--) { n       int coeff2 = (finish == n - 1 ? L : p[finish + 1].y) - p[finish].y; n       ans += Mint(coeff) * coeff2 * (c2 - value); n       int col = p[finish].c; n       auto it = s[col].find(p[finish].x); n       assert(it != s[col].end()); n       auto pr = prev(it); n       auto nx = next(it); n       Add((*pr) + 1, *nx); n       s[col].erase(it); n       if (value == c2) { n         break; n       } n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 5; n const int MOD = 1e9 + 7.5; n char s[MAXN]; n int f[MAXN], n; n int main() { n   scanf( %s , s + 1); n   n = strlen(s + 1); n   int preb = 0; n   for (int i = 1; i <= n; ++i) { n     f[i] = f[i - 1]; n     if (s[i] ==  a ) { n       f[i] = (f[i] + f[preb] + 1) % MOD; n     } else if (s[i] ==  b ) { n       preb = i; n     } n   } n   cout << f[n] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace io { n void _(int &k) { n   char c; n   int e = 1; n   k = 0; n   while ((c = getchar()) >  9  || c <  0 ) n     if (c ==  - ) e = -1; n   k = c -  0 ; n   while ((c = getchar()) <=  9  && c >=  0 ) { n     k *= 10; n     k += c -  0 ; n   } n   k *= e; n } n void _(long long &k) { n   char c; n   int e = 1; n   k = 0; n   while ((c = getchar()) >  9  || c <  0 ) n     if (c ==  - ) e = -1; n   k = c -  0 ; n   while ((c = getchar()) <=  9  && c >=  0 ) { n     k *= 10; n     k += c -  0 ; n   } n   k *= e; n } n void _(char &c) { n   while ((c = getchar()) ==     || c ==   n ) n     ; n } n void _(double &c) { scanf( %lf , &c); } n void _(char *s) { n   char c; n   while ((c = getchar()) != EOF && c !=     && c != 10) *s++ = c; n } n template <class t1, class t2> n void _(t1 &a, t2 &b) { n   _(a); n   _(b); n } n template <class t1, class t2, class t3> n void _(t1 &a, t2 &b, t3 &c) { n   _(a); n   _(b); n   _(c); n } n template <class t1, class t2, class t3, class t4> n void _(t1 &a, t2 &b, t3 &c, t4 &d) { n   _(a); n   _(b); n   _(c); n   _(d); n } n template <class t1, class t2, class t3, class t4, class t5> n void _(t1 &a, t2 &b, t3 &c, t4 &d, t5 &e) { n   _(a); n   _(b); n   _(c); n   _(d); n   _(e); n } n void _p(double k) { printf( %.6lf , k); } n void _p(char *c) { n   for (; *c; putchar(*c++)) n     ; n } n void _p(const char *c) { n   for (; *c; putchar(*c++)) n     ; n } n void _p(char c) { putchar(c); } n template <class T> n void _p0(T k) { n   if (k >= 10) _p0(k / 10); n   putchar(k % 10 +  0 ); n } n template <class T> n void _p(T k) { n   if (k < 0) { n     putchar( - ); n     _p0(-k); n   } else n     _p0(k); n } n template <class T> n void __p(T k) { n   _p(k); n   putchar(   ); n } n template <class T> n void _pn(T k) { n   _p(k); n   putchar(  n ); n } n template <class t1, class t2> n void _p(t1 a, t2 b) { n   __p(a); n   _pn(b); n } n template <class t1, class t2, class t3> n void _p(t1 a, t2 b, t3 c) { n   __p(a); n   __p(b); n   _pn(c); n } n template <class t1, class t2, class t3, class t4> n void _p(t1 a, t2 b, t3 c, t4 d) { n   __p(a); n   __p(b); n   __p(c); n   _pn(d); n } n template <class T> n void op(T *a, int n) { n   int i; n   n--; n   for (i = 1; i <= n; i++) __p(a[i]); n   _pn(a[n + 1]); n } n int gi() { n   int first; n   _(first); n   return first; n } n long long gll() { n   long long first; n   _(first); n   return first; n } n }  // namespace io n int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } n void fcl() { n   fclose(stdin); n   fclose(stdout); n } n void fop(const char *s) { n   char c[256], d[256]; n   memset(c, 0, sizeof(c)); n   memset(d, 0, sizeof(d)); n   strcpy(c, s); n   strcpy(d, s); n   freopen(strcat(c,  .in ),  r , stdin); n   freopen(strcat(d,  .out ),  w , stdout); n } n int eq(double a, double b) { n   return a + 0.00000000001 >= b && b + 0.00000000001 >= a; n } n template <class T> n void _ma(T &a, T b) { n   if (a < b) a = b; n } n template <class T> n void _mi(T &a, T b) { n   if (a > b) a = b; n } n const int N = 1234567, EE = 100000000, GG = 1000000000, ima = 2147483647; n using namespace io; n int n, m, a[N], an, T, l, r; n const int p = 1000000007; n long long f[N][3]; n int main() { n   int i, j; n   long long a0, a1, a2; n   _(n, l, r); n   a0 = r / 3 - (l - 1) / 3; n   a1 = (r + 2) / 3 - (l + 1) / 3; n   a2 = (r + 1) / 3 - l / 3; n   f[0][0] = 1; n   for (i = 1; i <= n; i++) { n     f[i][0] = (f[i - 1][0] * a0 + f[i - 1][1] * a2 + f[i - 1][2] * a1) % p; n     f[i][1] = (f[i - 1][0] * a1 + f[i - 1][1] * a0 + f[i - 1][2] * a2) % p; n     f[i][2] = (f[i - 1][0] * a2 + f[i - 1][1] * a1 + f[i - 1][2] * a0) % p; n   } n   _pn(f[n][0]); n } n


#include <bits/stdc++.h> n using namespace std; n int N, C, cnt; n int A[33], P[33]; n double dp[33][33][222], sol; n inline int f(int l, int r, int i) { n   if (i < l || i > r) return i; n   int ret = i - l + 1; n   int len = r - l + 1; n   ret = len - ret + 1; n   ret = l + ret - 1; n   return ret; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout << setprecision(15) << fixed; n   cin >> N >> C; n   for (int I = 1; I <= N; I++) cin >> A[I]; n   for (int I = 1; I <= N; I++) n     for (int K = I + 1; K <= N; K++) dp[I][K][0] = 1; n   for (int c = 1; c <= C; c++) { n     for (int I = 1; I <= N; I++) { n       for (int K = 1; K <= N; K++) { n         for (int l = 1; l <= N; l++) { n           for (int r = l; r <= N; r++) { n             int pi = f(l, r, I); n             int pk = f(l, r, K); n             dp[I][K][c] += dp[pi][pk][c - 1]; n           } n         } n         dp[I][K][c] /= (N * (N - 1) / 2) + N; n       } n     } n   } n   for (int I = 1; I <= N; I++) n     for (int K = 1; K <= N; K++) n       if (A[I] > A[K]) { n         sol += dp[I][K][C]; n       } n   cout << sol << endl; n } n


#include <bits/stdc++.h> n const int inf = INT_MAX; n const int MAX = 1e6 + 8; n const long long MOD = 998244353; n const int TOT_PRIMES = 1e6 + 9; n const int MAX_A = 71; n const int LN = 20; n using namespace std; n vector<int> adj[MAX]; n int vis[MAX]; n long long c = 0; n void dfs(int u) { n   vis[u] = 1; n   c = c + 1; n   for (auto v : adj[u]) { n     if (!vis[v]) { n       dfs(v); n     } n   } n } n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     int x; n     cin >> x; n     adj[i].push_back(x); n     adj[x].push_back(i); n   } n   vector<long long> res; n   for (int i = 1; i <= n; i++) { n     if (!vis[i]) { n       dfs(i); n       res.push_back(c); n       c = 0; n     } n   } n   sort(res.begin(), res.end()); n   long long ans = 0; n   int m = res.size(); n   if (m == 1) { n     cout << res[0] * res[0]; n     return 0; n   } n   ans = res[m - 1] + res[m - 2]; n   ans = ans * ans; n   for (int i = 0; i < m - 2; i++) { n     ans = ans + (res[i] * res[i]); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O2 ) n using namespace std; n long long mod = 1000000007; n void solve() { n   long long n; n   cin >> n; n   long long a[n]; n   long long k0 = 0; n   long long k1 = 0; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i] == 0) k0++; n     if (a[i] == 1) k1++; n   } n   long long ans = k1 * (pow(2, k0)); n   cout << ans << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t; n   cin >> t; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n const long long inf = std::numeric_limits<long long>::max(); n const int infint = std::numeric_limits<int>::max(); n const long long mod = 1e9 + 7; n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n vector<int> g[500100]; n long long a[500100]; n long long par[500100][21]; n void dfs(int v, int p) { n   for (auto i : g[v]) { n     if (i == p) continue; n     dfs(i, v); n     par[i][0] = v; n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   long long mn = inf; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     mn = min(a[i], mn); n   } n   for (int i = 0; i < n - 1; i++) { n     int x, y; n     cin >> x >> y; n     x--, y--; n     g[x].push_back(y); n     g[y].push_back(x); n   } n   for (int i = 0; i < n; i++) { n     if (a[i] == mn) { n       par[i][0] = i; n       dfs(i, -1); n       break; n     } n   } n   long long w = 0; n   for (int i = 1; i < 21; i++) n     for (int j = 0; j < n; j++) par[j][i] = par[par[j][i - 1]][i - 1]; n   for (int i = 0; i < n; i++) { n     if (a[i] == mn) continue; n     long long now = inf; n     for (int j = 0; j < 21; j++) { n       now = min(now, a[par[i][j]] * (j + 1) + a[i]); n     } n     w += now; n   } n   cout << w; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename _T> n void read(_T &x) { n   _T f = 1; n   x = 0; n   char s = getchar(); n   while (s >  9  || s <  0 ) { n     if (s ==  - ) f = -1; n     s = getchar(); n   } n   while ( 0  <= s && s <=  9 ) { n     x = (x << 3) + (x << 1) + (s ^ 48); n     s = getchar(); n   } n   x *= f; n } n struct ming { n   long long typ, t, x, id, pos; n } a[100010]; n long long n, ans[100010], num[100010]; n vector<long long> vec; n long long cmp1(const ming &a, const ming &b) { return a.t < b.t; } n long long cmp2(const ming &a, const ming &b) { return a.id < b.id; } n void merge(long long l, long long r) { n   if (l == r) return; n   long long mid = l + r >> 1, j = l; n   merge(l, mid); n   merge(mid + 1, r); n   sort(a + l, a + mid + 1, cmp1); n   sort(a + mid + 1, a + r + 1, cmp1); n   for (long long i = mid + 1; i <= r; i++) { n     while (j <= mid && a[j].t <= a[i].t) num[a[j].pos] += a[j].typ, j++; n     if (!a[i].typ) ans[a[i].id] += num[a[i].pos]; n   } n   for (long long i = l; i < j; i++) num[a[i].pos] -= a[i].typ; n } n signed main() { n   read(n); n   for (long long i = 1; i <= n; i++) { n     read(a[i].typ); n     read(a[i].t); n     read(a[i].x); n     if (a[i].typ == 2) a[i].typ = -1; n     if (a[i].typ == 3) a[i].typ = 0; n     a[i].id = i; n     vec.push_back(a[i].x); n   } n   sort(vec.begin(), vec.end()); n   vec.erase(unique(vec.begin(), vec.end()), vec.end()); n   for (long long i = 1; i <= n; i++) n     a[i].pos = lower_bound(vec.begin(), vec.end(), a[i].x) - vec.begin() + 1; n   merge(1, n); n   sort(a + 1, a + n + 1, cmp2); n   for (long long i = 1; i <= n; i++) n     if (!a[i].typ) printf( %lld n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   int x1, y1, x2, y2; n   cin >> n; n   long long ans = 0; n   for (int i = 1; i <= n; i++) { n     cin >> x1 >> y1 >> x2 >> y2; n     ans += (long long)(x2 - x1 + 1) * (y2 - y1 + 1); n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e13, Mo = 998244353; n const int N = 1000000; n const double eps = 1e-6; n namespace slow_IO { n long long read() { n   long long x = 0; n   int zf = 1; n   char ch = getchar(); n   while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar(); n   if (ch ==  - ) zf = -1, ch = getchar(); n   while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar(); n   return x * zf; n } n void write(long long y) { n   if (y < 0) putchar( - ), y = -y; n   if (y > 9) write(y / 10); n   putchar(y % 10 +  0 ); n } n }  // namespace slow_IO n using namespace slow_IO; n vector<int> E1[N + 5], E2[N + 5]; n int Flag1[N + 5], Flag2[N + 5]; n int Ans[N + 5]; n int ans = 0; n int main() { n   int n = read(), m = read(); n   for (int i = (1); i <= (m); i++) { n     int x = read(), y = read(); n     E1[x].push_back(y); n     E2[y].push_back(x); n   } n   for (int i = (1); i <= (n); i++) n     if (!Flag1[i]) { n       Flag1[i] = Flag2[i] = 1; n       for (int j = (0); j < (E1[i].size()); j++) Flag1[E1[i][j]] = 1; n     } n   for (int i = (n); i >= (1); i--) n     if (Flag2[i]) { n       for (int j = (0); j < (E2[i].size()); j++) n         if (Flag2[E2[i][j]]) Flag2[i] = 0; n     } n   for (int i = (1); i <= (n); i++) n     if (Flag2[i]) Ans[++ans] = i; n   printf( %d n , ans); n   for (int i = (1); i <= (ans); i++) n     printf( %d%c , Ans[i], i == ans ?   n  :    ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 109; n int n; n int a[N]; n map<int, int> m; n set<int> s[2]; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; ++i) { n     cin >> a[i]; n     m[a[i]]++; n   } n   int pos = 0; n   for (auto p : m) n     if (p.second == 1) { n       s[pos].insert(p.first); n       pos = 1 - pos; n     } n   if (s[0].size() == s[1].size()) { n     string res(n,  A ); n     for (int i = 0; i < n; ++i) n       if (s[1].count(a[i])) res[i] =  B ; n     cout <<  YES  << endl; n     for (auto c : res) cout << c; n     cout << endl; n     return 0; n   } else { n     assert(int(s[0].size()) - 1 == int(s[1].size())); n     string res(n,  A ); n     for (int i = 0; i < n; ++i) n       if (s[1].count(a[i])) res[i] =  B ; n     int id = -1; n     for (auto p : m) n       if (p.second >= 3) { n         id = p.first; n         break; n       } n     if (id == -1) { n       cout <<  NO  << endl; n       return 0; n     } n     bool flag = false; n     for (int i = 0; i < n; ++i) { n       if (a[i] == id) n         if (!flag) { n           flag = true; n           res[i] =  B ; n         } n     } n     cout <<  YES  << endl; n     for (auto c : res) cout << c; n     cout << endl; n     return 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n bool comp(const int& a, const int& b) { return a < b ? false : true; } n using namespace std; n int main() { n   long long int k, a, b, m, n; n   cin >> k >> m >> n; n   a = max(m, n); n   b = min(m, n); n   long long int ans = 0; n   if (a > 0 && b > 0) { n     ans = a / k - (b - 1) / k; n   } else if (a < 0 && b < 0) { n     ans = abs(b) / k - (abs(a) - 1) / k; n   } else { n     ans = abs(a) / k; n     ans += (abs(b)) / k; n     ans += 1; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2000 + 11; n const int MOD = 1e9 + 7; n int dp[N][2][2][N]; n int m, d; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> m >> d; n   string s1, s2; n   cin >> s1 >> s2; n   s1 =  .  + s1; n   s2 =  .  + s2; n   dp[0][0][0][0] = 1; n   int n = s1.size() - 1; n   for (int i = 1; i <= n; i++) n     for (int d1 = 0; d1 <= 1; d1++) n       for (int d2 = 0; d2 <= 1; d2++) n         for (int mm = 0; mm < m; mm++) { n           for (int x = 0; x <= 9; x++) { n             if (d1 == 0 && x < s1[i] -  0 ) continue; n             if (d2 == 0 && x > s2[i] -  0 ) continue; n             if (i % 2 == 1 && x == d) continue; n             if (i % 2 == 0 && x != d) continue; n             int dd1 = d1, dd2 = d2, mmm = (mm * 10 + x) % m; n             if (x > s1[i] -  0 ) dd1 = 1; n             if (x < s2[i] -  0 ) dd2 = 1; n             dp[i][dd1][dd2][mmm] = n                 (dp[i][dd1][dd2][mmm] + dp[i - 1][d1][d2][mm]) % MOD; n           } n         } n   int ans = 0; n   for (int d1 = 0; d1 <= 1; d1++) n     for (int d2 = 0; d2 <= 1; d2++) ans = (ans + dp[n][d1][d2][0]) % MOD; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cout << setprecision(10); n   ; n   int n; n   cin >> n; n   vector<int> deg(n); n   int ones = 0; n   vector<int> others, ops; n   long long total = 0; n   for (int i = 0; i < (int)n; i++) { n     cin >> deg[i]; n     if (deg[i] == 1) { n       ones++; n       ops.push_back(i); n     } else { n       total += deg[i]; n       others.push_back(i); n     } n   } n   if (total - (n - ones - 1) * 2 < ones) return cout <<  NO n , 0; n   vector<pair<int, int>> edges; n   if (others.size() == 0 && ops.size() == 2) { n     cout <<  YES 1 n ; n     cout <<  1 n ; n     cout << ops[0] + 1 <<     << ops[1] + 1 <<   n ; n     return 0; n   } n   for (int i = 1; i < (int)others.size(); i++) { n     edges.push_back({others[i - 1], others[i]}); n   } n   int opptr = 0; n   if (others.size() == 1) { n     for (int i = 0; i < (int)ops.size(); i++) n       edges.push_back({ops[i], others[0]}); n   } else { n     if (opptr < (int)ops.size()) edges.push_back({ops[opptr++], others[0]}); n     if (opptr < (int)ops.size()) edges.push_back({ops[opptr++], others.back()}); n     for (int i = 0; i < (int)deg[others[0]] - 2; i++) { n       if (opptr >= (int)ops.size()) break; n       edges.push_back({ops[opptr++], others[0]}); n     } n     for (int i = 0; i < (int)deg[others.back()] - 2; i++) { n       if (opptr >= (int)ops.size()) break; n       edges.push_back({ops[opptr++], others.back()}); n     } n   } n   for (int i = 1; i < (int)others.size() - 1; i++) { n     int av = deg[others[i]] - 2; n     while (opptr < (int)ops.size() && av > 0) { n       edges.push_back({others[i], ops[opptr++]}); n       av--; n     } n   } n   cout <<  YES   << (others.size() - 1 + (ops.size() > 0) + (ops.size() > 1)) n        <<   n ; n   cout << edges.size() <<   n ; n   for (int i = 0; i < (int)edges.size(); i++) n     cout << (edges[i].first + 1) <<     << edges[i].second + 1 <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1.0); n int dx[] = {1, -1, 0, 0, -1, 1, -1, 1}; n int dy[] = {0, 0, 1, -1, -1, -1, 1, 1}; n void file() {} n int main() { n   cout << setprecision(20) << fixed; n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int k; n   cin >> k; n   int x = 0; n   for (int i = 2; i <= 2000; i++) { n     long long s = k + i; n     if (ceil(s / (double(i - 1))) <= 1e6) { n       x = i; n       break; n     } n   } n   if (!x) return cout << -1 <<   n , 0; n   cout << x <<   n ; n   cout <<  -1  ; n   long long s = k + x; n   long long rem = s % (x - 1); n   long long num = s / (x - 1); n   for (int i = 0; i < x - 1; i++) n     if (rem) n       cout << num + 1 <<    , rem--; n     else n       cout << num <<    ; n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline void read(T &x) { n   x = 0; n   bool w = 1; n   char c = getchar(); n   while (!isdigit(c)) { n     if (c ==  - ) w = 0; n     c = getchar(); n   } n   while (isdigit(c)) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   x = w ? x : -x; n } n const long long N = 1e5 + 10, Mod = 1e9 + 7; n long long n, m, a[N], lg[N], b[N], f[N], c[N], sum[N], d[N], ans[N]; n struct en { n   long long l, r, id; n   bool operator<(const en &x) const { return r < x.r; } n } q[N]; n inline long long Get(long long x) { return f[x] ? f[x] = Get(f[x]) : x; } n inline long long ji(long long x, long long y) { n   return (b[x] - b[y + 1] * lg[y - x + 1] % Mod + Mod) % Mod; n } n inline void add(long long x, long long y) { n   f[x] = y; n   c[y] = c[x]; n   if ((x - c[x] > 30 && sum[y] > 9) || (sum[x] + (sum[y] << x - c[x])) > Mod) n     sum[y] = Mod; n   else n     sum[y] = sum[x] + (sum[y] << x - c[x]); n } n signed main() { n   read(n), read(m); n   lg[0] = 1; n   for (long long i = 1; i <= n; i++) n     read(a[i]), sum[i] = a[i], lg[i] = (lg[i - 1] << 1) % Mod, c[i] = i - 1; n   for (long long i = 1; i <= m; i++) read(q[i].l), read(q[i].r), q[i].id = i; n   for (long long i = n; i >= 1; i--) n     b[i] = ((b[i + 1] << 1) + a[i] + Mod) % Mod; n   sort(q + 1, q + m + 1); n   long long k = 1; n   for (long long i = 1; i <= n; i++) { n     while (sum[i] >= 0 && c[i]) add(c[i], i); n     d[i] = (d[c[i]] + (ji(c[i] + 1, i) << 1) % Mod + Mod) % Mod; n     while (q[k].r == i) { n       long long x = Get(q[k].l); n       ans[q[k].id] = (d[i] - d[x] + ji(q[k].l, x) + Mod) % Mod; n       k++; n     } n   } n   for (long long i = 1; i <= m; i++) printf( %lld n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long read() { n   char ch = getchar(); n   long long x = 0, ff = 1; n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) ff = -ff; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar(); n   return x * ff; n } n void write(long long aa) { n   if (aa < 0) putchar( - ), aa = -aa; n   if (aa > 9) write(aa / 10); n   putchar(aa % 10 +  0 ); n   return; n } n long long n; n long long a[200005]; n long long tt[800005], tts[800005], lz[800005]; n void up(long long rt) { n   tt[rt] = min(tt[rt << 1], tt[rt << 1 | 1]); n   if (tt[rt << 1] >= tt[rt << 1 | 1]) n     tts[rt] = tts[rt << 1 | 1]; n   else n     tts[rt] = tts[rt << 1]; n   return; n } n void bt(long long rt, long long ll, long long rr) { n   if (ll == rr) { n     tt[rt] = read(), tts[rt] = ll; n     return; n   } n   long long mid = (ll + rr) >> 1; n   bt(rt << 1, ll, mid); n   bt(rt << 1 | 1, mid + 1, rr); n   up(rt); n   return; n } n void push(long long rt) { n   if (!lz[rt]) return; n   tt[rt << 1] += lz[rt]; n   tt[rt << 1 | 1] += lz[rt]; n   lz[rt << 1] += lz[rt]; n   lz[rt << 1 | 1] += lz[rt]; n   lz[rt] = 0; n   return; n } n void update(long long rt, long long ll, long long rr, long long L, long long R, n             long long kk) { n   if (ll == L && rr == R) { n     tt[rt] += kk; n     lz[rt] += kk; n     return; n   } n   long long mid = (ll + rr) >> 1; n   push(rt); n   if (R <= mid) n     update(rt << 1, ll, mid, L, R, kk); n   else if (L > mid) n     update(rt << 1 | 1, mid + 1, rr, L, R, kk); n   else n     update(rt << 1, ll, mid, L, mid, kk), n         update(rt << 1 | 1, mid + 1, rr, mid + 1, R, kk); n   up(rt); n   return; n } n int main() { n   n = read(); n   bt(1, 1, n); n   for (long long i = 1; i <= n; ++i) { n     long long now = tts[1]; n     a[now] = i; n     update(1, 1, n, now, now, n * n); n     if (now < n) update(1, 1, n, now + 1, n, -i); n   } n   for (long long i = 1; i <= n; ++i, putchar(   )) write(a[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int k; n   scanf( %d , &k); n   if (k % 2 == 1) { n     printf( -1 n ); n     return 0; n   } n   char a[k][k]; n   memset(a, 0, sizeof(a)); n   for (int layer = 0; layer < k / 2; layer++) { n     char c; n     if (layer % 2) n       c =  w ; n     else n       c =  b ; n     for (int runner = layer; runner < k - layer; runner++) n       a[runner][layer] = a[layer][runner] = a[runner][k - layer - 1] = n           a[k - layer - 1][runner] = c; n   } n   for (int i = 0; i < k; i++) n     for (int j = 0; j < k; j++) { n       for (int l = 0; l < k; l++) n         if (i % 2) n           if (a[j][l] ==  w ) n             printf( b ); n           else n             printf( w ); n         else n           printf( %c , a[j][l]); n       printf(  n ); n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string a, s; n   cin >> a; n   cin >> s; n   long la = 0, ls = 0, i = 0, ps = 0, pv = 0; n   la = a.length(); n   ls = s.length(); n   vector<int> v; n   for (i = 0; i < ls; i++) v.push_back(s[i]); n   sort(v.rbegin(), v.rend()); n   while (ps < la && pv < ls) { n     if (a[ps] < v[pv]) { n       a[ps] = v[pv]; n       ps++; n       pv++; n     } else if (a[ps] >= v[pv]) n       ps++; n   } n   cout << a; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n int n1; n vector<long long> v; n int c[20]; n int a[20]; n bool viz[20]; n int f[20]; n inline void get(int i) { n   int cif = 0; n   long long zece = 1; n   long long r = 0; n   for (zece = 1; i > 0; i >>= 1, zece *= 10LL) { n     ++cif; n     if ((i & 1) != 0) n       r += 7LL * zece; n     else n       r += 4LL * zece; n   } n   if (r != 0LL) v.push_back(r); n   for (++cif; cif < 11; ++cif, zece *= 10LL) { n     r += 4LL * zece; n     v.push_back(r); n   } n } n void back(int k1) { n   if (k1 == n1 + 1) return; n   for (int i = 1; i <= n1; ++i) { n     if (viz[i]) continue; n     if (k > f[n1 - k1]) n       k -= f[n1 - k1]; n     else { n       viz[i] = true; n       a[k1] = i; n       back(k1 + 1); n       return; n     } n   } n   printf( -1 n ); n   exit(0); n } n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 0; i < 1024; ++i) { n     get(i); n   } n   sort(v.begin(), v.end()); n   int start = max(1, n - 12); n   f[0] = f[1] = 1; n   for (int i = 2; i < 13; ++i) f[i] = f[i - 1] * i; n   n1 = n - start + 1; n   back(1); n   int rez = 0; n   long long start1 = (long long)start; n   for (size_t i = 0, lim = v.size(); i < lim && v[i] < start1; ++i) { n     ++rez; n   } n   int x = start; n   for (int i = 1; i <= n1; ++i, ++x) { n     c[i] = x; n   } n   for (int i = 1; i <= n1; ++i) { n     if (find(v.begin(), v.end(), (long long)(i - 1) + start1) != v.end() && n         find(v.begin(), v.end(), (long long)c[a[i]]) != v.end()) n       ++rez; n   } n   printf( %d n , rez); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c, d, i, j, e, ar[105]; n   scanf( %d , &a); n   while (a--) { n     scanf( %d , &b); n     if (b == 1) { n       scanf( %d , &c); n       if (c % 2 == 0) n         printf( 1 n1 n ); n       else n         printf( -1 n ); n     } else { n       e = -1; n       for (i = 1; i <= b; i++) { n         scanf( %d , &ar[i]); n       } n       for (i = 1; i <= b; i++) { n         if (ar[i] % 2 == 0) { n           d = 1; n           break; n         } n         if (e != -1) { n           d = 2; n           break; n         } n         if (e == -1) e = i; n       } n       printf( %d n , d); n       if (d == 1) n         printf( %d n , i); n       else n         printf( %d %d n , e, i); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double mn = 1e20, mx, t; n int n, low, high; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> t; n     mn = min(mn, (t + 1 - 1e-8) / i); n     mx = max(mx, t / i); n   } n   n++; n   low = (int)(n * mx + 1e-9), high = (int)(n * mn + 1 - 1e-9); n   if (low + 1 == high) n     cout <<  unique n  << low; n   else n     cout <<  not unique ; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   string s; n   cin >> s; n   int arr[26] = {}; n   int n = s.length(); n   int count = 0; n   for (int i = 0; i < n; i++) { n     arr[s[i] -  a ]++; n     if (arr[s[i] -  a ] == 2) { n       arr[s[i] -  a ] = 0; n       count--; n     } else n       count++; n   } n   if (count == 0 || count == 1) { n     cout <<  First  n          <<   n ; n   } else { n     if (count % 2 == 0) { n       cout <<  Second  n            <<   n ; n     } else n       cout <<  First  n            <<   n ; n   } n } n int main() { n   long long t = 1; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 400100; n vector<int> grafo[MAXN]; n int a[MAXN], b[MAXN]; n pair<int, int> p[MAXN]; n int q[MAXN]; n bool vis[MAXN]; n int n; n vector<int> vec; n void dfs(int x) { n   vis[x] = true; n   vec.push_back(x); n   if (x > n) n     vis[x - n] = true; n   else n     vis[x + n] = true; n   for (int i = 0; i < grafo[x].size(); i++) { n     int at = grafo[x][i]; n     if (vis[at] == true) continue; n     dfs(at); n   } n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     cin >> n; n     vec.clear(); n     for (int i = 1; i <= 2 * n; i++) { n       p[i] = {0, 0}; n       grafo[i].clear(); n       q[i] = 0; n       vis[i] = false; n       a[i] = b[i] = 0; n     } n     for (int i = 1; i <= n; i++) { n       int x; n       cin >> x; n       a[x] = i; n       q[x]++; n       if (p[x].first == 0) n         p[x].first = i; n       else n         p[x].second = i; n     } n     for (int i = 1; i <= n; i++) { n       int x; n       cin >> x; n       b[x] = i; n       q[x]++; n       if (p[x].first == 0) n         p[x].first = i; n       else n         p[x].second = i; n     } n     bool f = true; n     for (int i = 1; i <= n; i++) n       if (q[i] != 2) f = false; n     if (f == false) { n       cout << -1 << endl; n       continue; n     } n     for (int i = 1; i <= n; i++) { n       int p1 = p[i].first, p2 = p[i].second; n       if (a[i] > 0 && b[i] > 0) { n         grafo[p1].push_back(p2); n         grafo[p2].push_back(p1); n         grafo[p1 + n].push_back(p2 + n); n         grafo[p2 + n].push_back(p1 + n); n       } else { n         grafo[p1].push_back(p2 + n); n         grafo[p2].push_back(p1 + n); n         grafo[p2 + n].push_back(p1); n         grafo[p1 + n].push_back(p2); n       } n     } n     vector<int> resp; n     for (int i = 1; i <= n; i++) { n       if (vis[i] == true) continue; n       vec.clear(); n       dfs(i); n       int h = vec.size(); n       int cnt = 0; n       for (int j = 0; j < vec.size(); j++) { n         int at = vec[j]; n         if (at > n) cnt++; n       } n       if (cnt < h - cnt) { n         for (int j = 0; j < vec.size(); j++) n           if (vec[j] > n) resp.push_back(vec[j] - n); n       } else { n         for (int j = 0; j < vec.size(); j++) n           if (vec[j] <= n) resp.push_back(vec[j]); n       } n     } n     cout << resp.size() << endl; n     for (int i = 0; i < resp.size(); i++) cout << resp[i] <<    ; n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n int read() { n   int s = 0; n   char c = getchar(), lc =  + ; n   while (c <  0  ||  9  < c) lc = c, c = getchar(); n   while ( 0  <= c && c <=  9 ) s = s * 10 + c -  0 , c = getchar(); n   return lc ==  -  ? -s : s; n } n void write(int x) { n   if (x < 0) { n     putchar( - ); n     x = -x; n   } n   if (x < 10) n     putchar(x +  0 ); n   else { n     write(x / 10); n     putchar(x % 10 +  0 ); n   } n } n void print(int x, char c =   n ) { n   write(x); n   putchar(c); n } n void L(int x) { n   putchar( L ); n   putchar(   ); n   print(x); n } n void R(int x) { n   putchar( R ); n   putchar(   ); n   print(x); n } n char a[N]; n signed main() { n   scanf( %s , a + 1); n   int n = strlen(a + 1); n   print(4); n   L(2); n   L(2); n   R(2); n   R(n + 2 + n - 1); n   return 0; n } n


#include <bits/stdc++.h> n int n, m, k, s, a[1000000], b[1000000]; n int amin[1000000]; n int bmin[1000000]; n struct Gadget { n   long long cost; n   int id; n   Gadget(long long cost, int id) : cost(cost), id(id) {} n   bool operator<(const Gadget &other) const { return cost < other.cost; } n }; n int main() { n   scanf( %d %d %d %d , &n, &m, &k, &s); n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     amin[i] = i; n     if (i > 0 && a[amin[i - 1]] < a[i]) amin[i] = amin[i - 1]; n   } n   for (int i = 0; i < n; i++) { n     scanf( %d , &b[i]); n     bmin[i] = i; n     if (i > 0 && b[bmin[i - 1]] < b[i]) bmin[i] = bmin[i - 1]; n   } n   long long asum, bsum; n   std::vector<Gadget> d, p; n   for (int i = 0; i < m; i++) { n     int t, c; n     scanf( %d %d , &t, &c); n     if (t == 1) n       d.push_back(Gadget(c, i + 1)); n     else n       p.push_back(Gadget(c, i + 1)); n   } n   d.push_back(Gadget(0, 0)); n   p.push_back(Gadget(0, 0)); n   std::sort(d.begin(), d.end()); n   std::sort(p.begin(), p.end()); n   for (int i = 1; i < d.size(); i++) d[i].cost += d[i - 1].cost; n   for (int i = 1; i < p.size(); i++) p[i].cost += p[i - 1].cost; n   int day_ans = n; n   int d_ans = 0, p_ans = 0; n   for (int i = 0; i <= std::min(k, (int)d.size() - 1); i++) { n     int j = k - i; n     if (j >= p.size()) continue; n     int left = 0, right = day_ans - 1; n     while (left <= right) { n       int mid = (left + right) >> 1; n       long long cost = d[i].cost * a[amin[mid]] + p[j].cost * b[bmin[mid]]; n       if (cost <= s) { n         if (mid < day_ans) { n           day_ans = mid; n           d_ans = i; n           p_ans = j; n         } n         right = mid - 1; n       } else { n         left = mid + 1; n       } n     } n   } n   if (day_ans == n) { n     puts( -1 ); n     return 0; n   } n   printf( %d n , day_ans + 1); n   for (int i = 1; i <= d_ans; i++) { n     printf( %d %d n , d[i].id, amin[day_ans] + 1); n   } n   for (int i = 1; i <= p_ans; i++) { n     printf( %d %d n , p[i].id, bmin[day_ans] + 1); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int to1[1000010], w[1000010], begin1[1000010], next1[1000010], v[1000010], n     p[1000010], d[1000010], e; n void add(int x, int y, int z) { n   to1[++e] = y; n   next1[e] = begin1[x]; n   begin1[x] = e; n   w[e] = z; n } n void ins(int x) { n   int i; n   for (i = 30; i >= 0; i--) n     if ((x >> i) & 1) { n       if (!p[i]) { n         p[i] = x; n         break; n       } n       x ^= p[i]; n     } n } n void dfs(int x, int now) { n   int i; n   d[x] = now; n   v[x] = 1; n   for (i = begin1[x]; i; i = next1[i]) { n     if (!v[to1[i]]) n       dfs(to1[i], now ^ w[i]); n     else n       ins(now ^ w[i] ^ d[to1[i]]); n   } n } n int find(int x) { n   int i; n   for (i = 30; i >= 0; i--) n     if ((p[i] ^ x) < x) x = p[i] ^ x; n   return x; n } n int main() { n   int i, u, v, w, n, m; n   scanf( %d%d , &n, &m); n   for (i = 1; i <= m; i++) { n     scanf( %d%d%d , &u, &v, &w); n     add(u, v, w); n     add(v, u, w); n   } n   dfs(1, 0); n   printf( %d n , find(d[n])); n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1000000000; n const long long INF = 1LL * inf * inf; n const double eps = 1e-9; n const int md = (int)1e9 + 7; n const double EPS = 1e-7; n const long long maxll = numeric_limits<long long>::max(); n const double PI = acos(-1.0); n template <typename name> n inline name sqr(name x) { n   return x * x; n } n inline long long multmod(long long a, long long b, long long md) { n   if (!a) return 0; n   if (a % 2 == 1) n     return (multmod(a - 1, b, md) + b) % md; n   else n     return sqr<long long>(multmod(a / 2, b, md)) % md; n } n template <typename name> n inline name bpow(name base, long long exp) { n   name res = base; n   while (exp) { n     if (exp % 2 == 1) { n       res = res * base; n     } n     base = base * base; n     exp /= 2; n   } n   return res; n } n int n, x, m; n double p[2000]; n struct matr { n   double a[1 << 7][1 << 7]; n } mat, qq; n const matr& operator*(const matr& x, const matr& y) { n   for (int i = 0; i < (1 << 7); i++) n     for (int j = 0; j < (1 << 7); j++) qq.a[i][j] = 0; n   for (int i = 0; i < (1 << 7); i++) n     for (int j = 0; j < (1 << 7); j++) n       for (int k = 0; k < (1 << 7); k++) qq.a[i][j] += x.a[i][k] * y.a[k][j]; n   return qq; n } n int main() { n   ios_base ::sync_with_stdio(0); n   cin >> n >> x; n   for (int i = 0; i <= x; i++) cin >> p[i]; n   for (int mask1 = 0; mask1 < (1 << 7); mask1++) n     for (int mask2 = 0; mask2 < (1 << 7); mask2++) n       mat.a[mask1][mask2] = p[mask1 ^ mask2]; n   mat = bpow(mat, n - 1); n   cout << fixed << setprecision(10) << 1 - mat.a[0][0]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n, k; n   cin >> n >> k; n   string ans =   ; n   for (long long i = 0; i < n; i++) { n     ans.push_back( a ); n   } n   for (long long i = n - 2; i >= 0; i--) { n     if (k <= n - i - 1) { n       ans[i] =  b ; n       ans[n - k] =  b ; n       break; n     } n     k -= (n - i - 1); n   } n   cout << ans << endl; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, a, b, c, d, x, y, x1, x2, y1, y2; n   scanf( %d , &t); n   while (t--) { n     scanf( %d%d%d%d , &a, &b, &c, &d); n     int t1 = a - b; n     int t2 = c - d; n     scanf( %d%d%d%d%d%d , &x, &y, &x1, &y1, &x2, &y2); n     if (x - t1 >= x1 && x - t1 <= x2 && y - t2 >= y1 && y - t2 <= y2) { n       if ((a > 0 || b > 0) && x1 == x2) n         printf( NO n ); n       else if ((c > 0 || d > 0) && y1 == y2) n         printf( NO n ); n       else n         printf( YES n ); n     } else n       printf( NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0), cout.tie(0); n   cin.tie(0), cout.tie(0); n   ; n   long long int a, b, t, n, m, k, i, j, l, sum = 0, sum1 = 0, ans = 0; n   vector<long long int> v; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> a; n     v.push_back(a); n     if (i & 1) { n       sum1 += a; n     } else n       sum += a; n   } n   ans = max(sum1, sum); n   for (i = 0; i < n; i++) { n     if (i & 1) { n       sum1 -= v[i]; n       sum += v[i]; n     } else { n       sum -= v[i]; n       sum1 += v[i]; n     } n     ans = max(ans, max(sum, sum1)); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long a, b, c; n   cin >> a; n   b = a - 1; n   c = a - 2; n   if (a >= 3) { n     if (b % 2 != 0) { n       if (a % 3 == 0) { n         long long e = a * b * c / 2; n         long long r = a * b * (c - 1) / 3; n         long long t = a * b * (c - 2) / 2; n         long long y = a * b * (c - 3); n         long long h = (a - 1) * (b - 1) * (c - 1); n         cout << max(max(max(e, r), max(t, y)), h); n       } else { n         c--; n         cout << a * b * c; n       } n     } else { n       cout << a * b * c; n     } n   } else { n     b = 1; n     c = 1; n     cout << a * b * c; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int h; n int edge[5000]; n int extend[5000]; n int maximum; n int v[5000]; n bool flag = 0; n void dfs_m(int p, int value) { n   v[p] = value; n   if (edge[p * 2] != 0) n     dfs_m(p * 2 + 0, value + edge[p * 2]); n   else { n     if (maximum < value) maximum = value; n   } n   if (edge[p * 2 + 1] != 0) n     dfs_m(p * 2 + 1, value + edge[p * 2 + 1]); n   else { n     if (maximum < value) maximum = value; n   } n } n void dfs(int p, int value) { n   if (edge[p * 2] != 0) { n     dfs(p * 2, value + edge[p * 2] + extend[p * 2]); n   } else { n     if (value < maximum) { n       extend[p] += (maximum - value); n     } n   } n   if (edge[p * 2 + 1] != 0) { n     dfs(p * 2 + 1, value + edge[p * 2 + 1] + extend[p * 2 + 1]); n   } else { n     if (value < maximum) { n       extend[p] += (maximum - value); n     } n   } n } n int min(int a, int b) { n   if (a == b) return -1; n   if (a < b) { n     return a; n   } n   return b; n } n void merge(int n) { n   if (extend[n * 2] != 0 && extend[n * 2 + 1] != 0) { n     int m = min(extend[n * 2 + 1], extend[n * 2]); n     flag = false; n     if (m == -1) { n       extend[n] += extend[n * 2 + 1]; n       extend[n * 2] = extend[n * 2 + 1] = 0; n       merge(n / 2); n     } else { n       extend[n] += m; n       extend[n * 2] -= m; n       extend[n * 2 + 1] -= m; n       merge(n / 2); n     } n   } n } n int main() { n   scanf( %d , &h); n   int e = pow(2, h + 1) - 2; n   memset(edge, 0, sizeof(edge)); n   memset(extend, 0, sizeof(extend)); n   memset(v, 0, sizeof(v)); n   for (int i = 2; i <= e + 1; i++) { n     scanf( %d , &edge[i]); n   } n   maximum = 0; n   dfs_m(1, 0); n   dfs(1, 0); n   int node = pow(2, h + 1); n   for (int i = 2; i <= e + 1; i++) { n     extend[i] /= 2; n   } n   while (true) { n     flag = true; n     for (int i = 0; i < node; i++) { n       merge(i); n     } n     for (int i = 2; i <= e + 1; i++) { n     } n     if (flag) { n       break; n     } n   } n   int ans = 0; n   for (int i = 0; i <= e + 1; i++) { n     ans += extend[i]; n   } n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<pair<long long int, long long int>, int> m; n long long int comb(long long int n, long long int r) { n   int k1, k2; n   if (m[make_pair(n, r)] != 0) return m[make_pair(n, r)]; n   if (r > n) return 0; n   if (n == r) return 1; n   if (r == 0) return 1; n   if (r == 1) return n; n   k1 = comb(n - 1, r - 1); n   k2 = comb(n - 1, r); n   m[make_pair(n - 1, r - 1)] = k1; n   m[make_pair(n - 1, r)] = k2; n   return k1 + k2; n } n int main() { n   long long int n, m, t, k1 = 0, k2 = 0, k3 = 0, sum = 0, i = 0, x, y; n   cin >> n >> m >> t; n   if ((n + m) < t) cout << 0; n   if (n < 4 || m < 1) cout << 0; n   for (x = 4; x <= t - 1; x++) { n     if (m >= (t - x)) sum += (comb(n, x) * comb(m, t - x)); n   } n   cout << sum; n } n


#include <bits/stdc++.h> n using namespace std; n int a[123], p[123]; n signed main() { n   int t; n   scanf( %d , &t); n   while (t--) { n     int n, m; n     scanf( %d %d , &n, &m); n     memset(p, 0, sizeof(p)); n     for (int i = 1; i <= n; ++i) scanf( %d , a + i); n     for (int i = 1, x; i <= m; ++i) scanf( %d , &x), p[x] = 1; n     bool ok = 1; n     for (int i = 1; i <= n; ++i) n       for (int j = i + 1; j <= n; ++j) { n         if (!ok) break; n         if (a[i] > a[j]) n           for (int k = i; k < j; ++k) n             if (!p[k]) { n               ok = 0; n               break; n             } n       } n     ok ? puts( YES ) : puts( NO ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long fac[3000060]; n void pre() { n   fac[0] = 1; n   for (int i = 1; i < 3000060; i++) fac[i] = fac[i - 1] * i % 1000000007; n } n long long powermod(long long x, long long y, long long p) { n   long long res = 1; n   x = x % p; n   if (x == 0) return 0; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n long long nCrmod(long long n, long long r, long long p) { n   if (r == 0) return 1; n   return (fac[n] * powermod(fac[r], p - 2, p) % p * n           powermod(fac[n - r], p - 2, p) % p) % n          p; n } n void solve() { n   long long n; n   cin >> n; n   long long use[n][n]; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       cin >> use[i][j]; n     } n   } n   for (int i = 0; i < n; i++) { n     long long p = (use[i][(i + 1) % n] * use[i][(i + 2) % n]) / n                   use[(i + 1) % n][(i + 2) % n]; n     p = sqrt(p); n     cout << p <<    ; n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.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 long long inf = 1e18; n vector<long long> a; n map<long long, bool> p; n int binp(long long x) { n   int l = 0, r = 1e9 + 1; n   while (r - l > 1) { n     int m = (l + r) / 2; n     if (1LL * m * m <= x) n       l = m; n     else n       r = m; n   } n   return l; n } n int main() { n   a.push_back(0); n   for (long long i = 2; i <= 1000000; ++i) { n     long long cur = i * i * i; n     while (inf / i >= cur) { n       long long x = binp(cur); n       if (!p[cur] && x * x != cur) a.push_back(cur); n       p[cur] = 1; n       cur *= i; n     } n     long long x = binp(cur); n     if (!p[cur] && x * x != cur) a.push_back(cur); n     p[cur] = 1; n   } n   sort(a.begin(), a.end()); n   int t; n   scanf( %d , &t); n   while (t--) { n     long long l, r; n     scanf( %lld %lld , &l, &r); n     long long ans = upper_bound(a.begin(), a.end(), r) - n                     upper_bound(a.begin(), a.end(), l - 1); n     ans += binp(r) - binp(l - 1); n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC target(   n      sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native ) n void read(int &a) { n   a = 0; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     a = (a << 1) + (a << 3) + (c ^ 48); n     c = getchar(); n   } n } n const int Maxn = 50000; n const int Inf = 0x3f3f3f3f; n int n, q; n int a[Maxn + 5]; n int fa[Maxn + 5]; n int head[Maxn + 5], arrive[Maxn + 5], nxt[Maxn + 5], tot; n void add_edge(int from, int to) { n   arrive[++tot] = to; n   nxt[tot] = head[from]; n   head[from] = tot; n } n int dep[Maxn + 5], dis[Maxn + 5]; n int dfn[Maxn + 5], right[Maxn + 5], rnk[Maxn + 5], dfn_tot, sz[Maxn + 5]; n int sum[Maxn + 5]; n long long f[Maxn + 5]; n void init_dfs(int u) { n   dep[u] = dep[fa[u]] + 1; n   if (a[u] != 1) { n     dfn[u] = ++dfn_tot; n     dis[dfn_tot] = dep[u]; n     rnk[dfn_tot] = u; n     sz[u] = 1; n     sum[u] = 0; n   } else { n     dfn[u] = dfn_tot + 1; n     sz[u] = 0; n     sum[u] = 1; n   } n   for (int i = head[u]; i; i = nxt[i]) { n     int v = arrive[i]; n     init_dfs(v); n     sz[u] += sz[v]; n     sum[u] += sum[v]; n     f[u] += f[v]; n     f[u] += sum[v]; n   } n   right[u] = dfn[u] + sz[u] - 1; n } n int del[Maxn + 5]; n int main() { n   read(n), read(q); n   for (register int i = 1; i <= n; ++i) { n     read(a[i]); n     del[i] = -Inf; n   } n   for (register int i = 2; i <= n; ++i) { n     read(fa[i]); n     add_edge(fa[i], i); n   } n   init_dfs(1); n   for (register int i = 1; i <= q; ++i) { n     int u; n     read(u); n     long long ans_1 = 0; n     int ans_2 = 0; n     for (register int j = dfn[u]; j <= right[u]; ++j) { n       int tmp = (i >= del[j]); n       ans_1 += dis[j] * tmp; n       ans_2 += tmp; n       del[j] = (tmp ? i + a[rnk[j]] : del[j]); n     } n     ans_1 -= 1ll * ans_2 * dep[u]; n     ans_1 += f[u], ans_2 += sum[u]; n     printf( %lld %d n , ans_1, ans_2); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n long long sum[1505][1505]; n long long ans[1505]; n long long t[1505]; n int main() { n   int i, j, x; n   long long val, now, res; n   scanf( %d%d , &n, &m); n   for (i = 1; i <= n; i++) n     for (j = 1; j <= m; j++) n       scanf( %I64d , &val), sum[i][j] = sum[i][j - 1] + val; n   for (i = 1; i <= m; i++) ans[i] = sum[1][i]; n   for (i = 2; i <= n; i++) { n     if (i % 2 == 0) { n       now = -(long long)1e15; n       for (x = m; x > 0; x--) { n         t[x] = now + sum[i][x]; n         now = max(now, ans[x]); n       } n     } else { n       now = -(long long)1e15; n       for (x = 1; x <= m; x++) { n         t[x] = now + sum[i][x]; n         now = max(now, ans[x]); n       } n     } n     for (x = 1; x <= m; x++) ans[x] = t[x]; n   } n   res = -(long long)1e15; n   for (x = 1; x <= m; x++) res = max(res, ans[x]); n   printf( %I64d , res); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, m, a[105], cnt = 0, i; n   fill_n(a, 105, 0); n   for (cin >> m >> n; n; n /= m) a[cnt++] = n % m; n   if (cnt > 100) { n     cout <<  NO ; n     return 0; n   } n   for (i = 0; i < 105; ++i) { n     if (a[i] <= 1) n       continue; n     else if (a[i] < m - 1) { n       cout <<  NO ; n       return 0; n     } else n       ++a[i + 1]; n   } n   cout <<  YES ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100 * 1000 + 10, M = 300 + 10; n int a[N], dp[N][M]; n vector<int> p[N]; n int main() { n   ios_base::sync_with_stdio(false); n   int n, m, s, e; n   cin >> n >> m >> s >> e; n   for (int i = (0); i <= (n - 1); i++) cin >> a[i]; n   for (int i = (1); i <= (m); i++) { n     int x; n     cin >> x; n     p[x].emplace_back(i); n   } n   int ans = 0; n   for (int i = (0); i <= (s / e); i++) dp[0][i] = i * (m + 1); n   for (int i = (1); i <= (n); i++) { n     for (int j = (1); j <= (s / e); j++) { n       auto it = upper_bound((p[a[i - 1]]).begin(), (p[a[i - 1]]).end(), n                             (j == 1 ? 0 : dp[i - 1][j - 1])); n       dp[i][j] = dp[i - 1][j]; n       if (it != p[a[i - 1]].end()) { n         dp[i][j] = min(dp[i][j], *it); n         if (s - e * j >= i + dp[i][j]) ans = max(ans, j); n       } n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Node { n   int val; n   int op; n   int cl; n   Node(int x, int y, int z) { n     val = x; n     op = y; n     cl = z; n   } n   Node() { Node(0, 0, 0); }; n }; n string s; n vector<Node> ST; n Node temp; n int n, t, x, y, t1, t2; n void update(int root, int l, int r, int pos) { n   if (l > pos || r < pos) return; n   if (l == r) { n     if (s[pos - 1] ==  ( ) ST[root].op = 1; n     if (s[pos - 1] ==  ) ) ST[root].cl = 1; n     return; n   } n   int mid = (l + r) / 2; n   update(root * 2, l, mid, pos); n   update(root * 2 + 1, mid + 1, r, pos); n   ST[root].val = ST[root * 2].val + ST[root * 2 + 1].val + n                  min(ST[root * 2].op - ST[root * 2].val, n                      ST[root * 2 + 1].cl - ST[root * 2 + 1].val); n   ST[root].op = ST[root * 2].op + ST[root * 2 + 1].op; n   ST[root].cl = ST[root * 2].cl + ST[root * 2 + 1].cl; n } n Node get(int root, int l, int r, int u, int v) { n   if (u > r || v < l) return Node(0, 0, 0); n   if (u == l && v == r) return ST[root]; n   int mid = (l + r) / 2; n   if (v <= mid) n     return get(root * 2, l, mid, u, v); n   else if (u > mid) n     return get(root * 2 + 1, mid + 1, r, u, v); n   else { n     Node n1 = get(root * 2, l, mid, u, mid), n          n2 = get(root * 2 + 1, mid + 1, r, mid + 1, v); n     int t1 = n1.val + n2.val + min(n1.op - n1.val, n2.cl - n2.val); n     return Node(t1, n1.op + n2.op, n1.cl + n2.cl); n   } n } n int main() { n   cin >> s; n   n = s.size(); n   for (int i = 0; i < 4 * n; ++i) ST.push_back(Node(0, 0, 0)); n   for (int i = 1; i <= n; ++i) update(1, 1, n, i); n   cin >> t; n   while (t--) { n     cin >> x >> y; n     cout << get(1, 1, n, x, y).val * 2 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   int i, j, t, n, a[150], b[150], sum1 = 0, sum2 = 0; n   cin >> n; n   for (i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   for (i = 1; i <= n; i++) { n     cin >> b[i]; n   } n   for (i = 1; i <= n; i++) { n     if (a[i] && !b[i]) sum1++; n     if (!a[i] && b[i]) sum2++; n   } n   if (sum1 == 0) { n     cout <<  -1  <<   n ; n   } else if (sum1 > sum2) { n     cout << 1 <<   n ; n   } else { n     int k = sum2 / sum1; n     k++; n     cout << k <<   n ; n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n double maxoo(double, double); n int main() { n   int p1, p2, t1, t2; n   cin >> p1 >> p2 >> t1 >> t2; n   double p11, p12, p21, p22, misha, vasya; n   p11 = (3 * p1) / 10; n   p12 = (p1 - (p1 / 250) * t1); n   p21 = (3 * p2) / 10; n   p22 = p2 - (p2 / 250) * t2; n   misha = maxoo(p11, p12); n   vasya = maxoo(p21, p22); n   if (misha > vasya) n     cout <<  Misha ; n   else if (misha == vasya) n     cout <<  Tie ; n   else if (misha < vasya) n     cout <<  Vasya ; n   return 0; n } n double maxoo(double m, double n) { n   if (m >= n) n     return m; n   else n     return n; n } n


#include <bits/stdc++.h> n using namespace std; n struct SuffixArray { n   char* T; n   int n; n   vector<int> RA, tempRA; n   vector<int> SA, tempSA, c; n   vector<int> phi, pLCP, LCP; n   SuffixArray(string& t) { n     n = t.length(); n     T = new char[n + n]; n     for (int i = 0; i < n; T[i] = t[i], i++) n       ; n     T[n++] =  # , T[n] =   0 ; n     c.resize(max(300, n)); n     RA.resize(n), tempRA.resize(n); n     SA.resize(n), tempSA.resize(n); n   } n   void countingSort(int k) { n     fill(c.begin(), c.end(), 0); n     for (int i = 0; i < n; i++) c[i + k < n ? RA[i + k] : 0]++; n     for (int i = 0, sum = 0, lim = max(300, n); i < lim; i++) { n       int t = c[i]; n       c[i] = sum, sum += t; n     } n     for (int i = 0; i < n; i++) n       tempSA[c[SA[i] + k < n ? RA[SA[i] + k] : 0]++] = SA[i]; n     for (int i = 0; i < n; i++) SA[i] = tempSA[i]; n   } n   void buildSA() { n     for (int i = 0; i < n; SA[i] = i, i++) n       ; n     for (int i = 0; i < n; RA[i] = T[i], i++) n       ; n     for (int k = 1, r; k < n; k <<= 1) { n       countingSort(k); n       countingSort(0); n       tempRA[SA[0]] = r = 0; n       for (int i = 1; i < n; i++) { n         tempRA[SA[i]] = n             (RA[SA[i]] == RA[SA[i - 1]] and RA[SA[i] + k] == RA[SA[i - 1] + k] n                  ? r n                  : ++r); n       } n       for (int i = 0; i < n; RA[i] = tempRA[i], i++) n         ; n       if (RA[SA[n - 1]] == n - 1) break; n     } n   } n   void computeLCP() { n     phi.resize(n), pLCP.resize(n), LCP.resize(n); n     phi[SA[0]] = -1; n     for (int i = 1; i < n; phi[SA[i]] = SA[i - 1], i++) n       ; n     for (int i = 0, L = 0; i < n; i++) { n       if (phi[i] == -1) { n         pLCP[i] = 0; n         continue; n       } n       for (; T[i + L] == T[phi[i] + L]; L++) n         ; n       pLCP[i] = L; n       L = max(0, L - 1); n     } n     for (int i = 0; i < n; LCP[i] = pLCP[SA[i]], i++) n       ; n   } n   void print() { n     for (int i = 0; i + 1 < n; i++) { n       printf( %2d t%2d t%s n , SA[i], LCP[i], T + SA[i]); n     } n   } n }; n struct Node { n   int sum, lft, rgt; n   Node() : sum(0), lft(0), rgt(0) {} n }; n struct PersistantSegmentTree { n   int avail; n   vector<int> roots; n   vector<Node> tree; n   PersistantSegmentTree(int n) { n     avail = 0; n     roots.resize(n + 10, 0); n     tree.resize(n * 30, Node()); n   } n   int update(int last, int l, int r, int p) { n     int cur = ++avail; n     tree[cur] = tree[last]; n     if (l == r) { n       tree[cur].sum++; n       return cur; n     } n     int mid = l + (r - l) / 2; n     if (p <= mid) n       tree[cur].lft = update(tree[last].lft, l, mid, p); n     else n       tree[cur].rgt = update(tree[last].rgt, mid + 1, r, p); n     tree[cur].sum = tree[tree[cur].lft].sum + tree[tree[cur].rgt].sum; n     return cur; n   } n   int query(int cur, int l, int r, int L, int R) { n     if (l > R or r < L or L > R) return 0; n     if (l >= L and r <= R) return tree[cur].sum; n     int mid = l + (r - l) / 2; n     int pp = query(tree[cur].lft, l, mid, L, R); n     int qq = query(tree[cur].rgt, mid + 1, r, L, R); n     return pp + qq; n   } n }; n int main() { n   ios_base ::sync_with_stdio(0); n   cin.tie(0), cout.tie(0); n   int n; n   string s; n   cin >> n >> s; n   SuffixArray SA(s); n   SA.buildSA(); n   SA.computeLCP(); n   PersistantSegmentTree PSG(SA.n); n   vector<int> have; n   for (int i = n - 1; i >= 0; i--) { n     if (s[i] ==  ) ) { n       have.push_back(i); n       continue; n     } n     if (!have.empty()) { n       PSG.roots[i] = n           PSG.update(PSG.roots[have.back() + 1], 0, SA.n, have.back()); n       have.pop_back(); n     } n   } n   long long res = 0; n   for (int i = 1; i < SA.n; i++) { n     if (s[SA.SA[i]] ==  ) ) continue; n     int L = SA.SA[i]; n     int R = L + SA.LCP[i] - 1; n     int add = PSG.query(PSG.roots[L], 0, SA.n, L, SA.n); n     int bad = PSG.query(PSG.roots[L], 0, SA.n, L, R); n     res += (0, max(0, add - bad)); n   } n   cout << res <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n long long sum[500]; n int deep[500]; n int in1[500]; n int out1[500]; n int in2[500]; n int out2[500]; n vector<int> maps1[500]; n vector<int> maps2[500]; n long long dp[150000]; n long long n, m, t; n int cnt = 0; n void topo2() { n   queue<int> q; n   for (int i = 1; i <= n; ++i) n     if (in2[i] == 0) { n       q.push(i); n       deep[i] = 0; n     } n   int n1, n2; n   while (!q.empty()) { n     n1 = q.front(); n     q.pop(); n     cnt++; n     t -= deep[n1] * sum[n1]; n     for (int i = 0; i < maps2[n1].size(); ++i) { n       n2 = maps2[n1][i]; n       in2[n2]--; n       deep[n2] = max(deep[n2], deep[n1] + 1); n       if (in2[n2] == 0) q.push(n2); n     } n   } n } n void topo1() { n   queue<int> q; n   int n1, n2; n   for (int i = 1; i <= n; ++i) n     if (in1[i] == 0) { n       q.push(i); n     } n   while (!q.empty()) { n     n1 = q.front(); n     q.pop(); n     for (int i = 0; i < maps1[n1].size(); ++i) { n       n2 = maps1[n1][i]; n       in1[n2]--; n       sum[n2] += sum[n1]; n       if (in1[n2] == 0) { n         q.push(n2); n       } n     } n   } n } n int main() { n   scanf( %lld%lld%lld , &n, &m, &t); n   for (int i = 1; i <= n; ++i) scanf( %lld , &sum[i]); n   for (int i = 1; i <= m; ++i) { n     int x, y; n     scanf( %d%d , &x, &y); n     maps1[x].push_back(y); n     in1[y]++; n     out1[x]++; n     maps2[y].push_back(x); n     in2[x]++; n     out2[y]++; n   } n   topo2(); n   if (t < 0 || cnt != n) n     printf( 0 n ); n   else { n     topo1(); n     memset(dp, 0, sizeof(dp)); n     dp[0] = 1; n     for (long long i = 1; i <= n; ++i) { n       for (long long j = sum[i]; j <= t; ++j) { n         dp[j] += dp[j - sum[i]]; n         dp[j] %= 1000000007; n       } n     } n     printf( %lld n , dp[t]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int wyn[1024]; n int odp[1024]; n int n; n int pyt; n vector<pair<int, int> > v[2]; n void pytaj(vector<int>& skad, vector<int>& gdzie) { n   if (skad.size() == 0) return; n   printf( %d n , int(skad.size())); n   for (int i = 0; i < skad.size(); i++) printf( %d  , skad[i] + 1); n   printf(  n ); n   fflush(stdout); n   for (int i = 0; i < n; i++) scanf( %d , &odp[i]); n   pyt++; n   for (int q = 0; q < gdzie.size(); q++) { n     int i = gdzie[q]; n     wyn[i] = min(wyn[i], odp[i]); n   } n } n int main() { n   pyt = 0; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) wyn[i] = 1000000010; n   v[0].push_back(make_pair(0, n - 1)); n   int akt = 0; n   while (!v[akt].empty()) { n     v[1 - akt].clear(); n     vector<int> pyt1, pyt2; n     for (int k = 0; k < v[akt].size(); k++) { n       int a = v[akt][k].first; n       int b = v[akt][k].second; n       int sr = (a + b) / 2; n       for (int q = a; q <= sr; q++) pyt1.push_back(q); n       for (int q = sr + 1; q <= b; q++) pyt2.push_back(q); n       if (sr > a) v[1 - akt].push_back(make_pair(a, sr)); n       if (b > sr + 1) v[1 - akt].push_back(make_pair(sr + 1, b)); n     } n     pytaj(pyt1, pyt2); n     pytaj(pyt2, pyt1); n     akt = 1 - akt; n   } n   printf( -1 n ); n   for (int i = 0; i < n; i++) printf( %d  , wyn[i]); n   printf(  n ); n   fflush(stdout); n } n


#include <bits/stdc++.h> n using namespace std; n int main(void) { n   int n; n   cin >> n; n   if (n == 0) { n     cout << 1 << endl; n     return 0; n   } n   vector<double> p(n); n   vector<int> powers(n, 1); n   vector<double> curval(n); n   using pdi = pair<double, int>; n   priority_queue<pdi, vector<pdi>> q; n   double prob = 1.0; n   for (int i = 0; i < n; ++i) { n     cin >> p[i]; n     p[i] /= 100.0; n     prob *= p[i]; n     curval[i] = p[i]; n     q.push(pdi((1 - pow(1 - p[i], powers[i] + 1)) / curval[i], i)); n   } n   double result = n + 1 - prob; n   for (int i = 0; i < 500000; ++i) { n     auto c = q.top(); n     q.pop(); n     prob /= curval[c.second]; n     ++powers[c.second]; n     curval[c.second] = 1 - pow(1 - p[c.second], powers[c.second]); n     prob *= curval[c.second]; n     q.push( n         pdi((1 - pow(1 - p[c.second], powers[c.second] + 1)) / curval[c.second], n             c.second)); n     result += 1 - prob; n   } n   cout << fixed << setprecision(20) << result << endl; n } n


n // Problem: A. Robot Program n // Contest: Codeforces - Educational Codeforces Round 98 (Rated for Div. 2) n // URL: https://codeforces.com/contest/1452/problem/A n // Memory Limit: 256 MB n // Time Limit: 2000 ms n // Powered by CP Editor (https://github.com/cpeditor/cpeditor) n  n #include <bits/stdc++.h> n  n using namespace std; n  n #define fi first n #define se second n #define pb push_back n #define int long long n #define F(i, n) for (int i = 0; i < n; i++) n #define all(x)(x).begin(), (x).end() n  n using ld = long double; n using vi = vector <int>; n using mi = map <int, int>; n using pii = pair <int, int>; n  n const int N = 100005; n const int MOD = 1e9 + 7; n  n #define show(arr) { for (auto x: arr) cout << x <<    ; cout <<   n ; } n #define show_(arr, n) F(i, n) show(arr[i]) n  n void solve() { n  int n; cin>>n; n  int a[n],sum=0,mx=0; n  F(i,n){ n   cin>>a[i]; n   sum+=a[i]; n   mx=max(mx,a[i]); n  } n  cout<<max((n-1)*((sum+n-2)/(n-1)),mx*(n-1))-sum<<  n ; n } n int32_t main() { n    ios::sync_with_stdio(false); n    cin.tie(0); n    cout.tie(0); n  n    int32_t t=1; n    cin >> t; n    while (t--) solve(); n  n    return 0; n }


#include <bits/stdc++.h> n using namespace std; n using namespace std; n int k; n string ad; n vector<string> c(string s) { n   vector<string> ans; n   int last = 0; n   for (long long i = 0; i < (s.size()); i++) { n     if (s[i] ==     || s[i] ==  -  || i == s.size() - 1) { n       ans.push_back(s.substr(last, i - last + 1)); n       last = i + 1; n     } n   } n   return ans; n } n vector<string> v; n bool check(int mid) { n   int nlen = 0; n   int cnt = 1; n   for (long long i = 0; i < (v.size()); i++) { n     if (v[i].size() > mid) { n       return false; n     } n     if (nlen + v[i].size() <= mid) { n       nlen += v[i].size(); n     } else { n       nlen = v[i].size(); n       cnt++; n     } n   } n   if (cnt <= k) { n     return true; n   } n   return false; n } n int main() { n   cin >> k; n   cin.ignore(); n   getline(cin, ad,   n ); n   v = c(ad); n   int l = 0, r = ad.size(); n   while (l < r) { n     int mid = (l + r) >> 1; n     if (!check(mid)) { n       l = mid + 1; n     } else { n       r = mid; n     } n   } n   cout << r; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b, r, x; n int main() { n   cin >> a; n   b = 45 * 17 * 10000000000000000LL; n   r = 100000000000000000LL - 1; n   x = b % a; n   cout << a - x <<     << a - x + r; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(2) n #pragma GCC optimize(3) n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( inline ) n #pragma GCC optimize( -fgcse ) n #pragma GCC optimize( -fgcse-lm ) n #pragma GCC optimize( -fipa-sra ) n #pragma GCC optimize( -ftree-pre ) n #pragma GCC optimize( -ftree-vrp ) n #pragma GCC optimize( -fpeephole2 ) n #pragma GCC optimize( -ffast-math ) n #pragma GCC optimize( -fsched-spec ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC optimize( -falign-jumps ) n #pragma GCC optimize( -falign-loops ) n #pragma GCC optimize( -falign-labels ) n #pragma GCC optimize( -fdevirtualize ) n #pragma GCC optimize( -fcaller-saves ) n #pragma GCC optimize( -fcrossjumping ) n #pragma GCC optimize( -fthread-jumps ) n #pragma GCC optimize( -funroll-loops ) n #pragma GCC optimize( -fwhole-program ) n #pragma GCC optimize( -freorder-blocks ) n #pragma GCC optimize( -fschedule-insns ) n #pragma GCC optimize( inline-functions ) n #pragma GCC optimize( -ftree-tail-merge ) n #pragma GCC optimize( -fschedule-insns2 ) n #pragma GCC optimize( -fstrict-aliasing ) n #pragma GCC optimize( -fstrict-overflow ) n #pragma GCC optimize( -falign-functions ) n #pragma GCC optimize( -fcse-skip-blocks ) n #pragma GCC optimize( -fcse-follow-jumps ) n #pragma GCC optimize( -fsched-interblock ) n #pragma GCC optimize( -fpartial-inlining ) n #pragma GCC optimize( no-stack-protector ) n #pragma GCC optimize( -freorder-functions ) n #pragma GCC optimize( -findirect-inlining ) n #pragma GCC optimize( -frerun-cse-after-loop ) n #pragma GCC optimize( inline-small-functions ) n #pragma GCC optimize( -finline-small-functions ) n #pragma GCC optimize( -ftree-switch-conversion ) n #pragma GCC optimize( -foptimize-sibling-calls ) n #pragma GCC optimize( -fexpensive-optimizations ) n #pragma GCC optimize( -funsafe-loop-optimizations ) n #pragma GCC optimize( inline-functions-called-once ) n #pragma GCC optimize( -fdelete-null-pointer-checks ) n using namespace std; n inline long long read() { n   long long x = 0, y = 0, c = getchar(); n   while (!isdigit(c)) y = c, c = getchar(); n   while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^  0 ), c = getchar(); n   return y ==  -  ? -x : x; n } n inline void print(long long q) { n   if (q < 0) putchar( - ), q = -q; n   if (q >= 10) print(q / 10); n   putchar(q % 10 +  0 ); n } n int n, m, k; n struct edge { n   int fr, to, val, id; n   bool fg; n } e[1000010]; n int f[1000010]; n inline int getf(int q) { return f[q] == q ? q : f[q] = getf(f[q]); } n inline bool operator<(edge q, edge w) { n   return q.val == w.val ? q.fg < w.fg : q.val < w.val; n } n inline bool cmp(edge q, edge w) { n   return q.val == w.val ? q.fg > w.fg : q.val < w.val; n } n int as[1000010], ft; n bool usd[1000010]; n inline int work() { n   int i, as = 0, as2 = 0; n   sort(e + 1, e + m + 1); n   for (i = 1; i <= n; ++i) f[i] = i; n   for (i = 1; i <= m; ++i) n     if (getf(e[i].fr) != getf(e[i].to)) { n       f[f[e[i].fr]] = f[e[i].to]; n       as += e[i].fg; n       ++as2; n     } n   return as2 != n - 1 ? -1 : as; n } n int main() { n   int i, j, l, r, mid, ans; n   n = read(); n   m = read(); n   k = read(); n   for (i = 1; i <= m; ++i) { n     e[i].fr = read(); n     e[i].to = read(); n     e[i].val = read(); n     e[i].id = i; n     e[i].fg = (e[i].fr == 1 || e[i].to == 1); n   } n   l = -1e6; n   r = 1e6; n   ans = l - 1; n   while (l <= r) { n     mid = l + r >> 1; n     for (i = 1; i <= m; ++i) n       if (e[i].fg) e[i].val -= mid; n     int tmp = work(); n     if (tmp == -1) { n       puts( -1 ); n       return 0; n     } n     if (tmp <= k) n       ans = mid, l = mid + 1; n     else n       r = mid - 1; n     for (i = 1; i <= m; ++i) n       if (e[i].fg) e[i].val += mid; n   } n   if (ans == -1e6 - 1) { n     puts( -1 ); n     return 0; n   } n   int tp = 0; n   for (i = 1; i <= m; ++i) n     if (e[i].fg) e[i].val -= ans; n   sort(e + 1, e + m + 1); n   for (i = 1; i <= n; ++i) f[i] = i; n   for (i = 1; i <= m; ++i) n     if (getf(e[i].fr) != getf(e[i].to)) { n       f[f[e[i].fr]] = f[e[i].to]; n       if (e[i].fg) usd[e[i].id] = 1, as[++ft] = e[i].id, ++tp; n     } n   if (tp > k) { n     puts( -1 ); n     return 0; n   } n   for (i = 1; i <= n; ++i) f[i] = i; n   for (i = 1; i <= m; ++i) n     if (usd[e[i].id]) f[getf(e[i].fr)] = getf(e[i].to); n   sort(e + 1, e + m + 1, cmp); n   for (i = 1; i <= m; ++i) n     if (!usd[e[i].id] && getf(e[i].fr) != getf(e[i].to)) { n       if (e[i].fg && tp == k) continue; n       f[f[e[i].fr]] = f[e[i].to]; n       as[++ft] = e[i].id; n       tp += e[i].fg; n     } n   if (tp < k) { n     puts( -1 ); n     return 0; n   } n   print(ft); n   putchar(  n ); n   for (i = 1; i <= ft; ++i) print(as[i]), putchar(   ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline void getar(T a, int n, int m) { n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; ++j) { n       scanf( %d , &a[i][j]); n     } n } n inline void getar(int *a, int n) { n   for (int ii = 0; ii < n; ii++) { n     scanf( %d , a + ii); n   } n } n inline void getar(pair<int, int> *a, int n) { n   for (int ii = 0; ii < n; ii++) { n     scanf( d , &a[ii].first, &a[ii].second); n   } n } n inline void getar(long long *a, int n) { n   for (int ii = 0; ii < n; ii++) { n     scanf( %I64d , a + ii); n   } n } n inline void getv(vector<int> &a, int n) { n   for (int ii = 0; ii < n; ii++) { n     scanf( %d , &a[ii]); n   } n } n inline void getv(vector<long long> &a, int n) { n   for (int ii = 0; ii < n; ii++) { n     scanf( %I64d , &a[ii]); n   } n } n inline void getv(vector<pair<int, int> > &a, int n) { n   for (int ii = 0; ii < n; ii++) { n     scanf( %d , &a[ii].first, &a[ii].second); n   } n } n inline void getv(vector<pair<long long, long long> > &a, int n) { n   for (int ii = 0; ii < n; ii++) { n     scanf( %I64d , &a[ii].first, &a[ii].second); n   } n } n inline void getvv(vector<vector<int> > &a, int n, int m) { n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; ++j) { n       scanf( %d , &a[i][j]); n     } n } n inline void printa(int *a, int i, int j) { n   for (int ii = i; ii <= j; ii++) { n     printf( %d  , a[ii]); n   } n } n inline void printa(long long *a, int i, int j) { n   for (int ii = i; ii <= j; ii++) { n     printf( %I64d  , a[ii]); n   } n } n inline void printv(vector<int> &a, int i, int j) { n   for (int ii = i; ii <= j; ii++) { n     printf( %d  , a[ii]); n   } n } n inline void printv(vector<long long> &a, int n, int i, int j) { n   for (int ii = i; ii <= j; ii++) { n     printf( %I64d  , a[ii]); n   } n } n inline long long max(long long a, long long b) { return (a > b) ? a : b; } n inline int max(int a, int b) { return (a > b) ? a : b; } n inline double max(double a, double b) { return (a > b) ? a : b; } n inline long long max(long long a, long long b, long long c) { n   return max(a, max(b, c)); n } n inline int max(int a, int b, int c) { return max(a, max(b, c)); } n inline double max(double a, double b, double c) { return max(a, max(b, c)); } n inline long long min(long long a, long long b) { return (a < b) ? a : b; } n inline int min(int a, int b) { return (a < b) ? a : b; } n inline double min(double a, double b) { return (a < b) ? a : b; } n inline long long min(long long a, long long b, long long c) { n   return min(a, min(b, c)); n } n inline int min(int a, int b, int c) { return min(a, min(b, c)); } n inline double min(double a, double b, double c) { return min(a, min(b, c)); } n inline long long pow(long long x, long long n) { n   long long res = 1; n   while (n) { n     if (n & 1) res *= x; n     x *= x; n     n >>= 1; n   } n   return res; n } n inline long long powmod(long long x, long long n, long long _mod) { n   long long res = 1; n   while (n) { n     if (n & 1) res = (res * x) % _mod; n     x = (x * x) % _mod; n     n >>= 1; n   } n   return res; n } n inline long long gcd(long long a, long long b) { n   long long t; n   while (b) { n     a = a % b; n     t = a; n     a = b; n     b = t; n   } n   return a; n } n inline int gcd(int a, int b) { n   int t; n   while (b) { n     a = a % b; n     t = a; n     a = b; n     b = t; n   } n   return a; n } n inline long long lcm(int a, int b) { return a / gcd(a, b) * (long long)b; } n inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n inline long long gcd(long long a, long long b, long long c) { n   return gcd(gcd(a, b), c); n } n inline int gcd(int a, int b, int c) { return gcd(gcd(a, b), c); } n inline long long lcm(long long a, long long b, long long c) { n   return lcm(lcm(a, b), c); n } n inline long long lcm(int a, int b, int c) { n   return lcm(lcm(a, b), (long long)c); n } n inline int bits_count(int v) { n   v = v - ((v >> 1) & 0x55555555); n   v = (v & 0x33333333) + ((v >> 2) & 0x33333333); n   return ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; n } n inline int bits_count(long long v) { n   long long t = v >> 32; n   long long p = (v & ((1LL << 32) - 1)); n   return bits_count(t) + bits_count(p); n } n inline bool ispow2(int x) { return (x != 0 && (x & (x - 1)) == 0); } n const char nl =   n ; n void solve() { n   int n; n   cin >> n; n   vector<int> a(n); n   getv(a, n); n   int last = -1, cnt = 0; n   sort(a.begin(), a.end()); n   for (int i = 0; i < n; i++) { n     if (a[i] != 1 && last < a[i] - 1) n       last = a[i] - 1, cnt++; n     else if (last < a[i]) n       last = a[i], cnt++; n     else if (last < a[i] + 1) n       last = a[i] + 1, cnt++; n   } n   cout << cnt << nl; n } n int main() { n   clock_t clk = clock(); n   cerr <<  Hey P.. n ; n   int t; n   t = 1; n   while (t--) solve(); n   cerr <<  Look at the sky. n ; n   cerr <<  Time (in ms):   << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC n        <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename _T> n inline void read(_T &f) { n   f = 0; n   _T fu = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) { n       fu = -1; n     } n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     f = (f << 3) + (f << 1) + (c & 15); n     c = getchar(); n   } n   f *= fu; n } n template <typename T> n void print(T x) { n   if (x < 0) putchar( - ), x = -x; n   if (x < 10) n     putchar(x + 48); n   else n     print(x / 10), putchar(x % 10 + 48); n } n template <typename T> n void print(T x, char t) { n   print(x); n   putchar(t); n } n const int N = 1e6 + 5; n struct ele { n   int f, g; n   ele(int a = 0, int b = 0) : f(a), g(b) {} n   bool operator<(const ele A) const { n     if (f != A.f) return f < A.f; n     return g > A.g; n   } n }; n ele operator+(const ele a, const ele b) { return ele(a.f + b.f, a.g + b.g); } n ele f[N]; n char c[N]; n int s[N]; n int n, k, l; n ele dp(int mid) { n   for (int i = 0; i < l; i++) f[i] = ele(0, 0); n   for (int i = l; i <= n; i++) n     f[i] = max(f[i - 1], f[i - l] + ele(s[i] - s[i - l] - mid, 1)); n   return f[n]; n } n int solve(int opt) { n   for (int i = 1; i <= n; i++) n     s[i] = s[i - 1] + ((c[i] >=  a  && c[i] <=  z ) == opt); n   int l = 0, r = n - 1, ans = n; n   while (l <= r) { n     int mid = (l + r) >> 1; n     if (dp(mid).g <= k) n       ans = mid, r = mid - 1; n     else n       l = mid + 1; n   } n   return s[n] - (dp(ans).f + ans * k); n } n int main() { n   read(n); n   read(k); n   read(l); n   scanf( %s , c + 1); n   if (1ll * k * l > n) { n     print(0,   n ); n     return 0; n   } n   print(min(solve(0), solve(1)),   n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100005; n int legs[N]; n bool hide[N]; n vector<vector<int> > adj; n void dfs(int v, int par = 0) { n   if (adj[v].size() <= 2u) { n     hide[v] = true; n     for (int i : adj[v]) { n       if (i != par) { n         dfs(i, v); n       } n     } n   } n } n int main() { n   int n, a, b; n   scanf( %d , &n); n   adj.resize(n + 1); n   for (int i = 0; i < n - 1; ++i) { n     scanf( %d%d , &a, &b); n     adj[a].push_back(b); n     adj[b].push_back(a); n   } n   for (int i = 1; i <= n; ++i) { n     if (adj[i].size() == 1u) { n       dfs(i); n     } n   } n   for (int i = 1; i <= n; ++i) { n     for (int j : adj[i]) { n       if (hide[j]) { n         legs[i] = min(2, legs[i] + 1); n       } n     } n   } n   for (int i = 1; i <= n; ++i) { n     if (!hide[i]) { n       int count = 0; n       for (int j : adj[i]) { n         if (!hide[j] && (int)adj[j].size() - legs[j] > 1) { n           ++count; n         } n       } n       if (count > 2) { n         printf( No n ); n         return 0; n       } n     } n   } n   printf( Yes n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int parent[5001][5001]; n int dp[5001][5001]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   long long n, m, t; n   cin >> n >> m >> t; n   vector<int> u(m + 1), v(m + 1), tm(m + 1); n   for (int i = 1; i <= m; i++) { n     cin >> u[i] >> v[i] >> tm[i]; n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       dp[i][j] = 1e9 + 5; n     } n   } n   dp[1][1] = 0; n   for (int i = 2; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       int p = u[j]; n       int cur = v[j]; n       if (dp[p][i - 1] + tm[j] < dp[cur][i]) { n         dp[cur][i] = dp[p][i - 1] + tm[j]; n         parent[cur][i] = p; n       } n     } n   } n   int res = 0; n   for (int i = n; i > 0; i--) { n     if (dp[n][i] <= t) { n       res = i; n       break; n     } n   } n   cout << res << endl; n   int ind = n; n   int visit = res; n   vector<int> path; n   while (ind != 0) { n     path.push_back(ind); n     ind = parent[ind][visit--]; n   } n   for (int i = path.size() - 1; i >= 0; i--) { n     cout << path[i] <<    ; n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n pair<long long, long long> dp[1100][20]; n int bitcnt[1100]; n long long p10[21]; n string a; n int n, k; n pair<long long, long long> dfs(int bi, int pos, int flag, int leading) { n   if (pos == -1) return make_pair(0, 1); n   if (dp[bi][pos].second != -1 && !flag && !leading) { n     return dp[bi][pos]; n   } n   long long ans = 0; n   long long cnt = 0; n   int upper = (flag ? a[n - pos - 1] -  0  : 9); n   for (int i = 0; i <= upper; i++) { n     int nextstate = (bi | (1 << i)); n     if ((bi & (1 << i)) == 0 && !(leading && i == 0)) { n       if (bitcnt[nextstate] > k) continue; n       pair<long long, long long> p = n           dfs(nextstate, pos - 1, flag && (i == upper), leading && (i == 0)); n       cnt = (cnt + p.second) % 998244353; n       ans = (ans + n              ((((p.second * i) % 998244353) * p10[pos]) % 998244353 + p.first) % n                  998244353) % n             998244353; n     } else { n       pair<long long, long long> p = n           dfs(bi, pos - 1, flag && (i == upper), leading && (i == 0)); n       cnt = (cnt + p.second) % 998244353; n       ans = (ans + n              ((((p.second * i) % 998244353) * p10[pos]) % 998244353 + p.first) % n                  998244353) % n             998244353; n     } n   } n   if (!flag && !leading) { n     dp[bi][pos] = make_pair(ans % 998244353, cnt % 998244353); n   } n   return make_pair(ans % 998244353, cnt % 998244353); n } n long long solve(long long num) { n   a = to_string(num); n   n = (int)a.length(); n   pair<long long, long long> p = dfs(0, n - 1, 1, 1); n   return p.first % 998244353; n } n int main() { n   long long l, r; n   int i, j; n   p10[0] = 1; n   for (i = 1; i <= 20; i++) { n     p10[i] = (p10[i - 1] * 10) % 998244353; n   } n   for (i = 0; i < 1100; i++) { n     for (j = 0; j < 20; j++) { n       dp[i][j] = make_pair(0, -1); n     } n   } n   bitcnt[0] = 0; n   bitcnt[1] = 1; n   for (i = 2; i < 1100; i++) bitcnt[i] = bitcnt[i - (i & -i)] + 1; n   cin >> l >> r >> k; n   cout << (solve(r) - solve(l - 1) + 998244353) % 998244353 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-8; n const double pi = acos(-1.0); n const int INF = 0x3f3f3f3f; n const int mod = 1e9 + 7; n long long powmod(long long a, long long b) { n   long long res = 1; n   a %= mod; n   assert(b >= 0); n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n   } n   return res; n } n string s; n int main() { n   int t, cas = 1; n   cin >> s; n   int n = ((int)(s).size()); n   for (int i = 1; i <= n / 2; i++) { n     int cnt = 0; n     for (int j = 0; j < n - i; j++) { n       if (s[j] == s[j + i]) n         cnt++; n       else n         cnt = 0; n       if (cnt == i) { n         s = s.substr(0, j - i + 1) + s.substr(j + 1, n - j - 1); n         n -= i; n         i = 0; n         break; n       } n     } n   } n   cout << s << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   int b[200005]; n   vector<int> a; n   cin >> n; n   a.push_back(31); n   a.push_back(28); n   a.push_back(31); n   a.push_back(30); n   a.push_back(31); n   a.push_back(30); n   a.push_back(31); n   a.push_back(31); n   a.push_back(30); n   a.push_back(31); n   a.push_back(30); n   a.push_back(31); n   for (int i = 0; i < n; i++) { n     cin >> b[i]; n   } n   for (int i = 0; i < 12; i++) { n     int count = 0, f = 0; n     for (int j = 0; j < n; j++) { n       if ((i + j) % 12 == 1) { n         if (a[(i + j) % 12] == b[j]) n           continue; n         else { n           if (a[(i + j) % 12] == 28 && b[j] == 29 && count == 0) { n             count = 1; n             continue; n           } n         } n       } n       if (a[(i + j) % 12] != b[j]) { n         f = 1; n         break; n       } n     } n     if (f == 0) { n       cout <<  YES  << endl; n       return 0; n     } n   } n   cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC target( sse4,avx ) n const double pi = 3.14159265358979323; n struct dpoint { n   double x, y; n   dpoint() : x(0), y(0) {} n   dpoint(double x, double y) : x(x), y(y) {} n }; n void run(std::istream& in, std::ostream& out) { n   int n; n   dpoint p; n   in >> n >> p.x >> p.y; n   std::vector<dpoint> points(n); n   for (int i = 0; i < n; i++) { n     in >> points[i].x >> points[i].y; n   } n   double maxR = 0; n   double minR = 1e10; n   for (int i = 0; i < n; i++) { n     double dist1 = hypot(points[i].x - p.x, points[i].y - p.y); n     maxR = std::max(maxR, dist1); n     minR = std::min(minR, dist1); n     dpoint& p1 = points[i]; n     dpoint& p2 = points[(i + 1) % n]; n     if ((p2.x - p1.x) * (p.x - p1.x) + (p2.y - p1.y) * (p.y - p1.y) > 0.5 && n         (p1.x - p2.x) * (p.x - p2.x) + (p1.y - p2.y) * (p.y - p2.y) > 0.5) { n       double a = p1.y - p2.y; n       double b = p2.x - p1.x; n       double dist = a * p.x + b * p.y - a * p1.x - b * p1.y; n       dist /= hypot(a, b); n       minR = std::min(minR, std::abs(dist)); n     } n   } n   out.precision(20); n   out << std::fixed; n   out << (maxR * maxR - minR * minR) * pi << std::endl; n } n int main() { n   std::cin.sync_with_stdio(false); n   std::cin.tie(nullptr); n   run(std::cin, std::cout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void fastInOut() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL), cout.tie(NULL); n } n int dx[] = {0, 0, 1, -1, -1, -1, 1, 1}; n int dy[] = {1, -1, 0, 0, -1, 1, -1, 1}; n int main() { n   double m, n, total = 0.0; n   cin >> m >> n; n   for (double i = 1; i <= m; i++) { n     double temp = pow(i / m, n) - pow((i - 1) / m, n); n     temp *= i; n     total += temp; n   } n   cout << fixed << setprecision(12) << total; n } n


#include <bits/stdc++.h> n using namespace std; n const int _1e5 = 100000; n const int _1e7 = 10000000; n const int _1e9 = 1000000000; n template <typename A, typename B> n ostream& operator<<(ostream& str, const pair<A, B>& p) { n   return str <<  (  << p.first <<  ,   << p.second <<  ) ; n } n template <typename T> n ostream& operator<<(ostream& str, const vector<T>& v) { n   str <<  [ ; n   for (const auto& n : v) str << n <<  ,  ; n   str <<  ] ; n   return str; n } n template <typename T> n ostream& operator<<(ostream& str, const set<T>& v) { n   str <<  { ; n   for (const auto& n : v) { n     str << n <<  ,  ; n   } n   str <<  } ; n   return str; n } n template <typename K, typename V> n ostream& operator<<(ostream& str, const unordered_map<K, V>& v) { n   str <<  { ; n   for (const auto& p : v) { n     str << p.first <<   =>   << p.second <<  ,  ; n   } n   str <<  } ; n   return str; n } n int main() { n   ios_base::sync_with_stdio(false); n   cout.setf(std::ios::fixed); n   cout.precision(12); n   int n; n   cin >> n; n   string a; n   cin >> a; n   vector<int> f(10); n   f[0] = 0; n   for (int i = 1; i <= 9; ++i) { n     cin >> f[i]; n   } n   int left_start = -1; n   for (int i = 0; i < a.size(); ++i) { n     int digit = a[i] -  0 ; n     if (f[digit] > digit) { n       left_start = i; n       break; n     } n   } n   if (left_start == -1) { n     cout << a << endl; n     return 0; n   } n   while (true) { n     if (left_start >= a.size()) { n       break; n     } n     int digit = a[left_start] -  0 ; n     if (f[digit] < digit) { n       break; n     } n     a[left_start++] =  0  + f[digit]; n   } n   cout << a << endl; n } n


#include <bits/stdc++.h> n using namespace std; n typedef pair<int, int> PII; n long long qpow(long long a, long long b, long long m) { n   long long ans = 1; n   while (b) { n     if (b & 1) ans = ans * a % m; n     a = a * a % m, b >>= 1; n   } n   return ans; n } n long long qpow(long long a, long long b) { n   long long ans = 1; n   while (b) { n     if (b & 1) ans = ans * a; n     a = a * a, b >>= 1; n   } n   return ans; n } n long long qmul(long long a, long long b, long long m) { n   long long res = 0; n   while (b > 0) { n     if (b & 1) res = (res + a) % m; n     a = (a + a) % m; n     b >>= 1; n   } n   return res; n } n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n long long inv(long long t, long long p) { n   return t == 1 ? 1 : (p - p / t) * inv(p % t, p) % p; n } n long long exgcd(long long a, long long b, long long &x, long long &y) { n   if (b == 0) { n     x = 1; n     y = 0; n     return a; n   } n   long long r = exgcd(b, a % b, y, x); n   y -= (a / b) * x; n   return r; n } n long long inv1(long long a, long long p) { n   long long d, x, y; n   d = exgcd(a, p, x, y); n   return d == 1 ? (x % p + p) % p : -1; n } n template <typename T, typename B> n T Add(T a, B b, long long m) { n   return a + b >= m ? (a + b) % m : a + b; n } n template <typename T, typename B> n T Sub(T a, B b, long long m) { n   return a - b < 0 ? (a - b + m) % m : a - b; n } n template <class T> n void _sf(T &x) { n   cin >> x; n } n void _sf(int &x) { scanf( %d , &x); } n void _sf(long long &x) { scanf( %lld , &x); } n void _sf(double &x) { scanf( %lf , &x); } n void _sf(char &x) { scanf(  %c , &x); } n void _sf(char *x) { scanf( %s , x); } n void sf() {} n template <class T, class... U> n void sf(T &head, U &...tail) { n   _sf(head); n   sf(tail...); n } n template <class T> n void _pf(const T &x) { n   cout << x; n } n void _pf(const int &x) { printf( %d , x); } n void _pf(const long long &x) { printf( %lld , x); } n void _pf(const double &x) { printf( %.16f , x); } n void _pf(const char &x) { putchar(x); } n void _pf(const char *x) { printf( %s , x); } n template <class T, class U> n void _pf(const pair<T, U> &x) { n   pf(x.first); n   putchar(   ); n   pf(x.second); n } n template <class T> n void _pf(const vector<T> &x) { n   for (auto i = x.begin(); i != x.end(); _pf(*i++)) n     if (i != x.cbegin()) putchar(   ); n } n void pf() {} n template <class T, class... U> n void pf(const T &head, const U &...tail) { n   _pf(head); n   putchar(sizeof...(tail) ?     :   n ); n   pf(tail...); n } n template <typename T> n inline void read(T &x) { n   x = 0; n   static int p; n   p = 1; n   static char c; n   c = getchar(); n   while (!isdigit(c)) { n     if (c ==  - ) p = -1; n     c = getchar(); n   } n   while (isdigit(c)) { n     x = (x << 1) + (x << 3) + (c - 48); n     c = getchar(); n   } n   x *= p; n } n const bool IOS = false; n const double PI = acos(-1); n const double eps = 1e-8; n const long long linf = 0x3f3f3f3f3f3f3f3f; n const long long INV2 = 500000004; n const long long mod = 1e9 + 7; n const int inf = 0x3f3f3f3f; n const int maxn = 1e6 + 100; n char s1[maxn], s2[maxn]; n long long a[maxn], b[maxn]; n void init() { n   a[0] = b[0] = 1; n   for (int i = 1; i < maxn; ++i) { n     a[i] = (a[i - 1] * i) % mod; n   } n   b[maxn - 1] = qpow(a[maxn - 1], mod - 2, mod); n   for (int i = maxn - 1; i > 0; i--) b[i - 1] = b[i] * i % mod; n } n long long C(long long n, long long m) { n   if (n < m) return 0; n   return a[n] * b[m] % mod * b[n - m] % mod; n } n int cnt[256]; n long long calc(char s[], int n) { n   memset(cnt, 0, sizeof(cnt)); n   for (int i = 1; i <= n; ++i) cnt[s1[i]]++; n   long long tmp = a[n]; n   for (int i =  a ; i <=  z ; ++i) tmp = tmp * b[cnt[i]] % mod; n   long long ret = 0; n   for (int i = 1; i <= n; ++i) { n     tmp = tmp * qpow(n - i + 1, mod - 2, mod) % mod; n     for (int j =  a ; j < s[i]; ++j) n       if (cnt[j]) ret = (ret + tmp * cnt[j] % mod) % mod; n     tmp = tmp * cnt[s[i]] % mod; n     cnt[s[i]]--; n     if (cnt[s[i]] < 0) return ret; n   } n   return ret; n } n void Main(); n int main() { n   if (IOS) std::ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   Main(); n   0; n   return 0; n } n void Main() { n   init(); n   scanf( %s%s , s1 + 1, s2 + 1); n   int len = strlen(s1 + 1); n   long long res = calc(s2, len) - calc(s1, len); n   res--; n   res = (res % mod + mod) % mod; n   pf(res); n } n